From 5e17826ba525a1ad6d006699dce011be619b6450 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Tue, 20 Oct 2026 13:09:37 +0200 Subject: [PATCH] A settings for every part, overlap-free wiring with crossing styles, accounts with sync - Clicking anything opens its settings: swap parts in place (wires stay on matching pins), clock frequency per clock, keyboard keys for switches and buttons, lamp/display colours, note sizes, component names on the canvas, position, unlink all wires, unpack a component, make an independent copy. - Wires of different signals never share a line: auto routes pick free columns or detours, remaining clashes go on separate lanes. Crossings drawn as bow, triangle, bridge, gap or plain. - Accounts (email + scrypt password, httpOnly session) with two-way project sync and conflict copies; per-account limits; cross-site writes refused. - Compatibility suite: a project and both browser-storage layouts from release a241adc must load and compute identically. Co-Authored-By: Claude Opus 5.5 (1M context) --- README.md | 16 +- app/assets/css/main.css | 116 + app/components/editor/AccountDialog.vue | 139 + app/components/editor/App.vue | 2 + app/components/editor/Canvas.vue | 50 +- app/components/editor/CrossingIcon.vue | 14 + app/components/editor/Help.vue | 5 +- app/components/editor/Inspector.vue | 111 +- app/components/editor/NodeSettings.vue | 251 ++ app/components/editor/NodeView.vue | 25 +- app/components/editor/ProjectsDialog.vue | 11 +- app/components/editor/Toolbar.vue | 16 + app/composables/useEditor.ts | 341 ++- app/lib/draw.ts | 40 +- app/lib/logic/compile.ts | 16 +- app/lib/logic/geometry.ts | 14 +- app/lib/logic/ops.ts | 124 +- app/lib/logic/project.ts | 17 +- app/lib/logic/routing.ts | 384 +++ app/lib/logic/sim.ts | 17 +- app/lib/logic/storage.ts | 45 + app/lib/logic/types.ts | 17 + nuxt.config.ts | 5 +- server/api/auth/delete.post.ts | 15 + server/api/auth/login.post.ts | 10 + server/api/auth/logout.post.ts | 4 + server/api/auth/me.get.ts | 5 + server/api/auth/password.post.ts | 13 + server/api/auth/register.post.ts | 16 + server/api/me/projects/[id].delete.ts | 15 + server/api/me/projects/[id].get.ts | 10 + server/api/me/projects/[id].put.ts | 48 + server/api/me/projects/index.get.ts | 6 + server/middleware/origin.ts | 13 + server/utils/accounts.ts | 51 + server/utils/auth.ts | 109 + tests/compat.test.ts | 75 + tests/fixtures/v1-expected.json | 793 +++++ tests/fixtures/v1-localstorage.json | 10 + tests/fixtures/v1-project.json | 3424 ++++++++++++++++++++++ tests/parts.test.ts | 140 + tests/perf.test.ts | 19 + tests/routing.test.ts | 107 + 43 files changed, 6542 insertions(+), 117 deletions(-) create mode 100644 app/components/editor/AccountDialog.vue create mode 100644 app/components/editor/CrossingIcon.vue create mode 100644 app/components/editor/NodeSettings.vue create mode 100644 app/lib/logic/routing.ts create mode 100644 server/api/auth/delete.post.ts create mode 100644 server/api/auth/login.post.ts create mode 100644 server/api/auth/logout.post.ts create mode 100644 server/api/auth/me.get.ts create mode 100644 server/api/auth/password.post.ts create mode 100644 server/api/auth/register.post.ts create mode 100644 server/api/me/projects/[id].delete.ts create mode 100644 server/api/me/projects/[id].get.ts create mode 100644 server/api/me/projects/[id].put.ts create mode 100644 server/api/me/projects/index.get.ts create mode 100644 server/middleware/origin.ts create mode 100644 server/utils/accounts.ts create mode 100644 server/utils/auth.ts create mode 100644 tests/compat.test.ts create mode 100644 tests/fixtures/v1-expected.json create mode 100644 tests/fixtures/v1-localstorage.json create mode 100644 tests/fixtures/v1-project.json create mode 100644 tests/parts.test.ts create mode 100644 tests/perf.test.ts create mode 100644 tests/routing.test.ts diff --git a/README.md b/README.md index d243555..c4493b4 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,20 @@ Logic circuit editor and simulator at , in the spirit of the game "Turing Complete". NAND is the only gate. You draw circuits with it, package them as components, and reuse those in bigger circuits, up to a CPU. Everything runs live while you draw: green wires carry a 1, grey wires a 0. -Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@nuxt/icon`, Inter and JetBrains Mono self-hosted via `@nuxt/fonts`. No tracking. Projects live in the browser's localStorage; the only server part is the share-link API. +Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@nuxt/icon`, Inter and JetBrains Mono self-hosted via `@nuxt/fonts`. No tracking. Projects live in the browser's localStorage, and in the user's account when signed in. The server part is the share-link and account API. ## What it does - Parts: NAND, input switch, output pin, lamp, push button, clock, constant 1, ground, hex display, note. - Every circuit is a component. Its input and output nodes become its pins, ordered top to bottom. Double-click a component to open it. - Lamps and hex displays inside a component show on its box, with their labels, lit by that instance's state. They are laid out in rows the way they sit inside. A checkbox in the inspector turns this off per component. +- Clicking anything opens its settings on the right. Parts can be swapped in place (wires stay on the pins in the same position): NAND and components with each other, switch/button/clock/constants with each other, output/lamp/display with each other. Clocks have their own frequency or follow the top bar. Switches and buttons can get a keyboard key. Lamps and displays have colours, notes have sizes, components a name on the canvas. Components can be unpacked into their parts or given their own copy of the definition; any part can have all its wires unlinked. - Select parts and press "Make component" to turn them into a new component; wires crossing the selection become pins. - Gate symbols in IEC 60617 (DIN, default) or ANSI. A component with one output can be drawn as a gate symbol. +- Wires of different signals never share a line: auto-routed wires pick a free column or a detour, and anything still clashing (hand-placed bends) is drawn on its own lane. Crossings are drawn as a bow, triangle, bridge, gap or plain crossing (Display settings on the right with nothing selected). Clicking a junction dot selects its whole signal. - Wire editing: drag any segment (a stub keeps the pin end straight), drag corner squares, Alt+drag to pull out a new bend, Ctrl+drag to branch a new wire off a signal, double-click to select the whole signal, Shift+click and box selection for several wires, arrow keys to shift them, six colour tags. - Several projects per browser (Projects dialog: open, rename, duplicate, delete). Export a project file, open a file as a new project, or add the components of a file to the open project. +- Accounts: email and password. Signed in, every project in the browser is also kept in the account and synced in both directions (on sign-in, on focus, every minute, and two seconds after a change). If two computers changed the same project, both versions are kept. The untouched starter project of a new browser is not uploaded; signing in there opens your latest project instead. - Share links: `/p/`. The creator's changes save to the link automatically. Anyone else who opens it gets their own copy; their first edit detaches it from the link. - Truth table, NAND count, gate delay, and loop detection for the open circuit. - 17 challenges (NOT up to a D flip-flop) checked against a truth table or a step sequence. @@ -27,6 +30,7 @@ All in [app/lib/logic/](app/lib/logic/), plain TypeScript with no Vue dependency - Gate outputs are keyed by their path ("chipNode/chipNode/nand"), so latch state survives editing. - `analyze.ts` builds truth tables, counts NANDs, computes the longest gate path, and runs challenge tests. - `examples.ts` builds the example library with a small builder; `ops.ts` holds project edits (package selection, copy/paste, prune dangling wires, recursion check). +- `routing.ts` lays out all wires of a circuit (free lanes, detours, separation, crossings). - `wires.ts` edits wire routes (segment and corner drags, splits, branches); `project.ts` validates project data for both the browser and the server; `storage.ts` is the browser's project library. The editor UI is in [app/components/editor/](app/components/editor/) with state in [app/composables/useEditor.ts](app/composables/useEditor.ts). @@ -35,6 +39,14 @@ The editor UI is in [app/components/editor/](app/components/editor/) with state [server/api/p/](server/api/p/): `POST /api/p` stores a project and returns `{ id, key }`; `GET /api/p/:id` reads it; `PUT /api/p/:id` with header `x-edit-key` replaces it. Only a SHA-256 of the key is stored. Each link is one JSON file in `data/shares/` (Nitro fs storage). Limits: 2 MB and 100,000 nodes per project, 30 new links and 600 saves per IP per 10 minutes (in memory). The edit key lives only in the creator's browser (project index in localStorage), never in exported files. +## Accounts + +[server/api/auth/](server/api/auth/) (register, login, logout, me, password, delete) and [server/api/me/projects/](server/api/me/projects/) (list, get, put, delete). Passwords are hashed with scrypt; the session is a random token in an httpOnly, SameSite=Lax cookie, stored server-side as a SHA-256. API calls that change something are refused when their Origin is another site. Storage (Nitro fs): `data/users`, `data/sessions`, `data/accounts//` with an index (revision per project, deletions for a year) and one file per project. Each save sends the revision it started from; a mismatch answers 409 and the browser keeps the other version as a copy. Limits: 1000 projects and 100 MB per account, 2 MB per project, login 20 tries per 10 minutes per IP, 10 new accounts per hour per IP. + +## Compatibility + +Projects saved by earlier releases must keep working. [tests/compat.test.ts](tests/compat.test.ts) loads a project and both browser-storage layouts written by release a241adc ([tests/fixtures/](tests/fixtures/), never edit them) and checks every component's truth table, NAND count and delay. New fields are optional and have defaults. + ## Develop ```bash @@ -47,4 +59,4 @@ pnpm build # .output/ ## Deploy -Same pattern as autismus-spektrum. On edgerealm the repo lives in `/mnt/HC_Volume_102040804/srv/logigate`; run `./deploy.sh` there. It pulls, builds in a one-shot container and recreates the `logigate` container. Shared projects live in `data/` next to the repo (mounted into the container), so redeploys keep them; include that folder in backups. Host nginx terminates TLS with the `*.blax.at` wildcard cert and forwards to Traefik, which routes `logicate.blax.at` and `logigate.blax.at` by the labels in [docker-compose.yml](docker-compose.yml). +Same pattern as autismus-spektrum. On edgerealm the repo lives in `/mnt/HC_Volume_102040804/srv/logigate`; run `./deploy.sh` there. It pulls, builds in a one-shot container and recreates the `logigate` container. Share links and accounts live in `data/` next to the repo (mounted into the container), so redeploys keep them; include that folder in backups. Host nginx terminates TLS with the `*.blax.at` wildcard cert and forwards to Traefik, which routes `logicate.blax.at` and `logigate.blax.at` by the labels in [docker-compose.yml](docker-compose.yml). diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 9272028..0725841 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -1370,3 +1370,119 @@ kbd { .modal.share .result { align-items: center; } + +/* Lamp and display colours */ +.lamp.on.l-red { fill: #ff5c5c; stroke: #ffc2c2; filter: drop-shadow(0 0 6px rgb(255 92 92 / 0.75)); } +.lamp.on.l-green { fill: #3ddc84; stroke: #b5f5d0; filter: drop-shadow(0 0 6px rgb(61 220 132 / 0.75)); } +.lamp.on.l-blue { fill: #4dabff; stroke: #bfe0ff; filter: drop-shadow(0 0 6px rgb(77 171 255 / 0.75)); } +.lamp.on.l-white { fill: #f4f6fa; stroke: #ffffff; filter: drop-shadow(0 0 6px rgb(244 246 250 / 0.7)); } +.l-yellow .seg.on { stroke: #ffd34d; filter: drop-shadow(0 0 3px rgb(255 211 77 / 0.8)); } +.l-green .seg.on { stroke: #3ddc84; filter: drop-shadow(0 0 3px rgb(61 220 132 / 0.8)); } +.l-blue .seg.on { stroke: #4dabff; filter: drop-shadow(0 0 3px rgb(77 171 255 / 0.8)); } +.l-white .seg.on { stroke: #f4f6fa; filter: drop-shadow(0 0 3px rgb(244 246 250 / 0.7)); } + +.lamp-swatch.default, +.lamp-swatch.l-yellow { background: #ffd34d; } +.lamp-swatch.default.hex, +.lamp-swatch.l-red { background: #ff5c5c; } +.lamp-swatch.l-green { background: #3ddc84; } +.lamp-swatch.l-blue { background: #4dabff; } +.lamp-swatch.l-white { background: #f4f6fa; } + +.instance-label { + fill: var(--accent); + font-family: var(--font-mono); + font-size: 10px; + font-weight: 600; + pointer-events: none; +} + +.key-badge { + fill: var(--muted); + font-family: var(--font-mono); + font-size: 8px; + pointer-events: none; +} + +.junction { + cursor: pointer; +} + +.key-input { + cursor: pointer; + caret-color: transparent; +} + +.field.mb-0 { + margin-bottom: 0; +} + +.crossings { + display: grid; + grid-template-columns: repeat(5, 1fr); + gap: 4px; +} + +.crossing { + display: flex; + flex-direction: column; + align-items: center; + gap: 2px; + padding: 4px 0 3px; + border: 1px solid var(--border); + border-radius: 6px; + font-size: 10px; + color: var(--muted); +} + +.crossing.active { + border-color: var(--accent); + color: var(--accent); + background: rgb(76 194 255 / 0.08); +} + +.ci-v, +.ci-h { + fill: none; + stroke-width: 2; + stroke-linejoin: round; +} + +.ci-v { stroke: var(--muted); } +.ci-h { stroke: var(--on); } + +.account-btn { + position: relative; +} + +.avatar { + display: grid; + place-items: center; + width: 22px; + height: 22px; + border-radius: 50%; + background: rgb(76 194 255 / 0.18); + color: var(--accent); + font-size: 11px; + font-weight: 700; +} + +.sync-dot { + position: absolute; + right: 5px; + bottom: 5px; + width: 7px; + height: 7px; + border-radius: 50%; + border: 1.5px solid var(--panel); + background: var(--muted); +} + +.account-btn.synced .sync-dot { background: var(--on); } +.account-btn.syncing .sync-dot { background: var(--lamp); } +.account-btn.error .sync-dot, +.account-btn.offline .sync-dot { background: var(--danger); } + +.modal .hint a { + color: var(--accent); +} diff --git a/app/components/editor/AccountDialog.vue b/app/components/editor/AccountDialog.vue new file mode 100644 index 0000000..755ef66 --- /dev/null +++ b/app/components/editor/AccountDialog.vue @@ -0,0 +1,139 @@ + + + diff --git a/app/components/editor/App.vue b/app/components/editor/App.vue index 5347235..42098cb 100644 --- a/app/components/editor/App.vue +++ b/app/components/editor/App.vue @@ -4,6 +4,7 @@ const ed = useEditor() onMounted(() => { const stop = ed.startLoop() onBeforeUnmount(stop) + void ed.startAccount() try { if (!localStorage.getItem('logigate:help-seen')) ed.showHelp.value = true } catch {} @@ -29,5 +30,6 @@ onMounted(() => { + diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index 4c4692f..5d0ca16 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -2,6 +2,8 @@ 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' +import { circuitRoutes, findCrossings } from '~/lib/logic/routing' +import { wirePath } from '~/lib/draw' const ed = useEditor() const root = ref() @@ -18,7 +20,10 @@ const wireSelected = computed(() => new Set(ed.wireSel.value)) // ── Wires ─────────────────────────────────────────────────────────── interface Route { wire: Wire + /** Whole-grid route, used for dragging, handles and hit areas. */ pts: Pt[] + /** Route as drawn: on its own lane where it would share a line with another signal. */ + draw: Pt[] d: string src: string } @@ -26,18 +31,15 @@ interface Route { const toPath = (pts: Pt[]) => pts.map(([x, y], i) => `${i ? 'L' : 'M'}${x * G} ${y * G}`).join('') const routes = computed(() => { - 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}` }) + const routed = circuitRoutes(def.value, shapes.value) + const hops = new Map>() + for (const c of findCrossings(routed)) { + const segs = hops.get(c.wire) ?? hops.set(c.wire, new Map()).get(c.wire)! + segs.set(c.seg, [...(segs.get(c.seg) ?? []), c.x]) } - return out + const style = ed.project.value.settings.crossing ?? 'bow' + const byId = new Map(def.value.wires.map(w => [w.id, w])) + return routed.map((r, k) => ({ wire: byId.get(r.id)!, pts: r.grid, draw: r.draw, d: wirePath(r.draw, hops.get(k), style), src: r.net })) }) const routeOf = (wire: Wire) => routes.value.find(r => r.wire === wire) @@ -48,8 +50,8 @@ const junctions = computed(() => { const colors = new Map() 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 (g) g.push(r.draw) + else groups.set(r.src, [r.draw]) 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 }[] = [] @@ -244,6 +246,15 @@ function onPointerDown(e: PointerEvent) { return } + const junctionEl = target.closest('[data-junction]') + if (junctionEl) { + // A junction dot stands for its whole signal. + const src = junctionEl.getAttribute('data-junction') + ed.wireSel.value = def.value.wires.filter(x => `${x.from.node}:${x.from.pin}` === src).map(x => x.id) + ed.selection.value = [] + return + } + const wireEl = target.closest('[data-wire]') if (wireEl) return onWireDown(e, wireEl, w) @@ -480,6 +491,15 @@ function onKey(e: KeyboardEvent) { } const mod = e.ctrlKey || e.metaKey const key = e.key.toLowerCase() + // Keys bound to switches and buttons win over the shortcuts below. + if (!mod && !e.altKey && e.key.length === 1) { + const bound = def.value.nodes.filter(n => n.key === key && (n.kind === 'input' || n.kind === 'button')) + if (bound.length) { + e.preventDefault() + if (!e.repeat) for (const n of bound) n.kind === 'input' ? ed.toggleInput(n) : ed.press(n, true) + return + } + } if (mod && key === 'z') { e.preventDefault() if (e.shiftKey) ed.redo() @@ -519,6 +539,8 @@ function onKey(e: KeyboardEvent) { function onKeyUp(e: KeyboardEvent) { if (e.key === ' ') spaceDown.value = false + const key = e.key.toLowerCase() + for (const n of def.value.nodes) if (n.kind === 'button' && n.key === key) ed.press(n, false) } // ── Overlays ──────────────────────────────────────────────────────── @@ -626,7 +648,7 @@ defineExpose({ fit, zoomAt }) /> - + diff --git a/app/components/editor/CrossingIcon.vue b/app/components/editor/CrossingIcon.vue new file mode 100644 index 0000000..eaf4073 --- /dev/null +++ b/app/components/editor/CrossingIcon.vue @@ -0,0 +1,14 @@ + + + diff --git a/app/components/editor/Help.vue b/app/components/editor/Help.vue index 4917b1f..823e030 100644 --- a/app/components/editor/Help.vue +++ b/app/components/editor/Help.vue @@ -2,7 +2,8 @@ const ed = useEditor() const SHORTCUTS: [string, string][] = [ - ['Click switch', 'Flip an input between 0 and 1'], + ['Click switch', 'Flip an input between 0 and 1 (give it a keyboard key in its settings)'], + ['Click anything', 'Its settings appear on the right: swap the part, clock speed, colours, keys, position'], ['Drag from a pin', 'Draw a wire to another pin'], ['Drag a wire segment', 'Move that segment; drag a corner square to move a bend'], ['Alt + drag a wire', 'Pull a new bend out of it'], @@ -62,7 +63,7 @@ function close() {
{{ v }}
-

Your work is saved in this browser. Use Share to get a link or export a file.

+

Your work is saved in this browser. Sign in (top right) to have it on every computer; use Share to get a link or export a file.

diff --git a/app/components/editor/Inspector.vue b/app/components/editor/Inspector.vue index bb301e4..a705c84 100644 --- a/app/components/editor/Inspector.vue +++ b/app/components/editor/Inspector.vue @@ -1,28 +1,13 @@ + +