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-28 12:30:07 +00:00
|
|
|
import { benchLayout } from './benchLayout'
|
2026-10-28 12:35:04 +00:00
|
|
|
import { scopeLayout } from './scopeLayout'
|
2026-10-28 12:05:57 +00:00
|
|
|
import { DATA_KEYS, DEVICE_PIN_NAMES } from './devices'
|
2026-10-28 12:47:14 +00:00
|
|
|
import { displayLayout, displayPins } from './displays'
|
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
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
/** A line of a port split on a component's box: the port's key. */
|
|
|
|
|
port?: string
|
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-28 11:51:09 +00:00
|
|
|
/** What an RGB pixel shows for its red, green and blue inputs (index r + 2g + 4b); black is off. */
|
|
|
|
|
export const RGB_HEX = ['', '#ff4d4d', '#3ddc84', '#ffe04d', '#4d7dff', '#ff5cf0', '#4de8ff', '#f2f6fa'] as const
|
|
|
|
|
export const rgbHex = (r: number, g: number, b: number) => RGB_HEX[(r ? 1 : 0) + (g ? 2 : 0) + (b ? 4 : 0)]!
|
|
|
|
|
|
2026-10-20 17:29:16 +00:00
|
|
|
export interface ScreenPixel {
|
|
|
|
|
/** Pixel node id inside the component. */
|
|
|
|
|
id: string
|
2026-10-28 11:51:09 +00:00
|
|
|
/** Lit by its red, green and blue inputs. */
|
|
|
|
|
rgb?: boolean
|
2026-10-20 17:29:16 +00:00
|
|
|
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
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
/** A pixel shown on its own: the key of the screen it is part of. */
|
|
|
|
|
screenOf?: 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}`
|
|
|
|
|
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
/** What a port is called on a component's box: its own name, else its connector type's. */
|
|
|
|
|
export const portName = (p: PortPin, get?: DefLookup) => p.label || get?.conn?.(p.conn)?.name || 'port'
|
|
|
|
|
|
|
|
|
|
/** Pin key of a line of a port split on a component's box: port.line (a dot, so it never reads as a panel row). */
|
|
|
|
|
export const linePin = (port: string, line: string) => `${port}.${line}`
|
|
|
|
|
|
|
|
|
|
export interface SplitLine {
|
|
|
|
|
/** Pin key on the box. */
|
|
|
|
|
key: string
|
|
|
|
|
name: string
|
|
|
|
|
/** The port's key, and the line's place in its connector type. */
|
|
|
|
|
port: string
|
|
|
|
|
index: number
|
|
|
|
|
/** The line goes into the component (an input pin on the box); otherwise it comes out (an output). */
|
|
|
|
|
enters: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The lines of the ports split on a placed component's box, top to bottom,
|
|
|
|
|
* as pins of their own: inputs for lines going into the component, outputs
|
|
|
|
|
* for lines coming out. An in port brings its forward lines in, an out port
|
|
|
|
|
* its back lines.
|
|
|
|
|
*/
|
|
|
|
|
export function splitLines(node: CircuitNode, pins: ChipPins, get?: DefLookup): SplitLine[] {
|
|
|
|
|
if (!node.splitPorts?.length) return []
|
|
|
|
|
const split = new Set(node.splitPorts)
|
|
|
|
|
const out: SplitLine[] = []
|
|
|
|
|
for (const p of pins.ports ?? []) {
|
|
|
|
|
if (!split.has(p.key)) continue
|
|
|
|
|
get?.conn?.(p.conn)?.lines.forEach((l, i) => out.push({ key: linePin(p.key, `l${i}`), name: l.name, port: p.key, index: i, enters: (p.side === 'in') !== !!l.back }))
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** 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 ?? [])
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
// As its own box shows them: turned and sized the same, screens split into pixels where it does.
|
|
|
|
|
const looks = (it: FaceItem): FaceItem => ({
|
|
|
|
|
...it,
|
|
|
|
|
...(d?.scale?.[it.key] ? { scale: d.scale[it.key] } : {}),
|
|
|
|
|
...(d?.rotate?.[it.key] ? { rotate: d.rotate[it.key] } : {}),
|
|
|
|
|
})
|
|
|
|
|
const own = splitScreens(ownFaceItems(def), new Set(d?.split ?? [])).filter(it => !hide.has(it.key)).map(looks)
|
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 (!d?.show?.length) return own
|
|
|
|
|
const show = new Set(d.show)
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
return [...own, ...nestedItems(def, get, depth).filter(it => show.has(it.key)).map(looks)]
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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]
|
|
|
|
|
}
|
|
|
|
|
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
/** The key of one pixel of a screen shown pixel by pixel. */
|
|
|
|
|
export const pixelKey = (pixelId: string) => `px:${pixelId}`
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Screens listed in `split` shown pixel by pixel: each pixel its own item,
|
|
|
|
|
* where it sat in the screen (sized and turned as the screen was, `looks`),
|
|
|
|
|
* so splitting moves nothing.
|
|
|
|
|
*/
|
|
|
|
|
export function splitScreens(items: FaceItem[], split: Set<string>, looks: (key: string) => { scale?: number; rotate?: number } = () => ({})): FaceItem[] {
|
|
|
|
|
if (!split.size) return items
|
|
|
|
|
return items.flatMap(it => {
|
|
|
|
|
if (it.kind !== 'screen' || !split.has(it.key) || !it.pixels || !it.px) return [it]
|
|
|
|
|
const { scale, rotate } = { scale: it.scale, rotate: it.rotate, ...looks(it.key) }
|
|
|
|
|
const k = scale ?? 1
|
|
|
|
|
const px = it.px!
|
|
|
|
|
// The screen's middle; each pixel's middle turned around it.
|
|
|
|
|
const cx = it.x + (it.w * k) / 2
|
|
|
|
|
const cy = it.y + (it.h * k) / 2
|
|
|
|
|
const turn = (((rotate ?? 0) % 360) + 360) % 360
|
|
|
|
|
return it.pixels.map(p => {
|
|
|
|
|
let dx = (p.col + 0.5) * px * k - (it.w * k) / 2
|
|
|
|
|
let dy = (p.row + 0.5) * px * k - (it.h * k) / 2
|
|
|
|
|
for (let a = 0; a < turn; a += 90) [dx, dy] = [-dy, dx]
|
|
|
|
|
const item: FaceItem = {
|
|
|
|
|
...it,
|
|
|
|
|
id: p.id,
|
|
|
|
|
key: pixelKey(p.id),
|
|
|
|
|
label: '',
|
|
|
|
|
x: cx + dx - (px * k) / 2,
|
|
|
|
|
y: cy + dy - (px * k) / 2,
|
|
|
|
|
w: px,
|
|
|
|
|
h: px,
|
|
|
|
|
pixels: [{ ...p, col: 0, row: 0 }],
|
|
|
|
|
screenOf: it.key,
|
|
|
|
|
}
|
|
|
|
|
delete item.rotate
|
|
|
|
|
if (k !== 1) item.scale = k
|
|
|
|
|
else delete item.scale
|
|
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/** 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,
|
2026-10-28 11:51:09 +00:00
|
|
|
pixels: pixels.map(n => ({ id: n.id, col: col.get(n.x)!, row: row.get(n.y)!, color: n.color, ...(n.rgb ? { rgb: true } : {}) })),
|
2026-10-20 17:29:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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 ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
function designedShape(def: ComponentDef, pins: ChipPins, face: ReturnType<typeof faceLayout>, get: DefLookup, node?: CircuitNode): Shape {
|
|
|
|
|
const auto = boxShape(def.name, pins, face, get, node)
|
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 ?? {}
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
// Pins on each edge, top to bottom (in the order set, else as they come): where they were put, the others one row under the pin above.
|
|
|
|
|
const order = new Map((d.pinOrder ?? []).map((k, i) => [k, i]))
|
|
|
|
|
const rank = (p: PinInfo) => order.get(p.key) ?? 1e6 + p.dy
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
const placePins = (list: PinInfo[]) => {
|
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
|
|
|
let prev = -Infinity
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
// The first pin takes the edge's first row, whichever pin that is.
|
|
|
|
|
const first = Math.min(...list.map(p => p.dy))
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
return list
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
.sort((a, b) => rank(a) - rank(b) || a.dy - b.dy)
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
.map(p => {
|
|
|
|
|
const want = d.pinAt?.[p.key]
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
const dy = Math.max(want ?? (prev === -Infinity ? first : prev + 1), prev + 1, 0)
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
prev = dy
|
|
|
|
|
return [p.key, dy] as const
|
|
|
|
|
})
|
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
|
|
|
}
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
const edgePins = [...auto.inputs, ...auto.outputs]
|
|
|
|
|
const rightPins = edgePins.filter(p => p.dx > 0)
|
|
|
|
|
const rows = new Map([...placePins(edgePins.filter(p => p.dx === 0)), ...placePins(rightPins)])
|
|
|
|
|
const lowest = Math.max(0, ...rightPins.map(p => d.pinAt?.[p.key] ?? p.dy))
|
|
|
|
|
const bottom = Math.max(lowest, ...rows.values())
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
// Fitted: as wide as its pin names and its name need, as high as its pins; what it shows makes it bigger.
|
|
|
|
|
const longest = (ps: PinInfo[]) => ps.reduce((m, p) => Math.max(m, p.label.length), 0)
|
|
|
|
|
const labels = Math.ceil(longest(edgePins.filter(p => p.dx === 0)) * LABEL_CHAR + longest(rightPins) * LABEL_CHAR + (hide.has('name') || place.name ? 0 : def.name.length * NAME_CHAR) + 1.5)
|
|
|
|
|
const w = d.fit ? Math.max(2, labels) : Math.max(2, d.w)
|
|
|
|
|
const h = d.fit ? Math.max(bottom - top + 0.5, 2) : Math.max(d.h, bottom - top + 0.5, 2)
|
|
|
|
|
// Own items where the automatic layout put them unless placed; displays of parts inside only when shown,
|
|
|
|
|
// each in the first free spot unless placed. Screens split into pixels where asked: each pixel where it
|
|
|
|
|
// sat in the screen as placed, unless placed on its own.
|
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
|
|
|
const show = new Set(d.show ?? [])
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
const split = new Set(d.split ?? [])
|
|
|
|
|
const placed = (it: FaceItem): FaceItem => (place[it.key] ? { ...it, x: place[it.key]!.x, y: top + place[it.key]!.y } : it)
|
|
|
|
|
const sized = (it: FaceItem) => {
|
|
|
|
|
const k = d.scale?.[it.key] ?? it.scale ?? 1
|
|
|
|
|
const turned = (d.rotate?.[it.key] ?? it.rotate) === 90 || (d.rotate?.[it.key] ?? it.rotate) === 270
|
|
|
|
|
return { w: (turned ? it.h : it.w) * k, h: (turned ? it.w : it.h) * k }
|
|
|
|
|
}
|
|
|
|
|
const own = (auto.face ?? []).filter(it => !hide.has(it.key)).map(placed)
|
|
|
|
|
const nestedAll = nestedItems(def, get).filter(it => show.has(it.key) && !hide.has(it.key))
|
|
|
|
|
const taken: { x: number; y: number; w: number; h: number }[] = own.map(it => ({ x: it.x, y: it.y, ...sized(it) }))
|
|
|
|
|
// The name, where it shows.
|
|
|
|
|
if (!hide.has('name')) {
|
|
|
|
|
const nw = def.name.length * NAME_CHAR + 0.4
|
|
|
|
|
const c = place.name ? { x: place.name.x, y: top + place.name.y } : { x: w / 2, y: auto.nameY ?? 0 }
|
|
|
|
|
taken.push({ x: c.x - nw / 2, y: c.y - 0.55, w: nw, h: 1.1 })
|
|
|
|
|
}
|
|
|
|
|
for (const it of nestedAll) if (place[it.key]) taken.push({ x: place[it.key]!.x, y: top + place[it.key]!.y, ...sized(it) })
|
|
|
|
|
const labelL = longest(edgePins.filter(p => p.dx === 0)) * LABEL_CHAR + 0.6
|
|
|
|
|
const labelR = longest(rightPins) * LABEL_CHAR + 0.6
|
|
|
|
|
const nested = nestedAll.map(it => {
|
|
|
|
|
if (place[it.key]) return placed(it)
|
|
|
|
|
const spot = freeSpot(taken, sized(it), { x0: labelL, x1: Math.max(w - labelR, labelL + sized(it).w), y0: top + 0.3 })
|
|
|
|
|
taken.push({ ...spot, ...sized(it) })
|
|
|
|
|
return { ...it, ...spot }
|
|
|
|
|
})
|
|
|
|
|
const looks = (key: string) => ({ ...(d.scale?.[key] ? { scale: d.scale[key] } : {}), ...(d.rotate?.[key] ? { rotate: d.rotate[key] } : {}) })
|
|
|
|
|
const items = splitScreens([...own, ...nested], split, looks)
|
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
|
|
|
.filter(it => !hide.has(it.key))
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
.map(it => (it.screenOf ? placed(it) : it))
|
|
|
|
|
// Sized and turned as this box says, else as the part inside shows it.
|
|
|
|
|
const shown = items.map(it => {
|
|
|
|
|
const out: FaceItem = { ...it }
|
|
|
|
|
const scale = d.scale?.[it.key] ?? it.scale
|
|
|
|
|
const rotate = d.rotate?.[it.key] ?? it.rotate
|
|
|
|
|
if (scale) out.scale = scale
|
|
|
|
|
else delete out.scale
|
|
|
|
|
if (rotate) out.rotate = rotate
|
|
|
|
|
else delete out.rotate
|
|
|
|
|
return out
|
|
|
|
|
})
|
|
|
|
|
// The box is never smaller than what it shows (sized and turned as shown), its name and, fitted, 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
|
|
|
let right = w
|
|
|
|
|
let floor = top + h
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
if (d.fit) {
|
|
|
|
|
for (const sh of d.shapes ?? []) {
|
|
|
|
|
const tw = sh.kind === 'text' ? (sh.text?.length ?? 1) * 0.42 * (sh.size ?? 1) : 0
|
|
|
|
|
right = Math.max(right, sh.x + Math.max(sh.w, 0, tw) + 0.3)
|
|
|
|
|
floor = Math.max(floor, top + sh.y + Math.max(sh.h, 0, sh.kind === 'text' ? (sh.size ?? 1) : 0) + 0.3)
|
|
|
|
|
}
|
|
|
|
|
if (place.name && !hide.has('name')) right = Math.max(right, place.name.x + (def.name.length * NAME_CHAR) / 2 + 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 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
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
const onEdge = (p: PinInfo) => ({ ...p, dx: p.dx > 0 ? bw : 0, dy: rows.get(p.key)! })
|
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 ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
inputs: auto.inputs.map(onEdge),
|
|
|
|
|
outputs: auto.outputs.map(onEdge),
|
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
|
|
|
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 })),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
R box designer: size by the corner, reorder pins, pick and move several, pixels one by one, fitted boxes, displays from inside in free spots
- A picked lamp, display or screen has a size grip on its corner.
- A pin dragged onto or past its neighbour swaps places with it (the
order is kept in the design; boxes designed before keep theirs).
- Shift + click, or a box around things, picks several: dragged or moved
with the arrow keys together, drawings among them deleted together.
- A screen can be split into its pixels, each placed on its own (they
start where they sat, sized and turned as the screen was), or joined.
- New designs fit the box to what is on it (Fit, on and off): it shrinks
as well as grows. A size typed in turns it off.
- A display of a part inside lands in the first free spot inside the box
instead of under it, and keeps the size and turn its own box gives it.
- Pointing at a display from a part inside (in the designer and on the
placed box) says which part it is from.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-27 12:54:30 +00:00
|
|
|
/**
|
|
|
|
|
* The first spot for a thing of size `s`, going along rows from the top
|
|
|
|
|
* left, that keeps clear of everything taken; below them all when none is.
|
|
|
|
|
*/
|
|
|
|
|
function freeSpot(taken: { x: number; y: number; w: number; h: number }[], s: { w: number; h: number }, area: { x0: number; x1: number; y0: number }): { x: number; y: number } {
|
|
|
|
|
const gap = 0.3
|
|
|
|
|
const clear = (x: number, y: number) => taken.every(t => x + s.w + gap <= t.x || x >= t.x + t.w + gap || y + s.h + gap <= t.y || y >= t.y + t.h + gap)
|
|
|
|
|
const lowest = taken.reduce((m, t) => Math.max(m, t.y + t.h), area.y0)
|
|
|
|
|
for (let y = area.y0; y <= lowest; y += 0.25) {
|
|
|
|
|
for (let x = area.x0; x + s.w <= area.x1 + 1e-9; x += 0.25) if (clear(x, y)) return { x, y }
|
|
|
|
|
}
|
|
|
|
|
return { x: area.x0, y: lowest + gap }
|
|
|
|
|
}
|
|
|
|
|
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
/** A pin on one edge of a component's box, and whether a signal goes in or comes out there. */
|
|
|
|
|
interface EdgePin {
|
|
|
|
|
pin: Omit<PinInfo, 'dx' | 'dy'>
|
|
|
|
|
dir: 'in' | 'out'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function boxShape(name: string, plain: ChipPins, face: ReturnType<typeof faceLayout>, get?: DefLookup, node?: CircuitNode): Shape {
|
|
|
|
|
// Ports sit at the very top of their side, as one cable pin each. A port
|
|
|
|
|
// split on this box has a pin per line right below it, facing out of its side.
|
|
|
|
|
const lines = node ? splitLines(node, plain, get) : []
|
|
|
|
|
const edge = (side: 'in' | 'out'): EdgePin[] => {
|
|
|
|
|
const out: EdgePin[] = []
|
|
|
|
|
for (const p of plain.ports ?? []) {
|
|
|
|
|
if (p.side !== side) continue
|
|
|
|
|
out.push({ dir: side, pin: { key: p.key, label: portName(p, get), bus: true, conn: p.conn } })
|
|
|
|
|
for (const l of lines) {
|
|
|
|
|
if (l.port === p.key) out.push({ dir: l.enters ? 'in' : 'out', pin: { key: l.key, label: l.name, face: side === 'in' ? -1 : 1, port: p.key } })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const p of side === 'in' ? plain.inputs : plain.outputs) out.push({ dir: side, pin: p })
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
const left = edge('in')
|
|
|
|
|
const right = edge('out')
|
|
|
|
|
const n = Math.max(left.length, right.length, 1)
|
|
|
|
|
const longest = (ps: EdgePin[]) => ps.reduce((m, p) => Math.max(m, p.pin.label.length), 0)
|
2026-10-17 10:49:38 +00:00
|
|
|
const w = Math.max(
|
|
|
|
|
3,
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
Math.ceil(longest(left) * LABEL_CHAR + longest(right) * 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
|
|
|
)
|
BF split ports: no wire against the cable, pins that stay put, lines kept on unpack
A wire dropped on a socket with a cable in it only takes a line coming
out; the lines going in are the cable's, so it no longer drives one
against the cable. Wired by hand anyway, the check calls that an error,
like a signal sent by two parts. A line going in with neither a wire nor
a cable gets the usual "not connected (reads 0)" warning and marker.
While a wire is drawn over a socket it ends on the socket, where it goes
when let go, not on the pin below. Splitting or joining a port no longer
moves the pins on the other side of the box. Pins on their usual edge
come first, so a wire dropped on the box body takes those, and the cable
button only offers pins whose cable end sits outside the box.
Unpacking a component joins wires on its split lines to the parts that
used the line inside; wires that had nowhere to go are counted in a
notice. Docked panels line up with the moved ports when a project is
opened, not at the next edit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:38:32 +00:00
|
|
|
// An edge with ports starts at the top; one of single pins only is centred,
|
|
|
|
|
// on the box as it is without split lines, so splitting a port never moves it.
|
|
|
|
|
const unsplit = Math.max(...[left, right].map(ps => ps.filter(p => !p.pin.port).length), 1)
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
const place = (ps: EdgePin[], dx: number) => {
|
BF split ports: no wire against the cable, pins that stay put, lines kept on unpack
A wire dropped on a socket with a cable in it only takes a line coming
out; the lines going in are the cable's, so it no longer drives one
against the cable. Wired by hand anyway, the check calls that an error,
like a signal sent by two parts. A line going in with neither a wire nor
a cable gets the usual "not connected (reads 0)" warning and marker.
While a wire is drawn over a socket it ends on the socket, where it goes
when let go, not on the pin below. Splitting or joining a port no longer
moves the pins on the other side of the box. Pins on their usual edge
come first, so a wire dropped on the box body takes those, and the cable
button only offers pins whose cable end sits outside the box.
Unpacking a component joins wires on its split lines to the parts that
used the line inside; wires that had nowhere to go are counted in a
notice. Docked panels line up with the moved ports when a project is
opened, not at the next edit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:38:32 +00:00
|
|
|
const off = ps.some(p => p.pin.bus) ? 0 : Math.floor((unsplit - ps.length) / 2)
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
return ps.map((p, i) => ({ dir: p.dir, pin: { ...p.pin, dx, dy: off + i } }))
|
|
|
|
|
}
|
BF split ports: no wire against the cable, pins that stay put, lines kept on unpack
A wire dropped on a socket with a cable in it only takes a line coming
out; the lines going in are the cable's, so it no longer drives one
against the cable. Wired by hand anyway, the check calls that an error,
like a signal sent by two parts. A line going in with neither a wire nor
a cable gets the usual "not connected (reads 0)" warning and marker.
While a wire is drawn over a socket it ends on the socket, where it goes
when let go, not on the pin below. Splitting or joining a port no longer
moves the pins on the other side of the box. Pins on their usual edge
come first, so a wire dropped on the box body takes those, and the cable
button only offers pins whose cable end sits outside the box.
Unpacking a component joins wires on its split lines to the parts that
used the line inside; wires that had nowhere to go are counted in a
notice. Docked panels line up with the moved ports when a project is
opened, not at the next edit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:38:32 +00:00
|
|
|
// Each edge's own pins first: code that takes the first free input or output finds one on its usual edge.
|
|
|
|
|
const onLeft = place(left, 0)
|
|
|
|
|
const onRight = place(right, w)
|
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) },
|
BF split ports: no wire against the cable, pins that stay put, lines kept on unpack
A wire dropped on a socket with a cable in it only takes a line coming
out; the lines going in are the cable's, so it no longer drives one
against the cable. Wired by hand anyway, the check calls that an error,
like a signal sent by two parts. A line going in with neither a wire nor
a cable gets the usual "not connected (reads 0)" warning and marker.
While a wire is drawn over a socket it ends on the socket, where it goes
when let go, not on the pin below. Splitting or joining a port no longer
moves the pins on the other side of the box. Pins on their usual edge
come first, so a wire dropped on the box body takes those, and the cable
button only offers pins whose cable end sits outside the box.
Unpacking a component joins wires on its split lines to the parts that
used the line inside; wires that had nowhere to go are counted in a
notice. Docked panels line up with the moved ports when a project is
opened, not at the next edit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:38:32 +00:00
|
|
|
inputs: [...onLeft, ...onRight].filter(p => p.dir === 'in').map(p => p.pin),
|
|
|
|
|
outputs: [...onRight, ...onLeft].filter(p => p.dir === 'out').map(p => p.pin),
|
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: [],
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-28 11:51:09 +00:00
|
|
|
const PIXEL_RGB_SHAPE: Shape = {
|
|
|
|
|
body: { x: 0, y: -0.5, w: 1, h: 3 },
|
|
|
|
|
inputs: [
|
|
|
|
|
{ key: 'r', label: '', dx: 0, dy: 0 },
|
|
|
|
|
{ key: 'g', label: '', dx: 0, dy: 1 },
|
|
|
|
|
{ key: 'b', label: '', dx: 0, dy: 2 },
|
|
|
|
|
],
|
|
|
|
|
outputs: [],
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-28 12:47:14 +00:00
|
|
|
function displayShape(node: CircuitNode): Shape {
|
|
|
|
|
const l = displayLayout(node)
|
|
|
|
|
return { body: { x: 0, y: -0.5, w: l.w, h: l.h }, inputs: displayPins(node).map((p, i) => ({ ...p, dx: 0, dy: i })), outputs: [] }
|
2026-10-28 12:05:57 +00:00
|
|
|
}
|
|
|
|
|
|
2026-10-28 12:30:07 +00:00
|
|
|
function benchShape(node: CircuitNode): Shape {
|
|
|
|
|
const l = benchLayout(node)
|
|
|
|
|
return {
|
|
|
|
|
body: { x: 0, y: -0.5, w: l.w, h: l.h },
|
|
|
|
|
inputs: l.left.map((p, i) => ({ key: p.key, label: p.label, dx: 0, dy: i })),
|
|
|
|
|
outputs: l.right.map((p, i) => ({ key: p.key, label: p.label, dx: l.w, dy: i })),
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-28 12:12:43 +00:00
|
|
|
|
2026-10-28 12:05:57 +00:00
|
|
|
const KEYBOARD_SHAPE: Shape = {
|
|
|
|
|
body: { x: 0, y: -0.5, w: 7, h: 9 },
|
|
|
|
|
inputs: [{ key: 'next', label: 'NEXT', dx: 0, dy: 8 }],
|
|
|
|
|
outputs: [...DATA_KEYS, 'rdy'].map((key, i) => ({ key, label: DEVICE_PIN_NAMES[key]!, dx: 7, dy: i })),
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
2026-10-28 10:52:56 +00:00
|
|
|
// Wide enough for the longest line name, and for the title "<type> in · <name>" (9px letters, about a third of a square each).
|
2026-10-22 16:59:56 +00:00
|
|
|
const title = `${(node.conn && get.conn?.(node.conn)?.name) || 'Port'} out${node.label?.trim() ? ` · ${node.label.trim()}` : ''}`
|
2026-10-28 10:52:56 +00:00
|
|
|
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.34 + 0.8))
|
2026-10-22 16:59:56 +00:00
|
|
|
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':
|
2026-10-28 11:51:09 +00:00
|
|
|
return node.rgb ? PIXEL_RGB_SHAPE : PIXEL_SHAPE
|
2026-10-28 12:05:57 +00:00
|
|
|
case 'terminal':
|
2026-10-28 12:47:14 +00:00
|
|
|
case 'monitor':
|
|
|
|
|
case 'rgbmonitor':
|
|
|
|
|
return displayShape(node)
|
2026-10-28 12:12:43 +00:00
|
|
|
case 'bench':
|
2026-10-28 12:30:07 +00:00
|
|
|
return benchShape(node)
|
2026-10-28 12:35:04 +00:00
|
|
|
case 'scope': {
|
|
|
|
|
const l = scopeLayout(node)
|
|
|
|
|
return { body: { x: 0, y: -0.5, w: l.w, h: l.h }, inputs: l.pins.map(p => ({ key: p.key, label: p.label, dx: 0, dy: p.dy })), outputs: [] }
|
|
|
|
|
}
|
2026-10-28 12:05:57 +00:00
|
|
|
case 'keyboard':
|
|
|
|
|
return KEYBOARD_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 ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
if (def.design) return designedShape(def, pins, face, getDef, node)
|
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]!)
|
|
|
|
|
}
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
return boxShape(def.name, pins, face, getDef, node)
|
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]
|
|
|
|
|
}
|