Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for color-scheme dependent pictures #236

Merged
merged 3 commits into from
Feb 16, 2024

Conversation

CosmicHorrorDev
Copy link
Collaborator

@CosmicHorrorDev CosmicHorrorDev commented Feb 13, 2024

Resolves #231

Adds support for color-scheme dependent <picture>s like

<p align="center">
  <a href="https://nixos.org">
    <picture>
      <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/NixOS/nixos-homepage/master/logo/nixos-hires.png"/>
      <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/NixOS/nixos-artwork/master/logo/nixos-white.png"/>
      <img src="https://raw.githubusercontent.com/NixOS/nixos-homepage/master/logo/nixos-hires.png" width="500px" alt="NixOS logo"/>
    </picture>
  </a>
</p>

which displays like so on this PR

Dark Light
image image

Implementation-wise the main parts involved

  • Threading color_scheme: Option<ResolvedTheme> through everything to represent the None (default src), Some(Dark) (dark's srcset), and Some(Light) (light's srcset)
  • Handling the <picture> meta-element which was done using a picture::Builder that stores relevant information from the various elements and finalizes on the closing tag. Overall I'm rather happy with this approach to complex elements

@CosmicHorrorDev CosmicHorrorDev added C-enhancement Category: New feature or request A-image Area: Image decoding/rendering/etc. A-theme Area: Themes, system theme detection, and syntax highlighting A-interpreter Area: Changes impacting the HTML interpreter labels Feb 13, 2024
@CosmicHorrorDev CosmicHorrorDev force-pushed the pic-dark-light branch 2 times, most recently from 4fd4660 to 44b1199 Compare February 15, 2024 02:22
@CosmicHorrorDev CosmicHorrorDev marked this pull request as ready for review February 15, 2024 03:00
@CosmicHorrorDev CosmicHorrorDev linked an issue Feb 16, 2024 that may be closed by this pull request
@CosmicHorrorDev CosmicHorrorDev merged commit 5b7929b into Inlyne-Project:main Feb 16, 2024
9 checks passed
@CosmicHorrorDev CosmicHorrorDev deleted the pic-dark-light branch February 16, 2024 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-image Area: Image decoding/rendering/etc. A-interpreter Area: Changes impacting the HTML interpreter A-theme Area: Themes, system theme detection, and syntax highlighting C-enhancement Category: New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for theme-specific picture+source image variants
1 participant