From a241adc94ee86149cfd5fcb4d2a21a51d0ce007a Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Sat, 17 Oct 2026 13:21:49 +0200 Subject: [PATCH] A component faces, project library with share links, fine-grained wire editing - Lamps and hex displays inside a component show on its box with their labels, lit by that instance's state; Counter 4 example shows its count. - Several projects per browser; share links at /p/ that the creator's edits save to automatically, others get their own copy. Export, open a file as project, or add a file's components to the open project. - Wires: drag any segment or corner, Alt+drag for a new bend, Ctrl+drag to branch, double-click selects the whole signal, multi-select, arrow keys, colour tags. - Share-link API (POST/GET/PUT /api/p) on Nitro fs storage in data/, mounted as a volume on edgerealm. Co-Authored-By: Claude Opus 5.5 (1M context) --- .dockerignore | 1 + .gitignore | 3 + README.md | 13 +- app/assets/css/main.css | 243 ++++++++++++- app/components/editor/App.vue | 33 ++ app/components/editor/Canvas.vue | 234 +++++++++---- app/components/editor/Help.vue | 9 +- app/components/editor/Inspector.vue | 61 +++- app/components/editor/NodeView.vue | 19 +- app/components/editor/Palette.vue | 5 +- app/components/editor/ProjectsDialog.vue | 78 +++++ app/components/editor/ShareDialog.vue | 71 ++++ app/components/editor/Toolbar.vue | 71 ++-- app/composables/useEditor.ts | 427 ++++++++++++++++++++--- app/lib/logic/compile.ts | 11 + app/lib/logic/examples.ts | 10 +- app/lib/logic/geometry.ts | 85 ++++- app/lib/logic/ops.ts | 30 +- app/lib/logic/project.ts | 45 +++ app/lib/logic/sim.ts | 6 + app/lib/logic/storage.ts | 126 +++++-- app/lib/logic/types.ts | 8 + app/lib/logic/wires.ts | 113 ++++++ app/pages/index.vue | 27 +- app/pages/p/[id].vue | 10 + deploy.sh | 2 +- docker-compose.yml | 2 + nuxt.config.ts | 7 + package.json | 1 + pnpm-lock.yaml | 288 ++++++++------- server/api/p/[id].get.ts | 9 + server/api/p/[id].put.ts | 16 + server/api/p/index.post.ts | 13 + server/utils/shares.ts | 65 ++++ tests/features.test.ts | 194 ++++++++++ 35 files changed, 1935 insertions(+), 401 deletions(-) create mode 100644 app/components/editor/App.vue create mode 100644 app/components/editor/ProjectsDialog.vue create mode 100644 app/components/editor/ShareDialog.vue create mode 100644 app/lib/logic/project.ts create mode 100644 app/lib/logic/wires.ts create mode 100644 app/pages/p/[id].vue create mode 100644 server/api/p/[id].get.ts create mode 100644 server/api/p/[id].put.ts create mode 100644 server/api/p/index.post.ts create mode 100644 server/utils/shares.ts create mode 100644 tests/features.test.ts diff --git a/.dockerignore b/.dockerignore index c0431b1..a5b5b7f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,3 +17,4 @@ localhost-key.pem *.key *.map *.log +data diff --git a/.gitignore b/.gitignore index 8ddf438..176aeb2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ docker-data/ # Playwright artefacts test-results/ playwright-report/ + +# Shared projects (server storage) +data/ diff --git a/README.md b/README.md index 7ca8550..d243555 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,18 @@ 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, `ssr: false`), Tailwind CSS v4, Lucide icons via `@nuxt/icon`, Inter and JetBrains Mono self-hosted via `@nuxt/fonts`. No backend, no tracking: projects live in the browser's localStorage and can be exported as JSON. +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. ## 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. - 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. +- 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. +- 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. - Example library, all built from NAND: NOT, AND, OR, NOR, XOR, XNOR, Mux, Half/Full Adder, SR Latch, D Latch, D Flip-Flop, Register 4, Increment 4, Adder 4, Counter 4, and a counter demo with a hex display. @@ -23,9 +27,14 @@ 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). +- `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). +## Share links + +[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. + ## Develop ```bash @@ -38,4 +47,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. 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. 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). diff --git a/app/assets/css/main.css b/app/assets/css/main.css index b2e1ace..9272028 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -703,23 +703,55 @@ kbd { fill: #303b4c; } +.wire { + --w-on: var(--on); + --w-off: var(--off); +} + +.wire.c-red { --w-on: #ff5c5c; --w-off: #6b3337; } +.wire.c-orange { --w-on: #ff9f43; --w-off: #6b4a2b; } +.wire.c-yellow { --w-on: #ffd93d; --w-off: #625a2e; } +.wire.c-blue { --w-on: #4dabff; --w-off: #2b4a6b; } +.wire.c-purple { --w-on: #b388ff; --w-off: #463768; } +.wire.c-pink { --w-on: #ff7ac6; --w-off: #673657; } + .wire-line { fill: none; - stroke: var(--off); + stroke: var(--w-off); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; } .wire.on .wire-line { - stroke: var(--on); + stroke: var(--w-on); } -.wire.selected .wire-line { - stroke: var(--accent); +.wire.hover .wire-line { stroke-width: 3; } +.wire-halo { + fill: none; + stroke: var(--accent); + stroke-opacity: 0.35; + stroke-width: 8; + stroke-linejoin: round; + stroke-linecap: round; + pointer-events: none; +} + +.corner-handle { + fill: var(--panel); + stroke: var(--accent); + stroke-width: 1.5; + cursor: move; +} + +.corner-handle:hover { + fill: var(--accent); +} + .wire-flow { fill: none; stroke: #d2ffe6; @@ -744,20 +776,20 @@ kbd { cursor: pointer; } -.wire-hit.draggable { +.wire-hit { cursor: ns-resize; } -.wire-hit.draggable.vertical { +.wire-hit.vertical { cursor: ew-resize; } .junction { - fill: var(--off); + fill: var(--w-off); } -.junction.on { - fill: var(--on); +.wire.on .junction { + fill: var(--w-on); } .temp-wire { @@ -1145,3 +1177,196 @@ kbd { .shortcuts dd { color: #c3ccd6; } + +.face-label { + fill: var(--muted); + font-family: var(--font-mono); + font-size: 8px; + pointer-events: none; +} + +.swatches { + display: flex; + gap: 6px; +} + +.swatch { + width: 22px; + height: 22px; + border-radius: 50%; + border: 2px solid transparent; + background: var(--w-on); + outline: 1px solid var(--border); +} + +.swatch.none { + background: var(--on); +} + +.swatch.c-red { --w-on: #ff5c5c; } +.swatch.c-orange { --w-on: #ff9f43; } +.swatch.c-yellow { --w-on: #ffd93d; } +.swatch.c-blue { --w-on: #4dabff; } +.swatch.c-purple { --w-on: #b388ff; } +.swatch.c-pink { --w-on: #ff7ac6; } + +.swatch.active { + border-color: var(--panel); + outline: 2px solid var(--text); +} + +.tips { + font-size: 12px; + color: var(--muted); + line-height: 1.5; + margin: 2px 0 12px; + display: grid; + gap: 3px; +} + +.tips strong { + color: var(--text); + font-weight: 600; +} + +.check { + display: flex; + align-items: flex-start; + gap: 8px; + font-size: 12px; + color: var(--text); + margin: 2px 0 12px; + line-height: 1.4; +} + +.check input { + margin-top: 2px; + accent-color: var(--accent); +} + +.btn:disabled { + opacity: 0.4; + cursor: not-allowed; +} + +.project-btn { + max-width: 220px; + font-weight: 600; +} + +.share-btn { + border: 1px solid var(--border); +} + +.share-btn.saved, +.share-btn.dirty, +.share-btn.saving { + color: var(--on); +} + +.share-btn.error { + color: var(--danger); +} + +.project-list { + margin-top: 14px; + display: grid; + gap: 4px; + max-height: 50vh; + overflow-y: auto; +} + +.project-list li { + display: flex; + align-items: center; + gap: 4px; + padding: 4px; + border-radius: 8px; + border: 1px solid transparent; +} + +.project-list li:hover { + background: var(--panel-2); +} + +.project-list li.current { + border-color: var(--border); + background: var(--panel-2); +} + +.project-list .pick { + flex: 1; + min-width: 0; + display: grid; + gap: 2px; + text-align: left; + padding: 4px 6px; +} + +.project-list .name { + font-weight: 600; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.project-list .meta { + display: inline-flex; + align-items: center; + gap: 4px; + font-size: 12px; + color: var(--muted); +} + +.project-list .badge { + font-size: 10px; + font-weight: 600; + color: var(--accent); + margin-left: 6px; +} + +.project-list .rename { + flex: 1; + background: var(--bg); + border: 1px solid var(--accent); + border-radius: 6px; + padding: 6px 8px; + outline: none; +} + +.icon-btn { + display: grid; + place-items: center; + width: 28px; + height: 28px; + border-radius: 6px; + color: var(--muted); +} + +.icon-btn:hover { + background: var(--panel); + color: var(--text); +} + +.link-row { + display: flex; + gap: 8px; +} + +.link-row input { + flex: 1; + min-width: 0; + height: 32px; + padding: 0 10px; + border-radius: 6px; + border: 1px solid var(--border); + background: var(--bg); + font-family: var(--font-mono); + font-size: 13px; + color: var(--text); + outline: none; +} + +.modal.share .result { + align-items: center; +} diff --git a/app/components/editor/App.vue b/app/components/editor/App.vue new file mode 100644 index 0000000..5347235 --- /dev/null +++ b/app/components/editor/App.vue @@ -0,0 +1,33 @@ + + + diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index 9c64dee..4c4692f 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -1,6 +1,7 @@ + + diff --git a/app/components/editor/ShareDialog.vue b/app/components/editor/ShareDialog.vue new file mode 100644 index 0000000..1674f5d --- /dev/null +++ b/app/components/editor/ShareDialog.vue @@ -0,0 +1,71 @@ + + + diff --git a/app/components/editor/Toolbar.vue b/app/components/editor/Toolbar.vue index b3a1779..978910c 100644 --- a/app/components/editor/Toolbar.vue +++ b/app/components/editor/Toolbar.vue @@ -1,8 +1,5 @@