spine-html 1.22.3 → 1.23.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.
package/dist/index.js CHANGED
@@ -13147,6 +13147,14 @@ class RigPlayer {
13147
13147
  /** Set once anything beyond a plain play on track 0 happened: a mix, another track, a queue, a clear. `seek` and `skin` then cannot replay and refuse. */
13148
13148
  beyondBase = false;
13149
13149
  paused = false;
13150
+ /** `hold(true)`: `advance` moves the physics clock and re-poses at the same track time (#248). */
13151
+ holding = false;
13152
+ /** Set only while a held step is in flight: the step the physics clock moves by in place of the track's zero step. */
13153
+ heldClockStep = null;
13154
+ /** Test-only (#248's planted controls): the held step as a plain advance, as nothing, or a release that replays the time as `seek` does. Not API. */
13155
+ heldPlant = null;
13156
+ /** Handed to every track the player opens as its physics clock: rig-c's render clock of the step, or of the held step while one is in flight. */
13157
+ clockHook = (dt) => physicsClockStep(this.heldClockStep ?? dt);
13150
13158
  pose = null;
13151
13159
  /** The un-overridden pose from the track/tracks (or setup pose when `setSet` is called before `play`). */
13152
13160
  rawPose = null;
@@ -13285,6 +13293,7 @@ class RigPlayer {
13285
13293
  const alpha = options.alpha ?? 1;
13286
13294
  const additive = options.additive ?? false;
13287
13295
  this.paused = false;
13296
+ this.holding = false;
13288
13297
  this.clearSeekCache();
13289
13298
  const plain = track === 0 && mix === 0 && alpha === 1 && !additive;
13290
13299
  if (!plain) this.beyondBase = true;
@@ -13293,7 +13302,7 @@ class RigPlayer {
13293
13302
  this.oracle("animation not supported by the runtime");
13294
13303
  this.animation = name;
13295
13304
  this.loop = loop;
13296
- this.track = openTrack(this.view, name, { loop, reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13305
+ this.track = openTrack(this.view, name, { loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13297
13306
  this.setRawPose(this.initializeSingle(this.track));
13298
13307
  this.applyEnvironment(this.track);
13299
13308
  return;
@@ -13396,7 +13405,7 @@ class RigPlayer {
13396
13405
  this.oracle("track composition");
13397
13406
  if (this.tracks !== null) return this.tracks;
13398
13407
  this.clearSeekCache();
13399
- const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13408
+ const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13400
13409
  const single = this.track;
13401
13410
  const time = single?.trackTime ?? 0;
13402
13411
  if (single !== null && this.animation !== null) {
@@ -13586,6 +13595,46 @@ class RigPlayer {
13586
13595
  resume() {
13587
13596
  this.paused = false;
13588
13597
  }
13598
+ /**
13599
+ * Holds the track time while the physics keeps running (#248). While held,
13600
+ * `advance(dt)` and `frame(dt)` move the physics clock by `dt × timeScale`
13601
+ * (on rig-c's render clock, as a plain step does) and re-pose at the
13602
+ * **same** track time: every animation timeline — bone keys, slot colour,
13603
+ * attachments, deform, draw order — reads what it read, and only what the
13604
+ * physics drives moves, so a rig settles and stays alive on a held frame.
13605
+ * No event or complete fires, `time` stands, and an eased set switch holds
13606
+ * where it is. `hold(false)` releases it: the next step continues from the
13607
+ * physics state the held steps left, with no reset. A rig with no physics
13608
+ * constraint ignores held steps outright — nothing is re-posed. `pause()`
13609
+ * still stops everything, held or not; `play` releases the hold, as it
13610
+ * releases a pause; `seek` keeps it, and replays the time as it always does.
13611
+ */
13612
+ hold(on = true) {
13613
+ if (on !== true && on !== false) throw new Error(`hold expects true or false, got ${JSON.stringify(on)}`);
13614
+ const releasing = this.holding && !on;
13615
+ this.holding = on;
13616
+ if (releasing && this.heldPlant === "reset" && this.animation !== null && this.runtimeFrames === null && !this.beyondBase) this.seek(this.time);
13617
+ }
13618
+ /** Whether `hold(true)` is in force. */
13619
+ get held() {
13620
+ return this.holding;
13621
+ }
13622
+ /** One held step (`hold`): the open track or tracks stepped by 0 while their physics clock moves by `step`. */
13623
+ heldStep(step) {
13624
+ if (!Number.isFinite(step)) throw new Error(`advance step must be finite, got ${String(step)}`);
13625
+ if (this.heldPlant === "freeze") return;
13626
+ if (!this.view.constraints.some((constraint) => constraint.kind === "physics")) return;
13627
+ const live = this.tracks ?? this.track;
13628
+ if (live === null) return;
13629
+ this.heldClockStep = step;
13630
+ let raw;
13631
+ try {
13632
+ raw = live.step(0);
13633
+ } finally {
13634
+ this.heldClockStep = null;
13635
+ }
13636
+ this.setRawPose(raw);
13637
+ }
13589
13638
  /**
13590
13639
  * Moves a single animation on track 0 to `time`: snapshot-backed deterministic
13591
13640
  * seek (#141) that produces the exact pose and physics state of reopening at 0
@@ -13682,14 +13731,14 @@ class RigPlayer {
13682
13731
  let frontier;
13683
13732
  let firstPose;
13684
13733
  if (mode === "tracks") {
13685
- const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13734
+ const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13686
13735
  tracks.setAnimation(0, this.animation, { loop: this.loop, mixDuration: 0 });
13687
13736
  firstPose = tracks.start();
13688
13737
  this.applyPhysicsParameters(tracks);
13689
13738
  this.applyEnvironment(tracks);
13690
13739
  frontier = tracks;
13691
13740
  } else {
13692
- const track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13741
+ const track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13693
13742
  firstPose = this.initializeSingle(track);
13694
13743
  this.applyEnvironment(track);
13695
13744
  frontier = track;
@@ -13708,7 +13757,7 @@ class RigPlayer {
13708
13757
  /** Whatever is open, opened again with track 0's animation as `play` last set it, at pose 0: the single track, or the tracks under `tracks: true`. */
13709
13758
  reopen() {
13710
13759
  if (this.tracks !== null) {
13711
- const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13760
+ const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13712
13761
  tracks.setAnimation(0, this.animation, { loop: this.loop, mixDuration: 0 });
13713
13762
  this.trackCount = 1;
13714
13763
  this.tracks = tracks;
@@ -13717,7 +13766,7 @@ class RigPlayer {
13717
13766
  this.applyEnvironment(tracks);
13718
13767
  return;
13719
13768
  }
13720
- this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13769
+ this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13721
13770
  this.setRawPose(this.initializeSingle(this.track));
13722
13771
  this.applyEnvironment(this.track);
13723
13772
  }
@@ -13767,6 +13816,7 @@ class RigPlayer {
13767
13816
  const step2 = dt * this.timeScale;
13768
13817
  if (this.paused || !(step2 > 0)) return;
13769
13818
  if (!Number.isFinite(step2)) throw new Error(`advance step must be finite, got ${String(step2)}`);
13819
+ if (this.holding && this.heldPlant !== "advance") return;
13770
13820
  const before2 = this.runtimeFrames.pose.trackTime;
13771
13821
  const duration = this.runtimeFrames.model.animations.get(this.animation).duration;
13772
13822
  this.runtimeFrames.pose.trackTime += step2;
@@ -13793,6 +13843,10 @@ class RigPlayer {
13793
13843
  if (this.pose === null) return;
13794
13844
  const step = dt * this.timeScale;
13795
13845
  if (this.paused || !(step > 0)) return;
13846
+ if (this.holding && this.heldPlant !== "advance") {
13847
+ this.heldStep(step);
13848
+ return;
13849
+ }
13796
13850
  this.lastStep = step;
13797
13851
  if (this.easing !== null) this.advanceEase(this.easing, step);
13798
13852
  const tracks = this.tracks;
@@ -14520,7 +14574,7 @@ class RigPlayer {
14520
14574
  this.runtimeFrames = null;
14521
14575
  this.runtimeReadback = null;
14522
14576
  if (this.poserLabel === "runtime") this.poserLabel = `oracle: ${reason}`;
14523
- this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
14577
+ this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
14524
14578
  this.setRawPose(this.track.first);
14525
14579
  if (time > 0) this.setRawPose(this.track.step(time));
14526
14580
  this.poseGeneration = generation;