@esotericsoftware/spine-canvaskit 4.2.49 → 4.2.53

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.
@@ -41,7 +41,6 @@ var spine = (() => {
41
41
  BoneData: () => BoneData,
42
42
  BoundingBoxAttachment: () => BoundingBoxAttachment,
43
43
  CURRENT: () => CURRENT,
44
- CanvasKitTexture: () => CanvasKitTexture,
45
44
  ClippingAttachment: () => ClippingAttachment,
46
45
  Color: () => Color,
47
46
  ConstraintData: () => ConstraintData,
@@ -115,6 +114,7 @@ var spine = (() => {
115
114
  SkeletonBounds: () => SkeletonBounds,
116
115
  SkeletonClipping: () => SkeletonClipping,
117
116
  SkeletonData: () => SkeletonData,
117
+ SkeletonDrawable: () => SkeletonDrawable,
118
118
  SkeletonJson: () => SkeletonJson,
119
119
  SkeletonRenderer: () => SkeletonRenderer,
120
120
  Skin: () => Skin,
@@ -144,6 +144,7 @@ var spine = (() => {
144
144
  Vector2: () => Vector2,
145
145
  VertexAttachment: () => VertexAttachment,
146
146
  WindowedMean: () => WindowedMean,
147
+ loadSkeletonData: () => loadSkeletonData,
147
148
  loadTextureAtlas: () => loadTextureAtlas
148
149
  });
149
150
 
@@ -11766,6 +11767,15 @@ var spine = (() => {
11766
11767
  return ck.BlendMode.SrcOver;
11767
11768
  }
11768
11769
  }
11770
+ function bufferToUtf8String(buffer) {
11771
+ if (typeof Buffer !== "undefined") {
11772
+ return buffer.toString("utf-8");
11773
+ } else if (typeof TextDecoder !== "undefined") {
11774
+ return new TextDecoder("utf-8").decode(buffer);
11775
+ } else {
11776
+ throw new Error("Unsupported environment");
11777
+ }
11778
+ }
11769
11779
  var CanvasKitTexture = class extends Texture {
11770
11780
  getImage() {
11771
11781
  return this._image;
@@ -11805,26 +11815,51 @@ var spine = (() => {
11805
11815
  return new CanvasKitTexture({ shaders, paintPerBlendMode, image });
11806
11816
  }
11807
11817
  };
11808
- function bufferToUtf8String(buffer) {
11809
- if (typeof Buffer !== "undefined") {
11810
- return buffer.toString("utf-8");
11811
- } else if (typeof TextDecoder !== "undefined") {
11812
- return new TextDecoder("utf-8").decode(buffer);
11813
- } else {
11814
- throw new Error("Unsupported environment");
11815
- }
11816
- }
11817
11818
  async function loadTextureAtlas(ck, atlasFile, readFile) {
11818
11819
  const atlas = new TextureAtlas(bufferToUtf8String(await readFile(atlasFile)));
11819
11820
  const slashIndex = atlasFile.lastIndexOf("/");
11820
- const parentDir = slashIndex >= 0 ? atlasFile.substring(0, slashIndex + 1) : "";
11821
+ const parentDir = slashIndex >= 0 ? atlasFile.substring(0, slashIndex + 1) + "/" : "";
11821
11822
  for (const page of atlas.pages) {
11822
- const texture = await CanvasKitTexture.fromFile(ck, parentDir + "/" + page.name, readFile);
11823
+ const texture = await CanvasKitTexture.fromFile(ck, parentDir + page.name, readFile);
11823
11824
  page.setTexture(texture);
11824
11825
  }
11825
11826
  return atlas;
11826
11827
  }
11828
+ async function loadSkeletonData(skeletonFile, atlas, readFile) {
11829
+ const attachmentLoader = new AtlasAttachmentLoader(atlas);
11830
+ const loader = skeletonFile.endsWith(".json") ? new SkeletonJson(attachmentLoader) : new SkeletonBinary(attachmentLoader);
11831
+ const skeletonData = loader.readSkeletonData(await readFile(skeletonFile));
11832
+ return skeletonData;
11833
+ }
11834
+ var SkeletonDrawable = class {
11835
+ skeleton;
11836
+ animationState;
11837
+ /**
11838
+ * Constructs a new drawble from the skeleton data.
11839
+ */
11840
+ constructor(skeletonData) {
11841
+ this.skeleton = new Skeleton(skeletonData);
11842
+ this.animationState = new AnimationState(new AnimationStateData(skeletonData));
11843
+ }
11844
+ /**
11845
+ * Updates the animation state and skeleton time by the delta time. Applies the
11846
+ * animations to the skeleton and calculates the final pose of the skeleton.
11847
+ *
11848
+ * @param deltaTime the time since the last update in seconds
11849
+ * @param physicsUpdate optional {@link Physics} update mode.
11850
+ */
11851
+ update(deltaTime, physicsUpdate = 2 /* update */) {
11852
+ this.animationState.update(deltaTime);
11853
+ this.skeleton.update(deltaTime);
11854
+ this.animationState.apply(this.skeleton);
11855
+ this.skeleton.updateWorldTransform(physicsUpdate);
11856
+ }
11857
+ };
11827
11858
  var _SkeletonRenderer = class {
11859
+ /**
11860
+ * Creates a new skeleton renderer.
11861
+ * @param ck the {@link CanvasKit} instance returned by `CanvasKitInit()`.
11862
+ */
11828
11863
  constructor(ck) {
11829
11864
  this.ck = ck;
11830
11865
  }
@@ -11833,7 +11868,14 @@ var spine = (() => {
11833
11868
  tempColor2 = new Color();
11834
11869
  scratchPositions = Utils.newFloatArray(100);
11835
11870
  scratchColors = Utils.newFloatArray(100);
11871
+ /**
11872
+ * Renders a skeleton or skeleton drawable in its current pose to the canvas.
11873
+ * @param canvas the canvas to render to.
11874
+ * @param skeleton the skeleton or drawable to render.
11875
+ */
11836
11876
  render(canvas, skeleton) {
11877
+ if (skeleton instanceof SkeletonDrawable)
11878
+ skeleton = skeleton.skeleton;
11837
11879
  let clipper = this.clipper;
11838
11880
  let drawOrder = skeleton.drawOrder;
11839
11881
  let skeletonColor = skeleton.color;