@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.
Files changed (168) hide show
  1. package/README.md +1 -0
  2. package/css/zcomponent.css +121 -122
  3. package/index.js +0 -3
  4. package/lib/actionbehavior.d.ts +3 -3
  5. package/lib/actionbehavior.js +20 -19
  6. package/lib/animation/animation.d.ts +13 -6
  7. package/lib/animation/animation.js +56 -43
  8. package/lib/animation/bezier.d.ts +6 -0
  9. package/lib/animation/bezier.js +8 -2
  10. package/lib/animation/clips/clip.d.ts +13 -1
  11. package/lib/animation/clips/clip.js +34 -14
  12. package/lib/animation/index.d.ts +4 -4
  13. package/lib/animation/index.js +4 -4
  14. package/lib/animation/layer.d.ts +9 -0
  15. package/lib/animation/layer.js +28 -12
  16. package/lib/animation/layerclip.d.ts +21 -0
  17. package/lib/animation/layerclip.js +82 -45
  18. package/lib/animation/tracks/cliptrack.d.ts +18 -0
  19. package/lib/animation/tracks/cliptrack.js +27 -6
  20. package/lib/animation/tracks/functiontrack.d.ts +9 -0
  21. package/lib/animation/tracks/functiontrack.js +16 -3
  22. package/lib/animation/tracks/propertytrack.d.ts +20 -1
  23. package/lib/animation/tracks/propertytrack.js +48 -11
  24. package/lib/animation/tracks/streamtrack.d.ts +18 -0
  25. package/lib/animation/tracks/streamtrack.js +32 -6
  26. package/lib/animation/tracks/track.d.ts +8 -2
  27. package/lib/animation/tracks/track.js +3 -2
  28. package/lib/behavior.js +13 -10
  29. package/lib/behaviors/ActivateState.d.ts +22 -24
  30. package/lib/behaviors/ActivateState.js +145 -35
  31. package/lib/behaviors/CallFunction.d.ts +2 -4
  32. package/lib/behaviors/CallFunction.js +69 -11
  33. package/lib/behaviors/ChangeRootScene.d.ts +35 -0
  34. package/lib/behaviors/ChangeRootScene.js +123 -0
  35. package/lib/behaviors/ConsoleLog.d.ts +6 -5
  36. package/lib/behaviors/ConsoleLog.js +95 -12
  37. package/lib/behaviors/DownloadSnapshot.d.ts +7 -12
  38. package/lib/behaviors/DownloadSnapshot.js +70 -19
  39. package/lib/behaviors/EmitComponentPropEvent.d.ts +1 -3
  40. package/lib/behaviors/EmitComponentPropEvent.js +80 -12
  41. package/lib/behaviors/LaunchURL.d.ts +5 -5
  42. package/lib/behaviors/LaunchURL.js +92 -10
  43. package/lib/behaviors/LogAnalyticsEvent.d.ts +10 -4
  44. package/lib/behaviors/LogAnalyticsEvent.js +88 -7
  45. package/lib/behaviors/PauseLayerClip.d.ts +7 -9
  46. package/lib/behaviors/PauseLayerClip.js +89 -21
  47. package/lib/behaviors/PlayLayerClip.d.ts +35 -32
  48. package/lib/behaviors/PlayLayerClip.js +202 -48
  49. package/lib/behaviors/PlaySound.d.ts +19 -25
  50. package/lib/behaviors/PlaySound.js +122 -28
  51. package/lib/behaviors/SetLayerOff.d.ts +7 -9
  52. package/lib/behaviors/SetLayerOff.js +88 -21
  53. package/lib/behaviors/ShareSnapshot.d.ts +5 -9
  54. package/lib/behaviors/ShareSnapshot.js +70 -17
  55. package/lib/behaviors/ShowTextAlert.d.ts +16 -29
  56. package/lib/behaviors/ShowTextAlert.js +116 -48
  57. package/lib/behaviors/TakeSnapshot.d.ts +22 -26
  58. package/lib/behaviors/TakeSnapshot.js +131 -56
  59. package/lib/behaviors/ToggleLayerClips.d.ts +45 -62
  60. package/lib/behaviors/ToggleLayerClips.js +233 -64
  61. package/lib/behaviors/stream/PauseStream.d.ts +5 -16
  62. package/lib/behaviors/stream/PauseStream.js +94 -34
  63. package/lib/behaviors/stream/PlayStream.d.ts +14 -27
  64. package/lib/behaviors/stream/PlayStream.js +123 -34
  65. package/lib/behaviors/stream/SeekStream.d.ts +8 -18
  66. package/lib/behaviors/stream/SeekStream.js +97 -31
  67. package/lib/behaviors/stream/StopStream.d.ts +6 -15
  68. package/lib/behaviors/stream/StopStream.js +89 -27
  69. package/lib/component.d.ts +36 -13
  70. package/lib/component.js +237 -151
  71. package/lib/components/AnimatedLoader.d.ts +51 -0
  72. package/lib/components/AnimatedLoader.js +159 -0
  73. package/lib/components/Audio.d.ts +35 -37
  74. package/lib/components/Audio.js +264 -151
  75. package/lib/components/AudioLayerSettings.d.ts +13 -11
  76. package/lib/components/AudioLayerSettings.js +76 -18
  77. package/lib/components/Children.d.ts +2 -1
  78. package/lib/components/Children.js +66 -13
  79. package/lib/components/ConditionalConstruct.d.ts +44 -0
  80. package/lib/components/ConditionalConstruct.js +142 -0
  81. package/lib/components/DefaultCookieConsent.d.ts +53 -73
  82. package/lib/components/DefaultCookieConsent.js +382 -264
  83. package/lib/components/DefaultLoader.d.ts +40 -28
  84. package/lib/components/DefaultLoader.js +198 -46
  85. package/lib/components/Gamepad.d.ts +5 -26
  86. package/lib/components/Gamepad.js +201 -65
  87. package/lib/components/LoaderScope.d.ts +15 -0
  88. package/lib/components/LoaderScope.js +71 -0
  89. package/lib/components/LongLoad.d.ts +11 -15
  90. package/lib/components/LongLoad.js +89 -34
  91. package/lib/components/SnapshotUI.d.ts +19 -24
  92. package/lib/components/SnapshotUI.js +202 -105
  93. package/lib/context.d.ts +23 -5
  94. package/lib/context.js +12 -6
  95. package/lib/contexts/analyticscontext.d.ts +12 -2
  96. package/lib/contexts/analyticscontext.js +68 -10
  97. package/lib/contexts/audiocontextcontext.d.ts +1 -1
  98. package/lib/contexts/audiocontextcontext.js +9 -8
  99. package/lib/contexts/canvascontext.d.ts +32 -18
  100. package/lib/contexts/canvascontext.js +195 -120
  101. package/lib/contexts/cookieconsentcontext.d.ts +38 -28
  102. package/lib/contexts/cookieconsentcontext.js +35 -32
  103. package/lib/contexts/documentflagmanager.js +15 -11
  104. package/lib/contexts/environmentcontext.d.ts +22 -6
  105. package/lib/contexts/environmentcontext.js +135 -21
  106. package/lib/contexts/gamepadcontext.d.ts +29 -26
  107. package/lib/contexts/gamepadcontext.js +46 -46
  108. package/lib/contexts/gesturecontext.d.ts +31 -6
  109. package/lib/contexts/gesturecontext.js +110 -85
  110. package/lib/contexts/globaltagcontext.d.ts +1 -1
  111. package/lib/contexts/globaltagcontext.js +8 -11
  112. package/lib/contexts/loadcontext.d.ts +45 -8
  113. package/lib/contexts/loadcontext.js +232 -82
  114. package/lib/contexts/orientationcontext.d.ts +13 -15
  115. package/lib/contexts/orientationcontext.js +150 -67
  116. package/lib/contexts/rootcomponentscontext.d.ts +16 -0
  117. package/lib/contexts/rootcomponentscontext.js +65 -0
  118. package/lib/contexts/snapshotContext.d.ts +0 -3
  119. package/lib/contexts/snapshotContext.js +78 -23
  120. package/lib/contexts/tagcontext.d.ts +5 -5
  121. package/lib/contexts/tagcontext.js +16 -16
  122. package/lib/contexts/textalertcontext.d.ts +1 -5
  123. package/lib/contexts/textalertcontext.js +1 -5
  124. package/lib/contexts/usereventcontext.d.ts +1 -1
  125. package/lib/contexts/usereventcontext.js +12 -12
  126. package/lib/data/animation.d.ts +10 -2
  127. package/lib/data/change.d.ts +1 -1
  128. package/lib/data/change.js +7 -0
  129. package/lib/data/core.d.ts +9 -1
  130. package/lib/data/index.d.ts +1 -1
  131. package/lib/data/index.js +1 -1
  132. package/lib/decorators.d.ts +348 -0
  133. package/lib/decorators.js +239 -0
  134. package/lib/decoratorutils.d.ts +3 -0
  135. package/lib/decoratorutils.js +8 -0
  136. package/lib/emitter.d.ts +15 -2
  137. package/lib/emitter.js +15 -6
  138. package/lib/entity.d.ts +43 -25
  139. package/lib/entity.js +104 -71
  140. package/lib/event.d.ts +2 -1
  141. package/lib/event.js +1 -4
  142. package/lib/groups.d.ts +18 -0
  143. package/lib/groups.js +19 -0
  144. package/lib/icons.d.ts +3372 -0
  145. package/lib/icons.js +1 -0
  146. package/lib/index.d.ts +18 -13
  147. package/lib/index.js +17 -13
  148. package/lib/inflate.d.ts +7 -7
  149. package/lib/inflate.js +5 -5
  150. package/lib/observable.d.ts +9 -2
  151. package/lib/observable.js +5 -4
  152. package/lib/observe.d.ts +18 -0
  153. package/lib/observe.js +177 -0
  154. package/lib/profile.d.ts +9 -5
  155. package/lib/profile.js +27 -17
  156. package/lib/selectors.d.ts +1 -1
  157. package/lib/selectors.js +5 -4
  158. package/lib/types.d.ts +161 -19
  159. package/lib/types.js +22 -1
  160. package/lib/values/values.d.ts +7 -8
  161. package/lib/values/values.js +1 -2
  162. package/lib/values/valuesmutator.d.ts +4 -1
  163. package/lib/values/valuesmutator.js +10 -8
  164. package/lib/zcomponent.d.ts +21 -10
  165. package/lib/zcomponent.js +717 -540
  166. package/package.json +22 -5
  167. package/lib/behaviors/ChangeCursor.d.ts +0 -39
  168. package/lib/behaviors/ChangeCursor.js +0 -44
