@industry-theme/repository-composition-panels 0.7.15 → 0.7.16

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 (38) hide show
  1. package/dist/browserAll-XNN46GKF.js +7 -0
  2. package/dist/browserAll-XNN46GKF.js.map +1 -0
  3. package/dist/{index-pPFTSf2O.js → index-Bt-XsLNt.js} +16092 -689
  4. package/dist/{index-pPFTSf2O.js.map → index-Bt-XsLNt.js.map} +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/init-Ccb5WXmw.js +4 -0
  8. package/dist/init-Ccb5WXmw.js.map +1 -0
  9. package/dist/panels/CollectionMapPanel.d.ts.map +1 -1
  10. package/dist/panels/overworld-map/OverworldMapPanel.d.ts.map +1 -1
  11. package/dist/panels/overworld-map/components/RepoSprite.d.ts +47 -0
  12. package/dist/panels/overworld-map/components/RepoSprite.d.ts.map +1 -0
  13. package/dist/panels/overworld-map/index.d.ts +3 -1
  14. package/dist/panels/overworld-map/index.d.ts.map +1 -1
  15. package/dist/panels.bundle.js +32 -31
  16. package/dist/webworkerAll-Ez5pUZRt.js +3 -0
  17. package/dist/webworkerAll-Ez5pUZRt.js.map +1 -0
  18. package/package.json +1 -1
  19. package/dist/BufferResource-DME1VWVJ.js +0 -593
  20. package/dist/BufferResource-DME1VWVJ.js.map +0 -1
  21. package/dist/CanvasRenderer-Md8Ayshs.js +0 -1525
  22. package/dist/CanvasRenderer-Md8Ayshs.js.map +0 -1
  23. package/dist/Filter-Bi2t_gmW.js +0 -81
  24. package/dist/Filter-Bi2t_gmW.js.map +0 -1
  25. package/dist/RenderTargetSystem-D98tiHim.js +0 -3046
  26. package/dist/RenderTargetSystem-D98tiHim.js.map +0 -1
  27. package/dist/WebGLRenderer-2YtxQhbh.js +0 -3884
  28. package/dist/WebGLRenderer-2YtxQhbh.js.map +0 -1
  29. package/dist/WebGPURenderer-kS6gO2Xc.js +0 -2142
  30. package/dist/WebGPURenderer-kS6gO2Xc.js.map +0 -1
  31. package/dist/browserAll-TZZf5l7B.js +0 -2687
  32. package/dist/browserAll-TZZf5l7B.js.map +0 -1
  33. package/dist/init-CfSmqCnm.js +0 -670
  34. package/dist/init-CfSmqCnm.js.map +0 -1
  35. package/dist/panels/overworld-map/spriteGenerator.d.ts +0 -53
  36. package/dist/panels/overworld-map/spriteGenerator.d.ts.map +0 -1
  37. package/dist/webworkerAll-TcJuZTza.js +0 -3
  38. package/dist/webworkerAll-TcJuZTza.js.map +0 -1
