stear/extra/Pages/showStatus.js

87 lines
2 KiB
JavaScript
Raw Normal View History

2022-06-09 21:37:23 +02:00
import { SFrame, Stear, _ } from "../../main.js";
import { fadein, fadeout, wait } from "../../utils.js";
const preRender = true;
Stear.addGlobalStyleJSON({
position: "fixed",
left: "50%",
bottom: "1rem",
transform: "translate(-50%, -50%)",
textAlign: "center",
border: `2px soild transparent`,
borderRadius: "1rem",
padding: "1rem",
transition: "background-color 200ms",
backgroundColor: "#212121",
color:"#fafafa",
2022-06-10 01:07:55 +02:00
webkitUserSelect: "none",
2022-06-09 21:37:23 +02:00
},".stear_status");
const render = ({ }, { }) => {
return _({
find:"main",
class:"stear_status",
});
}
const statusList = [];
var statusActive = false;
const call = async (stear, { find, resolve, render, call }, { text, color="grey" }) => {
statusList.push({ text, color, resolve});
if (statusActive) return;
statusActive = true;
var next = statusList.shift();
var last;
find.main.settings = {style:{
border: "2px solid " + next.color
}};
find.main._.innerText = next.text;
await fadein(find.main._, 200, true);
2022-06-10 15:01:23 +02:00
//find.main._.style.transition = "";
2022-06-09 21:37:23 +02:00
async function loop(){
last = next;
next = statusList.shift();
if (next == null) return finish();
last.resolve(null, false);
find.main.settings = { style: { backgroundColor: "#555" } };
await wait(200);
find.main.settings = {
style: {
backgroundColor: "",
border: "2px solid " + next.color
}
};
find.main._.innerText = next.text;
timeoutId = setTimeout(loop,3000);
}
var timeoutId = setTimeout(loop, 3000);
find.main._.onclick = ()=>{
if(timeoutId<0)return;
clearTimeout(timeoutId);
timeoutId = -1;
loop();
};
async function finish(){
if (timeoutId >= 0)clearTimeout(timeoutId);
timeoutId = -1;
statusActive = false;
await fadeout(find.main._);
last.resolve();
}
}
export default new SFrame({
preRender, render, call
});