Files
lasercut-scrap-modeller/src/App.svelte
T

87 lines
1.9 KiB
Svelte

<script lang="ts">
import { onMount } from 'svelte';
import ImageCanvas from './components/ImageCanvas.svelte';
import Sidebar from './components/Sidebar.svelte';
import { AppState } from './lib/app-state.svelte';
import { loadOpenCV } from './lib/opencv-loader';
const app = new AppState();
onMount(() => {
loadOpenCV().then(
({ cv }) => app.setCv(cv),
() => (app.cvError = 'Could not load image processing (OpenCV).'),
);
});
function ondrop(e: DragEvent) {
e.preventDefault();
const file = e.dataTransfer?.files[0];
if (file) app.loadFile(file);
}
function onFile(e: Event & { currentTarget: HTMLInputElement }) {
const file = e.currentTarget.files?.[0];
if (file) app.loadFile(file);
}
</script>
<div class="layout">
<aside>
<Sidebar {app} />
</aside>
<main ondragover={(e) => e.preventDefault()} {ondrop}>
{#if app.image}
<ImageCanvas {app} />
{:else}
<label class="dropzone">
<input type="file" accept="image/*" hidden onchange={onFile} />
<strong>Drop a photo of a scrap piece here</strong>
<span>or click to choose a file</span>
</label>
{/if}
</main>
</div>
<style>
:global(body) {
margin: 0;
}
.layout {
display: grid;
grid-template-columns: 320px 1fr;
height: 100vh;
}
aside {
overflow-y: auto;
border-right: 1px solid var(--border);
padding: 16px;
}
main {
position: relative;
background: #2b2b2b;
}
.dropzone {
position: absolute;
inset: 24px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 4px;
border: 2px dashed #555;
border-radius: 12px;
color: #bbb;
cursor: pointer;
transition: border-color 0.15s, background-color 0.15s;
}
.dropzone:hover {
border-color: #888;
background: rgba(255, 255, 255, 0.03);
}
.dropzone span {
color: #888;
font-size: 0.9rem;
}
</style>