logigate/app/components/editor/Canvas.vue

673 lines
24 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { GRID as G, pinPos, routeWire, type Pt, type Shape } from '~/lib/logic/geometry'
import type { CircuitNode, Wire } from '~/lib/logic/types'
import { branchCorners, branchTo, moveCorner, moveSegment, segmentDrag, splitDrag } from '~/lib/logic/wires'
const ed = useEditor()
const root = ref<HTMLDivElement>()
const size = reactive({ w: 800, h: 600 })
const def = ed.def
const view = computed(() => ed.views[def.value.id] ?? { x: 40, y: 40, zoom: 1 })
const nodeMap = computed(() => new Map(def.value.nodes.map(n => [n.id, n])))
const shapes = computed(() => new Map<string, Shape>(def.value.nodes.map(n => [n.id, ed.shape(n)])))
const selected = computed(() => new Set(ed.selection.value))
const wireSelected = computed(() => new Set(ed.wireSel.value))
// ── Wires ───────────────────────────────────────────────────────────
interface Route {
wire: Wire
pts: Pt[]
d: string
src: string
}
const toPath = (pts: Pt[]) => pts.map(([x, y], i) => `${i ? 'L' : 'M'}${x * G} ${y * G}`).join('')
const routes = computed<Route[]>(() => {
const out: Route[] = []
for (const w of def.value.wires) {
const fn = nodeMap.value.get(w.from.node)
const tn = nodeMap.value.get(w.to.node)
if (!fn || !tn) continue
const a = pinPos(fn, shapes.value.get(fn.id)!, w.from.pin, 'out')
const b = pinPos(tn, shapes.value.get(tn.id)!, w.to.pin, 'in')
if (!a || !b) continue
const pts = routeWire([a.x, a.y], [b.x, b.y], w.pts)
out.push({ wire: w, pts, d: toPath(pts), src: `${w.from.node}:${w.from.pin}` })
}
return out
})
const routeOf = (wire: Wire) => routes.value.find(r => r.wire === wire)
/** Dots where a net branches, so crossings without a dot read as "not connected". */
const junctions = computed(() => {
const groups = new Map<string, Pt[][]>()
const colors = new Map<string, string>()
for (const r of routes.value) {
const g = groups.get(r.src)
if (g) g.push(r.pts)
else groups.set(r.src, [r.pts])
if (r.wire.color && !colors.has(r.src)) colors.set(r.src, r.wire.color)
}
const dots: { x: number; y: number; src: string; color: string }[] = []
for (const [src, list] of groups) {
if (list.length < 2) continue
const candidates = new Map<string, Pt>()
for (const r of list) for (let i = 0; i < r.length - 1; i++) candidates.set(`${r[i]![0]},${r[i]![1]}`, r[i]!)
for (const [x, y] of candidates.values()) {
const dirs = new Set<string>()
for (const r of list) {
for (let i = 0; i < r.length - 1; i++) {
const [ax, ay] = r[i]!
const [bx, by] = r[i + 1]!
const onV = ax === bx && x === ax && y >= Math.min(ay, by) && y <= Math.max(ay, by)
const onH = ay === by && y === ay && x >= Math.min(ax, bx) && x <= Math.max(ax, bx)
if (!onV && !onH) continue
for (const [px, py] of [[ax, ay], [bx, by]] as Pt[]) {
if (px === x && py === y) continue
dirs.add(px < x ? 'L' : px > x ? 'R' : py < y ? 'U' : 'D')
}
}
}
if (dirs.size >= 3) dots.push({ x, y, src, color: colors.get(src) ?? '' })
}
}
return dots
})
const srcVal = (src: string) => {
const [node, pin] = src.split(':')
return ed.val(node!, pin!)
}
const hoverSrc = ref<string | null>(null)
// ── View ────────────────────────────────────────────────────────────
function bounds(nodes: CircuitNode[]) {
let x0 = Infinity
let y0 = Infinity
let x1 = -Infinity
let y1 = -Infinity
for (const n of nodes) {
const b = (shapes.value.get(n.id) ?? ed.shape(n)).body
x0 = Math.min(x0, n.x + b.x - (n.kind === 'input' || n.kind === 'button' ? 2 : 0))
y0 = Math.min(y0, n.y + b.y)
x1 = Math.max(x1, n.x + b.x + b.w + (n.kind === 'output' || n.kind === 'lamp' ? 2 : 0))
y1 = Math.max(y1, n.y + b.y + b.h)
}
return { x0, y0, x1, y1 }
}
function fit() {
const nodes = def.value.nodes
if (!nodes.length) {
ed.views[def.value.id] = { x: size.w / 2, y: size.h / 2, zoom: 1.25 }
return
}
const { x0, y0, x1, y1 } = bounds(nodes)
const pad = 2
const zoom = Math.min(2.2, Math.max(0.25, Math.min(size.w / ((x1 - x0 + 2 * pad) * G), size.h / ((y1 - y0 + 2 * pad) * G))))
ed.views[def.value.id] = {
zoom,
x: size.w / 2 - ((x0 + x1) / 2) * G * zoom,
y: size.h / 2 - ((y0 + y1) / 2) * G * zoom,
}
}
function zoomAt(factor: number, sx = size.w / 2, sy = size.h / 2) {
const v = view.value
const zoom = Math.min(4, Math.max(0.15, v.zoom * factor))
const k = zoom / v.zoom
ed.views[def.value.id] = { zoom, x: sx - (sx - v.x) * k, y: sy - (sy - v.y) * k }
}
function toWorld(e: { clientX: number; clientY: number }): Pt {
const r = root.value!.getBoundingClientRect()
const v = view.value
return [(e.clientX - r.left - v.x) / (G * v.zoom), (e.clientY - r.top - v.y) / (G * v.zoom)]
}
watch(
() => def.value.id,
id => {
if (!ed.views[id]) nextTick(fit)
},
)
let resize: ResizeObserver | undefined
onMounted(() => {
resize = new ResizeObserver(([entry]) => {
size.w = entry!.contentRect.width
size.h = entry!.contentRect.height
if (!ed.views[def.value.id]) fit()
})
resize.observe(root.value!)
window.addEventListener('keydown', onKey)
window.addEventListener('keyup', onKeyUp)
})
onBeforeUnmount(() => {
resize?.disconnect()
window.removeEventListener('keydown', onKey)
window.removeEventListener('keyup', onKeyUp)
})
// ── Placing ─────────────────────────────────────────────────────────
const cursor = ref<Pt | null>(null)
function originFor(p: { kind: CircuitNode['kind']; chip?: string }, at: Pt): Pt {
const b = ed.shape({ id: 'ghost', kind: p.kind, chip: p.chip, x: 0, y: 0 }).body
return [Math.round(at[0] - (b.x + b.w / 2)), Math.round(at[1] - (b.y + b.h / 2))]
}
const ghost = computed<CircuitNode | null>(() => {
const p = ed.placing.value
if (!p || !cursor.value) return null
const [x, y] = originFor(p, cursor.value)
return { id: 'ghost', kind: p.kind, chip: p.chip, x, y, label: p.kind === 'note' ? 'Note' : p.kind === 'input' ? '?' : undefined }
})
function onDrop(e: DragEvent) {
const raw = e.dataTransfer?.getData('application/x-logigate')
if (!raw) return
const p = JSON.parse(raw) as { kind: CircuitNode['kind']; chip?: string }
if (p.chip && !ed.canPlace(p.chip)) return ed.notify('A component cannot contain itself', 'error')
const [x, y] = originFor(p, toWorld(e))
ed.addNode(p, x, y)
}
// ── Pointer interaction ─────────────────────────────────────────────
type Drag =
| { kind: 'pan'; sx: number; sy: number; vx: number; vy: number }
| { kind: 'move'; start: Pt; orig: Map<string, Pt>; wires: Map<Wire, Pt[]>; moved: boolean; node: CircuitNode; toggle: boolean }
| { kind: 'wire'; node: string; pin: string; dir: 'in' | 'out'; cur: Pt; branch?: Pt[] }
| { kind: 'box'; start: Pt; cur: Pt; nodes: string[]; wires: string[] }
| { kind: 'segment'; wire: Wire; base: Pt[]; k: number; axis: 0 | 1; start: number; moved: boolean }
| { kind: 'corner'; wire: Wire; route: Pt[]; i: number; moved: boolean }
const drag = ref<Drag | null>(null)
const spaceDown = ref(false)
let lastClick = { id: '', t: 0 }
function isDoubleClick(id: string) {
const now = performance.now()
const dbl = lastClick.id === id && now - lastClick.t < 350
lastClick = dbl ? { id: '', t: 0 } : { id, t: now }
return dbl
}
/** Wires whose corner points travel with the nodes being moved. */
function wiresToShift(moving: Set<string>): Map<Wire, Pt[]> {
const out = new Map<Wire, Pt[]>()
for (const wire of def.value.wires) {
const both = moving.has(wire.from.node) && moving.has(wire.to.node)
if (wire.pts && (both || wireSelected.value.has(wire.id))) out.set(wire, wire.pts.map(p => [...p] as Pt))
}
return out
}
function onPointerDown(e: PointerEvent) {
const w = toWorld(e)
const v = view.value
if (e.button === 1 || e.button === 2 || (e.button === 0 && spaceDown.value)) {
drag.value = { kind: 'pan', sx: e.clientX, sy: e.clientY, vx: v.x, vy: v.y }
root.value!.setPointerCapture(e.pointerId)
return
}
if (e.button !== 0) return
root.value!.setPointerCapture(e.pointerId)
const placing = ed.placing.value
if (placing) {
if (placing.chip && !ed.canPlace(placing.chip)) {
ed.placing.value = null
return ed.notify('A component cannot contain itself', 'error')
}
const [x, y] = originFor(placing, w)
ed.addNode(placing, x, y)
if (!e.shiftKey && !placing.keep) ed.placing.value = null
return
}
const target = e.target as Element
const pinEl = target.closest('[data-pin]')
if (pinEl) {
drag.value = {
kind: 'wire',
node: pinEl.getAttribute('data-node')!,
pin: pinEl.getAttribute('data-pin')!,
dir: pinEl.getAttribute('data-dir') as 'in' | 'out',
cur: w,
}
return
}
const wireEl = target.closest('[data-wire]')
if (wireEl) return onWireDown(e, wireEl, w)
const nodeEl = target.closest('[data-node]')
if (nodeEl) {
const id = nodeEl.getAttribute('data-node')!
const node = nodeMap.value.get(id)
if (!node) return
const multi = e.shiftKey || e.ctrlKey || e.metaKey
if (multi) {
ed.selection.value = selected.value.has(id) ? ed.selection.value.filter(s => s !== id) : [...ed.selection.value, id]
} else if (!selected.value.has(id)) {
ed.selection.value = [id]
ed.wireSel.value = []
}
if (isDoubleClick(`n:${id}`)) return onDoubleClick(node)
if (node.kind === 'button') ed.press(node, true)
const ids = selected.value.has(id) ? ed.selection.value : [id]
const orig = new Map<string, Pt>()
for (const sid of ids) {
const n = nodeMap.value.get(sid)
if (n) orig.set(sid, [n.x, n.y])
}
drag.value = { kind: 'move', start: w, orig, wires: wiresToShift(new Set(ids)), moved: false, node, toggle: node.kind === 'input' && !multi }
return
}
if (!e.shiftKey) ed.clearSelection()
drag.value = { kind: 'box', start: w, cur: w, nodes: [...ed.selection.value], wires: [...ed.wireSel.value] }
}
function onWireDown(e: PointerEvent, el: Element, w: Pt) {
const wire = def.value.wires.find(x => x.id === el.getAttribute('data-wire'))
const route = wire && routeOf(wire)
if (!wire || !route) return
const corner = el.getAttribute('data-corner')
if (corner !== null) {
drag.value = { kind: 'corner', wire, route: route.pts.map(p => [...p] as Pt), i: Number(corner), moved: false }
return
}
const index = Number(el.getAttribute('data-seg'))
if (e.ctrlKey || e.metaKey) {
// Branch: a new wire from the same signal, starting at this point.
drag.value = { kind: 'wire', node: wire.from.node, pin: wire.from.pin, dir: 'out', cur: w, branch: branchCorners(route.pts, index, w) }
return
}
if (e.shiftKey) {
ed.wireSel.value = wireSelected.value.has(wire.id) ? ed.wireSel.value.filter(id => id !== wire.id) : [...ed.wireSel.value, wire.id]
return
}
if (isDoubleClick(`w:${wire.id}`)) {
ed.selectNet(wire.id)
ed.selection.value = []
return
}
if (!wireSelected.value.has(wire.id)) {
ed.wireSel.value = [wire.id]
ed.selection.value = []
}
const prep = e.altKey ? splitDrag(route.pts, index, w) : segmentDrag(route.pts, index)
if (prep) drag.value = { kind: 'segment', wire, ...prep, start: w[prep.axis], moved: false }
}
function onPointerMove(e: PointerEvent) {
const w = toWorld(e)
cursor.value = w
const d = drag.value
if (!d) return
switch (d.kind) {
case 'pan':
ed.views[def.value.id] = { ...view.value, x: d.vx + e.clientX - d.sx, y: d.vy + e.clientY - d.sy }
break
case 'move': {
const dx = Math.round(w[0] - d.start[0])
const dy = Math.round(w[1] - d.start[1])
if (!d.moved && (dx || dy)) {
d.moved = true
if (d.node.kind === 'button') ed.press(d.node, false)
}
for (const [id, [x, y]] of d.orig) {
const n = nodeMap.value.get(id)
if (n) {
n.x = x + dx
n.y = y + dy
}
}
for (const [wire, pts] of d.wires) wire.pts = pts.map(([x, y]) => [x + dx, y + dy])
break
}
case 'wire':
d.cur = w
break
case 'box': {
d.cur = w
const x0 = Math.min(d.start[0], w[0])
const x1 = Math.max(d.start[0], w[0])
const y0 = Math.min(d.start[1], w[1])
const y1 = Math.max(d.start[1], w[1])
const nodes = def.value.nodes
.filter(n => {
const b = shapes.value.get(n.id)!.body
return n.x + b.x < x1 && n.x + b.x + b.w > x0 && n.y + b.y < y1 && n.y + b.y + b.h > y0
})
.map(n => n.id)
const wires = routes.value.filter(r => r.pts.every(([x, y]) => x >= x0 && x <= x1 && y >= y0 && y <= y1)).map(r => r.wire.id)
ed.selection.value = [...new Set([...d.nodes, ...nodes])]
ed.wireSel.value = [...new Set([...d.wires, ...wires])]
break
}
case 'segment': {
const delta = Math.round(w[d.axis] - d.start)
if (!delta && !d.moved) break
d.moved = true
d.wire.pts = moveSegment(d.base, d.k, d.axis, delta)
break
}
case 'corner': {
const to: Pt = [Math.round(w[0]), Math.round(w[1])]
const at = d.route[d.i]!
if (!d.moved && to[0] === at[0] && to[1] === at[1]) break
d.moved = true
d.wire.pts = moveCorner(d.route, d.i, to)
break
}
}
}
function nearestPin(at: Pt, dir: 'in' | 'out'): { node: string; pin: string } | null {
let best: { node: string; pin: string } | null = null
let bestD = 0.8 * 0.8
for (const n of def.value.nodes) {
const s = shapes.value.get(n.id)!
for (const p of dir === 'in' ? s.inputs : s.outputs) {
const dx = n.x + p.dx - at[0]
const dy = n.y + p.dy - at[1]
const dd = dx * dx + dy * dy
if (dd < bestD) {
bestD = dd
best = { node: n.id, pin: p.key }
}
}
}
return best
}
function onPointerUp() {
const d = drag.value
drag.value = null
if (!d) return
switch (d.kind) {
case 'move':
if (d.node.kind === 'button') ed.press(d.node, false)
if (d.moved) ed.commit(false)
else if (d.toggle) ed.toggleInput(d.node)
break
case 'wire': {
const target = nearestPin(d.cur, d.dir === 'out' ? 'in' : 'out')
if (!target) break
const here = { node: d.node, pin: d.pin }
if (d.dir === 'in') {
ed.connect(target, here)
break
}
let corners = d.branch
if (corners) {
const fn = nodeMap.value.get(d.node)!
const tn = nodeMap.value.get(target.node)!
const a = pinPos(fn, shapes.value.get(fn.id)!, d.pin, 'out')!
const b = pinPos(tn, shapes.value.get(tn.id)!, target.pin, 'in')!
corners = branchTo(corners, [a.x, a.y], [b.x, b.y])
}
ed.connect(here, target, corners)
break
}
case 'segment':
case 'corner':
if (d.moved) ed.commit(false)
break
}
}
function onDoubleClick(node: CircuitNode) {
if (node.kind === 'chip' && node.chip) ed.open(node.chip)
else if (['input', 'output', 'lamp', 'button', 'note', 'hex'].includes(node.kind)) {
ed.selection.value = [node.id]
ed.labelFocus.value++
}
}
function onWheel(e: WheelEvent) {
const r = root.value!.getBoundingClientRect()
const k = e.ctrlKey ? 0.01 : 0.0015
zoomAt(Math.exp(-e.deltaY * k), e.clientX - r.left, e.clientY - r.top)
}
// ── Keyboard ────────────────────────────────────────────────────────
const QUICK: Record<string, CircuitNode['kind']> = { n: 'nand', i: 'input', o: 'output', l: 'lamp', c: 'clock', b: 'button', h: 'hex', t: 'note' }
const ARROWS: Record<string, Pt> = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }
/** Arrow keys: move the selected parts and wires one grid step (four with Shift). */
function nudge(dx: number, dy: number) {
const ids = new Set(ed.selection.value)
if (!ids.size && !ed.wireSel.value.length) return
for (const n of def.value.nodes) {
if (!ids.has(n.id)) continue
n.x += dx
n.y += dy
}
for (const r of routes.value) {
const both = ids.has(r.wire.from.node) && ids.has(r.wire.to.node)
if (wireSelected.value.has(r.wire.id)) {
const pts = r.wire.pts ?? r.pts.slice(1, -1)
r.wire.pts = pts.map(([x, y]) => [x + dx, y + dy])
} else if (both && r.wire.pts) {
r.wire.pts = r.wire.pts.map(([x, y]) => [x + dx, y + dy])
}
}
ed.commit(false)
}
function onKey(e: KeyboardEvent) {
const el = e.target as HTMLElement
if (el.closest('input, textarea, select, [contenteditable]')) return
if (ed.dialog.value || ed.showHelp.value) {
if (e.key === 'Escape') {
ed.dialog.value = null
ed.showHelp.value = false
}
return
}
const mod = e.ctrlKey || e.metaKey
const key = e.key.toLowerCase()
if (mod && key === 'z') {
e.preventDefault()
if (e.shiftKey) ed.redo()
else ed.undo()
} else if (mod && key === 'y') {
e.preventDefault()
ed.redo()
} else if (mod && key === 'c') ed.copy()
else if (mod && key === 'v') ed.paste()
else if (mod && key === 'd') {
e.preventDefault()
ed.duplicate()
} else if (mod && key === 'a') {
e.preventDefault()
ed.selectAll()
} else if (e.key === 'Delete' || e.key === 'Backspace') {
e.preventDefault()
ed.deleteSelected()
} else if (e.key === 'Escape') {
ed.placing.value = null
ed.clearSelection()
} else if (ARROWS[e.key]) {
e.preventDefault()
const [dx, dy] = ARROWS[e.key]!
const step = e.shiftKey ? 4 : 1
nudge(dx * step, dy * step)
} else if (e.key === ' ') {
e.preventDefault()
spaceDown.value = true
} else if (e.key === 'Enter' && ed.selection.value.length === 1) {
const n = nodeMap.value.get(ed.selection.value[0]!)
if (n?.kind === 'chip' && n.chip) ed.open(n.chip)
} else if (!mod && !e.altKey && key === 'f') fit()
else if (!mod && !e.altKey && e.key === '?') ed.showHelp.value = !ed.showHelp.value
else if (!mod && !e.altKey && QUICK[key]) ed.placing.value = { kind: QUICK[key]! }
}
function onKeyUp(e: KeyboardEvent) {
if (e.key === ' ') spaceDown.value = false
}
// ── Overlays ────────────────────────────────────────────────────────
const tempWire = computed(() => {
const d = drag.value
if (d?.kind !== 'wire') return null
const n = nodeMap.value.get(d.node)
if (!n) return null
const p = pinPos(n, shapes.value.get(n.id)!, d.pin, d.dir)!
const target = nearestPin(d.cur, d.dir === 'out' ? 'in' : 'out')
let end: Pt = [Math.round(d.cur[0]), Math.round(d.cur[1])]
if (target) {
const tn = nodeMap.value.get(target.node)!
const tp = pinPos(tn, shapes.value.get(tn.id)!, target.pin, d.dir === 'out' ? 'in' : 'out')!
end = [tp.x, tp.y]
}
const pts =
d.dir === 'out'
? routeWire([p.x, p.y], end, d.branch && branchTo(d.branch, [p.x, p.y], end))
: routeWire(end, [p.x, p.y])
return { d: toPath(pts), snapped: !!target }
})
const boxRect = computed(() => {
const d = drag.value
if (d?.kind !== 'box') return null
return {
x: Math.min(d.start[0], d.cur[0]) * G,
y: Math.min(d.start[1], d.cur[1]) * G,
width: Math.abs(d.cur[0] - d.start[0]) * G,
height: Math.abs(d.cur[1] - d.start[1]) * G,
}
})
/** Corner handles of the selected wires. */
const handles = computed(() =>
routes.value
.filter(r => wireSelected.value.has(r.wire.id))
.flatMap(r => r.pts.slice(1, -1).map((p, i) => ({ wire: r.wire.id, i: i + 1, x: p[0], y: p[1] }))),
)
const gridSize = computed(() => G * view.value.zoom)
const flow = computed(() => ed.project.value.settings.flow)
const cursorStyle = computed(() => {
if (drag.value?.kind === 'pan') return 'grabbing'
if (spaceDown.value) return 'grab'
if (ed.placing.value) return 'copy'
return 'default'
})
defineExpose({ fit, zoomAt })
</script>
<template>
<div
ref="root"
class="canvas"
:style="{ cursor: cursorStyle }"
@pointerdown="onPointerDown"
@pointermove="onPointerMove"
@pointerup="onPointerUp"
@pointercancel="onPointerUp"
@pointerleave="cursor = null"
@wheel.prevent="onWheel"
@contextmenu.prevent
@dragover.prevent
@drop.prevent="onDrop"
>
<svg width="100%" height="100%">
<defs>
<pattern id="grid-dots" :width="gridSize" :height="gridSize" patternUnits="userSpaceOnUse" :x="view.x" :y="view.y">
<circle :cx="0.75" :cy="0.75" :r="view.zoom > 0.5 ? 0.9 : 0.6" class="grid-dot" />
</pattern>
<pattern id="grid-major" :width="gridSize * 8" :height="gridSize * 8" patternUnits="userSpaceOnUse" :x="view.x" :y="view.y">
<circle :cx="0.75" :cy="0.75" r="1.4" class="grid-major" />
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#grid-dots)" />
<rect width="100%" height="100%" fill="url(#grid-major)" />
<g :transform="`translate(${view.x} ${view.y}) scale(${view.zoom})`">
<g class="wires">
<g
v-for="r in routes"
:key="r.wire.id"
class="wire"
:class="[
r.wire.color ? `c-${r.wire.color}` : '',
{ on: srcVal(r.src) === 1, selected: wireSelected.has(r.wire.id), hover: hoverSrc === r.src },
]"
>
<path v-if="wireSelected.has(r.wire.id)" :d="r.d" class="wire-halo" />
<path :d="r.d" class="wire-line" />
<path v-if="flow && srcVal(r.src) === 1" :d="r.d" class="wire-flow" />
<path
v-for="(p, i) in r.pts.slice(0, -1)"
:key="i"
:d="`M${p[0] * G} ${p[1] * G}L${r.pts[i + 1]![0] * G} ${r.pts[i + 1]![1] * G}`"
class="wire-hit"
:class="{ vertical: p[0] === r.pts[i + 1]![0] }"
:data-wire="r.wire.id"
:data-seg="i"
@pointerenter="hoverSrc = r.src"
@pointerleave="hoverSrc = null"
/>
</g>
<g v-for="(j, i) in junctions" :key="`j${i}`" class="wire" :class="[j.color ? `c-${j.color}` : '', { on: srcVal(j.src) === 1 }]">
<circle :cx="j.x * G" :cy="j.y * G" r="3.2" class="junction" />
</g>
</g>
<EditorNodeView
v-for="n in def.nodes"
:key="n.id"
:node="n"
:shape="shapes.get(n.id)!"
:selected="selected.has(n.id)"
/>
<rect
v-for="h in handles"
:key="`${h.wire}-${h.i}`"
:x="h.x * G - 3.5"
:y="h.y * G - 3.5"
width="7"
height="7"
rx="1.5"
class="corner-handle"
:data-wire="h.wire"
:data-corner="h.i"
/>
<path v-if="tempWire" :d="tempWire.d" class="temp-wire" :class="{ snapped: tempWire.snapped }" />
<EditorNodeView v-if="ghost" :node="ghost" :shape="ed.shape(ghost)" :selected="false" ghost />
<rect v-if="boxRect" v-bind="boxRect" class="box-select" />
</g>
</svg>
<div v-if="!def.nodes.length" class="empty-hint">
<p class="font-semibold">Empty circuit</p>
<p>Drag parts in from the left, or press <kbd>N</kbd> for a NAND gate.</p>
</div>
<div class="zoom-controls" @pointerdown.stop>
<button title="Zoom out" @click="zoomAt(1 / 1.25)"><Icon name="lucide:minus" /></button>
<span class="tabular-nums">{{ Math.round(view.zoom * 100) }}%</span>
<button title="Zoom in" @click="zoomAt(1.25)"><Icon name="lucide:plus" /></button>
<button title="Fit to screen (F)" @click="fit"><Icon name="lucide:scan" /></button>
</div>
</div>
</template>