@prismicio/client 7.20.2-alpha.0 → 7.20.3

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 (276) hide show
  1. package/dist/Client.cjs +120 -132
  2. package/dist/Client.cjs.map +1 -1
  3. package/dist/Client.d.ts +7 -7
  4. package/dist/Client.js +120 -132
  5. package/dist/Client.js.map +1 -1
  6. package/dist/Migration.cjs +83 -101
  7. package/dist/Migration.cjs.map +1 -1
  8. package/dist/Migration.d.ts +9 -9
  9. package/dist/Migration.js +83 -101
  10. package/dist/Migration.js.map +1 -1
  11. package/dist/WriteClient.cjs +115 -92
  12. package/dist/WriteClient.cjs.map +1 -1
  13. package/dist/WriteClient.d.ts +6 -6
  14. package/dist/WriteClient.js +115 -92
  15. package/dist/WriteClient.js.map +1 -1
  16. package/dist/buildQueryURL.cjs.map +1 -1
  17. package/dist/buildQueryURL.d.ts +29 -21
  18. package/dist/buildQueryURL.js.map +1 -1
  19. package/dist/createClient.cjs.map +1 -1
  20. package/dist/createClient.d.ts +13 -10
  21. package/dist/createClient.js.map +1 -1
  22. package/dist/createMigration.cjs.map +1 -1
  23. package/dist/createMigration.d.ts +2 -2
  24. package/dist/createMigration.js.map +1 -1
  25. package/dist/createWriteClient.cjs.map +1 -1
  26. package/dist/createWriteClient.d.ts +2 -2
  27. package/dist/errors/ForbiddenError.d.ts +1 -1
  28. package/dist/errors/InvalidDataError.d.ts +1 -1
  29. package/dist/errors/NotFoundError.d.ts +1 -1
  30. package/dist/errors/ParsingError.d.ts +1 -1
  31. package/dist/errors/PreviewTokenExpired.d.ts +1 -1
  32. package/dist/errors/PrismicError.cjs +2 -5
  33. package/dist/errors/PrismicError.cjs.map +1 -1
  34. package/dist/errors/PrismicError.js +2 -5
  35. package/dist/errors/PrismicError.js.map +1 -1
  36. package/dist/errors/RefExpiredError.d.ts +1 -1
  37. package/dist/errors/RefNotFoundError.d.ts +1 -1
  38. package/dist/errors/RepositoryNotFoundError.d.ts +1 -1
  39. package/dist/filter.cjs.map +1 -1
  40. package/dist/filter.js.map +1 -1
  41. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  42. package/dist/getGraphQLEndpoint.js.map +1 -1
  43. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  44. package/dist/getRepositoryEndpoint.d.ts +9 -2
  45. package/dist/getRepositoryEndpoint.js.map +1 -1
  46. package/dist/getRepositoryName.cjs.map +1 -1
  47. package/dist/getRepositoryName.js.map +1 -1
  48. package/dist/getToolbarSrc.cjs.map +1 -1
  49. package/dist/getToolbarSrc.js.map +1 -1
  50. package/dist/helpers/asDate.cjs.map +1 -1
  51. package/dist/helpers/asDate.d.ts +13 -6
  52. package/dist/helpers/asDate.js.map +1 -1
  53. package/dist/helpers/asHTML.cjs +22 -22
  54. package/dist/helpers/asHTML.cjs.map +1 -1
  55. package/dist/helpers/asHTML.d.ts +37 -29
  56. package/dist/helpers/asHTML.js +22 -22
  57. package/dist/helpers/asHTML.js.map +1 -1
  58. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  59. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +17 -16
  60. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  61. package/dist/helpers/asImageSrc.cjs.map +1 -1
  62. package/dist/helpers/asImageSrc.d.ts +12 -11
  63. package/dist/helpers/asImageSrc.js.map +1 -1
  64. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  65. package/dist/helpers/asImageWidthSrcSet.d.ts +19 -18
  66. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  67. package/dist/helpers/asLink.cjs.map +1 -1
  68. package/dist/helpers/asLink.d.ts +36 -35
  69. package/dist/helpers/asLink.js.map +1 -1
  70. package/dist/helpers/asLinkAttrs.cjs.map +1 -1
  71. package/dist/helpers/asLinkAttrs.d.ts +11 -14
  72. package/dist/helpers/asLinkAttrs.js.map +1 -1
  73. package/dist/helpers/asText.cjs.map +1 -1
  74. package/dist/helpers/asText.d.ts +21 -11
  75. package/dist/helpers/asText.js.map +1 -1
  76. package/dist/helpers/documentToLinkField.cjs +1 -2
  77. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  78. package/dist/helpers/documentToLinkField.d.ts +2 -2
  79. package/dist/helpers/documentToLinkField.js +1 -2
  80. package/dist/helpers/documentToLinkField.js.map +1 -1
  81. package/dist/helpers/isFilled.cjs +1 -1
  82. package/dist/helpers/isFilled.cjs.map +1 -1
  83. package/dist/helpers/isFilled.d.ts +35 -34
  84. package/dist/helpers/isFilled.js +1 -1
  85. package/dist/helpers/isFilled.js.map +1 -1
  86. package/dist/helpers/mapSliceZone.cjs.map +1 -1
  87. package/dist/helpers/mapSliceZone.d.ts +11 -11
  88. package/dist/helpers/mapSliceZone.js.map +1 -1
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.ts +120 -120
  91. package/dist/index.js.map +1 -1
  92. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  93. package/dist/isRepositoryEndpoint.d.ts +2 -2
  94. package/dist/isRepositoryEndpoint.js.map +1 -1
  95. package/dist/isRepositoryName.cjs.map +1 -1
  96. package/dist/isRepositoryName.js.map +1 -1
  97. package/dist/lib/appendFilters.cjs.map +1 -1
  98. package/dist/lib/appendFilters.js.map +1 -1
  99. package/dist/lib/castArray.cjs.map +1 -1
  100. package/dist/lib/castArray.js.map +1 -1
  101. package/dist/lib/castThunk.cjs.map +1 -1
  102. package/dist/lib/castThunk.js.map +1 -1
  103. package/dist/lib/devMsg.cjs.map +1 -1
  104. package/dist/lib/devMsg.js.map +1 -1
  105. package/dist/lib/escapeHTML.cjs.map +1 -1
  106. package/dist/lib/escapeHTML.js.map +1 -1
  107. package/dist/lib/everyTagFilter.cjs.map +1 -1
  108. package/dist/lib/everyTagFilter.js.map +1 -1
  109. package/dist/lib/findMasterRef.cjs.map +1 -1
  110. package/dist/lib/findMasterRef.d.ts +1 -1
  111. package/dist/lib/findMasterRef.js.map +1 -1
  112. package/dist/lib/findRef.cjs.map +1 -1
  113. package/dist/lib/findRef.d.ts +1 -1
  114. package/dist/lib/findRef.js.map +1 -1
  115. package/dist/lib/findRefByID.cjs.map +1 -1
  116. package/dist/lib/findRefByID.d.ts +1 -1
  117. package/dist/lib/findRefByID.js.map +1 -1
  118. package/dist/lib/findRefByLabel.cjs.map +1 -1
  119. package/dist/lib/findRefByLabel.d.ts +1 -1
  120. package/dist/lib/findRefByLabel.js.map +1 -1
  121. package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
  122. package/dist/lib/getOptionalLinkProperties.d.ts +1 -1
  123. package/dist/lib/getOptionalLinkProperties.js.map +1 -1
  124. package/dist/lib/getPreviewCookie.cjs.map +1 -1
  125. package/dist/lib/getPreviewCookie.js.map +1 -1
  126. package/dist/lib/isInternalURL.cjs.map +1 -1
  127. package/dist/lib/isInternalURL.js.map +1 -1
  128. package/dist/lib/isMigrationValue.cjs.map +1 -1
  129. package/dist/lib/isMigrationValue.d.ts +8 -8
  130. package/dist/lib/isMigrationValue.js.map +1 -1
  131. package/dist/lib/isValue.cjs.map +1 -1
  132. package/dist/lib/isValue.d.ts +10 -10
  133. package/dist/lib/isValue.js.map +1 -1
  134. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
  135. package/dist/lib/minifyGraphQLQuery.js.map +1 -1
  136. package/dist/lib/pLimit.cjs +3 -4
  137. package/dist/lib/pLimit.cjs.map +1 -1
  138. package/dist/lib/pLimit.js +3 -4
  139. package/dist/lib/pLimit.js.map +1 -1
  140. package/dist/lib/request.cjs +8 -10
  141. package/dist/lib/request.cjs.map +1 -1
  142. package/dist/lib/request.js +8 -10
  143. package/dist/lib/request.js.map +1 -1
  144. package/dist/lib/resolveMigrationDocumentData.cjs +4 -6
  145. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
  146. package/dist/lib/resolveMigrationDocumentData.d.ts +8 -8
  147. package/dist/lib/resolveMigrationDocumentData.js +4 -6
  148. package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
  149. package/dist/lib/serializerHelpers.cjs +2 -2
  150. package/dist/lib/serializerHelpers.cjs.map +1 -1
  151. package/dist/lib/serializerHelpers.d.ts +3 -3
  152. package/dist/lib/serializerHelpers.js +2 -2
  153. package/dist/lib/serializerHelpers.js.map +1 -1
  154. package/dist/lib/someTagsFilter.cjs.map +1 -1
  155. package/dist/lib/someTagsFilter.js.map +1 -1
  156. package/dist/lib/throttledLog.cjs.map +1 -1
  157. package/dist/lib/throttledLog.js.map +1 -1
  158. package/dist/lib/typeFilter.cjs.map +1 -1
  159. package/dist/lib/typeFilter.js.map +1 -1
  160. package/dist/lib/validateAssetMetadata.cjs.map +1 -1
  161. package/dist/lib/validateAssetMetadata.d.ts +1 -1
  162. package/dist/lib/validateAssetMetadata.js.map +1 -1
  163. package/dist/package.json.cjs +1 -1
  164. package/dist/package.json.js +1 -1
  165. package/dist/richtext/asText.cjs.map +1 -1
  166. package/dist/richtext/asText.d.ts +6 -6
  167. package/dist/richtext/asText.js.map +1 -1
  168. package/dist/richtext/asTree.cjs.map +1 -1
  169. package/dist/richtext/asTree.d.ts +2 -2
  170. package/dist/richtext/asTree.js.map +1 -1
  171. package/dist/richtext/composeSerializers.cjs.map +1 -1
  172. package/dist/richtext/composeSerializers.d.ts +1 -1
  173. package/dist/richtext/composeSerializers.js.map +1 -1
  174. package/dist/richtext/index.d.ts +7 -7
  175. package/dist/richtext/serialize.cjs.map +1 -1
  176. package/dist/richtext/serialize.d.ts +10 -10
  177. package/dist/richtext/serialize.js.map +1 -1
  178. package/dist/richtext/types.cjs.map +1 -1
  179. package/dist/richtext/types.d.ts +7 -7
  180. package/dist/richtext/types.js.map +1 -1
  181. package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
  182. package/dist/richtext/wrapMapSerializer.d.ts +1 -1
  183. package/dist/richtext/wrapMapSerializer.js.map +1 -1
  184. package/dist/types/api/asset/asset.d.ts +1 -1
  185. package/dist/types/api/integration.d.ts +1 -1
  186. package/dist/types/api/migration/document.d.ts +1 -1
  187. package/dist/types/api/query.d.ts +1 -1
  188. package/dist/types/api/release.d.ts +1 -1
  189. package/dist/types/api/repository.d.ts +1 -1
  190. package/dist/types/migration/Asset.cjs +12 -15
  191. package/dist/types/migration/Asset.cjs.map +1 -1
  192. package/dist/types/migration/Asset.d.ts +7 -7
  193. package/dist/types/migration/Asset.js +12 -15
  194. package/dist/types/migration/Asset.js.map +1 -1
  195. package/dist/types/migration/ContentRelationship.d.ts +3 -3
  196. package/dist/types/migration/Document.cjs +24 -27
  197. package/dist/types/migration/Document.cjs.map +1 -1
  198. package/dist/types/migration/Document.d.ts +9 -9
  199. package/dist/types/migration/Document.js +24 -27
  200. package/dist/types/migration/Document.js.map +1 -1
  201. package/dist/types/migration/Link.d.ts +1 -1
  202. package/dist/types/model/boolean.d.ts +1 -1
  203. package/dist/types/model/color.d.ts +1 -1
  204. package/dist/types/model/contentRelationship.d.ts +3 -2
  205. package/dist/types/model/customType.d.ts +1 -1
  206. package/dist/types/model/date.d.ts +1 -1
  207. package/dist/types/model/embed.d.ts +1 -1
  208. package/dist/types/model/geoPoint.d.ts +1 -1
  209. package/dist/types/model/group.d.ts +1 -1
  210. package/dist/types/model/image.d.ts +1 -1
  211. package/dist/types/model/integration.d.ts +1 -1
  212. package/dist/types/model/keyText.d.ts +1 -1
  213. package/dist/types/model/link.d.ts +1 -1
  214. package/dist/types/model/linkToMedia.d.ts +2 -2
  215. package/dist/types/model/number.d.ts +1 -1
  216. package/dist/types/model/range.d.ts +1 -1
  217. package/dist/types/model/richText.d.ts +1 -1
  218. package/dist/types/model/select.d.ts +1 -1
  219. package/dist/types/model/separator.d.ts +1 -1
  220. package/dist/types/model/sharedSlice.d.ts +2 -2
  221. package/dist/types/model/sharedSliceVariation.d.ts +1 -1
  222. package/dist/types/model/slice.d.ts +3 -3
  223. package/dist/types/model/sliceZone.d.ts +2 -2
  224. package/dist/types/model/table.d.ts +1 -1
  225. package/dist/types/model/timestamp.d.ts +1 -1
  226. package/dist/types/model/title.d.ts +1 -1
  227. package/dist/types/model/types.d.ts +22 -22
  228. package/dist/types/model/uid.d.ts +1 -1
  229. package/dist/types/value/color.d.ts +1 -1
  230. package/dist/types/value/contentRelationship.d.ts +3 -3
  231. package/dist/types/value/date.d.ts +1 -1
  232. package/dist/types/value/document.d.ts +4 -4
  233. package/dist/types/value/embed.d.ts +1 -1
  234. package/dist/types/value/geoPoint.d.ts +1 -1
  235. package/dist/types/value/group.d.ts +1 -1
  236. package/dist/types/value/image.d.ts +1 -1
  237. package/dist/types/value/integration.d.ts +1 -1
  238. package/dist/types/value/keyText.d.ts +1 -1
  239. package/dist/types/value/link.d.ts +5 -5
  240. package/dist/types/value/linkToMedia.d.ts +2 -2
  241. package/dist/types/value/number.d.ts +1 -1
  242. package/dist/types/value/richText.d.ts +3 -3
  243. package/dist/types/value/select.d.ts +1 -1
  244. package/dist/types/value/sharedSlice.d.ts +1 -1
  245. package/dist/types/value/sharedSliceVariation.d.ts +1 -1
  246. package/dist/types/value/slice.d.ts +1 -1
  247. package/dist/types/value/sliceZone.d.ts +3 -3
  248. package/dist/types/value/table.d.ts +2 -2
  249. package/dist/types/value/timestamp.d.ts +2 -2
  250. package/dist/types/value/title.d.ts +2 -2
  251. package/dist/types/value/types.d.ts +18 -18
  252. package/dist/types/webhook/apiUpdate.d.ts +1 -1
  253. package/dist/types/webhook/testTrigger.d.ts +1 -1
  254. package/dist/types/webhook/types.d.ts +2 -2
  255. package/package.json +11 -11
  256. package/src/WriteClient.ts +32 -21
  257. package/src/buildQueryURL.ts +29 -21
  258. package/src/createClient.ts +11 -8
  259. package/src/getRepositoryEndpoint.ts +9 -2
  260. package/src/helpers/asDate.ts +11 -4
  261. package/src/helpers/asHTML.ts +34 -26
  262. package/src/helpers/asImagePixelDensitySrcSet.ts +16 -15
  263. package/src/helpers/asImageSrc.ts +11 -10
  264. package/src/helpers/asImageWidthSrcSet.ts +18 -17
  265. package/src/helpers/asLink.ts +33 -32
  266. package/src/helpers/asLinkAttrs.ts +6 -9
  267. package/src/helpers/asText.ts +20 -10
  268. package/src/helpers/isFilled.ts +15 -14
  269. package/src/helpers/mapSliceZone.ts +10 -10
  270. package/src/index.ts +2 -2
  271. package/src/isRepositoryEndpoint.ts +2 -2
  272. package/src/richtext/asText.ts +5 -5
  273. package/src/richtext/serialize.ts +8 -8
  274. package/src/richtext/types.ts +6 -6
  275. package/src/types/migration/Asset.ts +10 -2
  276. package/src/types/model/contentRelationship.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A pixel-densitye-based `srcset` attribute value for the image field's\n\t\t\t\t * image with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Creates a pixel-density-based `srcset` from an image field with optional\n * image transformations (via Imgix URL parameters).\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities\n * will be used by default: 1, 2, 3.\n *\n * @example\n *\n * ```ts\n * const srcset = asImagePixelDensitySrcSet(document.data.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 *\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":";;;;AAUA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AA+DjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,wBAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,YAAgB,IAAA;AAE9D,WAAA;AAAA,MACN,KAAKC,gBAAA,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQC,gBAAAA,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MACA,CAAA;AAAA;SAEI;AACC,WAAA;AAAA,EAAA;AAET;;"}
