Make overlay

This commit is contained in:
0xa663
2024-02-15 19:27:26 +01:00
parent 179fdc8f4d
commit cc2aa552ba
34 changed files with 11168 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
export class FileInput {
private input = document.createElement("input");
constructor() {
this.input.type = "file";
}
allowMultiple(value: boolean) {
this.input.multiple = value;
}
setAcceptType(extensions?: string[]) {
if (extensions) {
this.input.accept = extensions.map(e => `.${e}`).join(", ");
} else {
this.input.accept = "";
}
}
show() {
return new Promise<FileList>((resolve, reject) => {
const subs: (keyof WindowEventMap)[] = ["mousemove", "touchend"];
const onCancel = () => {
unCancel();
reject(new Error("Not selected"));
};
const unCancel = () => {
subs.forEach(s => window.removeEventListener(s, onCancel));
};
const frame = setTimeout(() => {
subs.forEach(s => window.addEventListener(s, () => onCancel));
}, 100);
this.input.addEventListener("change", () => {
clearTimeout(frame);
unCancel();
if (this.input.files) {
resolve(this.input.files);
} else {
reject(new Error("Missing file"));
}
});
this.input.click();
});
}
}