rapid-render 1.0.18 → 1.0.19

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.
@@ -163,19 +163,19 @@ class bt {
163
163
  async load(t, e) {
164
164
  let r = this.cache.get(t);
165
165
  if (r)
166
- return new N(r);
166
+ return new D(r);
167
167
  try {
168
168
  const i = await this._fetchImage(t);
169
- return r = G.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new N(r);
169
+ return r = X.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new D(r);
170
170
  } catch (i) {
171
171
  throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
172
172
  }
173
173
  }
174
174
  create(t, e) {
175
175
  if (e?.key && this.cache.has(e.key))
176
- return new N(this.cache.get(e.key));
177
- const r = G.fromSource(this.render, t, e);
178
- return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new N(r);
176
+ return new D(this.cache.get(e.key));
177
+ const r = X.fromSource(this.render, t, e);
178
+ return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new D(r);
179
179
  }
180
180
  createRenderTexture(t) {
181
181
  return new Ut(this.render, t);
@@ -185,7 +185,7 @@ class bt {
185
185
  }
186
186
  destroy(t, e = !1) {
187
187
  let r, i;
188
- 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));
188
+ typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof D ? (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));
189
189
  }
190
190
  destroyAll() {
191
191
  for (const t of this.cache.values())
@@ -199,7 +199,7 @@ class bt {
199
199
  });
200
200
  }
201
201
  }
202
- class G {
202
+ class X {
203
203
  glTexture = null;
204
204
  width;
205
205
  height;
@@ -210,7 +210,7 @@ class G {
210
210
  }
211
211
  static fromSource(t, e, r = {}) {
212
212
  const i = rt(t, e, r);
213
- return new G(i, e.width, e.height);
213
+ return new X(i, e.width, e.height);
214
214
  }
215
215
  updateSource(t, e, r = {}) {
216
216
  this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && ht(t, r.textureFilter), r.wrap !== void 0 && at(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));
@@ -225,7 +225,7 @@ class G {
225
225
  this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
226
226
  }
227
227
  }
228
- class N {
228
+ class D {
229
229
  base;
230
230
  uvX = 0;
231
231
  uvY = 0;
@@ -259,12 +259,12 @@ class N {
259
259
  return this.base ? (this._px = t, this._py = e, this.isAtlas = t !== 0 || e !== 0 || r !== this.base.width || i !== this.base.height, this.uvX = t / this.base.width, this.uvY = e / this.base.height, this.uvW = this.uvX + r / this.base.width, this.uvH = this.uvY + i / this.base.height, this.rawWidth = r * this.scale, this.rawHeight = i * this.scale, this) : this;
260
260
  }
261
261
  getSubTexture(t, e, r, i) {
262
- if (!this.base) return new N();
262
+ if (!this.base) return new D();
263
263
  const s = this.clone(), a = this._px, h = this._py;
264
264
  return s.setRegion(a + t, h + e, r, i), s;
265
265
  }
266
266
  clone(t) {
267
- const e = t ?? new N(this.base);
267
+ const e = t ?? new D(this.base);
268
268
  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;
269
269
  }
270
270
  splitGrid(t, e, r, i, s = 0) {
@@ -277,13 +277,13 @@ class N {
277
277
  }
278
278
  static fromImageSource(t, e, r = {}) {
279
279
  const i = rt(t, e, r);
280
- return new N(new G(i, e.width, e.height));
280
+ return new D(new X(i, e.width, e.height));
281
281
  }
282
282
  destroy() {
283
283
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
284
284
  }
285
285
  }
286
- class Ut extends N {
286
+ class Ut extends D {
287
287
  framebuffer;
288
288
  renderbuffer;
289
289
  gl;
@@ -293,7 +293,7 @@ class Ut extends N {
293
293
  constructor(t, e) {
294
294
  super(), this.gl = t.gl, this.clearColor = e.clearColor ?? m.Black;
295
295
  const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = rt(t, { width: r, height: i }, { ...e, onlySize: !0 });
296
- if (this.setBase(new G(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
296
+ if (this.setBase(new X(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
297
297
  throw new Error("Failed to create Framebuffer or Renderbuffer");
298
298
  this.resize(r, i, !0);
299
299
  }
@@ -346,7 +346,7 @@ const Ct = {
346
346
  align: "left",
347
347
  lineHeight: 1
348
348
  };
349
- class _t extends N {
349
+ class _t extends D {
350
350
  canvas;
351
351
  ctx;
352
352
  render;
@@ -360,7 +360,7 @@ class _t extends N {
360
360
  if (!r) throw new Error("Failed to get 2d context for TextTexture");
361
361
  this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
362
362
  const i = rt(t, this.canvas, this.options);
363
- this.setBase(new G(i, 1, 1)), this.update();
363
+ this.setBase(new X(i, 1, 1)), this.update();
364
364
  }
365
365
  get text() {
366
366
  return this._text;
@@ -379,31 +379,39 @@ class _t extends N {
379
379
  case "center":
380
380
  return t / 2;
381
381
  case "right":
382
- return t;
382
+ return t - e;
383
383
  default:
384
384
  return e;
385
385
  }
386
386
  }
387
387
  update() {
388
- const t = this.ctx, e = this.style, r = e.fontSize, i = e.fontWeight, s = e.fontFamily, a = e.lineHeight, h = `${i} ${r}px ${s}`, o = this.render.dpr;
389
- t.font = h, t.textBaseline = "top";
390
- const c = this._text.split(`
391
- `);
392
- let u = 0, l = 0;
393
- const x = t.measureText(c[0] || "M").fontBoundingBoxDescent;
394
- for (const b of c) {
395
- const M = t.measureText(b);
396
- M.width > u && (u = M.width), l += x * a;
388
+ const t = this.ctx, e = this.style, r = this.render.dpr, i = e.fontSize, s = e.fontWeight, a = e.fontFamily, h = e.lineHeight, o = `${s} ${i}px ${a}`, c = e.baseline ?? "middle", u = e.align ?? "left", l = e.strokeThickness ?? 0, f = l > 0, d = this._text.split(`
389
+ `), x = "国g", p = d[0] || x;
390
+ t.font = o, t.textBaseline = "alphabetic", t.textAlign = "left";
391
+ let y = 0, v = 0, E = 0;
392
+ for (const F of d) {
393
+ const H = t.measureText(F || x);
394
+ y = Math.max(y, F ? H.width : 0), v = Math.max(v, H.actualBoundingBoxAscent), E = Math.max(E, H.actualBoundingBoxDescent);
397
395
  }
398
- l -= x * (a - 1);
399
- const p = this._style.strokeThickness || 0, v = Math.ceil(u + p * 2) || 1, y = Math.ceil(l + p * 2) || 1, E = Math.ceil(v * o), w = Math.ceil(y * o);
400
- (this.canvas.width !== E || this.canvas.height !== w) && (this.canvas.width = E, this.canvas.height = w), t.setTransform(o, 0, 0, o, 0, 0), t.clearRect(0, 0, v, y), t.font = h, t.textBaseline = "top", t.textAlign = this._style.align;
401
- const _ = this.updateOffset(v, p), L = e.strokeThickness, W = L > 0;
402
- W && (t.lineWidth = L, t.strokeStyle = e.stroke, t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
403
- let O = p;
404
- for (const b of c)
405
- W && t.strokeText(b, _, O), e.fill && t.fillText(b, _, O), O += x * a;
406
- this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, E, w);
396
+ t.textBaseline = "alphabetic";
397
+ const S = t.measureText(p).fontBoundingBoxDescent;
398
+ t.textBaseline = c;
399
+ const _ = t.measureText(p).fontBoundingBoxDescent, P = i * h, k = v + E + (d.length - 1) * P, I = l / 2 + 1, C = Math.max(
400
+ 1,
401
+ Math.ceil(y + I * 2)
402
+ ), R = Math.max(
403
+ 1,
404
+ Math.ceil(k + I * 2)
405
+ ), w = Math.ceil(C * r), W = Math.ceil(R * r);
406
+ (this.canvas.width !== w || this.canvas.height !== W) && (this.canvas.width = w, this.canvas.height = W), t.setTransform(r, 0, 0, r, 0, 0), t.clearRect(0, 0, w / r, W / r), t.font = o, t.textBaseline = "alphabetic", t.textAlign = u;
407
+ const B = this.updateOffset(C, I);
408
+ f && (t.lineWidth = l, t.strokeStyle = e.stroke ?? "#000000", t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
409
+ let L = I + v;
410
+ for (const F of d)
411
+ f && t.strokeText(F, B, L), e.fill && t.fillText(F, B, L), L += P;
412
+ this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, w, W);
413
+ const O = S - _;
414
+ this.offsetY = -I - v - O;
407
415
  }
408
416
  }
409
417
  const Lt = (n, t = !1, e = !0) => {
@@ -769,7 +777,7 @@ class Et {
769
777
  }
770
778
  }
771
779
  var A = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(A || {});
772
- class S {
780
+ class b {
773
781
  usedElemNum;
774
782
  typedArray;
775
783
  arrayType;
@@ -868,7 +876,7 @@ class S {
868
876
  return this.usedElemNum;
869
877
  }
870
878
  }
871
- class ut extends S {
879
+ class ut extends b {
872
880
  buffer;
873
881
  gl;
874
882
  dirty = !0;
@@ -979,7 +987,7 @@ void main(void) {\r
979
987
  \r
980
988
  // CUSTOM_CODE_CALL\r
981
989
  }\r
982
- `, Y = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
990
+ `, z = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
983
991
  class lt extends Et {
984
992
  instanceBuffer;
985
993
  quadBuffer;
@@ -1002,11 +1010,11 @@ class lt extends Et {
1002
1010
  createShader(t, e) {
1003
1011
  const r = super.createShader(t, e);
1004
1012
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1005
- { name: "aMatrixRow0", size: 3, stride: Y, offset: 0, divisor: 1 },
1006
- { name: "aMatrixRow1", size: 3, stride: Y, offset: 12, divisor: 1 },
1007
- { name: "aUVRect", size: 4, stride: Y, offset: 24, divisor: 1 },
1008
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: Y, offset: 40, divisor: 1 },
1009
- { name: "aTextureId", size: 1, type: ot, stride: Y, offset: 44, divisor: 1 }
1013
+ { name: "aMatrixRow0", size: 3, stride: z, offset: 0, divisor: 1 },
1014
+ { name: "aMatrixRow1", size: 3, stride: z, offset: 12, divisor: 1 },
1015
+ { name: "aUVRect", size: 4, stride: z, offset: 24, divisor: 1 },
1016
+ { name: "aColor", size: 4, type: ot, normalized: !0, stride: z, offset: 40, divisor: 1 },
1017
+ { name: "aTextureId", size: 1, type: ot, stride: z, offset: 44, divisor: 1 }
1010
1018
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1011
1019
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1012
1020
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
@@ -1033,17 +1041,17 @@ class lt extends Et {
1033
1041
  f
1034
1042
  );
1035
1043
  }
1036
- drawSpriteAffine(t, e, r, i, s, a, h, o = 0, c = 0, u = 1, l = 1, f = 4294967295, d = 0, x = 0, p = !1, v = !1, y = !1) {
1037
- const E = t.base, w = t.rawWidth, _ = t.rawHeight, L = t.offsetX, W = t.offsetY, O = this.useTexture(
1044
+ drawSpriteAffine(t, e, r, i, s, a, h, o = 0, c = 0, u = 1, l = 1, f = 4294967295, d = 0, x = 0, p = !1, y = !1, v = !1) {
1045
+ const E = t.base, S = t.rawWidth, _ = t.rawHeight, P = t.offsetX, k = t.offsetY, I = this.useTexture(
1038
1046
  t.glTexture,
1039
1047
  d / E.width,
1040
1048
  x / E.height
1041
- ), b = this.instanceBuffer, M = b.usedElemNum;
1042
- b.resize(12);
1043
- const C = b.float32, D = b.uint32, B = y ? _ : w, k = y ? w : _, I = B + 2 * d, F = k + 2 * x, V = L - d, z = W - x, R = this.localSpriteMatrix;
1044
- y ? (R[0] = 0, R[1] = v ? F : -F, R[2] = p ? -I : I, R[3] = 0, R[4] = V + (p ? I : 0), R[5] = z + (v ? 0 : F)) : (R[0] = p ? -I : I, R[1] = 0, R[2] = 0, R[3] = v ? -F : F, R[4] = V + (p ? I : 0), R[5] = z + (v ? F : 0));
1049
+ ), C = this.instanceBuffer, R = C.usedElemNum;
1050
+ C.resize(12);
1051
+ const w = C.float32, W = C.uint32, B = v ? _ : S, G = v ? S : _, L = B + 2 * d, O = G + 2 * x, F = P - d, H = k - x, M = this.localSpriteMatrix;
1052
+ v ? (M[0] = 0, M[1] = y ? O : -O, M[2] = p ? -L : L, M[3] = 0, M[4] = F + (p ? L : 0), M[5] = H + (y ? 0 : O)) : (M[0] = p ? -L : L, M[1] = 0, M[2] = 0, M[3] = y ? -O : O, M[4] = F + (p ? L : 0), M[5] = H + (y ? O : 0));
1045
1053
  const U = this.worldSpriteMatrix;
1046
- U[0] = e * R[0] + i * R[1], U[1] = r * R[0] + s * R[1], U[2] = e * R[2] + i * R[3], U[3] = r * R[2] + s * R[3], U[4] = a + e * R[4] + i * R[5], U[5] = h + r * R[4] + s * R[5], C[M + 6] = o, C[M + 7] = c, C[M + 8] = u, C[M + 9] = l, D[M + 10] = f, D[M + 11] = O, this.rapid.roundPixels && (U[4] = Math.round(U[4]), U[5] = Math.round(U[5])), C[M] = U[0], C[M + 1] = U[2], C[M + 2] = U[4], C[M + 3] = U[1], C[M + 4] = U[3], C[M + 5] = U[5], b.usedElemNum += 12, b.makeDirty(), this.instanceCount++;
1054
+ U[0] = e * M[0] + i * M[1], U[1] = r * M[0] + s * M[1], U[2] = e * M[2] + i * M[3], U[3] = r * M[2] + s * M[3], U[4] = a + e * M[4] + i * M[5], U[5] = h + r * M[4] + s * M[5], w[R + 6] = o, w[R + 7] = c, w[R + 8] = u, w[R + 9] = l, W[R + 10] = f, W[R + 11] = I, this.rapid.roundPixels && (U[4] = Math.round(U[4]), U[5] = Math.round(U[5])), w[R] = U[0], w[R + 1] = U[2], w[R + 2] = U[4], w[R + 3] = U[1], w[R + 4] = U[3], w[R + 5] = U[5], C.usedElemNum += 12, C.makeDirty(), this.instanceCount++;
1047
1055
  }
1048
1056
  render() {
1049
1057
  if (this.instanceCount === 0) return;
@@ -1065,7 +1073,7 @@ class Bt {
1065
1073
  data;
1066
1074
  temporary = -1;
1067
1075
  constructor(t = 10) {
1068
- this.buffer = new S(A.Float32), this.buffer.resize(t * T), this.data = this.buffer.getArray(), this.reset();
1076
+ this.buffer = new b(A.Float32), this.buffer.resize(t * T), this.data = this.buffer.getArray(), this.reset();
1069
1077
  }
1070
1078
  alloc() {
1071
1079
  const t = this.allocDirty();
@@ -1104,8 +1112,8 @@ class Bt {
1104
1112
  this.multiplyOut(t, t, e);
1105
1113
  }
1106
1114
  multiplyOut(t, e, r) {
1107
- const i = t * T, s = e * T, a = r * T, h = this.data, o = h[s], c = h[s + 1], u = h[s + 2], l = h[s + 3], f = h[s + 4], d = h[s + 5], x = h[a], p = h[a + 1], v = h[a + 2], y = h[a + 3], E = h[a + 4], w = h[a + 5];
1108
- h[i] = o * x + u * p, h[i + 1] = c * x + l * p, h[i + 2] = o * v + u * y, h[i + 3] = c * v + l * y, h[i + 4] = o * E + u * w + f, h[i + 5] = c * E + l * w + d;
1115
+ const i = t * T, s = e * T, a = r * T, h = this.data, o = h[s], c = h[s + 1], u = h[s + 2], l = h[s + 3], f = h[s + 4], d = h[s + 5], x = h[a], p = h[a + 1], y = h[a + 2], v = h[a + 3], E = h[a + 4], S = h[a + 5];
1116
+ h[i] = o * x + u * p, h[i + 1] = c * x + l * p, h[i + 2] = o * y + u * v, h[i + 3] = c * y + l * v, h[i + 4] = o * E + u * S + f, h[i + 5] = c * E + l * S + d;
1109
1117
  }
1110
1118
  invert(t) {
1111
1119
  const e = t * T, r = this.data, i = r[e], s = r[e + 1], a = r[e + 2], h = r[e + 3], o = r[e + 4], c = r[e + 5];
@@ -1165,19 +1173,19 @@ class Bt {
1165
1173
  c[o] = u * e + f * r, c[o + 1] = l * e + d * r, c[o + 2] = u * i + f * s, c[o + 3] = l * i + d * s, c[o + 4] = u * a + f * h + x, c[o + 5] = l * a + d * h + p;
1166
1174
  }
1167
1175
  multiplyAffine(t, e, r, i, s, a, h, o) {
1168
- const c = t * 6, u = e * 6, l = this.data, f = l[c], d = l[c + 1], x = l[c + 2], p = l[c + 3], v = l[c + 4], y = l[c + 5];
1169
- l[u] = f * r + x * i, l[u + 1] = d * r + p * i, l[u + 2] = f * s + x * a, l[u + 3] = d * s + p * a, l[u + 4] = f * h + x * o + v, l[u + 5] = d * h + p * o + y;
1176
+ const c = t * 6, u = e * 6, l = this.data, f = l[c], d = l[c + 1], x = l[c + 2], p = l[c + 3], y = l[c + 4], v = l[c + 5];
1177
+ l[u] = f * r + x * i, l[u + 1] = d * r + p * i, l[u + 2] = f * s + x * a, l[u + 3] = d * s + p * a, l[u + 4] = f * h + x * o + y, l[u + 5] = d * h + p * o + v;
1170
1178
  }
1171
1179
  }
1172
1180
  class kt {
1173
1181
  matrix = new Bt();
1174
1182
  step = 0;
1175
- stack = new S(A.Uint32);
1176
- stepWorldM = new S(A.Uint32);
1177
- stepAction = new S(A.Uint32);
1178
- stepParentM = new S(A.Uint32);
1179
- stepClose = new S(A.Uint32);
1180
- stepStack = new S(A.Uint32);
1183
+ stack = new b(A.Uint32);
1184
+ stepWorldM = new b(A.Uint32);
1185
+ stepAction = new b(A.Uint32);
1186
+ stepParentM = new b(A.Uint32);
1187
+ stepClose = new b(A.Uint32);
1188
+ stepStack = new b(A.Uint32);
1181
1189
  curLocalM = -1;
1182
1190
  curWorldM = -1;
1183
1191
  rapid;
@@ -1295,36 +1303,36 @@ class kt {
1295
1303
  t.offset && (l += t.offset.x, f += t.offset.y);
1296
1304
  const d = t.origin;
1297
1305
  d !== void 0 && (typeof d == "number" ? (l -= d * e, f -= d * r) : (l -= d.x * e, f -= d.y * r));
1298
- const x = u ? Math.cos(u) : 1, p = u ? Math.sin(u) : 0, v = x * h, y = p * h, E = -p * o, w = x * o, _ = s + v * l + E * f, L = a + y * l + w * f;
1306
+ const x = u ? Math.cos(u) : 1, p = u ? Math.sin(u) : 0, y = x * h, v = p * h, E = -p * o, S = x * o, _ = s + y * l + E * f, P = a + v * l + S * f;
1299
1307
  if (i !== -1) {
1300
1308
  this.matrix.multiplyAffine(
1301
1309
  this.curWorldM,
1302
1310
  i,
1303
- v,
1304
1311
  y,
1312
+ v,
1305
1313
  E,
1306
- w,
1314
+ S,
1307
1315
  _,
1308
- L
1316
+ P
1309
1317
  );
1310
1318
  return;
1311
1319
  }
1312
1320
  this.matrix.multiplyAffineInPlace(
1313
1321
  this.curLocalM,
1314
- v,
1315
1322
  y,
1323
+ v,
1316
1324
  E,
1317
- w,
1325
+ S,
1318
1326
  _,
1319
- L
1327
+ P
1320
1328
  ), this.matrix.multiplyAffineInPlace(
1321
1329
  this.curWorldM,
1322
- v,
1323
1330
  y,
1331
+ v,
1324
1332
  E,
1325
- w,
1333
+ S,
1326
1334
  _,
1327
- L
1335
+ P
1328
1336
  );
1329
1337
  }
1330
1338
  }
@@ -1450,7 +1458,7 @@ void main(void) {\r
1450
1458
  }\r
1451
1459
  }\r
1452
1460
  `, $ = 20;
1453
- class zt extends Et {
1461
+ class Yt extends Et {
1454
1462
  vertexBuffer;
1455
1463
  vertexCount = 0;
1456
1464
  extraTextureUnit = 1;
@@ -1624,7 +1632,7 @@ class g {
1624
1632
  return new g(Math.cos(t), Math.sin(t));
1625
1633
  }
1626
1634
  }
1627
- const Yt = (n, t) => {
1635
+ const zt = (n, t) => {
1628
1636
  const [e, r, i, s, a, h] = t, o = new Float32Array([
1629
1637
  e,
1630
1638
  i,
@@ -1659,8 +1667,8 @@ var jt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1]
1659
1667
  const nt = 10, mt = (n, t, e, r, i, s) => {
1660
1668
  const a = [], h = [], o = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new g(t.y, -t.x);
1661
1669
  for (let l = 0; l < nt; l++) {
1662
- const f = l / nt, d = (l + 1) / nt, x = o + f * c, p = o + d * c, v = new g(Math.cos(x) * e, Math.sin(x) * e), y = new g(Math.cos(p) * e, Math.sin(p) * e);
1663
- a.push(n), h.push(new g(i, 0.5)), a.push(n.add(v)), h.push(new g(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e)), a.push(n.add(y)), h.push(new g(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e));
1670
+ const f = l / nt, d = (l + 1) / nt, x = o + f * c, p = o + d * c, y = new g(Math.cos(x) * e, Math.sin(x) * e), v = new g(Math.cos(p) * e, Math.sin(p) * e);
1671
+ a.push(n), h.push(new g(i, 0.5)), a.push(n.add(y)), h.push(new g(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e)), a.push(n.add(v)), h.push(new g(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e));
1664
1672
  }
1665
1673
  return { vertices: a, uv: h };
1666
1674
  }, Kt = (n, t = !1) => {
@@ -1710,16 +1718,16 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1710
1718
  let c = 0;
1711
1719
  const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
1712
1720
  for (let f = 0; f < l; f++) {
1713
- const d = t[f], x = e[f].normal, p = e[f].miters, v = (f + 1) % t.length, y = t[v], E = e[v].normal, w = e[v].miters, _ = d.add(x.multiply(p * i)), L = d.subtract(x.multiply(p * i)), W = y.add(E.multiply(w * i)), O = y.subtract(E.multiply(w * i)), b = d.distanceTo(y);
1714
- let M = 0, C = 0;
1715
- o === 0 ? (M = c / r, C = (c + b) / r) : (M = c / u, C = M + b / u);
1716
- const D = new g(M, 0), B = new g(M, 1), k = new g(C, 0), I = new g(C, 1);
1717
- s.push(_), a.push(D), s.push(L), a.push(B), s.push(W), a.push(k), s.push(W), a.push(k), s.push(O), a.push(I), s.push(L), a.push(B), c += b;
1721
+ const d = t[f], x = e[f].normal, p = e[f].miters, y = (f + 1) % t.length, v = t[y], E = e[y].normal, S = e[y].miters, _ = d.add(x.multiply(p * i)), P = d.subtract(x.multiply(p * i)), k = v.add(E.multiply(S * i)), I = v.subtract(E.multiply(S * i)), C = d.distanceTo(v);
1722
+ let R = 0, w = 0;
1723
+ o === 0 ? (R = c / r, w = (c + C) / r) : (R = c / u, w = R + C / u);
1724
+ const W = new g(R, 0), B = new g(R, 1), G = new g(w, 0), L = new g(w, 1);
1725
+ s.push(_), a.push(W), s.push(P), a.push(B), s.push(k), a.push(G), s.push(k), a.push(G), s.push(I), a.push(L), s.push(P), a.push(B), c += C;
1718
1726
  }
1719
1727
  if (h && !n.closed) {
1720
1728
  const f = t[0], d = e[0].normal, x = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, p = mt(f, d, i, !0, 0, x);
1721
1729
  s.push(...p.vertices), a.push(...p.uv);
1722
- const v = t[t.length - 1], y = e[t.length - 1].normal, E = o === 0 ? 1 : c / u, w = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, _ = mt(v, y, i, !1, E, w);
1730
+ const y = t[t.length - 1], v = e[t.length - 1].normal, E = o === 0 ? 1 : c / u, S = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, _ = mt(y, v, i, !1, E, S);
1723
1731
  s.push(..._.vertices), a.push(..._.uv);
1724
1732
  }
1725
1733
  return { vertices: s, uv: a };
@@ -1793,7 +1801,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1793
1801
  t.reverseOrder,
1794
1802
  t.customMatrix
1795
1803
  );
1796
- }, Rt = (n, t) => {
1804
+ }, Mt = (n, t) => {
1797
1805
  if (t.points.length === 0) return;
1798
1806
  const e = Q(n, t, 0, 0);
1799
1807
  n.startGraphic(
@@ -1817,7 +1825,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1817
1825
  if (n.inCreateMask)
1818
1826
  return;
1819
1827
  const { vertices: e, uv: r } = qt(t);
1820
- Rt(n, {
1828
+ Mt(n, {
1821
1829
  ...t,
1822
1830
  points: e,
1823
1831
  uv: r,
@@ -1960,7 +1968,7 @@ void main(void) {\r
1960
1968
  \r
1961
1969
  // CUSTOM_CODE_CALL\r
1962
1970
  }\r
1963
- `, H = 48, oe = H / 4;
1971
+ `, V = 48, oe = V / 4;
1964
1972
  class ce extends lt {
1965
1973
  KEY = "ParticleSprite";
1966
1974
  texture;
@@ -1980,41 +1988,41 @@ class ce extends lt {
1980
1988
  createShader(t, e) {
1981
1989
  const r = super.createShader(t, e);
1982
1990
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1983
- { name: "aPosition", size: 2, stride: H, offset: 0, divisor: 1 },
1984
- { name: "aScale", size: 2, stride: H, offset: 8, divisor: 1 },
1985
- { name: "aRotation", size: 1, stride: H, offset: 16, divisor: 1 },
1986
- { name: "aUVRect", size: 4, stride: H, offset: 20, divisor: 1 },
1987
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: H, offset: 36, divisor: 1 },
1988
- { name: "aOrigin", size: 2, stride: H, offset: 40, divisor: 1 }
1991
+ { name: "aPosition", size: 2, stride: V, offset: 0, divisor: 1 },
1992
+ { name: "aScale", size: 2, stride: V, offset: 8, divisor: 1 },
1993
+ { name: "aRotation", size: 1, stride: V, offset: 16, divisor: 1 },
1994
+ { name: "aUVRect", size: 4, stride: V, offset: 20, divisor: 1 },
1995
+ { name: "aColor", size: 4, type: ot, normalized: !0, stride: V, offset: 36, divisor: 1 },
1996
+ { name: "aOrigin", size: 2, stride: V, offset: 40, divisor: 1 }
1989
1997
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1990
1998
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1991
1999
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1992
2000
  }
1993
- drawParticles(t, e, r, i = 0, s = 4294967295, a, h = 1, o = 1, c = 0, u = 0, l = 1, f = 1, d = !1, x = !1, p = !1, v = 0.5, y = 0.5, E, w = !1, _) {
2001
+ drawParticles(t, e, r, i = 0, s = 4294967295, a, h = 1, o = 1, c = 0, u = 0, l = 1, f = 1, d = !1, x = !1, p = !1, y = 0.5, v = 0.5, E, S = !1, _) {
1994
2002
  if (!t.glTexture || a <= 0) return;
1995
2003
  this.texture && t !== this.texture && this.flush();
1996
- const L = typeof h == "number", W = typeof o == "number", O = typeof i == "number", b = typeof s == "number", M = typeof c == "number", C = !b && typeof s[0] == "number", D = t.uvW - t.uvX, B = t.uvH - t.uvY, k = D === 0 ? 0 : 1 / D, I = B === 0 ? 0 : 1 / B;
1997
- let F = t.rawWidth * (d ? -1 : 1);
1998
- L && (F *= h);
1999
- let V = t.rawHeight * (x ? -1 : 1);
2000
- W && (V *= o), M && (F *= (l - c) * k, V *= (f - u) * I);
2001
- let z = p ? Math.PI / 2 : 0;
2002
- O && (z += i);
2003
- const R = s ?? 4294967295, U = this.getParticleLoop(
2004
- L,
2005
- W,
2006
- O,
2007
- M,
2008
- b,
2004
+ const P = typeof h == "number", k = typeof o == "number", I = typeof i == "number", C = typeof s == "number", R = typeof c == "number", w = !C && typeof s[0] == "number", W = t.uvW - t.uvX, B = t.uvH - t.uvY, G = W === 0 ? 0 : 1 / W, L = B === 0 ? 0 : 1 / B;
2005
+ let O = t.rawWidth * (d ? -1 : 1);
2006
+ P && (O *= h);
2007
+ let F = t.rawHeight * (x ? -1 : 1);
2008
+ k && (F *= o), R && (O *= (l - c) * G, F *= (f - u) * L);
2009
+ let H = p ? Math.PI / 2 : 0;
2010
+ I && (H += i);
2011
+ const M = s ?? 4294967295, U = this.getParticleLoop(
2012
+ P,
2013
+ k,
2014
+ I,
2015
+ R,
2009
2016
  C,
2010
2017
  w,
2018
+ S,
2011
2019
  E
2012
2020
  );
2013
2021
  this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2014
- const it = a, X = this.instanceBuffer;
2015
- let st = X.usedElemNum;
2016
- X.resize(it * oe);
2017
- const At = X.float32, St = X.uint32;
2022
+ const it = a, Y = this.instanceBuffer;
2023
+ let st = Y.usedElemNum;
2024
+ Y.resize(it * oe);
2025
+ const At = Y.float32, St = Y.uint32;
2018
2026
  st = U(
2019
2027
  e,
2020
2028
  r,
@@ -2028,18 +2036,18 @@ class ce extends lt {
2028
2036
  s,
2029
2037
  At,
2030
2038
  St,
2039
+ O,
2031
2040
  F,
2032
- V,
2033
- k,
2034
- I,
2035
- z,
2036
- R,
2037
- v,
2041
+ G,
2042
+ L,
2043
+ H,
2044
+ M,
2038
2045
  y,
2046
+ v,
2039
2047
  a,
2040
2048
  it,
2041
2049
  st
2042
- ), X.usedElemNum = st, X.makeDirty(), this.instanceCount += it, this.customMatrix = _, this.flush();
2050
+ ), Y.usedElemNum = st, Y.makeDirty(), this.instanceCount += it, this.customMatrix = _, this.flush();
2043
2051
  }
2044
2052
  getParticleLoop(t, e, r, i, s, a, h, o) {
2045
2053
  const c = [...arguments].join("_");
@@ -2095,11 +2103,11 @@ return idx;
2095
2103
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2096
2104
  const e = this.currentShader;
2097
2105
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2098
- const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = Yt(this.rapid.projection, s);
2106
+ const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = zt(this.rapid.projection, s);
2099
2107
  this.currentShader.setUniform("u_projection", a), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2100
2108
  }
2101
2109
  }
2102
- var Mt = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(Mt || {}), ue = /* @__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))(ue || {}), le = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(le || {});
2110
+ var Rt = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(Rt || {}), ue = /* @__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))(ue || {}), le = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(le || {});
2103
2111
  class pe {
2104
2112
  gl;
2105
2113
  canvas;
@@ -2128,7 +2136,7 @@ class pe {
2128
2136
  textureFilter;
2129
2137
  scaleMode;
2130
2138
  _filterRT = [null, null];
2131
- _filterInput = new N();
2139
+ _filterInput = new D();
2132
2140
  get height() {
2133
2141
  return this.logicHeight;
2134
2142
  }
@@ -2138,7 +2146,7 @@ class pe {
2138
2146
  constructor(t) {
2139
2147
  this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? tt.NEAREST, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
2140
2148
  const e = Lt(this.canvas, this.antialias, this.premultipliedAlpha);
2141
- this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new lt(this), this.graphicRegion = new zt(this), this.atlasSpriteRegion = new ne(this), this.particleRegion = new ce(this);
2149
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new lt(this), this.graphicRegion = new Yt(this), this.atlasSpriteRegion = new ne(this), this.particleRegion = new ce(this);
2142
2150
  const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
2143
2151
  this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new bt(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
2144
2152
  }
@@ -2161,7 +2169,7 @@ class pe {
2161
2169
  ee(this, t);
2162
2170
  }
2163
2171
  drawGraphic(t) {
2164
- Rt(this, t);
2172
+ Mt(this, t);
2165
2173
  }
2166
2174
  drawRect(t) {
2167
2175
  ie(this, t);
@@ -2393,7 +2401,7 @@ class pe {
2393
2401
  function de(n) {
2394
2402
  return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof g || n instanceof m);
2395
2403
  }
2396
- class P {
2404
+ class N {
2397
2405
  static float(t, e) {
2398
2406
  return Math.random() * (e - t) + t;
2399
2407
  }
@@ -2404,18 +2412,18 @@ class P {
2404
2412
  return Math.random() * Math.PI * 2;
2405
2413
  }
2406
2414
  static vector(t, e, r, i) {
2407
- return new g(P.float(t, e), P.float(r, i));
2415
+ return new g(N.float(t, e), N.float(r, i));
2408
2416
  }
2409
2417
  static randomColor(t, e) {
2410
2418
  return new m(
2411
- P.float(t.r, e.r),
2412
- P.float(t.g, e.g),
2413
- P.float(t.b, e.b),
2414
- P.float(t.a, e.a)
2419
+ N.float(t.r, e.r),
2420
+ N.float(t.g, e.g),
2421
+ N.float(t.b, e.b),
2422
+ N.float(t.a, e.a)
2415
2423
  );
2416
2424
  }
2417
2425
  static pick(t) {
2418
- return t[P.int(0, t.length - 1)];
2426
+ return t[N.int(0, t.length - 1)];
2419
2427
  }
2420
2428
  static pickWeight(t) {
2421
2429
  if (!t || t.length === 0) return null;
@@ -2431,11 +2439,11 @@ class P {
2431
2439
  if (Array.isArray(t)) {
2432
2440
  const [r, i] = t;
2433
2441
  if (typeof r == "number")
2434
- return P.float(r, i);
2442
+ return N.float(r, i);
2435
2443
  if (r instanceof g)
2436
- return P.vector(r.x, i.x, r.y, i.y);
2444
+ return N.vector(r.x, i.x, r.y, i.y);
2437
2445
  if (r instanceof m)
2438
- return P.randomColor(r, i);
2446
+ return N.randomColor(r, i);
2439
2447
  }
2440
2448
  return typeof t == "number" ? t : t.clone();
2441
2449
  }
@@ -2449,9 +2457,9 @@ class j {
2449
2457
  if (!Number.isInteger(t) || t <= 0)
2450
2458
  throw new RangeError("ParticleAttributeStore size must be a positive integer");
2451
2459
  this.components = Array.from({ length: t }, () => ({
2452
- value: new S(A.Float32),
2453
- delta: new S(A.Float32),
2454
- damping: new S(A.Float32)
2460
+ value: new b(A.Float32),
2461
+ delta: new b(A.Float32),
2462
+ damping: new b(A.Float32)
2455
2463
  }));
2456
2464
  }
2457
2465
  getArrayBuffer() {
@@ -2484,7 +2492,7 @@ class j {
2484
2492
  }
2485
2493
  }
2486
2494
  resolveComponent(t, e, r) {
2487
- return t === void 0 ? r : Array.isArray(t) ? P.float(
2495
+ return t === void 0 ? r : Array.isArray(t) ? N.float(
2488
2496
  this.getComponent(t[0], e),
2489
2497
  this.getComponent(t[1], e)
2490
2498
  ) : this.getComponent(t, e);
@@ -2508,13 +2516,13 @@ class wt {
2508
2516
  emitTimeCounter = 0;
2509
2517
  localSpace = vt;
2510
2518
  rapid;
2511
- x = new S(A.Float32);
2512
- y = new S(A.Float32);
2513
- scaleX = new S(A.Float32);
2514
- scaleY = new S(A.Float32);
2515
- rotation = new S(A.Float32);
2516
- color = new S(A.Uint32);
2517
- remainingLife = new S(A.Float32);
2519
+ x = new b(A.Float32);
2520
+ y = new b(A.Float32);
2521
+ scaleX = new b(A.Float32);
2522
+ scaleY = new b(A.Float32);
2523
+ rotation = new b(A.Float32);
2524
+ color = new b(A.Uint32);
2525
+ remainingLife = new b(A.Float32);
2518
2526
  animations = {
2519
2527
  speed: new j(),
2520
2528
  rotation: new j(),
@@ -2567,7 +2575,7 @@ class wt {
2567
2575
  this.createParticle();
2568
2576
  }
2569
2577
  createParticle() {
2570
- const t = P.scalarOrRange(this.options.life, 1);
2578
+ const t = N.scalarOrRange(this.options.life, 1);
2571
2579
  this.remainingLife.push(t);
2572
2580
  let e = 0, r = 0;
2573
2581
  switch (this.options.emitShape) {
@@ -2610,7 +2618,7 @@ class wt {
2610
2618
  r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
2611
2619
  }
2612
2620
  const e = this.updateParticle(t);
2613
- this.count -= e.length, S.removeAtIndices(e, this.getAllArrayBuffer());
2621
+ this.count -= e.length, b.removeAtIndices(e, this.getAllArrayBuffer());
2614
2622
  }
2615
2623
  updateParticle(t) {
2616
2624
  const e = [], r = this.animations;
@@ -2749,13 +2757,13 @@ class ve {
2749
2757
  i.withMask(() => {
2750
2758
  i.startMaskGraphic(i.gl.TRIANGLES);
2751
2759
  for (let c = 0; c < h.length; c++) {
2752
- const u = h[c], l = h[(c + 1) % h.length], f = u.subtract(a).normalized(), d = l.subtract(a).normalized(), x = Math.max(-0.999, Math.min(1, f.dot(d))), p = Math.sqrt((1 + x) * 0.5), v = o / p, y = a.add(f.multiply(v)), E = a.add(d.multiply(v));
2753
- i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(l.x, l.y), i.addGraphicVertex(E.x, E.y), i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(E.x, E.y), i.addGraphicVertex(y.x, y.y);
2760
+ const u = h[c], l = h[(c + 1) % h.length], f = u.subtract(a).normalized(), d = l.subtract(a).normalized(), x = Math.max(-0.999, Math.min(1, f.dot(d))), p = Math.sqrt((1 + x) * 0.5), y = o / p, v = a.add(f.multiply(y)), E = a.add(d.multiply(y));
2761
+ i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(l.x, l.y), i.addGraphicVertex(E.x, E.y), i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(E.x, E.y), i.addGraphicVertex(v.x, v.y);
2754
2762
  }
2755
2763
  i.endGraphic();
2756
2764
  }, () => {
2757
2765
  i.drawSprite({ texture: t });
2758
- }, Mt.NOT_EQUAL);
2766
+ }, Rt.NOT_EQUAL);
2759
2767
  }), this.rt;
2760
2768
  }
2761
2769
  setupLight(t) {
@@ -2782,7 +2790,7 @@ class ve {
2782
2790
  }
2783
2791
  }
2784
2792
  export {
2785
- G as BaseTexture,
2793
+ X as BaseTexture,
2786
2794
  ue as BlendMode,
2787
2795
  le as CanvasScaleMode,
2788
2796
  m as Color,
@@ -2792,20 +2800,20 @@ export {
2792
2800
  ge as LightShader,
2793
2801
  jt as LineTextureMode,
2794
2802
  J as MAX_LIGHTS,
2795
- Mt as MaskType,
2803
+ Rt as MaskType,
2796
2804
  wt as ParticleEmitter,
2797
2805
  fe as ParticleShape,
2798
2806
  pe as Rapid,
2799
2807
  Ut as RenderTexture,
2800
2808
  _t as TextTexture,
2801
- N as Texture,
2809
+ D as Texture,
2802
2810
  tt as TextureFilterMode,
2803
2811
  bt as TextureManager,
2804
2812
  q as TextureWrapMode,
2805
2813
  g as Vec2,
2806
- Yt as composeProjectionWithAffine,
2814
+ zt as composeProjectionWithAffine,
2807
2815
  se as drawCircle,
2808
- Rt as drawGraphic,
2816
+ Mt as drawGraphic,
2809
2817
  ee as drawLine,
2810
2818
  re as drawMaskImage,
2811
2819
  te as drawParticles,
@@ -1,5 +1,5 @@
1
- (function(v,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(v=typeof globalThis<"u"?globalThis:v||self,f(v.RapidRender={}))})(this,(function(v){"use strict";class f{_r;_g;_b;_a;uint32;premultipliedUint32;static clampByte(t){return t<=0?0:t>=255?255:Math.round(t)}constructor(t,e,r,i=255){this._r=t,this._g=e,this._b=r,this._a=i,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=f.clampByte(this._a),e=f.clampByte(this._r*t/255),r=f.clampByte(this._g*t/255),i=f.clampByte(this._b*t/255);this.premultipliedUint32=(t<<24|i<<16|r<<8|e)>>>0}reset(){this._r=0,this._g=0,this._b=0,this._a=255,this.updateUint()}setRGBA(t,e,r,i){this._r=t,this._g=e,this._b=r,this._a=i,this.updateUint()}setHSL(t,e,r){t=(t%360+360)%360,e=Math.max(0,Math.min(100,e))/100,r=Math.max(0,Math.min(100,r))/100;const i=(1-Math.abs(2*r-1))*e,s=i*(1-Math.abs(t/60%2-1)),a=r-i/2;let h=0,o=0,c=0;return t<60?[h,o,c]=[i,s,0]:t<120?[h,o,c]=[s,i,0]:t<180?[h,o,c]=[0,i,s]:t<240?[h,o,c]=[0,s,i]:t<300?[h,o,c]=[s,0,i]:[h,o,c]=[i,0,s],this.setRGBA((h+a)*255,(o+a)*255,(c+a)*255,255),this}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new f(this._r,this._g,this._b,this._a)}toHexString(t=!0){const e=this.r.toString(16).padStart(2,"0"),r=this.g.toString(16).padStart(2,"0"),i=this.b.toString(16).padStart(2,"0"),s=this.a.toString(16).padStart(2,"0");return`#${e}${r}${i}${t?s:""}`}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}static FromHSL(t,e,r){return new f(0,0,0).setHSL(t,e,r)}static FromRGB(t,e,r){return new f(t,e,r)}static fromNorm(t,e,r,i=1){return new f(Math.round(t*255),Math.round(e*255),Math.round(r*255),Math.round(i*255))}static packColor(t,e,r,i,s){const a=f.clampByte(i),h=s?a/255:1,o=f.clampByte(t*h),c=f.clampByte(e*h),u=f.clampByte(r*h);return(a<<24|u<<16|c<<8|o)>>>0}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);let s=255;return t.length>=8&&(s=parseInt(t.slice(6,8),16)),new f(e,r,i,s)}add(t){return new f(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 f(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)}divide(t){return t instanceof f?new f(this.r/t.r,this.g/t.g,this.b/t.b,this.a/t.a):new f(this.r/t,this.g/t,this.b/t,this.a/t)}multiply(t){return t instanceof f?new f(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a):new f(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)),this.updateUint()}static Red=new f(255,0,0,255);static Green=new f(0,255,0,255);static Blue=new f(0,0,255,255);static Yellow=new f(255,255,0,255);static Purple=new f(128,0,128,255);static Orange=new f(255,165,0,255);static Pink=new f(255,192,203,255);static Gray=new f(128,128,128,255);static Brown=new f(139,69,19,255);static Cyan=new f(0,255,255,255);static Magenta=new f(255,0,255,255);static Lime=new f(192,255,0,255);static White=new f(255,255,255,255);static Black=new f(0,0,0,255);static Transparent=new f(0,0,0,0)}var $=(n=>(n[n.LINEAR=0]="LINEAR",n[n.NEAREST=1]="NEAREST",n))($||{}),X=(n=>(n[n.REPEAT=0]="REPEAT",n[n.CLAMP=1]="CLAMP",n[n.MIRRORED_REPEAT=2]="MIRRORED_REPEAT",n))(X||{});class pt{render;cache=new Map;constructor(t){this.render=t}async load(t,e){let r=this.cache.get(t);if(r)return new N(r);try{const i=await this._fetchImage(t);return r=B.fromSource(this.render,i,e),r.uid=t,this.cache.set(t,r),new N(r)}catch(i){throw console.error(`[TextureManager] Failed to load: ${t}`,i),i}}create(t,e){if(e?.key&&this.cache.has(e.key))return new N(this.cache.get(e.key));const r=B.fromSource(this.render,t,e);return e?.key&&(r.uid=e.key,this.cache.set(e.key,r)),new N(r)}createRenderTexture(t){return new vt(this.render,t)}createTextTexture(t){return new yt(this.render,t)}destroy(t,e=!1){let r,i;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))}destroyAll(){for(const t of this.cache.values())t.destroy(this.render.gl);this.cache.clear()}_fetchImage(t){return new Promise((e,r)=>{const i=new Image;i.crossOrigin="anonymous",i.onload=()=>e(i),i.onerror=()=>r(new Error(`Failed to load image resource: ${t}`)),i.src=t})}}class B{glTexture=null;width;height;uid;refCount=0;constructor(t,e,r){this.glTexture=t,this.width=e,this.height=r}static fromSource(t,e,r={}){const i=et(t,e,r);return new B(i,e.width,e.height)}updateSource(t,e,r={}){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),r.textureFilter!==void 0&&at(t,r.textureFilter),r.wrap!==void 0&&nt(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))}setFilterMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),at(t,e),t.bindTexture(t.TEXTURE_2D,null))}setWrapMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),nt(t,e),t.bindTexture(t.TEXTURE_2D,null))}destroy(t){this.glTexture&&(t.deleteTexture(this.glTexture),this.glTexture=null)}}class N{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}get height(){return this.isRotated?this.rawWidth:this.rawHeight}_px=0;_py=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,r,i){return this.base?(this._px=t,this._py=e,this.isAtlas=t!==0||e!==0||r!==this.base.width||i!==this.base.height,this.uvX=t/this.base.width,this.uvY=e/this.base.height,this.uvW=this.uvX+r/this.base.width,this.uvH=this.uvY+i/this.base.height,this.rawWidth=r*this.scale,this.rawHeight=i*this.scale,this):this}getSubTexture(t,e,r,i){if(!this.base)return new N;const s=this.clone(),a=this._px,h=this._py;return s.setRegion(a+t,h+e,r,i),s}clone(t){const e=t??new N(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}splitGrid(t,e,r,i,s=0){if(!this.base)return[];const a=[],h=this.rawWidth,o=this.rawHeight,c=Math.max(0,s),u=t+c,l=e+c,m=r??Math.floor((h+c)/u),d=i??Math.floor((o+c)/l);for(let x=0;x<d;x++)for(let p=0;p<m;p++)a.push(this.getSubTexture(p*u,x*l,t,e));return a}static fromImageSource(t,e,r={}){const i=et(t,e,r);return new N(new B(i,e.width,e.height))}destroy(){this.base&&(this.base.refCount--,this.base=void 0),this.glTexture=null}}class vt extends N{framebuffer;renderbuffer;gl;clearColor;_allocW=0;_allocH=0;constructor(t,e){super(),this.gl=t.gl,this.clearColor=e.clearColor??f.Black;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});if(this.setBase(new B(a,r,i)),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(r,i,!0)}resize(t,e,r=!1){t=Math.max(Math.round(t),1),e=Math.max(Math.round(e),1);const i=this.rawWidth===t&&this.rawHeight===e;if(!r&&i)return;const s=this.gl;(r||t>this._allocW||e>this._allocH)&&this.base&&(this._allocW=Math.max(this._allocW,t),this._allocH=Math.max(this._allocH,e),this.base.width=this._allocW,this.base.height=this._allocH,s.bindTexture(s.TEXTURE_2D,this.base.glTexture),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this._allocW,this._allocH,0,s.RGBA,s.UNSIGNED_BYTE,null),s.bindRenderbuffer(s.RENDERBUFFER,this.renderbuffer),s.renderbufferStorage(s.RENDERBUFFER,s.STENCIL_INDEX8,this._allocW,this._allocH),s.bindFramebuffer(s.FRAMEBUFFER,this.framebuffer),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.base.glTexture,0),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.STENCIL_ATTACHMENT,s.RENDERBUFFER,this.renderbuffer),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindRenderbuffer(s.RENDERBUFFER,null),s.bindTexture(s.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,r=t??this.clearColor;r&&(r.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,r=this.rawWidth,i=this.rawHeight){if(!this.framebuffer)return new Uint8Array(0);const s=Math.floor(t),a=Math.floor(e),h=Math.floor(r),o=Math.floor(i);if(h<=0||o<=0)return new Uint8Array(0);if(s<0||a<0||s>=this.rawWidth||a>=this.rawHeight)return new Uint8Array(0);const c=Math.min(h,this.rawWidth-s),u=Math.min(o,this.rawHeight-a),l=this.gl,m=l.getParameter(l.FRAMEBUFFER_BINDING);l.bindFramebuffer(l.FRAMEBUFFER,this.framebuffer);const d=new Uint8Array(c*u*4);return l.readPixels(s,a,c,u,l.RGBA,l.UNSIGNED_BYTE,d),l.bindFramebuffer(l.FRAMEBUFFER,m),d}GetColorAt(t,e){const r=this.GetPixels(t,e,1,1);return r.length<4?new f(0,0,0,0):new f(r[0],r[1],r[2],r[3])}destroy(){super.destroy(),this.framebuffer&&this.gl.deleteFramebuffer(this.framebuffer),this.renderbuffer&&this.gl.deleteRenderbuffer(this.renderbuffer),this.base?.destroy(this.gl)}}const zt={fontFamily:"Arial",fontSize:24,fontWeight:"normal",fill:"#000000",strokeThickness:0,align:"left",lineHeight:1};class yt extends N{canvas;ctx;render;_text;_style;options;flipY=!0;constructor(t,e){super(),this.render=t,this._style={...zt,...e},this._text=e?.text??"",this.options={premultipliedAlpha:t.premultipliedAlpha,...e},this.scale=1/t.dpr,this.canvas=document.createElement("canvas");const r=this.canvas.getContext("2d",{willReadFrequently:!0});if(!r)throw new Error("Failed to get 2d context for TextTexture");this.ctx=r,this.canvas.width=1,this.canvas.height=1;const i=et(t,this.canvas,this.options);this.setBase(new B(i,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":return t/2;case"right":return t;default:return e}}update(){const t=this.ctx,e=this.style,r=e.fontSize,i=e.fontWeight,s=e.fontFamily,a=e.lineHeight,h=`${i} ${r}px ${s}`,o=this.render.dpr;t.font=h,t.textBaseline="top";const c=this._text.split(`
2
- `);let u=0,l=0;const x=t.measureText(c[0]||"M").fontBoundingBoxDescent;for(const U of c){const w=t.measureText(U);w.width>u&&(u=w.width),l+=x*a}l-=x*(a-1);const p=this._style.strokeThickness||0,y=Math.ceil(u+p*2)||1,T=Math.ceil(l+p*2)||1,R=Math.ceil(y*o),A=Math.ceil(T*o);(this.canvas.width!==R||this.canvas.height!==A)&&(this.canvas.width=R,this.canvas.height=A),t.setTransform(o,0,0,o,0,0),t.clearRect(0,0,y,T),t.font=h,t.textBaseline="top",t.textAlign=this._style.align;const L=this.updateOffset(y,p),P=e.strokeThickness,O=P>0;O&&(t.lineWidth=P,t.strokeStyle=e.stroke,t.lineJoin="round"),e.fill&&(t.fillStyle=e.fill);let F=p;for(const U of c)O&&t.strokeText(U,L,F),e.fill&&t.fillText(U,L,F),F+=x*a;this.base?.updateSource(this.render.gl,this.canvas,this.options),this.setRegion(0,0,R,A)}}const Yt=(n,t=!1,e=!0)=>{const r=n.getContext("webgl2",{stencil:!0,antialias:t,premultipliedAlpha:e});if(!r)throw new Error("WebGL2 is not supported in this browser.");return r},Tt=(n,t,e)=>{const r=n.createShader(e);if(!r)throw new Error("Unable to create webgl shader");if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS)){const s=n.getShaderInfoLog(r);throw console.error("Shader compilation failed:",s),new Error("Unable to compile shader: "+s+t)}return r},$t=(n,t,e)=>{var r=n.createProgram(),i=Tt(n,t,35633),s=Tt(n,e,35632);if(!r)throw new Error("Unable to create program shader");if(n.attachShader(r,i),n.attachShader(r,s),n.linkProgram(r),!n.getProgramParameter(r,n.LINK_STATUS)){const h=n.getProgramInfoLog(r);throw new Error("Unable to link shader program: "+h)}return r};function nt(n,t){const e={[X.CLAMP]:n.CLAMP_TO_EDGE,[X.REPEAT]:n.REPEAT,[X.MIRRORED_REPEAT]:n.MIRRORED_REPEAT}[t]||n.CLAMP_TO_EDGE;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,e)}function at(n,t){const e={[$.LINEAR]:n.LINEAR,[$.NEAREST]:n.NEAREST}[t]??n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,e)}function et(n,t,e){const r=n.gl,i=r.createTexture();if(!i)throw new Error("Unable to create WebGL texture");if(r.bindTexture(r.TEXTURE_2D,i),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,0),r.pixelStorei(r.UNPACK_ALIGNMENT,1),nt(r,e.wrap??X.CLAMP),at(r,e.textureFilter??n.textureFilter),e.onlySize){const s=t;r.texImage2D(r.TEXTURE_2D,0,r.RGBA,s.width,s.height,0,r.RGBA,r.UNSIGNED_BYTE,null)}else{const s=e.premultipliedAlpha??n.premultipliedAlpha;s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)}return r.bindTexture(r.TEXTURE_2D,null),i}function j(n,t,e="vTextureId",r="uv",i="return"){if(n.includes("%TEXTURE_NUM%")&&(n=n.replaceAll("%TEXTURE_NUM%",t.toString())),n.includes("%GET_COLOR%")){let s="";for(let a=0;a<t;a++)a==0?s+=`if(${e} == ${a})`:a==t-1?s+="else":s+=`else if(${e} == ${a})`,s+=`{${i} texture(uTextures[${a}], ${r});}`;n=n.replaceAll("%GET_COLOR%",s)}return n}const jt=5126,ht=5121;function Kt(n,t,e){n.vertexAttribDivisor(t,e)}function Mt(n,t,e,r,i){n.drawArraysInstanced(t,e,r,i)}let qt=0;class ot{program;attributeLoc={};uniformLoc={};isCustom=!1;padding=0;uniformType={};uniformIsArray={};gl;shaderId=qt++;vao;constructor(t,e,r,i){this.gl=t,this.program=$t(t,e,r),this.parseShader(e),this.parseShader(r),this.vao=t.createVertexArray(),i&&this.setAttributes(i)}use(){this.gl.useProgram(this.program)}bindVAO(){this.gl.bindVertexArray(this.vao)}unbindVAO(){this.gl.bindVertexArray(null)}setUniform(t,e){const r=this.uniformLoc[t];if(r===void 0)return;const i=this.uniformType[t],s=this.uniformIsArray[t];Qt(this.gl,r,i,e,s)}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 r=this.gl;r.vertexAttribPointer(e,t.size,t.type??jt,t.normalized??!1,t.stride,t.offset??0),r.enableVertexAttribArray(e),Kt(r,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,r=t.match(/(?:in|attribute)\s+\w+\s+\w+/g);if(r)for(const s of r){const h=s.split(/\s+/)[2],o=e.getAttribLocation(this.program,h);o!==-1&&(this.attributeLoc[h]=o)}const i=t.matchAll(/uniform\s+(?:(?:lowp|mediump|highp)\s+)?(\w+)\s+(\w+)(\s*\[\s*\d+\s*\])?/g);for(const s of i){const a=s[1],h=s[2],o=e.getUniformLocation(this.program,h);o!==null&&(this.uniformLoc[h]=o,this.uniformType[h]=a,this.uniformIsArray[h]=s[3]!==void 0)}}}function Qt(n,t,e,r,i=!1){switch(e){case"float":return i?n.uniform1fv(t,r):n.uniform1f(t,r);case"int":case"bool":case"sampler2D":case"samplerCube":return i?n.uniform1iv(t,r):n.uniform1i(t,r);case"vec2":return n.uniform2fv(t,r);case"vec3":return n.uniform3fv(t,r);case"vec4":return n.uniform4fv(t,r);case"ivec2":case"bvec2":return n.uniform2iv(t,r);case"ivec3":case"bvec3":return n.uniform3iv(t,r);case"ivec4":case"bvec4":return n.uniform4iv(t,r);case"mat2":return n.uniformMatrix2fv(t,!1,r);case"mat3":return n.uniformMatrix3fv(t,!1,r);case"mat4":return n.uniformMatrix4fv(t,!1,r);case"mat3x2":return n.uniformMatrix3x2fv(t,!1,r);default:return Zt(n,t,r)}}function Zt(n,t,e){if(typeof e=="number")return n.uniform1f(t,e);const r=e;switch(r.length){case 2:return n.uniform2fv(t,r);case 3:return n.uniform3fv(t,r);case 4:return n.uniform4fv(t,r);case 9:return n.uniformMatrix3fv(t,!1,r);case 16:return n.uniformMatrix4fv(t,!1,r);default:return n.uniform1fv(t,r)}}class rt{vs;fs;glshader=new Map;uniforms={};uniformDirty=new Set;uniformTextures={};uniformArrayTexture={};usedTextureUnitNum=0;padding=0;rapid;prefix=[];constructor(t,e="",r="",i=0,s){this.vs=e,this.fs=r,this.rapid=t,this.uniforms=s??{},this.usedTextureUnitNum=i}setUniforms(t){this.rapid.flush();const e={},r={},i={};for(const[s,a]of Object.entries(t))a instanceof WebGLTexture?r[s]=a:Array.isArray(a)&&a[0]instanceof WebGLTexture?i[s]=a:e[s]=a;Object.assign(this.uniforms,e),Object.assign(this.uniformTextures,r),Object.assign(this.uniformArrayTexture,i);for(const s of this.glshader.keys())this.uniformDirty.add(s)}setPadding(t){this.padding=t;for(const e of this.glshader.values())e.padding=t;return this}applyUniform(t,e){const r=this.glshader.get(t);r&&(Object.keys(e).length>0&&r.setUniforms(e),this.uniformDirty.has(t)&&(r.setUniforms(this.uniforms),this.uniformDirty.delete(t)))}replaceCustomCode(t,e){return t=t.replace("// CUSTOM_CODE",e+"// CUSTOM_CODE"),t}getGLShader(t,e,r,i){if(this.glshader.has(e))return this.glshader.get(e);if(i==null||r==null)return console.warn("CustomGlShader: missing base shader for "+e),null;const s=this.prefix.length==0?[""]:this.prefix;r=r.replace("// CUSTOM_CODE_CALL",s.map(h=>h+"vertex(position, vRegion);").join("")),r=this.replaceCustomCode(r,this.vs),i=i.replace("// CUSTOM_CODE_CALL",s.map(h=>h+"fragment(fragColor, vRegion);").join("")),i=this.replaceCustomCode(i,this.fs);const a=t.createShader(r,i);return a.isCustom=!0,a.padding=this.padding,this.glshader.set(e,a),this.uniformDirty.add(e),a}destroy(){this.glshader.forEach(t=>t.destroy())}}class Rt{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=[];extraTextureUnit=0;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,r=0){for(let i=0;i<this.usedTextures.length;i++){const s=i*2;if(this.usedTextures[i]===t&&this.usedTexturePadding[s]===e&&this.usedTexturePadding[s+1]===r)return i}return-1}useTexture(t,e=0,r=0){const i=this.findTextureUnit(t,e,r);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}getMaxTexutreUnit(t){return this.rapid.maxTextureUnits-this.extraTextureUnit-(t?.usedTextureUnitNum??0)}createShader(t,e){const r=this.getMaxTexutreUnit();return e=j(e,r),t=j(t,r),new ot(this.gl,t,e)}createCustomShader(t){const e=this.getMaxTexutreUnit(t),r=j(this.fs,e),i=j(this.vs,e);return t.getGLShader(this,this.KEY,i,r)}getCustomShader(t){if(!t)return this.defaultShader;if(t instanceof rt){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 rt?(this.customShader=t,this.customShaderUsedTextureNum=t.usedTextureUnitNum):(this.customShader=null,this.customShaderUsedTextureNum=0),this.isDefaultShader=this.currentShader==this.defaultShader,this.currentShader.use(),this.currentShader.setUniform("u_projection",this.rapid.projection)}exit(){this.hasPendingContent()&&this.flush(),this.gl.bindVertexArray(null)}flush(){this.render(),this.resetRender()}render(){this.prepareRender()}prepareRender(){const t=this.currentShader;if(t.use(),this.customShader){const r=this.customShader,i={};for(const[s,a]of Object.entries(r.uniformTextures))i[s]=this.useTexture(a);for(const[s,a]of Object.entries(r.uniformArrayTexture))i[s]=a.map(h=>this.useTexture(h));this.customShader.applyUniform(this.KEY,i)}const e=this.gl;for(let r=0;r<this.usedTextures.length;r++)e.activeTexture(e.TEXTURE0+r),e.bindTexture(e.TEXTURE_2D,this.usedTextures[r]);t.setUniform("uTextures",Int32Array.from({length:this.usedTextures.length},(r,i)=>i)),t.setUniform("uPadding",Float32Array.from({length:this.usedTexturePadding.length},(r,i)=>this.usedTexturePadding[i]))}resetRender(){const t=this.gl;for(let e=0;e<this.usedTextures.length;e++)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,null);this.usedTextures.length=0,this.usedTexturePadding.length=0}hasPendingContent(){return!1}}var S=(n=>(n[n.Float32=0]="Float32",n[n.Uint32=1]="Uint32",n[n.Uint16=2]="Uint16",n))(S||{});class b{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}static removeAtIndices(t,e){const r=Math.max(...e.map(h=>h.usedElemNum)),i=[...new Set(t)].filter(h=>h>=0&&h<r).sort((h,o)=>h-o);if(i.length===0)return 0;let s=0,a=0;for(let h=0;h<r;h++){if(a<i.length&&h===i[a]){a++;continue}if(s!==h)for(const o of e)o.typedArray[s]=o.typedArray[h];s++}for(const h of e)h.usedElemNum=s;return r-s}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}}class ct extends b{buffer;gl;dirty=!0;type;webglBufferSize=0;usage;constructor(t,e,r=t.ARRAY_BUFFER,i=t.DYNAMIC_DRAW){super(e),this.gl=t,this.buffer=t.createBuffer(),this.type=r,this.usage=i}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}}}const it=`#version 300 es\r
1
+ (function(p,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(p=typeof globalThis<"u"?globalThis:p||self,f(p.RapidRender={}))})(this,(function(p){"use strict";class f{_r;_g;_b;_a;uint32;premultipliedUint32;static clampByte(t){return t<=0?0:t>=255?255:Math.round(t)}constructor(t,e,r,i=255){this._r=t,this._g=e,this._b=r,this._a=i,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=f.clampByte(this._a),e=f.clampByte(this._r*t/255),r=f.clampByte(this._g*t/255),i=f.clampByte(this._b*t/255);this.premultipliedUint32=(t<<24|i<<16|r<<8|e)>>>0}reset(){this._r=0,this._g=0,this._b=0,this._a=255,this.updateUint()}setRGBA(t,e,r,i){this._r=t,this._g=e,this._b=r,this._a=i,this.updateUint()}setHSL(t,e,r){t=(t%360+360)%360,e=Math.max(0,Math.min(100,e))/100,r=Math.max(0,Math.min(100,r))/100;const i=(1-Math.abs(2*r-1))*e,s=i*(1-Math.abs(t/60%2-1)),a=r-i/2;let h=0,o=0,c=0;return t<60?[h,o,c]=[i,s,0]:t<120?[h,o,c]=[s,i,0]:t<180?[h,o,c]=[0,i,s]:t<240?[h,o,c]=[0,s,i]:t<300?[h,o,c]=[s,0,i]:[h,o,c]=[i,0,s],this.setRGBA((h+a)*255,(o+a)*255,(c+a)*255,255),this}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new f(this._r,this._g,this._b,this._a)}toHexString(t=!0){const e=this.r.toString(16).padStart(2,"0"),r=this.g.toString(16).padStart(2,"0"),i=this.b.toString(16).padStart(2,"0"),s=this.a.toString(16).padStart(2,"0");return`#${e}${r}${i}${t?s:""}`}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}static FromHSL(t,e,r){return new f(0,0,0).setHSL(t,e,r)}static FromRGB(t,e,r){return new f(t,e,r)}static fromNorm(t,e,r,i=1){return new f(Math.round(t*255),Math.round(e*255),Math.round(r*255),Math.round(i*255))}static packColor(t,e,r,i,s){const a=f.clampByte(i),h=s?a/255:1,o=f.clampByte(t*h),c=f.clampByte(e*h),u=f.clampByte(r*h);return(a<<24|u<<16|c<<8|o)>>>0}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);let s=255;return t.length>=8&&(s=parseInt(t.slice(6,8),16)),new f(e,r,i,s)}add(t){return new f(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 f(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)}divide(t){return t instanceof f?new f(this.r/t.r,this.g/t.g,this.b/t.b,this.a/t.a):new f(this.r/t,this.g/t,this.b/t,this.a/t)}multiply(t){return t instanceof f?new f(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a):new f(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)),this.updateUint()}static Red=new f(255,0,0,255);static Green=new f(0,255,0,255);static Blue=new f(0,0,255,255);static Yellow=new f(255,255,0,255);static Purple=new f(128,0,128,255);static Orange=new f(255,165,0,255);static Pink=new f(255,192,203,255);static Gray=new f(128,128,128,255);static Brown=new f(139,69,19,255);static Cyan=new f(0,255,255,255);static Magenta=new f(255,0,255,255);static Lime=new f(192,255,0,255);static White=new f(255,255,255,255);static Black=new f(0,0,0,255);static Transparent=new f(0,0,0,0)}var j=(n=>(n[n.LINEAR=0]="LINEAR",n[n.NEAREST=1]="NEAREST",n))(j||{}),z=(n=>(n[n.REPEAT=0]="REPEAT",n[n.CLAMP=1]="CLAMP",n[n.MIRRORED_REPEAT=2]="MIRRORED_REPEAT",n))(z||{});class pt{render;cache=new Map;constructor(t){this.render=t}async load(t,e){let r=this.cache.get(t);if(r)return new I(r);try{const i=await this._fetchImage(t);return r=V.fromSource(this.render,i,e),r.uid=t,this.cache.set(t,r),new I(r)}catch(i){throw console.error(`[TextureManager] Failed to load: ${t}`,i),i}}create(t,e){if(e?.key&&this.cache.has(e.key))return new I(this.cache.get(e.key));const r=V.fromSource(this.render,t,e);return e?.key&&(r.uid=e.key,this.cache.set(e.key,r)),new I(r)}createRenderTexture(t){return new vt(this.render,t)}createTextTexture(t){return new yt(this.render,t)}destroy(t,e=!1){let r,i;typeof t=="string"?(i=t,r=this.cache.get(i)):t instanceof I?(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))}destroyAll(){for(const t of this.cache.values())t.destroy(this.render.gl);this.cache.clear()}_fetchImage(t){return new Promise((e,r)=>{const i=new Image;i.crossOrigin="anonymous",i.onload=()=>e(i),i.onerror=()=>r(new Error(`Failed to load image resource: ${t}`)),i.src=t})}}class V{glTexture=null;width;height;uid;refCount=0;constructor(t,e,r){this.glTexture=t,this.width=e,this.height=r}static fromSource(t,e,r={}){const i=et(t,e,r);return new V(i,e.width,e.height)}updateSource(t,e,r={}){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),r.textureFilter!==void 0&&at(t,r.textureFilter),r.wrap!==void 0&&nt(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))}setFilterMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),at(t,e),t.bindTexture(t.TEXTURE_2D,null))}setWrapMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),nt(t,e),t.bindTexture(t.TEXTURE_2D,null))}destroy(t){this.glTexture&&(t.deleteTexture(this.glTexture),this.glTexture=null)}}class I{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}get height(){return this.isRotated?this.rawWidth:this.rawHeight}_px=0;_py=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,r,i){return this.base?(this._px=t,this._py=e,this.isAtlas=t!==0||e!==0||r!==this.base.width||i!==this.base.height,this.uvX=t/this.base.width,this.uvY=e/this.base.height,this.uvW=this.uvX+r/this.base.width,this.uvH=this.uvY+i/this.base.height,this.rawWidth=r*this.scale,this.rawHeight=i*this.scale,this):this}getSubTexture(t,e,r,i){if(!this.base)return new I;const s=this.clone(),a=this._px,h=this._py;return s.setRegion(a+t,h+e,r,i),s}clone(t){const e=t??new I(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}splitGrid(t,e,r,i,s=0){if(!this.base)return[];const a=[],h=this.rawWidth,o=this.rawHeight,c=Math.max(0,s),u=t+c,l=e+c,m=r??Math.floor((h+c)/u),d=i??Math.floor((o+c)/l);for(let x=0;x<d;x++)for(let v=0;v<m;v++)a.push(this.getSubTexture(v*u,x*l,t,e));return a}static fromImageSource(t,e,r={}){const i=et(t,e,r);return new I(new V(i,e.width,e.height))}destroy(){this.base&&(this.base.refCount--,this.base=void 0),this.glTexture=null}}class vt extends I{framebuffer;renderbuffer;gl;clearColor;_allocW=0;_allocH=0;constructor(t,e){super(),this.gl=t.gl,this.clearColor=e.clearColor??f.Black;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});if(this.setBase(new V(a,r,i)),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(r,i,!0)}resize(t,e,r=!1){t=Math.max(Math.round(t),1),e=Math.max(Math.round(e),1);const i=this.rawWidth===t&&this.rawHeight===e;if(!r&&i)return;const s=this.gl;(r||t>this._allocW||e>this._allocH)&&this.base&&(this._allocW=Math.max(this._allocW,t),this._allocH=Math.max(this._allocH,e),this.base.width=this._allocW,this.base.height=this._allocH,s.bindTexture(s.TEXTURE_2D,this.base.glTexture),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this._allocW,this._allocH,0,s.RGBA,s.UNSIGNED_BYTE,null),s.bindRenderbuffer(s.RENDERBUFFER,this.renderbuffer),s.renderbufferStorage(s.RENDERBUFFER,s.STENCIL_INDEX8,this._allocW,this._allocH),s.bindFramebuffer(s.FRAMEBUFFER,this.framebuffer),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.base.glTexture,0),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.STENCIL_ATTACHMENT,s.RENDERBUFFER,this.renderbuffer),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindRenderbuffer(s.RENDERBUFFER,null),s.bindTexture(s.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,r=t??this.clearColor;r&&(r.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,r=this.rawWidth,i=this.rawHeight){if(!this.framebuffer)return new Uint8Array(0);const s=Math.floor(t),a=Math.floor(e),h=Math.floor(r),o=Math.floor(i);if(h<=0||o<=0)return new Uint8Array(0);if(s<0||a<0||s>=this.rawWidth||a>=this.rawHeight)return new Uint8Array(0);const c=Math.min(h,this.rawWidth-s),u=Math.min(o,this.rawHeight-a),l=this.gl,m=l.getParameter(l.FRAMEBUFFER_BINDING);l.bindFramebuffer(l.FRAMEBUFFER,this.framebuffer);const d=new Uint8Array(c*u*4);return l.readPixels(s,a,c,u,l.RGBA,l.UNSIGNED_BYTE,d),l.bindFramebuffer(l.FRAMEBUFFER,m),d}GetColorAt(t,e){const r=this.GetPixels(t,e,1,1);return r.length<4?new f(0,0,0,0):new f(r[0],r[1],r[2],r[3])}destroy(){super.destroy(),this.framebuffer&&this.gl.deleteFramebuffer(this.framebuffer),this.renderbuffer&&this.gl.deleteRenderbuffer(this.renderbuffer),this.base?.destroy(this.gl)}}const Yt={fontFamily:"Arial",fontSize:24,fontWeight:"normal",fill:"#000000",strokeThickness:0,align:"left",lineHeight:1};class yt extends I{canvas;ctx;render;_text;_style;options;flipY=!0;constructor(t,e){super(),this.render=t,this._style={...Yt,...e},this._text=e?.text??"",this.options={premultipliedAlpha:t.premultipliedAlpha,...e},this.scale=1/t.dpr,this.canvas=document.createElement("canvas");const r=this.canvas.getContext("2d",{willReadFrequently:!0});if(!r)throw new Error("Failed to get 2d context for TextTexture");this.ctx=r,this.canvas.width=1,this.canvas.height=1;const i=et(t,this.canvas,this.options);this.setBase(new V(i,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":return t/2;case"right":return t-e;default:return e}}update(){const t=this.ctx,e=this.style,r=this.render.dpr,i=e.fontSize,s=e.fontWeight,a=e.fontFamily,h=e.lineHeight,o=`${s} ${i}px ${a}`,c=e.baseline??"middle",u=e.align??"left",l=e.strokeThickness??0,m=l>0,d=this._text.split(`
2
+ `),x="国g",v=d[0]||x;t.font=o,t.textBaseline="alphabetic",t.textAlign="left";let T=0,y=0,R=0;for(const B of d){const G=t.measureText(B||x);T=Math.max(T,B?G.width:0),y=Math.max(y,G.actualBoundingBoxAscent),R=Math.max(R,G.actualBoundingBoxDescent)}t.textBaseline="alphabetic";const U=t.measureText(v).fontBoundingBoxDescent;t.textBaseline=c;const L=t.measureText(v).fontBoundingBoxDescent,N=i*h,H=y+R+(d.length-1)*N,O=l/2+1,_=Math.max(1,Math.ceil(T+O*2)),w=Math.max(1,Math.ceil(H+O*2)),S=Math.ceil(_*r),F=Math.ceil(w*r);(this.canvas.width!==S||this.canvas.height!==F)&&(this.canvas.width=S,this.canvas.height=F),t.setTransform(r,0,0,r,0,0),t.clearRect(0,0,S/r,F/r),t.font=o,t.textBaseline="alphabetic",t.textAlign=u;const k=this.updateOffset(_,O);m&&(t.lineWidth=l,t.strokeStyle=e.stroke??"#000000",t.lineJoin="round"),e.fill&&(t.fillStyle=e.fill);let P=O+y;for(const B of d)m&&t.strokeText(B,k,P),e.fill&&t.fillText(B,k,P),P+=N;this.base?.updateSource(this.render.gl,this.canvas,this.options),this.setRegion(0,0,S,F);const D=U-L;this.offsetY=-O-y-D}}const zt=(n,t=!1,e=!0)=>{const r=n.getContext("webgl2",{stencil:!0,antialias:t,premultipliedAlpha:e});if(!r)throw new Error("WebGL2 is not supported in this browser.");return r},Tt=(n,t,e)=>{const r=n.createShader(e);if(!r)throw new Error("Unable to create webgl shader");if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS)){const s=n.getShaderInfoLog(r);throw console.error("Shader compilation failed:",s),new Error("Unable to compile shader: "+s+t)}return r},$t=(n,t,e)=>{var r=n.createProgram(),i=Tt(n,t,35633),s=Tt(n,e,35632);if(!r)throw new Error("Unable to create program shader");if(n.attachShader(r,i),n.attachShader(r,s),n.linkProgram(r),!n.getProgramParameter(r,n.LINK_STATUS)){const h=n.getProgramInfoLog(r);throw new Error("Unable to link shader program: "+h)}return r};function nt(n,t){const e={[z.CLAMP]:n.CLAMP_TO_EDGE,[z.REPEAT]:n.REPEAT,[z.MIRRORED_REPEAT]:n.MIRRORED_REPEAT}[t]||n.CLAMP_TO_EDGE;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,e)}function at(n,t){const e={[j.LINEAR]:n.LINEAR,[j.NEAREST]:n.NEAREST}[t]??n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,e)}function et(n,t,e){const r=n.gl,i=r.createTexture();if(!i)throw new Error("Unable to create WebGL texture");if(r.bindTexture(r.TEXTURE_2D,i),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,0),r.pixelStorei(r.UNPACK_ALIGNMENT,1),nt(r,e.wrap??z.CLAMP),at(r,e.textureFilter??n.textureFilter),e.onlySize){const s=t;r.texImage2D(r.TEXTURE_2D,0,r.RGBA,s.width,s.height,0,r.RGBA,r.UNSIGNED_BYTE,null)}else{const s=e.premultipliedAlpha??n.premultipliedAlpha;s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)}return r.bindTexture(r.TEXTURE_2D,null),i}function K(n,t,e="vTextureId",r="uv",i="return"){if(n.includes("%TEXTURE_NUM%")&&(n=n.replaceAll("%TEXTURE_NUM%",t.toString())),n.includes("%GET_COLOR%")){let s="";for(let a=0;a<t;a++)a==0?s+=`if(${e} == ${a})`:a==t-1?s+="else":s+=`else if(${e} == ${a})`,s+=`{${i} texture(uTextures[${a}], ${r});}`;n=n.replaceAll("%GET_COLOR%",s)}return n}const jt=5126,ht=5121;function Kt(n,t,e){n.vertexAttribDivisor(t,e)}function Mt(n,t,e,r,i){n.drawArraysInstanced(t,e,r,i)}let qt=0;class ot{program;attributeLoc={};uniformLoc={};isCustom=!1;padding=0;uniformType={};uniformIsArray={};gl;shaderId=qt++;vao;constructor(t,e,r,i){this.gl=t,this.program=$t(t,e,r),this.parseShader(e),this.parseShader(r),this.vao=t.createVertexArray(),i&&this.setAttributes(i)}use(){this.gl.useProgram(this.program)}bindVAO(){this.gl.bindVertexArray(this.vao)}unbindVAO(){this.gl.bindVertexArray(null)}setUniform(t,e){const r=this.uniformLoc[t];if(r===void 0)return;const i=this.uniformType[t],s=this.uniformIsArray[t];Qt(this.gl,r,i,e,s)}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 r=this.gl;r.vertexAttribPointer(e,t.size,t.type??jt,t.normalized??!1,t.stride,t.offset??0),r.enableVertexAttribArray(e),Kt(r,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,r=t.match(/(?:in|attribute)\s+\w+\s+\w+/g);if(r)for(const s of r){const h=s.split(/\s+/)[2],o=e.getAttribLocation(this.program,h);o!==-1&&(this.attributeLoc[h]=o)}const i=t.matchAll(/uniform\s+(?:(?:lowp|mediump|highp)\s+)?(\w+)\s+(\w+)(\s*\[\s*\d+\s*\])?/g);for(const s of i){const a=s[1],h=s[2],o=e.getUniformLocation(this.program,h);o!==null&&(this.uniformLoc[h]=o,this.uniformType[h]=a,this.uniformIsArray[h]=s[3]!==void 0)}}}function Qt(n,t,e,r,i=!1){switch(e){case"float":return i?n.uniform1fv(t,r):n.uniform1f(t,r);case"int":case"bool":case"sampler2D":case"samplerCube":return i?n.uniform1iv(t,r):n.uniform1i(t,r);case"vec2":return n.uniform2fv(t,r);case"vec3":return n.uniform3fv(t,r);case"vec4":return n.uniform4fv(t,r);case"ivec2":case"bvec2":return n.uniform2iv(t,r);case"ivec3":case"bvec3":return n.uniform3iv(t,r);case"ivec4":case"bvec4":return n.uniform4iv(t,r);case"mat2":return n.uniformMatrix2fv(t,!1,r);case"mat3":return n.uniformMatrix3fv(t,!1,r);case"mat4":return n.uniformMatrix4fv(t,!1,r);case"mat3x2":return n.uniformMatrix3x2fv(t,!1,r);default:return Zt(n,t,r)}}function Zt(n,t,e){if(typeof e=="number")return n.uniform1f(t,e);const r=e;switch(r.length){case 2:return n.uniform2fv(t,r);case 3:return n.uniform3fv(t,r);case 4:return n.uniform4fv(t,r);case 9:return n.uniformMatrix3fv(t,!1,r);case 16:return n.uniformMatrix4fv(t,!1,r);default:return n.uniform1fv(t,r)}}class rt{vs;fs;glshader=new Map;uniforms={};uniformDirty=new Set;uniformTextures={};uniformArrayTexture={};usedTextureUnitNum=0;padding=0;rapid;prefix=[];constructor(t,e="",r="",i=0,s){this.vs=e,this.fs=r,this.rapid=t,this.uniforms=s??{},this.usedTextureUnitNum=i}setUniforms(t){this.rapid.flush();const e={},r={},i={};for(const[s,a]of Object.entries(t))a instanceof WebGLTexture?r[s]=a:Array.isArray(a)&&a[0]instanceof WebGLTexture?i[s]=a:e[s]=a;Object.assign(this.uniforms,e),Object.assign(this.uniformTextures,r),Object.assign(this.uniformArrayTexture,i);for(const s of this.glshader.keys())this.uniformDirty.add(s)}setPadding(t){this.padding=t;for(const e of this.glshader.values())e.padding=t;return this}applyUniform(t,e){const r=this.glshader.get(t);r&&(Object.keys(e).length>0&&r.setUniforms(e),this.uniformDirty.has(t)&&(r.setUniforms(this.uniforms),this.uniformDirty.delete(t)))}replaceCustomCode(t,e){return t=t.replace("// CUSTOM_CODE",e+"// CUSTOM_CODE"),t}getGLShader(t,e,r,i){if(this.glshader.has(e))return this.glshader.get(e);if(i==null||r==null)return console.warn("CustomGlShader: missing base shader for "+e),null;const s=this.prefix.length==0?[""]:this.prefix;r=r.replace("// CUSTOM_CODE_CALL",s.map(h=>h+"vertex(position, vRegion);").join("")),r=this.replaceCustomCode(r,this.vs),i=i.replace("// CUSTOM_CODE_CALL",s.map(h=>h+"fragment(fragColor, vRegion);").join("")),i=this.replaceCustomCode(i,this.fs);const a=t.createShader(r,i);return a.isCustom=!0,a.padding=this.padding,this.glshader.set(e,a),this.uniformDirty.add(e),a}destroy(){this.glshader.forEach(t=>t.destroy())}}class Rt{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=[];extraTextureUnit=0;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,r=0){for(let i=0;i<this.usedTextures.length;i++){const s=i*2;if(this.usedTextures[i]===t&&this.usedTexturePadding[s]===e&&this.usedTexturePadding[s+1]===r)return i}return-1}useTexture(t,e=0,r=0){const i=this.findTextureUnit(t,e,r);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}getMaxTexutreUnit(t){return this.rapid.maxTextureUnits-this.extraTextureUnit-(t?.usedTextureUnitNum??0)}createShader(t,e){const r=this.getMaxTexutreUnit();return e=K(e,r),t=K(t,r),new ot(this.gl,t,e)}createCustomShader(t){const e=this.getMaxTexutreUnit(t),r=K(this.fs,e),i=K(this.vs,e);return t.getGLShader(this,this.KEY,i,r)}getCustomShader(t){if(!t)return this.defaultShader;if(t instanceof rt){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 rt?(this.customShader=t,this.customShaderUsedTextureNum=t.usedTextureUnitNum):(this.customShader=null,this.customShaderUsedTextureNum=0),this.isDefaultShader=this.currentShader==this.defaultShader,this.currentShader.use(),this.currentShader.setUniform("u_projection",this.rapid.projection)}exit(){this.hasPendingContent()&&this.flush(),this.gl.bindVertexArray(null)}flush(){this.render(),this.resetRender()}render(){this.prepareRender()}prepareRender(){const t=this.currentShader;if(t.use(),this.customShader){const r=this.customShader,i={};for(const[s,a]of Object.entries(r.uniformTextures))i[s]=this.useTexture(a);for(const[s,a]of Object.entries(r.uniformArrayTexture))i[s]=a.map(h=>this.useTexture(h));this.customShader.applyUniform(this.KEY,i)}const e=this.gl;for(let r=0;r<this.usedTextures.length;r++)e.activeTexture(e.TEXTURE0+r),e.bindTexture(e.TEXTURE_2D,this.usedTextures[r]);t.setUniform("uTextures",Int32Array.from({length:this.usedTextures.length},(r,i)=>i)),t.setUniform("uPadding",Float32Array.from({length:this.usedTexturePadding.length},(r,i)=>this.usedTexturePadding[i]))}resetRender(){const t=this.gl;for(let e=0;e<this.usedTextures.length;e++)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,null);this.usedTextures.length=0,this.usedTexturePadding.length=0}hasPendingContent(){return!1}}var A=(n=>(n[n.Float32=0]="Float32",n[n.Uint32=1]="Uint32",n[n.Uint16=2]="Uint16",n))(A||{});class b{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}static removeAtIndices(t,e){const r=Math.max(...e.map(h=>h.usedElemNum)),i=[...new Set(t)].filter(h=>h>=0&&h<r).sort((h,o)=>h-o);if(i.length===0)return 0;let s=0,a=0;for(let h=0;h<r;h++){if(a<i.length&&h===i[a]){a++;continue}if(s!==h)for(const o of e)o.typedArray[s]=o.typedArray[h];s++}for(const h of e)h.usedElemNum=s;return r-s}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}}class ct extends b{buffer;gl;dirty=!0;type;webglBufferSize=0;usage;constructor(t,e,r=t.ARRAY_BUFFER,i=t.DYNAMIC_DRAW){super(e),this.gl=t,this.buffer=t.createBuffer(),this.type=r,this.usage=i}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}}}const it=`#version 300 es\r
3
3
  precision highp float;\r
4
4
  \r
5
5
  // per-vertex\r
@@ -84,7 +84,7 @@ void main(void) {\r
84
84
  \r
85
85
  // CUSTOM_CODE_CALL\r
86
86
  }\r
87
- `,K=48,Jt=new Float32Array([0,0,1,0,0,1,1,1]);class ut extends Rt{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 ct(t,S.Float32,t.ARRAY_BUFFER,t.STATIC_DRAW),this.quadBuffer.bindBuffer();for(const e of Jt)this.quadBuffer.pushFloat32(e);this.quadBuffer.makeDirty(),this.quadBuffer.bufferData(),this.instanceBuffer=new ct(t,S.Uint32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW)}createDefaultShader(){return this.vs=it,this.fs=Et,this.defaultShader=this.createShader(it,Et),this.defaultShader}createShader(t,e){const r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aMatrixRow0",size:3,stride:K,offset:0,divisor:1},{name:"aMatrixRow1",size:3,stride:K,offset:12,divisor:1},{name:"aUVRect",size:4,stride:K,offset:24,divisor:1},{name:"aColor",size:4,type:ht,normalized:!0,stride:K,offset:40,divisor:1},{name:"aTextureId",size:1,type:ht,stride:K,offset:44,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}drawSprite(t,e,r=0,i=0,s=1,a=1,h=4294967295,o=0,c=0,u=!1,l=!1,m=!1){const d=e*6,x=this.matrixStore.data;this.drawSpriteAffine(t,x[d],x[d+1],x[d+2],x[d+3],x[d+4],x[d+5],r,i,s,a,h,o,c,u,l,m)}drawSpriteAffine(t,e,r,i,s,a,h,o=0,c=0,u=1,l=1,m=4294967295,d=0,x=0,p=!1,y=!1,T=!1){const R=t.base,A=t.rawWidth,L=t.rawHeight,P=t.offsetX,O=t.offsetY,F=this.useTexture(t.glTexture,d/R.width,x/R.height),U=this.instanceBuffer,w=U.usedElemNum;U.resize(12);const _=U.float32,H=U.uint32,G=T?L:A,V=T?A:L,W=G+2*d,D=V+2*x,z=P-d,tt=O-x,E=this.localSpriteMatrix;T?(E[0]=0,E[1]=y?D:-D,E[2]=p?-W:W,E[3]=0,E[4]=z+(p?W:0),E[5]=tt+(y?0:D)):(E[0]=p?-W:W,E[1]=0,E[2]=0,E[3]=y?-D:D,E[4]=z+(p?W:0),E[5]=tt+(y?D:0));const C=this.worldSpriteMatrix;C[0]=e*E[0]+i*E[1],C[1]=r*E[0]+s*E[1],C[2]=e*E[2]+i*E[3],C[3]=r*E[2]+s*E[3],C[4]=a+e*E[4]+i*E[5],C[5]=h+r*E[4]+s*E[5],_[w+6]=o,_[w+7]=c,_[w+8]=u,_[w+9]=l,H[w+10]=m,H[w+11]=F,this.rapid.roundPixels&&(C[4]=Math.round(C[4]),C[5]=Math.round(C[5])),_[w]=C[0],_[w+1]=C[2],_[w+2]=C[4],_[w+3]=C[1],_[w+4]=C[3],_[w+5]=C[5],U.usedElemNum+=12,U.makeDirty(),this.instanceCount++}render(){if(this.instanceCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO(),Mt(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 M=6;class te{matrixCount=0;buffer;data;temporary=-1;constructor(t=10){this.buffer=new b(S.Float32),this.buffer.resize(t*M),this.data=this.buffer.getArray(),this.reset()}alloc(){const t=this.allocDirty();return this.identity(t),t}allocDirty(){return this.buffer.resize(M)&&(this.data=this.buffer.getArray()),this.buffer.usedElemNum+=M,this.matrixCount++}reset(){this.matrixCount=0,this.buffer.usedElemNum=0,this.temporary=this.alloc()}identity(t){const e=t*M,r=this.data;r[e]=1,r[e+1]=0,r[e+2]=0,r[e+3]=1,r[e+4]=0,r[e+5]=0}translate(t,e,r){const i=t*M,s=this.data;s[i+4]=s[i]*e+s[i+2]*r+s[i+4],s[i+5]=s[i+1]*e+s[i+3]*r+s[i+5]}scale(t,e,r){const i=t*M,s=this.data;s[i]*=e,s[i+1]*=e,s[i+2]*=r,s[i+3]*=r}rotate(t,e){const r=t*M,i=this.data,s=Math.cos(e),a=Math.sin(e),h=i[r],o=i[r+1],c=i[r+2],u=i[r+3];i[r]=h*s+c*a,i[r+1]=o*s+u*a,i[r+2]=h*-a+c*s,i[r+3]=o*-a+u*s}rotateWithOffset(t,e,r,i){this.translate(t,r,i),this.rotate(t,e),this.translate(t,-r,-i)}copy(t,e){const r=t*M,i=e*M,s=this.data;s[r]=s[i],s[r+1]=s[i+1],s[r+2]=s[i+2],s[r+3]=s[i+3],s[r+4]=s[i+4],s[r+5]=s[i+5]}multiply(t,e){this.multiplyOut(t,t,e)}multiplyOut(t,e,r){const i=t*M,s=e*M,a=r*M,h=this.data,o=h[s],c=h[s+1],u=h[s+2],l=h[s+3],m=h[s+4],d=h[s+5],x=h[a],p=h[a+1],y=h[a+2],T=h[a+3],R=h[a+4],A=h[a+5];h[i]=o*x+u*p,h[i+1]=c*x+l*p,h[i+2]=o*y+u*T,h[i+3]=c*y+l*T,h[i+4]=o*R+u*A+m,h[i+5]=c*R+l*A+d}invert(t){const e=t*M,r=this.data,i=r[e],s=r[e+1],a=r[e+2],h=r[e+3],o=r[e+4],c=r[e+5];let u=i*h-s*a;if(!u){this.identity(t);return}u=1/u,r[e]=h*u,r[e+1]=-s*u,r[e+2]=-a*u,r[e+3]=i*u,r[e+4]=(a*c-h*o)*u,r[e+5]=(s*o-i*c)*u}transformPoint(t,e,r){const i=t*M,s=this.data;return{x:e*s[i]+r*s[i+2]+s[i+4],y:e*s[i+1]+r*s[i+3]+s[i+5]}}worldToLocal(t,e,r){const i=this.allocDirty();this.copy(i,t),this.invert(i);const s=this.transformPoint(i,e,r);return this.matrixCount--,this.buffer.usedElemNum-=M,s}localToWorld(t,e,r){return this.transformPoint(t,e,r)}getPosition(t){const e=t*M,r=this.data;return{x:r[e+4],y:r[e+5]}}getScale(t){const e=t*M,r=this.data,i=Math.sqrt(r[e]*r[e]+r[e+1]*r[e+1]),s=Math.sqrt(r[e+2]*r[e+2]+r[e+3]*r[e+3]);return{x:i,y:s}}getRotation(t){const e=t*M,r=this.data;return Math.atan2(r[e+1],r[e])}toCSSMatrix(t,e=1,r=1){const i=t*M,s=this.data;return`matrix(${s[i]*e}, ${s[i+1]*r}, ${s[i+2]*e}, ${s[i+3]*r}, ${s[i+4]*e}, ${s[i+5]*r})`}getMatrix(t){const e=t*M;return this.data.slice(e,e+M)}getMatrixRef(t){const e=t*M;return this.data.subarray(e,e+M)}setMatrix(t,e){const r=t*M,i=this.data;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]}multiplyAffineInPlace(t,e,r,i,s,a,h){const o=t*6,c=this.data,u=c[o],l=c[o+1],m=c[o+2],d=c[o+3],x=c[o+4],p=c[o+5];c[o]=u*e+m*r,c[o+1]=l*e+d*r,c[o+2]=u*i+m*s,c[o+3]=l*i+d*s,c[o+4]=u*a+m*h+x,c[o+5]=l*a+d*h+p}multiplyAffine(t,e,r,i,s,a,h,o){const c=t*6,u=e*6,l=this.data,m=l[c],d=l[c+1],x=l[c+2],p=l[c+3],y=l[c+4],T=l[c+5];l[u]=m*r+x*i,l[u+1]=d*r+p*i,l[u+2]=m*s+x*a,l[u+3]=d*s+p*a,l[u+4]=m*h+x*o+y,l[u+5]=d*h+p*o+T}}class ee{matrix=new te;step=0;stack=new b(S.Uint32);stepWorldM=new b(S.Uint32);stepAction=new b(S.Uint32);stepParentM=new b(S.Uint32);stepClose=new b(S.Uint32);stepStack=new b(S.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.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.allocDirty(),this.stepWorldM.push(this.curWorldM),this.stepParentM.push(t),this.stepAction.push(1),this.stepClose.push(0),this.stepStack.push(this.step),this.matrix.copy(this.curWorldM,t),{world:this.curWorldM,local:this.curLocalM,step:this.step++}}restore(){this.stack.length==0||this.stepStack.length==0||(this.curWorldM=this.stack.pop(),this.curLocalM=this.curWorldM-1,this.stepParentM.push(this.stack.get(this.stack.length-1)),this.stepWorldM.push(this.curWorldM),this.stepAction.push(0),this.stepClose.push(0),this.stepClose.typedArray[this.stepStack.pop()]=this.step,this.step++)}restoreAll(){for(;this.stack.length>0&&this.stepStack.length>0;)this.restore()}getStep(t){return typeof t=="number"?t:t.step}walkSubtree(t,e,r=1/0){let i=0,s=t;for(;s<this.step;){const a=this.stepAction.get(s);if(a===1){if(i++,i>r){const h=this.stepClose.get(s);if(h>s){s=h+1,i--;continue}}}else i--;if(e(s,a,i)===!1||a===0&&i===0)return;s++}}getParent(t){const e=this.getStep(t);return this.stepParentM.get(e)}getChildren(t){const e=this.getStep(t),r=this.stepClose.get(e),i=[];let s=e+1;for(;s<r;)this.stepAction.get(s)===1?(i.push(s),s=this.stepClose.get(s)+1):s++;return i}updateMatrixSubtree(t){const e=this.getStep(t);this.walkSubtree(e,(r,i)=>{if(i===1){const s=this.stepWorldM.get(r),a=s-1,h=this.stepParentM.get(r);this.matrix.multiplyOut(s,h,a)}})}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,r){this.matrix.rotateWithOffset(this.curLocalM,t,e,r),this.matrix.rotateWithOffset(this.curWorldM,t,e,r)}identity(){this.matrix.identity(this.curLocalM),this.matrix.identity(this.curWorldM)}reset(){this.matrix.reset(),this.stack.clear(),this.stepAction.clear(),this.stepWorldM.clear(),this.stepParentM.clear(),this.stepClose.clear(),this.stepStack.clear(),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*M;return this.matrix.data.slice(t,t+M)}setTransform(t){const e=this.curWorldM*M,r=this.matrix.data;r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2],r[e+3]=t[3],r[e+4]=t[4],r[e+5]=t[5]}transformPoint(t,e){return this.matrix.transformPoint(this.curLocalM,t,e)}applyTransform(t,e=0,r=0,i=-1){let s=t.x??0,a=t.y??0;t.position&&(s+=t.position.x,a+=t.position.y);let h=1,o=1;const c=t.scale;c&&(typeof c=="number"?(h=c,o=c):(h=c.x,o=c.y));const u=t.rotation??0;let l=t.offsetX??0,m=t.offsetY??0;t.offset&&(l+=t.offset.x,m+=t.offset.y);const d=t.origin;d!==void 0&&(typeof d=="number"?(l-=d*e,m-=d*r):(l-=d.x*e,m-=d.y*r));const x=u?Math.cos(u):1,p=u?Math.sin(u):0,y=x*h,T=p*h,R=-p*o,A=x*o,L=s+y*l+R*m,P=a+T*l+A*m;if(i!==-1){this.matrix.multiplyAffine(this.curWorldM,i,y,T,R,A,L,P);return}this.matrix.multiplyAffineInPlace(this.curLocalM,y,T,R,A,L,P),this.matrix.multiplyAffineInPlace(this.curWorldM,y,T,R,A,L,P)}}const re=`#version 300 es\r
87
+ `,q=48,Jt=new Float32Array([0,0,1,0,0,1,1,1]);class ut extends Rt{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 ct(t,A.Float32,t.ARRAY_BUFFER,t.STATIC_DRAW),this.quadBuffer.bindBuffer();for(const e of Jt)this.quadBuffer.pushFloat32(e);this.quadBuffer.makeDirty(),this.quadBuffer.bufferData(),this.instanceBuffer=new ct(t,A.Uint32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW)}createDefaultShader(){return this.vs=it,this.fs=Et,this.defaultShader=this.createShader(it,Et),this.defaultShader}createShader(t,e){const r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aMatrixRow0",size:3,stride:q,offset:0,divisor:1},{name:"aMatrixRow1",size:3,stride:q,offset:12,divisor:1},{name:"aUVRect",size:4,stride:q,offset:24,divisor:1},{name:"aColor",size:4,type:ht,normalized:!0,stride:q,offset:40,divisor:1},{name:"aTextureId",size:1,type:ht,stride:q,offset:44,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}drawSprite(t,e,r=0,i=0,s=1,a=1,h=4294967295,o=0,c=0,u=!1,l=!1,m=!1){const d=e*6,x=this.matrixStore.data;this.drawSpriteAffine(t,x[d],x[d+1],x[d+2],x[d+3],x[d+4],x[d+5],r,i,s,a,h,o,c,u,l,m)}drawSpriteAffine(t,e,r,i,s,a,h,o=0,c=0,u=1,l=1,m=4294967295,d=0,x=0,v=!1,T=!1,y=!1){const R=t.base,U=t.rawWidth,L=t.rawHeight,N=t.offsetX,H=t.offsetY,O=this.useTexture(t.glTexture,d/R.width,x/R.height),_=this.instanceBuffer,w=_.usedElemNum;_.resize(12);const S=_.float32,F=_.uint32,k=y?L:U,X=y?U:L,P=k+2*d,D=X+2*x,B=N-d,G=H-x,E=this.localSpriteMatrix;y?(E[0]=0,E[1]=T?D:-D,E[2]=v?-P:P,E[3]=0,E[4]=B+(v?P:0),E[5]=G+(T?0:D)):(E[0]=v?-P:P,E[1]=0,E[2]=0,E[3]=T?-D:D,E[4]=B+(v?P:0),E[5]=G+(T?D:0));const C=this.worldSpriteMatrix;C[0]=e*E[0]+i*E[1],C[1]=r*E[0]+s*E[1],C[2]=e*E[2]+i*E[3],C[3]=r*E[2]+s*E[3],C[4]=a+e*E[4]+i*E[5],C[5]=h+r*E[4]+s*E[5],S[w+6]=o,S[w+7]=c,S[w+8]=u,S[w+9]=l,F[w+10]=m,F[w+11]=O,this.rapid.roundPixels&&(C[4]=Math.round(C[4]),C[5]=Math.round(C[5])),S[w]=C[0],S[w+1]=C[2],S[w+2]=C[4],S[w+3]=C[1],S[w+4]=C[3],S[w+5]=C[5],_.usedElemNum+=12,_.makeDirty(),this.instanceCount++}render(){if(this.instanceCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO(),Mt(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 M=6;class te{matrixCount=0;buffer;data;temporary=-1;constructor(t=10){this.buffer=new b(A.Float32),this.buffer.resize(t*M),this.data=this.buffer.getArray(),this.reset()}alloc(){const t=this.allocDirty();return this.identity(t),t}allocDirty(){return this.buffer.resize(M)&&(this.data=this.buffer.getArray()),this.buffer.usedElemNum+=M,this.matrixCount++}reset(){this.matrixCount=0,this.buffer.usedElemNum=0,this.temporary=this.alloc()}identity(t){const e=t*M,r=this.data;r[e]=1,r[e+1]=0,r[e+2]=0,r[e+3]=1,r[e+4]=0,r[e+5]=0}translate(t,e,r){const i=t*M,s=this.data;s[i+4]=s[i]*e+s[i+2]*r+s[i+4],s[i+5]=s[i+1]*e+s[i+3]*r+s[i+5]}scale(t,e,r){const i=t*M,s=this.data;s[i]*=e,s[i+1]*=e,s[i+2]*=r,s[i+3]*=r}rotate(t,e){const r=t*M,i=this.data,s=Math.cos(e),a=Math.sin(e),h=i[r],o=i[r+1],c=i[r+2],u=i[r+3];i[r]=h*s+c*a,i[r+1]=o*s+u*a,i[r+2]=h*-a+c*s,i[r+3]=o*-a+u*s}rotateWithOffset(t,e,r,i){this.translate(t,r,i),this.rotate(t,e),this.translate(t,-r,-i)}copy(t,e){const r=t*M,i=e*M,s=this.data;s[r]=s[i],s[r+1]=s[i+1],s[r+2]=s[i+2],s[r+3]=s[i+3],s[r+4]=s[i+4],s[r+5]=s[i+5]}multiply(t,e){this.multiplyOut(t,t,e)}multiplyOut(t,e,r){const i=t*M,s=e*M,a=r*M,h=this.data,o=h[s],c=h[s+1],u=h[s+2],l=h[s+3],m=h[s+4],d=h[s+5],x=h[a],v=h[a+1],T=h[a+2],y=h[a+3],R=h[a+4],U=h[a+5];h[i]=o*x+u*v,h[i+1]=c*x+l*v,h[i+2]=o*T+u*y,h[i+3]=c*T+l*y,h[i+4]=o*R+u*U+m,h[i+5]=c*R+l*U+d}invert(t){const e=t*M,r=this.data,i=r[e],s=r[e+1],a=r[e+2],h=r[e+3],o=r[e+4],c=r[e+5];let u=i*h-s*a;if(!u){this.identity(t);return}u=1/u,r[e]=h*u,r[e+1]=-s*u,r[e+2]=-a*u,r[e+3]=i*u,r[e+4]=(a*c-h*o)*u,r[e+5]=(s*o-i*c)*u}transformPoint(t,e,r){const i=t*M,s=this.data;return{x:e*s[i]+r*s[i+2]+s[i+4],y:e*s[i+1]+r*s[i+3]+s[i+5]}}worldToLocal(t,e,r){const i=this.allocDirty();this.copy(i,t),this.invert(i);const s=this.transformPoint(i,e,r);return this.matrixCount--,this.buffer.usedElemNum-=M,s}localToWorld(t,e,r){return this.transformPoint(t,e,r)}getPosition(t){const e=t*M,r=this.data;return{x:r[e+4],y:r[e+5]}}getScale(t){const e=t*M,r=this.data,i=Math.sqrt(r[e]*r[e]+r[e+1]*r[e+1]),s=Math.sqrt(r[e+2]*r[e+2]+r[e+3]*r[e+3]);return{x:i,y:s}}getRotation(t){const e=t*M,r=this.data;return Math.atan2(r[e+1],r[e])}toCSSMatrix(t,e=1,r=1){const i=t*M,s=this.data;return`matrix(${s[i]*e}, ${s[i+1]*r}, ${s[i+2]*e}, ${s[i+3]*r}, ${s[i+4]*e}, ${s[i+5]*r})`}getMatrix(t){const e=t*M;return this.data.slice(e,e+M)}getMatrixRef(t){const e=t*M;return this.data.subarray(e,e+M)}setMatrix(t,e){const r=t*M,i=this.data;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]}multiplyAffineInPlace(t,e,r,i,s,a,h){const o=t*6,c=this.data,u=c[o],l=c[o+1],m=c[o+2],d=c[o+3],x=c[o+4],v=c[o+5];c[o]=u*e+m*r,c[o+1]=l*e+d*r,c[o+2]=u*i+m*s,c[o+3]=l*i+d*s,c[o+4]=u*a+m*h+x,c[o+5]=l*a+d*h+v}multiplyAffine(t,e,r,i,s,a,h,o){const c=t*6,u=e*6,l=this.data,m=l[c],d=l[c+1],x=l[c+2],v=l[c+3],T=l[c+4],y=l[c+5];l[u]=m*r+x*i,l[u+1]=d*r+v*i,l[u+2]=m*s+x*a,l[u+3]=d*s+v*a,l[u+4]=m*h+x*o+T,l[u+5]=d*h+v*o+y}}class ee{matrix=new te;step=0;stack=new b(A.Uint32);stepWorldM=new b(A.Uint32);stepAction=new b(A.Uint32);stepParentM=new b(A.Uint32);stepClose=new b(A.Uint32);stepStack=new b(A.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.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.allocDirty(),this.stepWorldM.push(this.curWorldM),this.stepParentM.push(t),this.stepAction.push(1),this.stepClose.push(0),this.stepStack.push(this.step),this.matrix.copy(this.curWorldM,t),{world:this.curWorldM,local:this.curLocalM,step:this.step++}}restore(){this.stack.length==0||this.stepStack.length==0||(this.curWorldM=this.stack.pop(),this.curLocalM=this.curWorldM-1,this.stepParentM.push(this.stack.get(this.stack.length-1)),this.stepWorldM.push(this.curWorldM),this.stepAction.push(0),this.stepClose.push(0),this.stepClose.typedArray[this.stepStack.pop()]=this.step,this.step++)}restoreAll(){for(;this.stack.length>0&&this.stepStack.length>0;)this.restore()}getStep(t){return typeof t=="number"?t:t.step}walkSubtree(t,e,r=1/0){let i=0,s=t;for(;s<this.step;){const a=this.stepAction.get(s);if(a===1){if(i++,i>r){const h=this.stepClose.get(s);if(h>s){s=h+1,i--;continue}}}else i--;if(e(s,a,i)===!1||a===0&&i===0)return;s++}}getParent(t){const e=this.getStep(t);return this.stepParentM.get(e)}getChildren(t){const e=this.getStep(t),r=this.stepClose.get(e),i=[];let s=e+1;for(;s<r;)this.stepAction.get(s)===1?(i.push(s),s=this.stepClose.get(s)+1):s++;return i}updateMatrixSubtree(t){const e=this.getStep(t);this.walkSubtree(e,(r,i)=>{if(i===1){const s=this.stepWorldM.get(r),a=s-1,h=this.stepParentM.get(r);this.matrix.multiplyOut(s,h,a)}})}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,r){this.matrix.rotateWithOffset(this.curLocalM,t,e,r),this.matrix.rotateWithOffset(this.curWorldM,t,e,r)}identity(){this.matrix.identity(this.curLocalM),this.matrix.identity(this.curWorldM)}reset(){this.matrix.reset(),this.stack.clear(),this.stepAction.clear(),this.stepWorldM.clear(),this.stepParentM.clear(),this.stepClose.clear(),this.stepStack.clear(),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*M;return this.matrix.data.slice(t,t+M)}setTransform(t){const e=this.curWorldM*M,r=this.matrix.data;r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2],r[e+3]=t[3],r[e+4]=t[4],r[e+5]=t[5]}transformPoint(t,e){return this.matrix.transformPoint(this.curLocalM,t,e)}applyTransform(t,e=0,r=0,i=-1){let s=t.x??0,a=t.y??0;t.position&&(s+=t.position.x,a+=t.position.y);let h=1,o=1;const c=t.scale;c&&(typeof c=="number"?(h=c,o=c):(h=c.x,o=c.y));const u=t.rotation??0;let l=t.offsetX??0,m=t.offsetY??0;t.offset&&(l+=t.offset.x,m+=t.offset.y);const d=t.origin;d!==void 0&&(typeof d=="number"?(l-=d*e,m-=d*r):(l-=d.x*e,m-=d.y*r));const x=u?Math.cos(u):1,v=u?Math.sin(u):0,T=x*h,y=v*h,R=-v*o,U=x*o,L=s+T*l+R*m,N=a+y*l+U*m;if(i!==-1){this.matrix.multiplyAffine(this.curWorldM,i,T,y,R,U,L,N);return}this.matrix.multiplyAffineInPlace(this.curLocalM,T,y,R,U,L,N),this.matrix.multiplyAffineInPlace(this.curWorldM,T,y,R,U,L,N)}}const re=`#version 300 es\r
88
88
  precision highp float;\r
89
89
  \r
90
90
  in vec2 aPosition;\r
@@ -205,7 +205,7 @@ void main(void) {\r
205
205
  discard;\r
206
206
  }\r
207
207
  }\r
208
- `,q=20;class ae extends Rt{vertexBuffer;vertexCount=0;extraTextureUnit=1;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 ct(t,S.Float32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW),this.maskShader=this.createMaskShader(se,ne)}createDefaultShader(){return this.vs=re,this.fs=ie,this.defaultShader=this.createShader(this.vs,this.fs),this.defaultShader}createMaskShader(t,e){const r=this.gl,i=new ot(r,t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:q-4,offset:0,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:q-4,offset:8,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}createShader(t,e){const r=this.gl,i=super.createShader(t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:q,offset:0,divisor:0},{name:"aColor",size:4,type:r.UNSIGNED_BYTE,normalized:!0,stride:q,offset:8,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:q,offset:12,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}startGraphic(t,e=this.gl.TRIANGLES,r){this.vertexBuffer.clear(),this.vertexCount=0,this.matrixIndex=t,this.drawMode=e,this.texture=r,this.texture?.glTexture&&this.useTexture(this.texture.glTexture,0,0)}addVertex(t,e,r=0,i=0,s=4294967295){const a=this.vertexBuffer;a.pushFloat32(t),a.pushFloat32(e),this.currentShader!=this.maskShader&&a.pushUint32(s),a.pushFloat32(r),a.pushFloat32(i),this.vertexCount++,this.vertexBuffer.makeDirty()}endGraphic(){this.flush()}render(){if(this.vertexCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader,r=this.matrixIndex*6,i=this.matrixStore.data;let s=i[r+4],a=i[r+5];this.rapid.roundPixels&&(s=Math.round(s),a=Math.round(a)),e.setUniform("uMatrixRow0",[i[r],i[r+2],s]),e.setUniform("uMatrixRow1",[i[r+1],i[r+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 g{x;y;static ZERO=new g(0,0);static ONE=new g(1,1);static UP=new g(0,1);static DOWN=new g(0,-1);static LEFT=new g(-1,0);static RIGHT=new g(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 g(this.x+t.x,this.y+t.y)}subtract(t){return new g(this.x-t.x,this.y-t.y)}multiply(t){return t instanceof g?new g(this.x*t.x,this.y*t.y):new g(this.x*t,this.y*t)}divide(t){return t instanceof g?new g(this.x/t.x,this.y/t.y):new g(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,r=this.y-t.y;return Math.sqrt(e*e+r*r)}clone(){return new g(this.x,this.y)}to(t){this.x=t.x,this.y=t.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 g(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 g(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 g(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 g(Math.abs(this.x),Math.abs(this.y))}floor(){return new g(Math.floor(this.x),Math.floor(this.y))}ceil(){return new g(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 g(e[0],e[1]))}static fromAngle(t){return new g(Math.cos(t),Math.sin(t))}}const wt=(n,t)=>{const[e,r,i,s,a,h]=t,o=new Float32Array([e,i,0,0,r,s,0,0,0,0,1,0,a,h,0,1]);return St(o,n)},St=(n,t)=>{const e=new Float32Array(16);for(let r=0;r<4;r++)for(let i=0;i<4;i++){let s=0;for(let a=0;a<4;a++)s+=n[i*4+a]*t[a*4+r];e[i*4+r]=s}return e};var At=(n=>(n[n.STRETCH=0]="STRETCH",n[n.REPEAT=1]="REPEAT",n))(At||{});const lt=10,bt=(n,t,e,r,i,s)=>{const a=[],h=[],o=r?Math.atan2(t.y,t.x):Math.atan2(-t.y,-t.x),c=Math.PI,u=new g(t.y,-t.x);for(let l=0;l<lt;l++){const m=l/lt,d=(l+1)/lt,x=o+m*c,p=o+d*c,y=new g(Math.cos(x)*e,Math.sin(x)*e),T=new g(Math.cos(p)*e,Math.sin(p)*e);a.push(n),h.push(new g(i,.5)),a.push(n.add(y)),h.push(new g(i+y.dot(u)*s,.5-.5*y.dot(t)/e)),a.push(n.add(T)),h.push(new g(i+T.dot(u)*s,.5-.5*T.dot(t)/e))}return{vertices:a,uv:h}},Ut=(n,t=!1)=>{const e=[];if(n.length<2||t&&n.length<3)return{normals:e,length:0};const r=4,i=.001,s=n.length;let a=0;if(t)for(let o=0;o<s;o++){const c=n[o],u=n[(o+1)%s];a+=c.distanceTo(u)}else for(let o=0;o<s-1;o++)a+=n[o].distanceTo(n[o+1]);const h=(o,c,u)=>{const l=c.subtract(o).normalize(),m=c.subtract(u).normalize(),d=m.dot(l);if(d<-1+i)return{normal:l.perpendicular(),miters:1};{let x=m.add(l).normalize();l.cross(m)<0&&(x=x.multiply(-1));let p=1/Math.sqrt((1-d)/2);return{normal:x,miters:Math.min(p,r)}}};if(t)for(let o=0;o<s;o++){const c=o===0?n[s-1]:n[o-1],u=n[o],l=o===s-1?n[0]:n[o+1];e.push(h(c,u,l))}else for(let o=0;o<s;o++)if(o===0){const c=n[1].subtract(n[0]).normalize();e.push({normal:c.perpendicular(),miters:1})}else if(o===s-1){const c=n[o].subtract(n[o-1]).normalize();e.push({normal:c.perpendicular(),miters:1})}else e.push(h(n[o-1],n[o],n[o+1]));return{normals:e,length:a}},Ct=n=>{const t=n.points;if(t.length<2)return{vertices:[],uv:[]};const{normals:e,length:r}=Ut(t,n.closed),i=(n.width||1)/2,s=[],a=[],h=n.roundCap||!1,o=n.textureMode||0;let c=0;const u=n.texture?.rawWidth||1,l=n.closed?t.length:t.length-1;for(let m=0;m<l;m++){const d=t[m],x=e[m].normal,p=e[m].miters,y=(m+1)%t.length,T=t[y],R=e[y].normal,A=e[y].miters,L=d.add(x.multiply(p*i)),P=d.subtract(x.multiply(p*i)),O=T.add(R.multiply(A*i)),F=T.subtract(R.multiply(A*i)),U=d.distanceTo(T);let w=0,_=0;o===0?(w=c/r,_=(c+U)/r):(w=c/u,_=w+U/u);const H=new g(w,0),G=new g(w,1),V=new g(_,0),W=new g(_,1);s.push(L),a.push(H),s.push(P),a.push(G),s.push(O),a.push(V),s.push(O),a.push(V),s.push(F),a.push(W),s.push(P),a.push(G),c+=U}if(h&&!n.closed){const m=t[0],d=e[0].normal,x=o===0?r>0?1/r:0:1/u,p=bt(m,d,i,!0,0,x);s.push(...p.vertices),a.push(...p.uv);const y=t[t.length-1],T=e[t.length-1].normal,R=o===0?1:c/u,A=o===0?r>0?1/r:0:1/u,L=bt(y,T,i,!1,R,A);s.push(...L.vertices),a.push(...L.uv)}return{vertices:s,uv:a}},Q=(n,t,e,r)=>{if(t.customMatrix!==void 0)return t.customMatrix;if(t.modifyStack){n.matrixStack.applyTransform(t,e,r);return}else{const i=n.matrix.temporary;return n.matrixStack.applyTransform(t,e,r,i),i}},_t=(n,t)=>t?n?t.premultipliedUint32:t.uint32:4294967295,he=2,Lt=(n,t)=>{const e=Q(n,t,t.texture.rawWidth,t.texture.rawHeight),r=t.texture;if(!r?.base||n.inCreateMask)return;const i=r.isAtlas?n.atlasSpriteRegion:n.spriteRegion;n.enterRegion(i,t.shader);let s=r.uvX,a=r.uvY,h=r.uvW,o=r.uvH;const c=!!t.flipX,u=!!t.flipY!=!!r.flipY;let l=t.padding??i.currentShader.padding;r.isAtlas&&(l+=he);const m=s<=h?l:-l,d=a<=o?l:-l;i.drawSprite(r,e??t.customMatrix??n.matrixStack.curWorldM,s,a,h,o,n.getColorUint32(t.color),m,d,c,u,r.isRotated)},Pt=(n,t)=>{const e=n.particleRegion;n.enterRegion(e,t.shader);const r=t.texture,i=t.count??t.x.length,s=t.color;e.drawParticles(r,t.x,t.y,t.rotation,s,i,t.scaleX,t.scaleY,t.u0??r.uvX,t.v0??r.uvY,t.u1??r.uvW,t.v1??r.uvH,t.flipX,t.flipY,r.isRotated,t.originX,t.originY,n.premultipliedAlpha,t.reverseOrder,t.customMatrix)},dt=(n,t)=>{if(t.points.length===0)return;const e=Q(n,t,0,0);n.startGraphic(t.drawMode??n.gl.TRIANGLES,t.texture,t.shader,e??t.customMatrix);for(let r=0;r<t.points.length;r++){const i=t.points[r],s=t.uv?.[r],a=Array.isArray(t.color)?t.color[r]:t.color;n.addGraphicVertex(i.x,i.y,s?.x??0,s?.y??0,n.getColorUint32(a))}n.endGraphic()},Nt=(n,t)=>{if(n.inCreateMask)return;const{vertices:e,uv:r}=Ct(t);dt(n,{...t,points:e,uv:r,drawMode:n.gl.TRIANGLES})},It=(n,t)=>{const e=Q(n,t,t.texture.rawWidth,t.texture.rawHeight);n.startMaskGraphic(n.gl.TRIANGLE_FAN,t.texture,e??t.customMatrix),n.addRectVertex(t.texture.rawWidth,t.texture.rawHeight),n.endGraphic()},Wt=(n,t)=>{const e=Q(n,t,t.width,t.height);n.startGraphic(n.gl.TRIANGLE_FAN,t.texture,t.shader,e??t.customMatrix),n.addRectVertex(t.width,t.height,t.color),n.endGraphic()},Ot=(n,t)=>{const e=t.segments??32,r=Q(n,t,0,0);n.startGraphic(n.gl.TRIANGLE_FAN,void 0,t.shader,r??t.customMatrix);const i=n.getColorUint32(t.color);n.addGraphicVertex(0,0,.5,.5,i),n.addCircleVertex(t.radius,t.color,e),n.addGraphicVertex(t.radius,0,1,.5,i),n.endGraphic()},Ft=`#version 300 es\r
208
+ `,Q=20;class ae extends Rt{vertexBuffer;vertexCount=0;extraTextureUnit=1;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 ct(t,A.Float32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW),this.maskShader=this.createMaskShader(se,ne)}createDefaultShader(){return this.vs=re,this.fs=ie,this.defaultShader=this.createShader(this.vs,this.fs),this.defaultShader}createMaskShader(t,e){const r=this.gl,i=new ot(r,t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:Q-4,offset:0,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:Q-4,offset:8,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}createShader(t,e){const r=this.gl,i=super.createShader(t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:Q,offset:0,divisor:0},{name:"aColor",size:4,type:r.UNSIGNED_BYTE,normalized:!0,stride:Q,offset:8,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:Q,offset:12,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}startGraphic(t,e=this.gl.TRIANGLES,r){this.vertexBuffer.clear(),this.vertexCount=0,this.matrixIndex=t,this.drawMode=e,this.texture=r,this.texture?.glTexture&&this.useTexture(this.texture.glTexture,0,0)}addVertex(t,e,r=0,i=0,s=4294967295){const a=this.vertexBuffer;a.pushFloat32(t),a.pushFloat32(e),this.currentShader!=this.maskShader&&a.pushUint32(s),a.pushFloat32(r),a.pushFloat32(i),this.vertexCount++,this.vertexBuffer.makeDirty()}endGraphic(){this.flush()}render(){if(this.vertexCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader,r=this.matrixIndex*6,i=this.matrixStore.data;let s=i[r+4],a=i[r+5];this.rapid.roundPixels&&(s=Math.round(s),a=Math.round(a)),e.setUniform("uMatrixRow0",[i[r],i[r+2],s]),e.setUniform("uMatrixRow1",[i[r+1],i[r+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 g{x;y;static ZERO=new g(0,0);static ONE=new g(1,1);static UP=new g(0,1);static DOWN=new g(0,-1);static LEFT=new g(-1,0);static RIGHT=new g(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 g(this.x+t.x,this.y+t.y)}subtract(t){return new g(this.x-t.x,this.y-t.y)}multiply(t){return t instanceof g?new g(this.x*t.x,this.y*t.y):new g(this.x*t,this.y*t)}divide(t){return t instanceof g?new g(this.x/t.x,this.y/t.y):new g(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,r=this.y-t.y;return Math.sqrt(e*e+r*r)}clone(){return new g(this.x,this.y)}to(t){this.x=t.x,this.y=t.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 g(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 g(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 g(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 g(Math.abs(this.x),Math.abs(this.y))}floor(){return new g(Math.floor(this.x),Math.floor(this.y))}ceil(){return new g(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 g(e[0],e[1]))}static fromAngle(t){return new g(Math.cos(t),Math.sin(t))}}const wt=(n,t)=>{const[e,r,i,s,a,h]=t,o=new Float32Array([e,i,0,0,r,s,0,0,0,0,1,0,a,h,0,1]);return St(o,n)},St=(n,t)=>{const e=new Float32Array(16);for(let r=0;r<4;r++)for(let i=0;i<4;i++){let s=0;for(let a=0;a<4;a++)s+=n[i*4+a]*t[a*4+r];e[i*4+r]=s}return e};var At=(n=>(n[n.STRETCH=0]="STRETCH",n[n.REPEAT=1]="REPEAT",n))(At||{});const lt=10,bt=(n,t,e,r,i,s)=>{const a=[],h=[],o=r?Math.atan2(t.y,t.x):Math.atan2(-t.y,-t.x),c=Math.PI,u=new g(t.y,-t.x);for(let l=0;l<lt;l++){const m=l/lt,d=(l+1)/lt,x=o+m*c,v=o+d*c,T=new g(Math.cos(x)*e,Math.sin(x)*e),y=new g(Math.cos(v)*e,Math.sin(v)*e);a.push(n),h.push(new g(i,.5)),a.push(n.add(T)),h.push(new g(i+T.dot(u)*s,.5-.5*T.dot(t)/e)),a.push(n.add(y)),h.push(new g(i+y.dot(u)*s,.5-.5*y.dot(t)/e))}return{vertices:a,uv:h}},Ut=(n,t=!1)=>{const e=[];if(n.length<2||t&&n.length<3)return{normals:e,length:0};const r=4,i=.001,s=n.length;let a=0;if(t)for(let o=0;o<s;o++){const c=n[o],u=n[(o+1)%s];a+=c.distanceTo(u)}else for(let o=0;o<s-1;o++)a+=n[o].distanceTo(n[o+1]);const h=(o,c,u)=>{const l=c.subtract(o).normalize(),m=c.subtract(u).normalize(),d=m.dot(l);if(d<-1+i)return{normal:l.perpendicular(),miters:1};{let x=m.add(l).normalize();l.cross(m)<0&&(x=x.multiply(-1));let v=1/Math.sqrt((1-d)/2);return{normal:x,miters:Math.min(v,r)}}};if(t)for(let o=0;o<s;o++){const c=o===0?n[s-1]:n[o-1],u=n[o],l=o===s-1?n[0]:n[o+1];e.push(h(c,u,l))}else for(let o=0;o<s;o++)if(o===0){const c=n[1].subtract(n[0]).normalize();e.push({normal:c.perpendicular(),miters:1})}else if(o===s-1){const c=n[o].subtract(n[o-1]).normalize();e.push({normal:c.perpendicular(),miters:1})}else e.push(h(n[o-1],n[o],n[o+1]));return{normals:e,length:a}},Ct=n=>{const t=n.points;if(t.length<2)return{vertices:[],uv:[]};const{normals:e,length:r}=Ut(t,n.closed),i=(n.width||1)/2,s=[],a=[],h=n.roundCap||!1,o=n.textureMode||0;let c=0;const u=n.texture?.rawWidth||1,l=n.closed?t.length:t.length-1;for(let m=0;m<l;m++){const d=t[m],x=e[m].normal,v=e[m].miters,T=(m+1)%t.length,y=t[T],R=e[T].normal,U=e[T].miters,L=d.add(x.multiply(v*i)),N=d.subtract(x.multiply(v*i)),H=y.add(R.multiply(U*i)),O=y.subtract(R.multiply(U*i)),_=d.distanceTo(y);let w=0,S=0;o===0?(w=c/r,S=(c+_)/r):(w=c/u,S=w+_/u);const F=new g(w,0),k=new g(w,1),X=new g(S,0),P=new g(S,1);s.push(L),a.push(F),s.push(N),a.push(k),s.push(H),a.push(X),s.push(H),a.push(X),s.push(O),a.push(P),s.push(N),a.push(k),c+=_}if(h&&!n.closed){const m=t[0],d=e[0].normal,x=o===0?r>0?1/r:0:1/u,v=bt(m,d,i,!0,0,x);s.push(...v.vertices),a.push(...v.uv);const T=t[t.length-1],y=e[t.length-1].normal,R=o===0?1:c/u,U=o===0?r>0?1/r:0:1/u,L=bt(T,y,i,!1,R,U);s.push(...L.vertices),a.push(...L.uv)}return{vertices:s,uv:a}},Z=(n,t,e,r)=>{if(t.customMatrix!==void 0)return t.customMatrix;if(t.modifyStack){n.matrixStack.applyTransform(t,e,r);return}else{const i=n.matrix.temporary;return n.matrixStack.applyTransform(t,e,r,i),i}},_t=(n,t)=>t?n?t.premultipliedUint32:t.uint32:4294967295,he=2,Lt=(n,t)=>{const e=Z(n,t,t.texture.rawWidth,t.texture.rawHeight),r=t.texture;if(!r?.base||n.inCreateMask)return;const i=r.isAtlas?n.atlasSpriteRegion:n.spriteRegion;n.enterRegion(i,t.shader);let s=r.uvX,a=r.uvY,h=r.uvW,o=r.uvH;const c=!!t.flipX,u=!!t.flipY!=!!r.flipY;let l=t.padding??i.currentShader.padding;r.isAtlas&&(l+=he);const m=s<=h?l:-l,d=a<=o?l:-l;i.drawSprite(r,e??t.customMatrix??n.matrixStack.curWorldM,s,a,h,o,n.getColorUint32(t.color),m,d,c,u,r.isRotated)},Pt=(n,t)=>{const e=n.particleRegion;n.enterRegion(e,t.shader);const r=t.texture,i=t.count??t.x.length,s=t.color;e.drawParticles(r,t.x,t.y,t.rotation,s,i,t.scaleX,t.scaleY,t.u0??r.uvX,t.v0??r.uvY,t.u1??r.uvW,t.v1??r.uvH,t.flipX,t.flipY,r.isRotated,t.originX,t.originY,n.premultipliedAlpha,t.reverseOrder,t.customMatrix)},dt=(n,t)=>{if(t.points.length===0)return;const e=Z(n,t,0,0);n.startGraphic(t.drawMode??n.gl.TRIANGLES,t.texture,t.shader,e??t.customMatrix);for(let r=0;r<t.points.length;r++){const i=t.points[r],s=t.uv?.[r],a=Array.isArray(t.color)?t.color[r]:t.color;n.addGraphicVertex(i.x,i.y,s?.x??0,s?.y??0,n.getColorUint32(a))}n.endGraphic()},Nt=(n,t)=>{if(n.inCreateMask)return;const{vertices:e,uv:r}=Ct(t);dt(n,{...t,points:e,uv:r,drawMode:n.gl.TRIANGLES})},It=(n,t)=>{const e=Z(n,t,t.texture.rawWidth,t.texture.rawHeight);n.startMaskGraphic(n.gl.TRIANGLE_FAN,t.texture,e??t.customMatrix),n.addRectVertex(t.texture.rawWidth,t.texture.rawHeight),n.endGraphic()},Wt=(n,t)=>{const e=Z(n,t,t.width,t.height);n.startGraphic(n.gl.TRIANGLE_FAN,t.texture,t.shader,e??t.customMatrix),n.addRectVertex(t.width,t.height,t.color),n.endGraphic()},Ot=(n,t)=>{const e=t.segments??32,r=Z(n,t,0,0);n.startGraphic(n.gl.TRIANGLE_FAN,void 0,t.shader,r??t.customMatrix);const i=n.getColorUint32(t.color);n.addGraphicVertex(0,0,.5,.5,i),n.addCircleVertex(t.radius,t.color,e),n.addGraphicVertex(t.radius,0,1,.5,i),n.endGraphic()},Ft=`#version 300 es\r
209
209
  precision mediump float;\r
210
210
  \r
211
211
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -302,7 +302,7 @@ void main(void) {\r
302
302
  \r
303
303
  // CUSTOM_CODE_CALL\r
304
304
  }\r
305
- `,k=48,le=k/4;class de extends ut{KEY="ParticleSprite";texture;customMatrix;particleLoopCache=new Map;extraTextureUnit=1;constructor(t){super(t)}createDefaultShader(){const t=ue,e=ce;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 r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,stride:k,offset:0,divisor:1},{name:"aScale",size:2,stride:k,offset:8,divisor:1},{name:"aRotation",size:1,stride:k,offset:16,divisor:1},{name:"aUVRect",size:4,stride:k,offset:20,divisor:1},{name:"aColor",size:4,type:ht,normalized:!0,stride:k,offset:36,divisor:1},{name:"aOrigin",size:2,stride:k,offset:40,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}drawParticles(t,e,r,i=0,s=4294967295,a,h=1,o=1,c=0,u=0,l=1,m=1,d=!1,x=!1,p=!1,y=.5,T=.5,R,A=!1,L){if(!t.glTexture||a<=0)return;this.texture&&t!==this.texture&&this.flush();const P=typeof h=="number",O=typeof o=="number",F=typeof i=="number",U=typeof s=="number",w=typeof c=="number",_=!U&&typeof s[0]=="number",H=t.uvW-t.uvX,G=t.uvH-t.uvY,V=H===0?0:1/H,W=G===0?0:1/G;let D=t.rawWidth*(d?-1:1);P&&(D*=h);let z=t.rawHeight*(x?-1:1);O&&(z*=o),w&&(D*=(l-c)*V,z*=(m-u)*W);let tt=p?Math.PI/2:0;F&&(tt+=i);const E=s??4294967295,C=this.getParticleLoop(P,O,F,w,U,_,A,R);this.texture||(this.texture=t,this.useTexture(t.glTexture,0,0));const xt=a,Y=this.instanceBuffer;let gt=Y.usedElemNum;Y.resize(xt*le);const ve=Y.float32,ye=Y.uint32;gt=C(e,r,h,o,i,c,u,l,m,s,ve,ye,D,z,V,W,tt,E,y,T,a,xt,gt),Y.usedElemNum=gt,Y.makeDirty(),this.instanceCount+=xt,this.customMatrix=L,this.flush()}getParticleLoop(t,e,r,i,s,a,h,o){const c=[...arguments].join("_");if(this.particleLoopCache.has(c))return this.particleLoopCache.get(c);let u=`
305
+ `,Y=48,le=Y/4;class de extends ut{KEY="ParticleSprite";texture;customMatrix;particleLoopCache=new Map;extraTextureUnit=1;constructor(t){super(t)}createDefaultShader(){const t=ue,e=ce;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 r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,stride:Y,offset:0,divisor:1},{name:"aScale",size:2,stride:Y,offset:8,divisor:1},{name:"aRotation",size:1,stride:Y,offset:16,divisor:1},{name:"aUVRect",size:4,stride:Y,offset:20,divisor:1},{name:"aColor",size:4,type:ht,normalized:!0,stride:Y,offset:36,divisor:1},{name:"aOrigin",size:2,stride:Y,offset:40,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}drawParticles(t,e,r,i=0,s=4294967295,a,h=1,o=1,c=0,u=0,l=1,m=1,d=!1,x=!1,v=!1,T=.5,y=.5,R,U=!1,L){if(!t.glTexture||a<=0)return;this.texture&&t!==this.texture&&this.flush();const N=typeof h=="number",H=typeof o=="number",O=typeof i=="number",_=typeof s=="number",w=typeof c=="number",S=!_&&typeof s[0]=="number",F=t.uvW-t.uvX,k=t.uvH-t.uvY,X=F===0?0:1/F,P=k===0?0:1/k;let D=t.rawWidth*(d?-1:1);N&&(D*=h);let B=t.rawHeight*(x?-1:1);H&&(B*=o),w&&(D*=(l-c)*X,B*=(m-u)*P);let G=v?Math.PI/2:0;O&&(G+=i);const E=s??4294967295,C=this.getParticleLoop(N,H,O,w,_,S,U,R);this.texture||(this.texture=t,this.useTexture(t.glTexture,0,0));const xt=a,$=this.instanceBuffer;let gt=$.usedElemNum;$.resize(xt*le);const ve=$.float32,ye=$.uint32;gt=C(e,r,h,o,i,c,u,l,m,s,ve,ye,D,B,X,P,G,E,T,y,a,xt,gt),$.usedElemNum=gt,$.makeDirty(),this.instanceCount+=xt,this.customMatrix=L,this.flush()}getParticleLoop(t,e,r,i,s,a,h,o){const c=[...arguments].join("_");if(this.particleLoopCache.has(c))return this.particleLoopCache.get(c);let u=`
306
306
  return function( x, y, scaleX, scaleY, rotation, u0, v0, u1, v1, color, f32, u32, rawWidth, rawHeight, uv2texW, uv2texH, rotationOffset, staticColor, originX, originY, count, batchCount, index ) {
307
307
  ${t&&i?"const baseSx = rawWidth;":""}
308
308
  ${e&&i?"const baseSy = rawHeight;":""}
@@ -341,7 +341,7 @@ f32[idx + 11] = originY;
341
341
  }
342
342
  return idx;
343
343
  }
344
- `;const l=new Function(u)();return this.particleLoopCache.set(c,l),l}render(){if(this.instanceCount===0)return;this.prepareRender();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 r=this.rapid.matrixStack,s=this.rapid.matrix.getMatrix(this.customMatrix??r.curWorldM),a=wt(this.rapid.projection,s);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}}var ft=(n=>(n[n.EQUAL=0]="EQUAL",n[n.NOT_EQUAL=1]="NOT_EQUAL",n))(ft||{}),Dt=(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))(Dt||{}),Bt=(n=>(n[n.CanvasItem=0]="CanvasItem",n[n.Viewport=1]="Viewport",n))(Bt||{});class fe{gl;canvas;projection=new Float32Array(16);projectionDirty=!0;dpr;backgroundColor=f.Black;logicWidth=0;logicHeight=0;physicsWidth=0;physicsHeight=0;currentRegion=null;maxTextureUnits=0;matrixStack=new ee(this);matrix;spriteRegion;graphicRegion;atlasSpriteRegion;particleRegion;drawcallCount=0;inCreateMask=!1;texture;premultipliedAlpha;antialias;roundPixels;textureFilter;scaleMode;_filterRT=[null,null];_filterInput=new N;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??$.NEAREST,this.premultipliedAlpha=t.premultipliedAlpha??!0,this.roundPixels=t.roundPixels??!1,this.scaleMode=t.scaleMode??0;const e=Yt(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 ut(this),this.graphicRegion=new ae(this),this.atlasSpriteRegion=new oe(this),this.particleRegion=new de(this);const r=this.canvas.clientWidth||this.canvas.width,i=this.canvas.clientHeight||this.canvas.height;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 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}getColorUint32(t){return _t(this.premultipliedAlpha,t)}enterRegion(t,e){this.currentRegion===t&&this.currentRegion.isSameShader(e)||(this.flush(),this.currentRegion=t,t.enter(e))}drawParticles(t){Pt(this,t)}drawSprite(t){Lt(this,t)}drawLine(t){Nt(this,t)}drawGraphic(t){dt(this,t)}drawRect(t){Wt(this,t)}drawCircle(t){Ot(this,t)}startGraphic(t=this.gl.TRIANGLES,e,r,i){this.enterRegion(this.graphicRegion,r),this.graphicRegion.startGraphic(i??this.matrixStack.curWorldM,t,e)}startMaskGraphic(t=this.gl.TRIANGLES,e,r){this.startGraphic(t,e,this.graphicRegion.maskShader,r)}drawMaskImage(t){It(this,t)}addRectVertex(t,e,r){const i=this.getColorUint32(r);this.addGraphicVertex(0,0,0,0,i),this.addGraphicVertex(t,0,1,0,i),this.addGraphicVertex(t,e,1,1,i),this.addGraphicVertex(0,e,0,1,i)}addCircleVertex(t,e,r=32){const i=Math.PI*2/r,s=this.getColorUint32(e);for(let a=0;a<r;a++){const h=i*a,o=Math.cos(h)*t,c=Math.sin(h)*t,u=.5+Math.cos(h)*.5,l=.5+Math.sin(h)*.5;this.addGraphicVertex(o,c,u,l,s)}}addGraphicVertex(t,e,r=0,i=0,s=4294967295){this.graphicRegion.addVertex(t,e,r,i,typeof s=="number"?s:this.getColorUint32(s))}endGraphic(){this.graphicRegion.endGraphic()}resize(t,e,r,i){this.flush();const s=r??this.canvas.clientWidth??this.canvas.width,a=i??this.canvas.clientHeight??this.canvas.height;switch(r!==void 0&&(this.canvas.style.width=s+"px"),i!==void 0&&(this.canvas.style.height=a+"px"),this.physicsWidth=s*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,r,i){this.updateOrthMatrix(this.projection,t,e,r,i),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,r,i,s){t[0]=2/(r-e),t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2/(s-i),t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=-(r+e)/(r-e),t[13]=-(s+i)/(s-i),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 r=Math.max(...e.map(c=>c.padding)),i=r,s=t.rawWidth+r*2,a=t.rawHeight+r*2;for(let c=0;c<2;c++)this._filterRT[c]?this._filterRT[c].resize(s,a):this._filterRT[c]=this.texture.createRenderTexture({width:s,height:a});let h=t.clone(this._filterInput),o=0;this.matrixStack.save(),this.matrixStack.identity();for(let c=0;c<e.length;c++){const u=this._filterRT[o%2];u.offsetX=0,u.offsetY=0,this.enterRenderTexture(u),this.clearRenderTexture(),this.drawSprite({texture:h,shader:e[c],offsetX:c==0?i:0,offsetY:c==0?i:0,padding:r}),this.leaveRenderTexture(),h=u,o++}return this.matrixStack.restore(),h.offsetX=-i,h.offsetY=-i,h}enterRenderTexture(t){this.flush(),t.activate(),this.gl.viewport(0,0,t.rawWidth,t.rawHeight),this.updateProjection(0,t.rawWidth,0,t.rawHeight)}clearRenderTexture(t=new f(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,r=new f(0,0,0,0)){this.enterRenderTexture(t);try{r!==null&&this.clearRenderTexture(r),e()}finally{this.leaveRenderTexture()}}withMask(t,e,r=0,i=1){this.clearMask(),this.startDrawMask(i);try{t()}finally{this.endDrawMask()}this.enterMask(r,i);try{e()}finally{this.exitMask()}}withTransform(t,e,r=0,i=0){this.matrixStack.save();try{e&&this.matrixStack.applyTransform(e,r,i),t()}finally{this.matrixStack.restore()}}withScissor(t,e,r,i,s){this.startScissor(t,e,r,i);try{s()}finally{this.endScissor()}}withBlendMode(t,e){this.setBlendMode(t);try{e()}finally{this.setBlendMode(0)}}startDrawMask(t=1,e=255){this.flush();const r=this.gl;r.stencilMask(e),r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.ALWAYS,t,e),r.stencilOp(r.KEEP,r.KEEP,r.REPLACE),this.enterRegion(this.graphicRegion,this.graphicRegion.maskShader),this.inCreateMask=!0}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,r=255){this.flush();const i=this.gl;i.colorMask(!0,!0,!0,!0),i.stencilMask(0),i.stencilFunc(t===0?i.EQUAL:i.NOTEQUAL,e,r),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),this.inCreateMask=!1}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,r,i){this.flush();const s=this.gl,a=this.physicsWidth/this.logicWidth,h=this.physicsHeight/this.logicHeight,o=Math.round(t*a),c=Math.round(this.physicsHeight-(e+i)*h),u=Math.round(r*a),l=Math.round(i*h);s.enable(s.SCISSOR_TEST),s.scissor(o,c,u,l)}endScissor(){this.flush(),this.gl.disable(this.gl.SCISSOR_TEST)}applyCamera(t){this.matrixStack.applyTransform(t);const e=this.matrixStack.curWorldM;this.matrix.invert(e)}logicToPhysics(t){return t.multiply(new g(this.physicsWidth/this.logicWidth,this.physicsHeight/this.logicHeight))}physicsToLogic(t){return t.multiply(new g(this.logicWidth/this.physicsWidth,this.logicHeight/this.physicsHeight))}cssToDevicePixel(t){return t.multiply(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,r=this.physicsHeight/this.dpr/this.logicHeight;return this.matrix.toCSSMatrix(t??this.matrixStack.curWorldM,e,r)}}function me(n){return!(n===null||typeof n!="object"||Array.isArray(n)||n instanceof g||n instanceof f)}class I{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,r,i){return new g(I.float(t,e),I.float(r,i))}static randomColor(t,e){return new f(I.float(t.r,e.r),I.float(t.g,e.g),I.float(t.b,e.b),I.float(t.a,e.a))}static pick(t){return t[I.int(0,t.length-1)]}static pickWeight(t){if(!t||t.length===0)return null;let e=0;for(const[,i]of t)e+=i;let r=Math.random()*e;for(const[i,s]of t)if(r-=s,r<=0)return i;return t[t.length-1][0]}static scalarOrRange(t,e){if(t==null)return e;if(Array.isArray(t)){const[r,i]=t;if(typeof r=="number")return I.float(r,i);if(r instanceof g)return I.vector(r.x,i.x,r.y,i.y);if(r instanceof f)return I.randomColor(r,i)}return typeof t=="number"?t:t.clone()}}const st=(n,t)=>(Array.isArray(n)?n:[n]).slice(0,t);var kt=(n=>(n.POINT="point",n.CIRCLE="circle",n.RECT="rect",n))(kt||{});const Ht=10,Gt=0,Vt=!0;class Z{components;constructor(t=1){if(!Number.isInteger(t)||t<=0)throw new RangeError("ParticleAttributeStore size must be a positive integer");this.components=Array.from({length:t},()=>({value:new b(S.Float32),delta:new b(S.Float32),damping:new b(S.Float32)}))}getArrayBuffer(){return this.components.flatMap(({value:t,delta:e,damping:r})=>[t,e,r])}update(t){for(const{value:e,delta:r,damping:i}of this.components)for(let s=0;s<e.usedElemNum;s++)e.typedArray[s]*=Math.pow(i.get(s),t),e.typedArray[s]+=r.get(s)*t}get(t,e=0){return this.components[e].value.get(t)}getComponent(t,e){if(typeof t=="number")return t;if(t instanceof g)return e===0?t.x:t.y;switch(e){case 0:return t.r;case 1:return t.g;case 2:return t.b;case 3:return t.a;default:return 0}}resolveComponent(t,e,r){return t===void 0?r:Array.isArray(t)?I.float(this.getComponent(t[0],e),this.getComponent(t[1],e)):this.getComponent(t,e)}create(t,e,r=1){const i=me(t)?t:void 0,s=i===void 0?t:void 0,a=r>0?r:1;let h=0;for(let o=0;o<this.components.length;o++){const{value:c,delta:u,damping:l}=this.components[o],m=this.getComponent(e,o),d=s===void 0?this.resolveComponent(i?.start,o,m):this.getComponent(s,o),x=i?.end===void 0?d:this.resolveComponent(i.end,o,m);c.push(d),u.push(i?.delta===void 0?(x-d)/a:this.getComponent(i.delta,o)),l.push(i?.damping??1),o===0&&(h=d)}return h}}class mt{options;emitting=!1;emitTimer=0;emitRate=Ht;emitTime=Gt;emitTimeCounter=0;localSpace=Vt;rapid;x=new b(S.Float32);y=new b(S.Float32);scaleX=new b(S.Float32);scaleY=new b(S.Float32);rotation=new b(S.Float32);color=new b(S.Uint32);remainingLife=new b(S.Float32);animations={speed:new Z,rotation:new Z,scale:new Z,color:new Z(4),velocity:new Z(2)};count=0;constructor(t,e){this.rapid=t,this.options=e,this.emitRate=e.emitRate??Ht,this.emitTime=e.emitTime??Gt,this.localSpace=e.localSpace??Vt}getAllArrayBuffer(){return[this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.color,this.remainingLife,...Object.values(this.animations).flatMap(t=>t.getArrayBuffer())]}setTexture(t){this.options.texture=t}clone(){return new mt(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(){for(const t of this.getAllArrayBuffer())t.clear();this.count=0,this.emitTimeCounter=0}emit(t){const e=this.options.maxParticles??1/0,r=Math.min(t,e-this.count);for(let i=0;i<r;i++)this.createParticle()}createParticle(){const t=I.scalarOrRange(this.options.life,1);this.remainingLife.push(t);let e=0,r=0;switch(this.options.emitShape){case"circle":{const c=Math.random()*Math.PI*2,u=(this.options.emitRadius??0)*Math.sqrt(Math.random());e=Math.cos(c)*u,r=Math.sin(c)*u;break}case"rect":{e=(Math.random()-.5)*(this.options.emitRect?.width??0),r=(Math.random()-.5)*(this.options.emitRect?.height??0);break}}const i=this.rapid.matrixStack;if(this.localSpace)this.x.push(e),this.y.push(r);else{const{x:c,y:u}=i.localToWorld(e,r);this.x.push(c),this.y.push(u)}const s=this.options.animation,a=this.animations,h=a.scale.create(s.scale,1,t),o=a.rotation.create(s.rotation,0,t);a.speed.create(s.speed,0,t),a.velocity.create(s.velocity,g.ZERO,t),a.color.create(s.color,f.White,t),this.rotation.push(o),this.scaleX.push(h),this.scaleY.push(h),this.color.pushUint32(f.packColor(a.color.get(this.count,0),a.color.get(this.count,1),a.color.get(this.count,2),a.color.get(this.count,3),this.rapid.premultipliedAlpha)),this.count+=1}update(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0){if(this.emitTimeCounter+=t,this.emitTimeCounter>=this.emitTime){const r=Math.floor(this.emitTimeCounter/this.emitTime);this.emit(this.emitRate*r),this.emitTimeCounter-=r*this.emitTime}}else{this.emitTimer+=t;const r=Math.floor(this.emitTimer*this.emitRate);r>0&&(this.emit(r),this.emitTimer-=r/this.emitRate)}const e=this.updateParticle(t);this.count-=e.length,b.removeAtIndices(e,this.getAllArrayBuffer())}updateParticle(t){const e=[],r=this.animations;Object.values(r).forEach(i=>i.update(t));for(let i=0;i<this.count;i++){if(this.remainingLife.typedArray[i]-=t,this.remainingLife.typedArray[i]<=0){e.push(i);continue}const s=r.rotation.get(i),a=r.scale.get(i),h=r.speed.get(i);this.rotation.typedArray[i]=s,this.scaleX.typedArray[i]=a,this.scaleY.typedArray[i]=a,this.color.uint32[i]=f.packColor(r.color.get(i,0),r.color.get(i,1),r.color.get(i,2),r.color.get(i,3),this.rapid.premultipliedAlpha),this.x.typedArray[i]+=(h*Math.cos(s)+r.velocity.get(i,0))*t,this.y.typedArray[i]+=(h*Math.sin(s)+r.velocity.get(i,1))*t}return e}render(){const t=this.options,e=this.localSpace?void 0:this.rapid.matrix.alloc();this.rapid.drawParticles({texture:t.texture,shader:t.shader,x:this.x.typedArray,y:this.y.typedArray,scaleX:this.scaleX.typedArray,scaleY:this.scaleY.typedArray,rotation:this.rotation.typedArray,color:this.color.typedArray,count:this.count,reverseOrder:!0,originX:t.origin?.x??.5,originY:t.origin?.y??.5,customMatrix:e})}isActive(){return this.emitting||this.count>0}oneShot(){this.emit(this.emitRate)}}const xe=`
344
+ `;const l=new Function(u)();return this.particleLoopCache.set(c,l),l}render(){if(this.instanceCount===0)return;this.prepareRender();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 r=this.rapid.matrixStack,s=this.rapid.matrix.getMatrix(this.customMatrix??r.curWorldM),a=wt(this.rapid.projection,s);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}}var ft=(n=>(n[n.EQUAL=0]="EQUAL",n[n.NOT_EQUAL=1]="NOT_EQUAL",n))(ft||{}),Dt=(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))(Dt||{}),Bt=(n=>(n[n.CanvasItem=0]="CanvasItem",n[n.Viewport=1]="Viewport",n))(Bt||{});class fe{gl;canvas;projection=new Float32Array(16);projectionDirty=!0;dpr;backgroundColor=f.Black;logicWidth=0;logicHeight=0;physicsWidth=0;physicsHeight=0;currentRegion=null;maxTextureUnits=0;matrixStack=new ee(this);matrix;spriteRegion;graphicRegion;atlasSpriteRegion;particleRegion;drawcallCount=0;inCreateMask=!1;texture;premultipliedAlpha;antialias;roundPixels;textureFilter;scaleMode;_filterRT=[null,null];_filterInput=new I;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??j.NEAREST,this.premultipliedAlpha=t.premultipliedAlpha??!0,this.roundPixels=t.roundPixels??!1,this.scaleMode=t.scaleMode??0;const e=zt(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 ut(this),this.graphicRegion=new ae(this),this.atlasSpriteRegion=new oe(this),this.particleRegion=new de(this);const r=this.canvas.clientWidth||this.canvas.width,i=this.canvas.clientHeight||this.canvas.height;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 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}getColorUint32(t){return _t(this.premultipliedAlpha,t)}enterRegion(t,e){this.currentRegion===t&&this.currentRegion.isSameShader(e)||(this.flush(),this.currentRegion=t,t.enter(e))}drawParticles(t){Pt(this,t)}drawSprite(t){Lt(this,t)}drawLine(t){Nt(this,t)}drawGraphic(t){dt(this,t)}drawRect(t){Wt(this,t)}drawCircle(t){Ot(this,t)}startGraphic(t=this.gl.TRIANGLES,e,r,i){this.enterRegion(this.graphicRegion,r),this.graphicRegion.startGraphic(i??this.matrixStack.curWorldM,t,e)}startMaskGraphic(t=this.gl.TRIANGLES,e,r){this.startGraphic(t,e,this.graphicRegion.maskShader,r)}drawMaskImage(t){It(this,t)}addRectVertex(t,e,r){const i=this.getColorUint32(r);this.addGraphicVertex(0,0,0,0,i),this.addGraphicVertex(t,0,1,0,i),this.addGraphicVertex(t,e,1,1,i),this.addGraphicVertex(0,e,0,1,i)}addCircleVertex(t,e,r=32){const i=Math.PI*2/r,s=this.getColorUint32(e);for(let a=0;a<r;a++){const h=i*a,o=Math.cos(h)*t,c=Math.sin(h)*t,u=.5+Math.cos(h)*.5,l=.5+Math.sin(h)*.5;this.addGraphicVertex(o,c,u,l,s)}}addGraphicVertex(t,e,r=0,i=0,s=4294967295){this.graphicRegion.addVertex(t,e,r,i,typeof s=="number"?s:this.getColorUint32(s))}endGraphic(){this.graphicRegion.endGraphic()}resize(t,e,r,i){this.flush();const s=r??this.canvas.clientWidth??this.canvas.width,a=i??this.canvas.clientHeight??this.canvas.height;switch(r!==void 0&&(this.canvas.style.width=s+"px"),i!==void 0&&(this.canvas.style.height=a+"px"),this.physicsWidth=s*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,r,i){this.updateOrthMatrix(this.projection,t,e,r,i),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,r,i,s){t[0]=2/(r-e),t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2/(s-i),t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=-(r+e)/(r-e),t[13]=-(s+i)/(s-i),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 r=Math.max(...e.map(c=>c.padding)),i=r,s=t.rawWidth+r*2,a=t.rawHeight+r*2;for(let c=0;c<2;c++)this._filterRT[c]?this._filterRT[c].resize(s,a):this._filterRT[c]=this.texture.createRenderTexture({width:s,height:a});let h=t.clone(this._filterInput),o=0;this.matrixStack.save(),this.matrixStack.identity();for(let c=0;c<e.length;c++){const u=this._filterRT[o%2];u.offsetX=0,u.offsetY=0,this.enterRenderTexture(u),this.clearRenderTexture(),this.drawSprite({texture:h,shader:e[c],offsetX:c==0?i:0,offsetY:c==0?i:0,padding:r}),this.leaveRenderTexture(),h=u,o++}return this.matrixStack.restore(),h.offsetX=-i,h.offsetY=-i,h}enterRenderTexture(t){this.flush(),t.activate(),this.gl.viewport(0,0,t.rawWidth,t.rawHeight),this.updateProjection(0,t.rawWidth,0,t.rawHeight)}clearRenderTexture(t=new f(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,r=new f(0,0,0,0)){this.enterRenderTexture(t);try{r!==null&&this.clearRenderTexture(r),e()}finally{this.leaveRenderTexture()}}withMask(t,e,r=0,i=1){this.clearMask(),this.startDrawMask(i);try{t()}finally{this.endDrawMask()}this.enterMask(r,i);try{e()}finally{this.exitMask()}}withTransform(t,e,r=0,i=0){this.matrixStack.save();try{e&&this.matrixStack.applyTransform(e,r,i),t()}finally{this.matrixStack.restore()}}withScissor(t,e,r,i,s){this.startScissor(t,e,r,i);try{s()}finally{this.endScissor()}}withBlendMode(t,e){this.setBlendMode(t);try{e()}finally{this.setBlendMode(0)}}startDrawMask(t=1,e=255){this.flush();const r=this.gl;r.stencilMask(e),r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.ALWAYS,t,e),r.stencilOp(r.KEEP,r.KEEP,r.REPLACE),this.enterRegion(this.graphicRegion,this.graphicRegion.maskShader),this.inCreateMask=!0}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,r=255){this.flush();const i=this.gl;i.colorMask(!0,!0,!0,!0),i.stencilMask(0),i.stencilFunc(t===0?i.EQUAL:i.NOTEQUAL,e,r),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),this.inCreateMask=!1}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,r,i){this.flush();const s=this.gl,a=this.physicsWidth/this.logicWidth,h=this.physicsHeight/this.logicHeight,o=Math.round(t*a),c=Math.round(this.physicsHeight-(e+i)*h),u=Math.round(r*a),l=Math.round(i*h);s.enable(s.SCISSOR_TEST),s.scissor(o,c,u,l)}endScissor(){this.flush(),this.gl.disable(this.gl.SCISSOR_TEST)}applyCamera(t){this.matrixStack.applyTransform(t);const e=this.matrixStack.curWorldM;this.matrix.invert(e)}logicToPhysics(t){return t.multiply(new g(this.physicsWidth/this.logicWidth,this.physicsHeight/this.logicHeight))}physicsToLogic(t){return t.multiply(new g(this.logicWidth/this.physicsWidth,this.logicHeight/this.physicsHeight))}cssToDevicePixel(t){return t.multiply(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,r=this.physicsHeight/this.dpr/this.logicHeight;return this.matrix.toCSSMatrix(t??this.matrixStack.curWorldM,e,r)}}function me(n){return!(n===null||typeof n!="object"||Array.isArray(n)||n instanceof g||n instanceof f)}class W{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,r,i){return new g(W.float(t,e),W.float(r,i))}static randomColor(t,e){return new f(W.float(t.r,e.r),W.float(t.g,e.g),W.float(t.b,e.b),W.float(t.a,e.a))}static pick(t){return t[W.int(0,t.length-1)]}static pickWeight(t){if(!t||t.length===0)return null;let e=0;for(const[,i]of t)e+=i;let r=Math.random()*e;for(const[i,s]of t)if(r-=s,r<=0)return i;return t[t.length-1][0]}static scalarOrRange(t,e){if(t==null)return e;if(Array.isArray(t)){const[r,i]=t;if(typeof r=="number")return W.float(r,i);if(r instanceof g)return W.vector(r.x,i.x,r.y,i.y);if(r instanceof f)return W.randomColor(r,i)}return typeof t=="number"?t:t.clone()}}const st=(n,t)=>(Array.isArray(n)?n:[n]).slice(0,t);var kt=(n=>(n.POINT="point",n.CIRCLE="circle",n.RECT="rect",n))(kt||{});const Ht=10,Gt=0,Vt=!0;class J{components;constructor(t=1){if(!Number.isInteger(t)||t<=0)throw new RangeError("ParticleAttributeStore size must be a positive integer");this.components=Array.from({length:t},()=>({value:new b(A.Float32),delta:new b(A.Float32),damping:new b(A.Float32)}))}getArrayBuffer(){return this.components.flatMap(({value:t,delta:e,damping:r})=>[t,e,r])}update(t){for(const{value:e,delta:r,damping:i}of this.components)for(let s=0;s<e.usedElemNum;s++)e.typedArray[s]*=Math.pow(i.get(s),t),e.typedArray[s]+=r.get(s)*t}get(t,e=0){return this.components[e].value.get(t)}getComponent(t,e){if(typeof t=="number")return t;if(t instanceof g)return e===0?t.x:t.y;switch(e){case 0:return t.r;case 1:return t.g;case 2:return t.b;case 3:return t.a;default:return 0}}resolveComponent(t,e,r){return t===void 0?r:Array.isArray(t)?W.float(this.getComponent(t[0],e),this.getComponent(t[1],e)):this.getComponent(t,e)}create(t,e,r=1){const i=me(t)?t:void 0,s=i===void 0?t:void 0,a=r>0?r:1;let h=0;for(let o=0;o<this.components.length;o++){const{value:c,delta:u,damping:l}=this.components[o],m=this.getComponent(e,o),d=s===void 0?this.resolveComponent(i?.start,o,m):this.getComponent(s,o),x=i?.end===void 0?d:this.resolveComponent(i.end,o,m);c.push(d),u.push(i?.delta===void 0?(x-d)/a:this.getComponent(i.delta,o)),l.push(i?.damping??1),o===0&&(h=d)}return h}}class mt{options;emitting=!1;emitTimer=0;emitRate=Ht;emitTime=Gt;emitTimeCounter=0;localSpace=Vt;rapid;x=new b(A.Float32);y=new b(A.Float32);scaleX=new b(A.Float32);scaleY=new b(A.Float32);rotation=new b(A.Float32);color=new b(A.Uint32);remainingLife=new b(A.Float32);animations={speed:new J,rotation:new J,scale:new J,color:new J(4),velocity:new J(2)};count=0;constructor(t,e){this.rapid=t,this.options=e,this.emitRate=e.emitRate??Ht,this.emitTime=e.emitTime??Gt,this.localSpace=e.localSpace??Vt}getAllArrayBuffer(){return[this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.color,this.remainingLife,...Object.values(this.animations).flatMap(t=>t.getArrayBuffer())]}setTexture(t){this.options.texture=t}clone(){return new mt(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(){for(const t of this.getAllArrayBuffer())t.clear();this.count=0,this.emitTimeCounter=0}emit(t){const e=this.options.maxParticles??1/0,r=Math.min(t,e-this.count);for(let i=0;i<r;i++)this.createParticle()}createParticle(){const t=W.scalarOrRange(this.options.life,1);this.remainingLife.push(t);let e=0,r=0;switch(this.options.emitShape){case"circle":{const c=Math.random()*Math.PI*2,u=(this.options.emitRadius??0)*Math.sqrt(Math.random());e=Math.cos(c)*u,r=Math.sin(c)*u;break}case"rect":{e=(Math.random()-.5)*(this.options.emitRect?.width??0),r=(Math.random()-.5)*(this.options.emitRect?.height??0);break}}const i=this.rapid.matrixStack;if(this.localSpace)this.x.push(e),this.y.push(r);else{const{x:c,y:u}=i.localToWorld(e,r);this.x.push(c),this.y.push(u)}const s=this.options.animation,a=this.animations,h=a.scale.create(s.scale,1,t),o=a.rotation.create(s.rotation,0,t);a.speed.create(s.speed,0,t),a.velocity.create(s.velocity,g.ZERO,t),a.color.create(s.color,f.White,t),this.rotation.push(o),this.scaleX.push(h),this.scaleY.push(h),this.color.pushUint32(f.packColor(a.color.get(this.count,0),a.color.get(this.count,1),a.color.get(this.count,2),a.color.get(this.count,3),this.rapid.premultipliedAlpha)),this.count+=1}update(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0){if(this.emitTimeCounter+=t,this.emitTimeCounter>=this.emitTime){const r=Math.floor(this.emitTimeCounter/this.emitTime);this.emit(this.emitRate*r),this.emitTimeCounter-=r*this.emitTime}}else{this.emitTimer+=t;const r=Math.floor(this.emitTimer*this.emitRate);r>0&&(this.emit(r),this.emitTimer-=r/this.emitRate)}const e=this.updateParticle(t);this.count-=e.length,b.removeAtIndices(e,this.getAllArrayBuffer())}updateParticle(t){const e=[],r=this.animations;Object.values(r).forEach(i=>i.update(t));for(let i=0;i<this.count;i++){if(this.remainingLife.typedArray[i]-=t,this.remainingLife.typedArray[i]<=0){e.push(i);continue}const s=r.rotation.get(i),a=r.scale.get(i),h=r.speed.get(i);this.rotation.typedArray[i]=s,this.scaleX.typedArray[i]=a,this.scaleY.typedArray[i]=a,this.color.uint32[i]=f.packColor(r.color.get(i,0),r.color.get(i,1),r.color.get(i,2),r.color.get(i,3),this.rapid.premultipliedAlpha),this.x.typedArray[i]+=(h*Math.cos(s)+r.velocity.get(i,0))*t,this.y.typedArray[i]+=(h*Math.sin(s)+r.velocity.get(i,1))*t}return e}render(){const t=this.options,e=this.localSpace?void 0:this.rapid.matrix.alloc();this.rapid.drawParticles({texture:t.texture,shader:t.shader,x:this.x.typedArray,y:this.y.typedArray,scaleX:this.scaleX.typedArray,scaleY:this.scaleY.typedArray,rotation:this.rotation.typedArray,color:this.color.typedArray,count:this.count,reverseOrder:!0,originX:t.origin?.x??.5,originY:t.origin?.y??.5,customMatrix:e})}isActive(){return this.emitting||this.count>0}oneShot(){this.emit(this.emitRate)}}const xe=`
345
345
  uniform mediump int uLightTextureId[%TEXTURE_NUM%];
346
346
 
347
347
  uniform sampler2D uNormalMap;
@@ -394,4 +394,4 @@ void light_fragment(inout vec4 color, in vec2 vRegion) {
394
394
 
395
395
  color.rgb = color.rgb * (uAmbientColor + totalDiffuse) + totalSpecular;
396
396
  }
397
- `,ge="void light_vertex(inout vec4 p, vec2 u) {}",J=8;class Xt extends rt{constructor(t,e="",r="",i=0,s){super(t,e,r,i+2,s),this.prefix.push("light_")}getGLShader(t,e,r,i){const s=j(xe,t.getMaxTexutreUnit(this),"layer","lightUV","lightTex = ");return i=this.replaceCustomCode(i,s),r=this.replaceCustomCode(r,ge),super.getGLShader(t,e,r,i)}}class pe{shader;rapid;rt;constructor(t){this.rapid=t,this.shader=new Xt(t),this.rt=t.texture.createRenderTexture({width:0,height:0})}lightShadow(t,e,r){if(r.length===0)return;const i=this.rapid,s=typeof e=="number"?e:e.world,a=new g(t.rawWidth*.5,t.rawHeight*.5),h=r.map(c=>{const u=i.matrixStack.localToWorld(c.x,c.y),l=i.matrix.worldToLocal(s,u.x,u.y);return new g((l.x+.5)*t.rawWidth,(l.y+.5)*t.rawHeight)});this.rt.resize(t.rawWidth,t.rawHeight);const o=Math.hypot(t.rawWidth,t.rawHeight)*.5*1.05;return i.drawToRenderTexture(this.rt,()=>{i.withMask(()=>{i.startMaskGraphic(i.gl.TRIANGLES);for(let c=0;c<h.length;c++){const u=h[c],l=h[(c+1)%h.length],m=u.subtract(a).normalized(),d=l.subtract(a).normalized(),x=Math.max(-.999,Math.min(1,m.dot(d))),p=Math.sqrt((1+x)*.5),y=o/p,T=a.add(m.multiply(y)),R=a.add(d.multiply(y));i.addGraphicVertex(u.x,u.y),i.addGraphicVertex(l.x,l.y),i.addGraphicVertex(R.x,R.y),i.addGraphicVertex(u.x,u.y),i.addGraphicVertex(R.x,R.y),i.addGraphicVertex(T.x,T.y)}i.endGraphic()},()=>{i.drawSprite({texture:t})},ft.NOT_EQUAL)}),this.rt}setupLight(t){const e=t.customShader??this.shader,r=st(t.lightMatrix,J),i=st(t.color,J),s=st(t.lightHeight,J),a=st(t.lightTexture,J);return e.setUniforms({uResolution:[this.rapid.physicsWidth,this.rapid.physicsHeight],uLogicalResolution:[this.rapid.logicWidth,this.rapid.logicHeight],uNormalMap:t.normalMap.glTexture,uLightTextureId:a.map(h=>h.glTexture),uLightCount:r.length,uLightMatrix:Float32Array.from(r.flatMap(h=>Array.from(this.rapid.matrix.getMatrix(typeof h=="number"?h:h.world)))),uLightColor:Float32Array.from(r.flatMap((h,o)=>{const c=i[o]??i[0];return c?[c.r/255,c.g/255,c.b/255,c.a/255]:[1,1,1,1]})),uLightHeight:Float32Array.from(r.map((h,o)=>s[o]??s[0]??80)),uMetallic:t.metallic??.8,uRoughness:t.roughness??.15,uAmbientColor:t.ambientColor?[t.ambientColor.r/255,t.ambientColor.g/255,t.ambientColor.b/255]:[.1,.1,.15],uNormalScale:[t.normalScaleX??1,t.normalScaleY??1]}),e}}v.BaseTexture=B,v.BlendMode=Dt,v.CanvasScaleMode=Bt,v.Color=f,v.CustomGlShader=rt,v.GLShader=ot,v.Light=pe,v.LightShader=Xt,v.LineTextureMode=At,v.MAX_LIGHTS=J,v.MaskType=ft,v.ParticleEmitter=mt,v.ParticleShape=kt,v.Rapid=fe,v.RenderTexture=vt,v.TextTexture=yt,v.Texture=N,v.TextureFilterMode=$,v.TextureManager=pt,v.TextureWrapMode=X,v.Vec2=g,v.composeProjectionWithAffine=wt,v.drawCircle=Ot,v.drawGraphic=dt,v.drawLine=Nt,v.drawMaskImage=It,v.drawParticles=Pt,v.drawRect=Wt,v.drawSprite=Lt,v.getColorUint32=_t,v.getLineGeometry=Ct,v.getLineNormal=Ut,v.multiplyMat4=St,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
397
+ `,ge="void light_vertex(inout vec4 p, vec2 u) {}",tt=8;class Xt extends rt{constructor(t,e="",r="",i=0,s){super(t,e,r,i+2,s),this.prefix.push("light_")}getGLShader(t,e,r,i){const s=K(xe,t.getMaxTexutreUnit(this),"layer","lightUV","lightTex = ");return i=this.replaceCustomCode(i,s),r=this.replaceCustomCode(r,ge),super.getGLShader(t,e,r,i)}}class pe{shader;rapid;rt;constructor(t){this.rapid=t,this.shader=new Xt(t),this.rt=t.texture.createRenderTexture({width:0,height:0})}lightShadow(t,e,r){if(r.length===0)return;const i=this.rapid,s=typeof e=="number"?e:e.world,a=new g(t.rawWidth*.5,t.rawHeight*.5),h=r.map(c=>{const u=i.matrixStack.localToWorld(c.x,c.y),l=i.matrix.worldToLocal(s,u.x,u.y);return new g((l.x+.5)*t.rawWidth,(l.y+.5)*t.rawHeight)});this.rt.resize(t.rawWidth,t.rawHeight);const o=Math.hypot(t.rawWidth,t.rawHeight)*.5*1.05;return i.drawToRenderTexture(this.rt,()=>{i.withMask(()=>{i.startMaskGraphic(i.gl.TRIANGLES);for(let c=0;c<h.length;c++){const u=h[c],l=h[(c+1)%h.length],m=u.subtract(a).normalized(),d=l.subtract(a).normalized(),x=Math.max(-.999,Math.min(1,m.dot(d))),v=Math.sqrt((1+x)*.5),T=o/v,y=a.add(m.multiply(T)),R=a.add(d.multiply(T));i.addGraphicVertex(u.x,u.y),i.addGraphicVertex(l.x,l.y),i.addGraphicVertex(R.x,R.y),i.addGraphicVertex(u.x,u.y),i.addGraphicVertex(R.x,R.y),i.addGraphicVertex(y.x,y.y)}i.endGraphic()},()=>{i.drawSprite({texture:t})},ft.NOT_EQUAL)}),this.rt}setupLight(t){const e=t.customShader??this.shader,r=st(t.lightMatrix,tt),i=st(t.color,tt),s=st(t.lightHeight,tt),a=st(t.lightTexture,tt);return e.setUniforms({uResolution:[this.rapid.physicsWidth,this.rapid.physicsHeight],uLogicalResolution:[this.rapid.logicWidth,this.rapid.logicHeight],uNormalMap:t.normalMap.glTexture,uLightTextureId:a.map(h=>h.glTexture),uLightCount:r.length,uLightMatrix:Float32Array.from(r.flatMap(h=>Array.from(this.rapid.matrix.getMatrix(typeof h=="number"?h:h.world)))),uLightColor:Float32Array.from(r.flatMap((h,o)=>{const c=i[o]??i[0];return c?[c.r/255,c.g/255,c.b/255,c.a/255]:[1,1,1,1]})),uLightHeight:Float32Array.from(r.map((h,o)=>s[o]??s[0]??80)),uMetallic:t.metallic??.8,uRoughness:t.roughness??.15,uAmbientColor:t.ambientColor?[t.ambientColor.r/255,t.ambientColor.g/255,t.ambientColor.b/255]:[.1,.1,.15],uNormalScale:[t.normalScaleX??1,t.normalScaleY??1]}),e}}p.BaseTexture=V,p.BlendMode=Dt,p.CanvasScaleMode=Bt,p.Color=f,p.CustomGlShader=rt,p.GLShader=ot,p.Light=pe,p.LightShader=Xt,p.LineTextureMode=At,p.MAX_LIGHTS=tt,p.MaskType=ft,p.ParticleEmitter=mt,p.ParticleShape=kt,p.Rapid=fe,p.RenderTexture=vt,p.TextTexture=yt,p.Texture=I,p.TextureFilterMode=j,p.TextureManager=pt,p.TextureWrapMode=z,p.Vec2=g,p.composeProjectionWithAffine=wt,p.drawCircle=Ot,p.drawGraphic=dt,p.drawLine=Nt,p.drawMaskImage=It,p.drawParticles=Pt,p.drawRect=Wt,p.drawSprite=Lt,p.getColorUint32=_t,p.getLineGeometry=Ct,p.getLineNormal=Ut,p.multiplyMat4=St,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
package/dist/texture.d.ts CHANGED
@@ -247,6 +247,7 @@ export interface ITextStyle {
247
247
  strokeThickness?: number;
248
248
  align?: "left" | "center" | "right";
249
249
  lineHeight?: number;
250
+ baseline?: CanvasTextBaseline;
250
251
  }
251
252
  export interface ITextOptions extends ITextStyle, ITextureOptions {
252
253
  text?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rapid-render",
3
3
  "private": false,
4
- "version": "1.0.18",
4
+ "version": "1.0.19",
5
5
  "type": "module",
6
6
  "description": "A high-performance lightweight WebGL 2D renderer for browser games.",
7
7
  "repository": "https://github.com/Nightre/Rapid.js",