import { Declaration, TokenOrValue } from "lightningcss"; import { Plugin } from "vite"; //#region packages/core/types.d.ts type HandlerResult = string | string[] | Declaration | Declaration[] | TokenOrValue | TokenOrValue[]; /** Info about a single directive argument or computed variable. */ interface ArgInfo { /** Raw string from CSS before var() resolution. */ original: string; /** String after var() resolution and validation. */ parsed: string; /** Compiled CSS var() reference for use in value(). */ var: string; } /** Unified context passed to directive value() handlers. */ type DirectiveContext = Record; type Handler = { (args: TokenOrValue[] | null, ctx?: DirectiveContext): HandlerResult; /** When set, generates root-level CSS (e.g. @keyframes, @font-face). */ spawn?: () => string; }; type FunctionHandlers = Record; //#endregion //#region packages/core/transform.d.ts declare function transformCSS(css: string, handlers: FunctionHandlers, filename?: string): string; //#endregion //#region packages/core/utils/id.d.ts declare function generateId(length?: number): string; //#endregion //#region node_modules/.bun/valibot@1.4.1+7524df1edfed9f02/node_modules/valibot/dist/index.d.mts //#endregion //#region src/types/metadata.d.ts /** * Base metadata interface. */ interface BaseMetadata { /** * The object kind. */ readonly kind: "metadata"; /** * The metadata type. */ readonly type: string; /** * The metadata reference. */ readonly reference: (...args: any[]) => BaseMetadata; /** * The input, output and issue type. * * @internal */ readonly "~types"?: { readonly input: TInput$1; readonly output: TInput$1; readonly issue: never; } | undefined; } /** * Generic metadata type. */ //#endregion //#region src/types/dataset.d.ts /** * Unknown dataset interface. */ interface UnknownDataset { /** * Whether is's typed. */ typed?: false; /** * The dataset value. */ value: unknown; /** * The dataset issues. */ issues?: undefined; } /** * Success dataset interface. */ interface SuccessDataset { /** * Whether is's typed. */ typed: true; /** * The dataset value. */ value: TValue$1; /** * The dataset issues. */ issues?: undefined; } /** * Partial dataset interface. */ interface PartialDataset> { /** * Whether is's typed. */ typed: true; /** * The dataset value. */ value: TValue$1; /** * The dataset issues. */ issues: [TIssue, ...TIssue[]]; } /** * Failure dataset interface. */ interface FailureDataset> { /** * Whether is's typed. */ typed: false; /** * The dataset value. */ value: unknown; /** * The dataset issues. */ issues: [TIssue, ...TIssue[]]; } /** * Output dataset type. */ type OutputDataset> = SuccessDataset | PartialDataset | FailureDataset; //#endregion //#region src/types/standard.d.ts /** * The Standard Schema properties interface. */ interface StandardProps { /** * The version number of the standard. */ readonly version: 1; /** * The vendor name of the schema library. */ readonly vendor: "valibot"; /** * Validates unknown input values. */ readonly validate: (value: unknown) => StandardResult | Promise>; /** * Inferred types associated with the schema. */ readonly types?: StandardTypes | undefined; } /** * The result interface of the validate function. */ type StandardResult = StandardSuccessResult | StandardFailureResult; /** * The result interface if validation succeeds. */ interface StandardSuccessResult { /** * The typed output value. */ readonly value: TOutput$1; /** * The non-existent issues. */ readonly issues?: undefined; } /** * The result interface if validation fails. */ interface StandardFailureResult { /** * The issues of failed validation. */ readonly issues: readonly StandardIssue[]; } /** * The issue interface of the failure output. */ interface StandardIssue { /** * The error message of the issue. */ readonly message: string; /** * The path of the issue, if any. */ readonly path?: readonly (PropertyKey | StandardPathItem)[] | undefined; } /** * The path item interface of the issue. */ interface StandardPathItem { /** * The key of the path item. */ readonly key: PropertyKey; } /** * The Standard Schema types interface. */ interface StandardTypes { /** * The input type of the schema. */ readonly input: TInput$1; /** * The output type of the schema. */ readonly output: TOutput$1; } //#endregion //#region src/types/schema.d.ts /** * Base schema interface. */ interface BaseSchema> { /** * The object kind. */ readonly kind: "schema"; /** * The schema type. */ readonly type: string; /** * The schema reference. */ readonly reference: (...args: any[]) => BaseSchema>; /** * The expected property. */ readonly expects: string; /** * Whether it's async. */ readonly async: false; /** * The Standard Schema properties. * * @internal */ readonly "~standard": StandardProps; /** * Parses unknown input values. * * @param dataset The input dataset. * @param config The configuration. * * @returns The output dataset. * * @internal */ readonly "~run": (dataset: UnknownDataset, config: Config>) => OutputDataset; /** * The input, output and issue type. * * @internal */ readonly "~types"?: { readonly input: TInput$1; readonly output: TOutput$1; readonly issue: TIssue; } | undefined; } /** * Base schema async interface. */ interface BaseSchemaAsync> extends Omit, "reference" | "async" | "~run"> { /** * The schema reference. */ readonly reference: (...args: any[]) => BaseSchema> | BaseSchemaAsync>; /** * Whether it's async. */ readonly async: true; /** * Parses unknown input values. * * @param dataset The input dataset. * @param config The configuration. * * @returns The output dataset. * * @internal */ readonly "~run": (dataset: UnknownDataset, config: Config>) => Promise>; } /** * Generic schema type. */ //#endregion //#region src/types/transformation.d.ts /** * Base transformation interface. */ interface BaseTransformation> { /** * The object kind. */ readonly kind: "transformation"; /** * The transformation type. */ readonly type: string; /** * The transformation reference. */ readonly reference: (...args: any[]) => BaseTransformation>; /** * Whether it's async. */ readonly async: false; /** * Transforms known input values. * * @param dataset The input dataset. * @param config The configuration. * * @returns The output dataset. * * @internal */ readonly "~run": (dataset: SuccessDataset, config: Config>) => OutputDataset | TIssue>; /** * The input, output and issue type. * * @internal */ readonly "~types"?: { readonly input: TInput$1; readonly output: TOutput$1; readonly issue: TIssue; } | undefined; } /** * Base transformation async interface. */ interface BaseTransformationAsync> extends Omit, "reference" | "async" | "~run"> { /** * The transformation reference. */ readonly reference: (...args: any[]) => BaseTransformation> | BaseTransformationAsync>; /** * Whether it's async. */ readonly async: true; /** * Transforms known input values. * * @param dataset The input dataset. * @param config The configuration. * * @returns The output dataset. * * @internal */ readonly "~run": (dataset: SuccessDataset, config: Config>) => Promise | TIssue>>; } /** * Generic transformation type. */ //#endregion //#region src/types/validation.d.ts /** * Base validation interface. */ interface BaseValidation> { /** * The object kind. */ readonly kind: "validation"; /** * The validation type. */ readonly type: string; /** * The validation reference. */ readonly reference: (...args: any[]) => BaseValidation>; /** * The expected property. */ readonly expects: string | null; /** * Whether it's async. */ readonly async: false; /** * Validates known input values. * * @param dataset The input dataset. * @param config The configuration. * * @returns The output dataset. * * @internal */ readonly "~run": (dataset: OutputDataset>, config: Config>) => OutputDataset | TIssue>; /** * The input, output and issue type. * * @internal */ readonly "~types"?: { readonly input: TInput$1; readonly output: TOutput$1; readonly issue: TIssue; } | undefined; } /** * Base validation async interface. */ interface BaseValidationAsync> extends Omit, "reference" | "async" | "~run"> { /** * The validation reference. */ readonly reference: (...args: any[]) => BaseValidation> | BaseValidationAsync>; /** * Whether it's async. */ readonly async: true; /** * Validates known input values. * * @param dataset The input dataset. * @param config The configuration. * * @returns The output dataset. * * @internal */ readonly "~run": (dataset: OutputDataset>, config: Config>) => Promise | TIssue>>; } /** * Generic validation type. */ /** * Infer output type. */ type InferOutput> | BaseSchemaAsync> | BaseValidation> | BaseValidationAsync> | BaseTransformation> | BaseTransformationAsync> | BaseMetadata> = NonNullable["output"]; /** * Infer issue type. */ /** * Constructs a type that is maybe readonly. */ type MaybeReadonly = TValue$1 | Readonly; /** * Constructs a type that is deeply readonly. */ //#endregion //#region src/types/other.d.ts /** * Error message type. */ type ErrorMessage> = ((issue: TIssue) => string) | string; /** * Default type. */ //#endregion //#region src/types/issue.d.ts /** * Array path item interface. */ interface ArrayPathItem { /** * The path item type. */ readonly type: "array"; /** * The path item origin. */ readonly origin: "value"; /** * The path item input. */ readonly input: MaybeReadonly; /** * The path item key. */ readonly key: number; /** * The path item value. */ readonly value: unknown; } /** * Map path item interface. */ interface MapPathItem { /** * The path item type. */ readonly type: "map"; /** * The path item origin. */ readonly origin: "key" | "value"; /** * The path item input. */ readonly input: Map; /** * The path item key. */ readonly key: unknown; /** * The path item value. */ readonly value: unknown; } /** * Object path item interface. */ interface ObjectPathItem { /** * The path item type. */ readonly type: "object"; /** * The path item origin. */ readonly origin: "key" | "value"; /** * The path item input. */ readonly input: Record; /** * The path item key. */ readonly key: string; /** * The path item value. */ readonly value: unknown; } /** * Set path item interface. */ interface SetPathItem { /** * The path item type. */ readonly type: "set"; /** * The path item origin. */ readonly origin: "value"; /** * The path item input. */ readonly input: Set; /** * The path item key. */ readonly key: null; /** * The path item key. */ readonly value: unknown; } /** * Unknown path item interface. */ interface UnknownPathItem { /** * The path item type. */ readonly type: "unknown"; /** * The path item origin. */ readonly origin: "key" | "value"; /** * The path item input. */ readonly input: unknown; /** * The path item key. */ readonly key: unknown; /** * The path item value. */ readonly value: unknown; } /** * Issue path item type. */ type IssuePathItem = ArrayPathItem | MapPathItem | ObjectPathItem | SetPathItem | UnknownPathItem; /** * Base issue interface. */ interface BaseIssue extends Config> { /** * The issue kind. */ readonly kind: "schema" | "validation" | "transformation"; /** * The issue type. */ readonly type: string; /** * The raw input data. */ readonly input: TInput$1; /** * The expected property. */ readonly expected: string | null; /** * The received property. */ readonly received: string; /** * The error message. */ readonly message: string; /** * The input requirement. */ readonly requirement?: unknown | undefined; /** * The issue path. */ readonly path?: [IssuePathItem, ...IssuePathItem[]] | undefined; /** * The sub issues. */ readonly issues?: [BaseIssue, ...BaseIssue[]] | undefined; } /** * Generic issue type. */ //#endregion //#region src/types/config.d.ts /** * Config interface. */ interface Config> { /** * The selected language. */ readonly lang?: string | undefined; /** * The error message. */ readonly message?: ErrorMessage | undefined; /** * Whether it should be aborted early. */ readonly abortEarly?: boolean | undefined; /** * Whether a pipe should be aborted early. */ readonly abortPipeEarly?: boolean | undefined; } //#endregion //#region src/types/pipe.d.ts /** * Pipe action type. */ //#endregion //#region packages/core/constant.d.ts /** * Allowed directive types for tscss helpers. * Used to determine how a directive is processed at the AST level. */ declare const HELPER_TYPES: readonly ["var", "declaration", "selector", "media", "function"]; type HelperType = (typeof HELPER_TYPES)[number]; //#endregion //#region packages/core/utils/meta.d.ts interface TypedPropertyConfig { /** Optional name override (defaults to the directive's name). */ name?: string; /** CSS syntax descriptor (e.g. '', '', ''). */ syntax: string; /** Whether the property inherits. */ inherits: boolean; /** Initial value. */ initialValue: string; } //#endregion //#region packages/core/utils/defineHelper.d.ts interface DefineHelperContext { /** The CSS property this directive targets (if any). */ property?: string; } /** Single field in the schema config: a valibot rule plus an optional default. */ interface SchemaField { rule: BaseSchema>; default?: string; } /** Infer the output object shape from a schema config. */ type InferSchemaArgs> = { [K in keyof T]: T[K] extends { rule: infer R; } ? R extends BaseSchema> ? InferOutput : never : never }; interface DefineHelperOptions | undefined = undefined> { /** CSS property to auto-wrap bare at-rules with (e.g. 'background-image'). */ property?: string; /** Directive type. Defaults to 'function'. */ type?: HelperType; /** Custom property name (for type='var'). */ name?: string; /** Whether vars stay inline (default) or extract to :root. */ inline?: boolean; /** When set, generates root-level CSS via this function (not inside a selector). */ spawn?: () => string; /** Typed property configurations for generating @property rules. */ typedProperties?: TypedPropertyConfig[]; /** Alias name(s) for this directive. Allows invoking the same handler via alternate at-rule names. */ alias?: string | string[]; /** When true, var() references are passed raw (not resolved) to the handler. */ raw?: boolean; /** Schema object: each key maps to a valibot rule + optional default. * Positional args are matched to keys in insertion order. * Missing args fall back to their `default` (which goes through `rule` validation). */ schema?: TSchema; /** Optional function that returns a map of computed variable names to raw CSS values. * The framework decides whether to emit custom properties or pass `var()` through directly. * When no `schema` is set, receives raw `string[]` (backward-compat for delegators). */ vars?: (args: TSchema extends Record ? InferSchemaArgs : string[], ctx: DefineHelperContext) => Record; /** The handler function that receives a unified context with original, parsed, and var for each key. */ value: (ctx: DirectiveContext) => string | string[]; } interface Directive extends Handler { /** Raw string-level function for composition. Builds a minimal context and returns the value. */ value: (args: string[]) => string | string[]; /** Optional function that returns a map of computed variable names to raw CSS values. */ vars?: (args: string[]) => Record; /** When set, generates root-level CSS. */ spawn?: () => string; /** Builds a DirectiveContext for AST-level processing. */ buildContext: (originalArgs: string[], parsedArgs: string[], namePrefix: string | null, pushDecl?: (decl: string) => void) => DirectiveContext; } /** * Creates a tscss helper directive that works at the AST level. * * When used as a bare at-rule (`@paper;`), it auto-wraps the result * with the specified CSS `property`. * * When used as a value function (`background-image: @paper('50px');`), * it replaces the function call with the computed value. * * The returned directive exposes `.value` for string-level composition. * * @example * const paper = defineHelper({ * property: 'background-image', * schema: { size: { rule: css.length, default: '50px' } }, * value: (ctx) => `linear-gradient(${ctx.size.var} ...)`, * }); * * // AST-level * transformCSS(css, { paper }); * * // String-level composition * paper.value(['20px']); */ declare function defineHelper | undefined = undefined>(options: DefineHelperOptions): Directive; //#endregion //#region packages/directives/cssVar.d.ts interface PropertyOptions { /** Property name (used as the CSS custom property prefix). */ name?: string; /** When true, generates a random property name instead of using `name`. */ random?: boolean; /** Transform the raw string value before returning. */ transform?: (value: string) => string | string[]; /** When `true` (default), declarations stay inline. When `false`, extracted to `:root`. */ inline?: boolean; /** When provided, generates an @property rule for typed custom properties. */ typed?: TypedPropertyConfig; } /** * Creates a handler for CSS custom properties. * * - If the callback returns a `string`, it becomes `--: ;` * - If the callback returns a `string[]`, each item becomes its own declaration. * - When `typed` is provided, also generates `@property -- { ... }`. * - Automatically registers `var` as an alias so `@var('name', 'value')` also works. * * @example * cssVar('primary') * // @primary('blue') → --primary: blue * * @example * cssVar({ name: 'size', transform: (v) => pxToRem(v) }) * // @size('16px') → --size: calc(16px / 16px * 1rem) * * @example * cssVar({ random: true }) * // @token('blue') → --aB3dE5: blue * * @example * cssVar({ name: 'primary', typed: { syntax: '', inherits: false, initialValue: 'blue' } }) * // generates @property --primary { syntax: ''; inherits: false; initial-value: blue; } */ declare function cssVar(options: PropertyOptions | string | ((args: string[]) => string | string[]), optsOrFn?: { inline?: boolean; random?: boolean; } | ((args: string[]) => string | string[])): Directive; //#endregion //#region packages/directives/declaration.d.ts /** * Creates a handler that outputs a specific CSS property declaration. * * When used as an at-rule, it automatically adds `property: ` * to the current rule. When used as a value function, it returns the raw value. * * @example * declaration('background-image', (ctx) => paper(ctx[0].parsed)) * // .test { @paper('50px'); } * // → .test { background-image: ; } */ declare function declaration(property: string, value: (ctx: DirectiveContext) => string): Directive; //#endregion //#region packages/directives/selector.d.ts /** * Creates a handler that generates a CSS selector variant. * * When used as an at-rule with a block, it creates a new rule with the * generated selector and copies the block's declarations. * * Use `&` as a placeholder for the parent selector. * * @example * selector(() => '&:hover') * // .btn { @hover() { color: red; } } * // → .btn:hover { color: red; } */ declare function selector(value: (args: string[]) => string): Directive; //#endregion //#region packages/directives/media.d.ts /** * Creates a CSS @media wrapper directive. * * When used inside a selector, it wraps the parent rule in a media query. * * @example * const mobile = media('(max-width: 768px)'); * * // .btn { @mobile { padding: 1rem; } } * // → @media (max-width: 768px) { .btn { padding: 1rem; } } */ declare function media(query: string): Directive; //#endregion //#region packages/directives/keyframes.d.ts /** * Creates a CSS @keyframes animation directive. * * @example * const fadeIn = keyframes('fadeIn', { * '0%': { opacity: '0', transform: 'scale(0)' }, * '100%': { opacity: '1', transform: 'scale(1)' } * }); * * // Usage: * // .test { animation: @fadeIn 0.3s ease; } * // → generates @keyframes fadeIn { ... } at the top level */ declare function keyframes(name: string, frames: Record>): Directive; //#endregion //#region packages/directives/fontFace.d.ts interface FontFaceConfig { src: string; family: string; weight?: string; } /** * Creates a CSS @font-face directive + utility class. * * @example * const myFont = fontFace({ * src: "url('/fonts/myfont.woff2')", * family: 'MyFont', * weight: '400', * }); * * // .test { @myFont; } * // → generates @font-face { ... } + .abc123 { font-family: MyFont; } * // → .test { font-family: MyFont; } */ declare function fontFace(config: FontFaceConfig): Directive; //#endregion //#region packages/vite/index.d.ts interface TscssPluginOptions { /** Directory to scan for custom directive files (.ts, .js). */ directives?: string; /** Filter which CSS files get transformed. */ include?: RegExp | string | (RegExp | string)[]; /** Filter which CSS files should NOT be transformed. */ exclude?: RegExp | string | (RegExp | string)[]; } /** * Loads directive handler functions from a directory. * Scans for `.ts` and `.js` files and collects exported functions. */ declare function loadFromDir(dir: string): Promise; /** * Vite plugin for tscss — transforms CSS files using tscss directives. * * @example * import { tscss } from '@subwaytime/tscss/vite'; * export default { plugins: [tscss()] }; */ declare function tscss(options?: TscssPluginOptions): Plugin; //#endregion export { type FunctionHandlers, type Handler, type HandlerResult, TscssPluginOptions, cssVar, declaration, defineHelper, fontFace, generateId, keyframes, loadFromDir, media, selector, transformCSS, tscss };