// Framework-only adversarial fixture: real built-in pads, intentionally selectable renderer faults. import { useLayoutEffect, useRef, useState } from "react"; import { createRoot } from "react-dom/client"; import { VectorControl, type VectorControlValue } from "@repo/ui/controls"; import { drawVectorShaderFixture } from "./browser-vector-shader-fixture"; export type VectorFixtureMode = | "dom" | "canvas" | "mirror-x" | "mirror-y" | "swapped" | "stationary" | "release-only" | "moving-frame" | "missing-marker" | "nested-mirror" | "cartesian" | "shader" | "shader-mirrored"; function Fixture({ mode }: { mode: VectorFixtureMode }) { const [values, setValues] = useState([ { x: "0", y: "0" }, { x: "0", y: "0" }, ]); const [released, setReleased] = useState(values); const canvas = useRef(null); const rendered = mode === "release-only" ? released : values; let x = Number(rendered[0]!.x) * 70; let y = Number(rendered[0]!.y) * 70; if (mode === "mirror-x") x = -x; if (mode === "mirror-y" || mode === "cartesian") y = -y; if (mode === "swapped") [x, y] = [y, x]; if (mode === "stationary") { x = 0; y = 0; } if (mode === "nested-mirror") { x -= Number(rendered[1]!.x) * 70; y += Number(rendered[1]!.y) * 70; } useLayoutEffect(() => { if (!canvas.current) return; if (mode === "shader" || mode === "shader-mirrored") { return drawVectorShaderFixture( canvas.current, x, y, mode === "shader-mirrored", ); } const context = canvas.current.getContext("2d")!; context.fillStyle = "#101010"; context.fillRect(0, 0, 320, 320); context.fillStyle = "rgb(255, 0, 128)"; context.fillRect(148 + x, 148 + y, 24, 24); }, [x, y, mode]); return ( <>
setReleased(values)} > {values .slice(0, mode === "nested-mirror" ? 2 : 1) .map((value, index) => ( setValues((current) => current.map((item, i) => (i === index ? next : item)), ) } /> ))}
{mode === "canvas" || mode === "shader" || mode === "shader-mirrored" ? ( ) : (
)}
); } export function mountVectorFixture(mode: VectorFixtureMode): void { const host = document.createElement("div"); document.querySelector('[data-slot="toolcraft-runtime-app"]')!.append(host); createRoot(host).render(); }