@kachingappz/bundles-js 1.1.9 → 1.1.10

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.
@@ -565,27 +565,27 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
565
565
  ...k(e),
566
566
  ...A(e),
567
567
  ...j(e),
568
- ...ee(e),
569
- ...te(e),
570
568
  ...M(e),
571
- ...ne(e),
572
569
  ...N(e),
573
570
  ...P(e),
571
+ ...ee(e),
572
+ ...te(e),
573
+ ...ne(e),
574
574
  ...re(e),
575
575
  ...ie(e),
576
576
  ...ae(e)
577
- ].filter((e) => e != null && !e.includes("placeholder")), O = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), k = (e) => e.dealBars.flatMap((e) => e.dealBarType === d.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), A = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), j = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), ee = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), te = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
577
+ ].filter((e) => e != null && !e.includes("placeholder")), O = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), k = (e) => e.dealBars.flatMap((e) => e.dealBarType === d.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), A = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), j = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), M = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), N = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
578
578
  let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
579
579
  return [...e, ...n];
580
- }, []) : [], M = (e) => {
580
+ }, []) : [], P = (e) => {
581
581
  if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
582
582
  let t = e.collectionBreaks.mediaImageGID;
583
583
  return t ? [t] : [];
584
- }, ne = (e) => e.progressiveGifts ? [
584
+ }, ee = (e) => e.progressiveGifts ? [
585
585
  ...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
586
586
  e.progressiveGifts.style?.lockedMediaImageGID,
587
587
  e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
588
- ].filter((e) => e != null) : [], N = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), P = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), re = (e) => {
588
+ ].filter((e) => e != null) : [], te = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ne = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), re = (e) => {
589
589
  let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
590
590
  return n ? [...t, n] : t;
591
591
  }, ie = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), ae = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], oe = (e, { includeMixAndMatchSwapProducts: t = !0 } = {}) => {
@@ -594,43 +594,43 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
594
594
  ...ce(e),
595
595
  ...le(e),
596
596
  ...ue(e),
597
+ ...de(e),
598
+ ...fe(e, t),
597
599
  ...F(e),
598
- ...I(e, t),
599
- ...L(e),
600
- ...R(e)
600
+ ...I(e)
601
601
  ];
602
602
  return Array.from(new Set(n.filter((e) => e != null)));
