@zcomponent/core 0.0.29 → 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.
- package/lib/data/animation.d.ts +4 -0
- package/lib/data/animation.js +66 -9
- package/lib/data/core.d.ts +2 -0
- package/lib/selectors.d.ts +6 -2
- package/lib/selectors.js +61 -3
- package/lib/zcomponent.js +4 -0
- package/package.json +1 -1
package/lib/data/animation.d.ts
CHANGED
package/lib/data/animation.js
CHANGED
|
@@ -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: [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
// [
|
package/lib/data/core.d.ts
CHANGED
|
@@ -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/selectors.d.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
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
|
@@ -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
|
};
|