chronos/src/diagram.typ

60 lines
1.1 KiB
Typst

#import "renderer.typ": render
#let _seq(
p1,
p2,
comment: none,
dashed: false,
tip: "default",
color: black
) = {
return ((
type: "seq",
p1: p1,
p2: p2,
comment: comment,
dashed: dashed,
tip: tip,
color: color,
),)
}
#let _par(name, display-name: auto, start-at: 0) = {
return ((
type: "par",
name: name,
display-name: if display-name == auto {name} else {display-name},
start-at: start-at
),)
}
#let _par-exists(participants, name) = {
for p in participants {
if name == p.name {
return true
}
}
return false
}
#let diagram(elements) = {
let participants = ()
for elmt in elements {
if elmt.type == "par" {
participants.push(elmt)
} else if elmt.type == "seq" {
if not _par-exists(participants, elmt.p1) {
participants.push(_par(elmt.p1).first())
}
if not _par-exists(participants, elmt.p2) {
participants.push(_par(elmt.p2).first())
}
}
}
render(participants, elements)
}
#let from-plantuml(code) = {
let code = code.text
}