@zcomponent/core 1.12.0 → 1.13.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.
@@ -33,5 +33,6 @@ export declare class Clip {
33
33
  resolveClipTime(t: number, t0: number, s0: number, rate: number, t1?: number): number;
34
34
  streamPause(isActive: boolean, active: LayerClip | null | undefined): void;
35
35
  streamSeek(t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined): void;
36
- streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, parentWeight?: number): void;
36
+ streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, stalled?: boolean, parentWeight?: number): void;
37
+ stalled(): boolean;
37
38
  }
@@ -126,9 +126,16 @@ export class Clip {
126
126
  track.streamSeek(t, rate, isActive, active);
127
127
  }
128
128
  }
129
- streamTick(clipState, t, rate, isActive, active, force = false, parentWeight) {
129
+ streamTick(clipState, t, rate, isActive, active, force = false, stalled = false, parentWeight) {
130
130
  for (const track of this._streamTracks) {
131
- track.streamTick(clipState, t, rate, isActive, active, force, parentWeight);
131
+ track.streamTick(clipState, t, rate, isActive, active, force, stalled, parentWeight);
132
132
  }
133
133
  }
134
+ stalled() {
135
+ for (const track of this._tracks) {
136
+ if (track.stalled())
137
+ return true;
138
+ }
139
+ return false;
140
+ }
134
141
  }
