ops: add lib with tag function

This commit is contained in:
Klagarge committed 2026-10-11 23:22:42 +02:00
1 parent 975ba4f312
commit 54a69b51ae
1 file changed
+51
+51
View File
@@ -0,0 +1,51 @@
// #import "@preview/calepin:0.1.0" as calepin
#import "@preview/hes-so-core:0.1.0"
#import "@preview/frackable:0.2.0": *
// #import "@preview/cetz:0.5.2"
//
// #let drawing(..args) = {
// let canvas = cetz.canvas(..args)
// context if target() == "html" {
// html.frame(canvas)
// } else {
// canvas
// }
// }
#let tag(body, fill: yellow, stroke: auto) = {
let stroke-color = if stroke == auto {
fill.darken(25%)
} else if type(stroke) == color {
stroke
} else if type(stroke) == stroke {
stroke.paint
} else {
fill.darken(25%)
}
let stroke-rule = if stroke == auto {
1pt + stroke-color
} else if type(stroke) == color {
1pt + stroke
} else {
stroke
}
context if target() == "html" {
let bg-hex = fill.to-hex()
let border-hex = stroke-color.to-hex()
html.elem("span", attrs: (
style: "display: inline-block; background-color: " + bg-hex
+ "; border: 1px solid " + border-hex
+ "; color: #1f2933; border-radius: 1em; padding: 0.2em 0.6em; font-size: 0.85em; font-weight: 500; line-height: 1.2;"
))[#body]
} else {
box(
fill: fill,
stroke: stroke-rule,
radius: 1em,
inset: (x: 0.5em, y: 0.5em)
)[#body]
}
}