1
+ {"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A pixel-density-based `srcset` attribute value for the image field\n\t\t\t\t * with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Creates a pixel-density-based `srcset` from an image field with optional\n * image transformations via imgix URL parameters.\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities\n * will be used by default: 1, 2, 3.\n *\n * @example\n *\n * ```ts\n * const srcset = asImagePixelDensitySrcSet(document.data.photo, {\n * \tpixelDensities: [1, 2],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` pixel densities.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImagePixelDensitySrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImagePixelDensitySrcSetConfig = {},\n): AsImagePixelDensitySrcSetReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\t// We are using destructuring to omit `pixelDensities` from the\n\t\t// object we will pass to `buildURL()`.\n\t\tconst { pixelDensities = DEFAULT_PIXEL_DENSITIES, ...imgixParams } = config\n\n\t\treturn {\n\t\t\tsrc: buildURL(field.url, imgixParams),\n\t\t\tsrcset: buildPixelDensitySrcSet(field.url, {\n\t\t\t\t...imgixParams,\n\t\t\t\tpixelDensities,\n\t\t\t}),\n\t\t} as AsImagePixelDensitySrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImagePixelDensitySrcSetReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled","buildURL","buildPixelDensitySrcSet"],"mappings":";;;;AAUA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AAgEjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC/C,MAAI,SAASA,wBAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAErE,WAAO;AAAA,MACN,KAAKC,gBAAAA,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQC,gBAAAA,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,EAEH,OAAO;AACN,WAAO;AAAA,EACR;AACD;;"}
@@ -1,5 +1,5 @@
1
1
  import type { BuildPixelDensitySrcSetParams } from "imgix-url-builder";
2
- import type { ImageFieldImage } from "../types/value/image";
2
+ import type { ImageFieldImage } from "../types/value/image.js";
3
3
  /**
4
4
  * Configuration for `asImagePixelDensitySrcSet()`.
5
5
  */
@@ -9,18 +9,18 @@ type AsImagePixelDensitySrcSetConfig = Omit<BuildPixelDensitySrcSetParams, "pixe
9
9
  */
10
10
  type AsImagePixelDensitySrcSetReturnType<Field extends ImageFieldImage | null | undefined> = Field extends ImageFieldImage<"filled"> ? {
11
11
  /**
12
- * The image field's image URL with Imgix URL parameters (if given).
12
+ * The image field's 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
17
- * image with Imgix URL parameters (if given).
16
+ * A pixel-density-based `srcset` attribute value for the image field
17
+ * with imgix URL parameters (if given).
18
18
  */
19
19
  srcset: string;
20
20
  } : null;
