@zcomponent/core 0.0.20 → 0.0.22

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 (36) hide show
  1. package/lib/animation/animation.d.ts +16 -2
  2. package/lib/animation/animation.js +42 -13
  3. package/lib/animation/bezier.d.ts +1 -1
  4. package/lib/animation/bezier.js +1 -1
  5. package/lib/animation/clips/clip.d.ts +4 -3
  6. package/lib/animation/clips/clip.js +5 -1
  7. package/lib/animation/layer.d.ts +8 -3
  8. package/lib/animation/layer.js +10 -1
  9. package/lib/animation/layerclip.d.ts +4 -3
  10. package/lib/animation/layerclip.js +5 -1
  11. package/lib/animation/tracks/cliptrack.d.ts +2 -2
  12. package/lib/animation/tracks/cliptrack.js +2 -2
  13. package/lib/animation/tracks/propertytrack.d.ts +2 -2
  14. package/lib/animation/tracks/propertytrack.js +2 -2
  15. package/lib/animation/tracks/track.d.ts +4 -2
  16. package/lib/animation/tracks/track.js +4 -1
  17. package/lib/behaviors/ToggleLayerClips.d.ts +100 -0
  18. package/lib/behaviors/ToggleLayerClips.js +76 -0
  19. package/lib/{animation.d.ts → data/animation.d.ts} +3 -0
  20. package/lib/{data.d.ts → data/change.d.ts} +2 -2
  21. package/lib/{data.js → data/change.js} +2 -2
  22. package/lib/{interfaces.d.ts → data/core.d.ts} +1 -1
  23. package/lib/data/index.d.ts +3 -0
  24. package/lib/data/index.js +3 -0
  25. package/lib/inflate.d.ts +3 -2
  26. package/lib/inflate.js +24 -21
  27. package/lib/selectors.d.ts +7 -7
  28. package/lib/selectors.js +20 -6
  29. package/lib/types.d.ts +1 -1
  30. package/lib/types.js +1 -1
  31. package/lib/validators.d.ts +1 -1
  32. package/lib/zcomponent.d.ts +3 -9
  33. package/lib/zcomponent.js +12 -15
  34. package/package.json +1 -1
  35. /package/lib/{animation.js → data/animation.js} +0 -0
  36. /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
- layers: Layer[];
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.layers = [];
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.layers) {
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.layers) {
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.layers.push(l);
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.layers.splice(indx, 0, l);
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.layers.indexOf(l);
70
+ const indx = this._layers.indexOf(l);
56
71
  if (indx >= 0)
57
- this.layers.splice(indx, 1);
58
- const hasLayers = this.layers.length > 0 || this._spotlightLayer !== undefined;
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.layers) {
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.layers) {
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.layers.length > 0 || this._spotlightLayer !== undefined;
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.layers) {
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);
@@ -1,4 +1,4 @@
1
- import { Bezier as BezierData, predefinedCurve } from "../animation";
1
+ import { Bezier as BezierData, predefinedCurve } from "../data";
2
2
  export type Easing = keyof typeof predefinedCurve | null | Bezier;
