🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@webwriter/logic-circuit

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webwriter/logic-circuit

Create and simulate circuits with logic gates (AND, OR, XOR, etc.).

latest
npmnpm
Version
1.2.0
Version published
Maintainers
3
Created
Source

Logic,Circuit (@webwriter/logic-circuit@1.2.0)

License: MIT | Version: 1.2.0

Create and simulate circuits with logic gates (AND, OR, XOR, etc.).

Snippets

Snippets are examples and templates using the package's widgets.

NameImport Path
Halfadder@webwriter/logic-circuit/snippets/halfadder.html
RS FlipFlop@webwriter/logic-circuit/snippets/RS-FlipFlop.html

LogicCircuit (<webwriter-logic-circuit>)

Usage

Use with a CDN (e.g. jsdelivr):

<link href="https://cdn.jsdelivr.net/npm/@webwriter/logic-circuit/widgets/webwriter-logic-circuit.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/logic-circuit/widgets/webwriter-logic-circuit.js"></script>
<webwriter-logic-circuit></webwriter-logic-circuit>

Or use with a bundler (e.g. Vite):

npm install @webwriter/logic-circuit
<link href="@webwriter/logic-circuit/widgets/webwriter-logic-circuit.css" rel="stylesheet">
<script type="module" src="@webwriter/logic-circuit/widgets/webwriter-logic-circuit.js"></script>
<webwriter-logic-circuit></webwriter-logic-circuit>

Fields

Name (Attribute Name)TypeDescriptionDefaultReflects
LogicCircuit.shadowRootOptionsobject-{ ...LitElementWw.shadowRootOptions, delegatesFocus: true, }âś—
localize-i18n handler for the widget.LOCALIZEâś—
LogicCircuit.scopedElements-Registers scoped custom elements used within the logic circuit widget.-âś—
lineElements (lineElements)arrayThe list of all current wire (line) elements.[]âś—
gateElements (gateElements)arrayThe list of all current gate elements.[]âś—
reflectGates (reflectGates)StringStringified representation of gate state, synced via attribute.""âś“
reflectCons (reflectCons)StringStringified representation of connector state, synced via attribute.""âś“
gateID (gateID)numberInternal gate ID counter for uniquely identifying gates.0âś—
lineID (lineID)numberInternal line ID counter for uniquely identifying wires.0âś—
zoom (zoom)numberCurrent zoom level of the circuit canvas.1âś—
dragStartX (dragStartX)numberX coordinate where the drag operation started.0âś—
dragStartY (dragStartY)numberY coordinate where the drag operation started.0âś—
simulate (simulate)booleanWhether the simulation is running.trueâś—
simulationDelay (simulationDelay)numberDelay in milliseconds between simulation steps.500âś“
allowSimulation (allowSimulation)numberWhether simulation is allowed (1 = allowed, 0 = disallowed).1âś“
notGateAllowed (notGateAllowed)numberLimit or enable state for NOT gates (-1 = unlimited, 0+ = limited).-1âś“
andGateAllowed (andGateAllowed)numberLimit or enable state for AND gates.-1âś“
orGateAllowed (orGateAllowed)numberLimit or enable state for OR gates.-1âś“
nandGateAllowed (nandGateAllowed)numberLimit or enable state for NAND gates.-1âś“
norGateAllowed (norGateAllowed)numberLimit or enable state for NOR gates.-1âś“
xnorGateAllowed (xnorGateAllowed)numberLimit or enable state for XNOR gates.-1âś“
xorGateAllowed (xorGateAllowed)numberLimit or enable state for XOR gates.-1âś“
splitterAllowed (splitterAllowed)numberLimit or enable state for splitter gates.-1âś“
isDragging (isDragging)booleanWhether the user is currently dragging the canvas or an element.falseâś—
isDrawingLinebooleanWhether a connection line is currently being drawn.falseâś—
startConnectorConnectorElementReference to the starting connector for a wire being drawn.nullâś—
endConnectorConnectorElementReference to the ending connector for a wire being drawn.nullâś—
svgCanvas-Reference to the SVG canvas element.-âś—
workspaceContainer-Reference to the overall workspace container.-âś—
wsDrag-Reference to the draggable inner workspace.-âś—
simCheckbox-Reference to the simulation checkbox toggle.-âś—
instructionsContainer-Reference to the instructions container.-âś—
getGateElements-Get the current list of gate elements.-âś—
getLineElements-Get the current list of line elements.-âś—
svgPathToMouseSVGPathElement | nullThe temporary path element used when drawing a wire to follow the mouse.nullâś—

Fields including properties and attributes define the current state of the widget and offer customization options.

Methods

NameDescriptionParameters
toggleInstructionsToggles the visibility of the instructions container in the UI.-
handleAllowSimulationToggles simulation mode on or off.
Resets the circuit and updates the simulation checkbox and internal flag.
-
handleFlipAllGatesEnables or disables the "truth table" display on all gates,
depending on the state of the main switch.
-
handleMouseDownHandles mouse down interactions on the workspace.
- Starts dragging the canvas if the background is clicked.
- Cancels in-progress line drawing.
- Hides any open gate context menus.
event: MouseEvent
handleMouseMoveHandles mouse move events during dragging or line drawing.
Updates canvas position or live line path accordingly.
event: MouseEvent
transformWorkspaceApplies the current workspace offset and zoom transform to the container.-
handleMouseUpStops dragging behavior.-
handleWheelHandles zooming the workspace with the mouse wheel.
Clamps zoom between 0.5 and 2.5, and recalculates boundaries.
event: WheelEvent
handleDragLeaveHandles mouse leaving the workspace area while dragging.
Updates line positions to initial position.
event: MouseEvent
handleContextMenuPrevents the default browser context menu.event: MouseEvent
handleDragOverCalled when a gate is dragged over the workspace.
- Moves any connected lines dynamically.
- Highlights the trash can icon if hovering over it.
event: DragEvent
handleDropHandles a drop event on the workspace.
- Adds new gates or moves existing ones.
- Deletes gates if dropped over the trash icon.
event: DragEvent
handleDropTrashCanDeletes a gate when it is dropped over the trash can.event: DragEvent
handleInputChangeParses a numeric input field and sets the corresponding property.
Defaults to -1 if the value is invalid.
event: InputEvent, propertyName: string
simulateCircuitStarts circuit simulation.
Calculates outputs from all input gates and propagates through the circuit.
Stops simulation if the checkbox is unchecked.
-
resetCircuitResets all gates and lines in the circuit to their initial state.-
calculateBoundariesEnsures the workspace stays within bounds during dragging or zooming.
Clamps workspaceOffsetX and workspaceOffsetY based on viewport and canvas size.
-

Methods allow programmatic access to the widget.

Slots

NameDescriptionContent Type
(default)The default slot (currently unused in this widget)-

Slots define how the content of the widget is rendered.

Custom CSS properties

NameDescription
--circuit-backgroundBackground color of the workspace

Custom CSS properties offer defined customization of the widget's style.

CSS parts

NameDescription
gateStyles individual gate components
lineStyles the connecting lines between gates

CSS parts allow freely styling internals of the widget with CSS.

Editing config

NameValue

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public events.

Generated with @webwriter/build@1.8.1

Keywords

webwriter-widget

FAQs

Package last updated on 24 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts