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
|
|
|
// Editor state: the project library, the open project, selection, undo
|
|
|
|
|
// history, share links and the running simulation of the open circuit.
|
|
|
|
|
// One shared instance for the whole page.
|
2026-10-17 10:49:38 +00:00
|
|
|
|
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
|
|
|
import { runSteps, stats, tableCsv, truthTable, type Stats, type TestResult, type TruthTable } from '~/lib/logic/analyze'
|
2026-10-17 10:49:38 +00:00
|
|
|
import { CHALLENGES, challengeSteps, type Challenge } from '~/lib/logic/challenges'
|
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
|
|
|
import { compile, rowSource } from '~/lib/logic/compile'
|
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
|
|
|
import { shapeOf, type Pt } from '~/lib/logic/geometry'
|
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
|
|
|
import { adoptName, continueSeries, newPinLabel } from '~/lib/logic/labels'
|
|
|
|
|
import { attachPanel, detachPanel, dockedPanels, newPanelRows, removeRow, syncPanels } from '~/lib/logic/panels'
|
2026-10-17 10:49:38 +00:00
|
|
|
import {
|
|
|
|
|
addExamples,
|
|
|
|
|
containsDef,
|
|
|
|
|
copySelection,
|
|
|
|
|
createProject,
|
|
|
|
|
deleteComponent,
|
|
|
|
|
duplicateComponent,
|
|
|
|
|
lookup,
|
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
|
|
|
makeUnique,
|
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
|
|
|
mergeComponents,
|
2026-10-17 10:49:38 +00:00
|
|
|
newComponent,
|
|
|
|
|
packageSelection,
|
|
|
|
|
pasteClip,
|
|
|
|
|
pruneWires,
|
|
|
|
|
startChallenge,
|
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
|
|
|
swapNode,
|
2026-10-17 10:49:38 +00:00
|
|
|
uid,
|
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
|
|
|
unlinkWires,
|
|
|
|
|
unpackChip,
|
2026-10-17 10:49:38 +00:00
|
|
|
type Clip,
|
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
|
|
|
type SwapTarget,
|
2026-10-17 10:49:38 +00:00
|
|
|
} from '~/lib/logic/ops'
|
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
|
|
|
import { parseProject, toProject } from '~/lib/logic/project'
|
2026-10-17 10:49:38 +00:00
|
|
|
import { Simulator } from '~/lib/logic/sim'
|
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
|
|
|
import {
|
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
|
|
|
cachedAccount,
|
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
|
|
|
currentId,
|
|
|
|
|
listProjects,
|
|
|
|
|
loadProject,
|
|
|
|
|
migrateLegacy,
|
|
|
|
|
newLocalId,
|
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
|
|
|
pendingDeletes,
|
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
|
|
|
removeProject,
|
|
|
|
|
saveMeta,
|
|
|
|
|
saveProject,
|
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
|
|
|
setCachedAccount,
|
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
|
|
|
setCurrentId,
|
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
|
|
|
setPendingDeletes,
|
|
|
|
|
type AccountUser,
|
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
|
|
|
type ProjectMeta,
|
|
|
|
|
} from '~/lib/logic/storage'
|
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
|
|
|
import type { CircuitNode, NodeKind, PanelControl, PanelRow, PinRef, Project, WireColor } from '~/lib/logic/types'
|
|
|
|
|
|
|
|
|
|
/** One pin waiting to be wired in "connect one by one". */
|
|
|
|
|
export interface LinkEnd {
|
|
|
|
|
node: string
|
|
|
|
|
pin: string
|
|
|
|
|
dir: 'in' | 'out'
|
|
|
|
|
label: string
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
export interface Placing {
|
|
|
|
|
kind: NodeKind
|
|
|
|
|
chip?: string
|
|
|
|
|
keep?: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface View {
|
|
|
|
|
x: number
|
|
|
|
|
y: number
|
|
|
|
|
zoom: number
|
|
|
|
|
}
|
|
|
|
|
|
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 type LinkState = 'none' | 'viewer' | 'dirty' | 'saving' | 'saved' | 'error'
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
const BUDGET = 300_000
|
|
|
|
|
|
|
|
|
|
function create() {
|
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
|
|
|
// ── Library ───────────────────────────────────────────────────────
|
|
|
|
|
migrateLegacy()
|
|
|
|
|
const projects = ref<ProjectMeta[]>(listProjects())
|
|
|
|
|
|
|
|
|
|
function initial(): { meta: ProjectMeta; project: Project } {
|
|
|
|
|
const list = listProjects()
|
|
|
|
|
const id = currentId()
|
|
|
|
|
for (const m of [list.find(m => m.id === id), ...list]) {
|
|
|
|
|
if (!m) continue
|
|
|
|
|
const p = loadProject(m.id)
|
|
|
|
|
if (p) return { meta: m, project: p }
|
|
|
|
|
}
|
|
|
|
|
const project = createProject({ examples: 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
|
|
|
const meta: ProjectMeta = { id: newLocalId(), name: project.name, updated: Date.now(), starter: 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 first visit through a share link should not leave an unused starter
|
|
|
|
|
// project behind; it is saved only once something changes in it.
|
|
|
|
|
placeholder = location.pathname.startsWith('/p/')
|
|
|
|
|
if (!placeholder) saveProject(meta, project)
|
|
|
|
|
return { meta, project }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let placeholder = false
|
|
|
|
|
|
|
|
|
|
const start = initial()
|
|
|
|
|
const meta = ref<ProjectMeta>(start.meta)
|
|
|
|
|
const project = ref<Project>(start.project)
|
|
|
|
|
setCurrentId(start.meta.id)
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
const getDef = computed(() => lookup(project.value))
|
|
|
|
|
const def = computed(() => getDef.value(project.value.openId) ?? project.value.components[0]!)
|
|
|
|
|
|
|
|
|
|
const selection = ref<string[]>([])
|
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
|
|
|
const wireSel = ref<string[]>([])
|
2026-10-17 10:49:38 +00:00
|
|
|
const placing = ref<Placing | null>(null)
|
|
|
|
|
const nav = ref<string[]>([])
|
|
|
|
|
const views = reactive<Record<string, View>>({})
|
|
|
|
|
const notice = ref<{ text: string; kind: 'ok' | 'error' } | null>(null)
|
|
|
|
|
const labelFocus = ref(0)
|
|
|
|
|
const showHelp = ref(false)
|
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 dialog = ref<null | 'projects' | 'share' | 'account' | 'versions' | 'table'>(null)
|
|
|
|
|
/** Pins being wired one after another; `at` is the one the next click connects. */
|
|
|
|
|
const linking = ref<{ queue: LinkEnd[]; at: number } | null>(null)
|
2026-10-20 11:20:55 +00:00
|
|
|
/** Project whose savegames the versions dialog shows. */
|
|
|
|
|
const versionsFor = ref<string | null>(null)
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
let noticeTimer: ReturnType<typeof setTimeout> | undefined
|
|
|
|
|
function notify(text: string, kind: 'ok' | 'error' = 'ok') {
|
|
|
|
|
notice.value = { text, kind }
|
|
|
|
|
clearTimeout(noticeTimer)
|
|
|
|
|
noticeTimer = setTimeout(() => (notice.value = null), 3500)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
function clearSelection() {
|
|
|
|
|
selection.value = []
|
|
|
|
|
wireSel.value = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Saving ────────────────────────────────────────────────────────
|
|
|
|
|
let saveTimer: ReturnType<typeof setTimeout> | undefined
|
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
|
|
|
let changed = false
|
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
|
|
|
function persistNow() {
|
|
|
|
|
clearTimeout(saveTimer)
|
|
|
|
|
saveTimer = undefined
|
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
|
|
|
meta.value = { ...meta.value, name: project.value.name, updated: Date.now(), ...(changed ? { dirty: true, starter: undefined } : {}) }
|
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 (!saveProject(toRaw(meta.value), toRaw(project.value))) notify('Browser storage is full. Export your project to keep it.', 'error')
|
|
|
|
|
projects.value = listProjects()
|
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
|
|
|
if (changed) scheduleCloud()
|
|
|
|
|
changed = false
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function persist() {
|
|
|
|
|
placeholder = false
|
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
|
|
|
changed = 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
|
|
|
clearTimeout(saveTimer)
|
|
|
|
|
saveTimer = setTimeout(persistNow, 300)
|
|
|
|
|
scheduleSync()
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
// ── History ───────────────────────────────────────────────────────
|
|
|
|
|
const snap = () => JSON.stringify({ components: project.value.components, solved: project.value.solved })
|
|
|
|
|
let last = snap()
|
|
|
|
|
const undoStack: string[] = []
|
|
|
|
|
const redoStack: string[] = []
|
|
|
|
|
const canUndo = ref(false)
|
|
|
|
|
const canRedo = ref(false)
|
|
|
|
|
|
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
|
|
|
function resetHistory() {
|
|
|
|
|
undoStack.length = 0
|
|
|
|
|
redoStack.length = 0
|
|
|
|
|
last = snap()
|
|
|
|
|
canUndo.value = false
|
|
|
|
|
canRedo.value = false
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Record a change. Structural changes (parts, wires) rebuild the simulation. */
|
|
|
|
|
function commit(structural = true) {
|
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 (structural) {
|
|
|
|
|
syncPanels(project.value)
|
|
|
|
|
pruneWires(project.value)
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
const s = snap()
|
|
|
|
|
if (s === last) return
|
|
|
|
|
undoStack.push(last)
|
|
|
|
|
if (undoStack.length > 200) undoStack.shift()
|
|
|
|
|
redoStack.length = 0
|
|
|
|
|
last = s
|
|
|
|
|
canUndo.value = true
|
|
|
|
|
canRedo.value = false
|
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
|
|
|
forkIfViewer()
|
2026-10-17 10:49:38 +00:00
|
|
|
persist()
|
|
|
|
|
if (structural) scheduleRebuild()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function restore(s: string) {
|
|
|
|
|
const data = JSON.parse(s) as Pick<Project, 'components' | 'solved'>
|
|
|
|
|
project.value.components = data.components
|
|
|
|
|
project.value.solved = data.solved
|
|
|
|
|
if (!project.value.components.some(d => d.id === project.value.openId)) project.value.openId = project.value.components[0]!.id
|
|
|
|
|
last = s
|
|
|
|
|
selection.value = selection.value.filter(id => def.value.nodes.some(n => n.id === id))
|
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
|
|
|
wireSel.value = wireSel.value.filter(id => def.value.wires.some(w => w.id === id))
|
2026-10-17 10:49:38 +00:00
|
|
|
canUndo.value = undoStack.length > 0
|
|
|
|
|
canRedo.value = redoStack.length > 0
|
|
|
|
|
persist()
|
|
|
|
|
scheduleRebuild()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function undo() {
|
|
|
|
|
const s = undoStack.pop()
|
|
|
|
|
if (s === undefined) return
|
|
|
|
|
redoStack.push(last)
|
|
|
|
|
restore(s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function redo() {
|
|
|
|
|
const s = redoStack.pop()
|
|
|
|
|
if (s === undefined) return
|
|
|
|
|
undoStack.push(last)
|
|
|
|
|
restore(s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Simulation ────────────────────────────────────────────────────
|
|
|
|
|
const sim = shallowRef<Simulator | null>(null)
|
|
|
|
|
let simRoot = ''
|
|
|
|
|
const tick = ref(0)
|
|
|
|
|
const status = ref<'stable' | 'busy' | 'oscillating'>('stable')
|
|
|
|
|
const running = ref(true)
|
|
|
|
|
const hz = ref(2)
|
|
|
|
|
const cycles = ref(0)
|
|
|
|
|
const errors = ref<string[]>([])
|
|
|
|
|
const circuitStats = ref<Stats>({ nands: 0, sequential: false, delay: 0 })
|
|
|
|
|
const pressed = new Set<string>()
|
|
|
|
|
|
|
|
|
|
function rebuild() {
|
|
|
|
|
const d = def.value
|
|
|
|
|
const nl = compile(getDef.value, d.id)
|
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
|
|
|
const key = `${meta.value.id}/${d.id}`
|
|
|
|
|
const carry = sim.value && simRoot === key ? sim.value.carry() : undefined
|
2026-10-17 10:49:38 +00:00
|
|
|
const s = new Simulator(nl, carry)
|
|
|
|
|
for (const n of d.nodes) {
|
|
|
|
|
if (n.kind === 'input') s.setSource(n.id, !!n.on)
|
|
|
|
|
else if (n.kind === 'button') s.setSource(n.id, pressed.has(n.id))
|
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
|
|
|
else if (n.kind === 'panel') {
|
|
|
|
|
for (const r of n.rows ?? []) {
|
|
|
|
|
const key = rowSource(n.id, r.id)
|
|
|
|
|
if (r.type === 'switch') s.setSource(key, !!r.on)
|
|
|
|
|
else if (r.type === 'button') s.setSource(key, pressed.has(key))
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
s.run(BUDGET)
|
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 (simRoot !== key) cycles.value = 0
|
2026-10-17 10:49:38 +00:00
|
|
|
sim.value = s
|
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
|
|
|
simRoot = key
|
2026-10-17 10:49:38 +00:00
|
|
|
errors.value = nl.errors
|
|
|
|
|
circuitStats.value = stats(nl)
|
|
|
|
|
tick.value++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rebuildQueued = false
|
|
|
|
|
function scheduleRebuild() {
|
|
|
|
|
if (rebuildQueued) return
|
|
|
|
|
rebuildQueued = true
|
|
|
|
|
queueMicrotask(() => {
|
|
|
|
|
rebuildQueued = false
|
|
|
|
|
rebuild()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Value at a pin of the open circuit. Reactive through `tick`. */
|
|
|
|
|
function val(nodeId: string, pin: string): number {
|
|
|
|
|
void tick.value
|
|
|
|
|
return sim.value?.pin(nodeId, pin) ?? 0
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** Value at a lamp or display inside a chip of the open circuit. */
|
|
|
|
|
function faceVal(chipNode: string, inner: string, pin: string): number {
|
|
|
|
|
void tick.value
|
|
|
|
|
return sim.value?.face(chipNode, inner, pin) ?? 0
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
let raf = 0
|
|
|
|
|
function startLoop() {
|
|
|
|
|
let lastT = performance.now()
|
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
|
|
|
let acc: number[] = []
|
2026-10-17 10:49:38 +00:00
|
|
|
let unsettled = 0
|
|
|
|
|
let lastChanges = -1
|
|
|
|
|
const frame = (t: number) => {
|
|
|
|
|
const dt = Math.min(100, t - lastT)
|
|
|
|
|
lastT = t
|
|
|
|
|
const s = sim.value
|
|
|
|
|
if (s) {
|
|
|
|
|
let rises = 0
|
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
|
|
|
const n = s.nl.clocks.length
|
|
|
|
|
if (running.value && n) {
|
|
|
|
|
if (acc.length !== n) acc = new Array(n).fill(0)
|
|
|
|
|
// Ticks count the first clock that follows the top-bar speed (or the first clock).
|
|
|
|
|
const counted = Math.max(0, s.nl.clockHz.indexOf(0))
|
|
|
|
|
const fastest: number[] = []
|
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
|
const f = s.nl.clockHz[i] || hz.value
|
|
|
|
|
if (f <= 0) {
|
|
|
|
|
fastest.push(i)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
acc[i]! += dt
|
|
|
|
|
const half = 500 / f
|
|
|
|
|
for (let k = 0; acc[i]! >= half && k < 16; k++) {
|
|
|
|
|
acc[i]! -= half
|
2026-10-17 10:49:38 +00:00
|
|
|
s.run(BUDGET)
|
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
|
|
|
if (s.toggleClock(i) && i === counted) rises++
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
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
|
|
|
if (acc[i]! > half) acc[i] = 0
|
|
|
|
|
}
|
|
|
|
|
if (fastest.length) {
|
2026-10-17 10:49:38 +00:00
|
|
|
const end = performance.now() + 10
|
|
|
|
|
while (performance.now() < end) {
|
|
|
|
|
if (!s.run(BUDGET)) break
|
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 i of fastest) if (s.toggleClock(i) && i === counted) rises++
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rises) cycles.value += rises
|
|
|
|
|
const settled = s.run(BUDGET)
|
|
|
|
|
unsettled = settled ? 0 : unsettled + 1
|
|
|
|
|
status.value = settled ? 'stable' : unsettled > 30 ? 'oscillating' : 'busy'
|
|
|
|
|
if (s.changes !== lastChanges) {
|
|
|
|
|
lastChanges = s.changes
|
|
|
|
|
tick.value++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
raf = requestAnimationFrame(frame)
|
|
|
|
|
}
|
|
|
|
|
raf = requestAnimationFrame(frame)
|
|
|
|
|
return () => cancelAnimationFrame(raf)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** One full clock cycle (rise and fall), each half settled. */
|
|
|
|
|
function step() {
|
|
|
|
|
const s = sim.value
|
|
|
|
|
if (!s) return
|
|
|
|
|
s.run(BUDGET)
|
|
|
|
|
if (s.clock) {
|
|
|
|
|
s.setClock(0)
|
|
|
|
|
s.run(BUDGET)
|
|
|
|
|
}
|
|
|
|
|
s.setClock(1)
|
|
|
|
|
s.run(BUDGET)
|
|
|
|
|
cycles.value++
|
|
|
|
|
s.setClock(0)
|
|
|
|
|
s.run(BUDGET)
|
|
|
|
|
tick.value++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Navigation ────────────────────────────────────────────────────
|
|
|
|
|
function open(id: string, push = true) {
|
|
|
|
|
if (id === def.value.id || !getDef.value(id)) return
|
|
|
|
|
if (push) nav.value.push(def.value.id)
|
|
|
|
|
project.value.openId = id
|
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
|
|
|
clearSelection()
|
2026-10-17 10:49:38 +00:00
|
|
|
placing.value = null
|
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
|
|
|
linking.value = null
|
2026-10-17 10:49:38 +00:00
|
|
|
persist()
|
|
|
|
|
rebuild()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function back() {
|
|
|
|
|
const id = nav.value.pop()
|
|
|
|
|
if (id) open(id, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Editing ───────────────────────────────────────────────────────
|
|
|
|
|
function addNode(p: Placing, x: number, y: number): CircuitNode {
|
|
|
|
|
const node: CircuitNode = { id: uid('n'), kind: p.kind, x, y }
|
|
|
|
|
if (p.chip) node.chip = p.chip
|
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 (p.kind === 'input' || p.kind === 'output') {
|
|
|
|
|
node.label = newPinLabel(def.value, p.kind)
|
|
|
|
|
node.autoLabel = true
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
if (p.kind === 'note') node.label = 'Note'
|
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 (p.kind === 'panel') node.rows = newPanelRows()
|
2026-10-17 10:49:38 +00:00
|
|
|
def.value.nodes.push(node)
|
|
|
|
|
selection.value = [node.id]
|
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
|
|
|
wireSel.value = []
|
2026-10-17 10:49:38 +00:00
|
|
|
commit()
|
|
|
|
|
return node
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function canPlace(chipId: string) {
|
|
|
|
|
return !containsDef(project.value, chipId, def.value.id)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
function connect(from: PinRef, to: PinRef, pts?: Pt[]) {
|
2026-10-17 10:49:38 +00:00
|
|
|
const d = def.value
|
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
|
|
|
const old = d.wires.find(w => w.to.node === to.node && w.to.pin === to.pin)
|
|
|
|
|
d.wires = d.wires.filter(w => w !== old)
|
|
|
|
|
const wire: (typeof d.wires)[number] = { id: uid('w'), from, to }
|
|
|
|
|
if (pts?.length) wire.pts = pts
|
|
|
|
|
const sameNet = d.wires.find(w => w.from.node === from.node && w.from.pin === from.pin && w.color)
|
|
|
|
|
if (sameNet?.color) wire.color = sameNet.color
|
|
|
|
|
d.wires.push(wire)
|
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
|
|
|
// An unnamed switch, lamp or pin takes the name of the component pin it now connects to.
|
|
|
|
|
const fn = d.nodes.find(n => n.id === from.node)
|
|
|
|
|
const tn = d.nodes.find(n => n.id === to.node)
|
|
|
|
|
if (fn && tn) {
|
|
|
|
|
adoptName(d, fn, from.pin, tn, to.pin, getDef.value)
|
|
|
|
|
adoptName(d, tn, to.pin, fn, from.pin, getDef.value)
|
|
|
|
|
}
|
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
|
|
|
wireSel.value = []
|
2026-10-17 10:49:38 +00:00
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** Parts plus the panels docked to them: they move, copy and delete together. */
|
|
|
|
|
function withDocked(ids: Iterable<string>): Set<string> {
|
|
|
|
|
const set = new Set(ids)
|
|
|
|
|
for (const p of dockedPanels(def.value, set)) set.add(p.id)
|
|
|
|
|
return set
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
function deleteSelected() {
|
|
|
|
|
const d = def.value
|
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 (!selection.value.length && !wireSel.value.length) return
|
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 ids = withDocked(selection.value)
|
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
|
|
|
const wires = new Set(wireSel.value)
|
|
|
|
|
d.nodes = d.nodes.filter(n => !ids.has(n.id))
|
|
|
|
|
d.wires = d.wires.filter(w => !ids.has(w.from.node) && !ids.has(w.to.node) && !wires.has(w.id))
|
|
|
|
|
clearSelection()
|
|
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const selectedWires = computed(() => {
|
|
|
|
|
const ids = new Set(wireSel.value)
|
|
|
|
|
return def.value.wires.filter(w => ids.has(w.id))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function setWireColor(color: WireColor | undefined) {
|
|
|
|
|
for (const w of selectedWires.value) {
|
|
|
|
|
if (color) w.color = color
|
|
|
|
|
else delete w.color
|
2026-10-17 10:49:38 +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
|
|
|
commit(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function autoRoute() {
|
|
|
|
|
for (const w of selectedWires.value) delete w.pts
|
|
|
|
|
commit(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Select every wire that carries the same signal (same source pin). */
|
|
|
|
|
function selectNet(wireId: string) {
|
|
|
|
|
const w = def.value.wires.find(x => x.id === wireId)
|
|
|
|
|
if (!w) return
|
|
|
|
|
wireSel.value = def.value.wires.filter(x => x.from.node === w.from.node && x.from.pin === w.from.pin).map(x => x.id)
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
function swap(nodeId: string, target: SwapTarget) {
|
|
|
|
|
const removed = swapNode(project.value, def.value, nodeId, target)
|
|
|
|
|
commit()
|
|
|
|
|
if (removed) notify(`Swapped. ${removed} wire${removed === 1 ? '' : 's'} had no matching pin and were removed.`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unlink(ids: string[]) {
|
|
|
|
|
const n = unlinkWires(def.value, new Set(ids))
|
|
|
|
|
commit()
|
|
|
|
|
notify(n ? `Removed ${n} wire${n === 1 ? '' : 's'}` : 'Nothing was connected')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unpack(nodeId: string) {
|
|
|
|
|
const res = unpackChip(project.value, def.value.id, nodeId)
|
|
|
|
|
if (!res.ok) return notify(res.error, 'error')
|
|
|
|
|
selection.value = res.nodes
|
|
|
|
|
wireSel.value = []
|
|
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeIndependent(nodeId: string) {
|
|
|
|
|
const copy = makeUnique(project.value, def.value, nodeId)
|
|
|
|
|
if (!copy) return
|
|
|
|
|
commit()
|
|
|
|
|
notify(`This one now uses its own copy, "${copy.name}"`)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
function toggleInput(node: CircuitNode) {
|
|
|
|
|
node.on = !node.on
|
|
|
|
|
sim.value?.setSource(node.id, node.on)
|
|
|
|
|
persist()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function press(node: CircuitNode, down: boolean) {
|
|
|
|
|
if (down) pressed.add(node.id)
|
|
|
|
|
else pressed.delete(node.id)
|
|
|
|
|
sim.value?.setSource(node.id, down)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** Click on a panel row: flips a switch row. */
|
|
|
|
|
function toggleRow(node: CircuitNode, row: PanelRow) {
|
|
|
|
|
if (row.type !== 'switch') return
|
|
|
|
|
row.on = !row.on
|
|
|
|
|
sim.value?.setSource(rowSource(node.id, row.id), row.on)
|
|
|
|
|
persist()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pressRow(node: CircuitNode, row: PanelRow, down: boolean) {
|
|
|
|
|
if (row.type !== 'button') return
|
|
|
|
|
const key = rowSource(node.id, row.id)
|
|
|
|
|
if (down) pressed.add(key)
|
|
|
|
|
else pressed.delete(key)
|
|
|
|
|
sim.value?.setSource(key, down)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Panels ────────────────────────────────────────────────────────
|
|
|
|
|
function addPanel(chipId: string) {
|
|
|
|
|
const panel = attachPanel(project.value, def.value, chipId)
|
|
|
|
|
if (!panel) return notify('Every input of this component is already connected', 'error')
|
|
|
|
|
selection.value = [panel.id]
|
|
|
|
|
wireSel.value = []
|
|
|
|
|
commit()
|
|
|
|
|
notify(`Input panel with ${panel.rows!.length} switch${panel.rows!.length === 1 ? '' : 'es'} attached`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function undock(panel: CircuitNode) {
|
|
|
|
|
detachPanel(panel)
|
|
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setRowType(row: PanelRow, type: PanelControl) {
|
|
|
|
|
row.type = type
|
|
|
|
|
if (type !== 'switch') delete row.on
|
|
|
|
|
if (type !== 'clock') delete row.hz
|
|
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addRow(panel: CircuitNode) {
|
|
|
|
|
panel.rows = [...(panel.rows ?? []), ...newPanelRows(1)]
|
|
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dropRow(panel: CircuitNode, rowId: string) {
|
|
|
|
|
removeRow(def.value, panel, rowId)
|
|
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
let clip: Clip | null = null
|
|
|
|
|
let pasteCount = 0
|
|
|
|
|
function copy() {
|
|
|
|
|
if (!selection.value.length) return
|
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
|
|
|
clip = copySelection(def.value, withDocked(selection.value))
|
2026-10-17 10:49:38 +00:00
|
|
|
pasteCount = 0
|
|
|
|
|
notify(`Copied ${clip.nodes.length} part${clip.nodes.length === 1 ? '' : 's'}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function paste() {
|
|
|
|
|
if (!clip) return
|
|
|
|
|
pasteCount++
|
|
|
|
|
const blocked = clip.nodes.filter(n => n.kind === 'chip' && n.chip && !canPlace(n.chip))
|
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
|
|
|
const usable: Clip = blocked.length ? { nodes: clip.nodes.filter(n => !blocked.includes(n)), wires: clip.wires } : clip
|
2026-10-17 10:49:38 +00:00
|
|
|
if (blocked.length) notify('Skipped parts that would contain this circuit itself', 'error')
|
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 ids = pasteClip(def.value, usable, 2 * pasteCount, 2 * pasteCount)
|
|
|
|
|
const fresh = new Set(ids)
|
|
|
|
|
continueSeries(def.value, def.value.nodes.filter(n => fresh.has(n.id)))
|
|
|
|
|
selection.value = ids
|
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
|
|
|
wireSel.value = []
|
2026-10-17 10:49:38 +00:00
|
|
|
commit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function duplicate() {
|
|
|
|
|
copy()
|
|
|
|
|
paste()
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// ── Connect one by one ────────────────────────────────────────────
|
|
|
|
|
/**
|
|
|
|
|
* Pins of the given parts, top to bottom, ready to be wired one after the
|
|
|
|
|
* other: their outputs, or their inputs when asked for (or when they have
|
|
|
|
|
* no outputs, like lamps).
|
|
|
|
|
*/
|
|
|
|
|
function linkQueue(ids: string[], want?: 'in' | 'out'): LinkEnd[] {
|
|
|
|
|
const nodes = def.value.nodes.filter(n => ids.includes(n.id) && n.kind !== 'note').sort((a, b) => a.y - b.y || a.x - b.x)
|
|
|
|
|
const shapes = nodes.map(n => ({ n, s: shapeOf(n, getDef.value) }))
|
|
|
|
|
const dir = want ?? (shapes.some(({ s }) => s.outputs.length) ? 'out' : 'in')
|
|
|
|
|
const queue: LinkEnd[] = []
|
|
|
|
|
for (const { n, s } of shapes) {
|
|
|
|
|
for (const p of dir === 'out' ? s.outputs : s.inputs) {
|
|
|
|
|
const label = p.label || n.label?.trim() || ''
|
|
|
|
|
queue.push({ node: n.id, pin: p.key, dir, label })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return queue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startLinking(ids = selection.value, want?: 'in' | 'out') {
|
|
|
|
|
const queue = linkQueue(ids, want)
|
|
|
|
|
if (!queue.length) return notify('Nothing to connect: select parts with pins', 'error')
|
|
|
|
|
placing.value = null
|
|
|
|
|
linking.value = null
|
|
|
|
|
linking.value = { queue, at: 0 }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Wires the pin whose turn it is to `target`, then moves on to the next one. */
|
|
|
|
|
function linkTo(target: PinRef) {
|
|
|
|
|
const l = linking.value
|
|
|
|
|
const cur = l?.queue[l.at]
|
|
|
|
|
if (!l || !cur) return
|
|
|
|
|
const here = { node: cur.node, pin: cur.pin }
|
|
|
|
|
if (cur.dir === 'out') connect(here, target)
|
|
|
|
|
else connect(target, here)
|
|
|
|
|
l.at++
|
|
|
|
|
if (l.at >= l.queue.length) {
|
|
|
|
|
linking.value = null
|
|
|
|
|
if (l.queue.length > 1) notify(`Connected ${l.queue.length} pins`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function stopLinking() {
|
|
|
|
|
linking.value = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Tidy wiring ───────────────────────────────────────────────────
|
|
|
|
|
function setTidy(on: boolean) {
|
|
|
|
|
if (on) project.value.settings.tidy = true
|
|
|
|
|
else delete project.value.settings.tidy
|
|
|
|
|
persist()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Removes all hand-placed bends in the open circuit and lays every wire out tidily. */
|
|
|
|
|
function tidyAll() {
|
|
|
|
|
const bent = def.value.wires.filter(w => w.pts).length
|
|
|
|
|
for (const w of def.value.wires) delete w.pts
|
|
|
|
|
project.value.settings.tidy = true
|
|
|
|
|
commit(false)
|
|
|
|
|
persist()
|
|
|
|
|
notify(bent ? `Tidied. ${bent} hand-placed bend${bent === 1 ? ' was' : 's were'} removed (Ctrl+Z brings ${bent === 1 ? 'it' : 'them'} back)` : 'Tidy wiring is on')
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
function selectAll() {
|
|
|
|
|
selection.value = def.value.nodes.map(n => n.id)
|
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
|
|
|
wireSel.value = def.value.wires.map(w => w.id)
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function packageSelected(name: string) {
|
|
|
|
|
const res = packageSelection(project.value, def.value.id, new Set(selection.value), name)
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
notify(res.error, 'error')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
selection.value = [res.chipNode]
|
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
|
|
|
wireSel.value = []
|
2026-10-17 10:49:38 +00:00
|
|
|
commit()
|
|
|
|
|
notify(`Created component "${res.def.name}"`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Components ────────────────────────────────────────────────────
|
|
|
|
|
function createComponent(name = 'New part') {
|
|
|
|
|
const d = newComponent(project.value, name)
|
|
|
|
|
commit()
|
|
|
|
|
open(d.id)
|
|
|
|
|
labelFocus.value++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeComponent(id: string) {
|
|
|
|
|
const err = deleteComponent(project.value, id)
|
|
|
|
|
if (err) return notify(err, 'error')
|
|
|
|
|
nav.value = nav.value.filter(n => n !== id)
|
|
|
|
|
commit()
|
|
|
|
|
rebuild()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function copyComponent(id: string) {
|
|
|
|
|
const d = duplicateComponent(project.value, id)
|
|
|
|
|
if (!d) return
|
|
|
|
|
commit()
|
|
|
|
|
open(d.id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function beginChallenge(c: Challenge) {
|
|
|
|
|
const existing = project.value.components.find(d => d.challenge === c.id)
|
|
|
|
|
if (existing) return open(existing.id)
|
|
|
|
|
const d = startChallenge(project.value, c)
|
|
|
|
|
commit()
|
|
|
|
|
open(d.id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkChallenge(): TestResult | null {
|
|
|
|
|
const c = CHALLENGES.find(c => c.id === def.value.challenge)
|
|
|
|
|
if (!c) return null
|
|
|
|
|
const res = runSteps(getDef.value, def.value.id, challengeSteps(c))
|
|
|
|
|
if (res.pass && !project.value.solved.includes(c.id)) {
|
|
|
|
|
project.value.solved.push(c.id)
|
|
|
|
|
commit(false)
|
|
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function table(): TruthTable | { error: string } {
|
|
|
|
|
return truthTable(getDef.value, def.value.id)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// ── Projects ──────────────────────────────────────────────────────
|
|
|
|
|
function activate(m: ProjectMeta, p: Project) {
|
|
|
|
|
meta.value = m
|
2026-10-17 10:49:38 +00:00
|
|
|
project.value = p
|
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
|
|
|
setCurrentId(m.id)
|
|
|
|
|
resetHistory()
|
2026-10-17 10:49:38 +00:00
|
|
|
nav.value = []
|
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
|
|
|
clearSelection()
|
|
|
|
|
placing.value = null
|
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
|
|
|
linking.value = 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
|
|
|
for (const k of Object.keys(views)) delete views[k]
|
|
|
|
|
linkState.value = m.link ? (m.link.key ? 'saved' : 'viewer') : 'none'
|
|
|
|
|
projects.value = listProjects()
|
|
|
|
|
syncUrl()
|
2026-10-17 10:49:38 +00:00
|
|
|
rebuild()
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
function switchProject(id: string) {
|
|
|
|
|
if (id === meta.value.id) return
|
|
|
|
|
persistNow()
|
|
|
|
|
const p = loadProject(id)
|
|
|
|
|
const m = listProjects().find(x => x.id === id)
|
|
|
|
|
if (!p || !m) return notify('Could not open that project', 'error')
|
|
|
|
|
activate(m, p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addProject(p: Project, link?: ProjectMeta['link']): ProjectMeta {
|
|
|
|
|
const m: ProjectMeta = { id: newLocalId(), name: p.name, updated: Date.now() }
|
|
|
|
|
if (link) m.link = link
|
|
|
|
|
saveProject(m, p)
|
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
|
|
|
scheduleCloud()
|
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
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
function newProject(examples: boolean) {
|
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
|
|
|
persistNow()
|
|
|
|
|
const p = createProject({ examples })
|
|
|
|
|
activate(addProject(p), p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function duplicateProject(id: string) {
|
|
|
|
|
persistNow()
|
|
|
|
|
const p = loadProject(id)
|
|
|
|
|
if (!p) return
|
|
|
|
|
p.name = `${p.name} copy`
|
|
|
|
|
activate(addProject(p), p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteProject(id: string) {
|
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
|
|
|
const gone = listProjects().find(m => m.id === id)
|
|
|
|
|
if (gone?.cloud) {
|
|
|
|
|
setPendingDeletes([...pendingDeletes(), { owner: gone.cloud.owner, id }])
|
|
|
|
|
scheduleCloud()
|
|
|
|
|
}
|
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
|
|
|
removeProject(id)
|
|
|
|
|
projects.value = listProjects()
|
|
|
|
|
if (id !== meta.value.id) return
|
|
|
|
|
const next = projects.value[0]
|
|
|
|
|
const p = next && loadProject(next.id)
|
|
|
|
|
if (next && p) activate(next, p)
|
|
|
|
|
else {
|
|
|
|
|
const fresh = createProject({ examples: true })
|
|
|
|
|
activate(addProject(fresh), fresh)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renameProject(id: string, name: string) {
|
|
|
|
|
const clean = name.trim().slice(0, 80) || 'Untitled'
|
|
|
|
|
if (id === meta.value.id) {
|
|
|
|
|
project.value.name = clean
|
|
|
|
|
persist()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const p = loadProject(id)
|
|
|
|
|
const m = listProjects().find(x => x.id === id)
|
|
|
|
|
if (!p || !m) return
|
|
|
|
|
p.name = clean
|
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
|
|
|
saveProject({ ...m, name: clean, dirty: true }, p)
|
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
|
|
|
projects.value = listProjects()
|
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
|
|
|
scheduleCloud()
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadExamples() {
|
|
|
|
|
const n = addExamples(project.value)
|
|
|
|
|
commit()
|
|
|
|
|
notify(n ? `Added ${n} example parts` : 'All examples are already here')
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
function download(name: string, text: string, type = 'application/json') {
|
|
|
|
|
const blob = new Blob([text], { type })
|
2026-10-17 10:49:38 +00:00
|
|
|
const a = document.createElement('a')
|
|
|
|
|
a.href = URL.createObjectURL(blob)
|
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.download = name
|
2026-10-17 10:49:38 +00:00
|
|
|
a.click()
|
|
|
|
|
URL.revokeObjectURL(a.href)
|
|
|
|
|
}
|
|
|
|
|
|
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 slug = (name: string, fallback: string) => name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || fallback
|
|
|
|
|
|
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
|
|
|
function exportJson() {
|
|
|
|
|
persistNow()
|
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
|
|
|
download(`${slug(project.value.name, 'project')}.logigate.json`, JSON.stringify(project.value, null, 1))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function exportTable(t: TruthTable) {
|
|
|
|
|
download(`${slug(def.value.name, 'circuit')}-truth-table.csv`, tableCsv(t), 'text/csv')
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Opens a project file as a new project in the library. */
|
|
|
|
|
async function importAsProject(file: File) {
|
|
|
|
|
try {
|
|
|
|
|
const p = parseProject(await file.text())
|
|
|
|
|
if (p.name === 'Untitled') p.name = file.name.replace(/(\.logigate)?\.json$/i, '')
|
|
|
|
|
persistNow()
|
|
|
|
|
activate(addProject(p), p)
|
|
|
|
|
notify(`Opened ${file.name}`)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
notify((e as Error).message, 'error')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Adds the components of a project file to the open project. */
|
|
|
|
|
async function importComponents(file: File) {
|
|
|
|
|
try {
|
|
|
|
|
const p = parseProject(await file.text())
|
|
|
|
|
const n = mergeComponents(project.value, p.components)
|
|
|
|
|
commit()
|
|
|
|
|
notify(n ? `Added ${n} component${n === 1 ? '' : 's'} from ${file.name}` : 'Nothing new in that file')
|
|
|
|
|
} catch (e) {
|
|
|
|
|
notify((e as Error).message, 'error')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Share links ───────────────────────────────────────────────────
|
|
|
|
|
const linkState = ref<LinkState>(meta.value.link ? (meta.value.link.key ? 'saved' : 'viewer') : 'none')
|
|
|
|
|
const linkError = ref('')
|
|
|
|
|
const linkUrl = computed(() => (meta.value.link ? `${location.origin}/p/${meta.value.link.id}` : ''))
|
|
|
|
|
|
|
|
|
|
function syncUrl() {
|
|
|
|
|
const path = meta.value.link ? `/p/${meta.value.link.id}` : '/'
|
|
|
|
|
if (location.pathname !== path) history.replaceState(history.state, '', path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function api<T>(method: string, url: string, body?: unknown, key?: string): Promise<T> {
|
|
|
|
|
const res = await fetch(url, {
|
|
|
|
|
method,
|
|
|
|
|
headers: { 'content-type': 'application/json', ...(key ? { 'x-edit-key': key } : {}) },
|
|
|
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
|
|
|
})
|
|
|
|
|
const data = await res.json().catch(() => ({}))
|
|
|
|
|
if (!res.ok) throw new Error((data as { message?: string }).message || `Server error ${res.status}`)
|
|
|
|
|
return data as T
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createLink() {
|
|
|
|
|
persistNow()
|
|
|
|
|
linkState.value = 'saving'
|
2026-10-17 10:49:38 +00:00
|
|
|
try {
|
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
|
|
|
const res = await api<{ id: string; key: string }>('POST', '/api/p', { project: toRaw(project.value) })
|
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
|
|
|
meta.value = { ...meta.value, link: { id: res.id, key: res.key }, dirty: 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
|
|
|
saveMeta(toRaw(meta.value))
|
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
|
|
|
scheduleCloud()
|
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
|
|
|
projects.value = listProjects()
|
|
|
|
|
linkState.value = 'saved'
|
|
|
|
|
syncUrl()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
linkError.value = (e as Error).message
|
|
|
|
|
linkState.value = 'error'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let syncTimer: ReturnType<typeof setTimeout> | undefined
|
|
|
|
|
let syncing = false
|
|
|
|
|
async function pushLink() {
|
|
|
|
|
const link = meta.value.link
|
|
|
|
|
if (!link?.key) return
|
|
|
|
|
if (syncing) return scheduleSync()
|
|
|
|
|
syncing = true
|
|
|
|
|
linkState.value = 'saving'
|
|
|
|
|
try {
|
|
|
|
|
await api('PUT', `/api/p/${link.id}`, { project: toRaw(project.value) }, link.key)
|
|
|
|
|
linkState.value = 'saved'
|
|
|
|
|
} catch (e) {
|
|
|
|
|
linkError.value = (e as Error).message
|
|
|
|
|
linkState.value = 'error'
|
|
|
|
|
} finally {
|
|
|
|
|
syncing = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The person who made a link saves to it automatically, a few seconds after each change. */
|
|
|
|
|
function scheduleSync() {
|
|
|
|
|
if (!meta.value.link?.key) return
|
|
|
|
|
linkState.value = 'dirty'
|
|
|
|
|
clearTimeout(syncTimer)
|
|
|
|
|
syncTimer = setTimeout(pushLink, 2500)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Editing someone else's shared project turns it into your own copy. */
|
|
|
|
|
function forkIfViewer() {
|
|
|
|
|
if (!meta.value.link || meta.value.link.key) return
|
|
|
|
|
meta.value = { ...meta.value, link: undefined }
|
|
|
|
|
saveMeta(toRaw(meta.value))
|
|
|
|
|
linkState.value = 'none'
|
|
|
|
|
syncUrl()
|
|
|
|
|
notify('This is now your own copy. Share it to get your own link.')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Opens /p/:id: your own linked project, or a fresh copy of someone else's. */
|
|
|
|
|
async function openLink(id: string) {
|
|
|
|
|
const list = listProjects()
|
|
|
|
|
const own = list.find(m => m.link?.id === id && m.link.key)
|
|
|
|
|
if (own) {
|
|
|
|
|
if (own.id !== meta.value.id) switchProject(own.id)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`/api/p/${encodeURIComponent(id)}`)
|
|
|
|
|
if (!res.ok) throw new Error(res.status === 404 ? 'This link does not exist' : 'Could not load the link')
|
|
|
|
|
const data = (await res.json()) as { project: unknown }
|
|
|
|
|
const p = toProject(data.project)
|
|
|
|
|
if (!placeholder) persistNow()
|
|
|
|
|
const viewer = list.find(m => m.link?.id === id && !m.link.key)
|
|
|
|
|
if (viewer) {
|
|
|
|
|
const m = { ...viewer, name: p.name, updated: Date.now() }
|
|
|
|
|
saveProject(m, p)
|
|
|
|
|
activate(m, p)
|
|
|
|
|
} else activate(addProject(p, { id }), p)
|
|
|
|
|
notify(`Opened "${p.name}" from a shared link`)
|
2026-10-17 10:49:38 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
notify((e as Error).message, 'error')
|
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 (placeholder) persistNow()
|
|
|
|
|
syncUrl()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
async function copyText(text: string, done = 'Link copied') {
|
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
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(text)
|
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
|
|
|
notify(done)
|
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
|
|
|
} catch {
|
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
|
|
|
notify('Copy failed: the browser did not allow it', 'error')
|
2026-10-17 10:49:38 +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
|
|
|
window.addEventListener('beforeunload', () => {
|
|
|
|
|
if (saveTimer) persistNow()
|
|
|
|
|
})
|
|
|
|
|
|
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
|
|
|
// ── Account ───────────────────────────────────────────────────────
|
|
|
|
|
// Signed in, every project in this browser is also kept in the account and
|
|
|
|
|
// other devices get it on their next sync. Each upload names the revision
|
|
|
|
|
// it started from; when another device saved in between, both versions are
|
|
|
|
|
// kept (the other one as a copy) instead of one silently replacing the other.
|
|
|
|
|
const account = ref<AccountUser | null>(cachedAccount())
|
|
|
|
|
const cloudState = ref<'off' | 'syncing' | 'synced' | 'offline' | 'error'>(account.value ? 'syncing' : 'off')
|
|
|
|
|
const cloudError = ref('')
|
|
|
|
|
|
|
|
|
|
function setAccount(user: AccountUser | null) {
|
|
|
|
|
account.value = user
|
|
|
|
|
setCachedAccount(user)
|
|
|
|
|
cloudState.value = user ? cloudState.value : 'off'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function authCall<T>(method: string, url: string, body?: unknown): Promise<T> {
|
|
|
|
|
const res = await fetch(url, {
|
|
|
|
|
method,
|
|
|
|
|
headers: { 'content-type': 'application/json' },
|
|
|
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
|
|
|
})
|
|
|
|
|
const data = await res.json().catch(() => ({}))
|
|
|
|
|
if (res.status === 401 && url.startsWith('/api/me/')) {
|
|
|
|
|
setAccount(null)
|
|
|
|
|
notify('You were signed out. Sign in again to keep syncing.', 'error')
|
|
|
|
|
}
|
|
|
|
|
if (!res.ok && res.status !== 409) throw new Error((data as { message?: string }).message || `Server error ${res.status}`)
|
|
|
|
|
return { ...(data as object), status: res.status } as T
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function localProject(m: ProjectMeta): Project | null {
|
|
|
|
|
if (m.id === meta.value.id) {
|
|
|
|
|
if (saveTimer) persistNow()
|
|
|
|
|
return toRaw(project.value)
|
|
|
|
|
}
|
|
|
|
|
return loadProject(m.id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateMeta(id: string, patch: Partial<ProjectMeta>) {
|
|
|
|
|
const m = listProjects().find(x => x.id === id)
|
|
|
|
|
if (!m) return
|
|
|
|
|
const next = { ...m, ...patch }
|
|
|
|
|
if (patch.dirty === false) delete next.dirty
|
|
|
|
|
saveMeta(next)
|
|
|
|
|
if (id === meta.value.id) meta.value = { ...meta.value, ...patch }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface CloudMeta {
|
|
|
|
|
id: string
|
|
|
|
|
name: string
|
|
|
|
|
updated: number
|
|
|
|
|
rev: number
|
|
|
|
|
link?: ProjectMeta['link']
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Keeps the account's version as a separate project, so nothing is lost when two devices changed the same one. */
|
|
|
|
|
async function keepRemoteCopy(id: string) {
|
|
|
|
|
const res = await authCall<{ project?: Project; status: number }>('GET', `/api/me/projects/${id}`)
|
|
|
|
|
if (!res.project) return
|
|
|
|
|
const p = toProject(res.project)
|
|
|
|
|
p.name = `${p.name} (other device)`
|
|
|
|
|
saveProject({ id: newLocalId(), name: p.name, updated: Date.now() }, p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function upload(m: ProjectMeta, uid: string) {
|
|
|
|
|
const p = localProject(m)
|
|
|
|
|
if (!p) return
|
2026-10-20 11:20:55 +00:00
|
|
|
const body = { project: p, baseRev: m.cloud?.owner === uid ? m.cloud.rev : 0, link: m.link, snapshot: m.snapshot === 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
|
|
|
let res = await authCall<{ meta?: CloudMeta; conflict?: boolean; status: number }>('PUT', `/api/me/projects/${m.id}`, body)
|
|
|
|
|
if (res.conflict) {
|
|
|
|
|
await keepRemoteCopy(m.id)
|
|
|
|
|
res = await authCall('PUT', `/api/me/projects/${m.id}`, { ...body, force: true })
|
|
|
|
|
notify(`"${m.name}" was also changed on another device. That version is kept as a copy.`)
|
|
|
|
|
}
|
2026-10-20 11:20:55 +00:00
|
|
|
if (res.meta) updateMeta(m.id, { cloud: { owner: uid, rev: res.meta.rev }, dirty: false, snapshot: undefined })
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let syncingAccount = false
|
|
|
|
|
let syncAgain = false
|
|
|
|
|
/** Brings this browser and the account up to date in both directions. */
|
|
|
|
|
async function syncAccount() {
|
|
|
|
|
const uid = account.value?.id
|
|
|
|
|
if (!uid) return
|
|
|
|
|
if (syncingAccount) {
|
|
|
|
|
syncAgain = true
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
syncingAccount = true
|
|
|
|
|
cloudState.value = 'syncing'
|
|
|
|
|
try {
|
|
|
|
|
if (saveTimer) persistNow()
|
|
|
|
|
for (const d of pendingDeletes().filter(d => d.owner === uid)) {
|
|
|
|
|
await authCall('DELETE', `/api/me/projects/${d.id}`).catch(() => {})
|
|
|
|
|
}
|
|
|
|
|
setPendingDeletes(pendingDeletes().filter(d => d.owner !== uid))
|
|
|
|
|
|
|
|
|
|
const remote = await authCall<{ projects: CloudMeta[]; deleted: { id: string }[]; status: number }>('GET', '/api/me/projects')
|
|
|
|
|
if (!account.value) return
|
|
|
|
|
|
|
|
|
|
// Deleted on another device.
|
|
|
|
|
for (const t of remote.deleted) {
|
|
|
|
|
const m = listProjects().find(x => x.id === t.id && x.cloud?.owner === uid)
|
|
|
|
|
if (m && !m.dirty) {
|
|
|
|
|
if (m.id === meta.value.id) {
|
|
|
|
|
notify(`"${m.name}" was deleted on another device`)
|
|
|
|
|
deleteProject(m.id)
|
|
|
|
|
} else removeProject(m.id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New or newer in the account.
|
|
|
|
|
for (const r of remote.projects) {
|
|
|
|
|
const m = listProjects().find(x => x.id === r.id)
|
|
|
|
|
if (m && ((m.cloud && m.cloud.owner !== uid) || m.dirty || (m.cloud?.rev ?? 0) >= r.rev)) continue
|
|
|
|
|
const res = await authCall<{ project?: Project; status: number }>('GET', `/api/me/projects/${r.id}`)
|
|
|
|
|
if (!res.project) continue
|
|
|
|
|
const p = toProject(res.project)
|
|
|
|
|
const next: ProjectMeta = { id: r.id, name: p.name, updated: r.updated, cloud: { owner: uid, rev: r.rev } }
|
|
|
|
|
const link = r.link ?? m?.link
|
|
|
|
|
if (link) next.link = link
|
|
|
|
|
saveProject(next, p)
|
|
|
|
|
if (r.id === meta.value.id) {
|
|
|
|
|
activate(next, p)
|
|
|
|
|
notify(`Updated "${p.name}" from another device`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Projects that are new here or changed here (not the untouched starter project).
|
|
|
|
|
for (const m of listProjects()) {
|
|
|
|
|
if ((m.cloud && m.cloud.owner !== uid) || (m.starter && !m.dirty)) continue
|
|
|
|
|
if (!m.cloud || m.dirty) await upload(m, uid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A new browser: open the account's latest project instead of the untouched starter.
|
|
|
|
|
if (meta.value.starter && !meta.value.dirty) {
|
|
|
|
|
const latest = listProjects().filter(m => m.cloud?.owner === uid).sort((a, b) => b.updated - a.updated)[0]
|
|
|
|
|
const p = latest && loadProject(latest.id)
|
|
|
|
|
if (latest && p) {
|
|
|
|
|
const starter = meta.value.id
|
|
|
|
|
activate(latest, p)
|
|
|
|
|
removeProject(starter)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
projects.value = listProjects()
|
|
|
|
|
cloudState.value = 'synced'
|
|
|
|
|
cloudError.value = ''
|
|
|
|
|
} catch (e) {
|
|
|
|
|
cloudError.value = (e as Error).message
|
|
|
|
|
cloudState.value = navigator.onLine ? 'error' : 'offline'
|
|
|
|
|
} finally {
|
|
|
|
|
syncingAccount = false
|
|
|
|
|
if (syncAgain) {
|
|
|
|
|
syncAgain = false
|
|
|
|
|
void syncAccount()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let cloudTimer: ReturnType<typeof setTimeout> | undefined
|
|
|
|
|
function scheduleCloud() {
|
|
|
|
|
if (!account.value) return
|
|
|
|
|
clearTimeout(cloudTimer)
|
|
|
|
|
cloudTimer = setTimeout(syncAccount, 2000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function signIn(email: string, password: string, create: boolean) {
|
|
|
|
|
const res = await authCall<{ user?: AccountUser; message?: string; status: number }>('POST', create ? '/api/auth/register' : '/api/auth/login', { email, password })
|
|
|
|
|
if (!res.user) throw new Error(res.message || 'Could not sign in')
|
|
|
|
|
setAccount(res.user)
|
|
|
|
|
await syncAccount()
|
|
|
|
|
notify(create ? 'Account created. Your projects are now saved in it.' : `Signed in as ${res.user.email}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function signOut(removeHere: boolean) {
|
|
|
|
|
const uid = account.value?.id
|
|
|
|
|
if (uid) await syncAccount()
|
|
|
|
|
await authCall('POST', '/api/auth/logout').catch(() => {})
|
|
|
|
|
setAccount(null)
|
|
|
|
|
if (removeHere && uid) {
|
|
|
|
|
for (const m of listProjects()) if (m.cloud?.owner === uid && !m.dirty) removeProject(m.id)
|
|
|
|
|
projects.value = listProjects()
|
|
|
|
|
if (!projects.value.some(m => m.id === meta.value.id)) deleteProject(meta.value.id)
|
|
|
|
|
}
|
|
|
|
|
notify('Signed out')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function changePassword(current: string, next: string) {
|
|
|
|
|
await authCall('POST', '/api/auth/password', { current, next })
|
|
|
|
|
notify('Password changed. Other devices need to sign in again.')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function deleteAccount(password: string) {
|
|
|
|
|
const uid = account.value?.id
|
|
|
|
|
await authCall('POST', '/api/auth/delete', { password })
|
|
|
|
|
setAccount(null)
|
|
|
|
|
// The projects stay in this browser, now as local-only projects.
|
|
|
|
|
for (const m of listProjects()) {
|
|
|
|
|
if (m.cloud?.owner !== uid) continue
|
|
|
|
|
const next = { ...m }
|
|
|
|
|
delete next.cloud
|
|
|
|
|
saveMeta(next)
|
|
|
|
|
}
|
|
|
|
|
if (meta.value.cloud?.owner === uid) {
|
|
|
|
|
const next = { ...meta.value }
|
|
|
|
|
delete next.cloud
|
|
|
|
|
meta.value = next
|
|
|
|
|
}
|
|
|
|
|
projects.value = listProjects()
|
|
|
|
|
notify('Account deleted. Your projects are still in this browser.')
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-20 11:20:55 +00:00
|
|
|
// ── Savegames ─────────────────────────────────────────────────────
|
|
|
|
|
interface VersionInfo {
|
|
|
|
|
v: number
|
|
|
|
|
at: number
|
|
|
|
|
rev: number
|
|
|
|
|
name: string
|
|
|
|
|
size: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function listVersions(projectId: string): Promise<VersionInfo[]> {
|
|
|
|
|
const res = await authCall<{ versions: VersionInfo[]; status: number }>('GET', `/api/me/projects/${projectId}/versions`)
|
|
|
|
|
return res.versions ?? []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fetchVersion(projectId: string, v: number): Promise<Project> {
|
|
|
|
|
const res = await authCall<{ version?: { project: unknown }; status: number }>('GET', `/api/me/projects/${projectId}/versions/${v}`)
|
|
|
|
|
if (!res.version) throw new Error('Version not found')
|
|
|
|
|
return toProject(res.version.project)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Brings back a savegame: as a new project, or in place of the current
|
|
|
|
|
* state (which the server keeps as a savegame first, so this can be undone).
|
|
|
|
|
*/
|
|
|
|
|
async function restoreVersion(projectId: string, v: number, asCopy: boolean) {
|
|
|
|
|
if (projectId === meta.value.id && saveTimer) persistNow()
|
|
|
|
|
const p = await fetchVersion(projectId, v)
|
|
|
|
|
if (asCopy) {
|
|
|
|
|
p.name = `${p.name} (${new Date(v).toLocaleDateString()})`
|
|
|
|
|
activate(addProject(p), p)
|
|
|
|
|
notify(`Opened the saved version as "${p.name}"`)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const m = listProjects().find(x => x.id === projectId)
|
|
|
|
|
if (!m) return
|
|
|
|
|
const next: ProjectMeta = { ...m, name: p.name, updated: Date.now(), dirty: true, snapshot: true }
|
|
|
|
|
saveProject(next, p)
|
|
|
|
|
activate(next, p)
|
|
|
|
|
scheduleCloud()
|
|
|
|
|
notify('Restored. The state before is kept as a savegame too.')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function listTrash(): Promise<{ id: string; name: string; deleted: number; v: number }[]> {
|
|
|
|
|
const res = await authCall<{ projects: { id: string; name: string; deleted: number; v: number }[]; status: number }>('GET', '/api/me/trash')
|
|
|
|
|
return res.projects ?? []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function restoreDeleted(item: { id: string; v: number }) {
|
|
|
|
|
const p = await fetchVersion(item.id, item.v)
|
|
|
|
|
persistNow()
|
|
|
|
|
setPendingDeletes(pendingDeletes().filter(d => d.id !== item.id))
|
|
|
|
|
const m: ProjectMeta = { id: item.id, name: p.name, updated: Date.now(), dirty: true }
|
|
|
|
|
saveProject(m, p)
|
|
|
|
|
activate(m, p)
|
|
|
|
|
scheduleCloud()
|
|
|
|
|
notify(`"${p.name}" is back`)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** Checks the session with the server, then syncs; again on focus and every minute. */
|
|
|
|
|
async function startAccount() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await authCall<{ user: AccountUser | null; status: number }>('GET', '/api/auth/me')
|
|
|
|
|
setAccount(res.user)
|
|
|
|
|
if (res.user) await syncAccount()
|
|
|
|
|
} catch {
|
|
|
|
|
if (account.value) cloudState.value = 'offline'
|
|
|
|
|
}
|
|
|
|
|
let lastFocusSync = Date.now()
|
|
|
|
|
const onFocus = () => {
|
|
|
|
|
if (document.visibilityState === 'visible' && Date.now() - lastFocusSync > 10_000) {
|
|
|
|
|
lastFocusSync = Date.now()
|
|
|
|
|
void syncAccount()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
document.addEventListener('visibilitychange', onFocus)
|
|
|
|
|
window.addEventListener('online', () => void syncAccount())
|
|
|
|
|
setInterval(() => document.visibilityState === 'visible' && void syncAccount(), 60_000)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
function shape(node: CircuitNode) {
|
|
|
|
|
return shapeOf(node, getDef.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rebuild()
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
project,
|
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
|
|
|
meta,
|
|
|
|
|
projects,
|
2026-10-17 10:49:38 +00:00
|
|
|
getDef,
|
|
|
|
|
def,
|
|
|
|
|
selection,
|
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
|
|
|
wireSel,
|
|
|
|
|
selectedWires,
|
|
|
|
|
clearSelection,
|
2026-10-17 10:49:38 +00:00
|
|
|
placing,
|
|
|
|
|
nav,
|
|
|
|
|
views,
|
|
|
|
|
notice,
|
|
|
|
|
labelFocus,
|
|
|
|
|
showHelp,
|
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
|
|
|
dialog,
|
2026-10-17 10:49:38 +00:00
|
|
|
notify,
|
|
|
|
|
commit,
|
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
|
|
|
persist,
|
2026-10-17 10:49:38 +00:00
|
|
|
undo,
|
|
|
|
|
redo,
|
|
|
|
|
canUndo,
|
|
|
|
|
canRedo,
|
|
|
|
|
sim,
|
|
|
|
|
tick,
|
|
|
|
|
status,
|
|
|
|
|
running,
|
|
|
|
|
hz,
|
|
|
|
|
cycles,
|
|
|
|
|
errors,
|
|
|
|
|
circuitStats,
|
|
|
|
|
val,
|
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
|
|
|
faceVal,
|
2026-10-17 10:49:38 +00:00
|
|
|
startLoop,
|
|
|
|
|
step,
|
|
|
|
|
rebuild,
|
|
|
|
|
open,
|
|
|
|
|
back,
|
|
|
|
|
addNode,
|
|
|
|
|
canPlace,
|
|
|
|
|
connect,
|
|
|
|
|
deleteSelected,
|
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
|
|
|
setWireColor,
|
|
|
|
|
autoRoute,
|
|
|
|
|
selectNet,
|
2026-10-17 10:49:38 +00:00
|
|
|
toggleInput,
|
|
|
|
|
press,
|
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
|
|
|
toggleRow,
|
|
|
|
|
pressRow,
|
|
|
|
|
addPanel,
|
|
|
|
|
undock,
|
|
|
|
|
setRowType,
|
|
|
|
|
addRow,
|
|
|
|
|
dropRow,
|
|
|
|
|
withDocked,
|
|
|
|
|
linking,
|
|
|
|
|
startLinking,
|
|
|
|
|
linkTo,
|
|
|
|
|
stopLinking,
|
|
|
|
|
setTidy,
|
|
|
|
|
tidyAll,
|
|
|
|
|
exportTable,
|
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
|
|
|
swap,
|
|
|
|
|
unlink,
|
|
|
|
|
unpack,
|
|
|
|
|
makeIndependent,
|
2026-10-17 10:49:38 +00:00
|
|
|
copy,
|
|
|
|
|
paste,
|
|
|
|
|
duplicate,
|
|
|
|
|
selectAll,
|
|
|
|
|
packageSelected,
|
|
|
|
|
createComponent,
|
|
|
|
|
removeComponent,
|
|
|
|
|
copyComponent,
|
|
|
|
|
beginChallenge,
|
|
|
|
|
checkChallenge,
|
|
|
|
|
table,
|
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
|
|
|
switchProject,
|
2026-10-17 10:49:38 +00:00
|
|
|
newProject,
|
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
|
|
|
duplicateProject,
|
|
|
|
|
deleteProject,
|
|
|
|
|
renameProject,
|
2026-10-17 10:49:38 +00:00
|
|
|
loadExamples,
|
|
|
|
|
exportJson,
|
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
|
|
|
importAsProject,
|
|
|
|
|
importComponents,
|
|
|
|
|
linkState,
|
|
|
|
|
linkError,
|
|
|
|
|
linkUrl,
|
|
|
|
|
createLink,
|
|
|
|
|
pushLink,
|
|
|
|
|
openLink,
|
|
|
|
|
syncUrl,
|
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
|
|
|
account,
|
|
|
|
|
cloudState,
|
|
|
|
|
cloudError,
|
|
|
|
|
syncAccount,
|
|
|
|
|
signIn,
|
|
|
|
|
signOut,
|
|
|
|
|
changePassword,
|
|
|
|
|
deleteAccount,
|
|
|
|
|
startAccount,
|
2026-10-20 11:20:55 +00:00
|
|
|
versionsFor,
|
|
|
|
|
listVersions,
|
|
|
|
|
restoreVersion,
|
|
|
|
|
listTrash,
|
|
|
|
|
restoreDeleted,
|
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
|
|
|
copyText,
|
2026-10-17 10:49:38 +00:00
|
|
|
shape,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let editor: ReturnType<typeof create> | undefined
|
|
|
|
|
|
|
|
|
|
export function useEditor() {
|
|
|
|
|
editor ??= create()
|
|
|
|
|
return editor
|
|
|
|
|
}
|