3
3
  export declare class Bezier {
4
4
  private _curves;
@@ -1,4 +1,4 @@
1
- import { predefinedCurve } from "../animation";
1
+ import { predefinedCurve } from "../data";
2
2
  function BezierFactory(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y) {
3
3
  function sampleCurveX(t) {
4
4
  return (Math.pow(1 - t, 3) * p0x +
@@ -1,18 +1,19 @@
1
- import * as Data from '../../animation';
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
- id?: string;
8
+ readonly scriptName?: string | undefined;
9
+ readonly id?: string | undefined;
9
10
  influencedPathsDirty: Observable<boolean, never>;
10
11
  defaultFadeParameters?: 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;
@@ -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);
@@ -1,17 +1,21 @@
1
- import * as Data from '../animation';
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
- id?: string;
8
+ readonly scriptName?: string | undefined;
9
+ readonly id?: string | undefined;
10
+ clips: {
11
+ [id: string]: LayerClip;
12
+ };
9
13
  influencedPathsDirty: Observable<boolean, never>;
10
14
  private _influencedPaths;
11
15
  private _active;
12
16
  private _queue;
13
17
  private _layerClips;
14
- constructor(animation: Animation);
18
+ constructor(animation: Animation, scriptName?: string | undefined, id?: string | undefined);
15
19
  computePathProperty(t: number, p: string, valueBefore: any): any;
16
20
  tick(t: number, touchedPaths: string[]): void;
17
21
  pause(): void;
@@ -20,6 +24,7 @@ export declare class Layer {
20
24
  queue(layerClip: LayerClip | null, playOptions?: LayerClipPlayOptions): QueueEntry;
21
25
  get active(): LayerClip | null | undefined;
22
26
  set active(layerClip: LayerClip | null | undefined);
27
+ setActive(layerClip: LayerClip | null, playOptions?: LayerClipPlayOptions): void;
23
28
  /** @internal */
24
29
  _activateLayerClip(layerClip: LayerClip | null | undefined, playOptions?: LayerClipPlayOptions): void;
25
30
  /** @internal */
@@ -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;
@@ -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;
@@ -96,6 +101,10 @@ export class Layer {
96
101
  this._activateLayerClip(layerClip);
97
102
  this._evaulate();
98
103
  }
104
+ setActive(layerClip, playOptions) {
105
+ this._activateLayerClip(layerClip, playOptions);
106
+ this._evaulate();
107
+ }
99
108
  /** @internal */
100
109
  _activateLayerClip(layerClip, playOptions) {
101
110
  if (layerClip === undefined) {
@@ -1,4 +1,4 @@
1
- import { FadeParameters } from '../animation';
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
- id?: string;
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 '../../animation';
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 '../../animation';
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 '../../animation';
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 {
@@ -51,6 +53,7 @@ export interface Clip {
51
53
  lengthType: ClipLengthType;
52
54
  defaultFadeParameters?: FadeParameters;
53
55
  timeSourceTrack?: string;
56
+ scriptName?: string;
54
57
  }
55
58
  export interface Keyframe {
56
59
  id: string;
@@ -1,5 +1,5 @@
1
- import { BehaviorByID, BehaviorData, ComputedHierarchy, EntityPropOverride, NodeByID, NodeData, ZComponentData } from './interfaces';
2
- import { Prop } from './types';
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;
@@ -1,5 +1,5 @@
1
- import { generateKeyBetween, generateNKeysBetween } from './fractionalindexing';
2
- import { EntityPropOverrideType } from './interfaces';
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();
@@ -1,4 +1,4 @@
1
- import { Prop } from './types';
1
+ import { Prop } from '../types';
2
2
  import { Animation } from './animation';
3
3
  export interface ID {
4
4
  id: string;
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export * from './animation';
3
+ export * from './change';
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export * from './animation';
3
+ export * from './change';
package/lib/inflate.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Track } from './animation/tracks/track';
2
- import * as Data from './animation';
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 populateAnimationFromData(zcomp: ZComponent, anim: Animation, data: Data.Animation): void;
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 './animation';
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,18 @@ 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.id = data.id;
97
+ if (data.defaultClip === null)
98
+ ret.active = null;
110
99
  for (const layerClip of Object.values(data.clips)) {
111
100
  if (!layerClip)
112
101
  continue;
@@ -116,10 +105,24 @@ export function createLayerFromData(zcomp, anim, data) {
116
105
  if (data.defaultClip === layerClip.id)
117
106
  ret.active = instance;
118
107
  }
119
- zcomp.animation.layerByID.set(data.id, ret);
120
108
  return ret;
121
109
  }
122
- export function populateAnimationFromData(zcomp, anim, data) {
110
+ export function populateAnimationTracksFromData(zcomp, anim, data) {
111
+ const clips = resolveClipDependencies(data.clips).reverse();
112
+ for (const clipData of Object.values(clips)) {
113
+ const clip = anim.clipByID.get(clipData.id);
114
+ if (!clip)
115
+ continue;
116
+ for (const track of Object.values(clipData.tracks)) {
117
+ if (!track)
118
+ continue;
119
+ const instance = createTrackFromData(zcomp, anim, track);
120
+ if (instance)
121
+ clip.addTrack(instance);
122
+ }
123
+ }
124
+ }
125
+ export function populateAnimationStructureFromData(zcomp, anim, data) {
123
126
  const clips = resolveClipDependencies(data.clips).reverse();
124
127
  for (const clip of Object.values(clips)) {
125
128
  if (!clip)
@@ -1,9 +1,9 @@
1
- import { EntityPropOverride, Import, NodeByID, ParsedImport, Props } from './interfaces';
2
- import { PropertyTrack } from './animation';
3
- import { Clip } from './animation';
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 './interfaces';
1
+ import { EntityPropOverrideType } from './data/core';
2
2
  import * as path from 'path';
3
3
  import { outputForType } from './types';
4
- import { TrackType } from './animation';
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 (requireUniqueIn[finalname]) {
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
@@ -1,4 +1,4 @@
1
- import { EntityPropOverride } from "./interfaces";
1
+ import { EntityPropOverride } from "./data/core";
2
2
  export interface BaseType {
3
3
  comments?: string[];
4
4
  typeHint?: TypeHint;
package/lib/types.js CHANGED
@@ -1,4 +1,4 @@
1
- import { EntityPropOverrideType } from "./interfaces";
1
+ import { EntityPropOverrideType } from "./data/core";
2
2
  import { getSafeKeyName } from "./selectors";
3
3
  export var TypeName;
4
4
  (function (TypeName) {
@@ -1,4 +1,4 @@
1
- import { Import, NodeData, ZComponentData } from './interfaces';
1
+ import { Import, NodeData, ZComponentData } from './data/core';
2
2
  interface Issue {
3
3
  text: string;
4
4
  }
@@ -1,8 +1,8 @@
1
- import { Animation, Clip, LayerClip, Layer, Track } from './animation/index';
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 './interfaces';
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
- 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
- };
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 { populateAnimationFromData, updateClipFromData } from './inflate';
11
- import { EntityPropOverrideType } from './interfaces';
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.animationManager = new Animation();
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.animationManager.hasLayers && isStarted(this.contextManager) && !this.disposed)
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.animationManager.tick();
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
- populateAnimationFromData(this, this.animationManager, this._opts.data.animation);
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.animationManager.hasLayers, this._updateAnimationRegistrations, { bindWhenDisabled: true });
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.animationManager.clearCachedDefault(entityID, prop);
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.animationManager.dispose();
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
File without changes
File without changes