@wardic/core 1.0.1 → 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.
- package/dist/Batch.d.ts +4 -2
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +80 -13
- package/dist/Batch.js.map +1 -1
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +1 -1
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/LiveValue.d.ts +61 -0
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +79 -5
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +10 -1
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +18 -1
- package/dist/Machine.js.map +1 -1
- package/dist/Renderer.js +2 -2
- package/dist/Renderer.js.map +1 -1
- package/dist/Spans.d.ts +41 -0
- package/dist/Spans.d.ts.map +1 -0
- package/dist/Spans.js +39 -0
- package/dist/Spans.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +1 -1
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +42 -19
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +2 -2
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/tracing.d.ts +34 -14
- package/dist/internal/tracing.d.ts.map +1 -1
- package/dist/internal/tracing.js +56 -24
- package/dist/internal/tracing.js.map +1 -1
- package/dist/unstable/AnimationControls.d.ts +110 -0
- package/dist/unstable/AnimationControls.d.ts.map +1 -0
- package/dist/unstable/AnimationControls.js +107 -0
- package/dist/unstable/AnimationControls.js.map +1 -0
- package/dist/unstable/AppearHandoff.d.ts +53 -0
- package/dist/unstable/AppearHandoff.d.ts.map +1 -0
- package/dist/unstable/AppearHandoff.js +23 -0
- package/dist/unstable/AppearHandoff.js.map +1 -0
- package/dist/unstable/Config.d.ts +285 -0
- package/dist/unstable/Config.d.ts.map +1 -0
- package/dist/unstable/Config.js +3 -0
- package/dist/unstable/Config.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +222 -0
- package/dist/unstable/FlushGate.d.ts.map +1 -0
- package/dist/unstable/FlushGate.js +567 -0
- package/dist/unstable/FlushGate.js.map +1 -0
- package/dist/unstable/FrameTime.d.ts +21 -0
- package/dist/unstable/FrameTime.d.ts.map +1 -0
- package/dist/unstable/FrameTime.js +45 -0
- package/dist/unstable/FrameTime.js.map +1 -0
- package/dist/unstable/MeasuredPairs.d.ts +51 -0
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -0
- package/dist/unstable/MeasuredPairs.js +20 -0
- package/dist/unstable/MeasuredPairs.js.map +1 -0
- package/dist/unstable/OwnValues.d.ts +29 -0
- package/dist/unstable/OwnValues.d.ts.map +1 -0
- package/dist/unstable/OwnValues.js +22 -0
- package/dist/unstable/OwnValues.js.map +1 -0
- package/dist/unstable/PresenceRecord.d.ts +176 -0
- package/dist/unstable/PresenceRecord.d.ts.map +1 -0
- package/dist/unstable/PresenceRecord.js +26 -0
- package/dist/unstable/PresenceRecord.js.map +1 -0
- package/dist/unstable/Reactivity.d.ts +29 -0
- package/dist/unstable/Reactivity.d.ts.map +1 -0
- package/dist/unstable/Reactivity.js +15 -0
- package/dist/unstable/Reactivity.js.map +1 -0
- package/dist/unstable/Report.d.ts +30 -0
- package/dist/unstable/Report.d.ts.map +1 -0
- package/dist/unstable/Report.js +66 -0
- package/dist/unstable/Report.js.map +1 -0
- package/dist/unstable/RetargetLegs.d.ts +189 -0
- package/dist/unstable/RetargetLegs.d.ts.map +1 -0
- package/dist/unstable/RetargetLegs.js +834 -0
- package/dist/unstable/RetargetLegs.js.map +1 -0
- package/dist/unstable/Spine.d.ts +696 -0
- package/dist/unstable/Spine.d.ts.map +1 -0
- package/dist/unstable/Spine.js +2617 -0
- package/dist/unstable/Spine.js.map +1 -0
- package/dist/unstable/Stops.d.ts +82 -0
- package/dist/unstable/Stops.d.ts.map +1 -0
- package/dist/unstable/Stops.js +149 -0
- package/dist/unstable/Stops.js.map +1 -0
- package/dist/unstable/Subject.d.ts +11 -0
- package/dist/unstable/Subject.d.ts.map +1 -0
- package/dist/unstable/Subject.js +12 -0
- package/dist/unstable/Subject.js.map +1 -0
- package/dist/unstable/Timelines.d.ts +51 -0
- package/dist/unstable/Timelines.d.ts.map +1 -0
- package/dist/unstable/Timelines.js +10 -0
- package/dist/unstable/Timelines.js.map +1 -0
- package/dist/unstable/VariableValues.d.ts +27 -0
- package/dist/unstable/VariableValues.d.ts.map +1 -0
- package/dist/unstable/VariableValues.js +19 -0
- package/dist/unstable/VariableValues.js.map +1 -0
- package/dist/unstable/VariantTarget.d.ts +106 -0
- package/dist/unstable/VariantTarget.d.ts.map +1 -0
- package/dist/unstable/VariantTarget.js +185 -0
- package/dist/unstable/VariantTarget.js.map +1 -0
- package/dist/unstable/VariantTree.d.ts +351 -0
- package/dist/unstable/VariantTree.d.ts.map +1 -0
- package/dist/unstable/VariantTree.js +362 -0
- package/dist/unstable/VariantTree.js.map +1 -0
- package/dist/unstable/WardicConfigValue.d.ts +89 -0
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -0
- package/dist/unstable/WardicConfigValue.js +106 -0
- package/dist/unstable/WardicConfigValue.js.map +1 -0
- package/dist/unstable/WardicServices.d.ts +46 -0
- package/dist/unstable/WardicServices.d.ts.map +1 -0
- package/dist/unstable/WardicServices.js +72 -0
- package/dist/unstable/WardicServices.js.map +1 -0
- package/package.json +1 -1
- package/src/Batch.ts +68 -12
- package/src/DefaultTransition.ts +1 -1
- package/src/LiveValue.ts +129 -5
- package/src/Machine.ts +22 -1
- package/src/Renderer.ts +2 -2
- package/src/Spans.ts +50 -0
- package/src/index.ts +1 -0
- package/src/internal/frameLoop.ts +44 -20
- package/src/internal/options.ts +2 -2
- package/src/internal/tracing.ts +82 -28
- package/src/unstable/AnimationControls.ts +199 -0
- package/src/unstable/AppearHandoff.ts +81 -0
- package/src/unstable/Config.ts +326 -0
- package/src/unstable/FlushGate.ts +730 -0
- package/src/unstable/FrameTime.ts +52 -0
- package/src/unstable/MeasuredPairs.ts +56 -0
- package/src/unstable/OwnValues.ts +32 -0
- package/src/unstable/PresenceRecord.ts +201 -0
- package/src/unstable/Reactivity.ts +35 -0
- package/src/unstable/Report.ts +75 -0
- package/src/unstable/RetargetLegs.ts +1062 -0
- package/src/unstable/Spine.ts +3275 -0
- package/src/unstable/Stops.ts +221 -0
- package/src/unstable/Subject.ts +13 -0
- package/src/unstable/Timelines.ts +58 -0
- package/src/unstable/VariableValues.ts +27 -0
- package/src/unstable/VariantTarget.ts +246 -0
- package/src/unstable/VariantTree.ts +643 -0
- package/src/unstable/WardicConfigValue.ts +154 -0
- package/src/unstable/WardicServices.ts +125 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Subject's values before its first Frame, read purely, with no runtime: its `initial` resolved
|
|
3
|
+
* (`resolveInitial`), a values map's own values and its Keyframes split apart (`splitValues`), each
|
|
4
|
+
* read at one of its stops (`valuesAt`). Every binding reads its starting values through these, on a
|
|
5
|
+
* server and on the client, so both start alike.
|
|
6
|
+
*
|
|
7
|
+
* Unstable, for Wardic's own packages: public, with no semver promise. `@wardic/dom/Style` re-exports
|
|
8
|
+
* it for binding authors.
|
|
9
|
+
*
|
|
10
|
+
* Observability: pure and per element, so quiet (no span, no log).
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
// Unstable: ADR-0071, decision 5. #672: the pure half of dom's `internal/starting-style.ts` (ADR-0003,
|
|
15
|
+
// ADR-0021), moved so the spine reads its starting values from core once it's lifted there. Its other
|
|
16
|
+
// half, the Starting style an Environment draws and the merges of an app's style, stays dom's.
|
|
17
|
+
import type * as Values from "../Values.ts"
|
|
18
|
+
import * as Arr from "effect/Array"
|
|
19
|
+
import * as Bool from "effect/Boolean"
|
|
20
|
+
import * as Match from "effect/Match"
|
|
21
|
+
import * as Option from "effect/Option"
|
|
22
|
+
import * as Predicate from "effect/Predicate"
|
|
23
|
+
import * as Rec from "effect/Record"
|
|
24
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A values map with only the keys an animation can take: numbers and strings. `undefined` and anything else drop out, so the engine never sees
|
|
28
|
+
* them.
|
|
29
|
+
*/
|
|
30
|
+
export const toValues = (v: object | undefined): Values.Values =>
|
|
31
|
+
UndefinedOr.match(v, {
|
|
32
|
+
onUndefined: (): Values.Values => ({}),
|
|
33
|
+
onDefined: (values) => Rec.filter(values as Readonly<Record<string, unknown>>, isAnimatable),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
/** Whether a value is one an animation can take: a number or a string. */
|
|
37
|
+
const isAnimatable = Predicate.or(Predicate.isNumber, Predicate.isString)
|
|
38
|
+
|
|
39
|
+
/** A keyframes value's stops, as Motion's: each a value, or `null`, for where the key is (the first) or the stop before (a later one). */
|
|
40
|
+
// **Keyframes** (#429).
|
|
41
|
+
export type Stops = ReadonlyArray<number | string | null>
|
|
42
|
+
|
|
43
|
+
/** Where a keyframes value is read: `initial`'s at its first stop, a target's at its last. */
|
|
44
|
+
// **Keyframes** (#429).
|
|
45
|
+
export type StopAt = "first" | "last"
|
|
46
|
+
|
|
47
|
+
/** Whether a stop is one an animation can take, or `null`. */
|
|
48
|
+
const isStop = Predicate.or(isAnimatable, Predicate.isNull)
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A Keyframes value's stop (#429): its first, as Motion's `initial` reads it (`use-visual-state.ts`),
|
|
52
|
+
* or its last that isn't `null`, where it rests (Motion's final keyframe, `fill-wildcards.ts`'s).
|
|
53
|
+
* `null` or `undefined` when it has none.
|
|
54
|
+
*/
|
|
55
|
+
const stopOf = (stops: ReadonlyArray<unknown>, at: StopAt): unknown =>
|
|
56
|
+
Bool.match(at === "first", { onTrue: () => stops[0], onFalse: () => Option.getOrUndefined(Arr.findLast(stops, Predicate.isNotNull)) })
|
|
57
|
+
|
|
58
|
+
/** Whether a value is Keyframes an animation can take (#429): an array of stops, one of them not `null`. */
|
|
59
|
+
const isStops = (value: unknown): value is Stops => {
|
|
60
|
+
if (Bool.not(Arr.isArray(value))) return false
|
|
61
|
+
const stops = value as ReadonlyArray<unknown>
|
|
62
|
+
// #672: core's lint (`BOOL_OPERANDS`), met before the move: `Bool.and` read the `some` for an array
|
|
63
|
+
// its `every` had already ruled out.
|
|
64
|
+
if (Bool.not(Arr.every(stops, isStop))) return false
|
|
65
|
+
return Arr.some(stops, Predicate.isNotNull)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The Keyframes {@link keepAnimatable} set aside while it filtered a values map (#452): written by it,
|
|
70
|
+
* read and cleared right after, never across a call. A target with none leaves it `undefined`.
|
|
71
|
+
*/
|
|
72
|
+
// Module state (#460, Q7): scratch within one synchronous call, never held across one.
|
|
73
|
+
let setAside: Record<string, Stops> | undefined
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A values map's filter (#452): a value an animation can take stays, and Keyframes go aside, into
|
|
77
|
+
* {@link setAside}, so one pass over the keys finds both. Built once, at module load.
|
|
78
|
+
*/
|
|
79
|
+
const keepAnimatable = (value: unknown, key: string): boolean => {
|
|
80
|
+
if (Bool.not(Arr.isArray(value))) return isAnimatable(value)
|
|
81
|
+
if (isStops(value)) {
|
|
82
|
+
if (Predicate.isUndefined(setAside)) setAside = {}
|
|
83
|
+
setAside[key] = value
|
|
84
|
+
}
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A values map's numbers and strings, its Keyframes set aside (#452, {@link keepAnimatable}): {@link toValues}' one pass. */
|
|
89
|
+
const filtered = (v: object | undefined): Values.Values => {
|
|
90
|
+
// Per element at mount (#540): statements and a loop.
|
|
91
|
+
setAside = undefined
|
|
92
|
+
const out: Record<string, number | string> = {}
|
|
93
|
+
if (Predicate.isUndefined(v)) return out
|
|
94
|
+
const values = v as Readonly<Record<string, unknown>>
|
|
95
|
+
for (const key of Object.keys(values)) {
|
|
96
|
+
const value = values[key]
|
|
97
|
+
// `keepAnimatable` keeps numbers and strings alone, as `isAnimatable` does.
|
|
98
|
+
if (keepAnimatable(value, key)) out[key] = value as number | string
|
|
99
|
+
}
|
|
100
|
+
return out
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The Keyframes the last {@link filtered} set aside, taken: `undefined` with none. */
|
|
104
|
+
const takeSetAside = (): Readonly<Record<string, Stops>> | undefined => {
|
|
105
|
+
const taken = setAside
|
|
106
|
+
setAside = undefined
|
|
107
|
+
return taken
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `values` with each of `keyframes` at one of its stops (#429), one with no such stop left out. */
|
|
111
|
+
const withStops = (values: Values.Values, keyframes: Readonly<Record<string, Stops>>, at: StopAt): Values.Values => ({
|
|
112
|
+
...values,
|
|
113
|
+
...toValues(Rec.map(keyframes, (stops) => stopOf(stops, at))),
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
/** A values map's own values and its keyframes: `splitValues`' result. */
|
|
117
|
+
// #452.
|
|
118
|
+
export interface SplitValues {
|
|
119
|
+
/** Its numbers and strings, each Keyframes value at one of its stops. */
|
|
120
|
+
readonly values: Values.Values
|
|
121
|
+
/** Its Keyframes, if it has any. */
|
|
122
|
+
// An `Option` (#618, A1): none is Effect's one `None`, so a target with no Keyframes allocates nothing.
|
|
123
|
+
readonly keyframes: Option.Option<Readonly<Record<string, Stops>>>
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A values map's values, each keyframes value read at one of its stops, and its keyframes, in one pass
|
|
128
|
+
* over its keys: a target's resolution reads both, and a target with no keyframes makes nothing
|
|
129
|
+
* `toValues` doesn't.
|
|
130
|
+
*/
|
|
131
|
+
// **Keyframes** (#429); one pass (#452).
|
|
132
|
+
export const splitValues = (v: object | undefined, at: StopAt): SplitValues => {
|
|
133
|
+
const values = filtered(v)
|
|
134
|
+
const keyframes = takeSetAside()
|
|
135
|
+
if (Predicate.isUndefined(keyframes)) return { values, keyframes: Option.none() }
|
|
136
|
+
return { values: withStops(values, keyframes, at), keyframes: Option.some(keyframes) }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A values map with only the keys an animation can take, each keyframes value read at one of its stops:
|
|
141
|
+
* `initial`'s first, a target's last. A keyframes value with no such stop drops out, as does an array
|
|
142
|
+
* `keyframesOf` doesn't take, and anything that isn't a number or a string. One pass over its keys, as
|
|
143
|
+
* `toValues`'.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* valuesAt({ opacity: [0, 0.5, 1], x: 10 }, "first") // { x: 10, opacity: 0 }
|
|
147
|
+
*/
|
|
148
|
+
// **Keyframes** (#429); one pass (#452).
|
|
149
|
+
export const valuesAt = (v: object | undefined, at: StopAt): Values.Values => {
|
|
150
|
+
const values = filtered(v)
|
|
151
|
+
const keyframes = takeSetAside()
|
|
152
|
+
if (Predicate.isUndefined(keyframes)) return values
|
|
153
|
+
return withStops(values, keyframes, at)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A values map's keyframes values: each array of stops an animation can take, one with a stop that isn't
|
|
158
|
+
* `null`. None when it has none, so a target without any makes nothing.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* keyframesOf({ opacity: [0, 0.5, 1], x: 10 }) // { opacity: [0, 0.5, 1] }
|
|
162
|
+
*/
|
|
163
|
+
// **Keyframes** (#429).
|
|
164
|
+
export const keyframesOf = (v: object | undefined): Option.Option<Readonly<Record<string, Stops>>> => splitValues(v, "last").keyframes
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* What of an element's config its starting style is read from. Its values are typed `object`, so a
|
|
168
|
+
* binding's own value types fit as they are.
|
|
169
|
+
*/
|
|
170
|
+
export interface InitialConfig {
|
|
171
|
+
/**
|
|
172
|
+
* Its start: values used as they are, the name of a `variants` entry, a list of names merged in order,
|
|
173
|
+
* a later one's winning, or `false`, to start at `animate`, as Motion's `initial={false}`.
|
|
174
|
+
*/
|
|
175
|
+
// #297 (lists); #134 (`false`).
|
|
176
|
+
readonly initial?: object | string | ReadonlyArray<string> | false | undefined
|
|
177
|
+
/** What `initial: false` starts at: a values map, the name of a `variants` entry, or a list of names. */
|
|
178
|
+
readonly animate?: object | string | ReadonlyArray<string> | undefined
|
|
179
|
+
/** Its variants: the values each name stands for. */
|
|
180
|
+
readonly variants?: Readonly<Record<string, object | undefined>> | undefined
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** One values entry, the variants a name in it would name, and the stop its Keyframes values are read at (#429). */
|
|
184
|
+
interface Entry {
|
|
185
|
+
readonly entry: object | string | ReadonlyArray<string> | undefined
|
|
186
|
+
readonly variants: InitialConfig["variants"]
|
|
187
|
+
readonly at: StopAt
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Whether an entry is a list of names (#297): an array, which a values map never is. */
|
|
191
|
+
const isList = (entry: unknown): entry is ReadonlyArray<string> => Arr.isArray(entry)
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A values map, or the `variants` entry a name names (an unknown name is empty), or nothing.
|
|
195
|
+
* Built once, at module load: every element reads its own at setup (#69).
|
|
196
|
+
*/
|
|
197
|
+
const entryOf: (entry: Entry) => Values.Values = Match.type<Entry>().pipe(
|
|
198
|
+
Match.when({ entry: Match.undefined }, (): Values.Values => ({})),
|
|
199
|
+
Match.when({ entry: Match.string }, ({ entry, variants, at }) => valuesAt(UndefinedOr.map(variants, (byName) => byName[entry]), at)),
|
|
200
|
+
// A list's names merged in order, a later one's winning a key both set (#297, Motion's).
|
|
201
|
+
Match.when({ entry: isList }, ({ entry, variants, at }) =>
|
|
202
|
+
Arr.reduce(entry, {} as Values.Values, (merged, name) => ({ ...merged, ...valuesAt(UndefinedOr.map(variants, (byName) => byName[name]), at) }))),
|
|
203
|
+
Match.orElse(({ entry, at }) => valuesAt(entry as object, at)),
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The values an element starts from: its `initial` values, or the `variants` entries its `initial` names,
|
|
208
|
+
* an unknown name empty, or nothing. With `initial: false`, its `animate`, resolved the same way, so it
|
|
209
|
+
* starts at its target and nothing animates at mount, as Motion's. A keyframes value starts at its first
|
|
210
|
+
* stop, or, with `initial: false`, at `animate`'s last, where the animation it skips would end. Read once,
|
|
211
|
+
* at setup: the starting style is where it starts, never a live target.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* resolveInitial({ initial: false, animate: { opacity: 1 } }) // { opacity: 1 }
|
|
215
|
+
*/
|
|
216
|
+
// #134, Motion's `initial={false}`; **Keyframes** (#429, Motion's `use-visual-state.ts`).
|
|
217
|
+
export const resolveInitial = (config: InitialConfig): Values.Values => {
|
|
218
|
+
// Per element at mount (#540): statements.
|
|
219
|
+
if (config.initial === false) return entryOf({ entry: config.animate, variants: config.variants, at: "last" })
|
|
220
|
+
return entryOf({ entry: config.initial as object | string | ReadonlyArray<string> | undefined, variants: config.variants, at: "first" })
|
|
221
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an Environment draws and a Ward binds (**Subject**): opaque to core. An element in `@wardic/dom`, an
|
|
3
|
+
* object in a scene; an Environment decides what its Subjects are.
|
|
4
|
+
*
|
|
5
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
// Unstable: ADR-0071, decision 5. #672 (the build grill's Q20): a type, not a port; nothing core holds
|
|
10
|
+
// checks what kind of Subject it has.
|
|
11
|
+
|
|
12
|
+
/** A Subject: any object its Environment draws. */
|
|
13
|
+
export type Subject = object
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **Timeline values** (#240, ADR-0043 *Amendment (#240)*): what an element's spine tells of its keys,
|
|
3
|
+
* and the service that runs their Timeline values, which a binding's `scroll` Feature gives. Only the
|
|
4
|
+
* type and the key are here, on every element's path: the code is the Feature's, so an app that reads
|
|
5
|
+
* no scroll ships none of it.
|
|
6
|
+
*
|
|
7
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
// Unstable: ADR-0071, decision 5. #672 (Q15): solid's `timelines.ts`, moved for the spine to tell its keys'
|
|
12
|
+
// Timeline values in core; its options' element a Subject, its runtime a Runner.
|
|
13
|
+
import type * as FlushGate from "./FlushGate.ts"
|
|
14
|
+
import * as Context from "effect/Context"
|
|
15
|
+
import type * as Atom from "effect/reactivity/Atom"
|
|
16
|
+
import type * as Subject from "./Subject.ts"
|
|
17
|
+
import type * as WardicServices from "./WardicServices.ts"
|
|
18
|
+
|
|
19
|
+
/** An element's keys' Timeline values, as its spine tells of them. */
|
|
20
|
+
export interface TimelineKeys {
|
|
21
|
+
/** The element shows `key`'s Live value: its Timeline value runs, when it has one. */
|
|
22
|
+
readonly shown: (key: string) => void
|
|
23
|
+
/** Something else draws `key` now (an entry, a drag, an Imperative animation), or it left the `style`: its Timeline value stops. */
|
|
24
|
+
readonly taken: (key: string) => void
|
|
25
|
+
/** The element's unmounted: it's no longer told of a value described. */
|
|
26
|
+
readonly dispose: () => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What an element's {@link TimelineKeys} are made with. */
|
|
30
|
+
export interface TimelineKeysOptions {
|
|
31
|
+
readonly runtime: WardicServices.Runner<WardicServices.WardicServices>
|
|
32
|
+
readonly gate: FlushGate.Shape
|
|
33
|
+
readonly id: string
|
|
34
|
+
readonly element: Subject.Subject
|
|
35
|
+
/** Its routed `style` keys: each key's Atom, which describes its derivation. */
|
|
36
|
+
readonly live: LiveAtoms
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What an element's Timeline values read of its Live values: a routed key's Atom, `undefined` for one not routed. */
|
|
40
|
+
// #672: the one member the Timelines' keys call of the spine's LiveRoutes, which meets it; named here, so
|
|
41
|
+
// this module, which the spine imports, imports nothing of the spine's.
|
|
42
|
+
export interface LiveAtoms {
|
|
43
|
+
readonly atomOf: (key: string) => Atom.Atom<unknown> | undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The `scroll` Feature's Timeline values (#240), one per provider: an element's {@link TimelineKeys},
|
|
48
|
+
* made at its first write of a Live value; and `described`, told by a `createScroll` that has described
|
|
49
|
+
* its values (`LiveValue.derivesAs`), after the elements following them may have shown them, so each
|
|
50
|
+
* key an element shows finds its Timeline value then, its value unchanged.
|
|
51
|
+
*/
|
|
52
|
+
export class Timelines extends /*#__PURE__*/ Context.Service<
|
|
53
|
+
Timelines,
|
|
54
|
+
{
|
|
55
|
+
readonly keysOf: (options: TimelineKeysOptions) => TimelineKeys
|
|
56
|
+
readonly described: () => void
|
|
57
|
+
}
|
|
58
|
+
>()("@wardic/core/unstable/Timelines") {}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How an Environment reads a value that names a variable it resolves when it draws (**Variable
|
|
3
|
+
* value**): whether a value is one, and a Subject's Key rule, which blends a pair with one at either
|
|
4
|
+
* end by what it resolves to there. One of the Environment's optional members. An Environment other than `@wardic/dom`'s gives
|
|
5
|
+
* one (`@wardic/test`'s `TestLive` a headless one); a binding on `@wardic/dom` falls back to
|
|
6
|
+
* `@wardic/dom/unstable/DomValues`' when its Environment gives none, so an app that never reads it
|
|
7
|
+
* ships none of that code.
|
|
8
|
+
*
|
|
9
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
// Unstable: ADR-0071, decision 5. #672 (PR2-Q1, PR2-Q2; ADR-0071's *Amendment (#672)*): a port, so the
|
|
14
|
+
// spine reads its Environment's variables through it, not through dom (#55, ADR-0035).
|
|
15
|
+
import * as Context from "effect/Context"
|
|
16
|
+
import type * as InterpolatorRegistry from "../InterpolatorRegistry.ts"
|
|
17
|
+
|
|
18
|
+
/** An Environment's reads of its Subjects' Variable values. */
|
|
19
|
+
export interface Shape {
|
|
20
|
+
/** Whether `value` names a variable the Environment resolves when it draws. */
|
|
21
|
+
readonly isValue: (value: unknown) => boolean
|
|
22
|
+
/** `subject`'s Key rule for its Variable values: it takes a pair with one at either end, and declines every other. */
|
|
23
|
+
readonly values: (subject: object) => InterpolatorRegistry.KeyRule
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The Environment's member that reads its Subjects' Variable values. */
|
|
27
|
+
export class VariableValues extends /*#__PURE__*/ Context.Service<VariableValues, Shape>()("@wardic/core/unstable/VariableValues") {}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A target resolved (#277, ADR-0048): a values map, or a variant name against an element's
|
|
3
|
+
* `variants`, each a target with its own transition or a dynamic variant, a function of `custom`.
|
|
4
|
+
* Motion's `resolveVariantFromProps` and `resolveTransition`. Shared by every binding's spine, its
|
|
5
|
+
* variant nodes and its Starting style.
|
|
6
|
+
*
|
|
7
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
// Unstable: ADR-0071, decision 5. #672: solid's `variant-target.ts`, moved for the spine and the
|
|
12
|
+
// variant tree to resolve targets in core.
|
|
13
|
+
import type * as Values from "../Values.ts"
|
|
14
|
+
import * as Stops from "./Stops.ts"
|
|
15
|
+
import * as Arr from "effect/Array"
|
|
16
|
+
import * as Bool from "effect/Boolean"
|
|
17
|
+
import * as Option from "effect/Option"
|
|
18
|
+
import * as Predicate from "effect/Predicate"
|
|
19
|
+
import * as Rec from "effect/Record"
|
|
20
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
21
|
+
import type * as Config from "./Config.ts"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* What a dynamic variant reads besides `custom` (#277, Motion's `current` and `velocity`): the
|
|
25
|
+
* element's values now and their velocities, its Snapshot's. Copied only when a resolver is called.
|
|
26
|
+
*/
|
|
27
|
+
export interface VariantState {
|
|
28
|
+
readonly values: Readonly<Record<string, number | string>>
|
|
29
|
+
readonly velocities: Readonly<Record<string, number>>
|
|
30
|
+
/** The velocities now, worked out when read (#663): a Snapshot's, whose spring legs' aren't in `velocities`. */
|
|
31
|
+
velocitiesNow?(state: VariantState): Readonly<Record<string, number>>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** No values yet: a server render's, and the Starting style's. */
|
|
35
|
+
export const NO_VARIANT_STATE: VariantState = { values: {}, velocities: {} }
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A target resolved (#277): its values, clean for core, its own transition, if it has one, its
|
|
39
|
+
* **Transition end** (#428), the values set once its keys land, if it has one, and its Keyframes (#429).
|
|
40
|
+
*/
|
|
41
|
+
export interface Target {
|
|
42
|
+
readonly values: Values.Values
|
|
43
|
+
readonly transition: Config.WardicVariantTransition | undefined
|
|
44
|
+
readonly transitionEnd: Values.Values | undefined
|
|
45
|
+
/**
|
|
46
|
+
* Its **Keyframes** (#429): each such key's stops, its value in `values` the last stop it rests at,
|
|
47
|
+
* so the Override stack, a Base value and a Transition end read it as any target's. `undefined` with
|
|
48
|
+
* none.
|
|
49
|
+
*/
|
|
50
|
+
readonly keyframes: Keyframes | undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A target's **Keyframes** (#429): each such key's stops. */
|
|
54
|
+
export type Keyframes = Readonly<Record<string, Stops.Stops>>
|
|
55
|
+
|
|
56
|
+
/** A variant prop's entry: a target, a name, a list of names (#297), or nothing. */
|
|
57
|
+
export type Entry = Config.WardicVariant | Config.WardicVariantLabels | undefined
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether an entry names variants (#297): a name, or a list of names. Not a values map: a list is an
|
|
61
|
+
* object too, so a check for a string alone would take it for one.
|
|
62
|
+
*/
|
|
63
|
+
export const isLabels = (entry: unknown): entry is Config.WardicVariantLabels => Bool.or(Predicate.isString(entry), Arr.isArray(entry))
|
|
64
|
+
|
|
65
|
+
/** An entry's names, in order (#297): one for a name, a list's own, none for a values map or nothing. */
|
|
66
|
+
export const labelsOf = (entry: unknown): ReadonlyArray<string> => {
|
|
67
|
+
if (Predicate.isString(entry)) return [entry]
|
|
68
|
+
if (Arr.isArray(entry)) return entry as ReadonlyArray<string>
|
|
69
|
+
return NO_LABELS
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** No names. */
|
|
73
|
+
export const NO_LABELS: ReadonlyArray<string> = []
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Two entries' names the same (#297, Motion's `shallowCompare`): a name, or a list equal name by name
|
|
77
|
+
* in order, so a fresh list with the same names each render isn't a change. A values map, or nothing,
|
|
78
|
+
* matches only itself.
|
|
79
|
+
*/
|
|
80
|
+
export const sameLabels = (a: Config.WardicVariantLabels | undefined, b: Config.WardicVariantLabels | undefined): boolean => {
|
|
81
|
+
if (a === b) return true
|
|
82
|
+
if (Bool.or(Bool.not(Arr.isArray(a)), Bool.not(Arr.isArray(b)))) return false
|
|
83
|
+
const x = a as ReadonlyArray<string>
|
|
84
|
+
const y = b as ReadonlyArray<string>
|
|
85
|
+
// #672: core's lint (`BOOL_OPERANDS`), met before the move: the `every` is read only for lists of one length.
|
|
86
|
+
if (x.length !== y.length) return false
|
|
87
|
+
return Arr.every(x, (name, i) => name === y[i])
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A target resolved for one of an entry's names (#297): `name` its name, `undefined` for a values map. */
|
|
91
|
+
export interface NamedTarget extends Target {
|
|
92
|
+
readonly name: string | undefined
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** What a variant name, a variants entry or a resolver's result can be. */
|
|
96
|
+
type Definition = Config.WardicVariant | Config.WardicVariantResolver | string | undefined
|
|
97
|
+
|
|
98
|
+
/** A state's velocities now (#663): worked out where it can, else as it holds them. Per resolver call. */
|
|
99
|
+
const velocitiesOf = (state: VariantState): Readonly<Record<string, number>> =>
|
|
100
|
+
UndefinedOr.match(state.velocitiesNow, { onUndefined: () => state.velocities, onDefined: (now) => now(state) })
|
|
101
|
+
|
|
102
|
+
/** A resolver called with what it reads, as Motion calls it; anything else as it is. */
|
|
103
|
+
const calledOf = (definition: Definition, custom: unknown, state: VariantState): Definition => {
|
|
104
|
+
if (Predicate.isFunction(definition)) return definition(custom, { ...state.values }, { ...velocitiesOf(state) })
|
|
105
|
+
return definition
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A name looked up in `variants`; anything else as it is. */
|
|
109
|
+
const namedOf = (definition: Definition, variants: Config.WardicVariants | undefined): Definition => {
|
|
110
|
+
if (Bool.not(Predicate.isString(definition))) return definition
|
|
111
|
+
if (Predicate.isUndefined(variants)) return undefined
|
|
112
|
+
return variants[definition as string]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Resolve a target (#277): a values map, or a variant name, against `variants`, Motion's
|
|
117
|
+
* `resolveVariantFromProps`. A name's entry is looked up, a resolver is called with `custom` and the
|
|
118
|
+
* element's `state`, and a resolver that returns a name is followed once more. Its values go through
|
|
119
|
+
* `Stops.valuesAt`, so `Override.resolve` and `Values.split` never see an `undefined` value, nor an
|
|
120
|
+
* array: a key's Keyframes (#429) are split off, its value their last stop; its `transition` is split
|
|
121
|
+
* off too.
|
|
122
|
+
*/
|
|
123
|
+
export const resolveTarget = (entry: Entry, variants: Config.WardicVariants | undefined, custom: unknown, state: VariantState): Target => {
|
|
124
|
+
if (Arr.isArray(entry)) return mergedOf(resolveTargets(entry, variants, custom, state))
|
|
125
|
+
return resolveOne(entry as Config.WardicVariant | string | undefined, variants, custom, state)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Each of an entry's targets, in order (#297): a list's names each resolved on its own, Motion's
|
|
130
|
+
* `definitionList`; a name or a values map alone. An empty list resolves nothing.
|
|
131
|
+
*/
|
|
132
|
+
export const resolveTargets = (entry: Entry, variants: Config.WardicVariants | undefined, custom: unknown, state: VariantState): ReadonlyArray<NamedTarget> => {
|
|
133
|
+
if (Arr.isArray(entry)) {
|
|
134
|
+
return Arr.map(entry as ReadonlyArray<string>, (name): NamedTarget => ({ ...resolveOne(name, variants, custom, state), name }))
|
|
135
|
+
}
|
|
136
|
+
const one = entry as Config.WardicVariant | string | undefined
|
|
137
|
+
return [{ ...resolveOne(one, variants, custom, state), name: Bool.match(Predicate.isString(one), { onTrue: () => one as string, onFalse: () => undefined }) }]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Targets merged in order (#297): their values, a later one's winning a key both set, and their own
|
|
142
|
+
* transitions field by field, a later one's winning. The merged transition is what orchestration
|
|
143
|
+
* reads for a list as a whole (`when` the last name's that sets it); each key's legs run on the own
|
|
144
|
+
* transition of the name that drives it, not on this.
|
|
145
|
+
*/
|
|
146
|
+
export const mergedOf = (targets: ReadonlyArray<Target>): Target =>
|
|
147
|
+
Arr.reduce(targets, NO_TARGET, (merged, target): Target => ({
|
|
148
|
+
values: { ...merged.values, ...target.values },
|
|
149
|
+
keyframes: keyframesOver(target, merged.keyframes),
|
|
150
|
+
transition: UndefinedOr.match(target.transition, {
|
|
151
|
+
onUndefined: () => merged.transition,
|
|
152
|
+
onDefined: (own) => UndefinedOr.match(merged.transition, { onUndefined: () => own, onDefined: (before) => ({ ...before, ...own }) as Config.WardicVariantTransition }),
|
|
153
|
+
}),
|
|
154
|
+
transitionEnd: UndefinedOr.match(target.transitionEnd, {
|
|
155
|
+
onUndefined: () => merged.transitionEnd,
|
|
156
|
+
onDefined: (own) => UndefinedOr.match(merged.transitionEnd, { onUndefined: () => own, onDefined: (before) => ({ ...before, ...own }) }),
|
|
157
|
+
}),
|
|
158
|
+
}))
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* `target`'s Keyframes over `before` (#429): a later name's own, and `before`'s for the keys it doesn't
|
|
162
|
+
* set, so a key it sets to one value is no longer Keyframes. `undefined` when neither has any.
|
|
163
|
+
*/
|
|
164
|
+
const keyframesOver = (target: Target, before: Keyframes | undefined): Keyframes | undefined => {
|
|
165
|
+
if (Predicate.isUndefined(before)) return target.keyframes
|
|
166
|
+
const kept = Rec.filter(before, (_, key) => Bool.not(Object.hasOwn(target.values, key)))
|
|
167
|
+
const over: Keyframes = { ...kept, ...target.keyframes }
|
|
168
|
+
return Bool.match(Rec.isEmptyRecord(over), { onTrue: () => undefined, onFalse: () => over })
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Nothing resolved. */
|
|
172
|
+
export const NO_TARGET: Target = { values: {}, transition: undefined, transitionEnd: undefined, keyframes: undefined }
|
|
173
|
+
|
|
174
|
+
/** One name or values map resolved ({@link resolveTarget}). */
|
|
175
|
+
const resolveOne = (entry: Config.WardicVariant | string | undefined, variants: Config.WardicVariants | undefined, custom: unknown, state: VariantState): Target => {
|
|
176
|
+
const definition = calledOf(namedOf(calledOf(namedOf(entry, variants), custom, state), variants), custom, state)
|
|
177
|
+
if (Bool.or(Predicate.isUndefined(definition), Bool.or(Predicate.isString(definition), Predicate.isFunction(definition)))) {
|
|
178
|
+
return NO_TARGET
|
|
179
|
+
}
|
|
180
|
+
// Its own transition is an object; a `transition` string stays a value, as it was. Its
|
|
181
|
+
// Transition end (#428) is an object too, which `toValues` leaves out of its values.
|
|
182
|
+
const target = definition as { readonly transition?: unknown; readonly transitionEnd?: unknown }
|
|
183
|
+
const transitionEnd = transitionEndOf(target.transitionEnd)
|
|
184
|
+
// A key's Keyframes (#429) rest at their last stop: its value, beside its stops, both found in one
|
|
185
|
+
// pass over its keys (#452).
|
|
186
|
+
if (Bool.not(Predicate.isObject(target.transition))) {
|
|
187
|
+
const split = Stops.splitValues(target, "last")
|
|
188
|
+
return { values: split.values, transition: undefined, transitionEnd, keyframes: Option.getOrUndefined(split.keyframes) }
|
|
189
|
+
}
|
|
190
|
+
const { transition, ...values } = target
|
|
191
|
+
const split = Stops.splitValues(values, "last")
|
|
192
|
+
return { values: split.values, transition: transition as Config.WardicVariantTransition, transitionEnd, keyframes: Option.getOrUndefined(split.keyframes) }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** A target's Transition end (#428), clean for core: none for anything but a values map, or an empty one. */
|
|
196
|
+
const transitionEndOf = (given: unknown): Values.Values | undefined => {
|
|
197
|
+
if (Bool.not(Predicate.isObject(given))) return undefined
|
|
198
|
+
const values = Stops.toValues(given as object)
|
|
199
|
+
if (Rec.isEmptyRecord(values)) return undefined
|
|
200
|
+
return values
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The transition an animation to a target runs on (#277, Motion's `resolveTransition`): the target's
|
|
205
|
+
* own in place of the element's, or laid over it with `inherit: true` (a shallow merge, its own keys
|
|
206
|
+
* winning); the element's when it has none. An own transition with no `inherit` is handed back as it
|
|
207
|
+
* is, the same object each call, so a memo of it holds (#460: a copy per call made Solid 2's variant
|
|
208
|
+
* node re-run its orchestration's readers at every gesture, `UNSTABLE_MEMO_OUTPUT`).
|
|
209
|
+
*/
|
|
210
|
+
export const transitionOfTarget = (own: Config.WardicVariantTransition | undefined, element: Config.WardicTransition | undefined): Config.WardicTransition | undefined => {
|
|
211
|
+
if (Predicate.isUndefined(own)) return element
|
|
212
|
+
if (!("inherit" in own)) return own as Config.WardicTransition
|
|
213
|
+
const { inherit, ...rest } = own
|
|
214
|
+
if (inherit === true) return { ...element, ...rest } as Config.WardicTransition
|
|
215
|
+
return rest as Config.WardicTransition
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* `variants` with each entry resolved to its values, a dynamic one with `custom` and no values yet
|
|
220
|
+
* (#277): what dom's Starting style reads, which takes values maps only. As they are when none is a
|
|
221
|
+
* function.
|
|
222
|
+
*/
|
|
223
|
+
export const startingVariantsOf = (variants: object | undefined, custom: unknown): object | undefined => {
|
|
224
|
+
if (Predicate.isUndefined(variants)) return undefined
|
|
225
|
+
const entries = variants as Config.WardicVariants
|
|
226
|
+
if (Bool.not(Arr.some(Rec.values(entries), Predicate.isFunction))) return variants
|
|
227
|
+
return Rec.map(entries, (_, name) => resolveTarget(name, entries, custom, NO_VARIANT_STATE).values)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The own transition of an element's target now (#277): its `animate` map's, else the variant it
|
|
232
|
+
* names or inherits (`name`), resolved with `custom` and no values. What its orchestration reads.
|
|
233
|
+
*/
|
|
234
|
+
export const ownTransitionOf = (
|
|
235
|
+
animate: object | Config.WardicVariantLabels | undefined,
|
|
236
|
+
name: Config.WardicVariantLabels | undefined,
|
|
237
|
+
variants: object | undefined,
|
|
238
|
+
custom: unknown,
|
|
239
|
+
): Config.WardicVariantTransition | undefined => {
|
|
240
|
+
const byName = variants as Config.WardicVariants | undefined
|
|
241
|
+
if (Bool.and(Predicate.isNotUndefined(animate), Bool.not(isLabels(animate)))) {
|
|
242
|
+
return resolveTarget(animate as Config.WardicVariant, byName, custom, NO_VARIANT_STATE).transition
|
|
243
|
+
}
|
|
244
|
+
if (Predicate.isUndefined(name)) return undefined
|
|
245
|
+
return resolveTarget(name, byName, custom, NO_VARIANT_STATE).transition
|
|
246
|
+
}
|