@zcomponent/core 0.0.27 → 0.0.29

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.
@@ -5,6 +5,7 @@ import { LayerClip } from './layerclip';
5
5
  import { Clip } from './clips/clip';
6
6
  import { AnimationState } from './animationstate';
7
7
  import { Track } from './tracks/track';
8
+ import { Bezier } from './bezier';
8
9
  /** @internal */
9
10
  export declare enum AnimationEvents {
10
11
  onLayerClipActive = "onLayerClipActive",
@@ -18,6 +19,9 @@ export declare class Animation {
18
19
  clips: {
19
20
  [id: string]: Clip;
20
21
  };
22
+ curves: {
23
+ [id: string]: Bezier;
24
+ };
21
25
  onTick: Event<[]>;
22
26
  onLayerClipActive: Event<[layerClip: LayerClip]>;
23
27
  onLayerClipState: Event<[layerClip: LayerClip]>;
@@ -12,6 +12,7 @@ export class Animation {
12
12
  this._initialize = _initialize;
13
13
  this.layers = Object.create(null);
14
14
  this.clips = Object.create(null);
15
+ this.curves = Object.create(null);
15
16
  this.onTick = new Event();
16
17
  this.onLayerClipActive = new Event();
17
18
  this.onLayerClipState = new Event();
@@ -0,0 +1,8 @@
1
+ import { Easing } from "./bezier";
2
+ export interface Keyframe {
3
+ id: string;
4
+ v: any;
5
+ t: number;
6
+ label?: string;
7
+ easing?: Easing;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,14 @@
1
- import * as Data from '../data';
2
1
  import { Observable } from '../observable';
3
2
  import { Animation } from './animation';
4
3
  import { AnimationState } from './animationstate';
4
+ import { Easing } from './bezier';
5
5
  import { LayerClip, LayerClipPlayOptions } from './layerclip';
6
+ export interface FadeParameters {
7
+ time: number;
8
+ pin?: number;
9
+ easing?: Easing;
10
+ reverse?: boolean;
11
+ }
6
12
  export declare class Layer {
7
13
  readonly animation: Animation;
8
14
  readonly scriptName?: string | undefined;
@@ -10,7 +16,7 @@ export declare class Layer {
10
16
  clips: {
11
17
  [id: string]: LayerClip;
12
18
  };
13
- defaultFadeParameters?: Data.FadeParameters;
19
+ defaultFadeParameters?: FadeParameters;
14
20
  influencedPathsDirty: Observable<boolean, never>;
15
21
  private _influencedPaths;
16
22
  private _active;
@@ -41,7 +47,7 @@ export interface QueueEntry {
41
47
  layerClip: LayerClip | null;
42
48
  playOptions?: LayerClipPlayOptions;
43
49
  fadeByPath: {
44
- [id: string]: Partial<Data.FadeParameters>;
50
+ [id: string]: Partial<FadeParameters>;
45
51
  };
46
52
  fadeTime: number;
47
53
  startTime?: number;
@@ -1,5 +1,6 @@
1
- import { Keyframe, ClipTrackEntity } from '../../data';
1
+ import { ClipTrackEntity } from '../../data';
2
2
  import { Clip } from '../clips/clip';
3
+ import { Keyframe } from '../keyframe';
3
4
  import { Track } from './track';
4
5
  export declare class ClipTrack extends Track {
5
6
  readonly clip: Clip;
@@ -1,5 +1,6 @@
1
- import { FadeParameters, Keyframe, BlendType } from '../../data';
1
+ import { FadeParameters, BlendType } from '../../data';
2
2
  import { Animation } from '../animation';
3
+ import { Keyframe } from '../keyframe';
3
4
  import { Track } from './track';
4
5
  export declare class PropertyTrack extends Track {
5
6
  private _entityID;
@@ -1,6 +1,6 @@
1
- import { Keyframe } from '../../data';
2
1
  import { Observable } from '../../observable';
3
2
  import { Animation } from '../animation';
3
+ import { Keyframe } from '../keyframe';
4
4
  export declare abstract class Track {
5
5
  readonly id?: string | undefined;
6
6
  influencedPathsDirty: Observable<boolean, never>;
@@ -3,9 +3,7 @@ export interface DefaultLoaderConstructorProps {
3
3
  /** @zprop
4
4
  * @zgroup Appearance
5
5
  * @zgrouppriority 10
6
- * @zvalues files *.jpeg
7
- * @zvalues files *.png
8
- * @zvalues files *.jpg
6
+ * @zvalues files *.+(jpg|jpeg|png)
9
7
  */
10
8
  backgroundImage: string;
11
9
  }
package/lib/inflate.d.ts CHANGED
@@ -5,7 +5,13 @@ import { Clip } from './animation/clips/clip';
5
5
  import { Animation } from './animation/animation';
6
6
  import { LayerClip } from './animation/layerclip';
7
7
  import { Layer } from './animation/layer';
8
+ import { ByID } from './data';
9
+ import { Bezier } from './animation/bezier';
10
+ import { Keyframe } from './animation/keyframe';
8
11
  export declare function createTrackFromData(zcomp: ZComponent, anim: Animation, data: Data.Track): Track | undefined;
12
+ export declare function processKeyframes(keyframes: ByID<Data.Keyframe>, beziers: ByID<Bezier>): {
13
+ [id: string]: Keyframe;
14
+ };
9
15
  export declare function createClipFromData(zcomp: ZComponent, anim: Animation, data: Data.Clip): Clip;
10
16
  export declare function updateClipFromData(zcomp: ZComponent, clip: Clip, data: Data.Clip): void;
11
17
  export declare function createLayerClipFromData(zcomp: ZComponent, layer: Layer, data: Data.LayerClip): LayerClip | undefined;
package/lib/inflate.js CHANGED
@@ -4,6 +4,7 @@ import { Clip } from './animation/clips/clip';
4
4
  import { LayerClip } from './animation/layerclip';
5
5
  import { Layer } from './animation/layer';
6
6
  import { ClipTrack } from './animation/tracks/cliptrack';
7
+ import { Bezier } from './animation/bezier';
7
8
  export function createTrackFromData(zcomp, anim, data) {
8
9
  switch (data.type) {
9
10
  case Data.TrackType.Property: {
@@ -11,9 +12,9 @@ export function createTrackFromData(zcomp, anim, data) {
11
12
  if (!entity)
12
13
  return;
13
14
  const ret = new PropertyTrack(anim, data.entityID, entity, data.property, data.id);
14
- ret.setKeyframesById(data.keyframes);
15
- ret.setWeightsById(data.weight);
16
- ret.fadeParameters = data.fadeParameters;
15
+ ret.setKeyframesById(processKeyframes(data.keyframes, anim.curves));
16
+ ret.setWeightsById(processKeyframes(data.weight, anim.curves));
17
+ ret.fadeParameters = resolvedFadeParameters(data.fadeParameters, anim.curves);
17
18
  ret.blend = data.blend ?? 'overlay';
18
19
  return ret;
19
20
  }
@@ -23,12 +24,46 @@ export function createTrackFromData(zcomp, anim, data) {
23
24
  return;
24
25
  const ret = new ClipTrack(clip, data.id);
25
26
  ret.setBlocksById(data.data);
26
- ret.setWeightsById(data.weight);
27
+ ret.setWeightsById(processKeyframes(data.weight, anim.curves));
27
28
  return ret;
28
29
  }
29
30
  }
30
31
  return undefined;
31
32
  }
33
+ export function processKeyframes(keyframes, beziers) {
34
+ let needsNew = false;
35
+ const keyframeArray = Object.values(keyframes);
36
+ for (const keyframe of keyframeArray) {
37
+ if (keyframe?.easing) {
38
+ const bezier = beziers[keyframe.easing];
39
+ if (bezier) {
40
+ needsNew = true;
41
+ break;
42
+ }
43
+ }
44
+ }
45
+ if (!needsNew)
46
+ return keyframes;
47
+ const ret = Object.create(null);
48
+ for (const keyframe of keyframeArray) {
49
+ if (!keyframe)
50
+ continue;
51
+ if (!keyframe.easing) {
52
+ ret[keyframe.id] = keyframe;
53
+ continue;
54
+ }
55
+ const bezier = beziers[keyframe.easing];
56
+ if (!bezier) {
57
+ ret[keyframe.id] = keyframe;
58
+ continue;
59
+ }
60
+ ret[keyframe.id] = {
61
+ ...keyframe,
62
+ easing: bezier,
63
+ };
64
+ }
65
+ return ret;
66
+ }
32
67
  export function createClipFromData(zcomp, anim, data) {
33
68
  let length = data.length;
34
69
  if (length === undefined) {
@@ -64,12 +99,23 @@ export function createClipFromData(zcomp, anim, data) {
64
99
  }
65
100
  }
66
101
  const ret = new Clip(anim, length, data.scriptName, data.id);
67
- ret.defaultFadeParameters = data.defaultFadeParameters;
102
+ ret.defaultFadeParameters = resolvedFadeParameters(data.defaultFadeParameters, anim.curves);
68
103
  zcomp.animation.clipByID.set(data.id, ret);
69
104
  return ret;
70
105
  }
106
+ function resolvedFadeParameters(fade, beziers) {
107
+ if (!fade?.easing)
108
+ return fade;
109
+ const bezier = beziers[fade?.easing];
110
+ if (!bezier)
111
+ return fade;
112
+ return {
113
+ ...fade,
114
+ easing: bezier,
115
+ };
116
+ }
71
117
  export function updateClipFromData(zcomp, clip, data) {
72
- clip.defaultFadeParameters = data.defaultFadeParameters;
118
+ clip.defaultFadeParameters = resolvedFadeParameters(data.defaultFadeParameters, zcomp.animation.curves);
73
119
  clip.length = data.length;
74
120
  clip.clearTracks();
75
121
  for (const track of Object.values(data.tracks)) {
@@ -94,7 +140,7 @@ export function createLayerClipFromData(zcomp, layer, data) {
94
140
  export function createLayerFromData(zcomp, anim, data) {
95
141
  const ret = new Layer(anim, data.scriptName, data.id);
96
142
  ret.active = undefined;
97
- ret.defaultFadeParameters = data.defaultFadeParameters;
143
+ ret.defaultFadeParameters = resolvedFadeParameters(data.defaultFadeParameters, anim.curves);
98
144
  if (data.defaultClip === null)
99
145
  ret.active = null;
100
146
  for (const layerClip of Object.values(data.clips)) {
@@ -140,6 +186,11 @@ export function populateAnimationStructureFromData(zcomp, anim, data) {
140
186
  }
141
187
  return a < b ? -1 : 1;
142
188
  });
189
+ for (const curve of Object.values(data.curves)) {
190
+ if (!curve)
191
+ continue;
192
+ anim.curves[curve.id] = new Bezier(curve.curve);
193
+ }
143
194
  for (const layer of Object.values(layers)) {
144
195
  if (!layer)
145
196
  continue;
package/lib/types.d.ts CHANGED
@@ -100,6 +100,8 @@ export interface Prop {
100
100
  group?: string;
101
101
  groupPriority?: number;
102
102
  values?: Values[];
103
+ order?: number;
104
+ priority?: number;
103
105
  }
104
106
  export interface DefaultChild {
105
107
  label: string;
package/lib/types.js CHANGED
@@ -142,7 +142,9 @@ export function mergeProps(a, b) {
142
142
  default: def,
143
143
  group: a.group === b.group ? a.group : undefined,
144
144
  groupPriority: Math.max(a.groupPriority ?? 0, b.groupPriority ?? 0),
145
+ priority: Math.max(a.priority ?? 0, b.priority ?? 0),
145
146
  values: mergeValues(a.values, b.values),
147
+ order: Math.min(a.order ?? 0, b.order ?? 0),
146
148
  };
147
149
  }
148
150
  function mergeComments(a, b) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "css/**/*"
20
20
  ],
21
21
  "scripts": {
22
- "build": "tsc",
22
+ "build": "rm -rf lib && tsc",
23
23
  "build-animation-tests": "tsc -p ./tsconfig.test.animation.json",
24
24
  "test": "PW_EXPERIMENTAL_TS_ESM=1 playwright test",
25
25
  "tests": "parcel serve tests/index.html -p 8088"