2023-08-01 14:20:57 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2023-08-02 16:43:02 +00:00
|
|
|
import parsePng from "./parsePng.js";
|
2023-08-01 14:20:57 +00:00
|
|
|
import parseHash from "./parseHash.js";
|
2023-08-02 18:39:57 +00:00
|
|
|
import getNodeUi from "./getNodeUi.js";
|
2023-08-02 18:48:36 +00:00
|
|
|
import explorer from "./explorer.js";
|
2023-08-01 14:20:57 +00:00
|
|
|
|
|
|
|
const errorEl = document.getElementById("error");
|
|
|
|
const explorerEl = document.getElementById("explorer");
|
|
|
|
if (!errorEl || !explorerEl) throw new Error("HTML is not set up correctly");
|
|
|
|
|
|
|
|
const main = () => {
|
|
|
|
// TODO: We may want a better UI here.
|
2023-08-02 16:58:06 +00:00
|
|
|
// TODO: Handle hash changes.
|
2023-08-01 14:20:57 +00:00
|
|
|
const parsedHash = parseHash(location.hash);
|
|
|
|
if (!parsedHash) {
|
|
|
|
location.href = "..";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-02 16:43:02 +00:00
|
|
|
const { bytes } = parsedHash;
|
|
|
|
|
|
|
|
const rootNode = parsePng(bytes);
|
|
|
|
if (!rootNode) {
|
|
|
|
// TODO: Is there better UI than this?
|
|
|
|
errorEl.removeAttribute("hidden");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:25:42 +00:00
|
|
|
explorerEl.innerHTML = "";
|
2023-08-02 18:48:36 +00:00
|
|
|
explorerEl.append(explorer(rootNode, getNodeUi));
|
2023-08-02 17:25:42 +00:00
|
|
|
explorerEl.removeAttribute("hidden");
|
2023-08-01 14:20:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
main();
|