diff --git a/async.d.ts b/async.d.ts new file mode 100644 index 0000000..0a1bafd --- /dev/null +++ b/async.d.ts @@ -0,0 +1,5 @@ +import { async as _async } from './index.js' + +declare const async: typeof _async + +export = async diff --git a/index.d.mts b/index.d.mts new file mode 100644 index 0000000..2806382 --- /dev/null +++ b/index.d.mts @@ -0,0 +1,9 @@ +export { + CssInJs, + ObjectifyOptions, + sync, + async, + objectify, + parse, + default +} from './index.js' diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..3917874 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,59 @@ +// From DefinitelyTyped by Adam Thompson-Sharpe (https://github.com/MysteryBlokHed) with some modifications. +import { AcceptedPlugin, Root } from 'postcss' + +declare namespace postcssJs { + /** CSS-in-JS object */ + type CssInJs = Record + + /** + * Create a PostCSS processor with a simple API + * @param plugins Synchronous plugins to use with PostCSS + * @returns A processor function that accepts (idk) and returns a CSS-in-JS object + */ + function sync( + plugins?: readonly AcceptedPlugin[] + ): (input: CssInJs) => CssInJs + function sync(...plugins: AcceptedPlugin[]): (input: CssInJs) => CssInJs + + /** + * Create a PostCSS processor with a simple API, allowing asynchronous plugins + * @param plugins Plugins to use with PostCSS + * @returns A processor function that accepts (idk) and returns a CSS-in-JS object + */ + function async( + plugins?: readonly AcceptedPlugin[] + ): (input: CssInJs) => Promise + function async( + ...plugins: AcceptedPlugin[] + ): (input: CssInJs) => Promise + + /** + * Parse a CSS-in-JS object into a PostCSS `Root` + * @param obj The CSS-in-JS to parse + * @returns A PostCSS `Root` + */ + function parse(obj: CssInJs): Root + + interface ObjectifyOptions { + stringifyImportant?: boolean | undefined + } + + /** + * Convert a PostCSS `Root` into a CSS-in-JS object + * @param root The root to convert + * @returns CSS-in-JS object + */ + function objectify(root: Root, options?: ObjectifyOptions): CssInJs + + export { + CssInJs, + ObjectifyOptions, + sync, + async, + objectify, + parse, + postcssJs as default + } +} + +export = postcssJs diff --git a/objectifier.d.ts b/objectifier.d.ts new file mode 100644 index 0000000..636626a --- /dev/null +++ b/objectifier.d.ts @@ -0,0 +1,7 @@ +import { ObjectifyOptions, objectifiy } from './index.js' + +declare namespace objectifier { + export { ObjectifyOptions, objectifiy as default } +} + +export = objectifier diff --git a/parser.d.ts b/parser.d.ts new file mode 100644 index 0000000..56d34e8 --- /dev/null +++ b/parser.d.ts @@ -0,0 +1,5 @@ +import { parse } from './index.js' + +declare const parser: typeof parse + +export = parser diff --git a/process-result.d.ts b/process-result.d.ts new file mode 100644 index 0000000..5f1167a --- /dev/null +++ b/process-result.d.ts @@ -0,0 +1,7 @@ +import { CssInJs } from './index.js' +import { LazyResult } from 'postcss' +import NoWorkResult from 'postcss/lib/no-work-result' + +declare function processResult(result: LazyResult | NoWorkResult): CssInJs + +export = processResult diff --git a/sync.d.ts b/sync.d.ts new file mode 100644 index 0000000..bbed26c --- /dev/null +++ b/sync.d.ts @@ -0,0 +1,5 @@ +import { sync as _sync } from './index.js' + +declare const sync: typeof _sync + +export = sync