Compare commits
	
		
			50 Commits
		
	
	
		
			fd5b147e86
			...
			v0.2.1
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6bf98ebcb8 | |||
| 
						
						
							
						
						c46b345771
	
				 | 
					
					
						|||
| 
						
						
							
						
						060e37e38e
	
				 | 
					
					
						|||
| 
						
						
							
						
						788c8999b1
	
				 | 
					
					
						|||
| 3eadf63db3 | |||
| e57e617bb9 | |||
| dfb980e366 | |||
| 3beaad03d4 | |||
| 5cb8f50f2a | |||
| 
						
						
							
						
						e8d737ff00
	
				 | 
					
					
						|||
| 19c60c5ecf | |||
| 
						
						
							
						
						df3a2ddf68
	
				 | 
					
					
						|||
| 
						
						
							
						
						42e8e26aa7
	
				 | 
					
					
						|||
| 
						
						
							
						
						b33531bef5
	
				 | 
					
					
						|||
| 
						
						
							
						
						ab1386e721
	
				 | 
					
					
						|||
| 
						
						
							
						
						1f155063a8
	
				 | 
					
					
						|||
| 
						
						
							
						
						d986284e4e
	
				 | 
					
					
						|||
| 
						
						
							
						
						a037727edf
	
				 | 
					
					
						|||
| 
						
						
							
						
						b0950f5e68
	
				 | 
					
					
						|||
| 
						
						
							
						
						eb09a23fc1
	
				 | 
					
					
						|||
| 
						
						
							
						
						c4f09a0a3e
	
				 | 
					
					
						|||
| 
						
						
							
						
						9275169e8c
	
				 | 
					
					
						|||
| 
						
						
							
						
						a198708743
	
				 | 
					
					
						|||
| 
						
						
							
						
						b66634d44f
	
				 | 
					
					
						|||
| 
						
						
							
						
						3bc103b9d7
	
				 | 
					
					
						|||
| 
						
						
							
						
						feff030510
	
				 | 
					
					
						|||
| 
						
						
							
						
						56cc1b11c0
	
				 | 
					
					
						|||
| 
						
						
							
						
						647d50e125
	
				 | 
					
					
						|||
| 
						
						
							
						
						522cd1537a
	
				 | 
					
					
						|||
| 
						
						
							
						
						6f563750fb
	
				 | 
					
					
						|||
| 
						
						
							
						
						5822d705f2
	
				 | 
					
					
						|||
| 
						
						
							
						
						226efa46b7
	
				 | 
					
					
						|||
| 
						
						
							
						
						3d9e045b56
	
				 | 
					
					
						|||
| 
						
						
							
						
						eb05c41810
	
				 | 
					
					
						|||
| 
						
						
							
						
						b9bbe6f93d
	
				 | 
					
					
						|||
| 
						
						
							
						
						b5c34c154f
	
				 | 
					
					
						|||
| 
						
						
							
						
						030fd3edba
	
				 | 
					
					
						|||
| 
						
						
							
						
						cbba14ed04
	
				 | 
					
					
						|||
| 
						
						
							
						
						77a65a3199
	
				 | 
					
					
						|||
| 
						
						
							
						
						ff6a7e52bc
	
				 | 
					
					
						|||
| 
						
						
							
						
						ebd4d8f1ca
	
				 | 
					
					
						|||
| 
						
						
							
						
						3b25d68f1e
	
				 | 
					
					
						|||
| 
						
						
							
						
						0968436c8a
	
				 | 
					
					
						|||
| 
						
						
							
						
						2c724598e9
	
				 | 
					
					
						|||
| 
						
						
							
						
						0cff9d6799
	
				 | 
					
					
						|||
| 
						
						
							
						
						f08f30b9e2
	
				 | 
					
					
						|||
| 
						
						
							
						
						81871e2aca
	
				 | 
					
					
						|||
| 
						
						
							
						
						6500e5a4a3
	
				 | 
					
					
						|||
| 
						
						
							
						
						6e7dc9913f
	
				 | 
					
					
						|||
| 
						
						
							
						
						9c83f810bb
	
				 | 
					
					
						
							
								
								
									
										147
									
								
								README.md
									
									
									
									
									
								
							
							
						
						@@ -1,3 +1,150 @@
 | 
				
			|||||||
# chronos
 | 
					# chronos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
