2026-10-17 10:49:38 +00:00
|
|
|
// Node shapes and pin positions, all in grid units relative to the node's
|
|
|
|
|
// (x, y). Pins always sit on whole grid points so straight wires line up.
|
|
|
|
|
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
import type { CircuitNode, ComponentDef, FaceShape, LampColor, PanelRow, SymbolKind } from './types'
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
export const GRID = 16
|
|
|
|
|
|
|
|
|
|
export interface PinInfo {
|
|
|
|
|
key: string
|
|
|
|
|
label: string
|
|
|
|
|
dx: number
|
|
|
|
|
dy: number
|
2026-10-20 17:29:16 +00:00
|
|
|
/** A cable pin: only joins another cable pin. */
|
|
|
|
|
bus?: boolean
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface Shape {
|
|
|
|
|
body: { x: number; y: number; w: number; h: number }
|
|
|
|
|
inputs: PinInfo[]
|
|
|
|
|
outputs: PinInfo[]
|
|
|
|
|
/** Set when the node draws as a logic gate symbol. */
|
|
|
|
|
gate?: SymbolKind
|
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
|
|
|
/** Vertical centre of the pin area, where a box prints its name. */
|
|
|
|
|
nameY?: number
|
|
|
|
|
/** Lamps and displays from inside the component, shown on its box. */
|
|
|
|
|
face?: FaceItem[]
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
/** Where a box prints its name (its middle), or null when it is left off; empty: centred. */
|
|
|
|
|
nameAt?: { x: number; y: number } | null
|
|
|
|
|
/** Drawings on a hand-drawn box, in grid units relative to the chip node. */
|
|
|
|
|
drawing?: FaceShape[]
|
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
|
|
|
}
|
|
|
|
|
|
2026-10-20 17:29:16 +00:00
|
|
|
export interface ScreenPixel {
|
|
|
|
|
/** Pixel node id inside the component. */
|
|
|
|
|
id: string
|
|
|
|
|
col: number
|
|
|
|
|
row: number
|
|
|
|
|
color?: LampColor
|
|
|
|
|
}
|
|
|
|
|
|
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 interface FaceItem {
|
2026-10-20 17:29:16 +00:00
|
|
|
/** Node id inside the component; for a screen, the first pixel'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
|
|
|
id: string
|
2026-10-20 17:29:16 +00:00
|
|
|
kind: 'lamp' | 'hex' | 'screen'
|
|
|
|
|
/** Screen only: its pixels and the size of one, in grid units. */
|
|
|
|
|
pixels?: ScreenPixel[]
|
|
|
|
|
px?: 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
|
|
|
label: 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
|
|
|
color?: LampColor
|
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
|
|
|
/** Top-left corner and size in grid units, relative to the chip node. */
|
|
|
|
|
x: number
|
|
|
|
|
y: number
|
|
|
|
|
w: number
|
|
|
|
|
h: number
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type DefLookup = (id: string) => ComponentDef | undefined
|
|
|
|
|
|
|
|
|
|
const LABEL_CHAR = 0.4 // grid units per character of a pin label
|
|
|
|
|
const NAME_CHAR = 0.44
|
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 FACE_CHAR = 0.34
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
export interface ChipPins {
|
|
|
|
|
inputs: { key: string; label: string }[]
|
|
|
|
|
outputs: { key: string; label: string }[]
|
|
|
|
|
}
|
|
|
|
|
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
/** Pin key of a panel row: the same key the row has as a switch in the simulator. */
|
|
|
|
|
export const rowPin = (panelId: string, rowId: string) => `${panelId}:${rowId}`
|
|
|
|
|
|
|
|
|
|
/** Panel rows that are input pins of their component: switches and buttons, unless the panel keeps them inside. */
|
|
|
|
|
export const isPinRow = (panel: CircuitNode, row: PanelRow) => !panel.inner && row.type !== 'clock'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A component's pins, ordered top to bottom: its input and output nodes,
|
|
|
|
|
* and the switch and button rows of its input panels, which count as inputs.
|
|
|
|
|
*/
|
2026-10-17 10:49:38 +00:00
|
|
|
export function chipPins(def: ComponentDef): ChipPins {
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
const inputs: { key: string; label: string; x: number; y: number }[] = []
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
if (n.kind === 'input') inputs.push({ key: n.id, label: n.label?.trim() ?? '', x: n.x, y: n.y })
|
|
|
|
|
else if (n.kind === 'panel') {
|
|
|
|
|
const rows = n.rows ?? []
|
|
|
|
|
const at = panelOffsets(rows)
|
|
|
|
|
rows.forEach((r, i) => {
|
|
|
|
|
if (isPinRow(n, r)) inputs.push({ key: rowPin(n.id, r.id), label: r.label?.trim() || r.name?.trim() || '', x: n.x, y: n.y + at[i]! })
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
inputs.sort((a, b) => a.y - b.y || a.x - b.x)
|
|
|
|
|
const outputs = def.nodes.filter(n => n.kind === 'output').sort((a, b) => a.y - b.y || a.x - b.x)
|
|
|
|
|
return {
|
|
|
|
|
inputs: inputs.map((p, i) => ({ key: p.key, label: p.label || `in${i + 1}` })),
|
|
|
|
|
outputs: outputs.map((n, i) => ({ key: n.id, label: n.label?.trim() || `out${i + 1}` })),
|
|
|
|
|
}
|
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
|
|
|
/**
|
|
|
|
|
* Lamps and hex displays inside a component, arranged on its box the way
|
|
|
|
|
* they are placed inside: nodes at about the same height share a row.
|
|
|
|
|
*/
|
|
|
|
|
export function faceLayout(def: ComponentDef): { items: FaceItem[]; w: number; h: number } {
|
|
|
|
|
const empty = { items: [], w: 0, h: 0 }
|
|
|
|
|
if (def.face === false) return empty
|
|
|
|
|
const nodes = def.nodes.filter(n => n.kind === 'lamp' || n.kind === 'hex').sort((a, b) => a.y - b.y || a.x - b.x)
|
|
|
|
|
const rows: CircuitNode[][] = []
|
|
|
|
|
for (const n of nodes) {
|
|
|
|
|
const row = rows[rows.length - 1]
|
|
|
|
|
if (row && Math.abs(n.y - row[0]!.y) <= 1) row.push(n)
|
|
|
|
|
else rows.push([n])
|
|
|
|
|
}
|
|
|
|
|
const items: FaceItem[] = []
|
|
|
|
|
let y = 0
|
|
|
|
|
let w = 0
|
|
|
|
|
for (const row of rows) {
|
|
|
|
|
row.sort((a, b) => a.x - b.x)
|
|
|
|
|
let x = 0
|
|
|
|
|
let h = 0
|
|
|
|
|
for (const n of row) {
|
|
|
|
|
const label = n.label?.trim() ?? ''
|
|
|
|
|
const iw = Math.max(n.kind === 'hex' ? 1.6 : 1.4, label.length * FACE_CHAR + 0.4)
|
|
|
|
|
const ih = (n.kind === 'hex' ? 2.2 : 1.2) + (label ? 0.7 : 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
|
|
|
items.push({ id: n.id, kind: n.kind as 'lamp' | 'hex', label, color: n.color, x, y, w: iw, h: ih })
|
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
|
|
|
x += iw + 0.3
|
|
|
|
|
h = Math.max(h, ih)
|
|
|
|
|
}
|
|
|
|
|
w = Math.max(w, x - 0.3)
|
|
|
|
|
y += h + 0.3
|
|
|
|
|
}
|
2026-10-20 17:29:16 +00:00
|
|
|
const screen = screenLayout(def)
|
|
|
|
|
if (screen) {
|
|
|
|
|
w = Math.max(w, screen.w)
|
|
|
|
|
items.push({ ...screen, x: (w - screen.w) / 2, y })
|
|
|
|
|
y += screen.h + 0.3
|
|
|
|
|
}
|
|
|
|
|
if (!items.length) return empty
|
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 { items, w, h: y - 0.3 }
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-20 17:29:16 +00:00
|
|
|
/**
|
|
|
|
|
* Pixels inside a component, drawn as one screen without gaps: every
|
|
|
|
|
* distinct column and row they sit on becomes a column and row of the
|
|
|
|
|
* screen, so they can be spaced out inside for wiring.
|
|
|
|
|
*/
|
|
|
|
|
export function screenLayout(def: ComponentDef): FaceItem | null {
|
|
|
|
|
const pixels = def.nodes.filter(n => n.kind === 'pixel')
|
|
|
|
|
if (!pixels.length) return null
|
|
|
|
|
const xs = [...new Set(pixels.map(n => n.x))].sort((a, b) => a - b)
|
|
|
|
|
const ys = [...new Set(pixels.map(n => n.y))].sort((a, b) => a - b)
|
|
|
|
|
const col = new Map(xs.map((x, i) => [x, i]))
|
|
|
|
|
const row = new Map(ys.map((y, i) => [y, i]))
|
|
|
|
|
const size = Math.max(xs.length, ys.length)
|
|
|
|
|
const px = size <= 8 ? 1 : size <= 32 ? 0.5 : 0.25
|
|
|
|
|
return {
|
|
|
|
|
id: pixels[0]!.id,
|
|
|
|
|
kind: 'screen',
|
|
|
|
|
label: '',
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
w: xs.length * px,
|
|
|
|
|
h: ys.length * px,
|
|
|
|
|
px,
|
|
|
|
|
pixels: pixels.map(n => ({ id: n.id, col: col.get(n.x)!, row: row.get(n.y)!, color: n.color })),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
function gateShape(symbol: SymbolKind, inputs: { key: string; label: string }[], output: { key: string; label: string }): Shape {
|
|
|
|
|
const n = inputs.length
|
|
|
|
|
if (n === 1) {
|
|
|
|
|
return {
|
|
|
|
|
gate: symbol,
|
|
|
|
|
body: { x: 0, y: -1, w: 3, h: 2 },
|
|
|
|
|
inputs: [{ ...inputs[0]!, dx: 0, dy: 0 }],
|
|
|
|
|
outputs: [{ ...output, dx: 3, dy: 0 }],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (n === 2) {
|
|
|
|
|
return {
|
|
|
|
|
gate: symbol,
|
|
|
|
|
body: { x: 0, y: -0.5, w: 4, h: 3 },
|
|
|
|
|
inputs: inputs.map((p, i) => ({ ...p, dx: 0, dy: i * 2 })),
|
|
|
|
|
outputs: [{ ...output, dx: 4, dy: 1 }],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
gate: symbol,
|
|
|
|
|
body: { x: 0, y: -0.5, w: 4, h: n },
|
|
|
|
|
inputs: inputs.map((p, i) => ({ ...p, dx: 0, dy: i })),
|
|
|
|
|
outputs: [{ ...output, dx: 4, dy: Math.floor((n - 1) / 2) }],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
/**
|
|
|
|
|
* A box drawn by hand: the size it was given (never shorter than its pins
|
|
|
|
|
* need), everything placed where it was put, the rest where it would go
|
|
|
|
|
* anyway, and its drawings.
|
|
|
|
|
*/
|
|
|
|
|
function designedShape(def: ComponentDef, pins: ChipPins, face: ReturnType<typeof faceLayout>): Shape {
|
|
|
|
|
const auto = boxShape(def.name, pins, face)
|
|
|
|
|
const d = def.design!
|
|
|
|
|
const top = auto.body.y
|
|
|
|
|
const pinH = Math.max(pins.inputs.length, pins.outputs.length, 1)
|
|
|
|
|
const w = Math.max(2, d.w)
|
|
|
|
|
const h = Math.max(pinH === 1 ? 2 : pinH, d.h)
|
|
|
|
|
const hide = new Set(d.hide ?? [])
|
|
|
|
|
const place = d.place ?? {}
|
|
|
|
|
return {
|
|
|
|
|
...auto,
|
|
|
|
|
body: { x: 0, y: top, w, h },
|
|
|
|
|
outputs: auto.outputs.map(p => ({ ...p, dx: w })),
|
|
|
|
|
face: (auto.face ?? [])
|
|
|
|
|
.filter(it => !hide.has(it.kind === 'screen' ? 'screen' : it.id))
|
|
|
|
|
.map(it => {
|
|
|
|
|
const at = place[it.kind === 'screen' ? 'screen' : it.id]
|
|
|
|
|
return at ? { ...it, x: at.x, y: top + at.y } : it
|
|
|
|
|
}),
|
|
|
|
|
nameAt: hide.has('name') ? null : place.name ? { x: place.name.x, y: top + place.name.y } : undefined,
|
|
|
|
|
drawing: (d.shapes ?? []).map(sh => ({ ...sh, y: top + sh.y })),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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 boxShape(name: string, pins: ChipPins, face: ReturnType<typeof faceLayout>): Shape {
|
2026-10-17 10:49:38 +00:00
|
|
|
const nIn = pins.inputs.length
|
|
|
|
|
const nOut = pins.outputs.length
|
|
|
|
|
const n = Math.max(nIn, nOut, 1)
|
|
|
|
|
const inOff = Math.floor((n - nIn) / 2)
|
|
|
|
|
const outOff = Math.floor((n - nOut) / 2)
|
|
|
|
|
const longest = (ps: { label: string }[]) => ps.reduce((m, p) => Math.max(m, p.label.length), 0)
|
|
|
|
|
const w = Math.max(
|
|
|
|
|
3,
|
|
|
|
|
Math.ceil(longest(pins.inputs) * LABEL_CHAR + longest(pins.outputs) * LABEL_CHAR + name.length * NAME_CHAR + 1.5),
|
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
|
|
|
Math.ceil(face.w + 1.2),
|
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
|
|
|
const top = n === 1 ? -1 : -0.5
|
|
|
|
|
const pinBottom = n === 1 ? 1 : n - 0.5
|
|
|
|
|
const faceTop = pinBottom + 0.2
|
|
|
|
|
const faceLeft = (w - face.w) / 2
|
2026-10-17 10:49:38 +00:00
|
|
|
return {
|
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
|
|
|
body: { x: 0, y: top, w, h: pinBottom - top + (face.items.length ? face.h + 0.6 : 0) },
|
2026-10-17 10:49:38 +00:00
|
|
|
inputs: pins.inputs.map((p, i) => ({ ...p, dx: 0, dy: inOff + i })),
|
|
|
|
|
outputs: pins.outputs.map((p, i) => ({ ...p, dx: w, dy: outOff + i })),
|
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
|
|
|
nameY: (top + pinBottom) / 2,
|
|
|
|
|
face: face.items.map(it => ({ ...it, x: it.x + faceLeft, y: it.y + faceTop })),
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NAND_SHAPE = gateShape('nand', [{ key: 'a', label: 'A' }, { key: 'b', label: 'B' }], { key: 'q', label: 'Q' })
|
|
|
|
|
|
|
|
|
|
const SOURCE_SHAPE: Shape = {
|
|
|
|
|
body: { x: 0, y: -0.75, w: 2, h: 1.5 },
|
|
|
|
|
inputs: [],
|
|
|
|
|
outputs: [{ key: 'q', label: '', dx: 2, dy: 0 }],
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-20 18:09:23 +00:00
|
|
|
// Output pins and lamps pass their signal on: the pin on the right carries the same value.
|
2026-10-17 10:49:38 +00:00
|
|
|
const SINK_SHAPE: Shape = {
|
|
|
|
|
body: { x: 0, y: -0.75, w: 2, h: 1.5 },
|
|
|
|
|
inputs: [{ key: 'a', label: '', dx: 0, dy: 0 }],
|
2026-10-20 18:09:23 +00:00
|
|
|
outputs: [{ key: 'q', label: '', dx: 2, dy: 0 }],
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
/** Width of a signal tag's flag, from its name. */
|
|
|
|
|
function tagWidth(node: CircuitNode): number {
|
|
|
|
|
return Math.max(2.5, Math.ceil((signalName(node) || '?').length * 0.45 + 1.4))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The name a signal tag sends, or a reference uses. */
|
|
|
|
|
export const signalName = (node: CircuitNode) => node.label?.trim() ?? ''
|
|
|
|
|
|
|
|
|
|
/** Send: the wire comes in on the left into a flag carrying the name. */
|
|
|
|
|
function tagShape(node: CircuitNode): Shape {
|
|
|
|
|
const w = tagWidth(node)
|
|
|
|
|
return { body: { x: 0.5, y: -0.6, w, h: 1.2 }, inputs: [{ key: 'a', label: '', dx: 0, dy: 0 }], outputs: [] }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Use: a flag with the name, the signal leaves on the right. */
|
|
|
|
|
function refShape(node: CircuitNode): Shape {
|
|
|
|
|
const w = tagWidth(node)
|
|
|
|
|
return { body: { x: 0, y: -0.6, w, h: 1.2 }, inputs: [], outputs: [{ key: 'q', label: '', dx: w + 0.5, dy: 0 }] }
|
|
|
|
|
}
|
|
|
|
|
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
// A hex display passes its four bits on, so it can sit in the middle of a bus.
|
2026-10-17 10:49:38 +00:00
|
|
|
const HEX_SHAPE: Shape = {
|
|
|
|
|
body: { x: 0, y: -0.5, w: 3, h: 4 },
|
|
|
|
|
inputs: ['1', '2', '4', '8'].map((label, i) => ({ key: `b${i}`, label, dx: 0, dy: i })),
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
outputs: ['1', '2', '4', '8'].map((label, i) => ({ key: `q${i}`, label, dx: 3, dy: i })),
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CLOCK_SHAPE: Shape = {
|
|
|
|
|
body: { x: 0, y: -0.75, w: 3, h: 1.5 },
|
|
|
|
|
inputs: [],
|
|
|
|
|
outputs: [{ key: 'q', label: '', dx: 3, dy: 0 }],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MISSING_SHAPE: Shape = { body: { x: 0, y: -1, w: 4, h: 2 }, inputs: [], outputs: [] }
|
|
|
|
|
|
2026-10-20 17:29:16 +00:00
|
|
|
export const MAX_BITS = 32
|
|
|
|
|
|
|
|
|
|
/** Wires in a cable, within range. */
|
|
|
|
|
export function cableBits(node: CircuitNode): number {
|
|
|
|
|
const n = node.bits ?? 4
|
|
|
|
|
return Math.min(MAX_BITS, Math.max(2, Math.round(n)))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-21 09:51:45 +00:00
|
|
|
/** Row of each wire of a cable end below the first: evenly `pitch` apart, or as plugged. */
|
|
|
|
|
export function cableOffsets(node: CircuitNode): number[] {
|
2026-10-20 17:29:16 +00:00
|
|
|
const n = cableBits(node)
|
2026-10-21 09:51:45 +00:00
|
|
|
const o = node.offsets
|
|
|
|
|
if (o?.length === n && o[0] === 0 && o.every((v, i) => i === 0 || v > o[i - 1]!)) return o
|
|
|
|
|
const pitch = Math.max(1, Math.min(8, Math.round(node.pitch ?? 1)))
|
|
|
|
|
return Array.from({ length: n }, (_, i) => i * pitch)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-21 09:59:17 +00:00
|
|
|
/** Bundle: one input per wire on the left, the cable leaves on the right. Split: the mirror image. */
|
2026-10-21 09:51:45 +00:00
|
|
|
function cableShape(node: CircuitNode): Shape {
|
|
|
|
|
const dys = cableOffsets(node)
|
2026-10-21 09:59:17 +00:00
|
|
|
const wires = dys.map((dy, i) => ({ key: `b${i}`, label: node.names?.[i] || String(i), dy }))
|
2026-10-21 09:51:45 +00:00
|
|
|
const last = dys[dys.length - 1]!
|
|
|
|
|
const mid = Math.floor(last / 2)
|
2026-10-21 09:59:17 +00:00
|
|
|
const body = { x: 0, y: -0.5, w: 1, h: last + 1 }
|
2026-10-20 17:29:16 +00:00
|
|
|
if (node.kind === 'bundle') {
|
2026-10-21 09:59:17 +00:00
|
|
|
return { body, inputs: wires.map(p => ({ ...p, dx: 0 })), outputs: [{ key: 'q', label: '', dx: 1, dy: mid, bus: true }] }
|
2026-10-20 17:29:16 +00:00
|
|
|
}
|
2026-10-21 09:59:17 +00:00
|
|
|
return { body, inputs: [{ key: 'a', label: '', dx: 0, dy: mid, bus: true }], outputs: wires.map(p => ({ ...p, dx: 1 })) }
|
2026-10-20 17:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PIXEL_SHAPE: Shape = {
|
|
|
|
|
body: { x: 0, y: -0.5, w: 1, h: 1 },
|
|
|
|
|
inputs: [{ key: 'a', label: '', dx: 0, dy: 0 }],
|
|
|
|
|
outputs: [],
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** Grid offset of every panel row below the first one. */
|
|
|
|
|
export function panelOffsets(rows: PanelRow[]): number[] {
|
|
|
|
|
const out: number[] = []
|
|
|
|
|
for (const r of rows) {
|
|
|
|
|
const prev = out.length ? out[out.length - 1]! : -1
|
|
|
|
|
out.push(r.dy !== undefined && r.dy > prev ? r.dy : prev + 1)
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Name shown next to a panel row: the user's, the driven pin's, or its number. */
|
|
|
|
|
export function rowLabel(row: PanelRow, i: number): string {
|
|
|
|
|
return row.label?.trim() || row.name?.trim() || String(i + 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Width of the control drawn in each panel row, in grid units. */
|
|
|
|
|
export const PANEL_CONTROL_W = 2.2
|
|
|
|
|
|
|
|
|
|
function panelShape(node: CircuitNode): Shape {
|
|
|
|
|
const rows = node.rows ?? []
|
|
|
|
|
const dys = panelOffsets(rows)
|
|
|
|
|
const labels = rows.map(rowLabel)
|
2026-10-21 09:51:45 +00:00
|
|
|
const keys = rows.some(r => r.key) ? 0.7 : 0
|
|
|
|
|
const w = Math.max(4, Math.ceil(labels.reduce((m, l) => Math.max(m, l.length), 0) * LABEL_CHAR + PANEL_CONTROL_W + 1.1 + keys))
|
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 last = dys.length ? dys[dys.length - 1]! : 0
|
|
|
|
|
return {
|
|
|
|
|
body: { x: 0, y: -0.5, w, h: last + 1 },
|
|
|
|
|
inputs: [],
|
|
|
|
|
outputs: rows.map((r, i) => ({ key: r.id, label: labels[i]!, dx: w, dy: dys[i]! })),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
export function noteLines(node: CircuitNode): string[] {
|
|
|
|
|
return (node.label || 'Note').split('\n')
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
export function noteScale(node: CircuitNode): number {
|
|
|
|
|
return node.size === 'sm' ? 0.8 : node.size === 'lg' ? 1.5 : 1
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
export function shapeOf(node: CircuitNode, getDef: DefLookup): Shape {
|
|
|
|
|
switch (node.kind) {
|
|
|
|
|
case 'nand':
|
|
|
|
|
return NAND_SHAPE
|
|
|
|
|
case 'input':
|
|
|
|
|
case 'high':
|
|
|
|
|
case 'low':
|
|
|
|
|
case 'button':
|
|
|
|
|
return SOURCE_SHAPE
|
|
|
|
|
case 'clock':
|
|
|
|
|
return CLOCK_SHAPE
|
|
|
|
|
case 'output':
|
|
|
|
|
case 'lamp':
|
|
|
|
|
return SINK_SHAPE
|
|
|
|
|
case 'hex':
|
|
|
|
|
return HEX_SHAPE
|
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
|
|
|
case 'panel':
|
|
|
|
|
return panelShape(node)
|
2026-10-20 17:29:16 +00:00
|
|
|
case 'bundle':
|
|
|
|
|
case 'split':
|
|
|
|
|
return cableShape(node)
|
|
|
|
|
case 'pixel':
|
|
|
|
|
return PIXEL_SHAPE
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
case 'tag':
|
|
|
|
|
return tagShape(node)
|
|
|
|
|
case 'ref':
|
|
|
|
|
return refShape(node)
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'note': {
|
|
|
|
|
const lines = noteLines(node)
|
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 k = noteScale(node)
|
|
|
|
|
const w = Math.max(2, Math.ceil(Math.max(...lines.map(l => l.length)) * NAME_CHAR * k + 1))
|
|
|
|
|
return { body: { x: 0, y: -0.75 * k, w, h: (lines.length + 0.5) * k }, inputs: [], outputs: [] }
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
case 'chip': {
|
|
|
|
|
const def = node.chip ? getDef(node.chip) : undefined
|
|
|
|
|
if (!def) return MISSING_SHAPE
|
|
|
|
|
const pins = chipPins(def)
|
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 face = faceLayout(def)
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (def.design) return designedShape(def, pins, face)
|
2026-10-20 18:09:23 +00:00
|
|
|
if (def.symbol !== 'box' && !face.items.length && pins.outputs.length === 1 && pins.inputs.length >= 1 && pins.inputs.length <= 16) {
|
2026-10-17 10:49:38 +00:00
|
|
|
return gateShape(def.symbol, pins.inputs, pins.outputs[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
|
|
|
return boxShape(def.name, pins, face)
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function pinPos(node: CircuitNode, shape: Shape, key: string, dir: 'in' | 'out') {
|
|
|
|
|
const pin = (dir === 'in' ? shape.inputs : shape.outputs).find(p => p.key === key)
|
|
|
|
|
return pin ? { x: node.x + pin.dx, y: node.y + pin.dy } : undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type Pt = [number, 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
|
|
|
/** Drop repeated points and points in the middle of a straight run (or a spike that doubles back). */
|
2026-10-17 10:49:38 +00:00
|
|
|
export function simplify(pts: Pt[]): Pt[] {
|
|
|
|
|
const out: Pt[] = []
|
|
|
|
|
for (const p of pts) {
|
|
|
|
|
out.push(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
|
|
|
for (;;) {
|
|
|
|
|
const n = out.length
|
|
|
|
|
const [a, b, c] = [out[n - 3], out[n - 2], out[n - 1]!]
|
|
|
|
|
if (b && b[0] === c[0] && b[1] === c[1]) out.splice(n - 2, 1)
|
|
|
|
|
else if (a && b && ((a[0] === b[0] && b[0] === c[0]) || (a[1] === b[1] && b[1] === c[1]))) out.splice(n - 2, 1)
|
|
|
|
|
else break
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Orthogonal route from an output pin to an input pin, as a list of points.
|
|
|
|
|
* With corner points set, the route runs through them. Otherwise forward
|
|
|
|
|
* wires get one vertical segment halfway; backward wires (feedback loops) go
|
|
|
|
|
* out to the right, around, and back in from the left.
|
|
|
|
|
*/
|
|
|
|
|
export function routeWire(a: Pt, b: Pt, corners?: Pt[]): Pt[] {
|
|
|
|
|
const [x1, y1] = a
|
|
|
|
|
const [x2, y2] = b
|
|
|
|
|
if (corners?.length) {
|
|
|
|
|
const out: Pt[] = [a]
|
|
|
|
|
let prev = a
|
|
|
|
|
for (const p of corners) {
|
|
|
|
|
if (p[0] !== prev[0] && p[1] !== prev[1]) out.push([p[0], prev[1]])
|
|
|
|
|
out.push(p)
|
|
|
|
|
prev = p
|
|
|
|
|
}
|
|
|
|
|
if (b[0] !== prev[0] && b[1] !== prev[1]) out.push([prev[0], b[1]])
|
|
|
|
|
out.push(b)
|
|
|
|
|
return simplify(out)
|
|
|
|
|
}
|
|
|
|
|
if (y1 === y2 && x2 > x1) return [a, b]
|
|
|
|
|
if (x2 >= x1 + 1) {
|
|
|
|
|
const m = Math.round((x1 + x2) / 2)
|
|
|
|
|
return [a, [m, y1], [m, y2], b]
|
|
|
|
|
}
|
|
|
|
|
const ym = Math.abs(y2 - y1) >= 3 ? Math.round((y1 + y2) / 2) : Math.max(y1, y2) + 2
|
|
|
|
|
return [a, [x1 + 1, y1], [x1 + 1, ym], [x2 - 1, ym], [x2 - 1, y2], b]
|
|
|
|
|
}
|