@zcomponent/core 1.23.0-beta.1 → 1.24.0-beta.1

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.
@@ -86,7 +86,7 @@ export declare class LayerClip implements Stream {
86
86
  *
87
87
  * @param opts Optional play options to customize playback behavior.
88
88
  */
89
- queue(opts?: LayerClipPlayOptions): void;
89
+ queue(opts?: LayerClipPlayOptions): this;
90
90
  /**
91
91
  * @returns The length of the clip.
92
92
  */
@@ -96,11 +96,11 @@ export declare class LayerClip implements Stream {
96
96
  *
97
97
  * @param opts Optional play options to customize playback behavior.
98
98
  */
99
- play(opts?: LayerClipPlayOptions): void;
99
+ play(opts?: LayerClipPlayOptions): this;
100
100
  /**
101
101
  * Pauses the playback of the clip.
102
102
  */
103
- pause(): void;
103
+ pause(): this;
104
104
  private _cancelStall;
105
105
  /**
106
106
  * Seeks to a specific time within the clip and optionally applies fade parameters.
@@ -108,7 +108,7 @@ export declare class LayerClip implements Stream {
108
108
  * @param ct The clip time to seek to.
109
109
  * @param opts Optional seek options, including fade parameters.
110
110
  */
111
- seek(ct: number, opts?: LayerClipSeekOptions): void;
111
+ seek(ct: number, opts?: LayerClipSeekOptions): this;
112
112
  /** @internal */
113
113
  _serialize(state: AnimationState): void;
114
114
  /** @internal */
@@ -122,7 +122,7 @@ export declare class LayerClip implements Stream {
122
122
  /**
123
123
  * Stops the clip's playback.
124
124
  */
125
- stop(): void;
125
+ stop(): this;
126
126
  /**
127
127
  * Determines if the clip is currently stalled.
128
128
  *
@@ -142,6 +142,7 @@ export class LayerClip {
142
142
  */
143
143
  queue(opts) {
144
144
  this.layer.queue(this, opts);
145
+ return this;
145
146
  }
146
147
  /**
147
148
  * @returns The length of the clip.
@@ -156,8 +157,7 @@ export class LayerClip {
156
157
  */
157
158
  play(opts) {
158
159
  if (opts?.speed === 0) {
159
- this.pause();
160
- return;
160
+ return this.pause();
161
161
  }
162
162
  this._stopped = false;
163
163
  this._loop = opts?.loop ?? this.defaultLoop;
@@ -201,6 +201,7 @@ export class LayerClip {
201
201
  this.clip.streamTick(this._state, bt, this._rate, this.layer.active === this, this.layer.active, loop !== this._lastLoop, this._stallStartTime !== undefined, 1);
202
202
  this._lastLoop = loop;
203
203
  this.state.value = this._state;
204
+ return this;
204
205
  }
205
206
  /**
206
207
  * Pauses the playback of the clip.
@@ -208,13 +209,14 @@ export class LayerClip {
208
209
  pause() {
209
210
  delete this._lastLoop;
210
211
  if (this._pauseTime !== undefined || this._state !== StreamState.Playing)
211
- return;
212
+ return this;
212
213
  this._state = StreamState.Paused;
213
214
  this.animation._pendingEvents.push({ evt: AnimationEvents.onLayerClipState, args: [this] });
214
215
  this._pauseTime = this._getTime();
215
216
  this._cancelStall();
216
217
  this.clip.streamPause(this.layer.active === this, this.layer.active);
217
218
  this.state.value = this._state;
219
+ return this;
218
220
  }
219
221
  _cancelStall() {
220
222
  if (this._stallStartTime === undefined)
@@ -232,14 +234,15 @@ export class LayerClip {
232
234
  * @param opts Optional seek options, including fade parameters.
233
235
  */
234
236
  seek(ct, opts) {
237
+ const clampedTime = Math.max(0, Math.min(ct, this.clip.length));
235
238
  const t = this._getTime();
236
239
  this._stopped = false;
237
240
  if (this._rate >= 0) {
238
- this._t0 = t - ct / this._rate;
241
+ this._t0 = t - clampedTime / this._rate;
239
242
  this._t1 = this._t0 + this.clip.length / this._rate;
240
243
  }
241
244
  else {
242
- this._t0 = t - (this.clip.length - ct) / -this._rate;
245
+ this._t0 = t - (this.clip.length - clampedTime) / -this._rate;
243
246
  this._t1 = this._t0 + this.clip.length / -this._rate;
244
247
  }
245
248
  if (this._pauseTime !== undefined) {
@@ -247,15 +250,16 @@ export class LayerClip {
247
250
  }
248
251
  if (this._loop)
249
252
  this._t1 = Infinity;
250
- this._lastClipTime = undefined;
251
- this._lastTickTime = undefined;
253
+ this._lastTickTime = clampedTime;
254
+ this._lastClipTime = clampedTime;
252
255
  if (this.layer.active !== this && !opts?.dontActivateLayer) {
253
256
  this.layer._activateLayerClip(this, { fade: opts?.fade });
254
257
  }
255
258
  delete this._lastLoop;
256
259
  delete this._stallStartTime;
257
- this.clip.streamSeek(ct, this._rate, this.layer.active === this, this.layer.active);
260
+ this.clip.streamSeek(clampedTime, this._rate, this.layer.active === this, this.layer.active);
258
261
  this.layer._evaulate();
262
+ return this;
259
263
  }
260
264
  /** @internal */
261
265
  _serialize(state) {
@@ -316,6 +320,7 @@ export class LayerClip {
316
320
  this._state = StreamState.Ended;
317
321
  this.animation._pendingEvents.push({ evt: AnimationEvents.onLayerClipState, args: [this] });
318
322
  this.state.value = this._state;
323
+ return this;
319
324
  }
320
325
  /**
321
326
  * Determines if the clip is currently stalled.
@@ -0,0 +1,12 @@
1
+ import type { EnvironmentContext } from './environmentcontext';
2
+ import type { LoadContext } from './loadcontext';
3
+ /**
4
+ * Internal context that manages the document flags.
5
+ */
6
+ export declare class DocumentFlagManager {
7
+ private readonly _environmentContext;
8
+ private readonly _loadContext;
9
+ constructor(_environmentContext: EnvironmentContext, _loadContext: LoadContext);
10
+ private _update;
11
+ dispose(): void;
12
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Internal context that manages the document flags.
3
+ */
4
+ export class DocumentFlagManager {
5
+ constructor(_environmentContext, _loadContext) {
6
+ this._environmentContext = _environmentContext;
7
+ this._loadContext = _loadContext;
8
+ this._update = () => {
9
+ if (!document?.body)
10
+ return;
11
+ document.body.classList.toggle('zcomponent-designtime', this._environmentContext.designTime.value);
12
+ document.body.classList.toggle('zcomponent-runtime', this._environmentContext.runTime.value);
13
+ document.body.classList.toggle('zcomponent-development', this._environmentContext.developmentBuild.value);
14
+ document.body.classList.toggle('zcomponent-production', this._environmentContext.productionBuild.value);
15
+ document.body.classList.toggle('zcomponent-started', this._loadContext.isStarted.value);
16
+ document.body.classList.toggle('zcomponent-launched', this._loadContext.isLaunched.value);
17
+ document.body.classList.toggle('zcomponent-loaded', this._loadContext.isLoaded.value);
18
+ };
19
+ this._update();
20
+ this._environmentContext.designTime.addListener(this._update);
21
+ this._environmentContext.runTime.addListener(this._update);
22
+ this._environmentContext.productionBuild.addListener(this._update);
23
+ this._environmentContext.developmentBuild.addListener(this._update);
24
+ this._loadContext.isStarted.addListener(this._update);
25
+ this._loadContext.isLaunched.addListener(this._update);
26
+ this._loadContext.isLoaded.addListener(this._update);
27
+ }
28
+ dispose() {
29
+ this._environmentContext.designTime.removeListener(this._update);
30
+ this._environmentContext.runTime.removeListener(this._update);
31
+ this._environmentContext.productionBuild.removeListener(this._update);
32
+ this._environmentContext.developmentBuild.removeListener(this._update);
33
+ this._loadContext.isStarted.removeListener(this._update);
34
+ this._loadContext.isLaunched.removeListener(this._update);
35
+ this._loadContext.isLoaded.removeListener(this._update);
36
+ }
37
+ }
@@ -27,6 +27,9 @@ export declare class EnvironmentContext extends Context {
27
27
  * @zprop
28
28
  * */
29
29
  readonly productionBuild: Observable<boolean, never>;
30
+ private readonly _documentFlagManager;
31
+ constructor(contextManager: ContextManager, props: {});
32
+ dispose(): never;
30
33
  }
31
34
  /**
32
35
  * Determines if the application is in design time.
@@ -1,9 +1,11 @@
1
1
  import { Context } from '../context';
2
2
  import { Observable } from '../observable';
3
+ import { DocumentFlagManager } from './documentflagmanager';
4
+ import { LoadContext } from './loadcontext';
3
5
  /** @zcontext */
4
6
  export class EnvironmentContext extends Context {
5
- constructor() {
6
- super(...arguments);
7
+ constructor(contextManager, props) {
8
+ super(contextManager, props);
7
9
  /**
8
10
  * Observable indicating if the application is in design time.
9
11
  * @zprop
@@ -29,6 +31,12 @@ export class EnvironmentContext extends Context {
29
31
  * @zprop
30
32
  * */
31
33
  this.productionBuild = new Observable(!this.developmentBuild.value);
34
+ const loadContext = this.contextManager.get(LoadContext);
35
+ this._documentFlagManager = new DocumentFlagManager(this, loadContext);
36
+ }
37
+ dispose() {
38
+ this._documentFlagManager.dispose();
39
+ return super.dispose();
32
40
  }
33
41
  }
34
42
  /**
@@ -74,8 +74,6 @@ export class LoadContext extends Context {
74
74
  start() {
75
75
  if (this.isStarted.value)
76
76
  return;
77
- if (document.body)
78
- document.body.classList.add('zcomponent-started');
79
77
  this.isStarted.value = true;
80
78
  this._startedResolved?.();
81
79
  }
@@ -94,8 +92,6 @@ export class LoadContext extends Context {
94
92
  launch() {
95
93
  if (this.isLaunched.value)
96
94
  return;
97
- if (document.body)
98
- document.body.classList.add('zcomponent-launched');
99
95
  this.isLaunched.value = true;
100
96
  this._launchedResolved();
101
97
  }
@@ -107,8 +103,6 @@ export class LoadContext extends Context {
107
103
  }
108
104
  if (this._loadables.size === 0 && this.isLoaded.value === false) {
109
105
  this.isLoaded.value = true;
110
- if (document.body)
111
- document.body.classList.add('zcomponent-loaded');
112
106
  }
113
107
  this.progressPercent.value = this.isLoaded.value ? 100 : (100 * this._loadedCount) / this._totalLoadables;
114
108
  if (this._startWhenLoaded && this.isLoaded.value && !this.isStarted.value) {
@@ -49,6 +49,11 @@ export interface ZComponentData {
49
49
  [id: string]: boolean;
50
50
  };
51
51
  };
52
+ group?: string;
53
+ icon?: string;
54
+ tags?: string[];
55
+ allowedParents?: string[];
56
+ comments?: string[];
52
57
  }
53
58
  export interface NodeData {
54
59
  id: string;
@@ -104,7 +104,7 @@ export declare const typeDefinitionForComponent: (nodes: NodeByID, props: Props,
104
104
  [id: string]: {
105
105
  [id: string]: boolean;
106
106
  };
107
- } | undefined, layers: Data.ByID<Data.Layer>, behaviors: BehaviorByID) => string;
107
+ } | undefined, layers: Data.ByID<Data.Layer>, behaviors: BehaviorByID, group: string | undefined, tags: string[] | undefined, icon: string | undefined, comments?: string[] | undefined, parents?: string[] | undefined) => string;
108
108
  /**
109
109
  * Sanitizes a key name to ensure it is safe for use in scripting.
110
110
  *
package/lib/selectors.js CHANGED
@@ -288,7 +288,7 @@ function typeContainsType(p, name) {
288
288
  * @param behaviors - The behaviors of the ZComponent.
289
289
  * @returns A string containing the TypeScript type definition for the ZComponent.
290
290
  */
291
- export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, layers, behaviors) => {
291
+ export const typeDefinitionForComponent = (nodes, props, constructorProps, scriptNames, layers, behaviors, group, tags, icon, comments, parents) => {
292
292
  const importMapping = new Map();
293
293
  let indx = 0;
294
294
  const importStrings = [];
@@ -319,6 +319,14 @@ export const typeDefinitionForComponent = (nodes, props, constructorProps, scrip
319
319
  }
320
320
  }
321
321
  }
322
+ const jsdoc = [
323
+ ...(comments ? [...comments.map(entry => entry.replaceAll('\r', '').split('\n')).flat(), ''] : []),
324
+ '@zcomponent',
325
+ `@zicon ${icon ?? 'zcomponent'}`,
326
+ ...(group ? [`@zgroup ${group}`] : []),
327
+ ...(tags ?? []).map(tag => `@ztag ${tag}`),
328
+ ...(parents ?? []).map(parent => `@zparents ${parent}`),
329
+ ];
322
330
  return `import { ZComponent, ContextManager, Observable, Animation, Layer, LayerClip, Event } from "@zcomponent/core";
323
331
 
324
332
  ${importStrings.join('\n')}
@@ -330,8 +338,7 @@ ${Object.values(constructorProps ?? {})
330
338
  }
331
339
 
332
340
  /**
333
- * @zcomponent
334
- * @zicon zcomponent
341
+ * ${jsdoc.join('\n* ')}
335
342
  */
336
343
  declare class Comp extends ZComponent {
337
344
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "1.23.0-beta.1",
3
+ "version": "1.24.0-beta.1",
4
4
  "description": "The core component model and built-in functionality for Mattercraft.",
5
5
  "author": "Zappar Limited",
6
6
  "license": "Proprietary",