@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.
Files changed (141) hide show
  1. package/README.md +0 -6
  2. package/lib/actionbehavior.d.ts +12 -3
  3. package/lib/actionbehavior.js +12 -3
  4. package/lib/animation/animation.d.ts +96 -4
  5. package/lib/animation/animation.js +93 -0
  6. package/lib/animation/animationstate.d.ts +52 -2
  7. package/lib/animation/bezier.d.ts +12 -1
  8. package/lib/animation/bezier.js +15 -12
  9. package/lib/animation/clips/clip.d.ts +71 -0
  10. package/lib/animation/clips/clip.js +68 -0
  11. package/lib/animation/interpolate.d.ts +17 -0
  12. package/lib/animation/interpolate.js +71 -0
  13. package/lib/animation/keyframe.d.ts +24 -1
  14. package/lib/animation/layer.d.ts +73 -1
  15. package/lib/animation/layer.js +69 -0
  16. package/lib/animation/layerclip.d.ts +75 -0
  17. package/lib/animation/layerclip.js +69 -0
  18. package/lib/animation/stream.d.ts +49 -7
  19. package/lib/animation/stream.js +3 -0
  20. package/lib/animation/tracks/cliptrack.d.ts +64 -0
  21. package/lib/animation/tracks/cliptrack.js +65 -1
  22. package/lib/animation/tracks/functiontrack.d.ts +60 -0
  23. package/lib/animation/tracks/functiontrack.js +62 -3
  24. package/lib/animation/tracks/propertytrack.d.ts +84 -0
  25. package/lib/animation/tracks/propertytrack.js +75 -0
  26. package/lib/animation/tracks/streamtrack.d.ts +51 -0
  27. package/lib/animation/tracks/streamtrack.js +54 -3
  28. package/lib/animation/tracks/track.d.ts +56 -0
  29. package/lib/animation/tracks/track.js +40 -0
  30. package/lib/behavior.d.ts +37 -0
  31. package/lib/behavior.js +21 -0
  32. package/lib/behaviors/ActivateState.d.ts +10 -3
  33. package/lib/behaviors/ActivateState.js +8 -4
  34. package/lib/behaviors/CallFunction.d.ts +1 -1
  35. package/lib/behaviors/CallFunction.js +2 -2
  36. package/lib/behaviors/ConsoleLog.d.ts +1 -1
  37. package/lib/behaviors/ConsoleLog.js +2 -2
  38. package/lib/behaviors/DownloadSnapshot.d.ts +5 -2
  39. package/lib/behaviors/DownloadSnapshot.js +5 -2
  40. package/lib/behaviors/LaunchURL.d.ts +1 -1
  41. package/lib/behaviors/LaunchURL.js +1 -1
  42. package/lib/behaviors/LogAnalyticsEvent.d.ts +1 -1
  43. package/lib/behaviors/LogAnalyticsEvent.js +2 -2
  44. package/lib/behaviors/PauseLayerClip.d.ts +5 -3
  45. package/lib/behaviors/PauseLayerClip.js +3 -2
  46. package/lib/behaviors/PlayLayerClip.d.ts +10 -4
  47. package/lib/behaviors/PlayLayerClip.js +7 -5
  48. package/lib/behaviors/PlaySound.d.ts +4 -4
  49. package/lib/behaviors/PlaySound.js +4 -4
  50. package/lib/behaviors/SetLayerOff.d.ts +4 -3
  51. package/lib/behaviors/SetLayerOff.js +3 -2
  52. package/lib/behaviors/ShowTextAlert.d.ts +2 -2
  53. package/lib/behaviors/ShowTextAlert.js +5 -5
  54. package/lib/behaviors/ToggleLayerClips.d.ts +4 -3
  55. package/lib/behaviors/ToggleLayerClips.js +5 -4
  56. package/lib/behaviors/stream/PauseStream.d.ts +15 -3
  57. package/lib/behaviors/stream/PauseStream.js +13 -2
  58. package/lib/behaviors/stream/PlayStream.d.ts +14 -4
  59. package/lib/behaviors/stream/PlayStream.js +10 -3
  60. package/lib/behaviors/stream/SeekStream.d.ts +12 -3
  61. package/lib/behaviors/stream/SeekStream.js +10 -2
  62. package/lib/behaviors/stream/StopStream.d.ts +11 -3
  63. package/lib/behaviors/stream/StopStream.js +9 -2
  64. package/lib/component.d.ts +85 -5
  65. package/lib/component.js +49 -1
  66. package/lib/components/Audio.d.ts +14 -5
  67. package/lib/components/Audio.js +19 -10
  68. package/lib/components/AudioLayerSettings.d.ts +9 -3
  69. package/lib/components/AudioLayerSettings.js +9 -3
  70. package/lib/components/Children.d.ts +7 -2
  71. package/lib/components/Children.js +6 -1
  72. package/lib/components/DefaultCookieConsent.d.ts +13 -3
  73. package/lib/components/DefaultCookieConsent.js +62 -38
  74. package/lib/components/DefaultLoader.d.ts +14 -9
  75. package/lib/components/DefaultLoader.js +25 -20
  76. package/lib/components/Gamepad.d.ts +12 -4
  77. package/lib/components/Gamepad.js +16 -8
  78. package/lib/components/LongLoad.d.ts +7 -1
  79. package/lib/components/LongLoad.js +7 -1
  80. package/lib/components/SnapshotUI.d.ts +10 -0
  81. package/lib/components/SnapshotUI.js +24 -0
  82. package/lib/context.d.ts +117 -0
  83. package/lib/context.js +50 -71
  84. package/lib/contexts/analyticscontext.d.ts +6 -0
  85. package/lib/contexts/analyticscontext.js +6 -0
  86. package/lib/contexts/audiocontextcontext.d.ts +26 -1
  87. package/lib/contexts/audiocontextcontext.js +26 -1
  88. package/lib/contexts/canvascontext.d.ts +59 -1
  89. package/lib/contexts/canvascontext.js +54 -1
  90. package/lib/contexts/cookieconsentcontext.d.ts +84 -10
  91. package/lib/contexts/cookieconsentcontext.js +71 -0
  92. package/lib/contexts/environmentcontext.d.ts +40 -5
  93. package/lib/contexts/environmentcontext.js +40 -5
  94. package/lib/contexts/gamepadcontext.d.ts +38 -0
  95. package/lib/contexts/gamepadcontext.js +38 -0
  96. package/lib/contexts/gesturecontext.d.ts +31 -4
  97. package/lib/contexts/gesturecontext.js +28 -4
  98. package/lib/contexts/globaltagcontext.d.ts +14 -2
  99. package/lib/contexts/globaltagcontext.js +13 -1
  100. package/lib/contexts/loadcontext.d.ts +92 -5
  101. package/lib/contexts/loadcontext.js +98 -11
  102. package/lib/contexts/orientationcontext.d.ts +58 -1
  103. package/lib/contexts/orientationcontext.js +51 -1
  104. package/lib/contexts/snapshotContext.d.ts +97 -4
  105. package/lib/contexts/snapshotContext.js +115 -4
  106. package/lib/contexts/tagcontext.d.ts +56 -2
  107. package/lib/contexts/tagcontext.js +77 -7
  108. package/lib/contexts/textalertcontext.d.ts +35 -2
  109. package/lib/contexts/textalertcontext.js +20 -2
  110. package/lib/contexts/usereventcontext.d.ts +29 -0
  111. package/lib/contexts/usereventcontext.js +30 -1
  112. package/lib/data/animation.d.ts +163 -0
  113. package/lib/data/animation.js +9 -0
  114. package/lib/data/change.d.ts +199 -0
  115. package/lib/data/change.js +190 -0
  116. package/lib/emitter.d.ts +8 -1
  117. package/lib/emitter.js +7 -0
  118. package/lib/entity.d.ts +30 -5
  119. package/lib/entity.js +23 -7
  120. package/lib/event.d.ts +19 -2
  121. package/lib/event.js +19 -2
  122. package/lib/fractionalindexing.js +38 -42
  123. package/lib/inflate.d.ts +68 -0
  124. package/lib/inflate.js +76 -0
  125. package/lib/observable.d.ts +3 -3
  126. package/lib/observable.js +4 -4
  127. package/lib/profile.d.ts +27 -0
  128. package/lib/profile.js +26 -0
  129. package/lib/selectors.d.ts +114 -0
  130. package/lib/selectors.js +159 -7
  131. package/lib/types.d.ts +215 -0
  132. package/lib/types.js +110 -1
  133. package/lib/validators.d.ts +27 -0
  134. package/lib/validators.js +27 -0
  135. package/lib/values/values.d.ts +5 -0
  136. package/lib/values/values.js +5 -0
  137. package/lib/zcomponent.d.ts +72 -0
  138. package/lib/zcomponent.js +81 -0
  139. package/lib/zcomponentconstruction.d.ts +11 -1
  140. package/lib/zcomponentconstruction.js +10 -0
  141. package/package.json +7 -2
@@ -27,22 +27,54 @@ export interface ZComponentContextConstructorProps {
27
27
  export declare class ZComponentContext extends Context {
28
28
  zcomponent: ZComponent;
29
29
  children: ComponentChildren;
30
+ /**
31
+ * Creates an instance of ZComponentContext.
32
+ * @param contextManager - The current ContextManager
33
+ * @param props - The constructor properties.
34
+ */
30
35
  constructor(contextManager: ContextManager, props: ZComponentContextConstructorProps);
31
36
  }
32
37
  export declare class ZComponent<RootType = any> extends Component<RootType> {
33
38
  constructorProps: ConstructorProps;
34
39
  private _opts;
40
+ /**
41
+ * The id of the component.
42
+ */
35
43
  id: string;
44
+ /**
45
+ * A map of elements to node IDs.
46
+ */
36
47
  idByElement: Map<any, string>;
48
+ /**
49
+ * Object that maps node script names to scripts.
50
+ */
37
51
  nodes: {
38
52
  [id: string]: Component | Component[];
39
53
  };
54
+ /**
55
+ * Map of entites by ID.
56
+ */
40
57
  entityByID: Map<string, Entity>;
58
+ /**
59
+ * A map of entity labels to components.
60
+ */
41
61
  entityByLabel: Map<string, Entity>;
62
+ /**
63
+ * A map of node labels to components.
64
+ */
42
65
  nodeByLabel: Map<string, Component<any, ConstructorProps>>;
43
66
  private _constructedResolve;
67
+ /**
68
+ * A promise that is resolved once construction of this component is complete.
69
+ */
44
70
  constructed: Promise<void>;
71
+ /**
72
+ * A boolean indicating if construction of this component is complete.
73
+ */
45
74
  isConstructed: boolean;
75
+ /**
76
+ * The animation object for this component.
77
+ */
46
78
  animation: Animation;
47
79
  /**
48
80
  * @zstreams layerclipids
@@ -53,24 +85,64 @@ export declare class ZComponent<RootType = any> extends Component<RootType> {
53
85
  private _nodesById;
54
86
  private _behaviorsToInitialize;
55
87
  private _constructorPropOverridesByEntityID;
88
+ /**
89
+ * Creates an instance of ZComponent.
90
+ * @param contextManager - The current ContextManager
91
+ * @param constructorProps - The constructor properties.
92
+ * @param _opts - The options for the component.
93
+ */
56
94
  constructor(contextManager: ContextManager, constructorProps: ConstructorProps, _opts: ZComponentOptions);
57
95
  private _updateAnimationRegistrations;
58
96
  private _animationTick;
59
97
  private _constructorForNode;
60
98
  private _constructorForBehavior;
99
+ /**
100
+ * This function returns the component with the given ID. If the component is not found, it will return undefined.
101
+ * This function is used to get a component from a node ID, which is a string representation of a node.
102
+ * The node ID is used to identify a node in the graph.
103
+ * If a component constructor is passed as `type`, this function will ensure that the node that's returned
104
+ * is an instance of that component, or return undefined if it is not.
105
+ */
61
106
  resolveNodeID<T extends Component = Component>(id: string, type?: ConstructorForComponent<T>): T | undefined;
107
+ /**
108
+ * Resolves an entity ID to an entity instance.
109
+ *
110
+ * @param id - The ID of the entity to resolve.
111
+ * @returns The resolved entity as an instance of T (which extends Entity), or undefined if the entity could not be resolved.
112
+ * @template T The entity type.
113
+ */
62
114
  resolveEntityID<T extends Entity = Entity>(id: string): T | undefined;
63
115
  private _inflateBehaviors;
64
116
  private _wrapBehaviors;
65
117
  private _wrapFunctionCall;
118
+ /**
119
+ * Notifies the component that the properties of certain entities have changed.
120
+ *
121
+ * @param entries - A map where the keys are entity IDs and the values are sets of property names.
122
+ */
66
123
  notifyPropsChanged(entries: Map<string, Set<string>>): void;
124
+ /**
125
+ * The animation editor will call this function when the user changes
126
+ * the list of clips in the animation. We need to update the clip
127
+ * data for each clip that was changed.
128
+ */
67
129
  notifyClipsChanged(clips: Set<string>): void;
68
130
  private _initializeOverrides;
69
131
  private _initializeConstructorPropOverrides;
70
132
  private _initializeComponentProps;
71
133
  private _setEntityProp;
72
134
  private _setEntityPropPath;
135
+ /**
136
+ * Returns the node with the specified ID.
137
+ */
73
138
  _getNodeById(id: string): Component | undefined;
139
+ /**
140
+ * Rsolves a stream ID to a stream object. The stream ID is a string that
141
+ * is constructed from the entity ID of the stream's parent entity, followed by a
142
+ * period, followed by the name of the stream. This function splits the string into
143
+ * parts, and then uses the parts to traverse the entity tree until it finds the
144
+ * named stream.
145
+ */
74
146
  resolveStreamID(id: string): Stream | undefined;
75
147
  /**
76
148
  * Traverses the component tree starting from the current component,
package/lib/zcomponent.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-this-alias */
1
2
  import { Animation } from './animation/index';
2
3
  import { shouldBehaviorRunAtDesignTime } from './behavior';
3
4
  import { Component } from './component';
@@ -13,6 +14,11 @@ import { EntityPropOverrideType, FunctionCallType } from './data/core';
13
14
  import { Observable } from './observable';
14
15
  import { setCurrentZComponentConstruction } from './zcomponentconstruction';
15
16
  export class ZComponentContext extends Context {
17
+ /**
18
+ * Creates an instance of ZComponentContext.
19
+ * @param contextManager - The current ContextManager
20
+ * @param props - The constructor properties.
21
+ */
16
22
  constructor(contextManager, props) {
17
23
  super(contextManager, props);
18
24
  this.zcomponent = props.zcomponent;
@@ -20,17 +26,47 @@ export class ZComponentContext extends Context {
20
26
  }
21
27
  }
22
28
  export class ZComponent extends Component {
29
+ /**
30
+ * Creates an instance of ZComponent.
31
+ * @param contextManager - The current ContextManager
32
+ * @param constructorProps - The constructor properties.
33
+ * @param _opts - The options for the component.
34
+ */
23
35
  constructor(contextManager, constructorProps, _opts) {
24
36
  super(contextManager, { ...constructorProps, children: [] });
25
37
  this.constructorProps = constructorProps;
26
38
  this._opts = _opts;
39
+ /**
40
+ * A map of elements to node IDs.
41
+ */
27
42
  this.idByElement = new Map();
43
+ /**
44
+ * Object that maps node script names to scripts.
45
+ */
28
46
  this.nodes = {};
47
+ /**
48
+ * Map of entites by ID.
49
+ */
29
50
  this.entityByID = new Map();
51
+ /**
52
+ * A map of entity labels to components.
53
+ */
30
54
  this.entityByLabel = new Map();
55
+ /**
56
+ * A map of node labels to components.
57
+ */
31
58
  this.nodeByLabel = new Map();
59
+ /**
60
+ * A promise that is resolved once construction of this component is complete.
61
+ */
32
62
  this.constructed = new Promise(resolve => (this._constructedResolve = resolve));
63
+ /**
64
+ * A boolean indicating if construction of this component is complete.
65
+ */
33
66
  this.isConstructed = false;
67
+ /**
68
+ * The animation object for this component.
69
+ */
34
70
  this.animation = new Animation(false);
35
71
  /**
36
72
  * @zstreams layerclipids
@@ -89,6 +125,11 @@ export class ZComponent extends Component {
89
125
  }
90
126
  const that = this;
91
127
  return class extends construct {
128
+ /**
129
+ * Creates an instance of the component.
130
+ * @param contextManager - The current ContextManager
131
+ * @param constructorProps - The constructor properties.
132
+ */
92
133
  constructor(contextManager, constructorProps) {
93
134
  that._opts.onConstructingNode?.(nodeId);
94
135
  const children = constructorProps.children ?? [];
@@ -182,6 +223,12 @@ export class ZComponent extends Component {
182
223
  return;
183
224
  const that = this;
184
225
  return class extends construct {
226
+ /**
227
+ * Creates an instance of the behavior.
228
+ * @param contextManager - The current ContextManager
229
+ * @param instance - The instance of the component that this behavior is attached to
230
+ * @param constructorProps - The constructor properties.
231
+ */
185
232
  constructor(contextManager, instance, constructorProps) {
186
233
  constructorProps = {
187
234
  ...constructorProps,
@@ -221,6 +268,13 @@ export class ZComponent extends Component {
221
268
  }
222
269
  };
223
270
  }
271
+ /**
272
+ * This function returns the component with the given ID. If the component is not found, it will return undefined.
273
+ * This function is used to get a component from a node ID, which is a string representation of a node.
274
+ * The node ID is used to identify a node in the graph.
275
+ * If a component constructor is passed as `type`, this function will ensure that the node that's returned
276
+ * is an instance of that component, or return undefined if it is not.
277
+ */
224
278
  resolveNodeID(id, type) {
225
279
  const entity = this.entityByID.get(id);
226
280
  if (!entity)
@@ -233,6 +287,13 @@ export class ZComponent extends Component {
233
287
  return entity;
234
288
  return undefined;
235
289
  }
290
+ /**
291
+ * Resolves an entity ID to an entity instance.
292
+ *
293
+ * @param id - The ID of the entity to resolve.
294
+ * @returns The resolved entity as an instance of T (which extends Entity), or undefined if the entity could not be resolved.
295
+ * @template T The entity type.
296
+ */
236
297
  resolveEntityID(id) {
237
298
  const entity = this.entityByID.get(id);
238
299
  if (!entity)
@@ -311,6 +372,11 @@ export class ZComponent extends Component {
311
372
  };
312
373
  }
313
374
  }
375
+ /**
376
+ * Notifies the component that the properties of certain entities have changed.
377
+ *
378
+ * @param entries - A map where the keys are entity IDs and the values are sets of property names.
379
+ */
314
380
  notifyPropsChanged(entries) {
315
381
  for (const [entityID, propSet] of entries.entries()) {
316
382
  const entity = this.entityByID.get(entityID);
@@ -327,6 +393,11 @@ export class ZComponent extends Component {
327
393
  }
328
394
  }
329
395
  }
396
+ /**
397
+ * The animation editor will call this function when the user changes
398
+ * the list of clips in the animation. We need to update the clip
399
+ * data for each clip that was changed.
400
+ */
330
401
  notifyClipsChanged(clips) {
331
402
  for (const clipId of clips.values()) {
332
403
  const clip = this.animation.clipByID.get(clipId);
@@ -442,9 +513,19 @@ export class ZComponent extends Component {
442
513
  v = this._wrapFunctionCall(v);
443
514
  parent[currentKey] = v;
444
515
  }
516
+ /**
517
+ * Returns the node with the specified ID.
518
+ */
445
519
  _getNodeById(id) {
446
520
  return this._nodesById.get(id);
447
521
  }
522
+ /**
523
+ * Rsolves a stream ID to a stream object. The stream ID is a string that
524
+ * is constructed from the entity ID of the stream's parent entity, followed by a
525
+ * period, followed by the name of the stream. This function splits the string into
526
+ * parts, and then uses the parts to traverse the entity tree until it finds the
527
+ * named stream.
528
+ */
448
529
  resolveStreamID(id) {
449
530
  const parts = id.split('.');
450
531
  let obj = this.entityByID.get(parts[0]);
@@ -1,3 +1,13 @@
1
- import { ZComponent } from "./zcomponent";
1
+ import { ZComponent } from './zcomponent';
2
+ /**
3
+ * Retrieves the current `ZComponent` that is under construction.
4
+ *
5
+ * @returns The `ZComponent` currently under construction, or undefined if there isn't one.
6
+ */
2
7
  export declare function getCurrentZComponentConstruction(): ZComponent<any> | undefined;
8
+ /**
9
+ * Sets the current `ZComponent` that is under construction.
10
+ *
11
+ * @param z - The `ZComponent` to set as currently under construction, or undefined to clear the current construction.
12
+ */
3
13
  export declare function setCurrentZComponentConstruction(z: ZComponent | undefined): void;
@@ -1,7 +1,17 @@
1
1
  let currentZComponentConstruction;
2
+ /**
3
+ * Retrieves the current `ZComponent` that is under construction.
4
+ *
5
+ * @returns The `ZComponent` currently under construction, or undefined if there isn't one.
6
+ */
2
7
  export function getCurrentZComponentConstruction() {
3
8
  return currentZComponentConstruction;
4
9
  }
10
+ /**
11
+ * Sets the current `ZComponent` that is under construction.
12
+ *
13
+ * @param z - The `ZComponent` to set as currently under construction, or undefined to clear the current construction.
14
+ */
5
15
  export function setCurrentZComponentConstruction(z) {
6
16
  currentZComponentConstruction = z;
7
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "1.14.3",
3
+ "version": "1.16.0-beta",
4
4
  "description": "The core component model and built-in functionality for Mattercraft.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -23,14 +23,19 @@
23
23
  "build": "rm -rf lib && tsc",
24
24
  "build-animation-tests": "tsc -p ./tsconfig.test.animation.json",
25
25
  "test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --es-module-specifier-resolution=node",
26
- "watch": "tsc -w"
26
+ "watch": "tsc -w",
27
+ "predocs": "tsc",
28
+ "docs": "typedoc"
27
29
  },
28
30
  "author": "Zappar Limited",
29
31
  "license": "Proprietary",
30
32
  "devDependencies": {
31
33
  "@types/mocha": "^10.0.1",
34
+ "@zappar/typedoc-plugin-mattercraft": "^0.0.4",
32
35
  "mocha": "^10.2.0",
33
36
  "ts-node": "^10.9.1",
37
+ "typedoc": "^0.24.8",
38
+ "typedoc-plugin-mdn-links": "^3.1.7",
34
39
  "typescript": "^4.9.4"
35
40
  },
36
41
  "zexports": [