npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sphinx-colorschemed-images

v0.2.0

Published

Include color-scheme aware images in Sphinx projects.

Downloads

319

Readme

Color schemed images for Sphinx tests

An extension for Sphinx that adds support for color-scheme aware images. This README.md is also used for the NodeJS package. The NodeJS package contains only the JavaScript module. See below the paragraph about the JavaScript plugin.

Tested

Description

Sphinx Color Schemed Images is an extension that makes available two new image directives to your project:

  • cs_image extends the image directive, and
  • cs_figure extends the figure directive.

These new directives add data attributes to the HTML <img> tag to help web browsers to automatically transition between light and dark color schemes. The extension adds a bit of JavaScript code to trigger an image update when the user switches the color scheme.

Usage

Install the package:

pip install sphinx-colorschemed-images

Add sphinx_colorschemed_images to the extensions setting, in your project's conf.py file.

As an example, download the following files and place them in the source directory of your Sphinx project, inside the image directory. I assume the sources are in the docs/ directory, and the image directory is docs/img/:

Now edit your index.rst or index.md file, and add a cs_image directive. For index.rst, add:

.. cs_image:: img/balloon.png
   :alt: A balloon icon
   :align: center
   :width: 200

If it is an index.md, add the following instead:

```{cs_image} img/balloon.png
:alt: A balloon icon
:align: center
:width: 200
```

Build your Sphinx project and serve it. You should see either the image for the light color scheme, balloon.light.png, or the image for the dark color scheme, balloon.dark.png. Switch your operating system settings and the image should update automatically.

JavaScript plugin

When using the extension Sphinx adds a script to your HTML output, sphinx-colorschemed-images.js, that listens for changes on the user's preferred color-scheme and switches between the images accordingly. It works in all Sphinx themes regardless of whether they have support for light/dark color schemes.

If you have your own theme and it offers the user control over the color-scheme, you can use the NPM package sphinx-colorschemed-images and its class SphinxColorschemeImageHandler when building your own plugin.

The source code is rather small, so it is better to look into it than to explain it here. If your theme already listens for changes in prefers-color-scheme, pass {auto: false} to the constructor, to avoid adding the listeners again. To switch between light and dark images, call the activate method with either light or dark.

Contributing

The Makefile is the lead for all development tasks. Mind the tests in Python and JavaScript.

Appropriate documentation will come soon.