param styles param options export function createStylesFromCache ( styles = require ( "@dash-ui/styles" ) . styles , options = { } ) { const { clearCache = false } = options ; const { dash } = styles ; const styleCache = dash . cache ; const names = new Set ( [ ... dash . sheets . keys ( ) , ... dash . inserted . values ( ) ] ) ; let css = "" ; for ( const name of names ) css += styleCache . get ( name ) ; if ( clearCache ) dash . inserted . clear ( ) ; return { names : [ ... names ] , css } ; } param styles param options export function createStyleTagFromCache ( styles = require ( "@dash-ui/styles" ) . styles , options = { } ) { const { css , names } = createStylesFromCache ( styles , options ) ; const nonceString = styles . dash . sheet . nonce ? ` nonce="${ styles . dash . sheet . nonce }"` : "" ; return `<style data-dash="${ names . join ( " " ) }" data-cache="${ styles . dash . key }"${ nonceString }>${ css }</style>` ; } param outputPath param styles param options export async function writeStylesFromCache ( outputPath = "" , styles = require ( "@dash-ui/styles" ) . styles , options ? ) { const fs = require ( "fs" ) ; const path = require ( "path" ) ; let { name , hash = styles . hash , clearCache = false } = options || { } ; const { css , names } = createStylesFromCache ( styles , { clearCache } ) ; name = `${ name || styles . dash . key + "-" + hash ( css ) + ".css" }` ; const filename = path . join ( outputPath , name ) ; await fs . promises . writeFile ( filename , css ) ; return { filename , name , path : outputPath , css , names } ; } param html param styles export function createStylesFromString ( html , styles = require ( "@dash-ui/styles" ) . styles ) { const { dash } = styles ; const styleCache = dash . cache ; const names = new Set < string > ( dash . sheets . keys ( ) ) ; let css = "" ; for ( let name of names ) css += styleCache . get ( name ) ; const re = new RegExp ( `["\\s'=]${ dash . key }-(\\w+)` , "g" ) ; for ( const [ , name ] of html . matchAll ( re ) ) { if ( ! names . has ( name ) ) { css += styleCache . get ( name ) || "" ; names . add ( name ) ; } } return { names : [ ... names ] , css } ; } param html param styles export function createStyleTagFromString ( html , styles = require ( "@dash-ui/styles" ) . styles ) { const { css , names } = createStylesFromString ( html , styles ) ; const nonceString = styles . dash . sheet . nonce ? ` nonce="${ styles . dash . sheet . nonce }"` : "" ; return `<style data-dash="${ names . join ( " " ) }" data-cache="${ styles . dash . key }"${ nonceString }>${ css }</style>` ; } param html param styles param outputPath param options export async function writeStylesFromString ( html , outputPath = "" , styles = require ( "@dash-ui/styles" ) . styles , options ? ) { const fs = require ( "fs" ) ; const path = require ( "path" ) ; let { name , hash = styles . hash } = options || { } ; const { css , names } = createStylesFromString ( html , styles ) ; name = `${ name || styles . dash . key + "-" + hash ( css ) + ".css" }` ; const filename = path . join ( outputPath , name ) ; await fs . promises . writeFile ( filename , css ) ; return { filename , name , path : outputPath , css , names } ; } export interface ServerStylesResult { /**
     * A CSS string containing all of the styles that were used
     */ css : string ; /**
     * Hash names of all of the styles used in the generated CSS
     */ names : string [ ] ; } export interface CreateServerStylesOptions { default clearCache ? : boolean ; } export interface WriteServerStylesOptions { /**
     * Use this if you want to create your own name for the CSS file.
     * By default, this function will create a filename based on the hash
     * of the generated CSS string.
     */ name ? : string ; /**
     * Use a custom hash function for creating the name of your CSS file.
     * By default this function will use the hash function attached to your
     * `styles()` instance.
     */ hash ? : ( string : string ) => string ; } export interface WriteServerStylesResult { /**
     * The filename of the generated file. This is the `outputPath` joined
     * to the basename of the CSS file that was generated.
     */ filename : string ; /**
     * The basename of the CSS file that was generated.
     */ name : string ; /**
     * The output path of the CSS file excluding the basename.
     */ path : string ; /**
     * The CSS string that was generated and written to the output
     * file.
     */ css : string ; /**
     * The hash names of all of the styles that were inserted into
     * the generated CSS string.
     */ names : string [ ] ; }