Skip to content

API Reference

@theme-kit/astro

Astro islands integration with a zero-flash blocking script.

Functions

buildThemeCssMap(themes): Record<string, Record<string, string>>

ParameterTypeDescription
themesreadonly ThemeDefinition<string>[]

Returns Record<string, Record<string, string>>


computeFingerprint(themes, defaultTheme?): string

ParameterTypeDescription
themesreadonly ThemeDefinition<string>[]
defaultThemestring (optional)

Returns string


createAstroThemePersistence(themes?, defaultTheme?): ThemeSelectionPersistenceAdapter | null

ParameterTypeDescription
themesreadonly ThemeDefinition<string>[] (optional)
defaultThemestring (optional)

Returns ThemeSelectionPersistenceAdapter | null


createBlockingScript(fingerprint, themeCssMap): string

ParameterTypeDescription
fingerprintstring
themeCssMapRecord<string, Record<string, string>>

Returns string


darkModeCSSTemplate(variables): string

ParameterTypeDescription
variablesRecord<string, string>

Returns string


getGlobalRuntime<T extends ThemeDefinition<string>>(): ThemeRuntime<T> | null

Returns ThemeRuntime<T> | null


setGlobalRuntime(runtime): void

ParameterTypeDescription
runtimeThemeRuntime<ThemeDefinition<string>>

Returns void


ThemeInspector(__namedParameters?): Element

Returns Element


ThemeProviderClient<T extends ThemeDefinition<string>>(__namedParameters): null

Returns null


ThemeScope(__namedParameters): Element

Returns Element


ThemeScrollbar(props): null

ThemeScrollbar — overlay only.

Creates the custom scrollbar overlay.

Lifecycle: mount → create overlay → measure → attach listeners paint → add tk-scrollbar-ready destroy → remove overlay

Props are organized into three optional groups — behavior, appearance and icons — but every option is also accepted as a flat, top-level prop (flat props win over the grouped ones).

<ThemeScrollbar behavior={{ autoHide: true, smooth: true }} appearance={{ thickness: 8, radius: 999 }} icons={{ up: <ArrowUpIcon />, down: <ArrowDownIcon /> }} />

ParameterTypeDescription
propsThemeScrollbarProps

Returns null


useSetThemeFamily(): __type(nextFamily: string): void

Returns __type(nextFamily: string): void


useSetThemeMode(): __type(nextMode: ThemeMode): void

Returns __type(nextMode: ThemeMode): void


useTheme<T extends ThemeDefinition<string>>(): { family: string; mode: ThemeMode; setFamily: __type(nextFamily: string): void; setMode: __type(nextMode: ThemeMode): void; theme: T; toggleTheme: __type(): void }

Returns { family: string; mode: ThemeMode; setFamily: __type(nextFamily: string): void; setMode: __type(nextMode: ThemeMode): void; theme: T; toggleTheme: __type(): void }


useThemeBatch(): __type(callback: __type(): void): void

Returns __type(callback: __type(): void): void


useThemeFamily(): string

Returns string


useThemeHistory(): { canRedo: boolean; canUndo: boolean; clear: __type(): void; history: HistoryEntry<ThemeDefinition<string>>[]; jump: __type(index: number): void; redo: __type(): void; undo: __type(): void }

Returns { canRedo: boolean; canUndo: boolean; clear: __type(): void; history: HistoryEntry<ThemeDefinition<string>>[]; jump: __type(index: number): void; redo: __type(): void; undo: __type(): void }


useThemeLifecycle(): { on: __type(event: keyof ThemeLifecycleEventMap<ThemeDefinition<string>>, listener: __type(data: unknown): void): __type(): void }

Returns { on: __type(event: keyof ThemeLifecycleEventMap<ThemeDefinition<string>>, listener: __type(data: unknown): void): __type(): void }


useThemeMode(): ThemeMode

Returns ThemeMode


useThemePacks(): __type(pack: ThemePack<any>): void

Returns __type(pack: ThemePack<any>): void


useThemeRestore(): __type(snapshot: ThemeRuntimeSnapshot): void

