diff --git a/README.md b/README.md index df760a3..11da78a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n - Gates with more inputs: a placed AND, OR, XOR, NAND or NOR (built in, from the examples, or your own) has an "Inputs" setting from 2 to 16. The wide version is a component built as a balanced tree of the two-input gate (NAND and NOR as the plain gate plus a final inverted one), made once per gate and width in "Wide gates" and reused; transistors count honestly and changes to the two-input gate carry through. Which gates qualify is read off their truth table ([app/lib/logic/wide.ts](app/lib/logic/wide.ts)). - Campaign (Projects → New campaign): you start with NAND, inputs, outputs, lamps and notes, and no examples. Each challenge opens once the ones it builds on are solved (NOT → AND, OR, SR Latch → …), and your own solution becomes a part you can place. Other basic parts unlock on the way: constants with NOT, the input panel with AND, hex display and pixel with the decoder, cables with Adder 2, the button with the SR latch, the clock with the D latch. Rules in [app/lib/logic/progress.ts](app/lib/logic/progress.ts). Sandbox projects keep everything open. - Puzzles: "Publish as puzzle" (This circuit) turns a circuit into a link `/puzzle/`. Only its behaviour is published, as a truth table, or for circuits with memory as a run of input changes from power-on; the circuit stays private. Whoever opens the link gets the puzzle in their project, sees the target and the author's transistor count, and after a pass their solution goes to the server, which re-runs the checks and counts the transistors itself (with a fixed work budget) and keeps each player's best. The board shows everyone's transistor counts and your place. The puzzle of the week is generated from the ISO week, the same for everyone: three or four inputs, one or two outputs, each depending on every input. Players are anonymous ids per browser. +- Library: everyone's published components in one public list (bottom bar → Components → Library, Space, or the main menu), searchable by name, description and author, each with its transistors, pins and what it uses. "Publish to the library…" in the menu on a circuit's name sends it with every component it uses and their connector types, under your leaderboard name; the server checks it like any project and counts transistors and pins itself. Publishing the same component again from the same browser and project makes the next version of the same entry; only that browser has the entry's edit key, so only it can update or remove it. "Add" brings an entry into the open project and starts placing it: what the project has in exactly that form already is used as it is, the rest comes with new ids (a name that is taken gets a number) and connector types join one with the same lines. The This panel says where a component came from and offers a newer version, which replaces it in place; what came along with the old version goes once nothing else uses it. Another entry's component is never reused, so updating one entry leaves the others as they were. Challenges and puzzles, and components with a solution anywhere inside, are never published. A campaign takes nothing from the library: it is built from your own work. Logic in [app/lib/logic/library.ts](app/lib/logic/library.ts). - Sound (speaker in the top bar; volume and clock ticks in Settings, the gear in the top bar): clicks for placing, wiring, switches and buttons, a tick per clock cycle up to 8 Hz (off by default), and jingles for a solve, a failed check, unlocks and new records. All synthesised with Web Audio, no sound files ([app/lib/audio.ts](app/lib/audio.ts)). - Transistors: every component shows how many it takes, counted as a CMOS NAND (4 transistors) per gate at every depth: in the palette, its settings and the circuit stats. Each challenge keeps your record, the fewest transistors of any passing solution, and says so when you beat it. - Cables: a bundle gathers 2 to 32 wires into one cable, a split fans it out again in the same order; one bundle can feed several splits. Select the wires (a box across them, or Shift + click) and press "Bundle into cable" or Ctrl+G: the cable starts right after the sources on their middle row and ends right before the targets on theirs, so the wires keep running as they did (backwards too); an end steps aside when another part is in the way. "Place the ends yourself…" (Ctrl+Shift+G) lets you click where it starts and ends, with a preview; Esc cancels. "Unlink all" on a bundle or split removes only the wires going in or out; the cable stays. Drag the bundle and split later to move the ends. Up to 16 wires, the cable is drawn as a ribbon: each wire is its own thin line inside, in its own colour, lit while it carries a 1. The sleeve starts neutral and gets its own colour (cable or bundle/split settings). "Remove cable" turns it back into single wires. A cable end only joins another cable end, and the cable shows its width. @@ -55,6 +56,7 @@ All in [app/lib/logic/](app/lib/logic/), plain TypeScript with no Vue dependency - `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, and the tidy layout), and after a move keeps the hand-placed bends that still leave a clear way (`settleCorners`). - `move.ts` moves parts for a drag and the arrow keys, always from where they started, with their wires. +- `library.ts` gathers a component with everything it uses for the public library, checks what comes from outside and adds entries to a project (shared with the server, [server/api/library/](server/api/library/)). - `progress.ts` holds the campaign rules; `puzzles.ts` makes, checks and scores puzzles and generates the weekly one (shared with the server, [server/api/puzzles/](server/api/puzzles/), storage in `data/puzzles`). - `cables.ts` bundles wires into cables (ends where you click, or next to sources and targets), takes them apart again, and lays out the ribbon lines (`offsetPath`, `ribbon`). - `panels.ts` docks input panels to components and keeps them in step; `labels.ts` does series names and names taken from pins. @@ -66,6 +68,10 @@ 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. +## Library + +[server/api/library/](server/api/library/): `POST /api/library` publishes `{ player, root, components, connectors }` and returns `{ id, key, version }`; `PUT /api/library/:id` with header `x-edit-key` publishes the next version; `DELETE /api/library/:id` with the key takes it out. `GET /api/library?q=` lists every entry, newest first, narrowed to those with every word in name, description, group or author; `GET /api/library/:id` returns one with its components (`?meta`: without). Each entry is one JSON file in `data/library/entries/`, plus `data/library/index` for the list (both in the daily backup). Only a SHA-256 of the key is stored; authors show by their leaderboard name, never by their player id. Challenge and library marks are dropped from what comes in, and the list keeps only short texts, pin counts and the first 16 pin names a side, so it stays small. Limits: 1 MB per entry, 30 publishes per IP per 10 minutes, 20,000 entries. + ## 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: `data/users`, `data/sessions`, `data/accounts//` with an index (revision per project, deletions for a year), one file per project, and savegames in `h//`. 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 plus 500 KB for what its circuits hold, login 20 tries per 10 minutes per IP, 10 new accounts per hour per IP. diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 7c03662..2dab846 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -3362,6 +3362,114 @@ kbd { color: var(--muted); } +/* ── Library: components everyone published ─────────────────────── */ +.modal.library-modal { + width: min(720px, 100%); +} + +.library-modal .search.part-search { + margin: 12px 0 4px; +} + +.lib-list { + display: grid; + gap: 6px; + margin-top: 10px; +} + +.lib-entry { + display: grid; + grid-template-columns: 56px minmax(0, 1fr) auto; + gap: 12px; + align-items: start; + padding: 10px; + border: 1px solid var(--border); + border-radius: 8px; + background: var(--panel-2); +} + +.lib-thumb { + width: 56px; + height: 56px; +} + +.lib-thumb rect { + fill: var(--chip); + stroke: var(--chip-stroke); + stroke-width: 0.12; +} + +.lib-thumb line { + stroke: var(--chip-stroke); + stroke-width: 0.12; +} + +.lib-title { + display: flex; + align-items: baseline; + min-width: 0; + font-weight: 600; +} + +.lib-by, +.lib-stats { + font-size: 12px; + color: var(--muted); +} + +.lib-desc { + display: -webkit-box; + margin-top: 4px; + overflow: hidden; + font-size: 12.5px; + line-height: 1.45; + color: #c3ccd6; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; +} + +.lib-stats { + display: flex; + flex-wrap: wrap; + gap: 4px 12px; + margin-top: 6px; + font-family: var(--font-mono); + font-size: 11px; +} + +.lib-actions { + display: flex; + flex-direction: column; + align-items: stretch; + gap: 6px; +} + +@media (max-width: 560px) { + .lib-entry { + grid-template-columns: 40px minmax(0, 1fr); + } + + .lib-thumb { + width: 40px; + height: 40px; + } + + .lib-actions { + grid-column: 1 / -1; + flex-direction: row; + } +} + +/* A component from the library, in the This panel. */ +.lib-origin { + display: flex; + align-items: center; + gap: 6px; + margin: -6px 0 12px; + font-size: 12px; + color: var(--muted); +} + /* ── Face designer ──────────────────────────────────────────────── */ .modal.face-modal { width: min(900px, 100%); diff --git a/app/components/editor/App.vue b/app/components/editor/App.vue index db4cc7f..56a280c 100644 --- a/app/components/editor/App.vue +++ b/app/components/editor/App.vue @@ -81,5 +81,7 @@ watch( + + diff --git a/app/components/editor/BottomBar.vue b/app/components/editor/BottomBar.vue index 44951cc..aac7968 100644 --- a/app/components/editor/BottomBar.vue +++ b/app/components/editor/BottomBar.vue @@ -320,6 +320,7 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
+
diff --git a/app/components/editor/CircuitPane.vue b/app/components/editor/CircuitPane.vue index 2130691..2b9f2fd 100644 --- a/app/components/editor/CircuitPane.vue +++ b/app/components/editor/CircuitPane.vue @@ -1,11 +1,13 @@ + + diff --git a/app/components/editor/LibraryPublishDialog.vue b/app/components/editor/LibraryPublishDialog.vue new file mode 100644 index 0000000..fbd6de9 --- /dev/null +++ b/app/components/editor/LibraryPublishDialog.vue @@ -0,0 +1,137 @@ + + +