@poupe/theme-builder
Version:
Design token management and theme generation system for Poupe UI framework
119 lines (114 loc) • 6.14 kB
TypeScript
import { R as HexColor, C as Color } from './shared/theme-builder.BBfchCYS.js';
export { t as colord, A as hct, O as hexString } from './shared/theme-builder.BBfchCYS.js';
import { S as StandardDynamicSchemeKey } from './shared/theme-builder.C631FE2Q.js';
export { Hct } from '@poupe/material-color-utilities';
import { CSSRulesFormatOptions, CSSRules, CSSRuleObject } from '@poupe/css';
export { Colord } from 'colord';
/** @returns if the value is a string suitable for {@link hct} */
declare const isHexValue: (s: string | HexColor) => boolean;
/** @returns if the value is a valid {@link StandardDynamicSchemeKey} */
declare const isThemeSchemeKey: (s?: string) => boolean;
/** @returns the given string as a valid StandardDynamicSchemeKey, or undefined if it is not a valid key */
declare const asThemeSchemeKey: (key?: string) => StandardDynamicSchemeKey | undefined;
/** Extracts the first parameter from a potentially undefined or array-like parameter, returning a single string or undefined. */
declare const getParam: (param?: string | string[]) => (string | undefined);
/**
* @returns a random hex color value, throwing an error if generation fails
* It uses `colord` to generate the random color.
* */
declare const getRandomColor: () => HexColor;
/** Converts a color to a URL-friendly hex string, generating a random color if none is provided.
* It uses `colord` to generate the random color.
* @param c - Optional color to convert
* @returns A hex color string without the leading '#'
*/
declare const colorToURL: (c?: Color) => string;
/**
* Options for formatting CSS rules with newLine support.
*/
interface CSSRulesStringifyOptions extends CSSRulesFormatOptions {
/**
* Character(s) to use for line breaks.
* @defaultValue `'\n'`
*/
newLine?: string;
}
/**
* Converts CSS rules array to a string with newLine between
* each line. Uses the efficient generator implementation internally.
* No trailing newLine for composition purposes.
*
* @param rules - The array of CSS rules to format
* @param options - Configuration options for formatting
* @returns A string with newLine-separated lines
*/
declare function stringifyCSSRulesArray(rules?: (string | CSSRules | CSSRuleObject)[], options?: CSSRulesStringifyOptions): string;
/**
* Converts CSS rules array to an async generator for streaming responses.
* Uses the efficient generator implementation that yields lines as they're generated.
*
* @param rules - The array of CSS rules to format
* @param options - Configuration options for formatting
* @returns Formatted CSS lines with newLine endings
*/
declare function stringifyCSSRulesArrayStream(rules?: (string | CSSRules | CSSRuleObject)[], options?: CSSRulesStringifyOptions): AsyncGenerator<string, void, unknown>;
/**
* Creates a ReadableStream with formatted CSS rules array.
* Uses the generator directly for true streaming without building arrays.
* Perfect for Cloudflare Workers and other edge environments.
*
* @param rules - The array of CSS rules to format
* @param options - Configuration options for formatting
* @returns A ReadableStream ready to be used in Response or other contexts
*/
declare function stringifyCSSRulesArrayAsStream(rules?: (string | CSSRules | CSSRuleObject)[], options?: CSSRulesStringifyOptions): ReadableStream<Uint8Array>;
/**
* Creates a Response object with formatted CSS rules array.
* Sets appropriate Content-Type header and allows for additional headers.
*
* @param rules - The array of CSS rules to format
* @param options - Configuration options for formatting and response
* @returns A Response object ready to be sent
*/
declare function stringifyCSSRulesArrayAsResponse(rules?: (string | CSSRules | CSSRuleObject)[], options?: CSSRulesStringifyOptions & {
/**
* Additional headers to include in the response.
*/
headers?: HeadersInit;
}): Response;
/**
* Creates a streaming Response object with formatted CSS rules array.
* Uses the ReadableStream function for true streaming without building arrays.
* Sets appropriate Content-Type header and allows for additional headers.
*
* @param rules - The array of CSS rules to format
* @param options - Configuration options for formatting and response
* @returns A streaming Response object ready to be sent
*/
declare function stringifyCSSRulesArrayAsStreamingResponse(rules?: (string | CSSRules | CSSRuleObject)[], options?: CSSRulesStringifyOptions & {
/**
* Additional headers to include in the response.
*/
headers?: HeadersInit;
}): Response;
/** Attempts to convert a parameter to a valid hex color.
* @param param - An optional string or string array representing a color
* @param filter - Optional function to pre-process the parameter before validation
* @returns An object containing the original parameter and a validated hex color, if applicable
* @remarks Supports hex values directly, as well as other color formats supported by colord
* (including RGB, HSL, HSV, LAB, LCH, CMYK and color names if the colord plugin has been enabled)
*/
declare const getColorParam: (param?: string | string[], filter?: (s?: string) => (string | undefined)) => {
param?: string;
color?: HexColor;
};
/** Attempts to convert a parameter to a valid StandardDynamicSchemeKey.
* @param param - An optional string or string array representing a theme scheme key
* @param filter - Optional function to pre-process the parameter before validation
* @returns An object containing the original parameter and a validated theme scheme key, if applicable
*/
declare const getThemeSchemeParam: (param?: string | string[], filter?: (s?: string) => (string | undefined)) => {
param?: string;
scheme?: StandardDynamicSchemeKey;
};
export { type CSSRulesStringifyOptions, Color, HexColor, StandardDynamicSchemeKey, asThemeSchemeKey, colorToURL, getColorParam, getParam, getRandomColor, getThemeSchemeParam, isHexValue, isThemeSchemeKey, stringifyCSSRulesArray, stringifyCSSRulesArrayAsResponse, stringifyCSSRulesArrayAsStream, stringifyCSSRulesArrayAsStreamingResponse, stringifyCSSRulesArrayStream };