rapid-render 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- class m {
1
+ class g {
2
2
  _r;
3
3
  _g;
4
4
  _b;
@@ -11,8 +11,14 @@ class m {
11
11
  constructor(t, e, r, i = 255) {
12
12
  this._r = t, this._g = e, this._b = r, this._a = i, this.updateUint();
13
13
  }
14
- setClearColor(t) {
15
- t.clearColor(this.r / 255, this.g / 255, this.b / 255, this.a / 255);
14
+ setClearColor(t, e = !0) {
15
+ const r = e ? this.premultipliedUint32 : this.uint32;
16
+ t.clearColor(
17
+ (r & 255) / 255,
18
+ (r >>> 8 & 255) / 255,
19
+ (r >>> 16 & 255) / 255,
20
+ (r >>> 24) / 255
21
+ );
16
22
  }
17
23
  get r() {
18
24
  return this._r;
@@ -40,7 +46,7 @@ class m {
40
46
  }
41
47
  updateUint() {
42
48
  this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
43
- const t = m.clampByte(this._a), e = m.clampByte(this._r * t / 255), r = m.clampByte(this._g * t / 255), i = m.clampByte(this._b * t / 255);
49
+ const t = g.clampByte(this._a), e = g.clampByte(this._r * t / 255), r = g.clampByte(this._g * t / 255), i = g.clampByte(this._b * t / 255);
44
50
  this.premultipliedUint32 = (t << 24 | i << 16 | r << 8 | e) >>> 0;
45
51
  }
46
52
  reset() {
@@ -52,14 +58,14 @@ class m {
52
58
  setHSL(t, e, r) {
53
59
  t = (t % 360 + 360) % 360, e = Math.max(0, Math.min(100, e)) / 100, r = Math.max(0, Math.min(100, r)) / 100;
54
60
  const i = (1 - Math.abs(2 * r - 1)) * e, s = i * (1 - Math.abs(t / 60 % 2 - 1)), a = r - i / 2;
55
- let h = 0, o = 0, c = 0;
56
- 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;
61
+ let o = 0, h = 0, c = 0;
62
+ return t < 60 ? [o, h, c] = [i, s, 0] : t < 120 ? [o, h, c] = [s, i, 0] : t < 180 ? [o, h, c] = [0, i, s] : t < 240 ? [o, h, c] = [0, s, i] : t < 300 ? [o, h, c] = [s, 0, i] : [o, h, c] = [i, 0, s], this.setRGBA((o + a) * 255, (h + a) * 255, (c + a) * 255, 255), this;
57
63
  }
58
64
  copy(t) {
59
65
  this.setRGBA(t.r, t.g, t.b, t.a);
60
66
  }
61
67
  clone() {
62
- return new m(this._r, this._g, this._b, this._a);
68
+ return new g(this._r, this._g, this._b, this._a);
63
69
  }
64
70
  toHexString(t = !0) {
65
71
  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");
@@ -69,13 +75,13 @@ class m {
69
75
  return t.r === this.r && t.g === this.g && t.b === this.b && t.a === this.a;
70
76
  }
71
77
  static FromHSL(t, e, r) {
72
- return new m(0, 0, 0).setHSL(t, e, r);
78
+ return new g(0, 0, 0).setHSL(t, e, r);
73
79
  }
74
80
  static FromRGB(t, e, r) {
75
- return new m(t, e, r);
81
+ return new g(t, e, r);
76
82
  }
77
83
  static fromNorm(t, e, r, i = 1) {
78
- return new m(
84
+ return new g(
79
85
  Math.round(t * 255),
80
86
  Math.round(e * 255),
81
87
  Math.round(r * 255),
@@ -83,17 +89,17 @@ class m {
83
89
  );
84
90
  }
85
91
  static packColor(t, e, r, i, s) {
86
- const a = m.clampByte(i), h = s ? a / 255 : 1, o = m.clampByte(t * h), c = m.clampByte(e * h), u = m.clampByte(r * h);
87
- return (a << 24 | u << 16 | c << 8 | o) >>> 0;
92
+ const a = g.clampByte(i), o = s ? a / 255 : 1, h = g.clampByte(t * o), c = g.clampByte(e * o), u = g.clampByte(r * o);
93
+ return (a << 24 | u << 16 | c << 8 | h) >>> 0;
88
94
  }
89
95
  static fromHex(t) {
90
96
  t.startsWith("#") && (t = t.slice(1));
91
97
  const e = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16);
92
98
  let s = 255;
93
- return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new m(e, r, i, s);
99
+ return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new g(e, r, i, s);
94
100
  }
95
101
  add(t) {
96
- return new m(
102
+ return new g(
97
103
  Math.min(this.r + t.r, 255),
98
104
  Math.min(this.g + t.g, 255),
99
105
  Math.min(this.b + t.b, 255),
@@ -101,7 +107,7 @@ class m {
101
107
  );
102
108
  }
103
109
  subtract(t) {
104
- return new m(
110
+ return new g(
105
111
  this.r - t.r,
106
112
  this.g - t.g,
107
113
  this.b - t.b,
@@ -109,12 +115,12 @@ class m {
109
115
  );
110
116
  }
111
117
  divide(t) {
112
- return t instanceof m ? new m(
118
+ return t instanceof g ? new g(
113
119
  this.r / t.r,
114
120
  this.g / t.g,
115
121
  this.b / t.b,
116
122
  this.a / t.a
117
- ) : new m(
123
+ ) : new g(
118
124
  this.r / t,
119
125
  this.g / t,
120
126
  this.b / t,
@@ -122,12 +128,12 @@ class m {
122
128
  );
123
129
  }
124
130
  multiply(t) {
125
- return t instanceof m ? new m(
131
+ return t instanceof g ? new g(
126
132
  this.r * t.r,
127
133
  this.g * t.g,
128
134
  this.b * t.b,
129
135
  this.a * t.a
130
- ) : new m(
136
+ ) : new g(
131
137
  this.r * t,
132
138
  this.g * t,
133
139
  this.b * t,
@@ -137,55 +143,62 @@ class m {
137
143
  clamp() {
138
144
  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();
139
145
  }
140
- static Red = new m(255, 0, 0, 255);
141
- static Green = new m(0, 255, 0, 255);
142
- static Blue = new m(0, 0, 255, 255);
143
- static Yellow = new m(255, 255, 0, 255);
144
- static Purple = new m(128, 0, 128, 255);
145
- static Orange = new m(255, 165, 0, 255);
146
- static Pink = new m(255, 192, 203, 255);
147
- static Gray = new m(128, 128, 128, 255);
148
- static Brown = new m(139, 69, 19, 255);
149
- static Cyan = new m(0, 255, 255, 255);
150
- static Magenta = new m(255, 0, 255, 255);
151
- static Lime = new m(192, 255, 0, 255);
152
- static White = new m(255, 255, 255, 255);
153
- static Black = new m(0, 0, 0, 255);
154
- static Transparent = new m(0, 0, 0, 0);
146
+ static Red = new g(255, 0, 0, 255);
147
+ static Green = new g(0, 255, 0, 255);
148
+ static Blue = new g(0, 0, 255, 255);
149
+ static Yellow = new g(255, 255, 0, 255);
150
+ static Purple = new g(128, 0, 128, 255);
151
+ static Orange = new g(255, 165, 0, 255);
152
+ static Pink = new g(255, 192, 203, 255);
153
+ static Gray = new g(128, 128, 128, 255);
154
+ static Brown = new g(139, 69, 19, 255);
155
+ static Cyan = new g(0, 255, 255, 255);
156
+ static Magenta = new g(255, 0, 255, 255);
157
+ static Lime = new g(192, 255, 0, 255);
158
+ static White = new g(255, 255, 255, 255);
159
+ static Black = new g(0, 0, 0, 255);
160
+ static Transparent = new g(0, 0, 0, 0);
155
161
  }
156
- var Q = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(Q || {}), q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(q || {});
157
- class bt {
162
+ var it = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(it || {}), J = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(J || {});
163
+ class Ct {
158
164
  render;
159
165
  cache = /* @__PURE__ */ new Map();
166
+ texture = /* @__PURE__ */ new Set();
160
167
  constructor(t) {
161
168
  this.render = t;
162
169
  }
170
+ addTexture(t) {
171
+ return this.texture.add(t), t;
172
+ }
173
+ removeTexture(t) {
174
+ return this.texture.delete(t), t;
175
+ }
163
176
  async load(t, e) {
164
177
  let r = this.cache.get(t);
165
178
  if (r)
166
- return new F(r);
179
+ return this.addTexture(new W(r));
167
180
  try {
168
181
  const i = await this._fetchImage(t);
169
- return r = X.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new F(r);
182
+ return r = z.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), this.addTexture(new W(r));
170
183
  } catch (i) {
171
184
  throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
172
185
  }
173
186
  }
174
187
  create(t, e) {
175
188
  if (e?.key && this.cache.has(e.key))
176
- return new F(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 F(r);
189
+ return this.addTexture(new W(this.cache.get(e.key)));
190
+ const r = z.fromSource(this.render, t, e);
191
+ return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), this.addTexture(new W(r));
179
192
  }
180
193
  createRenderTexture(t) {
181
- return new Ut(this.render, t);
194
+ return this.addTexture(new _t(this.render, t));
182
195
  }
183
196
  createTextTexture(t) {
184
- return new _t(this.render, t);
197
+ return this.addTexture(new Lt(this.render, t));
185
198
  }
186
199
  destroy(t, e = !1) {
187
200
  let r, i;
188
- typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof F ? (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));
201
+ typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof W ? (r = t.base, i = r?.uid, this.removeTexture(t), t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
189
202
  }
190
203
  destroyAll() {
191
204
  for (const t of this.cache.values())
@@ -199,7 +212,7 @@ class bt {
199
212
  });
200
213
  }
201
214
  }
202
- class X {
215
+ class z {
203
216
  glTexture = null;
204
217
  width;
205
218
  height;
@@ -209,23 +222,23 @@ class X {
209
222
  this.glTexture = t, this.width = e, this.height = r;
210
223
  }
211
224
  static fromSource(t, e, r = {}) {
212
- const i = rt(t, e, r);
213
- return new X(i, e.width, e.height);
225
+ const i = nt(t, e, r);
226
+ return new z(i, e.width, e.height);
214
227
  }
215
228
  updateSource(t, e, r = {}) {
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));
229
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && ht(t, r.textureFilter), r.wrap !== void 0 && ot(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));
217
230
  }
218
231
  setFilterMode(t, e) {
219
232
  this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), ht(t, e), t.bindTexture(t.TEXTURE_2D, null));
220
233
  }
221
234
  setWrapMode(t, e) {
222
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), at(t, e), t.bindTexture(t.TEXTURE_2D, null));
235
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), ot(t, e), t.bindTexture(t.TEXTURE_2D, null));
223
236
  }
224
237
  destroy(t) {
225
238
  this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
226
239
  }
227
240
  }
228
- class F {
241
+ class W {
229
242
  base;
230
243
  uvX = 0;
231
244
  uvY = 0;
@@ -252,6 +265,8 @@ class F {
252
265
  constructor(t) {
253
266
  t && this.setBase(t);
254
267
  }
268
+ updateResolution() {
269
+ }
255
270
  setBase(t) {
256
271
  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);
257
272
  }
@@ -259,41 +274,42 @@ class F {
259
274
  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
275
  }
261
276
  getSubTexture(t, e, r, i) {
262
- if (!this.base) return new F();
263
- const s = this.clone(), a = this._px, h = this._py;
264
- return s.setRegion(a + t, h + e, r, i), s;
277
+ if (!this.base) return new W();
278
+ const s = this.clone(), a = this._px, o = this._py;
279
+ return s.setRegion(a + t, o + e, r, i), s;
265
280
  }
266
281
  clone(t) {
267
- const e = t ?? new F(this.base);
282
+ const e = t ?? new W(this.base);
268
283
  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
284
  }
270
285
  splitGrid(t, e, r, i, s = 0) {
271
286
  if (!this.base) return [];
272
- const a = [], h = this.rawWidth, o = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, f = r ?? Math.floor((h + c) / u), d = i ?? Math.floor((o + c) / l);
273
- for (let x = 0; x < d; x++)
274
- for (let p = 0; p < f; p++)
275
- a.push(this.getSubTexture(p * u, x * l, t, e));
287
+ const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, d = r ?? Math.floor((o + c) / u), f = i ?? Math.floor((h + c) / l);
288
+ for (let m = 0; m < f; m++)
289
+ for (let x = 0; x < d; x++)
290
+ a.push(this.getSubTexture(x * u, m * l, t, e));
276
291
  return a;
277
292
  }
278
293
  static fromImageSource(t, e, r = {}) {
279
- const i = rt(t, e, r);
280
- return new F(new X(i, e.width, e.height));
294
+ const i = nt(t, e, r);
295
+ return new W(new z(i, e.width, e.height));
281
296
  }
282
297
  destroy() {
283
298
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
284
299
  }
285
300
  }
286
- class Ut extends F {
301
+ class _t extends W {
287
302
  framebuffer;
288
303
  renderbuffer;
289
304
  gl;
305
+ premultipliedAlpha;
290
306
  clearColor;
291
307
  _allocW = 0;
292
308
  _allocH = 0;
293
309
  constructor(t, e) {
294
- super(), this.gl = t.gl, this.clearColor = e.clearColor ?? m.Black;
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 X(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
310
+ super(), this.gl = t.gl, this.premultipliedAlpha = t.premultipliedAlpha, this.clearColor = e.clearColor ?? g.Black;
311
+ const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = nt(t, { width: r, height: i }, { ...e, onlySize: !0 });
312
+ if (this.setBase(new z(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
297
313
  throw new Error("Failed to create Framebuffer or Renderbuffer");
298
314
  this.resize(r, i, !0);
299
315
  }
@@ -312,7 +328,7 @@ class Ut extends F {
312
328
  clear(t) {
313
329
  if (!this.framebuffer) return;
314
330
  const e = this.gl, r = t ?? this.clearColor;
315
- r && (r.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT | e.STENCIL_BUFFER_BIT));
331
+ r && (r.setClearColor(e, this.premultipliedAlpha), e.clear(e.COLOR_BUFFER_BIT | e.STENCIL_BUFFER_BIT));
316
332
  }
317
333
  deactivate() {
318
334
  const t = this.gl;
@@ -320,24 +336,24 @@ class Ut extends F {
320
336
  }
321
337
  GetPixels(t = 0, e = 0, r = this.rawWidth, i = this.rawHeight) {
322
338
  if (!this.framebuffer) return new Uint8Array(0);
323
- const s = Math.floor(t), a = Math.floor(e), h = Math.floor(r), o = Math.floor(i);
324
- if (h <= 0 || o <= 0) return new Uint8Array(0);
339
+ const s = Math.floor(t), a = Math.floor(e), o = Math.floor(r), h = Math.floor(i);
340
+ if (o <= 0 || h <= 0) return new Uint8Array(0);
325
341
  if (s < 0 || a < 0 || s >= this.rawWidth || a >= this.rawHeight)
326
342
  return new Uint8Array(0);
327
- const c = Math.min(h, this.rawWidth - s), u = Math.min(o, this.rawHeight - a), l = this.gl, f = l.getParameter(l.FRAMEBUFFER_BINDING);
343
+ const c = Math.min(o, this.rawWidth - s), u = Math.min(h, this.rawHeight - a), l = this.gl, d = l.getParameter(l.FRAMEBUFFER_BINDING);
328
344
  l.bindFramebuffer(l.FRAMEBUFFER, this.framebuffer);
329
- const d = new Uint8Array(c * u * 4);
330
- return l.readPixels(s, a, c, u, l.RGBA, l.UNSIGNED_BYTE, d), l.bindFramebuffer(l.FRAMEBUFFER, f), d;
345
+ const f = new Uint8Array(c * u * 4);
346
+ return l.readPixels(s, a, c, u, l.RGBA, l.UNSIGNED_BYTE, f), l.bindFramebuffer(l.FRAMEBUFFER, d), f;
331
347
  }
332
348
  GetColorAt(t, e) {
333
349
  const r = this.GetPixels(t, e, 1, 1);
334
- return r.length < 4 ? new m(0, 0, 0, 0) : new m(r[0], r[1], r[2], r[3]);
350
+ return r.length < 4 ? new g(0, 0, 0, 0) : new g(r[0], r[1], r[2], r[3]);
335
351
  }
336
352
  destroy() {
337
353
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
338
354
  }
339
355
  }
340
- const Ct = {
356
+ const Pt = {
341
357
  fontFamily: "Arial",
342
358
  fontSize: 24,
343
359
  fontWeight: "normal",
@@ -346,25 +362,26 @@ const Ct = {
346
362
  align: "left",
347
363
  lineHeight: 1
348
364
  };
349
- class _t extends F {
365
+ class Lt extends W {
350
366
  canvas;
351
367
  ctx;
352
368
  render;
353
369
  _text;
354
370
  _style;
355
371
  options;
356
- flipY = !0;
372
+ resolution = 1;
357
373
  constructor(t, e) {
358
- super(), this.render = t, this._style = { ...Ct, ...e }, this._text = e?.text ?? "", this.options = {
374
+ super(), this.render = t, this._style = { ...Pt, ...e }, this._text = e?.text ?? "", this.options = {
359
375
  premultipliedAlpha: t.premultipliedAlpha,
360
- textureFilter: Q.LINEAR,
361
- ...e
376
+ ...e,
377
+ textureFilter: 1
378
+ /* NEAREST */
362
379
  }, this.canvas = document.createElement("canvas");
363
380
  const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
364
381
  if (!r) throw new Error("Failed to get 2d context for TextTexture");
365
382
  this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
366
- const i = rt(t, this.canvas, this.options);
367
- this.setBase(new X(i, 1, 1)), this.update();
383
+ const i = nt(t, this.canvas, this.options);
384
+ this.setBase(new z(i, 1, 1)), this.updateResolution(), this.update();
368
385
  }
369
386
  get text() {
370
387
  return this._text;
@@ -388,49 +405,44 @@ class _t extends F {
388
405
  return e;
389
406
  }
390
407
  }
408
+ updateResolution() {
409
+ let t = 1;
410
+ t *= this.render.viewport.resolution, t != this.resolution && (this.resolution = t, this.update());
411
+ }
391
412
  update() {
392
- const t = this.ctx, e = this.style, r = this.render.dpr;
393
- this.scale = 1 / r;
394
- const i = e.fontSize, s = e.fontWeight, a = e.fontFamily, h = e.lineHeight, o = `${s} ${i}px ${a}`, c = e.baseline ?? "top", u = e.align ?? "left", l = e.strokeThickness ?? 0, f = l > 0, d = this._text.split(`
395
- `), x = "国g", p = d[0] || x;
396
- t.font = o, t.textBaseline = "alphabetic", t.textAlign = "left";
397
- let y = 0, v = 0, E = 0;
398
- for (const D of d) {
399
- const H = t.measureText(D || x);
400
- y = Math.max(y, D ? H.width : 0), v = Math.max(v, H.actualBoundingBoxAscent), E = Math.max(E, H.actualBoundingBoxDescent);
413
+ const t = this.ctx, e = this.style, r = e.fontSize, i = e.fontWeight, s = e.fontFamily, a = e.lineHeight, h = Math.max(r, 32), c = r / h, u = `${i} ${r}px ${s}`, l = `${i} ${h}px ${s}`, d = this.resolution, f = e.baseline ?? "top", m = e.align ?? "left", x = e.strokeThickness ?? 0, y = x > 0, v = this._text.split(`
414
+ `), T = "国g", w = v[0] || T;
415
+ t.font = l, t.textBaseline = "alphabetic", t.textAlign = "left";
416
+ let U = 0, P = 0, O = 0;
417
+ for (const B of v) {
418
+ const X = t.measureText(B || T);
419
+ U = Math.max(U, B ? X.width * c : 0), B == v.at(0) && (P = X.actualBoundingBoxAscent * c), B == v.at(-1) && (O = X.actualBoundingBoxDescent * c);
401
420
  }
402
421
  t.textBaseline = "alphabetic";
403
- const S = t.measureText(p).fontBoundingBoxDescent;
404
- t.textBaseline = c;
405
- const _ = t.measureText(p).fontBoundingBoxDescent, P = i * h, k = v + E + (d.length - 1) * P, I = Math.ceil(l / 2) + 2, C = Math.max(
406
- 1,
407
- Math.ceil(y + I * 2)
408
- ), R = Math.max(
409
- 1,
410
- Math.ceil(k + I * 2)
411
- ), w = Math.ceil(C * r), O = Math.ceil(R * r);
412
- (this.canvas.width !== w || this.canvas.height !== O) && (this.canvas.width = w, this.canvas.height = O), t.setTransform(r, 0, 0, r, 0, 0), t.clearRect(
422
+ const L = t.measureText(w).fontBoundingBoxDescent * c;
423
+ t.textBaseline = f;
424
+ const S = t.measureText(w).fontBoundingBoxDescent * c, E = r * a, b = P + O + (v.length - 1) * E, I = x / 2 + 2 / d, k = U + I * 2, G = b + I * 2, N = Math.max(1, Math.ceil(k * d)), F = Math.max(1, Math.ceil(G * d)), V = N / d;
425
+ (this.canvas.width !== N || this.canvas.height !== F) && (this.canvas.width = N, this.canvas.height = F), t.setTransform(d, 0, 0, -d, 0, F), t.clearRect(
413
426
  0,
414
427
  0,
415
- w / r,
416
- O / r
417
- ), t.font = o, t.textBaseline = "alphabetic", t.textAlign = u;
418
- const B = this.updateOffset(C, I);
419
- f && (t.lineWidth = l, t.strokeStyle = e.stroke ?? "#000000", t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
420
- let L = I + v;
421
- for (const D of d)
422
- f && t.strokeText(D, B, L), e.fill && t.fillText(D, B, L), L += P;
423
- this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, w, O);
424
- const W = _ - S;
425
- this.offsetY = -I - v + W;
428
+ N / d,
429
+ F / d
430
+ ), t.font = u, t.textBaseline = "alphabetic", t.textAlign = m;
431
+ const H = this.updateOffset(V, I);
432
+ y && (t.lineWidth = x, t.strokeStyle = e.stroke ?? "#000000", t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
433
+ let A = I + P;
434
+ for (const B of v)
435
+ y && t.strokeText(B, H, A), e.fill && t.fillText(B, H, A), A += E;
436
+ const $ = S - L;
437
+ this.scale = 1 / this.resolution, this.offsetX = -H, this.offsetY = -I - P + $, this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, N, F);
426
438
  }
427
439
  }
428
- const Lt = (n, t = !1, e = !0) => {
440
+ const Nt = (n, t = !1, e = !0) => {
429
441
  const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
430
442
  if (!r)
431
443
  throw new Error("WebGL2 is not supported in this browser.");
432
444
  return r;
433
- }, dt = (n, t, e) => {
445
+ }, ft = (n, t, e) => {
434
446
  const r = n.createShader(e);
435
447
  if (!r)
436
448
  throw new Error("Unable to create webgl shader");
@@ -439,36 +451,36 @@ const Lt = (n, t = !1, e = !0) => {
439
451
  throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
440
452
  }
441
453
  return r;
442
- }, Pt = (n, t, e) => {
443
- var r = n.createProgram(), i = dt(n, t, 35633), s = dt(n, e, 35632);
454
+ }, It = (n, t, e) => {
455
+ var r = n.createProgram(), i = ft(n, t, 35633), s = ft(n, e, 35632);
444
456
  if (!r)
445
457
  throw new Error("Unable to create program shader");
446
458
  if (n.attachShader(r, i), n.attachShader(r, s), n.linkProgram(r), !n.getProgramParameter(r, n.LINK_STATUS)) {
447
- const h = n.getProgramInfoLog(r);
448
- throw new Error("Unable to link shader program: " + h);
459
+ const o = n.getProgramInfoLog(r);
460
+ throw new Error("Unable to link shader program: " + o);
449
461
  }
450
462
  return r;
451
463
  };
452
- function at(n, t) {
464
+ function ot(n, t) {
453
465
  const e = {
454
- [q.CLAMP]: n.CLAMP_TO_EDGE,
455
- [q.REPEAT]: n.REPEAT,
456
- [q.MIRRORED_REPEAT]: n.MIRRORED_REPEAT
466
+ [J.CLAMP]: n.CLAMP_TO_EDGE,
467
+ [J.REPEAT]: n.REPEAT,
468
+ [J.MIRRORED_REPEAT]: n.MIRRORED_REPEAT
457
469
  }[t] || n.CLAMP_TO_EDGE;
458
470
  n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, e);
459
471
  }
460
472
  function ht(n, t) {
461
473
  const e = {
462
- [Q.LINEAR]: n.LINEAR,
463
- [Q.NEAREST]: n.NEAREST
474
+ [it.LINEAR]: n.LINEAR,
475
+ [it.NEAREST]: n.NEAREST
464
476
  }[t] ?? n.NEAREST;
465
477
  n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, e);
466
478
  }
467
- function rt(n, t, e) {
479
+ function nt(n, t, e) {
468
480
  const r = n.gl, i = r.createTexture();
469
481
  if (!i)
470
482
  throw new Error("Unable to create WebGL texture");
471
- if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), at(r, e.wrap ?? q.CLAMP), ht(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
483
+ if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), ot(r, e.wrap ?? J.CLAMP), ht(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
472
484
  const s = t;
473
485
  r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, s.width, s.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
474
486
  } else {
@@ -477,7 +489,7 @@ function rt(n, t, e) {
477
489
  }
478
490
  return r.bindTexture(r.TEXTURE_2D, null), i;
479
491
  }
480
- function K(n, t, e = "vTextureId", r = "uv", i = "return") {
492
+ function Z(n, t, e = "vTextureId", r = "uv", i = "return") {
481
493
  if (n.includes("%TEXTURE_NUM%") && (n = n.replaceAll("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
482
494
  let s = "";
483
495
  for (let a = 0; a < t; a++)
@@ -486,15 +498,15 @@ function K(n, t, e = "vTextureId", r = "uv", i = "return") {
486
498
  }
487
499
  return n;
488
500
  }
489
- const Nt = 5126, ot = 5121;
490
- function It(n, t, e) {
501
+ const Ft = 5126, ct = 5121;
502
+ function Ot(n, t, e) {
491
503
  n.vertexAttribDivisor(t, e);
492
504
  }
493
- function yt(n, t, e, r, i) {
505
+ function wt(n, t, e, r, i) {
494
506
  n.drawArraysInstanced(t, e, r, i);
495
507
  }
496
- let Ot = 0;
497
- class Tt {
508
+ let Bt = 0;
509
+ class Et {
498
510
  program;
499
511
  attributeLoc = {};
500
512
  uniformLoc = {};
@@ -503,11 +515,11 @@ class Tt {
503
515
  uniformType = {};
504
516
  uniformIsArray = {};
505
517
  gl;
506
- shaderId = Ot++;
518
+ shaderId = Bt++;
507
519
  // for debug
508
520
  vao;
509
521
  constructor(t, e, r, i) {
510
- this.gl = t, this.program = Pt(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
522
+ this.gl = t, this.program = It(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
511
523
  }
512
524
  use() {
513
525
  this.gl.useProgram(this.program);
@@ -523,7 +535,7 @@ class Tt {
523
535
  const r = this.uniformLoc[t];
524
536
  if (r === void 0) return;
525
537
  const i = this.uniformType[t], s = this.uniformIsArray[t];
526
- Wt(this.gl, r, i, e, s);
538
+ Dt(this.gl, r, i, e, s);
527
539
  }
528
540
  setUniforms(t) {
529
541
  for (const e in t)
@@ -537,11 +549,11 @@ class Tt {
537
549
  r.vertexAttribPointer(
538
550
  e,
539
551
  t.size,
540
- t.type ?? Nt,
552
+ t.type ?? Ft,
541
553
  t.normalized ?? !1,
542
554
  t.stride,
543
555
  t.offset ?? 0
544
- ), r.enableVertexAttribArray(e), It(r, e, t.divisor ?? 0);
556
+ ), r.enableVertexAttribArray(e), Ot(r, e, t.divisor ?? 0);
545
557
  }
546
558
  setAttributes(t) {
547
559
  for (const e of t)
@@ -555,19 +567,19 @@ class Tt {
555
567
  const e = this.gl, r = t.match(/(?:in|attribute)\s+\w+\s+\w+/g);
556
568
  if (r)
557
569
  for (const s of r) {
558
- const h = s.split(/\s+/)[2], o = e.getAttribLocation(this.program, h);
559
- o !== -1 && (this.attributeLoc[h] = o);
570
+ const o = s.split(/\s+/)[2], h = e.getAttribLocation(this.program, o);
571
+ h !== -1 && (this.attributeLoc[o] = h);
560
572
  }
561
573
  const i = t.matchAll(
562
574
  /uniform\s+(?:(?:lowp|mediump|highp)\s+)?(\w+)\s+(\w+)(\s*\[\s*\d+\s*\])?/g
563
575
  );
564
576
  for (const s of i) {
565
- const a = s[1], h = s[2], o = e.getUniformLocation(this.program, h);
566
- o !== null && (this.uniformLoc[h] = o, this.uniformType[h] = a, this.uniformIsArray[h] = s[3] !== void 0);
577
+ const a = s[1], o = s[2], h = e.getUniformLocation(this.program, o);
578
+ h !== null && (this.uniformLoc[o] = h, this.uniformType[o] = a, this.uniformIsArray[o] = s[3] !== void 0);
567
579
  }
568
580
  }
569
581
  }
570
- function Wt(n, t, e, r, i = !1) {
582
+ function Dt(n, t, e, r, i = !1) {
571
583
  switch (e) {
572
584
  // scalars
573
585
  case "float":
@@ -605,10 +617,10 @@ function Wt(n, t, e, r, i = !1) {
605
617
  return n.uniformMatrix3x2fv(t, !1, r);
606
618
  // fallback: guess by value shape
607
619
  default:
608
- return Dt(n, t, r);
620
+ return Wt(n, t, r);
609
621
  }
610
622
  }
611
- function Dt(n, t, e) {
623
+ function Wt(n, t, e) {
612
624
  if (typeof e == "number")
613
625
  return n.uniform1f(t, e);
614
626
  const r = e;
@@ -627,7 +639,7 @@ function Dt(n, t, e) {
627
639
  return n.uniform1fv(t, r);
628
640
  }
629
641
  }
630
- class ct {
642
+ class ut {
631
643
  vs;
632
644
  fs;
633
645
  glshader = /* @__PURE__ */ new Map();
@@ -640,7 +652,11 @@ class ct {
640
652
  rapid;
641
653
  prefix = [];
642
654
  constructor(t, e = "", r = "", i = 0, s) {
643
- this.vs = e, this.fs = r, this.rapid = t, this.uniforms = s ?? {}, this.usedTextureUnitNum = i;
655
+ this.vs = e, this.fs = r, this.rapid = t, this.uniforms = s ?? {}, this.usedTextureUnitNum = i, this.beforePreCompile(), this.preCompile();
656
+ }
657
+ beforePreCompile() {
658
+ }
659
+ preCompile() {
644
660
  }
645
661
  setUniforms(t) {
646
662
  this.rapid.flush();
@@ -670,7 +686,7 @@ class ct {
670
686
  if (i == null || r == null)
671
687
  return console.warn("CustomGlShader: missing base shader for " + e), null;
672
688
  const s = this.prefix.length == 0 ? [""] : this.prefix;
673
- 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);
689
+ r = r.replace("// CUSTOM_CODE_CALL", s.map((o) => o + "vertex(position, vRegion);").join("")), r = this.replaceCustomCode(r, this.vs), i = i.replace("// CUSTOM_CODE_CALL", s.map((o) => o + "fragment(fragColor, vRegion);").join("")), i = this.replaceCustomCode(i, this.fs);
674
690
  const a = t.createShader(r, i);
675
691
  return a.isCustom = !0, a.padding = this.padding, this.glshader.set(e, a), this.uniformDirty.add(e), a;
676
692
  }
@@ -678,7 +694,7 @@ class ct {
678
694
  this.glshader.forEach((t) => t.destroy());
679
695
  }
680
696
  }
681
- class Et {
697
+ class Rt {
682
698
  constructor(t) {
683
699
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
684
700
  }
@@ -726,16 +742,16 @@ class Et {
726
742
  }
727
743
  createShader(t, e) {
728
744
  const r = this.getMaxTexutreUnit();
729
- return e = K(e, r), t = K(t, r), new Tt(this.gl, t, e);
745
+ return e = Z(e, r), t = Z(t, r), new Et(this.gl, t, e);
730
746
  }
731
747
  createCustomShader(t) {
732
- const e = this.getMaxTexutreUnit(t), r = K(this.fs, e), i = K(this.vs, e);
748
+ const e = this.getMaxTexutreUnit(t), r = Z(this.fs, e), i = Z(this.vs, e);
733
749
  return t.getGLShader(this, this.KEY, i, r);
734
750
  }
735
751
  getCustomShader(t) {
736
752
  if (!t)
737
753
  return this.defaultShader;
738
- if (t instanceof ct) {
754
+ if (t instanceof ut) {
739
755
  const e = this.createCustomShader(t);
740
756
  return e ?? this.defaultShader;
741
757
  }
@@ -745,7 +761,7 @@ class Et {
745
761
  return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
746
762
  }
747
763
  enter(t) {
748
- this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ct ? (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);
764
+ this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ut ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
749
765
  }
750
766
  exit() {
751
767
  this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
@@ -763,7 +779,7 @@ class Et {
763
779
  for (const [s, a] of Object.entries(r.uniformTextures))
764
780
  i[s] = this.useTexture(a);
765
781
  for (const [s, a] of Object.entries(r.uniformArrayTexture))
766
- i[s] = a.map((h) => this.useTexture(h));
782
+ i[s] = a.map((o) => this.useTexture(o));
767
783
  this.customShader.applyUniform(this.KEY, i);
768
784
  }
769
785
  const e = this.gl;
@@ -787,8 +803,8 @@ class Et {
787
803
  return !1;
788
804
  }
789
805
  }
790
- var A = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(A || {});
791
- class b {
806
+ var C = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(C || {});
807
+ class _ {
792
808
  usedElemNum;
793
809
  typedArray;
794
810
  arrayType;
@@ -830,24 +846,24 @@ class b {
830
846
  this.usedElemNum = 0;
831
847
  }
832
848
  static removeAtIndices(t, e) {
833
- const r = Math.max(...e.map((h) => h.usedElemNum)), i = [...new Set(t)].filter(
834
- (h) => h >= 0 && h < r
835
- ).sort((h, o) => h - o);
849
+ const r = Math.max(...e.map((o) => o.usedElemNum)), i = [...new Set(t)].filter(
850
+ (o) => o >= 0 && o < r
851
+ ).sort((o, h) => o - h);
836
852
  if (i.length === 0)
837
853
  return 0;
838
854
  let s = 0, a = 0;
839
- for (let h = 0; h < r; h++) {
840
- if (a < i.length && h === i[a]) {
855
+ for (let o = 0; o < r; o++) {
856
+ if (a < i.length && o === i[a]) {
841
857
  a++;
842
858
  continue;
843
859
  }
844
- if (s !== h)
845
- for (const o of e)
846
- o.typedArray[s] = o.typedArray[h];
860
+ if (s !== o)
861
+ for (const h of e)
862
+ h.typedArray[s] = h.typedArray[o];
847
863
  s++;
848
864
  }
849
- for (const h of e)
850
- h.usedElemNum = s;
865
+ for (const o of e)
866
+ o.usedElemNum = s;
851
867
  return r - s;
852
868
  }
853
869
  resize(t = 0) {
@@ -887,7 +903,7 @@ class b {
887
903
  return this.usedElemNum;
888
904
  }
889
905
  }
890
- class ut extends b {
906
+ class lt extends _ {
891
907
  buffer;
892
908
  gl;
893
909
  dirty = !0;
@@ -913,7 +929,7 @@ class ut extends b {
913
929
  }
914
930
  }
915
931
  }
916
- const et = `#version 300 es\r
932
+ const st = `#version 300 es\r
917
933
  precision highp float;\r
918
934
  \r
919
935
  // per-vertex\r
@@ -961,7 +977,7 @@ void main(void) {\r
961
977
  \r
962
978
  gl_Position = u_projection * position;\r
963
979
  }\r
964
- `, ft = `#version 300 es\r
980
+ `, mt = `#version 300 es\r
965
981
  precision mediump float;\r
966
982
  \r
967
983
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -998,8 +1014,8 @@ void main(void) {\r
998
1014
  \r
999
1015
  // CUSTOM_CODE_CALL\r
1000
1016
  }\r
1001
- `, z = 48, Ft = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1002
- class lt extends Et {
1017
+ `, j = 48, kt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1018
+ class dt extends Rt {
1003
1019
  instanceBuffer;
1004
1020
  quadBuffer;
1005
1021
  instanceCount = 0;
@@ -1011,64 +1027,64 @@ class lt extends Et {
1011
1027
  }
1012
1028
  createBuffer() {
1013
1029
  const t = this.gl;
1014
- this.quadBuffer = new ut(t, A.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1015
- for (const e of Ft) this.quadBuffer.pushFloat32(e);
1016
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new ut(t, A.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1030
+ this.quadBuffer = new lt(t, C.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1031
+ for (const e of kt) this.quadBuffer.pushFloat32(e);
1032
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new lt(t, C.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1017
1033
  }
1018
1034
  createDefaultShader() {
1019
- return this.vs = et, this.fs = ft, this.defaultShader = this.createShader(et, ft), this.defaultShader;
1035
+ return this.vs = st, this.fs = mt, this.defaultShader = this.createShader(st, mt), this.defaultShader;
1020
1036
  }
1021
1037
  createShader(t, e) {
1022
1038
  const r = super.createShader(t, e);
1023
1039
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1024
- { name: "aMatrixRow0", size: 3, stride: z, offset: 0, divisor: 1 },
1025
- { name: "aMatrixRow1", size: 3, stride: z, offset: 12, divisor: 1 },
1026
- { name: "aUVRect", size: 4, stride: z, offset: 24, divisor: 1 },
1027
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: z, offset: 40, divisor: 1 },
1028
- { name: "aTextureId", size: 1, type: ot, stride: z, offset: 44, divisor: 1 }
1040
+ { name: "aMatrixRow0", size: 3, stride: j, offset: 0, divisor: 1 },
1041
+ { name: "aMatrixRow1", size: 3, stride: j, offset: 12, divisor: 1 },
1042
+ { name: "aUVRect", size: 4, stride: j, offset: 24, divisor: 1 },
1043
+ { name: "aColor", size: 4, type: ct, normalized: !0, stride: j, offset: 40, divisor: 1 },
1044
+ { name: "aTextureId", size: 1, type: ct, stride: j, offset: 44, divisor: 1 }
1029
1045
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1030
1046
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1031
1047
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1032
1048
  }
1033
- drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, h = 4294967295, o = 0, c = 0, u = !1, l = !1, f = !1) {
1034
- const d = e * 6, x = this.matrixStore.data;
1049
+ drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, o = 4294967295, h = 0, c = 0, u = !1, l = !1, d = !1) {
1050
+ const f = e * 6, m = this.matrixStore.data;
1035
1051
  this.drawSpriteAffine(
1036
1052
  t,
1037
- x[d],
1038
- x[d + 1],
1039
- x[d + 2],
1040
- x[d + 3],
1041
- x[d + 4],
1042
- x[d + 5],
1053
+ m[f],
1054
+ m[f + 1],
1055
+ m[f + 2],
1056
+ m[f + 3],
1057
+ m[f + 4],
1058
+ m[f + 5],
1043
1059
  r,
1044
1060
  i,
1045
1061
  s,
1046
1062
  a,
1047
- h,
1048
1063
  o,
1064
+ h,
1049
1065
  c,
1050
1066
  u,
1051
1067
  l,
1052
- f
1068
+ d
1053
1069
  );
1054
1070
  }
1055
- 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) {
1056
- const E = t.base, S = t.rawWidth, _ = t.rawHeight, P = t.offsetX, k = t.offsetY, I = this.useTexture(
1071
+ drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0, x = !1, y = !1, v = !1) {
1072
+ const T = t.base, w = t.rawWidth, U = t.rawHeight, P = t.offsetX, O = t.offsetY, L = this.useTexture(
1057
1073
  t.glTexture,
1058
- d / E.width,
1059
- x / E.height
1060
- ), C = this.instanceBuffer, R = C.usedElemNum;
1061
- C.resize(12);
1062
- const w = C.float32, O = C.uint32, B = v ? _ : S, G = v ? S : _, L = B + 2 * d, W = G + 2 * x, D = P - d, H = k - x, M = this.localSpriteMatrix;
1063
- v ? (M[0] = 0, M[1] = y ? W : -W, M[2] = p ? -L : L, M[3] = 0, M[4] = D + (p ? L : 0), M[5] = H + (y ? 0 : W)) : (M[0] = p ? -L : L, M[1] = 0, M[2] = 0, M[3] = y ? -W : W, M[4] = D + (p ? L : 0), M[5] = H + (y ? W : 0));
1064
- const U = this.worldSpriteMatrix;
1065
- 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, O[R + 10] = f, O[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++;
1074
+ f / T.width,
1075
+ m / T.height
1076
+ ), S = this.instanceBuffer, E = S.usedElemNum;
1077
+ S.resize(12);
1078
+ const b = S.float32, I = S.uint32, k = v ? U : w, G = v ? w : U, N = k + 2 * f, F = G + 2 * m, V = P - f, H = O - m, R = this.localSpriteMatrix;
1079
+ v ? (R[0] = 0, R[1] = y ? F : -F, R[2] = x ? -N : N, R[3] = 0, R[4] = V + (x ? N : 0), R[5] = H + (y ? 0 : F)) : (R[0] = x ? -N : N, R[1] = 0, R[2] = 0, R[3] = y ? -F : F, R[4] = V + (x ? N : 0), R[5] = H + (y ? F : 0));
1080
+ const A = this.worldSpriteMatrix;
1081
+ A[0] = e * R[0] + i * R[1], A[1] = r * R[0] + s * R[1], A[2] = e * R[2] + i * R[3], A[3] = r * R[2] + s * R[3], A[4] = a + e * R[4] + i * R[5], A[5] = o + r * R[4] + s * R[5], b[E + 6] = h, b[E + 7] = c, b[E + 8] = u, b[E + 9] = l, I[E + 10] = d, I[E + 11] = L, this.rapid.roundPixels && (A[4] = Math.round(A[4]), A[5] = Math.round(A[5])), b[E] = A[0], b[E + 1] = A[2], b[E + 2] = A[4], b[E + 3] = A[1], b[E + 4] = A[3], b[E + 5] = A[5], S.usedElemNum += 12, S.makeDirty(), this.instanceCount++;
1066
1082
  }
1067
1083
  render() {
1068
1084
  if (this.instanceCount === 0) return;
1069
1085
  this.prepareRender();
1070
1086
  const t = this.gl, e = this.currentShader;
1071
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1087
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), wt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1072
1088
  }
1073
1089
  resetRender() {
1074
1090
  super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
@@ -1077,66 +1093,78 @@ class lt extends Et {
1077
1093
  return this.instanceCount > 0;
1078
1094
  }
1079
1095
  }
1080
- const T = 6;
1081
- class Bt {
1096
+ const M = 6;
1097
+ class Gt {
1082
1098
  matrixCount = 0;
1083
1099
  buffer;
1084
1100
  data;
1101
+ freeFlag;
1102
+ freeMatrixStack;
1085
1103
  temporary = -1;
1104
+ identityMatrix = -1;
1086
1105
  constructor(t = 10) {
1087
- this.buffer = new b(A.Float32), this.buffer.resize(t * T), this.data = this.buffer.getArray(), this.reset();
1106
+ this.buffer = new _(C.Float32), this.buffer.resize(t * M), this.data = this.buffer.getArray(), this.freeFlag = new _(C.Uint32), this.freeMatrixStack = new _(C.Uint32), this.reset();
1088
1107
  }
1089
1108
  alloc() {
1090
1109
  const t = this.allocDirty();
1091
1110
  return this.identity(t), t;
1092
1111
  }
1093
1112
  allocDirty() {
1094
- return this.buffer.resize(T) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += T, this.matrixCount++;
1113
+ if (this.freeMatrixStack.length > 0) {
1114
+ const e = this.freeMatrixStack.pop();
1115
+ return this.freeFlag.typedArray[e] = 1, e;
1116
+ }
1117
+ this.buffer.resize(M) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += M, this.freeFlag.resize(1);
1118
+ const t = this.matrixCount++;
1119
+ return this.freeFlag.typedArray[this.freeFlag.usedElemNum++] = 1, t;
1120
+ }
1121
+ free(t) {
1122
+ !Number.isInteger(t) || t < 0 || t >= this.matrixCount || this.freeFlag.typedArray[t] !== 0 && (this.freeFlag.typedArray[t] = 0, this.freeMatrixStack.push(t));
1095
1123
  }
1096
1124
  reset() {
1097
- this.matrixCount = 0, this.buffer.usedElemNum = 0, this.temporary = this.alloc();
1125
+ this.matrixCount = 0, this.buffer.usedElemNum = 0, this.freeFlag.clear(), this.freeMatrixStack.clear(), this.temporary = this.alloc(), this.identityMatrix = this.alloc();
1098
1126
  }
1099
1127
  identity(t) {
1100
- const e = t * T, r = this.data;
1128
+ const e = t * M, r = this.data;
1101
1129
  r[e] = 1, r[e + 1] = 0, r[e + 2] = 0, r[e + 3] = 1, r[e + 4] = 0, r[e + 5] = 0;
1102
1130
  }
1103
1131
  translate(t, e, r) {
1104
- const i = t * T, s = this.data;
1132
+ const i = t * M, s = this.data;
1105
1133
  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];
1106
1134
  }
1107
1135
  scale(t, e, r) {
1108
- const i = t * T, s = this.data;
1136
+ const i = t * M, s = this.data;
1109
1137
  s[i] *= e, s[i + 1] *= e, s[i + 2] *= r, s[i + 3] *= r;
1110
1138
  }
1111
1139
  rotate(t, e) {
1112
- const r = t * T, 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];
1113
- 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;
1140
+ const r = t * M, i = this.data, s = Math.cos(e), a = Math.sin(e), o = i[r], h = i[r + 1], c = i[r + 2], u = i[r + 3];
1141
+ i[r] = o * s + c * a, i[r + 1] = h * s + u * a, i[r + 2] = o * -a + c * s, i[r + 3] = h * -a + u * s;
1114
1142
  }
1115
1143
  rotateWithOffset(t, e, r, i) {
1116
1144
  this.translate(t, r, i), this.rotate(t, e), this.translate(t, -r, -i);
1117
1145
  }
1118
1146
  copy(t, e) {
1119
- const r = t * T, i = e * T, s = this.data;
1147
+ const r = t * M, i = e * M, s = this.data;
1120
1148
  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];
1121
1149
  }
1122
1150
  multiply(t, e) {
1123
1151
  this.multiplyOut(t, t, e);
1124
1152
  }
1125
1153
  multiplyOut(t, e, r) {
1126
- 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];
1127
- 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;
1154
+ const i = t * M, s = e * M, a = r * M, o = this.data, h = o[s], c = o[s + 1], u = o[s + 2], l = o[s + 3], d = o[s + 4], f = o[s + 5], m = o[a], x = o[a + 1], y = o[a + 2], v = o[a + 3], T = o[a + 4], w = o[a + 5];
1155
+ o[i] = h * m + u * x, o[i + 1] = c * m + l * x, o[i + 2] = h * y + u * v, o[i + 3] = c * y + l * v, o[i + 4] = h * T + u * w + d, o[i + 5] = c * T + l * w + f;
1128
1156
  }
1129
1157
  invert(t) {
1130
- 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];
1131
- let u = i * h - s * a;
1158
+ const e = t * M, r = this.data, i = r[e], s = r[e + 1], a = r[e + 2], o = r[e + 3], h = r[e + 4], c = r[e + 5];
1159
+ let u = i * o - s * a;
1132
1160
  if (!u) {
1133
1161
  this.identity(t);
1134
1162
  return;
1135
1163
  }
1136
- 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;
1164
+ u = 1 / u, r[e] = o * u, r[e + 1] = -s * u, r[e + 2] = -a * u, r[e + 3] = i * u, r[e + 4] = (a * c - o * h) * u, r[e + 5] = (s * h - i * c) * u;
1137
1165
  }
1138
1166
  transformPoint(t, e, r) {
1139
- const i = t * T, s = this.data;
1167
+ const i = t * M, s = this.data;
1140
1168
  return {
1141
1169
  x: e * s[i] + r * s[i + 2] + s[i + 4],
1142
1170
  y: e * s[i + 1] + r * s[i + 3] + s[i + 5]
@@ -1146,115 +1174,105 @@ class Bt {
1146
1174
  const i = this.allocDirty();
1147
1175
  this.copy(i, t), this.invert(i);
1148
1176
  const s = this.transformPoint(i, e, r);
1149
- return this.matrixCount--, this.buffer.usedElemNum -= T, s;
1177
+ return this.free(i), s;
1150
1178
  }
1151
1179
  localToWorld(t, e, r) {
1152
1180
  return this.transformPoint(t, e, r);
1153
1181
  }
1154
1182
  getPosition(t) {
1155
- const e = t * T, r = this.data;
1183
+ const e = t * M, r = this.data;
1156
1184
  return { x: r[e + 4], y: r[e + 5] };
1157
1185
  }
1158
1186
  getScale(t) {
1159
- const e = t * T, 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]);
1187
+ 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]);
1160
1188
  return { x: i, y: s };
1161
1189
  }
1162
1190
  getRotation(t) {
1163
- const e = t * T, r = this.data;
1191
+ const e = t * M, r = this.data;
1164
1192
  return Math.atan2(r[e + 1], r[e]);
1165
1193
  }
1166
1194
  toCSSMatrix(t, e = 1, r = 1) {
1167
- const i = t * T, s = this.data;
1195
+ const i = t * M, s = this.data;
1168
1196
  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})`;
1169
1197
  }
1170
1198
  getMatrix(t) {
1171
- const e = t * T;
1172
- return this.data.slice(e, e + T);
1199
+ const e = t * M;
1200
+ return this.data.slice(e, e + M);
1173
1201
  }
1174
1202
  getMatrixRef(t) {
1175
- const e = t * T;
1176
- return this.data.subarray(e, e + T);
1203
+ const e = t * M;
1204
+ return this.data.subarray(e, e + M);
1177
1205
  }
1178
1206
  setMatrix(t, e) {
1179
- const r = t * T, i = this.data;
1207
+ const r = t * M, i = this.data;
1180
1208
  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];
1181
1209
  }
1182
- multiplyAffineInPlace(t, e, r, i, s, a, h) {
1183
- const o = t * 6, c = this.data, u = c[o], l = c[o + 1], f = c[o + 2], d = c[o + 3], x = c[o + 4], p = c[o + 5];
1184
- 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;
1210
+ multiplyAffineInPlace(t, e, r, i, s, a, o) {
1211
+ const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], m = c[h + 4], x = c[h + 5];
1212
+ c[h] = u * e + d * r, c[h + 1] = l * e + f * r, c[h + 2] = u * i + d * s, c[h + 3] = l * i + f * s, c[h + 4] = u * a + d * o + m, c[h + 5] = l * a + f * o + x;
1185
1213
  }
1186
- multiplyAffine(t, e, r, i, s, a, h, o) {
1187
- 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];
1188
- 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;
1214
+ multiplyAffine(t, e, r, i, s, a, o, h) {
1215
+ const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2], x = l[c + 3], y = l[c + 4], v = l[c + 5];
1216
+ l[u] = d * r + m * i, l[u + 1] = f * r + x * i, l[u + 2] = d * s + m * a, l[u + 3] = f * s + x * a, l[u + 4] = d * o + m * h + y, l[u + 5] = f * o + x * h + v;
1217
+ }
1218
+ clampBounds(t, e, r, i, s, a, o) {
1219
+ if (i === void 0 && s === void 0 && a === void 0 && o === void 0)
1220
+ return;
1221
+ const h = t * M, c = this.data, u = Math.sqrt(c[h] * c[h] + c[h + 1] * c[h + 1]) || 1, l = Math.sqrt(c[h + 2] * c[h + 2] + c[h + 3] * c[h + 3]) || 1, d = e * 0.5 * u, f = r * 0.5 * l;
1222
+ let m = c[h + 4], x = c[h + 5];
1223
+ i !== void 0 && s !== void 0 ? m = s - i < d * 2 ? (i + s) * 0.5 : Math.max(i + d, Math.min(m, s - d)) : i !== void 0 ? m = Math.max(m, i + d) : s !== void 0 && (m = Math.min(m, s - d)), a !== void 0 && o !== void 0 ? x = o - a < f * 2 ? (a + o) * 0.5 : Math.max(a + f, Math.min(x, o - f)) : a !== void 0 ? x = Math.max(x, a + f) : o !== void 0 && (x = Math.min(x, o - f)), c[h + 4] = m, c[h + 5] = x;
1224
+ }
1225
+ applyTransform(t, e = 0, r = 0) {
1226
+ let i = t.x ?? 0, s = t.y ?? 0;
1227
+ t.position && (i += t.position.x, s += t.position.y);
1228
+ let a = 1, o = 1;
1229
+ const h = t.scale;
1230
+ h !== void 0 && (typeof h == "number" ? (a = h, o = h) : (a = h.x, o = h.y));
1231
+ const c = t.rotation ?? 0;
1232
+ let u = t.offsetX ?? 0, l = t.offsetY ?? 0;
1233
+ t.offset && (u += t.offset.x, l += t.offset.y);
1234
+ const d = t.origin;
1235
+ d !== void 0 && (typeof d == "number" ? (u -= d * e, l -= d * r) : (u -= d.x * e, l -= d.y * r));
1236
+ const f = c ? Math.cos(c) : 1, m = c ? Math.sin(c) : 0, x = f * a, y = m * a, v = -m * o, T = f * o, w = i + x * u + v * l, U = s + y * u + T * l;
1237
+ return [
1238
+ x,
1239
+ y,
1240
+ v,
1241
+ T,
1242
+ w,
1243
+ U
1244
+ ];
1189
1245
  }
1190
1246
  }
1191
- class kt {
1192
- matrix = new Bt();
1193
- step = 0;
1194
- stack = new b(A.Uint32);
1195
- stepWorldM = new b(A.Uint32);
1196
- stepAction = new b(A.Uint32);
1197
- stepParentM = new b(A.Uint32);
1198
- stepClose = new b(A.Uint32);
1199
- stepStack = new b(A.Uint32);
1247
+ class Ht {
1248
+ matrix = new Gt();
1249
+ stack = new _(C.Uint32);
1250
+ currStack = new _(C.Uint32);
1200
1251
  curLocalM = -1;
1201
1252
  curWorldM = -1;
1202
1253
  rapid;
1203
1254
  constructor(t) {
1204
1255
  this.reset(), this.rapid = t;
1205
1256
  }
1206
- save() {
1207
- this.stack.push(this.curWorldM);
1208
- const t = this.curWorldM;
1209
- 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++ };
1257
+ save(t, e) {
1258
+ this.stack.push(this.curLocalM), this.stack.push(this.curWorldM);
1259
+ const r = this.curWorldM;
1260
+ return this.curLocalM = e ?? this.matrix.alloc(), this.curWorldM = t ?? this.matrix.allocDirty(), t === void 0 && (e === void 0 ? this.matrix.copy(this.curWorldM, r) : this.matrix.multiplyOut(this.curWorldM, r, this.curLocalM)), this.currStack.push(this.curLocalM), this.currStack.push(this.curWorldM), { parent: r, world: this.curWorldM, local: this.curLocalM };
1210
1261
  }
1211
1262
  restore() {
1212
- 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++);
1263
+ this.stack.length != 0 && (this.curWorldM = this.stack.pop(), this.curLocalM = this.stack.pop());
1213
1264
  }
1214
1265
  restoreAll() {
1215
- for (; this.stack.length > 0 && this.stepStack.length > 0; )
1266
+ for (; this.stack.length > 0; )
1216
1267
  this.restore();
1217
1268
  }
1218
- getStep(t) {
1219
- return typeof t == "number" ? t : t.step;
1220
- }
1221
- walkSubtree(t, e, r = 1 / 0) {
1222
- let i = 0, s = t;
1223
- for (; s < this.step; ) {
1224
- const a = this.stepAction.get(s);
1225
- if (a === 1) {
1226
- if (i++, i > r) {
1227
- const h = this.stepClose.get(s);
1228
- if (h > s) {
1229
- s = h + 1, i--;
1230
- continue;
1231
- }
1232
- }
1233
- } else
1234
- i--;
1235
- if (e(s, a, i) === !1 || a === 0 && i === 0) return;
1236
- s++;
1237
- }
1238
- }
1239
- getParent(t) {
1240
- const e = this.getStep(t);
1241
- return this.stepParentM.get(e);
1242
- }
1243
- getChildren(t) {
1244
- const e = this.getStep(t), r = this.stepClose.get(e), i = [];
1245
- let s = e + 1;
1246
- for (; s < r; )
1247
- this.stepAction.get(s) === 1 ? (i.push(s), s = this.stepClose.get(s) + 1) : s++;
1248
- return i;
1249
- }
1250
- updateMatrixSubtree(t) {
1251
- const e = this.getStep(t);
1252
- this.walkSubtree(e, (r, i) => {
1253
- if (i === 1) {
1254
- const s = this.stepWorldM.get(r), a = s - 1, h = this.stepParentM.get(r);
1255
- this.matrix.multiplyOut(s, h, a);
1256
- }
1257
- });
1269
+ retainMatrix(t) {
1270
+ const e = new Set(
1271
+ typeof t == "number" ? [t] : [t.local, t.world]
1272
+ ), r = [];
1273
+ for (let i = 0; i < this.currStack.length; i++)
1274
+ e.has(this.currStack.get(i)) && r.push(i);
1275
+ _.removeAtIndices(r, [this.currStack]);
1258
1276
  }
1259
1277
  translate(t, e) {
1260
1278
  this.matrix.translate(this.curLocalM, t, e), this.matrix.translate(this.curWorldM, t, e);
@@ -1272,7 +1290,9 @@ class kt {
1272
1290
  this.matrix.identity(this.curLocalM), this.matrix.identity(this.curWorldM);
1273
1291
  }
1274
1292
  reset() {
1275
- 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();
1293
+ for (let t = 0; t < this.currStack.length; t++)
1294
+ this.matrix.free(this.currStack.typedArray[t]);
1295
+ this.currStack.clear(), this.stack.clear(), this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.alloc(), this.currStack.push(this.curLocalM), this.currStack.push(this.curWorldM);
1276
1296
  }
1277
1297
  localToWorld(t, e) {
1278
1298
  return this.matrix.localToWorld(this.curWorldM, t, e);
@@ -1293,61 +1313,54 @@ class kt {
1293
1313
  return this.matrix.toCSSMatrix(this.curWorldM);
1294
1314
  }
1295
1315
  getTransform() {
1296
- const t = this.curWorldM * T;
1297
- return this.matrix.data.slice(t, t + T);
1316
+ const t = this.curWorldM * M;
1317
+ return this.matrix.data.slice(t, t + M);
1298
1318
  }
1299
1319
  setTransform(t) {
1300
- const e = this.curWorldM * T, r = this.matrix.data;
1320
+ const e = this.curWorldM * M, r = this.matrix.data;
1301
1321
  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];
1302
1322
  }
1303
1323
  transformPoint(t, e) {
1304
1324
  return this.matrix.transformPoint(this.curLocalM, t, e);
1305
1325
  }
1306
- applyTransform(t, e = 0, r = 0, i = -1) {
1307
- let s = t.x ?? 0, a = t.y ?? 0;
1308
- t.position && (s += t.position.x, a += t.position.y);
1309
- let h = 1, o = 1;
1310
- const c = t.scale;
1311
- c && (typeof c == "number" ? (h = c, o = c) : (h = c.x, o = c.y));
1312
- const u = t.rotation ?? 0;
1313
- let l = t.offsetX ?? 0, f = t.offsetY ?? 0;
1314
- t.offset && (l += t.offset.x, f += t.offset.y);
1315
- const d = t.origin;
1316
- d !== void 0 && (typeof d == "number" ? (l -= d * e, f -= d * r) : (l -= d.x * e, f -= d.y * r));
1317
- 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;
1318
- if (i !== -1) {
1319
- this.matrix.multiplyAffine(
1320
- this.curWorldM,
1321
- i,
1322
- y,
1323
- v,
1324
- E,
1325
- S,
1326
- _,
1327
- P
1328
- );
1329
- return;
1330
- }
1331
- this.matrix.multiplyAffineInPlace(
1332
- this.curLocalM,
1333
- y,
1334
- v,
1335
- E,
1336
- S,
1337
- _,
1338
- P
1326
+ applyTransform(t, e = 0, r = 0, i, s = this.curWorldM, a = this.curLocalM) {
1327
+ const [
1328
+ o,
1329
+ h,
1330
+ c,
1331
+ u,
1332
+ l,
1333
+ d
1334
+ ] = this.matrix.applyTransform(t, e, r);
1335
+ i != null ? this.matrix.multiplyAffine(
1336
+ s,
1337
+ i,
1338
+ o,
1339
+ h,
1340
+ c,
1341
+ u,
1342
+ l,
1343
+ d
1344
+ ) : (this.matrix.multiplyAffineInPlace(
1345
+ a,
1346
+ o,
1347
+ h,
1348
+ c,
1349
+ u,
1350
+ l,
1351
+ d
1339
1352
  ), this.matrix.multiplyAffineInPlace(
1340
- this.curWorldM,
1341
- y,
1342
- v,
1343
- E,
1344
- S,
1345
- _,
1346
- P
1347
- );
1353
+ s,
1354
+ o,
1355
+ h,
1356
+ c,
1357
+ u,
1358
+ l,
1359
+ d
1360
+ ));
1348
1361
  }
1349
1362
  }
1350
- const Ht = `#version 300 es\r
1363
+ const Vt = `#version 300 es\r
1351
1364
  precision highp float;\r
1352
1365
  \r
1353
1366
  in vec2 aPosition;\r
@@ -1378,7 +1391,7 @@ void main(void) {\r
1378
1391
  // CUSTOM_CODE_CALL\r
1379
1392
  gl_Position = u_projection * position;\r
1380
1393
  }\r
1381
- `, Gt = `#version 300 es\r
1394
+ `, Xt = `#version 300 es\r
1382
1395
  precision mediump float;\r
1383
1396
  \r
1384
1397
  in vec4 vColor;\r
@@ -1425,7 +1438,7 @@ void main(void) {\r
1425
1438
  fragColor = sampleTexture(vRegion) * vColor;\r
1426
1439
  // CUSTOM_CODE_CALL\r
1427
1440
  }\r
1428
- `, Vt = `#version 300 es\r
1441
+ `, Yt = `#version 300 es\r
1429
1442
  precision highp float;\r
1430
1443
  \r
1431
1444
  in vec2 aPosition;\r
@@ -1448,7 +1461,7 @@ void main(void) {\r
1448
1461
  );\r
1449
1462
  gl_Position = u_projection * position;\r
1450
1463
  }\r
1451
- `, Xt = `#version 300 es\r
1464
+ `, zt = `#version 300 es\r
1452
1465
  precision mediump float;\r
1453
1466
  \r
1454
1467
  in vec2 vRegion;\r
@@ -1468,8 +1481,8 @@ void main(void) {\r
1468
1481
  discard;\r
1469
1482
  }\r
1470
1483
  }\r
1471
- `, $ = 20;
1472
- class Yt extends Et {
1484
+ `, K = 20;
1485
+ class $t extends Rt {
1473
1486
  vertexBuffer;
1474
1487
  vertexCount = 0;
1475
1488
  extraTextureUnit = 1;
@@ -1483,24 +1496,24 @@ class Yt extends Et {
1483
1496
  }
1484
1497
  createBuffer() {
1485
1498
  const t = this.gl;
1486
- this.vertexBuffer = new ut(t, A.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Vt, Xt);
1499
+ this.vertexBuffer = new lt(t, C.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Yt, zt);
1487
1500
  }
1488
1501
  createDefaultShader() {
1489
- return this.vs = Ht, this.fs = Gt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1502
+ return this.vs = Vt, this.fs = Xt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1490
1503
  }
1491
1504
  createMaskShader(t, e) {
1492
- const r = this.gl, i = new Tt(r, t, e);
1505
+ const r = this.gl, i = new Et(r, t, e);
1493
1506
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
1494
- { name: "aPosition", size: 2, type: r.FLOAT, stride: $ - 4, offset: 0, divisor: 0 },
1495
- { name: "aUV", size: 2, type: r.FLOAT, stride: $ - 4, offset: 8, divisor: 0 }
1507
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: K - 4, offset: 0, divisor: 0 },
1508
+ { name: "aUV", size: 2, type: r.FLOAT, stride: K - 4, offset: 8, divisor: 0 }
1496
1509
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1497
1510
  }
1498
1511
  createShader(t, e) {
1499
1512
  const r = this.gl, i = super.createShader(t, e);
1500
1513
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
1501
- { name: "aPosition", size: 2, type: r.FLOAT, stride: $, offset: 0, divisor: 0 },
1502
- { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: $, offset: 8, divisor: 0 },
1503
- { name: "aUV", size: 2, type: r.FLOAT, stride: $, offset: 12, divisor: 0 }
1514
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: K, offset: 0, divisor: 0 },
1515
+ { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: K, offset: 8, divisor: 0 },
1516
+ { name: "aUV", size: 2, type: r.FLOAT, stride: K, offset: 12, divisor: 0 }
1504
1517
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1505
1518
  }
1506
1519
  startGraphic(t, e = this.gl.TRIANGLES, r) {
@@ -1527,32 +1540,32 @@ class Yt extends Et {
1527
1540
  return !1;
1528
1541
  }
1529
1542
  }
1530
- class g {
1543
+ class p {
1531
1544
  x;
1532
1545
  y;
1533
- static ZERO = new g(0, 0);
1534
- static ONE = new g(1, 1);
1535
- static UP = new g(0, 1);
1536
- static DOWN = new g(0, -1);
1537
- static LEFT = new g(-1, 0);
1538
- static RIGHT = new g(1, 0);
1546
+ static ZERO = new p(0, 0);
1547
+ static ONE = new p(1, 1);
1548
+ static UP = new p(0, 1);
1549
+ static DOWN = new p(0, -1);
1550
+ static LEFT = new p(-1, 0);
1551
+ static RIGHT = new p(1, 0);
1539
1552
  constructor(t, e) {
1540
- this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
1553
+ this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : this.x;
1541
1554
  }
1542
1555
  set(t, e) {
1543
1556
  return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
1544
1557
  }
1545
1558
  add(t) {
1546
- return new g(this.x + t.x, this.y + t.y);
1559
+ return new p(this.x + t.x, this.y + t.y);
1547
1560
  }
1548
1561
  subtract(t) {
1549
- return new g(this.x - t.x, this.y - t.y);
1562
+ return new p(this.x - t.x, this.y - t.y);
1550
1563
  }
1551
1564
  multiply(t) {
1552
- return t instanceof g ? new g(this.x * t.x, this.y * t.y) : new g(this.x * t, this.y * t);
1565
+ return t instanceof p ? new p(this.x * t.x, this.y * t.y) : new p(this.x * t, this.y * t);
1553
1566
  }
1554
1567
  divide(t) {
1555
- return t instanceof g ? new g(this.x / t.x, this.y / t.y) : new g(this.x / t, this.y / t);
1568
+ return t instanceof p ? new p(this.x / t.x, this.y / t.y) : new p(this.x / t, this.y / t);
1556
1569
  }
1557
1570
  dot(t) {
1558
1571
  return this.x * t.x + this.y * t.y;
@@ -1565,7 +1578,7 @@ class g {
1565
1578
  return Math.sqrt(e * e + r * r);
1566
1579
  }
1567
1580
  clone() {
1568
- return new g(this.x, this.y);
1581
+ return new p(this.x, this.y);
1569
1582
  }
1570
1583
  to(t) {
1571
1584
  this.x = t.x, this.y = t.y;
@@ -1581,7 +1594,7 @@ class g {
1581
1594
  return this.x = -this.x, this.y = -this.y, this;
1582
1595
  }
1583
1596
  inverted() {
1584
- return new g(this.x * -1, this.y * -1);
1597
+ return new p(this.x * -1, this.y * -1);
1585
1598
  }
1586
1599
  length() {
1587
1600
  return Math.sqrt(this.x * this.x + this.y * this.y);
@@ -1595,13 +1608,13 @@ class g {
1595
1608
  }
1596
1609
  normalized() {
1597
1610
  const t = this.length();
1598
- return new g(this.x / t || 0, this.y / t || 0);
1611
+ return new p(this.x / t || 0, this.y / t || 0);
1599
1612
  }
1600
1613
  fix(t = 1e-13) {
1601
1614
  this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
1602
1615
  }
1603
1616
  fixed(t = 1e-13) {
1604
- return new g(
1617
+ return new p(
1605
1618
  Math.abs(this.x) < t ? 0 : this.x,
1606
1619
  Math.abs(this.y) < t ? 0 : this.y
1607
1620
  );
@@ -1610,13 +1623,13 @@ class g {
1610
1623
  return Math.atan2(this.y, this.x);
1611
1624
  }
1612
1625
  abs() {
1613
- return new g(Math.abs(this.x), Math.abs(this.y));
1626
+ return new p(Math.abs(this.x), Math.abs(this.y));
1614
1627
  }
1615
1628
  floor() {
1616
- return new g(Math.floor(this.x), Math.floor(this.y));
1629
+ return new p(Math.floor(this.x), Math.floor(this.y));
1617
1630
  }
1618
1631
  ceil() {
1619
- return new g(Math.ceil(this.x), Math.ceil(this.y));
1632
+ return new p(Math.ceil(this.x), Math.ceil(this.y));
1620
1633
  }
1621
1634
  stringify() {
1622
1635
  return `Vec2(${this.x}, ${this.y})`;
@@ -1637,14 +1650,14 @@ class g {
1637
1650
  return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
1638
1651
  }
1639
1652
  static FromArray(t) {
1640
- return t.map((e) => new g(e[0], e[1]));
1653
+ return t.map((e) => new p(e[0], e[1]));
1641
1654
  }
1642
1655
  static fromAngle(t) {
1643
- return new g(Math.cos(t), Math.sin(t));
1656
+ return new p(Math.cos(t), Math.sin(t));
1644
1657
  }
1645
1658
  }
1646
- const zt = (n, t) => {
1647
- const [e, r, i, s, a, h] = t, o = new Float32Array([
1659
+ const jt = (n, t) => {
1660
+ const [e, r, i, s, a, o] = t, h = new Float32Array([
1648
1661
  e,
1649
1662
  i,
1650
1663
  0,
@@ -1658,12 +1671,12 @@ const zt = (n, t) => {
1658
1671
  1,
1659
1672
  0,
1660
1673
  a,
1661
- h,
1674
+ o,
1662
1675
  0,
1663
1676
  1
1664
1677
  ]);
1665
- return $t(o, n);
1666
- }, $t = (n, t) => {
1678
+ return Kt(h, n);
1679
+ }, Kt = (n, t) => {
1667
1680
  const e = new Float32Array(16);
1668
1681
  for (let r = 0; r < 4; r++)
1669
1682
  for (let i = 0; i < 4; i++) {
@@ -1674,77 +1687,84 @@ const zt = (n, t) => {
1674
1687
  }
1675
1688
  return e;
1676
1689
  };
1677
- var jt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(jt || {});
1678
- const nt = 10, mt = (n, t, e, r, i, s) => {
1679
- 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);
1680
- for (let l = 0; l < nt; l++) {
1681
- 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);
1682
- 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));
1683
- }
1684
- return { vertices: a, uv: h };
1685
- }, Kt = (n, t = !1) => {
1690
+ var qt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(qt || {});
1691
+ const at = 10, xt = (n, t, e, r, i, s) => {
1692
+ const a = [], o = [], h = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new p(t.y, -t.x);
1693
+ for (let l = 0; l < at; l++) {
1694
+ const d = l / at, f = (l + 1) / at, m = h + d * c, x = h + f * c, y = new p(Math.cos(m) * e, Math.sin(m) * e), v = new p(Math.cos(x) * e, Math.sin(x) * e);
1695
+ a.push(n), o.push(new p(i, 0.5)), a.push(n.add(y)), o.push(new p(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e)), a.push(n.add(v)), o.push(new p(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e));
1696
+ }
1697
+ return { vertices: a, uv: o };
1698
+ }, Zt = (n, t = !1) => {
1686
1699
  const e = [];
1687
1700
  if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
1688
1701
  const r = 4, i = 1e-3, s = n.length;
1689
1702
  let a = 0;
1690
1703
  if (t)
1691
- for (let o = 0; o < s; o++) {
1692
- const c = n[o], u = n[(o + 1) % s];
1704
+ for (let h = 0; h < s; h++) {
1705
+ const c = n[h], u = n[(h + 1) % s];
1693
1706
  a += c.distanceTo(u);
1694
1707
  }
1695
1708
  else
1696
- for (let o = 0; o < s - 1; o++)
1697
- a += n[o].distanceTo(n[o + 1]);
1698
- const h = (o, c, u) => {
1699
- const l = c.subtract(o).normalize(), f = c.subtract(u).normalize(), d = f.dot(l);
1700
- if (d < -1 + i)
1709
+ for (let h = 0; h < s - 1; h++)
1710
+ a += n[h].distanceTo(n[h + 1]);
1711
+ const o = (h, c, u) => {
1712
+ const l = c.subtract(h).normalize(), d = c.subtract(u).normalize(), f = d.dot(l);
1713
+ if (f < -1 + i)
1701
1714
  return { normal: l.perpendicular(), miters: 1 };
1702
1715
  {
1703
- let x = f.add(l).normalize();
1704
- l.cross(f) < 0 && (x = x.multiply(-1));
1705
- let p = 1 / Math.sqrt((1 - d) / 2);
1706
- return { normal: x, miters: Math.min(p, r) };
1716
+ let m = d.add(l).normalize();
1717
+ l.cross(d) < 0 && (m = m.multiply(-1));
1718
+ let x = 1 / Math.sqrt((1 - f) / 2);
1719
+ return { normal: m, miters: Math.min(x, r) };
1707
1720
  }
1708
1721
  };
1709
1722
  if (t)
1710
- for (let o = 0; o < s; o++) {
1711
- const c = o === 0 ? n[s - 1] : n[o - 1], u = n[o], l = o === s - 1 ? n[0] : n[o + 1];
1712
- e.push(h(c, u, l));
1723
+ for (let h = 0; h < s; h++) {
1724
+ const c = h === 0 ? n[s - 1] : n[h - 1], u = n[h], l = h === s - 1 ? n[0] : n[h + 1];
1725
+ e.push(o(c, u, l));
1713
1726
  }
1714
1727
  else
1715
- for (let o = 0; o < s; o++)
1716
- if (o === 0) {
1728
+ for (let h = 0; h < s; h++)
1729
+ if (h === 0) {
1717
1730
  const c = n[1].subtract(n[0]).normalize();
1718
1731
  e.push({ normal: c.perpendicular(), miters: 1 });
1719
- } else if (o === s - 1) {
1720
- const c = n[o].subtract(n[o - 1]).normalize();
1732
+ } else if (h === s - 1) {
1733
+ const c = n[h].subtract(n[h - 1]).normalize();
1721
1734
  e.push({ normal: c.perpendicular(), miters: 1 });
1722
1735
  } else
1723
- e.push(h(n[o - 1], n[o], n[o + 1]));
1736
+ e.push(o(n[h - 1], n[h], n[h + 1]));
1724
1737
  return { normals: e, length: a };
1725
- }, qt = (n) => {
1738
+ }, Qt = (n) => {
1726
1739
  const t = n.points;
1727
1740
  if (t.length < 2) return { vertices: [], uv: [] };
1728
- const { normals: e, length: r } = Kt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], h = n.roundCap || !1, o = n.textureMode || 0;
1741
+ const { normals: e, length: r } = Zt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], o = n.roundCap || !1, h = n.textureMode || 0;
1729
1742
  let c = 0;
1730
1743
  const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
1731
- for (let f = 0; f < l; f++) {
1732
- 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);
1733
- let R = 0, w = 0;
1734
- o === 0 ? (R = c / r, w = (c + C) / r) : (R = c / u, w = R + C / u);
1735
- const O = new g(R, 0), B = new g(R, 1), G = new g(w, 0), L = new g(w, 1);
1736
- s.push(_), a.push(O), 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;
1737
- }
1738
- if (h && !n.closed) {
1739
- 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);
1740
- s.push(...p.vertices), a.push(...p.uv);
1741
- 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);
1742
- s.push(..._.vertices), a.push(..._.uv);
1744
+ for (let d = 0; d < l; d++) {
1745
+ const f = t[d], m = e[d].normal, x = e[d].miters, y = (d + 1) % t.length, v = t[y], T = e[y].normal, w = e[y].miters, U = f.add(m.multiply(x * i)), P = f.subtract(m.multiply(x * i)), O = v.add(T.multiply(w * i)), L = v.subtract(T.multiply(w * i)), S = f.distanceTo(v);
1746
+ let E = 0, b = 0;
1747
+ h === 0 ? (E = c / r, b = (c + S) / r) : (E = c / u, b = E + S / u);
1748
+ const I = new p(E, 0), k = new p(E, 1), G = new p(b, 0), N = new p(b, 1);
1749
+ s.push(U), a.push(I), s.push(P), a.push(k), s.push(O), a.push(G), s.push(O), a.push(G), s.push(L), a.push(N), s.push(P), a.push(k), c += S;
1750
+ }
1751
+ if (o && !n.closed) {
1752
+ const d = t[0], f = e[0].normal, m = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, x = xt(d, f, i, !0, 0, m);
1753
+ s.push(...x.vertices), a.push(...x.uv);
1754
+ const y = t[t.length - 1], v = e[t.length - 1].normal, T = h === 0 ? 1 : c / u, w = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, U = xt(y, v, i, !1, T, w);
1755
+ s.push(...U.vertices), a.push(...U.uv);
1743
1756
  }
1744
1757
  return { vertices: s, uv: a };
1745
- }, Z = (n, t, e, r) => {
1758
+ }, tt = (n, t, e, r) => {
1759
+ const i = n.matrix.temporary;
1746
1760
  if (t.customMatrix !== void 0)
1747
- return t.customMatrix;
1761
+ return n.matrixStack.applyTransform(
1762
+ t,
1763
+ e,
1764
+ r,
1765
+ i,
1766
+ t.customMatrix
1767
+ ), i;
1748
1768
  if (t.modifyStack) {
1749
1769
  n.matrixStack.applyTransform(
1750
1770
  t,
@@ -1752,41 +1772,40 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1752
1772
  r
1753
1773
  );
1754
1774
  return;
1755
- } else {
1756
- const i = n.matrix.temporary;
1775
+ } else
1757
1776
  return n.matrixStack.applyTransform(
1758
1777
  t,
1759
1778
  e,
1760
1779
  r,
1761
- i
1780
+ i,
1781
+ n.matrixStack.curWorldM
1762
1782
  ), i;
1763
- }
1764
- }, Qt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, Zt = 2, Jt = (n, t) => {
1765
- const e = Z(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
1783
+ }, Jt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, te = 2, ee = (n, t) => {
1784
+ const e = tt(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
1766
1785
  if (!r?.base || n.inCreateMask)
1767
1786
  return;
1768
1787
  const i = r.isAtlas ? n.atlasSpriteRegion : n.spriteRegion;
1769
1788
  n.enterRegion(i, t.shader);
1770
- let s = r.uvX, a = r.uvY, h = r.uvW, o = r.uvH;
1789
+ let s = r.uvX, a = r.uvY, o = r.uvW, h = r.uvH;
1771
1790
  const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
1772
1791
  let l = t.padding ?? i.currentShader.padding;
1773
- r.isAtlas && (l += Zt);
1774
- const f = s <= h ? l : -l, d = a <= o ? l : -l;
1792
+ r.isAtlas && (l += te);
1793
+ const d = s <= o ? l : -l, f = a <= h ? l : -l;
1775
1794
  i.drawSprite(
1776
1795
  r,
1777
1796
  e ?? t.customMatrix ?? n.matrixStack.curWorldM,
1778
1797
  s,
1779
1798
  a,
1780
- h,
1781
1799
  o,
1800
+ h,
1782
1801
  n.getColorUint32(t.color),
1783
- f,
1784
1802
  d,
1803
+ f,
1785
1804
  c,
1786
1805
  u,
1787
1806
  r.isRotated
1788
1807
  );
1789
- }, te = (n, t) => {
1808
+ }, re = (n, t) => {
1790
1809
  const e = n.particleRegion;
1791
1810
  n.enterRegion(e, t.shader);
1792
1811
  const r = t.texture, i = t.count ?? t.x.length, s = t.color;
@@ -1814,7 +1833,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1814
1833
  );
1815
1834
  }, Mt = (n, t) => {
1816
1835
  if (t.points.length === 0) return;
1817
- const e = Z(n, t, 0, 0);
1836
+ const e = tt(n, t, 0, 0);
1818
1837
  n.startGraphic(
1819
1838
  t.drawMode ?? n.gl.TRIANGLES,
1820
1839
  t.texture,
@@ -1832,18 +1851,18 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1832
1851
  );
1833
1852
  }
1834
1853
  n.endGraphic();
1835
- }, ee = (n, t) => {
1854
+ }, ie = (n, t) => {
1836
1855
  if (n.inCreateMask)
1837
1856
  return;
1838
- const { vertices: e, uv: r } = qt(t);
1857
+ const { vertices: e, uv: r } = Qt(t);
1839
1858
  Mt(n, {
1840
1859
  ...t,
1841
1860
  points: e,
1842
1861
  uv: r,
1843
1862
  drawMode: n.gl.TRIANGLES
1844
1863
  });
1845
- }, re = (n, t) => {
1846
- const e = Z(
1864
+ }, se = (n, t) => {
1865
+ const e = tt(
1847
1866
  n,
1848
1867
  t,
1849
1868
  t.texture.rawWidth,
@@ -1854,16 +1873,16 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1854
1873
  t.texture,
1855
1874
  e ?? t.customMatrix
1856
1875
  ), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
1857
- }, ie = (n, t) => {
1858
- const e = Z(n, t, t.width, t.height);
1876
+ }, ne = (n, t) => {
1877
+ const e = tt(n, t, t.width, t.height);
1859
1878
  n.startGraphic(
1860
1879
  n.gl.TRIANGLE_FAN,
1861
1880
  t.texture,
1862
1881
  t.shader,
1863
1882
  e ?? t.customMatrix
1864
1883
  ), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
1865
- }, se = (n, t) => {
1866
- const e = t.segments ?? 32, r = Z(n, t, 0, 0);
1884
+ }, ae = (n, t) => {
1885
+ const e = t.segments ?? 32, r = tt(n, t, 0, 0);
1867
1886
  n.startGraphic(
1868
1887
  n.gl.TRIANGLE_FAN,
1869
1888
  void 0,
@@ -1872,7 +1891,7 @@ const nt = 10, mt = (n, t, e, r, i, s) => {
1872
1891
  );
1873
1892
  const i = n.getColorUint32(t.color);
1874
1893
  n.addGraphicVertex(0, 0, 0.5, 0.5, i), n.addCircleVertex(t.radius, t.color, e), n.addGraphicVertex(t.radius, 0, 1, 0.5, i), n.endGraphic();
1875
- }, xt = `#version 300 es\r
1894
+ }, pt = `#version 300 es\r
1876
1895
  precision mediump float;\r
1877
1896
  \r
1878
1897
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -1916,16 +1935,16 @@ void main(void) {\r
1916
1935
  // CUSTOM_CODE_CALL\r
1917
1936
  }\r
1918
1937
  `;
1919
- class ne extends lt {
1938
+ class oe extends dt {
1920
1939
  KEY = "AtlasSprite";
1921
1940
  constructor(t) {
1922
1941
  super(t);
1923
1942
  }
1924
1943
  createDefaultShader() {
1925
- return this.vs = et, this.fs = xt, this.defaultShader = this.createShader(et, xt), this.defaultShader;
1944
+ return this.vs = st, this.fs = pt, this.defaultShader = this.createShader(st, pt), this.defaultShader;
1926
1945
  }
1927
1946
  }
1928
- const ae = `#version 300 es\r
1947
+ const he = `#version 300 es\r
1929
1948
  precision highp float;\r
1930
1949
  \r
1931
1950
  // per-vertex\r
@@ -1942,7 +1961,8 @@ in vec4 aUVRect;\r
1942
1961
  \r
1943
1962
  // per-instance:tint color\r
1944
1963
  in vec4 aColor;\r
1945
- uniform mat4 u_projection;\r
1964
+ // Projection and scene transform are combined once per particle batch on the CPU.
1965
+ uniform mat4 u_matrix;
1946
1966
  \r
1947
1967
  out vec2 vRegion;\r
1948
1968
  out vec4 vColor;\r
@@ -1960,9 +1980,9 @@ void main(void) {\r
1960
1980
  vec4 position = vec4(mat2(c, s, -s, c) * scaled + aPosition, 0.0, 1.0);\r
1961
1981
  // CUSTOM_CODE_CALL\r
1962
1982
  \r
1963
- gl_Position = u_projection * position;\r
1983
+ gl_Position = u_matrix * position;
1964
1984
  }\r
1965
- `, he = `#version 300 es\r
1985
+ `, ce = `#version 300 es\r
1966
1986
  precision mediump float;\r
1967
1987
  \r
1968
1988
  uniform sampler2D uTexture;\r
@@ -1979,8 +1999,8 @@ void main(void) {\r
1979
1999
  \r
1980
2000
  // CUSTOM_CODE_CALL\r
1981
2001
  }\r
1982
- `, V = 48, oe = V / 4;
1983
- class ce extends lt {
2002
+ `, Y = 48, ue = Y / 4;
2003
+ class le extends dt {
1984
2004
  KEY = "ParticleSprite";
1985
2005
  texture;
1986
2006
  customMatrix;
@@ -1990,77 +2010,77 @@ class ce extends lt {
1990
2010
  super(t);
1991
2011
  }
1992
2012
  createDefaultShader() {
1993
- const t = he, e = ae;
2013
+ const t = ce, e = he;
1994
2014
  return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
1995
2015
  }
1996
2016
  enter(t) {
1997
- super.enter(t), this.currentShader.setUniform("u_projection", this.rapid.projection);
2017
+ super.enter(t), this.currentShader.setUniform("u_matrix", this.rapid.projection);
1998
2018
  }
1999
2019
  createShader(t, e) {
2000
2020
  const r = super.createShader(t, e);
2001
2021
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
2002
- { name: "aPosition", size: 2, stride: V, offset: 0, divisor: 1 },
2003
- { name: "aScale", size: 2, stride: V, offset: 8, divisor: 1 },
2004
- { name: "aRotation", size: 1, stride: V, offset: 16, divisor: 1 },
2005
- { name: "aUVRect", size: 4, stride: V, offset: 20, divisor: 1 },
2006
- { name: "aColor", size: 4, type: ot, normalized: !0, stride: V, offset: 36, divisor: 1 },
2007
- { name: "aOrigin", size: 2, stride: V, offset: 40, divisor: 1 }
2022
+ { name: "aPosition", size: 2, stride: Y, offset: 0, divisor: 1 },
2023
+ { name: "aScale", size: 2, stride: Y, offset: 8, divisor: 1 },
2024
+ { name: "aRotation", size: 1, stride: Y, offset: 16, divisor: 1 },
2025
+ { name: "aUVRect", size: 4, stride: Y, offset: 20, divisor: 1 },
2026
+ { name: "aColor", size: 4, type: ct, normalized: !0, stride: Y, offset: 36, divisor: 1 },
2027
+ { name: "aOrigin", size: 2, stride: Y, offset: 40, divisor: 1 }
2008
2028
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
2009
2029
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2010
2030
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2011
2031
  }
2012
- 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, _) {
2032
+ drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1, x = !1, y = 0.5, v = 0.5, T, w = !1, U) {
2013
2033
  if (!t.glTexture || a <= 0) return;
2014
2034
  this.texture && t !== this.texture && this.flush();
2015
- 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", O = t.uvW - t.uvX, B = t.uvH - t.uvY, G = O === 0 ? 0 : 1 / O, L = B === 0 ? 0 : 1 / B;
2016
- let W = t.rawWidth * (d ? -1 : 1);
2017
- P && (W *= h);
2018
- let D = t.rawHeight * (x ? -1 : 1);
2019
- k && (D *= o), R && (W *= (l - c) * G, D *= (f - u) * L);
2020
- let H = p ? Math.PI / 2 : 0;
2021
- I && (H += i);
2022
- const M = s ?? 4294967295, U = this.getParticleLoop(
2035
+ const P = typeof o == "number", O = typeof h == "number", L = typeof i == "number", S = typeof s == "number", E = typeof c == "number", b = !S && typeof s[0] == "number", I = t.uvW - t.uvX, k = t.uvH - t.uvY, G = I === 0 ? 0 : 1 / I, N = k === 0 ? 0 : 1 / k;
2036
+ let F = t.rawWidth * (f ? -1 : 1);
2037
+ P && (F *= o);
2038
+ let V = t.rawHeight * (m ? -1 : 1);
2039
+ O && (V *= h), E && (F *= (l - c) * G, V *= (d - u) * N);
2040
+ let H = x ? Math.PI / 2 : 0;
2041
+ L && (H += i);
2042
+ const R = s ?? 4294967295, A = this.getParticleLoop(
2023
2043
  P,
2024
- k,
2025
- I,
2026
- R,
2027
- C,
2028
- w,
2044
+ O,
2045
+ L,
2046
+ E,
2029
2047
  S,
2030
- E
2048
+ b,
2049
+ w,
2050
+ T
2031
2051
  );
2032
2052
  this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2033
- const it = a, Y = this.instanceBuffer;
2034
- let st = Y.usedElemNum;
2035
- Y.resize(it * oe);
2036
- const At = Y.float32, St = Y.uint32;
2037
- st = U(
2053
+ const $ = a, B = this.instanceBuffer;
2054
+ let X = B.usedElemNum;
2055
+ B.resize($ * ue);
2056
+ const bt = B.float32, Ut = B.uint32;
2057
+ X = A(
2038
2058
  e,
2039
2059
  r,
2040
- h,
2041
2060
  o,
2061
+ h,
2042
2062
  i,
2043
2063
  c,
2044
2064
  u,
2045
2065
  l,
2046
- f,
2066
+ d,
2047
2067
  s,
2048
- At,
2049
- St,
2050
- W,
2051
- D,
2068
+ bt,
2069
+ Ut,
2070
+ F,
2071
+ V,
2052
2072
  G,
2053
- L,
2073
+ N,
2054
2074
  H,
2055
- M,
2056
- y,
2057
- v,
2075
+ R,
2076
+ 1 - y,
2077
+ 1 - v,
2058
2078
  a,
2059
- it,
2060
- st
2061
- ), Y.usedElemNum = st, Y.makeDirty(), this.instanceCount += it, this.customMatrix = _, this.flush();
2079
+ $,
2080
+ X
2081
+ ), B.usedElemNum = X, B.makeDirty(), this.instanceCount += $, this.customMatrix = U, this.flush();
2062
2082
  }
2063
- getParticleLoop(t, e, r, i, s, a, h, o) {
2083
+ getParticleLoop(t, e, r, i, s, a, o, h) {
2064
2084
  const c = [...arguments].join("_");
2065
2085
  if (this.particleLoopCache.has(c))
2066
2086
  return this.particleLoopCache.get(c);
@@ -2073,7 +2093,7 @@ const endIdx = index + batchCount * 12;
2073
2093
  let idx = index;
2074
2094
  if (endIdx > f32.length) return index;
2075
2095
 
2076
- ${h ? "for (let src = count - 1; idx < endIdx; src--, idx += 12) {" : "for (let src = 0; idx < endIdx; src++, idx += 12) {"}
2096
+ ${o ? "for (let src = count - 1; idx < endIdx; src--, idx += 12) {" : "for (let src = 0; idx < endIdx; src++, idx += 12) {"}
2077
2097
  f32[idx] = x[src];
2078
2098
  f32[idx + 1] = y[src];
2079
2099
 
@@ -2096,7 +2116,7 @@ f32[idx + 7] = cu1;
2096
2116
  f32[idx + 8] = cv1;
2097
2117
  `}
2098
2118
 
2099
- u32[idx + 9] = ${s ? "staticColor" : a ? "color[src]" : `color[src].${o ? "premultipliedUint32" : "uint32"}`};
2119
+ u32[idx + 9] = ${s ? "staticColor" : a ? "color[src]" : `color[src].${h ? "premultipliedUint32" : "uint32"}`};
2100
2120
 
2101
2121
  f32[idx + 10] = originX;
2102
2122
  f32[idx + 11] = originY;
@@ -2114,30 +2134,171 @@ return idx;
2114
2134
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2115
2135
  const e = this.currentShader;
2116
2136
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2117
- const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = zt(this.rapid.projection, s);
2118
- 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;
2137
+ const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = jt(this.rapid.projection, s);
2138
+ this.currentShader.setUniform("u_matrix", a), wt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2139
+ }
2140
+ }
2141
+ var de = /* @__PURE__ */ ((n) => (n[n.KEEP_W = 0] = "KEEP_W", n[n.KEEP_H = 1] = "KEEP_H", n[n.KEEP = 2] = "KEEP", n[n.IGNORE = 3] = "IGNORE", n[n.EXPAND = 4] = "EXPAND", n[n.NONE = 5] = "NONE", n))(de || {});
2142
+ const fe = {
2143
+ 4: new p(1, 1),
2144
+ 0: new p(0, 1),
2145
+ 1: new p(1, 0),
2146
+ 2: new p(0, 0)
2147
+ }, gt = {
2148
+ 4: new p(0.5, 0.5),
2149
+ 0: new p(0.5, 0),
2150
+ 1: new p(0, 0.5),
2151
+ 2: new p(0.5, 0.5)
2152
+ };
2153
+ class me {
2154
+ constructor(t, e) {
2155
+ this.rapid = t, this.updateWindowOption(e);
2156
+ }
2157
+ viewLeft = 0;
2158
+ viewRight = 0;
2159
+ viewTop = 0;
2160
+ viewBottom = 0;
2161
+ window = {};
2162
+ scissorViewport = null;
2163
+ resolution = 0;
2164
+ updateWindowOption(t) {
2165
+ Object.assign(this.window, t);
2166
+ }
2167
+ resize(t, e, r, i) {
2168
+ const s = this.rapid, a = this.window, o = a.scale ?? 1;
2169
+ t /= o, e /= o, s.flush();
2170
+ const h = r ?? s.canvas.clientWidth ?? s.canvas.width, c = i ?? s.canvas.clientHeight ?? s.canvas.height;
2171
+ r !== void 0 && (s.canvas.style.width = h + "px"), i !== void 0 && (s.canvas.style.height = c + "px"), s.physicsWidth = h * s.dpr, s.physicsHeight = c * s.dpr, s.logicWidth = t, s.logicHeight = e;
2172
+ let u = 0, l = t, d = e, f = 0;
2173
+ const m = a.scaleMode ?? Q.CanvasItem, x = a.expand ?? 2;
2174
+ let y = p.ZERO, v = p.ZERO;
2175
+ switch (x in gt && (y = a.expandPosition ?? gt[x], v = fe[x]), this.scissorViewport = null, x) {
2176
+ case 3: {
2177
+ u = 0, l = t, d = e, f = 0;
2178
+ break;
2179
+ }
2180
+ case 5: {
2181
+ u = 0, l = s.physicsWidth, d = s.physicsHeight, f = 0;
2182
+ break;
2183
+ }
2184
+ default:
2185
+ case 4:
2186
+ case 0:
2187
+ case 1:
2188
+ case 2: {
2189
+ const T = y, w = v, U = Math.min(
2190
+ s.physicsWidth / t,
2191
+ s.physicsHeight / e
2192
+ ), P = s.physicsWidth / U, O = s.physicsHeight / U, L = P - t, S = O - e;
2193
+ if (u = -L * T.x, l = t + L * (1 - T.x), f = -S * T.y, d = e + S * (1 - T.y), !w.x && L > 0 || !w.y && S > 0) {
2194
+ const E = w.x && L > 0 ? u : 0, b = w.x && L > 0 ? l : t, I = w.y && S > 0 ? f : 0, k = w.y && S > 0 ? d : e;
2195
+ this.scissorViewport = {
2196
+ x: E,
2197
+ y: I,
2198
+ width: b - E,
2199
+ height: k - I
2200
+ };
2201
+ }
2202
+ break;
2203
+ }
2204
+ }
2205
+ switch (m) {
2206
+ case Q.Viewport:
2207
+ s.canvas.width = t, s.canvas.height = e, s.canvas.style.imageRendering = "pixelated", s.gl.viewport(0, 0, t, e);
2208
+ break;
2209
+ default:
2210
+ case Q.CanvasItem:
2211
+ s.canvas.width = s.physicsWidth, s.canvas.height = s.physicsHeight, s.canvas.style.imageRendering = "auto", s.gl.viewport(
2212
+ 0,
2213
+ 0,
2214
+ s.physicsWidth,
2215
+ s.physicsHeight
2216
+ );
2217
+ break;
2218
+ }
2219
+ this.viewLeft = u, this.viewRight = l, this.viewTop = f, this.viewBottom = d, this.updateProjection(), this.restoreViewportScissor(), this.updateResolution(m);
2220
+ }
2221
+ updateResolution(t) {
2222
+ let e = 1;
2223
+ const r = this.rapid.texture;
2224
+ if (t !== Q.Viewport) {
2225
+ const i = this.viewRight - this.viewLeft, s = this.viewBottom - this.viewTop;
2226
+ e = Math.max(
2227
+ this.rapid.physicsWidth / i,
2228
+ this.rapid.physicsHeight / s
2229
+ );
2230
+ }
2231
+ e != this.resolution && (this.resolution = e, r.texture.forEach((i) => i.updateResolution()));
2232
+ }
2233
+ updateProjection() {
2234
+ this.rapid.updateProjection(
2235
+ this.viewLeft,
2236
+ this.viewRight,
2237
+ this.viewBottom,
2238
+ this.viewTop
2239
+ );
2240
+ }
2241
+ updateOrthMatrix(t, e, r, i, s) {
2242
+ 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;
2243
+ }
2244
+ applyCamera(t) {
2245
+ const e = this.rapid, r = e.matrix, i = e.matrixStack, s = this.scissorViewport && e.gl.getParameter(e.gl.FRAMEBUFFER_BINDING) === null ? this.scissorViewport : null, a = s?.width ?? this.viewRight - this.viewLeft, o = s?.height ?? this.viewBottom - this.viewTop, h = s ? s.x + a / 2 : (this.viewLeft + this.viewRight) / 2, c = s ? s.y + o / 2 : (this.viewTop + this.viewBottom) / 2, u = i.curWorldM, l = r.temporary, d = r.applyTransform(t, 0, 0);
2246
+ r.setMatrix(l, d), r.clampBounds(
2247
+ l,
2248
+ a,
2249
+ o,
2250
+ t.limitLeft,
2251
+ t.limitRight,
2252
+ t.limitTop,
2253
+ t.limitBottom
2254
+ ), i.translate(h, c), r.invert(l), r.multiplyOut(u, u, l);
2255
+ }
2256
+ startScissor(t, e, r, i) {
2257
+ const s = this.rapid;
2258
+ s.flush();
2259
+ const a = s.gl, o = this.scissorViewport;
2260
+ if (o && a.getParameter(a.FRAMEBUFFER_BINDING) === null) {
2261
+ const P = Math.max(Math.min(t, t + r), o.x), O = Math.min(Math.max(t, t + r), o.x + o.width), L = Math.max(Math.min(e, e + i), o.y), S = Math.min(
2262
+ Math.max(e, e + i),
2263
+ o.y + o.height
2264
+ );
2265
+ t = P, e = L, r = Math.max(0, O - P), i = Math.max(0, S - L);
2266
+ }
2267
+ const [h, c, u, l] = a.getParameter(
2268
+ a.VIEWPORT
2269
+ ), d = s.projection, f = h + (d[0] * t + d[12] + 1) * u / 2, m = h + (d[0] * (t + r) + d[12] + 1) * u / 2, x = c + (d[5] * e + d[13] + 1) * l / 2, y = c + (d[5] * (e + i) + d[13] + 1) * l / 2, v = Math.round(Math.min(f, m)), T = Math.round(Math.max(f, m)), w = Math.round(Math.min(x, y)), U = Math.round(Math.max(x, y));
2270
+ a.enable(a.SCISSOR_TEST), a.scissor(v, w, T - v, U - w);
2271
+ }
2272
+ restoreViewportScissor() {
2273
+ this.rapid.flush();
2274
+ const t = this.rapid.gl, e = this.scissorViewport;
2275
+ e && t.getParameter(t.FRAMEBUFFER_BINDING) === null ? this.startScissor(e.x, e.y, e.width, e.height) : t.disable(t.SCISSOR_TEST);
2276
+ }
2277
+ endScissor() {
2278
+ this.restoreViewportScissor();
2119
2279
  }
2120
2280
  }
2121
- 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 || {});
2122
- class pe {
2281
+ var St = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(St || {}), xe = /* @__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))(xe || {}), Q = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(Q || {});
2282
+ class we {
2123
2283
  gl;
2124
2284
  canvas;
2125
2285
  projection = new Float32Array(16);
2126
2286
  projectionDirty = !0;
2127
2287
  dpr;
2128
- backgroundColor = m.Black;
2288
+ backgroundColor = g.Black;
2129
2289
  logicWidth = 0;
2130
2290
  logicHeight = 0;
2131
2291
  physicsWidth = 0;
2132
2292
  physicsHeight = 0;
2133
2293
  currentRegion = null;
2134
2294
  maxTextureUnits = 0;
2135
- matrixStack = new kt(this);
2295
+ matrixStack = new Ht(this);
2136
2296
  matrix;
2137
2297
  spriteRegion;
2138
2298
  graphicRegion;
2139
2299
  atlasSpriteRegion;
2140
2300
  particleRegion;
2301
+ regions;
2141
2302
  drawcallCount = 0;
2142
2303
  inCreateMask = !1;
2143
2304
  texture;
@@ -2145,9 +2306,9 @@ class pe {
2145
2306
  antialias;
2146
2307
  roundPixels;
2147
2308
  textureFilter;
2148
- scaleMode;
2309
+ viewport;
2149
2310
  _filterRT = [null, null];
2150
- _filterInput = new F();
2311
+ _filterInput = new W();
2151
2312
  get height() {
2152
2313
  return this.logicHeight;
2153
2314
  }
@@ -2155,38 +2316,41 @@ class pe {
2155
2316
  return this.logicWidth;
2156
2317
  }
2157
2318
  constructor(t) {
2158
- this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? Q.NEAREST, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
2159
- const e = Lt(this.canvas, this.antialias, this.premultipliedAlpha);
2160
- 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);
2161
- const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
2162
- 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);
2319
+ this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? it.NEAREST, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1;
2320
+ const e = Nt(this.canvas, this.antialias, this.premultipliedAlpha);
2321
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new dt(this), this.graphicRegion = new $t(this), this.atlasSpriteRegion = new oe(this), this.particleRegion = new le(this), this.viewport = new me(this, t.window), this.texture = new Ct(this), this.regions = [
2322
+ this.spriteRegion,
2323
+ this.atlasSpriteRegion
2324
+ ];
2325
+ const r = this.canvas.clientWidth ?? this.canvas.width, i = this.canvas.clientHeight ?? this.canvas.height;
2326
+ this.physicsWidth = t.physicsWidth ?? Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight ?? Math.round(i * this.dpr), this.logicWidth = t.width ?? this.physicsWidth / this.dpr, this.logicHeight = t.height ?? this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), 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);
2163
2327
  }
2164
2328
  setTextureFilter(t) {
2165
2329
  this.textureFilter = t;
2166
2330
  }
2167
2331
  getColorUint32(t) {
2168
- return Qt(this.premultipliedAlpha, t);
2332
+ return Jt(this.premultipliedAlpha, t);
2169
2333
  }
2170
2334
  enterRegion(t, e) {
2171
2335
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2172
2336
  }
2173
2337
  drawParticles(t) {
2174
- te(this, t);
2338
+ re(this, t);
2175
2339
  }
2176
2340
  drawSprite(t) {
2177
- Jt(this, t);
2341
+ ee(this, t);
2178
2342
  }
2179
2343
  drawLine(t) {
2180
- ee(this, t);
2344
+ ie(this, t);
2181
2345
  }
2182
2346
  drawGraphic(t) {
2183
2347
  Mt(this, t);
2184
2348
  }
2185
2349
  drawRect(t) {
2186
- ie(this, t);
2350
+ ne(this, t);
2187
2351
  }
2188
2352
  drawCircle(t) {
2189
- se(this, t);
2353
+ ae(this, t);
2190
2354
  }
2191
2355
  startGraphic(t = this.gl.TRIANGLES, e, r, i) {
2192
2356
  this.enterRegion(this.graphicRegion, r), this.graphicRegion.startGraphic(i ?? this.matrixStack.curWorldM, t, e);
@@ -2195,7 +2359,7 @@ class pe {
2195
2359
  this.startGraphic(t, e, this.graphicRegion.maskShader, r);
2196
2360
  }
2197
2361
  drawMaskImage(t) {
2198
- re(this, t);
2362
+ se(this, t);
2199
2363
  }
2200
2364
  addRectVertex(t, e, r) {
2201
2365
  const i = this.getColorUint32(r);
@@ -2204,8 +2368,8 @@ class pe {
2204
2368
  addCircleVertex(t, e, r = 32) {
2205
2369
  const i = Math.PI * 2 / r, s = this.getColorUint32(e);
2206
2370
  for (let a = 0; a < r; a++) {
2207
- const h = i * a, o = Math.cos(h) * t, c = Math.sin(h) * t, u = 0.5 + Math.cos(h) * 0.5, l = 0.5 + Math.sin(h) * 0.5;
2208
- this.addGraphicVertex(o, c, u, l, s);
2371
+ const o = i * a, h = Math.cos(o) * t, c = Math.sin(o) * t, u = 0.5 + Math.cos(o) * 0.5, l = 0.5 + Math.sin(o) * 0.5;
2372
+ this.addGraphicVertex(h, c, u, l, s);
2209
2373
  }
2210
2374
  }
2211
2375
  addGraphicVertex(t, e, r = 0, i = 0, s = 4294967295) {
@@ -2215,29 +2379,14 @@ class pe {
2215
2379
  this.graphicRegion.endGraphic();
2216
2380
  }
2217
2381
  resize(t, e, r, i) {
2218
- this.flush();
2219
- const s = r ?? this.canvas.clientWidth ?? this.canvas.width, a = i ?? this.canvas.clientHeight ?? this.canvas.height;
2220
- 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) {
2221
- case 1:
2222
- this.canvas.width = t, this.canvas.height = e, this.canvas.style.imageRendering = "pixelated", this.gl.viewport(0, 0, t, e);
2223
- break;
2224
- case 0:
2225
- this.canvas.width = this.physicsWidth, this.canvas.height = this.physicsHeight, this.canvas.style.imageRendering = "auto", this.gl.viewport(0, 0, this.physicsWidth, this.physicsHeight);
2226
- break;
2227
- default:
2228
- throw new Error("scaleMode can only be CanvasScaleMode.Viewport or CanvasScaleMode.CanvasItem");
2229
- }
2230
- this.updateProjection(0, this.logicWidth, this.logicHeight, 0);
2382
+ this.viewport.resize(t, e, r, i);
2231
2383
  }
2232
2384
  updateProjection(t, e, r, i) {
2233
- this.updateOrthMatrix(this.projection, t, e, r, i), this.projectionDirty = !0;
2385
+ this.viewport.updateOrthMatrix(this.projection, t, e, r, i), this.projectionDirty = !0;
2234
2386
  }
2235
2387
  clear() {
2236
2388
  const t = this.gl;
2237
- this.backgroundColor.setClearColor(t), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT), this.drawcallCount = 0, this.matrixStack.reset();
2238
- }
2239
- updateOrthMatrix(t, e, r, i, s) {
2240
- 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;
2389
+ this.flush(), t.disable(t.SCISSOR_TEST), this.viewport.scissorViewport && t.getParameter(t.FRAMEBUFFER_BINDING) === null ? (t.clearColor(0, 0, 0, 1), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT), this.backgroundColor.setClearColor(t, this.premultipliedAlpha), this.viewport.restoreViewportScissor(), t.clear(t.COLOR_BUFFER_BIT)) : (this.backgroundColor.setClearColor(t, this.premultipliedAlpha), t.clear(t.COLOR_BUFFER_BIT | t.STENCIL_BUFFER_BIT)), this.drawcallCount = 0, this.matrixStack.reset();
2241
2390
  }
2242
2391
  flush() {
2243
2392
  this.currentRegion && (this.currentRegion.exit(), this.currentRegion = null);
@@ -2248,33 +2397,33 @@ class pe {
2248
2397
  const r = Math.max(...e.map((c) => c.padding)), i = r, s = t.rawWidth + r * 2, a = t.rawHeight + r * 2;
2249
2398
  for (let c = 0; c < 2; c++)
2250
2399
  this._filterRT[c] ? this._filterRT[c].resize(s, a) : this._filterRT[c] = this.texture.createRenderTexture({ width: s, height: a });
2251
- let h = t.clone(this._filterInput), o = 0;
2400
+ let o = t.clone(this._filterInput), h = 0;
2252
2401
  this.matrixStack.save(), this.matrixStack.identity();
2253
2402
  for (let c = 0; c < e.length; c++) {
2254
- const u = this._filterRT[o % 2];
2403
+ const u = this._filterRT[h % 2];
2255
2404
  u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
2256
- texture: h,
2405
+ texture: o,
2257
2406
  shader: e[c],
2258
2407
  offsetX: c == 0 ? i : 0,
2259
2408
  // padding back
2260
2409
  offsetY: c == 0 ? i : 0,
2261
2410
  padding: r
2262
- }), this.leaveRenderTexture(), h = u, o++;
2411
+ }), this.leaveRenderTexture(), o = u, h++;
2263
2412
  }
2264
- return this.matrixStack.restore(), h.offsetX = -i, h.offsetY = -i, h;
2413
+ return this.matrixStack.restore(), o.offsetX = -i, o.offsetY = -i, o;
2265
2414
  }
2266
2415
  enterRenderTexture(t) {
2267
- this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, 0, t.rawHeight);
2416
+ this.flush(), t.activate(), this.viewport.restoreViewportScissor(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, 0, t.rawHeight);
2268
2417
  }
2269
- clearRenderTexture(t = new m(0, 0, 0, 0)) {
2418
+ clearRenderTexture(t = new g(0, 0, 0, 0)) {
2270
2419
  this.flush();
2271
2420
  const e = this.gl;
2272
- t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
2421
+ t.setClearColor(e, this.premultipliedAlpha), e.clear(e.COLOR_BUFFER_BIT);
2273
2422
  }
2274
2423
  leaveRenderTexture() {
2275
- 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);
2424
+ this.flush(), this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null), this.gl.viewport(0, 0, this.canvas.width, this.canvas.height), this.viewport.updateProjection(), this.viewport.restoreViewportScissor();
2276
2425
  }
2277
- drawToRenderTexture(t, e, r = new m(0, 0, 0, 0)) {
2426
+ drawToRenderTexture(t, e, r = new g(0, 0, 0, 0)) {
2278
2427
  this.enterRenderTexture(t);
2279
2428
  try {
2280
2429
  r !== null && this.clearRenderTexture(r), e();
@@ -2370,26 +2519,22 @@ class pe {
2370
2519
  }
2371
2520
  }
2372
2521
  startScissor(t, e, r, i) {
2373
- this.flush();
2374
- 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);
2375
- s.enable(s.SCISSOR_TEST), s.scissor(o, c, u, l);
2522
+ this.viewport.startScissor(t, e, r, i);
2376
2523
  }
2377
2524
  endScissor() {
2378
- this.flush(), this.gl.disable(this.gl.SCISSOR_TEST);
2525
+ this.viewport.endScissor();
2379
2526
  }
2380
2527
  applyCamera(t) {
2381
- this.matrixStack.applyTransform(t);
2382
- const e = this.matrixStack.curWorldM;
2383
- this.matrix.invert(e);
2528
+ this.viewport.applyCamera(t);
2384
2529
  }
2385
2530
  logicToPhysics(t) {
2386
- return t.multiply(new g(
2531
+ return t.multiply(new p(
2387
2532
  this.physicsWidth / this.logicWidth,
2388
2533
  this.physicsHeight / this.logicHeight
2389
2534
  ));
2390
2535
  }
2391
2536
  physicsToLogic(t) {
2392
- return t.multiply(new g(
2537
+ return t.multiply(new p(
2393
2538
  this.logicWidth / this.physicsWidth,
2394
2539
  this.logicHeight / this.physicsHeight
2395
2540
  ));
@@ -2409,10 +2554,10 @@ class pe {
2409
2554
  return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
2410
2555
  }
2411
2556
  }
2412
- function de(n) {
2413
- return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof g || n instanceof m);
2557
+ function pe(n) {
2558
+ return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof g);
2414
2559
  }
2415
- class N {
2560
+ class D {
2416
2561
  static float(t, e) {
2417
2562
  return Math.random() * (e - t) + t;
2418
2563
  }
@@ -2423,18 +2568,18 @@ class N {
2423
2568
  return Math.random() * Math.PI * 2;
2424
2569
  }
2425
2570
  static vector(t, e, r, i) {
2426
- return new g(N.float(t, e), N.float(r, i));
2571
+ return new p(D.float(t, e), D.float(r, i));
2427
2572
  }
2428
2573
  static randomColor(t, e) {
2429
- return new m(
2430
- N.float(t.r, e.r),
2431
- N.float(t.g, e.g),
2432
- N.float(t.b, e.b),
2433
- N.float(t.a, e.a)
2574
+ return new g(
2575
+ D.float(t.r, e.r),
2576
+ D.float(t.g, e.g),
2577
+ D.float(t.b, e.b),
2578
+ D.float(t.a, e.a)
2434
2579
  );
2435
2580
  }
2436
2581
  static pick(t) {
2437
- return t[N.int(0, t.length - 1)];
2582
+ return t[D.int(0, t.length - 1)];
2438
2583
  }
2439
2584
  static pickWeight(t) {
2440
2585
  if (!t || t.length === 0) return null;
@@ -2450,27 +2595,27 @@ class N {
2450
2595
  if (Array.isArray(t)) {
2451
2596
  const [r, i] = t;
2452
2597
  if (typeof r == "number")
2453
- return N.float(r, i);
2598
+ return D.float(r, i);
2599
+ if (r instanceof p)
2600
+ return D.vector(r.x, i.x, r.y, i.y);
2454
2601
  if (r instanceof g)
2455
- return N.vector(r.x, i.x, r.y, i.y);
2456
- if (r instanceof m)
2457
- return N.randomColor(r, i);
2602
+ return D.randomColor(r, i);
2458
2603
  }
2459
2604
  return typeof t == "number" ? t : t.clone();
2460
2605
  }
2461
2606
  }
2462
- const J = (n, t) => (Array.isArray(n) ? n : [n]).slice(0, t);
2463
- var fe = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(fe || {});
2464
- const gt = 10, pt = 0, vt = !0;
2465
- class j {
2607
+ const et = (n, t) => (Array.isArray(n) ? n : [n]).slice(0, t);
2608
+ var ge = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(ge || {});
2609
+ const vt = 10, yt = 0, Tt = !0;
2610
+ class q {
2466
2611
  components;
2467
2612
  constructor(t = 1) {
2468
2613
  if (!Number.isInteger(t) || t <= 0)
2469
2614
  throw new RangeError("ParticleAttributeStore size must be a positive integer");
2470
2615
  this.components = Array.from({ length: t }, () => ({
2471
- value: new b(A.Float32),
2472
- delta: new b(A.Float32),
2473
- damping: new b(A.Float32)
2616
+ value: new _(C.Float32),
2617
+ delta: new _(C.Float32),
2618
+ damping: new _(C.Float32)
2474
2619
  }));
2475
2620
  }
2476
2621
  getArrayBuffer() {
@@ -2487,7 +2632,7 @@ class j {
2487
2632
  getComponent(t, e) {
2488
2633
  if (typeof t == "number")
2489
2634
  return t;
2490
- if (t instanceof g)
2635
+ if (t instanceof p)
2491
2636
  return e === 0 ? t.x : t.y;
2492
2637
  switch (e) {
2493
2638
  case 0:
@@ -2503,47 +2648,47 @@ class j {
2503
2648
  }
2504
2649
  }
2505
2650
  resolveComponent(t, e, r) {
2506
- return t === void 0 ? r : Array.isArray(t) ? N.float(
2651
+ return t === void 0 ? r : Array.isArray(t) ? D.float(
2507
2652
  this.getComponent(t[0], e),
2508
2653
  this.getComponent(t[1], e)
2509
2654
  ) : this.getComponent(t, e);
2510
2655
  }
2511
2656
  create(t, e, r = 1) {
2512
- const i = de(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
2513
- let h = 0;
2514
- for (let o = 0; o < this.components.length; o++) {
2515
- const { value: c, delta: u, damping: l } = this.components[o], f = this.getComponent(e, o), d = s === void 0 ? this.resolveComponent(i?.start, o, f) : this.getComponent(s, o), x = i?.end === void 0 ? d : this.resolveComponent(i.end, o, f);
2516
- 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);
2657
+ const i = pe(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
2658
+ let o = 0;
2659
+ for (let h = 0; h < this.components.length; h++) {
2660
+ const { value: c, delta: u, damping: l } = this.components[h], d = this.getComponent(e, h), f = s === void 0 ? this.resolveComponent(i?.start, h, d) : this.getComponent(s, h), m = i?.end === void 0 ? f : this.resolveComponent(i.end, h, d);
2661
+ c.push(f), u.push(i?.delta === void 0 ? (m - f) / a : this.getComponent(i.delta, h)), l.push(i?.damping ?? 1), h === 0 && (o = f);
2517
2662
  }
2518
- return h;
2663
+ return o;
2519
2664
  }
2520
2665
  }
2521
- class wt {
2666
+ class At {
2522
2667
  options;
2523
2668
  emitting = !1;
2524
2669
  emitTimer = 0;
2525
- emitRate = gt;
2526
- emitTime = pt;
2670
+ emitRate = vt;
2671
+ emitTime = yt;
2527
2672
  emitTimeCounter = 0;
2528
- localSpace = vt;
2673
+ localSpace = Tt;
2529
2674
  rapid;
2530
- x = new b(A.Float32);
2531
- y = new b(A.Float32);
2532
- scaleX = new b(A.Float32);
2533
- scaleY = new b(A.Float32);
2534
- rotation = new b(A.Float32);
2535
- color = new b(A.Uint32);
2536
- remainingLife = new b(A.Float32);
2675
+ x = new _(C.Float32);
2676
+ y = new _(C.Float32);
2677
+ scaleX = new _(C.Float32);
2678
+ scaleY = new _(C.Float32);
2679
+ rotation = new _(C.Float32);
2680
+ color = new _(C.Uint32);
2681
+ remainingLife = new _(C.Float32);
2537
2682
  animations = {
2538
- speed: new j(),
2539
- rotation: new j(),
2540
- scale: new j(),
2541
- color: new j(4),
2542
- velocity: new j(2)
2683
+ speed: new q(),
2684
+ rotation: new q(),
2685
+ scale: new q(),
2686
+ color: new q(4),
2687
+ velocity: new q(2)
2543
2688
  };
2544
2689
  count = 0;
2545
2690
  constructor(t, e) {
2546
- this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? gt, this.emitTime = e.emitTime ?? pt, this.localSpace = e.localSpace ?? vt;
2691
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? vt, this.emitTime = e.emitTime ?? yt, this.localSpace = e.localSpace ?? Tt;
2547
2692
  }
2548
2693
  getAllArrayBuffer() {
2549
2694
  return [
@@ -2561,7 +2706,7 @@ class wt {
2561
2706
  this.options.texture = t;
2562
2707
  }
2563
2708
  clone() {
2564
- return new wt(this.rapid, { ...this.options });
2709
+ return new At(this.rapid, { ...this.options });
2565
2710
  }
2566
2711
  setEmitRate(t) {
2567
2712
  this.emitRate = t;
@@ -2586,7 +2731,7 @@ class wt {
2586
2731
  this.createParticle();
2587
2732
  }
2588
2733
  createParticle() {
2589
- const t = N.scalarOrRange(this.options.life, 1);
2734
+ const t = D.scalarOrRange(this.options.life, 1);
2590
2735
  this.remainingLife.push(t);
2591
2736
  let e = 0, r = 0;
2592
2737
  switch (this.options.emitShape) {
@@ -2607,8 +2752,8 @@ class wt {
2607
2752
  const { x: c, y: u } = i.localToWorld(e, r);
2608
2753
  this.x.push(c), this.y.push(u);
2609
2754
  }
2610
- const s = this.options.animation, a = this.animations, h = a.scale.create(s.scale, 1, t), o = a.rotation.create(s.rotation, 0, t);
2611
- a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity, g.ZERO, t), a.color.create(s.color, m.White, t), this.rotation.push(o), this.scaleX.push(h), this.scaleY.push(h), this.color.pushUint32(m.packColor(
2755
+ const s = this.options.animation, a = this.animations, o = a.scale.create(s.scale, 1, t), h = a.rotation.create(s.rotation, 0, t);
2756
+ a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity, p.ZERO, t), a.color.create(s.color, g.White, t), this.rotation.push(h), this.scaleX.push(o), this.scaleY.push(o), this.color.pushUint32(g.packColor(
2612
2757
  a.color.get(this.count, 0),
2613
2758
  a.color.get(this.count, 1),
2614
2759
  a.color.get(this.count, 2),
@@ -2629,7 +2774,7 @@ class wt {
2629
2774
  r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
2630
2775
  }
2631
2776
  const e = this.updateParticle(t);
2632
- this.count -= e.length, b.removeAtIndices(e, this.getAllArrayBuffer());
2777
+ this.count -= e.length, _.removeAtIndices(e, this.getAllArrayBuffer());
2633
2778
  }
2634
2779
  updateParticle(t) {
2635
2780
  const e = [], r = this.animations;
@@ -2639,34 +2784,38 @@ class wt {
2639
2784
  e.push(i);
2640
2785
  continue;
2641
2786
  }
2642
- const s = r.rotation.get(i), a = r.scale.get(i), h = r.speed.get(i);
2643
- this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = m.packColor(
2787
+ const s = r.rotation.get(i), a = r.scale.get(i), o = r.speed.get(i);
2788
+ this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = g.packColor(
2644
2789
  r.color.get(i, 0),
2645
2790
  r.color.get(i, 1),
2646
2791
  r.color.get(i, 2),
2647
2792
  r.color.get(i, 3),
2648
2793
  this.rapid.premultipliedAlpha
2649
- ), 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;
2794
+ ), this.x.typedArray[i] += (o * Math.cos(s) + r.velocity.get(i, 0)) * t, this.y.typedArray[i] += (o * Math.sin(s) + r.velocity.get(i, 1)) * t;
2650
2795
  }
2651
2796
  return e;
2652
2797
  }
2653
- render() {
2654
- const t = this.options, e = this.localSpace ? void 0 : this.rapid.matrix.alloc();
2655
- this.rapid.drawParticles({
2656
- texture: t.texture,
2657
- shader: t.shader,
2658
- x: this.x.typedArray,
2659
- y: this.y.typedArray,
2660
- scaleX: this.scaleX.typedArray,
2661
- scaleY: this.scaleY.typedArray,
2662
- rotation: this.rotation.typedArray,
2663
- color: this.color.typedArray,
2664
- count: this.count,
2665
- reverseOrder: !0,
2666
- originX: t.origin?.x ?? 0.5,
2667
- originY: t.origin?.y ?? 0.5,
2668
- customMatrix: e
2669
- });
2798
+ render(t) {
2799
+ const e = this.options, r = t ?? (this.localSpace ? void 0 : this.rapid.matrix.alloc());
2800
+ try {
2801
+ this.rapid.drawParticles({
2802
+ texture: e.texture,
2803
+ shader: e.shader,
2804
+ x: this.x.typedArray,
2805
+ y: this.y.typedArray,
2806
+ scaleX: this.scaleX.typedArray,
2807
+ scaleY: this.scaleY.typedArray,
2808
+ rotation: this.rotation.typedArray,
2809
+ color: this.color.typedArray,
2810
+ count: this.count,
2811
+ reverseOrder: !0,
2812
+ originX: e.origin?.x ?? 0.5,
2813
+ originY: e.origin?.y ?? 0.5,
2814
+ customMatrix: r
2815
+ });
2816
+ } finally {
2817
+ t === void 0 && r !== void 0 && !this.localSpace && this.rapid.matrix.free(r);
2818
+ }
2670
2819
  }
2671
2820
  isActive() {
2672
2821
  return this.emitting || this.count > 0;
@@ -2675,12 +2824,10 @@ class wt {
2675
2824
  this.emit(this.emitRate);
2676
2825
  }
2677
2826
  }
2678
- const me = `
2827
+ const ve = `
2679
2828
  uniform mediump int uLightTextureId[%TEXTURE_NUM%];
2680
2829
 
2681
2830
  uniform sampler2D uNormalMap;
2682
- uniform vec2 uResolution;
2683
- uniform vec2 uLogicalResolution;
2684
2831
  uniform mediump int uLightCount;
2685
2832
  uniform vec4 uLightColor[%TEXTURE_NUM%];
2686
2833
  uniform mat3x2 uLightMatrix[%TEXTURE_NUM%];
@@ -2690,10 +2837,12 @@ uniform float uRoughness;
2690
2837
  uniform vec3 uAmbientColor;
2691
2838
  uniform vec2 uNormalScale;
2692
2839
 
2840
+ in vec2 light_worldPos;
2841
+
2693
2842
  void light_fragment(inout vec4 color, in vec2 vRegion) {
2694
2843
  if (color.a < 0.005) return;
2695
2844
 
2696
- vec2 worldPos = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) * (uLogicalResolution / uResolution);
2845
+ vec2 worldPos = light_worldPos;
2697
2846
  vec3 normal = normalize(texture(uNormalMap, vRegion).rgb * 2.0 - 1.0);
2698
2847
  normal = normalize(normal * vec3(uNormalScale, 1.0));
2699
2848
 
@@ -2728,8 +2877,13 @@ void light_fragment(inout vec4 color, in vec2 vRegion) {
2728
2877
 
2729
2878
  color.rgb = color.rgb * (uAmbientColor + totalDiffuse) + totalSpecular;
2730
2879
  }
2731
- `, xe = "void light_vertex(inout vec4 p, vec2 u) {}", tt = 8;
2732
- class ge extends ct {
2880
+ `, ye = `out vec2 light_worldPos;
2881
+
2882
+ void light_vertex(inout vec4 p, vec2 u) {
2883
+ light_worldPos = p.xy;
2884
+ }
2885
+ `, rt = 8;
2886
+ class Te extends ut {
2733
2887
  constructor(t, e = "", r = "", i = 0, s) {
2734
2888
  super(
2735
2889
  t,
@@ -2737,25 +2891,28 @@ class ge extends ct {
2737
2891
  r,
2738
2892
  i + 2,
2739
2893
  s
2740
- ), this.prefix.push("light_");
2894
+ );
2895
+ }
2896
+ beforePreCompile() {
2897
+ this.prefix.push("light_");
2741
2898
  }
2742
2899
  getGLShader(t, e, r, i) {
2743
- const s = K(me, t.getMaxTexutreUnit(this), "layer", "lightUV", "lightTex = ");
2744
- return i = this.replaceCustomCode(i, s), r = this.replaceCustomCode(r, xe), super.getGLShader(t, e, r, i);
2900
+ const s = Z(ve, t.getMaxTexutreUnit(this), "layer", "lightUV", "lightTex = ");
2901
+ return i = this.replaceCustomCode(i, s), r = this.replaceCustomCode(r, ye), super.getGLShader(t, e, r, i);
2745
2902
  }
2746
2903
  }
2747
- class ve {
2904
+ class Ee {
2748
2905
  shader;
2749
2906
  rapid;
2750
2907
  rt;
2751
2908
  constructor(t) {
2752
- this.rapid = t, this.shader = new ge(t), this.rt = t.texture.createRenderTexture({ width: 0, height: 0 });
2909
+ this.rapid = t, this.shader = new Te(t), this.rt = t.texture.createRenderTexture({ width: 0, height: 0 });
2753
2910
  }
2754
2911
  lightShadow(t, e, r) {
2755
2912
  if (r.length === 0) return;
2756
- const i = this.rapid, s = typeof e == "number" ? e : e.world, a = new g(t.rawWidth * 0.5, t.rawHeight * 0.5), h = r.map((c) => {
2913
+ const i = this.rapid, s = typeof e == "number" ? e : e.world, a = new p(t.rawWidth * 0.5, t.rawHeight * 0.5), o = r.map((c) => {
2757
2914
  const u = i.matrixStack.localToWorld(c.x, c.y), l = i.matrix.worldToLocal(s, u.x, u.y);
2758
- return new g(
2915
+ return new p(
2759
2916
  // 要把LightTexture的基向量转化为RenderTexture的坐标
2760
2917
  // 纹理是从左上角开始的,所以要 + 0.5
2761
2918
  (l.x + 0.5) * t.rawWidth,
@@ -2763,36 +2920,39 @@ class ve {
2763
2920
  );
2764
2921
  });
2765
2922
  this.rt.resize(t.rawWidth, t.rawHeight);
2766
- const o = Math.hypot(t.rawWidth, t.rawHeight) * 0.5 * 1.05;
2923
+ const h = Math.hypot(t.rawWidth, t.rawHeight) * 0.5 * 1.05;
2767
2924
  return i.drawToRenderTexture(this.rt, () => {
2768
- i.withMask(() => {
2769
- i.startMaskGraphic(i.gl.TRIANGLES);
2770
- for (let c = 0; c < h.length; c++) {
2771
- 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));
2772
- 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);
2773
- }
2774
- i.endGraphic();
2775
- }, () => {
2776
- i.drawSprite({ texture: t });
2777
- }, Rt.NOT_EQUAL);
2925
+ i.matrixStack.save(), i.matrixStack.identity();
2926
+ try {
2927
+ i.withMask(() => {
2928
+ i.startMaskGraphic(i.gl.TRIANGLES);
2929
+ for (let c = 0; c < o.length; c++) {
2930
+ const u = o[c], l = o[(c + 1) % o.length], d = u.subtract(a).normalized(), f = l.subtract(a).normalized(), m = Math.max(-0.999, Math.min(1, d.dot(f))), x = Math.sqrt((1 + m) * 0.5), y = h / x, v = a.add(d.multiply(y)), T = a.add(f.multiply(y));
2931
+ i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(l.x, l.y), i.addGraphicVertex(T.x, T.y), i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(T.x, T.y), i.addGraphicVertex(v.x, v.y);
2932
+ }
2933
+ i.endGraphic();
2934
+ }, () => {
2935
+ i.drawSprite({ texture: t });
2936
+ }, St.NOT_EQUAL);
2937
+ } finally {
2938
+ i.matrixStack.restore();
2939
+ }
2778
2940
  }), this.rt;
2779
2941
  }
2780
2942
  setupLight(t) {
2781
- const e = t.customShader ?? this.shader, r = J(t.lightMatrix, tt), i = J(t.color, tt), s = J(t.lightHeight, tt), a = J(t.lightTexture, tt);
2943
+ const e = t.customShader ?? this.shader, r = et(t.lightMatrix, rt), i = et(t.color, rt), s = et(t.lightHeight, rt), a = et(t.lightTexture, rt);
2782
2944
  return e.setUniforms({
2783
- uResolution: [this.rapid.physicsWidth, this.rapid.physicsHeight],
2784
- uLogicalResolution: [this.rapid.logicWidth, this.rapid.logicHeight],
2785
2945
  uNormalMap: t.normalMap.glTexture,
2786
- uLightTextureId: a.map((h) => h.glTexture),
2946
+ uLightTextureId: a.map((o) => o.glTexture),
2787
2947
  uLightCount: r.length,
2788
2948
  uLightMatrix: Float32Array.from(r.flatMap(
2789
- (h) => Array.from(this.rapid.matrix.getMatrix(typeof h == "number" ? h : h.world))
2949
+ (o) => Array.from(this.rapid.matrix.getMatrix(typeof o == "number" ? o : o.world))
2790
2950
  )),
2791
- uLightColor: Float32Array.from(r.flatMap((h, o) => {
2792
- const c = i[o] ?? i[0];
2951
+ uLightColor: Float32Array.from(r.flatMap((o, h) => {
2952
+ const c = i[h] ?? i[0];
2793
2953
  return c ? [c.r / 255, c.g / 255, c.b / 255, c.a / 255] : [1, 1, 1, 1];
2794
2954
  })),
2795
- uLightHeight: Float32Array.from(r.map((h, o) => s[o] ?? s[0] ?? 80)),
2955
+ uLightHeight: Float32Array.from(r.map((o, h) => s[h] ?? s[0] ?? 80)),
2796
2956
  uMetallic: t.metallic ?? 0.8,
2797
2957
  uRoughness: t.roughness ?? 0.15,
2798
2958
  uAmbientColor: t.ambientColor ? [t.ambientColor.r / 255, t.ambientColor.g / 255, t.ambientColor.b / 255] : [0.1, 0.1, 0.15],
@@ -2801,37 +2961,39 @@ class ve {
2801
2961
  }
2802
2962
  }
2803
2963
  export {
2804
- X as BaseTexture,
2805
- ue as BlendMode,
2806
- le as CanvasScaleMode,
2807
- m as Color,
2808
- ct as CustomGlShader,
2809
- Tt as GLShader,
2810
- ve as Light,
2811
- ge as LightShader,
2812
- jt as LineTextureMode,
2813
- tt as MAX_LIGHTS,
2814
- Rt as MaskType,
2815
- wt as ParticleEmitter,
2816
- fe as ParticleShape,
2817
- pe as Rapid,
2818
- Ut as RenderTexture,
2819
- _t as TextTexture,
2820
- F as Texture,
2821
- Q as TextureFilterMode,
2822
- bt as TextureManager,
2823
- q as TextureWrapMode,
2824
- g as Vec2,
2825
- zt as composeProjectionWithAffine,
2826
- se as drawCircle,
2964
+ z as BaseTexture,
2965
+ xe as BlendMode,
2966
+ Q as CanvasScaleMode,
2967
+ g as Color,
2968
+ ut as CustomGlShader,
2969
+ de as ExpandMode,
2970
+ Et as GLShader,
2971
+ Ee as Light,
2972
+ Te as LightShader,
2973
+ qt as LineTextureMode,
2974
+ rt as MAX_LIGHTS,
2975
+ St as MaskType,
2976
+ At as ParticleEmitter,
2977
+ ge as ParticleShape,
2978
+ we as Rapid,
2979
+ _t as RenderTexture,
2980
+ Lt as TextTexture,
2981
+ W as Texture,
2982
+ it as TextureFilterMode,
2983
+ Ct as TextureManager,
2984
+ J as TextureWrapMode,
2985
+ p as Vec2,
2986
+ me as ViewPort,
2987
+ jt as composeProjectionWithAffine,
2988
+ ae as drawCircle,
2827
2989
  Mt as drawGraphic,
2828
- ee as drawLine,
2829
- re as drawMaskImage,
2830
- te as drawParticles,
2831
- ie as drawRect,
2832
- Jt as drawSprite,
2833
- Qt as getColorUint32,
2834
- qt as getLineGeometry,
2835
- Kt as getLineNormal,
2836
- $t as multiplyMat4
2990
+ ie as drawLine,
2991
+ se as drawMaskImage,
2992
+ re as drawParticles,
2993
+ ne as drawRect,
2994
+ ee as drawSprite,
2995
+ Jt as getColorUint32,
2996
+ Qt as getLineGeometry,
2997
+ Zt as getLineNormal,
2998
+ Kt as multiplyMat4
2837
2999
  };