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.
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
import type { CircuitNode, ComponentDef, ConnectorType, 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-22 16:59:56 +00:00
|
|
|
/** A port of a connector type: only joins a port of the same type (and is a cable pin). */
|
|
|
|
|
conn?: string
|
|
|
|
|
/** Side the wire leaves (outputs) or arrives from (inputs): 1 right, -1 left. Default: outputs right, inputs left. */
|
|
|
|
|
face?: 1 | -1
|
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 {
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
/** Node id inside the component; for a screen, the first pixel's; a path (chip/…/node) for a display inside. */
|
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
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
/** What a design calls it: the node id, 'screen' or 'screen:<name>', or '<chip node id>/<its key>'. */
|
|
|
|
|
key: string
|
|
|
|
|
/** Size and turn from a hand-drawn box. */
|
|
|
|
|
scale?: number
|
|
|
|
|
rotate?: number
|
|
|
|
|
/** A display of a component inside: that component's name. */
|
|
|
|
|
from?: 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
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
/** Finds a component by id; `conn` finds a connector type (set by `lookup(project)`). */
|
|
|
|
|
export type DefLookup = ((id: string) => ComponentDef | undefined) & { conn?: (id: string) => ConnectorType | undefined }
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
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 }[]
|
2026-10-22 16:59:56 +00:00
|
|
|
/** Connector ports, top to bottom: "in" ones sit with the inputs, "out" ones with the outputs. */
|
|
|
|
|
ports?: PortPin[]
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
export interface PortPin {
|
|
|
|
|
/** The port node's id inside the component. */
|
|
|
|
|
key: string
|
|
|
|
|
label: string
|
|
|
|
|
conn: string
|
|
|
|
|
side: 'in' | 'out'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** What a pin plugs into: '' a single wire, 'bus' a cable end, 'c:<id>' a port of that connector type. */
|
|
|
|
|
export const pinKindOf = (p: { bus?: boolean; conn?: string }) => (p.conn ? `c:${p.conn}` : p.bus ? 'bus' : '')
|
|
|
|
|
|
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)
|
2026-10-21 12:38:59 +00:00
|
|
|
// Outputs: output pins and the rows of output panels.
|
|
|
|
|
const outputs: { key: string; label: string; x: number; y: number }[] = []
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
if (n.kind === 'output') outputs.push({ key: n.id, label: n.label?.trim() ?? '', x: n.x, y: n.y })
|
|
|
|
|
else if (n.kind === 'outpanel' && !n.inner) {
|
|
|
|
|
const rows = n.rows ?? []
|
|
|
|
|
const at = panelOffsets(rows)
|
|
|
|
|
rows.forEach((r, i) => outputs.push({ key: rowPin(n.id, r.id), label: r.label?.trim() || r.name?.trim() || '', x: n.x, y: n.y + at[i]! }))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
outputs.sort((a, b) => a.y - b.y || a.x - b.x)
|
2026-10-22 16:59:56 +00:00
|
|
|
const ports = def.nodes
|
|
|
|
|
.filter(n => (n.kind === 'portin' || n.kind === 'portout') && n.conn)
|
|
|
|
|
.sort((a, b) => a.y - b.y || a.x - b.x)
|
|
|
|
|
.map(n => ({ key: n.id, label: n.label?.trim() ?? '', conn: n.conn!, side: n.kind === 'portin' ? ('in' as const) : ('out' as const) }))
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
return {
|
|
|
|
|
inputs: inputs.map((p, i) => ({ key: p.key, label: p.label || `in${i + 1}` })),
|
2026-10-21 12:38:59 +00:00
|
|
|
outputs: outputs.map((p, i) => ({ key: p.key, label: p.label || `out${i + 1}` })),
|
2026-10-22 16:59:56 +00:00
|
|
|
...(ports.length ? { ports } : {}),
|
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
|
|
|
}
|
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
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
return autoFace(def, ownFaceItems(def))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The lamps, displays and screens of a component itself, before they are laid out. */
|
|
|
|
|
function ownFaceItems(def: ComponentDef): FaceItem[] {
|
|
|
|
|
const items: FaceItem[] = []
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
if (n.kind !== 'lamp' && n.kind !== 'hex') continue
|
|
|
|
|
const label = n.label?.trim() ?? ''
|
|
|
|
|
const w = Math.max(n.kind === 'hex' ? 1.6 : 1.4, label.length * FACE_CHAR + 0.4)
|
|
|
|
|
const h = (n.kind === 'hex' ? 2.2 : 1.2) + (label ? 0.7 : 0)
|
|
|
|
|
items.push({ id: n.id, key: n.id, kind: n.kind, label, color: n.color, x: n.x, y: n.y, w, h })
|
|
|
|
|
}
|
|
|
|
|
return [...items, ...screenLayouts(def)]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lays the items out the way they sit inside: lamps and displays at about
|
|
|
|
|
* the same height share a row, screens go below.
|
|
|
|
|
*/
|
|
|
|
|
function autoFace(def: ComponentDef, all: FaceItem[]): { items: FaceItem[]; w: number; h: number } {
|
|
|
|
|
const empty = { items: [], w: 0, h: 0 }
|
|
|
|
|
void def
|
|
|
|
|
// The x and y of an item here are where its node sits inside, used for ordering.
|
|
|
|
|
const nodes = all.filter(it => it.kind !== 'screen').sort((a, b) => a.y - b.y || a.x - b.x)
|
|
|
|
|
const rows: FaceItem[][] = []
|
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 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) {
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
items.push({ ...n, x, y })
|
|
|
|
|
x += n.w + 0.3
|
|
|
|
|
h = Math.max(h, n.h)
|
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
|
|
|
}
|
|
|
|
|
w = Math.max(w, x - 0.3)
|
|
|
|
|
y += h + 0.3
|
|
|
|
|
}
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
for (const screen of all.filter(it => it.kind === 'screen')) {
|
2026-10-20 17:29:16 +00:00
|
|
|
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 }
|
|
|
|
|
}
|
|
|
|
|
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
/**
|
|
|
|
|
* What a component shows on its box, for a component placed inside another
|
|
|
|
|
* one to offer: the items its own design shows (or all, laid out
|
|
|
|
|
* automatically), including displays of components inside it it shows.
|
|
|
|
|
*/
|
|
|
|
|
function shownItems(def: ComponentDef, get: DefLookup, depth: number): FaceItem[] {
|
|
|
|
|
if (def.face === false || depth > 4) return []
|
|
|
|
|
const d = def.design
|
|
|
|
|
const hide = new Set(d?.hide ?? [])
|
|
|
|
|
const own = ownFaceItems(def).filter(it => !hide.has(it.key))
|
|
|
|
|
if (!d?.show?.length) return own
|
|
|
|
|
const show = new Set(d.show)
|
|
|
|
|
return [...own, ...nestedItems(def, get, depth).filter(it => show.has(it.key))]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Everything a component's box can show, for the box designer: its own
|
|
|
|
|
* lamps, displays and screens (shown unless left off), and the displays of
|
|
|
|
|
* components inside it (left off unless shown).
|
|
|
|
|
*/
|
|
|
|
|
export function faceCandidates(def: ComponentDef, get: DefLookup): { key: string; label: string; kind: FaceItem['kind']; nested: boolean }[] {
|
|
|
|
|
if (def.face === false) return []
|
|
|
|
|
const own = ownFaceItems(def).map(it => ({ key: it.key, label: it.label || (it.kind === 'screen' ? 'Screen' : it.kind === 'hex' ? 'Display' : 'Lamp'), kind: it.kind, nested: false }))
|
|
|
|
|
const nested = nestedItems(def, get).map(it => ({ key: it.key, label: [it.from, it.label].filter(Boolean).join(' ') || it.kind, kind: it.kind, nested: true }))
|
|
|
|
|
return [...own, ...nested]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A box item's size and turn, as an SVG transform: grown from its top left corner, turned around its middle. */
|
|
|
|
|
export function faceTransform(f: FaceItem): string | undefined {
|
|
|
|
|
if (!f.scale && !f.rotate) return undefined
|
|
|
|
|
const k = f.scale ?? 1
|
|
|
|
|
const x = f.x * GRID
|
|
|
|
|
const y = f.y * GRID
|
|
|
|
|
const cx = x + (f.w * k * GRID) / 2
|
|
|
|
|
const cy = y + (f.h * k * GRID) / 2
|
|
|
|
|
return `${f.rotate ? `rotate(${f.rotate} ${cx} ${cy}) ` : ''}translate(${x} ${y}) scale(${k}) translate(${-x} ${-y})`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A drawing on a box turned around its middle, as an SVG transform. */
|
|
|
|
|
export function shapeTransform(d: FaceShape): string | undefined {
|
|
|
|
|
if (!d.rotate) return undefined
|
|
|
|
|
const w = d.kind === 'text' ? (d.text?.length ?? 1) * 0.42 * (d.size ?? 1) : d.w
|
|
|
|
|
const h = d.kind === 'text' ? (d.size ?? 1) : d.h
|
|
|
|
|
return `rotate(${d.rotate} ${(d.x + w / 2) * GRID} ${(d.y + h / 2) * GRID})`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Displays of the components inside one: each keyed by its chip node and its own key there. */
|
|
|
|
|
export function nestedItems(def: ComponentDef, get: DefLookup, depth = 0): FaceItem[] {
|
|
|
|
|
const out: FaceItem[] = []
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
if (n.kind !== 'chip' || !n.chip || n.chip === def.id) continue
|
|
|
|
|
const child = get(n.chip)
|
|
|
|
|
if (!child) continue
|
|
|
|
|
const name = n.label?.trim() || child.name
|
|
|
|
|
for (const it of shownItems(child, get, depth + 1)) {
|
|
|
|
|
out.push({
|
|
|
|
|
...it,
|
|
|
|
|
id: `${n.id}/${it.id}`,
|
|
|
|
|
key: `${n.id}/${it.key}`,
|
|
|
|
|
// On the box it keeps its own name; the designer lists it with the part's.
|
|
|
|
|
from: name,
|
|
|
|
|
pixels: it.pixels?.map(p => ({ ...p, id: `${n.id}/${p.id}` })),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
return screenLayouts(def)[0] ?? null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Pixels make one screen per screen name (those without a name the main screen, listed first). */
|
|
|
|
|
export function screenLayouts(def: ComponentDef): FaceItem[] {
|
|
|
|
|
const groups = new Map<string, CircuitNode[]>()
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
if (n.kind !== 'pixel') continue
|
|
|
|
|
const g = n.screen?.trim() ?? ''
|
|
|
|
|
groups.set(g, [...(groups.get(g) ?? []), n])
|
|
|
|
|
}
|
|
|
|
|
return [...groups.entries()]
|
|
|
|
|
.sort(([a], [b]) => (a === '' ? -1 : b === '' ? 1 : a.localeCompare(b)))
|
|
|
|
|
.map(([name, pixels]) => screenOf(pixels, name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function screenOf(pixels: CircuitNode[], name: string): FaceItem {
|
2026-10-20 17:29:16 +00:00
|
|
|
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,
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
key: name ? `screen:${name}` : 'screen',
|
2026-10-20 17:29:16 +00:00
|
|
|
kind: 'screen',
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
label: name,
|
|
|
|
|
x: Math.min(...pixels.map(n => n.x)),
|
|
|
|
|
y: Math.min(...pixels.map(n => n.y)),
|
2026-10-20 17:29:16 +00:00
|
|
|
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.
|
|
|
|
|
*/
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
function designedShape(def: ComponentDef, pins: ChipPins, face: ReturnType<typeof faceLayout>, get: DefLookup): Shape {
|
2026-10-22 16:59:56 +00:00
|
|
|
const auto = boxShape(def.name, pins, face, get)
|
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 d = def.design!
|
|
|
|
|
const top = auto.body.y
|
|
|
|
|
const hide = new Set(d.hide ?? [])
|
|
|
|
|
const place = d.place ?? {}
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
// Pins on their edges: where they were put, the others one row under the pin above.
|
|
|
|
|
const placePins = <P extends PinInfo>(list: P[]) => {
|
|
|
|
|
let prev = -Infinity
|
|
|
|
|
return list.map(p => {
|
|
|
|
|
const want = d.pinAt?.[p.key]
|
|
|
|
|
const dy = Math.max(want ?? (prev === -Infinity ? p.dy : prev + 1), prev + 1, 0)
|
|
|
|
|
prev = dy
|
|
|
|
|
return { ...p, dy }
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const inputs = placePins(auto.inputs)
|
|
|
|
|
const lowest = Math.max(0, ...inputs.map(p => p.dy), ...auto.outputs.map(p => d.pinAt?.[p.key] ?? p.dy))
|
|
|
|
|
const w = Math.max(2, d.w)
|
|
|
|
|
const outputs = placePins(auto.outputs).map(p => ({ ...p, dx: w }))
|
|
|
|
|
const bottom = Math.max(...inputs.map(p => p.dy), ...outputs.map(p => p.dy), lowest)
|
|
|
|
|
const h = Math.max(d.h, bottom - top + 0.5, 2)
|
|
|
|
|
// Own items where auto layout put them unless placed; displays of parts inside only when shown.
|
|
|
|
|
const show = new Set(d.show ?? [])
|
|
|
|
|
const nested = nestedItems(def, get).filter(it => show.has(it.key))
|
|
|
|
|
let below = (auto.face ?? []).reduce((m, it) => Math.max(m, it.y + it.h), auto.body.y + auto.body.h - 0.6) + 0.3
|
|
|
|
|
const items = [
|
|
|
|
|
...(auto.face ?? []),
|
|
|
|
|
...nested.map(it => {
|
|
|
|
|
const at = { ...it, x: 0.6, y: below }
|
|
|
|
|
below += it.h + 0.3
|
|
|
|
|
return at
|
|
|
|
|
}),
|
|
|
|
|
]
|
|
|
|
|
const shown = items
|
|
|
|
|
.filter(it => !hide.has(it.key))
|
|
|
|
|
.map(it => {
|
|
|
|
|
const at = place[it.key]
|
|
|
|
|
const scale = d.scale?.[it.key]
|
|
|
|
|
const rotate = d.rotate?.[it.key]
|
|
|
|
|
return { ...it, ...(at ? { x: at.x, y: top + at.y } : {}), ...(scale ? { scale } : {}), ...(rotate ? { rotate } : {}) }
|
|
|
|
|
})
|
|
|
|
|
// The box is never smaller than what it shows (sized and turned as shown).
|
|
|
|
|
let right = w
|
|
|
|
|
let floor = top + h
|
|
|
|
|
for (const it of shown) {
|
|
|
|
|
const k = it.scale ?? 1
|
|
|
|
|
const turned = it.rotate === 90 || it.rotate === 270
|
|
|
|
|
const iw = (turned ? it.h : it.w) * k
|
|
|
|
|
const ih = (turned ? it.w : it.h) * k
|
|
|
|
|
const cx = it.x + (it.w * k) / 2
|
|
|
|
|
const cy = it.y + (it.h * k) / 2
|
|
|
|
|
right = Math.max(right, cx + iw / 2 + 0.3)
|
|
|
|
|
floor = Math.max(floor, cy + ih / 2 + 0.3)
|
|
|
|
|
}
|
|
|
|
|
const bw = Math.ceil(right * 2) / 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
|
|
|
return {
|
|
|
|
|
...auto,
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
inputs,
|
|
|
|
|
outputs: bw === w ? outputs : outputs.map(p => ({ ...p, dx: bw })),
|
|
|
|
|
body: { x: 0, y: top, w: bw, h: Math.ceil((floor - top) * 2) / 2 },
|
|
|
|
|
face: shown,
|
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
|
|
|
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 })),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
function boxShape(name: string, plain: ChipPins, face: ReturnType<typeof faceLayout>, get?: DefLookup): Shape {
|
|
|
|
|
// Ports sit below the single pins of their side, as one cable pin each.
|
|
|
|
|
const port = (side: 'in' | 'out') =>
|
|
|
|
|
(plain.ports ?? [])
|
|
|
|
|
.filter(p => p.side === side)
|
|
|
|
|
.map(p => ({ key: p.key, label: p.label || get?.conn?.(p.conn)?.name || 'port', bus: true, conn: p.conn }))
|
|
|
|
|
const pins = { inputs: [...plain.inputs, ...port('in')], outputs: [...plain.outputs, ...port('out')] }
|
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() ?? ''
|
|
|
|
|
|
2026-10-21 12:38:59 +00:00
|
|
|
/** Output panel: a lamp per row with its name, the wire in on the left and on again on the right. */
|
|
|
|
|
function outPanelShape(node: CircuitNode): Shape {
|
|
|
|
|
const rows = node.rows ?? []
|
|
|
|
|
const dys = panelOffsets(rows)
|
|
|
|
|
const labels = rows.map(rowLabel)
|
|
|
|
|
const w = Math.max(3, Math.ceil(labels.reduce((m, l) => Math.max(m, l.length), 0) * LABEL_CHAR + 2.4))
|
|
|
|
|
const last = dys.length ? dys[dys.length - 1]! : 0
|
|
|
|
|
return {
|
|
|
|
|
body: { x: 0, y: -0.5, w, h: last + 1 },
|
|
|
|
|
inputs: rows.map((r, i) => ({ key: r.id, label: labels[i]!, dx: 0, dy: dys[i]! })),
|
|
|
|
|
outputs: rows.map((r, i) => ({ key: r.id, label: labels[i]!, dx: w, dy: dys[i]! })),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** 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-22 16:59:56 +00:00
|
|
|
/**
|
|
|
|
|
* The lines of a port, each with whether its signal comes into the circuit
|
|
|
|
|
* through this port (and so is an output pin of the port part) or leaves it
|
|
|
|
|
* (an input pin). An in port brings the forward lines in and sends the back
|
|
|
|
|
* lines out; an out port the other way round.
|
|
|
|
|
*/
|
|
|
|
|
export function portLines(node: CircuitNode, get: DefLookup): { name: string; enters: boolean; key: string }[] {
|
|
|
|
|
const type = node.conn ? get.conn?.(node.conn) : undefined
|
|
|
|
|
return (type?.lines ?? []).map((l, i) => ({ name: l.name, enters: (node.kind === 'portin') !== !!l.back, key: `l${i}` }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A port inside a component: on its inner side, a pin per line (outputs for
|
|
|
|
|
* lines coming in, inputs for lines going out) and, at the top, a cable pin
|
|
|
|
|
* that passes the whole cable on to a part inside with the same port. An in
|
|
|
|
|
* port sits on the left of a circuit and faces right; an out port the reverse.
|
|
|
|
|
*/
|
|
|
|
|
function portShape(node: CircuitNode, get: DefLookup): Shape {
|
|
|
|
|
const lines = portLines(node, get)
|
|
|
|
|
// Wide enough for the longest line name, and for the title: "<type> in · <name>".
|
|
|
|
|
const title = `${(node.conn && get.conn?.(node.conn)?.name) || 'Port'} out${node.label?.trim() ? ` · ${node.label.trim()}` : ''}`
|
|
|
|
|
const w = Math.max(4, Math.ceil(lines.reduce((m, l) => Math.max(m, l.name.length), 0) * LABEL_CHAR + 2.6), Math.ceil(title.length * 0.42 + 1.2))
|
|
|
|
|
const inner = node.kind === 'portin' ? w : 0
|
|
|
|
|
const face: 1 | -1 = node.kind === 'portin' ? 1 : -1
|
|
|
|
|
const bus: PinInfo = { key: 'bus', label: '', dx: inner, dy: 0, bus: true, conn: node.conn }
|
|
|
|
|
const pins = lines.map((l, i) => ({ key: l.key, label: l.name, dx: inner, dy: i + 1, face }))
|
|
|
|
|
return {
|
|
|
|
|
body: { x: 0, y: -0.75, w, h: lines.length + 1.5 },
|
|
|
|
|
inputs: node.kind === 'portin' ? pins.filter((_, i) => !lines[i]!.enters) : [bus, ...pins.filter((_, i) => !lines[i]!.enters)],
|
|
|
|
|
outputs: node.kind === 'portin' ? [bus, ...pins.filter((_, i) => lines[i]!.enters)] : pins.filter((_, i) => lines[i]!.enters),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2026-10-21 12:38:59 +00:00
|
|
|
case 'outpanel':
|
|
|
|
|
return outPanelShape(node)
|
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)
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
if (def.design) return designedShape(def, pins, face, getDef)
|
2026-10-22 16:59:56 +00:00
|
|
|
if (def.symbol !== 'box' && !face.items.length && !pins.ports && 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]!)
|
|
|
|
|
}
|
2026-10-22 16:59:56 +00:00
|
|
|
return boxShape(def.name, pins, face, getDef)
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
2026-10-22 16:59:56 +00:00
|
|
|
case 'portin':
|
|
|
|
|
case 'portout':
|
|
|
|
|
return portShape(node, getDef)
|
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)
|
2026-10-22 16:59:56 +00:00
|
|
|
return pin ? { x: node.x + pin.dx, y: node.y + pin.dy, face: pin.face ?? (dir === 'in' ? -1 : 1) } : undefined
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2026-10-22 16:59:56 +00:00
|
|
|
export function routeWire(a: Pt, b: Pt, corners?: Pt[], aFace: 1 | -1 = 1, bFace: 1 | -1 = -1): Pt[] {
|
2026-10-17 10:49:38 +00:00
|
|
|
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)
|
|
|
|
|
}
|
2026-10-22 16:59:56 +00:00
|
|
|
// Pins that face the other way (the inner pins of ports): out the side the
|
|
|
|
|
// source faces, in from the side the target faces.
|
|
|
|
|
if (aFace === -1 && bFace === 1) return routeWire([-x1, y1], [-x2, y2]).map(([x, y]) => [-x, y] as Pt)
|
|
|
|
|
if (aFace === bFace) {
|
|
|
|
|
const x = aFace === 1 ? Math.max(x1, x2) + 1 : Math.min(x1, x2) - 1
|
|
|
|
|
return simplify([a, [x, y1], [x, y2], b])
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
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]
|
|
|
|
|
}
|