-
Notifications
You must be signed in to change notification settings - Fork 370
Allow content creators to "Suppress Dark Mode Filter" for PNG and SVG images #4101
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95ab769
[benc/fix-inversion-toggle] Allow content creators to "Suppress Dark …
benchristel d9dbc7e
[benc/fix-inversion-toggle] docs(changeset): Content creators can now…
benchristel e907e43
[benc/fix-inversion-toggle] Enable "Suppress Dark Mode Filter" for GIFs
benchristel fa62cdd
[benc/fix-inversion-toggle] Add test
benchristel 90bac25
[benc/fix-inversion-toggle] Update changeset
benchristel 78b3b5b
[benc/fix-inversion-toggle] Update test
benchristel f7b5d37
[benc/fix-inversion-toggle] Never invert GIF images
benchristel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@khanacademy/perseus-editor": minor | ||
| --- | ||
|
|
||
| Content creators can now exempt SVG images from being inverted in dark mode, in addition to PNGs. |
49 changes: 49 additions & 0 deletions
49
packages/perseus-editor/src/widgets/image-editor/components/dark-mode-toggle.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import {describe, it, expect} from "@jest/globals"; | ||
|
|
||
| import {isGraphicalImage} from "./dark-mode-toggle"; | ||
|
|
||
| describe("isGraphicalImage", () => { | ||
| it("is true for a PNG", () => { | ||
| expect(isGraphicalImage("https://example.com/foo.png")).toBe(true); | ||
| }); | ||
|
|
||
| it("is true for an SVG", () => { | ||
| expect(isGraphicalImage("https://example.com/foo.svg")).toBe(true); | ||
| }); | ||
|
|
||
| it("is false for a JPEG", () => { | ||
| expect(isGraphicalImage("https://example.com/foo.jpg")).toBe(false); | ||
| }); | ||
|
|
||
| it("is false for null", () => { | ||
| expect(isGraphicalImage(null)).toBe(false); | ||
| }); | ||
|
|
||
| it("is false for undefined", () => { | ||
| expect(isGraphicalImage(undefined)).toBe(false); | ||
| }); | ||
|
|
||
| it("is false for a non-url string", () => { | ||
| expect(isGraphicalImage("!foo")).toBe(false); | ||
| }); | ||
|
|
||
| it("is true for a graphical image URL with a query param", () => { | ||
| expect(isGraphicalImage("https://example.com/foo.png?q=1")).toBe(true); | ||
| }); | ||
|
|
||
| it("is false for a non-graphical image URL with a query param containing a graphical filename", () => { | ||
| // This test forces us to actually parse the URL, not just pattern-match | ||
| // on the string. | ||
| expect(isGraphicalImage("https://example.com/foo.jpg?q=bar.png")).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| it("is false for an image with an unrecognized extension starting with .png", () => { | ||
| expect(isGraphicalImage("https://example.com/foo.pngqxz")).toBe(false); | ||
| }); | ||
|
|
||
| it("is false for an image with another extension after .png", () => { | ||
| expect(isGraphicalImage("https://example.com/foo.png.qxz")).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.