rapid-render 1.0.17 → 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.
@@ -154,7 +154,7 @@ class m {
154
154
  static Transparent = new m(0, 0, 0, 0);
155
155
  }
156
156
  var tt = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(tt || {}), q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(q || {});
157
- class Ct {
157
+ class bt {
158
158
  render;
159
159
  cache = /* @__PURE__ */ new Map();
160
160
  constructor(t) {
@@ -163,29 +163,29 @@ class Ct {
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 = V.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 = V.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
- return new _t(this.render, t);
181
+ return new Ut(this.render, t);
182
182
  }
183
183
  createTextTexture(t) {
184
- return new Pt(this.render, t);
184
+ return new _t(this.render, t);
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 Ct {
199
199
  });
200
200
  }
201
201
  }
202
- class V {
202
+ class X {
203
203
  glTexture = null;
204
204
  width;
205
205
  height;
@@ -210,7 +210,7 @@ class V {
210
210
  }
211
211
  static fromSource(t, e, r = {}) {
212
212
  const i = rt(t, e, r);
213
- return new V(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 V {
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 V(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 _t extends N {
286
+ class Ut extends D {
287
287
  framebuffer;
288
288
  renderbuffer;
289
289
  gl;
@@ -293,7 +293,7 @@ class _t 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 V(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
  }
@@ -337,7 +337,7 @@ class _t extends N {
337
337
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
338
338
  }
339
339
  }
340
- const Lt = {
340
+ const Ct = {
341
341
  fontFamily: "Arial",
342
342
  fontSize: 24,
343
343
  fontWeight: "normal",
@@ -346,7 +346,7 @@ const Lt = {
346
346
  align: "left",
347
347
  lineHeight: 1
348
348
  };
349
- class Pt extends N {
349
+ class _t extends D {
350
350
  canvas;
351
351
  ctx;
352
352
  render;
@@ -355,12 +355,12 @@ class Pt extends N {
355
355
  options;
356
356
  flipY = !0;
357
357
  constructor(t, e) {
358
- super(), this.render = t, this._style = { ...Lt, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
358
+ super(), this.render = t, this._style = { ...Ct, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
359
359
  const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
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 V(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,34 +379,42 @@ class Pt 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
- const Nt = (n, t = !1, e = !0) => {
417
+ const Lt = (n, t = !1, e = !0) => {
410
418
  const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
411
419
  if (!r)
412
420
  throw new Error("WebGL2 is not supported in this browser.");
@@ -420,7 +428,7 @@ const Nt = (n, t = !1, e = !0) => {
420
428
  throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
421
429
  }
422
430
  return r;
423
- }, It = (n, t, e) => {
431
+ }, Pt = (n, t, e) => {
424
432
  var r = n.createProgram(), i = dt(n, t, 35633), s = dt(n, e, 35632);
425
433
  if (!r)
426
434
  throw new Error("Unable to create program shader");
@@ -458,7 +466,7 @@ function rt(n, t, e) {
458
466
  }
459
467
  return r.bindTexture(r.TEXTURE_2D, null), i;
460
468
  }
461
- function D(n, t, e = "vTextureId", r = "uv", i = "return") {
469
+ function K(n, t, e = "vTextureId", r = "uv", i = "return") {
462
470
  if (n.includes("%TEXTURE_NUM%") && (n = n.replaceAll("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
463
471
  let s = "";
464
472
  for (let a = 0; a < t; a++)
@@ -467,15 +475,15 @@ function D(n, t, e = "vTextureId", r = "uv", i = "return") {
467
475
  }
468
476
  return n;
469
477
  }
470
- const Wt = 5126, ot = 5121;
471
- function Ot(n, t, e) {
478
+ const Nt = 5126, ot = 5121;
479
+ function It(n, t, e) {
472
480
  n.vertexAttribDivisor(t, e);
473
481
  }
474
- function Et(n, t, e, r, i) {
482
+ function yt(n, t, e, r, i) {
475
483
  n.drawArraysInstanced(t, e, r, i);
476
484
  }
477
- let Ft = 0;
478
- class Rt {
485
+ let Wt = 0;
486
+ class Tt {
479
487
  program;
480
488
  attributeLoc = {};
481
489
  uniformLoc = {};
@@ -484,11 +492,11 @@ class Rt {
484
492
  uniformType = {};
485
493
  uniformIsArray = {};
486
494
  gl;
487
- shaderId = Ft++;
495
+ shaderId = Wt++;
488
496
  // for debug
489
497
  vao;
490
498
  constructor(t, e, r, i) {
491
- this.gl = t, this.program = It(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
499
+ this.gl = t, this.program = Pt(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
492
500
  }
493
501
  use() {
494
502
  this.gl.useProgram(this.program);
@@ -504,7 +512,7 @@ class Rt {
504
512
  const r = this.uniformLoc[t];
505
513
  if (r === void 0) return;
506
514
  const i = this.uniformType[t], s = this.uniformIsArray[t];
507
- Dt(this.gl, r, i, e, s);
515
+ Ot(this.gl, r, i, e, s);
508
516
  }
509
517
  setUniforms(t) {
510
518
  for (const e in t)
@@ -518,11 +526,11 @@ class Rt {
518
526
  r.vertexAttribPointer(
519
527
  e,
520
528
  t.size,
521
- t.type ?? Wt,
529
+ t.type ?? Nt,
522
530
  t.normalized ?? !1,
523
531
  t.stride,
524
532
  t.offset ?? 0
525
- ), r.enableVertexAttribArray(e), Ot(r, e, t.divisor ?? 0);
533
+ ), r.enableVertexAttribArray(e), It(r, e, t.divisor ?? 0);
526
534
  }
527
535
  setAttributes(t) {
528
536
  for (const e of t)
@@ -548,7 +556,7 @@ class Rt {
548
556
  }
549
557
  }
550
558
  }
551
- function Dt(n, t, e, r, i = !1) {
559
+ function Ot(n, t, e, r, i = !1) {
552
560
  switch (e) {
553
561
  // scalars
554
562
  case "float":
@@ -586,10 +594,10 @@ function Dt(n, t, e, r, i = !1) {
586
594
  return n.uniformMatrix3x2fv(t, !1, r);
587
595
  // fallback: guess by value shape
588
596
  default:
589
- return Bt(n, t, r);
597
+ return Ft(n, t, r);
590
598
  }
591
599
  }
592
- function Bt(n, t, e) {
600
+ function Ft(n, t, e) {
593
601
  if (typeof e == "number")
594
602
  return n.uniform1f(t, e);
595
603
  const r = e;
@@ -642,13 +650,16 @@ class ct {
642
650
  const r = this.glshader.get(t);
643
651
  r && (Object.keys(e).length > 0 && r.setUniforms(e), this.uniformDirty.has(t) && (r.setUniforms(this.uniforms), this.uniformDirty.delete(t)));
644
652
  }
653
+ replaceCustomCode(t, e) {
654
+ return t = t.replace("// CUSTOM_CODE", e + "// CUSTOM_CODE"), t;
655
+ }
645
656
  getGLShader(t, e, r, i) {
646
657
  if (this.glshader.has(e))
647
658
  return this.glshader.get(e);
648
659
  if (i == null || r == null)
649
660
  return console.warn("CustomGlShader: missing base shader for " + e), null;
650
661
  const s = this.prefix.length == 0 ? [""] : this.prefix;
651
- r = r.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "vertex(position, vRegion);").join("")), r = r.replace("// CUSTOM_CODE", this.vs), i = i.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "fragment(fragColor, vRegion);").join("")), i = i.replace("// CUSTOM_CODE", this.fs);
662
+ 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);
652
663
  const a = t.createShader(r, i);
653
664
  return a.isCustom = !0, a.padding = this.padding, this.glshader.set(e, a), this.uniformDirty.add(e), a;
654
665
  }
@@ -656,7 +667,7 @@ class ct {
656
667
  this.glshader.forEach((t) => t.destroy());
657
668
  }
658
669
  }
659
- class Mt {
670
+ class Et {
660
671
  constructor(t) {
661
672
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
662
673
  }
@@ -673,6 +684,7 @@ class Mt {
673
684
  fs = "";
674
685
  usedTextures = [];
675
686
  usedTexturePadding = [];
687
+ extraTextureUnit = 0;
676
688
  createBuffer() {
677
689
  }
678
690
  createDefaultShader() {
@@ -698,11 +710,16 @@ class Mt {
698
710
  const i = this.findTextureUnit(t, e, r);
699
711
  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;
700
712
  }
713
+ getMaxTexutreUnit(t) {
714
+ return this.rapid.maxTextureUnits - this.extraTextureUnit - (t?.usedTextureUnitNum ?? 0);
715
+ }
701
716
  createShader(t, e) {
702
- return new Rt(this.gl, t, e);
717
+ const r = this.getMaxTexutreUnit();
718
+ return e = K(e, r), t = K(t, r), new Tt(this.gl, t, e);
703
719
  }
704
720
  createCustomShader(t) {
705
- return t.getGLShader(this, this.KEY, this.vs, this.fs);
721
+ const e = this.getMaxTexutreUnit(t), r = K(this.fs, e), i = K(this.vs, e);
722
+ return t.getGLShader(this, this.KEY, i, r);
706
723
  }
707
724
  getCustomShader(t) {
708
725
  if (!t)
@@ -759,8 +776,8 @@ class Mt {
759
776
  return !1;
760
777
  }
761
778
  }
762
- var S = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(S || {});
763
- class A {
779
+ var A = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(A || {});
780
+ class b {
764
781
  usedElemNum;
765
782
  typedArray;
766
783
  arrayType;
@@ -859,7 +876,7 @@ class A {
859
876
  return this.usedElemNum;
860
877
  }
861
878
  }
862
- class ut extends A {
879
+ class ut extends b {
863
880
  buffer;
864
881
  gl;
865
882
  dirty = !0;
@@ -970,8 +987,8 @@ void main(void) {\r
970
987
  \r
971
988
  // CUSTOM_CODE_CALL\r
972
989
  }\r
973
- `, $ = 48, kt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
974
- class lt extends Mt {
990
+ `, z = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
991
+ class lt extends Et {
975
992
  instanceBuffer;
976
993
  quadBuffer;
977
994
  instanceCount = 0;
@@ -983,30 +1000,25 @@ class lt extends Mt {
983
1000
  }
984
1001
  createBuffer() {
985
1002
  const t = this.gl;
986
- this.quadBuffer = new ut(t, S.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
987
- for (const e of kt) this.quadBuffer.pushFloat32(e);
988
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new ut(t, S.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1003
+ this.quadBuffer = new ut(t, A.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1004
+ for (const e of Dt) this.quadBuffer.pushFloat32(e);
1005
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new ut(t, A.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
989
1006
  }
990
1007
  createDefaultShader() {
991
- const t = this.rapid, e = D(ft, t.maxTextureUnits), r = D(et, t.maxTextureUnits);
992
- return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1008
+ return this.vs = et, this.fs = ft, this.defaultShader = this.createShader(et, ft), this.defaultShader;
993
1009
  }
994
1010
  createShader(t, e) {
995
1011
  const r = super.createShader(t, e);
996
1012
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
997
- { name: "aMatrixRow0", size: 3, stride: $, offset: 0, divisor: 1 },
998
- { name: "aMatrixRow1", size: 3, stride: $, offset: 12, divisor: 1 },
999
- { name: "aUVRect", size: 4, stride: $, offset: 24, divisor: 1 },
1000
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: $, offset: 40, divisor: 1 },
1001
- { name: "aTextureId", size: 1, type: ot, stride: $, 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 }
1002
1018
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1003
1019
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1004
1020
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1005
1021
  }
1006
- createCustomShader(t) {
1007
- const e = D(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = D(et, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1008
- return t.getGLShader(this, this.KEY, r, e);
1009
- }
1010
1022
  drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, h = 4294967295, o = 0, c = 0, u = !1, l = !1, f = !1) {
1011
1023
  const d = e * 6, x = this.matrixStore.data;
1012
1024
  this.drawSpriteAffine(
@@ -1029,23 +1041,23 @@ class lt extends Mt {
1029
1041
  f
1030
1042
  );
1031
1043
  }
1032
- 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) {
1033
- 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(
1034
1046
  t.glTexture,
1035
1047
  d / E.width,
1036
1048
  x / E.height
1037
- ), b = this.instanceBuffer, M = b.usedElemNum;
1038
- b.resize(12);
1039
- const C = b.float32, B = b.uint32, k = y ? _ : w, H = y ? w : _, I = k + 2 * d, F = H + 2 * x, X = L - d, z = W - x, R = this.localSpriteMatrix;
1040
- y ? (R[0] = 0, R[1] = v ? F : -F, R[2] = p ? -I : I, R[3] = 0, R[4] = X + (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] = X + (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));
1041
1053
  const U = this.worldSpriteMatrix;
1042
- 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, B[M + 10] = f, B[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++;
1043
1055
  }
1044
1056
  render() {
1045
1057
  if (this.instanceCount === 0) return;
1046
1058
  this.prepareRender();
1047
1059
  const t = this.gl, e = this.currentShader;
1048
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Et(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1060
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1049
1061
  }
1050
1062
  resetRender() {
1051
1063
  super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
@@ -1055,13 +1067,13 @@ class lt extends Mt {
1055
1067
  }
1056
1068
  }
1057
1069
  const T = 6;
1058
- class Ht {
1070
+ class Bt {
1059
1071
  matrixCount = 0;
1060
1072
  buffer;
1061
1073
  data;
1062
1074
  temporary = -1;
1063
1075
  constructor(t = 10) {
1064
- this.buffer = new A(S.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();
1065
1077
  }
1066
1078
  alloc() {
1067
1079
  const t = this.allocDirty();
@@ -1100,8 +1112,8 @@ class Ht {
1100
1112
  this.multiplyOut(t, t, e);
1101
1113
  }
1102
1114
  multiplyOut(t, e, r) {
1103
- 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];
1104
- 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;
1105
1117
  }
1106
1118
  invert(t) {
1107
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];
@@ -1161,19 +1173,19 @@ class Ht {
1161
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;
1162
1174
  }
1163
1175
  multiplyAffine(t, e, r, i, s, a, h, o) {
1164
- 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];
1165
- 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;
1166
1178
  }
1167
1179
  }
1168
- class Gt {
1169
- matrix = new Ht();
1180
+ class kt {
1181
+ matrix = new Bt();
1170
1182
  step = 0;
1171
- stack = new A(S.Uint32);
1172
- stepWorldM = new A(S.Uint32);
1173
- stepAction = new A(S.Uint32);
1174
- stepParentM = new A(S.Uint32);
1175
- stepClose = new A(S.Uint32);
1176
- stepStack = new A(S.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);
1177
1189
  curLocalM = -1;
1178
1190
  curWorldM = -1;
1179
1191
  rapid;
@@ -1291,40 +1303,40 @@ class Gt {
1291
1303
  t.offset && (l += t.offset.x, f += t.offset.y);
1292
1304
  const d = t.origin;
1293
1305
  d !== void 0 && (typeof d == "number" ? (l -= d * e, f -= d * r) : (l -= d.x * e, f -= d.y * r));
1294
- 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;
1295
1307
  if (i !== -1) {
1296
1308
  this.matrix.multiplyAffine(
1297
1309
  this.curWorldM,
1298
1310
  i,
1299
- v,
1300
1311
  y,
1312
+ v,
1301
1313
  E,
1302
- w,
1314
+ S,
1303
1315
  _,
1304
- L
1316
+ P
1305
1317
  );
1306
1318
  return;
1307
1319
  }
1308
1320
  this.matrix.multiplyAffineInPlace(
1309
1321
  this.curLocalM,
1310
- v,
1311
1322
  y,
1323
+ v,
1312
1324
  E,
1313
- w,
1325
+ S,
1314
1326
  _,
1315
- L
1327
+ P
1316
1328
  ), this.matrix.multiplyAffineInPlace(
1317
1329
  this.curWorldM,
1318
- v,
1319
1330
  y,
1331
+ v,
1320
1332
  E,
1321
- w,
1333
+ S,
1322
1334
  _,
1323
- L
1335
+ P
1324
1336
  );
1325
1337
  }
1326
1338
  }
1327
- const Vt = `#version 300 es\r
1339
+ const Ht = `#version 300 es\r
1328
1340
  precision highp float;\r
1329
1341
  \r
1330
1342
  in vec2 aPosition;\r
@@ -1355,7 +1367,7 @@ void main(void) {\r
1355
1367
  // CUSTOM_CODE_CALL\r
1356
1368
  gl_Position = u_projection * position;\r
1357
1369
  }\r
1358
- `, Xt = `#version 300 es\r
1370
+ `, Gt = `#version 300 es\r
1359
1371
  precision mediump float;\r
1360
1372
  \r
1361
1373
  in vec4 vColor;\r
@@ -1363,6 +1375,7 @@ in vec2 vRegion;\r
1363
1375
  in vec4 vUVRect;\r
1364
1376
  \r
1365
1377
  uniform sampler2D uTexture;\r
1378
+ uniform sampler2D uTextures[%TEXTURE_NUM%];\r
1366
1379
  uniform int uUseTexture;\r
1367
1380
  \r
1368
1381
  out vec4 fragColor;\r
@@ -1401,7 +1414,7 @@ void main(void) {\r
1401
1414
  fragColor = sampleTexture(vRegion) * vColor;\r
1402
1415
  // CUSTOM_CODE_CALL\r
1403
1416
  }\r
1404
- `, Yt = `#version 300 es\r
1417
+ `, Vt = `#version 300 es\r
1405
1418
  precision highp float;\r
1406
1419
  \r
1407
1420
  in vec2 aPosition;\r
@@ -1424,7 +1437,7 @@ void main(void) {\r
1424
1437
  );\r
1425
1438
  gl_Position = u_projection * position;\r
1426
1439
  }\r
1427
- `, zt = `#version 300 es\r
1440
+ `, Xt = `#version 300 es\r
1428
1441
  precision mediump float;\r
1429
1442
  \r
1430
1443
  in vec2 vRegion;\r
@@ -1444,10 +1457,11 @@ void main(void) {\r
1444
1457
  discard;\r
1445
1458
  }\r
1446
1459
  }\r
1447
- `, j = 20;
1448
- class $t extends Mt {
1460
+ `, $ = 20;
1461
+ class Yt extends Et {
1449
1462
  vertexBuffer;
1450
1463
  vertexCount = 0;
1464
+ extraTextureUnit = 1;
1451
1465
  matrixIndex = -1;
1452
1466
  drawMode = this.gl.TRIANGLES;
1453
1467
  texture;
@@ -1458,24 +1472,24 @@ class $t extends Mt {
1458
1472
  }
1459
1473
  createBuffer() {
1460
1474
  const t = this.gl;
1461
- this.vertexBuffer = new ut(t, S.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Yt, zt);
1475
+ this.vertexBuffer = new ut(t, A.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Vt, Xt);
1462
1476
  }
1463
1477
  createDefaultShader() {
1464
- return this.vs = Vt, this.fs = Xt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1478
+ return this.vs = Ht, this.fs = Gt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1465
1479
  }
1466
1480
  createMaskShader(t, e) {
1467
- const r = this.gl, i = new Rt(r, t, e);
1481
+ const r = this.gl, i = new Tt(r, t, e);
1468
1482
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
1469
- { name: "aPosition", size: 2, type: r.FLOAT, stride: j - 4, offset: 0, divisor: 0 },
1470
- { name: "aUV", size: 2, type: r.FLOAT, stride: j - 4, offset: 8, divisor: 0 }
1483
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: $ - 4, offset: 0, divisor: 0 },
1484
+ { name: "aUV", size: 2, type: r.FLOAT, stride: $ - 4, offset: 8, divisor: 0 }
1471
1485
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1472
1486
  }
1473
1487
  createShader(t, e) {
1474
1488
  const r = this.gl, i = super.createShader(t, e);
1475
1489
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
1476
- { name: "aPosition", size: 2, type: r.FLOAT, stride: j, offset: 0, divisor: 0 },
1477
- { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: j, offset: 8, divisor: 0 },
1478
- { name: "aUV", size: 2, type: r.FLOAT, stride: j, offset: 12, divisor: 0 }
1490
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: $, offset: 0, divisor: 0 },
1491
+ { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: $, offset: 8, divisor: 0 },
1492
+ { name: "aUV", size: 2, type: r.FLOAT, stride: $, offset: 12, divisor: 0 }
1479
1493
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1480
1494
  }
1481
1495
  startGraphic(t, e = this.gl.TRIANGLES, r) {
@@ -1618,7 +1632,7 @@ class g {
1618
1632
  return new g(Math.cos(t), Math.sin(t));
1619
1633
  }
1620
1634
  }
1621
- const jt = (n, t) => {
1635
+ const zt = (n, t) => {
1622
1636
  const [e, r, i, s, a, h] = t, o = new Float32Array([
1623
1637
  e,
1624
1638
  i,
@@ -1637,8 +1651,8 @@ const jt = (n, t) => {
1637
1651
  0,
1638
1652
  1
1639
1653
  ]);
1640
- return Kt(o, n);
1641
- }, Kt = (n, t) => {
1654
+ return $t(o, n);
1655
+ }, $t = (n, t) => {
1642
1656
  const e = new Float32Array(16);
1643
1657
  for (let r = 0; r < 4; r++)
1644
1658
  for (let i = 0; i < 4; i++) {
@@ -1649,15 +1663,15 @@ const jt = (n, t) => {
1649
1663
  }
1650
1664
  return e;
1651
1665
  };
1652
- var qt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(qt || {});
1666
+ var jt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(jt || {});
1653
1667
  const nt = 10, mt = (n, t, e, r, i, s) => {
1654
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);
1655
1669
  for (let l = 0; l < nt; l++) {
1656
- 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);
1657
- 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));
1658
1672
  }
1659
1673
  return { vertices: a, uv: h };
1660
- }, Qt = (n, t = !1) => {
1674
+ }, Kt = (n, t = !1) => {
1661
1675
  const e = [];
1662
1676
  if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
1663
1677
  const r = 4, i = 1e-3, s = n.length;
@@ -1697,23 +1711,23 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1697
1711
  } else
1698
1712
  e.push(h(n[o - 1], n[o], n[o + 1]));
1699
1713
  return { normals: e, length: a };
1700
- }, Zt = (n) => {
1714
+ }, qt = (n) => {
1701
1715
  const t = n.points;
1702
1716
  if (t.length < 2) return { vertices: [], uv: [] };
1703
- const { normals: e, length: r } = Qt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], h = n.roundCap || !1, o = n.textureMode || 0;
1717
+ const { normals: e, length: r } = Kt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], h = n.roundCap || !1, o = n.textureMode || 0;
1704
1718
  let c = 0;
1705
1719
  const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
1706
1720
  for (let f = 0; f < l; f++) {
1707
- 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);
1708
- let M = 0, C = 0;
1709
- o === 0 ? (M = c / r, C = (c + b) / r) : (M = c / u, C = M + b / u);
1710
- const B = new g(M, 0), k = new g(M, 1), H = new g(C, 0), I = new g(C, 1);
1711
- s.push(_), a.push(B), s.push(L), a.push(k), s.push(W), a.push(H), s.push(W), a.push(H), s.push(O), a.push(I), s.push(L), a.push(k), 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;
1712
1726
  }
1713
1727
  if (h && !n.closed) {
1714
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);
1715
1729
  s.push(...p.vertices), a.push(...p.uv);
1716
- 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);
1717
1731
  s.push(..._.vertices), a.push(..._.uv);
1718
1732
  }
1719
1733
  return { vertices: s, uv: a };
@@ -1736,7 +1750,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1736
1750
  i
1737
1751
  ), i;
1738
1752
  }
1739
- }, Jt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, te = 2, ee = (n, t) => {
1753
+ }, Qt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, Zt = 2, Jt = (n, t) => {
1740
1754
  const e = Q(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
1741
1755
  if (!r?.base || n.inCreateMask)
1742
1756
  return;
@@ -1745,7 +1759,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1745
1759
  let s = r.uvX, a = r.uvY, h = r.uvW, o = r.uvH;
1746
1760
  const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
1747
1761
  let l = t.padding ?? i.currentShader.padding;
1748
- r.isAtlas && (l += te);
1762
+ r.isAtlas && (l += Zt);
1749
1763
  const f = s <= h ? l : -l, d = a <= o ? l : -l;
1750
1764
  i.drawSprite(
1751
1765
  r,
@@ -1761,7 +1775,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1761
1775
  u,
1762
1776
  r.isRotated
1763
1777
  );
1764
- }, re = (n, t) => {
1778
+ }, te = (n, t) => {
1765
1779
  const e = n.particleRegion;
1766
1780
  n.enterRegion(e, t.shader);
1767
1781
  const r = t.texture, i = t.count ?? t.x.length, s = t.color;
@@ -1787,7 +1801,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1787
1801
  t.reverseOrder,
1788
1802
  t.customMatrix
1789
1803
  );
1790
- }, wt = (n, t) => {
1804
+ }, Mt = (n, t) => {
1791
1805
  if (t.points.length === 0) return;
1792
1806
  const e = Q(n, t, 0, 0);
1793
1807
  n.startGraphic(
@@ -1807,17 +1821,17 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1807
1821
  );
1808
1822
  }
1809
1823
  n.endGraphic();
1810
- }, ie = (n, t) => {
1824
+ }, ee = (n, t) => {
1811
1825
  if (n.inCreateMask)
1812
1826
  return;
1813
- const { vertices: e, uv: r } = Zt(t);
1814
- wt(n, {
1827
+ const { vertices: e, uv: r } = qt(t);
1828
+ Mt(n, {
1815
1829
  ...t,
1816
1830
  points: e,
1817
1831
  uv: r,
1818
1832
  drawMode: n.gl.TRIANGLES
1819
1833
  });
1820
- }, se = (n, t) => {
1834
+ }, re = (n, t) => {
1821
1835
  const e = Q(
1822
1836
  n,
1823
1837
  t,
@@ -1829,7 +1843,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1829
1843
  t.texture,
1830
1844
  e ?? t.customMatrix
1831
1845
  ), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
1832
- }, ne = (n, t) => {
1846
+ }, ie = (n, t) => {
1833
1847
  const e = Q(n, t, t.width, t.height);
1834
1848
  n.startGraphic(
1835
1849
  n.gl.TRIANGLE_FAN,
@@ -1837,7 +1851,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1837
1851
  t.shader,
1838
1852
  e ?? t.customMatrix
1839
1853
  ), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
1840
- }, ae = (n, t) => {
1854
+ }, se = (n, t) => {
1841
1855
  const e = t.segments ?? 32, r = Q(n, t, 0, 0);
1842
1856
  n.startGraphic(
1843
1857
  n.gl.TRIANGLE_FAN,
@@ -1891,21 +1905,16 @@ void main(void) {\r
1891
1905
  // CUSTOM_CODE_CALL\r
1892
1906
  }\r
1893
1907
  `;
1894
- class he extends lt {
1908
+ class ne extends lt {
1895
1909
  KEY = "AtlasSprite";
1896
1910
  constructor(t) {
1897
1911
  super(t);
1898
1912
  }
1899
- createCustomShader(t) {
1900
- const e = D(xt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = D(et, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1901
- return t.getGLShader(this, this.KEY, r, e);
1902
- }
1903
1913
  createDefaultShader() {
1904
- const t = this.rapid, e = D(xt, t.maxTextureUnits), r = D(et, t.maxTextureUnits);
1905
- return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1914
+ return this.vs = et, this.fs = xt, this.defaultShader = this.createShader(et, xt), this.defaultShader;
1906
1915
  }
1907
1916
  }
1908
- const gt = `#version 300 es\r
1917
+ const ae = `#version 300 es\r
1909
1918
  precision highp float;\r
1910
1919
  \r
1911
1920
  // per-vertex\r
@@ -1932,23 +1941,21 @@ void main(void) {\r
1932
1941
  vColor = aColor;\r
1933
1942
  \r
1934
1943
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
1935
- // CUSTOM_CODE_CALL\r
1936
1944
  \r
1937
1945
  vec2 scaled = (aVertex - aOrigin) * aScale;\r
1938
1946
  float c = cos(aRotation);\r
1939
1947
  float s = sin(aRotation);\r
1940
1948
  \r
1941
- vec2 position = vec2(\r
1942
- scaled.x * c - scaled.y * s,\r
1943
- scaled.x * s + scaled.y * c\r
1944
- ) + aPosition;\r
1949
+ vec4 position = vec4(mat2(c, s, -s, c) * scaled + aPosition, 0.0, 1.0);\r
1950
+ // CUSTOM_CODE_CALL\r
1945
1951
  \r
1946
- gl_Position = u_projection * vec4(position, 0.0, 1.0);\r
1952
+ gl_Position = u_projection * position;\r
1947
1953
  }\r
1948
- `, pt = `#version 300 es\r
1954
+ `, he = `#version 300 es\r
1949
1955
  precision mediump float;\r
1950
1956
  \r
1951
1957
  uniform sampler2D uTexture;\r
1958
+ uniform sampler2D uTextures[%TEXTURE_NUM%];\r
1952
1959
  \r
1953
1960
  in vec2 vRegion;\r
1954
1961
  in vec4 vColor;\r
@@ -1961,20 +1968,18 @@ void main(void) {\r
1961
1968
  \r
1962
1969
  // CUSTOM_CODE_CALL\r
1963
1970
  }\r
1964
- `, G = 48, oe = G / 4;
1971
+ `, V = 48, oe = V / 4;
1965
1972
  class ce extends lt {
1966
1973
  KEY = "ParticleSprite";
1967
1974
  texture;
1968
1975
  customMatrix;
1969
1976
  particleLoopCache = /* @__PURE__ */ new Map();
1977
+ extraTextureUnit = 1;
1970
1978
  constructor(t) {
1971
1979
  super(t);
1972
1980
  }
1973
- createCustomShader(t) {
1974
- return t.getGLShader(this, this.KEY, gt, pt);
1975
- }
1976
1981
  createDefaultShader() {
1977
- const t = pt, e = gt;
1982
+ const t = he, e = ae;
1978
1983
  return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
1979
1984
  }
1980
1985
  enter(t) {
@@ -1983,41 +1988,41 @@ class ce extends lt {
1983
1988
  createShader(t, e) {
1984
1989
  const r = super.createShader(t, e);
1985
1990
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1986
- { name: "aPosition", size: 2, stride: G, offset: 0, divisor: 1 },
1987
- { name: "aScale", size: 2, stride: G, offset: 8, divisor: 1 },
1988
- { name: "aRotation", size: 1, stride: G, offset: 16, divisor: 1 },
1989
- { name: "aUVRect", size: 4, stride: G, offset: 20, divisor: 1 },
1990
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: G, offset: 36, divisor: 1 },
1991
- { name: "aOrigin", size: 2, stride: G, 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 }
1992
1997
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1993
1998
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1994
1999
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1995
2000
  }
1996
- 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, _) {
1997
2002
  if (!t.glTexture || a <= 0) return;
1998
2003
  this.texture && t !== this.texture && this.flush();
1999
- 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", B = t.uvW - t.uvX, k = t.uvH - t.uvY, H = B === 0 ? 0 : 1 / B, I = k === 0 ? 0 : 1 / k;
2000
- let F = t.rawWidth * (d ? -1 : 1);
2001
- L && (F *= h);
2002
- let X = t.rawHeight * (x ? -1 : 1);
2003
- W && (X *= o), M && (F *= (l - c) * H, X *= (f - u) * I);
2004
- let z = p ? Math.PI / 2 : 0;
2005
- O && (z += i);
2006
- const R = s ?? 4294967295, U = this.getParticleLoop(
2007
- L,
2008
- W,
2009
- O,
2010
- M,
2011
- 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,
2012
2016
  C,
2013
2017
  w,
2018
+ S,
2014
2019
  E
2015
2020
  );
2016
2021
  this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2017
2022
  const it = a, Y = this.instanceBuffer;
2018
2023
  let st = Y.usedElemNum;
2019
2024
  Y.resize(it * oe);
2020
- const bt = Y.float32, Ut = Y.uint32;
2025
+ const At = Y.float32, St = Y.uint32;
2021
2026
  st = U(
2022
2027
  e,
2023
2028
  r,
@@ -2029,16 +2034,16 @@ class ce extends lt {
2029
2034
  l,
2030
2035
  f,
2031
2036
  s,
2032
- bt,
2033
- Ut,
2037
+ At,
2038
+ St,
2039
+ O,
2034
2040
  F,
2035
- X,
2041
+ G,
2042
+ L,
2036
2043
  H,
2037
- I,
2038
- z,
2039
- R,
2040
- v,
2044
+ M,
2041
2045
  y,
2046
+ v,
2042
2047
  a,
2043
2048
  it,
2044
2049
  st
@@ -2098,11 +2103,11 @@ return idx;
2098
2103
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2099
2104
  const e = this.currentShader;
2100
2105
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2101
- const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = jt(this.rapid.projection, s);
2102
- this.currentShader.setUniform("u_projection", a), Et(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2106
+ const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = zt(this.rapid.projection, s);
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;
2103
2108
  }
2104
2109
  }
2105
- var St = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(St || {}), 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 || {});
2106
2111
  class pe {
2107
2112
  gl;
2108
2113
  canvas;
@@ -2116,7 +2121,7 @@ class pe {
2116
2121
  physicsHeight = 0;
2117
2122
  currentRegion = null;
2118
2123
  maxTextureUnits = 0;
2119
- matrixStack = new Gt(this);
2124
+ matrixStack = new kt(this);
2120
2125
  matrix;
2121
2126
  spriteRegion;
2122
2127
  graphicRegion;
@@ -2131,7 +2136,7 @@ class pe {
2131
2136
  textureFilter;
2132
2137
  scaleMode;
2133
2138
  _filterRT = [null, null];
2134
- _filterInput = new N();
2139
+ _filterInput = new D();
2135
2140
  get height() {
2136
2141
  return this.logicHeight;
2137
2142
  }
@@ -2140,37 +2145,37 @@ class pe {
2140
2145
  }
2141
2146
  constructor(t) {
2142
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;
2143
- const e = Nt(this.canvas, this.antialias, this.premultipliedAlpha);
2144
- 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 $t(this), this.atlasSpriteRegion = new he(this), this.particleRegion = new ce(this);
2148
+ const e = Lt(this.canvas, this.antialias, this.premultipliedAlpha);
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);
2145
2150
  const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
2146
- 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 Ct(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);
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);
2147
2152
  }
2148
2153
  setTextureFilter(t) {
2149
2154
  this.textureFilter = t;
2150
2155
  }
2151
2156
  getColorUint32(t) {
2152
- return Jt(this.premultipliedAlpha, t);
2157
+ return Qt(this.premultipliedAlpha, t);
2153
2158
  }
2154
2159
  enterRegion(t, e) {
2155
2160
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2156
2161
  }
2157
2162
  drawParticles(t) {
2158
- re(this, t);
2163
+ te(this, t);
2159
2164
  }
2160
2165
  drawSprite(t) {
2161
- ee(this, t);
2166
+ Jt(this, t);
2162
2167
  }
2163
2168
  drawLine(t) {
2164
- ie(this, t);
2169
+ ee(this, t);
2165
2170
  }
2166
2171
  drawGraphic(t) {
2167
- wt(this, t);
2172
+ Mt(this, t);
2168
2173
  }
2169
2174
  drawRect(t) {
2170
- ne(this, t);
2175
+ ie(this, t);
2171
2176
  }
2172
2177
  drawCircle(t) {
2173
- ae(this, t);
2178
+ se(this, t);
2174
2179
  }
2175
2180
  startGraphic(t = this.gl.TRIANGLES, e, r, i) {
2176
2181
  this.enterRegion(this.graphicRegion, r), this.graphicRegion.startGraphic(i ?? this.matrixStack.curWorldM, t, e);
@@ -2179,7 +2184,7 @@ class pe {
2179
2184
  this.startGraphic(t, e, this.graphicRegion.maskShader, r);
2180
2185
  }
2181
2186
  drawMaskImage(t) {
2182
- se(this, t);
2187
+ re(this, t);
2183
2188
  }
2184
2189
  addRectVertex(t, e, r) {
2185
2190
  const i = this.getColorUint32(r);
@@ -2396,7 +2401,7 @@ class pe {
2396
2401
  function de(n) {
2397
2402
  return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof g || n instanceof m);
2398
2403
  }
2399
- class P {
2404
+ class N {
2400
2405
  static float(t, e) {
2401
2406
  return Math.random() * (e - t) + t;
2402
2407
  }
@@ -2407,18 +2412,18 @@ class P {
2407
2412
  return Math.random() * Math.PI * 2;
2408
2413
  }
2409
2414
  static vector(t, e, r, i) {
2410
- return new g(P.float(t, e), P.float(r, i));
2415
+ return new g(N.float(t, e), N.float(r, i));
2411
2416
  }
2412
2417
  static randomColor(t, e) {
2413
2418
  return new m(
2414
- P.float(t.r, e.r),
2415
- P.float(t.g, e.g),
2416
- P.float(t.b, e.b),
2417
- 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)
2418
2423
  );
2419
2424
  }
2420
2425
  static pick(t) {
2421
- return t[P.int(0, t.length - 1)];
2426
+ return t[N.int(0, t.length - 1)];
2422
2427
  }
2423
2428
  static pickWeight(t) {
2424
2429
  if (!t || t.length === 0) return null;
@@ -2434,27 +2439,27 @@ class P {
2434
2439
  if (Array.isArray(t)) {
2435
2440
  const [r, i] = t;
2436
2441
  if (typeof r == "number")
2437
- return P.float(r, i);
2442
+ return N.float(r, i);
2438
2443
  if (r instanceof g)
2439
- return P.vector(r.x, i.x, r.y, i.y);
2444
+ return N.vector(r.x, i.x, r.y, i.y);
2440
2445
  if (r instanceof m)
2441
- return P.randomColor(r, i);
2446
+ return N.randomColor(r, i);
2442
2447
  }
2443
2448
  return typeof t == "number" ? t : t.clone();
2444
2449
  }
2445
2450
  }
2446
2451
  const Z = (n, t) => (Array.isArray(n) ? n : [n]).slice(0, t);
2447
2452
  var fe = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(fe || {});
2448
- const vt = 10, yt = 0, Tt = !0;
2449
- class K {
2453
+ const gt = 10, pt = 0, vt = !0;
2454
+ class j {
2450
2455
  components;
2451
2456
  constructor(t = 1) {
2452
2457
  if (!Number.isInteger(t) || t <= 0)
2453
2458
  throw new RangeError("ParticleAttributeStore size must be a positive integer");
2454
2459
  this.components = Array.from({ length: t }, () => ({
2455
- value: new A(S.Float32),
2456
- delta: new A(S.Float32),
2457
- damping: new A(S.Float32)
2460
+ value: new b(A.Float32),
2461
+ delta: new b(A.Float32),
2462
+ damping: new b(A.Float32)
2458
2463
  }));
2459
2464
  }
2460
2465
  getArrayBuffer() {
@@ -2487,7 +2492,7 @@ class K {
2487
2492
  }
2488
2493
  }
2489
2494
  resolveComponent(t, e, r) {
2490
- return t === void 0 ? r : Array.isArray(t) ? P.float(
2495
+ return t === void 0 ? r : Array.isArray(t) ? N.float(
2491
2496
  this.getComponent(t[0], e),
2492
2497
  this.getComponent(t[1], e)
2493
2498
  ) : this.getComponent(t, e);
@@ -2502,32 +2507,32 @@ class K {
2502
2507
  return h;
2503
2508
  }
2504
2509
  }
2505
- class At {
2510
+ class wt {
2506
2511
  options;
2507
2512
  emitting = !1;
2508
2513
  emitTimer = 0;
2509
- emitRate = vt;
2510
- emitTime = yt;
2514
+ emitRate = gt;
2515
+ emitTime = pt;
2511
2516
  emitTimeCounter = 0;
2512
- localSpace = Tt;
2517
+ localSpace = vt;
2513
2518
  rapid;
2514
- x = new A(S.Float32);
2515
- y = new A(S.Float32);
2516
- scaleX = new A(S.Float32);
2517
- scaleY = new A(S.Float32);
2518
- rotation = new A(S.Float32);
2519
- color = new A(S.Uint32);
2520
- remainingLife = new A(S.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);
2521
2526
  animations = {
2522
- speed: new K(),
2523
- rotation: new K(),
2524
- scale: new K(),
2525
- color: new K(4),
2526
- velocity: new K(2)
2527
+ speed: new j(),
2528
+ rotation: new j(),
2529
+ scale: new j(),
2530
+ color: new j(4),
2531
+ velocity: new j(2)
2527
2532
  };
2528
2533
  count = 0;
2529
2534
  constructor(t, e) {
2530
- this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? vt, this.emitTime = e.emitTime ?? yt, this.localSpace = e.localSpace ?? Tt;
2535
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? gt, this.emitTime = e.emitTime ?? pt, this.localSpace = e.localSpace ?? vt;
2531
2536
  }
2532
2537
  getAllArrayBuffer() {
2533
2538
  return [
@@ -2545,7 +2550,7 @@ class At {
2545
2550
  this.options.texture = t;
2546
2551
  }
2547
2552
  clone() {
2548
- return new At(this.rapid, { ...this.options });
2553
+ return new wt(this.rapid, { ...this.options });
2549
2554
  }
2550
2555
  setEmitRate(t) {
2551
2556
  this.emitRate = t;
@@ -2570,7 +2575,7 @@ class At {
2570
2575
  this.createParticle();
2571
2576
  }
2572
2577
  createParticle() {
2573
- const t = P.scalarOrRange(this.options.life, 1);
2578
+ const t = N.scalarOrRange(this.options.life, 1);
2574
2579
  this.remainingLife.push(t);
2575
2580
  let e = 0, r = 0;
2576
2581
  switch (this.options.emitShape) {
@@ -2613,7 +2618,7 @@ class At {
2613
2618
  r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
2614
2619
  }
2615
2620
  const e = this.updateParticle(t);
2616
- this.count -= e.length, A.removeAtIndices(e, this.getAllArrayBuffer());
2621
+ this.count -= e.length, b.removeAtIndices(e, this.getAllArrayBuffer());
2617
2622
  }
2618
2623
  updateParticle(t) {
2619
2624
  const e = [], r = this.animations;
@@ -2671,13 +2676,15 @@ uniform mat3x2 uLightMatrix[%TEXTURE_NUM%];
2671
2676
  uniform float uLightHeight[%TEXTURE_NUM%];
2672
2677
  uniform float uMetallic;
2673
2678
  uniform float uRoughness;
2679
+ uniform vec3 uAmbientColor;
2680
+ uniform vec2 uNormalScale;
2674
2681
 
2675
2682
  void light_fragment(inout vec4 color, in vec2 vRegion) {
2676
2683
  if (color.a < 0.005) return;
2677
2684
 
2678
- // 屏幕坐标映射到世界坐标
2679
2685
  vec2 worldPos = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) * (uLogicalResolution / uResolution);
2680
- vec3 normal = normalize(texture(uNormalMap, vRegion).rgb * 2.0 - 1.0) * vec3(1.0, -1.0, 1.0);
2686
+ vec3 normal = normalize(texture(uNormalMap, vRegion).rgb * 2.0 - 1.0);
2687
+ normal = normalize(normal * vec3(uNormalScale, 1.0));
2681
2688
 
2682
2689
  vec3 totalDiffuse = vec3(0.0);
2683
2690
  vec3 totalSpecular = vec3(0.0);
@@ -2692,11 +2699,8 @@ void light_fragment(inout vec4 color, in vec2 vRegion) {
2692
2699
  mat2 lightBasis = mat2(uLightMatrix[i][0], uLightMatrix[i][1]);
2693
2700
  vec2 lightUV = inverse(lightBasis) * (worldPos - lightPos) + 0.5;
2694
2701
 
2695
- // 判断当前像素是否在该光源范围内
2696
2702
  if (lightUV.x >= 0.0 && lightUV.x <= 1.0 && lightUV.y >= 0.0 && lightUV.y <= 1.0) {
2697
2703
 
2698
- // ⭐️ 核心修复:sampler2DArray 采样必须传 vec3
2699
- // 第三个分量是该光源对应的图层 ID (转为 float)
2700
2704
  int layer = uLightTextureId[i];
2701
2705
  vec4 lightTex;
2702
2706
  %GET_COLOR%
@@ -2711,20 +2715,23 @@ void light_fragment(inout vec4 color, in vec2 vRegion) {
2711
2715
  }
2712
2716
  }
2713
2717
 
2714
- // 环境光 + 漫反射 + 高光
2715
- color.rgb = color.rgb * (vec3(0.1, 0.1, 0.15) + totalDiffuse) + totalSpecular;
2718
+ color.rgb = color.rgb * (uAmbientColor + totalDiffuse) + totalSpecular;
2716
2719
  }
2717
2720
  `, xe = "void light_vertex(inout vec4 p, vec2 u) {}", J = 8;
2718
2721
  class ge extends ct {
2719
2722
  constructor(t, e = "", r = "", i = 0, s) {
2720
2723
  super(
2721
2724
  t,
2722
- e + xe,
2723
- D(r + me, t.maxTextureUnits - 1, "layer", "lightUV", "lightTex = "),
2724
- i + 1,
2725
+ e,
2726
+ r,
2727
+ i + 2,
2725
2728
  s
2726
2729
  ), this.prefix.push("light_");
2727
2730
  }
2731
+ getGLShader(t, e, r, i) {
2732
+ const s = K(me, t.getMaxTexutreUnit(this), "layer", "lightUV", "lightTex = ");
2733
+ return i = this.replaceCustomCode(i, s), r = this.replaceCustomCode(r, xe), super.getGLShader(t, e, r, i);
2734
+ }
2728
2735
  }
2729
2736
  class ve {
2730
2737
  shader;
@@ -2750,13 +2757,13 @@ class ve {
2750
2757
  i.withMask(() => {
2751
2758
  i.startMaskGraphic(i.gl.TRIANGLES);
2752
2759
  for (let c = 0; c < h.length; c++) {
2753
- 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));
2754
- 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);
2755
2762
  }
2756
2763
  i.endGraphic();
2757
2764
  }, () => {
2758
2765
  i.drawSprite({ texture: t });
2759
- }, St.NOT_EQUAL);
2766
+ }, Rt.NOT_EQUAL);
2760
2767
  }), this.rt;
2761
2768
  }
2762
2769
  setupLight(t) {
@@ -2776,34 +2783,44 @@ class ve {
2776
2783
  })),
2777
2784
  uLightHeight: Float32Array.from(r.map((h, o) => s[o] ?? s[0] ?? 80)),
2778
2785
  uMetallic: t.metallic ?? 0.8,
2779
- uRoughness: t.roughness ?? 0.15
2786
+ uRoughness: t.roughness ?? 0.15,
2787
+ uAmbientColor: t.ambientColor ? [t.ambientColor.r / 255, t.ambientColor.g / 255, t.ambientColor.b / 255] : [0.1, 0.1, 0.15],
2788
+ uNormalScale: [t.normalScaleX ?? 1, t.normalScaleY ?? 1]
2780
2789
  }), e;
2781
2790
  }
2782
2791
  }
2783
2792
  export {
2784
- V as BaseTexture,
2793
+ X as BaseTexture,
2785
2794
  ue as BlendMode,
2786
2795
  le as CanvasScaleMode,
2787
2796
  m as Color,
2788
2797
  ct as CustomGlShader,
2789
- Rt as GLShader,
2798
+ Tt as GLShader,
2790
2799
  ve as Light,
2791
2800
  ge as LightShader,
2792
- qt as LineTextureMode,
2801
+ jt as LineTextureMode,
2793
2802
  J as MAX_LIGHTS,
2794
- St as MaskType,
2795
- At as ParticleEmitter,
2803
+ Rt as MaskType,
2804
+ wt as ParticleEmitter,
2796
2805
  fe as ParticleShape,
2797
2806
  pe as Rapid,
2798
- _t as RenderTexture,
2799
- Pt as TextTexture,
2800
- N as Texture,
2807
+ Ut as RenderTexture,
2808
+ _t as TextTexture,
2809
+ D as Texture,
2801
2810
  tt as TextureFilterMode,
2802
- Ct as TextureManager,
2811
+ bt as TextureManager,
2803
2812
  q as TextureWrapMode,
2804
2813
  g as Vec2,
2805
- jt as composeProjectionWithAffine,
2806
- Zt as getLineGeometry,
2807
- Qt as getLineNormal,
2808
- Kt as multiplyMat4
2814
+ zt as composeProjectionWithAffine,
2815
+ se as drawCircle,
2816
+ Mt as drawGraphic,
2817
+ ee as drawLine,
2818
+ re as drawMaskImage,
2819
+ te as drawParticles,
2820
+ ie as drawRect,
2821
+ Jt as drawSprite,
2822
+ Qt as getColorUint32,
2823
+ qt as getLineGeometry,
2824
+ Kt as getLineNormal,
2825
+ $t as multiplyMat4
2809
2826
  };