@nosto/nosto-react 0.3.0 → 0.4.1

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,10 +1,12 @@
1
- import * as React from "react";
2
- import React__default, { createContext, useContext, useEffect, isValidElement, useState, useRef } from "react";
1
+ import React, { createContext, useContext, useEffect, useRef, useMemo, isValidElement, useState } from "react";
3
2
  import { createRoot } from "react-dom/client";
4
3
  const NostoContext = createContext({
5
- account: void 0,
4
+ account: "",
6
5
  currentVariation: "",
7
- renderFunction: void 0
6
+ pageType: "",
7
+ responseMode: "HTML",
8
+ clientScriptLoaded: false,
9
+ useRenderCampaigns: () => void 0
8
10
  });
9
11
  function useNostoContext() {
10
12
  const context = useContext(NostoContext);
@@ -24,7 +26,7 @@ var reactJsxRuntime_production_min = {};
24
26
  * This source code is licensed under the MIT license found in the
25
27
  * LICENSE file in the root directory of this source tree.
26
28
  */
27
- var f = React__default, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
29
+ var f = React, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
28
30
  function q(c, a, g) {
29
31
  var b, d = {}, e = null, h = null;
30
32
  void 0 !== g && (e = "" + g);
@@ -46,7 +48,7 @@ reactJsxRuntime_production_min.jsxs = q;
46
48
  const jsx = jsxRuntime.exports.jsx;
47
49
  const jsxs = jsxRuntime.exports.jsxs;
48
50
  const Fragment = jsxRuntime.exports.Fragment;
49
- const NostoFohofo = () => {
51
+ function Nosto404(props) {
50
52
  const {
51
53
  clientScriptLoaded,
52
54
  currentVariation,
@@ -61,7 +63,7 @@ const NostoFohofo = () => {
61
63
  useEffect(() => {
62
64
  if (clientScriptLoaded && pageTypeUpdated) {
63
65
  window.nostojs((api) => {
64
- api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewNotFound().setPlacements(api.placements.getPlacements()).load().then((data) => {
66
+ api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewNotFound().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
65
67
  renderCampaigns(data, api);
66
68
  });
67
69
  });
@@ -76,8 +78,8 @@ const NostoFohofo = () => {
76
78
  children: "notfound"
77
79
  })
78
80
  });
79
- };
80
- const NostoOther = () => {
81
+ }
82
+ function NostoOther(props) {
81
83
  const {
82
84
  clientScriptLoaded,
83
85
  currentVariation,
@@ -92,7 +94,7 @@ const NostoOther = () => {
92
94
  useEffect(() => {
93
95
  if (clientScriptLoaded && pageTypeUpdated) {
94
96
  window.nostojs((api) => {
95
- api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewOther().setPlacements(api.placements.getPlacements()).load().then((data) => {
97
+ api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewOther().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
96
98
  renderCampaigns(data, api);
97
99
  });
98
100
  });
@@ -107,8 +109,8 @@ const NostoOther = () => {
107
109
  children: "other"
108
110
  })
109
111
  });
110
- };
111
- const NostoCheckout = () => {
112
+ }
113
+ function NostoCheckout(props) {
112
114
  const {
113
115
  clientScriptLoaded,
114
116
  currentVariation,
@@ -123,7 +125,7 @@ const NostoCheckout = () => {
123
125
  useEffect(() => {
124
126
  if (clientScriptLoaded && pageTypeUpdated) {
125
127
  window.nostojs((api) => {
126
- api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCart().setPlacements(api.placements.getPlacements()).load().then((data) => {
128
+ api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCart().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
127
129
  renderCampaigns(data, api);
128
130
  });
129
131
  });
@@ -138,11 +140,61 @@ const NostoCheckout = () => {
138
140
  children: "cart"
139
141
  })
140
142
  });
141
- };
142
- const NostoProduct = ({
143
- product,
144
- tagging
145
- }) => {
143
+ }
144
+ function isPlainObject(value) {
145
+ const isObject = (v) => String(v) === "[object Object]";
146
+ if (!isObject(value))
147
+ return false;
148
+ const constructor = value.constructor;
149
+ if (constructor === void 0)
150
+ return true;
151
+ const prototype = constructor.prototype;
152
+ if (!isObject(prototype))
153
+ return false;
154
+ if (!prototype.hasOwnProperty("isPrototypeOf")) {
155
+ return false;
156
+ }
157
+ return true;
158
+ }
159
+ function deepCompare(a, b) {
160
+ if (a === b) {
161
+ return true;
162
+ }
163
+ if (a instanceof Date && b instanceof Date) {
164
+ return a.getTime() === b.getTime();
165
+ }
166
+ if (a instanceof Array && b instanceof Array) {
167
+ if (a.length !== b.length) {
168
+ return false;
169
+ }
170
+ return a.every((v, i) => deepCompare(v, b[i]));
171
+ }
172
+ if (isPlainObject(a) && isPlainObject(b)) {
173
+ const entriesA = Object.entries(a);
174
+ if (entriesA.length !== Object.keys(b).length) {
175
+ return false;
176
+ }
177
+ return entriesA.every(([k2, v]) => deepCompare(v, b[k2]));
178
+ }
179
+ return false;
180
+ }
181
+ function useDeepCompareEffect(callback, dependencies) {
182
+ return useEffect(callback, useDeepCompareMemoize(dependencies));
183
+ }
184
+ function useDeepCompareMemoize(value) {
185
+ const ref = useRef(value);
186
+ const signalRef = useRef(0);
187
+ if (!deepCompare(value, ref.current)) {
188
+ ref.current = value;
189
+ signalRef.current += 1;
190
+ }
191
+ return useMemo(() => ref.current, [signalRef.current]);
192
+ }
193
+ function NostoProduct(props) {
194
+ const {
195
+ product,
196
+ tagging
197
+ } = props;
146
198
  const {
147
199
  clientScriptLoaded,
148
200
  currentVariation,
@@ -154,15 +206,15 @@ const NostoProduct = ({
154
206
  renderCampaigns,
155
207
  pageTypeUpdated
156
208
  } = useRenderCampaigns("product");
157
- useEffect(() => {
209
+ useDeepCompareEffect(() => {
158
210
  if (clientScriptLoaded && pageTypeUpdated) {
159
211
  window.nostojs((api) => {
160
- api.defaultSession().setResponseMode(responseMode).viewProduct(product).setPlacements(api.placements.getPlacements()).load().then((data) => {
212
+ api.defaultSession().setResponseMode(responseMode).viewProduct(product).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
161
213
  renderCampaigns(data, api);
162
214
  });
163
- }, [clientScriptLoaded, currentVariation, product, recommendationComponent, pageTypeUpdated]);
215
+ });
164
216
  }
165
- });
217
+ }, [clientScriptLoaded, currentVariation, product, recommendationComponent, pageTypeUpdated]);
166
218
  return /* @__PURE__ */ jsxs(Fragment, {
167
219
  children: [/* @__PURE__ */ jsx("div", {
168
220
  className: "nosto_page_type",
@@ -280,10 +332,11 @@ const NostoProduct = ({
280
332
  }, index))]
281
333
  })]
282
334
  });
283
- };
284
- const NostoCategory = ({
285
- category
286
- }) => {
335
+ }
336
+ function NostoCategory(props) {
337
+ const {
338
+ category
339
+ } = props;
287
340
  const {
288
341
  clientScriptLoaded,
289
342
  currentVariation,
@@ -298,7 +351,7 @@ const NostoCategory = ({
298
351
  useEffect(() => {
299
352
  if (clientScriptLoaded && pageTypeUpdated) {
300
353
  window.nostojs((api) => {
301
- api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCategory(category).setPlacements(api.placements.getPlacements()).load().then((data) => {
354
+ api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewCategory(category).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
302
355
  renderCampaigns(data, api);
303
356
  });
304
357
  });
@@ -319,10 +372,11 @@ const NostoCategory = ({
319
372
  children: category
320
373
  })]
321
374
  });
322
- };
323
- const NostoSearch = ({
324
- query
325
- }) => {
375
+ }
376
+ function NostoSearch(props) {
377
+ const {
378
+ query
379
+ } = props;
326
380
  const {
327
381
  clientScriptLoaded,
328
382
  currentVariation,
@@ -337,7 +391,7 @@ const NostoSearch = ({
337
391
  useEffect(() => {
338
392
  if (clientScriptLoaded && pageTypeUpdated) {
339
393
  window.nostojs((api) => {
340
- api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewSearch(query).setPlacements(api.placements.getPlacements()).load().then((data) => {
394
+ api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewSearch(query).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
341
395
  renderCampaigns(data, api);
342
396
  });
343
397
  });
@@ -358,31 +412,35 @@ const NostoSearch = ({
358
412
  children: query
359
413
  })]
360
414
  });
361
- };
362
- var snakeize = function walk(obj) {
363
- if (!obj || typeof obj !== "object")
415
+ }
416
+ function snakeize(obj) {
417
+ if (!obj || typeof obj !== "object") {
364
418
  return obj;
365
- if (isDate(obj) || isRegex(obj))
419
+ }
420
+ if (isDate(obj) || isRegex(obj)) {
366
421
  return obj;
367
- if (Array.isArray(obj))
368
- return obj.map(walk);
369
- return Object.keys(obj).reduce(function(acc, key) {
370
- var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, function(m2, x) {
422
+ }
423
+ if (Array.isArray(obj)) {
424
+ return obj.map(snakeize);
425
+ }
426
+ return Object.keys(obj).reduce((acc, key) => {
427
+ var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, (_, x) => {
371
428
  return "_" + x.toLowerCase();
372
429
  });
373
- acc[camel] = walk(obj[key]);
430
+ acc[camel] = snakeize(obj[key]);
374
431
  return acc;
375
432
  }, {});
376
- };
377
- var isDate = function(obj) {
433
+ }
434
+ function isDate(obj) {
378
435
  return Object.prototype.toString.call(obj) === "[object Date]";
379
- };
380
- var isRegex = function(obj) {
436
+ }
437
+ function isRegex(obj) {
381
438
  return Object.prototype.toString.call(obj) === "[object RegExp]";
382
- };
383
- const NostoOrder = ({
384
- order
385
- }) => {
439
+ }
440
+ function NostoOrder(props) {
441
+ const {
442
+ order
443
+ } = props;
386
444
  const {
387
445
  clientScriptLoaded,
388
446
  currentVariation,
@@ -397,7 +455,7 @@ const NostoOrder = ({
397
455
  useEffect(() => {
398
456
  if (clientScriptLoaded && pageTypeUpdated) {
399
457
  window.nostojs((api) => {
400
- api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).addOrder(snakeize(order)).setPlacements(api.placements.getPlacements()).load().then((data) => {
458
+ api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).addOrder(snakeize(order)).setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
401
459
  renderCampaigns(data, api);
402
460
  });
403
461
  });
@@ -418,8 +476,8 @@ const NostoOrder = ({
418
476
  children: order.purchase.number
419
477
  })]
420
478
  });
421
- };
422
- const NostoHome = () => {
479
+ }
480
+ function NostoHome(props) {
423
481
  const {
424
482
  clientScriptLoaded,
425
483
  currentVariation,
@@ -434,7 +492,7 @@ const NostoHome = () => {
434
492
  useEffect(() => {
435
493
  if (clientScriptLoaded && pageTypeUpdated) {
436
494
  window.nostojs((api) => {
437
- api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewFrontPage().setPlacements(api.placements.getPlacements()).load().then((data) => {
495
+ api.defaultSession().setVariation(currentVariation).setResponseMode(responseMode).viewFrontPage().setPlacements(props.placements || api.placements.getPlacements()).load().then((data) => {
438
496
  renderCampaigns(data, api);
439
497
  });
440
498
  });
@@ -449,31 +507,34 @@ const NostoHome = () => {
449
507
  children: "front"
450
508
  })
451
509
  });
452
- };
453
- const NostoPlacement = ({
454
- id,
455
- pageType
456
- }) => {
510
+ }
511
+ function NostoPlacement(props) {
512
+ const {
513
+ id,
514
+ pageType
515
+ } = props;
457
516
  return /* @__PURE__ */ jsx("div", {
458
517
  className: "nosto_element",
459
518
  id
460
- }, id + pageType);
461
- };
462
- const NostoProvider = ({
463
- account,
464
- currentVariation = "",
465
- multiCurrency = false,
466
- host,
467
- children,
468
- recommendationComponent
469
- }) => {
470
- const [clientScriptLoadedState, setClientScriptLoadedState] = React__default.useState(false);
471
- const clientScriptLoaded = React__default.useMemo(() => clientScriptLoadedState, [clientScriptLoadedState]);
519
+ }, id + (pageType || ""));
520
+ }
521
+ function NostoProvider(props) {
522
+ let {
523
+ account,
524
+ currentVariation = "",
525
+ multiCurrency = false,
526
+ host,
527
+ children,
528
+ recommendationComponent,
529
+ shopifyMarkets
530
+ } = props;
531
+ const [clientScriptLoadedState, setClientScriptLoadedState] = React.useState(false);
532
+ const clientScriptLoaded = React.useMemo(() => clientScriptLoadedState, [clientScriptLoadedState]);
472
533
  currentVariation = multiCurrency ? currentVariation : "";
473
534
  const responseMode = isValidElement(recommendationComponent) ? "JSON_ORIGINAL" : "HTML";
474
- function RecommendationComponentWrapper(props) {
475
- return React__default.cloneElement(recommendationComponent, {
476
- nostoRecommendation: props.nostoRecommendation
535
+ function RecommendationComponentWrapper(props2) {
536
+ return React.cloneElement(recommendationComponent, {
537
+ nostoRecommendation: props2.nostoRecommendation
477
538
  });
478
539
  }
479
540
  const [pageType, setPageType] = useState("");
@@ -511,21 +572,59 @@ const NostoProvider = ({
511
572
  };
512
573
  };
513
574
  useEffect(() => {
514
- if (!document.querySelectorAll("[nosto-client-script]").length) {
575
+ var _a, _b, _c;
576
+ if (!window.nostojs) {
577
+ window.nostojs = (cb) => {
578
+ (window.nostojs.q = window.nostojs.q || []).push(cb);
579
+ };
580
+ window.nostojs((api) => api.setAutoLoad(false));
581
+ }
582
+ if (!document.querySelectorAll("[nosto-client-script]").length && !shopifyMarkets) {
515
583
  const script = document.createElement("script");
516
584
  script.type = "text/javascript";
517
585
  script.src = "//" + (host || "connect.nosto.com") + "/include/" + account;
518
586
  script.async = true;
519
587
  script.setAttribute("nosto-client-script", "");
520
588
  script.onload = () => {
521
- console.log("Nosto client script loaded");
589
+ var _a2;
590
+ if (typeof jest !== "undefined") {
591
+ (_a2 = window.nosto) == null ? void 0 : _a2.reload({
592
+ site: "localhost"
593
+ });
594
+ }
522
595
  setClientScriptLoadedState(true);
523
596
  };
524
- document.head.appendChild(script);
597
+ document.body.appendChild(script);
598
+ }
599
+ if (!!shopifyMarkets) {
600
+ const existingScript = document.querySelector("[nosto-client-script]");
601
+ const nostoSandbox = document.querySelector("#nosto-sandbox");
602
+ if (!existingScript || (existingScript == null ? void 0 : existingScript.getAttribute("nosto-language")) != (shopifyMarkets == null ? void 0 : shopifyMarkets.language) || (existingScript == null ? void 0 : existingScript.getAttribute("nosto-market-id")) != (shopifyMarkets == null ? void 0 : shopifyMarkets.marketId)) {
603
+ if (clientScriptLoadedState) {
604
+ setClientScriptLoadedState(false);
605
+ }
606
+ (_a = existingScript == null ? void 0 : existingScript.parentNode) == null ? void 0 : _a.removeChild(existingScript);
607
+ (_b = nostoSandbox == null ? void 0 : nostoSandbox.parentNode) == null ? void 0 : _b.removeChild(nostoSandbox);
608
+ const script = document.createElement("script");
609
+ script.type = "text/javascript";
610
+ script.src = "//" + (host || "connect.nosto.com") + `/script/shopify/market/nosto.js?merchant=${account}&market=${shopifyMarkets.marketId || ""}&locale=${((_c = shopifyMarkets == null ? void 0 : shopifyMarkets.language) == null ? void 0 : _c.toLowerCase()) || ""}`;
611
+ script.async = true;
612
+ script.setAttribute("nosto-client-script", "");
613
+ script.setAttribute("nosto-language", (shopifyMarkets == null ? void 0 : shopifyMarkets.language) || "");
614
+ script.setAttribute("nosto-market-id", String(shopifyMarkets == null ? void 0 : shopifyMarkets.marketId));
615
+ script.onload = () => {
616
+ var _a2;
617
+ if (typeof jest !== "undefined") {
618
+ (_a2 = window.nosto) == null ? void 0 : _a2.reload({
619
+ site: "localhost"
620
+ });
621
+ }
622
+ setClientScriptLoadedState(true);
623
+ };
624
+ document.body.appendChild(script);
625
+ }
525
626
  }
526
- window.nostojs = (cb) => (window.nostojs.q = window.nostojs.q || []).push(cb);
527
- window.nostojs((api) => api.setAutoLoad(false));
528
- }, []);
627
+ }, [clientScriptLoadedState, shopifyMarkets]);
529
628
  return /* @__PURE__ */ jsx(NostoContext.Provider, {
530
629
  value: {
531
630
  account,
@@ -538,111 +637,12 @@ const NostoProvider = ({
538
637
  },
539
638
  children
540
639
  });
541
- };
542
- var has = Object.prototype.hasOwnProperty;
543
- function find(iter, tar, key) {
544
- for (key of iter.keys()) {
545
- if (dequal(key, tar))
546
- return key;
547
- }
548
- }
549
- function dequal(foo, bar) {
550
- var ctor, len, tmp;
551
- if (foo === bar)
552
- return true;
553
- if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
554
- if (ctor === Date)
555
- return foo.getTime() === bar.getTime();
556
- if (ctor === RegExp)
557
- return foo.toString() === bar.toString();
558
- if (ctor === Array) {
559
- if ((len = foo.length) === bar.length) {
560
- while (len-- && dequal(foo[len], bar[len]))
561
- ;
562
- }
563
- return len === -1;
564
- }
565
- if (ctor === Set) {
566
- if (foo.size !== bar.size) {
567
- return false;
568
- }
569
- for (len of foo) {
570
- tmp = len;
571
- if (tmp && typeof tmp === "object") {
572
- tmp = find(bar, tmp);
573
- if (!tmp)
574
- return false;
575
- }
576
- if (!bar.has(tmp))
577
- return false;
578
- }
579
- return true;
580
- }
581
- if (ctor === Map) {
582
- if (foo.size !== bar.size) {
583
- return false;
584
- }
585
- for (len of foo) {
586
- tmp = len[0];
587
- if (tmp && typeof tmp === "object") {
588
- tmp = find(bar, tmp);
589
- if (!tmp)
590
- return false;
591
- }
592
- if (!dequal(len[1], bar.get(tmp))) {
593
- return false;
594
- }
595
- }
596
- return true;
597
- }
598
- if (ctor === ArrayBuffer) {
599
- foo = new Uint8Array(foo);
600
- bar = new Uint8Array(bar);
601
- } else if (ctor === DataView) {
602
- if ((len = foo.byteLength) === bar.byteLength) {
603
- while (len-- && foo.getInt8(len) === bar.getInt8(len))
604
- ;
605
- }
606
- return len === -1;
607
- }
608
- if (ArrayBuffer.isView(foo)) {
609
- if ((len = foo.byteLength) === bar.byteLength) {
610
- while (len-- && foo[len] === bar[len])
611
- ;
612
- }
613
- return len === -1;
614
- }
615
- if (!ctor || typeof foo === "object") {
616
- len = 0;
617
- for (ctor in foo) {
618
- if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
619
- return false;
620
- if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
621
- return false;
622
- }
623
- return Object.keys(bar).length === len;
624
- }
625
- }
626
- return foo !== foo && bar !== bar;
627
- }
628
- function useDeepCompareMemoize(value) {
629
- var ref = React.useRef(value);
630
- var signalRef = React.useRef(0);
631
- if (!dequal(value, ref.current)) {
632
- ref.current = value;
633
- signalRef.current += 1;
634
- }
635
- return React.useMemo(function() {
636
- return ref.current;
637
- }, [signalRef.current]);
638
- }
639
- function useDeepCompareEffect(callback, dependencies) {
640
- return React.useEffect(callback, useDeepCompareMemoize(dependencies));
641
640
  }
642
- const NostoSession = ({
643
- cart,
644
- customer
645
- }) => {
641
+ function NostoSession(props) {
642
+ const {
643
+ cart,
644
+ customer
645
+ } = props;
646
646
  const {
647
647
  clientScriptLoaded
648
648
  } = useNostoContext();
@@ -654,7 +654,7 @@ const NostoSession = ({
654
654
  api.defaultSession().setResponseMode("HTML").setCart(currentCart).setCustomer(currentCustomer).viewOther().load();
655
655
  });
656
656
  }
657
- }, [clientScriptLoaded, cart || [], customer || {}]);
657
+ }, [clientScriptLoaded, cart, customer]);
658
658
  return /* @__PURE__ */ jsx(Fragment, {});
659
- };
660
- export { NostoFohofo as Nosto404, NostoCategory, NostoCheckout, NostoContext, NostoHome, NostoOrder, NostoOther, NostoPlacement, NostoProduct, NostoProvider, NostoSearch, NostoSession, useNostoContext };
659
+ }
660
+ export { Nosto404, NostoCategory, NostoCheckout, NostoContext, NostoHome, NostoOrder, NostoOther, NostoPlacement, NostoProduct, NostoProvider, NostoSearch, NostoSession, useNostoContext };
@@ -1,4 +1,4 @@
1
- (function(m,p){typeof exports=="object"&&typeof module!="undefined"?p(exports,require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client"],p):(m=typeof globalThis!="undefined"?globalThis:m||self,p(m["@nosto/nosto-react"]={},m.React,m.ReactDOM))})(this,function(m,p,A){"use strict";function D(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}function I(t){if(t&&t.__esModule)return t;var e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return t&&Object.keys(t).forEach(function(r){if(r!=="default"){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}}),e.default=t,Object.freeze(e)}var w=D(p),S=I(p);const O=p.createContext({account:void 0,currentVariation:"",renderFunction:void 0});function h(){const t=p.useContext(O);if(!t)throw new Error("No nosto context found");return t}var P={exports:{}},j={};/**
1
+ (function(f,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client"],u):(f=typeof globalThis!="undefined"?globalThis:f||self,u(f["@nosto/nosto-react"]={},f.React,f.ReactDOM))})(this,function(f,u,x){"use strict";function D(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var R=D(u);const V=u.createContext({account:"",currentVariation:"",pageType:"",responseMode:"HTML",clientScriptLoaded:!1,useRenderCampaigns:()=>{}});function h(){const t=u.useContext(V);if(!t)throw new Error("No nosto context found");return t}var E={exports:{}},b={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var b=w.default,z=Symbol.for("react.element"),q=Symbol.for("react.fragment"),H=Object.prototype.hasOwnProperty,B=b.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function E(t,e,r){var n,c={},a=null,d=null;r!==void 0&&(a=""+r),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(d=e.ref);for(n in e)H.call(e,n)&&!G.hasOwnProperty(n)&&(c[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)c[n]===void 0&&(c[n]=e[n]);return{$$typeof:z,type:t,key:a,ref:d,props:c,_owner:B.current}}j.Fragment=q,j.jsx=E,j.jsxs=E,P.exports=j;const o=P.exports.jsx,_=P.exports.jsxs,y=P.exports.Fragment,J=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("404");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewNotFound().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})},W=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("other");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewOther().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})},$=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("checkout");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewCart().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})})},Y=({product:t,tagging:e})=>{const{clientScriptLoaded:r,currentVariation:n,responseMode:c,recommendationComponent:a,useRenderCampaigns:d}=h(),{renderCampaigns:l,pageTypeUpdated:i}=d("product");return p.useEffect(()=>{r&&i&&window.nostojs(s=>{s.defaultSession().setResponseMode(c).viewProduct(t).setPlacements(s.placements.getPlacements()).load().then(u=>{l(u,s)})},[r,n,t,a,i])}),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"product"}),_("div",{className:"nosto_product",style:{display:"none"},children:[(e==null?void 0:e.variationId)&&o("span",{className:"variation_id",children:e.variationId}),t&&o("span",{className:"product_id",children:t}),(e==null?void 0:e.name)&&o("span",{className:"name",children:e.name}),(e==null?void 0:e.url)&&o("span",{className:"url",children:e.url.toString()}),(e==null?void 0:e.imageUrl)&&o("span",{className:"image_url",children:e.imageUrl.toString()}),(e==null?void 0:e.availability)&&o("span",{className:"availability",children:e.availability}),(e==null?void 0:e.price)&&o("span",{className:"price",children:e.price}),(e==null?void 0:e.listPrice)&&o("span",{className:"list_price",children:e.listPrice}),(e==null?void 0:e.priceCurrencyCode)&&o("span",{className:"price_currency_code",children:e.priceCurrencyCode}),(e==null?void 0:e.brand)&&o("span",{className:"brand",children:e.brand}),(e==null?void 0:e.description)&&o("span",{className:"description",children:e.description}),(e==null?void 0:e.googleCategory)&&o("span",{className:"description",children:e.googleCategory}),(e==null?void 0:e.condition)&&o("span",{className:"condition",children:e.condition}),(e==null?void 0:e.gender)&&o("span",{className:"gender",children:e.gender}),(e==null?void 0:e.ageGroup)&&o("span",{className:"age_group",children:e.ageGroup}),(e==null?void 0:e.gtin)&&o("span",{className:"gtin",children:e.gtin}),(e==null?void 0:e.category)&&(e==null?void 0:e.category.map((s,u)=>o("span",{className:"category",children:s},u))),(e==null?void 0:e.tags1)&&e.tags1.map((s,u)=>o("span",{className:"tag1",children:s},u)),(e==null?void 0:e.tags2)&&e.tags2.map((s,u)=>o("span",{className:"tag2",children:s},u)),(e==null?void 0:e.tags3)&&e.tags3.map((s,u)=>o("span",{className:"tag3",children:s},u)),(e==null?void 0:e.ratingValue)&&o("span",{className:"rating_value",children:e.ratingValue}),(e==null?void 0:e.reviewCount)&&o("span",{className:"review_count",children:e.reviewCount}),(e==null?void 0:e.alternateImageUrls)&&e.alternateImageUrls.map((s,u)=>o("span",{className:"alternate_image_url",children:s.toString()},u)),(e==null?void 0:e.customFields)&&Object.keys(e.customFields).map((s,u)=>e.customFields&&e.customFields[s]&&o("span",{className:s,children:e.customFields[s]},u)),(e==null?void 0:e.skus)&&e.skus.map((s,u)=>_("span",{className:"nosto_sku",children:[(s==null?void 0:s.id)&&o("span",{className:"product_id",children:s.id}),(s==null?void 0:s.name)&&o("span",{className:"name",children:s.name}),(s==null?void 0:s.price)&&o("span",{className:"price",children:s.price}),(s==null?void 0:s.listPrice)&&o("span",{className:"list_price",children:s.listPrice}),(s==null?void 0:s.url)&&o("span",{className:"url",children:s.url.toString()}),(s==null?void 0:s.imageUrl)&&o("span",{className:"image_url",children:s.imageUrl.toString()}),(s==null?void 0:s.gtin)&&o("span",{className:"gtin",children:s.gtin}),(s==null?void 0:s.availability)&&o("span",{className:"availability",children:s.availability}),(s==null?void 0:s.customFields)&&Object.keys(s.customFields).map((N,L)=>s.customFields&&s.customFields[N]&&o("span",{className:N,children:s.customFields[N]},L))]},u))]})]})},Z=({category:t})=>{const{clientScriptLoaded:e,currentVariation:r,responseMode:n,recommendationComponent:c,useRenderCampaigns:a}=h(),{renderCampaigns:d,pageTypeUpdated:l}=a("home");return p.useEffect(()=>{e&&l&&window.nostojs(i=>{i.defaultSession().setVariation(r).setResponseMode(n).viewCategory(t).setPlacements(i.placements.getPlacements()).load().then(s=>{d(s,i)})})},[e,t,r,c,l]),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"category"}),o("div",{className:"nosto_category",style:{display:"none"},children:t})]})},K=({query:t})=>{const{clientScriptLoaded:e,currentVariation:r,responseMode:n,recommendationComponent:c,useRenderCampaigns:a}=h(),{renderCampaigns:d,pageTypeUpdated:l}=a("search");return p.useEffect(()=>{e&&l&&window.nostojs(i=>{i.defaultSession().setVariation(r).setResponseMode(n).viewSearch(t).setPlacements(i.placements.getPlacements()).load().then(s=>{d(s,i)})})},[e,r,t,c,l]),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"search"}),o("div",{className:"nosto_search",style:{display:"none"},children:t})]})};var M=function t(e){return!e||typeof e!="object"||Q(e)||X(e)?e:Array.isArray(e)?e.map(t):Object.keys(e).reduce(function(r,n){var c=n[0].toLowerCase()+n.slice(1).replace(/([A-Z]+)/g,function(a,d){return"_"+d.toLowerCase()});return r[c]=t(e[n]),r},{})},Q=function(t){return Object.prototype.toString.call(t)==="[object Date]"},X=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"};const k=({order:t})=>{const{clientScriptLoaded:e,currentVariation:r,responseMode:n,recommendationComponent:c,useRenderCampaigns:a}=h(),{renderCampaigns:d,pageTypeUpdated:l}=a("order");return p.useEffect(()=>{e&&l&&window.nostojs(i=>{i.defaultSession().setVariation(r).setResponseMode(n).addOrder(M(t)).setPlacements(i.placements.getPlacements()).load().then(s=>{d(s,i)})})},[e,r,c,l]),_(y,{children:[o("div",{className:"nosto_page_type",style:{display:"none"},children:"order"}),o("div",{className:"nosto_order",style:{display:"none"},children:t.purchase.number})]})},g=()=>{const{clientScriptLoaded:t,currentVariation:e,responseMode:r,recommendationComponent:n,useRenderCampaigns:c}=h(),{renderCampaigns:a,pageTypeUpdated:d}=c("home");return p.useEffect(()=>{t&&d&&window.nostojs(l=>{l.defaultSession().setVariation(e).setResponseMode(r).viewFrontPage().setPlacements(l.placements.getPlacements()).load().then(i=>{a(i,l)})})},[t,e,n,d]),o(y,{children:o("div",{className:"nosto_page_type",style:{display:"none"},children:"front"})})},ee=({id:t,pageType:e})=>o("div",{className:"nosto_element",id:t},t+e),te=({account:t,currentVariation:e="",multiCurrency:r=!1,host:n,children:c,recommendationComponent:a})=>{const[d,l]=w.default.useState(!1),i=w.default.useMemo(()=>d,[d]);e=r?e:"";const s=p.isValidElement(a)?"JSON_ORIGINAL":"HTML";function u(f){return w.default.cloneElement(a,{nostoRecommendation:f.nostoRecommendation})}const[N,L]=p.useState(""),oe=function(f=""){const R=p.useRef({});p.useEffect(()=>{N!=f&&L(f)},[]);const ce=f==N;function le(V,de){if(s=="HTML")de.placements.injectCampaigns(V.recommendations);else{const F=V.campaigns.recommendations;for(const C in F){let ae=F[C],ie="#"+C,x=()=>document.querySelector(ie);x()&&(R.current[C]||(R.current[C]=A.createRoot(x())),R.current[C].render(o(u,{nostoRecommendation:ae})))}}}return{renderCampaigns:le,pageTypeUpdated:ce}};return p.useEffect(()=>{if(!document.querySelectorAll("[nosto-client-script]").length){const f=document.createElement("script");f.type="text/javascript",f.src="//"+(n||"connect.nosto.com")+"/include/"+t,f.async=!0,f.setAttribute("nosto-client-script",""),f.onload=()=>{console.log("Nosto client script loaded"),l(!0)},document.head.appendChild(f)}window.nostojs=f=>(window.nostojs.q=window.nostojs.q||[]).push(f),window.nostojs(f=>f.setAutoLoad(!1))},[]),o(O.Provider,{value:{account:t,clientScriptLoaded:i,currentVariation:e,responseMode:s,recommendationComponent:a,useRenderCampaigns:oe,pageType:N},children:c})};var T=Object.prototype.hasOwnProperty;function U(t,e,r){for(r of t.keys())if(v(r,e))return r}function v(t,e){var r,n,c;if(t===e)return!0;if(t&&e&&(r=t.constructor)===e.constructor){if(r===Date)return t.getTime()===e.getTime();if(r===RegExp)return t.toString()===e.toString();if(r===Array){if((n=t.length)===e.length)for(;n--&&v(t[n],e[n]););return n===-1}if(r===Set){if(t.size!==e.size)return!1;for(n of t)if(c=n,c&&typeof c=="object"&&(c=U(e,c),!c)||!e.has(c))return!1;return!0}if(r===Map){if(t.size!==e.size)return!1;for(n of t)if(c=n[0],c&&typeof c=="object"&&(c=U(e,c),!c)||!v(n[1],e.get(c)))return!1;return!0}if(r===ArrayBuffer)t=new Uint8Array(t),e=new Uint8Array(e);else if(r===DataView){if((n=t.byteLength)===e.byteLength)for(;n--&&t.getInt8(n)===e.getInt8(n););return n===-1}if(ArrayBuffer.isView(t)){if((n=t.byteLength)===e.byteLength)for(;n--&&t[n]===e[n];);return n===-1}if(!r||typeof t=="object"){n=0;for(r in t)if(T.call(t,r)&&++n&&!T.call(e,r)||!(r in e)||!v(t[r],e[r]))return!1;return Object.keys(e).length===n}}return t!==t&&e!==e}function se(t){var e=S.useRef(t),r=S.useRef(0);return v(t,e.current)||(e.current=t,r.current+=1),S.useMemo(function(){return e.current},[r.current])}function ne(t,e){return S.useEffect(t,se(e))}const re=({cart:t,customer:e})=>{const{clientScriptLoaded:r}=h();return ne(()=>{const n=t?M(t):void 0,c=e?M(e):void 0;r&&window.nostojs(a=>{a.defaultSession().setResponseMode("HTML").setCart(n).setCustomer(c).viewOther().load()})},[r,t||[],e||{}]),o(y,{})};m.Nosto404=J,m.NostoCategory=Z,m.NostoCheckout=$,m.NostoContext=O,m.NostoHome=g,m.NostoOrder=k,m.NostoOther=W,m.NostoPlacement=ee,m.NostoProduct=Y,m.NostoProvider=te,m.NostoSearch=K,m.NostoSession=re,m.useNostoContext=h,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
9
+ */var H=R.default,$=Symbol.for("react.element"),G=Symbol.for("react.fragment"),z=Object.prototype.hasOwnProperty,J=H.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,W={key:!0,ref:!0,__self:!0,__source:!0};function A(t,n,e){var r,i={},l=null,m=null;e!==void 0&&(l=""+e),n.key!==void 0&&(l=""+n.key),n.ref!==void 0&&(m=n.ref);for(r in n)z.call(n,r)&&!W.hasOwnProperty(r)&&(i[r]=n[r]);if(t&&t.defaultProps)for(r in n=t.defaultProps,n)i[r]===void 0&&(i[r]=n[r]);return{$$typeof:$,type:t,key:l,ref:m,props:i,_owner:J.current}}b.Fragment=G,b.jsx=A,b.jsxs=A,E.exports=b;const s=E.exports.jsx,w=E.exports.jsxs,_=E.exports.Fragment;function B(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("404");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewNotFound().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"notfound"})})}function Y(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("other");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewOther().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"other"})})}function Z(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("checkout");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewCart().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"cart"})})}function F(t){const n=i=>String(i)==="[object Object]";if(!n(t))return!1;const e=t.constructor;if(e===void 0)return!0;const r=e.prototype;return!(!n(r)||!r.hasOwnProperty("isPrototypeOf"))}function U(t,n){if(t===n)return!0;if(t instanceof Date&&n instanceof Date)return t.getTime()===n.getTime();if(t instanceof Array&&n instanceof Array)return t.length!==n.length?!1:t.every((e,r)=>U(e,n[r]));if(F(t)&&F(n)){const e=Object.entries(t);return e.length!==Object.keys(n).length?!1:e.every(([r,i])=>U(i,n[r]))}return!1}function I(t,n){return u.useEffect(t,K(n))}function K(t){const n=u.useRef(t),e=u.useRef(0);return U(t,n.current)||(n.current=t,e.current+=1),u.useMemo(()=>n.current,[e.current])}function Q(t){const{product:n,tagging:e}=t,{clientScriptLoaded:r,currentVariation:i,responseMode:l,recommendationComponent:m,useRenderCampaigns:a}=h(),{renderCampaigns:c,pageTypeUpdated:d}=a("product");return I(()=>{r&&d&&window.nostojs(o=>{o.defaultSession().setResponseMode(l).viewProduct(n).setPlacements(t.placements||o.placements.getPlacements()).load().then(y=>{c(y,o)})})},[r,i,n,m,d]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"product"}),w("div",{className:"nosto_product",style:{display:"none"},children:[(e==null?void 0:e.variationId)&&s("span",{className:"variation_id",children:e.variationId}),n&&s("span",{className:"product_id",children:n}),(e==null?void 0:e.name)&&s("span",{className:"name",children:e.name}),(e==null?void 0:e.url)&&s("span",{className:"url",children:e.url.toString()}),(e==null?void 0:e.imageUrl)&&s("span",{className:"image_url",children:e.imageUrl.toString()}),(e==null?void 0:e.availability)&&s("span",{className:"availability",children:e.availability}),(e==null?void 0:e.price)&&s("span",{className:"price",children:e.price}),(e==null?void 0:e.listPrice)&&s("span",{className:"list_price",children:e.listPrice}),(e==null?void 0:e.priceCurrencyCode)&&s("span",{className:"price_currency_code",children:e.priceCurrencyCode}),(e==null?void 0:e.brand)&&s("span",{className:"brand",children:e.brand}),(e==null?void 0:e.description)&&s("span",{className:"description",children:e.description}),(e==null?void 0:e.googleCategory)&&s("span",{className:"description",children:e.googleCategory}),(e==null?void 0:e.condition)&&s("span",{className:"condition",children:e.condition}),(e==null?void 0:e.gender)&&s("span",{className:"gender",children:e.gender}),(e==null?void 0:e.ageGroup)&&s("span",{className:"age_group",children:e.ageGroup}),(e==null?void 0:e.gtin)&&s("span",{className:"gtin",children:e.gtin}),(e==null?void 0:e.category)&&(e==null?void 0:e.category.map((o,y)=>s("span",{className:"category",children:o},y))),(e==null?void 0:e.tags1)&&e.tags1.map((o,y)=>s("span",{className:"tag1",children:o},y)),(e==null?void 0:e.tags2)&&e.tags2.map((o,y)=>s("span",{className:"tag2",children:o},y)),(e==null?void 0:e.tags3)&&e.tags3.map((o,y)=>s("span",{className:"tag3",children:o},y)),(e==null?void 0:e.ratingValue)&&s("span",{className:"rating_value",children:e.ratingValue}),(e==null?void 0:e.reviewCount)&&s("span",{className:"review_count",children:e.reviewCount}),(e==null?void 0:e.alternateImageUrls)&&e.alternateImageUrls.map((o,y)=>s("span",{className:"alternate_image_url",children:o.toString()},y)),(e==null?void 0:e.customFields)&&Object.keys(e.customFields).map((o,y)=>e.customFields&&e.customFields[o]&&s("span",{className:o,children:e.customFields[o]},y)),(e==null?void 0:e.skus)&&e.skus.map((o,y)=>w("span",{className:"nosto_sku",children:[(o==null?void 0:o.id)&&s("span",{className:"product_id",children:o.id}),(o==null?void 0:o.name)&&s("span",{className:"name",children:o.name}),(o==null?void 0:o.price)&&s("span",{className:"price",children:o.price}),(o==null?void 0:o.listPrice)&&s("span",{className:"list_price",children:o.listPrice}),(o==null?void 0:o.url)&&s("span",{className:"url",children:o.url.toString()}),(o==null?void 0:o.imageUrl)&&s("span",{className:"image_url",children:o.imageUrl.toString()}),(o==null?void 0:o.gtin)&&s("span",{className:"gtin",children:o.gtin}),(o==null?void 0:o.availability)&&s("span",{className:"availability",children:o.availability}),(o==null?void 0:o.customFields)&&Object.keys(o.customFields).map((j,O)=>o.customFields&&o.customFields[j]&&s("span",{className:j,children:o.customFields[j]},O))]},y))]})]})}function X(t){const{category:n}=t,{clientScriptLoaded:e,currentVariation:r,responseMode:i,recommendationComponent:l,useRenderCampaigns:m}=h(),{renderCampaigns:a,pageTypeUpdated:c}=m("home");return u.useEffect(()=>{e&&c&&window.nostojs(d=>{d.defaultSession().setVariation(r).setResponseMode(i).viewCategory(n).setPlacements(t.placements||d.placements.getPlacements()).load().then(o=>{a(o,d)})})},[e,n,r,l,c]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"category"}),s("div",{className:"nosto_category",style:{display:"none"},children:n})]})}function g(t){const{query:n}=t,{clientScriptLoaded:e,currentVariation:r,responseMode:i,recommendationComponent:l,useRenderCampaigns:m}=h(),{renderCampaigns:a,pageTypeUpdated:c}=m("search");return u.useEffect(()=>{e&&c&&window.nostojs(d=>{d.defaultSession().setVariation(r).setResponseMode(i).viewSearch(n).setPlacements(t.placements||d.placements.getPlacements()).load().then(o=>{a(o,d)})})},[e,r,n,l,c]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"search"}),s("div",{className:"nosto_search",style:{display:"none"},children:n})]})}function P(t){return!t||typeof t!="object"||k(t)||ee(t)?t:Array.isArray(t)?t.map(P):Object.keys(t).reduce((n,e)=>{var r=e[0].toLowerCase()+e.slice(1).replace(/([A-Z]+)/g,(i,l)=>"_"+l.toLowerCase());return n[r]=P(t[e]),n},{})}function k(t){return Object.prototype.toString.call(t)==="[object Date]"}function ee(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function te(t){const{order:n}=t,{clientScriptLoaded:e,currentVariation:r,responseMode:i,recommendationComponent:l,useRenderCampaigns:m}=h(),{renderCampaigns:a,pageTypeUpdated:c}=m("order");return u.useEffect(()=>{e&&c&&window.nostojs(d=>{d.defaultSession().setVariation(r).setResponseMode(i).addOrder(P(n)).setPlacements(t.placements||d.placements.getPlacements()).load().then(o=>{a(o,d)})})},[e,r,l,c]),w(_,{children:[s("div",{className:"nosto_page_type",style:{display:"none"},children:"order"}),s("div",{className:"nosto_order",style:{display:"none"},children:n.purchase.number})]})}function ne(t){const{clientScriptLoaded:n,currentVariation:e,responseMode:r,recommendationComponent:i,useRenderCampaigns:l}=h(),{renderCampaigns:m,pageTypeUpdated:a}=l("home");return u.useEffect(()=>{n&&a&&window.nostojs(c=>{c.defaultSession().setVariation(e).setResponseMode(r).viewFrontPage().setPlacements(t.placements||c.placements.getPlacements()).load().then(d=>{m(d,c)})})},[n,e,i,a]),s(_,{children:s("div",{className:"nosto_page_type",style:{display:"none"},children:"front"})})}function oe(t){const{id:n,pageType:e}=t;return s("div",{className:"nosto_element",id:n},n+(e||""))}function se(t){let{account:n,currentVariation:e="",multiCurrency:r=!1,host:i,children:l,recommendationComponent:m,shopifyMarkets:a}=t;const[c,d]=R.default.useState(!1),o=R.default.useMemo(()=>c,[c]);e=r?e:"";const y=u.isValidElement(m)?"JSON_ORIGINAL":"HTML";function j(v){return R.default.cloneElement(m,{nostoRecommendation:v.nostoRecommendation})}const[O,ae]=u.useState(""),ce=function(v=""){const S=u.useRef({});u.useEffect(()=>{O!=v&&ae(v)},[]);const M=v==O;function p(N,C){if(y=="HTML")C.placements.injectCampaigns(N.recommendations);else{const L=N.campaigns.recommendations;for(const T in L){let ie=L[T],de="#"+T,q=()=>document.querySelector(de);q()&&(S.current[T]||(S.current[T]=x.createRoot(q())),S.current[T].render(s(j,{nostoRecommendation:ie})))}}}return{renderCampaigns:p,pageTypeUpdated:M}};return u.useEffect(()=>{var v,S,M;if(window.nostojs||(window.nostojs=p=>{(window.nostojs.q=window.nostojs.q||[]).push(p)},window.nostojs(p=>p.setAutoLoad(!1))),!document.querySelectorAll("[nosto-client-script]").length&&!a){const p=document.createElement("script");p.type="text/javascript",p.src="//"+(i||"connect.nosto.com")+"/include/"+n,p.async=!0,p.setAttribute("nosto-client-script",""),p.onload=()=>{var N;typeof jest!="undefined"&&((N=window.nosto)==null||N.reload({site:"localhost"})),d(!0)},document.body.appendChild(p)}if(a){const p=document.querySelector("[nosto-client-script]"),N=document.querySelector("#nosto-sandbox");if(!p||(p==null?void 0:p.getAttribute("nosto-language"))!=(a==null?void 0:a.language)||(p==null?void 0:p.getAttribute("nosto-market-id"))!=(a==null?void 0:a.marketId)){c&&d(!1),(v=p==null?void 0:p.parentNode)==null||v.removeChild(p),(S=N==null?void 0:N.parentNode)==null||S.removeChild(N);const C=document.createElement("script");C.type="text/javascript",C.src="//"+(i||"connect.nosto.com")+`/script/shopify/market/nosto.js?merchant=${n}&market=${a.marketId||""}&locale=${((M=a==null?void 0:a.language)==null?void 0:M.toLowerCase())||""}`,C.async=!0,C.setAttribute("nosto-client-script",""),C.setAttribute("nosto-language",(a==null?void 0:a.language)||""),C.setAttribute("nosto-market-id",String(a==null?void 0:a.marketId)),C.onload=()=>{var L;typeof jest!="undefined"&&((L=window.nosto)==null||L.reload({site:"localhost"})),d(!0)},document.body.appendChild(C)}}},[c,a]),s(V.Provider,{value:{account:n,clientScriptLoaded:o,currentVariation:e,responseMode:y,recommendationComponent:m,useRenderCampaigns:ce,pageType:O},children:l})}function re(t){const{cart:n,customer:e}=t,{clientScriptLoaded:r}=h();return I(()=>{const i=n?P(n):void 0,l=e?P(e):void 0;r&&window.nostojs(m=>{m.defaultSession().setResponseMode("HTML").setCart(i).setCustomer(l).viewOther().load()})},[r,n,e]),s(_,{})}f.Nosto404=B,f.NostoCategory=X,f.NostoCheckout=Z,f.NostoContext=V,f.NostoHome=ne,f.NostoOrder=te,f.NostoOther=Y,f.NostoPlacement=oe,f.NostoProduct=Q,f.NostoProvider=se,f.NostoSearch=g,f.NostoSession=re,f.useNostoContext=h,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});