@getlupa/vue 0.17.6 → 0.17.8

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.
@@ -1759,1319 +1759,36 @@ const LupaSearchSdk = {
1759
1759
  return loadRedirectionRules(queryKey, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
1760
1760
  }
1761
1761
  };
1762
- const getNormalizedString = (str) => {
1763
- var _a, _b;
1764
- if (!str) {
1765
- return "";
1766
- }
1767
- const transformedStr = typeof str === "string" ? str : str.toString();
1768
- return transformedStr.normalize === void 0 ? (_a = transformedStr.toLocaleLowerCase()) == null ? void 0 : _a.trim() : (_b = transformedStr.toLocaleLowerCase().normalize("NFKD").replace(/[^\w\s.-_/]/g, "")) == null ? void 0 : _b.trim();
1769
- };
1770
- const getTransformedString = (str) => {
1771
- var _a, _b;
1772
- if (!str) {
1773
- return "";
1774
- }
1775
- const transformedStr = typeof str === "string" ? str : str.toString();
1776
- return transformedStr.normalize === void 0 ? (_a = transformedStr.toLocaleLowerCase()) == null ? void 0 : _a.trim() : (_b = transformedStr.toLocaleLowerCase().normalize("NFKD")) == null ? void 0 : _b.trim();
1777
- };
1778
- const capitalize$1 = (str) => {
1779
- if (!str) {
1780
- return "";
1781
- }
1782
- return str[0].toLocaleUpperCase() + str.slice(1);
1783
- };
1784
- const addParamsToLabel = (label, ...params) => {
1785
- if (!params || params.length < 1) {
1786
- return label;
1787
- }
1788
- const paramKeys = Array.from(Array(params.length).keys());
1789
- return paramKeys.reduce((a, c2) => a.replace(`{${c2 + 1}}`, params[c2]), label);
1790
- };
1791
- const getRandomString = (length) => {
1792
- const chars = "0123456789abcdefghijklmnopqrstuvwxyz";
1793
- let result2 = "";
1794
- for (let i = length; i > 0; --i) {
1795
- result2 += chars[Math.floor(Math.random() * chars.length)];
1796
- }
1797
- return result2;
1798
- };
1799
- const toFixedIfNecessary = (value, precision = 2) => {
1800
- return (+parseFloat(value).toFixed(precision)).toString();
1801
- };
1802
- const getDisplayValue = (value) => {
1803
- if (value === void 0) {
1804
- return "";
1805
- }
1806
- if (typeof value === "string") {
1807
- return value;
1808
- }
1809
- return toFixedIfNecessary(value.toString());
1810
- };
1811
- const getProductKey = (index, product, idKey) => {
1812
- if (!idKey) {
1813
- return index;
1814
- }
1815
- if (product[idKey]) {
1816
- return product[idKey];
1817
- }
1818
- return index;
1819
- };
1820
- const normalizeFloat = (value) => {
1821
- var _a;
1822
- if (!value) {
1823
- return 0;
1824
- }
1825
- return +((_a = value == null ? void 0 : value.replace(/[^0-9,.]/g, "")) == null ? void 0 : _a.replace(",", "."));
1826
- };
1827
- const escapeHtml$1 = (value) => {
1828
- if (!value) {
1829
- return "";
1830
- }
1831
- let output = "";
1832
- let isSkip = false;
1833
- value.split(/(<del>.*?<\/del>)/g).forEach((segment) => {
1834
- if (segment.startsWith("<del>") && segment.endsWith("</del>")) {
1835
- output += segment;
1836
- isSkip = true;
1837
- }
1838
- if (!isSkip) {
1839
- output += segment.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
1840
- }
1841
- if (isSkip) {
1842
- isSkip = false;
1843
- }
1844
- });
1845
- return output;
1846
- };
1847
- const inputsAreEqual = (input2, possibleValues) => {
1848
- if (!input2) {
1849
- return false;
1850
- }
1851
- const normalizedInput = getTransformedString(input2);
1852
- return possibleValues.some((v) => getTransformedString(v) === normalizedInput);
1853
- };
1854
- const levenshteinDistance = (s = "", t = "") => {
1855
- if (!(s == null ? void 0 : s.length)) {
1856
- return t.length;
1857
- }
1858
- if (!(t == null ? void 0 : t.length)) {
1859
- return s.length;
1860
- }
1861
- const arr = [];
1862
- for (let i = 0; i <= t.length; i++) {
1863
- arr[i] = [i];
1864
- for (let j = 1; j <= s.length; j++) {
1865
- arr[i][j] = i === 0 ? j : Math.min(
1866
- arr[i - 1][j] + 1,
1867
- arr[i][j - 1] + 1,
1868
- arr[i - 1][j - 1] + (s[j - 1] === t[i - 1] ? 0 : 1)
1869
- );
1870
- }
1871
- }
1872
- return arr[t.length][s.length];
1873
- };
1874
- const findClosestStringValue = (input2, possibleValues, key) => {
1875
- var _a;
1876
- const directMatch = possibleValues.find((v) => v[key] === input2);
1877
- if (directMatch) {
1878
- return directMatch;
1879
- }
1880
- const distances = possibleValues.map((v) => levenshteinDistance(`${v[key]}`, input2));
1881
- const minDistance = Math.min(...distances);
1882
- const closestValue = (_a = possibleValues.filter((_, i) => distances[i] === minDistance)) == null ? void 0 : _a[0];
1883
- return closestValue;
1884
- };
1885
- const DEFAULT_SEARCH_BOX_OPTIONS = {
1886
- inputSelector: "#searchBox",
1887
- options: {
1888
- environment: "production"
1889
- },
1890
- showTotalCount: false,
1891
- minInputLength: 1,
1892
- inputAttributes: {
1893
- name: "q"
1894
- },
1895
- debounce: 0,
1896
- labels: {
1897
- placeholder: "Search for products...",
1898
- noResults: "There are no results found.",
1899
- moreResults: "Show more results",
1900
- currency: "€",
1901
- defaultFacetLabel: "Category:"
1902
- },
1903
- links: {
1904
- searchResults: "/search"
1905
- },
1906
- panels: [
1907
- {
1908
- type: "suggestion",
1909
- queryKey: "",
1910
- highlight: true,
1911
- limit: 5
1912
- },
1913
- {
1914
- type: "document",
1915
- queryKey: "",
1916
- limit: 5,
1917
- searchBySuggestion: false,
1918
- links: {
1919
- details: "{url}"
1920
- },
1921
- titleKey: "name",
1922
- elements: []
1923
- }
1924
- ],
1925
- history: {
1926
- labels: {
1927
- clear: "Clear History"
1928
- }
1929
- }
1930
- };
1931
- const DEFAULT_OPTIONS_RESULTS = {
1932
- options: {
1933
- environment: "production"
1934
- },
1935
- queryKey: "",
1936
- containerSelector: "#searchResultsContainer",
1937
- searchTitlePosition: "page-top",
1938
- labels: {
1939
- pageSize: "Page size:",
1940
- sortBy: "Sort by:",
1941
- itemCount: "Items {1} of {2}",
1942
- filteredItemCount: "",
1943
- currency: "€",
1944
- showMore: "Show more",
1945
- searchResults: "Search Query: ",
1946
- emptyResults: "There are no results for the query:",
1947
- mobileFilterButton: "Filter",
1948
- htmlTitleTemplate: "Search Query: '{1}'",
1949
- noResultsSuggestion: "No results found for this query: {1}",
1950
- didYouMean: "Did you mean to search: {1}",
1951
- similarQuery: "Search results for phrase {1}",
1952
- similarQueries: "Similar queries:",
1953
- similarResultsLabel: "Related to your query:"
1954
- },
1955
- grid: {
1956
- columns: {
1957
- xl: 4,
1958
- l: 3,
1959
- md: 2,
1960
- sm: 2,
1961
- xs: 1
1962
- }
1963
- },
1964
- pagination: {
1965
- sizeSelection: {
1966
- position: {
1967
- top: false,
1968
- bottom: true
1969
- },
1970
- sizes: [10, 20, 25]
1971
- },
1972
- pageSelection: {
1973
- position: {
1974
- top: false,
1975
- bottom: true
1976
- },
1977
- display: 5,
1978
- displayMobile: 3
1979
- }
1980
- },
1981
- sort: [],
1982
- filters: {
1983
- currentFilters: {
1984
- visibility: {
1985
- mobileSidebar: true,
1986
- mobileToolbar: true
1987
- },
1988
- labels: {
1989
- title: "Current filters:",
1990
- clearAll: "Clear all"
1762
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
1763
+ function getDefaultExportFromCjs(x2) {
1764
+ return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
1765
+ }
1766
+ function getAugmentedNamespace(n) {
1767
+ if (n.__esModule)
1768
+ return n;
1769
+ var f2 = n.default;
1770
+ if (typeof f2 == "function") {
1771
+ var a = function a2() {
1772
+ if (this instanceof a2) {
1773
+ var args = [null];
1774
+ args.push.apply(args, arguments);
1775
+ var Ctor = Function.bind.apply(f2, args);
1776
+ return new Ctor();
1991
1777
  }
1992
- },
1993
- facets: {
1994
- labels: {
1995
- title: "Filters:",
1996
- showAll: "Show more",
1997
- facetFilter: "Filter...",
1998
- facetClear: "Clear"
1999
- },
2000
- filterable: {
2001
- minValues: 5
2002
- },
2003
- hierarchy: {
2004
- maxInitialLevel: 2,
2005
- topLevelValueCountLimit: 5,
2006
- filterable: true
2007
- },
2008
- facetValueCountLimit: 20,
2009
- showDocumentCount: true,
2010
- style: {
2011
- type: "sidebar"
2012
- }
2013
- }
2014
- },
2015
- toolbar: {
2016
- layoutSelector: true,
2017
- itemSummary: true,
2018
- clearFilters: false
2019
- },
2020
- isInStock: () => {
2021
- return true;
2022
- },
2023
- badges: {
2024
- anchor: "tr",
2025
- elements: []
2026
- },
2027
- links: {
2028
- details: "/{id}"
2029
- },
2030
- elements: [],
2031
- breadcrumbs: []
2032
- };
2033
- const useScreenStore = defineStore("screen", () => {
2034
- const measuredScreenWidth = ref(1e3);
2035
- const optionsStore = useOptionsStore();
2036
- const screenWidth = computed(() => {
2037
- var _a, _b;
2038
- const { searchResultOptions } = storeToRefs(optionsStore);
2039
- return (_b = (_a = searchResultOptions.value.grid) == null ? void 0 : _a.forcedScreenWidth) != null ? _b : measuredScreenWidth.value;
2040
- });
2041
- const configuredGridSizes = computed(() => {
2042
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2043
- const { searchResultOptions } = storeToRefs(optionsStore);
2044
- return {
2045
- smMin: (_d = (_c = (_b = (_a = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _a.grid) == null ? void 0 : _b.sizes) == null ? void 0 : _c.sm) != null ? _d : S_MIN_WIDTH,
2046
- mdMin: (_h = (_g = (_f = (_e = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _e.grid) == null ? void 0 : _f.sizes) == null ? void 0 : _g.md) != null ? _h : MD_MIN_WIDTH,
2047
- lMin: (_l = (_k = (_j = (_i = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _i.grid) == null ? void 0 : _j.sizes) == null ? void 0 : _k.l) != null ? _l : L_MIN_WIDTH,
2048
- xlMin: (_p = (_o = (_n = (_m = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _m.grid) == null ? void 0 : _n.sizes) == null ? void 0 : _o.xl) != null ? _p : XL_MIN_WIDTH
1778
+ return f2.apply(this, arguments);
2049
1779
  };
2050
- });
2051
- const currentScreenWidth = computed(() => {
2052
- const width = screenWidth.value;
2053
- if (width <= configuredGridSizes.value.smMin) {
2054
- return "xs";
2055
- } else if (width > configuredGridSizes.value.smMin && width <= configuredGridSizes.value.mdMin) {
2056
- return "sm";
2057
- } else if (width > configuredGridSizes.value.mdMin && width <= configuredGridSizes.value.lMin) {
2058
- return "md";
2059
- } else if (width > configuredGridSizes.value.lMin && width <= configuredGridSizes.value.xlMin) {
2060
- return "l";
2061
- } else {
2062
- return "xl";
2063
- }
2064
- });
2065
- const isMobileWidth = computed(() => {
2066
- var _a;
2067
- return (_a = ["xs", "sm"]) == null ? void 0 : _a.includes(currentScreenWidth.value);
2068
- });
2069
- const setScreenWidth = ({ width }) => {
2070
- measuredScreenWidth.value = width;
2071
- };
2072
- return { screenWidth, currentScreenWidth, isMobileWidth, setScreenWidth };
2073
- });
2074
- const useOptionsStore = defineStore("options", () => {
2075
- const searchBoxOptions = ref(
2076
- DEFAULT_SEARCH_BOX_OPTIONS
2077
- );
2078
- const searchResultOptions = ref(
2079
- DEFAULT_OPTIONS_RESULTS
2080
- );
2081
- const trackingOptions = ref({});
2082
- const searchResultInitialFilters = ref({});
2083
- const productRecommendationOptions = ref({});
2084
- const screenStore = useScreenStore();
2085
- const envOptions = computed(
2086
- () => {
2087
- var _a;
2088
- return (_a = searchBoxOptions.value.options) != null ? _a : searchResultOptions.value.options;
2089
- }
2090
- );
2091
- const classMap = computed(() => {
2092
- var _a;
2093
- return (_a = searchResultOptions.value.classMap) != null ? _a : {};
2094
- });
2095
- const initialFilters = computed(() => searchResultInitialFilters.value);
2096
- const boxRoutingBehavior = computed(() => {
2097
- var _a;
2098
- return (_a = searchBoxOptions.value.routingBehavior) != null ? _a : "direct-link";
2099
- });
2100
- const searchResultsRoutingBehavior = computed(
2101
- () => {
2102
- var _a;
2103
- return (_a = searchResultOptions.value.routingBehavior) != null ? _a : "direct-link";
2104
- }
2105
- );
2106
- const defaultSearchResultPageSize = computed(
2107
- () => {
2108
- var _a, _b;
2109
- return (_b = (_a = currentResolutionPageSizes.value) == null ? void 0 : _a[0]) != null ? _b : DEFAULT_PAGE_SIZE;
2110
- }
2111
- );
2112
- const currentResolutionPageSizes = computed(() => {
2113
- var _a, _b, _c, _d;
2114
- const pageSizes = (_d = (_c = (_b = (_a = searchResultOptions.value) == null ? void 0 : _a.pagination) == null ? void 0 : _b.sizeSelection) == null ? void 0 : _c.sizes) != null ? _d : DEFAULT_PAGE_SIZE_SELECTION;
2115
- if (Array.isArray(pageSizes)) {
2116
- return pageSizes;
2117
- }
2118
- const screenSize = screenStore.currentScreenWidth;
2119
- switch (screenSize) {
2120
- case "xs":
2121
- return pageSizes.xs;
2122
- case "sm":
2123
- return pageSizes.sm;
2124
- case "md":
2125
- return pageSizes.md;
2126
- case "l":
2127
- return pageSizes.l;
2128
- case "xl":
2129
- return pageSizes.xl;
2130
- }
2131
- });
2132
- const setSearchBoxOptions = ({ options }) => {
2133
- searchBoxOptions.value = options;
2134
- };
2135
- const setTrackingOptions = ({ options }) => {
2136
- trackingOptions.value = options;
2137
- };
2138
- const setSearchResultOptions = ({ options }) => {
2139
- searchResultOptions.value = options;
2140
- };
2141
- const setInitialFilters = ({ initialFilters: initialFilters2 }) => {
2142
- searchResultInitialFilters.value = initialFilters2;
2143
- };
2144
- const setProductRecommendationOptions = ({
2145
- options
2146
- }) => {
2147
- productRecommendationOptions.value = options;
2148
- };
2149
- const getQueryParamName = (param) => {
2150
- var _a;
2151
- const nameMap = searchBoxOptions.value.queryParameterNames;
2152
- return (_a = nameMap == null ? void 0 : nameMap[param]) != null ? _a : param;
2153
- };
2154
- return {
2155
- searchBoxOptions,
2156
- searchResultOptions,
2157
- trackingOptions,
2158
- envOptions,
2159
- classMap,
2160
- initialFilters,
2161
- boxRoutingBehavior,
2162
- searchResultsRoutingBehavior,
2163
- defaultSearchResultPageSize,
2164
- currentResolutionPageSizes,
2165
- productRecommendationOptions,
2166
- setSearchBoxOptions,
2167
- setTrackingOptions,
2168
- setSearchResultOptions,
2169
- setInitialFilters,
2170
- setProductRecommendationOptions,
2171
- getQueryParamName
2172
- };
2173
- });
2174
- const initAnalyticsTracking = (analyticsOptions) => {
2175
- try {
2176
- if (analyticsOptions == null ? void 0 : analyticsOptions.enabled) {
2177
- window.sessionStorage.setItem(TRACKING_ANALYTICS_KEY, JSON.stringify(analyticsOptions));
2178
- } else {
2179
- window.sessionStorage.removeItem(TRACKING_ANALYTICS_KEY);
2180
- }
2181
- } catch (e2) {
2182
- }
2183
- };
2184
- const initBaseTracking = (enabled) => {
2185
- try {
2186
- if (enabled) {
2187
- window.sessionStorage.setItem(TRACKING_STORAGE_KEY_BASE, "1");
2188
- } else {
2189
- window.sessionStorage.removeItem(TRACKING_STORAGE_KEY_BASE);
2190
- clearSessionTracking();
2191
- clearUserTracking();
2192
- }
2193
- } catch (e2) {
2194
- }
2195
- };
2196
- const clearSessionTracking = () => {
2197
- try {
2198
- window.sessionStorage.removeItem(TRACKING_STORAGE_KEY);
2199
- } catch (e2) {
2200
- }
2201
- };
2202
- const initSessionTracking = () => {
2203
- try {
2204
- if (getSessionKey()) {
2205
- return;
2206
- }
2207
- const key = getRandomString(TRACKING_KEY_LENGTH);
2208
- window.sessionStorage.setItem(TRACKING_STORAGE_KEY, key);
2209
- } catch (e2) {
2210
- }
2211
- };
2212
- const initUserTracking = (userKey) => {
2213
- try {
2214
- if (getUserKey()) {
2215
- return;
2216
- }
2217
- const key = userKey || getRandomString(TRACKING_KEY_LENGTH);
2218
- window.localStorage.setItem(TRACKING_STORAGE_KEY, key);
2219
- } catch (e2) {
2220
- }
2221
- };
2222
- const clearUserTracking = () => {
2223
- try {
2224
- window.localStorage.removeItem(TRACKING_STORAGE_KEY);
2225
- } catch (e2) {
2226
- }
2227
- };
2228
- const isTrackingEnabled = () => {
2229
- try {
2230
- return Boolean(window.sessionStorage.getItem(TRACKING_STORAGE_KEY_BASE));
2231
- } catch (e2) {
2232
- return false;
2233
- }
2234
- };
2235
- const isDelayedClickTracking = () => {
2236
- try {
2237
- return Boolean(window.localStorage.getItem(TRACKING_CLICK_DELAYED));
2238
- } catch (e2) {
2239
- return false;
2240
- }
2241
- };
2242
- const getSessionKey = () => {
2243
- var _a;
2244
- try {
2245
- return (_a = window.sessionStorage.getItem(TRACKING_STORAGE_KEY)) != null ? _a : void 0;
2246
- } catch (e2) {
2247
- return void 0;
2248
- }
2249
- };
2250
- const getUserKey = () => {
2251
- var _a;
2252
- try {
2253
- return (_a = window.localStorage.getItem(TRACKING_STORAGE_KEY)) != null ? _a : void 0;
2254
- } catch (e2) {
2255
- return void 0;
2256
- }
2257
- };
2258
- const initTracking = (options) => {
2259
- initBaseTracking(Boolean(options.trackBase));
2260
- if (options.trackSession) {
2261
- initSessionTracking();
2262
- } else {
2263
- clearSessionTracking();
2264
- }
2265
- if (options.trackUser) {
2266
- initUserTracking(options.userKey);
2267
- } else {
2268
- clearUserTracking();
2269
- }
2270
- if (options.analytics) {
2271
- initAnalyticsTracking(options.analytics);
2272
- }
2273
- if (options.delayedClickTracking) {
2274
- window.localStorage.setItem(TRACKING_CLICK_DELAYED, "1");
2275
- checkAndDispatchDelayedEvents();
2276
- } else {
2277
- window.localStorage.removeItem(TRACKING_CLICK_DELAYED);
2278
- }
2279
- };
2280
- const getLupaTrackingContext = () => {
2281
- if (!isTrackingEnabled()) {
2282
- return {};
2283
- }
2284
- return {
2285
- userId: getUserKey(),
2286
- sessionId: getSessionKey()
2287
- };
2288
- };
2289
- const trackLupaEvent = (queryKey, data = {}, options) => {
2290
- var _a, _b;
2291
- if (!queryKey || !data.type) {
2292
- return;
2293
- }
2294
- const eventData = {
2295
- searchQuery: (_a = data.searchQuery) != null ? _a : "",
2296
- itemId: (_b = data.itemId) != null ? _b : "",
2297
- name: data.type,
2298
- userId: getUserKey(),
2299
- sessionId: getSessionKey(),
2300
- filters: data.filters,
2301
- metadata: data.metadata,
2302
- sourceItemId: data.sourceItemId
2303
- };
2304
- LupaSearchSdk.track(queryKey, eventData, options);
2305
- };
2306
- const sendGa = (name, ...args) => {
2307
- window.ga(() => {
2308
- const trackers = window.ga.getAll();
2309
- const firstTracker = trackers[0];
2310
- if (!firstTracker) {
2311
- console.error("GA tracker not found");
2312
- }
2313
- const trackerName = firstTracker.get("name");
2314
- window.ga(`${trackerName}.${name}`, ...args);
2315
- });
2316
- };
2317
- const trackAnalyticsEvent = (data) => {
2318
- var _a, _b, _c;
2319
- try {
2320
- const options = JSON.parse(
2321
- (_a = window.sessionStorage.getItem(TRACKING_ANALYTICS_KEY)) != null ? _a : "{}"
2322
- );
2323
- if (!data.analytics || !options.enabled || ((_c = options.ignoreEvents) == null ? void 0 : _c.includes((_b = data.analytics) == null ? void 0 : _b.type))) {
2324
- return;
2325
- }
2326
- switch (options.type) {
2327
- case "ua":
2328
- sendUaAnalyticsEvent(data, options);
2329
- break;
2330
- case "ga4":
2331
- sendGa4AnalyticsEvent(data, options);
2332
- break;
2333
- case "debug":
2334
- processDebugEvent(data);
2335
- break;
2336
- default:
2337
- sendUaAnalyticsEvent(data, options);
2338
- }
2339
- } catch (e2) {
2340
- console.error("Unable to send an event to google analytics");
2341
- }
2342
- };
2343
- const parseEcommerceData = (data, title) => {
2344
- var _a, _b;
2345
- return ((_a = data.analytics) == null ? void 0 : _a.items) ? {
2346
- item_list_name: title,
2347
- items: (_b = data.analytics) == null ? void 0 : _b.items
2348
- } : void 0;
2349
- };
2350
- const sendUaAnalyticsEvent = (data, options) => {
2351
- var _a, _b, _c, _d;
2352
- const ga = window.ga;
2353
- if (!ga) {
2354
- console.error("Google Analytics object not found");
2355
- return;
2356
- }
2357
- sendGa(
2358
- "send",
2359
- "event",
2360
- options.parentEventName,
2361
- (_b = (_a = data.analytics) == null ? void 0 : _a.type) != null ? _b : "",
2362
- (_d = (_c = data.analytics) == null ? void 0 : _c.label) != null ? _d : ""
2363
- );
2364
- };
2365
- const sendGa4AnalyticsEvent = (data, options) => {
2366
- var _a, _b, _c, _d, _e, _f, _g;
2367
- if (!window || !window.dataLayer) {
2368
- console.error("dataLayer object not found.");
2369
- return;
2370
- }
2371
- const sendItemTitle = data.searchQuery !== ((_a = data.analytics) == null ? void 0 : _a.label);
2372
- const title = sendItemTitle ? (_b = data.analytics) == null ? void 0 : _b.label : void 0;
2373
- const params = __spreadValues({
2374
- search_text: data.searchQuery,
2375
- item_title: title,
2376
- item_id: data.itemId,
2377
- ecommerce: parseEcommerceData(data, (_c = data.analytics) == null ? void 0 : _c.listLabel)
2378
- }, (_e = (_d = data.analytics) == null ? void 0 : _d.additionalParams) != null ? _e : {});
2379
- window.dataLayer.push(__spreadValues({
2380
- event: (_g = (_f = data.analytics) == null ? void 0 : _f.type) != null ? _g : options.parentEventName
2381
- }, params));
2382
- };
2383
- const processDebugEvent = (data) => {
2384
- var _a, _b, _c, _d;
2385
- const sendItemTitle = data.searchQuery !== ((_a = data.analytics) == null ? void 0 : _a.label);
2386
- const title = sendItemTitle ? (_b = data.analytics) == null ? void 0 : _b.label : void 0;
2387
- const params = {
2388
- event: (_c = data.analytics) == null ? void 0 : _c.type,
2389
- search_text: data.searchQuery,
2390
- item_title: title,
2391
- item_id: data.itemId,
2392
- ecommerce: parseEcommerceData(data, (_d = data.analytics) == null ? void 0 : _d.listLabel)
2393
- };
2394
- console.debug("Analytics debug event:", params);
2395
- };
2396
- const getDelayedEventsCache = () => {
2397
- var _a;
2398
- try {
2399
- return JSON.parse((_a = window.localStorage.getItem(DELAYED_TRACKING_EVENTS_CACHE)) != null ? _a : "{}");
2400
- } catch (e2) {
2401
- return {};
2402
- }
2403
- };
2404
- const storeDelayedEventCache = (cache) => {
2405
- try {
2406
- window.localStorage.setItem(DELAYED_TRACKING_EVENTS_CACHE, JSON.stringify(cache));
2407
- } catch (e2) {
2408
- }
2409
- };
2410
- const checkAndDispatchDelayedEvents = () => {
2411
- var _a, _b;
2412
- const optionsStore = useOptionsStore();
2413
- const eventCache = getDelayedEventsCache();
2414
- const urls = Object.keys(eventCache);
2415
- for (const url of urls) {
2416
- if ((_a = window.location.href) == null ? void 0 : _a.includes(url)) {
2417
- const options = (_b = optionsStore.envOptions) != null ? _b : { environment: "production" };
2418
- const { queryKey, data } = eventCache[url];
2419
- track(queryKey, data, options);
2420
- }
2421
- }
2422
- storeDelayedEventCache({});
2423
- };
2424
- const track = (queryKey, data = {}, options) => {
2425
- var _a;
2426
- if (!isTrackingEnabled()) {
2427
- return;
2428
- }
2429
- const hasSearchQuery = data.searchQuery;
2430
- if (!hasSearchQuery && !((_a = data.options) == null ? void 0 : _a.allowEmptySearchQuery)) {
2431
- return;
2432
- }
2433
- trackAnalyticsEvent(data);
2434
- trackLupaEvent(queryKey, data, options);
2435
- };
2436
- var DocumentElementType = /* @__PURE__ */ ((DocumentElementType2) => {
2437
- DocumentElementType2["IMAGE"] = "image";
2438
- DocumentElementType2["TITLE"] = "title";
2439
- DocumentElementType2["CUSTOM"] = "custom";
2440
- DocumentElementType2["DESCRIPTION"] = "description";
2441
- DocumentElementType2["PRICE"] = "price";
2442
- DocumentElementType2["REGULARPRICE"] = "regularPrice";
2443
- DocumentElementType2["RATING"] = "rating";
2444
- DocumentElementType2["SINGLE_STAR_RATING"] = "singleStarRating";
2445
- DocumentElementType2["ADDTOCART"] = "addToCart";
2446
- DocumentElementType2["CUSTOM_HTML"] = "customHtml";
2447
- return DocumentElementType2;
2448
- })(DocumentElementType || {});
2449
- var SearchBoxPanelType = /* @__PURE__ */ ((SearchBoxPanelType2) => {
2450
- SearchBoxPanelType2["SUGGESTION"] = "suggestion";
2451
- SearchBoxPanelType2["DOCUMENT"] = "document";
2452
- SearchBoxPanelType2["RELATED_SOURCE"] = "related-source";
2453
- return SearchBoxPanelType2;
2454
- })(SearchBoxPanelType || {});
2455
- var BadgeType = /* @__PURE__ */ ((BadgeType2) => {
2456
- BadgeType2["NEWITEM"] = "newItem";
2457
- BadgeType2["TEXT"] = "text";
2458
- BadgeType2["IMAGE"] = "image";
2459
- BadgeType2["CUSTOM_HTML"] = "customHtml";
2460
- BadgeType2["DISCOUNT"] = "discount";
2461
- return BadgeType2;
2462
- })(BadgeType || {});
2463
- const retrieveHistory = () => {
2464
- try {
2465
- const historyString = window.localStorage.getItem(HISTORY_LOCAL_STORAGE_KEY);
2466
- return historyString ? JSON.parse(historyString) : [];
2467
- } catch (e2) {
2468
- return [];
2469
- }
2470
- };
2471
- const saveHistory = (items) => {
2472
- try {
2473
- window.localStorage.setItem(
2474
- HISTORY_LOCAL_STORAGE_KEY,
2475
- JSON.stringify(items.slice(0, HISTORY_MAX_ITEMS))
2476
- );
2477
- } catch (e2) {
2478
- }
2479
- };
2480
- const useHistoryStore = defineStore("history", () => {
2481
- const items = ref(retrieveHistory());
2482
- const count = computed(() => items.value.length);
2483
- const add = ({ item }) => {
2484
- if (!item) {
2485
- return items.value;
2486
- }
2487
- const newItems = items.value ? [item, ...items.value] : [item];
2488
- const uniqueItems = Array.from(new Set(newItems));
2489
- items.value = uniqueItems;
2490
- saveHistory(uniqueItems);
2491
- return uniqueItems;
2492
- };
2493
- const remove = ({ item }) => {
2494
- var _a, _b;
2495
- const tempItems = (_b = (_a = items.value) == null ? void 0 : _a.filter((i) => i !== item)) != null ? _b : [];
2496
- saveHistory(tempItems);
2497
- items.value = tempItems;
2498
- return tempItems;
2499
- };
2500
- const clear = () => {
2501
- saveHistory([]);
2502
- items.value = [];
2503
- };
2504
- return { items, count, add, remove, clear };
2505
- });
2506
- const QUERY_PARAMS = {
2507
- QUERY: "q",
2508
- PAGE: "p",
2509
- LIMIT: "l",
2510
- SORT: "s"
2511
- };
2512
- const QUERY_PARAMS_PARSED = {
2513
- QUERY: "query",
2514
- PAGE: "page",
2515
- LIMIT: "limit",
2516
- SORT: "sort"
2517
- };
2518
- const FACET_PARAMS_TYPE = {
2519
- TERMS: "f.",
2520
- RANGE: "fr.",
2521
- HIERARCHY: "fh."
2522
- };
2523
- const FACET_FILTER_MAP = {
2524
- terms: FACET_PARAMS_TYPE.TERMS,
2525
- range: FACET_PARAMS_TYPE.RANGE,
2526
- hierarchy: FACET_PARAMS_TYPE.HIERARCHY
2527
- };
2528
- const FACET_KEY_SEPARATOR = ".";
2529
- const FACET_RANGE_SEPARATOR = ":";
2530
- const HIERARCHY_SEPARATOR = ">";
2531
- const FACET_TERM_RANGE_SEPARATOR = "-";
2532
- const getAmount = (price, separator = ".") => {
2533
- var _a, _b;
2534
- if (typeof price === "number") {
2535
- return `${(_a = price.toFixed(2)) == null ? void 0 : _a.replace(".", separator)}`;
2536
- }
2537
- const value = parseFloat(price);
2538
- if (isNaN(value)) {
2539
- return "";
2540
- }
2541
- return (_b = value.toFixed(2)) == null ? void 0 : _b.replace(".", separator);
2542
- };
2543
- const formatPrice = (price, currency = "€", separator = ",", currencyTemplate = "") => {
2544
- if (price !== 0 && !price) {
2545
- return "";
2546
- }
2547
- const amount = getAmount(price, separator);
2548
- if (!amount) {
2549
- return "";
2550
- }
2551
- if (currencyTemplate) {
2552
- return addParamsToLabel(currencyTemplate, amount);
2553
- }
2554
- return `${amount} ${currency}`;
2555
- };
2556
- const formatPriceSummary = ([min, max], currency, separator = ",", currencyTemplate = "") => {
2557
- if (min !== void 0 && max !== void 0) {
2558
- return `${formatPrice(min, currency, separator, currencyTemplate)} - ${formatPrice(
2559
- max,
2560
- currency,
2561
- separator,
2562
- currencyTemplate
2563
- )}`;
2564
- }
2565
- if (min !== void 0) {
2566
- return `> ${formatPrice(min, currency, separator, currencyTemplate)}`;
2567
- }
2568
- return `< ${formatPrice(max, currency, separator, currencyTemplate)}`;
2569
- };
2570
- const getTranslatedFacetKey = (facet, translations) => {
2571
- var _a, _b;
2572
- return (_b = (_a = translations == null ? void 0 : translations.keyTranslations) == null ? void 0 : _a[facet.key]) != null ? _b : facet.label;
2573
- };
2574
- const getTranslatedFacetValue = (facet, value, translations) => {
2575
- var _a, _b, _c;
2576
- return (_c = (_b = (_a = translations == null ? void 0 : translations.valueTranslations) == null ? void 0 : _a[facet.key]) == null ? void 0 : _b[value == null ? void 0 : value.title]) != null ? _c : value.title;
2577
- };
2578
- const formatRange = (filter2) => {
2579
- var _a, _b;
2580
- const lt = (_a = filter2.lt) != null ? _a : filter2.lte;
2581
- const gt = (_b = filter2.gt) != null ? _b : filter2.gte;
2582
- if (gt !== void 0 && lt !== void 0) {
2583
- return `${gt} - ${lt}`;
2584
- }
2585
- if (lt !== void 0) {
2586
- return `<${filter2.lte !== void 0 ? "=" : ""} ${lt}`;
2587
- }
2588
- return `>${filter2.gte !== void 0 ? "=" : ""} ${gt}`;
2589
- };
2590
- const unfoldTermFilter = (key, filter2) => {
2591
- const seed = [];
2592
- return filter2.reduce((a, c2) => [...a, { key, value: c2, type: "terms" }], seed);
2593
- };
2594
- const unfoldHierarchyFilter = (key, filter2) => {
2595
- const seed = [];
2596
- return filter2.terms.reduce((a, c2) => [...a, { key, value: c2, type: "hierarchy" }], seed);
2597
- };
2598
- const unfoldRangeFilter = (key, filter2, price = {}) => {
2599
- var _a;
2600
- const gt = filter2.gte || filter2.gt;
2601
- const lt = filter2.lte || filter2.lt;
2602
- if (key.includes(CURRENCY_KEY_INDICATOR) || ((_a = price == null ? void 0 : price.keys) == null ? void 0 : _a.includes(key))) {
2603
- return [
2604
- {
2605
- key,
2606
- value: formatPriceSummary(
2607
- [gt, lt],
2608
- price.currency,
2609
- price.separator,
2610
- price.currencyTemplate
2611
- ),
2612
- type: "range"
2613
- }
2614
- ];
2615
- }
2616
- return [{ key, value: `${gt} - ${lt}`, type: "range" }];
2617
- };
2618
- const unfoldFilter = (key, filter2, price = {}) => {
2619
- if (Array.isArray(filter2)) {
2620
- return unfoldTermFilter(key, filter2);
2621
- }
2622
- if (filter2.gte) {
2623
- return unfoldRangeFilter(key, filter2, price);
2624
- }
2625
- if (filter2.terms) {
2626
- return unfoldHierarchyFilter(key, filter2);
2627
- }
2628
- return [];
2629
- };
2630
- const unfoldFilters = (filters, price = {}) => {
2631
- if (!filters) {
2632
- return [];
2633
- }
2634
- const seed = [];
2635
- return Object.entries(filters).reduce((a, c2) => [...a, ...unfoldFilter(...c2, price)], seed);
2636
- };
2637
- const getLabeledFilters = (filters, facets2, translations) => {
2638
- return filters.map((f2) => {
2639
- var _a, _b, _c, _d;
2640
- return __spreadProps(__spreadValues({}, f2), {
2641
- label: (_d = (_c = (_a = translations == null ? void 0 : translations.keyTranslations) == null ? void 0 : _a[f2.key]) != null ? _c : (_b = facets2 == null ? void 0 : facets2.find((ft) => ft.key === f2.key)) == null ? void 0 : _b.label) != null ? _d : capitalize$1(f2.key),
2642
- value: getTranslatedFacetValue({ key: f2.key }, { title: f2.value }, translations)
2643
- });
2644
- });
2645
- };
2646
- const isFacetKey = (key) => key.startsWith(FACET_PARAMS_TYPE.RANGE) || key.startsWith(FACET_PARAMS_TYPE.TERMS) || key.startsWith(FACET_PARAMS_TYPE.HIERARCHY);
2647
- const getMostSpecificHierarchyTerms = (terms) => {
2648
- const specificTerms = [];
2649
- for (const term of terms) {
2650
- if (!terms.some((t) => t.startsWith(term) && t !== term)) {
2651
- specificTerms.push(term);
2652
- }
2653
- }
2654
- return Array.from(new Set(specificTerms));
2655
- };
2656
- const recursiveFilter = (items, query = "") => {
2657
- if (!query) {
2658
- return items;
2659
- }
2660
- return items.map((i) => recursiveFilterItem(i, query)).filter(Boolean);
2661
- };
2662
- const recursiveFilterItem = (item, query = "") => {
2663
- const filterable = getNormalizedString(item.title).includes(getNormalizedString(query)) ? item : void 0;
2664
- if (!item.children) {
2665
- return filterable;
2666
- }
2667
- const children = recursiveFilter(item.children, query).filter(Boolean);
2668
- const include = children.length > 0 || filterable;
2669
- return include ? __spreadProps(__spreadValues({}, item), {
2670
- children
2671
- }) : void 0;
2672
- };
2673
- const rangeFilterToString = (rangeFilter, separator) => {
2674
- separator = separator || FACET_TERM_RANGE_SEPARATOR;
2675
- return rangeFilter && Object.keys(rangeFilter).length ? rangeFilter.gte + separator + (rangeFilter.lte || rangeFilter.lt) : "";
2676
- };
2677
- const pick = (obj, keys) => {
2678
- const ret = /* @__PURE__ */ Object.create({});
2679
- for (const k of keys) {
2680
- ret[k] = obj[k];
2681
- }
2682
- return ret;
2683
- };
2684
- const getHint = (suggestion, inputValue) => {
2685
- var _a;
2686
- if (!inputValue) {
2687
- return escapeHtml$1(suggestion);
2688
- }
2689
- return (_a = suggestion == null ? void 0 : suggestion.replace(
2690
- inputValue == null ? void 0 : inputValue.toLocaleLowerCase(),
2691
- `<strong>${escapeHtml$1(inputValue == null ? void 0 : inputValue.toLocaleLowerCase())}</strong>`
2692
- )) != null ? _a : "";
2693
- };
2694
- const reverseKeyValue = (obj) => {
2695
- return Object.fromEntries(Object.entries(obj).map(([k, v]) => [v, k.toLowerCase()]));
2696
- };
2697
- const getPageCount = (total, limit) => {
2698
- return Math.ceil(total / limit) || 0;
2699
- };
2700
- const isObject$1 = (value) => {
2701
- return value !== null && typeof value === "object" && !Array.isArray(value);
2702
- };
2703
- const parseParam = (key, params) => {
2704
- const value = params.get(key);
2705
- if (!value) {
2706
- return void 0;
2707
- }
2708
- try {
2709
- return decodeURIComponent(value);
2710
- } catch (e2) {
2711
- return void 0;
2712
- }
2713
- };
2714
- const parseRegularKeys = (regularKeys, searchParams, getQueryParamName) => {
2715
- const params = /* @__PURE__ */ Object.create({});
2716
- const keys = reverseKeyValue({
2717
- QUERY: getQueryParamName ? getQueryParamName(QUERY_PARAMS.QUERY) : QUERY_PARAMS.QUERY,
2718
- LIMIT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.LIMIT) : QUERY_PARAMS.LIMIT,
2719
- PAGE: getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE,
2720
- SORT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.SORT) : QUERY_PARAMS.SORT
2721
- });
2722
- for (const key of regularKeys) {
2723
- const rawKey = keys[key] || key;
2724
- params[rawKey] = parseParam(key, searchParams);
2725
- }
2726
- return params;
2727
- };
2728
- const parseFacetKey = (key, searchParams) => {
2729
- var _a, _b, _c, _d;
2730
- if (key.startsWith(FACET_PARAMS_TYPE.TERMS)) {
2731
- return (_b = (_a = searchParams.getAll(key)) == null ? void 0 : _a.map((v) => decodeURIComponent(v))) != null ? _b : [];
2732
- }
2733
- if (key.startsWith(FACET_PARAMS_TYPE.RANGE)) {
2734
- const range = searchParams.get(key);
2735
- if (!range) {
2736
- return {};
2737
- }
2738
- const [min, max] = range.split(FACET_RANGE_SEPARATOR);
2739
- return {
2740
- gte: min,
2741
- lte: max
2742
- };
2743
- }
2744
- if (key.startsWith(FACET_PARAMS_TYPE.HIERARCHY)) {
2745
- return {
2746
- level: 0,
2747
- terms: (_d = (_c = searchParams.getAll(key)) == null ? void 0 : _c.map((v) => decodeURIComponent(v))) != null ? _d : []
2748
- };
2749
- }
2750
- return [];
2751
- };
2752
- const parseFacetKeys = (facetKeys, searchParams) => {
2753
- const params = {};
2754
- params.filters = {};
2755
- for (const key of facetKeys) {
2756
- const parsedKey = key.slice(key.indexOf(FACET_KEY_SEPARATOR) + 1);
2757
- params.filters = __spreadProps(__spreadValues({}, params.filters), {
2758
- [parsedKey]: parseFacetKey(key, searchParams)
2759
- });
2760
- }
2761
- return params;
2762
- };
2763
- const parseParams = (getQueryParamName, searchParams) => {
2764
- const params = /* @__PURE__ */ Object.create({});
2765
- if (!searchParams)
2766
- return params;
2767
- const paramKeys = Array.from(searchParams.keys());
2768
- const facetKeys = paramKeys.filter((k) => isFacetKey(k));
2769
- const regularKeys = paramKeys.filter((k) => !isFacetKey(k));
2770
- const r = __spreadValues(__spreadValues({
2771
- [QUERY_PARAMS_PARSED.QUERY]: ""
2772
- }, parseRegularKeys(regularKeys, searchParams, getQueryParamName)), parseFacetKeys(facetKeys, searchParams));
2773
- return r;
2774
- };
2775
- const appendParam = (url, { name, value }, encode2 = true) => {
2776
- if (Array.isArray(value)) {
2777
- appendArrayParams(url, { name, value });
2778
- } else {
2779
- appendSingleParam(url, { name, value }, encode2);
2780
- }
2781
- };
2782
- const appendSingleParam = (url, param, encode2 = true) => {
2783
- const valueToAppend = encode2 ? encodeParam(param.value) : param.value;
2784
- if (url.searchParams.has(param.name)) {
2785
- url.searchParams.set(param.name, valueToAppend);
2786
- } else {
2787
- url.searchParams.append(param.name, valueToAppend);
2788
- }
2789
- };
2790
- const appendArrayParams = (url, param) => {
2791
- url.searchParams.delete(param.name);
2792
- param.value.forEach((v) => url.searchParams.append(param.name, encodeParam(v)));
2793
- };
2794
- const getRemovableParams = (url, getQueryParamName, paramsToRemove) => {
2795
- if (paramsToRemove === "all") {
2796
- const params = {
2797
- QUERY: getQueryParamName ? getQueryParamName(QUERY_PARAMS.QUERY) : QUERY_PARAMS.QUERY,
2798
- LIMIT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.LIMIT) : QUERY_PARAMS.LIMIT,
2799
- PAGE: getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE,
2800
- SORT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.SORT) : QUERY_PARAMS.SORT
2801
- };
2802
- return [
2803
- ...Object.values(params),
2804
- ...Array.from(url.searchParams.keys()).filter((k) => isFacetKey(k))
2805
- ];
2806
- }
2807
- return paramsToRemove;
2808
- };
2809
- const removeParams = (url, params = []) => {
2810
- for (const param of params) {
2811
- if (url.searchParams.has(param)) {
2812
- url.searchParams.delete(param);
2813
- }
2814
- }
2815
- };
2816
- const encodeParam = (param) => {
2817
- const encoded = encodeURIComponent(param);
2818
- return encoded.replace(/%C4%85/g, "ą").replace(/%C4%8D/g, "č").replace(/%C4%99/g, "ę").replace(/%C4%97/g, "ė").replace(/%C4%AF/g, "į").replace(/%C5%A1/g, "š").replace(/%C5%B3/g, "ų").replace(/%C5%AB/g, "ū").replace(/%C5%BE/g, "ž").replace(/%20/g, " ");
2819
- };
2820
- const getQueryParam = (name) => {
2821
- try {
2822
- const urlParams = new URLSearchParams(window.location.search);
2823
- return urlParams.get(name);
2824
- } catch (e2) {
2825
- return null;
2826
- }
2827
- };
2828
- const PATH_REPLACE_REGEXP = /{(.*?)}/gm;
2829
- const generateLink = (linkPattern, document2) => {
2830
- const matches = linkPattern.match(PATH_REPLACE_REGEXP);
2831
- if (!matches) {
2832
- return linkPattern;
2833
- }
2834
- let link = linkPattern;
2835
- for (const match of matches) {
2836
- const propertyKey = match.slice(1, match.length - 1);
2837
- const property = document2[propertyKey] || "";
2838
- link = link.replace(match, property);
2839
- }
2840
- return link;
2841
- };
2842
- const generateResultLink = (link, getQueryParamName, searchText, facet) => {
2843
- if (!searchText) {
2844
- return link;
2845
- }
2846
- const facetParam = facet ? `&${FACET_PARAMS_TYPE.TERMS}${encodeParam(facet.key)}=${encodeParam(facet.title)}` : "";
2847
- const queryParam = `?${getQueryParamName ? getQueryParamName(QUERY_PARAMS.QUERY) : QUERY_PARAMS.QUERY}=${encodeParam(searchText)}`;
2848
- return `${link}${queryParam}${facetParam}`;
2849
- };
2850
- const getRelativePath = (link) => {
2851
- try {
2852
- const url = new URL(link);
2853
- const partialUrl = url.toString().substring(url.origin.length);
2854
- return partialUrl.endsWith("/") ? partialUrl.slice(0, partialUrl.length - 1) : partialUrl;
2855
- } catch (e2) {
2856
- return (link == null ? void 0 : link.endsWith("/")) ? link.slice(0, link.length - 1) : link;
2857
- }
2858
- };
2859
- const linksMatch = (link1, link2) => {
2860
- if (!link1 || !link2) {
2861
- return false;
2862
- }
2863
- return link1 === link2 || getRelativePath(link1) === getRelativePath(link2);
2864
- };
2865
- const emitRoutingEvent = (url) => {
2866
- const event = new CustomEvent(LUPA_ROUTING_EVENT, { detail: url });
2867
- window.dispatchEvent(event);
2868
- };
2869
- const handleRoutingEvent = (link, event, hasEventRouting = false) => {
2870
- if (!hasEventRouting) {
2871
- return;
2872
- }
2873
- event == null ? void 0 : event.preventDefault();
2874
- emitRoutingEvent(link);
2875
- };
2876
- const redirectToResultsPage = (link, searchText, getQueryParamName, facet, routingBehavior = "direct-link") => {
2877
- const url = generateResultLink(link, getQueryParamName, searchText, facet);
2878
- if (routingBehavior === "event") {
2879
- emitRoutingEvent(url);
2880
- } else {
2881
- window.location.assign(url);
2882
- }
2883
- };
2884
- const getPageUrl = (pathnameOverride, ssr) => {
2885
- if (typeof window !== "undefined") {
2886
- const pathname = pathnameOverride || window.location.pathname;
2887
- const origin = window.location.origin;
2888
- const search2 = window.location.search;
2889
- return new URL(origin + pathname + search2);
2890
- }
2891
- return new URL(ssr.url, ssr.baseUrl);
2892
- };
2893
- const getFacetKey = (key, type) => {
2894
- return `${FACET_FILTER_MAP[type]}${key}`;
2895
- };
2896
- const getFacetParam = (key, value, type = FACET_PARAMS_TYPE.TERMS) => {
2897
- return {
2898
- name: `${type}${key}`,
2899
- value
2900
- };
2901
- };
2902
- const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentFilters, paramsToRemove = []) => {
2903
- const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
2904
- const newParams = toggleTermParam(currentFilter, facetAction.value);
2905
- appendParams({
2906
- params: [getFacetParam(facetAction.key, newParams)],
2907
- paramsToRemove: [
2908
- ...paramsToRemove,
2909
- ...[getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
2910
- ]
2911
- });
2912
- };
2913
- const replaceHierarchyParam = (params = [], param = "") => {
2914
- if (params.some((p2) => p2.startsWith(param))) {
2915
- return toggleLastPram(params, param);
2916
- }
2917
- return [param];
2918
- };
2919
- const toggleHierarchyFilter = (appendParams, facetAction, getQueryParamName, currentFilters, removeAllLevels = false) => {
2920
- var _a, _b;
2921
- const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
2922
- const newParams = facetAction.behavior === "replace" ? replaceHierarchyParam((_a = currentFilter == null ? void 0 : currentFilter.terms) != null ? _a : [], facetAction.value) : toggleHierarchyParam((_b = currentFilter == null ? void 0 : currentFilter.terms) != null ? _b : [], facetAction.value, removeAllLevels);
2923
- appendParams({
2924
- params: [getFacetParam(facetAction.key, newParams, FACET_PARAMS_TYPE.HIERARCHY)],
2925
- paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
2926
- });
2927
- };
2928
- const toggleRangeFilter = (appendParams, facetAction, getQueryParamName, currentFilters) => {
2929
- const currentFilter = rangeFilterToString(
2930
- currentFilters == null ? void 0 : currentFilters[facetAction.key],
2931
- FACET_RANGE_SEPARATOR
2932
- );
2933
- let facetValue = facetAction.value.join(FACET_RANGE_SEPARATOR);
2934
- facetValue = currentFilter === facetValue ? "" : facetValue;
2935
- appendParams({
2936
- params: [getFacetParam(facetAction.key, facetValue, FACET_PARAMS_TYPE.RANGE)],
2937
- paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE],
2938
- encode: false
2939
- });
2940
- };
2941
- const toggleTermParam = (params = [], param = "") => {
2942
- if (params == null ? void 0 : params.includes(param)) {
2943
- return params.filter((p2) => p2 !== param);
2944
- }
2945
- return [param, ...params];
2946
- };
2947
- const toggleLastPram = (params = [], param = "") => {
2948
- const paramLevel = param.split(">").length;
2949
- return getMostSpecificHierarchyTerms(
2950
- params.map(
2951
- (p2) => p2.startsWith(param) ? p2.split(HIERARCHY_SEPARATOR).slice(0, paramLevel - 1).join(HIERARCHY_SEPARATOR).trim() : p2
2952
- ).filter(Boolean)
2953
- );
2954
- };
2955
- const toggleHierarchyParam = (params = [], param = "", removeAllLevels = false) => {
2956
- if (params == null ? void 0 : params.some((p2) => p2.startsWith(param))) {
2957
- return removeAllLevels ? getMostSpecificHierarchyTerms(params.filter((p2) => !p2.startsWith(param))) : toggleLastPram(params, param);
2958
- }
2959
- return getMostSpecificHierarchyTerms([param, ...params]);
2960
- };
2961
- const CACHE_KEY = "lupasearch-client-redirections";
2962
- const useRedirectionStore = defineStore("redirections", () => {
2963
- const redirections = ref({ rules: [] });
2964
- const redirectionOptions = ref({ enabled: false, queryKey: "" });
2965
- const saveToLocalStorage = () => {
2966
- try {
2967
- localStorage.setItem(
2968
- CACHE_KEY,
2969
- JSON.stringify({
2970
- redirections: redirections.value,
2971
- savedAt: Date.now(),
2972
- queryKey: redirectionOptions.value.queryKey
2973
- })
2974
- );
2975
- } catch (e2) {
2976
- }
2977
- };
2978
- const tryLoadFromLocalStorage = (config) => {
2979
- var _a;
2980
- if (!config.cacheSeconds)
2981
- return false;
2982
- try {
2983
- const data = JSON.parse((_a = localStorage.getItem(CACHE_KEY)) != null ? _a : "");
2984
- if (data.queryKey !== config.queryKey) {
2985
- return false;
2986
- }
2987
- if ((data == null ? void 0 : data.redirections) && Date.now() - data.savedAt < 1e3 * config.cacheSeconds) {
2988
- redirections.value = data.redirections;
2989
- return true;
2990
- }
2991
- } catch (e2) {
2992
- }
2993
- return false;
2994
- };
2995
- const initiate = (config, options) => __async(void 0, null, function* () {
2996
- var _a, _b, _c, _d;
2997
- if ((_a = redirectionOptions.value) == null ? void 0 : _a.enabled) {
2998
- return;
2999
- }
3000
- redirectionOptions.value = config;
3001
- if (!(config == null ? void 0 : config.enabled)) {
3002
- return;
3003
- }
3004
- const loaded = tryLoadFromLocalStorage(config);
3005
- if (loaded || ((_c = (_b = redirections.value) == null ? void 0 : _b.rules) == null ? void 0 : _c.length) > 0) {
3006
- return;
3007
- }
3008
- try {
3009
- const result2 = yield LupaSearchSdk.loadRedirectionRules(config.queryKey, options);
3010
- if (!((_d = result2 == null ? void 0 : result2.rules) == null ? void 0 : _d.length)) {
3011
- redirections.value = { rules: [] };
3012
- return;
3013
- }
3014
- redirections.value = result2;
3015
- saveToLocalStorage();
3016
- } catch (e2) {
3017
- }
3018
- });
3019
- const redirectOnKeywordIfConfigured = (input2, routingBehavior = "direct-link") => {
3020
- var _a, _b, _c, _d;
3021
- if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
3022
- return false;
3023
- }
3024
- const redirectTo = redirections.value.rules.find((r) => inputsAreEqual(input2, r.sources));
3025
- if (!redirectTo) {
3026
- return false;
3027
- }
3028
- const url = ((_c = redirectionOptions.value) == null ? void 0 : _c.urlTransformer) ? (_d = redirectionOptions.value) == null ? void 0 : _d.urlTransformer(redirectTo == null ? void 0 : redirectTo.target) : redirectTo == null ? void 0 : redirectTo.target;
3029
- if (url === void 0 || url === null || url === "") {
3030
- return false;
3031
- }
3032
- if (routingBehavior === "event") {
3033
- emitRoutingEvent(url);
3034
- } else {
3035
- window.location.assign(url);
3036
- }
3037
- return true;
3038
- };
3039
- return {
3040
- redirections,
3041
- redirectOnKeywordIfConfigured,
3042
- initiate
3043
- };
3044
- });
3045
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
3046
- function getDefaultExportFromCjs(x2) {
3047
- return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
3048
- }
3049
- function getAugmentedNamespace(n) {
3050
- if (n.__esModule)
3051
- return n;
3052
- var f2 = n.default;
3053
- if (typeof f2 == "function") {
3054
- var a = function a2() {
3055
- if (this instanceof a2) {
3056
- var args = [null];
3057
- args.push.apply(args, arguments);
3058
- var Ctor = Function.bind.apply(f2, args);
3059
- return new Ctor();
3060
- }
3061
- return f2.apply(this, arguments);
3062
- };
3063
- a.prototype = f2.prototype;
3064
- } else
3065
- a = {};
3066
- Object.defineProperty(a, "__esModule", { value: true });
3067
- Object.keys(n).forEach(function(k) {
3068
- var d2 = Object.getOwnPropertyDescriptor(n, k);
3069
- Object.defineProperty(a, k, d2.get ? d2 : {
3070
- enumerable: true,
3071
- get: function() {
3072
- return n[k];
3073
- }
3074
- });
1780
+ a.prototype = f2.prototype;
1781
+ } else
1782
+ a = {};
1783
+ Object.defineProperty(a, "__esModule", { value: true });
1784
+ Object.keys(n).forEach(function(k) {
1785
+ var d2 = Object.getOwnPropertyDescriptor(n, k);
1786
+ Object.defineProperty(a, k, d2.get ? d2 : {
1787
+ enumerable: true,
1788
+ get: function() {
1789
+ return n[k];
1790
+ }
1791
+ });
3075
1792
  });
3076
1793
  return a;
3077
1794
  }
@@ -8545,18 +7262,1308 @@ lodash.exports;
8545
7262
  if (symIterator) {
8546
7263
  lodash2.prototype[symIterator] = wrapperToIterator;
8547
7264
  }
8548
- return lodash2;
8549
- };
8550
- var _ = runInContext();
8551
- if (freeModule) {
8552
- (freeModule.exports = _)._ = _;
8553
- freeExports._ = _;
7265
+ return lodash2;
7266
+ };
7267
+ var _ = runInContext();
7268
+ if (freeModule) {
7269
+ (freeModule.exports = _)._ = _;
7270
+ freeExports._ = _;
7271
+ } else {
7272
+ root2._ = _;
7273
+ }
7274
+ }).call(commonjsGlobal);
7275
+ })(lodash, lodash.exports);
7276
+ var lodashExports = lodash.exports;
7277
+ const getNormalizedString = (str) => {
7278
+ var _a, _b;
7279
+ if (!str) {
7280
+ return "";
7281
+ }
7282
+ const transformedStr = typeof str === "string" ? str : str.toString();
7283
+ return transformedStr.normalize === void 0 ? (_a = transformedStr.toLocaleLowerCase()) == null ? void 0 : _a.trim() : (_b = transformedStr.toLocaleLowerCase().normalize("NFKD").replace(/[^\w\s.-_/]/g, "")) == null ? void 0 : _b.trim();
7284
+ };
7285
+ const getTransformedString = (str) => {
7286
+ var _a, _b;
7287
+ if (!str) {
7288
+ return "";
7289
+ }
7290
+ const transformedStr = typeof str === "string" ? str : str.toString();
7291
+ return transformedStr.normalize === void 0 ? (_a = transformedStr.toLocaleLowerCase()) == null ? void 0 : _a.trim() : (_b = transformedStr.toLocaleLowerCase().normalize("NFKD")) == null ? void 0 : _b.trim();
7292
+ };
7293
+ const capitalize$1 = (str) => {
7294
+ if (!str) {
7295
+ return "";
7296
+ }
7297
+ return str[0].toLocaleUpperCase() + str.slice(1);
7298
+ };
7299
+ const addParamsToLabel = (label, ...params) => {
7300
+ if (!params || params.length < 1) {
7301
+ return label;
7302
+ }
7303
+ const paramKeys = Array.from(Array(params.length).keys());
7304
+ return paramKeys.reduce((a, c2) => a.replace(`{${c2 + 1}}`, params[c2]), label);
7305
+ };
7306
+ const getRandomString = (length) => {
7307
+ const chars = "0123456789abcdefghijklmnopqrstuvwxyz";
7308
+ let result2 = "";
7309
+ for (let i = length; i > 0; --i) {
7310
+ result2 += chars[Math.floor(Math.random() * chars.length)];
7311
+ }
7312
+ return result2;
7313
+ };
7314
+ const toFixedIfNecessary = (value, precision = 2) => {
7315
+ return (+parseFloat(value).toFixed(precision)).toString();
7316
+ };
7317
+ const getDisplayValue = (value) => {
7318
+ if (value === void 0) {
7319
+ return "";
7320
+ }
7321
+ if (typeof value === "string") {
7322
+ return value;
7323
+ }
7324
+ return toFixedIfNecessary(value.toString());
7325
+ };
7326
+ const getProductKey = (index, product, idKey) => {
7327
+ if (!idKey) {
7328
+ return index;
7329
+ }
7330
+ if (product[idKey]) {
7331
+ return product[idKey];
7332
+ }
7333
+ return index;
7334
+ };
7335
+ const normalizeFloat = (value) => {
7336
+ var _a;
7337
+ if (!value) {
7338
+ return 0;
7339
+ }
7340
+ return +((_a = value == null ? void 0 : value.replace(/[^0-9,.]/g, "")) == null ? void 0 : _a.replace(",", "."));
7341
+ };
7342
+ const escapeHtml$1 = (value) => {
7343
+ if (!value) {
7344
+ return "";
7345
+ }
7346
+ let output = "";
7347
+ let isSkip = false;
7348
+ value.split(/(<del>.*?<\/del>)/g).forEach((segment) => {
7349
+ if (segment.startsWith("<del>") && segment.endsWith("</del>")) {
7350
+ output += segment;
7351
+ isSkip = true;
7352
+ }
7353
+ if (!isSkip) {
7354
+ output += segment.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
7355
+ }
7356
+ if (isSkip) {
7357
+ isSkip = false;
7358
+ }
7359
+ });
7360
+ return output;
7361
+ };
7362
+ const inputsAreEqual = (input2, possibleValues) => {
7363
+ if (!input2) {
7364
+ return false;
7365
+ }
7366
+ const normalizedInput = getTransformedString(input2);
7367
+ return possibleValues.some((v) => getTransformedString(v) === normalizedInput);
7368
+ };
7369
+ const levenshteinDistance = (s = "", t = "") => {
7370
+ if (!(s == null ? void 0 : s.length)) {
7371
+ return t.length;
7372
+ }
7373
+ if (!(t == null ? void 0 : t.length)) {
7374
+ return s.length;
7375
+ }
7376
+ const arr = [];
7377
+ for (let i = 0; i <= t.length; i++) {
7378
+ arr[i] = [i];
7379
+ for (let j = 1; j <= s.length; j++) {
7380
+ arr[i][j] = i === 0 ? j : Math.min(
7381
+ arr[i - 1][j] + 1,
7382
+ arr[i][j - 1] + 1,
7383
+ arr[i - 1][j - 1] + (s[j - 1] === t[i - 1] ? 0 : 1)
7384
+ );
7385
+ }
7386
+ }
7387
+ return arr[t.length][s.length];
7388
+ };
7389
+ const findClosestStringValue = (input2, possibleValues, key) => {
7390
+ var _a;
7391
+ const directMatch = possibleValues.find((v) => v[key] === input2);
7392
+ if (directMatch) {
7393
+ return directMatch;
7394
+ }
7395
+ const distances = possibleValues.map((v) => levenshteinDistance(`${v[key]}`, input2));
7396
+ const minDistance = Math.min(...distances);
7397
+ const closestValue = (_a = possibleValues.filter((_, i) => distances[i] === minDistance)) == null ? void 0 : _a[0];
7398
+ return closestValue;
7399
+ };
7400
+ const slugifyClass = (s) => {
7401
+ let slug = lodashExports.kebabCase(s);
7402
+ if (!slug || /^[0-9-]/.test(slug)) {
7403
+ slug = `c-${slug}`;
7404
+ }
7405
+ return slug;
7406
+ };
7407
+ const DEFAULT_SEARCH_BOX_OPTIONS = {
7408
+ inputSelector: "#searchBox",
7409
+ options: {
7410
+ environment: "production"
7411
+ },
7412
+ showTotalCount: false,
7413
+ minInputLength: 1,
7414
+ inputAttributes: {
7415
+ name: "q"
7416
+ },
7417
+ debounce: 0,
7418
+ labels: {
7419
+ placeholder: "Search for products...",
7420
+ noResults: "There are no results found.",
7421
+ moreResults: "Show more results",
7422
+ currency: "€",
7423
+ defaultFacetLabel: "Category:"
7424
+ },
7425
+ links: {
7426
+ searchResults: "/search"
7427
+ },
7428
+ panels: [
7429
+ {
7430
+ type: "suggestion",
7431
+ queryKey: "",
7432
+ highlight: true,
7433
+ limit: 5
7434
+ },
7435
+ {
7436
+ type: "document",
7437
+ queryKey: "",
7438
+ limit: 5,
7439
+ searchBySuggestion: false,
7440
+ links: {
7441
+ details: "{url}"
7442
+ },
7443
+ titleKey: "name",
7444
+ elements: []
7445
+ }
7446
+ ],
7447
+ history: {
7448
+ labels: {
7449
+ clear: "Clear History"
7450
+ }
7451
+ }
7452
+ };
7453
+ const DEFAULT_OPTIONS_RESULTS = {
7454
+ options: {
7455
+ environment: "production"
7456
+ },
7457
+ queryKey: "",
7458
+ containerSelector: "#searchResultsContainer",
7459
+ searchTitlePosition: "page-top",
7460
+ labels: {
7461
+ pageSize: "Page size:",
7462
+ sortBy: "Sort by:",
7463
+ itemCount: "Items {1} of {2}",
7464
+ filteredItemCount: "",
7465
+ currency: "€",
7466
+ showMore: "Show more",
7467
+ searchResults: "Search Query: ",
7468
+ emptyResults: "There are no results for the query:",
7469
+ mobileFilterButton: "Filter",
7470
+ htmlTitleTemplate: "Search Query: '{1}'",
7471
+ noResultsSuggestion: "No results found for this query: {1}",
7472
+ didYouMean: "Did you mean to search: {1}",
7473
+ similarQuery: "Search results for phrase {1}",
7474
+ similarQueries: "Similar queries:",
7475
+ similarResultsLabel: "Related to your query:"
7476
+ },
7477
+ grid: {
7478
+ columns: {
7479
+ xl: 4,
7480
+ l: 3,
7481
+ md: 2,
7482
+ sm: 2,
7483
+ xs: 1
7484
+ }
7485
+ },
7486
+ pagination: {
7487
+ sizeSelection: {
7488
+ position: {
7489
+ top: false,
7490
+ bottom: true
7491
+ },
7492
+ sizes: [10, 20, 25]
7493
+ },
7494
+ pageSelection: {
7495
+ position: {
7496
+ top: false,
7497
+ bottom: true
7498
+ },
7499
+ display: 5,
7500
+ displayMobile: 3
7501
+ }
7502
+ },
7503
+ sort: [],
7504
+ filters: {
7505
+ currentFilters: {
7506
+ visibility: {
7507
+ mobileSidebar: true,
7508
+ mobileToolbar: true
7509
+ },
7510
+ labels: {
7511
+ title: "Current filters:",
7512
+ clearAll: "Clear all"
7513
+ }
7514
+ },
7515
+ facets: {
7516
+ labels: {
7517
+ title: "Filters:",
7518
+ showAll: "Show more",
7519
+ facetFilter: "Filter...",
7520
+ facetClear: "Clear"
7521
+ },
7522
+ filterable: {
7523
+ minValues: 5
7524
+ },
7525
+ hierarchy: {
7526
+ maxInitialLevel: 2,
7527
+ topLevelValueCountLimit: 5,
7528
+ filterable: true
7529
+ },
7530
+ facetValueCountLimit: 20,
7531
+ showDocumentCount: true,
7532
+ style: {
7533
+ type: "sidebar"
7534
+ }
7535
+ }
7536
+ },
7537
+ toolbar: {
7538
+ layoutSelector: true,
7539
+ itemSummary: true,
7540
+ clearFilters: false
7541
+ },
7542
+ isInStock: () => {
7543
+ return true;
7544
+ },
7545
+ badges: {
7546
+ anchor: "tr",
7547
+ elements: []
7548
+ },
7549
+ links: {
7550
+ details: "/{id}"
7551
+ },
7552
+ elements: [],
7553
+ breadcrumbs: []
7554
+ };
7555
+ const useScreenStore = defineStore("screen", () => {
7556
+ const measuredScreenWidth = ref(1e3);
7557
+ const optionsStore = useOptionsStore();
7558
+ const screenWidth = computed(() => {
7559
+ var _a, _b;
7560
+ const { searchResultOptions } = storeToRefs(optionsStore);
7561
+ return (_b = (_a = searchResultOptions.value.grid) == null ? void 0 : _a.forcedScreenWidth) != null ? _b : measuredScreenWidth.value;
7562
+ });
7563
+ const configuredGridSizes = computed(() => {
7564
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
7565
+ const { searchResultOptions } = storeToRefs(optionsStore);
7566
+ return {
7567
+ smMin: (_d = (_c = (_b = (_a = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _a.grid) == null ? void 0 : _b.sizes) == null ? void 0 : _c.sm) != null ? _d : S_MIN_WIDTH,
7568
+ mdMin: (_h = (_g = (_f = (_e = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _e.grid) == null ? void 0 : _f.sizes) == null ? void 0 : _g.md) != null ? _h : MD_MIN_WIDTH,
7569
+ lMin: (_l = (_k = (_j = (_i = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _i.grid) == null ? void 0 : _j.sizes) == null ? void 0 : _k.l) != null ? _l : L_MIN_WIDTH,
7570
+ xlMin: (_p = (_o = (_n = (_m = searchResultOptions == null ? void 0 : searchResultOptions.value) == null ? void 0 : _m.grid) == null ? void 0 : _n.sizes) == null ? void 0 : _o.xl) != null ? _p : XL_MIN_WIDTH
7571
+ };
7572
+ });
7573
+ const currentScreenWidth = computed(() => {
7574
+ const width = screenWidth.value;
7575
+ if (width <= configuredGridSizes.value.smMin) {
7576
+ return "xs";
7577
+ } else if (width > configuredGridSizes.value.smMin && width <= configuredGridSizes.value.mdMin) {
7578
+ return "sm";
7579
+ } else if (width > configuredGridSizes.value.mdMin && width <= configuredGridSizes.value.lMin) {
7580
+ return "md";
7581
+ } else if (width > configuredGridSizes.value.lMin && width <= configuredGridSizes.value.xlMin) {
7582
+ return "l";
7583
+ } else {
7584
+ return "xl";
7585
+ }
7586
+ });
7587
+ const isMobileWidth = computed(() => {
7588
+ var _a;
7589
+ return (_a = ["xs", "sm"]) == null ? void 0 : _a.includes(currentScreenWidth.value);
7590
+ });
7591
+ const setScreenWidth = ({ width }) => {
7592
+ measuredScreenWidth.value = width;
7593
+ };
7594
+ return { screenWidth, currentScreenWidth, isMobileWidth, setScreenWidth };
7595
+ });
7596
+ const useOptionsStore = defineStore("options", () => {
7597
+ const searchBoxOptions = ref(
7598
+ DEFAULT_SEARCH_BOX_OPTIONS
7599
+ );
7600
+ const searchResultOptions = ref(
7601
+ DEFAULT_OPTIONS_RESULTS
7602
+ );
7603
+ const trackingOptions = ref({});
7604
+ const searchResultInitialFilters = ref({});
7605
+ const productRecommendationOptions = ref({});
7606
+ const screenStore = useScreenStore();
7607
+ const envOptions = computed(
7608
+ () => {
7609
+ var _a;
7610
+ return (_a = searchBoxOptions.value.options) != null ? _a : searchResultOptions.value.options;
7611
+ }
7612
+ );
7613
+ const classMap = computed(() => {
7614
+ var _a;
7615
+ return (_a = searchResultOptions.value.classMap) != null ? _a : {};
7616
+ });
7617
+ const initialFilters = computed(() => searchResultInitialFilters.value);
7618
+ const boxRoutingBehavior = computed(() => {
7619
+ var _a;
7620
+ return (_a = searchBoxOptions.value.routingBehavior) != null ? _a : "direct-link";
7621
+ });
7622
+ const searchResultsRoutingBehavior = computed(
7623
+ () => {
7624
+ var _a;
7625
+ return (_a = searchResultOptions.value.routingBehavior) != null ? _a : "direct-link";
7626
+ }
7627
+ );
7628
+ const defaultSearchResultPageSize = computed(
7629
+ () => {
7630
+ var _a, _b;
7631
+ return (_b = (_a = currentResolutionPageSizes.value) == null ? void 0 : _a[0]) != null ? _b : DEFAULT_PAGE_SIZE;
7632
+ }
7633
+ );
7634
+ const currentResolutionPageSizes = computed(() => {
7635
+ var _a, _b, _c, _d;
7636
+ const pageSizes = (_d = (_c = (_b = (_a = searchResultOptions.value) == null ? void 0 : _a.pagination) == null ? void 0 : _b.sizeSelection) == null ? void 0 : _c.sizes) != null ? _d : DEFAULT_PAGE_SIZE_SELECTION;
7637
+ if (Array.isArray(pageSizes)) {
7638
+ return pageSizes;
7639
+ }
7640
+ const screenSize = screenStore.currentScreenWidth;
7641
+ switch (screenSize) {
7642
+ case "xs":
7643
+ return pageSizes.xs;
7644
+ case "sm":
7645
+ return pageSizes.sm;
7646
+ case "md":
7647
+ return pageSizes.md;
7648
+ case "l":
7649
+ return pageSizes.l;
7650
+ case "xl":
7651
+ return pageSizes.xl;
7652
+ }
7653
+ });
7654
+ const setSearchBoxOptions = ({ options }) => {
7655
+ searchBoxOptions.value = options;
7656
+ };
7657
+ const setTrackingOptions = ({ options }) => {
7658
+ trackingOptions.value = options;
7659
+ };
7660
+ const setSearchResultOptions = ({ options }) => {
7661
+ searchResultOptions.value = options;
7662
+ };
7663
+ const setInitialFilters = ({ initialFilters: initialFilters2 }) => {
7664
+ searchResultInitialFilters.value = initialFilters2;
7665
+ };
7666
+ const setProductRecommendationOptions = ({
7667
+ options
7668
+ }) => {
7669
+ productRecommendationOptions.value = options;
7670
+ };
7671
+ const getQueryParamName = (param) => {
7672
+ var _a;
7673
+ const nameMap = searchBoxOptions.value.queryParameterNames;
7674
+ return (_a = nameMap == null ? void 0 : nameMap[param]) != null ? _a : param;
7675
+ };
7676
+ return {
7677
+ searchBoxOptions,
7678
+ searchResultOptions,
7679
+ trackingOptions,
7680
+ envOptions,
7681
+ classMap,
7682
+ initialFilters,
7683
+ boxRoutingBehavior,
7684
+ searchResultsRoutingBehavior,
7685
+ defaultSearchResultPageSize,
7686
+ currentResolutionPageSizes,
7687
+ productRecommendationOptions,
7688
+ setSearchBoxOptions,
7689
+ setTrackingOptions,
7690
+ setSearchResultOptions,
7691
+ setInitialFilters,
7692
+ setProductRecommendationOptions,
7693
+ getQueryParamName
7694
+ };
7695
+ });
7696
+ const initAnalyticsTracking = (analyticsOptions) => {
7697
+ try {
7698
+ if (analyticsOptions == null ? void 0 : analyticsOptions.enabled) {
7699
+ window.sessionStorage.setItem(TRACKING_ANALYTICS_KEY, JSON.stringify(analyticsOptions));
7700
+ } else {
7701
+ window.sessionStorage.removeItem(TRACKING_ANALYTICS_KEY);
7702
+ }
7703
+ } catch (e2) {
7704
+ }
7705
+ };
7706
+ const initBaseTracking = (enabled) => {
7707
+ try {
7708
+ if (enabled) {
7709
+ window.sessionStorage.setItem(TRACKING_STORAGE_KEY_BASE, "1");
7710
+ } else {
7711
+ window.sessionStorage.removeItem(TRACKING_STORAGE_KEY_BASE);
7712
+ clearSessionTracking();
7713
+ clearUserTracking();
7714
+ }
7715
+ } catch (e2) {
7716
+ }
7717
+ };
7718
+ const clearSessionTracking = () => {
7719
+ try {
7720
+ window.sessionStorage.removeItem(TRACKING_STORAGE_KEY);
7721
+ } catch (e2) {
7722
+ }
7723
+ };
7724
+ const initSessionTracking = () => {
7725
+ try {
7726
+ if (getSessionKey()) {
7727
+ return;
7728
+ }
7729
+ const key = getRandomString(TRACKING_KEY_LENGTH);
7730
+ window.sessionStorage.setItem(TRACKING_STORAGE_KEY, key);
7731
+ } catch (e2) {
7732
+ }
7733
+ };
7734
+ const initUserTracking = (userKey) => {
7735
+ try {
7736
+ if (getUserKey()) {
7737
+ return;
7738
+ }
7739
+ const key = userKey || getRandomString(TRACKING_KEY_LENGTH);
7740
+ window.localStorage.setItem(TRACKING_STORAGE_KEY, key);
7741
+ } catch (e2) {
7742
+ }
7743
+ };
7744
+ const clearUserTracking = () => {
7745
+ try {
7746
+ window.localStorage.removeItem(TRACKING_STORAGE_KEY);
7747
+ } catch (e2) {
7748
+ }
7749
+ };
7750
+ const isTrackingEnabled = () => {
7751
+ try {
7752
+ return Boolean(window.sessionStorage.getItem(TRACKING_STORAGE_KEY_BASE));
7753
+ } catch (e2) {
7754
+ return false;
7755
+ }
7756
+ };
7757
+ const isDelayedClickTracking = () => {
7758
+ try {
7759
+ return Boolean(window.localStorage.getItem(TRACKING_CLICK_DELAYED));
7760
+ } catch (e2) {
7761
+ return false;
7762
+ }
7763
+ };
7764
+ const getSessionKey = () => {
7765
+ var _a;
7766
+ try {
7767
+ return (_a = window.sessionStorage.getItem(TRACKING_STORAGE_KEY)) != null ? _a : void 0;
7768
+ } catch (e2) {
7769
+ return void 0;
7770
+ }
7771
+ };
7772
+ const getUserKey = () => {
7773
+ var _a;
7774
+ try {
7775
+ return (_a = window.localStorage.getItem(TRACKING_STORAGE_KEY)) != null ? _a : void 0;
7776
+ } catch (e2) {
7777
+ return void 0;
7778
+ }
7779
+ };
7780
+ const initTracking = (options) => {
7781
+ initBaseTracking(Boolean(options.trackBase));
7782
+ if (options.trackSession) {
7783
+ initSessionTracking();
7784
+ } else {
7785
+ clearSessionTracking();
7786
+ }
7787
+ if (options.trackUser) {
7788
+ initUserTracking(options.userKey);
7789
+ } else {
7790
+ clearUserTracking();
7791
+ }
7792
+ if (options.analytics) {
7793
+ initAnalyticsTracking(options.analytics);
7794
+ }
7795
+ if (options.delayedClickTracking) {
7796
+ window.localStorage.setItem(TRACKING_CLICK_DELAYED, "1");
7797
+ checkAndDispatchDelayedEvents();
7798
+ } else {
7799
+ window.localStorage.removeItem(TRACKING_CLICK_DELAYED);
7800
+ }
7801
+ };
7802
+ const getLupaTrackingContext = () => {
7803
+ if (!isTrackingEnabled()) {
7804
+ return {};
7805
+ }
7806
+ return {
7807
+ userId: getUserKey(),
7808
+ sessionId: getSessionKey()
7809
+ };
7810
+ };
7811
+ const trackLupaEvent = (queryKey, data = {}, options) => {
7812
+ var _a, _b;
7813
+ if (!queryKey || !data.type) {
7814
+ return;
7815
+ }
7816
+ const eventData = {
7817
+ searchQuery: (_a = data.searchQuery) != null ? _a : "",
7818
+ itemId: (_b = data.itemId) != null ? _b : "",
7819
+ name: data.type,
7820
+ userId: getUserKey(),
7821
+ sessionId: getSessionKey(),
7822
+ filters: data.filters,
7823
+ metadata: data.metadata,
7824
+ sourceItemId: data.sourceItemId
7825
+ };
7826
+ LupaSearchSdk.track(queryKey, eventData, options);
7827
+ };
7828
+ const sendGa = (name, ...args) => {
7829
+ window.ga(() => {
7830
+ const trackers = window.ga.getAll();
7831
+ const firstTracker = trackers[0];
7832
+ if (!firstTracker) {
7833
+ console.error("GA tracker not found");
7834
+ }
7835
+ const trackerName = firstTracker.get("name");
7836
+ window.ga(`${trackerName}.${name}`, ...args);
7837
+ });
7838
+ };
7839
+ const trackAnalyticsEvent = (data) => {
7840
+ var _a, _b, _c;
7841
+ try {
7842
+ const options = JSON.parse(
7843
+ (_a = window.sessionStorage.getItem(TRACKING_ANALYTICS_KEY)) != null ? _a : "{}"
7844
+ );
7845
+ if (!data.analytics || !options.enabled || ((_c = options.ignoreEvents) == null ? void 0 : _c.includes((_b = data.analytics) == null ? void 0 : _b.type))) {
7846
+ return;
7847
+ }
7848
+ switch (options.type) {
7849
+ case "ua":
7850
+ sendUaAnalyticsEvent(data, options);
7851
+ break;
7852
+ case "ga4":
7853
+ sendGa4AnalyticsEvent(data, options);
7854
+ break;
7855
+ case "debug":
7856
+ processDebugEvent(data);
7857
+ break;
7858
+ default:
7859
+ sendUaAnalyticsEvent(data, options);
7860
+ }
7861
+ } catch (e2) {
7862
+ console.error("Unable to send an event to google analytics");
7863
+ }
7864
+ };
7865
+ const parseEcommerceData = (data, title) => {
7866
+ var _a, _b;
7867
+ return ((_a = data.analytics) == null ? void 0 : _a.items) ? {
7868
+ item_list_name: title,
7869
+ items: (_b = data.analytics) == null ? void 0 : _b.items
7870
+ } : void 0;
7871
+ };
7872
+ const sendUaAnalyticsEvent = (data, options) => {
7873
+ var _a, _b, _c, _d;
7874
+ const ga = window.ga;
7875
+ if (!ga) {
7876
+ console.error("Google Analytics object not found");
7877
+ return;
7878
+ }
7879
+ sendGa(
7880
+ "send",
7881
+ "event",
7882
+ options.parentEventName,
7883
+ (_b = (_a = data.analytics) == null ? void 0 : _a.type) != null ? _b : "",
7884
+ (_d = (_c = data.analytics) == null ? void 0 : _c.label) != null ? _d : ""
7885
+ );
7886
+ };
7887
+ const sendGa4AnalyticsEvent = (data, options) => {
7888
+ var _a, _b, _c, _d, _e, _f, _g;
7889
+ if (!window || !window.dataLayer) {
7890
+ console.error("dataLayer object not found.");
7891
+ return;
7892
+ }
7893
+ const sendItemTitle = data.searchQuery !== ((_a = data.analytics) == null ? void 0 : _a.label);
7894
+ const title = sendItemTitle ? (_b = data.analytics) == null ? void 0 : _b.label : void 0;
7895
+ const params = __spreadValues({
7896
+ search_text: data.searchQuery,
7897
+ item_title: title,
7898
+ item_id: data.itemId,
7899
+ ecommerce: parseEcommerceData(data, (_c = data.analytics) == null ? void 0 : _c.listLabel)
7900
+ }, (_e = (_d = data.analytics) == null ? void 0 : _d.additionalParams) != null ? _e : {});
7901
+ window.dataLayer.push(__spreadValues({
7902
+ event: (_g = (_f = data.analytics) == null ? void 0 : _f.type) != null ? _g : options.parentEventName
7903
+ }, params));
7904
+ };
7905
+ const processDebugEvent = (data) => {
7906
+ var _a, _b, _c, _d;
7907
+ const sendItemTitle = data.searchQuery !== ((_a = data.analytics) == null ? void 0 : _a.label);
7908
+ const title = sendItemTitle ? (_b = data.analytics) == null ? void 0 : _b.label : void 0;
7909
+ const params = {
7910
+ event: (_c = data.analytics) == null ? void 0 : _c.type,
7911
+ search_text: data.searchQuery,
7912
+ item_title: title,
7913
+ item_id: data.itemId,
7914
+ ecommerce: parseEcommerceData(data, (_d = data.analytics) == null ? void 0 : _d.listLabel)
7915
+ };
7916
+ console.debug("Analytics debug event:", params);
7917
+ };
7918
+ const getDelayedEventsCache = () => {
7919
+ var _a;
7920
+ try {
7921
+ return JSON.parse((_a = window.localStorage.getItem(DELAYED_TRACKING_EVENTS_CACHE)) != null ? _a : "{}");
7922
+ } catch (e2) {
7923
+ return {};
7924
+ }
7925
+ };
7926
+ const storeDelayedEventCache = (cache) => {
7927
+ try {
7928
+ window.localStorage.setItem(DELAYED_TRACKING_EVENTS_CACHE, JSON.stringify(cache));
7929
+ } catch (e2) {
7930
+ }
7931
+ };
7932
+ const checkAndDispatchDelayedEvents = () => {
7933
+ var _a, _b;
7934
+ const optionsStore = useOptionsStore();
7935
+ const eventCache = getDelayedEventsCache();
7936
+ const urls = Object.keys(eventCache);
7937
+ for (const url of urls) {
7938
+ if ((_a = window.location.href) == null ? void 0 : _a.includes(url)) {
7939
+ const options = (_b = optionsStore.envOptions) != null ? _b : { environment: "production" };
7940
+ const { queryKey, data } = eventCache[url];
7941
+ track(queryKey, data, options);
7942
+ }
7943
+ }
7944
+ storeDelayedEventCache({});
7945
+ };
7946
+ const track = (queryKey, data = {}, options) => {
7947
+ var _a;
7948
+ if (!isTrackingEnabled()) {
7949
+ return;
7950
+ }
7951
+ const hasSearchQuery = data.searchQuery;
7952
+ if (!hasSearchQuery && !((_a = data.options) == null ? void 0 : _a.allowEmptySearchQuery)) {
7953
+ return;
7954
+ }
7955
+ trackAnalyticsEvent(data);
7956
+ trackLupaEvent(queryKey, data, options);
7957
+ };
7958
+ var DocumentElementType = /* @__PURE__ */ ((DocumentElementType2) => {
7959
+ DocumentElementType2["IMAGE"] = "image";
7960
+ DocumentElementType2["TITLE"] = "title";
7961
+ DocumentElementType2["CUSTOM"] = "custom";
7962
+ DocumentElementType2["DESCRIPTION"] = "description";
7963
+ DocumentElementType2["PRICE"] = "price";
7964
+ DocumentElementType2["REGULARPRICE"] = "regularPrice";
7965
+ DocumentElementType2["RATING"] = "rating";
7966
+ DocumentElementType2["SINGLE_STAR_RATING"] = "singleStarRating";
7967
+ DocumentElementType2["ADDTOCART"] = "addToCart";
7968
+ DocumentElementType2["CUSTOM_HTML"] = "customHtml";
7969
+ return DocumentElementType2;
7970
+ })(DocumentElementType || {});
7971
+ var SearchBoxPanelType = /* @__PURE__ */ ((SearchBoxPanelType2) => {
7972
+ SearchBoxPanelType2["SUGGESTION"] = "suggestion";
7973
+ SearchBoxPanelType2["DOCUMENT"] = "document";
7974
+ SearchBoxPanelType2["RELATED_SOURCE"] = "related-source";
7975
+ return SearchBoxPanelType2;
7976
+ })(SearchBoxPanelType || {});
7977
+ var BadgeType = /* @__PURE__ */ ((BadgeType2) => {
7978
+ BadgeType2["NEWITEM"] = "newItem";
7979
+ BadgeType2["TEXT"] = "text";
7980
+ BadgeType2["IMAGE"] = "image";
7981
+ BadgeType2["CUSTOM_HTML"] = "customHtml";
7982
+ BadgeType2["DISCOUNT"] = "discount";
7983
+ return BadgeType2;
7984
+ })(BadgeType || {});
7985
+ const retrieveHistory = () => {
7986
+ try {
7987
+ const historyString = window.localStorage.getItem(HISTORY_LOCAL_STORAGE_KEY);
7988
+ return historyString ? JSON.parse(historyString) : [];
7989
+ } catch (e2) {
7990
+ return [];
7991
+ }
7992
+ };
7993
+ const saveHistory = (items) => {
7994
+ try {
7995
+ window.localStorage.setItem(
7996
+ HISTORY_LOCAL_STORAGE_KEY,
7997
+ JSON.stringify(items.slice(0, HISTORY_MAX_ITEMS))
7998
+ );
7999
+ } catch (e2) {
8000
+ }
8001
+ };
8002
+ const useHistoryStore = defineStore("history", () => {
8003
+ const items = ref(retrieveHistory());
8004
+ const count = computed(() => items.value.length);
8005
+ const add = ({ item }) => {
8006
+ if (!item) {
8007
+ return items.value;
8008
+ }
8009
+ const newItems = items.value ? [item, ...items.value] : [item];
8010
+ const uniqueItems = Array.from(new Set(newItems));
8011
+ items.value = uniqueItems;
8012
+ saveHistory(uniqueItems);
8013
+ return uniqueItems;
8014
+ };
8015
+ const remove = ({ item }) => {
8016
+ var _a, _b;
8017
+ const tempItems = (_b = (_a = items.value) == null ? void 0 : _a.filter((i) => i !== item)) != null ? _b : [];
8018
+ saveHistory(tempItems);
8019
+ items.value = tempItems;
8020
+ return tempItems;
8021
+ };
8022
+ const clear = () => {
8023
+ saveHistory([]);
8024
+ items.value = [];
8025
+ };
8026
+ return { items, count, add, remove, clear };
8027
+ });
8028
+ const QUERY_PARAMS = {
8029
+ QUERY: "q",
8030
+ PAGE: "p",
8031
+ LIMIT: "l",
8032
+ SORT: "s"
8033
+ };
8034
+ const QUERY_PARAMS_PARSED = {
8035
+ QUERY: "query",
8036
+ PAGE: "page",
8037
+ LIMIT: "limit",
8038
+ SORT: "sort"
8039
+ };
8040
+ const FACET_PARAMS_TYPE = {
8041
+ TERMS: "f.",
8042
+ RANGE: "fr.",
8043
+ HIERARCHY: "fh."
8044
+ };
8045
+ const FACET_FILTER_MAP = {
8046
+ terms: FACET_PARAMS_TYPE.TERMS,
8047
+ range: FACET_PARAMS_TYPE.RANGE,
8048
+ hierarchy: FACET_PARAMS_TYPE.HIERARCHY
8049
+ };
8050
+ const FACET_KEY_SEPARATOR = ".";
8051
+ const FACET_RANGE_SEPARATOR = ":";
8052
+ const HIERARCHY_SEPARATOR = ">";
8053
+ const FACET_TERM_RANGE_SEPARATOR = "-";
8054
+ const getAmount = (price, separator = ".") => {
8055
+ var _a, _b;
8056
+ if (typeof price === "number") {
8057
+ return `${(_a = price.toFixed(2)) == null ? void 0 : _a.replace(".", separator)}`;
8058
+ }
8059
+ const value = parseFloat(price);
8060
+ if (isNaN(value)) {
8061
+ return "";
8062
+ }
8063
+ return (_b = value.toFixed(2)) == null ? void 0 : _b.replace(".", separator);
8064
+ };
8065
+ const formatPrice = (price, currency = "€", separator = ",", currencyTemplate = "") => {
8066
+ if (price !== 0 && !price) {
8067
+ return "";
8068
+ }
8069
+ const amount = getAmount(price, separator);
8070
+ if (!amount) {
8071
+ return "";
8072
+ }
8073
+ if (currencyTemplate) {
8074
+ return addParamsToLabel(currencyTemplate, amount);
8075
+ }
8076
+ return `${amount} ${currency}`;
8077
+ };
8078
+ const formatPriceSummary = ([min, max], currency, separator = ",", currencyTemplate = "") => {
8079
+ if (min !== void 0 && max !== void 0) {
8080
+ return `${formatPrice(min, currency, separator, currencyTemplate)} - ${formatPrice(
8081
+ max,
8082
+ currency,
8083
+ separator,
8084
+ currencyTemplate
8085
+ )}`;
8086
+ }
8087
+ if (min !== void 0) {
8088
+ return `> ${formatPrice(min, currency, separator, currencyTemplate)}`;
8089
+ }
8090
+ return `< ${formatPrice(max, currency, separator, currencyTemplate)}`;
8091
+ };
8092
+ const getTranslatedFacetKey = (facet, translations) => {
8093
+ var _a, _b;
8094
+ return (_b = (_a = translations == null ? void 0 : translations.keyTranslations) == null ? void 0 : _a[facet.key]) != null ? _b : facet.label;
8095
+ };
8096
+ const getTranslatedFacetValue = (facet, value, translations) => {
8097
+ var _a, _b, _c;
8098
+ return (_c = (_b = (_a = translations == null ? void 0 : translations.valueTranslations) == null ? void 0 : _a[facet.key]) == null ? void 0 : _b[value == null ? void 0 : value.title]) != null ? _c : value.title;
8099
+ };
8100
+ const formatRange = (filter2) => {
8101
+ var _a, _b;
8102
+ const lt = (_a = filter2.lt) != null ? _a : filter2.lte;
8103
+ const gt = (_b = filter2.gt) != null ? _b : filter2.gte;
8104
+ if (gt !== void 0 && lt !== void 0) {
8105
+ return `${gt} - ${lt}`;
8106
+ }
8107
+ if (lt !== void 0) {
8108
+ return `<${filter2.lte !== void 0 ? "=" : ""} ${lt}`;
8109
+ }
8110
+ return `>${filter2.gte !== void 0 ? "=" : ""} ${gt}`;
8111
+ };
8112
+ const unfoldTermFilter = (key, filter2) => {
8113
+ const seed = [];
8114
+ return filter2.reduce((a, c2) => [...a, { key, value: c2, type: "terms" }], seed);
8115
+ };
8116
+ const unfoldHierarchyFilter = (key, filter2) => {
8117
+ const seed = [];
8118
+ return filter2.terms.reduce((a, c2) => [...a, { key, value: c2, type: "hierarchy" }], seed);
8119
+ };
8120
+ const unfoldRangeFilter = (key, filter2, price = {}) => {
8121
+ var _a;
8122
+ const gt = filter2.gte || filter2.gt;
8123
+ const lt = filter2.lte || filter2.lt;
8124
+ if (key.includes(CURRENCY_KEY_INDICATOR) || ((_a = price == null ? void 0 : price.keys) == null ? void 0 : _a.includes(key))) {
8125
+ return [
8126
+ {
8127
+ key,
8128
+ value: formatPriceSummary(
8129
+ [gt, lt],
8130
+ price.currency,
8131
+ price.separator,
8132
+ price.currencyTemplate
8133
+ ),
8134
+ type: "range"
8135
+ }
8136
+ ];
8137
+ }
8138
+ return [{ key, value: `${gt} - ${lt}`, type: "range" }];
8139
+ };
8140
+ const unfoldFilter = (key, filter2, price = {}) => {
8141
+ if (Array.isArray(filter2)) {
8142
+ return unfoldTermFilter(key, filter2);
8143
+ }
8144
+ if (filter2.gte) {
8145
+ return unfoldRangeFilter(key, filter2, price);
8146
+ }
8147
+ if (filter2.terms) {
8148
+ return unfoldHierarchyFilter(key, filter2);
8149
+ }
8150
+ return [];
8151
+ };
8152
+ const unfoldFilters = (filters, price = {}) => {
8153
+ if (!filters) {
8154
+ return [];
8155
+ }
8156
+ const seed = [];
8157
+ return Object.entries(filters).reduce((a, c2) => [...a, ...unfoldFilter(...c2, price)], seed);
8158
+ };
8159
+ const getLabeledFilters = (filters, facets2, translations) => {
8160
+ return filters.map((f2) => {
8161
+ var _a, _b, _c, _d;
8162
+ return __spreadProps(__spreadValues({}, f2), {
8163
+ label: (_d = (_c = (_a = translations == null ? void 0 : translations.keyTranslations) == null ? void 0 : _a[f2.key]) != null ? _c : (_b = facets2 == null ? void 0 : facets2.find((ft) => ft.key === f2.key)) == null ? void 0 : _b.label) != null ? _d : capitalize$1(f2.key),
8164
+ value: getTranslatedFacetValue({ key: f2.key }, { title: f2.value }, translations)
8165
+ });
8166
+ });
8167
+ };
8168
+ const isFacetKey = (key) => key.startsWith(FACET_PARAMS_TYPE.RANGE) || key.startsWith(FACET_PARAMS_TYPE.TERMS) || key.startsWith(FACET_PARAMS_TYPE.HIERARCHY);
8169
+ const getMostSpecificHierarchyTerms = (terms) => {
8170
+ const specificTerms = [];
8171
+ for (const term of terms) {
8172
+ if (!terms.some((t) => t.startsWith(term) && t !== term)) {
8173
+ specificTerms.push(term);
8174
+ }
8175
+ }
8176
+ return Array.from(new Set(specificTerms));
8177
+ };
8178
+ const recursiveFilter = (items, query = "") => {
8179
+ if (!query) {
8180
+ return items;
8181
+ }
8182
+ return items.map((i) => recursiveFilterItem(i, query)).filter(Boolean);
8183
+ };
8184
+ const recursiveFilterItem = (item, query = "") => {
8185
+ const filterable = getNormalizedString(item.title).includes(getNormalizedString(query)) ? item : void 0;
8186
+ if (!item.children) {
8187
+ return filterable;
8188
+ }
8189
+ const children = recursiveFilter(item.children, query).filter(Boolean);
8190
+ const include = children.length > 0 || filterable;
8191
+ return include ? __spreadProps(__spreadValues({}, item), {
8192
+ children
8193
+ }) : void 0;
8194
+ };
8195
+ const rangeFilterToString = (rangeFilter, separator) => {
8196
+ separator = separator || FACET_TERM_RANGE_SEPARATOR;
8197
+ return rangeFilter && Object.keys(rangeFilter).length ? rangeFilter.gte + separator + (rangeFilter.lte || rangeFilter.lt) : "";
8198
+ };
8199
+ const pick = (obj, keys) => {
8200
+ const ret = /* @__PURE__ */ Object.create({});
8201
+ for (const k of keys) {
8202
+ ret[k] = obj[k];
8203
+ }
8204
+ return ret;
8205
+ };
8206
+ const getHint = (suggestion, inputValue) => {
8207
+ var _a;
8208
+ if (!inputValue) {
8209
+ return escapeHtml$1(suggestion);
8210
+ }
8211
+ return (_a = suggestion == null ? void 0 : suggestion.replace(
8212
+ inputValue == null ? void 0 : inputValue.toLocaleLowerCase(),
8213
+ `<strong>${escapeHtml$1(inputValue == null ? void 0 : inputValue.toLocaleLowerCase())}</strong>`
8214
+ )) != null ? _a : "";
8215
+ };
8216
+ const reverseKeyValue = (obj) => {
8217
+ return Object.fromEntries(Object.entries(obj).map(([k, v]) => [v, k.toLowerCase()]));
8218
+ };
8219
+ const getPageCount = (total, limit) => {
8220
+ return Math.ceil(total / limit) || 0;
8221
+ };
8222
+ const isObject$1 = (value) => {
8223
+ return value !== null && typeof value === "object" && !Array.isArray(value);
8224
+ };
8225
+ const parseParam = (key, params) => {
8226
+ const value = params.get(key);
8227
+ if (!value) {
8228
+ return void 0;
8229
+ }
8230
+ try {
8231
+ return decodeURIComponent(value);
8232
+ } catch (e2) {
8233
+ return void 0;
8234
+ }
8235
+ };
8236
+ const parseRegularKeys = (regularKeys, searchParams, getQueryParamName) => {
8237
+ const params = /* @__PURE__ */ Object.create({});
8238
+ const keys = reverseKeyValue({
8239
+ QUERY: getQueryParamName ? getQueryParamName(QUERY_PARAMS.QUERY) : QUERY_PARAMS.QUERY,
8240
+ LIMIT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.LIMIT) : QUERY_PARAMS.LIMIT,
8241
+ PAGE: getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE,
8242
+ SORT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.SORT) : QUERY_PARAMS.SORT
8243
+ });
8244
+ for (const key of regularKeys) {
8245
+ const rawKey = keys[key] || key;
8246
+ params[rawKey] = parseParam(key, searchParams);
8247
+ }
8248
+ return params;
8249
+ };
8250
+ const parseFacetKey = (key, searchParams) => {
8251
+ var _a, _b, _c, _d;
8252
+ if (key.startsWith(FACET_PARAMS_TYPE.TERMS)) {
8253
+ return (_b = (_a = searchParams.getAll(key)) == null ? void 0 : _a.map((v) => decodeURIComponent(v))) != null ? _b : [];
8254
+ }
8255
+ if (key.startsWith(FACET_PARAMS_TYPE.RANGE)) {
8256
+ const range = searchParams.get(key);
8257
+ if (!range) {
8258
+ return {};
8259
+ }
8260
+ const [min, max] = range.split(FACET_RANGE_SEPARATOR);
8261
+ return {
8262
+ gte: min,
8263
+ lte: max
8264
+ };
8265
+ }
8266
+ if (key.startsWith(FACET_PARAMS_TYPE.HIERARCHY)) {
8267
+ return {
8268
+ level: 0,
8269
+ terms: (_d = (_c = searchParams.getAll(key)) == null ? void 0 : _c.map((v) => decodeURIComponent(v))) != null ? _d : []
8270
+ };
8271
+ }
8272
+ return [];
8273
+ };
8274
+ const parseFacetKeys = (facetKeys, searchParams) => {
8275
+ const params = {};
8276
+ params.filters = {};
8277
+ for (const key of facetKeys) {
8278
+ const parsedKey = key.slice(key.indexOf(FACET_KEY_SEPARATOR) + 1);
8279
+ params.filters = __spreadProps(__spreadValues({}, params.filters), {
8280
+ [parsedKey]: parseFacetKey(key, searchParams)
8281
+ });
8282
+ }
8283
+ return params;
8284
+ };
8285
+ const parseParams = (getQueryParamName, searchParams) => {
8286
+ const params = /* @__PURE__ */ Object.create({});
8287
+ if (!searchParams)
8288
+ return params;
8289
+ const paramKeys = Array.from(searchParams.keys());
8290
+ const facetKeys = paramKeys.filter((k) => isFacetKey(k));
8291
+ const regularKeys = paramKeys.filter((k) => !isFacetKey(k));
8292
+ const r = __spreadValues(__spreadValues({
8293
+ [QUERY_PARAMS_PARSED.QUERY]: ""
8294
+ }, parseRegularKeys(regularKeys, searchParams, getQueryParamName)), parseFacetKeys(facetKeys, searchParams));
8295
+ return r;
8296
+ };
8297
+ const appendParam = (url, { name, value }, encode2 = true) => {
8298
+ if (Array.isArray(value)) {
8299
+ appendArrayParams(url, { name, value });
8300
+ } else {
8301
+ appendSingleParam(url, { name, value }, encode2);
8302
+ }
8303
+ };
8304
+ const appendSingleParam = (url, param, encode2 = true) => {
8305
+ const valueToAppend = encode2 ? encodeParam(param.value) : param.value;
8306
+ if (url.searchParams.has(param.name)) {
8307
+ url.searchParams.set(param.name, valueToAppend);
8308
+ } else {
8309
+ url.searchParams.append(param.name, valueToAppend);
8310
+ }
8311
+ };
8312
+ const appendArrayParams = (url, param) => {
8313
+ url.searchParams.delete(param.name);
8314
+ param.value.forEach((v) => url.searchParams.append(param.name, encodeParam(v)));
8315
+ };
8316
+ const getRemovableParams = (url, getQueryParamName, paramsToRemove) => {
8317
+ if (paramsToRemove === "all") {
8318
+ const params = {
8319
+ QUERY: getQueryParamName ? getQueryParamName(QUERY_PARAMS.QUERY) : QUERY_PARAMS.QUERY,
8320
+ LIMIT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.LIMIT) : QUERY_PARAMS.LIMIT,
8321
+ PAGE: getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE,
8322
+ SORT: getQueryParamName ? getQueryParamName(QUERY_PARAMS.SORT) : QUERY_PARAMS.SORT
8323
+ };
8324
+ return [
8325
+ ...Object.values(params),
8326
+ ...Array.from(url.searchParams.keys()).filter((k) => isFacetKey(k))
8327
+ ];
8328
+ }
8329
+ return paramsToRemove;
8330
+ };
8331
+ const removeParams = (url, params = []) => {
8332
+ for (const param of params) {
8333
+ if (url.searchParams.has(param)) {
8334
+ url.searchParams.delete(param);
8335
+ }
8336
+ }
8337
+ };
8338
+ const encodeParam = (param) => {
8339
+ const encoded = encodeURIComponent(param);
8340
+ return encoded.replace(/%C4%85/g, "ą").replace(/%C4%8D/g, "č").replace(/%C4%99/g, "ę").replace(/%C4%97/g, "ė").replace(/%C4%AF/g, "į").replace(/%C5%A1/g, "š").replace(/%C5%B3/g, "ų").replace(/%C5%AB/g, "ū").replace(/%C5%BE/g, "ž").replace(/%20/g, " ");
8341
+ };
8342
+ const getQueryParam = (name) => {
8343
+ try {
8344
+ const urlParams = new URLSearchParams(window.location.search);
8345
+ return urlParams.get(name);
8346
+ } catch (e2) {
8347
+ return null;
8348
+ }
8349
+ };
8350
+ const PATH_REPLACE_REGEXP = /{(.*?)}/gm;
8351
+ const generateLink = (linkPattern, document2) => {
8352
+ const matches = linkPattern.match(PATH_REPLACE_REGEXP);
8353
+ if (!matches) {
8354
+ return linkPattern;
8355
+ }
8356
+ let link = linkPattern;
8357
+ for (const match of matches) {
8358
+ const propertyKey = match.slice(1, match.length - 1);
8359
+ const property = document2[propertyKey] || "";
8360
+ link = link.replace(match, property);
8361
+ }
8362
+ return link;
8363
+ };
8364
+ const generateResultLink = (link, getQueryParamName, searchText, facet) => {
8365
+ if (!searchText) {
8366
+ return link;
8367
+ }
8368
+ const facetParam = facet ? `&${FACET_PARAMS_TYPE.TERMS}${encodeParam(facet.key)}=${encodeParam(facet.title)}` : "";
8369
+ const queryParam = `?${getQueryParamName ? getQueryParamName(QUERY_PARAMS.QUERY) : QUERY_PARAMS.QUERY}=${encodeParam(searchText)}`;
8370
+ return `${link}${queryParam}${facetParam}`;
8371
+ };
8372
+ const getRelativePath = (link) => {
8373
+ try {
8374
+ const url = new URL(link);
8375
+ const partialUrl = url.toString().substring(url.origin.length);
8376
+ return partialUrl.endsWith("/") ? partialUrl.slice(0, partialUrl.length - 1) : partialUrl;
8377
+ } catch (e2) {
8378
+ return (link == null ? void 0 : link.endsWith("/")) ? link.slice(0, link.length - 1) : link;
8379
+ }
8380
+ };
8381
+ const linksMatch = (link1, link2) => {
8382
+ if (!link1 || !link2) {
8383
+ return false;
8384
+ }
8385
+ return link1 === link2 || getRelativePath(link1) === getRelativePath(link2);
8386
+ };
8387
+ const emitRoutingEvent = (url) => {
8388
+ const event = new CustomEvent(LUPA_ROUTING_EVENT, { detail: url });
8389
+ window.dispatchEvent(event);
8390
+ };
8391
+ const handleRoutingEvent = (link, event, hasEventRouting = false) => {
8392
+ if (!hasEventRouting) {
8393
+ return;
8394
+ }
8395
+ event == null ? void 0 : event.preventDefault();
8396
+ emitRoutingEvent(link);
8397
+ };
8398
+ const redirectToResultsPage = (link, searchText, getQueryParamName, facet, routingBehavior = "direct-link") => {
8399
+ const url = generateResultLink(link, getQueryParamName, searchText, facet);
8400
+ if (routingBehavior === "event") {
8401
+ emitRoutingEvent(url);
8402
+ } else {
8403
+ window.location.assign(url);
8404
+ }
8405
+ };
8406
+ const getPageUrl = (pathnameOverride, ssr) => {
8407
+ if (typeof window !== "undefined") {
8408
+ const pathname = pathnameOverride || window.location.pathname;
8409
+ const origin = window.location.origin;
8410
+ const search2 = window.location.search;
8411
+ return new URL(origin + pathname + search2);
8412
+ }
8413
+ return new URL(ssr.url, ssr.baseUrl);
8414
+ };
8415
+ const getFacetKey = (key, type) => {
8416
+ return `${FACET_FILTER_MAP[type]}${key}`;
8417
+ };
8418
+ const getFacetParam = (key, value, type = FACET_PARAMS_TYPE.TERMS) => {
8419
+ return {
8420
+ name: `${type}${key}`,
8421
+ value
8422
+ };
8423
+ };
8424
+ const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentFilters, paramsToRemove = []) => {
8425
+ const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
8426
+ const newParams = toggleTermParam(currentFilter, facetAction.value);
8427
+ appendParams({
8428
+ params: [getFacetParam(facetAction.key, newParams)],
8429
+ paramsToRemove: [
8430
+ ...paramsToRemove,
8431
+ ...[getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
8432
+ ]
8433
+ });
8434
+ };
8435
+ const replaceHierarchyParam = (params = [], param = "") => {
8436
+ if (params.some((p2) => p2.startsWith(param))) {
8437
+ return toggleLastPram(params, param);
8438
+ }
8439
+ return [param];
8440
+ };
8441
+ const toggleHierarchyFilter = (appendParams, facetAction, getQueryParamName, currentFilters, removeAllLevels = false) => {
8442
+ var _a, _b;
8443
+ const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
8444
+ const newParams = facetAction.behavior === "replace" ? replaceHierarchyParam((_a = currentFilter == null ? void 0 : currentFilter.terms) != null ? _a : [], facetAction.value) : toggleHierarchyParam((_b = currentFilter == null ? void 0 : currentFilter.terms) != null ? _b : [], facetAction.value, removeAllLevels);
8445
+ appendParams({
8446
+ params: [getFacetParam(facetAction.key, newParams, FACET_PARAMS_TYPE.HIERARCHY)],
8447
+ paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
8448
+ });
8449
+ };
8450
+ const toggleRangeFilter = (appendParams, facetAction, getQueryParamName, currentFilters) => {
8451
+ const currentFilter = rangeFilterToString(
8452
+ currentFilters == null ? void 0 : currentFilters[facetAction.key],
8453
+ FACET_RANGE_SEPARATOR
8454
+ );
8455
+ let facetValue = facetAction.value.join(FACET_RANGE_SEPARATOR);
8456
+ facetValue = currentFilter === facetValue ? "" : facetValue;
8457
+ appendParams({
8458
+ params: [getFacetParam(facetAction.key, facetValue, FACET_PARAMS_TYPE.RANGE)],
8459
+ paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE],
8460
+ encode: false
8461
+ });
8462
+ };
8463
+ const toggleTermParam = (params = [], param = "") => {
8464
+ if (params == null ? void 0 : params.includes(param)) {
8465
+ return params.filter((p2) => p2 !== param);
8466
+ }
8467
+ return [param, ...params];
8468
+ };
8469
+ const toggleLastPram = (params = [], param = "") => {
8470
+ const paramLevel = param.split(">").length;
8471
+ return getMostSpecificHierarchyTerms(
8472
+ params.map(
8473
+ (p2) => p2.startsWith(param) ? p2.split(HIERARCHY_SEPARATOR).slice(0, paramLevel - 1).join(HIERARCHY_SEPARATOR).trim() : p2
8474
+ ).filter(Boolean)
8475
+ );
8476
+ };
8477
+ const toggleHierarchyParam = (params = [], param = "", removeAllLevels = false) => {
8478
+ if (params == null ? void 0 : params.some((p2) => p2.startsWith(param))) {
8479
+ return removeAllLevels ? getMostSpecificHierarchyTerms(params.filter((p2) => !p2.startsWith(param))) : toggleLastPram(params, param);
8480
+ }
8481
+ return getMostSpecificHierarchyTerms([param, ...params]);
8482
+ };
8483
+ const CACHE_KEY = "lupasearch-client-redirections";
8484
+ const useRedirectionStore = defineStore("redirections", () => {
8485
+ const redirections = ref({ rules: [] });
8486
+ const redirectionOptions = ref({ enabled: false, queryKey: "" });
8487
+ const saveToLocalStorage = () => {
8488
+ try {
8489
+ localStorage.setItem(
8490
+ CACHE_KEY,
8491
+ JSON.stringify({
8492
+ redirections: redirections.value,
8493
+ savedAt: Date.now(),
8494
+ queryKey: redirectionOptions.value.queryKey
8495
+ })
8496
+ );
8497
+ } catch (e2) {
8498
+ }
8499
+ };
8500
+ const tryLoadFromLocalStorage = (config) => {
8501
+ var _a;
8502
+ if (!config.cacheSeconds)
8503
+ return false;
8504
+ try {
8505
+ const data = JSON.parse((_a = localStorage.getItem(CACHE_KEY)) != null ? _a : "");
8506
+ if (data.queryKey !== config.queryKey) {
8507
+ return false;
8508
+ }
8509
+ if ((data == null ? void 0 : data.redirections) && Date.now() - data.savedAt < 1e3 * config.cacheSeconds) {
8510
+ redirections.value = data.redirections;
8511
+ return true;
8512
+ }
8513
+ } catch (e2) {
8514
+ }
8515
+ return false;
8516
+ };
8517
+ const initiate = (config, options) => __async(void 0, null, function* () {
8518
+ var _a, _b, _c, _d;
8519
+ if ((_a = redirectionOptions.value) == null ? void 0 : _a.enabled) {
8520
+ return;
8521
+ }
8522
+ redirectionOptions.value = config;
8523
+ if (!(config == null ? void 0 : config.enabled)) {
8524
+ return;
8525
+ }
8526
+ const loaded = tryLoadFromLocalStorage(config);
8527
+ if (loaded || ((_c = (_b = redirections.value) == null ? void 0 : _b.rules) == null ? void 0 : _c.length) > 0) {
8528
+ return;
8529
+ }
8530
+ try {
8531
+ const result2 = yield LupaSearchSdk.loadRedirectionRules(config.queryKey, options);
8532
+ if (!((_d = result2 == null ? void 0 : result2.rules) == null ? void 0 : _d.length)) {
8533
+ redirections.value = { rules: [] };
8534
+ return;
8535
+ }
8536
+ redirections.value = result2;
8537
+ saveToLocalStorage();
8538
+ } catch (e2) {
8539
+ }
8540
+ });
8541
+ const redirectOnKeywordIfConfigured = (input2, routingBehavior = "direct-link") => {
8542
+ var _a, _b, _c, _d;
8543
+ if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
8544
+ return false;
8545
+ }
8546
+ const redirectTo = redirections.value.rules.find((r) => inputsAreEqual(input2, r.sources));
8547
+ if (!redirectTo) {
8548
+ return false;
8549
+ }
8550
+ const url = ((_c = redirectionOptions.value) == null ? void 0 : _c.urlTransformer) ? (_d = redirectionOptions.value) == null ? void 0 : _d.urlTransformer(redirectTo == null ? void 0 : redirectTo.target) : redirectTo == null ? void 0 : redirectTo.target;
8551
+ if (url === void 0 || url === null || url === "") {
8552
+ return false;
8553
+ }
8554
+ if (routingBehavior === "event") {
8555
+ emitRoutingEvent(url);
8554
8556
  } else {
8555
- root2._ = _;
8557
+ window.location.assign(url);
8556
8558
  }
8557
- }).call(commonjsGlobal);
8558
- })(lodash, lodash.exports);
8559
- var lodashExports = lodash.exports;
8559
+ return true;
8560
+ };
8561
+ return {
8562
+ redirections,
8563
+ redirectOnKeywordIfConfigured,
8564
+ initiate
8565
+ };
8566
+ });
8560
8567
  const joinUrlParts = (...parts) => {
8561
8568
  var _a, _b, _c;
8562
8569
  if (parts.length === 1) {
@@ -8995,7 +9002,7 @@ const _hoisted_1$1i = { id: "lupa-search-box-input-container" };
8995
9002
  const _hoisted_2$T = { class: "lupa-input-clear" };
8996
9003
  const _hoisted_3$C = { id: "lupa-search-box-input" };
8997
9004
  const _hoisted_4$s = ["value"];
8998
- const _hoisted_5$j = ["aria-label", "placeholder"];
9005
+ const _hoisted_5$i = ["aria-label", "placeholder"];
8999
9006
  const _hoisted_6$9 = /* @__PURE__ */ createElementVNode("span", { class: "lupa-search-submit-icon" }, null, -1);
9000
9007
  const _hoisted_7$7 = [
9001
9008
  _hoisted_6$9
@@ -9115,7 +9122,7 @@ const _sfc_main$1v = /* @__PURE__ */ defineComponent({
9115
9122
  placeholder: labels.value.placeholder,
9116
9123
  onInput: handleInput,
9117
9124
  onFocus: handleFocus
9118
- }), null, 16, _hoisted_5$j), [
9125
+ }), null, 16, _hoisted_5$i), [
9119
9126
  [vModelText, inputValue.value]
9120
9127
  ]),
