@esotericsoftware/spine-canvaskit 4.2.86 → 4.2.88

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.
@@ -4552,21 +4552,21 @@ var spine = (() => {
4552
4552
  return this._image;
4553
4553
  }
4554
4554
  };
4555
- var TextureFilter = /* @__PURE__ */ ((TextureFilter3) => {
4556
- TextureFilter3[TextureFilter3["Nearest"] = 9728] = "Nearest";
4557
- TextureFilter3[TextureFilter3["Linear"] = 9729] = "Linear";
4558
- TextureFilter3[TextureFilter3["MipMap"] = 9987] = "MipMap";
4559
- TextureFilter3[TextureFilter3["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
4560
- TextureFilter3[TextureFilter3["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
4561
- TextureFilter3[TextureFilter3["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
4562
- TextureFilter3[TextureFilter3["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
4563
- return TextureFilter3;
4555
+ var TextureFilter = /* @__PURE__ */ ((TextureFilter2) => {
4556
+ TextureFilter2[TextureFilter2["Nearest"] = 9728] = "Nearest";
4557
+ TextureFilter2[TextureFilter2["Linear"] = 9729] = "Linear";
4558
+ TextureFilter2[TextureFilter2["MipMap"] = 9987] = "MipMap";
4559
+ TextureFilter2[TextureFilter2["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
4560
+ TextureFilter2[TextureFilter2["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
4561
+ TextureFilter2[TextureFilter2["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
4562
+ TextureFilter2[TextureFilter2["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
4563
+ return TextureFilter2;
4564
4564
  })(TextureFilter || {});
4565
- var TextureWrap = /* @__PURE__ */ ((TextureWrap3) => {
4566
- TextureWrap3[TextureWrap3["MirroredRepeat"] = 33648] = "MirroredRepeat";
4567
- TextureWrap3[TextureWrap3["ClampToEdge"] = 33071] = "ClampToEdge";
4568
- TextureWrap3[TextureWrap3["Repeat"] = 10497] = "Repeat";
4569
- return TextureWrap3;
4565
+ var TextureWrap = /* @__PURE__ */ ((TextureWrap2) => {
4566
+ TextureWrap2[TextureWrap2["MirroredRepeat"] = 33648] = "MirroredRepeat";
4567
+ TextureWrap2[TextureWrap2["ClampToEdge"] = 33071] = "ClampToEdge";
4568
+ TextureWrap2[TextureWrap2["Repeat"] = 10497] = "Repeat";
4569
+ return TextureWrap2;
4570
4570
  })(TextureWrap || {});
4571
4571
  var TextureRegion = class {
4572
4572
  texture;
@@ -11455,9 +11455,9 @@ var spine = (() => {
11455
11455
  getImage() {
11456
11456
  return this._image;
11457
11457
  }
11458
- setFilters(minFilter, magFilter) {
11458
+ setFilters() {
11459
11459
  }
11460
- setWraps(uWrap, vWrap) {
11460
+ setWraps() {
11461
11461
  }
11462
11462
  dispose() {
11463
11463
  const data = this._image;
@@ -11516,12 +11516,11 @@ var spine = (() => {
11516
11516
  const attachmentLoader = new AtlasAttachmentLoader(atlas);
11517
11517
  const loader = skeletonFile.endsWith(".json") ? new SkeletonJson(attachmentLoader) : new SkeletonBinary(attachmentLoader);
11518
11518
  loader.scale = scale;
11519
- let data = await readFile(skeletonFile);
11520
- if (skeletonFile.endsWith(".json")) {
11521
- data = bufferToUtf8String(data);
11519
+ const data = await readFile(skeletonFile);
11520
+ if (loader instanceof SkeletonJson) {
11521
+ return loader.readSkeletonData(bufferToUtf8String(data));
11522
11522
  }
11523
- const skeletonData = loader.readSkeletonData(data);
11524
- return skeletonData;
11523
+ return loader.readSkeletonData(data);
11525
11524
  }
11526
11525
  var SkeletonDrawable = class {
11527
11526
  skeleton;
@@ -11558,12 +11557,10 @@ var spine = (() => {
11558
11557
  this.ck = ck;
11559
11558
  }
11560
11559
  clipper = new SkeletonClipping();
11561
- tempColor = new Color();
11562
- tempColor2 = new Color();
11563
11560
  static QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
11564
11561
  scratchPositions = Utils.newFloatArray(100);
11565
- scratchColors = Utils.newFloatArray(100);
11566
11562
  scratchUVs = Utils.newFloatArray(100);
11563
+ scratchColors = new Uint32Array(100 / 4);
11567
11564
  /**
11568
11565
  * Renders a skeleton or skeleton drawable in its current pose to the canvas.
11569
11566
  * @param canvas the canvas to render to.
@@ -11571,90 +11568,79 @@ var spine = (() => {
11571
11568
  */
11572
11569
  render(canvas, skeleton) {
11573
11570
  if (skeleton instanceof SkeletonDrawable) skeleton = skeleton.skeleton;
11574
- let clipper = this.clipper;
11575
- let drawOrder = skeleton.drawOrder;
11576
- let skeletonColor = skeleton.color;
11571
+ const clipper = this.clipper;
11572
+ const drawOrder = skeleton.drawOrder;
11573
+ const skeletonColor = skeleton.color;
11577
11574
  for (let i = 0, n = drawOrder.length; i < n; i++) {
11578
- let slot = drawOrder[i];
11575
+ const slot = drawOrder[i];
11579
11576
  if (!slot.bone.active) {
11580
11577
  clipper.clipEndWithSlot(slot);
11581
11578
  continue;
11582
11579
  }
11583
- let attachment = slot.getAttachment();
11580
+ const attachment = slot.getAttachment();
11584
11581
  let positions = this.scratchPositions;
11585
- let colors = this.scratchColors;
11586
- let uvs;
11587
- let texture;
11588
11582
  let triangles;
11589
- let attachmentColor;
11590
- let numVertices = 0;
11583
+ let numVertices = 4;
11591
11584
  if (attachment instanceof RegionAttachment) {
11592
- let region = attachment;
11593
- positions = positions.length < 8 ? Utils.newFloatArray(8) : positions;
11594
- numVertices = 4;
11595
- region.computeWorldVertices(slot, positions, 0, 2);
11585
+ attachment.computeWorldVertices(slot, positions, 0, 2);
11596
11586
  triangles = _SkeletonRenderer.QUAD_TRIANGLES;
11597
- uvs = region.uvs;
11598
- texture = region.region?.texture;
11599
- attachmentColor = region.color;
11600
11587
  } else if (attachment instanceof MeshAttachment) {
11601
- let mesh = attachment;
11602
- positions = positions.length < mesh.worldVerticesLength ? Utils.newFloatArray(mesh.worldVerticesLength) : positions;
11603
- numVertices = mesh.worldVerticesLength >> 1;
11604
- mesh.computeWorldVertices(
11588
+ if (positions.length < attachment.worldVerticesLength) {
11589
+ this.scratchPositions = Utils.newFloatArray(attachment.worldVerticesLength);
11590
+ positions = this.scratchPositions;
11591
+ }
11592
+ numVertices = attachment.worldVerticesLength >> 1;
11593
+ attachment.computeWorldVertices(
11605
11594
  slot,
11606
11595
  0,
11607
- mesh.worldVerticesLength,
11596
+ attachment.worldVerticesLength,
11608
11597
  positions,
11609
11598
  0,
11610
11599
  2
11611
11600
  );
11612
- triangles = mesh.triangles;
11613
- texture = mesh.region?.texture;
11614
- uvs = mesh.uvs;
11615
- attachmentColor = mesh.color;
11601
+ triangles = attachment.triangles;
11616
11602
  } else if (attachment instanceof ClippingAttachment) {
11617
- let clip = attachment;
11618
- clipper.clipStart(slot, clip);
11603
+ clipper.clipStart(slot, attachment);
11619
11604
  continue;
11620
11605
  } else {
11621
11606
  clipper.clipEndWithSlot(slot);
11622
11607
  continue;
11623
11608
  }
11609
+ const texture = attachment.region?.texture;
11624
11610
  if (texture) {
11611
+ let uvs = attachment.uvs;
11612
+ let scaledUvs;
11613
+ let colors = this.scratchColors;
11625
11614
  if (clipper.isClipping()) {
11626
- clipper.clipTrianglesUnpacked(
11627
- positions,
11628
- triangles,
11629
- triangles.length,
11630
- uvs
11631
- );
11615
+ clipper.clipTrianglesUnpacked(positions, triangles, triangles.length, uvs);
11616
+ if (clipper.clippedVertices.length <= 0) {
11617
+ clipper.clipEndWithSlot(slot);
11618
+ continue;
11619
+ }
11632
11620
  positions = clipper.clippedVertices;
11633
- uvs = clipper.clippedUVs;
11621
+ uvs = scaledUvs = clipper.clippedUVs;
11634
11622
  triangles = clipper.clippedTriangles;
11623
+ numVertices = clipper.clippedVertices.length / 2;
11624
+ colors = new Uint32Array(numVertices);
11625
+ } else {
11626
+ scaledUvs = this.scratchUVs;
11627
+ if (this.scratchUVs.length < uvs.length)
11628
+ scaledUvs = this.scratchUVs = Utils.newFloatArray(uvs.length);
11629
+ if (colors.length < numVertices)
11630
+ colors = this.scratchColors = new Uint32Array(numVertices);
11635
11631
  }
11636
- let slotColor = slot.color;
11637
- let finalColor = this.tempColor;
11638
- finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r;
11639
- finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g;
11640
- finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b;
11641
- finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a;
11642
- if (colors.length / 4 < numVertices)
11643
- colors = Utils.newFloatArray(numVertices * 4);
11644
- for (let i2 = 0, n2 = numVertices * 4; i2 < n2; i2 += 4) {
11645
- colors[i2] = finalColor.r;
11646
- colors[i2 + 1] = finalColor.g;
11647
- colors[i2 + 2] = finalColor.b;
11648
- colors[i2 + 3] = finalColor.a;
11649
- }
11650
- const scaledUvs = this.scratchUVs.length < uvs.length ? Utils.newFloatArray(uvs.length) : this.scratchUVs;
11651
- const width = texture.getImage().image.width();
11652
- const height = texture.getImage().image.height();
11632
+ const ckImage = texture.getImage();
11633
+ const image = ckImage.image;
11634
+ const width = image.width();
11635
+ const height = image.height();
11653
11636
  for (let i2 = 0; i2 < uvs.length; i2 += 2) {
11654
11637
  scaledUvs[i2] = uvs[i2] * width;
11655
11638
  scaledUvs[i2 + 1] = uvs[i2 + 1] * height;
11656
11639
  }
11657
- const blendMode = slot.data.blendMode;
11640
+ const attachmentColor = attachment.color;
11641
+ const slotColor = slot.color;
11642
+ 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;
11643
+ for (let i2 = 0, n2 = numVertices; i2 < n2; i2++) colors[i2] = finalColor;
11658
11644
  const vertices = this.ck.MakeVertices(
11659
11645
  this.ck.VertexMode.Triangles,
11660
11646
  positions,
@@ -11663,11 +11649,8 @@ var spine = (() => {
11663
11649
  triangles,
11664
11650
  false
11665
11651
  );
11666
- canvas.drawVertices(
11667
- vertices,
11668
- this.ck.BlendMode.Modulate,
11669
- texture.getImage().paintPerBlendMode.get(blendMode)
11670
- );
11652
+ const ckPaint = ckImage.paintPerBlendMode.get(slot.data.blendMode);
11653
+ if (ckPaint) canvas.drawVertices(vertices, this.ck.BlendMode.Modulate, ckPaint);
11671
11654
  vertices.delete();
11672
11655
  }
11673
11656
  clipper.clipEndWithSlot(slot);