diff --git a/README.md b/README.md
index ea42787..08ce598 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ This package lets you render sequence diagrams directly in Typst. The following
```typst
-#import "@preview/chronos:0.2.0"
+#import "@preview/chronos:0.2.1"
#chronos.diagram({
import chronos: *
_par("Alice")
diff --git a/docs/example.typ b/docs/example.typ
index 4b614ba..5f980a3 100644
--- a/docs/example.typ
+++ b/docs/example.typ
@@ -5,7 +5,7 @@
chronos: chronos
)
-#let example(src, show-src: true, vertical: false, fill: true, wrap: true) = {
+#let example(src, show-src: true, vertical: false, fill: false, wrap: true) = {
src = src.text
let full-src = example-preamble + src
let body = eval(full-src, scope: example-scope)
@@ -16,15 +16,15 @@
box(
stroke: black + 1pt,
radius: .5em,
- fill: if fill {color.white.darken(5%)} else {none},
+ fill: if fill {color.white.darken(2%)} else {none},
if show-src {
- let src-block = align(left, raw(src, lang: "typc"))
+ let src-block = raw(src, block: true, lang: "typc")
table(
columns: if vertical {1} else {2},
- inset: 1em,
+ inset: 5pt,
align: horizon + center,
stroke: none,
- img,
+ table.cell(inset: 1em, img),
if vertical {table.hline()} else {table.vline()}, src-block
)
} else {
diff --git a/docs/examples.typ b/docs/examples.typ
index a37ab85..f50b16c 100644
--- a/docs/examples.typ
+++ b/docs/examples.typ
@@ -1,8 +1,23 @@
#import "example.typ": example
+#let seq-return = example(```
+_seq(
+ "Bob", "Alice",
+ comment: [hello],
+ enable-dst: true
+)
+_seq(
+ "Alice", "Alice",
+ comment: [some action]
+)
+_ret(comment: [bye])
+```)
+
#let seq-comm-align = example(```
-_par("p1", display-name: "Start participant")
-_par("p2", display-name: "End participant")
+_par("p1",
+ display-name: "Start participant")
+_par("p2",
+ display-name: "End participant")
let alignments = (
"start", "end",
"left", "right",
@@ -90,15 +105,15 @@ _par("a", display-name: "Alice")
_par("b", display-name: "Bob")
_loop("default loop", {
- _seq("a", "b", comment: "Are you here ?")
+ _seq("a", "b", comment: "Are you here?")
})
_gap()
_loop("min loop", min: 1, {
- _seq("a", "b", comment: "Are you here ?")
+ _seq("a", "b", comment: "Are you here?")
})
_gap()
_loop("min-max loop", min: 1, max: 5, {
- _seq("a", "b", comment: "Are you still here ?")
+ _seq("a", "b", comment: "Are you still here?")
})
```)
@@ -121,15 +136,58 @@ _sync({
})
```)
-#let gaps-seps = example(```
-_par("alice", display-name: "Alice")
-_par("bob", display-name: "Bob")
+#let gaps = example(```
+_par("a", display-name: "Alice")
+_par("b", display-name: "Bob")
-_seq("alice", "bob", comment: "Hello")
-_gap(size: 10)
-_seq("bob", "alice", comment: "Hi")
-_sep("Another day")
-_seq("alice", "bob", comment: "Hello again")
+_seq("a", "b", comment: [message 1])
+_seq("b", "a", comment: [ok], dashed: true)
+_gap()
+_seq("a", "b", comment: [message 2])
+_seq("b", "a", comment: [ok], dashed: true)
+_gap(size: 40)
+_seq("a", "b", comment: [message 3])
+_seq("b", "a", comment: [ok], dashed: true)
+```)
+
+#let seps = example(```
+_par("a", display-name: "Alice")
+_par("b", display-name: "Bob")
+
+_sep[Initialization]
+_seq("a", "b", comment: [Request 1])
+_seq(
+ "b", "a",
+ comment: [Response 1],
+ dashed: true
+)
+
+_sep[Repetition]
+_seq("a", "b", comment: [Request 2])
+_seq(
+ "b", "a",
+ comment: [Response 2],
+ dashed: true
+)
+```)
+
+#let delays = example(```
+_par("a", display-name: "Alice")
+_par("b", display-name: "Bob")
+
+_seq("a", "b", comment: [Auth Request])
+_delay()
+_seq(
+ "b", "a",
+ comment: [Auth Response],
+ dashed: true
+)
+_delay(name: [5 minutes later])
+_seq(
+ "b", "a",
+ comment: [Good Bye !],
+ dashed: true
+)
```)
#let notes-shapes = example(```
diff --git a/docs/gaps_seps.typ b/docs/gaps_seps.typ
index d569ab9..678a6f3 100644
--- a/docs/gaps_seps.typ
+++ b/docs/gaps_seps.typ
@@ -1,8 +1,15 @@
-/// Creates a gap before the next element
-/// - size (int): Size of the gap
-#let _gap(size: 20) = {}
-
/// Creates a separator before the next element
-/// #examples.gaps-seps
+/// #examples.seps
/// - name (content): Name to display in the middle of the separator
-#let _sep(name) = {}
\ No newline at end of file
+#let _sep(name) = {}
+
+/// Creates a delay before the next element
+/// #examples.delays
+/// - name (content, none): Name to display in the middle of the delay area
+/// - size (int): Size of the delay
+#let _delay(name: none, size: 30) = {}
+
+/// Creates a gap before the next element
+/// #examples.gaps
+/// - size (int): Size of the gap
+#let _gap(size: 20) = {}
\ No newline at end of file
diff --git a/docs/sequences.typ b/docs/sequences.typ
index e9be9a6..cc5fc1d 100644
--- a/docs/sequences.typ
+++ b/docs/sequences.typ
@@ -42,6 +42,17 @@
slant: none
) = {}
+/// Creates a return sequence
+/// #examples.seq-return
+/// - comment (none, content): Optional comment to display along the arrow
+#let _ret(comment: none) = {}
+
+/// Accepted values for `comment-align` argument of @@_seq()
+/// #examples.seq-comm-align
+#let comment-align = (
+ "start", "end", "left", "center", "right"
+)
+
/// Accepted values for `event` argument of @@_evt()
///
/// `EVENTS = ("create", "destroy", "enable", "disable")`
@@ -51,10 +62,4 @@
/// #examples.seq-tips
#let tips = (
"", ">", ">>", "\\", "\\\\", "/", "//", "x", "o",
-)
-
-/// Accepted values for `comment-align` argument of @@_seq()
-/// #examples.seq-comm-align
-#let comment-align = (
- "start", "end", "left", "center", "right"
)
\ No newline at end of file
diff --git a/gallery.bash b/gallery.bash
deleted file mode 100644
index ea50654..0000000
--- a/gallery.bash
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-
-
-echo
-echo "Generating gallery PDFs"
-
-set -- ./gallery/*.typ
-cnt="$#"
-i=1
-for f
-do
- f2="${f/typ/pdf}"
- echo "($i/$cnt) $f -> $f2"
- typst c --root ./ "$f" "$f2"
- i=$((i+1))
-done
-
-set -- ./gallery/readme/*.typ
-cnt="$#"
-i=1
-for f
-do
- f2="${f/typ/png}"
- echo "($i/$cnt) $f -> $f2"
- typst c --root ./ "$f" "$f2"
- i=$((i+1))
-done
diff --git a/gallery/example1.pdf b/gallery/example1.pdf
index 693d6e1..17fe065 100644
Binary files a/gallery/example1.pdf and b/gallery/example1.pdf differ
diff --git a/gallery/example2.pdf b/gallery/example2.pdf
index 0861fff..c13a497 100644
Binary files a/gallery/example2.pdf and b/gallery/example2.pdf differ
diff --git a/gallery/example3.pdf b/gallery/example3.pdf
index f916e4d..b6ee5b1 100644
Binary files a/gallery/example3.pdf and b/gallery/example3.pdf differ
diff --git a/gallery/notes.pdf b/gallery/notes.pdf
index 2ff99fd..df8c796 100644
Binary files a/gallery/notes.pdf and b/gallery/notes.pdf differ
diff --git a/gallery/readme/boilerplate.png b/gallery/readme/boilerplate.png
index 755b523..4fcfa88 100644
Binary files a/gallery/readme/boilerplate.png and b/gallery/readme/boilerplate.png differ
diff --git a/gallery/readme/lifelines.png b/gallery/readme/lifelines.png
index fbd5bcf..2e33758 100644
Binary files a/gallery/readme/lifelines.png and b/gallery/readme/lifelines.png differ
diff --git a/gallery/readme/simple_sequence.png b/gallery/readme/simple_sequence.png
index f771ad5..e55bc0d 100644
Binary files a/gallery/readme/simple_sequence.png and b/gallery/readme/simple_sequence.png differ
diff --git a/justfile b/justfile
new file mode 100644
index 0000000..de19b92
--- /dev/null
+++ b/justfile
@@ -0,0 +1,12 @@
+# Local Variables:
+# mode: makefile
+# End:
+gallery_dir := "./gallery"
+set shell := ["bash", "-uc"]
+
+manual:
+ typst c manual.typ manual.pdf
+
+gallery:
+ for f in "{{gallery_dir}}"/*.typ; do typst c --root . "$f" "${f%typ}pdf"; done
+ for f in "{{gallery_dir}}"/readme/*.typ; do typst c --root . "$f" "${f%typ}png"; done
\ No newline at end of file
diff --git a/manual.pdf b/manual.pdf
index dca8906..b3a1bf0 100644
Binary files a/manual.pdf and b/manual.pdf differ
diff --git a/manual.typ b/manual.typ
index 69e96c7..65dc6e5 100644
--- a/manual.typ
+++ b/manual.typ
@@ -1,4 +1,6 @@
-#import "@preview/tidy:0.3.0"
+#import "@preview/tidy:0.4.2"
+#import "@preview/codly:1.2.0": codly-init, codly
+#import "@preview/codly-languages:0.1.8": codly-languages
#import "src/lib.typ" as chronos
#import "src/participant.typ" as mod-par
#import "docs/examples.typ"
@@ -6,25 +8,41 @@
#let TYPST = image("gallery/typst.png", width: 1.5cm, height: 1.5cm, fit: "contain")
-#let doc-ref(target, full: false, var: false) = {
- let (module, func) = target.split(".")
- let label-name = module + func
- let display-name = func
- if full {
- display-name = target
- }
- if not var {
- label-name += "()"
- display-name += "()"
- }
- link(label(label-name))[#display-name]
-}
+#show: codly-init
+#codly(
+ languages: codly-languages
+)
+
+#set text(font: "Source Sans 3")
#set heading(numbering: (..num) => if num.pos().len() < 4 {
numbering("1.1", ..num)
})
+
+#align(center)[
+ #v(2cm)
+ #text(size: 2em)[*Chronos*]
+
+ _v#chronos.version;_
+ #v(1cm)
+ #chronos.diagram({
+ import chronos: *
+ _par("u", display-name: [User], shape: "actor")
+ _par("wa", display-name: [Web App])
+ _par("tu", display-name: [Typst Universe], shape: "database")
+
+ _seq("u", "wa", comment: [Compile document], enable-dst: true)
+ _seq("wa", "tu", comment: [Fetch Chronos])
+ _seq("tu", "wa", dashed: true, slant: 10)
+ _seq("wa", "wa", comment: [Render])
+ _ret(comment: [Nice sequence diagram])
+ })
+]
+
+#pagebreak()
+
#{
- outline(indent: true, depth: 3)
+ outline(indent: auto, depth: 3)
}
#show link: set text(fill: blue)
@@ -40,14 +58,16 @@ This package lets you create nice sequence diagrams using the CeTZ package.
= Usage
+#let import-stmt = "#import \"@preview/chronos:" + str(chronos.version) + "\""
+
Simply import #link("https://typst.app/universe/package/chronos/")[chronos] and call the `diagram` function:
-#pad(left: 1em)[```typ
-#import "@preview/chronos:0.1.0"
+#raw(block:true, lang: "typ", ```typ
+$import
#chronos.diagram({
import chronos: *
...
})
-```]
+```.text.replace("$import", import-stmt))
= Examples
@@ -121,7 +141,11 @@ chronos.diagram({
== Custom images
#example(```
-let load-img(path) = image(path, width: 1.5cm, height: 1.5cm, fit:"contain")
+let load-img(path) = image(
+ path,
+ width: 1.5cm, height: 1.5cm,
+ fit:"contain"
+)
let TYPST = load-img("../gallery/typst.png")
let FERRIS = load-img("../gallery/ferris.png")
let ME = load-img("../gallery/me.jpg")
@@ -148,11 +172,11 @@ chronos.diagram({
read("docs/participants.typ"),
name: "Participants",
require-all-parameters: true,
+ old-syntax: true,
scope: (
chronos: chronos,
mod-par: mod-par,
- TYPST: TYPST,
- doc-ref: doc-ref
+ TYPST: TYPST
)
)
#tidy.show-module(par-docs, show-outline: false, sort-functions: none)
@@ -163,9 +187,9 @@ chronos.diagram({
read("docs/sequences.typ"),
name: "Sequences",
require-all-parameters: true,
+ old-syntax: true,
scope: (
chronos: chronos,
- doc-ref: doc-ref,
examples: examples
)
)
@@ -177,9 +201,9 @@ chronos.diagram({
read("docs/groups.typ"),
name: "Groups",
require-all-parameters: true,
+ old-syntax: true,
scope: (
chronos: chronos,
- doc-ref: doc-ref,
examples: examples
)
)
@@ -191,13 +215,13 @@ chronos.diagram({
read("docs/gaps_seps.typ"),
name: "Gaps and separators",
require-all-parameters: true,
+ old-syntax: true,
scope: (
chronos: chronos,
- doc-ref: doc-ref,
examples: examples
)
)
-#tidy.show-module(gap-sep-docs, show-outline: false)
+#tidy.show-module(gap-sep-docs, show-outline: false, sort-functions: none)
#pagebreak(weak: true)
@@ -205,9 +229,9 @@ chronos.diagram({
read("docs/notes.typ"),
name: "Notes",
require-all-parameters: true,
+ old-syntax: true,
scope: (
chronos: chronos,
- doc-ref: doc-ref,
examples: examples
)
)
diff --git a/src/diagram.typ b/src/diagram.typ
index b286ffc..0e78117 100644
--- a/src/diagram.typ
+++ b/src/diagram.typ
@@ -46,7 +46,6 @@
while i < elmts.len() {
let elmt = elmts.at(i)
if elmt.type == "grp" {
- let grp-elmts = elmt.elmts
elmt.elmts = elmt.elmts.map(e => {
if e.type == "seq" {
if e.p1 == "?" {
@@ -60,12 +59,17 @@
elmts.at(i) = elmt
elmts = (
elmts.slice(0, i + 1) +
- grp-elmts +
+ elmt.elmts +
((
- type: "grp-end"
+ type: "grp-end",
+ start-i: i
),) +
elmts.slice(i+1)
)
+ } else if elmt.type == "grp-end" {
+ // Put back elements in group because they might have changed
+ elmts.at(elmt.start-i).elmts = elmts.slice(elmt.start-i + 1, i)
+
} else if elmt.type == "seq" {
if elmt.enable-dst {
activation-history.push(elmt)
diff --git a/src/group.typ b/src/group.typ
index 821b0cb..db0933b 100644
--- a/src/group.typ
+++ b/src/group.typ
@@ -1,4 +1,4 @@
-#import "@preview/cetz:0.3.1": draw
+#import "/src/cetz.typ": draw
#import "consts.typ": *
#let _grp(name, desc: none, type: "default", elmts) = {
diff --git a/src/lib.typ b/src/lib.typ
index 25671e5..2575674 100644
--- a/src/lib.typ
+++ b/src/lib.typ
@@ -1,4 +1,4 @@
-#let version = version(0, 2, 0)
+#let version = version(0, 2, 1)
#import "diagram.typ": diagram, from-plantuml, _gap, _evt, _col
#import "sequence.typ": _seq, _ret
diff --git a/src/note.typ b/src/note.typ
index feaa5eb..14d3c98 100644
--- a/src/note.typ
+++ b/src/note.typ
@@ -1,4 +1,4 @@
-#import "@preview/cetz:0.3.1": draw
+#import "/src/cetz.typ": draw
#import "consts.typ": *
#let SIDES = (
diff --git a/src/participant.typ b/src/participant.typ
index 26e4a7e..a9e5572 100644
--- a/src/participant.typ
+++ b/src/participant.typ
@@ -1,4 +1,4 @@
-#import "@preview/cetz:0.3.1": draw
+#import "/src/cetz.typ": draw
#import "consts.typ": *
#let PAR-SPECIALS = "?[]"
diff --git a/src/renderer.typ b/src/renderer.typ
index 9938e64..4f70d02 100644
--- a/src/renderer.typ
+++ b/src/renderer.typ
@@ -1,4 +1,4 @@
-#import "@preview/cetz:0.3.1": canvas, draw
+#import "/src/cetz.typ": canvas, draw
#import "utils.typ": get-participants-i, get-style, normalize-units
#import "group.typ"
#import "participant.typ"
diff --git a/src/separator.typ b/src/separator.typ
index c51b65f..e0d1b71 100644
--- a/src/separator.typ
+++ b/src/separator.typ
@@ -1,4 +1,4 @@
-#import "@preview/cetz:0.3.1": draw
+#import "/src/cetz.typ": draw
#import "consts.typ": *
#let _sep(name) = {
diff --git a/src/sequence.typ b/src/sequence.typ
index 4c20ae1..eb315de 100644
--- a/src/sequence.typ
+++ b/src/sequence.typ
@@ -1,4 +1,4 @@
-#import "@preview/cetz:0.3.1": draw, vector
+#import "/src/cetz.typ": draw, vector
#import "consts.typ": *
#import "participant.typ"
#import "note.typ"
diff --git a/src/utils.typ b/src/utils.typ
index a97a3b5..e8d750d 100644
--- a/src/utils.typ
+++ b/src/utils.typ
@@ -36,6 +36,9 @@
max-i = calc.max(max-i, i1)
}
}
+ if max-i < min-i {
+ (min-i, max-i) = (max-i, min-i)
+ }
return (min-i, max-i)
}
diff --git a/typst.toml b/typst.toml
index f11f016..54d8602 100644
--- a/typst.toml
+++ b/typst.toml
@@ -1,7 +1,7 @@
[package]
name = "chronos"
-version = "0.2.0"
-compiler = "0.12.0"
+version = "0.2.1"
+compiler = "0.13.1"
repository = "https://git.kb28.ch/HEL/chronos"
entrypoint = "src/lib.typ"
authors = [
@@ -11,4 +11,4 @@ categories = ["visualization"]
license = "Apache-2.0"
description = "A package to draw sequence diagrams with CeTZ"
keywords = ["sequence", "diagram", "plantuml"]
-exclude = [ "gallery", "gallery.bash", "docs" ]
+exclude = [ "gallery", "justfile", "docs" ]
|