diff --git a/types/config.d.ts b/types/config.d.ts index b2b9d2d1..15a4abee 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -1,3 +1,4 @@ +import type Events from './events'; import type BuildConfig from './build'; import type MinifyConfig from './minify'; import type PostHTMLConfig from './posthtml'; @@ -11,20 +12,11 @@ import type WidowWordsConfig from './widowWords'; import type { CoreBeautifyOptions } from 'js-beautify'; import type { BaseURLConfig } from 'posthtml-base-url'; import type URLParametersConfig from './urlParameters'; -import type { - beforeCreateType, - beforeRenderType, - afterRenderType, - afterTransformersType, - afterBuildType -} from './events'; import type PlaintextConfig from './plaintext'; import type { Config as TailwindConfig } from 'tailwindcss'; export default interface Config { - [key: string]: any; // eslint-disable-line - /** * Add or remove attributes from elements. */ @@ -488,83 +480,87 @@ export default interface Config { * @example * ``` * export default { - * beforeCreate: async (config) => { + * beforeCreate: async ({config}) => { * // do something with `config` * } * } * ``` */ - beforeCreate: beforeCreateType; + beforeCreate: Events['beforeCreate']; /** * Runs after the Template's config has been computed, but just before it is compiled. - * It exposes the Template's HTML, its config, and the Maizzle `render` function. - * Must return the `html` string. + * + * Must return the `html` string, otherwise the original will be used. * * @default undefined * * @example * ``` * export default { - * beforeRender: async ({html, config, render}) => { + * beforeRender: async ({html, matter, config, posthtml, transform}) => { * // do something... * return html; * } * } * ``` */ - beforeRender: beforeRenderType; + beforeRender: Events['beforeRender']; /** * Runs after the Template has been compiled, but before any Transformers have been applied. - * Exposes the rendered `html` string and the `config`. Must return the `html` string. + * + * Must return the `html` string, otherwise the original will be used. * * @default undefined * * @example * ``` * export default { - * afterRender: async ({html, config}) => { + * afterRender: async ({html, matter, config, posthtml, transform}) => { * // do something... * return html; * } * } * ``` */ - afterRender: afterRenderType; + afterRender: Events['afterRender']; /** * Runs after all Transformers have been applied, just before the final HTML is returned. - * Exposes the rendered `html` string and the `config`. Must return the `html` string. + * + * Must return the `html` string, otherwise the original will be used. * * @default undefined * * @example * ``` * export default { - * afterTransformers: async ({html, config, render}) => { + * afterTransformers: async ({html, matter, config, posthtml, transform}) => { * // do something... * return html; * } * } * ``` */ - afterTransformers: afterTransformersType; + afterTransformers: Events['afterTransformers']; /** * Runs after all Templates have been compiled and output to disk. - * The files parameter will contain the paths to all the files inside the `build.templates.destination.path` directory. + * `files` will contain the paths to all the files inside the `build.output.path` directory. * * @default undefined * * @example * ``` * export default { - * afterBuild: async ({files, config, render}) => { + * afterBuild: async ({files, config, transform}) => { * // do something... * } * } * ``` */ - afterBuild: afterBuildType; + afterBuild: Events['afterBuild']; + + [key: string]: any; } diff --git a/types/events.d.ts b/types/events.d.ts index 56f650ff..9daf82d4 100644 --- a/types/events.d.ts +++ b/types/events.d.ts @@ -1,5 +1,346 @@ -export type beforeCreateType = (config: object) => Promise; -export type beforeRenderType = (html: string, config: object, render: (html: string, config: object) => Promise) => Promise; -export type afterRenderType = ({ html, config }: { html: string, config: object }) => Promise; -export type afterTransformersType = ({ html, config, render }: { html: string, config: object, render: (html: string, config: object) => Promise }) => Promise; -export type afterBuildType = ({ files, config, render }: { files: string[], config: object, render: (html: string, config: object) => Promise }) => Promise; +import type Config from "./config"; +import type { + safeClassNames, + markdown, + preventWidows, + attributeToStyle, + inlineCSS, + shorthandCSS, + removeUnusedCSS, + purgeCSS, + removeAttributes, + addAttributes, + prettify, + applyBaseURL, + addUrlParams, + sixHEX, + minify, + replaceStrings, + plaintext, +} from "./index"; + +type PostHTMLType = (html: string, config: Config) => { html: string; config: Config }; + +type TransformType = { + /** + * Normalize escaped character class names like `\:` or `\/` by replacing them with email-safe alternatives. + * + * @param {string} html The HTML string to normalize. + * @param {Record} replacements A dictionary of replacements to apply. + * @returns {string} The normalized HTML string. + * @see https://maizzle.com/docs/transformers/safe-class-names + */ + safeClassNames: typeof safeClassNames; + /** + * Compile Markdown to HTML. + * + * @param {string} input The Markdown string to compile. + * @param {MarkdownConfig} [options] A configuration object for the Markdown compiler. + * @returns {string} The compiled HTML string. + * @see https://maizzle.com/docs/transformers/markdown + */ + markdown: typeof markdown; + /** + * Prevent widow words inside a tag by adding a ` ` between its last two words. + * + * @param {string} html The HTML string to process. + * @param {WidowWordsConfig} [options] A configuration object for the widow words transformer. + * @returns {string} The processed HTML string. + * @see https://maizzle.com/docs/transformers/widows + */ + preventWidows: typeof preventWidows; + /** + * Duplicate HTML attributes to inline CSS. + * + * @param {string} html The HTML string to process. + * @param {AttributeToStyleSupportedAttributes[]} attributes An array of attributes to inline. + * @param {PostHTMLConfig} [posthtmlConfig] A configuration object for PostHTML. + * @returns {string} The processed HTML string. + * @see https://maizzle.com/docs/transformers/attribute-to-style + */ + attributeToStyle: typeof attributeToStyle; + /** + * Inline CSS styles in an HTML string. + * + * @param {string} html The HTML string to process. + * @param {CSSInlineConfig} [options] A configuration object for the CSS inliner. + * @returns {string} The processed HTML string. + * @see https://maizzle.com/docs/transformers/inline-css + */ + inlineCSS: typeof inlineCSS; + /** + * Rewrite longhand CSS inside style attributes with shorthand syntax. + * Only works with margin, padding and border, and only when all sides are specified. + * + * @param {string} html The HTML string to process. + * @returns {string} The processed HTML string. + * @see https://maizzle.com/docs/transformers/shorthand-css + */ + shorthandCSS: typeof shorthandCSS; + /** + * Remove unused CSS from `