From 5d03b40dc995a704e803896ee4de04f03289f42d Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 12 Apr 2024 15:38:00 +0200 Subject: refactor(frontend): remember export setting for auto theme --- .../src/graph/export/ExportSettingsStore.ts | 42 ++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/subprojects/frontend/src/graph/export/ExportSettingsStore.ts b/subprojects/frontend/src/graph/export/ExportSettingsStore.ts index 478227af..7c691a7b 100644 --- a/subprojects/frontend/src/graph/export/ExportSettingsStore.ts +++ b/subprojects/frontend/src/graph/export/ExportSettingsStore.ts @@ -7,18 +7,21 @@ import { makeAutoObservable } from 'mobx'; export type ExportFormat = 'svg' | 'pdf' | 'png'; -export type ExportTheme = 'light' | 'dark' | 'dynamic'; +export type StaticTheme = 'light' | 'dark'; +export type ExportTheme = StaticTheme | 'dynamic'; export default class ExportSettingsStore { format: ExportFormat = 'svg'; - theme: ExportTheme = 'light'; + private staticTheme: StaticTheme = 'light'; - transparent = true; + private _theme: ExportTheme = 'light'; - embedSVGFonts = false; + private _transparent = true; - embedPDFFonts = true; + private embedSVGFonts = false; + + private embedPDFFonts = true; scale = 100; @@ -28,24 +31,17 @@ export default class ExportSettingsStore { setFormat(format: ExportFormat): void { this.format = format; - if (this.theme === 'dynamic' && this.format !== 'svg') { - this.theme = 'light'; - } } setTheme(theme: ExportTheme): void { - this.theme = theme; - if (this.theme === 'dynamic') { - this.format = 'svg'; - this.transparent = true; + this._theme = theme; + if (theme !== 'dynamic') { + this.staticTheme = theme; } } toggleTransparent(): void { - this.transparent = !this.transparent; - if (!this.transparent && this.theme === 'dynamic') { - this.theme = 'light'; - } + this._transparent = !this._transparent; } toggleEmbedFonts(): void { @@ -56,7 +52,18 @@ export default class ExportSettingsStore { this.scale = scale; } + get theme(): ExportTheme { + return this.format === 'svg' ? this._theme : this.staticTheme; + } + + get transparent(): boolean { + return this.theme === 'dynamic' ? true : this._transparent; + } + get embedFonts(): boolean { + if (this.theme === 'dynamic') { + return false; + } return this.format === 'pdf' ? this.embedPDFFonts : this.embedSVGFonts; } @@ -65,9 +72,6 @@ export default class ExportSettingsStore { this.embedPDFFonts = embedFonts; } this.embedSVGFonts = embedFonts; - if (this.embedSVGFonts && this.theme === 'dynamic') { - this.theme = 'light'; - } } get canSetDynamicTheme(): boolean { -- cgit v1.2.3-54-g00ecf