tinymist/typ/templates/theme.typ
Myriad-Dreamin 51db97ffcc
Some checks failed
tinymist::ci / Duplicate Actions Detection (push) Has been cancelled
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Has been cancelled
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Has been cancelled
tinymist::ci / prepare-build (push) Has been cancelled
tinymist::gh_pages / build-gh-pages (push) Has been cancelled
tinymist::ci / E2E Tests (darwin-arm64 on macos-latest) (push) Has been cancelled
tinymist::ci / E2E Tests (linux-x64 on ubuntu-22.04) (push) Has been cancelled
tinymist::ci / E2E Tests (linux-x64 on ubuntu-latest) (push) Has been cancelled
tinymist::ci / E2E Tests (win32-x64 on windows-2019) (push) Has been cancelled
tinymist::ci / E2E Tests (win32-x64 on windows-latest) (push) Has been cancelled
tinymist::ci / build-binary (push) Has been cancelled
tinymist::ci / build-vsc-assets (push) Has been cancelled
tinymist::ci / build-vscode (push) Has been cancelled
tinymist::ci / build-vscode-others (push) Has been cancelled
tinymist::ci / publish-vscode (push) Has been cancelled
feat: build theme-aware pictures (equations) (#1772)
* revert: "test: bad changes"

* feat: m1source
2025-06-05 11:10:04 +08:00

55 lines
1.2 KiB
Typst

#import "@preview/shiroa:0.2.3": templates, book-sys
#import templates: *
#let is-md-target = book-sys.target == "md"
#let sys-is-html-target = book-sys.sys-is-html-target
// Theme (Colors)
#let dark-theme = book-theme-from(toml("theme-style.toml"), xml: it => xml(it), target: "web-ayu")
#let light-theme = book-theme-from(
toml("theme-style.toml"),
xml: it => xml(it),
target: if sys-is-html-target {
"web-light"
} else {
"pdf"
},
)
#let default-theme = if sys-is-html-target {
dark-theme
} else {
light-theme
}
#let theme-box(render, tag: "div", theme-tag: none) = if is-md-target {
show: html.elem.with(tag)
show: html.elem.with("picture")
html.elem(
"m1source",
attrs: (media: "(prefers-color-scheme: dark)"),
render(dark-theme),
)
render(light-theme)
} else if sys-is-html-target {
if theme-tag == none {
theme-tag = tag
}
html.elem(
tag,
attrs: (class: "code-image themed"),
{
html.elem(
theme-tag,
render(dark-theme),
attrs: (class: "dark"),
)
html.elem(
theme-tag,
render(light-theme),
attrs: (class: "light"),
)
},
)
} else {
render(default-theme)
}