import { RichTextField } from "../types/value/richText.js"; import { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction } from "../richtext/types.js"; import { LinkResolverFunction } from "./asLink.js"; //#region src/helpers/asHTML.d.ts /** * Serializes a node from a rich text field with a function to HTML. * * Unlike a typical `@prismicio/client/richtext` function serializer, this serializer converts the * `children` argument to a single string rather than an array of strings. * * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text} */ type HTMLRichTextFunctionSerializer = (type: Parameters>[0], node: Parameters>[1], text: Parameters>[2], children: Parameters>[3][number], key: Parameters>[4]) => string | null | undefined; /** * Serializes a node from a rich text field with a map to HTML. * * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer converts the * `children` property to a single string rather than an array of strings and accepts shorthand * declarations. * * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text} */ type HTMLRichTextMapSerializer = { [P in keyof RichTextMapSerializer]: P extends RichTextMapSerializer["span"] ? HTMLStrictRichTextMapSerializer[P] : HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand }; /** * Serializes a node from a rich text field with a map to HTML. * * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer converts the * `children` property to a single string rather than an array of strings but doesn't accept * shorthand declarations. * * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text} */ type HTMLStrictRichTextMapSerializer = { [P in keyof RichTextMapSerializer]: (payload: { type: Parameters>[0]["type"]; node: Parameters>[0]["node"]; text: Parameters>[0]["text"]; children: Parameters>[0]["children"][number]; key: Parameters>[0]["key"]; }) => string | null | undefined }; /** * A {@link RichTextMapSerializerFunction} type specifically for {@link HTMLRichTextMapSerializer}. * * @typeParam BlockName - The serializer's rich text block type. */ type HTMLRichTextMapSerializerFunction> = RichTextMapSerializerFunction[BlockType]>, ExtractTextTypeGeneric[BlockType]>>; /** * Returns the `Node` generic from {@link RichTextMapSerializerFunction}. * * @typeParam T - The `RichTextMapSerializerFunction` containing the needed * `Node` generic. */ type ExtractNodeGeneric = T extends RichTextMapSerializerFunction ? U : never; /** * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}. * * @typeParam T - The `RichTextMapSerializerFunction` containing the needed * `TextType` generic. */ type ExtractTextTypeGeneric = T extends RichTextMapSerializerFunction ? U : never; /** A shorthand definition for {@link HTMLRichTextMapSerializer} element types. */ type HTMLRichTextMapSerializerShorthand = { /** Classes to apply to the element type. */class?: string; /** Other attributes to apply to the element type. */ [Attribute: string]: string | boolean | null | undefined; }; /** * Serializes a node from a rich text field with a map or a function to HTML. * * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer} * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text} */ type HTMLRichTextSerializer = HTMLRichTextMapSerializer | HTMLRichTextFunctionSerializer; /** Configuration that determines the output of `asHTML()`. */ type AsHTMLConfig = { /** * An optional link resolver function to resolve links. Without it, you're expected to use the * `routes` option from the API. */ linkResolver?: LinkResolverFunction | null; /** An optional rich text serializer. Unhandled cases will fall back to the default serializer. */ serializer?: HTMLRichTextSerializer | null; }; /** @deprecated Use object-style configuration instead. */ type AsHTMLDeprecatedTupleConfig = [linkResolver?: LinkResolverFunction | null, serializer?: HTMLRichTextSerializer | null]; /** The return type of `asHTML()`. */ type AsHTMLReturnType = Field extends RichTextField ? string : null; declare const asHTML: { /** * Converts a rich text field to an HTML string. * * @example * ;```ts * const html = asHTML(document.data.content) * // => "

Hello world

" * ``` * * @param richTextField - A rich text field from Prismic. * @param config - Configuration that determines the output of `asHTML()`. * @returns HTML equivalent of the rich text field, or `null` if the field is * empty. * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text} */ (richTextField: Field, config?: AsHTMLConfig): AsHTMLReturnType; /** * Converts a rich text field to an HTML string. * * @deprecated Use object-style configuration instead. * @param richTextField - A rich text field from Prismic. * @param linkResolver - An optional link resolver function to resolve links. Without it, you're * expected to use the `routes` option from the API. * @param serializer - An optional rich text serializer. Unhandled cases will fall back to the * default serializer. * @returns HTML equivalent of the rich text field, or `null` if the field is * empty. * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text} */ (richTextField: Field, ...config: AsHTMLDeprecatedTupleConfig): AsHTMLReturnType; }; //#endregion export { HTMLRichTextFunctionSerializer, HTMLRichTextMapSerializer, HTMLRichTextSerializer, asHTML }; //# sourceMappingURL=asHTML.d.ts.map