A Typst package to draw sequence diagrams with CeTZ
 | 
					A Typst package to draw sequence diagrams with CeTZ
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This package lets you render sequence diagrams directly in Typst. The following boilerplate code creates an empty sequence diagram with two participants:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<table>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td><strong>Typst</strong></td>
 | 
				
			||||||
 | 
					<td><strong>Result</strong></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typst
 | 
				
			||||||
 | 
					#import "@preview/chronos:0.2.1"
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("Alice")
 | 
				
			||||||
 | 
					  _par("Bob")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</td>
 | 
				
			||||||
 | 
					<td><img src="./gallery/readme/boilerplate.png"></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					</table>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> *Disclaimer*\
 | 
				
			||||||
 | 
					> The package cannot parse PlantUML syntax for the moment, and thus requires the use of element functions, as shown in the examples.
 | 
				
			||||||
 | 
					> A PlantUML parser is in the TODO list, just not the top priority
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Basic sequences
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can make basic sequences using the `_seq` function:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<table>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td><strong>Typst</strong></td>
 | 
				
			||||||
 | 
					<td><strong>Result</strong></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typst
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("Alice")
 | 
				
			||||||
 | 
					  _par("Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("Alice", "Bob", comment: "Hello")
 | 
				
			||||||
 | 
					  _seq("Bob", "Bob", comment: "Think")
 | 
				
			||||||
 | 
					  _seq("Bob", "Alice", comment: "Hi")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</td>
 | 
				
			||||||
 | 
					<td><img src="./gallery/readme/simple_sequence.png"></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					</table>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can make lifelines using the following parameters of the `_seq` function:
 | 
				
			||||||
 | 
					 - `enable-dst`: enables the destination lifeline
 | 
				
			||||||
 | 
					 - `create-dst`: creates the destination lifeline and participant
 | 
				
			||||||
 | 
					 - `disable-dst`: disables the destination lifeline
 | 
				
			||||||
 | 
					 - `destroy-dst`: destroys the destination lifeline and participant
 | 
				
			||||||
 | 
					 - `disable-src`: disables the source lifeline
 | 
				
			||||||
 | 
					 - `destroy-src`: destroy the source lifeline and participant
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<table>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td><strong>Typst</strong></td>
 | 
				
			||||||
 | 
					<td><strong>Result</strong></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typst
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("A", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("B", display-name: "Bob")
 | 
				
			||||||
 | 
					  _par("C", display-name: "Charlie")
 | 
				
			||||||
 | 
					  _par("D", display-name: "Derek")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("A", "B", comment: "hello", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("B", "B", comment: "self call", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("C", "B", comment: "hello from thread 2", enable-dst: true, lifeline-style: (fill: rgb("#005500")))
 | 
				
			||||||
 | 
					  _seq("B", "D", comment: "create", create-dst: true)
 | 
				
			||||||
 | 
					  _seq("B", "C", comment: "done in thread 2", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					  _seq("B", "B", comment: "rc", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					  _seq("B", "D", comment: "delete", destroy-dst: true)
 | 
				
			||||||
 | 
					  _seq("B", "A", comment: "success", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</td>
 | 
				
			||||||
 | 
					<td><img src="./gallery/readme/lifelines.png"></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					</table>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Showcase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Several features have already been implemented in Chronos. Don't hesitate to checkout the examples in the [gallery](./gallery) folder to see what you can do. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Quick example reference:
 | 
				
			||||||
 | 
					<table>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td><strong>Example</strong></td>
 | 
				
			||||||
 | 
					<td><strong>Features</strong></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`example1` <br>([PDF](./gallery/example1.pdf)|[Typst](./gallery/example1.typ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</td>
 | 
				
			||||||
 | 
					<td>Simple cases, color sequences, groups, separators, gaps, self-sequences</td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`example2` <br>([PDF](./gallery/example2.pdf)|[Typst](./gallery/example2.typ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</td>
 | 
				
			||||||
 | 
					<td>Lifelines, found/lost messages, synchronized sequences, slanted sequences</td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`example3` <br>([PDF](./gallery/example3.pdf)|[Typst](./gallery/example3.typ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</td>
 | 
				
			||||||
 | 
					<td>Participant shapes, sequence tips, hidden partipicant ends</td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`notes` <br>([PDF](./gallery/notes.pdf)|[Typst](./gallery/notes.typ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</td>
 | 
				
			||||||
 | 
					<td>Notes (duh), deferred participant creation</td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					</table>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> [!NOTE]
 | 
				
			||||||
 | 
					> 
 | 
				
			||||||
 | 
					> Many examples were taken/adapted from the PlantUML [documentation](https://plantuml.com/sequence-diagram) on sequence diagrams
 | 
				
			||||||
							
								
								
									
										28
									
								
								TODO.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					# TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- [x] Basic participants
 | 
				
			||||||
 | 
					- [x] Basic sequences
 | 
				
			||||||
 | 
					- [x] Separators
 | 
				
			||||||
 | 
					- [x] Gaps
 | 
				
			||||||
 | 
					- [x] Groups
 | 
				
			||||||
 | 
					- [x] Self arrows
 | 
				
			||||||
 | 
					- [x] Arrow from start / to end, small arrows
 | 
				
			||||||
 | 
					- [x] Lifelines
 | 
				
			||||||
 | 
					- [x] Different types of participants
 | 
				
			||||||
 | 
					- [x] Notes
 | 
				
			||||||
 | 
					- [x] Synchronized arrows
 | 
				
			||||||
 | 
					- [x] Slanted arrows
 | 
				
			||||||
 | 
					- [x] Different types of arrow tips
 | 
				
			||||||
 | 
					- [x] Sequence comment alignment
 | 
				
			||||||
 | 
					- [x] Fix group size with syncs
 | 
				
			||||||
 | 
					- [ ] Fix column spacing with notes over multiple columns
 | 
				
			||||||
 | 
					- [ ] Fix notes with arrows from start / to end / small arrows
 | 
				
			||||||
 | 
					- [ ] Fix group size with self arrows + notes
 | 
				
			||||||
 | 
					- [ ] Unify styling structure
 | 
				
			||||||
 | 
					- [ ] Add args verification to catch user errors + pretty error messages
 | 
				
			||||||
 | 
					- [ ] PlantUML parser
 | 
				
			||||||
 | 
					- [ ] (Message numbering)
 | 
				
			||||||
 | 
					- [ ] Mainframes
 | 
				
			||||||
 | 
					- [x] Different types of groups (alt/loop/etc.)
 | 
				
			||||||
 | 
					- [ ] Delays
 | 
				
			||||||
 | 
					- [ ] Auto-fit in parent
 | 
				
			||||||
							
								
								
									
										39
									
								
								docs/example.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					#import "../src/lib.typ" as chronos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let example-preamble = "import \"../src/lib.typ\": *;"
 | 
				
			||||||
 | 
					#let example-scope = (
 | 
				
			||||||
 | 
					  chronos: chronos
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#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)
 | 
				
			||||||
 | 
					  let img = if wrap { chronos.diagram(body) } else { body }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  block(width: 100%,
 | 
				
			||||||
 | 
					    align(center,
 | 
				
			||||||
 | 
					      box(
 | 
				
			||||||
 | 
					        stroke: black + 1pt,
 | 
				
			||||||
 | 
					        radius: .5em,
 | 
				
			||||||
 | 
					        fill: if fill {color.white.darken(2%)} else {none},
 | 
				
			||||||
 | 
					        if show-src {
 | 
				
			||||||
 | 
					          let src-block = raw(src, block: true, lang: "typc")
 | 
				
			||||||
 | 
					          table(
 | 
				
			||||||
 | 
					            columns: if vertical {1} else {2},
 | 
				
			||||||
 | 
					            inset: 5pt,
 | 
				
			||||||
 | 
					            align: horizon + center,
 | 
				
			||||||
 | 
					            stroke: none,
 | 
				
			||||||
 | 
					            table.cell(inset: 1em, img),
 | 
				
			||||||
 | 
					            if vertical {table.hline()} else {table.vline()}, src-block
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          table(
 | 
				
			||||||
 | 
					            inset: 1em,
 | 
				
			||||||
 | 
					            img
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										213
									
								
								docs/examples.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,213 @@
 | 
				
			|||||||
 | 
					#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")
 | 
				
			||||||
 | 
					let alignments = (
 | 
				
			||||||
 | 
					  "start", "end",
 | 
				
			||||||
 | 
					  "left", "right",
 | 
				
			||||||
 | 
					  "center"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					for a in alignments {
 | 
				
			||||||
 | 
					  _seq(
 | 
				
			||||||
 | 
					    "p2", "p1",
 | 
				
			||||||
 | 
					    comment: raw(a),
 | 
				
			||||||
 | 
					    comment-align: a
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let seq-tips = example(```
 | 
				
			||||||
 | 
					let _seq = _seq.with(comment-align: "center")
 | 
				
			||||||
 | 
					_par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_seq("a", "b", comment: "Various tips", end-tip: "")
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ">", comment: `->`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ">>", comment: `->>`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: "\\", comment: `-\`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: "\\\\", comment: `-\\`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: "/", comment: `-/`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: "//", comment: `-//`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: "x", comment: `->x`)
 | 
				
			||||||
 | 
					_seq("a", "b", start-tip: "x", comment: `x->`)
 | 
				
			||||||
 | 
					_seq("a", "b", start-tip: "o", comment: `o->`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ("o", ">"), comment: `->o`)
 | 
				
			||||||
 | 
					_seq("a", "b", start-tip: "o",
 | 
				
			||||||
 | 
					               end-tip: ("o", ">"), comment: `o->o`)
 | 
				
			||||||
 | 
					_seq("a", "b", start-tip: ">",
 | 
				
			||||||
 | 
					               end-tip: ">", comment: `<->`)
 | 
				
			||||||
 | 
					_seq("a", "b", start-tip: ("o", ">"),
 | 
				
			||||||
 | 
					               end-tip: ("o", ">"), comment: `o<->o`)
 | 
				
			||||||
 | 
					_seq("a", "b", start-tip: "x",
 | 
				
			||||||
 | 
					               end-tip: "x", comment: `x<->x`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ("o", ">>"), comment: `->>o`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ("o", "\\"), comment: `-\o`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ("o", "\\\\"), comment: `-\\o`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ("o", "/"), comment: `-/o`)
 | 
				
			||||||
 | 
					_seq("a", "b", end-tip: ("o", "//"), comment: `-//o`)
 | 
				
			||||||
 | 
					_seq("a", "b", start-tip: "x",
 | 
				
			||||||
 | 
					               end-tip: ("o", ">"), comment: `x->o`)
 | 
				
			||||||
 | 
					```)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let grp = example(```
 | 
				
			||||||
 | 
					_par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_grp("Group 1", desc: "Description", {
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: "Authentication")
 | 
				
			||||||
 | 
					  _grp("loop", desc: "1000 times", {
 | 
				
			||||||
 | 
					    _seq("a", "b", comment: "DoS Attack")
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: "x")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let alt = example(```
 | 
				
			||||||
 | 
					_par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_alt(
 | 
				
			||||||
 | 
					  "first encounter", {
 | 
				
			||||||
 | 
					    _seq("a", "b", comment: "Who are you ?")
 | 
				
			||||||
 | 
					    _seq("b", "a", comment: "I'm Bob")
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "know eachother", {
 | 
				
			||||||
 | 
					    _seq("a", "b", comment: "Hello Bob")
 | 
				
			||||||
 | 
					    _seq("b", "a", comment: "Hello Alice")
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "best friends", {
 | 
				
			||||||
 | 
					    _seq("a", "b", comment: "Hi !")
 | 
				
			||||||
 | 
					    _seq("b", "a", comment: "Hi !")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					```)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let loop = example(```
 | 
				
			||||||
 | 
					_par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_loop("default loop", {
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: "Are you here?")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					_gap()
 | 
				
			||||||
 | 
					_loop("min loop", min: 1, {
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: "Are you here?")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					_gap()
 | 
				
			||||||
 | 
					_loop("min-max loop", min: 1, max: 5, {
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: "Are you still here?")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let sync = example(```
 | 
				
			||||||
 | 
					_par("alice", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("bob", display-name: "Bob")
 | 
				
			||||||
 | 
					_par("craig", display-name: "Craig")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_seq("bob", "alice")  // Unsynchronized
 | 
				
			||||||
 | 
					_seq("bob", "craig")  //  "
 | 
				
			||||||
 | 
					_sync({
 | 
				
			||||||
 | 
					  _seq("bob", "alice")  // Synchronized
 | 
				
			||||||
 | 
					  _seq("bob", "craig")  //  "
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					_seq("alice", "bob")  // Unsynchronized
 | 
				
			||||||
 | 
					_seq("craig", "bob")  //  "
 | 
				
			||||||
 | 
					_sync({
 | 
				
			||||||
 | 
					  _seq("alice", "bob")  // Synchronized
 | 
				
			||||||
 | 
					  _seq("craig", "bob")  //  "
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let gaps = example(```
 | 
				
			||||||
 | 
					_par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_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(```
 | 
				
			||||||
 | 
					_par("alice", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("bob", display-name: "Bob")
 | 
				
			||||||
 | 
					_note("over", `default`, pos: "alice")
 | 
				
			||||||
 | 
					_note("over", `rect`, pos: "bob", shape: "rect")
 | 
				
			||||||
 | 
					_note("over", `hex`, pos: ("alice", "bob"), shape: "hex")
 | 
				
			||||||
 | 
					```)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let notes-sides = example(```
 | 
				
			||||||
 | 
					_par("alice", display-name: "Alice")
 | 
				
			||||||
 | 
					_par("bob", display-name: "Bob")
 | 
				
			||||||
 | 
					_par("charlie", display-name: "Charlie")
 | 
				
			||||||
 | 
					_note("left", [`left` of Alice], pos: "alice")
 | 
				
			||||||
 | 
					_note("right", [`right` of Charlie], pos: "charlie")
 | 
				
			||||||
 | 
					_note("over", [`over` Alice and Bob], pos: ("alice", "bob"))
 | 
				
			||||||
 | 
					_note("across", [`across` all participants])
 | 
				
			||||||
 | 
					_seq("alice", "bob")
 | 
				
			||||||
 | 
					_note("left", [linked with sequence])
 | 
				
			||||||
 | 
					_note("over", [A note], pos: "alice")
 | 
				
			||||||
 | 
					_note("over", [Aligned note], pos: "charlie", aligned: true)
 | 
				
			||||||
 | 
					```, vertical: true)
 | 
				
			||||||
							
								
								
									
										15
									
								
								docs/gaps_seps.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					/// Creates a separator before the next element
 | 
				
			||||||
 | 
					/// #examples.seps
 | 
				
			||||||
 | 
					/// - name (content): Name to display in the middle of the separator
 | 
				
			||||||
 | 
					#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) = {}
 | 
				
			||||||
							
								
								
									
										58
									
								
								docs/groups.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					/// Creates a group of sequences
 | 
				
			||||||
 | 
					/// #examples.grp
 | 
				
			||||||
 | 
					/// - name (content): The group's name
 | 
				
			||||||
 | 
					/// - desc (none, content): Optional description
 | 
				
			||||||
 | 
					/// - type (str): The groups's type (should only be set through other functions like @@_alt() or @@_loop() )
 | 
				
			||||||
 | 
					/// - elmts (array): Elements inside the group (can be sequences, other groups, notes, etc.)
 | 
				
			||||||
 | 
					#let _grp(
 | 
				
			||||||
 | 
					  name,
 | 
				
			||||||
 | 
					  desc: none,
 | 
				
			||||||
 | 
					  type: "default",
 | 
				
			||||||
 | 
					  elmts
 | 
				
			||||||
 | 
					) = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Creates an alt-else group of sequences
 | 
				
			||||||
 | 
					/// 
 | 
				
			||||||
 | 
					/// It contains at least one section but can have as many as needed
 | 
				
			||||||
 | 
					/// #examples.alt
 | 
				
			||||||
 | 
					/// - desc (content): The alt's label
 | 
				
			||||||
 | 
					/// - elmts (array): Elements inside the alt's first section
 | 
				
			||||||
 | 
					/// - ..args (content, array): Complementary "else" sections.\ You can add as many else sections as you need by passing a content (else section label) followed by an array of elements (see example)
 | 
				
			||||||
 | 
					#let _alt(
 | 
				
			||||||
 | 
					  desc,
 | 
				
			||||||
 | 
					  elmts,
 | 
				
			||||||
 | 
					  ..args
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Creates a looped group of sequences
 | 
				
			||||||
 | 
					/// #examples.loop
 | 
				
			||||||
 | 
					/// - desc (content): Loop description
 | 
				
			||||||
 | 
					/// - min (none, number): Optional lower bound of the loop
 | 
				
			||||||
 | 
					/// - max (auto, number): Upper bound of the loop. If left as `auto` and `min` is set, it will be infinity (`'*'`)
 | 
				
			||||||
 | 
					/// - elmts (array): Elements inside the group
 | 
				
			||||||
 | 
					#let _loop(
 | 
				
			||||||
 | 
					  desc,
 | 
				
			||||||
 | 
					  min: none,
 | 
				
			||||||
 | 
					  max: auto,
 | 
				
			||||||
 | 
					  elmts
 | 
				
			||||||
 | 
					) = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Synchronizes multiple sequences\
 | 
				
			||||||
 | 
					/// All elements inside a synchronized group will start at the same time
 | 
				
			||||||
 | 
					/// #examples.sync
 | 
				
			||||||
 | 
					/// - elmts (array): Synchronized elements (generally sequences or notes)
 | 
				
			||||||
 | 
					#let _sync(
 | 
				
			||||||
 | 
					  elmts
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Creates an optional group\
 | 
				
			||||||
 | 
					/// This is a simple wrapper around @@_grp()
 | 
				
			||||||
 | 
					/// - desc (content): Group description
 | 
				
			||||||
 | 
					/// - elmts (array): Elements inside the group
 | 
				
			||||||
 | 
					#let _opt(desc, elmts) = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Creates a break group\
 | 
				
			||||||
 | 
					/// This is a simple wrapper around @@_grp()
 | 
				
			||||||
 | 
					/// - desc (content): Group description
 | 
				
			||||||
 | 
					/// - elmts (array): Elements inside the group
 | 
				
			||||||
 | 
					#let _break(desc, elmts) = {}
 | 
				
			||||||
							
								
								
									
										23
									
								
								docs/notes.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					/// Creates a note
 | 
				
			||||||
 | 
					/// - side (str): The side on which to place the note (see @@SIDES for accepted values)
 | 
				
			||||||
 | 
					/// - content (content): The note's content
 | 
				
			||||||
 | 
					/// - pos (none, str, array): Optional participant(s) on which to draw next to / over. If `side` is "left" or "right", sets next to which participant the note is placed. If `side` is "over", sets over which participant(s) it is placed
 | 
				
			||||||
 | 
					/// - color (color): The note's color
 | 
				
			||||||
 | 
					/// - shape (str): The note's shape (see @@SHAPES for accepted values)
 | 
				
			||||||
 | 
					/// - aligned (bool): True if the note is aligned with another note, in which case `side` must be `"over"`, false otherwise
 | 
				
			||||||
 | 
					#let _note(
 | 
				
			||||||
 | 
					  side,
 | 
				
			||||||
 | 
					  content,
 | 
				
			||||||
 | 
					  pos: none,
 | 
				
			||||||
 | 
					  color: rgb("#FEFFDD"),
 | 
				
			||||||
 | 
					  shape: "default",
 | 
				
			||||||
 | 
					  aligned: false
 | 
				
			||||||
 | 
					) = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Accepted values for `shape` argument of @@_note()
 | 
				
			||||||
 | 
					/// #examples.notes-shapes
 | 
				
			||||||
 | 
					#let SHAPES = ("default", "rect", "hex")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Accepted values for `side` argument of @@_note()
 | 
				
			||||||
 | 
					/// #examples.notes-sides
 | 
				
			||||||
 | 
					#let SIDES = ("left", "right", "over", "across")
 | 
				
			||||||
							
								
								
									
										69
									
								
								docs/participants.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					/// Possible participant shapes
 | 
				
			||||||
 | 
					/// #box(width: 100%, align(center)[
 | 
				
			||||||
 | 
					///   #chronos.diagram({
 | 
				
			||||||
 | 
					///     import chronos: *
 | 
				
			||||||
 | 
					///     let _par = _par.with(show-bottom: false)
 | 
				
			||||||
 | 
					///     _par("Foo", display-name: "participant", shape: "participant")
 | 
				
			||||||
 | 
					///     _par("Foo1", display-name: "actor", shape: "actor")
 | 
				
			||||||
 | 
					///     _par("Foo2", display-name: "boundary", shape: "boundary")
 | 
				
			||||||
 | 
					///     _par("Foo3", display-name: "control", shape: "control")
 | 
				
			||||||
 | 
					///     _par("Foo4", display-name: "entity", shape: "entity")
 | 
				
			||||||
 | 
					///     _par("Foo5", display-name: "database", shape: "database")
 | 
				
			||||||
 | 
					///     _par("Foo6", display-name: "collections", shape: "collections")
 | 
				
			||||||
 | 
					///     _par("Foo7", display-name: "queue", shape: "queue")
 | 
				
			||||||
 | 
					///     _par("Foo8", display-name: "custom", shape: "custom", custom-image: TYPST)
 | 
				
			||||||
 | 
					///     _gap()
 | 
				
			||||||
 | 
					///   })
 | 
				
			||||||
 | 
					/// ])
 | 
				
			||||||
 | 
					#let SHAPES = (
 | 
				
			||||||
 | 
					  "participant",
 | 
				
			||||||
 | 
					  "actor",
 | 
				
			||||||
 | 
					  "boundary",
 | 
				
			||||||
 | 
					  "control",
 | 
				
			||||||
 | 
					  "entity",
 | 
				
			||||||
 | 
					  "database",
 | 
				
			||||||
 | 
					  "collections",
 | 
				
			||||||
 | 
					  "queue",
 | 
				
			||||||
 | 
					  "custom"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Creates a new participant
 | 
				
			||||||
 | 
					/// - name (str): Unique participant name used as reference in other functions
 | 
				
			||||||
 | 
					/// - display-name (auto, content): Name to display in the diagram. If set to `auto`, `name` is used
 | 
				
			||||||
 | 
					/// - from-start (bool): If set to true, the participant is created at the top of the diagram. Otherwise, it is created at the first reference
 | 
				
			||||||
 | 
					/// - invisible (bool): If set to true, the participant will not be shown
 | 
				
			||||||
 | 
					/// - shape (str): The shape of the participant. Possible values in @@SHAPES
 | 
				
			||||||
 | 
					/// - color (color): The participant's color
 | 
				
			||||||
 | 
					/// - custom-image (none, image): If shape is 'custom', sets the custom image to display
 | 
				
			||||||
 | 
					/// - show-bottom (bool): Whether to display the bottom shape
 | 
				
			||||||
 | 
					/// - show-top (bool): Whether to display the top shape
 | 
				
			||||||
 | 
					/// -> array
 | 
				
			||||||
 | 
					#let _par(
 | 
				
			||||||
 | 
					  name,
 | 
				
			||||||
 | 
					  display-name: auto,
 | 
				
			||||||
 | 
					  from-start: true,
 | 
				
			||||||
 | 
					  invisible: false,
 | 
				
			||||||
 | 
					  shape: "participant",
 | 
				
			||||||
 | 
					  color: rgb("#E2E2F0"),
 | 
				
			||||||
 | 
					  custom-image: none,
 | 
				
			||||||
 | 
					  show-bottom: true,
 | 
				
			||||||
 | 
					  show-top: true,
 | 
				
			||||||
 | 
					) = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Sets some options for columns between participants
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// Parameters `p1` and `p2` MUST be consecutive participants (also counting found/lost messages), but they do not need to be in the left to right order
 | 
				
			||||||
 | 
					/// - p1 (str): The first neighbouring participant
 | 
				
			||||||
 | 
					/// - p2 (str): The second neighbouring participant
 | 
				
			||||||
 | 
					/// - width (auto, int, float, length): Optional fixed width of the column\ If the column's content (e.g. sequence comments) is larger, it will overflow
 | 
				
			||||||
 | 
					/// - margin (int, float, length): Additional margin to add to the column\ This margin is not included in `width` and `min-width`, but rather added separately
 | 
				
			||||||
 | 
					/// - min-width (int, float, length): Minimum width of the column\ If set to a larger value than `width`, the latter will be overriden
 | 
				
			||||||
 | 
					/// - max-width (int, float, length, none): Maximum width of the column\ If set to a lower value than `width`, the latter will be overriden\ If set to `none`, no restriction is applied
 | 
				
			||||||
 | 
					#let _col(
 | 
				
			||||||
 | 
					  p1,
 | 
				
			||||||
 | 
					  p2,
 | 
				
			||||||
 | 
					  width: auto,
 | 
				
			||||||
 | 
					  margin: 0,
 | 
				
			||||||
 | 
					  min-width: 0,
 | 
				
			||||||
 | 
					  max-width: none
 | 
				
			||||||
 | 
					) = {}
 | 
				
			||||||
							
								
								
									
										65
									
								
								docs/sequences.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,65 @@
 | 
				
			|||||||
 | 
					/// Manually adds an event to the given participant
 | 
				
			||||||
 | 
					/// - participant (str): The participant concerned by the event
 | 
				
			||||||
 | 
					/// - event (str): The event type (see @@EVENTS for ccepted values)
 | 
				
			||||||
 | 
					#let _evt(participant, event) = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Creates a sequence / message between two participants
 | 
				
			||||||
 | 
					/// - p1 (str): Start participant
 | 
				
			||||||
 | 
					/// - p2 (str): End participant
 | 
				
			||||||
 | 
					/// - comment (none, content): Optional comment to display along the arrow
 | 
				
			||||||
 | 
					/// - comment-align (str): Where to align the comment with respect to the arrow (see @@comment-align for accepted values)
 | 
				
			||||||
 | 
					/// - dashed (bool): Whether the arrow's stroke is dashed or not
 | 
				
			||||||
 | 
					/// - start-tip (str): Start arrow tip (see @@tips for accepted values)
 | 
				
			||||||
 | 
					/// - end-tip (str): End arrow tip (see @@tips for accepted values)
 | 
				
			||||||
 | 
					/// - color (color): Arrow's color
 | 
				
			||||||
 | 
					/// - flip (bool): If true, the arrow is flipped (goes from end to start). This is particularly useful for self calls, to change the side on which the arrow appears
 | 
				
			||||||
 | 
					/// - enable-dst (bool): If true, enables the destination lifeline
 | 
				
			||||||
 | 
					/// - create-dst (bool): If true, creates the destination lifeline and participant
 | 
				
			||||||
 | 
					/// - disable-dst (bool): If true, disables the destination lifeline
 | 
				
			||||||
 | 
					/// - destroy-dst (bool): If true, destroys the destination lifeline and participant
 | 
				
			||||||
 | 
					/// - disable-src (bool): If true, disables the source lifeline
 | 
				
			||||||
 | 
					/// - destroy-src (bool): If true, destroy the source lifeline and participant
 | 
				
			||||||
 | 
					/// - lifeline-style (auto, dict): Optional styling options for lifeline rectangles (see CeTZ documentation for more information on all possible values)
 | 
				
			||||||
 | 
					/// - slant (none, int): Optional slant of the arrow
 | 
				
			||||||
 | 
					/// -> array
 | 
				
			||||||
 | 
					#let _seq(
 | 
				
			||||||
 | 
					  p1,
 | 
				
			||||||
 | 
					  p2,
 | 
				
			||||||
 | 
					  comment: none,
 | 
				
			||||||
 | 
					  comment-align: "left",
 | 
				
			||||||
 | 
					  dashed: false,
 | 
				
			||||||
 | 
					  start-tip: "",
 | 
				
			||||||
 | 
					  end-tip: ">",
 | 
				
			||||||
 | 
					  color: black,
 | 
				
			||||||
 | 
					  flip: false,
 | 
				
			||||||
 | 
					  enable-dst: false,
 | 
				
			||||||
 | 
					  create-dst: false,
 | 
				
			||||||
 | 
					  disable-dst: false,
 | 
				
			||||||
 | 
					  destroy-dst: false,
 | 
				
			||||||
 | 
					  disable-src: false,
 | 
				
			||||||
 | 
					  destroy-src: false,
 | 
				
			||||||
 | 
					  lifeline-style: auto,
 | 
				
			||||||
 | 
					  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")`
 | 
				
			||||||
 | 
					#let EVENTS = ("create", "destroy", "enable", "disable")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Accepted values for `start-tip` and `end-tip` arguments of @@_seq()
 | 
				
			||||||
 | 
					/// #examples.seq-tips
 | 
				
			||||||
 | 
					#let tips = (
 | 
				
			||||||
 | 
					  "", ">", ">>", "\\", "\\\\", "/", "//", "x", "o",
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -33,15 +33,38 @@ Alice <-- Bob: Another authentication Response
 | 
				
			|||||||
#chronos.diagram({
 | 
					#chronos.diagram({
 | 
				
			||||||
  import chronos: *
 | 
					  import chronos: *
 | 
				
			||||||
  _seq("Alice", "Bob", comment: "Authentication Request")
 | 
					  _seq("Alice", "Bob", comment: "Authentication Request")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _alt(
 | 
				
			||||||
 | 
					    "successful case", {
 | 
				
			||||||
 | 
					      _seq("Bob", "Alice", comment: "Authentication Accepted")
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "some kind of failure", {
 | 
				
			||||||
      _seq("Bob", "Alice", comment: "Authentication Failure")
 | 
					      _seq("Bob", "Alice", comment: "Authentication Failure")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      _grp("My own label", desc: "My own label2", {
 | 
					      _grp("My own label", desc: "My own label2", {
 | 
				
			||||||
        _seq("Alice", "Log", comment: "Log attack start")
 | 
					        _seq("Alice", "Log", comment: "Log attack start")
 | 
				
			||||||
    _grp("loop", desc: "1000 times", {
 | 
					        _loop("1000 times", {
 | 
				
			||||||
          _seq("Alice", "Bob", comment: "DNS Attack")
 | 
					          _seq("Alice", "Bob", comment: "DNS Attack")
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    _seq("Alice", "Bob", comment: "Log attack end")
 | 
					        _seq("Alice", "Log", comment: "Log attack end")
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "Another type of failure", {
 | 
				
			||||||
 | 
					      _seq("Bob", "Alice", comment: "Please repeat")
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("a", display-name: box(width: 1.5em, height: .5em), show-bottom: false)
 | 
				
			||||||
 | 
					  _par("b", display-name: box(width: 1.5em, height: .5em), show-bottom: false)
 | 
				
			||||||
 | 
					  _col("a", "b", width: 2cm)
 | 
				
			||||||
 | 
					  _loop("a<1", min: 1, {
 | 
				
			||||||
 | 
					    _seq("a", "b", end-tip: ">>")
 | 
				
			||||||
 | 
					    _seq("b", "a", end-tip: ">>")
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ">>")
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#chronos.diagram({
 | 
					#chronos.diagram({
 | 
				
			||||||
@@ -55,6 +78,15 @@ Alice <-- Bob: Another authentication Response
 | 
				
			|||||||
  _seq("Bob", "Alice", comment: "another authentication Response", dashed: true)
 | 
					  _seq("Bob", "Alice", comment: "another authentication Response", dashed: true)
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _seq("Alice", "Bob", comment: "Authentication Request")
 | 
				
			||||||
 | 
					  _delay()
 | 
				
			||||||
 | 
					  _seq("Bob", "Alice", comment: "Authentication Response")
 | 
				
			||||||
 | 
					  _delay(name: "5 minutes later")
 | 
				
			||||||
 | 
					  _seq("Bob", "Alice", comment: "Good Bye !")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#chronos.diagram({
 | 
					#chronos.diagram({
 | 
				
			||||||
  import chronos: *
 | 
					  import chronos: *
 | 
				
			||||||
  _seq("Alice", "Bob", comment: "message 1")
 | 
					  _seq("Alice", "Bob", comment: "message 1")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,3 +49,121 @@
 | 
				
			|||||||
  _seq("Alice", "?", comment: [->?\ *short* from actor1])
 | 
					  _seq("Alice", "?", comment: [->?\ *short* from actor1])
 | 
				
			||||||
  _seq("Alice", "Bob", comment: [->\ from actor1 to actor2])
 | 
					  _seq("Alice", "Bob", comment: [->\ from actor1 to actor2])
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("alice", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("bob", display-name: "Bob")
 | 
				
			||||||
 | 
					  _par("craig", display-name: "Craig")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("bob", "alice")
 | 
				
			||||||
 | 
					  _seq("bob", "craig")
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  _sync({
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Synched", comment-align: "start")
 | 
				
			||||||
 | 
					    _seq("bob", "craig", comment: "Synched", comment-align: "start")
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  _seq("alice", "bob")
 | 
				
			||||||
 | 
					  _seq("craig", "bob")
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  _sync({
 | 
				
			||||||
 | 
					    _seq("alice", "bob")
 | 
				
			||||||
 | 
					    _seq("craig", "bob")
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  _sync({
 | 
				
			||||||
 | 
					    _seq("alice", "bob", enable-dst: true)
 | 
				
			||||||
 | 
					    _seq("craig", "bob")
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _evt("bob", "disable")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("alice", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("bob", display-name: "Bob")
 | 
				
			||||||
 | 
					  _par("craig", display-name: "Craig")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("alice", "bob")
 | 
				
			||||||
 | 
					  _seq("bob", "craig", slant: auto)
 | 
				
			||||||
 | 
					  _seq("alice", "craig", slant: 20)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _sync({
 | 
				
			||||||
 | 
					    _seq("alice", "bob", slant: 10)
 | 
				
			||||||
 | 
					    _seq("craig", "bob", slant: 20)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _sync({
 | 
				
			||||||
 | 
					    _seq("alice", "bob", slant: auto)
 | 
				
			||||||
 | 
					    _seq("bob", "alice", slant: auto)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					  _evt("bob", "disable")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#grid(columns: 2, column-gutter: 2em,
 | 
				
			||||||
 | 
					  chronos.diagram({
 | 
				
			||||||
 | 
					    import chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _par("alice", display-name: "Alice")
 | 
				
			||||||
 | 
					    _par("bob", display-name: "Bob")
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "This is a very long comment")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Left to right
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Start aligned", comment-align: "start")
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "End aligned", comment-align: "end")
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Left aligned", comment-align: "left")
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Right aligned", comment-align: "right")
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Centered", comment-align: "center")
 | 
				
			||||||
 | 
					    _gap()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Right to left
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Start aligned", comment-align: "start")
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "End aligned", comment-align: "end")
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Left aligned", comment-align: "left")
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Right aligned", comment-align: "right")
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Centered", comment-align: "center")
 | 
				
			||||||
 | 
					    _gap()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Slant left to right
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Start aligned", comment-align: "start", slant: 10)
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "End aligned", comment-align: "end", slant: 10)
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Left aligned", comment-align: "left", slant: 10)
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Right aligned", comment-align: "right", slant: 10)
 | 
				
			||||||
 | 
					    _seq("alice", "bob", comment: "Centered", comment-align: "center", slant: 10)
 | 
				
			||||||
 | 
					    _gap()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Slant right to left
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Start aligned", comment-align: "start", slant: 10)
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "End aligned", comment-align: "end", slant: 10)
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Left aligned", comment-align: "left", slant: 10)
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Right aligned", comment-align: "right", slant: 10)
 | 
				
			||||||
 | 
					    _seq("bob", "alice", comment: "Centered", comment-align: "center", slant: 10)
 | 
				
			||||||
 | 
					  }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  chronos.diagram({
 | 
				
			||||||
 | 
					    import chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _par("alice", display-name: "Alice")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Start aligned", comment-align: "start")
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "End aligned", comment-align: "end")
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Left aligned", comment-align: "left")
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Right aligned", comment-align: "right")
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Centered", comment-align: "center")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Start aligned", comment-align: "start", flip: true)
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "End aligned", comment-align: "end", flip: true)
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Left aligned", comment-align: "left", flip: true)
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Right aligned", comment-align: "right", flip: true)
 | 
				
			||||||
 | 
					    _seq("alice", "alice", comment: "Centered", comment-align: "center", flip: true)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								gallery/example3.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										166
									
								
								gallery/example3.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,166 @@
 | 
				
			|||||||
 | 
					#import "/src/lib.typ" as chronos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#set page(width: auto, height: auto)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let TYPST = image("typst.png", width: 1.5cm, height: 1.5cm, fit: "contain")
 | 
				
			||||||
 | 
					#let FERRIS = image("ferris.png", width: 1.5cm, height: 1.5cm, fit: "contain")
 | 
				
			||||||
 | 
					#let ME = image("me.jpg", width: 1.5cm, height: 1.5cm, fit: "contain")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("Foo", display-name: "Participant", shape: "participant")
 | 
				
			||||||
 | 
					  _par("Foo1", display-name: "Actor", shape: "actor")
 | 
				
			||||||
 | 
					  _par("Foo2", display-name: "Boundary", shape: "boundary")
 | 
				
			||||||
 | 
					  _par("Foo3", display-name: "Control", shape: "control")
 | 
				
			||||||
 | 
					  _par("Foo4", display-name: "Entity", shape: "entity")
 | 
				
			||||||
 | 
					  _par("Foo5", display-name: "Database", shape: "database")
 | 
				
			||||||
 | 
					  _par("Foo6", display-name: "Collections", shape: "collections")
 | 
				
			||||||
 | 
					  _par("Foo7", display-name: "Queue", shape: "queue")
 | 
				
			||||||
 | 
					  _par("Foo8", display-name: "Typst", shape: "custom", custom-image: TYPST)
 | 
				
			||||||
 | 
					  _par("Foo9", display-name: "Ferris", shape: "custom", custom-image: FERRIS)
 | 
				
			||||||
 | 
					  _par("Foo10", display-name: "Baryhobal", shape: "custom", custom-image: ME)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo1", comment: "To actor")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo2", comment: "To boundary")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo3", comment: "To control")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo4", comment: "To entity")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo5", comment: "To database")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo6", comment: "To collections")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo7", comment: "To queue")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo8", comment: "To Typst")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo9", comment: "To ferris")
 | 
				
			||||||
 | 
					  _seq("Foo", "Foo10", comment: "To Baryhobal")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("me", display-name: "Me", shape: "custom", custom-image: ME)
 | 
				
			||||||
 | 
					  _par("typst", display-name: "Typst", shape: "custom", custom-image: TYPST)
 | 
				
			||||||
 | 
					  _par("rust", display-name: "Rust", shape: "custom", custom-image: FERRIS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("me", "typst", comment: "opens document", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("me", "typst", comment: "types document")
 | 
				
			||||||
 | 
					  _seq("typst", "rust", comment: "compiles content", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("rust", "typst", comment: "renders document", disable-src: true)
 | 
				
			||||||
 | 
					  _seq("typst", "me", comment: "displays document")
 | 
				
			||||||
 | 
					  _evt("typst", "disable")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#stack(dir: ltr, spacing: 1em,
 | 
				
			||||||
 | 
					chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ">", comment: `->`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ">>", comment: `->>`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: "\\", comment: `-\`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: "\\\\", comment: `-\\`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: "/", comment: `-/`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: "//", comment: `-//`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: "x", comment: `->x`)
 | 
				
			||||||
 | 
					  _seq("a", "b", start-tip: "x", comment: `x->`)
 | 
				
			||||||
 | 
					  _seq("a", "b", start-tip: "o", comment: `o->`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ("o", ">"), comment: `->o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", start-tip: "o", end-tip: ("o", ">"), comment: `o->o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", start-tip: ">", end-tip: ">", comment: `<->`)
 | 
				
			||||||
 | 
					  _seq("a", "b", start-tip: ("o", ">"), end-tip: ("o", ">"), comment: `o<->o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", start-tip: "x", end-tip: "x", comment: `x<->x`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ("o", ">>"), comment: `->>o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ("o", "\\"), comment: `-\o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ("o", "\\\\"), comment: `-\\o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ("o", "/"), comment: `-/o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", end-tip: ("o", "//"), comment: `-//o`)
 | 
				
			||||||
 | 
					  _seq("a", "b", start-tip: "x", end-tip: ("o", ">"), comment: `x->o`)
 | 
				
			||||||
 | 
					}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ">", comment: `->`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ">>", comment: `->>`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: "\\", comment: `-\`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: "\\\\", comment: `-\\`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: "/", comment: `-/`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: "//", comment: `-//`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: "x", comment: `->x`)
 | 
				
			||||||
 | 
					  _seq("b", "a", start-tip: "x", comment: `x->`)
 | 
				
			||||||
 | 
					  _seq("b", "a", start-tip: "o", comment: `o->`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ("o", ">"), comment: `->o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", start-tip: "o", end-tip: ("o", ">"), comment: `o->o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", start-tip: ">", end-tip: ">", comment: `<->`)
 | 
				
			||||||
 | 
					  _seq("b", "a", start-tip: ("o", ">"), end-tip: ("o", ">"), comment: `o<->o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", start-tip: "x", end-tip: "x", comment: `x<->x`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ("o", ">>"), comment: `->>o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ("o", "\\"), comment: `-\o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ("o", "\\\\"), comment: `-\\o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ("o", "/"), comment: `-/o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", end-tip: ("o", "//"), comment: `-//o`)
 | 
				
			||||||
 | 
					  _seq("b", "a", start-tip: "x", end-tip: ("o", ">"), comment: `x->o`)
 | 
				
			||||||
 | 
					}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ">", comment: `->`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ">>", comment: `->>`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: "\\", comment: `-\`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: "\\\\", comment: `-\\`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: "/", comment: `-/`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: "//", comment: `-//`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: "x", comment: `->x`)
 | 
				
			||||||
 | 
					  _seq("a", "a", start-tip: "x", comment: `x->`)
 | 
				
			||||||
 | 
					  _seq("a", "a", start-tip: "o", comment: `o->`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ("o", ">"), comment: `->o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", start-tip: "o", end-tip: ("o", ">"), comment: `o->o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", start-tip: ">", end-tip: ">", comment: `<->`)
 | 
				
			||||||
 | 
					  _seq("a", "a", start-tip: ("o", ">"), end-tip: ("o", ">"), comment: `o<->o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", start-tip: "x", end-tip: "x", comment: `x<->x`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ("o", ">>"), comment: `->>o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ("o", "\\"), comment: `-\o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ("o", "\\\\"), comment: `-\\o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ("o", "/"), comment: `-/o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", end-tip: ("o", "//"), comment: `-//o`)
 | 
				
			||||||
 | 
					  _seq("a", "a", start-tip: "x", end-tip: ("o", ">"), comment: `x->o`)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob", show-bottom: false)
 | 
				
			||||||
 | 
					  _par("c", display-name: "Caleb", show-top: false)
 | 
				
			||||||
 | 
					  _par("d", display-name: "Danny", show-bottom: false, show-top: false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					  _par("c", display-name: "Caleb")
 | 
				
			||||||
 | 
					  _par("d", display-name: "Danny")
 | 
				
			||||||
 | 
					  _par("e", display-name: "Erika")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _col("a", "b")
 | 
				
			||||||
 | 
					  _col("b", "c", width: 2cm)
 | 
				
			||||||
 | 
					  _col("c", "d", margin: .5cm)
 | 
				
			||||||
 | 
					  _col("d", "e", min-width: 2cm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  //_seq("b", "c", comment: [Hello World !])
 | 
				
			||||||
 | 
					  //_seq("c", "d", comment: [Hello World])
 | 
				
			||||||
 | 
					  //_seq("d", "e", comment: [Hello World])
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								gallery/ferris.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 25 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								gallery/gitea.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 17 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								gallery/me.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 530 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								gallery/notes.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										145
									
								
								gallery/notes.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,145 @@
 | 
				
			|||||||
 | 
					#import "/src/lib.typ" as chronos: *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#set page(width: auto, height: auto)
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: [hello])
 | 
				
			||||||
 | 
					  _note("left", [this is a first note])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("b", "a", comment: [ok])
 | 
				
			||||||
 | 
					  _note("right", [this is another note])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("b", "b", comment: [I am thinking])
 | 
				
			||||||
 | 
					  _note("left", [a note\ can also be defined\ on several lines])
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _note("left", [This is displayed\ left of Alice.], pos: "a", color: rgb("#00FFFF"))
 | 
				
			||||||
 | 
					  _note("right", [This is displayed right of Alice.], pos: "a")
 | 
				
			||||||
 | 
					  _note("over", [This is displayed over Alice.], pos: "a")
 | 
				
			||||||
 | 
					  _note("over", [This is displayed\ over Bob and Alice.], pos: ("a", "b"), color: rgb("#FFAAAA"))
 | 
				
			||||||
 | 
					  _note("over", [This is yet another\ example of\ a long note.], pos: ("a", "b"))
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("caller")
 | 
				
			||||||
 | 
					  _par("server")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("caller", "server", comment: [conReq])
 | 
				
			||||||
 | 
					  _note("over", [idle], pos: "caller", shape: "hex")
 | 
				
			||||||
 | 
					  _seq("server", "caller", comment: [conConf])
 | 
				
			||||||
 | 
					  _note("over", ["r" as rectangle\ "h" as hexagon], pos: "server", shape: "rect")
 | 
				
			||||||
 | 
					  _note("over", [this is\ on several\ lines], pos: "server", shape: "rect")
 | 
				
			||||||
 | 
					  _note("over", [this is\ on several\ lines], pos: "caller", shape: "hex")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					  _par("c", display-name: "Charlie")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: [m1])
 | 
				
			||||||
 | 
					  _seq("b", "c", comment: [m2])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _note("over", [Old method for note over all part. with:\ `note over FirstPart, LastPart`.], pos: ("a", "c"))
 | 
				
			||||||
 | 
					  _note("across", [New method with:\ `note across`.])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("b", "a")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _note("across", [Note across all part.], shape: "hex")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _note("over", [initial state of Alice], pos: "a")
 | 
				
			||||||
 | 
					  _note("over", [initial state of Bob], pos: "b")
 | 
				
			||||||
 | 
					  _seq("b", "a", comment: [hello])
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("a", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("b", display-name: "Bob")
 | 
				
			||||||
 | 
					  _par("c", display-name: "Charlie")
 | 
				
			||||||
 | 
					  _par("d", display-name: "Donald")
 | 
				
			||||||
 | 
					  _par("e", display-name: "Eddie")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _note("over", [initial state of Alice], pos: "a")
 | 
				
			||||||
 | 
					  _note("over", [initial state of Bob the builder], pos: "b", aligned: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _note("over", [Note 1], pos: "a")
 | 
				
			||||||
 | 
					  _note("over", [Note 2], pos: "b", aligned: true)
 | 
				
			||||||
 | 
					  _note("over", [Note 3], pos: "c", aligned: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "d")
 | 
				
			||||||
 | 
					  _note("over", [this is an extremely long note], pos: ("d", "e"))
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("a", display-name: [Alice])
 | 
				
			||||||
 | 
					  _par("b", display-name: [The *Famous* Bob])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: [hello #strike([there])])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _gap()
 | 
				
			||||||
 | 
					  _seq("b", "a", comment: [ok])
 | 
				
			||||||
 | 
					  _note("left", [
 | 
				
			||||||
 | 
					    This is *bold*\
 | 
				
			||||||
 | 
					    This is _italics_\
 | 
				
			||||||
 | 
					    This is `monospaced`\
 | 
				
			||||||
 | 
					    This is #strike([stroked])\
 | 
				
			||||||
 | 
					    This is #underline([underlined])\
 | 
				
			||||||
 | 
					    This is #underline([waved])\
 | 
				
			||||||
 | 
					  ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: [A _well formatted_ message])
 | 
				
			||||||
 | 
					  _note("right", [
 | 
				
			||||||
 | 
					    This is #box(text([displayed], size: 18pt), fill: rgb("#5F9EA0"))\
 | 
				
			||||||
 | 
					    #underline([left of]) Alice.
 | 
				
			||||||
 | 
					  ], pos: "a")
 | 
				
			||||||
 | 
					  _note("left", [
 | 
				
			||||||
 | 
					    #underline([This], stroke: red) is #text([displayed], fill: rgb("#118888"))\
 | 
				
			||||||
 | 
					    *#text([left of], fill: rgb("#800080")) #strike([Alice], stroke: red) Bob.*
 | 
				
			||||||
 | 
					  ], pos: "b")
 | 
				
			||||||
 | 
					  _note("over", [
 | 
				
			||||||
 | 
					    #underline([This is hosted], stroke: rgb("#FF33FF")) by #box(baseline: 50%, image("gitea.png", width: 1cm, height: 1cm, fit: "contain"))
 | 
				
			||||||
 | 
					  ], pos: ("a", "b"))
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _par("a", display-name: [Alice])
 | 
				
			||||||
 | 
					  _par("b", display-name: [Bob])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("a", "b", comment: [Hello])
 | 
				
			||||||
 | 
					  _note("left", [This is a note])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("[", "a", comment: [Test])
 | 
				
			||||||
 | 
					  _note("left", [This is also a note])
 | 
				
			||||||
 | 
					})*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  _seq("Bob", "Alice", comment: [Hello])
 | 
				
			||||||
 | 
					  _evt("Other", "create")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								gallery/readme/boilerplate.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								gallery/readme/boilerplate.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 12 KiB  | 
							
								
								
									
										13
									
								
								gallery/readme/boilerplate.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					#import "/src/lib.typ" as chronos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#set page(
 | 
				
			||||||
 | 
					  width: auto,
 | 
				
			||||||
 | 
					  height: auto,
 | 
				
			||||||
 | 
					  margin: 0.5cm
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("Alice")
 | 
				
			||||||
 | 
					  _par("Bob")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								gallery/readme/lifelines.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								gallery/readme/lifelines.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 88 KiB  | 
							
								
								
									
										24
									
								
								gallery/readme/lifelines.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					#import "/src/lib.typ" as chronos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#set page(
 | 
				
			||||||
 | 
					  width: auto,
 | 
				
			||||||
 | 
					  height: auto,
 | 
				
			||||||
 | 
					  margin: 0.5cm
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("A", display-name: "Alice")
 | 
				
			||||||
 | 
					  _par("B", display-name: "Bob")
 | 
				
			||||||
 | 
					  _par("C", display-name: "Charlie")
 | 
				
			||||||
 | 
					  _par("D", display-name: "Derek")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("A", "B", comment: "hello", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("B", "B", comment: "self call", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("C", "B", comment: "hello from thread 2", enable-dst: true, lifeline-style: (fill: rgb("#005500")))
 | 
				
			||||||
 | 
					  _seq("B", "D", comment: "create", create-dst: true)
 | 
				
			||||||
 | 
					  _seq("B", "C", comment: "done in thread 2", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					  _seq("B", "B", comment: "rc", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					  _seq("B", "D", comment: "delete", destroy-dst: true)
 | 
				
			||||||
 | 
					  _seq("B", "A", comment: "success", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								gallery/readme/simple_sequence.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								gallery/readme/simple_sequence.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 22 KiB  | 
							
								
								
									
										17
									
								
								gallery/readme/simple_sequence.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					#import "/src/lib.typ" as chronos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#set page(
 | 
				
			||||||
 | 
					  width: auto,
 | 
				
			||||||
 | 
					  height: auto,
 | 
				
			||||||
 | 
					  margin: 0.5cm
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("Alice")
 | 
				
			||||||
 | 
					  _par("Bob")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("Alice", "Bob", comment: "Hello")
 | 
				
			||||||
 | 
					  _seq("Bob", "Bob", comment: "Think")
 | 
				
			||||||
 | 
					  _seq("Bob", "Alice", comment: "Hi")
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								gallery/typst.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 42 KiB  | 
							
								
								
									
										12
									
								
								justfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -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
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								manual.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										238
									
								
								manual.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,238 @@
 | 
				
			|||||||
 | 
					#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"
 | 
				
			||||||
 | 
					#import "docs/example.typ": example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let TYPST = image("gallery/typst.png", width: 1.5cm, height: 1.5cm, fit: "contain")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#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: auto, depth: 3)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#show link: set text(fill: blue)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#set page(numbering: "1/1", header: align(right)[chronos #sym.dash.em v#chronos.version])
 | 
				
			||||||
 | 
					#set page(
 | 
				
			||||||
 | 
					  header: align(left)[chronos #sym.dash.em v#chronos.version],
 | 
				
			||||||
 | 
					  footer: context align(center, counter(page).display("1/1", both: true))
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					= Introduction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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:
 | 
				
			||||||
 | 
					#raw(block:true, lang: "typ", ```typ
 | 
				
			||||||
 | 
					$import
 | 
				
			||||||
 | 
					#chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  ...
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```.text.replace("$import", import-stmt))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					= Examples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can find the following examples and more in the #link("https://git.kb28.ch/HEL/circuiteria/src/branch/main/gallery")[gallery] directory
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					== Some groups and sequences
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#example(```
 | 
				
			||||||
 | 
					chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _seq("Alice", "Bob", comment: "Authentication Request")
 | 
				
			||||||
 | 
					  _seq("Bob", "Alice", comment: "Authentication Failure")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _grp("My own label", desc: "My own label2", {
 | 
				
			||||||
 | 
					    _seq("Alice", "Log", comment: "Log attack start")
 | 
				
			||||||
 | 
					    _grp("loop", desc: "1000 times", {
 | 
				
			||||||
 | 
					      _seq("Alice", "Bob", comment: "DNS Attack")
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    _seq("Alice", "Bob", comment: "Log attack end")
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```, wrap: false, vertical: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					== Lifelines
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#example(```
 | 
				
			||||||
 | 
					chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _seq("alice", "bob", comment: "hello", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("bob", "bob", comment: "self call", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq(
 | 
				
			||||||
 | 
					    "bill", "bob",
 | 
				
			||||||
 | 
					    comment: "hello from thread 2",
 | 
				
			||||||
 | 
					    enable-dst: true,
 | 
				
			||||||
 | 
					    lifeline-style: (fill: rgb("#005500"))
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  _seq("bob", "george", comment: "create", create-dst: true)
 | 
				
			||||||
 | 
					  _seq(
 | 
				
			||||||
 | 
					    "bob", "bill",
 | 
				
			||||||
 | 
					    comment: "done in thread 2",
 | 
				
			||||||
 | 
					    disable-src: true,
 | 
				
			||||||
 | 
					    dashed: true
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  _seq("bob", "bob", comment: "rc", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					  _seq("bob", "george", comment: "delete", destroy-dst: true)
 | 
				
			||||||
 | 
					  _seq("bob", "alice", comment: "success", disable-src: true, dashed: true)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```, wrap: false, vertical: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					== Found and lost messages
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#example(```
 | 
				
			||||||
 | 
					chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _seq("?", "Alice", comment: [?->\ *short* to actor1])
 | 
				
			||||||
 | 
					  _seq("[", "Alice", comment: [\[->\ *from start* to actor1])
 | 
				
			||||||
 | 
					  _seq("[", "Bob", comment: [\[->\ *from start* to actor2])
 | 
				
			||||||
 | 
					  _seq("?", "Bob", comment: [?->\ *short* to actor2])
 | 
				
			||||||
 | 
					  _seq("Alice", "]", comment: [->\]\ from actor1 *to end*])
 | 
				
			||||||
 | 
					  _seq("Alice", "?", comment: [->?\ *short* from actor1])
 | 
				
			||||||
 | 
					  _seq("Alice", "Bob", comment: [->\ from actor1 to actor2])
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```, wrap: false, vertical: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					== Custom images
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#example(```
 | 
				
			||||||
 | 
					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")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chronos.diagram({
 | 
				
			||||||
 | 
					  import chronos: *
 | 
				
			||||||
 | 
					  _par("me", display-name: "Me", shape: "custom", custom-image: ME)
 | 
				
			||||||
 | 
					  _par("typst", display-name: "Typst", shape: "custom", custom-image: TYPST)
 | 
				
			||||||
 | 
					  _par("rust", display-name: "Rust", shape: "custom", custom-image: FERRIS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _seq("me", "typst", comment: "opens document", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("me", "typst", comment: "types document")
 | 
				
			||||||
 | 
					  _seq("typst", "rust", comment: "compiles content", enable-dst: true)
 | 
				
			||||||
 | 
					  _seq("rust", "typst", comment: "renders document", disable-src: true)
 | 
				
			||||||
 | 
					  _seq("typst", "me", comment: "displays document", disable-src: true)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					```, wrap: false, vertical: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					= Reference
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let par-docs = tidy.parse-module(
 | 
				
			||||||
 | 
					  read("docs/participants.typ"),
 | 
				
			||||||
 | 
					  name: "Participants",
 | 
				
			||||||
 | 
					  require-all-parameters: true,
 | 
				
			||||||
 | 
					  old-syntax: true,
 | 
				
			||||||
 | 
					  scope: (
 | 
				
			||||||
 | 
					    chronos: chronos,
 | 
				
			||||||
 | 
					    mod-par: mod-par,
 | 
				
			||||||
 | 
					    TYPST: TYPST
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					#tidy.show-module(par-docs, show-outline: false, sort-functions: none)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let seq-docs = tidy.parse-module(
 | 
				
			||||||
 | 
					  read("docs/sequences.typ"),
 | 
				
			||||||
 | 
					  name: "Sequences",
 | 
				
			||||||
 | 
					  require-all-parameters: true,
 | 
				
			||||||
 | 
					  old-syntax: true,
 | 
				
			||||||
 | 
					  scope: (
 | 
				
			||||||
 | 
					    chronos: chronos,
 | 
				
			||||||
 | 
					    examples: examples
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					#tidy.show-module(seq-docs, show-outline: false, sort-functions: none)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let grp-docs = tidy.parse-module(
 | 
				
			||||||
 | 
					  read("docs/groups.typ"),
 | 
				
			||||||
 | 
					  name: "Groups",
 | 
				
			||||||
 | 
					  require-all-parameters: true,
 | 
				
			||||||
 | 
					  old-syntax: true,
 | 
				
			||||||
 | 
					  scope: (
 | 
				
			||||||
 | 
					    chronos: chronos,
 | 
				
			||||||
 | 
					    examples: examples
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					#tidy.show-module(grp-docs, show-outline: false, sort-functions: none)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let gap-sep-docs = tidy.parse-module(
 | 
				
			||||||
 | 
					  read("docs/gaps_seps.typ"),
 | 
				
			||||||
 | 
					  name: "Gaps and separators",
 | 
				
			||||||
 | 
					  require-all-parameters: true,
 | 
				
			||||||
 | 
					  old-syntax: true,
 | 
				
			||||||
 | 
					  scope: (
 | 
				
			||||||
 | 
					    chronos: chronos,
 | 
				
			||||||
 | 
					    examples: examples
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					#tidy.show-module(gap-sep-docs, show-outline: false, sort-functions: none)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pagebreak(weak: true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let notes-docs = tidy.parse-module(
 | 
				
			||||||
 | 
					  read("docs/notes.typ"),
 | 
				
			||||||
 | 
					  name: "Notes",
 | 
				
			||||||
 | 
					  require-all-parameters: true,
 | 
				
			||||||
 | 
					  old-syntax: true,
 | 
				
			||||||
 | 
					  scope: (
 | 
				
			||||||
 | 
					    chronos: chronos,
 | 
				
			||||||
 | 
					    examples: examples
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					#tidy.show-module(notes-docs, show-outline: false)
 | 
				
			||||||
@@ -2,6 +2,10 @@
 | 
				
			|||||||
#let PAR-SPACE = 10
 | 
					#let PAR-SPACE = 10
 | 
				
			||||||
#let COMMENT-PAD = 8
 | 
					#let COMMENT-PAD = 8
 | 
				
			||||||
#let LIFELINE-W = 10
 | 
					#let LIFELINE-W = 10
 | 
				
			||||||
 | 
					#let CREATE-OFFSET = 15
 | 
				
			||||||
 | 
					#let DEFAULT-SLANT = 10
 | 
				
			||||||
 | 
					#let CROSS-TIP-SIZE = 4
 | 
				
			||||||
 | 
					#let CIRCLE-TIP-RADIUS = 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let SYM-GAP = 5
 | 
					#let SYM-GAP = 5
 | 
				
			||||||
#let PAR-PAD = (5pt, 3pt)
 | 
					#let PAR-PAD = (5pt, 3pt)
 | 
				
			||||||
@@ -15,6 +19,12 @@
 | 
				
			|||||||
#let COLLECTIONS-DY = 3
 | 
					#let COLLECTIONS-DY = 3
 | 
				
			||||||
#let QUEUE-PAD = (5pt, 3pt)
 | 
					#let QUEUE-PAD = (5pt, 3pt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let NOTE-PAD = (6, 3)
 | 
				
			||||||
 | 
					#let NOTE-CORNER-SIZE = 6
 | 
				
			||||||
 | 
					#let NOTE-GAP = 3
 | 
				
			||||||
 | 
					#let NOTE-HEX-PAD = (6, 8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let COL-DESTRUCTION = rgb("#A80238")
 | 
					#let COL-DESTRUCTION = rgb("#A80238")
 | 
				
			||||||
#let COL-GRP-NAME = rgb("#EEEEEE")
 | 
					#let COL-GRP-NAME = rgb("#EEEEEE")
 | 
				
			||||||
#let COL-SEP-NAME = rgb("#EEEEEE")
 | 
					#let COL-SEP-NAME = rgb("#EEEEEE")
 | 
				
			||||||
 | 
					#let COL-NOTE = rgb("#FEFFDD")
 | 
				
			||||||
							
								
								
									
										148
									
								
								src/diagram.typ
									
									
									
									
									
								
							
							
						
						@@ -1,6 +1,7 @@
 | 
				
			|||||||
#import "utils.typ": get-group-span
 | 
					#import "utils.typ": get-group-span, fit-canvas
 | 
				
			||||||
#import "renderer.typ": render
 | 
					#import "renderer.typ": render
 | 
				
			||||||
#import "participant.typ" as participant: _par, PAR-SPECIALS
 | 
					#import "participant.typ" as participant: _par, PAR-SPECIALS
 | 
				
			||||||
 | 
					#import "sequence.typ": _seq
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let _gap(size: 20) = {
 | 
					#let _gap(size: 20) = {
 | 
				
			||||||
  return ((
 | 
					  return ((
 | 
				
			||||||
@@ -9,7 +10,28 @@
 | 
				
			|||||||
  ),)
 | 
					  ),)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let diagram(elements) = {
 | 
					#let _evt(participant, event) = {
 | 
				
			||||||
 | 
					  return ((
 | 
				
			||||||
 | 
					    type: "evt",
 | 
				
			||||||
 | 
					    participant: participant,
 | 
				
			||||||
 | 
					    event: event,
 | 
				
			||||||
 | 
					    lifeline-style: auto
 | 
				
			||||||
 | 
					  ),)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _col(p1, p2, width: auto, margin: 0, min-width: 0, max-width: none) = {
 | 
				
			||||||
 | 
					  return ((
 | 
				
			||||||
 | 
					    type: "col",
 | 
				
			||||||
 | 
					    p1: p1,
 | 
				
			||||||
 | 
					    p2: p2,
 | 
				
			||||||
 | 
					    width: width,
 | 
				
			||||||
 | 
					    margin: margin,
 | 
				
			||||||
 | 
					    min-width: min-width,
 | 
				
			||||||
 | 
					    max-width: max-width
 | 
				
			||||||
 | 
					  ),)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let diagram(elements, width: auto) = {
 | 
				
			||||||
  if elements == none {
 | 
					  if elements == none {
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -18,11 +40,12 @@
 | 
				
			|||||||
  let elmts = elements
 | 
					  let elmts = elements
 | 
				
			||||||
  let i = 0
 | 
					  let i = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Flatten groups
 | 
					  let activation-history = ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Flatten groups + convert returns
 | 
				
			||||||
  while i < elmts.len() {
 | 
					  while i < elmts.len() {
 | 
				
			||||||
    let elmt = elmts.at(i)
 | 
					    let elmt = elmts.at(i)
 | 
				
			||||||
    if elmt.type == "grp" {
 | 
					    if elmt.type == "grp" {
 | 
				
			||||||
      let grp-elmts = elmt.elmts
 | 
					 | 
				
			||||||
      elmt.elmts = elmt.elmts.map(e => {
 | 
					      elmt.elmts = elmt.elmts.map(e => {
 | 
				
			||||||
        if e.type == "seq" {
 | 
					        if e.type == "seq" {
 | 
				
			||||||
          if e.p1 == "?" {
 | 
					          if e.p1 == "?" {
 | 
				
			||||||
@@ -36,19 +59,50 @@
 | 
				
			|||||||
      elmts.at(i) = elmt
 | 
					      elmts.at(i) = elmt
 | 
				
			||||||
      elmts = (
 | 
					      elmts = (
 | 
				
			||||||
        elmts.slice(0, i + 1) +
 | 
					        elmts.slice(0, i + 1) +
 | 
				
			||||||
        grp-elmts +
 | 
					        elmt.elmts +
 | 
				
			||||||
        ((
 | 
					        ((
 | 
				
			||||||
          type: "grp-end"
 | 
					          type: "grp-end",
 | 
				
			||||||
 | 
					          start-i: i
 | 
				
			||||||
        ),) +
 | 
					        ),) +
 | 
				
			||||||
        elmts.slice(i+1)
 | 
					        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)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } else if elmt.type == "evt" {
 | 
				
			||||||
 | 
					      if elmt.event == "enable" {
 | 
				
			||||||
 | 
					        for elmt2 in elmts.slice(0, i).rev() {
 | 
				
			||||||
 | 
					          if elmt2.type == "seq" {
 | 
				
			||||||
 | 
					            activation-history.push(elmt2)
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } else if elmt.type == "ret" {
 | 
				
			||||||
 | 
					      if activation-history.len() == 0 {
 | 
				
			||||||
 | 
					        panic("Cannot return if no lifeline is activated")
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      let seq = activation-history.pop()
 | 
				
			||||||
 | 
					      elmts.at(i) = _seq(
 | 
				
			||||||
 | 
					        seq.p2, seq.p1,
 | 
				
			||||||
 | 
					        comment: elmt.comment,
 | 
				
			||||||
 | 
					        disable-src: true,
 | 
				
			||||||
 | 
					        dashed: true
 | 
				
			||||||
 | 
					      ).first()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    i += 1
 | 
					    i += 1
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // List participants
 | 
					  // List participants
 | 
				
			||||||
  let linked = ()
 | 
					  let linked = ()
 | 
				
			||||||
  for elmt in elmts {
 | 
					  let last-seq = none
 | 
				
			||||||
 | 
					  let last-note = none
 | 
				
			||||||
 | 
					  for (i, elmt) in elmts.enumerate() {
 | 
				
			||||||
    if elmt.type == "par" {
 | 
					    if elmt.type == "par" {
 | 
				
			||||||
      participants.push(elmt)
 | 
					      participants.push(elmt)
 | 
				
			||||||
    } else if elmt.type == "seq" {
 | 
					    } else if elmt.type == "seq" {
 | 
				
			||||||
@@ -64,15 +118,78 @@
 | 
				
			|||||||
        participants.at(i).from-start = false
 | 
					        participants.at(i).from-start = false
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      let p1 = elmt.p1
 | 
				
			||||||
 | 
					      let p2 = elmt.p2
 | 
				
			||||||
      if elmt.p1 == "?" {
 | 
					      if elmt.p1 == "?" {
 | 
				
			||||||
        linked.push("?" + elmt.p2)
 | 
					        p1 = "?" + elmt.p2
 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
        linked.push(elmt.p1)
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if elmt.p2 == "?" {
 | 
					      if elmt.p2 == "?" {
 | 
				
			||||||
        linked.push(elmt.p1 + "?")
 | 
					        p2 = elmt.p1 + "?"
 | 
				
			||||||
      } else {
 | 
					      }
 | 
				
			||||||
        linked.push(elmt.p2)
 | 
					      linked.push(p1)
 | 
				
			||||||
 | 
					      linked.push(p2)
 | 
				
			||||||
 | 
					      last-seq = (
 | 
				
			||||||
 | 
					        elmt: elmt,
 | 
				
			||||||
 | 
					        i: i,
 | 
				
			||||||
 | 
					        p1: p1,
 | 
				
			||||||
 | 
					        p2: p2
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    } else if elmt.type == "note" {
 | 
				
			||||||
 | 
					      elmt.insert("linked", elmt.pos == none and elmt.side != "across")
 | 
				
			||||||
 | 
					      if elmt.pos == none and elmt.side != "across" {
 | 
				
			||||||
 | 
					        let names = participants.map(p => p.name)
 | 
				
			||||||
 | 
					        let i1 = names.position(n => n == last-seq.p1)
 | 
				
			||||||
 | 
					        let i2 = names.position(n => n == last-seq.p2)
 | 
				
			||||||
 | 
					        let pars = ((i1, last-seq.p1), (i2, last-seq.p2)).sorted(key: p => p.first())
 | 
				
			||||||
 | 
					        if elmt.side == "left" {
 | 
				
			||||||
 | 
					          elmt.pos = pars.first().last()
 | 
				
			||||||
 | 
					        } else if elmt.side == "right" {
 | 
				
			||||||
 | 
					          elmt.pos = pars.last().last()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let seq = last-seq.elmt
 | 
				
			||||||
 | 
					        seq.insert("linked-note", elmt)
 | 
				
			||||||
 | 
					        elmts.at(last-seq.i) = seq
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if elmt.aligned {
 | 
				
			||||||
 | 
					        let n = last-note.elmt
 | 
				
			||||||
 | 
					        n.aligned-with = elmt
 | 
				
			||||||
 | 
					        elmts.at(last-note.i) = n
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      elmts.at(i) = elmt
 | 
				
			||||||
 | 
					      if elmt.side == "left" {
 | 
				
			||||||
 | 
					        linked.push("[")
 | 
				
			||||||
 | 
					      } else if elmt.side == "right" {
 | 
				
			||||||
 | 
					        linked.push("]")
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      let pars = none
 | 
				
			||||||
 | 
					      if type(elmt.pos) == str {
 | 
				
			||||||
 | 
					        pars = (elmt.pos,)
 | 
				
			||||||
 | 
					      } else if type(elmt.pos) == array {
 | 
				
			||||||
 | 
					        pars = elmt.pos
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if pars != none {
 | 
				
			||||||
 | 
					        for par in pars {
 | 
				
			||||||
 | 
					          if not participant._exists(participants, par) {
 | 
				
			||||||
 | 
					            participants.push(_par(par).first())
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      last-note = (
 | 
				
			||||||
 | 
					        elmt: elmt,
 | 
				
			||||||
 | 
					        i: i
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    } else if elmt.type == "evt" {
 | 
				
			||||||
 | 
					      let par = elmt.participant
 | 
				
			||||||
 | 
					      if not participant._exists(participants, par) {
 | 
				
			||||||
 | 
					        let p = _par(par, from-start: elmt.event != "create").first()
 | 
				
			||||||
 | 
					        participants.push(p)
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      } else if elmt.event == "create" {
 | 
				
			||||||
 | 
					        let i = participants.position(p => p.name == par)
 | 
				
			||||||
 | 
					        participants.at(i).from-start = false
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -115,7 +232,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // Compute groups spans (horizontal)
 | 
					  // Compute groups spans (horizontal)
 | 
				
			||||||
  for (i, elmt) in elmts.enumerate() {
 | 
					  for (i, elmt) in elmts.enumerate() {
 | 
				
			||||||
    if elmt.type == "grp" {
 | 
					    if elmt.type == "grp" or elmt.type == "alt" {
 | 
				
			||||||
      let (min-i, max-i) = get-group-span(participants, elmt)
 | 
					      let (min-i, max-i) = get-group-span(participants, elmt)
 | 
				
			||||||
      elmts.at(i).insert("min-i", min-i)
 | 
					      elmts.at(i).insert("min-i", min-i)
 | 
				
			||||||
      elmts.at(i).insert("max-i", max-i)
 | 
					      elmts.at(i).insert("max-i", max-i)
 | 
				
			||||||
@@ -128,7 +245,8 @@
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  render(participants, elmts)
 | 
					  let canvas = render(participants, elmts)
 | 
				
			||||||
 | 
					  fit-canvas(canvas, width: width)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let from-plantuml(code) = {
 | 
					#let from-plantuml(code) = {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
#import "@preview/cetz:0.2.2": draw
 | 
					#import "/src/cetz.typ": draw
 | 
				
			||||||
#import "consts.typ": *
 | 
					#import "consts.typ": *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let _grp(name, desc: none, type: "default", elmts) = {
 | 
					#let _grp(name, desc: none, type: "default", elmts) = {
 | 
				
			||||||
@@ -11,6 +11,36 @@
 | 
				
			|||||||
  ),)
 | 
					  ),)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _alt(desc, elmts, ..args) = {
 | 
				
			||||||
 | 
					  let all-elmts = ()
 | 
				
			||||||
 | 
					  all-elmts += elmts
 | 
				
			||||||
 | 
					  let args = args.pos()
 | 
				
			||||||
 | 
					  for i in range(0, args.len(), step: 2) {
 | 
				
			||||||
 | 
					    let else-desc = args.at(i)
 | 
				
			||||||
 | 
					    let else-elmts = args.at(i + 1, default: ())
 | 
				
			||||||
 | 
					    all-elmts.push((
 | 
				
			||||||
 | 
					      type: "else",
 | 
				
			||||||
 | 
					      desc: else-desc
 | 
				
			||||||
 | 
					    ))
 | 
				
			||||||
 | 
					    all-elmts += else-elmts
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return _grp("alt", desc: desc, type: "alt", all-elmts)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _loop(desc, min: none, max: auto, elmts) = {
 | 
				
			||||||
 | 
					  let name = "loop"
 | 
				
			||||||
 | 
					  if min != none {
 | 
				
			||||||
 | 
					    if max == auto {
 | 
				
			||||||
 | 
					      max = "*"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    name += "(" + str(min) + "," + str(max) + ")"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  _grp(name, desc: desc, type: "loop", elmts)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#let _opt(desc, elmts) = grp("opt", desc: desc, type: "opt", elmts)
 | 
				
			||||||
 | 
					#let _break(desc, elmts) = grp("break", desc: desc, type: "break", elmts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let render(x0, x1, y0, y1, group) = {
 | 
					#let render(x0, x1, y0, y1, group) = {
 | 
				
			||||||
  let shapes = ()
 | 
					  let shapes = ()
 | 
				
			||||||
  let name = text(group.name, weight: "bold")
 | 
					  let name = text(group.name, weight: "bold")
 | 
				
			||||||
@@ -44,7 +74,7 @@
 | 
				
			|||||||
  if group.desc != none {
 | 
					  if group.desc != none {
 | 
				
			||||||
    shapes += draw.content(
 | 
					    shapes += draw.content(
 | 
				
			||||||
      (x0 + w, y0),
 | 
					      (x0 + w, y0),
 | 
				
			||||||
      text([\[#group.desc\]], weight: "bold"),
 | 
					      text([\[#group.desc\]], weight: "bold", size: .8em),
 | 
				
			||||||
      anchor: "north-west",
 | 
					      anchor: "north-west",
 | 
				
			||||||
      padding: 3pt
 | 
					      padding: 3pt
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
@@ -52,3 +82,18 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  return shapes
 | 
					  return shapes
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let render-else(x0, x1, y, elmt) = {
 | 
				
			||||||
 | 
					  let shapes = draw.line(
 | 
				
			||||||
 | 
					    (x0, y),
 | 
				
			||||||
 | 
					    (x1, y),
 | 
				
			||||||
 | 
					    stroke: (dash: (2pt, 1pt), thickness: .5pt)
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  shapes += draw.content(
 | 
				
			||||||
 | 
					    (x0, y),
 | 
				
			||||||
 | 
					    text([\[#elmt.desc\]], weight: "bold", size: .8em),
 | 
				
			||||||
 | 
					    anchor: "north-west",
 | 
				
			||||||
 | 
					    padding: 3pt
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  return shapes
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										11
									
								
								src/lib.typ
									
									
									
									
									
								
							
							
						
						@@ -1,6 +1,9 @@
 | 
				
			|||||||
#import "diagram.typ": diagram, from-plantuml, _gap
 | 
					#let version = version(0, 2, 1)
 | 
				
			||||||
 | 
					#import "diagram.typ": diagram, from-plantuml, _gap, _evt, _col
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#import "sequence.typ": _seq
 | 
					#import "sequence.typ": _seq, _ret
 | 
				
			||||||
#import "group.typ": _grp
 | 
					#import "group.typ": _grp, _loop, _alt, _opt, _break
 | 
				
			||||||
#import "participant.typ": _par
 | 
					#import "participant.typ": _par
 | 
				
			||||||
#import "separator.typ": _sep
 | 
					#import "separator.typ": _sep, _delay
 | 
				
			||||||
 | 
					#import "note.typ": _note
 | 
				
			||||||
 | 
					#import "sync.typ": _sync
 | 
				
			||||||
							
								
								
									
										185
									
								
								src/note.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,185 @@
 | 
				
			|||||||
 | 
					#import "/src/cetz.typ": draw
 | 
				
			||||||
 | 
					#import "consts.typ": *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let SIDES = (
 | 
				
			||||||
 | 
					  "left",
 | 
				
			||||||
 | 
					  "right",
 | 
				
			||||||
 | 
					  "over",
 | 
				
			||||||
 | 
					  "across"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let SHAPES = (
 | 
				
			||||||
 | 
					  "default",
 | 
				
			||||||
 | 
					  "rect",
 | 
				
			||||||
 | 
					  "hex"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _note(side, content, pos: none, color: COL-NOTE, shape: "default", aligned: false) = {
 | 
				
			||||||
 | 
					  if side == "over" {
 | 
				
			||||||
 | 
					    if pos == none {
 | 
				
			||||||
 | 
					      panic("Pos cannot be none with side 'over'")
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if aligned {
 | 
				
			||||||
 | 
					    if side != "over" {
 | 
				
			||||||
 | 
					      panic("Aligned notes can only be over a participant (got side '" + side + "')")
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if color == auto {
 | 
				
			||||||
 | 
					    color = COL-NOTE
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return ((
 | 
				
			||||||
 | 
					    type: "note",
 | 
				
			||||||
 | 
					    side: side,
 | 
				
			||||||
 | 
					    content: content,
 | 
				
			||||||
 | 
					    pos: pos,
 | 
				
			||||||
 | 
					    color: color,
 | 
				
			||||||
 | 
					    shape: shape,
 | 
				
			||||||
 | 
					    aligned: aligned,
 | 
				
			||||||
 | 
					    aligned-with: none
 | 
				
			||||||
 | 
					  ),)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let get-note-box(note) = {
 | 
				
			||||||
 | 
					  let PAD = if note.shape == "hex" {NOTE-HEX-PAD} else {NOTE-PAD}
 | 
				
			||||||
 | 
					  let inset = (
 | 
				
			||||||
 | 
					    left: PAD.last() * 1pt,
 | 
				
			||||||
 | 
					    right: PAD.last() * 1pt,
 | 
				
			||||||
 | 
					    top: PAD.first() * 1pt,
 | 
				
			||||||
 | 
					    bottom: PAD.first() * 1pt,
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  if note.shape == "default" {
 | 
				
			||||||
 | 
					    inset.right += NOTE-CORNER-SIZE * 1pt
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if note.side == "left" {
 | 
				
			||||||
 | 
					    inset.right += NOTE-GAP * 1pt
 | 
				
			||||||
 | 
					  } else if note.side == "right" {
 | 
				
			||||||
 | 
					    inset.left += NOTE-GAP * 1pt
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return box(note.content, inset: inset)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let get-size(note) = {
 | 
				
			||||||
 | 
					  let PAD = if note.shape == "hex" {NOTE-HEX-PAD} else {NOTE-PAD}
 | 
				
			||||||
 | 
					  let m = measure(box(note.content))
 | 
				
			||||||
 | 
					  let w = m.width / 1pt + PAD.last() * 2
 | 
				
			||||||
 | 
					  let h = m.height / 1pt + PAD.first() * 2
 | 
				
			||||||
 | 
					  if note.shape == "default" {
 | 
				
			||||||
 | 
					    w += NOTE-CORNER-SIZE
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    width: w,
 | 
				
			||||||
 | 
					    height: h
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _get-base-x(pars-i, x-pos, note) = {
 | 
				
			||||||
 | 
					  if note.side == "across" {
 | 
				
			||||||
 | 
					    return (x-pos.first() + x-pos.last()) / 2
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if note.side == "over" {
 | 
				
			||||||
 | 
					    if type(note.pos) == array {
 | 
				
			||||||
 | 
					      let xs = note.pos.map(par => x-pos.at(pars-i.at(par)))
 | 
				
			||||||
 | 
					      return (calc.min(..xs) + calc.max(..xs)) / 2
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return x-pos.at(pars-i.at(note.pos))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let render(pars-i, x-pos, note, y, lifelines) = {
 | 
				
			||||||
 | 
					  let shapes = ()
 | 
				
			||||||
 | 
					  let PAD = if note.shape == "hex" {NOTE-HEX-PAD} else {NOTE-PAD}
 | 
				
			||||||
 | 
					  let m = measure(box(note.content))
 | 
				
			||||||
 | 
					  let w = m.width / 1pt + PAD.last() * 2
 | 
				
			||||||
 | 
					  let h = m.height / 1pt + PAD.first() * 2
 | 
				
			||||||
 | 
					  let total-w = w
 | 
				
			||||||
 | 
					  if note.shape == "default" {
 | 
				
			||||||
 | 
					    total-w += NOTE-CORNER-SIZE
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let base-x = _get-base-x(pars-i, x-pos, note)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let i = none
 | 
				
			||||||
 | 
					  if note.pos != none and type(note.pos) == str {
 | 
				
			||||||
 | 
					    i = pars-i.at(note.pos)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  let x0 = base-x
 | 
				
			||||||
 | 
					  if note.side == "left" {
 | 
				
			||||||
 | 
					    x0 -= NOTE-GAP
 | 
				
			||||||
 | 
					    x0 -= total-w
 | 
				
			||||||
 | 
					    if lifelines.at(i).level != 0 {
 | 
				
			||||||
 | 
					      x0 -= LIFELINE-W / 2
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  } else if note.side == "right" {
 | 
				
			||||||
 | 
					    x0 += NOTE-GAP
 | 
				
			||||||
 | 
					    x0 += lifelines.at(i).level * LIFELINE-W / 2
 | 
				
			||||||
 | 
					  } else if note.side == "over" or note.side == "across" {
 | 
				
			||||||
 | 
					    x0 -= total-w / 2
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let x1 = x0 + w
 | 
				
			||||||
 | 
					  let x2 = x0 + total-w
 | 
				
			||||||
 | 
					  let y0 = y
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if note.linked {
 | 
				
			||||||
 | 
					    y0 += h / 2
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  let y1 = y0 - h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if note.shape == "default" {
 | 
				
			||||||
 | 
					    shapes += draw.merge-path(
 | 
				
			||||||
 | 
					      stroke: black + .5pt,
 | 
				
			||||||
 | 
					      fill: note.color,
 | 
				
			||||||
 | 
					      close: true,
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        draw.line(
 | 
				
			||||||
 | 
					          (x0, y0),
 | 
				
			||||||
 | 
					          (x1, y0),
 | 
				
			||||||
 | 
					          (x2, y0 - NOTE-CORNER-SIZE),
 | 
				
			||||||
 | 
					          (x2, y1),
 | 
				
			||||||
 | 
					          (x0, y1)
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    shapes += draw.line((x1, y0), (x1, y0 - NOTE-CORNER-SIZE), (x2, y0 - NOTE-CORNER-SIZE), stroke: black + .5pt)
 | 
				
			||||||
 | 
					  } else if note.shape == "rect" {
 | 
				
			||||||
 | 
					    shapes += draw.rect(
 | 
				
			||||||
 | 
					      (x0, y0),
 | 
				
			||||||
 | 
					      (x2, y1),
 | 
				
			||||||
 | 
					      stroke: black + .5pt,
 | 
				
			||||||
 | 
					      fill: note.color
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  } else if note.shape == "hex" {
 | 
				
			||||||
 | 
					    let lx = x0 + PAD.last()
 | 
				
			||||||
 | 
					    let rx = x2 - PAD.last()
 | 
				
			||||||
 | 
					    let my = (y0 + y1) / 2
 | 
				
			||||||
 | 
					    shapes += draw.merge-path(
 | 
				
			||||||
 | 
					      stroke: black + .5pt,
 | 
				
			||||||
 | 
					      fill: note.color,
 | 
				
			||||||
 | 
					      close: true,
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        draw.line(
 | 
				
			||||||
 | 
					          (lx, y0),
 | 
				
			||||||
 | 
					          (rx, y0),
 | 
				
			||||||
 | 
					          (x2, my),
 | 
				
			||||||
 | 
					          (rx, y1),
 | 
				
			||||||
 | 
					          (lx, y1),
 | 
				
			||||||
 | 
					          (x0, my),
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  shapes += draw.content(
 | 
				
			||||||
 | 
					    ((x0 + x1)/2, (y0 + y1)/2),
 | 
				
			||||||
 | 
					    note.content,
 | 
				
			||||||
 | 
					    anchor: "center"
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if note.aligned-with == none and (note.pos != none or note.side == "across") {
 | 
				
			||||||
 | 
					    y -= h
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let r = (y, shapes)
 | 
				
			||||||
 | 
					  return r
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
#import "@preview/cetz:0.2.2": draw
 | 
					#import "/src/cetz.typ": draw
 | 
				
			||||||
#import "consts.typ": *
 | 
					#import "consts.typ": *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let PAR-SPECIALS = "?[]"
 | 
					#let PAR-SPECIALS = "?[]"
 | 
				
			||||||
@@ -13,6 +13,7 @@
 | 
				
			|||||||
  "queue",
 | 
					  "queue",
 | 
				
			||||||
  "custom"
 | 
					  "custom"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					#let DEFAULT-COLOR = rgb("#E2E2F0")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let _par(
 | 
					#let _par(
 | 
				
			||||||
  name,
 | 
					  name,
 | 
				
			||||||
@@ -20,9 +21,14 @@
 | 
				
			|||||||
  from-start: true,
 | 
					  from-start: true,
 | 
				
			||||||
  invisible: false,
 | 
					  invisible: false,
 | 
				
			||||||
  shape: "participant",
 | 
					  shape: "participant",
 | 
				
			||||||
  color: rgb("#E2E2F0"),
 | 
					  color: DEFAULT-COLOR,
 | 
				
			||||||
  custom-image: none
 | 
					  custom-image: none,
 | 
				
			||||||
 | 
					  show-bottom: true,
 | 
				
			||||||
 | 
					  show-top: true,
 | 
				
			||||||
) = {
 | 
					) = {
 | 
				
			||||||
 | 
					  if color == auto {
 | 
				
			||||||
 | 
					    color = DEFAULT-COLOR
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  return ((
 | 
					  return ((
 | 
				
			||||||
    type: "par",
 | 
					    type: "par",
 | 
				
			||||||
    name: name,
 | 
					    name: name,
 | 
				
			||||||
@@ -31,7 +37,9 @@
 | 
				
			|||||||
    invisible: invisible,
 | 
					    invisible: invisible,
 | 
				
			||||||
    shape: shape,
 | 
					    shape: shape,
 | 
				
			||||||
    color: color,
 | 
					    color: color,
 | 
				
			||||||
    custom-image: custom-image
 | 
					    custom-image: custom-image,
 | 
				
			||||||
 | 
					    show-bottom: show-bottom,
 | 
				
			||||||
 | 
					    show-top: show-top
 | 
				
			||||||
  ),)
 | 
					  ),)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										261
									
								
								src/renderer.typ
									
									
									
									
									
								
							
							
						
						@@ -1,11 +1,13 @@
 | 
				
			|||||||
#import "@preview/cetz:0.2.2": canvas, draw
 | 
					#import "/src/cetz.typ": canvas, draw
 | 
				
			||||||
#import "utils.typ": get-participants-i, get-style
 | 
					#import "utils.typ": get-participants-i, get-style, normalize-units
 | 
				
			||||||
#import "group.typ"
 | 
					#import "group.typ"
 | 
				
			||||||
#import "participant.typ"
 | 
					#import "participant.typ"
 | 
				
			||||||
#import participant: PAR-SPECIALS
 | 
					#import participant: PAR-SPECIALS
 | 
				
			||||||
#import "sequence.typ"
 | 
					#import "sequence.typ"
 | 
				
			||||||
#import "separator.typ"
 | 
					#import "separator.typ"
 | 
				
			||||||
 | 
					#import "sync.typ"
 | 
				
			||||||
#import "consts.typ": *
 | 
					#import "consts.typ": *
 | 
				
			||||||
 | 
					#import "note.typ" as note: get-note-box
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let DEBUG-INVISIBLE = false
 | 
					#let DEBUG-INVISIBLE = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -18,6 +20,16 @@
 | 
				
			|||||||
  let pars-i = get-participants-i(participants)
 | 
					  let pars-i = get-participants-i(participants)
 | 
				
			||||||
  let cells = ()
 | 
					  let cells = ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Unwrap syncs
 | 
				
			||||||
 | 
					  let i = 0
 | 
				
			||||||
 | 
					  while i < elements.len() {
 | 
				
			||||||
 | 
					    let elmt = elements.at(i)
 | 
				
			||||||
 | 
					    if elmt.type == "sync" {
 | 
				
			||||||
 | 
					      elements = elements.slice(0, i + 1) + elmt.elmts + elements.slice(i + 1)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    i += 1
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Compute max lifeline levels
 | 
					  // Compute max lifeline levels
 | 
				
			||||||
  for elmt in elements {
 | 
					  for elmt in elements {
 | 
				
			||||||
    if elmt.type == "seq" {
 | 
					    if elmt.type == "seq" {
 | 
				
			||||||
@@ -49,6 +61,54 @@
 | 
				
			|||||||
        p.max-lifelines = calc.max(p.max-lifelines, p.lifeline-lvl)
 | 
					        p.max-lifelines = calc.max(p.max-lifelines, p.lifeline-lvl)
 | 
				
			||||||
        participants.at(i2) = p
 | 
					        participants.at(i2) = p
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    } else if elmt.type == "evt" {
 | 
				
			||||||
 | 
					      let par-name = elmt.participant
 | 
				
			||||||
 | 
					      let i = pars-i.at(par-name)
 | 
				
			||||||
 | 
					      let par = participants.at(i)
 | 
				
			||||||
 | 
					      if elmt.event == "disable" or elmt.event == "destroy" {
 | 
				
			||||||
 | 
					        par.lifeline-lvl -= 1
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      } else if elmt.event == "enable" {
 | 
				
			||||||
 | 
					        par.lifeline-lvl += 1
 | 
				
			||||||
 | 
					        par.max-lifelines = calc.max(par.max-lifelines, par.lifeline-lvl)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      participants.at(i) = par
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    } else if elmt.type == "note" {
 | 
				
			||||||
 | 
					      let (p1, p2) = (none, none)
 | 
				
			||||||
 | 
					      let cell = none
 | 
				
			||||||
 | 
					      if elmt.side == "left" {
 | 
				
			||||||
 | 
					        p1 = "["
 | 
				
			||||||
 | 
					        p2 = elmt.pos
 | 
				
			||||||
 | 
					        cell = get-note-box(elmt)
 | 
				
			||||||
 | 
					      } else if elmt.side == "right" {
 | 
				
			||||||
 | 
					        p1 = elmt.pos
 | 
				
			||||||
 | 
					        p2 = "]"
 | 
				
			||||||
 | 
					        cell = get-note-box(elmt)
 | 
				
			||||||
 | 
					      } else if elmt.side == "over" {
 | 
				
			||||||
 | 
					        if elmt.aligned-with != none {
 | 
				
			||||||
 | 
					          let box1 = get-note-box(elmt)
 | 
				
			||||||
 | 
					          let box2 = get-note-box(elmt.aligned-with)
 | 
				
			||||||
 | 
					          let m1 = measure(box1)
 | 
				
			||||||
 | 
					          let m2 = measure(box2)
 | 
				
			||||||
 | 
					          cell = box(width: (m1.width + m2.width) / 2, height: calc.max(m1.height, m2.height))
 | 
				
			||||||
 | 
					          p1 = elmt.pos
 | 
				
			||||||
 | 
					          p2 = elmt.aligned-with.pos
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if p1 != none and p2 != none and cell != none {
 | 
				
			||||||
 | 
					        let i1 = pars-i.at(p1)
 | 
				
			||||||
 | 
					        let i2 = pars-i.at(p2)
 | 
				
			||||||
 | 
					        cells.push(
 | 
				
			||||||
 | 
					          (
 | 
				
			||||||
 | 
					            elmt: elmt,
 | 
				
			||||||
 | 
					            i1: calc.min(i1, i2),
 | 
				
			||||||
 | 
					            i2: calc.max(i1, i2),
 | 
				
			||||||
 | 
					            cell: cell
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -65,6 +125,28 @@
 | 
				
			|||||||
    widths.push(w1 / 2pt + w2 / 2pt + PAR-SPACE)
 | 
					    widths.push(w1 / 2pt + w2 / 2pt + PAR-SPACE)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Compute minimum width for over notes
 | 
				
			||||||
 | 
					  for n in elements.filter(e => (e.type == "note" and
 | 
				
			||||||
 | 
					                                 e.side == "over" and 
 | 
				
			||||||
 | 
					                                 type(e.pos) == str)) {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    let m = note.get-size(n)
 | 
				
			||||||
 | 
					    let i = pars-i.at(n.pos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if i < widths.len() {
 | 
				
			||||||
 | 
					      widths.at(i) = calc.max(
 | 
				
			||||||
 | 
					        widths.at(i),
 | 
				
			||||||
 | 
					        m.width / 2 + NOTE-GAP
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if i > 0 {
 | 
				
			||||||
 | 
					      widths.at(i - 1) = calc.max(
 | 
				
			||||||
 | 
					        widths.at(i - 1),
 | 
				
			||||||
 | 
					        m.width / 2 + NOTE-GAP
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Compute minimum width for simple sequences (spanning 1 column)
 | 
					  // Compute minimum width for simple sequences (spanning 1 column)
 | 
				
			||||||
  for cell in cells.filter(c => c.i2 - c.i1 == 1) {
 | 
					  for cell in cells.filter(c => c.i2 - c.i1 == 1) {
 | 
				
			||||||
    let m = measure(cell.cell)
 | 
					    let m = measure(cell.cell)
 | 
				
			||||||
@@ -74,6 +156,21 @@
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Compute minimum width for self sequences
 | 
				
			||||||
 | 
					  for cell in cells.filter(c => c.elmt.type == "seq" and c.i1 == c.i2) {
 | 
				
			||||||
 | 
					    let m = measure(cell.cell)
 | 
				
			||||||
 | 
					    let i = cell.i1
 | 
				
			||||||
 | 
					    if cell.elmt.flip {
 | 
				
			||||||
 | 
					      i -= 1
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if 0 <= i and i < widths.len() {
 | 
				
			||||||
 | 
					      widths.at(i) = calc.max(
 | 
				
			||||||
 | 
					        widths.at(i),
 | 
				
			||||||
 | 
					        m.width / 1pt + COMMENT-PAD
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Compute remaining widths for longer sequences (spanning multiple columns)
 | 
					  // Compute remaining widths for longer sequences (spanning multiple columns)
 | 
				
			||||||
  let multicol-cells = cells.filter(c => c.i2 - c.i1 > 1)
 | 
					  let multicol-cells = cells.filter(c => c.i2 - c.i1 > 1)
 | 
				
			||||||
  multicol-cells = multicol-cells.sorted(key: c => {
 | 
					  multicol-cells = multicol-cells.sorted(key: c => {
 | 
				
			||||||
@@ -97,6 +194,40 @@
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    widths.at(i) = w
 | 
					    widths.at(i) = w
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for elmt in elements {
 | 
				
			||||||
 | 
					    if elmt.type == "col" {
 | 
				
			||||||
 | 
					      let i1 = pars-i.at(elmt.p1)
 | 
				
			||||||
 | 
					      let i2 = pars-i.at(elmt.p2)
 | 
				
			||||||
 | 
					      if calc.abs(i1 - i2) != 1 {
 | 
				
			||||||
 | 
					        let i-min = calc.min(i1, i2)
 | 
				
			||||||
 | 
					        let i-max = calc.max(i1, i2)
 | 
				
			||||||
 | 
					        let others = pars-i.pairs()
 | 
				
			||||||
 | 
					                           .sorted(key: p => p.last())
 | 
				
			||||||
 | 
					                           .slice(i-min + 1, i-max)
 | 
				
			||||||
 | 
					                           .map(p => "'" + p.first() + "'")
 | 
				
			||||||
 | 
					                           .join(", ")
 | 
				
			||||||
 | 
					        panic(
 | 
				
			||||||
 | 
					          "Column participants must be consecutive (participants (" +
 | 
				
			||||||
 | 
					          others +
 | 
				
			||||||
 | 
					          ") are in between)"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      let i = calc.min(i1, i2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if elmt.width != auto {
 | 
				
			||||||
 | 
					        widths.at(i) = normalize-units(elmt.width)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      let width = widths.at(i)
 | 
				
			||||||
 | 
					      width = calc.max(width, normalize-units(elmt.min-width))
 | 
				
			||||||
 | 
					      if elmt.max-width != none {
 | 
				
			||||||
 | 
					        width = calc.min(width, normalize-units(elmt.max-width))
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      widths.at(i) = width + normalize-units(elmt.margin)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return widths
 | 
					  return widths
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -114,17 +245,20 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  let draw-seq = sequence.render.with(pars-i, x-pos, participants)
 | 
					  let draw-seq = sequence.render.with(pars-i, x-pos, participants)
 | 
				
			||||||
  let draw-group = group.render.with()
 | 
					  let draw-group = group.render.with()
 | 
				
			||||||
 | 
					  let draw-else = group.render-else.with()
 | 
				
			||||||
  let draw-sep = separator.render.with(x-pos)
 | 
					  let draw-sep = separator.render.with(x-pos)
 | 
				
			||||||
  let draw-par = participant.render.with(x-pos)
 | 
					  let draw-par = participant.render.with(x-pos)
 | 
				
			||||||
 | 
					  let draw-note = note.render.with(pars-i, x-pos)
 | 
				
			||||||
 | 
					  let draw-sync = sync.render.with(pars-i, x-pos, participants)
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // Draw participants (start)
 | 
					  // Draw participants (start)
 | 
				
			||||||
  for p in participants {
 | 
					  for p in participants {
 | 
				
			||||||
    if p.from-start and not p.invisible {
 | 
					    if p.from-start and not p.invisible and p.show-top {
 | 
				
			||||||
      shapes += draw-par(p)
 | 
					      shapes += draw-par(p)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let y = -Y-SPACE
 | 
					  let y = 0
 | 
				
			||||||
  let groups = ()
 | 
					  let groups = ()
 | 
				
			||||||
  let lifelines = participants.map(_ => (
 | 
					  let lifelines = participants.map(_ => (
 | 
				
			||||||
    level: 0,
 | 
					    level: 0,
 | 
				
			||||||
@@ -141,6 +275,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Groups (start) -> reserve space for labels + store position
 | 
					    // Groups (start) -> reserve space for labels + store position
 | 
				
			||||||
    } else if elmt.type == "grp" {
 | 
					    } else if elmt.type == "grp" {
 | 
				
			||||||
 | 
					      y -= Y-SPACE
 | 
				
			||||||
      let m = measure(
 | 
					      let m = measure(
 | 
				
			||||||
        box(
 | 
					        box(
 | 
				
			||||||
          elmt.name,
 | 
					          elmt.name,
 | 
				
			||||||
@@ -152,17 +287,34 @@
 | 
				
			|||||||
        if g.at(1).max-i == elmt.max-i { g.at(3) += 1 }
 | 
					        if g.at(1).max-i == elmt.max-i { g.at(3) += 1 }
 | 
				
			||||||
        g
 | 
					        g
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
 | 
					      if elmt.grp-type == "alt" {
 | 
				
			||||||
 | 
					        elmt.insert("elses", ())
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      groups.push((y, elmt, 0, 0))
 | 
					      groups.push((y, elmt, 0, 0))
 | 
				
			||||||
      y -= m.height / 1pt + Y-SPACE
 | 
					      y -= m.height / 1pt
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // Groups (end) -> actual drawing
 | 
					    // Groups (end) -> actual drawing
 | 
				
			||||||
    } else if elmt.type == "grp-end" {
 | 
					    } else if elmt.type == "grp-end" {
 | 
				
			||||||
 | 
					      y -= Y-SPACE
 | 
				
			||||||
      let (start-y, group, start-lvl, end-lvl) = groups.pop()
 | 
					      let (start-y, group, start-lvl, end-lvl) = groups.pop()
 | 
				
			||||||
      let x0 = x-pos.at(group.min-i) - start-lvl * 10 - 20
 | 
					      let x0 = x-pos.at(group.min-i) - start-lvl * 10 - 20
 | 
				
			||||||
      let x1 = x-pos.at(group.max-i) + end-lvl * 10 + 20
 | 
					      let x1 = x-pos.at(group.max-i) + end-lvl * 10 + 20
 | 
				
			||||||
      shapes += draw-group(x0, x1, start-y, y, group)
 | 
					      shapes += draw-group(x0, x1, start-y, y, group)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if group.grp-type == "alt" {
 | 
				
			||||||
 | 
					        for (else-y, else-elmt) in group.elses {
 | 
				
			||||||
 | 
					          shapes += draw-else(x0, x1, else-y, else-elmt)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Alt's elses -> reserve space for label + store position
 | 
				
			||||||
 | 
					    } else if elmt.type == "else" {
 | 
				
			||||||
      y -= Y-SPACE
 | 
					      y -= Y-SPACE
 | 
				
			||||||
 | 
					      let m = measure(text([\[#elmt.desc\]], weight: "bold", size: .8em))
 | 
				
			||||||
 | 
					      groups.last().at(1).elses.push((
 | 
				
			||||||
 | 
					        y, elmt
 | 
				
			||||||
 | 
					      ))
 | 
				
			||||||
 | 
					      y -= m.height / 1pt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Separator
 | 
					    // Separator
 | 
				
			||||||
    } else if elmt.type == "sep" {
 | 
					    } else if elmt.type == "sep" {
 | 
				
			||||||
@@ -173,9 +325,72 @@
 | 
				
			|||||||
    // Gap
 | 
					    // Gap
 | 
				
			||||||
    } else if elmt.type == "gap" {
 | 
					    } else if elmt.type == "gap" {
 | 
				
			||||||
      y -= elmt.size
 | 
					      y -= elmt.size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Delay
 | 
				
			||||||
 | 
					    } else if elmt.type == "delay" {
 | 
				
			||||||
 | 
					      let y0 = y
 | 
				
			||||||
 | 
					      let y1 = y - elmt.size
 | 
				
			||||||
 | 
					      for (i, line) in lifelines.enumerate() {
 | 
				
			||||||
 | 
					        line.lines.push(("delay-start", y0))
 | 
				
			||||||
 | 
					        line.lines.push(("delay-end", y1))
 | 
				
			||||||
 | 
					        lifelines.at(i) = line
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if elmt.name != none {
 | 
				
			||||||
 | 
					        let x0 = x-pos.first()
 | 
				
			||||||
 | 
					        let x1 = x-pos.last()
 | 
				
			||||||
 | 
					        shapes += draw.content(
 | 
				
			||||||
 | 
					          ((x0 + x1) / 2, (y0 + y1) / 2),
 | 
				
			||||||
 | 
					          anchor: "center",
 | 
				
			||||||
 | 
					          elmt.name
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      y = y1
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // Event
 | 
				
			||||||
 | 
					    } else if elmt.type == "evt" {
 | 
				
			||||||
 | 
					      let par-name = elmt.participant
 | 
				
			||||||
 | 
					      let i = pars-i.at(par-name)
 | 
				
			||||||
 | 
					      let par = participants.at(i)
 | 
				
			||||||
 | 
					      let line = lifelines.at(i)
 | 
				
			||||||
 | 
					      if elmt.event == "disable" {
 | 
				
			||||||
 | 
					        line.level -= 1
 | 
				
			||||||
 | 
					        line.lines.push(("disable", y))
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      } else if elmt.event == "destroy" {
 | 
				
			||||||
 | 
					        line.lines.push(("destroy", y))
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      } else if elmt.event == "enable" {
 | 
				
			||||||
 | 
					        line.level += 1
 | 
				
			||||||
 | 
					        line.lines.push(("enable", y, elmt.lifeline-style))
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      } else if elmt.event == "create" {
 | 
				
			||||||
 | 
					        y -= CREATE-OFFSET
 | 
				
			||||||
 | 
					        shapes += participant.render(x-pos, par, y: y)
 | 
				
			||||||
 | 
					        line.lines.push(("create", y))
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      lifelines.at(i) = line
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // Note
 | 
				
			||||||
 | 
					    } else if elmt.type == "note" {
 | 
				
			||||||
 | 
					      if not elmt.linked {
 | 
				
			||||||
 | 
					        if not elmt.aligned {
 | 
				
			||||||
 | 
					          y -= Y-SPACE
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let shps
 | 
				
			||||||
 | 
					        (y, shps) = draw-note(elmt, y, lifelines)
 | 
				
			||||||
 | 
					        shapes += shps
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Synched sequences
 | 
				
			||||||
 | 
					    } else if elmt.type == "sync" {
 | 
				
			||||||
 | 
					      let shps
 | 
				
			||||||
 | 
					      (y, lifelines, shps) = draw-sync(elmt, y, lifelines)
 | 
				
			||||||
 | 
					      shapes += shps
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  y -= Y-SPACE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Draw vertical lines + lifelines + end participants
 | 
					  // Draw vertical lines + lifelines + end participants
 | 
				
			||||||
  shapes += draw.on-layer(-1, {
 | 
					  shapes += draw.on-layer(-1, {
 | 
				
			||||||
    if DEBUG-INVISIBLE {
 | 
					    if DEBUG-INVISIBLE {
 | 
				
			||||||
@@ -217,7 +432,11 @@
 | 
				
			|||||||
            draw.line(
 | 
					            draw.line(
 | 
				
			||||||
              (x, last-y),
 | 
					              (x, last-y),
 | 
				
			||||||
              (x, line.at(1)),
 | 
					              (x, line.at(1)),
 | 
				
			||||||
              stroke: (dash: "dashed", paint: gray.darken(40%))
 | 
					              stroke: (
 | 
				
			||||||
 | 
					                dash: "dashed",
 | 
				
			||||||
 | 
					                paint: gray.darken(40%),
 | 
				
			||||||
 | 
					                thickness: .5pt
 | 
				
			||||||
 | 
					              )
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          lines.push(line)
 | 
					          lines.push(line)
 | 
				
			||||||
@@ -239,13 +458,39 @@
 | 
				
			|||||||
          if event == "destroy" {
 | 
					          if event == "destroy" {
 | 
				
			||||||
            destructions.push((x + lvl * LIFELINE-W / 2, line.at(1)))
 | 
					            destructions.push((x + lvl * LIFELINE-W / 2, line.at(1)))
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					        } else if event == "delay-start" {
 | 
				
			||||||
 | 
					          draw.line(
 | 
				
			||||||
 | 
					            (x, last-y),
 | 
				
			||||||
 | 
					            (x, line.at(1)),
 | 
				
			||||||
 | 
					            stroke: (
 | 
				
			||||||
 | 
					              dash: "dashed",
 | 
				
			||||||
 | 
					              paint: gray.darken(40%),
 | 
				
			||||||
 | 
					              thickness: .5pt
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					          last-y = line.at(1)
 | 
				
			||||||
 | 
					        } else if event == "delay-end" {
 | 
				
			||||||
 | 
					          draw.line(
 | 
				
			||||||
 | 
					            (x, last-y),
 | 
				
			||||||
 | 
					            (x, line.at(1)),
 | 
				
			||||||
 | 
					            stroke: (
 | 
				
			||||||
 | 
					              dash: "loosely-dotted",
 | 
				
			||||||
 | 
					              paint: gray.darken(40%),
 | 
				
			||||||
 | 
					              thickness: .8pt
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					          last-y = line.at(1)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      draw.line(
 | 
					      draw.line(
 | 
				
			||||||
        (x, last-y),
 | 
					        (x, last-y),
 | 
				
			||||||
        (x, y),
 | 
					        (x, y),
 | 
				
			||||||
        stroke: (dash: "dashed", paint: gray.darken(40%))
 | 
					        stroke: (
 | 
				
			||||||
 | 
					          dash: "dashed",
 | 
				
			||||||
 | 
					          paint: gray.darken(40%),
 | 
				
			||||||
 | 
					          thickness: .5pt
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Draw lifeline rectangles (reverse for bottom to top)
 | 
					      // Draw lifeline rectangles (reverse for bottom to top)
 | 
				
			||||||
@@ -267,8 +512,10 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Draw participants (end)
 | 
					      // Draw participants (end)
 | 
				
			||||||
 | 
					      if p.show-bottom {
 | 
				
			||||||
        draw-par(p, y: y, bottom: true)
 | 
					        draw-par(p, y: y, bottom: true)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  shapes
 | 
					  shapes
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
#import "@preview/cetz:0.2.2": draw
 | 
					#import "/src/cetz.typ": draw
 | 
				
			||||||
#import "consts.typ": *
 | 
					#import "consts.typ": *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let _sep(name) = {
 | 
					#let _sep(name) = {
 | 
				
			||||||
@@ -8,8 +8,17 @@
 | 
				
			|||||||
  ),)
 | 
					  ),)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _delay(name: none, size: 30) = {
 | 
				
			||||||
 | 
					  return ((
 | 
				
			||||||
 | 
					    type: "delay",
 | 
				
			||||||
 | 
					    name: name,
 | 
				
			||||||
 | 
					    size: size
 | 
				
			||||||
 | 
					  ),)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let render(x-pos, elmt, y) = {
 | 
					#let render(x-pos, elmt, y) = {
 | 
				
			||||||
  let shapes = ()
 | 
					  let shapes = ()
 | 
				
			||||||
 | 
					  y -= Y-SPACE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let x0 = x-pos.first() - 20
 | 
					  let x0 = x-pos.first() - 20
 | 
				
			||||||
  let x1 = x-pos.last() + 20
 | 
					  let x1 = x-pos.last() + 20
 | 
				
			||||||
@@ -48,7 +57,6 @@
 | 
				
			|||||||
    fill: COL-SEP-NAME
 | 
					    fill: COL-SEP-NAME
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
  y -= h / 2
 | 
					  y -= h / 2
 | 
				
			||||||
  y -= Y-SPACE
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let r = (y, shapes)
 | 
					  let r = (y, shapes)
 | 
				
			||||||
  return r
 | 
					  return r
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										297
									
								
								src/sequence.typ
									
									
									
									
									
								
							
							
						
						@@ -1,13 +1,60 @@
 | 
				
			|||||||
#import "@preview/cetz:0.2.2": draw
 | 
					#import "/src/cetz.typ": draw, vector
 | 
				
			||||||
#import "consts.typ": *
 | 
					#import "consts.typ": *
 | 
				
			||||||
#import "participant.typ"
 | 
					#import "participant.typ"
 | 
				
			||||||
 | 
					#import "note.typ"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let get-arrow-marks(sym, color) = {
 | 
				
			||||||
 | 
					  if sym == none {
 | 
				
			||||||
 | 
					    return none
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if type(sym) == array {
 | 
				
			||||||
 | 
					    return sym.map(s => get-arrow-marks(s, color))
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  (
 | 
				
			||||||
 | 
					    "": none,
 | 
				
			||||||
 | 
					    ">": (symbol: ">", fill: color),
 | 
				
			||||||
 | 
					    ">>": (symbol: "straight"),
 | 
				
			||||||
 | 
					    "\\": (symbol: ">", fill: color, harpoon: true, flip: true),
 | 
				
			||||||
 | 
					    "\\\\": (symbol: "straight", harpoon: true, flip: true),
 | 
				
			||||||
 | 
					    "/": (symbol: ">", fill: color, harpoon: true),
 | 
				
			||||||
 | 
					    "//": (symbol: "straight", harpoon: true),
 | 
				
			||||||
 | 
					    "x": none,
 | 
				
			||||||
 | 
					    "o": none,
 | 
				
			||||||
 | 
					  ).at(sym)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let reverse-arrow-mark(mark) = {
 | 
				
			||||||
 | 
					  if type(mark) == array {
 | 
				
			||||||
 | 
					    return mark.map(m => reverse-arrow-mark(m))
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  let mark2 = mark
 | 
				
			||||||
 | 
					  if type(mark) == dictionary and mark.at("harpoon", default: false) {
 | 
				
			||||||
 | 
					    let flipped = mark.at("flip", default: false)
 | 
				
			||||||
 | 
					    mark2.insert("flip", not flipped)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return mark2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let is-tip-of-type(type_, tip) = {
 | 
				
			||||||
 | 
					  if type(tip) == str and tip == type_ {
 | 
				
			||||||
 | 
					    return true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if type(tip) == array and tip.contains(type_) {
 | 
				
			||||||
 | 
					    return true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#let is-circle-tip = is-tip-of-type.with("o")
 | 
				
			||||||
 | 
					#let is-cross-tip = is-tip-of-type.with("x")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let _seq(
 | 
					#let _seq(
 | 
				
			||||||
  p1,
 | 
					  p1,
 | 
				
			||||||
  p2,
 | 
					  p2,
 | 
				
			||||||
  comment: none,
 | 
					  comment: none,
 | 
				
			||||||
 | 
					  comment-align: "left",
 | 
				
			||||||
  dashed: false,
 | 
					  dashed: false,
 | 
				
			||||||
  tip: "default",
 | 
					  start-tip: "",
 | 
				
			||||||
 | 
					  end-tip: ">",
 | 
				
			||||||
  color: black,
 | 
					  color: black,
 | 
				
			||||||
  flip: false,
 | 
					  flip: false,
 | 
				
			||||||
  enable-dst: false,
 | 
					  enable-dst: false,
 | 
				
			||||||
@@ -16,15 +63,18 @@
 | 
				
			|||||||
  destroy-dst: false,
 | 
					  destroy-dst: false,
 | 
				
			||||||
  disable-src: false,
 | 
					  disable-src: false,
 | 
				
			||||||
  destroy-src: false,
 | 
					  destroy-src: false,
 | 
				
			||||||
  lifeline-style: auto
 | 
					  lifeline-style: auto,
 | 
				
			||||||
 | 
					  slant: none
 | 
				
			||||||
) = {
 | 
					) = {
 | 
				
			||||||
  return ((
 | 
					  return ((
 | 
				
			||||||
    type: "seq",
 | 
					    type: "seq",
 | 
				
			||||||
    p1: p1,
 | 
					    p1: p1,
 | 
				
			||||||
    p2: p2,
 | 
					    p2: p2,
 | 
				
			||||||
    comment: comment,
 | 
					    comment: comment,
 | 
				
			||||||
 | 
					    comment-align: comment-align,
 | 
				
			||||||
    dashed: dashed,
 | 
					    dashed: dashed,
 | 
				
			||||||
    tip: tip,
 | 
					    start-tip: start-tip,
 | 
				
			||||||
 | 
					    end-tip: end-tip,
 | 
				
			||||||
    color: color,
 | 
					    color: color,
 | 
				
			||||||
    flip: flip,
 | 
					    flip: flip,
 | 
				
			||||||
    enable-dst: enable-dst,
 | 
					    enable-dst: enable-dst,
 | 
				
			||||||
@@ -34,19 +84,42 @@
 | 
				
			|||||||
    disable-src: disable-src,
 | 
					    disable-src: disable-src,
 | 
				
			||||||
    destroy-src: destroy-src,
 | 
					    destroy-src: destroy-src,
 | 
				
			||||||
    lifeline-style: lifeline-style,
 | 
					    lifeline-style: lifeline-style,
 | 
				
			||||||
 | 
					    slant: slant
 | 
				
			||||||
 | 
					  ),)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _ret(comment: none) = {
 | 
				
			||||||
 | 
					  return ((
 | 
				
			||||||
 | 
					    type: "ret",
 | 
				
			||||||
 | 
					    comment: comment
 | 
				
			||||||
  ),)
 | 
					  ),)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#let render(pars-i, x-pos, participants, elmt, y, lifelines) = {
 | 
					#let render(pars-i, x-pos, participants, elmt, y, lifelines) = {
 | 
				
			||||||
  let shapes = ()
 | 
					  let shapes = ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Reserve space for comment
 | 
					  y -= Y-SPACE
 | 
				
			||||||
  if elmt.comment != none {
 | 
					 | 
				
			||||||
    y -= measure(box(elmt.comment)).height / 1pt + 6
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let i1 = pars-i.at(elmt.p1)
 | 
					  let i1 = pars-i.at(elmt.p1)
 | 
				
			||||||
  let i2 = pars-i.at(elmt.p2)
 | 
					  let i2 = pars-i.at(elmt.p2)
 | 
				
			||||||
 | 
					  let width = calc.abs(x-pos.at(i1) - x-pos.at(i2))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let h = 0
 | 
				
			||||||
 | 
					  let comment = if elmt.comment == none {none} else {
 | 
				
			||||||
 | 
					    let w = calc.min(width * 1pt, measure(elmt.comment).width)
 | 
				
			||||||
 | 
					    box(
 | 
				
			||||||
 | 
					      width: if i1 == i2 {auto} else {w},
 | 
				
			||||||
 | 
					      elmt.comment
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  // Reserve space for comment
 | 
				
			||||||
 | 
					  if comment != none {
 | 
				
			||||||
 | 
					    h = calc.max(h, measure(comment).height / 1pt + 6)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if "linked-note" in elmt {
 | 
				
			||||||
 | 
					    h = calc.max(h, note.get-size(elmt.linked-note).height / 2)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  y -= h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let start-info = (
 | 
					  let start-info = (
 | 
				
			||||||
    i: i1,
 | 
					    i: i1,
 | 
				
			||||||
@@ -60,27 +133,38 @@
 | 
				
			|||||||
    y: y,
 | 
					    y: y,
 | 
				
			||||||
    ll-lvl: lifelines.at(i2).level * LIFELINE-W / 2
 | 
					    ll-lvl: lifelines.at(i2).level * LIFELINE-W / 2
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					  let slant = if elmt.slant == auto {
 | 
				
			||||||
 | 
					    DEFAULT-SLANT
 | 
				
			||||||
 | 
					  } else if elmt.slant != none {
 | 
				
			||||||
 | 
					    elmt.slant
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    0
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  end-info.y -= slant
 | 
				
			||||||
 | 
					  if elmt.p1 == elmt.p2 {
 | 
				
			||||||
 | 
					    end-info.y -= 10
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if elmt.disable-src {
 | 
					  if elmt.disable-src {
 | 
				
			||||||
    let src-line = lifelines.at(i1)
 | 
					    let src-line = lifelines.at(i1)
 | 
				
			||||||
    src-line.level -= 1
 | 
					    src-line.level -= 1
 | 
				
			||||||
    src-line.lines.push(("disable", y))
 | 
					    src-line.lines.push(("disable", start-info.y))
 | 
				
			||||||
    lifelines.at(i1) = src-line
 | 
					    lifelines.at(i1) = src-line
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if elmt.destroy-src {
 | 
					  if elmt.destroy-src {
 | 
				
			||||||
    let src-line = lifelines.at(i1)
 | 
					    let src-line = lifelines.at(i1)
 | 
				
			||||||
    src-line.lines.push(("destroy", y))
 | 
					    src-line.lines.push(("destroy", start-info.y))
 | 
				
			||||||
    lifelines.at(i1) = src-line
 | 
					    lifelines.at(i1) = src-line
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if elmt.disable-dst {
 | 
					  if elmt.disable-dst {
 | 
				
			||||||
    let dst-line = lifelines.at(i2)
 | 
					    let dst-line = lifelines.at(i2)
 | 
				
			||||||
    dst-line.level -= 1
 | 
					    dst-line.level -= 1
 | 
				
			||||||
    dst-line.lines.push(("disable", y))
 | 
					    dst-line.lines.push(("disable", end-info.y))
 | 
				
			||||||
    lifelines.at(i2) = dst-line
 | 
					    lifelines.at(i2) = dst-line
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if elmt.destroy-dst {
 | 
					  if elmt.destroy-dst {
 | 
				
			||||||
    let dst-line = lifelines.at(i2)
 | 
					    let dst-line = lifelines.at(i2)
 | 
				
			||||||
    dst-line.lines.push(("destroy", y))
 | 
					    dst-line.lines.push(("destroy", end-info.y))
 | 
				
			||||||
    lifelines.at(i2) = dst-line
 | 
					    lifelines.at(i2) = dst-line
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if elmt.enable-dst {
 | 
					  if elmt.enable-dst {
 | 
				
			||||||
@@ -93,7 +177,7 @@
 | 
				
			|||||||
    let m = measure(box(par.display-name))
 | 
					    let m = measure(box(par.display-name))
 | 
				
			||||||
    let f = if i1 > i2 {-1} else {1}
 | 
					    let f = if i1 > i2 {-1} else {1}
 | 
				
			||||||
    end-info.x -= (m.width + PAR-PAD.last() * 2) / 2pt * f
 | 
					    end-info.x -= (m.width + PAR-PAD.last() * 2) / 2pt * f
 | 
				
			||||||
    shapes += participant.render(x-pos, par, y: y)
 | 
					    shapes += participant.render(x-pos, par, y: end-info.y)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  end-info.ll-lvl = lifelines.at(i2).level * LIFELINE-W / 2
 | 
					  end-info.ll-lvl = lifelines.at(i2).level * LIFELINE-W / 2
 | 
				
			||||||
@@ -117,13 +201,37 @@
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let style = (
 | 
					  let style = (
 | 
				
			||||||
    mark: (end: ">", fill: elmt.color),
 | 
					    mark: (
 | 
				
			||||||
 | 
					      start: get-arrow-marks(elmt.start-tip, elmt.color),
 | 
				
			||||||
 | 
					      end: get-arrow-marks(elmt.end-tip, elmt.color),
 | 
				
			||||||
 | 
					      scale: 1.2
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
    stroke: (
 | 
					    stroke: (
 | 
				
			||||||
      dash: if elmt.dashed {"dashed"} else {"solid"},
 | 
					      dash: if elmt.dashed {(2pt,2pt)} else {"solid"},
 | 
				
			||||||
      paint: elmt.color
 | 
					      paint: elmt.color,
 | 
				
			||||||
 | 
					      thickness: .5pt
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let y0 = start-info.y
 | 
				
			||||||
 | 
					  if "linked-note" in elmt {
 | 
				
			||||||
 | 
					    let shps = note.render(pars-i, x-pos, elmt.linked-note, start-info.y, lifelines).last()
 | 
				
			||||||
 | 
					    shapes += shps
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let flip-mark = end-info.i <= start-info.i
 | 
				
			||||||
 | 
					  if elmt.flip {
 | 
				
			||||||
 | 
					    flip-mark = not flip-mark
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if flip-mark {
 | 
				
			||||||
 | 
					    style.mark.end = reverse-arrow-mark(style.mark.end)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let pts
 | 
				
			||||||
 | 
					  let comment-pt
 | 
				
			||||||
 | 
					  let comment-anchor
 | 
				
			||||||
 | 
					  let comment-angle = 0deg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if elmt.p1 == elmt.p2 {
 | 
					  if elmt.p1 == elmt.p2 {
 | 
				
			||||||
    if elmt.flip {
 | 
					    if elmt.flip {
 | 
				
			||||||
      x1 = start-info.lx
 | 
					      x1 = start-info.lx
 | 
				
			||||||
@@ -137,56 +245,143 @@
 | 
				
			|||||||
      calc.max(x1, x2) + 20
 | 
					      calc.max(x1, x2) + 20
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if elmt.comment != none {
 | 
					    pts = (
 | 
				
			||||||
      shapes += draw.content(
 | 
					      (x1, start-info.y),
 | 
				
			||||||
        (x1, y),
 | 
					      (x-mid, start-info.y),
 | 
				
			||||||
        elmt.comment,
 | 
					      (x-mid, end-info.y),
 | 
				
			||||||
        anchor: if elmt.flip {"south-east"} else {"south-west"},
 | 
					      (x2, end-info.y)
 | 
				
			||||||
        padding: 3pt
 | 
					 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    shapes += draw.line(
 | 
					    if comment != none {
 | 
				
			||||||
      (x1, y),
 | 
					      comment-anchor = (
 | 
				
			||||||
      (x-mid, y),
 | 
					        start: if x-mid < x1 {"south-east"} else {"south-west"},
 | 
				
			||||||
      (x-mid, y - 10),
 | 
					        end: if x-mid < x1 {"south-west"} else {"south-east"},
 | 
				
			||||||
      (x2, y - 10),
 | 
					        left: "south-west",
 | 
				
			||||||
      ..style
 | 
					        right: "south-east",
 | 
				
			||||||
    )
 | 
					        center: "south",
 | 
				
			||||||
    y -= 10
 | 
					      ).at(elmt.comment-align)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      comment-pt = (
 | 
				
			||||||
 | 
					        start: pts.first(),
 | 
				
			||||||
 | 
					        end: pts.at(1),
 | 
				
			||||||
 | 
					        left: if x-mid < x1 {pts.at(1)} else {pts.first()},
 | 
				
			||||||
 | 
					        right: if x-mid < x1 {pts.first()} else {pts.at(1)},
 | 
				
			||||||
 | 
					        center: (pts.first(), 50%, pts.at(1))
 | 
				
			||||||
 | 
					      ).at(elmt.comment-align)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    if elmt.comment != none {
 | 
					    pts = (
 | 
				
			||||||
      let x = calc.min(x1, x2)
 | 
					      (x1, start-info.y),
 | 
				
			||||||
      if x2 < x1 {
 | 
					      (x2, end-info.y)
 | 
				
			||||||
        x += COMMENT-PAD
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if comment != none {
 | 
				
			||||||
 | 
					      let start-pt = pts.first()
 | 
				
			||||||
 | 
					      let end-pt = pts.last()
 | 
				
			||||||
 | 
					      if elmt.start-tip != "" {
 | 
				
			||||||
 | 
					        start-pt = (pts.first(), COMMENT-PAD, pts.last())
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      if elmt.end-tip != "" {
 | 
				
			||||||
 | 
					        end-pt = (pts.last(), COMMENT-PAD, pts.first())
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      comment-pt = (
 | 
				
			||||||
 | 
					        start: start-pt,
 | 
				
			||||||
 | 
					        end: end-pt,
 | 
				
			||||||
 | 
					        left: if x2 < x1 {end-pt} else {start-pt},
 | 
				
			||||||
 | 
					        right: if x2 < x1 {start-pt} else {end-pt},
 | 
				
			||||||
 | 
					        center: (start-pt, 50%, end-pt)
 | 
				
			||||||
 | 
					      ).at(elmt.comment-align)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      comment-anchor = (
 | 
				
			||||||
 | 
					        start: if x2 < x1 {"south-east"} else {"south-west"},
 | 
				
			||||||
 | 
					        end: if x2 < x1 {"south-west"} else {"south-east"},
 | 
				
			||||||
 | 
					        left: "south-west",
 | 
				
			||||||
 | 
					        right: "south-east",
 | 
				
			||||||
 | 
					        center: "south",
 | 
				
			||||||
 | 
					      ).at(elmt.comment-align)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let (p1, p2) = pts
 | 
				
			||||||
 | 
					    if x2 < x1 {
 | 
				
			||||||
 | 
					      (p1, p2) = (p2, p1)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    comment-angle = vector.angle2(p1, p2)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Start circle tip
 | 
				
			||||||
 | 
					  if is-circle-tip(elmt.start-tip) {
 | 
				
			||||||
 | 
					    shapes += draw.circle(pts.first(), radius: CIRCLE-TIP-RADIUS, stroke: none, fill: elmt.color, name: "_circle-start-tip")
 | 
				
			||||||
 | 
					    pts.at(0) = "_circle-start-tip"
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  // Start cross tip
 | 
				
			||||||
 | 
					  } else if is-cross-tip(elmt.start-tip) {
 | 
				
			||||||
 | 
					    let size = CROSS-TIP-SIZE
 | 
				
			||||||
 | 
					    let cross-pt = (pts.first(), size * 2, pts.at(1))
 | 
				
			||||||
 | 
					    shapes += draw.line(
 | 
				
			||||||
 | 
					      (rel: (-size, -size), to: cross-pt),
 | 
				
			||||||
 | 
					      (rel: (size, size), to: cross-pt),
 | 
				
			||||||
 | 
					      stroke: elmt.color + 1.5pt
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    shapes += draw.line(
 | 
				
			||||||
 | 
					      (rel: (-size, size), to: cross-pt),
 | 
				
			||||||
 | 
					      (rel: (size, -size), to: cross-pt),
 | 
				
			||||||
 | 
					      stroke: elmt.color + 1.5pt
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    pts.at(0) = cross-pt
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // End circle tip
 | 
				
			||||||
 | 
					  if is-circle-tip(elmt.end-tip) {
 | 
				
			||||||
 | 
					    shapes += draw.circle(pts.last(), radius: 3, stroke: none, fill: elmt.color, name: "_circle-end-tip")
 | 
				
			||||||
 | 
					    pts.at(pts.len() - 1) = "_circle-end-tip"
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  // End cross tip
 | 
				
			||||||
 | 
					  } else if is-cross-tip(elmt.end-tip) {
 | 
				
			||||||
 | 
					    let size = CROSS-TIP-SIZE
 | 
				
			||||||
 | 
					    let cross-pt = (pts.last(), size * 2, pts.at(pts.len() - 2))
 | 
				
			||||||
 | 
					    shapes += draw.line(
 | 
				
			||||||
 | 
					      (rel: (-size, -size), to: cross-pt),
 | 
				
			||||||
 | 
					      (rel: (size, size), to: cross-pt),
 | 
				
			||||||
 | 
					      stroke: elmt.color + 1.5pt
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    shapes += draw.line(
 | 
				
			||||||
 | 
					      (rel: (-size, size), to: cross-pt),
 | 
				
			||||||
 | 
					      (rel: (size, -size), to: cross-pt),
 | 
				
			||||||
 | 
					      stroke: elmt.color + 1.5pt
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    pts.at(pts.len() - 1) = cross-pt
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  shapes += draw.line(..pts, ..style)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if comment != none {
 | 
				
			||||||
    shapes += draw.content(
 | 
					    shapes += draw.content(
 | 
				
			||||||
        (x, y),
 | 
					      comment-pt,
 | 
				
			||||||
        elmt.comment,
 | 
					      comment,
 | 
				
			||||||
        anchor: "south-west",
 | 
					      anchor: comment-anchor,
 | 
				
			||||||
 | 
					      angle: comment-angle,
 | 
				
			||||||
      padding: 3pt
 | 
					      padding: 3pt
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    shapes += draw.line(
 | 
					  if elmt.create-dst {
 | 
				
			||||||
      (x1, y),
 | 
					    let dst-line = lifelines.at(i2)
 | 
				
			||||||
      (x2, y),
 | 
					    dst-line.lines.push(("create", end-info.y))
 | 
				
			||||||
      ..style
 | 
					    lifelines.at(i2) = dst-line
 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if elmt.enable-dst {
 | 
					  if elmt.enable-dst {
 | 
				
			||||||
    let dst-line = lifelines.at(i2)
 | 
					    let dst-line = lifelines.at(i2)
 | 
				
			||||||
    dst-line.lines.push(("enable", y, elmt.lifeline-style))
 | 
					    dst-line.lines.push(("enable", end-info.y, elmt.lifeline-style))
 | 
				
			||||||
    lifelines.at(i2) = dst-line
 | 
					    lifelines.at(i2) = dst-line
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if elmt.create-dst {
 | 
					 | 
				
			||||||
    let dst-line = lifelines.at(i2)
 | 
					 | 
				
			||||||
    dst-line.lines.push(("create", y))
 | 
					 | 
				
			||||||
    lifelines.at(i2) = dst-line
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  y -= Y-SPACE
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let r = (y, lifelines, shapes)
 | 
					  if "linked-note" in elmt {
 | 
				
			||||||
 | 
					    let m = note.get-size(elmt.linked-note)
 | 
				
			||||||
 | 
					    end-info.y = calc.min(end-info.y, y0 - m.height / 2)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let r = (end-info.y, lifelines, shapes)
 | 
				
			||||||
  return r
 | 
					  return r
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										27
									
								
								src/sync.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					#import "sequence.typ"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let _sync(elmts) = {
 | 
				
			||||||
 | 
					  return ((
 | 
				
			||||||
 | 
					    type: "sync",
 | 
				
			||||||
 | 
					    elmts: elmts
 | 
				
			||||||
 | 
					  ),)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let render(pars-i, x-pos, participants, elmt, y, lifelines) = {
 | 
				
			||||||
 | 
					  let draw-seq = sequence.render.with(pars-i, x-pos, participants)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let shapes = ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let end-y = y
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for e in elmt.elmts {
 | 
				
			||||||
 | 
					    let yi
 | 
				
			||||||
 | 
					    let shps
 | 
				
			||||||
 | 
					    (yi, lifelines, shps) = draw-seq(e, y, lifelines)
 | 
				
			||||||
 | 
					    shapes += shps
 | 
				
			||||||
 | 
					    end-y = calc.min(end-y, yi)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let r = (end-y, lifelines, shapes)
 | 
				
			||||||
 | 
					  return r
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,3 +1,12 @@
 | 
				
			|||||||
 | 
					#let normalize-units(value) = {
 | 
				
			||||||
 | 
					  if type(value) == int or type(value) == float {
 | 
				
			||||||
 | 
					    return value
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if type(value) == length {
 | 
				
			||||||
 | 
					    return value / 1pt
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  panic("Unsupported type '" + str(type(value)) + "'")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
#let get-participants-i(participants) = {
 | 
					#let get-participants-i(participants) = {
 | 
				
			||||||
  let pars-i = (:)
 | 
					  let pars-i = (:)
 | 
				
			||||||
  for (i, p) in participants.enumerate() {
 | 
					  for (i, p) in participants.enumerate() {
 | 
				
			||||||
@@ -21,8 +30,15 @@
 | 
				
			|||||||
      let (i0, i1) = get-group-span(participants, elmt)
 | 
					      let (i0, i1) = get-group-span(participants, elmt)
 | 
				
			||||||
      min-i = calc.min(min-i, i0)
 | 
					      min-i = calc.min(min-i, i0)
 | 
				
			||||||
      max-i = calc.max(max-i, i1)
 | 
					      max-i = calc.max(max-i, i1)
 | 
				
			||||||
 | 
					    } else if elmt.type == "sync" {
 | 
				
			||||||
 | 
					      let (i0, i1) = get-group-span(participants, elmt)
 | 
				
			||||||
 | 
					      min-i = calc.min(min-i, i0)
 | 
				
			||||||
 | 
					      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)
 | 
					  return (min-i, max-i)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,3 +57,26 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  panic("Invalid type for parameter mods, expected auto or dictionary, got " + str(type(mods)))
 | 
					  panic("Invalid type for parameter mods, expected auto or dictionary, got " + str(type(mods)))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#let fit-canvas(canvas, width: auto) = layout(size => {
 | 
				
			||||||
 | 
					  let m = measure(canvas)
 | 
				
			||||||
 | 
					  let w = m.width
 | 
				
			||||||
 | 
					  let h = m.height
 | 
				
			||||||
 | 
					  let r = if w == 0pt {0} else {
 | 
				
			||||||
 | 
					    if width == auto {1}
 | 
				
			||||||
 | 
					    else if type(width) == length {
 | 
				
			||||||
 | 
					      width / w
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      size.width * width / w
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  let new-w = w * r
 | 
				
			||||||
 | 
					  let new-h = h * r
 | 
				
			||||||
 | 
					  r *= 100%
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  box(
 | 
				
			||||||
 | 
					    width: new-w,
 | 
				
			||||||
 | 
					    height: new-h,
 | 
				
			||||||
 | 
					    scale(x: r, y: r, reflow: true, canvas)
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "chronos"
 | 
					name = "chronos"
 | 
				
			||||||
version = "0.0.1"
 | 
					version = "0.2.1"
 | 
				
			||||||
compiler = "0.11.0"
 | 
					compiler = "0.13.1"
 | 
				
			||||||
repository = "https://git.kb28.ch/HEL/chronos"
 | 
					repository = "https://git.kb28.ch/HEL/chronos"
 | 
				
			||||||
entrypoint = "src/lib.typ"
 | 
					entrypoint = "src/lib.typ"
 | 
				
			||||||
authors = [
 | 
					authors = [
 | 
				
			||||||
@@ -11,4 +11,4 @@ categories = ["visualization"]
 | 
				
			|||||||
license = "Apache-2.0"
 | 
					license = "Apache-2.0"
 | 
				
			||||||
description = "A package to draw sequence diagrams with CeTZ"
 | 
					description = "A package to draw sequence diagrams with CeTZ"
 | 
				
			||||||
keywords = ["sequence", "diagram", "plantuml"]
 | 
					keywords = ["sequence", "diagram", "plantuml"]
 | 
				
			||||||
exclude = [ "/gallery/*" ]
 | 
					exclude = [ "gallery", "justfile", "docs" ]
 | 
				
			||||||
 
 | 
				
			|||||||