{"version":3,"file":"index.production.js","sources":["../../../autocomplete-shared/dist/esm/getAttributeValueByPath.js","../../../autocomplete-shared/dist/esm/version.js","../../../autocomplete-shared/dist/esm/userAgents.js","../../src/constants/index.ts","../../src/highlight/parseAttribute.ts","../../src/highlight/parseAlgoliaHitHighlight.ts","../../src/highlight/isPartHighlighted.ts","../../src/highlight/reverseHighlightedParts.ts","../../src/highlight/parseAlgoliaHitSnippet.ts","../../src/requester/createRequester.ts","../../src/search/fetchAlgoliaResults.ts","../../src/utils/getAppIdAndApiKey.ts","../../src/requester/createAlgoliaRequester.ts","../../src/requester/getAlgoliaFacets.ts","../../src/requester/getAlgoliaResults.ts","../../src/highlight/parseAlgoliaHitReverseHighlight.ts","../../src/highlight/parseAlgoliaHitReverseSnippet.ts"],"sourcesContent":["export function getAttributeValueByPath(record, path) {\n return path.reduce(function (current, key) {\n return current && current[key];\n }, record);\n}","export var version = '1.9.3';","import { version } from './version';\nexport var userAgents = [{\n segment: 'autocomplete-core',\n version: version\n}];","export const HIGHLIGHT_PRE_TAG = '__aa-highlight__';\nexport const HIGHLIGHT_POST_TAG = '__/aa-highlight__';\n","import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from '../constants';\n\nimport { ParsedAttribute } from './ParsedAttribute';\n\n/**\n * Creates a data structure that allows to concatenate similar highlighting\n * parts in a single value.\n */\nfunction createAttributeSet(initialValue: ParsedAttribute[] = []) {\n const value = initialValue;\n\n return {\n get() {\n return value;\n },\n add(part: ParsedAttribute) {\n const lastPart: ParsedAttribute | undefined = value[value.length - 1];\n\n if (lastPart?.isHighlighted === part.isHighlighted) {\n value[value.length - 1] = {\n value: lastPart.value + part.value,\n isHighlighted: lastPart.isHighlighted,\n };\n } else {\n value.push(part);\n }\n },\n };\n}\n\ntype ParseAttributeParams = {\n highlightedValue: string;\n};\n\nexport function parseAttribute({\n highlightedValue,\n}: ParseAttributeParams): ParsedAttribute[] {\n const preTagParts = highlightedValue.split(HIGHLIGHT_PRE_TAG);\n const firstValue = preTagParts.shift();\n const parts = createAttributeSet(\n firstValue ? [{ value: firstValue, isHighlighted: false }] : []\n );\n\n preTagParts.forEach((part) => {\n const postTagParts = part.split(HIGHLIGHT_POST_TAG);\n\n parts.add({\n value: postTagParts[0],\n isHighlighted: true,\n });\n\n if (postTagParts[1] !== '') {\n parts.add({\n value: postTagParts[1],\n isHighlighted: false,\n });\n }\n });\n\n return parts.get();\n}\n","import { getAttributeValueByPath, warn } from '@algolia/autocomplete-shared';\n\nimport { HighlightedHit } from './HighlightedHit';\nimport { ParseAlgoliaHitParams } from './ParseAlgoliaHitParams';\nimport { parseAttribute } from './parseAttribute';\nimport { ParsedAttribute } from './ParsedAttribute';\n\nexport function parseAlgoliaHitHighlight>({\n hit,\n attribute,\n}: ParseAlgoliaHitParams): ParsedAttribute[] {\n const path = Array.isArray(attribute) ? attribute : ([attribute] as string[]);\n let highlightedValue = getAttributeValueByPath(hit, [\n '_highlightResult',\n ...path,\n 'value',\n ]);\n\n if (typeof highlightedValue !== 'string') {\n warn(\n false,\n `The attribute \"${path.join('.')}\" described by the path ${JSON.stringify(\n path\n )} does not exist on the hit. Did you set it in \\`attributesToHighlight\\`?` +\n '\\nSee https://www.algolia.com/doc/api-reference/api-parameters/attributesToHighlight/'\n );\n\n highlightedValue = getAttributeValueByPath(hit, path) || '';\n }\n\n return parseAttribute({ highlightedValue });\n}\n","import { ParsedAttribute } from './ParsedAttribute';\n\nconst htmlEscapes = {\n '&': '&',\n '<': '<',\n '>': '>',\n '"': '\"',\n ''': \"'\",\n};\nconst hasAlphanumeric = new RegExp(/\\w/i);\nconst regexEscapedHtml = /&(amp|quot|lt|gt|#39);/g;\nconst regexHasEscapedHtml = RegExp(regexEscapedHtml.source);\n\nfunction unescape(value: string): string {\n return value && regexHasEscapedHtml.test(value)\n ? value.replace(regexEscapedHtml, (character) => htmlEscapes[character])\n : value;\n}\n\nexport function isPartHighlighted(parts: ParsedAttribute[], i: number) {\n const current = parts[i];\n const isNextHighlighted = parts[i + 1]?.isHighlighted || true;\n const isPreviousHighlighted = parts[i - 1]?.isHighlighted || true;\n\n if (\n !hasAlphanumeric.test(unescape(current.value)) &&\n isPreviousHighlighted === isNextHighlighted\n ) {\n return isPreviousHighlighted;\n }\n\n return current.isHighlighted;\n}\n","import { isPartHighlighted } from './isPartHighlighted';\nimport { ParsedAttribute } from './ParsedAttribute';\n\nexport function reverseHighlightedParts(parts: ParsedAttribute[]) {\n // We don't want to highlight the whole word when no parts match.\n if (!parts.some((part) => part.isHighlighted)) {\n return parts.map((part) => ({ ...part, isHighlighted: false }));\n }\n\n return parts.map((part, i) => ({\n ...part,\n isHighlighted: !isPartHighlighted(parts, i),\n }));\n}\n","import { getAttributeValueByPath, warn } from '@algolia/autocomplete-shared';\n\nimport { ParseAlgoliaHitParams } from './ParseAlgoliaHitParams';\nimport { parseAttribute } from './parseAttribute';\nimport { ParsedAttribute } from './ParsedAttribute';\nimport { SnippetedHit } from './SnippetedHit';\n\nexport function parseAlgoliaHitSnippet>({\n hit,\n attribute,\n}: ParseAlgoliaHitParams): ParsedAttribute[] {\n const path = Array.isArray(attribute) ? attribute : ([attribute] as string[]);\n let highlightedValue = getAttributeValueByPath(hit, [\n '_snippetResult',\n ...path,\n 'value',\n ]);\n\n if (typeof highlightedValue !== 'string') {\n warn(\n false,\n `The attribute \"${path.join('.')}\" described by the path ${JSON.stringify(\n path\n )} does not exist on the hit. Did you set it in \\`attributesToSnippet\\`?` +\n '\\nSee https://www.algolia.com/doc/api-reference/api-parameters/attributesToSnippet/'\n );\n\n highlightedValue = getAttributeValueByPath(hit, path) || '';\n }\n\n return parseAttribute({ highlightedValue });\n}\n","import type {\n Fetcher,\n ExecuteParams,\n RequesterParams,\n RequestParams,\n RequesterDescription,\n} from '../types';\n\nexport function createRequester(fetcher: Fetcher, requesterId?: string) {\n function execute(fetcherParams: ExecuteParams) {\n return fetcher({\n searchClient: fetcherParams.searchClient,\n queries: fetcherParams.requests.map((x) => x.query),\n }).then((responses) =>\n responses.map((response, index) => {\n const { sourceId, transformResponse } = fetcherParams.requests[index];\n\n return {\n items: response,\n sourceId,\n transformResponse,\n };\n })\n );\n }\n\n return function createSpecifiedRequester(\n requesterParams: RequesterParams\n ) {\n return function requester(\n requestParams: RequestParams\n ): RequesterDescription {\n return {\n requesterId,\n execute,\n ...requesterParams,\n ...requestParams,\n };\n };\n };\n}\n","import {\n userAgents as coreUserAgents,\n UserAgent,\n invariant,\n} from '@algolia/autocomplete-shared';\n\nimport { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from '../constants';\nimport type {\n SearchForFacetValuesResponse,\n SearchResponse,\n SearchParams,\n} from '../types';\nimport { getAppIdAndApiKey } from '../utils';\n\nexport function fetchAlgoliaResults({\n searchClient,\n queries,\n userAgents = [],\n}: SearchParams): Promise<\n Array | SearchForFacetValuesResponse>\n> {\n if (typeof searchClient.addAlgoliaAgent === 'function') {\n const algoliaAgents: UserAgent[] = [...coreUserAgents, ...userAgents];\n\n algoliaAgents.forEach(({ segment, version }) => {\n searchClient.addAlgoliaAgent(segment, version);\n });\n }\n\n const { appId, apiKey } = getAppIdAndApiKey(searchClient);\n\n invariant(\n Boolean(appId),\n 'The Algolia `appId` was not accessible from the searchClient passed.'\n );\n invariant(\n Boolean(apiKey),\n 'The Algolia `apiKey` was not accessible from the searchClient passed.'\n );\n\n return searchClient\n .search(\n queries.map((searchParameters) => {\n const { params, ...headers } = searchParameters;\n\n return {\n ...headers,\n params: {\n hitsPerPage: 5,\n highlightPreTag: HIGHLIGHT_PRE_TAG,\n highlightPostTag: HIGHLIGHT_POST_TAG,\n ...params,\n },\n };\n })\n )\n .then((response) => {\n return response.results.map((result, resultIndex) => ({\n ...result,\n hits: result.hits?.map((hit) => ({\n ...hit,\n // Bring support for the Insights plugin.\n __autocomplete_indexName:\n result.index || queries[resultIndex].indexName,\n __autocomplete_queryID: result.queryID,\n __autocomplete_algoliaCredentials: {\n appId,\n apiKey,\n },\n })),\n }));\n });\n}\n","import type { SearchClient } from '../types';\n\nexport function getAppIdAndApiKey(searchClient: SearchClient): {\n appId: string;\n apiKey: string;\n} {\n const { headers = {}, queryParameters = {} } = searchClient.transporter || {};\n const APP_ID = 'x-algolia-application-id';\n const API_KEY = 'x-algolia-api-key';\n const appId = headers[APP_ID] || queryParameters[APP_ID];\n const apiKey = headers[API_KEY] || queryParameters[API_KEY];\n return { appId, apiKey };\n}\n","import { fetchAlgoliaResults } from '../search';\n\nimport { createRequester } from './createRequester';\n\nexport const createAlgoliaRequester = createRequester(\n fetchAlgoliaResults,\n 'algolia'\n);\n","import { invariant } from '@algolia/autocomplete-shared';\n\nimport type { MultipleQueriesQuery } from '../types';\nimport { RequestParams } from '../types';\n\nimport { createAlgoliaRequester } from './createAlgoliaRequester';\n\n/**\n * Retrieves Algolia facet hits from multiple indices.\n */\nexport function getAlgoliaFacets(requestParams: RequestParams) {\n invariant(\n typeof requestParams.searchClient === 'object',\n 'The `searchClient` parameter is required for getAlgoliaFacets({ searchClient }).'\n );\n\n const requester = createAlgoliaRequester({\n transformResponse: (response) => response.facetHits,\n });\n\n const queries = requestParams.queries.map((query) => ({\n ...query,\n type: 'facet',\n })) as MultipleQueriesQuery[];\n\n return requester({\n ...requestParams,\n queries,\n });\n}\n","import { invariant } from '@algolia/autocomplete-shared';\n\nimport { RequestParams } from '../types';\n\nimport { createAlgoliaRequester } from './createAlgoliaRequester';\n\n/**\n * Retrieves Algolia results from multiple indices.\n */\nexport function getAlgoliaResults(requestParams: RequestParams) {\n invariant(\n typeof requestParams.searchClient === 'object',\n 'The `searchClient` parameter is required for getAlgoliaResults({ searchClient }).'\n );\n\n const requester = createAlgoliaRequester({\n transformResponse: (response) => response.hits,\n });\n\n return requester(requestParams);\n}\n","import { HighlightedHit } from './HighlightedHit';\nimport { parseAlgoliaHitHighlight } from './parseAlgoliaHitHighlight';\nimport { ParseAlgoliaHitParams } from './ParseAlgoliaHitParams';\nimport { ParsedAttribute } from './ParsedAttribute';\nimport { reverseHighlightedParts } from './reverseHighlightedParts';\n\nexport function parseAlgoliaHitReverseHighlight<\n THit extends HighlightedHit\n>(props: ParseAlgoliaHitParams): ParsedAttribute[] {\n return reverseHighlightedParts(parseAlgoliaHitHighlight(props));\n}\n","import { ParseAlgoliaHitParams } from './ParseAlgoliaHitParams';\nimport { parseAlgoliaHitSnippet } from './parseAlgoliaHitSnippet';\nimport { ParsedAttribute } from './ParsedAttribute';\nimport { reverseHighlightedParts } from './reverseHighlightedParts';\nimport { SnippetedHit } from './SnippetedHit';\n\nexport function parseAlgoliaHitReverseSnippet<\n THit extends SnippetedHit\n>(props: ParseAlgoliaHitParams): ParsedAttribute[] {\n return reverseHighlightedParts(parseAlgoliaHitSnippet(props));\n}\n"],"names":["getAttributeValueByPath","record","path","reduce","current","key","userAgents","segment","version","HIGHLIGHT_PRE_TAG","HIGHLIGHT_POST_TAG","parseAttribute","_ref","preTagParts","highlightedValue","split","firstValue","shift","parts","value","arguments","length","undefined","get","add","part","lastPart","isHighlighted","push","createAttributeSet","forEach","postTagParts","parseAlgoliaHitHighlight","hit","attribute","Array","isArray","concat","_toConsumableArray","htmlEscapes","hasAlphanumeric","RegExp","regexEscapedHtml","regexHasEscapedHtml","source","isPartHighlighted","i","_parts","_parts2","isNextHighlighted","isPreviousHighlighted","test","replace","character","reverseHighlightedParts","some","map","_objectSpread","parseAlgoliaHitSnippet","createRequester","fetcher","requesterId","execute","fetcherParams","searchClient","queries","requests","x","query","then","responses","response","index","_fetcherParams$reques","items","sourceId","transformResponse","requesterParams","requestParams","fetchAlgoliaResults","_ref$userAgents","addAlgoliaAgent","coreUserAgents","_ref2","_getAppIdAndApiKey","transporter","_ref$headers","headers","_ref$queryParameters","queryParameters","APP_ID","API_KEY","appId","apiKey","getAppIdAndApiKey","search","searchParameters","params","_objectWithoutProperties","_excluded","hitsPerPage","highlightPreTag","highlightPostTag","results","result","resultIndex","_result$hits","hits","__autocomplete_indexName","indexName","__autocomplete_queryID","queryID","__autocomplete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