import { FileSystemAdapter } from "obsidian" ; import path from "path" ; import fs from "fs" ; import { TextInputSuggest } from "./Suggest" ; export class ThemeSuggest extends TextInputSuggest < string > { getSuggestions ( inputStr ) { const adapter = this . app . vault . adapter as FileSystemAdapter ; const vaultDirectory = adapter . getBasePath ( ) ; const pluginDirectory = path . join ( vaultDirectory , this . app . vault . configDir , 'plugins/obsidian-advanced-slides/' ) ; const cssDirectory = path . join ( pluginDirectory , 'css/' ) ; const themeDirectory = path . join ( pluginDirectory , 'dist/theme/' ) ; const cssFiles = this . formatCss ( this . getFiles ( [ cssDirectory ] ) ) ; const themeFiles = this . formatTheme ( this . getFiles ( [ themeDirectory ] ) ) ; const allFiles = [ ... cssFiles , ... themeFiles ] ; const files = [ ] ; const lowerCaseInputStr = inputStr . toLowerCase ( ) ; allFiles . forEach ( ( file ) => { if ( file . toLowerCase ( ) . includes ( lowerCaseInputStr ) ) { files . push ( file ) ; } } ) ; return files ; } formatCss ( input ) { return Array . of ( ... input ) . filter ( ( value ) => value . endsWith ( '.css' ) ) . map ( ( value ) => 'css/' + value ) ; } formatTheme ( input ) { return Array . of ( ... input ) . filter ( ( value ) => value . endsWith ( '.css' ) ) . map ( ( value ) => value . replaceAll ( '.css' , '' ) ) ; } getFiles ( directories ) { const result = new Set < string > ( ) ; for ( const directory of directories ) { fs . readdirSync ( directory ) . forEach ( file => { result . add ( file ) ; } ) ; } return result ; } renderSuggestion ( file , el ) { el . setText ( file ) ; } selectSuggestion ( file ) { this . inputEl . value = file ; this . inputEl . trigger ( "input" ) ; this . close ( ) ; } }