package/lib/component.js CHANGED
@@ -1,6 +1,41 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
1
35
  import { TagContext } from './contexts/tagcontext';
36
+ import { zObserve, zUI } from './decorators';
2
37
  import { Entity } from './entity';
3
- import { Observable } from './observable';
38
+ import { notify } from './observe';
4
39
  /**
5
40
  * Base class for all components.
6
41
  *
@@ -10,23 +45,186 @@ import { Observable } from './observable';
10
45
  *
11
46
  * @link [custom-components](https://docs.zap.works/mattercraft/scripting/custom-components/)
12
47
  */
13
- export class Component extends Entity {
14
- /**
15
- * Creates an instance of Component.
16
- * @param contextManager The current ContextManager
17
- * @param constructorProps - The constructor properties.
18
- */
19
- constructor(contextManager, constructorProps) {
20
- super(contextManager);
21
- this.constructorProps = constructorProps;
48
+ let Component = (() => {
49
+ let _classSuper = Entity;
50
+ let _tags_decorators;
51
+ let _tags_initializers = [];
52
+ let _tags_extraInitializers = [];
53
+ return class Component extends _classSuper {
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
56
+ _tags_decorators = [zUI({ group: 'Other', priority: 0 }), zObserve((v, instance) => {
57
+ const context = instance.contextManager.get(TagContext);
58
+ context.registerComponent(instance, v);
59
+ })];
60
+ __esDecorate(null, null, _tags_decorators, { kind: "field", name: "tags", static: false, private: false, access: { has: obj => "tags" in obj, get: obj => obj.tags, set: (obj, value) => { obj.tags = value; } }, metadata: _metadata }, _tags_initializers, _tags_extraInitializers);
61
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
62
+ }
63
+ constructorProps;
64
+ /**
65
+ * The raw element(s) that this component exposes
66
+ * @zignore
67
+ */
68
+ element;
22
69
  /**
23
70
  * The children of this component.
71
+ *
72
+ * @zignore
73
+ * @default []
24
74
  */
25
- this.children = [];
75
+ children = [];
26
76
  /**
27
77
  * The behaviors attached to this component.
78
+ *
79
+ * @zignore
80
+ * @default []
81
+ */
82
+ behaviors = [];
83
+ /**
84
+ * If true, this component can't be selected at design time in the 3D preview.
85
+ * @zignore
86
+ */
87
+ locked;
88
+ _parent;
89
+ /**
90
+ * The parent of this component.
91
+ * @zignore
92
+ */
93
+ get parent() {
94
+ return this._parent;
95
+ }
96
+ /**
97
+ * Creates an instance of Component.
98
+ * @param contextManager The current ContextManager
99
+ * @param constructorProps - The constructor properties.
100
+ */
101
+ constructor(contextManager, constructorProps) {
102
+ super(contextManager);
103
+ this.constructorProps = constructorProps;
104
+ this.constructChildren(constructorProps?.children ?? []);
105
+ this.observe(this, 'enabled', this._updateEnabledResolved, { bindWhenDisabled: true });
106
+ }
107
+ /**
108
+ * Constructs the children of this component.
109
+ * @zignore
110
+ */
111
+ constructChildren(children, contextManager) {
112
+ contextManager = contextManager ?? this.contextManager;
113
+ for (const [_constructor, props, ref] of children) {
114
+ try {
115
+ const instance = new _constructor(contextManager, props);
116
+ this.appendChild(instance);
117
+ if (ref)
118
+ ref.value = instance;
119
+ }
120
+ catch (err) {
121
+ console.log('An error occurred when constructing component child of type:', _constructor, err);
122
+ }
123
+ }
124
+ }
125
+ /**
126
+ * Adds the supplied component instance as a child of this component, removing it from any existing parent.
127
+ *
128
+ * @param c The component instance to add
129
+ * @zignore
130
+ */
131
+ appendChild(c) {
132
+ c.remove();
133
+ this.children.push(c);
134
+ c._parent = this;
135
+ c.connectElements();
136
+ c._updateEnabledResolved();
137
+ }
138
+ connectElements() {
139
+ if (this.element === undefined) {
140
+ for (const child of this.children) {
141
+ child.connectElements();
142
+ }
143
+ }
144
+ }
145
+ /**
146
+ * Removes the supplied component instance from the list of children.
147
+ * @param c The component to remove
148
+ * @zignore
149
+ */
150
+ removeChild(c) {
151
+ const indx = this.children.indexOf(c);
152
+ if (indx >= 0)
153
+ this.children.splice(indx, 1);
154
+ if (c._parent === this)
155
+ delete c._parent;
156
+ }
157
+ /**
158
+ * Removes this component from its parent component.
159
+ * @zignore
160
+ */
161
+ remove() {
162
+ this._parent?.removeChild(this);
163
+ }
164
+ /**
165
+ * Adds a behavior to the component.
166
+ * @param {Behavior} b - The behavior to add.
167
+ * @zignore
168
+ */
169
+ addBehavior(b) {
170
+ this.behaviors.push(b);
171
+ }
172
+ /**
173
+ * Removes a behavior from the component.
174
+ * @param {Behavior} b - The behavior to remove.
175
+ * @zignore
176
+ */
177
+ removeBehavior(b) {
178
+ const indx = this.behaviors.indexOf(b);
179
+ if (indx >= 0)
180
+ this.behaviors.splice(indx, 1);
181
+ }
182
+ /**
183
+ * Gets a behavior of a specific type from the component.
184
+ * @param {T} type - The type of behavior to get.
185
+ * @returns {InstanceType<T> | undefined} The behavior of the specified type, or undefined if no such behavior exists.
186
+ * @template T The behavior type.
187
+ * @zignore
188
+ */
189
+ getBehavior(type) {
190
+ for (const behavior of this.behaviors) {
191
+ if (behavior instanceof type)
192
+ return behavior;
193
+ }
194
+ }
195
+ /**
196
+ * Gets all behaviors of a specific type from the component.
197
+ * @param {T} type - The type of behaviors to get.
198
+ * @returns {InstanceType<T>[]} An array of behaviors of the specified type.
199
+ * @template T The behavior type.
200
+ * @zignore
28
201
  */
29
- this.behaviors = [];
202
+ getBehaviors(type) {
203
+ return this.behaviors.filter(entry => entry instanceof type);
204
+ }
205
+ /**
206
+ * An array of the elements that this component instance exposes. In the case that this component
207
+ * does not expose any elements of its own, this will be an array of the elements
208
+ * exposed by this component's children.
209
+ */
210
+ get elementsResolved() {
211
+ if (this.element !== undefined) {
212
+ if (Array.isArray(this.element))
213
+ return this.element;
214
+ return [this.element];
215
+ }
216
+ const ret = [];
217
+ for (const child of this.children) {
218
+ ret.push(...child.elementsResolved);
219
+ }
220
+ return ret;
221
+ }
222
+ /**
223
+ * Returns true if this component, or any of its parents, are marked as locked.
224
+ */
225
+ get lockedResolved() {
226
+ return (this.locked ?? false) || (this._parent?.lockedResolved ?? false);
227
+ }
30
228
  /**
31
229
  * An array of string 'tags' assocated with this component.
32
230
  *
@@ -35,150 +233,38 @@ export class Component extends Entity {
35
233
  *
36
234
  * By default, tags are scoped to the ZComponent instance that a component is constructed by.
37
235
  * Tags that begin with `global:` are scoped to the experience as a whole.
38
- *
39
- * @zprop
236
+ * @default []
237
+ * @zui
40
238
  * @zgroup Other
41
- * @group Other
42
- * @zgrouppriority 0
43
239
  */
44
- this.tags = new Observable([]);
45
- this._updateEnabledResolved = () => {
46
- let newValue = this.enabled.value;
47
- if (this.parent?.enabledResolved?.value === false)
240
+ tags = __runInitializers(this, _tags_initializers, []);
241
+ _updateEnabledResolved = (__runInitializers(this, _tags_extraInitializers), () => {
242
+ let newValue = this.enabled;
243
+ if (this._parent?.enabledResolved === false)
48
244
  newValue = false;
49
- if (newValue !== this.enabledResolved.value) {
50
- this.enabledResolved.value = newValue;
245
+ if (newValue !== this.enabledResolved) {
246
+ this._enabledResolved = newValue;
247
+ notify(this, 'enabledResolved');
51
248
  for (const child of this.children)
52
249
  child._updateEnabledResolved();
53
250
  }
54
- };
55
- this._updateTags = () => {
56
- const context = this.contextManager.get(TagContext);
57
- context.registerComponent(this, this.tags.value);
58
- };
59
- this.constructChildren(constructorProps?.children ?? []);
60
- this.register(this.enabled, this._updateEnabledResolved, { bindWhenDisabled: true });
61
- this.register(this.tags, this._updateTags, { bindWhenDisabled: true });
62
- }
63
- /**
64
- * Constructs the children of this component.
65
- */
66
- constructChildren(children, contextManager) {
67
- contextManager = contextManager ?? this.contextManager;
68
- for (const [constructor, props, ref] of children) {
69
- try {
70
- const instance = new constructor(contextManager, props);
71
- this.appendChild(instance);
72
- if (ref)
73
- ref.value = instance;
74
- }
75
- catch (err) {
76
- console.log('An error occurred when constructing component child of type:', constructor, err);
77
- }
78
- }
79
- }
80
- /**
81
- * Adds the supplied component instance as a child of this component, removing it from any existing parent.
82
- *
83
- * @param c The component instance to add
84
- */
85
- appendChild(c) {
86
- c.remove();
87
- this.children.push(c);
88
- c.parent = this;
89
- c._updateEnabledResolved();
90
- }
91
- /**
92
- * Removes the supplied component instance from the list of children.
93
- * @param c The component to remove
94
- */
95
- removeChild(c) {
96
- const indx = this.children.indexOf(c);
97
- if (indx >= 0)
98
- this.children.splice(indx, 1);
99
- if (c.parent === this)
100
- delete c.parent;
101
- }
102
- /**
103
- * Removes this component from its parent component.
104
- */
105
- remove() {
106
- this.parent?.removeChild(this);
107
- }
108
- /**
109
- * Adds a behavior to the component.
110
- * @param {Behavior} b - The behavior to add.
111
- */
112
- addBehavior(b) {
113
- this.behaviors.push(b);
114
- }
115
- /**
116
- * Removes a behavior from the component.
117
- * @param {Behavior} b - The behavior to remove.
118
- */
119
- removeBehavior(b) {
120
- const indx = this.behaviors.indexOf(b);
121
- if (indx >= 0)
122
- this.behaviors.splice(indx, 1);
123
- }
124
- /**
125
- * Gets a behavior of a specific type from the component.
126
- * @param {T} type - The type of behavior to get.
127
- * @returns {InstanceType<T> | undefined} The behavior of the specified type, or undefined if no such behavior exists.
128
- * @template T The behavior type.
129
- */
130
- getBehavior(type) {
131
- for (const behavior of this.behaviors) {
132
- if (behavior instanceof type)
133
- return behavior;
134
- }
135
- }
136
- /**
137
- * Gets all behaviors of a specific type from the component.
138
- * @param {T} type - The type of behaviors to get.
139
- * @returns {InstanceType<T>[]} An array of behaviors of the specified type.
140
- * @template T The behavior type.
141
- */
142
- getBehaviors(type) {
143
- return this.behaviors.filter(entry => entry instanceof type);
144
- }
145
- /**
146
- * An array of the elements that this component instance exposes. In the case that this component
147
- * does not expose any elements of its own, this will be an array of the elements
148
- * exposed by this component's children.
149
- */
150
- get elementsResolved() {
151
- if (this.element !== undefined) {
152
- if (Array.isArray(this.element))
153
- return this.element;
154
- return [this.element];
155
- }
156
- const ret = [];
157
- for (const child of this.children) {
158
- ret.push(...child.elementsResolved);
159
- }
160
- return ret;
161
- }
162
- /**
163
- * Returns true if this component, or any of its parents, are marked as locked.
164
- */
165
- get lockedResolved() {
166
- return (this.locked ?? false) || (this.parent?.lockedResolved ?? false);
167
- }
168
- /**
169
- * Dispose of this component and all of its children.
170
- */
171
- dispose() {
172
- for (const child of this.children) {
173
- try {
174
- child.dispose();
175
- }
176
- catch (err) {
177
- // Fail silently
251
+ });
252
+ /**
253
+ * Dispose of this component and all of its children.
254
+ */
255
+ dispose() {
256
+ for (const child of this.children) {
257
+ try {
258
+ child.dispose();
259
+ }
260
+ catch (err) {
261
+ // Fail silently
262
+ }
178
263
  }
264
+ this.children.length = 0;
265
+ this.contextManager.get(TagContext).unregisterComponent(this);
266
+ return super.dispose();
179
267
  }
180
- this.children.length = 0;
181
- this.contextManager.get(TagContext).unregisterComponent(this);
182
- return super.dispose();
183
- }
184
- }
268
+ };
269
+ })();
270
+ export { Component };
@@ -0,0 +1,51 @@
1
+ import { Component, ConstructorProps } from '../component';
2
+ import { ContextManager } from '../context';
3
+ import { Event } from '../event';
4
+ /**
5
+ * A component that plays different layer clips and emits events based on the loading state of the experience. Use it to build animated loading screens for your experience.
6
+ *
7
+ * For the initial loading of the experience, the 3D scene and animation system may not yet be available, so it's recommended to use the DefaultLoader component for that phase.
8
+ *
9
+ * Placing this component within a LoaderScope, along with other loadable components, allows it to track the loading state of those components specifically.
10
+ * @zcomponent
11
+ * @zicon hourglass_bottom
12
+ * @zgroup Advanced
13
+ */
14
+ export declare class AnimatedLoader extends Component {
15
+ onLoading: Event<[]>;
16
+ onNotLoading: Event<[]>;
17
+ /**
18
+ * A layer clip that will be played when there is no loading being performed
19
+ * @zui
20
+ * @zgroup Animation
21
+ * @zgrouppriority 10
22
+ * @zvalues layerclipids
23
+ */
24
+ notLoadingLayerClip: string | undefined;
25
+ /**
26
+ * A layer clip that will be played when there is loading being performed
27
+ * @zui
28
+ * @zgroup Animation
29
+ * @zgrouppriority 10
30
+ * @zvalues layerclipids
31
+ */
32
+ loadingLayerClip: string | undefined;
33
+ /**
34
+ * A timeline that will have it's current time set to the percentage of loading completion
35
+ * @zui
36
+ * @zgroup Animation
37
+ * @zgrouppriority 10
38
+ * @zvalues layerclipids
39
+ */
40
+ loadingProgressLayerClip: string | undefined;
41
+ /**
42
+ * Creates a new AnimatedLoader component.
43
+ * @param contextManager - The current ContextManager
44
+ * @param constructorProps - The constructor properties.
45
+ */
46
+ constructor(contextManager: ContextManager, constructorProps: ConstructorProps);
47
+ private _updatePercentage;
48
+ private _updateVisibility;
49
+ private _playLayerClip;
50
+ private _setLayerClipPercentage;
51
+ }
@@ -0,0 +1,159 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ import { Component } from '../component';
36
+ import { useIsLoaded, useLoadPercent } from '../contexts/loadcontext';
37
+ import { zComponent, zUI } from '../decorators';
38
+ import { Event } from '../event';
39
+ /**
40
+ * A component that plays different layer clips and emits events based on the loading state of the experience. Use it to build animated loading screens for your experience.
41
+ *
42
+ * For the initial loading of the experience, the 3D scene and animation system may not yet be available, so it's recommended to use the DefaultLoader component for that phase.
43
+ *
44
+ * Placing this component within a LoaderScope, along with other loadable components, allows it to track the loading state of those components specifically.
45
+ * @zcomponent
46
+ * @zicon hourglass_bottom
47
+ * @zgroup Advanced
48
+ */
49
+ let AnimatedLoader = (() => {
50
+ let _classDecorators = [zComponent({ icon: 'hourglass_bottom', group: 'Advanced' })];
51
+ let _classDescriptor;
52
+ let _classExtraInitializers = [];
53
+ let _classThis;
54
+ let _classSuper = Component;
55
+ let _onLoading_decorators;
56
+ let _onLoading_initializers = [];
57
+ let _onLoading_extraInitializers = [];
58
+ let _onNotLoading_decorators;
59
+ let _onNotLoading_initializers = [];
60
+ let _onNotLoading_extraInitializers = [];
61
+ let _notLoadingLayerClip_decorators;
62
+ let _notLoadingLayerClip_initializers = [];
63
+ let _notLoadingLayerClip_extraInitializers = [];
64
+ let _loadingLayerClip_decorators;
65
+ let _loadingLayerClip_initializers = [];
66
+ let _loadingLayerClip_extraInitializers = [];
67
+ let _loadingProgressLayerClip_decorators;
68
+ let _loadingProgressLayerClip_initializers = [];
69
+ let _loadingProgressLayerClip_extraInitializers = [];
70
+ var AnimatedLoader = class extends _classSuper {
71
+ static { _classThis = this; }
72
+ static {
73
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
74
+ _onLoading_decorators = [zUI()];
75
+ _onNotLoading_decorators = [zUI()];
76
+ _notLoadingLayerClip_decorators = [zUI({ group: { name: 'Animation', priority: 10 }, values: 'layerclipids' })];
77
+ _loadingLayerClip_decorators = [zUI({ group: { name: 'Animation', priority: 10 }, values: 'layerclipids' })];
78
+ _loadingProgressLayerClip_decorators = [zUI({ group: { name: 'Animation', priority: 10 }, values: 'layerclipids' })];
79
+ __esDecorate(null, null, _onLoading_decorators, { kind: "field", name: "onLoading", static: false, private: false, access: { has: obj => "onLoading" in obj, get: obj => obj.onLoading, set: (obj, value) => { obj.onLoading = value; } }, metadata: _metadata }, _onLoading_initializers, _onLoading_extraInitializers);
80
+ __esDecorate(null, null, _onNotLoading_decorators, { kind: "field", name: "onNotLoading", static: false, private: false, access: { has: obj => "onNotLoading" in obj, get: obj => obj.onNotLoading, set: (obj, value) => { obj.onNotLoading = value; } }, metadata: _metadata }, _onNotLoading_initializers, _onNotLoading_extraInitializers);
81
+ __esDecorate(null, null, _notLoadingLayerClip_decorators, { kind: "field", name: "notLoadingLayerClip", static: false, private: false, access: { has: obj => "notLoadingLayerClip" in obj, get: obj => obj.notLoadingLayerClip, set: (obj, value) => { obj.notLoadingLayerClip = value; } }, metadata: _metadata }, _notLoadingLayerClip_initializers, _notLoadingLayerClip_extraInitializers);
82
+ __esDecorate(null, null, _loadingLayerClip_decorators, { kind: "field", name: "loadingLayerClip", static: false, private: false, access: { has: obj => "loadingLayerClip" in obj, get: obj => obj.loadingLayerClip, set: (obj, value) => { obj.loadingLayerClip = value; } }, metadata: _metadata }, _loadingLayerClip_initializers, _loadingLayerClip_extraInitializers);
83
+ __esDecorate(null, null, _loadingProgressLayerClip_decorators, { kind: "field", name: "loadingProgressLayerClip", static: false, private: false, access: { has: obj => "loadingProgressLayerClip" in obj, get: obj => obj.loadingProgressLayerClip, set: (obj, value) => { obj.loadingProgressLayerClip = value; } }, metadata: _metadata }, _loadingProgressLayerClip_initializers, _loadingProgressLayerClip_extraInitializers);
84
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
85
+ AnimatedLoader = _classThis = _classDescriptor.value;
86
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
87
+ __runInitializers(_classThis, _classExtraInitializers);
88
+ }
89
+ onLoading = __runInitializers(this, _onLoading_initializers, new Event());
90
+ onNotLoading = (__runInitializers(this, _onLoading_extraInitializers), __runInitializers(this, _onNotLoading_initializers, new Event()));
91
+ /**
92
+ * A layer clip that will be played when there is no loading being performed
93
+ * @zui
94
+ * @zgroup Animation
95
+ * @zgrouppriority 10
96
+ * @zvalues layerclipids
97
+ */
98
+ notLoadingLayerClip = (__runInitializers(this, _onNotLoading_extraInitializers), __runInitializers(this, _notLoadingLayerClip_initializers, void 0));
99
+ /**
100
+ * A layer clip that will be played when there is loading being performed
101
+ * @zui
102
+ * @zgroup Animation
103
+ * @zgrouppriority 10
104
+ * @zvalues layerclipids
105
+ */
106
+ loadingLayerClip = (__runInitializers(this, _notLoadingLayerClip_extraInitializers), __runInitializers(this, _loadingLayerClip_initializers, void 0));
107
+ /**
108
+ * A timeline that will have it's current time set to the percentage of loading completion
109
+ * @zui
110
+ * @zgroup Animation
111
+ * @zgrouppriority 10
112
+ * @zvalues layerclipids
113
+ */
114
+ loadingProgressLayerClip = (__runInitializers(this, _loadingLayerClip_extraInitializers), __runInitializers(this, _loadingProgressLayerClip_initializers, void 0));
115
+ /**
116
+ * Creates a new AnimatedLoader component.
117
+ * @param contextManager - The current ContextManager
118
+ * @param constructorProps - The constructor properties.
119
+ */
120
+ constructor(contextManager, constructorProps) {
121
+ super(contextManager, constructorProps);
122
+ this.register(useIsLoaded(contextManager), this._updateVisibility);
123
+ this.register(useLoadPercent(contextManager), this._updatePercentage);
124
+ }
125
+ _updatePercentage = (__runInitializers(this, _loadingProgressLayerClip_extraInitializers), () => {
126
+ this._setLayerClipPercentage(this.loadingProgressLayerClip, useLoadPercent(this.contextManager).value);
127
+ });
128
+ _updateVisibility = v => {
129
+ if (v) {
130
+ this.onNotLoading.emit();
131
+ this._playLayerClip(this.notLoadingLayerClip);
132
+ }
133
+ else {
134
+ this.onLoading.emit();
135
+ this._playLayerClip(this.loadingLayerClip);
136
+ }
137
+ };
138
+ _playLayerClip(clip, fade = true) {
139
+ if (!clip)
140
+ return;
141
+ const zcomponent = this.getZComponentInstance();
142
+ const layerclip = zcomponent.animation.layerClipByID.get(clip);
143
+ if (!layerclip)
144
+ return;
145
+ layerclip.play(fade ? undefined : { fade: { time: 0 } });
146
+ }
147
+ _setLayerClipPercentage(clip, percentage, fade = true) {
148
+ if (!clip)
149
+ return;
150
+ const zcomponent = this.getZComponentInstance();
151
+ const layerclip = zcomponent.animation.layerClipByID.get(clip);
152
+ if (!layerclip)
153
+ return;
154
+ layerclip.seek((layerclip.length() * percentage) / 100);
155
+ }
156
+ };
157
+ return AnimatedLoader = _classThis;
158
+ })();
159
+ export { AnimatedLoader };