@prismicio/client 7.20.1 → 7.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.ts +29 -21
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +11 -8
- package/dist/createClient.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts +9 -2
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.ts +11 -4
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +34 -26
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +16 -15
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +11 -10
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +18 -17
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.ts +32 -31
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +6 -9
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.ts +20 -10
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/isFilled.cjs +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.ts +14 -13
- package/dist/helpers/isFilled.js +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +10 -10
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts +2 -2
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.ts +5 -5
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.ts +8 -8
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.ts +6 -6
- package/dist/richtext/types.js.map +1 -1
- package/package.json +1 -1
- package/src/buildQueryURL.ts +29 -21
- package/src/createClient.ts +11 -8
- package/src/getRepositoryEndpoint.ts +9 -2
- package/src/helpers/asDate.ts +11 -4
- package/src/helpers/asHTML.ts +34 -26
- package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
- package/src/helpers/asImageSrc.ts +11 -10
- package/src/helpers/asImageWidthSrcSet.ts +18 -17
- package/src/helpers/asLink.ts +33 -32
- package/src/helpers/asLinkAttrs.ts +6 -9
- package/src/helpers/asText.ts +20 -10
- package/src/helpers/isFilled.ts +15 -14
- package/src/helpers/mapSliceZone.ts +10 -10
- package/src/index.ts +1 -1
- package/src/isRepositoryEndpoint.ts +2 -2
- package/src/richtext/asText.ts +5 -5
- package/src/richtext/serialize.ts +8 -8
- package/src/richtext/types.ts +6 -6
package/dist/helpers/asHTML.d.ts
CHANGED
|
@@ -2,35 +2,35 @@ import type { RichTextField } from "../types/value/richText";
|
|
|
2
2
|
import type { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction } from "../richtext";
|
|
3
3
|
import type { LinkResolverFunction } from "./asLink";
|
|
4
4
|
/**
|
|
5
|
-
* Serializes a node from a rich text
|
|
5
|
+
* Serializes a node from a rich text field with a function to HTML.
|
|
6
6
|
*
|
|
7
7
|
* Unlike a typical `@prismicio/client/richtext` function serializer, this
|
|
8
8
|
* serializer converts the `children` argument to a single string rather than an
|
|
9
9
|
* array of strings.
|
|
10
10
|
*
|
|
11
|
-
* @see
|
|
11
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
12
12
|
*/
|
|
13
13
|
export type HTMLRichTextFunctionSerializer = (type: Parameters<RichTextFunctionSerializer<string>>[0], node: Parameters<RichTextFunctionSerializer<string>>[1], text: Parameters<RichTextFunctionSerializer<string>>[2], children: Parameters<RichTextFunctionSerializer<string>>[3][number], key: Parameters<RichTextFunctionSerializer<string>>[4]) => string | null | undefined;
|
|
14
14
|
/**
|
|
15
|
-
* Serializes a node from a rich text
|
|
15
|
+
* Serializes a node from a rich text field with a map to HTML.
|
|
16
16
|
*
|
|
17
17
|
* Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
|
|
18
18
|
* converts the `children` property to a single string rather than an array of
|
|
19
19
|
* strings and accepts shorthand declarations.
|
|
20
20
|
*
|
|
21
|
-
* @see
|
|
21
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
22
22
|
*/
|
|
23
23
|
export type HTMLRichTextMapSerializer = {
|
|
24
24
|
[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>["span"] ? HTMLStrictRichTextMapSerializer[P] : HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
|
-
* Serializes a node from a rich text
|
|
27
|
+
* Serializes a node from a rich text field with a map to HTML.
|
|
28
28
|
*
|
|
29
29
|
* Unlike a typical `@prismicio/client/richtext` map serializer, this serializer
|
|
30
30
|
* converts the `children` property to a single string rather than an array of
|
|
31
31
|
* strings but doesn't accept shorthand declarations.
|
|
32
32
|
*
|
|
33
|
-
* @see
|
|
33
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
34
34
|
*/
|
|
35
35
|
export type HTMLStrictRichTextMapSerializer = {
|
|
36
36
|
[P in keyof RichTextMapSerializer<string>]: (payload: {
|
|
@@ -76,11 +76,10 @@ export type HTMLRichTextMapSerializerShorthand = {
|
|
|
76
76
|
[Attribute: string]: string | boolean | null | undefined;
|
|
77
77
|
};
|
|
78
78
|
/**
|
|
79
|
-
* Serializes a node from a rich text
|
|
80
|
-
* HTML
|
|
79
|
+
* Serializes a node from a rich text field with a map or a function to HTML.
|
|
81
80
|
*
|
|
82
81
|
* @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}
|
|
83
|
-
* @see
|
|
82
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
84
83
|
*/
|
|
85
84
|
export type HTMLRichTextSerializer = HTMLRichTextMapSerializer | HTMLRichTextFunctionSerializer;
|
|
86
85
|
/**
|
|
@@ -88,13 +87,13 @@ export type HTMLRichTextSerializer = HTMLRichTextMapSerializer | HTMLRichTextFun
|
|
|
88
87
|
*/
|
|
89
88
|
type AsHTMLConfig = {
|
|
90
89
|
/**
|
|
91
|
-
* An optional link resolver function to resolve links. Without it you're
|
|
92
|
-
* expected to use the `routes`
|
|
90
|
+
* An optional link resolver function to resolve links. Without it, you're
|
|
91
|
+
* expected to use the `routes` option from the API.
|
|
93
92
|
*/
|
|
94
93
|
linkResolver?: LinkResolverFunction | null;
|
|
95
94
|
/**
|
|
96
|
-
* An optional rich text serializer
|
|
97
|
-
* default serializer
|
|
95
|
+
* An optional rich text serializer. Unhandled cases will fall back to the
|
|
96
|
+
* default serializer.
|
|
98
97
|
*/
|
|
99
98
|
serializer?: HTMLRichTextSerializer | null;
|
|
100
99
|
};
|
|
@@ -111,30 +110,39 @@ type AsHTMLDeprecatedTupleConfig = [
|
|
|
111
110
|
type AsHTMLReturnType<Field extends RichTextField | null | undefined> = Field extends RichTextField ? string : null;
|
|
112
111
|
export declare const asHTML: {
|
|
113
112
|
/**
|
|
114
|
-
*
|
|
113
|
+
* Converts a rich text field to an HTML string.
|
|
115
114
|
*
|
|
116
|
-
* @
|
|
117
|
-
* @param config - Configuration that determines the output of `asHTML()`
|
|
115
|
+
* @example
|
|
118
116
|
*
|
|
119
|
-
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* const html = asHTML(document.data.content)
|
|
119
|
+
* // => "<p>Hello world</p>"
|
|
120
|
+
* ```
|
|
120
121
|
*
|
|
121
|
-
* @
|
|
122
|
+
* @param richTextField - A rich text field from Prismic.
|
|
123
|
+
* @param config - Configuration that determines the output of `asHTML()`.
|
|
124
|
+
*
|
|
125
|
+
* @returns HTML equivalent of the rich text field, or `null` if the field is
|
|
126
|
+
* empty.
|
|
127
|
+
*
|
|
128
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
122
129
|
*/
|
|
123
130
|
<Field extends RichTextField | null | undefined>(richTextField: Field, config?: AsHTMLConfig): AsHTMLReturnType<Field>;
|
|
124
131
|
/**
|
|
125
|
-
*
|
|
132
|
+
* Converts a rich text field to an HTML string.
|
|
126
133
|
*
|
|
127
134
|
* @deprecated Use object-style configuration instead.
|
|
128
135
|
*
|
|
129
|
-
* @param richTextField - A rich text
|
|
130
|
-
* @param linkResolver - An optional link resolver function to resolve links
|
|
131
|
-
*
|
|
132
|
-
* @param serializer - An optional rich text serializer
|
|
133
|
-
*
|
|
136
|
+
* @param richTextField - A rich text field from Prismic.
|
|
137
|
+
* @param linkResolver - An optional link resolver function to resolve links.
|
|
138
|
+
* Without it, you're expected to use the `routes` option from the API.
|
|
139
|
+
* @param serializer - An optional rich text serializer. Unhandled cases will
|
|
140
|
+
* fall back to the default serializer.
|
|
134
141
|
*
|
|
135
|
-
* @returns HTML equivalent of the
|
|
142
|
+
* @returns HTML equivalent of the rich text field, or `null` if the field is
|
|
143
|
+
* empty.
|
|
136
144
|
*
|
|
137
|
-
* @see
|
|
145
|
+
* @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}
|
|
138
146
|
*/
|
|
139
147
|
<Field extends RichTextField | null | undefined>(richTextField: Field, ...config: AsHTMLDeprecatedTupleConfig): AsHTMLReturnType<Field>;
|
|
140
148
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asHTML.js","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tserializeEmbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text or title field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text or title field with a map or a function to\n * HTML\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it you're\n\t * expected to use the `routes` options from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer, unhandled cases will fallback to the\n\t * default serializer\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param config - Configuration that determines the output of `asHTML()`\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param linkResolver - An optional link resolver function to resolve links,\n\t * without it you're expected to use the `routes` options from the API\n\t * @param serializer - An optional rich text serializer, unhandled cases will\n\t * fallback to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":";;;;AAyJA,MAAM,+BAA+B,CACpC,cACA,eACuC;AACjC,QAAA,yBAAyB,CAG9B,2BACA,yBAG4D;AACxD,QAAA,OAAO,8BAA8B,YAAY;AACpD,aAAQ,CAAC,YAAW;AACnB,gBAEE,uEACG,aAAY,qBAAqB,OAAO;AAAA,MAE9C;AAAA,IAAA;AAGM,WAAA;AAAA,EACR;AAEA,QAAM,gBAA2D;AAAA,IAChE,UAAU,uBACT,yCAAY,UACZ,qBAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,yCAAY,UACZ,qBAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,yCAAY,UACZ,qBAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,yCAAY,UACZ,qBAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,yCAAY,UACZ,qBAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,UAAU,uBACT,yCAAY,UACZ,qBAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,WAAW,uBACV,yCAAY,WACZ,qBAAkC,KAAK,yCAAY,SAAS,CAAC;AAAA,IAE9D,cAAc,uBACb,yCAAY,cACZ,sBAAsB,yCAAY,YAAY,CAAC;AAAA,IAEhD,QAAQ,uBACP,yCAAY,QACZ,qBAA+B,UAAU,yCAAY,MAAM,CAAC;AAAA,IAE7D,IAAI,uBACH,yCAAY,IACZ,qBAA2B,MAAM,yCAAY,EAAE,CAAC;AAAA,IAEjD,UAAU,uBACT,yCAAY,UACZ,qBAAiC,MAAM,yCAAY,QAAQ,CAAC;AAAA,IAE7D,WAAW,uBACV,yCAAY,WACZ,qBAAkC,MAAM,yCAAY,SAAS,CAAC;AAAA,IAE/D,MAAM,uBACL,yCAAY,MACZ,qBAA6B,MAAM,yCAAY,IAAI,CAAC;AAAA,IAErD,OAAO,uBACN,yCAAY,OACZ,qBAA8B,MAAM,yCAAY,KAAK,CAAC;AAAA,IAEvD,OAAO,uBACN,yCAAY,OACZ,eAAe,cAAc,yCAAY,KAAK,CAAC;AAAA,IAEhD,OAAO,uBACN,yCAAY,OACZ,eAAe,yCAAY,KAAK,CAAC;AAAA,IAElC,WAAW,uBACV,yCAAY,WACZ,mBAAmB,cAAc,yCAAY,SAAS,CAAC;AAAA,IAExD,OAAO,uBACN,yCAAY,OACZ,qBAA8B,QAAQ,yCAAY,KAAK,CAAC;AAAA,IAEzD,MAAM,uBAA+B,yCAAY,MAAM,cAAe,CAAA;AAAA;AAGvE,SAAO,oCAAoC,aAAa;AACzD;AAWA,MAAM,sCAAsC,CAC3C,kBACuC;AACvC,QAAM,wBAAwB,CAAA;AAE9B,aAAW,OAAO,eAAe;AAC1B,UAAA,gBAAgB,cAAc,GAAiC;AAErE,QAAI,eAAe;AACI,4BAAA,GAAiC,IAAI,CAAC,YAAW;AACtE,eAAO,cAAc;AAAA,UACpB,GAAG;AAAA;AAAA,UAEH,UAAU,QAAQ,SAAS,KAAK,EAAE;AAAA,QAAA,CAClC;AAAA,MACF;AAAA,IAAA;AAAA,EACD;AAGD,SAAO,kBAAkB,qBAAqB;AAC/C;AAmCa,MAAA,SAmCT,CACH,kBAEG,wBACyB;AAC5B,MAAI,eAAe;AAEZ,UAAA,CAAC,4BAA4B,eAAe,IAAI;AAClD,QAAA;AACJ,QACC,OAAO,+BAA+B,cACtC,8BAA8B,MAC7B;AACQ,eAAA;AAAA,QACR,cAAc;AAAA,QACd,YAAY;AAAA;WAEP;AACG,eAAA,EAAE,GAAG;;AAGX,QAAA;AACJ,QAAI,OAAO,YAAY;AAClB,UAAA,OAAO,OAAO,eAAe,YAAY;AAC5C,qBAAa,mBACZ,CAAC,MAAM,MAAM,MAAM,UAAU;AAAA;AAAA,UAE3B,OAAO,WACP,MACA,MACA,MACA,SAAS,KAAK,EAAE,GAChB,GAAG;AAAA,WAEL,6BAA6B,OAAO,YAAY,CAAC;AAAA,MAAA,OAE5C;AACN,qBAAa,6BACZ,OAAO,cACP,OAAO,UAAU;AAAA,MAAA;AAAA,IAEnB,OACM;AACO,mBAAA,6BAA6B,OAAO,YAAY;AAAA,IAAA;AAG9D,WAAO,UAAU,eAAe,UAAU,EAAE,KAC3C,EAAE;AAAA,EAAA,OAEG;AACC,WAAA;AAAA,EAAA;AAET;"}
|
|
1
|
+
{"version":3,"file":"asHTML.js","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tserializeEmbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text field with a map to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text field with a map to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text field with a map or a function to HTML.\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it, you're\n\t * expected to use the `routes` option from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer. Unhandled cases will fall back to the\n\t * default serializer.\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Converts a rich text field to an HTML string.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const html = asHTML(document.data.content)\n\t * // => \"<p>Hello world</p>\"\n\t * ```\n\t *\n\t * @param richTextField - A rich text field from Prismic.\n\t * @param config - Configuration that determines the output of `asHTML()`.\n\t *\n\t * @returns HTML equivalent of the rich text field, or `null` if the field is\n\t * empty.\n\t *\n\t * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Converts a rich text field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text field from Prismic.\n\t * @param linkResolver - An optional link resolver function to resolve links.\n\t * Without it, you're expected to use the `routes` option from the API.\n\t * @param serializer - An optional rich text serializer. Unhandled cases will\n\t * fall back to the default serializer.\n\t *\n\t * @returns HTML equivalent of the rich text field, or `null` if the field is\n\t * empty.\n\t *\n\t * @see Learn how to style rich text and customize rendering: {@link https://prismic.io/docs/fields/rich-text}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's
|
|
1
|
+
{"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A pixel-density-based `srcset` attribute value for the image field\n\t\t\t\t * with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Creates a pixel-density-based `srcset` from an image field with optional\n * image transformations via imgix URL parameters.\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities\n * will be used by default: 1, 2, 3.\n *\n * @example\n *\n * ```ts\n * const srcset = asImagePixelDensitySrcSet(document.data.photo, {\n * \tpixelDensities: [1, 2],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` pixel densities.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImagePixelDensitySrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImagePixelDensitySrcSetConfig = {},\n): AsImagePixelDensitySrcSetReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\t// We are using destructuring to omit `pixelDensities` from the\n\t\t// object we will pass to `buildURL()`.\n\t\tconst { pixelDensities = DEFAULT_PIXEL_DENSITIES, ...imgixParams } = config\n\n\t\treturn {\n\t\t\tsrc: buildURL(field.url, imgixParams),\n\t\t\tsrcset: buildPixelDensitySrcSet(field.url, {\n\t\t\t\t...imgixParams,\n\t\t\t\tpixelDensities,\n\t\t\t}),\n\t\t} as AsImagePixelDensitySrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImagePixelDensitySrcSetReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled","buildURL","buildPixelDensitySrcSet"],"mappings":";;;;AAUA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AAgEjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,wBAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,YAAgB,IAAA;AAE9D,WAAA;AAAA,MACN,KAAKC,gBAAA,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQC,gBAAAA,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MACA,CAAA;AAAA;SAEI;AACC,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -9,18 +9,18 @@ type AsImagePixelDensitySrcSetConfig = Omit<BuildPixelDensitySrcSetParams, "pixe
|
|
|
9
9
|
*/
|
|
10
10
|
type AsImagePixelDensitySrcSetReturnType<Field extends ImageFieldImage | null | undefined> = Field extends ImageFieldImage<"filled"> ? {
|
|
11
11
|
/**
|
|
12
|
-
* The image field's
|
|
12
|
+
* The image field's URL with imgix URL parameters (if given).
|
|
13
13
|
*/
|
|
14
14
|
src: string;
|
|
15
15
|
/**
|
|
16
|
-
* A pixel-
|
|
17
|
-
*
|
|
16
|
+
* A pixel-density-based `srcset` attribute value for the image field
|
|
17
|
+
* with imgix URL parameters (if given).
|
|
18
18
|
*/
|
|
19
19
|
srcset: string;
|
|
20
20
|
} : null;
|
|
21
21
|
/**
|
|
22
22
|
* Creates a pixel-density-based `srcset` from an image field with optional
|
|
23
|
-
* image transformations
|
|
23
|
+
* image transformations via imgix URL parameters.
|
|
24
24
|
*
|
|
25
25
|
* If a `pixelDensities` parameter is not given, the following pixel densities
|
|
26
26
|
* will be used by default: 1, 2, 3.
|
|
@@ -28,26 +28,27 @@ type AsImagePixelDensitySrcSetReturnType<Field extends ImageFieldImage | null |
|
|
|
28
28
|
* @example
|
|
29
29
|
*
|
|
30
30
|
* ```ts
|
|
31
|
-
* const srcset = asImagePixelDensitySrcSet(document.data.
|
|
31
|
+
* const srcset = asImagePixelDensitySrcSet(document.data.photo, {
|
|
32
32
|
* pixelDensities: [1, 2],
|
|
33
33
|
* sat: -100,
|
|
34
34
|
* })
|
|
35
35
|
* // => {
|
|
36
|
-
* // src:
|
|
37
|
-
* // srcset:
|
|
38
|
-
* //
|
|
36
|
+
* // src: "https://images.prismic.io/repo/image.png?sat=-100",
|
|
37
|
+
* // srcset: "https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, " +
|
|
38
|
+
* // "https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x"
|
|
39
39
|
* // }
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
|
-
* @param field -
|
|
43
|
-
* an image URL.
|
|
44
|
-
* @param config - An object of
|
|
45
|
-
* parameter defines the resulting `srcset`
|
|
42
|
+
* @param field - An image field (or one of its responsive views) from which to
|
|
43
|
+
* get an image URL.
|
|
44
|
+
* @param config - An object of imgix URL API parameters. The `pixelDensities`
|
|
45
|
+
* parameter defines the resulting `srcset` pixel densities.
|
|
46
46
|
*
|
|
47
|
-
* @returns A `srcset` attribute value for the image field with
|
|
48
|
-
* parameters
|
|
47
|
+
* @returns A `srcset` attribute value for the image field with imgix URL
|
|
48
|
+
* parameters, or `null` if the field is empty.
|
|
49
49
|
*
|
|
50
|
-
* @see
|
|
50
|
+
* @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
|
|
51
|
+
* @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
|
|
51
52
|
*/
|
|
52
53
|
export declare const asImagePixelDensitySrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImagePixelDensitySrcSetConfig) => AsImagePixelDensitySrcSetReturnType<Field>;
|
|
53
54
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asImagePixelDensitySrcSet.js","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's
|
|
1
|
+
{"version":3,"file":"asImagePixelDensitySrcSet.js","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A pixel-density-based `srcset` attribute value for the image field\n\t\t\t\t * with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Creates a pixel-density-based `srcset` from an image field with optional\n * image transformations via imgix URL parameters.\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities\n * will be used by default: 1, 2, 3.\n *\n * @example\n *\n * ```ts\n * const srcset = asImagePixelDensitySrcSet(document.data.photo, {\n * \tpixelDensities: [1, 2],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` pixel densities.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImagePixelDensitySrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImagePixelDensitySrcSetConfig = {},\n): AsImagePixelDensitySrcSetReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\t// We are using destructuring to omit `pixelDensities` from the\n\t\t// object we will pass to `buildURL()`.\n\t\tconst { pixelDensities = DEFAULT_PIXEL_DENSITIES, ...imgixParams } = config\n\n\t\treturn {\n\t\t\tsrc: buildURL(field.url, imgixParams),\n\t\t\tsrcset: buildPixelDensitySrcSet(field.url, {\n\t\t\t\t...imgixParams,\n\t\t\t\tpixelDensities,\n\t\t\t}),\n\t\t} as AsImagePixelDensitySrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImagePixelDensitySrcSetReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled"],"mappings":";;AAUA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AAgEjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,eAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,YAAgB,IAAA;AAE9D,WAAA;AAAA,MACN,KAAK,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQ,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MACA,CAAA;AAAA;SAEI;AACC,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asImageSrc.cjs","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations
|
|
1
|
+
{"version":3,"file":"asImageSrc.cjs","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations via\n * imgix URL parameters.\n *\n * @example\n *\n * ```ts\n * const src = asImageSrc(document.data.photo, { sat: -100 })\n * // => \"https://images.prismic.io/repo/image.png?sat=-100\"\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters to transform the image.\n *\n * @returns The image field's URL with transformations applied, or `null` if the\n * field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageSrc = <Field extends ImageFieldImage | null | undefined>(\n\tfield: Field,\n\tconfig: ImgixURLParams = {},\n): AsImageSrcReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\treturn buildURL(field.url, config) as AsImageSrcReturnType<Field>\n\t} else {\n\t\treturn null as AsImageSrcReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled","buildURL"],"mappings":";;;;AAkCO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,wBAAuB,KAAK,GAAG;AACpC,WAAAC,yBAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -5,24 +5,25 @@ import type { ImageFieldImage } from "../types/value/image";
|
|
|
5
5
|
*/
|
|
6
6
|
type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> = Field extends ImageFieldImage<"filled"> ? string : null;
|
|
7
7
|
/**
|
|
8
|
-
* Returns the URL of an image field with optional image transformations
|
|
9
|
-
*
|
|
8
|
+
* Returns the URL of an image field with optional image transformations via
|
|
9
|
+
* imgix URL parameters.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
*
|
|
13
13
|
* ```ts
|
|
14
|
-
* const src = asImageSrc(document.data.
|
|
15
|
-
* // => https://images.prismic.io/repo/image.png?sat=-100
|
|
14
|
+
* const src = asImageSrc(document.data.photo, { sat: -100 })
|
|
15
|
+
* // => "https://images.prismic.io/repo/image.png?sat=-100"
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
|
-
* @param field -
|
|
19
|
-
* an image URL.
|
|
20
|
-
* @param config - An object of
|
|
18
|
+
* @param field - An image field (or one of its responsive views) from which to
|
|
19
|
+
* get an image URL.
|
|
20
|
+
* @param config - An object of imgix URL API parameters to transform the image.
|
|
21
21
|
*
|
|
22
|
-
* @returns The image field's
|
|
23
|
-
*
|
|
22
|
+
* @returns The image field's URL with transformations applied, or `null` if the
|
|
23
|
+
* field is empty.
|
|
24
24
|
*
|
|
25
|
-
* @see
|
|
25
|
+
* @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
|
|
26
|
+
* @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
|
|
26
27
|
*/
|
|
27
28
|
export declare const asImageSrc: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: ImgixURLParams) => AsImageSrcReturnType<Field>;
|
|
28
29
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asImageSrc.js","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations
|
|
1
|
+
{"version":3,"file":"asImageSrc.js","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations via\n * imgix URL parameters.\n *\n * @example\n *\n * ```ts\n * const src = asImageSrc(document.data.photo, { sat: -100 })\n * // => \"https://images.prismic.io/repo/image.png?sat=-100\"\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters to transform the image.\n *\n * @returns The image field's URL with transformations applied, or `null` if the\n * field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageSrc = <Field extends ImageFieldImage | null | undefined>(\n\tfield: Field,\n\tconfig: ImgixURLParams = {},\n): AsImageSrcReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\treturn buildURL(field.url, config) as AsImageSrcReturnType<Field>\n\t} else {\n\t\treturn null as AsImageSrcReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled"],"mappings":";;AAkCO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,eAAuB,KAAK,GAAG;AACpC,WAAA,SAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asImageWidthSrcSet.cjs","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's
|
|
1
|
+
{"version":3,"file":"asImageWidthSrcSet.cjs","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A width-based `srcset` attribute value for the image field with imgix\n\t\t\t\t * URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Configuration for `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, \"widths\"> & {\n\twidths?: \"thumbnails\" | BuildWidthSrcSetParams[\"widths\"]\n}\n\n/**\n * Creates a width-based `srcset` from an image field with optional image\n * transformations via imgix URL parameters.\n *\n * If a `widths` parameter is not given, the following widths (in pixels) will\n * be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.\n *\n * If the image field contains responsive views, each responsive view can be\n * used as a width in the resulting `srcset` by passing `\"thumbnails\"` as the\n * `widths` parameter.\n *\n * @example\n *\n * ```ts\n * const srcset = asImageWidthSrcSet(document.data.photo, {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths. Pass `\"thumbnails\"` to automatically\n * use the field's responsive views.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageWidthSrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImageWidthSrcSetConfig = {},\n): AsImageWidthSrcSetReturnType<Field> => {\n\tif (field && isFilled.imageThumbnail(field)) {\n\t\t// We are using destructuring to omit `widths` from the object\n\t\t// we will pass to `buildURL()`.\n\t\tlet {\n\t\t\twidths = DEFAULT_WIDTHS,\n\t\t\t// eslint-disable-next-line prefer-const\n\t\t\t...imgixParams\n\t\t} = config\n\t\tconst {\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tid: _id,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\tedit: _edit,\n\t\t\t...responsiveViews\n\t\t} = field\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews)\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t\t}),\n\t\t} as AsImageWidthSrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>\n\t}\n}\n"],"names":["isFilled.imageThumbnail","buildURL","buildWidthSrcSet"],"mappings":";;;;AAUA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAoE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,wBAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IAAA,IACA;AACJ,UAAM,EACL,KACA,YACA,IAAI,KACJ,KAAK,MACL,WAAW,YACX,MAAM,OACN,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IAAA;AAGH,WAAA;AAAA,MACN,KAAKC,gBAAAA,SAAS,KAAK,WAAW;AAAA,MAC9B;AAAA;AAAA;AAAA,QAGC,WAAW,eACR;AAAA,UACAC,gBAAAA,iBAAiB,KAAK;AAAA,YACrB,GAAG;AAAA,YACH,QAAQ,CAAC,WAAW,KAAK;AAAA,UAAA,CACzB;AAAA,UACD,GAAG,sBAAsB,IAAI,CAAC,cAAa;AACnC,mBAAAA,gBAAA,iBAAiB,UAAU,KAAK;AAAA,cACtC,GAAG;AAAA,cACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,YAAA,CACnC;AAAA,UACD,CAAA;AAAA,UACA,KAAK,IAAI,IACVA,gBAAAA,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QACA,CAAA;AAAA;AAAA;SAEC;AACC,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -5,12 +5,12 @@ import type { ImageFieldImage } from "../types/value/image";
|
|
|
5
5
|
*/
|
|
6
6
|
type AsImageWidthSrcSetReturnType<Field extends ImageFieldImage | null | undefined> = Field extends ImageFieldImage<"filled"> ? {
|
|
7
7
|
/**
|
|
8
|
-
* The image field's
|
|
8
|
+
* The image field's URL with imgix URL parameters (if given).
|
|
9
9
|
*/
|
|
10
10
|
src: string;
|
|
11
11
|
/**
|
|
12
|
-
* A width-based `srcset` attribute value for the image field
|
|
13
|
-
*
|
|
12
|
+
* A width-based `srcset` attribute value for the image field with imgix
|
|
13
|
+
* URL parameters (if given).
|
|
14
14
|
*/
|
|
15
15
|
srcset: string;
|
|
16
16
|
} : null;
|
|
@@ -22,10 +22,10 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
|
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
24
|
* Creates a width-based `srcset` from an image field with optional image
|
|
25
|
-
* transformations
|
|
25
|
+
* transformations via imgix URL parameters.
|
|
26
26
|
*
|
|
27
|
-
* If a `widths` parameter is not given, the following widths
|
|
28
|
-
* default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
|
|
27
|
+
* If a `widths` parameter is not given, the following widths (in pixels) will
|
|
28
|
+
* be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
|
|
29
29
|
*
|
|
30
30
|
* If the image field contains responsive views, each responsive view can be
|
|
31
31
|
* used as a width in the resulting `srcset` by passing `"thumbnails"` as the
|
|
@@ -34,28 +34,29 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
|
|
|
34
34
|
* @example
|
|
35
35
|
*
|
|
36
36
|
* ```ts
|
|
37
|
-
* const srcset = asImageWidthSrcSet(document.data.
|
|
37
|
+
* const srcset = asImageWidthSrcSet(document.data.photo, {
|
|
38
38
|
* widths: [400, 800, 1600],
|
|
39
39
|
* sat: -100,
|
|
40
40
|
* })
|
|
41
41
|
* // => {
|
|
42
|
-
* // src:
|
|
43
|
-
* // srcset:
|
|
44
|
-
* //
|
|
45
|
-
* //
|
|
42
|
+
* // src: "https://images.prismic.io/repo/image.png?sat=-100",
|
|
43
|
+
* // srcset: "https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, " +
|
|
44
|
+
* // "https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, " +
|
|
45
|
+
* // "https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w"
|
|
46
46
|
* // }
|
|
47
47
|
* ```
|
|
48
48
|
*
|
|
49
|
-
* @param field -
|
|
50
|
-
* an image URL.
|
|
51
|
-
* @param config - An object of
|
|
49
|
+
* @param field - An image field (or one of its responsive views) from which to
|
|
50
|
+
* get an image URL.
|
|
51
|
+
* @param config - An object of imgix URL API parameters. The `widths` parameter
|
|
52
52
|
* defines the resulting `srcset` widths. Pass `"thumbnails"` to automatically
|
|
53
53
|
* use the field's responsive views.
|
|
54
54
|
*
|
|
55
|
-
* @returns A `srcset` attribute value for the image field with
|
|
56
|
-
* parameters
|
|
55
|
+
* @returns A `srcset` attribute value for the image field with imgix URL
|
|
56
|
+
* parameters, or `null` if the field is empty.
|
|
57
57
|
*
|
|
58
|
-
* @see
|
|
58
|
+
* @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
|
|
59
|
+
* @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
|
|
59
60
|
*/
|
|
60
61
|
export declare const asImageWidthSrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImageWidthSrcSetConfig) => AsImageWidthSrcSetReturnType<Field>;
|
|
61
62
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asImageWidthSrcSet.js","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's
|
|
1
|
+
{"version":3,"file":"asImageWidthSrcSet.js","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A width-based `srcset` attribute value for the image field with imgix\n\t\t\t\t * URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Configuration for `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, \"widths\"> & {\n\twidths?: \"thumbnails\" | BuildWidthSrcSetParams[\"widths\"]\n}\n\n/**\n * Creates a width-based `srcset` from an image field with optional image\n * transformations via imgix URL parameters.\n *\n * If a `widths` parameter is not given, the following widths (in pixels) will\n * be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.\n *\n * If the image field contains responsive views, each responsive view can be\n * used as a width in the resulting `srcset` by passing `\"thumbnails\"` as the\n * `widths` parameter.\n *\n * @example\n *\n * ```ts\n * const srcset = asImageWidthSrcSet(document.data.photo, {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths. Pass `\"thumbnails\"` to automatically\n * use the field's responsive views.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageWidthSrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImageWidthSrcSetConfig = {},\n): AsImageWidthSrcSetReturnType<Field> => {\n\tif (field && isFilled.imageThumbnail(field)) {\n\t\t// We are using destructuring to omit `widths` from the object\n\t\t// we will pass to `buildURL()`.\n\t\tlet {\n\t\t\twidths = DEFAULT_WIDTHS,\n\t\t\t// eslint-disable-next-line prefer-const\n\t\t\t...imgixParams\n\t\t} = config\n\t\tconst {\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tid: _id,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\tedit: _edit,\n\t\t\t...responsiveViews\n\t\t} = field\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews)\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t\t}),\n\t\t} as AsImageWidthSrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>\n\t}\n}\n"],"names":["isFilled.imageThumbnail"],"mappings":";;AAUA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAoE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,eAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IAAA,IACA;AACJ,UAAM,EACL,KACA,YACA,IAAI,KACJ,KAAK,MACL,WAAW,YACX,MAAM,OACN,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IAAA;AAGH,WAAA;AAAA,MACN,KAAK,SAAS,KAAK,WAAW;AAAA,MAC9B;AAAA;AAAA;AAAA,QAGC,WAAW,eACR;AAAA,UACA,iBAAiB,KAAK;AAAA,YACrB,GAAG;AAAA,YACH,QAAQ,CAAC,WAAW,KAAK;AAAA,UAAA,CACzB;AAAA,UACD,GAAG,sBAAsB,IAAI,CAAC,cAAa;AACnC,mBAAA,iBAAiB,UAAU,KAAK;AAAA,cACtC,GAAG;AAAA,cACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,YAAA,CACnC;AAAA,UACD,CAAA;AAAA,UACA,KAAK,IAAI,IACV,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QACA,CAAA;AAAA;AAAA;SAEC;AACC,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asLink.cjs","sources":["../../../src/helpers/asLink.ts"],"sourcesContent":["import type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport { documentToLinkField } from \"./documentToLinkField\"\n\n/**\n * Resolves a link to a Prismic
|
|
1
|
+
{"version":3,"file":"asLink.cjs","sources":["../../../src/helpers/asLink.ts"],"sourcesContent":["import type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport { documentToLinkField } from \"./documentToLinkField\"\n\n/**\n * Resolves a link to a Prismic page to a URL.\n *\n * @typeParam ReturnType - Return type of your link resolver function. Useful if\n * you prefer to return a complex object.\n *\n * @param linkToDocumentField - A page link field to resolve.\n *\n * @returns Resolved URL.\n *\n * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n */\nexport type LinkResolverFunction<ReturnType = string | null | undefined> = (\n\tlinkToDocumentField: FilledContentRelationshipField,\n) => ReturnType\n\n/**\n * Configuration that determines the output of `asLink()`.\n */\ntype AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =\n\t{\n\t\t/**\n\t\t * An optional link resolver function. Without it, you're expected to use\n\t\t * the `routes` option from the API.\n\t\t */\n\t\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null\n\t}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsLinkDeprecatedTupleConfig<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n> = [linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null]\n\n/**\n * The return type of `asLink()`.\n */\nexport type AsLinkReturnType<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = Field extends\n\t| FilledLinkToWebField\n\t| FilledLinkToMediaField\n\t| FilledContentRelationshipField\n\t| PrismicDocument\n\t? LinkResolverFunctionReturnType | string | null\n\t: null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asLink: {\n\t/**\n\t * Converts any type of link field or Prismic page to a URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = asLink(document.data.link)\n\t * // => \"/blog/my-post\"\n\t * ```\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n\t * type.\n\t * @typeParam Field - Link field or Prismic page to resolve to a URL.\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a page to resolve.\n\t * @param config - Configuration that determines the output of `asLink()`.\n\t *\n\t * @returns Resolved URL, or `null` if the link field or page is empty.\n\t *\n\t * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\tconfig?: AsLinkConfig<LinkResolverFunctionReturnType>,\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\n\t/**\n\t * Converts any type of link field or Prismic page to a URL.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n\t * type.\n\t * @typeParam Field - Link field or Prismic page to resolve to a URL.\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a page to resolve.\n\t * @param linkResolver - An optional link resolver function. Without it,\n\t * you're expected to use the `routes` option from the API.\n\t *\n\t * @returns Resolved URL, or `null` if the link field or page is empty.\n\t *\n\t * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\t...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n} = <\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n>(\n\tlinkFieldOrDocument: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple:\n\t\t| [config?: AsLinkConfig<LinkResolverFunctionReturnType>]\n\t\t| AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n): AsLinkReturnType<LinkResolverFunctionReturnType, Field> => {\n\tif (!linkFieldOrDocument) {\n\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n\n\t// Converts document to link field if needed\n\tconst linkField =\n\t\t// prettier-ignore\n\t\t(\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t\t// TODO: Remove the `prettier-ignore` comment when this bug is fixed.\n\t\t\t\"link_type\" in linkFieldOrDocument\n\t\t\t\t? linkFieldOrDocument\n\t\t\t\t: documentToLinkField(linkFieldOrDocument)\n\t\t) as LinkField\n\n\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\tconst [configObjectOrLinkResolver] = configObjectOrTuple\n\tlet config: AsLinkConfig<LinkResolverFunctionReturnType>\n\tif (\n\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\tconfigObjectOrLinkResolver == null\n\t) {\n\t\tconfig = {\n\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t}\n\t} else {\n\t\tconfig = { ...configObjectOrLinkResolver }\n\t}\n\n\tswitch (linkField.link_type) {\n\t\tcase LinkType.Media:\n\t\tcase LinkType.Web:\n\t\t\treturn (\"url\" in linkField ? linkField.url : null) as AsLinkReturnType<\n\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\tField\n\t\t\t>\n\n\t\tcase LinkType.Document: {\n\t\t\tif (\"id\" in linkField && config.linkResolver) {\n\t\t\t\t// When using link resolver...\n\t\t\t\tconst resolvedURL = config.linkResolver(linkField)\n\n\t\t\t\tif (resolvedURL != null) {\n\t\t\t\t\treturn resolvedURL as AsLinkReturnType<\n\t\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\t\tField\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\"url\" in linkField && linkField.url) {\n\t\t\t\t// When using route resolver...\n\t\t\t\treturn linkField.url as AsLinkReturnType<\n\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\tField\n\t\t\t\t>\n\t\t\t}\n\n\t\t\t// When empty or route resolver and link resolver are not used...\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t\t}\n\n\t\tcase LinkType.Any:\n\t\tdefault:\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n}\n"],"names":["documentToLinkField","LinkType"],"mappings":";;;;AA+Da,MAAA,SA8DT,CAQH,wBAEG,wBAGyD;AAC5D,MAAI,CAAC,qBAAqB;AAClB,WAAA;AAAA,EAAA;AAIF,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMJ,eAAe,sBACZ,sBACAA,oBAAAA,oBAAoB,mBAAmB;AAAA;AAItC,QAAA,CAAC,0BAA0B,IAAI;AACjC,MAAA;AACJ,MACC,OAAO,+BAA+B,cACtC,8BAA8B,MAC7B;AACQ,aAAA;AAAA,MACR,cAAc;AAAA;SAET;AACG,aAAA,EAAE,GAAG;;AAGf,UAAQ,UAAU,WAAW;AAAA,IAC5B,KAAKC,KAAS,SAAA;AAAA,IACd,KAAKA,KAAS,SAAA;AACL,aAAA,SAAS,YAAY,UAAU,MAAM;AAAA,IAK9C,KAAKA,KAAAA,SAAS,UAAU;AACnB,UAAA,QAAQ,aAAa,OAAO,cAAc;AAEvC,cAAA,cAAc,OAAO,aAAa,SAAS;AAEjD,YAAI,eAAe,MAAM;AACjB,iBAAA;AAAA,QAAA;AAAA,MAIR;AAGG,UAAA,SAAS,aAAa,UAAU,KAAK;AAExC,eAAO,UAAU;AAAA,MAAA;AAOX,aAAA;AAAA,IAAA;AAAA,IAGR,KAAKA,KAAS,SAAA;AAAA,IACd;AACQ,aAAA;AAAA,EAAA;AAEV;;"}
|