@nosto/search-js 3.25.4 → 3.25.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/AutocompletePageProvider-D48n1GB-.js +37 -0
  2. package/dist/AutocompletePageProvider-DzjwKsBp.cjs +1 -0
  3. package/dist/BaseElement-BnP6tQrH.cjs +1 -0
  4. package/dist/BaseElement-C25wjvSR.js +19 -0
  5. package/dist/CategoryPageProvider-B6w4FHhB.cjs +1 -0
  6. package/dist/CategoryPageProvider-BYw7KGoS.js +30 -0
  7. package/dist/ErrorBoundary-BtAe8lXu.cjs +1 -0
  8. package/dist/ErrorBoundary-Bxyssvki.js +11 -0
  9. package/dist/InfiniteScrollWithObserver-8imjYGGz.js +226 -0
  10. package/dist/InfiniteScrollWithObserver-k7oYk4f9.cjs +1 -0
  11. package/dist/SerpPageProvider-BgRZJNth.cjs +1 -0
  12. package/dist/SerpPageProvider-fg14kNV9.js +30 -0
  13. package/dist/baseConfig-Che6Adb6.js +50 -0
  14. package/dist/baseConfig-jLd7jchq.cjs +1 -0
  15. package/dist/cl-CYT5y6Dn.cjs +1 -0
  16. package/dist/cl-G5KK1qHD.js +6 -0
  17. package/dist/core/core.cjs.js +1 -1
  18. package/dist/core/core.es.js +8 -8
  19. package/dist/currencies/currencies.cjs.js +1 -1
  20. package/dist/currencies/currencies.es.js +61 -65
  21. package/dist/disableNativeAutocomplete-CcR_Ek_P.js +26 -0
  22. package/dist/disableNativeAutocomplete-CjBGhRWW.cjs +1 -0
  23. package/dist/eventBusDispatch-B6VswTu8.cjs +1 -0
  24. package/dist/eventBusDispatch-DnFmEqYe.js +15 -0
  25. package/dist/eventBusSubscribe-C6qT1aOO.js +22 -0
  26. package/dist/eventBusSubscribe-c9a_PP0j.cjs +1 -0
  27. package/dist/index.es-Ba4tuzxb.cjs +1 -0
  28. package/dist/index.es-jSYcbRvi.js +25 -0
  29. package/dist/{isBot-B05pQGIe.js → isBot-CPesLwHL.js} +18 -17
  30. package/dist/isBot-CkyQfegP.cjs +1 -0
  31. package/dist/jsxRuntime.module-BRdvPAre.js +30 -0
  32. package/dist/jsxRuntime.module-Ba9fccPy.cjs +1 -0
  33. package/dist/parseNumber-BH_92pM8.cjs +1 -0
  34. package/dist/parseNumber-DFsrGj64.js +9 -0
  35. package/dist/pick-0KNFTqKn.cjs +1 -0
  36. package/dist/pick-B8ymxJme.js +6 -0
  37. package/dist/preact/autocomplete/autocomplete.cjs.js +1 -1
  38. package/dist/preact/autocomplete/autocomplete.es.js +49 -42
  39. package/dist/preact/category/category.cjs.js +1 -1
  40. package/dist/preact/category/category.es.js +9 -4
  41. package/dist/preact/common/common.cjs.js +1 -1
  42. package/dist/preact/common/common.es.js +27 -31
  43. package/dist/preact/events/events.cjs.js +1 -1
  44. package/dist/preact/events/events.es.js +3 -8
  45. package/dist/preact/hooks/hooks.cjs.js +1 -1
  46. package/dist/preact/hooks/hooks.es.js +495 -508
  47. package/dist/preact/inject/inject.cjs.js +1 -1
  48. package/dist/preact/inject/inject.es.js +318 -301
  49. package/dist/preact/legacy/legacy.cjs.js +1 -1
  50. package/dist/preact/legacy/legacy.es.js +8 -10
  51. package/dist/preact/serp/serp.cjs.js +1 -1
  52. package/dist/preact/serp/serp.es.js +28 -18
  53. package/dist/search-BeFE0Ezr.cjs +1 -0
  54. package/dist/search-C2WGFf4C.js +155 -0
  55. package/dist/storage-B3FIcJQv.cjs +1 -0
  56. package/dist/storage-DeAo7M3s.js +115 -0
  57. package/dist/thumbnails/thumbnails.cjs.js +1 -1
  58. package/dist/thumbnails/thumbnails.es.js +93 -97
  59. package/dist/unique-BXFI_-3F.cjs +1 -0
  60. package/dist/unique-DSDxyj90.js +37 -0
  61. package/dist/useActions-BmWNZAES.js +182 -0
  62. package/dist/useActions-boQy-Vp0.cjs +1 -0
  63. package/dist/useHistory-BMkSr69f.js +24 -0
  64. package/dist/useHistory-GRnuHgQ5.cjs +1 -0
  65. package/dist/useLoadMore-B9LiuhfV.cjs +1 -0
  66. package/dist/useLoadMore-BkJV7F21.js +38 -0
  67. package/dist/utils/utils.cjs.js +1 -1
  68. package/dist/utils/utils.es.js +9 -28
  69. package/package.json +5 -5
  70. package/dist/AutocompletePageProvider-CFEbt11-.cjs +0 -1
  71. package/dist/AutocompletePageProvider-CQePqAhB.js +0 -35
  72. package/dist/BaseElement-CIHACCWd.cjs +0 -1
  73. package/dist/BaseElement-DD_4UwDm.js +0 -24
  74. package/dist/CategoryPageProvider-037sXEh9.cjs +0 -1
  75. package/dist/CategoryPageProvider-DVL9lsCU.js +0 -26
  76. package/dist/ErrorBoundary-DFs5vnv-.js +0 -11
  77. package/dist/ErrorBoundary-DNPL7EwP.cjs +0 -1
  78. package/dist/InfiniteScrollWithObserver-BliG4dEl.cjs +0 -1
  79. package/dist/InfiniteScrollWithObserver-DvkEUZUE.js +0 -205
  80. package/dist/SerpPageProvider-BzrNPc7g.js +0 -26
  81. package/dist/SerpPageProvider-CxqiX9Zo.cjs +0 -1
  82. package/dist/baseConfig-BOOw0mWW.cjs +0 -1
  83. package/dist/baseConfig-Cf28X268.js +0 -48
  84. package/dist/cl-B00bZ7jc.cjs +0 -1
  85. package/dist/cl-CcykAxZN.js +0 -6
  86. package/dist/disableNativeAutocomplete-Bkta_WR2.js +0 -27
  87. package/dist/disableNativeAutocomplete-DI6zaZII.cjs +0 -1
  88. package/dist/eventBusDispatch-BKQcSHAB.cjs +0 -1
  89. package/dist/eventBusDispatch-DPR2Vwd4.js +0 -20
  90. package/dist/eventBusSubscribe-B5E7dTzk.js +0 -26
  91. package/dist/eventBusSubscribe-C4H9Nv1Z.cjs +0 -1
  92. package/dist/index.es-Dp6Iaxz3.cjs +0 -1
  93. package/dist/index.es-XNBESE3P.js +0 -26
  94. package/dist/isBot-C-qPIZyF.cjs +0 -1
  95. package/dist/jsxRuntime.module-B3sGoTIU.cjs +0 -1
  96. package/dist/jsxRuntime.module-Bzuv3cXw.js +0 -13
  97. package/dist/parseNumber-FsZ8w61u.cjs +0 -1
  98. package/dist/parseNumber-QA48nJLp.js +0 -11
  99. package/dist/pick-DReBictn.js +0 -9
  100. package/dist/pick-rYi1lc2m.cjs +0 -1
  101. package/dist/search-BchLEATK.cjs +0 -1
  102. package/dist/search-D1jQPG6P.js +0 -156
  103. package/dist/storage-9KuhFI9v.cjs +0 -1
  104. package/dist/storage-B97DRj5i.js +0 -121
  105. package/dist/unique-C1G3v2Y8.cjs +0 -1
  106. package/dist/unique-CCu7ChUL.js +0 -39
  107. package/dist/useActions-BD6dgsX8.js +0 -260
  108. package/dist/useActions-DIlSparF.cjs +0 -1
  109. package/dist/useHistory-DLCyHMo1.cjs +0 -1
  110. package/dist/useHistory-sjFYeR68.js +0 -27
  111. package/dist/useLoadMore-BMOT8Dfn.js +0 -33
  112. package/dist/useLoadMore-vCpwy6JC.cjs +0 -1
