@zcomponent/core 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/lib/animation/animation.d.ts +46 -0
  2. package/lib/animation/animation.js +159 -0
  3. package/lib/animation/animationstate.d.ts +27 -0
  4. package/lib/animation/animationstate.js +1 -0
  5. package/lib/animation/bezier.d.ts +9 -0
  6. package/lib/animation/bezier.js +93 -0
  7. package/lib/animation/clips/clip.d.ts +30 -0
  8. package/lib/animation/clips/clip.js +114 -0
  9. package/lib/animation/index.d.ts +7 -0
  10. package/lib/animation/index.js +7 -0
  11. package/lib/animation/interpolate.d.ts +2 -0
  12. package/lib/animation/interpolate.js +44 -0
  13. package/lib/animation/layer.d.ts +42 -0
  14. package/lib/animation/layer.js +211 -0
  15. package/lib/animation/layerclip.d.ts +46 -0
  16. package/lib/animation/layerclip.js +168 -0
  17. package/lib/animation/stream.d.ts +15 -0
  18. package/lib/animation/stream.js +6 -0
  19. package/lib/animation/tracks/cliptrack.d.ts +25 -0
  20. package/lib/animation/tracks/cliptrack.js +68 -0
  21. package/lib/animation/tracks/propertytrack.d.ts +32 -0
  22. package/lib/animation/tracks/propertytrack.js +79 -0
  23. package/lib/animation/tracks/track.d.ts +10 -0
  24. package/lib/animation/tracks/track.js +30 -0
  25. package/lib/animation.d.ts +86 -65
  26. package/lib/animation.js +83 -1
  27. package/lib/behaviors/PauseLayerClip.d.ts +20 -0
  28. package/lib/behaviors/PauseLayerClip.js +26 -0
  29. package/lib/behaviors/PlayLayerClip.d.ts +78 -0
  30. package/lib/behaviors/PlayLayerClip.js +62 -0
  31. package/lib/behaviors/SetLayerOff.d.ts +20 -0
  32. package/lib/behaviors/SetLayerOff.js +26 -0
  33. package/lib/data.d.ts +3 -2
  34. package/lib/data.js +8 -5
  35. package/lib/index.d.ts +1 -0
  36. package/lib/index.js +1 -0
  37. package/lib/inflate.d.ts +13 -0
  38. package/lib/inflate.js +183 -0
  39. package/lib/interfaces.d.ts +1 -0
  40. package/lib/selectors.d.ts +5 -0
  41. package/lib/selectors.js +14 -0
  42. package/lib/types.d.ts +25 -4
  43. package/lib/types.js +42 -15
  44. package/lib/zcomponent.d.ts +11 -0
  45. package/lib/zcomponent.js +35 -0
  46. package/package.json +2 -1
