Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/preview/zap/0.6.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Louis Grange

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions packages/preview/zap/0.6.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Zap for Typst

**Zap** ⚡ is a Typst package that makes drawing electronic circuits simple and intuitive 💥. It's the first circuit library inspired by widely recognized standards 🧷 like **IEC** and **IEEE/ANSI**. Unlike circuitikz in LaTeX (2007), its design philosophy balances ease of use with powerful customization, avoiding any awkward syntax.

[Repository](https://codeberg.org/grangelouis/zap) – [Documentation](https://zap.grangelouis.ch) – [Examples](https://codeberg.org/grangelouis/zap/src/branch/main/examples)

Check warning on line 5 in packages/preview/zap/0.6.0/README.md

View check run for this annotation

Typst package check / @preview/zap:0.6.0

packages/preview/zap/0.6.0/README.md#L5

Codeberg URL links to default branch: `https://codeberg.org/grangelouis/zap/src/branch/main/examples`. Consider using a link to a specific tag/release or a permalink to a commit instead. This will ensure that the linked resource always matches this version of the package. You can create a permalink here: https://codeberg.org/grangelouis/zap/src/branch/main/examples Alternatively you can also link to a local file. This is preferred if the linked file is already present in the submitted package.

## Examples

You can find the full list of examples [here](https://codeberg.org/grangelouis/zap/src/branch/main/examples).

Check warning on line 9 in packages/preview/zap/0.6.0/README.md

View check run for this annotation

Typst package check / @preview/zap:0.6.0

packages/preview/zap/0.6.0/README.md#L9

Codeberg URL links to default branch: `https://codeberg.org/grangelouis/zap/src/branch/main/examples`. Consider using a link to a specific tag/release or a permalink to a commit instead. This will ensure that the linked resource always matches this version of the package. You can create a permalink here: https://codeberg.org/grangelouis/zap/src/branch/main/examples Alternatively you can also link to a local file. This is preferred if the linked file is already present in the submitted package.

### Operational amplifier

![Operational amplifier example](https://codeberg.org/grangelouis/zap/raw/branch/main/examples/example1.svg)

Check warning on line 13 in packages/preview/zap/0.6.0/README.md

View check run for this annotation

Typst package check / @preview/zap:0.6.0

packages/preview/zap/0.6.0/README.md#L13

Codeberg URL links to default branch: `https://codeberg.org/grangelouis/zap/raw/branch/main/examples/example1.svg`. Consider using a link to a specific tag/release or a permalink to a commit instead. This will ensure that the linked resource always matches this version of the package. You can create a permalink here: https://codeberg.org/grangelouis/zap/src/branch/main/examples/example1.svg Alternatively you can also link to a local file. This is preferred if the linked file is already present in the submitted package.

### MicroController Unit

![MicroController Unit example](https://codeberg.org/grangelouis/zap/raw/branch/main/examples/example2.svg)

Check warning on line 17 in packages/preview/zap/0.6.0/README.md

View check run for this annotation

Typst package check / @preview/zap:0.6.0

packages/preview/zap/0.6.0/README.md#L17

Codeberg URL links to default branch: `https://codeberg.org/grangelouis/zap/raw/branch/main/examples/example2.svg`. Consider using a link to a specific tag/release or a permalink to a commit instead. This will ensure that the linked resource always matches this version of the package. You can create a permalink here: https://codeberg.org/grangelouis/zap/src/branch/main/examples/example2.svg Alternatively you can also link to a local file. This is preferred if the linked file is already present in the submitted package.

### Logic circuit

![Logic circuit example](https://codeberg.org/grangelouis/zap/raw/branch/main/examples/example3.svg)

Check warning on line 21 in packages/preview/zap/0.6.0/README.md

View check run for this annotation

Typst package check / @preview/zap:0.6.0

packages/preview/zap/0.6.0/README.md#L21

Codeberg URL links to default branch: `https://codeberg.org/grangelouis/zap/raw/branch/main/examples/example3.svg`. Consider using a link to a specific tag/release or a permalink to a commit instead. This will ensure that the linked resource always matches this version of the package. You can create a permalink here: https://codeberg.org/grangelouis/zap/src/branch/main/examples/example3.svg Alternatively you can also link to a local file. This is preferred if the linked file is already present in the submitted package.

## Quick usage

```typst
#import "@preview/zap:0.6.0"

#zap.circuit({
import zap: *

// Here is a minimalist example
node("B", (0, 0))
resistor("r1", "B", (rel: (0, 4)), i: $i_1$)
})
```

## Online documentation

You can find the full documentation 📚 [available online](https://zap.grangelouis.ch). It provides comprehensive guides, a detailed list of components, styling options, and example codes to get you started easily.

## Contributing

I highly welcome contributions 🌱! Creating and maintaining Zap takes time and love. If you'd like to help, check out the [contribution procedure](https://codeberg.org/grangelouis/zap/src/branch/main/CONTRIBUTING.md) and join the journey 🤩!

Check warning on line 43 in packages/preview/zap/0.6.0/README.md

View check run for this annotation

Typst package check / @preview/zap:0.6.0

packages/preview/zap/0.6.0/README.md#L43

Codeberg URL links to default branch: `https://codeberg.org/grangelouis/zap/src/branch/main/CONTRIBUTING.md`. Consider using a link to a specific tag/release or a permalink to a commit instead. This will ensure that the linked resource always matches this version of the package. You can create a permalink here: https://codeberg.org/grangelouis/zap/src/branch/main/CONTRIBUTING.md Alternatively you can also link to a local file. This is preferred if the linked file is already present in the submitted package.

## Legal disclaimer

This project is an independent, open-source library licensed under [MIT](https://codeberg.org/grangelouis/zap/src/branch/main/LICENSE) with symbols generated algorithmically from scratch. While inspired by international conventions (IEC, IEEE) for compatibility, Zap is **not affiliated with or certified by** any standards body. These are stylistic approximations for illustration. For safety-critical or regulatory compliance, please consult official standards and [create custom symbols](https://zap.grangelouis.ch/#custom).

Check warning on line 47 in packages/preview/zap/0.6.0/README.md

View check run for this annotation

Typst package check / @preview/zap:0.6.0

packages/preview/zap/0.6.0/README.md#L47

Codeberg URL links to default branch: `https://codeberg.org/grangelouis/zap/src/branch/main/LICENSE`. Consider using a link to a specific tag/release or a permalink to a commit instead. This will ensure that the linked resource always matches this version of the package. You can create a permalink here: https://codeberg.org/grangelouis/zap/src/branch/main/LICENSE Alternatively you can also link to a local file. This is preferred if the linked file is already present in the submitted package.
19 changes: 19 additions & 0 deletions packages/preview/zap/0.6.0/src/circuit.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#import "/src/deps.typ": cetz
#import "/src/styles.typ": default

/// CeTZ native canvas wrapper
///
/// https://zap.grangelouis.ch/#getting-started
///
/// - drawing (none, array, element): canvas content, typically containing the circuit elements
/// -> content
#let circuit(drawing, ..params) = {
cetz.canvas(..params, {
// Init style directory
cetz.draw.set-ctx(ctx => {
ctx.style.insert("zap", default)
return ctx
})
drawing
})
}
119 changes: 119 additions & 0 deletions packages/preview/zap/0.6.0/src/decorations.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#import "/src/deps.typ": cetz
#import cetz.draw: bezier-through, catmull, circle, content, get-ctx, hobby, line, mark
#import cetz.styles: merge

#let resolve-directions(direction) = {
let vertical = "north"
let horizontal = "east"
if "south" in direction {
vertical = "south"
}
if "west" in direction {
horizontal = "west"
}
return (x: horizontal, y: vertical)
}

#let resolve-decoration(ctx, deco, decor-type) = {
if type(deco) == dictionary and deco.at("content", default: none) == none { panic("decoration dictionary needs at least the 'content' key") }

let style = cetz.styles.resolve(ctx.style.zap.decoration, merge: if type(deco) == dictionary { deco } else { (content: deco) }, root: decor-type)
style.size = cetz.util.measure(ctx, style.content)
style.position = resolve-directions(style.anchor)
style.side = if style.position.y == "north" { 1 } else { -1 }
style.label-distance = style.at("label-distance", default: (0.1 + style.size.last()) * style.side)

return style
}

/// Symbol current decoration
///
/// - label (content | dict): label content
/// -> content
#let current(label) = {
get-ctx(ctx => {
let style = resolve-decoration(ctx, label, "current")

let mark-position = if style.position.x == "west" {
(("in", style.distance, "symbol.west"), "in")
} else {
(("symbol.east", style.distance, "out"), "out")
}

mark(..mark-position, symbol: style.symbol, reverse: style.invert, anchor: "center", fill: cetz.util.resolve-stroke(style.stroke).paint, stroke: 0pt, scale: style.scale)
content((rel: (0, style.label-distance), to: mark-position.at(0)), style.content)
})
}

/// Symbol flow decoration
///
/// - label (content | dict): label content
/// -> content
#let flow(label) = {
get-ctx(ctx => {
let style = resolve-decoration(ctx, label, "flow")

let west = style.position.x == "west"
let a-start = (to: ("symbol." + style.position.x, style.distance, if west { "in" } else { "out" }), rel: (0, style.indent * style.side))
let a-end = (to: a-start, rel: (style.length * if west { -1 } else { 1 }, 0))

line(
a-start,
a-end,
mark: (
(if style.invert { "start" } else { "end" }): style.symbol,
stroke: 0pt,
fill: cetz.util.resolve-stroke(style.stroke).paint,
scale: style.scale,
),
stroke: style.stroke,
)
content((rel: (0, style.label-distance), to: (a-start, style.label-ratio, a-end)), style.content)
})
}

/// Symbol voltage decoration
///
/// - label (content | dict): label content
/// -> content
#let voltage(label, p-rotate) = {
get-ctx(ctx => {
let style = resolve-decoration(ctx, label, "voltage")

let r-distance = cetz.util.resolve-number(ctx, style.distance)
let a-start = (rel: (style.start.at(0), (r-distance + style.start.at(1)) * style.side), to: "symbol." + style.position.y + "-west")
let a-end = (rel: (style.end.at(0), (r-distance + style.end.at(1)) * style.side), to: "symbol." + style.position.y + "-east")
let a-center = (rel: (style.center.at(0), (r-distance + style.center.at(1)) * style.side), to: "symbol." + style.position.y)

let (a-start, a-end) = if style.position.x == "west" { (a-end, a-start) } else { (a-start, a-end) }
content((rel: (0, style.label-distance), to: a-center), style.content)
if (style.shape == "curved") {
hobby(
a-start,
a-center,
a-end,
mark: (
(if style.invert { "start" } else { "end" }): style.symbol,
stroke: 0pt,
fill: cetz.util.resolve-stroke(style.stroke).paint,
scale: style.scale,
),
stroke: style.stroke,
)
} else if (style.shape == "straight") {
line(
a-start,
a-end,
mark: (
(if style.invert { "start" } else { "end" }): style.symbol,
stroke: 0pt,
fill: cetz.util.resolve-stroke(style.stroke).paint,
scale: style.scale,
),
stroke: style.stroke,
)
} else {
panic("Only 'curved' and 'straight' variants are supported for voltage arrows")
}
})
}
1 change: 1 addition & 0 deletions packages/preview/zap/0.6.0/src/deps.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import "@preview/cetz:0.5.2"
44 changes: 44 additions & 0 deletions packages/preview/zap/0.6.0/src/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Export dependencies
#import "deps.typ": cetz

// Export circuit
#import "circuit.typ": circuit

// Export decorations
#import "decorations.typ": current, flow, voltage

// Export styles
#import "styles.typ"

// Export core
#import "symbol.typ": interface, symbol

// Export symbols
#import "symbols/antenna.typ": antenna
#import "symbols/transformer.typ": transformer
#import "symbols/stub.typ": estub, nstub, sstub, stub, wstub
#import "symbols/wire.typ": swire, wire, zwire
#import "symbols/circulator.typ": circulator
#import "symbols/node.typ": node
#import "symbols/capacitor.typ": capacitor, pcapacitor
#import "symbols/diode.typ": diode, led, photodiode, schottky, tunnel, zener
#import "symbols/switch.typ": switch
#import "symbols/fuse.typ": afuse, fuse
#import "symbols/supply.typ": earth, frame, ground, rground, vcc, vee
#import "symbols/inductor.typ": inductor
#import "symbols/lamp.typ": lamp
#import "symbols/piezo.typ": piezo
#import "symbols/logic.typ": land, lnand, lnor, lnot, lor, lxnor, lxor
#import "symbols/resistor.typ": heater, potentiometer, resistor, rheostat
#import "symbols/source.typ": acvsource, disource, dvsource, isource, vsource
#import "symbols/battery.typ": battery, cell, multicell
#import "symbols/motor.typ": acmotor, dcmotor
#import "symbols/transistors/bjt.typ": bjt, npn, pnp
#import "symbols/transistors/mosfet.typ": mosfet, nmos, nmosd, pmos, pmosd
#import "symbols/transistors/jfet.typ": jfet, njfet, pjfet
#import "symbols/integrated/opamp.typ": opamp
#import "symbols/integrated/mcu.typ": mcu
#import "symbols/integrated/converter.typ": adc, dac
#import "symbols/instruments/round-meter.typ": ammeter, ohmmeter, round-meter, voltmeter, wattmeter
#import "symbols/button.typ": button, ncbutton, ncibutton, nobutton, noibutton
#import "symbols/integrated/flipflop.typ": dflipflop, flipflop, jkflipflop, srlatch
Loading
Loading