Typst-Snippets/slides.typ

201 lines
5.0 KiB
Plaintext

#import "@preview/polylux:0.3.1": *
#import themes.university as uni
#let count-length(it) = {
let fn = repr(it.func())
if fn == "sequence" { it.children.map(count-length).sum() }
else if fn == "heading" { count-length(it.body) }
else if fn == "figure" { count-length(it.caption.body) }
else if fn == "text" { it.text.len() }
else if fn in ("styled") { count-length(it.child) }
else if fn in ("highlight", "item", "strong", "link") { count-length(it.body) }
else if fn == "equation" { count-length(it.body) }
else { 0 }
}
#let progress-barline = locate( loc => {
if uni.uni-progress-bar.at(loc) {
let cell = block.with( width: 100%, height: 100%, above: 0pt, below: 0pt, breakable: false )
let colors = uni.uni-colors.at(loc)
utils.polylux-progress( ratio => {
grid(
rows: 2pt, columns: (ratio * 100%, 1fr),
cell(fill: colors.a),
cell(fill: colors.b)
)
})
} else { [] }
})
#let header-text(
title: none,
new-section: none
) = {
if title != none {
if new-section != none {
utils.register-section(new-section)
}
locate( loc => {
let colors = uni.uni-colors.at(loc)
block(fill: colors.c, inset: (x: .5em), grid(
columns: (1fr, auto),
align(top + left, heading(level: 2, text(fill: colors.a, title))),
align(top + right, text(fill: colors.a.lighten(65%), utils.current-section))
))
})
} else { [] }
}
#let slides-theme(
aspect-ratio: "16-9",
short-title: none,
short-author: none,
short-date: none,
color-a: rgb("#0C6291"),
color-b: rgb("#A63446"),
color-c: rgb("#FBFEF9"),
progress-bar: true,
body
) = {
uni.university-theme(
aspect-ratio: aspect-ratio,
short-title: short-title,
short-author: short-author,
short-date: short-date,
color-a: color-a,
color-b: color-b,
color-c: color-c,
progress-bar: progress-bar,
body
)
}
#let title-slide(
title: [],
subtitle: none,
authors: (),
institution-name: "University",
date: none,
) = {
let authors = if type(authors) == "array" { authors }else { (authors,) }
let content = locate( loc => {
let colors = uni.uni-colors.at(loc)
align(center + horizon, {
block(
inset: 0em,
breakable: false,
{
text(size: 1.8em, fill: colors.a, strong(title))
if subtitle != none {
parbreak()
text(size: 1.2em, fill: colors.a, subtitle)
}
}
)
set text(size: .8em)
grid(
columns: (1fr,) * calc.min(authors.len(), 3),
column-gutter: 1em,
row-gutter: 1em,
..authors.map(author => text(fill: black, author))
)
v(1em)
if institution-name != none {
parbreak()
text(size: .9em, institution-name)
}
if date != none {
parbreak()
text(size: .8em, date)
}
})
})
logic.polylux-slide(content)
}
#let slide(
title: none,
new-section: none,
body
) = {
uni.slide(title: title, header: header-text(title: title, new-section: new-section), footer: none, new-section: new-section, body)
}
#let matrix-slide(
title: none,
new-section: none,
columns: none,
rows: none,
..bodies
) = {
let header = {
set align(top)
grid(rows: (auto, auto), row-gutter: 3mm, progress-barline, header-text(title: title, new-section: new-section))
}
let footer = {
set text(size: 10pt)
set align(center + bottom)
let cell(fill: none, it) = rect(
width: 100%, height: 100%, inset: 1mm, outset: 0mm, fill: fill, stroke: none,
align(horizon, text(fill: white, it))
)
locate( loc => {
let colors = uni.uni-colors.at(loc)
show: block.with(width: 100%, height: auto, fill: colors.b)
grid(
columns: (25%, 1fr, 15%, 10%),
rows: (1.5em, auto),
cell(fill: colors.a, uni.uni-short-author.display()),
cell(uni.uni-short-title.display()),
cell(uni.uni-short-date.display()),
cell(logic.logical-slide.display() + [~/~] + utils.last-slide-number)
)
})
}
set page(
margin: ( top: 2em, bottom: 1em, x: 0em ),
header: header,
footer: footer,
footer-descent: 0em,
header-ascent: .6em,
)
uni.matrix-slide(..bodies)
}
#let slide-outline-length(loc) = {
let section-state = state("polylux-sections", ())
let sections = section-state.final(loc)
sections.len() - 1
}
#let slide-outline(num) = {
set text(font: "Cascadia Mono")
locate(loc => {
let section-state = state("polylux-sections", ())
let sections = section-state.final(loc)
for p in range(0, num) {
let section = sections.at(p)
let content = {
let url = link(section.loc, section.body)
let page = logic.logical-slide.at(section.loc).at(0)
let length = 46 - str(page).len() - count-length(section.body)
let dots = " " + "." * length
[#grid(
columns: (auto, 1fr, 1fr),
url, align[#dots], align(right)[#page]
)]
}
[+ #content ]
}
})
}