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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
// Reading project data from files, links and storage. Shared by the browser
|
|
|
|
|
// and the share-link server, so it must stay free of browser APIs.
|
|
|
|
|
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
import { cleanPuzzle } from './puzzles'
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
import {
|
|
|
|
|
CROSSING_STYLES,
|
|
|
|
|
FACE_INKS,
|
|
|
|
|
LAMP_COLORS,
|
|
|
|
|
PANEL_CONTROLS,
|
|
|
|
|
WIRE_COLORS,
|
2026-10-28 11:59:18 +00:00
|
|
|
type AsmDoc,
|
2026-10-28 12:12:43 +00:00
|
|
|
type Bench,
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
type CircuitNode,
|
|
|
|
|
type ComponentDef,
|
2026-10-22 16:59:56 +00:00
|
|
|
type ConnectorType,
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
type FaceDesign,
|
A memory that stays: circuits keep their bits across visits and saves; Power off and on
What latches, flip-flops, registers and RAM built from NANDs hold is no
longer lost when you go into a component and come back, reload the page or
open the project on another computer. Leaving a circuit puts its bits in
the project, and opening it starts from them.
Only the gates on feedback loops can hold a bit, so only those that are 1
are kept, plus the clocks that are high: each node id once, each gate as
the path levels it shares with the gate before plus the rest. 1,024
flip-flops take about 30 KB. Restoring runs the gates in the order signals
flow, so the gates in front of a latch are right before it reads them;
gates that no longer exist after an edit are ignored.
The bits go with every save, file, share link and account upload. Between
saves (a clock running, a button pressed) they are put in this browser's
copy every 30 seconds and when the page is left, without counting as a
change: no sync, savegame or undo step of their own, and never over a save
made in another tab. Projects without them start from all zeros as before.
"Power off and on" in the menu on the circuit's name, or with Space,
starts the open circuit again from all zeros.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:09:18 +00:00
|
|
|
type HeldState,
|
A public library of components: publish yours, add everybody's
"Publish to the library…" in the menu on a circuit's name (or Space)
sends the component with every component it uses and their connector
types, under your leaderboard name. The server checks it like any
project, refuses what is missing, inside itself, nested too deep or too
big to run, and counts its transistors and pins itself. Publishing again
from the same browser makes the next version of the same entry; only that
browser holds the entry's key, so only it can update or remove it.
Challenge circuits and puzzle solutions stay private.
The Library (Components in the bottom bar, Space, the main menu) lists
every entry, newest first, searchable by name, description and author,
with a picture of its box, its transistors, pins and what comes along.
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 taken name gets a number, 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. A campaign only adds
what is built from parts it has earned, and its challenges take nothing
from the library.
Components keep an optional "from" mark; projects without it load and
compute as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:14:46 +00:00
|
|
|
type LibraryOrigin,
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
type PanelRow,
|
|
|
|
|
type Project,
|
|
|
|
|
type PuzzleSpec,
|
|
|
|
|
} from './types'
|
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) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
|
|
|
|
|
/** Drops optional node settings that are out of range, so a hand-edited file can't break the editor. */
|
|
|
|
|
function cleanNode(n: CircuitNode) {
|
|
|
|
|
if (n.hz !== undefined && !(typeof n.hz === 'number' && n.hz > 0 && n.hz <= 1000)) delete n.hz
|
|
|
|
|
if (n.color !== undefined && !LAMP_COLORS.includes(n.color)) delete n.color
|
|
|
|
|
if (n.key !== undefined && !(typeof n.key === 'string' && n.key.length === 1)) delete n.key
|
|
|
|
|
if (n.size !== undefined && !['sm', 'md', 'lg'].includes(n.size)) delete n.size
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
if (n.autoLabel !== undefined && n.autoLabel !== true) delete n.autoLabel
|
2026-10-20 17:29:16 +00:00
|
|
|
if (n.bits !== undefined && !(Number.isInteger(n.bits) && n.bits >= 2 && n.bits <= 32)) delete n.bits
|
2026-10-22 16:59:56 +00:00
|
|
|
if (n.conn !== undefined && !(typeof n.conn === 'string' && n.conn.length <= 32)) delete n.conn
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
if (n.attach !== undefined && typeof n.attach !== 'string') delete n.attach
|
|
|
|
|
if (n.skip !== undefined) {
|
|
|
|
|
if (Array.isArray(n.skip)) n.skip = n.skip.filter(k => typeof k === 'string').slice(0, MAX_ROWS)
|
|
|
|
|
else delete n.skip
|
|
|
|
|
}
|
|
|
|
|
if (n.rows !== undefined) {
|
|
|
|
|
if (!Array.isArray(n.rows)) delete n.rows
|
|
|
|
|
else n.rows = n.rows.filter(cleanRow).slice(0, MAX_ROWS)
|
|
|
|
|
}
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (n.plug !== undefined && typeof n.plug !== 'string') delete n.plug
|
2026-10-23 13:34:36 +00:00
|
|
|
if (n.latch !== undefined && typeof n.latch !== 'string') delete n.latch
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (n.pitch !== undefined && !(Number.isInteger(n.pitch) && n.pitch >= 1 && n.pitch <= 8)) delete n.pitch
|
|
|
|
|
if (n.offsets !== undefined && !(Array.isArray(n.offsets) && n.offsets.every(v => Number.isInteger(v) && v >= 0 && v <= 10_000))) delete n.offsets
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
for (const k of ['names', 'invert', 'splitPorts'] as const) {
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (n[k] !== undefined && !(Array.isArray(n[k]) && n[k]!.every(v => typeof v === 'string'))) delete n[k]
|
|
|
|
|
}
|
|
|
|
|
if (n.inner !== undefined && n.inner !== true) delete n.inner
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
if (n.screen !== undefined && typeof n.screen !== 'string') delete n.screen
|
2026-10-28 11:51:09 +00:00
|
|
|
if (n.rgb !== undefined && n.rgb !== true) delete n.rgb
|
2026-10-28 12:12:43 +00:00
|
|
|
if (n.bench !== undefined) {
|
|
|
|
|
const b = n.bench as Partial<Bench>
|
|
|
|
|
const cells = (r: unknown) => (r && typeof r === 'object' && !Array.isArray(r) ? Object.fromEntries(Object.entries(r).filter(([, v]) => typeof v === 'string').slice(0, 256)) : undefined)
|
|
|
|
|
if (!b || typeof b !== 'object' || !Array.isArray(b.rows)) delete n.bench
|
|
|
|
|
else {
|
2026-10-28 12:30:07 +00:00
|
|
|
const cols = Array.isArray(b.cols)
|
|
|
|
|
? b.cols
|
|
|
|
|
.filter(c => c && typeof c.id === 'string' && typeof c.name === 'string' && (c.dir === 'drive' || c.dir === 'check'))
|
|
|
|
|
.slice(0, 64)
|
|
|
|
|
.map(c => ({ id: c.id, name: c.name.slice(0, 40), bits: Number.isInteger(c.bits) && c.bits >= 1 && c.bits <= 32 ? c.bits : 1, dir: c.dir }))
|
|
|
|
|
: undefined
|
2026-10-28 12:12:43 +00:00
|
|
|
n.bench = {
|
|
|
|
|
...(typeof b.on === 'string' ? { on: b.on } : {}),
|
2026-10-28 12:30:07 +00:00
|
|
|
...(cols ? { cols } : {}),
|
2026-10-28 12:12:43 +00:00
|
|
|
rows: b.rows.slice(0, 4096).filter(r => r && typeof r === 'object').map(r => ({
|
|
|
|
|
...(cells(r.set) ? { set: cells(r.set) } : {}),
|
|
|
|
|
...(cells(r.expect) ? { expect: cells(r.expect) } : {}),
|
|
|
|
|
...(typeof r.ticks === 'string' ? { ticks: r.ticks } : {}),
|
|
|
|
|
})),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MAX_ROWS = 256
|
|
|
|
|
|
|
|
|
|
function cleanRow(r: PanelRow): boolean {
|
|
|
|
|
if (!r || typeof r !== 'object' || typeof r.id !== 'string' || !r.id) return false
|
|
|
|
|
if (!PANEL_CONTROLS.includes(r.type)) r.type = 'switch'
|
|
|
|
|
for (const k of ['label', 'name'] as const) if (r[k] !== undefined && typeof r[k] !== 'string') delete r[k]
|
|
|
|
|
if (r.on !== undefined && typeof r.on !== 'boolean') delete r.on
|
|
|
|
|
if (r.hz !== undefined && !(typeof r.hz === 'number' && r.hz > 0 && r.hz <= 1000)) delete r.hz
|
|
|
|
|
if (r.dy !== undefined && !(Number.isInteger(r.dy) && r.dy >= 0 && r.dy <= 10_000)) delete r.dy
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (r.key !== undefined && !(typeof r.key === 'string' && r.key.length === 1)) delete r.key
|
|
|
|
|
if (r.color !== undefined && !LAMP_COLORS.includes(r.color)) delete r.color
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
return true
|
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) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
}
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
const num = (v: unknown, lo: number, hi: number) => typeof v === 'number' && Number.isFinite(v) && v >= lo && v <= hi
|
|
|
|
|
|
|
|
|
|
/** A hand-drawn box: sizes and places in range, drawings of known kinds; a broken one is dropped. */
|
|
|
|
|
function cleanDesign(d: ComponentDef) {
|
|
|
|
|
const f = d.design as FaceDesign | undefined
|
|
|
|
|
if (!f || typeof f !== 'object' || !num(f.w, 1, 200) || !num(f.h, 1, 200)) {
|
|
|
|
|
delete d.design
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (f.place !== undefined) {
|
|
|
|
|
if (!f.place || typeof f.place !== 'object' || Array.isArray(f.place)) delete f.place
|
|
|
|
|
else for (const [k, v] of Object.entries(f.place)) if (!v || !num(v.x, -200, 400) || !num(v.y, -200, 400)) delete f.place[k]
|
|
|
|
|
}
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
for (const k of ['hide', 'show'] as const) if (f[k] !== undefined && !(Array.isArray(f[k]) && f[k]!.every(v => typeof v === 'string'))) delete f[k]
|
|
|
|
|
// Sizes, turns and pin rows: numbers in range only.
|
|
|
|
|
const nums = (rec: Record<string, number> | undefined, ok: (v: number) => boolean) => {
|
|
|
|
|
if (!rec || typeof rec !== 'object' || Array.isArray(rec)) return undefined
|
|
|
|
|
for (const [k, v] of Object.entries(rec)) if (!(typeof v === 'number' && ok(v))) delete rec[k]
|
|
|
|
|
return rec
|
|
|
|
|
}
|
|
|
|
|
if (f.scale !== undefined) f.scale = nums(f.scale, v => v >= 0.25 && v <= 4)
|
|
|
|
|
if (f.rotate !== undefined) f.rotate = nums(f.rotate, v => [0, 90, 180, 270].includes(v))
|
|
|
|
|
if (f.pinAt !== undefined) f.pinAt = nums(f.pinAt, v => Number.isInteger(v) && v >= 0 && v <= 1000)
|
|
|
|
|
for (const k of ['scale', 'rotate', 'pinAt'] as const) if (f[k] === undefined) delete f[k]
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
for (const k of ['pinOrder', 'split'] as const) if (f[k] !== undefined && !(Array.isArray(f[k]) && f[k]!.every(v => typeof v === 'string'))) delete f[k]
|
|
|
|
|
if (f.fit !== undefined && f.fit !== true) delete f.fit
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (f.shapes !== undefined) {
|
|
|
|
|
f.shapes = Array.isArray(f.shapes)
|
|
|
|
|
? f.shapes
|
|
|
|
|
.filter(
|
|
|
|
|
sh =>
|
|
|
|
|
sh &&
|
|
|
|
|
typeof sh.id === 'string' &&
|
|
|
|
|
['line', 'rect', 'ellipse', 'text'].includes(sh.kind) &&
|
|
|
|
|
[sh.x, sh.y, sh.w, sh.h].every(v => num(v, -400, 400)),
|
|
|
|
|
)
|
|
|
|
|
.slice(0, 500)
|
|
|
|
|
: []
|
|
|
|
|
for (const sh of f.shapes) {
|
|
|
|
|
if (sh.ink !== undefined && !FACE_INKS.includes(sh.ink)) delete sh.ink
|
|
|
|
|
if (sh.text !== undefined && typeof sh.text !== 'string') delete sh.text
|
|
|
|
|
if (sh.size !== undefined && !num(sh.size, 0.25, 4)) delete sh.size
|
|
|
|
|
if (sh.fill !== undefined && sh.fill !== true) delete sh.fill
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
if (sh.rotate !== undefined && ![0, 90, 180, 270].includes(sh.rotate)) delete sh.rotate
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
A public library of components: publish yours, add everybody's
"Publish to the library…" in the menu on a circuit's name (or Space)
sends the component with every component it uses and their connector
types, under your leaderboard name. The server checks it like any
project, refuses what is missing, inside itself, nested too deep or too
big to run, and counts its transistors and pins itself. Publishing again
from the same browser makes the next version of the same entry; only that
browser holds the entry's key, so only it can update or remove it.
Challenge circuits and puzzle solutions stay private.
The Library (Components in the bottom bar, Space, the main menu) lists
every entry, newest first, searchable by name, description and author,
with a picture of its box, its transistors, pins and what comes along.
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 taken name gets a number, 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. A campaign only adds
what is built from parts it has earned, and its challenges take nothing
from the library.
Components keep an optional "from" mark; projects without it load and
compute as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:14:46 +00:00
|
|
|
/** Where a library component came from: an entry id, a version and a name; anything else is dropped. */
|
|
|
|
|
function cleanOrigin(d: ComponentDef) {
|
|
|
|
|
const f = d.from as Partial<LibraryOrigin> | undefined
|
|
|
|
|
if (!f || typeof f.id !== 'string' || !/^[A-Za-z0-9]{6,16}$/.test(f.id) || !Number.isInteger(f.version) || f.version! < 1) {
|
|
|
|
|
delete d.from
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
d.from = { id: f.id, version: f.version!, author: typeof f.author === 'string' ? f.author.slice(0, 24) : '', ...(f.inside === true ? { inside: true } : {}) }
|
|
|
|
|
}
|
|
|
|
|
|
BF library: no solutions inside, nothing into a campaign, marks only from the entry, a small listing, updates clear what they replace
A component with a challenge or puzzle solution anywhere inside stays
private, not only a challenge circuit itself, so wrapping a solution in a
part of its own no longer publishes it.
A campaign takes nothing from the library: Add and "Get version" are off
there, with a line saying why. A library part could be duplicated,
published again or taken apart into a solution, so a check on placing was
not enough.
Library marks come only from the entry being added. The server drops the
marks a publisher sends, and whether an entry is yours depends only on the
key this browser keeps for that project and component, so a part claiming
to be someone's entry can't be published over it.
The listing keeps pin counts and the first 16 pin names a side, short, and
a group of 40 characters at most, so it stays small whatever is sent.
"Get version" clears away what came along with the old version once
nothing else uses it, and the new parts take its names. Adding never
reuses another entry's component, so updating one entry leaves the others
as they were.
Wire corner points that aren't number pairs are dropped when a project,
link or library entry is read, so a circuit can always be drawn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:44:13 +00:00
|
|
|
/** A wire's corner points: [x, y] pairs of plain numbers, or the wire can't be drawn. */
|
|
|
|
|
const cornersOk = (pts: unknown) => Array.isArray(pts) && pts.every(p => Array.isArray(p) && p.length === 2 && p.every(v => typeof v === 'number' && Number.isFinite(v)))
|
|
|
|
|
|
BF memory: a newer save brings its own bits, bits reach the account when you leave, room for them
A project that comes in with the same circuit open (a newer save from
another computer, a savegame restored in place, a shared link opened
again) now runs from the bits it brings. Before, the running circuit
went on with this computer's old bits and wrote them over the newer ones
at the next save, and a savegame could not undo Power off and on.
Bits changed only by buttons or a clock are sent to the account when the
page is hidden or closed, when you leave the project, and before signing
out, so they are no longer lost by "remove from this browser" and reach
the other computer. A running clock alone still sends nothing. Bits alone
keep the project's save time, so an edit saved on another computer wins
over them and they end up in its savegames.
What circuits hold has its own room of 500 KB per project on top of the
2 MB limit, in the browser, the account and share links. When it is full,
the circuits left longest ago start from 0; a circuit that holds more than
that on its own says so once. A project can no longer become too large to
load because of its memory.
A savegame opened as a copy saves the project it leaves first, like every
other way of switching projects.
Tests now run the editor itself (in a stand-in browser with an account
server) for going into components and back, reloads, two projects, other
computers, savegames, signing out and the room limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:44:43 +00:00
|
|
|
/** Upper bounds for a project that comes from outside. What its circuits hold has its own room (`state`) on top of `bytes`. */
|
|
|
|
|
export const LIMITS = { bytes: 2_000_000, components: 2_000, nodes: 100_000, state: 500_000 }
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
|
|
|
|
|
/** Checks and normalises project data. Throws with a readable message. */
|
|
|
|
|
export function toProject(data: unknown): Project {
|
|
|
|
|
const p = data as Partial<Project>
|
|
|
|
|
if (!p || typeof p !== 'object' || !Array.isArray(p.components) || p.components.length === 0) {
|
|
|
|
|
throw new Error('Not a Logigate project (no components)')
|
|
|
|
|
}
|
|
|
|
|
if (p.components.length > LIMITS.components) throw new Error('Too many components')
|
|
|
|
|
let nodes = 0
|
|
|
|
|
for (const d of p.components) {
|
|
|
|
|
if (typeof d?.id !== 'string' || typeof d.name !== 'string' || !Array.isArray(d.nodes) || !Array.isArray(d.wires)) {
|
|
|
|
|
throw new Error('Not a Logigate project (broken component)')
|
|
|
|
|
}
|
|
|
|
|
nodes += d.nodes.length
|
|
|
|
|
d.symbol ??= 'box'
|
2026-10-20 18:09:23 +00:00
|
|
|
if (d.wide !== undefined && !(d.wide && typeof d.wide.base === 'string' && Number.isInteger(d.wide.n) && d.wide.n >= 2 && d.wide.n <= 16)) delete d.wide
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (d.design !== undefined) cleanDesign(d)
|
A public library of components: publish yours, add everybody's
"Publish to the library…" in the menu on a circuit's name (or Space)
sends the component with every component it uses and their connector
types, under your leaderboard name. The server checks it like any
project, refuses what is missing, inside itself, nested too deep or too
big to run, and counts its transistors and pins itself. Publishing again
from the same browser makes the next version of the same entry; only that
browser holds the entry's key, so only it can update or remove it.
Challenge circuits and puzzle solutions stay private.
The Library (Components in the bottom bar, Space, the main menu) lists
every entry, newest first, searchable by name, description and author,
with a picture of its box, its transistors, pins and what comes along.
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 taken name gets a number, 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. A campaign only adds
what is built from parts it has earned, and its challenges take nothing
from the library.
Components keep an optional "from" mark; projects without it load and
compute as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:14:46 +00:00
|
|
|
if (d.from !== undefined) cleanOrigin(d)
|
2026-10-28 11:36:30 +00:00
|
|
|
if (d.probes !== undefined) {
|
|
|
|
|
d.probes = Array.isArray(d.probes) ? d.probes.filter(p => p && typeof p.node === 'string' && typeof p.pin === 'string').slice(0, 64) : []
|
|
|
|
|
for (const p of d.probes) if (p.label !== undefined && typeof p.label !== 'string') delete p.label
|
|
|
|
|
if (!d.probes.length) delete d.probes
|
|
|
|
|
}
|
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) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
for (const n of d.nodes) cleanNode(n)
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
for (const w of d.wires) if (w.color && !WIRE_COLORS.includes(w.color)) delete w.color
|
BF library: no solutions inside, nothing into a campaign, marks only from the entry, a small listing, updates clear what they replace
A component with a challenge or puzzle solution anywhere inside stays
private, not only a challenge circuit itself, so wrapping a solution in a
part of its own no longer publishes it.
A campaign takes nothing from the library: Add and "Get version" are off
there, with a line saying why. A library part could be duplicated,
published again or taken apart into a solution, so a check on placing was
not enough.
Library marks come only from the entry being added. The server drops the
marks a publisher sends, and whether an entry is yours depends only on the
key this browser keeps for that project and component, so a part claiming
to be someone's entry can't be published over it.
The listing keeps pin counts and the first 16 pin names a side, short, and
a group of 40 characters at most, so it stays small whatever is sent.
"Get version" clears away what came along with the old version once
nothing else uses it, and the new parts take its names. Adding never
reuses another entry's component, so updating one entry leaves the others
as they were.
Wire corner points that aren't number pairs are dropped when a project,
link or library entry is read, so a circuit can always be drawn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:44:13 +00:00
|
|
|
for (const w of d.wires) if (w.pts !== undefined && !cornersOk(w.pts)) delete w.pts
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
}
|
|
|
|
|
if (nodes > LIMITS.nodes) throw new Error('Project too large')
|
|
|
|
|
return {
|
|
|
|
|
version: 1,
|
|
|
|
|
name: typeof p.name === 'string' && p.name.trim() ? p.name.trim().slice(0, 80) : 'Untitled',
|
|
|
|
|
components: p.components,
|
|
|
|
|
openId: p.components.some(d => d.id === p.openId) ? p.openId! : p.components[0]!.id,
|
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) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
settings: {
|
|
|
|
|
symbols: p.settings?.symbols === 'ansi' ? 'ansi' : 'iec',
|
|
|
|
|
flow: p.settings?.flow ?? true,
|
|
|
|
|
...(p.settings?.crossing && CROSSING_STYLES.includes(p.settings.crossing) ? { crossing: p.settings.crossing } : {}),
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
...(p.settings?.tidy === true ? { tidy: true } : {}),
|
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) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
},
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
solved: Array.isArray(p.solved) ? p.solved.filter(s => typeof s === 'string') : [],
|
2026-10-20 17:29:16 +00:00
|
|
|
...(bestOf(p.best) ? { best: bestOf(p.best)! } : {}),
|
A main menu: free play, campaign, challenges and leaderboard over a circuit that builds itself
Logigate opens on a title screen. Continue, Free play (your own projects),
Campaign (progress and what is next), Challenges (every challenge and the
puzzle of the week in one Challenges project), Leaderboard (the best ten of
this and earlier weeks, your place, your records), Settings. Arrow keys,
Enter and Esc work through it; links still open straight into the editor.
Players can name themselves on the leaderboards. The logo in the editor
leads back to the menu.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 10:22:35 +00:00
|
|
|
...(p.mode === 'campaign' || p.mode === 'challenges' ? { mode: p.mode } : {}),
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
...(puzzlesOf(p.puzzles) ? { puzzles: puzzlesOf(p.puzzles)! } : {}),
|
2026-10-22 16:59:56 +00:00
|
|
|
...(connectorsOf(p.connectors) ? { connectors: connectorsOf(p.connectors)! } : {}),
|
A memory that stays: circuits keep their bits across visits and saves; Power off and on
What latches, flip-flops, registers and RAM built from NANDs hold is no
longer lost when you go into a component and come back, reload the page or
open the project on another computer. Leaving a circuit puts its bits in
the project, and opening it starts from them.
Only the gates on feedback loops can hold a bit, so only those that are 1
are kept, plus the clocks that are high: each node id once, each gate as
the path levels it shares with the gate before plus the rest. 1,024
flip-flops take about 30 KB. Restoring runs the gates in the order signals
flow, so the gates in front of a latch are right before it reads them;
gates that no longer exist after an edit are ignored.
The bits go with every save, file, share link and account upload. Between
saves (a clock running, a button pressed) they are put in this browser's
copy every 30 seconds and when the page is left, without counting as a
change: no sync, savegame or undo step of their own, and never over a save
made in another tab. Projects without them start from all zeros as before.
"Power off and on" in the menu on the circuit's name, or with Space,
starts the open circuit again from all zeros.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:09:18 +00:00
|
|
|
...(stateOf(p.state, p.components) ? { state: stateOf(p.state, p.components)! } : {}),
|
2026-10-28 11:59:18 +00:00
|
|
|
...(asmOf(p.asm) ? { asm: asmOf(p.asm)! } : {}),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The assembler's texts, if they are texts (long ones cut). */
|
|
|
|
|
function asmOf(a: unknown): AsmDoc | null {
|
|
|
|
|
const d = a as Partial<AsmDoc> | null
|
|
|
|
|
if (!d || typeof d !== 'object' || typeof d.table !== 'string' || typeof d.source !== 'string') return null
|
|
|
|
|
const width = Number.isInteger(d.width) && d.width! >= 1 && d.width! <= 32 ? d.width! : 8
|
|
|
|
|
return {
|
|
|
|
|
table: d.table.slice(0, 50_000),
|
|
|
|
|
source: d.source.slice(0, 200_000),
|
|
|
|
|
width,
|
|
|
|
|
...(typeof d.target === 'string' ? { target: d.target } : {}),
|
|
|
|
|
...(d.msbTop === true ? { msbTop: true } : {}),
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
A memory that stays: circuits keep their bits across visits and saves; Power off and on
What latches, flip-flops, registers and RAM built from NANDs hold is no
longer lost when you go into a component and come back, reload the page or
open the project on another computer. Leaving a circuit puts its bits in
the project, and opening it starts from them.
Only the gates on feedback loops can hold a bit, so only those that are 1
are kept, plus the clocks that are high: each node id once, each gate as
the path levels it shares with the gate before plus the rest. 1,024
flip-flops take about 30 KB. Restoring runs the gates in the order signals
flow, so the gates in front of a latch are right before it reads them;
gates that no longer exist after an edit are ignored.
The bits go with every save, file, share link and account upload. Between
saves (a clock running, a button pressed) they are put in this browser's
copy every 30 seconds and when the page is left, without counting as a
change: no sync, savegame or undo step of their own, and never over a save
made in another tab. Projects without them start from all zeros as before.
"Power off and on" in the menu on the circuit's name, or with Space,
starts the open circuit again from all zeros.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:09:18 +00:00
|
|
|
/** Bits the circuits held: only for circuits of the project, names and gates as text; broken entries are dropped. */
|
|
|
|
|
function stateOf(raw: unknown, components: ComponentDef[]): Record<string, HeldState> | null {
|
|
|
|
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null
|
|
|
|
|
const ids = new Set(components.map(d => d.id))
|
|
|
|
|
const out: Record<string, HeldState> = {}
|
|
|
|
|
for (const [id, s] of Object.entries(raw as Record<string, Partial<HeldState>>)) {
|
|
|
|
|
if (!ids.has(id) || !s || typeof s.on !== 'string' || !Array.isArray(s.names) || !s.names.every(n => typeof n === 'string')) continue
|
|
|
|
|
const clocks = Array.isArray(s.clocks) ? s.clocks.filter(k => typeof k === 'string') : []
|
|
|
|
|
if (!s.on && !clocks.length) continue
|
|
|
|
|
out[id] = { names: s.names, on: s.on, ...(clocks.length ? { clocks } : {}) }
|
|
|
|
|
}
|
BF memory: a newer save brings its own bits, bits reach the account when you leave, room for them
A project that comes in with the same circuit open (a newer save from
another computer, a savegame restored in place, a shared link opened
again) now runs from the bits it brings. Before, the running circuit
went on with this computer's old bits and wrote them over the newer ones
at the next save, and a savegame could not undo Power off and on.
Bits changed only by buttons or a clock are sent to the account when the
page is hidden or closed, when you leave the project, and before signing
out, so they are no longer lost by "remove from this browser" and reach
the other computer. A running clock alone still sends nothing. Bits alone
keep the project's save time, so an edit saved on another computer wins
over them and they end up in its savegames.
What circuits hold has its own room of 500 KB per project on top of the
2 MB limit, in the browser, the account and share links. When it is full,
the circuits left longest ago start from 0; a circuit that holds more than
that on its own says so once. A project can no longer become too large to
load because of its memory.
A savegame opened as a copy saves the project it leaves first, like every
other way of switching projects.
Tests now run the editor itself (in a stand-in browser with an account
server) for going into components and back, reloads, two projects, other
computers, savegames, signing out and the room limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:44:43 +00:00
|
|
|
const kept = trimState(out)
|
|
|
|
|
return Object.keys(kept).length ? kept : null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* What circuits hold, newest last, cut to LIMITS.state: the newest are kept,
|
|
|
|
|
* older ones that no longer fit are dropped (those circuits start from 0), so
|
|
|
|
|
* no amount of memory makes a project too large to load or save.
|
|
|
|
|
*/
|
|
|
|
|
export function trimState(state: Record<string, HeldState>): Record<string, HeldState> {
|
|
|
|
|
const ids = Object.keys(state)
|
|
|
|
|
const kept = new Set<string>()
|
|
|
|
|
let room = LIMITS.state
|
|
|
|
|
for (let i = ids.length - 1; i >= 0; i--) {
|
|
|
|
|
const id = ids[i]!
|
|
|
|
|
const size = id.length + JSON.stringify(state[id]).length + 4
|
|
|
|
|
if (size > room) continue
|
|
|
|
|
room -= size
|
|
|
|
|
kept.add(id)
|
|
|
|
|
}
|
|
|
|
|
return kept.size === ids.length ? state : Object.fromEntries(ids.filter(id => kept.has(id)).map(id => [id, state[id]!]))
|
A memory that stays: circuits keep their bits across visits and saves; Power off and on
What latches, flip-flops, registers and RAM built from NANDs hold is no
longer lost when you go into a component and come back, reload the page or
open the project on another computer. Leaving a circuit puts its bits in
the project, and opening it starts from them.
Only the gates on feedback loops can hold a bit, so only those that are 1
are kept, plus the clocks that are high: each node id once, each gate as
the path levels it shares with the gate before plus the rest. 1,024
flip-flops take about 30 KB. Restoring runs the gates in the order signals
flow, so the gates in front of a latch are right before it reads them;
gates that no longer exist after an edit are ignored.
The bits go with every save, file, share link and account upload. Between
saves (a clock running, a button pressed) they are put in this browser's
copy every 30 seconds and when the page is left, without counting as a
change: no sync, savegame or undo step of their own, and never over a save
made in another tab. Projects without them start from all zeros as before.
"Power off and on" in the menu on the circuit's name, or with Space,
starts the open circuit again from all zeros.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
2026-10-20 17:29:16 +00:00
|
|
|
/** Challenge records: challenge id → fewest transistors, whole non-negative numbers only. */
|
|
|
|
|
function bestOf(raw: unknown): Record<string, number> | null {
|
|
|
|
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null
|
|
|
|
|
const out: Record<string, number> = {}
|
|
|
|
|
for (const [k, v] of Object.entries(raw)) if (typeof v === 'number' && Number.isInteger(v) && v >= 0 && k.length <= 64) out[k] = v
|
|
|
|
|
return Object.keys(out).length ? out : null
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
/** Connector types of a project: names, colours and lines within bounds; broken ones are dropped. */
|
|
|
|
|
function connectorsOf(raw: unknown): ConnectorType[] | null {
|
|
|
|
|
if (!Array.isArray(raw)) return null
|
|
|
|
|
const out: ConnectorType[] = []
|
|
|
|
|
for (const c of raw.slice(0, 200) as Partial<ConnectorType>[]) {
|
|
|
|
|
if (!c || typeof c.id !== 'string' || !c.id || c.id.length > 32 || out.some(o => o.id === c.id) || !Array.isArray(c.lines)) continue
|
|
|
|
|
const lines = c.lines
|
|
|
|
|
.slice(0, 64)
|
|
|
|
|
.filter(l => l && typeof l.name === 'string')
|
|
|
|
|
.map(l => ({ name: l.name.trim().slice(0, 24) || 'line', ...(l.back === true ? { back: true } : {}) }))
|
|
|
|
|
out.push({
|
|
|
|
|
id: c.id,
|
|
|
|
|
name: typeof c.name === 'string' && c.name.trim() ? c.name.trim().slice(0, 40) : 'Connector',
|
|
|
|
|
...(c.color && WIRE_COLORS.includes(c.color) ? { color: c.color } : {}),
|
|
|
|
|
lines,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return out.length ? out : null
|
|
|
|
|
}
|
|
|
|
|
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
/** Puzzles kept in a project; broken ones are dropped. */
|
|
|
|
|
function puzzlesOf(raw: unknown): PuzzleSpec[] | null {
|
|
|
|
|
if (!Array.isArray(raw)) return null
|
|
|
|
|
const out: PuzzleSpec[] = []
|
|
|
|
|
for (const p of raw.slice(0, 200)) {
|
|
|
|
|
const id = (p as PuzzleSpec)?.id
|
|
|
|
|
if (typeof id !== 'string' || !/^(pz|week):[A-Za-z0-9-]{1,32}$/.test(id) || out.some(o => o.id === id)) continue
|
|
|
|
|
try {
|
|
|
|
|
out.push(cleanPuzzle(p, id))
|
|
|
|
|
} catch {}
|
|
|
|
|
}
|
|
|
|
|
return out.length ? out : null
|
|
|
|
|
}
|
|
|
|
|
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
export function parseProject(json: string): Project {
|
BF memory: a newer save brings its own bits, bits reach the account when you leave, room for them
A project that comes in with the same circuit open (a newer save from
another computer, a savegame restored in place, a shared link opened
again) now runs from the bits it brings. Before, the running circuit
went on with this computer's old bits and wrote them over the newer ones
at the next save, and a savegame could not undo Power off and on.
Bits changed only by buttons or a clock are sent to the account when the
page is hidden or closed, when you leave the project, and before signing
out, so they are no longer lost by "remove from this browser" and reach
the other computer. A running clock alone still sends nothing. Bits alone
keep the project's save time, so an edit saved on another computer wins
over them and they end up in its savegames.
What circuits hold has its own room of 500 KB per project on top of the
2 MB limit, in the browser, the account and share links. When it is full,
the circuits left longest ago start from 0; a circuit that holds more than
that on its own says so once. A project can no longer become too large to
load because of its memory.
A savegame opened as a copy saves the project it leaves first, like every
other way of switching projects.
Tests now run the editor itself (in a stand-in browser with an account
server) for going into components and back, reloads, two projects, other
computers, savegames, signing out and the room limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:44:43 +00:00
|
|
|
if (json.length > LIMITS.bytes + LIMITS.state) throw new Error('File too large')
|
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/<id> 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) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
let data: unknown
|
|
|
|
|
try {
|
|
|
|
|
data = JSON.parse(json)
|
|
|
|
|
} catch {
|
|
|
|
|
throw new Error('Not a valid JSON file')
|
|
|
|
|
}
|
|
|
|
|
return toProject(data)
|
|
|
|
|
}
|