@wardic/solid 1.0.0-rc.7 → 1.0.0-rc.9

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.
Files changed (69) hide show
  1. package/dist/browser/animation-controls.js +1 -1
  2. package/dist/browser/animation-controls.js.map +1 -1
  3. package/dist/browser/index.js +1 -1
  4. package/dist/browser/layout-member.js +13 -5
  5. package/dist/browser/layout-member.js.map +1 -1
  6. package/dist/browser/presence-controller.js +108 -28
  7. package/dist/browser/presence-controller.js.map +1 -1
  8. package/dist/browser/retarget-legs.js +6 -3
  9. package/dist/browser/retarget-legs.js.map +1 -1
  10. package/dist/browser/spine.js +33 -6
  11. package/dist/browser/spine.js.map +1 -1
  12. package/dist/browser/unstable/v2/ward.js +8 -1
  13. package/dist/browser/unstable/v2/ward.js.map +1 -1
  14. package/dist/browser/variant-target.js +6 -1
  15. package/dist/browser/variant-target.js.map +1 -1
  16. package/dist/server/animation-controls.js +1 -1
  17. package/dist/server/animation-controls.js.map +1 -1
  18. package/dist/server/index.js +1 -1
  19. package/dist/server/layout-member.js +13 -5
  20. package/dist/server/layout-member.js.map +1 -1
  21. package/dist/server/presence-controller.js +108 -28
  22. package/dist/server/presence-controller.js.map +1 -1
  23. package/dist/server/retarget-legs.js +6 -3
  24. package/dist/server/retarget-legs.js.map +1 -1
  25. package/dist/server/spine.js +33 -6
  26. package/dist/server/spine.js.map +1 -1
  27. package/dist/server/unstable/v2/ward.js +8 -1
  28. package/dist/server/unstable/v2/ward.js.map +1 -1
  29. package/dist/server/variant-target.js +6 -1
  30. package/dist/server/variant-target.js.map +1 -1
  31. package/dist/solid/animation-controls.d.ts +3 -4
  32. package/dist/solid/animation-controls.d.ts.map +1 -1
  33. package/dist/solid/animation-controls.js +1 -1
  34. package/dist/solid/animation-controls.js.map +1 -1
  35. package/dist/solid/config.d.ts +6 -2
  36. package/dist/solid/config.d.ts.map +1 -1
  37. package/dist/solid/index.d.ts +1 -1
  38. package/dist/solid/index.js +1 -1
  39. package/dist/solid/layout-member.d.ts +15 -5
  40. package/dist/solid/layout-member.d.ts.map +1 -1
  41. package/dist/solid/layout-member.js +15 -5
  42. package/dist/solid/layout-member.js.map +1 -1
  43. package/dist/solid/presence-controller.d.ts.map +1 -1
  44. package/dist/solid/presence-controller.js +100 -22
  45. package/dist/solid/presence-controller.js.map +1 -1
  46. package/dist/solid/retarget-legs.d.ts.map +1 -1
  47. package/dist/solid/retarget-legs.js +4 -3
  48. package/dist/solid/retarget-legs.js.map +1 -1
  49. package/dist/solid/spine.d.ts +12 -2
  50. package/dist/solid/spine.d.ts.map +1 -1
  51. package/dist/solid/spine.js +34 -5
  52. package/dist/solid/spine.js.map +1 -1
  53. package/dist/solid/unstable/v2/ward.d.ts.map +1 -1
  54. package/dist/solid/unstable/v2/ward.jsx +8 -1
  55. package/dist/solid/unstable/v2/ward.jsx.map +1 -1
  56. package/dist/solid/variant-target.d.ts +2 -0
  57. package/dist/solid/variant-target.d.ts.map +1 -1
  58. package/dist/solid/variant-target.js +3 -1
  59. package/dist/solid/variant-target.js.map +1 -1
  60. package/package.json +4 -4
  61. package/src/animation-controls.ts +4 -2
  62. package/src/config.ts +8 -3
  63. package/src/index.ts +1 -1
  64. package/src/layout-member.ts +24 -9
  65. package/src/presence-controller.ts +108 -22
  66. package/src/retarget-legs.ts +4 -3
  67. package/src/spine.ts +43 -8
  68. package/src/unstable/v2/ward.tsx +8 -1
  69. package/src/variant-target.ts +7 -1
