@zcomponent/core 1.14.3 → 1.16.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/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/context.d.ts
CHANGED
|
@@ -1,44 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type representing a constructor for a context.
|
|
3
|
+
*
|
|
4
|
+
* It defines a constructor signature for a context with a given set of constructor properties.
|
|
5
|
+
* @typeParam ConstructorProps - The type of the constructor properties, defaulting to a string-indexed object.
|
|
6
|
+
*/
|
|
1
7
|
export type ContextConstructor<ConstructorProps extends {
|
|
2
8
|
[id: string]: any;
|
|
3
9
|
} = {
|
|
4
10
|
[id: string]: any;
|
|
5
11
|
}> = new (contextManager: ContextManager, props: ConstructorProps) => Context<ConstructorProps>;
|
|
12
|
+
/**
|
|
13
|
+
* Type representing the keys of an object that are required.
|
|
14
|
+
*
|
|
15
|
+
* This type extracts the keys from an object type where the corresponding properties are not optional.
|
|
16
|
+
* @typeParam T - The object type to analyze for required keys.
|
|
17
|
+
*/
|
|
6
18
|
type RequiredKeys<T> = {
|
|
7
19
|
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
8
20
|
}[keyof T];
|
|
21
|
+
/**
|
|
22
|
+
* Type representing the constructor properties of a given type.
|
|
23
|
+
*
|
|
24
|
+
* It extracts the constructor properties from a type that has a constructor signature.
|
|
25
|
+
* @typeParam T - The type with a constructor signature to extract the properties from.
|
|
26
|
+
*/
|
|
9
27
|
type ConstructorProps<T> = T extends {
|
|
10
28
|
new (contextManager: ContextManager, props: infer U): any;
|
|
11
29
|
} ? U : never;
|
|
30
|
+
/**
|
|
31
|
+
* Type representing a constructor where all properties are optional.
|
|
32
|
+
*
|
|
33
|
+
* This type filters for constructors where all the constructor properties are optional.
|
|
34
|
+
* @typeParam T - The constructor type to filter.
|
|
35
|
+
*/
|
|
12
36
|
type ConstructorWithOnlyOptional<T> = RequiredKeys<ConstructorProps<T>> extends never ? T : never;
|
|
37
|
+
/**
|
|
38
|
+
* Type representing a constructor with its associated properties.
|
|
39
|
+
*
|
|
40
|
+
* This type creates a tuple consisting of a constructor type and its corresponding properties.
|
|
41
|
+
* @typeParam T - The type of the context constructor.
|
|
42
|
+
*/
|
|
13
43
|
type ConstructorWithProps<T extends ContextConstructor = ContextConstructor> = [T, ConstructorParameters<T>[1]];
|
|
44
|
+
/**
|
|
45
|
+
* Type representing instances of a list of constructors with properties.
|
|
46
|
+
*
|
|
47
|
+
* It maps an array of constructors with properties to their corresponding instance types.
|
|
48
|
+
* @typeParam T - An array type of `ConstructorWithProps`.
|
|
49
|
+
*/
|
|
14
50
|
type InstancesOfConstructorsWithProps<T extends Array<ConstructorWithProps>> = {
|
|
15
51
|
[K in keyof T]: InstanceType<T[K][0]>;
|
|
16
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* The base class for all contexts.
|
|
55
|
+
*
|
|
56
|
+
* Contexts are used to manage and maintain state and functionality that can be shared across different components and behaviors.
|
|
57
|
+
* @typeParam ConstructorPropsType - The type of the constructor properties, defaulting to an empty object.
|
|
58
|
+
*/
|
|
17
59
|
export declare class Context<ConstructorPropsType extends {
|
|
18
60
|
[id: string]: any;
|
|
19
61
|
} = {}> {
|
|
20
62
|
contextManager: ContextManager;
|
|
21
63
|
constructorProps: ConstructorPropsType;
|
|
22
64
|
disposed: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Creates an instance of Context.
|
|
67
|
+
* @param contextManager The current ContextManager
|
|
68
|
+
* @param constructorProps - The constructor properties.
|
|
69
|
+
*/
|
|
23
70
|
constructor(contextManager: ContextManager, constructorProps: ConstructorPropsType);
|
|
24
71
|
dispose(): never;
|
|
25
72
|
private static callSuperDispose;
|
|
26
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Class for managing contexts.
|
|
76
|
+
*
|
|
77
|
+
* This class provides functionality to create, retrieve, and manage contexts.
|
|
78
|
+
*
|
|
79
|
+
* The `ContextManager` is also used to create components, behaviors, and other objects that require a context.
|
|
80
|
+
*/
|
|
27
81
|
export declare class ContextManager {
|
|
28
82
|
private _byKey;
|
|
29
83
|
private _root;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new instance of `ContextManager`.
|
|
86
|
+
*
|
|
87
|
+
* @typeParam T - The type of the context to initialize.
|
|
88
|
+
* @param ctx - The constructor of the context to initialize.
|
|
89
|
+
* @param props - Optional properties to initialize the context.
|
|
90
|
+
* @returns A new instance of `ContextManager`.
|
|
91
|
+
*/
|
|
30
92
|
static create<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: ConstructorWithOnlyOptional<T>): ContextManager;
|
|
31
93
|
static create<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: T, props: ConstructorParameters<T>[1]): ContextManager;
|
|
94
|
+
/**
|
|
95
|
+
* Retrieves an existing context instance or creates a new one if it does not exist.
|
|
96
|
+
*
|
|
97
|
+
* @typeParam T - The type of the context to retrieve or create.
|
|
98
|
+
* @param ctx - The constructor of the context to retrieve or create.
|
|
99
|
+
* @param props - Optional properties to initialize the context if it needs to be created.
|
|
100
|
+
* @returns The retrieved or newly created context instance.
|
|
101
|
+
*/
|
|
32
102
|
get<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: ConstructorWithOnlyOptional<T>): InstanceType<T>;
|
|
33
103
|
get<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: T, props: ConstructorParameters<T>[1]): InstanceType<T>;
|
|
104
|
+
/**
|
|
105
|
+
* Retrieves an existing context instance, or returns undefined if it does not exist.
|
|
106
|
+
*
|
|
107
|
+
* @typeParam T - The type of the context to retrieve.
|
|
108
|
+
* @param ctx - The constructor of the context to retrieve.
|
|
109
|
+
* @returns The retrieved context instance or undefined.
|
|
110
|
+
*/
|
|
34
111
|
getExisting<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: T): InstanceType<T> | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves an existing context or throws an error if it does not exist.
|
|
114
|
+
*
|
|
115
|
+
* @typeParam T - The type of the context to retrieve.
|
|
116
|
+
* @param ctx - The constructor of the context to retrieve.
|
|
117
|
+
* @returns The retrieved context instance.
|
|
118
|
+
* @throws Error if the required context is not present.
|
|
119
|
+
*/
|
|
35
120
|
getOrThrow<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: T): InstanceType<T>;
|
|
121
|
+
/**
|
|
122
|
+
* Adds a context to the `ContextManager`.
|
|
123
|
+
*
|
|
124
|
+
* @typeParam T - The type of the context to add.
|
|
125
|
+
* @param ctx - The constructor of the context to add.
|
|
126
|
+
* @param props - Properties to initialize the context.
|
|
127
|
+
* @returns The newly added context instance.
|
|
128
|
+
*/
|
|
36
129
|
add<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: ConstructorWithOnlyOptional<T>): InstanceType<T>;
|
|
37
130
|
add<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: T, props: ConstructorParameters<T>[1]): InstanceType<T>;
|
|
131
|
+
/**
|
|
132
|
+
* Creates a fork of the `ContextManager` with a specific context added.
|
|
133
|
+
*
|
|
134
|
+
* @typeParam T - The type of the context to fork.
|
|
135
|
+
* @param ctx - The constructor of the context to add.
|
|
136
|
+
* @param props - Optional properties to initialize the context.
|
|
137
|
+
* @returns A tuple containing the forked `ContextManager` and the newly added context instance.
|
|
138
|
+
*/
|
|
38
139
|
fork<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: ConstructorWithOnlyOptional<T>): [ContextManager, InstanceType<T>];
|
|
39
140
|
fork<T extends new (contextManager: ContextManager, props: {}) => any>(ctx: T, props: ConstructorParameters<T>[1]): [ContextManager, InstanceType<T>];
|
|
141
|
+
/**
|
|
142
|
+
* Factory function for creating new instances of a given context type, along with associated properties.
|
|
143
|
+
*
|
|
144
|
+
* @typeParam T - An array type representing a combination of a constructor and its corresponding properties.
|
|
145
|
+
* @returns An array where each element is a tuple, with the first element being the context manager and the second being the instance created by the constructor.
|
|
146
|
+
*/
|
|
40
147
|
forkMultiple<T extends ConstructorWithProps[]>(...ctx: T): [ContextManager, InstancesOfConstructorsWithProps<T>];
|
|
148
|
+
/**
|
|
149
|
+
* Creates a new forked `ContextManager` instance with a shallow copy of the current context.
|
|
150
|
+
*
|
|
151
|
+
* @returns A new `ContextManager` instance forked from the current context.
|
|
152
|
+
*/
|
|
41
153
|
emptyFork(): ContextManager;
|
|
154
|
+
/**
|
|
155
|
+
* Deletes a context from the manager.
|
|
156
|
+
*
|
|
157
|
+
* @param ctx - The constructor of the context to delete.
|
|
158
|
+
*/
|
|
42
159
|
delete(ctx: ContextConstructor): void;
|
|
43
160
|
private _keyForContext;
|
|
44
161
|
}
|
package/lib/context.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
let _nextContextKey = 1;
|
|
2
|
+
/**
|
|
3
|
+
* The base class for all contexts.
|
|
4
|
+
*
|
|
5
|
+
* Contexts are used to manage and maintain state and functionality that can be shared across different components and behaviors.
|
|
6
|
+
* @typeParam ConstructorPropsType - The type of the constructor properties, defaulting to an empty object.
|
|
7
|
+
*/
|
|
2
8
|
export class Context {
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of Context.
|
|
11
|
+
* @param contextManager The current ContextManager
|
|
12
|
+
* @param constructorProps - The constructor properties.
|
|
13
|
+
*/
|
|
3
14
|
constructor(contextManager, constructorProps) {
|
|
4
15
|
this.contextManager = contextManager;
|
|
5
16
|
this.constructorProps = constructorProps;
|
|
@@ -12,6 +23,13 @@ export class Context {
|
|
|
12
23
|
}
|
|
13
24
|
Context.callSuperDispose = Symbol('Calling super.dispose() is mandatory');
|
|
14
25
|
const keysByType = new Map();
|
|
26
|
+
/**
|
|
27
|
+
* Class for managing contexts.
|
|
28
|
+
*
|
|
29
|
+
* This class provides functionality to create, retrieve, and manage contexts.
|
|
30
|
+
*
|
|
31
|
+
* The `ContextManager` is also used to create components, behaviors, and other objects that require a context.
|
|
32
|
+
*/
|
|
15
33
|
export class ContextManager {
|
|
16
34
|
constructor() {
|
|
17
35
|
this._byKey = {};
|
|
@@ -29,14 +47,29 @@ export class ContextManager {
|
|
|
29
47
|
return this.add(ctx, props);
|
|
30
48
|
return entry ?? this.add(ctx, props);
|
|
31
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves an existing context instance, or returns undefined if it does not exist.
|
|
52
|
+
*
|
|
53
|
+
* @typeParam T - The type of the context to retrieve.
|
|
54
|
+
* @param ctx - The constructor of the context to retrieve.
|
|
55
|
+
* @returns The retrieved context instance or undefined.
|
|
56
|
+
*/
|
|
32
57
|
getExisting(ctx) {
|
|
33
58
|
const key = this._keyForContext(ctx);
|
|
34
59
|
return this._byKey[key];
|
|
35
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves an existing context or throws an error if it does not exist.
|
|
63
|
+
*
|
|
64
|
+
* @typeParam T - The type of the context to retrieve.
|
|
65
|
+
* @param ctx - The constructor of the context to retrieve.
|
|
66
|
+
* @returns The retrieved context instance.
|
|
67
|
+
* @throws Error if the required context is not present.
|
|
68
|
+
*/
|
|
36
69
|
getOrThrow(ctx) {
|
|
37
70
|
const entry = this.getExisting(ctx);
|
|
38
71
|
if (!entry)
|
|
39
|
-
throw new Error(
|
|
72
|
+
throw new Error('Required context not present');
|
|
40
73
|
return entry;
|
|
41
74
|
}
|
|
42
75
|
add(ctx, props) {
|
|
@@ -54,6 +87,12 @@ export class ContextManager {
|
|
|
54
87
|
ret._byKey[key] = instance;
|
|
55
88
|
return [ret, instance];
|
|
56
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Factory function for creating new instances of a given context type, along with associated properties.
|
|
92
|
+
*
|
|
93
|
+
* @typeParam T - An array type representing a combination of a constructor and its corresponding properties.
|
|
94
|
+
* @returns An array where each element is a tuple, with the first element being the context manager and the second being the instance created by the constructor.
|
|
95
|
+
*/
|
|
57
96
|
forkMultiple(...ctx) {
|
|
58
97
|
const ret = new ContextManager();
|
|
59
98
|
ret._root = this._root;
|
|
@@ -67,11 +106,21 @@ export class ContextManager {
|
|
|
67
106
|
}
|
|
68
107
|
return [ret, instances];
|
|
69
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new forked `ContextManager` instance with a shallow copy of the current context.
|
|
111
|
+
*
|
|
112
|
+
* @returns A new `ContextManager` instance forked from the current context.
|
|
113
|
+
*/
|
|
70
114
|
emptyFork() {
|
|
71
115
|
const ret = new ContextManager();
|
|
72
116
|
ret._byKey = Object.create(this._byKey);
|
|
73
117
|
return ret;
|
|
74
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Deletes a context from the manager.
|
|
121
|
+
*
|
|
122
|
+
* @param ctx - The constructor of the context to delete.
|
|
123
|
+
*/
|
|
75
124
|
delete(ctx) {
|
|
76
125
|
const key = this._keyForContext(ctx);
|
|
77
126
|
const existing = this._byKey[key];
|
|
@@ -87,73 +136,3 @@ export class ContextManager {
|
|
|
87
136
|
return key;
|
|
88
137
|
}
|
|
89
138
|
}
|
|
90
|
-
// export function defineContextType<T extends {}>(): ContextType<T>;
|
|
91
|
-
// export function defineContextType<T extends {}, Args extends Array<any> = []>(def: (ctx: ContextManager, ...args: Args) => T): ContextTypeWithDefault<T, Args>;
|
|
92
|
-
// export function defineContextType<T extends {}, Args extends Array<any> = []>(def?: (ctx: ContextManager, ...args: Args) => T): ContextType<T> | ContextTypeWithDefault<T, Args> {
|
|
93
|
-
// _nextContextKey++;
|
|
94
|
-
// if (def) {
|
|
95
|
-
// return {
|
|
96
|
-
// key: _nextContextKey.toString(),
|
|
97
|
-
// hasDefault: def !== undefined,
|
|
98
|
-
// def,
|
|
99
|
-
// }
|
|
100
|
-
// } else return {
|
|
101
|
-
// key: _nextContextKey.toString(),
|
|
102
|
-
// hasDefault: false
|
|
103
|
-
// }
|
|
104
|
-
// }
|
|
105
|
-
// export class ContextManager {
|
|
106
|
-
// private _byKey: { [id: string]: unknown | undefined } = {};
|
|
107
|
-
// private _root: ContextManager = this;
|
|
108
|
-
// constructor() {
|
|
109
|
-
// }
|
|
110
|
-
// static create(): ContextManager;
|
|
111
|
-
// static create<T extends {}>(type: ContextType<T>, props: T): ContextManager;
|
|
112
|
-
// static create<T extends {}, Args extends Array<any>>(type: ContextTypeWithDefault<T, Args>, ...args: Args): ContextManager;
|
|
113
|
-
// static create<T extends {}, Args extends Array<any>>(type?: ContextType<T> | ContextTypeWithDefault<T, Args>, ...args: Args): ContextManager {
|
|
114
|
-
// const ctx = new ContextManager();
|
|
115
|
-
// if (type) {
|
|
116
|
-
// if (type.hasDefault) ctx.add(type, ...args);
|
|
117
|
-
// else ctx.add(type, args[0]);
|
|
118
|
-
// }
|
|
119
|
-
// return ctx;
|
|
120
|
-
// }
|
|
121
|
-
// add<T extends {}>(type: ContextType<T>, obj: T): T;
|
|
122
|
-
// add<T extends {}, Args extends Array<any>>(type: ContextTypeWithDefault<T, Args>, ...args: Args): T;
|
|
123
|
-
// add<T extends {}, Args extends Array<any>>(type: ContextType<T> | ContextTypeWithDefault<T, Args>, ...args: Args): T {
|
|
124
|
-
// const root = this._root;
|
|
125
|
-
// const t = type.hasDefault ? type.def(root, ...args) : args[0] as T;
|
|
126
|
-
// root._byKey[type.key] = t;
|
|
127
|
-
// return t;
|
|
128
|
-
// }
|
|
129
|
-
// fork<T extends {}>(type: ContextType<T>, obj: T): [ContextManager, T];
|
|
130
|
-
// fork<T extends {}, Args extends Array<any>>(type: ContextTypeWithDefault<T, Args>, ...args: Args): [ContextManager, T];
|
|
131
|
-
// fork<T extends {}, Args extends Array<any>>(type: ContextType<T> | ContextTypeWithDefault<T, Args>, ...args: Args): [ContextManager, T] {
|
|
132
|
-
// const ret = new ContextManager();
|
|
133
|
-
// ret._root = this._root;
|
|
134
|
-
// ret._byKey = Object.create(this._byKey);
|
|
135
|
-
// const t = type.hasDefault ? type.def(ret, ...args) : args[0] as T;
|
|
136
|
-
// ret._byKey[type.key] = t;
|
|
137
|
-
// return [ret, t];
|
|
138
|
-
// }
|
|
139
|
-
// get<T extends {}>(type: ContextType<T>): T | undefined;
|
|
140
|
-
// get<T extends {}, Args extends Array<any>>(type: ContextTypeWithDefault<T, Args>, ...args: Args): T;
|
|
141
|
-
// get<T extends {}, Args extends Array<any>>(type: ContextType<T> | ContextTypeWithDefault<T, Args>, ...args: Args): T | undefined {
|
|
142
|
-
// let entry = this._byKey[type.key] as T | undefined;
|
|
143
|
-
// if (!entry && type.hasDefault) {
|
|
144
|
-
// entry = this.add(type, ...args);
|
|
145
|
-
// }
|
|
146
|
-
// return entry;
|
|
147
|
-
// }
|
|
148
|
-
// getExisting<T extends {}, Args extends Array<any>>(type: ContextType<T> | ContextTypeWithDefault<T, Args>): T | undefined {
|
|
149
|
-
// return this._byKey[type.key] as T | undefined;
|
|
150
|
-
// }
|
|
151
|
-
// getOrThrow<T extends {}, Args extends Array<any>>(type: ContextType<T> | ContextTypeWithDefault<T, Args>): T {
|
|
152
|
-
// const res = this._byKey[type.key] as T | undefined;
|
|
153
|
-
// if (!res) throw new Error("Required context not present");
|
|
154
|
-
// return res;
|
|
155
|
-
// }
|
|
156
|
-
// delete<T extends {}, Args extends Array<any>>(type: ContextType<T> | ContextTypeWithDefault<T, Args>) {
|
|
157
|
-
// delete this._byKey[type.key];
|
|
158
|
-
// }
|
|
159
|
-
// }
|
|
@@ -6,5 +6,11 @@ export declare class AnalyticsContext extends Context {
|
|
|
6
6
|
/** @zprop */
|
|
7
7
|
logEvent(name: string, params?: any): void;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Logs an analytics event.
|
|
11
|
+
*/
|
|
9
12
|
export declare function logEvent(mgr: ContextManager, name: string, params?: any): void;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the analytics onEvent event.
|
|
15
|
+
*/
|
|
10
16
|
export declare function useAnalyticsOnEvent(mgr: ContextManager): Event<[string, any]>;
|
|
@@ -11,9 +11,15 @@ export class AnalyticsContext extends Context {
|
|
|
11
11
|
this.onEvent.emit(name, params);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Logs an analytics event.
|
|
16
|
+
*/
|
|
14
17
|
export function logEvent(mgr, name, params) {
|
|
15
18
|
return mgr.get(AnalyticsContext).logEvent(name, params);
|
|
16
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns the analytics onEvent event.
|
|
22
|
+
*/
|
|
17
23
|
export function useAnalyticsOnEvent(mgr) {
|
|
18
24
|
return mgr.get(AnalyticsContext).onEvent;
|
|
19
25
|
}
|
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
import { ContextManager, Context } from '../context';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A context dedicated to audio management.
|
|
4
|
+
* @zcontext
|
|
5
|
+
*/
|
|
3
6
|
export declare class AudioContextContext extends Context {
|
|
4
7
|
constructorProps: {};
|
|
5
8
|
readonly audioContext: AudioContext;
|
|
6
9
|
private _layers;
|
|
7
10
|
readonly layers: Map<string, AudioNode>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of AudioContextContext.
|
|
13
|
+
* @param contextManager - The current ContextManager
|
|
14
|
+
* @param constructorProps - The constructor properties.
|
|
15
|
+
*/
|
|
8
16
|
constructor(contextManager: ContextManager, constructorProps: {});
|
|
9
17
|
private _getLayer;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves an audio layer by its name.
|
|
20
|
+
* @param {string} [name] - The name of the audio layer.
|
|
21
|
+
* @returns {AudioNode} The audio layer.
|
|
22
|
+
*/
|
|
10
23
|
getLayer(name?: string): AudioNode;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the volume for a specific audio layer.
|
|
26
|
+
* @param {string} [name] - The name of the audio layer.
|
|
27
|
+
* @param {number} v - The new volume level.
|
|
28
|
+
*/
|
|
11
29
|
setVolumeForLayer(name: string | undefined, v: number): void;
|
|
30
|
+
/**
|
|
31
|
+
* Disposes of the audio context and calls the parent dispose method.
|
|
32
|
+
* @returns {Promise<boolean>} A promise that resolves to a boolean indicating whether the disposal was successful.
|
|
33
|
+
*/
|
|
12
34
|
dispose(): never;
|
|
13
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the audio context.
|
|
38
|
+
*/
|
|
14
39
|
export declare function useAudioContext(ctx: ContextManager): AudioContext;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { Context } from '../context';
|
|
2
2
|
import { nextUserEvent } from './usereventcontext';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* A context dedicated to audio management.
|
|
5
|
+
* @zcontext
|
|
6
|
+
*/
|
|
4
7
|
export class AudioContextContext extends Context {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of AudioContextContext.
|
|
10
|
+
* @param contextManager - The current ContextManager
|
|
11
|
+
* @param constructorProps - The constructor properties.
|
|
12
|
+
*/
|
|
5
13
|
constructor(contextManager, constructorProps) {
|
|
6
14
|
super(contextManager, constructorProps);
|
|
7
15
|
this.constructorProps = constructorProps;
|
|
@@ -21,18 +29,35 @@ export class AudioContextContext extends Context {
|
|
|
21
29
|
}
|
|
22
30
|
return existing;
|
|
23
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves an audio layer by its name.
|
|
34
|
+
* @param {string} [name] - The name of the audio layer.
|
|
35
|
+
* @returns {AudioNode} The audio layer.
|
|
36
|
+
*/
|
|
24
37
|
getLayer(name) {
|
|
25
38
|
return this._getLayer(name);
|
|
26
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the volume for a specific audio layer.
|
|
42
|
+
* @param {string} [name] - The name of the audio layer.
|
|
43
|
+
* @param {number} v - The new volume level.
|
|
44
|
+
*/
|
|
27
45
|
setVolumeForLayer(name, v) {
|
|
28
46
|
const layer = this._getLayer(name);
|
|
29
47
|
layer.gain.value = v;
|
|
30
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Disposes of the audio context and calls the parent dispose method.
|
|
51
|
+
* @returns {Promise<boolean>} A promise that resolves to a boolean indicating whether the disposal was successful.
|
|
52
|
+
*/
|
|
31
53
|
dispose() {
|
|
32
54
|
this.audioContext.close();
|
|
33
55
|
return super.dispose();
|
|
34
56
|
}
|
|
35
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the audio context.
|
|
60
|
+
*/
|
|
36
61
|
export function useAudioContext(ctx) {
|
|
37
62
|
return ctx.get(AudioContextContext).audioContext;
|
|
38
63
|
}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { ContextManager, Context } from '../context';
|
|
2
2
|
import { Event } from '../event';
|
|
3
3
|
import { Observable } from '../observable';
|
|
4
|
+
/**
|
|
5
|
+
* Defines options for initializing a `CanvasContext`.
|
|
6
|
+
* - `canvas`: Optional HTMLCanvasElement to be managed.
|
|
7
|
+
* - `overlay`: Optional HTMLDivElement to be used as an overlay.
|
|
8
|
+
*/
|
|
4
9
|
export interface CanvasContextOptions {
|
|
5
10
|
canvas?: HTMLCanvasElement;
|
|
6
11
|
overlay?: HTMLDivElement;
|
|
7
12
|
}
|
|
8
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Manages a canvas and an overlay within a context, providing events and observables for canvas rendering and resizing.
|
|
15
|
+
* - `onBeforeRender`: Event triggered before rendering the canvas.
|
|
16
|
+
* - `onAfterRender`: Event triggered after rendering the canvas.
|
|
17
|
+
* - `canvas`: The HTMLCanvasElement being managed.
|
|
18
|
+
* - `overlayDefault`: Default HTMLDivElement used as an overlay.
|
|
19
|
+
* - `overlay`: Observable for the overlay element.
|
|
20
|
+
* - `size`: Observable for the canvas size, updated on resize.
|
|
21
|
+
* @zcontext
|
|
22
|
+
* */
|
|
9
23
|
export declare class CanvasContext extends Context {
|
|
10
24
|
constructorProps: CanvasContextOptions;
|
|
11
25
|
readonly onBeforeRender: Event<[number]>;
|
|
@@ -16,6 +30,11 @@ export declare class CanvasContext extends Context {
|
|
|
16
30
|
/** @zui */
|
|
17
31
|
readonly size: Observable<[number, number]>;
|
|
18
32
|
private _resizeObserver;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance of CanvasContext.
|
|
35
|
+
* @param contextManager - The current ContextManager
|
|
36
|
+
* @param constructorProps - The constructor properties.
|
|
37
|
+
*/
|
|
19
38
|
constructor(contextManager: ContextManager, constructorProps: CanvasContextOptions);
|
|
20
39
|
/**
|
|
21
40
|
* Captures the canvas content and returns it as a Data URL after the current frame has rendered.
|
|
@@ -33,20 +52,53 @@ export declare class CanvasContext extends Context {
|
|
|
33
52
|
private blobToArrayBuffer;
|
|
34
53
|
dispose(): never;
|
|
35
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Enum representing horizontal alignment options: 'left', 'center', 'right'.
|
|
57
|
+
*/
|
|
36
58
|
export declare enum HorizontalAlignment {
|
|
37
59
|
'left' = "left",
|
|
38
60
|
'center' = "center",
|
|
39
61
|
'right' = "right"
|
|
40
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Enum representing vertical alignment options: 'top', 'center', 'bottom'.
|
|
65
|
+
*/
|
|
41
66
|
export declare enum VerticalAlignment {
|
|
42
67
|
'top' = "top",
|
|
43
68
|
'center' = "center",
|
|
44
69
|
'bottom' = "bottom"
|
|
45
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves the canvas element from the `CanvasContext`.
|
|
73
|
+
* @param {ContextManager} mgr The context manager instance.
|
|
74
|
+
* @returns {HTMLCanvasElement} The canvas element managed by `CanvasContext`.
|
|
75
|
+
*/
|
|
46
76
|
export declare function useCanvas(mgr: ContextManager): HTMLCanvasElement;
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves the overlay element from the `CanvasContext`.
|
|
79
|
+
* @param {ContextManager} mgr The context manager instance.
|
|
80
|
+
* @returns {Observable<HTMLDivElement>} The overlay element as an observable managed by `CanvasContext`.
|
|
81
|
+
*/
|
|
47
82
|
export declare function useOverlay(mgr: ContextManager): Observable<HTMLDivElement, never>;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the size of the canvas from the `CanvasContext`.
|
|
85
|
+
* @param {ContextManager} mgr - The context manager.
|
|
86
|
+
* @returns {Size} The size of the canvas.
|
|
87
|
+
*/
|
|
48
88
|
export declare function useCanvasSize(mgr: ContextManager): Observable<[number, number], never>;
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the onBeforeRender event from the `CanvasContext`. This event is fired before the canvas is rendered.
|
|
91
|
+
*
|
|
92
|
+
* `this.register(useOnBeforeRender(this.contextManager), ()=>{ });`
|
|
93
|
+
* @param {ContextManager} mgr - The context manager.
|
|
94
|
+
* @returns {Function} The onBeforeRender function.
|
|
95
|
+
*/
|
|
49
96
|
export declare function useOnBeforeRender(mgr: ContextManager): Event<[number]>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves the onAfterRender event from the `CanvasContext`.
|
|
99
|
+
* @param {ContextManager} mgr The context manager instance.
|
|
100
|
+
* @returns {Event<[number]>} The onAfterRender event, triggered after canvas rendering.
|
|
101
|
+
*/
|
|
50
102
|
export declare function useOnAfterRender(mgr: ContextManager): Event<[number]>;
|
|
51
103
|
/**
|
|
52
104
|
* Returns a promise that resovles a data url of the canvas as jpeg.
|
|
@@ -60,4 +112,10 @@ export declare function useCanvasToDataURL(mgr: ContextManager): Promise<string>
|
|
|
60
112
|
* For custom MIME types or quality settings, use`contextManager.get(CanvasContext).captureToArrayBuffer();`
|
|
61
113
|
*/
|
|
62
114
|
export declare function useCanvasToArrayBuffer(mgr: ContextManager): Promise<ArrayBuffer>;
|
|
115
|
+
/**
|
|
116
|
+
* Generates class names for alignment based on specified horizontal and vertical alignment values.
|
|
117
|
+
* @param {HorizontalAlignment} h The horizontal alignment value.
|
|
118
|
+
* @param {VerticalAlignment} v The vertical alignment value.
|
|
119
|
+
* @returns {string} A string of class names for the specified alignments.
|
|
120
|
+
*/
|
|
63
121
|
export declare function classNameForAlignment(h: HorizontalAlignment, v: VerticalAlignment): string;
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { Context } from '../context';
|
|
2
2
|
import { Event } from '../event';
|
|
3
3
|
import { Observable } from '../observable';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Manages a canvas and an overlay within a context, providing events and observables for canvas rendering and resizing.
|
|
6
|
+
* - `onBeforeRender`: Event triggered before rendering the canvas.
|
|
7
|
+
* - `onAfterRender`: Event triggered after rendering the canvas.
|
|
8
|
+
* - `canvas`: The HTMLCanvasElement being managed.
|
|
9
|
+
* - `overlayDefault`: Default HTMLDivElement used as an overlay.
|
|
10
|
+
* - `overlay`: Observable for the overlay element.
|
|
11
|
+
* - `size`: Observable for the canvas size, updated on resize.
|
|
12
|
+
* @zcontext
|
|
13
|
+
* */
|
|
5
14
|
export class CanvasContext extends Context {
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of CanvasContext.
|
|
17
|
+
* @param contextManager - The current ContextManager
|
|
18
|
+
* @param constructorProps - The constructor properties.
|
|
19
|
+
*/
|
|
6
20
|
constructor(contextManager, constructorProps) {
|
|
7
21
|
super(contextManager, constructorProps);
|
|
8
22
|
this.constructorProps = constructorProps;
|
|
@@ -107,30 +121,63 @@ export class CanvasContext extends Context {
|
|
|
107
121
|
return super.dispose();
|
|
108
122
|
}
|
|
109
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Enum representing horizontal alignment options: 'left', 'center', 'right'.
|
|
126
|
+
*/
|
|
110
127
|
export var HorizontalAlignment;
|
|
111
128
|
(function (HorizontalAlignment) {
|
|
112
129
|
HorizontalAlignment["left"] = "left";
|
|
113
130
|
HorizontalAlignment["center"] = "center";
|
|
114
131
|
HorizontalAlignment["right"] = "right";
|
|
115
132
|
})(HorizontalAlignment || (HorizontalAlignment = {}));
|
|
133
|
+
/**
|
|
134
|
+
* Enum representing vertical alignment options: 'top', 'center', 'bottom'.
|
|
135
|
+
*/
|
|
116
136
|
export var VerticalAlignment;
|
|
117
137
|
(function (VerticalAlignment) {
|
|
118
138
|
VerticalAlignment["top"] = "top";
|
|
119
139
|
VerticalAlignment["center"] = "center";
|
|
120
140
|
VerticalAlignment["bottom"] = "bottom";
|
|
121
141
|
})(VerticalAlignment || (VerticalAlignment = {}));
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves the canvas element from the `CanvasContext`.
|
|
144
|
+
* @param {ContextManager} mgr The context manager instance.
|
|
145
|
+
* @returns {HTMLCanvasElement} The canvas element managed by `CanvasContext`.
|
|
146
|
+
*/
|
|
122
147
|
export function useCanvas(mgr) {
|
|
123
148
|
return mgr.get(CanvasContext).canvas;
|
|
124
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Retrieves the overlay element from the `CanvasContext`.
|
|
152
|
+
* @param {ContextManager} mgr The context manager instance.
|
|
153
|
+
* @returns {Observable<HTMLDivElement>} The overlay element as an observable managed by `CanvasContext`.
|
|
154
|
+
*/
|
|
125
155
|
export function useOverlay(mgr) {
|
|
126
156
|
return mgr.get(CanvasContext).overlay;
|
|
127
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves the size of the canvas from the `CanvasContext`.
|
|
160
|
+
* @param {ContextManager} mgr - The context manager.
|
|
161
|
+
* @returns {Size} The size of the canvas.
|
|
162
|
+
*/
|
|
128
163
|
export function useCanvasSize(mgr) {
|
|
129
164
|
return mgr.get(CanvasContext).size;
|
|
130
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Retrieves the onBeforeRender event from the `CanvasContext`. This event is fired before the canvas is rendered.
|
|
168
|
+
*
|
|
169
|
+
* `this.register(useOnBeforeRender(this.contextManager), ()=>{ });`
|
|
170
|
+
* @param {ContextManager} mgr - The context manager.
|
|
171
|
+
* @returns {Function} The onBeforeRender function.
|
|
172
|
+
*/
|
|
131
173
|
export function useOnBeforeRender(mgr) {
|
|
132
174
|
return mgr.get(CanvasContext).onBeforeRender;
|
|
133
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Retrieves the onAfterRender event from the `CanvasContext`.
|
|
178
|
+
* @param {ContextManager} mgr The context manager instance.
|
|
179
|
+
* @returns {Event<[number]>} The onAfterRender event, triggered after canvas rendering.
|
|
180
|
+
*/
|
|
134
181
|
export function useOnAfterRender(mgr) {
|
|
135
182
|
return mgr.get(CanvasContext).onAfterRender;
|
|
136
183
|
}
|
|
@@ -150,6 +197,12 @@ export function useCanvasToDataURL(mgr) {
|
|
|
150
197
|
export function useCanvasToArrayBuffer(mgr) {
|
|
151
198
|
return mgr.get(CanvasContext).captureToArrayBuffer('image/jpeg', 1);
|
|
152
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Generates class names for alignment based on specified horizontal and vertical alignment values.
|
|
202
|
+
* @param {HorizontalAlignment} h The horizontal alignment value.
|
|
203
|
+
* @param {VerticalAlignment} v The vertical alignment value.
|
|
204
|
+
* @returns {string} A string of class names for the specified alignments.
|
|
205
|
+
*/
|
|
153
206
|
export function classNameForAlignment(h, v) {
|
|
154
207
|
const names = ['zcomponent-align'];
|
|
155
208
|
switch (h) {
|