mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2026-11-23 02:30:31 +01:00
repo: switch to nu for just
This commit is contained in:
parent
9a2f982d40
commit
47f6025963
5 changed files with 32 additions and 28 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#import "../template.typ": conf
|
||||
#import "graphics.typ"
|
||||
#import "util/graphics.typ"
|
||||
#import graphics: arrow
|
||||
|
||||
#show: conf.with(
|
||||
|
|
|
|||
251
docs/design/util/graphics.typ
Normal file
251
docs/design/util/graphics.typ
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
#import "@preview/cetz:0.1.2"
|
||||
#import cetz.draw: *
|
||||
|
||||
// quick reference
|
||||
// - `graphic` is for inline icons/images
|
||||
// - `canvas` is for centered more prominent stuff
|
||||
// - `group` can be used in either of ^, but not standalone
|
||||
|
||||
#let graphic(what) = box({
|
||||
cetz.canvas({
|
||||
// any preamble-ish stuff can go here
|
||||
set-style(
|
||||
mark: (angle: 90deg),
|
||||
stroke: (cap: "round", join: "round"),
|
||||
)
|
||||
|
||||
what
|
||||
})
|
||||
})
|
||||
|
||||
#let canvas(what) = {
|
||||
align(center, graphic(what))
|
||||
}
|
||||
|
||||
|
||||
// smaller stuff
|
||||
|
||||
#let arrow(length: 0.4cm, lift: 3pt, stroke: 1pt) = graphic({
|
||||
line((0, lift), (rel: (length, 0)), mark: (end: ">", stroke: stroke))
|
||||
|
||||
// hack for the bounding box bottom
|
||||
// so that `lift` even has any effect
|
||||
line((0, 0), (0, 0), stroke: none)
|
||||
})
|
||||
|
||||
// larger stuff
|
||||
|
||||
#let sequence(
|
||||
distance: 3cm,
|
||||
arrow-spacing: 0.15cm,
|
||||
// cetz will support rounded rects in 0.2.0
|
||||
style: (frame: "rect", padding: 0.1cm),
|
||||
..labels,
|
||||
) = group({
|
||||
let labels = labels.pos()
|
||||
|
||||
// draw each label itself
|
||||
for (i, label) in labels.enumerate() {
|
||||
if i != 0 {
|
||||
set-origin((distance, 0))
|
||||
}
|
||||
content((0, 0), name: "label-" + str(i), label, ..style)
|
||||
}
|
||||
|
||||
// then draw an arrow from each to each
|
||||
// since an arrow is between two, the last one can't be connected with the "next-to-last" one
|
||||
// so we leave it out
|
||||
for i in range(labels.len() - 1) {
|
||||
line(
|
||||
(rel: (arrow-spacing, 0), to: "label-" + str(i) + ".right"),
|
||||
(rel: (-arrow-spacing, 0), to: "label-" + str(i + 1) + ".left"),
|
||||
mark: (end: ">"),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
#let stages-overview = canvas({
|
||||
sequence(
|
||||
[Source],
|
||||
[Graph IR],
|
||||
[Runtime],
|
||||
)
|
||||
})
|
||||
|
||||
// A few commands to help demonstration in the docs.
|
||||
// Supply a string to mark the input or output as simple.
|
||||
// (fwiw in typst, parenthesis around a single expression just evaluate the expression, and don't put it into an array)
|
||||
#let cmds = (
|
||||
"const": (
|
||||
inputs: (),
|
||||
outputs: ("data",),
|
||||
),
|
||||
"open": (
|
||||
inputs: ("path",),
|
||||
outputs: ("data",),
|
||||
),
|
||||
"save": (
|
||||
inputs: ("data", "path"),
|
||||
outputs: (),
|
||||
),
|
||||
"show": (
|
||||
inputs: ("data",),
|
||||
outputs: (),
|
||||
),
|
||||
"invert": (
|
||||
inputs: ("base",),
|
||||
outputs: ("",),
|
||||
),
|
||||
"mask": (
|
||||
inputs: ("base", "stencil"),
|
||||
outputs: ("masked", "rest"),
|
||||
),
|
||||
)
|
||||
|
||||
#let opposite(anchor) = {
|
||||
(
|
||||
"bottom": "top",
|
||||
"top": "bottom",
|
||||
)
|
||||
.at(anchor)
|
||||
}
|
||||
|
||||
#let sockets(
|
||||
start,
|
||||
stop,
|
||||
sockets,
|
||||
socket-size: (0.5, 0.1),
|
||||
socket-shape: "circle",
|
||||
parent-name: "",
|
||||
label-anchor: "bottom",
|
||||
) = {
|
||||
for (i, socket) in sockets.enumerate() {
|
||||
let x-ratio = (i + 1) / (sockets.len() + 1)
|
||||
let center = (start, x-ratio, stop)
|
||||
|
||||
let socket-name = parent-name + "/" + socket
|
||||
|
||||
let common-args = (name: socket-name, fill: black)
|
||||
if socket-shape == "rect" {
|
||||
rect(
|
||||
(rel: ((0, 0), -0.5, socket-size), to: center),
|
||||
(rel: socket-size),
|
||||
..common-args,
|
||||
)
|
||||
} else if socket-shape == "circle" {
|
||||
circle(
|
||||
center,
|
||||
radius: socket-size.at(1),
|
||||
..common-args,
|
||||
)
|
||||
} else {
|
||||
panic("unknown socket shape: `" + socket-shape + "`")
|
||||
}
|
||||
set-style(fill: none)
|
||||
|
||||
// don't ask why, I don't know myself
|
||||
let use-opposite-anchor = socket-shape == "circle"
|
||||
content(
|
||||
socket-name + "." + if use-opposite-anchor { opposite(label-anchor) } else { label-anchor },
|
||||
anchor: opposite(label-anchor),
|
||||
box(inset: 0.25em, text(8pt, socket)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#let node(
|
||||
at,
|
||||
size: (3, 1.5),
|
||||
ty: none,
|
||||
body: none,
|
||||
name: "unnamed",
|
||||
) = {
|
||||
set-origin(at)
|
||||
let label = [#ty]
|
||||
if body != none {
|
||||
label += [\ ] + text(0.7em, font: "IBM Plex Mono", body)
|
||||
size.at(1) += 0.5
|
||||
}
|
||||
rect((0, 0), (rel: size), name: name)
|
||||
content(((0, 0), 0.5, size), align(center, label))
|
||||
|
||||
// input and output sockets
|
||||
if ty == none { return }
|
||||
let ty = cmds.at(ty)
|
||||
|
||||
let sockets = sockets.with(parent-name: name)
|
||||
sockets(
|
||||
((0, 0), "|-", size),
|
||||
size,
|
||||
ty.inputs,
|
||||
)
|
||||
sockets(
|
||||
(0, 0),
|
||||
((0, 0), "-|", size),
|
||||
label-anchor: "top",
|
||||
ty.outputs,
|
||||
)
|
||||
|
||||
// helper text
|
||||
let helper(base, label, where) = {
|
||||
if not type(base) != list or base.len() != 0 {
|
||||
content(
|
||||
name + "." + where + "-left",
|
||||
anchor: "right",
|
||||
box(inset: 0.25em, text(fill: luma(75%), label))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
helper(ty.inputs, [in], "top")
|
||||
helper(ty.outputs, [out], "bottom")
|
||||
|
||||
// reset the origin transform so other nodes can still work in the global coord system
|
||||
// can't use groups since otherwise the anchors are not exported
|
||||
set-origin(((0, 0), -1, at))
|
||||
}
|
||||
|
||||
#let connect(from, to, bend: 1.5, mark-cfg: (size: 0.25, offset: 0.1)) = {
|
||||
bezier(
|
||||
from,
|
||||
to,
|
||||
(rel: (0, -bend * 1cm), to: from),
|
||||
(rel: (0, bend * 1cm), to: to),
|
||||
)
|
||||
mark(
|
||||
(rel: (0, mark-cfg.size + mark-cfg.offset), to: to),
|
||||
(rel: (0, -mark-cfg.size)),
|
||||
symbol: ">",
|
||||
)
|
||||
}
|
||||
|
||||
#let graph-example = canvas({
|
||||
let x = 3
|
||||
let y = -3
|
||||
node((-x, -0.75 * y), ty: "const", body: "\"base.png\"", name: "base")
|
||||
node((x, -0.75 * y), ty: "const", body: "\"stencil.png\"", name: "stencil")
|
||||
node((-x, 0), ty: "open", name: "a")
|
||||
node((x, 0), ty: "open", name: "b")
|
||||
node((0, y), ty: "mask", name: "c")
|
||||
node((-x, 2 * y), ty: "invert", name: "d")
|
||||
node((-x, 2.75 * y), ty: "show", name: "e")
|
||||
node((x, 2.75 * y), ty: "show", name: "f")
|
||||
|
||||
connect("base/data", "a/path")
|
||||
connect("stencil/data", "b/path")
|
||||
|
||||
connect("a/data", "c/base")
|
||||
connect("b/data", "c/stencil")
|
||||
|
||||
connect("c/masked", "d/base")
|
||||
connect("d/", "e/data")
|
||||
|
||||
connect("c/rest", "f/data", bend: 2.5)
|
||||
})
|
||||
|
||||
// literally just for standalone display of the graphics alone
|
||||
#import "../../template.typ": conf
|
||||
#show: conf
|
||||
#set page(width: auto, height: auto)
|
||||
|
||||
#graph-example
|
||||
38
flake.lock
generated
38
flake.lock
generated
|
|
@ -8,11 +8,11 @@
|
|||
"pre-commit-hooks": "pre-commit-hooks"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1699541523,
|
||||
"narHash": "sha256-Rv0ryuBC5KtA/3YqwIEe58Tabu71qSGnGcGRd67mMUY=",
|
||||
"lastModified": 1704835383,
|
||||
"narHash": "sha256-SoC0rYR9iHW0dVOEmxNEfa8vk9dTK86P5iXTgHafmwM=",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"rev": "14fdefc0bb80c3d6f3a18a491e33429b4064c371",
|
||||
"rev": "18ef9849d1ecac7a9a7920eb4f2e4adcf67a8c3a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -27,11 +27,11 @@
|
|||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1699510895,
|
||||
"narHash": "sha256-eaOkJUvHeYNW/xEoRotz0rHkKihKoQdWB1ctX4q1MTQ=",
|
||||
"lastModified": 1704867811,
|
||||
"narHash": "sha256-pG4O1vPpNSMjz7p/5x+/OH4tXC0thzAPbJ55kI/W5dU=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "8eeef23f2c8d092227af40eff98afe5b41891e3b",
|
||||
"rev": "93e89638c15512db65e931f26ce36edf8cfbb4a5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -186,11 +186,11 @@
|
|||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1699099776,
|
||||
"narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=",
|
||||
"lastModified": 1704538339,
|
||||
"narHash": "sha256-1734d3mQuux9ySvwf6axRWZRBhtcZA9Q8eftD6EZg6U=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb",
|
||||
"rev": "46ae0210ce163b3cba6c7da08840c1d63de9c701",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -202,16 +202,16 @@
|
|||
},
|
||||
"nixpkgs_3": {
|
||||
"locked": {
|
||||
"lastModified": 1699291058,
|
||||
"narHash": "sha256-5ggduoaAMPHUy4riL+OrlAZE14Kh7JWX4oLEs22ZqfU=",
|
||||
"lastModified": 1704722960,
|
||||
"narHash": "sha256-mKGJ3sPsT6//s+Knglai5YflJUF2DGj7Ai6Ynopz0kI=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "41de143fda10e33be0f47eab2bfe08a50f234267",
|
||||
"rev": "317484b1ead87b9c1b8ac5261a8d2dd748a0492d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-23.05",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
|
@ -231,11 +231,11 @@
|
|||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1688056373,
|
||||
"narHash": "sha256-2+SDlNRTKsgo3LBRiMUcoEUb6sDViRNQhzJquZ4koOI=",
|
||||
"lastModified": 1704725188,
|
||||
"narHash": "sha256-qq8NbkhRZF1vVYQFt1s8Mbgo8knj+83+QlL5LBnYGpI=",
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "5843cf069272d92b60c3ed9e55b7a8989c01d4c7",
|
||||
"rev": "ea96f0c05924341c551a797aaba8126334c505d2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -255,11 +255,11 @@
|
|||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1699451299,
|
||||
"narHash": "sha256-7HJMyp62fCS6/aCCCASz8MdJM2/M8d1pBNukyLmPdwA=",
|
||||
"lastModified": 1704833483,
|
||||
"narHash": "sha256-Ox01mpYmjapNYaqOu4fMS/4Ma9NLd2rVNz6d4rJmcf4=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "7059ae2fc2d55fa20d7e2671597b516431129445",
|
||||
"rev": "ae6e73772432cfe35bb0ff6de6fdcfa908642b67",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
systems.url = "github:nix-systems/default";
|
||||
devenv.url = "github:cachix/devenv";
|
||||
fenix.url = "github:nix-community/fenix";
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
rustfmt.enable = true;
|
||||
};
|
||||
|
||||
packages = [];
|
||||
packages = with pkgs; [just nushell typst];
|
||||
})
|
||||
];
|
||||
};
|
||||
|
|
|
|||
14
justfile
14
justfile
|
|
@ -1,6 +1,10 @@
|
|||
docs:
|
||||
for doc in $(fd '.typ' './docs' --exclude 'template*' --exclude 'util*'); do \
|
||||
typst compile $doc --root=docs; \
|
||||
mv "$(dirname $doc)/$(basename $doc .typ).pdf" docs/compiled/; \
|
||||
done
|
||||
|
||||
#!/usr/bin/env nu
|
||||
glob **/*.typ --exclude [**/{template.typ,util/**}] | par-each { |source|
|
||||
typst compile $source --root=docs
|
||||
let pdf = (
|
||||
(echo $source | path dirname)
|
||||
| path join (echo $source | path basename | str replace ".typ" ".pdf")
|
||||
)
|
||||
mv $pdf docs/compiled
|
||||
} | ignore
|
||||
|
|
|
|||
Loading…
Reference in a new issue