@wardic/object 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ObjectValues.d.ts.map +1 -1
- package/dist/ObjectValues.js +38 -4
- package/dist/ObjectValues.js.map +1 -1
- package/dist/WardicObject.d.ts +60 -14
- package/dist/WardicObject.d.ts.map +1 -1
- package/dist/WardicObject.js +13 -4
- package/dist/WardicObject.js.map +1 -1
- package/dist/internal/transform-keys.d.ts +16 -0
- package/dist/internal/transform-keys.d.ts.map +1 -0
- package/dist/internal/transform-keys.js +47 -0
- package/dist/internal/transform-keys.js.map +1 -0
- package/package.json +2 -2
- package/src/ObjectValues.ts +36 -4
- package/src/WardicObject.ts +116 -16
- package/src/internal/transform-keys.ts +51 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectValues.d.ts","sourceRoot":"","sources":["../src/ObjectValues.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ObjectValues.d.ts","sourceRoot":"","sources":["../src/ObjectValues.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,aAAa,MAAM,qCAAqC,CAAA;AACzE,OAAO,KAAK,KAAK,SAAS,MAAM,iCAAiC,CAAA;AACjE,OAAO,KAAK,KAAK,KAAK,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,KAAK,cAAc,MAAM,sCAAsC,CAAA;AAE3E,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAoEvC;;;;GAIG;AAGH,eAAO,MAAM,cAAc,SAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,eAAe,MAAM,KAAG,KAAK,CAAC,UAQlI,CAAA;AAED;;;GAGG;AAEH,eAAO,MAAM,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,UAAqD,CAAA;AAK3G,+EAA+E;AAC/E,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,KAIjC,CAAA;AAKD,qCAAqC;AACrC,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,KAGzC,CAAA;AAKD,sCAAsC;AACtC,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,KAG3C,CAAA"}
|
package/dist/ObjectValues.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A plain object's values for Wardic: where each key it animates starts (the property's own value), and
|
|
3
3
|
* the ports core reads an Environment's values through, with no style, no layout to measure and no
|
|
4
|
-
* variables. A key the object doesn't have,
|
|
5
|
-
* error naming it: Wardic writes no property
|
|
4
|
+
* variables. A key the object doesn't have, whose value is neither a number nor a string, or that it
|
|
5
|
+
* can't write (read-only, or a getter with no setter) is an error naming it: Wardic writes no property
|
|
6
|
+
* the object didn't have.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* import * as ObjectValues from "@wardic/object/ObjectValues"
|
|
@@ -20,11 +21,44 @@ import * as Predicate from "effect/Predicate";
|
|
|
20
21
|
const isClassName = (name) => Bool.and(Predicate.isString(name), Bool.and(name !== "", name !== "Object"));
|
|
21
22
|
/** What `subject` is called in an error: its class's name, else "the object". */
|
|
22
23
|
const nameOf = (subject) => Option.fromNullishOr(subject.constructor).pipe(Option.map((made) => made.name), Option.filter(isClassName), Option.match({ onNone: () => "the object", onSome: (name) => `a ${name}` }));
|
|
23
|
-
/**
|
|
24
|
+
/** The nearest descriptor for `key` up `holder`'s prototypes, past its own; none where none has it. */
|
|
25
|
+
const inheritedOf = (holder, key) => {
|
|
26
|
+
const above = Object.getPrototypeOf(holder);
|
|
27
|
+
if (Predicate.isNull(above))
|
|
28
|
+
return undefined;
|
|
29
|
+
const found = Object.getOwnPropertyDescriptor(above, key);
|
|
30
|
+
if (Predicate.isNotUndefined(found))
|
|
31
|
+
return found;
|
|
32
|
+
return inheritedOf(above, key);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Whether Wardic can write `holder`'s `key`: a writable property of its own, or a getter with a setter, its
|
|
36
|
+
* own or inherited; or an inherited writable property, where the holder can take one of its own (it isn't
|
|
37
|
+
* frozen, sealed or kept from extending).
|
|
38
|
+
*/
|
|
39
|
+
// #968: else each frame's write threw, in strict mode, and the flush stopped at it (#969). @wardic/three's
|
|
40
|
+
// lookup has its own, over each holder it finds a key at. Per key at a leg's start, the hot path
|
|
41
|
+
// (effect-first.md): statements.
|
|
42
|
+
const isWritable = (holder, key) => {
|
|
43
|
+
const own = Object.getOwnPropertyDescriptor(holder, key);
|
|
44
|
+
if (Predicate.isNotUndefined(own))
|
|
45
|
+
return own.writable === true || Predicate.isNotUndefined(own.set);
|
|
46
|
+
const inherited = inheritedOf(holder, key);
|
|
47
|
+
if (Predicate.isUndefined(inherited))
|
|
48
|
+
return true;
|
|
49
|
+
if (Predicate.isNotUndefined(inherited.set))
|
|
50
|
+
return true;
|
|
51
|
+
return inherited.writable === true && Object.isExtensible(holder);
|
|
52
|
+
};
|
|
53
|
+
/** `subject`'s own value for `key`: a number or a string it can write, else an error naming the key. */
|
|
24
54
|
const ownValueOf = (subject, key) => {
|
|
25
55
|
const value = subject[key];
|
|
26
|
-
if (Bool.or(Predicate.isNumber(value), Predicate.isString(value)))
|
|
56
|
+
if (Bool.or(Predicate.isNumber(value), Predicate.isString(value))) {
|
|
57
|
+
if (!isWritable(subject, key)) {
|
|
58
|
+
throw new Error(`wardic.animate: ${nameOf(subject)}'s "${key}" can't be written (it's read-only, or a getter with no setter), so Wardic can't animate it. Give a key it can write.`);
|
|
59
|
+
}
|
|
27
60
|
return Option.some(value);
|
|
61
|
+
}
|
|
28
62
|
if (Predicate.isUndefined(value)) {
|
|
29
63
|
throw new Error(`wardic.animate: ${nameOf(subject)} has no "${key}" to animate. Give a key it has, a number or a string; Wardic adds no property to an object.`);
|
|
30
64
|
}
|
package/dist/ObjectValues.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectValues.js","sourceRoot":"","sources":["../src/ObjectValues.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ObjectValues.js","sourceRoot":"","sources":["../src/ObjectValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,8FAA8F;AAC9F,uGAAuG;AACvG,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAA;AAMnD,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAE7C,+DAA+D;AAC/D,MAAM,WAAW,GAAG,CAAC,IAAa,EAAkB,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAA;AAEnI,iFAAiF;AACjF,MAAM,MAAM,GAAG,CAAC,OAAe,EAAU,EAAE,CACzC,MAAM,CAAC,aAAa,CAAE,OAAkE,CAAC,WAAW,CAAC,CAAC,IAAI,CACxG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAC/B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAC1B,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,CAC5E,CAAA;AAEH,uGAAuG;AACvG,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,GAAW,EAAkC,EAAE;IAClF,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAkB,CAAA;IAC5D,IAAI,SAAS,CAAC,MAAM,CAAC,K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AE,EAAE,CAAA;AAE7G,sCAAsC;AACtC,MAAM,CAAC,MAAM,cAAc,GAAyB;IAClD,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK;IACpB,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY;CAC3B,CAAA"}
|
package/dist/WardicObject.d.ts
CHANGED
|
@@ -12,24 +12,65 @@ import * as Layer from "effect/Layer";
|
|
|
12
12
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
13
13
|
import * as ObjectBatch from "./ObjectBatch.ts";
|
|
14
14
|
import * as PumpedFrames from "./PumpedFrames.ts";
|
|
15
|
-
/** A key of `T` Wardic animates: one whose value is a number or a string. */
|
|
16
|
-
export type AnimatableKey<T> = {
|
|
17
|
-
readonly [K in keyof T]-?: T[K] extends number | string ? K : never;
|
|
18
|
-
}[keyof T] & string;
|
|
19
15
|
/**
|
|
20
|
-
* A
|
|
21
|
-
*
|
|
22
|
-
*
|
|
16
|
+
* A key of `T` Wardic animates, by name: one whose value is a number or a string. An optional one among
|
|
17
|
+
* them: `animate` throws if the object lacks it when called. A numeric key by its name too, as `"0"`, a
|
|
18
|
+
* number index's as `` `${number}` ``: a typed array's elements, not its own numbers (`length`,
|
|
19
|
+
* `byteLength`, `byteOffset`, `BYTES_PER_ELEMENT`), which it can't write. An array has none: a list is
|
|
20
|
+
* many Subjects.
|
|
23
21
|
*/
|
|
24
|
-
export type
|
|
25
|
-
readonly [K in
|
|
22
|
+
export type AnimatableKey<T> = [T] extends [ReadonlyArray<unknown>] ? never : Exclude<{
|
|
23
|
+
readonly [K in keyof T]-?: [Defined<T[K]>] extends [never] ? never : Defined<T[K]> extends number | string ? KeyName<K> : never;
|
|
24
|
+
}[keyof T], TypedArrayOwnKey<T>>;
|
|
25
|
+
/** A typed array's own numbers, which it can't write: on `T`, or on any of a list's. */
|
|
26
|
+
type TypedArrayOwnKey<T> = T extends ArrayBufferView ? "length" | "byteLength" | "byteOffset" | "BYTES_PER_ELEMENT" : never;
|
|
27
|
+
/** A key's value with its `undefined` left out: an optional key's, as the object holds it. */
|
|
28
|
+
type Defined<V> = Exclude<V, undefined>;
|
|
29
|
+
/** A key's name: a number key's as a string, as the run time reads it. */
|
|
30
|
+
type KeyName<K> = K extends string ? K : K extends number ? `${K}` : never;
|
|
31
|
+
/** A key's name as a target writes it: a numeric one as its number, a name that only reads as one (`"01"`) as itself. */
|
|
32
|
+
type TargetKey<K> = K extends `${infer N extends number}` ? (`${N}` extends K ? N : K) : K;
|
|
33
|
+
/** The value `T` holds under its key named `K`, without `undefined`: a numeric name's at its number. */
|
|
34
|
+
type HeldAt<T, K> = Defined<K extends keyof T ? T[K] : K extends `${infer N extends number}` ? T[N & keyof T] : never>;
|
|
35
|
+
/**
|
|
36
|
+
* A target for `T`: each of its animatable keys a value or keyframes, never `undefined` (an optional
|
|
37
|
+
* key's too), a numeric key by its index (a typed array's element, `{ 0: 1 }`); a transition, with an
|
|
38
|
+
* entry under any of those keys, which `animate`'s options are laid over field by field; and a
|
|
39
|
+
* Transition end, its values set once the object lands. An array has none that fits: `animate` reads
|
|
40
|
+
* one as a list of Subjects, or a sequence, never as one Subject.
|
|
41
|
+
*/
|
|
42
|
+
export type ObjectTarget<T> = [T] extends [ReadonlyArray<unknown>] ? NotOneSubject : {
|
|
43
|
+
readonly [K in AnimatableKey<T> as TargetKey<K>]?: ValueAt<T, K>;
|
|
26
44
|
} & {
|
|
27
45
|
/** How it gets there: a spring, a tween or an inertia, with an entry under any of `T`'s keys it animates. */
|
|
28
46
|
readonly transition?: Config.WardicTransitionFor<AnimatableKey<T>> | undefined;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Values set once it lands, with no animation, each under a key the object has and can write: one
|
|
49
|
+
* it lacks or can't write is an error at the call, as a key it animates is. One it has lost, or can
|
|
50
|
+
* no longer write, by then is reported and left as it is, and the rest are set.
|
|
51
|
+
*/
|
|
52
|
+
readonly transitionEnd?: TransitionEndOf<T> | undefined;
|
|
53
|
+
};
|
|
54
|
+
/** The target an array meets, which nothing fits: its name says why. */
|
|
55
|
+
type NotOneSubject = {
|
|
56
|
+
readonly "an array isn't one Subject: a list of them, or a sequence, whose options are WardicSequenceOptions": never;
|
|
57
|
+
};
|
|
58
|
+
/** A target's value for `T`'s key named `K`: one of its values, or keyframes of them. */
|
|
59
|
+
type ValueAt<T, K> = HeldAt<T, K> | Config.WardicKeyframes<HeldAt<T, K>>;
|
|
60
|
+
/** `T`'s Transition end: values for its animatable keys, set once it lands. */
|
|
61
|
+
type TransitionEndOf<T> = {
|
|
62
|
+
readonly [K in AnimatableKey<T> as TargetKey<K>]?: HeldAt<T, K>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* A target for `T` whose keys are any name (it has an index signature), checked key by key as given
|
|
66
|
+
* (`G`): `transition` as a transition, `transitionEnd` as its Transition end, and any other key as one
|
|
67
|
+
* of `T`'s values or keyframes. Since any name is one of its keys, a misspelt key isn't caught.
|
|
68
|
+
*/
|
|
69
|
+
type AnyKeyTarget<T, G> = {
|
|
70
|
+
readonly [P in keyof G]: P extends "transition" ? Config.WardicTransitionFor<string> | undefined : P extends "transitionEnd" ? TransitionEndOf<T> | undefined : ValueAt<T, P>;
|
|
32
71
|
};
|
|
72
|
+
/** Where `T`'s keys are any name, the target given, checked key by key ({@link AnyKeyTarget}); else nothing, an {@link ObjectTarget} its target. */
|
|
73
|
+
type AnyKeyTargetFor<T, G> = string extends AnimatableKey<T> ? AnyKeyTarget<T, G> : never;
|
|
33
74
|
/** A Segment of objects, `[subject, target, options?]`: an object, or a list of them. Motion's. */
|
|
34
75
|
export type ObjectSegment = readonly [subject: object | ReadonlyArray<object>, target: Readonly<Record<string, number | string | Config.WardicKeyframes<number | string>>>] | readonly [subject: object | ReadonlyArray<object>, target: Readonly<Record<string, number | string | Config.WardicKeyframes<number | string>>>, options: Imperative.WardicSegmentOptions];
|
|
35
76
|
/** A Segment of a Batch, `[batch, target, options?]`: every member, or a member's handle, `batch.at(i)`. */
|
|
@@ -40,11 +81,15 @@ export type ObjectSequence = ReadonlyArray<Imperative.WardicSequenceLabel | Obje
|
|
|
40
81
|
* `animate(subject, target, options?)` animates an object, or each of a list of them, to `target`;
|
|
41
82
|
* `animate(sequence, options?)` plays a sequence. Either returns its Playback controls. Motion's.
|
|
42
83
|
* The options' transition takes an entry under any of the keys the Subject animates: a Batch's, its keys.
|
|
84
|
+
* A Subject whose keys are any name (an index signature) has its target checked key by key as given,
|
|
85
|
+
* though a misspelt key isn't caught, any name being one of its keys; naming its type, `animate<T>(…)`,
|
|
86
|
+
* checks its keys as values only.
|
|
43
87
|
*/
|
|
44
88
|
export interface ObjectAnimate {
|
|
45
89
|
<T extends object>(batch: ObjectBatch.ObjectBatch<T> | ObjectBatch.Member<T>, target: ObjectBatch.Target<T>, options?: Imperative.WardicAnimateOptionsFor<ObjectBatch.NumberKey<T>>): Imperative.WardicPlaybackControls;
|
|
46
|
-
<T extends
|
|
90
|
+
<T extends Readonly<Record<string, unknown>>, const G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>>(subject: T, target: ObjectTarget<T> | AnyKeyTargetFor<T, G>, options?: Imperative.WardicAnimateOptionsFor<AnimatableKey<T>>): Imperative.WardicPlaybackControls;
|
|
47
91
|
(sequence: ObjectSequence, options?: Imperative.WardicSequenceOptions): Imperative.WardicPlaybackControls;
|
|
92
|
+
<T extends object, const G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>>(subject: T | ReadonlyArray<T>, target: ObjectTarget<T> | AnyKeyTargetFor<T, G>, options?: Imperative.WardicAnimateOptionsFor<AnimatableKey<T>>): Imperative.WardicPlaybackControls;
|
|
48
93
|
}
|
|
49
94
|
/** A runtime's options. */
|
|
50
95
|
export interface Options {
|
|
@@ -131,7 +176,7 @@ export interface Environment {
|
|
|
131
176
|
* its own way. `undefined` for anything it doesn't make a Batch of.
|
|
132
177
|
*/
|
|
133
178
|
readonly batchSource?: ((given: object) => BatchSource | undefined) | undefined;
|
|
134
|
-
/** Layers of its own: its `UnitScale`, say. */
|
|
179
|
+
/** Layers of its own, which win over the services `make` gives: its `UnitScale`, say, or a Default transition. */
|
|
135
180
|
readonly layers?: Layer.Layer<never> | undefined;
|
|
136
181
|
}
|
|
137
182
|
/** Plain objects' Environment: each key the object's own property. */
|
|
@@ -145,4 +190,5 @@ export declare const layer: (frames: PumpedFrames.PumpedFrames, options?: Option
|
|
|
145
190
|
export declare const make: (options?: Options) => WardicObject;
|
|
146
191
|
/** A runtime on frames the host pumps, for `environment`'s objects: what `@wardic/three` builds on. */
|
|
147
192
|
export declare const makeWith: (environment: Environment, options?: Options) => WardicObject;
|
|
193
|
+
export {};
|
|
148
194
|
//# sourceMappingURL=WardicObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WardicObject.d.ts","sourceRoot":"","sources":["../src/WardicObject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WardicObject.d.ts","sourceRoot":"","sources":["../src/WardicObject.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,KAAK,QAAQ,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAA;AAE3D,OAAO,KAAK,KAAK,MAAM,MAAM,8BAA8B,CAAA;AAC3D,OAAO,KAAK,SAAS,MAAM,iCAAiC,CAAA;AAC5D,OAAO,KAAK,KAAK,SAAS,MAAM,iCAAiC,CAAA;AACjE,OAAO,KAAK,KAAK,KAAK,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,YAAY,MAAM,oCAAoC,CAAA;AAElE,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAA;AAE9D,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAA;AAQtE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAKrC,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAA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7E,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,UAAU,CAAA;IAC5D,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,KAAK,CAAA;IACnC,8CAA8C;IAC9C,QAAQ,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;IAClE,4CAA4C;IAC5C,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1C,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;IAC7D;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAC/E,kHAAkH;IAClH,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;CACjD;AAED,sEAAsE;AACtE,eAAO,MAAM,OAAO,EAAE,WAWrB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,WAAY,YAAY,CAAC,YAAY,YAAW,OAAO,gBAAoB,WAAW,KAAa,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CACrH,CAAA;AA0EzC,4GAA4G;AAC5G,eAAO,MAAM,IAAI,aAAa,OAAO,KAAQ,YAA0C,CAAA;AAEvF,uGAAuG;AACvG,eAAO,MAAM,QAAQ,gBAAiB,WAAW,YAAW,OAAO,KAAQ,YA8D1E,CAAA"}
|
package/dist/WardicObject.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* - **Keys** are an object's own properties, by name: `animate(sprite, { x: 100 })` writes `sprite.x`.
|
|
8
8
|
* Each starts from the property's value when the animation starts. A key the object doesn't have,
|
|
9
|
-
* or whose value is neither a number nor a string, is an error naming it
|
|
9
|
+
* can't write, or whose value is neither a number nor a string, is an error at the call naming it,
|
|
10
|
+
* and the call takes nothing: what animated the other keys runs on.
|
|
10
11
|
* - **Values** are numbers, and strings with a unit or of numbers (`"10px"`, `"0 0 4px"`). An array in
|
|
11
12
|
* a target is keyframes, as Motion's.
|
|
12
13
|
* - **Transitions** are Motion's by a key's name when a key gives none: a spring for a transform's
|
|
@@ -62,6 +63,7 @@ import * as ObjectBatch from "./ObjectBatch.js";
|
|
|
62
63
|
import * as ObjectRenderer from "./ObjectRenderer.js";
|
|
63
64
|
import * as ObjectValues from "./ObjectValues.js";
|
|
64
65
|
import * as PumpedFrames from "./PumpedFrames.js";
|
|
66
|
+
import * as TransformKeys from "./internal/transform-keys.js";
|
|
65
67
|
/** The user's reduced-motion query, where the host has `matchMedia`; none in Node or a worker. */
|
|
66
68
|
const reducedMotionQuery = () => UndefinedOr.match(globalThis.matchMedia, {
|
|
67
69
|
onUndefined: constUndefined,
|
|
@@ -86,15 +88,22 @@ export const OBJECTS = {
|
|
|
86
88
|
gate: ObjectRenderer.GATE,
|
|
87
89
|
startLinksOf: ObjectValues.startLinksOf,
|
|
88
90
|
ownValues: ObjectValues.ownValues,
|
|
89
|
-
positionalKeys:
|
|
91
|
+
positionalKeys: TransformKeys.positionalKeys,
|
|
90
92
|
batchWriter: ObjectBatch.writer,
|
|
91
93
|
batchRead: ObjectBatch.read,
|
|
94
|
+
// Motion's names beside core's transforms run on a transform's spring (#1002): over core's Default transition,
|
|
95
|
+
// which an Environment of objects that draws none of them, three's, keeps.
|
|
96
|
+
layers: TransformKeys.defaultTransition,
|
|
92
97
|
};
|
|
93
98
|
/**
|
|
94
99
|
* The Environment's services, on `frames`: the Effect form, for an app that runs Wardic's Effects
|
|
95
100
|
* itself. `make` builds its runtime on it; `environment` is plain objects' unless given.
|
|
96
101
|
*/
|
|
97
|
-
export const layer = (frames, options = {}, environment = OBJECTS) =>
|
|
102
|
+
export const layer = (frames, options = {}, environment = OBJECTS) => layerWith(environment, frames, options);
|
|
103
|
+
/** `environment`'s services, on `frames`: what `layer` gives, with no Environment to fall back on. */
|
|
104
|
+
// #972: `makeWith` builds on this, not on `layer`, whose default would keep `OBJECTS` (plain objects' renderer,
|
|
105
|
+
// gate and own-value read) in every app that gives an Environment of its own, `@wardic/three`'s.
|
|
106
|
+
const layerWith = (environment, frames, options) => FrameLoop.layer.pipe(Layer.provideMerge(Layer.mergeAll(Clock.layer.pipe(Layer.provideMerge(PumpedFrames.layer(frames))), environment.renderer, probeLayer(reducedMotionQuery()), InterpolatorRegistry.layer, environment.positionalKeys, DefaultTransition.layerByKey, Announcer.layerSilent, UndefinedOr.match(environment.layers, { onUndefined: () => Layer.empty, onDefined: (given) => given }))), Layer.provideMerge(UndefinedOr.match(options.registry, {
|
|
98
107
|
onUndefined: () => AtomRegistry.layer,
|
|
99
108
|
onDefined: (registry) => Layer.succeed(AtomRegistry.AtomRegistry, registry),
|
|
100
109
|
})));
|
|
@@ -143,7 +152,7 @@ export const make = (options = {}) => makeWith(OBJECTS, options);
|
|
|
143
152
|
/** A runtime on frames the host pumps, for `environment`'s objects: what `@wardic/three` builds on. */
|
|
144
153
|
export const makeWith = (environment, options = {}) => {
|
|
145
154
|
const frames = PumpedFrames.make(options.now);
|
|
146
|
-
const runtime = ManagedRuntime.make(gateLayerOf(environment.gate).pipe(Layer.provideMerge(
|
|
155
|
+
const runtime = ManagedRuntime.make(gateLayerOf(environment.gate).pipe(Layer.provideMerge(layerWith(environment, frames, options))));
|
|
147
156
|
const { gate, positionalKeys, defaultTransition } = runtime.runSync(Effect.all({ gate: Gate, positionalKeys: ReducedMotion.PositionalKeys, defaultTransition: DefaultTransition.DefaultTransition }));
|
|
148
157
|
const config = UndefinedOr.match(options.reducedMotion, { onUndefined: () => "user", onDefined: (given) => given });
|
|
149
158
|
const skip = options.skipAnimations === true;
|
package/dist/WardicObject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WardicObject.js","sourceRoot":"","sources":["../src/WardicObject.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"WardicObject.js","sourceRoot":"","sources":["../src/WardicObject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,mGAAmG;AACnG,sGAAsG;AACtG,yGAAyG;AACzG,8BAA8B;AAC9B,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAA;AACnD,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,iBAAiB,MAAM,gCAAgC,CAAA;AACnE,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAA;AACnD,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAA;AACnD,OAAO,KAAK,oBAAoB,MAAM,mCAAmC,CAAA;AACzE,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAG3C,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAA;AAEnD,OAAO,KAAK,SAAS,MAAM,iCAAiC,CAAA;AAG5D,OAAO,KAAK,YAAY,MAAM,oCAAoC,CAAA;AAClE,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAA;AAC9D,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAA;AAC9D,OAAO,KAAK,MAAM,MAAM,8BAA8B,CAAA;AACtD,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAA;AACtE,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD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H,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,WAAW,CAAC,IAAI,CAAI,YAAY,EAAE,KAAyB,EAAE,OAAO,CAAC,CAAA;QACpG,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;QAC9B,IAAI,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,4HAA4H,CAAC,CAAA;QAChL,OAAO,WAAW,CAAC,IAAI,CAAI,EAAE,GAAG,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,OAA2B,EAAE,OAAO,CAAC,CAAA;IACxI,CAAC,CAAA;IACD,OAAO;QACL,OAAO;QACP,KAAK;QACL,WAAW,EAAE,OAAO,CAAC,GAAG;QACxB,KAAK;QACL,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;QACnE,OAAO;QACP,gBAAgB,EAAE,EAAE,GAAG,GAAG,EAAE,YAAY,EAAE,WAAW,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE;KAC5F,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object's transform keys: core's (`ReducedMotion.isTransform`), and the names Motion gives a transform
|
|
3
|
+
* beside them, `translateX`, `translateY` and `translateZ`, the turn in the plane (`rotate`) and the skews.
|
|
4
|
+
* A key named as Motion names a transform runs as one on any object: on a transform's spring when it gives
|
|
5
|
+
* no transition, and snapped under reduced motion.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import * as DefaultTransition from "@wardic/core/DefaultTransition";
|
|
10
|
+
import * as ReducedMotion from "@wardic/core/ReducedMotion";
|
|
11
|
+
import * as Layer from "effect/Layer";
|
|
12
|
+
/** An object's Positional keys: its transform keys, which reduced motion snaps. */
|
|
13
|
+
export declare const positionalKeys: Layer.Layer<ReducedMotion.PositionalKeys>;
|
|
14
|
+
/** An object's Default transition: {@link transitionFor} for each key, Motion's keyframes tween through more than two stops. */
|
|
15
|
+
export declare const defaultTransition: Layer.Layer<DefaultTransition.DefaultTransition>;
|
|
16
|
+
//# sourceMappingURL=transform-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-keys.d.ts","sourceRoot":"","sources":["../../src/internal/transform-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,iBAAiB,MAAM,gCAAgC,CAAA;AACnE,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAoBrC,mFAAmF;AACnF,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAA+F,CAAA;AAUpK,gIAAgI;AAChI,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAG7E,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object's transform keys: core's (`ReducedMotion.isTransform`), and the names Motion gives a transform
|
|
3
|
+
* beside them, `translateX`, `translateY` and `translateZ`, the turn in the plane (`rotate`) and the skews.
|
|
4
|
+
* A key named as Motion names a transform runs as one on any object: on a transform's spring when it gives
|
|
5
|
+
* no transition, and snapped under reduced motion.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
// #1002 (ADR-0073, *Amendment (#1002)*, Q4): core's table lost the six only the DOM draws, but an object's
|
|
10
|
+
// keys are Motion's names (`animate(sprite, { rotate: 90 })`), so it adds them, as three adds `fov` and
|
|
11
|
+
// `zoom`. Plain objects' Environment, `OBJECTS`, gives this Default transition through its `layers`, over
|
|
12
|
+
// core's, which an Environment built on `WardicObject`'s takes otherwise: three's, since a scene draws none of
|
|
13
|
+
// the six (Q9, the review), and which leaves this module out of its bundle.
|
|
14
|
+
import * as DefaultTransition from "@wardic/core/DefaultTransition";
|
|
15
|
+
import * as ReducedMotion from "@wardic/core/ReducedMotion";
|
|
16
|
+
import * as Layer from "effect/Layer";
|
|
17
|
+
import * as Predicate from "effect/Predicate";
|
|
18
|
+
/** Each of an object's own transform keys, with the key of core's it runs as: its twin, a translation's or a turn's. */
|
|
19
|
+
// Q3: a twin's transition, the same object, as the DOM's own keys take one.
|
|
20
|
+
const RUNS_AS = new Map([
|
|
21
|
+
["translateX", "x"],
|
|
22
|
+
["translateY", "y"],
|
|
23
|
+
["translateZ", "z"],
|
|
24
|
+
["rotate", "rotateZ"],
|
|
25
|
+
["skewX", "rotateZ"],
|
|
26
|
+
["skewY", "rotateZ"],
|
|
27
|
+
]);
|
|
28
|
+
/** Whether `key` is one of an object's own transform keys, Motion's names beside core's. */
|
|
29
|
+
const isOwnTransformKey = (key) => RUNS_AS.has(key);
|
|
30
|
+
/** Whether `key` is one of an object's transform keys: core's, or Motion's names beside them. */
|
|
31
|
+
const isTransformKey = /*#__PURE__*/ Predicate.or(ReducedMotion.isTransform, isOwnTransformKey);
|
|
32
|
+
/** An object's Positional keys: its transform keys, which reduced motion snaps. */
|
|
33
|
+
export const positionalKeys = /*#__PURE__*/ Layer.succeed(ReducedMotion.PositionalKeys, { isPositional: isTransformKey });
|
|
34
|
+
/** The transition `key` runs on toward `target` when its own isn't defined: Motion's, by its name. */
|
|
35
|
+
// Per key per Retarget: statements (docs/agents/effect-first.md, the hot path).
|
|
36
|
+
const transitionFor = (key, target) => {
|
|
37
|
+
const twin = RUNS_AS.get(key);
|
|
38
|
+
if (Predicate.isUndefined(twin))
|
|
39
|
+
return DefaultTransition.byKey(key, target);
|
|
40
|
+
return DefaultTransition.byKey(twin, target);
|
|
41
|
+
};
|
|
42
|
+
/** An object's Default transition: {@link transitionFor} for each key, Motion's keyframes tween through more than two stops. */
|
|
43
|
+
export const defaultTransition = /*#__PURE__*/ Layer.succeed(DefaultTransition.DefaultTransition, {
|
|
44
|
+
transitionFor,
|
|
45
|
+
keyframes: DefaultTransition.KEYFRAMES_TWEEN,
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=transform-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-keys.js","sourceRoot":"","sources":["../../src/internal/transform-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,2GAA2G;AAC3G,wGAAwG;AACxG,0GAA0G;AAC1G,+GAA+G;AAC/G,4EAA4E;AAC5E,OAAO,KAAK,iBAAiB,MAAM,gCAAgC,CAAA;AACnE,OAAO,KAAK,aAAa,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAE7C,wHAAwH;AACxH,4EAA4E;AAC5E,MAAM,OAAO,GAAgC,IAAI,GAAG,CAAC;IACnD,CAAC,YAAY,EAAE,GAAG,CAAC;IACnB,CAAC,YAAY,EAAE,GAAG,CAAC;IACnB,CAAC,YAAY,EAAE,GAAG,CAAC;IACnB,CAAC,QAAQ,EAAE,SAAS,CAAC;IACrB,CAAC,OAAO,EAAE,SAAS,CAAC;IACpB,CAAC,OAAO,EAAE,SAAS,CAAC;CACrB,CAAC,CAAA;AAEF,4FAA4F;AAC5F,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAEpE,iGAAiG;AACjG,MAAM,cAAc,GAAgC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAA;AAE5H,mFAAmF;AACnF,MAAM,CAAC,MAAM,cAAc,GAA8C,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,cAAc,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC,CAAA;AAEpK,sGAAsG;AACtG,gFAAgF;AAChF,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,MAAuB,EAAgC,EAAE;IAC3F,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC;QAAE,OAAO,iBAAiB,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAC5E,OAAO,iBAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,gIAAgI;AAChI,MAAM,CAAC,MAAM,iBAAiB,GAAqD,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,iBAAiB,EAAE;IAClJ,aAAa;IACb,SAAS,EAAE,iBAAiB,CAAC,eAAe;CAC7C,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wardic/object",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Wardic for any object's properties: Motion's animate on plain objects, on frames the host pumps, for canvas and WebGL.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"animation",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"typecheck:tests": "../../node_modules/typescript-7/bin/tsc -p tsconfig.test.json"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@wardic/core": "1.
|
|
60
|
+
"@wardic/core": "1.4.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"effect": "^4.1.4"
|
package/src/ObjectValues.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A plain object's values for Wardic: where each key it animates starts (the property's own value), and
|
|
3
3
|
* the ports core reads an Environment's values through, with no style, no layout to measure and no
|
|
4
|
-
* variables. A key the object doesn't have,
|
|
5
|
-
* error naming it: Wardic writes no property
|
|
4
|
+
* variables. A key the object doesn't have, whose value is neither a number nor a string, or that it
|
|
5
|
+
* can't write (read-only, or a getter with no setter) is an error naming it: Wardic writes no property
|
|
6
|
+
* the object didn't have.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* import * as ObjectValues from "@wardic/object/ObjectValues"
|
|
@@ -33,10 +34,41 @@ const nameOf = (subject: object): string =>
|
|
|
33
34
|
Option.match({ onNone: () => "the object", onSome: (name) => `a ${name}` }),
|
|
34
35
|
)
|
|
35
36
|
|
|
36
|
-
/**
|
|
37
|
+
/** The nearest descriptor for `key` up `holder`'s prototypes, past its own; none where none has it. */
|
|
38
|
+
const inheritedOf = (holder: object, key: string): PropertyDescriptor | undefined => {
|
|
39
|
+
const above = Object.getPrototypeOf(holder) as object | null
|
|
40
|
+
if (Predicate.isNull(above)) return undefined
|
|
41
|
+
const found = Object.getOwnPropertyDescriptor(above, key)
|
|
42
|
+
if (Predicate.isNotUndefined(found)) return found
|
|
43
|
+
return inheritedOf(above, key)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Whether Wardic can write `holder`'s `key`: a writable property of its own, or a getter with a setter, its
|
|
48
|
+
* own or inherited; or an inherited writable property, where the holder can take one of its own (it isn't
|
|
49
|
+
* frozen, sealed or kept from extending).
|
|
50
|
+
*/
|
|
51
|
+
// #968: else each frame's write threw, in strict mode, and the flush stopped at it (#969). @wardic/three's
|
|
52
|
+
// lookup has its own, over each holder it finds a key at. Per key at a leg's start, the hot path
|
|
53
|
+
// (effect-first.md): statements.
|
|
54
|
+
const isWritable = (holder: object, key: string): boolean => {
|
|
55
|
+
const own = Object.getOwnPropertyDescriptor(holder, key)
|
|
56
|
+
if (Predicate.isNotUndefined(own)) return own.writable === true || Predicate.isNotUndefined(own.set)
|
|
57
|
+
const inherited = inheritedOf(holder, key)
|
|
58
|
+
if (Predicate.isUndefined(inherited)) return true
|
|
59
|
+
if (Predicate.isNotUndefined(inherited.set)) return true
|
|
60
|
+
return inherited.writable === true && Object.isExtensible(holder)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** `subject`'s own value for `key`: a number or a string it can write, else an error naming the key. */
|
|
37
64
|
const ownValueOf = (subject: object, key: string): Option.Option<number | string> => {
|
|
38
65
|
const value = (subject as Readonly<Record<string, unknown>>)[key]
|
|
39
|
-
if (Bool.or(Predicate.isNumber(value), Predicate.isString(value)))
|
|
66
|
+
if (Bool.or(Predicate.isNumber(value), Predicate.isString(value))) {
|
|
67
|
+
if (!isWritable(subject, key)) {
|
|
68
|
+
throw new Error(`wardic.animate: ${nameOf(subject)}'s "${key}" can't be written (it's read-only, or a getter with no setter), so Wardic can't animate it. Give a key it can write.`)
|
|
69
|
+
}
|
|
70
|
+
return Option.some(value as number | string)
|
|
71
|
+
}
|
|
40
72
|
if (Predicate.isUndefined(value)) {
|
|
41
73
|
throw new Error(`wardic.animate: ${nameOf(subject)} has no "${key}" to animate. Give a key it has, a number or a string; Wardic adds no property to an object.`)
|
|
42
74
|
}
|
package/src/WardicObject.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* - **Keys** are an object's own properties, by name: `animate(sprite, { x: 100 })` writes `sprite.x`.
|
|
8
8
|
* Each starts from the property's value when the animation starts. A key the object doesn't have,
|
|
9
|
-
* or whose value is neither a number nor a string, is an error naming it
|
|
9
|
+
* can't write, or whose value is neither a number nor a string, is an error at the call naming it,
|
|
10
|
+
* and the call takes nothing: what animated the other keys runs on.
|
|
10
11
|
* - **Values** are numbers, and strings with a unit or of numbers (`"10px"`, `"0 0 4px"`). An array in
|
|
11
12
|
* a target is keyframes, as Motion's.
|
|
12
13
|
* - **Transitions** are Motion's by a key's name when a key gives none: a spring for a transform's
|
|
@@ -67,23 +68,95 @@ import * as ObjectBatch from "./ObjectBatch.ts"
|
|
|
67
68
|
import * as ObjectRenderer from "./ObjectRenderer.ts"
|
|
68
69
|
import * as ObjectValues from "./ObjectValues.ts"
|
|
69
70
|
import * as PumpedFrames from "./PumpedFrames.ts"
|
|
71
|
+
import * as TransformKeys from "./internal/transform-keys.ts"
|
|
70
72
|
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
+
/**
|
|
74
|
+
* A key of `T` Wardic animates, by name: one whose value is a number or a string. An optional one among
|
|
75
|
+
* them: `animate` throws if the object lacks it when called. A numeric key by its name too, as `"0"`, a
|
|
76
|
+
* number index's as `` `${number}` ``: a typed array's elements, not its own numbers (`length`,
|
|
77
|
+
* `byteLength`, `byteOffset`, `BYTES_PER_ELEMENT`), which it can't write. An array has none: a list is
|
|
78
|
+
* many Subjects.
|
|
79
|
+
*/
|
|
80
|
+
// #963: over an array, the mapped keys come out as `string`, so an inline sequence, read as a list of
|
|
81
|
+
// arrays, looked like Subjects of any name, its options unchecked. `[T]`, not `T`: a union of Subjects
|
|
82
|
+
// (a mixed list's) keeps only the keys its members share, not distributed over each.
|
|
83
|
+
// #964: a key's `undefined` left out, an optional key's; one that only ever holds `undefined` has none.
|
|
84
|
+
// A number key by its name, so the keys stay strings, as the run time reads them.
|
|
85
|
+
export type AnimatableKey<T> = [T] extends [ReadonlyArray<unknown>]
|
|
86
|
+
? never
|
|
87
|
+
: Exclude<{ readonly [K in keyof T]-?: [Defined<T[K]>] extends [never] ? never : Defined<T[K]> extends number | string ? KeyName<K> : never }[keyof T], TypedArrayOwnKey<T>>
|
|
88
|
+
|
|
89
|
+
/** A typed array's own numbers, which it can't write: on `T`, or on any of a list's. */
|
|
90
|
+
// #968: their writes threw each frame. Only these: `readonly` says nothing at run time, a Readonly<…>
|
|
91
|
+
// being writable. Distributed, so a list with a typed array in it leaves them out too.
|
|
92
|
+
type TypedArrayOwnKey<T> = T extends ArrayBufferView ? "length" | "byteLength" | "byteOffset" | "BYTES_PER_ELEMENT" : never
|
|
93
|
+
|
|
94
|
+
/** A key's value with its `undefined` left out: an optional key's, as the object holds it. */
|
|
95
|
+
type Defined<V> = Exclude<V, undefined>
|
|
96
|
+
|
|
97
|
+
/** A key's name: a number key's as a string, as the run time reads it. */
|
|
98
|
+
type KeyName<K> = K extends string ? K : K extends number ? `${K}` : never
|
|
99
|
+
|
|
100
|
+
/** A key's name as a target writes it: a numeric one as its number, a name that only reads as one (`"01"`) as itself. */
|
|
101
|
+
// #964: a `${number}` index never checks a numeric key's value (`{ 0: "x" }`), in TS 6 or 7; a number
|
|
102
|
+
// index does. `"01"` infers `number`, so a name is a number only if that number prints as it.
|
|
103
|
+
type TargetKey<K> = K extends `${infer N extends number}` ? (`${N}` extends K ? N : K) : K
|
|
104
|
+
|
|
105
|
+
/** The value `T` holds under its key named `K`, without `undefined`: a numeric name's at its number. */
|
|
106
|
+
type HeldAt<T, K> = Defined<K extends keyof T ? T[K] : K extends `${infer N extends number}` ? T[N & keyof T] : never>
|
|
73
107
|
|
|
74
108
|
/**
|
|
75
|
-
* A target for `T`: each of its animatable keys a value or keyframes
|
|
76
|
-
*
|
|
77
|
-
*
|
|
109
|
+
* A target for `T`: each of its animatable keys a value or keyframes, never `undefined` (an optional
|
|
110
|
+
* key's too), a numeric key by its index (a typed array's element, `{ 0: 1 }`); a transition, with an
|
|
111
|
+
* entry under any of those keys, which `animate`'s options are laid over field by field; and a
|
|
112
|
+
* Transition end, its values set once the object lands. An array has none that fits: `animate` reads
|
|
113
|
+
* one as a list of Subjects, or a sequence, never as one Subject.
|
|
78
114
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
115
|
+
// #963: else an inline sequence with options, read as a list of arrays, fit the subject signature
|
|
116
|
+
// with whatever options fit an array's target (`{}`, a `transition`), unchecked, its Segments with it.
|
|
117
|
+
export type ObjectTarget<T> = [T] extends [ReadonlyArray<unknown>]
|
|
118
|
+
? NotOneSubject
|
|
119
|
+
: {
|
|
120
|
+
readonly [K in AnimatableKey<T> as TargetKey<K>]?: ValueAt<T, K>
|
|
121
|
+
} & {
|
|
122
|
+
/** How it gets there: a spring, a tween or an inertia, with an entry under any of `T`'s keys it animates. */
|
|
123
|
+
readonly transition?: Config.WardicTransitionFor<AnimatableKey<T>> | undefined
|
|
124
|
+
/**
|
|
125
|
+
* Values set once it lands, with no animation, each under a key the object has and can write: one
|
|
126
|
+
* it lacks or can't write is an error at the call, as a key it animates is. One it has lost, or can
|
|
127
|
+
* no longer write, by then is reported and left as it is, and the rest are set.
|
|
128
|
+
*/
|
|
129
|
+
readonly transitionEnd?: TransitionEndOf<T> | undefined
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The target an array meets, which nothing fits: its name says why. */
|
|
133
|
+
type NotOneSubject = { readonly "an array isn't one Subject: a list of them, or a sequence, whose options are WardicSequenceOptions": never }
|
|
134
|
+
|
|
135
|
+
/** A target's value for `T`'s key named `K`: one of its values, or keyframes of them. */
|
|
136
|
+
type ValueAt<T, K> = HeldAt<T, K> | Config.WardicKeyframes<HeldAt<T, K>>
|
|
137
|
+
|
|
138
|
+
/** `T`'s Transition end: values for its animatable keys, set once it lands. */
|
|
139
|
+
type TransitionEndOf<T> = { readonly [K in AnimatableKey<T> as TargetKey<K>]?: HeldAt<T, K> }
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A target for `T` whose keys are any name (it has an index signature), checked key by key as given
|
|
143
|
+
* (`G`): `transition` as a transition, `transitionEnd` as its Transition end, and any other key as one
|
|
144
|
+
* of `T`'s values or keyframes. Since any name is one of its keys, a misspelt key isn't caught.
|
|
145
|
+
*/
|
|
146
|
+
// #958: as an ObjectTarget, its keys an index signature, `transition` and `transitionEnd` would have
|
|
147
|
+
// to be values too, which no transition is.
|
|
148
|
+
type AnyKeyTarget<T, G> = {
|
|
149
|
+
readonly [P in keyof G]: P extends "transition"
|
|
150
|
+
? Config.WardicTransitionFor<string> | undefined
|
|
151
|
+
: P extends "transitionEnd"
|
|
152
|
+
? TransitionEndOf<T> | undefined
|
|
153
|
+
: ValueAt<T, P>
|
|
85
154
|
}
|
|
86
155
|
|
|
156
|
+
/** Where `T`'s keys are any name, the target given, checked key by key ({@link AnyKeyTarget}); else nothing, an {@link ObjectTarget} its target. */
|
|
157
|
+
// Beside ObjectTarget<T>, not in place of it: a target typed as one, a wrapper's among them, still fits.
|
|
158
|
+
type AnyKeyTargetFor<T, G> = string extends AnimatableKey<T> ? AnyKeyTarget<T, G> : never
|
|
159
|
+
|
|
87
160
|
/** A Segment of objects, `[subject, target, options?]`: an object, or a list of them. Motion's. */
|
|
88
161
|
export type ObjectSegment =
|
|
89
162
|
| readonly [subject: object | ReadonlyArray<object>, target: Readonly<Record<string, number | string | Config.WardicKeyframes<number | string>>>]
|
|
@@ -101,11 +174,29 @@ export type ObjectSequence = ReadonlyArray<Imperative.WardicSequenceLabel | Obje
|
|
|
101
174
|
* `animate(subject, target, options?)` animates an object, or each of a list of them, to `target`;
|
|
102
175
|
* `animate(sequence, options?)` plays a sequence. Either returns its Playback controls. Motion's.
|
|
103
176
|
* The options' transition takes an entry under any of the keys the Subject animates: a Batch's, its keys.
|
|
177
|
+
* A Subject whose keys are any name (an index signature) has its target checked key by key as given,
|
|
178
|
+
* though a misspelt key isn't caught, any name being one of its keys; naming its type, `animate<T>(…)`,
|
|
179
|
+
* checks its keys as values only.
|
|
104
180
|
*/
|
|
105
181
|
export interface ObjectAnimate {
|
|
106
182
|
<T extends object>(batch: ObjectBatch.ObjectBatch<T> | ObjectBatch.Member<T>, target: ObjectBatch.Target<T>, options?: Imperative.WardicAnimateOptionsFor<ObjectBatch.NumberKey<T>>): Imperative.WardicPlaybackControls
|
|
107
|
-
|
|
183
|
+
// #959: a Subject whose type is assignable to a string record (an object literal's, an index
|
|
184
|
+
// signature's, a Record), its type inferred from it alone. Through `T | ReadonlyArray<T>`, an index
|
|
185
|
+
// signature reads as a list's members, and `T` falls back to `object`. Classes and arrays aren't
|
|
186
|
+
// string records, so they take the last signature, as before.
|
|
187
|
+
<T extends Readonly<Record<string, unknown>>, const G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>>(
|
|
188
|
+
subject: T,
|
|
189
|
+
target: ObjectTarget<T> | AnyKeyTargetFor<T, G>,
|
|
190
|
+
options?: Imperative.WardicAnimateOptionsFor<AnimatableKey<T>>,
|
|
191
|
+
): Imperative.WardicPlaybackControls
|
|
108
192
|
(sequence: ObjectSequence, options?: Imperative.WardicSequenceOptions): Imperative.WardicPlaybackControls
|
|
193
|
+
// Last, since past three overloads TypeScript reports only the last one's error: a Subject's target
|
|
194
|
+
// misspelt names its key, rather than "not a sequence".
|
|
195
|
+
<T extends object, const G extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>>(
|
|
196
|
+
subject: T | ReadonlyArray<T>,
|
|
197
|
+
target: ObjectTarget<T> | AnyKeyTargetFor<T, G>,
|
|
198
|
+
options?: Imperative.WardicAnimateOptionsFor<AnimatableKey<T>>,
|
|
199
|
+
): Imperative.WardicPlaybackControls
|
|
109
200
|
}
|
|
110
201
|
|
|
111
202
|
/** A runtime's options. */
|
|
@@ -229,7 +320,7 @@ export interface Environment {
|
|
|
229
320
|
* its own way. `undefined` for anything it doesn't make a Batch of.
|
|
230
321
|
*/
|
|
231
322
|
readonly batchSource?: ((given: object) => BatchSource | undefined) | undefined
|
|
232
|
-
/** Layers of its own: its `UnitScale`, say. */
|
|
323
|
+
/** Layers of its own, which win over the services `make` gives: its `UnitScale`, say, or a Default transition. */
|
|
233
324
|
readonly layers?: Layer.Layer<never> | undefined
|
|
234
325
|
}
|
|
235
326
|
|
|
@@ -239,9 +330,12 @@ export const OBJECTS: Environment = {
|
|
|
239
330
|
gate: ObjectRenderer.GATE,
|
|
240
331
|
startLinksOf: ObjectValues.startLinksOf,
|
|
241
332
|
ownValues: ObjectValues.ownValues,
|
|
242
|
-
positionalKeys:
|
|
333
|
+
positionalKeys: TransformKeys.positionalKeys,
|
|
243
334
|
batchWriter: ObjectBatch.writer,
|
|
244
335
|
batchRead: ObjectBatch.read,
|
|
336
|
+
// Motion's names beside core's transforms run on a transform's spring (#1002): over core's Default transition,
|
|
337
|
+
// which an Environment of objects that draws none of them, three's, keeps.
|
|
338
|
+
layers: TransformKeys.defaultTransition,
|
|
245
339
|
}
|
|
246
340
|
|
|
247
341
|
/**
|
|
@@ -249,6 +343,12 @@ export const OBJECTS: Environment = {
|
|
|
249
343
|
* itself. `make` builds its runtime on it; `environment` is plain objects' unless given.
|
|
250
344
|
*/
|
|
251
345
|
export const layer = (frames: PumpedFrames.PumpedFrames, options: Options = {}, environment: Environment = OBJECTS): Layer.Layer<WardicServices.WardicServices> =>
|
|
346
|
+
layerWith(environment, frames, options)
|
|
347
|
+
|
|
348
|
+
/** `environment`'s services, on `frames`: what `layer` gives, with no Environment to fall back on. */
|
|
349
|
+
// #972: `makeWith` builds on this, not on `layer`, whose default would keep `OBJECTS` (plain objects' renderer,
|
|
350
|
+
// gate and own-value read) in every app that gives an Environment of its own, `@wardic/three`'s.
|
|
351
|
+
const layerWith = (environment: Environment, frames: PumpedFrames.PumpedFrames, options: Options): Layer.Layer<WardicServices.WardicServices> =>
|
|
252
352
|
FrameLoop.layer.pipe(
|
|
253
353
|
Layer.provideMerge(
|
|
254
354
|
Layer.mergeAll(
|
|
@@ -323,7 +423,7 @@ export const make = (options: Options = {}): WardicObject => makeWith(OBJECTS, o
|
|
|
323
423
|
/** A runtime on frames the host pumps, for `environment`'s objects: what `@wardic/three` builds on. */
|
|
324
424
|
export const makeWith = (environment: Environment, options: Options = {}): WardicObject => {
|
|
325
425
|
const frames = PumpedFrames.make(options.now)
|
|
326
|
-
const runtime = ManagedRuntime.make(gateLayerOf(environment.gate).pipe(Layer.provideMerge(
|
|
426
|
+
const runtime = ManagedRuntime.make(gateLayerOf(environment.gate).pipe(Layer.provideMerge(layerWith(environment, frames, options))))
|
|
327
427
|
const { gate, positionalKeys, defaultTransition } = runtime.runSync(
|
|
328
428
|
Effect.all({ gate: Gate, positionalKeys: ReducedMotion.PositionalKeys, defaultTransition: DefaultTransition.DefaultTransition }),
|
|
329
429
|
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object's transform keys: core's (`ReducedMotion.isTransform`), and the names Motion gives a transform
|
|
3
|
+
* beside them, `translateX`, `translateY` and `translateZ`, the turn in the plane (`rotate`) and the skews.
|
|
4
|
+
* A key named as Motion names a transform runs as one on any object: on a transform's spring when it gives
|
|
5
|
+
* no transition, and snapped under reduced motion.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
// #1002 (ADR-0073, *Amendment (#1002)*, Q4): core's table lost the six only the DOM draws, but an object's
|
|
10
|
+
// keys are Motion's names (`animate(sprite, { rotate: 90 })`), so it adds them, as three adds `fov` and
|
|
11
|
+
// `zoom`. Plain objects' Environment, `OBJECTS`, gives this Default transition through its `layers`, over
|
|
12
|
+
// core's, which an Environment built on `WardicObject`'s takes otherwise: three's, since a scene draws none of
|
|
13
|
+
// the six (Q9, the review), and which leaves this module out of its bundle.
|
|
14
|
+
import * as DefaultTransition from "@wardic/core/DefaultTransition"
|
|
15
|
+
import * as ReducedMotion from "@wardic/core/ReducedMotion"
|
|
16
|
+
import * as Layer from "effect/Layer"
|
|
17
|
+
import * as Predicate from "effect/Predicate"
|
|
18
|
+
|
|
19
|
+
/** Each of an object's own transform keys, with the key of core's it runs as: its twin, a translation's or a turn's. */
|
|
20
|
+
// Q3: a twin's transition, the same object, as the DOM's own keys take one.
|
|
21
|
+
const RUNS_AS: ReadonlyMap<string, string> = new Map([
|
|
22
|
+
["translateX", "x"],
|
|
23
|
+
["translateY", "y"],
|
|
24
|
+
["translateZ", "z"],
|
|
25
|
+
["rotate", "rotateZ"],
|
|
26
|
+
["skewX", "rotateZ"],
|
|
27
|
+
["skewY", "rotateZ"],
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
/** Whether `key` is one of an object's own transform keys, Motion's names beside core's. */
|
|
31
|
+
const isOwnTransformKey = (key: string): boolean => RUNS_AS.has(key)
|
|
32
|
+
|
|
33
|
+
/** Whether `key` is one of an object's transform keys: core's, or Motion's names beside them. */
|
|
34
|
+
const isTransformKey: Predicate.Predicate<string> = /*#__PURE__*/ Predicate.or(ReducedMotion.isTransform, isOwnTransformKey)
|
|
35
|
+
|
|
36
|
+
/** An object's Positional keys: its transform keys, which reduced motion snaps. */
|
|
37
|
+
export const positionalKeys: Layer.Layer<ReducedMotion.PositionalKeys> = /*#__PURE__*/ Layer.succeed(ReducedMotion.PositionalKeys, { isPositional: isTransformKey })
|
|
38
|
+
|
|
39
|
+
/** The transition `key` runs on toward `target` when its own isn't defined: Motion's, by its name. */
|
|
40
|
+
// Per key per Retarget: statements (docs/agents/effect-first.md, the hot path).
|
|
41
|
+
const transitionFor = (key: string, target: number | string): DefaultTransition.Transition => {
|
|
42
|
+
const twin = RUNS_AS.get(key)
|
|
43
|
+
if (Predicate.isUndefined(twin)) return DefaultTransition.byKey(key, target)
|
|
44
|
+
return DefaultTransition.byKey(twin, target)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** An object's Default transition: {@link transitionFor} for each key, Motion's keyframes tween through more than two stops. */
|
|
48
|
+
export const defaultTransition: Layer.Layer<DefaultTransition.DefaultTransition> = /*#__PURE__*/ Layer.succeed(DefaultTransition.DefaultTransition, {
|
|
49
|
+
transitionFor,
|
|
50
|
+
keyframes: DefaultTransition.KEYFRAMES_TWEEN,
|
|
51
|
+
})
|