Mc-Zen / tidy

A documentation generator for Typst in Typst.
https://typst.app/universe/package/tidy
MIT License
49 stars 2 forks source link

Use alpha in `type-colors` to support dark mode themes #13

Closed ntjess closed 6 months ago

ntjess commented 7 months ago

When the default tidy style is applied to a page with a black background & white text, the styling prevents visibility: image

However, if you added transparency to every color in the style list, the light mode is unaffected and the dark mode looks fine: image

Relevant changes:

#import "@preview/tidy:0.1.0"
#import tidy.styles.default: *

#let show-parameter-block(
  name, types, content, style-args,
  show-default: false,
  default: none,
) = block(
  inset: 10pt, fill: rgb("ddd3"), width: 100%,
  breakable: style-args.break-param-descriptions,
  [
    #text(weight: "bold", size: 1.1em, name)
    #h(.5cm)
    #types.map(x => (style-args.style.show-type)(x)).join([ #text("or",size:.6em) ])

    #content
    #if show-default [ #parbreak() Default: #raw(lang: "typc", default) ]
  ]
)

#let type-colors = (
  "content": rgb("#a6ebe699"),
  "color": rgb("#a6ebe699"),
  "string": rgb("#d1ffe299"),
  "none": rgb("#ffcbc499"),
  "auto": rgb("#ffcbc499"),
  "boolean": rgb("#ffedc199"),
  "integer": rgb("#e7d9ff99"),
  "float": rgb("#e7d9ff99"),
  "ratio": rgb("#e7d9ff99"),
  "length": rgb("#e7d9ff99"),
  "angle": rgb("#e7d9ff99"),
  "relative-length": rgb("#e7d9ff99"),
  "fraction": rgb("#e7d9ff99"),
  "symbol": rgb("#eff0f399"),
  "array": rgb("#eff0f399"),
  "dictionary": rgb("#eff0f399"),
  "arguments": rgb("#eff0f399"),
  "selector": rgb("#eff0f399"),
  "module": rgb("#eff0f399"),
  "stroke": rgb("#eff0f399"),
  "function": rgb("#f9dfff99"),
)
#let get-type-color(type) = type-colors.at(type, default: rgb("#eff0f333"))

// Create beautiful, colored type box
#let show-type(type) = {
  h(2pt)
  box(outset: 2pt, fill: get-type-color(type), radius: 2pt, raw(type))
  h(2pt)
}
Mc-Zen commented 7 months ago

oof, you're right. Thanks for letting me know and proposing changes!

I will take a look at this, I'm not sure whether to use opacity as you suggested or if it would make sense to expose different default color schemes for light and dark theme from which the user can select.

Mc-Zen commented 7 months ago

Originally, one could pass your own type-color dictionary but I removed that in favour of totally customizable styles. I think it would be good to get this intermediate level of customization back.

Mc-Zen commented 6 months ago

Different colors are now supported in the lastly mentioned way with tidy:0.2.0.

Also, the default theme uses transparency for the parameter blocks as suggested by you.

Thanks!