@@ -16,6 +16,7 @@ export declare class LayerClip implements Stream {
16
16
  readonly animation: Animation;
17
17
  private _t0;
18
18
  private _pauseTime;
19
+ private _stallStartTime;
19
20
  private _t1;
20
21
  private _rate;
21
22
  private _loop;
@@ -34,6 +35,7 @@ export declare class LayerClip implements Stream {
34
35
  length(): number;
35
36
  play(opts?: LayerClipPlayOptions): void;
36
37
  pause(): void;
38
+ private _cancelStall;
37
39
  seek(ct: number, opts?: LayerClipSeekOptions): void;
38
40
  /** @internal */
39
41
  _serialize(state: AnimationState): void;
@@ -41,6 +43,7 @@ export declare class LayerClip implements Stream {
41
43
  _restore(state: AnimationState): void;
42
44
  get clipTime(): number;
43
45
  stop(): void;
46
+ stalled(): boolean;
44
47
  }
45
48
  export interface LayerClipSeekOptions {
46
49
  fade?: FadeParameters | null;
@@ -30,8 +30,16 @@ export class LayerClip {
30
30
  }
31
31
  tick(touchedPaths, force) {
32
32
  const t = this._getTime();
33
- const t0 = this._t0 + (t - (this._pauseTime ?? t));
34
- const t1 = this._t1 + (t - (this._pauseTime ?? t));
33
+ if (this._stallStartTime !== undefined) {
34
+ if (!this.clip.stalled())
35
+ this._cancelStall();
36
+ }
37
+ else if (this.state === StreamState.Playing) {
38
+ if (this.clip.stalled())
39
+ this._stallStartTime = t;
40
+ }
41
+ const t0 = this._t0 + (t - (this._pauseTime ?? t)) + (t - (this._stallStartTime ?? t));
42
+ const t1 = this._t1 + (t - (this._pauseTime ?? t)) + (t - (this._stallStartTime ?? t));
35
43
  const ct = this.clip.resolveClipTime(t, t0, this._rate >= 0 ? 0 : this.clip.length, this._rate, t1);
36
44
  this._lastTickTime = ct;
37
45
  if (ct !== this._lastClipTime || force) {
@@ -43,25 +51,25 @@ export class LayerClip {
43
51
  }
44
52
  else {
45
53
  const [bt, loop] = resolveClipTimeLoops(t, t0, this._rate >= 0 ? 0 : this.clip.length, this._rate, this.clip.length, this._rate < 0, t1);
46
- this.clip.streamTick(this.state, bt, this._rate, this.layer.active === this, this.layer.active, loop !== this._lastLoop, 1);
54
+ this.clip.streamTick(this.state, bt, this._rate, this.layer.active === this, this.layer.active, loop !== this._lastLoop, this._stallStartTime !== undefined, 1);
47
55
  this._lastLoop = loop;
48
56
  }
49
57
  }
50
58
  computePathProperty(p, valueBefore) {
51
59
  const t = this._getTime();
52
- const t0 = this._t0 + (t - (this._pauseTime ?? t));
53
- const t1 = this._t1 + (t - (this._pauseTime ?? t));
60
+ const t0 = this._t0 + (t - (this._pauseTime ?? t)) + (t - (this._stallStartTime ?? t));
61
+ const t1 = this._t1 + (t - (this._pauseTime ?? t)) + (t - (this._stallStartTime ?? t));
54
62
  const ct = this.clip.resolveClipTime(t, t0, this._rate >= 0 ? 0 : this.clip.length, this._rate, t1);
55
63
  this._lastClipTime = ct;
56
64
  return this.clip.computePathProperty(ct ?? 0, p, valueBefore);
57
65
  }
58
66
  getRemainingTimeEstimate() {
59
67
  const t = this._getTime();
60
- const t1 = this._t1 + (t - (this._pauseTime ?? t));
68
+ const t1 = this._t1 + (t - (this._pauseTime ?? t)) + (t - (this._stallStartTime ?? t));
61
69
  return t1 - t;
62
70
  }
63
71
  _getTime() {
64
- return this.timeSource?.() ?? this.animation.timeSource?.() ?? performance.now();
72
+ return this.timeSource?.() ?? this.animation?.timeSource?.() ?? performance.now();
65
73
  }
66
74
  queue(opts) {
67
75
  this.layer.queue(this, opts);
@@ -108,8 +116,10 @@ export class LayerClip {
108
116
  this.layer._activateLayerClip(this, opts);
109
117
  this.layer._evaulate();
110
118
  }
119
+ if (this.clip.stalled())
120
+ this._stallStartTime = t;
111
121
  const [bt, loop] = resolveClipTimeLoops(t, t0, this._rate >= 0 ? 0 : this.clip.length, this._rate, this.clip.length, this._rate < 0, t1);
112
- this.clip.streamTick(this.state, bt, this._rate, this.layer.active === this, this.layer.active, loop !== this._lastLoop, 1);
122
+ this.clip.streamTick(this.state, bt, this._rate, this.layer.active === this, this.layer.active, loop !== this._lastLoop, this._stallStartTime !== undefined, 1);
113
123
  this._lastLoop = loop;
114
124
  }
115
125
  pause() {
@@ -119,8 +129,17 @@ export class LayerClip {
119
129
  this.state = StreamState.Paused;
120
130
  this.animation._pendingEvents.push({ evt: AnimationEvents.onLayerClipState, args: [this] });
121
131
  this._pauseTime = this._getTime();
132
+ this._cancelStall();
122
133
  this.clip.streamPause(this.layer.active === this, this.layer.active);
123
134
  }
135
+ _cancelStall() {
136
+ if (this._stallStartTime === undefined)
137
+ return;
138
+ const t = this._getTime();
139
+ this._t0 += t - this._stallStartTime;
140
+ this._t1 += t - this._stallStartTime;
141
+ delete this._stallStartTime;
142
+ }
124
143
  seek(ct, opts) {
125
144
  const t = this._getTime();
126
145
  this._stopped = false;
@@ -143,6 +162,7 @@ export class LayerClip {
143
162
  this.layer._activateLayerClip(this, { fade: opts?.fade });
144
163
  }
145
164
  delete this._lastLoop;
165
+ delete this._stallStartTime;
146
166
  this.clip.streamSeek(ct, this._rate, this.layer.active === this, this.layer.active);
147
167
  this.layer._evaulate();
148
168
  }
@@ -190,9 +210,13 @@ export class LayerClip {
190
210
  this._lastClipTime = undefined;
191
211
  this._lastTickTime = undefined;
192
212
  delete this._lastLoop;
213
+ delete this._stallStartTime;
193
214
  this._rate = 1;
194
215
  this.clip.streamTick(StreamState.Ended, this._t0, 1, this.layer.active === this, this.layer.active, true);
195
216
  this.state = StreamState.Ended;
196
217
  this.animation._pendingEvents.push({ evt: AnimationEvents.onLayerClipState, args: [this] });
197
218
  }
219
+ stalled() {
220
+ return this._stallStartTime !== undefined;
221
+ }
198
222
  }
@@ -9,6 +9,7 @@ export interface Stream {
9
9
  seek: (t: number) => void;
10
10
  stop: () => void;
11
11
  length?: () => number | undefined;
12
+ stalled?: () => boolean;
12
13
  }
13
14
  export interface PlayOptions {
14
15
  speed?: number;
@@ -29,6 +29,7 @@ export declare class ClipTrack extends Track {
29
29
  computePathProperty(t: number, p: string, valueBefore: any, parentWeight?: number): any;
30
30
  streamPause(isActive: boolean, active: LayerClip | null | undefined): void;
31
31
  streamSeek(t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined): void;
32
- streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, parentWeight?: number): void;
32
+ streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, stalled?: boolean, parentWeight?: number): void;
33
33
  private _resolveBlock;
34
+ stalled(): boolean;
34
35
  }
@@ -79,7 +79,7 @@ export class ClipTrack extends Track {
79
79
  return;
80
80
  }
81
81
  }
82
- streamTick(clipState, t, rate, isActive, active, force = false, parentWeight) {
82
+ streamTick(clipState, t, rate, isActive, active, force = false, stalled = false, parentWeight) {
83
83
  if (force)
84
84
  delete this._lastLoopNumber;
85
85
  const block = this._resolveBlock(t, rate);
@@ -94,7 +94,7 @@ export class ClipTrack extends Track {
94
94
  this.clip.streamPause(isActive, active);
95
95
  }
96
96
  else {
97
- this.clip.streamTick(clipState, bt, rate * block.rate, isActive, active, this._lastLoopNumber !== loopNumber || block !== lastBlock, parentWeight);
97
+ this.clip.streamTick(clipState, bt, rate * block.rate, isActive, active, this._lastLoopNumber !== loopNumber || block !== lastBlock, stalled, parentWeight);
98
98
  this._lastLoopNumber = loopNumber;
99
99
  }
100
100
  }
@@ -113,4 +113,7 @@ export class ClipTrack extends Track {
113
113
  }
114
114
  return undefined;
115
115
  }
116
+ stalled() {
117
+ return this.clip.stalled();
118
+ }
116
119
  }
@@ -25,7 +25,7 @@ export declare class FunctionTrack extends Track {
25
25
  }): void;