@@ -1,539 +1,526 @@
1
- import { h as A } from "../../useActions-BD6dgsX8.js";
2
- import { b as X } from "../../storage-B97DRj5i.js";
3
- import { a as S } from "../../useLoadMore-BMOT8Dfn.js";
4
- import { u as Le } from "../../useLoadMore-BMOT8Dfn.js";
5
- import { u as P } from "../../eventBusSubscribe-B5E7dTzk.js";
6
- import { useState as b, useCallback as p, useMemo as y, useEffect as k, useRef as z } from "preact/hooks";
7
- import { a as Me, g as Te, u as Ne } from "../../useHistory-sjFYeR68.js";
8
- import { s as C } from "../../index.es-XNBESE3P.js";
9
- import { d as O } from "../../eventBusDispatch-DPR2Vwd4.js";
10
- import { p as R } from "../../parseNumber-QA48nJLp.js";
11
- function le(e) {
12
- const n = S((t) => t.response);
13
- return e && Array.isArray(e) || e && X(e) ? e : n;
1
+ import { r as e } from "../../index.es-jSYcbRvi.js";
2
+ import "../../search-C2WGFf4C.js";
3
+ import { l as t } from "../../storage-DeAo7M3s.js";
4
+ import { t as n } from "../../parseNumber-DFsrGj64.js";
5
+ import { t as r } from "../../useActions-BmWNZAES.js";
6
+ import { n as i } from "../../eventBusSubscribe-C6qT1aOO.js";
7
+ import { n as a, r as o, t as s } from "../../useHistory-BMkSr69f.js";
8
+ import { r as c, t as l } from "../../useLoadMore-BkJV7F21.js";
9
+ import { t as u } from "../../eventBusDispatch-DnFmEqYe.js";
10
+ import { useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "preact/hooks";
11
+ //#region packages/preact/hooks/src/useDecoratedSearchResults.ts
12
+ function g(e) {
13
+ let n = c((e) => e.response);
14
+ return e && Array.isArray(e) || e && t(e) ? e : n;
14
15
  }
15
- function de(e, n) {
16
- const t = e.data?.filter((d) => d.selected).length ?? 0, { active: o } = {
17
- active: t > 0,
18
- ...n
19
- }, [r, c] = b(o), { toggleProductFilter: i } = A(), u = p(() => {
20
- c(!r);
21
- }, [r]);
22
- return P({
23
- event: "events/removeAllFilters",
24
- callback: () => {
25
- c(!1);
26
- }
27
- }), {
28
- /** Active value */
29
- active: r,
30
- /** Selected filters count */
31
- selectedFiltersCount: t,
32
- /** Toggle active function */
33
- toggleActive: u,
34
- /** Toggle product filter function */
35
- toggleProductFilter: i
36
- };
16
+ //#endregion
17
+ //#region packages/preact/hooks/src/useFacet.ts
18
+ function _(e, t) {
19
+ let n = e.data?.filter((e) => e.selected).length ?? 0, { active: a } = {
20
+ active: n > 0,
21
+ ...t
22
+ }, [o, s] = h(a), { toggleProductFilter: c } = r(), l = d(() => {
23
+ s(!o);
24
+ }, [o]);
25
+ return i({
26
+ event: "events/removeAllFilters",
27
+ callback: () => {
28
+ s(!1);
29
+ }
30
+ }), {
31
+ active: o,
32
+ selectedFiltersCount: n,
33
+ toggleActive: l,
34
+ toggleProductFilter: c
35
+ };
37
36
  }
38
- function fe() {
39
- const { loading: e, facets: n } = S((t) => ({
40
- loading: t.loading,
41
- facets: t.response?.products?.facets ?? []
42
- }));
43
- return {
44
- /** Loading state */
45
- loading: e,
46
- /** Array of facets*/
47
- facets: n
48
- };
37
+ //#endregion
38
+ //#region packages/preact/hooks/src/useFacets.ts
39
+ function v() {
40
+ let { loading: e, facets: t } = c((e) => ({
41
+ loading: e.loading,
42
+ facets: e.response?.products?.facets ?? []
43
+ }));
44
+ return {
45
+ loading: e,
46
+ facets: t
47
+ };
49
48
  }
50
- function j(e, n) {
51
- const t = n - e;
52
- return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((o, r) => r + e) : [];
49
+ //#endregion
50
+ //#region packages/utils/src/range.ts
51
+ function y(e, t) {
52
+ let n = t - e;
53
+ return !isNaN(n) && n > 0 ? Array(t - e).fill(void 0).map((t, n) => n + e) : [];
53
54
  }
54
- function pe(e) {
55
- const { query: n, products: t } = S((o) => ({
56
- query: o.query,
57
- products: o.response.products
58
- }));
59
- return y(() => {
60
- if (!t)
61
- return {
62
- totalPages: 0,
63
- resultsFrom: 0,
64
- resultsTo: 0,
65
- pages: []
66
- };
67
- const o = n.products?.from ?? 0, r = e?.width ?? 1 / 0, c = Math.max(Math.floor(r - 1) / 2, 1), i = t.size > 0 ? Math.floor(o / t.size) + 1 : 1, u = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (w) => w >= i - c && w <= i + c, s = o + 1, a = Math.min(o + t.total, t.total), l = {
68
- from: o,
69
- page: i,
70
- current: !0
71
- }, f = (w) => ({
72
- from: (w - 1) * t.size,
73
- page: w,
74
- current: w === i
75
- }), h = i > 1 ? f(i - 1) : void 0, v = i < u ? f(i + 1) : void 0, m = i - c - 1 > 1 ? f(1) : void 0, g = i + c + 1 < u ? f(u) : void 0, F = j(1, u + 1).filter(d).map(f);
76
- return !m && F[0]?.page === 2 && F.unshift(f(1)), !g && F[F.length - 1]?.page === u - 1 && F.push(f(u)), {
77
- totalPages: u,
78
- resultsFrom: s,
79
- resultsTo: a,
80
- current: l,
81
- prev: h,
82
- next: v,
83
- first: m,
84
- last: g,
85
- pages: F
86
- };
87
- }, [n, t, e?.width]);
55
+ //#endregion
56
+ //#region packages/preact/hooks/src/usePagination.ts
57
+ function b(e) {
58
+ let { query: t, products: n } = c((e) => ({
59
+ query: e.query,
60
+ products: e.response.products
61
+ }));
62
+ return p(() => {
63
+ if (!n) return {
64
+ totalPages: 0,
65
+ resultsFrom: 0,
66
+ resultsTo: 0,
67
+ pages: []
68
+ };
69
+ let r = t.products?.from ?? 0, i = e?.width ?? Infinity, a = Math.max(Math.floor(i - 1) / 2, 1), o = n.size > 0 ? Math.floor(r / n.size) + 1 : 1, s = n.size > 0 ? Math.ceil(n.total / n.size) : 0, c = (e) => e >= o - a && e <= o + a, l = r + 1, u = Math.min(r + n.total, n.total), d = {
70
+ from: r,
71
+ page: o,
72
+ current: !0
73
+ }, f = (e) => ({
74
+ from: (e - 1) * n.size,
75
+ page: e,
76
+ current: e === o
77
+ }), p = o > 1 ? f(o - 1) : void 0, m = o < s ? f(o + 1) : void 0, h = o - a - 1 > 1 ? f(1) : void 0, g = o + a + 1 < s ? f(s) : void 0, _ = y(1, s + 1).filter(c).map(f);
78
+ return !h && _[0]?.page === 2 && _.unshift(f(1)), !g && _[_.length - 1]?.page === s - 1 && _.push(f(s)), {
79
+ totalPages: s,
80
+ resultsFrom: l,
81
+ resultsTo: u,
82
+ current: d,
83
+ prev: p,
84
+ next: m,
85
+ first: h,
86
+ last: g,
87
+ pages: _
88
+ };
89
+ }, [
90
+ t,
91
+ n,
92
+ e?.width
93
+ ]);
88
94
  }
89
- function ge() {
90
- const [e, n] = b([]), [t, o] = b([]);
91
- return k(() => {
92
- C(async (r) => {
93
- const { products: c, segments: i } = await r.getSearchSessionParams();
94
- n(i ?? []), o(c?.personalizationBoost ?? []);
95
- });
96
- }, []), {
97
- segments: e,
98
- boost: t
99
- };
95
+ //#endregion
96
+ //#region packages/preact/hooks/src/usePersonalization.ts
97
+ function x() {
98
+ let [t, n] = h([]), [r, i] = h([]);
99
+ return f(() => {
100
+ e(async (e) => {
101
+ let { products: t, segments: r } = await e.getSearchSessionParams();
102
+ n(r ?? []), i(t?.personalizationBoost ?? []);
103
+ });
104
+ }, []), {
105
+ segments: t,
106
+ boost: r
107
+ };
100
108
  }
101
- function q() {
102
- const { facets: e } = S((s) => ({
103
- facets: s.response.products?.facets ?? []
104
- })), { replaceFilter: n, toggleProductFilter: t } = A(), o = p(
105
- (s) => {
106
- const a = e?.find((l) => l.type === "stats" && l.field === s);
107
- if (a && "min" in a && "max" in a)
108
- return a;
109
- },
110
- [e]
111
- ), r = p(
112
- (s) => e?.find((a) => a.field === s)?.name ?? s,
113
- [e]
114
- ), c = p((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), i = p((s) => ({
115
- ...s,
116
- range: s.range?.map((a) => ({
117
- gt: a.gt ? Number(a.gt) : a.gt,
118
- gte: a.gte ? Number(a.gte) : a.gte,
119
- lt: a.lt ? Number(a.lt) : a.lt,
120
- lte: a.lte ? Number(a.lte) : a.lte
121
- }))
122
- }), []), u = p(
123
- (s) => (s.value ?? []).map((l) => ({
124
- value: l,
125
- field: s.field,
126
- name: r(s.field),
127
- filter: i(s),
128
- remove: () => {
129
- t(s.field, l, !1);
130
- }
131
- })),
132
- [i, r, t]
133
- ), d = p(
134
- (s) => (s.range ?? []).map((l) => {
135
- const f = l.gte ?? l.gt ?? o(s.field)?.min, h = l.lte ?? l.lt ?? o(s.field)?.max;
136
- if (f !== void 0 && h !== void 0)
137
- return {
138
- value: `${f} - ${h}`,
139
- field: s.field,
140
- name: r(s.field),
141
- filter: i(s),
142
- remove: () => {
143
- n(s.field, void 0);
144
- }
145
- };
146
- }).filter(Boolean),
147
- [i, o, r, n]
148
- );
149
- return {
150
- selectFilters: c,
151
- toValueFilter: u,
152
- toRangeFilter: d
153
- };
109
+ //#endregion
110
+ //#region packages/preact/hooks/src/useProductFilters/useProductFiltersUtils.ts
111
+ function S() {
112
+ let { facets: e } = c((e) => ({ facets: e.response.products?.facets ?? [] })), { replaceFilter: t, toggleProductFilter: n } = r(), i = d((t) => {
113
+ let n = e?.find((e) => e.type === "stats" && e.field === t);
114
+ if (n && "min" in n && "max" in n) return n;
115
+ }, [e]), a = d((t) => e?.find((e) => e.field === t)?.name ?? t, [e]), o = d((e) => "field" in e && (e.value instanceof Array || e.range instanceof Array), []), s = d((e) => ({
116
+ ...e,
117
+ range: e.range?.map((e) => ({
118
+ gt: e.gt ? Number(e.gt) : e.gt,
119
+ gte: e.gte ? Number(e.gte) : e.gte,
120
+ lt: e.lt ? Number(e.lt) : e.lt,
121
+ lte: e.lte ? Number(e.lte) : e.lte
122
+ }))
123
+ }), []);
124
+ return {
125
+ selectFilters: o,
126
+ toValueFilter: d((e) => (e.value ?? []).map((t) => ({
127
+ value: t,
128
+ field: e.field,
129
+ name: a(e.field),
130
+ filter: s(e),
131
+ remove: () => {
132
+ n(e.field, t, !1);
133
+ }
134
+ })), [
135
+ s,
136
+ a,
137
+ n
138
+ ]),
139
+ toRangeFilter: d((e) => (e.range ?? []).map((n) => {
140
+ let r = n.gte ?? n.gt ?? i(e.field)?.min, o = n.lte ?? n.lt ?? i(e.field)?.max;
141
+ if (r !== void 0 && o !== void 0) return {
142
+ value: `${r} - ${o}`,
143
+ field: e.field,
144
+ name: a(e.field),
145
+ filter: s(e),
146
+ remove: () => {
147
+ t(e.field, void 0);
148
+ }
149
+ };
150
+ }).filter(Boolean), [
151
+ s,
152
+ i,
153
+ a,
154
+ t
155
+ ])
156
+ };
154
157
  }
155
- function E() {
156
- const { filter: e } = S((u) => ({
157
- filter: u.query.products?.filter ?? []
158
- })), { updateSearch: n } = A(), { selectFilters: t, toValueFilter: o, toRangeFilter: r } = q(), c = y(() => e ? e.filter(t).flatMap((u) => "value" in u ? o(u) : "range" in u ? r(u) : []).filter(Boolean) : [], [e, t, r, o]), i = p(() => {
159
- n({
160
- products: {
161
- filter: []
162
- }
163
- }), O({
164
- event: "events/removeAllFilters",
165
- params: null
166
- });
167
- }, [n]);
168
- return {
169
- /** Selected filters array. */
170
- filters: c,
171
- /** Should remove all selected filters. */
172
- removeAll: i
173
- };
158
+ //#endregion
159
+ //#region packages/preact/hooks/src/useProductFilters/useProductFilters.tsx
160
+ function C() {
161
+ let { filter: e } = c((e) => ({ filter: e.query.products?.filter ?? [] })), { updateSearch: t } = r(), { selectFilters: n, toValueFilter: i, toRangeFilter: a } = S();
162
+ return {
163
+ filters: p(() => e ? e.filter(n).flatMap((e) => "value" in e ? i(e) : "range" in e ? a(e) : []).filter(Boolean) : [], [
164
+ e,
165
+ n,
166
+ a,
167
+ i
168
+ ]),
169
+ removeAll: d(() => {
170
+ t({ products: { filter: [] } }), u({
171
+ event: "events/removeAllFilters",
172
+ params: null
173
+ });
174
+ }, [t])
175
+ };
174
176
  }
175
- function V(e) {
176
- const { replaceFilter: n } = A(), { query: t, products: o } = S((g) => ({
177
- query: g.query,
178
- products: g.response.products
179
- })), r = o?.facets?.find((g) => g.id === e), c = t.products?.filter?.find((g) => g.field === r?.field), [i, u] = U(c), d = r && "min" in r ? Math.floor(r.min ?? 0) : 0, s = r && "max" in r ? Math.ceil(r.max ?? 0) : 0, a = y(() => [i ?? d, u ?? s], [i, u, d, s]), l = i !== void 0 || u !== void 0, [f, h] = b(l), v = p(() => {
180
- h((g) => !g);
181
- }, []), m = p(
182
- ([g, F]) => {
183
- if (!r)
184
- return;
185
- const w = B(g, F, d, s);
186
- n(r.field, w);
187
- },
188
- [d, s, n, r]
189
- );
190
- return P({
191
- event: "events/removeAllFilters",
192
- callback: () => {
193
- h(!1);
194
- }
195
- }), r ? {
196
- /** Min value */
197
- min: d,
198
- /** Max value */
199
- max: s,
200
- /** Range value */
201
- range: a,
202
- /** Update range function */
203
- updateRange: m,
204
- /** Is the range filter active */
205
- active: f,
206
- /** Toggle active state function */
207
- toggleActive: v
208
- } : $;
177
+ //#endregion
178
+ //#region packages/preact/hooks/src/useRange.ts
179
+ function w(e) {
180
+ let { replaceFilter: t } = r(), { query: n, products: a } = c((e) => ({
181
+ query: e.query,
182
+ products: e.response.products
183
+ })), o = a?.facets?.find((t) => t.id === e), s = n.products?.filter?.find((e) => e.field === o?.field), [l, u] = E(s), f = o && "min" in o ? Math.floor(o.min ?? 0) : 0, m = o && "max" in o ? Math.ceil(o.max ?? 0) : 0, g = p(() => [l ?? f, u ?? m], [
184
+ l,
185
+ u,
186
+ f,
187
+ m
188
+ ]), [_, v] = h(l !== void 0 || u !== void 0), y = d(() => {
189
+ v((e) => !e);
190
+ }, []), b = d(([e, n]) => {
191
+ if (!o) return;
192
+ let r = D(e, n, f, m);
193
+ t(o.field, r);
194
+ }, [
195
+ f,
196
+ m,
197
+ t,
198
+ o
199
+ ]);
200
+ return i({
201
+ event: "events/removeAllFilters",
202
+ callback: () => {
203
+ v(!1);
204
+ }
205
+ }), o ? {
206
+ min: f,
207
+ max: m,
208
+ range: g,
209
+ updateRange: b,
210
+ active: _,
211
+ toggleActive: y
212
+ } : T;
209
213
  }
210
- const $ = {
211
- min: 0,
212
- max: 0,
213
- range: [0, 0],
214
- active: !1,
215
- toggleActive: () => {
216
- },
217
- updateRange: () => {
218
- }
214
+ var T = {
215
+ min: 0,
216
+ max: 0,
217
+ range: [0, 0],
218
+ active: !1,
219
+ toggleActive: () => {},
220
+ updateRange: () => {}
219
221
  };
220
- function U(e) {
221
- const n = e?.range?.[0];
222
- return typeof n == "object" && ("gte" in n || "lte" in n) ? [R(n.gte), R(n.lte)] : [void 0, void 0];
222
+ function E(e) {
223
+ let t = e?.range?.[0];
224
+ return typeof t == "object" && ("gte" in t || "lte" in t) ? [n(t.gte), n(t.lte)] : [void 0, void 0];
223
225
  }
224
- function B(e, n, t, o) {
225
- const r = e !== void 0 ? Math.floor(e) : void 0, c = n !== void 0 ? Math.ceil(n) : void 0, i = r !== void 0, u = c !== void 0;
226
- if ((t === r || !i) && (o === c || !u))
227
- return;
228
- const d = {};
229
- return i && r !== t && (d.gte = r.toString()), u && c !== o && (d.lte = c.toString()), Object.keys(d).length > 0 ? d : void 0;
226
+ function D(e, t, n, r) {
227
+ let i = e === void 0 ? void 0 : Math.floor(e), a = t === void 0 ? void 0 : Math.ceil(t), o = i !== void 0, s = a !== void 0;
228
+ if ((n === i || !o) && (r === a || !s)) return;
229
+ let c = {};
230
+ return o && i !== n && (c.gte = i.toString()), s && a !== r && (c.lte = a.toString()), Object.keys(c).length > 0 ? c : void 0;
230
231
  }
231
- function me(e, n) {
232
- const { min: t, max: o, range: r, updateRange: c } = V(e), { filters: i } = E(), u = y(() => {
233
- const l = i.find((m) => m?.filter?.range);
234
- let f = null;
235
- if (l) {
236
- const m = l.filter.range?.[0];
237
- f = [R(m?.gte), R(m?.lte)];
238
- }
239
- const h = [];
240
- let v = Math.floor(t / n) * n;
241
- for (; v < o; ) {
242
- const m = v + n, g = f && f[0] === v && f[1] === m;
243
- h.push({
244
- min: v,
245
- max: m,
246
- selected: g
247
- }), v = m;
248
- }
249
- return h;
250
- }, [i, t, o, n]), d = p(
251
- (l) => {
252
- c([l, r[1]]);
253
- },
254
- [r, c]
255
- ), s = p(
256
- (l) => {
257
- c([r[0], l]);
258
- },
259
- [r, c]
260
- ), a = t !== r[0] || o !== r[1];
261
- return {
262
- /** Minimum value */
263
- min: t,
264
- /** Maximum value */
265
- max: o,
266
- /** Range value */
267
- range: r,
268
- /** Update range function */
269
- updateRange: c,
270
- /** Ranges */
271
- ranges: u,
272
- /** Handle min change */
273
- handleMinChange: d,
274
- /** Handle max change */
275
- handleMaxChange: s,
276
- /** Is selected */
277
- isSelected: a
278
- };
232
+ //#endregion
233
+ //#region packages/preact/hooks/src/useRangeSelector.ts
234
+ function O(e, t) {
235
+ let { min: r, max: i, range: a, updateRange: o } = w(e), { filters: s } = C();
236
+ return {
237
+ min: r,
238
+ max: i,
239
+ range: a,
240
+ updateRange: o,
241
+ ranges: p(() => {
242
+ let e = s.find((e) => e?.filter?.range), a = null;
243
+ if (e) {
244
+ let t = e.filter.range?.[0];
245
+ a = [n(t?.gte), n(t?.lte)];
246
+ }
247
+ let o = [], c = Math.floor(r / t) * t;
248
+ for (; c < i;) {
249
+ let e = c + t, n = a && a[0] === c && a[1] === e;
250
+ o.push({
251
+ min: c,
252
+ max: e,
253
+ selected: n
254
+ }), c = e;
255
+ }
256
+ return o;
257
+ }, [
258
+ s,
259
+ r,
260
+ i,
261
+ t
262
+ ]),
263
+ handleMinChange: d((e) => {
264
+ o([e, a[1]]);
265
+ }, [a, o]),
266
+ handleMaxChange: d((e) => {
267
+ o([a[0], e]);
268
+ }, [a, o]),
269
+ isSelected: r !== a[0] || i !== a[1]
270
+ };
279
271
  }
280
- function he() {
281
- const { products: e, keywords: n, popularSearches: t, categories: o } = S((r) => ({
282
- products: r.response.products ?? L,
283
- keywords: r.response.keywords ?? L,
284
- popularSearches: r.response.popularSearches ?? L,
285
- categories: r.response.categories ?? L
286
- }));
287
- return {
288
- /** Array of products */
289
- products: e,
290
- /** Array of keywords */
291
- keywords: n,
292
- /** Array of popular searches */
293
- popularSearches: t,
294
- /** Array of categories */
295
- categories: o
296
- };
272
+ //#endregion
273
+ //#region packages/preact/hooks/src/useResponse.ts
274
+ function k() {
275
+ let { products: e, keywords: t, popularSearches: n, categories: r } = c((e) => ({
276
+ products: e.response.products ?? A,
277
+ keywords: e.response.keywords ?? A,
278
+ popularSearches: e.response.popularSearches ?? A,
279
+ categories: e.response.categories ?? A
280
+ }));
281
+ return {
282
+ products: e,
283
+ keywords: t,
284
+ popularSearches: n,
285
+ categories: r
286
+ };
297
287
  }
298
- const L = { hits: [], total: 0 };
299
- function ve() {
300
- const e = S((t) => t.query.products?.filter);
301
- return y(() => e ? e.reduce((t, o) => t + (Array.isArray(o.value) ? o.value.length : 1), 0) : 0, [e]);
288
+ var A = {
289
+ hits: [],
290
+ total: 0
291
+ };
292
+ //#endregion
293
+ //#region packages/preact/hooks/src/useSelectedFiltersCount.ts
294
+ function j() {
295
+ let e = c((e) => e.query.products?.filter);
296
+ return p(() => e ? e.reduce((e, t) => e + (Array.isArray(t.value) ? t.value.length : 1), 0) : 0, [e]);
302
297
  }
303
- const D = 300 * 1e3, M = /* @__PURE__ */ new Map();
304
- function Se(e) {
305
- const [n, t] = b({
306
- product: null,
307
- loading: !0,
308
- error: null
309
- });
310
- return k(() => {
311
- if (!e) {
312
- t({
313
- product: null,
314
- loading: !1,
315
- error: "Product handle is required"
316
- });
317
- return;
318
- }
319
- t((r) => ({
320
- ...r,
321
- loading: !0,
322
- error: null
323
- }));
324
- const o = I(e);
325
- if (o) {
326
- t({
327
- product: o,
328
- loading: !1,
329
- error: null
330
- });
331
- return;
332
- }
333
- H(e).then((r) => {
334
- K(e, r), t({
335
- product: r,
336
- loading: !1,
337
- error: null
338
- });
339
- }).catch((r) => {
340
- t({
341
- product: null,
342
- loading: !1,
343
- error: r.message || "Failed to fetch product"
344
- });
345
- });
346
- }, [e]), n;
298
+ //#endregion
299
+ //#region packages/preact/hooks/src/useShopifyProduct/useShopifyProduct.ts
300
+ var M = 300 * 1e3, N = /* @__PURE__ */ new Map();
301
+ function P(e) {
302
+ let [t, n] = h({
303
+ product: null,
304
+ loading: !0,
305
+ error: null
306
+ });
307
+ return f(() => {
308
+ if (!e) {
309
+ n({
310
+ product: null,
311
+ loading: !1,
312
+ error: "Product handle is required"
313
+ });
314
+ return;
315
+ }
316
+ n((e) => ({
317
+ ...e,
318
+ loading: !0,
319
+ error: null
320
+ }));
321
+ let t = L(e);
322
+ if (t) {
323
+ n({
324
+ product: t,
325
+ loading: !1,
326
+ error: null
327
+ });
328
+ return;
329
+ }
330
+ I(e).then((t) => {
331
+ R(e, t), n({
332
+ product: t,
333
+ loading: !1,
334
+ error: null
335
+ });
336
+ }).catch((e) => {
337
+ n({
338
+ product: null,
339
+ loading: !1,
340
+ error: e.message || "Failed to fetch product"
341
+ });
342
+ });
343
+ }, [e]), t;
347
344
  }
348
- function _(e) {
349
- const n = window.Shopify?.routes?.root;
350
- return n ? new URL(`${n}products/${e}`, window.location.href) : e;
345
+ function F(e) {
346
+ let t = window.Shopify?.routes?.root;
347
+ return t ? new URL(`${t}products/${e}`, window.location.href) : e;
351
348
  }
352
- async function H(e) {
353
- const n = await fetch(_(`/products/${e}.js`));
354
- if (!n.ok)
355
- throw new Error(`Failed to fetch product: ${n.status} ${n.statusText}`);
356
- return n.json();
349
+ async function I(e) {
350
+ let t = await fetch(F(`/products/${e}.js`));
351
+ if (!t.ok) throw Error(`Failed to fetch product: ${t.status} ${t.statusText}`);
352
+ return t.json();
357
353
  }
358
- function I(e) {
359
- const n = M.get(e);
360
- return n ? Date.now() - n.created > D ? (M.delete(e), null) : n.product : null;
354
+ function L(e) {
355
+ let t = N.get(e);
356
+ return t ? Date.now() - t.created > M ? (N.delete(e), null) : t.product : null;
361
357
  }
362
- function K(e, n) {
363
- M.set(e, {
364
- product: n,
365
- created: Date.now()
366
- });
358
+ function R(e, t) {
359
+ N.set(e, {
360
+ product: t,
361
+ created: Date.now()
362
+ });
367
363
  }
368
- function x(e) {
369
- return e && !Number.isNaN(e) ? e : 0;
364
+ //#endregion
365
+ //#region packages/preact/hooks/src/useSizeOptions.ts
366
+ function z(e) {
367
+ return e && !Number.isNaN(e) ? e : 0;
370
368
  }
371
- function ye(e, n) {
372
- const { from: t, size: o, total: r } = S((s) => ({
373
- from: x(s.query.products?.from ?? 0),
374
- size: x(s.response?.products?.size ?? n),
375
- total: x(s.response?.products?.total ?? 0)
376
- })), { updateSearch: c } = A(), i = t + o, u = y(() => [...e].reverse().filter((s) => s < r), [e, r]), d = p(
377
- (s) => {
378
- c({
379
- products: {
380
- size: R(s)
381
- }
382
- });
383
- },
384
- [c]
385
- );
386
- return {
387
- /** from value */
388
- from: t,
389
- /** to value */
390
- to: i,
391
- /** total value */
392
- total: r,
393
- /** size value */
394
- size: o,
395
- /** Array of size options */
396
- sizeOptions: u,
397
- /** Should be called when size is changed */
398
- handleSizeChange: d
399
- };
369
+ function B(e, t) {
370
+ let { from: i, size: a, total: o } = c((e) => ({
371
+ from: z(e.query.products?.from ?? 0),
372
+ size: z(e.response?.products?.size ?? t),
373
+ total: z(e.response?.products?.total ?? 0)
374
+ })), { updateSearch: s } = r();
375
+ return {
376
+ from: i,
377
+ to: i + a,
378
+ total: o,
379
+ size: a,
380
+ sizeOptions: p(() => [...e].reverse().filter((e) => e < o), [e, o]),
381
+ handleSizeChange: d((e) => {
382
+ s({ products: { size: n(e) } });
383
+ }, [s])
384
+ };
400
385
  }
401
- function Z(e, n) {
402
- return e.length !== n.length ? !1 : e.every((t) => n.find((o) => t.field === o.field && t.order === o.order));
386
+ //#endregion
387
+ //#region packages/preact/hooks/src/useSort/utils.ts
388
+ function V(e, t) {
389
+ return e.length === t.length ? e.every((e) => t.find((t) => e.field === t.field && e.order === t.order)) : !1;
403
390
  }
404
- function Fe(e) {
405
- const n = S((c) => c.query), { updateSearch: t } = A(), o = e.find((c) => Z(c.value.sort, n.products?.sort || []))?.id ?? e[0]?.id, r = p(
406
- (c) => {
407
- if (c === o)
408
- return;
409
- const i = e.find((u) => u.id === c);
410
- i && t({
411
- products: {
412
- sort: i.value.sort
413
- }
414
- });
415
- },
416
- [e, t, o]
417
- );
418
- return {
419
- /** Active sort */
420
- activeSort: o,
421
- /** Set sort function */
422
- setSort: r
423
- };
391
+ //#endregion
392
+ //#region packages/preact/hooks/src/useSort/useSort.ts
393
+ function H(e) {
394
+ let t = c((e) => e.query), { updateSearch: n } = r(), i = e.find((e) => V(e.value.sort, t.products?.sort || []))?.id ?? e[0]?.id;
395
+ return {
396
+ activeSort: i,
397
+ setSort: d((t) => {
398
+ if (t === i) return;
399
+ let r = e.find((e) => e.id === t);
400
+ r && n({ products: { sort: r.value.sort } });
401
+ }, [
402
+ e,
403
+ n,
404
+ i
405
+ ])
406
+ };
424
407
  }
425
- const T = window.SpeechRecognition || window.webkitSpeechRecognition, G = !!(T && typeof T == "function");
426
- function J() {
427
- return {
428
- listening: !1,
429
- startListening: () => {
430
- },
431
- stopListening: () => {
432
- }
433
- };
408
+ //#endregion
409
+ //#region packages/preact/hooks/src/useSpeechToText.ts
410
+ var U = window.SpeechRecognition || window.webkitSpeechRecognition, W = !!(U && typeof U == "function");
411
+ function G() {
412
+ return {
413
+ listening: !1,
414
+ startListening: () => {},
415
+ stopListening: () => {}
416
+ };
434
417
  }
435
- function Q({
436
- language: e = "en-US",
437
- interimResults: n = !1,
438
- onResult: t,
439
- onError: o
440
- } = {}) {
441
- const [r, c] = b(!1), i = z(null), u = p(() => {
442
- const s = new T();
443
- s.lang = e, s.interimResults = n, s.onstart = () => c(!0), t && (s.onresult = (a) => {
444
- const { transcript: l } = a.results?.[0]?.[0];
445
- t(l);
446
- }), o && (s.onerror = (a) => o(a.error)), s.onend = () => c(!1), i.current = s, s.start();
447
- }, [e, n, o, t]), d = p(() => {
448
- i.current?.stop();
449
- }, [i]);
450
- return {
451
- listening: r,
452
- startListening: u,
453
- stopListening: d
454
- };
418
+ function K({ language: e = "en-US", interimResults: t = !1, onResult: n, onError: r } = {}) {
419
+ let [i, a] = h(!1), o = m(null);
420
+ return {
421
+ listening: i,
422
+ startListening: d(() => {
423
+ let i = new U();
424
+ i.lang = e, i.interimResults = t, i.onstart = () => a(!0), n && (i.onresult = (e) => {
425
+ let { transcript: t } = e.results?.[0]?.[0];
426
+ n(t);
427
+ }), r && (i.onerror = (e) => r(e.error)), i.onend = () => a(!1), o.current = i, i.start();
428
+ }, [
429
+ e,
430
+ t,
431
+ r,
432
+ n
433
+ ]),
434
+ stopListening: d(() => {
435
+ o.current?.stop();
436
+ }, [o])
437
+ };
455
438
  }
456
- const we = G ? Q : J;
457
- function W(e, n) {
458
- if (!e.length || !n.length) return [];
459
- const t = n.reduce((o, r) => (o[r] = {}, o), {});
460
- return e.forEach((o) => {
461
- o.customFields?.forEach(({ key: r, value: c }) => {
462
- const i = r.toLowerCase();
463
- n.includes(i) && (t[i][c] = t[i][c] || [], t[i][c].push(o));
464
- });
465
- }), Object.entries(t).filter((o) => Object.keys(o[1]).length).map(([o, r]) => ({
466
- field: o,
467
- options: Object.entries(r).map(([c, i]) => ({
468
- value: c,
469
- skus: i,
470
- unavailable: !1,
471
- selected: !1
472
- }))
473
- }));
439
+ var q = W ? K : G;
440
+ //#endregion
441
+ //#region packages/preact/hooks/src/useSwatches/aggregateSwatches.ts
442
+ function J(e, t) {
443
+ if (!e.length || !t.length) return [];
444
+ let n = t.reduce((e, t) => (e[t] = {}, e), {});
445
+ return e.forEach((e) => {
446
+ e.customFields?.forEach(({ key: r, value: i }) => {
447
+ let a = r.toLowerCase();
448
+ t.includes(a) && (n[a][i] = n[a][i] || [], n[a][i].push(e));
449
+ });
450
+ }), Object.entries(n).filter((e) => Object.keys(e[1]).length).map(([e, t]) => ({
451
+ field: e,
452
+ options: Object.entries(t).map(([e, t]) => ({
453
+ value: e,
454
+ skus: t,
455
+ unavailable: !1,
456
+ selected: !1
457
+ }))
458
+ }));
474
459
  }
475
- function Y(e, n) {
476
- return e.length ? e.map(({ field: t, options: o }) => ({
477
- field: t,
478
- options: o.map((r) => {
479
- const c = !r.skus?.some((u) => Object.entries(n).every(([d, s]) => d === t ? !0 : u.customFields?.find((l) => l.key.toLowerCase() === d)?.value === s)), i = n[t] === r.value;
480
- return {
481
- ...r,
482
- unavailable: c,
483
- selected: i
484
- };
485
- })
486
- })) : [];
460
+ //#endregion
461
+ //#region packages/preact/hooks/src/useSwatches/applySelectionStates.ts
462
+ function Y(e, t) {
463
+ return e.length ? e.map(({ field: e, options: n }) => ({
464
+ field: e,
465
+ options: n.map((n) => {
466
+ let r = !n.skus?.some((n) => Object.entries(t).every(([t, r]) => t === e ? !0 : n.customFields?.find((e) => e.key.toLowerCase() === t)?.value === r)), i = t[e] === n.value;
467
+ return {
468
+ ...n,
469
+ unavailable: r,
470
+ selected: i
471
+ };
472
+ })
473
+ })) : [];
487
474
  }
488
- const N = ["4XS", "3XS", "2XS", "XXS", "XS", "S", "M", "L", "XL", "XXL", "2XL", "XXXL", "3XL", "4XL"];
489
- function ee(e) {
490
- if (N.includes(e))
491
- return 1e3 + N.indexOf(e);
492
- const n = parseFloat(e);
493
- return isNaN(n) ? e : n;
475
+ //#endregion
476
+ //#region packages/preact/hooks/src/useSwatches/sortOptions.ts
477
+ var X = [
478
+ "4XS",
479
+ "3XS",
480
+ "2XS",
481
+ "XXS",
482
+ "XS",
483
+ "S",
484
+ "M",
485
+ "L",
486
+ "XL",
487
+ "XXL",
488
+ "2XL",
489
+ "XXXL",
490
+ "3XL",
491
+ "4XL"
492
+ ];
493
+ function Z(e) {
494
+ if (X.includes(e)) return 1e3 + X.indexOf(e);
495
+ let t = parseFloat(e);
496
+ return isNaN(t) ? e : t;
494
497
  }
495
- function te(e, n) {
496
- return [...n].sort((t, o) => {
497
- const [r, c] = [t.value, o.value].map(ee);
498
- return r < c ? -1 : 1;
499
- });
498
+ function Q(e, t) {
499
+ return [...t].sort((e, t) => {
500
+ let [n, r] = [e.value, t.value].map(Z);
501
+ return n < r ? -1 : 1;
502
+ });
500
503
  }
501
- function be(e = [], n = []) {
502
- const [t, o] = b({}), r = y(() => W(e, n).map(({ field: s, options: a }) => ({
503
- field: s,
504
- options: te(s, a)
505
- })), [e, n]), c = y(() => Y(r, t), [r, t]), i = p((d, s) => {
506
- o((a) => {
507
- const l = { ...a };
508
- return l[d] === s ? delete l[d] : l[d] = s, l;
509
- });
510
- }, []), u = y(() => Object.keys(t).filter((a) => t[a]).length === 0 ? [] : c.filter(({ field: a }) => t[a]).map(({ field: a, options: l }) => {
511
- const f = t[a];
512
- return l.find((v) => v.value === f)?.skus ?? [];
513
- }).reduce((a, l) => a.filter((f) => l.includes(f))), [c, t]);
514
- return { swatches: c, toggleOption: i, matchedSkus: u };
504
+ //#endregion
505
+ //#region packages/preact/hooks/src/useSwatches/useSwatches.ts
506
+ function $(e = [], t = []) {
507
+ let [n, r] = h({}), i = p(() => J(e, t).map(({ field: e, options: t }) => ({
508
+ field: e,
509
+ options: Q(e, t)
510
+ })), [e, t]), a = p(() => Y(i, n), [i, n]);
511
+ return {
512
+ swatches: a,
513
+ toggleOption: d((e, t) => {
514
+ r((n) => {
515
+ let r = { ...n };
516
+ return r[e] === t ? delete r[e] : r[e] = t, r;
517
+ });
518
+ }, []),
519
+ matchedSkus: p(() => Object.keys(n).filter((e) => n[e]).length === 0 ? [] : a.filter(({ field: e }) => n[e]).map(({ field: e, options: t }) => {
520
+ let r = n[e];
521
+ return t.find((e) => e.value === r)?.skus ?? [];
522
+ }).reduce((e, t) => e.filter((e) => t.includes(e))), [a, n])
523
+ };
515
524
  }
516
- export {
517
- Me as addToHistory,
518
- Te as getSavedHistory,
519
- G as speechToTextSupported,
520
- A as useActions,
521
- le as useDecoratedSearchResults,
522
- de as useFacet,
523
- fe as useFacets,
524
- Ne as useHistory,
525
- Le as useLoadMore,
526
- S as useNostoAppState,
527
- pe as usePagination,
528
- ge as usePersonalization,
529
- E as useProductFilters,
530
- V as useRange,
531
- me as useRangeSelector,
532
- he as useResponse,
533
- ve as useSelectedFiltersCount,
534
- Se as useShopifyProduct,
535
- ye as useSizeOptions,
536
- Fe as useSort,
537
- we as useSpeechToText,
538
- be as useSwatches
539
- };
525
+ //#endregion
526
+ export { s as addToHistory, a as getSavedHistory, W as speechToTextSupported, r as useActions, g as useDecoratedSearchResults, _ as useFacet, v as useFacets, o as useHistory, l as useLoadMore, c as useNostoAppState, b as usePagination, x as usePersonalization, C as useProductFilters, w as useRange, O as useRangeSelector, k as useResponse, j as useSelectedFiltersCount, P as useShopifyProduct, B as useSizeOptions, H as useSort, q as useSpeechToText, $ as useSwatches };