-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.typ
More file actions
65 lines (51 loc) · 1.52 KB
/
Copy pathlib.typ
File metadata and controls
65 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! typst-iconify
//! https://github.com/jmuchovej/typst-iconify
#let iconify = state("iconify", (:))
#let from-key(name) = {
let (library, icon) = name.replace("iconify::", "").split(":")
return (library: library, icon: icon)
}
#let to-key(library: auto, icon: auto) = (library, icon).join(":")
#let icon-key(name) = {
let state-key = ("iconify", name).join("::")
return state-key
}
#let load-icon(alias, iconset, icon) = {
let file-path = "./icons/" + iconset + "/" + icon + ".svg"
let state-key = icon-key(to-key(library: alias, icon: icon))
state(state-key, none).update(image(file-path, height: 1em))
}
#let load-icons(alias, iconset) = {
let icon-list = json("./collections/" + iconset + ".json").icons
for icon in icon-list {
load-icon(alias, iconset, icon)
}
}
// TODO support dynamically calling icons
#let show-icon(name) = (
context {
let state-key = icon-key(name)
let (library, icon) = from-key(name)
return state(state-key).get()
}
)
#let prefetch-icons(..iconsets) = {
let desired-icons = (:)
for icon in iconsets.pos() {
desired-icons.insert(icon, icon)
}
for (alias, icon) in iconsets.named() {
assert(
icon not in desired-icons,
message: "Found " + icon + " already specified! Please clean-up your icon specification!",
)
desired-icons.insert(alias, icon)
}
iconify.update(desired-icons)
for (alias, iconset) in desired-icons {
load-icons(alias, iconset)
}
}
#let icon(name, height: 1em, width: 1em, ..args) = {
return show-icon(name)
}