Skip to content

CustomCSS

Unofficial

Manager for custom CSS themes and snippets.

Import:

import type { CustomCSS } from '@obsidian-typings/obsidian-public-latest';

Signature:

export interface CustomCSS extends Component

Extends: Component

Constructor

new CustomCSS(app: App)

Constructor.

To get the constructor instance, use getCustomCSSConstructor from obsidian-typings/implementations.

Properties

PropertyTypeDescription
_childrenComponent[]Child Components attached to current component, will be unloaded on unloading parent component.
(Inherited from Component)
_eventsEventRef[]Events that are attached to the current component, will be detached on unloading parent component.
(Inherited from Component)
_loadedbooleanWhether the component and its children are loaded.
(Inherited from Component)
appAppReference to the obsidian#App.
csscacheMap<string, string>Cache of CSS snippet filepath (relative to vault root) to CSS snippet contents.
enabledSnippetsSet<string>Set of enabled snippet, given by filenames.
extraStyleElsHTMLStyleElement[]Contains references to Style elements containing custom CSS snippets.
oldThemesstring[]List of theme names not fully updated to post v1.0.0 theme guidelines.
queuePromisedQueueQueue for sequential CSS processing operations.
requestLoadSnippetsDebouncer<[], void>Debounced function to reload CSS snippets.
requestLoadThemeDebouncer<[], void>Debounced function to reload the active theme.
requestReadThemesDebouncer<[], void>Debounced function to re-read available themes from disk.
snippetsstring[]List of snippets detected by Obsidian, given by their filenames.
styleElHTMLStyleElementMain style element for the active theme.
theme'' | stringCurrently active theme, given by its name.
themesCustomCSSThemesRecordMapping of theme names to their manifest.
updatesCustomCSSUpdatesRecordRecord of available theme updates.

Methods

MethodReturnsDescription
addChild(component)TAdds a child component, loading it if this component is loaded.
(Inherited from Component)
boundRaw(themeName)voidBound callback for handling raw file change events for a theme.
checkForUpdate(themeName)voidCheck whether a specific theme can be updated.
checkForUpdates()voidCheck all themes for updates.
disableTranslucency()voidDisable translucency of application background.
downloadLegacyTheme(options)Promise<string>Fetch legacy theme CSS using the pre-v1.0.0 theme download pipeline.
enableTranslucency()voidEnable translucency of application background.
getManifest(repoUrl)Promise<ThemeManifest>Fetch a theme's manifest using repository URL.
getSnippetPath(snippetName)stringConvert snippet name to its corresponding filepath (relative to vault root).
getSnippetsFolder()stringReturns the folder path where snippets are stored (relative to vault root).
getThemeFolder()stringReturns the folder path where themes are stored (relative to vault root).
getThemePath(themeName)stringConvert theme name to its corresponding filepath (relative to vault root).
hasUpdates()booleanReturns whether there are themes that can be updated.
installLegacyTheme(options)Promise<void>Install a legacy theme using the pre-v1.0.0 theme download pipeline<br> Will create a corresponding. dummy manifest for the theme.
installTheme(options, version)Promise<void>Install a theme using the regular theme download pipeline.
isDarkMode()booleanCheck whether the current theme is dark mode.
isThemeInstalled(themeName)booleanCheck whether a specific theme is installed by theme name.
load()voidLoad this component and its children.
(Inherited from Component)
loadCss(arg1)Promise<unknown>Load and apply CSS from the given source.
loadData()unknownLoad stored CustomCSS configuration data.
loadSnippets()unknownLoad and apply all enabled CSS snippets.
loadTheme(arg1)unknownLoad and apply a specific theme.
onload()voidLifecycle hook called when the component is loaded.
onRaw(themeName)voidHandle raw file system change events for a theme.
onunload()voidOverride this to unload your component
(Inherited from Component)
readSnippets(reload?)voidRead available CSS snippets from the snippets folder.
readThemes(reload?)voidRead available themes from the themes folder.
register(cb)voidRegisters a callback to be called when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
(Inherited from Component)
registerEvent(eventRef)voidRegisters an event to be detached when unloading.
(Inherited from Component)
registerInterval(id)numberRegisters an interval (from setInterval) to be cancelled when unloading. Use window.setInterval instead of setInterval to avoid TypeScript confusing between NodeJS vs Browser API
(Inherited from Component)
registerScopeEvent(keymapEventHandler)voidRegister a scope keymap event handler to be removed on unload.
(Inherited from Component)
reloadTheme()voidReload the active theme CSS.
removeChild(component)TRemoves a child component, unloading it.
(Inherited from Component)
removeTheme(themeName)Promise<void>Remove a theme by theme name.
setCssEnabledStatus(snippetName, enabled)voidSet the activation status of a snippet by snippet name.
setTheme(themeName)voidSet the active theme by theme name.
setTranslucency(translucency)voidSet the translucency of application background.
unload()voidOverride this to unload your component.
(Inherited from Component)

Links to this page: