mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
25 lines
568 B
TypeScript
25 lines
568 B
TypeScript
import { addStyle } from '@/core/style'
|
|
|
|
export interface LoadStyleOptions<D> {
|
|
style: string | ((dep: D) => any)
|
|
name?: string
|
|
container?: HTMLElement
|
|
}
|
|
|
|
export const loadStyle = <D>({ style, name, container }: LoadStyleOptions<D>) => {
|
|
let styleElement
|
|
const complete = () => styleElement?.remove()
|
|
const next = (dep: D) => {
|
|
complete()
|
|
const styleText = typeof style === 'function' ? style(dep) : style
|
|
if (!styleText) {
|
|
return
|
|
}
|
|
styleElement = addStyle(styleText, name, container)
|
|
}
|
|
return {
|
|
next,
|
|
complete,
|
|
}
|
|
}
|