Skip to content

Commit

Permalink
auto invert images in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ibastawisi committed Jan 17, 2025
1 parent 63262bb commit 3800c47
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
14 changes: 1 addition & 13 deletions src/editor/nodes/GraphNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,9 @@ export class GraphNode extends ImageNode {
return node;
}

createDOM(config: EditorConfig, editor: LexicalEditor): HTMLElement {
const element = super.createDOM(config, editor);
element.dataset.type = 'graph';
return element;
}

exportDOM(editor: LexicalEditor): DOMExportOutput {
const isSVG = this.__src.startsWith('data:image/svg+xml');
if (!isSVG) {
const { element } = super.exportDOM(editor);
if (element && isHTMLElement(element)) {
element.dataset.type = 'graph';
}
return { element };
}
if (!isSVG) return super.exportDOM(editor);
const element = this.createDOM(editor._config, editor);
if (element && isHTMLElement(element)) {
const html = decodeURIComponent(this.__src.split(',')[1]);
Expand Down
1 change: 0 additions & 1 deletion src/editor/nodes/ImageNode/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
}

.LexicalTheme__image .image-control-wrapper--active,
.LexicalTheme__image .image-control-wrapper:active ,
.LexicalTheme__image:focus-within {
outline: 2px solid rgb(95 183 255 / 75%);
}
Expand Down
10 changes: 8 additions & 2 deletions src/editor/plugins/ToolbarPlugin/Tools/ImageTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useEffect, useState } from "react";
import { SET_DIALOGS_COMMAND } from '../Dialogs/commands';
import { SxProps, Theme } from '@mui/material/styles';
import { ToggleButtonGroup, ToggleButton, SvgIcon } from "@mui/material";
import { Edit, ClosedCaptionDisabled, ClosedCaption, ViewHeadline, Delete, Draw } from "@mui/icons-material";
import { Edit, ClosedCaptionDisabled, ClosedCaption, ViewHeadline, Delete, Draw, FilterBAndW } from "@mui/icons-material";
import { $isIFrameNode, IFrameNode } from "@/editor/nodes/IFrameNode";

const FormatImageRight = () => <SvgIcon viewBox='0 -960 960 960'>
Expand Down Expand Up @@ -71,6 +71,12 @@ export default function ImageTools({ editor, node, sx }: { editor: LexicalEditor
onClick={toggleShowCaption}>
{node.getShowCaption() ? <ClosedCaption /> : <ClosedCaptionDisabled />}
</ToggleButton>
<ToggleButton value="filter-toggle" key="filter-toggle" selected={!!(style && style.filter !== "none")}
onClick={() => {
updateStyle({ "filter": style?.filter === "none" ? "" : "none" });
}}>
<FilterBAndW />
</ToggleButton>
<ToggleButton value="delete"
onClick={() => {
editor.update(() => {
Expand All @@ -88,7 +94,7 @@ export default function ImageTools({ editor, node, sx }: { editor: LexicalEditor
}}>
<FormatImageLeft />
</ToggleButton>
<ToggleButton value="float-none" key="float-none" selected={!style || style?.float === "none"}
<ToggleButton value="float-none" key="float-none" selected={!style?.float || style?.float === "none"}
onClick={() => {
updateStyle({ "float": "none", "margin": "0", "max-width": "100%" });
}}>
Expand Down
8 changes: 4 additions & 4 deletions src/editor/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ iframe {
}

[theme=light] .LexicalTheme__image svg :is(path, rect, circle, ellipse, polygon, polyline, line, text, tspan, textPath),
[theme=light] .LexicalTheme__image[data-type='graph'] img {
filter: initial !important;
[theme=light] .LexicalTheme__image img {
filter: none !important;
}

[theme=light] .details__container .details__container li img {
Expand Down Expand Up @@ -787,7 +787,7 @@ iframe {
}

[theme=dark] .LexicalTheme__image svg :is(path, rect, circle, ellipse, polygon, polyline, line, text, tspan, textPath),
[theme=dark] .LexicalTheme__image[data-type='graph'] img {
[theme=dark] .LexicalTheme__image:not(:is([style*="filter:none"], [style*="filter: none"])) img {
filter: invert(93%) hue-rotate(180deg);
}

Expand Down Expand Up @@ -847,7 +847,7 @@ iframe {
}

.LexicalTheme__image svg :is(path, rect, circle, ellipse, polygon, polyline, line, text, tspan, textPath),
.LexicalTheme__image[data-type='graph'] img {
.LexicalTheme__image:not(:is([style*="filter:none"], [style*="filter: none"])) img {
filter: invert(93%) hue-rotate(180deg);
}
}

0 comments on commit 3800c47

Please sign in to comment.