9121
9128
  _ctx.options.showSubmitButton ? (openBlock(), createElementBlock("button", {
@@ -9331,7 +9338,7 @@ const _hoisted_4$r = {
9331
9338
  class: "lupa-suggestion-facet-label",
9332
9339
  "data-cy": "lupa-suggestion-facet-label"
9333
9340
  };
9334
- const _hoisted_5$i = {
9341
+ const _hoisted_5$h = {
9335
9342
  class: "lupa-suggestion-facet-value",
9336
9343
  "data-cy": "lupa-suggestion-facet-value"
9337
9344
  };
@@ -9374,7 +9381,7 @@ const _sfc_main$1q = /* @__PURE__ */ defineComponent({
9374
9381
  }, null, 8, _hoisted_1$1e)) : (openBlock(), createElementBlock("div", _hoisted_2$R, toDisplayString(_ctx.suggestion.display), 1)),
9375
9382
  _ctx.suggestion.facet ? (openBlock(), createElementBlock("div", _hoisted_3$B, [
9376
9383
  createElementVNode("span", _hoisted_4$r, toDisplayString(facetLabel.value), 1),
9377
- createElementVNode("span", _hoisted_5$i, toDisplayString(_ctx.suggestion.facet.title), 1)
9384
+ createElementVNode("span", _hoisted_5$h, toDisplayString(_ctx.suggestion.facet.title), 1)
9378
9385
  ])) : createCommentVNode("", true)
9379
9386
  ]);
9380
9387
  };