26
26
  get sortedBlocks(): ResolvedFunctionTrackEntity[];
27
27
  streamSeek(t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined): void;
28
- streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, parentWeight?: number): void;
28
+ streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, stalled?: boolean, parentWeight?: number): void;
29
29
  streamPause(isActive: boolean, active: LayerClip | null | undefined): void;
30
30
  private _resolveBlocksBetween;
31
31
  private _getBoundedT;
@@ -32,7 +32,7 @@ export class FunctionTrack extends Track {
32
32
  streamSeek(t, rate, isActive, active) {
33
33
  this._lastTick = t;
34
34
  }
35
- streamTick(clipState, t, rate, isActive, active, force = false, parentWeight) {
35
+ streamTick(clipState, t, rate, isActive, active, force = false, stalled = false, parentWeight) {
36
36
  // if (clipState !== StreamState.Playing || this._lastTick === undefined) {
37
37
  // this._lastTick = t;
38
38
  // return;
@@ -36,7 +36,8 @@ export declare class StreamTrack extends Track {
36
36
  streamSeek(t: number, resolvedRate: number, isActive: boolean, active: LayerClip | null | undefined): void;
37
37
  private _isPlayingInClip;
38
38
  private _isPlayingInLayerClip;
39
- streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, parentWeight?: number): void;
39
+ streamTick(clipState: StreamState, t: number, rate: number, isActive: boolean, active: LayerClip | null | undefined, force?: boolean, stalled?: boolean, parentWeight?: number): void;
40
40
  private _applyState;
41
41
  private _resolveBlock;
42
+ stalled(): boolean;
42
43
  }
@@ -99,7 +99,7 @@ export class StreamTrack extends Track {
99
99
  return false;
100
100
  return this._isPlayingInClip(stream, layerClip.clip);
101
101
  }
102
- streamTick(clipState, t, rate, isActive, active, force = false, parentWeight) {
102
+ streamTick(clipState, t, rate, isActive, active, force = false, stalled = false, parentWeight) {
103
103
  if (!isActive && this._isPlayingInLayerClip(active)) {
104
104
  delete this._lastLoopNumber;
105
105
  return;
@@ -110,7 +110,7 @@ export class StreamTrack extends Track {
110
110
  let desiredState = clipState;
111
111
  const lastBlock = this._lastTick === undefined ? undefined : this._resolveBlock(this._lastTick, rate);
112
112
  this._lastTick = t;
113
- if (!block) {
113
+ if (!block || stalled) {
114
114
  desiredState = StreamState.Paused;
115
115
  }
116
116
  else {
@@ -158,4 +158,7 @@ export class StreamTrack extends Track {
158
158
  }
159
159
  return undefined;
160
160
  }
161
+ stalled() {
162
+ return this.stream?.stalled?.() ?? false;
163
+ }
161
164
  }
@@ -7,6 +7,7 @@ export declare abstract class Track {
7
7
  constructor(anim: Animation, id?: string | undefined);
8
8
  abstract get influencedPaths(): string[];
9
9
  abstract computePathProperty(t: number, p: string, valueBefore: any, parentWeight?: number): any;
10
+ stalled(): boolean;
10
11
  }
11
12
  export declare function resolveKeyframeValue(t: number, before: Keyframe, after: Keyframe | undefined): any;
12
13
  export declare function resolveKeyframes(keyframes: Keyframe[], t: number): [before: Keyframe | undefined, after: Keyframe | undefined];
@@ -8,6 +8,9 @@ export class Track {
8
8
  if (id)
9
9
  anim.trackByID.set(id, this);
10
10
  }
11
+ stalled() {
12
+ return false;
13
+ }
11
14
  }
12
15
  export function resolveKeyframeValue(t, before, after) {
13
16
  if (!after || !before.easing)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "1.12.0",
4
- "description": "",
3
+ "version": "1.13.0-beta",
4
+ "description": "The core component model and built-in functionality for Mattercraft.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "engines": {