evotars 0.0.10 → 0.0.12
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.
- package/dist/CanvasPool-5ekdWScU.js +46 -0
- package/dist/SharedSystems-n7sA1Ui-.js +2134 -0
- package/dist/WebGLRenderer-BUvcWTmB.js +2564 -0
- package/dist/WebGPURenderer-BPb_585F.js +1561 -0
- package/dist/browserAll-DR-9ZkSp.js +1968 -0
- package/dist/colorToUniform-Cp4M-zOy.js +1308 -0
- package/dist/evotars.js +6 -26280
- package/dist/evotars.umd.cjs +902 -1069
- package/dist/getBatchSamplersUniformGroup-CIYh8OT7.js +16 -0
- package/dist/index-B5GUB2He.js +14036 -0
- package/dist/index.d.ts +9 -21
- package/dist/webworkerAll-Bg_9Ksbn.js +2661 -0
- package/package.json +11 -5
|
@@ -0,0 +1,2661 @@
|
|
|
1
|
+
import { E as b, U as pt, T as pe, O as q, M as U, N as Fe, c as Me, w as L, j as R, P as gt, t as Re, K as k, L as H, b as Q, B as D, I, Q as mt, V as xt, a as _t, W as re, X as z, R as V, Y as bt, Z as M, _ as E, $ as yt, q as B, a0 as Tt, D as $, a1 as wt, a2 as Z, a3 as vt, m as St, a4 as Ct, a5 as se, n as ge, e as P, a6 as Bt } from "./index-B5GUB2He.js";
|
|
2
|
+
import { U as Y, T as A, R as ne, S as Ae, i as ae, b as ke, c as Ue, j as Ge, e as Pt, r as ze, o as Ft, n as He, a as Mt, g as Rt, k as At, m as kt, B as Ie } from "./colorToUniform-Cp4M-zOy.js";
|
|
3
|
+
import { C as W } from "./CanvasPool-5ekdWScU.js";
|
|
4
|
+
import { g as Ut } from "./getBatchSamplersUniformGroup-CIYh8OT7.js";
|
|
5
|
+
class We {
|
|
6
|
+
/**
|
|
7
|
+
* Initialize the plugin with scope of application instance
|
|
8
|
+
* @static
|
|
9
|
+
* @private
|
|
10
|
+
* @param {object} [options] - See application options
|
|
11
|
+
*/
|
|
12
|
+
static init(e) {
|
|
13
|
+
Object.defineProperty(
|
|
14
|
+
this,
|
|
15
|
+
"resizeTo",
|
|
16
|
+
/**
|
|
17
|
+
* The HTML element or window to automatically resize the
|
|
18
|
+
* renderer's view element to match width and height.
|
|
19
|
+
* @member {Window|HTMLElement}
|
|
20
|
+
* @name resizeTo
|
|
21
|
+
* @memberof app.Application#
|
|
22
|
+
*/
|
|
23
|
+
{
|
|
24
|
+
set(t) {
|
|
25
|
+
globalThis.removeEventListener("resize", this.queueResize), this._resizeTo = t, t && (globalThis.addEventListener("resize", this.queueResize), this.resize());
|
|
26
|
+
},
|
|
27
|
+
get() {
|
|
28
|
+
return this._resizeTo;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
), this.queueResize = () => {
|
|
32
|
+
this._resizeTo && (this._cancelResize(), this._resizeId = requestAnimationFrame(() => this.resize()));
|
|
33
|
+
}, this._cancelResize = () => {
|
|
34
|
+
this._resizeId && (cancelAnimationFrame(this._resizeId), this._resizeId = null);
|
|
35
|
+
}, this.resize = () => {
|
|
36
|
+
if (!this._resizeTo)
|
|
37
|
+
return;
|
|
38
|
+
this._cancelResize();
|
|
39
|
+
let t, r;
|
|
40
|
+
if (this._resizeTo === globalThis.window)
|
|
41
|
+
t = globalThis.innerWidth, r = globalThis.innerHeight;
|
|
42
|
+
else {
|
|
43
|
+
const { clientWidth: s, clientHeight: n } = this._resizeTo;
|
|
44
|
+
t = s, r = n;
|
|
45
|
+
}
|
|
46
|
+
this.renderer.resize(t, r), this.render();
|
|
47
|
+
}, this._resizeId = null, this._resizeTo = null, this.resizeTo = e.resizeTo || null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Clean up the ticker, scoped to application
|
|
51
|
+
* @static
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
static destroy() {
|
|
55
|
+
globalThis.removeEventListener("resize", this.queueResize), this._cancelResize(), this._cancelResize = null, this.queueResize = null, this.resizeTo = null, this.resize = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
We.extension = b.Application;
|
|
59
|
+
class Oe {
|
|
60
|
+
/**
|
|
61
|
+
* Initialize the plugin with scope of application instance
|
|
62
|
+
* @static
|
|
63
|
+
* @private
|
|
64
|
+
* @param {object} [options] - See application options
|
|
65
|
+
*/
|
|
66
|
+
static init(e) {
|
|
67
|
+
e = Object.assign({
|
|
68
|
+
autoStart: !0,
|
|
69
|
+
sharedTicker: !1
|
|
70
|
+
}, e), Object.defineProperty(
|
|
71
|
+
this,
|
|
72
|
+
"ticker",
|
|
73
|
+
{
|
|
74
|
+
set(t) {
|
|
75
|
+
this._ticker && this._ticker.remove(this.render, this), this._ticker = t, t && t.add(this.render, this, pt.LOW);
|
|
76
|
+
},
|
|
77
|
+
get() {
|
|
78
|
+
return this._ticker;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
), this.stop = () => {
|
|
82
|
+
this._ticker.stop();
|
|
83
|
+
}, this.start = () => {
|
|
84
|
+
this._ticker.start();
|
|
85
|
+
}, this._ticker = null, this.ticker = e.sharedTicker ? pe.shared : new pe(), e.autoStart && this.start();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Clean up the ticker, scoped to application.
|
|
89
|
+
* @static
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
static destroy() {
|
|
93
|
+
if (this._ticker) {
|
|
94
|
+
const e = this._ticker;
|
|
95
|
+
this.ticker = null, e.destroy();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
Oe.extension = b.Application;
|
|
100
|
+
class De {
|
|
101
|
+
constructor(e) {
|
|
102
|
+
this._renderer = e;
|
|
103
|
+
}
|
|
104
|
+
push(e, t, r) {
|
|
105
|
+
this._renderer.renderPipes.batch.break(r), r.add({
|
|
106
|
+
renderPipeId: "filter",
|
|
107
|
+
canBundle: !1,
|
|
108
|
+
action: "pushFilter",
|
|
109
|
+
container: t,
|
|
110
|
+
filterEffect: e
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
pop(e, t, r) {
|
|
114
|
+
this._renderer.renderPipes.batch.break(r), r.add({
|
|
115
|
+
renderPipeId: "filter",
|
|
116
|
+
action: "popFilter",
|
|
117
|
+
canBundle: !1
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
execute(e) {
|
|
121
|
+
e.action === "pushFilter" ? this._renderer.filter.push(e) : e.action === "popFilter" && this._renderer.filter.pop();
|
|
122
|
+
}
|
|
123
|
+
destroy() {
|
|
124
|
+
this._renderer = null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
De.extension = {
|
|
128
|
+
type: [
|
|
129
|
+
b.WebGLPipes,
|
|
130
|
+
b.WebGPUPipes,
|
|
131
|
+
b.CanvasPipes
|
|
132
|
+
],
|
|
133
|
+
name: "filter"
|
|
134
|
+
};
|
|
135
|
+
const Gt = new U();
|
|
136
|
+
function zt(i, e) {
|
|
137
|
+
return e.clear(), Le(i, e), e.isValid || e.set(0, 0, 0, 0), i.renderGroup ? e.applyMatrix(i.renderGroup.localTransform) : e.applyMatrix(i.parentRenderGroup.worldTransform), e;
|
|
138
|
+
}
|
|
139
|
+
function Le(i, e) {
|
|
140
|
+
if (i.localDisplayStatus !== 7 || !i.measurable)
|
|
141
|
+
return;
|
|
142
|
+
const t = !!i.effects.length;
|
|
143
|
+
let r = e;
|
|
144
|
+
if ((i.renderGroup || t) && (r = q.get().clear()), i.boundsArea)
|
|
145
|
+
e.addRect(i.boundsArea, i.worldTransform);
|
|
146
|
+
else {
|
|
147
|
+
if (i.renderPipeId) {
|
|
148
|
+
const n = i.bounds;
|
|
149
|
+
r.addFrame(
|
|
150
|
+
n.minX,
|
|
151
|
+
n.minY,
|
|
152
|
+
n.maxX,
|
|
153
|
+
n.maxY,
|
|
154
|
+
i.groupTransform
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
const s = i.children;
|
|
158
|
+
for (let n = 0; n < s.length; n++)
|
|
159
|
+
Le(s[n], r);
|
|
160
|
+
}
|
|
161
|
+
if (t) {
|
|
162
|
+
let s = !1;
|
|
163
|
+
for (let n = 0; n < i.effects.length; n++)
|
|
164
|
+
i.effects[n].addBounds && (s || (s = !0, r.applyMatrix(i.parentRenderGroup.worldTransform)), i.effects[n].addBounds(r, !0));
|
|
165
|
+
s && (r.applyMatrix(i.parentRenderGroup.worldTransform.copyTo(Gt).invert()), e.addBounds(r, i.relativeGroupTransform)), e.addBounds(r), q.return(r);
|
|
166
|
+
} else
|
|
167
|
+
i.renderGroup && (e.addBounds(r, i.relativeGroupTransform), q.return(r));
|
|
168
|
+
}
|
|
169
|
+
function Ht(i, e) {
|
|
170
|
+
e.clear();
|
|
171
|
+
const t = e.matrix;
|
|
172
|
+
for (let r = 0; r < i.length; r++) {
|
|
173
|
+
const s = i[r];
|
|
174
|
+
s.globalDisplayStatus < 7 || (e.matrix = s.worldTransform, s.addBounds(e));
|
|
175
|
+
}
|
|
176
|
+
return e.matrix = t, e;
|
|
177
|
+
}
|
|
178
|
+
const It = new Fe({
|
|
179
|
+
attributes: {
|
|
180
|
+
aPosition: {
|
|
181
|
+
buffer: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
182
|
+
location: 0,
|
|
183
|
+
format: "float32x2",
|
|
184
|
+
stride: 2 * 4,
|
|
185
|
+
offset: 0
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
indexBuffer: new Uint32Array([0, 1, 2, 0, 2, 3])
|
|
189
|
+
});
|
|
190
|
+
class Ee {
|
|
191
|
+
constructor(e) {
|
|
192
|
+
this._filterStackIndex = 0, this._filterStack = [], this._filterGlobalUniforms = new Y({
|
|
193
|
+
uInputSize: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
194
|
+
uInputPixel: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
195
|
+
uInputClamp: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
196
|
+
uOutputFrame: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
197
|
+
uGlobalFrame: { value: new Float32Array(4), type: "vec4<f32>" },
|
|
198
|
+
uOutputTexture: { value: new Float32Array(4), type: "vec4<f32>" }
|
|
199
|
+
}), this._globalFilterBindGroup = new Me({}), this.renderer = e;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The back texture of the currently active filter. Requires the filter to have `blendRequired` set to true.
|
|
203
|
+
* @readonly
|
|
204
|
+
*/
|
|
205
|
+
get activeBackTexture() {
|
|
206
|
+
var e;
|
|
207
|
+
return (e = this._activeFilterData) == null ? void 0 : e.backTexture;
|
|
208
|
+
}
|
|
209
|
+
push(e) {
|
|
210
|
+
var f;
|
|
211
|
+
const t = this.renderer, r = e.filterEffect.filters;
|
|
212
|
+
this._filterStack[this._filterStackIndex] || (this._filterStack[this._filterStackIndex] = this._getFilterData());
|
|
213
|
+
const s = this._filterStack[this._filterStackIndex];
|
|
214
|
+
if (this._filterStackIndex++, r.length === 0) {
|
|
215
|
+
s.skip = !0;
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const n = s.bounds;
|
|
219
|
+
e.renderables ? Ht(e.renderables, n) : e.filterEffect.filterArea ? (n.clear(), n.addRect(e.filterEffect.filterArea), n.applyMatrix(e.container.worldTransform)) : zt(e.container, n);
|
|
220
|
+
const a = t.renderTarget.rootRenderTarget.colorTexture.source;
|
|
221
|
+
let o = a._resolution, c = 0, l = a.antialias, h = !1, d = !1;
|
|
222
|
+
for (let p = 0; p < r.length; p++) {
|
|
223
|
+
const g = r[p];
|
|
224
|
+
if (o = Math.min(o, g.resolution), c += g.padding, g.antialias !== "inherit" && (g.antialias === "on" ? l = !0 : l = !1), !!!(g.compatibleRenderers & t.type)) {
|
|
225
|
+
d = !1;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
if (g.blendRequired && !(((f = t.backBuffer) == null ? void 0 : f.useBackBuffer) ?? !0)) {
|
|
229
|
+
L("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."), d = !1;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
d = g.enabled || d, h = h || g.blendRequired;
|
|
233
|
+
}
|
|
234
|
+
if (!d) {
|
|
235
|
+
s.skip = !0;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const u = t.renderTarget.rootViewPort;
|
|
239
|
+
if (n.scale(o).fitBounds(0, u.width, 0, u.height).scale(1 / o).pad(c).ceil(), !n.isPositive) {
|
|
240
|
+
s.skip = !0;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
s.skip = !1, s.bounds = n, s.blendRequired = h, s.container = e.container, s.filterEffect = e.filterEffect, s.previousRenderSurface = t.renderTarget.renderSurface, s.inputTexture = A.getOptimalTexture(
|
|
244
|
+
n.width,
|
|
245
|
+
n.height,
|
|
246
|
+
o,
|
|
247
|
+
l
|
|
248
|
+
), t.renderTarget.bind(s.inputTexture, !0), t.globalUniforms.push({
|
|
249
|
+
offset: n
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
pop() {
|
|
253
|
+
const e = this.renderer;
|
|
254
|
+
this._filterStackIndex--;
|
|
255
|
+
const t = this._filterStack[this._filterStackIndex];
|
|
256
|
+
if (t.skip)
|
|
257
|
+
return;
|
|
258
|
+
this._activeFilterData = t;
|
|
259
|
+
const r = t.inputTexture, s = t.bounds;
|
|
260
|
+
let n = R.EMPTY;
|
|
261
|
+
if (e.renderTarget.finishRenderPass(), t.blendRequired) {
|
|
262
|
+
const o = this._filterStackIndex > 0 ? this._filterStack[this._filterStackIndex - 1].bounds : null, c = e.renderTarget.getRenderTarget(t.previousRenderSurface);
|
|
263
|
+
n = this.getBackTexture(c, s, o);
|
|
264
|
+
}
|
|
265
|
+
t.backTexture = n;
|
|
266
|
+
const a = t.filterEffect.filters;
|
|
267
|
+
if (this._globalFilterBindGroup.setResource(r.source.style, 2), this._globalFilterBindGroup.setResource(n.source, 3), e.globalUniforms.pop(), a.length === 1)
|
|
268
|
+
a[0].apply(this, r, t.previousRenderSurface, !1), A.returnTexture(r);
|
|
269
|
+
else {
|
|
270
|
+
let o = t.inputTexture, c = A.getOptimalTexture(
|
|
271
|
+
s.width,
|
|
272
|
+
s.height,
|
|
273
|
+
o.source._resolution,
|
|
274
|
+
!1
|
|
275
|
+
), l = 0;
|
|
276
|
+
for (l = 0; l < a.length - 1; ++l) {
|
|
277
|
+
a[l].apply(this, o, c, !0);
|
|
278
|
+
const d = o;
|
|
279
|
+
o = c, c = d;
|
|
280
|
+
}
|
|
281
|
+
a[l].apply(this, o, t.previousRenderSurface, !1), A.returnTexture(o), A.returnTexture(c);
|
|
282
|
+
}
|
|
283
|
+
t.blendRequired && A.returnTexture(n);
|
|
284
|
+
}
|
|
285
|
+
getBackTexture(e, t, r) {
|
|
286
|
+
const s = e.colorTexture.source._resolution, n = A.getOptimalTexture(
|
|
287
|
+
t.width,
|
|
288
|
+
t.height,
|
|
289
|
+
s,
|
|
290
|
+
!1
|
|
291
|
+
);
|
|
292
|
+
let a = t.minX, o = t.minY;
|
|
293
|
+
r && (a -= r.minX, o -= r.minY), a = Math.floor(a * s), o = Math.floor(o * s);
|
|
294
|
+
const c = Math.ceil(t.width * s), l = Math.ceil(t.height * s);
|
|
295
|
+
return this.renderer.renderTarget.copyToTexture(
|
|
296
|
+
e,
|
|
297
|
+
n,
|
|
298
|
+
{ x: a, y: o },
|
|
299
|
+
{ width: c, height: l },
|
|
300
|
+
{ x: 0, y: 0 }
|
|
301
|
+
), n;
|
|
302
|
+
}
|
|
303
|
+
applyFilter(e, t, r, s) {
|
|
304
|
+
const n = this.renderer, a = this._filterStack[this._filterStackIndex], o = a.bounds, c = gt.shared, h = a.previousRenderSurface === r;
|
|
305
|
+
let d = this.renderer.renderTarget.rootRenderTarget.colorTexture.source._resolution, u = this._filterStackIndex - 1;
|
|
306
|
+
for (; u > 0 && this._filterStack[u].skip; )
|
|
307
|
+
--u;
|
|
308
|
+
u > 0 && (d = this._filterStack[u].inputTexture.source._resolution);
|
|
309
|
+
const f = this._filterGlobalUniforms, p = f.uniforms, g = p.uOutputFrame, m = p.uInputSize, x = p.uInputPixel, _ = p.uInputClamp, y = p.uGlobalFrame, T = p.uOutputTexture;
|
|
310
|
+
if (h) {
|
|
311
|
+
let v = this._filterStackIndex;
|
|
312
|
+
for (; v > 0; ) {
|
|
313
|
+
v--;
|
|
314
|
+
const S = this._filterStack[this._filterStackIndex - 1];
|
|
315
|
+
if (!S.skip) {
|
|
316
|
+
c.x = S.bounds.minX, c.y = S.bounds.minY;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
g[0] = o.minX - c.x, g[1] = o.minY - c.y;
|
|
321
|
+
} else
|
|
322
|
+
g[0] = 0, g[1] = 0;
|
|
323
|
+
g[2] = t.frame.width, g[3] = t.frame.height, m[0] = t.source.width, m[1] = t.source.height, m[2] = 1 / m[0], m[3] = 1 / m[1], x[0] = t.source.pixelWidth, x[1] = t.source.pixelHeight, x[2] = 1 / x[0], x[3] = 1 / x[1], _[0] = 0.5 * x[2], _[1] = 0.5 * x[3], _[2] = t.frame.width * m[2] - 0.5 * x[2], _[3] = t.frame.height * m[3] - 0.5 * x[3];
|
|
324
|
+
const w = this.renderer.renderTarget.rootRenderTarget.colorTexture;
|
|
325
|
+
y[0] = c.x * d, y[1] = c.y * d, y[2] = w.source.width * d, y[3] = w.source.height * d;
|
|
326
|
+
const F = this.renderer.renderTarget.getRenderTarget(r);
|
|
327
|
+
if (n.renderTarget.bind(r, !!s), r instanceof R ? (T[0] = r.frame.width, T[1] = r.frame.height) : (T[0] = F.width, T[1] = F.height), T[2] = F.isRoot ? -1 : 1, f.update(), n.renderPipes.uniformBatch) {
|
|
328
|
+
const v = n.renderPipes.uniformBatch.getUboResource(f);
|
|
329
|
+
this._globalFilterBindGroup.setResource(v, 0);
|
|
330
|
+
} else
|
|
331
|
+
this._globalFilterBindGroup.setResource(f, 0);
|
|
332
|
+
this._globalFilterBindGroup.setResource(t.source, 1), this._globalFilterBindGroup.setResource(t.source.style, 2), e.groups[0] = this._globalFilterBindGroup, n.encoder.draw({
|
|
333
|
+
geometry: It,
|
|
334
|
+
shader: e,
|
|
335
|
+
state: e._state,
|
|
336
|
+
topology: "triangle-list"
|
|
337
|
+
}), n.type === ne.WEBGL && n.renderTarget.finishRenderPass();
|
|
338
|
+
}
|
|
339
|
+
_getFilterData() {
|
|
340
|
+
return {
|
|
341
|
+
skip: !1,
|
|
342
|
+
inputTexture: null,
|
|
343
|
+
bounds: new Re(),
|
|
344
|
+
container: null,
|
|
345
|
+
filterEffect: null,
|
|
346
|
+
blendRequired: !1,
|
|
347
|
+
previousRenderSurface: null
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Multiply _input normalized coordinates_ to this matrix to get _sprite texture normalized coordinates_.
|
|
352
|
+
*
|
|
353
|
+
* Use `outputMatrix * vTextureCoord` in the shader.
|
|
354
|
+
* @param outputMatrix - The matrix to output to.
|
|
355
|
+
* @param {Sprite} sprite - The sprite to map to.
|
|
356
|
+
* @returns The mapped matrix.
|
|
357
|
+
*/
|
|
358
|
+
calculateSpriteMatrix(e, t) {
|
|
359
|
+
const r = this._activeFilterData, s = e.set(
|
|
360
|
+
r.inputTexture._source.width,
|
|
361
|
+
0,
|
|
362
|
+
0,
|
|
363
|
+
r.inputTexture._source.height,
|
|
364
|
+
r.bounds.minX,
|
|
365
|
+
r.bounds.minY
|
|
366
|
+
), n = t.worldTransform.copyTo(U.shared);
|
|
367
|
+
return n.invert(), s.prepend(n), s.scale(
|
|
368
|
+
1 / t.texture.frame.width,
|
|
369
|
+
1 / t.texture.frame.height
|
|
370
|
+
), s.translate(t.anchor.x, t.anchor.y), s;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
Ee.extension = {
|
|
374
|
+
type: [
|
|
375
|
+
b.WebGLSystem,
|
|
376
|
+
b.WebGPUSystem
|
|
377
|
+
],
|
|
378
|
+
name: "filter"
|
|
379
|
+
};
|
|
380
|
+
const $e = class Ye extends Fe {
|
|
381
|
+
constructor(...e) {
|
|
382
|
+
let t = e[0] ?? {};
|
|
383
|
+
t instanceof Float32Array && (k(H, "use new MeshGeometry({ positions, uvs, indices }) instead"), t = {
|
|
384
|
+
positions: t,
|
|
385
|
+
uvs: e[1],
|
|
386
|
+
indices: e[2]
|
|
387
|
+
}), t = { ...Ye.defaultOptions, ...t };
|
|
388
|
+
const r = t.positions || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), s = t.uvs || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), n = t.indices || new Uint32Array([0, 1, 2, 0, 2, 3]), a = t.shrinkBuffersToFit, o = new Q({
|
|
389
|
+
data: r,
|
|
390
|
+
label: "attribute-mesh-positions",
|
|
391
|
+
shrinkToFit: a,
|
|
392
|
+
usage: D.VERTEX | D.COPY_DST
|
|
393
|
+
}), c = new Q({
|
|
394
|
+
data: s,
|
|
395
|
+
label: "attribute-mesh-uvs",
|
|
396
|
+
shrinkToFit: a,
|
|
397
|
+
usage: D.VERTEX | D.COPY_DST
|
|
398
|
+
}), l = new Q({
|
|
399
|
+
data: n,
|
|
400
|
+
label: "index-mesh-buffer",
|
|
401
|
+
shrinkToFit: a,
|
|
402
|
+
usage: D.INDEX | D.COPY_DST
|
|
403
|
+
});
|
|
404
|
+
super({
|
|
405
|
+
attributes: {
|
|
406
|
+
aPosition: {
|
|
407
|
+
buffer: o,
|
|
408
|
+
format: "float32x2",
|
|
409
|
+
stride: 2 * 4,
|
|
410
|
+
offset: 0
|
|
411
|
+
},
|
|
412
|
+
aUV: {
|
|
413
|
+
buffer: c,
|
|
414
|
+
format: "float32x2",
|
|
415
|
+
stride: 2 * 4,
|
|
416
|
+
offset: 0
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
indexBuffer: l,
|
|
420
|
+
topology: t.topology
|
|
421
|
+
}), this.batchMode = "auto";
|
|
422
|
+
}
|
|
423
|
+
/** The positions of the mesh. */
|
|
424
|
+
get positions() {
|
|
425
|
+
return this.attributes.aPosition.buffer.data;
|
|
426
|
+
}
|
|
427
|
+
set positions(e) {
|
|
428
|
+
this.attributes.aPosition.buffer.data = e;
|
|
429
|
+
}
|
|
430
|
+
/** The UVs of the mesh. */
|
|
431
|
+
get uvs() {
|
|
432
|
+
return this.attributes.aUV.buffer.data;
|
|
433
|
+
}
|
|
434
|
+
set uvs(e) {
|
|
435
|
+
this.attributes.aUV.buffer.data = e;
|
|
436
|
+
}
|
|
437
|
+
/** The indices of the mesh. */
|
|
438
|
+
get indices() {
|
|
439
|
+
return this.indexBuffer.data;
|
|
440
|
+
}
|
|
441
|
+
set indices(e) {
|
|
442
|
+
this.indexBuffer.data = e;
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
$e.defaultOptions = {
|
|
446
|
+
topology: "triangle-list",
|
|
447
|
+
shrinkBuffersToFit: !1
|
|
448
|
+
};
|
|
449
|
+
let oe = $e;
|
|
450
|
+
function K(i, e) {
|
|
451
|
+
if (i.texture === R.WHITE && !i.fill)
|
|
452
|
+
return I.shared.setValue(i.color).toHex();
|
|
453
|
+
if (i.fill) {
|
|
454
|
+
if (i.fill instanceof mt) {
|
|
455
|
+
const t = i.fill, r = e.createPattern(t.texture.source.resource, "repeat"), s = t.transform.copyTo(U.shared);
|
|
456
|
+
return s.scale(
|
|
457
|
+
t.texture.frame.width,
|
|
458
|
+
t.texture.frame.height
|
|
459
|
+
), r.setTransform(s), r;
|
|
460
|
+
} else if (i.fill instanceof xt) {
|
|
461
|
+
const t = i.fill;
|
|
462
|
+
if (t.type === "linear") {
|
|
463
|
+
const r = e.createLinearGradient(
|
|
464
|
+
t.x0,
|
|
465
|
+
t.y0,
|
|
466
|
+
t.x1,
|
|
467
|
+
t.y1
|
|
468
|
+
);
|
|
469
|
+
return t.gradientStops.forEach((s) => {
|
|
470
|
+
r.addColorStop(s.offset, I.shared.setValue(s.color).toHex());
|
|
471
|
+
}), r;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
const t = e.createPattern(i.texture.source.resource, "repeat"), r = i.matrix.copyTo(U.shared);
|
|
476
|
+
return r.scale(i.texture.frame.width, i.texture.frame.height), t.setTransform(r), t;
|
|
477
|
+
}
|
|
478
|
+
return L("FillStyle not recognised", i), "red";
|
|
479
|
+
}
|
|
480
|
+
class Xe extends _t {
|
|
481
|
+
constructor() {
|
|
482
|
+
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.baseMeasurementFontSize = 100, this.baseRenderedFontSize = 100;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* The name of the font face.
|
|
486
|
+
* @deprecated since 8.0.0 Use `fontFamily` instead.
|
|
487
|
+
*/
|
|
488
|
+
get font() {
|
|
489
|
+
return k(H, "BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead."), this.fontFamily;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* The map of base page textures (i.e., sheets of glyphs).
|
|
493
|
+
* @deprecated since 8.0.0 Use `pages` instead.
|
|
494
|
+
*/
|
|
495
|
+
get pageTextures() {
|
|
496
|
+
return k(H, "BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."), this.pages;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* The size of the font face in pixels.
|
|
500
|
+
* @deprecated since 8.0.0 Use `fontMetrics.fontSize` instead.
|
|
501
|
+
*/
|
|
502
|
+
get size() {
|
|
503
|
+
return k(H, "BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead."), this.fontMetrics.fontSize;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* The kind of distance field for this font or "none".
|
|
507
|
+
* @deprecated since 8.0.0 Use `distanceField.type` instead.
|
|
508
|
+
*/
|
|
509
|
+
get distanceFieldRange() {
|
|
510
|
+
return k(H, "BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead."), this.distanceField.range;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* The range of the distance field in pixels.
|
|
514
|
+
* @deprecated since 8.0.0 Use `distanceField.range` instead.
|
|
515
|
+
*/
|
|
516
|
+
get distanceFieldType() {
|
|
517
|
+
return k(H, "BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead."), this.distanceField.type;
|
|
518
|
+
}
|
|
519
|
+
destroy(e = !1) {
|
|
520
|
+
this.emit("destroy", this), this.removeAllListeners();
|
|
521
|
+
for (const t in this.chars)
|
|
522
|
+
this.chars[t].texture.destroy();
|
|
523
|
+
this.chars = null, e && (this.pages.forEach((t) => t.texture.destroy(!0)), this.pages = null);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
function je(i) {
|
|
527
|
+
if (i === "")
|
|
528
|
+
return [];
|
|
529
|
+
typeof i == "string" && (i = [i]);
|
|
530
|
+
const e = [];
|
|
531
|
+
for (let t = 0, r = i.length; t < r; t++) {
|
|
532
|
+
const s = i[t];
|
|
533
|
+
if (Array.isArray(s)) {
|
|
534
|
+
if (s.length !== 2)
|
|
535
|
+
throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${s.length}.`);
|
|
536
|
+
if (s[0].length === 0 || s[1].length === 0)
|
|
537
|
+
throw new Error("[BitmapFont]: Invalid character delimiter.");
|
|
538
|
+
const n = s[0].charCodeAt(0), a = s[1].charCodeAt(0);
|
|
539
|
+
if (a < n)
|
|
540
|
+
throw new Error("[BitmapFont]: Invalid character range.");
|
|
541
|
+
for (let o = n, c = a; o <= c; o++)
|
|
542
|
+
e.push(String.fromCharCode(o));
|
|
543
|
+
} else
|
|
544
|
+
e.push(...Array.from(s));
|
|
545
|
+
}
|
|
546
|
+
if (e.length === 0)
|
|
547
|
+
throw new Error("[BitmapFont]: Empty set when resolving characters.");
|
|
548
|
+
return e;
|
|
549
|
+
}
|
|
550
|
+
class me extends Xe {
|
|
551
|
+
/**
|
|
552
|
+
* @param options - The options for the dynamic bitmap font.
|
|
553
|
+
*/
|
|
554
|
+
constructor(e) {
|
|
555
|
+
super(), this.resolution = 1, this.pages = [], this._padding = 4, this._measureCache = /* @__PURE__ */ Object.create(null), this._currentChars = [], this._currentX = 0, this._currentY = 0, this._currentPageIndex = -1, this._skipKerning = !1;
|
|
556
|
+
const t = e, r = t.style.clone();
|
|
557
|
+
t.overrideFill && (r._fill.color = 16777215, r._fill.alpha = 1, r._fill.texture = R.WHITE, r._fill.fill = null);
|
|
558
|
+
const s = r.fontSize;
|
|
559
|
+
r.fontSize = this.baseMeasurementFontSize;
|
|
560
|
+
const n = re(r);
|
|
561
|
+
t.overrideSize ? r._stroke && (r._stroke.width *= this.baseRenderedFontSize / s) : r.fontSize = this.baseRenderedFontSize = s, this._style = r, this._skipKerning = t.skipKerning ?? !1, this.resolution = t.resolution ?? 1, this._padding = t.padding ?? 4, this.fontMetrics = z.measureFont(n), this.lineHeight = r.lineHeight || this.fontMetrics.fontSize || r.fontSize;
|
|
562
|
+
}
|
|
563
|
+
ensureCharacters(e) {
|
|
564
|
+
var g, m;
|
|
565
|
+
const t = je(e).filter((x) => !this._currentChars.includes(x)).filter((x, _, y) => y.indexOf(x) === _);
|
|
566
|
+
if (!t.length)
|
|
567
|
+
return;
|
|
568
|
+
this._currentChars = [...this._currentChars, ...t];
|
|
569
|
+
let r;
|
|
570
|
+
this._currentPageIndex === -1 ? r = this._nextPage() : r = this.pages[this._currentPageIndex];
|
|
571
|
+
let { canvas: s, context: n } = r.canvasAndContext, a = r.texture.source;
|
|
572
|
+
const o = this._style;
|
|
573
|
+
let c = this._currentX, l = this._currentY;
|
|
574
|
+
const h = this.baseRenderedFontSize / this.baseMeasurementFontSize, d = this._padding * h, u = o.fontStyle === "italic" ? 2 : 1;
|
|
575
|
+
let f = 0, p = !1;
|
|
576
|
+
for (let x = 0; x < t.length; x++) {
|
|
577
|
+
const _ = t[x], y = z.measureText(_, o, s, !1);
|
|
578
|
+
y.lineHeight = y.height;
|
|
579
|
+
const T = u * y.width * h, w = y.height * h, F = T + d * 2, v = w + d * 2;
|
|
580
|
+
if (p = !1, _ !== `
|
|
581
|
+
` && _ !== "\r" && _ !== " " && _ !== " " && (p = !0, f = Math.ceil(Math.max(v, f))), c + F > 512 && (l += f, f = v, c = 0, l + f > 512)) {
|
|
582
|
+
a.update();
|
|
583
|
+
const G = this._nextPage();
|
|
584
|
+
s = G.canvasAndContext.canvas, n = G.canvasAndContext.context, a = G.texture.source, l = 0;
|
|
585
|
+
}
|
|
586
|
+
const S = T / h - (((g = o.dropShadow) == null ? void 0 : g.distance) ?? 0) - (((m = o._stroke) == null ? void 0 : m.width) ?? 0);
|
|
587
|
+
if (this.chars[_] = {
|
|
588
|
+
id: _.codePointAt(0),
|
|
589
|
+
xOffset: -this._padding,
|
|
590
|
+
yOffset: -this._padding,
|
|
591
|
+
xAdvance: S,
|
|
592
|
+
kerning: {}
|
|
593
|
+
}, p) {
|
|
594
|
+
this._drawGlyph(
|
|
595
|
+
n,
|
|
596
|
+
y,
|
|
597
|
+
c + d,
|
|
598
|
+
l + d,
|
|
599
|
+
h,
|
|
600
|
+
o
|
|
601
|
+
);
|
|
602
|
+
const G = a.width * h, O = a.height * h, N = new V(
|
|
603
|
+
c / G * a.width,
|
|
604
|
+
l / O * a.height,
|
|
605
|
+
F / G * a.width,
|
|
606
|
+
v / O * a.height
|
|
607
|
+
);
|
|
608
|
+
this.chars[_].texture = new R({
|
|
609
|
+
source: a,
|
|
610
|
+
frame: N
|
|
611
|
+
}), c += Math.ceil(F);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
a.update(), this._currentX = c, this._currentY = l, this._skipKerning && this._applyKerning(t, n);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* @deprecated since 8.0.0
|
|
618
|
+
* The map of base page textures (i.e., sheets of glyphs).
|
|
619
|
+
*/
|
|
620
|
+
get pageTextures() {
|
|
621
|
+
return k(H, "BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."), this.pages;
|
|
622
|
+
}
|
|
623
|
+
_applyKerning(e, t) {
|
|
624
|
+
const r = this._measureCache;
|
|
625
|
+
for (let s = 0; s < e.length; s++) {
|
|
626
|
+
const n = e[s];
|
|
627
|
+
for (let a = 0; a < this._currentChars.length; a++) {
|
|
628
|
+
const o = this._currentChars[a];
|
|
629
|
+
let c = r[n];
|
|
630
|
+
c || (c = r[n] = t.measureText(n).width);
|
|
631
|
+
let l = r[o];
|
|
632
|
+
l || (l = r[o] = t.measureText(o).width);
|
|
633
|
+
let h = t.measureText(n + o).width, d = h - (c + l);
|
|
634
|
+
d && (this.chars[n].kerning[o] = d), h = t.measureText(n + o).width, d = h - (c + l), d && (this.chars[o].kerning[n] = d);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
_nextPage() {
|
|
639
|
+
this._currentPageIndex++;
|
|
640
|
+
const e = this.resolution, t = W.getOptimalCanvasAndContext(512, 512, e);
|
|
641
|
+
this._setupContext(t.context, this._style, e);
|
|
642
|
+
const r = e * (this.baseRenderedFontSize / this.baseMeasurementFontSize), s = new R({
|
|
643
|
+
source: new bt({
|
|
644
|
+
resource: t.canvas,
|
|
645
|
+
resolution: r,
|
|
646
|
+
alphaMode: "premultiply-alpha-on-upload"
|
|
647
|
+
})
|
|
648
|
+
}), n = {
|
|
649
|
+
canvasAndContext: t,
|
|
650
|
+
texture: s
|
|
651
|
+
};
|
|
652
|
+
return this.pages[this._currentPageIndex] = n, n;
|
|
653
|
+
}
|
|
654
|
+
// canvas style!
|
|
655
|
+
_setupContext(e, t, r) {
|
|
656
|
+
t.fontSize = this.baseRenderedFontSize, e.scale(r, r), e.font = re(t), t.fontSize = this.baseMeasurementFontSize, e.textBaseline = t.textBaseline;
|
|
657
|
+
const s = t._stroke, n = (s == null ? void 0 : s.width) ?? 0;
|
|
658
|
+
if (s && (e.lineWidth = n, e.lineJoin = s.join, e.miterLimit = s.miterLimit, e.strokeStyle = K(s, e)), t._fill && (e.fillStyle = K(t._fill, e)), t.dropShadow) {
|
|
659
|
+
const a = t.dropShadow, o = I.shared.setValue(a.color).toArray(), c = a.blur * r, l = a.distance * r;
|
|
660
|
+
e.shadowColor = `rgba(${o[0] * 255},${o[1] * 255},${o[2] * 255},${a.alpha})`, e.shadowBlur = c, e.shadowOffsetX = Math.cos(a.angle) * l, e.shadowOffsetY = Math.sin(a.angle) * l;
|
|
661
|
+
} else
|
|
662
|
+
e.shadowColor = "black", e.shadowBlur = 0, e.shadowOffsetX = 0, e.shadowOffsetY = 0;
|
|
663
|
+
}
|
|
664
|
+
_drawGlyph(e, t, r, s, n, a) {
|
|
665
|
+
const o = t.text, c = t.fontProperties, l = a._stroke, h = ((l == null ? void 0 : l.width) ?? 0) * n, d = r + h / 2, u = s - h / 2, f = c.descent * n, p = t.lineHeight * n;
|
|
666
|
+
a.stroke && h && e.strokeText(o, d, u + p - f), a._fill && e.fillText(o, d, u + p - f);
|
|
667
|
+
}
|
|
668
|
+
destroy() {
|
|
669
|
+
super.destroy();
|
|
670
|
+
for (let e = 0; e < this.pages.length; e++) {
|
|
671
|
+
const { canvasAndContext: t, texture: r } = this.pages[e];
|
|
672
|
+
W.returnCanvasAndContext(t), r.destroy(!0);
|
|
673
|
+
}
|
|
674
|
+
this.pages = null;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function Ve(i, e, t) {
|
|
678
|
+
const r = {
|
|
679
|
+
width: 0,
|
|
680
|
+
height: 0,
|
|
681
|
+
offsetY: 0,
|
|
682
|
+
scale: e.fontSize / t.baseMeasurementFontSize,
|
|
683
|
+
lines: [{
|
|
684
|
+
width: 0,
|
|
685
|
+
charPositions: [],
|
|
686
|
+
spaceWidth: 0,
|
|
687
|
+
spacesIndex: [],
|
|
688
|
+
chars: []
|
|
689
|
+
}]
|
|
690
|
+
};
|
|
691
|
+
r.offsetY = t.baseLineOffset;
|
|
692
|
+
let s = r.lines[0], n = null, a = !0;
|
|
693
|
+
const o = {
|
|
694
|
+
spaceWord: !1,
|
|
695
|
+
width: 0,
|
|
696
|
+
start: 0,
|
|
697
|
+
index: 0,
|
|
698
|
+
// use index to not modify the array as we use it a lot!
|
|
699
|
+
positions: [],
|
|
700
|
+
chars: []
|
|
701
|
+
}, c = (f) => {
|
|
702
|
+
const p = s.width;
|
|
703
|
+
for (let g = 0; g < o.index; g++) {
|
|
704
|
+
const m = f.positions[g];
|
|
705
|
+
s.chars.push(f.chars[g]), s.charPositions.push(m + p);
|
|
706
|
+
}
|
|
707
|
+
s.width += f.width, a = !1, o.width = 0, o.index = 0, o.chars.length = 0;
|
|
708
|
+
}, l = () => {
|
|
709
|
+
let f = s.chars.length - 1, p = s.chars[f];
|
|
710
|
+
for (; p === " "; )
|
|
711
|
+
s.width -= t.chars[p].xAdvance, p = s.chars[--f];
|
|
712
|
+
r.width = Math.max(r.width, s.width), s = {
|
|
713
|
+
width: 0,
|
|
714
|
+
charPositions: [],
|
|
715
|
+
chars: [],
|
|
716
|
+
spaceWidth: 0,
|
|
717
|
+
spacesIndex: []
|
|
718
|
+
}, a = !0, r.lines.push(s), r.height += t.lineHeight;
|
|
719
|
+
}, h = t.baseMeasurementFontSize / e.fontSize, d = e.letterSpacing * h, u = e.wordWrapWidth * h;
|
|
720
|
+
for (let f = 0; f < i.length + 1; f++) {
|
|
721
|
+
let p;
|
|
722
|
+
const g = f === i.length;
|
|
723
|
+
g || (p = i[f]);
|
|
724
|
+
const m = t.chars[p] || t.chars[" "];
|
|
725
|
+
if (/(?:\s)/.test(p) || p === "\r" || p === `
|
|
726
|
+
` || g) {
|
|
727
|
+
if (!a && e.wordWrap && s.width + o.width - d > u ? (l(), c(o), g || s.charPositions.push(0)) : (o.start = s.width, c(o), g || s.charPositions.push(0)), p === "\r" || p === `
|
|
728
|
+
`)
|
|
729
|
+
s.width !== 0 && l();
|
|
730
|
+
else if (!g) {
|
|
731
|
+
const T = m.xAdvance + (m.kerning[n] || 0) + d;
|
|
732
|
+
s.width += T, s.spaceWidth = T, s.spacesIndex.push(s.charPositions.length), s.chars.push(p);
|
|
733
|
+
}
|
|
734
|
+
} else {
|
|
735
|
+
const y = m.kerning[n] || 0, T = m.xAdvance + y + d;
|
|
736
|
+
o.positions[o.index++] = o.width + y, o.chars.push(p), o.width += T;
|
|
737
|
+
}
|
|
738
|
+
n = p;
|
|
739
|
+
}
|
|
740
|
+
return l(), e.align === "center" ? Wt(r) : e.align === "right" ? Ot(r) : e.align === "justify" && Dt(r), r;
|
|
741
|
+
}
|
|
742
|
+
function Wt(i) {
|
|
743
|
+
for (let e = 0; e < i.lines.length; e++) {
|
|
744
|
+
const t = i.lines[e], r = i.width / 2 - t.width / 2;
|
|
745
|
+
for (let s = 0; s < t.charPositions.length; s++)
|
|
746
|
+
t.charPositions[s] += r;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function Ot(i) {
|
|
750
|
+
for (let e = 0; e < i.lines.length; e++) {
|
|
751
|
+
const t = i.lines[e], r = i.width - t.width;
|
|
752
|
+
for (let s = 0; s < t.charPositions.length; s++)
|
|
753
|
+
t.charPositions[s] += r;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function Dt(i) {
|
|
757
|
+
const e = i.width;
|
|
758
|
+
for (let t = 0; t < i.lines.length; t++) {
|
|
759
|
+
const r = i.lines[t];
|
|
760
|
+
let s = 0, n = r.spacesIndex[s++], a = 0;
|
|
761
|
+
const o = r.spacesIndex.length, l = (e - r.width) / o;
|
|
762
|
+
for (let h = 0; h < r.charPositions.length; h++)
|
|
763
|
+
h === n && (n = r.spacesIndex[s++], a += l), r.charPositions[h] += a;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
class Lt {
|
|
767
|
+
constructor() {
|
|
768
|
+
this.ALPHA = [["a", "z"], ["A", "Z"], " "], this.NUMERIC = [["0", "9"]], this.ALPHANUMERIC = [["a", "z"], ["A", "Z"], ["0", "9"], " "], this.ASCII = [[" ", "~"]], this.defaultOptions = {
|
|
769
|
+
chars: this.ALPHANUMERIC,
|
|
770
|
+
resolution: 1,
|
|
771
|
+
padding: 4,
|
|
772
|
+
skipKerning: !1
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Get a font for the specified text and style.
|
|
777
|
+
* @param text - The text to get the font for
|
|
778
|
+
* @param style - The style to use
|
|
779
|
+
*/
|
|
780
|
+
getFont(e, t) {
|
|
781
|
+
var a;
|
|
782
|
+
let r = `${t.fontFamily}-bitmap`, s = !0;
|
|
783
|
+
if (t._fill.fill && (r += t._fill.fill.uid, s = !1), !M.has(r)) {
|
|
784
|
+
const o = new me({
|
|
785
|
+
style: t,
|
|
786
|
+
overrideFill: s,
|
|
787
|
+
overrideSize: !0,
|
|
788
|
+
...this.defaultOptions
|
|
789
|
+
});
|
|
790
|
+
o.once("destroy", () => M.remove(r)), M.set(
|
|
791
|
+
r,
|
|
792
|
+
o
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
const n = M.get(r);
|
|
796
|
+
return (a = n.ensureCharacters) == null || a.call(n, e), n;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Get the layout of a text for the specified style.
|
|
800
|
+
* @param text - The text to get the layout for
|
|
801
|
+
* @param style - The style to use
|
|
802
|
+
*/
|
|
803
|
+
getLayout(e, t) {
|
|
804
|
+
const r = this.getFont(e, t);
|
|
805
|
+
return Ve([...e], t, r);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Measure the text using the specified style.
|
|
809
|
+
* @param text - The text to measure
|
|
810
|
+
* @param style - The style to use
|
|
811
|
+
*/
|
|
812
|
+
measureText(e, t) {
|
|
813
|
+
return this.getLayout(e, t);
|
|
814
|
+
}
|
|
815
|
+
// eslint-disable-next-line max-len
|
|
816
|
+
install(...e) {
|
|
817
|
+
var l, h, d, u;
|
|
818
|
+
let t = e[0];
|
|
819
|
+
typeof t == "string" && (t = {
|
|
820
|
+
name: t,
|
|
821
|
+
style: e[1],
|
|
822
|
+
chars: (l = e[2]) == null ? void 0 : l.chars,
|
|
823
|
+
resolution: (h = e[2]) == null ? void 0 : h.resolution,
|
|
824
|
+
padding: (d = e[2]) == null ? void 0 : d.padding,
|
|
825
|
+
skipKerning: (u = e[2]) == null ? void 0 : u.skipKerning
|
|
826
|
+
}, k(H, "BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})"));
|
|
827
|
+
const r = t == null ? void 0 : t.name;
|
|
828
|
+
if (!r)
|
|
829
|
+
throw new Error("[BitmapFontManager] Property `name` is required.");
|
|
830
|
+
t = { ...this.defaultOptions, ...t };
|
|
831
|
+
const s = t.style, n = s instanceof E ? s : new E(s), a = n._fill.fill !== null && n._fill.fill !== void 0, o = new me({
|
|
832
|
+
style: n,
|
|
833
|
+
overrideFill: a,
|
|
834
|
+
skipKerning: t.skipKerning,
|
|
835
|
+
padding: t.padding,
|
|
836
|
+
resolution: t.resolution,
|
|
837
|
+
overrideSize: !1
|
|
838
|
+
}), c = je(t.chars);
|
|
839
|
+
return o.ensureCharacters(c.join("")), M.set(`${r}-bitmap`, o), o.once("destroy", () => M.remove(`${r}-bitmap`)), o;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Uninstalls a bitmap font from the cache.
|
|
843
|
+
* @param {string} name - The name of the bitmap font to uninstall.
|
|
844
|
+
*/
|
|
845
|
+
uninstall(e) {
|
|
846
|
+
const t = `${e}-bitmap`, r = M.get(t);
|
|
847
|
+
r && (M.remove(t), r.destroy());
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
const ie = new Lt();
|
|
851
|
+
function Et(i) {
|
|
852
|
+
const e = i._stroke, t = i._fill, s = [`div { ${[
|
|
853
|
+
`color: ${I.shared.setValue(t.color).toHex()}`,
|
|
854
|
+
`font-size: ${i.fontSize}px`,
|
|
855
|
+
`font-family: ${i.fontFamily}`,
|
|
856
|
+
`font-weight: ${i.fontWeight}`,
|
|
857
|
+
`font-style: ${i.fontStyle}`,
|
|
858
|
+
`font-variant: ${i.fontVariant}`,
|
|
859
|
+
`letter-spacing: ${i.letterSpacing}px`,
|
|
860
|
+
`text-align: ${i.align}`,
|
|
861
|
+
`padding: ${i.padding}px`,
|
|
862
|
+
`white-space: ${i.whiteSpace === "pre" && i.wordWrap ? "pre-wrap" : i.whiteSpace}`,
|
|
863
|
+
...i.lineHeight ? [`line-height: ${i.lineHeight}px`] : [],
|
|
864
|
+
...i.wordWrap ? [
|
|
865
|
+
`word-wrap: ${i.breakWords ? "break-all" : "break-word"}`,
|
|
866
|
+
`max-width: ${i.wordWrapWidth}px`
|
|
867
|
+
] : [],
|
|
868
|
+
...e ? [Ne(e)] : [],
|
|
869
|
+
...i.dropShadow ? [Ke(i.dropShadow)] : [],
|
|
870
|
+
...i.cssOverrides
|
|
871
|
+
].join(";")} }`];
|
|
872
|
+
return $t(i.tagStyles, s), s.join(" ");
|
|
873
|
+
}
|
|
874
|
+
function Ke(i) {
|
|
875
|
+
const e = I.shared.setValue(i.color).setAlpha(i.alpha).toHexa(), t = Math.round(Math.cos(i.angle) * i.distance), r = Math.round(Math.sin(i.angle) * i.distance), s = `${t}px ${r}px`;
|
|
876
|
+
return i.blur > 0 ? `text-shadow: ${s} ${i.blur}px ${e}` : `text-shadow: ${s} ${e}`;
|
|
877
|
+
}
|
|
878
|
+
function Ne(i) {
|
|
879
|
+
return [
|
|
880
|
+
`-webkit-text-stroke-width: ${i.width}px`,
|
|
881
|
+
`-webkit-text-stroke-color: ${I.shared.setValue(i.color).toHex()}`,
|
|
882
|
+
`text-stroke-width: ${i.width}px`,
|
|
883
|
+
`text-stroke-color: ${I.shared.setValue(i.color).toHex()}`,
|
|
884
|
+
"paint-order: stroke"
|
|
885
|
+
].join(";");
|
|
886
|
+
}
|
|
887
|
+
const xe = {
|
|
888
|
+
fontSize: "font-size: {{VALUE}}px",
|
|
889
|
+
fontFamily: "font-family: {{VALUE}}",
|
|
890
|
+
fontWeight: "font-weight: {{VALUE}}",
|
|
891
|
+
fontStyle: "font-style: {{VALUE}}",
|
|
892
|
+
fontVariant: "font-variant: {{VALUE}}",
|
|
893
|
+
letterSpacing: "letter-spacing: {{VALUE}}px",
|
|
894
|
+
align: "text-align: {{VALUE}}",
|
|
895
|
+
padding: "padding: {{VALUE}}px",
|
|
896
|
+
whiteSpace: "white-space: {{VALUE}}",
|
|
897
|
+
lineHeight: "line-height: {{VALUE}}px",
|
|
898
|
+
wordWrapWidth: "max-width: {{VALUE}}px"
|
|
899
|
+
}, _e = {
|
|
900
|
+
fill: (i) => `color: ${I.shared.setValue(i).toHex()}`,
|
|
901
|
+
breakWords: (i) => `word-wrap: ${i ? "break-all" : "break-word"}`,
|
|
902
|
+
stroke: Ne,
|
|
903
|
+
dropShadow: Ke
|
|
904
|
+
};
|
|
905
|
+
function $t(i, e) {
|
|
906
|
+
for (const t in i) {
|
|
907
|
+
const r = i[t], s = [];
|
|
908
|
+
for (const n in r)
|
|
909
|
+
_e[n] ? s.push(_e[n](r[n])) : xe[n] && s.push(xe[n].replace("{{VALUE}}", r[n]));
|
|
910
|
+
e.push(`${t} { ${s.join(";")} }`);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
class ce extends E {
|
|
914
|
+
constructor(e = {}) {
|
|
915
|
+
super(e), this._cssOverrides = [], this.cssOverrides ?? (this.cssOverrides = e.cssOverrides), this.tagStyles = e.tagStyles ?? {};
|
|
916
|
+
}
|
|
917
|
+
/** List of style overrides that will be applied to the HTML text. */
|
|
918
|
+
set cssOverrides(e) {
|
|
919
|
+
this._cssOverrides = e instanceof Array ? e : [e], this.update();
|
|
920
|
+
}
|
|
921
|
+
get cssOverrides() {
|
|
922
|
+
return this._cssOverrides;
|
|
923
|
+
}
|
|
924
|
+
_generateKey() {
|
|
925
|
+
return this._styleKey = yt(this) + this._cssOverrides.join("-"), this._styleKey;
|
|
926
|
+
}
|
|
927
|
+
update() {
|
|
928
|
+
this._cssStyle = null, super.update();
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Creates a new HTMLTextStyle object with the same values as this one.
|
|
932
|
+
* @returns New cloned HTMLTextStyle object
|
|
933
|
+
*/
|
|
934
|
+
clone() {
|
|
935
|
+
return new ce({
|
|
936
|
+
align: this.align,
|
|
937
|
+
breakWords: this.breakWords,
|
|
938
|
+
dropShadow: this.dropShadow,
|
|
939
|
+
fill: this._fill,
|
|
940
|
+
fontFamily: this.fontFamily,
|
|
941
|
+
fontSize: this.fontSize,
|
|
942
|
+
fontStyle: this.fontStyle,
|
|
943
|
+
fontVariant: this.fontVariant,
|
|
944
|
+
fontWeight: this.fontWeight,
|
|
945
|
+
letterSpacing: this.letterSpacing,
|
|
946
|
+
lineHeight: this.lineHeight,
|
|
947
|
+
padding: this.padding,
|
|
948
|
+
stroke: this._stroke,
|
|
949
|
+
whiteSpace: this.whiteSpace,
|
|
950
|
+
wordWrap: this.wordWrap,
|
|
951
|
+
wordWrapWidth: this.wordWrapWidth,
|
|
952
|
+
cssOverrides: this.cssOverrides
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
get cssStyle() {
|
|
956
|
+
return this._cssStyle || (this._cssStyle = Et(this)), this._cssStyle;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Add a style override, this can be any CSS property
|
|
960
|
+
* it will override any built-in style. This is the
|
|
961
|
+
* property and the value as a string (e.g., `color: red`).
|
|
962
|
+
* This will override any other internal style.
|
|
963
|
+
* @param {string} value - CSS style(s) to add.
|
|
964
|
+
* @example
|
|
965
|
+
* style.addOverride('background-color: red');
|
|
966
|
+
*/
|
|
967
|
+
addOverride(...e) {
|
|
968
|
+
const t = e.filter((r) => !this.cssOverrides.includes(r));
|
|
969
|
+
t.length > 0 && (this.cssOverrides.push(...t), this.update());
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Remove any overrides that match the value.
|
|
973
|
+
* @param {string} value - CSS style to remove.
|
|
974
|
+
* @example
|
|
975
|
+
* style.removeOverride('background-color: red');
|
|
976
|
+
*/
|
|
977
|
+
removeOverride(...e) {
|
|
978
|
+
const t = e.filter((r) => this.cssOverrides.includes(r));
|
|
979
|
+
t.length > 0 && (this.cssOverrides = this.cssOverrides.filter((r) => !t.includes(r)), this.update());
|
|
980
|
+
}
|
|
981
|
+
set fill(e) {
|
|
982
|
+
typeof e != "string" && typeof e != "number" && L("[HTMLTextStyle] only color fill is not supported by HTMLText"), super.fill = e;
|
|
983
|
+
}
|
|
984
|
+
set stroke(e) {
|
|
985
|
+
e && typeof e != "string" && typeof e != "number" && L("[HTMLTextStyle] only color stroke is not supported by HTMLText"), super.stroke = e;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const be = "http://www.w3.org/2000/svg", ye = "http://www.w3.org/1999/xhtml";
|
|
989
|
+
class qe {
|
|
990
|
+
constructor() {
|
|
991
|
+
this.svgRoot = document.createElementNS(be, "svg"), this.foreignObject = document.createElementNS(be, "foreignObject"), this.domElement = document.createElementNS(ye, "div"), this.styleElement = document.createElementNS(ye, "style"), this.image = new Image();
|
|
992
|
+
const { foreignObject: e, svgRoot: t, styleElement: r, domElement: s } = this;
|
|
993
|
+
e.setAttribute("width", "10000"), e.setAttribute("height", "10000"), e.style.overflow = "hidden", t.appendChild(e), e.appendChild(r), e.appendChild(s);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
let Te;
|
|
997
|
+
function Yt(i, e, t, r) {
|
|
998
|
+
r = r || Te || (Te = new qe());
|
|
999
|
+
const { domElement: s, styleElement: n, svgRoot: a } = r;
|
|
1000
|
+
s.innerHTML = `<style>${e.cssStyle}</style><div>${i}</div>`, s.setAttribute("style", "transform-origin: top left; display: inline-block"), t && (n.textContent = t), document.body.appendChild(a);
|
|
1001
|
+
const o = s.getBoundingClientRect();
|
|
1002
|
+
a.remove();
|
|
1003
|
+
const c = z.measureFont(e.fontStyle).descent;
|
|
1004
|
+
return {
|
|
1005
|
+
width: o.width,
|
|
1006
|
+
height: o.height + c
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
class Qe {
|
|
1010
|
+
constructor(e, t) {
|
|
1011
|
+
this.state = Ae.for2d(), this._graphicsBatchesHash = /* @__PURE__ */ Object.create(null), this.renderer = e, this._adaptor = t, this._adaptor.init();
|
|
1012
|
+
}
|
|
1013
|
+
validateRenderable(e) {
|
|
1014
|
+
const t = e.context, r = !!this._graphicsBatchesHash[e.uid], s = this.renderer.graphicsContext.updateGpuContext(t);
|
|
1015
|
+
return !!(s.isBatchable || r !== s.isBatchable);
|
|
1016
|
+
}
|
|
1017
|
+
addRenderable(e, t) {
|
|
1018
|
+
const r = this.renderer.graphicsContext.updateGpuContext(e.context);
|
|
1019
|
+
e._didGraphicsUpdate && (e._didGraphicsUpdate = !1, this._rebuild(e)), r.isBatchable ? this._addToBatcher(e, t) : (this.renderer.renderPipes.batch.break(t), t.add(e));
|
|
1020
|
+
}
|
|
1021
|
+
updateRenderable(e) {
|
|
1022
|
+
const t = this._graphicsBatchesHash[e.uid];
|
|
1023
|
+
if (t)
|
|
1024
|
+
for (let r = 0; r < t.length; r++) {
|
|
1025
|
+
const s = t[r];
|
|
1026
|
+
s.batcher.updateElement(s);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
destroyRenderable(e) {
|
|
1030
|
+
this._graphicsBatchesHash[e.uid] && this._removeBatchForRenderable(e.uid);
|
|
1031
|
+
}
|
|
1032
|
+
execute(e) {
|
|
1033
|
+
if (!e.isRenderable)
|
|
1034
|
+
return;
|
|
1035
|
+
const t = this.renderer, r = e.context;
|
|
1036
|
+
if (!t.graphicsContext.getGpuContext(r).batches.length)
|
|
1037
|
+
return;
|
|
1038
|
+
const n = r.customShader || this._adaptor.shader;
|
|
1039
|
+
this.state.blendMode = e.groupBlendMode;
|
|
1040
|
+
const a = n.resources.localUniforms.uniforms;
|
|
1041
|
+
a.uTransformMatrix = e.groupTransform, a.uRound = t._roundPixels | e._roundPixels, ae(
|
|
1042
|
+
e.groupColorAlpha,
|
|
1043
|
+
a.uColor,
|
|
1044
|
+
0
|
|
1045
|
+
), this._adaptor.execute(this, e);
|
|
1046
|
+
}
|
|
1047
|
+
_rebuild(e) {
|
|
1048
|
+
const t = !!this._graphicsBatchesHash[e.uid], r = this.renderer.graphicsContext.updateGpuContext(e.context);
|
|
1049
|
+
t && this._removeBatchForRenderable(e.uid), r.isBatchable && this._initBatchesForRenderable(e), e.batched = r.isBatchable;
|
|
1050
|
+
}
|
|
1051
|
+
_addToBatcher(e, t) {
|
|
1052
|
+
const r = this.renderer.renderPipes.batch, s = this._getBatchesForRenderable(e);
|
|
1053
|
+
for (let n = 0; n < s.length; n++) {
|
|
1054
|
+
const a = s[n];
|
|
1055
|
+
r.addToBatch(a, t);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
_getBatchesForRenderable(e) {
|
|
1059
|
+
return this._graphicsBatchesHash[e.uid] || this._initBatchesForRenderable(e);
|
|
1060
|
+
}
|
|
1061
|
+
_initBatchesForRenderable(e) {
|
|
1062
|
+
const t = e.context, r = this.renderer.graphicsContext.getGpuContext(t), s = this.renderer._roundPixels | e._roundPixels, n = r.batches.map((a) => {
|
|
1063
|
+
const o = B.get(Tt);
|
|
1064
|
+
return a.copyTo(o), o.renderable = e, o.roundPixels = s, o;
|
|
1065
|
+
});
|
|
1066
|
+
return this._graphicsBatchesHash[e.uid] === void 0 && e.on("destroyed", () => {
|
|
1067
|
+
this.destroyRenderable(e);
|
|
1068
|
+
}), this._graphicsBatchesHash[e.uid] = n, n;
|
|
1069
|
+
}
|
|
1070
|
+
_removeBatchForRenderable(e) {
|
|
1071
|
+
this._graphicsBatchesHash[e].forEach((t) => {
|
|
1072
|
+
B.return(t);
|
|
1073
|
+
}), this._graphicsBatchesHash[e] = null;
|
|
1074
|
+
}
|
|
1075
|
+
destroy() {
|
|
1076
|
+
this.renderer = null, this._adaptor.destroy(), this._adaptor = null, this.state = null;
|
|
1077
|
+
for (const e in this._graphicsBatchesHash)
|
|
1078
|
+
this._removeBatchForRenderable(e);
|
|
1079
|
+
this._graphicsBatchesHash = null;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
Qe.extension = {
|
|
1083
|
+
type: [
|
|
1084
|
+
b.WebGLPipes,
|
|
1085
|
+
b.WebGPUPipes,
|
|
1086
|
+
b.CanvasPipes
|
|
1087
|
+
],
|
|
1088
|
+
name: "graphics"
|
|
1089
|
+
};
|
|
1090
|
+
const Ze = class Je extends oe {
|
|
1091
|
+
constructor(...e) {
|
|
1092
|
+
super({});
|
|
1093
|
+
let t = e[0] ?? {};
|
|
1094
|
+
typeof t == "number" && (k(H, "PlaneGeometry constructor changed please use { width, height, verticesX, verticesY } instead"), t = {
|
|
1095
|
+
width: t,
|
|
1096
|
+
height: e[1],
|
|
1097
|
+
verticesX: e[2],
|
|
1098
|
+
verticesY: e[3]
|
|
1099
|
+
}), this.build(t);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Refreshes plane coordinates
|
|
1103
|
+
* @param options - Options to be applied to plane geometry
|
|
1104
|
+
*/
|
|
1105
|
+
build(e) {
|
|
1106
|
+
e = { ...Je.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;
|
|
1107
|
+
const t = this.verticesX * this.verticesY, r = [], s = [], n = [], a = this.verticesX - 1, o = this.verticesY - 1, c = this.width / a, l = this.height / o;
|
|
1108
|
+
for (let d = 0; d < t; d++) {
|
|
1109
|
+
const u = d % this.verticesX, f = d / this.verticesX | 0;
|
|
1110
|
+
r.push(u * c, f * l), s.push(u / a, f / o);
|
|
1111
|
+
}
|
|
1112
|
+
const h = a * o;
|
|
1113
|
+
for (let d = 0; d < h; d++) {
|
|
1114
|
+
const u = d % a, f = d / a | 0, p = f * this.verticesX + u, g = f * this.verticesX + u + 1, m = (f + 1) * this.verticesX + u, x = (f + 1) * this.verticesX + u + 1;
|
|
1115
|
+
n.push(
|
|
1116
|
+
p,
|
|
1117
|
+
g,
|
|
1118
|
+
m,
|
|
1119
|
+
g,
|
|
1120
|
+
x,
|
|
1121
|
+
m
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
this.buffers[0].data = new Float32Array(r), this.buffers[1].data = new Float32Array(s), this.indexBuffer.data = new Uint32Array(n), this.buffers[0].update(), this.buffers[1].update(), this.indexBuffer.update();
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
Ze.defaultOptions = {
|
|
1128
|
+
width: 100,
|
|
1129
|
+
height: 100,
|
|
1130
|
+
verticesX: 10,
|
|
1131
|
+
verticesY: 10
|
|
1132
|
+
};
|
|
1133
|
+
let Xt = Ze;
|
|
1134
|
+
class he {
|
|
1135
|
+
constructor() {
|
|
1136
|
+
this.batcher = null, this.batch = null, this.roundPixels = 0, this._uvUpdateId = -1, this._textureMatrixUpdateId = -1;
|
|
1137
|
+
}
|
|
1138
|
+
get blendMode() {
|
|
1139
|
+
return this.mesh.groupBlendMode;
|
|
1140
|
+
}
|
|
1141
|
+
reset() {
|
|
1142
|
+
this.mesh = null, this.texture = null, this.batcher = null, this.batch = null;
|
|
1143
|
+
}
|
|
1144
|
+
packIndex(e, t, r) {
|
|
1145
|
+
const s = this.geometry.indices;
|
|
1146
|
+
for (let n = 0; n < s.length; n++)
|
|
1147
|
+
e[t++] = s[n] + r;
|
|
1148
|
+
}
|
|
1149
|
+
packAttributes(e, t, r, s) {
|
|
1150
|
+
const n = this.mesh, a = this.geometry, o = n.groupTransform, c = s << 16 | this.roundPixels & 65535, l = o.a, h = o.b, d = o.c, u = o.d, f = o.tx, p = o.ty, g = a.positions, m = a.getBuffer("aUV"), x = m.data;
|
|
1151
|
+
let _ = x;
|
|
1152
|
+
const y = this.texture.textureMatrix;
|
|
1153
|
+
y.isSimple || (_ = this._transformedUvs, (this._textureMatrixUpdateId !== y._updateID || this._uvUpdateId !== m._updateID) && ((!_ || _.length < x.length) && (_ = this._transformedUvs = new Float32Array(x.length)), this._textureMatrixUpdateId = y._updateID, this._uvUpdateId = m._updateID, y.multiplyUvs(x, _)));
|
|
1154
|
+
const T = n.groupColorAlpha;
|
|
1155
|
+
for (let w = 0; w < g.length; w += 2) {
|
|
1156
|
+
const F = g[w], v = g[w + 1];
|
|
1157
|
+
e[r] = l * F + d * v + f, e[r + 1] = h * F + u * v + p, e[r + 2] = _[w], e[r + 3] = _[w + 1], t[r + 4] = T, t[r + 5] = c, r += 6;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
get vertexSize() {
|
|
1161
|
+
return this.geometry.positions.length / 2;
|
|
1162
|
+
}
|
|
1163
|
+
get indexSize() {
|
|
1164
|
+
return this.geometry.indices.length;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
class et {
|
|
1168
|
+
constructor(e, t) {
|
|
1169
|
+
this.localUniforms = new Y({
|
|
1170
|
+
uTransformMatrix: { value: new U(), type: "mat3x3<f32>" },
|
|
1171
|
+
uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
|
|
1172
|
+
uRound: { value: 0, type: "f32" }
|
|
1173
|
+
}), this.localUniformsBindGroup = new Me({
|
|
1174
|
+
0: this.localUniforms
|
|
1175
|
+
}), this._meshDataHash = /* @__PURE__ */ Object.create(null), this._gpuBatchableMeshHash = /* @__PURE__ */ Object.create(null), this.renderer = e, this._adaptor = t, this._adaptor.init();
|
|
1176
|
+
}
|
|
1177
|
+
validateRenderable(e) {
|
|
1178
|
+
const t = this._getMeshData(e), r = t.batched, s = e.batched;
|
|
1179
|
+
if (t.batched = s, r !== s)
|
|
1180
|
+
return !0;
|
|
1181
|
+
if (s) {
|
|
1182
|
+
const n = e._geometry;
|
|
1183
|
+
if (n.indices.length !== t.indexSize || n.positions.length !== t.vertexSize)
|
|
1184
|
+
return t.indexSize = n.indices.length, t.vertexSize = n.positions.length, !0;
|
|
1185
|
+
const a = this._getBatchableMesh(e), o = e.texture;
|
|
1186
|
+
if (a.texture._source !== o._source && a.texture._source !== o._source)
|
|
1187
|
+
return !a.batcher.checkAndUpdateTexture(a, o);
|
|
1188
|
+
}
|
|
1189
|
+
return !1;
|
|
1190
|
+
}
|
|
1191
|
+
addRenderable(e, t) {
|
|
1192
|
+
const r = this.renderer.renderPipes.batch, { batched: s } = this._getMeshData(e);
|
|
1193
|
+
if (s) {
|
|
1194
|
+
const n = this._getBatchableMesh(e);
|
|
1195
|
+
n.texture = e._texture, n.geometry = e._geometry, r.addToBatch(n);
|
|
1196
|
+
} else
|
|
1197
|
+
r.break(t), t.add({
|
|
1198
|
+
renderPipeId: "mesh",
|
|
1199
|
+
mesh: e
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
updateRenderable(e) {
|
|
1203
|
+
if (e.batched) {
|
|
1204
|
+
const t = this._gpuBatchableMeshHash[e.uid];
|
|
1205
|
+
t.texture = e._texture, t.geometry = e._geometry, t.batcher.updateElement(t);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
destroyRenderable(e) {
|
|
1209
|
+
this._meshDataHash[e.uid] = null;
|
|
1210
|
+
const t = this._gpuBatchableMeshHash[e.uid];
|
|
1211
|
+
t && (B.return(t), this._gpuBatchableMeshHash[e.uid] = null);
|
|
1212
|
+
}
|
|
1213
|
+
execute({ mesh: e }) {
|
|
1214
|
+
if (!e.isRenderable)
|
|
1215
|
+
return;
|
|
1216
|
+
e.state.blendMode = e.groupBlendMode;
|
|
1217
|
+
const t = this.localUniforms;
|
|
1218
|
+
t.uniforms.uTransformMatrix = e.groupTransform, t.uniforms.uRound = this.renderer._roundPixels | e._roundPixels, t.update(), ae(
|
|
1219
|
+
e.groupColorAlpha,
|
|
1220
|
+
t.uniforms.uColor,
|
|
1221
|
+
0
|
|
1222
|
+
), this._adaptor.execute(this, e);
|
|
1223
|
+
}
|
|
1224
|
+
_getMeshData(e) {
|
|
1225
|
+
return this._meshDataHash[e.uid] || this._initMeshData(e);
|
|
1226
|
+
}
|
|
1227
|
+
_initMeshData(e) {
|
|
1228
|
+
var t, r;
|
|
1229
|
+
return this._meshDataHash[e.uid] = {
|
|
1230
|
+
batched: e.batched,
|
|
1231
|
+
indexSize: (t = e._geometry.indices) == null ? void 0 : t.length,
|
|
1232
|
+
vertexSize: (r = e._geometry.positions) == null ? void 0 : r.length
|
|
1233
|
+
}, e.on("destroyed", () => {
|
|
1234
|
+
this.destroyRenderable(e);
|
|
1235
|
+
}), this._meshDataHash[e.uid];
|
|
1236
|
+
}
|
|
1237
|
+
_getBatchableMesh(e) {
|
|
1238
|
+
return this._gpuBatchableMeshHash[e.uid] || this._initBatchableMesh(e);
|
|
1239
|
+
}
|
|
1240
|
+
_initBatchableMesh(e) {
|
|
1241
|
+
const t = B.get(he);
|
|
1242
|
+
return t.mesh = e, t.texture = e._texture, t.roundPixels = this.renderer._roundPixels | e._roundPixels, this._gpuBatchableMeshHash[e.uid] = t, t.mesh = e, t;
|
|
1243
|
+
}
|
|
1244
|
+
destroy() {
|
|
1245
|
+
for (const e in this._gpuBatchableMeshHash)
|
|
1246
|
+
this._gpuBatchableMeshHash[e] && B.return(this._gpuBatchableMeshHash[e]);
|
|
1247
|
+
this._gpuBatchableMeshHash = null, this._meshDataHash = null, this.localUniforms = null, this.localUniformsBindGroup = null, this._adaptor.destroy(), this._adaptor = null, this.renderer = null;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
et.extension = {
|
|
1251
|
+
type: [
|
|
1252
|
+
b.WebGLPipes,
|
|
1253
|
+
b.WebGPUPipes,
|
|
1254
|
+
b.CanvasPipes
|
|
1255
|
+
],
|
|
1256
|
+
name: "mesh"
|
|
1257
|
+
};
|
|
1258
|
+
const tt = class rt extends Xt {
|
|
1259
|
+
constructor(e = {}) {
|
|
1260
|
+
e = { ...rt.defaultOptions, ...e }, super({
|
|
1261
|
+
width: e.width,
|
|
1262
|
+
height: e.height,
|
|
1263
|
+
verticesX: 4,
|
|
1264
|
+
verticesY: 4
|
|
1265
|
+
}), this.update(e);
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Updates the NineSliceGeometry with the options.
|
|
1269
|
+
* @param options - The options of the NineSliceGeometry.
|
|
1270
|
+
*/
|
|
1271
|
+
update(e) {
|
|
1272
|
+
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.updateUvs(), this.updatePositions();
|
|
1273
|
+
}
|
|
1274
|
+
/** Updates the positions of the vertices. */
|
|
1275
|
+
updatePositions() {
|
|
1276
|
+
const e = this.positions, t = this._leftWidth + this._rightWidth, r = this.width > t ? 1 : this.width / t, s = this._topHeight + this._bottomHeight, n = this.height > s ? 1 : this.height / s, a = Math.min(r, n);
|
|
1277
|
+
e[9] = e[11] = e[13] = e[15] = this._topHeight * a, e[17] = e[19] = e[21] = e[23] = this.height - this._bottomHeight * a, e[25] = e[27] = e[29] = e[31] = this.height, e[2] = e[10] = e[18] = e[26] = this._leftWidth * a, e[4] = e[12] = e[20] = e[28] = this.width - this._rightWidth * a, e[6] = e[14] = e[22] = e[30] = this.width, this.getBuffer("aPosition").update();
|
|
1278
|
+
}
|
|
1279
|
+
/** Updates the UVs of the vertices. */
|
|
1280
|
+
updateUvs() {
|
|
1281
|
+
const e = this.uvs;
|
|
1282
|
+
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;
|
|
1283
|
+
const t = 1 / this._originalWidth, r = 1 / this._originalHeight;
|
|
1284
|
+
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();
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
tt.defaultOptions = {
|
|
1288
|
+
/** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
|
|
1289
|
+
width: 100,
|
|
1290
|
+
/** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
|
|
1291
|
+
height: 100,
|
|
1292
|
+
/** The width of the left column. */
|
|
1293
|
+
leftWidth: 10,
|
|
1294
|
+
/** The height of the top row. */
|
|
1295
|
+
topHeight: 10,
|
|
1296
|
+
/** The width of the right column. */
|
|
1297
|
+
rightWidth: 10,
|
|
1298
|
+
/** The height of the bottom row. */
|
|
1299
|
+
bottomHeight: 10,
|
|
1300
|
+
/** The original width of the texture */
|
|
1301
|
+
originalWidth: 100,
|
|
1302
|
+
/** The original height of the texture */
|
|
1303
|
+
originalHeight: 100
|
|
1304
|
+
};
|
|
1305
|
+
let jt = tt;
|
|
1306
|
+
class st {
|
|
1307
|
+
constructor(e) {
|
|
1308
|
+
this._gpuSpriteHash = /* @__PURE__ */ Object.create(null), this._renderer = e;
|
|
1309
|
+
}
|
|
1310
|
+
addRenderable(e, t) {
|
|
1311
|
+
const r = this._getGpuSprite(e);
|
|
1312
|
+
e._didSpriteUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r);
|
|
1313
|
+
}
|
|
1314
|
+
updateRenderable(e) {
|
|
1315
|
+
const t = this._gpuSpriteHash[e.uid];
|
|
1316
|
+
e._didSpriteUpdate && this._updateBatchableSprite(e, t), t.batcher.updateElement(t);
|
|
1317
|
+
}
|
|
1318
|
+
validateRenderable(e) {
|
|
1319
|
+
const t = e._texture, r = this._getGpuSprite(e);
|
|
1320
|
+
return r.texture._source !== t._source ? !r.batcher.checkAndUpdateTexture(r, t) : !1;
|
|
1321
|
+
}
|
|
1322
|
+
destroyRenderable(e) {
|
|
1323
|
+
const t = this._gpuSpriteHash[e.uid];
|
|
1324
|
+
B.return(t), this._gpuSpriteHash[e.uid] = null;
|
|
1325
|
+
}
|
|
1326
|
+
_updateBatchableSprite(e, t) {
|
|
1327
|
+
e._didSpriteUpdate = !1, t.geometry.update(e), t.texture = e._texture;
|
|
1328
|
+
}
|
|
1329
|
+
_getGpuSprite(e) {
|
|
1330
|
+
return this._gpuSpriteHash[e.uid] || this._initGPUSprite(e);
|
|
1331
|
+
}
|
|
1332
|
+
_initGPUSprite(e) {
|
|
1333
|
+
const t = new he();
|
|
1334
|
+
return t.geometry = new jt(), t.mesh = e, t.texture = e._texture, t.roundPixels = this._renderer._roundPixels | e._roundPixels, this._gpuSpriteHash[e.uid] = t, e.on("destroyed", () => {
|
|
1335
|
+
this.destroyRenderable(e);
|
|
1336
|
+
}), t;
|
|
1337
|
+
}
|
|
1338
|
+
destroy() {
|
|
1339
|
+
for (const e in this._gpuSpriteHash)
|
|
1340
|
+
this._gpuSpriteHash[e].geometry.destroy();
|
|
1341
|
+
this._gpuSpriteHash = null, this._renderer = null;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
st.extension = {
|
|
1345
|
+
type: [
|
|
1346
|
+
b.WebGLPipes,
|
|
1347
|
+
b.WebGPUPipes,
|
|
1348
|
+
b.CanvasPipes
|
|
1349
|
+
],
|
|
1350
|
+
name: "nineSliceSprite"
|
|
1351
|
+
};
|
|
1352
|
+
const Vt = {
|
|
1353
|
+
name: "tiling-bit",
|
|
1354
|
+
vertex: {
|
|
1355
|
+
header: (
|
|
1356
|
+
/* wgsl */
|
|
1357
|
+
`
|
|
1358
|
+
struct TilingUniforms {
|
|
1359
|
+
uMapCoord:mat3x3<f32>,
|
|
1360
|
+
uClampFrame:vec4<f32>,
|
|
1361
|
+
uClampOffset:vec2<f32>,
|
|
1362
|
+
uTextureTransform:mat3x3<f32>,
|
|
1363
|
+
uSizeAnchor:vec4<f32>
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
|
1367
|
+
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
|
1368
|
+
@group(2) @binding(2) var uSampler: sampler;
|
|
1369
|
+
`
|
|
1370
|
+
),
|
|
1371
|
+
main: (
|
|
1372
|
+
/* wgsl */
|
|
1373
|
+
`
|
|
1374
|
+
uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy;
|
|
1375
|
+
|
|
1376
|
+
position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy;
|
|
1377
|
+
`
|
|
1378
|
+
)
|
|
1379
|
+
},
|
|
1380
|
+
fragment: {
|
|
1381
|
+
header: (
|
|
1382
|
+
/* wgsl */
|
|
1383
|
+
`
|
|
1384
|
+
struct TilingUniforms {
|
|
1385
|
+
uMapCoord:mat3x3<f32>,
|
|
1386
|
+
uClampFrame:vec4<f32>,
|
|
1387
|
+
uClampOffset:vec2<f32>,
|
|
1388
|
+
uTextureTransform:mat3x3<f32>,
|
|
1389
|
+
uSizeAnchor:vec4<f32>
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
|
1393
|
+
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
|
1394
|
+
@group(2) @binding(2) var uSampler: sampler;
|
|
1395
|
+
`
|
|
1396
|
+
),
|
|
1397
|
+
main: (
|
|
1398
|
+
/* wgsl */
|
|
1399
|
+
`
|
|
1400
|
+
|
|
1401
|
+
var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV);
|
|
1402
|
+
coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy;
|
|
1403
|
+
var unclamped = coord;
|
|
1404
|
+
coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw);
|
|
1405
|
+
|
|
1406
|
+
var bias = 0.;
|
|
1407
|
+
|
|
1408
|
+
if(unclamped.x == coord.x && unclamped.y == coord.y)
|
|
1409
|
+
{
|
|
1410
|
+
bias = -32.;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
outColor = textureSampleBias(uTexture, uSampler, coord, bias);
|
|
1414
|
+
`
|
|
1415
|
+
)
|
|
1416
|
+
}
|
|
1417
|
+
}, Kt = {
|
|
1418
|
+
name: "tiling-bit",
|
|
1419
|
+
vertex: {
|
|
1420
|
+
header: (
|
|
1421
|
+
/* glsl */
|
|
1422
|
+
`
|
|
1423
|
+
uniform mat3 uTextureTransform;
|
|
1424
|
+
uniform vec4 uSizeAnchor;
|
|
1425
|
+
|
|
1426
|
+
`
|
|
1427
|
+
),
|
|
1428
|
+
main: (
|
|
1429
|
+
/* glsl */
|
|
1430
|
+
`
|
|
1431
|
+
uv = (uTextureTransform * vec3(aUV, 1.0)).xy;
|
|
1432
|
+
|
|
1433
|
+
position = (position - uSizeAnchor.zw) * uSizeAnchor.xy;
|
|
1434
|
+
`
|
|
1435
|
+
)
|
|
1436
|
+
},
|
|
1437
|
+
fragment: {
|
|
1438
|
+
header: (
|
|
1439
|
+
/* glsl */
|
|
1440
|
+
`
|
|
1441
|
+
uniform sampler2D uTexture;
|
|
1442
|
+
uniform mat3 uMapCoord;
|
|
1443
|
+
uniform vec4 uClampFrame;
|
|
1444
|
+
uniform vec2 uClampOffset;
|
|
1445
|
+
`
|
|
1446
|
+
),
|
|
1447
|
+
main: (
|
|
1448
|
+
/* glsl */
|
|
1449
|
+
`
|
|
1450
|
+
|
|
1451
|
+
vec2 coord = vUV + ceil(uClampOffset - vUV);
|
|
1452
|
+
coord = (uMapCoord * vec3(coord, 1.0)).xy;
|
|
1453
|
+
vec2 unclamped = coord;
|
|
1454
|
+
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
|
|
1455
|
+
|
|
1456
|
+
outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0
|
|
1457
|
+
|
|
1458
|
+
`
|
|
1459
|
+
)
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
let J, ee;
|
|
1463
|
+
class Nt extends ke {
|
|
1464
|
+
constructor() {
|
|
1465
|
+
J ?? (J = Ue({
|
|
1466
|
+
name: "tiling-sprite-shader",
|
|
1467
|
+
bits: [
|
|
1468
|
+
Pt,
|
|
1469
|
+
Vt,
|
|
1470
|
+
ze
|
|
1471
|
+
]
|
|
1472
|
+
})), ee ?? (ee = Ge({
|
|
1473
|
+
name: "tiling-sprite-shader",
|
|
1474
|
+
bits: [
|
|
1475
|
+
Ft,
|
|
1476
|
+
Kt,
|
|
1477
|
+
He
|
|
1478
|
+
]
|
|
1479
|
+
}));
|
|
1480
|
+
const e = new Y({
|
|
1481
|
+
uMapCoord: { value: new U(), type: "mat3x3<f32>" },
|
|
1482
|
+
uClampFrame: { value: new Float32Array([0, 0, 1, 1]), type: "vec4<f32>" },
|
|
1483
|
+
uClampOffset: { value: new Float32Array([0, 0]), type: "vec2<f32>" },
|
|
1484
|
+
uTextureTransform: { value: new U(), type: "mat3x3<f32>" },
|
|
1485
|
+
uSizeAnchor: { value: new Float32Array([100, 100, 0.5, 0.5]), type: "vec4<f32>" }
|
|
1486
|
+
});
|
|
1487
|
+
super({
|
|
1488
|
+
glProgram: ee,
|
|
1489
|
+
gpuProgram: J,
|
|
1490
|
+
resources: {
|
|
1491
|
+
localUniforms: new Y({
|
|
1492
|
+
uTransformMatrix: { value: new U(), type: "mat3x3<f32>" },
|
|
1493
|
+
uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
|
|
1494
|
+
uRound: { value: 0, type: "f32" }
|
|
1495
|
+
}),
|
|
1496
|
+
tilingUniforms: e,
|
|
1497
|
+
uTexture: R.EMPTY.source,
|
|
1498
|
+
uSampler: R.EMPTY.source.style
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
updateUniforms(e, t, r, s, n, a) {
|
|
1503
|
+
const o = this.resources.tilingUniforms, c = a.width, l = a.height, h = a.textureMatrix, d = o.uniforms.uTextureTransform;
|
|
1504
|
+
d.set(
|
|
1505
|
+
r.a * c / e,
|
|
1506
|
+
r.b * c / t,
|
|
1507
|
+
r.c * l / e,
|
|
1508
|
+
r.d * l / t,
|
|
1509
|
+
r.tx / e,
|
|
1510
|
+
r.ty / t
|
|
1511
|
+
), d.invert(), o.uniforms.uMapCoord = h.mapCoord, o.uniforms.uClampFrame = h.uClampFrame, o.uniforms.uClampOffset = h.uClampOffset, o.uniforms.uTextureTransform = d, o.uniforms.uSizeAnchor[0] = e, o.uniforms.uSizeAnchor[1] = t, o.uniforms.uSizeAnchor[2] = s, o.uniforms.uSizeAnchor[3] = n, a && (this.resources.uTexture = a.source, this.resources.uSampler = a.source.style);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
class qt extends oe {
|
|
1515
|
+
constructor() {
|
|
1516
|
+
super({
|
|
1517
|
+
positions: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
1518
|
+
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
|
|
1519
|
+
indices: new Uint32Array([0, 1, 2, 0, 2, 3])
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
function Qt(i, e) {
|
|
1524
|
+
const t = i.anchor.x, r = i.anchor.y;
|
|
1525
|
+
e[0] = -t * i.width, e[1] = -r * i.height, e[2] = (1 - t) * i.width, e[3] = -r * i.height, e[4] = (1 - t) * i.width, e[5] = (1 - r) * i.height, e[6] = -t * i.width, e[7] = (1 - r) * i.height;
|
|
1526
|
+
}
|
|
1527
|
+
function Zt(i, e, t, r) {
|
|
1528
|
+
let s = 0;
|
|
1529
|
+
const n = i.length / e, a = r.a, o = r.b, c = r.c, l = r.d, h = r.tx, d = r.ty;
|
|
1530
|
+
for (t *= e; s < n; ) {
|
|
1531
|
+
const u = i[t], f = i[t + 1];
|
|
1532
|
+
i[t] = a * u + c * f + h, i[t + 1] = o * u + l * f + d, t += e, s++;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function Jt(i, e) {
|
|
1536
|
+
const t = i.texture, r = t.frame.width, s = t.frame.height;
|
|
1537
|
+
let n = 0, a = 0;
|
|
1538
|
+
i._applyAnchorToTexture && (n = i.anchor.x, a = i.anchor.y), e[0] = e[6] = -n, e[2] = e[4] = 1 - n, e[1] = e[3] = -a, e[5] = e[7] = 1 - a;
|
|
1539
|
+
const o = U.shared;
|
|
1540
|
+
o.copyFrom(i._tileTransform.matrix), o.tx /= i.width, o.ty /= i.height, o.invert(), o.scale(i.width / r, i.height / s), Zt(e, 2, 0, o);
|
|
1541
|
+
}
|
|
1542
|
+
const X = new qt();
|
|
1543
|
+
class it {
|
|
1544
|
+
constructor(e) {
|
|
1545
|
+
this._tilingSpriteDataHash = /* @__PURE__ */ Object.create(null), this._renderer = e;
|
|
1546
|
+
}
|
|
1547
|
+
validateRenderable(e) {
|
|
1548
|
+
const t = this._getTilingSpriteData(e), r = t.canBatch;
|
|
1549
|
+
this._updateCanBatch(e);
|
|
1550
|
+
const s = t.canBatch;
|
|
1551
|
+
if (s && s === r) {
|
|
1552
|
+
const { batchableMesh: n } = t;
|
|
1553
|
+
if (n.texture._source !== e.texture._source)
|
|
1554
|
+
return !n.batcher.checkAndUpdateTexture(n, e.texture);
|
|
1555
|
+
}
|
|
1556
|
+
return r !== s;
|
|
1557
|
+
}
|
|
1558
|
+
addRenderable(e, t) {
|
|
1559
|
+
const r = this._renderer.renderPipes.batch;
|
|
1560
|
+
this._updateCanBatch(e);
|
|
1561
|
+
const s = this._getTilingSpriteData(e), { geometry: n, canBatch: a } = s;
|
|
1562
|
+
if (a) {
|
|
1563
|
+
s.batchableMesh || (s.batchableMesh = new he());
|
|
1564
|
+
const o = s.batchableMesh;
|
|
1565
|
+
e._didTilingSpriteUpdate && (e._didTilingSpriteUpdate = !1, this._updateBatchableMesh(e), o.geometry = n, o.mesh = e, o.texture = e._texture), o.roundPixels = this._renderer._roundPixels | e._roundPixels, r.addToBatch(o);
|
|
1566
|
+
} else
|
|
1567
|
+
r.break(t), s.shader || (s.shader = new Nt()), this.updateRenderable(e), t.add(e);
|
|
1568
|
+
}
|
|
1569
|
+
execute(e) {
|
|
1570
|
+
const { shader: t } = this._tilingSpriteDataHash[e.uid];
|
|
1571
|
+
t.groups[0] = this._renderer.globalUniforms.bindGroup;
|
|
1572
|
+
const r = t.resources.localUniforms.uniforms;
|
|
1573
|
+
r.uTransformMatrix = e.groupTransform, r.uRound = this._renderer._roundPixels | e._roundPixels, ae(
|
|
1574
|
+
e.groupColorAlpha,
|
|
1575
|
+
r.uColor,
|
|
1576
|
+
0
|
|
1577
|
+
), this._renderer.encoder.draw({
|
|
1578
|
+
geometry: X,
|
|
1579
|
+
shader: t,
|
|
1580
|
+
state: Ae.default2d
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
updateRenderable(e) {
|
|
1584
|
+
const t = this._getTilingSpriteData(e), { canBatch: r } = t;
|
|
1585
|
+
if (r) {
|
|
1586
|
+
const { batchableMesh: s } = t;
|
|
1587
|
+
e._didTilingSpriteUpdate && this._updateBatchableMesh(e), s.batcher.updateElement(s);
|
|
1588
|
+
} else if (e._didTilingSpriteUpdate) {
|
|
1589
|
+
const { shader: s } = t;
|
|
1590
|
+
s.updateUniforms(
|
|
1591
|
+
e.width,
|
|
1592
|
+
e.height,
|
|
1593
|
+
e._tileTransform.matrix,
|
|
1594
|
+
e.anchor.x,
|
|
1595
|
+
e.anchor.y,
|
|
1596
|
+
e.texture
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
e._didTilingSpriteUpdate = !1;
|
|
1600
|
+
}
|
|
1601
|
+
destroyRenderable(e) {
|
|
1602
|
+
var r;
|
|
1603
|
+
const t = this._getTilingSpriteData(e);
|
|
1604
|
+
t.batchableMesh = null, (r = t.shader) == null || r.destroy(), this._tilingSpriteDataHash[e.uid] = null;
|
|
1605
|
+
}
|
|
1606
|
+
_getTilingSpriteData(e) {
|
|
1607
|
+
return this._tilingSpriteDataHash[e.uid] || this._initTilingSpriteData(e);
|
|
1608
|
+
}
|
|
1609
|
+
_initTilingSpriteData(e) {
|
|
1610
|
+
const t = new oe({
|
|
1611
|
+
indices: X.indices,
|
|
1612
|
+
positions: X.positions.slice(),
|
|
1613
|
+
uvs: X.uvs.slice()
|
|
1614
|
+
});
|
|
1615
|
+
return this._tilingSpriteDataHash[e.uid] = {
|
|
1616
|
+
canBatch: !0,
|
|
1617
|
+
renderable: e,
|
|
1618
|
+
geometry: t
|
|
1619
|
+
}, e.on("destroyed", () => {
|
|
1620
|
+
this.destroyRenderable(e);
|
|
1621
|
+
}), this._tilingSpriteDataHash[e.uid];
|
|
1622
|
+
}
|
|
1623
|
+
_updateBatchableMesh(e) {
|
|
1624
|
+
const t = this._getTilingSpriteData(e), { geometry: r } = t, s = e.texture.source.style;
|
|
1625
|
+
s.addressMode !== "repeat" && (s.addressMode = "repeat", s.update()), Jt(e, r.uvs), Qt(e, r.positions);
|
|
1626
|
+
}
|
|
1627
|
+
destroy() {
|
|
1628
|
+
for (const e in this._tilingSpriteDataHash)
|
|
1629
|
+
this.destroyRenderable(this._tilingSpriteDataHash[e].renderable);
|
|
1630
|
+
this._tilingSpriteDataHash = null, this._renderer = null;
|
|
1631
|
+
}
|
|
1632
|
+
_updateCanBatch(e) {
|
|
1633
|
+
const t = this._getTilingSpriteData(e), r = e.texture;
|
|
1634
|
+
let s = !0;
|
|
1635
|
+
return this._renderer.type === ne.WEBGL && (s = this._renderer.context.supports.nonPowOf2wrapping), t.canBatch = r.textureMatrix.isSimple && (s || r.source.isPowerOfTwo), t.canBatch;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
it.extension = {
|
|
1639
|
+
type: [
|
|
1640
|
+
b.WebGLPipes,
|
|
1641
|
+
b.WebGPUPipes,
|
|
1642
|
+
b.CanvasPipes
|
|
1643
|
+
],
|
|
1644
|
+
name: "tilingSprite"
|
|
1645
|
+
};
|
|
1646
|
+
const te = {
|
|
1647
|
+
test(i) {
|
|
1648
|
+
return typeof i == "string" && i.startsWith("info face=");
|
|
1649
|
+
},
|
|
1650
|
+
parse(i) {
|
|
1651
|
+
const e = i.match(/^[a-z]+\s+.+$/gm), t = {
|
|
1652
|
+
info: [],
|
|
1653
|
+
common: [],
|
|
1654
|
+
page: [],
|
|
1655
|
+
char: [],
|
|
1656
|
+
chars: [],
|
|
1657
|
+
kerning: [],
|
|
1658
|
+
kernings: [],
|
|
1659
|
+
distanceField: []
|
|
1660
|
+
};
|
|
1661
|
+
for (const d in e) {
|
|
1662
|
+
const u = e[d].match(/^[a-z]+/gm)[0], f = e[d].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm), p = {};
|
|
1663
|
+
for (const g in f) {
|
|
1664
|
+
const m = f[g].split("="), x = m[0], _ = m[1].replace(/"/gm, ""), y = parseFloat(_), T = isNaN(y) ? _ : y;
|
|
1665
|
+
p[x] = T;
|
|
1666
|
+
}
|
|
1667
|
+
t[u].push(p);
|
|
1668
|
+
}
|
|
1669
|
+
const r = {
|
|
1670
|
+
chars: {},
|
|
1671
|
+
pages: [],
|
|
1672
|
+
lineHeight: 0,
|
|
1673
|
+
fontSize: 0,
|
|
1674
|
+
fontFamily: "",
|
|
1675
|
+
distanceField: null,
|
|
1676
|
+
baseLineOffset: 0
|
|
1677
|
+
}, [s] = t.info, [n] = t.common, [a] = t.distanceField ?? [];
|
|
1678
|
+
a && (r.distanceField = {
|
|
1679
|
+
range: parseInt(a.distanceRange, 10),
|
|
1680
|
+
type: a.fieldType
|
|
1681
|
+
}), r.fontSize = parseInt(s.size, 10), r.fontFamily = s.face, r.lineHeight = parseInt(n.lineHeight, 10);
|
|
1682
|
+
const o = t.page;
|
|
1683
|
+
for (let d = 0; d < o.length; d++)
|
|
1684
|
+
r.pages.push({
|
|
1685
|
+
id: parseInt(o[d].id, 10) || 0,
|
|
1686
|
+
file: o[d].file
|
|
1687
|
+
});
|
|
1688
|
+
const c = {};
|
|
1689
|
+
r.baseLineOffset = r.lineHeight - parseInt(n.base, 10);
|
|
1690
|
+
const l = t.char;
|
|
1691
|
+
for (let d = 0; d < l.length; d++) {
|
|
1692
|
+
const u = l[d], f = parseInt(u.id, 10);
|
|
1693
|
+
let p = u.letter ?? u.char ?? String.fromCharCode(f);
|
|
1694
|
+
p === "space" && (p = " "), c[f] = p, r.chars[p] = {
|
|
1695
|
+
id: f,
|
|
1696
|
+
// texture deets..
|
|
1697
|
+
page: parseInt(u.page, 10) || 0,
|
|
1698
|
+
x: parseInt(u.x, 10),
|
|
1699
|
+
y: parseInt(u.y, 10),
|
|
1700
|
+
width: parseInt(u.width, 10),
|
|
1701
|
+
height: parseInt(u.height, 10),
|
|
1702
|
+
xOffset: parseInt(u.xoffset, 10),
|
|
1703
|
+
yOffset: parseInt(u.yoffset, 10),
|
|
1704
|
+
xAdvance: parseInt(u.xadvance, 10),
|
|
1705
|
+
kerning: {}
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
const h = t.kerning || [];
|
|
1709
|
+
for (let d = 0; d < h.length; d++) {
|
|
1710
|
+
const u = parseInt(h[d].first, 10), f = parseInt(h[d].second, 10), p = parseInt(h[d].amount, 10);
|
|
1711
|
+
r.chars[c[f]].kerning[c[u]] = p;
|
|
1712
|
+
}
|
|
1713
|
+
return r;
|
|
1714
|
+
}
|
|
1715
|
+
}, we = {
|
|
1716
|
+
test(i) {
|
|
1717
|
+
const e = i;
|
|
1718
|
+
return typeof e != "string" && "getElementsByTagName" in e && e.getElementsByTagName("page").length && e.getElementsByTagName("info")[0].getAttribute("face") !== null;
|
|
1719
|
+
},
|
|
1720
|
+
parse(i) {
|
|
1721
|
+
const e = {
|
|
1722
|
+
chars: {},
|
|
1723
|
+
pages: [],
|
|
1724
|
+
lineHeight: 0,
|
|
1725
|
+
fontSize: 0,
|
|
1726
|
+
fontFamily: "",
|
|
1727
|
+
distanceField: null,
|
|
1728
|
+
baseLineOffset: 0
|
|
1729
|
+
}, t = i.getElementsByTagName("info")[0], r = i.getElementsByTagName("common")[0], s = i.getElementsByTagName("distanceField")[0];
|
|
1730
|
+
s && (e.distanceField = {
|
|
1731
|
+
type: s.getAttribute("fieldType"),
|
|
1732
|
+
range: parseInt(s.getAttribute("distanceRange"), 10)
|
|
1733
|
+
});
|
|
1734
|
+
const n = i.getElementsByTagName("page"), a = i.getElementsByTagName("char"), o = i.getElementsByTagName("kerning");
|
|
1735
|
+
e.fontSize = parseInt(t.getAttribute("size"), 10), e.fontFamily = t.getAttribute("face"), e.lineHeight = parseInt(r.getAttribute("lineHeight"), 10);
|
|
1736
|
+
for (let l = 0; l < n.length; l++)
|
|
1737
|
+
e.pages.push({
|
|
1738
|
+
id: parseInt(n[l].getAttribute("id"), 10) || 0,
|
|
1739
|
+
file: n[l].getAttribute("file")
|
|
1740
|
+
});
|
|
1741
|
+
const c = {};
|
|
1742
|
+
e.baseLineOffset = e.lineHeight - parseInt(r.getAttribute("base"), 10);
|
|
1743
|
+
for (let l = 0; l < a.length; l++) {
|
|
1744
|
+
const h = a[l], d = parseInt(h.getAttribute("id"), 10);
|
|
1745
|
+
let u = h.getAttribute("letter") ?? h.getAttribute("char") ?? String.fromCharCode(d);
|
|
1746
|
+
u === "space" && (u = " "), c[d] = u, e.chars[u] = {
|
|
1747
|
+
id: d,
|
|
1748
|
+
// texture deets..
|
|
1749
|
+
page: parseInt(h.getAttribute("page"), 10) || 0,
|
|
1750
|
+
x: parseInt(h.getAttribute("x"), 10),
|
|
1751
|
+
y: parseInt(h.getAttribute("y"), 10),
|
|
1752
|
+
width: parseInt(h.getAttribute("width"), 10),
|
|
1753
|
+
height: parseInt(h.getAttribute("height"), 10),
|
|
1754
|
+
// render deets..
|
|
1755
|
+
xOffset: parseInt(h.getAttribute("xoffset"), 10),
|
|
1756
|
+
yOffset: parseInt(h.getAttribute("yoffset"), 10),
|
|
1757
|
+
// + baseLineOffset,
|
|
1758
|
+
xAdvance: parseInt(h.getAttribute("xadvance"), 10),
|
|
1759
|
+
kerning: {}
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
for (let l = 0; l < o.length; l++) {
|
|
1763
|
+
const h = parseInt(o[l].getAttribute("first"), 10), d = parseInt(o[l].getAttribute("second"), 10), u = parseInt(o[l].getAttribute("amount"), 10);
|
|
1764
|
+
e.chars[c[d]].kerning[c[h]] = u;
|
|
1765
|
+
}
|
|
1766
|
+
return e;
|
|
1767
|
+
}
|
|
1768
|
+
}, ve = {
|
|
1769
|
+
test(i) {
|
|
1770
|
+
return typeof i == "string" && i.includes("<font>") ? we.test($.get().parseXML(i)) : !1;
|
|
1771
|
+
},
|
|
1772
|
+
parse(i) {
|
|
1773
|
+
return we.parse($.get().parseXML(i));
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1776
|
+
class nt extends Xe {
|
|
1777
|
+
constructor(e, t) {
|
|
1778
|
+
super();
|
|
1779
|
+
const { textures: r, data: s } = e;
|
|
1780
|
+
Object.keys(s.pages).forEach((n) => {
|
|
1781
|
+
const a = s.pages[parseInt(n, 10)], o = r[a.id];
|
|
1782
|
+
this.pages.push({ texture: o });
|
|
1783
|
+
}), Object.keys(s.chars).forEach((n) => {
|
|
1784
|
+
const a = s.chars[n], {
|
|
1785
|
+
frame: o,
|
|
1786
|
+
source: c
|
|
1787
|
+
} = r[a.page], l = new V(
|
|
1788
|
+
a.x + o.x,
|
|
1789
|
+
a.y + o.y,
|
|
1790
|
+
a.width,
|
|
1791
|
+
a.height
|
|
1792
|
+
), h = new R({
|
|
1793
|
+
source: c,
|
|
1794
|
+
frame: l
|
|
1795
|
+
});
|
|
1796
|
+
this.chars[n] = {
|
|
1797
|
+
id: n.codePointAt(0),
|
|
1798
|
+
xOffset: a.xOffset,
|
|
1799
|
+
yOffset: a.yOffset,
|
|
1800
|
+
xAdvance: a.xAdvance,
|
|
1801
|
+
kerning: a.kerning ?? {},
|
|
1802
|
+
texture: h
|
|
1803
|
+
};
|
|
1804
|
+
}), this.baseRenderedFontSize = s.fontSize, this.baseMeasurementFontSize = s.fontSize, this.fontMetrics = {
|
|
1805
|
+
ascent: 0,
|
|
1806
|
+
descent: 0,
|
|
1807
|
+
fontSize: s.fontSize
|
|
1808
|
+
}, this.baseLineOffset = s.baseLineOffset, this.lineHeight = s.lineHeight, this.fontFamily = s.fontFamily, this.distanceField = s.distanceField ?? {
|
|
1809
|
+
type: "none",
|
|
1810
|
+
range: 0
|
|
1811
|
+
}, this.url = t;
|
|
1812
|
+
}
|
|
1813
|
+
/** Destroys the BitmapFont object. */
|
|
1814
|
+
destroy() {
|
|
1815
|
+
super.destroy();
|
|
1816
|
+
for (let e = 0; e < this.pages.length; e++) {
|
|
1817
|
+
const { texture: t } = this.pages[e];
|
|
1818
|
+
t.destroy(!0);
|
|
1819
|
+
}
|
|
1820
|
+
this.pages = null;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Generates a bitmap-font for the given style and character set
|
|
1824
|
+
* @param options - Setup options for font generation.
|
|
1825
|
+
* @returns Font generated by style options.
|
|
1826
|
+
* @example
|
|
1827
|
+
* import { BitmapFont, BitmapText } from 'pixi.js';
|
|
1828
|
+
*
|
|
1829
|
+
* BitmapFont.install('TitleFont', {
|
|
1830
|
+
* fontFamily: 'Arial',
|
|
1831
|
+
* fontSize: 12,
|
|
1832
|
+
* strokeThickness: 2,
|
|
1833
|
+
* fill: 'purple',
|
|
1834
|
+
* });
|
|
1835
|
+
*
|
|
1836
|
+
* const title = new BitmapText({ text: 'This is the title', fontFamily: 'TitleFont' });
|
|
1837
|
+
*/
|
|
1838
|
+
static install(e) {
|
|
1839
|
+
ie.install(e);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Uninstalls a bitmap font from the cache.
|
|
1843
|
+
* @param {string} name - The name of the bitmap font to uninstall.
|
|
1844
|
+
*/
|
|
1845
|
+
static uninstall(e) {
|
|
1846
|
+
ie.uninstall(e);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
const er = [".xml", ".fnt"], tr = {
|
|
1850
|
+
extension: b.CacheParser,
|
|
1851
|
+
test: (i) => i instanceof nt,
|
|
1852
|
+
getCacheableAssets(i, e) {
|
|
1853
|
+
const t = {};
|
|
1854
|
+
return i.forEach((r) => {
|
|
1855
|
+
t[r] = e;
|
|
1856
|
+
}), t[`${e.fontFamily}-bitmap`] = e, t;
|
|
1857
|
+
}
|
|
1858
|
+
}, rr = {
|
|
1859
|
+
extension: {
|
|
1860
|
+
type: b.LoadParser,
|
|
1861
|
+
priority: wt.Normal
|
|
1862
|
+
},
|
|
1863
|
+
test(i) {
|
|
1864
|
+
return er.includes(Z.extname(i).toLowerCase());
|
|
1865
|
+
},
|
|
1866
|
+
async testParse(i) {
|
|
1867
|
+
return te.test(i) || ve.test(i);
|
|
1868
|
+
},
|
|
1869
|
+
async parse(i, e, t) {
|
|
1870
|
+
const r = te.test(i) ? te.parse(i) : ve.parse(i), { src: s } = e, { pages: n } = r, a = [];
|
|
1871
|
+
for (let h = 0; h < n.length; ++h) {
|
|
1872
|
+
const d = n[h].file;
|
|
1873
|
+
let u = Z.join(Z.dirname(s), d);
|
|
1874
|
+
u = vt(u, s), a.push(u);
|
|
1875
|
+
}
|
|
1876
|
+
const o = await t.load(a), c = a.map((h) => o[h]);
|
|
1877
|
+
return new nt({
|
|
1878
|
+
data: r,
|
|
1879
|
+
textures: c
|
|
1880
|
+
}, s);
|
|
1881
|
+
},
|
|
1882
|
+
async load(i, e) {
|
|
1883
|
+
return await (await $.get().fetch(i)).text();
|
|
1884
|
+
},
|
|
1885
|
+
async unload(i, e, t) {
|
|
1886
|
+
await Promise.all(i.pages.map((r) => t.unload(r.texture.source._sourceOrigin))), i.destroy();
|
|
1887
|
+
}
|
|
1888
|
+
}, sr = {
|
|
1889
|
+
name: "local-uniform-msdf-bit",
|
|
1890
|
+
vertex: {
|
|
1891
|
+
header: (
|
|
1892
|
+
/* wgsl */
|
|
1893
|
+
`
|
|
1894
|
+
struct LocalUniforms {
|
|
1895
|
+
uColor:vec4<f32>,
|
|
1896
|
+
uTransformMatrix:mat3x3<f32>,
|
|
1897
|
+
uDistance: f32,
|
|
1898
|
+
uRound:f32,
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
1902
|
+
`
|
|
1903
|
+
),
|
|
1904
|
+
main: (
|
|
1905
|
+
/* wgsl */
|
|
1906
|
+
`
|
|
1907
|
+
vColor *= localUniforms.uColor;
|
|
1908
|
+
modelMatrix *= localUniforms.uTransformMatrix;
|
|
1909
|
+
`
|
|
1910
|
+
),
|
|
1911
|
+
end: (
|
|
1912
|
+
/* wgsl */
|
|
1913
|
+
`
|
|
1914
|
+
if(localUniforms.uRound == 1)
|
|
1915
|
+
{
|
|
1916
|
+
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
1917
|
+
}
|
|
1918
|
+
`
|
|
1919
|
+
)
|
|
1920
|
+
},
|
|
1921
|
+
fragment: {
|
|
1922
|
+
header: (
|
|
1923
|
+
/* wgsl */
|
|
1924
|
+
`
|
|
1925
|
+
struct LocalUniforms {
|
|
1926
|
+
uColor:vec4<f32>,
|
|
1927
|
+
uTransformMatrix:mat3x3<f32>,
|
|
1928
|
+
uDistance: f32
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
1932
|
+
`
|
|
1933
|
+
),
|
|
1934
|
+
main: (
|
|
1935
|
+
/* wgsl */
|
|
1936
|
+
`
|
|
1937
|
+
outColor = vColor * calculateMSDFAlpha(outColor, localUniforms.uDistance);
|
|
1938
|
+
`
|
|
1939
|
+
)
|
|
1940
|
+
}
|
|
1941
|
+
}, ir = {
|
|
1942
|
+
name: "local-uniform-msdf-bit",
|
|
1943
|
+
vertex: {
|
|
1944
|
+
header: (
|
|
1945
|
+
/* glsl */
|
|
1946
|
+
`
|
|
1947
|
+
uniform mat3 uTransformMatrix;
|
|
1948
|
+
uniform vec4 uColor;
|
|
1949
|
+
uniform float uRound;
|
|
1950
|
+
`
|
|
1951
|
+
),
|
|
1952
|
+
main: (
|
|
1953
|
+
/* glsl */
|
|
1954
|
+
`
|
|
1955
|
+
vColor *= uColor;
|
|
1956
|
+
modelMatrix *= uTransformMatrix;
|
|
1957
|
+
`
|
|
1958
|
+
),
|
|
1959
|
+
end: (
|
|
1960
|
+
/* glsl */
|
|
1961
|
+
`
|
|
1962
|
+
if(uRound == 1.)
|
|
1963
|
+
{
|
|
1964
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
1965
|
+
}
|
|
1966
|
+
`
|
|
1967
|
+
)
|
|
1968
|
+
},
|
|
1969
|
+
fragment: {
|
|
1970
|
+
header: (
|
|
1971
|
+
/* glsl */
|
|
1972
|
+
`
|
|
1973
|
+
uniform float uDistance;
|
|
1974
|
+
`
|
|
1975
|
+
),
|
|
1976
|
+
main: (
|
|
1977
|
+
/* glsl */
|
|
1978
|
+
`
|
|
1979
|
+
outColor = vColor * calculateMSDFAlpha(outColor, uDistance);
|
|
1980
|
+
`
|
|
1981
|
+
)
|
|
1982
|
+
}
|
|
1983
|
+
}, nr = {
|
|
1984
|
+
name: "msdf-bit",
|
|
1985
|
+
fragment: {
|
|
1986
|
+
header: (
|
|
1987
|
+
/* wgsl */
|
|
1988
|
+
`
|
|
1989
|
+
fn calculateMSDFAlpha(msdfColor:vec4<f32>, distance:f32) -> f32 {
|
|
1990
|
+
|
|
1991
|
+
// MSDF
|
|
1992
|
+
var median = msdfColor.r + msdfColor.g + msdfColor.b -
|
|
1993
|
+
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
|
1994
|
+
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
|
1995
|
+
|
|
1996
|
+
// SDF
|
|
1997
|
+
median = min(median, msdfColor.a);
|
|
1998
|
+
|
|
1999
|
+
var screenPxDistance = distance * (median - 0.5);
|
|
2000
|
+
var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
|
2001
|
+
if (median < 0.01) {
|
|
2002
|
+
alpha = 0.0;
|
|
2003
|
+
} else if (median > 0.99) {
|
|
2004
|
+
alpha = 1.0;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
return alpha;
|
|
2008
|
+
}
|
|
2009
|
+
`
|
|
2010
|
+
)
|
|
2011
|
+
}
|
|
2012
|
+
}, ar = {
|
|
2013
|
+
name: "msdf-bit",
|
|
2014
|
+
fragment: {
|
|
2015
|
+
header: (
|
|
2016
|
+
/* glsl */
|
|
2017
|
+
`
|
|
2018
|
+
float calculateMSDFAlpha(vec4 msdfColor, float distance) {
|
|
2019
|
+
|
|
2020
|
+
// MSDF
|
|
2021
|
+
float median = msdfColor.r + msdfColor.g + msdfColor.b -
|
|
2022
|
+
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
|
2023
|
+
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
|
2024
|
+
|
|
2025
|
+
// SDF
|
|
2026
|
+
median = min(median, msdfColor.a);
|
|
2027
|
+
|
|
2028
|
+
float screenPxDistance = distance * (median - 0.5);
|
|
2029
|
+
float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
|
2030
|
+
|
|
2031
|
+
if (median < 0.01) {
|
|
2032
|
+
alpha = 0.0;
|
|
2033
|
+
} else if (median > 0.99) {
|
|
2034
|
+
alpha = 1.0;
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
return alpha;
|
|
2038
|
+
}
|
|
2039
|
+
`
|
|
2040
|
+
)
|
|
2041
|
+
}
|
|
2042
|
+
};
|
|
2043
|
+
class or extends ke {
|
|
2044
|
+
constructor() {
|
|
2045
|
+
const e = new Y({
|
|
2046
|
+
uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
|
|
2047
|
+
uTransformMatrix: { value: new U(), type: "mat3x3<f32>" },
|
|
2048
|
+
uDistance: { value: 4, type: "f32" },
|
|
2049
|
+
uRound: { value: 0, type: "f32" }
|
|
2050
|
+
}), t = St(), r = Ue({
|
|
2051
|
+
name: "sdf-shader",
|
|
2052
|
+
bits: [
|
|
2053
|
+
Mt,
|
|
2054
|
+
Rt(t),
|
|
2055
|
+
sr,
|
|
2056
|
+
nr,
|
|
2057
|
+
ze
|
|
2058
|
+
]
|
|
2059
|
+
}), s = Ge({
|
|
2060
|
+
name: "sdf-shader",
|
|
2061
|
+
bits: [
|
|
2062
|
+
At,
|
|
2063
|
+
kt(t),
|
|
2064
|
+
ir,
|
|
2065
|
+
ar,
|
|
2066
|
+
He
|
|
2067
|
+
]
|
|
2068
|
+
});
|
|
2069
|
+
super({
|
|
2070
|
+
glProgram: s,
|
|
2071
|
+
gpuProgram: r,
|
|
2072
|
+
resources: {
|
|
2073
|
+
localUniforms: e,
|
|
2074
|
+
batchSamplers: Ut(t)
|
|
2075
|
+
}
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
class at {
|
|
2080
|
+
constructor(e) {
|
|
2081
|
+
this._gpuBitmapText = {}, this._renderer = e;
|
|
2082
|
+
}
|
|
2083
|
+
validateRenderable(e) {
|
|
2084
|
+
const t = this._getGpuBitmapText(e);
|
|
2085
|
+
return e._didTextUpdate && (e._didTextUpdate = !1, this._updateContext(e, t)), this._renderer.renderPipes.graphics.validateRenderable(t);
|
|
2086
|
+
}
|
|
2087
|
+
addRenderable(e, t) {
|
|
2088
|
+
const r = this._getGpuBitmapText(e);
|
|
2089
|
+
Se(e, r), e._didTextUpdate && (e._didTextUpdate = !1, this._updateContext(e, r)), this._renderer.renderPipes.graphics.addRenderable(r, t), r.context.customShader && this._updateDistanceField(e);
|
|
2090
|
+
}
|
|
2091
|
+
destroyRenderable(e) {
|
|
2092
|
+
this._destroyRenderableByUid(e.uid);
|
|
2093
|
+
}
|
|
2094
|
+
_destroyRenderableByUid(e) {
|
|
2095
|
+
B.return(this._gpuBitmapText[e]), this._gpuBitmapText[e] = null;
|
|
2096
|
+
}
|
|
2097
|
+
updateRenderable(e) {
|
|
2098
|
+
const t = this._getGpuBitmapText(e);
|
|
2099
|
+
Se(e, t), this._renderer.renderPipes.graphics.updateRenderable(t), t.context.customShader && this._updateDistanceField(e);
|
|
2100
|
+
}
|
|
2101
|
+
_updateContext(e, t) {
|
|
2102
|
+
var f;
|
|
2103
|
+
const { context: r } = t, s = ie.getFont(e.text, e._style);
|
|
2104
|
+
r.clear(), s.distanceField.type !== "none" && (r.customShader || (this._sdfShader || (this._sdfShader = new or()), r.customShader = this._sdfShader));
|
|
2105
|
+
const n = Array.from(e.text), a = e._style;
|
|
2106
|
+
let o = (((f = a._stroke) == null ? void 0 : f.width) || 0) / 2;
|
|
2107
|
+
o += s.baseLineOffset;
|
|
2108
|
+
const c = Ve(n, a, s);
|
|
2109
|
+
let l = 0;
|
|
2110
|
+
const h = a.padding, d = c.scale;
|
|
2111
|
+
r.translate(
|
|
2112
|
+
-e._anchor._x * c.width - h,
|
|
2113
|
+
-e._anchor._y * (c.height + c.offsetY) - h
|
|
2114
|
+
).scale(d, d);
|
|
2115
|
+
const u = a._fill.color;
|
|
2116
|
+
for (let p = 0; p < c.lines.length; p++) {
|
|
2117
|
+
const g = c.lines[p];
|
|
2118
|
+
for (let m = 0; m < g.charPositions.length; m++) {
|
|
2119
|
+
const x = n[l++], _ = s.chars[x];
|
|
2120
|
+
_ != null && _.texture && r.texture(
|
|
2121
|
+
_.texture,
|
|
2122
|
+
u || "black",
|
|
2123
|
+
Math.round(g.charPositions[m] + _.xOffset),
|
|
2124
|
+
Math.round(o + _.yOffset)
|
|
2125
|
+
);
|
|
2126
|
+
}
|
|
2127
|
+
o += s.lineHeight;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
_getGpuBitmapText(e) {
|
|
2131
|
+
return this._gpuBitmapText[e.uid] || this.initGpuText(e);
|
|
2132
|
+
}
|
|
2133
|
+
initGpuText(e) {
|
|
2134
|
+
const t = B.get(Ct);
|
|
2135
|
+
return this._gpuBitmapText[e.uid] = t, this._updateContext(e, t), e.on("destroyed", () => {
|
|
2136
|
+
this.destroyRenderable(e);
|
|
2137
|
+
}), this._gpuBitmapText[e.uid];
|
|
2138
|
+
}
|
|
2139
|
+
_updateDistanceField(e) {
|
|
2140
|
+
const t = this._getGpuBitmapText(e).context, r = e._style.fontFamily, s = M.get(`${r}-bitmap`), { a: n, b: a, c: o, d: c } = e.groupTransform, l = Math.sqrt(n * n + a * a), h = Math.sqrt(o * o + c * c), d = (Math.abs(l) + Math.abs(h)) / 2, u = s.baseRenderedFontSize / e._style.fontSize, f = e.resolution ?? this._renderer.resolution, p = d * s.distanceField.range * (1 / u) * f;
|
|
2141
|
+
t.customShader.resources.localUniforms.uniforms.uDistance = p;
|
|
2142
|
+
}
|
|
2143
|
+
destroy() {
|
|
2144
|
+
var e;
|
|
2145
|
+
for (const t in this._gpuBitmapText)
|
|
2146
|
+
this._destroyRenderableByUid(t);
|
|
2147
|
+
this._gpuBitmapText = null, (e = this._sdfShader) == null || e.destroy(!0), this._sdfShader = null, this._renderer = null;
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
at.extension = {
|
|
2151
|
+
type: [
|
|
2152
|
+
b.WebGLPipes,
|
|
2153
|
+
b.WebGPUPipes,
|
|
2154
|
+
b.CanvasPipes
|
|
2155
|
+
],
|
|
2156
|
+
name: "bitmapText"
|
|
2157
|
+
};
|
|
2158
|
+
function Se(i, e) {
|
|
2159
|
+
e.groupTransform = i.groupTransform, e.groupColorAlpha = i.groupColorAlpha, e.groupColor = i.groupColor, e.groupBlendMode = i.groupBlendMode, e.globalDisplayStatus = i.globalDisplayStatus, e.groupTransform = i.groupTransform, e.localDisplayStatus = i.localDisplayStatus, e.groupAlpha = i.groupAlpha, e._roundPixels = i._roundPixels;
|
|
2160
|
+
}
|
|
2161
|
+
class ot {
|
|
2162
|
+
constructor(e) {
|
|
2163
|
+
this._gpuText = /* @__PURE__ */ Object.create(null), this._renderer = e;
|
|
2164
|
+
}
|
|
2165
|
+
validateRenderable(e) {
|
|
2166
|
+
const t = this._getGpuText(e), r = e._getKey();
|
|
2167
|
+
return t.textureNeedsUploading ? (t.textureNeedsUploading = !1, !0) : t.currentKey !== r;
|
|
2168
|
+
}
|
|
2169
|
+
addRenderable(e) {
|
|
2170
|
+
const r = this._getGpuText(e).batchableSprite;
|
|
2171
|
+
e._didTextUpdate && this._updateText(e), this._renderer.renderPipes.batch.addToBatch(r);
|
|
2172
|
+
}
|
|
2173
|
+
updateRenderable(e) {
|
|
2174
|
+
const r = this._getGpuText(e).batchableSprite;
|
|
2175
|
+
e._didTextUpdate && this._updateText(e), r.batcher.updateElement(r);
|
|
2176
|
+
}
|
|
2177
|
+
destroyRenderable(e) {
|
|
2178
|
+
this._destroyRenderableById(e.uid);
|
|
2179
|
+
}
|
|
2180
|
+
_destroyRenderableById(e) {
|
|
2181
|
+
const t = this._gpuText[e];
|
|
2182
|
+
this._renderer.htmlText.decreaseReferenceCount(t.currentKey), B.return(t.batchableSprite), this._gpuText[e] = null;
|
|
2183
|
+
}
|
|
2184
|
+
_updateText(e) {
|
|
2185
|
+
const t = e._getKey(), r = this._getGpuText(e), s = r.batchableSprite;
|
|
2186
|
+
r.currentKey !== t && this._updateGpuText(e).catch((a) => {
|
|
2187
|
+
console.error(a);
|
|
2188
|
+
}), e._didTextUpdate = !1;
|
|
2189
|
+
const n = e._style.padding;
|
|
2190
|
+
se(s.bounds, e._anchor, s.texture, n);
|
|
2191
|
+
}
|
|
2192
|
+
async _updateGpuText(e) {
|
|
2193
|
+
e._didTextUpdate = !1;
|
|
2194
|
+
const t = this._getGpuText(e);
|
|
2195
|
+
if (t.generatingTexture)
|
|
2196
|
+
return;
|
|
2197
|
+
const r = e._getKey();
|
|
2198
|
+
this._renderer.htmlText.decreaseReferenceCount(t.currentKey), t.generatingTexture = !0, t.currentKey = r;
|
|
2199
|
+
const s = e.resolution ?? this._renderer.resolution, n = await this._renderer.htmlText.getManagedTexture(
|
|
2200
|
+
e.text,
|
|
2201
|
+
s,
|
|
2202
|
+
e._style,
|
|
2203
|
+
e._getKey()
|
|
2204
|
+
), a = t.batchableSprite;
|
|
2205
|
+
a.texture = t.texture = n, t.generatingTexture = !1, t.textureNeedsUploading = !0, e.onViewUpdate();
|
|
2206
|
+
const o = e._style.padding;
|
|
2207
|
+
se(a.bounds, e._anchor, a.texture, o);
|
|
2208
|
+
}
|
|
2209
|
+
_getGpuText(e) {
|
|
2210
|
+
return this._gpuText[e.uid] || this.initGpuText(e);
|
|
2211
|
+
}
|
|
2212
|
+
initGpuText(e) {
|
|
2213
|
+
const t = {
|
|
2214
|
+
texture: R.EMPTY,
|
|
2215
|
+
currentKey: "--",
|
|
2216
|
+
batchableSprite: B.get(Ie),
|
|
2217
|
+
textureNeedsUploading: !1,
|
|
2218
|
+
generatingTexture: !1
|
|
2219
|
+
}, r = t.batchableSprite;
|
|
2220
|
+
return r.renderable = e, r.texture = R.EMPTY, r.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, r.roundPixels = this._renderer._roundPixels | e._roundPixels, this._gpuText[e.uid] = t, e.on("destroyed", () => {
|
|
2221
|
+
this.destroyRenderable(e);
|
|
2222
|
+
}), t;
|
|
2223
|
+
}
|
|
2224
|
+
destroy() {
|
|
2225
|
+
for (const e in this._gpuText)
|
|
2226
|
+
this._destroyRenderableById(e);
|
|
2227
|
+
this._gpuText = null, this._renderer = null;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
ot.extension = {
|
|
2231
|
+
type: [
|
|
2232
|
+
b.WebGLPipes,
|
|
2233
|
+
b.WebGPUPipes,
|
|
2234
|
+
b.CanvasPipes
|
|
2235
|
+
],
|
|
2236
|
+
name: "htmlText"
|
|
2237
|
+
};
|
|
2238
|
+
function cr() {
|
|
2239
|
+
const { userAgent: i } = $.get().getNavigator();
|
|
2240
|
+
return /^((?!chrome|android).)*safari/i.test(i);
|
|
2241
|
+
}
|
|
2242
|
+
const hr = new Re();
|
|
2243
|
+
function ct(i, e, t, r) {
|
|
2244
|
+
const s = hr;
|
|
2245
|
+
s.minX = 0, s.minY = 0, s.maxX = i.width / r | 0, s.maxY = i.height / r | 0;
|
|
2246
|
+
const n = A.getOptimalTexture(
|
|
2247
|
+
s.width,
|
|
2248
|
+
s.height,
|
|
2249
|
+
r,
|
|
2250
|
+
!1
|
|
2251
|
+
);
|
|
2252
|
+
return n.source.uploadMethodId = "image", n.source.resource = i, n.source.alphaMode = "premultiply-alpha-on-upload", n.frame.width = e / r, n.frame.height = t / r, n.source.emit("update", n.source), n.updateUvs(), n;
|
|
2253
|
+
}
|
|
2254
|
+
function lr(i, e) {
|
|
2255
|
+
const t = e.fontFamily, r = [], s = {}, n = /font-family:([^;"\s]+)/g, a = i.match(n);
|
|
2256
|
+
function o(c) {
|
|
2257
|
+
s[c] || (r.push(c), s[c] = !0);
|
|
2258
|
+
}
|
|
2259
|
+
if (Array.isArray(t))
|
|
2260
|
+
for (let c = 0; c < t.length; c++)
|
|
2261
|
+
o(t[c]);
|
|
2262
|
+
else
|
|
2263
|
+
o(t);
|
|
2264
|
+
a && a.forEach((c) => {
|
|
2265
|
+
const l = c.split(":")[1].trim();
|
|
2266
|
+
o(l);
|
|
2267
|
+
});
|
|
2268
|
+
for (const c in e.tagStyles) {
|
|
2269
|
+
const l = e.tagStyles[c].fontFamily;
|
|
2270
|
+
o(l);
|
|
2271
|
+
}
|
|
2272
|
+
return r;
|
|
2273
|
+
}
|
|
2274
|
+
async function dr(i) {
|
|
2275
|
+
const t = await (await $.get().fetch(i)).blob(), r = new FileReader();
|
|
2276
|
+
return await new Promise((n, a) => {
|
|
2277
|
+
r.onloadend = () => n(r.result), r.onerror = a, r.readAsDataURL(t);
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
async function Ce(i, e) {
|
|
2281
|
+
const t = await dr(e);
|
|
2282
|
+
return `@font-face {
|
|
2283
|
+
font-family: "${i.fontFamily}";
|
|
2284
|
+
src: url('${t}');
|
|
2285
|
+
font-weight: ${i.fontWeight};
|
|
2286
|
+
font-style: ${i.fontStyle};
|
|
2287
|
+
}`;
|
|
2288
|
+
}
|
|
2289
|
+
const j = /* @__PURE__ */ new Map();
|
|
2290
|
+
async function ur(i, e, t) {
|
|
2291
|
+
const r = i.filter((s) => M.has(`${s}-and-url`)).map((s, n) => {
|
|
2292
|
+
if (!j.has(s)) {
|
|
2293
|
+
const { url: a } = M.get(`${s}-and-url`);
|
|
2294
|
+
n === 0 ? j.set(s, Ce(e, a)) : j.set(s, Ce({
|
|
2295
|
+
fontWeight: t.fontWeight,
|
|
2296
|
+
fontStyle: t.fontStyle,
|
|
2297
|
+
fontFamily: s
|
|
2298
|
+
}, a));
|
|
2299
|
+
}
|
|
2300
|
+
return j.get(s);
|
|
2301
|
+
});
|
|
2302
|
+
return (await Promise.all(r)).join(`
|
|
2303
|
+
`);
|
|
2304
|
+
}
|
|
2305
|
+
function fr(i, e, t, r, s) {
|
|
2306
|
+
const { domElement: n, styleElement: a, svgRoot: o } = s;
|
|
2307
|
+
n.innerHTML = `<style>${e.cssStyle}</style><div>${i}</div>`, n.setAttribute("style", `transform: scale(${t});transform-origin: top left; display: inline-block`), a.textContent = r;
|
|
2308
|
+
const { width: c, height: l } = s.image;
|
|
2309
|
+
return o.setAttribute("width", c.toString()), o.setAttribute("height", l.toString()), new XMLSerializer().serializeToString(o);
|
|
2310
|
+
}
|
|
2311
|
+
function pr(i, e) {
|
|
2312
|
+
const t = W.getOptimalCanvasAndContext(
|
|
2313
|
+
i.width,
|
|
2314
|
+
i.height,
|
|
2315
|
+
e
|
|
2316
|
+
), { context: r } = t;
|
|
2317
|
+
return r.clearRect(0, 0, i.width, i.height), r.drawImage(i, 0, 0), W.returnCanvasAndContext(t), t.canvas;
|
|
2318
|
+
}
|
|
2319
|
+
function gr(i, e, t) {
|
|
2320
|
+
return new Promise(async (r) => {
|
|
2321
|
+
t && await new Promise((s) => setTimeout(s, 100)), i.onload = () => {
|
|
2322
|
+
r();
|
|
2323
|
+
}, i.src = `data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`, i.crossOrigin = "anonymous";
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
class le {
|
|
2327
|
+
constructor(e) {
|
|
2328
|
+
this._activeTextures = {}, this._renderer = e, this._createCanvas = e.type === ne.WEBGPU;
|
|
2329
|
+
}
|
|
2330
|
+
getTexture(e) {
|
|
2331
|
+
return this._buildTexturePromise(
|
|
2332
|
+
e.text,
|
|
2333
|
+
e.resolution,
|
|
2334
|
+
e.style
|
|
2335
|
+
);
|
|
2336
|
+
}
|
|
2337
|
+
getManagedTexture(e, t, r, s) {
|
|
2338
|
+
if (this._activeTextures[s])
|
|
2339
|
+
return this._increaseReferenceCount(s), this._activeTextures[s].promise;
|
|
2340
|
+
const n = this._buildTexturePromise(e, t, r).then((a) => (this._activeTextures[s].texture = a, a));
|
|
2341
|
+
return this._activeTextures[s] = {
|
|
2342
|
+
texture: null,
|
|
2343
|
+
promise: n,
|
|
2344
|
+
usageCount: 1
|
|
2345
|
+
}, n;
|
|
2346
|
+
}
|
|
2347
|
+
async _buildTexturePromise(e, t, r) {
|
|
2348
|
+
const s = B.get(qe), n = lr(e, r), a = await ur(
|
|
2349
|
+
n,
|
|
2350
|
+
r,
|
|
2351
|
+
ce.defaultTextStyle
|
|
2352
|
+
), o = Yt(e, r, a, s), c = Math.ceil(Math.ceil(Math.max(1, o.width) + r.padding * 2) * t), l = Math.ceil(Math.ceil(Math.max(1, o.height) + r.padding * 2) * t), h = s.image;
|
|
2353
|
+
h.width = c | 0, h.height = l | 0;
|
|
2354
|
+
const d = fr(e, r, t, a, s);
|
|
2355
|
+
await gr(h, d, cr() && n.length > 0);
|
|
2356
|
+
let u = h;
|
|
2357
|
+
this._createCanvas && (u = pr(h, t));
|
|
2358
|
+
const f = ct(u, h.width, h.height, t);
|
|
2359
|
+
return this._createCanvas && this._renderer.texture.initSource(f.source), B.return(s), f;
|
|
2360
|
+
}
|
|
2361
|
+
_increaseReferenceCount(e) {
|
|
2362
|
+
this._activeTextures[e].usageCount++;
|
|
2363
|
+
}
|
|
2364
|
+
decreaseReferenceCount(e) {
|
|
2365
|
+
const t = this._activeTextures[e];
|
|
2366
|
+
t && (t.usageCount--, t.usageCount === 0 && (t.texture ? this._cleanUp(t) : t.promise.then((r) => {
|
|
2367
|
+
t.texture = r, this._cleanUp(t);
|
|
2368
|
+
}).catch(() => {
|
|
2369
|
+
L("HTMLTextSystem: Failed to clean texture");
|
|
2370
|
+
}), this._activeTextures[e] = null));
|
|
2371
|
+
}
|
|
2372
|
+
_cleanUp(e) {
|
|
2373
|
+
A.returnTexture(e.texture), e.texture.source.resource = null, e.texture.source.uploadMethodId = "unknown";
|
|
2374
|
+
}
|
|
2375
|
+
getReferenceCount(e) {
|
|
2376
|
+
return this._activeTextures[e].usageCount;
|
|
2377
|
+
}
|
|
2378
|
+
destroy() {
|
|
2379
|
+
this._activeTextures = null;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
le.extension = {
|
|
2383
|
+
type: [
|
|
2384
|
+
b.WebGLSystem,
|
|
2385
|
+
b.WebGPUSystem,
|
|
2386
|
+
b.CanvasSystem
|
|
2387
|
+
],
|
|
2388
|
+
name: "htmlText"
|
|
2389
|
+
};
|
|
2390
|
+
le.defaultFontOptions = {
|
|
2391
|
+
fontFamily: "Arial",
|
|
2392
|
+
fontStyle: "normal",
|
|
2393
|
+
fontWeight: "normal"
|
|
2394
|
+
};
|
|
2395
|
+
class ht {
|
|
2396
|
+
constructor(e) {
|
|
2397
|
+
this._gpuText = /* @__PURE__ */ Object.create(null), this._renderer = e;
|
|
2398
|
+
}
|
|
2399
|
+
validateRenderable(e) {
|
|
2400
|
+
const t = this._getGpuText(e), r = e._getKey();
|
|
2401
|
+
if (t.currentKey !== r) {
|
|
2402
|
+
const s = e.resolution ?? this._renderer.resolution, { width: n, height: a } = this._renderer.canvasText.getTextureSize(
|
|
2403
|
+
e.text,
|
|
2404
|
+
s,
|
|
2405
|
+
e._style
|
|
2406
|
+
);
|
|
2407
|
+
return (
|
|
2408
|
+
// is only being used by this text:
|
|
2409
|
+
!(this._renderer.canvasText.getReferenceCount(t.currentKey) === 1 && n === t.texture._source.width && a === t.texture._source.height)
|
|
2410
|
+
);
|
|
2411
|
+
}
|
|
2412
|
+
return !1;
|
|
2413
|
+
}
|
|
2414
|
+
addRenderable(e, t) {
|
|
2415
|
+
const s = this._getGpuText(e).batchableSprite;
|
|
2416
|
+
e._didTextUpdate && this._updateText(e), this._renderer.renderPipes.batch.addToBatch(s);
|
|
2417
|
+
}
|
|
2418
|
+
updateRenderable(e) {
|
|
2419
|
+
const r = this._getGpuText(e).batchableSprite;
|
|
2420
|
+
e._didTextUpdate && this._updateText(e), r.batcher.updateElement(r);
|
|
2421
|
+
}
|
|
2422
|
+
destroyRenderable(e) {
|
|
2423
|
+
this._destroyRenderableById(e.uid);
|
|
2424
|
+
}
|
|
2425
|
+
_destroyRenderableById(e) {
|
|
2426
|
+
const t = this._gpuText[e];
|
|
2427
|
+
this._renderer.canvasText.decreaseReferenceCount(t.currentKey), B.return(t.batchableSprite), this._gpuText[e] = null;
|
|
2428
|
+
}
|
|
2429
|
+
_updateText(e) {
|
|
2430
|
+
const t = e._getKey(), r = this._getGpuText(e), s = r.batchableSprite;
|
|
2431
|
+
r.currentKey !== t && this._updateGpuText(e), e._didTextUpdate = !1;
|
|
2432
|
+
const n = e._style.padding;
|
|
2433
|
+
se(s.bounds, e._anchor, s.texture, n);
|
|
2434
|
+
}
|
|
2435
|
+
_updateGpuText(e) {
|
|
2436
|
+
const t = this._getGpuText(e), r = t.batchableSprite;
|
|
2437
|
+
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;
|
|
2438
|
+
}
|
|
2439
|
+
_getGpuText(e) {
|
|
2440
|
+
return this._gpuText[e.uid] || this.initGpuText(e);
|
|
2441
|
+
}
|
|
2442
|
+
initGpuText(e) {
|
|
2443
|
+
const t = {
|
|
2444
|
+
texture: null,
|
|
2445
|
+
currentKey: "--",
|
|
2446
|
+
batchableSprite: B.get(Ie)
|
|
2447
|
+
};
|
|
2448
|
+
return t.batchableSprite.renderable = e, t.batchableSprite.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, t.batchableSprite.roundPixels = this._renderer._roundPixels | e._roundPixels, this._gpuText[e.uid] = t, this._updateText(e), e.on("destroyed", () => {
|
|
2449
|
+
this.destroyRenderable(e);
|
|
2450
|
+
}), t;
|
|
2451
|
+
}
|
|
2452
|
+
destroy() {
|
|
2453
|
+
for (const e in this._gpuText)
|
|
2454
|
+
this._destroyRenderableById(e);
|
|
2455
|
+
this._gpuText = null, this._renderer = null;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
ht.extension = {
|
|
2459
|
+
type: [
|
|
2460
|
+
b.WebGLPipes,
|
|
2461
|
+
b.WebGPUPipes,
|
|
2462
|
+
b.CanvasPipes
|
|
2463
|
+
],
|
|
2464
|
+
name: "text"
|
|
2465
|
+
};
|
|
2466
|
+
function Be(i, e, t) {
|
|
2467
|
+
for (let r = 0, s = 4 * t * e; r < e; ++r, s += 4)
|
|
2468
|
+
if (i[s + 3] !== 0)
|
|
2469
|
+
return !1;
|
|
2470
|
+
return !0;
|
|
2471
|
+
}
|
|
2472
|
+
function Pe(i, e, t, r, s) {
|
|
2473
|
+
const n = 4 * e;
|
|
2474
|
+
for (let a = r, o = r * n + 4 * t; a <= s; ++a, o += n)
|
|
2475
|
+
if (i[o + 3] !== 0)
|
|
2476
|
+
return !1;
|
|
2477
|
+
return !0;
|
|
2478
|
+
}
|
|
2479
|
+
function mr(i, e = 1) {
|
|
2480
|
+
const { width: t, height: r } = i, s = i.getContext("2d", {
|
|
2481
|
+
willReadFrequently: !0
|
|
2482
|
+
});
|
|
2483
|
+
if (s === null)
|
|
2484
|
+
throw new TypeError("Failed to get canvas 2D context");
|
|
2485
|
+
const a = s.getImageData(0, 0, t, r).data;
|
|
2486
|
+
let o = 0, c = 0, l = t - 1, h = r - 1;
|
|
2487
|
+
for (; c < r && Be(a, t, c); )
|
|
2488
|
+
++c;
|
|
2489
|
+
if (c === r)
|
|
2490
|
+
return V.EMPTY;
|
|
2491
|
+
for (; Be(a, t, h); )
|
|
2492
|
+
--h;
|
|
2493
|
+
for (; Pe(a, t, o, c, h); )
|
|
2494
|
+
++o;
|
|
2495
|
+
for (; Pe(a, t, l, c, h); )
|
|
2496
|
+
--l;
|
|
2497
|
+
return ++l, ++h, new V(o / e, c / e, (l - o) / e, (h - c) / e);
|
|
2498
|
+
}
|
|
2499
|
+
class lt {
|
|
2500
|
+
constructor(e) {
|
|
2501
|
+
this._activeTextures = {}, this._renderer = e;
|
|
2502
|
+
}
|
|
2503
|
+
getTextureSize(e, t, r) {
|
|
2504
|
+
const s = z.measureText(e || " ", r);
|
|
2505
|
+
let n = Math.ceil(Math.ceil(Math.max(1, s.width) + r.padding * 2) * t), a = Math.ceil(Math.ceil(Math.max(1, s.height) + r.padding * 2) * t);
|
|
2506
|
+
return n = Math.ceil(n - 1e-6), a = Math.ceil(a - 1e-6), n = ge(n), a = ge(a), { width: n, height: a };
|
|
2507
|
+
}
|
|
2508
|
+
getTexture(e, t, r, s) {
|
|
2509
|
+
typeof e == "string" && (k("8.0.0", "CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"), e = {
|
|
2510
|
+
text: e,
|
|
2511
|
+
style: r,
|
|
2512
|
+
resolution: t
|
|
2513
|
+
}), e.style instanceof E || (e.style = new E(e.style));
|
|
2514
|
+
const { texture: n, canvasAndContext: a } = this.createTextureAndCanvas(
|
|
2515
|
+
e
|
|
2516
|
+
);
|
|
2517
|
+
return this._renderer.texture.initSource(n._source), W.returnCanvasAndContext(a), n;
|
|
2518
|
+
}
|
|
2519
|
+
createTextureAndCanvas(e) {
|
|
2520
|
+
const { text: t, style: r } = e, s = e.resolution ?? this._renderer.resolution, n = z.measureText(t || " ", r), a = Math.ceil(Math.ceil(Math.max(1, n.width) + r.padding * 2) * s), o = Math.ceil(Math.ceil(Math.max(1, n.height) + r.padding * 2) * s), c = W.getOptimalCanvasAndContext(a, o), { canvas: l } = c;
|
|
2521
|
+
this.renderTextToCanvas(t, r, s, c);
|
|
2522
|
+
const h = ct(l, a, o, s);
|
|
2523
|
+
if (r.trim) {
|
|
2524
|
+
const d = mr(l, s);
|
|
2525
|
+
h.frame.copyFrom(d), h.updateUvs();
|
|
2526
|
+
}
|
|
2527
|
+
return { texture: h, canvasAndContext: c };
|
|
2528
|
+
}
|
|
2529
|
+
getManagedTexture(e) {
|
|
2530
|
+
const t = e._getKey();
|
|
2531
|
+
if (this._activeTextures[t])
|
|
2532
|
+
return this._increaseReferenceCount(t), this._activeTextures[t].texture;
|
|
2533
|
+
const { texture: r, canvasAndContext: s } = this.createTextureAndCanvas(e);
|
|
2534
|
+
return this._activeTextures[t] = {
|
|
2535
|
+
canvasAndContext: s,
|
|
2536
|
+
texture: r,
|
|
2537
|
+
usageCount: 1
|
|
2538
|
+
}, r;
|
|
2539
|
+
}
|
|
2540
|
+
_increaseReferenceCount(e) {
|
|
2541
|
+
this._activeTextures[e].usageCount++;
|
|
2542
|
+
}
|
|
2543
|
+
decreaseReferenceCount(e) {
|
|
2544
|
+
const t = this._activeTextures[e];
|
|
2545
|
+
if (t.usageCount--, t.usageCount === 0) {
|
|
2546
|
+
W.returnCanvasAndContext(t.canvasAndContext), A.returnTexture(t.texture);
|
|
2547
|
+
const r = t.texture.source;
|
|
2548
|
+
r.resource = null, r.uploadMethodId = "unknown", r.alphaMode = "no-premultiply-alpha", this._activeTextures[e] = null;
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
getReferenceCount(e) {
|
|
2552
|
+
return this._activeTextures[e].usageCount;
|
|
2553
|
+
}
|
|
2554
|
+
/**
|
|
2555
|
+
* Renders text to its canvas, and updates its texture.
|
|
2556
|
+
*
|
|
2557
|
+
* By default this is used internally to ensure the texture is correct before rendering,
|
|
2558
|
+
* but it can be used called externally, for example from this class to 'pre-generate' the texture from a piece of text,
|
|
2559
|
+
* and then shared across multiple Sprites.
|
|
2560
|
+
* @param text
|
|
2561
|
+
* @param style
|
|
2562
|
+
* @param resolution
|
|
2563
|
+
* @param canvasAndContext
|
|
2564
|
+
*/
|
|
2565
|
+
renderTextToCanvas(e, t, r, s) {
|
|
2566
|
+
var y, T, w, F, v;
|
|
2567
|
+
const { canvas: n, context: a } = s, o = re(t), c = z.measureText(e || " ", t), l = c.lines, h = c.lineHeight, d = c.lineWidths, u = c.maxLineWidth, f = c.fontProperties, p = n.height;
|
|
2568
|
+
a.resetTransform(), a.scale(r, r);
|
|
2569
|
+
const g = t.padding * 2;
|
|
2570
|
+
if (a.clearRect(0, 0, c.width + 4 + g, c.height + 4 + g), (y = t._stroke) != null && y.width) {
|
|
2571
|
+
const S = t._stroke;
|
|
2572
|
+
a.lineWidth = S.width, a.miterLimit = S.miterLimit, a.lineJoin = S.join, a.lineCap = S.cap;
|
|
2573
|
+
}
|
|
2574
|
+
a.font = o;
|
|
2575
|
+
let m, x;
|
|
2576
|
+
const _ = t.dropShadow ? 2 : 1;
|
|
2577
|
+
for (let S = 0; S < _; ++S) {
|
|
2578
|
+
const G = t.dropShadow && S === 0, O = G ? Math.ceil(Math.max(1, p) + t.padding * 2) : 0, N = O * r;
|
|
2579
|
+
if (G) {
|
|
2580
|
+
a.fillStyle = "black", a.strokeStyle = "black";
|
|
2581
|
+
const C = t.dropShadow, dt = C.color, ut = C.alpha;
|
|
2582
|
+
a.shadowColor = I.shared.setValue(dt).setAlpha(ut).toRgbaString();
|
|
2583
|
+
const ft = C.blur * r, fe = C.distance * r;
|
|
2584
|
+
a.shadowBlur = ft, a.shadowOffsetX = Math.cos(C.angle) * fe, a.shadowOffsetY = Math.sin(C.angle) * fe + N;
|
|
2585
|
+
} else
|
|
2586
|
+
a.globalAlpha = ((T = t._fill) == null ? void 0 : T.alpha) ?? 1, a.fillStyle = t._fill ? K(t._fill, a) : null, (w = t._stroke) != null && w.width && (a.strokeStyle = K(t._stroke, a)), a.shadowColor = "black";
|
|
2587
|
+
let de = (h - f.fontSize) / 2;
|
|
2588
|
+
h - f.fontSize < 0 && (de = 0);
|
|
2589
|
+
const ue = ((F = t._stroke) == null ? void 0 : F.width) ?? 0;
|
|
2590
|
+
for (let C = 0; C < l.length; C++)
|
|
2591
|
+
m = ue / 2, x = ue / 2 + C * h + f.ascent + de, t.align === "right" ? m += u - d[C] : t.align === "center" && (m += (u - d[C]) / 2), (v = t._stroke) != null && v.width && this._drawLetterSpacing(
|
|
2592
|
+
l[C],
|
|
2593
|
+
t,
|
|
2594
|
+
s,
|
|
2595
|
+
m + t.padding,
|
|
2596
|
+
x + t.padding - O,
|
|
2597
|
+
!0
|
|
2598
|
+
), t._fill !== void 0 && this._drawLetterSpacing(
|
|
2599
|
+
l[C],
|
|
2600
|
+
t,
|
|
2601
|
+
s,
|
|
2602
|
+
m + t.padding,
|
|
2603
|
+
x + t.padding - O
|
|
2604
|
+
);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Render the text with letter-spacing.
|
|
2609
|
+
* @param text - The text to draw
|
|
2610
|
+
* @param style
|
|
2611
|
+
* @param canvasAndContext
|
|
2612
|
+
* @param x - Horizontal position to draw the text
|
|
2613
|
+
* @param y - Vertical position to draw the text
|
|
2614
|
+
* @param isStroke - Is this drawing for the outside stroke of the
|
|
2615
|
+
* text? If not, it's for the inside fill
|
|
2616
|
+
*/
|
|
2617
|
+
_drawLetterSpacing(e, t, r, s, n, a = !1) {
|
|
2618
|
+
const { context: o } = r, c = t.letterSpacing;
|
|
2619
|
+
let l = !1;
|
|
2620
|
+
if (z.experimentalLetterSpacingSupported && (z.experimentalLetterSpacing ? (o.letterSpacing = `${c}px`, o.textLetterSpacing = `${c}px`, l = !0) : (o.letterSpacing = "0px", o.textLetterSpacing = "0px")), c === 0 || l) {
|
|
2621
|
+
a ? o.strokeText(e, s, n) : o.fillText(e, s, n);
|
|
2622
|
+
return;
|
|
2623
|
+
}
|
|
2624
|
+
let h = s;
|
|
2625
|
+
const d = z.graphemeSegmenter(e);
|
|
2626
|
+
let u = o.measureText(e).width, f = 0;
|
|
2627
|
+
for (let p = 0; p < d.length; ++p) {
|
|
2628
|
+
const g = d[p];
|
|
2629
|
+
a ? o.strokeText(g, h, n) : o.fillText(g, h, n);
|
|
2630
|
+
let m = "";
|
|
2631
|
+
for (let x = p + 1; x < d.length; ++x)
|
|
2632
|
+
m += d[x];
|
|
2633
|
+
f = o.measureText(m).width, h += u - f + c, u = f;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
destroy() {
|
|
2637
|
+
this._activeTextures = null;
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
lt.extension = {
|
|
2641
|
+
type: [
|
|
2642
|
+
b.WebGLSystem,
|
|
2643
|
+
b.WebGPUSystem,
|
|
2644
|
+
b.CanvasSystem
|
|
2645
|
+
],
|
|
2646
|
+
name: "canvasText"
|
|
2647
|
+
};
|
|
2648
|
+
P.add(We);
|
|
2649
|
+
P.add(Oe);
|
|
2650
|
+
P.add(Qe);
|
|
2651
|
+
P.add(Bt);
|
|
2652
|
+
P.add(et);
|
|
2653
|
+
P.add(lt);
|
|
2654
|
+
P.add(ht);
|
|
2655
|
+
P.add(at, rr, tr);
|
|
2656
|
+
P.add(le);
|
|
2657
|
+
P.add(ot);
|
|
2658
|
+
P.add(it);
|
|
2659
|
+
P.add(st);
|
|
2660
|
+
P.add(Ee);
|
|
2661
|
+
P.add(De);
|