@nosto/search-js 1.7.5 → 1.7.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.
@@ -1,566 +1,171 @@
1
- import { isBot as H } from "../utils/utils.es.js";
2
- import { options as B, createContext as W, Fragment as G, toChildArray as ne } from "preact";
3
- import { useContext as q, useState as I, useEffect as N, useMemo as M, useCallback as v, useRef as oe } from "preact/hooks";
4
- import { s as se } from "../search-B0-bVNMy.js";
5
- import { s as E } from "../index.es-B8mbAxS4.js";
6
- var ie = 0;
7
- function w(e, r, t, n, o, c) {
8
- r || (r = {});
9
- var s, i, l = r;
10
- if ("ref" in l) for (i in l = {}, r) i == "ref" ? s = r[i] : l[i] = r[i];
11
- var u = { type: e, props: l, key: t, ref: s, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --ie, __i: -1, __u: 0, __source: o, __self: c };
12
- if (typeof e == "function" && (s = e.defaultProps)) for (i in s) l[i] === void 0 && (l[i] = s[i]);
13
- return B.vnode && B.vnode(u), u;
14
- }
15
- const U = (e) => String(e) === "[object Object]";
16
- function F(e) {
17
- if (!U(e))
18
- return !1;
19
- const r = e.constructor;
20
- if (r === void 0)
21
- return !0;
22
- const t = r.prototype;
23
- return !(!U(t) || !t.hasOwnProperty("isPrototypeOf"));
24
- }
25
- function x(...e) {
26
- return e.reduce((r, t) => V(r, t));
27
- }
28
- function Q(...e) {
29
- return e.reduce((r, t) => V(r, t));
30
- }
31
- function V(e, r) {
32
- return F(e) && F(r) ? Object.entries(r).reduce(
33
- (t, [n, o]) => (t[n] = V(t[n], o), t),
34
- { ...e }
35
- ) : F(e) ? e : r;
36
- }
37
- function b(e, r) {
38
- if (e === r)
39
- return !0;
40
- if (e instanceof Date && r instanceof Date)
41
- return e.getTime() === r.getTime();
42
- if (Array.isArray(e) && Array.isArray(r))
43
- return e.length !== r.length ? !1 : e.every((t, n) => b(t, r[n]));
44
- if (F(e) && F(r)) {
45
- const t = Object.entries(e);
46
- return t.length !== Object.keys(r).length ? !1 : t.every(([n, o]) => b(o, r[n]));
47
- }
48
- return !1;
49
- }
50
- function ce(e, r = {}) {
51
- const t = /* @__PURE__ */ new Map();
52
- let n = Q(e, r ?? {});
53
- const o = Q(e, r);
54
- function c(a) {
55
- n = a(n);
56
- for (const d of t.values())
57
- d(n);
58
- }
59
- function s(a) {
60
- c((d) => ({ ...d, ...a }));
61
- }
62
- function i() {
63
- return n;
64
- }
65
- function l() {
66
- return structuredClone(o);
67
- }
68
- function u(a, d) {
69
- let m;
70
- t.set(d, (g) => {
71
- const h = a(g);
72
- b(h, m) || (m = h, d(h));
73
- });
74
- }
75
- function f(a) {
76
- t.delete(a);
77
- }
78
- return {
79
- updateState: s,
80
- getState: i,
81
- getInitialState: l,
82
- onChange: u,
83
- clearOnChange: f
84
- };
85
- }
86
- const ue = {
87
- loading: !0,
88
- query: {},
89
- response: {},
90
- initialized: !1
91
- };
92
- function _(e = {}) {
93
- return ce(ue, e);
94
- }
95
- const A = W(_());
96
- function y(e = ae) {
97
- const r = q(A), [t, n] = I(e(r.getState()));
98
- return r.onChange(e, n), N(() => () => r.clearOnChange(n), [r]), t;
99
- }
100
- const ae = (e) => e;
101
- function J(e, ...r) {
102
- return r.reduce(
103
- (t, n) => (t[n] = e[n], t),
104
- {}
105
- );
106
- }
107
- const T = W(null), Y = () => {
108
- const e = q(T);
109
- if (!e)
110
- throw new Error("useConfig must be used within a ConfigProvider");
111
- return e;
112
- };
113
- function le(e) {
114
- return Array.from(new Set(e));
115
- }
116
- function fe(e, r) {
117
- return {
118
- ...r,
119
- products: {
120
- facets: e === "autocomplete" ? void 0 : ["*"],
121
- fields: de,
122
- ...r.products
123
- },
124
- ...r.keywords ? {
125
- keywords: {
126
- ...r.keywords,
127
- fields: le([...ge, ...r.keywords.fields ?? []]),
128
- highlight: r.keywords.highlight ?? {
129
- preTag: "<strong>",
130
- postTag: "</strong>"
131
- }
132
- }
133
- } : {}
134
- };
135
- }
136
- const de = [
137
- "productId",
138
- "url",
139
- "name",
140
- "imageUrl",
141
- "imageHash",
142
- "thumbUrl",
143
- "description",
144
- "brand",
145
- "variantId",
146
- "availability",
147
- "price",
148
- "priceText",
149
- "categoryIds",
150
- "categories",
151
- "customFields.key",
152
- "customFields.value",
153
- "priceCurrencyCode",
154
- "datePublished",
155
- "listPrice",
156
- "unitPricingBaseMeasure",
157
- "unitPricingUnit",
158
- "unitPricingMeasure",
159
- "googleCategory",
160
- "gtin",
161
- "ageGroup",
162
- "gender",
163
- "condition",
164
- "alternateImageUrls",
165
- "ratingValue",
166
- "reviewCount",
167
- "inventoryLevel",
168
- "skus.id",
169
- "skus.name",
170
- "skus.price",
171
- "skus.listPrice",
172
- "skus.priceText",
173
- "skus.url",
174
- "skus.imageUrl",
175
- "skus.inventoryLevel",
176
- "skus.customFields.key",
177
- "skus.customFields.value",
178
- "skus.availability",
179
- "pid",
180
- "onDiscount",
181
- "extra.key",
182
- "extra.value",
183
- "saleable",
184
- "available",
185
- "tags1",
186
- "tags2",
187
- "tags3"
188
- ], ge = ["keyword", "_redirect"];
189
- function pe(...e) {
190
- if (!e.every((r) => r == null))
191
- return e.filter((r) => Array.isArray(r)).reduce((r, t) => r.concat(t), []);
192
- }
193
- const X = "nosto.search.";
194
- function me(e) {
195
- var t;
196
- const r = `${X}${e}`;
197
- (t = window.performance) == null || t.mark(`${r}.start`);
198
- }
199
- function he(e) {
200
- var t, n;
201
- const r = `${X}${e}`;
202
- (t = window.performance) == null || t.mark(`${r}.end`), (n = window.performance) == null || n.measure(r, `${r}.start`, `${r}.end`);
203
- }
204
- function O(e) {
205
- return me(e), () => he(e);
206
- }
207
- function ye(e, r, t) {
208
- const n = JSON.stringify(r);
209
- try {
210
- console.info("Setting storage", e, n), t.setItem(e, n);
211
- } catch (o) {
212
- console.warn(o);
213
- }
214
- }
215
- function Se(e, r) {
216
- try {
217
- const t = r.getItem(e);
218
- if (t)
219
- return JSON.parse(t);
220
- } catch (t) {
221
- console.warn(t);
222
- }
223
- }
224
- function ve(e, r) {
225
- ye(e, r, sessionStorage);
226
- }
227
- function we(e) {
228
- return Se(e, sessionStorage);
229
- }
230
- const Z = "nosto:search:searchResult";
231
- function Ce(e, r, t) {
232
- if (!e)
233
- return;
234
- ve(Z, { query: r, result: t });
235
- }
236
- function ke(e, r) {
237
- if (!e)
238
- return null;
239
- const t = we(Z);
240
- if (!t || !Pe(t))
241
- return null;
242
- const n = K(t.query);
243
- return b(K(r), n) ? t.result : null;
244
- }
245
- function K(e) {
246
- return {
247
- accountId: e.accountId,
248
- customRules: e.customRules,
249
- explain: e.explain,
250
- keywords: e.keywords,
251
- products: e.products,
252
- query: e.query,
253
- redirect: e.redirect,
254
- rules: e.rules,
255
- segments: e.segments,
256
- sessionParams: e.sessionParams
257
- };
258
- }
259
- function Pe(e) {
260
- return typeof e == "object" && e !== null && "query" in e && "result" in e;
261
- }
262
- async function ee(e, r, t) {
263
- var u, f, a;
264
- const n = O("newSearch"), o = e.config.pageType, c = x(e.store.getInitialState().query, r), s = x(e.config.search, t, {
265
- track: o,
266
- redirect: o !== "autocomplete",
267
- isKeyword: !!(t != null && t.isKeyword)
268
- });
269
- e.store.updateState({
270
- query: c,
271
- loading: !0,
272
- initialized: !0
273
- });
274
- const i = o !== "autocomplete" && e.config.persistentSearchCache, l = e.config.queryModifications(
275
- {
276
- ...c,
277
- products: {
278
- ...c.products,
279
- // Apply filter merging to avoid overwriting base filters
280
- filter: pe((f = (u = e.store.getInitialState().query) == null ? void 0 : u.products) == null ? void 0 : f.filter, (a = r.products) == null ? void 0 : a.filter)
281
- }
282
- },
283
- o
284
- );
285
- try {
286
- let d;
287
- const m = ke(i, l);
288
- if (m)
289
- d = m;
290
- else {
291
- const g = fe(o, l);
292
- d = await se(g, s), Ce(i, l, d);
293
- }
294
- e.store.updateState({
295
- response: d,
296
- loading: !1
297
- });
298
- } catch (d) {
299
- console.error("Search action failed", d);
300
- }
301
- n();
302
- }
303
- async function $(e, r, t) {
304
- const n = O("updateSearch"), o = x(e.store.getState().query, { products: { from: 0 } }, r);
305
- await ee(e, o, t), n();
306
- }
307
- async function Fe(e, r, t) {
308
- var s;
309
- const n = O("replaceFilter"), o = (s = e.store.getState().query.products) == null ? void 0 : s.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
310
- await $(e, {
311
- products: {
312
- filter: [...(o == null ? void 0 : o.filter((i) => i.field !== r)) ?? [], ...c]
313
- }
314
- }), n();
315
- }
316
- async function be(e, r, t, n) {
317
- var l, u;
318
- const o = O("toggleProductFilter"), c = (l = e.store.getState().query.products) == null ? void 0 : l.filter, s = c == null ? void 0 : c.find((f) => f.value instanceof Array && f.field === r), i = s != null && s.value ? {
319
- ...s,
320
- value: [...s.value.filter((f) => !b(f, t)), ...n ? [t] : []]
321
- } : n ? {
322
- field: r,
323
- value: [t]
324
- } : void 0;
325
- await $(e, {
326
- products: {
327
- filter: [...(c == null ? void 0 : c.filter((f) => f !== s)) ?? [], ...(u = i == null ? void 0 : i.value) != null && u.length ? [i] : []]
328
- }
329
- }), o();
330
- }
331
- function P() {
332
- const e = Y(), r = q(A), t = M(
333
- () => ({
334
- config: e,
335
- store: r
336
- }),
337
- [e, r]
338
- ), n = v(
339
- (i, l) => ee(t, i, l),
340
- [t]
341
- ), o = v(
342
- (i, l) => $(t, i, l),
343
- [t]
344
- ), c = v(
345
- (i, l, u) => be(t, i, l, u),
346
- [t]
347
- ), s = v(
348
- (i, l) => Fe(t, i, l),
349
- [t]
350
- );
351
- return {
352
- newSearch: n,
353
- updateSearch: o,
354
- toggleProductFilter: c,
355
- replaceFilter: s
356
- };
357
- }
358
- function Me({ from: e, size: r, pageSize: t }) {
359
- return H() ? {
360
- products: { from: e + t }
361
- } : {
362
- products: { size: r + t }
363
- };
364
- }
365
- function te(e = 24) {
366
- const { from: r, size: t } = y((c) => {
367
- var s, i;
368
- return {
369
- from: ((s = c.query.products) == null ? void 0 : s.from) ?? 0,
370
- size: ((i = c.query.products) == null ? void 0 : i.size) ?? 0
371
- };
372
- }), { updateSearch: n } = P();
373
- return {
374
- loadMore: v(async () => {
375
- await n(Me({ from: r, size: t, pageSize: e }));
376
- }, [r, t, e, n])
377
- };
378
- }
379
- function Ae({ pageSize: e }) {
380
- const { loadMore: r } = te(e);
381
- return /* @__PURE__ */ w("button", { onClick: r, children: "More results" });
382
- }
383
- function re(e, r) {
384
- var c, s, i;
385
- const t = ((c = r.products) == null ? void 0 : c.total) ?? 0, n = ((s = e.products) == null ? void 0 : s.from) ?? 0, o = ((i = e.products) == null ? void 0 : i.size) ?? 0;
386
- return t > 0 && t > n + o;
387
- }
388
- function Ie() {
389
- return !!(window.IntersectionObserver && window.IntersectionObserverEntry && "intersectionRatio" in window.IntersectionObserverEntry.prototype);
390
- }
391
- function Re({ children: e, loadMoreComponent: r, pageSize: t }) {
392
- const { loading: n, query: o, response: c } = y((i) => J(i, "loading", "query", "response")), s = !n && re(o, c);
393
- return /* @__PURE__ */ w(G, { children: [
1
+ import { isBot as B } from "../utils/utils.es.js";
2
+ import { u as L, a as C, b as v, h as j, p as V, i as D, I as H, c as O, d as R, S as x, C as k, e as U, f as P } from "../InfiniteScrollWithObserver-kuSGeBWr.js";
3
+ import { k as ze, j as Ie } from "../InfiniteScrollWithObserver-kuSGeBWr.js";
4
+ import { Fragment as W, toChildArray as $ } from "preact";
5
+ import { s as q } from "../index.es-B8mbAxS4.js";
6
+ import { useEffect as E, useState as N, useMemo as w, useCallback as M } from "preact/hooks";
7
+ function K({ pageSize: e }) {
8
+ const { loadMore: n } = L(e);
9
+ return /* @__PURE__ */ C("button", { onClick: n, children: "More results" });
10
+ }
11
+ function Y({ children: e, loadMoreComponent: n, pageSize: t }) {
12
+ const { loading: r, query: o, response: a } = v((u) => V(u, "loading", "query", "response")), i = !r && j(o, a);
13
+ return /* @__PURE__ */ C(W, { children: [
394
14
  e,
395
- s && (r ? /* @__PURE__ */ w(r, { pageSize: t }) : /* @__PURE__ */ w(Ae, { pageSize: t }))
15
+ i && (n ? /* @__PURE__ */ C(n, { pageSize: t }) : /* @__PURE__ */ C(K, { pageSize: t }))
396
16
  ] });
397
17
  }
398
- function Ne({ children: e, pageSize: r }) {
399
- const t = oe(null), { query: n, response: o } = y((s) => J(s, "query", "response")), { loadMore: c } = te(r);
400
- return N(() => {
401
- let s, i;
402
- return re(n, o) && (s = t.current, i = new IntersectionObserver((l) => {
403
- const u = l[0];
404
- u != null && u.isIntersecting && c();
405
- }), s && i.observe(s)), () => {
406
- s && i.unobserve(s);
407
- };
408
- }, [o]), /* @__PURE__ */ w(G, { children: [
409
- e,
410
- /* @__PURE__ */ w("div", { ref: t, style: { height: "1px" } })
411
- ] });
412
- }
413
- const Ye = !H() && Ie() ? Ne : Re;
414
- function _e(e) {
18
+ const ge = !B() && D() ? H : Y;
19
+ function _(e) {
415
20
  return e.type === "input";
416
21
  }
417
- function Te(e) {
22
+ function G(e) {
418
23
  return !!e && typeof e == "object" && "type" in e && "props" in e;
419
24
  }
420
- function j(e, r = { depth: 0 }) {
25
+ function z(e, n = { depth: 0 }) {
421
26
  const { children: t } = e;
422
- return ne(t).map((n) => {
423
- if (!Te(n))
424
- return n;
425
- const o = e.updateElement(n, r);
27
+ return $(t).map((r) => {
28
+ if (!G(r))
29
+ return r;
30
+ const o = e.updateElement(r, n);
426
31
  return o === null ? null : (o.props = {
427
32
  ...o.props,
428
- children: j({ ...e, children: o.props.children }, { depth: r.depth + 1 })
33
+ children: z({ ...e, children: o.props.children }, { depth: n.depth + 1 })
429
34
  }, o);
430
35
  });
431
36
  }
432
- function Xe({ children: e, onSearchInput: r }) {
433
- return j({
37
+ function me({ children: e, onSearchInput: n }) {
38
+ return z({
434
39
  children: e,
435
- updateElement: (t) => (!_e(t) || t.props.type !== "search" || (t.props = {
40
+ updateElement: (t) => (!_(t) || t.props.type !== "search" || (t.props = {
436
41
  ...t.props,
437
- onInput: (n) => {
438
- n.target instanceof HTMLInputElement && r(n.target);
42
+ onInput: (r) => {
43
+ r.target instanceof HTMLInputElement && n(r.target);
439
44
  }
440
45
  }), t)
441
46
  });
442
47
  }
443
- const Oe = "nosto:search:scrollPos";
444
- function ze() {
445
- window.sessionStorage.setItem(Oe, window.scrollY.toString());
48
+ const J = "nosto:search:scrollPos";
49
+ function Q() {
50
+ window.sessionStorage.setItem(J, window.scrollY.toString());
446
51
  }
447
- function Ze({ children: e, hit: r, onClick: t }) {
448
- const { pageType: n } = Y(), o = n === "autocomplete" ? void 0 : n;
449
- return j({
52
+ function he({ children: e, hit: n, onClick: t }) {
53
+ const { pageType: r } = O(), o = r === "autocomplete" ? void 0 : r;
54
+ return z({
450
55
  children: e,
451
- updateElement: (c, s) => (s.depth > 0 || (c.props = {
452
- ...c.props,
453
- onClick: (i) => {
454
- r && o && E((l) => l.recordSearchClick(o, r)), ze(), typeof t == "function" && t(i);
56
+ updateElement: (a, i) => (i.depth > 0 || (a.props = {
57
+ ...a.props,
58
+ onClick: (u) => {
59
+ n && o && q((f) => f.recordSearchClick(o, n)), Q(), typeof t == "function" && t(u);
455
60
  }
456
- }), c)
61
+ }), a)
457
62
  });
458
63
  }
459
- function D() {
460
- N(() => {
64
+ function I() {
65
+ E(() => {
461
66
  const e = window.setTimeout(() => {
462
67
  console.error("Nosto client script has not loaded after 3 seconds.");
463
68
  }, 3e3);
464
- E(() => {
69
+ q(() => {
465
70
  window.clearTimeout(e);
466
71
  });
467
72
  }, []);
468
73
  }
469
- const L = {
74
+ const T = {
470
75
  defaultCurrency: "EUR",
471
76
  queryModifications: (e) => e
472
- }, xe = {
473
- ...L
77
+ }, X = {
78
+ ...T
474
79
  };
475
- function qe(e) {
80
+ function Z(e) {
476
81
  return {
477
82
  pageType: "autocomplete",
478
- ...xe,
83
+ ...X,
479
84
  ...e
480
85
  };
481
86
  }
482
- function et({ config: e, store: r, children: t }) {
483
- const n = r ?? _();
484
- return D(), /* @__PURE__ */ w(T, { value: qe(e), children: /* @__PURE__ */ w(A, { value: n, children: t }) });
87
+ function Se({ config: e, store: n, children: t }) {
88
+ const r = n ?? R();
89
+ return I(), /* @__PURE__ */ C(k, { value: Z(e), children: /* @__PURE__ */ C(x, { value: r, children: t }) });
485
90
  }
486
- const Ee = {
487
- ...L,
91
+ const ee = {
92
+ ...T,
488
93
  persistentSearchCache: !1,
489
94
  preservePageScroll: !1
490
95
  };
491
- function Ve(e) {
96
+ function te(e) {
492
97
  return {
493
98
  pageType: "category",
494
- ...Ee,
99
+ ...ee,
495
100
  ...e
496
101
  };
497
102
  }
498
- function tt({ config: e, store: r, children: t }) {
499
- const n = r ?? _();
500
- return D(), /* @__PURE__ */ w(T, { value: Ve(e), children: /* @__PURE__ */ w(A, { value: n, children: t }) });
103
+ function ve({ config: e, store: n, children: t }) {
104
+ const r = n ?? R();
105
+ return I(), /* @__PURE__ */ C(k, { value: te(e), children: /* @__PURE__ */ C(x, { value: r, children: t }) });
501
106
  }
502
- const $e = {
503
- ...L,
107
+ const ne = {
108
+ ...T,
504
109
  persistentSearchCache: !1,
505
110
  preservePageScroll: !1
506
111
  };
507
- function je(e = {}) {
112
+ function re(e = {}) {
508
113
  return {
509
114
  pageType: "serp",
510
- ...$e,
115
+ ...ne,
511
116
  ...e
512
117
  };
513
118
  }
514
- function rt({ config: e, store: r, children: t }) {
515
- const n = r ?? _();
516
- return D(), /* @__PURE__ */ w(T, { value: je(e), children: /* @__PURE__ */ w(A, { value: n, children: t }) });
119
+ function ye({ config: e, store: n, children: t }) {
120
+ const r = n ?? R();
121
+ return I(), /* @__PURE__ */ C(k, { value: re(e), children: /* @__PURE__ */ C(x, { value: r, children: t }) });
517
122
  }
518
- function nt(e) {
519
- const r = y((t) => t.response);
520
- return e && Array.isArray(e) || e && F(e) ? e : r;
123
+ function Ce(e) {
124
+ const n = v((t) => t.response);
125
+ return e && Array.isArray(e) || e && U(e) ? e : n;
521
126
  }
522
- function ot(e) {
523
- var s;
524
- const r = ((s = e.data) == null ? void 0 : s.filter((i) => i.selected).length) ?? 0, [t, n] = I(r > 0), { toggleProductFilter: o } = P();
127
+ function Fe(e) {
128
+ var i;
129
+ const n = ((i = e.data) == null ? void 0 : i.filter((u) => u.selected).length) ?? 0, [t, r] = N(n > 0), { toggleProductFilter: o } = P();
525
130
  return {
526
131
  /** Active value */
527
132
  active: t,
528
133
  /** Selected filters count */
529
- selectedFiltersCount: r,
134
+ selectedFiltersCount: n,
530
135
  /** Toggle active function */
531
136
  toggleActive: () => {
532
- n(!t);
137
+ r(!t);
533
138
  },
534
139
  /** Toggle product filter function */
535
140
  toggleProductFilter: o
536
141
  };
537
142
  }
538
- function st() {
539
- const { loading: e, facets: r } = y((t) => {
540
- var n, o;
143
+ function Me() {
144
+ const { loading: e, facets: n } = v((t) => {
145
+ var r, o;
541
146
  return {
542
147
  loading: t.loading,
543
- facets: ((o = (n = t.response) == null ? void 0 : n.products) == null ? void 0 : o.facets) ?? []
148
+ facets: ((o = (r = t.response) == null ? void 0 : r.products) == null ? void 0 : o.facets) ?? []
544
149
  };
545
150
  });
546
151
  return {
547
152
  /** Loading state */
548
153
  loading: e,
549
154
  /** Array of facets*/
550
- facets: r
155
+ facets: n
551
156
  };
552
157
  }
553
- function De(e, r) {
554
- const t = r - e;
555
- return !isNaN(t) && t > 0 ? new Array(r - e).fill(void 0).map((n, o) => o + e) : [];
158
+ function oe(e, n) {
159
+ const t = n - e;
160
+ return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((r, o) => o + e) : [];
556
161
  }
557
- function it(e) {
558
- const { query: r, products: t } = y((n) => ({
559
- query: n.query,
560
- products: n.response.products
162
+ function Pe(e) {
163
+ const { query: n, products: t } = v((r) => ({
164
+ query: r.query,
165
+ products: r.response.products
561
166
  }));
562
- return M(() => {
563
- var k;
167
+ return w(() => {
168
+ var F;
564
169
  if (!t)
565
170
  return {
566
171
  totalPages: 0,
@@ -568,138 +173,138 @@ function it(e) {
568
173
  resultsTo: 0,
569
174
  pages: []
570
175
  };
571
- const n = ((k = r.products) == null ? void 0 : k.from) ?? 0, o = (e == null ? void 0 : e.width) ?? 1 / 0, c = Math.max(Math.floor(o - 1) / 2, 1), s = t.size > 0 ? Math.floor(n / t.size) + 1 : 1, i = t.size > 0 ? Math.ceil(t.total / t.size) : 0, l = (C) => C >= s - c && C <= s + c, u = n + 1, f = Math.min(n + t.total, t.total), a = {
572
- from: n,
573
- page: s,
176
+ const r = ((F = n.products) == null ? void 0 : F.from) ?? 0, o = (e == null ? void 0 : e.width) ?? 1 / 0, a = Math.max(Math.floor(o - 1) / 2, 1), i = t.size > 0 ? Math.floor(r / t.size) + 1 : 1, u = t.size > 0 ? Math.ceil(t.total / t.size) : 0, f = (S) => S >= i - a && S <= i + a, s = r + 1, l = Math.min(r + t.total, t.total), c = {
177
+ from: r,
178
+ page: i,
574
179
  current: !0
575
- }, d = (C) => ({
576
- from: (C - 1) * t.size,
577
- page: C,
578
- current: C === s
579
- }), m = s > 1 ? d(s - 1) : void 0, g = s < i ? d(s + 1) : void 0, h = c === 1 / 0 || s - c - 1 > 1 ? d(1) : void 0, p = c === 1 / 0 || s + c + 1 < i ? d(i) : void 0, S = De(1, i + 1).filter(l).map(d);
180
+ }, g = (S) => ({
181
+ from: (S - 1) * t.size,
182
+ page: S,
183
+ current: S === i
184
+ }), m = i > 1 ? g(i - 1) : void 0, d = i < u ? g(i + 1) : void 0, y = a === 1 / 0 || i - a - 1 > 1 ? g(1) : void 0, p = a === 1 / 0 || i + a + 1 < u ? g(u) : void 0, h = oe(1, u + 1).filter(f).map(g);
580
185
  return {
581
- totalPages: i,
582
- resultsFrom: u,
583
- resultsTo: f,
584
- current: a,
186
+ totalPages: u,
187
+ resultsFrom: s,
188
+ resultsTo: l,
189
+ current: c,
585
190
  prev: m,
586
- next: g,
587
- first: h,
191
+ next: d,
192
+ first: y,
588
193
  last: p,
589
- pages: S
194
+ pages: h
590
195
  };
591
- }, [r, t, e == null ? void 0 : e.width]);
592
- }
593
- function ct() {
594
- const [e, r] = I([]), [t, n] = I([]);
595
- return N(() => {
596
- E(async (o) => {
597
- const { products: c, segments: s } = await o.getSearchSessionParams();
598
- r(s ?? []), n((c == null ? void 0 : c.personalizationBoost) ?? []);
196
+ }, [n, t, e == null ? void 0 : e.width]);
197
+ }
198
+ function be() {
199
+ const [e, n] = N([]), [t, r] = N([]);
200
+ return E(() => {
201
+ q(async (o) => {
202
+ const { products: a, segments: i } = await o.getSearchSessionParams();
203
+ n(i ?? []), r((a == null ? void 0 : a.personalizationBoost) ?? []);
599
204
  });
600
205
  }, []), {
601
206
  segments: e,
602
207
  boost: t
603
208
  };
604
209
  }
605
- function Le() {
606
- const { facets: e } = y((u) => {
607
- var f;
210
+ function se() {
211
+ const { facets: e } = v((s) => {
212
+ var l;
608
213
  return {
609
- facets: ((f = u.response.products) == null ? void 0 : f.facets) ?? []
214
+ facets: ((l = s.response.products) == null ? void 0 : l.facets) ?? []
610
215
  };
611
- }), { replaceFilter: r, toggleProductFilter: t } = P(), n = v(
612
- (u) => {
613
- const f = e == null ? void 0 : e.find((a) => a.type === "stats" && a.field === u);
614
- if (f && "min" in f && "max" in f)
615
- return f;
216
+ }), { replaceFilter: n, toggleProductFilter: t } = P(), r = M(
217
+ (s) => {
218
+ const l = e == null ? void 0 : e.find((c) => c.type === "stats" && c.field === s);
219
+ if (l && "min" in l && "max" in l)
220
+ return l;
616
221
  },
617
222
  [e]
618
- ), o = v(
619
- (u) => {
620
- var f;
621
- return ((f = e == null ? void 0 : e.find((a) => a.field === u)) == null ? void 0 : f.name) ?? u;
223
+ ), o = M(
224
+ (s) => {
225
+ var l;
226
+ return ((l = e == null ? void 0 : e.find((c) => c.field === s)) == null ? void 0 : l.name) ?? s;
622
227
  },
623
228
  [e]
624
- ), c = v((u) => "field" in u && (u.value instanceof Array || u.range instanceof Array), []), s = v((u) => {
625
- var f;
229
+ ), a = M((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), i = M((s) => {
230
+ var l;
626
231
  return {
627
- ...u,
628
- range: (f = u.range) == null ? void 0 : f.map((a) => ({
629
- gt: a.gt ? Number(a.gt) : a.gt,
630
- gte: a.gte ? Number(a.gte) : a.gte,
631
- lt: a.lt ? Number(a.lt) : a.lt,
632
- lte: a.lte ? Number(a.lte) : a.lte
232
+ ...s,
233
+ range: (l = s.range) == null ? void 0 : l.map((c) => ({
234
+ gt: c.gt ? Number(c.gt) : c.gt,
235
+ gte: c.gte ? Number(c.gte) : c.gte,
236
+ lt: c.lt ? Number(c.lt) : c.lt,
237
+ lte: c.lte ? Number(c.lte) : c.lte
633
238
  }))
634
239
  };
635
- }, []), i = v(
636
- (u) => (u.value ?? []).map((a) => ({
637
- value: a,
638
- field: u.field,
639
- name: o(u.field),
640
- filter: s(u),
240
+ }, []), u = M(
241
+ (s) => (s.value ?? []).map((c) => ({
242
+ value: c,
243
+ field: s.field,
244
+ name: o(s.field),
245
+ filter: i(s),
641
246
  remove: () => {
642
- t(u.field, a, !1);
247
+ t(s.field, c, !1);
643
248
  }
644
249
  })),
645
- [s, o, t]
646
- ), l = v(
647
- (u) => (u.range ?? []).map((a) => {
648
- var g, h;
649
- const d = a.gte ?? a.gt ?? ((g = n(u.field)) == null ? void 0 : g.min), m = a.lte ?? a.lt ?? ((h = n(u.field)) == null ? void 0 : h.max);
650
- if (d !== void 0 && m !== void 0)
250
+ [i, o, t]
251
+ ), f = M(
252
+ (s) => (s.range ?? []).map((c) => {
253
+ var d, y;
254
+ const g = c.gte ?? c.gt ?? ((d = r(s.field)) == null ? void 0 : d.min), m = c.lte ?? c.lt ?? ((y = r(s.field)) == null ? void 0 : y.max);
255
+ if (g !== void 0 && m !== void 0)
651
256
  return {
652
- value: `${d} - ${m}`,
653
- field: u.field,
654
- name: o(u.field),
655
- filter: s(u),
257
+ value: `${g} - ${m}`,
258
+ field: s.field,
259
+ name: o(s.field),
260
+ filter: i(s),
656
261
  remove: () => {
657
- r(u.field, void 0);
262
+ n(s.field, void 0);
658
263
  }
659
264
  };
660
265
  }).filter(Boolean),
661
- [s, n, o, r]
266
+ [i, r, o, n]
662
267
  );
663
268
  return {
664
- selectFilters: c,
665
- toValueFilter: i,
666
- toRangeFilter: l
269
+ selectFilters: a,
270
+ toValueFilter: u,
271
+ toRangeFilter: f
667
272
  };
668
273
  }
669
- function Be() {
670
- const { filter: e } = y((i) => {
671
- var l;
274
+ function ie() {
275
+ const { filter: e } = v((u) => {
276
+ var f;
672
277
  return {
673
- filter: ((l = i.query.products) == null ? void 0 : l.filter) ?? []
278
+ filter: ((f = u.query.products) == null ? void 0 : f.filter) ?? []
674
279
  };
675
- }), { updateSearch: r } = P(), { selectFilters: t, toValueFilter: n, toRangeFilter: o } = Le(), c = M(() => e ? e.filter(t).flatMap((i) => "value" in i ? n(i) : "range" in i ? o(i) : []).filter(Boolean) : [], [e, t, o, n]), s = v(() => {
676
- r({
280
+ }), { updateSearch: n } = P(), { selectFilters: t, toValueFilter: r, toRangeFilter: o } = se(), a = w(() => e ? e.filter(t).flatMap((u) => "value" in u ? r(u) : "range" in u ? o(u) : []).filter(Boolean) : [], [e, t, o, r]), i = M(() => {
281
+ n({
677
282
  products: {
678
283
  filter: []
679
284
  }
680
285
  });
681
- }, [r]);
286
+ }, [n]);
682
287
  return {
683
288
  /** Selected filters array. */
684
- filters: c,
289
+ filters: a,
685
290
  /** Should remove all selected filters. */
686
- removeAll: s
291
+ removeAll: i
687
292
  };
688
293
  }
689
- function R(e) {
294
+ function b(e) {
690
295
  if (typeof e == "number")
691
296
  return e;
692
297
  if (typeof e != "string")
693
298
  return;
694
- const r = Number(e);
695
- return isNaN(r) ? void 0 : r;
696
- }
697
- function Ue(e) {
698
- var a, d, m;
699
- const { replaceFilter: r } = P(), { query: t, products: n } = y((g) => ({
700
- query: g.query,
701
- products: g.response.products
702
- })), o = (a = n == null ? void 0 : n.facets) == null ? void 0 : a.find((g) => g.id === e);
299
+ const n = Number(e);
300
+ return isNaN(n) ? void 0 : n;
301
+ }
302
+ function ce(e) {
303
+ var c, g, m;
304
+ const { replaceFilter: n } = P(), { query: t, products: r } = v((d) => ({
305
+ query: d.query,
306
+ products: d.response.products
307
+ })), o = (c = r == null ? void 0 : r.facets) == null ? void 0 : c.find((d) => d.id === e);
703
308
  if (!o)
704
309
  return {
705
310
  min: 0,
@@ -708,173 +313,172 @@ function Ue(e) {
708
313
  updateRange: () => {
709
314
  }
710
315
  };
711
- const c = (m = (d = t.products) == null ? void 0 : d.filter) == null ? void 0 : m.find((g) => g.field === o.field), s = c != null && c.range ? c.range[0] : void 0, i = typeof s == "object" && ("gte" in s || "lte" in s) ? [R(s.gte), R(s.lte)] : [void 0, void 0], l = "min" in o ? Math.floor(o.min) : 0, u = "max" in o ? Math.ceil(o.max) : 0, f = ([g, h]) => {
712
- const p = g !== void 0 ? Math.floor(g) : void 0, S = h !== void 0 ? Math.ceil(h) : void 0, k = p !== void 0, C = S !== void 0;
713
- (l === p || !k) && (u === S || !C) ? r(o.field, void 0) : (l === p || !k) && C ? r(o.field, {
714
- lte: S.toString()
715
- }) : (u === S || !C) && k ? r(o.field, {
316
+ const a = (m = (g = t.products) == null ? void 0 : g.filter) == null ? void 0 : m.find((d) => d.field === o.field), i = a != null && a.range ? a.range[0] : void 0, u = typeof i == "object" && ("gte" in i || "lte" in i) ? [b(i.gte), b(i.lte)] : [void 0, void 0], f = "min" in o ? Math.floor(o.min) : 0, s = "max" in o ? Math.ceil(o.max) : 0, l = ([d, y]) => {
317
+ const p = d !== void 0 ? Math.floor(d) : void 0, h = y !== void 0 ? Math.ceil(y) : void 0, F = p !== void 0, S = h !== void 0;
318
+ (f === p || !F) && (s === h || !S) ? n(o.field, void 0) : (f === p || !F) && S ? n(o.field, {
319
+ lte: h.toString()
320
+ }) : (s === h || !S) && F ? n(o.field, {
716
321
  gte: p.toString()
717
- }) : k && C && r(o.field, {
322
+ }) : F && S && n(o.field, {
718
323
  gte: p.toString(),
719
- lte: S.toString()
324
+ lte: h.toString()
720
325
  });
721
326
  };
722
327
  return {
723
328
  /** Min value */
724
- min: l,
329
+ min: f,
725
330
  /** Max value */
726
- max: u,
331
+ max: s,
727
332
  /** Range value */
728
- range: [i[0] ?? l, i[1] ?? u],
333
+ range: [u[0] ?? f, u[1] ?? s],
729
334
  /** Update range function */
730
- updateRange: f
335
+ updateRange: l
731
336
  };
732
337
  }
733
- function ut(e, r) {
734
- const { min: t, max: n, range: o, updateRange: c } = Ue(e), { filters: s } = Be(), i = M(() => {
735
- var h;
736
- const a = s.find((p) => {
737
- var S;
738
- return (S = p == null ? void 0 : p.filter) == null ? void 0 : S.range;
338
+ function we(e, n) {
339
+ const { min: t, max: r, range: o, updateRange: a } = ce(e), { filters: i } = ie(), u = w(() => {
340
+ var y;
341
+ const c = i.find((p) => {
342
+ var h;
343
+ return (h = p == null ? void 0 : p.filter) == null ? void 0 : h.range;
739
344
  });
740
- let d = null;
741
- if (a) {
742
- const p = (h = a.filter.range) == null ? void 0 : h[0];
743
- d = [R(p == null ? void 0 : p.gte), R(p == null ? void 0 : p.lte)];
345
+ let g = null;
346
+ if (c) {
347
+ const p = (y = c.filter.range) == null ? void 0 : y[0];
348
+ g = [b(p == null ? void 0 : p.gte), b(p == null ? void 0 : p.lte)];
744
349
  }
745
350
  const m = [];
746
- let g = Math.floor(t / r) * r;
747
- for (; g < n; ) {
748
- const p = g + r, S = d && d[0] === g && d[1] === p;
351
+ let d = Math.floor(t / n) * n;
352
+ for (; d < r; ) {
353
+ const p = d + n, h = g && g[0] === d && g[1] === p;
749
354
  m.push({
750
- min: g,
355
+ min: d,
751
356
  max: p,
752
- selected: S
753
- }), g = p;
357
+ selected: h
358
+ }), d = p;
754
359
  }
755
360
  return m;
756
- }, [s, t, n, r]), l = (a) => {
757
- c([a, o[1]]);
758
- }, u = (a) => {
759
- c([o[0], a]);
760
- }, f = t !== o[0] || n !== o[1];
361
+ }, [i, t, r, n]), f = (c) => {
362
+ a([c, o[1]]);
363
+ }, s = (c) => {
364
+ a([o[0], c]);
365
+ }, l = t !== o[0] || r !== o[1];
761
366
  return {
762
367
  /** Minimum value */
763
368
  min: t,
764
369
  /** Maximum value */
765
- max: n,
370
+ max: r,
766
371
  /** Range value */
767
372
  range: o,
768
373
  /** Update range function */
769
- updateRange: c,
374
+ updateRange: a,
770
375
  /** Ranges */
771
- ranges: i,
376
+ ranges: u,
772
377
  /** Handle min change */
773
- handleMinChange: l,
378
+ handleMinChange: f,
774
379
  /** Handle max change */
775
- handleMaxChange: u,
380
+ handleMaxChange: s,
776
381
  /** Is selected */
777
- isSelected: f
382
+ isSelected: l
778
383
  };
779
384
  }
780
- function at() {
781
- const { products: e, keywords: r } = y((t) => t.response);
385
+ function Ae() {
386
+ const { products: e, keywords: n } = v((t) => t.response);
782
387
  return {
783
388
  /** Array of products */
784
389
  products: e ?? { hits: [], total: 0 },
785
390
  /** Array of keywords */
786
- keywords: r ?? { hits: [], total: 0 }
391
+ keywords: n ?? { hits: [], total: 0 }
787
392
  };
788
393
  }
789
- function lt() {
790
- const e = y((t) => {
791
- var n;
792
- return (n = t.query.products) == null ? void 0 : n.filter;
394
+ function Ne() {
395
+ const e = v((t) => {
396
+ var r;
397
+ return (r = t.query.products) == null ? void 0 : r.filter;
793
398
  });
794
- return M(() => e ? e.reduce((t, n) => t + (Array.isArray(n.value) ? n.value.length : 1), 0) : 0, [e]);
399
+ return w(() => e ? e.reduce((t, r) => t + (Array.isArray(r.value) ? r.value.length : 1), 0) : 0, [e]);
795
400
  }
796
- function z(e) {
401
+ function A(e) {
797
402
  return e && !Number.isNaN(e) ? e : 0;
798
403
  }
799
- function ft(e, r) {
800
- const { from: t, size: n, total: o } = y((u) => {
801
- var f, a, d, m, g;
404
+ function Re(e, n) {
405
+ const { from: t, size: r, total: o } = v((s) => {
406
+ var l, c, g, m, d;
802
407
  return {
803
- from: z(((f = u.query.products) == null ? void 0 : f.from) ?? 0),
804
- size: z(((d = (a = u.response) == null ? void 0 : a.products) == null ? void 0 : d.size) ?? 0),
805
- total: z(((g = (m = u.response) == null ? void 0 : m.products) == null ? void 0 : g.total) ?? 0)
408
+ from: A(((l = s.query.products) == null ? void 0 : l.from) ?? 0),
409
+ size: A(((g = (c = s.response) == null ? void 0 : c.products) == null ? void 0 : g.size) ?? 0),
410
+ total: A(((d = (m = s.response) == null ? void 0 : m.products) == null ? void 0 : d.total) ?? 0)
806
411
  };
807
- }), { updateSearch: c } = P(), s = t + n, i = [...e].reverse().filter((u) => u + r < o);
412
+ }), { updateSearch: a } = P(), i = t + r, u = [...e].reverse().filter((s) => s + n < o);
808
413
  return {
809
414
  /** from value */
810
415
  from: t,
811
416
  /** to value */
812
- to: s,
417
+ to: i,
813
418
  /** total value */
814
419
  total: o,
815
420
  /** size value */
816
- size: n,
421
+ size: r,
817
422
  /** Array of size options */
818
- sizeOptions: i,
423
+ sizeOptions: u,
819
424
  /** Should be called when size is changed */
820
- handleSizeChange: (u) => {
821
- c({
425
+ handleSizeChange: (s) => {
426
+ a({
822
427
  products: {
823
- size: u
428
+ size: s
824
429
  }
825
430
  });
826
431
  }
827
432
  };
828
433
  }
829
- function Qe(e, r) {
830
- return e.length !== r.length ? !1 : e.every((t) => r.find((n) => t.field === n.field && t.order === n.order));
434
+ function ae(e, n) {
435
+ return e.length !== n.length ? !1 : e.every((t) => n.find((r) => t.field === r.field && t.order === r.order));
831
436
  }
832
- function dt(e) {
833
- var c, s;
834
- const r = y((i) => i.query), { updateSearch: t } = P();
437
+ function xe(e) {
438
+ var a, i;
439
+ const n = v((u) => u.query), { updateSearch: t } = P();
835
440
  return {
836
441
  /** Active sort */
837
- activeSort: ((c = e.find((i) => {
838
- var l;
839
- return Qe(i.value.sort, ((l = r.products) == null ? void 0 : l.sort) || []);
840
- })) == null ? void 0 : c.id) ?? ((s = e[0]) == null ? void 0 : s.id),
442
+ activeSort: ((a = e.find((u) => {
443
+ var f;
444
+ return ae(u.value.sort, ((f = n.products) == null ? void 0 : f.sort) || []);
445
+ })) == null ? void 0 : a.id) ?? ((i = e[0]) == null ? void 0 : i.id),
841
446
  /** Set sort function */
842
- setSort: (i) => {
843
- const l = e.find((u) => u.id === i);
844
- l && t({
447
+ setSort: (u) => {
448
+ const f = e.find((s) => s.id === u);
449
+ f && t({
845
450
  products: {
846
- sort: l.value.sort
451
+ sort: f.value.sort
847
452
  }
848
453
  });
849
454
  }
850
455
  };
851
456
  }
852
457
  export {
853
- et as AutocompletePageProvider,
854
- tt as CategoryPageProvider,
855
- Ye as InfiniteScroll,
856
- Re as InfiniteScrollWithLink,
857
- Xe as SearchInput,
858
- rt as SearchPageProvider,
859
- Ze as SerpElement,
860
- A as StoreContext,
861
- ce as createExtendableStore,
862
- _ as createStore,
863
- ue as defaultState,
864
- Me as getNextPageQuery,
458
+ Se as AutocompletePageProvider,
459
+ ve as CategoryPageProvider,
460
+ ge as InfiniteScroll,
461
+ Y as InfiniteScrollWithLink,
462
+ me as SearchInput,
463
+ ye as SearchPageProvider,
464
+ he as SerpElement,
465
+ x as StoreContext,
466
+ ze as createExtendableStore,
467
+ R as createStore,
468
+ Ie as defaultState,
865
469
  P as useActions,
866
- nt as useDecoratedSearchResults,
867
- ot as useFacet,
868
- st as useFacets,
869
- te as useLoadMore,
870
- y as useNostoAppState,
871
- it as usePagination,
872
- ct as usePersonalization,
873
- Be as useProductFilters,
874
- Ue as useRange,
875
- ut as useRangeSelector,
876
- at as useResponse,
877
- lt as useSelectedFiltersCount,
878
- ft as useSizeOptions,
879
- dt as useSort
470
+ Ce as useDecoratedSearchResults,
471
+ Fe as useFacet,
472
+ Me as useFacets,
473
+ L as useLoadMore,
474
+ v as useNostoAppState,
475
+ Pe as usePagination,
476
+ be as usePersonalization,
477
+ ie as useProductFilters,
478
+ ce as useRange,
479
+ we as useRangeSelector,
480
+ Ae as useResponse,
481
+ Ne as useSelectedFiltersCount,
482
+ Re as useSizeOptions,
483
+ xe as useSort
880
484
  };