@zcomponent/core 0.0.28 → 0.0.30-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.
@@ -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
  }
@@ -90,6 +90,10 @@ export interface BaseTrack {
90
90
  id: string;
91
91
  type: TrackType;
92
92
  entityID: string;
93
+ lock?: {
94
+ track?: boolean;
95
+ weight?: boolean;
96
+ };
93
97
  }
94
98
  export interface PropertyTrack extends BaseTrack {
95
99
  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
@@ -170,7 +170,6 @@ export function populateAnimationTracksFromData(zcomp, anim, data) {
170
170
  }
171
171
  }
172
172
  export function populateAnimationStructureFromData(zcomp, anim, data) {
173
- console.log('ANIM', data);
174
173
  const clips = resolveClipDependencies(data.clips).reverse();
175
174
  for (const clip of Object.values(clips)) {
176
175
  if (!clip)
@@ -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/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/lib/zcomponent.js CHANGED
@@ -179,6 +179,8 @@ export class ZComponent extends Component {
179
179
  setCurrentZComponentConstruction(that);
180
180
  super(contextManager, instance, constructorProps);
181
181
  that.entityByID.set(behaviorId, this);
182
+ if (node?.parent?.scriptName)
183
+ instance.behaviors[node.parent.scriptName] = this;
182
184
  const props = {
183
185
  ...(that._opts.data.entityProps?.[behaviorId] ?? {}),
184
186
  ...(that._opts.propReplacement?.[behaviorId] ?? {}),
@@ -195,6 +197,8 @@ export class ZComponent extends Component {
195
197
  }
196
198
  dispose() {
197
199
  that.entityByID.delete(behaviorId);
200
+ if (node?.parent?.scriptName)
201
+ delete this.instance.behaviors[node.parent.scriptName];
198
202
  return super.dispose();
199
203
  }
200
204
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "0.0.28",
3
+ "version": "0.0.30-beta",
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"