package/lib/inflate.js ADDED
@@ -0,0 +1,183 @@
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
+ for (const layerClip of Object.values(data.clips)) {
111
+ if (!layerClip)
112
+ continue;
113
+ const instance = createLayerClipFromData(zcomp, ret, layerClip);
114
+ if (!instance)
115
+ continue;
116
+ if (data.defaultClip === layerClip.id)
117
+ ret.active = instance;
118
+ }
119
+ zcomp.animation.layerByID.set(data.id, ret);
120
+ return ret;
121
+ }
122
+ export function populateAnimationFromData(zcomp, anim, data) {
123
+ const clips = resolveClipDependencies(data.clips).reverse();
124
+ for (const clip of Object.values(clips)) {
125
+ if (!clip)
126
+ continue;
127
+ createClipFromData(zcomp, anim, clip);
128
+ }
129
+ const layers = Object.values(data.layers);
130
+ layers.sort((alayer, blayer) => {
131
+ let a = alayer.order ?? 'A0';
132
+ let b = blayer.order ?? 'A0';
133
+ if (a === b) {
134
+ a = alayer.id;
135
+ b = blayer.id;
136
+ }
137
+ return a < b ? -1 : 1;
138
+ });
139
+ for (const layer of Object.values(layers)) {
140
+ if (!layer)
141
+ continue;
142
+ const instance = createLayerFromData(zcomp, anim, layer);
143
+ if (!instance)
144
+ continue;
145
+ anim.addLayer(instance);
146
+ }
147
+ }
148
+ /** Depth-first topological sort of clips */
149
+ function resolveClipDependencies(clips) {
150
+ const ret = [];
151
+ const nodesWithoutPermanentMark = new Set(Object.values(clips));
152
+ const nodesWithTemporaryMark = new Set();
153
+ function visit(n) {
154
+ if (!nodesWithoutPermanentMark.has(n))
155
+ return true; // n has permanent mark
156
+ if (nodesWithTemporaryMark.has(n))
157
+ return false; // cycle
158
+ nodesWithTemporaryMark.add(n);
159
+ for (const track of Object.values(n.tracks)) {
160
+ if (track?.type !== Data.TrackType.Clip)
161
+ continue;
162
+ const clip = clips[track.entityID];
163
+ if (!clip)
164
+ continue;
165
+ if (!visit(clip))
166
+ return false;
167
+ }
168
+ nodesWithTemporaryMark.delete(n);
169
+ nodesWithoutPermanentMark.delete(n);
170
+ ret.splice(0, 0, n);
171
+ return true;
172
+ }
173
+ let iteration = 100000;
174
+ while (iteration > 0) {
175
+ const nextVal = nodesWithoutPermanentMark.values().next().value;
176
+ if (!nextVal)
177
+ break;
178
+ iteration--;
179
+ if (!visit(nextVal))
180
+ break;
181
+ }
182
+ return ret;
183
+ }
@@ -1,4 +1,5 @@
1
1
  import { Prop } from './types';
2
+ import { Animation } from './animation';
2
3
  export interface ID {
3
4
  id: string;
4
5
  }
@@ -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,13 +64,17 @@ export interface FunctionType extends BaseType {
50
64
  export interface EventType extends BaseType {
51
65
  name: 'event';
52
66
  }
53
- export type Type = StringPrimitiveType | NumberPrimitiveType | BooleanPrimitiveType | ArrayType | TupleType | UnknownType | EnumType | UnionType | LiteralType | FunctionType | EventType;
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
- "proportion" = "proportion",
72
+ 'proportion' = "proportion",
56
73
  'color-norm-rgb' = "color-norm-rgb",
57
74
  'color-unnorm-rgb' = "color-unnorm-rgb",
58
75
  'color-hex' = "color-hex",
59
- 'color-css' = "color-css"
76
+ 'color-css' = "color-css",
77
+ 'text-multiline' = "text-multiline"
60
78
  }
61
79
  export declare enum ValuesType {
62
80
  'files' = "files",
@@ -65,7 +83,10 @@ export declare enum ValuesType {
65
83
  'events' = "events",
66
84
  'parentNodes' = "parentNodes",
67
85
  'nodelabels' = "nodelabels",
68
- 'nodeids' = "nodeids"
86
+ 'nodeids' = "nodeids",
87
+ 'layerclipids' = "layerclipids",
88
+ 'easings' = "easings",
89
+ 'layerids' = "layerids"
69
90
  }
70
91
  export interface Values {
71
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";
@@ -7,6 +22,7 @@ export var TypeHint;
7
22
  TypeHint["color-unnorm-rgb"] = "color-unnorm-rgb";
8
23
  TypeHint["color-hex"] = "color-hex";
9
24
  TypeHint["color-css"] = "color-css";
25
+ TypeHint["text-multiline"] = "text-multiline";
10
26
  })(TypeHint || (TypeHint = {}));
11
27
  export var ValuesType;
12
28
  (function (ValuesType) {
@@ -17,6 +33,9 @@ export var ValuesType;
17
33
  ValuesType["parentNodes"] = "parentNodes";
18
34
  ValuesType["nodelabels"] = "nodelabels";
19
35
  ValuesType["nodeids"] = "nodeids";
36
+ ValuesType["layerclipids"] = "layerclipids";
37
+ ValuesType["easings"] = "easings";
38
+ ValuesType["layerids"] = "layerids";
20
39
  })(ValuesType || (ValuesType = {}));
