Skip to content

library-styles

Injects the library’s stylesheet once per renderer, letting the newest loaded copy win.

Every plugin bundles its own copy, so several copies can share one renderer, and only one of them should own the <style> element. Copies of the retired obsidian-dev-utils package decide that by comparing their own version against __obsidianDevUtils.lastLibraryVersion. obsidian-lib restarted its version line, so it cannot take part in that comparison: a 1.x copy would lose to every 107.x copy for ever. It therefore keeps its own record under a separate key, and treats any obsidian-dev-utils copy as older than itself.

Interface Description
InjectLibraryStylesParams Params for injectLibraryStyles.
Function Description
injectLibraryStyles Injects the library styles, unless an obsidian-lib copy of the same or a newer version already did. A style element left by an obsidian-dev-utils copy is always replaced, whatever its version.
Variable Description
LAST_OBSIDIAN_LIB_VERSION_KEY The shared-state key under which obsidian-lib copies record the version that injected the styles.
LEGACY_LAST_LIBRARY_VERSION_KEY The shared-state key under which obsidian-dev-utils copies record the version that injected the styles.
LEGACY_LAST_LIBRARY_VERSION_SENTINEL The value obsidian-lib writes under LEGACY_LAST_LIBRARY_VERSION_KEY. It is above every obsidian-dev-utils version, so an obsidian-dev-utils copy loading later compares lower and leaves the styles alone.
LIBRARY_STYLES_ELEMENT_ID The id of the <style> element holding the library styles. It is the id obsidian-dev-utils copies use too, so whichever copy injects last replaces the element instead of adding a second one.