@@ -1,1525 +0,0 @@
1
- import { D as DOMAdapter, m as groupD8, C as Color, n as bgr2rgb, o as multiplyHexColors, M as Matrix, E as ExtensionType, p as Graphics, w as warn, c as Texture, q as generateTextureMatrix, s as shapeBuilders, r as buildLine, F as FillGradient, t as FillPattern, v as CanvasSource, A as AbstractRenderer, R as RendererType, f as extensions } from "./index-pPFTSf2O.js";
2
- import { R as RenderTargetSystem, S as SharedSystems, B as BlendModePipe, a as BatcherPipe, b as SpritePipe, c as RenderGroupPipe, A as AlphaMaskPipe, C as CustomRenderPipe } from "./RenderTargetSystem-D98tiHim.js";
3
- let canUseNewCanvasBlendModesValue;
4
- function createColoredCanvas(color) {
5
- const canvas = DOMAdapter.get().createCanvas(6, 1);
6
- const context = canvas.getContext("2d");
7
- context.fillStyle = color;
8
- context.fillRect(0, 0, 6, 1);
9
- return canvas;
10
- }
11
- function canUseNewCanvasBlendModes() {
12
- if (canUseNewCanvasBlendModesValue !== void 0) {
13
- return canUseNewCanvasBlendModesValue;
14
- }
15
- try {
16
- const magenta = createColoredCanvas("#ff00ff");
17
- const yellow = createColoredCanvas("#ffff00");
18
- const canvas = DOMAdapter.get().createCanvas(6, 1);
19
- const context = canvas.getContext("2d");
20
- context.globalCompositeOperation = "multiply";
21
- context.drawImage(magenta, 0, 0);
22
- context.drawImage(yellow, 2, 0);
23
- const imageData = context.getImageData(2, 0, 1, 1);
24
- if (!imageData) {
25
- canUseNewCanvasBlendModesValue = false;
26
- } else {
27
- const data = imageData.data;
28
- canUseNewCanvasBlendModesValue = data[0] === 255 && data[1] === 0 && data[2] === 0;
29
- }
30
- } catch (_error) {
31
- canUseNewCanvasBlendModesValue = false;
32
- }
33
- return canUseNewCanvasBlendModesValue;
34
- }
35
- const canvasUtils = {
36
- canvas: null,
37
- convertTintToImage: false,
38
- cacheStepsPerColorChannel: 8,
39
- canUseMultiply: canUseNewCanvasBlendModes(),
40
- tintMethod: null,
41
- _canvasSourceCache: /* @__PURE__ */ new WeakMap(),
42
- _unpremultipliedCache: /* @__PURE__ */ new WeakMap(),
43
- getCanvasSource: (texture) => {
44
- const source = texture.source;
45
- const resource = source == null ? void 0 : source.resource;
46
- if (!resource) {
47
- return null;
48
- }
49
- const isPMA = source.alphaMode === "premultiplied-alpha";
50
- const resourceWidth = source.resourceWidth ?? source.pixelWidth;
51
- const resourceHeight = source.resourceHeight ?? source.pixelHeight;
52
- const needsResize = resourceWidth !== source.pixelWidth || resourceHeight !== source.pixelHeight;
53
- if (isPMA) {
54
- if (resource instanceof HTMLCanvasElement || typeof OffscreenCanvas !== "undefined" && resource instanceof OffscreenCanvas) {
55
- if (!needsResize) {
56
- return resource;
57
- }
58
- }
59
- const cached = canvasUtils._unpremultipliedCache.get(source);
60
- if ((cached == null ? void 0 : cached.resourceId) === source._resourceId) {
61
- return cached.canvas;
62
- }
63
- }
64
- if (resource instanceof Uint8Array || resource instanceof Uint8ClampedArray || resource instanceof Int8Array || resource instanceof Uint16Array || resource instanceof Int16Array || resource instanceof Uint32Array || resource instanceof Int32Array || resource instanceof Float32Array || resource instanceof ArrayBuffer) {
65
- const cached = canvasUtils._canvasSourceCache.get(source);
66
- if ((cached == null ? void 0 : cached.resourceId) === source._resourceId) {
67
- return cached.canvas;
68
- }
69
- const canvas = DOMAdapter.get().createCanvas(source.pixelWidth, source.pixelHeight);
70
- const context = canvas.getContext("2d");
71
- const imageData = context.createImageData(source.pixelWidth, source.pixelHeight);
72
- const data = imageData.data;
73
- const bytes = resource instanceof ArrayBuffer ? new Uint8Array(resource) : new Uint8Array(resource.buffer, resource.byteOffset, resource.byteLength);
74
- if (source.format === "bgra8unorm") {
75
- for (let i = 0; i < data.length && i + 3 < bytes.length; i += 4) {
76
- data[i] = bytes[i + 2];
77
- data[i + 1] = bytes[i + 1];
78
- data[i + 2] = bytes[i];
79
- data[i + 3] = bytes[i + 3];
80
- }
81
- } else {
82
- data.set(bytes.subarray(0, data.length));
83
- }
84
- context.putImageData(imageData, 0, 0);
85
- canvasUtils._canvasSourceCache.set(source, { canvas, resourceId: source._resourceId });
86
- return canvas;
87
- }
88
- if (isPMA) {
89
- const canvas = DOMAdapter.get().createCanvas(source.pixelWidth, source.pixelHeight);
90
- const context = canvas.getContext("2d", { willReadFrequently: true });
91
- canvas.width = source.pixelWidth;
92
- canvas.height = source.pixelHeight;
93
- context.drawImage(resource, 0, 0);
94
- const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
95
- const data = imageData.data;
96
- for (let i = 0; i < data.length; i += 4) {
97
- const a = data[i + 3];
98
- if (a > 0) {
99
- const alphaInv = 255 / a;
100
- data[i] = Math.min(255, data[i] * alphaInv + 0.5);
101
- data[i + 1] = Math.min(255, data[i + 1] * alphaInv + 0.5);
102
- data[i + 2] = Math.min(255, data[i + 2] * alphaInv + 0.5);
103
- }
104
- }
105
- context.putImageData(imageData, 0, 0);
106
- canvasUtils._unpremultipliedCache.set(source, { canvas, resourceId: source._resourceId });
107
- return canvas;
108
- }
109
- if (needsResize) {
110
- const cached = canvasUtils._canvasSourceCache.get(source);
111
- if ((cached == null ? void 0 : cached.resourceId) === source._resourceId) {
112
- return cached.canvas;
113
- }
114
- const canvas = DOMAdapter.get().createCanvas(source.pixelWidth, source.pixelHeight);
115
- const context = canvas.getContext("2d");
116
- canvas.width = source.pixelWidth;
117
- canvas.height = source.pixelHeight;
118
- context.drawImage(resource, 0, 0);
119
- canvasUtils._canvasSourceCache.set(source, { canvas, resourceId: source._resourceId });
120
- return canvas;
121
- }
122
- return resource;
123
- },
124
- getTintedCanvas: (sprite, color) => {
125
- const texture = sprite.texture;
126
- const stringColor = Color.shared.setValue(color).toHex();
127
- const cache = texture.tintCache || (texture.tintCache = {});
128
- const cachedCanvas = cache[stringColor];
129
- const resourceId = texture.source._resourceId;
130
- if ((cachedCanvas == null ? void 0 : cachedCanvas.tintId) === resourceId) {
131
- return cachedCanvas;
132
- }
133
- const canvas = cachedCanvas && "getContext" in cachedCanvas ? cachedCanvas : DOMAdapter.get().createCanvas();
134
- canvasUtils.tintMethod(texture, color, canvas);
135
- canvas.tintId = resourceId;
136
- {
137
- cache[stringColor] = canvas;
138
- }
139
- return cache[stringColor];
140
- },
141
- getTintedPattern: (texture, color) => {
142
- const stringColor = Color.shared.setValue(color).toHex();
143
- const cache = texture.patternCache || (texture.patternCache = {});
144
- const resourceId = texture.source._resourceId;
145
- let pattern = cache[stringColor];
146
- if ((pattern == null ? void 0 : pattern.tintId) === resourceId) {
147
- return pattern;
148
- }
149
- if (!canvasUtils.canvas) {
150
- canvasUtils.canvas = DOMAdapter.get().createCanvas();
151
- }
152
- canvasUtils.tintMethod(texture, color, canvasUtils.canvas);
153
- const context = canvasUtils.canvas.getContext("2d");
154
- pattern = context.createPattern(canvasUtils.canvas, "repeat");
155
- pattern.tintId = resourceId;
156
- cache[stringColor] = pattern;
157
- return pattern;
158
- },
159
- /**
160
- * Applies a transform to a CanvasPattern.
161
- * @param pattern - The pattern to apply the transform to.
162
- * @param matrix - The matrix to apply.
163
- * @param matrix.a
164
- * @param matrix.b
165
- * @param matrix.c
166
- * @param matrix.d
167
- * @param matrix.tx
168
- * @param matrix.ty
169
- * @param invert
170
- */
171
- applyPatternTransform: (pattern, matrix, invert = true) => {
172
- if (!matrix) return;
173
- const patternAny = pattern;
174
- if (!patternAny.setTransform) return;
175
- const DOMMatrixCtor = globalThis.DOMMatrix;
176
- if (!DOMMatrixCtor) return;
177
- const domMatrix = new DOMMatrixCtor([matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty]);
178
- patternAny.setTransform(invert ? domMatrix.inverse() : domMatrix);
179
- },
180
- tintWithMultiply: (texture, color, canvas) => {
181
- const context = canvas.getContext("2d");
182
- const crop = texture.frame.clone();
183
- const resolution = texture.source._resolution ?? texture.source.resolution ?? 1;
184
- const rotate = texture.rotate;
185
- crop.x *= resolution;
186
- crop.y *= resolution;
187
- crop.width *= resolution;
188
- crop.height *= resolution;
189
- const isVertical = groupD8.isVertical(rotate);
190
- const outWidth = isVertical ? crop.height : crop.width;
191
- const outHeight = isVertical ? crop.width : crop.height;
192
- canvas.width = Math.ceil(outWidth);
193
- canvas.height = Math.ceil(outHeight);
194
- context.save();
195
- context.fillStyle = Color.shared.setValue(color).toHex();
196
- context.fillRect(0, 0, outWidth, outHeight);
197
- context.globalCompositeOperation = "multiply";
198
- const source = canvasUtils.getCanvasSource(texture);
199
- if (!source) {
200
- context.restore();
201
- return;
202
- }
203
- if (rotate) {
204
- canvasUtils._applyInverseRotation(context, rotate, crop.width, crop.height);
205
- }
206
- context.drawImage(
207
- source,
208
- crop.x,
209
- crop.y,
210
- crop.width,
211
- crop.height,
212
- 0,
213
- 0,
214
- crop.width,
215
- crop.height
216
- );
217
- context.globalCompositeOperation = "destination-atop";
218
- context.drawImage(
219
- source,
220
- crop.x,
221
- crop.y,
222
- crop.width,
223
- crop.height,
224
- 0,
225
- 0,
226
- crop.width,
227
- crop.height
228
- );
229
- context.restore();
230
- },
231
- tintWithOverlay: (texture, color, canvas) => {
232
- const context = canvas.getContext("2d");
233
- const crop = texture.frame.clone();
234
- const resolution = texture.source._resolution ?? texture.source.resolution ?? 1;
235
- const rotate = texture.rotate;
236
- crop.x *= resolution;
237
- crop.y *= resolution;
238
- crop.width *= resolution;
239
- crop.height *= resolution;
240
- const isVertical = groupD8.isVertical(rotate);
241
- const outWidth = isVertical ? crop.height : crop.width;
242
- const outHeight = isVertical ? crop.width : crop.height;
243
- canvas.width = Math.ceil(outWidth);
244
- canvas.height = Math.ceil(outHeight);
245
- context.save();
246
- context.globalCompositeOperation = "copy";
247
- context.fillStyle = Color.shared.setValue(color).toHex();
248
- context.fillRect(0, 0, outWidth, outHeight);
249
- context.globalCompositeOperation = "destination-atop";
250
- const source = canvasUtils.getCanvasSource(texture);
251
- if (!source) {
252
- context.restore();
253
- return;
254
- }
255
- if (rotate) {
256
- canvasUtils._applyInverseRotation(context, rotate, crop.width, crop.height);
257
- }
258
- context.drawImage(
259
- source,
260
- crop.x,
261
- crop.y,
262
- crop.width,
263
- crop.height,
264
- 0,
265
- 0,
266
- crop.width,
267
- crop.height
268
- );
269
- context.restore();
270
- },
271
- tintWithPerPixel: (texture, color, canvas) => {
272
- const context = canvas.getContext("2d");
273
- const crop = texture.frame.clone();
274
- const resolution = texture.source._resolution ?? texture.source.resolution ?? 1;
275
- const rotate = texture.rotate;
276
- crop.x *= resolution;
277
- crop.y *= resolution;
278
- crop.width *= resolution;
279
- crop.height *= resolution;
280
- const isVertical = groupD8.isVertical(rotate);
281
- const outWidth = isVertical ? crop.height : crop.width;
282
- const outHeight = isVertical ? crop.width : crop.height;
283
- canvas.width = Math.ceil(outWidth);
284
- canvas.height = Math.ceil(outHeight);
285
- context.save();
286
- context.globalCompositeOperation = "copy";
287
- const source = canvasUtils.getCanvasSource(texture);
288
- if (!source) {
289
- context.restore();
290
- return;
291
- }
292
- if (rotate) {
293
- canvasUtils._applyInverseRotation(context, rotate, crop.width, crop.height);
294
- }
295
- context.drawImage(
296
- source,
297
- crop.x,
298
- crop.y,
299
- crop.width,
300
- crop.height,
301
- 0,
302
- 0,
303
- crop.width,
304
- crop.height
305
- );
306
- context.restore();
307
- const r = color >> 16 & 255;
308
- const g = color >> 8 & 255;
309
- const b = color & 255;
310
- const imageData = context.getImageData(0, 0, outWidth, outHeight);
311
- const data = imageData.data;
312
- for (let i = 0; i < data.length; i += 4) {
313
- data[i] = data[i] * r / 255;
314
- data[i + 1] = data[i + 1] * g / 255;
315
- data[i + 2] = data[i + 2] * b / 255;
316
- }
317
- context.putImageData(imageData, 0, 0);
318
- },
319
- /**
320
- * Applies inverse rotation transform to context for texture packer rotation compensation.
321
- * Supports all 16 groupD8 symmetries (rotations and reflections).
322
- * @param context - Canvas 2D context
323
- * @param rotate - The groupD8 rotation value
324
- * @param srcWidth - Source crop width (before rotation)
325
- * @param srcHeight - Source crop height (before rotation)
326
- */
327
- _applyInverseRotation: (context, rotate, srcWidth, srcHeight) => {
328
- const inv = groupD8.inv(rotate);
329
- const a = groupD8.uX(inv);
330
- const b = groupD8.uY(inv);
331
- const c = groupD8.vX(inv);
332
- const d = groupD8.vY(inv);
333
- const tx = -Math.min(0, a * srcWidth, c * srcHeight, a * srcWidth + c * srcHeight);
334
- const ty = -Math.min(0, b * srcWidth, d * srcHeight, b * srcWidth + d * srcHeight);
335
- context.transform(a, b, c, d, tx, ty);
336
- }
337
- };
338
- canvasUtils.tintMethod = canvasUtils.canUseMultiply ? canvasUtils.tintWithMultiply : canvasUtils.tintWithPerPixel;
339
- const _CanvasBatchAdaptor = class _CanvasBatchAdaptor2 {
340
- static _getPatternRepeat(addressModeU, addressModeV) {
341
- const repeatU = addressModeU && addressModeU !== "clamp-to-edge";
342
- const repeatV = addressModeV && addressModeV !== "clamp-to-edge";
343
- if (repeatU && repeatV) return "repeat";
344
- if (repeatU) return "repeat-x";
345
- if (repeatV) return "repeat-y";
346
- return "no-repeat";
347
- }
348
- start(batchPipe, geometry, shader) {
349
- }
350
- execute(batchPipe, batch) {
351
- var _a, _b, _c, _d;
352
- const elements = batch.elements;
353
- if (!elements || !elements.length) return;
354
- const renderer = batchPipe.renderer;
355
- const contextSystem = renderer.canvasContext;
356
- const context = contextSystem.activeContext;
357
- for (let i = 0; i < elements.length; i++) {
358
- const element = elements[i];
359
- if (!element.packAsQuad) continue;
360
- const quad = element;
361
- const texture = quad.texture;
362
- const source = texture ? canvasUtils.getCanvasSource(texture) : null;
363
- if (!source) continue;
364
- const textureStyle = texture.source.style;
365
- const smoothProperty = contextSystem.smoothProperty;
366
- const shouldSmooth = textureStyle.scaleMode !== "nearest";
367
- if (context[smoothProperty] !== shouldSmooth) {
368
- context[smoothProperty] = shouldSmooth;
369
- }
370
- contextSystem.setBlendMode(batch.blendMode);
371
- const globalColor = ((_a = renderer.globalUniforms.globalUniformData) == null ? void 0 : _a.worldColor) ?? 4294967295;
372
- const argb = quad.color;
373
- const globalAlpha = (globalColor >>> 24 & 255) / 255;
374
- const quadAlpha = (argb >>> 24 & 255) / 255;
375
- const filterAlpha = ((_b = renderer.filter) == null ? void 0 : _b.alphaMultiplier) ?? 1;
376
- const alpha = globalAlpha * quadAlpha * filterAlpha;
377
- if (alpha <= 0) continue;
378
- context.globalAlpha = alpha;
379
- const globalTint = globalColor & 16777215;
380
- const quadTint = argb & 16777215;
381
- const tint = bgr2rgb(multiplyHexColors(quadTint, globalTint));
382
- const frame = texture.frame;
383
- const repeatU = textureStyle.addressModeU ?? textureStyle.addressMode;
384
- const repeatV = textureStyle.addressModeV ?? textureStyle.addressMode;
385
- const repeat = _CanvasBatchAdaptor2._getPatternRepeat(repeatU, repeatV);
386
- const resolution = texture.source._resolution ?? texture.source.resolution ?? 1;
387
- const isFromCachedRenderGroup = (_d = (_c = quad.renderable) == null ? void 0 : _c.renderGroup) == null ? void 0 : _d.isCachedAsTexture;
388
- const sx = frame.x * resolution;
389
- const sy = frame.y * resolution;
390
- const sw = frame.width * resolution;
391
- const sh = frame.height * resolution;
392
- const bounds = quad.bounds;
393
- const isRootTarget = renderer.renderTarget.renderTarget.isRoot;
394
- const dx = bounds.minX;
395
- const dy = bounds.minY;
396
- const dw = bounds.maxX - bounds.minX;
397
- const dh = bounds.maxY - bounds.minY;
398
- const rotate = texture.rotate;
399
- const uvs = texture.uvs;
400
- const uvMin = Math.min(uvs.x0, uvs.x1, uvs.x2, uvs.x3, uvs.y0, uvs.y1, uvs.y2, uvs.y3);
401
- const uvMax = Math.max(uvs.x0, uvs.x1, uvs.x2, uvs.x3, uvs.y0, uvs.y1, uvs.y2, uvs.y3);
402
- const needsRepeat = repeat !== "no-repeat" && (uvMin < 0 || uvMax > 1);
403
- const willUseProcessedCanvas = !needsRepeat && (tint !== 16777215 || rotate);
404
- const applyRotateTransform = rotate && !willUseProcessedCanvas;
405
- if (applyRotateTransform) {
406
- _CanvasBatchAdaptor2._tempPatternMatrix.copyFrom(quad.transform);
407
- groupD8.matrixAppendRotationInv(
408
- _CanvasBatchAdaptor2._tempPatternMatrix,
409
- rotate,
410
- dx,
411
- dy,
412
- dw,
413
- dh
414
- );
415
- contextSystem.setContextTransform(
416
- _CanvasBatchAdaptor2._tempPatternMatrix,
417
- quad.roundPixels === 1,
418
- void 0,
419
- isFromCachedRenderGroup && isRootTarget
420
- );
421
- } else {
422
- contextSystem.setContextTransform(
423
- quad.transform,
424
- quad.roundPixels === 1,
425
- void 0,
426
- isFromCachedRenderGroup && isRootTarget
427
- );
428
- }
429
- const drawX = applyRotateTransform ? 0 : dx;
430
- const drawY = applyRotateTransform ? 0 : dy;
431
- const drawW = dw;
432
- const drawH = dh;
433
- if (needsRepeat) {
434
- let patternSource = source;
435
- const canTint = tint !== 16777215 && !rotate;
436
- const fitsFrame = frame.width <= texture.source.width && frame.height <= texture.source.height;
437
- if (canTint && fitsFrame) {
438
- patternSource = canvasUtils.getTintedCanvas({ texture }, tint);
439
- }
440
- const pattern = context.createPattern(patternSource, repeat);
441
- if (!pattern) continue;
442
- const denomX = drawW;
443
- const denomY = drawH;
444
- if (denomX === 0 || denomY === 0) continue;
445
- const invDx = 1 / denomX;
446
- const invDy = 1 / denomY;
447
- const a = (uvs.x1 - uvs.x0) * invDx;
448
- const b = (uvs.y1 - uvs.y0) * invDx;
449
- const c = (uvs.x3 - uvs.x0) * invDy;
450
- const d = (uvs.y3 - uvs.y0) * invDy;
451
- const tx = uvs.x0 - a * drawX - c * drawY;
452
- const ty = uvs.y0 - b * drawX - d * drawY;
453
- const pixelWidth = texture.source.pixelWidth;
454
- const pixelHeight = texture.source.pixelHeight;
455
- _CanvasBatchAdaptor2._tempPatternMatrix.set(
456
- a * pixelWidth,
457
- b * pixelHeight,
458
- c * pixelWidth,
459
- d * pixelHeight,
460
- tx * pixelWidth,
461
- ty * pixelHeight
462
- );
463
- canvasUtils.applyPatternTransform(pattern, _CanvasBatchAdaptor2._tempPatternMatrix);
464
- context.fillStyle = pattern;
465
- context.fillRect(drawX, drawY, drawW, drawH);
466
- } else {
467
- const needsProcessing = tint !== 16777215 || rotate;
468
- const processedSource = needsProcessing ? canvasUtils.getTintedCanvas({ texture }, tint) : source;
469
- const isProcessed = processedSource !== source;
470
- context.drawImage(
471
- processedSource,
472
- isProcessed ? 0 : sx,
473
- isProcessed ? 0 : sy,
474
- isProcessed ? processedSource.width : sw,
475
- isProcessed ? processedSource.height : sh,
476
- drawX,
477
- drawY,
478
- drawW,
479
- drawH
480
- );
481
- }
482
- }
483
- }
484
- };
485
- _CanvasBatchAdaptor._tempPatternMatrix = new Matrix();
486
- _CanvasBatchAdaptor.extension = {
487
- type: [
488
- ExtensionType.CanvasPipesAdaptor
489
- ],
490
- name: "batch"
491
- };
492
- let CanvasBatchAdaptor = _CanvasBatchAdaptor;
493
- class CanvasColorMaskPipe {
494
- constructor(renderer) {
495
- this._colorStack = [];
496
- this._colorStackIndex = 0;
497
- this._currentColor = 0;
498
- this._renderer = renderer;
499
- }
500
- buildStart() {
501
- this._colorStack[0] = 15;
502
- this._colorStackIndex = 1;
503
- this._currentColor = 15;
504
- }
505
- push(mask, _container, instructionSet) {
506
- this._renderer.renderPipes.batch.break(instructionSet);
507
- const colorStack = this._colorStack;
508
- colorStack[this._colorStackIndex] = colorStack[this._colorStackIndex - 1] & mask.mask;
509
- const currentColor = this._colorStack[this._colorStackIndex];
510
- if (currentColor !== this._currentColor) {
511
- this._currentColor = currentColor;
512
- instructionSet.add({
513
- renderPipeId: "colorMask",
514
- colorMask: currentColor,
515
- canBundle: false
516
- });
517
- }
518
- this._colorStackIndex++;
519
- }
520
- pop(_mask, _container, instructionSet) {
521
- this._renderer.renderPipes.batch.break(instructionSet);
522
- const colorStack = this._colorStack;
523
- this._colorStackIndex--;
524
- const currentColor = colorStack[this._colorStackIndex - 1];
525
- if (currentColor !== this._currentColor) {
526
- this._currentColor = currentColor;
527
- instructionSet.add({
528
- renderPipeId: "colorMask",
529
- colorMask: currentColor,
530
- canBundle: false
531
- });
532
- }
533
- }
534
- execute(_instruction) {
535
- }
536
- destroy() {
537
- this._renderer = null;
538
- this._colorStack = null;
539
- }
540
- }
541
- CanvasColorMaskPipe.extension = {
542
- type: [
543
- ExtensionType.CanvasPipes
544
- ],
545
- name: "colorMask"
546
- };
547
- function buildRoundedRectPath$1(context, x, y, width, height, radius) {
548
- radius = Math.max(0, Math.min(radius, Math.min(width, height) / 2));
549
- context.moveTo(x + radius, y);
550
- context.lineTo(x + width - radius, y);
551
- context.quadraticCurveTo(x + width, y, x + width, y + radius);
552
- context.lineTo(x + width, y + height - radius);
553
- context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
554
- context.lineTo(x + radius, y + height);
555
- context.quadraticCurveTo(x, y + height, x, y + height - radius);
556
- context.lineTo(x, y + radius);
557
- context.quadraticCurveTo(x, y, x + radius, y);
558
- }
559
- function buildShapePath$1(context, shape) {
560
- switch (shape.type) {
561
- case "rectangle": {
562
- const rect = shape;
563
- context.rect(rect.x, rect.y, rect.width, rect.height);
564
- break;
565
- }
566
- case "roundedRectangle": {
567
- const rect = shape;
568
- buildRoundedRectPath$1(context, rect.x, rect.y, rect.width, rect.height, rect.radius);
569
- break;
570
- }
571
- case "circle": {
572
- const circle = shape;
573
- context.moveTo(circle.x + circle.radius, circle.y);
574
- context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2);
575
- break;
576
- }
577
- case "ellipse": {
578
- const ellipse = shape;
579
- if (context.ellipse) {
580
- context.moveTo(ellipse.x + ellipse.halfWidth, ellipse.y);
581
- context.ellipse(ellipse.x, ellipse.y, ellipse.halfWidth, ellipse.halfHeight, 0, 0, Math.PI * 2);
582
- } else {
583
- context.save();
584
- context.translate(ellipse.x, ellipse.y);
585
- context.scale(ellipse.halfWidth, ellipse.halfHeight);
586
- context.moveTo(1, 0);
587
- context.arc(0, 0, 1, 0, Math.PI * 2);
588
- context.restore();
589
- }
590
- break;
591
- }
592
- case "triangle": {
593
- const tri = shape;
594
- context.moveTo(tri.x, tri.y);
595
- context.lineTo(tri.x2, tri.y2);
596
- context.lineTo(tri.x3, tri.y3);
597
- context.closePath();
598
- break;
599
- }
600
- case "polygon":
601
- default: {
602
- const poly = shape;
603
- const points = poly.points;
604
- if (!(points == null ? void 0 : points.length)) break;
605
- context.moveTo(points[0], points[1]);
606
- for (let i = 2; i < points.length; i += 2) {
607
- context.lineTo(points[i], points[i + 1]);
608
- }
609
- if (poly.closePath) {
610
- context.closePath();
611
- }
612
- break;
613
- }
614
- }
615
- }
616
- function addHolePaths$1(context, holes) {
617
- if (!(holes == null ? void 0 : holes.length)) return false;
618
- for (let i = 0; i < holes.length; i++) {
619
- const hole = holes[i];
620
- if (!(hole == null ? void 0 : hole.shape)) continue;
621
- const transform = hole.transform;
622
- const hasTransform = transform && !transform.isIdentity();
623
- if (hasTransform) {
624
- context.save();
625
- context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty);
626
- }
627
- buildShapePath$1(context, hole.shape);
628
- if (hasTransform) {
629
- context.restore();
630
- }
631
- }
632
- return true;
633
- }
634
- class CanvasStencilMaskPipe {
635
- constructor(renderer) {
636
- this._warnedMaskTypes = /* @__PURE__ */ new Set();
637
- this._canvasMaskStack = [];
638
- this._renderer = renderer;
639
- }
640
- push(mask, _container, instructionSet) {
641
- this._renderer.renderPipes.batch.break(instructionSet);
642
- instructionSet.add({
643
- renderPipeId: "stencilMask",
644
- action: "pushMaskBegin",
645
- mask,
646
- inverse: _container._maskOptions.inverse,
647
- canBundle: false
648
- });
649
- }
650
- pop(_mask, _container, instructionSet) {
651
- this._renderer.renderPipes.batch.break(instructionSet);
652
- instructionSet.add({
653
- renderPipeId: "stencilMask",
654
- action: "popMaskEnd",
655
- mask: _mask,
656
- inverse: _container._maskOptions.inverse,
657
- canBundle: false
658
- });
659
- }
660
- execute(instruction) {
661
- var _a, _b, _c;
662
- if (instruction.action !== "pushMaskBegin" && instruction.action !== "popMaskEnd") {
663
- return;
664
- }
665
- const canvasRenderer = this._renderer;
666
- const contextSystem = canvasRenderer.canvasContext;
667
- const context = contextSystem == null ? void 0 : contextSystem.activeContext;
668
- if (!context) return;
669
- if (instruction.action === "popMaskEnd") {
670
- const didClip = this._canvasMaskStack.pop();
671
- if (didClip) {
672
- context.restore();
673
- }
674
- return;
675
- }
676
- if (instruction.inverse) {
677
- this._warnOnce(
678
- "inverse",
679
- "CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag."
680
- );
681
- }
682
- const maskContainer = instruction.mask.mask;
683
- if (!(maskContainer instanceof Graphics)) {
684
- this._warnOnce(
685
- "nonGraphics",
686
- "CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."
687
- );
688
- this._canvasMaskStack.push(false);
689
- return;
690
- }
691
- const graphics = maskContainer;
692
- const instructions = (_a = graphics.context) == null ? void 0 : _a.instructions;
693
- if (!(instructions == null ? void 0 : instructions.length)) {
694
- this._canvasMaskStack.push(false);
695
- return;
696
- }
697
- context.save();
698
- contextSystem.setContextTransform(
699
- graphics.groupTransform,
700
- (canvasRenderer._roundPixels | graphics._roundPixels) === 1
701
- );
702
- context.beginPath();
703
- let drewPath = false;
704
- let hasHoles = false;
705
- for (let i = 0; i < instructions.length; i++) {
706
- const instructionData = instructions[i];
707
- const action = instructionData.action;
708
- if (action !== "fill" && action !== "stroke") continue;
709
- const data = instructionData.data;
710
- const shapePath = (_b = data == null ? void 0 : data.path) == null ? void 0 : _b.shapePath;
711
- if (!((_c = shapePath == null ? void 0 : shapePath.shapePrimitives) == null ? void 0 : _c.length)) continue;
712
- const shapePrimitives = shapePath.shapePrimitives;
713
- for (let j = 0; j < shapePrimitives.length; j++) {
714
- const primitive = shapePrimitives[j];
715
- if (!(primitive == null ? void 0 : primitive.shape)) continue;
716
- const transform = primitive.transform;
717
- const hasTransform = transform && !transform.isIdentity();
718
- if (hasTransform) {
719
- context.save();
720
- context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty);
721
- }
722
- buildShapePath$1(context, primitive.shape);
723
- hasHoles = addHolePaths$1(context, primitive.holes) || hasHoles;
724
- drewPath = true;
725
- if (hasTransform) {
726
- context.restore();
727
- }
728
- }
729
- }
730
- if (!drewPath) {
731
- context.restore();
732
- this._canvasMaskStack.push(false);
733
- return;
734
- }
735
- if (hasHoles) {
736
- context.clip("evenodd");
737
- } else {
738
- context.clip();
739
- }
740
- this._canvasMaskStack.push(true);
741
- }
742
- destroy() {
743
- this._renderer = null;
744
- this._warnedMaskTypes = null;
745
- this._canvasMaskStack = null;
746
- }
747
- _warnOnce(key, message) {
748
- if (this._warnedMaskTypes.has(key)) return;
749
- this._warnedMaskTypes.add(key);
750
- warn(message);
751
- }
752
- }
753
- CanvasStencilMaskPipe.extension = {
754
- type: [
755
- ExtensionType.CanvasPipes
756
- ],
757
- name: "stencilMask"
758
- };
759
- const FALLBACK_BLEND = "source-over";
760
- function mapCanvasBlendModesToPixi() {
761
- const supportsAdvanced = canUseNewCanvasBlendModes();
762
- const map = /* @__PURE__ */ Object.create(null);
763
- map.inherit = FALLBACK_BLEND;
764
- map.none = FALLBACK_BLEND;
765
- map.normal = "source-over";
766
- map.add = "lighter";
767
- map.multiply = supportsAdvanced ? "multiply" : FALLBACK_BLEND;
768
- map.screen = supportsAdvanced ? "screen" : FALLBACK_BLEND;
769
- map.overlay = supportsAdvanced ? "overlay" : FALLBACK_BLEND;
770
- map.darken = supportsAdvanced ? "darken" : FALLBACK_BLEND;
771
- map.lighten = supportsAdvanced ? "lighten" : FALLBACK_BLEND;
772
- map["color-dodge"] = supportsAdvanced ? "color-dodge" : FALLBACK_BLEND;
773
- map["color-burn"] = supportsAdvanced ? "color-burn" : FALLBACK_BLEND;
774
- map["hard-light"] = supportsAdvanced ? "hard-light" : FALLBACK_BLEND;
775
- map["soft-light"] = supportsAdvanced ? "soft-light" : FALLBACK_BLEND;
776
- map.difference = supportsAdvanced ? "difference" : FALLBACK_BLEND;
777
- map.exclusion = supportsAdvanced ? "exclusion" : FALLBACK_BLEND;
778
- map.saturation = supportsAdvanced ? "saturation" : FALLBACK_BLEND;
779
- map.color = supportsAdvanced ? "color" : FALLBACK_BLEND;
780
- map.luminosity = supportsAdvanced ? "luminosity" : FALLBACK_BLEND;
781
- map["linear-burn"] = supportsAdvanced ? "color-burn" : FALLBACK_BLEND;
782
- map["linear-dodge"] = supportsAdvanced ? "color-dodge" : FALLBACK_BLEND;
783
- map["linear-light"] = supportsAdvanced ? "hard-light" : FALLBACK_BLEND;
784
- map["pin-light"] = supportsAdvanced ? "hard-light" : FALLBACK_BLEND;
785
- map["vivid-light"] = supportsAdvanced ? "hard-light" : FALLBACK_BLEND;
786
- map["hard-mix"] = FALLBACK_BLEND;
787
- map.negation = supportsAdvanced ? "difference" : FALLBACK_BLEND;
788
- map["normal-npm"] = map.normal;
789
- map["add-npm"] = map.add;
790
- map["screen-npm"] = map.screen;
791
- map.erase = "destination-out";
792
- map.subtract = FALLBACK_BLEND;
793
- map.divide = FALLBACK_BLEND;
794
- map.min = FALLBACK_BLEND;
795
- map.max = FALLBACK_BLEND;
796
- return map;
797
- }
798
- const tempMatrix$1 = new Matrix();
799
- class CanvasContextSystem {
800
- /**
801
- * @param renderer - The owning CanvasRenderer.
802
- */
803
- constructor(renderer) {
804
- this.activeResolution = 1;
805
- this.smoothProperty = "imageSmoothingEnabled";
806
- this.blendModes = mapCanvasBlendModesToPixi();
807
- this._activeBlendMode = "normal";
808
- this._projTransform = null;
809
- this._outerBlend = false;
810
- this._warnedBlendModes = /* @__PURE__ */ new Set();
811
- this._renderer = renderer;
812
- }
813
- resolutionChange(resolution) {
814
- this.activeResolution = resolution;
815
- }
816
- /** Initializes the root context and smoothing flag selection. */
817
- init() {
818
- const alpha = this._renderer.background.alpha < 1;
819
- this.rootContext = this._renderer.canvas.getContext(
820
- "2d",
821
- { alpha }
822
- );
823
- this.activeContext = this.rootContext;
824
- this.activeResolution = this._renderer.resolution;
825
- if (!this.rootContext.imageSmoothingEnabled) {
826
- const rc = this.rootContext;
827
- if (rc.webkitImageSmoothingEnabled) {
828
- this.smoothProperty = "webkitImageSmoothingEnabled";
829
- } else if (rc.mozImageSmoothingEnabled) {
830
- this.smoothProperty = "mozImageSmoothingEnabled";
831
- } else if (rc.oImageSmoothingEnabled) {
832
- this.smoothProperty = "oImageSmoothingEnabled";
833
- } else if (rc.msImageSmoothingEnabled) {
834
- this.smoothProperty = "msImageSmoothingEnabled";
835
- }
836
- }
837
- }
838
- /**
839
- * Sets the current transform on the active context.
840
- * @param transform - Transform to apply.
841
- * @param roundPixels - Whether to round translation to integers.
842
- * @param localResolution - Optional local resolution multiplier.
843
- * @param skipGlobalTransform - If true, skip applying the global world transform matrix.
844
- */
845
- setContextTransform(transform, roundPixels, localResolution, skipGlobalTransform) {
846
- var _a;
847
- const globalTransform = skipGlobalTransform ? Matrix.IDENTITY : ((_a = this._renderer.globalUniforms.globalUniformData) == null ? void 0 : _a.worldTransformMatrix) || Matrix.IDENTITY;
848
- let mat = tempMatrix$1;
849
- mat.copyFrom(globalTransform);
850
- mat.append(transform);
851
- const proj = this._projTransform;
852
- const contextResolution = this.activeResolution;
853
- localResolution = localResolution || contextResolution;
854
- if (proj) {
855
- const finalMat = Matrix.shared;
856
- finalMat.copyFrom(mat);
857
- finalMat.prepend(proj);
858
- mat = finalMat;
859
- }
860
- if (roundPixels) {
861
- this.activeContext.setTransform(
862
- mat.a * localResolution,
863
- mat.b * localResolution,
864
- mat.c * localResolution,
865
- mat.d * localResolution,
866
- mat.tx * contextResolution | 0,
867
- mat.ty * contextResolution | 0
868
- );
869
- } else {
870
- this.activeContext.setTransform(
871
- mat.a * localResolution,
872
- mat.b * localResolution,
873
- mat.c * localResolution,
874
- mat.d * localResolution,
875
- mat.tx * contextResolution,
876
- mat.ty * contextResolution
877
- );
878
- }
879
- }
880
- /**
881
- * Clears the current render target, optionally filling with a color.
882
- * @param clearColor - Color to fill after clearing.
883
- * @param alpha - Alpha override for the clear color.
884
- */
885
- clear(clearColor, alpha) {
886
- const context = this.activeContext;
887
- const renderer = this._renderer;
888
- context.clearRect(0, 0, renderer.width, renderer.height);
889
- if (clearColor) {
890
- const color = Color.shared.setValue(clearColor);
891
- context.globalAlpha = alpha ?? color.alpha;
892
- context.fillStyle = color.toHex();
893
- context.fillRect(0, 0, renderer.width, renderer.height);
894
- context.globalAlpha = 1;
895
- }
896
- }
897
- /**
898
- * Sets the active blend mode.
899
- * @param blendMode - Pixi blend mode.
900
- */
901
- setBlendMode(blendMode) {
902
- if (this._activeBlendMode === blendMode) return;
903
- this._activeBlendMode = blendMode;
904
- this._outerBlend = false;
905
- const mappedBlend = this.blendModes[blendMode];
906
- if (!mappedBlend) {
907
- if (!this._warnedBlendModes.has(blendMode)) {
908
- console.warn(
909
- `CanvasRenderer: blend mode "${blendMode}" is not supported in Canvas2D; falling back to "source-over".`
910
- );
911
- this._warnedBlendModes.add(blendMode);
912
- }
913
- this.activeContext.globalCompositeOperation = "source-over";
914
- return;
915
- }
916
- this.activeContext.globalCompositeOperation = mappedBlend;
917
- }
918
- /** Releases context references. */
919
- destroy() {
920
- this.rootContext = null;
921
- this.activeContext = null;
922
- this._warnedBlendModes.clear();
923
- }
924
- }
925
- CanvasContextSystem.extension = {
926
- type: [
927
- ExtensionType.CanvasSystem
928
- ],
929
- name: "canvasContext"
930
- };
931
- class CanvasLimitsSystem {
932
- constructor() {
933
- this.maxTextures = 16;
934
- this.maxBatchableTextures = 16;
935
- this.maxUniformBindings = 0;
936
- }
937
- init() {
938
- }
939
- }
940
- CanvasLimitsSystem.extension = {
941
- type: [
942
- ExtensionType.CanvasSystem
943
- ],
944
- name: "limits"
945
- };
946
- const emptyCanvasStyle = "#808080";
947
- const tempMatrix = new Matrix();
948
- const tempTextureMatrix = new Matrix();
949
- const tempGradientMatrix = new Matrix();
950
- const tempPatternMatrix = new Matrix();
951
- function fillTriangles(context, vertices, indices) {
952
- context.beginPath();
953
- for (let i = 0; i < indices.length; i += 3) {
954
- const i0 = indices[i] * 2;
955
- const i1 = indices[i + 1] * 2;
956
- const i2 = indices[i + 2] * 2;
957
- context.moveTo(vertices[i0], vertices[i0 + 1]);
958
- context.lineTo(vertices[i1], vertices[i1 + 1]);
959
- context.lineTo(vertices[i2], vertices[i2 + 1]);
960
- context.closePath();
961
- }
962
- context.fill();
963
- }
964
- function colorToHex(color) {
965
- const clamped = color & 16777215;
966
- return `#${clamped.toString(16).padStart(6, "0")}`;
967
- }
968
- function buildRoundedRectPath(context, x, y, width, height, radius) {
969
- radius = Math.max(0, Math.min(radius, Math.min(width, height) / 2));
970
- context.moveTo(x + radius, y);
971
- context.lineTo(x + width - radius, y);
972
- context.quadraticCurveTo(x + width, y, x + width, y + radius);
973
- context.lineTo(x + width, y + height - radius);
974
- context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
975
- context.lineTo(x + radius, y + height);
976
- context.quadraticCurveTo(x, y + height, x, y + height - radius);
977
- context.lineTo(x, y + radius);
978
- context.quadraticCurveTo(x, y, x + radius, y);
979
- }
980
- function buildShapePath(context, shape) {
981
- switch (shape.type) {
982
- case "rectangle": {
983
- const rect = shape;
984
- context.rect(rect.x, rect.y, rect.width, rect.height);
985
- break;
986
- }
987
- case "roundedRectangle": {
988
- const rect = shape;
989
- buildRoundedRectPath(context, rect.x, rect.y, rect.width, rect.height, rect.radius);
990
- break;
991
- }
992
- case "circle": {
993
- const circle = shape;
994
- context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2);
995
- break;
996
- }
997
- case "ellipse": {
998
- const ellipse = shape;
999
- if (context.ellipse) {
1000
- context.ellipse(ellipse.x, ellipse.y, ellipse.halfWidth, ellipse.halfHeight, 0, 0, Math.PI * 2);
1001
- } else {
1002
- context.save();
1003
- context.translate(ellipse.x, ellipse.y);
1004
- context.scale(ellipse.halfWidth, ellipse.halfHeight);
1005
- context.arc(0, 0, 1, 0, Math.PI * 2);
1006
- context.restore();
1007
- }
1008
- break;
1009
- }
1010
- case "triangle": {
1011
- const tri = shape;
1012
- context.moveTo(tri.x, tri.y);
1013
- context.lineTo(tri.x2, tri.y2);
1014
- context.lineTo(tri.x3, tri.y3);
1015
- context.closePath();
1016
- break;
1017
- }
1018
- case "polygon":
1019
- default: {
1020
- const poly = shape;
1021
- const points = poly.points;
1022
- if (!(points == null ? void 0 : points.length)) break;
1023
- context.moveTo(points[0], points[1]);
1024
- for (let i = 2; i < points.length; i += 2) {
1025
- context.lineTo(points[i], points[i + 1]);
1026
- }
1027
- if (poly.closePath) {
1028
- context.closePath();
1029
- }
1030
- break;
1031
- }
1032
- }
1033
- }
1034
- function addHolePaths(context, holes) {
1035
- if (!(holes == null ? void 0 : holes.length)) return false;
1036
- for (let i = 0; i < holes.length; i++) {
1037
- const hole = holes[i];
1038
- if (!(hole == null ? void 0 : hole.shape)) continue;
1039
- const transform = hole.transform;
1040
- const hasTransform = transform && !transform.isIdentity();
1041
- if (hasTransform) {
1042
- context.save();
1043
- context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty);
1044
- }
1045
- buildShapePath(context, hole.shape);
1046
- if (hasTransform) {
1047
- context.restore();
1048
- }
1049
- }
1050
- return true;
1051
- }
1052
- function getCanvasStyle(style, tint, textureMatrix, currentTransform) {
1053
- const fill = style.fill;
1054
- if (fill instanceof FillGradient) {
1055
- fill.buildGradient();
1056
- const gradientTexture = fill.texture;
1057
- if (gradientTexture) {
1058
- const pattern = canvasUtils.getTintedPattern(gradientTexture, tint);
1059
- const patternMatrix = textureMatrix ? tempPatternMatrix.copyFrom(textureMatrix).scale(gradientTexture.source.pixelWidth, gradientTexture.source.pixelHeight) : tempPatternMatrix.copyFrom(fill.transform);
1060
- if (currentTransform && !style.textureSpace) {
1061
- patternMatrix.append(currentTransform);
1062
- }
1063
- canvasUtils.applyPatternTransform(pattern, patternMatrix);
1064
- return pattern;
1065
- }
1066
- }
1067
- if (fill instanceof FillPattern) {
1068
- const pattern = canvasUtils.getTintedPattern(fill.texture, tint);
1069
- canvasUtils.applyPatternTransform(pattern, fill.transform);
1070
- return pattern;
1071
- }
1072
- const texture = style.texture;
1073
- if (texture && texture !== Texture.WHITE) {
1074
- if (!texture.source.resource) {
1075
- return emptyCanvasStyle;
1076
- }
1077
- const pattern = canvasUtils.getTintedPattern(texture, tint);
1078
- const patternMatrix = textureMatrix ? tempPatternMatrix.copyFrom(textureMatrix).scale(texture.source.pixelWidth, texture.source.pixelHeight) : style.matrix;
1079
- canvasUtils.applyPatternTransform(pattern, patternMatrix);
1080
- return pattern;
1081
- }
1082
- return colorToHex(tint);
1083
- }
1084
- class CanvasGraphicsAdaptor {
1085
- constructor() {
1086
- this.shader = null;
1087
- }
1088
- contextChange(renderer) {
1089
- }
1090
- execute(graphicsPipe, renderable) {
1091
- var _a, _b, _c, _d, _e, _f, _g;
1092
- const renderer = graphicsPipe.renderer;
1093
- const contextSystem = renderer.canvasContext;
1094
- const context = contextSystem.activeContext;
1095
- const baseTransform = renderable.groupTransform;
1096
- const globalColor = ((_a = renderer.globalUniforms.globalUniformData) == null ? void 0 : _a.worldColor) ?? 4294967295;
1097
- const groupColorAlpha = renderable.groupColorAlpha;
1098
- const globalAlpha = (globalColor >>> 24 & 255) / 255;
1099
- const groupAlphaValue = (groupColorAlpha >>> 24 & 255) / 255;
1100
- const filterAlpha = ((_b = renderer.filter) == null ? void 0 : _b.alphaMultiplier) ?? 1;
1101
- const groupAlpha = globalAlpha * groupAlphaValue * filterAlpha;
1102
- if (groupAlpha <= 0) return;
1103
- const globalTint = globalColor & 16777215;
1104
- const groupTintBGR = groupColorAlpha & 16777215;
1105
- const groupTint = bgr2rgb(multiplyHexColors(groupTintBGR, globalTint));
1106
- const roundPixels = renderer._roundPixels | renderable._roundPixels;
1107
- context.save();
1108
- contextSystem.setContextTransform(baseTransform, roundPixels === 1);
1109
- contextSystem.setBlendMode(renderable.groupBlendMode);
1110
- const instructions = renderable.context.instructions;
1111
- for (let i = 0; i < instructions.length; i++) {
1112
- const instruction = instructions[i];
1113
- if (instruction.action === "texture") {
1114
- const data2 = instruction.data;
1115
- const texture = data2.image;
1116
- const source = texture ? canvasUtils.getCanvasSource(texture) : null;
1117
- if (!source) continue;
1118
- const alpha2 = data2.alpha * groupAlpha;
1119
- if (alpha2 <= 0) continue;
1120
- const tint2 = multiplyHexColors(data2.style, groupTint);
1121
- context.globalAlpha = alpha2;
1122
- let drawSource = source;
1123
- if (tint2 !== 16777215) {
1124
- drawSource = canvasUtils.getTintedCanvas({ texture }, tint2);
1125
- }
1126
- const frame = texture.frame;
1127
- const resolution = texture.source._resolution ?? texture.source.resolution ?? 1;
1128
- let sx = frame.x * resolution;
1129
- let sy = frame.y * resolution;
1130
- const sw = frame.width * resolution;
1131
- const sh = frame.height * resolution;
1132
- if (drawSource !== source) {
1133
- sx = 0;
1134
- sy = 0;
1135
- }
1136
- const transform = data2.transform;
1137
- const hasTransform = transform && !transform.isIdentity();
1138
- const rotate = texture.rotate;
1139
- if (hasTransform || rotate) {
1140
- tempMatrix.copyFrom(baseTransform);
1141
- if (hasTransform) {
1142
- tempMatrix.append(transform);
1143
- }
1144
- if (rotate) {
1145
- groupD8.matrixAppendRotationInv(tempMatrix, rotate, data2.dx, data2.dy, data2.dw, data2.dh);
1146
- }
1147
- contextSystem.setContextTransform(tempMatrix, roundPixels === 1);
1148
- } else {
1149
- contextSystem.setContextTransform(baseTransform, roundPixels === 1);
1150
- }
1151
- context.drawImage(
1152
- drawSource,
1153
- sx,
1154
- sy,
1155
- drawSource === source ? sw : drawSource.width,
1156
- drawSource === source ? sh : drawSource.height,
1157
- rotate ? 0 : data2.dx,
1158
- rotate ? 0 : data2.dy,
1159
- data2.dw,
1160
- data2.dh
1161
- );
1162
- if (hasTransform || rotate) {
1163
- contextSystem.setContextTransform(baseTransform, roundPixels === 1);
1164
- }
1165
- continue;
1166
- }
1167
- const data = instruction.data;
1168
- const shapePath = (_c = data == null ? void 0 : data.path) == null ? void 0 : _c.shapePath;
1169
- if (!((_d = shapePath == null ? void 0 : shapePath.shapePrimitives) == null ? void 0 : _d.length)) continue;
1170
- const style = data.style;
1171
- const tint = multiplyHexColors(style.color, groupTint);
1172
- const alpha = style.alpha * groupAlpha;
1173
- if (alpha <= 0) continue;
1174
- const isStroke = instruction.action === "stroke";
1175
- context.globalAlpha = alpha;
1176
- if (isStroke) {
1177
- const strokeStyle = style;
1178
- context.lineWidth = strokeStyle.width;
1179
- context.lineCap = strokeStyle.cap;
1180
- context.lineJoin = strokeStyle.join;
1181
- context.miterLimit = strokeStyle.miterLimit;
1182
- }
1183
- const shapePrimitives = shapePath.shapePrimitives;
1184
- if (!isStroke && ((_g = (_f = (_e = data.hole) == null ? void 0 : _e.shapePath) == null ? void 0 : _f.shapePrimitives) == null ? void 0 : _g.length)) {
1185
- const lastShape = shapePrimitives[shapePrimitives.length - 1];
1186
- lastShape.holes = data.hole.shapePath.shapePrimitives;
1187
- }
1188
- for (let j = 0; j < shapePrimitives.length; j++) {
1189
- const primitive = shapePrimitives[j];
1190
- if (!(primitive == null ? void 0 : primitive.shape)) continue;
1191
- const transform = primitive.transform;
1192
- const hasTransform = transform && !transform.isIdentity();
1193
- const hasTexture = style.texture && style.texture !== Texture.WHITE;
1194
- const textureTransform = style.textureSpace === "global" ? transform : null;
1195
- const textureMatrix = hasTexture ? generateTextureMatrix(tempTextureMatrix, style, primitive.shape, textureTransform) : null;
1196
- const currentTransform = hasTransform ? tempGradientMatrix.copyFrom(baseTransform).append(transform) : baseTransform;
1197
- const canvasStyle = getCanvasStyle(
1198
- style,
1199
- tint,
1200
- textureMatrix,
1201
- currentTransform
1202
- );
1203
- if (hasTransform) {
1204
- context.save();
1205
- context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty);
1206
- }
1207
- if (isStroke) {
1208
- const strokeStyle = style;
1209
- const useStrokeGeometry = strokeStyle.alignment !== 0.5 && !strokeStyle.pixelLine;
1210
- if (useStrokeGeometry) {
1211
- const points = [];
1212
- const vertices = [];
1213
- const indices = [];
1214
- const shapeBuilder = shapeBuilders[primitive.shape.type];
1215
- if (shapeBuilder == null ? void 0 : shapeBuilder.build(primitive.shape, points)) {
1216
- const close = primitive.shape.closePath ?? true;
1217
- buildLine(points, strokeStyle, false, close, vertices, indices);
1218
- context.fillStyle = canvasStyle;
1219
- fillTriangles(context, vertices, indices);
1220
- } else {
1221
- context.strokeStyle = canvasStyle;
1222
- context.beginPath();
1223
- buildShapePath(context, primitive.shape);
1224
- context.stroke();
1225
- }
1226
- } else {
1227
- context.strokeStyle = canvasStyle;
1228
- context.beginPath();
1229
- buildShapePath(context, primitive.shape);
1230
- context.stroke();
1231
- }
1232
- } else {
1233
- context.fillStyle = canvasStyle;
1234
- context.beginPath();
1235
- buildShapePath(context, primitive.shape);
1236
- const hasHoles = addHolePaths(context, primitive.holes);
1237
- if (hasHoles) {
1238
- context.fill("evenodd");
1239
- } else {
1240
- context.fill();
1241
- }
1242
- }
1243
- if (hasTransform) {
1244
- context.restore();
1245
- }
1246
- }
1247
- }
1248
- context.restore();
1249
- }
1250
- destroy() {
1251
- this.shader = null;
1252
- }
1253
- }
1254
- CanvasGraphicsAdaptor.extension = {
1255
- type: [
1256
- ExtensionType.CanvasPipesAdaptor
1257
- ],
1258
- name: "graphics"
1259
- };
1260
- class CanvasRenderTargetAdaptor {
1261
- /**
1262
- * Initializes the adaptor.
1263
- * @param renderer - Canvas renderer instance.
1264
- * @param renderTargetSystem - The render target system.
1265
- * @advanced
1266
- */
1267
- init(renderer, renderTargetSystem) {
1268
- this._renderer = renderer;
1269
- this._renderTargetSystem = renderTargetSystem;
1270
- }
1271
- /**
1272
- * Creates a GPU render target for canvas.
1273
- * @param renderTarget - Render target to initialize.
1274
- * @advanced
1275
- */
1276
- initGpuRenderTarget(renderTarget) {
1277
- const colorTexture = renderTarget.colorTexture;
1278
- const { canvas, context } = this._ensureCanvas(colorTexture);
1279
- return {
1280
- canvas,
1281
- context,
1282
- width: canvas.width,
1283
- height: canvas.height
1284
- };
1285
- }
1286
- /**
1287
- * Resizes the backing canvas for a render target.
1288
- * @param renderTarget - Render target to resize.
1289
- * @advanced
1290
- */
1291
- resizeGpuRenderTarget(renderTarget) {
1292
- const colorTexture = renderTarget.colorTexture;
1293
- const { canvas } = this._ensureCanvas(colorTexture);
1294
- canvas.width = renderTarget.pixelWidth;
1295
- canvas.height = renderTarget.pixelHeight;
1296
- }
1297
- /**
1298
- * Starts a render pass on the canvas target.
1299
- * @param renderTarget - Target to render to.
1300
- * @param clear - Clear mode.
1301
- * @param clearColor - Optional clear color.
1302
- * @param viewport - Optional viewport.
1303
- * @advanced
1304
- */
1305
- startRenderPass(renderTarget, clear, clearColor, viewport) {
1306
- const gpuRenderTarget = this._renderTargetSystem.getGpuRenderTarget(renderTarget);
1307
- this._renderer.canvasContext.activeContext = gpuRenderTarget.context;
1308
- this._renderer.canvasContext.activeResolution = renderTarget.resolution;
1309
- if (clear) {
1310
- this.clear(renderTarget, clear, clearColor, viewport);
1311
- }
1312
- }
1313
- /**
1314
- * Clears the render target.
1315
- * @param renderTarget - Target to clear.
1316
- * @param _clear - Clear mode (unused).
1317
- * @param clearColor - Optional clear color.
1318
- * @param viewport - Optional viewport rectangle.
1319
- * @advanced
1320
- */
1321
- clear(renderTarget, _clear, clearColor, viewport) {
1322
- const gpuRenderTarget = this._renderTargetSystem.getGpuRenderTarget(renderTarget);
1323
- const context = gpuRenderTarget.context;
1324
- const bounds = viewport || { x: 0, y: 0, width: renderTarget.pixelWidth, height: renderTarget.pixelHeight };
1325
- context.setTransform(1, 0, 0, 1, 0, 0);
1326
- context.clearRect(bounds.x, bounds.y, bounds.width, bounds.height);
1327
- if (clearColor) {
1328
- const color = Color.shared.setValue(clearColor);
1329
- if (color.alpha > 0) {
1330
- context.globalAlpha = color.alpha;
1331
- context.fillStyle = color.toHex();
1332
- context.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
1333
- context.globalAlpha = 1;
1334
- }
1335
- }
1336
- }
1337
- /**
1338
- * Finishes the render pass (no-op for canvas).
1339
- * @advanced
1340
- */
1341
- finishRenderPass() {
1342
- }
1343
- /**
1344
- * Copies a render target into a texture source.
1345
- * @param {RenderTarget} sourceRenderSurfaceTexture - Source render target.
1346
- * @param {Texture} destinationTexture - Destination texture.
1347
- * @param {object} originSrc - Source origin.
1348
- * @param {number} originSrc.x - Source x origin.
1349
- * @param {number} originSrc.y - Source y origin.
1350
- * @param {object} size - Copy size.
1351
- * @param {number} size.width - Copy width.
1352
- * @param {number} size.height - Copy height.
1353
- * @param {object} [originDest] - Destination origin.
1354
- * @param {number} originDest.x - Destination x origin.
1355
- * @param {number} originDest.y - Destination y origin.
1356
- * @advanced
1357
- */
1358
- copyToTexture(sourceRenderSurfaceTexture, destinationTexture, originSrc, size, originDest) {
1359
- const sourceGpuTarget = this._renderTargetSystem.getGpuRenderTarget(sourceRenderSurfaceTexture);
1360
- const sourceCanvas = sourceGpuTarget.canvas;
1361
- const destSource = destinationTexture.source;
1362
- const { context } = this._ensureCanvas(destSource);
1363
- const dx = (originDest == null ? void 0 : originDest.x) ?? 0;
1364
- const dy = (originDest == null ? void 0 : originDest.y) ?? 0;
1365
- context.drawImage(
1366
- sourceCanvas,
1367
- originSrc.x,
1368
- originSrc.y,
1369
- size.width,
1370
- size.height,
1371
- dx,
1372
- dy,
1373
- size.width,
1374
- size.height
1375
- );
1376
- destSource.update();
1377
- return destinationTexture;
1378
- }
1379
- /**
1380
- * Destroys a GPU render target (no-op for canvas).
1381
- * @param _gpuRenderTarget - Target to destroy.
1382
- * @advanced
1383
- */
1384
- destroyGpuRenderTarget(_gpuRenderTarget) {
1385
- }
1386
- _ensureCanvas(source) {
1387
- let canvas = source.resource;
1388
- if (!canvas || !CanvasSource.test(canvas)) {
1389
- canvas = DOMAdapter.get().createCanvas(source.pixelWidth, source.pixelHeight);
1390
- source.resource = canvas;
1391
- }
1392
- if (canvas.width !== source.pixelWidth || canvas.height !== source.pixelHeight) {
1393
- canvas.width = source.pixelWidth;
1394
- canvas.height = source.pixelHeight;
1395
- }
1396
- const context = canvas.getContext("2d");
1397
- return { canvas, context };
1398
- }
1399
- }
1400
- class CanvasRenderTargetSystem extends RenderTargetSystem {
1401
- constructor(renderer) {
1402
- super(renderer);
1403
- this.adaptor = new CanvasRenderTargetAdaptor();
1404
- this.adaptor.init(renderer, this);
1405
- }
1406
- }
1407
- CanvasRenderTargetSystem.extension = {
1408
- type: [ExtensionType.CanvasSystem],
1409
- name: "renderTarget"
1410
- };
1411
- class CanvasTextureSystem {
1412
- /**
1413
- * @param renderer - The owning CanvasRenderer.
1414
- */
1415
- constructor(renderer) {
1416
- }
1417
- /** Initializes the system (no-op for canvas). */
1418
- init() {
1419
- }
1420
- /**
1421
- * Initializes a texture source (no-op for canvas).
1422
- * @param _source - Texture source.
1423
- */
1424
- initSource(_source) {
1425
- }
1426
- /**
1427
- * Creates a canvas containing the texture's frame.
1428
- * @param texture - Texture to render.
1429
- */
1430
- generateCanvas(texture) {
1431
- const canvas = DOMAdapter.get().createCanvas();
1432
- const context = canvas.getContext("2d");
1433
- const source = canvasUtils.getCanvasSource(texture);
1434
- if (!source) {
1435
- return canvas;
1436
- }
1437
- const frame = texture.frame;
1438
- const resolution = texture.source._resolution ?? texture.source.resolution ?? 1;
1439
- const sx = frame.x * resolution;
1440
- const sy = frame.y * resolution;
1441
- const sw = frame.width * resolution;
1442
- const sh = frame.height * resolution;
1443
- canvas.width = Math.ceil(sw);
1444
- canvas.height = Math.ceil(sh);
1445
- context.drawImage(
1446
- source,
1447
- sx,
1448
- sy,
1449
- sw,
1450
- sh,
1451
- 0,
1452
- 0,
1453
- sw,
1454
- sh
1455
- );
1456
- return canvas;
1457
- }
1458
- /**
1459
- * Reads pixel data from a texture.
1460
- * @param texture - Texture to read.
1461
- */
1462
- getPixels(texture) {
1463
- const canvas = this.generateCanvas(texture);
1464
- const context = canvas.getContext("2d", { willReadFrequently: true });
1465
- const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
1466
- return {
1467
- pixels: imageData.data,
1468
- width: canvas.width,
1469
- height: canvas.height
1470
- };
1471
- }
1472
- /** Destroys the system (no-op for canvas). */
1473
- destroy() {
1474
- }
1475
- }
1476
- CanvasTextureSystem.extension = {
1477
- type: [
1478
- ExtensionType.CanvasSystem
1479
- ],
1480
- name: "texture"
1481
- };
1482
- const DefaultCanvasSystems = [
1483
- ...SharedSystems,
1484
- CanvasContextSystem,
1485
- CanvasLimitsSystem,
1486
- CanvasTextureSystem,
1487
- CanvasRenderTargetSystem
1488
- ];
1489
- const DefaultCanvasPipes = [
1490
- BlendModePipe,
1491
- BatcherPipe,
1492
- SpritePipe,
1493
- RenderGroupPipe,
1494
- AlphaMaskPipe,
1495
- CanvasStencilMaskPipe,
1496
- CanvasColorMaskPipe,
1497
- CustomRenderPipe
1498
- ];
1499
- const DefaultCanvasAdapters = [
1500
- CanvasBatchAdaptor,
1501
- CanvasGraphicsAdaptor
1502
- ];
1503
- const systems = [];
1504
- const renderPipes = [];
1505
- const renderPipeAdaptors = [];
1506
- extensions.handleByNamedList(ExtensionType.CanvasSystem, systems);
1507
- extensions.handleByNamedList(ExtensionType.CanvasPipes, renderPipes);
1508
- extensions.handleByNamedList(ExtensionType.CanvasPipesAdaptor, renderPipeAdaptors);
1509
- extensions.add(...DefaultCanvasSystems, ...DefaultCanvasPipes, ...DefaultCanvasAdapters);
1510
- class CanvasRenderer extends AbstractRenderer {
1511
- constructor() {
1512
- const systemConfig = {
1513
- name: "canvas",
1514
- type: RendererType.CANVAS,
1515
- systems,
1516
- renderPipes,
1517
- renderPipeAdaptors
1518
- };
1519
- super(systemConfig);
1520
- }
1521
- }
1522
- export {
1523
- CanvasRenderer
1524
- };
1525
- //# sourceMappingURL=CanvasRenderer-Md8Ayshs.js.map