Returns __type(snapshot: ThemeRuntimeSnapshot): void


useThemeRuntime<T extends ThemeDefinition<string>>(): ThemeRuntime<T>

Returns ThemeRuntime<T>


useThemeSchedule(): ThemeSchedule | null

Reactive sunrise/sunset schedule controller. Returns null when the runtime was created without the scheduled option.

tsx
const schedule = useThemeSchedule();
schedule?.enable();
schedule?.disable();
schedule?.set({ timeZone: "Asia/Kathmandu" });

Returns ThemeSchedule | null


useThemeSnapshot(): __type(): ThemeRuntimeSnapshot

Returns __type(): ThemeRuntimeSnapshot


useThemeTokens<T extends ThemeDefinition<string>>(): ThemeTokens | undefined

Returns ThemeTokens | undefined


useThemeValue<T extends ThemeDefinition<string>>(): T

Returns T


useToggleTheme(): __type(): void

Returns __type(): void


Interfaces

ThemeInspectorProps

MemberTypeDescription
bottom (optional)numberVertical distance from the bottom of the viewport, in px. Default 104.
right (optional)numberHorizontal distance from the right edge of the viewport, in px. Default 32.
size (optional)numberToggle button size (width and height), in px. Default 40.
zIndex (optional)numberZ-index for the floating toggle and panel. Default 9999.

ThemeProviderClientProps<T extends ThemeDefinition>

MemberTypeDescription
defaultTheme (optional)string
initialInitialThemeResolution<T>
themes (optional)readonly T[]

ThemeScopeProps

MemberTypeDescription
childrenReactNode
className (optional)string
themestring
transition (optional)ThemeTransitionOptionsTransition applied when the scope's theme changes. Defaults to the owning
runtime's transition (the provider's), or pass your own to override.

ThemeScrollbarProps

MemberTypeDescription
activeThumbColor (optional)string
animationDuration (optional)number
appearance (optional)ThemeScrollbarAppearanceGrouped appearance options. Flat props override these.
arrowDownIcon (optional)ReactNodeJSX / element for the "scroll down" button. Falls back to arrowIcon.
arrowIcon (optional)ReactNodeJSX / element rendered inside every arrow button (overrides the built-in
CSS triangle). Accepts any ReactNode.
arrowLeftIcon (optional)ReactNodeJSX / element for the "scroll left" button. Falls back to arrowIcon.
arrowRightIcon (optional)ReactNodeJSX / element for the "scroll right" button. Falls back to arrowIcon.
arrows (optional)boolean
arrowUpIcon (optional)ReactNodeJSX / element for the "scroll up" button. Falls back to arrowIcon.
autoHide (optional)booleanFlat aliases mirroring OverlayScrollbarOptions (for convenience /
backwards compatibility). Each is overridden by the matching flat prop.
autoHideDelay (optional)numberIdle (ms) before a revealed strip fades out after its last activity.
Each host has its own timer, so only the strip you're scrolling/hovering
is revealed, then it fades after idle; other scrollbars stay hidden.
Default 900. Only takes effect when autoHide is true.
axes (optional)ScrollbarAxis[]
behavior (optional)ThemeScrollbarBehaviorGrouped behavior options. Flat props (e.g. autoHide) override these.
children (optional)ReactNode
clickToJump (optional)boolean
dir (optional)`"ltr""rtl"
draggable (optional)boolean
duration (optional)number
exclude (optional)`string[]null`
hoverExpand (optional)boolean
hoverThickness (optional)number
icons (optional)ThemeScrollbarIconsGrouped arrow button icons. Flat arrow*Icon props override these.
include (optional)`string[]null`
minThumbSize (optional)number
offset (optional)number
overscroll (optional)boolean
radius (optional)number
smooth (optional)boolean
thickness (optional)number
thumbColor (optional)string
thumbHoverColor (optional)string
thumbOpacity (optional)number
touch (optional)boolean
trackColor (optional)string
trackOpacity (optional)number
zIndex (optional)number

@theme-kit/astro — API Reference — Theme Kit