2026-10-17 10:49:38 +00:00
< script setup lang = "ts" >
import { CHALLENGES } from '~/lib/logic/challenges'
import type { ComponentDef , NodeKind } from '~/lib/logic/types'
const ed = useEditor ( )
const tab = ref < 'parts' | 'challenges' > ( 'parts' )
const query = ref ( '' )
const BASICS : { kind : NodeKind ; name : string ; icon : string ; key ? : string ; hint : string } [ ] = [
{ kind : 'nand' , name : 'NAND' , icon : 'lucide:square-function' , key : 'N' , hint : 'The one logic gate. Output is 0 only when both inputs are 1.' } ,
{ kind : 'input' , name : 'Input' , icon : 'lucide:toggle-left' , key : 'I' , hint : 'A switch. Inside a component it becomes an input pin.' } ,
{ kind : 'output' , name : 'Output' , icon : 'lucide:log-out' , key : 'O' , hint : 'Shows a value. Inside a component it becomes an output pin.' } ,
{ kind : 'lamp' , name : 'Lamp' , icon : 'lucide:lightbulb' , key : 'L' , hint : 'Lights up at 1.' } ,
{ kind : 'button' , name : 'Push button' , icon : 'lucide:circle-dot' , key : 'B' , hint : '1 while held down.' } ,
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
{ kind : 'panel' , name : 'Input panel' , icon : 'lucide:sliders-vertical' , key : 'P' , hint : 'A column of switches, buttons and clocks. On a component, "Attach input panel" makes one for its inputs.' } ,
2026-10-17 10:49:38 +00:00
{ kind : 'clock' , name : 'Clock' , icon : 'lucide:audio-waveform' , key : 'C' , hint : 'Square wave. Speed and pause are in the top bar.' } ,
{ kind : 'high' , name : 'Constant 1' , icon : 'lucide:plus' , hint : 'Always 1, like the supply rail.' } ,
{ kind : 'low' , name : 'Ground (0)' , icon : 'lucide:arrow-down-to-line' , hint : 'Always 0.' } ,
{ kind : 'hex' , name : 'Hex display' , icon : 'lucide:binary' , key : 'H' , hint : 'Shows 4 bits as 0– F.' } ,
{ kind : 'note' , name : 'Note' , icon : 'lucide:sticky-note' , key : 'T' , hint : 'Text label for your drawing.' } ,
]
const GROUP _ORDER = [ '' , 'Gates' , 'Routing' , 'Arithmetic' , 'Memory' , 'Demos' ]
const groups = computed ( ( ) => {
const q = query . value . trim ( ) . toLowerCase ( )
const map = new Map < string , ComponentDef [ ] > ( )
for ( const d of ed . project . value . components ) {
if ( q && ! d . name . toLowerCase ( ) . includes ( q ) ) continue
const g = d . group ? . trim ( ) ? ? ''
if ( ! map . has ( g ) ) map . set ( g , [ ] )
map . get ( g ) ! . push ( d )
}
const rank = ( g : string ) => ( GROUP _ORDER . includes ( g ) ? GROUP _ORDER . indexOf ( g ) : GROUP _ORDER . length )
return [ ... map . entries ( ) ]
. sort ( ( [ a ] , [ b ] ) => rank ( a ) - rank ( b ) || a . localeCompare ( b ) )
. map ( ( [ name , defs ] ) => ( { name : name || 'My components' , defs } ) )
} )
function pick ( kind : NodeKind , chip ? : string ) {
if ( chip && ! ed . canPlace ( chip ) ) return
ed . placing . value = { kind , chip }
}
function onDragStart ( e : DragEvent , kind : NodeKind , chip ? : string ) {
if ( chip && ! ed . canPlace ( chip ) ) {
e . preventDefault ( )
return
}
e . dataTransfer ? . setData ( 'application/x-logigate' , JSON . stringify ( { kind , chip } ) )
if ( e . dataTransfer ) e . dataTransfer . effectAllowed = 'copy'
}
const solved = computed ( ( ) => new Set ( ed . project . value . solved ) )
const started = computed ( ( ) => new Map ( ed . project . value . components . filter ( d => d . challenge ) . map ( d => [ d . challenge ! , d ] ) ) )
< / script >
< template >
< aside class = "palette" >
< div class = "tabs" >
< button : class = "{ active: tab === 'parts' }" @ click = "tab = 'parts'" > Parts < / button >
< button : class = "{ active: tab === 'challenges' }" @ click = "tab = 'challenges'" >
Challenges
< span class = "count" > { { solved . size } } / { { CHALLENGES . length } } < / span >
< / button >
< / div >
< div v-if ="tab === 'parts'" class="scroll" >
< h3 > Basics < / h3 >
< ul class = "items" >
< li v-for ="item in BASICS" :key="item.kind" >
< button
class = "item"
: class = "{ active: ed.placing.value?.kind === item.kind && !ed.placing.value?.chip }"
: title = "item.hint"
draggable = "true"
@ click = "pick(item.kind)"
@ dragstart = "onDragStart($event, item.kind)"
>
< span v-if ="item.kind === 'nand'" class="nand-badge" > & amp ; < / span >
< Icon v -else :name ="item.icon" class = "size-4 shrink-0 text-(--muted)" / >
< span class = "grow truncate" > { { item . name } } < / span >
< kbd v-if ="item.key" > {{ item.key }} < / kbd >
< / button >
< / li >
< / ul >
< div class = "search" >
< Icon name = "lucide:search" class = "size-3.5 text-(--muted)" / >
< input v -model = " query " placeholder = "Find component" / >
< / div >
< template v-for ="g in groups" :key="g.name" >
< h3 > { { g . name } } < / h3 >
< ul class = "items" >
< li v-for ="d in g.defs" :key="d.id" class="comp-row" >
< button
class = "item"
: class = "{ active: ed.placing.value?.chip === d.id, current: d.id === ed.def.value.id, blocked: !ed.canPlace(d.id) }"
: title = "d.id === ed.def.value.id ? 'You are editing this one' : !ed.canPlace(d.id) ? 'Contains the circuit you are editing' : d.description || 'Click, then click on the canvas to place'"
: draggable = "ed.canPlace(d.id)"
@ click = "pick('chip', d.id)"
@ dragstart = "onDragStart($event, 'chip', d.id)"
>
< Icon : name = "d.challenge && solved.has(d.challenge) ? 'lucide:badge-check' : 'lucide:box'" class = "size-4 shrink-0" : class = "d.challenge && solved.has(d.challenge) ? 'text-(--on)' : 'text-(--muted)'" / >
< span class = "grow truncate" > { { d . name } } < / span >
< span v-if ="d.id === ed.def.value.id" class="editing" > editing < / span >
< / button >
< button v-if ="d.id !== ed.def.value.id" class="open" title="Open and edit" @click="ed.open(d.id)" >
< Icon name = "lucide:pencil" class = "size-3.5" / >
< / button >
< / li >
< / ul >
< / template >
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
< div class = "grid gap-2 px-3 pt-2 pb-4" >
2026-10-17 10:49:38 +00:00
< button class = "btn w-full" @click ="ed.createComponent()" >
< Icon name = "lucide:plus" class = "size-4" / > New component
< / button >
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
< button class = "btn btn-ghost w-full" title = "NOT, AND, … up to a 4-bit counter, all built from NAND" @click ="ed.loadExamples()" >
< Icon name = "lucide:library" class = "size-4" / > Add example parts
< / button >
2026-10-17 10:49:38 +00:00
< / div >
< / div >
< div v -else class = "scroll" >
< p class = "intro" >
Build each part from NAND and the parts you already made . Start a challenge , wire it up , then press
< strong > Check < / strong > on the right .
< / p >
< ul class = "challenges" >
< li v-for ="c in CHALLENGES" :key="c.id" :class="{ solved: solved.has(c.id) }" >
< div class = "flex items-center gap-2" >
< Icon : name = "solved.has(c.id) ? 'lucide:circle-check' : 'lucide:circle'" class = "size-4 shrink-0" : class = "solved.has(c.id) ? 'text-(--on)' : 'text-(--muted)'" / >
< span class = "grow font-medium" > { { c . name } } < / span >
< button class = "btn-sm" @click ="ed.beginChallenge(c)" > {{ started.has ( c.id ) ? ' Open ' : ' Start ' }} < / button >
< / div >
< p > { { c . goal } } < / p >
< p class = "pins" > { { c . inputs . join ( ', ' ) } } → { { c . outputs . join ( ', ' ) } } < / p >
< / li >
< / ul >
< / div >
< / aside >
< / template >