@@ -18918,7 +18925,7 @@ const _hoisted_1$18 = ["innerHTML"];
18918
18925
  const _hoisted_2$N = { key: 0 };
18919
18926
  const _hoisted_3$A = { key: 1 };
18920
18927
  const _hoisted_4$q = { class: "lupa-search-box-custom-label" };
18921
- const _hoisted_5$h = { class: "lupa-search-box-custom-text" };
18928
+ const _hoisted_5$g = { class: "lupa-search-box-custom-text" };
18922
18929
  const _sfc_main$1h = /* @__PURE__ */ defineComponent({
18923
18930
  __name: "SearchBoxProductCustom",
18924
18931
  props: {
@@ -18951,7 +18958,7 @@ const _sfc_main$1h = /* @__PURE__ */ defineComponent({
18951
18958
  }, toHandlers(_ctx.options.action ? { click: handleClick } : {}, true)), [
18952
18959
  !label.value ? (openBlock(), createElementBlock("div", _hoisted_2$N, toDisplayString(text.value), 1)) : (openBlock(), createElementBlock("div", _hoisted_3$A, [
18953
18960
  createElementVNode("div", _hoisted_4$q, toDisplayString(label.value), 1),
18954
- createElementVNode("div", _hoisted_5$h, toDisplayString(text.value), 1)
18961
+ createElementVNode("div", _hoisted_5$g, toDisplayString(text.value), 1)
18955
18962
  ]))
18956
18963
  ], 16));
18957
18964
  };
