forked from lkoehl/typst-boxes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typst-boxes.typ
172 lines (157 loc) · 3.85 KB
/
typst-boxes.typ
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#let colorbox(title: "title", color: none, radius: 2pt, width: auto, breakable: true, body) = {
let strokeColor = luma(70)
let backgroundColor = white
if color == "red" {
strokeColor = rgb(237, 32, 84)
backgroundColor = rgb(253, 228, 224)
} else if color == "green" {
strokeColor = rgb(102, 174, 62)
backgroundColor = rgb(235, 244, 222)
} else if color == "blue" {
strokeColor = rgb(29, 144, 208)
backgroundColor = rgb(232, 246, 253)
}
return box(
fill: backgroundColor,
stroke: 2pt + strokeColor,
radius: radius,
width: width,
breakable: breakable
)[
#block(
fill: strokeColor,
inset: 8pt,
radius: (top-left: radius, bottom-right: radius),
)[
#text(fill: white, weight: "bold")[#title]
]
#block(
width: 100%,
inset: (x: 8pt, bottom: 8pt)
)[
#body
]
]
}
#let slantedBackground(color: black, body) = {
set text(fill: white, weight: "bold")
style(styles => {
let size = measure(body, styles)
let inset = 8pt
[#block()[
#polygon(
fill: color,
(0pt, 0pt),
(0pt, size.height + (2*inset)),
(size.width + (2*inset), size.height + (2*inset)),
(size.width + (2*inset) + 6pt, 0cm)
)
#place(center + top, dy: size.height, dx: -3pt)[#body]
]]
})
}
#let slantedColorbox(title: "title", color: none, radius: 0pt, width: auto, breakable: true, body) = {
let strokeColor = luma(70)
let backgroundColor = white
if color == "red" {
strokeColor = rgb(237, 32, 84)
backgroundColor = rgb(253, 228, 224)
} else if color == "green" {
strokeColor = rgb(102, 174, 62)
backgroundColor = rgb(235, 244, 222)
} else if color == "blue" {
strokeColor = rgb(29, 144, 208)
backgroundColor = rgb(232, 246, 253)
}
return box(
fill: backgroundColor,
stroke: 2pt + strokeColor,
radius: radius,
width: width,
breakable: breakable
)[
#slantedBackground(color: strokeColor)[#title]
#block(
width: 100%,
inset: (top: -2pt, x: 10pt, bottom: 10pt)
)[
#body
]
]
}
#let outlinebox(title: "title",color: none, width: 100%, radius: 2pt, centering: false, breakable: true, body) = {
let strokeColor = luma(70)
if color == "red" {
strokeColor = rgb(237, 32, 84)
} else if color == "green" {
strokeColor = rgb(102, 174, 62)
} else if color == "blue" {
strokeColor = rgb(29, 144, 208)
}
return block(
stroke: 2pt + strokeColor,
radius: radius,
width: width,
above: 26pt,
breakable: breakable
)[
#if centering [
#place(top + center, dy: -12pt)[
#block(
fill: strokeColor,
inset: 8pt,
radius: radius,
)[
#text(fill: white, weight: "bold")[#title]
]
]
] else [
#place(top + start, dy: -12pt, dx:20pt)[
#block(
fill: strokeColor,
inset: 8pt,
radius: radius,
)[
#text(fill: white, weight: "bold")[#title]
]
]
]
#block(
width: 100%,
inset: (top:20pt, x: 10pt, bottom: 10pt)
)[
#body
]
]
}
#let stickybox(rotation: 0deg, width: 100%, body) = {
let stickyYellow = rgb(255, 240, 172)
return rotate(rotation)[
#let shadow = 100%
#if width != 100% {
shadow = width
}
#place(bottom + center, dy: 0.04*shadow)[
#image("background.svg",
width: shadow - 3mm,
)
]
#block(
fill: stickyYellow,
width: width
)[
#place(top + center, dy: -2mm)[
#image("tape.svg",
width: calc.clamp(width * 0.35 / 1cm, 1, 4) * 1cm,
height: 4mm,
)
]
#block(
width: 100%,
inset: (top:12pt, x: 8pt, bottom: 8pt)
)[
#body
]
]
]
}