@zcomponent/core 0.0.29 → 0.0.31-beta

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.
@@ -57,6 +57,7 @@ export declare class Animation {
57
57
  private _emitPendingEvents;
58
58
  private _resolvePath;
59
59
  private _evaluatePath;
60
+ start(): void;
60
61
  }
61
62
  export interface EntityPath {
62
63
  entity: any;
@@ -186,4 +186,12 @@ export class Animation {
186
186
  }
187
187
  resolved[0][resolved[1]] = val;
188
188
  }
189
+ start() {
190
+ for (const layer of this._layers) {
191
+ for (const clip of Object.values(layer.clips)) {
192
+ if (clip.playAtStart)
193
+ clip.play();
194
+ }
195
+ }
196
+ }
189
197
  }
@@ -11,6 +11,7 @@ export declare class LayerClip implements Stream {
11
11
  readonly id?: string | undefined;
12
12
  defaultLoop: boolean;
13
13
  defaultPlaySpeed: number;
14
+ playAtStart: boolean;
14
15
  timeSource: (() => number) | undefined;
15
16
  readonly animation: Animation;
16
17
  private _t0;
@@ -8,6 +8,7 @@ export class LayerClip {
8
8
  this.id = id;
9
9
  this.defaultLoop = false;
10
10
  this.defaultPlaySpeed = 1;
11
+ this.playAtStart = false;
11
12
  this._t0 = 0;
12
13
  this._pauseTime = 0;
13
14
  // private _s0: number = 0;
@@ -36,6 +36,7 @@ export interface LayerClip {
36
36
  reverse?: boolean;
37
37
  playbackSpeed?: number;
38
38
  scriptName?: string;
39
+ playAtStart?: boolean;
39
40
  }
40
41
  export type ActiveLayerClips = ByID<string | undefined>;
41
42
  export declare enum ClipType {
@@ -90,6 +91,10 @@ export interface BaseTrack {
90
91
  id: string;
91
92
  type: TrackType;
92
93
  entityID: string;
94
+ lock?: {
95
+ track?: boolean;
96
+ weight?: boolean;
97
+ };
93
98
  }
94
99
  export interface PropertyTrack extends BaseTrack {
95
100
  type: TrackType.Property;
@@ -6,15 +6,72 @@ export var ClipType;
6
6
  })(ClipType || (ClipType = {}));
7
7
  // TODO: it's a temporary placement for this object
8
8
  export const predefinedCurve = {
9
- linear: [[[0, 0], [0.5, 0.5], [0.5, 0.5], [1, 1]]],
10
- ease: [[[0, 0], [0.25, 0.1], [0.25, 1], [1, 1]]],
11
- easeIn: [[[0, 0], [0.42, 0], [1, 1], [1, 1]]],
12
- easeOut: [[[0, 0], [0, 0], [0.58, 1], [1, 1]]],
13
- easeInOut: [[[0, 0], [0.42, 0], [0.58, 1], [1, 1]]],
14
- bounceOut: [[[0, 0], [0.1, 0], [0.2, 0.5], [0.3, 1]],
15
- [[0.3, 1], [0.4, 0.7], [0.6, 0.7], [0.7, 1]],
16
- [[0.7, 1], [0.75, 0.85], [0.85, 0.85], [0.9, 1]],
17
- [[0.9, 1], [0.925, 0.95], [0.975, 0.95], [1, 1]]]
9
+ linear: [
10
+ [
11
+ [0, 0],
12
+ [0.5, 0.5],
13
+ [0.5, 0.5],
14
+ [1, 1],
15
+ ],
16
+ ],
17
+ ease: [
18
+ [
19
+ [0, 0],
20
+ [0.25, 0.1],
21
+ [0.25, 1],
22
+ [1, 1],
23
+ ],
24
+ ],
25
+ easeIn: [
26
+ [
27
+ [0, 0],
28
+ [0.42, 0],
29
+ [1, 1],
30
+ [1, 1],
31
+ ],
32
+ ],
33
+ easeOut: [
34
+ [
35
+ [0, 0],
36
+ [0, 0],
37
+ [0.58, 1],
38
+ [1, 1],
39
+ ],
40
+ ],
41
+ easeInOut: [
42
+ [
43
+ [0, 0],
44
+ [0.42, 0],
45
+ [0.58, 1],
46
+ [1, 1],
47
+ ],
48
+ ],
49
+ bounceOut: [
50
+ [
51
+ [0, 0],
52
+ [0.1, 0],
53
+ [0.2, 0.5],
54
+ [0.3, 1],
55
+ ],
56
+ [
57
+ [0.3, 1],
58
+ [0.4, 0.7],
59
+ [0.6, 0.7],
60
+ [0.7, 1],
61
+ ],
62
+ [
63
+ [0.7, 1],
64
+ [0.75, 0.85],
65
+ [0.85, 0.85],
66
+ [0.9, 1],
67
+ ],
68
+ [
69
+ [0.9, 1],
70
+ [0.925, 0.95],
71
+ [0.975, 0.95],
72
+ [1, 1],
73
+ ],
74
+ ],
18
75
  };
19
76
  // Simple linear transition between two object position value could look like this:
20
77
  // [
@@ -63,9 +63,11 @@ export interface NodeData {
63
63
  export interface BehaviorData {
64
64
  id: string;
65
65
  type: Import;
66
+ label?: string;
66
67
  parent: {
67
68
  id: string;
68
69
  order: string;
70
+ scriptName?: string;
69
71
  };
70
72
  }
71
73
  export type EntityPropOverride = PropEntityPropOverride | ImportEntityPropOverride | ContextValueEntityPropOverride;
package/lib/inflate.js CHANGED
@@ -135,6 +135,7 @@ export function createLayerClipFromData(zcomp, layer, data) {
135
135
  if (data.reverse)
136
136
  ret.defaultPlaySpeed *= -1;
137
137
  ret.defaultLoop = data.loop ?? false;
138
+ ret.playAtStart = data.playAtStart ?? false;
138
139
  return ret;
139
140
  }
140
141
  export function createLayerFromData(zcomp, anim, data) {
@@ -1,4 +1,4 @@
1
- import { EntityPropOverride, Import, NodeByID, ParsedImport, Props } from './data/core';
1
+ import { BehaviorByID, EntityPropOverride, Import, NodeByID, ParsedImport, Props, ZComponentData } from './data/core';
2
2
  import * as Data from './data';
3
3
  import { Layer } from './animation';
4
4
  export declare function parseImport(i: Import): ParsedImport;
@@ -6,6 +6,8 @@ export declare function constructImport(from: string, destFile: string, imp: str
6
6
  export declare function getScriptName(n: string, requireUniqueIn: string[] | {
7
7
  [k: string]: any;
8
8
  }): string;
9
+ export declare function getScriptNameForBehaviorLabel(zcomp: ZComponentData, nodeID: string, label: string): string;
10
+ export declare function getScriptNameForNodeLabel(zcomp: ZComponentData, label: string): string;
9
11
  export declare function isValidVariableName(n: string): boolean;
10
12
  export declare function variableNameFromImport(imp: ParsedImport): string;
11
13
  export type EntityPropOverrideByEntityPropPath = {
@@ -23,8 +25,10 @@ export declare const typeDefinitionForComponent: (nodes: NodeByID, props: Props,
23
25
  [id: string]: {
24
26
  [id: string]: boolean;
25
27
  };
26
- } | undefined, url: string, layers: Data.ByID<Data.Layer>) => string;
28
+ } | undefined, layers: Data.ByID<Data.Layer>, behaviors: BehaviorByID) => string;
27
29
  export declare function getSafeKeyName(n: string): string;
28
30
  export declare function propertyTracksByEntityID(clip: Data.Clip): {
29
31
  [id: string]: Data.PropertyTrack[];
30
32
  };
33
+ export declare function getBehaviorBlockForNode(behaviors: BehaviorByID, behaviorIDs: string[], importMapping: Map<string, string>): string;
34
+ export declare function importNameWithoutExt(imp: string): string;
package/lib/selectors.js CHANGED
@@ -2,6 +2,7 @@ import { EntityPropOverrideType } from './data/core';
2
2
  import * as path from 'path';
3
3
  import { outputForType } from './types';
4
4
  import * as Data from './data';
5
+ import { computeBehaviorHierarchy } from './data';
5
6
  export function parseImport(i) {
6
7
  if (typeof i !== 'string')
7
8
  return ['', ''];
@@ -107,6 +108,29 @@ export function getScriptName(n, requireUniqueIn) {
107
108
  }
108
109
  return finalname;
109
110
  }
111
+ export function getScriptNameForBehaviorLabel(zcomp, nodeID, label) {
112
+ const uniques = [];
113
+ const behaviorsByNode = computeBehaviorHierarchy(zcomp.behaviors);
114
+ const nodeBehaviors = behaviorsByNode[nodeID];
115
+ if (nodeBehaviors) {
116
+ for (const behaviorID of nodeBehaviors) {
117
+ const behavior = zcomp.behaviors[behaviorID];
118
+ if (!behavior?.parent.scriptName)
119
+ continue;
120
+ uniques.push(behavior.parent.scriptName);
121
+ }
122
+ }
123
+ return getScriptName(label, uniques);
124
+ }
125
+ export function getScriptNameForNodeLabel(zcomp, label) {
126
+ const uniques = [];
127
+ for (const node of Object.values(zcomp.nodes)) {
128
+ if (!node?.scriptName)
129
+ continue;
130
+ uniques.push(node.scriptName);
131
+ }
132
+ return getScriptName(label, uniques);
133
+ }
110
134
  const variableNameRegex = new RegExp(/[a-zA-Z_$][0-9a-zA-Z_$]*/);
111
135
  export function isValidVariableName(n) {
112
136
  return variableNameRegex.test(n);
@@ -161,10 +185,11 @@ export function summaryForEntityPropOverrideDestination(o) {
161
185
  }
162
186
  return '?';
163
187
  }
164
- export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, url, layers) => {
188
+ export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, layers, behaviors) => {
165
189
  const importMapping = new Map();
166
190
  let indx = 0;
167
191
  let importStrings = [];
192
+ const behaviorsByNodeID = computeBehaviorHierarchy(behaviors);
168
193
  for (const scriptNameNodes of Object.values(scriptNames ?? {})) {
169
194
  for (const nodeID of Object.keys(scriptNameNodes)) {
170
195
  const node = nodes[nodeID];
@@ -177,6 +202,18 @@ export const typeDefinitionForComponent = (nodes, props, constructorProps, scrip
177
202
  importMapping.set(node.type, variable);
178
203
  indx++;
179
204
  }
205
+ for (const behaviorID of behaviorsByNodeID[nodeID] ?? []) {
206
+ const behavior = behaviors[behaviorID];
207
+ if (!behavior)
208
+ continue;
209
+ if (!importMapping.has(behavior.type)) {
210
+ const imp = parseImport(behavior.type);
211
+ const variable = `${getScriptName(variableNameFromImport(imp), {})}_${indx.toString()}`;
212
+ importStrings.push(`import { ${imp[1]} as ${variable} } from ${JSON.stringify(importNameWithoutExt(imp[0]))};`);
213
+ importMapping.set(behavior.type, variable);
214
+ indx++;
215
+ }
216
+ }
180
217
  }
181
218
  }
182
219
  return `import { ZComponent, ContextManager, Observable, Animation, Layer, LayerClip } from "@zcomponent/core";
@@ -199,10 +236,10 @@ declare class Comp extends ZComponent {
199
236
  ${Object.entries(scriptNames ?? {}).map(entry => {
200
237
  const values = Object.keys(entry[1]);
201
238
  if (values.length > 1) {
202
- return `\t\t${entry[0]}: {${values.map(e => `${JSON.stringify(e)}: ${importMapping.get(nodes[e].type)}`).join(', ')}},`;
239
+ return `\t\t${entry[0]}: {${values.map(e => `${JSON.stringify(e)}: ${importMapping.get(nodes[e].type)}${getBehaviorBlockForNode(behaviors, behaviorsByNodeID[nodes[e].id] ?? [], importMapping)}`).join(', ')}},`;
203
240
  }
204
241
  else {
205
- return `\t\t${entry[0]}: ${importMapping.get(nodes[values[0]].type)},`;
242
+ return `\t\t${entry[0]}: ${importMapping.get(nodes[values[0]].type)}${getBehaviorBlockForNode(behaviors, behaviorsByNodeID[nodes[values[0]].id] ?? [], importMapping)},`;
206
243
  }
207
244
  }).join("\n")}
208
245
  };
@@ -287,3 +324,24 @@ export function propertyTracksByEntityID(clip) {
287
324
  }
288
325
  return ret;
289
326
  }
327
+ export function getBehaviorBlockForNode(behaviors, behaviorIDs, importMapping) {
328
+ return ` & {
329
+ behaviors: {
330
+ ${behaviorIDs.map((entry, indx) => {
331
+ const behavior = behaviors[entry];
332
+ if (!behavior)
333
+ return '';
334
+ const type = importMapping.get(behavior.type);
335
+ const ret = [`\t\t\t\t${indx.toString()}: ${type},`];
336
+ if (behavior.parent.scriptName)
337
+ ret.push(`\t\t\t\t${behavior.parent.scriptName}: ${type},`);
338
+ return ret.join('\n');
339
+ }).join('\n')}
340
+ }
341
+ }`;
342
+ }
343
+ export function importNameWithoutExt(imp) {
344
+ if (imp.toLowerCase().endsWith('.ts'))
345
+ return imp.substring(0, imp.length - 3);
346
+ return imp;
347
+ }
package/lib/zcomponent.js CHANGED
@@ -62,7 +62,11 @@ export class ZComponent extends Component {
62
62
  this.animation.initialize();
63
63
  this.isConstructed = true;
64
64
  this._constructedResolve();
65
- started(contextManager).then(this._updateAnimationRegistrations);
65
+ started(contextManager).then(() => {
66
+ this._updateAnimationRegistrations();
67
+ if (!isDesignTime(contextManager))
68
+ this.animation.start();
69
+ });
66
70
  this.register(this.animation.hasLayers, this._updateAnimationRegistrations, { bindWhenDisabled: true });
67
71
  }
68
72
  _constructorForNode(nodeId) {
@@ -179,6 +183,8 @@ export class ZComponent extends Component {
179
183
  setCurrentZComponentConstruction(that);
180
184
  super(contextManager, instance, constructorProps);
181
185
  that.entityByID.set(behaviorId, this);
186
+ if (node?.parent?.scriptName)
187
+ instance.behaviors[node.parent.scriptName] = this;
182
188
  const props = {
183
189
  ...(that._opts.data.entityProps?.[behaviorId] ?? {}),
184
190
  ...(that._opts.propReplacement?.[behaviorId] ?? {}),
@@ -195,6 +201,8 @@ export class ZComponent extends Component {
195
201
  }
196
202
  dispose() {
197
203
  that.entityByID.delete(behaviorId);
204
+ if (node?.parent?.scriptName)
205
+ delete this.instance.behaviors[node.parent.scriptName];
198
206
  return super.dispose();
199
207
  }
200
208
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "0.0.29",
3
+ "version": "0.0.31-beta",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",