Skip to content

Allow content creators to "Suppress Dark Mode Filter" for PNG and SVG images - #4101

Merged
benchristel merged 7 commits into
mainfrom
benc/fix-inversion-toggle
Aug 21, 2026
Merged

Allow content creators to "Suppress Dark Mode Filter" for PNG and SVG images#4101
benchristel merged 7 commits into
mainfrom
benc/fix-inversion-toggle

Conversation

@benchristel

@benchristel benchristel commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary:

Context: In dark mode, we use a CSS filter to invert the lightness of each pixel
in an image. This allows diagrams authored with a transparent background and
black foreground to be visible against the dark background of the page.

However, we don't want to invert all images. Photographs and paintings should
not be inverted in dark mode. We never invert JPG images, since those are likely
to be photographs, and we also don't invert GIFs. Content creators can also use
the "Suppress Dark Mode Filter" toggle in the image widget editor to turn off
the inversion for selected images.

Previously, this option was only available for PNGs. But we've encountered some
real-world examples where SVG images should not be inverted. Therefore, we
are expanding the setting to SVGs.

Issue: LEMS-4473

Test plan:

  • View the EditorPage story in Storybook
  • Add an image widget
  • Set the image URL to
    https://ka-perseus-images.s3.amazonaws.com/34a448332ebd1515364999919ae1b646aaebba0f.svg
  • The "Suppress Dark Mode Filter" toggle should be enabled and effective.

… suppress value inversion in dark mode for SVG images as well as PNGs."
@github-actions

Copy link
Copy Markdown
Contributor

npm Snapshot

Want to try this PR's changes before it merges? Comment /snapshot below and we'll publish an npm snapshot you can install right away.

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Size Change: +73 B (+0.01%)

Total Size: 519 kB

📦 View Changed
Filename Size Change
packages/perseus-editor/dist/es/index.js 106 kB +73 B (+0.07%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.6 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 6.31 kB
packages/math-input/dist/es/index.js 98.6 kB
packages/math-input/dist/es/strings.js 1.63 kB
packages/perseus-core/dist/es/index.item-splitting.js 13.1 kB
packages/perseus-core/dist/es/index.js 28.3 kB
packages/perseus-linter/dist/es/index.js 10.1 kB
packages/perseus-score/dist/es/index.js 9.86 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/index.js 203 kB
packages/perseus/dist/es/strings.js 12.9 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.12 kB

compressed-size-action

@benchristel
benchristel marked this pull request as draft August 20, 2026 14:48
@benchristel
benchristel force-pushed the benc/fix-inversion-toggle branch from 96106cd to e907e43 Compare August 20, 2026 15:26
@benchristel benchristel changed the title Allow content creators to "Suppress Dark Mode Filter" for all image types Allow content creators to "Suppress Dark Mode Filter" for PNG, SVG, and GIF images Aug 20, 2026
@benchristel
benchristel marked this pull request as ready for review August 20, 2026 16:04

@Myranae Myranae left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Looks like the text in the "tooltip shows note about image format for non-PNG images" image editor test might need to be updated, but otherwise, all good!

Comment thread packages/perseus/src/styles/widgets/image.css Outdated
@benchristel benchristel changed the title Allow content creators to "Suppress Dark Mode Filter" for PNG, SVG, and GIF images Allow content creators to "Suppress Dark Mode Filter" for PNG and SVG images Aug 20, 2026
* image.css and dark-mode-toggle.tsx. Replace these selectors with a
* class that gets added to images that should be inverted, so the set of
* extensions can have a single representation in TypeScript code.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought with this current setup (all images with either of these extensions) is that any image in Perseus automatically gets this treatment. So, for instance, if content has an inline image, it will get the dark mode treatment. If we set up a function that adds a class to images, I would want to ensure that all avenues of including an image (both now and in the future) are managed by that code.

@mark-fitzgerald mark-fitzgerald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@benchristel
benchristel merged commit 2a57799 into main Aug 21, 2026
15 of 24 checks passed
@benchristel
benchristel deleted the benc/fix-inversion-toggle branch August 21, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants