Files
nodarium/app/src/lib/graph-interface/components/BoxSelection.svelte
Max Richter 1ea544e765
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 3m33s
chore: rename @nodes -> @nodarium for everything
2025-12-01 17:03:14 +01:00

39 lines
935 B
Svelte

<script lang="ts">
import { HTML } from "@threlte/extras";
type Props = {
p1: { x: number; y: number };
p2: { x: number; y: number };
cameraPosition: [number, number, number];
};
const {
p1 = { x: 0, y: 0 },
p2 = { x: 0, y: 0 },
cameraPosition = [0, 1, 0],
}: Props = $props();
const width = $derived(Math.abs(p1.x - p2.x) * cameraPosition[2]);
const height = $derived(Math.abs(p1.y - p2.y) * cameraPosition[2]);
const x = $derived(Math.max(p1.x, p2.x) - width / cameraPosition[2]);
const y = $derived(Math.max(p1.y, p2.y) - height / cameraPosition[2]);
</script>
<HTML position.x={x} position.z={y} transform={false}>
<div
class="box-selection"
style={`width: ${width}px; height: ${height}px;`}
></div>
</HTML>
<style>
.box-selection {
width: 40px;
height: 20px;
border: solid 2px var(--outline);
border-style: dashed;
border-radius: 2px;
}
</style>