@designcombo/video 0.0.0

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.
Files changed (47) hide show
  1. package/LICENSE +63 -0
  2. package/dist/SharedSystems-BSw9neqH.js +2691 -0
  3. package/dist/WebGLRenderer-BrabW-VK.js +2639 -0
  4. package/dist/WebGPURenderer-BKwBKkzk.js +1655 -0
  5. package/dist/browserAll-C7HVZtqZ.js +1876 -0
  6. package/dist/clips/audio-clip.d.ts +132 -0
  7. package/dist/clips/base-clip.d.ts +86 -0
  8. package/dist/clips/caption-clip.d.ts +257 -0
  9. package/dist/clips/iclip.d.ts +120 -0
  10. package/dist/clips/image-clip.d.ts +110 -0
  11. package/dist/clips/index.d.ts +8 -0
  12. package/dist/clips/text-clip.d.ts +192 -0
  13. package/dist/clips/video-clip.d.ts +200 -0
  14. package/dist/colorToUniform-Du0ROyNd.js +274 -0
  15. package/dist/compositor.d.ts +111 -0
  16. package/dist/index-CjzowIhV.js +28270 -0
  17. package/dist/index.d.ts +14 -0
  18. package/dist/index.es.js +20 -0
  19. package/dist/index.umd.js +1295 -0
  20. package/dist/internal-utils/event-tool.d.ts +50 -0
  21. package/dist/internal-utils/index.d.ts +14 -0
  22. package/dist/internal-utils/log.d.ts +34 -0
  23. package/dist/internal-utils/meta-box.d.ts +1 -0
  24. package/dist/internal-utils/recodemux.d.ts +65 -0
  25. package/dist/internal-utils/stream-utils.d.ts +43 -0
  26. package/dist/internal-utils/worker-timer.d.ts +8 -0
  27. package/dist/json-serialization.d.ts +142 -0
  28. package/dist/mp4-utils/index.d.ts +31 -0
  29. package/dist/mp4-utils/mp4box-utils.d.ts +36 -0
  30. package/dist/mp4-utils/sample-transform.d.ts +23 -0
  31. package/dist/sprite/base-sprite.d.ts +147 -0
  32. package/dist/sprite/pixi-sprite-renderer.d.ts +48 -0
  33. package/dist/studio.d.ts +142 -0
  34. package/dist/transfomer/parts/handle.d.ts +17 -0
  35. package/dist/transfomer/parts/wireframe.d.ts +5 -0
  36. package/dist/transfomer/transformer.d.ts +21 -0
  37. package/dist/utils/audio.d.ts +82 -0
  38. package/dist/utils/chromakey.d.ts +24 -0
  39. package/dist/utils/color.d.ts +4 -0
  40. package/dist/utils/common.d.ts +7 -0
  41. package/dist/utils/dom.d.ts +48 -0
  42. package/dist/utils/fonts.d.ts +16 -0
  43. package/dist/utils/index.d.ts +5 -0
  44. package/dist/utils/srt-parser.d.ts +15 -0
  45. package/dist/utils/video.d.ts +18 -0
  46. package/dist/webworkerAll-DsE6HIYE.js +2497 -0
  47. package/package.json +53 -0
@@ -0,0 +1,2497 @@
1
+ import { E as p, U as $e, T as ee, G as he, a as fe, M as P, m as C, h as pe, F as v, t as w, a6 as N, R as $, w as Y, z as me, a3 as G, a4 as ge, d as F, B as T, D as j, x as M, ad as je, ae as q, J as L, af as U, S as Q, _ as qe, Z as X, o as xe, s as _e, a8 as be, ab as ye, p as Qe, q as Je, a9 as Ze, aa as et, ac as tt, ag as rt, ah as nt, ai as st, aj as H, ak as it, al as at, n as ve, am as te, an as k, e as b, ao as ot } from "./index-CjzowIhV.js";
2
+ import { F as ut, S as D, c as z, a as lt, b as ct, B as Te } from "./colorToUniform-Du0ROyNd.js";
3
+ class Pe {
4
+ /**
5
+ * Initialize the plugin with scope of application instance
6
+ * @private
7
+ * @param {object} [options] - See application options
8
+ */
9
+ static init(e) {
10
+ Object.defineProperty(
11
+ this,
12
+ "resizeTo",
13
+ {
14
+ configurable: !0,
15
+ set(t) {
16
+ globalThis.removeEventListener("resize", this.queueResize), this._resizeTo = t, t && (globalThis.addEventListener("resize", this.queueResize), this.resize());
17
+ },
18
+ get() {
19
+ return this._resizeTo;
20
+ }
21
+ }
22
+ ), this.queueResize = () => {
23
+ this._resizeTo && (this._cancelResize(), this._resizeId = requestAnimationFrame(() => this.resize()));
24
+ }, this._cancelResize = () => {
25
+ this._resizeId && (cancelAnimationFrame(this._resizeId), this._resizeId = null);
26
+ }, this.resize = () => {
27
+ if (!this._resizeTo)
28
+ return;
29
+ this._cancelResize();
30
+ let t, r;
31
+ if (this._resizeTo === globalThis.window)
32
+ t = globalThis.innerWidth, r = globalThis.innerHeight;
33
+ else {
34
+ const { clientWidth: n, clientHeight: s } = this._resizeTo;
35
+ t = n, r = s;
36
+ }
37
+ this.renderer.resize(t, r), this.render();
38
+ }, this._resizeId = null, this._resizeTo = null, this.resizeTo = e.resizeTo || null;
39
+ }
40
+ /**
41
+ * Clean up the ticker, scoped to application
42
+ * @private
43
+ */
44
+ static destroy() {
45
+ globalThis.removeEventListener("resize", this.queueResize), this._cancelResize(), this._cancelResize = null, this.queueResize = null, this.resizeTo = null, this.resize = null;
46
+ }
47
+ }
48
+ Pe.extension = p.Application;
49
+ class we {
50
+ /**
51
+ * Initialize the plugin with scope of application instance
52
+ * @private
53
+ * @param {object} [options] - See application options
54
+ */
55
+ static init(e) {
56
+ e = Object.assign({
57
+ autoStart: !0,
58
+ sharedTicker: !1
59
+ }, e), Object.defineProperty(
60
+ this,
61
+ "ticker",
62
+ {
63
+ configurable: !0,
64
+ set(t) {
65
+ this._ticker && this._ticker.remove(this.render, this), this._ticker = t, t && t.add(this.render, this, $e.LOW);
66
+ },
67
+ get() {
68
+ return this._ticker;
69
+ }
70
+ }
71
+ ), this.stop = () => {
72
+ this._ticker.stop();
73
+ }, this.start = () => {
74
+ this._ticker.start();
75
+ }, this._ticker = null, this.ticker = e.sharedTicker ? ee.shared : new ee(), e.autoStart && this.start();
76
+ }
77
+ /**
78
+ * Clean up the ticker, scoped to application.
79
+ * @private
80
+ */
81
+ static destroy() {
82
+ if (this._ticker) {
83
+ const e = this._ticker;
84
+ this.ticker = null, e.destroy();
85
+ }
86
+ }
87
+ }
88
+ we.extension = p.Application;
89
+ var dt = `in vec2 aPosition;
90
+ out vec2 vTextureCoord;
91
+
92
+ uniform vec4 uInputSize;
93
+ uniform vec4 uOutputFrame;
94
+ uniform vec4 uOutputTexture;
95
+
96
+ vec4 filterVertexPosition( void )
97
+ {
98
+ vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
99
+
100
+ position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
101
+ position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
102
+
103
+ return vec4(position, 0.0, 1.0);
104
+ }
105
+
106
+ vec2 filterTextureCoord( void )
107
+ {
108
+ return aPosition * (uOutputFrame.zw * uInputSize.zw);
109
+ }
110
+
111
+ void main(void)
112
+ {
113
+ gl_Position = filterVertexPosition();
114
+ vTextureCoord = filterTextureCoord();
115
+ }
116
+ `, ht = `in vec2 vTextureCoord;
117
+ out vec4 finalColor;
118
+ uniform sampler2D uTexture;
119
+ void main() {
120
+ finalColor = texture(uTexture, vTextureCoord);
121
+ }
122
+ `, re = `struct GlobalFilterUniforms {
123
+ uInputSize: vec4<f32>,
124
+ uInputPixel: vec4<f32>,
125
+ uInputClamp: vec4<f32>,
126
+ uOutputFrame: vec4<f32>,
127
+ uGlobalFrame: vec4<f32>,
128
+ uOutputTexture: vec4<f32>,
129
+ };
130
+
131
+ @group(0) @binding(0) var <uniform> gfu: GlobalFilterUniforms;
132
+ @group(0) @binding(1) var uTexture: texture_2d<f32>;
133
+ @group(0) @binding(2) var uSampler: sampler;
134
+
135
+ struct VSOutput {
136
+ @builtin(position) position: vec4<f32>,
137
+ @location(0) uv: vec2<f32>
138
+ };
139
+
140
+ fn filterVertexPosition(aPosition: vec2<f32>) -> vec4<f32>
141
+ {
142
+ var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
143
+
144
+ position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
145
+ position.y = position.y * (2.0 * gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
146
+
147
+ return vec4(position, 0.0, 1.0);
148
+ }
149
+
150
+ fn filterTextureCoord(aPosition: vec2<f32>) -> vec2<f32>
151
+ {
152
+ return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
153
+ }
154
+
155
+ @vertex
156
+ fn mainVertex(
157
+ @location(0) aPosition: vec2<f32>,
158
+ ) -> VSOutput {
159
+ return VSOutput(
160
+ filterVertexPosition(aPosition),
161
+ filterTextureCoord(aPosition)
162
+ );
163
+ }
164
+
165
+ @fragment
166
+ fn mainFragment(
167
+ @location(0) uv: vec2<f32>,
168
+ ) -> @location(0) vec4<f32> {
169
+ return textureSample(uTexture, uSampler, uv);
170
+ }
171
+ `;
172
+ class ft extends ut {
173
+ constructor() {
174
+ const e = he.from({
175
+ vertex: { source: re, entryPoint: "mainVertex" },
176
+ fragment: { source: re, entryPoint: "mainFragment" },
177
+ name: "passthrough-filter"
178
+ }), t = fe.from({
179
+ vertex: dt,
180
+ fragment: ht,
181
+ name: "passthrough-filter"
182
+ });
183
+ super({
184
+ gpuProgram: e,
185
+ glProgram: t
186
+ });
187
+ }
188
+ }
189
+ class Ce {
190
+ constructor(e) {
191
+ this._renderer = e;
192
+ }
193
+ push(e, t, r) {
194
+ this._renderer.renderPipes.batch.break(r), r.add({
195
+ renderPipeId: "filter",
196
+ canBundle: !1,
197
+ action: "pushFilter",
198
+ container: t,
199
+ filterEffect: e
200
+ });
201
+ }
202
+ pop(e, t, r) {
203
+ this._renderer.renderPipes.batch.break(r), r.add({
204
+ renderPipeId: "filter",
205
+ action: "popFilter",
206
+ canBundle: !1
207
+ });
208
+ }
209
+ execute(e) {
210
+ e.action === "pushFilter" ? this._renderer.filter.push(e) : e.action === "popFilter" && this._renderer.filter.pop();
211
+ }
212
+ destroy() {
213
+ this._renderer = null;
214
+ }
215
+ }
216
+ Ce.extension = {
217
+ type: [
218
+ p.WebGLPipes,
219
+ p.WebGPUPipes,
220
+ p.CanvasPipes
221
+ ],
222
+ name: "filter"
223
+ };
224
+ const ne = new P();
225
+ function pt(a, e) {
226
+ e.clear();
227
+ const t = e.matrix;
228
+ for (let r = 0; r < a.length; r++) {
229
+ const n = a[r];
230
+ if (n.globalDisplayStatus < 7)
231
+ continue;
232
+ const s = n.renderGroup ?? n.parentRenderGroup;
233
+ s?.isCachedAsTexture ? e.matrix = ne.copyFrom(s.textureOffsetInverseTransform).append(n.worldTransform) : s?._parentCacheAsTextureRenderGroup ? e.matrix = ne.copyFrom(s._parentCacheAsTextureRenderGroup.inverseWorldTransform).append(n.groupTransform) : e.matrix = n.worldTransform, e.addBounds(n.bounds);
234
+ }
235
+ return e.matrix = t, e;
236
+ }
237
+ const mt = new N({
238
+ attributes: {
239
+ aPosition: {
240
+ buffer: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
241
+ format: "float32x2",
242
+ stride: 8,
243
+ offset: 0
244
+ }
245
+ },
246
+ indexBuffer: new Uint32Array([0, 1, 2, 0, 2, 3])
247
+ });
248
+ class gt {
249
+ constructor() {
250
+ this.skip = !1, this.inputTexture = null, this.backTexture = null, this.filters = null, this.bounds = new me(), this.container = null, this.blendRequired = !1, this.outputRenderSurface = null, this.globalFrame = { x: 0, y: 0, width: 0, height: 0 }, this.firstEnabledIndex = -1, this.lastEnabledIndex = -1;
251
+ }
252
+ }
253
+ class Se {
254
+ constructor(e) {
255
+ this._filterStackIndex = 0, this._filterStack = [], this._filterGlobalUniforms = new C({
256
+ uInputSize: { value: new Float32Array(4), type: "vec4<f32>" },
257
+ uInputPixel: { value: new Float32Array(4), type: "vec4<f32>" },
258
+ uInputClamp: { value: new Float32Array(4), type: "vec4<f32>" },
259
+ uOutputFrame: { value: new Float32Array(4), type: "vec4<f32>" },
260
+ uGlobalFrame: { value: new Float32Array(4), type: "vec4<f32>" },
261
+ uOutputTexture: { value: new Float32Array(4), type: "vec4<f32>" }
262
+ }), this._globalFilterBindGroup = new pe({}), this.renderer = e;
263
+ }
264
+ /**
265
+ * The back texture of the currently active filter. Requires the filter to have `blendRequired` set to true.
266
+ * @readonly
267
+ */
268
+ get activeBackTexture() {
269
+ return this._activeFilterData?.backTexture;
270
+ }
271
+ /**
272
+ * Pushes a filter instruction onto the filter stack.
273
+ * @param instruction - The instruction containing the filter effect and container.
274
+ * @internal
275
+ */
276
+ push(e) {
277
+ const t = this.renderer, r = e.filterEffect.filters, n = this._pushFilterData();
278
+ n.skip = !1, n.filters = r, n.container = e.container, n.outputRenderSurface = t.renderTarget.renderSurface;
279
+ const s = t.renderTarget.renderTarget.colorTexture.source, i = s.resolution, o = s.antialias;
280
+ if (r.every((f) => !f.enabled)) {
281
+ n.skip = !0;
282
+ return;
283
+ }
284
+ const u = n.bounds;
285
+ if (this._calculateFilterArea(e, u), this._calculateFilterBounds(n, t.renderTarget.rootViewPort, o, i, 1), n.skip)
286
+ return;
287
+ const c = this._getPreviousFilterData(), h = this._findFilterResolution(i);
288
+ let l = 0, d = 0;
289
+ c && (l = c.bounds.minX, d = c.bounds.minY), this._calculateGlobalFrame(
290
+ n,
291
+ l,
292
+ d,
293
+ h,
294
+ s.width,
295
+ s.height
296
+ ), this._setupFilterTextures(n, u, t, c);
297
+ }
298
+ /**
299
+ * Applies filters to a texture.
300
+ *
301
+ * This method takes a texture and a list of filters, applies the filters to the texture,
302
+ * and returns the resulting texture.
303
+ * @param {object} params - The parameters for applying filters.
304
+ * @param {Texture} params.texture - The texture to apply filters to.
305
+ * @param {Filter[]} params.filters - The filters to apply.
306
+ * @returns {Texture} The resulting texture after all filters have been applied.
307
+ * @example
308
+ *
309
+ * ```ts
310
+ * // Create a texture and a list of filters
311
+ * const texture = new Texture(...);
312
+ * const filters = [new BlurFilter(), new ColorMatrixFilter()];
313
+ *
314
+ * // Apply the filters to the texture
315
+ * const resultTexture = filterSystem.applyToTexture({ texture, filters });
316
+ *
317
+ * // Use the resulting texture
318
+ * sprite.texture = resultTexture;
319
+ * ```
320
+ *
321
+ * Key Points:
322
+ * 1. padding is not currently supported here - so clipping may occur with filters that use padding.
323
+ * 2. If all filters are disabled or skipped, the original texture is returned.
324
+ */
325
+ generateFilteredTexture({ texture: e, filters: t }) {
326
+ const r = this._pushFilterData();
327
+ this._activeFilterData = r, r.skip = !1, r.filters = t;
328
+ const n = e.source, s = n.resolution, i = n.antialias;
329
+ if (t.every((f) => !f.enabled))
330
+ return r.skip = !0, e;
331
+ const o = r.bounds;
332
+ if (o.addRect(e.frame), this._calculateFilterBounds(r, o.rectangle, i, s, 0), r.skip)
333
+ return e;
334
+ const u = s;
335
+ this._calculateGlobalFrame(
336
+ r,
337
+ 0,
338
+ 0,
339
+ u,
340
+ n.width,
341
+ n.height
342
+ ), r.outputRenderSurface = v.getOptimalTexture(
343
+ o.width,
344
+ o.height,
345
+ r.resolution,
346
+ r.antialias
347
+ ), r.backTexture = w.EMPTY, r.inputTexture = e, this.renderer.renderTarget.finishRenderPass(), this._applyFiltersToTexture(r, !0);
348
+ const d = r.outputRenderSurface;
349
+ return d.source.alphaMode = "premultiplied-alpha", d;
350
+ }
351
+ /** @internal */
352
+ pop() {
353
+ const e = this.renderer, t = this._popFilterData();
354
+ t.skip || (e.globalUniforms.pop(), e.renderTarget.finishRenderPass(), this._activeFilterData = t, this._applyFiltersToTexture(t, !1), t.blendRequired && v.returnTexture(t.backTexture), v.returnTexture(t.inputTexture));
355
+ }
356
+ /**
357
+ * Copies the last render surface to a texture.
358
+ * @param lastRenderSurface - The last render surface to copy from.
359
+ * @param bounds - The bounds of the area to copy.
360
+ * @param previousBounds - The previous bounds to use for offsetting the copy.
361
+ */
362
+ getBackTexture(e, t, r) {
363
+ const n = e.colorTexture.source._resolution, s = v.getOptimalTexture(
364
+ t.width,
365
+ t.height,
366
+ n,
367
+ !1
368
+ );
369
+ let i = t.minX, o = t.minY;
370
+ r && (i -= r.minX, o -= r.minY), i = Math.floor(i * n), o = Math.floor(o * n);
371
+ const u = Math.ceil(t.width * n), c = Math.ceil(t.height * n);
372
+ return this.renderer.renderTarget.copyToTexture(
373
+ e,
374
+ s,
375
+ { x: i, y: o },
376
+ { width: u, height: c },
377
+ { x: 0, y: 0 }
378
+ ), s;
379
+ }
380
+ /**
381
+ * Applies a filter to a texture.
382
+ * @param filter - The filter to apply.
383
+ * @param input - The input texture.
384
+ * @param output - The output render surface.
385
+ * @param clear - Whether to clear the output surface before applying the filter.
386
+ */
387
+ applyFilter(e, t, r, n) {
388
+ const s = this.renderer, i = this._activeFilterData, u = i.outputRenderSurface === r, c = s.renderTarget.rootRenderTarget.colorTexture.source._resolution, h = this._findFilterResolution(c);
389
+ let l = 0, d = 0;
390
+ if (u) {
391
+ const g = this._findPreviousFilterOffset();
392
+ l = g.x, d = g.y;
393
+ }
394
+ this._updateFilterUniforms(t, r, i, l, d, h, u, n);
395
+ const f = e.enabled ? e : this._getPassthroughFilter();
396
+ this._setupBindGroupsAndRender(f, t, s);
397
+ }
398
+ /**
399
+ * Multiply _input normalized coordinates_ to this matrix to get _sprite texture normalized coordinates_.
400
+ *
401
+ * Use `outputMatrix * vTextureCoord` in the shader.
402
+ * @param outputMatrix - The matrix to output to.
403
+ * @param {Sprite} sprite - The sprite to map to.
404
+ * @returns The mapped matrix.
405
+ */
406
+ calculateSpriteMatrix(e, t) {
407
+ const r = this._activeFilterData, n = e.set(
408
+ r.inputTexture._source.width,
409
+ 0,
410
+ 0,
411
+ r.inputTexture._source.height,
412
+ r.bounds.minX,
413
+ r.bounds.minY
414
+ ), s = t.worldTransform.copyTo(P.shared), i = t.renderGroup || t.parentRenderGroup;
415
+ return i && i.cacheToLocalTransform && s.prepend(i.cacheToLocalTransform), s.invert(), n.prepend(s), n.scale(
416
+ 1 / t.texture.orig.width,
417
+ 1 / t.texture.orig.height
418
+ ), n.translate(t.anchor.x, t.anchor.y), n;
419
+ }
420
+ destroy() {
421
+ this._passthroughFilter?.destroy(!0), this._passthroughFilter = null;
422
+ }
423
+ _getPassthroughFilter() {
424
+ return this._passthroughFilter ?? (this._passthroughFilter = new ft()), this._passthroughFilter;
425
+ }
426
+ /**
427
+ * Sets up the bind groups and renders the filter.
428
+ * @param filter - The filter to apply
429
+ * @param input - The input texture
430
+ * @param renderer - The renderer instance
431
+ */
432
+ _setupBindGroupsAndRender(e, t, r) {
433
+ if (r.renderPipes.uniformBatch) {
434
+ const n = r.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);
435
+ this._globalFilterBindGroup.setResource(n, 0);
436
+ } else
437
+ this._globalFilterBindGroup.setResource(this._filterGlobalUniforms, 0);
438
+ this._globalFilterBindGroup.setResource(t.source, 1), this._globalFilterBindGroup.setResource(t.source.style, 2), e.groups[0] = this._globalFilterBindGroup, r.encoder.draw({
439
+ geometry: mt,
440
+ shader: e,
441
+ state: e._state,
442
+ topology: "triangle-list"
443
+ }), r.type === $.WEBGL && r.renderTarget.finishRenderPass();
444
+ }
445
+ /**
446
+ * Sets up the filter textures including input texture and back texture if needed.
447
+ * @param filterData - The filter data to update
448
+ * @param bounds - The bounds for the texture
449
+ * @param renderer - The renderer instance
450
+ * @param previousFilterData - The previous filter data for back texture calculation
451
+ */
452
+ _setupFilterTextures(e, t, r, n) {
453
+ if (e.backTexture = w.EMPTY, e.inputTexture = v.getOptimalTexture(
454
+ t.width,
455
+ t.height,
456
+ e.resolution,
457
+ e.antialias
458
+ ), e.blendRequired) {
459
+ r.renderTarget.finishRenderPass();
460
+ const s = r.renderTarget.getRenderTarget(e.outputRenderSurface);
461
+ e.backTexture = this.getBackTexture(s, t, n?.bounds);
462
+ }
463
+ r.renderTarget.bind(e.inputTexture, !0), r.globalUniforms.push({
464
+ offset: t
465
+ });
466
+ }
467
+ /**
468
+ * Calculates and sets the global frame for the filter.
469
+ * @param filterData - The filter data to update
470
+ * @param offsetX - The X offset
471
+ * @param offsetY - The Y offset
472
+ * @param globalResolution - The global resolution
473
+ * @param sourceWidth - The source texture width
474
+ * @param sourceHeight - The source texture height
475
+ */
476
+ _calculateGlobalFrame(e, t, r, n, s, i) {
477
+ const o = e.globalFrame;
478
+ o.x = t * n, o.y = r * n, o.width = s * n, o.height = i * n;
479
+ }
480
+ /**
481
+ * Updates the filter uniforms with the current filter state.
482
+ * @param input - The input texture
483
+ * @param output - The output render surface
484
+ * @param filterData - The current filter data
485
+ * @param offsetX - The X offset for positioning
486
+ * @param offsetY - The Y offset for positioning
487
+ * @param resolution - The current resolution
488
+ * @param isFinalTarget - Whether this is the final render target
489
+ * @param clear - Whether to clear the output surface
490
+ */
491
+ _updateFilterUniforms(e, t, r, n, s, i, o, u) {
492
+ const c = this._filterGlobalUniforms.uniforms, h = c.uOutputFrame, l = c.uInputSize, d = c.uInputPixel, f = c.uInputClamp, g = c.uGlobalFrame, m = c.uOutputTexture;
493
+ o ? (h[0] = r.bounds.minX - n, h[1] = r.bounds.minY - s) : (h[0] = 0, h[1] = 0), h[2] = e.frame.width, h[3] = e.frame.height, l[0] = e.source.width, l[1] = e.source.height, l[2] = 1 / l[0], l[3] = 1 / l[1], d[0] = e.source.pixelWidth, d[1] = e.source.pixelHeight, d[2] = 1 / d[0], d[3] = 1 / d[1], f[0] = 0.5 * d[2], f[1] = 0.5 * d[3], f[2] = e.frame.width * l[2] - 0.5 * d[2], f[3] = e.frame.height * l[3] - 0.5 * d[3];
494
+ const x = this.renderer.renderTarget.rootRenderTarget.colorTexture;
495
+ g[0] = n * i, g[1] = s * i, g[2] = x.source.width * i, g[3] = x.source.height * i, t instanceof w && (t.source.resource = null);
496
+ const _ = this.renderer.renderTarget.getRenderTarget(t);
497
+ this.renderer.renderTarget.bind(t, !!u), t instanceof w ? (m[0] = t.frame.width, m[1] = t.frame.height) : (m[0] = _.width, m[1] = _.height), m[2] = _.isRoot ? -1 : 1, this._filterGlobalUniforms.update();
498
+ }
499
+ /**
500
+ * Finds the correct resolution by looking back through the filter stack.
501
+ * @param rootResolution - The fallback root resolution to use
502
+ * @returns The resolution from the previous filter or root resolution
503
+ */
504
+ _findFilterResolution(e) {
505
+ let t = this._filterStackIndex - 1;
506
+ for (; t > 0 && this._filterStack[t].skip; )
507
+ --t;
508
+ return t > 0 && this._filterStack[t].inputTexture ? this._filterStack[t].inputTexture.source._resolution : e;
509
+ }
510
+ /**
511
+ * Finds the offset from the previous non-skipped filter in the stack.
512
+ * @returns The offset coordinates from the previous filter
513
+ */
514
+ _findPreviousFilterOffset() {
515
+ let e = 0, t = 0, r = this._filterStackIndex;
516
+ for (; r > 0; ) {
517
+ r--;
518
+ const n = this._filterStack[r];
519
+ if (!n.skip) {
520
+ e = n.bounds.minX, t = n.bounds.minY;
521
+ break;
522
+ }
523
+ }
524
+ return { x: e, y: t };
525
+ }
526
+ /**
527
+ * Calculates the filter area bounds based on the instruction type.
528
+ * @param instruction - The filter instruction
529
+ * @param bounds - The bounds object to populate
530
+ */
531
+ _calculateFilterArea(e, t) {
532
+ if (e.renderables ? pt(e.renderables, t) : e.filterEffect.filterArea ? (t.clear(), t.addRect(e.filterEffect.filterArea), t.applyMatrix(e.container.worldTransform)) : e.container.getFastGlobalBounds(!0, t), e.container) {
533
+ const n = (e.container.renderGroup || e.container.parentRenderGroup).cacheToLocalTransform;
534
+ n && t.applyMatrix(n);
535
+ }
536
+ }
537
+ _applyFiltersToTexture(e, t) {
538
+ const r = e.inputTexture, n = e.bounds, s = e.filters, i = e.firstEnabledIndex, o = e.lastEnabledIndex;
539
+ if (this._globalFilterBindGroup.setResource(r.source.style, 2), this._globalFilterBindGroup.setResource(e.backTexture.source, 3), i === o)
540
+ s[i].apply(this, r, e.outputRenderSurface, t);
541
+ else {
542
+ let u = e.inputTexture;
543
+ const c = v.getOptimalTexture(
544
+ n.width,
545
+ n.height,
546
+ u.source._resolution,
547
+ !1
548
+ );
549
+ let h = c;
550
+ for (let l = i; l < o; l++) {
551
+ const d = s[l];
552
+ if (!d.enabled)
553
+ continue;
554
+ d.apply(this, u, h, !0);
555
+ const f = u;
556
+ u = h, h = f;
557
+ }
558
+ s[o].apply(this, u, e.outputRenderSurface, t), v.returnTexture(c);
559
+ }
560
+ }
561
+ _calculateFilterBounds(e, t, r, n, s) {
562
+ const i = this.renderer, o = e.bounds, u = e.filters;
563
+ let c = 1 / 0, h = 0, l = !0, d = !1, f = !1, g = !0, m = -1, x = -1;
564
+ for (let _ = 0; _ < u.length; _++) {
565
+ const y = u[_];
566
+ if (!y.enabled)
567
+ continue;
568
+ if (m === -1 && (m = _), x = _, c = Math.min(c, y.resolution === "inherit" ? n : y.resolution), h += y.padding, y.antialias === "off" ? l = !1 : y.antialias === "inherit" && l && (l = r), y.clipToViewport || (g = !1), !!!(y.compatibleRenderers & i.type)) {
569
+ f = !1;
570
+ break;
571
+ }
572
+ if (y.blendRequired && !(i.backBuffer?.useBackBuffer ?? !0)) {
573
+ Y("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."), f = !1;
574
+ break;
575
+ }
576
+ f = !0, d || (d = y.blendRequired);
577
+ }
578
+ if (!f) {
579
+ e.skip = !0;
580
+ return;
581
+ }
582
+ if (g && o.fitBounds(0, t.width / n, 0, t.height / n), o.scale(c).ceil().scale(1 / c).pad((h | 0) * s), !o.isPositive) {
583
+ e.skip = !0;
584
+ return;
585
+ }
586
+ e.antialias = l, e.resolution = c, e.blendRequired = d, e.firstEnabledIndex = m, e.lastEnabledIndex = x;
587
+ }
588
+ _popFilterData() {
589
+ return this._filterStackIndex--, this._filterStack[this._filterStackIndex];
590
+ }
591
+ _getPreviousFilterData() {
592
+ let e, t = this._filterStackIndex - 1;
593
+ for (; t > 0 && (t--, e = this._filterStack[t], !!e.skip); )
594
+ ;
595
+ return e;
596
+ }
597
+ _pushFilterData() {
598
+ let e = this._filterStack[this._filterStackIndex];
599
+ return e || (e = this._filterStack[this._filterStackIndex] = new gt()), this._filterStackIndex++, e;
600
+ }
601
+ }
602
+ Se.extension = {
603
+ type: [
604
+ p.WebGLSystem,
605
+ p.WebGPUSystem
606
+ ],
607
+ name: "filter"
608
+ };
609
+ const Fe = class Re extends N {
610
+ constructor(...e) {
611
+ let t = e[0] ?? {};
612
+ t instanceof Float32Array && (G(ge, "use new MeshGeometry({ positions, uvs, indices }) instead"), t = {
613
+ positions: t,
614
+ uvs: e[1],
615
+ indices: e[2]
616
+ }), t = { ...Re.defaultOptions, ...t };
617
+ const r = t.positions || new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
618
+ let n = t.uvs;
619
+ n || (t.positions ? n = new Float32Array(r.length) : n = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]));
620
+ const s = t.indices || new Uint32Array([0, 1, 2, 0, 2, 3]), i = t.shrinkBuffersToFit, o = new F({
621
+ data: r,
622
+ label: "attribute-mesh-positions",
623
+ shrinkToFit: i,
624
+ usage: T.VERTEX | T.COPY_DST
625
+ }), u = new F({
626
+ data: n,
627
+ label: "attribute-mesh-uvs",
628
+ shrinkToFit: i,
629
+ usage: T.VERTEX | T.COPY_DST
630
+ }), c = new F({
631
+ data: s,
632
+ label: "index-mesh-buffer",
633
+ shrinkToFit: i,
634
+ usage: T.INDEX | T.COPY_DST
635
+ });
636
+ super({
637
+ attributes: {
638
+ aPosition: {
639
+ buffer: o,
640
+ format: "float32x2",
641
+ stride: 8,
642
+ offset: 0
643
+ },
644
+ aUV: {
645
+ buffer: u,
646
+ format: "float32x2",
647
+ stride: 8,
648
+ offset: 0
649
+ }
650
+ },
651
+ indexBuffer: c,
652
+ topology: t.topology
653
+ }), this.batchMode = "auto";
654
+ }
655
+ /** The positions of the mesh. */
656
+ get positions() {
657
+ return this.attributes.aPosition.buffer.data;
658
+ }
659
+ /**
660
+ * Set the positions of the mesh.
661
+ * When setting the positions, its important that the uvs array is at least as long as the positions array.
662
+ * otherwise the geometry will not be valid.
663
+ * @param {Float32Array} value - The positions of the mesh.
664
+ */
665
+ set positions(e) {
666
+ this.attributes.aPosition.buffer.data = e;
667
+ }
668
+ /** The UVs of the mesh. */
669
+ get uvs() {
670
+ return this.attributes.aUV.buffer.data;
671
+ }
672
+ /**
673
+ * Set the UVs of the mesh.
674
+ * Its important that the uvs array you set is at least as long as the positions array.
675
+ * otherwise the geometry will not be valid.
676
+ * @param {Float32Array} value - The UVs of the mesh.
677
+ */
678
+ set uvs(e) {
679
+ this.attributes.aUV.buffer.data = e;
680
+ }
681
+ /** The indices of the mesh. */
682
+ get indices() {
683
+ return this.indexBuffer.data;
684
+ }
685
+ set indices(e) {
686
+ this.indexBuffer.data = e;
687
+ }
688
+ };
689
+ Fe.defaultOptions = {
690
+ topology: "triangle-list",
691
+ shrinkBuffersToFit: !1
692
+ };
693
+ let J = Fe;
694
+ const se = "http://www.w3.org/2000/svg", ie = "http://www.w3.org/1999/xhtml";
695
+ class Ue {
696
+ constructor() {
697
+ this.svgRoot = document.createElementNS(se, "svg"), this.foreignObject = document.createElementNS(se, "foreignObject"), this.domElement = document.createElementNS(ie, "div"), this.styleElement = document.createElementNS(ie, "style");
698
+ const { foreignObject: e, svgRoot: t, styleElement: r, domElement: n } = this;
699
+ e.setAttribute("width", "10000"), e.setAttribute("height", "10000"), e.style.overflow = "hidden", t.appendChild(e), e.appendChild(r), e.appendChild(n), this.image = j.get().createImage();
700
+ }
701
+ destroy() {
702
+ this.svgRoot.remove(), this.foreignObject.remove(), this.styleElement.remove(), this.domElement.remove(), this.image.src = "", this.image.remove(), this.svgRoot = null, this.foreignObject = null, this.styleElement = null, this.domElement = null, this.image = null, this.canvasAndContext = null;
703
+ }
704
+ }
705
+ let ae;
706
+ function xt(a, e, t, r) {
707
+ r || (r = ae || (ae = new Ue()));
708
+ const { domElement: n, styleElement: s, svgRoot: i } = r;
709
+ n.innerHTML = `<style>${e.cssStyle};</style><div style='padding:0'>${a}</div>`, n.setAttribute("style", "transform-origin: top left; display: inline-block"), t && (s.textContent = t), document.body.appendChild(i);
710
+ const o = n.getBoundingClientRect();
711
+ i.remove();
712
+ const u = e.padding * 2;
713
+ return {
714
+ width: o.width - u,
715
+ height: o.height - u
716
+ };
717
+ }
718
+ class _t {
719
+ constructor() {
720
+ this.batches = [], this.batched = !1;
721
+ }
722
+ destroy() {
723
+ this.batches.forEach((e) => {
724
+ M.return(e);
725
+ }), this.batches.length = 0;
726
+ }
727
+ }
728
+ class Be {
729
+ constructor(e, t) {
730
+ this.state = D.for2d(), this.renderer = e, this._adaptor = t, this.renderer.runners.contextChange.add(this);
731
+ }
732
+ contextChange() {
733
+ this._adaptor.contextChange(this.renderer);
734
+ }
735
+ validateRenderable(e) {
736
+ const t = e.context, r = !!e._gpuData, n = this.renderer.graphicsContext.updateGpuContext(t);
737
+ return !!(n.isBatchable || r !== n.isBatchable);
738
+ }
739
+ addRenderable(e, t) {
740
+ const r = this.renderer.graphicsContext.updateGpuContext(e.context);
741
+ e.didViewUpdate && this._rebuild(e), r.isBatchable ? this._addToBatcher(e, t) : (this.renderer.renderPipes.batch.break(t), t.add(e));
742
+ }
743
+ updateRenderable(e) {
744
+ const r = this._getGpuDataForRenderable(e).batches;
745
+ for (let n = 0; n < r.length; n++) {
746
+ const s = r[n];
747
+ s._batcher.updateElement(s);
748
+ }
749
+ }
750
+ execute(e) {
751
+ if (!e.isRenderable)
752
+ return;
753
+ const t = this.renderer, r = e.context;
754
+ if (!t.graphicsContext.getGpuContext(r).batches.length)
755
+ return;
756
+ const s = r.customShader || this._adaptor.shader;
757
+ this.state.blendMode = e.groupBlendMode;
758
+ const i = s.resources.localUniforms.uniforms;
759
+ i.uTransformMatrix = e.groupTransform, i.uRound = t._roundPixels | e._roundPixels, z(
760
+ e.groupColorAlpha,
761
+ i.uColor,
762
+ 0
763
+ ), this._adaptor.execute(this, e);
764
+ }
765
+ _rebuild(e) {
766
+ const t = this._getGpuDataForRenderable(e), r = this.renderer.graphicsContext.updateGpuContext(e.context);
767
+ t.destroy(), r.isBatchable && this._updateBatchesForRenderable(e, t);
768
+ }
769
+ _addToBatcher(e, t) {
770
+ const r = this.renderer.renderPipes.batch, n = this._getGpuDataForRenderable(e).batches;
771
+ for (let s = 0; s < n.length; s++) {
772
+ const i = n[s];
773
+ r.addToBatch(i, t);
774
+ }
775
+ }
776
+ _getGpuDataForRenderable(e) {
777
+ return e._gpuData[this.renderer.uid] || this._initGpuDataForRenderable(e);
778
+ }
779
+ _initGpuDataForRenderable(e) {
780
+ const t = new _t();
781
+ return e._gpuData[this.renderer.uid] = t, t;
782
+ }
783
+ _updateBatchesForRenderable(e, t) {
784
+ const r = e.context, n = this.renderer.graphicsContext.getGpuContext(r), s = this.renderer._roundPixels | e._roundPixels;
785
+ t.batches = n.batches.map((i) => {
786
+ const o = M.get(je);
787
+ return i.copyTo(o), o.renderable = e, o.roundPixels = s, o;
788
+ });
789
+ }
790
+ destroy() {
791
+ this.renderer = null, this._adaptor.destroy(), this._adaptor = null, this.state = null;
792
+ }
793
+ }
794
+ Be.extension = {
795
+ type: [
796
+ p.WebGLPipes,
797
+ p.WebGPUPipes,
798
+ p.CanvasPipes
799
+ ],
800
+ name: "graphics"
801
+ };
802
+ const Ge = class Me extends J {
803
+ constructor(...e) {
804
+ super({});
805
+ let t = e[0] ?? {};
806
+ typeof t == "number" && (G(ge, "PlaneGeometry constructor changed please use { width, height, verticesX, verticesY } instead"), t = {
807
+ width: t,
808
+ height: e[1],
809
+ verticesX: e[2],
810
+ verticesY: e[3]
811
+ }), this.build(t);
812
+ }
813
+ /**
814
+ * Refreshes plane coordinates
815
+ * @param options - Options to be applied to plane geometry
816
+ */
817
+ build(e) {
818
+ e = { ...Me.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;
819
+ const t = this.verticesX * this.verticesY, r = [], n = [], s = [], i = this.verticesX - 1, o = this.verticesY - 1, u = this.width / i, c = this.height / o;
820
+ for (let l = 0; l < t; l++) {
821
+ const d = l % this.verticesX, f = l / this.verticesX | 0;
822
+ r.push(d * u, f * c), n.push(d / i, f / o);
823
+ }
824
+ const h = i * o;
825
+ for (let l = 0; l < h; l++) {
826
+ const d = l % i, f = l / i | 0, g = f * this.verticesX + d, m = f * this.verticesX + d + 1, x = (f + 1) * this.verticesX + d, _ = (f + 1) * this.verticesX + d + 1;
827
+ s.push(
828
+ g,
829
+ m,
830
+ x,
831
+ m,
832
+ _,
833
+ x
834
+ );
835
+ }
836
+ this.buffers[0].data = new Float32Array(r), this.buffers[1].data = new Float32Array(n), this.indexBuffer.data = new Uint32Array(s), this.buffers[0].update(), this.buffers[1].update(), this.indexBuffer.update();
837
+ }
838
+ };
839
+ Ge.defaultOptions = {
840
+ width: 100,
841
+ height: 100,
842
+ verticesX: 10,
843
+ verticesY: 10
844
+ };
845
+ let bt = Ge;
846
+ class Z {
847
+ constructor() {
848
+ this.batcherName = "default", this.packAsQuad = !1, this.indexOffset = 0, this.attributeOffset = 0, this.roundPixels = 0, this._batcher = null, this._batch = null, this._textureMatrixUpdateId = -1, this._uvUpdateId = -1;
849
+ }
850
+ get blendMode() {
851
+ return this.renderable.groupBlendMode;
852
+ }
853
+ get topology() {
854
+ return this._topology || this.geometry.topology;
855
+ }
856
+ set topology(e) {
857
+ this._topology = e;
858
+ }
859
+ reset() {
860
+ this.renderable = null, this.texture = null, this._batcher = null, this._batch = null, this.geometry = null, this._uvUpdateId = -1, this._textureMatrixUpdateId = -1;
861
+ }
862
+ /**
863
+ * Sets the texture for the batchable mesh.
864
+ * As it does so, it resets the texture matrix update ID.
865
+ * this is to ensure that the texture matrix is recalculated when the uvs are referenced
866
+ * @param value - The texture to set.
867
+ */
868
+ setTexture(e) {
869
+ this.texture !== e && (this.texture = e, this._textureMatrixUpdateId = -1);
870
+ }
871
+ get uvs() {
872
+ const t = this.geometry.getBuffer("aUV"), r = t.data;
873
+ let n = r;
874
+ const s = this.texture.textureMatrix;
875
+ return s.isSimple || (n = this._transformedUvs, (this._textureMatrixUpdateId !== s._updateID || this._uvUpdateId !== t._updateID) && ((!n || n.length < r.length) && (n = this._transformedUvs = new Float32Array(r.length)), this._textureMatrixUpdateId = s._updateID, this._uvUpdateId = t._updateID, s.multiplyUvs(r, n))), n;
876
+ }
877
+ get positions() {
878
+ return this.geometry.positions;
879
+ }
880
+ get indices() {
881
+ return this.geometry.indices;
882
+ }
883
+ get color() {
884
+ return this.renderable.groupColorAlpha;
885
+ }
886
+ get groupTransform() {
887
+ return this.renderable.groupTransform;
888
+ }
889
+ get attributeSize() {
890
+ return this.geometry.positions.length / 2;
891
+ }
892
+ get indexSize() {
893
+ return this.geometry.indices.length;
894
+ }
895
+ }
896
+ class oe {
897
+ destroy() {
898
+ }
899
+ }
900
+ class De {
901
+ constructor(e, t) {
902
+ this.localUniforms = new C({
903
+ uTransformMatrix: { value: new P(), type: "mat3x3<f32>" },
904
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
905
+ uRound: { value: 0, type: "f32" }
906
+ }), this.localUniformsBindGroup = new pe({
907
+ 0: this.localUniforms
908
+ }), this.renderer = e, this._adaptor = t, this._adaptor.init();
909
+ }
910
+ validateRenderable(e) {
911
+ const t = this._getMeshData(e), r = t.batched, n = e.batched;
912
+ if (t.batched = n, r !== n)
913
+ return !0;
914
+ if (n) {
915
+ const s = e._geometry;
916
+ if (s.indices.length !== t.indexSize || s.positions.length !== t.vertexSize)
917
+ return t.indexSize = s.indices.length, t.vertexSize = s.positions.length, !0;
918
+ const i = this._getBatchableMesh(e);
919
+ return i.texture.uid !== e._texture.uid && (i._textureMatrixUpdateId = -1), !i._batcher.checkAndUpdateTexture(
920
+ i,
921
+ e._texture
922
+ );
923
+ }
924
+ return !1;
925
+ }
926
+ addRenderable(e, t) {
927
+ const r = this.renderer.renderPipes.batch, n = this._getMeshData(e);
928
+ if (e.didViewUpdate && (n.indexSize = e._geometry.indices?.length, n.vertexSize = e._geometry.positions?.length), n.batched) {
929
+ const s = this._getBatchableMesh(e);
930
+ s.setTexture(e._texture), s.geometry = e._geometry, r.addToBatch(s, t);
931
+ } else
932
+ r.break(t), t.add(e);
933
+ }
934
+ updateRenderable(e) {
935
+ if (e.batched) {
936
+ const t = this._getBatchableMesh(e);
937
+ t.setTexture(e._texture), t.geometry = e._geometry, t._batcher.updateElement(t);
938
+ }
939
+ }
940
+ execute(e) {
941
+ if (!e.isRenderable)
942
+ return;
943
+ e.state.blendMode = q(e.groupBlendMode, e.texture._source);
944
+ const t = this.localUniforms;
945
+ t.uniforms.uTransformMatrix = e.groupTransform, t.uniforms.uRound = this.renderer._roundPixels | e._roundPixels, t.update(), z(
946
+ e.groupColorAlpha,
947
+ t.uniforms.uColor,
948
+ 0
949
+ ), this._adaptor.execute(this, e);
950
+ }
951
+ _getMeshData(e) {
952
+ var t, r;
953
+ return (t = e._gpuData)[r = this.renderer.uid] || (t[r] = new oe()), e._gpuData[this.renderer.uid].meshData || this._initMeshData(e);
954
+ }
955
+ _initMeshData(e) {
956
+ return e._gpuData[this.renderer.uid].meshData = {
957
+ batched: e.batched,
958
+ indexSize: 0,
959
+ vertexSize: 0
960
+ }, e._gpuData[this.renderer.uid].meshData;
961
+ }
962
+ _getBatchableMesh(e) {
963
+ var t, r;
964
+ return (t = e._gpuData)[r = this.renderer.uid] || (t[r] = new oe()), e._gpuData[this.renderer.uid].batchableMesh || this._initBatchableMesh(e);
965
+ }
966
+ _initBatchableMesh(e) {
967
+ const t = new Z();
968
+ return t.renderable = e, t.setTexture(e._texture), t.transform = e.groupTransform, t.roundPixels = this.renderer._roundPixels | e._roundPixels, e._gpuData[this.renderer.uid].batchableMesh = t, t;
969
+ }
970
+ destroy() {
971
+ this.localUniforms = null, this.localUniformsBindGroup = null, this._adaptor.destroy(), this._adaptor = null, this.renderer = null;
972
+ }
973
+ }
974
+ De.extension = {
975
+ type: [
976
+ p.WebGLPipes,
977
+ p.WebGPUPipes,
978
+ p.CanvasPipes
979
+ ],
980
+ name: "mesh"
981
+ };
982
+ class yt {
983
+ execute(e, t) {
984
+ const r = e.state, n = e.renderer, s = t.shader || e.defaultShader;
985
+ s.resources.uTexture = t.texture._source, s.resources.uniforms = e.localUniforms;
986
+ const i = n.gl, o = e.getBuffers(t);
987
+ n.shader.bind(s), n.state.set(r), n.geometry.bind(o.geometry, s.glProgram);
988
+ const c = o.geometry.indexBuffer.data.BYTES_PER_ELEMENT === 2 ? i.UNSIGNED_SHORT : i.UNSIGNED_INT;
989
+ i.drawElements(i.TRIANGLES, t.particleChildren.length * 6, c, 0);
990
+ }
991
+ }
992
+ class vt {
993
+ execute(e, t) {
994
+ const r = e.renderer, n = t.shader || e.defaultShader;
995
+ n.groups[0] = r.renderPipes.uniformBatch.getUniformBindGroup(e.localUniforms, !0), n.groups[1] = r.texture.getTextureBindGroup(t.texture);
996
+ const s = e.state, i = e.getBuffers(t);
997
+ r.encoder.draw({
998
+ geometry: i.geometry,
999
+ shader: t.shader || e.defaultShader,
1000
+ state: s,
1001
+ size: t.particleChildren.length * 6
1002
+ });
1003
+ }
1004
+ }
1005
+ function ue(a, e = null) {
1006
+ const t = a * 6;
1007
+ if (t > 65535 ? e || (e = new Uint32Array(t)) : e || (e = new Uint16Array(t)), e.length !== t)
1008
+ throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${t}`);
1009
+ for (let r = 0, n = 0; r < t; r += 6, n += 4)
1010
+ e[r + 0] = n + 0, e[r + 1] = n + 1, e[r + 2] = n + 2, e[r + 3] = n + 0, e[r + 4] = n + 2, e[r + 5] = n + 3;
1011
+ return e;
1012
+ }
1013
+ function Tt(a) {
1014
+ return {
1015
+ dynamicUpdate: le(a, !0),
1016
+ staticUpdate: le(a, !1)
1017
+ };
1018
+ }
1019
+ function le(a, e) {
1020
+ const t = [];
1021
+ t.push(`
1022
+
1023
+ var index = 0;
1024
+
1025
+ for (let i = 0; i < ps.length; ++i)
1026
+ {
1027
+ const p = ps[i];
1028
+
1029
+ `);
1030
+ let r = 0;
1031
+ for (const s in a) {
1032
+ const i = a[s];
1033
+ if (e !== i.dynamic)
1034
+ continue;
1035
+ t.push(`offset = index + ${r}`), t.push(i.code);
1036
+ const o = L(i.format);
1037
+ r += o.stride / 4;
1038
+ }
1039
+ t.push(`
1040
+ index += stride * 4;
1041
+ }
1042
+ `), t.unshift(`
1043
+ var stride = ${r};
1044
+ `);
1045
+ const n = t.join(`
1046
+ `);
1047
+ return new Function("ps", "f32v", "u32v", n);
1048
+ }
1049
+ class Pt {
1050
+ constructor(e) {
1051
+ this._size = 0, this._generateParticleUpdateCache = {};
1052
+ const t = this._size = e.size ?? 1e3, r = e.properties;
1053
+ let n = 0, s = 0;
1054
+ for (const h in r) {
1055
+ const l = r[h], d = L(l.format);
1056
+ l.dynamic ? s += d.stride : n += d.stride;
1057
+ }
1058
+ this._dynamicStride = s / 4, this._staticStride = n / 4, this.staticAttributeBuffer = new U(t * 4 * n), this.dynamicAttributeBuffer = new U(t * 4 * s), this.indexBuffer = ue(t);
1059
+ const i = new N();
1060
+ let o = 0, u = 0;
1061
+ this._staticBuffer = new F({
1062
+ data: new Float32Array(1),
1063
+ label: "static-particle-buffer",
1064
+ shrinkToFit: !1,
1065
+ usage: T.VERTEX | T.COPY_DST
1066
+ }), this._dynamicBuffer = new F({
1067
+ data: new Float32Array(1),
1068
+ label: "dynamic-particle-buffer",
1069
+ shrinkToFit: !1,
1070
+ usage: T.VERTEX | T.COPY_DST
1071
+ });
1072
+ for (const h in r) {
1073
+ const l = r[h], d = L(l.format);
1074
+ l.dynamic ? (i.addAttribute(l.attributeName, {
1075
+ buffer: this._dynamicBuffer,
1076
+ stride: this._dynamicStride * 4,
1077
+ offset: o * 4,
1078
+ format: l.format
1079
+ }), o += d.size) : (i.addAttribute(l.attributeName, {
1080
+ buffer: this._staticBuffer,
1081
+ stride: this._staticStride * 4,
1082
+ offset: u * 4,
1083
+ format: l.format
1084
+ }), u += d.size);
1085
+ }
1086
+ i.addIndex(this.indexBuffer);
1087
+ const c = this.getParticleUpdate(r);
1088
+ this._dynamicUpload = c.dynamicUpdate, this._staticUpload = c.staticUpdate, this.geometry = i;
1089
+ }
1090
+ getParticleUpdate(e) {
1091
+ const t = wt(e);
1092
+ return this._generateParticleUpdateCache[t] ? this._generateParticleUpdateCache[t] : (this._generateParticleUpdateCache[t] = this.generateParticleUpdate(e), this._generateParticleUpdateCache[t]);
1093
+ }
1094
+ generateParticleUpdate(e) {
1095
+ return Tt(e);
1096
+ }
1097
+ update(e, t) {
1098
+ e.length > this._size && (t = !0, this._size = Math.max(e.length, this._size * 1.5 | 0), this.staticAttributeBuffer = new U(this._size * this._staticStride * 4 * 4), this.dynamicAttributeBuffer = new U(this._size * this._dynamicStride * 4 * 4), this.indexBuffer = ue(this._size), this.geometry.indexBuffer.setDataWithSize(
1099
+ this.indexBuffer,
1100
+ this.indexBuffer.byteLength,
1101
+ !0
1102
+ ));
1103
+ const r = this.dynamicAttributeBuffer;
1104
+ if (this._dynamicUpload(e, r.float32View, r.uint32View), this._dynamicBuffer.setDataWithSize(
1105
+ this.dynamicAttributeBuffer.float32View,
1106
+ e.length * this._dynamicStride * 4,
1107
+ !0
1108
+ ), t) {
1109
+ const n = this.staticAttributeBuffer;
1110
+ this._staticUpload(e, n.float32View, n.uint32View), this._staticBuffer.setDataWithSize(
1111
+ n.float32View,
1112
+ e.length * this._staticStride * 4,
1113
+ !0
1114
+ );
1115
+ }
1116
+ }
1117
+ destroy() {
1118
+ this._staticBuffer.destroy(), this._dynamicBuffer.destroy(), this.geometry.destroy();
1119
+ }
1120
+ }
1121
+ function wt(a) {
1122
+ const e = [];
1123
+ for (const t in a) {
1124
+ const r = a[t];
1125
+ e.push(t, r.code, r.dynamic ? "d" : "s");
1126
+ }
1127
+ return e.join("_");
1128
+ }
1129
+ var Ct = `varying vec2 vUV;
1130
+ varying vec4 vColor;
1131
+
1132
+ uniform sampler2D uTexture;
1133
+
1134
+ void main(void){
1135
+ vec4 color = texture2D(uTexture, vUV) * vColor;
1136
+ gl_FragColor = color;
1137
+ }`, St = `attribute vec2 aVertex;
1138
+ attribute vec2 aUV;
1139
+ attribute vec4 aColor;
1140
+
1141
+ attribute vec2 aPosition;
1142
+ attribute float aRotation;
1143
+
1144
+ uniform mat3 uTranslationMatrix;
1145
+ uniform float uRound;
1146
+ uniform vec2 uResolution;
1147
+ uniform vec4 uColor;
1148
+
1149
+ varying vec2 vUV;
1150
+ varying vec4 vColor;
1151
+
1152
+ vec2 roundPixels(vec2 position, vec2 targetSize)
1153
+ {
1154
+ return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
1155
+ }
1156
+
1157
+ void main(void){
1158
+ float cosRotation = cos(aRotation);
1159
+ float sinRotation = sin(aRotation);
1160
+ float x = aVertex.x * cosRotation - aVertex.y * sinRotation;
1161
+ float y = aVertex.x * sinRotation + aVertex.y * cosRotation;
1162
+
1163
+ vec2 v = vec2(x, y);
1164
+ v = v + aPosition;
1165
+
1166
+ gl_Position = vec4((uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
1167
+
1168
+ if(uRound == 1.0)
1169
+ {
1170
+ gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
1171
+ }
1172
+
1173
+ vUV = aUV;
1174
+ vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uColor;
1175
+ }
1176
+ `, ce = `
1177
+ struct ParticleUniforms {
1178
+ uTranslationMatrix:mat3x3<f32>,
1179
+ uColor:vec4<f32>,
1180
+ uRound:f32,
1181
+ uResolution:vec2<f32>,
1182
+ };
1183
+
1184
+ fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
1185
+ {
1186
+ return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
1187
+ }
1188
+
1189
+ @group(0) @binding(0) var<uniform> uniforms: ParticleUniforms;
1190
+
1191
+ @group(1) @binding(0) var uTexture: texture_2d<f32>;
1192
+ @group(1) @binding(1) var uSampler : sampler;
1193
+
1194
+ struct VSOutput {
1195
+ @builtin(position) position: vec4<f32>,
1196
+ @location(0) uv : vec2<f32>,
1197
+ @location(1) color : vec4<f32>,
1198
+ };
1199
+ @vertex
1200
+ fn mainVertex(
1201
+ @location(0) aVertex: vec2<f32>,
1202
+ @location(1) aPosition: vec2<f32>,
1203
+ @location(2) aUV: vec2<f32>,
1204
+ @location(3) aColor: vec4<f32>,
1205
+ @location(4) aRotation: f32,
1206
+ ) -> VSOutput {
1207
+
1208
+ let v = vec2(
1209
+ aVertex.x * cos(aRotation) - aVertex.y * sin(aRotation),
1210
+ aVertex.x * sin(aRotation) + aVertex.y * cos(aRotation)
1211
+ ) + aPosition;
1212
+
1213
+ var position = vec4((uniforms.uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
1214
+
1215
+ if(uniforms.uRound == 1.0) {
1216
+ position = vec4(roundPixels(position.xy, uniforms.uResolution), position.zw);
1217
+ }
1218
+
1219
+ let vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uniforms.uColor;
1220
+
1221
+ return VSOutput(
1222
+ position,
1223
+ aUV,
1224
+ vColor,
1225
+ );
1226
+ }
1227
+
1228
+ @fragment
1229
+ fn mainFragment(
1230
+ @location(0) uv: vec2<f32>,
1231
+ @location(1) color: vec4<f32>,
1232
+ @builtin(position) position: vec4<f32>,
1233
+ ) -> @location(0) vec4<f32> {
1234
+
1235
+ var sample = textureSample(uTexture, uSampler, uv) * color;
1236
+
1237
+ return sample;
1238
+ }`;
1239
+ class Ft extends Q {
1240
+ constructor() {
1241
+ const e = fe.from({
1242
+ vertex: St,
1243
+ fragment: Ct
1244
+ }), t = he.from({
1245
+ fragment: {
1246
+ source: ce,
1247
+ entryPoint: "mainFragment"
1248
+ },
1249
+ vertex: {
1250
+ source: ce,
1251
+ entryPoint: "mainVertex"
1252
+ }
1253
+ });
1254
+ super({
1255
+ glProgram: e,
1256
+ gpuProgram: t,
1257
+ resources: {
1258
+ // this will be replaced with the texture from the particle container
1259
+ uTexture: w.WHITE.source,
1260
+ // this will be replaced with the texture style from the particle container
1261
+ uSampler: new X({}),
1262
+ // this will be replaced with the local uniforms from the particle container
1263
+ uniforms: {
1264
+ uTranslationMatrix: { value: new P(), type: "mat3x3<f32>" },
1265
+ uColor: { value: new qe(16777215), type: "vec4<f32>" },
1266
+ uRound: { value: 1, type: "f32" },
1267
+ uResolution: { value: [0, 0], type: "vec2<f32>" }
1268
+ }
1269
+ }
1270
+ });
1271
+ }
1272
+ }
1273
+ class ze {
1274
+ /**
1275
+ * @param renderer - The renderer this sprite batch works for.
1276
+ * @param adaptor
1277
+ */
1278
+ constructor(e, t) {
1279
+ this.state = D.for2d(), this.localUniforms = new C({
1280
+ uTranslationMatrix: { value: new P(), type: "mat3x3<f32>" },
1281
+ uColor: { value: new Float32Array(4), type: "vec4<f32>" },
1282
+ uRound: { value: 1, type: "f32" },
1283
+ uResolution: { value: [0, 0], type: "vec2<f32>" }
1284
+ }), this.renderer = e, this.adaptor = t, this.defaultShader = new Ft(), this.state = D.for2d();
1285
+ }
1286
+ validateRenderable(e) {
1287
+ return !1;
1288
+ }
1289
+ addRenderable(e, t) {
1290
+ this.renderer.renderPipes.batch.break(t), t.add(e);
1291
+ }
1292
+ getBuffers(e) {
1293
+ return e._gpuData[this.renderer.uid] || this._initBuffer(e);
1294
+ }
1295
+ _initBuffer(e) {
1296
+ return e._gpuData[this.renderer.uid] = new Pt({
1297
+ size: e.particleChildren.length,
1298
+ properties: e._properties
1299
+ }), e._gpuData[this.renderer.uid];
1300
+ }
1301
+ updateRenderable(e) {
1302
+ }
1303
+ execute(e) {
1304
+ const t = e.particleChildren;
1305
+ if (t.length === 0)
1306
+ return;
1307
+ const r = this.renderer, n = this.getBuffers(e);
1308
+ e.texture || (e.texture = t[0].texture);
1309
+ const s = this.state;
1310
+ n.update(t, e._childrenDirty), e._childrenDirty = !1, s.blendMode = q(e.blendMode, e.texture._source);
1311
+ const i = this.localUniforms.uniforms, o = i.uTranslationMatrix;
1312
+ e.worldTransform.copyTo(o), o.prepend(r.globalUniforms.globalUniformData.projectionMatrix), i.uResolution = r.globalUniforms.globalUniformData.resolution, i.uRound = r._roundPixels | e._roundPixels, z(
1313
+ e.groupColorAlpha,
1314
+ i.uColor,
1315
+ 0
1316
+ ), this.adaptor.execute(this, e);
1317
+ }
1318
+ /** Destroys the ParticleRenderer. */
1319
+ destroy() {
1320
+ this.renderer = null, this.defaultShader && (this.defaultShader.destroy(), this.defaultShader = null);
1321
+ }
1322
+ }
1323
+ class Ae extends ze {
1324
+ constructor(e) {
1325
+ super(e, new yt());
1326
+ }
1327
+ }
1328
+ Ae.extension = {
1329
+ type: [
1330
+ p.WebGLPipes
1331
+ ],
1332
+ name: "particle"
1333
+ };
1334
+ class ke extends ze {
1335
+ constructor(e) {
1336
+ super(e, new vt());
1337
+ }
1338
+ }
1339
+ ke.extension = {
1340
+ type: [
1341
+ p.WebGPUPipes
1342
+ ],
1343
+ name: "particle"
1344
+ };
1345
+ const Oe = class Ie extends bt {
1346
+ constructor(e = {}) {
1347
+ e = { ...Ie.defaultOptions, ...e }, super({
1348
+ width: e.width,
1349
+ height: e.height,
1350
+ verticesX: 4,
1351
+ verticesY: 4
1352
+ }), this.update(e);
1353
+ }
1354
+ /**
1355
+ * Updates the NineSliceGeometry with the options.
1356
+ * @param options - The options of the NineSliceGeometry.
1357
+ */
1358
+ update(e) {
1359
+ this.width = e.width ?? this.width, this.height = e.height ?? this.height, this._originalWidth = e.originalWidth ?? this._originalWidth, this._originalHeight = e.originalHeight ?? this._originalHeight, this._leftWidth = e.leftWidth ?? this._leftWidth, this._rightWidth = e.rightWidth ?? this._rightWidth, this._topHeight = e.topHeight ?? this._topHeight, this._bottomHeight = e.bottomHeight ?? this._bottomHeight, this._anchorX = e.anchor?.x, this._anchorY = e.anchor?.y, this.updateUvs(), this.updatePositions();
1360
+ }
1361
+ /** Updates the positions of the vertices. */
1362
+ updatePositions() {
1363
+ const e = this.positions, {
1364
+ width: t,
1365
+ height: r,
1366
+ _leftWidth: n,
1367
+ _rightWidth: s,
1368
+ _topHeight: i,
1369
+ _bottomHeight: o,
1370
+ _anchorX: u,
1371
+ _anchorY: c
1372
+ } = this, h = n + s, l = t > h ? 1 : t / h, d = i + o, f = r > d ? 1 : r / d, g = Math.min(l, f), m = u * t, x = c * r;
1373
+ e[0] = e[8] = e[16] = e[24] = -m, e[2] = e[10] = e[18] = e[26] = n * g - m, e[4] = e[12] = e[20] = e[28] = t - s * g - m, e[6] = e[14] = e[22] = e[30] = t - m, e[1] = e[3] = e[5] = e[7] = -x, e[9] = e[11] = e[13] = e[15] = i * g - x, e[17] = e[19] = e[21] = e[23] = r - o * g - x, e[25] = e[27] = e[29] = e[31] = r - x, this.getBuffer("aPosition").update();
1374
+ }
1375
+ /** Updates the UVs of the vertices. */
1376
+ updateUvs() {
1377
+ const e = this.uvs;
1378
+ 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;
1379
+ const t = 1 / this._originalWidth, r = 1 / this._originalHeight;
1380
+ 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();
1381
+ }
1382
+ };
1383
+ Oe.defaultOptions = {
1384
+ /** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
1385
+ width: 100,
1386
+ /** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
1387
+ height: 100,
1388
+ /** The width of the left column. */
1389
+ leftWidth: 10,
1390
+ /** The height of the top row. */
1391
+ topHeight: 10,
1392
+ /** The width of the right column. */
1393
+ rightWidth: 10,
1394
+ /** The height of the bottom row. */
1395
+ bottomHeight: 10,
1396
+ /** The original width of the texture */
1397
+ originalWidth: 100,
1398
+ /** The original height of the texture */
1399
+ originalHeight: 100
1400
+ };
1401
+ let Rt = Oe;
1402
+ class Ut extends Z {
1403
+ constructor() {
1404
+ super(), this.geometry = new Rt();
1405
+ }
1406
+ destroy() {
1407
+ this.geometry.destroy();
1408
+ }
1409
+ }
1410
+ class Ee {
1411
+ constructor(e) {
1412
+ this._renderer = e;
1413
+ }
1414
+ addRenderable(e, t) {
1415
+ const r = this._getGpuSprite(e);
1416
+ e.didViewUpdate && this._updateBatchableSprite(e, r), this._renderer.renderPipes.batch.addToBatch(r, t);
1417
+ }
1418
+ updateRenderable(e) {
1419
+ const t = this._getGpuSprite(e);
1420
+ e.didViewUpdate && this._updateBatchableSprite(e, t), t._batcher.updateElement(t);
1421
+ }
1422
+ validateRenderable(e) {
1423
+ const t = this._getGpuSprite(e);
1424
+ return !t._batcher.checkAndUpdateTexture(
1425
+ t,
1426
+ e._texture
1427
+ );
1428
+ }
1429
+ _updateBatchableSprite(e, t) {
1430
+ t.geometry.update(e), t.setTexture(e._texture);
1431
+ }
1432
+ _getGpuSprite(e) {
1433
+ return e._gpuData[this._renderer.uid] || this._initGPUSprite(e);
1434
+ }
1435
+ _initGPUSprite(e) {
1436
+ const t = e._gpuData[this._renderer.uid] = new Ut(), r = t;
1437
+ return r.renderable = e, r.transform = e.groupTransform, r.texture = e._texture, r.roundPixels = this._renderer._roundPixels | e._roundPixels, e.didViewUpdate || this._updateBatchableSprite(e, r), t;
1438
+ }
1439
+ destroy() {
1440
+ this._renderer = null;
1441
+ }
1442
+ }
1443
+ Ee.extension = {
1444
+ type: [
1445
+ p.WebGLPipes,
1446
+ p.WebGPUPipes,
1447
+ p.CanvasPipes
1448
+ ],
1449
+ name: "nineSliceSprite"
1450
+ };
1451
+ const Bt = {
1452
+ name: "tiling-bit",
1453
+ vertex: {
1454
+ header: (
1455
+ /* wgsl */
1456
+ `
1457
+ struct TilingUniforms {
1458
+ uMapCoord:mat3x3<f32>,
1459
+ uClampFrame:vec4<f32>,
1460
+ uClampOffset:vec2<f32>,
1461
+ uTextureTransform:mat3x3<f32>,
1462
+ uSizeAnchor:vec4<f32>
1463
+ };
1464
+
1465
+ @group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
1466
+ @group(2) @binding(1) var uTexture: texture_2d<f32>;
1467
+ @group(2) @binding(2) var uSampler: sampler;
1468
+ `
1469
+ ),
1470
+ main: (
1471
+ /* wgsl */
1472
+ `
1473
+ uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy;
1474
+
1475
+ position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy;
1476
+ `
1477
+ )
1478
+ },
1479
+ fragment: {
1480
+ header: (
1481
+ /* wgsl */
1482
+ `
1483
+ struct TilingUniforms {
1484
+ uMapCoord:mat3x3<f32>,
1485
+ uClampFrame:vec4<f32>,
1486
+ uClampOffset:vec2<f32>,
1487
+ uTextureTransform:mat3x3<f32>,
1488
+ uSizeAnchor:vec4<f32>
1489
+ };
1490
+
1491
+ @group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
1492
+ @group(2) @binding(1) var uTexture: texture_2d<f32>;
1493
+ @group(2) @binding(2) var uSampler: sampler;
1494
+ `
1495
+ ),
1496
+ main: (
1497
+ /* wgsl */
1498
+ `
1499
+
1500
+ var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV);
1501
+ coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy;
1502
+ var unclamped = coord;
1503
+ coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw);
1504
+
1505
+ var bias = 0.;
1506
+
1507
+ if(unclamped.x == coord.x && unclamped.y == coord.y)
1508
+ {
1509
+ bias = -32.;
1510
+ }
1511
+
1512
+ outColor = textureSampleBias(uTexture, uSampler, coord, bias);
1513
+ `
1514
+ )
1515
+ }
1516
+ }, Gt = {
1517
+ name: "tiling-bit",
1518
+ vertex: {
1519
+ header: (
1520
+ /* glsl */
1521
+ `
1522
+ uniform mat3 uTextureTransform;
1523
+ uniform vec4 uSizeAnchor;
1524
+
1525
+ `
1526
+ ),
1527
+ main: (
1528
+ /* glsl */
1529
+ `
1530
+ uv = (uTextureTransform * vec3(aUV, 1.0)).xy;
1531
+
1532
+ position = (position - uSizeAnchor.zw) * uSizeAnchor.xy;
1533
+ `
1534
+ )
1535
+ },
1536
+ fragment: {
1537
+ header: (
1538
+ /* glsl */
1539
+ `
1540
+ uniform sampler2D uTexture;
1541
+ uniform mat3 uMapCoord;
1542
+ uniform vec4 uClampFrame;
1543
+ uniform vec2 uClampOffset;
1544
+ `
1545
+ ),
1546
+ main: (
1547
+ /* glsl */
1548
+ `
1549
+
1550
+ vec2 coord = vUV + ceil(uClampOffset - vUV);
1551
+ coord = (uMapCoord * vec3(coord, 1.0)).xy;
1552
+ vec2 unclamped = coord;
1553
+ coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
1554
+
1555
+ outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0
1556
+
1557
+ `
1558
+ )
1559
+ }
1560
+ };
1561
+ let O, I;
1562
+ class Mt extends Q {
1563
+ constructor() {
1564
+ O ?? (O = xe({
1565
+ name: "tiling-sprite-shader",
1566
+ bits: [
1567
+ lt,
1568
+ Bt,
1569
+ _e
1570
+ ]
1571
+ })), I ?? (I = be({
1572
+ name: "tiling-sprite-shader",
1573
+ bits: [
1574
+ ct,
1575
+ Gt,
1576
+ ye
1577
+ ]
1578
+ }));
1579
+ const e = new C({
1580
+ uMapCoord: { value: new P(), type: "mat3x3<f32>" },
1581
+ uClampFrame: { value: new Float32Array([0, 0, 1, 1]), type: "vec4<f32>" },
1582
+ uClampOffset: { value: new Float32Array([0, 0]), type: "vec2<f32>" },
1583
+ uTextureTransform: { value: new P(), type: "mat3x3<f32>" },
1584
+ uSizeAnchor: { value: new Float32Array([100, 100, 0.5, 0.5]), type: "vec4<f32>" }
1585
+ });
1586
+ super({
1587
+ glProgram: I,
1588
+ gpuProgram: O,
1589
+ resources: {
1590
+ localUniforms: new C({
1591
+ uTransformMatrix: { value: new P(), type: "mat3x3<f32>" },
1592
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
1593
+ uRound: { value: 0, type: "f32" }
1594
+ }),
1595
+ tilingUniforms: e,
1596
+ uTexture: w.EMPTY.source,
1597
+ uSampler: w.EMPTY.source.style
1598
+ }
1599
+ });
1600
+ }
1601
+ updateUniforms(e, t, r, n, s, i) {
1602
+ const o = this.resources.tilingUniforms, u = i.width, c = i.height, h = i.textureMatrix, l = o.uniforms.uTextureTransform;
1603
+ l.set(
1604
+ r.a * u / e,
1605
+ r.b * u / t,
1606
+ r.c * c / e,
1607
+ r.d * c / t,
1608
+ r.tx / e,
1609
+ r.ty / t
1610
+ ), l.invert(), o.uniforms.uMapCoord = h.mapCoord, o.uniforms.uClampFrame = h.uClampFrame, o.uniforms.uClampOffset = h.uClampOffset, o.uniforms.uTextureTransform = l, o.uniforms.uSizeAnchor[0] = e, o.uniforms.uSizeAnchor[1] = t, o.uniforms.uSizeAnchor[2] = n, o.uniforms.uSizeAnchor[3] = s, i && (this.resources.uTexture = i.source, this.resources.uSampler = i.source.style);
1611
+ }
1612
+ }
1613
+ class Dt extends J {
1614
+ constructor() {
1615
+ super({
1616
+ positions: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
1617
+ uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
1618
+ indices: new Uint32Array([0, 1, 2, 0, 2, 3])
1619
+ });
1620
+ }
1621
+ }
1622
+ function zt(a, e) {
1623
+ const t = a.anchor.x, r = a.anchor.y;
1624
+ e[0] = -t * a.width, e[1] = -r * a.height, e[2] = (1 - t) * a.width, e[3] = -r * a.height, e[4] = (1 - t) * a.width, e[5] = (1 - r) * a.height, e[6] = -t * a.width, e[7] = (1 - r) * a.height;
1625
+ }
1626
+ function At(a, e, t, r) {
1627
+ let n = 0;
1628
+ const s = a.length / e, i = r.a, o = r.b, u = r.c, c = r.d, h = r.tx, l = r.ty;
1629
+ for (t *= e; n < s; ) {
1630
+ const d = a[t], f = a[t + 1];
1631
+ a[t] = i * d + u * f + h, a[t + 1] = o * d + c * f + l, t += e, n++;
1632
+ }
1633
+ }
1634
+ function kt(a, e) {
1635
+ const t = a.texture, r = t.frame.width, n = t.frame.height;
1636
+ let s = 0, i = 0;
1637
+ a.applyAnchorToTexture && (s = a.anchor.x, i = a.anchor.y), e[0] = e[6] = -s, e[2] = e[4] = 1 - s, e[1] = e[3] = -i, e[5] = e[7] = 1 - i;
1638
+ const o = P.shared;
1639
+ o.copyFrom(a._tileTransform.matrix), o.tx /= a.width, o.ty /= a.height, o.invert(), o.scale(a.width / r, a.height / n), At(e, 2, 0, o);
1640
+ }
1641
+ const B = new Dt();
1642
+ class Ot {
1643
+ constructor() {
1644
+ this.canBatch = !0, this.geometry = new J({
1645
+ indices: B.indices.slice(),
1646
+ positions: B.positions.slice(),
1647
+ uvs: B.uvs.slice()
1648
+ });
1649
+ }
1650
+ destroy() {
1651
+ this.geometry.destroy(), this.shader?.destroy();
1652
+ }
1653
+ }
1654
+ class Ve {
1655
+ constructor(e) {
1656
+ this._state = D.default2d, this._renderer = e;
1657
+ }
1658
+ validateRenderable(e) {
1659
+ const t = this._getTilingSpriteData(e), r = t.canBatch;
1660
+ this._updateCanBatch(e);
1661
+ const n = t.canBatch;
1662
+ if (n && n === r) {
1663
+ const { batchableMesh: s } = t;
1664
+ return !s._batcher.checkAndUpdateTexture(
1665
+ s,
1666
+ e.texture
1667
+ );
1668
+ }
1669
+ return r !== n;
1670
+ }
1671
+ addRenderable(e, t) {
1672
+ const r = this._renderer.renderPipes.batch;
1673
+ this._updateCanBatch(e);
1674
+ const n = this._getTilingSpriteData(e), { geometry: s, canBatch: i } = n;
1675
+ if (i) {
1676
+ n.batchableMesh || (n.batchableMesh = new Z());
1677
+ const o = n.batchableMesh;
1678
+ e.didViewUpdate && (this._updateBatchableMesh(e), o.geometry = s, o.renderable = e, o.transform = e.groupTransform, o.setTexture(e._texture)), o.roundPixels = this._renderer._roundPixels | e._roundPixels, r.addToBatch(o, t);
1679
+ } else
1680
+ r.break(t), n.shader || (n.shader = new Mt()), this.updateRenderable(e), t.add(e);
1681
+ }
1682
+ execute(e) {
1683
+ const { shader: t } = this._getTilingSpriteData(e);
1684
+ t.groups[0] = this._renderer.globalUniforms.bindGroup;
1685
+ const r = t.resources.localUniforms.uniforms;
1686
+ r.uTransformMatrix = e.groupTransform, r.uRound = this._renderer._roundPixels | e._roundPixels, z(
1687
+ e.groupColorAlpha,
1688
+ r.uColor,
1689
+ 0
1690
+ ), this._state.blendMode = q(e.groupBlendMode, e.texture._source), this._renderer.encoder.draw({
1691
+ geometry: B,
1692
+ shader: t,
1693
+ state: this._state
1694
+ });
1695
+ }
1696
+ updateRenderable(e) {
1697
+ const t = this._getTilingSpriteData(e), { canBatch: r } = t;
1698
+ if (r) {
1699
+ const { batchableMesh: n } = t;
1700
+ e.didViewUpdate && this._updateBatchableMesh(e), n._batcher.updateElement(n);
1701
+ } else if (e.didViewUpdate) {
1702
+ const { shader: n } = t;
1703
+ n.updateUniforms(
1704
+ e.width,
1705
+ e.height,
1706
+ e._tileTransform.matrix,
1707
+ e.anchor.x,
1708
+ e.anchor.y,
1709
+ e.texture
1710
+ );
1711
+ }
1712
+ }
1713
+ _getTilingSpriteData(e) {
1714
+ return e._gpuData[this._renderer.uid] || this._initTilingSpriteData(e);
1715
+ }
1716
+ _initTilingSpriteData(e) {
1717
+ const t = new Ot();
1718
+ return t.renderable = e, e._gpuData[this._renderer.uid] = t, t;
1719
+ }
1720
+ _updateBatchableMesh(e) {
1721
+ const t = this._getTilingSpriteData(e), { geometry: r } = t, n = e.texture.source.style;
1722
+ n.addressMode !== "repeat" && (n.addressMode = "repeat", n.update()), kt(e, r.uvs), zt(e, r.positions);
1723
+ }
1724
+ destroy() {
1725
+ this._renderer = null;
1726
+ }
1727
+ _updateCanBatch(e) {
1728
+ const t = this._getTilingSpriteData(e), r = e.texture;
1729
+ let n = !0;
1730
+ return this._renderer.type === $.WEBGL && (n = this._renderer.context.supports.nonPowOf2wrapping), t.canBatch = r.textureMatrix.isSimple && (n || r.source.isPowerOfTwo), t.canBatch;
1731
+ }
1732
+ }
1733
+ Ve.extension = {
1734
+ type: [
1735
+ p.WebGLPipes,
1736
+ p.WebGPUPipes,
1737
+ p.CanvasPipes
1738
+ ],
1739
+ name: "tilingSprite"
1740
+ };
1741
+ const It = {
1742
+ name: "local-uniform-msdf-bit",
1743
+ vertex: {
1744
+ header: (
1745
+ /* wgsl */
1746
+ `
1747
+ struct LocalUniforms {
1748
+ uColor:vec4<f32>,
1749
+ uTransformMatrix:mat3x3<f32>,
1750
+ uDistance: f32,
1751
+ uRound:f32,
1752
+ }
1753
+
1754
+ @group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
1755
+ `
1756
+ ),
1757
+ main: (
1758
+ /* wgsl */
1759
+ `
1760
+ vColor *= localUniforms.uColor;
1761
+ modelMatrix *= localUniforms.uTransformMatrix;
1762
+ `
1763
+ ),
1764
+ end: (
1765
+ /* wgsl */
1766
+ `
1767
+ if(localUniforms.uRound == 1)
1768
+ {
1769
+ vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
1770
+ }
1771
+ `
1772
+ )
1773
+ },
1774
+ fragment: {
1775
+ header: (
1776
+ /* wgsl */
1777
+ `
1778
+ struct LocalUniforms {
1779
+ uColor:vec4<f32>,
1780
+ uTransformMatrix:mat3x3<f32>,
1781
+ uDistance: f32
1782
+ }
1783
+
1784
+ @group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
1785
+ `
1786
+ ),
1787
+ main: (
1788
+ /* wgsl */
1789
+ `
1790
+ outColor = vec4<f32>(calculateMSDFAlpha(outColor, localUniforms.uColor, localUniforms.uDistance));
1791
+ `
1792
+ )
1793
+ }
1794
+ }, Et = {
1795
+ name: "local-uniform-msdf-bit",
1796
+ vertex: {
1797
+ header: (
1798
+ /* glsl */
1799
+ `
1800
+ uniform mat3 uTransformMatrix;
1801
+ uniform vec4 uColor;
1802
+ uniform float uRound;
1803
+ `
1804
+ ),
1805
+ main: (
1806
+ /* glsl */
1807
+ `
1808
+ vColor *= uColor;
1809
+ modelMatrix *= uTransformMatrix;
1810
+ `
1811
+ ),
1812
+ end: (
1813
+ /* glsl */
1814
+ `
1815
+ if(uRound == 1.)
1816
+ {
1817
+ gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
1818
+ }
1819
+ `
1820
+ )
1821
+ },
1822
+ fragment: {
1823
+ header: (
1824
+ /* glsl */
1825
+ `
1826
+ uniform float uDistance;
1827
+ `
1828
+ ),
1829
+ main: (
1830
+ /* glsl */
1831
+ `
1832
+ outColor = vec4(calculateMSDFAlpha(outColor, vColor, uDistance));
1833
+ `
1834
+ )
1835
+ }
1836
+ }, Vt = {
1837
+ name: "msdf-bit",
1838
+ fragment: {
1839
+ header: (
1840
+ /* wgsl */
1841
+ `
1842
+ fn calculateMSDFAlpha(msdfColor:vec4<f32>, shapeColor:vec4<f32>, distance:f32) -> f32 {
1843
+
1844
+ // MSDF
1845
+ var median = msdfColor.r + msdfColor.g + msdfColor.b -
1846
+ min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
1847
+ max(msdfColor.r, max(msdfColor.g, msdfColor.b));
1848
+
1849
+ // SDF
1850
+ median = min(median, msdfColor.a);
1851
+
1852
+ var screenPxDistance = distance * (median - 0.5);
1853
+ var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
1854
+ if (median < 0.01) {
1855
+ alpha = 0.0;
1856
+ } else if (median > 0.99) {
1857
+ alpha = 1.0;
1858
+ }
1859
+
1860
+ // Gamma correction for coverage-like alpha
1861
+ var luma: f32 = dot(shapeColor.rgb, vec3<f32>(0.299, 0.587, 0.114));
1862
+ var gamma: f32 = mix(1.0, 1.0 / 2.2, luma);
1863
+ var coverage: f32 = pow(shapeColor.a * alpha, gamma);
1864
+
1865
+ return coverage;
1866
+
1867
+ }
1868
+ `
1869
+ )
1870
+ }
1871
+ }, Wt = {
1872
+ name: "msdf-bit",
1873
+ fragment: {
1874
+ header: (
1875
+ /* glsl */
1876
+ `
1877
+ float calculateMSDFAlpha(vec4 msdfColor, vec4 shapeColor, float distance) {
1878
+
1879
+ // MSDF
1880
+ float median = msdfColor.r + msdfColor.g + msdfColor.b -
1881
+ min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
1882
+ max(msdfColor.r, max(msdfColor.g, msdfColor.b));
1883
+
1884
+ // SDF
1885
+ median = min(median, msdfColor.a);
1886
+
1887
+ float screenPxDistance = distance * (median - 0.5);
1888
+ float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
1889
+
1890
+ if (median < 0.01) {
1891
+ alpha = 0.0;
1892
+ } else if (median > 0.99) {
1893
+ alpha = 1.0;
1894
+ }
1895
+
1896
+ // Gamma correction for coverage-like alpha
1897
+ float luma = dot(shapeColor.rgb, vec3(0.299, 0.587, 0.114));
1898
+ float gamma = mix(1.0, 1.0 / 2.2, luma);
1899
+ float coverage = pow(shapeColor.a * alpha, gamma);
1900
+
1901
+ return coverage;
1902
+ }
1903
+ `
1904
+ )
1905
+ }
1906
+ };
1907
+ let E, V;
1908
+ class Yt extends Q {
1909
+ constructor(e) {
1910
+ const t = new C({
1911
+ uColor: { value: new Float32Array([1, 1, 1, 1]), type: "vec4<f32>" },
1912
+ uTransformMatrix: { value: new P(), type: "mat3x3<f32>" },
1913
+ uDistance: { value: 4, type: "f32" },
1914
+ uRound: { value: 0, type: "f32" }
1915
+ });
1916
+ E ?? (E = xe({
1917
+ name: "sdf-shader",
1918
+ bits: [
1919
+ Qe,
1920
+ Je(e),
1921
+ It,
1922
+ Vt,
1923
+ _e
1924
+ ]
1925
+ })), V ?? (V = be({
1926
+ name: "sdf-shader",
1927
+ bits: [
1928
+ Ze,
1929
+ et(e),
1930
+ Et,
1931
+ Wt,
1932
+ ye
1933
+ ]
1934
+ })), super({
1935
+ glProgram: V,
1936
+ gpuProgram: E,
1937
+ resources: {
1938
+ localUniforms: t,
1939
+ batchSamplers: tt(e)
1940
+ }
1941
+ });
1942
+ }
1943
+ }
1944
+ class Lt extends it {
1945
+ destroy() {
1946
+ this.context.customShader && this.context.customShader.destroy(), super.destroy();
1947
+ }
1948
+ }
1949
+ class We {
1950
+ constructor(e) {
1951
+ this._renderer = e;
1952
+ }
1953
+ validateRenderable(e) {
1954
+ const t = this._getGpuBitmapText(e);
1955
+ return this._renderer.renderPipes.graphics.validateRenderable(t);
1956
+ }
1957
+ addRenderable(e, t) {
1958
+ const r = this._getGpuBitmapText(e);
1959
+ de(e, r), e._didTextUpdate && (e._didTextUpdate = !1, this._updateContext(e, r)), this._renderer.renderPipes.graphics.addRenderable(r, t), r.context.customShader && this._updateDistanceField(e);
1960
+ }
1961
+ updateRenderable(e) {
1962
+ const t = this._getGpuBitmapText(e);
1963
+ de(e, t), this._renderer.renderPipes.graphics.updateRenderable(t), t.context.customShader && this._updateDistanceField(e);
1964
+ }
1965
+ _updateContext(e, t) {
1966
+ const { context: r } = t, n = rt.getFont(e.text, e._style);
1967
+ r.clear(), n.distanceField.type !== "none" && (r.customShader || (r.customShader = new Yt(this._renderer.limits.maxBatchableTextures)));
1968
+ const s = nt.graphemeSegmenter(e.text), i = e._style;
1969
+ let o = n.baseLineOffset;
1970
+ const u = st(s, i, n, !0), c = i.padding, h = u.scale;
1971
+ let l = u.width, d = u.height + u.offsetY;
1972
+ i._stroke && (l += i._stroke.width / h, d += i._stroke.width / h), r.translate(-e._anchor._x * l - c, -e._anchor._y * d - c).scale(h, h);
1973
+ const f = n.applyFillAsTint ? i._fill.color : 16777215;
1974
+ let g = n.fontMetrics.fontSize, m = n.lineHeight;
1975
+ i.lineHeight && (g = i.fontSize / h, m = i.lineHeight / h);
1976
+ let x = (m - g) / 2;
1977
+ x - n.baseLineOffset < 0 && (x = 0);
1978
+ for (let _ = 0; _ < u.lines.length; _++) {
1979
+ const y = u.lines[_];
1980
+ for (let S = 0; S < y.charPositions.length; S++) {
1981
+ const Ne = y.chars[S], R = n.chars[Ne];
1982
+ if (R?.texture) {
1983
+ const A = R.texture;
1984
+ r.texture(
1985
+ A,
1986
+ f || "black",
1987
+ Math.round(y.charPositions[S] + R.xOffset),
1988
+ Math.round(o + R.yOffset + x),
1989
+ A.orig.width,
1990
+ A.orig.height
1991
+ );
1992
+ }
1993
+ }
1994
+ o += m;
1995
+ }
1996
+ }
1997
+ _getGpuBitmapText(e) {
1998
+ return e._gpuData[this._renderer.uid] || this.initGpuText(e);
1999
+ }
2000
+ initGpuText(e) {
2001
+ const t = new Lt();
2002
+ return e._gpuData[this._renderer.uid] = t, this._updateContext(e, t), t;
2003
+ }
2004
+ _updateDistanceField(e) {
2005
+ const t = this._getGpuBitmapText(e).context, r = e._style.fontFamily, n = H.get(`${r}-bitmap`), { a: s, b: i, c: o, d: u } = e.groupTransform, c = Math.sqrt(s * s + i * i), h = Math.sqrt(o * o + u * u), l = (Math.abs(c) + Math.abs(h)) / 2, d = n.baseRenderedFontSize / e._style.fontSize, f = l * n.distanceField.range * (1 / d);
2006
+ t.customShader.resources.localUniforms.uniforms.uDistance = f;
2007
+ }
2008
+ destroy() {
2009
+ this._renderer = null;
2010
+ }
2011
+ }
2012
+ We.extension = {
2013
+ type: [
2014
+ p.WebGLPipes,
2015
+ p.WebGPUPipes,
2016
+ p.CanvasPipes
2017
+ ],
2018
+ name: "bitmapText"
2019
+ };
2020
+ function de(a, e) {
2021
+ e.groupTransform = a.groupTransform, e.groupColorAlpha = a.groupColorAlpha, e.groupColor = a.groupColor, e.groupBlendMode = a.groupBlendMode, e.globalDisplayStatus = a.globalDisplayStatus, e.groupTransform = a.groupTransform, e.localDisplayStatus = a.localDisplayStatus, e.groupAlpha = a.groupAlpha, e._roundPixels = a._roundPixels;
2022
+ }
2023
+ class Xt extends Te {
2024
+ /**
2025
+ * Creates an instance of BatchableHTMLText.
2026
+ * @param renderer - The renderer instance to be used.
2027
+ */
2028
+ constructor(e) {
2029
+ super(), this.generatingTexture = !1, this.currentKey = "--", this._renderer = e, e.runners.resolutionChange.add(this);
2030
+ }
2031
+ /** Handles resolution changes for the HTML text. If the text has auto resolution enabled, it triggers a view update. */
2032
+ resolutionChange() {
2033
+ const e = this.renderable;
2034
+ e._autoResolution && e.onViewUpdate();
2035
+ }
2036
+ /** Destroys the BatchableHTMLText instance. Returns the texture promise to the renderer and cleans up references. */
2037
+ destroy() {
2038
+ const { htmlText: e } = this._renderer;
2039
+ e.getReferenceCount(this.currentKey) === null ? e.returnTexturePromise(this.texturePromise) : e.decreaseReferenceCount(this.currentKey), this._renderer.runners.resolutionChange.remove(this), this.texturePromise = null, this._renderer = null;
2040
+ }
2041
+ }
2042
+ function K(a, e) {
2043
+ const { texture: t, bounds: r } = a, n = e._style._getFinalPadding();
2044
+ at(r, e._anchor, t);
2045
+ const s = e._anchor._x * n * 2, i = e._anchor._y * n * 2;
2046
+ r.minX -= n - s, r.minY -= n - i, r.maxX -= n - s, r.maxY -= n - i;
2047
+ }
2048
+ class Ye {
2049
+ constructor(e) {
2050
+ this._renderer = e;
2051
+ }
2052
+ validateRenderable(e) {
2053
+ const t = this._getGpuText(e), r = e.styleKey;
2054
+ return t.currentKey !== r;
2055
+ }
2056
+ addRenderable(e, t) {
2057
+ const r = this._getGpuText(e);
2058
+ if (e._didTextUpdate) {
2059
+ const n = e._autoResolution ? this._renderer.resolution : e.resolution;
2060
+ (r.currentKey !== e.styleKey || e.resolution !== n) && this._updateGpuText(e).catch((s) => {
2061
+ console.error(s);
2062
+ }), e._didTextUpdate = !1, K(r, e);
2063
+ }
2064
+ this._renderer.renderPipes.batch.addToBatch(r, t);
2065
+ }
2066
+ updateRenderable(e) {
2067
+ const t = this._getGpuText(e);
2068
+ t._batcher.updateElement(t);
2069
+ }
2070
+ async _updateGpuText(e) {
2071
+ e._didTextUpdate = !1;
2072
+ const t = this._getGpuText(e);
2073
+ if (t.generatingTexture)
2074
+ return;
2075
+ const r = t.texturePromise;
2076
+ t.texturePromise = null, t.generatingTexture = !0, e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution;
2077
+ let n = this._renderer.htmlText.getTexturePromise(e);
2078
+ r && (n = n.finally(() => {
2079
+ this._renderer.htmlText.decreaseReferenceCount(t.currentKey), this._renderer.htmlText.returnTexturePromise(r);
2080
+ })), t.texturePromise = n, t.currentKey = e.styleKey, t.texture = await n;
2081
+ const s = e.renderGroup || e.parentRenderGroup;
2082
+ s && (s.structureDidChange = !0), t.generatingTexture = !1, K(t, e);
2083
+ }
2084
+ _getGpuText(e) {
2085
+ return e._gpuData[this._renderer.uid] || this.initGpuText(e);
2086
+ }
2087
+ initGpuText(e) {
2088
+ const t = new Xt(this._renderer);
2089
+ return t.renderable = e, t.transform = e.groupTransform, t.texture = w.EMPTY, t.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution, e._gpuData[this._renderer.uid] = t, t;
2090
+ }
2091
+ destroy() {
2092
+ this._renderer = null;
2093
+ }
2094
+ }
2095
+ Ye.extension = {
2096
+ type: [
2097
+ p.WebGLPipes,
2098
+ p.WebGPUPipes,
2099
+ p.CanvasPipes
2100
+ ],
2101
+ name: "htmlText"
2102
+ };
2103
+ function Ht() {
2104
+ const { userAgent: a } = j.get().getNavigator();
2105
+ return /^((?!chrome|android).)*safari/i.test(a);
2106
+ }
2107
+ const Kt = new me();
2108
+ function Le(a, e, t, r) {
2109
+ const n = Kt;
2110
+ n.minX = 0, n.minY = 0, n.maxX = a.width / r | 0, n.maxY = a.height / r | 0;
2111
+ const s = v.getOptimalTexture(
2112
+ n.width,
2113
+ n.height,
2114
+ r,
2115
+ !1
2116
+ );
2117
+ return s.source.uploadMethodId = "image", s.source.resource = a, s.source.alphaMode = "premultiply-alpha-on-upload", s.frame.width = e / r, s.frame.height = t / r, s.source.emit("update", s.source), s.updateUvs(), s;
2118
+ }
2119
+ function Nt(a, e) {
2120
+ const t = e.fontFamily, r = [], n = {}, s = /font-family:([^;"\s]+)/g, i = a.match(s);
2121
+ function o(u) {
2122
+ n[u] || (r.push(u), n[u] = !0);
2123
+ }
2124
+ if (Array.isArray(t))
2125
+ for (let u = 0; u < t.length; u++)
2126
+ o(t[u]);
2127
+ else
2128
+ o(t);
2129
+ i && i.forEach((u) => {
2130
+ const c = u.split(":")[1].trim();
2131
+ o(c);
2132
+ });
2133
+ for (const u in e.tagStyles) {
2134
+ const c = e.tagStyles[u].fontFamily;
2135
+ o(c);
2136
+ }
2137
+ return r;
2138
+ }
2139
+ async function $t(a) {
2140
+ const t = await (await j.get().fetch(a)).blob(), r = new FileReader();
2141
+ return await new Promise((s, i) => {
2142
+ r.onloadend = () => s(r.result), r.onerror = i, r.readAsDataURL(t);
2143
+ });
2144
+ }
2145
+ async function jt(a, e) {
2146
+ const t = await $t(e);
2147
+ return `@font-face {
2148
+ font-family: "${a.fontFamily}";
2149
+ font-weight: ${a.fontWeight};
2150
+ font-style: ${a.fontStyle};
2151
+ src: url('${t}');
2152
+ }`;
2153
+ }
2154
+ const W = /* @__PURE__ */ new Map();
2155
+ async function qt(a) {
2156
+ const e = a.filter((t) => H.has(`${t}-and-url`)).map((t) => {
2157
+ if (!W.has(t)) {
2158
+ const { entries: r } = H.get(`${t}-and-url`), n = [];
2159
+ r.forEach((s) => {
2160
+ const i = s.url, u = s.faces.map((c) => ({ weight: c.weight, style: c.style }));
2161
+ n.push(
2162
+ ...u.map(
2163
+ (c) => jt(
2164
+ {
2165
+ fontWeight: c.weight,
2166
+ fontStyle: c.style,
2167
+ fontFamily: t
2168
+ },
2169
+ i
2170
+ )
2171
+ )
2172
+ );
2173
+ }), W.set(
2174
+ t,
2175
+ Promise.all(n).then((s) => s.join(`
2176
+ `))
2177
+ );
2178
+ }
2179
+ return W.get(t);
2180
+ });
2181
+ return (await Promise.all(e)).join(`
2182
+ `);
2183
+ }
2184
+ function Qt(a, e, t, r, n) {
2185
+ const { domElement: s, styleElement: i, svgRoot: o } = n;
2186
+ s.innerHTML = `<style>${e.cssStyle}</style><div style='padding:0;'>${a}</div>`, s.setAttribute("style", `transform: scale(${t});transform-origin: top left; display: inline-block`), i.textContent = r;
2187
+ const { width: u, height: c } = n.image;
2188
+ return o.setAttribute("width", u.toString()), o.setAttribute("height", c.toString()), new XMLSerializer().serializeToString(o);
2189
+ }
2190
+ function Jt(a, e) {
2191
+ const t = ve.getOptimalCanvasAndContext(
2192
+ a.width,
2193
+ a.height,
2194
+ e
2195
+ ), { context: r } = t;
2196
+ return r.clearRect(0, 0, a.width, a.height), r.drawImage(a, 0, 0), t;
2197
+ }
2198
+ function Zt(a, e, t) {
2199
+ return new Promise(async (r) => {
2200
+ t && await new Promise((n) => setTimeout(n, 100)), a.onload = () => {
2201
+ r();
2202
+ }, a.src = `data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`, a.crossOrigin = "anonymous";
2203
+ });
2204
+ }
2205
+ class Xe {
2206
+ constructor(e) {
2207
+ this._activeTextures = {}, this._renderer = e, this._createCanvas = e.type === $.WEBGPU;
2208
+ }
2209
+ /**
2210
+ * @param options
2211
+ * @deprecated Use getTexturePromise instead
2212
+ */
2213
+ getTexture(e) {
2214
+ return this.getTexturePromise(e);
2215
+ }
2216
+ /**
2217
+ * Increases the reference count for a texture.
2218
+ * @param text - The HTMLText instance associated with the texture.
2219
+ */
2220
+ getManagedTexture(e) {
2221
+ const t = e.styleKey;
2222
+ if (this._activeTextures[t])
2223
+ return this._increaseReferenceCount(t), this._activeTextures[t].promise;
2224
+ const r = this._buildTexturePromise(e).then((n) => (this._activeTextures[t].texture = n, n));
2225
+ return this._activeTextures[t] = {
2226
+ texture: null,
2227
+ promise: r,
2228
+ usageCount: 1
2229
+ }, r;
2230
+ }
2231
+ /**
2232
+ * Gets the current reference count for a texture associated with a text key.
2233
+ * @param textKey - The unique key identifying the text style configuration
2234
+ * @returns The number of Text instances currently using this texture
2235
+ */
2236
+ getReferenceCount(e) {
2237
+ return this._activeTextures[e]?.usageCount ?? null;
2238
+ }
2239
+ _increaseReferenceCount(e) {
2240
+ this._activeTextures[e].usageCount++;
2241
+ }
2242
+ /**
2243
+ * Decreases the reference count for a texture.
2244
+ * If the count reaches zero, the texture is cleaned up.
2245
+ * @param textKey - The key associated with the HTMLText instance.
2246
+ */
2247
+ decreaseReferenceCount(e) {
2248
+ const t = this._activeTextures[e];
2249
+ t && (t.usageCount--, t.usageCount === 0 && (t.texture ? this._cleanUp(t.texture) : t.promise.then((r) => {
2250
+ t.texture = r, this._cleanUp(t.texture);
2251
+ }).catch(() => {
2252
+ Y("HTMLTextSystem: Failed to clean texture");
2253
+ }), this._activeTextures[e] = null));
2254
+ }
2255
+ /**
2256
+ * Returns a promise that resolves to a texture for the given HTMLText options.
2257
+ * @param options - The options for the HTMLText.
2258
+ * @returns A promise that resolves to a Texture.
2259
+ */
2260
+ getTexturePromise(e) {
2261
+ return this._buildTexturePromise(e);
2262
+ }
2263
+ async _buildTexturePromise(e) {
2264
+ const { text: t, style: r, resolution: n, textureStyle: s } = e, i = M.get(Ue), o = Nt(t, r), u = await qt(o), c = xt(t, r, u, i), h = Math.ceil(Math.ceil(Math.max(1, c.width) + r.padding * 2) * n), l = Math.ceil(Math.ceil(Math.max(1, c.height) + r.padding * 2) * n), d = i.image, f = 2;
2265
+ d.width = (h | 0) + f, d.height = (l | 0) + f;
2266
+ const g = Qt(t, r, n, u, i);
2267
+ await Zt(d, g, Ht() && o.length > 0);
2268
+ const m = d;
2269
+ let x;
2270
+ this._createCanvas && (x = Jt(d, n));
2271
+ const _ = Le(
2272
+ x ? x.canvas : m,
2273
+ d.width - f,
2274
+ d.height - f,
2275
+ n
2276
+ );
2277
+ return s && (_.source.style = s), this._createCanvas && (this._renderer.texture.initSource(_.source), ve.returnCanvasAndContext(x)), M.return(i), _;
2278
+ }
2279
+ returnTexturePromise(e) {
2280
+ e.then((t) => {
2281
+ this._cleanUp(t);
2282
+ }).catch(() => {
2283
+ Y("HTMLTextSystem: Failed to clean texture");
2284
+ });
2285
+ }
2286
+ _cleanUp(e) {
2287
+ v.returnTexture(e, !0), e.source.resource = null, e.source.uploadMethodId = "unknown";
2288
+ }
2289
+ destroy() {
2290
+ this._renderer = null;
2291
+ for (const e in this._activeTextures)
2292
+ this._activeTextures[e] && this.returnTexturePromise(this._activeTextures[e].promise);
2293
+ this._activeTextures = null;
2294
+ }
2295
+ }
2296
+ Xe.extension = {
2297
+ type: [
2298
+ p.WebGLSystem,
2299
+ p.WebGPUSystem,
2300
+ p.CanvasSystem
2301
+ ],
2302
+ name: "htmlText"
2303
+ };
2304
+ class er extends Te {
2305
+ constructor(e) {
2306
+ super(), this._renderer = e, e.runners.resolutionChange.add(this);
2307
+ }
2308
+ resolutionChange() {
2309
+ const e = this.renderable;
2310
+ e._autoResolution && e.onViewUpdate();
2311
+ }
2312
+ destroy() {
2313
+ const { canvasText: e } = this._renderer;
2314
+ e.getReferenceCount(this.currentKey) > 0 ? e.decreaseReferenceCount(this.currentKey) : this.texture && e.returnTexture(this.texture), this._renderer.runners.resolutionChange.remove(this), this._renderer = null;
2315
+ }
2316
+ }
2317
+ class He {
2318
+ constructor(e) {
2319
+ this._renderer = e;
2320
+ }
2321
+ validateRenderable(e) {
2322
+ const t = this._getGpuText(e), r = e.styleKey;
2323
+ return t.currentKey !== r ? !0 : e._didTextUpdate;
2324
+ }
2325
+ addRenderable(e, t) {
2326
+ const r = this._getGpuText(e);
2327
+ if (e._didTextUpdate) {
2328
+ const n = e._autoResolution ? this._renderer.resolution : e.resolution;
2329
+ (r.currentKey !== e.styleKey || e.resolution !== n) && this._updateGpuText(e), e._didTextUpdate = !1, K(r, e);
2330
+ }
2331
+ this._renderer.renderPipes.batch.addToBatch(r, t);
2332
+ }
2333
+ updateRenderable(e) {
2334
+ const t = this._getGpuText(e);
2335
+ t._batcher.updateElement(t);
2336
+ }
2337
+ _updateGpuText(e) {
2338
+ const t = this._getGpuText(e);
2339
+ t.texture && this._renderer.canvasText.decreaseReferenceCount(t.currentKey), e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution, t.texture = this._renderer.canvasText.getManagedTexture(e), t.currentKey = e.styleKey;
2340
+ }
2341
+ _getGpuText(e) {
2342
+ return e._gpuData[this._renderer.uid] || this.initGpuText(e);
2343
+ }
2344
+ initGpuText(e) {
2345
+ const t = new er(this._renderer);
2346
+ return t.currentKey = "--", t.renderable = e, t.transform = e.groupTransform, t.bounds = { minX: 0, maxX: 1, minY: 0, maxY: 0 }, t.roundPixels = this._renderer._roundPixels | e._roundPixels, e._gpuData[this._renderer.uid] = t, t;
2347
+ }
2348
+ destroy() {
2349
+ this._renderer = null;
2350
+ }
2351
+ }
2352
+ He.extension = {
2353
+ type: [
2354
+ p.WebGLPipes,
2355
+ p.WebGPUPipes,
2356
+ p.CanvasPipes
2357
+ ],
2358
+ name: "text"
2359
+ };
2360
+ class Ke {
2361
+ constructor(e) {
2362
+ this._activeTextures = {}, this._renderer = e;
2363
+ }
2364
+ getTexture(e, t, r, n) {
2365
+ typeof e == "string" && (G("8.0.0", "CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"), e = {
2366
+ text: e,
2367
+ style: r,
2368
+ resolution: t
2369
+ }), e.style instanceof te || (e.style = new te(e.style)), e.textureStyle instanceof X || (e.textureStyle = new X(e.textureStyle)), typeof e.text != "string" && (e.text = e.text.toString());
2370
+ const { text: s, style: i, textureStyle: o } = e, u = e.resolution ?? this._renderer.resolution, { frame: c, canvasAndContext: h } = k.getCanvasAndContext({
2371
+ text: s,
2372
+ style: i,
2373
+ resolution: u
2374
+ }), l = Le(h.canvas, c.width, c.height, u);
2375
+ if (o && (l.source.style = o), i.trim && (c.pad(i.padding), l.frame.copyFrom(c), l.frame.scale(1 / u), l.updateUvs()), i.filters) {
2376
+ const d = this._applyFilters(l, i.filters);
2377
+ return this.returnTexture(l), k.returnCanvasAndContext(h), d;
2378
+ }
2379
+ return this._renderer.texture.initSource(l._source), k.returnCanvasAndContext(h), l;
2380
+ }
2381
+ /**
2382
+ * Returns a texture that was created wit the above `getTexture` function.
2383
+ * Handy if you are done with a texture and want to return it to the pool.
2384
+ * @param texture - The texture to be returned.
2385
+ */
2386
+ returnTexture(e) {
2387
+ const t = e.source;
2388
+ t.resource = null, t.uploadMethodId = "unknown", t.alphaMode = "no-premultiply-alpha", v.returnTexture(e, !0);
2389
+ }
2390
+ /**
2391
+ * Renders text to its canvas, and updates its texture.
2392
+ * @deprecated since 8.10.0
2393
+ */
2394
+ renderTextToCanvas() {
2395
+ G(
2396
+ "8.10.0",
2397
+ "CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead"
2398
+ );
2399
+ }
2400
+ /**
2401
+ * Gets or creates a managed texture for a Text object. This method handles texture reuse and reference counting.
2402
+ * @param text - The Text object that needs a texture
2403
+ * @returns A Texture instance that represents the rendered text
2404
+ * @remarks
2405
+ * This method performs the following:
2406
+ * 1. Sets the appropriate resolution based on auto-resolution settings
2407
+ * 2. Checks if a texture already exists for the text's style
2408
+ * 3. Creates a new texture if needed or returns an existing one
2409
+ * 4. Manages reference counting for texture reuse
2410
+ */
2411
+ getManagedTexture(e) {
2412
+ e._resolution = e._autoResolution ? this._renderer.resolution : e.resolution;
2413
+ const t = e.styleKey;
2414
+ if (this._activeTextures[t])
2415
+ return this._increaseReferenceCount(t), this._activeTextures[t].texture;
2416
+ const r = this.getTexture({
2417
+ text: e.text,
2418
+ style: e.style,
2419
+ resolution: e._resolution,
2420
+ textureStyle: e.textureStyle
2421
+ });
2422
+ return this._activeTextures[t] = {
2423
+ texture: r,
2424
+ usageCount: 1
2425
+ }, r;
2426
+ }
2427
+ /**
2428
+ * Decreases the reference count for a texture associated with a text key.
2429
+ * When the reference count reaches zero, the texture is returned to the pool.
2430
+ * @param textKey - The unique key identifying the text style configuration
2431
+ * @remarks
2432
+ * This method is crucial for memory management, ensuring textures are properly
2433
+ * cleaned up when they are no longer needed by any Text instances.
2434
+ */
2435
+ decreaseReferenceCount(e) {
2436
+ const t = this._activeTextures[e];
2437
+ t.usageCount--, t.usageCount === 0 && (this.returnTexture(t.texture), this._activeTextures[e] = null);
2438
+ }
2439
+ /**
2440
+ * Gets the current reference count for a texture associated with a text key.
2441
+ * @param textKey - The unique key identifying the text style configuration
2442
+ * @returns The number of Text instances currently using this texture
2443
+ */
2444
+ getReferenceCount(e) {
2445
+ return this._activeTextures[e]?.usageCount ?? 0;
2446
+ }
2447
+ _increaseReferenceCount(e) {
2448
+ this._activeTextures[e].usageCount++;
2449
+ }
2450
+ /**
2451
+ * Applies the specified filters to the given texture.
2452
+ *
2453
+ * This method takes a texture and a list of filters, applies the filters to the texture,
2454
+ * and returns the resulting texture. It also ensures that the alpha mode of the resulting
2455
+ * texture is set to 'premultiplied-alpha'.
2456
+ * @param {Texture} texture - The texture to which the filters will be applied.
2457
+ * @param {Filter[]} filters - The filters to apply to the texture.
2458
+ * @returns {Texture} The resulting texture after all filters have been applied.
2459
+ */
2460
+ _applyFilters(e, t) {
2461
+ const r = this._renderer.renderTarget.renderTarget, n = this._renderer.filter.generateFilteredTexture({
2462
+ texture: e,
2463
+ filters: t
2464
+ });
2465
+ return this._renderer.renderTarget.bind(r, !1), n;
2466
+ }
2467
+ destroy() {
2468
+ this._renderer = null;
2469
+ for (const e in this._activeTextures)
2470
+ this._activeTextures[e] && this.returnTexture(this._activeTextures[e].texture);
2471
+ this._activeTextures = null;
2472
+ }
2473
+ }
2474
+ Ke.extension = {
2475
+ type: [
2476
+ p.WebGLSystem,
2477
+ p.WebGPUSystem,
2478
+ p.CanvasSystem
2479
+ ],
2480
+ name: "canvasText"
2481
+ };
2482
+ b.add(Pe);
2483
+ b.add(we);
2484
+ b.add(Be);
2485
+ b.add(ot);
2486
+ b.add(De);
2487
+ b.add(Ae);
2488
+ b.add(ke);
2489
+ b.add(Ke);
2490
+ b.add(He);
2491
+ b.add(We);
2492
+ b.add(Xe);
2493
+ b.add(Ye);
2494
+ b.add(Ve);
2495
+ b.add(Ee);
2496
+ b.add(Se);
2497
+ b.add(Ce);