603
- }, se = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), ce = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), le = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], ue = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), F = (e) => e.dealBars.filter((e) => e.dealBarType === d.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), I = (e, t) => e.dealBars.filter((e) => e.dealBarType === d.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...t ? e.selectedProducts?.map((e) => e.id) ?? [] : []]) : []).filter((e) => e != null).filter((e) => e !== "default"), L = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), R = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), z = class extends Error {
603
+ }, se = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), ce = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), le = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], ue = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), de = (e) => e.dealBars.filter((e) => e.dealBarType === d.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), fe = (e, t) => e.dealBars.filter((e) => e.dealBarType === d.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...t ? e.selectedProducts?.map((e) => e.id) ?? [] : []]) : []).filter((e) => e != null).filter((e) => e !== "default"), F = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), I = (e) => e.dealBars.filter((e) => e.dealBarType === d.Sku).flatMap(({ productGID: e }) => e ? [e] : []), L = class extends Error {
604
604
  constructor({ status: e, operationName: t, graphqlErrors: n }) {
605
605
  let r = n.length ? `: ${n.join("; ")}` : "";
606
606
  super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
607
607
  }
608
- }, B = async (e, t) => {
608
+ }, R = async (e, t) => {
609
609
  let n = await e.text();
610
610
  if (!n) throw Error("Empty graphql response");
611
611
  let r;
612
612
  try {
613
613
  r = JSON.parse(n);
614
614
  } catch (n) {
615
- throw e.ok ? n : new z({
615
+ throw e.ok ? n : new L({
616
616
  status: e.status,
617
617
  operationName: t,
618
618
  graphqlErrors: []
619
619
  });
620
620
  }
621
- if (!e.ok || r.data === null || r.data === void 0) throw new z({
621
+ if (!e.ok || r.data === null || r.data === void 0) throw new L({
622
622
  status: e.status,
623
623
  operationName: t,
624
624
  graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
625
625
  });
626
626
  return r.data;
627
- }, V = class {
627
+ }, z = class {
628
628
  constructor(e, t) {
629
629
  this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
630
630
  }
631
631
  async query(e, t) {
632
632
  let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
633
- return i && (r += `?operation_name=${i}`), B(await fetch(r, {
633
+ return i && (r += `?operation_name=${i}`), R(await fetch(r, {
634
634
  method: "POST",
635
635
  headers: {
636
636
  "Content-Type": "application/json",
@@ -642,7 +642,7 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
642
642
  })
643
643
  }), i);
644
644
  }
645
- }, H = (e, t) => {
645
+ }, B = (e, t) => {
646
646
  let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
647
647
  for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
648
648
  let i = e.filter((e) => e.blockVisibility === "selected-collections");
@@ -652,7 +652,23 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
652
652
  let o = e.filter((e) => e.blockVisibility === "all-products");
653
653
  for (let e of o) n.push(e);
654
654
  return n;
655
- }, U = async (e, t, { country: n, language: r }) => {
655
+ };
656
+ [
657
+ "primaryBackground",
658
+ "secondaryBackground",
659
+ "primaryText",
660
+ "secondaryText",
661
+ "border",
662
+ "overlay",
663
+ "primaryAccent",
664
+ "primaryAccentText",
665
+ "badgeBackground",
666
+ "badgeText",
667
+ "error"
668
+ ].map((e) => `brand_${e}`);
669
+ var V = /* @__PURE__ */ function(e) {
670
+ return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
671
+ }({}), pe = async (e, t, { country: n, language: r }) => {
656
672
  let i = t.collectionBreaks;
657
673
  if (!t.collectionBreaksEnabled || !i) return;
658
674
  let a;
@@ -677,8 +693,8 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
677
693
  productIds: a.map((e) => Number(e.split("/").pop())),
678
694
  useExternalMetafieldNamespace: !0
679
695
  }), s = i.visibility === "deal-products" && t.blockVisibility === "excluded-products";
680
- return o = o.filter((e) => e.availableForSale && (!s || H([t], e).length > 0)), o;
681
- }, de = ({ language: e, dealBlockId: t }) => {
696
+ return o = o.filter((e) => e.availableForSale && (!s || B([t], e).length > 0)), o;
697
+ }, me = ({ language: e, dealBlockId: t }) => {
682
698
  let n = {
683
699
  "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
684
700
  "system.invalid_variant": "Sorry, this is not currently available.",
@@ -705,13 +721,13 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
705
721
  "system.numbers_only": "Only numbers are allowed.",
706
722
  "system.personalisation_required_alert": "Please add personalisation for every item to continue.",
707
723
  "system.gifts_required_alert": "Please choose your free gifts"
708
- }, r = e ? fe(e) : void 0;
724
+ }, r = e ? he(e) : void 0;
709
725
  return {
710
726
  ...n,
711
727
  ...r?.system,
712
728
  ...r?.dealBlocks[t]
713
729
  };
714
- }, fe = (e) => {
730
+ }, he = (e) => {
715
731
  if (typeof document > "u") return;
716
732
  let t = document.querySelector("script#kaching-bundles-translations");
717
733
  if (!t?.textContent) return;
@@ -721,11 +737,11 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
721
737
  } catch {
722
738
  return;
723
739
  }
724
- let r = W(e);
725
- return n.find((e) => W(e.locale) === r)?.translations;
726
- }, W = (e) => e.toLowerCase().replace(/_/g, "-"), pe = "2026-07", G = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
740
+ let r = H(e);
741
+ return n.find((e) => H(e.locale) === r)?.translations;
742
+ }, H = (e) => e.toLowerCase().replace(/_/g, "-"), ge = "2026-07", U = async (e, { productId: t, dealBlockId: n, abTestVariantId: r, country: i = void 0, language: a = void 0 }) => {
727
743
  try {
728
- let o = [Number(t.split("/").pop())], s = new me(e);
744
+ let o = [Number(t.split("/").pop())], s = new xe(e);
729
745
  i ||= s.i18n?.country, a ||= s.i18n?.language;
730
746
  let l = await S(s, {
731
747
  language: a,
@@ -733,7 +749,7 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
733
749
  useExternalMetafieldNamespace: !0
734
750
  });
735
751
  s.shopifyDomain = l.shopifyDomain;
736
- let u = l.storefrontAccessToken ? new V(l.shopifyDomain, l.storefrontAccessToken) : s, [d, f] = await Promise.all([m(u, {
752
+ let u = l.storefrontAccessToken ? new z(l.shopifyDomain, l.storefrontAccessToken) : s, [d, f] = await Promise.all([m(u, {
737
753
  country: i,
738
754
  language: a,
739
755
  productIds: o,
@@ -743,50 +759,77 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
743
759
  useMetaobjects: l.featureFlags.storefront_metaobjects
744
760
  })]), p = d[0];
745
761
  if (!p) return null;
746
- let h = H(f, p), g = n ? h.filter((e) => e.id === n || e.nanoId === n) : h, _ = (r ? g.find((e) => e.abTestVariantId === r) : void 0) ?? g[0] ?? h[0];
762
+ let h = B(f, p), g = n ? h.filter((e) => e.id === n || e.nanoId === n) : h, _ = (r ? g.find((e) => e.abTestVariantId === r) : void 0) ?? g[0] ?? h[0];
747
763
  if (!_) return null;
748
- let v = D(_), [y, b, x, C] = await Promise.all([
749
- (async () => {
750
- let e = [];
751
- try {
752
- e = await E(u, {
753
- dealBlock: _,
754
- country: i,
755
- language: a
756
- });
757
- } catch (e) {
758
- console.error(e);
759
- }
760
- return m(u, {
761
- country: i,
762
- language: a,
763
- productIds: [.../* @__PURE__ */ new Set([...oe(_), ...e])],
764
- useExternalMetafieldNamespace: !0
765
- });
766
- })(),
767
- w(u, v, 300),
768
- U(u, _, {
764
+ let v = oe(_, { includeMixAndMatchSwapProducts: !1 }), y = _e(u, _, {
765
+ otherProductGIDs: v,
766
+ country: i,
767
+ language: a
768
+ }), [b, x, C] = await Promise.all([
769
+ m(u, {
769
770
  country: i,
770
- language: a
771
+ language: a,
772
+ productIds: v,
773
+ useExternalMetafieldNamespace: !0
771
774
  }),
772
- de({
775
+ w(u, D(_), 300),
776
+ me({
773
777
  language: a,
774
778
  dealBlockId: _.id
775
779
  })
776
780
  ]);
777
781
  return {
778
- product: p,
779
- dealBlock: _,
780
- config: l,
781
- otherProducts: y,
782
- mediaImages: b,
783
- collectionBreaksProducts: x ?? [],
784
- translations: C
782
+ data: {
783
+ config: l,
784
+ dealBlock: _,
785
+ product: p,
786
+ otherProducts: b,
787
+ mediaImages: x,
788
+ translations: C
789
+ },
790
+ modalProducts: y
785
791
  };
786
792
  } catch (e) {
787
793
  return console.error(e), null;
788
794
  }
789
- }, me = class {
795
+ }, _e = async (e, t, n) => {
796
+ let [r, i] = await Promise.all([ve(e, t, n), be(e, t, n)]);
797
+ return {
798
+ mixAndMatchSwapProducts: r,
799
+ collectionBreaksProducts: i
800
+ };
801
+ }, ve = async (e, t, { otherProductGIDs: n, country: r, language: i }) => {
802
+ try {
803
+ let a = [];
804
+ try {
805
+ a = await E(e, {
806
+ dealBlock: t,
807
+ country: r,
808
+ language: i
809
+ });
810
+ } catch (e) {
811
+ console.error(e);
812
+ }
813
+ let o = new Set(n), s = [.../* @__PURE__ */ new Set([...ye(t), ...a])].filter((e) => !o.has(e));
814
+ return s.length ? await m(e, {
815
+ country: r,
816
+ language: i,
817
+ productIds: s,
818
+ useExternalMetafieldNamespace: !0
819
+ }) : [];
820
+ } catch (e) {
821
+ return console.error(e), [];
822
+ }
823
+ }, ye = (e) => e.dealBars.flatMap((e) => e.dealBarType === V.MixAndMatch ? e.bundleProducts.flatMap((e) => (e.selectedProducts ?? []).map((e) => e.id)) : []), be = async (e, t, { country: n, language: r }) => {
824
+ try {
825
+ return await pe(e, t, {
826
+ country: n,
827
+ language: r
828
+ }) ?? [];
829
+ } catch (e) {
830
+ return console.error(e), [];
831
+ }
832
+ }, xe = class {
790
833
  constructor(e) {
791
834
  this.storefront = e, this.shopifyDomain = "";
792
835
  }
@@ -799,7 +842,7 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
799
842
  }
800
843
  if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
801
844
  if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
802
- let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${pe}/graphql.json`, {
845
+ let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${ge}/graphql.json`, {
803
846
  body: JSON.stringify({
804
847
  query: e,
805
848
  variables: t?.variables
@@ -829,62 +872,46 @@ var x = "app--2935586817", S = async (t, { language: n, country: r, useExternalM
829
872
  get i18n() {
830
873
  if ("i18n" in this.storefront) return this.storefront.i18n;
831
874
  }
832
- }, K = "kaching-bundles-block", q = 1e4, J = "/kaching-bundles-block.js", he = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", ge = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", Y = /* @__PURE__ */ new WeakSet(), X = async (e) => {
875
+ }, W = "kaching-bundles-block", G = 1e4, K = "/kaching-bundles-block.js", Se = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", Ce = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", q = /* @__PURE__ */ new WeakSet(), J = async (e) => {
833
876
  let t = e.document;
834
- if (!e.customElements.get(K)) {
835
- if (Y.has(t)) return Q(e, K);
836
- Y.add(t);
877
+ if (!e.customElements.get(W)) {
878
+ if (q.has(t)) return Z(e, W);
879
+ q.add(t);
837
880
  try {
838
- await ye(e);
881
+ await Te(e);
839
882
  } catch (e) {
840
- throw Y.delete(t), e;
883
+ throw q.delete(t), e;
841
884
  }
842
885
  }
843
- }, _e = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, ve = () => _e() ? he : ge, ye = async (e) => {
844
- let t = e.document, n = ve();
845
- if (t.querySelector(`script[src="${n}"]`)) return Q(e, K);
846
- let r = be(t);
847
- if (r && await Se(t, r)) return Q(e, K);
886
+ }, we = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, Y = () => we() ? Se : Ce, Te = async (e) => {
887
+ let t = e.document, n = Y();
888
+ if (t.querySelector(`script[src="${n}"]`)) return Z(e, W);
889
+ let r = Ee(t);
890
+ if (r && await Oe(t, r)) return Z(e, W);
848
891
  let i = t.createElement("script");
849
- return i.src = n, await Z(t, i), Q(e, K);
850
- }, be = (e) => {
851
- let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${J}"]`);
852
- return Array.from(t, (e) => e.href).find(xe);
853
- }, xe = (e) => {
892
+ return i.src = n, await X(t, i), Z(e, W);
893
+ }, Ee = (e) => {
894
+ let t = e.querySelectorAll(`link[rel="modulepreload"][href$="${K}"]`);
895
+ return Array.from(t, (e) => e.href).find(De);
896
+ }, De = (e) => {
854
897
  try {
855
- return new URL(e).pathname.endsWith(J);
898
+ return new URL(e).pathname.endsWith(K);
856
899
  } catch {
857
900
  return !1;
858
901
  }
859
- }, Se = async (e, t) => {
902
+ }, Oe = async (e, t) => {
860
903
  let n = e.createElement("script");
861
904
  n.type = "module", n.setAttribute("crossorigin", "anonymous"), n.src = t;
862
905
  try {
863
- return await Z(e, n), !0;
906
+ return await X(e, n), !0;
864
907
  } catch {
865
908
  return n.remove(), !1;
866
909
  }
867
- }, Z = (e, t) => new Promise((n, r) => {
910
+ }, X = (e, t) => new Promise((n, r) => {
868
911
  t.onload = () => n(), t.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), e.head.appendChild(t);
869
- }), Q = (e, t) => new Promise((n, r) => {
870
- e.customElements.get(t) ? n() : Promise.race([e.customElements.whenDefined(t), new Promise((e, n) => setTimeout(() => n(/* @__PURE__ */ Error(`Custom element "${t}" failed to register within ${q}ms`)), q))]).then(() => n()).catch(r);
871
- });
872
- [
873
- "primaryBackground",
874
- "secondaryBackground",
875
- "primaryText",
876
- "secondaryText",
877
- "border",
878
- "overlay",
879
- "primaryAccent",
880
- "primaryAccentText",
881
- "badgeBackground",
882
- "badgeText",
883
- "error"
884
- ].map((e) => `brand_${e}`);
885
- var $ = /* @__PURE__ */ function(e) {
886
- return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
887
- }({}), Ce = {
912
+ }), Z = (e, t) => new Promise((n, r) => {
913
+ e.customElements.get(t) ? n() : Promise.race([e.customElements.whenDefined(t), new Promise((e, n) => setTimeout(() => n(/* @__PURE__ */ Error(`Custom element "${t}" failed to register within ${G}ms`)), G))]).then(() => n()).catch(r);
914
+ }), Q = {
888
915
  config: {
889
916
  shopifyDomain: "",
890
917
  moneyFormat: "${{amount}}",
@@ -1134,7 +1161,7 @@ var $ = /* @__PURE__ */ function(e) {
1134
1161
  dealBars: [
1135
1162
  {
1136
1163
  id: "single",
1137
- dealBarType: $.QuantityBreak,
1164
+ dealBarType: V.QuantityBreak,
1138
1165
  quantitySelector: !1,
1139
1166
  title: "Single",
1140
1167
  subtitle: "Standard price",
@@ -1159,7 +1186,7 @@ var $ = /* @__PURE__ */ function(e) {
1159
1186
  },
1160
1187
  {
1161
1188
  id: "duo",
1162
- dealBarType: $.QuantityBreak,
1189
+ dealBarType: V.QuantityBreak,
1163
1190
  quantitySelector: !1,
1164
1191
  title: "Duo",
1165
1192
  subtitle: "You save 20%",
@@ -1184,7 +1211,7 @@ var $ = /* @__PURE__ */ function(e) {
1184
1211
  },
1185
1212
  {
1186
1213
  id: "trio",
1187
- dealBarType: $.QuantityBreak,
1214
+ dealBarType: V.QuantityBreak,
1188
1215
  quantitySelector: !1,
1189
1216
  title: "Trio",
1190
1217
  subtitle: "You save 25%",
@@ -1280,10 +1307,29 @@ var $ = /* @__PURE__ */ function(e) {
1280
1307
  isNativeBundle: !1
1281
1308
  },
1282
1309
  otherProducts: [],
1310
+ mixAndMatchSwapProducts: [],
1283
1311
  mediaImages: [],
1284
1312
  collectionBreaksProducts: [],
1285
1313
  translations: {}
1286
- }, we = class extends HTMLElement {
1314
+ }, ke = async (e, t) => {
1315
+ try {
1316
+ let n = await U(e, t);
1317
+ if (!n) return null;
1318
+ let { config: r, dealBlock: i, product: a, otherProducts: o, mediaImages: s, translations: c } = n.data, { mixAndMatchSwapProducts: l, collectionBreaksProducts: u } = await n.modalProducts;
1319
+ return {
1320
+ config: r,
1321
+ dealBlock: i,
1322
+ product: a,
1323
+ otherProducts: o,
1324
+ mixAndMatchSwapProducts: l,
1325
+ mediaImages: s,
1326
+ collectionBreaksProducts: u,
1327
+ translations: c
1328
+ };
1329
+ } catch (e) {
1330
+ return console.error(e), null;
1331
+ }
1332
+ }, Ae = class extends HTMLElement {
1287
1333
  constructor(...e) {
1288
1334
  super(...e), this.innerElement = null, this.handleItemsChanged = null, this.initializeId = 0;
1289
1335
  }
@@ -1301,13 +1347,13 @@ var $ = /* @__PURE__ */ function(e) {
1301
1347
  async initialize() {
1302
1348
  let e = ++this.initializeId;
1303
1349
  if (this.cleanup(), this.hasAttribute("demo")) {
1304
- if (await X(window), e !== this.initializeId) return;
1305
- this.renderInnerElement(Ce);
1350
+ if (await J(window), e !== this.initializeId) return;
1351
+ $(this.renderInnerElement(Q), Q);
1306
1352
  return;
1307
1353
  }
1308
1354
  let t = this.getAttribute("shop-domain"), n = this.getAttribute("storefront-token"), r = this.getAttribute("product-id");
1309
1355
  if (!t || !n || !r) return;
1310
- let [i] = await Promise.all([G({
1356
+ let [i] = await Promise.all([U({
1311
1357
  shopifyDomain: t,
1312
1358
  storefrontAccessToken: n
1313
1359
  }, {
@@ -1316,29 +1362,31 @@ var $ = /* @__PURE__ */ function(e) {
1316
1362
  abTestVariantId: this.getAttribute("ab-test-variant-id") ?? void 0,
1317
1363
  country: this.getAttribute("country")?.toUpperCase() ?? void 0,
1318
1364
  language: this.getAttribute("language")?.toUpperCase() ?? void 0
1319
- }), X(window)]);
1320
- i && e === this.initializeId && this.renderInnerElement(i);
1365
+ }), J(window)]);
1366
+ if (!i || e !== this.initializeId) return;
1367
+ let a = this.renderInnerElement(i.data), o = await i.modalProducts;
1368
+ e === this.initializeId && this.innerElement === a && $(a, o);
1321
1369
  }
1322
1370
  renderInnerElement(e) {
1323
- let { config: t, dealBlock: n, product: r, otherProducts: i, mediaImages: a, collectionBreaksProducts: o, translations: s } = e;
1324
- this.innerElement = document.createElement("kaching-bundles-block"), this.innerElement.setAttribute("deal-block-id", n.id), this.innerElement.setAttribute("config", JSON.stringify(t)), this.innerElement.setAttribute("deal-block", JSON.stringify(n)), this.innerElement.setAttribute("media-images", JSON.stringify(a ?? [])), this.innerElement.setAttribute("product", JSON.stringify(r)), this.innerElement.setAttribute("other-products", JSON.stringify(i ?? [])), this.innerElement.setAttribute("collection-breaks-products", JSON.stringify(o ?? [])), this.innerElement.setAttribute("translations", JSON.stringify(s ?? {}));
1325
- let c = this.getAttribute("selected-variant-id");
1326
- this.innerElement.setAttribute("current-variant-id", String(c ? c.split("/").pop() : r.variants[0].id)), this.hasAttribute("compact") && this.innerElement.setAttribute("compact", "");
1327
- let l = this.innerElement, u = () => {
1328
- if (this.innerElement !== l) return;
1329
- let e = l.items();
1371
+ let { config: t, dealBlock: n, product: r, otherProducts: i, mediaImages: a, translations: o } = e;
1372
+ this.innerElement = document.createElement("kaching-bundles-block"), this.innerElement.setAttribute("deal-block-id", n.id), this.innerElement.setAttribute("config", JSON.stringify(t)), this.innerElement.setAttribute("deal-block", JSON.stringify(n)), this.innerElement.setAttribute("media-images", JSON.stringify(a ?? [])), this.innerElement.setAttribute("product", JSON.stringify(r)), this.innerElement.setAttribute("other-products", JSON.stringify(i ?? [])), this.innerElement.setAttribute("translations", JSON.stringify(o ?? {}));
1373
+ let s = this.getAttribute("selected-variant-id");
1374
+ this.innerElement.setAttribute("current-variant-id", String(s ? s.split("/").pop() : r.variants[0].id)), this.hasAttribute("compact") && this.innerElement.setAttribute("compact", "");
1375
+ let c = this.innerElement, l = () => {
1376
+ if (this.innerElement !== c) return;
1377
+ let e = c.items();
1330
1378
  e && this.dispatchEvent(new CustomEvent("items-changed", {
1331
1379
  detail: { items: e },
1332
1380
  bubbles: !0
1333
1381
  }));
1334
1382
  };
1335
1383
  this.handleItemsChanged = (e) => {
1336
- e.stopPropagation(), u();
1384
+ e.stopPropagation(), l();
1337
1385
  };
1338
- let d = this.handleItemsChanged;
1339
- l.addEventListener("kaching-bundles-block-loaded", () => {
1340
- this.innerElement === l && (l.addEventListener("items-changed", d), this.dispatchEvent(new CustomEvent("loaded", { bubbles: !0 })));
1341
- }, { once: !0 }), this.appendChild(this.innerElement);
1386
+ let u = this.handleItemsChanged;
1387
+ return c.addEventListener("kaching-bundles-block-loaded", () => {
1388
+ this.innerElement === c && (c.addEventListener("items-changed", u), this.dispatchEvent(new CustomEvent("loaded", { bubbles: !0 })));
1389
+ }, { once: !0 }), this.appendChild(c), c;
1342
1390
  }
1343
1391
  cleanup() {
1344
1392
  this.handleItemsChanged && this.innerElement && (this.innerElement.removeEventListener("items-changed", this.handleItemsChanged), this.handleItemsChanged = null), this.innerElement &&= (this.innerElement.remove(), null);
@@ -1352,6 +1400,8 @@ var $ = /* @__PURE__ */ function(e) {
1352
1400
  disconnectedCallback() {
1353
1401
  this.cleanup(), this.initializeId++;
1354
1402
  }
1403
+ }, $ = (e, { mixAndMatchSwapProducts: t, collectionBreaksProducts: n }) => {
1404
+ t.length && e.setAttribute("mix-and-match-swap-products", JSON.stringify(t)), e.setAttribute("collection-breaks-products", JSON.stringify(n));
1355
1405
  };
1356
- customElements.define("kaching-bundle-component", we);
1357
- export { G as fetchKachingBundlesData };
1406
+ customElements.define("kaching-bundle-component", Ae);
1407
+ export { ke as fetchKachingBundlesData };
@@ -266,5 +266,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
266
266
  }
267
267
  }
268
268
  }
269
- `,{variables:{collectionGIDs:i}});return[...new Set(o.nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes).filter(e=>!e.variants.nodes.some(e=>e.requiresComponents)).map(e=>e.id))]},k=e=>[...A(e),...j(e),...M(e),...ee(e),...te(e),...ne(e),...re(e),...ie(e),...ae(e),...oe(e),...se(e),...ce(e),...le(e)].filter(e=>e!=null&&!e.includes(`placeholder`)),A=e=>e.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),j=e=>e.dealBars.flatMap(e=>e.dealBarType===p.Bundle?e.bundleProducts.map(e=>e.mediaImageGID):[]).filter(e=>e!=null),M=e=>e.dealBars.map(({freeGifts:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),ee=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(e=>e.mediaImageGID)).filter(e=>e!=null),te=e=>e.dealBars.map(({upsells:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),ne=e=>e.swatchOptions?e.swatchOptions.reduce((e,t)=>{let n=t.images.map(e=>e.mediaImageGID).filter(e=>e!=null);return[...e,...n]},[]):[],re=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];let t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},ie=e=>e.progressiveGifts?[...e.progressiveGifts.gifts?.map(e=>e.mediaImageGID)||[],e.progressiveGifts.style?.lockedMediaImageGID,e.progressiveGifts.dealBarStyle?.lockedMediaImageGID].filter(e=>e!=null):[],ae=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),oe=e=>e.dealBars.map(e=>e.productPersonalisation?.mediaImageGID).filter(e=>e!=null),se=e=>{let t=e.dealBars.map(e=>e.highlights?.customIconGID).filter(e=>e!=null),n=e.subscriptions?.highlights?.customIconGID;return n?[...t,n]:t},ce=e=>(e.badges||[]).flatMap(e=>e.badgeType===`custom`&&e.imageGID?[e.imageGID]:[]),le=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],ue=(e,{includeMixAndMatchSwapProducts:t=!0}={})=>{let n=[...de(e),...N(e),...P(e),...F(e),...I(e),...L(e,t),...R(e),...z(e)];return Array.from(new Set(n.filter(e=>e!=null)))},de=e=>e.dealBars.flatMap(({freeGifts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),N=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(e=>e.products?e.products.map(e=>e.id):[]):[]).filter(e=>e!=null),P=e=>e.progressiveGiftsEnabled&&e.progressiveGifts?.gifts.map(e=>e.productGID).filter(e=>e!=null)||[],F=e=>e.dealBars.flatMap(({upsells:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),I=e=>e.dealBars.filter(e=>e.dealBarType===p.Bundle).flatMap(({bundleProducts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),L=(e,t)=>e.dealBars.filter(e=>e.dealBarType===p.MixAndMatch).flatMap(({bundleProducts:e})=>e?e.flatMap(e=>[e.productGID,...t?e.selectedProducts?.map(e=>e.id)??[]:[]]):[]).filter(e=>e!=null).filter(e=>e!=="default"),R=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),z=e=>e.dealBars.filter(e=>e.dealBarType===p.Sku).flatMap(({productGID:e})=>e?[e]:[]),B=class extends Error{constructor({status:e,operationName:t,graphqlErrors:n}){let r=n.length?`: ${n.join(`; `)}`:``;super(`Storefront API ${t??`query`} failed (HTTP ${e})${r}`),this.name=`StorefrontApiError`,this.status=e,this.operationName=t,this.graphqlErrors=n}},V=async(e,t)=>{let n=await e.text();if(!n)throw Error(`Empty graphql response`);let r;try{r=JSON.parse(n)}catch(n){throw e.ok?n:new B({status:e.status,operationName:t,graphqlErrors:[]})}if(!e.ok||r.data===null||r.data===void 0)throw new B({status:e.status,operationName:t,graphqlErrors:(r.errors??[]).map(({message:e})=>e).filter(Boolean)});return r.data},H=class{constructor(e,t){this.storefrontApiVersion=`2026-07`,this.storefrontAccessToken=t,this.shopifyDomain=e}async query(e,t){let n=t?.variables??{},r=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`,i=e.match(/query\s+(\w+)/)?.[1];return i&&(r+=`?operation_name=${i}`),V(await fetch(r,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:n})}),i)}},U=(e,t)=>{let n=[],r=e.filter(e=>e.blockVisibility===`selected-products`);for(let e of r)e.selectedProductIds.map(Number).includes(t.id)&&n.push(e);let i=e.filter(e=>e.blockVisibility===`selected-collections`);for(let e of i)t.collectionIds.some(t=>e.selectedCollectionIds.map(Number).includes(t))&&n.push(e);let a=e.filter(e=>e.blockVisibility===`excluded-products`);for(let e of a)!e.excludedProductIds.map(Number).includes(t.id)&&!(e.excludedCollectionIds||[]).some(e=>t.collectionIds.includes(e))&&n.push(e);let o=e.filter(e=>e.blockVisibility===`all-products`);for(let e of o)n.push(e);return n},fe=async(e,t,{country:n,language:r})=>{let i=t.collectionBreaks;if(!t.collectionBreaksEnabled||!i)return;let a;a=i.visibility===`deal-products`?await m(e,{country:n,language:r,blockVisibility:t.blockVisibility,excludedProductGIDs:(t.excludedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedProductGIDs:(t.selectedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedCollectionGIDs:(t.selectedCollectionIds||[]).map(e=>`gid://shopify/Collection/${e}`)}):await m(e,{country:n,language:r,blockVisibility:i.visibility,excludedProductGIDs:(i.excludedProducts||[]).map(({id:e})=>e),selectedProductGIDs:(i.selectedProducts||[]).map(({id:e})=>e),selectedCollectionGIDs:(i.selectedCollections||[]).map(({id:e})=>e)});let o=await g(e,{country:n,language:r,productIds:a.map(e=>Number(e.split(`/`).pop())),useExternalMetafieldNamespace:!0}),s=i.visibility===`deal-products`&&t.blockVisibility===`excluded-products`;return o=o.filter(e=>e.availableForSale&&(!s||U([t],e).length>0)),o},pe=({language:e,dealBlockId:t})=>{let n={"system.out_of_stock":`There's not enough items in our stock, please select smaller bundle.`,"system.invalid_variant":`Sorry, this is not currently available.`,"system.unavailable_option_value":`Unavailable`,"system.confirm":`Confirm`,"system.cancel":`Cancel`,"system.free":`FREE`,"system.search":`Search`,"system.quantity":`Quantity`,"system.subscription_plan":`Subscription plan`,"system.remove":`Remove`,"system.sort_by":`Sort by`,"system.sort_relevance":`Relevance`,"system.sort_newest_first":`Newest first`,"system.sort_price_low_to_high":`Price: Low → High`,"system.sort_price_high_to_low":`Price: High → Low`,"system.no_results_found":`No results found`,"system.no_results_description":`We can't find any item matching your search.`,"system.clear_search":`Clear search`,"system.no_products_available":`No products available`,"system.original_price":`Original price:`,"system.price":`Price:`,"system.letters_only":`Only letters are allowed.`,"system.numbers_only":`Only numbers are allowed.`,"system.personalisation_required_alert":`Please add personalisation for every item to continue.`,"system.gifts_required_alert":`Please choose your free gifts`},r=e?me(e):void 0;return{...n,...r?.system,...r?.dealBlocks[t]}},me=e=>{if(typeof document>`u`)return;let t=document.querySelector(`script#kaching-bundles-translations`);if(!t?.textContent)return;let n;try{n=JSON.parse(t.textContent)}catch{return}let r=W(e);return n.find(e=>W(e.locale)===r)?.translations},W=e=>e.toLowerCase().replace(/_/g,`-`),he=`2026-07`,ge=async(e,{productId:t,dealBlockId:n,abTestVariantId:r,country:i=void 0,language:a=void 0})=>{try{let o=[Number(t.split(`/`).pop())],s=new _e(e);i||=s.i18n?.country,a||=s.i18n?.language;let c=await w(s,{language:a,country:i,useExternalMetafieldNamespace:!0});s.shopifyDomain=c.shopifyDomain;let l=c.storefrontAccessToken?new H(c.shopifyDomain,c.storefrontAccessToken):s,[d,f]=await Promise.all([g(l,{country:i,language:a,productIds:o,useExternalMetafieldNamespace:!0}),u(l,{useExternalMetafieldNamespace:!0,useMetaobjects:c.featureFlags.storefront_metaobjects})]),p=d[0];if(!p)return null;let m=U(f,p),h=n?m.filter(e=>e.id===n||e.nanoId===n):m,_=(r?h.find(e=>e.abTestVariantId===r):void 0)??h[0]??m[0];if(!_)return null;let v=k(_),[y,b,x,S]=await Promise.all([(async()=>{let e=[];try{e=await O(l,{dealBlock:_,country:i,language:a})}catch(e){console.error(e)}return g(l,{country:i,language:a,productIds:[...new Set([...ue(_),...e])],useExternalMetafieldNamespace:!0})})(),E(l,v,300),fe(l,_,{country:i,language:a}),pe({language:a,dealBlockId:_.id})]);return{product:p,dealBlock:_,config:c,otherProducts:y,mediaImages:b,collectionBreaksProducts:x??[],translations:S}}catch(e){return console.error(e),null}},_e=class{constructor(e){this.storefront=e,this.shopifyDomain=``}async query(e,t){if(`query`in this.storefront&&`i18n`in this.storefront)return await this.storefront.query(e,t);if(`graphql`in this.storefront){let n=await this.storefront.graphql(e,t);if(n.errors?.length)throw Error(n.errors.map(e=>e.message).join(`
270
- `));return n.data}if(`request`in this.storefront)return(await this.storefront.request(e,t)).data;if(`shopifyDomain`in this.storefront&&`storefrontAccessToken`in this.storefront){let n=await fetch(`https://${this.storefront.shopifyDomain}/api/${he}/graphql.json`,{body:JSON.stringify({query:e,variables:t?.variables}),headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}{let n=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:e,variables:t?.variables}),headers:this.storefront.getPublicTokenHeaders(),method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}}get i18n(){if(`i18n`in this.storefront)return this.storefront.i18n}},ve=ge,G=`kaching-bundles-block`,K=1e4,q=`/kaching-bundles-block.js`,ye=`https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js`,be=`https://bundles-integrations.kachingappz.app/kaching-bundles-block.js`,J=new WeakSet,xe=async e=>{let t=e.document;if(!e.customElements.get(G)){if(J.has(t))return X(e,G);J.add(t);try{await we(e)}catch(e){throw J.delete(t),e}}},Se=()=>typeof window<`u`&&window.__KACHING_DEV__!==void 0,Ce=()=>Se()?ye:be,we=async e=>{let t=e.document,n=Ce();if(t.querySelector(`script[src="${n}"]`))return X(e,G);let r=Te(t);if(r&&await De(t,r))return X(e,G);let i=t.createElement(`script`);return i.src=n,await Y(t,i),X(e,G)},Te=e=>{let t=e.querySelectorAll(`link[rel="modulepreload"][href$="${q}"]`);return Array.from(t,e=>e.href).find(Ee)},Ee=e=>{try{return new URL(e).pathname.endsWith(q)}catch{return!1}},De=async(e,t)=>{let n=e.createElement(`script`);n.type=`module`,n.setAttribute(`crossorigin`,`anonymous`),n.src=t;try{return await Y(e,n),!0}catch{return n.remove(),!1}},Y=(e,t)=>new Promise((n,r)=>{t.onload=()=>n(),t.onerror=()=>r(Error(`Failed to load script`)),e.head.appendChild(t)}),X=(e,t)=>new Promise((n,r)=>{e.customElements.get(t)?n():Promise.race([e.customElements.whenDefined(t),new Promise((e,n)=>setTimeout(()=>n(Error(`Custom element "${t}" failed to register within ${K}ms`)),K))]).then(()=>n()).catch(r)});[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var Z=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),Q=`a-f\\d`,Oe=`#?[${Q}]{3}[${Q}]?`,ke=`#?[${Q}]{6}([${Q}]{2})?`,Ae=RegExp(`[^#${Q}]`,`gi`),$=RegExp(`^${Oe}$|^${ke}$`,`i`);function je(e,t={}){if(typeof e!=`string`||Ae.test(e)||!$.test(e))throw TypeError(`Expected a valid hex string`);e=e.replace(/^#/,``);let n=1;e.length===8&&(n=Number.parseInt(e.slice(6,8),16)/255,e=e.slice(0,6)),e.length===4&&(n=Number.parseInt(e.slice(3,4).repeat(2),16)/255,e=e.slice(0,3)),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]);let r=Number.parseInt(e,16),i=r>>16,a=r>>8&255,o=r&255,s=typeof t.alpha==`number`?t.alpha:n;return t.format===`array`?[i,a,o,s]:t.format===`css`?`rgb(${i} ${a} ${o}${s===1?``:` / ${Number((s*100).toFixed(2))}%`})`:{red:i,green:a,blue:o,alpha:s}}var Me=({price:e})=>({id:123,handle:`123`,url:null,availableForSale:!0,requiresSellingPlan:!1,title:``,image:null,selectedVariantId:456,collectionIds:[],options:[],sellingPlans:[],variants:[{id:456,availableForSale:!0,price:Math.round((e??10)*100),compareAtPrice:null,options:[],imageId:null,image:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50,unitPriceMeasurement:null}],metafields:{text:null,text2:null,text3:null,text4:null},isNativeBundle:!1}),Ne=()=>({shopifyDomain:``,moneyFormat:"${{amount_with_comma_separator}}",locale:`en`,liquidLocale:`en`,country:`US`,marketId:0,productId:null,storefrontAccessToken:null,includeSellingPlans:!1,includeAvailableQuantity:!1,customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,previewScratchOff:!1,currencyRate:1,defaultTranslations:{"system.out_of_stock":``,"system.invalid_variant":``,"system.unavailable_option_value":``,"system.confirm":``,"system.cancel":``,"system.free":``,"system.search":``,"system.quantity":``,"system.subscription_plan":``,"system.remove":``,"system.sort_by":``,"system.sort_relevance":``,"system.sort_newest_first":``,"system.sort_price_low_to_high":``,"system.sort_price_high_to_low":``,"system.no_results_found":``,"system.no_results_description":``,"system.clear_search":``,"system.no_products_available":``,"system.original_price":``,"system.price":``,"system.letters_only":``,"system.numbers_only":``},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null},shopCustomStyles:``,featureFlags:{}}),Pe=({color:e,cornerRadius:t})=>{let n={id:`123`,nanoId:`123`,blockName:`Bundle`,discountName:``,blockTitle:`BUNDLE & SAVE`,blockLayout:`vertical`,blockVisibility:`all-products`,marketId:null,currency:null,excludedProductIds:[],excludedCollectionIds:[],selectedProductIds:[],selectedCollectionIds:[],excludeB2bCustomers:!1,excludePos:!1,startTimestamp:175811496e4,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!1,showPricesPerItem:!1,showBothPrices:!1,useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:`.00`,updateNativePrice:!1,updateNativePriceType:`item`,skipCart:!1,showVariantsForSingleQuantity:!0,preselectedDealBarId:`1f-9`,defaultVariantsV2:[],collectionBreaksEnabled:!1,collectionBreaks:null,chooseProductModal:null,timerEnabled:!1,timer:null,subscriptionsEnabled:!1,subscriptions:null,stickyAtcEnabled:!1,stickyAtc:null,progressiveGiftsEnabled:!1,progressiveGifts:null,checkboxUpsellsEnabled:!1,checkboxUpsells:null,lowStockAlertEnabled:!1,lowStockAlert:null,dealBars:[{id:`PfFU`,dealBarType:Z.QuantityBreak,title:`1 pack`,subtitle:`Standard price`,label:``,quantity:1,discountType:`default`,discountValue:``,badgeStyle:`simple`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null},{id:`1f-9`,dealBarType:Z.QuantityBreak,title:`2 pack`,subtitle:`You save {{saved_percentage}}`,label:`SAVE {{saved_total}}`,quantity:2,discountType:`percentage`,discountValue:`15`,badgeStyle:`most-popular`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null}],badgesEnabled:!0,badges:[{id:`bdg1`,attachedTo:{type:`dealBar`,dealBarId:`1f-9`},text:`MOST POPULAR`,colors:null,badgeType:`most-popular`,size:90}],cornerRadius:t??8,spacing:1,colors:{background:{red:255,green:255,blue:255,alpha:1},selectedBackground:{red:255,green:255,blue:255,alpha:1},border:{red:0,green:0,blue:0,alpha:1},blockTitle:{red:0,green:0,blue:0,alpha:1},title:{red:0,green:0,blue:0,alpha:1},subtitle:{red:85,green:85,blue:85,alpha:1},price:{red:0,green:0,blue:0,alpha:1},fullPrice:{red:85,green:85,blue:85,alpha:1},labelBackground:{red:238,green:238,blue:238,alpha:1},label:{red:0,green:0,blue:0,alpha:1},badgeBackground:{red:255,green:17,blue:17,alpha:1},badgeText:{red:255,green:255,blue:255,alpha:1},freeGiftBackground:{red:0,green:0,blue:0,alpha:.3},freeGiftText:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedBackground:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedText:{red:255,green:255,blue:255,alpha:1},upsellBackground:{red:0,green:0,blue:0,alpha:.2},upsellText:{red:0,green:0,blue:0,alpha:1},upsellSelectedBackground:{red:0,green:0,blue:0,alpha:.2},upsellSelectedText:{red:0,green:0,blue:0,alpha:1}},fonts:{blockTitle:{size:`14`,style:`bold`},title:{size:`20`,style:`bold`},subtitle:{size:`14`,style:`regular`},label:{size:`12`,style:`regular`},freeGift:{size:`13`,style:`bold`},upsell:{size:`13`,style:`bold`},unitLabel:{size:`14`,style:`regular`}},swatchOptions:[],swatchSize:18,swatchShape:`circle`,imageSize:48,imageCornerRadius:6};return e!==void 0&&(n.colors.border={...je(e),alpha:1}),n},Fe=({data:n,selectedVariantId:r,preview:i,onLinesChange:a,targetWindow:o})=>{let s=(0,e.useRef)(null),[c,l]=(0,e.useState)(!1),u=(0,e.useRef)(!1);(0,e.useEffect)(()=>{s.current&&!c&&(async()=>{await xe(o??window),l(!0)})()},[c,o]),(0,e.useEffect)(()=>{let e=s.current;if(!c||!e)return;let t=()=>{let t=e.items().map(e=>({merchandiseId:`gid://shopify/ProductVariant/${e.id}`,quantity:e.quantity,attributes:Object.entries(e.properties).map(([e,t])=>({key:e,value:String(t)})),sellingPlanId:e.selling_plan?`gid://shopify/SellingPlan/${e.selling_plan}`:void 0}));a?.(t)};return u.current||=(typeof e.items==`function`?t():e.addEventListener(`kaching-bundles-block-loaded`,t),!0),e.addEventListener(`variants-changed`,t),()=>{e.removeEventListener(`kaching-bundles-block-loaded`,t),e.removeEventListener(`variants-changed`,t)}},[c,a]);let d=n?Le(n,r):i?Re(i):null;return Ie(()=>{let e=s.current;if(e&&d)for(let[t,n]of Object.entries(d.jsonAttributes))e.getAttribute(t)!==n&&e.setAttribute(t,n)}),d?(0,t.jsx)(`kaching-bundles-block`,{ref:s,"deal-block-id":d.dealBlockId,...d.jsonAttributes,"current-variant-id":d.currentVariantId}):null},Ie=typeof window>`u`?e.useEffect:e.useLayoutEffect,Le=({config:e,dealBlock:t,product:n,otherProducts:r,mediaImages:i,collectionBreaksProducts:a,translations:o},s)=>({dealBlockId:t.id,currentVariantId:s?s.split(`/`).pop():String(n.variants[0].id),jsonAttributes:{config:JSON.stringify(e),"deal-block":JSON.stringify(t),"media-images":JSON.stringify(i),product:JSON.stringify(n),"other-products":JSON.stringify(r),"collection-breaks-products":JSON.stringify(a),translations:JSON.stringify(o)}}),Re=({cornerRadius:e,color:t,price:n})=>{let r=Me({price:n}),i=Ne(),a=Pe({color:t,cornerRadius:e});return{dealBlockId:a.id,currentVariantId:String(r.variants[0].id),jsonAttributes:{config:JSON.stringify(i),"deal-block":JSON.stringify(a),"media-images":JSON.stringify([]),product:JSON.stringify(r),"other-products":JSON.stringify([]),"collection-breaks-products":JSON.stringify([]),translations:JSON.stringify({})}}};exports.KachingBundle=Fe,exports.fetchKachingBundlesData=ve;
269
+ `,{variables:{collectionGIDs:i}});return[...new Set(o.nodes.filter(e=>e!==null).flatMap(e=>e.products.nodes).filter(e=>!e.variants.nodes.some(e=>e.requiresComponents)).map(e=>e.id))]},k=e=>[...A(e),...j(e),...ee(e),...te(e),...ne(e),...re(e),...ie(e),...ae(e),...M(e),...oe(e),...se(e),...ce(e),...le(e)].filter(e=>e!=null&&!e.includes(`placeholder`)),A=e=>e.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),j=e=>e.dealBars.flatMap(e=>e.dealBarType===p.Bundle?e.bundleProducts.map(e=>e.mediaImageGID):[]).filter(e=>e!=null),ee=e=>e.dealBars.map(({freeGifts:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),te=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(e=>e.mediaImageGID)).filter(e=>e!=null),ne=e=>e.dealBars.map(({upsells:e})=>(e||[]).map(e=>e.mediaImageGID)).reduce((e,t)=>e.concat(t),[]).filter(e=>e!=null),re=e=>e.swatchOptions?e.swatchOptions.reduce((e,t)=>{let n=t.images.map(e=>e.mediaImageGID).filter(e=>e!=null);return[...e,...n]},[]):[],ie=e=>{if(!e.collectionBreaksEnabled||!e.collectionBreaks)return[];let t=e.collectionBreaks.mediaImageGID;return t?[t]:[]},ae=e=>e.progressiveGifts?[...e.progressiveGifts.gifts?.map(e=>e.mediaImageGID)||[],e.progressiveGifts.style?.lockedMediaImageGID,e.progressiveGifts.dealBarStyle?.lockedMediaImageGID].filter(e=>e!=null):[],M=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),oe=e=>e.dealBars.map(e=>e.productPersonalisation?.mediaImageGID).filter(e=>e!=null),se=e=>{let t=e.dealBars.map(e=>e.highlights?.customIconGID).filter(e=>e!=null),n=e.subscriptions?.highlights?.customIconGID;return n?[...t,n]:t},ce=e=>(e.badges||[]).flatMap(e=>e.badgeType===`custom`&&e.imageGID?[e.imageGID]:[]),le=e=>!e.savingsSummaryEnabled||!e.savingsSummary?[]:e.savingsSummary.customIconGID?[e.savingsSummary.customIconGID]:[],ue=(e,{includeMixAndMatchSwapProducts:t=!0}={})=>{let n=[...de(e),...N(e),...P(e),...F(e),...I(e),...L(e,t),...R(e),...z(e)];return Array.from(new Set(n.filter(e=>e!=null)))},de=e=>e.dealBars.flatMap(({freeGifts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),N=e=>e.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(e=>e.products?e.products.map(e=>e.id):[]):[]).filter(e=>e!=null),P=e=>e.progressiveGiftsEnabled&&e.progressiveGifts?.gifts.map(e=>e.productGID).filter(e=>e!=null)||[],F=e=>e.dealBars.flatMap(({upsells:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null),I=e=>e.dealBars.filter(e=>e.dealBarType===p.Bundle).flatMap(({bundleProducts:e})=>e?e.map(e=>e.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),L=(e,t)=>e.dealBars.filter(e=>e.dealBarType===p.MixAndMatch).flatMap(({bundleProducts:e})=>e?e.flatMap(e=>[e.productGID,...t?e.selectedProducts?.map(e=>e.id)??[]:[]]):[]).filter(e=>e!=null).filter(e=>e!=="default"),R=e=>!e.checkboxUpsellsEnabled||!e.checkboxUpsells?[]:e.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),z=e=>e.dealBars.filter(e=>e.dealBarType===p.Sku).flatMap(({productGID:e})=>e?[e]:[]),B=class extends Error{constructor({status:e,operationName:t,graphqlErrors:n}){let r=n.length?`: ${n.join(`; `)}`:``;super(`Storefront API ${t??`query`} failed (HTTP ${e})${r}`),this.name=`StorefrontApiError`,this.status=e,this.operationName=t,this.graphqlErrors=n}},V=async(e,t)=>{let n=await e.text();if(!n)throw Error(`Empty graphql response`);let r;try{r=JSON.parse(n)}catch(n){throw e.ok?n:new B({status:e.status,operationName:t,graphqlErrors:[]})}if(!e.ok||r.data===null||r.data===void 0)throw new B({status:e.status,operationName:t,graphqlErrors:(r.errors??[]).map(({message:e})=>e).filter(Boolean)});return r.data},H=class{constructor(e,t){this.storefrontApiVersion=`2026-07`,this.storefrontAccessToken=t,this.shopifyDomain=e}async query(e,t){let n=t?.variables??{},r=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`,i=e.match(/query\s+(\w+)/)?.[1];return i&&(r+=`?operation_name=${i}`),V(await fetch(r,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:n})}),i)}},U=(e,t)=>{let n=[],r=e.filter(e=>e.blockVisibility===`selected-products`);for(let e of r)e.selectedProductIds.map(Number).includes(t.id)&&n.push(e);let i=e.filter(e=>e.blockVisibility===`selected-collections`);for(let e of i)t.collectionIds.some(t=>e.selectedCollectionIds.map(Number).includes(t))&&n.push(e);let a=e.filter(e=>e.blockVisibility===`excluded-products`);for(let e of a)!e.excludedProductIds.map(Number).includes(t.id)&&!(e.excludedCollectionIds||[]).some(e=>t.collectionIds.includes(e))&&n.push(e);let o=e.filter(e=>e.blockVisibility===`all-products`);for(let e of o)n.push(e);return n};[`primaryBackground`,`secondaryBackground`,`primaryText`,`secondaryText`,`border`,`overlay`,`primaryAccent`,`primaryAccentText`,`badgeBackground`,`badgeText`,`error`].map(e=>`brand_${e}`);var W=function(e){return e.QuantityBreak=`quantity-break`,e.Bxgy=`bxgy`,e.Bundle=`bundle`,e.MixAndMatch=`mix-and-match`,e.Sku=`sku`,e}({}),fe=async(e,t,{country:n,language:r})=>{let i=t.collectionBreaks;if(!t.collectionBreaksEnabled||!i)return;let a;a=i.visibility===`deal-products`?await m(e,{country:n,language:r,blockVisibility:t.blockVisibility,excludedProductGIDs:(t.excludedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedProductGIDs:(t.selectedProductIds||[]).map(e=>`gid://shopify/Product/${e}`),selectedCollectionGIDs:(t.selectedCollectionIds||[]).map(e=>`gid://shopify/Collection/${e}`)}):await m(e,{country:n,language:r,blockVisibility:i.visibility,excludedProductGIDs:(i.excludedProducts||[]).map(({id:e})=>e),selectedProductGIDs:(i.selectedProducts||[]).map(({id:e})=>e),selectedCollectionGIDs:(i.selectedCollections||[]).map(({id:e})=>e)});let o=await g(e,{country:n,language:r,productIds:a.map(e=>Number(e.split(`/`).pop())),useExternalMetafieldNamespace:!0}),s=i.visibility===`deal-products`&&t.blockVisibility===`excluded-products`;return o=o.filter(e=>e.availableForSale&&(!s||U([t],e).length>0)),o},pe=({language:e,dealBlockId:t})=>{let n={"system.out_of_stock":`There's not enough items in our stock, please select smaller bundle.`,"system.invalid_variant":`Sorry, this is not currently available.`,"system.unavailable_option_value":`Unavailable`,"system.confirm":`Confirm`,"system.cancel":`Cancel`,"system.free":`FREE`,"system.search":`Search`,"system.quantity":`Quantity`,"system.subscription_plan":`Subscription plan`,"system.remove":`Remove`,"system.sort_by":`Sort by`,"system.sort_relevance":`Relevance`,"system.sort_newest_first":`Newest first`,"system.sort_price_low_to_high":`Price: Low → High`,"system.sort_price_high_to_low":`Price: High → Low`,"system.no_results_found":`No results found`,"system.no_results_description":`We can't find any item matching your search.`,"system.clear_search":`Clear search`,"system.no_products_available":`No products available`,"system.original_price":`Original price:`,"system.price":`Price:`,"system.letters_only":`Only letters are allowed.`,"system.numbers_only":`Only numbers are allowed.`,"system.personalisation_required_alert":`Please add personalisation for every item to continue.`,"system.gifts_required_alert":`Please choose your free gifts`},r=e?me(e):void 0;return{...n,...r?.system,...r?.dealBlocks[t]}},me=e=>{if(typeof document>`u`)return;let t=document.querySelector(`script#kaching-bundles-translations`);if(!t?.textContent)return;let n;try{n=JSON.parse(t.textContent)}catch{return}let r=G(e);return n.find(e=>G(e.locale)===r)?.translations},G=e=>e.toLowerCase().replace(/_/g,`-`),he=`2026-07`,ge=async(e,{productId:t,dealBlockId:n,abTestVariantId:r,country:i=void 0,language:a=void 0})=>{try{let o=[Number(t.split(`/`).pop())],s=new be(e);i||=s.i18n?.country,a||=s.i18n?.language;let c=await w(s,{language:a,country:i,useExternalMetafieldNamespace:!0});s.shopifyDomain=c.shopifyDomain;let l=c.storefrontAccessToken?new H(c.shopifyDomain,c.storefrontAccessToken):s,[d,f]=await Promise.all([g(l,{country:i,language:a,productIds:o,useExternalMetafieldNamespace:!0}),u(l,{useExternalMetafieldNamespace:!0,useMetaobjects:c.featureFlags.storefront_metaobjects})]),p=d[0];if(!p)return null;let m=U(f,p),h=n?m.filter(e=>e.id===n||e.nanoId===n):m,_=(r?h.find(e=>e.abTestVariantId===r):void 0)??h[0]??m[0];if(!_)return null;let v=ue(_,{includeMixAndMatchSwapProducts:!1}),y=_e(l,_,{otherProductGIDs:v,country:i,language:a}),[b,x,S]=await Promise.all([g(l,{country:i,language:a,productIds:v,useExternalMetafieldNamespace:!0}),E(l,k(_),300),pe({language:a,dealBlockId:_.id})]);return{data:{config:c,dealBlock:_,product:p,otherProducts:b,mediaImages:x,translations:S},modalProducts:y}}catch(e){return console.error(e),null}},_e=async(e,t,n)=>{let[r,i]=await Promise.all([K(e,t,n),ye(e,t,n)]);return{mixAndMatchSwapProducts:r,collectionBreaksProducts:i}},K=async(e,t,{otherProductGIDs:n,country:r,language:i})=>{try{let a=[];try{a=await O(e,{dealBlock:t,country:r,language:i})}catch(e){console.error(e)}let o=new Set(n),s=[...new Set([...ve(t),...a])].filter(e=>!o.has(e));return s.length?await g(e,{country:r,language:i,productIds:s,useExternalMetafieldNamespace:!0}):[]}catch(e){return console.error(e),[]}},ve=e=>e.dealBars.flatMap(e=>e.dealBarType===W.MixAndMatch?e.bundleProducts.flatMap(e=>(e.selectedProducts??[]).map(e=>e.id)):[]),ye=async(e,t,{country:n,language:r})=>{try{return await fe(e,t,{country:n,language:r})??[]}catch(e){return console.error(e),[]}},be=class{constructor(e){this.storefront=e,this.shopifyDomain=``}async query(e,t){if(`query`in this.storefront&&`i18n`in this.storefront)return await this.storefront.query(e,t);if(`graphql`in this.storefront){let n=await this.storefront.graphql(e,t);if(n.errors?.length)throw Error(n.errors.map(e=>e.message).join(`
270
+ `));return n.data}if(`request`in this.storefront)return(await this.storefront.request(e,t)).data;if(`shopifyDomain`in this.storefront&&`storefrontAccessToken`in this.storefront){let n=await fetch(`https://${this.storefront.shopifyDomain}/api/${he}/graphql.json`,{body:JSON.stringify({query:e,variables:t?.variables}),headers:{"Content-Type":`application/json`,"X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}{let n=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:e,variables:t?.variables}),headers:this.storefront.getPublicTokenHeaders(),method:`POST`});if(!n.ok)throw Error(n.statusText);return(await n.json()).data}}get i18n(){if(`i18n`in this.storefront)return this.storefront.i18n}},xe=async(e,t)=>{try{let n=await ge(e,t);if(!n)return null;let{config:r,dealBlock:i,product:a,otherProducts:o,mediaImages:s,translations:c}=n.data,{mixAndMatchSwapProducts:l,collectionBreaksProducts:u}=await n.modalProducts;return{config:r,dealBlock:i,product:a,otherProducts:o,mixAndMatchSwapProducts:l,mediaImages:s,collectionBreaksProducts:u,translations:c}}catch(e){return console.error(e),null}},q=`kaching-bundles-block`,J=1e4,Y=`/kaching-bundles-block.js`,Se=`https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js`,Ce=`https://bundles-integrations.kachingappz.app/kaching-bundles-block.js`,X=new WeakSet,we=async e=>{let t=e.document;if(!e.customElements.get(q)){if(X.has(t))return Q(e,q);X.add(t);try{await De(e)}catch(e){throw X.delete(t),e}}},Te=()=>typeof window<`u`&&window.__KACHING_DEV__!==void 0,Ee=()=>Te()?Se:Ce,De=async e=>{let t=e.document,n=Ee();if(t.querySelector(`script[src="${n}"]`))return Q(e,q);let r=Oe(t);if(r&&await Ae(t,r))return Q(e,q);let i=t.createElement(`script`);return i.src=n,await Z(t,i),Q(e,q)},Oe=e=>{let t=e.querySelectorAll(`link[rel="modulepreload"][href$="${Y}"]`);return Array.from(t,e=>e.href).find(ke)},ke=e=>{try{return new URL(e).pathname.endsWith(Y)}catch{return!1}},Ae=async(e,t)=>{let n=e.createElement(`script`);n.type=`module`,n.setAttribute(`crossorigin`,`anonymous`),n.src=t;try{return await Z(e,n),!0}catch{return n.remove(),!1}},Z=(e,t)=>new Promise((n,r)=>{t.onload=()=>n(),t.onerror=()=>r(Error(`Failed to load script`)),e.head.appendChild(t)}),Q=(e,t)=>new Promise((n,r)=>{e.customElements.get(t)?n():Promise.race([e.customElements.whenDefined(t),new Promise((e,n)=>setTimeout(()=>n(Error(`Custom element "${t}" failed to register within ${J}ms`)),J))]).then(()=>n()).catch(r)}),$=`a-f\\d`,je=`#?[${$}]{3}[${$}]?`,Me=`#?[${$}]{6}([${$}]{2})?`,Ne=RegExp(`[^#${$}]`,`gi`),Pe=RegExp(`^${je}$|^${Me}$`,`i`);function Fe(e,t={}){if(typeof e!=`string`||Ne.test(e)||!Pe.test(e))throw TypeError(`Expected a valid hex string`);e=e.replace(/^#/,``);let n=1;e.length===8&&(n=Number.parseInt(e.slice(6,8),16)/255,e=e.slice(0,6)),e.length===4&&(n=Number.parseInt(e.slice(3,4).repeat(2),16)/255,e=e.slice(0,3)),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]);let r=Number.parseInt(e,16),i=r>>16,a=r>>8&255,o=r&255,s=typeof t.alpha==`number`?t.alpha:n;return t.format===`array`?[i,a,o,s]:t.format===`css`?`rgb(${i} ${a} ${o}${s===1?``:` / ${Number((s*100).toFixed(2))}%`})`:{red:i,green:a,blue:o,alpha:s}}var Ie=({price:e})=>({id:123,handle:`123`,url:null,availableForSale:!0,requiresSellingPlan:!1,title:``,image:null,selectedVariantId:456,collectionIds:[],options:[],sellingPlans:[],variants:[{id:456,availableForSale:!0,price:Math.round((e??10)*100),compareAtPrice:null,options:[],imageId:null,image:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50,unitPriceMeasurement:null}],metafields:{text:null,text2:null,text3:null,text4:null},isNativeBundle:!1}),Le=()=>({shopifyDomain:``,moneyFormat:"${{amount_with_comma_separator}}",locale:`en`,liquidLocale:`en`,country:`US`,marketId:0,productId:null,storefrontAccessToken:null,includeSellingPlans:!1,includeAvailableQuantity:!1,customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,previewScratchOff:!1,currencyRate:1,defaultTranslations:{"system.out_of_stock":``,"system.invalid_variant":``,"system.unavailable_option_value":``,"system.confirm":``,"system.cancel":``,"system.free":``,"system.search":``,"system.quantity":``,"system.subscription_plan":``,"system.remove":``,"system.sort_by":``,"system.sort_relevance":``,"system.sort_newest_first":``,"system.sort_price_low_to_high":``,"system.sort_price_high_to_low":``,"system.no_results_found":``,"system.no_results_description":``,"system.clear_search":``,"system.no_products_available":``,"system.original_price":``,"system.price":``,"system.letters_only":``,"system.numbers_only":``},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null},shopCustomStyles:``,featureFlags:{}}),Re=({color:e,cornerRadius:t})=>{let n={id:`123`,nanoId:`123`,blockName:`Bundle`,discountName:``,blockTitle:`BUNDLE & SAVE`,blockLayout:`vertical`,blockVisibility:`all-products`,marketId:null,currency:null,excludedProductIds:[],excludedCollectionIds:[],selectedProductIds:[],selectedCollectionIds:[],excludeB2bCustomers:!1,excludePos:!1,startTimestamp:175811496e4,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!1,showPricesPerItem:!1,showBothPrices:!1,useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:`.00`,updateNativePrice:!1,updateNativePriceType:`item`,skipCart:!1,showVariantsForSingleQuantity:!0,preselectedDealBarId:`1f-9`,defaultVariantsV2:[],collectionBreaksEnabled:!1,collectionBreaks:null,chooseProductModal:null,timerEnabled:!1,timer:null,subscriptionsEnabled:!1,subscriptions:null,stickyAtcEnabled:!1,stickyAtc:null,progressiveGiftsEnabled:!1,progressiveGifts:null,checkboxUpsellsEnabled:!1,checkboxUpsells:null,lowStockAlertEnabled:!1,lowStockAlert:null,dealBars:[{id:`PfFU`,dealBarType:W.QuantityBreak,title:`1 pack`,subtitle:`Standard price`,label:``,quantity:1,discountType:`default`,discountValue:``,badgeStyle:`simple`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null},{id:`1f-9`,dealBarType:W.QuantityBreak,title:`2 pack`,subtitle:`You save {{saved_percentage}}`,label:`SAVE {{saved_total}}`,quantity:2,discountType:`percentage`,discountValue:`15`,badgeStyle:`most-popular`,badgeText:``,badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null}],badgesEnabled:!0,badges:[{id:`bdg1`,attachedTo:{type:`dealBar`,dealBarId:`1f-9`},text:`MOST POPULAR`,colors:null,badgeType:`most-popular`,size:90}],cornerRadius:t??8,spacing:1,colors:{background:{red:255,green:255,blue:255,alpha:1},selectedBackground:{red:255,green:255,blue:255,alpha:1},border:{red:0,green:0,blue:0,alpha:1},blockTitle:{red:0,green:0,blue:0,alpha:1},title:{red:0,green:0,blue:0,alpha:1},subtitle:{red:85,green:85,blue:85,alpha:1},price:{red:0,green:0,blue:0,alpha:1},fullPrice:{red:85,green:85,blue:85,alpha:1},labelBackground:{red:238,green:238,blue:238,alpha:1},label:{red:0,green:0,blue:0,alpha:1},badgeBackground:{red:255,green:17,blue:17,alpha:1},badgeText:{red:255,green:255,blue:255,alpha:1},freeGiftBackground:{red:0,green:0,blue:0,alpha:.3},freeGiftText:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedBackground:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedText:{red:255,green:255,blue:255,alpha:1},upsellBackground:{red:0,green:0,blue:0,alpha:.2},upsellText:{red:0,green:0,blue:0,alpha:1},upsellSelectedBackground:{red:0,green:0,blue:0,alpha:.2},upsellSelectedText:{red:0,green:0,blue:0,alpha:1}},fonts:{blockTitle:{size:`14`,style:`bold`},title:{size:`20`,style:`bold`},subtitle:{size:`14`,style:`regular`},label:{size:`12`,style:`regular`},freeGift:{size:`13`,style:`bold`},upsell:{size:`13`,style:`bold`},unitLabel:{size:`14`,style:`regular`}},swatchOptions:[],swatchSize:18,swatchShape:`circle`,imageSize:48,imageCornerRadius:6};return e!==void 0&&(n.colors.border={...Fe(e),alpha:1}),n},ze=({data:n,selectedVariantId:r,preview:i,onLinesChange:a,targetWindow:o})=>{let s=(0,e.useRef)(null),[c,l]=(0,e.useState)(!1),u=(0,e.useRef)(!1);(0,e.useEffect)(()=>{s.current&&!c&&(async()=>{await we(o??window),l(!0)})()},[c,o]),(0,e.useEffect)(()=>{let e=s.current;if(!c||!e)return;let t=()=>{let t=e.items().map(e=>({merchandiseId:`gid://shopify/ProductVariant/${e.id}`,quantity:e.quantity,attributes:Object.entries(e.properties).map(([e,t])=>({key:e,value:String(t)})),sellingPlanId:e.selling_plan?`gid://shopify/SellingPlan/${e.selling_plan}`:void 0}));a?.(t)};return u.current||=(typeof e.items==`function`?t():e.addEventListener(`kaching-bundles-block-loaded`,t),!0),e.addEventListener(`variants-changed`,t),()=>{e.removeEventListener(`kaching-bundles-block-loaded`,t),e.removeEventListener(`variants-changed`,t)}},[c,a]);let d=n?Ve(n,r):i?He(i):null;return Be(()=>{let e=s.current;if(e&&d)for(let[t,n]of Object.entries(d.jsonAttributes))e.getAttribute(t)!==n&&e.setAttribute(t,n)}),d?(0,t.jsx)(`kaching-bundles-block`,{ref:s,"deal-block-id":d.dealBlockId,...d.jsonAttributes,"current-variant-id":d.currentVariantId}):null},Be=typeof window>`u`?e.useEffect:e.useLayoutEffect,Ve=({config:e,dealBlock:t,product:n,otherProducts:r,mixAndMatchSwapProducts:i,mediaImages:a,collectionBreaksProducts:o,translations:s},c)=>({dealBlockId:t.id,currentVariantId:c?c.split(`/`).pop():String(n.variants[0].id),jsonAttributes:{config:JSON.stringify(e),"deal-block":JSON.stringify(t),"media-images":JSON.stringify(a),product:JSON.stringify(n),"other-products":JSON.stringify(r),"mix-and-match-swap-products":JSON.stringify(i??[]),"collection-breaks-products":JSON.stringify(o),translations:JSON.stringify(s)}}),He=({cornerRadius:e,color:t,price:n})=>{let r=Ie({price:n}),i=Le(),a=Re({color:t,cornerRadius:e});return{dealBlockId:a.id,currentVariantId:String(r.variants[0].id),jsonAttributes:{config:JSON.stringify(i),"deal-block":JSON.stringify(a),"media-images":JSON.stringify([]),product:JSON.stringify(r),"other-products":JSON.stringify([]),"mix-and-match-swap-products":JSON.stringify([]),"collection-breaks-products":JSON.stringify([]),translations:JSON.stringify({})}}};exports.KachingBundle=ze,exports.fetchKachingBundlesData=xe;