|
|
@@ -1,5 +1,31 @@
|
|
|
import { dom_manager, type_manager } from "./functions.js";
|
|
|
|
|
|
+class applet_animations {
|
|
|
+ static display(state, target) {
|
|
|
+ if (state) {
|
|
|
+ target.style.display = "block";
|
|
|
+ } else {
|
|
|
+ target.style.display = "none";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static hide_left(state, target) {
|
|
|
+ if (state) {
|
|
|
+ target.style.left = "0";
|
|
|
+ } else {
|
|
|
+ target.style.left = -target.offsetWidth + "px";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static hide_right(state, target) {
|
|
|
+ if (state) {
|
|
|
+ target.style.right = "0";
|
|
|
+ } else {
|
|
|
+ target.style.right = -target.offsetWidth + "px";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class applet_builder {
|
|
|
#minimalise;
|
|
|
#maximalise;
|
|
|
@@ -10,7 +36,7 @@ class applet_builder {
|
|
|
this.#minimalise = undefined;
|
|
|
this.#maximalise = undefined;
|
|
|
this.#target = undefined;
|
|
|
- this.#animation = undefined;
|
|
|
+ this.#animation = applet_animations.display;
|
|
|
}
|
|
|
|
|
|
set minimalise(target) {
|
|
|
@@ -42,7 +68,7 @@ class applet_builder {
|
|
|
throw "Animation must be an function.";
|
|
|
}
|
|
|
|
|
|
- this.#animation = animation;
|
|
|
+ this.#animation = target;
|
|
|
}
|
|
|
|
|
|
get is_valid() {
|
|
|
@@ -58,6 +84,10 @@ class applet_builder {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if (this.#animation === undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -94,38 +124,17 @@ class applet {
|
|
|
}
|
|
|
|
|
|
_run_animation() {
|
|
|
- const time = this._animation(this._state, this._target);
|
|
|
-
|
|
|
- if (!isInteger(time)) {
|
|
|
- throw "Animation must return time which it cost in ms.";
|
|
|
- }
|
|
|
-
|
|
|
- return time;
|
|
|
+ this._animation(this._state, this._target);
|
|
|
}
|
|
|
|
|
|
show() {
|
|
|
this._state = true;
|
|
|
- this._target.style.display = "";
|
|
|
-
|
|
|
- if (this._has_animation) {
|
|
|
- this._run_animation();
|
|
|
- }
|
|
|
+ this._run_animation();
|
|
|
}
|
|
|
|
|
|
- hide(now) {
|
|
|
+ hide() {
|
|
|
this._state = false;
|
|
|
-
|
|
|
- if (now) {
|
|
|
- this._target.style.display = "none";
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!this._has_animation) {
|
|
|
- this.hide(true);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- setTimeout(() => { this.hide(true); }, this._run_animation());
|
|
|
+ this._run_animation();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -169,4 +178,4 @@ class swapable_applet extends applet {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export { applet_builder };
|
|
|
+export { applet_builder, applet_animations };
|