@@ -100,6 +100,19 @@ export default class ExportCanvasExtension extends CanvasExtension {
100100 . onChange ( value => noFontExport = value )
101101 )
102102
103+ let theme : 'light' | 'dark' = document . body . classList . contains ( 'theme-dark' ) ? 'dark' : 'light'
104+ new Setting ( modal . contentEl )
105+ . setName ( 'Theme' )
106+ . setDesc ( 'The theme used for the export.' )
107+ . addDropdown ( dropdown => dropdown
108+ . addOptions ( {
109+ light : 'Light' ,
110+ dark : 'Dark'
111+ } as Record < 'light' | 'dark' , string > )
112+ . setValue ( theme )
113+ . onChange ( value => theme = value as 'light' | 'dark' )
114+ )
115+
103116 let watermark = false
104117 new Setting ( modal . contentEl )
105118 . setName ( 'Show logo' )
@@ -140,6 +153,7 @@ export default class ExportCanvasExtension extends CanvasExtension {
140153 svg ,
141154 svg ? 1 : pixelRatioFactor ,
142155 svg ? noFontExport : false ,
156+ theme ,
143157 watermark ,
144158 garbledText ,
145159 svg ? true : transparentBackground
@@ -151,7 +165,14 @@ export default class ExportCanvasExtension extends CanvasExtension {
151165 modal . open ( )
152166 }
153167
154- private async exportImage ( canvas : Canvas , nodesToExport : CanvasNode [ ] | null , svg : boolean , pixelRatioFactor : number , noFontExport : boolean , watermark : boolean , garbledText : boolean , transparentBackground : boolean ) {
168+ private async exportImage ( canvas : Canvas , nodesToExport : CanvasNode [ ] | null , svg : boolean , pixelRatioFactor : number , noFontExport : boolean , theme : 'light' | 'dark' , watermark : boolean , garbledText : boolean , transparentBackground : boolean ) {
169+ // Set theme
170+ const cachedTheme = document . body . classList . contains ( 'theme-dark' ) ? 'dark' : 'light'
171+ if ( theme !== cachedTheme ) {
172+ document . body . classList . toggle ( 'theme-dark' , theme === 'dark' )
173+ document . body . classList . toggle ( 'theme-light' , theme === 'light' )
174+ }
175+
155176 const isWholeCanvas = nodesToExport === null
156177 if ( ! nodesToExport ) nodesToExport = [ ...canvas . nodes . values ( ) ]
157178
@@ -325,6 +346,12 @@ export default class ExportCanvasExtension extends CanvasExtension {
325346
326347 // Remove the loading overlay
327348 interactionBlocker . remove ( )
349+
350+ // Restore theme
351+ if ( theme !== cachedTheme ) {
352+ document . body . classList . toggle ( 'theme-dark' , cachedTheme === 'dark' )
353+ document . body . classList . toggle ( 'theme-light' , cachedTheme === 'light' )
354+ }
328355 }
329356 }
330357
0 commit comments