@wardic/core 1.1.0 → 1.1.1

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 (101) hide show
  1. package/dist/unstable/AnimationControls.d.ts +110 -0
  2. package/dist/unstable/AnimationControls.d.ts.map +1 -0
  3. package/dist/unstable/AnimationControls.js +107 -0
  4. package/dist/unstable/AnimationControls.js.map +1 -0
  5. package/dist/unstable/AppearHandoff.d.ts +53 -0
  6. package/dist/unstable/AppearHandoff.d.ts.map +1 -0
  7. package/dist/unstable/AppearHandoff.js +23 -0
  8. package/dist/unstable/AppearHandoff.js.map +1 -0
  9. package/dist/unstable/Config.d.ts +285 -0
  10. package/dist/unstable/Config.d.ts.map +1 -0
  11. package/dist/unstable/Config.js +3 -0
  12. package/dist/unstable/Config.js.map +1 -0
  13. package/dist/unstable/FlushGate.d.ts +222 -0
  14. package/dist/unstable/FlushGate.d.ts.map +1 -0
  15. package/dist/unstable/FlushGate.js +567 -0
  16. package/dist/unstable/FlushGate.js.map +1 -0
  17. package/dist/unstable/FrameTime.d.ts +21 -0
  18. package/dist/unstable/FrameTime.d.ts.map +1 -0
  19. package/dist/unstable/FrameTime.js +45 -0
  20. package/dist/unstable/FrameTime.js.map +1 -0
  21. package/dist/unstable/MeasuredPairs.d.ts +51 -0
  22. package/dist/unstable/MeasuredPairs.d.ts.map +1 -0
  23. package/dist/unstable/MeasuredPairs.js +20 -0
  24. package/dist/unstable/MeasuredPairs.js.map +1 -0
  25. package/dist/unstable/OwnValues.d.ts +29 -0
  26. package/dist/unstable/OwnValues.d.ts.map +1 -0
  27. package/dist/unstable/OwnValues.js +22 -0
  28. package/dist/unstable/OwnValues.js.map +1 -0
  29. package/dist/unstable/PresenceRecord.d.ts +176 -0
  30. package/dist/unstable/PresenceRecord.d.ts.map +1 -0
  31. package/dist/unstable/PresenceRecord.js +26 -0
  32. package/dist/unstable/PresenceRecord.js.map +1 -0
  33. package/dist/unstable/Reactivity.d.ts +29 -0
  34. package/dist/unstable/Reactivity.d.ts.map +1 -0
  35. package/dist/unstable/Reactivity.js +15 -0
  36. package/dist/unstable/Reactivity.js.map +1 -0
  37. package/dist/unstable/Report.d.ts +30 -0
  38. package/dist/unstable/Report.d.ts.map +1 -0
  39. package/dist/unstable/Report.js +66 -0
  40. package/dist/unstable/Report.js.map +1 -0
  41. package/dist/unstable/RetargetLegs.d.ts +189 -0
  42. package/dist/unstable/RetargetLegs.d.ts.map +1 -0
  43. package/dist/unstable/RetargetLegs.js +834 -0
  44. package/dist/unstable/RetargetLegs.js.map +1 -0
  45. package/dist/unstable/Spine.d.ts +696 -0
  46. package/dist/unstable/Spine.d.ts.map +1 -0
  47. package/dist/unstable/Spine.js +2617 -0
  48. package/dist/unstable/Spine.js.map +1 -0
  49. package/dist/unstable/Stops.d.ts +82 -0
  50. package/dist/unstable/Stops.d.ts.map +1 -0
  51. package/dist/unstable/Stops.js +149 -0
  52. package/dist/unstable/Stops.js.map +1 -0
  53. package/dist/unstable/Subject.d.ts +11 -0
  54. package/dist/unstable/Subject.d.ts.map +1 -0
  55. package/dist/unstable/Subject.js +12 -0
  56. package/dist/unstable/Subject.js.map +1 -0
  57. package/dist/unstable/Timelines.d.ts +51 -0
  58. package/dist/unstable/Timelines.d.ts.map +1 -0
  59. package/dist/unstable/Timelines.js +10 -0
  60. package/dist/unstable/Timelines.js.map +1 -0
  61. package/dist/unstable/VariableValues.d.ts +27 -0
  62. package/dist/unstable/VariableValues.d.ts.map +1 -0
  63. package/dist/unstable/VariableValues.js +19 -0
  64. package/dist/unstable/VariableValues.js.map +1 -0
  65. package/dist/unstable/VariantTarget.d.ts +106 -0
  66. package/dist/unstable/VariantTarget.d.ts.map +1 -0
  67. package/dist/unstable/VariantTarget.js +185 -0
  68. package/dist/unstable/VariantTarget.js.map +1 -0
  69. package/dist/unstable/VariantTree.d.ts +351 -0
  70. package/dist/unstable/VariantTree.d.ts.map +1 -0
  71. package/dist/unstable/VariantTree.js +362 -0
  72. package/dist/unstable/VariantTree.js.map +1 -0
  73. package/dist/unstable/WardicConfigValue.d.ts +89 -0
  74. package/dist/unstable/WardicConfigValue.d.ts.map +1 -0
  75. package/dist/unstable/WardicConfigValue.js +106 -0
  76. package/dist/unstable/WardicConfigValue.js.map +1 -0
  77. package/dist/unstable/WardicServices.d.ts +46 -0
  78. package/dist/unstable/WardicServices.d.ts.map +1 -0
  79. package/dist/unstable/WardicServices.js +72 -0
  80. package/dist/unstable/WardicServices.js.map +1 -0
  81. package/package.json +1 -1
  82. package/src/unstable/AnimationControls.ts +199 -0
  83. package/src/unstable/AppearHandoff.ts +81 -0
  84. package/src/unstable/Config.ts +326 -0
  85. package/src/unstable/FlushGate.ts +730 -0
  86. package/src/unstable/FrameTime.ts +52 -0
  87. package/src/unstable/MeasuredPairs.ts +56 -0
  88. package/src/unstable/OwnValues.ts +32 -0
  89. package/src/unstable/PresenceRecord.ts +201 -0
  90. package/src/unstable/Reactivity.ts +35 -0
  91. package/src/unstable/Report.ts +75 -0
  92. package/src/unstable/RetargetLegs.ts +1062 -0
  93. package/src/unstable/Spine.ts +3275 -0
  94. package/src/unstable/Stops.ts +221 -0
  95. package/src/unstable/Subject.ts +13 -0
  96. package/src/unstable/Timelines.ts +58 -0
  97. package/src/unstable/VariableValues.ts +27 -0
  98. package/src/unstable/VariantTarget.ts +246 -0
  99. package/src/unstable/VariantTree.ts +643 -0
  100. package/src/unstable/WardicConfigValue.ts +154 -0
  101. package/src/unstable/WardicServices.ts +125 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WardicServices.d.ts","sourceRoot":"","sources":["../../src/unstable/WardicServices.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,IAAI,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,KA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AC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7E;;;OAGG;IAEH,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/E;;;OAGG;IAEH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;CAC5B;AAcD;;;;;;GAMG;AAGH,eAAO,MAAM,UAAU,GAAI,CAAC,OAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAyB5E,CAAA"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * What a binding runs Wardic on: the services an Environment gives ({@link WardicServices}), the Layer
3
+ * an app hands its provider ({@link WardicEnv}), and a {@link Runner}, which runs Effects on a built
4
+ * context, synchronously and forked into the Scope it was made in.
5
+ *
6
+ * Unstable, for Wardic's own packages: public, with no semver promise.
7
+ *
8
+ * @module
9
+ */
10
+ // Unstable: ADR-0071, decision 5. #672: `WardicServices` and `WardicEnv` from solid's `runtime.ts`,
11
+ // the Runner from dom's `internal/runner.ts` (ADR-0071 decision 4; #561 round 1, Q6). A
12
+ // `ManagedRuntime` meets the Runner's shape, so Solid hands its runtime over as it is.
13
+ import * as Bool from "effect/Boolean";
14
+ import * as Context from "effect/Context";
15
+ import * as Effect from "effect/Effect";
16
+ import * as Fiber from "effect/Fiber";
17
+ import * as Scheduler from "effect/Scheduler";
18
+ import * as Scope from "effect/Scope";
19
+ // A Layer-built service's runner (#132, ADR-0041; dom's `internal/runner.ts` until #672): how the
20
+ // Flush gate's and the projection system's `make` run their Effects after they're built, synchronously
21
+ // and forked, on the context their Layer was built in, forking into its Scope.
22
+ //
23
+ // The context drops a sync scheduler, and keeps any other (ADR-0041, *Amendment (#208)*). A
24
+ // binding's first read builds the Layer inside a `ManagedRuntime.runSync`, whose fiber carries a sync
25
+ // `MixedScheduler`: kept, it would pin every later fork to that scheduler, which resumes a fork's
26
+ // yields on a microtask, where Effect's default resumes them on a macrotask. Without it, forks use
27
+ // the default, as a `ManagedRuntime`'s do. A host's own async scheduler, provided in the Layers it
28
+ // hands Wardic (Foldkit's microtask `MixedScheduler`), is the host's choice: forks keep it (ADR-0027,
29
+ // decision 6: a fork inherits the scheduler it's forked under). A host that provides a *sync* one is
30
+ // overridden too: a sync scheduler is for draining a `runSync`.
31
+ /**
32
+ * A runner over the current context, without a sync scheduler, holding its forks in a set of its own
33
+ * until the current Scope closes and interrupts them (#746: what a `FiberSet` held, so an app ships no
34
+ * FiberSet); a fork after that is interrupted at once. It forks with that context itself (`Effect.runForkWith`), not through
35
+ * `FiberSet.runtime`, which reads the context again in the current fiber, where the building call's
36
+ * scheduler still is: `Effect.provideContext` merges into a fiber's context, it doesn't replace it.
37
+ */
38
+ // Not `Effect.fnUntraced`, as effect-4's guide prefers: TypeScript can't carry `R` through it, and the
39
+ // runner's context would be `unknown` (#618, H1).
40
+ export const makeRunner = () => Effect.gen(function* () {
41
+ const context = withoutSyncScheduler(yield* Effect.context());
42
+ const fibers = new Set();
43
+ let closed = false;
44
+ yield* Effect.addFinalizer(() => Effect.suspend(() => {
45
+ closed = true;
46
+ return Fiber.interruptAll(fibers);
47
+ }));
48
+ const fork = Effect.runForkWith(context);
49
+ const runFork = (effect) => {
50
+ const fiber = fork(effect);
51
+ if (closed) {
52
+ fiber.interruptUnsafe();
53
+ return fiber;
54
+ }
55
+ fibers.add(fiber);
56
+ fiber.addObserver(() => {
57
+ if (!closed)
58
+ fibers.delete(fiber);
59
+ });
60
+ return fiber;
61
+ };
62
+ return { runSync: Effect.runSyncWith(context), runSyncExit: Effect.runSyncExitWith(context), runFork, scope: Context.get(context, Scope.Scope) };
63
+ });
64
+ /**
65
+ * `context` without its scheduler when that one is sync (`runSync`'s), else as it is: a host's
66
+ * async scheduler stays, and with none stored the context has Effect's default already.
67
+ */
68
+ const withoutSyncScheduler = (context) => Bool.match(Context.get(context, Scheduler.Scheduler).executionMode === "sync", {
69
+ onTrue: () => Context.omit(Scheduler.Scheduler)(context),
70
+ onFalse: () => context,
71
+ });
72
+ //# sourceMappingURL=WardicServices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WardicServices.js","sourceRoot":"","sources":["../../src/unstable/WardicServices.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,oGAAoG;AACpG,wFAAwF;AACxF,uFAAuF;AACvF,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAgDrC,kGAAkG;AAClG,uGAAuG;AACvG,+EAA+E;AAC/E,EAAE;AACF,4FAA4F;AAC5F,sGAAsG;AACtG,kGAAkG;AAClG,mGAAmG;AACnG,mGAAmG;AACnG,sGAAsG;AACtG,qGAAqG;AACrG,gEAAgE;AAChE;;;;;;GAMG;AACH,uGAAuG;AACvG,kDAAkD;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAwD,EAAE,CAClF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAmB,CAAC,CAAA;IAC9E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiC,CAAA;IACvD,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,KAAK,CAAC,CAAC,MAAM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O,EAAE,GAAG,EAAE,CAAC,OAAO;CACvB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wardic/core",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Wardic's animation engine on Effect: springs, tweens, keyframes, variants, the projection geometry, and the services an environment provides.",
5
5
  "keywords": [
6
6
  "animation",
@@ -0,0 +1,199 @@
1
+ /**
2
+ * **Animation controls** (#433's PR 3, CONTEXT.md; Motion's `useAnimationControls`), on every binding:
3
+ * one object made outside any component and given as `animate={controls}` to any number of Wardic
4
+ * elements, which follow its calls.
5
+ *
6
+ * - **`start(definition, transitionOverride)`** sets each element's `animate` entry (a **Controls
7
+ * change**), so it Retargets, staggers its Variant children and lands as a change of the prop would.
8
+ * It resolves once each element and the Variant children it hands its names to have landed.
9
+ * - The override is the transition of that change: it beats the definition's own on the element and
10
+ * on each Variant child, and it is their orchestration (stagger, `when`), as Motion's
11
+ * `transitionOverride` is.
12
+ * - Their next Retarget, a gesture's, runs on their own transitions again.
13
+ * - **`set(definition)`** is an **Instant change**: the elements and their Variant children
14
+ * snap there, as Motion's `setValues` sets them.
15
+ * - **`stop()`** ends each element's running legs where they are.
16
+ *
17
+ * A function definition is called once per element, with its `custom`, values and velocities, as
18
+ * Motion's `controls.start((i) => …)`. An element hears the controls from its mount to its unmount.
19
+ *
20
+ * Unstable, for Wardic's own packages: public, with no semver promise.
21
+ *
22
+ * @module
23
+ */
24
+ // Unstable: ADR-0071, decision 5. #672: solid's `animation-controls.ts`, moved for the spine to join and
25
+ // leave a Controls change in core.
26
+ import type * as Values from "../Values.ts"
27
+ import * as Arr from "effect/Array"
28
+ import * as Bool from "effect/Boolean"
29
+ import * as Predicate from "effect/Predicate"
30
+ import * as UndefinedOr from "effect/UndefinedOr"
31
+ import * as Config from "./Config.ts"
32
+
33
+ // #672: declared here, as core's `Microtask.ts` declares it, since core builds with no DOM in its lib.
34
+ declare const queueMicrotask: (callback: () => void) => void
35
+
36
+ // #672: the controls' interface, its definition and its mark are Config's, where the config types
37
+ // reach them.
38
+ export type { WardicAnimationControls, WardicControlsDefinition } from "./Config.ts"
39
+
40
+ /**
41
+ * A **Controls change** (#433): what one `start` or `set` set one element's `animate` entry to, the
42
+ * transition it runs on, and the landings it waits for. The element and each Variant child it reaches
43
+ * join it at the Retarget it makes them run, and leave at that one's landing (or the next's).
44
+ */
45
+ export interface ControlsChange {
46
+ /** Its place among every change: a trigger key part, so a change is a trigger even to the same name. */
47
+ readonly serial: number
48
+ /** The element's `animate` entry: a target or a name, a resolver already called. */
49
+ readonly definition: Config.WardicVariant | Config.WardicVariantLabels
50
+ /** The transition of the change (start's override, set's instant one), or none: the element's own. */
51
+ readonly override: Config.WardicTransition | undefined
52
+ /** Elements in it that haven't landed. */
53
+ pending: number
54
+ /** Whether every element it reaches has had its chance to join: its binding's flush has run. */
55
+ armed: boolean
56
+ /** Told once it has landed. */
57
+ readonly landed: () => void
58
+ }
59
+
60
+ /** What a controlled element does at a change, as its binding wires it: its entry set, and the change's landing promised. */
61
+ export interface Controlled {
62
+ readonly change: (definition: Config.WardicControlsDefinition, override: Config.WardicTransition | undefined) => Promise<void>
63
+ readonly stop: () => void
64
+ }
65
+
66
+ /** The elements each controls reach, by the controls. */
67
+ // Module state (#460, Q7): each controls object's subscribers, held weakly by it.
68
+ const subscribers = new WeakMap<Config.WardicAnimationControls, Set<Controlled>>()
69
+
70
+ /** `set`'s transition (#433, Motion's `setValues`): none to speak of, and no orchestration. */
71
+ export const INSTANT: Config.WardicTransition = { type: "tween", duration: 0 }
72
+
73
+ /**
74
+ * Makes animation controls, which animate elements from code by their variants or targets: give them
75
+ * to each element as `animate={controls}`, on a `w.*` element, in a ward's config or on a
76
+ * `Reorder.Item`, then `start`, `set` or `stop` them. Needs no owner. Motion's `useAnimationControls`.
77
+ *
78
+ * @example
79
+ * const controls = createAnimationControls()
80
+ * <w.ul initial="hidden" animate={controls} variants={list}>…</w.ul>
81
+ * await controls.start("visible")
82
+ * @see https://wardic.dev/reference/solid/animation/create-animation-controls
83
+ */
84
+ // #433's PR 3: each `start` or `set` is a Controls change of each element's `animate` entry.
85
+ export const createAnimationControls = (): Config.WardicAnimationControls => {
86
+ const reached = new Set<Controlled>()
87
+ const controls: Config.WardicAnimationControls = {
88
+ [Config.CONTROLS]: true,
89
+ start: (definition, transitionOverride) =>
90
+ Promise.all(Arr.map(Arr.fromIterable(reached), (element) => element.change(definition, transitionOverride))).then(() => undefined),
91
+ set: (definition) =>
92
+ reached.forEach((element) => {
93
+ void element.change(definition, INSTANT)
94
+ }),
95
+ stop: () => reached.forEach((element) => element.stop()),
96
+ }
97
+ subscribers.set(controls, reached)
98
+ return controls
99
+ }
100
+
101
+ /** Whether `u` is **Animation controls** (Motion's `isAnimationControls`). */
102
+ export const isAnimationControls = (u: unknown): u is Config.WardicAnimationControls => Predicate.hasProperty(u, Config.CONTROLS)
103
+
104
+ /** Reach `element` from `controls`, until the returned function: its mount to its unmount. */
105
+ export const subscribe = (controls: Config.WardicAnimationControls, element: Controlled): (() => void) => {
106
+ const reached = subscribers.get(controls)
107
+ if (Predicate.isUndefined(reached)) return () => undefined
108
+ reached.add(element)
109
+ return () => {
110
+ reached.delete(element)
111
+ }
112
+ }
113
+
114
+ /** The changes made, counted. */
115
+ // Module state (#460, Q7): an id counter, only compared for order and identity.
116
+ let serials = 0
117
+
118
+ /**
119
+ * A change of one element (#433): its entry, `definition` called with the element's `custom`, values
120
+ * and velocities when it's a resolver (once, as Motion's), on `override`; and its landing, promised. It
121
+ * lands once every element it reaches has joined, at the end of the binding's flush (`armed`), and
122
+ * left. One that reaches no element lands then.
123
+ */
124
+ export const changeOf = (
125
+ definition: Config.WardicControlsDefinition,
126
+ override: Config.WardicTransition | undefined,
127
+ custom: unknown,
128
+ values: Readonly<Record<string, number | string>>,
129
+ velocities: Readonly<Record<string, number>>,
130
+ ): { readonly change: ControlsChange; readonly landing: Promise<void> } => {
131
+ let resolve!: () => void
132
+ const landing = new Promise<void>((done) => {
133
+ resolve = done
134
+ })
135
+ const entry = Bool.match(Predicate.isFunction(definition), {
136
+ onTrue: () => (definition as Config.WardicVariantResolver)(custom, { ...values }, { ...velocities }),
137
+ onFalse: () => definition as Config.WardicVariant | Config.WardicVariantLabels,
138
+ })
139
+ const change: ControlsChange = { serial: ++serials, definition: entry, override, pending: 0, armed: false, landed: resolve }
140
+ return { change, landing }
141
+ }
142
+
143
+ /** An element joins `change`: it runs a Retarget for it. */
144
+ export const join = (change: ControlsChange): void => {
145
+ change.pending++
146
+ }
147
+
148
+ /** An element in `change` landed, or left it (a later change, its unmount): it lands once none is left and it's armed. */
149
+ export const leave = (change: ControlsChange): void => {
150
+ change.pending--
151
+ if (change.armed && change.pending <= 0) change.landed()
152
+ }
153
+
154
+ /** `change` armed, its binding's flush having run: it lands now if no element joined, or all have left. */
155
+ export const arm = (change: ControlsChange): void => {
156
+ change.armed = true
157
+ if (change.pending <= 0) change.landed()
158
+ }
159
+
160
+ /**
161
+ * An element's config with **Animation controls** for its `animate` (#433), as everything but its
162
+ * controls reads it: `change`'s entry (none before the first), and marked controlled, so it names its
163
+ * own variants whatever the entry is (Motion's `isControllingVariants`).
164
+ */
165
+ export const controlledConfigOf = <C extends Pick<Config.SpineConfig, "animate">>(config: C, change: ControlsChange | undefined): C =>
166
+ ({ ...config, animate: UndefinedOr.map(change, (c) => c.definition), controlled: true }) as C
167
+
168
+ /** A config as a server reads it (#433): one given **Animation controls** has no entry yet, and is controlled. */
169
+ export const uncontrolledOf = <C extends Pick<Config.SpineConfig, "animate">>(config: C): C =>
170
+ Bool.match(isAnimationControls(config.animate), { onTrue: () => controlledConfigOf(config, undefined), onFalse: () => config })
171
+
172
+ /** What a controlled element reads at a change: its `custom`, and its values and velocities now (its Snapshot). */
173
+ export interface ControlledState {
174
+ readonly custom: () => unknown
175
+ /** Its Snapshot: its values, and its velocities now (#663), a spring leg's being on its Frame. */
176
+ readonly snapshot: ControlledSnapshot
177
+ }
178
+
179
+ /** What Animation controls read of an element's Snapshot: its values, and its velocities now (#663). */
180
+ // #672: the controls name what they read, so they import nothing of the spine, whose Snapshot meets it.
181
+ export interface ControlledSnapshot {
182
+ readonly values: Values.Values
183
+ velocitiesNow(snapshot: ControlledSnapshot): Readonly<Record<string, number>>
184
+ }
185
+
186
+ /**
187
+ * A mounted element as its controls reach it (#433): a change sets its entry through `setChange`, its
188
+ * binding's signal, and arms once the binding's flush has run (a microtask after, Solid 2's included),
189
+ * every element it reaches joined by then; `stop` ends its legs.
190
+ */
191
+ export const controlledElement = (setChange: (change: ControlsChange) => void, state: ControlledState, stop: () => void): Controlled => ({
192
+ change: (definition, override) => {
193
+ const made = changeOf(definition, override, state.custom(), state.snapshot.values, state.snapshot.velocitiesNow(state.snapshot))
194
+ setChange(made.change)
195
+ queueMicrotask(() => arm(made.change))
196
+ return made.landing
197
+ },
198
+ stop,
199
+ })
@@ -0,0 +1,81 @@
1
+ /**
2
+ * An element's mount animation as both sides describe it, and its **Handoff** as the spine reads it
3
+ * (#48, ADR-0044): how far in its first legs start, from where its Appear animation has got. Its
4
+ * binding samples a server's and finds a client's.
5
+ *
6
+ * Unstable, for Wardic's own packages: public, with no semver promise.
7
+ *
8
+ * @module
9
+ */
10
+ // Unstable: ADR-0071, decision 5. #672 (PR4-Q3): solid's `appear-handoff.ts`, what of its `appear.ts` the
11
+ // spine reads, moved for the spine in core; the rest of `appear.ts` goes to dom with its importers.
12
+ import type * as Machine from "../Machine.ts"
13
+ import type * as Values from "../Values.ts"
14
+ import * as Bool from "effect/Boolean"
15
+ import * as UndefinedOr from "effect/UndefinedOr"
16
+ import type * as Config from "./Config.ts"
17
+ import * as RetargetLegs from "./RetargetLegs.ts"
18
+
19
+ /** An element's mount animation, described the same on the server and the client. */
20
+ export interface MountAnimation {
21
+ /** The element's tag, by which its Environment routes some keys; `undefined` for an element whose tag isn't known. */
22
+ readonly tag: string | undefined
23
+ /** Each animated key's start. */
24
+ readonly from: Values.Values
25
+ /** Each animated key's target. */
26
+ readonly to: Values.Values
27
+ /** The element's own transition: its stagger isn't in it (ADR-0007). */
28
+ readonly transition: Config.WardicTransition | undefined
29
+ /** Whether reduced motion is on for it (ADR-0029). */
30
+ readonly reduced: boolean
31
+ /**
32
+ * Whether it's a layout node (#245): drawn through its projection at rest, as the client draws
33
+ * it, its own translate on top (#363). Part of its key.
34
+ */
35
+ readonly layout: boolean
36
+ /** Each key's Keyframes of more than two stops (#429), `from` at their first: part of its key. Left out with none. */
37
+ readonly stops?: RetargetLegs.StopsByKey | undefined
38
+ /**
39
+ * Whether it's a **Skipped animation** (#468): every key lands on its first frame, so its Appear
40
+ * animation takes 0 s, holding its end from first paint. Part of its key; left out when it isn't.
41
+ */
42
+ readonly skipped?: boolean | undefined
43
+ /** Its **Transform template** (#443): its stops drawn through it, as the client draws them. Left out with none. */
44
+ readonly template?: Config.SpineConfig["transformTemplate"]
45
+ }
46
+
47
+ /** Whether a transition repeats for ever: a tween's `repeat: Infinity`, a tween as it runs (ADR-0051). */
48
+ export const repeatsForever = (transition: Config.WardicTransition | undefined): boolean =>
49
+ UndefinedOr.match(RetargetLegs.runOf(transition), { onUndefined: () => false, onDefined: (run) => Bool.and(run.type === "tween", (run as Machine.AnimateOptions).repeat === Number.POSITIVE_INFINITY) })
50
+
51
+ /** A transition's own delay, 0 without one. */
52
+ export const ownDelayOf = (transition: Config.WardicTransition | undefined): number =>
53
+ UndefinedOr.match(transition, { onUndefined: () => 0, onDefined: ({ delay = 0 }) => delay })
54
+
55
+ /**
56
+ * The seconds an Appear animation holds before it moves, of the delay the client counts: a
57
+ * transition's own delay is in the animation, except a forever-repeating one's, which is sampled as
58
+ * one cycle, its own delay given with the stagger.
59
+ */
60
+ const heldInAppear = (transition: Config.WardicTransition | undefined): number =>
61
+ Bool.match(repeatsForever(transition), { onTrue: () => 0, onFalse: () => ownDelayOf(transition) })
62
+
63
+ /** A mount animation's `skipped` (#468): left out when it isn't, so its key is as before. */
64
+ export const skippedField = (skipped: boolean): { readonly skipped?: true } => Bool.match(skipped, { onTrue: () => ({ skipped: true }) as const, onFalse: () => ({}) })
65
+
66
+ /** An element's Appear animation, found at mount: the spine starts its first legs as far in as it has got. */
67
+ export interface Handoff {
68
+ /** How far its animation has run, in seconds (its delay included). */
69
+ readonly elapsed: () => number
70
+ /** The delay its animation was given, in seconds. */
71
+ readonly delay: () => number
72
+ }
73
+
74
+ /**
75
+ * How far into its own run the client's first legs start, in seconds, read at their first tick:
76
+ * where the Appear animation has got, less what it waited that the client waits for itself. It
77
+ * waited its delay and its own hold; the client's legs hold their transition's delay (`clientDelay`,
78
+ * the stagger in it). The difference is a `when` wait, which the client has already waited.
79
+ */
80
+ export const startAtOf = (handoff: Handoff, ownTransition: Config.WardicTransition | undefined, clientDelay: number) => (): number =>
81
+ handoff.elapsed() - handoff.delay() - heldInAppear(ownTransition) + clientDelay