@zcomponent/core 1.29.0 → 2.0.0-alpha.2
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 +1 -0
- package/css/zcomponent.css +121 -122
- package/index.js +0 -3
- package/lib/actionbehavior.d.ts +3 -3
- package/lib/actionbehavior.js +20 -19
- package/lib/animation/animation.d.ts +13 -6
- package/lib/animation/animation.js +56 -43
- package/lib/animation/bezier.d.ts +6 -0
- package/lib/animation/bezier.js +8 -2
- package/lib/animation/clips/clip.d.ts +13 -1
- package/lib/animation/clips/clip.js +34 -14
- package/lib/animation/index.d.ts +4 -4
- package/lib/animation/index.js +4 -4
- package/lib/animation/layer.d.ts +9 -0
- package/lib/animation/layer.js +28 -12
- package/lib/animation/layerclip.d.ts +21 -0
- package/lib/animation/layerclip.js +82 -45
- package/lib/animation/tracks/cliptrack.d.ts +18 -0
- package/lib/animation/tracks/cliptrack.js +27 -6
- package/lib/animation/tracks/functiontrack.d.ts +9 -0
- package/lib/animation/tracks/functiontrack.js +16 -3
- package/lib/animation/tracks/propertytrack.d.ts +20 -1
- package/lib/animation/tracks/propertytrack.js +48 -11
- package/lib/animation/tracks/streamtrack.d.ts +18 -0
- package/lib/animation/tracks/streamtrack.js +32 -6
- package/lib/animation/tracks/track.d.ts +8 -2
- package/lib/animation/tracks/track.js +3 -2
- package/lib/behavior.js +13 -10
- package/lib/behaviors/ActivateState.d.ts +22 -24
- package/lib/behaviors/ActivateState.js +145 -35
- package/lib/behaviors/CallFunction.d.ts +2 -4
- package/lib/behaviors/CallFunction.js +69 -11
- package/lib/behaviors/ChangeRootScene.d.ts +35 -0
- package/lib/behaviors/ChangeRootScene.js +123 -0
- package/lib/behaviors/ConsoleLog.d.ts +6 -5
- package/lib/behaviors/ConsoleLog.js +95 -12
- package/lib/behaviors/DownloadSnapshot.d.ts +7 -12
- package/lib/behaviors/DownloadSnapshot.js +70 -19
- package/lib/behaviors/EmitComponentPropEvent.d.ts +1 -3
- package/lib/behaviors/EmitComponentPropEvent.js +80 -12
- package/lib/behaviors/LaunchURL.d.ts +5 -5
- package/lib/behaviors/LaunchURL.js +92 -10
- package/lib/behaviors/LogAnalyticsEvent.d.ts +10 -4
- package/lib/behaviors/LogAnalyticsEvent.js +88 -7
- package/lib/behaviors/PauseLayerClip.d.ts +7 -9
- package/lib/behaviors/PauseLayerClip.js +89 -21
- package/lib/behaviors/PlayLayerClip.d.ts +35 -32
- package/lib/behaviors/PlayLayerClip.js +202 -48
- package/lib/behaviors/PlaySound.d.ts +19 -25
- package/lib/behaviors/PlaySound.js +122 -28
- package/lib/behaviors/SetLayerOff.d.ts +7 -9
- package/lib/behaviors/SetLayerOff.js +88 -21
- package/lib/behaviors/ShareSnapshot.d.ts +5 -9
- package/lib/behaviors/ShareSnapshot.js +70 -17
- package/lib/behaviors/ShowTextAlert.d.ts +16 -29
- package/lib/behaviors/ShowTextAlert.js +116 -48
- package/lib/behaviors/TakeSnapshot.d.ts +22 -26
- package/lib/behaviors/TakeSnapshot.js +131 -56
- package/lib/behaviors/ToggleLayerClips.d.ts +45 -62
- package/lib/behaviors/ToggleLayerClips.js +233 -64
- package/lib/behaviors/stream/PauseStream.d.ts +5 -16
- package/lib/behaviors/stream/PauseStream.js +94 -34
- package/lib/behaviors/stream/PlayStream.d.ts +14 -27
- package/lib/behaviors/stream/PlayStream.js +123 -34
- package/lib/behaviors/stream/SeekStream.d.ts +8 -18
- package/lib/behaviors/stream/SeekStream.js +97 -31
- package/lib/behaviors/stream/StopStream.d.ts +6 -15
- package/lib/behaviors/stream/StopStream.js +89 -27
- package/lib/component.d.ts +36 -13
- package/lib/component.js +237 -151
- package/lib/components/AnimatedLoader.d.ts +51 -0
- package/lib/components/AnimatedLoader.js +159 -0
- package/lib/components/Audio.d.ts +35 -37
- package/lib/components/Audio.js +264 -151
- package/lib/components/AudioLayerSettings.d.ts +13 -11
- package/lib/components/AudioLayerSettings.js +76 -18
- package/lib/components/Children.d.ts +2 -1
- package/lib/components/Children.js +66 -13
- package/lib/components/ConditionalConstruct.d.ts +44 -0
- package/lib/components/ConditionalConstruct.js +142 -0
- package/lib/components/DefaultCookieConsent.d.ts +53 -73
- package/lib/components/DefaultCookieConsent.js +382 -264
- package/lib/components/DefaultLoader.d.ts +40 -28
- package/lib/components/DefaultLoader.js +198 -46
- package/lib/components/Gamepad.d.ts +5 -26
- package/lib/components/Gamepad.js +201 -65
- package/lib/components/LoaderScope.d.ts +15 -0
- package/lib/components/LoaderScope.js +71 -0
- package/lib/components/LongLoad.d.ts +11 -15
- package/lib/components/LongLoad.js +89 -34
- package/lib/components/SnapshotUI.d.ts +19 -24
- package/lib/components/SnapshotUI.js +202 -105
- package/lib/context.d.ts +23 -5
- package/lib/context.js +12 -6
- package/lib/contexts/analyticscontext.d.ts +12 -2
- package/lib/contexts/analyticscontext.js +68 -10
- package/lib/contexts/audiocontextcontext.d.ts +1 -1
- package/lib/contexts/audiocontextcontext.js +9 -8
- package/lib/contexts/canvascontext.d.ts +32 -18
- package/lib/contexts/canvascontext.js +195 -120
- package/lib/contexts/cookieconsentcontext.d.ts +38 -28
- package/lib/contexts/cookieconsentcontext.js +35 -32
- package/lib/contexts/documentflagmanager.js +15 -11
- package/lib/contexts/environmentcontext.d.ts +22 -6
- package/lib/contexts/environmentcontext.js +135 -21
- package/lib/contexts/gamepadcontext.d.ts +29 -26
- package/lib/contexts/gamepadcontext.js +46 -46
- package/lib/contexts/gesturecontext.d.ts +31 -6
- package/lib/contexts/gesturecontext.js +110 -85
- package/lib/contexts/globaltagcontext.d.ts +1 -1
- package/lib/contexts/globaltagcontext.js +8 -11
- package/lib/contexts/loadcontext.d.ts +45 -8
- package/lib/contexts/loadcontext.js +232 -82
- package/lib/contexts/orientationcontext.d.ts +13 -15
- package/lib/contexts/orientationcontext.js +150 -67
- package/lib/contexts/rootcomponentscontext.d.ts +16 -0
- package/lib/contexts/rootcomponentscontext.js +65 -0
- package/lib/contexts/snapshotContext.d.ts +0 -3
- package/lib/contexts/snapshotContext.js +78 -23
- package/lib/contexts/tagcontext.d.ts +5 -5
- package/lib/contexts/tagcontext.js +16 -16
- package/lib/contexts/textalertcontext.d.ts +1 -5
- package/lib/contexts/textalertcontext.js +1 -5
- package/lib/contexts/usereventcontext.d.ts +1 -1
- package/lib/contexts/usereventcontext.js +12 -12
- package/lib/data/animation.d.ts +10 -2
- package/lib/data/change.d.ts +1 -1
- package/lib/data/change.js +7 -0
- package/lib/data/core.d.ts +9 -1
- package/lib/data/index.d.ts +1 -1
- package/lib/data/index.js +1 -1
- package/lib/decorators.d.ts +348 -0
- package/lib/decorators.js +239 -0
- package/lib/decoratorutils.d.ts +3 -0
- package/lib/decoratorutils.js +8 -0
- package/lib/emitter.d.ts +15 -2
- package/lib/emitter.js +15 -6
- package/lib/entity.d.ts +43 -25
- package/lib/entity.js +104 -71
- package/lib/event.d.ts +2 -1
- package/lib/event.js +1 -4
- package/lib/groups.d.ts +18 -0
- package/lib/groups.js +19 -0
- package/lib/icons.d.ts +3372 -0
- package/lib/icons.js +1 -0
- package/lib/index.d.ts +18 -13
- package/lib/index.js +17 -13
- package/lib/inflate.d.ts +7 -7
- package/lib/inflate.js +5 -5
- package/lib/observable.d.ts +9 -2
- package/lib/observable.js +5 -4
- package/lib/observe.d.ts +18 -0
- package/lib/observe.js +177 -0
- package/lib/profile.d.ts +9 -5
- package/lib/profile.js +27 -17
- package/lib/selectors.d.ts +1 -1
- package/lib/selectors.js +5 -4
- package/lib/types.d.ts +161 -19
- package/lib/types.js +22 -1
- package/lib/values/values.d.ts +7 -8
- package/lib/values/values.js +1 -2
- package/lib/values/valuesmutator.d.ts +4 -1
- package/lib/values/valuesmutator.js +10 -8
- package/lib/zcomponent.d.ts +21 -10
- package/lib/zcomponent.js +717 -540
- package/package.json +22 -5
- package/lib/behaviors/ChangeCursor.d.ts +0 -39
- package/lib/behaviors/ChangeCursor.js +0 -44
|
@@ -5,18 +5,18 @@ import { Observable } from '../observable';
|
|
|
5
5
|
* Manages and tracks user events within the application context.
|
|
6
6
|
*/
|
|
7
7
|
export class UserEventContext extends Context {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* Event triggered when a user event occurs.
|
|
10
|
+
*/
|
|
11
|
+
onUserEvent = new EventClass();
|
|
12
|
+
_resolveNextUserEvent;
|
|
13
|
+
/**
|
|
14
|
+
* An observable that emits the next user event as a promise.
|
|
15
|
+
* It gets resolved with the event object when a user event occurs.
|
|
16
|
+
*/
|
|
17
|
+
nextUserEvent = new Observable(new Promise(resolve => {
|
|
18
|
+
this._resolveNextUserEvent = resolve;
|
|
19
|
+
}), undefined, false);
|
|
20
20
|
/**
|
|
21
21
|
* Registers and emits a user event.
|
|
22
22
|
* @param evt The user event to register.
|
package/lib/data/animation.d.ts
CHANGED
|
@@ -112,14 +112,22 @@ export type Easing = null | keyof typeof predefinedCurve | string;
|
|
|
112
112
|
/**
|
|
113
113
|
* Type representing a point in a Bezier curve.
|
|
114
114
|
*/
|
|
115
|
-
export type Point = [
|
|
115
|
+
export type Point = [
|
|
116
|
+
number,
|
|
117
|
+
number
|
|
118
|
+
];
|
|
116
119
|
/**
|
|
117
120
|
* Type representing a Bezier curve.
|
|
118
121
|
*
|
|
119
122
|
* @note
|
|
120
123
|
* Bezier represents the four control points between this keyframe and the next
|
|
121
124
|
*/
|
|
122
|
-
export type Bezier = [
|
|
125
|
+
export type Bezier = [
|
|
126
|
+
Point,
|
|
127
|
+
Point,
|
|
128
|
+
Point,
|
|
129
|
+
Point
|
|
130
|
+
];
|
|
123
131
|
/**
|
|
124
132
|
* Type representing a curve, which is a collection of Bezier segments.
|
|
125
133
|
*/
|
package/lib/data/change.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BehaviorByID, BehaviorData, ComputedHierarchy, EntityPropOverride, NodeByID, NodeData, ZComponentData } from './core';
|
|
2
1
|
import { Prop } from '../types';
|
|
2
|
+
import { BehaviorByID, BehaviorData, ComputedHierarchy, EntityPropOverride, NodeByID, NodeData, ZComponentData } from './core';
|
|
3
3
|
/**
|
|
4
4
|
* Computes and memoizes the hierarchy of nodes.
|
|
5
5
|
*
|
package/lib/data/change.js
CHANGED
|
@@ -134,6 +134,11 @@ export function addNode(zcomp, info) {
|
|
|
134
134
|
addNodeScriptNameToRegister(zcomp, info.data.id);
|
|
135
135
|
addEntity(zcomp, info.data.id, info);
|
|
136
136
|
computedHierarchies.delete(zcomp.nodes);
|
|
137
|
+
if (!info.data.parent) {
|
|
138
|
+
if (!zcomp.topLevelComponents)
|
|
139
|
+
zcomp.topLevelComponents = {};
|
|
140
|
+
zcomp.topLevelComponents[info.data.id] = true;
|
|
141
|
+
}
|
|
137
142
|
}
|
|
138
143
|
/**
|
|
139
144
|
* Adds a new behavior to the specified ZComponentData.
|
|
@@ -310,6 +315,8 @@ export function deleteNode(zcomp, id) {
|
|
|
310
315
|
removeNodeLabelFromRegister(zcomp, id);
|
|
311
316
|
removeNodeScriptNameFromRegister(zcomp, id);
|
|
312
317
|
delete zcomp.nodes[id];
|
|
318
|
+
if (zcomp.topLevelComponents)
|
|
319
|
+
delete zcomp.topLevelComponents[id];
|
|
313
320
|
computedHierarchies.delete(zcomp.nodes);
|
|
314
321
|
}
|
|
315
322
|
/**
|
package/lib/data/core.d.ts
CHANGED
|
@@ -22,7 +22,10 @@ export type ComputedHierarchy = {
|
|
|
22
22
|
[id: string]: string[];
|
|
23
23
|
};
|
|
24
24
|
export type Import = string;
|
|
25
|
-
export type ParsedImport = [
|
|
25
|
+
export type ParsedImport = [
|
|
26
|
+
string,
|
|
27
|
+
string
|
|
28
|
+
];
|
|
26
29
|
export type ElementType = Import;
|
|
27
30
|
export type PropType = string;
|
|
28
31
|
export interface ZComponentData {
|
|
@@ -54,6 +57,9 @@ export interface ZComponentData {
|
|
|
54
57
|
tags?: string[];
|
|
55
58
|
allowedParents?: string[];
|
|
56
59
|
comments?: string[];
|
|
60
|
+
topLevelComponents?: {
|
|
61
|
+
[id: string]: boolean;
|
|
62
|
+
};
|
|
57
63
|
}
|
|
58
64
|
export interface NodeData {
|
|
59
65
|
id: string;
|
|
@@ -61,6 +67,8 @@ export interface NodeData {
|
|
|
61
67
|
scriptName?: string;
|
|
62
68
|
type: ElementType;
|
|
63
69
|
locked?: boolean;
|
|
70
|
+
excludeRuntime?: boolean;
|
|
71
|
+
excludeDesignTime?: boolean;
|
|
64
72
|
parent?: {
|
|
65
73
|
id: string;
|
|
66
74
|
order: string;
|
package/lib/data/index.d.ts
CHANGED
package/lib/data/index.js
CHANGED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { Behavior } from './behavior';
|
|
2
|
+
import type { Component } from './component';
|
|
3
|
+
import { Context, ContextManager } from './context';
|
|
4
|
+
import type { Entity, RegisterOptions } from './entity';
|
|
5
|
+
import { Event } from './event';
|
|
6
|
+
import { MaterialSymbol } from './icons';
|
|
7
|
+
import { Observable } from './observable';
|
|
8
|
+
import { TypeHint, ValuesType } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Creates an observable property that automatically triggers a callback when its value changes.
|
|
11
|
+
* This enables reactive programming patterns where property changes can update UI elements,
|
|
12
|
+
* trigger side effects, or synchronize state across components.
|
|
13
|
+
*
|
|
14
|
+
* @decorator
|
|
15
|
+
* @param withHandler - Optional callback function that executes when the property value changes.
|
|
16
|
+
* Receives the new value, the entity instance, and the property name.
|
|
17
|
+
* @param deep - Whether to observe nested object changes (default: true)
|
|
18
|
+
* @returns A property decorator that makes the property observable
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Simple observer that updates element visibility
|
|
23
|
+
* @zObserve((val, instance) => (instance.element.visible = val))
|
|
24
|
+
* public visible = true;
|
|
25
|
+
*
|
|
26
|
+
* // Observer that calls a method on change
|
|
27
|
+
* @zObserve((v, instance: Audio) => {
|
|
28
|
+
* instance._updateVolume();
|
|
29
|
+
* })
|
|
30
|
+
* public muted = false;
|
|
31
|
+
*
|
|
32
|
+
* // Observer without handler (just makes property observable)
|
|
33
|
+
* @zObserve()
|
|
34
|
+
* public position = { x: 0, y: 0, z: 0 };
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function zObserve<EntityType extends Entity, ValueType>(withHandler?: (this: EntityType, v: ValueType, entity: EntityType, propName: string) => void, deep?: boolean): (value: undefined, context: any) => (this: EntityType, initialValue: ValueType) => ValueType;
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for property groups in the Mattercraft UI.
|
|
40
|
+
* Groups help organize related properties under collapsible sections.
|
|
41
|
+
*/
|
|
42
|
+
export interface ZPropGroup {
|
|
43
|
+
/** The display name of the group in the UI */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Display order priority - higher values appear first */
|
|
46
|
+
priority?: number;
|
|
47
|
+
/** Whether the group should be collapsed by default */
|
|
48
|
+
collapsed?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Configuration options for properties exposed to the Mattercraft UI.
|
|
52
|
+
*/
|
|
53
|
+
export interface ZPropOptions {
|
|
54
|
+
/** Property group - either a string name or full group configuration */
|
|
55
|
+
group?: string | ZPropGroup;
|
|
56
|
+
/** Display order priority within the group - higher values appear first */
|
|
57
|
+
priority?: number;
|
|
58
|
+
/** UI widget type (e.g., 'proportion', 'color-hex', 'angle-degrees', 'time-seconds') */
|
|
59
|
+
type?: keyof typeof TypeHint;
|
|
60
|
+
/** Constrains values to specific types (e.g., 'layerclipids', 'streamids', 'easings') */
|
|
61
|
+
values?: keyof typeof ValuesType | [
|
|
62
|
+
type: keyof typeof ValuesType,
|
|
63
|
+
param: string
|
|
64
|
+
] | [
|
|
65
|
+
type: keyof typeof ValuesType,
|
|
66
|
+
param: string
|
|
67
|
+
][];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Exposes a property to the Mattercraft UI editor, allowing users to configure it visually.
|
|
71
|
+
* Supports various UI widget types, grouping, and value constraints.
|
|
72
|
+
*
|
|
73
|
+
* @decorator
|
|
74
|
+
* @param opts - Configuration options for how the property appears in the UI
|
|
75
|
+
* @returns A property decorator that exposes the property to the UI
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Simple UI property
|
|
80
|
+
* @zUI()
|
|
81
|
+
* public volume = 1;
|
|
82
|
+
*
|
|
83
|
+
* // UI property with group and priority
|
|
84
|
+
* @zUI({ group: 'Audio', priority: 20 })
|
|
85
|
+
* public muted = false;
|
|
86
|
+
*
|
|
87
|
+
* // UI property with specific widget type
|
|
88
|
+
* @zUI({ type: 'proportion' })
|
|
89
|
+
* public opacity = 0.8;
|
|
90
|
+
*
|
|
91
|
+
* // UI property with value constraints
|
|
92
|
+
* @zUI({ values: 'layerclipids' })
|
|
93
|
+
* public state?: string;
|
|
94
|
+
*
|
|
95
|
+
* // Combined with @zObserve for reactive updates
|
|
96
|
+
* @zUI({ group: 'Appearance', type: 'color-hex' })
|
|
97
|
+
* @zObserve((val, instance) => instance.updateColor(val))
|
|
98
|
+
* public color = '#FF0000';
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function zUI<T>(opts?: ZPropOptions): (val: any, context: any) => any;
|
|
102
|
+
/**
|
|
103
|
+
* Excludes a property from serialization and the Mattercraft UI.
|
|
104
|
+
* Use this for internal properties that shouldn't be exposed to users or persisted.
|
|
105
|
+
*
|
|
106
|
+
* @decorator
|
|
107
|
+
* @returns A property decorator that marks the property as ignored
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // Internal element reference
|
|
112
|
+
* @zIgnore()
|
|
113
|
+
* public element: HTMLElement;
|
|
114
|
+
*
|
|
115
|
+
* // Private cache that shouldn't be serialized
|
|
116
|
+
* @zIgnore()
|
|
117
|
+
* private _cache: Map<string, any>;
|
|
118
|
+
*
|
|
119
|
+
* // Temporary state
|
|
120
|
+
* @zIgnore()
|
|
121
|
+
* public isProcessing = false;
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function zIgnore(): (val: any, context: any) => void;
|
|
125
|
+
export type UnwrapObservable<T> = T extends Observable<infer U, any> ? U : T;
|
|
126
|
+
export type ExtractComponentConstructorProps<T extends new (...args: any[]) => Component> = T extends new (contextManager: ContextManager, props: infer P) => any ? P : {};
|
|
127
|
+
export type ExtractComponentProps<T extends new (...args: any[]) => Component> = Partial<{
|
|
128
|
+
[K in keyof InstanceType<T> as K extends keyof Component | 'contextManager' | 'constructor' ? never : InstanceType<T>[K] extends Function ? never : K extends `_${string}` ? never : K]: UnwrapObservable<InstanceType<T>[K]>;
|
|
129
|
+
}>;
|
|
130
|
+
export type DefaultChildProps<T extends new (...args: any[]) => Component> = Partial<ExtractComponentProps<T> & ExtractComponentConstructorProps<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* Base configuration options for registering entities (components and behaviors) with Mattercraft.
|
|
133
|
+
*/
|
|
134
|
+
export interface ZEntityDecOptions {
|
|
135
|
+
/**
|
|
136
|
+
* A list of tags that can be used elsewhere to reference this type of entity.
|
|
137
|
+
* Tags help with categorization and search in the Mattercraft UI.
|
|
138
|
+
*/
|
|
139
|
+
tags?: string[];
|
|
140
|
+
/**
|
|
141
|
+
* Set to a list of tags to limit where Mattercraft's user interface will allow the user to create a new instance
|
|
142
|
+
* of this entity. It's possible to use a glob pattern, e.g.: 'three/Object3D/**'
|
|
143
|
+
*/
|
|
144
|
+
parents?: string[];
|
|
145
|
+
/**
|
|
146
|
+
* The icon to show for this entity when it appears in the trees and menus of Mattercraft's user interface.
|
|
147
|
+
* Icons can be chosen from the [Material Symbols icon set](https://fonts.google.com/icons).
|
|
148
|
+
*/
|
|
149
|
+
icon?: MaterialSymbol;
|
|
150
|
+
/**
|
|
151
|
+
* If supplied, Mattercraft's 'New' menu will list this entity under a group of this name.
|
|
152
|
+
*/
|
|
153
|
+
group?: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Configuration for default child nodes that are automatically added when a component is created.
|
|
157
|
+
*/
|
|
158
|
+
export interface DefaultChild {
|
|
159
|
+
/**
|
|
160
|
+
* A name for this node in the Hierarchy.
|
|
161
|
+
*/
|
|
162
|
+
label: string;
|
|
163
|
+
/**
|
|
164
|
+
* The type of the node to initialize. This should be of the form of the import file, a `#`, then the export name from that file.
|
|
165
|
+
*
|
|
166
|
+
* @example `@zcomponent/three/lib/components/meshes/Box#Box`
|
|
167
|
+
*/
|
|
168
|
+
type: string;
|
|
169
|
+
/**
|
|
170
|
+
* An object containing any initial values to set as props of the created node.
|
|
171
|
+
*/
|
|
172
|
+
props?: {
|
|
173
|
+
[id: string]: any;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Configuration options specific to components registered with @zComponent.
|
|
178
|
+
*/
|
|
179
|
+
export interface ZComponentDecOptions extends ZEntityDecOptions {
|
|
180
|
+
/**
|
|
181
|
+
* An array of children to automatically add under this entity when it's added to the Hierarchy.
|
|
182
|
+
* Useful for creating complex components with a predefined structure.
|
|
183
|
+
*/
|
|
184
|
+
defaultChildren?: DefaultChild[];
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Configuration options specific to behaviors registered with @zBehavior.
|
|
188
|
+
*/
|
|
189
|
+
export interface ZBehaviorDecOptions extends ZEntityDecOptions {
|
|
190
|
+
/**
|
|
191
|
+
* If true, this behavior will be constructed and run in the editor at design time.
|
|
192
|
+
* Useful for behaviors that provide preview functionality or editor-specific features.
|
|
193
|
+
*/
|
|
194
|
+
runAtDesignTime?: boolean;
|
|
195
|
+
}
|
|
196
|
+
type ClassDecorator<TFunction extends Function> = (target: TFunction) => TFunction | void;
|
|
197
|
+
/**
|
|
198
|
+
* Registers a class as a component in Mattercraft, making it available in the editor's UI.
|
|
199
|
+
* Components are the primary building blocks for creating interactive experiences.
|
|
200
|
+
*
|
|
201
|
+
* @decorator
|
|
202
|
+
* @param opts - Configuration options for the component
|
|
203
|
+
* @returns A class decorator that registers the component
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Basic component registration
|
|
208
|
+
* @zComponent({ icon: 'deployed_code', group: 'Meshes' })
|
|
209
|
+
* export class Box extends Mesh {
|
|
210
|
+
* // Component implementation
|
|
211
|
+
* }
|
|
212
|
+
*
|
|
213
|
+
* // Component with tags and parent restrictions
|
|
214
|
+
* @zComponent({
|
|
215
|
+
* icon: 'music_note',
|
|
216
|
+
* group: 'Media',
|
|
217
|
+
* tags: ['core/audio'],
|
|
218
|
+
* })
|
|
219
|
+
* export class Audio extends Component {
|
|
220
|
+
* // Audio component implementation
|
|
221
|
+
* }
|
|
222
|
+
*
|
|
223
|
+
* // Component with default children
|
|
224
|
+
* @zComponent({
|
|
225
|
+
* icon: 'view_in_ar',
|
|
226
|
+
* group: '3D Objects',
|
|
227
|
+
* defaultChildren: [
|
|
228
|
+
* {
|
|
229
|
+
* label: 'Material',
|
|
230
|
+
* type: '@zcomponent/three/lib/components/materials/MeshStandardMaterial#MeshStandardMaterial',
|
|
231
|
+
* props: { color: '#FF0000' }
|
|
232
|
+
* }
|
|
233
|
+
* ]
|
|
234
|
+
* })
|
|
235
|
+
* export class CustomMesh extends Component {
|
|
236
|
+
* // Mesh with default material
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export declare function zComponent<T extends new (...args: any[]) => Component>(opts?: ZComponentDecOptions): ClassDecorator<T>;
|
|
241
|
+
/**
|
|
242
|
+
* Registers a class as a behavior that can be attached to components.
|
|
243
|
+
* Behaviors add functionality to existing components without modifying their structure.
|
|
244
|
+
*
|
|
245
|
+
* @decorator
|
|
246
|
+
* @param opts - Configuration options for the behavior
|
|
247
|
+
* @returns A class decorator that registers the behavior
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* // Basic behavior registration
|
|
252
|
+
* @zBehavior({ icon: 'directions_run', parents: ['three/Object3D/**'] })
|
|
253
|
+
* export class Animation extends Behavior {
|
|
254
|
+
* // Animation behavior implementation
|
|
255
|
+
* }
|
|
256
|
+
*
|
|
257
|
+
* // Behavior that runs in the editor
|
|
258
|
+
* @zBehavior({
|
|
259
|
+
* icon: 'visibility',
|
|
260
|
+
* group: 'Actions',
|
|
261
|
+
* runAtDesignTime: true,
|
|
262
|
+
* parents: ['three/Object3D/**']
|
|
263
|
+
* })
|
|
264
|
+
* export class PreviewMode extends Behavior {
|
|
265
|
+
* // Provides preview functionality in the editor
|
|
266
|
+
* }
|
|
267
|
+
*
|
|
268
|
+
* // Action behavior with specific parent restrictions
|
|
269
|
+
* @zBehavior({
|
|
270
|
+
* icon: 'play_circle',
|
|
271
|
+
* group: 'Animation Actions',
|
|
272
|
+
* parents: ['three/Object3D/GLTF'],
|
|
273
|
+
* tags: ['animation/control']
|
|
274
|
+
* })
|
|
275
|
+
* export class PlayAnimation extends ActionBehavior {
|
|
276
|
+
* // Plays animations on GLTF models
|
|
277
|
+
* }
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export declare function zBehavior<T extends new (...args: any[]) => Behavior>(opts?: ZBehaviorDecOptions): ClassDecorator<T>;
|
|
281
|
+
type KeysOfType<T, KT> = Exclude<{
|
|
282
|
+
[K in keyof T]: T[K] extends KT ? K : never;
|
|
283
|
+
}[keyof T], undefined>;
|
|
284
|
+
type EventArgs<E> = E extends Event<infer X> ? X : never;
|
|
285
|
+
/**
|
|
286
|
+
* Automatically registers a method as an event listener during entity initialization.
|
|
287
|
+
* The decorated method will be called whenever the specified event is emitted.
|
|
288
|
+
* Supports three patterns: direct event objects, events from contexts, and events from the entity itself.
|
|
289
|
+
*
|
|
290
|
+
* @decorator
|
|
291
|
+
* @param event - Direct event object to listen to
|
|
292
|
+
* @param opts - Optional registration options (e.g., priority, once)
|
|
293
|
+
* @returns A method decorator that registers the event listener
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* // Listen to a direct event object
|
|
298
|
+
* @zRegister(someEvent)
|
|
299
|
+
* private handleEvent(data: EventData) {
|
|
300
|
+
* console.log('Event received:', data);
|
|
301
|
+
* }
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
export declare function zRegister<EntityType extends Entity, EventType extends Event<any>, EventArgsType extends EventArgs<EventType>>(event: EventType, opts?: RegisterOptions): (originalMethod: (...args: EventArgsType) => void, context: ClassMethodDecoratorContext<EntityType>) => any;
|
|
305
|
+
/**
|
|
306
|
+
* Registers a method to listen to an event from a context.
|
|
307
|
+
*
|
|
308
|
+
* @decorator
|
|
309
|
+
* @param contextConstructor - The context class constructor
|
|
310
|
+
* @param prop - The property name of the event in the context
|
|
311
|
+
* @param opts - Optional registration options
|
|
312
|
+
* @returns A method decorator that registers the event listener
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* // Listen to an event from a context
|
|
317
|
+
* @zRegister(AudioContext, 'onVolumeChange')
|
|
318
|
+
* private handleVolumeChange(volume: number) {
|
|
319
|
+
* this.updateVolume(volume);
|
|
320
|
+
* }
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
export declare function zRegister<EntityType extends Entity, ContextType extends Context, PropType extends KeysOfType<ContextType, Event<any>>, EventArgsType extends EventArgs<ContextType[PropType]>>(contextConstructor: new (...args: any[]) => ContextType, prop: PropType, opts?: RegisterOptions): (originalMethod: (...args: EventArgsType) => void, context: ClassMethodDecoratorContext<EntityType>) => any;
|
|
324
|
+
/**
|
|
325
|
+
* Registers a method to listen to an event from the entity itself.
|
|
326
|
+
*
|
|
327
|
+
* @decorator
|
|
328
|
+
* @param prop - The property name of the event in the entity
|
|
329
|
+
* @param opts - Optional registration options
|
|
330
|
+
* @returns A method decorator that registers the event listener
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```typescript
|
|
334
|
+
* // Listen to an event from the same entity
|
|
335
|
+
* @zRegister('onStateChange')
|
|
336
|
+
* private handleStateChange(newState: State) {
|
|
337
|
+
* this.processStateChange(newState);
|
|
338
|
+
* }
|
|
339
|
+
*
|
|
340
|
+
* // With registration options
|
|
341
|
+
* @zRegister('onClick', { once: true })
|
|
342
|
+
* private handleFirstClick() {
|
|
343
|
+
* this.initializeOnFirstInteraction();
|
|
344
|
+
* }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
export declare function zRegister<EntityType extends Entity, PropType extends KeysOfType<EntityType, Event<any>>, EventArgsType extends EventArgs<EntityType[PropType]>>(prop: PropType, opts?: RegisterOptions): (originalMethod: (...args: EventArgsType) => void, context: ClassMethodDecoratorContext<EntityType>) => any;
|
|
348
|
+
export {};
|