@zcomponent/core 0.0.21 → 0.0.23
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/lib/animation/animation.d.ts +16 -2
- package/lib/animation/animation.js +42 -13
- package/lib/animation/bezier.d.ts +1 -1
- package/lib/animation/bezier.js +1 -1
- package/lib/animation/clips/clip.d.ts +6 -5
- package/lib/animation/clips/clip.js +6 -5
- package/lib/animation/layer.d.ts +10 -4
- package/lib/animation/layer.js +20 -16
- package/lib/animation/layerclip.d.ts +4 -3
- package/lib/animation/layerclip.js +5 -1
- package/lib/animation/tracks/cliptrack.d.ts +2 -2
- package/lib/animation/tracks/cliptrack.js +2 -2
- package/lib/animation/tracks/propertytrack.d.ts +2 -2
- package/lib/animation/tracks/propertytrack.js +2 -2
- package/lib/animation/tracks/track.d.ts +4 -2
- package/lib/animation/tracks/track.js +4 -1
- package/lib/behaviors/ToggleLayerClips.d.ts +100 -0
- package/lib/behaviors/ToggleLayerClips.js +76 -0
- package/lib/{animation.d.ts → data/animation.d.ts} +5 -2
- package/lib/{data.d.ts → data/change.d.ts} +3 -2
- package/lib/{data.js → data/change.js} +23 -2
- package/lib/{interfaces.d.ts → data/core.d.ts} +1 -1
- package/lib/data/index.d.ts +3 -0
- package/lib/data/index.js +3 -0
- package/lib/inflate.d.ts +3 -2
- package/lib/inflate.js +23 -21
- package/lib/selectors.d.ts +7 -7
- package/lib/selectors.js +20 -6
- package/lib/types.d.ts +1 -1
- package/lib/types.js +1 -1
- package/lib/validators.d.ts +1 -1
- package/lib/zcomponent.d.ts +3 -9
- package/lib/zcomponent.js +12 -15
- package/package.json +1 -1
- /package/lib/{animation.js → data/animation.js} +0 -0
- /package/lib/{interfaces.js → data/core.js} +0 -0
|
@@ -2,18 +2,31 @@ import { Layer } from './layer';
|
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
3
|
import { Event } from '../event';
|
|
4
4
|
import { LayerClip } from './layerclip';
|
|
5
|
+
import { Clip } from './clips/clip';
|
|
5
6
|
import { AnimationState } from './animationstate';
|
|
7
|
+
import { Track } from './tracks/track';
|
|
6
8
|
/** @internal */
|
|
7
9
|
export declare enum AnimationEvents {
|
|
8
10
|
onLayerClipActive = "onLayerClipActive",
|
|
9
11
|
onLayerClipState = "onLayerClipState"
|
|
10
12
|
}
|
|
11
13
|
export declare class Animation {
|
|
14
|
+
private _initialize;
|
|
15
|
+
layers: {
|
|
16
|
+
[id: string]: Layer;
|
|
17
|
+
};
|
|
18
|
+
clips: {
|
|
19
|
+
[id: string]: Clip;
|
|
20
|
+
};
|
|
12
21
|
onTick: Event<[]>;
|
|
13
22
|
onLayerClipActive: Event<[layerClip: LayerClip]>;
|
|
14
23
|
onLayerClipState: Event<[layerClip: LayerClip]>;
|
|
24
|
+
clipByID: Map<string, Clip>;
|
|
25
|
+
layerByID: Map<string, Layer>;
|
|
26
|
+
layerClipByID: Map<string, LayerClip>;
|
|
27
|
+
trackByID: Map<string, Track>;
|
|
15
28
|
hasLayers: Observable<boolean, never>;
|
|
16
|
-
|
|
29
|
+
private _layers;
|
|
17
30
|
private _spotlightLayer?;
|
|
18
31
|
timeSource: (() => number) | undefined;
|
|
19
32
|
private _entityPaths;
|
|
@@ -23,13 +36,14 @@ export declare class Animation {
|
|
|
23
36
|
evt: AnimationEvents;
|
|
24
37
|
args: any[];
|
|
25
38
|
}[];
|
|
26
|
-
constructor();
|
|
39
|
+
constructor(_initialize?: boolean);
|
|
27
40
|
serializeState(): AnimationState;
|
|
28
41
|
restoreState(state: AnimationState): void;
|
|
29
42
|
dispose(): void;
|
|
30
43
|
addLayer(l: Layer): void;
|
|
31
44
|
insertLayer(l: Layer, indx: number): void;
|
|
32
45
|
removeLayer(l: Layer): void;
|
|
46
|
+
initialize(): void;
|
|
33
47
|
tick(): void;
|
|
34
48
|
registerEntityPath(path: string, entity: any, pathParts: (string | number)[]): void;
|
|
35
49
|
evaluateTouchedPaths(paths: string[], t?: number): void;
|
|
@@ -8,12 +8,19 @@ export var AnimationEvents;
|
|
|
8
8
|
AnimationEvents["onLayerClipState"] = "onLayerClipState";
|
|
9
9
|
})(AnimationEvents || (AnimationEvents = {}));
|
|
10
10
|
export class Animation {
|
|
11
|
-
constructor() {
|
|
11
|
+
constructor(_initialize = true) {
|
|
12
|
+
this._initialize = _initialize;
|
|
13
|
+
this.layers = Object.create(null);
|
|
14
|
+
this.clips = Object.create(null);
|
|
12
15
|
this.onTick = new Event();
|
|
13
16
|
this.onLayerClipActive = new Event();
|
|
14
17
|
this.onLayerClipState = new Event();
|
|
18
|
+
this.clipByID = new Map();
|
|
19
|
+
this.layerByID = new Map();
|
|
20
|
+
this.layerClipByID = new Map();
|
|
21
|
+
this.trackByID = new Map();
|
|
15
22
|
this.hasLayers = new Observable(false);
|
|
16
|
-
this.
|
|
23
|
+
this._layers = [];
|
|
17
24
|
this._entityPaths = new Map();
|
|
18
25
|
this._defaultValues = new Map();
|
|
19
26
|
/** @internal */
|
|
@@ -24,14 +31,14 @@ export class Animation {
|
|
|
24
31
|
byLayer: {},
|
|
25
32
|
byLayerClip: {},
|
|
26
33
|
};
|
|
27
|
-
for (const layer of this.
|
|
34
|
+
for (const layer of this._layers) {
|
|
28
35
|
layer._serialize(state);
|
|
29
36
|
}
|
|
30
37
|
this._spotlightLayer?._serialize(state);
|
|
31
38
|
return state;
|
|
32
39
|
}
|
|
33
40
|
restoreState(state) {
|
|
34
|
-
for (const layer of this.
|
|
41
|
+
for (const layer of this._layers) {
|
|
35
42
|
layer._restore(state);
|
|
36
43
|
}
|
|
37
44
|
this._spotlightLayer?._restore(state);
|
|
@@ -42,31 +49,51 @@ export class Animation {
|
|
|
42
49
|
this.onLayerClipState.clearListeners();
|
|
43
50
|
}
|
|
44
51
|
addLayer(l) {
|
|
45
|
-
this.
|
|
52
|
+
this._layers.push(l);
|
|
46
53
|
if (!this.hasLayers.value)
|
|
47
54
|
this.hasLayers.value = true;
|
|
55
|
+
if (l.scriptName)
|
|
56
|
+
this.layers[l.scriptName] = l;
|
|
57
|
+
if (l.id)
|
|
58
|
+
this.layerByID.set(l.id, l);
|
|
48
59
|
}
|
|
49
60
|
insertLayer(l, indx) {
|
|
50
|
-
this.
|
|
61
|
+
this._layers.splice(indx, 0, l);
|
|
51
62
|
if (!this.hasLayers.value)
|
|
52
63
|
this.hasLayers.value = true;
|
|
64
|
+
if (l.scriptName)
|
|
65
|
+
this.layers[l.scriptName] = l;
|
|
66
|
+
if (l.id)
|
|
67
|
+
this.layerByID.set(l.id, l);
|
|
53
68
|
}
|
|
54
69
|
removeLayer(l) {
|
|
55
|
-
const indx = this.
|
|
70
|
+
const indx = this._layers.indexOf(l);
|
|
56
71
|
if (indx >= 0)
|
|
57
|
-
this.
|
|
58
|
-
const hasLayers = this.
|
|
72
|
+
this._layers.splice(indx, 1);
|
|
73
|
+
const hasLayers = this._layers.length > 0 || this._spotlightLayer !== undefined;
|
|
59
74
|
if (this.hasLayers.value !== hasLayers)
|
|
60
75
|
this.hasLayers.value = hasLayers;
|
|
76
|
+
if (l.scriptName)
|
|
77
|
+
delete this.layers[l.scriptName];
|
|
78
|
+
if (l.id)
|
|
79
|
+
this.layerByID.delete(l.id);
|
|
80
|
+
}
|
|
81
|
+
initialize() {
|
|
82
|
+
if (this._initialize === true)
|
|
83
|
+
return;
|
|
84
|
+
this._initialize = true;
|
|
85
|
+
this.evaluateTouchedPaths(Object.keys(this._entityPaths));
|
|
61
86
|
}
|
|
62
87
|
tick() {
|
|
88
|
+
if (!this._initialize)
|
|
89
|
+
return;
|
|
63
90
|
const t = this.timeSource?.() ?? performance.now();
|
|
64
91
|
const touchedPaths = [];
|
|
65
92
|
if (this._spotlightLayer) {
|
|
66
93
|
this._spotlightLayer.tick(t, touchedPaths);
|
|
67
94
|
}
|
|
68
95
|
else {
|
|
69
|
-
for (const layer of this.
|
|
96
|
+
for (const layer of this._layers) {
|
|
70
97
|
layer.tick(t, touchedPaths);
|
|
71
98
|
}
|
|
72
99
|
}
|
|
@@ -77,6 +104,8 @@ export class Animation {
|
|
|
77
104
|
this._entityPaths.set(path, { entity, pathParts });
|
|
78
105
|
}
|
|
79
106
|
evaluateTouchedPaths(paths, t) {
|
|
107
|
+
if (!this._initialize)
|
|
108
|
+
return;
|
|
80
109
|
t = t ?? this.timeSource?.() ?? performance.now();
|
|
81
110
|
const unique = new Set([...paths]);
|
|
82
111
|
for (const entry of unique.values()) {
|
|
@@ -94,13 +123,13 @@ export class Animation {
|
|
|
94
123
|
if (this._spotlightLayer)
|
|
95
124
|
touchedPaths.push(...this._spotlightLayer.influencedPaths.values());
|
|
96
125
|
this._spotlightLayer = l;
|
|
97
|
-
for (const layer of this.
|
|
126
|
+
for (const layer of this._layers) {
|
|
98
127
|
touchedPaths.push(...layer.influencedPaths.values());
|
|
99
128
|
if (l)
|
|
100
129
|
layer.pause();
|
|
101
130
|
}
|
|
102
131
|
this.evaluateTouchedPaths(touchedPaths);
|
|
103
|
-
const hasLayers = this.
|
|
132
|
+
const hasLayers = this._layers.length > 0 || this._spotlightLayer !== undefined;
|
|
104
133
|
if (this.hasLayers.value !== hasLayers)
|
|
105
134
|
this.hasLayers.value = hasLayers;
|
|
106
135
|
}
|
|
@@ -148,7 +177,7 @@ export class Animation {
|
|
|
148
177
|
val = this._spotlightLayer.computePathProperty(t, p, val);
|
|
149
178
|
}
|
|
150
179
|
else {
|
|
151
|
-
for (const layer of this.
|
|
180
|
+
for (const layer of this._layers) {
|
|
152
181
|
if (!layer.influencedPaths.has(p))
|
|
153
182
|
continue;
|
|
154
183
|
val = layer.computePathProperty(t, p, val);
|
package/lib/animation/bezier.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import * as Data from '../../
|
|
1
|
+
import * as Data from '../../data';
|
|
2
2
|
import { Observable } from '../../observable';
|
|
3
3
|
import { Animation } from '../animation';
|
|
4
4
|
import { Track } from '../tracks/track';
|
|
5
5
|
export declare class Clip {
|
|
6
6
|
animation: Animation;
|
|
7
7
|
length: number;
|
|
8
|
-
|
|
8
|
+
readonly scriptName?: string | undefined;
|
|
9
|
+
readonly id?: string | undefined;
|
|
9
10
|
influencedPathsDirty: Observable<boolean, never>;
|
|
10
|
-
defaultFadeParameters?: Data.FadeParameters
|
|
11
|
+
defaultFadeParameters?: Partial<Data.FadeParameters>;
|
|
11
12
|
private _influencedPaths;
|
|
12
13
|
private _tracksByPath;
|
|
13
14
|
private _tracksByPathDirty;
|
|
14
15
|
private _tracks;
|
|
15
|
-
constructor(animation: Animation, length: number);
|
|
16
|
+
constructor(animation: Animation, length: number, scriptName?: string | undefined, id?: string | undefined);
|
|
16
17
|
computePathProperty(t: number, p: string, valueBefore: any, parentWeight?: number): any;
|
|
17
18
|
addTrack(t: Track): void;
|
|
18
19
|
clearTracks(): void;
|
|
@@ -20,7 +21,7 @@ export declare class Clip {
|
|
|
20
21
|
get tracksByPath(): Map<string, Track[]>;
|
|
21
22
|
get influencedPaths(): string[];
|
|
22
23
|
fadePropertiesByPath(props: {
|
|
23
|
-
[id: string]: Data.FadeParameters
|
|
24
|
+
[id: string]: Partial<Data.FadeParameters>;
|
|
24
25
|
}): void;
|
|
25
26
|
resolveClipTime(t: number, t0: number, s0: number, rate: number, t1?: number): number;
|
|
26
27
|
streamPlay(speed?: number): void;
|
|
@@ -2,9 +2,11 @@ import { Observable } from '../../observable';
|
|
|
2
2
|
import { ClipTrack } from '../tracks/cliptrack';
|
|
3
3
|
import { PropertyTrack } from '../tracks/propertytrack';
|
|
4
4
|
export class Clip {
|
|
5
|
-
constructor(animation, length) {
|
|
5
|
+
constructor(animation, length, scriptName, id) {
|
|
6
6
|
this.animation = animation;
|
|
7
7
|
this.length = length;
|
|
8
|
+
this.scriptName = scriptName;
|
|
9
|
+
this.id = id;
|
|
8
10
|
this.influencedPathsDirty = new Observable(false);
|
|
9
11
|
this._influencedPaths = [];
|
|
10
12
|
this._tracksByPath = new Map();
|
|
@@ -16,6 +18,8 @@ export class Clip {
|
|
|
16
18
|
this._tracksByPathDirty = true;
|
|
17
19
|
}
|
|
18
20
|
};
|
|
21
|
+
if (scriptName)
|
|
22
|
+
this.animation.clips[scriptName] = this;
|
|
19
23
|
}
|
|
20
24
|
computePathProperty(t, p, valueBefore, parentWeight) {
|
|
21
25
|
const tracks = this.tracksByPath.get(p);
|
|
@@ -72,16 +76,13 @@ export class Clip {
|
|
|
72
76
|
if (this.defaultFadeParameters) {
|
|
73
77
|
// Replace any existing fade properties with our defaults
|
|
74
78
|
for (const id in props) {
|
|
75
|
-
props[id] = { ...this.defaultFadeParameters };
|
|
79
|
+
props[id] = { ...props[id], ...this.defaultFadeParameters };
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
for (const track of this._tracks) {
|
|
79
83
|
if (track instanceof PropertyTrack) {
|
|
80
84
|
if (track.fadeParameters || this.defaultFadeParameters) {
|
|
81
85
|
const params = {
|
|
82
|
-
time: 0,
|
|
83
|
-
easing: null,
|
|
84
|
-
pin: 0,
|
|
85
86
|
...this.defaultFadeParameters,
|
|
86
87
|
...track.fadeParameters,
|
|
87
88
|
};
|
package/lib/animation/layer.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import * as Data from '../
|
|
1
|
+
import * as Data from '../data';
|
|
2
2
|
import { Observable } from '../observable';
|
|
3
3
|
import { Animation } from './animation';
|
|
4
4
|
import { AnimationState } from './animationstate';
|
|
5
5
|
import { LayerClip, LayerClipPlayOptions } from './layerclip';
|
|
6
6
|
export declare class Layer {
|
|
7
7
|
readonly animation: Animation;
|
|
8
|
-
|
|
8
|
+
readonly scriptName?: string | undefined;
|
|
9
|
+
readonly id?: string | undefined;
|
|
10
|
+
clips: {
|
|
11
|
+
[id: string]: LayerClip;
|
|
12
|
+
};
|
|
13
|
+
defaultFadeParameters?: Data.FadeParameters;
|
|
9
14
|
influencedPathsDirty: Observable<boolean, never>;
|
|
10
15
|
private _influencedPaths;
|
|
11
16
|
private _active;
|
|
12
17
|
private _queue;
|
|
13
18
|
private _layerClips;
|
|
14
|
-
constructor(animation: Animation);
|
|
19
|
+
constructor(animation: Animation, scriptName?: string | undefined, id?: string | undefined);
|
|
15
20
|
computePathProperty(t: number, p: string, valueBefore: any): any;
|
|
16
21
|
tick(t: number, touchedPaths: string[]): void;
|
|
17
22
|
pause(): void;
|
|
@@ -20,6 +25,7 @@ export declare class Layer {
|
|
|
20
25
|
queue(layerClip: LayerClip | null, playOptions?: LayerClipPlayOptions): QueueEntry;
|
|
21
26
|
get active(): LayerClip | null | undefined;
|
|
22
27
|
set active(layerClip: LayerClip | null | undefined);
|
|
28
|
+
setActive(layerClip: LayerClip | null, playOptions?: LayerClipPlayOptions): void;
|
|
23
29
|
/** @internal */
|
|
24
30
|
_activateLayerClip(layerClip: LayerClip | null | undefined, playOptions?: LayerClipPlayOptions): void;
|
|
25
31
|
/** @internal */
|
|
@@ -35,7 +41,7 @@ export interface QueueEntry {
|
|
|
35
41
|
layerClip: LayerClip | null;
|
|
36
42
|
playOptions?: LayerClipPlayOptions;
|
|
37
43
|
fadeByPath: {
|
|
38
|
-
[id: string]: Data.FadeParameters
|
|
44
|
+
[id: string]: Partial<Data.FadeParameters>;
|
|
39
45
|
};
|
|
40
46
|
fadeTime: number;
|
|
41
47
|
startTime?: number;
|
package/lib/animation/layer.js
CHANGED
|
@@ -4,8 +4,11 @@ import { computeEasing } from './bezier';
|
|
|
4
4
|
import { interpolate } from './interpolate';
|
|
5
5
|
import { StreamState } from './stream';
|
|
6
6
|
export class Layer {
|
|
7
|
-
constructor(animation) {
|
|
7
|
+
constructor(animation, scriptName, id) {
|
|
8
8
|
this.animation = animation;
|
|
9
|
+
this.scriptName = scriptName;
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.clips = Object.create(null);
|
|
9
12
|
this.influencedPathsDirty = new Observable(false);
|
|
10
13
|
this._influencedPaths = new Set();
|
|
11
14
|
this._active = null;
|
|
@@ -22,7 +25,7 @@ export class Layer {
|
|
|
22
25
|
if (ct >= entry.fadeTime)
|
|
23
26
|
fadeValue = clipValue;
|
|
24
27
|
else
|
|
25
|
-
fadeValue = computeFade(entry.fadeByPath[p], entry.playOptions?.fade, ct, entry.fadeTime, fadeValue, clipValue);
|
|
28
|
+
fadeValue = computeFade(this.defaultFadeParameters, entry.fadeByPath[p], entry.playOptions?.fade, ct, entry.fadeTime, fadeValue, clipValue);
|
|
26
29
|
}
|
|
27
30
|
else {
|
|
28
31
|
fadeValue = clipValue;
|
|
@@ -59,6 +62,8 @@ export class Layer {
|
|
|
59
62
|
/** @internal */
|
|
60
63
|
_registerLayerClip(layerClip) {
|
|
61
64
|
this._layerClips.push(layerClip);
|
|
65
|
+
if (layerClip.scriptName)
|
|
66
|
+
this.clips[layerClip.scriptName] = layerClip;
|
|
62
67
|
layerClip.clip.influencedPathsDirty.addListener(v => {
|
|
63
68
|
if (v)
|
|
64
69
|
this.influencedPathsDirty.value = true;
|
|
@@ -66,20 +71,15 @@ export class Layer {
|
|
|
66
71
|
this.influencedPathsDirty.value = true;
|
|
67
72
|
}
|
|
68
73
|
queue(layerClip, playOptions) {
|
|
69
|
-
const previous = this._queue[this._queue.length - 1];
|
|
70
74
|
const fadeByPath = {};
|
|
71
|
-
previous?.layerClip?.clip?.fadePropertiesByPath(fadeByPath);
|
|
72
|
-
for (const [path, params] of Object.entries(fadeByPath)) {
|
|
73
|
-
fadeByPath[path] = {
|
|
74
|
-
...params,
|
|
75
|
-
reverse: !(params.reverse ?? false),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
75
|
layerClip?.clip?.fadePropertiesByPath(fadeByPath);
|
|
79
76
|
let fadeTime = playOptions?.fade?.time ?? 0;
|
|
80
77
|
for (const params of Object.values(fadeByPath)) {
|
|
81
|
-
|
|
78
|
+
if (params.time !== undefined)
|
|
79
|
+
fadeTime = Math.max(fadeTime, params.time);
|
|
82
80
|
}
|
|
81
|
+
if (this.defaultFadeParameters)
|
|
82
|
+
fadeTime = Math.max(fadeTime, this.defaultFadeParameters.time);
|
|
83
83
|
const ret = {
|
|
84
84
|
layerClip,
|
|
85
85
|
fadeTime,
|
|
@@ -96,6 +96,10 @@ export class Layer {
|
|
|
96
96
|
this._activateLayerClip(layerClip);
|
|
97
97
|
this._evaulate();
|
|
98
98
|
}
|
|
99
|
+
setActive(layerClip, playOptions) {
|
|
100
|
+
this._activateLayerClip(layerClip, playOptions);
|
|
101
|
+
this._evaulate();
|
|
102
|
+
}
|
|
99
103
|
/** @internal */
|
|
100
104
|
_activateLayerClip(layerClip, playOptions) {
|
|
101
105
|
if (layerClip === undefined) {
|
|
@@ -188,11 +192,11 @@ export class Layer {
|
|
|
188
192
|
return this._influencedPaths;
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
|
-
function computeFade(params, override, t, fadeTime, before, after) {
|
|
195
|
+
function computeFade(defaults, params, override, t, fadeTime, before, after) {
|
|
192
196
|
// TODO further implementation
|
|
193
|
-
const paramTime = override?.time ?? params?.time ?? 0;
|
|
194
|
-
let paramPin = override?.pin ?? params?.pin ?? 0;
|
|
195
|
-
const reverse = override?.reverse ?? params?.reverse ?? false;
|
|
197
|
+
const paramTime = override?.time ?? params?.time ?? defaults?.time ?? 0;
|
|
198
|
+
let paramPin = override?.pin ?? params?.pin ?? defaults?.pin ?? 0;
|
|
199
|
+
const reverse = override?.reverse ?? params?.reverse ?? defaults?.reverse ?? false;
|
|
196
200
|
if (reverse)
|
|
197
201
|
paramPin = 1 - paramPin;
|
|
198
202
|
const emptyTime = fadeTime - paramTime;
|
|
@@ -204,7 +208,7 @@ function computeFade(params, override, t, fadeTime, before, after) {
|
|
|
204
208
|
let prop = (t - startTime) / paramTime;
|
|
205
209
|
if (reverse)
|
|
206
210
|
prop = 1 - prop;
|
|
207
|
-
prop = computeEasing(prop, override?.easing ?? params?.easing);
|
|
211
|
+
prop = computeEasing(prop, override?.easing ?? params?.easing ?? defaults?.easing);
|
|
208
212
|
if (reverse)
|
|
209
213
|
prop = 1 - prop;
|
|
210
214
|
return interpolate(before, after, prop);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FadeParameters } from '../
|
|
1
|
+
import { FadeParameters } from '../data';
|
|
2
2
|
import { Animation } from './animation';
|
|
3
3
|
import { AnimationState } from './animationstate';
|
|
4
4
|
import { Clip } from './clips/clip';
|
|
@@ -7,7 +7,8 @@ import { PlayOptions, Stream, StreamState } from './stream';
|
|
|
7
7
|
export declare class LayerClip implements Stream {
|
|
8
8
|
readonly layer: Layer;
|
|
9
9
|
readonly clip: Clip;
|
|
10
|
-
|
|
10
|
+
readonly scriptName?: string | undefined;
|
|
11
|
+
readonly id?: string | undefined;
|
|
11
12
|
defaultLoop: boolean;
|
|
12
13
|
defaultPlaySpeed: number;
|
|
13
14
|
timeSource: (() => number) | undefined;
|
|
@@ -20,7 +21,7 @@ export declare class LayerClip implements Stream {
|
|
|
20
21
|
private _lastClipTime;
|
|
21
22
|
private _stopped;
|
|
22
23
|
state: StreamState;
|
|
23
|
-
constructor(layer: Layer, clip: Clip);
|
|
24
|
+
constructor(layer: Layer, clip: Clip, scriptName?: string | undefined, id?: string | undefined);
|
|
24
25
|
private _clipDirty;
|
|
25
26
|
tick(touchedPaths: string[], force?: boolean): void;
|
|
26
27
|
computePathProperty(p: string, valueBefore: any): any;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { AnimationEvents } from './animation';
|
|
2
2
|
import { StreamState } from './stream';
|
|
3
3
|
export class LayerClip {
|
|
4
|
-
constructor(layer, clip) {
|
|
4
|
+
constructor(layer, clip, scriptName, id) {
|
|
5
5
|
this.layer = layer;
|
|
6
6
|
this.clip = clip;
|
|
7
|
+
this.scriptName = scriptName;
|
|
8
|
+
this.id = id;
|
|
7
9
|
this.defaultLoop = false;
|
|
8
10
|
this.defaultPlaySpeed = 1;
|
|
9
11
|
this._t0 = 0;
|
|
@@ -21,6 +23,8 @@ export class LayerClip {
|
|
|
21
23
|
this._t1 = clip.length;
|
|
22
24
|
layer._registerLayerClip(this);
|
|
23
25
|
this.clip.influencedPathsDirty.addListener(this._clipDirty);
|
|
26
|
+
if (id)
|
|
27
|
+
layer.animation.layerClipByID.set(id, this);
|
|
24
28
|
}
|
|
25
29
|
tick(touchedPaths, force) {
|
|
26
30
|
const t = this._getTime();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Keyframe, ClipTrackEntity } from '../../
|
|
1
|
+
import { Keyframe, ClipTrackEntity } from '../../data';
|
|
2
2
|
import { Clip } from '../clips/clip';
|
|
3
3
|
import { Track } from './track';
|
|
4
4
|
export declare class ClipTrack extends Track {
|
|
@@ -9,7 +9,7 @@ export declare class ClipTrack extends Track {
|
|
|
9
9
|
private _entities;
|
|
10
10
|
private _entitiesById;
|
|
11
11
|
private _entitiesDirty;
|
|
12
|
-
constructor(clip: Clip);
|
|
12
|
+
constructor(clip: Clip, id?: string);
|
|
13
13
|
get influencedPaths(): string[];
|
|
14
14
|
addWeight(k: Keyframe): void;
|
|
15
15
|
setWeightsById(weights: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveKeyframes, resolveKeyframeValue, Track } from './track';
|
|
2
2
|
export class ClipTrack extends Track {
|
|
3
|
-
constructor(clip) {
|
|
4
|
-
super();
|
|
3
|
+
constructor(clip, id) {
|
|
4
|
+
super(clip.animation, id);
|
|
5
5
|
this.clip = clip;
|
|
6
6
|
this._weights = [];
|
|
7
7
|
this._weightsById = {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FadeParameters, Keyframe, BlendType } from '../../
|
|
1
|
+
import { FadeParameters, Keyframe, BlendType } from '../../data';
|
|
2
2
|
import { Animation } from '../animation';
|
|
3
3
|
import { Track } from './track';
|
|
4
4
|
export declare class PropertyTrack extends Track {
|
|
@@ -15,7 +15,7 @@ export declare class PropertyTrack extends Track {
|
|
|
15
15
|
fadeParameters?: Partial<FadeParameters>;
|
|
16
16
|
blend: BlendType;
|
|
17
17
|
influencedPaths: string[];
|
|
18
|
-
constructor(anim: Animation, _entityID: string, _entity: any, property: string | number | (string | number)[]);
|
|
18
|
+
constructor(anim: Animation, _entityID: string, _entity: any, property: string | number | (string | number)[], id?: string);
|
|
19
19
|
addKeyframe(k: Keyframe): void;
|
|
20
20
|
getKeyframeById(id: string): Keyframe | undefined;
|
|
21
21
|
setKeyframesById(keyframes: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { addBlend, interpolate } from '../interpolate';
|
|
2
2
|
import { resolveKeyframes, resolveKeyframeValue, Track } from './track';
|
|
3
3
|
export class PropertyTrack extends Track {
|
|
4
|
-
constructor(anim, _entityID, _entity, property) {
|
|
5
|
-
super();
|
|
4
|
+
constructor(anim, _entityID, _entity, property, id) {
|
|
5
|
+
super(anim, id);
|
|
6
6
|
this._entityID = _entityID;
|
|
7
7
|
this._entity = _entity;
|
|
8
8
|
this._keyframes = [];
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Keyframe } from '../../
|
|
1
|
+
import { Keyframe } from '../../data';
|
|
2
2
|
import { Observable } from '../../observable';
|
|
3
|
+
import { Animation } from '../animation';
|
|
3
4
|
export declare abstract class Track {
|
|
5
|
+
readonly id?: string | undefined;
|
|
4
6
|
influencedPathsDirty: Observable<boolean, never>;
|
|
5
|
-
constructor();
|
|
7
|
+
constructor(anim: Animation, id?: string | undefined);
|
|
6
8
|
abstract get influencedPaths(): string[];
|
|
7
9
|
abstract computePathProperty(t: number, p: string, valueBefore: any, parentWeight?: number): any;
|
|
8
10
|
}
|
|
@@ -2,8 +2,11 @@ import { Observable } from '../../observable';
|
|
|
2
2
|
import { computeEasing } from '../bezier';
|
|
3
3
|
import { interpolate } from '../interpolate';
|
|
4
4
|
export class Track {
|
|
5
|
-
constructor() {
|
|
5
|
+
constructor(anim, id) {
|
|
6
|
+
this.id = id;
|
|
6
7
|
this.influencedPathsDirty = new Observable(false);
|
|
8
|
+
if (id)
|
|
9
|
+
anim.trackByID.set(id, this);
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
12
|
export function resolveKeyframeValue(t, before, after) {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ActionBehavior, ActionBehaviorConstructorProps } from "../actionbehavior";
|
|
2
|
+
import { Component } from "../component";
|
|
3
|
+
import { ContextManager } from "../context";
|
|
4
|
+
/**
|
|
5
|
+
* @zbehavior
|
|
6
|
+
* @zicon play_circle
|
|
7
|
+
* @zgroup Animation Actions
|
|
8
|
+
*/
|
|
9
|
+
export declare class ToggleLayerClips extends ActionBehavior {
|
|
10
|
+
private zcomponent;
|
|
11
|
+
/**
|
|
12
|
+
* @zprop
|
|
13
|
+
* @zgroup Play Settings
|
|
14
|
+
* @zgrouppriority 20
|
|
15
|
+
* @zvalues layerclipids
|
|
16
|
+
*/
|
|
17
|
+
layerClipA: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* @zprop
|
|
20
|
+
* @zgroup Play Settings
|
|
21
|
+
* @zgrouppriority 20
|
|
22
|
+
* @zvalues layerids
|
|
23
|
+
*/
|
|
24
|
+
layerOffA: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* @zprop
|
|
27
|
+
* @zgroup Play Settings
|
|
28
|
+
* @zgrouppriority 20
|
|
29
|
+
* @zvalues layerclipids
|
|
30
|
+
*/
|
|
31
|
+
layerClipB: string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* @zprop
|
|
34
|
+
* @zgroup Play Settings
|
|
35
|
+
* @zgrouppriority 20
|
|
36
|
+
* @zvalues layerids
|
|
37
|
+
*/
|
|
38
|
+
layerOffB: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* @zprop
|
|
41
|
+
* @zgroup Play Settings
|
|
42
|
+
* @zgrouppriority 20
|
|
43
|
+
* @zdefault false
|
|
44
|
+
*/
|
|
45
|
+
loop?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @zprop
|
|
48
|
+
* @zgroup Play Settings
|
|
49
|
+
* @zgrouppriority 20
|
|
50
|
+
* @zdefault 1
|
|
51
|
+
*/
|
|
52
|
+
speed?: number;
|
|
53
|
+
/**
|
|
54
|
+
* @zprop
|
|
55
|
+
* @zgroup Play Settings
|
|
56
|
+
* @zgrouppriority 20
|
|
57
|
+
* @zdefault false
|
|
58
|
+
*/
|
|
59
|
+
queue: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Seek the clip to the start before playing
|
|
62
|
+
*
|
|
63
|
+
* @zprop
|
|
64
|
+
* @zgroup Play Settings
|
|
65
|
+
* @zgrouppriority 20
|
|
66
|
+
* @zdefault false
|
|
67
|
+
*/
|
|
68
|
+
fromStart: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* @zprop
|
|
71
|
+
* @zgroup Override Fade
|
|
72
|
+
* @zgrouppriority 10
|
|
73
|
+
*/
|
|
74
|
+
fadeTime?: number;
|
|
75
|
+
/**
|
|
76
|
+
* @zprop
|
|
77
|
+
* @zgroup Override Fade
|
|
78
|
+
* @zgrouppriority 10
|
|
79
|
+
* @zdefault 0
|
|
80
|
+
*/
|
|
81
|
+
pin?: Pin | number;
|
|
82
|
+
/**
|
|
83
|
+
* @zprop
|
|
84
|
+
* @zgroup Override Fade
|
|
85
|
+
* @zgrouppriority 10
|
|
86
|
+
* @zdefault 0
|
|
87
|
+
* @zvalues easings
|
|
88
|
+
*/
|
|
89
|
+
easing?: string;
|
|
90
|
+
isA: boolean;
|
|
91
|
+
constructor(contextManager: ContextManager, instance: Component, props: ActionBehaviorConstructorProps);
|
|
92
|
+
perform(): void;
|
|
93
|
+
/** @zprop */
|
|
94
|
+
preview(): void;
|
|
95
|
+
}
|
|
96
|
+
export declare enum Pin {
|
|
97
|
+
Start = 0,
|
|
98
|
+
Middle = 0.5,
|
|
99
|
+
End = 1
|
|
100
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ActionBehavior, } from "../actionbehavior";
|
|
2
|
+
import { registerBehaviorRunAtDesignTime } from "../behavior";
|
|
3
|
+
/**
|
|
4
|
+
* @zbehavior
|
|
5
|
+
* @zicon play_circle
|
|
6
|
+
* @zgroup Animation Actions
|
|
7
|
+
*/
|
|
8
|
+
export class ToggleLayerClips extends ActionBehavior {
|
|
9
|
+
constructor(contextManager, instance, props) {
|
|
10
|
+
super(contextManager, instance, props);
|
|
11
|
+
this.zcomponent = this.getZComponentInstance();
|
|
12
|
+
/**
|
|
13
|
+
* @zprop
|
|
14
|
+
* @zgroup Play Settings
|
|
15
|
+
* @zgrouppriority 20
|
|
16
|
+
* @zdefault false
|
|
17
|
+
*/
|
|
18
|
+
this.queue = false;
|
|
19
|
+
/**
|
|
20
|
+
* Seek the clip to the start before playing
|
|
21
|
+
*
|
|
22
|
+
* @zprop
|
|
23
|
+
* @zgroup Play Settings
|
|
24
|
+
* @zgrouppriority 20
|
|
25
|
+
* @zdefault false
|
|
26
|
+
*/
|
|
27
|
+
this.fromStart = false;
|
|
28
|
+
this.isA = true;
|
|
29
|
+
}
|
|
30
|
+
perform() {
|
|
31
|
+
this.isA = !this.isA;
|
|
32
|
+
const opts = {
|
|
33
|
+
loop: this.loop,
|
|
34
|
+
speed: this.speed,
|
|
35
|
+
fade: {
|
|
36
|
+
time: this.fadeTime,
|
|
37
|
+
pin: this.pin,
|
|
38
|
+
easing: this.easing
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const layerID = this.isA ? this.layerOffA : this.layerOffB;
|
|
42
|
+
const layerClipID = this.isA ? this.layerClipA : this.layerClipB;
|
|
43
|
+
if (layerID) {
|
|
44
|
+
const layer = this.zcomponent.animation.layerByID.get(layerID);
|
|
45
|
+
if (!layer)
|
|
46
|
+
return;
|
|
47
|
+
if (this.queue ?? false)
|
|
48
|
+
layer.queue(null, opts);
|
|
49
|
+
else
|
|
50
|
+
layer.setActive(null, opts);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (layerClipID) {
|
|
54
|
+
const layerclip = this.zcomponent.animation.layerClipByID.get(layerClipID);
|
|
55
|
+
if (!layerclip)
|
|
56
|
+
return;
|
|
57
|
+
if (this.fromStart ?? false)
|
|
58
|
+
layerclip.seek(0, { dontActivateLayer: true });
|
|
59
|
+
if (this.queue ?? false)
|
|
60
|
+
layerclip.queue(opts);
|
|
61
|
+
else
|
|
62
|
+
layerclip.play(opts);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** @zprop */
|
|
66
|
+
preview() {
|
|
67
|
+
this.perform();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export var Pin;
|
|
71
|
+
(function (Pin) {
|
|
72
|
+
Pin[Pin["Start"] = 0] = "Start";
|
|
73
|
+
Pin[Pin["Middle"] = 0.5] = "Middle";
|
|
74
|
+
Pin[Pin["End"] = 1] = "End";
|
|
75
|
+
})(Pin || (Pin = {}));
|
|
76
|
+
registerBehaviorRunAtDesignTime(ToggleLayerClips);
|
|
@@ -21,6 +21,7 @@ export interface FadeParameters {
|
|
|
21
21
|
export interface Layer {
|
|
22
22
|
order: string;
|
|
23
23
|
name: string;
|
|
24
|
+
scriptName?: string;
|
|
24
25
|
id: string;
|
|
25
26
|
defaultFadeParameters?: FadeParameters;
|
|
26
27
|
clips: ByID<LayerClip>;
|
|
@@ -34,6 +35,7 @@ export interface LayerClip {
|
|
|
34
35
|
loop?: boolean;
|
|
35
36
|
reverse?: boolean;
|
|
36
37
|
playbackSpeed?: number;
|
|
38
|
+
scriptName?: string;
|
|
37
39
|
}
|
|
38
40
|
export type ActiveLayerClips = ByID<string | undefined>;
|
|
39
41
|
export declare enum ClipType {
|
|
@@ -49,8 +51,9 @@ export interface Clip {
|
|
|
49
51
|
tracks: ByID<Track>;
|
|
50
52
|
length: number;
|
|
51
53
|
lengthType: ClipLengthType;
|
|
52
|
-
defaultFadeParameters?: FadeParameters
|
|
54
|
+
defaultFadeParameters?: Partial<FadeParameters>;
|
|
53
55
|
timeSourceTrack?: string;
|
|
56
|
+
scriptName?: string;
|
|
54
57
|
}
|
|
55
58
|
export interface Keyframe {
|
|
56
59
|
id: string;
|
|
@@ -114,7 +117,7 @@ export interface StreamTrack extends BaseTrack {
|
|
|
114
117
|
data: ByID<StreamTrackEntity>;
|
|
115
118
|
weight: ByID<Keyframe>;
|
|
116
119
|
}
|
|
117
|
-
export interface StreamTrackEntity {
|
|
120
|
+
export interface StreamTrackEntity extends BaseTrack {
|
|
118
121
|
t0: number;
|
|
119
122
|
t1: number;
|
|
120
123
|
s0: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BehaviorByID, BehaviorData, ComputedHierarchy, EntityPropOverride, NodeByID, NodeData, ZComponentData } from './
|
|
2
|
-
import { Prop } from '
|
|
1
|
+
import { BehaviorByID, BehaviorData, ComputedHierarchy, EntityPropOverride, NodeByID, NodeData, ZComponentData } from './core';
|
|
2
|
+
import { Prop } from '../types';
|
|
3
3
|
export declare function computeNodeHierarchy(nodes: NodeByID): ComputedHierarchy;
|
|
4
4
|
export declare function computeBehaviorHierarchy(behaviors: BehaviorByID): ComputedHierarchy;
|
|
5
5
|
export declare function addNode(zcomp: ZComponentData, info: NodeDataCombined): void;
|
|
@@ -41,3 +41,4 @@ export interface NodeDataCombined extends EntityDataCombined {
|
|
|
41
41
|
export interface BehaviorDataCombined extends EntityDataCombined {
|
|
42
42
|
data: BehaviorData;
|
|
43
43
|
}
|
|
44
|
+
export declare function getUniqueLabel(zcomp: ZComponentData, label: string): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { generateKeyBetween, generateNKeysBetween } from '
|
|
2
|
-
import { EntityPropOverrideType } from './
|
|
1
|
+
import { generateKeyBetween, generateNKeysBetween } from '../fractionalindexing';
|
|
2
|
+
import { EntityPropOverrideType } from './core';
|
|
3
3
|
// Simple memoizing of computed hierarchy
|
|
4
4
|
const computedHierarchies = new Map();
|
|
5
5
|
const computedBehaviors = new Map();
|
|
@@ -350,6 +350,16 @@ export function deleteEntity(zcomp, id) {
|
|
|
350
350
|
delete zcomp.entityPropOverrides[overrideID];
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
+
if (zcomp.animation) {
|
|
354
|
+
for (const clip of Object.values(zcomp.animation.clips)) {
|
|
355
|
+
if (!clip)
|
|
356
|
+
continue;
|
|
357
|
+
for (const track of Object.values(clip.tracks)) {
|
|
358
|
+
if (track?.entityID === id)
|
|
359
|
+
delete clip.tracks[track.id];
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
353
363
|
}
|
|
354
364
|
export function forEachNodeAncestor(zcomp, id, fn) {
|
|
355
365
|
const node = zcomp.nodes[id];
|
|
@@ -358,3 +368,14 @@ export function forEachNodeAncestor(zcomp, id, fn) {
|
|
|
358
368
|
fn(node.parent.id);
|
|
359
369
|
forEachNodeAncestor(zcomp, node.parent.id, fn);
|
|
360
370
|
}
|
|
371
|
+
export function getUniqueLabel(zcomp, label) {
|
|
372
|
+
const existingLabels = zcomp.entitiesByLabel ?? {};
|
|
373
|
+
for (let i = 1; i < 10000; i++) {
|
|
374
|
+
const testName = i === 1 ? label : `${label} ${i.toString()}`;
|
|
375
|
+
if (!Object.prototype.hasOwnProperty.call(existingLabels, testName)) {
|
|
376
|
+
label = testName;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return label;
|
|
381
|
+
}
|
package/lib/inflate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Track } from './animation/tracks/track';
|
|
2
|
-
import * as Data from './
|
|
2
|
+
import * as Data from './data';
|
|
3
3
|
import { ZComponent } from './zcomponent';
|
|
4
4
|
import { Clip } from './animation/clips/clip';
|
|
5
5
|
import { Animation } from './animation/animation';
|
|
@@ -10,4 +10,5 @@ export declare function createClipFromData(zcomp: ZComponent, anim: Animation, d
|
|
|
10
10
|
export declare function updateClipFromData(zcomp: ZComponent, clip: Clip, data: Data.Clip): void;
|
|
11
11
|
export declare function createLayerClipFromData(zcomp: ZComponent, layer: Layer, data: Data.LayerClip): LayerClip | undefined;
|
|
12
12
|
export declare function createLayerFromData(zcomp: ZComponent, anim: Animation, data: Data.Layer): Layer | undefined;
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function populateAnimationTracksFromData(zcomp: ZComponent, anim: Animation, data: Data.Animation): void;
|
|
14
|
+
export declare function populateAnimationStructureFromData(zcomp: ZComponent, anim: Animation, data: Data.Animation): void;
|
package/lib/inflate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as Data from './
|
|
1
|
+
import * as Data from './data';
|
|
2
2
|
import { PropertyTrack } from './animation/tracks/propertytrack';
|
|
3
3
|
import { Clip } from './animation/clips/clip';
|
|
4
4
|
import { LayerClip } from './animation/layerclip';
|
|
@@ -10,22 +10,20 @@ export function createTrackFromData(zcomp, anim, data) {
|
|
|
10
10
|
const entity = zcomp.entityByID.get(data.entityID);
|
|
11
11
|
if (!entity)
|
|
12
12
|
return;
|
|
13
|
-
const ret = new PropertyTrack(anim, data.entityID, entity, data.property);
|
|
13
|
+
const ret = new PropertyTrack(anim, data.entityID, entity, data.property, data.id);
|
|
14
14
|
ret.setKeyframesById(data.keyframes);
|
|
15
15
|
ret.setWeightsById(data.weight);
|
|
16
16
|
ret.fadeParameters = data.fadeParameters;
|
|
17
17
|
ret.blend = data.blend ?? 'overlay';
|
|
18
|
-
zcomp.animation.trackByID.set(data.id, ret);
|
|
19
18
|
return ret;
|
|
20
19
|
}
|
|
21
20
|
case Data.TrackType.Clip: {
|
|
22
21
|
const clip = zcomp.animation.clipByID.get(data.entityID);
|
|
23
22
|
if (!clip)
|
|
24
23
|
return;
|
|
25
|
-
const ret = new ClipTrack(clip);
|
|
24
|
+
const ret = new ClipTrack(clip, data.id);
|
|
26
25
|
ret.setBlocksById(data.data);
|
|
27
26
|
ret.setWeightsById(data.weight);
|
|
28
|
-
zcomp.animation.trackByID.set(data.id, ret);
|
|
29
27
|
return ret;
|
|
30
28
|
}
|
|
31
29
|
}
|
|
@@ -65,17 +63,9 @@ export function createClipFromData(zcomp, anim, data) {
|
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
const ret = new Clip(anim, length);
|
|
66
|
+
const ret = new Clip(anim, length, data.scriptName, data.id);
|
|
69
67
|
ret.defaultFadeParameters = data.defaultFadeParameters;
|
|
70
|
-
for (const track of Object.values(data.tracks)) {
|
|
71
|
-
if (!track)
|
|
72
|
-
continue;
|
|
73
|
-
const instance = createTrackFromData(zcomp, anim, track);
|
|
74
|
-
if (instance)
|
|
75
|
-
ret.addTrack(instance);
|
|
76
|
-
}
|
|
77
68
|
zcomp.animation.clipByID.set(data.id, ret);
|
|
78
|
-
ret.id = data.id;
|
|
79
69
|
return ret;
|
|
80
70
|
}
|
|
81
71
|
export function updateClipFromData(zcomp, clip, data) {
|
|
@@ -94,19 +84,17 @@ export function createLayerClipFromData(zcomp, layer, data) {
|
|
|
94
84
|
const clip = zcomp.animation.clipByID.get(data.clipId);
|
|
95
85
|
if (!clip)
|
|
96
86
|
return;
|
|
97
|
-
const ret = new LayerClip(layer, clip);
|
|
98
|
-
ret.id = data.id;
|
|
87
|
+
const ret = new LayerClip(layer, clip, data.scriptName, data.id);
|
|
99
88
|
ret.defaultPlaySpeed = data.playbackSpeed ?? 1;
|
|
100
89
|
if (data.reverse)
|
|
101
90
|
ret.defaultPlaySpeed *= -1;
|
|
102
91
|
ret.defaultLoop = data.loop ?? false;
|
|
103
|
-
zcomp.animation.layerClipByID.set(data.id, ret);
|
|
104
92
|
return ret;
|
|
105
93
|
}
|
|
106
94
|
export function createLayerFromData(zcomp, anim, data) {
|
|
107
|
-
const ret = new Layer(anim);
|
|
95
|
+
const ret = new Layer(anim, data.scriptName, data.id);
|
|
108
96
|
ret.active = undefined;
|
|
109
|
-
ret.
|
|
97
|
+
ret.defaultFadeParameters = data.defaultFadeParameters;
|
|
110
98
|
if (data.defaultClip === null)
|
|
111
99
|
ret.active = null;
|
|
112
100
|
for (const layerClip of Object.values(data.clips)) {
|
|
@@ -118,10 +106,24 @@ export function createLayerFromData(zcomp, anim, data) {
|
|
|
118
106
|
if (data.defaultClip === layerClip.id)
|
|
119
107
|
ret.active = instance;
|
|
120
108
|
}
|
|
121
|
-
zcomp.animation.layerByID.set(data.id, ret);
|
|
122
109
|
return ret;
|
|
123
110
|
}
|
|
124
|
-
export function
|
|
111
|
+
export function populateAnimationTracksFromData(zcomp, anim, data) {
|
|
112
|
+
const clips = resolveClipDependencies(data.clips).reverse();
|
|
113
|
+
for (const clipData of Object.values(clips)) {
|
|
114
|
+
const clip = anim.clipByID.get(clipData.id);
|
|
115
|
+
if (!clip)
|
|
116
|
+
continue;
|
|
117
|
+
for (const track of Object.values(clipData.tracks)) {
|
|
118
|
+
if (!track)
|
|
119
|
+
continue;
|
|
120
|
+
const instance = createTrackFromData(zcomp, anim, track);
|
|
121
|
+
if (instance)
|
|
122
|
+
clip.addTrack(instance);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function populateAnimationStructureFromData(zcomp, anim, data) {
|
|
125
127
|
const clips = resolveClipDependencies(data.clips).reverse();
|
|
126
128
|
for (const clip of Object.values(clips)) {
|
|
127
129
|
if (!clip)
|
package/lib/selectors.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { EntityPropOverride, Import, NodeByID, ParsedImport, Props } from './
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { EntityPropOverride, Import, NodeByID, ParsedImport, Props } from './data/core';
|
|
2
|
+
import * as Data from './data';
|
|
3
|
+
import { Layer } from './animation';
|
|
4
4
|
export declare function parseImport(i: Import): ParsedImport;
|
|
5
5
|
export declare function constructImport(from: string, destFile: string, imp: string): string;
|
|
6
|
-
export declare function getScriptName(n: string, requireUniqueIn: {
|
|
6
|
+
export declare function getScriptName(n: string, requireUniqueIn: string[] | {
|
|
7
7
|
[k: string]: any;
|
|
8
8
|
}): string;
|
|
9
9
|
export declare function isValidVariableName(n: string): boolean;
|
|
@@ -23,8 +23,8 @@ export declare const typeDefinitionForComponent: (nodes: NodeByID, props: Props,
|
|
|
23
23
|
[id: string]: {
|
|
24
24
|
[id: string]: boolean;
|
|
25
25
|
};
|
|
26
|
-
} | undefined, url: string) => string;
|
|
26
|
+
} | undefined, url: string, layers: Data.ByID<Data.Layer>) => string;
|
|
27
27
|
export declare function getSafeKeyName(n: string): string;
|
|
28
|
-
export declare function propertyTracksByEntityID(clip: Clip): {
|
|
29
|
-
[id: string]: PropertyTrack[];
|
|
28
|
+
export declare function propertyTracksByEntityID(clip: Data.Clip): {
|
|
29
|
+
[id: string]: Data.PropertyTrack[];
|
|
30
30
|
};
|
package/lib/selectors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EntityPropOverrideType } from './
|
|
1
|
+
import { EntityPropOverrideType } from './data/core';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { outputForType } from './types';
|
|
4
|
-
import
|
|
4
|
+
import * as Data from './data';
|
|
5
5
|
export function parseImport(i) {
|
|
6
6
|
if (typeof i !== 'string')
|
|
7
7
|
return ['', ''];
|
|
@@ -85,6 +85,7 @@ const reservedWords = [
|
|
|
85
85
|
'yield',
|
|
86
86
|
];
|
|
87
87
|
export function getScriptName(n, requireUniqueIn) {
|
|
88
|
+
const existing = new Set(Array.isArray(requireUniqueIn) ? requireUniqueIn : Object.keys(requireUniqueIn));
|
|
88
89
|
if (n === undefined || n.length === 0) {
|
|
89
90
|
n = 'node';
|
|
90
91
|
}
|
|
@@ -100,7 +101,7 @@ export function getScriptName(n, requireUniqueIn) {
|
|
|
100
101
|
}
|
|
101
102
|
let finalname = scriptname;
|
|
102
103
|
let indx = 0;
|
|
103
|
-
while (
|
|
104
|
+
while (existing.has(finalname)) {
|
|
104
105
|
finalname = scriptname + indx;
|
|
105
106
|
indx++;
|
|
106
107
|
}
|
|
@@ -160,7 +161,7 @@ export function summaryForEntityPropOverrideDestination(o) {
|
|
|
160
161
|
}
|
|
161
162
|
return '?';
|
|
162
163
|
}
|
|
163
|
-
export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, url) => {
|
|
164
|
+
export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, url, layers) => {
|
|
164
165
|
const importMapping = new Map();
|
|
165
166
|
let indx = 0;
|
|
166
167
|
let importStrings = [];
|
|
@@ -178,7 +179,7 @@ export const typeDefinitionForComponent = (nodes, props, constructorProps, scrip
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
|
-
return `import { ZComponent, ContextManager, Observable } from "@zcomponent/core";
|
|
182
|
+
return `import { ZComponent, ContextManager, Observable, Animation, Layer, LayerClip } from "@zcomponent/core";
|
|
182
183
|
|
|
183
184
|
${importStrings.join('\n')}
|
|
184
185
|
|
|
@@ -206,12 +207,25 @@ ${Object.entries(scriptNames ?? {}).map(entry => {
|
|
|
206
207
|
}).join("\n")}
|
|
207
208
|
};
|
|
208
209
|
|
|
210
|
+
animation: ${typeForAnimation(layers)}
|
|
211
|
+
|
|
209
212
|
${Object.values(props).map(typeOutputForProp).join('\n\n')}
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
export default Comp;
|
|
213
216
|
`;
|
|
214
217
|
};
|
|
218
|
+
function typeForAnimation(layers) {
|
|
219
|
+
const layersWithScriptNames = Object.values(layers).filter(l => l?.scriptName !== undefined);
|
|
220
|
+
return `Animation & { layers: {
|
|
221
|
+
${Object.values(layersWithScriptNames).map(layer => {
|
|
222
|
+
const clipsWithScriptNames = Object.values(layer.clips).filter(lc => lc?.scriptName !== undefined);
|
|
223
|
+
return `\t\t${layer.scriptName ?? '""'}: Layer & { clips: {
|
|
224
|
+
${Object.values(clipsWithScriptNames).map(lc => `\t\t\t${lc.scriptName ?? '""'}: LayerClip;`).join('\n')}
|
|
225
|
+
}};`;
|
|
226
|
+
}).join('\n')}
|
|
227
|
+
}};`;
|
|
228
|
+
}
|
|
215
229
|
function makeCommentSafe(c) {
|
|
216
230
|
return c.replaceAll('*/', '');
|
|
217
231
|
}
|
|
@@ -265,7 +279,7 @@ export function propertyTracksByEntityID(clip) {
|
|
|
265
279
|
for (const track of Object.values(clip.tracks)) {
|
|
266
280
|
if (!track)
|
|
267
281
|
continue;
|
|
268
|
-
if (track.type !== TrackType.Property)
|
|
282
|
+
if (track.type !== Data.TrackType.Property)
|
|
269
283
|
continue;
|
|
270
284
|
const arr = ret[track.entityID] ?? [];
|
|
271
285
|
arr.push(track);
|
package/lib/types.d.ts
CHANGED
package/lib/types.js
CHANGED
package/lib/validators.d.ts
CHANGED
package/lib/zcomponent.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Animation
|
|
1
|
+
import { Animation } from './animation/index';
|
|
2
2
|
import { Component, ComponentChildren, ConstructorForComponent, ConstructorProps } from './component';
|
|
3
3
|
import { ContextManager, Context } from './context';
|
|
4
4
|
import { Entity } from './entity';
|
|
5
|
-
import { ZComponentData } from './
|
|
5
|
+
import { ZComponentData } from './data/core';
|
|
6
6
|
export interface ZComponentOptions {
|
|
7
7
|
data: ZComponentData;
|
|
8
8
|
importMapping: {
|
|
@@ -43,13 +43,7 @@ export declare class ZComponent<RootType = any> extends Component<RootType> {
|
|
|
43
43
|
private _constructedResolve;
|
|
44
44
|
constructed: Promise<void>;
|
|
45
45
|
isConstructed: boolean;
|
|
46
|
-
|
|
47
|
-
animation: {
|
|
48
|
-
clipByID: Map<string, Clip>;
|
|
49
|
-
layerClipByID: Map<string, LayerClip>;
|
|
50
|
-
layerByID: Map<string, Layer>;
|
|
51
|
-
trackByID: Map<string, Track>;
|
|
52
|
-
};
|
|
46
|
+
animation: Animation;
|
|
53
47
|
private _nodesById;
|
|
54
48
|
private _behaviorsToInitialize;
|
|
55
49
|
private _constructorPropOverridesByEntityID;
|
package/lib/zcomponent.js
CHANGED
|
@@ -7,8 +7,8 @@ import { isDesignTime } from './contexts/environmentcontext';
|
|
|
7
7
|
import { isStarted, started } from './contexts/loadcontext';
|
|
8
8
|
import { TagContext } from './contexts/tagcontext';
|
|
9
9
|
import { computeBehaviorHierarchy, computeNodeHierarchy } from './data';
|
|
10
|
-
import {
|
|
11
|
-
import { EntityPropOverrideType } from './
|
|
10
|
+
import { populateAnimationStructureFromData, populateAnimationTracksFromData, updateClipFromData } from './inflate';
|
|
11
|
+
import { EntityPropOverrideType } from './data/core';
|
|
12
12
|
import { Observable } from './observable';
|
|
13
13
|
import { setCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
14
14
|
export class ZComponentContext extends Context {
|
|
@@ -30,28 +30,24 @@ export class ZComponent extends Component {
|
|
|
30
30
|
this.nodeByLabel = new Map();
|
|
31
31
|
this.constructed = new Promise(resolve => this._constructedResolve = resolve);
|
|
32
32
|
this.isConstructed = false;
|
|
33
|
-
this.
|
|
34
|
-
this.animation = {
|
|
35
|
-
clipByID: new Map(),
|
|
36
|
-
layerClipByID: new Map(),
|
|
37
|
-
layerByID: new Map(),
|
|
38
|
-
trackByID: new Map,
|
|
39
|
-
};
|
|
33
|
+
this.animation = new Animation(false);
|
|
40
34
|
this._nodesById = new Map();
|
|
41
35
|
this._behaviorsToInitialize = [];
|
|
42
36
|
this._constructorPropOverridesByEntityID = new Map();
|
|
43
37
|
this._updateAnimationRegistrations = () => {
|
|
44
|
-
if (this.
|
|
38
|
+
if (this.animation.hasLayers && isStarted(this.contextManager) && !this.disposed)
|
|
45
39
|
this.register(useOnBeforeRender(this.contextManager), this._animationTick);
|
|
46
40
|
else
|
|
47
41
|
this.unregister(useOnBeforeRender(this.contextManager), this._animationTick);
|
|
48
42
|
};
|
|
49
43
|
this._animationTick = () => {
|
|
50
|
-
this.
|
|
44
|
+
this.animation.tick();
|
|
51
45
|
};
|
|
52
46
|
const contextManagerForChildren = contextManager.forkMultiple([ZComponentContext, { zcomponent: this }], [TagContext, {}])[0];
|
|
53
47
|
this.id = this._opts.data.id;
|
|
54
48
|
this._initializeConstructorPropOverrides();
|
|
49
|
+
if (this._opts.data.animation)
|
|
50
|
+
populateAnimationStructureFromData(this, this.animation, this._opts.data.animation);
|
|
55
51
|
const rootConstructor = this._constructorForNode(this._opts.data.root);
|
|
56
52
|
if (rootConstructor) {
|
|
57
53
|
this.constructChildren([
|
|
@@ -62,11 +58,12 @@ export class ZComponent extends Component {
|
|
|
62
58
|
this._initializeComponentProps();
|
|
63
59
|
this._initializeOverrides();
|
|
64
60
|
if (this._opts.data.animation)
|
|
65
|
-
|
|
61
|
+
populateAnimationTracksFromData(this, this.animation, this._opts.data.animation);
|
|
62
|
+
this.animation.initialize();
|
|
66
63
|
this.isConstructed = true;
|
|
67
64
|
this._constructedResolve();
|
|
68
65
|
started(contextManager).then(this._updateAnimationRegistrations);
|
|
69
|
-
this.register(this.
|
|
66
|
+
this.register(this.animation.hasLayers, this._updateAnimationRegistrations, { bindWhenDisabled: true });
|
|
70
67
|
}
|
|
71
68
|
_constructorForNode(nodeId) {
|
|
72
69
|
const node = this._opts.data.nodes[nodeId];
|
|
@@ -243,7 +240,7 @@ export class ZComponent extends Component {
|
|
|
243
240
|
for (const prop of propSet.values()) {
|
|
244
241
|
try {
|
|
245
242
|
this._setEntityProp(entity, prop, this._opts.data.entityProps[entityID]?.[prop]);
|
|
246
|
-
this.
|
|
243
|
+
this.animation.clearCachedDefault(entityID, prop);
|
|
247
244
|
}
|
|
248
245
|
catch (err) {
|
|
249
246
|
console.log('Warning - unable to set prop', entityID, prop);
|
|
@@ -366,7 +363,7 @@ export class ZComponent extends Component {
|
|
|
366
363
|
return this._nodesById.get(id);
|
|
367
364
|
}
|
|
368
365
|
dispose() {
|
|
369
|
-
this.
|
|
366
|
+
this.animation.dispose();
|
|
370
367
|
for (const entity of this.entityByID.values()) {
|
|
371
368
|
if (entity && typeof entity.dispose === 'function') {
|
|
372
369
|
try {
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|