@@ -20371,7 +20378,7 @@ const _hoisted_4$o = {
20371
20378
  key: 1,
20372
20379
  class: "lupa-panel-title"
20373
20380
  };
20374
- const _hoisted_5$g = {
20381
+ const _hoisted_5$f = {
20375
20382
  key: 1,
20376
20383
  id: "lupa-search-box-panel"
20377
20384
  };
@@ -20595,7 +20602,7 @@ const _sfc_main$11 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValue
20595
20602
  options: _ctx.options,
20596
20603
  onGoToResults: _cache[4] || (_cache[4] = ($event) => _ctx.$emit("go-to-results"))
20597
20604
  }, null, 8, ["labels", "options"])) : createCommentVNode("", true)
20598
- ])) : displayHistory.value ? (openBlock(), createElementBlock("div", _hoisted_5$g, [
20605
+ ])) : displayHistory.value ? (openBlock(), createElementBlock("div", _hoisted_5$f, [
20599
20606
  createVNode(_sfc_main$1s, {
20600
20607
  options: _ctx.options.history,
20601
20608
  history: history.value,
@@ -20681,6 +20688,10 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20681
20688
  var _a2;
20682
20689
  return (_a2 = props.options.searchTriggers) != null ? _a2 : [];
20683
20690
  });
20691
+ const searchBoxCloseTriggers = computed(() => {
20692
+ var _a2, _b;
20693
+ return (_b = (_a2 = props.options.searchBoxCloseTriggers) == null ? void 0 : _a2.map((selector) => document.querySelector(selector))) != null ? _b : [];
20694
+ });
20684
20695
  const goToResultsDebounced = debounce$1(paramsStore.goToResults, (_a = props.options.debounce) != null ? _a : 300);
20685
20696
  onMounted(() => {
20686
20697
  var _a2, _b, _c;
@@ -20704,7 +20715,7 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20704
20715
  unbindSearchTriggers(searchTriggers.value, handleCurrentValueSearch);
20705
20716
  });
20706
20717
  const handleMouseClick = (e2) => {
20707
- var _a2, _b, _c, _d;
20718
+ var _a2, _b, _c, _d, _e;
20708
20719
  const el = document.getElementById("lupa-search-box");
20709
20720
  const elementClass = (_b = (_a2 = e2.target) == null ? void 0 : _a2.className) != null ? _b : "";
20710
20721
  const hasLupaClass = typeof elementClass.includes == "function" && elementClass.includes("lupa-search-box");
@@ -20712,6 +20723,9 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20712
20723
  if (openedAt.value && Date.now() - (openedAt == null ? void 0 : openedAt.value) < 500) {
20713
20724
  return;
20714
20725
  }
20726
+ if ((_c = searchBoxCloseTriggers.value) == null ? void 0 : _c.includes(e2.target)) {
20727
+ close();
20728
+ }
20715
20729
  if (isOutsideElement && props.options.keepOpen) {
20716
20730
  focused.value = false;
20717
20731
  }
@@ -20720,11 +20734,11 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20720
20734
  }
20721
20735
  opened.value = false;
20722
20736
  suggestedValue.value = defaultSuggestedValue;
20723
- if ((_c = props.options.callbacks) == null ? void 0 : _c.onClosed) {
20724
- (_d = props.options.callbacks) == null ? void 0 : _d.onClosed();
20737
+ if ((_d = props.options.callbacks) == null ? void 0 : _d.onClosed) {
20738
+ (_e = props.options.callbacks) == null ? void 0 : _e.onClosed();
20725
20739
  }
20726
20740
  };
20727
- const close = () => {
20741
+ const close = (e2) => {
20728
20742
  var _a2, _b;
20729
20743
  opened.value = false;
20730
20744
  focused.value = false;
@@ -21169,7 +21183,7 @@ const _hoisted_3$u = {
21169
21183
  class: "lupa-results-total-count"
21170
21184
  };
21171
21185
  const _hoisted_4$m = { class: "lupa-results-total-count-number" };
21172
- const _hoisted_5$f = ["innerHTML"];
21186
+ const _hoisted_5$e = ["innerHTML"];
21173
21187
  const _sfc_main$Z = /* @__PURE__ */ defineComponent({
21174
21188
  __name: "SearchResultsTitle",
21175
21189
  props: {
@@ -21230,7 +21244,7 @@ const _sfc_main$Z = /* @__PURE__ */ defineComponent({
21230
21244
  key: 2,
21231
21245
  class: "lupa-result-page-description-top",
21232
21246
  innerHTML: descriptionTop.value
21233
- }, null, 8, _hoisted_5$f)) : createCommentVNode("", true)
21247
+ }, null, 8, _hoisted_5$e)) : createCommentVNode("", true)
21234
21248
  ]);
21235
21249
  };
21236
21250
  }
