UNPKG

otion

Version:

Atomic CSS-in-JS with a featherweight runtime

49 lines 1.98 kB
interface InjectorConfig<T> { /** Sets a cryptographic nonce (number used once) on the enclosing `<style>` tag when generating a page on demand. Useful for enforcing a [Content Security Policy (CSP)](https://developer.mozilla.org/docs/Web/HTTP/CSP). */ nonce?: string; /** Target to insert rules into. */ target?: T; } type InjectorInstance = { sheet?: CSSStyleSheet; insert(rule: string, index: number): number; }; type VirtualInjectorInstance = InjectorInstance & { nonce: string | undefined; ruleTexts: string[]; }; /** * Creates an injector which collects style rules during server-side rendering. */ declare function VirtualInjector({ nonce, target: ruleTexts }?: InjectorConfig<string[]>): VirtualInjectorInstance; /** * Transforms an injector's data into `<style>` tag properties. Useful as a base to build custom server-side renderers upon. * * @param injector Server-side style rule injector. * * @returns Properties of a `<style>` tag as an object. */ declare function getStyleProps(injector: ReturnType<typeof VirtualInjector>): { id: string; nonce: string | undefined; textContent: string; }; /** * Transforms an injector's data into a `<style>` tag string. * * @param injector Server-side style rule injector. * * @returns A stringified `<style>` tag containing server-renderable CSS. */ declare function getStyleTag(injector: ReturnType<typeof VirtualInjector>): string; /** * Filters out style rules which are not statically referenced by the given HTML code. * * @param injector Server-side style rule injector. * @param html HTML code of the underlying page. * * @returns A copy of the given injector instance with the unused rules filtered out. */ declare function filterOutUnusedRules(injector: ReturnType<typeof VirtualInjector>, html: string): ReturnType<typeof VirtualInjector>; export { VirtualInjector, getStyleProps, getStyleTag, filterOutUnusedRules }; //# sourceMappingURL=index.d.ts.map