j-templates 7.0.65 → 7.0.67
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/DOM/domNodeConfig.js +3 -1
- package/DOM/index.js +1 -0
- package/DOM/svgElements.js +12 -0
- package/Node/component.d.ts +73 -10
- package/Node/component.js +117 -15
- package/Node/vNode.js +78 -46
- package/Node/vNode.types.d.ts +1 -3
- package/Store/Store/storeAsync.d.ts +78 -0
- package/Store/Store/storeAsync.js +74 -0
- package/Store/Store/storeSync.d.ts +62 -0
- package/Store/Store/storeSync.js +58 -0
- package/Store/Tree/observableNode.d.ts +1 -0
- package/Store/Tree/observableNode.js +6 -2
- package/Store/Tree/observableScope.d.ts +16 -41
- package/Store/Tree/observableScope.js +192 -207
- package/Utils/animation.d.ts +43 -0
- package/Utils/animation.js +50 -3
- package/Utils/array.d.ts +48 -0
- package/Utils/array.js +56 -0
- package/Utils/decorators.d.ts +140 -5
- package/Utils/decorators.js +281 -28
- package/Utils/emitter.js +6 -4
- package/Utils/injector.d.ts +24 -0
- package/Utils/injector.js +27 -0
- package/Utils/list.js +4 -4
- package/Utils/router.js +110 -0
- package/Utils/thread.d.ts +75 -0
- package/Utils/thread.js +79 -0
- package/package.json +1 -1
|
@@ -1,144 +1,222 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObservableScope =
|
|
3
|
+
exports.ObservableScope = void 0;
|
|
4
4
|
exports.CalcScope = CalcScope;
|
|
5
5
|
const array_1 = require("../../Utils/array");
|
|
6
6
|
const emitter_1 = require("../../Utils/emitter");
|
|
7
7
|
const functions_1 = require("../../Utils/functions");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
function CreateDynamicScope(getFunction, greedy, value) {
|
|
9
|
+
const async = (0, functions_1.IsAsync)(getFunction);
|
|
10
|
+
const scope = {
|
|
11
|
+
type: "dynamic",
|
|
12
|
+
async,
|
|
13
|
+
greedy: greedy || async,
|
|
14
|
+
dirty: false,
|
|
15
|
+
destroyed: false,
|
|
16
|
+
getFunction,
|
|
17
|
+
setCallback: function () {
|
|
18
|
+
return OnSet(scope);
|
|
19
|
+
},
|
|
20
|
+
value,
|
|
21
|
+
emitter: emitter_1.Emitter.Create(),
|
|
22
|
+
emitters: null,
|
|
23
|
+
onDestroyed: null,
|
|
24
|
+
calcScopes: null,
|
|
25
|
+
};
|
|
26
|
+
return scope;
|
|
27
|
+
}
|
|
28
|
+
function CreateStaticScope(initialValue) {
|
|
29
|
+
return {
|
|
30
|
+
type: "static",
|
|
31
|
+
value: initialValue,
|
|
32
|
+
};
|
|
15
33
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
let scopeQueue = [];
|
|
35
|
+
function ProcessScopeQueue() {
|
|
36
|
+
const queue = scopeQueue;
|
|
37
|
+
scopeQueue = [];
|
|
38
|
+
for (let x = 0; x < queue.length; x++) {
|
|
39
|
+
const scope = queue[x];
|
|
40
|
+
if (!scope.destroyed) {
|
|
41
|
+
const value = scope.value;
|
|
42
|
+
ExecuteScope(scope);
|
|
43
|
+
if (scope.value !== value)
|
|
44
|
+
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
23
45
|
}
|
|
24
46
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
}
|
|
48
|
+
function OnSetQueued(scope) {
|
|
49
|
+
if (scopeQueue.length === 0)
|
|
50
|
+
queueMicrotask(ProcessScopeQueue);
|
|
51
|
+
scopeQueue.push(scope);
|
|
52
|
+
}
|
|
53
|
+
function OnSet(scope) {
|
|
54
|
+
if (scope.type === "static" || scope.destroyed)
|
|
55
|
+
return true;
|
|
56
|
+
if (scope.dirty)
|
|
57
|
+
return false;
|
|
58
|
+
scope.dirty = true;
|
|
59
|
+
if (scope.greedy) {
|
|
60
|
+
OnSetQueued(scope);
|
|
61
|
+
return;
|
|
33
62
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
function RegisterEmitter(emitter) {
|
|
67
|
+
if (watchState.emitterIds) {
|
|
68
|
+
if (!watchState.emitterIds.has(emitter[0])) {
|
|
69
|
+
watchState.emitters.push(emitter);
|
|
70
|
+
watchState.emitterIds.add(emitter[0]);
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
38
73
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
74
|
+
watchState.emitters.push(emitter);
|
|
75
|
+
if (watchState.emitters.length > 50) {
|
|
76
|
+
const idSet = (watchState.emitterIds = new Set());
|
|
77
|
+
let writePos = 0;
|
|
78
|
+
for (let x = 1; x < watchState.emitters.length; x++) {
|
|
79
|
+
if (!idSet.has(watchState.emitters[x][0])) {
|
|
80
|
+
watchState.emitters[++writePos] = watchState.emitters[x];
|
|
81
|
+
idSet.add(watchState.emitters[x][0]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
writePos++;
|
|
85
|
+
if (writePos < watchState.emitters.length)
|
|
86
|
+
watchState.emitters.splice(writePos);
|
|
42
87
|
}
|
|
43
88
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
89
|
+
function RegisterScope(scope) {
|
|
90
|
+
if (watchState === null || scope.type === "static")
|
|
91
|
+
return;
|
|
92
|
+
RegisterEmitter(scope.emitter);
|
|
93
|
+
}
|
|
94
|
+
function GetScopeValue(scope) {
|
|
95
|
+
if (scope.type === "static" || !scope.dirty || scope.destroyed)
|
|
96
|
+
return scope.value;
|
|
97
|
+
ExecuteScope(scope);
|
|
98
|
+
return scope.value;
|
|
49
99
|
}
|
|
50
|
-
exports.ObservableScope = ObservableScope;
|
|
51
100
|
let watchState = null;
|
|
52
|
-
function
|
|
101
|
+
function WatchFunction(callback, currentCalc = null) {
|
|
53
102
|
const parent = watchState;
|
|
54
|
-
watchState =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
scope.calcScopes = watchState[2];
|
|
103
|
+
watchState = {
|
|
104
|
+
value: null,
|
|
105
|
+
emitters: [],
|
|
106
|
+
emitterIds: null,
|
|
107
|
+
currentCalc: currentCalc,
|
|
108
|
+
nextCalc: null,
|
|
109
|
+
};
|
|
110
|
+
watchState.value = callback();
|
|
111
|
+
const resultState = watchState;
|
|
65
112
|
watchState = parent;
|
|
66
|
-
return
|
|
113
|
+
return resultState;
|
|
67
114
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
115
|
+
function ExecuteScope(scope) {
|
|
116
|
+
scope.dirty = false;
|
|
117
|
+
const state = WatchFunction(scope.getFunction, scope.calcScopes);
|
|
118
|
+
UpdateEmitters(scope, state.emitters, !!state.emitterIds);
|
|
119
|
+
const calcScopes = state.currentCalc;
|
|
120
|
+
for (const key in calcScopes)
|
|
121
|
+
DestroyScope(calcScopes[key]);
|
|
122
|
+
scope.calcScopes = state.nextCalc;
|
|
123
|
+
if (scope.async)
|
|
124
|
+
state.value.then(function (result) {
|
|
125
|
+
scope.value = result;
|
|
126
|
+
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
127
|
+
});
|
|
128
|
+
else
|
|
129
|
+
scope.value = state.value;
|
|
130
|
+
}
|
|
131
|
+
function ExecuteFunction(callback, greedy, allowStatic) {
|
|
132
|
+
const async = (0, functions_1.IsAsync)(callback);
|
|
133
|
+
const state = WatchFunction(callback);
|
|
134
|
+
if (!allowStatic || async || state.emitters.length > 0) {
|
|
135
|
+
const scope = CreateDynamicScope(callback, greedy, async ? null : state.value);
|
|
136
|
+
scope.calcScopes = state.nextCalc;
|
|
137
|
+
UpdateEmitters(scope, state.emitters, !!state.emitterIds);
|
|
138
|
+
if (async)
|
|
139
|
+
state.value.then(function (result) {
|
|
140
|
+
scope.value = result;
|
|
141
|
+
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
142
|
+
});
|
|
143
|
+
return scope;
|
|
79
144
|
}
|
|
80
|
-
|
|
81
|
-
return [async ? null : result, scope];
|
|
145
|
+
return CreateStaticScope(state.value);
|
|
82
146
|
}
|
|
83
147
|
function CalcScope(callback, idOverride) {
|
|
84
148
|
if (watchState === null)
|
|
85
149
|
return callback();
|
|
86
|
-
const nextScopes = (watchState
|
|
87
|
-
const currentScopes = watchState[1];
|
|
150
|
+
const nextScopes = (watchState.nextCalc ??= {});
|
|
88
151
|
const id = idOverride ?? callback.toString();
|
|
89
|
-
|
|
90
|
-
|
|
152
|
+
if (nextScopes[id]) {
|
|
153
|
+
RegisterScope(nextScopes[id]);
|
|
154
|
+
return GetScopeValue(nextScopes[id]);
|
|
155
|
+
}
|
|
156
|
+
const currentScopes = watchState.currentCalc;
|
|
157
|
+
nextScopes[id] = currentScopes?.[id] ?? ExecuteFunction(callback, true, true);
|
|
158
|
+
if (currentScopes?.[id])
|
|
91
159
|
delete currentScopes[id];
|
|
92
|
-
|
|
160
|
+
RegisterScope(nextScopes[id]);
|
|
161
|
+
return GetScopeValue(nextScopes[id]);
|
|
162
|
+
}
|
|
163
|
+
function UpdateEmitters(scope, right, distinct = false) {
|
|
164
|
+
distinct ? emitter_1.Emitter.Sort(right) : emitter_1.Emitter.Distinct(right);
|
|
165
|
+
if (scope.emitters === null) {
|
|
166
|
+
for (let x = 0; x < right.length; x++)
|
|
167
|
+
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
168
|
+
scope.emitters = right;
|
|
169
|
+
return;
|
|
93
170
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
171
|
+
if (right.length === 0) {
|
|
172
|
+
if (scope.emitters.length > 0) {
|
|
173
|
+
for (let x = 0; x < scope.emitters.length; x++)
|
|
174
|
+
emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
|
|
175
|
+
scope.emitters = [];
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
97
178
|
}
|
|
98
|
-
|
|
179
|
+
(0, array_1.ReconcileSortedEmitters)(scope.emitters, right, function (emitter) {
|
|
180
|
+
emitter_1.Emitter.On(emitter, scope.setCallback);
|
|
181
|
+
}, function (emitter) {
|
|
182
|
+
emitter_1.Emitter.Remove(emitter, scope.setCallback);
|
|
183
|
+
});
|
|
184
|
+
scope.emitters = right;
|
|
99
185
|
}
|
|
186
|
+
function DestroyAllScopes(scopes) {
|
|
187
|
+
for (let x = 0; x < scopes.length; x++)
|
|
188
|
+
DestroyScope(scopes[x]);
|
|
189
|
+
}
|
|
190
|
+
function DestroyScope(scope) {
|
|
191
|
+
if (!scope || scope.type === "static")
|
|
192
|
+
return;
|
|
193
|
+
emitter_1.Emitter.Clear(scope.emitter);
|
|
194
|
+
const scopes = scope.calcScopes && Object.values(scope.calcScopes);
|
|
195
|
+
scopes && DestroyAllScopes(scopes);
|
|
196
|
+
scope.calcScopes = null;
|
|
197
|
+
for (let x = 0; x < scope.emitters.length; x++)
|
|
198
|
+
emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
|
|
199
|
+
scope.value = undefined;
|
|
200
|
+
scope.calcScopes = null;
|
|
201
|
+
scope.emitters = null;
|
|
202
|
+
scope.emitter = null;
|
|
203
|
+
scope.getFunction = null;
|
|
204
|
+
scope.setCallback = null;
|
|
205
|
+
scope.destroyed = true;
|
|
206
|
+
scope.onDestroyed && emitter_1.Emitter.Emit(scope.onDestroyed, scope);
|
|
207
|
+
}
|
|
208
|
+
var ObservableScope;
|
|
100
209
|
(function (ObservableScope) {
|
|
101
|
-
function Create(valueFunction,
|
|
102
|
-
|
|
103
|
-
getFunction: valueFunction,
|
|
104
|
-
value: null,
|
|
105
|
-
promise: null,
|
|
106
|
-
async: (0, functions_1.IsAsync)(valueFunction),
|
|
107
|
-
dirty: true,
|
|
108
|
-
emitter: emitter_1.Emitter.Create(),
|
|
109
|
-
emitters: null,
|
|
110
|
-
calcScopes: null,
|
|
111
|
-
calc,
|
|
112
|
-
destroyed: false,
|
|
113
|
-
onDestroyed: null,
|
|
114
|
-
setCallback: function () {
|
|
115
|
-
return OnSet(scope);
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
return scope;
|
|
210
|
+
function Create(valueFunction, greedy = false, force = false) {
|
|
211
|
+
return ExecuteFunction(valueFunction, greedy, !force);
|
|
119
212
|
}
|
|
120
213
|
ObservableScope.Create = Create;
|
|
121
|
-
function CreateIf(valueFunction) {
|
|
122
|
-
return WatchFunction(valueFunction);
|
|
123
|
-
}
|
|
124
|
-
ObservableScope.CreateIf = CreateIf;
|
|
125
214
|
function Register(emitter) {
|
|
126
|
-
|
|
127
|
-
return;
|
|
128
|
-
watchState[0].push(emitter);
|
|
215
|
+
RegisterEmitter(emitter);
|
|
129
216
|
}
|
|
130
217
|
ObservableScope.Register = Register;
|
|
131
|
-
function Init(scope) {
|
|
132
|
-
if (!scope)
|
|
133
|
-
return;
|
|
134
|
-
UpdateValue(scope);
|
|
135
|
-
}
|
|
136
|
-
ObservableScope.Init = Init;
|
|
137
218
|
function Peek(scope) {
|
|
138
|
-
|
|
139
|
-
return undefined;
|
|
140
|
-
UpdateValue(scope);
|
|
141
|
-
return scope.value;
|
|
219
|
+
return GetScopeValue(scope);
|
|
142
220
|
}
|
|
143
221
|
ObservableScope.Peek = Peek;
|
|
144
222
|
function Value(scope) {
|
|
@@ -149,30 +227,32 @@ function CalcScope(callback, idOverride) {
|
|
|
149
227
|
}
|
|
150
228
|
ObservableScope.Value = Value;
|
|
151
229
|
function Touch(scope) {
|
|
152
|
-
if (!scope
|
|
230
|
+
if (!scope)
|
|
153
231
|
return;
|
|
154
|
-
|
|
232
|
+
RegisterScope(scope);
|
|
155
233
|
}
|
|
156
234
|
ObservableScope.Touch = Touch;
|
|
157
235
|
function Watch(scope, callback) {
|
|
158
|
-
if (!scope ||
|
|
236
|
+
if (!scope || scope.type === "static")
|
|
159
237
|
return;
|
|
160
238
|
emitter_1.Emitter.On(scope.emitter, callback);
|
|
161
239
|
}
|
|
162
240
|
ObservableScope.Watch = Watch;
|
|
163
241
|
function Unwatch(scope, callback) {
|
|
164
|
-
if (!scope ||
|
|
242
|
+
if (!scope || scope.type === "static")
|
|
165
243
|
return;
|
|
166
244
|
emitter_1.Emitter.Remove(scope.emitter, callback);
|
|
167
245
|
}
|
|
168
246
|
ObservableScope.Unwatch = Unwatch;
|
|
169
247
|
function OnDestroyed(scope, callback) {
|
|
248
|
+
if (scope.type === "static")
|
|
249
|
+
return;
|
|
170
250
|
scope.onDestroyed ??= emitter_1.Emitter.Create();
|
|
171
251
|
emitter_1.Emitter.On(scope.onDestroyed, callback);
|
|
172
252
|
}
|
|
173
253
|
ObservableScope.OnDestroyed = OnDestroyed;
|
|
174
254
|
function Update(scope) {
|
|
175
|
-
if (!scope
|
|
255
|
+
if (!scope)
|
|
176
256
|
return;
|
|
177
257
|
OnSet(scope);
|
|
178
258
|
}
|
|
@@ -182,102 +262,7 @@ function CalcScope(callback, idOverride) {
|
|
|
182
262
|
}
|
|
183
263
|
ObservableScope.Destroy = Destroy;
|
|
184
264
|
function DestroyAll(scopes) {
|
|
185
|
-
|
|
186
|
-
Destroy(scopes[x]);
|
|
265
|
+
DestroyAllScopes(scopes);
|
|
187
266
|
}
|
|
188
267
|
ObservableScope.DestroyAll = DestroyAll;
|
|
189
268
|
})(ObservableScope || (exports.ObservableScope = ObservableScope = {}));
|
|
190
|
-
function DirtyScope(scope) {
|
|
191
|
-
if (scope.dirty || !scope.getFunction)
|
|
192
|
-
return;
|
|
193
|
-
scope.dirty = true;
|
|
194
|
-
if (scope.async)
|
|
195
|
-
UpdateValue(scope);
|
|
196
|
-
else if (scope.calc) {
|
|
197
|
-
const startValue = scope.value;
|
|
198
|
-
UpdateValue(scope);
|
|
199
|
-
startValue !== scope.value && emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
200
|
-
}
|
|
201
|
-
else
|
|
202
|
-
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
203
|
-
}
|
|
204
|
-
let scopeQueue = [];
|
|
205
|
-
function ProcessScopeQueue() {
|
|
206
|
-
const scopes = scopeQueue;
|
|
207
|
-
scopeQueue = [];
|
|
208
|
-
const distinct = new Set();
|
|
209
|
-
for (let x = 0; x < scopes.length; x++) {
|
|
210
|
-
if (!distinct.has(scopes[x])) {
|
|
211
|
-
distinct.add(scopes[x]);
|
|
212
|
-
DirtyScope(scopes[x]);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
function OnSet(scope) {
|
|
217
|
-
if (scope.destroyed)
|
|
218
|
-
return true;
|
|
219
|
-
if (scope.async || scope.calc) {
|
|
220
|
-
if (scopeQueue.length === 0)
|
|
221
|
-
queueMicrotask(ProcessScopeQueue);
|
|
222
|
-
scopeQueue.push(scope);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
DirtyScope(scope);
|
|
226
|
-
}
|
|
227
|
-
function UpdateValue(scope, valueOverride = undefined) {
|
|
228
|
-
if (!scope.dirty)
|
|
229
|
-
return;
|
|
230
|
-
scope.dirty = false;
|
|
231
|
-
const value = valueOverride === undefined ? WatchScope(scope) : valueOverride;
|
|
232
|
-
if (scope.async) {
|
|
233
|
-
scope.promise = value.then(function (result) {
|
|
234
|
-
if (scope.destroyed)
|
|
235
|
-
return;
|
|
236
|
-
scope.value = result;
|
|
237
|
-
emitter_1.Emitter.Emit(scope.emitter, scope);
|
|
238
|
-
return result;
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
else
|
|
242
|
-
scope.value = value;
|
|
243
|
-
}
|
|
244
|
-
function UpdateEmitters(scope, right) {
|
|
245
|
-
emitter_1.Emitter.Distinct(right);
|
|
246
|
-
if (scope.emitters === null) {
|
|
247
|
-
for (let x = 0; x < right.length; x++)
|
|
248
|
-
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
249
|
-
scope.emitters = right;
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
if (right.length === 0) {
|
|
253
|
-
if (scope.emitters.length > 0) {
|
|
254
|
-
for (let x = 0; x < scope.emitters.length; x++)
|
|
255
|
-
emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
|
|
256
|
-
scope.emitters = [];
|
|
257
|
-
}
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
(0, array_1.ReconcileSortedEmitters)(scope.emitters, right, function (emitter) {
|
|
261
|
-
emitter_1.Emitter.On(emitter, scope.setCallback);
|
|
262
|
-
}, function (emitter) {
|
|
263
|
-
emitter_1.Emitter.Remove(emitter, scope.setCallback);
|
|
264
|
-
});
|
|
265
|
-
scope.emitters = right;
|
|
266
|
-
}
|
|
267
|
-
function DestroyScope(scope) {
|
|
268
|
-
if (!scope)
|
|
269
|
-
return;
|
|
270
|
-
emitter_1.Emitter.Clear(scope.emitter);
|
|
271
|
-
const scopes = scope.calcScopes && Object.values(scope.calcScopes);
|
|
272
|
-
scopes && ObservableScope.DestroyAll(scopes);
|
|
273
|
-
scope.calcScopes = null;
|
|
274
|
-
for (let x = 0; x < scope.emitters.length; x++)
|
|
275
|
-
emitter_1.Emitter.Remove(scope.emitters[x], scope.setCallback);
|
|
276
|
-
scope.calcScopes = null;
|
|
277
|
-
scope.emitters = null;
|
|
278
|
-
scope.emitter = null;
|
|
279
|
-
scope.getFunction = null;
|
|
280
|
-
scope.setCallback = null;
|
|
281
|
-
scope.destroyed = true;
|
|
282
|
-
scope.onDestroyed && emitter_1.Emitter.Emit(scope.onDestroyed);
|
|
283
|
-
}
|
package/Utils/animation.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { IDestroyable } from "./utils.types";
|
|
2
|
+
/**
|
|
3
|
+
* Supported animation functions.
|
|
4
|
+
*/
|
|
2
5
|
export declare enum AnimationType {
|
|
3
6
|
Linear = 0,
|
|
4
7
|
EaseIn = 1
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Class for handling interpolation for basic animations.
|
|
11
|
+
*/
|
|
6
12
|
export declare class Animation implements IDestroyable {
|
|
7
13
|
private type;
|
|
8
14
|
private running;
|
|
@@ -13,16 +19,53 @@ export declare class Animation implements IDestroyable {
|
|
|
13
19
|
private animationDuration;
|
|
14
20
|
private animationUpdate;
|
|
15
21
|
private animationRun;
|
|
22
|
+
/**
|
|
23
|
+
* Is the animation currently running.
|
|
24
|
+
*/
|
|
16
25
|
get Running(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The starting value of the current animation.
|
|
28
|
+
*/
|
|
17
29
|
get Start(): number;
|
|
30
|
+
/**
|
|
31
|
+
* The ending value of the current animation.
|
|
32
|
+
*/
|
|
18
33
|
get End(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Is this animation enabled.
|
|
36
|
+
*/
|
|
19
37
|
get Enabled(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @param type Interpolation function
|
|
40
|
+
* @param duration The duration of the Animation
|
|
41
|
+
* @param update Callback invoked during the animation with the next value
|
|
42
|
+
*/
|
|
20
43
|
constructor(type: AnimationType, duration: number, update: {
|
|
21
44
|
(next: number): void;
|
|
22
45
|
});
|
|
46
|
+
/**
|
|
47
|
+
* Start an animation. Calls the passed `update` callback for each animation frame
|
|
48
|
+
* with interpolated values based on the passed `AnimationType`.
|
|
49
|
+
*
|
|
50
|
+
* @param start initial animation value
|
|
51
|
+
* @param end ending animation value
|
|
52
|
+
* @returns Promise<void> that resolves once the animation is complete
|
|
53
|
+
*/
|
|
23
54
|
Animate(start: number, end: number): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Disables the Animation. Cancels the animation if it is running.
|
|
57
|
+
*/
|
|
24
58
|
Disable(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Enables the Animation.
|
|
61
|
+
*/
|
|
25
62
|
Enable(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Cancels the Animation if it is running by clearing any sheduled timeout events.
|
|
65
|
+
*/
|
|
26
66
|
Cancel(): void;
|
|
67
|
+
/**
|
|
68
|
+
* IDestroyable. Cancels the animation.
|
|
69
|
+
*/
|
|
27
70
|
Destroy(): void;
|
|
28
71
|
}
|
package/Utils/animation.js
CHANGED
|
@@ -20,24 +20,47 @@ var StepFunctions;
|
|
|
20
20
|
}
|
|
21
21
|
StepFunctions.Linear = Linear;
|
|
22
22
|
})(StepFunctions || (StepFunctions = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Supported animation functions.
|
|
25
|
+
*/
|
|
23
26
|
var AnimationType;
|
|
24
27
|
(function (AnimationType) {
|
|
25
28
|
AnimationType[AnimationType["Linear"] = 0] = "Linear";
|
|
26
29
|
AnimationType[AnimationType["EaseIn"] = 1] = "EaseIn";
|
|
27
30
|
})(AnimationType || (exports.AnimationType = AnimationType = {}));
|
|
31
|
+
/**
|
|
32
|
+
* Class for handling interpolation for basic animations.
|
|
33
|
+
*/
|
|
28
34
|
class Animation {
|
|
35
|
+
/**
|
|
36
|
+
* Is the animation currently running.
|
|
37
|
+
*/
|
|
29
38
|
get Running() {
|
|
30
39
|
return this.running;
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The starting value of the current animation.
|
|
43
|
+
*/
|
|
32
44
|
get Start() {
|
|
33
45
|
return this.start;
|
|
34
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The ending value of the current animation.
|
|
49
|
+
*/
|
|
35
50
|
get End() {
|
|
36
51
|
return this.end;
|
|
37
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Is this animation enabled.
|
|
55
|
+
*/
|
|
38
56
|
get Enabled() {
|
|
39
57
|
return this.enabled;
|
|
40
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* @param type Interpolation function
|
|
61
|
+
* @param duration The duration of the Animation
|
|
62
|
+
* @param update Callback invoked during the animation with the next value
|
|
63
|
+
*/
|
|
41
64
|
constructor(type, duration, update) {
|
|
42
65
|
this.animationStart = 0;
|
|
43
66
|
this.animationRun = null;
|
|
@@ -49,13 +72,23 @@ class Animation {
|
|
|
49
72
|
this.animationDuration = duration;
|
|
50
73
|
this.animationUpdate = nodeConfig_1.NodeConfig.wrapPriorityUpdates(update);
|
|
51
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Start an animation. Calls the passed `update` callback for each animation frame
|
|
77
|
+
* with interpolated values based on the passed `AnimationType`.
|
|
78
|
+
*
|
|
79
|
+
* @param start initial animation value
|
|
80
|
+
* @param end ending animation value
|
|
81
|
+
* @returns Promise<void> that resolves once the animation is complete
|
|
82
|
+
*/
|
|
52
83
|
Animate(start, end) {
|
|
53
84
|
if (!this.enabled)
|
|
54
85
|
return;
|
|
86
|
+
this.Cancel();
|
|
55
87
|
const diff = end - start;
|
|
56
|
-
if (diff === 0)
|
|
88
|
+
if (diff === 0) {
|
|
89
|
+
this.animationUpdate(end);
|
|
57
90
|
return;
|
|
58
|
-
|
|
91
|
+
}
|
|
59
92
|
this.animationStart = Date.now();
|
|
60
93
|
this.running = true;
|
|
61
94
|
this.start = start;
|
|
@@ -63,8 +96,10 @@ class Animation {
|
|
|
63
96
|
return new Promise((resolve) => {
|
|
64
97
|
const stepFunc = StepFunctions[AnimationType[this.type]];
|
|
65
98
|
const animationRun = () => {
|
|
66
|
-
if (this.animationRun !== animationRun)
|
|
99
|
+
if (this.animationRun !== animationRun) {
|
|
100
|
+
resolve();
|
|
67
101
|
return;
|
|
102
|
+
}
|
|
68
103
|
const percent = stepFunc(this.animationStart, this.animationDuration);
|
|
69
104
|
const step = percent * diff;
|
|
70
105
|
const next = this.start + step;
|
|
@@ -81,19 +116,31 @@ class Animation {
|
|
|
81
116
|
this.Cancel();
|
|
82
117
|
});
|
|
83
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Disables the Animation. Cancels the animation if it is running.
|
|
121
|
+
*/
|
|
84
122
|
Disable() {
|
|
85
123
|
this.Cancel();
|
|
86
124
|
this.enabled = false;
|
|
87
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Enables the Animation.
|
|
128
|
+
*/
|
|
88
129
|
Enable() {
|
|
89
130
|
this.enabled = true;
|
|
90
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Cancels the Animation if it is running by clearing any sheduled timeout events.
|
|
134
|
+
*/
|
|
91
135
|
Cancel() {
|
|
92
136
|
this.running = false;
|
|
93
137
|
this.start = null;
|
|
94
138
|
this.end = null;
|
|
95
139
|
this.animationRun = null;
|
|
96
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* IDestroyable. Cancels the animation.
|
|
143
|
+
*/
|
|
97
144
|
Destroy() {
|
|
98
145
|
this.Disable();
|
|
99
146
|
}
|