21
21
  /**
22
22
  * Creates a pixel-density-based `srcset` from an image field with optional
23
- * image transformations (via Imgix URL parameters).
23
+ * image transformations via imgix URL parameters.
24
24
  *
25
25
  * If a `pixelDensities` parameter is not given, the following pixel densities
26
26
  * will be used by default: 1, 2, 3.
@@ -28,26 +28,27 @@ type AsImagePixelDensitySrcSetReturnType<Field extends ImageFieldImage | null |
28
28
  * @example
29
29
  *
30
30
  * ```ts
31
- * const srcset = asImagePixelDensitySrcSet(document.data.imageField, {
31
+ * const srcset = asImagePixelDensitySrcSet(document.data.photo, {
32
32
  * pixelDensities: [1, 2],
33
33
  * sat: -100,
34
34
  * })
35
35
  * // => {
36
- * // src: 'https://images.prismic.io/repo/image.png?sat=-100',
37
- * // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, ' +
38
- * // 'https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x'
36
+ * // src: "https://images.prismic.io/repo/image.png?sat=-100",
37
+ * // srcset: "https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, " +
38
+ * // "https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x"
39
39
  * // }
40
40
  * ```
41
41
  *
42
- * @param field - Image field (or one of its responsive views) from which to get
43
- * an image URL.
44
- * @param config - An object of Imgix URL API parameters. The `pixelDensities`
45
- * parameter defines the resulting `srcset` widths.
42
+ * @param field - An image field (or one of its responsive views) from which to
43
+ * get an image URL.
44
+ * @param config - An object of imgix URL API parameters. The `pixelDensities`
45
+ * parameter defines the resulting `srcset` pixel densities.
46
46
  *
47
- * @returns A `srcset` attribute value for the image field with 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, or `null` if the field is empty.
49
49
  *
50
- * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
50
+ * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
51
+ * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
51
52
  */
52
53
  export declare const asImagePixelDensitySrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImagePixelDensitySrcSetConfig) => AsImagePixelDensitySrcSetReturnType<Field>;
53
54
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"asImagePixelDensitySrcSet.js","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A pixel-densitye-based `srcset` attribute value for the image field's\n\t\t\t\t * image with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Creates a pixel-density-based `srcset` from an image field with optional\n * image transformations (via Imgix URL parameters).\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities\n * will be used by default: 1, 2, 3.\n *\n * @example\n *\n * ```ts\n * const srcset = asImagePixelDensitySrcSet(document.data.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 *\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":";;AAUA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AA+DjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC3C,MAAA,SAASA,eAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,YAAgB,IAAA;AAE9D,WAAA;AAAA,MACN,KAAK,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQ,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MACA,CAAA;AAAA;SAEI;AACC,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"asImagePixelDensitySrcSet.js","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A pixel-density-based `srcset` attribute value for the image field\n\t\t\t\t * with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Creates a pixel-density-based `srcset` from an image field with optional\n * image transformations via imgix URL parameters.\n *\n * If a `pixelDensities` parameter is not given, the following pixel densities\n * will be used by default: 1, 2, 3.\n *\n * @example\n *\n * ```ts\n * const srcset = asImagePixelDensitySrcSet(document.data.photo, {\n * \tpixelDensities: [1, 2],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&dpr=1 1x, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&dpr=2 2x\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` pixel densities.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImagePixelDensitySrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImagePixelDensitySrcSetConfig = {},\n): AsImagePixelDensitySrcSetReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\t// We are using destructuring to omit `pixelDensities` from the\n\t\t// object we will pass to `buildURL()`.\n\t\tconst { pixelDensities = DEFAULT_PIXEL_DENSITIES, ...imgixParams } = config\n\n\t\treturn {\n\t\t\tsrc: buildURL(field.url, imgixParams),\n\t\t\tsrcset: buildPixelDensitySrcSet(field.url, {\n\t\t\t\t...imgixParams,\n\t\t\t\tpixelDensities,\n\t\t\t}),\n\t\t} as AsImagePixelDensitySrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImagePixelDensitySrcSetReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled"],"mappings":";;AAUA,MAAM,0BAA0B,CAAC,GAAG,GAAG,CAAC;AAgEjC,MAAM,4BAA4B,CAGxC,OACA,SAA0C,OACK;AAC/C,MAAI,SAASA,eAAuB,KAAK,GAAG;AAG3C,UAAM,EAAE,iBAAiB,yBAAyB,GAAG,gBAAgB;AAErE,WAAO;AAAA,MACN,KAAK,SAAS,MAAM,KAAK,WAAW;AAAA,MACpC,QAAQ,wBAAwB,MAAM,KAAK;AAAA,QAC1C,GAAG;AAAA,QACH;AAAA,MAAA,CACA;AAAA,IAAA;AAAA,EAEH,OAAO;AACN,WAAO;AAAA,EACR;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asImageSrc.cjs","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations (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 *\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":";;;;AAiCO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,wBAAuB,KAAK,GAAG;AACpC,WAAAC,yBAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EAAA;AAET;;"}
1
+ {"version":3,"file":"asImageSrc.cjs","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations via\n * imgix URL parameters.\n *\n * @example\n *\n * ```ts\n * const src = asImageSrc(document.data.photo, { sat: -100 })\n * // => \"https://images.prismic.io/repo/image.png?sat=-100\"\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters to transform the image.\n *\n * @returns The image field's URL with transformations applied, or `null` if the\n * field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageSrc = <Field extends ImageFieldImage | null | undefined>(\n\tfield: Field,\n\tconfig: ImgixURLParams = {},\n): AsImageSrcReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\treturn buildURL(field.url, config) as AsImageSrcReturnType<Field>\n\t} else {\n\t\treturn null as AsImageSrcReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled","buildURL"],"mappings":";;;;AAkCO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAChC,MAAI,SAASA,wBAAuB,KAAK,GAAG;AAC3C,WAAOC,yBAAS,MAAM,KAAK,MAAM;AAAA,EAClC,OAAO;AACN,WAAO;AAAA,EACR;AACD;;"}
@@ -1,28 +1,29 @@
1
1
  import type { ImgixURLParams } from "imgix-url-builder";
2
- import type { ImageFieldImage } from "../types/value/image";
2
+ import type { ImageFieldImage } from "../types/value/image.js";
3
3
  /**
4
4
  * The return type of `asImageSrc()`.
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
9
- * Imgix URL parameters).
8
+ * Returns the URL of an image field with optional image transformations via
9
+ * imgix URL parameters.
10
10
  *
11
11
  * @example
12
12
  *
13
13
  * ```ts
14
- * const src = asImageSrc(document.data.imageField, { sat: -100 })
15
- * // => https://images.prismic.io/repo/image.png?sat=-100
14
+ * const src = asImageSrc(document.data.photo, { sat: -100 })
15
+ * // => "https://images.prismic.io/repo/image.png?sat=-100"
16
16
  * ```
17
17
  *
18
- * @param field - Image field (or one of its responsive views) from which to get
19
- * an image URL.
20
- * @param config - An object of Imgix URL API parameters to transform the image.
18
+ * @param field - An image field (or one of its responsive views) from which to
19
+ * get an image URL.
20
+ * @param config - An object of imgix URL API parameters to transform the image.
21
21
  *
22
- * @returns The image field's image URL with transformations applied (if given).
23
- * If the image field is empty, `null` is returned.
22
+ * @returns The image field's URL with transformations applied, or `null` if the
23
+ * field is empty.
24
24
  *
25
- * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
25
+ * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
26
+ * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
26
27
  */
27
28
  export declare const asImageSrc: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: ImgixURLParams) => AsImageSrcReturnType<Field>;
28
29
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"asImageSrc.js","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations (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 *\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":";;AAiCO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAC5B,MAAA,SAASA,eAAuB,KAAK,GAAG;AACpC,WAAA,SAAS,MAAM,KAAK,MAAM;AAAA,EAAA,OAC3B;AACC,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"asImageSrc.js","sources":["../../../src/helpers/asImageSrc.ts"],"sourcesContent":["import type { ImgixURLParams } from \"imgix-url-builder\"\nimport { buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The return type of `asImageSrc()`.\n */\ntype AsImageSrcReturnType<Field extends ImageFieldImage | null | undefined> =\n\tField extends ImageFieldImage<\"filled\"> ? string : null\n\n/**\n * Returns the URL of an image field with optional image transformations via\n * imgix URL parameters.\n *\n * @example\n *\n * ```ts\n * const src = asImageSrc(document.data.photo, { sat: -100 })\n * // => \"https://images.prismic.io/repo/image.png?sat=-100\"\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters to transform the image.\n *\n * @returns The image field's URL with transformations applied, or `null` if the\n * field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageSrc = <Field extends ImageFieldImage | null | undefined>(\n\tfield: Field,\n\tconfig: ImgixURLParams = {},\n): AsImageSrcReturnType<Field> => {\n\tif (field && isImageThumbnailFilled(field)) {\n\t\treturn buildURL(field.url, config) as AsImageSrcReturnType<Field>\n\t} else {\n\t\treturn null as AsImageSrcReturnType<Field>\n\t}\n}\n"],"names":["isImageThumbnailFilled"],"mappings":";;AAkCO,MAAM,aAAa,CACzB,OACA,SAAyB,OACO;AAChC,MAAI,SAASA,eAAuB,KAAK,GAAG;AAC3C,WAAO,SAAS,MAAM,KAAK,MAAM;AAAA,EAClC,OAAO;AACN,WAAO;AAAA,EACR;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asImageWidthSrcSet.cjs","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A width-based `srcset` attribute value for the image field's image\n\t\t\t\t * with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * 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 *\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\tid: _id,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\tedit: _edit,\n\t\t\t...responsiveViews\n\t\t} = field\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews)\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t\t}),\n\t\t} as AsImageWidthSrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>\n\t}\n}\n"],"names":["isFilled.imageThumbnail","buildURL","buildWidthSrcSet"],"mappings":";;;;AAUA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAmE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,wBAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IAAA,IACA;AACJ,UAAM,EACL,KACA,YACA,IAAI,KACJ,KAAK,MACL,WAAW,YACX,MAAM,OACN,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IAAA;AAGH,WAAA;AAAA,MACN,KAAKC,gBAAAA,SAAS,KAAK,WAAW;AAAA,MAC9B;AAAA;AAAA;AAAA,QAGC,WAAW,eACR;AAAA,UACAC,gBAAAA,iBAAiB,KAAK;AAAA,YACrB,GAAG;AAAA,YACH,QAAQ,CAAC,WAAW,KAAK;AAAA,UAAA,CACzB;AAAA,UACD,GAAG,sBAAsB,IAAI,CAAC,cAAa;AACnC,mBAAAA,gBAAA,iBAAiB,UAAU,KAAK;AAAA,cACtC,GAAG;AAAA,cACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,YAAA,CACnC;AAAA,UACD,CAAA;AAAA,UACA,KAAK,IAAI,IACVA,gBAAAA,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QACA,CAAA;AAAA;AAAA;SAEC;AACC,WAAA;AAAA,EAAA;AAET;;"}
1
+ {"version":3,"file":"asImageWidthSrcSet.cjs","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A width-based `srcset` attribute value for the image field with imgix\n\t\t\t\t * URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Configuration for `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, \"widths\"> & {\n\twidths?: \"thumbnails\" | BuildWidthSrcSetParams[\"widths\"]\n}\n\n/**\n * Creates a width-based `srcset` from an image field with optional image\n * transformations via imgix URL parameters.\n *\n * If a `widths` parameter is not given, the following widths (in pixels) will\n * be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.\n *\n * If the image field contains responsive views, each responsive view can be\n * used as a width in the resulting `srcset` by passing `\"thumbnails\"` as the\n * `widths` parameter.\n *\n * @example\n *\n * ```ts\n * const srcset = asImageWidthSrcSet(document.data.photo, {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths. Pass `\"thumbnails\"` to automatically\n * use the field's responsive views.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageWidthSrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImageWidthSrcSetConfig = {},\n): AsImageWidthSrcSetReturnType<Field> => {\n\tif (field && isFilled.imageThumbnail(field)) {\n\t\t// We are using destructuring to omit `widths` from the object\n\t\t// we will pass to `buildURL()`.\n\t\tlet {\n\t\t\twidths = DEFAULT_WIDTHS,\n\t\t\t// eslint-disable-next-line prefer-const\n\t\t\t...imgixParams\n\t\t} = config\n\t\tconst {\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tid: _id,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\tedit: _edit,\n\t\t\t...responsiveViews\n\t\t} = field\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews)\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t\t}),\n\t\t} as AsImageWidthSrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>\n\t}\n}\n"],"names":["isFilled.imageThumbnail","buildURL","buildWidthSrcSet"],"mappings":";;;;AAUA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAoE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,wBAAwB,KAAK,GAAG;AAG5C,QAAI;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IAAA,IACA;AACJ,UAAM,EACL,KACA,YACA,IAAI,KACJ,KAAK,MACL,WAAW,YACX,MAAM,OACN,GAAG,oBACA;AAIJ,UAAM,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AAChE,eAAS;AAAA,IACV;AAEA,WAAO;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;AAC1C,mBAAOA,gBAAAA,iBAAiB,UAAU,KAAK;AAAA,cACtC,GAAG;AAAA,cACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,YAAA,CACnC;AAAA,UACF,CAAC;AAAA,QAAA,EACA,KAAK,IAAI,IACVA,gBAAAA,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA;AAAA,IAAA;AAAA,EAEN,OAAO;AACN,WAAO;AAAA,EACR;AACD;;"}
@@ -1,16 +1,16 @@
1
1
  import type { BuildWidthSrcSetParams } from "imgix-url-builder";
2
- import type { ImageFieldImage } from "../types/value/image";
2
+ import type { ImageFieldImage } from "../types/value/image.js";
3
3
  /**
4
4
  * The return type of `asImageWidthSrcSet()`.
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 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
13
- * with Imgix URL parameters (if given).
12
+ * A width-based `srcset` attribute value for the image field with imgix
13
+ * URL parameters (if given).
14
14
  */
15
15
  srcset: string;
16
16
  } : null;
@@ -22,10 +22,10 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
22
22
  };
23
23
  /**
24
24
  * Creates a width-based `srcset` from an image field with optional image
25
- * transformations (via Imgix URL parameters).
25
+ * transformations via imgix URL parameters.
26
26
  *
27
- * If a `widths` parameter is not given, the following widths will be used by
28
- * default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
27
+ * If a `widths` parameter is not given, the following widths (in pixels) will
28
+ * be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
29
29
  *
30
30
  * If the image field contains responsive views, each responsive view can be
31
31
  * used as a width in the resulting `srcset` by passing `"thumbnails"` as the
@@ -34,28 +34,29 @@ type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
34
34
  * @example
35
35
  *
36
36
  * ```ts
37
- * const srcset = asImageWidthSrcSet(document.data.imageField, {
37
+ * const srcset = asImageWidthSrcSet(document.data.photo, {
38
38
  * widths: [400, 800, 1600],
39
39
  * sat: -100,
40
40
  * })
41
41
  * // => {
42
- * // src: 'https://images.prismic.io/repo/image.png?sat=-100',
43
- * // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, ' +
44
- * // 'https://images.prismic.io/repo/image.png?sat=-100&width=800 800w,' +
45
- * // 'https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w'
42
+ * // src: "https://images.prismic.io/repo/image.png?sat=-100",
43
+ * // srcset: "https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, " +
44
+ * // "https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, " +
45
+ * // "https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w"
46
46
  * // }
47
47
  * ```
48
48
  *
49
- * @param field - Image field (or one of its responsive views) from which to get
50
- * an image URL.
51
- * @param config - An object of Imgix URL API parameters. The `widths` parameter
49
+ * @param field - An image field (or one of its responsive views) from which to
50
+ * get an image URL.
51
+ * @param config - An object of imgix URL API parameters. The `widths` parameter
52
52
  * defines the resulting `srcset` widths. Pass `"thumbnails"` to automatically
53
53
  * use the field's responsive views.
54
54
  *
55
- * @returns A `srcset` attribute value for the image field with 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, or `null` if the field is empty.
57
57
  *
58
- * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
58
+ * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}
59
+ * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}
59
60
  */
60
61
  export declare const asImageWidthSrcSet: <Field extends ImageFieldImage | null | undefined>(field: Field, config?: AsImageWidthSrcSetConfig) => AsImageWidthSrcSetReturnType<Field>;
61
62
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"asImageWidthSrcSet.js","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's image URL with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A width-based `srcset` attribute value for the image field's image\n\t\t\t\t * with Imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * 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 *\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\tid: _id,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\tedit: _edit,\n\t\t\t...responsiveViews\n\t\t} = field\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews)\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t\t}),\n\t\t} as AsImageWidthSrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>\n\t}\n}\n"],"names":["isFilled.imageThumbnail"],"mappings":";;AAUA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAmE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,eAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IAAA,IACA;AACJ,UAAM,EACL,KACA,YACA,IAAI,KACJ,KAAK,MACL,WAAW,YACX,MAAM,OACN,GAAG,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IAAA;AAGH,WAAA;AAAA,MACN,KAAK,SAAS,KAAK,WAAW;AAAA,MAC9B;AAAA;AAAA;AAAA,QAGC,WAAW,eACR;AAAA,UACA,iBAAiB,KAAK;AAAA,YACrB,GAAG;AAAA,YACH,QAAQ,CAAC,WAAW,KAAK;AAAA,UAAA,CACzB;AAAA,UACD,GAAG,sBAAsB,IAAI,CAAC,cAAa;AACnC,mBAAA,iBAAiB,UAAU,KAAK;AAAA,cACtC,GAAG;AAAA,cACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,YAAA,CACnC;AAAA,UACD,CAAA;AAAA,UACA,KAAK,IAAI,IACV,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QACA,CAAA;AAAA;AAAA;SAEC;AACC,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"asImageWidthSrcSet.js","sources":["../../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import type { BuildWidthSrcSetParams } from \"imgix-url-builder\"\nimport { buildURL, buildWidthSrcSet } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport * as isFilled from \"./isFilled\"\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840]\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's URL with imgix URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrc: string\n\n\t\t\t\t/**\n\t\t\t\t * A width-based `srcset` attribute value for the image field with imgix\n\t\t\t\t * URL parameters (if given).\n\t\t\t\t */\n\t\t\t\tsrcset: string\n\t\t\t}\n\t\t: null\n\n/**\n * Configuration for `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, \"widths\"> & {\n\twidths?: \"thumbnails\" | BuildWidthSrcSetParams[\"widths\"]\n}\n\n/**\n * Creates a width-based `srcset` from an image field with optional image\n * transformations via imgix URL parameters.\n *\n * If a `widths` parameter is not given, the following widths (in pixels) will\n * be used by default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.\n *\n * If the image field contains responsive views, each responsive view can be\n * used as a width in the resulting `srcset` by passing `\"thumbnails\"` as the\n * `widths` parameter.\n *\n * @example\n *\n * ```ts\n * const srcset = asImageWidthSrcSet(document.data.photo, {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * })\n * // => {\n * // src: \"https://images.prismic.io/repo/image.png?sat=-100\",\n * // srcset: \"https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=800 800w, \" +\n * // \"https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w\"\n * // }\n * ```\n *\n * @param field - An image field (or one of its responsive views) from which to\n * get an image URL.\n * @param config - An object of imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths. Pass `\"thumbnails\"` to automatically\n * use the field's responsive views.\n *\n * @returns A `srcset` attribute value for the image field with imgix URL\n * parameters, or `null` if the field is empty.\n *\n * @see Learn how to optimize images with imgix: {@link https://prismic.io/docs/fields/image}\n * @see imgix URL parameters reference: {@link https://docs.imgix.com/apis/rendering}\n */\nexport const asImageWidthSrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tconfig: AsImageWidthSrcSetConfig = {},\n): AsImageWidthSrcSetReturnType<Field> => {\n\tif (field && isFilled.imageThumbnail(field)) {\n\t\t// We are using destructuring to omit `widths` from the object\n\t\t// we will pass to `buildURL()`.\n\t\tlet {\n\t\t\twidths = DEFAULT_WIDTHS,\n\t\t\t// eslint-disable-next-line prefer-const\n\t\t\t...imgixParams\n\t\t} = config\n\t\tconst {\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tid: _id,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\tedit: _edit,\n\t\t\t...responsiveViews\n\t\t} = field\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews)\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t\t}),\n\t\t} as AsImageWidthSrcSetReturnType<Field>\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>\n\t}\n}\n"],"names":["isFilled.imageThumbnail"],"mappings":";;AAUA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAoE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,eAAwB,KAAK,GAAG;AAG5C,QAAI;AAAA,MACH,SAAS;AAAA;AAAA,MAET,GAAG;AAAA,IAAA,IACA;AACJ,UAAM,EACL,KACA,YACA,IAAI,KACJ,KAAK,MACL,WAAW,YACX,MAAM,OACN,GAAG,oBACA;AAIJ,UAAM,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AAChE,eAAS;AAAA,IACV;AAEA,WAAO;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;AAC1C,mBAAO,iBAAiB,UAAU,KAAK;AAAA,cACtC,GAAG;AAAA,cACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,YAAA,CACnC;AAAA,UACF,CAAC;AAAA,QAAA,EACA,KAAK,IAAI,IACV,iBAAiB,MAAM,KAAK;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA;AAAA,IAAA;AAAA,EAEN,OAAO;AACN,WAAO;AAAA,EACR;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asLink.cjs","sources":["../../../src/helpers/asLink.ts"],"sourcesContent":["import type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport { documentToLinkField } from \"./documentToLinkField\"\n\n/**\n * Resolves a link to a Prismic document to a URL\n *\n * @typeParam ReturnType - Return type of your link resolver function, useful if\n * you prefer to return a complex object\n *\n * @param linkToDocumentField - A document link field to resolve\n *\n * @returns Resolved URL\n *\n * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}\n */\nexport type LinkResolverFunction<ReturnType = string | null | undefined> = (\n\tlinkToDocumentField: FilledContentRelationshipField,\n) => ReturnType\n\n/**\n * Configuration that determines the output of `asLink()`.\n */\ntype AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =\n\t{\n\t\t/**\n\t\t * An optional link resolver function. Without it, you are expected to use\n\t\t * the `routes` options from the API.\n\t\t */\n\t\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null\n\t}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsLinkDeprecatedTupleConfig<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n> = [linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null]\n\n/**\n * The return type of `asLink()`.\n */\nexport type AsLinkReturnType<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = Field extends\n\t| FilledLinkToWebField\n\t| FilledLinkToMediaField\n\t| FilledContentRelationshipField\n\t| PrismicDocument\n\t? LinkResolverFunctionReturnType | string | null\n\t: null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asLink: {\n\t/**\n\t * Resolves any type of link field or Prismic document to a URL.\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - link resolver function return\n\t * type\n\t * @typeParam Field - Link field or Prismic document to resolve to a URL\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a document to\n\t * resolve\n\t * @param config - Configuration that determines the output of `asLink()`\n\t *\n\t * @returns Resolved URL or, if the provided link field or document is empty,\n\t * `null`\n\t *\n\t * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}\n\t * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\tconfig?: AsLinkConfig<LinkResolverFunctionReturnType>,\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\n\t/**\n\t * Resolves any type of link field or Prismic document to a URL.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - link resolver function return\n\t * type\n\t * @typeParam Field - Link field or Prismic document to resolve to a URL\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a document to\n\t * resolve\n\t * @param linkResolver - An optional link resolver function. Without it, you\n\t * are expected to use the `routes` options from the API\n\t *\n\t * @returns Resolved URL or, if the provided link field or document is empty,\n\t * `null`\n\t *\n\t * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}\n\t * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\t...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n} = <\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n>(\n\tlinkFieldOrDocument: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple:\n\t\t| [config?: AsLinkConfig<LinkResolverFunctionReturnType>]\n\t\t| AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n): AsLinkReturnType<LinkResolverFunctionReturnType, Field> => {\n\tif (!linkFieldOrDocument) {\n\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n\n\t// Converts document to link field if needed\n\tconst linkField =\n\t\t// prettier-ignore\n\t\t(\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t\t// TODO: Remove the `prettier-ignore` comment when this bug is fixed.\n\t\t\t\"link_type\" in linkFieldOrDocument\n\t\t\t\t? linkFieldOrDocument\n\t\t\t\t: documentToLinkField(linkFieldOrDocument)\n\t\t) as LinkField\n\n\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\tconst [configObjectOrLinkResolver] = configObjectOrTuple\n\tlet config: AsLinkConfig<LinkResolverFunctionReturnType>\n\tif (\n\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\tconfigObjectOrLinkResolver == null\n\t) {\n\t\tconfig = {\n\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t}\n\t} else {\n\t\tconfig = { ...configObjectOrLinkResolver }\n\t}\n\n\tswitch (linkField.link_type) {\n\t\tcase LinkType.Media:\n\t\tcase LinkType.Web:\n\t\t\treturn (\"url\" in linkField ? linkField.url : null) as AsLinkReturnType<\n\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\tField\n\t\t\t>\n\n\t\tcase LinkType.Document: {\n\t\t\tif (\"id\" in linkField && config.linkResolver) {\n\t\t\t\t// When using link resolver...\n\t\t\t\tconst resolvedURL = config.linkResolver(linkField)\n\n\t\t\t\tif (resolvedURL != null) {\n\t\t\t\t\treturn resolvedURL as AsLinkReturnType<\n\t\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\t\tField\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\"url\" in linkField && linkField.url) {\n\t\t\t\t// When using route resolver...\n\t\t\t\treturn linkField.url as AsLinkReturnType<\n\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\tField\n\t\t\t\t>\n\t\t\t}\n\n\t\t\t// When empty or link resolver and route resolver are not used...\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t\t}\n\n\t\tcase LinkType.Any:\n\t\tdefault:\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n}\n"],"names":["documentToLinkField","LinkType"],"mappings":";;;;AA+Da,MAAA,SA6DT,CAQH,wBAEG,wBAGyD;AAC5D,MAAI,CAAC,qBAAqB;AAClB,WAAA;AAAA,EAAA;AAIF,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMJ,eAAe,sBACZ,sBACAA,oBAAAA,oBAAoB,mBAAmB;AAAA;AAItC,QAAA,CAAC,0BAA0B,IAAI;AACjC,MAAA;AACJ,MACC,OAAO,+BAA+B,cACtC,8BAA8B,MAC7B;AACQ,aAAA;AAAA,MACR,cAAc;AAAA;SAET;AACG,aAAA,EAAE,GAAG;;AAGf,UAAQ,UAAU,WAAW;AAAA,IAC5B,KAAKC,KAAS,SAAA;AAAA,IACd,KAAKA,KAAS,SAAA;AACL,aAAA,SAAS,YAAY,UAAU,MAAM;AAAA,IAK9C,KAAKA,KAAAA,SAAS,UAAU;AACnB,UAAA,QAAQ,aAAa,OAAO,cAAc;AAEvC,cAAA,cAAc,OAAO,aAAa,SAAS;AAEjD,YAAI,eAAe,MAAM;AACjB,iBAAA;AAAA,QAAA;AAAA,MAIR;AAGG,UAAA,SAAS,aAAa,UAAU,KAAK;AAExC,eAAO,UAAU;AAAA,MAAA;AAOX,aAAA;AAAA,IAAA;AAAA,IAGR,KAAKA,KAAS,SAAA;AAAA,IACd;AACQ,aAAA;AAAA,EAAA;AAEV;;"}
1
+ {"version":3,"file":"asLink.cjs","sources":["../../../src/helpers/asLink.ts"],"sourcesContent":["import type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport { documentToLinkField } from \"./documentToLinkField\"\n\n/**\n * Resolves a link to a Prismic page to a URL.\n *\n * @typeParam ReturnType - Return type of your link resolver function. Useful if\n * you prefer to return a complex object.\n *\n * @param linkToDocumentField - A page link field to resolve.\n *\n * @returns Resolved URL.\n *\n * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n */\nexport type LinkResolverFunction<ReturnType = string | null | undefined> = (\n\tlinkToDocumentField: FilledContentRelationshipField,\n) => ReturnType\n\n/**\n * Configuration that determines the output of `asLink()`.\n */\ntype AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =\n\t{\n\t\t/**\n\t\t * An optional link resolver function. Without it, you're expected to use\n\t\t * the `routes` option from the API.\n\t\t */\n\t\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null\n\t}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsLinkDeprecatedTupleConfig<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n> = [linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null]\n\n/**\n * The return type of `asLink()`.\n */\nexport type AsLinkReturnType<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = Field extends\n\t| FilledLinkToWebField\n\t| FilledLinkToMediaField\n\t| FilledContentRelationshipField\n\t| PrismicDocument\n\t? LinkResolverFunctionReturnType | string | null\n\t: null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asLink: {\n\t/**\n\t * Converts any type of link field or Prismic page to a URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = asLink(document.data.link)\n\t * // => \"/blog/my-post\"\n\t * ```\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n\t * type.\n\t * @typeParam Field - Link field or Prismic page to resolve to a URL.\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a page to resolve.\n\t * @param config - Configuration that determines the output of `asLink()`.\n\t *\n\t * @returns Resolved URL, or `null` if the link field or page is empty.\n\t *\n\t * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\tconfig?: AsLinkConfig<LinkResolverFunctionReturnType>,\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\n\t/**\n\t * Converts any type of link field or Prismic page to a URL.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n\t * type.\n\t * @typeParam Field - Link field or Prismic page to resolve to a URL.\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a page to resolve.\n\t * @param linkResolver - An optional link resolver function. Without it,\n\t * you're expected to use the `routes` option from the API.\n\t *\n\t * @returns Resolved URL, or `null` if the link field or page is empty.\n\t *\n\t * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\t...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n} = <\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n>(\n\tlinkFieldOrDocument: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple:\n\t\t| [config?: AsLinkConfig<LinkResolverFunctionReturnType>]\n\t\t| AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n): AsLinkReturnType<LinkResolverFunctionReturnType, Field> => {\n\tif (!linkFieldOrDocument) {\n\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n\n\t// Converts document to link field if needed\n\tconst linkField =\n\t\t// prettier-ignore\n\t\t(\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t\t// TODO: Remove the `prettier-ignore` comment when this bug is fixed.\n\t\t\t\"link_type\" in linkFieldOrDocument\n\t\t\t\t? linkFieldOrDocument\n\t\t\t\t: documentToLinkField(linkFieldOrDocument)\n\t\t) as LinkField\n\n\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\tconst [configObjectOrLinkResolver] = configObjectOrTuple\n\tlet config: AsLinkConfig<LinkResolverFunctionReturnType>\n\tif (\n\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\tconfigObjectOrLinkResolver == null\n\t) {\n\t\tconfig = {\n\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t}\n\t} else {\n\t\tconfig = { ...configObjectOrLinkResolver }\n\t}\n\n\tswitch (linkField.link_type) {\n\t\tcase LinkType.Media:\n\t\tcase LinkType.Web:\n\t\t\treturn (\"url\" in linkField ? linkField.url : null) as AsLinkReturnType<\n\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\tField\n\t\t\t>\n\n\t\tcase LinkType.Document: {\n\t\t\tif (\"id\" in linkField && config.linkResolver) {\n\t\t\t\t// When using link resolver...\n\t\t\t\tconst resolvedURL = config.linkResolver(linkField)\n\n\t\t\t\tif (resolvedURL != null) {\n\t\t\t\t\treturn resolvedURL as AsLinkReturnType<\n\t\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\t\tField\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\"url\" in linkField && linkField.url) {\n\t\t\t\t// When using route resolver...\n\t\t\t\treturn linkField.url as AsLinkReturnType<\n\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\tField\n\t\t\t\t>\n\t\t\t}\n\n\t\t\t// When empty or route resolver and link resolver are not used...\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t\t}\n\n\t\tcase LinkType.Any:\n\t\tdefault:\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n}\n"],"names":["documentToLinkField","LinkType"],"mappings":";;;;AA+DO,MAAM,SA8DT,CAQH,wBAEG,wBAGyD;AAC5D,MAAI,CAAC,qBAAqB;AACzB,WAAO;AAAA,EACR;AAGA,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA,IAMJ,eAAe,sBACZ,sBACAA,oBAAAA,oBAAoB,mBAAmB;AAAA;AAI5C,QAAM,CAAC,0BAA0B,IAAI;AACrC,MAAI;AACJ,MACC,OAAO,+BAA+B,cACtC,8BAA8B,MAC7B;AACD,aAAS;AAAA,MACR,cAAc;AAAA,IAAA;AAAA,EAEhB,OAAO;AACN,aAAS,EAAE,GAAG,2BAAA;AAAA,EACf;AAEA,UAAQ,UAAU,WAAA;AAAA,IACjB,KAAKC,KAAAA,SAAS;AAAA,IACd,KAAKA,KAAAA,SAAS;AACb,aAAQ,SAAS,YAAY,UAAU,MAAM;AAAA,IAK9C,KAAKA,KAAAA,SAAS,UAAU;AACvB,UAAI,QAAQ,aAAa,OAAO,cAAc;AAE7C,cAAM,cAAc,OAAO,aAAa,SAAS;AAEjD,YAAI,eAAe,MAAM;AACxB,iBAAO;AAAA,QAIR;AAAA,MACD;AAEA,UAAI,SAAS,aAAa,UAAU,KAAK;AAExC,eAAO,UAAU;AAAA,MAIlB;AAGA,aAAO;AAAA,IACR;AAAA,IAEA,KAAKA,KAAAA,SAAS;AAAA,IACd;AACC,aAAO;AAAA,EAAA;AAEV;;"}
@@ -1,18 +1,18 @@
1
- import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
2
- import type { PrismicDocument } from "../types/value/document";
3
- import type { FilledLinkToWebField, LinkField } from "../types/value/link";
4
- import type { FilledLinkToMediaField } from "../types/value/linkToMedia";
1
+ import type { FilledContentRelationshipField } from "../types/value/contentRelationship.js";
2
+ import type { PrismicDocument } from "../types/value/document.js";
3
+ import type { FilledLinkToWebField, LinkField } from "../types/value/link.js";
4
+ import type { FilledLinkToMediaField } from "../types/value/linkToMedia.js";
5
5
  /**
6
- * Resolves a link to a Prismic document to a URL
6
+ * Resolves a link to a Prismic page to a URL.
7
7
  *
8
- * @typeParam ReturnType - Return type of your link resolver function, useful if
9
- * you prefer to return a complex object
8
+ * @typeParam ReturnType - Return type of your link resolver function. Useful if
9
+ * you prefer to return a complex object.
10
10
  *
11
- * @param linkToDocumentField - A document link field to resolve
11
+ * @param linkToDocumentField - A page link field to resolve.
12
12
  *
13
- * @returns Resolved URL
13
+ * @returns Resolved URL.
14
14
  *
15
- * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
15
+ * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
16
16
  */
17
17
  export type LinkResolverFunction<ReturnType = string | null | undefined> = (linkToDocumentField: FilledContentRelationshipField) => ReturnType;
18
18
  /**
@@ -20,8 +20,8 @@ export type LinkResolverFunction<ReturnType = string | null | undefined> = (link
20
20
  */
21
21
  type AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> = {
22
22
  /**
23
- * An optional link resolver function. Without it, you are expected to use
24
- * the `routes` options from the API.
23
+ * An optional link resolver function. Without it, you're expected to use
24
+ * the `routes` option from the API.
25
25
  */
26
26
  linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null;
27
27
  };
@@ -35,42 +35,43 @@ type AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType = string | null
35
35
  export type AsLinkReturnType<LinkResolverFunctionReturnType = string | null | undefined, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined> = Field extends FilledLinkToWebField | FilledLinkToMediaField | FilledContentRelationshipField | PrismicDocument ? LinkResolverFunctionReturnType | string | null : null;
36
36
  export declare const asLink: {
37
37
  /**
38
- * Resolves any type of link field or Prismic document to a URL.
38
+ * Converts any type of link field or Prismic page to a URL.
39
39
  *
40
- * @typeParam LinkResolverFunctionReturnType - link resolver function return
41
- * type
42
- * @typeParam Field - Link field or Prismic document to resolve to a URL
40
+ * @example
43
41
  *
44
- * @param linkFieldOrDocument - Any kind of link field or a document to
45
- * resolve
46
- * @param config - Configuration that determines the output of `asLink()`
42
+ * ```ts
43
+ * const url = asLink(document.data.link)
44
+ * // => "/blog/my-post"
45
+ * ```
47
46
  *
48
- * @returns Resolved URL or, if the provided link field or document is empty,
49
- * `null`
47
+ * @typeParam LinkResolverFunctionReturnType - Link resolver function return
48
+ * type.
49
+ * @typeParam Field - Link field or Prismic page to resolve to a URL.
50
50
  *
51
- * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
52
- * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
51
+ * @param linkFieldOrDocument - Any kind of link field or a page to resolve.
52
+ * @param config - Configuration that determines the output of `asLink()`.
53
+ *
54
+ * @returns Resolved URL, or `null` if the link field or page is empty.
55
+ *
56
+ * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
53
57
  */
54
58
  <LinkResolverFunctionReturnType = string | null | undefined, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined>(linkFieldOrDocument: Field, config?: AsLinkConfig<LinkResolverFunctionReturnType>): AsLinkReturnType<LinkResolverFunctionReturnType, Field>;
55
59
  /**
56
- * Resolves any type of link field or Prismic document to a URL.
60
+ * Converts any type of link field or Prismic page to a URL.
57
61
  *
58
62
  * @deprecated Use object-style configuration instead.
59
63
  *
60
- * @typeParam LinkResolverFunctionReturnType - link resolver function return
61
- * type
62
- * @typeParam Field - Link field or Prismic document to resolve to a URL
64
+ * @typeParam LinkResolverFunctionReturnType - Link resolver function return
65
+ * type.
66
+ * @typeParam Field - Link field or Prismic page to resolve to a URL.
63
67
  *
64
- * @param linkFieldOrDocument - Any kind of link field or a document to
65
- * resolve
66
- * @param linkResolver - An optional link resolver function. Without it, you
67
- * are expected to use the `routes` options from the API
68
+ * @param linkFieldOrDocument - Any kind of link field or a page to resolve.
69
+ * @param linkResolver - An optional link resolver function. Without it,
70
+ * you're expected to use the `routes` option from the API.
68
71
  *
69
- * @returns Resolved URL or, if the provided link field or document is empty,
70
- * `null`
72
+ * @returns Resolved URL, or `null` if the link field or page is empty.
71
73
  *
72
- * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}
73
- * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}
74
+ * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}
74
75
  */
75
76
  <LinkResolverFunctionReturnType = string | null | undefined, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined>(linkFieldOrDocument: Field, ...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>): AsLinkReturnType<LinkResolverFunctionReturnType, Field>;
76
77
  };
