{"version":3,"file":"apply-search-params.cjs","sources":["../../../src/router/http/apply-search-params.ts"],"sourcesContent":["/**\n * Merges search params from one URLSearchParams object to another.\n *\n * Only appends the parameter if the target does not contain it, or if the value is different and not undefined.\n *\n * For params prefixed with `nxtP`, it also sets the param without the prefix if it does not exist.\n * The `nxtP` prefix indicates that it is for Next.js dynamic route parameters. In some cases,\n * Next.js fails to derive the correct route parameters and so we need to set them manually.\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/lib/constants.ts#L3\n *\n * For params prefixed with `nxtI`, this is a route intercept. It sets the param without the prefix,\n * and removes any intercepts from the param's value. This is so that the route intercept is able\n * to have the correct route parameters for the page.\n * https://github.com/vercel/next.js/blob/cdf2b79ea/packages/next/src/shared/lib/router/utils/route-regex.ts#L6\n *\n * @param target Target that search params will be applied to.\n * @param source Source search params to apply to the target.\n */\nexport const applySearchParams = (target: URLSearchParams, source: URLSearchParams): void => {\n\tfor (const [key, value] of source.entries()) {\n\t\tconst nxtParamMatch = /^nxtP(.+)$/.exec(key);\n\t\tconst nxtInterceptMatch = /^nxtI(.+)$/.exec(key);\n\t\tif (nxtParamMatch?.[1]) {\n\t\t\ttarget.set(key, value);\n\t\t\ttarget.set(nxtParamMatch[1], value);\n\t\t} else if (nxtInterceptMatch?.[1]) {\n\t\t\ttarget.set(nxtInterceptMatch[1], value.replace(/(\\(\\.+\\))+/, ''));\n\t\t} else if (!target.has(key) || (!!value && !target.getAll(key).includes(value))) {\n\t\t\ttarget.append(key, value);\n\t\t}\n\t}\n};\n"],"names":["applySearchParams","target","source","key","value","nxtParamMatch","nxtInterceptMatch"],"mappings":"gFAkBa,MAAAA,EAAoB,CAACC,EAAyBC,IAAkC,CAC5F,SAAW,CAACC,EAAKC,CAAK,IAAKF,EAAO,UAAW,CACtC,MAAAG,EAAgB,aAAa,KAAKF,CAAG,EACrCG,EAAoB,aAAa,KAAKH,CAAG,EAC3CE,GAAA,MAAAA,EAAgB,IACZJ,EAAA,IAAIE,EAAKC,CAAK,EACrBH,EAAO,IAAII,EAAc,CAAC,EAAGD,CAAK,GACxBE,GAAA,MAAAA,EAAoB,GACvBL,EAAA,IAAIK,EAAkB,CAAC,EAAGF,EAAM,QAAQ,aAAc,EAAE,CAAC,GACtD,CAACH,EAAO,IAAIE,CAAG,GAAQC,GAAS,CAACH,EAAO,OAAOE,CAAG,EAAE,SAASC,CAAK,IACrEH,EAAA,OAAOE,EAAKC,CAAK,CAE1B,CACD"}