21
40
  function valuesCompatible(l, r) {
22
41
  if (!l && !r)
@@ -123,7 +142,7 @@ export function mergeProps(a, b) {
123
142
  default: def,
124
143
  group: a.group === b.group ? a.group : undefined,
125
144
  groupPriority: Math.max(a.groupPriority ?? 0, b.groupPriority ?? 0),
126
- values: mergeValues(a.values, b.values)
145
+ values: mergeValues(a.values, b.values),
127
146
  };
128
147
  }
129
148
  function mergeComments(a, b) {
@@ -224,7 +243,7 @@ export function mergeTypes(a, b) {
224
243
  name: a.name,
225
244
  typeHint,
226
245
  children: a.children,
227
- comments: mergeComments(a.comments ?? [], b.comments ?? [])
246
+ comments: mergeComments(a.comments ?? [], b.comments ?? []),
228
247
  };
229
248
  case 'function':
230
249
  return {
@@ -232,7 +251,7 @@ export function mergeTypes(a, b) {
232
251
  typeHint,
233
252
  args: a.args,
234
253
  ret: a.ret,
235
- comments: mergeComments(a.comments ?? [], b.comments ?? [])
254
+ comments: mergeComments(a.comments ?? [], b.comments ?? []),
236
255
  };
237
256
  case 'event':
238
257
  return {
@@ -250,9 +269,12 @@ export function isValidValueForType(def, t, allowUndefined) {
250
269
  if (allowUndefined && typeof def === 'undefined')
251
270
  return true;
252
271
  switch (t.name) {
253
- case 'boolean': return typeof def === 'boolean';
254
- case 'number': return typeof def === 'number';
255
- case 'string': return typeof def === 'string';
272
+ case 'boolean':
273
+ return typeof def === 'boolean';
274
+ case 'number':
275
+ return typeof def === 'number';
276
+ case 'string':
277
+ return typeof def === 'string';
256
278
  case 'enum': {
257
279
  for (const v of Object.values(t.values)) {
258
280
  if (v === def)
@@ -266,7 +288,7 @@ export function isValidValueForType(def, t, allowUndefined) {
266
288
  if (!Array.isArray(def))
267
289
  return false;
268
290
  for (const entry of def) {
269
- if (!isValidValueForType(entry, t.child))
291
+ if (!isValidValueForType(entry, t.child, allowUndefined))
270
292
  return false;
271
293
  }
272
294
  return true;
@@ -274,23 +296,25 @@ export function isValidValueForType(def, t, allowUndefined) {
274
296
  case 'tuple': {
275
297
  if (!Array.isArray(def))
276
298
  return false;
277
- if (def.length !== t.children.length)
299
+ if (def.length !== t.children.length && !allowUndefined)
278
300
  return false;
279
301
  for (let i = 0; i < t.children.length; i++) {
280
- if (!isValidValueForType(def[i], t.children[i]))
302
+ if (!isValidValueForType(def[i], t.children[i], allowUndefined))
281
303
  return false;
282
304
  }
283
305
  return true;
284
306
  }
285
307
  case 'union': {
286
308
  for (const child of t.children) {
287
- if (isValidValueForType(def, child))
309
+ if (isValidValueForType(def, child, allowUndefined))
288
310
  return true;
289
311
  }
290
312
  return false;
291
313
  }
292
- case 'literal': return def === t.value;
293
- case 'function': return false;
314
+ case 'literal':
315
+ return def === t.value;
316
+ case 'function':
317
+ return false;
294
318
  }
295
319
  return false;
296
320
  }
@@ -314,14 +338,17 @@ function getBasicType(t) {
314
338
  case 'enum':
315
339
  case 'string':
316
340
  case 'boolean':
341
+ case 'entity':
317
342
  return t.name;
318
343
  case 'literal': {
319
344
  if (t.value === undefined)
320
- return "undefined";
345
+ return 'undefined';
321
346
  return JSON.stringify(t.value);
322
347
  }
323
- case 'union': return t.children.map(val => outputForType(val)).join(' | ');
324
- case 'function': return `(${t.args.map(entry => `${entry.name}: ${outputForType(entry.type)}`).join(', ')}) => ${t.ret ? outputForType(t.ret) : 'void'}`;
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'}`;
325
352
  case 'event':
326
353
  return 'Event';
327
354
  }
@@ -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.18",
3
+ "version": "0.0.20",
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
  },