@zcomponent/core 1.14.3 → 1.15.0-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/README.md +0 -6
- package/lib/actionbehavior.d.ts +12 -3
- package/lib/actionbehavior.js +12 -3
- package/lib/animation/animation.d.ts +96 -4
- package/lib/animation/animation.js +93 -0
- package/lib/animation/animationstate.d.ts +52 -2
- package/lib/animation/bezier.d.ts +12 -1
- package/lib/animation/bezier.js +15 -12
- package/lib/animation/clips/clip.d.ts +71 -0
- package/lib/animation/clips/clip.js +68 -0
- package/lib/animation/interpolate.d.ts +17 -0
- package/lib/animation/interpolate.js +71 -0
- package/lib/animation/keyframe.d.ts +24 -1
- package/lib/animation/layer.d.ts +73 -1
- package/lib/animation/layer.js +69 -0
- package/lib/animation/layerclip.d.ts +75 -0
- package/lib/animation/layerclip.js +69 -0
- package/lib/animation/stream.d.ts +49 -7
- package/lib/animation/stream.js +3 -0
- package/lib/animation/tracks/cliptrack.d.ts +64 -0
- package/lib/animation/tracks/cliptrack.js +65 -1
- package/lib/animation/tracks/functiontrack.d.ts +60 -0
- package/lib/animation/tracks/functiontrack.js +62 -3
- package/lib/animation/tracks/propertytrack.d.ts +84 -0
- package/lib/animation/tracks/propertytrack.js +75 -0
- package/lib/animation/tracks/streamtrack.d.ts +51 -0
- package/lib/animation/tracks/streamtrack.js +54 -3
- package/lib/animation/tracks/track.d.ts +56 -0
- package/lib/animation/tracks/track.js +40 -0
- package/lib/behavior.d.ts +37 -0
- package/lib/behavior.js +21 -0
- package/lib/behaviors/ActivateState.d.ts +10 -3
- package/lib/behaviors/ActivateState.js +8 -4
- package/lib/behaviors/CallFunction.d.ts +1 -1
- package/lib/behaviors/CallFunction.js +2 -2
- package/lib/behaviors/ConsoleLog.d.ts +1 -1
- package/lib/behaviors/ConsoleLog.js +2 -2
- package/lib/behaviors/DownloadSnapshot.d.ts +5 -2
- package/lib/behaviors/DownloadSnapshot.js +5 -2
- package/lib/behaviors/LaunchURL.d.ts +1 -1
- package/lib/behaviors/LaunchURL.js +1 -1
- package/lib/behaviors/LogAnalyticsEvent.d.ts +1 -1
- package/lib/behaviors/LogAnalyticsEvent.js +2 -2
- package/lib/behaviors/PauseLayerClip.d.ts +5 -3
- package/lib/behaviors/PauseLayerClip.js +3 -2
- package/lib/behaviors/PlayLayerClip.d.ts +10 -4
- package/lib/behaviors/PlayLayerClip.js +7 -5
- package/lib/behaviors/PlaySound.d.ts +4 -4
- package/lib/behaviors/PlaySound.js +4 -4
- package/lib/behaviors/SetLayerOff.d.ts +4 -3
- package/lib/behaviors/SetLayerOff.js +3 -2
- package/lib/behaviors/ShowTextAlert.d.ts +2 -2
- package/lib/behaviors/ShowTextAlert.js +5 -5
- package/lib/behaviors/ToggleLayerClips.d.ts +4 -3
- package/lib/behaviors/ToggleLayerClips.js +5 -4
- package/lib/behaviors/stream/PauseStream.d.ts +15 -3
- package/lib/behaviors/stream/PauseStream.js +13 -2
- package/lib/behaviors/stream/PlayStream.d.ts +14 -4
- package/lib/behaviors/stream/PlayStream.js +10 -3
- package/lib/behaviors/stream/SeekStream.d.ts +12 -3
- package/lib/behaviors/stream/SeekStream.js +10 -2
- package/lib/behaviors/stream/StopStream.d.ts +11 -3
- package/lib/behaviors/stream/StopStream.js +9 -2
- package/lib/component.d.ts +85 -5
- package/lib/component.js +49 -1
- package/lib/components/Audio.d.ts +14 -5
- package/lib/components/Audio.js +19 -10
- package/lib/components/AudioLayerSettings.d.ts +9 -3
- package/lib/components/AudioLayerSettings.js +9 -3
- package/lib/components/Children.d.ts +7 -2
- package/lib/components/Children.js +6 -1
- package/lib/components/DefaultCookieConsent.d.ts +13 -3
- package/lib/components/DefaultCookieConsent.js +62 -38
- package/lib/components/DefaultLoader.d.ts +14 -9
- package/lib/components/DefaultLoader.js +25 -20
- package/lib/components/Gamepad.d.ts +12 -4
- package/lib/components/Gamepad.js +16 -8
- package/lib/components/LongLoad.d.ts +7 -1
- package/lib/components/LongLoad.js +7 -1
- package/lib/components/SnapshotUI.d.ts +10 -0
- package/lib/components/SnapshotUI.js +24 -0
- package/lib/context.d.ts +117 -0
- package/lib/context.js +50 -71
- package/lib/contexts/analyticscontext.d.ts +6 -0
- package/lib/contexts/analyticscontext.js +6 -0
- package/lib/contexts/audiocontextcontext.d.ts +26 -1
- package/lib/contexts/audiocontextcontext.js +26 -1
- package/lib/contexts/canvascontext.d.ts +59 -1
- package/lib/contexts/canvascontext.js +54 -1
- package/lib/contexts/cookieconsentcontext.d.ts +84 -10
- package/lib/contexts/cookieconsentcontext.js +71 -0
- package/lib/contexts/environmentcontext.d.ts +40 -5
- package/lib/contexts/environmentcontext.js +40 -5
- package/lib/contexts/gamepadcontext.d.ts +38 -0
- package/lib/contexts/gamepadcontext.js +38 -0
- package/lib/contexts/gesturecontext.d.ts +31 -4
- package/lib/contexts/gesturecontext.js +28 -4
- package/lib/contexts/globaltagcontext.d.ts +14 -2
- package/lib/contexts/globaltagcontext.js +13 -1
- package/lib/contexts/loadcontext.d.ts +92 -5
- package/lib/contexts/loadcontext.js +98 -11
- package/lib/contexts/orientationcontext.d.ts +58 -1
- package/lib/contexts/orientationcontext.js +51 -1
- package/lib/contexts/snapshotContext.d.ts +97 -4
- package/lib/contexts/snapshotContext.js +115 -4
- package/lib/contexts/tagcontext.d.ts +56 -2
- package/lib/contexts/tagcontext.js +77 -7
- package/lib/contexts/textalertcontext.d.ts +35 -2
- package/lib/contexts/textalertcontext.js +20 -2
- package/lib/contexts/usereventcontext.d.ts +29 -0
- package/lib/contexts/usereventcontext.js +30 -1
- package/lib/data/animation.d.ts +163 -0
- package/lib/data/animation.js +9 -0
- package/lib/data/change.d.ts +199 -0
- package/lib/data/change.js +190 -0
- package/lib/emitter.d.ts +8 -1
- package/lib/emitter.js +7 -0
- package/lib/entity.d.ts +30 -5
- package/lib/entity.js +23 -7
- package/lib/event.d.ts +19 -2
- package/lib/event.js +19 -2
- package/lib/fractionalindexing.js +38 -42
- package/lib/index.d.ts +27 -1
- package/lib/index.js +27 -1
- package/lib/inflate.d.ts +68 -0
- package/lib/inflate.js +76 -0
- package/lib/observable.d.ts +3 -3
- package/lib/observable.js +4 -4
- package/lib/profile.d.ts +27 -0
- package/lib/profile.js +26 -0
- package/lib/selectors.d.ts +114 -0
- package/lib/selectors.js +159 -7
- package/lib/types.d.ts +215 -0
- package/lib/types.js +110 -1
- package/lib/validators.d.ts +27 -0
- package/lib/validators.js +27 -0
- package/lib/values/values.d.ts +5 -0
- package/lib/values/values.js +5 -0
- package/lib/zcomponent.d.ts +72 -0
- package/lib/zcomponent.js +81 -0
- package/lib/zcomponentconstruction.d.ts +11 -1
- package/lib/zcomponentconstruction.js +10 -0
- package/package.json +7 -2
package/lib/selectors.d.ts
CHANGED
|
@@ -1,15 +1,69 @@
|
|
|
1
1
|
import { BehaviorByID, EntityPropOverride, Import, NodeByID, ParsedImport, Props, ZComponentData } from './data/core';
|
|
2
2
|
import * as Data from './data';
|
|
3
3
|
import { ZValues } from './values/values';
|
|
4
|
+
/**
|
|
5
|
+
* Parses an import string into a tuple containing the import path and import name.
|
|
6
|
+
*
|
|
7
|
+
* @param i - The import string to parse.
|
|
8
|
+
* @returns A tuple where the first element is the import path and the second element is the import name.
|
|
9
|
+
*/
|
|
4
10
|
export declare function parseImport(i: Import): ParsedImport;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs an import string from given parameters.
|
|
13
|
+
*
|
|
14
|
+
* @param from - The source file path.
|
|
15
|
+
* @param destFile - The destination file path.
|
|
16
|
+
* @param imp - The import name.
|
|
17
|
+
* @returns A string representing the constructed import.
|
|
18
|
+
*/
|
|
5
19
|
export declare function constructImport(from: string, destFile: string, imp: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Generates a script name from a given string, ensuring uniqueness within a specified context.
|
|
22
|
+
*
|
|
23
|
+
* @param n - The input string to generate the script name from.
|
|
24
|
+
* @param requireUniqueIn - The context (array or object) in which the generated name should be unique.
|
|
25
|
+
* @returns A string representing the generated script name.
|
|
26
|
+
*/
|
|
6
27
|
export declare function getScriptName(n: string, requireUniqueIn: string[] | {
|
|
7
28
|
[k: string]: any;
|
|
8
29
|
}): string;
|
|
30
|
+
/**
|
|
31
|
+
* Generates a script name for a behavior label, ensuring uniqueness within the context of a ZComponent's nodes.
|
|
32
|
+
*
|
|
33
|
+
* @param zcomp - The ZComponent data.
|
|
34
|
+
* @param nodeID - The node ID associated with the behavior.
|
|
35
|
+
* @param label - The behavior label.
|
|
36
|
+
* @returns A string representing the generated script name for the behavior.
|
|
37
|
+
*/
|
|
9
38
|
export declare function getScriptNameForBehaviorLabel(zcomp: ZComponentData, nodeID: string, label: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Generates a script name for a node label, ensuring uniqueness within the context of a ZComponent's nodes.
|
|
41
|
+
*
|
|
42
|
+
* @param zcomp - The ZComponent data.
|
|
43
|
+
* @param label - The node label.
|
|
44
|
+
* @returns A string representing the generated script name for the node.
|
|
45
|
+
*/
|
|
10
46
|
export declare function getScriptNameForNodeLabel(zcomp: ZComponentData, label: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a given string is a valid variable name.
|
|
49
|
+
*
|
|
50
|
+
* @param n - The string to check.
|
|
51
|
+
* @returns True if the string is a valid variable name, otherwise false.
|
|
52
|
+
*/
|
|
11
53
|
export declare function isValidVariableName(n: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Generates a variable name from an import statement.
|
|
56
|
+
*
|
|
57
|
+
* @param imp - The parsed import statement.
|
|
58
|
+
* @returns A string representing the generated variable name.
|
|
59
|
+
*/
|
|
12
60
|
export declare function variableNameFromImport(imp: ParsedImport): string;
|
|
61
|
+
/**
|
|
62
|
+
* Organizes entity property overrides by entity ID and property name.
|
|
63
|
+
*
|
|
64
|
+
* @param entityPropOverrides - An object containing entity property overrides.
|
|
65
|
+
* @returns An object organized by entity ID and property name, containing the overrides.
|
|
66
|
+
*/
|
|
13
67
|
export type EntityPropOverrideByEntityPropPath = {
|
|
14
68
|
[entityID: string]: {
|
|
15
69
|
[propName: string]: {
|
|
@@ -17,19 +71,79 @@ export type EntityPropOverrideByEntityPropPath = {
|
|
|
17
71
|
};
|
|
18
72
|
};
|
|
19
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Generates a summary description for the destination of an entity property override.
|
|
76
|
+
*
|
|
77
|
+
* @param o - The entity property override object.
|
|
78
|
+
* @returns A string representing the summary description of the override's destination.
|
|
79
|
+
*/
|
|
20
80
|
export declare function entityPropOverrideByEntityAndProp(entityPropOverrides: {
|
|
21
81
|
[id: string]: EntityPropOverride;
|
|
22
82
|
}): EntityPropOverrideByEntityPropPath;
|
|
83
|
+
/**
|
|
84
|
+
* Generates a summary description for the destination of an entity property override.
|
|
85
|
+
*
|
|
86
|
+
* @param o - The entity property override object.
|
|
87
|
+
* @returns A string representing the summary description of the override's destination.
|
|
88
|
+
*/
|
|
23
89
|
export declare function summaryForEntityPropOverrideDestination(o: EntityPropOverride): string;
|
|
90
|
+
/**
|
|
91
|
+
* Generates a TypeScript type definition for a ZComponent.
|
|
92
|
+
*
|
|
93
|
+
* This function creates a type definition script for a ZComponent based on its nodes, properties, constructor properties, script names, layers, and behaviors.
|
|
94
|
+
*
|
|
95
|
+
* @param nodes - The nodes of the ZComponent.
|
|
96
|
+
* @param props - The properties of the ZComponent.
|
|
97
|
+
* @param constructorProps - The constructor properties of the ZComponent.
|
|
98
|
+
* @param scriptNames - The script names for the nodes and behaviors.
|
|
99
|
+
* @param layers - The layers of the ZComponent's animation.
|
|
100
|
+
* @param behaviors - The behaviors of the ZComponent.
|
|
101
|
+
* @returns A string containing the TypeScript type definition for the ZComponent.
|
|
102
|
+
*/
|
|
24
103
|
export declare const typeDefinitionForComponent: (nodes: NodeByID, props: Props, constructorProps: Props | undefined, scriptNames: {
|
|
25
104
|
[id: string]: {
|
|
26
105
|
[id: string]: boolean;
|
|
27
106
|
};
|
|
28
107
|
} | undefined, layers: Data.ByID<Data.Layer>, behaviors: BehaviorByID) => string;
|
|
108
|
+
/**
|
|
109
|
+
* Sanitizes a key name to ensure it is safe for use in scripting.
|
|
110
|
+
*
|
|
111
|
+
* @param n - The original key name.
|
|
112
|
+
* @returns A sanitized, script-safe key name.
|
|
113
|
+
*/
|
|
29
114
|
export declare function getSafeKeyName(n: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Extracts and groups property tracks by their associated entity ID from a given clip.
|
|
117
|
+
*
|
|
118
|
+
* @param clip - The clip containing property tracks.
|
|
119
|
+
* @returns An object mapping entity IDs to their respective property tracks.
|
|
120
|
+
*/
|
|
30
121
|
export declare function propertyTracksByEntityID(clip: Data.Clip): {
|
|
31
122
|
[id: string]: Data.PropertyTrack[];
|
|
32
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* Generates a behavior block for a node, based on the behaviors and their IDs.
|
|
126
|
+
*
|
|
127
|
+
* @param behaviors - An object containing behavior data.
|
|
128
|
+
* @param behaviorIDs - An array of behavior IDs.
|
|
129
|
+
* @param importMapping - A map of behavior types to their import names.
|
|
130
|
+
* @returns A string representing the behavior block for the node.
|
|
131
|
+
*/
|
|
33
132
|
export declare function getBehaviorBlockForNode(behaviors: BehaviorByID, behaviorIDs: string[], importMapping: Map<string, string>): string;
|
|
133
|
+
/**
|
|
134
|
+
* Removes the file extension from an import name, if it ends with '.ts'.
|
|
135
|
+
*
|
|
136
|
+
* @param imp - The import name to process.
|
|
137
|
+
* @returns The import name without the '.ts' extension.
|
|
138
|
+
*/
|
|
34
139
|
export declare function importNameWithoutExt(imp: string): string;
|
|
140
|
+
/**
|
|
141
|
+
* Generates a TypeScript type definition for ZValues.
|
|
142
|
+
*
|
|
143
|
+
* This function creates a type definition script for ZValues based on the values and their associated URL.
|
|
144
|
+
*
|
|
145
|
+
* @param values - The ZValues instance.
|
|
146
|
+
* @param url - The URL associated with the values.
|
|
147
|
+
* @returns A string containing the TypeScript type definition for ZValues.
|
|
148
|
+
*/
|
|
35
149
|
export declare const typeDefinitionForZValues: (values: ZValues, url: string) => string;
|
package/lib/selectors.js
CHANGED
|
@@ -4,6 +4,12 @@ import { outputForType } from './types';
|
|
|
4
4
|
import * as Data from './data';
|
|
5
5
|
import * as VALUES from './values/valuesmutator';
|
|
6
6
|
import { computeBehaviorHierarchy } from './data';
|
|
7
|
+
/**
|
|
8
|
+
* Parses an import string into a tuple containing the import path and import name.
|
|
9
|
+
*
|
|
10
|
+
* @param i - The import string to parse.
|
|
11
|
+
* @returns A tuple where the first element is the import path and the second element is the import name.
|
|
12
|
+
*/
|
|
7
13
|
export function parseImport(i) {
|
|
8
14
|
if (typeof i !== 'string')
|
|
9
15
|
return ['', ''];
|
|
@@ -12,6 +18,14 @@ export function parseImport(i) {
|
|
|
12
18
|
return [i, 'default'];
|
|
13
19
|
return [i.substr(0, indx), i.substr(indx + 1)];
|
|
14
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Constructs an import string from given parameters.
|
|
23
|
+
*
|
|
24
|
+
* @param from - The source file path.
|
|
25
|
+
* @param destFile - The destination file path.
|
|
26
|
+
* @param imp - The import name.
|
|
27
|
+
* @returns A string representing the constructed import.
|
|
28
|
+
*/
|
|
15
29
|
export function constructImport(from, destFile, imp) {
|
|
16
30
|
if (destFile.indexOf('/node_modules/') === 0) {
|
|
17
31
|
return destFile.substr('/node_modules/'.length) + '#' + imp;
|
|
@@ -86,6 +100,13 @@ const reservedWords = [
|
|
|
86
100
|
'with',
|
|
87
101
|
'yield',
|
|
88
102
|
];
|
|
103
|
+
/**
|
|
104
|
+
* Generates a script name from a given string, ensuring uniqueness within a specified context.
|
|
105
|
+
*
|
|
106
|
+
* @param n - The input string to generate the script name from.
|
|
107
|
+
* @param requireUniqueIn - The context (array or object) in which the generated name should be unique.
|
|
108
|
+
* @returns A string representing the generated script name.
|
|
109
|
+
*/
|
|
89
110
|
export function getScriptName(n, requireUniqueIn) {
|
|
90
111
|
const existing = new Set(Array.isArray(requireUniqueIn) ? requireUniqueIn : Object.keys(requireUniqueIn));
|
|
91
112
|
if (n === undefined || n.length === 0) {
|
|
@@ -109,6 +130,14 @@ export function getScriptName(n, requireUniqueIn) {
|
|
|
109
130
|
}
|
|
110
131
|
return finalname;
|
|
111
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Generates a script name for a behavior label, ensuring uniqueness within the context of a ZComponent's nodes.
|
|
135
|
+
*
|
|
136
|
+
* @param zcomp - The ZComponent data.
|
|
137
|
+
* @param nodeID - The node ID associated with the behavior.
|
|
138
|
+
* @param label - The behavior label.
|
|
139
|
+
* @returns A string representing the generated script name for the behavior.
|
|
140
|
+
*/
|
|
112
141
|
export function getScriptNameForBehaviorLabel(zcomp, nodeID, label) {
|
|
113
142
|
const uniques = [];
|
|
114
143
|
const behaviorsByNode = computeBehaviorHierarchy(zcomp.behaviors);
|
|
@@ -123,6 +152,13 @@ export function getScriptNameForBehaviorLabel(zcomp, nodeID, label) {
|
|
|
123
152
|
}
|
|
124
153
|
return getScriptName(label, uniques);
|
|
125
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Generates a script name for a node label, ensuring uniqueness within the context of a ZComponent's nodes.
|
|
157
|
+
*
|
|
158
|
+
* @param zcomp - The ZComponent data.
|
|
159
|
+
* @param label - The node label.
|
|
160
|
+
* @returns A string representing the generated script name for the node.
|
|
161
|
+
*/
|
|
126
162
|
export function getScriptNameForNodeLabel(zcomp, label) {
|
|
127
163
|
const uniques = [];
|
|
128
164
|
for (const node of Object.values(zcomp.nodes)) {
|
|
@@ -133,9 +169,21 @@ export function getScriptNameForNodeLabel(zcomp, label) {
|
|
|
133
169
|
return getScriptName(label, uniques);
|
|
134
170
|
}
|
|
135
171
|
const variableNameRegex = new RegExp(/[a-zA-Z_$][0-9a-zA-Z_$]*/);
|
|
172
|
+
/**
|
|
173
|
+
* Checks if a given string is a valid variable name.
|
|
174
|
+
*
|
|
175
|
+
* @param n - The string to check.
|
|
176
|
+
* @returns True if the string is a valid variable name, otherwise false.
|
|
177
|
+
*/
|
|
136
178
|
export function isValidVariableName(n) {
|
|
137
179
|
return variableNameRegex.test(n);
|
|
138
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Generates a variable name from an import statement.
|
|
183
|
+
*
|
|
184
|
+
* @param imp - The parsed import statement.
|
|
185
|
+
* @returns A string representing the generated variable name.
|
|
186
|
+
*/
|
|
139
187
|
export function variableNameFromImport(imp) {
|
|
140
188
|
if (imp[1] === 'default' && typeof imp[0] === 'string') {
|
|
141
189
|
const parts = imp[0].split(path.sep);
|
|
@@ -145,6 +193,12 @@ export function variableNameFromImport(imp) {
|
|
|
145
193
|
return imp[1];
|
|
146
194
|
return 'unknown';
|
|
147
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Generates a summary description for the destination of an entity property override.
|
|
198
|
+
*
|
|
199
|
+
* @param o - The entity property override object.
|
|
200
|
+
* @returns A string representing the summary description of the override's destination.
|
|
201
|
+
*/
|
|
148
202
|
export function entityPropOverrideByEntityAndProp(entityPropOverrides) {
|
|
149
203
|
const ret = Object.create(null);
|
|
150
204
|
for (const val of Object.values(entityPropOverrides)) {
|
|
@@ -159,6 +213,12 @@ export function entityPropOverrideByEntityAndProp(entityPropOverrides) {
|
|
|
159
213
|
}
|
|
160
214
|
return ret;
|
|
161
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Generates a summary description for the destination of an entity property override.
|
|
218
|
+
*
|
|
219
|
+
* @param o - The entity property override object.
|
|
220
|
+
* @returns A string representing the summary description of the override's destination.
|
|
221
|
+
*/
|
|
162
222
|
export function summaryForEntityPropOverrideDestination(o) {
|
|
163
223
|
switch (o.type) {
|
|
164
224
|
case EntityPropOverrideType.ComponentProp:
|
|
@@ -171,7 +231,7 @@ export function summaryForEntityPropOverrideDestination(o) {
|
|
|
171
231
|
}
|
|
172
232
|
if (typeof imp[1] === 'string')
|
|
173
233
|
return imp[1] + '.' + o.val;
|
|
174
|
-
return
|
|
234
|
+
return '?.' + o.val;
|
|
175
235
|
}
|
|
176
236
|
case EntityPropOverrideType.Import: {
|
|
177
237
|
return o.imp;
|
|
@@ -215,10 +275,23 @@ function typeContainsType(p, name) {
|
|
|
215
275
|
}
|
|
216
276
|
return false;
|
|
217
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Generates a TypeScript type definition for a ZComponent.
|
|
280
|
+
*
|
|
281
|
+
* This function creates a type definition script for a ZComponent based on its nodes, properties, constructor properties, script names, layers, and behaviors.
|
|
282
|
+
*
|
|
283
|
+
* @param nodes - The nodes of the ZComponent.
|
|
284
|
+
* @param props - The properties of the ZComponent.
|
|
285
|
+
* @param constructorProps - The constructor properties of the ZComponent.
|
|
286
|
+
* @param scriptNames - The script names for the nodes and behaviors.
|
|
287
|
+
* @param layers - The layers of the ZComponent's animation.
|
|
288
|
+
* @param behaviors - The behaviors of the ZComponent.
|
|
289
|
+
* @returns A string containing the TypeScript type definition for the ZComponent.
|
|
290
|
+
*/
|
|
218
291
|
export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, layers, behaviors) => {
|
|
219
292
|
const importMapping = new Map();
|
|
220
293
|
let indx = 0;
|
|
221
|
-
|
|
294
|
+
const importStrings = [];
|
|
222
295
|
const behaviorsByNodeID = computeBehaviorHierarchy(behaviors);
|
|
223
296
|
for (const scriptNameNodes of Object.values(scriptNames ?? {})) {
|
|
224
297
|
for (const nodeID of Object.keys(scriptNameNodes)) {
|
|
@@ -265,15 +338,19 @@ declare class Comp extends ZComponent {
|
|
|
265
338
|
constructor(contextManager: ContextManager, constructorProps: ConstructorProps);
|
|
266
339
|
|
|
267
340
|
nodes: {
|
|
268
|
-
${Object.entries(scriptNames ?? {})
|
|
341
|
+
${Object.entries(scriptNames ?? {})
|
|
342
|
+
.map(entry => {
|
|
269
343
|
const values = Object.keys(entry[1]);
|
|
270
344
|
if (values.length > 1) {
|
|
271
|
-
return `\t\t${entry[0]}: {${values
|
|
345
|
+
return `\t\t${entry[0]}: {${values
|
|
346
|
+
.map(e => `${JSON.stringify(e)}: ${importMapping.get(nodes[e].type)}${getBehaviorBlockForNode(behaviors, behaviorsByNodeID[nodes[e].id] ?? [], importMapping)}`)
|
|
347
|
+
.join(', ')}},`;
|
|
272
348
|
}
|
|
273
349
|
else {
|
|
274
350
|
return `\t\t${entry[0]}: ${importMapping.get(nodes[values[0]].type)}${getBehaviorBlockForNode(behaviors, behaviorsByNodeID[nodes[values[0]].id] ?? [], importMapping)},`;
|
|
275
351
|
}
|
|
276
|
-
})
|
|
352
|
+
})
|
|
353
|
+
.join('\n')}
|
|
277
354
|
};
|
|
278
355
|
|
|
279
356
|
animation: ${typeForAnimation(layers)}
|
|
@@ -284,6 +361,12 @@ ${Object.values(props).map(typeOutputForProp).join('\n\n')}
|
|
|
284
361
|
export default Comp;
|
|
285
362
|
`;
|
|
286
363
|
};
|
|
364
|
+
/**
|
|
365
|
+
* Generates a TypeScript type definition for an animation, based on its layer data.
|
|
366
|
+
*
|
|
367
|
+
* @param layers - An object containing layer data.
|
|
368
|
+
* @returns A string representing the TypeScript type for the animation, including layer and clip details.
|
|
369
|
+
*/
|
|
287
370
|
function typeForAnimation(layers) {
|
|
288
371
|
const layersWithScriptNames = Object.values(layers).filter(l => l?.scriptName !== undefined);
|
|
289
372
|
return `Animation & { layers: {
|
|
@@ -299,9 +382,21 @@ ${Object.values(clipsWithScriptNames)
|
|
|
299
382
|
.join('\n')}
|
|
300
383
|
}};`;
|
|
301
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Sanitizes a comment string by removing potentially harmful characters.
|
|
387
|
+
*
|
|
388
|
+
* @param c - The comment string to be sanitized.
|
|
389
|
+
* @returns A safe comment string.
|
|
390
|
+
*/
|
|
302
391
|
function makeCommentSafe(c) {
|
|
303
392
|
return c.replaceAll('*/', '');
|
|
304
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Generates JSDoc comments for a given property.
|
|
396
|
+
*
|
|
397
|
+
* @param prop - The property for which to generate JSDoc comments.
|
|
398
|
+
* @returns A string containing the JSDoc comments for the property.
|
|
399
|
+
*/
|
|
305
400
|
function getJSDocForProp(prop) {
|
|
306
401
|
let lines = [];
|
|
307
402
|
for (const comment of prop.comments ?? []) {
|
|
@@ -327,14 +422,32 @@ function getJSDocForProp(prop) {
|
|
|
327
422
|
lines = lines.map(entry => '\t * ' + entry);
|
|
328
423
|
return `\t/**\n${lines.join('\n')}\n\t */`;
|
|
329
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Generates TypeScript output for a property, including JSDoc comments.
|
|
427
|
+
*
|
|
428
|
+
* @param prop - The property to generate TypeScript output for.
|
|
429
|
+
* @returns A string representing the TypeScript output for the property.
|
|
430
|
+
*/
|
|
330
431
|
function typeOutputForProp(prop) {
|
|
331
432
|
return `${getJSDocForProp(prop)}
|
|
332
433
|
public ${prop.name}: Observable<${outputForType(prop.type, true)}>;`;
|
|
333
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* Generates TypeScript output for a constructor property, including JSDoc comments.
|
|
437
|
+
*
|
|
438
|
+
* @param prop - The constructor property to generate TypeScript output for.
|
|
439
|
+
* @returns A string representing the TypeScript output for the constructor property.
|
|
440
|
+
*/
|
|
334
441
|
function typeOutputForConstructorProp(prop) {
|
|
335
442
|
return `${getJSDocForProp(prop)}
|
|
336
443
|
${prop.name}: ${outputForType(prop.type, true)};`;
|
|
337
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* Sanitizes a key name to ensure it is safe for use in scripting.
|
|
447
|
+
*
|
|
448
|
+
* @param n - The original key name.
|
|
449
|
+
* @returns A sanitized, script-safe key name.
|
|
450
|
+
*/
|
|
338
451
|
export function getSafeKeyName(n) {
|
|
339
452
|
if (n.length === 0)
|
|
340
453
|
return '_';
|
|
@@ -347,6 +460,12 @@ export function getSafeKeyName(n) {
|
|
|
347
460
|
}
|
|
348
461
|
return scriptname;
|
|
349
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* Extracts and groups property tracks by their associated entity ID from a given clip.
|
|
465
|
+
*
|
|
466
|
+
* @param clip - The clip containing property tracks.
|
|
467
|
+
* @returns An object mapping entity IDs to their respective property tracks.
|
|
468
|
+
*/
|
|
350
469
|
export function propertyTracksByEntityID(clip) {
|
|
351
470
|
const ret = Object.create(null);
|
|
352
471
|
for (const track of Object.values(clip.tracks)) {
|
|
@@ -360,10 +479,19 @@ export function propertyTracksByEntityID(clip) {
|
|
|
360
479
|
}
|
|
361
480
|
return ret;
|
|
362
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* Generates a behavior block for a node, based on the behaviors and their IDs.
|
|
484
|
+
*
|
|
485
|
+
* @param behaviors - An object containing behavior data.
|
|
486
|
+
* @param behaviorIDs - An array of behavior IDs.
|
|
487
|
+
* @param importMapping - A map of behavior types to their import names.
|
|
488
|
+
* @returns A string representing the behavior block for the node.
|
|
489
|
+
*/
|
|
363
490
|
export function getBehaviorBlockForNode(behaviors, behaviorIDs, importMapping) {
|
|
364
491
|
return ` & {
|
|
365
492
|
behaviors: {
|
|
366
|
-
${behaviorIDs
|
|
493
|
+
${behaviorIDs
|
|
494
|
+
.map((entry, indx) => {
|
|
367
495
|
const behavior = behaviors[entry];
|
|
368
496
|
if (!behavior)
|
|
369
497
|
return '';
|
|
@@ -372,15 +500,31 @@ ${behaviorIDs.map((entry, indx) => {
|
|
|
372
500
|
if (behavior.parent.scriptName)
|
|
373
501
|
ret.push(`\t\t\t\t${behavior.parent.scriptName}: ${type},`);
|
|
374
502
|
return ret.join('\n');
|
|
375
|
-
})
|
|
503
|
+
})
|
|
504
|
+
.join('\n')}
|
|
376
505
|
}
|
|
377
506
|
}`;
|
|
378
507
|
}
|
|
508
|
+
/**
|
|
509
|
+
* Removes the file extension from an import name, if it ends with '.ts'.
|
|
510
|
+
*
|
|
511
|
+
* @param imp - The import name to process.
|
|
512
|
+
* @returns The import name without the '.ts' extension.
|
|
513
|
+
*/
|
|
379
514
|
export function importNameWithoutExt(imp) {
|
|
380
515
|
if (imp.toLowerCase().endsWith('.ts'))
|
|
381
516
|
return imp.substring(0, imp.length - 3);
|
|
382
517
|
return imp;
|
|
383
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Generates a TypeScript type definition for ZValues.
|
|
521
|
+
*
|
|
522
|
+
* This function creates a type definition script for ZValues based on the values and their associated URL.
|
|
523
|
+
*
|
|
524
|
+
* @param values - The ZValues instance.
|
|
525
|
+
* @param url - The URL associated with the values.
|
|
526
|
+
* @returns A string containing the TypeScript type definition for ZValues.
|
|
527
|
+
*/
|
|
384
528
|
export const typeDefinitionForZValues = (values, url) => {
|
|
385
529
|
const code = [];
|
|
386
530
|
const defaults = VALUES.getTypesAndDefaultsByKey(values);
|
|
@@ -393,6 +537,14 @@ export const typeDefinitionForZValues = (values, url) => {
|
|
|
393
537
|
return `import { Observable } from "@zcomponent/core";
|
|
394
538
|
${code.join('\n')}`;
|
|
395
539
|
};
|
|
540
|
+
/**
|
|
541
|
+
* Generates TypeScript output for a ZValue key.
|
|
542
|
+
*
|
|
543
|
+
* @param keyName - The name of the ZValue key.
|
|
544
|
+
* @param _type - The type of the ZValue.
|
|
545
|
+
* @param defaultValue - The default value for the ZValue.
|
|
546
|
+
* @returns A string representing the TypeScript output for the ZValue key.
|
|
547
|
+
*/
|
|
396
548
|
function typeOutputForZValueKey(keyName, _type, defaultValue) {
|
|
397
549
|
// TODO: Description
|
|
398
550
|
// const description = value.description ? `@description ${JSON.stringify(value.description)}` : '*';
|