@zcomponent/core 0.0.19 → 0.0.21
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 +46 -0
- package/lib/animation/animation.js +159 -0
- package/lib/animation/animationstate.d.ts +27 -0
- package/lib/animation/animationstate.js +1 -0
- package/lib/animation/bezier.d.ts +9 -0
- package/lib/animation/bezier.js +93 -0
- package/lib/animation/clips/clip.d.ts +30 -0
- package/lib/animation/clips/clip.js +114 -0
- package/lib/animation/index.d.ts +7 -0
- package/lib/animation/index.js +7 -0
- package/lib/animation/interpolate.d.ts +2 -0
- package/lib/animation/interpolate.js +44 -0
- package/lib/animation/layer.d.ts +42 -0
- package/lib/animation/layer.js +211 -0
- package/lib/animation/layerclip.d.ts +46 -0
- package/lib/animation/layerclip.js +168 -0
- package/lib/animation/stream.d.ts +15 -0
- package/lib/animation/stream.js +6 -0
- package/lib/animation/tracks/cliptrack.d.ts +25 -0
- package/lib/animation/tracks/cliptrack.js +68 -0
- package/lib/animation/tracks/propertytrack.d.ts +32 -0
- package/lib/animation/tracks/propertytrack.js +79 -0
- package/lib/animation/tracks/track.d.ts +10 -0
- package/lib/animation/tracks/track.js +30 -0
- package/lib/animation.d.ts +86 -65
- package/lib/animation.js +83 -1
- package/lib/behaviors/PauseLayerClip.d.ts +20 -0
- package/lib/behaviors/PauseLayerClip.js +26 -0
- package/lib/behaviors/PlayLayerClip.d.ts +78 -0
- package/lib/behaviors/PlayLayerClip.js +62 -0
- package/lib/behaviors/SetLayerOff.d.ts +20 -0
- package/lib/behaviors/SetLayerOff.js +26 -0
- package/lib/data.d.ts +3 -2
- package/lib/data.js +8 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/inflate.d.ts +13 -0
- package/lib/inflate.js +185 -0
- package/lib/interfaces.d.ts +1 -0
- package/lib/selectors.d.ts +5 -0
- package/lib/selectors.js +14 -0
- package/lib/types.d.ts +22 -2
- package/lib/types.js +41 -15
- package/lib/zcomponent.d.ts +11 -0
- package/lib/zcomponent.js +35 -0
- package/package.json +2 -1
package/lib/inflate.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import * as Data from './animation';
|
|
2
|
+
import { PropertyTrack } from './animation/tracks/propertytrack';
|
|
3
|
+
import { Clip } from './animation/clips/clip';
|
|
4
|
+
import { LayerClip } from './animation/layerclip';
|
|
5
|
+
import { Layer } from './animation/layer';
|
|
6
|
+
import { ClipTrack } from './animation/tracks/cliptrack';
|
|
7
|
+
export function createTrackFromData(zcomp, anim, data) {
|
|
8
|
+
switch (data.type) {
|
|
9
|
+
case Data.TrackType.Property: {
|
|
10
|
+
const entity = zcomp.entityByID.get(data.entityID);
|
|
11
|
+
if (!entity)
|
|
12
|
+
return;
|
|
13
|
+
const ret = new PropertyTrack(anim, data.entityID, entity, data.property);
|
|
14
|
+
ret.setKeyframesById(data.keyframes);
|
|
15
|
+
ret.setWeightsById(data.weight);
|
|
16
|
+
ret.fadeParameters = data.fadeParameters;
|
|
17
|
+
ret.blend = data.blend ?? 'overlay';
|
|
18
|
+
zcomp.animation.trackByID.set(data.id, ret);
|
|
19
|
+
return ret;
|
|
20
|
+
}
|
|
21
|
+
case Data.TrackType.Clip: {
|
|
22
|
+
const clip = zcomp.animation.clipByID.get(data.entityID);
|
|
23
|
+
if (!clip)
|
|
24
|
+
return;
|
|
25
|
+
const ret = new ClipTrack(clip);
|
|
26
|
+
ret.setBlocksById(data.data);
|
|
27
|
+
ret.setWeightsById(data.weight);
|
|
28
|
+
zcomp.animation.trackByID.set(data.id, ret);
|
|
29
|
+
return ret;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
export function createClipFromData(zcomp, anim, data) {
|
|
35
|
+
let length = data.length;
|
|
36
|
+
if (length === undefined) {
|
|
37
|
+
length = 0;
|
|
38
|
+
for (const track of Object.values(data.tracks)) {
|
|
39
|
+
if (!track)
|
|
40
|
+
continue;
|
|
41
|
+
switch (track.type) {
|
|
42
|
+
case Data.TrackType.Property:
|
|
43
|
+
for (const keyframe of Object.values(track.keyframes)) {
|
|
44
|
+
if (!keyframe)
|
|
45
|
+
continue;
|
|
46
|
+
length = Math.max(length, keyframe.t);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case Data.TrackType.Clip:
|
|
50
|
+
for (const keyframe of Object.values(track.data)) {
|
|
51
|
+
if (!keyframe)
|
|
52
|
+
continue;
|
|
53
|
+
length = Math.max(length, keyframe.t0);
|
|
54
|
+
length = Math.max(length, keyframe.t1);
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case Data.TrackType.Stream:
|
|
58
|
+
for (const keyframe of Object.values(track.data)) {
|
|
59
|
+
if (!keyframe)
|
|
60
|
+
continue;
|
|
61
|
+
length = Math.max(length, keyframe.t0);
|
|
62
|
+
length = Math.max(length, keyframe.t1);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const ret = new Clip(anim, length);
|
|
69
|
+
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
|
+
zcomp.animation.clipByID.set(data.id, ret);
|
|
78
|
+
ret.id = data.id;
|
|
79
|
+
return ret;
|
|
80
|
+
}
|
|
81
|
+
export function updateClipFromData(zcomp, clip, data) {
|
|
82
|
+
clip.defaultFadeParameters = data.defaultFadeParameters;
|
|
83
|
+
clip.length = data.length;
|
|
84
|
+
clip.clearTracks();
|
|
85
|
+
for (const track of Object.values(data.tracks)) {
|
|
86
|
+
if (!track)
|
|
87
|
+
continue;
|
|
88
|
+
const instance = createTrackFromData(zcomp, clip.animation, track);
|
|
89
|
+
if (instance)
|
|
90
|
+
clip.addTrack(instance);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function createLayerClipFromData(zcomp, layer, data) {
|
|
94
|
+
const clip = zcomp.animation.clipByID.get(data.clipId);
|
|
95
|
+
if (!clip)
|
|
96
|
+
return;
|
|
97
|
+
const ret = new LayerClip(layer, clip);
|
|
98
|
+
ret.id = data.id;
|
|
99
|
+
ret.defaultPlaySpeed = data.playbackSpeed ?? 1;
|
|
100
|
+
if (data.reverse)
|
|
101
|
+
ret.defaultPlaySpeed *= -1;
|
|
102
|
+
ret.defaultLoop = data.loop ?? false;
|
|
103
|
+
zcomp.animation.layerClipByID.set(data.id, ret);
|
|
104
|
+
return ret;
|
|
105
|
+
}
|
|
106
|
+
export function createLayerFromData(zcomp, anim, data) {
|
|
107
|
+
const ret = new Layer(anim);
|
|
108
|
+
ret.active = undefined;
|
|
109
|
+
ret.id = data.id;
|
|
110
|
+
if (data.defaultClip === null)
|
|
111
|
+
ret.active = null;
|
|
112
|
+
for (const layerClip of Object.values(data.clips)) {
|
|
113
|
+
if (!layerClip)
|
|
114
|
+
continue;
|
|
115
|
+
const instance = createLayerClipFromData(zcomp, ret, layerClip);
|
|
116
|
+
if (!instance)
|
|
117
|
+
continue;
|
|
118
|
+
if (data.defaultClip === layerClip.id)
|
|
119
|
+
ret.active = instance;
|
|
120
|
+
}
|
|
121
|
+
zcomp.animation.layerByID.set(data.id, ret);
|
|
122
|
+
return ret;
|
|
123
|
+
}
|
|
124
|
+
export function populateAnimationFromData(zcomp, anim, data) {
|
|
125
|
+
const clips = resolveClipDependencies(data.clips).reverse();
|
|
126
|
+
for (const clip of Object.values(clips)) {
|
|
127
|
+
if (!clip)
|
|
128
|
+
continue;
|
|
129
|
+
createClipFromData(zcomp, anim, clip);
|
|
130
|
+
}
|
|
131
|
+
const layers = Object.values(data.layers);
|
|
132
|
+
layers.sort((alayer, blayer) => {
|
|
133
|
+
let a = alayer.order ?? 'A0';
|
|
134
|
+
let b = blayer.order ?? 'A0';
|
|
135
|
+
if (a === b) {
|
|
136
|
+
a = alayer.id;
|
|
137
|
+
b = blayer.id;
|
|
138
|
+
}
|
|
139
|
+
return a < b ? -1 : 1;
|
|
140
|
+
});
|
|
141
|
+
for (const layer of Object.values(layers)) {
|
|
142
|
+
if (!layer)
|
|
143
|
+
continue;
|
|
144
|
+
const instance = createLayerFromData(zcomp, anim, layer);
|
|
145
|
+
if (!instance)
|
|
146
|
+
continue;
|
|
147
|
+
anim.addLayer(instance);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Depth-first topological sort of clips */
|
|
151
|
+
function resolveClipDependencies(clips) {
|
|
152
|
+
const ret = [];
|
|
153
|
+
const nodesWithoutPermanentMark = new Set(Object.values(clips));
|
|
154
|
+
const nodesWithTemporaryMark = new Set();
|
|
155
|
+
function visit(n) {
|
|
156
|
+
if (!nodesWithoutPermanentMark.has(n))
|
|
157
|
+
return true; // n has permanent mark
|
|
158
|
+
if (nodesWithTemporaryMark.has(n))
|
|
159
|
+
return false; // cycle
|
|
160
|
+
nodesWithTemporaryMark.add(n);
|
|
161
|
+
for (const track of Object.values(n.tracks)) {
|
|
162
|
+
if (track?.type !== Data.TrackType.Clip)
|
|
163
|
+
continue;
|
|
164
|
+
const clip = clips[track.entityID];
|
|
165
|
+
if (!clip)
|
|
166
|
+
continue;
|
|
167
|
+
if (!visit(clip))
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
nodesWithTemporaryMark.delete(n);
|
|
171
|
+
nodesWithoutPermanentMark.delete(n);
|
|
172
|
+
ret.splice(0, 0, n);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
let iteration = 100000;
|
|
176
|
+
while (iteration > 0) {
|
|
177
|
+
const nextVal = nodesWithoutPermanentMark.values().next().value;
|
|
178
|
+
if (!nextVal)
|
|
179
|
+
break;
|
|
180
|
+
iteration--;
|
|
181
|
+
if (!visit(nextVal))
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
return ret;
|
|
185
|
+
}
|
package/lib/interfaces.d.ts
CHANGED
package/lib/selectors.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { EntityPropOverride, Import, NodeByID, ParsedImport, Props } from './interfaces';
|
|
2
|
+
import { PropertyTrack } from './animation';
|
|
3
|
+
import { Clip } from './animation';
|
|
2
4
|
export declare function parseImport(i: Import): ParsedImport;
|
|
3
5
|
export declare function constructImport(from: string, destFile: string, imp: string): string;
|
|
4
6
|
export declare function getScriptName(n: string, requireUniqueIn: {
|
|
@@ -23,3 +25,6 @@ export declare const typeDefinitionForComponent: (nodes: NodeByID, props: Props,
|
|
|
23
25
|
};
|
|
24
26
|
} | undefined, url: string) => string;
|
|
25
27
|
export declare function getSafeKeyName(n: string): string;
|
|
28
|
+
export declare function propertyTracksByEntityID(clip: Clip): {
|
|
29
|
+
[id: string]: PropertyTrack[];
|
|
30
|
+
};
|
package/lib/selectors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EntityPropOverrideType } from './interfaces';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { outputForType } from './types';
|
|
4
|
+
import { TrackType } from './animation';
|
|
4
5
|
export function parseImport(i) {
|
|
5
6
|
if (typeof i !== 'string')
|
|
6
7
|
return ['', ''];
|
|
@@ -259,3 +260,16 @@ export function getSafeKeyName(n) {
|
|
|
259
260
|
}
|
|
260
261
|
return scriptname;
|
|
261
262
|
}
|
|
263
|
+
export function propertyTracksByEntityID(clip) {
|
|
264
|
+
const ret = Object.create(null);
|
|
265
|
+
for (const track of Object.values(clip.tracks)) {
|
|
266
|
+
if (!track)
|
|
267
|
+
continue;
|
|
268
|
+
if (track.type !== TrackType.Property)
|
|
269
|
+
continue;
|
|
270
|
+
const arr = ret[track.entityID] ?? [];
|
|
271
|
+
arr.push(track);
|
|
272
|
+
ret[track.entityID] = arr;
|
|
273
|
+
}
|
|
274
|
+
return ret;
|
|
275
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -4,6 +4,20 @@ export interface BaseType {
|
|
|
4
4
|
typeHint?: TypeHint;
|
|
5
5
|
isObservable?: boolean;
|
|
6
6
|
}
|
|
7
|
+
export declare enum TypeName {
|
|
8
|
+
String = "string",
|
|
9
|
+
Number = "number",
|
|
10
|
+
Boolean = "boolean",
|
|
11
|
+
Literal = "literal",
|
|
12
|
+
Array = "array",
|
|
13
|
+
Tuple = "tuple",
|
|
14
|
+
Union = "union",
|
|
15
|
+
Unknown = "unknown",
|
|
16
|
+
Enum = "enum",
|
|
17
|
+
Function = "function",
|
|
18
|
+
Event = "event",
|
|
19
|
+
Entity = "entity"
|
|
20
|
+
}
|
|
7
21
|
export interface StringPrimitiveType extends BaseType {
|
|
8
22
|
name: 'string';
|
|
9
23
|
}
|
|
@@ -50,7 +64,10 @@ export interface FunctionType extends BaseType {
|
|
|
50
64
|
export interface EventType extends BaseType {
|
|
51
65
|
name: 'event';
|
|
52
66
|
}
|
|
53
|
-
export
|
|
67
|
+
export interface EntityType extends BaseType {
|
|
68
|
+
name: 'entity';
|
|
69
|
+
}
|
|
70
|
+
export type Type = StringPrimitiveType | NumberPrimitiveType | BooleanPrimitiveType | ArrayType | TupleType | UnknownType | EnumType | UnionType | LiteralType | FunctionType | EventType | EntityType;
|
|
54
71
|
export declare enum TypeHint {
|
|
55
72
|
'proportion' = "proportion",
|
|
56
73
|
'color-norm-rgb' = "color-norm-rgb",
|
|
@@ -66,7 +83,10 @@ export declare enum ValuesType {
|
|
|
66
83
|
'events' = "events",
|
|
67
84
|
'parentNodes' = "parentNodes",
|
|
68
85
|
'nodelabels' = "nodelabels",
|
|
69
|
-
'nodeids' = "nodeids"
|
|
86
|
+
'nodeids' = "nodeids",
|
|
87
|
+
'layerclipids' = "layerclipids",
|
|
88
|
+
'easings' = "easings",
|
|
89
|
+
'layerids' = "layerids"
|
|
70
90
|
}
|
|
71
91
|
export interface Values {
|
|
72
92
|
type: ValuesType;
|
package/lib/types.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { EntityPropOverrideType } from "./interfaces";
|
|
2
2
|
import { getSafeKeyName } from "./selectors";
|
|
3
|
+
export var TypeName;
|
|
4
|
+
(function (TypeName) {
|
|
5
|
+
TypeName["String"] = "string";
|
|
6
|
+
TypeName["Number"] = "number";
|
|
7
|
+
TypeName["Boolean"] = "boolean";
|
|
8
|
+
TypeName["Literal"] = "literal";
|
|
9
|
+
TypeName["Array"] = "array";
|
|
10
|
+
TypeName["Tuple"] = "tuple";
|
|
11
|
+
TypeName["Union"] = "union";
|
|
12
|
+
TypeName["Unknown"] = "unknown";
|
|
13
|
+
TypeName["Enum"] = "enum";
|
|
14
|
+
TypeName["Function"] = "function";
|
|
15
|
+
TypeName["Event"] = "event";
|
|
16
|
+
TypeName["Entity"] = "entity";
|
|
17
|
+
})(TypeName || (TypeName = {}));
|
|
3
18
|
export var TypeHint;
|
|
4
19
|
(function (TypeHint) {
|
|
5
20
|
TypeHint["proportion"] = "proportion";
|
|
@@ -18,6 +33,9 @@ export var ValuesType;
|
|
|
18
33
|
ValuesType["parentNodes"] = "parentNodes";
|
|
19
34
|
ValuesType["nodelabels"] = "nodelabels";
|
|
20
35
|
ValuesType["nodeids"] = "nodeids";
|
|
36
|
+
ValuesType["layerclipids"] = "layerclipids";
|
|
37
|
+
ValuesType["easings"] = "easings";
|
|
38
|
+
ValuesType["layerids"] = "layerids";
|
|
21
39
|
})(ValuesType || (ValuesType = {}));
|
|
22
40
|
function valuesCompatible(l, r) {
|
|
23
41
|
if (!l && !r)
|
|
@@ -124,7 +142,7 @@ export function mergeProps(a, b) {
|
|
|
124
142
|
default: def,
|
|
125
143
|
group: a.group === b.group ? a.group : undefined,
|
|
126
144
|
groupPriority: Math.max(a.groupPriority ?? 0, b.groupPriority ?? 0),
|
|
127
|
-
values: mergeValues(a.values, b.values)
|
|
145
|
+
values: mergeValues(a.values, b.values),
|
|
128
146
|
};
|
|
129
147
|
}
|
|
130
148
|
function mergeComments(a, b) {
|
|
@@ -225,7 +243,7 @@ export function mergeTypes(a, b) {
|
|
|
225
243
|
name: a.name,
|
|
226
244
|
typeHint,
|
|
227
245
|
children: a.children,
|
|
228
|
-
comments: mergeComments(a.comments ?? [], b.comments ?? [])
|
|
246
|
+
comments: mergeComments(a.comments ?? [], b.comments ?? []),
|
|
229
247
|
};
|
|
230
248
|
case 'function':
|
|
231
249
|
return {
|
|
@@ -233,7 +251,7 @@ export function mergeTypes(a, b) {
|
|
|
233
251
|
typeHint,
|
|
234
252
|
args: a.args,
|
|
235
253
|
ret: a.ret,
|
|
236
|
-
comments: mergeComments(a.comments ?? [], b.comments ?? [])
|
|
254
|
+
comments: mergeComments(a.comments ?? [], b.comments ?? []),
|
|
237
255
|
};
|
|
238
256
|
case 'event':
|
|
239
257
|
return {
|
|
@@ -251,9 +269,12 @@ export function isValidValueForType(def, t, allowUndefined) {
|
|
|
251
269
|
if (allowUndefined && typeof def === 'undefined')
|
|
252
270
|
return true;
|
|
253
271
|
switch (t.name) {
|
|
254
|
-
case 'boolean':
|
|
255
|
-
|
|
256
|
-
case '
|
|
272
|
+
case 'boolean':
|
|
273
|
+
return typeof def === 'boolean';
|
|
274
|
+
case 'number':
|
|
275
|
+
return typeof def === 'number';
|
|
276
|
+
case 'string':
|
|
277
|
+
return typeof def === 'string';
|
|
257
278
|
case 'enum': {
|
|
258
279
|
for (const v of Object.values(t.values)) {
|
|
259
280
|
if (v === def)
|
|
@@ -267,7 +288,7 @@ export function isValidValueForType(def, t, allowUndefined) {
|
|
|
267
288
|
if (!Array.isArray(def))
|
|
268
289
|
return false;
|
|
269
290
|
for (const entry of def) {
|
|
270
|
-
if (!isValidValueForType(entry, t.child))
|
|
291
|
+
if (!isValidValueForType(entry, t.child, allowUndefined))
|
|
271
292
|
return false;
|
|
272
293
|
}
|
|
273
294
|
return true;
|
|
@@ -275,23 +296,25 @@ export function isValidValueForType(def, t, allowUndefined) {
|
|
|
275
296
|
case 'tuple': {
|
|
276
297
|
if (!Array.isArray(def))
|
|
277
298
|
return false;
|
|
278
|
-
if (def.length !== t.children.length)
|
|
299
|
+
if (def.length !== t.children.length && !allowUndefined)
|
|
279
300
|
return false;
|
|
280
301
|
for (let i = 0; i < t.children.length; i++) {
|
|
281
|
-
if (!isValidValueForType(def[i], t.children[i]))
|
|
302
|
+
if (!isValidValueForType(def[i], t.children[i], allowUndefined))
|
|
282
303
|
return false;
|
|
283
304
|
}
|
|
284
305
|
return true;
|
|
285
306
|
}
|
|
286
307
|
case 'union': {
|
|
287
308
|
for (const child of t.children) {
|
|
288
|
-
if (isValidValueForType(def, child))
|
|
309
|
+
if (isValidValueForType(def, child, allowUndefined))
|
|
289
310
|
return true;
|
|
290
311
|
}
|
|
291
312
|
return false;
|
|
292
313
|
}
|
|
293
|
-
case 'literal':
|
|
294
|
-
|
|
314
|
+
case 'literal':
|
|
315
|
+
return def === t.value;
|
|
316
|
+
case 'function':
|
|
317
|
+
return false;
|
|
295
318
|
}
|
|
296
319
|
return false;
|
|
297
320
|
}
|
|
@@ -315,14 +338,17 @@ function getBasicType(t) {
|
|
|
315
338
|
case 'enum':
|
|
316
339
|
case 'string':
|
|
317
340
|
case 'boolean':
|
|
341
|
+
case 'entity':
|
|
318
342
|
return t.name;
|
|
319
343
|
case 'literal': {
|
|
320
344
|
if (t.value === undefined)
|
|
321
|
-
return
|
|
345
|
+
return 'undefined';
|
|
322
346
|
return JSON.stringify(t.value);
|
|
323
347
|
}
|
|
324
|
-
case 'union':
|
|
325
|
-
|
|
348
|
+
case 'union':
|
|
349
|
+
return t.children.map(val => outputForType(val)).join(' | ');
|
|
350
|
+
case 'function':
|
|
351
|
+
return `(${t.args.map(entry => `${entry.name}: ${outputForType(entry.type)}`).join(', ')}) => ${t.ret ? outputForType(t.ret) : 'void'}`;
|
|
326
352
|
case 'event':
|
|
327
353
|
return 'Event';
|
|
328
354
|
}
|
package/lib/zcomponent.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Animation, Clip, LayerClip, Layer, Track } from './animation/index';
|
|
1
2
|
import { Component, ComponentChildren, ConstructorForComponent, ConstructorProps } from './component';
|
|
2
3
|
import { ContextManager, Context } from './context';
|
|
3
4
|
import { Entity } from './entity';
|
|
@@ -42,16 +43,26 @@ export declare class ZComponent<RootType = any> extends Component<RootType> {
|
|
|
42
43
|
private _constructedResolve;
|
|
43
44
|
constructed: Promise<void>;
|
|
44
45
|
isConstructed: boolean;
|
|
46
|
+
animationManager: Animation;
|
|
47
|
+
animation: {
|
|
48
|
+
clipByID: Map<string, Clip>;
|
|
49
|
+
layerClipByID: Map<string, LayerClip>;
|
|
50
|
+
layerByID: Map<string, Layer>;
|
|
51
|
+
trackByID: Map<string, Track>;
|
|
52
|
+
};
|
|
45
53
|
private _nodesById;
|
|
46
54
|
private _behaviorsToInitialize;
|
|
47
55
|
private _constructorPropOverridesByEntityID;
|
|
48
56
|
constructor(contextManager: ContextManager, constructorProps: ConstructorProps, _opts: ZComponentOptions);
|
|
57
|
+
private _updateAnimationRegistrations;
|
|
58
|
+
private _animationTick;
|
|
49
59
|
private _constructorForNode;
|
|
50
60
|
private _constructorForBehavior;
|
|
51
61
|
resolveNodeID<T extends Component = Component>(id: string, type?: ConstructorForComponent<T>): T | undefined;
|
|
52
62
|
private _inflateBehaviors;
|
|
53
63
|
private _wrapBehaviors;
|
|
54
64
|
notifyPropsChanged(entries: Map<string, Set<string>>): void;
|
|
65
|
+
notifyClipsChanged(clips: Set<string>): void;
|
|
55
66
|
private _initializeOverrides;
|
|
56
67
|
private _initializeConstructorPropOverrides;
|
|
57
68
|
private _initializeComponentProps;
|
package/lib/zcomponent.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { Animation } from './animation/index';
|
|
1
2
|
import { shouldBehaviorRunAtDesignTime } from './behavior';
|
|
2
3
|
import { Component } from './component';
|
|
3
4
|
import { Context } from './context';
|
|
5
|
+
import { useOnBeforeRender } from './contexts/canvascontext';
|
|
4
6
|
import { isDesignTime } from './contexts/environmentcontext';
|
|
7
|
+
import { isStarted, started } from './contexts/loadcontext';
|
|
5
8
|
import { TagContext } from './contexts/tagcontext';
|
|
6
9
|
import { computeBehaviorHierarchy, computeNodeHierarchy } from './data';
|
|
10
|
+
import { populateAnimationFromData, updateClipFromData } from './inflate';
|
|
7
11
|
import { EntityPropOverrideType } from './interfaces';
|
|
8
12
|
import { Observable } from './observable';
|
|
9
13
|
import { setCurrentZComponentConstruction } from './zcomponentconstruction';
|
|
@@ -26,9 +30,25 @@ export class ZComponent extends Component {
|
|
|
26
30
|
this.nodeByLabel = new Map();
|
|
27
31
|
this.constructed = new Promise(resolve => this._constructedResolve = resolve);
|
|
28
32
|
this.isConstructed = false;
|
|
33
|
+
this.animationManager = new Animation();
|
|
34
|
+
this.animation = {
|
|
35
|
+
clipByID: new Map(),
|
|
36
|
+
layerClipByID: new Map(),
|
|
37
|
+
layerByID: new Map(),
|
|
38
|
+
trackByID: new Map,
|
|
39
|
+
};
|
|
29
40
|
this._nodesById = new Map();
|
|
30
41
|
this._behaviorsToInitialize = [];
|
|
31
42
|
this._constructorPropOverridesByEntityID = new Map();
|
|
43
|
+
this._updateAnimationRegistrations = () => {
|
|
44
|
+
if (this.animationManager.hasLayers && isStarted(this.contextManager) && !this.disposed)
|
|
45
|
+
this.register(useOnBeforeRender(this.contextManager), this._animationTick);
|
|
46
|
+
else
|
|
47
|
+
this.unregister(useOnBeforeRender(this.contextManager), this._animationTick);
|
|
48
|
+
};
|
|
49
|
+
this._animationTick = () => {
|
|
50
|
+
this.animationManager.tick();
|
|
51
|
+
};
|
|
32
52
|
const contextManagerForChildren = contextManager.forkMultiple([ZComponentContext, { zcomponent: this }], [TagContext, {}])[0];
|
|
33
53
|
this.id = this._opts.data.id;
|
|
34
54
|
this._initializeConstructorPropOverrides();
|
|
@@ -41,8 +61,12 @@ export class ZComponent extends Component {
|
|
|
41
61
|
this._inflateBehaviors();
|
|
42
62
|
this._initializeComponentProps();
|
|
43
63
|
this._initializeOverrides();
|
|
64
|
+
if (this._opts.data.animation)
|
|
65
|
+
populateAnimationFromData(this, this.animationManager, this._opts.data.animation);
|
|
44
66
|
this.isConstructed = true;
|
|
45
67
|
this._constructedResolve();
|
|
68
|
+
started(contextManager).then(this._updateAnimationRegistrations);
|
|
69
|
+
this.register(this.animationManager.hasLayers, this._updateAnimationRegistrations, { bindWhenDisabled: true });
|
|
46
70
|
}
|
|
47
71
|
_constructorForNode(nodeId) {
|
|
48
72
|
const node = this._opts.data.nodes[nodeId];
|
|
@@ -219,6 +243,7 @@ export class ZComponent extends Component {
|
|
|
219
243
|
for (const prop of propSet.values()) {
|
|
220
244
|
try {
|
|
221
245
|
this._setEntityProp(entity, prop, this._opts.data.entityProps[entityID]?.[prop]);
|
|
246
|
+
this.animationManager.clearCachedDefault(entityID, prop);
|
|
222
247
|
}
|
|
223
248
|
catch (err) {
|
|
224
249
|
console.log('Warning - unable to set prop', entityID, prop);
|
|
@@ -226,6 +251,15 @@ export class ZComponent extends Component {
|
|
|
226
251
|
}
|
|
227
252
|
}
|
|
228
253
|
}
|
|
254
|
+
notifyClipsChanged(clips) {
|
|
255
|
+
for (const clipId of clips.values()) {
|
|
256
|
+
const clip = this.animation.clipByID.get(clipId);
|
|
257
|
+
const clipData = this._opts.data.animation?.clips?.[clipId];
|
|
258
|
+
if (!clip || !clipData)
|
|
259
|
+
continue;
|
|
260
|
+
updateClipFromData(this, clip, clipData);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
229
263
|
_initializeOverrides() {
|
|
230
264
|
const overrides = this._opts.data.entityPropOverrides ?? {};
|
|
231
265
|
for (const override of Object.values(overrides)) {
|
|
@@ -332,6 +366,7 @@ export class ZComponent extends Component {
|
|
|
332
366
|
return this._nodesById.get(id);
|
|
333
367
|
}
|
|
334
368
|
dispose() {
|
|
369
|
+
this.animationManager.dispose();
|
|
335
370
|
for (const entity of this.entityByID.values()) {
|
|
336
371
|
if (entity && typeof entity.dispose === 'function') {
|
|
337
372
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zcomponent/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc",
|
|
23
|
+
"build-animation-tests": "tsc -p ./tsconfig.test.animation.json",
|
|
23
24
|
"test": "PW_EXPERIMENTAL_TS_ESM=1 playwright test",
|
|
24
25
|
"tests": "parcel serve tests/index.html -p 8088"
|
|
25
26
|
},
|