1+ /*
2+ THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
3+ if you want to view the source, please visit the github repository of this plugin
4+ */
5+
6+ var __defProp = Object . defineProperty ;
7+ var __getOwnPropDesc = Object . getOwnPropertyDescriptor ;
8+ var __getOwnPropNames = Object . getOwnPropertyNames ;
9+ var __hasOwnProp = Object . prototype . hasOwnProperty ;
10+ var __export = ( target , all ) => {
11+ for ( var name in all )
12+ __defProp ( target , name , { get : all [ name ] , enumerable : true } ) ;
13+ } ;
14+ var __copyProps = ( to , from , except , desc ) => {
15+ if ( from && typeof from === "object" || typeof from === "function" ) {
16+ for ( let key of __getOwnPropNames ( from ) )
17+ if ( ! __hasOwnProp . call ( to , key ) && key !== except )
18+ __defProp ( to , key , { get : ( ) => from [ key ] , enumerable : ! ( desc = __getOwnPropDesc ( from , key ) ) || desc . enumerable } ) ;
19+ }
20+ return to ;
21+ } ;
22+ var __toCommonJS = ( mod ) => __copyProps ( __defProp ( { } , "__esModule" , { value : true } ) , mod ) ;
23+
24+ // main.ts
25+ var main_exports = { } ;
26+ __export ( main_exports , {
27+ default : ( ) => ThemeToggle
28+ } ) ;
29+ module . exports = __toCommonJS ( main_exports ) ;
30+ var import_obsidian = require ( "obsidian" ) ;
31+ var ThemeToggle = class extends import_obsidian . Plugin {
32+ async onload ( ) {
33+ this . ribbon = this . addRibbonIcon ( this . getThemeIcon ( ) , "Toggle to " + ( this . getCurrentTheme ( ) === "obsidian" ? "light" : "dark" ) + " mode" , ( evt ) => {
34+ this . app . changeTheme ( this . getCurrentTheme ( ) === "obsidian" ? "moonstone" : "obsidian" ) ;
35+ ( 0 , import_obsidian . setIcon ) ( evt . target , this . getThemeIcon ( ) ) ;
36+ evt . target . setAttr ( "aria-label" , "Toggle to " + ( this . getCurrentTheme ( ) === "obsidian" ? "light" : "dark" ) + " mode" ) ;
37+ } ) ;
38+ this . ribbon . addClass ( "ribbon-theme-toggle-plugin" ) ;
39+ this . registerEvent (
40+ this . app . workspace . on ( "css-change" , ( ) => {
41+ setTimeout ( ( ) => {
42+ ( 0 , import_obsidian . setIcon ) ( this . ribbon , this . getCurrentTheme ( ) === "obsidian" ? "sun" : "moon" ) ;
43+ this . ribbon . setAttr ( "aria-label" , "Toggle to " + ( this . getCurrentTheme ( ) === "obsidian" ? "light" : "dark" ) + " mode" ) ;
44+ } , 10 ) ;
45+ } )
46+ ) ;
47+ this . addCommand ( {
48+ id : "toggle-theme" ,
49+ name : "Toggle theme" ,
50+ callback : ( ) => {
51+ this . app . changeTheme ( this . getCurrentTheme ( ) === "obsidian" ? "moonstone" : "obsidian" ) ;
52+ ( 0 , import_obsidian . setIcon ) ( this . ribbon , this . getCurrentTheme ( ) === "obsidian" ? "sun" : "moon" ) ;
53+ }
54+ } ) ;
55+ }
56+ onunload ( ) {
57+ this . ribbon . remove ( ) ;
58+ }
59+ getCurrentTheme ( ) {
60+ let currentTheme = this . app . getTheme ( ) === "obsidian" ? "obsidian" : "moonstone" ;
61+ return currentTheme ;
62+ }
63+ getThemeIcon ( ) {
64+ let moonOrSunIcon = this . getCurrentTheme ( ) === "obsidian" ? "sun" : "moon" ;
65+ return moonOrSunIcon ;
66+ }
67+ } ;
68+
69+ /* nosourcemap */
0 commit comments