@micjanic/recursive-grid 1.0.2

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.
@@ -0,0 +1,3321 @@
1
+ import { E as w, U as wt, T as ve, a as Tt, a2 as U, a3 as O, D as H, t as R, $ as V, M as k, ac as vt, ad as St, w as ne, _ as j, Q as Z, ae as Ct, af as q, ag as G, l as Y, d as Le, I as A, a5 as me, R as xe, H as Ie, c as N, B as z, n as Se, S as ee, y as te, ah as Pt, ai as _e, L as pe, aj as K, s as be, v as Ft, G as Bt, m as Oe, q as Ee, a7 as He, aa as Ve, o as Mt, p as Rt, a8 as Ut, a9 as kt, ab as Gt, ak as At, al as zt, e as P, am as Dt } from "./PixiApp-D4xu0PT4.js";
2
+ import { c as se, a as Wt, b as Lt, B as Ye } from "./colorToUniform-C2jGzNe1.js";
3
+ import { C as X } from "./CanvasPool-BvJplAOp.js";
4
+ class Xe {
5
+ /**
6
+ * Initialize the plugin with scope of application instance
7
+ * @private
8
+ * @param {object} [options] - See application options
9
+ */
10
+ static init(e) {
11
+ Object.defineProperty(
12
+ this,
13
+ "resizeTo",
14
+ {
15
+ set(t) {
16
+ globalThis.removeEventListener("resize", this.queueResize), this._resizeTo = t, t && (globalThis.addEventListener("resize", this.queueResize), this.resize());
17
+ },
18
+ get() {
19
+ return this._resizeTo;
20
+ }
21
+ }
22
+ ), this.queueResize = () => {
23
+ this._resizeTo && (this._cancelResize(), this._resizeId = requestAnimationFrame(() => this.resize()));
24
+ }, this._cancelResize = () => {
25
+ this._resizeId && (cancelAnimationFrame(this._resizeId), this._resizeId = null);
26
+ }, this.resize = () => {
27
+ if (!this._resizeTo)
28
+ return;
29
+ this._cancelResize();
30
+ let t, r;
31
+ if (this._resizeTo === globalThis.window)
32
+ t = globalThis.innerWidth, r = globalThis.innerHeight;
33
+ else {
34
+ const { clientWidth: i, clientHeight: n } = this._resizeTo;
35
+ t = i, r = n;
36
+ }
37
+ this.renderer.resize(t, r), this.render();
38
+ }, this._resizeId = null, this._resizeTo = null, this.resizeTo = e.resizeTo || null;
39
+ }
40
+ /**
41
+ * Clean up the ticker, scoped to application
42
+ * @private
43
+ */
44
+ static destroy() {
45
+ globalThis.removeEventListener("resize", this.queueResize), this._cancelResize(), this._cancelResize = null, this.queueResize = null, this.resizeTo = null, this.resize = null;
46
+ }
47
+ }
48
+ Xe.extension = w.Application;
49
+ class $e {
50
+ /**
51
+ * Initialize the plugin with scope of application instance
52
+ * @private
53
+ * @param {object} [options] - See application options
54
+ */
55
+ static init(e) {
56
+ e = Object.assign({
57
+ autoStart: !0,
58
+ sharedTicker: !1
59
+ }, e), Object.defineProperty(
60
+ this,
61
+ "ticker",
62
+ {
63
+ set(t) {
64
+ this._ticker && this._ticker.remove(this.render, this), this._ticker = t, t && t.add(this.render, this, wt.LOW);
65
+ },
66
+ get() {
67
+ return this._ticker;
68
+ }
69
+ }
70
+ ), this.stop = () => {
71
+ this._ticker.stop();
72
+ }, this.start = () => {
73
+ this._ticker.start();
74
+ }, this._ticker = null, this.ticker = e.sharedTicker ? ve.shared : new ve(), e.autoStart && this.start();
75
+ }
76
+ /**
77
+ * Clean up the ticker, scoped to application.
78
+ * @private
79
+ */
80
+ static destroy() {
81
+ if (this._ticker) {
82
+ const e = this._ticker;
83
+ this.ticker = null, e.destroy();
84
+ }
85
+ }
86
+ }
87
+ $e.extension = w.Application;
88
+ class It extends Tt {
89
+ constructor() {
90
+ super(...arguments), this.chars = /* @__PURE__ */ Object.create(null), this.lineHeight = 0, this.fontFamily = "", this.fontMetrics = { fontSize: 0, ascent: 0, descent: 0 }, this.baseLineOffset = 0, this.distanceField = { type: "none", range: 0 }, this.pages = [], this.applyFillAsTint = !0, this.baseMeasurementFontSize = 100, this.baseRenderedFontSize = 100;
91
+ }
92
+ /**
93
+ * The name of the font face.
94
+ * @deprecated since 8.0.0 Use `fontFamily` instead.
95
+ */
96
+ get font() {
97
+ return U(O, "BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead."), this.fontFamily;
98
+ }
99
+ /**
100
+ * The map of base page textures (i.e., sheets of glyphs).
101
+ * @deprecated since 8.0.0 Use `pages` instead.
102
+ */
103
+ get pageTextures() {
104
+ return U(O, "BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."), this.pages;
105
+ }
106
+ /**
107
+ * The size of the font face in pixels.
108
+ * @deprecated since 8.0.0 Use `fontMetrics.fontSize` instead.
109
+ */
110
+ get size() {
111
+ return U(O, "BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead."), this.fontMetrics.fontSize;
112
+ }
113
+ /**
114
+ * The kind of distance field for this font or "none".
115
+ * @deprecated since 8.0.0 Use `distanceField.type` instead.
116
+ */
117
+ get distanceFieldRange() {
118
+ return U(O, "BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead."), this.distanceField.range;
119
+ }
120
+ /**
121
+ * The range of the distance field in pixels.
122
+ * @deprecated since 8.0.0 Use `distanceField.range` instead.
123
+ */
124
+ get distanceFieldType() {
125
+ return U(O, "BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead."), this.distanceField.type;
126
+ }
127
+ destroy(e = !1) {
128
+ var t;
129
+ this.emit("destroy", this), this.removeAllListeners();
130
+ for (const r in this.chars)
131
+ (t = this.chars[r].texture) == null || t.destroy();
132
+ this.chars = null, e && (this.pages.forEach((r) => r.texture.destroy(!0)), this.pages = null);
133
+ }
134
+ }
135
+ const Ot = [
136
+ "serif",
137
+ "sans-serif",
138
+ "monospace",
139
+ "cursive",
140
+ "fantasy",
141
+ "system-ui"
142
+ ];
143
+ function re(o) {
144
+ const e = typeof o.fontSize == "number" ? `${o.fontSize}px` : o.fontSize;
145
+ let t = o.fontFamily;
146
+ Array.isArray(o.fontFamily) || (t = o.fontFamily.split(","));
147
+ for (let r = t.length - 1; r >= 0; r--) {
148
+ let i = t[r].trim();
149
+ !/([\"\'])[^\'\"]+\1/.test(i) && !Ot.includes(i) && (i = `"${i}"`), t[r] = i;
150
+ }
151
+ return `${o.fontStyle} ${o.fontVariant} ${o.fontWeight} ${e} ${t.join(",")}`;
152
+ }
153
+ const oe = {
154
+ // TextMetrics requires getImageData readback for measuring fonts.
155
+ willReadFrequently: !0
156
+ }, W = class g {
157
+ /**
158
+ * Checking that we can use modern canvas 2D API.
159
+ *
160
+ * Note: This is an unstable API, Chrome < 94 use `textLetterSpacing`, later versions use `letterSpacing`.
161
+ * @see TextMetrics.experimentalLetterSpacing
162
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ICanvasRenderingContext2D/letterSpacing
163
+ * @see https://developer.chrome.com/origintrials/#/view_trial/3585991203293757441
164
+ */
165
+ static get experimentalLetterSpacingSupported() {
166
+ let e = g._experimentalLetterSpacingSupported;
167
+ if (e === void 0) {
168
+ const t = H.get().getCanvasRenderingContext2D().prototype;
169
+ e = g._experimentalLetterSpacingSupported = "letterSpacing" in t || "textLetterSpacing" in t;
170
+ }
171
+ return e;
172
+ }
173
+ /**
174
+ * @param text - the text that was measured
175
+ * @param style - the style that was measured
176
+ * @param width - the measured width of the text
177
+ * @param height - the measured height of the text
178
+ * @param lines - an array of the lines of text broken by new lines and wrapping if specified in style
179
+ * @param lineWidths - an array of the line widths for each line matched to `lines`
180
+ * @param lineHeight - the measured line height for this style
181
+ * @param maxLineWidth - the maximum line width for all measured lines
182
+ * @param {FontMetrics} fontProperties - the font properties object from TextMetrics.measureFont
183
+ */
184
+ constructor(e, t, r, i, n, s, a, l, c) {
185
+ this.text = e, this.style = t, this.width = r, this.height = i, this.lines = n, this.lineWidths = s, this.lineHeight = a, this.maxLineWidth = l, this.fontProperties = c;
186
+ }
187
+ /**
188
+ * Measures the supplied string of text and returns a Rectangle.
189
+ * @param text - The text to measure.
190
+ * @param style - The text style to use for measuring
191
+ * @param canvas - optional specification of the canvas to use for measuring.
192
+ * @param wordWrap
193
+ * @returns Measured width and height of the text.
194
+ */
195
+ static measureText(e = " ", t, r = g._canvas, i = t.wordWrap) {
196
+ var p;
197
+ const n = re(t), s = g.measureFont(n);
198
+ s.fontSize === 0 && (s.fontSize = t.fontSize, s.ascent = t.fontSize);
199
+ const a = g.__context;
200
+ a.font = n;
201
+ const c = (i ? g._wordWrap(e, t, r) : e).split(/(?:\r\n|\r|\n)/), d = new Array(c.length);
202
+ let u = 0;
203
+ for (let b = 0; b < c.length; b++) {
204
+ const y = g._measureText(c[b], t.letterSpacing, a);
205
+ d[b] = y, u = Math.max(u, y);
206
+ }
207
+ const h = ((p = t._stroke) == null ? void 0 : p.width) || 0;
208
+ let f = u + h;
209
+ t.dropShadow && (f += t.dropShadow.distance);
210
+ const m = t.lineHeight || s.fontSize;
211
+ let x = Math.max(m, s.fontSize + h) + (c.length - 1) * (m + t.leading);
212
+ return t.dropShadow && (x += t.dropShadow.distance), new g(
213
+ e,
214
+ t,
215
+ f,
216
+ x,
217
+ c,
218
+ d,
219
+ m + t.leading,
220
+ u,
221
+ s
222
+ );
223
+ }
224
+ static _measureText(e, t, r) {
225
+ let i = !1;
226
+ g.experimentalLetterSpacingSupported && (g.experimentalLetterSpacing ? (r.letterSpacing = `${t}px`, r.textLetterSpacing = `${t}px`, i = !0) : (r.letterSpacing = "0px", r.textLetterSpacing = "0px"));
227
+ const n = r.measureText(e);
228
+ let s = n.width;
229
+ const a = -n.actualBoundingBoxLeft;
230
+ let c = n.actualBoundingBoxRight - a;
231
+ if (s > 0)
232
+ if (i)
233
+ s -= t, c -= t;
234
+ else {
235
+ const d = (g.graphemeSegmenter(e).length - 1) * t;
236
+ s += d, c += d;
237
+ }
238
+ return Math.max(s, c);
239
+ }
240
+ /**
241
+ * Applies newlines to a string to have it optimally fit into the horizontal
242
+ * bounds set by the Text object's wordWrapWidth property.
243
+ * @param text - String to apply word wrapping to
244
+ * @param style - the style to use when wrapping
245
+ * @param canvas - optional specification of the canvas to use for measuring.
246
+ * @returns New string with new lines applied where required
247
+ */
248
+ static _wordWrap(e, t, r = g._canvas) {
249
+ const i = r.getContext("2d", oe);
250
+ let n = 0, s = "", a = "";
251
+ const l = /* @__PURE__ */ Object.create(null), { letterSpacing: c, whiteSpace: d } = t, u = g._collapseSpaces(d), h = g._collapseNewlines(d);
252
+ let f = !u;
253
+ const m = t.wordWrapWidth + c, x = g._tokenize(e);
254
+ for (let _ = 0; _ < x.length; _++) {
255
+ let p = x[_];
256
+ if (g._isNewline(p)) {
257
+ if (!h) {
258
+ a += g._addLine(s), f = !u, s = "", n = 0;
259
+ continue;
260
+ }
261
+ p = " ";
262
+ }
263
+ if (u) {
264
+ const y = g.isBreakingSpace(p), T = g.isBreakingSpace(s[s.length - 1]);
265
+ if (y && T)
266
+ continue;
267
+ }
268
+ const b = g._getFromCache(p, c, l, i);
269
+ if (b > m)
270
+ if (s !== "" && (a += g._addLine(s), s = "", n = 0), g.canBreakWords(p, t.breakWords)) {
271
+ const y = g.wordWrapSplit(p);
272
+ for (let T = 0; T < y.length; T++) {
273
+ let S = y[T], B = S, v = 1;
274
+ for (; y[T + v]; ) {
275
+ const M = y[T + v];
276
+ if (!g.canBreakChars(B, M, p, T, t.breakWords))
277
+ S += M;
278
+ else
279
+ break;
280
+ B = M, v++;
281
+ }
282
+ T += v - 1;
283
+ const F = g._getFromCache(S, c, l, i);
284
+ F + n > m && (a += g._addLine(s), f = !1, s = "", n = 0), s += S, n += F;
285
+ }
286
+ } else {
287
+ s.length > 0 && (a += g._addLine(s), s = "", n = 0);
288
+ const y = _ === x.length - 1;
289
+ a += g._addLine(p, !y), f = !1, s = "", n = 0;
290
+ }
291
+ else
292
+ b + n > m && (f = !1, a += g._addLine(s), s = "", n = 0), (s.length > 0 || !g.isBreakingSpace(p) || f) && (s += p, n += b);
293
+ }
294
+ return a += g._addLine(s, !1), a;
295
+ }
296
+ /**
297
+ * Convenience function for logging each line added during the wordWrap method.
298
+ * @param line - The line of text to add
299
+ * @param newLine - Add new line character to end
300
+ * @returns A formatted line
301
+ */
302
+ static _addLine(e, t = !0) {
303
+ return e = g._trimRight(e), e = t ? `${e}
304
+ ` : e, e;
305
+ }
306
+ /**
307
+ * Gets & sets the widths of calculated characters in a cache object
308
+ * @param key - The key
309
+ * @param letterSpacing - The letter spacing
310
+ * @param cache - The cache
311
+ * @param context - The canvas context
312
+ * @returns The from cache.
313
+ */
314
+ static _getFromCache(e, t, r, i) {
315
+ let n = r[e];
316
+ return typeof n != "number" && (n = g._measureText(e, t, i) + t, r[e] = n), n;
317
+ }
318
+ /**
319
+ * Determines whether we should collapse breaking spaces.
320
+ * @param whiteSpace - The TextStyle property whiteSpace
321
+ * @returns Should collapse
322
+ */
323
+ static _collapseSpaces(e) {
324
+ return e === "normal" || e === "pre-line";
325
+ }
326
+ /**
327
+ * Determines whether we should collapse newLine chars.
328
+ * @param whiteSpace - The white space
329
+ * @returns should collapse
330
+ */
331
+ static _collapseNewlines(e) {
332
+ return e === "normal";
333
+ }
334
+ /**
335
+ * Trims breaking whitespaces from string.
336
+ * @param text - The text
337
+ * @returns Trimmed string
338
+ */
339
+ static _trimRight(e) {
340
+ if (typeof e != "string")
341
+ return "";
342
+ for (let t = e.length - 1; t >= 0; t--) {
343
+ const r = e[t];
344
+ if (!g.isBreakingSpace(r))
345
+ break;
346
+ e = e.slice(0, -1);
347
+ }
348
+ return e;
349
+ }
350
+ /**
351
+ * Determines if char is a newline.
352
+ * @param char - The character
353
+ * @returns True if newline, False otherwise.
354
+ */
355
+ static _isNewline(e) {
356
+ return typeof e != "string" ? !1 : g._newlines.includes(e.charCodeAt(0));
357
+ }
358
+ /**
359
+ * Determines if char is a breaking whitespace.
360
+ *
361
+ * It allows one to determine whether char should be a breaking whitespace
362
+ * For example certain characters in CJK langs or numbers.
363
+ * It must return a boolean.
364
+ * @param char - The character
365
+ * @param [_nextChar] - The next character
366
+ * @returns True if whitespace, False otherwise.
367
+ */
368
+ static isBreakingSpace(e, t) {
369
+ return typeof e != "string" ? !1 : g._breakingSpaces.includes(e.charCodeAt(0));
370
+ }
371
+ /**
372
+ * Splits a string into words, breaking-spaces and newLine characters
373
+ * @param text - The text
374
+ * @returns A tokenized array
375
+ */
376
+ static _tokenize(e) {
377
+ const t = [];
378
+ let r = "";
379
+ if (typeof e != "string")
380
+ return t;
381
+ for (let i = 0; i < e.length; i++) {
382
+ const n = e[i], s = e[i + 1];
383
+ if (g.isBreakingSpace(n, s) || g._isNewline(n)) {
384
+ r !== "" && (t.push(r), r = ""), n === "\r" && s === `
385
+ ` ? (t.push(`\r
386
+ `), i++) : t.push(n);
387
+ continue;
388
+ }
389
+ r += n;
390
+ }
391
+ return r !== "" && t.push(r), t;
392
+ }
393
+ /**
394
+ * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
395
+ *
396
+ * It allows one to customise which words should break
397
+ * Examples are if the token is CJK or numbers.
398
+ * It must return a boolean.
399
+ * @param _token - The token
400
+ * @param breakWords - The style attr break words
401
+ * @returns Whether to break word or not
402
+ */
403
+ static canBreakWords(e, t) {
404
+ return t;
405
+ }
406
+ /**
407
+ * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
408
+ *
409
+ * It allows one to determine whether a pair of characters
410
+ * should be broken by newlines
411
+ * For example certain characters in CJK langs or numbers.
412
+ * It must return a boolean.
413
+ * @param _char - The character
414
+ * @param _nextChar - The next character
415
+ * @param _token - The token/word the characters are from
416
+ * @param _index - The index in the token of the char
417
+ * @param _breakWords - The style attr break words
418
+ * @returns whether to break word or not
419
+ */
420
+ static canBreakChars(e, t, r, i, n) {
421
+ return !0;
422
+ }
423
+ /**
424
+ * Overridable helper method used internally by TextMetrics, exposed to allow customizing the class's behavior.
425
+ *
426
+ * It is called when a token (usually a word) has to be split into separate pieces
427
+ * in order to determine the point to break a word.
428
+ * It must return an array of characters.
429
+ * @param token - The token to split
430
+ * @returns The characters of the token
431
+ * @see CanvasTextMetrics.graphemeSegmenter
432
+ */
433
+ static wordWrapSplit(e) {
434
+ return g.graphemeSegmenter(e);
435
+ }
436
+ /**
437
+ * Calculates the ascent, descent and fontSize of a given font-style
438
+ * @param font - String representing the style of the font
439
+ * @returns Font properties object
440
+ */
441
+ static measureFont(e) {
442
+ if (g._fonts[e])
443
+ return g._fonts[e];
444
+ const t = g._context;
445
+ t.font = e;
446
+ const r = t.measureText(g.METRICS_STRING + g.BASELINE_SYMBOL), i = {
447
+ ascent: r.actualBoundingBoxAscent,
448
+ descent: r.actualBoundingBoxDescent,
449
+ fontSize: r.actualBoundingBoxAscent + r.actualBoundingBoxDescent
450
+ };
451
+ return g._fonts[e] = i, i;
452
+ }
453
+ /**
454
+ * Clear font metrics in metrics cache.
455
+ * @param {string} [font] - font name. If font name not set then clear cache for all fonts.
456
+ */
457
+ static clearMetrics(e = "") {
458
+ e ? delete g._fonts[e] : g._fonts = {};
459
+ }
460
+ /**
461
+ * Cached canvas element for measuring text
462
+ * TODO: this should be private, but isn't because of backward compat, will fix later.
463
+ * @ignore
464
+ */
465
+ static get _canvas() {
466
+ if (!g.__canvas) {
467
+ let e;
468
+ try {
469
+ const t = new OffscreenCanvas(0, 0), r = t.getContext("2d", oe);
470
+ if (r != null && r.measureText)
471
+ return g.__canvas = t, t;
472
+ e = H.get().createCanvas();
473
+ } catch {
474
+ e = H.get().createCanvas();
475
+ }
476
+ e.width = e.height = 10, g.__canvas = e;
477
+ }
478
+ return g.__canvas;
479
+ }
480
+ /**
481
+ * TODO: this should be private, but isn't because of backward compat, will fix later.
482
+ * @ignore
483
+ */
484
+ static get _context() {
485
+ return g.__context || (g.__context = g._canvas.getContext("2d", oe)), g.__context;
486
+ }
487
+ };
488
+ W.METRICS_STRING = "|ÉqÅ";
489
+ W.BASELINE_SYMBOL = "M";
490
+ W.BASELINE_MULTIPLIER = 1.4;
491
+ W.HEIGHT_MULTIPLIER = 2;
492
+ W.graphemeSegmenter = (() => {
493
+ if (typeof (Intl == null ? void 0 : Intl.Segmenter) == "function") {
494
+ const o = new Intl.Segmenter();
495
+ return (e) => {
496
+ const t = o.segment(e), r = [];
497
+ let i = 0;
498
+ for (const n of t)
499
+ r[i++] = n.segment;
500
+ return r;
501
+ };
502
+ }
503
+ return (o) => [...o];
504
+ })();
505
+ W.experimentalLetterSpacing = !1;
506
+ W._fonts = {};
507
+ W._newlines = [
508
+ 10,
509
+ // line feed
510
+ 13
511
+ // carriage return
512
+ ];
513
+ W._breakingSpaces = [
514
+ 9,
515
+ // character tabulation
516
+ 32,
517
+ // space
518
+ 8192,
519
+ // en quad
520
+ 8193,
521
+ // em quad
522
+ 8194,
523
+ // en space
524
+ 8195,
525
+ // em space
526
+ 8196,
527
+ // three-per-em space
528
+ 8197,
529
+ // four-per-em space
530
+ 8198,
531
+ // six-per-em space
532
+ 8200,
533
+ // punctuation space
534
+ 8201,
535
+ // thin space
536
+ 8202,
537
+ // hair space
538
+ 8287,
539
+ // medium mathematical space
540
+ 12288
541
+ // ideographic space
542
+ ];
543
+ let D = W;
544
+ const Ce = 1e5;
545
+ function ie(o, e, t, r = 0) {
546
+ if (o.texture === R.WHITE && !o.fill)
547
+ return V.shared.setValue(o.color).setAlpha(o.alpha ?? 1).toHexa();
548
+ if (o.fill) {
549
+ if (o.fill instanceof vt) {
550
+ const i = o.fill, n = e.createPattern(i.texture.source.resource, "repeat"), s = i.transform.copyTo(k.shared);
551
+ return s.scale(
552
+ i.texture.frame.width,
553
+ i.texture.frame.height
554
+ ), n.setTransform(s), n;
555
+ } else if (o.fill instanceof St) {
556
+ const i = o.fill, n = i.type === "linear", s = i.textureSpace === "local";
557
+ let a = 1, l = 1;
558
+ s && t && (a = t.width + r, l = t.height + r);
559
+ let c, d = !1;
560
+ if (n) {
561
+ const { start: u, end: h } = i;
562
+ c = e.createLinearGradient(
563
+ u.x * a,
564
+ u.y * l,
565
+ h.x * a,
566
+ h.y * l
567
+ ), d = Math.abs(h.x - u.x) < Math.abs((h.y - u.y) * 0.1);
568
+ } else {
569
+ const { center: u, innerRadius: h, outerCenter: f, outerRadius: m } = i;
570
+ c = e.createRadialGradient(
571
+ u.x * a,
572
+ u.y * l,
573
+ h * a,
574
+ f.x * a,
575
+ f.y * l,
576
+ m * a
577
+ );
578
+ }
579
+ if (d && s && t) {
580
+ const u = t.lineHeight / l;
581
+ for (let h = 0; h < t.lines.length; h++) {
582
+ const f = (h * t.lineHeight + r / 2) / l;
583
+ i.colorStops.forEach((m) => {
584
+ const x = f + m.offset * u;
585
+ c.addColorStop(
586
+ // fix to 5 decimal places to avoid floating point precision issues
587
+ Math.floor(x * Ce) / Ce,
588
+ V.shared.setValue(m.color).toHex()
589
+ );
590
+ });
591
+ }
592
+ } else
593
+ i.colorStops.forEach((u) => {
594
+ c.addColorStop(u.offset, V.shared.setValue(u.color).toHex());
595
+ });
596
+ return c;
597
+ }
598
+ } else {
599
+ const i = e.createPattern(o.texture.source.resource, "repeat"), n = o.matrix.copyTo(k.shared);
600
+ return n.scale(o.texture.frame.width, o.texture.frame.height), i.setTransform(n), i;
601
+ }
602
+ return ne("FillStyle not recognised", o), "red";
603
+ }
604
+ const Ne = class je extends It {
605
+ /**
606
+ * @param options - The options for the dynamic bitmap font.
607
+ */
608
+ constructor(e) {
609
+ super(), this.resolution = 1, this.pages = [], this._padding = 0, this._measureCache = /* @__PURE__ */ Object.create(null), this._currentChars = [], this._currentX = 0, this._currentY = 0, this._currentMaxCharHeight = 0, this._currentPageIndex = -1, this._skipKerning = !1;
610
+ const t = { ...je.defaultOptions, ...e };
611
+ this._textureSize = t.textureSize, this._mipmap = t.mipmap;
612
+ const r = t.style.clone();
613
+ t.overrideFill && (r._fill.color = 16777215, r._fill.alpha = 1, r._fill.texture = R.WHITE, r._fill.fill = null), this.applyFillAsTint = t.overrideFill;
614
+ const i = r.fontSize;
615
+ r.fontSize = this.baseMeasurementFontSize;
616
+ const n = re(r);
617
+ t.overrideSize ? r._stroke && (r._stroke.width *= this.baseRenderedFontSize / i) : r.fontSize = this.baseRenderedFontSize = i, this._style = r, this._skipKerning = t.skipKerning ?? !1, this.resolution = t.resolution ?? 1, this._padding = t.padding ?? 4, t.textureStyle && (this._textureStyle = t.textureStyle instanceof j ? t.textureStyle : new j(t.textureStyle)), this.fontMetrics = D.measureFont(n), this.lineHeight = r.lineHeight || this.fontMetrics.fontSize || r.fontSize;
618
+ }
619
+ ensureCharacters(e) {
620
+ var _, p;
621
+ const t = D.graphemeSegmenter(e).filter((b) => !this._currentChars.includes(b)).filter((b, y, T) => T.indexOf(b) === y);
622
+ if (!t.length)
623
+ return;
624
+ this._currentChars = [...this._currentChars, ...t];
625
+ let r;
626
+ this._currentPageIndex === -1 ? r = this._nextPage() : r = this.pages[this._currentPageIndex];
627
+ let { canvas: i, context: n } = r.canvasAndContext, s = r.texture.source;
628
+ const a = this._style;
629
+ let l = this._currentX, c = this._currentY, d = this._currentMaxCharHeight;
630
+ const u = this.baseRenderedFontSize / this.baseMeasurementFontSize, h = this._padding * u;
631
+ let f = !1;
632
+ const m = i.width / this.resolution, x = i.height / this.resolution;
633
+ for (let b = 0; b < t.length; b++) {
634
+ const y = t[b], T = D.measureText(y, a, i, !1);
635
+ T.lineHeight = T.height;
636
+ const S = T.width * u, B = Math.ceil((a.fontStyle === "italic" ? 2 : 1) * S), v = T.height * u, F = B + h * 2, M = v + h * 2;
637
+ if (f = !1, y !== `
638
+ ` && y !== "\r" && y !== " " && y !== " " && (f = !0, d = Math.ceil(Math.max(M, d))), l + F > m && (c += d, d = M, l = 0, c + d > x)) {
639
+ s.update();
640
+ const L = this._nextPage();
641
+ i = L.canvasAndContext.canvas, n = L.canvasAndContext.context, s = L.texture.source, l = 0, c = 0, d = 0;
642
+ }
643
+ const ae = S / u - (((_ = a.dropShadow) == null ? void 0 : _.distance) ?? 0) - (((p = a._stroke) == null ? void 0 : p.width) ?? 0);
644
+ if (this.chars[y] = {
645
+ id: y.codePointAt(0),
646
+ xOffset: -this._padding,
647
+ yOffset: -this._padding,
648
+ xAdvance: ae,
649
+ kerning: {}
650
+ }, f) {
651
+ this._drawGlyph(
652
+ n,
653
+ T,
654
+ l + h,
655
+ c + h,
656
+ u,
657
+ a
658
+ );
659
+ const L = s.width * u, $ = s.height * u, C = new Z(
660
+ l / L * s.width,
661
+ c / $ * s.height,
662
+ F / L * s.width,
663
+ M / $ * s.height
664
+ );
665
+ this.chars[y].texture = new R({
666
+ source: s,
667
+ frame: C
668
+ }), l += Math.ceil(F);
669
+ }
670
+ }
671
+ s.update(), this._currentX = l, this._currentY = c, this._currentMaxCharHeight = d, this._skipKerning && this._applyKerning(t, n);
672
+ }
673
+ /**
674
+ * @deprecated since 8.0.0
675
+ * The map of base page textures (i.e., sheets of glyphs).
676
+ */
677
+ get pageTextures() {
678
+ return U(O, "BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."), this.pages;
679
+ }
680
+ _applyKerning(e, t) {
681
+ const r = this._measureCache;
682
+ for (let i = 0; i < e.length; i++) {
683
+ const n = e[i];
684
+ for (let s = 0; s < this._currentChars.length; s++) {
685
+ const a = this._currentChars[s];
686
+ let l = r[n];
687
+ l || (l = r[n] = t.measureText(n).width);
688
+ let c = r[a];
689
+ c || (c = r[a] = t.measureText(a).width);
690
+ let d = t.measureText(n + a).width, u = d - (l + c);
691
+ u && (this.chars[n].kerning[a] = u), d = t.measureText(n + a).width, u = d - (l + c), u && (this.chars[a].kerning[n] = u);
692
+ }
693
+ }
694
+ }
695
+ _nextPage() {
696
+ this._currentPageIndex++;
697
+ const e = this.resolution, t = X.getOptimalCanvasAndContext(
698
+ this._textureSize,
699
+ this._textureSize,
700
+ e
701
+ );
702
+ this._setupContext(t.context, this._style, e);
703
+ const r = e * (this.baseRenderedFontSize / this.baseMeasurementFontSize), i = new R({
704
+ source: new Ct({
705
+ resource: t.canvas,
706
+ resolution: r,
707
+ alphaMode: "premultiply-alpha-on-upload",
708
+ autoGenerateMipmaps: this._mipmap
709
+ })
710
+ });
711
+ this._textureStyle && (i.source.style = this._textureStyle);
712
+ const n = {
713
+ canvasAndContext: t,
714
+ texture: i
715
+ };
716
+ return this.pages[this._currentPageIndex] = n, n;
717
+ }
718
+ // canvas style!
719
+ _setupContext(e, t, r) {
720
+ t.fontSize = this.baseRenderedFontSize, e.scale(r, r), e.font = re(t), t.fontSize = this.baseMeasurementFontSize, e.textBaseline = t.textBaseline;
721
+ const i = t._stroke, n = (i == null ? void 0 : i.width) ?? 0;
722
+ if (i && (e.lineWidth = n, e.lineJoin = i.join, e.miterLimit = i.miterLimit, e.strokeStyle = ie(i, e)), t._fill && (e.fillStyle = ie(t._fill, e)), t.dropShadow) {
723
+ const s = t.dropShadow, a = V.shared.setValue(s.color).toArray(), l = s.blur * r, c = s.distance * r;
724
+ e.shadowColor = `rgba(${a[0] * 255},${a[1] * 255},${a[2] * 255},${s.alpha})`, e.shadowBlur = l, e.shadowOffsetX = Math.cos(s.angle) * c, e.shadowOffsetY = Math.sin(s.angle) * c;
725
+ } else
726
+ e.shadowColor = "black", e.shadowBlur = 0, e.shadowOffsetX = 0, e.shadowOffsetY = 0;
727
+ }
728
+ _drawGlyph(e, t, r, i, n, s) {
729
+ const a = t.text, l = t.fontProperties, c = s._stroke, d = ((c == null ? void 0 : c.width) ?? 0) * n, u = r + d / 2, h = i - d / 2, f = l.descent * n, m = t.lineHeight * n;
730
+ let x = !1;
731
+ s.stroke && d && (x = !0, e.strokeText(a, u, h + m - f));
732
+ const { shadowBlur: _, shadowOffsetX: p, shadowOffsetY: b } = e;
733
+ s._fill && (x && (e.shadowBlur = 0, e.shadowOffsetX = 0, e.shadowOffsetY = 0), e.fillText(a, u, h + m - f)), x && (e.shadowBlur = _, e.shadowOffsetX = p, e.shadowOffsetY = b);
734
+ }
735
+ destroy() {
736
+ super.destroy();
737
+ for (let e = 0; e < this.pages.length; e++) {
738
+ const { canvasAndContext: t, texture: r } = this.pages[e];
739
+ X.returnCanvasAndContext(t), r.destroy(!0);
740
+ }
741
+ this.pages = null;
742
+ }
743
+ };
744
+ Ne.defaultOptions = {
745
+ textureSize: 512,
746
+ style: new q(),
747
+ mipmap: !0
748
+ };
749
+ let Pe = Ne;
750
+ function qe(o, e, t, r) {
751
+ const i = {
752
+ width: 0,
753
+ height: 0,
754
+ offsetY: 0,
755
+ scale: e.fontSize / t.baseMeasurementFontSize,
756
+ lines: [{
757
+ width: 0,
758
+ charPositions: [],
759
+ spaceWidth: 0,
760
+ spacesIndex: [],
761
+ chars: []
762
+ }]
763
+ };
764
+ i.offsetY = t.baseLineOffset;
765
+ let n = i.lines[0], s = null, a = !0;
766
+ const l = {
767
+ width: 0,
768
+ start: 0,
769
+ index: 0,
770
+ // use index to not modify the array as we use it a lot!
771
+ positions: [],
772
+ chars: []
773
+ }, c = t.baseMeasurementFontSize / e.fontSize, d = e.letterSpacing * c, u = e.wordWrapWidth * c, h = e.lineHeight ? e.lineHeight * c : t.lineHeight, f = e.wordWrap && e.breakWords, m = (p) => {
774
+ const b = n.width;
775
+ for (let y = 0; y < l.index; y++) {
776
+ const T = p.positions[y];
777
+ n.chars.push(p.chars[y]), n.charPositions.push(T + b);
778
+ }
779
+ n.width += p.width, a = !1, l.width = 0, l.index = 0, l.chars.length = 0;
780
+ }, x = () => {
781
+ let p = n.chars.length - 1;
782
+ if (r) {
783
+ let b = n.chars[p];
784
+ for (; b === " "; )
785
+ n.width -= t.chars[b].xAdvance, b = n.chars[--p];
786
+ }
787
+ i.width = Math.max(i.width, n.width), n = {
788
+ width: 0,
789
+ charPositions: [],
790
+ chars: [],
791
+ spaceWidth: 0,
792
+ spacesIndex: []
793
+ }, a = !0, i.lines.push(n), i.height += h;
794
+ }, _ = (p) => p - d > u;
795
+ for (let p = 0; p < o.length + 1; p++) {
796
+ let b;
797
+ const y = p === o.length;
798
+ y || (b = o[p]);
799
+ const T = t.chars[b] || t.chars[" "];
800
+ if (/(?:\s)/.test(b) || b === "\r" || b === `
801
+ ` || y) {
802
+ if (!a && e.wordWrap && _(n.width + l.width) ? (x(), m(l), y || n.charPositions.push(0)) : (l.start = n.width, m(l), y || n.charPositions.push(0)), b === "\r" || b === `
803
+ `)
804
+ n.width !== 0 && x();
805
+ else if (!y) {
806
+ const F = T.xAdvance + (T.kerning[s] || 0) + d;
807
+ n.width += F, n.spaceWidth = F, n.spacesIndex.push(n.charPositions.length), n.chars.push(b);
808
+ }
809
+ } else {
810
+ const v = T.kerning[s] || 0, F = T.xAdvance + v + d;
811
+ f && _(n.width + l.width + F) && (m(l), x()), l.positions[l.index++] = l.width + v, l.chars.push(b), l.width += F;
812
+ }
813
+ s = b;
814
+ }
815
+ return x(), e.align === "center" ? Et(i) : e.align === "right" ? Ht(i) : e.align === "justify" && Vt(i), i;
816
+ }
817
+ function Et(o) {
818
+ for (let e = 0; e < o.lines.length; e++) {
819
+ const t = o.lines[e], r = o.width / 2 - t.width / 2;
820
+ for (let i = 0; i < t.charPositions.length; i++)
821
+ t.charPositions[i] += r;
822
+ }
823
+ }
824
+ function Ht(o) {
825
+ for (let e = 0; e < o.lines.length; e++) {
826
+ const t = o.lines[e], r = o.width - t.width;
827
+ for (let i = 0; i < t.charPositions.length; i++)
828
+ t.charPositions[i] += r;
829
+ }
830
+ }
831
+ function Vt(o) {
832
+ const e = o.width;
833
+ for (let t = 0; t < o.lines.length; t++) {
834
+ const r = o.lines[t];
835
+ let i = 0, n = r.spacesIndex[i++], s = 0;
836
+ const a = r.spacesIndex.length, c = (e - r.width) / a;
837
+ for (let d = 0; d < r.charPositions.length; d++)
838
+ d === n && (n = r.spacesIndex[i++], s += c), r.charPositions[d] += s;
839
+ }
840
+ }
841
+ function Yt(o) {
842
+ if (o === "")
843
+ return [];
844
+ typeof o == "string" && (o = [o]);
845
+ const e = [];
846
+ for (let t = 0, r = o.length; t < r; t++) {
847
+ const i = o[t];
848
+ if (Array.isArray(i)) {
849
+ if (i.length !== 2)
850
+ throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${i.length}.`);
851
+ if (i[0].length === 0 || i[1].length === 0)
852
+ throw new Error("[BitmapFont]: Invalid character delimiter.");
853
+ const n = i[0].charCodeAt(0), s = i[1].charCodeAt(0);
854
+ if (s < n)
855
+ throw new Error("[BitmapFont]: Invalid character range.");
856
+ for (let a = n, l = s; a <= l; a++)
857
+ e.push(String.fromCharCode(a));
858
+ } else
859
+ e.push(...Array.from(i));
860
+ }
861
+ if (e.length === 0)
862
+ throw new Error("[BitmapFont]: Empty set when resolving characters.");
863
+ return e;
864
+ }
865
+ let Q = 0;
866
+ class Xt {
867
+ constructor() {
868
+ this.ALPHA = [["a", "z"], ["A", "Z"], " "], this.NUMERIC = [["0", "9"]], this.ALPHANUMERIC = [["a", "z"], ["A", "Z"], ["0", "9"], " "], this.ASCII = [[" ", "~"]], this.defaultOptions = {
869
+ chars: this.ALPHANUMERIC,
870
+ resolution: 1,
871
+ padding: 4,
872
+ skipKerning: !1,
873
+ textureStyle: null
874
+ };
875
+ }
876
+ /**
877
+ * Get a font for the specified text and style.
878
+ * @param text - The text to get the font for
879
+ * @param style - The style to use
880
+ */
881
+ getFont(e, t) {
882
+ var s;
883
+ let r = `${t.fontFamily}-bitmap`, i = !0;
884
+ if (t._fill.fill && !t._stroke)
885
+ r += t._fill.fill.styleKey, i = !1;
886
+ else if (t._stroke || t.dropShadow) {
887
+ let a = t.styleKey;
888
+ a = a.substring(0, a.lastIndexOf("-")), r = `${a}-bitmap`, i = !1;
889
+ }
890
+ if (!G.has(r)) {
891
+ const a = Object.create(t);
892
+ a.lineHeight = 0;
893
+ const l = new Pe({
894
+ style: a,
895
+ overrideFill: i,
896
+ overrideSize: !0,
897
+ ...this.defaultOptions
898
+ });
899
+ Q++, Q > 50 && ne("BitmapText", `You have dynamically created ${Q} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``), l.once("destroy", () => {
900
+ Q--, G.remove(r);
901
+ }), G.set(
902
+ r,
903
+ l
904
+ );
905
+ }
906
+ const n = G.get(r);
907
+ return (s = n.ensureCharacters) == null || s.call(n, e), n;
908
+ }
909
+ /**
910
+ * Get the layout of a text for the specified style.
911
+ * @param text - The text to get the layout for
912
+ * @param style - The style to use
913
+ * @param trimEnd - Whether to ignore whitespaces at the end of each line
914
+ */
915
+ getLayout(e, t, r = !0) {
916
+ const i = this.getFont(e, t), n = D.graphemeSegmenter(e);
917
+ return qe(n, t, i, r);
918
+ }
919
+ /**
920
+ * Measure the text using the specified style.
921
+ * @param text - The text to measure
922
+ * @param style - The style to use
923
+ * @param trimEnd - Whether to ignore whitespaces at the end of each line
924
+ */
925
+ measureText(e, t, r = !0) {
926
+ return this.getLayout(e, t, r);
927
+ }
928
+ // eslint-disable-next-line max-len
929
+ install(...e) {
930
+ var c, d, u, h;
931
+ let t = e[0];
932
+ typeof t == "string" && (t = {
933
+ name: t,
934
+ style: e[1],
935
+ chars: (c = e[2]) == null ? void 0 : c.chars,
936
+ resolution: (d = e[2]) == null ? void 0 : d.resolution,
937
+ padding: (u = e[2]) == null ? void 0 : u.padding,
938
+ skipKerning: (h = e[2]) == null ? void 0 : h.skipKerning
939
+ }, U(O, "BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})"));
940
+ const r = t == null ? void 0 : t.name;
941
+ if (!r)
942
+ throw new Error("[BitmapFontManager] Property `name` is required.");
943
+ t = { ...this.defaultOptions, ...t };
944
+ const i = t.style, n = i instanceof q ? i : new q(i), s = t.dynamicFill ?? this._canUseTintForStyle(n), a = new Pe({
945
+ style: n,
946
+ overrideFill: s,
947
+ skipKerning: t.skipKerning,
948
+ padding: t.padding,
949
+ resolution: t.resolution,
950
+ overrideSize: !1,
951
+ textureStyle: t.textureStyle
952
+ }), l = Yt(t.chars);
953
+ return a.ensureCharacters(l.join("")), G.set(`${r}-bitmap`, a), a.once("destroy", () => G.remove(`${r}-bitmap`)), a;
954
+ }
955
+ /**
956
+ * Uninstalls a bitmap font from the cache.
957
+ * @param {string} name - The name of the bitmap font to uninstall.
958
+ */
959
+ uninstall(e) {
960
+ const t = `${e}-bitmap`, r = G.get(t);
961
+ r && r.destroy();
962
+ }
963
+ /**
964
+ * Determines if a style can use tinting instead of baking colors into the bitmap.
965
+ * Tinting is more efficient as it allows reusing the same bitmap with different colors.
966
+ * @param style - The text style to evaluate
967
+ * @returns true if the style can use tinting, false if colors must be baked in
968
+ * @private
969
+ */
970
+ _canUseTintForStyle(e) {
971
+ return !e._stroke && (!e.dropShadow || e.dropShadow.color === 0) && !e._fill.fill && e._fill.color === 16777215;
972
+ }
973
+ }
974
+ const $t = new Xt();
975
+ class Ke {
976
+ constructor(e) {
977
+ this._renderer = e;
978
+ }
979
+ push(e, t, r) {
980
+ this._renderer.renderPipes.batch.break(r), r.add({
981
+ renderPipeId: "filter",
982
+ canBundle: !1,
983
+ action: "pushFilter",
984
+ container: t,
985
+ filterEffect: e
986
+ });
987
+ }
988
+ pop(e, t, r) {
989
+ this._renderer.renderPipes.batch.break(r), r.add({
990
+ renderPipeId: "filter",
991
+ action: "popFilter",
992
+ canBundle: !1
993
+ });
994
+ }
995
+ execute(e) {
996
+ e.action === "pushFilter" ? this._renderer.filter.push(e) : e.action === "popFilter" && this._renderer.filter.pop();
997
+ }
998
+ destroy() {
999
+ this._renderer = null;
1000
+ }
1001
+ }
1002
+ Ke.extension = {
1003
+ type: [
1004
+ w.WebGLPipes,
1005
+ w.WebGPUPipes,
1006
+ w.CanvasPipes
1007
+ ],
1008
+ name: "filter"
1009
+ };
1010
+ function Nt(o, e) {
1011
+ e.clear();
1012
+ const t = e.matrix;
1013
+ for (let r = 0; r < o.length; r++) {
1014
+ const i = o[r];
1015
+ i.globalDisplayStatus < 7 || (e.matrix = i.worldTransform, e.addBounds(i.bounds));
1016
+ }
1017
+ return e.matrix = t, e;
1018
+ }
1019
+ const jt = new me({
1020
+ attributes: {
1021
+ aPosition: {
1022
+ buffer: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
1023
+ format: "float32x2",
1024
+ stride: 8,
1025
+ offset: 0
1026
+ }
1027
+ },
1028
+ indexBuffer: new Uint32Array([0, 1, 2, 0, 2, 3])
1029
+ });
1030
+ class qt {
1031
+ constructor() {
1032
+ this.skip = !1, this.inputTexture = null, this.backTexture = null, this.filters = null, this.bounds = new Ie(), this.container = null, this.blendRequired = !1, this.outputRenderSurface = null, this.globalFrame = { x: 0, y: 0, width: 0, height: 0 };
1033
+ }
1034
+ }
1035
+ class Qe {
1036
+ constructor(e) {
1037
+ this._filterStackIndex = 0, this._filterStack = [], this._filterGlobalUniforms = new Y({
1038
+ uInputSize: { value: new Float32Array(4), type: "vec4<f32>" },
1039
+ uInputPixel: { value: new Float32Array(4), type: "vec4<f32>" },
1040
+ uInputClamp: { value: new Float32Array(4), type: "vec4<f32>" },
1041
+ uOutputFrame: { value: new Float32Array(4), type: "vec4<f32>" },
1042
+ uGlobalFrame: { value: new Float32Array(4), type: "vec4<f32>" },
1043
+ uOutputTexture: { value: new Float32Array(4), type: "vec4<f32>" }
1044
+ }), this._globalFilterBindGroup = new Le({}), this.renderer = e;
1045
+ }
1046
+ /**
1047
+ * The back texture of the currently active filter. Requires the filter to have `blendRequired` set to true.
1048
+ * @readonly
1049
+ */
1050
+ get activeBackTexture() {
1051
+ var e;
1052
+ return (e = this._activeFilterData) == null ? void 0 : e.backTexture;
1053
+ }
1054
+ /**
1055
+ * Pushes a filter instruction onto the filter stack.
1056
+ * @param instruction - The instruction containing the filter effect and container.
1057
+ * @internal
1058
+ */
1059
+ push(e) {
1060
+ const t = this.renderer, r = e.filterEffect.filters, i = this._pushFilterData();
1061
+ i.skip = !1, i.filters = r, i.container = e.container, i.outputRenderSurface = t.renderTarget.renderSurface;
1062
+ const n = t.renderTarget.renderTarget.colorTexture.source, s = n.resolution, a = n.antialias;
1063
+ if (r.length === 0) {
1064
+ i.skip = !0;
1065
+ return;
1066
+ }
1067
+ const l = i.bounds;
1068
+ if (this._calculateFilterArea(e, l), this._calculateFilterBounds(i, t.renderTarget.rootViewPort, a, s, 1), i.skip)
1069
+ return;
1070
+ const c = this._getPreviousFilterData(), d = this._findFilterResolution(s);
1071
+ let u = 0, h = 0;
1072
+ c && (u = c.bounds.minX, h = c.bounds.minY), this._calculateGlobalFrame(
1073
+ i,
1074
+ u,
1075
+ h,
1076
+ d,
1077
+ n.width,
1078
+ n.height
1079
+ ), this._setupFilterTextures(i, l, t, c);
1080
+ }
1081
+ /**
1082
+ * Applies filters to a texture.
1083
+ *
1084
+ * This method takes a texture and a list of filters, applies the filters to the texture,
1085
+ * and returns the resulting texture.
1086
+ * @param {object} params - The parameters for applying filters.
1087
+ * @param {Texture} params.texture - The texture to apply filters to.
1088
+ * @param {Filter[]} params.filters - The filters to apply.
1089
+ * @returns {Texture} The resulting texture after all filters have been applied.
1090
+ * @example
1091
+ *
1092
+ * ```ts
1093
+ * // Create a texture and a list of filters
1094
+ * const texture = new Texture(...);
1095
+ * const filters = [new BlurFilter(), new ColorMatrixFilter()];
1096
+ *
1097
+ * // Apply the filters to the texture
1098
+ * const resultTexture = filterSystem.applyToTexture({ texture, filters });
1099
+ *
1100
+ * // Use the resulting texture
1101
+ * sprite.texture = resultTexture;
1102
+ * ```
1103
+ *
1104
+ * Key Points:
1105
+ * 1. padding is not currently supported here - so clipping may occur with filters that use padding.
1106
+ * 2. If all filters are disabled or skipped, the original texture is returned.
1107
+ */
1108
+ generateFilteredTexture({ texture: e, filters: t }) {
1109
+ const r = this._pushFilterData();
1110
+ this._activeFilterData = r, r.skip = !1, r.filters = t;
1111
+ const i = e.source, n = i.resolution, s = i.antialias;
1112
+ if (t.length === 0)
1113
+ return r.skip = !0, e;
1114
+ const a = r.bounds;
1115
+ if (a.addRect(e.frame), this._calculateFilterBounds(r, a.rectangle, s, n, 0), r.skip)
1116
+ return e;
1117
+ const l = n;
1118
+ this._calculateGlobalFrame(
1119
+ r,
1120
+ 0,
1121
+ 0,
1122
+ l,
1123
+ i.width,
1124
+ i.height
1125
+ ), r.outputRenderSurface = A.getOptimalTexture(
1126
+ a.width,
1127
+ a.height,
1128
+ r.resolution,
1129
+ r.antialias
1130
+ ), r.backTexture = R.EMPTY, r.inputTexture = e, this.renderer.renderTarget.finishRenderPass(), this._applyFiltersToTexture(r, !0);
1131
+ const h = r.outputRenderSurface;
1132
+ return h.source.alphaMode = "premultiplied-alpha", h;
1133
+ }
1134
+ /** @internal */
1135
+ pop() {
1136
+ const e = this.renderer, t = this._popFilterData();
1137
+ t.skip || (e.globalUniforms.pop(), e.renderTarget.finishRenderPass(), this._activeFilterData = t, this._applyFiltersToTexture(t, !1), t.blendRequired && A.returnTexture(t.backTexture), A.returnTexture(t.inputTexture));
1138
+ }
1139
+ /**
1140
+ * Copies the last render surface to a texture.
1141
+ * @param lastRenderSurface - The last render surface to copy from.
1142
+ * @param bounds - The bounds of the area to copy.
1143
+ * @param previousBounds - The previous bounds to use for offsetting the copy.
1144
+ */
1145
+ getBackTexture(e, t, r) {
1146
+ const i = e.colorTexture.source._resolution, n = A.getOptimalTexture(
1147
+ t.width,
1148
+ t.height,
1149
+ i,
1150
+ !1
1151
+ );
1152
+ let s = t.minX, a = t.minY;
1153
+ r && (s -= r.minX, a -= r.minY), s = Math.floor(s * i), a = Math.floor(a * i);
1154
+ const l = Math.ceil(t.width * i), c = Math.ceil(t.height * i);
1155
+ return this.renderer.renderTarget.copyToTexture(
1156
+ e,
1157
+ n,
1158
+ { x: s, y: a },
1159
+ { width: l, height: c },
1160
+ { x: 0, y: 0 }
1161
+ ), n;
1162
+ }
1163
+ /**
1164
+ * Applies a filter to a texture.
1165
+ * @param filter - The filter to apply.
1166
+ * @param input - The input texture.
1167
+ * @param output - The output render surface.
1168
+ * @param clear - Whether to clear the output surface before applying the filter.
1169
+ */
1170
+ applyFilter(e, t, r, i) {
1171
+ const n = this.renderer, s = this._activeFilterData, l = s.outputRenderSurface === r, c = n.renderTarget.rootRenderTarget.colorTexture.source._resolution, d = this._findFilterResolution(c);
1172
+ let u = 0, h = 0;
1173
+ if (l) {
1174
+ const f = this._findPreviousFilterOffset();
1175
+ u = f.x, h = f.y;
1176
+ }
1177
+ this._updateFilterUniforms(t, r, s, u, h, d, l, i), this._setupBindGroupsAndRender(e, t, n);
1178
+ }
1179
+ /**
1180
+ * Multiply _input normalized coordinates_ to this matrix to get _sprite texture normalized coordinates_.
1181
+ *
1182
+ * Use `outputMatrix * vTextureCoord` in the shader.
1183
+ * @param outputMatrix - The matrix to output to.
1184
+ * @param {Sprite} sprite - The sprite to map to.
1185
+ * @returns The mapped matrix.
1186
+ */
1187
+ calculateSpriteMatrix(e, t) {
1188
+ const r = this._activeFilterData, i = e.set(
1189
+ r.inputTexture._source.width,
1190
+ 0,
1191
+ 0,
1192
+ r.inputTexture._source.height,
1193
+ r.bounds.minX,
1194
+ r.bounds.minY
1195
+ ), n = t.worldTransform.copyTo(k.shared), s = t.renderGroup || t.parentRenderGroup;
1196
+ return s && s.cacheToLocalTransform && n.prepend(s.cacheToLocalTransform), n.invert(), i.prepend(n), i.scale(
1197
+ 1 / t.texture.orig.width,
1198
+ 1 / t.texture.orig.height
1199
+ ), i.translate(t.anchor.x, t.anchor.y), i;
1200
+ }
1201
+ destroy() {
1202
+ }
1203
+ /**
1204
+ * Sets up the bind groups and renders the filter.
1205
+ * @param filter - The filter to apply
1206
+ * @param input - The input texture
1207
+ * @param renderer - The renderer instance
1208
+ */
1209
+ _setupBindGroupsAndRender(e, t, r) {
1210
+ if (r.renderPipes.uniformBatch) {
1211
+ const i = r.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);
1212
+ this._globalFilterBindGroup.setResource(i, 0);
1213
+ } else
1214
+ this._globalFilterBindGroup.setResource(this._filterGlobalUniforms, 0);
1215
+ this._globalFilterBindGroup.setResource(t.source, 1), this._globalFilterBindGroup.setResource(t.source.style, 2), e.groups[0] = this._globalFilterBindGroup, r.encoder.draw({
1216
+ geometry: jt,
1217
+ shader: e,
1218
+ state: e._state,
1219
+ topology: "triangle-list"
1220
+ }), r.type === xe.WEBGL && r.renderTarget.finishRenderPass();
1221
+ }
1222
+ /**
1223
+ * Sets up the filter textures including input texture and back texture if needed.
1224
+ * @param filterData - The filter data to update
1225
+ * @param bounds - The bounds for the texture
1226
+ * @param renderer - The renderer instance
1227
+ * @param previousFilterData - The previous filter data for back texture calculation
1228
+ */
1229
+ _setupFilterTextures(e, t, r, i) {
1230
+ if (e.backTexture = R.EMPTY, e.blendRequired) {
1231
+ r.renderTarget.finishRenderPass();
1232
+ const n = r.renderTarget.getRenderTarget(e.outputRenderSurface);
1233
+ e.backTexture = this.getBackTexture(n, t, i == null ? void 0 : i.bounds);
1234
+ }
1235
+ e.inputTexture = A.getOptimalTexture(
1236
+ t.width,
1237
+ t.height,
1238
+ e.resolution,
1239
+ e.antialias
1240
+ ), r.renderTarget.bind(e.inputTexture, !0), r.globalUniforms.push({
1241
+ offset: t
1242
+ });
1243
+ }
1244
+ /**
1245
+ * Calculates and sets the global frame for the filter.
1246
+ * @param filterData - The filter data to update
1247
+ * @param offsetX - The X offset
1248
+ * @param offsetY - The Y offset
1249
+ * @param globalResolution - The global resolution
1250
+ * @param sourceWidth - The source texture width
1251
+ * @param sourceHeight - The source texture height
1252
+ */
1253
+ _calculateGlobalFrame(e, t, r, i, n, s) {
1254
+ const a = e.globalFrame;
1255
+ a.x = t * i, a.y = r * i, a.width = n * i, a.height = s * i;
1256
+ }
1257
+ /**
1258
+ * Updates the filter uniforms with the current filter state.
1259
+ * @param input - The input texture
1260
+ * @param output - The output render surface
1261
+ * @param filterData - The current filter data
1262
+ * @param offsetX - The X offset for positioning
1263
+ * @param offsetY - The Y offset for positioning
1264
+ * @param resolution - The current resolution
1265
+ * @param isFinalTarget - Whether this is the final render target
1266
+ * @param clear - Whether to clear the output surface
1267
+ */
1268
+ _updateFilterUniforms(e, t, r, i, n, s, a, l) {
1269
+ const c = this._filterGlobalUniforms.uniforms, d = c.uOutputFrame, u = c.uInputSize, h = c.uInputPixel, f = c.uInputClamp, m = c.uGlobalFrame, x = c.uOutputTexture;
1270
+ a ? (d[0] = r.bounds.minX - i, d[1] = r.bounds.minY - n) : (d[0] = 0, d[1] = 0), d[2] = e.frame.width, d[3] = e.frame.height, u[0] = e.source.width, u[1] = e.source.height, u[2] = 1 / u[0], u[3] = 1 / u[1], h[0] = e.source.pixelWidth, h[1] = e.source.pixelHeight, h[2] = 1 / h[0], h[3] = 1 / h[1], f[0] = 0.5 * h[2], f[1] = 0.5 * h[3], f[2] = e.frame.width * u[2] - 0.5 * h[2], f[3] = e.frame.height * u[3] - 0.5 * h[3];
1271
+ const _ = this.renderer.renderTarget.rootRenderTarget.colorTexture;
1272
+ m[0] = i * s, m[1] = n * s, m[2] = _.source.width * s, m[3] = _.source.height * s, t instanceof R && (t.source.resource = null);
1273
+ const p = this.renderer.renderTarget.getRenderTarget(t);
1274
+ this.renderer.renderTarget.bind(t, !!l), t instanceof R ? (x[0] = t.frame.width, x[1] = t.frame.height) : (x[0] = p.width, x[1] = p.height), x[2] = p.isRoot ? -1 : 1, this._filterGlobalUniforms.update();
1275
+ }
1276
+ /**
1277
+ * Finds the correct resolution by looking back through the filter stack.
1278
+ * @param rootResolution - The fallback root resolution to use
1279
+ * @returns The resolution from the previous filter or root resolution
1280
+ */
1281
+ _findFilterResolution(e) {
1282
+ let t = this._filterStackIndex - 1;
1283
+ for (; t > 0 && this._filterStack[t].skip; )
1284
+ --t;
1285
+ return t > 0 && this._filterStack[t].inputTexture ? this._filterStack[t].inputTexture.source._resolution : e;
1286
+ }
1287
+ /**
1288
+ * Finds the offset from the previous non-skipped filter in the stack.
1289
+ * @returns The offset coordinates from the previous filter
1290
+ */
1291
+ _findPreviousFilterOffset() {
1292
+ let e = 0, t = 0, r = this._filterStackIndex;
1293
+ for (; r > 0; ) {
1294
+ r--;
1295
+ const i = this._filterStack[r];
1296
+ if (!i.skip) {
1297
+ e = i.bounds.minX, t = i.bounds.minY;
1298
+ break;
1299
+ }
1300
+ }
1301
+ return { x: e, y: t };
1302
+ }
1303
+ /**
1304
+ * Calculates the filter area bounds based on the instruction type.
1305
+ * @param instruction - The filter instruction
1306
+ * @param bounds - The bounds object to populate
1307
+ */
1308
+ _calculateFilterArea(e, t) {
1309
+ if (e.renderables ? Nt(e.renderables, t) : e.filterEffect.filterArea ? (t.clear(), t.addRect(e.filterEffect.filterArea), t.applyMatrix(e.container.worldTransform)) : e.container.getFastGlobalBounds(!0, t), e.container) {
1310
+ const i = (e.container.renderGroup || e.container.parentRenderGroup).cacheToLocalTransform;
1311
+ i && t.applyMatrix(i);
1312
+ }
1313
+ }
1314
+ _applyFiltersToTexture(e, t) {
1315
+ const r = e.inputTexture, i = e.bounds, n = e.filters;
1316
+ if (this._globalFilterBindGroup.setResource(r.source.style, 2), this._globalFilterBindGroup.setResource(e.backTexture.source, 3), n.length === 1)
1317
+ n[0].apply(this, r, e.outputRenderSurface, t);
1318
+ else {
1319
+ let s = e.inputTexture;
1320
+ const a = A.getOptimalTexture(
1321
+ i.width,
1322
+ i.height,
1323
+ s.source._resolution,
1324
+ !1
1325
+ );
1326
+ let l = a, c = 0;
1327
+ for (c = 0; c < n.length - 1; ++c) {
1328
+ n[c].apply(this, s, l, !0);
1329
+ const u = s;
1330
+ s = l, l = u;
1331
+ }
1332
+ n[c].apply(this, s, e.outputRenderSurface, t), A.returnTexture(a);
1333
+ }
1334
+ }
1335
+ _calculateFilterBounds(e, t, r, i, n) {
1336
+ var x;
1337
+ const s = this.renderer, a = e.bounds, l = e.filters;
1338
+ let c = 1 / 0, d = 0, u = !0, h = !1, f = !1, m = !0;
1339
+ for (let _ = 0; _ < l.length; _++) {
1340
+ const p = l[_];
1341
+ if (c = Math.min(c, p.resolution === "inherit" ? i : p.resolution), d += p.padding, p.antialias === "off" ? u = !1 : p.antialias === "inherit" && u && (u = r), p.clipToViewport || (m = !1), !!!(p.compatibleRenderers & s.type)) {
1342
+ f = !1;
1343
+ break;
1344
+ }
1345
+ if (p.blendRequired && !(((x = s.backBuffer) == null ? void 0 : x.useBackBuffer) ?? !0)) {
1346
+ ne("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."), f = !1;
1347
+ break;
1348
+ }
1349
+ f = p.enabled || f, h || (h = p.blendRequired);
1350
+ }
1351
+ if (!f) {
1352
+ e.skip = !0;
1353
+ return;
1354
+ }
1355
+ if (m && a.fitBounds(0, t.width / i, 0, t.height / i), a.scale(c).ceil().scale(1 / c).pad((d | 0) * n), !a.isPositive) {
1356
+ e.skip = !0;
1357
+ return;
1358
+ }
1359
+ e.antialias = u, e.resolution = c, e.blendRequired = h;
1360
+ }
1361
+ _popFilterData() {
1362
+ return this._filterStackIndex--, this._filterStack[this._filterStackIndex];
1363
+ }
1364
+ _getPreviousFilterData() {
1365
+ let e, t = this._filterStackIndex - 1;
1366
+ for (; t > 1 && (t--, e = this._filterStack[t], !!e.skip); )
1367
+ ;
1368
+ return e;
1369
+ }
1370
+ _pushFilterData() {
1371
+ let e = this._filterStack[this._filterStackIndex];
1372
+ return e || (e = this._filterStack[this._filterStackIndex] = new qt()), this._filterStackIndex++, e;
1373
+ }
1374
+ }
1375
+ Qe.extension = {
1376
+ type: [
1377
+ w.WebGLSystem,
1378
+ w.WebGPUSystem
1379
+ ],
1380
+ name: "filter"
1381
+ };
1382
+ const Je = class Ze extends me {
1383
+ constructor(...e) {
1384
+ let t = e[0] ?? {};
1385
+ t instanceof Float32Array && (U(O, "use new MeshGeometry({ positions, uvs, indices }) instead"), t = {
1386
+ positions: t,
1387
+ uvs: e[1],
1388
+ indices: e[2]
1389
+ }), t = { ...Ze.defaultOptions, ...t };
1390
+ const r = t.positions || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
1391
+ let i = t.uvs;
1392
+ i || (t.positions ? i = new Float32Array(r.length) : i = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]));
1393
+ const n = t.indices || new Uint32Array([0, 1, 2, 0, 2, 3]), s = t.shrinkBuffersToFit, a = new N({
1394
+ data: r,
1395
+ label: "attribute-mesh-positions",
1396
+ shrinkToFit: s,
1397
+ usage: z.VERTEX | z.COPY_DST
1398
+ }), l = new N({
1399
+ data: i,
1400
+ label: "attribute-mesh-uvs",
1401
+ shrinkToFit: s,
1402
+ usage: z.VERTEX | z.COPY_DST
1403
+ }), c = new N({
1404
+ data: n,
1405
+ label: "index-mesh-buffer",
1406
+ shrinkToFit: s,
1407
+ usage: z.INDEX | z.COPY_DST
1408
+ });
1409
+ super({
1410
+ attributes: {
1411
+ aPosition: {
1412
+ buffer: a,
1413
+ format: "float32x2",
1414
+ stride: 8,
1415
+ offset: 0
1416
+ },
1417
+ aUV: {
1418
+ buffer: l,
1419
+ format: "float32x2",
1420
+ stride: 8,
1421
+ offset: 0
1422
+ }
1423
+ },
1424
+ indexBuffer: c,
1425
+ topology: t.topology
1426
+ }), this.batchMode = "auto";
1427
+ }
1428
+ /** The positions of the mesh. */
1429
+ get positions() {
1430
+ return this.attributes.aPosition.buffer.data;
1431
+ }
1432
+ /**
1433
+ * Set the positions of the mesh.
1434
+ * When setting the positions, its important that the uvs array is at least as long as the positions array.
1435
+ * otherwise the geometry will not be valid.
1436
+ * @param {Float32Array} value - The positions of the mesh.
1437
+ */
1438
+ set positions(e) {
1439
+ this.attributes.aPosition.buffer.data = e;
1440
+ }
1441
+ /** The UVs of the mesh. */
1442
+ get uvs() {
1443
+ return this.attributes.aUV.buffer.data;
1444
+ }
1445
+ /**
1446
+ * Set the UVs of the mesh.
1447
+ * Its important that the uvs array you set is at least as long as the positions array.
1448
+ * otherwise the geometry will not be valid.
1449
+ * @param {Float32Array} value - The UVs of the mesh.
1450
+ */
1451
+ set uvs(e) {
1452
+ this.attributes.aUV.buffer.data = e;
1453
+ }
1454
+ /** The indices of the mesh. */
1455
+ get indices() {
1456
+ return this.indexBuffer.data;
1457
+ }
1458
+ set indices(e) {
1459
+ this.indexBuffer.data = e;
1460
+ }
1461
+ };
1462
+ Je.defaultOptions = {
1463
+ topology: "triangle-list",
1464
+ shrinkBuffersToFit: !1
1465
+ };
1466
+ let ye = Je, E = null, I = null;
1467
+ function Kt(o, e) {
1468
+ E || (E = H.get().createCanvas(256, 128), I = E.getContext("2d", { willReadFrequently: !0 }), I.globalCompositeOperation = "copy", I.globalAlpha = 1), (E.width < o || E.height < e) && (E.width = Se(o), E.height = Se(e));
1469
+ }
1470
+ function Fe(o, e, t) {
1471
+ for (let r = 0, i = 4 * t * e; r < e; ++r, i += 4)
1472
+ if (o[i + 3] !== 0)
1473
+ return !1;
1474
+ return !0;
1475
+ }
1476
+ function Be(o, e, t, r, i) {
1477
+ const n = 4 * e;
1478
+ for (let s = r, a = r * n + 4 * t; s <= i; ++s, a += n)
1479
+ if (o[a + 3] !== 0)
1480
+ return !1;
1481
+ return !0;
1482
+ }
1483
+ function Qt(...o) {
1484
+ let e = o[0];
1485
+ e.canvas || (e = { canvas: o[0], resolution: o[1] });
1486
+ const { canvas: t } = e, r = Math.min(e.resolution ?? 1, 1), i = e.width ?? t.width, n = e.height ?? t.height;
1487
+ let s = e.output;
1488
+ if (Kt(i, n), !I)
1489
+ throw new TypeError("Failed to get canvas 2D context");
1490
+ I.drawImage(
1491
+ t,
1492
+ 0,
1493
+ 0,
1494
+ i,
1495
+ n,
1496
+ 0,
1497
+ 0,
1498
+ i * r,
1499
+ n * r
1500
+ );
1501
+ const l = I.getImageData(0, 0, i, n).data;
1502
+ let c = 0, d = 0, u = i - 1, h = n - 1;
1503
+ for (; d < n && Fe(l, i, d); )
1504
+ ++d;
1505
+ if (d === n)
1506
+ return Z.EMPTY;
1507
+ for (; Fe(l, i, h); )
1508
+ --h;
1509
+ for (; Be(l, i, c, d, h); )
1510
+ ++c;
1511
+ for (; Be(l, i, u, d, h); )
1512
+ --u;
1513
+ return ++u, ++h, I.globalCompositeOperation = "source-over", I.strokeRect(c, d, u - c, h - d), I.globalCompositeOperation = "copy", s ?? (s = new Z()), s.set(c / r, d / r, (u - c) / r, (h - d) / r), s;
1514
+ }
1515
+ const Me = new Z();
1516
+ class Jt {
1517
+ /**
1518
+ * Creates a canvas with the specified text rendered to it.
1519
+ *
1520
+ * Generates a canvas of appropriate size, renders the text with the provided style,
1521
+ * and returns both the canvas/context and a Rectangle representing the text bounds.
1522
+ *
1523
+ * When trim is enabled in the style, the frame will represent the bounds of the
1524
+ * non-transparent pixels, which can be smaller than the full canvas.
1525
+ * @param options - The options for generating the text canvas
1526
+ * @param options.text - The text to render
1527
+ * @param options.style - The style to apply to the text
1528
+ * @param options.resolution - The resolution of the canvas (defaults to 1)
1529
+ * @param options.padding
1530
+ * @returns An object containing the canvas/context and the frame (bounds) of the text
1531
+ */
1532
+ getCanvasAndContext(e) {
1533
+ const { text: t, style: r, resolution: i = 1 } = e, n = r._getFinalPadding(), s = D.measureText(t || " ", r), a = Math.ceil(Math.ceil(Math.max(1, s.width) + n * 2) * i), l = Math.ceil(Math.ceil(Math.max(1, s.height) + n * 2) * i), c = X.getOptimalCanvasAndContext(a, l);
1534
+ this._renderTextToCanvas(t, r, n, i, c);
1535
+ const d = r.trim ? Qt({ canvas: c.canvas, width: a, height: l, resolution: 1, output: Me }) : Me.set(0, 0, a, l);
1536
+ return {
1537
+ canvasAndContext: c,
1538
+ frame: d
1539
+ };
1540
+ }
1541
+ /**
1542
+ * Returns a canvas and context to the pool.
1543
+ *
1544
+ * This should be called when you're done with the canvas to allow reuse
1545
+ * and prevent memory leaks.
1546
+ * @param canvasAndContext - The canvas and context to return to the pool
1547
+ */
1548
+ returnCanvasAndContext(e) {
1549
+ X.returnCanvasAndContext(e);
1550
+ }
1551
+ /**
1552
+ * Renders text to its canvas, and updates its texture.
1553
+ * @param text - The text to render
1554
+ * @param style - The style of the text
1555
+ * @param padding - The padding of the text
1556
+ * @param resolution - The resolution of the text
1557
+ * @param canvasAndContext - The canvas and context to render the text to
1558
+ */
1559
+ _renderTextToCanvas(e, t, r, i, n) {
1560
+ var y, T, S, B;
1561
+ const { canvas: s, context: a } = n, l = re(t), c = D.measureText(e || " ", t), d = c.lines, u = c.lineHeight, h = c.lineWidths, f = c.maxLineWidth, m = c.fontProperties, x = s.height;
1562
+ if (a.resetTransform(), a.scale(i, i), a.textBaseline = t.textBaseline, (y = t._stroke) != null && y.width) {
1563
+ const v = t._stroke;
1564
+ a.lineWidth = v.width, a.miterLimit = v.miterLimit, a.lineJoin = v.join, a.lineCap = v.cap;
1565
+ }
1566
+ a.font = l;
1567
+ let _, p;
1568
+ const b = t.dropShadow ? 2 : 1;
1569
+ for (let v = 0; v < b; ++v) {
1570
+ const F = t.dropShadow && v === 0, M = F ? Math.ceil(Math.max(1, x) + r * 2) : 0, ae = M * i;
1571
+ if (F) {
1572
+ a.fillStyle = "black", a.strokeStyle = "black";
1573
+ const C = t.dropShadow, _t = C.color, bt = C.alpha;
1574
+ a.shadowColor = V.shared.setValue(_t).setAlpha(bt).toRgbaString();
1575
+ const yt = C.blur * i, Te = C.distance * i;
1576
+ a.shadowBlur = yt, a.shadowOffsetX = Math.cos(C.angle) * Te, a.shadowOffsetY = Math.sin(C.angle) * Te + ae;
1577
+ } else {
1578
+ if (a.fillStyle = t._fill ? ie(t._fill, a, c, r * 2) : null, (T = t._stroke) != null && T.width) {
1579
+ const C = t._stroke.width * 0.5 + r * 2;
1580
+ a.strokeStyle = ie(t._stroke, a, c, C);
1581
+ }
1582
+ a.shadowColor = "black";
1583
+ }
1584
+ let L = (u - m.fontSize) / 2;
1585
+ u - m.fontSize < 0 && (L = 0);
1586
+ const $ = ((S = t._stroke) == null ? void 0 : S.width) ?? 0;
1587
+ for (let C = 0; C < d.length; C++)
1588
+ _ = $ / 2, p = $ / 2 + C * u + m.ascent + L, t.align === "right" ? _ += f - h[C] : t.align === "center" && (_ += (f - h[C]) / 2), (B = t._stroke) != null && B.width && this._drawLetterSpacing(
1589
+ d[C],
1590
+ t,
1591
+ n,
1592
+ _ + r,
1593
+ p + r - M,
1594
+ !0
1595
+ ), t._fill !== void 0 && this._drawLetterSpacing(
1596
+ d[C],
1597
+ t,
1598
+ n,
1599
+ _ + r,
1600
+ p + r - M
1601
+ );
1602
+ }
1603
+ }
1604
+ /**
1605
+ * Render the text with letter-spacing.
1606
+ *
1607
+ * This method handles rendering text with the correct letter spacing, using either:
1608
+ * 1. Native letter spacing if supported by the browser
1609
+ * 2. Manual letter spacing calculation if not natively supported
1610
+ *
1611
+ * For manual letter spacing, it calculates the position of each character
1612
+ * based on its width and the desired spacing.
1613
+ * @param text - The text to draw
1614
+ * @param style - The text style to apply
1615
+ * @param canvasAndContext - The canvas and context to draw to
1616
+ * @param x - Horizontal position to draw the text
1617
+ * @param y - Vertical position to draw the text
1618
+ * @param isStroke - Whether to render the stroke (true) or fill (false)
1619
+ * @private
1620
+ */
1621
+ _drawLetterSpacing(e, t, r, i, n, s = !1) {
1622
+ const { context: a } = r, l = t.letterSpacing;
1623
+ let c = !1;
1624
+ if (D.experimentalLetterSpacingSupported && (D.experimentalLetterSpacing ? (a.letterSpacing = `${l}px`, a.textLetterSpacing = `${l}px`, c = !0) : (a.letterSpacing = "0px", a.textLetterSpacing = "0px")), l === 0 || c) {
1625
+ s ? a.strokeText(e, i, n) : a.fillText(e, i, n);
1626
+ return;
1627
+ }
1628
+ let d = i;
1629
+ const u = D.graphemeSegmenter(e);
1630
+ let h = a.measureText(e).width, f = 0;
1631
+ for (let m = 0; m < u.length; ++m) {
1632
+ const x = u[m];
1633
+ s ? a.strokeText(x, d, n) : a.fillText(x, d, n);
1634
+ let _ = "";
1635
+ for (let p = m + 1; p < u.length; ++p)
1636
+ _ += u[p];
1637
+ f = a.measureText(_).width, d += h - f + l, h = f;
1638
+ }
1639
+ }
1640
+ }
1641
+ const le = new Jt(), Re = "http://www.w3.org/2000/svg", Ue = "http://www.w3.org/1999/xhtml";
1642
+ class et {
1643
+ constructor() {
1644
+ this.svgRoot = document.createElementNS(Re, "svg"), this.foreignObject = document.createElementNS(Re, "foreignObject"), this.domElement = document.createElementNS(Ue, "div"), this.styleElement = document.createElementNS(Ue, "style");
1645
+ const { foreignObject: e, svgRoot: t, styleElement: r, domElement: i } = this;
1646
+ e.setAttribute("width", "10000"), e.setAttribute("height", "10000"), e.style.overflow = "hidden", t.appendChild(e), e.appendChild(r), e.appendChild(i), this.image = H.get().createImage();
1647
+ }
1648
+ }
1649
+ let ke;
1650
+ function Zt(o, e, t, r) {
1651
+ r || (r = ke || (ke = new et()));
1652
+ const { domElement: i, styleElement: n, svgRoot: s } = r;
1653
+ i.innerHTML = `<style>${e.cssStyle};</style><div style='padding:0'>${o}</div>`, i.setAttribute("style", "transform-origin: top left; display: inline-block"), t && (n.textContent = t), document.body.appendChild(s);
1654
+ const a = i.getBoundingClientRect();
1655
+ s.remove();
1656
+ const l = e.padding * 2;
1657
+ return {
1658
+ width: a.width - l,
1659
+ height: a.height - l
1660
+ };
1661
+ }
1662
+ class er {
1663
+ constructor() {
1664
+ this.batches = [], this.batched = !1;
1665
+ }
1666
+ destroy() {
1667
+ this.batches.forEach((e) => {
1668
+ te.return(e);
1669
+ }), this.batches.length = 0;
1670
+ }
1671
+ }
1672
+ class tt {
1673
+ constructor(e, t) {
1674
+ this.state = ee.for2d(), this.renderer = e, this._adaptor = t, this.renderer.runners.contextChange.add(this);
1675
+ }
1676
+ contextChange() {
1677
+ this._adaptor.contextChange(this.renderer);
1678
+ }
1679
+ validateRenderable(e) {
1680
+ const t = e.context, r = !!e._gpuData, i = this.renderer.graphicsContext.updateGpuContext(t);
1681
+ return !!(i.isBatchable || r !== i.isBatchable);
1682
+ }
1683
+ addRenderable(e, t) {
1684
+ const r = this.renderer.graphicsContext.updateGpuContext(e.context);
1685
+ e.didViewUpdate && this._rebuild(e), r.isBatchable ? this._addToBatcher(e, t) : (this.renderer.renderPipes.batch.break(t), t.add(e));
1686
+ }
1687
+ updateRenderable(e) {
1688
+ const r = this._getGpuDataForRenderable(e).batches;
1689
+ for (let i = 0; i < r.length; i++) {
1690
+ const n = r[i];
1691
+ n._batcher.updateElement(n);
1692
+ }
1693
+ }
1694
+ execute(e) {
1695
+ if (!e.isRenderable)
1696
+ return;
1697
+ const t = this.renderer, r = e.context;
1698
+ if (!t.graphicsContext.getGpuContext(r).batches.length)
1699
+ return;
1700
+ const n = r.customShader || this._adaptor.shader;
1701
+ this.state.blendMode = e.groupBlendMode;
1702
+ const s = n.resources.localUniforms.uniforms;
1703
+ s.uTransformMatrix = e.groupTransform, s.uRound = t._roundPixels | e._roundPixels, se(
1704
+ e.groupColorAlpha,
1705
+ s.uColor,
1706
+ 0
1707
+ ), this._adaptor.execute(this, e);
1708
+ }
1709
+ _rebuild(e) {
1710
+ const t = this._getGpuDataForRenderable(e), r = this.renderer.graphicsContext.updateGpuContext(e.context);
1711
+ t.destroy(), r.isBatchable && this._updateBatchesForRenderable(e, t);
1712
+ }
1713
+ _addToBatcher(e, t) {
1714
+ const r = this.renderer.renderPipes.batch, i = this._getGpuDataForRenderable(e).batches;
1715
+ for (let n = 0; n < i.length; n++) {
1716
+ const s = i[n];
1717
+ r.addToBatch(s, t);
1718
+ }
1719
+ }
1720
+ _getGpuDataForRenderable(e) {
1721
+ return e._gpuData[this.renderer.uid] || this._initGpuDataForRenderable(e);
1722
+ }
1723
+ _initGpuDataForRenderable(e) {
1724
+ const t = new er();
1725
+ return e._gpuData[this.renderer.uid] = t, t;
1726
+ }
1727
+ _updateBatchesForRenderable(e, t) {
1728
+ const r = e.context, i = this.renderer.graphicsContext.getGpuContext(r), n = this.renderer._roundPixels | e._roundPixels;
1729
+ t.batches = i.batches.map((s) => {
1730
+ const a = te.get(Pt);
1731
+ return s.copyTo(a), a.renderable = e, a.roundPixels = n, a;
1732
+ });
1733
+ }
1734
+ destroy() {
1735
+ this.renderer = null, this._adaptor.destroy(), this._adaptor = null, this.state = null;
1736
+ }
1737
+ }
1738
+ tt.extension = {
1739
+ type: [
1740
+ w.WebGLPipes,
1741
+ w.WebGPUPipes,
1742
+ w.CanvasPipes
1743
+ ],
1744
+ name: "graphics"
1745
+ };
1746
+ const rt = class it extends ye {
1747
+ constructor(...e) {
1748
+ super({});
1749
+ let t = e[0] ?? {};
1750
+ typeof t == "number" && (U(O, "PlaneGeometry constructor changed please use { width, height, verticesX, verticesY } instead"), t = {
1751
+ width: t,
1752
+ height: e[1],
1753
+ verticesX: e[2],
1754
+ verticesY: e[3]
1755
+ }), this.build(t);
1756
+ }
1757
+ /**
1758
+ * Refreshes plane coordinates
1759
+ * @param options - Options to be applied to plane geometry
1760
+ */
1761
+ build(e) {
1762
+ e = { ...it.defaultOptions, ...e }, this.verticesX = this.verticesX ?? e.verticesX, this.verticesY = this.verticesY ?? e.verticesY, this.width = this.width ?? e.width, this.height = this.height ?? e.height;
1763
+ const t = this.verticesX * this.verticesY, r = [], i = [], n = [], s = this.verticesX - 1, a = this.verticesY - 1, l = this.width / s, c = this.height / a;
1764
+ for (let u = 0; u < t; u++) {
1765
+ const h = u % this.verticesX, f = u / this.verticesX | 0;
1766
+ r.push(h * l, f * c), i.push(h / s, f / a);
1767
+ }
1768
+ const d = s * a;
1769
+ for (let u = 0; u < d; u++) {
1770
+ const h = u % s, f = u / s | 0, m = f * this.verticesX + h, x = f * this.verticesX + h + 1, _ = (f + 1) * this.verticesX + h, p = (f + 1) * this.verticesX + h + 1;
1771
+ n.push(
1772
+ m,
1773
+ x,
1774
+ _,
1775
+ x,
1776
+ p,
1777
+ _
1778
+ );
1779
+ }
1780
+ this.buffers[0].data = new Float32Array(r), this.buffers[1].data = new Float32Array(i), this.indexBuffer.data = new Uint32Array(n), this.buffers[0].update(), this.buffers[1].update(), this.indexBuffer.update();
1781
+ }
1782
+ };
1783
+ rt.defaultOptions = {
1784
+ width: 100,
1785
+ height: 100,
1786
+ verticesX: 10,
1787
+ verticesY: 10
1788
+ };
1789
+ let tr = rt;
1790
+ class we {
1791
+ constructor() {
1792
+ this.batcherName = "default", this.packAsQuad = !1, this.indexOffset = 0, this.attributeOffset = 0, this.roundPixels = 0, this._batcher = null, this._batch = null, this._textureMatrixUpdateId = -1, this._uvUpdateId = -1;
1793
+ }
1794
+ get blendMode() {
1795
+ return this.renderable.groupBlendMode;
1796
+ }
1797
+ get topology() {
1798
+ return this._topology || this.geometry.topology;
1799
+ }
1800
+ set topology(e) {
1801
+ this._topology = e;
1802
+ }
1803
+ reset() {
1804
+ this.renderable = null, this.texture = null, this._batcher = null, this._batch = null, this.geometry = null, this._uvUpdateId = -1, this._textureMatrixUpdateId = -1;
1805
+ }
1806
+ /**
1807
+ * Sets the texture for the batchable mesh.
1808
+ * As it does so, it resets the texture matrix update ID.
1809
+ * this is to ensure that the texture matrix is recalculated when the uvs are referenced
1810
+ * @param value - The texture to set.
1811
+ */
1812
+ setTexture(e) {
1813
+ this.texture !== e && (this.texture = e, this._textureMatrixUpdateId = -1);
1814
+ }
1815
+ get uvs() {
1816
+ const t = this.geometry.getBuffer("aUV"), r = t.data;
1817
+ let i = r;
1818
+ const n = this.texture.textureMatrix;
1819
+ return n.isSimple || (i = this._transformedUvs, (this._textureMatrixUpdateId !== n._updateID || this._uvUpdateId !== t._updateID) && ((!i || i.length < r.length) && (i = this._transformedUvs = new Float32Array(r.length)), this._textureMatrixUpdateId = n._updateID, this._uvUpdateId = t._updateID, n.multiplyUvs(r, i))), i;
1820
+ }
1821
+ get positions() {
1822
+ return this.geometry.positions;
1823
+ }
1824
+ get indices() {
1825
+ return this.geometry.indices;
1826
+ }
1827
+ get color() {
1828
+ return this.renderable.groupColorAlpha;
1829
+ }
1830
+ get groupTransform() {
1831
+ return this.renderable.groupTransform;
1832
+ }
1833
+ get attributeSize() {
1834
+ return this.geometry.positions.length / 2;
1835
+ }
1836
+ get indexSize() {
1837
+ return this.geometry.indices.length;
1838
+ }
1839
+ }
1840
+ class Ge {
1841
+ destroy() {
1842
+ }
1843
+ }
1844
+ class nt {
1845
+ constructor(e, t) {
1846
+ this.localUniforms = new Y({
1847
+ uTransformMatrix: { value: new k(), type: "mat3x3<f32>" },
1848
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
1849
+ uRound: { value: 0, type: "f32" }
1850
+ }), this.localUniformsBindGroup = new Le({
1851
+ 0: this.localUniforms
1852
+ }), this.renderer = e, this._adaptor = t, this._adaptor.init();
1853
+ }
1854
+ validateRenderable(e) {
1855
+ const t = this._getMeshData(e), r = t.batched, i = e.batched;
1856
+ if (t.batched = i, r !== i)
1857
+ return !0;
1858
+ if (i) {
1859
+ const n = e._geometry;
1860
+ if (n.indices.length !== t.indexSize || n.positions.length !== t.vertexSize)
1861
+ return t.indexSize = n.indices.length, t.vertexSize = n.positions.length, !0;
1862
+ const s = this._getBatchableMesh(e);
1863
+ return s.texture.uid !== e._texture.uid && (s._textureMatrixUpdateId = -1), !s._batcher.checkAndUpdateTexture(
1864
+ s,
1865
+ e._texture
1866
+ );
1867
+ }
1868
+ return !1;
1869
+ }
1870
+ addRenderable(e, t) {
1871
+ var n, s;
1872
+ const r = this.renderer.renderPipes.batch, i = this._getMeshData(e);
1873
+ if (e.didViewUpdate && (i.indexSize = (n = e._geometry.indices) == null ? void 0 : n.length, i.vertexSize = (s = e._geometry.positions) == null ? void 0 : s.length), i.batched) {
1874
+ const a = this._getBatchableMesh(e);
1875
+ a.setTexture(e._texture), a.geometry = e._geometry, r.addToBatch(a, t);
1876
+ } else
1877
+ r.break(t), t.add(e);
1878
+ }
1879
+ updateRenderable(e) {
1880
+ if (e.batched) {
1881
+ const t = this._getBatchableMesh(e);
1882
+ t.setTexture(e._texture), t.geometry = e._geometry, t._batcher.updateElement(t);
1883
+ }
1884
+ }
1885
+ execute(e) {
1886
+ if (!e.isRenderable)
1887
+ return;
1888
+ e.state.blendMode = _e(e.groupBlendMode, e.texture._source);
1889
+ const t = this.localUniforms;
1890
+ t.uniforms.uTransformMatrix = e.groupTransform, t.uniforms.uRound = this.renderer._roundPixels | e._roundPixels, t.update(), se(
1891
+ e.groupColorAlpha,
1892
+ t.uniforms.uColor,
1893
+ 0
1894
+ ), this._adaptor.execute(this, e);
1895
+ }
1896
+ _getMeshData(e) {
1897
+ var t, r;
1898
+ return (t = e._gpuData)[r = this.renderer.uid] || (t[r] = new Ge()), e._gpuData[this.renderer.uid].meshData || this._initMeshData(e);
1899
+ }
1900
+ _initMeshData(e) {
1901
+ return e._gpuData[this.renderer.uid].meshData = {
1902
+ batched: e.batched,
1903
+ indexSize: 0,
1904
+ vertexSize: 0
1905
+ }, e._gpuData[this.renderer.uid].meshData;
1906
+ }
1907
+ _getBatchableMesh(e) {
1908
+ var t, r;
1909
+ return (t = e._gpuData)[r = this.renderer.uid] || (t[r] = new Ge()), e._gpuData[this.renderer.uid].batchableMesh || this._initBatchableMesh(e);
1910
+ }
1911
+ _initBatchableMesh(e) {
1912
+ const t = new we();
1913
+ return t.renderable = e, t.setTexture(e._texture), t.transform = e.groupTransform, t.roundPixels = this.renderer._roundPixels | e._roundPixels, e._gpuData[this.renderer.uid].batchableMesh = t, t;
1914
+ }
1915
+ destroy() {
1916
+ this.localUniforms = null, this.localUniformsBindGroup = null, this._adaptor.destroy(), this._adaptor = null, this.renderer = null;
1917
+ }
1918
+ }
1919
+ nt.extension = {
1920
+ type: [
1921
+ w.WebGLPipes,
1922
+ w.WebGPUPipes,
1923
+ w.CanvasPipes
1924
+ ],
1925
+ name: "mesh"
1926
+ };
1927
+ class rr {
1928
+ execute(e, t) {
1929
+ const r = e.state, i = e.renderer, n = t.shader || e.defaultShader;
1930
+ n.resources.uTexture = t.texture._source, n.resources.uniforms = e.localUniforms;
1931
+ const s = i.gl, a = e.getBuffers(t);
1932
+ i.shader.bind(n), i.state.set(r), i.geometry.bind(a.geometry, n.glProgram);
1933
+ const c = a.geometry.indexBuffer.data.BYTES_PER_ELEMENT === 2 ? s.UNSIGNED_SHORT : s.UNSIGNED_INT;
1934
+ s.drawElements(s.TRIANGLES, t.particleChildren.length * 6, c, 0);
1935
+ }
1936
+ }
1937
+ class ir {
1938
+ execute(e, t) {
1939
+ const r = e.renderer, i = t.shader || e.defaultShader;
1940
+ i.groups[0] = r.renderPipes.uniformBatch.getUniformBindGroup(e.localUniforms, !0), i.groups[1] = r.texture.getTextureBindGroup(t.texture);
1941
+ const n = e.state, s = e.getBuffers(t);
1942
+ r.encoder.draw({
1943
+ geometry: s.geometry,
1944
+ shader: t.shader || e.defaultShader,
1945
+ state: n,
1946
+ size: t.particleChildren.length * 6
1947
+ });
1948
+ }
1949
+ }
1950
+ function Ae(o, e = null) {
1951
+ const t = o * 6;
1952
+ if (t > 65535 ? e || (e = new Uint32Array(t)) : e || (e = new Uint16Array(t)), e.length !== t)
1953
+ throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${t}`);
1954
+ for (let r = 0, i = 0; r < t; r += 6, i += 4)
1955
+ e[r + 0] = i + 0, e[r + 1] = i + 1, e[r + 2] = i + 2, e[r + 3] = i + 0, e[r + 4] = i + 2, e[r + 5] = i + 3;
1956
+ return e;
1957
+ }
1958
+ function nr(o) {
1959
+ return {
1960
+ dynamicUpdate: ze(o, !0),
1961
+ staticUpdate: ze(o, !1)
1962
+ };
1963
+ }
1964
+ function ze(o, e) {
1965
+ const t = [];
1966
+ t.push(`
1967
+
1968
+ var index = 0;
1969
+
1970
+ for (let i = 0; i < ps.length; ++i)
1971
+ {
1972
+ const p = ps[i];
1973
+
1974
+ `);
1975
+ let r = 0;
1976
+ for (const n in o) {
1977
+ const s = o[n];
1978
+ if (e !== s.dynamic)
1979
+ continue;
1980
+ t.push(`offset = index + ${r}`), t.push(s.code);
1981
+ const a = pe(s.format);
1982
+ r += a.stride / 4;
1983
+ }
1984
+ t.push(`
1985
+ index += stride * 4;
1986
+ }
1987
+ `), t.unshift(`
1988
+ var stride = ${r};
1989
+ `);
1990
+ const i = t.join(`
1991
+ `);
1992
+ return new Function("ps", "f32v", "u32v", i);
1993
+ }
1994
+ class sr {
1995
+ constructor(e) {
1996
+ this._size = 0, this._generateParticleUpdateCache = {};
1997
+ const t = this._size = e.size ?? 1e3, r = e.properties;
1998
+ let i = 0, n = 0;
1999
+ for (const d in r) {
2000
+ const u = r[d], h = pe(u.format);
2001
+ u.dynamic ? n += h.stride : i += h.stride;
2002
+ }
2003
+ this._dynamicStride = n / 4, this._staticStride = i / 4, this.staticAttributeBuffer = new K(t * 4 * i), this.dynamicAttributeBuffer = new K(t * 4 * n), this.indexBuffer = Ae(t);
2004
+ const s = new me();
2005
+ let a = 0, l = 0;
2006
+ this._staticBuffer = new N({
2007
+ data: new Float32Array(1),
2008
+ label: "static-particle-buffer",
2009
+ shrinkToFit: !1,
2010
+ usage: z.VERTEX | z.COPY_DST
2011
+ }), this._dynamicBuffer = new N({
2012
+ data: new Float32Array(1),
2013
+ label: "dynamic-particle-buffer",
2014
+ shrinkToFit: !1,
2015
+ usage: z.VERTEX | z.COPY_DST
2016
+ });
2017
+ for (const d in r) {
2018
+ const u = r[d], h = pe(u.format);
2019
+ u.dynamic ? (s.addAttribute(u.attributeName, {
2020
+ buffer: this._dynamicBuffer,
2021
+ stride: this._dynamicStride * 4,
2022
+ offset: a * 4,
2023
+ format: u.format
2024
+ }), a += h.size) : (s.addAttribute(u.attributeName, {
2025
+ buffer: this._staticBuffer,
2026
+ stride: this._staticStride * 4,
2027
+ offset: l * 4,
2028
+ format: u.format
2029
+ }), l += h.size);
2030
+ }
2031
+ s.addIndex(this.indexBuffer);
2032
+ const c = this.getParticleUpdate(r);
2033
+ this._dynamicUpload = c.dynamicUpdate, this._staticUpload = c.staticUpdate, this.geometry = s;
2034
+ }
2035
+ getParticleUpdate(e) {
2036
+ const t = ar(e);
2037
+ return this._generateParticleUpdateCache[t] ? this._generateParticleUpdateCache[t] : (this._generateParticleUpdateCache[t] = this.generateParticleUpdate(e), this._generateParticleUpdateCache[t]);
2038
+ }
2039
+ generateParticleUpdate(e) {
2040
+ return nr(e);
2041
+ }
2042
+ update(e, t) {
2043
+ e.length > this._size && (t = !0, this._size = Math.max(e.length, this._size * 1.5 | 0), this.staticAttributeBuffer = new K(this._size * this._staticStride * 4 * 4), this.dynamicAttributeBuffer = new K(this._size * this._dynamicStride * 4 * 4), this.indexBuffer = Ae(this._size), this.geometry.indexBuffer.setDataWithSize(
2044
+ this.indexBuffer,
2045
+ this.indexBuffer.byteLength,
2046
+ !0
2047
+ ));
2048
+ const r = this.dynamicAttributeBuffer;
2049
+ if (this._dynamicUpload(e, r.float32View, r.uint32View), this._dynamicBuffer.setDataWithSize(
2050
+ this.dynamicAttributeBuffer.float32View,
2051
+ e.length * this._dynamicStride * 4,
2052
+ !0
2053
+ ), t) {
2054
+ const i = this.staticAttributeBuffer;
2055
+ this._staticUpload(e, i.float32View, i.uint32View), this._staticBuffer.setDataWithSize(
2056
+ i.float32View,
2057
+ e.length * this._staticStride * 4,
2058
+ !0
2059
+ );
2060
+ }
2061
+ }
2062
+ destroy() {
2063
+ this._staticBuffer.destroy(), this._dynamicBuffer.destroy(), this.geometry.destroy();
2064
+ }
2065
+ }
2066
+ function ar(o) {
2067
+ const e = [];
2068
+ for (const t in o) {
2069
+ const r = o[t];
2070
+ e.push(t, r.code, r.dynamic ? "d" : "s");
2071
+ }
2072
+ return e.join("_");
2073
+ }
2074
+ var or = `varying vec2 vUV;
2075
+ varying vec4 vColor;
2076
+
2077
+ uniform sampler2D uTexture;
2078
+
2079
+ void main(void){
2080
+ vec4 color = texture2D(uTexture, vUV) * vColor;
2081
+ gl_FragColor = color;
2082
+ }`, lr = `attribute vec2 aVertex;
2083
+ attribute vec2 aUV;
2084
+ attribute vec4 aColor;
2085
+
2086
+ attribute vec2 aPosition;
2087
+ attribute float aRotation;
2088
+
2089
+ uniform mat3 uTranslationMatrix;
2090
+ uniform float uRound;
2091
+ uniform vec2 uResolution;
2092
+ uniform vec4 uColor;
2093
+
2094
+ varying vec2 vUV;
2095
+ varying vec4 vColor;
2096
+
2097
+ vec2 roundPixels(vec2 position, vec2 targetSize)
2098
+ {
2099
+ return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
2100
+ }
2101
+
2102
+ void main(void){
2103
+ float cosRotation = cos(aRotation);
2104
+ float sinRotation = sin(aRotation);
2105
+ float x = aVertex.x * cosRotation - aVertex.y * sinRotation;
2106
+ float y = aVertex.x * sinRotation + aVertex.y * cosRotation;
2107
+
2108
+ vec2 v = vec2(x, y);
2109
+ v = v + aPosition;
2110
+
2111
+ gl_Position = vec4((uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
2112
+
2113
+ if(uRound == 1.0)
2114
+ {
2115
+ gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
2116
+ }
2117
+
2118
+ vUV = aUV;
2119
+ vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uColor;
2120
+ }
2121
+ `, De = `
2122
+ struct ParticleUniforms {
2123
+ uProjectionMatrix:mat3x3<f32>,
2124
+ uColor:vec4<f32>,
2125
+ uResolution:vec2<f32>,
2126
+ uRoundPixels:f32,
2127
+ };
2128
+
2129
+ @group(0) @binding(0) var<uniform> uniforms: ParticleUniforms;
2130
+
2131
+ @group(1) @binding(0) var uTexture: texture_2d<f32>;
2132
+ @group(1) @binding(1) var uSampler : sampler;
2133
+
2134
+ struct VSOutput {
2135
+ @builtin(position) position: vec4<f32>,
2136
+ @location(0) uv : vec2<f32>,
2137
+ @location(1) color : vec4<f32>,
2138
+ };
2139
+ @vertex
2140
+ fn mainVertex(
2141
+ @location(0) aVertex: vec2<f32>,
2142
+ @location(1) aPosition: vec2<f32>,
2143
+ @location(2) aUV: vec2<f32>,
2144
+ @location(3) aColor: vec4<f32>,
2145
+ @location(4) aRotation: f32,
2146
+ ) -> VSOutput {
2147
+
2148
+ let v = vec2(
2149
+ aVertex.x * cos(aRotation) - aVertex.y * sin(aRotation),
2150
+ aVertex.x * sin(aRotation) + aVertex.y * cos(aRotation)
2151
+ ) + aPosition;
2152
+
2153
+ let position = vec4((uniforms.uProjectionMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
2154
+
2155
+ let vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uniforms.uColor;
2156
+
2157
+ return VSOutput(
2158
+ position,
2159
+ aUV,
2160
+ vColor,
2161
+ );
2162
+ }
2163
+
2164
+ @fragment
2165
+ fn mainFragment(
2166
+ @location(0) uv: vec2<f32>,
2167
+ @location(1) color: vec4<f32>,
2168
+ @builtin(position) position: vec4<f32>,
2169
+ ) -> @location(0) vec4<f32> {
2170
+
2171
+ var sample = textureSample(uTexture, uSampler, uv) * color;
2172
+
2173
+ return sample;
2174
+ }`;
2175
+ class cr extends be {
2176
+ constructor() {
2177
+ const e = Ft.from({
2178
+ vertex: lr,
2179
+ fragment: or
2180
+ }), t = Bt.from({
2181
+ fragment: {
2182
+ source: De,
2183
+ entryPoint: "mainFragment"
2184
+ },
2185
+ vertex: {
2186
+ source: De,
2187
+ entryPoint: "mainVertex"
2188
+ }
2189
+ });
2190
+ super({
2191
+ glProgram: e,
2192
+ gpuProgram: t,
2193
+ resources: {
2194
+ // this will be replaced with the texture from the particle container
2195
+ uTexture: R.WHITE.source,
2196
+ // this will be replaced with the texture style from the particle container
2197
+ uSampler: new j({}),
2198
+ // this will be replaced with the local uniforms from the particle container
2199
+ uniforms: {
2200
+ uTranslationMatrix: { value: new k(), type: "mat3x3<f32>" },
2201
+ uColor: { value: new V(16777215), type: "vec4<f32>" },
2202
+ uRound: { value: 1, type: "f32" },
2203
+ uResolution: { value: [0, 0], type: "vec2<f32>" }
2204
+ }
2205
+ }
2206
+ });
2207
+ }
2208
+ }
2209
+ class st {
2210
+ /**
2211
+ * @param renderer - The renderer this sprite batch works for.
2212
+ * @param adaptor
2213
+ */
2214
+ constructor(e, t) {
2215
+ this.state = ee.for2d(), this.localUniforms = new Y({
2216
+ uTranslationMatrix: { value: new k(), type: "mat3x3<f32>" },
2217
+ uColor: { value: new Float32Array(4), type: "vec4<f32>" },
2218
+ uRound: { value: 1, type: "f32" },
2219
+ uResolution: { value: [0, 0], type: "vec2<f32>" }
2220
+ }), this.renderer = e, this.adaptor = t, this.defaultShader = new cr(), this.state = ee.for2d();
2221
+ }
2222
+ validateRenderable(e) {
2223
+ return !1;
2224
+ }
2225
+ addRenderable(e, t) {
2226
+ this.renderer.renderPipes.batch.break(t), t.add(e);
2227
+ }
2228
+ getBuffers(e) {
2229
+ return e._gpuData[this.renderer.uid] || this._initBuffer(e);
2230
+ }
2231
+ _initBuffer(e) {
2232
+ return e._gpuData[this.renderer.uid] = new sr({
2233
+ size: e.particleChildren.length,
2234
+ properties: e._properties
2235
+ }), e._gpuData[this.renderer.uid];
2236
+ }
2237
+ updateRenderable(e) {
2238
+ }
2239
+ execute(e) {
2240
+ const t = e.particleChildren;
2241
+ if (t.length === 0)
2242
+ return;
2243
+ const r = this.renderer, i = this.getBuffers(e);
2244
+ e.texture || (e.texture = t[0].texture);
2245
+ const n = this.state;
2246
+ i.update(t, e._childrenDirty), e._childrenDirty = !1, n.blendMode = _e(e.blendMode, e.texture._source);
2247
+ const s = this.localUniforms.uniforms, a = s.uTranslationMatrix;
2248
+ e.worldTransform.copyTo(a), a.prepend(r.globalUniforms.globalUniformData.projectionMatrix), s.uResolution = r.globalUniforms.globalUniformData.resolution, s.uRound = r._roundPixels | e._roundPixels, se(
2249
+ e.groupColorAlpha,
2250
+ s.uColor,
2251
+ 0
2252
+ ), this.adaptor.execute(this, e);
2253
+ }
2254
+ /** Destroys the ParticleRenderer. */
2255
+ destroy() {
2256
+ this.defaultShader && (this.defaultShader.destroy(), this.defaultShader = null);
2257
+ }
2258
+ }
2259
+ class at extends st {
2260
+ constructor(e) {
2261
+ super(e, new rr());
2262
+ }
2263
+ }
2264
+ at.extension = {
2265
+ type: [
2266
+ w.WebGLPipes
2267
+ ],
2268
+ name: "particle"
2269
+ };
2270
+ class ot extends st {
2271
+ constructor(e) {
2272
+ super(e, new ir());
2273
+ }
2274
+ }
2275
+ ot.extension = {
2276
+ type: [
2277
+ w.WebGPUPipes
2278
+ ],
2279
+ name: "particle"
2280
+ };
2281
+ const lt = class ct extends tr {
2282
+ constructor(e = {}) {
2283
+ e = { ...ct.defaultOptions, ...e }, super({
2284
+ width: e.width,
2285
+ height: e.height,
2286
+ verticesX: 4,
2287
+ verticesY: 4
2288
+ }), this.update(e);
2289
+ }
2290
+ /**
2291
+ * Updates the NineSliceGeometry with the options.
2292
+ * @param options - The options of the NineSliceGeometry.
2293
+ */
2294
+ update(e) {
2295
+ var t, r;
2296
+ this.width = e.width ?? this.width, this.height = e.height ?? this.height, this._originalWidth = e.originalWidth ?? this._originalWidth, this._originalHeight = e.originalHeight ?? this._originalHeight, this._leftWidth = e.leftWidth ?? this._leftWidth, this._rightWidth = e.rightWidth ?? this._rightWidth, this._topHeight = e.topHeight ?? this._topHeight, this._bottomHeight = e.bottomHeight ?? this._bottomHeight, this._anchorX = (t = e.anchor) == null ? void 0 : t.x, this._anchorY = (r = e.anchor) == null ? void 0 : r.y, this.updateUvs(), this.updatePositions();
2297
+ }
2298
+ /** Updates the positions of the vertices. */
2299
+ updatePositions() {
2300
+ const e = this.positions, {
2301
+ width: t,
2302
+ height: r,
2303
+ _leftWidth: i,
2304
+ _rightWidth: n,
2305
+ _topHeight: s,
2306
+ _bottomHeight: a,
2307
+ _anchorX: l,
2308
+ _anchorY: c
2309
+ } = this, d = i + n, u = t > d ? 1 : t / d, h = s + a, f = r > h ? 1 : r / h, m = Math.min(u, f), x = l * t, _ = c * r;
2310
+ e[0] = e[8] = e[16] = e[24] = -x, e[2] = e[10] = e[18] = e[26] = i * m - x, e[4] = e[12] = e[20] = e[28] = t - n * m - x, e[6] = e[14] = e[22] = e[30] = t - x, e[1] = e[3] = e[5] = e[7] = -_, e[9] = e[11] = e[13] = e[15] = s * m - _, e[17] = e[19] = e[21] = e[23] = r - a * m - _, e[25] = e[27] = e[29] = e[31] = r - _, this.getBuffer("aPosition").update();
2311
+ }
2312
+ /** Updates the UVs of the vertices. */
2313
+ updateUvs() {
2314
+ const e = this.uvs;
2315
+ e[0] = e[8] = e[16] = e[24] = 0, e[1] = e[3] = e[5] = e[7] = 0, e[6] = e[14] = e[22] = e[30] = 1, e[25] = e[27] = e[29] = e[31] = 1;
2316
+ const t = 1 / this._originalWidth, r = 1 / this._originalHeight;
2317
+ e[2] = e[10] = e[18] = e[26] = t * this._leftWidth, e[9] = e[11] = e[13] = e[15] = r * this._topHeight, e[4] = e[12] = e[20] = e[28] = 1 - t * this._rightWidth, e[17] = e[19] = e[21] = e[23] = 1 - r * this._bottomHeight, this.getBuffer("aUV").update();
2318
+ }
2319
+ };
2320
+ lt.defaultOptions = {
2321
+ /** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
2322
+ width: 100,
2323
+ /** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
2324
+ height: 100,
2325
+ /** The width of the left column. */
2326
+ leftWidth: 10,
2327
+ /** The height of the top row. */
2328
+ topHeight: 10,
2329
+ /** The width of the right column. */
2330
+ rightWidth: 10,
2331
+ /** The height of the bottom row. */
2332
+ bottomHeight: 10,
2333
+ /** The original width of the texture */
2334
+ originalWidth: 100,
2335
+ /** The original height of the texture */
2336
+ originalHeight: 100
2337
+ };
2338
+ let ur = lt;
2339
+ class dr extends we {
2340
+ constructor() {
2341
+ super(), this.geometry = new ur();
2342
+ }
2343
+ destroy() {
2344
+ this.geometry.destroy();
2345
+ }
2346
+ }
2347
+ class ut {
2348
+ constructor(e) {
2349
+ this._renderer = e;
2350
+ }
2351
+ addRenderable(e, t) {
2352
+ const r = this._getGpuSprite(e);
2353
+ e.didViewUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r, t);
2354
+ }
2355
+ updateRenderable(e) {
2356
+ const t = this._getGpuSprite(e);
2357
+ e.didViewUpdate && this._updateBatchableSprite(e, t), t._batcher.updateElement(t);
2358
+ }
2359
+ validateRenderable(e) {
2360
+ const t = this._getGpuSprite(e);
2361
+ return !t._batcher.checkAndUpdateTexture(
2362
+ t,
2363
+ e._texture
2364
+ );
2365
+ }
2366
+ _updateBatchableSprite(e, t) {
2367
+ t.geometry.update(e), t.setTexture(e._texture);
2368
+ }
2369
+ _getGpuSprite(e) {
2370
+ return e._gpuData[this._renderer.uid] || this._initGPUSprite(e);
2371
+ }
2372
+ _initGPUSprite(e) {
2373
+ const t = e._gpuData[this._renderer.uid] = new dr(), r = t;
2374
+ return r.renderable = e, r.transform = e.groupTransform, r.texture = e._texture, r.roundPixels = this._renderer._roundPixels | e._roundPixels, e.didViewUpdate || this._updateBatchableSprite(e, r), t;
2375
+ }
2376
+ destroy() {
2377
+ this._renderer = null;
2378
+ }
2379
+ }
2380
+ ut.extension = {
2381
+ type: [
2382
+ w.WebGLPipes,
2383
+ w.WebGPUPipes,
2384
+ w.CanvasPipes
2385
+ ],
2386
+ name: "nineSliceSprite"
2387
+ };
2388
+ const hr = {
2389
+ name: "tiling-bit",
2390
+ vertex: {
2391
+ header: (
2392
+ /* wgsl */
2393
+ `
2394
+ struct TilingUniforms {
2395
+ uMapCoord:mat3x3<f32>,
2396
+ uClampFrame:vec4<f32>,
2397
+ uClampOffset:vec2<f32>,
2398
+ uTextureTransform:mat3x3<f32>,
2399
+ uSizeAnchor:vec4<f32>
2400
+ };
2401
+
2402
+ @group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
2403
+ @group(2) @binding(1) var uTexture: texture_2d<f32>;
2404
+ @group(2) @binding(2) var uSampler: sampler;
2405
+ `
2406
+ ),
2407
+ main: (
2408
+ /* wgsl */
2409
+ `
2410
+ uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy;
2411
+
2412
+ position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy;
2413
+ `
2414
+ )
2415
+ },
2416
+ fragment: {
2417
+ header: (
2418
+ /* wgsl */
2419
+ `
2420
+ struct TilingUniforms {
2421
+ uMapCoord:mat3x3<f32>,
2422
+ uClampFrame:vec4<f32>,
2423
+ uClampOffset:vec2<f32>,
2424
+ uTextureTransform:mat3x3<f32>,
2425
+ uSizeAnchor:vec4<f32>
2426
+ };
2427
+
2428
+ @group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
2429
+ @group(2) @binding(1) var uTexture: texture_2d<f32>;
2430
+ @group(2) @binding(2) var uSampler: sampler;
2431
+ `
2432
+ ),
2433
+ main: (
2434
+ /* wgsl */
2435
+ `
2436
+
2437
+ var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV);
2438
+ coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy;
2439
+ var unclamped = coord;
2440
+ coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw);
2441
+
2442
+ var bias = 0.;
2443
+
2444
+ if(unclamped.x == coord.x && unclamped.y == coord.y)
2445
+ {
2446
+ bias = -32.;
2447
+ }
2448
+
2449
+ outColor = textureSampleBias(uTexture, uSampler, coord, bias);
2450
+ `
2451
+ )
2452
+ }
2453
+ }, fr = {
2454
+ name: "tiling-bit",
2455
+ vertex: {
2456
+ header: (
2457
+ /* glsl */
2458
+ `
2459
+ uniform mat3 uTextureTransform;
2460
+ uniform vec4 uSizeAnchor;
2461
+
2462
+ `
2463
+ ),
2464
+ main: (
2465
+ /* glsl */
2466
+ `
2467
+ uv = (uTextureTransform * vec3(aUV, 1.0)).xy;
2468
+
2469
+ position = (position - uSizeAnchor.zw) * uSizeAnchor.xy;
2470
+ `
2471
+ )
2472
+ },
2473
+ fragment: {
2474
+ header: (
2475
+ /* glsl */
2476
+ `
2477
+ uniform sampler2D uTexture;
2478
+ uniform mat3 uMapCoord;
2479
+ uniform vec4 uClampFrame;
2480
+ uniform vec2 uClampOffset;
2481
+ `
2482
+ ),
2483
+ main: (
2484
+ /* glsl */
2485
+ `
2486
+
2487
+ vec2 coord = vUV + ceil(uClampOffset - vUV);
2488
+ coord = (uMapCoord * vec3(coord, 1.0)).xy;
2489
+ vec2 unclamped = coord;
2490
+ coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
2491
+
2492
+ outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0
2493
+
2494
+ `
2495
+ )
2496
+ }
2497
+ };
2498
+ let ce, ue;
2499
+ class pr extends be {
2500
+ constructor() {
2501
+ ce ?? (ce = Oe({
2502
+ name: "tiling-sprite-shader",
2503
+ bits: [
2504
+ Wt,
2505
+ hr,
2506
+ Ee
2507
+ ]
2508
+ })), ue ?? (ue = He({
2509
+ name: "tiling-sprite-shader",
2510
+ bits: [
2511
+ Lt,
2512
+ fr,
2513
+ Ve
2514
+ ]
2515
+ }));
2516
+ const e = new Y({
2517
+ uMapCoord: { value: new k(), type: "mat3x3<f32>" },
2518
+ uClampFrame: { value: new Float32Array([0, 0, 1, 1]), type: "vec4<f32>" },
2519
+ uClampOffset: { value: new Float32Array([0, 0]), type: "vec2<f32>" },
2520
+ uTextureTransform: { value: new k(), type: "mat3x3<f32>" },
2521
+ uSizeAnchor: { value: new Float32Array([100, 100, 0.5, 0.5]), type: "vec4<f32>" }
2522
+ });
2523
+ super({
2524
+ glProgram: ue,
2525
+ gpuProgram: ce,
2526
+ resources: {
2527
+ localUniforms: new Y({
2528
+ uTransformMatrix: { value: new k(), type: "mat3x3<f32>" },
2529
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
2530
+ uRound: { value: 0, type: "f32" }
2531
+ }),
2532
+ tilingUniforms: e,
2533
+ uTexture: R.EMPTY.source,
2534
+ uSampler: R.EMPTY.source.style
2535
+ }
2536
+ });
2537
+ }
2538
+ updateUniforms(e, t, r, i, n, s) {
2539
+ const a = this.resources.tilingUniforms, l = s.width, c = s.height, d = s.textureMatrix, u = a.uniforms.uTextureTransform;
2540
+ u.set(
2541
+ r.a * l / e,
2542
+ r.b * l / t,
2543
+ r.c * c / e,
2544
+ r.d * c / t,
2545
+ r.tx / e,
2546
+ r.ty / t
2547
+ ), u.invert(), a.uniforms.uMapCoord = d.mapCoord, a.uniforms.uClampFrame = d.uClampFrame, a.uniforms.uClampOffset = d.uClampOffset, a.uniforms.uTextureTransform = u, a.uniforms.uSizeAnchor[0] = e, a.uniforms.uSizeAnchor[1] = t, a.uniforms.uSizeAnchor[2] = i, a.uniforms.uSizeAnchor[3] = n, s && (this.resources.uTexture = s.source, this.resources.uSampler = s.source.style);
2548
+ }
2549
+ }
2550
+ class gr extends ye {
2551
+ constructor() {
2552
+ super({
2553
+ positions: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
2554
+ uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
2555
+ indices: new Uint32Array([0, 1, 2, 0, 2, 3])
2556
+ });
2557
+ }
2558
+ }
2559
+ function mr(o, e) {
2560
+ const t = o.anchor.x, r = o.anchor.y;
2561
+ e[0] = -t * o.width, e[1] = -r * o.height, e[2] = (1 - t) * o.width, e[3] = -r * o.height, e[4] = (1 - t) * o.width, e[5] = (1 - r) * o.height, e[6] = -t * o.width, e[7] = (1 - r) * o.height;
2562
+ }
2563
+ function xr(o, e, t, r) {
2564
+ let i = 0;
2565
+ const n = o.length / e, s = r.a, a = r.b, l = r.c, c = r.d, d = r.tx, u = r.ty;
2566
+ for (t *= e; i < n; ) {
2567
+ const h = o[t], f = o[t + 1];
2568
+ o[t] = s * h + l * f + d, o[t + 1] = a * h + c * f + u, t += e, i++;
2569
+ }
2570
+ }
2571
+ function _r(o, e) {
2572
+ const t = o.texture, r = t.frame.width, i = t.frame.height;
2573
+ let n = 0, s = 0;
2574
+ o.applyAnchorToTexture && (n = o.anchor.x, s = o.anchor.y), e[0] = e[6] = -n, e[2] = e[4] = 1 - n, e[1] = e[3] = -s, e[5] = e[7] = 1 - s;
2575
+ const a = k.shared;
2576
+ a.copyFrom(o._tileTransform.matrix), a.tx /= o.width, a.ty /= o.height, a.invert(), a.scale(o.width / r, o.height / i), xr(e, 2, 0, a);
2577
+ }
2578
+ const J = new gr();
2579
+ class br {
2580
+ constructor() {
2581
+ this.canBatch = !0, this.geometry = new ye({
2582
+ indices: J.indices.slice(),
2583
+ positions: J.positions.slice(),
2584
+ uvs: J.uvs.slice()
2585
+ });
2586
+ }
2587
+ destroy() {
2588
+ var e;
2589
+ this.geometry.destroy(), (e = this.shader) == null || e.destroy();
2590
+ }
2591
+ }
2592
+ class dt {
2593
+ constructor(e) {
2594
+ this._state = ee.default2d, this._renderer = e;
2595
+ }
2596
+ validateRenderable(e) {
2597
+ const t = this._getTilingSpriteData(e), r = t.canBatch;
2598
+ this._updateCanBatch(e);
2599
+ const i = t.canBatch;
2600
+ if (i && i === r) {
2601
+ const { batchableMesh: n } = t;
2602
+ return !n._batcher.checkAndUpdateTexture(
2603
+ n,
2604
+ e.texture
2605
+ );
2606
+ }
2607
+ return r !== i;
2608
+ }
2609
+ addRenderable(e, t) {
2610
+ const r = this._renderer.renderPipes.batch;
2611
+ this._updateCanBatch(e);
2612
+ const i = this._getTilingSpriteData(e), { geometry: n, canBatch: s } = i;
2613
+ if (s) {
2614
+ i.batchableMesh || (i.batchableMesh = new we());
2615
+ const a = i.batchableMesh;
2616
+ e.didViewUpdate && (this._updateBatchableMesh(e), a.geometry = n, a.renderable = e, a.transform = e.groupTransform, a.setTexture(e._texture)), a.roundPixels = this._renderer._roundPixels | e._roundPixels, r.addToBatch(a, t);
2617
+ } else
2618
+ r.break(t), i.shader || (i.shader = new pr()), this.updateRenderable(e), t.add(e);
2619
+ }
2620
+ execute(e) {
2621
+ const { shader: t } = this._getTilingSpriteData(e);
2622
+ t.groups[0] = this._renderer.globalUniforms.bindGroup;
2623
+ const r = t.resources.localUniforms.uniforms;
2624
+ r.uTransformMatrix = e.groupTransform, r.uRound = this._renderer._roundPixels | e._roundPixels, se(
2625
+ e.groupColorAlpha,
2626
+ r.uColor,
2627
+ 0
2628
+ ), this._state.blendMode = _e(e.groupBlendMode, e.texture._source), this._renderer.encoder.draw({
2629
+ geometry: J,
2630
+ shader: t,
2631
+ state: this._state
2632
+ });
2633
+ }
2634
+ updateRenderable(e) {
2635
+ const t = this._getTilingSpriteData(e), { canBatch: r } = t;
2636
+ if (r) {
2637
+ const { batchableMesh: i } = t;
2638
+ e.didViewUpdate && this._updateBatchableMesh(e), i._batcher.updateElement(i);
2639
+ } else if (e.didViewUpdate) {
2640
+ const { shader: i } = t;
2641
+ i.updateUniforms(
2642
+ e.width,
2643
+ e.height,
2644
+ e._tileTransform.matrix,
2645
+ e.anchor.x,
2646
+ e.anchor.y,
2647
+ e.texture
2648
+ );
2649
+ }
2650
+ }
2651
+ _getTilingSpriteData(e) {
2652
+ return e._gpuData[this._renderer.uid] || this._initTilingSpriteData(e);
2653
+ }
2654
+ _initTilingSpriteData(e) {
2655
+ const t = new br();
2656
+ return t.renderable = e, e._gpuData[this._renderer.uid] = t, t;
2657
+ }
2658
+ _updateBatchableMesh(e) {
2659
+ const t = this._getTilingSpriteData(e), { geometry: r } = t, i = e.texture.source.style;
2660
+ i.addressMode !== "repeat" && (i.addressMode = "repeat", i.update()), _r(e, r.uvs), mr(e, r.positions);
2661
+ }
2662
+ destroy() {
2663
+ this._renderer = null;
2664
+ }
2665
+ _updateCanBatch(e) {
2666
+ const t = this._getTilingSpriteData(e), r = e.texture;
2667
+ let i = !0;
2668
+ return this._renderer.type === xe.WEBGL && (i = this._renderer.context.supports.nonPowOf2wrapping), t.canBatch = r.textureMatrix.isSimple && (i || r.source.isPowerOfTwo), t.canBatch;
2669
+ }
2670
+ }
2671
+ dt.extension = {
2672
+ type: [
2673
+ w.WebGLPipes,
2674
+ w.WebGPUPipes,
2675
+ w.CanvasPipes
2676
+ ],
2677
+ name: "tilingSprite"
2678
+ };
2679
+ const yr = {
2680
+ name: "local-uniform-msdf-bit",
2681
+ vertex: {
2682
+ header: (
2683
+ /* wgsl */
2684
+ `
2685
+ struct LocalUniforms {
2686
+ uColor:vec4<f32>,
2687
+ uTransformMatrix:mat3x3<f32>,
2688
+ uDistance: f32,
2689
+ uRound:f32,
2690
+ }
2691
+
2692
+ @group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
2693
+ `
2694
+ ),
2695
+ main: (
2696
+ /* wgsl */
2697
+ `
2698
+ vColor *= localUniforms.uColor;
2699
+ modelMatrix *= localUniforms.uTransformMatrix;
2700
+ `
2701
+ ),
2702
+ end: (
2703
+ /* wgsl */
2704
+ `
2705
+ if(localUniforms.uRound == 1)
2706
+ {
2707
+ vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
2708
+ }
2709
+ `
2710
+ )
2711
+ },
2712
+ fragment: {
2713
+ header: (
2714
+ /* wgsl */
2715
+ `
2716
+ struct LocalUniforms {
2717
+ uColor:vec4<f32>,
2718
+ uTransformMatrix:mat3x3<f32>,
2719
+ uDistance: f32
2720
+ }
2721
+
2722
+ @group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
2723
+ `
2724
+ ),
2725
+ main: (
2726
+ /* wgsl */
2727
+ `
2728
+ outColor = vec4<f32>(calculateMSDFAlpha(outColor, localUniforms.uColor, localUniforms.uDistance));
2729
+ `
2730
+ )
2731
+ }
2732
+ }, wr = {
2733
+ name: "local-uniform-msdf-bit",
2734
+ vertex: {
2735
+ header: (
2736
+ /* glsl */
2737
+ `
2738
+ uniform mat3 uTransformMatrix;
2739
+ uniform vec4 uColor;
2740
+ uniform float uRound;
2741
+ `
2742
+ ),
2743
+ main: (
2744
+ /* glsl */
2745
+ `
2746
+ vColor *= uColor;
2747
+ modelMatrix *= uTransformMatrix;
2748
+ `
2749
+ ),
2750
+ end: (
2751
+ /* glsl */
2752
+ `
2753
+ if(uRound == 1.)
2754
+ {
2755
+ gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
2756
+ }
2757
+ `
2758
+ )
2759
+ },
2760
+ fragment: {
2761
+ header: (
2762
+ /* glsl */
2763
+ `
2764
+ uniform float uDistance;
2765
+ `
2766
+ ),
2767
+ main: (
2768
+ /* glsl */
2769
+ `
2770
+ outColor = vec4(calculateMSDFAlpha(outColor, vColor, uDistance));
2771
+ `
2772
+ )
2773
+ }
2774
+ }, Tr = {
2775
+ name: "msdf-bit",
2776
+ fragment: {
2777
+ header: (
2778
+ /* wgsl */
2779
+ `
2780
+ fn calculateMSDFAlpha(msdfColor:vec4<f32>, shapeColor:vec4<f32>, distance:f32) -> f32 {
2781
+
2782
+ // MSDF
2783
+ var median = msdfColor.r + msdfColor.g + msdfColor.b -
2784
+ min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
2785
+ max(msdfColor.r, max(msdfColor.g, msdfColor.b));
2786
+
2787
+ // SDF
2788
+ median = min(median, msdfColor.a);
2789
+
2790
+ var screenPxDistance = distance * (median - 0.5);
2791
+ var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
2792
+ if (median < 0.01) {
2793
+ alpha = 0.0;
2794
+ } else if (median > 0.99) {
2795
+ alpha = 1.0;
2796
+ }
2797
+
2798
+ // Gamma correction for coverage-like alpha
2799
+ var luma: f32 = dot(shapeColor.rgb, vec3<f32>(0.299, 0.587, 0.114));
2800
+ var gamma: f32 = mix(1.0, 1.0 / 2.2, luma);
2801
+ var coverage: f32 = pow(shapeColor.a * alpha, gamma);
2802
+
2803
+ return coverage;
2804
+
2805
+ }
2806
+ `
2807
+ )
2808
+ }
2809
+ }, vr = {
2810
+ name: "msdf-bit",
2811
+ fragment: {
2812
+ header: (
2813
+ /* glsl */
2814
+ `
2815
+ float calculateMSDFAlpha(vec4 msdfColor, vec4 shapeColor, float distance) {
2816
+
2817
+ // MSDF
2818
+ float median = msdfColor.r + msdfColor.g + msdfColor.b -
2819
+ min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
2820
+ max(msdfColor.r, max(msdfColor.g, msdfColor.b));
2821
+
2822
+ // SDF
2823
+ median = min(median, msdfColor.a);
2824
+
2825
+ float screenPxDistance = distance * (median - 0.5);
2826
+ float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
2827
+
2828
+ if (median < 0.01) {
2829
+ alpha = 0.0;
2830
+ } else if (median > 0.99) {
2831
+ alpha = 1.0;
2832
+ }
2833
+
2834
+ // Gamma correction for coverage-like alpha
2835
+ float luma = dot(shapeColor.rgb, vec3(0.299, 0.587, 0.114));
2836
+ float gamma = mix(1.0, 1.0 / 2.2, luma);
2837
+ float coverage = pow(shapeColor.a * alpha, gamma);
2838
+
2839
+ return coverage;
2840
+ }
2841
+ `
2842
+ )
2843
+ }
2844
+ };
2845
+ let de, he;
2846
+ class Sr extends be {
2847
+ constructor(e) {
2848
+ const t = new Y({
2849
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
2850
+ uTransformMatrix: { value: new k(), type: "mat3x3<f32>" },
2851
+ uDistance: { value: 4, type: "f32" },
2852
+ uRound: { value: 0, type: "f32" }
2853
+ });
2854
+ de ?? (de = Oe({
2855
+ name: "sdf-shader",
2856
+ bits: [
2857
+ Mt,
2858
+ Rt(e),
2859
+ yr,
2860
+ Tr,
2861
+ Ee
2862
+ ]
2863
+ })), he ?? (he = He({
2864
+ name: "sdf-shader",
2865
+ bits: [
2866
+ Ut,
2867
+ kt(e),
2868
+ wr,
2869
+ vr,
2870
+ Ve
2871
+ ]
2872
+ })), super({
2873
+ glProgram: he,
2874
+ gpuProgram: de,
2875
+ resources: {
2876
+ localUniforms: t,
2877
+ batchSamplers: Gt(e)
2878
+ }
2879
+ });
2880
+ }
2881
+ }
2882
+ class Cr extends At {
2883
+ destroy() {
2884
+ this.context.customShader && this.context.customShader.destroy(), super.destroy();
2885
+ }
2886
+ }
2887
+ class ht {
2888
+ constructor(e) {
2889
+ this._renderer = e, this._renderer.renderableGC.addManagedHash(this, "_gpuBitmapText");
2890
+ }
2891
+ validateRenderable(e) {
2892
+ const t = this._getGpuBitmapText(e);
2893
+ return this._renderer.renderPipes.graphics.validateRenderable(t);
2894
+ }
2895
+ addRenderable(e, t) {
2896
+ const r = this._getGpuBitmapText(e);
2897
+ We(e, r), e._didTextUpdate && (e._didTextUpdate = !1, this._updateContext(e, r)), this._renderer.renderPipes.graphics.addRenderable(r, t), r.context.customShader && this._updateDistanceField(e);
2898
+ }
2899
+ updateRenderable(e) {
2900
+ const t = this._getGpuBitmapText(e);
2901
+ We(e, t), this._renderer.renderPipes.graphics.updateRenderable(t), t.context.customShader && this._updateDistanceField(e);
2902
+ }
2903
+ _updateContext(e, t) {
2904
+ const { context: r } = t, i = $t.getFont(e.text, e._style);
2905
+ r.clear(), i.distanceField.type !== "none" && (r.customShader || (r.customShader = new Sr(this._renderer.limits.maxBatchableTextures)));
2906
+ const n = D.graphemeSegmenter(e.text), s = e._style;
2907
+ let a = i.baseLineOffset;
2908
+ const l = qe(n, s, i, !0), c = s.padding, d = l.scale;
2909
+ let u = l.width, h = l.height + l.offsetY;
2910
+ s._stroke && (u += s._stroke.width / d, h += s._stroke.width / d), r.translate(-e._anchor._x * u - c, -e._anchor._y * h - c).scale(d, d);
2911
+ const f = i.applyFillAsTint ? s._fill.color : 16777215;
2912
+ let m = i.fontMetrics.fontSize, x = i.lineHeight;
2913
+ s.lineHeight && (m = s.fontSize / d, x = s.lineHeight / d);
2914
+ let _ = (x - m) / 2;
2915
+ _ - i.baseLineOffset < 0 && (_ = 0);
2916
+ for (let p = 0; p < l.lines.length; p++) {
2917
+ const b = l.lines[p];
2918
+ for (let y = 0; y < b.charPositions.length; y++) {
2919
+ const T = b.chars[y], S = i.chars[T];
2920
+ if (S != null && S.texture) {
2921
+ const B = S.texture;
2922
+ r.texture(
2923
+ B,
2924
+ f || "black",
2925
+ Math.round(b.charPositions[y] + S.xOffset),
2926
+ Math.round(a + S.yOffset + _),
2927
+ B.orig.width,
2928
+ B.orig.height
2929
+ );
2930
+ }
2931
+ }
2932
+ a += x;
2933
+ }
2934
+ }
2935
+ _getGpuBitmapText(e) {
2936
+ return e._gpuData[this._renderer.uid] || this.initGpuText(e);
2937
+ }
2938
+ initGpuText(e) {
2939
+ const t = new Cr();
2940
+ return e._gpuData[this._renderer.uid] = t, this._updateContext(e, t), t;
2941
+ }
2942
+ _updateDistanceField(e) {
2943
+ const t = this._getGpuBitmapText(e).context, r = e._style.fontFamily, i = G.get(`${r}-bitmap`), { a: n, b: s, c: a, d: l } = e.groupTransform, c = Math.sqrt(n * n + s * s), d = Math.sqrt(a * a + l * l), u = (Math.abs(c) + Math.abs(d)) / 2, h = i.baseRenderedFontSize / e._style.fontSize, f = u * i.distanceField.range * (1 / h);
2944
+ t.customShader.resources.localUniforms.uniforms.uDistance = f;
2945
+ }
2946
+ destroy() {
2947
+ this._renderer = null;
2948
+ }
2949
+ }
2950
+ ht.extension = {
2951
+ type: [
2952
+ w.WebGLPipes,
2953
+ w.WebGPUPipes,
2954
+ w.CanvasPipes
2955
+ ],
2956
+ name: "bitmapText"
2957
+ };
2958
+ function We(o, e) {
2959
+ e.groupTransform = o.groupTransform, e.groupColorAlpha = o.groupColorAlpha, e.groupColor = o.groupColor, e.groupBlendMode = o.groupBlendMode, e.globalDisplayStatus = o.globalDisplayStatus, e.groupTransform = o.groupTransform, e.localDisplayStatus = o.localDisplayStatus, e.groupAlpha = o.groupAlpha, e._roundPixels = o._roundPixels;
2960
+ }
2961
+ class Pr extends Ye {
2962
+ /**
2963
+ * Creates an instance of BatchableHTMLText.
2964
+ * @param renderer - The renderer instance to be used.
2965
+ */
2966
+ constructor(e) {
2967
+ super(), this.generatingTexture = !1, this._renderer = e, e.runners.resolutionChange.add(this);
2968
+ }
2969
+ /** Handles resolution changes for the HTML text. If the text has auto resolution enabled, it triggers a view update. */
2970
+ resolutionChange() {
2971
+ const e = this.renderable;
2972
+ e._autoResolution && e.onViewUpdate();
2973
+ }
2974
+ /** Destroys the BatchableHTMLText instance. Returns the texture promise to the renderer and cleans up references. */
2975
+ destroy() {
2976
+ this._renderer.htmlText.returnTexturePromise(this.texturePromise), this.texturePromise = null, this._renderer = null;
2977
+ }
2978
+ }
2979
+ function ge(o, e) {
2980
+ const { texture: t, bounds: r } = o, i = e._style._getFinalPadding();
2981
+ zt(r, e._anchor, t);
2982
+ const n = e._anchor._x * i * 2, s = e._anchor._y * i * 2;
2983
+ r.minX -= i - n, r.minY -= i - s, r.maxX -= i - n, r.maxY -= i - s;
2984
+ }
2985
+ class ft {
2986
+ constructor(e) {
2987
+ this._renderer = e;
2988
+ }
2989
+ validateRenderable(e) {
2990
+ return e._didTextUpdate;
2991
+ }
2992
+ addRenderable(e, t) {
2993
+ const r = this._getGpuText(e);
2994
+ e._didTextUpdate && (this._updateGpuText(e).catch((i) => {
2995
+ console.error(i);
2996
+ }), e._didTextUpdate = !1, ge(r, e)), this._renderer.renderPipes.batch.addToBatch(r, t);
2997
+ }
2998
+ updateRenderable(e) {
2999
+ const t = this._getGpuText(e);
3000
+ t._batcher.updateElement(t);
3001
+ }
3002
+ async _updateGpuText(e) {
3003
+ e._didTextUpdate = !1;
3004
+ const t = this._getGpuText(e);
3005
+ if (t.generatingTexture)
3006
+ return;
3007
+ t.texturePromise && (this._renderer.htmlText.returnTexturePromise(t.texturePromise), t.texturePromise = null), t.generatingTexture = !0, e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution;
3008
+ const r = this._renderer.htmlText.getTexturePromise(e);
3009
+ t.texturePromise = r, t.texture = await r;
3010
+ const i = e.renderGroup || e.parentRenderGroup;
3011
+ i && (i.structureDidChange = !0), t.generatingTexture = !1, ge(t, e);
3012
+ }
3013
+ _getGpuText(e) {
3014
+ return e._gpuData[this._renderer.uid] || this.initGpuText(e);
3015
+ }
3016
+ initGpuText(e) {
3017
+ const t = new Pr(this._renderer);
3018
+ return t.renderable = e, t.transform = e.groupTransform, t.texture = R.EMPTY, t.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution, e._gpuData[this._renderer.uid] = t, t;
3019
+ }
3020
+ destroy() {
3021
+ this._renderer = null;
3022
+ }
3023
+ }
3024
+ ft.extension = {
3025
+ type: [
3026
+ w.WebGLPipes,
3027
+ w.WebGPUPipes,
3028
+ w.CanvasPipes
3029
+ ],
3030
+ name: "htmlText"
3031
+ };
3032
+ function Fr() {
3033
+ const { userAgent: o } = H.get().getNavigator();
3034
+ return /^((?!chrome|android).)*safari/i.test(o);
3035
+ }
3036
+ const Br = new Ie();
3037
+ function pt(o, e, t, r) {
3038
+ const i = Br;
3039
+ i.minX = 0, i.minY = 0, i.maxX = o.width / r | 0, i.maxY = o.height / r | 0;
3040
+ const n = A.getOptimalTexture(
3041
+ i.width,
3042
+ i.height,
3043
+ r,
3044
+ !1
3045
+ );
3046
+ return n.source.uploadMethodId = "image", n.source.resource = o, n.source.alphaMode = "premultiply-alpha-on-upload", n.frame.width = e / r, n.frame.height = t / r, n.source.emit("update", n.source), n.updateUvs(), n;
3047
+ }
3048
+ function Mr(o, e) {
3049
+ const t = e.fontFamily, r = [], i = {}, n = /font-family:([^;"\s]+)/g, s = o.match(n);
3050
+ function a(l) {
3051
+ i[l] || (r.push(l), i[l] = !0);
3052
+ }
3053
+ if (Array.isArray(t))
3054
+ for (let l = 0; l < t.length; l++)
3055
+ a(t[l]);
3056
+ else
3057
+ a(t);
3058
+ s && s.forEach((l) => {
3059
+ const c = l.split(":")[1].trim();
3060
+ a(c);
3061
+ });
3062
+ for (const l in e.tagStyles) {
3063
+ const c = e.tagStyles[l].fontFamily;
3064
+ a(c);
3065
+ }
3066
+ return r;
3067
+ }
3068
+ async function Rr(o) {
3069
+ const t = await (await H.get().fetch(o)).blob(), r = new FileReader();
3070
+ return await new Promise((n, s) => {
3071
+ r.onloadend = () => n(r.result), r.onerror = s, r.readAsDataURL(t);
3072
+ });
3073
+ }
3074
+ async function Ur(o, e) {
3075
+ const t = await Rr(e);
3076
+ return `@font-face {
3077
+ font-family: "${o.fontFamily}";
3078
+ font-weight: ${o.fontWeight};
3079
+ font-style: ${o.fontStyle};
3080
+ src: url('${t}');
3081
+ }`;
3082
+ }
3083
+ const fe = /* @__PURE__ */ new Map();
3084
+ async function kr(o) {
3085
+ const e = o.filter((t) => G.has(`${t}-and-url`)).map((t) => {
3086
+ if (!fe.has(t)) {
3087
+ const { entries: r } = G.get(`${t}-and-url`), i = [];
3088
+ r.forEach((n) => {
3089
+ const s = n.url, l = n.faces.map((c) => ({ weight: c.weight, style: c.style }));
3090
+ i.push(
3091
+ ...l.map(
3092
+ (c) => Ur(
3093
+ {
3094
+ fontWeight: c.weight,
3095
+ fontStyle: c.style,
3096
+ fontFamily: t
3097
+ },
3098
+ s
3099
+ )
3100
+ )
3101
+ );
3102
+ }), fe.set(
3103
+ t,
3104
+ Promise.all(i).then((n) => n.join(`
3105
+ `))
3106
+ );
3107
+ }
3108
+ return fe.get(t);
3109
+ });
3110
+ return (await Promise.all(e)).join(`
3111
+ `);
3112
+ }
3113
+ function Gr(o, e, t, r, i) {
3114
+ const { domElement: n, styleElement: s, svgRoot: a } = i;
3115
+ n.innerHTML = `<style>${e.cssStyle}</style><div style='padding:0;'>${o}</div>`, n.setAttribute("style", `transform: scale(${t});transform-origin: top left; display: inline-block`), s.textContent = r;
3116
+ const { width: l, height: c } = i.image;
3117
+ return a.setAttribute("width", l.toString()), a.setAttribute("height", c.toString()), new XMLSerializer().serializeToString(a);
3118
+ }
3119
+ function Ar(o, e) {
3120
+ const t = X.getOptimalCanvasAndContext(
3121
+ o.width,
3122
+ o.height,
3123
+ e
3124
+ ), { context: r } = t;
3125
+ return r.clearRect(0, 0, o.width, o.height), r.drawImage(o, 0, 0), t;
3126
+ }
3127
+ function zr(o, e, t) {
3128
+ return new Promise(async (r) => {
3129
+ t && await new Promise((i) => setTimeout(i, 100)), o.onload = () => {
3130
+ r();
3131
+ }, o.src = `data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`, o.crossOrigin = "anonymous";
3132
+ });
3133
+ }
3134
+ class gt {
3135
+ constructor(e) {
3136
+ this._renderer = e, this._createCanvas = e.type === xe.WEBGPU;
3137
+ }
3138
+ /**
3139
+ * @param options
3140
+ * @deprecated Use getTexturePromise instead
3141
+ */
3142
+ getTexture(e) {
3143
+ return this.getTexturePromise(e);
3144
+ }
3145
+ getTexturePromise(e) {
3146
+ return this._buildTexturePromise(e);
3147
+ }
3148
+ async _buildTexturePromise(e) {
3149
+ const { text: t, style: r, resolution: i, textureStyle: n } = e, s = te.get(et), a = Mr(t, r), l = await kr(a), c = Zt(t, r, l, s), d = Math.ceil(Math.ceil(Math.max(1, c.width) + r.padding * 2) * i), u = Math.ceil(Math.ceil(Math.max(1, c.height) + r.padding * 2) * i), h = s.image, f = 2;
3150
+ h.width = (d | 0) + f, h.height = (u | 0) + f;
3151
+ const m = Gr(t, r, i, l, s);
3152
+ await zr(h, m, Fr() && a.length > 0);
3153
+ const x = h;
3154
+ let _;
3155
+ this._createCanvas && (_ = Ar(h, i));
3156
+ const p = pt(
3157
+ _ ? _.canvas : x,
3158
+ h.width - f,
3159
+ h.height - f,
3160
+ i
3161
+ );
3162
+ return n && (p.source.style = n), this._createCanvas && (this._renderer.texture.initSource(p.source), X.returnCanvasAndContext(_)), te.return(s), p;
3163
+ }
3164
+ returnTexturePromise(e) {
3165
+ e.then((t) => {
3166
+ this._cleanUp(t);
3167
+ }).catch(() => {
3168
+ ne("HTMLTextSystem: Failed to clean texture");
3169
+ });
3170
+ }
3171
+ _cleanUp(e) {
3172
+ A.returnTexture(e, !0), e.source.resource = null, e.source.uploadMethodId = "unknown";
3173
+ }
3174
+ destroy() {
3175
+ this._renderer = null;
3176
+ }
3177
+ }
3178
+ gt.extension = {
3179
+ type: [
3180
+ w.WebGLSystem,
3181
+ w.WebGPUSystem,
3182
+ w.CanvasSystem
3183
+ ],
3184
+ name: "htmlText"
3185
+ };
3186
+ class Dr extends Ye {
3187
+ constructor(e) {
3188
+ super(), this._renderer = e, e.runners.resolutionChange.add(this);
3189
+ }
3190
+ resolutionChange() {
3191
+ const e = this.renderable;
3192
+ e._autoResolution && e.onViewUpdate();
3193
+ }
3194
+ destroy() {
3195
+ this._renderer.canvasText.returnTexture(this.texture), this._renderer = null;
3196
+ }
3197
+ }
3198
+ class mt {
3199
+ constructor(e) {
3200
+ this._renderer = e;
3201
+ }
3202
+ validateRenderable(e) {
3203
+ return e._didTextUpdate;
3204
+ }
3205
+ addRenderable(e, t) {
3206
+ const r = this._getGpuText(e);
3207
+ e._didTextUpdate && (this._updateGpuText(e), e._didTextUpdate = !1), this._renderer.renderPipes.batch.addToBatch(r, t);
3208
+ }
3209
+ updateRenderable(e) {
3210
+ const t = this._getGpuText(e);
3211
+ t._batcher.updateElement(t);
3212
+ }
3213
+ _updateGpuText(e) {
3214
+ const t = this._getGpuText(e);
3215
+ t.texture && this._renderer.canvasText.returnTexture(t.texture), e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution, t.texture = this._renderer.canvasText.getTexture(e), ge(t, e);
3216
+ }
3217
+ _getGpuText(e) {
3218
+ return e._gpuData[this._renderer.uid] || this.initGpuText(e);
3219
+ }
3220
+ initGpuText(e) {
3221
+ const t = new Dr(this._renderer);
3222
+ return t.renderable = e, t.transform = e.groupTransform, t.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._gpuData[this._renderer.uid] = t, t;
3223
+ }
3224
+ destroy() {
3225
+ this._renderer = null;
3226
+ }
3227
+ }
3228
+ mt.extension = {
3229
+ type: [
3230
+ w.WebGLPipes,
3231
+ w.WebGPUPipes,
3232
+ w.CanvasPipes
3233
+ ],
3234
+ name: "text"
3235
+ };
3236
+ class xt {
3237
+ constructor(e) {
3238
+ this._renderer = e;
3239
+ }
3240
+ getTexture(e, t, r, i) {
3241
+ typeof e == "string" && (U("8.0.0", "CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"), e = {
3242
+ text: e,
3243
+ style: r,
3244
+ resolution: t
3245
+ }), e.style instanceof q || (e.style = new q(e.style)), e.textureStyle instanceof j || (e.textureStyle = new j(e.textureStyle)), typeof e.text != "string" && (e.text = e.text.toString());
3246
+ const { text: n, style: s, textureStyle: a } = e, l = e.resolution ?? this._renderer.resolution, { frame: c, canvasAndContext: d } = le.getCanvasAndContext({
3247
+ text: n,
3248
+ style: s,
3249
+ resolution: l
3250
+ }), u = pt(d.canvas, c.width, c.height, l);
3251
+ if (a && (u.source.style = a), s.trim && (c.pad(s.padding), u.frame.copyFrom(c), u.frame.scale(1 / l), u.updateUvs()), s.filters) {
3252
+ const h = this._applyFilters(u, s.filters);
3253
+ return this.returnTexture(u), le.returnCanvasAndContext(d), h;
3254
+ }
3255
+ return this._renderer.texture.initSource(u._source), le.returnCanvasAndContext(d), u;
3256
+ }
3257
+ /**
3258
+ * Returns a texture that was created wit the above `getTexture` function.
3259
+ * Handy if you are done with a texture and want to return it to the pool.
3260
+ * @param texture - The texture to be returned.
3261
+ */
3262
+ returnTexture(e) {
3263
+ const t = e.source;
3264
+ t.resource = null, t.uploadMethodId = "unknown", t.alphaMode = "no-premultiply-alpha", A.returnTexture(e, !0);
3265
+ }
3266
+ /**
3267
+ * Renders text to its canvas, and updates its texture.
3268
+ * @deprecated since 8.10.0
3269
+ */
3270
+ renderTextToCanvas() {
3271
+ U(
3272
+ "8.10.0",
3273
+ "CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead"
3274
+ );
3275
+ }
3276
+ /**
3277
+ * Applies the specified filters to the given texture.
3278
+ *
3279
+ * This method takes a texture and a list of filters, applies the filters to the texture,
3280
+ * and returns the resulting texture. It also ensures that the alpha mode of the resulting
3281
+ * texture is set to 'premultiplied-alpha'.
3282
+ * @param {Texture} texture - The texture to which the filters will be applied.
3283
+ * @param {Filter[]} filters - The filters to apply to the texture.
3284
+ * @returns {Texture} The resulting texture after all filters have been applied.
3285
+ */
3286
+ _applyFilters(e, t) {
3287
+ const r = this._renderer.renderTarget.renderTarget, i = this._renderer.filter.generateFilteredTexture({
3288
+ texture: e,
3289
+ filters: t
3290
+ });
3291
+ return this._renderer.renderTarget.bind(r, !1), i;
3292
+ }
3293
+ destroy() {
3294
+ this._renderer = null;
3295
+ }
3296
+ }
3297
+ xt.extension = {
3298
+ type: [
3299
+ w.WebGLSystem,
3300
+ w.WebGPUSystem,
3301
+ w.CanvasSystem
3302
+ ],
3303
+ name: "canvasText"
3304
+ };
3305
+ P.add(Xe);
3306
+ P.add($e);
3307
+ P.add(tt);
3308
+ P.add(Dt);
3309
+ P.add(nt);
3310
+ P.add(at);
3311
+ P.add(ot);
3312
+ P.add(xt);
3313
+ P.add(mt);
3314
+ P.add(ht);
3315
+ P.add(gt);
3316
+ P.add(ft);
3317
+ P.add(dt);
3318
+ P.add(ut);
3319
+ P.add(Qe);
3320
+ P.add(Ke);
3321
+ //# sourceMappingURL=webworkerAll-CI8_Z7rX.js.map