@@ -23,7 +23,7 @@
23
23
  */
24
24
  import type * as Box from "@wardic/core/Box"
25
25
  import type * as DefaultTransition from "@wardic/core/DefaultTransition"
26
- import type * as Frame from "@wardic/core/Frame"
26
+ import * as Frame from "@wardic/core/Frame"
27
27
  import type * as FrameLoop from "@wardic/core/FrameLoop"
28
28
  import * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
29
29
  import type * as ReducedMotion from "@wardic/core/ReducedMotion"
@@ -178,7 +178,7 @@ const exitRunOf = (
178
178
  return Effect.suspend(() =>
179
179
  leg.machine().pipe(
180
180
  Machine.run((frame) => {
181
- Object.assign(velocities, frame.velocity)
181
+ velocitiesInto(velocities, frame)
182
182
  return commitFrame(frame)
183
183
  }),
184
184
  ))
@@ -189,6 +189,17 @@ const exitRunOf = (
189
189
  return Effect.suspend(() => leg.machine().pipe(Machine.run(commitFrame)))
190
190
  }
191
191
 
192
+ /** A Numbers leg's Frame's velocities written into `into`: a spring's by index (#663), as it writes no velocity record. */
193
+ const velocitiesInto = (into: Record<string, number>, frame: Frame.MultiPhysics): void => {
194
+ if (Frame.isSpringValues(frame)) {
195
+ Arr.forEach(frame.keys, (key, i) => {
196
+ into[key] = UndefinedOr.getOrThrow(frame.velocities[i])
197
+ })
198
+ return
199
+ }
200
+ Object.assign(into, frame.velocity)
201
+ }
202
+
192
203
  /** How far in each name's keys of an exit start (#297): seconds, by name; `undefined` for an exit that isn't a list's. */
193
204
  type DelayOf = (name: string | undefined) => number
194
205
 
@@ -355,8 +366,12 @@ const parentElementOf = (placed: ReadonlyArray<Placed>): Element | undefined =>
355
366
  /**
356
367
  * The children in Motion's order for a change (#486, its `AnimatePresence`, #3746 there): `now`, with
357
368
  * each of `before`, the children as they were, leavers still exiting among them, that isn't in `now`
358
- * put back right after the staying child it followed, after the others put back there; first, when it
359
- * followed none.
369
+ * put back by Motion 14.9's arithmetic (#675). Walking `before`, each staying child sets the place to
370
+ * just after its own index in `now`, counting every leaver put back so far, and each leaver goes in
371
+ * there; first, while no staying child has set it. While the staying children keep their order, that's
372
+ * right after the staying child it followed, after the others put back there. Under a reorder it can
373
+ * be after a leaver put back after another child: `[a, b, c, d]`, b and d leaving, then `[c, a]`, is
374
+ * `[c, a, d, b]`, where "after the child it followed" would be `[c, d, a, b]`.
360
375
  */
361
376
  const orderOf = (before: ReadonlyArray<HTMLElement>, now: ReadonlyArray<HTMLElement>): ReadonlyArray<HTMLElement> => {
362
377
  const at = new Map(Arr.map(now, (el, i) => [el, i] as const))
@@ -371,20 +386,42 @@ const orderOf = (before: ReadonlyArray<HTMLElement>, now: ReadonlyArray<HTMLElem
371
386
  }
372
387
 
373
388
  /**
374
- * Where the leaver at `i` in `order` goes back (#486): right after the nearest child before it that's on
375
- * the page, or before the nearest one after it; where it was, with neither.
389
+ * Where a leaver goes back (#675), walking the order with a cursor: right after `cursor`, the element
390
+ * before it in the order, already in its place; with none before it, right before `anchor`, where the
391
+ * presence's children start; with neither, where it was. Each leaver is placed against one already in
392
+ * place, never against a leaver that isn't yet, as the nearest neighbour on the page might be (#561's
393
+ * P19).
376
394
  */
377
- const backPlaceOf = (placed: Placed, order: ReadonlyArray<HTMLElement>, i: number): Placed => {
378
- const before = Arr.findLast(Arr.take(order, i), (el) => el.isConnected)
379
- const after = Arr.findFirst(Arr.drop(order, i + 1), (el) => el.isConnected)
380
- return Option.match(before, {
381
- onSome: (el) => ({ el: placed.el, parent: Option.getOrUndefined(Option.fromNullOr(el.parentNode)), next: Option.getOrUndefined(Option.fromNullOr(el.nextSibling)) }),
382
- onNone: () =>
383
- Option.match(after, {
384
- onSome: (el) => ({ el: placed.el, parent: Option.getOrUndefined(Option.fromNullOr(el.parentNode)), next: el }),
385
- onNone: () => placed,
395
+ const backPlaceOf = (placed: Placed, cursor: HTMLElement | undefined, anchor: ChildNode | undefined): Placed =>
396
+ UndefinedOr.match(cursor, {
397
+ onDefined: (at) => ({ ...placedOf(at), el: placed.el }),
398
+ onUndefined: () =>
399
+ UndefinedOr.match(anchor, {
400
+ onDefined: (at) => ({ el: placed.el, parent: Option.getOrUndefined(Option.fromNullOr(at.parentNode)), next: at }),
401
+ onUndefined: () => placed,
386
402
  }),
387
403
  })
404
+
405
+ /**
406
+ * Whether a leaver from an earlier change is at its place already (#675), so a change that doesn't
407
+ * move it leaves it be (its focus, and anything a removal would restart): the next element after
408
+ * `cursor`, text between them left be; with none, the anchor itself, the first of the order on the
409
+ * page; with neither, on the page.
410
+ */
411
+ const isInPlace = (el: HTMLElement, cursor: HTMLElement | undefined, anchor: ChildNode | undefined): boolean =>
412
+ UndefinedOr.match(cursor, {
413
+ onDefined: (at) => at.nextElementSibling === el,
414
+ onUndefined: () =>
415
+ UndefinedOr.match(anchor, {
416
+ onDefined: (at) => at === el,
417
+ onUndefined: () => Predicate.isNotNull(el.parentNode),
418
+ }),
419
+ })
420
+
421
+ /** Whether a node is there and on the page. */
422
+ const isOnPage = (node: ChildNode | undefined): node is ChildNode => {
423
+ if (Predicate.isUndefined(node)) return false
424
+ return node.isConnected
388
425
  }
389
426
 
390
427
  /** Put a retained node back into the parent it left: before its old next sibling while that's still there, else at the end. */
@@ -600,6 +637,9 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
600
637
  // and kept until it's gone. Whether this change popped one, so the projection is told.
601
638
  const pops = new Map<HTMLElement, PopBox>()
602
639
  let popped = false
640
+ // Whether this change moved a leaver from an earlier one to its place (#675), so the projection is
641
+ // told: a twin leaver crossfading in the flow is drawn on its Lead from where it now is.
642
+ let moved = false
603
643
 
604
644
  // Keys (#286, ADR-0048): each Wardic element made under this presence, told as it's made, so a
605
645
  // child's key is known before what goes on the page is decided.
@@ -1096,6 +1136,51 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1096
1136
  UndefinedOr.map(placed.parent, (parent) => reinsert(placed.el, parent, placed.next))
1097
1137
  }
1098
1138
 
1139
+ /**
1140
+ * Every leaver at its place in `order` (#675), walking it with a cursor: a child that stays is where
1141
+ * its framework put it, and each leaver goes right after the element before it in the order, this
1142
+ * change's as they leave, an earlier change's moved there. A framework moves its own nodes around a
1143
+ * leaver it doesn't know of: Solid's swap of `[a, c]` puts `c` before `a`'s next sibling, the leaver
1144
+ * between them. So each change places them all again, as Motion's presence renders every exiting child
1145
+ * at its place.
1146
+ */
1147
+ const placeLeavers = (order: ReadonlyArray<HTMLElement>, kept: ReadonlySet<HTMLElement>, gone: ReadonlyMap<HTMLElement, Placed>): void => {
1148
+ const anchor = anchorOf(order, gone)
1149
+ Arr.reduce<HTMLElement, HTMLElement | undefined>(order, undefined, (cursor, el) => {
1150
+ UndefinedOr.match(gone.get(el), {
1151
+ onDefined: (placed) => left(placed, backPlaceOf(placed, cursor, anchor)),
1152
+ onUndefined: () => {
1153
+ if (Bool.not(kept.has(el))) moveBack(el, cursor, anchor)
1154
+ },
1155
+ })
1156
+ return Bool.match(el.isConnected, { onTrue: () => el, onFalse: () => cursor })
1157
+ })
1158
+ }
1159
+
1160
+ /**
1161
+ * Where the presence's children start, for the leavers no element precedes in the order (#675): the
1162
+ * first element of the order on the page as the walk starts, a child that stays or an earlier
1163
+ * change's leaver. With none, where they ended: the node after one of them at its last place, still on
1164
+ * the page. Solid empties a list beside a sibling around its leavers, its own nodes gone, and that's
1165
+ * the sibling. With neither, `undefined`: nothing of theirs is left, as when Solid clears the parent.
1166
+ */
1167
+ const anchorOf = (order: ReadonlyArray<HTMLElement>, gone: ReadonlyMap<HTMLElement, Placed>): ChildNode | undefined =>
1168
+ Option.getOrUndefined(Option.orElse(Arr.findFirst(order, isOnPage), () => Arr.findFirst(Arr.map(order, (el) => lastNextOf(el, gone)), isOnPage)))
1169
+
1170
+ /** The node after a child at its last place: as the last change left it, or, an earlier leaver, as it left. */
1171
+ const lastNextOf = (el: HTMLElement, gone: ReadonlyMap<HTMLElement, Placed>): ChildNode | undefined =>
1172
+ UndefinedOr.map(UndefinedOr.match(gone.get(el), { onDefined: identity, onUndefined: () => places.get(el) }), (placed) => placed.next)
1173
+
1174
+ /** A leaver from an earlier change, still retained, moved to its place in the walk (#675) unless it's there already. */
1175
+ const moveBack = (el: HTMLElement, cursor: HTMLElement | undefined, anchor: ChildNode | undefined): void => {
1176
+ if (isInPlace(el, cursor, anchor)) return
1177
+ UndefinedOr.map(places.get(el), (placed) => {
1178
+ const back = backPlaceOf(placed, cursor, anchor)
1179
+ UndefinedOr.map(back.parent, (parent) => reinsert(el, parent, back.next))
1180
+ moved = true
1181
+ })
1182
+ }
1183
+
1099
1184
  /** A child that left: retained at `back` (#486), and exiting, unless it's leaving already. */
1100
1185
  const left = (placed: Placed, back: Placed): void => {
1101
1186
  const el = placed.el
@@ -1341,14 +1426,13 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1341
1426
  })
1342
1427
  settleTakeovers()
1343
1428
  }
1344
- // The children that left go back in Motion's order (#486): each right after the staying child it
1345
- // followed before the change, after the leavers back there already; first, when it followed none.
1346
- // Leavers from earlier changes, still exiting, keep their places in it.
1429
+ // The children that left go back in Motion's order (#486), and every leaver from an earlier change,
1430
+ // still exiting, keeps its place in it (#675), one a framework took out (a list emptied) too.
1347
1431
  const gone = new Map(Arr.map(Arr.filter(previous, (placed) => Bool.and(Bool.not(kept.has(placed.el)), Bool.not(takenOver.has(placed.el)))), (placed) => [placed.el, placed] as const))
1348
- const before = Arr.filter(rendered, (el) => Bool.or(Bool.or(kept.has(el), gone.has(el)), Bool.and(el.isConnected, Bool.not(takenOver.has(el)))))
1432
+ const before = Arr.filter(rendered, (el) => Bool.or(Bool.or(kept.has(el), gone.has(el)), Bool.and(Bool.or(el.isConnected, places.has(el)), Bool.not(takenOver.has(el)))))
1349
1433
  const listed = new Set(before)
1350
1434
  const order = orderOf(Arr.appendAll(before, Arr.filter(Arr.map(previous, (placed) => placed.el), (el) => Bool.not(listed.has(el)))), now)
1351
- Arr.forEach(order, (el, i) => UndefinedOr.map(gone.get(el), (placed) => left(placed, backPlaceOf(placed, order, i))))
1435
+ placeLeavers(order, kept, gone)
1352
1436
  rendered = Arr.filter(order, (el) => el.isConnected)
1353
1437
  // A child still exiting that the framework took out since (a list emptied) goes back too.
1354
1438
  Arr.forEach(Arr.fromIterable(places.values()), putBack)
@@ -1360,9 +1444,11 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1360
1444
  Arr.forEach(Arr.fromIterable(registry.keys()), dropDetached)
1361
1445
  Arr.forEach(Arr.fromIterable(watches), dropDetachedWatch)
1362
1446
  // A popped leaver moved its siblings (#277), and so did a child entering (#442): a `layout` one
1363
- // animates into the space, as Motion's presence re-renders its children then.
1364
- if (Bool.and(Bool.or(popped, entered), affectsLayout())) projection.notify()
1447
+ // animates into the space, as Motion's presence re-renders its children then. A leaver moved to its
1448
+ // place (#675) moved itself and them.
1449
+ if (Bool.and(Bool.or(Bool.or(popped, entered), moved), affectsLayout())) projection.notify()
1365
1450
  popped = false
1451
+ moved = false
1366
1452
  // The wards inside the children held until now start, the children on the page (#277). Held
1367
1453
  // children go on together, so none is left held then. (A ward started while its child is held
1368
1454
  // would only wait again: the check saves its re-run.)
@@ -537,10 +537,11 @@ const pathLegOf = (at: (t: number) => Arc.PathPoint, end: Values.Values, transit
537
537
  /** A Path's progress, 0 to 1, on `transition`: a spring's from rest over 1000 (#438), a tween's as a Measured pair's. */
538
538
  const progressOf = (transition: Run): ((dt: number) => Frame.Frame<number>) => {
539
539
  if (transition.type === "spring") {
540
- const spring = Machine.springValues({ progress: 1000 }, { ...(transition as Machine.SpringOptions), velocity: 0 }, { from: { progress: 0 } }).start()
540
+ // Its one key read by index (#663).
541
+ const spring = Machine.springValues({ progress: 1000 }, { ...(transition as Machine.SpringOptions), velocity: 0 }, { from: { progress: 0 }, records: "value" }).start()
541
542
  return (dt) => {
542
543
  const frame = spring(dt)
543
- return { value: UndefinedOr.getOrThrow(frame.value.progress) / 1000, done: frame.done }
544
+ return { value: frame.positions[0] / 1000, done: frame.done }
544
545
  }
545
546
  }
546
547
  return Machine.keyframes([0, 1], transition as Machine.KeyframesOptions).start()
@@ -905,7 +906,7 @@ const legsWith = (
905
906
  // Each key's own velocity, read now; none when the transition gives one, which every key then starts with.
906
907
  let fromVelocity: Record<string, number> = NO_NUMBERS
907
908
  if (Predicate.isUndefined(springOpts.velocity)) fromVelocity = Rec.map(numeric, (_, key) => velocities(key))
908
- legs.push({ _tag: "Numbers", to: numeric, machine: () => Machine.springValues(numeric, springOpts, { from: fromNumeric, velocity: fromVelocity }) })
909
+ legs.push({ _tag: "Numbers", to: numeric, machine: () => Machine.springValues(numeric, springOpts, { from: fromNumeric, velocity: fromVelocity, records: "value" }) })
909
910
  }
910
911
  if (hasKeys(strings)) {
911
912
  const fromStrings: Values.Values = Rec.map(strings, (_, key) => UndefinedOr.getOrThrow(from[key]))
package/src/spine.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import * as BaseValue from "@wardic/core/BaseValue"
18
18
  import type * as DefaultTransition from "@wardic/core/DefaultTransition"
19
- import type * as Frame from "@wardic/core/Frame"
19
+ import * as Frame from "@wardic/core/Frame"
20
20
  import type * as FrameLoop from "@wardic/core/FrameLoop"
21
21
  import * as InterpolatorRegistry from "@wardic/core/InterpolatorRegistry"
22
22
  import * as Machine from "@wardic/core/Machine"
@@ -534,8 +534,6 @@ interface Running extends Machine.RunOptions {
534
534
  count: number
535
535
  /** A frame's values for the keys it still draws: the frame's own while it draws all of them. */
536
536
  values: (value: Values.Values) => Values.Values
537
- /** The same, for a frame's velocities. */
538
- velocities: (velocity: Readonly<Record<string, number>>) => Readonly<Record<string, number>>
539
537
  /** It drew its last frame: its keys landed. */
540
538
  done: boolean
541
539
  /** It gave up a key in this Retarget: what it still draws is worked out at the Retarget's end. */
@@ -555,6 +553,11 @@ interface Running extends Machine.RunOptions {
555
553
  last: Values.Values | undefined
556
554
  before: Values.Values | undefined
557
555
  beforeAt: number
556
+ /**
557
+ * A Numbers leg's last Frame (#663): its keys' velocities are read from it when one is asked for, as
558
+ * a Blend leg's are from its frames, by index from a spring's. None before its first frame.
559
+ */
560
+ physics: Frame.MultiPhysics | undefined
558
561
  }
559
562
 
560
563
  /** No running legs. */
@@ -741,7 +744,6 @@ const runningOf = (to: Values.Values, resolution: Resolution, landing: Landing,
741
744
  resolution,
742
745
  count: 0,
743
746
  values: identity,
744
- velocities: identity,
745
747
  done: false,
746
748
  losing: false,
747
749
  fiber: undefined,
@@ -755,6 +757,7 @@ const runningOf = (to: Values.Values, resolution: Resolution, landing: Landing,
755
757
  last: undefined,
756
758
  before: undefined,
757
759
  beforeAt: Number.NEGATIVE_INFINITY,
760
+ physics: undefined,
758
761
  })
759
762
 
760
763
  /**
@@ -1647,13 +1650,19 @@ export interface Snapshot {
1647
1650
  owners: ReadonlyMap<string, Running | undefined> | undefined
1648
1651
  /** The time now, its provider's Clock's once its spine runs (#460, Q7), {@link frameNow} before. */
1649
1652
  now: () => number
1653
+ /**
1654
+ * Every numeric key's velocity now (#663), given the Snapshot: {@link velocitiesNowOf}, one function
1655
+ * every Snapshot shares. A resolver and Animation controls read these: `velocities` doesn't hold a
1656
+ * spring leg's. A method, so a Snapshot is a resolver's `VariantState`.
1657
+ */
1658
+ velocitiesNow(snapshot: Snapshot): Readonly<Record<string, number>>
1650
1659
  }
1651
1660
 
1652
1661
  /** A Snapshot seeded from the Starting values, velocities 0, so frame 1 flows out of the seed (no snap). */
1653
1662
  export const snapshotOf = (start: Start): Snapshot => emptySnapshotOf({ ...start.initialValues })
1654
1663
 
1655
1664
  /** A Snapshot of `values`, nothing moving: read as it is until a spine reads it. */
1656
- export const emptySnapshotOf = (values: Values.Values): Snapshot => ({ values, velocities: {}, drawnAt: {}, owners: undefined, now: frameNow })
1665
+ export const emptySnapshotOf = (values: Values.Values): Snapshot => ({ values, velocities: {}, drawnAt: {}, owners: undefined, now: frameNow, velocitiesNow: velocitiesNowOf })
1657
1666
 
1658
1667
  // --- Velocities (#464) ---------------------------------------------------------------------------
1659
1668
 
@@ -1661,9 +1670,28 @@ export const emptySnapshotOf = (values: Values.Values): Snapshot => ({ values, v
1661
1670
  const legVelocityOf = (snapshot: Snapshot, running: Running, key: string): number => {
1662
1671
  if (running.kind === "Blend") return blendVelocityOf(running, key)
1663
1672
  if (running.kind === "Snap") return 0
1673
+ if (running.kind === "Numbers") return numbersVelocityOf(snapshot, running, key)
1664
1674
  return velocityOf(snapshot, key)
1665
1675
  }
1666
1676
 
1677
+ /**
1678
+ * A Numbers leg's velocity for `key` (#663): its last Frame's, as it drew it, by index from a spring's
1679
+ * (whose velocity record it doesn't write), from the record of an inertia's; the Snapshot's before its
1680
+ * first frame, or for a key its Frame doesn't have. Per key, per Retarget: guards.
1681
+ */
1682
+ const numbersVelocityOf = (snapshot: Snapshot, running: Running, key: string): number => {
1683
+ const last = running.physics
1684
+ if (Predicate.isUndefined(last)) return velocityOf(snapshot, key)
1685
+ if (Frame.isSpringValues(last)) {
1686
+ const at = last.keys.indexOf(key)
1687
+ if (at < 0) return velocityOf(snapshot, key)
1688
+ return UndefinedOr.getOrThrow(last.velocities[at])
1689
+ }
1690
+ const velocity = last.velocity[key]
1691
+ if (Predicate.isUndefined(velocity)) return velocityOf(snapshot, key)
1692
+ return velocity
1693
+ }
1694
+
1667
1695
  /**
1668
1696
  * `key`'s velocity at `now` (#464, Motion's `getVelocity`): the leg drawing it, once it has drawn a
1669
1697
  * frame, else what the Snapshot holds for it (the last leg to let it go left it, a drag or a seed set
@@ -2155,7 +2183,6 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
2155
2183
  if (running.count === 0) return
2156
2184
  const kept = Arr.filter(Rec.keys(running.targets), (key) => owners.get(key) === running)
2157
2185
  running.values = keepingOnly(kept)
2158
- running.velocities = keepingOnly(kept)
2159
2186
  })
2160
2187
  losing.length = 0
2161
2188
  }
@@ -2228,11 +2255,19 @@ export const makeElementSpine = (options: ElementSpineOptions): ElementSpine =>
2228
2255
  // whatever keeps one copies it or reads it at once.
2229
2256
  const value = running.values(frame.value)
2230
2257
  Object.assign(snapshot.values, value)
2231
- Object.assign(snapshot.velocities, running.velocities(frame.velocity))
2258
+ // Its velocities stay on its Frame (#663), read by index when one is asked for: copied into
2259
+ // the Snapshot each frame, they cost a boxed number a key a frame that only a Retarget read.
2260
+ running.physics = frame
2232
2261
  gate.write(id, value)
2233
2262
  recordFrame(value)
2234
2263
  drew(running, frame.done, snapshot.now())
2235
- if (frame.done) landEndsOf(waiting)
2264
+ if (frame.done) {
2265
+ // Landed, its keys are at rest: the Snapshot says so for whatever reads it after it's gone.
2266
+ Arr.forEach(Rec.keys(value), (key) => {
2267
+ snapshot.velocities[key] = 0
2268
+ })
2269
+ landEndsOf(waiting)
2270
+ }
2236
2271
  return undefined
2237
2272
  }, running)
2238
2273
  )
@@ -1103,6 +1103,13 @@ export function wardWith(config: WardConfig, internal: WardInternals): Ward {
1103
1103
  // The Override stack, compared by value: a change that resolves the same target doesn't Retarget.
1104
1104
  // A keyboard lift turns `whileDrag` on, as a drag does (ADR-0037).
1105
1105
  const lifted = UndefinedOr.match(internal.lifted, { onUndefined: () => constFalse, onDefined: identity })
1106
+ // The target reads the lift through a boundary (#666): an item with no `whileDrag` of its own
1107
+ // resolves the same lifted or not (a dragged parent's name hands down with its own drag on), so
1108
+ // every lift and drop re-ran its target for nothing. A Reorder item's alone: no other ward lifts.
1109
+ const liftedLayer = UndefinedOr.match(internal.lifted, {
1110
+ onUndefined: () => constFalse,
1111
+ onDefined: (isLifted) => createMemo(() => Predicate.isNotUndefined(cfg().whileDrag) && isLifted(), CLIENT_ONLY),
1112
+ })
1106
1113
  const target = createMemo<Resolution>(
1107
1114
  () => {
1108
1115
  const g = gestures()
@@ -1115,7 +1122,7 @@ export function wardWith(config: WardConfig, internal: WardInternals): Ward {
1115
1122
  focused: g.focused,
1116
1123
  hovered: g.hovered,
1117
1124
  pressed: g.pressed,
1118
- dragged: Bool.or(g.dragging, lifted()),
1125
+ dragged: Bool.or(g.dragging, liftedLayer()),
1119
1126
  dragging: g.dragging,
1120
1127
  },
1121
1128
  snapshot,
@@ -23,6 +23,8 @@ import type { WardicTransition, WardicVariant, WardicVariantLabels, WardicVarian
23
23
  export interface VariantState {
24
24
  readonly values: Readonly<Record<string, number | string>>
25
25
  readonly velocities: Readonly<Record<string, number>>
26
+ /** The velocities now, worked out when read (#663): a Snapshot's, whose spring legs' aren't in `velocities`. */
27
+ velocitiesNow?(state: VariantState): Readonly<Record<string, number>>
26
28
  }
27
29
 
28
30
  /** No values yet: a server render's, and the Starting style's. */
@@ -87,9 +89,13 @@ export interface NamedTarget extends Target {
87
89
  /** What a variant name, a variants entry or a resolver's result can be. */
88
90
  type Definition = WardicVariant | WardicVariantResolver | string | undefined
89
91
 
92
+ /** A state's velocities now (#663): worked out where it can, else as it holds them. Per resolver call. */
93
+ const velocitiesOf = (state: VariantState): Readonly<Record<string, number>> =>
94
+ UndefinedOr.match(state.velocitiesNow, { onUndefined: () => state.velocities, onDefined: (now) => now(state) })
95
+
90
96
  /** A resolver called with what it reads, as Motion calls it; anything else as it is. */
91
97
  const calledOf = (definition: Definition, custom: unknown, state: VariantState): Definition => {
92
- if (Predicate.isFunction(definition)) return definition(custom, { ...state.values }, { ...state.velocities })
98
+ if (Predicate.isFunction(definition)) return definition(custom, { ...state.values }, { ...velocitiesOf(state) })
93
99
  return definition
94
100
  }
95
101