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