@esotericsoftware/spine-canvaskit 4.2.87 → 4.2.89

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.
@@ -4406,21 +4406,21 @@ var Texture = class {
4406
4406
  return this._image;
4407
4407
  }
4408
4408
  };
4409
- var TextureFilter = /* @__PURE__ */ ((TextureFilter3) => {
4410
- TextureFilter3[TextureFilter3["Nearest"] = 9728] = "Nearest";
4411
- TextureFilter3[TextureFilter3["Linear"] = 9729] = "Linear";
4412
- TextureFilter3[TextureFilter3["MipMap"] = 9987] = "MipMap";
4413
- TextureFilter3[TextureFilter3["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
4414
- TextureFilter3[TextureFilter3["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
4415
- TextureFilter3[TextureFilter3["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
4416
- TextureFilter3[TextureFilter3["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
4417
- return TextureFilter3;
4409
+ var TextureFilter = /* @__PURE__ */ ((TextureFilter2) => {
4410
+ TextureFilter2[TextureFilter2["Nearest"] = 9728] = "Nearest";
4411
+ TextureFilter2[TextureFilter2["Linear"] = 9729] = "Linear";
4412
+ TextureFilter2[TextureFilter2["MipMap"] = 9987] = "MipMap";
4413
+ TextureFilter2[TextureFilter2["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
4414
+ TextureFilter2[TextureFilter2["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
4415
+ TextureFilter2[TextureFilter2["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
4416
+ TextureFilter2[TextureFilter2["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
4417
+ return TextureFilter2;
4418
4418
  })(TextureFilter || {});
4419
- var TextureWrap = /* @__PURE__ */ ((TextureWrap3) => {
4420
- TextureWrap3[TextureWrap3["MirroredRepeat"] = 33648] = "MirroredRepeat";
4421
- TextureWrap3[TextureWrap3["ClampToEdge"] = 33071] = "ClampToEdge";
4422
- TextureWrap3[TextureWrap3["Repeat"] = 10497] = "Repeat";
4423
- return TextureWrap3;
4419
+ var TextureWrap = /* @__PURE__ */ ((TextureWrap2) => {
4420
+ TextureWrap2[TextureWrap2["MirroredRepeat"] = 33648] = "MirroredRepeat";
4421
+ TextureWrap2[TextureWrap2["ClampToEdge"] = 33071] = "ClampToEdge";
4422
+ TextureWrap2[TextureWrap2["Repeat"] = 10497] = "Repeat";
4423
+ return TextureWrap2;
4424
4424
  })(TextureWrap || {});
4425
4425
  var TextureRegion = class {
4426
4426
  texture;
@@ -11309,9 +11309,9 @@ var CanvasKitTexture = class _CanvasKitTexture extends Texture {
11309
11309
  getImage() {
11310
11310
  return this._image;
11311
11311
  }
11312
- setFilters(minFilter, magFilter) {
11312
+ setFilters() {
11313
11313
  }
11314
- setWraps(uWrap, vWrap) {
11314
+ setWraps() {
11315
11315
  }
11316
11316
  dispose() {
11317
11317
  const data = this._image;
@@ -11370,12 +11370,11 @@ async function loadSkeletonData(skeletonFile, atlas, readFile, scale = 1) {
11370
11370
  const attachmentLoader = new AtlasAttachmentLoader(atlas);
11371
11371
  const loader = skeletonFile.endsWith(".json") ? new SkeletonJson(attachmentLoader) : new SkeletonBinary(attachmentLoader);
11372
11372
  loader.scale = scale;
11373
- let data = await readFile(skeletonFile);
11374
- if (skeletonFile.endsWith(".json")) {
11375
- data = bufferToUtf8String(data);
11373
+ const data = await readFile(skeletonFile);
11374
+ if (loader instanceof SkeletonJson) {
11375
+ return loader.readSkeletonData(bufferToUtf8String(data));
11376
11376
  }
11377
- const skeletonData = loader.readSkeletonData(data);
11378
- return skeletonData;
11377
+ return loader.readSkeletonData(data);
11379
11378
  }
11380
11379
  var SkeletonDrawable = class {
11381
11380
  skeleton;
@@ -11412,12 +11411,10 @@ var SkeletonRenderer = class _SkeletonRenderer {
11412
11411
  this.ck = ck;
11413
11412
  }
11414
11413
  clipper = new SkeletonClipping();
11415
- tempColor = new Color();
11416
- tempColor2 = new Color();
11417
11414
  static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
11418
11415
  scratchPositions = Utils.newFloatArray(100);
11419
- scratchColors = Utils.newFloatArray(100);
11420
11416
  scratchUVs = Utils.newFloatArray(100);
11417
+ scratchColors = new Uint32Array(100 / 4);
11421
11418
  /**
11422
11419
  * Renders a skeleton or skeleton drawable in its current pose to the canvas.
11423
11420
  * @param canvas the canvas to render to.
@@ -11425,100 +11422,79 @@ var SkeletonRenderer = class _SkeletonRenderer {
11425
11422
  */
11426
11423
  render(canvas, skeleton) {
11427
11424
  if (skeleton instanceof SkeletonDrawable) skeleton = skeleton.skeleton;
11428
- let clipper = this.clipper;
11429
- let drawOrder = skeleton.drawOrder;
11430
- let skeletonColor = skeleton.color;
11425
+ const clipper = this.clipper;
11426
+ const drawOrder = skeleton.drawOrder;
11427
+ const skeletonColor = skeleton.color;
11431
11428
  for (let i = 0, n = drawOrder.length; i < n; i++) {
11432
- let slot = drawOrder[i];
11429
+ const slot = drawOrder[i];
11433
11430
  if (!slot.bone.active) {
11434
11431
  clipper.clipEndWithSlot(slot);
11435
11432
  continue;
11436
11433
  }
11437
- let attachment = slot.getAttachment();
11434
+ const attachment = slot.getAttachment();
11438
11435
  let positions = this.scratchPositions;
11439
- let colors = this.scratchColors;
11440
- let uvs;
11441
- let texture;
11442
11436
  let triangles;
11443
- let attachmentColor;
11444
- let numVertices = 0;
11437
+ let numVertices = 4;
11445
11438
  if (attachment instanceof RegionAttachment) {
11446
- let region = attachment;
11447
- if (positions.length < 8) this.scratchPositions = positions = Utils.newFloatArray(8);
11448
- numVertices = 4;
11449
- region.computeWorldVertices(slot, positions, 0, 2);
11439
+ attachment.computeWorldVertices(slot, positions, 0, 2);
11450
11440
  triangles = _SkeletonRenderer.QUAD_TRIANGLES;
11451
- uvs = region.uvs;
11452
- texture = region.region?.texture;
11453
- attachmentColor = region.color;
11454
11441
  } else if (attachment instanceof MeshAttachment) {
11455
- let mesh = attachment;
11456
- if (positions.length < mesh.worldVerticesLength)
11457
- this.scratchPositions = positions = Utils.newFloatArray(mesh.worldVerticesLength);
11458
- numVertices = mesh.worldVerticesLength >> 1;
11459
- mesh.computeWorldVertices(
11442
+ if (positions.length < attachment.worldVerticesLength) {
11443
+ this.scratchPositions = Utils.newFloatArray(attachment.worldVerticesLength);
11444
+ positions = this.scratchPositions;
11445
+ }
11446
+ numVertices = attachment.worldVerticesLength >> 1;
11447
+ attachment.computeWorldVertices(
11460
11448
  slot,
11461
11449
  0,
11462
- mesh.worldVerticesLength,
11450
+ attachment.worldVerticesLength,
11463
11451
  positions,
11464
11452
  0,
11465
11453
  2
11466
11454
  );
11467
- triangles = mesh.triangles;
11468
- texture = mesh.region?.texture;
11469
- uvs = mesh.uvs;
11470
- attachmentColor = mesh.color;
11455
+ triangles = attachment.triangles;
11471
11456
  } else if (attachment instanceof ClippingAttachment) {
11472
- let clip = attachment;
11473
- clipper.clipStart(slot, clip);
11457
+ clipper.clipStart(slot, attachment);
11474
11458
  continue;
11475
11459
  } else {
11476
11460
  clipper.clipEndWithSlot(slot);
11477
11461
  continue;
11478
11462
  }
11463
+ const texture = attachment.region?.texture;
11479
11464
  if (texture) {
11465
+ let uvs = attachment.uvs;
11466
+ let scaledUvs;
11467
+ let colors = this.scratchColors;
11480
11468
  if (clipper.isClipping()) {
11481
- clipper.clipTrianglesUnpacked(
11482
- positions,
11483
- triangles,
11484
- triangles.length,
11485
- uvs
11486
- );
11487
- if (clipper.clippedVertices.length > 0) {
11488
- if (positions.length < clipper.clippedVertices.length)
11489
- this.scratchPositions = positions = Utils.newFloatArray(clipper.clippedVertices.length);
11490
- numVertices = clipper.clippedVertices.length / 2;
11491
- for (let i2 = 0; i2 < clipper.clippedVertices.length; i2++)
11492
- positions[i2] = clipper.clippedVertices[i2];
11493
- uvs = clipper.clippedUVs;
11494
- triangles = clipper.clippedTriangles;
11495
- } else {
11469
+ clipper.clipTrianglesUnpacked(positions, triangles, triangles.length, uvs);
11470
+ if (clipper.clippedVertices.length <= 0) {
11496
11471
  clipper.clipEndWithSlot(slot);
11497
11472
  continue;
11498
11473
  }
11474
+ positions = clipper.clippedVertices;
11475
+ uvs = scaledUvs = clipper.clippedUVs;
11476
+ triangles = clipper.clippedTriangles;
11477
+ numVertices = clipper.clippedVertices.length / 2;
11478
+ colors = new Uint32Array(numVertices);
11479
+ } else {
11480
+ scaledUvs = this.scratchUVs;
11481
+ if (this.scratchUVs.length < uvs.length)
11482
+ scaledUvs = this.scratchUVs = Utils.newFloatArray(uvs.length);
11483
+ if (colors.length < numVertices)
11484
+ colors = this.scratchColors = new Uint32Array(numVertices);
11499
11485
  }
11500
- let slotColor = slot.color;
11501
- let finalColor = this.tempColor;
11502
- finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r;
11503
- finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g;
11504
- finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b;
11505
- finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a;
11506
- if (colors.length / 4 < numVertices)
11507
- this.scratchColors = colors = Utils.newFloatArray(numVertices * 4);
11508
- for (let i2 = 0, n2 = numVertices * 4; i2 < n2; i2 += 4) {
11509
- colors[i2] = finalColor.r;
11510
- colors[i2 + 1] = finalColor.g;
11511
- colors[i2 + 2] = finalColor.b;
11512
- colors[i2 + 3] = finalColor.a;
11513
- }
11514
- const scaledUvs = this.scratchUVs.length < uvs.length ? this.scratchUVs = Utils.newFloatArray(uvs.length) : this.scratchUVs;
11515
- const width = texture.getImage().image.width();
11516
- const height = texture.getImage().image.height();
11486
+ const ckImage = texture.getImage();
11487
+ const image = ckImage.image;
11488
+ const width = image.width();
11489
+ const height = image.height();
11517
11490
  for (let i2 = 0; i2 < uvs.length; i2 += 2) {
11518
11491
  scaledUvs[i2] = uvs[i2] * width;
11519
11492
  scaledUvs[i2 + 1] = uvs[i2 + 1] * height;
11520
11493
  }
11521
- const blendMode = slot.data.blendMode;
11494
+ const attachmentColor = attachment.color;
11495
+ const slotColor = slot.color;
11496
+ const finalColor = (MathUtils.clamp(skeletonColor.a * slotColor.a * attachmentColor.a * 255, 0, 255) << 24 | MathUtils.clamp(skeletonColor.r * slotColor.r * attachmentColor.r * 255, 0, 255) << 16 | MathUtils.clamp(skeletonColor.g * slotColor.g * attachmentColor.g * 255, 0, 255) << 8 | MathUtils.clamp(skeletonColor.b * slotColor.b * attachmentColor.b * 255, 0, 255) << 0) >>> 0;
11497
+ for (let i2 = 0, n2 = numVertices; i2 < n2; i2++) colors[i2] = finalColor;
11522
11498
  const vertices = this.ck.MakeVertices(
11523
11499
  this.ck.VertexMode.Triangles,
11524
11500
  positions,
@@ -11527,11 +11503,8 @@ var SkeletonRenderer = class _SkeletonRenderer {
11527
11503
  triangles,
11528
11504
  false
11529
11505
  );
11530
- canvas.drawVertices(
11531
- vertices,
11532
- this.ck.BlendMode.Modulate,
11533
- texture.getImage().paintPerBlendMode.get(blendMode)
11534
- );
11506
+ const ckPaint = ckImage.paintPerBlendMode.get(slot.data.blendMode);
11507
+ if (ckPaint) canvas.drawVertices(vertices, this.ck.BlendMode.Modulate, ckPaint);
11535
11508
  vertices.delete();
11536
11509
  }
11537
11510
  clipper.clipEndWithSlot(slot);