
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@webwriter/logic-circuit
Advanced tools
Create and simulate circuits with logic gates (AND, OR, XOR, etc.).
@webwriter/logic-circuit@1.2.0)License: MIT | Version: 1.2.0
Create and simulate circuits with logic gates (AND, OR, XOR, etc.).
Snippets are examples and templates using the package's widgets.
| Name | Import Path |
|---|---|
| Halfadder | @webwriter/logic-circuit/snippets/halfadder.html |
| RS FlipFlop | @webwriter/logic-circuit/snippets/RS-FlipFlop.html |
LogicCircuit (<webwriter-logic-circuit>)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>
| Name (Attribute Name) | Type | Description | Default | Reflects |
|---|---|---|---|---|
LogicCircuit.shadowRootOptions | object | - | { ...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) | array | The list of all current wire (line) elements. | [] | âś— |
gateElements (gateElements) | array | The list of all current gate elements. | [] | âś— |
reflectGates (reflectGates) | String | Stringified representation of gate state, synced via attribute. | "" | âś“ |
reflectCons (reflectCons) | String | Stringified representation of connector state, synced via attribute. | "" | âś“ |
gateID (gateID) | number | Internal gate ID counter for uniquely identifying gates. | 0 | âś— |
lineID (lineID) | number | Internal line ID counter for uniquely identifying wires. | 0 | âś— |
zoom (zoom) | number | Current zoom level of the circuit canvas. | 1 | âś— |
dragStartX (dragStartX) | number | X coordinate where the drag operation started. | 0 | âś— |
dragStartY (dragStartY) | number | Y coordinate where the drag operation started. | 0 | âś— |
simulate (simulate) | boolean | Whether the simulation is running. | true | âś— |
simulationDelay (simulationDelay) | number | Delay in milliseconds between simulation steps. | 500 | âś“ |
allowSimulation (allowSimulation) | number | Whether simulation is allowed (1 = allowed, 0 = disallowed). | 1 | âś“ |
notGateAllowed (notGateAllowed) | number | Limit or enable state for NOT gates (-1 = unlimited, 0+ = limited). | -1 | âś“ |
andGateAllowed (andGateAllowed) | number | Limit or enable state for AND gates. | -1 | âś“ |
orGateAllowed (orGateAllowed) | number | Limit or enable state for OR gates. | -1 | âś“ |
nandGateAllowed (nandGateAllowed) | number | Limit or enable state for NAND gates. | -1 | âś“ |
norGateAllowed (norGateAllowed) | number | Limit or enable state for NOR gates. | -1 | âś“ |
xnorGateAllowed (xnorGateAllowed) | number | Limit or enable state for XNOR gates. | -1 | âś“ |
xorGateAllowed (xorGateAllowed) | number | Limit or enable state for XOR gates. | -1 | âś“ |
splitterAllowed (splitterAllowed) | number | Limit or enable state for splitter gates. | -1 | âś“ |
isDragging (isDragging) | boolean | Whether the user is currently dragging the canvas or an element. | false | âś— |
isDrawingLine | boolean | Whether a connection line is currently being drawn. | false | âś— |
startConnector | ConnectorElement | Reference to the starting connector for a wire being drawn. | null | âś— |
endConnector | ConnectorElement | Reference 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. | - | âś— |
svgPathToMouse | SVGPathElement | null | The 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.
| Name | Description | Parameters |
|---|---|---|
toggleInstructions | Toggles the visibility of the instructions container in the UI. | - |
handleAllowSimulation | Toggles simulation mode on or off. Resets the circuit and updates the simulation checkbox and internal flag. | - |
handleFlipAllGates | Enables or disables the "truth table" display on all gates, depending on the state of the main switch. | - |
handleMouseDown | Handles 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 |
handleMouseMove | Handles mouse move events during dragging or line drawing. Updates canvas position or live line path accordingly. | event: MouseEvent |
transformWorkspace | Applies the current workspace offset and zoom transform to the container. | - |
handleMouseUp | Stops dragging behavior. | - |
handleWheel | Handles zooming the workspace with the mouse wheel. Clamps zoom between 0.5 and 2.5, and recalculates boundaries. | event: WheelEvent |
handleDragLeave | Handles mouse leaving the workspace area while dragging. Updates line positions to initial position. | event: MouseEvent |
handleContextMenu | Prevents the default browser context menu. | event: MouseEvent |
handleDragOver | Called when a gate is dragged over the workspace. - Moves any connected lines dynamically. - Highlights the trash can icon if hovering over it. | event: DragEvent |
handleDrop | Handles a drop event on the workspace. - Adds new gates or moves existing ones. - Deletes gates if dropped over the trash icon. | event: DragEvent |
handleDropTrashCan | Deletes a gate when it is dropped over the trash can. | event: DragEvent |
handleInputChange | Parses a numeric input field and sets the corresponding property. Defaults to -1 if the value is invalid. | event: InputEvent, propertyName: string |
simulateCircuit | Starts circuit simulation. Calculates outputs from all input gates and propagates through the circuit. Stops simulation if the checkbox is unchecked. | - |
resetCircuit | Resets all gates and lines in the circuit to their initial state. | - |
calculateBoundaries | Ensures 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.
| Name | Description | Content Type |
|---|---|---|
| (default) | The default slot (currently unused in this widget) | - |
Slots define how the content of the widget is rendered.
| Name | Description |
|---|---|
| --circuit-background | Background color of the workspace |
Custom CSS properties offer defined customization of the widget's style.
| Name | Description |
|---|---|
| gate | Styles individual gate components |
| line | Styles the connecting lines between gates |
CSS parts allow freely styling internals of the widget with CSS.
| Name | Value |
|---|
The editing config defines how explorable authoring tools such as WebWriter treat the widget.
No public events.
Generated with @webwriter/build@1.8.1
FAQs
Create and simulate circuits with logic gates (AND, OR, XOR, etc.).
We found that @webwriter/logic-circuit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.