@prismicio/client 7.17.0 → 7.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseClient.cjs.map +1 -1
- package/dist/BaseClient.js.map +1 -1
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.js.map +1 -1
- package/dist/Migration.cjs.map +1 -1
- package/dist/Migration.js.map +1 -1
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.js.map +1 -1
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/errors/PrismicError.cjs.map +1 -1
- package/dist/errors/PrismicError.js.map +1 -1
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.js.map +1 -1
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.js +1 -1
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.js +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.js +1 -1
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +1 -1
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.js.map +1 -1
- package/dist/lib/appendFilters.cjs.map +1 -1
- package/dist/lib/appendFilters.js.map +1 -1
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js.map +1 -1
- package/dist/lib/everyTagFilter.cjs.map +1 -1
- package/dist/lib/findMasterRef.cjs.map +1 -1
- package/dist/lib/findRef.cjs.map +1 -1
- package/dist/lib/findRef.js.map +1 -1
- package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
- package/dist/lib/getOptionalLinkProperties.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isMigrationValue.cjs.map +1 -1
- package/dist/lib/isValue.cjs.map +1 -1
- package/dist/lib/isValue.js.map +1 -1
- package/dist/lib/pLimit.cjs.map +1 -1
- package/dist/lib/pLimit.js.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/someTagsFilter.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.js.map +1 -1
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.js.map +1 -1
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/types/migration/Asset.cjs.map +1 -1
- package/dist/types/migration/Asset.js.map +1 -1
- package/dist/types/migration/Document.cjs.map +1 -1
- package/dist/types/migration/Document.js.map +1 -1
- package/package.json +13 -13
package/dist/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sources":["../../src/filter.ts"],"sourcesContent":["/**\n * Formats the value of a filter element to a stringified version accepted by\n * the Prismic REST API.\n *\n * @param value - Value to format.\n *\n * @returns `value` formatted for the Prismic REST API.\n */\nconst formatValue = (\n\tvalue:\n\t\t| string\n\t\t| number\n\t\t| Date\n\t\t| unknown\n\t\t| (string | number | Date | unknown)[],\n): string => {\n\tif (Array.isArray(value)) {\n\t\treturn `[${value.map(formatValue).join(\", \")}]`\n\t}\n\n\tif (typeof value === \"string\") {\n\t\treturn `\"${value}\"`\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn `${value.getTime()}`\n\t}\n\n\treturn `${value}`\n}\n\n/**\n * Creates a filter builder function for filters with a path and arguments.\n *\n * @typeParam Args - Arguments for the filter.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathWithArgsFilter = <Args extends unknown[]>(name: string) => {\n\t/**\n\t * @param path - Path to the value to be compared.\n\t */\n\tconst fn = (path: string, ...args: Args): string => {\n\t\tconst formattedArgs = args.map(formatValue).join(\", \")\n\t\tconst joiner = path && args.length ? \", \" : \"\"\n\n\t\treturn `[${name}(${path}${joiner}${formattedArgs})]`\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only a path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathFilter = (name: string) => {\n\tconst filterFn = pathWithArgsFilter(name)\n\n\t/**\n\t * @param path - Path for the filter.\n\t */\n\tconst fn = (path: string): string => {\n\t\treturn filterFn(path)\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only arguments and no\n * path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst argsFilter = <Args extends unknown[]>(name: string) => {\n\tconst filterFn = pathWithArgsFilter<Args>(name)\n\n\t/**\n\t * @param args - Arguments for the filter.\n\t */\n\tconst fn = (...args: Args): string => {\n\t\treturn filterFn(\"\", ...args)\n\t}\n\n\treturn fn\n}\n\nexport const filter = {\n\t/**\n\t * The `at` filter checks that the path matches the described value exactly.\n\t * It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#at}\n\t */\n\tat: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"at\",\n\t),\n\n\t/**\n\t * The `not` filter checks that the path doesn't match the provided value\n\t * exactly. It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#not}\n\t */\n\tnot: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"not\",\n\t),\n\n\t/**\n\t * The `any` filter takes an array of values. It works exactly the same way as\n\t * the `at` operator, but checks whether the fragment matches any of the\n\t * values in the array.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#any}\n\t */\n\tany: pathWithArgsFilter<[values: (string | number | boolean | Date)[]]>(\n\t\t\"any\",\n\t),\n\n\t/**\n\t * The `in` filter is used specifically to retrieve an array of documents by\n\t * their IDs or UIDs. This filter is much more efficient at this than the any\n\t * filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#in}\n\t */\n\tin: pathWithArgsFilter<[values: string[]]>(\"in\"),\n\n\t/**\n\t * The `fulltext` filter provides two capabilities:\n\t *\n\t * 1. Checking if a certain string is anywhere inside a document (this is what\n\t * you should use to make your project's search engine feature)\n\t * 2. Checking if the string is contained inside a specific custom type’s Rich\n\t * Text or Key Text fragment.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fulltext}\n\t */\n\tfulltext: pathWithArgsFilter<[searchTerms: string]>(\"fulltext\"),\n\n\t/**\n\t * The `has` filter checks whether a fragment has a value. It will return all\n\t * the documents of the specified type that contain a value for the specified\n\t * field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#has}\n\t */\n\thas: pathFilter(\"has\"),\n\n\t/**\n\t * The `missing` filter checks if a fragment doesn't have a value. It will\n\t * return all the documents of the specified type that do not contain a value\n\t * for the specified field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#missing}\n\t */\n\tmissing: pathFilter(\"missing\"),\n\n\t/**\n\t * The `similar` filter takes the ID of a document, and returns a list of\n\t * documents with similar content. This allows you to build an automated\n\t * content discovery feature (for example, a \"Related posts\" section).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#similar}\n\t */\n\tsimilar: argsFilter<[id: string, value: number]>(\"similar\"),\n\n\t/**\n\t * The `geopoint.near` filter checks that the value in the path is within the\n\t * radius of the given coordinates.\n\t *\n\t * This filter will only work for a geopoint field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#geopointnear}\n\t */\n\tgeopointNear:\n\t\tpathWithArgsFilter<[latitude: number, longitude: number, radius: number]>(\n\t\t\t\"geopoint.near\",\n\t\t),\n\n\t/**\n\t * The `number.lt` filter checks that the value in the number field is less\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberlessthan}\n\t */\n\tnumberLessThan: pathWithArgsFilter<[value: number]>(\"number.lt\"),\n\n\t/**\n\t * The `number.gt` filter checks that the value in the number field is greater\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numbergreaterthan}\n\t */\n\tnumberGreaterThan: pathWithArgsFilter<[value: number]>(\"number.gt\"),\n\n\t/**\n\t * The `number.inRange` filter checks that the value in the path is within the\n\t * two values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberinrange}\n\t */\n\tnumberInRange:\n\t\tpathWithArgsFilter<[lowerLimit: number, upperLimit: number]>(\n\t\t\t\"number.inRange\",\n\t\t),\n\n\t/**\n\t * The `date.after` filter checks that the value in the path is after the date\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateAfter: pathWithArgsFilter<[date: string | number | Date]>(\"date.after\"),\n\n\t/**\n\t * The `date.before` filter checks that the value in the path is before the\n\t * date value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBefore: pathWithArgsFilter<[date: string | number | Date]>(\"date.before\"),\n\n\t/**\n\t * The `date.between` filter checks that the value in the path is within the\n\t * date values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBetween:\n\t\tpathWithArgsFilter<\n\t\t\t[startDate: string | number | Date, endDate: string | number | Date]\n\t\t>(\"date.between\"),\n\n\t/**\n\t * The `date.day-of-month` filter checks that the value in the path is equal\n\t * to the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonth: pathWithArgsFilter<[day: number]>(\"date.day-of-month\"),\n\n\t/**\n\t * The `date.day-of-month-after` filter checks that the value in the path is\n\t * after the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthAfter: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-after\",\n\t),\n\n\t/**\n\t * The `date.day-of-month-before` filter checks that the value in the path is\n\t * before the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthBefore: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-before\",\n\t),\n\n\t/**\n\t * The `date.day-of-week` filter checks that the value in the path is equal to\n\t * the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeek: pathWithArgsFilter<[day: string | number]>(\"date.day-of-week\"),\n\n\t/**\n\t * The `date.day-of-week-after` filter checks that the value in the path is\n\t * after the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekAfter: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-after\",\n\t),\n\n\t/**\n\t * The date.day-of-week-before filter checks that the value in the path is\n\t * before the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekBefore: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-before\",\n\t),\n\n\t/**\n\t * The `date.month` filter checks that the value in the path occurs in the\n\t * month value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonth: pathWithArgsFilter<[month: string | number]>(\"date.month\"),\n\n\t/**\n\t * The `date.month-after` filter checks that the value in the path occurs in\n\t * any month after the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthAfter:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-after\"),\n\n\t/**\n\t * The `date.month-before` filter checks that the value in the path occurs in\n\t * any month before the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthBefore:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-before\"),\n\n\t/**\n\t * The `date.year` filter checks that the value in the path occurs in the year\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateYear: pathWithArgsFilter<[year: number]>(\"date.year\"),\n\n\t/**\n\t * The `date.hour` filter checks that the value in the path occurs within the\n\t * hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHour: pathWithArgsFilter<[hour: number]>(\"date.hour\"),\n\n\t/**\n\t * The `date.hour-after` filter checks that the value in the path occurs after\n\t * the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourAfter: pathWithArgsFilter<[hour: number]>(\"date.hour-after\"),\n\n\t/**\n\t * The `date.hour-before` filter checks that the value in the path occurs\n\t * before the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourBefore: pathWithArgsFilter<[hour: number]>(\"date.hour-before\"),\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"filter.js","sources":["../../src/filter.ts"],"sourcesContent":["/**\n * Formats the value of a filter element to a stringified version accepted by\n * the Prismic REST API.\n *\n * @param value - Value to format.\n *\n * @returns `value` formatted for the Prismic REST API.\n */\nconst formatValue = (\n\tvalue:\n\t\t| string\n\t\t| number\n\t\t| Date\n\t\t| unknown\n\t\t| (string | number | Date | unknown)[],\n): string => {\n\tif (Array.isArray(value)) {\n\t\treturn `[${value.map(formatValue).join(\", \")}]`\n\t}\n\n\tif (typeof value === \"string\") {\n\t\treturn `\"${value}\"`\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn `${value.getTime()}`\n\t}\n\n\treturn `${value}`\n}\n\n/**\n * Creates a filter builder function for filters with a path and arguments.\n *\n * @typeParam Args - Arguments for the filter.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathWithArgsFilter = <Args extends unknown[]>(name: string) => {\n\t/**\n\t * @param path - Path to the value to be compared.\n\t */\n\tconst fn = (path: string, ...args: Args): string => {\n\t\tconst formattedArgs = args.map(formatValue).join(\", \")\n\t\tconst joiner = path && args.length ? \", \" : \"\"\n\n\t\treturn `[${name}(${path}${joiner}${formattedArgs})]`\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only a path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst pathFilter = (name: string) => {\n\tconst filterFn = pathWithArgsFilter(name)\n\n\t/**\n\t * @param path - Path for the filter.\n\t */\n\tconst fn = (path: string): string => {\n\t\treturn filterFn(path)\n\t}\n\n\treturn fn\n}\n\n/**\n * Creates a filter builder function for filters with only arguments and no\n * path.\n *\n * @param name - Name of the filter used in the resulting string.\n *\n * @returns Filter builder function for the given name.\n */\nconst argsFilter = <Args extends unknown[]>(name: string) => {\n\tconst filterFn = pathWithArgsFilter<Args>(name)\n\n\t/**\n\t * @param args - Arguments for the filter.\n\t */\n\tconst fn = (...args: Args): string => {\n\t\treturn filterFn(\"\", ...args)\n\t}\n\n\treturn fn\n}\n\nexport const filter = {\n\t/**\n\t * The `at` filter checks that the path matches the described value exactly.\n\t * It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#at}\n\t */\n\tat: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"at\",\n\t),\n\n\t/**\n\t * The `not` filter checks that the path doesn't match the provided value\n\t * exactly. It takes a single value for a field or an array (only for tags).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#not}\n\t */\n\tnot: pathWithArgsFilter<[value: string | number | boolean | Date | string[]]>(\n\t\t\"not\",\n\t),\n\n\t/**\n\t * The `any` filter takes an array of values. It works exactly the same way as\n\t * the `at` operator, but checks whether the fragment matches any of the\n\t * values in the array.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#any}\n\t */\n\tany: pathWithArgsFilter<[values: (string | number | boolean | Date)[]]>(\n\t\t\"any\",\n\t),\n\n\t/**\n\t * The `in` filter is used specifically to retrieve an array of documents by\n\t * their IDs or UIDs. This filter is much more efficient at this than the any\n\t * filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#in}\n\t */\n\tin: pathWithArgsFilter<[values: string[]]>(\"in\"),\n\n\t/**\n\t * The `fulltext` filter provides two capabilities:\n\t *\n\t * 1. Checking if a certain string is anywhere inside a document (this is what\n\t * you should use to make your project's search engine feature)\n\t * 2. Checking if the string is contained inside a specific custom type’s Rich\n\t * Text or Key Text fragment.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#fulltext}\n\t */\n\tfulltext: pathWithArgsFilter<[searchTerms: string]>(\"fulltext\"),\n\n\t/**\n\t * The `has` filter checks whether a fragment has a value. It will return all\n\t * the documents of the specified type that contain a value for the specified\n\t * field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#has}\n\t */\n\thas: pathFilter(\"has\"),\n\n\t/**\n\t * The `missing` filter checks if a fragment doesn't have a value. It will\n\t * return all the documents of the specified type that do not contain a value\n\t * for the specified field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#missing}\n\t */\n\tmissing: pathFilter(\"missing\"),\n\n\t/**\n\t * The `similar` filter takes the ID of a document, and returns a list of\n\t * documents with similar content. This allows you to build an automated\n\t * content discovery feature (for example, a \"Related posts\" section).\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#similar}\n\t */\n\tsimilar: argsFilter<[id: string, value: number]>(\"similar\"),\n\n\t/**\n\t * The `geopoint.near` filter checks that the value in the path is within the\n\t * radius of the given coordinates.\n\t *\n\t * This filter will only work for a geopoint field.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#geopointnear}\n\t */\n\tgeopointNear:\n\t\tpathWithArgsFilter<[latitude: number, longitude: number, radius: number]>(\n\t\t\t\"geopoint.near\",\n\t\t),\n\n\t/**\n\t * The `number.lt` filter checks that the value in the number field is less\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberlessthan}\n\t */\n\tnumberLessThan: pathWithArgsFilter<[value: number]>(\"number.lt\"),\n\n\t/**\n\t * The `number.gt` filter checks that the value in the number field is greater\n\t * than the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numbergreaterthan}\n\t */\n\tnumberGreaterThan: pathWithArgsFilter<[value: number]>(\"number.gt\"),\n\n\t/**\n\t * The `number.inRange` filter checks that the value in the path is within the\n\t * two values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#numberinrange}\n\t */\n\tnumberInRange:\n\t\tpathWithArgsFilter<[lowerLimit: number, upperLimit: number]>(\n\t\t\t\"number.inRange\",\n\t\t),\n\n\t/**\n\t * The `date.after` filter checks that the value in the path is after the date\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateAfter: pathWithArgsFilter<[date: string | number | Date]>(\"date.after\"),\n\n\t/**\n\t * The `date.before` filter checks that the value in the path is before the\n\t * date value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBefore: pathWithArgsFilter<[date: string | number | Date]>(\"date.before\"),\n\n\t/**\n\t * The `date.between` filter checks that the value in the path is within the\n\t * date values passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateBetween:\n\t\tpathWithArgsFilter<\n\t\t\t[startDate: string | number | Date, endDate: string | number | Date]\n\t\t>(\"date.between\"),\n\n\t/**\n\t * The `date.day-of-month` filter checks that the value in the path is equal\n\t * to the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonth: pathWithArgsFilter<[day: number]>(\"date.day-of-month\"),\n\n\t/**\n\t * The `date.day-of-month-after` filter checks that the value in the path is\n\t * after the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthAfter: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-after\",\n\t),\n\n\t/**\n\t * The `date.day-of-month-before` filter checks that the value in the path is\n\t * before the day of the month passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfMonthBefore: pathWithArgsFilter<[day: number]>(\n\t\t\"date.day-of-month-before\",\n\t),\n\n\t/**\n\t * The `date.day-of-week` filter checks that the value in the path is equal to\n\t * the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeek: pathWithArgsFilter<[day: string | number]>(\"date.day-of-week\"),\n\n\t/**\n\t * The `date.day-of-week-after` filter checks that the value in the path is\n\t * after the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekAfter: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-after\",\n\t),\n\n\t/**\n\t * The date.day-of-week-before filter checks that the value in the path is\n\t * before the day of the week passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateDayOfWeekBefore: pathWithArgsFilter<[day: string | number]>(\n\t\t\"date.day-of-week-before\",\n\t),\n\n\t/**\n\t * The `date.month` filter checks that the value in the path occurs in the\n\t * month value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonth: pathWithArgsFilter<[month: string | number]>(\"date.month\"),\n\n\t/**\n\t * The `date.month-after` filter checks that the value in the path occurs in\n\t * any month after the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthAfter:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-after\"),\n\n\t/**\n\t * The `date.month-before` filter checks that the value in the path occurs in\n\t * any month before the value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateMonthBefore:\n\t\tpathWithArgsFilter<[month: string | number]>(\"date.month-before\"),\n\n\t/**\n\t * The `date.year` filter checks that the value in the path occurs in the year\n\t * value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateYear: pathWithArgsFilter<[year: number]>(\"date.year\"),\n\n\t/**\n\t * The `date.hour` filter checks that the value in the path occurs within the\n\t * hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHour: pathWithArgsFilter<[hour: number]>(\"date.hour\"),\n\n\t/**\n\t * The `date.hour-after` filter checks that the value in the path occurs after\n\t * the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourAfter: pathWithArgsFilter<[hour: number]>(\"date.hour-after\"),\n\n\t/**\n\t * The `date.hour-before` filter checks that the value in the path occurs\n\t * before the hour value passed into the filter.\n\t *\n\t * {@link https://prismic.io/docs/rest-api-technical-reference#date-filters}\n\t */\n\tdateHourBefore: pathWithArgsFilter<[hour: number]>(\"date.hour-before\"),\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGraphQLEndpoint.cjs","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAaa,MAAA,qBAAqB,CACjC,mBACuD;AACnD,MAAAA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAIC,
|
|
1
|
+
{"version":3,"file":"getGraphQLEndpoint.cjs","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAaa,MAAA,qBAAqB,CACjC,mBACuD;AACnD,MAAAA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAIC,aACT,aAAA,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAAA;AAGZ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGraphQLEndpoint.js","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAaa,MAAA,qBAAqB,CACjC,mBACuD;AACnD,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,
|
|
1
|
+
{"version":3,"file":"getGraphQLEndpoint.js","sources":["../../src/getGraphQLEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic GraphQL endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic REST API V2 endpoint\n */\nexport const getGraphQLEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/graphql` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/graphql` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAaa,MAAA,qBAAqB,CACjC,mBACuD;AACnD,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAAA;AAGZ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryEndpoint.cjs","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic Rest API V2 endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic Rest API V2 endpoint\n *\n * @throws {@link Error} Thrown if an invalid repository name is provided.\n */\nexport const getRepositoryEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/api/v2` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/api/v2` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAea,MAAA,wBAAwB,CACpC,mBACsD;AAClD,MAAAA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAIC,
|
|
1
|
+
{"version":3,"file":"getRepositoryEndpoint.cjs","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic Rest API V2 endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic Rest API V2 endpoint\n *\n * @throws {@link Error} Thrown if an invalid repository name is provided.\n */\nexport const getRepositoryEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/api/v2` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/api/v2` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAea,MAAA,wBAAwB,CACpC,mBACsD;AAClD,MAAAA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAIC,aACT,aAAA,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAAA;AAGZ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryEndpoint.js","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic Rest API V2 endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic Rest API V2 endpoint\n *\n * @throws {@link Error} Thrown if an invalid repository name is provided.\n */\nexport const getRepositoryEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/api/v2` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/api/v2` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAea,MAAA,wBAAwB,CACpC,mBACsD;AAClD,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,
|
|
1
|
+
{"version":3,"file":"getRepositoryEndpoint.js","sources":["../../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic Rest API V2 endpoint.\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic Rest API V2 endpoint\n *\n * @throws {@link Error} Thrown if an invalid repository name is provided.\n */\nexport const getRepositoryEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/api/v2` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/api/v2` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAea,MAAA,wBAAwB,CACpC,mBACsD;AAClD,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,WAAW,cAAc;AAAA,EAAA,OAC1B;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAAA;AAGZ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryName.cjs","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":["PrismicError"],"mappings":";;;AAaa,MAAA,oBAAoB,CAAC,uBAAsC;AACnE,MAAA;AACH,UAAM,WAAW,IAAI,IAAI,kBAAkB,EAAE;AAG5C,QAAA,SAAS,SAAS,YAAY;AAAA,IAC9B,SAAS,SAAS,UAAU;AAAA,IAC5B,SAAS,SAAS,YAAY,GAC7B;AACD,aAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,
|
|
1
|
+
{"version":3,"file":"getRepositoryName.cjs","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":["PrismicError"],"mappings":";;;AAaa,MAAA,oBAAoB,CAAC,uBAAsC;AACnE,MAAA;AACH,UAAM,WAAW,IAAI,IAAI,kBAAkB,EAAE;AAG5C,QAAA,SAAS,SAAS,YAAY;AAAA,IAC9B,SAAS,SAAS,UAAU;AAAA,IAC5B,SAAS,SAAS,YAAY,GAC7B;AACD,aAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,IAAA;AAAA,EAC7B,QACO;AAAA,EAAA;AAER,QAAM,IAAIA,aACT,aAAA,0DAA0D,kBAAkB,IAC5E,QACA,MAAS;AAEX;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryName.js","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":[],"mappings":";AAaa,MAAA,oBAAoB,CAAC,uBAAsC;AACnE,MAAA;AACH,UAAM,WAAW,IAAI,IAAI,kBAAkB,EAAE;AAG5C,QAAA,SAAS,SAAS,YAAY;AAAA,IAC9B,SAAS,SAAS,UAAU;AAAA,IAC5B,SAAS,SAAS,YAAY,GAC7B;AACD,aAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,
|
|
1
|
+
{"version":3,"file":"getRepositoryName.js","sources":["../../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"names":[],"mappings":";AAaa,MAAA,oBAAoB,CAAC,uBAAsC;AACnE,MAAA;AACH,UAAM,WAAW,IAAI,IAAI,kBAAkB,EAAE;AAG5C,QAAA,SAAS,SAAS,YAAY;AAAA,IAC9B,SAAS,SAAS,UAAU;AAAA,IAC5B,SAAS,SAAS,YAAY,GAC7B;AACD,aAAO,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,IAAA;AAAA,EAC7B,QACO;AAAA,EAAA;AAER,QAAM,IAAI,aACT,0DAA0D,kBAAkB,IAC5E,QACA,MAAS;AAEX;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getToolbarSrc.cjs","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAqCa,MAAA,gBAAgB,CAC5B,mBACgF;AAC5E,MAAAA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D,cAAc;AAAA,EAAA,OACzE;AACN,UAAM,IAAIC,
|
|
1
|
+
{"version":3,"file":"getToolbarSrc.cjs","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAqCa,MAAA,gBAAgB,CAC5B,mBACgF;AAC5E,MAAAA,iBAAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D,cAAc;AAAA,EAAA,OACzE;AACN,UAAM,IAAIC,aACT,aAAA,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAAA;AAGZ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getToolbarSrc.js","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAqCa,MAAA,gBAAgB,CAC5B,mBACgF;AAC5E,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D,cAAc;AAAA,EAAA,OACzE;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,
|
|
1
|
+
{"version":3,"file":"getToolbarSrc.js","sources":["../../src/getToolbarSrc.ts"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Returns the URL for a Prismic repository's Prismic Toolbar script. Use the\n * URL to inject the script into your app.\n *\n * @example\n *\n * ```typescriptreact\n * // In Next.js apps, use `next/script` in your `app/layout.tsx` file.\n *\n * import Script from \"next/script\";\n * import * as prismic from \"@prismicio/client\";\n *\n * export default function RootLayout({\n * \tchildren,\n * }: {\n * \tchildren: React.ReactNode,\n * }) {\n * \tconst toolbarSrc = prismic.getToolbarSrc(\"my-repo\");\n *\n * \treturn (\n * \t\t<html lang=\"en\">\n * \t\t\t<body>{children}</body>\n * \t\t\t<Script src={toolbarSrc} />\n * \t\t</html>\n * \t);\n * }\n * ```\n *\n * @param repositoryName - The name of the Prismic repository. For example,\n * `\"my-repo\"` if the repository URL is `my-repo.prismic.io`.\n *\n * @returns The URL for the given Prismic repository's Prismic Toolbar script.\n */\nexport const getToolbarSrc = <TRepositoryName extends string>(\n\trepositoryName: TRepositoryName,\n): `https://static.cdn.prismic.io/prismic.js?new=true&repo=${TRepositoryName}` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";;AAqCa,MAAA,gBAAgB,CAC5B,mBACgF;AAC5E,MAAA,iBAAiB,cAAc,GAAG;AACrC,WAAO,0DAA0D,cAAc;AAAA,EAAA,OACzE;AACN,UAAM,IAAI,aACT,iDAAiD,cAAc,IAC/D,QACA,MAAS;AAAA,EAAA;AAGZ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asDate.cjs","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n * Transforms a date or timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n *\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":";;AAmBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"asDate.cjs","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n * Transforms a date or timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n *\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":";;AAmBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,EAAA;AAIJ,MAAA,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAAA,OAE/D;AAEC,WAAA,IAAI,KAAK,oBAAoB;AAAA,EAAA;AAEtC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asDate.js","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n * Transforms a date or timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n *\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":"AAmBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"asDate.js","sources":["../../../src/helpers/asDate.ts"],"sourcesContent":["import type { DateField } from \"../types/value/date\"\nimport type { TimestampField } from \"../types/value/timestamp\"\n\n/**\n * The return type of `asDate()`.\n */\ntype AsDateReturnType<\n\tField extends DateField | TimestampField | null | undefined,\n> = Field extends DateField<\"filled\"> | TimestampField<\"filled\"> ? Date : null\n\n/**\n * Transforms a date or timestamp field into a JavaScript Date object\n *\n * @param dateOrTimestampField - A date or timestamp field from Prismic\n *\n * @returns A Date object, null if provided date is falsy\n *\n * @see Templating date field from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#date-and-timestamp}\n */\nexport const asDate = <\n\tField extends DateField | TimestampField | null | undefined,\n>(\n\tdateOrTimestampField: Field,\n): AsDateReturnType<Field> => {\n\tif (!dateOrTimestampField) {\n\t\treturn null as AsDateReturnType<Field>\n\t}\n\n\t// If field is a timestamp field...\n\tif (dateOrTimestampField.length === 24) {\n\t\t/**\n\t\t * Converts basic ISO 8601 to ECMAScript simplified ISO 8601 format for\n\t\t * browser compatibility issues\n\t\t *\n\t\t * From: YYYY-MM-DDTHH:mm:ssZ To: YYYY-MM-DDTHH:mm:ss.sssZ\n\t\t *\n\t\t * @see MDN documentation: {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#timestamp_string}\n\t\t * @see ECMAScript 2020 language specification: {@link https://262.ecma-international.org/11.0/#sec-date-time-string-format}\n\t\t * @see Related forum issue: {@link https://community.prismic.io/t/prismics-date-api/2520}\n\t\t * @see Regex101 expression: {@link https://regex101.com/r/jxyETT/1}\n\t\t */\n\t\treturn new Date(\n\t\t\tdateOrTimestampField.replace(/(\\+|-)(\\d{2})(\\d{2})$/, \".000$1$2:$3\"),\n\t\t) as AsDateReturnType<Field>\n\t} else {\n\t\t// ...else field is a date field\n\t\treturn new Date(dateOrTimestampField) as AsDateReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":"AAmBa,MAAA,SAAS,CAGrB,yBAC4B;AAC5B,MAAI,CAAC,sBAAsB;AACnB,WAAA;AAAA,EAAA;AAIJ,MAAA,qBAAqB,WAAW,IAAI;AAYvC,WAAO,IAAI,KACV,qBAAqB,QAAQ,yBAAyB,aAAa,CAAC;AAAA,EAAA,OAE/D;AAEC,WAAA,IAAI,KAAK,oBAAoB;AAAA,EAAA;AAEtC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asHTML.cjs","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tserializeEmbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text or title field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text or title field with a map or a function to\n * HTML\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it you're\n\t * expected to use the `routes` options from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer, unhandled cases will fallback to the\n\t * default serializer\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param config - Configuration that determines the output of `asHTML()`\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param linkResolver - An optional link resolver function to resolve links,\n\t * without it you're expected to use the `routes` options from the API\n\t * @param serializer - An optional rich text serializer, unhandled cases will\n\t * fallback to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":["serializeStandardTag","serializePreFormatted","serializeImage","serializeEmbed","serializeHyperlink","serializeSpan","wrapMapSerializer","composeSerializers","serialize"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"asHTML.cjs","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tserializeEmbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text or title field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text or title field with a map or a function to\n * HTML\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it you're\n\t * expected to use the `routes` options from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer, unhandled cases will fallback to the\n\t * default serializer\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param config - Configuration that determines the output of `asHTML()`\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param linkResolver - An optional link resolver function to resolve links,\n\t * without it you're expected to use the `routes` options from the API\n\t * @param serializer - An optional rich text serializer, unhandled cases will\n\t * fallback to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":["serializeStandardTag","serializePreFormatted","serializeImage","serializeEmbed","serializeHyperlink","serializeSpan","wrapMapSerializer","composeSerializers","serialize"],"mappings":"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"}
|
package/dist/helpers/asHTML.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { serializeStandardTag,
|
|
1
|
+
import { serializeStandardTag, serializeHyperlink, serializeEmbed, serializeImage, serializePreFormatted, serializeSpan } from "../lib/serializerHelpers.js";
|
|
2
2
|
import { serialize } from "../richtext/serialize.js";
|
|
3
3
|
import { wrapMapSerializer } from "../richtext/wrapMapSerializer.js";
|
|
4
4
|
import { composeSerializers } from "../richtext/composeSerializers.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asHTML.js","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tserializeEmbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text or title field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text or title field with a map or a function to\n * HTML\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it you're\n\t * expected to use the `routes` options from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer, unhandled cases will fallback to the\n\t * default serializer\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param config - Configuration that determines the output of `asHTML()`\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param linkResolver - An optional link resolver function to resolve links,\n\t * without it you're expected to use the `routes` options from the API\n\t * @param serializer - An optional rich text serializer, unhandled cases will\n\t * fallback to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"asHTML.js","sources":["../../../src/helpers/asHTML.ts"],"sourcesContent":["import {\n\tserializeEmbed,\n\tserializeHyperlink,\n\tserializeImage,\n\tserializePreFormatted,\n\tserializeSpan,\n\tserializeStandardTag,\n} from \"../lib/serializerHelpers\"\n\nimport type { RichTextField } from \"../types/value/richText\"\n\nimport type {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextMapSerializerFunction,\n} from \"../richtext\"\nimport { composeSerializers, serialize, wrapMapSerializer } from \"../richtext\"\n\nimport type { LinkResolverFunction } from \"./asLink\"\n\n/**\n * Serializes a node from a rich text or title field with a function to HTML.\n *\n * Unlike a typical `@prismicio/client/richtext` function serializer, this\n * serializer converts the `children` argument to a single string rather than an\n * array of strings.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextFunctionSerializer = (\n\ttype: Parameters<RichTextFunctionSerializer<string>>[0],\n\tnode: Parameters<RichTextFunctionSerializer<string>>[1],\n\ttext: Parameters<RichTextFunctionSerializer<string>>[2],\n\tchildren: Parameters<RichTextFunctionSerializer<string>>[3][number],\n\tkey: Parameters<RichTextFunctionSerializer<string>>[4],\n) => string | null | undefined\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings and accepts shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: P extends RichTextMapSerializer<string>[\"span\"]\n\t\t? HTMLStrictRichTextMapSerializer[P]\n\t\t: HTMLStrictRichTextMapSerializer[P] | HTMLRichTextMapSerializerShorthand\n}\n\n/**\n * Serializes a node from a rich text or title field with a map to HTML\n *\n * Unlike a typical `@prismicio/client/richtext` map serializer, this serializer\n * converts the `children` property to a single string rather than an array of\n * strings but doesn't accept shorthand declarations.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLStrictRichTextMapSerializer = {\n\t[P in keyof RichTextMapSerializer<string>]: (payload: {\n\t\ttype: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"type\"]\n\t\tnode: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"node\"]\n\t\ttext: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"text\"]\n\t\tchildren: Parameters<\n\t\t\tHTMLRichTextMapSerializerFunction<P>\n\t\t>[0][\"children\"][number]\n\t\tkey: Parameters<HTMLRichTextMapSerializerFunction<P>>[0][\"key\"]\n\t}) => string | null | undefined\n}\n\n/**\n * A {@link RichTextMapSerializerFunction} type specifically for\n * {@link HTMLRichTextMapSerializer}.\n *\n * @typeParam BlockName - The serializer's rich text block type.\n */\ntype HTMLRichTextMapSerializerFunction<\n\tBlockType extends keyof RichTextMapSerializer<string>,\n> = RichTextMapSerializerFunction<\n\tstring,\n\tExtractNodeGeneric<RichTextMapSerializer<string>[BlockType]>,\n\tExtractTextTypeGeneric<RichTextMapSerializer<string>[BlockType]>\n>\n\n/**\n * Returns the `Node` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `Node` generic.\n */\ntype ExtractNodeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * Returns the `TextType` generic from {@link RichTextMapSerializerFunction}.\n *\n * @typeParam T - The `RichTextMapSerializerFunction` containing the needed\n * `TextType` generic.\n */\ntype ExtractTextTypeGeneric<T> =\n\tT extends RichTextMapSerializerFunction<\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tany,\n\t\tinfer U\n\t>\n\t\t? U\n\t\t: never\n\n/**\n * A shorthand definition for {@link HTMLRichTextMapSerializer} element types.\n */\nexport type HTMLRichTextMapSerializerShorthand = {\n\t/**\n\t * Classes to apply to the element type.\n\t */\n\tclass?: string\n\n\t/**\n\t * Other attributes to apply to the element type.\n\t */\n\t[Attribute: string]: string | boolean | null | undefined\n}\n\n/**\n * Serializes a node from a rich text or title field with a map or a function to\n * HTML\n *\n * @see {@link HTMLRichTextMapSerializer} and {@link HTMLRichTextFunctionSerializer}\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n */\nexport type HTMLRichTextSerializer =\n\t| HTMLRichTextMapSerializer\n\t| HTMLRichTextFunctionSerializer\n\n/**\n * Creates a HTML rich text serializer with a given link resolver and provide\n * sensible and safe defaults for every node type\n *\n * @internal\n */\nconst createHTMLRichTextSerializer = (\n\tlinkResolver: LinkResolverFunction | undefined | null,\n\tserializer?: HTMLRichTextMapSerializer | null,\n): RichTextFunctionSerializer<string> => {\n\tconst useSerializerOrDefault = <\n\t\tBlockType extends keyof RichTextMapSerializer<string>,\n\t>(\n\t\tnodeSerializerOrShorthand: HTMLRichTextMapSerializer[BlockType],\n\t\tdefaultWithShorthand: NonNullable<\n\t\t\tHTMLStrictRichTextMapSerializer[BlockType]\n\t\t>,\n\t): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\t\tif (typeof nodeSerializerOrShorthand === \"function\") {\n\t\t\treturn ((payload) => {\n\t\t\t\treturn (\n\t\t\t\t\t(\n\t\t\t\t\t\tnodeSerializerOrShorthand as HTMLStrictRichTextMapSerializer[BlockType]\n\t\t\t\t\t)?.(payload) || defaultWithShorthand(payload)\n\t\t\t\t)\n\t\t\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n\t\t}\n\n\t\treturn defaultWithShorthand\n\t}\n\n\tconst mapSerializer: Required<HTMLStrictRichTextMapSerializer> = {\n\t\theading1: useSerializerOrDefault<\"heading1\">(\n\t\t\tserializer?.heading1,\n\t\t\tserializeStandardTag<\"heading1\">(\"h1\", serializer?.heading1),\n\t\t),\n\t\theading2: useSerializerOrDefault<\"heading2\">(\n\t\t\tserializer?.heading2,\n\t\t\tserializeStandardTag<\"heading2\">(\"h2\", serializer?.heading2),\n\t\t),\n\t\theading3: useSerializerOrDefault<\"heading3\">(\n\t\t\tserializer?.heading3,\n\t\t\tserializeStandardTag<\"heading3\">(\"h3\", serializer?.heading3),\n\t\t),\n\t\theading4: useSerializerOrDefault<\"heading4\">(\n\t\t\tserializer?.heading4,\n\t\t\tserializeStandardTag<\"heading4\">(\"h4\", serializer?.heading4),\n\t\t),\n\t\theading5: useSerializerOrDefault<\"heading5\">(\n\t\t\tserializer?.heading5,\n\t\t\tserializeStandardTag<\"heading5\">(\"h5\", serializer?.heading5),\n\t\t),\n\t\theading6: useSerializerOrDefault<\"heading6\">(\n\t\t\tserializer?.heading6,\n\t\t\tserializeStandardTag<\"heading6\">(\"h6\", serializer?.heading6),\n\t\t),\n\t\tparagraph: useSerializerOrDefault<\"paragraph\">(\n\t\t\tserializer?.paragraph,\n\t\t\tserializeStandardTag<\"paragraph\">(\"p\", serializer?.paragraph),\n\t\t),\n\t\tpreformatted: useSerializerOrDefault<\"preformatted\">(\n\t\t\tserializer?.preformatted,\n\t\t\tserializePreFormatted(serializer?.preformatted),\n\t\t),\n\t\tstrong: useSerializerOrDefault<\"strong\">(\n\t\t\tserializer?.strong,\n\t\t\tserializeStandardTag<\"strong\">(\"strong\", serializer?.strong),\n\t\t),\n\t\tem: useSerializerOrDefault<\"em\">(\n\t\t\tserializer?.em,\n\t\t\tserializeStandardTag<\"em\">(\"em\", serializer?.em),\n\t\t),\n\t\tlistItem: useSerializerOrDefault<\"listItem\">(\n\t\t\tserializer?.listItem,\n\t\t\tserializeStandardTag<\"listItem\">(\"li\", serializer?.listItem),\n\t\t),\n\t\toListItem: useSerializerOrDefault<\"oListItem\">(\n\t\t\tserializer?.oListItem,\n\t\t\tserializeStandardTag<\"oListItem\">(\"li\", serializer?.oListItem),\n\t\t),\n\t\tlist: useSerializerOrDefault<\"list\">(\n\t\t\tserializer?.list,\n\t\t\tserializeStandardTag<\"list\">(\"ul\", serializer?.list),\n\t\t),\n\t\toList: useSerializerOrDefault<\"oList\">(\n\t\t\tserializer?.oList,\n\t\t\tserializeStandardTag<\"oList\">(\"ol\", serializer?.oList),\n\t\t),\n\t\timage: useSerializerOrDefault<\"image\">(\n\t\t\tserializer?.image,\n\t\t\tserializeImage(linkResolver, serializer?.image),\n\t\t),\n\t\tembed: useSerializerOrDefault<\"embed\">(\n\t\t\tserializer?.embed,\n\t\t\tserializeEmbed(serializer?.embed),\n\t\t),\n\t\thyperlink: useSerializerOrDefault<\"hyperlink\">(\n\t\t\tserializer?.hyperlink,\n\t\t\tserializeHyperlink(linkResolver, serializer?.hyperlink),\n\t\t),\n\t\tlabel: useSerializerOrDefault<\"label\">(\n\t\t\tserializer?.label,\n\t\t\tserializeStandardTag<\"label\">(\"span\", serializer?.label),\n\t\t),\n\t\tspan: useSerializerOrDefault<\"span\">(serializer?.span, serializeSpan()),\n\t}\n\n\treturn wrapMapSerializerWithStringChildren(mapSerializer)\n}\n\n/**\n * Wraps a map serializer into a regular function serializer. The given map\n * serializer should accept children as a string, not as an array of strings\n * like `@prismicio/client/richtext`'s `wrapMapSerializer`.\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nconst wrapMapSerializerWithStringChildren = (\n\tmapSerializer: HTMLStrictRichTextMapSerializer,\n): RichTextFunctionSerializer<string> => {\n\tconst modifiedMapSerializer = {} as RichTextMapSerializer<string>\n\n\tfor (const tag in mapSerializer) {\n\t\tconst tagSerializer = mapSerializer[tag as keyof typeof mapSerializer]\n\n\t\tif (tagSerializer) {\n\t\t\tmodifiedMapSerializer[tag as keyof typeof mapSerializer] = (payload) => {\n\t\t\t\treturn tagSerializer({\n\t\t\t\t\t...payload,\n\t\t\t\t\t// @ts-expect-error - merging blockSerializer types causes TS to bail to a never type\n\t\t\t\t\tchildren: payload.children.join(\"\"),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn wrapMapSerializer(modifiedMapSerializer)\n}\n\n/**\n * Configuration that determines the output of `asHTML()`.\n */\ntype AsHTMLConfig = {\n\t/**\n\t * An optional link resolver function to resolve links. Without it you're\n\t * expected to use the `routes` options from the API.\n\t */\n\tlinkResolver?: LinkResolverFunction | null\n\n\t/**\n\t * An optional rich text serializer, unhandled cases will fallback to the\n\t * default serializer\n\t */\n\tserializer?: HTMLRichTextSerializer | null\n}\n\n// TODO: Remove when we remove support for deprecated tuple-style configuration.\n/**\n * @deprecated Use object-style configuration instead.\n */\ntype AsHTMLDeprecatedTupleConfig = [\n\tlinkResolver?: LinkResolverFunction | null,\n\tserializer?: HTMLRichTextSerializer | null,\n]\n\n/**\n * The return type of `asHTML()`.\n */\ntype AsHTMLReturnType<Field extends RichTextField | null | undefined> =\n\tField extends RichTextField ? string : null\n\n// TODO: Remove overload when we remove support for deprecated tuple-style configuration.\nexport const asHTML: {\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param config - Configuration that determines the output of `asHTML()`\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\tconfig?: AsHTMLConfig,\n\t): AsHTMLReturnType<Field>\n\n\t/**\n\t * Serializes a rich text or title field to an HTML string.\n\t *\n\t * @deprecated Use object-style configuration instead.\n\t *\n\t * @param richTextField - A rich text or title field from Prismic\n\t * @param linkResolver - An optional link resolver function to resolve links,\n\t * without it you're expected to use the `routes` options from the API\n\t * @param serializer - An optional rich text serializer, unhandled cases will\n\t * fallback to the default serializer\n\t *\n\t * @returns HTML equivalent of the provided rich text or title field\n\t *\n\t * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/template-content-vanilla-javascript#rich-text-and-title}\n\t */\n\t<Field extends RichTextField | null | undefined>(\n\t\trichTextField: Field,\n\t\t...config: AsHTMLDeprecatedTupleConfig\n\t): AsHTMLReturnType<Field>\n} = <Field extends RichTextField | null | undefined>(\n\trichTextField: Field,\n\t// TODO: Rename to `config` when we remove support for deprecated tuple-style configuration.\n\t...configObjectOrTuple: [config?: AsHTMLConfig] | AsHTMLDeprecatedTupleConfig\n): AsHTMLReturnType<Field> => {\n\tif (richTextField) {\n\t\t// TODO: Remove when we remove support for deprecated tuple-style configuration.\n\t\tconst [configObjectOrLinkResolver, maybeSerializer] = configObjectOrTuple\n\t\tlet config: AsHTMLConfig\n\t\tif (\n\t\t\ttypeof configObjectOrLinkResolver === \"function\" ||\n\t\t\tconfigObjectOrLinkResolver == null\n\t\t) {\n\t\t\tconfig = {\n\t\t\t\tlinkResolver: configObjectOrLinkResolver,\n\t\t\t\tserializer: maybeSerializer,\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = { ...configObjectOrLinkResolver }\n\t\t}\n\n\t\tlet serializer: RichTextFunctionSerializer<string>\n\t\tif (config.serializer) {\n\t\t\tif (typeof config.serializer === \"function\") {\n\t\t\t\tserializer = composeSerializers(\n\t\t\t\t\t(type, node, text, children, key) =>\n\t\t\t\t\t\t// TypeScript doesn't narrow the type correctly here since it is now in a callback function, so we have to cast it here.\n\t\t\t\t\t\t(config.serializer as HTMLRichTextFunctionSerializer)(\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\tchildren.join(\"\"),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t),\n\t\t\t\t\tcreateHTMLRichTextSerializer(config.linkResolver),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tserializer = createHTMLRichTextSerializer(\n\t\t\t\t\tconfig.linkResolver,\n\t\t\t\t\tconfig.serializer,\n\t\t\t\t)\n\t\t\t}\n\t\t} else {\n\t\t\tserializer = createHTMLRichTextSerializer(config.linkResolver)\n\t\t}\n\n\t\treturn serialize(richTextField, serializer).join(\n\t\t\t\"\",\n\t\t) as AsHTMLReturnType<Field>\n\t} else {\n\t\treturn null as AsHTMLReturnType<Field>\n\t}\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asImagePixelDensitySrcSet.cjs","sources":["../../../src/helpers/asImagePixelDensitySrcSet.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"imgix-url-builder\"\nimport { buildPixelDensitySrcSet, buildURL } from \"imgix-url-builder\"\n\nimport type { ImageFieldImage } from \"../types/value/image\"\n\nimport { imageThumbnail as isImageThumbnailFilled } from \"./isFilled\"\n\n/**\n * The default pixel densities used to generate a `srcset` value.\n */\nconst DEFAULT_PIXEL_DENSITIES = [1, 2, 3]\n\n/**\n * Configuration for `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetConfig = Omit<\n\tBuildPixelDensitySrcSetParams,\n\t\"pixelDensities\"\n> &\n\tPartial<Pick<BuildPixelDensitySrcSetParams, \"pixelDensities\">>\n\n/**\n * The return type of `asImagePixelDensitySrcSet()`.\n */\ntype AsImagePixelDensitySrcSetReturnType<\n\tField extends ImageFieldImage | null | undefined,\n> =\n\tField extends ImageFieldImage<\"filled\">\n\t\t? {\n\t\t\t\t/**\n\t\t\t\t * The image field's 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,
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildPixelDensitySrcSet, buildURL } from "imgix-url-builder";
|
|
2
2
|
import { imageThumbnail } from "./isFilled.js";
|
|
3
3
|
const DEFAULT_PIXEL_DENSITIES = [1, 2, 3];
|
|
4
4
|
const asImagePixelDensitySrcSet = (field, config = {}) => {
|
|
@@ -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,
|
|
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 +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,
|
|
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 +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,
|
|
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 +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,IACA
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildWidthSrcSet, buildURL } from "imgix-url-builder";
|
|
2
2
|
import { imageThumbnail } from "./isFilled.js";
|
|
3
3
|
const DEFAULT_WIDTHS = [640, 828, 1200, 2048, 3840];
|
|
4
4
|
const asImageWidthSrcSet = (field, config = {}) => {
|
|
@@ -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,IACA
|
|
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;"}
|