import React, { useState } from "react";
import { unmountComponentAtNode } from "react-dom";
import { createRoot } from "react-dom/client";
const urlParams = new URLSearchParams(import.meta.url.replaceAll(/.*?\?/g, ""));
const rootID = urlParams.get("root-id") ?? "root";
const root = createRoot(document.getElementById(rootID));
let componentModule;
switch (urlParams.get("bundle")) {
case "core": {
componentModule = (await import("../../dist/digital-rain.core.js"));
break;
}
default: {
componentModule = (await import("../../js/Matrix"));
}
}
const { Matrix } = componentModule;
const versions = [
"classic",
"3d",
"resurrections",
"operator",
"megacity",
"nightmare",
"paradise",
"trinity",
"bugs",
"morpheus",
];
const effects = ["none", "palette", "stripes", "pride", "trans", "image", "mirror"];
const App = () => {
const [version, setVersion] = useState(versions[0]);
const [effect, setEffect] = useState("palette");
const [numColumns, setNumColumns] = useState(80);
const [resolution, setResolution] = useState(0.75);
const [cursorColor, setCursorColor] = useState(null);
const [backgroundColor, setBackgroundColor] = useState("0,0,0");
const [rendererType, setRendererType] = useState(null);
const [density, setDensity] = useState(2);
const [destroyed, setDestroyed] = useState(false);
const onVersionButtonClick = () => {
setVersion((s) => {
let index = versions.indexOf(version) + 1;
if (index === versions.length) {
index = 0;
}
const newVersion = versions[index];
console.log("version:", newVersion);
return newVersion;
});
setCursorColor(null);
setBackgroundColor(null);
};
const onEffectButtonClick = () => {
setEffect((s) => {
let index = effects.indexOf(effect) + 1;
if (index === effects.length) {
index = 0;
}
const newEffect = effects[index];
console.log("effect:", newEffect);
return newEffect;
});
setCursorColor(null);
setBackgroundColor(null);
};
const onRendererButtonClick = () => {
setRendererType(() => (rendererType === "webgpu" ? "regl" : "webgpu"));
};
const onDestroyButtonClick = () => {
setDestroyed(true);
};
return (
<>
{
const values = e.target.value
.match(/[\da-fA-F]{2}/g)
.map((s) => parseInt(s, 16) / 0xff)
.join(",");
setCursorColor(values);
}}
/>
{
const values = e.target.value
.match(/[\da-fA-F]{2}/g)
.map((s) => parseInt(s, 16) / 0xff)
.join(",");
setBackgroundColor(values);
}}
/>
setNumColumns(parseInt(e.target.value))}
/>
setResolution(parseFloat(e.target.value))}
/>
{!destroyed && (
)}
>
);
};
root.render();