Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
style/image viewer: enable background effects for the desktop app
Adorian Dorancc0348442f41
diff --git a/apps/client/src/widgets/note_wrapper.spec.ts b/apps/client/src/widgets/note_wrapper.spec.tsindex 17d1c1f86c..431af0e684 100644--- a/apps/client/src/widgets/note_wrapper.spec.ts+++ b/apps/client/src/widgets/note_wrapper.spec.ts@@ -1,7 +1,7 @@import { describe, expect, it } from "vitest";import { buildNote } from "../test/easy-froca";-import NoteWrapperWidget, { isAlwaysFullWidthByType, isFullWidthNote } from "./note_wrapper";+import NoteWrapperWidget, { hasBackgroundEffects, isAlwaysFullWidthByType, isFullWidthNote } from "./note_wrapper";describe("NoteWrapperWidget", () => {it("preserves the classes owned by SplitNoteContainer through the class reset in refresh()", () => {@@ -19,6 +19,28 @@ describe("NoteWrapperWidget", () => {expect(widget.$widget.hasClass("note-split")).toBe(true);expect(widget.$widget.hasClass("empty-note")).toBe(true);});++ it("marks the split as translucent (bgfx) for the note types that render on a bare background", () => {+ expect(hasBackgroundEffects(buildNote({ title: "Photo", type: "image" }))).toBe(true);++ const pdf = buildNote({ title: "PDF", type: "file" });+ pdf.mime = "application/pdf";+ expect(hasBackgroundEffects(pdf)).toBe(true);++ const audio = buildNote({ title: "Audio", type: "file" });+ audio.mime = "audio/mpeg";+ expect(hasBackgroundEffects(audio)).toBe(true);++ expect(hasBackgroundEffects(buildNote({ title: "Grid", type: "book", "#viewType": "grid" }))).toBe(true);++ // Notes whose content paints its own background stay opaque.+ expect(hasBackgroundEffects(buildNote({ title: "Plain", type: "text" }))).toBe(false);+ expect(hasBackgroundEffects(buildNote({ title: "Calendar", type: "book", "#viewType": "calendar" }))).toBe(false);++ const doc = buildNote({ title: "Doc", type: "file" });+ doc.mime = "application/msword";+ expect(hasBackgroundEffects(doc)).toBe(false);+ });});describe("isAlwaysFullWidthByType", () => {diff --git a/apps/client/src/widgets/note_wrapper.ts b/apps/client/src/widgets/note_wrapper.tsindex 9d3c5df48e..53cce94b55 100644--- a/apps/client/src/widgets/note_wrapper.ts+++ b/apps/client/src/widgets/note_wrapper.ts@@ -64,7 +64,7 @@ export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {this.$widget.addClass(`view-mode-${this.noteContext?.viewScope?.viewMode ?? "default"}`);this.$widget.addClass(note.getColorClass());this.$widget.toggleClass("options", note.isOptions());- this.$widget.toggleClass("bgfx", this.#hasBackgroundEffects(note));+ this.$widget.toggleClass("bgfx", hasBackgroundEffects(note));this.$widget.toggleClass("protected", note.isProtected);const noteLanguage = note?.getLabelValue("language");@@ -72,31 +72,6 @@ export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {this.$widget.toggleClass("rtl", !!locale?.rtl);}- #hasBackgroundEffects(note: FNote): boolean {- const MIME_TYPES_WITH_BACKGROUND_EFFECTS = [- "application/pdf"- ];-- const COLLECTIONS_WITH_BACKGROUND_EFFECTS = [- "grid",- "list"- ];-- if (note.isOptions()) {- return true;- }-- if (note.type === "file" && (MIME_TYPES_WITH_BACKGROUND_EFFECTS.includes(note.mime) || note.mime.startsWith("audio/"))) {- return true;- }-- if (note.type === "book" && COLLECTIONS_WITH_BACKGROUND_EFFECTS.includes(note.getLabelValue("viewType") ?? "none")) {- return true;- }-- return false;- }-async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {// listening on changes of note.type and CSS classconst LABELS_CAUSING_REFRESH = ["cssClass", "language", "viewType", "color", "fullContentWidth"];@@ -113,6 +88,41 @@ export default class NoteWrapperWidget extends FlexContainer<BasicWidget> {/** Classes set on the split by `SplitNoteContainer`, based on the split's position among its siblings. */const CONTAINER_OWNED_CLASSES = [ "active", "last-visible" ];+/**+ * Whether the split should be translucent (`bgfx`), letting the window background effect show through.+ * This suits notes that render their content on a bare background (media, option pages, grid/list+ * collections); notes that paint their own background stay opaque. Exported as a pure function for+ * unit testing.+ */+export function hasBackgroundEffects(note: FNote): boolean {+ const MIME_TYPES_WITH_BACKGROUND_EFFECTS = [+ "application/pdf"+ ];++ const COLLECTIONS_WITH_BACKGROUND_EFFECTS = [+ "grid",+ "list"+ ];++ if (note.isOptions()) {+ return true;+ }++ if (note.type === "image") {+ return true;+ }++ if (note.type === "file" && (MIME_TYPES_WITH_BACKGROUND_EFFECTS.includes(note.mime) || note.mime.startsWith("audio/"))) {+ return true;+ }++ if (note.type === "book" && COLLECTIONS_WITH_BACKGROUND_EFFECTS.includes(note.getLabelValue("viewType") ?? "none")) {+ return true;+ }++ return false;+}+/*** Whether a note is full width purely because of its type (e.g. canvas, collections, media),* irrespective of the `fullContentWidth` label. For these notes the label has no effect, so the