@@ -1 +1 @@
1
- {"version":3,"file":"asLink.js","sources":["../../../src/helpers/asLink.ts"],"sourcesContent":["import type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport { documentToLinkField } from \"./documentToLinkField\"\n\n/**\n * Resolves a link to a Prismic document to a URL\n *\n * @typeParam ReturnType - Return type of your link resolver function, useful if\n * you prefer to return a complex object\n *\n * @param linkToDocumentField - A document link field to resolve\n *\n * @returns Resolved URL\n *\n * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}\n */\nexport type LinkResolverFunction<ReturnType = string | null | undefined> = (\n\tlinkToDocumentField: FilledContentRelationshipField,\n) => ReturnType\n\n/**\n * Configuration that determines the output of `asLink()`.\n */\ntype AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =\n\t{\n\t\t/**\n\t\t * An optional link resolver function. Without it, you are expected to use\n\t\t * the `routes` options from the API.\n\t\t */\n\t\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null\n\t}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsLinkDeprecatedTupleConfig<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n> = [linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null]\n\n/**\n * The return type of `asLink()`.\n */\nexport type AsLinkReturnType<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = Field extends\n\t| FilledLinkToWebField\n\t| FilledLinkToMediaField\n\t| FilledContentRelationshipField\n\t| PrismicDocument\n\t? LinkResolverFunctionReturnType | string | null\n\t: null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asLink: {\n\t/**\n\t * Resolves any type of link field or Prismic document to a URL.\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - link resolver function return\n\t * type\n\t * @typeParam Field - Link field or Prismic document to resolve to a URL\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a document to\n\t * resolve\n\t * @param config - Configuration that determines the output of `asLink()`\n\t *\n\t * @returns Resolved URL or, if the provided link field or document is empty,\n\t * `null`\n\t *\n\t * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}\n\t * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\tconfig?: AsLinkConfig<LinkResolverFunctionReturnType>,\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\n\t/**\n\t * Resolves any type of link field or Prismic document to a URL.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - link resolver function return\n\t * type\n\t * @typeParam Field - Link field or Prismic document to resolve to a URL\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a document to\n\t * resolve\n\t * @param linkResolver - An optional link resolver function. Without it, you\n\t * are expected to use the `routes` options from the API\n\t *\n\t * @returns Resolved URL or, if the provided link field or document is empty,\n\t * `null`\n\t *\n\t * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}\n\t * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\t...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n} = <\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n>(\n\tlinkFieldOrDocument: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple:\n\t\t| [config?: AsLinkConfig<LinkResolverFunctionReturnType>]\n\t\t| AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n): AsLinkReturnType<LinkResolverFunctionReturnType, Field> => {\n\tif (!linkFieldOrDocument) {\n\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n\n\t// Converts document to link field if needed\n\tconst linkField =\n\t\t// prettier-ignore\n\t\t(\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t\t// TODO: Remove the `prettier-ignore` comment when this bug is fixed.\n\t\t\t\"link_type\" in linkFieldOrDocument\n\t\t\t\t? linkFieldOrDocument\n\t\t\t\t: documentToLinkField(linkFieldOrDocument)\n\t\t) as LinkField\n\n\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\tconst [configObjectOrLinkResolver] = configObjectOrTuple\n\tlet config: AsLinkConfig<LinkResolverFunctionReturnType>\n\tif (\n\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\tconfigObjectOrLinkResolver == null\n\t) {\n\t\tconfig = {\n\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t}\n\t} else {\n\t\tconfig = { ...configObjectOrLinkResolver }\n\t}\n\n\tswitch (linkField.link_type) {\n\t\tcase LinkType.Media:\n\t\tcase LinkType.Web:\n\t\t\treturn (\"url\" in linkField ? linkField.url : null) as AsLinkReturnType<\n\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\tField\n\t\t\t>\n\n\t\tcase LinkType.Document: {\n\t\t\tif (\"id\" in linkField && config.linkResolver) {\n\t\t\t\t// When using link resolver...\n\t\t\t\tconst resolvedURL = config.linkResolver(linkField)\n\n\t\t\t\tif (resolvedURL != null) {\n\t\t\t\t\treturn resolvedURL as AsLinkReturnType<\n\t\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\t\tField\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\"url\" in linkField && linkField.url) {\n\t\t\t\t// When using route resolver...\n\t\t\t\treturn linkField.url as AsLinkReturnType<\n\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\tField\n\t\t\t\t>\n\t\t\t}\n\n\t\t\t// When empty or link resolver and route resolver are not used...\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t\t}\n\n\t\tcase LinkType.Any:\n\t\tdefault:\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n}\n"],"names":[],"mappings":";;AA+Da,MAAA,SA6DT,CAQH,wBAEG,wBAGyD;AAC5D,MAAI,CAAC,qBAAqB;AAClB,WAAA;AAAA,EAAA;AAIF,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMJ,eAAe,sBACZ,sBACA,oBAAoB,mBAAmB;AAAA;AAItC,QAAA,CAAC,0BAA0B,IAAI;AACjC,MAAA;AACJ,MACC,OAAO,+BAA+B,cACtC,8BAA8B,MAC7B;AACQ,aAAA;AAAA,MACR,cAAc;AAAA;SAET;AACG,aAAA,EAAE,GAAG;;AAGf,UAAQ,UAAU,WAAW;AAAA,IAC5B,KAAK,SAAS;AAAA,IACd,KAAK,SAAS;AACL,aAAA,SAAS,YAAY,UAAU,MAAM;AAAA,IAK9C,KAAK,SAAS,UAAU;AACnB,UAAA,QAAQ,aAAa,OAAO,cAAc;AAEvC,cAAA,cAAc,OAAO,aAAa,SAAS;AAEjD,YAAI,eAAe,MAAM;AACjB,iBAAA;AAAA,QAAA;AAAA,MAIR;AAGG,UAAA,SAAS,aAAa,UAAU,KAAK;AAExC,eAAO,UAAU;AAAA,MAAA;AAOX,aAAA;AAAA,IAAA;AAAA,IAGR,KAAK,SAAS;AAAA,IACd;AACQ,aAAA;AAAA,EAAA;AAEV;"}
1
+ {"version":3,"file":"asLink.js","sources":["../../../src/helpers/asLink.ts"],"sourcesContent":["import type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport { documentToLinkField } from \"./documentToLinkField\"\n\n/**\n * Resolves a link to a Prismic page to a URL.\n *\n * @typeParam ReturnType - Return type of your link resolver function. Useful if\n * you prefer to return a complex object.\n *\n * @param linkToDocumentField - A page link field to resolve.\n *\n * @returns Resolved URL.\n *\n * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n */\nexport type LinkResolverFunction<ReturnType = string | null | undefined> = (\n\tlinkToDocumentField: FilledContentRelationshipField,\n) => ReturnType\n\n/**\n * Configuration that determines the output of `asLink()`.\n */\ntype AsLinkConfig<LinkResolverFunctionReturnType = string | null | undefined> =\n\t{\n\t\t/**\n\t\t * An optional link resolver function. Without it, you're expected to use\n\t\t * the `routes` option from the API.\n\t\t */\n\t\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null\n\t}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsLinkDeprecatedTupleConfig<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n> = [linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null]\n\n/**\n * The return type of `asLink()`.\n */\nexport type AsLinkReturnType<\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = Field extends\n\t| FilledLinkToWebField\n\t| FilledLinkToMediaField\n\t| FilledContentRelationshipField\n\t| PrismicDocument\n\t? LinkResolverFunctionReturnType | string | null\n\t: null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asLink: {\n\t/**\n\t * Converts any type of link field or Prismic page to a URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = asLink(document.data.link)\n\t * // => \"/blog/my-post\"\n\t * ```\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n\t * type.\n\t * @typeParam Field - Link field or Prismic page to resolve to a URL.\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a page to resolve.\n\t * @param config - Configuration that determines the output of `asLink()`.\n\t *\n\t * @returns Resolved URL, or `null` if the link field or page is empty.\n\t *\n\t * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\tconfig?: AsLinkConfig<LinkResolverFunctionReturnType>,\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\n\t/**\n\t * Converts any type of link field or Prismic page to a URL.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n\t * type.\n\t * @typeParam Field - Link field or Prismic page to resolve to a URL.\n\t *\n\t * @param linkFieldOrDocument - Any kind of link field or a page to resolve.\n\t * @param linkResolver - An optional link resolver function. Without it,\n\t * you're expected to use the `routes` option from the API.\n\t *\n\t * @returns Resolved URL, or `null` if the link field or page is empty.\n\t *\n\t * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n\t */\n\t<\n\t\tLinkResolverFunctionReturnType = string | null | undefined,\n\t\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t\t| LinkField\n\t\t\t| PrismicDocument\n\t\t\t| null\n\t\t\t| undefined,\n\t>(\n\t\tlinkFieldOrDocument: Field,\n\t\t...config: AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n\t): AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n} = <\n\tLinkResolverFunctionReturnType = string | null | undefined,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n>(\n\tlinkFieldOrDocument: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple:\n\t\t| [config?: AsLinkConfig<LinkResolverFunctionReturnType>]\n\t\t| AsLinkDeprecatedTupleConfig<LinkResolverFunctionReturnType>\n): AsLinkReturnType<LinkResolverFunctionReturnType, Field> => {\n\tif (!linkFieldOrDocument) {\n\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n\n\t// Converts document to link field if needed\n\tconst linkField =\n\t\t// prettier-ignore\n\t\t(\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t\t// TODO: Remove the `prettier-ignore` comment when this bug is fixed.\n\t\t\t\"link_type\" in linkFieldOrDocument\n\t\t\t\t? linkFieldOrDocument\n\t\t\t\t: documentToLinkField(linkFieldOrDocument)\n\t\t) as LinkField\n\n\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\tconst [configObjectOrLinkResolver] = configObjectOrTuple\n\tlet config: AsLinkConfig<LinkResolverFunctionReturnType>\n\tif (\n\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\tconfigObjectOrLinkResolver == null\n\t) {\n\t\tconfig = {\n\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t}\n\t} else {\n\t\tconfig = { ...configObjectOrLinkResolver }\n\t}\n\n\tswitch (linkField.link_type) {\n\t\tcase LinkType.Media:\n\t\tcase LinkType.Web:\n\t\t\treturn (\"url\" in linkField ? linkField.url : null) as AsLinkReturnType<\n\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\tField\n\t\t\t>\n\n\t\tcase LinkType.Document: {\n\t\t\tif (\"id\" in linkField && config.linkResolver) {\n\t\t\t\t// When using link resolver...\n\t\t\t\tconst resolvedURL = config.linkResolver(linkField)\n\n\t\t\t\tif (resolvedURL != null) {\n\t\t\t\t\treturn resolvedURL as AsLinkReturnType<\n\t\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\t\tField\n\t\t\t\t\t>\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (\"url\" in linkField && linkField.url) {\n\t\t\t\t// When using route resolver...\n\t\t\t\treturn linkField.url as AsLinkReturnType<\n\t\t\t\t\tLinkResolverFunctionReturnType,\n\t\t\t\t\tField\n\t\t\t\t>\n\t\t\t}\n\n\t\t\t// When empty or route resolver and link resolver are not used...\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t\t}\n\n\t\tcase LinkType.Any:\n\t\tdefault:\n\t\t\treturn null as AsLinkReturnType<LinkResolverFunctionReturnType, Field>\n\t}\n}\n"],"names":[],"mappings":";;AA+DO,MAAM,SA8DT,CAQH,wBAEG,wBAGyD;AAC5D,MAAI,CAAC,qBAAqB;AACzB,WAAO;AAAA,EACR;AAGA,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA,IAMJ,eAAe,sBACZ,sBACA,oBAAoB,mBAAmB;AAAA;AAI5C,QAAM,CAAC,0BAA0B,IAAI;AACrC,MAAI;AACJ,MACC,OAAO,+BAA+B,cACtC,8BAA8B,MAC7B;AACD,aAAS;AAAA,MACR,cAAc;AAAA,IAAA;AAAA,EAEhB,OAAO;AACN,aAAS,EAAE,GAAG,2BAAA;AAAA,EACf;AAEA,UAAQ,UAAU,WAAA;AAAA,IACjB,KAAK,SAAS;AAAA,IACd,KAAK,SAAS;AACb,aAAQ,SAAS,YAAY,UAAU,MAAM;AAAA,IAK9C,KAAK,SAAS,UAAU;AACvB,UAAI,QAAQ,aAAa,OAAO,cAAc;AAE7C,cAAM,cAAc,OAAO,aAAa,SAAS;AAEjD,YAAI,eAAe,MAAM;AACxB,iBAAO;AAAA,QAIR;AAAA,MACD;AAEA,UAAI,SAAS,aAAa,UAAU,KAAK;AAExC,eAAO,UAAU;AAAA,MAIlB;AAGA,aAAO;AAAA,IACR;AAAA,IAEA,KAAK,SAAS;AAAA,IACd;AACC,aAAO;AAAA,EAAA;AAEV;"}
@@ -1 +1 @@
1
- {"version":3,"file":"asLinkAttrs.cjs","sources":["../../../src/helpers/asLinkAttrs.ts"],"sourcesContent":["import { isInternalURL } from \"../lib/isInternalURL\"\n\nimport type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport type { AsLinkReturnType, LinkResolverFunction } from \"./asLink\"\nimport { asLink } from \"./asLink\"\nimport { link as isFilledLink } from \"./isFilled\"\n\ntype AsLinkAttrsConfigRelArgs<\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = {\n\thref:\n\t\t| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>\n\t\t| undefined\n\tisExternal: boolean\n\ttarget?: string\n}\n\nexport type AsLinkAttrsConfig<\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = {\n\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType>\n\trel?: (\n\t\targs: AsLinkAttrsConfigRelArgs<LinkResolverFunctionReturnType, Field>,\n\t) => string | undefined | void\n}\n\n/**\n * The return type of `asLinkAttrs()`.\n */\ntype AsLinkAttrsReturnType<\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = Field extends\n\t| FilledLinkToWebField\n\t| FilledLinkToMediaField\n\t| FilledContentRelationshipField\n\t| PrismicDocument\n\t? {\n\t\t\thref:\n\t\t\t\t| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>\n\t\t\t\t| undefined\n\t\t\ttarget?: string\n\t\t\trel?: string\n\t\t}\n\t: {\n\t\t\thref?: undefined\n\t\t\ttarget?: undefined\n\t\t\trel?: undefined\n\t\t}\n\n/**\n * Resolves any type of link field or Prismic document to a set of link\n * attributes. The attributes are designed to be passed to link HTML elements,\n * like `<a>`.\n *\n * If a resolved URL is external (i.e. starts with a protocol like `https://`),\n * `rel` is returned as `\"noreferrer\"`.\n *\n * @typeParam LinkResolverFunctionReturnType - link resolver function return\n * type\n * @typeParam Field - Link field or Prismic document to resolve to link\n * attributes\n *\n * @param linkFieldOrDocument - Any kind of link field or a document to resolve\n * @param config - Configuration that determines the output of `asLinkAttrs()`\n *\n * @returns Resolved set of link attributes or, if the provided link field or\n * document is empty, and empty object\n *\n * @see Prismic link resolver documentation: {@link https://prismic.io/docs/route-resolver#link-resolver}\n * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/route-resolver}\n */\nexport const asLinkAttrs = <\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n>(\n\tlinkFieldOrDocument: Field,\n\tconfig: AsLinkAttrsConfig<LinkResolverFunctionReturnType> = {},\n): AsLinkAttrsReturnType<LinkResolverFunctionReturnType> => {\n\tif (\n\t\tlinkFieldOrDocument &&\n\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t(\"link_type\" in linkFieldOrDocument\n\t\t\t? isFilledLink(linkFieldOrDocument)\n\t\t\t: linkFieldOrDocument)\n\t) {\n\t\tconst target =\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t\t\"target\" in linkFieldOrDocument ? linkFieldOrDocument.target : undefined\n\n\t\tconst rawHref = asLink(linkFieldOrDocument, config.linkResolver)\n\t\tconst href =\n\t\t\trawHref == null ? undefined : (rawHref as NonNullable<typeof rawHref>)\n\n\t\tconst isExternal = typeof href === \"string\" ? !isInternalURL(href) : false\n\n\t\tconst rel = config.rel\n\t\t\t? config.rel({ href, isExternal, target })\n\t\t\t: isExternal\n\t\t\t\t? \"noreferrer\"\n\t\t\t\t: undefined\n\n\t\treturn {\n\t\t\thref,\n\t\t\ttarget,\n\t\t\trel: rel == null ? undefined : rel,\n\t\t}\n\t}\n\n\treturn {}\n}\n"],"names":["isFilledLink","asLink","isInternalURL"],"mappings":";;;;;AA0FO,MAAM,cAAc,CAQ1B,qBACA,SAA4D,OACF;AAEzD,MAAA;AAAA;AAAA,GAGC,eAAe,sBACbA,SAAAA,KAAa,mBAAmB,IAChC,sBACF;AACK,UAAA;AAAA;AAAA;AAAA,MAGL,YAAY,sBAAsB,oBAAoB,SAAS;AAAA;AAEhE,UAAM,UAAUC,OAAA,OAAO,qBAAqB,OAAO,YAAY;AACzD,UAAA,OACL,WAAW,OAAO,SAAa;AAEhC,UAAM,aAAa,OAAO,SAAS,WAAW,CAACC,cAAA,cAAc,IAAI,IAAI;AAErE,UAAM,MAAM,OAAO,MAChB,OAAO,IAAI,EAAE,MAAM,YAAY,OAAQ,CAAA,IACvC,aACC,eACA;AAEG,WAAA;AAAA,MACN;AAAA,MACA;AAAA,MACA,KAAK,OAAO,OAAO,SAAY;AAAA;;AAIjC,SAAO;AACR;;"}
1
+ {"version":3,"file":"asLinkAttrs.cjs","sources":["../../../src/helpers/asLinkAttrs.ts"],"sourcesContent":["import { isInternalURL } from \"../lib/isInternalURL\"\n\nimport type { FilledContentRelationshipField } from \"../types/value/contentRelationship\"\nimport type { PrismicDocument } from \"../types/value/document\"\nimport type { FilledLinkToWebField, LinkField } from \"../types/value/link\"\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\"\n\nimport type { AsLinkReturnType, LinkResolverFunction } from \"./asLink\"\nimport { asLink } from \"./asLink\"\nimport { link as isFilledLink } from \"./isFilled\"\n\ntype AsLinkAttrsConfigRelArgs<\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = {\n\thref:\n\t\t| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>\n\t\t| undefined\n\tisExternal: boolean\n\ttarget?: string\n}\n\nexport type AsLinkAttrsConfig<\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = {\n\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType>\n\trel?: (\n\t\targs: AsLinkAttrsConfigRelArgs<LinkResolverFunctionReturnType, Field>,\n\t) => string | undefined | void\n}\n\n/**\n * The return type of `asLinkAttrs()`.\n */\ntype AsLinkAttrsReturnType<\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n> = Field extends\n\t| FilledLinkToWebField\n\t| FilledLinkToMediaField\n\t| FilledContentRelationshipField\n\t| PrismicDocument\n\t? {\n\t\t\thref:\n\t\t\t\t| NonNullable<AsLinkReturnType<LinkResolverFunctionReturnType, Field>>\n\t\t\t\t| undefined\n\t\t\ttarget?: string\n\t\t\trel?: string\n\t\t}\n\t: {\n\t\t\thref?: undefined\n\t\t\ttarget?: undefined\n\t\t\trel?: undefined\n\t\t}\n\n/**\n * Resolves any type of link field or Prismic page to a set of link attributes.\n * The attributes are designed to be passed to link HTML elements, like `<a>`.\n *\n * If a resolved URL is external (i.e. starts with a protocol like `https://`),\n * `rel` is returned as `\"noreferrer\"`.\n *\n * @typeParam LinkResolverFunctionReturnType - link resolver function return\n * type\n * @typeParam Field - Link field or Prismic page to resolve to link attributes\n *\n * @param linkFieldOrDocument - Any kind of link field or a page to resolve\n * @param config - Configuration that determines the output of `asLinkAttrs()`\n *\n * @returns Resolved set of link attributes or, if the provided link field or\n * page is empty, and empty object\n *\n * @see Learn about route resolvers and link resolvers: {@link https://prismic.io/docs/routes}\n */\nexport const asLinkAttrs = <\n\tLinkResolverFunctionReturnType = ReturnType<LinkResolverFunction>,\n\tField extends LinkField | PrismicDocument | null | undefined =\n\t\t| LinkField\n\t\t| PrismicDocument\n\t\t| null\n\t\t| undefined,\n>(\n\tlinkFieldOrDocument: Field,\n\tconfig: AsLinkAttrsConfig<LinkResolverFunctionReturnType> = {},\n): AsLinkAttrsReturnType<LinkResolverFunctionReturnType> => {\n\tif (\n\t\tlinkFieldOrDocument &&\n\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t(\"link_type\" in linkFieldOrDocument\n\t\t\t? isFilledLink(linkFieldOrDocument)\n\t\t\t: linkFieldOrDocument)\n\t) {\n\t\tconst target =\n\t\t\t// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t// @ts-ignore - Bug in TypeScript 4.9: https://github.com/microsoft/TypeScript/issues/51501\n\t\t\t\"target\" in linkFieldOrDocument ? linkFieldOrDocument.target : undefined\n\n\t\tconst rawHref = asLink(linkFieldOrDocument, config.linkResolver)\n\t\tconst href =\n\t\t\trawHref == null ? undefined : (rawHref as NonNullable<typeof rawHref>)\n\n\t\tconst isExternal = typeof href === \"string\" ? !isInternalURL(href) : false\n\n\t\tconst rel = config.rel\n\t\t\t? config.rel({ href, isExternal, target })\n\t\t\t: isExternal\n\t\t\t\t? \"noreferrer\"\n\t\t\t\t: undefined\n\n\t\treturn {\n\t\t\thref,\n\t\t\ttarget,\n\t\t\trel: rel == null ? undefined : rel,\n\t\t}\n\t}\n\n\treturn {}\n}\n"],"names":["isFilledLink","asLink","isInternalURL"],"mappings":";;;;;AAuFO,MAAM,cAAc,CAQ1B,qBACA,SAA4D,OACF;AAC1D,MACC;AAAA;AAAA,GAGC,eAAe,sBACbA,SAAAA,KAAa,mBAAmB,IAChC,sBACF;AACD,UAAM;AAAA;AAAA;AAAA,MAGL,YAAY,sBAAsB,oBAAoB,SAAS;AAAA;AAEhE,UAAM,UAAUC,OAAAA,OAAO,qBAAqB,OAAO,YAAY;AAC/D,UAAM,OACL,WAAW,OAAO,SAAa;AAEhC,UAAM,aAAa,OAAO,SAAS,WAAW,CAACC,cAAAA,cAAc,IAAI,IAAI;AAErE,UAAM,MAAM,OAAO,MAChB,OAAO,IAAI,EAAE,MAAM,YAAY,OAAA,CAAQ,IACvC,aACC,eACA;AAEJ,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA,KAAK,OAAO,OAAO,SAAY;AAAA,IAAA;AAAA,EAEjC;AAEA,SAAO,CAAA;AACR;;"}