565 lines
20 KiB
Vue
565 lines
20 KiB
Vue
<script setup lang="ts">
|
|
import { GRID as G, pinPos, routeWire, simplify, type Pt, type Shape } from '~/lib/logic/geometry'
|
|
import type { CircuitNode, Wire } from '~/lib/logic/types'
|
|
|
|
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))
|
|
|
|
// ── 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
|
|
})
|
|
|
|
/** Dots where a net branches, so crossings without a dot read as "not connected". */
|
|
const junctions = computed(() => {
|
|
const groups = new Map<string, Pt[][]>()
|
|
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])
|
|
}
|
|
const dots: { x: number; y: number; src: 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 })
|
|
}
|
|
}
|
|
return dots
|
|
})
|
|
|
|
const srcVal = (src: string) => {
|
|
const [node, pin] = src.split(':')
|
|
return ed.val(node!, pin!)
|
|
}
|
|
|
|
// ── 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 }
|
|
| { kind: 'box'; start: Pt; cur: Pt; base: string[] }
|
|
| { kind: 'segment'; wire: Wire; index: number; axis: 0 | 1; base: Pt[]; start: number }
|
|
| { kind: 'press'; node: CircuitNode }
|
|
|
|
const drag = ref<Drag | null>(null)
|
|
const spaceDown = ref(false)
|
|
let lastClick = { id: '', t: 0 }
|
|
|
|
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 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.selectedWire.value = null
|
|
|
|
const now = performance.now()
|
|
if (lastClick.id === id && now - lastClick.t < 350) {
|
|
lastClick = { id: '', t: 0 }
|
|
onDoubleClick(node)
|
|
return
|
|
}
|
|
lastClick = { id, t: now }
|
|
|
|
if (node.kind === 'button') ed.press(node, true)
|
|
const ids = selected.value.has(id) ? ed.selection.value : [id]
|
|
const set = new Set(ids)
|
|
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])
|
|
}
|
|
const wires = new Map<Wire, Pt[]>()
|
|
for (const wire of def.value.wires) {
|
|
if (wire.pts && set.has(wire.from.node) && set.has(wire.to.node)) wires.set(wire, wire.pts.map(p => [...p] as Pt))
|
|
}
|
|
drag.value = { kind: 'move', start: w, orig, wires, moved: false, node, toggle: node.kind === 'input' && !multi }
|
|
return
|
|
}
|
|
|
|
const wireEl = target.closest('[data-wire]')
|
|
if (wireEl) {
|
|
const wire = def.value.wires.find(x => x.id === wireEl.getAttribute('data-wire'))
|
|
if (!wire) return
|
|
ed.selectedWire.value = wire.id
|
|
ed.selection.value = []
|
|
const route = routes.value.find(r => r.wire === wire)
|
|
const index = Number(wireEl.getAttribute('data-seg'))
|
|
if (route && index >= 1 && index + 1 <= route.pts.length - 2) {
|
|
const [a, b] = [route.pts[index]!, route.pts[index + 1]!]
|
|
const axis = a[0] === b[0] ? 0 : 1
|
|
drag.value = { kind: 'segment', wire, index, axis, base: route.pts.map(p => [...p] as Pt), start: w[axis] }
|
|
}
|
|
return
|
|
}
|
|
|
|
if (!e.shiftKey) {
|
|
ed.selection.value = []
|
|
ed.selectedWire.value = null
|
|
}
|
|
drag.value = { kind: 'box', start: w, cur: w, base: [...ed.selection.value] }
|
|
}
|
|
|
|
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 hits = 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)
|
|
ed.selection.value = [...new Set([...d.base, ...hits])]
|
|
break
|
|
}
|
|
case 'segment': {
|
|
const delta = Math.round(w[d.axis] - d.start)
|
|
const pts = d.base.map(p => [...p] as Pt)
|
|
pts[d.index]![d.axis] += delta
|
|
pts[d.index + 1]![d.axis] += delta
|
|
d.wire.pts = simplify(pts).slice(1, -1)
|
|
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 === 'out') ed.connect(here, target)
|
|
else ed.connect(target, here)
|
|
break
|
|
}
|
|
case 'segment':
|
|
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'].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' }
|
|
|
|
function onKey(e: KeyboardEvent) {
|
|
const el = e.target as HTMLElement
|
|
if (el.closest('input, textarea, select, [contenteditable]')) 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.selection.value = []
|
|
ed.selectedWire.value = null
|
|
ed.showHelp.value = false
|
|
} 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) : 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,
|
|
}
|
|
})
|
|
|
|
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="{ on: srcVal(r.src) === 1, selected: ed.selectedWire.value === r.wire.id }"
|
|
>
|
|
<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="{ draggable: i >= 1 && i + 1 <= r.pts.length - 2, vertical: p[0] === r.pts[i + 1]![0] }"
|
|
:data-wire="r.wire.id"
|
|
:data-seg="i"
|
|
/>
|
|
</g>
|
|
<circle
|
|
v-for="(j, i) in junctions"
|
|
:key="`j${i}`"
|
|
:cx="j.x * G"
|
|
:cy="j.y * G"
|
|
r="3.2"
|
|
class="junction"
|
|
:class="{ on: srcVal(j.src) === 1 }"
|
|
/>
|
|
</g>
|
|
|
|
<EditorNodeView
|
|
v-for="n in def.nodes"
|
|
:key="n.id"
|
|
:node="n"
|
|
:shape="shapes.get(n.id)!"
|
|
:selected="selected.has(n.id)"
|
|
/>
|
|
|
|
<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>
|