spine-html 1.22.3 → 1.24.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
@@ -3530,6 +3530,7 @@ function applyConstraints(bones, world, active, records, previous = null, applie
3530
3530
  if (changed.length > 0) repose(state, changed, inWorld);
3531
3531
  snap(i, "after");
3532
3532
  }
3533
+ settled?.(state);
3533
3534
  return state.world;
3534
3535
  }
3535
3536
  function planShape(c) {
@@ -4231,7 +4232,7 @@ function posedBoneStep(doc, timelines, t, plant, constraints, sliders, step) {
4231
4232
  const setupRecords = constraintRecords(doc);
4232
4233
  const records = pathDeformed(doc, posedRecords(setupRecords, constraints, t), timelines, t, plant);
4233
4234
  const previous = setupRecords.some((r) => r.kind === "path") ? applyConstraints(doc.bones, (plant.evaluate ?? worldTransforms)(doc.bones, active), active, plant.constraints ? plant.constraints(setupRecords) : setupRecords, null, void 0, void 0, void 0, solverRules(plant.solver)) : null;
4234
- world = applyConstraints(bones, initialWorld, active, plant.constraints ? plant.constraints(records) : records, previous, sliders, void 0, void 0, solverRules(plant.solver));
4235
+ world = applyConstraints(bones, initialWorld, active, plant.constraints ? plant.constraints(records) : records, previous, sliders, void 0, plant.readLocals === void 0 ? void 0 : (state) => plant.readLocals?.(state.bones, sliders ?? []), solverRules(plant.solver));
4235
4236
  if (stage !== void 0) stage.end("constraints");
4236
4237
  }
4237
4238
  for (const b of bones) if (world.get(b.name) === void 0) throw new CoreInputError(`the evaluator returned no transform for bone "${b.name}"`);
@@ -4252,7 +4253,7 @@ function steppedLocals(doc, bones, plant, records, physicsKeyed, t, sliders, ste
4252
4253
  stage.begin("constraints");
4253
4254
  }
4254
4255
  const stepped = stepPhysicsRecords(records(), physicsKeyed, t, active, step.ctx, step.before);
4255
- const world = applyConstraints(bones, initialWorld, active, plant.constraints ? plant.constraints(stepped) : stepped, null, sliders, step.ctx, void 0, solverRules(plant.solver));
4256
+ const world = applyConstraints(bones, initialWorld, active, plant.constraints ? plant.constraints(stepped) : stepped, null, sliders, step.ctx, plant.readLocals === void 0 ? void 0 : (state) => plant.readLocals?.(state.bones, sliders ?? []), solverRules(plant.solver));
4256
4257
  if (stage !== void 0) stage.end("constraints");
4257
4258
  for (const b of bones) if (world.get(b.name) === void 0) throw new CoreInputError(`the evaluator returned no transform for bone "${b.name}"`);
4258
4259
  return { bones, world, active, round: plant.round ?? gridRound };
@@ -4967,7 +4968,7 @@ function poseSetup(doc, plant = {}, physics) {
4967
4968
  if (bonesWhy === null) {
4968
4969
  const active = activeBones(doc);
4969
4970
  const records = constraintRecords(doc);
4970
- setupWorld = applyConstraints(doc.bones, evaluate(doc.bones, active), active, plant.constraints ? plant.constraints(records) : records, null, applied, physics, void 0, solverRules(plant.solver));
4971
+ setupWorld = applyConstraints(doc.bones, evaluate(doc.bones, active), active, plant.constraints ? plant.constraints(records) : records, null, applied, physics, plant.readLocals === void 0 ? void 0 : (state) => plant.readLocals?.(state.bones, applied), solverRules(plant.solver));
4971
4972
  const world = setupWorld;
4972
4973
  bones = doc.bones.map((b) => {
4973
4974
  const t = world.get(b.name);
@@ -13147,6 +13148,14 @@ class RigPlayer {
13147
13148
  /** 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
13149
  beyondBase = false;
13149
13150
  paused = false;
13151
+ /** `hold(true)`: `advance` moves the physics clock and re-poses at the same track time (#248). */
13152
+ holding = false;
13153
+ /** Set only while a held step is in flight: the step the physics clock moves by in place of the track's zero step. */
13154
+ heldClockStep = null;
13155
+ /** 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. */
13156
+ heldPlant = null;
13157
+ /** 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. */
13158
+ clockHook = (dt) => physicsClockStep(this.heldClockStep ?? dt);
13150
13159
  pose = null;
13151
13160
  /** The un-overridden pose from the track/tracks (or setup pose when `setSet` is called before `play`). */
13152
13161
  rawPose = null;
@@ -13285,6 +13294,7 @@ class RigPlayer {
13285
13294
  const alpha = options.alpha ?? 1;
13286
13295
  const additive = options.additive ?? false;
13287
13296
  this.paused = false;
13297
+ this.holding = false;
13288
13298
  this.clearSeekCache();
13289
13299
  const plain = track === 0 && mix === 0 && alpha === 1 && !additive;
13290
13300
  if (!plain) this.beyondBase = true;
@@ -13293,7 +13303,7 @@ class RigPlayer {
13293
13303
  this.oracle("animation not supported by the runtime");
13294
13304
  this.animation = name;
13295
13305
  this.loop = loop;
13296
- this.track = openTrack(this.view, name, { loop, reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13306
+ this.track = openTrack(this.view, name, { loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13297
13307
  this.setRawPose(this.initializeSingle(this.track));
13298
13308
  this.applyEnvironment(this.track);
13299
13309
  return;
@@ -13396,7 +13406,7 @@ class RigPlayer {
13396
13406
  this.oracle("track composition");
13397
13407
  if (this.tracks !== null) return this.tracks;
13398
13408
  this.clearSeekCache();
13399
- const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13409
+ const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13400
13410
  const single = this.track;
13401
13411
  const time = single?.trackTime ?? 0;
13402
13412
  if (single !== null && this.animation !== null) {
@@ -13586,6 +13596,46 @@ class RigPlayer {
13586
13596
  resume() {
13587
13597
  this.paused = false;
13588
13598
  }
13599
+ /**
13600
+ * Holds the track time while the physics keeps running (#248). While held,
13601
+ * `advance(dt)` and `frame(dt)` move the physics clock by `dt × timeScale`
13602
+ * (on rig-c's render clock, as a plain step does) and re-pose at the
13603
+ * **same** track time: every animation timeline — bone keys, slot colour,
13604
+ * attachments, deform, draw order — reads what it read, and only what the
13605
+ * physics drives moves, so a rig settles and stays alive on a held frame.
13606
+ * No event or complete fires, `time` stands, and an eased set switch holds
13607
+ * where it is. `hold(false)` releases it: the next step continues from the
13608
+ * physics state the held steps left, with no reset. A rig with no physics
13609
+ * constraint ignores held steps outright — nothing is re-posed. `pause()`
13610
+ * still stops everything, held or not; `play` releases the hold, as it
13611
+ * releases a pause; `seek` keeps it, and replays the time as it always does.
13612
+ */
13613
+ hold(on = true) {
13614
+ if (on !== true && on !== false) throw new Error(`hold expects true or false, got ${JSON.stringify(on)}`);
13615
+ const releasing = this.holding && !on;
13616
+ this.holding = on;
13617
+ if (releasing && this.heldPlant === "reset" && this.animation !== null && this.runtimeFrames === null && !this.beyondBase) this.seek(this.time);
13618
+ }
13619
+ /** Whether `hold(true)` is in force. */
13620
+ get held() {
13621
+ return this.holding;
13622
+ }
13623
+ /** One held step (`hold`): the open track or tracks stepped by 0 while their physics clock moves by `step`. */
13624
+ heldStep(step) {
13625
+ if (!Number.isFinite(step)) throw new Error(`advance step must be finite, got ${String(step)}`);
13626
+ if (this.heldPlant === "freeze") return;
13627
+ if (!this.view.constraints.some((constraint) => constraint.kind === "physics")) return;
13628
+ const live = this.tracks ?? this.track;
13629
+ if (live === null) return;
13630
+ this.heldClockStep = step;
13631
+ let raw;
13632
+ try {
13633
+ raw = live.step(0);
13634
+ } finally {
13635
+ this.heldClockStep = null;
13636
+ }
13637
+ this.setRawPose(raw);
13638
+ }
13589
13639
  /**
13590
13640
  * Moves a single animation on track 0 to `time`: snapshot-backed deterministic
13591
13641
  * seek (#141) that produces the exact pose and physics state of reopening at 0
@@ -13682,14 +13732,14 @@ class RigPlayer {
13682
13732
  let frontier;
13683
13733
  let firstPose;
13684
13734
  if (mode === "tracks") {
13685
- const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13735
+ const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13686
13736
  tracks.setAnimation(0, this.animation, { loop: this.loop, mixDuration: 0 });
13687
13737
  firstPose = tracks.start();
13688
13738
  this.applyPhysicsParameters(tracks);
13689
13739
  this.applyEnvironment(tracks);
13690
13740
  frontier = tracks;
13691
13741
  } else {
13692
- const track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13742
+ const track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13693
13743
  firstPose = this.initializeSingle(track);
13694
13744
  this.applyEnvironment(track);
13695
13745
  frontier = track;
@@ -13708,7 +13758,7 @@ class RigPlayer {
13708
13758
  /** 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
13759
  reopen() {
13710
13760
  if (this.tracks !== null) {
13711
- const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13761
+ const tracks = openTracks(this.view, { reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13712
13762
  tracks.setAnimation(0, this.animation, { loop: this.loop, mixDuration: 0 });
13713
13763
  this.trackCount = 1;
13714
13764
  this.tracks = tracks;
@@ -13717,7 +13767,7 @@ class RigPlayer {
13717
13767
  this.applyEnvironment(tracks);
13718
13768
  return;
13719
13769
  }
13720
- this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: physicsClockStep });
13770
+ this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
13721
13771
  this.setRawPose(this.initializeSingle(this.track));
13722
13772
  this.applyEnvironment(this.track);
13723
13773
  }
@@ -13767,6 +13817,7 @@ class RigPlayer {
13767
13817
  const step2 = dt * this.timeScale;
13768
13818
  if (this.paused || !(step2 > 0)) return;
13769
13819
  if (!Number.isFinite(step2)) throw new Error(`advance step must be finite, got ${String(step2)}`);
13820
+ if (this.holding && this.heldPlant !== "advance") return;
13770
13821
  const before2 = this.runtimeFrames.pose.trackTime;
13771
13822
  const duration = this.runtimeFrames.model.animations.get(this.animation).duration;
13772
13823
  this.runtimeFrames.pose.trackTime += step2;
@@ -13793,6 +13844,10 @@ class RigPlayer {
13793
13844
  if (this.pose === null) return;
13794
13845
  const step = dt * this.timeScale;
13795
13846
  if (this.paused || !(step > 0)) return;
13847
+ if (this.holding && this.heldPlant !== "advance") {
13848
+ this.heldStep(step);
13849
+ return;
13850
+ }
13796
13851
  this.lastStep = step;
13797
13852
  if (this.easing !== null) this.advanceEase(this.easing, step);
13798
13853
  const tracks = this.tracks;
@@ -14520,7 +14575,7 @@ class RigPlayer {
14520
14575
  this.runtimeFrames = null;
14521
14576
  this.runtimeReadback = null;
14522
14577
  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 });
14578
+ this.track = openTrack(this.view, this.animation, { loop: this.loop, reset: "animation", adjust: this.adjustHook, clock: this.clockHook });
14524
14579
  this.setRawPose(this.track.first);
14525
14580
  if (time > 0) this.setRawPose(this.track.step(time));
14526
14581
  this.poseGeneration = generation;