@@ -21433,7 +21447,7 @@ const _hoisted_1$P = {
21433
21447
  const _hoisted_2$B = { class: "lupa-category-back" };
21434
21448
  const _hoisted_3$s = ["href"];
21435
21449
  const _hoisted_4$k = ["href"];
21436
- const _hoisted_5$e = { class: "lupa-child-category-list" };
21450
+ const _hoisted_5$d = { class: "lupa-child-category-list" };
21437
21451
  const _sfc_main$V = /* @__PURE__ */ defineComponent({
21438
21452
  __name: "CategoryFilter",
21439
21453
  props: {
@@ -21541,7 +21555,7 @@ const _sfc_main$V = /* @__PURE__ */ defineComponent({
21541
21555
  onClick: handleNavigationParent
21542
21556
  }, toDisplayString(parentTitle.value), 11, _hoisted_4$k)
21543
21557
  ], 2),
21544
- createElementVNode("div", _hoisted_5$e, [
21558
+ createElementVNode("div", _hoisted_5$d, [
21545
21559
  (openBlock(true), createElementBlock(Fragment, null, renderList(categoryChildren.value, (child) => {
21546
21560
  return openBlock(), createBlock(_sfc_main$W, {
21547
21561
  key: getCategoryKey(child),
@@ -21561,15 +21575,14 @@ const _hoisted_1$O = {
21561
21575
  const _hoisted_2$A = ["placeholder"];
21562
21576
  const _hoisted_3$r = { class: "lupa-terms-list" };
21563
21577
  const _hoisted_4$j = ["onClick"];
21564
- const _hoisted_5$d = { class: "lupa-term-checkbox-wrapper" };
21565
- const _hoisted_6$8 = { class: "lupa-term-checkbox-label" };
21566
- const _hoisted_7$6 = { class: "lupa-term-label" };
21567
- const _hoisted_8$2 = {
21578
+ const _hoisted_5$c = { class: "lupa-term-checkbox-wrapper" };
21579
+ const _hoisted_6$8 = { class: "lupa-term-label" };
21580
+ const _hoisted_7$6 = {
21568
21581
  key: 0,
21569
21582
  class: "lupa-term-count"
21570
21583
  };
21571
- const _hoisted_9$2 = { key: 0 };
21572
- const _hoisted_10$1 = { key: 1 };
21584
+ const _hoisted_8$2 = { key: 0 };
21585
+ const _hoisted_9$2 = { key: 1 };
21573
21586
  const _sfc_main$U = /* @__PURE__ */ defineComponent({
21574
21587
  __name: "TermFacet",
21575
21588
  props: {
@@ -21601,7 +21614,12 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
21601
21614
  return searchResultStore.filterVisibleFilterValues(facet.value.key, (_b = (_a = facet.value) == null ? void 0 : _a.items) != null ? _b : []);
21602
21615
  });
21603
21616
  const displayValues = computed(() => {
21604
- return filteredValues.value.slice(0, itemLimit.value).map((v) => __spreadProps(__spreadValues({}, v), { title: getDisplayValue(v.title) }));
21617
+ return filteredValues.value.slice(0, itemLimit.value).filter(
21618
+ (v) => {
21619
+ var _a, _b, _c;
21620
+ return ((_a = props.options.excludeValues) == null ? void 0 : _a[facet.value.key]) ? !((_c = (_b = props.options.excludeValues) == null ? void 0 : _b[facet.value.key]) == null ? void 0 : _c[v.title]) : true;
21621
+ }
21622
+ ).map((v) => __spreadProps(__spreadValues({}, v), { title: getDisplayValue(v.title) }));
21605
21623
  });
21606
21624
  const filteredValues = computed(() => {
21607
21625
  var _a, _b;
@@ -21646,6 +21664,13 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
21646
21664
  var _a;
21647
21665
  return getTranslatedFacetValue(props.facet, item, (_a = searchResultOptions.value.filters) == null ? void 0 : _a.translations);
21648
21666
  };
21667
+ const getFacetValueClass = (item) => {
21668
+ try {
21669
+ return `lupa-facet-value-${slugifyClass(item.title)}`;
21670
+ } catch (e2) {
21671
+ return "";
21672
+ }
21673
+ };
21649
21674
  return (_ctx, _cache) => {
21650
21675
  return openBlock(), createElementBlock("div", _hoisted_1$O, [
21651
21676
  isFilterable.value ? withDirectives((openBlock(), createElementBlock("input", {
@@ -21665,15 +21690,17 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
21665
21690
  key: item.title,
21666
21691
  onClick: ($event) => handleFacetClick(item)
21667
21692
  }, [
21668
- createElementVNode("div", _hoisted_5$d, [
21693
+ createElementVNode("div", _hoisted_5$c, [
21669
21694
  createElementVNode("span", {
21670
21695
  class: normalizeClass(["lupa-term-checkbox", { checked: isChecked(item) }])
21671
21696
  }, null, 2)
21672
21697
  ]),
21673
- createElementVNode("div", _hoisted_6$8, [
21674
- createElementVNode("span", _hoisted_7$6, toDisplayString(getItemLabel(item)), 1),
21675
- _ctx.options.showDocumentCount ? (openBlock(), createElementBlock("span", _hoisted_8$2, "(" + toDisplayString(item.count) + ")", 1)) : createCommentVNode("", true)
21676
- ])
21698
+ createElementVNode("div", {
21699
+ class: normalizeClass(["lupa-term-checkbox-label", { [getFacetValueClass(item)]: true }])
21700
+ }, [
21701
+ createElementVNode("span", _hoisted_6$8, toDisplayString(getItemLabel(item)), 1),
21702
+ _ctx.options.showDocumentCount ? (openBlock(), createElementBlock("span", _hoisted_7$6, "(" + toDisplayString(item.count) + ")", 1)) : createCommentVNode("", true)
21703
+ ], 2)
21677
21704
  ], 10, _hoisted_4$j);
21678
21705
  }), 128))
21679
21706
  ]),
@@ -21683,7 +21710,7 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
21683
21710
  "data-cy": "lupa-facet-term",
21684
21711
  onClick: toggleShowAll
21685
21712
  }, [
21686
- showAll.value ? (openBlock(), createElementBlock("span", _hoisted_9$2, toDisplayString(_ctx.options.labels.showLess), 1)) : (openBlock(), createElementBlock("span", _hoisted_10$1, toDisplayString(_ctx.options.labels.showAll), 1))
21713
+ showAll.value ? (openBlock(), createElementBlock("span", _hoisted_8$2, toDisplayString(_ctx.options.labels.showLess), 1)) : (openBlock(), createElementBlock("span", _hoisted_9$2, toDisplayString(_ctx.options.labels.showAll), 1))
21687
21714
  ])) : createCommentVNode("", true)
21688
21715
  ]);
21689
21716
  };
@@ -22678,7 +22705,7 @@ const _hoisted_4$i = {
22678
22705
  key: 0,
22679
22706
  class: "lupa-stats-range-label"
22680
22707
  };
22681
- const _hoisted_5$c = { class: "lupa-stats-from" };
22708
+ const _hoisted_5$b = { class: "lupa-stats-from" };
22682
22709
  const _hoisted_6$7 = ["max", "min", "pattern", "aria-label"];
22683
22710
  const _hoisted_7$5 = { key: 0 };
22684
22711
  const _hoisted_8$1 = /* @__PURE__ */ createElementVNode("div", { class: "lupa-stats-separator" }, null, -1);
@@ -22878,7 +22905,7 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
22878
22905
  !isInputVisible.value ? (openBlock(), createElementBlock("div", _hoisted_2$z, toDisplayString(statsSummary.value), 1)) : (openBlock(), createElementBlock("div", _hoisted_3$q, [
22879
22906
  createElementVNode("div", null, [
22880
22907
  rangeLabelFrom.value ? (openBlock(), createElementBlock("div", _hoisted_4$i, toDisplayString(rangeLabelFrom.value), 1)) : createCommentVNode("", true),
22881
- createElementVNode("div", _hoisted_5$c, [
22908
+ createElementVNode("div", _hoisted_5$b, [
22882
22909
  withDirectives(createElementVNode("input", {
22883
22910
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => fromValue.value = $event),
22884
22911
  type: "text",
@@ -22942,13 +22969,12 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
22942
22969
  }
22943
22970
  });
22944
22971
  const _hoisted_1$M = { class: "lupa-term-checkbox-wrapper" };
22945
- const _hoisted_2$y = { class: "lupa-term-checkbox-label" };
22946
- const _hoisted_3$p = { class: "lupa-term-label" };
22947
- const _hoisted_4$h = {
22972
+ const _hoisted_2$y = { class: "lupa-term-label" };
22973
+ const _hoisted_3$p = {
22948
22974
  key: 0,
22949
22975
  class: "lupa-term-count"
22950
22976
  };
22951
- const _hoisted_5$b = {
22977
+ const _hoisted_4$h = {
22952
22978
  key: 0,
22953
22979
  class: "lupa-facet-level"
22954
22980
  };
@@ -22988,6 +23014,13 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
22988
23014
  value: item.key
22989
23015
  });
22990
23016
  };
23017
+ const getFacetValueClass = (item) => {
23018
+ try {
23019
+ return `lupa-facet-value-${slugifyClass(item.title)}`;
23020
+ } catch (e2) {
23021
+ return "";
23022
+ }
23023
+ };
22991
23024
  return (_ctx, _cache) => {
22992
23025
  const _component_HierarchyFacetLevel = resolveComponent("HierarchyFacetLevel", true);
22993
23026
  return openBlock(), createElementBlock("div", {
@@ -23003,12 +23036,14 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
23003
23036
  class: normalizeClass(["lupa-term-checkbox", { checked: isChecked.value }])
23004
23037
  }, null, 2)
23005
23038
  ]),
23006
- createElementVNode("div", _hoisted_2$y, [
23007
- createElementVNode("span", _hoisted_3$p, toDisplayString(_ctx.item.title) + toDisplayString(" "), 1),
23008
- _ctx.options.showDocumentCount ? (openBlock(), createElementBlock("span", _hoisted_4$h, "(" + toDisplayString(_ctx.item.count) + ")", 1)) : createCommentVNode("", true)
23009
- ])
23039
+ createElementVNode("div", {
23040
+ class: normalizeClass(["lupa-term-checkbox-label", { [getFacetValueClass(_ctx.item)]: true }])
23041
+ }, [
23042
+ createElementVNode("span", _hoisted_2$y, toDisplayString(_ctx.item.title) + toDisplayString(" "), 1),
23043
+ _ctx.options.showDocumentCount ? (openBlock(), createElementBlock("span", _hoisted_3$p, "(" + toDisplayString(_ctx.item.count) + ")", 1)) : createCommentVNode("", true)
23044
+ ], 2)
23010
23045
  ]),
23011
- showChildren.value ? (openBlock(), createElementBlock("div", _hoisted_5$b, [
23046
+ showChildren.value ? (openBlock(), createElementBlock("div", _hoisted_4$h, [
23012
23047
  (openBlock(true), createElementBlock(Fragment, null, renderList(treeItem.value.children, (itemChild) => {
23013
23048
  return openBlock(), createBlock(_component_HierarchyFacetLevel, {
23014
23049
  key: itemChild.title,