@prismicio/client 7.0.0-alpha.5 → 7.0.1-alpha.0

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.
Files changed (231) hide show
  1. package/dist/buildQueryURL.cjs.map +1 -1
  2. package/dist/buildQueryURL.d.ts +15 -14
  3. package/dist/buildQueryURL.js.map +1 -1
  4. package/dist/createClient.cjs +63 -30
  5. package/dist/createClient.cjs.map +1 -1
  6. package/dist/createClient.d.ts +95 -48
  7. package/dist/createClient.js +63 -30
  8. package/dist/createClient.js.map +1 -1
  9. package/dist/filter.cjs +39 -39
  10. package/dist/filter.cjs.map +1 -1
  11. package/dist/filter.d.ts +39 -39
  12. package/dist/filter.js +39 -39
  13. package/dist/filter.js.map +1 -1
  14. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  15. package/dist/getGraphQLEndpoint.d.ts +1 -0
  16. package/dist/getGraphQLEndpoint.js.map +1 -1
  17. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  18. package/dist/getRepositoryEndpoint.d.ts +2 -0
  19. package/dist/getRepositoryEndpoint.js.map +1 -1
  20. package/dist/getRepositoryName.cjs.map +1 -1
  21. package/dist/getRepositoryName.d.ts +1 -0
  22. package/dist/getRepositoryName.js.map +1 -1
  23. package/dist/getToolbarSrc.cjs.map +1 -1
  24. package/dist/getToolbarSrc.d.ts +1 -1
  25. package/dist/getToolbarSrc.js.map +1 -1
  26. package/dist/helpers/asDate.cjs.map +1 -1
  27. package/dist/helpers/asDate.d.ts +3 -2
  28. package/dist/helpers/asDate.js.map +1 -1
  29. package/dist/helpers/asHTML.cjs.map +1 -1
  30. package/dist/helpers/asHTML.d.ts +34 -28
  31. package/dist/helpers/asHTML.js.map +1 -1
  32. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  33. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +5 -5
  34. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  35. package/dist/helpers/asImageSrc.cjs.map +1 -1
  36. package/dist/helpers/asImageSrc.d.ts +3 -3
  37. package/dist/helpers/asImageSrc.js.map +1 -1
  38. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  39. package/dist/helpers/asImageWidthSrcSet.d.ts +6 -6
  40. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  41. package/dist/helpers/asLink.cjs.map +1 -1
  42. package/dist/helpers/asLink.d.ts +32 -23
  43. package/dist/helpers/asLink.js.map +1 -1
  44. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  45. package/dist/helpers/asLinkAttrs.d.ts +12 -7
  46. package/dist/helpers/asLinkAttrs.js.map +1 -1
  47. package/dist/helpers/asText.cjs.map +1 -1
  48. package/dist/helpers/asText.d.ts +18 -14
  49. package/dist/helpers/asText.js.map +1 -1
  50. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  51. package/dist/helpers/documentToLinkField.d.ts +2 -0
  52. package/dist/helpers/documentToLinkField.js.map +1 -1
  53. package/dist/helpers/isFilled.cjs +3 -1
  54. package/dist/helpers/isFilled.cjs.map +1 -1
  55. package/dist/helpers/isFilled.d.ts +24 -20
  56. package/dist/helpers/isFilled.js +3 -1
  57. package/dist/helpers/isFilled.js.map +1 -1
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/index.d.ts +13 -3
  60. package/dist/index.js.map +1 -1
  61. package/dist/lib/appendFilters.cjs.map +1 -1
  62. package/dist/lib/appendFilters.d.ts +4 -4
  63. package/dist/lib/appendFilters.js.map +1 -1
  64. package/dist/lib/castArray.cjs.map +1 -1
  65. package/dist/lib/castArray.d.ts +1 -0
  66. package/dist/lib/castArray.js.map +1 -1
  67. package/dist/lib/castThunk.cjs.map +1 -1
  68. package/dist/lib/castThunk.d.ts +2 -1
  69. package/dist/lib/castThunk.js.map +1 -1
  70. package/dist/lib/everyTagFilter.cjs.map +1 -1
  71. package/dist/lib/everyTagFilter.d.ts +2 -2
  72. package/dist/lib/everyTagFilter.js.map +1 -1
  73. package/dist/lib/findMasterRef.cjs.map +1 -1
  74. package/dist/lib/findMasterRef.d.ts +1 -0
  75. package/dist/lib/findMasterRef.js.map +1 -1
  76. package/dist/lib/findRef.cjs.map +1 -1
  77. package/dist/lib/findRef.d.ts +3 -2
  78. package/dist/lib/findRef.js.map +1 -1
  79. package/dist/lib/findRefByID.cjs.map +1 -1
  80. package/dist/lib/findRefByID.d.ts +1 -0
  81. package/dist/lib/findRefByID.js.map +1 -1
  82. package/dist/lib/findRefByLabel.cjs.map +1 -1
  83. package/dist/lib/findRefByLabel.d.ts +1 -0
  84. package/dist/lib/findRefByLabel.js.map +1 -1
  85. package/dist/package.json.cjs +1 -1
  86. package/dist/package.json.js +1 -1
  87. package/dist/types/api/query.d.ts +1 -0
  88. package/dist/types/api/release.d.ts +1 -0
  89. package/dist/types/api/repository.d.ts +2 -2
  90. package/dist/types/api/tags.d.ts +1 -0
  91. package/dist/types/model/boolean.d.ts +1 -1
  92. package/dist/types/model/color.d.ts +1 -1
  93. package/dist/types/model/contentRelationship.d.ts +2 -3
  94. package/dist/types/model/customType.d.ts +11 -11
  95. package/dist/types/model/date.d.ts +1 -1
  96. package/dist/types/model/embed.d.ts +1 -1
  97. package/dist/types/model/geoPoint.d.ts +1 -1
  98. package/dist/types/model/group.d.ts +1 -1
  99. package/dist/types/model/image.d.ts +3 -3
  100. package/dist/types/model/{integrationFields.d.ts → integration.d.ts} +3 -3
  101. package/dist/types/model/keyText.d.ts +1 -1
  102. package/dist/types/model/link.cjs.map +1 -1
  103. package/dist/types/model/link.d.ts +4 -6
  104. package/dist/types/model/link.js.map +1 -1
  105. package/dist/types/model/linkToMedia.d.ts +2 -3
  106. package/dist/types/model/number.d.ts +1 -1
  107. package/dist/types/model/richText.d.ts +3 -3
  108. package/dist/types/model/select.d.ts +1 -1
  109. package/dist/types/model/sharedSlice.d.ts +2 -2
  110. package/dist/types/model/sharedSliceVariation.d.ts +1 -1
  111. package/dist/types/model/slice.cjs.map +1 -1
  112. package/dist/types/model/slice.d.ts +1 -1
  113. package/dist/types/model/slice.js.map +1 -1
  114. package/dist/types/model/sliceZone.cjs.map +1 -1
  115. package/dist/types/model/sliceZone.d.ts +2 -2
  116. package/dist/types/model/sliceZone.js.map +1 -1
  117. package/dist/types/model/timestamp.d.ts +1 -1
  118. package/dist/types/model/title.d.ts +1 -1
  119. package/dist/types/model/types.cjs +5 -1
  120. package/dist/types/model/types.cjs.map +1 -1
  121. package/dist/types/model/types.d.ts +10 -6
  122. package/dist/types/model/types.js +5 -1
  123. package/dist/types/model/types.js.map +1 -1
  124. package/dist/types/model/uid.d.ts +1 -1
  125. package/dist/types/value/boolean.d.ts +1 -1
  126. package/dist/types/value/color.d.ts +2 -1
  127. package/dist/types/value/contentRelationship.d.ts +1 -1
  128. package/dist/types/value/date.d.ts +2 -1
  129. package/dist/types/value/document.d.ts +4 -4
  130. package/dist/types/value/embed.cjs.map +1 -1
  131. package/dist/types/value/embed.d.ts +2 -1
  132. package/dist/types/value/embed.js.map +1 -1
  133. package/dist/types/value/geoPoint.d.ts +2 -1
  134. package/dist/types/value/group.d.ts +1 -1
  135. package/dist/types/value/image.d.ts +5 -3
  136. package/dist/types/value/{integrationFields.d.ts → integration.d.ts} +3 -2
  137. package/dist/types/value/keyText.d.ts +2 -1
  138. package/dist/types/value/link.cjs.map +1 -1
  139. package/dist/types/value/link.d.ts +2 -2
  140. package/dist/types/value/link.js.map +1 -1
  141. package/dist/types/value/linkToMedia.d.ts +2 -2
  142. package/dist/types/value/number.d.ts +2 -1
  143. package/dist/types/value/richText.cjs.map +1 -1
  144. package/dist/types/value/richText.d.ts +26 -26
  145. package/dist/types/value/richText.js.map +1 -1
  146. package/dist/types/value/select.d.ts +2 -1
  147. package/dist/types/value/sharedSlice.d.ts +1 -1
  148. package/dist/types/value/sharedSliceVariation.d.ts +3 -0
  149. package/dist/types/value/slice.d.ts +1 -1
  150. package/dist/types/value/timestamp.d.ts +1 -1
  151. package/dist/types/value/title.d.ts +1 -1
  152. package/dist/types/value/types.d.ts +3 -2
  153. package/dist/types/webhook/apiUpdate.d.ts +1 -1
  154. package/package.json +4 -4
  155. package/src/buildQueryURL.ts +15 -14
  156. package/src/createClient.ts +112 -55
  157. package/src/filter.ts +43 -43
  158. package/src/getGraphQLEndpoint.ts +1 -0
  159. package/src/getRepositoryEndpoint.ts +2 -0
  160. package/src/getRepositoryName.ts +1 -0
  161. package/src/getToolbarSrc.ts +1 -1
  162. package/src/helpers/asDate.ts +3 -2
  163. package/src/helpers/asHTML.ts +36 -30
  164. package/src/helpers/asImagePixelDensitySrcSet.ts +5 -5
  165. package/src/helpers/asImageSrc.ts +3 -3
  166. package/src/helpers/asImageWidthSrcSet.ts +6 -6
  167. package/src/helpers/asLink.ts +36 -27
  168. package/src/helpers/asLinkAttrs.ts +12 -7
  169. package/src/helpers/asText.ts +18 -14
  170. package/src/helpers/documentToLinkField.ts +3 -1
  171. package/src/helpers/isFilled.ts +27 -22
  172. package/src/index.ts +20 -3
  173. package/src/lib/appendFilters.ts +4 -4
  174. package/src/lib/castArray.ts +1 -0
  175. package/src/lib/castThunk.ts +9 -2
  176. package/src/lib/everyTagFilter.ts +2 -2
  177. package/src/lib/findMasterRef.ts +1 -0
  178. package/src/lib/findRef.ts +3 -2
  179. package/src/lib/findRefByID.ts +1 -0
  180. package/src/lib/findRefByLabel.ts +1 -0
  181. package/src/types/api/query.ts +1 -0
  182. package/src/types/api/release.ts +1 -0
  183. package/src/types/api/repository.ts +2 -2
  184. package/src/types/api/tags.ts +1 -0
  185. package/src/types/model/boolean.ts +1 -1
  186. package/src/types/model/color.ts +1 -1
  187. package/src/types/model/contentRelationship.ts +2 -3
  188. package/src/types/model/customType.ts +11 -11
  189. package/src/types/model/date.ts +1 -1
  190. package/src/types/model/embed.ts +1 -1
  191. package/src/types/model/geoPoint.ts +1 -1
  192. package/src/types/model/group.ts +1 -1
  193. package/src/types/model/image.ts +3 -3
  194. package/src/types/model/{integrationFields.ts → integration.ts} +3 -3
  195. package/src/types/model/keyText.ts +1 -1
  196. package/src/types/model/link.ts +4 -6
  197. package/src/types/model/linkToMedia.ts +2 -3
  198. package/src/types/model/number.ts +1 -1
  199. package/src/types/model/richText.ts +3 -3
  200. package/src/types/model/select.ts +1 -1
  201. package/src/types/model/sharedSlice.ts +2 -2
  202. package/src/types/model/sharedSliceVariation.ts +1 -1
  203. package/src/types/model/slice.ts +1 -1
  204. package/src/types/model/sliceZone.ts +2 -2
  205. package/src/types/model/timestamp.ts +1 -1
  206. package/src/types/model/title.ts +1 -1
  207. package/src/types/model/types.ts +10 -6
  208. package/src/types/model/uid.ts +1 -1
  209. package/src/types/value/boolean.ts +1 -1
  210. package/src/types/value/color.ts +2 -1
  211. package/src/types/value/contentRelationship.ts +1 -1
  212. package/src/types/value/date.ts +2 -1
  213. package/src/types/value/document.ts +4 -4
  214. package/src/types/value/embed.ts +2 -1
  215. package/src/types/value/geoPoint.ts +2 -1
  216. package/src/types/value/group.ts +1 -1
  217. package/src/types/value/image.ts +6 -4
  218. package/src/types/value/{integrationFields.ts → integration.ts} +3 -2
  219. package/src/types/value/keyText.ts +2 -1
  220. package/src/types/value/link.ts +2 -2
  221. package/src/types/value/linkToMedia.ts +2 -2
  222. package/src/types/value/number.ts +2 -1
  223. package/src/types/value/richText.ts +26 -26
  224. package/src/types/value/select.ts +2 -1
  225. package/src/types/value/sharedSlice.ts +1 -1
  226. package/src/types/value/sharedSliceVariation.ts +3 -0
  227. package/src/types/value/slice.ts +1 -1
  228. package/src/types/value/timestamp.ts +1 -1
  229. package/src/types/value/title.ts +1 -1
  230. package/src/types/value/types.ts +3 -2
  231. package/src/types/webhook/apiUpdate.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"getToolbarSrc.js","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\";\n\nimport { isRepositoryName } from \"./isRepositoryName\";\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from '@prismicio/client'\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const;\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t);\n\t}\n};\n"],"names":[],"mappings":";;AAqCa,MAAA,gBAAgB,CAC5B,mBACgF;AAC5E,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D;AAAA,EAAA,OAC3D;AACN,UAAM,IAAI,aACT,iDAAiD,kBACjD,QACA,MAAS;AAAA,EAEV;AACF;"}
1
+ {"version":3,"file":"getToolbarSrc.js","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\";\n\nimport { isRepositoryName } from \"./isRepositoryName\";\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const;\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t);\n\t}\n};\n"],"names":[],"mappings":";;AAqCa,MAAA,gBAAgB,CAC5B,mBACgF;AAC5E,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D;AAAA,EAAA,OAC3D;AACN,UAAM,IAAI,aACT,iDAAiD,kBACjD,QACA,MAAS;AAAA,EAEV;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asDate.cjs","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\";\nimport type { TimestampField } from \"../types/value/timestamp\";\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null;\n\n/**\n * Transforms a Date or Timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A Date or Timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>;\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>;\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>;\n\t}\n};\n"],"names":[],"mappings":";;AAkBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,EACP;AAGG,MAAA,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAAA,OAE/D;AAEC,WAAA,IAAI,KAAK,oBAAoB;AAAA,EACpC;AACF;;"}
1
+ {"version":3,"file":"asDate.cjs","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\";\nimport type { TimestampField } from \"../types/value/timestamp\";\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null;\n\n/**\n * Transforms a date or timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n *\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>;\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>;\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>;\n\t}\n};\n"],"names":[],"mappings":";;AAmBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,EACP;AAGG,MAAA,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAAA,OAE/D;AAEC,WAAA,IAAI,KAAK,oBAAoB;AAAA,EACpC;AACF;;"}
@@ -5,11 +5,12 @@ import type { TimestampField } from "../types/value/timestamp";
5
5
  */
6
6
  type AsDateReturnType<Field extends DateField | TimestampField | null | undefined> = Field extends DateField<"filled"> | TimestampField<"filled"> ? Date : null;
7
7
  /**
8
- * Transforms a Date or Timestamp field into a JavaScript Date object
8
+ * Transforms a date or timestamp field into a JavaScript Date object
9
9
  *
10
- * @param dateOrTimestampField - A Date or Timestamp field from Prismic
10
+ * @param dateOrTimestampField - A date or timestamp field from Prismic
11
11
  *
12
12
  * @returns A Date object, null if provided date is falsy
13
+ *
13
14
  * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}
14
15
  */
15
16
  export declare const asDate: <Field extends `${number}-${number}-${number}` | `${number}-${number}-${number}T${number}:${number}:${number}+${number}` | null | undefined>(dateOrTimestampField: Field) => AsDateReturnType<Field>;
@@ -1 +1 @@
1
- {"version":3,"file":"asDate.js","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\";\nimport type { TimestampField } from \"../types/value/timestamp\";\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null;\n\n/**\n * Transforms a Date or Timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A Date or Timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>;\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>;\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>;\n\t}\n};\n"],"names":[],"mappings":"AAkBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,EACP;AAGG,MAAA,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAAA,OAE/D;AAEC,WAAA,IAAI,KAAK,oBAAoB;AAAA,EACpC;AACF;"}
1
+ {"version":3,"file":"asDate.js","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\";\nimport type { TimestampField } from \"../types/value/timestamp\";\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null;\n\n/**\n * Transforms a date or timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n *\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>;\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>;\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>;\n\t}\n};\n"],"names":[],"mappings":"AAmBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,EACP;AAGG,MAAA,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAAA,OAE/D;AAEC,WAAA,IAAI,KAAK,oBAAoB;AAAA,EACpC;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asHTML.cjs","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tElement,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n} from \"@prismicio/richtext\";\n\nimport {\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 { 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/richtext` function serializer, this serializer\n * converts the `children` argument to a single string rather than an array of\n * 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/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * 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 HTMLRichTextMapSerializer = {\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany\n>\n\t? U\n\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U\n>\n\t? U\n\t: never;\n\n/**\n * Serializes a node from a Rich Text or Title field with a map or a function to 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 default HTML Rich Text Serializer with a given Link Resolver providing\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createDefaultHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n): RichTextFunctionSerializer<string> => {\n\treturn (_type, node, text, children, _key) => {\n\t\tswitch (node.type) {\n\t\t\tcase Element.heading1:\n\t\t\t\treturn serializeStandardTag(\"h1\", node, children);\n\t\t\tcase Element.heading2:\n\t\t\t\treturn serializeStandardTag(\"h2\", node, children);\n\t\t\tcase Element.heading3:\n\t\t\t\treturn serializeStandardTag(\"h3\", node, children);\n\t\t\tcase Element.heading4:\n\t\t\t\treturn serializeStandardTag(\"h4\", node, children);\n\t\t\tcase Element.heading5:\n\t\t\t\treturn serializeStandardTag(\"h5\", node, children);\n\t\t\tcase Element.heading6:\n\t\t\t\treturn serializeStandardTag(\"h6\", node, children);\n\t\t\tcase Element.paragraph:\n\t\t\t\treturn serializeStandardTag(\"p\", node, children);\n\t\t\tcase Element.preformatted:\n\t\t\t\treturn serializePreFormatted(node);\n\t\t\tcase Element.strong:\n\t\t\t\treturn serializeStandardTag(\"strong\", node, children);\n\t\t\tcase Element.em:\n\t\t\t\treturn serializeStandardTag(\"em\", node, children);\n\t\t\tcase Element.listItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.oListItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.list:\n\t\t\t\treturn serializeStandardTag(\"ul\", node, children);\n\t\t\tcase Element.oList:\n\t\t\t\treturn serializeStandardTag(\"ol\", node, children);\n\t\t\tcase Element.image:\n\t\t\t\treturn serializeImage(linkResolver, node);\n\t\t\tcase Element.embed:\n\t\t\t\treturn serializeEmbed(node);\n\t\t\tcase Element.hyperlink:\n\t\t\t\treturn serializeHyperlink(linkResolver, node, children);\n\t\t\tcase Element.label:\n\t\t\t\treturn serializeStandardTag(\"span\", node, children);\n\t\t\tcase Element.span:\n\t\t\tdefault:\n\t\t\t\treturn serializeSpan(text);\n\t\t}\n\t};\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/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLRichTextMapSerializer,\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.\n\t * Without it you're 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 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 * @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 * @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 fallback\n\t * to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided Rich Text or Title field\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 * @deprecated Use object-style configuration instead.\n\t *\n\t * ```ts\n\t * asHTML(field);\n\t * asHTML(field, { linkResolver });\n\t * asHTML(field, { serializer });\n\t * asHTML(field, { linkResolver, serializer });\n\t * ```\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\tserializer = composeSerializers(\n\t\t\t\ttypeof config.serializer === \"object\"\n\t\t\t\t\t? wrapMapSerializerWithStringChildren(config.serializer)\n\t\t\t\t\t: (type, node, text, children, key) =>\n\t\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\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t),\n\t\t\t\tcreateDefaultHTMLRichTextSerializer(config.linkResolver),\n\t\t\t);\n\t\t} else {\n\t\t\tserializer = createDefaultHTMLRichTextSerializer(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":["Element","serializeStandardTag","serializePreFormatted","serializeImage","serializeEmbed","serializeHyperlink","serializeSpan","wrapMapSerializer","composeSerializers","serialize"],"mappings":";;;;AA2HA,MAAM,sCAAsC,CAC3C,iBACuC;AACvC,SAAO,CAAC,OAAO,MAAM,MAAM,UAAU,SAAQ;AAC5C,YAAQ,KAAK,MAAM;AAAA,MAClB,KAAKA,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,KAAK,MAAM,QAAQ;AAAA,MAChD,KAAKD,SAAQ,QAAA;AACZ,eAAOE,kBAAAA,sBAAsB,IAAI;AAAA,MAClC,KAAKF,SAAQ,QAAA;AACL,eAAAC,uCAAqB,UAAU,MAAM,QAAQ;AAAA,MACrD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAG,kBAAA,eAAe,cAAc,IAAI;AAAA,MACzC,KAAKH,SAAQ,QAAA;AACZ,eAAOI,kBAAAA,eAAe,IAAI;AAAA,MAC3B,KAAKJ,SAAQ,QAAA;AACL,eAAAK,qCAAmB,cAAc,MAAM,QAAQ;AAAA,MACvD,KAAKL,SAAQ,QAAA;AACL,eAAAC,uCAAqB,QAAQ,MAAM,QAAQ;AAAA,MACnD,KAAKD,SAAAA,QAAQ;AAAA,MACb;AACC,eAAOM,kBAAAA,cAAc,IAAI;AAAA,IAC1B;AAAA,EAAA;AAEH;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,MAAA;AAAA,IAEF;AAAA,EACD;AAED,SAAOC,SAAAA,kBAAkB,qBAAqB;AAC/C;AAkCa,MAAA,SAwCT,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,MAAA;AAAA,WAEP;AACG,eAAA,EAAE,GAAG;IACd;AAEG,QAAA;AACJ,QAAI,OAAO,YAAY;AACtB,mBAAaC,SAAAA,mBACZ,OAAO,OAAO,eAAe,WAC1B,oCAAoC,OAAO,UAAU,IACrD,CAAC,MAAM,MAAM,MAAM,UAAU;AAAA;AAAA,QAE5B,OAAO,WACP,MACA,MACA,MACA,SAAS,KAAK,EAAE,GAChB,GAAG;AAAA,SAEP,oCAAoC,OAAO,YAAY,CAAC;AAAA,IAAA,OAEnD;AACO,mBAAA,oCAAoC,OAAO,YAAY;AAAA,IACpE;AAED,WAAOC,SAAAA,UAAU,eAAe,UAAU,EAAE,KAC3C,EAAE;AAAA,EAAA,OAEG;AACC,WAAA;AAAA,EACP;AACF;;"}
1
+ {"version":3,"file":"asHTML.cjs","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tElement,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n} from \"@prismicio/richtext\";\n\nimport {\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 { 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/richtext` function serializer, this serializer\n * converts the `children` argument to a single string rather than an array of\n * 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/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * 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 HTMLRichTextMapSerializer = {\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany\n>\n\t? U\n\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U\n>\n\t? U\n\t: never;\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 default HTML rich text serializer with a given link resolver\n * providing sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createDefaultHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n): RichTextFunctionSerializer<string> => {\n\treturn (_type, node, text, children, _key) => {\n\t\tswitch (node.type) {\n\t\t\tcase Element.heading1:\n\t\t\t\treturn serializeStandardTag(\"h1\", node, children);\n\t\t\tcase Element.heading2:\n\t\t\t\treturn serializeStandardTag(\"h2\", node, children);\n\t\t\tcase Element.heading3:\n\t\t\t\treturn serializeStandardTag(\"h3\", node, children);\n\t\t\tcase Element.heading4:\n\t\t\t\treturn serializeStandardTag(\"h4\", node, children);\n\t\t\tcase Element.heading5:\n\t\t\t\treturn serializeStandardTag(\"h5\", node, children);\n\t\t\tcase Element.heading6:\n\t\t\t\treturn serializeStandardTag(\"h6\", node, children);\n\t\t\tcase Element.paragraph:\n\t\t\t\treturn serializeStandardTag(\"p\", node, children);\n\t\t\tcase Element.preformatted:\n\t\t\t\treturn serializePreFormatted(node);\n\t\t\tcase Element.strong:\n\t\t\t\treturn serializeStandardTag(\"strong\", node, children);\n\t\t\tcase Element.em:\n\t\t\t\treturn serializeStandardTag(\"em\", node, children);\n\t\t\tcase Element.listItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.oListItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.list:\n\t\t\t\treturn serializeStandardTag(\"ul\", node, children);\n\t\t\tcase Element.oList:\n\t\t\t\treturn serializeStandardTag(\"ol\", node, children);\n\t\t\tcase Element.image:\n\t\t\t\treturn serializeImage(linkResolver, node);\n\t\t\tcase Element.embed:\n\t\t\t\treturn serializeEmbed(node);\n\t\t\tcase Element.hyperlink:\n\t\t\t\treturn serializeHyperlink(linkResolver, node, children);\n\t\t\tcase Element.label:\n\t\t\t\treturn serializeStandardTag(\"span\", node, children);\n\t\t\tcase Element.span:\n\t\t\tdefault:\n\t\t\t\treturn serializeSpan(text);\n\t\t}\n\t};\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/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLRichTextMapSerializer,\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 * @example\n\t *\n\t * ```ts\n\t * asHTML(field);\n\t * asHTML(field, { linkResolver });\n\t * asHTML(field, { serializer });\n\t * asHTML(field, { linkResolver, serializer });\n\t * ```\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\tserializer = composeSerializers(\n\t\t\t\ttypeof config.serializer === \"object\"\n\t\t\t\t\t? wrapMapSerializerWithStringChildren(config.serializer)\n\t\t\t\t\t: (type, node, text, children, key) =>\n\t\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\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t),\n\t\t\t\tcreateDefaultHTMLRichTextSerializer(config.linkResolver),\n\t\t\t);\n\t\t} else {\n\t\t\tserializer = createDefaultHTMLRichTextSerializer(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":["Element","serializeStandardTag","serializePreFormatted","serializeImage","serializeEmbed","serializeHyperlink","serializeSpan","wrapMapSerializer","composeSerializers","serialize"],"mappings":";;;;AA4HA,MAAM,sCAAsC,CAC3C,iBACuC;AACvC,SAAO,CAAC,OAAO,MAAM,MAAM,UAAU,SAAQ;AAC5C,YAAQ,KAAK,MAAM;AAAA,MAClB,KAAKA,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,KAAK,MAAM,QAAQ;AAAA,MAChD,KAAKD,SAAQ,QAAA;AACZ,eAAOE,kBAAAA,sBAAsB,IAAI;AAAA,MAClC,KAAKF,SAAQ,QAAA;AACL,eAAAC,uCAAqB,UAAU,MAAM,QAAQ;AAAA,MACrD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAC,uCAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAKD,SAAQ,QAAA;AACL,eAAAG,kBAAA,eAAe,cAAc,IAAI;AAAA,MACzC,KAAKH,SAAQ,QAAA;AACZ,eAAOI,kBAAAA,eAAe,IAAI;AAAA,MAC3B,KAAKJ,SAAQ,QAAA;AACL,eAAAK,qCAAmB,cAAc,MAAM,QAAQ;AAAA,MACvD,KAAKL,SAAQ,QAAA;AACL,eAAAC,uCAAqB,QAAQ,MAAM,QAAQ;AAAA,MACnD,KAAKD,SAAAA,QAAQ;AAAA,MACb;AACC,eAAOM,kBAAAA,cAAc,IAAI;AAAA,IAC1B;AAAA,EAAA;AAEH;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,MAAA;AAAA,IAEF;AAAA,EACD;AAED,SAAOC,SAAAA,kBAAkB,qBAAqB;AAC/C;AAmCa,MAAA,SA4CT,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,MAAA;AAAA,WAEP;AACG,eAAA,EAAE,GAAG;IACd;AAEG,QAAA;AACJ,QAAI,OAAO,YAAY;AACtB,mBAAaC,SAAAA,mBACZ,OAAO,OAAO,eAAe,WAC1B,oCAAoC,OAAO,UAAU,IACrD,CAAC,MAAM,MAAM,MAAM,UAAU;AAAA;AAAA,QAE5B,OAAO,WACP,MACA,MACA,MACA,SAAS,KAAK,EAAE,GAChB,GAAG;AAAA,SAEP,oCAAoC,OAAO,YAAY,CAAC;AAAA,IAAA,OAEnD;AACO,mBAAA,oCAAoC,OAAO,YAAY;AAAA,IACpE;AAED,WAAOC,SAAAA,UAAU,eAAe,UAAU,EAAE,KAC3C,EAAE;AAAA,EAAA,OAEG;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -2,23 +2,23 @@ import { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerialize
2
2
  import type { RichTextField } from "../types/value/richText";
3
3
  import { LinkResolverFunction } from "./asLink";
4
4
  /**
5
- * Serializes a node from a Rich Text or Title field with a function to HTML.
5
+ * Serializes a node from a rich text or title field with a function to HTML.
6
6
  *
7
7
  * Unlike a typical `@prismicio/richtext` function serializer, this serializer
8
8
  * converts the `children` argument to a single string rather than an array of
9
9
  * strings.
10
10
  *
11
- * @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
11
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
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 or Title field with a map to HTML
15
+ * Serializes a node from a rich text or title field with a map to HTML
16
16
  *
17
17
  * Unlike a typical `@prismicio/richtext` map serializer, this serializer
18
18
  * converts the `children` property to a single string rather than an array of
19
19
  * strings.
20
20
  *
21
- * @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
21
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
22
22
  */
23
23
  export type HTMLRichTextMapSerializer = {
24
24
  [P in keyof RichTextMapSerializer<string>]: (payload: {
@@ -33,7 +33,7 @@ export type HTMLRichTextMapSerializer = {
33
33
  * A {@link RichTextMapSerializerFunction} type specifically for
34
34
  * {@link HTMLRichTextMapSerializer}.
35
35
  *
36
- * @typeParam BlockName - The serializer's Rich Text block type.
36
+ * @typeParam BlockName - The serializer's rich text block type.
37
37
  */
38
38
  type HTMLRichTextMapSerializerFunction<BlockType extends keyof RichTextMapSerializer<string>> = RichTextMapSerializerFunction<string, ExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>, ExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>>;
39
39
  /**
@@ -51,10 +51,11 @@ type ExtractNodeGeneric<T> = T extends RichTextMapSerializerFunction<any, infer
51
51
  */
52
52
  type ExtractTextTypeGeneric<T> = T extends RichTextMapSerializerFunction<any, any, infer U> ? U : never;
53
53
  /**
54
- * Serializes a node from a Rich Text or Title field with a map or a function to HTML
54
+ * Serializes a node from a rich text or title field with a map or a function to
55
+ * HTML
55
56
  *
56
57
  * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}
57
- * @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
58
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
58
59
  */
59
60
  export type HTMLRichTextSerializer = HTMLRichTextMapSerializer | HTMLRichTextFunctionSerializer;
60
61
  /**
@@ -62,12 +63,13 @@ export type HTMLRichTextSerializer = HTMLRichTextMapSerializer | HTMLRichTextFun
62
63
  */
63
64
  type AsHTMLConfig = {
64
65
  /**
65
- * An optional link resolver function to resolve links.
66
- * Without it you're expected to use the `routes` options from the API.
66
+ * An optional link resolver function to resolve links. Without it you're
67
+ * expected to use the `routes` options from the API.
67
68
  */
68
69
  linkResolver?: LinkResolverFunction | null;
69
70
  /**
70
- * An optional Rich Text Serializer, unhandled cases will fallback to the default serializer
71
+ * An optional rich text serializer, unhandled cases will fallback to the
72
+ * default serializer
71
73
  */
72
74
  serializer?: HTMLRichTextSerializer | null;
73
75
  };
@@ -84,35 +86,39 @@ type AsHTMLDeprecatedTupleConfig = [
84
86
  type AsHTMLReturnType<Field extends RichTextField | null | undefined> = Field extends RichTextField ? string : null;
85
87
  export declare const asHTML: {
86
88
  /**
87
- * Serializes a Rich Text or Title field to an HTML string.
89
+ * Serializes a rich text or title field to an HTML string.
88
90
  *
89
- * @param richTextField - A Rich Text or Title field from Prismic
91
+ * @example
92
+ *
93
+ * ```ts
94
+ * asHTML(field);
95
+ * asHTML(field, { linkResolver });
96
+ * asHTML(field, { serializer });
97
+ * asHTML(field, { linkResolver, serializer });
98
+ * ```
99
+ *
100
+ * @param richTextField - A rich text or title field from Prismic
90
101
  * @param config - Configuration that determines the output of `asHTML()`
91
102
  *
92
- * @returns HTML equivalent of the provided Rich Text or Title field
93
- * @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
103
+ * @returns HTML equivalent of the provided rich text or title field
104
+ *
105
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
94
106
  */
95
107
  <Field extends RichTextField | null | undefined>(richTextField: Field, config?: AsHTMLConfig): AsHTMLReturnType<Field>;
96
108
  /**
97
- * Serializes a Rich Text or Title field to an HTML string.
109
+ * Serializes a rich text or title field to an HTML string.
98
110
  *
99
- * @param richTextField - A Rich Text or Title field from Prismic
111
+ * @deprecated Use object-style configuration instead.
112
+ *
113
+ * @param richTextField - A rich text or title field from Prismic
100
114
  * @param linkResolver - An optional link resolver function to resolve links,
101
115
  * without it you're expected to use the `routes` options from the API
102
- * @param serializer - An optional Rich Text Serializer, unhandled cases will fallback
103
- * to the default serializer
104
- *
105
- * @returns HTML equivalent of the provided Rich Text or Title field
106
- * @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
116
+ * @param serializer - An optional rich text serializer, unhandled cases will
117
+ * fallback to the default serializer
107
118
  *
108
- * @deprecated Use object-style configuration instead.
119
+ * @returns HTML equivalent of the provided rich text or title field
109
120
  *
110
- * ```ts
111
- * asHTML(field);
112
- * asHTML(field, { linkResolver });
113
- * asHTML(field, { serializer });
114
- * asHTML(field, { linkResolver, serializer });
115
- * ```
121
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}
116
122
  */
117
123
  <Field extends RichTextField | null | undefined>(richTextField: Field, ...config: AsHTMLDeprecatedTupleConfig): AsHTMLReturnType<Field>;
118
124
  };
@@ -1 +1 @@
1
- {"version":3,"file":"asHTML.js","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tElement,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n} from \"@prismicio/richtext\";\n\nimport {\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 { 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/richtext` function serializer, this serializer\n * converts the `children` argument to a single string rather than an array of\n * 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/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * 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 HTMLRichTextMapSerializer = {\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany\n>\n\t? U\n\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U\n>\n\t? U\n\t: never;\n\n/**\n * Serializes a node from a Rich Text or Title field with a map or a function to 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 default HTML Rich Text Serializer with a given Link Resolver providing\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createDefaultHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n): RichTextFunctionSerializer<string> => {\n\treturn (_type, node, text, children, _key) => {\n\t\tswitch (node.type) {\n\t\t\tcase Element.heading1:\n\t\t\t\treturn serializeStandardTag(\"h1\", node, children);\n\t\t\tcase Element.heading2:\n\t\t\t\treturn serializeStandardTag(\"h2\", node, children);\n\t\t\tcase Element.heading3:\n\t\t\t\treturn serializeStandardTag(\"h3\", node, children);\n\t\t\tcase Element.heading4:\n\t\t\t\treturn serializeStandardTag(\"h4\", node, children);\n\t\t\tcase Element.heading5:\n\t\t\t\treturn serializeStandardTag(\"h5\", node, children);\n\t\t\tcase Element.heading6:\n\t\t\t\treturn serializeStandardTag(\"h6\", node, children);\n\t\t\tcase Element.paragraph:\n\t\t\t\treturn serializeStandardTag(\"p\", node, children);\n\t\t\tcase Element.preformatted:\n\t\t\t\treturn serializePreFormatted(node);\n\t\t\tcase Element.strong:\n\t\t\t\treturn serializeStandardTag(\"strong\", node, children);\n\t\t\tcase Element.em:\n\t\t\t\treturn serializeStandardTag(\"em\", node, children);\n\t\t\tcase Element.listItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.oListItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.list:\n\t\t\t\treturn serializeStandardTag(\"ul\", node, children);\n\t\t\tcase Element.oList:\n\t\t\t\treturn serializeStandardTag(\"ol\", node, children);\n\t\t\tcase Element.image:\n\t\t\t\treturn serializeImage(linkResolver, node);\n\t\t\tcase Element.embed:\n\t\t\t\treturn serializeEmbed(node);\n\t\t\tcase Element.hyperlink:\n\t\t\t\treturn serializeHyperlink(linkResolver, node, children);\n\t\t\tcase Element.label:\n\t\t\t\treturn serializeStandardTag(\"span\", node, children);\n\t\t\tcase Element.span:\n\t\t\tdefault:\n\t\t\t\treturn serializeSpan(text);\n\t\t}\n\t};\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/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLRichTextMapSerializer,\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.\n\t * Without it you're 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 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 * @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 * @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 fallback\n\t * to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided Rich Text or Title field\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 * @deprecated Use object-style configuration instead.\n\t *\n\t * ```ts\n\t * asHTML(field);\n\t * asHTML(field, { linkResolver });\n\t * asHTML(field, { serializer });\n\t * asHTML(field, { linkResolver, serializer });\n\t * ```\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\tserializer = composeSerializers(\n\t\t\t\ttypeof config.serializer === \"object\"\n\t\t\t\t\t? wrapMapSerializerWithStringChildren(config.serializer)\n\t\t\t\t\t: (type, node, text, children, key) =>\n\t\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\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t),\n\t\t\t\tcreateDefaultHTMLRichTextSerializer(config.linkResolver),\n\t\t\t);\n\t\t} else {\n\t\t\tserializer = createDefaultHTMLRichTextSerializer(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":";;AA2HA,MAAM,sCAAsC,CAC3C,iBACuC;AACvC,SAAO,CAAC,OAAO,MAAM,MAAM,UAAU,SAAQ;AAC5C,YAAQ,KAAK,MAAM;AAAA,MAClB,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,KAAK,MAAM,QAAQ;AAAA,MAChD,KAAK,QAAQ;AACZ,eAAO,sBAAsB,IAAI;AAAA,MAClC,KAAK,QAAQ;AACL,eAAA,qBAAqB,UAAU,MAAM,QAAQ;AAAA,MACrD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,eAAe,cAAc,IAAI;AAAA,MACzC,KAAK,QAAQ;AACZ,eAAO,eAAe,IAAI;AAAA,MAC3B,KAAK,QAAQ;AACL,eAAA,mBAAmB,cAAc,MAAM,QAAQ;AAAA,MACvD,KAAK,QAAQ;AACL,eAAA,qBAAqB,QAAQ,MAAM,QAAQ;AAAA,MACnD,KAAK,QAAQ;AAAA,MACb;AACC,eAAO,cAAc,IAAI;AAAA,IAC1B;AAAA,EAAA;AAEH;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,MAAA;AAAA,IAEF;AAAA,EACD;AAED,SAAO,kBAAkB,qBAAqB;AAC/C;AAkCa,MAAA,SAwCT,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,MAAA;AAAA,WAEP;AACG,eAAA,EAAE,GAAG;IACd;AAEG,QAAA;AACJ,QAAI,OAAO,YAAY;AACtB,mBAAa,mBACZ,OAAO,OAAO,eAAe,WAC1B,oCAAoC,OAAO,UAAU,IACrD,CAAC,MAAM,MAAM,MAAM,UAAU;AAAA;AAAA,QAE5B,OAAO,WACP,MACA,MACA,MACA,SAAS,KAAK,EAAE,GAChB,GAAG;AAAA,SAEP,oCAAoC,OAAO,YAAY,CAAC;AAAA,IAAA,OAEnD;AACO,mBAAA,oCAAoC,OAAO,YAAY;AAAA,IACpE;AAED,WAAO,UAAU,eAAe,UAAU,EAAE,KAC3C,EAAE;AAAA,EAAA,OAEG;AACC,WAAA;AAAA,EACP;AACF;"}
1
+ {"version":3,"file":"asHTML.js","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tElement,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n} from \"@prismicio/richtext\";\n\nimport {\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 { 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/richtext` function serializer, this serializer\n * converts the `children` argument to a single string rather than an array of\n * 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/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * 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 HTMLRichTextMapSerializer = {\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany\n>\n\t? U\n\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> = T extends RichTextMapSerializerFunction<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tinfer U\n>\n\t? U\n\t: never;\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 default HTML rich text serializer with a given link resolver\n * providing sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createDefaultHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n): RichTextFunctionSerializer<string> => {\n\treturn (_type, node, text, children, _key) => {\n\t\tswitch (node.type) {\n\t\t\tcase Element.heading1:\n\t\t\t\treturn serializeStandardTag(\"h1\", node, children);\n\t\t\tcase Element.heading2:\n\t\t\t\treturn serializeStandardTag(\"h2\", node, children);\n\t\t\tcase Element.heading3:\n\t\t\t\treturn serializeStandardTag(\"h3\", node, children);\n\t\t\tcase Element.heading4:\n\t\t\t\treturn serializeStandardTag(\"h4\", node, children);\n\t\t\tcase Element.heading5:\n\t\t\t\treturn serializeStandardTag(\"h5\", node, children);\n\t\t\tcase Element.heading6:\n\t\t\t\treturn serializeStandardTag(\"h6\", node, children);\n\t\t\tcase Element.paragraph:\n\t\t\t\treturn serializeStandardTag(\"p\", node, children);\n\t\t\tcase Element.preformatted:\n\t\t\t\treturn serializePreFormatted(node);\n\t\t\tcase Element.strong:\n\t\t\t\treturn serializeStandardTag(\"strong\", node, children);\n\t\t\tcase Element.em:\n\t\t\t\treturn serializeStandardTag(\"em\", node, children);\n\t\t\tcase Element.listItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.oListItem:\n\t\t\t\treturn serializeStandardTag(\"li\", node, children);\n\t\t\tcase Element.list:\n\t\t\t\treturn serializeStandardTag(\"ul\", node, children);\n\t\t\tcase Element.oList:\n\t\t\t\treturn serializeStandardTag(\"ol\", node, children);\n\t\t\tcase Element.image:\n\t\t\t\treturn serializeImage(linkResolver, node);\n\t\t\tcase Element.embed:\n\t\t\t\treturn serializeEmbed(node);\n\t\t\tcase Element.hyperlink:\n\t\t\t\treturn serializeHyperlink(linkResolver, node, children);\n\t\t\tcase Element.label:\n\t\t\t\treturn serializeStandardTag(\"span\", node, children);\n\t\t\tcase Element.span:\n\t\t\tdefault:\n\t\t\t\treturn serializeSpan(text);\n\t\t}\n\t};\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/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLRichTextMapSerializer,\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 * @example\n\t *\n\t * ```ts\n\t * asHTML(field);\n\t * asHTML(field, { linkResolver });\n\t * asHTML(field, { serializer });\n\t * asHTML(field, { linkResolver, serializer });\n\t * ```\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\tserializer = composeSerializers(\n\t\t\t\ttypeof config.serializer === \"object\"\n\t\t\t\t\t? wrapMapSerializerWithStringChildren(config.serializer)\n\t\t\t\t\t: (type, node, text, children, key) =>\n\t\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\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t),\n\t\t\t\tcreateDefaultHTMLRichTextSerializer(config.linkResolver),\n\t\t\t);\n\t\t} else {\n\t\t\tserializer = createDefaultHTMLRichTextSerializer(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":";;AA4HA,MAAM,sCAAsC,CAC3C,iBACuC;AACvC,SAAO,CAAC,OAAO,MAAM,MAAM,UAAU,SAAQ;AAC5C,YAAQ,KAAK,MAAM;AAAA,MAClB,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,KAAK,MAAM,QAAQ;AAAA,MAChD,KAAK,QAAQ;AACZ,eAAO,sBAAsB,IAAI;AAAA,MAClC,KAAK,QAAQ;AACL,eAAA,qBAAqB,UAAU,MAAM,QAAQ;AAAA,MACrD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,qBAAqB,MAAM,MAAM,QAAQ;AAAA,MACjD,KAAK,QAAQ;AACL,eAAA,eAAe,cAAc,IAAI;AAAA,MACzC,KAAK,QAAQ;AACZ,eAAO,eAAe,IAAI;AAAA,MAC3B,KAAK,QAAQ;AACL,eAAA,mBAAmB,cAAc,MAAM,QAAQ;AAAA,MACvD,KAAK,QAAQ;AACL,eAAA,qBAAqB,QAAQ,MAAM,QAAQ;AAAA,MACnD,KAAK,QAAQ;AAAA,MACb;AACC,eAAO,cAAc,IAAI;AAAA,IAC1B;AAAA,EAAA;AAEH;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,MAAA;AAAA,IAEF;AAAA,EACD;AAED,SAAO,kBAAkB,qBAAqB;AAC/C;AAmCa,MAAA,SA4CT,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,MAAA;AAAA,WAEP;AACG,eAAA,EAAE,GAAG;IACd;AAEG,QAAA;AACJ,QAAI,OAAO,YAAY;AACtB,mBAAa,mBACZ,OAAO,OAAO,eAAe,WAC1B,oCAAoC,OAAO,UAAU,IACrD,CAAC,MAAM,MAAM,MAAM,UAAU;AAAA;AAAA,QAE5B,OAAO,WACP,MACA,MACA,MACA,SAAS,KAAK,EAAE,GAChB,GAAG;AAAA,SAEP,oCAAoC,OAAO,YAAY,CAAC;AAAA,IAAA,OAEnD;AACO,mBAAA,oCAAoC,OAAO,YAAY;AAAA,IACpE;AAED,WAAO,UAAU,eAAe,UAAU,EAAE,KAC3C,EAAE;AAAA,EAAA,OAEG;AACC,WAAA;AAAA,EACP;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import {\n\tBuildPixelDensitySrcSetParams,\n\tbuildPixelDensitySrcSet,\n\tbuildURL,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The Image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A pixel-densitye-based `srcset` attribute value for the Image field's\n\t\t\t * image with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for the Image field with Imgix URL\n * parameters (if given). If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;;;AAaA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AA6DjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,wBAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAE9D,WAAA;AAAA,MACN,KAAKC,gBAAA,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQC,gBAAAA,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,SAEI;AACC,WAAA;AAAA,EACP;AACF;;"}
1
+ {"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import {\n\tBuildPixelDensitySrcSetParams,\n\tbuildPixelDensitySrcSet,\n\tbuildURL,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A pixel-densitye-based `srcset` attribute value for the image field's\n\t\t\t * image with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for the image field with Imgix URL\n * parameters (if given). If the image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;;;AAaA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AA6DjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,wBAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAE9D,WAAA;AAAA,MACN,KAAKC,gBAAA,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQC,gBAAAA,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,SAEI;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -9,17 +9,17 @@ 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 image URL with Imgix URL parameters (if given).
12
+ * The image field's image URL with Imgix URL parameters (if given).
13
13
  */
14
14
  src: string;
15
15
  /**
16
- * A pixel-densitye-based `srcset` attribute value for the Image field's
16
+ * A pixel-densitye-based `srcset` attribute value for the image field's
17
17
  * image with Imgix URL parameters (if given).
18
18
  */
19
19
  srcset: string;
20
20
  } : null;
21
21
  /**
22
- * Creates a pixel-density-based `srcset` from an Image field with optional
22
+ * Creates a pixel-density-based `srcset` from an image field with optional
23
23
  * image transformations (via Imgix URL parameters).
24
24
  *
25
25
  * If a `pixelDensities` parameter is not given, the following pixel densities
@@ -44,8 +44,8 @@ type AsImagePixelDensitySrcSetReturnType<Field extends ImageFieldImage | null |
44
44
  * @param config - An object of Imgix URL API parameters. The `pixelDensities`
45
45
  * parameter defines the resulting `srcset` widths.
46
46
  *
47
- * @returns A `srcset` attribute value for the Image field with Imgix URL
48
- * parameters (if given). If the Image field is empty, `null` is returned.
47
+ * @returns A `srcset` attribute value for the image field with Imgix URL
48
+ * parameters (if given). If the image field is empty, `null` is returned.
49
49
  * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
50
50
  */
51
51
  export declare const asImagePixelDensitySrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImagePixelDensitySrcSetConfig) => AsImagePixelDensitySrcSetReturnType<Field>;
@@ -1 +1 @@
1
- {"version":3,"file":"asImagePixelDensitySrcSet.js","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import {\n\tBuildPixelDensitySrcSetParams,\n\tbuildPixelDensitySrcSet,\n\tbuildURL,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The Image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A pixel-densitye-based `srcset` attribute value for the Image field's\n\t\t\t * image with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for the Image field with Imgix URL\n * parameters (if given). If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;AAaA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AA6DjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,eAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAE9D,WAAA;AAAA,MACN,KAAK,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQ,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,SAEI;AACC,WAAA;AAAA,EACP;AACF;"}
1
+ {"version":3,"file":"asImagePixelDensitySrcSet.js","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import {\n\tBuildPixelDensitySrcSetParams,\n\tbuildPixelDensitySrcSet,\n\tbuildURL,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A pixel-densitye-based `srcset` attribute value for the image field's\n\t\t\t * image with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for the image field with Imgix URL\n * parameters (if given). If the image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;AAaA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AA6DjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,eAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAE9D,WAAA;AAAA,MACN,KAAK,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQ,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,SAEI;AACC,WAAA;AAAA,EACP;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asImageSrc.cjs","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import { ImgixURLParams, 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.imageField, { sat: -100 });\n * // => https://images.prismic.io/repo/image.png?sat=-100\n * ```\n *\n * @param field - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters to transform the image.\n *\n * @returns The Image field's image URL with transformations applied (if given).\n * If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;;;AA+BO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,wBAAuB,KAAK,GAAG;AACpC,WAAAC,yBAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EACP;AACF;;"}
1
+ {"version":3,"file":"asImageSrc.cjs","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import { ImgixURLParams, 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.imageField, { sat: -100 });\n * // => https://images.prismic.io/repo/image.png?sat=-100\n * ```\n *\n * @param field - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters to transform the image.\n *\n * @returns The image field's image URL with transformations applied (if given).\n * If the image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;;;AA+BO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,wBAAuB,KAAK,GAAG;AACpC,WAAAC,yBAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -5,7 +5,7 @@ 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 (via
8
+ * Returns the URL of an image field with optional image transformations (via
9
9
  * Imgix URL parameters).
10
10
  *
11
11
  * @example
@@ -19,8 +19,8 @@ type AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> = Fi
19
19
  * an image URL.
20
20
  * @param config - An object of Imgix URL API parameters to transform the image.
21
21
  *
22
- * @returns The Image field's image URL with transformations applied (if given).
23
- * If the Image field is empty, `null` is returned.
22
+ * @returns The image field's image URL with transformations applied (if given).
23
+ * If the image field is empty, `null` is returned.
24
24
  * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
25
25
  */
26
26
  export declare const asImageSrc: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: ImgixURLParams) => AsImageSrcReturnType<Field>;
@@ -1 +1 @@
1
- {"version":3,"file":"asImageSrc.js","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import { ImgixURLParams, 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.imageField, { sat: -100 });\n * // => https://images.prismic.io/repo/image.png?sat=-100\n * ```\n *\n * @param field - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters to transform the image.\n *\n * @returns The Image field's image URL with transformations applied (if given).\n * If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;AA+BO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,eAAuB,KAAK,GAAG;AACpC,WAAA,SAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EACP;AACF;"}
1
+ {"version":3,"file":"asImageSrc.js","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import { ImgixURLParams, 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.imageField, { sat: -100 });\n * // => https://images.prismic.io/repo/image.png?sat=-100\n * ```\n *\n * @param field - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param config - An object of Imgix URL API parameters to transform the image.\n *\n * @returns The image field's image URL with transformations applied (if given).\n * If the image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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":";;AA+BO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,eAAuB,KAAK,GAAG;AACpC,WAAA,SAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EACP;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asImageWidthSrcSet.cjs","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import {\n\tBuildWidthSrcSetParams,\n\tbuildURL,\n\tbuildWidthSrcSet,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The Image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A width-based `srcset` attribute value for the Image field's image with\n\t\t\t * Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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 will be used by\n * 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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * 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 (if given). If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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\talt: _alt,\n\t\t\tcopyright: _copyright,\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 ].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 }),\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":";;;;AAaA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAiE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,wBAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IACA,IAAA;AACE,UAAA,EACL,KACA,YACA,KAAK,MACL,WAAW,YACX,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IACT;AAEM,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,UAAA,CACD;AAAA,UACC,KAAK,IAAI,IACXA,gBAAAA,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACC;AAAA;AAAA,IAAA;AAAA,SAEA;AACC,WAAA;AAAA,EACP;AACF;;"}
1
+ {"version":3,"file":"asImageWidthSrcSet.cjs","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import {\n\tBuildWidthSrcSetParams,\n\tbuildURL,\n\tbuildWidthSrcSet,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A width-based `srcset` attribute value for the image field's image with\n\t\t\t * Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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 will be used by\n * 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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * 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 (if given). If the image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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\talt: _alt,\n\t\t\tcopyright: _copyright,\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 ].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 }),\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":";;;;AAaA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAiE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,wBAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IACA,IAAA;AACE,UAAA,EACL,KACA,YACA,KAAK,MACL,WAAW,YACX,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IACT;AAEM,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,UAAA,CACD;AAAA,UACC,KAAK,IAAI,IACXA,gBAAAA,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACC;AAAA;AAAA,IAAA;AAAA,SAEA;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -5,11 +5,11 @@ 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 image URL with Imgix URL parameters (if given).
8
+ * The image field's image 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's image with
12
+ * A width-based `srcset` attribute value for the image field's image with
13
13
  * Imgix URL parameters (if given).
14
14
  */
15
15
  srcset: string;
@@ -21,13 +21,13 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
21
21
  widths?: "thumbnails" | BuildWidthSrcSetParams["widths"];
22
22
  };
23
23
  /**
24
- * Creates a width-based `srcset` from an Image field with optional image
24
+ * Creates a width-based `srcset` from an image field with optional image
25
25
  * transformations (via Imgix URL parameters).
26
26
  *
27
27
  * If a `widths` parameter is not given, the following widths will be used by
28
28
  * default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
29
29
  *
30
- * If the Image field contains responsive views, each responsive view can be
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
32
32
  * `widths` parameter.
33
33
  *
@@ -52,8 +52,8 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
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 Imgix URL
56
- * parameters (if given). If the Image field is empty, `null` is returned.
55
+ * @returns A `srcset` attribute value for the image field with Imgix URL
56
+ * parameters (if given). If the image field is empty, `null` is returned.
57
57
  * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
58
58
  */
59
59
  export declare const asImageWidthSrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImageWidthSrcSetConfig) => AsImageWidthSrcSetReturnType<Field>;
@@ -1 +1 @@
1
- {"version":3,"file":"asImageWidthSrcSet.js","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import {\n\tBuildWidthSrcSetParams,\n\tbuildURL,\n\tbuildWidthSrcSet,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The Image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A width-based `srcset` attribute value for the Image field's image with\n\t\t\t * Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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 will be used by\n * 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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * 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 (if given). If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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\talt: _alt,\n\t\t\tcopyright: _copyright,\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 ].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 }),\n\t\t} as AsImageWidthSrcSetReturnType<Field>;\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>;\n\t}\n};\n"],"names":["isFilled.imageThumbnail"],"mappings":";;AAaA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAiE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,eAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IACA,IAAA;AACE,UAAA,EACL,KACA,YACA,KAAK,MACL,WAAW,YACX,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IACT;AAEM,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,UAAA,CACD;AAAA,UACC,KAAK,IAAI,IACX,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACC;AAAA;AAAA,IAAA;AAAA,SAEA;AACC,WAAA;AAAA,EACP;AACF;"}
1
+ {"version":3,"file":"asImageWidthSrcSet.js","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import {\n\tBuildWidthSrcSetParams,\n\tbuildURL,\n\tbuildWidthSrcSet,\n} 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> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A width-based `srcset` attribute value for the image field's image with\n\t\t\t * Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\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 will be used by\n * 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.imageField, {\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 - Image field (or one of its responsive views) from which to get\n * 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 (if given). If the image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: 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\talt: _alt,\n\t\t\tcopyright: _copyright,\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 ].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 }),\n\t\t} as AsImageWidthSrcSetReturnType<Field>;\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>;\n\t}\n};\n"],"names":["isFilled.imageThumbnail"],"mappings":";;AAaA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAiE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,eAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IACA,IAAA;AACE,UAAA,EACL,KACA,YACA,KAAK,MACL,WAAW,YACX,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IACT;AAEM,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,UAAA,CACD;AAAA,UACC,KAAK,IAAI,IACX,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACC;AAAA;AAAA,IAAA;AAAA,SAEA;AACC,WAAA;AAAA,EACP;AACF;"}