import { n as __name } from "./chunk-O_arW02_.js"; import { E as Export, M as Path, N as ResolvedFile, P as Source, _ as inject, b as FileManager, c as FabricOptions, d as renderIndent, f as renderIntrinsic, g as createContext, h as Context, j as Import, k as File$1, n as FabricComponent, p as RenderContext, r as FabricConfig, s as FabricNode, t as Fabric$1, v as provide, w as BaseName, x as FileProcessor, y as unprovide } from "./Fabric-DcPYjTt7.js"; import { n as useNodeTree, r as TreeNode, t as ComponentNode } from "./useNodeTree-c9qOt3mv.js"; import { n as RootContext, t as JSDoc } from "./types-Ci0PIR4L.js"; //#region src/createComponent.d.ts type MakeChildrenOptional = T extends { children?: any; } ? Omit & Partial> : T; type ComponentBuilder = { (...args: unknown extends T ? [] : {} extends Omit ? [props?: MakeChildrenOptional] : [props: MakeChildrenOptional]): FabricComponent; displayName?: string | undefined; }; declare function createComponent(type: string, Component: (props: TProps) => FabricNode): ComponentBuilder; //#endregion //#region src/components/Br.d.ts /** * Generates a line break in the output. * * Use this component to add newlines in generated code. * * @example * ```tsx * <> * const x = 1 *
* const y = 2 * * ``` */ declare const Br: ComponentBuilder; //#endregion //#region src/components/Const.d.ts type ConstProps = { /** * Name of the constant. */ name: string; /** * Export this constant. * - `true` generates `export const` * - `false` generates internal const * @default false */ export?: boolean; /** * TypeScript type annotation. * * @example 'string' or 'User[]' */ type?: string; /** * JSDoc comments for the constant. */ JSDoc?: JSDoc; /** * Use const assertion. * - `true` adds `as const` for deep readonly * - `false` uses inferred or explicit type * @default false */ asConst?: boolean; /** * Constant value. */ children?: FabricNode; }; /** * Generates a TypeScript constant declaration. * * @example * ```tsx * * 'https://api.example.com' * * ``` */ declare const Const: ComponentBuilder; //#endregion //#region src/components/Dedent.d.ts /** * Decreases indentation level in the output. * * Use this component to reduce indentation after an indented code block. * Typically paired with Indent to control indentation levels. * * @example * ```tsx * <> * function example() {'{'}
* * return true
* * {'}'} * * ``` */ declare const Dedent: ComponentBuilder; //#endregion //#region src/components/Fabric.d.ts type FabricProps = { /** * Metadata attached to the App context. * * Use this to pass custom data to child components via useApp. */ meta?: TMeta; /** * Child components. */ children?: FabricNode; }; /** * Container component providing App context with metadata and lifecycle. * * Use this component to wrap your application and provide shared metadata * that can be accessed by child components using the useApp composable. * * @example * ```tsx * * * export type User = {} * * * ``` */ declare const Fabric: ComponentBuilder>; //#endregion //#region src/components/File.d.ts type FileProps = { /** * File name with extension. * * @example 'user.ts' */ baseName: BaseName; /** * Full path to the file including directory and file name. * * The path must include the baseName at the end. * * @example './generated/types/user.ts' */ path: Path; /** * Optional metadata attached to the file. * * Use this to store custom information about the file. */ meta?: TMeta; /** * Optional banner text added at the top of the file. */ banner?: string; /** * Optional footer text added at the bottom of the file. */ footer?: string; /** * Child components (File.Source, File.Import, File.Export). */ children?: FabricNode; }; /** * Component for generating files with sources, imports, and exports. * * Creates files in the FileManager that can be written to disk. * * @example * ```tsx * * * export type User = {{ '{' }} id: number {{ '}' }} * * * ``` */ declare const File: ComponentBuilder> & { Source: typeof FileSource; Import: typeof FileImport; Export: typeof FileExport; }; type FileSourceProps = Omit & { /** * Source code content. */ children?: FabricNode; }; /** * Adds source code to a file. * * Use this component inside a File component to add code blocks. * * @example * ```tsx * * export type User = {{ '{' }} id: number {{ '}' }} * * ``` */ declare const FileSource: ComponentBuilder; /** * Adds export statements to a file. * * Use this component to create re-exports from other files. * * @example * ```tsx * * ``` */ declare const FileExport: ComponentBuilder; /** * Adds import statements to a file. * * Use this component to import types or values from other files. * * @example * ```tsx * * ``` */ declare const FileImport: ComponentBuilder; //#endregion //#region src/components/Function.d.ts type FunctionProps = { /** * Name of the function. */ name: string; /** * Export with default keyword. * - `true` generates `export default function` * - `false` generates named export or no export * @default false */ default?: boolean; /** * Function parameters. * * @example 'id: number, name: string' */ params?: string; /** * Export this function. * - `true` generates `export function` * - `false` generates internal function * @default false */ export?: boolean; /** * Make the function async. * - `true` adds async keyword and wraps return type in Promise * - `false` generates synchronous function * @default false */ async?: boolean; /** * TypeScript generics. * * @example 'T' or ['T', 'U'] */ generics?: string | string[]; /** * Return type of the function. * * When async is true, this is automatically wrapped in Promise. */ returnType?: string; /** * JSDoc comments for the function. */ JSDoc?: JSDoc; /** * Function body. */ children?: FabricNode; }; /** * Generates a TypeScript function declaration. * * @example * ```tsx * * return fetch(`/users/${id}`).then(r => r.json()) * * ``` */ declare const Function: ComponentBuilder & { Arrow: typeof ArrowFunction; }; type ArrowFunctionProps = FunctionProps & { /** * Create Arrow function in one line */ singleLine?: boolean; }; /** * ArrowFunction * * Builds an arrow function declaration string for the fsx renderer. Supports * the same options as `Function`. Use `singleLine` to produce a one-line * arrow expression. */ declare const ArrowFunction: ComponentBuilder; //#endregion //#region src/components/Indent.d.ts /** * Increases indentation level in the output. * * Use this component to add indentation for nested code blocks. * Typically paired with Dedent to control indentation levels. * * @example * ```tsx * <> * function example() {'{'}
* * return true
* * {'}'} * * ``` */ declare const Indent: ComponentBuilder; //#endregion //#region src/components/Root.d.ts type RootProps = { /** * Callback to exit the Fabric application. * * Call this to stop rendering and clean up resources. */ onExit: (error?: Error) => void; /** * Error handler for runtime exceptions. * * Receives errors thrown during component rendering. */ onError: (error: Error) => void; /** * Tree structure representing the component hierarchy. * * Used internally for tracking component relationships. */ treeNode: TreeNode; /** * FileManager instance for file operations. * * Manages all files created during rendering. */ fileManager: FileManager; /** * Child components. */ children?: FabricNode; }; /** * Root component providing core Fabric runtime context. * * This component is typically used internally by the Fabric renderer. * It provides the root context including FileManager, error handling, * and lifecycle management. * * @example * ```tsx * process.exit(error ? 1 : 0)} * onError={(error) => console.error(error)} * treeNode={treeNode} * fileManager={fileManager} * > * * Your components here * * * ``` */ declare const Root: ComponentBuilder; //#endregion //#region src/components/Type.d.ts type TypeProps = { /** * Name of the type (must start with a capital letter). */ name: string; /** * Export this type. * - `true` generates `export type` * - `false` generates internal type * @default false */ export?: boolean; /** * JSDoc comments for the type. */ JSDoc?: JSDoc; /** * Type definition. */ children?: FabricNode; }; /** * Generates a TypeScript type declaration. * * @example * ```tsx * * {'{'} id: number; name: string {'}'} * * ``` */ declare const Type: ComponentBuilder; //#endregion //#region src/composables/useContext.d.ts /** * React-style alias for inject * * @example * ```ts * const theme = useContext(ThemeContext) // type is inferred from ThemeContext * ``` */ declare function useContext(key: Context): T; declare function useContext(key: Context, defaultValue: TValue): NonNullable | TValue; //#endregion //#region src/contexts/FabricContext.d.ts type FabricContextProps = { /** * Exit (unmount) */ exit: (error?: Error) => void; meta: TMeta; }; /** * Provides app-level metadata and lifecycle hooks (like `exit`) to * components and composables within a Fabric runtime. */ declare const FabricContext: Context>; //#endregion //#region src/composables/useFabric.d.ts /** * Accesses the App context with metadata and exit function. * * Use this composable to access metadata defined in the App component * or to exit the rendering process early. * * @throws Error when no AppContext is available * * @example * ```ts * const { meta, exit } = useFabric<{ version: string }>() * console.log(meta.version) * ``` */ declare function useFabric(): FabricContextProps; //#endregion //#region src/composables/useFile.d.ts /** * Accesses the current File context. * * Use this composable to access or modify the current file's properties, * sources, imports, or exports. * * @returns The current file object or null if not within a File component * * @example * ```ts * const file = useFile() * if (file) { * console.log(file.path) * file.sources.push({ value: 'export const x = 1', isExportable: true }) * } * ``` */ declare function useFile(): ResolvedFile | null; //#endregion //#region src/composables/useFileManager.d.ts /** * Accesses the FileManager from the Root context. * * Use this composable to interact with the FileManager directly, * such as adding, retrieving, or managing files. * * @returns The current FileManager instance * * @example * ```ts * const fileManager = useFileManager() * fileManager.add({ * baseName: 'user.ts', * path: './generated/user.ts', * sources: [] * }) * ``` */ declare function useFileManager(): FileManager; //#endregion //#region src/composables/useLifecycle.d.ts /** * Accesses lifecycle helpers for controlling generation flow. * * Use this composable to exit the rendering process early or perform * cleanup operations. * * @returns Object with lifecycle methods (exit) * * @example * ```ts * const { exit } = useLifecycle() * * // Stop generation on error * if (invalidData) { * exit(new Error('Invalid data')) * } * ``` */ declare function useLifecycle(): { exit: (error?: Error) => void; }; //#endregion //#region src/contexts/FileContext.d.ts /** * Provides app-level metadata and lifecycle hooks (like `exit`) to * components and composables within a Fabric runtime. */ declare const FileContext: Context | null>; //#endregion //#region src/contexts/NodeTreeContext.d.ts /** * Context for having the current NodeTree */ declare const NodeTreeContext: Context | null>; //#endregion //#region src/createFabric.d.ts /** * Creates a new Fabric instance for file generation. * * The Fabric instance provides methods for registering plugins, * adding files, and triggering file generation. * * @param config - Optional configuration object * @returns A new Fabric instance * * @example * ```ts * import { createFabric } from '@kubb/fabric-core' * import { fsPlugin } from '@kubb/fabric-core/plugins' * import { typescriptParser } from '@kubb/fabric-core/parsers' * * const fabric = createFabric() * fabric.use(fsPlugin) * fabric.use(typescriptParser) * * await fabric.addFile({ * baseName: 'user.ts', * path: './generated/user.ts', * sources: [{ value: 'export type User = {}', isExportable: true }], * imports: [], * exports: [], * }) * * await fabric.write({ extension: { '.ts': '.ts' } }) * ``` */ declare function createFabric(config?: FabricConfig): Fabric$1; //#endregion //#region src/createFile.d.ts /** * Helper to create a file with name and id set */ declare function createFile(file: File$1): ResolvedFile; //#endregion //#region src/utils/createJSDoc.d.ts /** * Create JSDoc comment block from comments array */ declare function createJSDoc({ comments }: { comments: string[]; }): string; //#endregion //#region src/utils/getRelativePath.d.ts declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string; //#endregion //#region src/utils/onProcessExit.d.ts /** * Register a callback to run when the process exits (via exit event or common signals). * Returns an unsubscribe function. * * Dynamically adjusts `process.maxListeners` to avoid MaxListenersExceededWarning * when multiple instances are created (e.g. in tests). */ declare function onProcessExit(callback: (code: number | null) => void): () => void; //#endregion export { Br, Const, Dedent, Fabric, FabricContext, File, FileContext, FileManager, FileProcessor, Function, Indent, NodeTreeContext, RenderContext, Root, RootContext, TreeNode, Type, createComponent, createContext, createFabric, createFile, createJSDoc, getRelativePath, inject, onProcessExit, provide, renderIndent, renderIntrinsic, unprovide, useContext, useFabric, useFile, useFileManager, useLifecycle, useNodeTree }; //# sourceMappingURL=index.d.ts.map