j-templates 6.1.4 → 6.1.6
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 +12 -5
- package/Utils/animation_v2.d.ts +28 -0
- package/Utils/animation_v2.js +98 -0
- package/Utils/index.d.ts +1 -0
- package/Utils/index.js +1 -0
- package/package.json +1 -1
package/DOM/domNodeConfig.js
CHANGED
|
@@ -10,26 +10,33 @@ const createPropertyAssignment_2 = require("./createPropertyAssignment");
|
|
|
10
10
|
let pendingUpdates = list_1.List.Create();
|
|
11
11
|
let updateScheduled = false;
|
|
12
12
|
const frameTime = 16;
|
|
13
|
-
let
|
|
13
|
+
let frameStart = 0;
|
|
14
14
|
function processUpdates() {
|
|
15
|
-
lastUpdate = Date.now();
|
|
16
15
|
list_1.List.Add(pendingUpdates, null);
|
|
17
16
|
let callback;
|
|
18
17
|
while ((callback = list_1.List.Pop(pendingUpdates)))
|
|
19
18
|
callback();
|
|
19
|
+
const now = Date.now();
|
|
20
20
|
if (pendingUpdates.size === 0)
|
|
21
21
|
updateScheduled = false;
|
|
22
|
-
else
|
|
22
|
+
else if (now - frameStart < frameTime)
|
|
23
|
+
queueMicrotask(processUpdates);
|
|
24
|
+
else {
|
|
25
|
+
frameStart = now;
|
|
23
26
|
window_1.wndw.requestAnimationFrame(processUpdates);
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
function scheduleUpdate(callback) {
|
|
26
30
|
list_1.List.Add(pendingUpdates, callback);
|
|
27
31
|
if (!updateScheduled) {
|
|
32
|
+
const now = Date.now();
|
|
28
33
|
updateScheduled = true;
|
|
29
|
-
if (
|
|
34
|
+
if (now - frameStart < frameTime)
|
|
30
35
|
queueMicrotask(processUpdates);
|
|
31
|
-
else
|
|
36
|
+
else {
|
|
37
|
+
frameStart = now;
|
|
32
38
|
window_1.wndw.requestAnimationFrame(processUpdates);
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
exports.DOMNodeConfig = {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IDestroyable } from "./utils.types";
|
|
2
|
+
export declare enum AnimationTypeV2 {
|
|
3
|
+
Linear = 0,
|
|
4
|
+
EaseIn = 1
|
|
5
|
+
}
|
|
6
|
+
export declare class AnimationV2 implements IDestroyable {
|
|
7
|
+
private type;
|
|
8
|
+
private running;
|
|
9
|
+
private start;
|
|
10
|
+
private end;
|
|
11
|
+
private enabled;
|
|
12
|
+
private animationStart;
|
|
13
|
+
private animationDuration;
|
|
14
|
+
private animationUpdate;
|
|
15
|
+
private animationRun;
|
|
16
|
+
get Running(): boolean;
|
|
17
|
+
get Start(): number;
|
|
18
|
+
get End(): number;
|
|
19
|
+
get Enabled(): boolean;
|
|
20
|
+
constructor(type: AnimationTypeV2, duration: number, update: {
|
|
21
|
+
(next: number): void;
|
|
22
|
+
});
|
|
23
|
+
Animate(start: number, end: number): Promise<void>;
|
|
24
|
+
Disable(): void;
|
|
25
|
+
Enable(): void;
|
|
26
|
+
Cancel(): void;
|
|
27
|
+
Destroy(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnimationV2 = exports.AnimationTypeV2 = void 0;
|
|
4
|
+
const domNodeConfig_1 = require("../DOM/domNodeConfig");
|
|
5
|
+
var StepFunctions;
|
|
6
|
+
(function (StepFunctions) {
|
|
7
|
+
function EaseIn(start, duration) {
|
|
8
|
+
const elapsed = Date.now() - start;
|
|
9
|
+
const percent = Math.min(elapsed / duration, 1);
|
|
10
|
+
return (1 - percent) * (1 - percent) * (1 - percent) * 0 + 3 * (1 - percent) * (1 - percent) * percent * 1 + 3 * (1 - percent) * percent * percent * 1 + percent * percent * percent * 1;
|
|
11
|
+
}
|
|
12
|
+
StepFunctions.EaseIn = EaseIn;
|
|
13
|
+
function Linear(start, duration) {
|
|
14
|
+
const elapsed = Date.now() - start;
|
|
15
|
+
const percent = Math.min(elapsed / duration, 1);
|
|
16
|
+
return percent;
|
|
17
|
+
}
|
|
18
|
+
StepFunctions.Linear = Linear;
|
|
19
|
+
})(StepFunctions || (StepFunctions = {}));
|
|
20
|
+
var AnimationTypeV2;
|
|
21
|
+
(function (AnimationTypeV2) {
|
|
22
|
+
AnimationTypeV2[AnimationTypeV2["Linear"] = 0] = "Linear";
|
|
23
|
+
AnimationTypeV2[AnimationTypeV2["EaseIn"] = 1] = "EaseIn";
|
|
24
|
+
})(AnimationTypeV2 || (exports.AnimationTypeV2 = AnimationTypeV2 = {}));
|
|
25
|
+
class AnimationV2 {
|
|
26
|
+
get Running() {
|
|
27
|
+
return this.running;
|
|
28
|
+
}
|
|
29
|
+
get Start() {
|
|
30
|
+
return this.start;
|
|
31
|
+
}
|
|
32
|
+
get End() {
|
|
33
|
+
return this.end;
|
|
34
|
+
}
|
|
35
|
+
get Enabled() {
|
|
36
|
+
return this.enabled;
|
|
37
|
+
}
|
|
38
|
+
constructor(type, duration, update) {
|
|
39
|
+
this.animationStart = 0;
|
|
40
|
+
this.animationRun = null;
|
|
41
|
+
this.running = false;
|
|
42
|
+
this.start = null;
|
|
43
|
+
this.end = null;
|
|
44
|
+
this.enabled = true;
|
|
45
|
+
this.type = type;
|
|
46
|
+
this.animationDuration = duration;
|
|
47
|
+
this.animationUpdate = update;
|
|
48
|
+
}
|
|
49
|
+
Animate(start, end) {
|
|
50
|
+
if (!this.enabled)
|
|
51
|
+
return;
|
|
52
|
+
const diff = end - start;
|
|
53
|
+
if (diff === 0)
|
|
54
|
+
return;
|
|
55
|
+
this.Cancel();
|
|
56
|
+
this.animationStart = Date.now();
|
|
57
|
+
this.running = true;
|
|
58
|
+
this.start = start;
|
|
59
|
+
this.end = end;
|
|
60
|
+
return new Promise(resolve => {
|
|
61
|
+
const stepFunc = StepFunctions[AnimationTypeV2[this.type]];
|
|
62
|
+
const animationRun = () => {
|
|
63
|
+
if (this.animationRun !== animationRun)
|
|
64
|
+
return;
|
|
65
|
+
const percent = stepFunc(this.animationStart, this.animationDuration);
|
|
66
|
+
const step = percent * diff;
|
|
67
|
+
const next = this.start + step;
|
|
68
|
+
this.animationUpdate(next);
|
|
69
|
+
if (percent < 1)
|
|
70
|
+
domNodeConfig_1.DOMNodeConfig.scheduleUpdate(this.animationRun);
|
|
71
|
+
else {
|
|
72
|
+
resolve();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
this.animationRun = animationRun;
|
|
76
|
+
domNodeConfig_1.DOMNodeConfig.scheduleUpdate(this.animationRun);
|
|
77
|
+
}).then(() => {
|
|
78
|
+
this.Cancel();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
Disable() {
|
|
82
|
+
this.Cancel();
|
|
83
|
+
this.enabled = false;
|
|
84
|
+
}
|
|
85
|
+
Enable() {
|
|
86
|
+
this.enabled = true;
|
|
87
|
+
}
|
|
88
|
+
Cancel() {
|
|
89
|
+
this.running = false;
|
|
90
|
+
this.start = null;
|
|
91
|
+
this.end = null;
|
|
92
|
+
this.animationRun = null;
|
|
93
|
+
}
|
|
94
|
+
Destroy() {
|
|
95
|
+
this.Cancel();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.AnimationV2 = AnimationV2;
|
package/Utils/index.d.ts
CHANGED
package/Utils/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./decorators"), exports);
|
|
18
18
|
__exportStar(require("./animation"), exports);
|
|
19
|
+
__exportStar(require("./animation_v2"), exports);
|