@prismicio/client 6.7.1 → 7.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/dist/ForbiddenError.cjs +7 -0
  2. package/dist/ForbiddenError.cjs.map +1 -0
  3. package/dist/ForbiddenError.d.ts +11 -0
  4. package/dist/ForbiddenError.js +7 -0
  5. package/dist/ForbiddenError.js.map +1 -0
  6. package/dist/NotFoundError.cjs +7 -0
  7. package/dist/NotFoundError.cjs.map +1 -0
  8. package/dist/NotFoundError.d.ts +3 -0
  9. package/dist/NotFoundError.js +7 -0
  10. package/dist/NotFoundError.js.map +1 -0
  11. package/dist/ParsingError.cjs +7 -0
  12. package/dist/ParsingError.cjs.map +1 -0
  13. package/dist/ParsingError.d.ts +12 -0
  14. package/dist/ParsingError.js +7 -0
  15. package/dist/ParsingError.js.map +1 -0
  16. package/dist/PrismicError.cjs +19 -0
  17. package/dist/PrismicError.cjs.map +1 -0
  18. package/dist/PrismicError.d.ts +5 -0
  19. package/dist/PrismicError.js +19 -0
  20. package/dist/PrismicError.js.map +1 -0
  21. package/dist/buildQueryURL.cjs +41 -0
  22. package/dist/buildQueryURL.cjs.map +1 -0
  23. package/dist/buildQueryURL.d.ts +130 -0
  24. package/dist/buildQueryURL.js +41 -0
  25. package/dist/buildQueryURL.js.map +1 -0
  26. package/dist/client.cjs +414 -0
  27. package/dist/client.cjs.map +1 -0
  28. package/dist/client.d.ts +908 -0
  29. package/dist/client.js +414 -0
  30. package/dist/client.js.map +1 -0
  31. package/dist/cookie.cjs +5 -0
  32. package/dist/cookie.cjs.map +1 -0
  33. package/dist/cookie.d.ts +5 -0
  34. package/dist/cookie.js +5 -0
  35. package/dist/cookie.js.map +1 -0
  36. package/dist/getGraphQLEndpoint.cjs +13 -0
  37. package/dist/getGraphQLEndpoint.cjs.map +1 -0
  38. package/dist/getGraphQLEndpoint.d.ts +9 -0
  39. package/dist/getGraphQLEndpoint.js +13 -0
  40. package/dist/getGraphQLEndpoint.js.map +1 -0
  41. package/dist/getRepositoryEndpoint.cjs +13 -0
  42. package/dist/getRepositoryEndpoint.cjs.map +1 -0
  43. package/dist/getRepositoryEndpoint.d.ts +10 -0
  44. package/dist/getRepositoryEndpoint.js +13 -0
  45. package/dist/getRepositoryEndpoint.js.map +1 -0
  46. package/dist/getRepositoryName.cjs +12 -0
  47. package/dist/getRepositoryName.cjs.map +1 -0
  48. package/dist/getRepositoryName.d.ts +13 -0
  49. package/dist/getRepositoryName.js +12 -0
  50. package/dist/getRepositoryName.js.map +1 -0
  51. package/dist/helpers/asDate.cjs +14 -0
  52. package/dist/helpers/asDate.cjs.map +1 -0
  53. package/dist/helpers/asDate.d.ts +16 -0
  54. package/dist/helpers/asDate.js +14 -0
  55. package/dist/helpers/asDate.js.map +1 -0
  56. package/dist/helpers/asHTML.cjs +79 -0
  57. package/dist/helpers/asHTML.cjs.map +1 -0
  58. package/dist/helpers/asHTML.d.ts +20 -0
  59. package/dist/helpers/asHTML.js +79 -0
  60. package/dist/helpers/asHTML.js.map +1 -0
  61. package/dist/helpers/asImagePixelDensitySrcSet.cjs +21 -0
  62. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -0
  63. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -0
  64. package/dist/helpers/asImagePixelDensitySrcSet.js +21 -0
  65. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -0
  66. package/dist/helpers/asImageSrc.cjs +13 -0
  67. package/dist/helpers/asImageSrc.cjs.map +1 -0
  68. package/dist/helpers/asImageSrc.d.ts +27 -0
  69. package/dist/helpers/asImageSrc.js +13 -0
  70. package/dist/helpers/asImageSrc.js.map +1 -0
  71. package/dist/helpers/asImageWidthSrcSet.cjs +40 -0
  72. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -0
  73. package/dist/helpers/asImageWidthSrcSet.d.ts +60 -0
  74. package/dist/helpers/asImageWidthSrcSet.js +40 -0
  75. package/dist/helpers/asImageWidthSrcSet.js.map +1 -0
  76. package/dist/helpers/asLink.cjs +32 -0
  77. package/dist/helpers/asLink.cjs.map +1 -0
  78. package/dist/helpers/asLink.d.ts +24 -0
  79. package/dist/helpers/asLink.js +32 -0
  80. package/dist/helpers/asLink.js.map +1 -0
  81. package/dist/helpers/asText.cjs +12 -0
  82. package/dist/helpers/asText.cjs.map +1 -0
  83. package/dist/helpers/asText.d.ts +16 -0
  84. package/dist/helpers/asText.js +12 -0
  85. package/dist/helpers/asText.js.map +1 -0
  86. package/dist/helpers/documentToLinkField.cjs +19 -0
  87. package/dist/helpers/documentToLinkField.cjs.map +1 -0
  88. package/dist/helpers/documentToLinkField.d.ts +15 -0
  89. package/dist/helpers/documentToLinkField.js +19 -0
  90. package/dist/helpers/documentToLinkField.js.map +1 -0
  91. package/dist/helpers/isFilled.cjs +67 -0
  92. package/dist/helpers/isFilled.cjs.map +1 -0
  93. package/dist/helpers/isFilled.d.ts +175 -0
  94. package/dist/helpers/isFilled.js +67 -0
  95. package/dist/helpers/isFilled.js.map +1 -0
  96. package/dist/index.cjs +67 -721
  97. package/dist/index.cjs.map +1 -1
  98. package/dist/index.d.ts +92 -1526
  99. package/dist/index.js +64 -681
  100. package/dist/index.js.map +1 -1
  101. package/dist/isRepositoryEndpoint.cjs +12 -0
  102. package/dist/isRepositoryEndpoint.cjs.map +1 -0
  103. package/dist/isRepositoryEndpoint.d.ts +10 -0
  104. package/dist/isRepositoryEndpoint.js +12 -0
  105. package/dist/isRepositoryEndpoint.js.map +1 -0
  106. package/dist/isRepositoryName.cjs +7 -0
  107. package/dist/isRepositoryName.cjs.map +1 -0
  108. package/dist/isRepositoryName.d.ts +9 -0
  109. package/dist/isRepositoryName.js +7 -0
  110. package/dist/isRepositoryName.js.map +1 -0
  111. package/dist/lib/appendPredicates.cjs +14 -0
  112. package/dist/lib/appendPredicates.cjs.map +1 -0
  113. package/dist/lib/appendPredicates.d.ts +18 -0
  114. package/dist/lib/appendPredicates.js +14 -0
  115. package/dist/lib/appendPredicates.js.map +1 -0
  116. package/dist/lib/castArray.cjs +5 -0
  117. package/dist/lib/castArray.cjs.map +1 -0
  118. package/dist/lib/castArray.d.ts +11 -0
  119. package/dist/lib/castArray.js +5 -0
  120. package/dist/lib/castArray.js.map +1 -0
  121. package/dist/lib/castThunk.cjs +5 -0
  122. package/dist/lib/castThunk.cjs.map +1 -0
  123. package/dist/lib/castThunk.d.ts +10 -0
  124. package/dist/lib/castThunk.js +5 -0
  125. package/dist/lib/castThunk.js.map +1 -0
  126. package/dist/lib/findMasterRef.cjs +8 -0
  127. package/dist/lib/findMasterRef.cjs.map +1 -0
  128. package/dist/lib/findMasterRef.d.ts +10 -0
  129. package/dist/lib/findMasterRef.js +8 -0
  130. package/dist/lib/findMasterRef.js.map +1 -0
  131. package/dist/lib/findRef.cjs +12 -0
  132. package/dist/lib/findRef.cjs.map +1 -0
  133. package/dist/lib/findRef.d.ts +13 -0
  134. package/dist/lib/findRef.js +12 -0
  135. package/dist/lib/findRef.js.map +1 -0
  136. package/dist/lib/findRefByID.cjs +8 -0
  137. package/dist/lib/findRefByID.cjs.map +1 -0
  138. package/dist/lib/findRefByID.d.ts +11 -0
  139. package/dist/lib/findRefByID.js +8 -0
  140. package/dist/lib/findRefByID.js.map +1 -0
  141. package/dist/lib/findRefByLabel.cjs +8 -0
  142. package/dist/lib/findRefByLabel.cjs.map +1 -0
  143. package/dist/lib/findRefByLabel.d.ts +11 -0
  144. package/dist/lib/findRefByLabel.js +8 -0
  145. package/dist/lib/findRefByLabel.js.map +1 -0
  146. package/dist/lib/getPreviewCookie.cjs +21 -0
  147. package/dist/lib/getPreviewCookie.cjs.map +1 -0
  148. package/dist/lib/getPreviewCookie.d.ts +9 -0
  149. package/dist/lib/getPreviewCookie.js +21 -0
  150. package/dist/lib/getPreviewCookie.js.map +1 -0
  151. package/dist/lib/minifyGraphQLQuery.cjs +7 -0
  152. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
  153. package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
  154. package/dist/lib/minifyGraphQLQuery.js +7 -0
  155. package/dist/lib/minifyGraphQLQuery.js.map +1 -0
  156. package/dist/lib/serializerHelpers.cjs +56 -0
  157. package/dist/lib/serializerHelpers.cjs.map +1 -0
  158. package/dist/lib/serializerHelpers.d.ts +9 -0
  159. package/dist/lib/serializerHelpers.js +54 -0
  160. package/dist/lib/serializerHelpers.js.map +1 -0
  161. package/dist/predicate.cjs +68 -0
  162. package/dist/predicate.cjs.map +1 -0
  163. package/dist/predicate.d.ts +209 -0
  164. package/dist/predicate.js +68 -0
  165. package/dist/predicate.js.map +1 -0
  166. package/dist/types/api/query.d.ts +42 -0
  167. package/dist/types/api/ref.d.ts +32 -0
  168. package/dist/types/api/release.d.ts +10 -0
  169. package/dist/types/api/repository.d.ts +100 -0
  170. package/dist/types/api/tags.d.ts +8 -0
  171. package/dist/types/client.d.ts +128 -0
  172. package/dist/types/helpers.d.ts +63 -0
  173. package/dist/types/model/boolean.d.ts +15 -0
  174. package/dist/types/model/color.d.ts +13 -0
  175. package/dist/types/model/contentRelationship.d.ts +18 -0
  176. package/dist/types/model/customType.d.ts +42 -0
  177. package/dist/types/model/date.d.ts +14 -0
  178. package/dist/types/model/embed.d.ts +13 -0
  179. package/dist/types/model/geoPoint.d.ts +12 -0
  180. package/dist/types/model/group.d.ts +15 -0
  181. package/dist/types/model/image.d.ts +31 -0
  182. package/dist/types/model/integrationFields.d.ts +14 -0
  183. package/dist/types/model/keyText.d.ts +13 -0
  184. package/dist/types/model/link.cjs +9 -0
  185. package/dist/types/model/link.cjs.map +1 -0
  186. package/dist/types/model/link.d.ts +27 -0
  187. package/dist/types/model/link.js +9 -0
  188. package/dist/types/model/link.js.map +1 -0
  189. package/dist/types/model/linkToMedia.d.ts +16 -0
  190. package/dist/types/model/number.d.ts +15 -0
  191. package/dist/types/model/range.d.ts +14 -0
  192. package/dist/types/model/richText.d.ts +35 -0
  193. package/dist/types/model/select.d.ts +18 -0
  194. package/dist/types/model/separator.d.ts +10 -0
  195. package/dist/types/model/sharedSlice.d.ts +19 -0
  196. package/dist/types/model/sharedSliceVariation.d.ts +22 -0
  197. package/dist/types/model/slice.cjs +8 -0
  198. package/dist/types/model/slice.cjs.map +1 -0
  199. package/dist/types/model/slice.d.ts +33 -0
  200. package/dist/types/model/slice.js +8 -0
  201. package/dist/types/model/slice.js.map +1 -0
  202. package/dist/types/model/sliceZone.cjs +8 -0
  203. package/dist/types/model/sliceZone.cjs.map +1 -0
  204. package/dist/types/model/sliceZone.d.ts +44 -0
  205. package/dist/types/model/sliceZone.js +8 -0
  206. package/dist/types/model/sliceZone.js.map +1 -0
  207. package/dist/types/model/timestamp.d.ts +14 -0
  208. package/dist/types/model/title.d.ts +7 -0
  209. package/dist/types/model/types.cjs +25 -0
  210. package/dist/types/model/types.cjs.map +1 -0
  211. package/dist/types/model/types.d.ts +62 -0
  212. package/dist/types/model/types.js +25 -0
  213. package/dist/types/model/types.js.map +1 -0
  214. package/dist/types/model/uid.d.ts +13 -0
  215. package/dist/types/utils.d.ts +28 -0
  216. package/dist/types/value/boolean.d.ts +6 -0
  217. package/dist/types/value/color.d.ts +8 -0
  218. package/dist/types/value/contentRelationship.d.ts +29 -0
  219. package/dist/types/value/date.d.ts +8 -0
  220. package/dist/types/value/document.d.ts +113 -0
  221. package/dist/types/value/embed.cjs +10 -0
  222. package/dist/types/value/embed.cjs.map +1 -0
  223. package/dist/types/value/embed.d.ts +167 -0
  224. package/dist/types/value/embed.js +10 -0
  225. package/dist/types/value/embed.js.map +1 -0
  226. package/dist/types/value/geoPoint.d.ts +11 -0
  227. package/dist/types/value/group.d.ts +7 -0
  228. package/dist/types/value/image.d.ts +36 -0
  229. package/dist/types/value/integrationFields.d.ts +9 -0
  230. package/dist/types/value/keyText.d.ts +8 -0
  231. package/dist/types/value/link.cjs +10 -0
  232. package/dist/types/value/link.cjs.map +1 -0
  233. package/dist/types/value/link.d.ts +40 -0
  234. package/dist/types/value/link.js +10 -0
  235. package/dist/types/value/link.js.map +1 -0
  236. package/dist/types/value/linkToMedia.d.ts +20 -0
  237. package/dist/types/value/number.d.ts +8 -0
  238. package/dist/types/value/richText.cjs +25 -0
  239. package/dist/types/value/richText.cjs.map +1 -0
  240. package/dist/types/value/richText.d.ts +203 -0
  241. package/dist/types/value/richText.js +25 -0
  242. package/dist/types/value/richText.js.map +1 -0
  243. package/dist/types/value/select.d.ts +9 -0
  244. package/dist/types/value/sharedSlice.d.ts +11 -0
  245. package/dist/types/value/sharedSliceVariation.d.ts +7 -0
  246. package/dist/types/value/slice.d.ts +13 -0
  247. package/dist/types/value/sliceZone.d.ts +12 -0
  248. package/dist/types/value/timestamp.d.ts +8 -0
  249. package/dist/types/value/title.d.ts +12 -0
  250. package/dist/types/value/types.d.ts +40 -0
  251. package/dist/types/webhook/apiUpdate.d.ts +52 -0
  252. package/dist/types/webhook/testTrigger.d.ts +9 -0
  253. package/dist/types/webhook/types.cjs +8 -0
  254. package/dist/types/webhook/types.cjs.map +1 -0
  255. package/dist/types/webhook/types.d.ts +18 -0
  256. package/dist/types/webhook/types.js +8 -0
  257. package/dist/types/webhook/types.js.map +1 -0
  258. package/package.json +40 -33
  259. package/src/buildQueryURL.ts +8 -4
  260. package/src/client.ts +111 -118
  261. package/src/cookie.ts +2 -1
  262. package/src/getRepositoryName.ts +4 -2
  263. package/src/helpers/asDate.ts +48 -0
  264. package/src/helpers/asHTML.ts +154 -0
  265. package/src/helpers/asImagePixelDensitySrcSet.ts +96 -0
  266. package/src/helpers/asImageSrc.ts +41 -0
  267. package/src/helpers/asImageWidthSrcSet.ts +139 -0
  268. package/src/helpers/asLink.ts +99 -0
  269. package/src/helpers/asText.ts +29 -0
  270. package/src/helpers/documentToLinkField.ts +47 -0
  271. package/src/helpers/isFilled.ts +290 -0
  272. package/src/index.ts +237 -21
  273. package/src/isRepositoryEndpoint.ts +2 -1
  274. package/src/isRepositoryName.ts +2 -1
  275. package/src/lib/appendPredicates.ts +2 -1
  276. package/src/lib/findMasterRef.ts +2 -2
  277. package/src/lib/findRef.ts +2 -5
  278. package/src/lib/findRefByID.ts +2 -2
  279. package/src/lib/findRefByLabel.ts +2 -5
  280. package/src/lib/getPreviewCookie.ts +3 -2
  281. package/src/lib/serializerHelpers.ts +96 -0
  282. package/src/predicate.ts +4 -2
  283. package/src/types/api/query.ts +50 -0
  284. package/src/types/api/ref.ts +36 -0
  285. package/src/types/api/release.ts +11 -0
  286. package/src/types/api/repository.ts +117 -0
  287. package/src/types/api/tags.ts +8 -0
  288. package/src/{types.ts → types/client.ts} +3 -37
  289. package/src/types/helpers.ts +103 -0
  290. package/src/types/model/boolean.ts +16 -0
  291. package/src/types/model/color.ts +14 -0
  292. package/src/types/model/contentRelationship.ts +22 -0
  293. package/src/types/model/customType.ts +61 -0
  294. package/src/types/model/date.ts +15 -0
  295. package/src/types/model/embed.ts +14 -0
  296. package/src/types/model/geoPoint.ts +13 -0
  297. package/src/types/model/group.ts +24 -0
  298. package/src/types/model/image.ts +37 -0
  299. package/src/types/model/integrationFields.ts +15 -0
  300. package/src/types/model/keyText.ts +14 -0
  301. package/src/types/model/link.ts +31 -0
  302. package/src/types/model/linkToMedia.ts +17 -0
  303. package/src/types/model/number.ts +16 -0
  304. package/src/types/model/range.ts +15 -0
  305. package/src/types/model/richText.ts +40 -0
  306. package/src/types/model/select.ts +22 -0
  307. package/src/types/model/separator.ts +11 -0
  308. package/src/types/model/sharedSlice.ts +23 -0
  309. package/src/types/model/sharedSliceVariation.ts +33 -0
  310. package/src/types/model/slice.ts +49 -0
  311. package/src/types/model/sliceZone.ts +62 -0
  312. package/src/types/model/timestamp.ts +15 -0
  313. package/src/types/model/title.ts +8 -0
  314. package/src/types/model/types.ts +91 -0
  315. package/src/types/model/uid.ts +14 -0
  316. package/src/types/utils.ts +34 -0
  317. package/src/types/value/boolean.ts +6 -0
  318. package/src/types/value/color.ts +10 -0
  319. package/src/types/value/contentRelationship.ts +48 -0
  320. package/src/types/value/date.ts +10 -0
  321. package/src/types/value/document.ts +142 -0
  322. package/src/types/value/embed.ts +196 -0
  323. package/src/types/value/geoPoint.ts +15 -0
  324. package/src/types/value/group.ts +14 -0
  325. package/src/types/value/image.ts +67 -0
  326. package/src/types/value/integrationFields.ts +13 -0
  327. package/src/types/value/keyText.ts +10 -0
  328. package/src/types/value/link.ts +59 -0
  329. package/src/types/value/linkToMedia.ts +25 -0
  330. package/src/types/value/number.ts +10 -0
  331. package/src/types/value/richText.ts +286 -0
  332. package/src/types/value/select.ts +13 -0
  333. package/src/types/value/sharedSlice.ts +15 -0
  334. package/src/types/value/sharedSliceVariation.ts +18 -0
  335. package/src/types/value/slice.ts +24 -0
  336. package/src/types/value/sliceZone.ts +16 -0
  337. package/src/types/value/timestamp.ts +12 -0
  338. package/src/types/value/title.ts +31 -0
  339. package/src/types/value/types.ts +60 -0
  340. package/src/types/webhook/apiUpdate.ts +56 -0
  341. package/src/types/webhook/testTrigger.ts +10 -0
  342. package/src/types/webhook/types.ts +21 -0
  343. package/src/lib/orElseThrow.ts +0 -17
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asImageWidthSrcSet.cjs","sources":["../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import {\n\tbuildURL,\n\tbuildWidthSrcSet,\n\tBuildWidthSrcSetParams,\n} from \"imgix-url-builder\";\n\nimport type { ImageFieldImage } from \"../types/value/image\";\n\nimport * as isFilled from \"./isFilled\";\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840];\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The Image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A width-based `srcset` attribute value for the Image field's image with\n\t\t\t * Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\t: null;\n\n/**\n * Configuration for `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, \"widths\"> & {\n\twidths?: \"thumbnails\" | BuildWidthSrcSetParams[\"widths\"];\n};\n\n/**\n * Creates a width-based `srcset` from an Image field with optional image\n * transformations (via Imgix URL parameters).\n *\n * If a `widths` parameter is not given, the following widths will be used by\n * default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.\n *\n * If the Image field contains responsive views, each responsive view can be\n * used as a width in the resulting `srcset` by passing `\"thumbnails\"` as the\n * `widths` parameter.\n *\n * @example\n *\n * ```ts\n * const srcset = asImageWidthSrcSet(document.data.imageField, {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => {\n * // src: 'https://images.prismic.io/repo/image.png?sat=-100',\n * // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, ' +\n * // 'https://images.prismic.io/repo/image.png?sat=-100&width=800 800w,' +\n * // 'https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w'\n * // }\n * ```\n *\n * @param field - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths. Pass `\"thumbnails\"` to automatically\n * use the field's responsive views.\n *\n * @returns A `srcset` attribute value for the Image field with Imgix URL\n * parameters (if given). If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering\n */\nexport const asImageWidthSrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tparams: 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} = params;\n\t\tconst {\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\t...responsiveViews\n\t\t} = field;\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews);\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS;\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t ].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t }),\n\t\t} as AsImageWidthSrcSetReturnType<Field>;\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>;\n\t}\n};\n"],"names":["isFilled.imageThumbnail","buildURL","buildWidthSrcSet"],"mappings":";;;;AAaA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAiE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,wBAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA,SAEN;AAAA,IACA,IAAA;AACE,UAAA,EACL,KACA,YACA,KAAK,MACL,WAAW,eACR,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IACT;AAEM,WAAA;AAAA,MACN,KAAKC,gBAAAA,SAAS,KAAK,WAAW;AAAA,MAC9B,QAGC,WAAW,eACR;AAAA,QACAC,gBAAAA,iBAAiB,KAAK;AAAA,UACrB,GAAG;AAAA,UACH,QAAQ,CAAC,WAAW,KAAK;AAAA,QAAA,CACzB;AAAA,QACD,GAAG,sBAAsB,IAAI,CAAC,cAAa;AACnC,iBAAAA,gBAAA,iBAAiB,UAAU,KAAK;AAAA,YACtC,GAAG;AAAA,YACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,UAAA,CACnC;AAAA,QAAA,CACD;AAAA,QACC,KAAK,IAAI,IACXA,gBAAAA,iBAAiB,MAAM,KAAK;AAAA,QAC5B,GAAG;AAAA,QACH;AAAA,MAAA,CACC;AAAA,IAAA;AAAA,SAEA;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -0,0 +1,60 @@
1
+ import { BuildWidthSrcSetParams } from "imgix-url-builder";
2
+ import type { ImageFieldImage } from "../types/value/image";
3
+ /**
4
+ * The return type of `asImageWidthSrcSet()`.
5
+ */
6
+ declare type AsImageWidthSrcSetReturnType<Field extends ImageFieldImage | null | undefined> = Field extends ImageFieldImage<"filled"> ? {
7
+ /**
8
+ * The Image field's image URL with Imgix URL parameters (if given).
9
+ */
10
+ src: string;
11
+ /**
12
+ * A width-based `srcset` attribute value for the Image field's image with
13
+ * Imgix URL parameters (if given).
14
+ */
15
+ srcset: string;
16
+ } : null;
17
+ /**
18
+ * Configuration for `asImageWidthSrcSet()`.
19
+ */
20
+ declare type AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, "widths"> & {
21
+ widths?: "thumbnails" | BuildWidthSrcSetParams["widths"];
22
+ };
23
+ /**
24
+ * Creates a width-based `srcset` from an Image field with optional image
25
+ * transformations (via Imgix URL parameters).
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.
29
+ *
30
+ * If the Image field contains responsive views, each responsive view can be
31
+ * used as a width in the resulting `srcset` by passing `"thumbnails"` as the
32
+ * `widths` parameter.
33
+ *
34
+ * @example
35
+ *
36
+ * ```ts
37
+ * const srcset = asImageWidthSrcSet(document.data.imageField, {
38
+ * widths: [400, 800, 1600],
39
+ * sat: -100,
40
+ * });
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'
46
+ * // }
47
+ * ```
48
+ *
49
+ * @param field - Image field (or one of its responsive views) from which to get
50
+ * an image URL.
51
+ * @param params - An object of Imgix URL API parameters. The `widths` parameter
52
+ * defines the resulting `srcset` widths. Pass `"thumbnails"` to automatically
53
+ * use the field's responsive views.
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.
57
+ * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
58
+ */
59
+ export declare const asImageWidthSrcSet: <Field extends import("../types/value/image").EmptyImageFieldImage | import("../types/value/image").FilledImageFieldImage | null | undefined>(field: Field, params?: AsImageWidthSrcSetConfig) => AsImageWidthSrcSetReturnType<Field>;
60
+ export {};
@@ -0,0 +1,40 @@
1
+ import { buildURL, buildWidthSrcSet } from "imgix-url-builder";
2
+ import { imageThumbnail } from "./isFilled.js";
3
+ const DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840];
4
+ const asImageWidthSrcSet = (field, params = {}) => {
5
+ if (field && imageThumbnail(field)) {
6
+ let {
7
+ widths = DEFAULT_WIDTHS,
8
+ ...imgixParams
9
+ } = params;
10
+ const { url, dimensions, alt: _alt, copyright: _copyright, ...responsiveViews } = field;
11
+ const responsiveViewObjects = Object.values(responsiveViews);
12
+ if (widths === "thumbnails" && responsiveViewObjects.length < 1) {
13
+ widths = DEFAULT_WIDTHS;
14
+ }
15
+ return {
16
+ src: buildURL(url, imgixParams),
17
+ srcset: widths === "thumbnails" ? [
18
+ buildWidthSrcSet(url, {
19
+ ...imgixParams,
20
+ widths: [dimensions.width]
21
+ }),
22
+ ...responsiveViewObjects.map((thumbnail) => {
23
+ return buildWidthSrcSet(thumbnail.url, {
24
+ ...imgixParams,
25
+ widths: [thumbnail.dimensions.width]
26
+ });
27
+ })
28
+ ].join(", ") : buildWidthSrcSet(field.url, {
29
+ ...imgixParams,
30
+ widths
31
+ })
32
+ };
33
+ } else {
34
+ return null;
35
+ }
36
+ };
37
+ export {
38
+ asImageWidthSrcSet
39
+ };
40
+ //# sourceMappingURL=asImageWidthSrcSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asImageWidthSrcSet.js","sources":["../../src/helpers/asImageWidthSrcSet.ts"],"sourcesContent":["import {\n\tbuildURL,\n\tbuildWidthSrcSet,\n\tBuildWidthSrcSetParams,\n} from \"imgix-url-builder\";\n\nimport type { ImageFieldImage } from \"../types/value/image\";\n\nimport * as isFilled from \"./isFilled\";\n\n/**\n * The default widths used to generate a `srcset` value.\n */\nconst DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840];\n\n/**\n * The return type of `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> = Field extends ImageFieldImage<\"filled\">\n\t? {\n\t\t\t/**\n\t\t\t * The Image field's image URL with Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrc: string;\n\n\t\t\t/**\n\t\t\t * A width-based `srcset` attribute value for the Image field's image with\n\t\t\t * Imgix URL parameters (if given).\n\t\t\t */\n\t\t\tsrcset: string;\n\t }\n\t: null;\n\n/**\n * Configuration for `asImageWidthSrcSet()`.\n */\ntype AsImageWidthSrcSetConfig = Omit<BuildWidthSrcSetParams, \"widths\"> & {\n\twidths?: \"thumbnails\" | BuildWidthSrcSetParams[\"widths\"];\n};\n\n/**\n * Creates a width-based `srcset` from an Image field with optional image\n * transformations (via Imgix URL parameters).\n *\n * If a `widths` parameter is not given, the following widths will be used by\n * default: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.\n *\n * If the Image field contains responsive views, each responsive view can be\n * used as a width in the resulting `srcset` by passing `\"thumbnails\"` as the\n * `widths` parameter.\n *\n * @example\n *\n * ```ts\n * const srcset = asImageWidthSrcSet(document.data.imageField, {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => {\n * // src: 'https://images.prismic.io/repo/image.png?sat=-100',\n * // srcset: 'https://images.prismic.io/repo/image.png?sat=-100&width=400 400w, ' +\n * // 'https://images.prismic.io/repo/image.png?sat=-100&width=800 800w,' +\n * // 'https://images.prismic.io/repo/image.png?sat=-100&width=1600 1600w'\n * // }\n * ```\n *\n * @param field - Image field (or one of its responsive views) from which to get\n * an image URL.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths. Pass `\"thumbnails\"` to automatically\n * use the field's responsive views.\n *\n * @returns A `srcset` attribute value for the Image field with Imgix URL\n * parameters (if given). If the Image field is empty, `null` is returned.\n * @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering\n */\nexport const asImageWidthSrcSet = <\n\tField extends ImageFieldImage | null | undefined,\n>(\n\tfield: Field,\n\tparams: 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} = params;\n\t\tconst {\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\talt: _alt,\n\t\t\tcopyright: _copyright,\n\t\t\t...responsiveViews\n\t\t} = field;\n\n\t\t// The Prismic Rest API will always return thumbnail values if\n\t\t// the base size is filled.\n\t\tconst responsiveViewObjects: ImageFieldImage<\"filled\">[] =\n\t\t\tObject.values(responsiveViews);\n\n\t\t// If this `asImageWidthSrcSet()` call is configured to use\n\t\t// thumbnail widths, but the field does not have thumbnails, we\n\t\t// fall back to the default set of widths.\n\t\tif (widths === \"thumbnails\" && responsiveViewObjects.length < 1) {\n\t\t\twidths = DEFAULT_WIDTHS;\n\t\t}\n\n\t\treturn {\n\t\t\tsrc: buildURL(url, imgixParams),\n\t\t\tsrcset:\n\t\t\t\t// By this point, we know `widths` can only be\n\t\t\t\t// `\"thubmanils\"` if the field has thumbnails.\n\t\t\t\twidths === \"thumbnails\"\n\t\t\t\t\t? [\n\t\t\t\t\t\t\tbuildWidthSrcSet(url, {\n\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\twidths: [dimensions.width],\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t...responsiveViewObjects.map((thumbnail) => {\n\t\t\t\t\t\t\t\treturn buildWidthSrcSet(thumbnail.url, {\n\t\t\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\t\t\twidths: [thumbnail.dimensions.width],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t ].join(\", \")\n\t\t\t\t\t: buildWidthSrcSet(field.url, {\n\t\t\t\t\t\t\t...imgixParams,\n\t\t\t\t\t\t\twidths,\n\t\t\t\t\t }),\n\t\t} as AsImageWidthSrcSetReturnType<Field>;\n\t} else {\n\t\treturn null as AsImageWidthSrcSetReturnType<Field>;\n\t}\n};\n"],"names":["isFilled.imageThumbnail"],"mappings":";;AAaA,MAAM,iBAAiB,CAAC,KAAK,KAAK,MAAM,MAAM,IAAI;AAiE3C,MAAM,qBAAqB,CAGjC,OACA,SAAmC,OACK;AACxC,MAAI,SAASA,eAAwB,KAAK,GAAG;AAGxC,QAAA;AAAA,MACH,SAAS;AAAA,SAEN;AAAA,IACA,IAAA;AACE,UAAA,EACL,KACA,YACA,KAAK,MACL,WAAW,eACR,gBACA,IAAA;AAIE,UAAA,wBACL,OAAO,OAAO,eAAe;AAK9B,QAAI,WAAW,gBAAgB,sBAAsB,SAAS,GAAG;AACvD,eAAA;AAAA,IACT;AAEM,WAAA;AAAA,MACN,KAAK,SAAS,KAAK,WAAW;AAAA,MAC9B,QAGC,WAAW,eACR;AAAA,QACA,iBAAiB,KAAK;AAAA,UACrB,GAAG;AAAA,UACH,QAAQ,CAAC,WAAW,KAAK;AAAA,QAAA,CACzB;AAAA,QACD,GAAG,sBAAsB,IAAI,CAAC,cAAa;AACnC,iBAAA,iBAAiB,UAAU,KAAK;AAAA,YACtC,GAAG;AAAA,YACH,QAAQ,CAAC,UAAU,WAAW,KAAK;AAAA,UAAA,CACnC;AAAA,QAAA,CACD;AAAA,QACC,KAAK,IAAI,IACX,iBAAiB,MAAM,KAAK;AAAA,QAC5B,GAAG;AAAA,QACH;AAAA,MAAA,CACC;AAAA,IAAA;AAAA,SAEA;AACC,WAAA;AAAA,EACP;AACF;"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const link = require("../types/value/link.cjs");
4
+ const documentToLinkField = require("./documentToLinkField.cjs");
5
+ const asLink = (linkFieldOrDocument, linkResolver) => {
6
+ if (!linkFieldOrDocument) {
7
+ return null;
8
+ }
9
+ const linkField = "link_type" in linkFieldOrDocument ? linkFieldOrDocument : documentToLinkField.documentToLinkField(linkFieldOrDocument);
10
+ switch (linkField.link_type) {
11
+ case link.LinkType.Media:
12
+ case link.LinkType.Web:
13
+ return "url" in linkField ? linkField.url : null;
14
+ case link.LinkType.Document: {
15
+ if ("id" in linkField && linkResolver) {
16
+ const resolvedURL = linkResolver(linkField);
17
+ if (resolvedURL != null) {
18
+ return resolvedURL;
19
+ }
20
+ }
21
+ if ("url" in linkField && linkField.url) {
22
+ return linkField.url;
23
+ }
24
+ return null;
25
+ }
26
+ case link.LinkType.Any:
27
+ default:
28
+ return null;
29
+ }
30
+ };
31
+ exports.asLink = asLink;
32
+ //# sourceMappingURL=asLink.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asLink.cjs","sources":["../../src/helpers/asLink.ts"],"sourcesContent":["import type { PrismicDocument } from \"../types/value/document\";\nimport { FilledLinkToWebField, LinkField, LinkType } from \"../types/value/link\";\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\";\nimport type { FilledContentRelationshipField } from \"../types/value/contentRelationship\";\nimport type { LinkResolverFunction } from \"../types/helpers\";\n\nimport { documentToLinkField } from \"./documentToLinkField\";\n\n/**\n * The return type of `asLink()`.\n */\ntype AsLinkReturnType<\n\tLinkResolverFunctionReturnType = string,\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/**\n * Resolves any type of link field or document to a URL\n *\n * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n * type\n * @param linkFieldOrDocument - Any kind of link field or a document to resolve\n * @param linkResolver - An optional link resolver function, without it you're\n * expected to use the `routes` options from the API\n *\n * @returns Resolved URL, null if provided link is empty\n * @see Prismic link resolver documentation: {@link https://prismic.io/docs/technologies/link-resolver-javascript}\n * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/technologies/route-resolver-nuxtjs}\n */\nexport const asLink = <\n\tLinkResolverFunctionReturnType = string,\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\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null,\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\"link_type\" in linkFieldOrDocument\n\t\t\t? linkFieldOrDocument\n\t\t\t: documentToLinkField(linkFieldOrDocument)\n\t) as LinkField;\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 && linkResolver) {\n\t\t\t\t// When using Link Resolver...\n\t\t\t\tconst resolvedURL = 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":";;;;AAuCa,MAAA,SAAS,CAQrB,qBACA,iBAC4D;AAC5D,MAAI,CAAC,qBAAqB;AAClB,WAAA;AAAA,EACP;AAGD,QAAM,YACL,eAAe,sBACZ,sBACAA,oBAAAA,oBAAoB,mBAAmB;AAG3C,UAAQ,UAAU,WAAW;AAAA,IAC5B,KAAKC,KAAAA,SAAS;AAAA,IACd,KAAKA,KAAS,SAAA;AACL,aAAA,SAAS,YAAY,UAAU,MAAM;AAAA,IAK9C,KAAKA,KAAAA,SAAS,UAAU;AACnB,UAAA,QAAQ,aAAa,cAAc;AAEhC,cAAA,cAAc,aAAa,SAAS;AAE1C,YAAI,eAAe,MAAM;AACjB,iBAAA;AAAA,QAIP;AAAA,MACD;AAEG,UAAA,SAAS,aAAa,UAAU,KAAK;AAExC,eAAO,UAAU;AAAA,MAIjB;AAGM,aAAA;AAAA,IACP;AAAA,IAED,KAAKA,KAAAA,SAAS;AAAA,IACd;AACQ,aAAA;AAAA,EACR;AACF;;"}
@@ -0,0 +1,24 @@
1
+ import type { PrismicDocument } from "../types/value/document";
2
+ import { FilledLinkToWebField, LinkField } from "../types/value/link";
3
+ import type { FilledLinkToMediaField } from "../types/value/linkToMedia";
4
+ import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
5
+ import type { LinkResolverFunction } from "../types/helpers";
6
+ /**
7
+ * The return type of `asLink()`.
8
+ */
9
+ declare type AsLinkReturnType<LinkResolverFunctionReturnType = string, Field extends LinkField | PrismicDocument | null | undefined = LinkField | PrismicDocument | null | undefined> = Field extends FilledLinkToWebField | FilledLinkToMediaField | FilledContentRelationshipField | PrismicDocument ? LinkResolverFunctionReturnType | string | null : null;
10
+ /**
11
+ * Resolves any type of link field or document to a URL
12
+ *
13
+ * @typeParam LinkResolverFunctionReturnType - Link resolver function return
14
+ * type
15
+ * @param linkFieldOrDocument - Any kind of link field or a document to resolve
16
+ * @param linkResolver - An optional link resolver function, without it you're
17
+ * expected to use the `routes` options from the API
18
+ *
19
+ * @returns Resolved URL, null if provided link is empty
20
+ * @see Prismic link resolver documentation: {@link https://prismic.io/docs/technologies/link-resolver-javascript}
21
+ * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/technologies/route-resolver-nuxtjs}
22
+ */
23
+ export declare const asLink: <LinkResolverFunctionReturnType = string, Field extends FilledContentRelationshipField<string, string, never> | import("../types/value/link").EmptyLinkField<"Any"> | FilledLinkToWebField | FilledLinkToMediaField | PrismicDocument<Record<string, any>, string, string> | null | undefined = FilledContentRelationshipField<string, string, never> | import("../types/value/link").EmptyLinkField<"Any"> | FilledLinkToWebField | FilledLinkToMediaField | PrismicDocument<Record<string, any>, string, string> | null | undefined>(linkFieldOrDocument: Field, linkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null | undefined) => AsLinkReturnType<LinkResolverFunctionReturnType, Field>;
24
+ export {};
@@ -0,0 +1,32 @@
1
+ import { LinkType } from "../types/value/link.js";
2
+ import { documentToLinkField } from "./documentToLinkField.js";
3
+ const asLink = (linkFieldOrDocument, linkResolver) => {
4
+ if (!linkFieldOrDocument) {
5
+ return null;
6
+ }
7
+ const linkField = "link_type" in linkFieldOrDocument ? linkFieldOrDocument : documentToLinkField(linkFieldOrDocument);
8
+ switch (linkField.link_type) {
9
+ case LinkType.Media:
10
+ case LinkType.Web:
11
+ return "url" in linkField ? linkField.url : null;
12
+ case LinkType.Document: {
13
+ if ("id" in linkField && linkResolver) {
14
+ const resolvedURL = linkResolver(linkField);
15
+ if (resolvedURL != null) {
16
+ return resolvedURL;
17
+ }
18
+ }
19
+ if ("url" in linkField && linkField.url) {
20
+ return linkField.url;
21
+ }
22
+ return null;
23
+ }
24
+ case LinkType.Any:
25
+ default:
26
+ return null;
27
+ }
28
+ };
29
+ export {
30
+ asLink
31
+ };
32
+ //# sourceMappingURL=asLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asLink.js","sources":["../../src/helpers/asLink.ts"],"sourcesContent":["import type { PrismicDocument } from \"../types/value/document\";\nimport { FilledLinkToWebField, LinkField, LinkType } from \"../types/value/link\";\nimport type { FilledLinkToMediaField } from \"../types/value/linkToMedia\";\nimport type { FilledContentRelationshipField } from \"../types/value/contentRelationship\";\nimport type { LinkResolverFunction } from \"../types/helpers\";\n\nimport { documentToLinkField } from \"./documentToLinkField\";\n\n/**\n * The return type of `asLink()`.\n */\ntype AsLinkReturnType<\n\tLinkResolverFunctionReturnType = string,\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/**\n * Resolves any type of link field or document to a URL\n *\n * @typeParam LinkResolverFunctionReturnType - Link resolver function return\n * type\n * @param linkFieldOrDocument - Any kind of link field or a document to resolve\n * @param linkResolver - An optional link resolver function, without it you're\n * expected to use the `routes` options from the API\n *\n * @returns Resolved URL, null if provided link is empty\n * @see Prismic link resolver documentation: {@link https://prismic.io/docs/technologies/link-resolver-javascript}\n * @see Prismic API `routes` options documentation: {@link https://prismic.io/docs/technologies/route-resolver-nuxtjs}\n */\nexport const asLink = <\n\tLinkResolverFunctionReturnType = string,\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\tlinkResolver?: LinkResolverFunction<LinkResolverFunctionReturnType> | null,\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\"link_type\" in linkFieldOrDocument\n\t\t\t? linkFieldOrDocument\n\t\t\t: documentToLinkField(linkFieldOrDocument)\n\t) as LinkField;\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 && linkResolver) {\n\t\t\t\t// When using Link Resolver...\n\t\t\t\tconst resolvedURL = 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":";;AAuCa,MAAA,SAAS,CAQrB,qBACA,iBAC4D;AAC5D,MAAI,CAAC,qBAAqB;AAClB,WAAA;AAAA,EACP;AAGD,QAAM,YACL,eAAe,sBACZ,sBACA,oBAAoB,mBAAmB;AAG3C,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,cAAc;AAEhC,cAAA,cAAc,aAAa,SAAS;AAE1C,YAAI,eAAe,MAAM;AACjB,iBAAA;AAAA,QAIP;AAAA,MACD;AAEG,UAAA,SAAS,aAAa,UAAU,KAAK;AAExC,eAAO,UAAU;AAAA,MAIjB;AAGM,aAAA;AAAA,IACP;AAAA,IAED,KAAK,SAAS;AAAA,IACd;AACQ,aAAA;AAAA,EACR;AACF;"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const richtext = require("@prismicio/richtext");
4
+ const asText = (richTextField, separator) => {
5
+ if (richTextField) {
6
+ return richtext.asText(richTextField, separator);
7
+ } else {
8
+ return null;
9
+ }
10
+ };
11
+ exports.asText = asText;
12
+ //# sourceMappingURL=asText.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asText.cjs","sources":["../../src/helpers/asText.ts"],"sourcesContent":["import { asText as baseAsText } from \"@prismicio/richtext\";\n\nimport { RichTextField } from \"../types/value/richText\";\n\n/**\n * The return type of `asText()`.\n */\ntype AsTextReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null;\n\n/**\n * Serializes a rich text or title field to a plain text string\n *\n * @param richTextField - A rich text or title field from Prismic\n * @param separator - Separator used to join each element, defaults to a space\n *\n * @returns Plain text equivalent of the provided rich text or title field\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport const asText = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\tseparator?: string,\n): AsTextReturnType<Field> => {\n\tif (richTextField) {\n\t\treturn baseAsText(richTextField, separator) as AsTextReturnType<Field>;\n\t} else {\n\t\treturn null as AsTextReturnType<Field>;\n\t}\n};\n"],"names":["baseAsText"],"mappings":";;;AAmBa,MAAA,SAAS,CACrB,eACA,cAC4B;AAC5B,MAAI,eAAe;AACX,WAAAA,SAAA,OAAW,eAAe,SAAS;AAAA,EAAA,OACpC;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -0,0 +1,16 @@
1
+ import { RichTextField } from "../types/value/richText";
2
+ /**
3
+ * The return type of `asText()`.
4
+ */
5
+ declare type AsTextReturnType<Field extends RichTextField | null | undefined> = Field extends RichTextField ? string : null;
6
+ /**
7
+ * Serializes a rich text or title field to a plain text string
8
+ *
9
+ * @param richTextField - A rich text or title field from Prismic
10
+ * @param separator - Separator used to join each element, defaults to a space
11
+ *
12
+ * @returns Plain text equivalent of the provided rich text or title field
13
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
14
+ */
15
+ export declare const asText: <Field extends [] | [import("../types/value/richText").RTNode, ...import("../types/value/richText").RTNode[]] | null | undefined>(richTextField: Field, separator?: string) => AsTextReturnType<Field>;
16
+ export {};
@@ -0,0 +1,12 @@
1
+ import { asText as asText$1 } from "@prismicio/richtext";
2
+ const asText = (richTextField, separator) => {
3
+ if (richTextField) {
4
+ return asText$1(richTextField, separator);
5
+ } else {
6
+ return null;
7
+ }
8
+ };
9
+ export {
10
+ asText
11
+ };
12
+ //# sourceMappingURL=asText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asText.js","sources":["../../src/helpers/asText.ts"],"sourcesContent":["import { asText as baseAsText } from \"@prismicio/richtext\";\n\nimport { RichTextField } from \"../types/value/richText\";\n\n/**\n * The return type of `asText()`.\n */\ntype AsTextReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null;\n\n/**\n * Serializes a rich text or title field to a plain text string\n *\n * @param richTextField - A rich text or title field from Prismic\n * @param separator - Separator used to join each element, defaults to a space\n *\n * @returns Plain text equivalent of the provided rich text or title field\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport const asText = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\tseparator?: string,\n): AsTextReturnType<Field> => {\n\tif (richTextField) {\n\t\treturn baseAsText(richTextField, separator) as AsTextReturnType<Field>;\n\t} else {\n\t\treturn null as AsTextReturnType<Field>;\n\t}\n};\n"],"names":["baseAsText"],"mappings":";AAmBa,MAAA,SAAS,CACrB,eACA,cAC4B;AAC5B,MAAI,eAAe;AACX,WAAAA,SAAW,eAAe,SAAS;AAAA,EAAA,OACpC;AACC,WAAA;AAAA,EACP;AACF;"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const link = require("../types/value/link.cjs");
4
+ const documentToLinkField = (prismicDocument) => {
5
+ var _a, _b, _c;
6
+ return {
7
+ link_type: link.LinkType.Document,
8
+ id: prismicDocument.id,
9
+ uid: (_a = prismicDocument.uid) != null ? _a : void 0,
10
+ type: prismicDocument.type,
11
+ tags: prismicDocument.tags,
12
+ lang: prismicDocument.lang,
13
+ url: (_b = prismicDocument.url) != null ? _b : void 0,
14
+ slug: (_c = prismicDocument.slugs) == null ? void 0 : _c[0],
15
+ ...prismicDocument.data && Object.keys(prismicDocument.data).length > 0 ? { data: prismicDocument.data } : {}
16
+ };
17
+ };
18
+ exports.documentToLinkField = documentToLinkField;
19
+ //# sourceMappingURL=documentToLinkField.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentToLinkField.cjs","sources":["../../src/helpers/documentToLinkField.ts"],"sourcesContent":["import type { PrismicDocument } from \"../types/value/document\";\nimport { LinkType } from \"../types/value/link\";\nimport type { FilledContentRelationshipField } from \"../types/value/contentRelationship\";\n\ntype SetOptional<T, Keys extends keyof T> = Omit<T, Keys> &\n\tPartial<Pick<T, Keys>>;\n\n/**\n * Converts a document into a link field, this is useful when crawling the API\n * for document links\n *\n * @typeParam TDocument - Specific interface of the provided document\n * @param prismicDocument - A document coming from Prismic\n *\n * @returns The equivalent link field to use with `asLink()`\n * @internal\n */\nexport const documentToLinkField = <\n\tTDocument extends SetOptional<PrismicDocument, \"slugs\">,\n>(\n\tprismicDocument: TDocument,\n): FilledContentRelationshipField<\n\tTDocument[\"type\"],\n\tTDocument[\"lang\"],\n\tTDocument[\"data\"]\n> => {\n\treturn {\n\t\tlink_type: LinkType.Document,\n\t\tid: prismicDocument.id,\n\t\tuid: prismicDocument.uid ?? undefined,\n\t\ttype: prismicDocument.type,\n\t\ttags: prismicDocument.tags,\n\t\tlang: prismicDocument.lang,\n\t\turl: prismicDocument.url ?? undefined,\n\t\tslug: prismicDocument.slugs?.[0], // Slug field is not available with GraphQl\n\t\t// The REST API does not include a `data` property if the data\n\t\t// object is empty.\n\t\t//\n\t\t// A presence check for `prismicDocument.data` is done to\n\t\t// support partial documents. While `documentToLinkField` is\n\t\t// not typed to accept partial documents, passing a partial\n\t\t// document can happen in untyped projects.\n\t\t...(prismicDocument.data && Object.keys(prismicDocument.data).length > 0\n\t\t\t? { data: prismicDocument.data }\n\t\t\t: {}),\n\t};\n};\n"],"names":["LinkType"],"mappings":";;;AAiBa,MAAA,sBAAsB,CAGlC,oBAKG;;AACI,SAAA;AAAA,IACN,WAAWA,KAAS,SAAA;AAAA,IACpB,IAAI,gBAAgB;AAAA,IACpB,MAAK,qBAAgB,QAAhB,YAAuB;AAAA,IAC5B,MAAM,gBAAgB;AAAA,IACtB,MAAM,gBAAgB;AAAA,IACtB,MAAM,gBAAgB;AAAA,IACtB,MAAK,qBAAgB,QAAhB,YAAuB;AAAA,IAC5B,OAAM,qBAAgB,UAAhB,mBAAwB;AAAA,IAQ9B,GAAI,gBAAgB,QAAQ,OAAO,KAAK,gBAAgB,IAAI,EAAE,SAAS,IACpE,EAAE,MAAM,gBAAgB,SACxB;;AAEL;;"}
@@ -0,0 +1,15 @@
1
+ import type { PrismicDocument } from "../types/value/document";
2
+ import type { FilledContentRelationshipField } from "../types/value/contentRelationship";
3
+ declare type SetOptional<T, Keys extends keyof T> = Omit<T, Keys> & Partial<Pick<T, Keys>>;
4
+ /**
5
+ * Converts a document into a link field, this is useful when crawling the API
6
+ * for document links
7
+ *
8
+ * @typeParam TDocument - Specific interface of the provided document
9
+ * @param prismicDocument - A document coming from Prismic
10
+ *
11
+ * @returns The equivalent link field to use with `asLink()`
12
+ * @internal
13
+ */
14
+ export declare const documentToLinkField: <TDocument extends SetOptional<PrismicDocument<Record<string, any>, string, string>, "slugs">>(prismicDocument: TDocument) => FilledContentRelationshipField<TDocument["type"], TDocument["lang"], TDocument["data"]>;
15
+ export {};
@@ -0,0 +1,19 @@
1
+ import { LinkType } from "../types/value/link.js";
2
+ const documentToLinkField = (prismicDocument) => {
3
+ var _a, _b, _c;
4
+ return {
5
+ link_type: LinkType.Document,
6
+ id: prismicDocument.id,
7
+ uid: (_a = prismicDocument.uid) != null ? _a : void 0,
8
+ type: prismicDocument.type,
9
+ tags: prismicDocument.tags,
10
+ lang: prismicDocument.lang,
11
+ url: (_b = prismicDocument.url) != null ? _b : void 0,
12
+ slug: (_c = prismicDocument.slugs) == null ? void 0 : _c[0],
13
+ ...prismicDocument.data && Object.keys(prismicDocument.data).length > 0 ? { data: prismicDocument.data } : {}
14
+ };
15
+ };
16
+ export {
17
+ documentToLinkField
18
+ };
19
+ //# sourceMappingURL=documentToLinkField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentToLinkField.js","sources":["../../src/helpers/documentToLinkField.ts"],"sourcesContent":["import type { PrismicDocument } from \"../types/value/document\";\nimport { LinkType } from \"../types/value/link\";\nimport type { FilledContentRelationshipField } from \"../types/value/contentRelationship\";\n\ntype SetOptional<T, Keys extends keyof T> = Omit<T, Keys> &\n\tPartial<Pick<T, Keys>>;\n\n/**\n * Converts a document into a link field, this is useful when crawling the API\n * for document links\n *\n * @typeParam TDocument - Specific interface of the provided document\n * @param prismicDocument - A document coming from Prismic\n *\n * @returns The equivalent link field to use with `asLink()`\n * @internal\n */\nexport const documentToLinkField = <\n\tTDocument extends SetOptional<PrismicDocument, \"slugs\">,\n>(\n\tprismicDocument: TDocument,\n): FilledContentRelationshipField<\n\tTDocument[\"type\"],\n\tTDocument[\"lang\"],\n\tTDocument[\"data\"]\n> => {\n\treturn {\n\t\tlink_type: LinkType.Document,\n\t\tid: prismicDocument.id,\n\t\tuid: prismicDocument.uid ?? undefined,\n\t\ttype: prismicDocument.type,\n\t\ttags: prismicDocument.tags,\n\t\tlang: prismicDocument.lang,\n\t\turl: prismicDocument.url ?? undefined,\n\t\tslug: prismicDocument.slugs?.[0], // Slug field is not available with GraphQl\n\t\t// The REST API does not include a `data` property if the data\n\t\t// object is empty.\n\t\t//\n\t\t// A presence check for `prismicDocument.data` is done to\n\t\t// support partial documents. While `documentToLinkField` is\n\t\t// not typed to accept partial documents, passing a partial\n\t\t// document can happen in untyped projects.\n\t\t...(prismicDocument.data && Object.keys(prismicDocument.data).length > 0\n\t\t\t? { data: prismicDocument.data }\n\t\t\t: {}),\n\t};\n};\n"],"names":[],"mappings":";AAiBa,MAAA,sBAAsB,CAGlC,oBAKG;;AACI,SAAA;AAAA,IACN,WAAW,SAAS;AAAA,IACpB,IAAI,gBAAgB;AAAA,IACpB,MAAK,qBAAgB,QAAhB,YAAuB;AAAA,IAC5B,MAAM,gBAAgB;AAAA,IACtB,MAAM,gBAAgB;AAAA,IACtB,MAAM,gBAAgB;AAAA,IACtB,MAAK,qBAAgB,QAAhB,YAAuB;AAAA,IAC5B,OAAM,qBAAgB,UAAhB,mBAAwB;AAAA,IAQ9B,GAAI,gBAAgB,QAAQ,OAAO,KAAK,gBAAgB,IAAI,EAAE,SAAS,IACpE,EAAE,MAAM,gBAAgB,SACxB;;AAEL;"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const isNonNullish = (input) => {
4
+ return input != null;
5
+ };
6
+ const isNonEmptyArray = (input) => {
7
+ return !!input.length;
8
+ };
9
+ const richText = (field) => {
10
+ if (!isNonNullish(field)) {
11
+ return false;
12
+ } else if (field.length === 1 && "text" in field[0]) {
13
+ return !!field[0].text;
14
+ } else {
15
+ return !!field.length;
16
+ }
17
+ };
18
+ const title = richText;
19
+ const imageThumbnail = (thumbnail) => {
20
+ return isNonNullish(thumbnail) && !!thumbnail.url;
21
+ };
22
+ const image = imageThumbnail;
23
+ const link = (field) => {
24
+ return isNonNullish(field) && ("id" in field || "url" in field);
25
+ };
26
+ const linkToMedia = link;
27
+ const contentRelationship = link;
28
+ const date = isNonNullish;
29
+ const timestamp = isNonNullish;
30
+ const color = isNonNullish;
31
+ const number = isNonNullish;
32
+ const keyText = (field) => {
33
+ return isNonNullish(keyText) && !!field;
34
+ };
35
+ const select = isNonNullish;
36
+ const embed = (field) => {
37
+ return isNonNullish(field) && !!field.embed_url;
38
+ };
39
+ const geoPoint = (field) => {
40
+ return isNonNullish(field) && "longitude" in field;
41
+ };
42
+ const integrationFields = isNonNullish;
43
+ const group = (group2) => {
44
+ return isNonNullish(group2) && isNonEmptyArray(group2);
45
+ };
46
+ const sliceZone = (slices) => {
47
+ return isNonNullish(slices) && isNonEmptyArray(slices);
48
+ };
49
+ exports.color = color;
50
+ exports.contentRelationship = contentRelationship;
51
+ exports.date = date;
52
+ exports.embed = embed;
53
+ exports.geoPoint = geoPoint;
54
+ exports.group = group;
55
+ exports.image = image;
56
+ exports.imageThumbnail = imageThumbnail;
57
+ exports.integrationFields = integrationFields;
58
+ exports.keyText = keyText;
59
+ exports.link = link;
60
+ exports.linkToMedia = linkToMedia;
61
+ exports.number = number;
62
+ exports.richText = richText;
63
+ exports.select = select;
64
+ exports.sliceZone = sliceZone;
65
+ exports.timestamp = timestamp;
66
+ exports.title = title;
67
+ //# sourceMappingURL=isFilled.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isFilled.cjs","sources":["../../src/helpers/isFilled.ts"],"sourcesContent":["import type { ColorField } from \"../types/value/color\";\nimport type { DateField } from \"../types/value/date\";\nimport type { EmbedField, AnyOEmbed } from \"../types/value/embed\";\nimport type { GeoPointField } from \"../types/value/geoPoint\";\nimport type { GroupField } from \"../types/value/group\";\nimport type { ImageFieldImage, ImageField } from \"../types/value/image\";\nimport type { IntegrationFields } from \"../types/value/integrationFields\";\nimport type { KeyTextField } from \"../types/value/keyText\";\nimport type { LinkField } from \"../types/value/link\";\nimport type { LinkToMediaField } from \"../types/value/linkToMedia\";\nimport type { ContentRelationshipField } from \"../types/value/contentRelationship\";\nimport type { NumberField } from \"../types/value/number\";\nimport type { RichTextField } from \"../types/value/richText\";\nimport type { SelectField } from \"../types/value/select\";\nimport type { SharedSlice } from \"../types/value/sharedSlice\";\nimport type { Slice } from \"../types/value/slice\";\nimport type { SliceZone } from \"../types/value/sliceZone\";\nimport type { TimestampField } from \"../types/value/timestamp\";\nimport type { TitleField } from \"../types/value/title\";\nimport type { AnyRegularField } from \"../types/value/types\";\n\n/**\n * Determines if a value is not nullish (i.e. not `null` or `undefined`). This\n * is used to check if nullable field values are filled.\n *\n * @param input - The value to check.\n *\n * @returns `true` if `input` is not nullish, `false` otherwise.\n */\nconst isNonNullish = <T>(input: T): input is NonNullable<T> => {\n\treturn input != null;\n};\n\n/**\n * Determines if an array is not empty. This is used to check if array-based\n * fields are filled.\n *\n * @param input - The array to check.\n *\n * @returns `true` if `input` has at least one element, `false` otherwise.\n */\nconst isNonEmptyArray = <T>(input: T[]): input is [T, ...T[]] => {\n\treturn !!input.length;\n};\n\n/**\n * Determines if a Rich Text field is filled.\n *\n * @param field - Rich Text field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const richText = (\n\tfield: RichTextField | null | undefined,\n): field is RichTextField<\"filled\"> => {\n\tif (!isNonNullish(field)) {\n\t\treturn false;\n\t} else if (field.length === 1 && \"text\" in field[0]) {\n\t\treturn !!field[0].text;\n\t} else {\n\t\treturn !!field.length;\n\t}\n};\n\n/**\n * Determines if a Title field is filled.\n *\n * @param field - Title field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const title = richText as (\n\tfield: TitleField | null | undefined,\n) => field is TitleField<\"filled\">;\n\n/**\n * Determines if an Image thumbnail is filled.\n *\n * @param thumbnail - Image thumbnail to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const imageThumbnail = (\n\tthumbnail: ImageFieldImage | null | undefined,\n): thumbnail is ImageFieldImage<\"filled\"> => {\n\treturn isNonNullish(thumbnail) && !!thumbnail.url;\n};\n\n/**\n * Determines if an Image field is filled.\n *\n * @param field - Image field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const image = imageThumbnail as <\n\tThumbnailNames extends string | null = never,\n>(\n\tfield: ImageField<ThumbnailNames> | null | undefined,\n) => field is ImageField<ThumbnailNames, \"filled\">;\n\n/**\n * Determines if a Link field is filled.\n *\n * @param field - Link field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const link = <\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends Record<\n\t\tstring,\n\t\tAnyRegularField | GroupField | SliceZone\n\t> = never,\n>(\n\tfield: LinkField<TypeEnum, LangEnum, DataInterface> | null | undefined,\n): field is LinkField<TypeEnum, LangEnum, DataInterface, \"filled\"> => {\n\treturn isNonNullish(field) && (\"id\" in field || \"url\" in field);\n};\n\n/**\n * Determines if a Link to Media field is filled.\n *\n * @param field - Link to Media field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const linkToMedia = link as (\n\tfield: LinkToMediaField | null | undefined,\n) => field is LinkToMediaField<\"filled\">;\n\n/**\n * Determines if a Content Relationship field is filled.\n *\n * @param field - Content Relationship field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const contentRelationship = link as <\n\tTypeEnum = string,\n\tLangEnum = string,\n\tDataInterface extends Record<\n\t\tstring,\n\t\tAnyRegularField | GroupField | SliceZone\n\t> = never,\n>(\n\tfield:\n\t\t| ContentRelationshipField<TypeEnum, LangEnum, DataInterface>\n\t\t| null\n\t\t| undefined,\n) => field is ContentRelationshipField<\n\tTypeEnum,\n\tLangEnum,\n\tDataInterface,\n\t\"filled\"\n>;\n\n/**\n * Determines if a Date field is filled.\n *\n * @param field - Date field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const date = isNonNullish as (\n\tfield: DateField | null | undefined,\n) => field is DateField<\"filled\">;\n\n/**\n * Determines if a Timestamp field is filled.\n *\n * @param field - Timestamp field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const timestamp = isNonNullish as (\n\tfield: TimestampField | null | undefined,\n) => field is TimestampField<\"filled\">;\n\n/**\n * Determines if a Color field is filled.\n *\n * @param field - Color field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const color = isNonNullish as (\n\tfield: ColorField | null | undefined,\n) => field is ColorField<\"filled\">;\n\n/**\n * Determines if a Number field is filled.\n *\n * @param field - Number field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const number = isNonNullish as (\n\tfield: NumberField | null | undefined,\n) => field is NumberField<\"filled\">;\n\n/**\n * Determines if a Key Text field is filled.\n *\n * @param field - Key Text field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const keyText = (\n\tfield: KeyTextField | null | undefined,\n): field is KeyTextField<\"filled\"> => {\n\treturn isNonNullish(keyText) && !!field;\n};\n\n/**\n * Determines if a Select field is filled.\n *\n * @param field - Select field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const select = isNonNullish as <Enum extends string>(\n\tfield: SelectField<Enum> | null | undefined,\n) => field is SelectField<Enum, \"filled\">;\n\n/**\n * Determines if an Embed field is filled.\n *\n * @param field - Embed field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const embed = <Field extends EmbedField<AnyOEmbed>>(\n\tfield: Field | null | undefined,\n): field is Extract<Field, EmbedField<AnyOEmbed, \"filled\">> => {\n\treturn isNonNullish(field) && !!field.embed_url;\n};\n\n/**\n * Determines if a GeoPoint field is filled.\n *\n * @param field - GeoPoint field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const geoPoint = (\n\tfield: GeoPointField | null | undefined,\n): field is GeoPointField<\"filled\"> => {\n\treturn isNonNullish(field) && \"longitude\" in field;\n};\n\n/**\n * Determines if an Integration Fields field is filled.\n *\n * @param field - Integration Fields field to check.\n *\n * @returns `true` if `field` is filled, `false` otherwise.\n */\nexport const integrationFields = isNonNullish as <\n\tData extends Record<string, unknown>,\n>(\n\tfield: IntegrationFields<Data> | null | undefined,\n) => field is IntegrationFields<Data, \"filled\">;\n\n/**\n * Determines if a Group has at least one item.\n *\n * @param group - Group to check.\n *\n * @returns `true` if `group` contains at least one item, `false` otherwise.\n */\nexport const group = <Fields extends Record<string, AnyRegularField>>(\n\tgroup: GroupField<Fields> | null | undefined,\n): group is GroupField<Fields, \"filled\"> => {\n\treturn isNonNullish(group) && isNonEmptyArray(group);\n};\n\n/**\n * Determines if a Slice Zone has at least one Slice.\n *\n * @param slices - Slice Zone to check.\n *\n * @returns `true` if `slices` contains at least one Slice, `false` otherwise.\n */\nexport const sliceZone = <Slices extends Slice | SharedSlice>(\n\tslices: SliceZone<Slices> | null | undefined,\n): slices is SliceZone<Slices, \"filled\"> => {\n\treturn isNonNullish(slices) && isNonEmptyArray(slices);\n};\n"],"names":["group"],"mappings":";;AA6BA,MAAM,eAAe,CAAI,UAAqC;AAC7D,SAAO,SAAS;AACjB;AAUA,MAAM,kBAAkB,CAAI,UAAoC;AACxD,SAAA,CAAC,CAAC,MAAM;AAChB;AASa,MAAA,WAAW,CACvB,UACqC;AACjC,MAAA,CAAC,aAAa,KAAK,GAAG;AAClB,WAAA;AAAA,EAAA,WACG,MAAM,WAAW,KAAK,UAAU,MAAM,IAAI;AAC7C,WAAA,CAAC,CAAC,MAAM,GAAG;AAAA,EAAA,OACZ;AACC,WAAA,CAAC,CAAC,MAAM;AAAA,EACf;AACF;AASO,MAAM,QAAQ;AAWR,MAAA,iBAAiB,CAC7B,cAC2C;AAC3C,SAAO,aAAa,SAAS,KAAK,CAAC,CAAC,UAAU;AAC/C;AASO,MAAM,QAAQ;AAaR,MAAA,OAAO,CAQnB,UACoE;AACpE,SAAO,aAAa,KAAK,MAAM,QAAQ,SAAS,SAAS;AAC1D;AASO,MAAM,cAAc;AAWpB,MAAM,sBAAsB;AA0B5B,MAAM,OAAO;AAWb,MAAM,YAAY;AAWlB,MAAM,QAAQ;AAWd,MAAM,SAAS;AAWT,MAAA,UAAU,CACtB,UACoC;AACpC,SAAO,aAAa,OAAO,KAAK,CAAC,CAAC;AACnC;AASO,MAAM,SAAS;AAWT,MAAA,QAAQ,CACpB,UAC6D;AAC7D,SAAO,aAAa,KAAK,KAAK,CAAC,CAAC,MAAM;AACvC;AASa,MAAA,WAAW,CACvB,UACqC;AAC9B,SAAA,aAAa,KAAK,KAAK,eAAe;AAC9C;AASO,MAAM,oBAAoB;AAapB,MAAA,QAAQ,CACpBA,WAC0C;AAC1C,SAAO,aAAaA,MAAK,KAAK,gBAAgBA,MAAK;AACpD;AASa,MAAA,YAAY,CACxB,WAC0C;AAC1C,SAAO,aAAa,MAAM,KAAK,gBAAgB,MAAM;AACtD;;;;;;;;;;;;;;;;;;;"}