Skip to content

Commit

Permalink
Fix waveform diagram default color scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Apr 7, 2024
1 parent eb22aa3 commit a7d392e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This package embeds the [upstream WaveDrom library][upstream] bundled with the m

* The `id` attribute of the root `<svg>` element is removed.
* The stylesheets are altered to take into account dark color scheme preference via media queries.
* When rendering waveform diagrams, the `default` skin automatically switches between light and dark color scheme, and the `light` skin corresponds to the upstream `default` skin.
* By default, the diagrams automatically switch between light and dark color schemes based on the user preference. The light variant is the default upstream WaveDrom color scheme, and the dark variant is the same but with colors inverted. Unfortunately, it is not feasible to use media queries to switch between the default/light skin and the dark skin for waveform diagrams, and an inversion filter is used instead.
* Several otherwise blocking bugs are worked around.

[upstream]: https://npmjs.org/package/wavedrom
Expand All @@ -63,4 +63,4 @@ Unlike most [YoWASP] packages, this package does not automatically track upstrea
License
-------

This package is covered by the [MIT license](LICENSE.txt).
This package is covered by the [MIT license](LICENSE.txt).
7 changes: 4 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ const WaveSkin = {
WaveSkin.default = JSON.parse(JSON.stringify(WaveSkin.light));
// `laneParamsFromSkin` uses hardcoded offsets into the skin to derive parameters, so the tag
// structure of a skin must be preserved exactly, e.g. there can be exactly one <style> element.
WaveSkin.default[2][2] = `\
@media(prefers-color-scheme:light){${WaveSkin.light[2][2]}}\
@media(prefers-color-scheme:dark){${WaveSkin.dark[2][2]}}`;
// Regretfully, some of the colors for the default/light color scheme are hardcoded in SVG
// elements, making it infeasible to switch between the CSS for the default/light and dark schemes
// using media queries.
WaveSkin.default[2][2] = `@media(prefers-color-scheme:dark){:root{filter:invert(1)}}${WaveSkin.light[2][2]}}`;

function renderSignal(source) {
const rendered = WaveDrom_renderSignal(0, source, WaveSkin);
Expand Down
2 changes: 1 addition & 1 deletion pypi/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ __pycache__/
/dist

/version.txt
/yowasp_wavedrom/bundle.js
/yowasp_wavedrom/bundle.js

0 comments on commit a7d392e

Please sign in to comment.