@esotericsoftware/spine-webgl 4.0.11 → 4.1.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.
@@ -26,6 +26,7 @@ var spine = (() => {
26
26
  BoneData: () => BoneData,
27
27
  BoundingBoxAttachment: () => BoundingBoxAttachment,
28
28
  CURRENT: () => CURRENT,
29
+ CameraController: () => CameraController,
29
30
  ClippingAttachment: () => ClippingAttachment,
30
31
  Color: () => Color,
31
32
  Color2Attribute: () => Color2Attribute,
@@ -109,6 +110,7 @@ var spine = (() => {
109
110
  ScaleXTimeline: () => ScaleXTimeline,
110
111
  ScaleYTimeline: () => ScaleYTimeline,
111
112
  SceneRenderer: () => SceneRenderer,
113
+ SequenceTimeline: () => SequenceTimeline,
112
114
  Shader: () => Shader,
113
115
  ShapeRenderer: () => ShapeRenderer,
114
116
  ShapeType: () => ShapeType,
@@ -553,7 +555,7 @@ var spine = (() => {
553
555
  super(name);
554
556
  this.id = _VertexAttachment.nextID++;
555
557
  this.worldVerticesLength = 0;
556
- this.deformAttachment = this;
558
+ this.timelineAttahment = this;
557
559
  }
558
560
  computeWorldVertices(slot, start, count, worldVertices, offset, stride) {
559
561
  count = offset + (count >> 1) * stride;
@@ -625,12 +627,75 @@ var spine = (() => {
625
627
  } else
626
628
  attachment.vertices = null;
627
629
  attachment.worldVerticesLength = this.worldVerticesLength;
628
- attachment.deformAttachment = this.deformAttachment;
630
+ attachment.timelineAttahment = this.timelineAttahment;
629
631
  }
630
632
  };
631
633
  var VertexAttachment = _VertexAttachment;
632
634
  VertexAttachment.nextID = 0;
633
635
 
636
+ // spine-core/src/attachments/Sequence.ts
637
+ var _Sequence = class {
638
+ constructor(count) {
639
+ this.id = _Sequence.nextID();
640
+ this.start = 0;
641
+ this.digits = 0;
642
+ this.setupIndex = 0;
643
+ this.regions = new Array(count);
644
+ }
645
+ copy() {
646
+ let copy = new _Sequence(this.regions.length);
647
+ Utils.arrayCopy(this.regions, 0, copy.regions, 0, this.regions.length);
648
+ copy.start = this.start;
649
+ copy.digits = this.digits;
650
+ copy.setupIndex = this.setupIndex;
651
+ return copy;
652
+ }
653
+ apply(slot, attachment) {
654
+ let index = slot.sequenceIndex;
655
+ if (index == -1)
656
+ index = this.setupIndex;
657
+ if (index >= this.regions.length)
658
+ index = this.regions.length - 1;
659
+ let region = this.regions[index];
660
+ if (attachment.region != region) {
661
+ attachment.region = region;
662
+ attachment.updateRegion();
663
+ }
664
+ }
665
+ getPath(basePath, index) {
666
+ let result = basePath;
667
+ let frame = (this.start + index).toString();
668
+ for (let i = this.digits - frame.length; i > 0; i--)
669
+ result += "0";
670
+ result += frame;
671
+ return result;
672
+ }
673
+ static nextID() {
674
+ return _Sequence._nextID++;
675
+ }
676
+ };
677
+ var Sequence = _Sequence;
678
+ Sequence._nextID = 0;
679
+ var SequenceMode;
680
+ (function(SequenceMode2) {
681
+ SequenceMode2[SequenceMode2["hold"] = 0] = "hold";
682
+ SequenceMode2[SequenceMode2["once"] = 1] = "once";
683
+ SequenceMode2[SequenceMode2["loop"] = 2] = "loop";
684
+ SequenceMode2[SequenceMode2["pingpong"] = 3] = "pingpong";
685
+ SequenceMode2[SequenceMode2["onceReverse"] = 4] = "onceReverse";
686
+ SequenceMode2[SequenceMode2["loopReverse"] = 5] = "loopReverse";
687
+ SequenceMode2[SequenceMode2["pingpongReverse"] = 6] = "pingpongReverse";
688
+ })(SequenceMode || (SequenceMode = {}));
689
+ var SequenceModeValues = [
690
+ 0,
691
+ 1,
692
+ 2,
693
+ 3,
694
+ 4,
695
+ 5,
696
+ 6
697
+ ];
698
+
634
699
  // spine-core/src/Animation.ts
635
700
  var Animation = class {
636
701
  constructor(name, timelines, duration) {
@@ -698,7 +763,8 @@ var spine = (() => {
698
763
  transformConstraint: 15,
699
764
  pathConstraintPosition: 16,
700
765
  pathConstraintSpacing: 17,
701
- pathConstraintMix: 18
766
+ pathConstraintMix: 18,
767
+ sequence: 19
702
768
  };
703
769
  var Timeline = class {
704
770
  constructor(frameCount, propertyIds) {
@@ -1856,7 +1922,7 @@ var spine = (() => {
1856
1922
  if (!slot.bone.active)
1857
1923
  return;
1858
1924
  let slotAttachment = slot.getAttachment();
1859
- if (!(slotAttachment instanceof VertexAttachment) || slotAttachment.deformAttachment != this.attachment)
1925
+ if (!(slotAttachment instanceof VertexAttachment) || slotAttachment.timelineAttahment != this.attachment)
1860
1926
  return;
1861
1927
  let deform = slot.deform;
1862
1928
  if (deform.length == 0)
@@ -1865,7 +1931,6 @@ var spine = (() => {
1865
1931
  let vertexCount = vertices[0].length;
1866
1932
  let frames = this.frames;
1867
1933
  if (time < frames[0]) {
1868
- let vertexAttachment = slotAttachment;
1869
1934
  switch (blend) {
1870
1935
  case 0:
1871
1936
  deform.length = 0;
@@ -1876,6 +1941,7 @@ var spine = (() => {
1876
1941
  return;
1877
1942
  }
1878
1943
  deform.length = vertexCount;
1944
+ let vertexAttachment = slotAttachment;
1879
1945
  if (!vertexAttachment.bones) {
1880
1946
  let setupVertices = vertexAttachment.vertices;
1881
1947
  for (var i = 0; i < vertexCount; i++)
@@ -2400,6 +2466,81 @@ var spine = (() => {
2400
2466
  }
2401
2467
  }
2402
2468
  };
2469
+ var _SequenceTimeline = class extends Timeline {
2470
+ constructor(frameCount, slotIndex, attachment) {
2471
+ super(frameCount, [
2472
+ Property.sequence + "|" + slotIndex + "|" + attachment.sequence.id
2473
+ ]);
2474
+ this.slotIndex = slotIndex;
2475
+ this.attachment = attachment;
2476
+ }
2477
+ getFrameEntries() {
2478
+ return _SequenceTimeline.ENTRIES;
2479
+ }
2480
+ getSlotIndex() {
2481
+ return this.slotIndex;
2482
+ }
2483
+ getAttachment() {
2484
+ return this.attachment;
2485
+ }
2486
+ setFrame(frame, time, mode, index, delay) {
2487
+ let frames = this.frames;
2488
+ frame *= _SequenceTimeline.ENTRIES;
2489
+ frames[frame] = time;
2490
+ frames[frame + _SequenceTimeline.MODE] = mode | index << 4;
2491
+ frames[frame + _SequenceTimeline.DELAY] = delay;
2492
+ }
2493
+ apply(skeleton, lastTime, time, events, alpha, blend, direction) {
2494
+ let slot = skeleton.slots[this.slotIndex];
2495
+ if (!slot.bone.active)
2496
+ return;
2497
+ let slotAttachment = slot.attachment;
2498
+ let attachment = this.attachment;
2499
+ if (slotAttachment != attachment) {
2500
+ if (!(slotAttachment instanceof VertexAttachment) || slotAttachment.timelineAttahment != attachment)
2501
+ return;
2502
+ }
2503
+ let frames = this.frames;
2504
+ if (time < frames[0]) {
2505
+ if (blend == 0 || blend == 1)
2506
+ slot.sequenceIndex = -1;
2507
+ return;
2508
+ }
2509
+ let i = Timeline.search(frames, time, _SequenceTimeline.ENTRIES);
2510
+ let before = frames[i];
2511
+ let modeAndIndex = frames[i + _SequenceTimeline.MODE];
2512
+ let delay = frames[i + _SequenceTimeline.DELAY];
2513
+ let index = modeAndIndex >> 4, count = this.attachment.sequence.regions.length;
2514
+ let mode = SequenceModeValues[modeAndIndex & 15];
2515
+ if (mode != SequenceMode.hold) {
2516
+ index += (time - before) / delay + 1e-5 | 0;
2517
+ switch (mode) {
2518
+ case SequenceMode.once:
2519
+ index = Math.min(count - 1, index);
2520
+ break;
2521
+ case SequenceMode.loop:
2522
+ index %= count;
2523
+ break;
2524
+ case SequenceMode.pingpong:
2525
+ let n = (count << 1) - 2;
2526
+ index %= n;
2527
+ if (index >= count)
2528
+ index = n - index;
2529
+ break;
2530
+ case SequenceMode.onceReverse:
2531
+ index = Math.max(count - 1 - index, 0);
2532
+ break;
2533
+ case SequenceMode.loopReverse:
2534
+ index = count - 1 - index % count;
2535
+ }
2536
+ }
2537
+ slot.sequenceIndex = index;
2538
+ }
2539
+ };
2540
+ var SequenceTimeline = _SequenceTimeline;
2541
+ SequenceTimeline.ENTRIES = 3;
2542
+ SequenceTimeline.MODE = 1;
2543
+ SequenceTimeline.DELAY = 2;
2403
2544
 
2404
2545
  // spine-core/src/AnimationState.ts
2405
2546
  var AnimationState = class {
@@ -3493,7 +3634,7 @@ var spine = (() => {
3493
3634
  this.color = new Color(1, 1, 1, 1);
3494
3635
  this.tempColor = new Color(0, 0, 0, 0);
3495
3636
  }
3496
- updateUVs() {
3637
+ updateRegion() {
3497
3638
  let regionUVs = this.regionUVs;
3498
3639
  if (!this.uvs || this.uvs.length != regionUVs.length)
3499
3640
  this.uvs = Utils.newFloatArray(regionUVs.length);
@@ -3581,6 +3722,7 @@ var spine = (() => {
3581
3722
  copy.triangles = new Array(this.triangles.length);
3582
3723
  Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
3583
3724
  copy.hullLength = this.hullLength;
3725
+ copy.sequence = this.sequence.copy();
3584
3726
  if (this.edges) {
3585
3727
  copy.edges = new Array(this.edges.length);
3586
3728
  Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
@@ -3589,14 +3731,20 @@ var spine = (() => {
3589
3731
  copy.height = this.height;
3590
3732
  return copy;
3591
3733
  }
3734
+ computeWorldVertices(slot, start, count, worldVertices, offset, stride) {
3735
+ if (this.sequence != null)
3736
+ this.sequence.apply(slot, this);
3737
+ super.computeWorldVertices(slot, start, count, worldVertices, offset, stride);
3738
+ }
3592
3739
  newLinkedMesh() {
3593
3740
  let copy = new MeshAttachment(this.name);
3594
3741
  copy.region = this.region;
3595
3742
  copy.path = this.path;
3596
3743
  copy.color.setFromColor(this.color);
3597
- copy.deformAttachment = this.deformAttachment;
3744
+ copy.timelineAttahment = this.timelineAttahment;
3598
3745
  copy.setParentMesh(this.parentMesh ? this.parentMesh : this);
3599
- copy.updateUVs();
3746
+ if (copy.region != null)
3747
+ copy.updateRegion();
3600
3748
  return copy;
3601
3749
  }
3602
3750
  };
@@ -3664,7 +3812,7 @@ var spine = (() => {
3664
3812
  this.uvs = Utils.newFloatArray(8);
3665
3813
  this.tempColor = new Color(1, 1, 1, 1);
3666
3814
  }
3667
- updateOffset() {
3815
+ updateRegion() {
3668
3816
  let region = this.region;
3669
3817
  let regionScaleX = this.width / this.region.originalWidth * this.scaleX;
3670
3818
  let regionScaleY = this.height / this.region.originalHeight * this.scaleY;
@@ -3693,9 +3841,6 @@ var spine = (() => {
3693
3841
  offset[5] = localY2Cos + localX2Sin;
3694
3842
  offset[6] = localX2Cos - localYSin;
3695
3843
  offset[7] = localYCos + localX2Sin;
3696
- }
3697
- setRegion(region) {
3698
- this.region = region;
3699
3844
  let uvs = this.uvs;
3700
3845
  if (region.degrees == 90) {
3701
3846
  uvs[2] = region.u;
@@ -3717,7 +3862,10 @@ var spine = (() => {
3717
3862
  uvs[7] = region.v2;
3718
3863
  }
3719
3864
  }
3720
- computeWorldVertices(bone, worldVertices, offset, stride) {
3865
+ computeWorldVertices(slot, worldVertices, offset, stride) {
3866
+ if (this.sequence != null)
3867
+ this.sequence.apply(slot, this);
3868
+ let bone = slot.bone;
3721
3869
  let vertexOffset = this.offset;
3722
3870
  let x = bone.worldX, y = bone.worldY;
3723
3871
  let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
@@ -3757,6 +3905,7 @@ var spine = (() => {
3757
3905
  Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
3758
3906
  Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
3759
3907
  copy.color.setFromColor(this.color);
3908
+ copy.sequence = this.sequence.copy();
3760
3909
  return copy;
3761
3910
  }
3762
3911
  };
@@ -3799,22 +3948,40 @@ var spine = (() => {
3799
3948
  constructor(atlas) {
3800
3949
  this.atlas = atlas;
3801
3950
  }
3802
- newRegionAttachment(skin, name, path) {
3803
- let region = this.atlas.findRegion(path);
3804
- if (!region)
3805
- throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
3806
- region.renderObject = region;
3951
+ loadSequence(name, basePath, sequence) {
3952
+ let regions = sequence.regions;
3953
+ for (let i = 0, n = regions.length; i < n; i++) {
3954
+ let path = sequence.getPath(basePath, i);
3955
+ regions[i] = this.atlas.findRegion(path);
3956
+ regions[i].renderObject = regions[i];
3957
+ if (regions[i] == null)
3958
+ throw new Error("Region not found in atlas: " + path + " (sequence: " + name + ")");
3959
+ }
3960
+ }
3961
+ newRegionAttachment(skin, name, path, sequence) {
3807
3962
  let attachment = new RegionAttachment(name);
3808
- attachment.setRegion(region);
3963
+ if (sequence != null) {
3964
+ this.loadSequence(name, path, sequence);
3965
+ } else {
3966
+ let region = this.atlas.findRegion(path);
3967
+ if (!region)
3968
+ throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
3969
+ region.renderObject = region;
3970
+ attachment.region = region;
3971
+ }
3809
3972
  return attachment;
3810
3973
  }
3811
- newMeshAttachment(skin, name, path) {
3812
- let region = this.atlas.findRegion(path);
3813
- if (!region)
3814
- throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
3815
- region.renderObject = region;
3974
+ newMeshAttachment(skin, name, path, sequence) {
3816
3975
  let attachment = new MeshAttachment(name);
3817
- attachment.region = region;
3976
+ if (sequence != null) {
3977
+ this.loadSequence(name, path, sequence);
3978
+ } else {
3979
+ let region = this.atlas.findRegion(path);
3980
+ if (!region)
3981
+ throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
3982
+ region.renderObject = region;
3983
+ attachment.region = region;
3984
+ }
3818
3985
  return attachment;
3819
3986
  }
3820
3987
  newBoundingBoxAttachment(skin, name) {
@@ -4291,14 +4458,14 @@ var spine = (() => {
4291
4458
  return dataUri.substr(dataUri.indexOf(",") + 1);
4292
4459
  }
4293
4460
  }
4294
- base64ToArrayBuffer(base64) {
4461
+ base64ToUint8Array(base64) {
4295
4462
  var binary_string = window.atob(base64);
4296
4463
  var len = binary_string.length;
4297
4464
  var bytes = new Uint8Array(len);
4298
4465
  for (var i = 0; i < len; i++) {
4299
4466
  bytes[i] = binary_string.charCodeAt(i);
4300
4467
  }
4301
- return bytes.buffer;
4468
+ return bytes;
4302
4469
  }
4303
4470
  dataUriToUint8Array(dataUri) {
4304
4471
  if (!dataUri.startsWith("data:")) {
@@ -4308,7 +4475,7 @@ var spine = (() => {
4308
4475
  if (base64Idx == -1)
4309
4476
  throw new Error("Not a binary data URI.");
4310
4477
  base64Idx += "base64,".length;
4311
- return this.base64ToArrayBuffer(dataUri.substr(base64Idx));
4478
+ return this.base64ToUint8Array(dataUri.substr(base64Idx));
4312
4479
  }
4313
4480
  downloadText(url, success, error) {
4314
4481
  if (this.start(url, success, error))
@@ -5121,17 +5288,11 @@ var spine = (() => {
5121
5288
  setAttachment(attachment) {
5122
5289
  if (this.attachment == attachment)
5123
5290
  return;
5124
- if (!(attachment instanceof VertexAttachment) || !(this.attachment instanceof VertexAttachment) || attachment.deformAttachment != this.attachment.deformAttachment) {
5291
+ if (!(attachment instanceof VertexAttachment) || !(this.attachment instanceof VertexAttachment) || attachment.timelineAttahment != this.attachment.timelineAttahment) {
5125
5292
  this.deform.length = 0;
5126
5293
  }
5127
5294
  this.attachment = attachment;
5128
- this.attachmentTime = this.bone.skeleton.time;
5129
- }
5130
- setAttachmentTime(time) {
5131
- this.attachmentTime = this.bone.skeleton.time - time;
5132
- }
5133
- getAttachmentTime() {
5134
- return this.bone.skeleton.time - this.attachmentTime;
5295
+ this.sequenceIndex = -1;
5135
5296
  }
5136
5297
  setToSetupPose() {
5137
5298
  this.color.setFromColor(this.data.color);
@@ -5357,7 +5518,6 @@ var spine = (() => {
5357
5518
  var Skeleton = class {
5358
5519
  constructor(data) {
5359
5520
  this._updateCache = new Array();
5360
- this.time = 0;
5361
5521
  this.scaleX = 1;
5362
5522
  this.scaleY = 1;
5363
5523
  this.x = 0;
@@ -5791,7 +5951,7 @@ var spine = (() => {
5791
5951
  if (attachment instanceof RegionAttachment) {
5792
5952
  verticesLength = 8;
5793
5953
  vertices = Utils.setArraySize(temp, verticesLength, 0);
5794
- attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
5954
+ attachment.computeWorldVertices(slot, vertices, 0, 2);
5795
5955
  } else if (attachment instanceof MeshAttachment) {
5796
5956
  let mesh = attachment;
5797
5957
  verticesLength = mesh.worldVerticesLength;
@@ -5811,9 +5971,6 @@ var spine = (() => {
5811
5971
  offset.set(minX, minY);
5812
5972
  size.set(maxX - minX, maxY - minY);
5813
5973
  }
5814
- update(delta) {
5815
- this.time += delta;
5816
- }
5817
5974
  };
5818
5975
 
5819
5976
  // spine-core/src/SkeletonData.ts
@@ -6265,9 +6422,10 @@ var spine = (() => {
6265
6422
  let linkedMesh = this.linkedMeshes[i];
6266
6423
  let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
6267
6424
  let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
6268
- linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent : linkedMesh.mesh;
6425
+ linkedMesh.mesh.timelineAttahment = linkedMesh.inheritTimeline ? parent : linkedMesh.mesh;
6269
6426
  linkedMesh.mesh.setParentMesh(parent);
6270
- linkedMesh.mesh.updateUVs();
6427
+ if (linkedMesh.mesh.region != null)
6428
+ linkedMesh.mesh.updateRegion();
6271
6429
  }
6272
6430
  this.linkedMeshes.length = 0;
6273
6431
  n = input.readInt(true);
@@ -6336,9 +6494,10 @@ var spine = (() => {
6336
6494
  let width = input.readFloat();
6337
6495
  let height = input.readFloat();
6338
6496
  let color = input.readInt32();
6497
+ let sequence = this.readSequence(input);
6339
6498
  if (!path)
6340
6499
  path = name;
6341
- let region = this.attachmentLoader.newRegionAttachment(skin, name, path);
6500
+ let region = this.attachmentLoader.newRegionAttachment(skin, name, path, sequence);
6342
6501
  if (!region)
6343
6502
  return null;
6344
6503
  region.path = path;
@@ -6350,7 +6509,9 @@ var spine = (() => {
6350
6509
  region.width = width * scale;
6351
6510
  region.height = height * scale;
6352
6511
  Color.rgba8888ToColor(region.color, color);
6353
- region.updateOffset();
6512
+ region.sequence = sequence;
6513
+ if (sequence == null)
6514
+ region.updateRegion();
6354
6515
  return region;
6355
6516
  }
6356
6517
  case AttachmentType.BoundingBox: {
@@ -6375,6 +6536,7 @@ var spine = (() => {
6375
6536
  let triangles = this.readShortArray(input);
6376
6537
  let vertices = this.readVertices(input, vertexCount);
6377
6538
  let hullLength = input.readInt(true);
6539
+ let sequence = this.readSequence(input);
6378
6540
  let edges = null;
6379
6541
  let width = 0, height = 0;
6380
6542
  if (nonessential) {
@@ -6384,7 +6546,7 @@ var spine = (() => {
6384
6546
  }
6385
6547
  if (!path)
6386
6548
  path = name;
6387
- let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
6549
+ let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence);
6388
6550
  if (!mesh)
6389
6551
  return null;
6390
6552
  mesh.path = path;
@@ -6394,8 +6556,10 @@ var spine = (() => {
6394
6556
  mesh.worldVerticesLength = vertexCount << 1;
6395
6557
  mesh.triangles = triangles;
6396
6558
  mesh.regionUVs = uvs;
6397
- mesh.updateUVs();
6559
+ if (sequence == null)
6560
+ mesh.updateRegion();
6398
6561
  mesh.hullLength = hullLength << 1;
6562
+ mesh.sequence = sequence;
6399
6563
  if (nonessential) {
6400
6564
  mesh.edges = edges;
6401
6565
  mesh.width = width * scale;
@@ -6408,7 +6572,8 @@ var spine = (() => {
6408
6572
  let color = input.readInt32();
6409
6573
  let skinName = input.readStringRef();
6410
6574
  let parent = input.readStringRef();
6411
- let inheritDeform = input.readBoolean();
6575
+ let inheritTimelines = input.readBoolean();
6576
+ let sequence = this.readSequence(input);
6412
6577
  let width = 0, height = 0;
6413
6578
  if (nonessential) {
6414
6579
  width = input.readFloat();
@@ -6416,16 +6581,17 @@ var spine = (() => {
6416
6581
  }
6417
6582
  if (!path)
6418
6583
  path = name;
6419
- let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
6584
+ let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence);
6420
6585
  if (!mesh)
6421
6586
  return null;
6422
6587
  mesh.path = path;
6423
6588
  Color.rgba8888ToColor(mesh.color, color);
6589
+ mesh.sequence = sequence;
6424
6590
  if (nonessential) {
6425
6591
  mesh.width = width * scale;
6426
6592
  mesh.height = height * scale;
6427
6593
  }
6428
- this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent, inheritDeform));
6594
+ this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent, inheritTimelines));
6429
6595
  return mesh;
6430
6596
  }
6431
6597
  case AttachmentType.Path: {
@@ -6484,6 +6650,15 @@ var spine = (() => {
6484
6650
  }
6485
6651
  return null;
6486
6652
  }
6653
+ readSequence(input) {
6654
+ if (!input.readBoolean())
6655
+ return null;
6656
+ let sequence = new Sequence(input.readInt(true));
6657
+ sequence.start = input.readInt(true);
6658
+ sequence.digits = input.readInt(true);
6659
+ sequence.setupIndex = input.readInt(true);
6660
+ return sequence;
6661
+ }
6487
6662
  readVertices(input, vertexCount) {
6488
6663
  let scale = this.scale;
6489
6664
  let verticesLength = vertexCount << 1;
@@ -6726,7 +6901,6 @@ var spine = (() => {
6726
6901
  a = a2;
6727
6902
  }
6728
6903
  timelines.push(timeline);
6729
- break;
6730
6904
  }
6731
6905
  }
6732
6906
  }
@@ -6866,49 +7040,66 @@ var spine = (() => {
6866
7040
  for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
6867
7041
  let attachmentName = input.readStringRef();
6868
7042
  let attachment = skin.getAttachment(slotIndex, attachmentName);
6869
- let weighted = attachment.bones;
6870
- let vertices = attachment.vertices;
6871
- let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
7043
+ let timelineType = input.readByte();
6872
7044
  let frameCount = input.readInt(true);
6873
7045
  let frameLast = frameCount - 1;
6874
- let bezierCount = input.readInt(true);
6875
- let timeline = new DeformTimeline(frameCount, bezierCount, slotIndex, attachment);
6876
- let time = input.readFloat();
6877
- for (let frame = 0, bezier = 0; ; frame++) {
6878
- let deform;
6879
- let end = input.readInt(true);
6880
- if (end == 0)
6881
- deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
6882
- else {
6883
- deform = Utils.newFloatArray(deformLength);
6884
- let start = input.readInt(true);
6885
- end += start;
6886
- if (scale == 1) {
6887
- for (let v = start; v < end; v++)
6888
- deform[v] = input.readFloat();
6889
- } else {
6890
- for (let v = start; v < end; v++)
6891
- deform[v] = input.readFloat() * scale;
6892
- }
6893
- if (!weighted) {
6894
- for (let v = 0, vn = deform.length; v < vn; v++)
6895
- deform[v] += vertices[v];
7046
+ switch (timelineType) {
7047
+ case ATTACHMENT_DEFORM: {
7048
+ let vertexAttachment = attachment;
7049
+ let weighted = vertexAttachment.bones;
7050
+ let vertices = vertexAttachment.vertices;
7051
+ let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
7052
+ let bezierCount = input.readInt(true);
7053
+ let timeline = new DeformTimeline(frameCount, bezierCount, slotIndex, vertexAttachment);
7054
+ let time = input.readFloat();
7055
+ for (let frame = 0, bezier = 0; ; frame++) {
7056
+ let deform;
7057
+ let end = input.readInt(true);
7058
+ if (end == 0)
7059
+ deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
7060
+ else {
7061
+ deform = Utils.newFloatArray(deformLength);
7062
+ let start = input.readInt(true);
7063
+ end += start;
7064
+ if (scale == 1) {
7065
+ for (let v = start; v < end; v++)
7066
+ deform[v] = input.readFloat();
7067
+ } else {
7068
+ for (let v = start; v < end; v++)
7069
+ deform[v] = input.readFloat() * scale;
7070
+ }
7071
+ if (!weighted) {
7072
+ for (let v = 0, vn = deform.length; v < vn; v++)
7073
+ deform[v] += vertices[v];
7074
+ }
7075
+ }
7076
+ timeline.setFrame(frame, time, deform);
7077
+ if (frame == frameLast)
7078
+ break;
7079
+ let time2 = input.readFloat();
7080
+ switch (input.readByte()) {
7081
+ case CURVE_STEPPED:
7082
+ timeline.setStepped(frame);
7083
+ break;
7084
+ case CURVE_BEZIER:
7085
+ setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
7086
+ }
7087
+ time = time2;
6896
7088
  }
7089
+ timelines.push(timeline);
7090
+ break;
6897
7091
  }
6898
- timeline.setFrame(frame, time, deform);
6899
- if (frame == frameLast)
7092
+ case ATTACHMENT_SEQUENCE: {
7093
+ let timeline = new SequenceTimeline(frameCount, slotIndex, attachment);
7094
+ for (let frame = 0; frame < frameCount; frame++) {
7095
+ let time = input.readFloat();
7096
+ let modeAndIndex = input.readInt32();
7097
+ timeline.setFrame(frame, time, SequenceModeValues[modeAndIndex & 15], modeAndIndex >> 4, input.readFloat());
7098
+ }
7099
+ timelines.push(timeline);
6900
7100
  break;
6901
- let time2 = input.readFloat();
6902
- switch (input.readByte()) {
6903
- case CURVE_STEPPED:
6904
- timeline.setStepped(frame);
6905
- break;
6906
- case CURVE_BEZIER:
6907
- setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
6908
7101
  }
6909
- time = time2;
6910
7102
  }
6911
- timelines.push(timeline);
6912
7103
  }
6913
7104
  }
6914
7105
  }
@@ -7055,7 +7246,7 @@ var spine = (() => {
7055
7246
  this.skin = skin;
7056
7247
  this.slotIndex = slotIndex;
7057
7248
  this.parent = parent;
7058
- this.inheritDeform = inheritDeform;
7249
+ this.inheritTimeline = inheritDeform;
7059
7250
  }
7060
7251
  };
7061
7252
  var Vertices = class {
@@ -7133,6 +7324,8 @@ var spine = (() => {
7133
7324
  var SLOT_RGBA2 = 3;
7134
7325
  var SLOT_RGB2 = 4;
7135
7326
  var SLOT_ALPHA = 5;
7327
+ var ATTACHMENT_DEFORM = 0;
7328
+ var ATTACHMENT_SEQUENCE = 1;
7136
7329
  var PATH_POSITION = 0;
7137
7330
  var PATH_SPACING = 1;
7138
7331
  var PATH_MIX = 2;
@@ -7968,9 +8161,10 @@ var spine = (() => {
7968
8161
  let linkedMesh = this.linkedMeshes[i];
7969
8162
  let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
7970
8163
  let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
7971
- linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent : linkedMesh.mesh;
8164
+ linkedMesh.mesh.timelineAttahment = linkedMesh.inheritTimeline ? parent : linkedMesh.mesh;
7972
8165
  linkedMesh.mesh.setParentMesh(parent);
7973
- linkedMesh.mesh.updateUVs();
8166
+ if (linkedMesh.mesh.region != null)
8167
+ linkedMesh.mesh.updateRegion();
7974
8168
  }
7975
8169
  this.linkedMeshes.length = 0;
7976
8170
  if (root.events) {
@@ -8002,7 +8196,8 @@ var spine = (() => {
8002
8196
  switch (getValue(map, "type", "region")) {
8003
8197
  case "region": {
8004
8198
  let path = getValue(map, "path", name);
8005
- let region = this.attachmentLoader.newRegionAttachment(skin, name, path);
8199
+ let sequence = this.readSequence(getValue(map, "sequence", null));
8200
+ let region = this.attachmentLoader.newRegionAttachment(skin, name, path, sequence);
8006
8201
  if (!region)
8007
8202
  return null;
8008
8203
  region.path = path;
@@ -8013,10 +8208,12 @@ var spine = (() => {
8013
8208
  region.rotation = getValue(map, "rotation", 0);
8014
8209
  region.width = map.width * scale;
8015
8210
  region.height = map.height * scale;
8211
+ region.sequence = sequence;
8016
8212
  let color = getValue(map, "color", null);
8017
8213
  if (color)
8018
8214
  region.color.setFromString(color);
8019
- region.updateOffset();
8215
+ if (region.region != null)
8216
+ region.updateRegion();
8020
8217
  return region;
8021
8218
  }
8022
8219
  case "boundingbox": {
@@ -8032,7 +8229,8 @@ var spine = (() => {
8032
8229
  case "mesh":
8033
8230
  case "linkedmesh": {
8034
8231
  let path = getValue(map, "path", name);
8035
- let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
8232
+ let sequence = this.readSequence(getValue(map, "sequence", null));
8233
+ let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence);
8036
8234
  if (!mesh)
8037
8235
  return null;
8038
8236
  mesh.path = path;
@@ -8041,16 +8239,18 @@ var spine = (() => {
8041
8239
  mesh.color.setFromString(color);
8042
8240
  mesh.width = getValue(map, "width", 0) * scale;
8043
8241
  mesh.height = getValue(map, "height", 0) * scale;
8242
+ mesh.sequence = sequence;
8044
8243
  let parent = getValue(map, "parent", null);
8045
8244
  if (parent) {
8046
- this.linkedMeshes.push(new LinkedMesh2(mesh, getValue(map, "skin", null), slotIndex, parent, getValue(map, "deform", true)));
8245
+ this.linkedMeshes.push(new LinkedMesh2(mesh, getValue(map, "skin", null), slotIndex, parent, getValue(map, "timelines", true)));
8047
8246
  return mesh;
8048
8247
  }
8049
8248
  let uvs = map.uvs;
8050
8249
  this.readVertices(map, mesh, uvs.length);
8051
8250
  mesh.triangles = map.triangles;
8052
8251
  mesh.regionUVs = uvs;
8053
- mesh.updateUVs();
8252
+ if (mesh.region != null)
8253
+ mesh.updateRegion();
8054
8254
  mesh.edges = getValue(map, "edges", null);
8055
8255
  mesh.hullLength = getValue(map, "hull", 0) * 2;
8056
8256
  return mesh;
@@ -8101,6 +8301,15 @@ var spine = (() => {
8101
8301
  }
8102
8302
  return null;
8103
8303
  }
8304
+ readSequence(map) {
8305
+ if (map == null)
8306
+ return null;
8307
+ let sequence = new Sequence(getValue(map, "count", 0));
8308
+ sequence.start = getValue(map, "start", 1);
8309
+ sequence.digits = getValue(map, "digits", 0);
8310
+ sequence.setupIndex = getValue(map, "setup", 0);
8311
+ return sequence;
8312
+ }
8104
8313
  readVertices(map, attachment, verticesLength) {
8105
8314
  let scale = this.scale;
8106
8315
  attachment.worldVerticesLength = verticesLength;
@@ -8145,7 +8354,7 @@ var spine = (() => {
8145
8354
  let timeline = new AttachmentTimeline(frames, slotIndex);
8146
8355
  for (let frame = 0; frame < frames; frame++) {
8147
8356
  let keyMap = timelineMap[frame];
8148
- timeline.setFrame(frame, getValue(keyMap, "time", 0), keyMap.name);
8357
+ timeline.setFrame(frame, getValue(keyMap, "time", 0), getValue(keyMap, "name", null));
8149
8358
  }
8150
8359
  timelines.push(timeline);
8151
8360
  } else if (timelineName == "rgba") {
@@ -8447,56 +8656,74 @@ var spine = (() => {
8447
8656
  }
8448
8657
  }
8449
8658
  }
8450
- if (map.deform) {
8451
- for (let deformName in map.deform) {
8452
- let deformMap = map.deform[deformName];
8453
- let skin = skeletonData.findSkin(deformName);
8454
- for (let slotName in deformMap) {
8455
- let slotMap = deformMap[slotName];
8456
- let slotIndex = skeletonData.findSlot(slotName).index;
8457
- for (let timelineName in slotMap) {
8458
- let timelineMap = slotMap[timelineName];
8459
- let keyMap = timelineMap[0];
8460
- if (!keyMap)
8461
- continue;
8462
- let attachment = skin.getAttachment(slotIndex, timelineName);
8463
- let weighted = attachment.bones;
8464
- let vertices = attachment.vertices;
8465
- let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
8466
- let timeline = new DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, attachment);
8467
- let time = getValue(keyMap, "time", 0);
8468
- for (let frame = 0, bezier = 0; ; frame++) {
8469
- let deform;
8470
- let verticesValue = getValue(keyMap, "vertices", null);
8471
- if (!verticesValue)
8472
- deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
8473
- else {
8474
- deform = Utils.newFloatArray(deformLength);
8475
- let start = getValue(keyMap, "offset", 0);
8476
- Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
8477
- if (scale != 1) {
8478
- for (let i = start, n = i + verticesValue.length; i < n; i++)
8479
- deform[i] *= scale;
8659
+ if (map.attachments) {
8660
+ for (let attachmentsName in map.attachments) {
8661
+ let attachmentsMap = map.attachments[attachmentsName];
8662
+ let skin = skeletonData.findSkin(attachmentsName);
8663
+ for (let slotMapName in attachmentsMap) {
8664
+ let slotMap = attachmentsMap[slotMapName];
8665
+ let slotIndex = skeletonData.findSlot(slotMapName).index;
8666
+ for (let attachmentMapName in slotMap) {
8667
+ let attachmentMap = slotMap[attachmentMapName];
8668
+ let attachment = skin.getAttachment(slotIndex, attachmentMapName);
8669
+ for (let timelineMapName in attachmentMap) {
8670
+ let timelineMap = attachmentMap[timelineMapName];
8671
+ let keyMap = timelineMap[0];
8672
+ if (!keyMap)
8673
+ continue;
8674
+ if (timelineMapName == "deform") {
8675
+ let weighted = attachment.bones;
8676
+ let vertices = attachment.vertices;
8677
+ let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
8678
+ let timeline = new DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, attachment);
8679
+ let time = getValue(keyMap, "time", 0);
8680
+ for (let frame = 0, bezier = 0; ; frame++) {
8681
+ let deform;
8682
+ let verticesValue = getValue(keyMap, "vertices", null);
8683
+ if (!verticesValue)
8684
+ deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
8685
+ else {
8686
+ deform = Utils.newFloatArray(deformLength);
8687
+ let start = getValue(keyMap, "offset", 0);
8688
+ Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
8689
+ if (scale != 1) {
8690
+ for (let i = start, n = i + verticesValue.length; i < n; i++)
8691
+ deform[i] *= scale;
8692
+ }
8693
+ if (!weighted) {
8694
+ for (let i = 0; i < deformLength; i++)
8695
+ deform[i] += vertices[i];
8696
+ }
8697
+ }
8698
+ timeline.setFrame(frame, time, deform);
8699
+ let nextMap = timelineMap[frame + 1];
8700
+ if (!nextMap) {
8701
+ timeline.shrink(bezier);
8702
+ break;
8703
+ }
8704
+ let time2 = getValue(nextMap, "time", 0);
8705
+ let curve = keyMap.curve;
8706
+ if (curve)
8707
+ bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1);
8708
+ time = time2;
8709
+ keyMap = nextMap;
8480
8710
  }
8481
- if (!weighted) {
8482
- for (let i = 0; i < deformLength; i++)
8483
- deform[i] += vertices[i];
8711
+ timelines.push(timeline);
8712
+ } else if (timelineMapName == "sequence") {
8713
+ let timeline = new SequenceTimeline(timelineMap.length, slotIndex, attachment);
8714
+ let lastDelay = 0;
8715
+ for (let frame = 0; frame < timelineMap.length; frame++) {
8716
+ let delay = getValue(keyMap, "delay", lastDelay);
8717
+ let time = getValue(keyMap, "time", 0);
8718
+ let mode = SequenceMode[getValue(keyMap, "mode", "hold")];
8719
+ let index = getValue(keyMap, "index", 0);
8720
+ timeline.setFrame(frame, time, mode, index, delay);
8721
+ lastDelay = delay;
8722
+ keyMap = timelineMap[frame + 1];
8484
8723
  }
8724
+ timelines.push(timeline);
8485
8725
  }
8486
- timeline.setFrame(frame, time, deform);
8487
- let nextMap = timelineMap[frame + 1];
8488
- if (!nextMap) {
8489
- timeline.shrink(bezier);
8490
- break;
8491
- }
8492
- let time2 = getValue(nextMap, "time", 0);
8493
- let curve = keyMap.curve;
8494
- if (curve)
8495
- bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1);
8496
- time = time2;
8497
- keyMap = nextMap;
8498
8726
  }
8499
- timelines.push(timeline);
8500
8727
  }
8501
8728
  }
8502
8729
  }
@@ -8560,7 +8787,7 @@ var spine = (() => {
8560
8787
  this.skin = skin;
8561
8788
  this.slotIndex = slotIndex;
8562
8789
  this.parent = parent;
8563
- this.inheritDeform = inheritDeform;
8790
+ this.inheritTimeline = inheritDeform;
8564
8791
  }
8565
8792
  };
8566
8793
  function readTimeline12(keys, timeline, defaultValue, scale) {
@@ -9254,14 +9481,13 @@ var spine = (() => {
9254
9481
  // spine-webgl/src/Input.ts
9255
9482
  var Input = class {
9256
9483
  constructor(element) {
9257
- this.lastX = 0;
9258
- this.lastY = 0;
9484
+ this.mouseX = 0;
9485
+ this.mouseY = 0;
9259
9486
  this.buttonDown = false;
9260
- this.currTouch = null;
9487
+ this.touch0 = null;
9488
+ this.touch1 = null;
9489
+ this.initialPinchDistance = 0;
9261
9490
  this.listeners = new Array();
9262
- this.touchesPool = new Pool(() => {
9263
- return new Touch(0, 0, 0);
9264
- });
9265
9491
  this.element = element;
9266
9492
  this.setupCallbacks(element);
9267
9493
  }
@@ -9269,15 +9495,14 @@ var spine = (() => {
9269
9495
  let mouseDown = (ev) => {
9270
9496
  if (ev instanceof MouseEvent) {
9271
9497
  let rect = element.getBoundingClientRect();
9272
- let x = ev.clientX - rect.left;
9273
- let y = ev.clientY - rect.top;
9274
- let listeners = this.listeners;
9275
- for (let i = 0; i < listeners.length; i++)
9276
- if (listeners[i].down)
9277
- listeners[i].down(x, y);
9278
- this.lastX = x;
9279
- this.lastY = y;
9498
+ this.mouseX = ev.clientX - rect.left;
9499
+ ;
9500
+ this.mouseY = ev.clientY - rect.top;
9280
9501
  this.buttonDown = true;
9502
+ this.listeners.map((listener) => {
9503
+ if (listener.down)
9504
+ listener.down(this.mouseX, this.mouseY);
9505
+ });
9281
9506
  document.addEventListener("mousemove", mouseMove);
9282
9507
  document.addEventListener("mouseup", mouseUp);
9283
9508
  }
@@ -9285,138 +9510,154 @@ var spine = (() => {
9285
9510
  let mouseMove = (ev) => {
9286
9511
  if (ev instanceof MouseEvent) {
9287
9512
  let rect = element.getBoundingClientRect();
9288
- let x = ev.clientX - rect.left;
9289
- let y = ev.clientY - rect.top;
9290
- let listeners = this.listeners;
9291
- for (let i = 0; i < listeners.length; i++) {
9513
+ this.mouseX = ev.clientX - rect.left;
9514
+ ;
9515
+ this.mouseY = ev.clientY - rect.top;
9516
+ this.listeners.map((listener) => {
9292
9517
  if (this.buttonDown) {
9293
- if (listeners[i].dragged)
9294
- listeners[i].dragged(x, y);
9518
+ if (listener.dragged)
9519
+ listener.dragged(this.mouseX, this.mouseY);
9295
9520
  } else {
9296
- if (listeners[i].moved)
9297
- listeners[i].moved(x, y);
9521
+ if (listener.moved)
9522
+ listener.moved(this.mouseX, this.mouseY);
9298
9523
  }
9299
- }
9300
- this.lastX = x;
9301
- this.lastY = y;
9524
+ });
9302
9525
  }
9303
9526
  };
9304
9527
  let mouseUp = (ev) => {
9305
9528
  if (ev instanceof MouseEvent) {
9306
9529
  let rect = element.getBoundingClientRect();
9307
- let x = ev.clientX - rect.left;
9308
- let y = ev.clientY - rect.top;
9309
- let listeners = this.listeners;
9310
- for (let i = 0; i < listeners.length; i++)
9311
- if (listeners[i].up)
9312
- listeners[i].up(x, y);
9313
- this.lastX = x;
9314
- this.lastY = y;
9530
+ this.mouseX = ev.clientX - rect.left;
9531
+ ;
9532
+ this.mouseY = ev.clientY - rect.top;
9315
9533
  this.buttonDown = false;
9534
+ this.listeners.map((listener) => {
9535
+ if (listener.up)
9536
+ listener.up(this.mouseX, this.mouseY);
9537
+ });
9316
9538
  document.removeEventListener("mousemove", mouseMove);
9317
9539
  document.removeEventListener("mouseup", mouseUp);
9318
9540
  }
9319
9541
  };
9542
+ let mouseWheel = (e) => {
9543
+ e.preventDefault();
9544
+ let deltaY = e.deltaY;
9545
+ if (e.deltaMode == WheelEvent.DOM_DELTA_LINE)
9546
+ deltaY *= 8;
9547
+ if (e.deltaMode == WheelEvent.DOM_DELTA_PAGE)
9548
+ deltaY *= 24;
9549
+ this.listeners.map((listener) => {
9550
+ if (listener.wheel)
9551
+ listener.wheel(e.deltaY);
9552
+ });
9553
+ };
9320
9554
  element.addEventListener("mousedown", mouseDown, true);
9321
9555
  element.addEventListener("mousemove", mouseMove, true);
9322
9556
  element.addEventListener("mouseup", mouseUp, true);
9557
+ element.addEventListener("wheel", mouseWheel, true);
9323
9558
  element.addEventListener("touchstart", (ev) => {
9324
- if (!this.currTouch) {
9559
+ if (!this.touch0 || !this.touch1) {
9325
9560
  var touches = ev.changedTouches;
9326
- for (var i = 0; i < touches.length; i++) {
9327
- var touch = touches[i];
9328
- let rect = element.getBoundingClientRect();
9329
- let x = touch.clientX - rect.left;
9330
- let y = touch.clientY - rect.top;
9331
- this.currTouch = this.touchesPool.obtain();
9332
- this.currTouch.identifier = touch.identifier;
9333
- this.currTouch.x = x;
9334
- this.currTouch.y = y;
9335
- break;
9336
- }
9337
- let listeners = this.listeners;
9338
- for (let i2 = 0; i2 < listeners.length; i2++) {
9339
- if (listeners[i2].down)
9340
- listeners[i2].down(this.currTouch.x, this.currTouch.y);
9341
- }
9342
- this.lastX = this.currTouch.x;
9343
- this.lastY = this.currTouch.y;
9561
+ let nativeTouch = touches.item(0);
9562
+ let rect = element.getBoundingClientRect();
9563
+ let x = nativeTouch.clientX - rect.left;
9564
+ let y = nativeTouch.clientY - rect.top;
9565
+ let touch = new Touch(nativeTouch.identifier, x, y);
9566
+ this.mouseX = x;
9567
+ this.mouseY = y;
9344
9568
  this.buttonDown = true;
9345
- }
9346
- ev.preventDefault();
9347
- }, false);
9348
- element.addEventListener("touchend", (ev) => {
9349
- if (this.currTouch) {
9350
- var touches = ev.changedTouches;
9351
- for (var i = 0; i < touches.length; i++) {
9352
- var touch = touches[i];
9353
- if (this.currTouch.identifier === touch.identifier) {
9354
- let rect = element.getBoundingClientRect();
9355
- let x = this.currTouch.x = touch.clientX - rect.left;
9356
- let y = this.currTouch.y = touch.clientY - rect.top;
9357
- this.touchesPool.free(this.currTouch);
9358
- let listeners = this.listeners;
9359
- for (let i2 = 0; i2 < listeners.length; i2++) {
9360
- if (listeners[i2].up)
9361
- listeners[i2].up(x, y);
9362
- }
9363
- this.lastX = x;
9364
- this.lastY = y;
9365
- this.buttonDown = false;
9366
- this.currTouch = null;
9367
- break;
9368
- }
9569
+ if (!this.touch0) {
9570
+ this.touch0 = touch;
9571
+ this.listeners.map((listener) => {
9572
+ if (listener.down)
9573
+ listener.down(touch.x, touch.y);
9574
+ });
9575
+ } else if (!this.touch1) {
9576
+ this.touch1 = touch;
9577
+ let dx = this.touch1.x - this.touch0.x;
9578
+ let dy = this.touch1.x - this.touch0.x;
9579
+ this.initialPinchDistance = Math.sqrt(dx * dx + dy * dy);
9580
+ this.listeners.map((listener) => {
9581
+ if (listener.zoom)
9582
+ listener.zoom(this.initialPinchDistance, this.initialPinchDistance);
9583
+ });
9369
9584
  }
9370
9585
  }
9371
9586
  ev.preventDefault();
9372
9587
  }, false);
9373
- element.addEventListener("touchcancel", (ev) => {
9374
- if (this.currTouch) {
9588
+ element.addEventListener("touchmove", (ev) => {
9589
+ if (this.touch0) {
9375
9590
  var touches = ev.changedTouches;
9591
+ let rect = element.getBoundingClientRect();
9376
9592
  for (var i = 0; i < touches.length; i++) {
9377
- var touch = touches[i];
9378
- if (this.currTouch.identifier === touch.identifier) {
9379
- let rect = element.getBoundingClientRect();
9380
- let x = this.currTouch.x = touch.clientX - rect.left;
9381
- let y = this.currTouch.y = touch.clientY - rect.top;
9382
- this.touchesPool.free(this.currTouch);
9383
- let listeners = this.listeners;
9384
- for (let i2 = 0; i2 < listeners.length; i2++) {
9385
- if (listeners[i2].up)
9386
- listeners[i2].up(x, y);
9387
- }
9388
- this.lastX = x;
9389
- this.lastY = y;
9390
- this.buttonDown = false;
9391
- this.currTouch = null;
9392
- break;
9593
+ var nativeTouch = touches[i];
9594
+ let x = nativeTouch.clientX - rect.left;
9595
+ let y = nativeTouch.clientY - rect.top;
9596
+ if (this.touch0.identifier === nativeTouch.identifier) {
9597
+ this.touch0.x = this.mouseX = x;
9598
+ this.touch0.y = this.mouseY = y;
9599
+ this.listeners.map((listener) => {
9600
+ if (listener.dragged)
9601
+ listener.dragged(x, y);
9602
+ });
9603
+ }
9604
+ if (this.touch1 && this.touch1.identifier === nativeTouch.identifier) {
9605
+ this.touch1.x = this.mouseX = x;
9606
+ this.touch1.y = this.mouseY = y;
9393
9607
  }
9394
9608
  }
9609
+ if (this.touch0 && this.touch1) {
9610
+ let dx = this.touch1.x - this.touch0.x;
9611
+ let dy = this.touch1.x - this.touch0.x;
9612
+ let distance = Math.sqrt(dx * dx + dy * dy);
9613
+ this.listeners.map((listener) => {
9614
+ if (listener.zoom)
9615
+ listener.zoom(this.initialPinchDistance, distance);
9616
+ });
9617
+ }
9395
9618
  }
9396
9619
  ev.preventDefault();
9397
9620
  }, false);
9398
- element.addEventListener("touchmove", (ev) => {
9399
- if (this.currTouch) {
9621
+ let touchEnd = (ev) => {
9622
+ if (this.touch0) {
9400
9623
  var touches = ev.changedTouches;
9624
+ let rect = element.getBoundingClientRect();
9401
9625
  for (var i = 0; i < touches.length; i++) {
9402
- var touch = touches[i];
9403
- if (this.currTouch.identifier === touch.identifier) {
9404
- let rect = element.getBoundingClientRect();
9405
- let x = touch.clientX - rect.left;
9406
- let y = touch.clientY - rect.top;
9407
- let listeners = this.listeners;
9408
- for (let i2 = 0; i2 < listeners.length; i2++) {
9409
- if (listeners[i2].dragged)
9410
- listeners[i2].dragged(x, y);
9626
+ var nativeTouch = touches[i];
9627
+ let x = nativeTouch.clientX - rect.left;
9628
+ let y = nativeTouch.clientY - rect.top;
9629
+ if (this.touch0.identifier === nativeTouch.identifier) {
9630
+ this.touch0 = null;
9631
+ this.mouseX = x;
9632
+ this.mouseY = y;
9633
+ this.listeners.map((listener) => {
9634
+ if (listener.up)
9635
+ listener.up(x, y);
9636
+ });
9637
+ if (!this.touch1) {
9638
+ this.buttonDown = false;
9639
+ break;
9640
+ } else {
9641
+ this.touch0 = this.touch1;
9642
+ this.touch1 = null;
9643
+ this.mouseX = this.touch0.x;
9644
+ this.mouseX = this.touch0.x;
9645
+ this.buttonDown = true;
9646
+ this.listeners.map((listener) => {
9647
+ if (listener.down)
9648
+ listener.down(this.touch0.x, this.touch0.y);
9649
+ });
9411
9650
  }
9412
- this.lastX = this.currTouch.x = x;
9413
- this.lastY = this.currTouch.y = y;
9414
- break;
9651
+ }
9652
+ if (this.touch1 && this.touch1.identifier) {
9653
+ this.touch1 = null;
9415
9654
  }
9416
9655
  }
9417
9656
  }
9418
9657
  ev.preventDefault();
9419
- }, false);
9658
+ };
9659
+ element.addEventListener("touchend", touchEnd, false);
9660
+ element.addEventListener("touchcancel", touchEnd);
9420
9661
  }
9421
9662
  addListener(listener) {
9422
9663
  this.listeners.push(listener);
@@ -9436,6 +9677,72 @@ var spine = (() => {
9436
9677
  }
9437
9678
  };
9438
9679
 
9680
+ // spine-webgl/src/CameraController.ts
9681
+ var CameraController = class {
9682
+ constructor(canvas, camera) {
9683
+ this.canvas = canvas;
9684
+ this.camera = camera;
9685
+ let cameraX = 0, cameraY = 0, cameraZoom = 0;
9686
+ let mouseX = 0, mouseY = 0;
9687
+ let lastX = 0, lastY = 0;
9688
+ let initialZoom = 0;
9689
+ new Input(canvas).addListener({
9690
+ down: (x, y) => {
9691
+ cameraX = camera.position.x;
9692
+ cameraY = camera.position.y;
9693
+ mouseX = lastX = x;
9694
+ mouseY = lastY = y;
9695
+ initialZoom = camera.zoom;
9696
+ },
9697
+ dragged: (x, y) => {
9698
+ let deltaX = x - mouseX;
9699
+ let deltaY = y - mouseY;
9700
+ let originWorld = camera.screenToWorld(new Vector3(0, 0), canvas.clientWidth, canvas.clientHeight);
9701
+ let deltaWorld = camera.screenToWorld(new Vector3(deltaX, deltaY), canvas.clientWidth, canvas.clientHeight).sub(originWorld);
9702
+ camera.position.set(cameraX - deltaWorld.x, cameraY - deltaWorld.y, 0);
9703
+ camera.update();
9704
+ lastX = x;
9705
+ lastY = y;
9706
+ },
9707
+ wheel: (delta) => {
9708
+ let zoomAmount = delta / 200 * camera.zoom;
9709
+ let newZoom = camera.zoom + zoomAmount;
9710
+ if (newZoom > 0) {
9711
+ let x = 0, y = 0;
9712
+ if (delta < 0) {
9713
+ x = lastX;
9714
+ y = lastY;
9715
+ } else {
9716
+ let viewCenter = new Vector3(canvas.clientWidth / 2 + 15, canvas.clientHeight / 2);
9717
+ let mouseToCenterX = lastX - viewCenter.x;
9718
+ let mouseToCenterY = canvas.clientHeight - 1 - lastY - viewCenter.y;
9719
+ x = viewCenter.x - mouseToCenterX;
9720
+ y = canvas.clientHeight - 1 - viewCenter.y + mouseToCenterY;
9721
+ }
9722
+ let oldDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
9723
+ camera.zoom = newZoom;
9724
+ camera.update();
9725
+ let newDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
9726
+ camera.position.add(oldDistance.sub(newDistance));
9727
+ camera.update();
9728
+ }
9729
+ },
9730
+ zoom: (initialDistance, distance) => {
9731
+ let newZoom = initialDistance / distance;
9732
+ camera.zoom = initialZoom * newZoom;
9733
+ },
9734
+ up: (x, y) => {
9735
+ lastX = x;
9736
+ lastY = y;
9737
+ },
9738
+ moved: (x, y) => {
9739
+ lastX = x;
9740
+ lastY = y;
9741
+ }
9742
+ });
9743
+ }
9744
+ };
9745
+
9439
9746
  // spine-webgl/src/Shader.ts
9440
9747
  var _Shader = class {
9441
9748
  constructor(context, vertexShader, fragmentShader) {
@@ -9888,6 +10195,8 @@ var spine = (() => {
9888
10195
  gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
9889
10196
  }
9890
10197
  setBlendMode(srcColorBlend, srcAlphaBlend, dstBlend) {
10198
+ if (this.srcColorBlend == srcColorBlend && this.srcAlphaBlend == srcAlphaBlend && this.dstBlend == dstBlend)
10199
+ return;
9891
10200
  this.srcColorBlend = srcColorBlend;
9892
10201
  this.srcAlphaBlend = srcAlphaBlend;
9893
10202
  this.dstBlend = dstBlend;
@@ -10285,9 +10594,9 @@ var spine = (() => {
10285
10594
  continue;
10286
10595
  if (!bone.parent)
10287
10596
  continue;
10288
- let x = skeletonX + bone.data.length * bone.a + bone.worldX;
10289
- let y = skeletonY + bone.data.length * bone.c + bone.worldY;
10290
- shapes.rectLine(true, skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, this.boneWidth * this.scale);
10597
+ let x = bone.data.length * bone.a + bone.worldX;
10598
+ let y = bone.data.length * bone.c + bone.worldY;
10599
+ shapes.rectLine(true, bone.worldX, bone.worldY, x, y, this.boneWidth * this.scale);
10291
10600
  }
10292
10601
  if (this.drawSkeletonXY)
10293
10602
  shapes.x(skeletonX, skeletonY, 4 * this.scale);
@@ -10301,7 +10610,7 @@ var spine = (() => {
10301
10610
  if (attachment instanceof RegionAttachment) {
10302
10611
  let regionAttachment = attachment;
10303
10612
  let vertices = this.vertices;
10304
- regionAttachment.computeWorldVertices(slot.bone, vertices, 0, 2);
10613
+ regionAttachment.computeWorldVertices(slot, vertices, 0, 2);
10305
10614
  shapes.line(vertices[0], vertices[1], vertices[2], vertices[3]);
10306
10615
  shapes.line(vertices[2], vertices[3], vertices[4], vertices[5]);
10307
10616
  shapes.line(vertices[4], vertices[5], vertices[6], vertices[7]);
@@ -10402,7 +10711,7 @@ var spine = (() => {
10402
10711
  let bone = bones[i];
10403
10712
  if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
10404
10713
  continue;
10405
- shapes.circle(true, skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * this.scale, _SkeletonDebugRenderer.GREEN, 8);
10714
+ shapes.circle(true, bone.worldX, bone.worldY, 3 * this.scale, _SkeletonDebugRenderer.GREEN, 8);
10406
10715
  }
10407
10716
  }
10408
10717
  if (this.drawClipping) {
@@ -10506,7 +10815,7 @@ var spine = (() => {
10506
10815
  renderable.vertices = this.vertices;
10507
10816
  renderable.numVertices = 4;
10508
10817
  renderable.numFloats = clippedVertexSize << 2;
10509
- region.computeWorldVertices(slot.bone, renderable.vertices, 0, clippedVertexSize);
10818
+ region.computeWorldVertices(slot, renderable.vertices, 0, clippedVertexSize);
10510
10819
  triangles = _SkeletonRenderer.QUAD_TRIANGLES;
10511
10820
  uvs = region.uvs;
10512
10821
  texture = region.region.renderObject.page.texture;