@kachingappz/bundles-js 1.1.2 → 1.1.4

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,138 +1,66 @@
1
- import { jsx as J } from "react/jsx-runtime";
2
- import { useRef as B, useState as z, useEffect as D, useLayoutEffect as Q } from "react";
3
- const H = (e, t) => {
4
- const a = [], r = e.filter(
5
- (i) => i.blockVisibility === "selected-products"
6
- );
7
- for (const i of r)
8
- i.selectedProductIds.map(Number).includes(t.id) && a.push(i);
9
- const s = e.filter(
10
- (i) => i.blockVisibility === "selected-collections"
11
- );
12
- for (const i of s)
13
- t.collectionIds.some(
14
- (d) => i.selectedCollectionIds.map(Number).includes(d)
15
- ) && a.push(i);
16
- const l = e.filter(
17
- (i) => i.blockVisibility === "excluded-products"
18
- );
19
- for (const i of l)
20
- !i.excludedProductIds.map(Number).includes(t.id) && !(i.excludedCollectionIds || []).some(
21
- (d) => t.collectionIds.includes(d)
22
- ) && a.push(i);
23
- const o = e.filter(
24
- (i) => i.blockVisibility === "all-products"
25
- );
26
- for (const i of o)
27
- a.push(i);
28
- return a;
29
- }, K = (e, { language: t, country: a }) => {
30
- var p, g;
31
- const r = W(t, a), s = new Intl.NumberFormat(r, {
32
- style: "currency",
33
- currency: e,
34
- currencyDisplay: "narrowSymbol"
35
- }).formatToParts(123456789e-2), l = (p = s.find((y) => y.type === "decimal")) == null ? void 0 : p.value, o = X(
36
- (g = s.find((y) => y.type === "group")) == null ? void 0 : g.value
37
- ), i = s.some((y) => y.type === "fraction"), d = Y(
38
- o,
39
- l,
40
- i
41
- ), u = s.findIndex(C), c = s.findLastIndex(C);
42
- return [
43
- ...s.slice(0, u).map(G),
44
- d,
45
- ...s.slice(c + 1).map(G)
46
- ].join("");
47
- }, G = (e) => F(e.value), F = (e) => e.replace(/\s/g, " "), C = (e) => e.type === "integer" || e.type === "group" || e.type === "decimal" || e.type === "fraction", W = (e, t) => e && t ? `${e}-${t.toUpperCase()}` : e || (t ? t.toUpperCase() : "en"), X = (e) => e === void 0 ? void 0 : F(e).replace(/’/g, "'"), Y = (e, t, a) => t === "," && e === "." ? a ? "{{amount_with_comma_separator}}" : "{{amount_no_decimals_with_comma_separator}}" : t === "," && e === " " ? a ? "{{amount_with_space_separator}}" : "{{amount_no_decimals_with_space_separator}}" : t === "." && e === " " ? "{{amount_with_period_and_space_separator}}" : t === "." && e === "'" ? "{{amount_with_apostrophe_separator}}" : a ? "{{amount}}" : "{{amount_no_decimals}}", w = ({
48
- country: e,
49
- language: t
50
- }) => {
51
- const a = [];
52
- return e && a.push(`country: ${e}`), t && a.push(`language: ${t}`), a.length > 0 ? `@inContext(${a.join(", ")})` : "";
53
- }, Z = async (e, {
54
- useExternalMetafieldNamespace: t,
55
- useMetaobjects: a
56
- }) => a ? te(
57
- e
58
- ) : ee(e), ee = async (e, t) => {
59
- var r;
60
- const a = (r = (await e.query(
61
- `
62
- query FetchDealBlocks($metafieldNamespace: String!) {
63
- shop {
64
- metafield(namespace: $metafieldNamespace, key: "deal_blocks") {
65
- value
66
- }
67
- }
68
- }
69
- `,
70
- {
71
- variables: {
72
- metafieldNamespace: "app--2935586817--kaching_bundles"
73
- }
74
- }
75
- )).shop.metafield) == null ? void 0 : r.value;
76
- return a ? JSON.parse(a) : [];
77
- }, te = async (e, t) => {
78
- const a = "app--2935586817--deal_block", r = [];
79
- let s = null;
80
- for (; ; ) {
81
- const l = await e.query(
82
- `
83
- query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
84
- metaobjects(type: $type, first: 250, after: $cursor) {
85
- nodes {
86
- fields {
87
- key
88
- value
89
- }
90
- }
91
- pageInfo {
92
- hasNextPage
93
- endCursor
94
- }
95
- }
96
- }
97
- `,
98
- {
99
- variables: {
100
- type: a,
101
- cursor: s
102
- }
103
- }
104
- );
105
- for (const o of l.metaobjects.nodes) {
106
- const i = o.fields.find(
107
- (d) => d.key === "settings"
108
- );
109
- i != null && i.value && r.push(JSON.parse(i.value));
110
- }
111
- if (!l.metaobjects.pageInfo.hasNextPage)
112
- break;
113
- s = l.metaobjects.pageInfo.endCursor;
114
- }
115
- return r;
116
- }, T = async (e, {
117
- country: t,
118
- language: a,
119
- blockVisibility: r,
120
- excludedProductGIDs: s,
121
- selectedProductGIDs: l,
122
- selectedCollectionGIDs: o,
123
- limit: i = 1e3
124
- }) => {
125
- switch (r) {
126
- case "selected-products":
127
- return l.slice(0, i);
128
- case "all-products":
129
- case "excluded-products": {
130
- const d = w({ country: t, language: a });
131
- let u = [], c = null;
132
- for (; u.length < i; ) {
133
- const p = Math.min(i - u.length, 250), g = await e.query(
134
- `
135
- query FetchProductGIDs($limit: Int!, $cursor: String) ${d} {
1
+ import { useEffect as e, useLayoutEffect as t, useRef as n, useState as r } from "react";
2
+ import { jsx as i } from "react/jsx-runtime";
3
+ // ../bundles-storefront-api/dist/buildMarketMoneyFormat.js
4
+ var a = (e, { language: t, country: n }) => {
5
+ let r = l(t, n), i = new Intl.NumberFormat(r, {
6
+ style: "currency",
7
+ currency: e,
8
+ currencyDisplay: "narrowSymbol"
9
+ }).formatToParts(1234567.89), a = i.find((e) => e.type === "decimal")?.value, s = d(u(i.find((e) => e.type === "group")?.value), a, i.some((e) => e.type === "fraction")), f = i.findIndex(c), p = i.findLastIndex(c);
10
+ return [
11
+ ...i.slice(0, f).map(o),
12
+ s,
13
+ ...i.slice(p + 1).map(o)
14
+ ].join("");
15
+ }, o = (e) => s(e.value), s = (e) => e.replace(/\s/g, " "), c = (e) => e.type === "integer" || e.type === "group" || e.type === "decimal" || e.type === "fraction", l = (e, t) => e && t ? `${e}-${t.toUpperCase()}` : e || (t ? t.toUpperCase() : "en"), u = (e) => e === void 0 ? void 0 : s(e).replace(/’/g, "'"), d = (e, t, n) => t === "," && e === "." ? n ? "{{amount_with_comma_separator}}" : "{{amount_no_decimals_with_comma_separator}}" : t === "," && e === " " ? n ? "{{amount_with_space_separator}}" : "{{amount_no_decimals_with_space_separator}}" : t === "." && e === " " ? "{{amount_with_period_and_space_separator}}" : t === "." && e === "'" ? "{{amount_with_apostrophe_separator}}" : n ? "{{amount}}" : "{{amount_no_decimals}}", f = ({ country: e, language: t }) => {
16
+ let n = [];
17
+ return e && n.push(`country: ${e}`), t && n.push(`language: ${t}`), n.length > 0 ? `@inContext(${n.join(", ")})` : "";
18
+ }, p = async (e, { useExternalMetafieldNamespace: t, useMetaobjects: n }) => n ? h(e, t) : m(e, t), m = async (e, t) => {
19
+ let n = (await e.query("\n query FetchDealBlocks($metafieldNamespace: String!) {\n shop {\n metafield(namespace: $metafieldNamespace, key: \"deal_blocks\") {\n value\n }\n }\n }\n ", { variables: { metafieldNamespace: t ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles" } })).shop.metafield?.value;
20
+ return n ? JSON.parse(n) : [];
21
+ }, h = async (e, t) => {
22
+ let n = t ? "app--2935586817--deal_block" : "$app:deal_block", r = [], i = null;
23
+ for (;;) {
24
+ let t = await e.query("\n query FetchDealBlockMetaobjects($type: String!, $cursor: String) {\n metaobjects(type: $type, first: 250, after: $cursor) {\n nodes {\n fields {\n key\n value\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n ", { variables: {
25
+ type: n,
26
+ cursor: i
27
+ } });
28
+ for (let e of t.metaobjects.nodes) {
29
+ let t = e.fields.find((e) => e.key === "settings");
30
+ t?.value && r.push(JSON.parse(t.value));
31
+ }
32
+ if (!t.metaobjects.pageInfo.hasNextPage) break;
33
+ i = t.metaobjects.pageInfo.endCursor;
34
+ }
35
+ return r;
36
+ };
37
+ [
38
+ "primaryBackground",
39
+ "secondaryBackground",
40
+ "primaryText",
41
+ "secondaryText",
42
+ "border",
43
+ "overlay",
44
+ "primaryAccent",
45
+ "primaryAccentText",
46
+ "badgeBackground",
47
+ "badgeText",
48
+ "error"
49
+ ].map((e) => `brand_${e}`);
50
+ var g = /* @__PURE__ */ function(e) {
51
+ return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
52
+ }({}), _ = async (e, { country: t, language: n, blockVisibility: r, excludedProductGIDs: i, selectedProductGIDs: a, selectedCollectionGIDs: o, limit: s = 1e3 }) => {
53
+ switch (r) {
54
+ case "selected-products": return a.slice(0, s);
55
+ case "all-products":
56
+ case "excluded-products": {
57
+ let a = f({
58
+ country: t,
59
+ language: n
60
+ }), o = [], c = null;
61
+ for (; o.length < s;) {
62
+ let t = Math.min(s - o.length, 250), n = await e.query(`
63
+ query FetchProductGIDs($limit: Int!, $cursor: String) ${a} {
136
64
  products(first: $limit, after: $cursor) {
137
65
  nodes {
138
66
  id
@@ -143,27 +71,25 @@ const H = (e, t) => {
143
71
  }
144
72
  }
145
73
  }
146
- `,
147
- {
148
- variables: {
149
- limit: p,
150
- cursor: c
151
- }
152
- }
153
- );
154
- if (u.push(...g.products.nodes.map((y) => y.id)), !g.products.pageInfo.hasNextPage) break;
155
- c = g.products.pageInfo.endCursor;
156
- }
157
- if (r === "excluded-products") {
158
- const p = new Set(s);
159
- u = u.filter((g) => !p.has(g));
160
- }
161
- return u;
162
- }
163
- case "selected-collections": {
164
- const d = w({ country: t, language: a }), u = (await e.query(
165
- `
166
- query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${d} {
74
+ `, { variables: {
75
+ limit: t,
76
+ cursor: c
77
+ } });
78
+ if (o.push(...n.products.nodes.map((e) => e.id)), !n.products.pageInfo.hasNextPage) break;
79
+ c = n.products.pageInfo.endCursor;
80
+ }
81
+ if (r === "excluded-products") {
82
+ let e = new Set(i);
83
+ o = o.filter((t) => !e.has(t));
84
+ }
85
+ return o;
86
+ }
87
+ case "selected-collections": {
88
+ let r = f({
89
+ country: t,
90
+ language: n
91
+ }), i = (await e.query(`
92
+ query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${r} {
167
93
  nodes(ids: $collectionGIDs) {
168
94
  ... on Collection {
169
95
  products(first: $limit) {
@@ -174,77 +100,23 @@ const H = (e, t) => {
174
100
  }
175
101
  }
176
102
  }
177
- `,
178
- {
179
- variables: {
180
- collectionGIDs: o,
181
- limit: Math.min(i, 250)
182
- }
183
- }
184
- )).nodes.filter((c) => c !== null).flatMap(
185
- (c) => c.products.nodes.map((p) => p.id)
186
- );
187
- return Array.from(new Set(u)).slice(0, i);
188
- }
189
- }
190
- }, L = `
191
- id
192
- availableForSale
193
- price {
194
- amount
195
- }
196
- compareAtPrice {
197
- amount
198
- }
199
- selectedOptions {
200
- name
201
- value
202
- }
203
- image {
204
- id
205
- url(transform: $variantImageTransform)
206
- }
207
- unitPriceMeasurement {
208
- quantityUnit
209
- quantityValue
210
- referenceUnit
211
- referenceValue
212
- }
213
- requiresComponents
214
- sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {
215
- nodes {
216
- sellingPlan {
217
- id
218
- }
219
- priceAdjustments {
220
- price {
221
- amount
222
- }
223
- compareAtPrice {
224
- amount
225
- }
226
- perDeliveryPrice {
227
- amount
228
- }
229
- }
230
- }
231
- }
232
- quantityAvailable @include(if: $includeAvailableQuantity)
233
- `, A = async (e, {
234
- country: t,
235
- language: a,
236
- productIds: r,
237
- includeSellingPlans: s = !0,
238
- includeAvailableQuantity: l = !0,
239
- useExternalMetafieldNamespace: o = !1,
240
- batchSize: i = 250,
241
- onBatchError: d,
242
- variantImageTransform: u = { maxWidth: 200, maxHeight: 200 }
243
- }) => {
244
- if (!r.length)
245
- return [];
246
- const c = r.map((f) => typeof f == "string" && f.startsWith("gid://") ? f : `gid://shopify/Product/${f}`), p = w({ country: t, language: a }), g = `
247
- query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${p} {
103
+ `, { variables: {
104
+ collectionGIDs: o,
105
+ limit: Math.min(s, 250)
106
+ } })).nodes.filter((e) => e !== null).flatMap((e) => e.products.nodes.map((e) => e.id));
107
+ return Array.from(new Set(i)).slice(0, s);
108
+ }
109
+ }
110
+ }, v = "\n id\n availableForSale\n price {\n amount\n }\n compareAtPrice {\n amount\n }\n selectedOptions {\n name\n value\n }\n image {\n id\n url(transform: $variantImageTransform)\n }\n unitPriceMeasurement {\n quantityUnit\n quantityValue\n referenceUnit\n referenceValue\n }\n requiresComponents\n sellingPlanAllocations(first: 100) @include(if: $includeSellingPlans) {\n nodes {\n sellingPlan {\n id\n }\n priceAdjustments {\n price {\n amount\n }\n compareAtPrice {\n amount\n }\n perDeliveryPrice {\n amount\n }\n }\n }\n }\n quantityAvailable @include(if: $includeAvailableQuantity)\n", y = async (e, { country: t, language: n, productIds: r, includeSellingPlans: i = !0, includeAvailableQuantity: a = !0, includeProductRating: o = !1, includeProductSubtitle: s = !1, productSubtitleMetafield: c = "descriptors.subtitle", useExternalMetafieldNamespace: l = !1, batchSize: u = 250, onBatchError: d, variantImageTransform: p = {
111
+ maxWidth: 200,
112
+ maxHeight: 200
113
+ } }) => {
114
+ if (!r.length) return [];
115
+ let m = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), h = f({
116
+ country: t,
117
+ language: n
118
+ }), g = `
119
+ query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $includeProductSubtitle: Boolean!, $subtitleNamespace: String!, $subtitleKey: String!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${h} {
248
120
  shop {
249
121
  currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
250
122
  value
@@ -278,7 +150,7 @@ const H = (e, t) => {
278
150
  }
279
151
  variants(first: 250) {
280
152
  nodes {
281
- ${L}
153
+ ${v}
282
154
  }
283
155
  }
284
156
  collections(first: 50) {
@@ -298,6 +170,15 @@ const H = (e, t) => {
298
170
  metafield4: metafield(namespace: $metafieldNamespace, key: "text4") {
299
171
  value
300
172
  }
173
+ reviewsRating: metafield(namespace: "reviews", key: "rating") @include(if: $includeProductRating) {
174
+ value
175
+ }
176
+ reviewsRatingCount: metafield(namespace: "reviews", key: "rating_count") @include(if: $includeProductRating) {
177
+ value
178
+ }
179
+ subtitle: metafield(namespace: $subtitleNamespace, key: $subtitleKey) @include(if: $includeProductSubtitle) {
180
+ value
181
+ }
301
182
  requiresSellingPlan
302
183
  sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
303
184
  nodes {
@@ -330,90 +211,53 @@ const H = (e, t) => {
330
211
  }
331
212
  }
332
213
  }
333
- `, y = o ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", h = [], n = Math.min(i, 250);
334
- for (let f = 0; f < c.length; f += n)
335
- h.push(c.slice(f, f + n));
336
- let m = 1;
337
- const b = async (f) => {
338
- const v = await e.query(g, {
339
- variables: {
340
- productGIDs: f,
341
- includeSellingPlans: s,
342
- includeAvailableQuantity: l,
343
- metafieldNamespace: y,
344
- variantImageTransform: u
345
- }
346
- });
347
- return v.shop.currencyRateConstant && (m = JSON.parse(v.shop.currencyRateConstant.value).amount / 1e6), v;
348
- };
349
- let I;
350
- if (d) {
351
- const f = await Promise.allSettled(h.map(b));
352
- for (const v of f)
353
- v.status === "rejected" && d(
354
- v.reason instanceof Error ? v.reason : new Error(String(v.reason))
355
- );
356
- I = f.filter(
357
- (v) => v.status === "fulfilled"
358
- ).flatMap((v) => v.value.nodes);
359
- } else
360
- I = (await Promise.all(h.map(b))).flatMap((f) => f.nodes);
361
- const _ = I.filter((f) => f != null);
362
- if (d) {
363
- const f = await Promise.allSettled(
364
- _.map(async (P) => {
365
- const R = await M(
366
- e,
367
- P,
368
- {
369
- includeSellingPlans: s,
370
- includeAvailableQuantity: l,
371
- variantImageTransform: u
372
- },
373
- p
374
- );
375
- return q(
376
- R,
377
- e.shopifyDomain,
378
- m
379
- );
380
- })
381
- ), v = [];
382
- for (const P of f)
383
- P.status === "fulfilled" ? v.push(P.value) : d(
384
- P.reason instanceof Error ? P.reason : new Error(String(P.reason))
385
- );
386
- return v;
387
- }
388
- return (await Promise.all(
389
- _.map(
390
- (f) => M(
391
- e,
392
- f,
393
- {
394
- includeSellingPlans: s,
395
- includeAvailableQuantity: l,
396
- variantImageTransform: u
397
- },
398
- p
399
- )
400
- )
401
- )).map(
402
- (f) => q(f, e.shopifyDomain, m)
403
- );
404
- }, M = async (e, t, a, r = "") => {
405
- if (t.variants.nodes.length < 250)
406
- return t;
407
- const s = /* @__PURE__ */ new Set(), l = [], o = [], i = async (d) => {
408
- let u = !0, c = null;
409
- for (; u; ) {
410
- const p = await e.query(
411
- `
214
+ `, _ = l ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", y = c.indexOf("."), S = c.slice(0, y), C = c.slice(y + 1), w = [], T = Math.min(u, 250);
215
+ for (let e = 0; e < m.length; e += T) w.push(m.slice(e, e + T));
216
+ let E = 1, D = async (t) => {
217
+ let n = await e.query(g, { variables: {
218
+ productGIDs: t,
219
+ includeSellingPlans: i,
220
+ includeAvailableQuantity: a,
221
+ includeProductRating: o,
222
+ includeProductSubtitle: s,
223
+ subtitleNamespace: S,
224
+ subtitleKey: C,
225
+ metafieldNamespace: _,
226
+ variantImageTransform: p
227
+ } });
228
+ return n.shop.currencyRateConstant && (E = JSON.parse(n.shop.currencyRateConstant.value).amount / 1e6), n;
229
+ }, O;
230
+ if (d) {
231
+ let e = await Promise.allSettled(w.map(D));
232
+ for (let t of e) t.status === "rejected" && d(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
233
+ O = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
234
+ } else O = (await Promise.all(w.map(D))).flatMap((e) => e.nodes);
235
+ let k = O.filter((e) => e != null);
236
+ if (d) {
237
+ let t = await Promise.allSettled(k.map(async (t) => x(await b(e, t, {
238
+ includeSellingPlans: i,
239
+ includeAvailableQuantity: a,
240
+ variantImageTransform: p
241
+ }, h), e.shopifyDomain, E))), n = [];
242
+ for (let e of t) e.status === "fulfilled" ? n.push(e.value) : d(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
243
+ return n;
244
+ }
245
+ return (await Promise.all(k.map((t) => b(e, t, {
246
+ includeSellingPlans: i,
247
+ includeAvailableQuantity: a,
248
+ variantImageTransform: p
249
+ }, h)))).map((t) => x(t, e.shopifyDomain, E));
250
+ }, b = async (e, t, n, r = "") => {
251
+ if (t.variants.nodes.length < 250) return t;
252
+ let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
253
+ let c = !0, l = null;
254
+ for (; c;) {
255
+ let { nodes: u, pageInfo: d } = (await e.query(`
412
256
  query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $variantImageTransform: ImageTransformInput) ${r} {
413
257
  product(id: $productGID) {
414
258
  variants(first: 250, after: $cursor, reverse: $reverse) {
415
259
  nodes {
416
- ${L}
260
+ ${v}
417
261
  }
418
262
  pageInfo {
419
263
  endCursor
@@ -422,169 +266,130 @@ const H = (e, t) => {
422
266
  }
423
267
  }
424
268
  }
425
- `,
426
- {
427
- variables: {
428
- productGID: t.id,
429
- cursor: c,
430
- reverse: d,
431
- ...a
432
- }
433
- }
434
- ), { nodes: g, pageInfo: y } = p.product.variants;
435
- for (const h of g) {
436
- if (s.has(h.id)) {
437
- u = !1;
438
- break;
439
- }
440
- s.add(h.id), d ? o.push(h) : l.push(h);
441
- }
442
- y.hasNextPage || (u = !1), c = y.endCursor;
443
- }
444
- };
445
- return await Promise.all([
446
- i(!1),
447
- i(!0)
448
- ]), t.variants.nodes = [...l, ...o.reverse()], t;
449
- }, q = (e, t, a) => {
450
- var u, c, p, g, y, h;
451
- const r = e.variants.nodes.map(
452
- ({ unitPriceMeasurement: n, ...m }) => {
453
- var b, I;
454
- return {
455
- id: Number(m.id.split("/").pop()),
456
- availableForSale: m.availableForSale,
457
- price: Math.round(Number(m.price.amount) * 100),
458
- compareAtPrice: m.compareAtPrice ? Math.round(Number(m.compareAtPrice.amount) * 100) : null,
459
- options: m.selectedOptions.map((_) => _.value),
460
- imageId: m.image ? Number(m.image.id.split("/").pop()) : null,
461
- image: ((b = m.image) == null ? void 0 : b.url) || null,
462
- sellingPlans: ((I = m.sellingPlanAllocations) == null ? void 0 : I.nodes.map((_) => ({
463
- id: Number(_.sellingPlan.id.split("/").pop()),
464
- price: _.priceAdjustments.length > 0 ? Math.round(Number(_.priceAdjustments[0].price.amount) * 100) : Math.round(Number(m.price.amount) * 100),
465
- compareAtPrice: _.priceAdjustments.length > 0 ? Math.round(
466
- Number(_.priceAdjustments[0].compareAtPrice.amount) * 100
467
- ) : Math.round(Number(m.price.amount) * 100),
468
- perDeliveryPrice: _.priceAdjustments.length > 0 ? Math.round(
469
- Number(_.priceAdjustments[0].perDeliveryPrice.amount) * 100
470
- ) : Math.round(Number(m.price.amount) * 100)
471
- }))) || [],
472
- inventoryManagement: null,
473
- // Storefront API does not return inventory management, only available in liquid
474
- inventoryPolicy: null,
475
- // Storefront API does not return inventory policy, only available in liquid
476
- inventoryQuantity: m.quantityAvailable ?? null,
477
- unitPriceMeasurement: n != null && n.quantityUnit && (n != null && n.referenceUnit) ? {
478
- quantityValue: n.quantityValue,
479
- quantityUnit: n.quantityUnit.toLowerCase(),
480
- referenceValue: n.referenceValue,
481
- referenceUnit: n.referenceUnit.toLowerCase()
482
- } : null
483
- };
484
- }
485
- ), s = e.options.map((n, m) => {
486
- const b = n.optionValues.map((I) => {
487
- var _, f, v, P;
488
- return {
489
- id: Number(I.id.split("/").pop()),
490
- defaultName: I.name,
491
- name: I.name,
492
- swatch: {
493
- color: ((_ = I.swatch) == null ? void 0 : _.color) || null,
494
- image: ((P = (v = (f = I.swatch) == null ? void 0 : f.image) == null ? void 0 : v.previewImage) == null ? void 0 : P.url) || null
495
- }
496
- };
497
- });
498
- return {
499
- defaultName: n.name,
500
- name: n.name,
501
- position: m + 1,
502
- optionValues: ae(b, m, r)
503
- };
504
- }), l = (n) => {
505
- const m = n.priceAdjustments[0];
506
- if (!m)
507
- return null;
508
- const b = m.adjustmentValue;
509
- switch (b.__typename) {
510
- case "SellingPlanPercentagePriceAdjustment":
511
- return {
512
- type: "percentage",
513
- value: b.adjustmentPercentage
514
- };
515
- case "SellingPlanFixedAmountPriceAdjustment":
516
- return {
517
- type: "fixed_amount",
518
- value: o(b.adjustmentAmount.amount)
519
- };
520
- case "SellingPlanFixedPriceAdjustment":
521
- return {
522
- type: "price",
523
- value: o(b.price.amount)
524
- };
525
- default:
526
- throw new Error(
527
- `Unknown price adjustment type: ${b.__typename}`
528
- );
529
- }
530
- }, o = (n) => a === 1 ? Number(n) * 100 : Math.round(Number(n) * 100 * a), i = ((u = e.sellingPlanGroups) == null ? void 0 : u.nodes.flatMap(
531
- (n) => n.sellingPlans.nodes.map((m) => ({
532
- id: Number(m.id.split("/").pop()),
533
- name: m.name,
534
- priceAdjustment: l(m)
535
- }))
536
- )) || [], d = e.variants.nodes.some(
537
- (n) => n.requiresComponents
538
- );
539
- return {
540
- id: Number(e.id.split("/").pop()),
541
- handle: e.handle,
542
- url: e.onlineStoreUrl || `https://${t}/products/${e.handle}`,
543
- availableForSale: e.availableForSale,
544
- createdAt: e.createdAt,
545
- title: e.title,
546
- image: ((c = e.featuredImage) == null ? void 0 : c.url) || null,
547
- collectionIds: e.collections.nodes.map(
548
- (n) => Number(n.id.split("/").pop())
549
- ),
550
- options: s,
551
- selectedVariantId: Number(
552
- e.variants.nodes[0].id.split("/").pop()
553
- ),
554
- variants: r,
555
- requiresSellingPlan: e.requiresSellingPlan,
556
- sellingPlans: i,
557
- isNativeBundle: d,
558
- metafields: {
559
- text: ((p = e.metafield) == null ? void 0 : p.value) || null,
560
- text2: ((g = e.metafield2) == null ? void 0 : g.value) || null,
561
- text3: ((y = e.metafield3) == null ? void 0 : y.value) || null,
562
- text4: ((h = e.metafield4) == null ? void 0 : h.value) || null
563
- }
564
- };
565
- }, ae = (e, t, a) => e.filter((r) => a.filter(
566
- (s) => s.options[t] === r.name
567
- ).length > 0), j = "app--2935586817", se = async (e, {
568
- language: t,
569
- country: a,
570
- useExternalMetafieldNamespace: r
571
- }) => {
572
- const s = `${j}--kaching_bundles`, l = j, o = w({ country: a }), {
573
- localization: {
574
- country: {
575
- currency: { isoCode: i }
576
- }
577
- },
578
- shop: {
579
- moneyFormat: d,
580
- paymentSettings: { currencyCode: u },
581
- currencyRateConstant: c,
582
- primaryDomain: p,
583
- settingsMetafield: g
584
- }
585
- } = await e.query(
586
- `
587
- query config($metafieldNamespace: String!, $settingsNamespace: String!) ${o} {
269
+ `, { variables: {
270
+ productGID: t.id,
271
+ cursor: l,
272
+ reverse: s,
273
+ ...n
274
+ } })).product.variants;
275
+ for (let e of u) {
276
+ if (i.has(e.id)) {
277
+ c = !1;
278
+ break;
279
+ }
280
+ i.add(e.id), s ? o.push(e) : a.push(e);
281
+ }
282
+ d.hasNextPage || (c = !1), l = d.endCursor;
283
+ }
284
+ };
285
+ return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
286
+ }, x = (e, t, n) => {
287
+ let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
288
+ id: Number(t.id.split("/").pop()),
289
+ availableForSale: t.availableForSale,
290
+ price: Math.round(Number(t.price.amount) * 100),
291
+ compareAtPrice: t.compareAtPrice ? Math.round(Number(t.compareAtPrice.amount) * 100) : null,
292
+ options: t.selectedOptions.map((e) => e.value),
293
+ imageId: t.image ? Number(t.image.id.split("/").pop()) : null,
294
+ image: t.image?.url || null,
295
+ sellingPlans: t.sellingPlanAllocations?.nodes.map((e) => ({
296
+ id: Number(e.sellingPlan.id.split("/").pop()),
297
+ price: e.priceAdjustments.length > 0 ? Math.round(Number(e.priceAdjustments[0].price.amount) * 100) : Math.round(Number(t.price.amount) * 100),
298
+ compareAtPrice: e.priceAdjustments.length > 0 ? Math.round(Number(e.priceAdjustments[0].compareAtPrice.amount) * 100) : Math.round(Number(t.price.amount) * 100),
299
+ perDeliveryPrice: e.priceAdjustments.length > 0 ? Math.round(Number(e.priceAdjustments[0].perDeliveryPrice.amount) * 100) : Math.round(Number(t.price.amount) * 100)
300
+ })) || [],
301
+ inventoryManagement: null,
302
+ inventoryPolicy: null,
303
+ inventoryQuantity: t.quantityAvailable ?? null,
304
+ unitPriceMeasurement: e?.quantityUnit && e?.referenceUnit ? {
305
+ quantityValue: e.quantityValue,
306
+ quantityUnit: e.quantityUnit.toLowerCase(),
307
+ referenceValue: e.referenceValue,
308
+ referenceUnit: e.referenceUnit.toLowerCase()
309
+ } : null
310
+ })), i = e.options.map((e, t) => {
311
+ let n = e.optionValues.map((e) => ({
312
+ id: Number(e.id.split("/").pop()),
313
+ defaultName: e.name,
314
+ name: e.name,
315
+ swatch: {
316
+ color: e.swatch?.color || null,
317
+ image: e.swatch?.image?.previewImage?.url || null
318
+ }
319
+ }));
320
+ return {
321
+ defaultName: e.name,
322
+ name: e.name,
323
+ position: t + 1,
324
+ optionValues: w(n, t, r)
325
+ };
326
+ }), a = (e) => {
327
+ let t = e.priceAdjustments[0];
328
+ if (!t) return null;
329
+ let n = t.adjustmentValue;
330
+ switch (n.__typename) {
331
+ case "SellingPlanPercentagePriceAdjustment": return {
332
+ type: "percentage",
333
+ value: n.adjustmentPercentage
334
+ };
335
+ case "SellingPlanFixedAmountPriceAdjustment": return {
336
+ type: "fixed_amount",
337
+ value: o(n.adjustmentAmount.amount)
338
+ };
339
+ case "SellingPlanFixedPriceAdjustment": return {
340
+ type: "price",
341
+ value: o(n.price.amount)
342
+ };
343
+ default: throw Error(`Unknown price adjustment type: ${n.__typename}`);
344
+ }
345
+ }, o = (e) => n === 1 ? Number(e) * 100 : Math.round(Number(e) * 100 * n), s = e.sellingPlanGroups?.nodes.flatMap((e) => e.sellingPlans.nodes.map((e) => ({
346
+ id: Number(e.id.split("/").pop()),
347
+ name: e.name,
348
+ priceAdjustment: a(e)
349
+ }))) || [], c = e.variants.nodes.some((e) => e.requiresComponents);
350
+ return {
351
+ id: Number(e.id.split("/").pop()),
352
+ handle: e.handle,
353
+ url: e.onlineStoreUrl || `https://${t}/products/${e.handle}`,
354
+ availableForSale: e.availableForSale,
355
+ createdAt: e.createdAt,
356
+ title: e.title,
357
+ image: e.featuredImage?.url || null,
358
+ collectionIds: e.collections.nodes.map((e) => Number(e.id.split("/").pop())),
359
+ options: i,
360
+ selectedVariantId: Number(e.variants.nodes[0].id.split("/").pop()),
361
+ variants: r,
362
+ requiresSellingPlan: e.requiresSellingPlan,
363
+ sellingPlans: s,
364
+ isNativeBundle: c,
365
+ metafields: {
366
+ text: e.metafield?.value || null,
367
+ text2: e.metafield2?.value || null,
368
+ text3: e.metafield3?.value || null,
369
+ text4: e.metafield4?.value || null
370
+ },
371
+ rating: S(e.reviewsRating, e.reviewsRatingCount),
372
+ subtitle: e.subtitle?.value || null
373
+ };
374
+ }, S = (e, t) => {
375
+ if (!e) return null;
376
+ let n = C(e.value);
377
+ if (n === null) return null;
378
+ let r = Number(t?.value);
379
+ return {
380
+ value: n,
381
+ count: Number.isInteger(r) && r > 0 ? r : null
382
+ };
383
+ }, C = (e) => {
384
+ try {
385
+ let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
386
+ return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
387
+ } catch {
388
+ return null;
389
+ }
390
+ }, w = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), T = "app--2935586817", E = async (e, { language: t, country: n, useExternalMetafieldNamespace: r }) => {
391
+ let i = r ? `${T}--kaching_bundles` : "$app:kaching_bundles", o = r ? T : "$app", s = f({ country: n }), { localization: { country: { currency: { isoCode: c } } }, shop: { moneyFormat: l, paymentSettings: { currencyCode: u }, currencyRateConstant: d, primaryDomain: p, settingsMetafield: m } } = await e.query(`
392
+ query config($metafieldNamespace: String!, $settingsNamespace: String!) ${s} {
588
393
  localization {
589
394
  country {
590
395
  currency {
@@ -608,968 +413,817 @@ const H = (e, t) => {
608
413
  }
609
414
  }
610
415
  }
611
- `,
612
- {
613
- variables: {
614
- metafieldNamespace: s,
615
- settingsNamespace: l
616
- }
617
- }
618
- ), y = i === u ? d : K(i, { language: t, country: a }), h = c ? re(c.value) : 1, n = g ? JSON.parse(g.value) : null, m = (n == null ? void 0 : n.feature_flags) ?? {}, b = (n == null ? void 0 : n.custom_selectors) ?? {};
619
- return {
620
- shopifyDomain: p.host,
621
- moneyFormat: y,
622
- locale: (t == null ? void 0 : t.toLowerCase()) || "en",
623
- liquidLocale: (t == null ? void 0 : t.toLowerCase()) || "en",
624
- country: a ?? "US",
625
- currencyRate: h,
626
- marketId: 0,
627
- productId: null,
628
- storefrontAccessToken: (n == null ? void 0 : n.storefront_access_token) ?? null,
629
- includeSellingPlans: (n == null ? void 0 : n.include_selling_plans) ?? !1,
630
- includeAvailableQuantity: (n == null ? void 0 : n.include_available_quantity) ?? !1,
631
- customApiHost: (n == null ? void 0 : n.custom_api_host) ?? null,
632
- keepQuantityInput: (n == null ? void 0 : n.keep_quantity_input) ?? !1,
633
- ignoreDeselect: (n == null ? void 0 : n.ignore_deselect) ?? !1,
634
- ignoreUnitPrice: (n == null ? void 0 : n.ignore_unit_price) ?? !1,
635
- requireCustomerLogin: (n == null ? void 0 : n.require_customer_login) ?? !1,
636
- abTestsRunning: (n == null ? void 0 : n.ab_tests_running) ?? !1,
637
- webPixel: (n == null ? void 0 : n.web_pixel) ?? !1,
638
- b2bCustomer: !1,
639
- isLoggedIn: !1,
640
- preview: !1,
641
- previewAlerts: !1,
642
- previewScratchOff: !1,
643
- defaultTranslations: {
644
- "system.out_of_stock": "Out of stock",
645
- "system.invalid_variant": "Invalid variant",
646
- "system.unavailable_option_value": "Unavailable option value",
647
- "system.confirm": "Confirm",
648
- "system.cancel": "Cancel",
649
- "system.free": "FREE",
650
- "system.search": "Search",
651
- "system.quantity": "Quantity",
652
- "system.subscription_plan": "Subscription plan",
653
- "system.remove": "Remove",
654
- "system.sort_by": "Sort by",
655
- "system.sort_relevance": "Relevance",
656
- "system.sort_newest_first": "Newest first",
657
- "system.sort_price_low_to_high": "Price: Low → High",
658
- "system.sort_price_high_to_low": "Price: High → Low",
659
- "system.no_results_found": "No results found",
660
- "system.no_results_description": "We can't find any item matching your search.",
661
- "system.clear_search": "Clear search",
662
- "system.no_products_available": "No products available",
663
- "system.original_price": "Original price:",
664
- "system.price": "Price:",
665
- "system.letters_only": "Only letters are allowed.",
666
- "system.numbers_only": "Only numbers are allowed."
667
- },
668
- customSelectors: {
669
- quantity: b.quantity ?? null,
670
- addToCartButton: b.add_to_cart_button ?? null,
671
- variantPicker: b.variant_picker ?? null,
672
- price: b.price ?? null,
673
- priceCompare: b.price_compare ?? null
674
- },
675
- shopCustomStyles: (n == null ? void 0 : n.shop_custom_styles) ?? "",
676
- featureFlags: m,
677
- brandColors: (n == null ? void 0 : n.brand_colors) ?? null
678
- };
679
- }, re = (e) => JSON.parse(e).amount / 1e6, ne = async (e, t, a = 200) => {
680
- const r = [
681
- ...new Set(
682
- t.filter(Boolean).filter((l) => !l.startsWith("placeholder"))
683
- )
684
- ];
685
- if (r.length === 0) return [];
686
- const s = [];
687
- for (let l = 0; l < r.length; l += 250)
688
- s.push(r.slice(l, l + 250));
689
- return (await Promise.all(
690
- s.map(
691
- (l) => e.query(
692
- `
693
- query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
694
- nodes(ids: $mediaImageIds) {
695
- ... on MediaImage {
696
- id
697
- image {
698
- url(transform: { maxWidth: $size, maxHeight: $size })
699
- }
700
- }
701
- }
702
- }
703
- `,
704
- {
705
- variables: {
706
- mediaImageIds: l,
707
- size: a
708
- }
709
- }
710
- )
711
- )
712
- )).flatMap((l) => l.nodes).flatMap(
713
- (l) => l != null && l.image ? [{ gid: l.id, url: l.image.url }] : []
714
- );
715
- };
716
- var k = /* @__PURE__ */ ((e) => (e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e))(k || {});
717
- const le = (e) => [
718
- ...ie(e),
719
- ...oe(e),
720
- ...ce(e),
721
- ...ue(e),
722
- ...de(e),
723
- ...me(e),
724
- ...pe(e),
725
- ...fe(e),
726
- ...ge(e),
727
- ...ye(e),
728
- ...he(e),
729
- ...be(e),
730
- ...ve(e)
731
- ].filter((t) => t != null && !t.includes("placeholder")), ie = (e) => e.dealBars.flatMap((t) => [t.mediaImageGID, t.badgeImageGID]).filter((t) => t != null), oe = (e) => e.dealBars.flatMap(
732
- (t) => t.dealBarType === k.Bundle ? t.bundleProducts.map(
733
- (a) => a.mediaImageGID
734
- ) : []
735
- ).filter((t) => t != null), ce = (e) => e.dealBars.map(
736
- ({ freeGifts: t }) => (t || []).map((a) => a.mediaImageGID)
737
- ).reduce((t, a) => t.concat(a), []).filter((t) => t != null), ue = (e) => e.dealBars.flatMap(
738
- ({ multipleGiftsSelectors: t }) => (t || []).map((a) => a.mediaImageGID)
739
- ).filter((t) => t != null), de = (e) => e.dealBars.map(({ upsells: t }) => (t || []).map((a) => a.mediaImageGID)).reduce((t, a) => t.concat(a), []).filter((t) => t != null), me = (e) => e.swatchOptions ? e.swatchOptions.reduce((t, a) => {
740
- const r = a.images.map((s) => s.mediaImageGID).filter((s) => s != null);
741
- return [...t, ...r];
742
- }, []) : [], pe = (e) => {
743
- if (!e.collectionBreaksEnabled || !e.collectionBreaks)
744
- return [];
745
- const t = e.collectionBreaks.mediaImageGID;
746
- return t ? [t] : [];
416
+ `, { variables: {
417
+ metafieldNamespace: i,
418
+ settingsNamespace: o
419
+ } }), h = c === u ? l : a(c, {
420
+ language: t,
421
+ country: n
422
+ }), g = d ? D(d.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
423
+ return {
424
+ shopifyDomain: p.host,
425
+ moneyFormat: h,
426
+ locale: t?.toLowerCase() || "en",
427
+ liquidLocale: t?.toLowerCase() || "en",
428
+ country: n ?? "US",
429
+ currencyRate: g,
430
+ marketId: 0,
431
+ productId: null,
432
+ storefrontAccessToken: _?.storefront_access_token ?? null,
433
+ includeSellingPlans: _?.include_selling_plans ?? !1,
434
+ includeAvailableQuantity: _?.include_available_quantity ?? !1,
435
+ customApiHost: _?.custom_api_host ?? null,
436
+ keepQuantityInput: _?.keep_quantity_input ?? !1,
437
+ ignoreDeselect: _?.ignore_deselect ?? !1,
438
+ ignoreUnitPrice: _?.ignore_unit_price ?? !1,
439
+ requireCustomerLogin: _?.require_customer_login ?? !1,
440
+ abTestsRunning: _?.ab_tests_running ?? !1,
441
+ webPixel: _?.web_pixel ?? !1,
442
+ b2bCustomer: !1,
443
+ isLoggedIn: !1,
444
+ preview: !1,
445
+ previewAlerts: !1,
446
+ previewScratchOff: !1,
447
+ defaultTranslations: {
448
+ "system.out_of_stock": "Out of stock",
449
+ "system.invalid_variant": "Invalid variant",
450
+ "system.unavailable_option_value": "Unavailable option value",
451
+ "system.confirm": "Confirm",
452
+ "system.cancel": "Cancel",
453
+ "system.free": "FREE",
454
+ "system.search": "Search",
455
+ "system.quantity": "Quantity",
456
+ "system.subscription_plan": "Subscription plan",
457
+ "system.remove": "Remove",
458
+ "system.sort_by": "Sort by",
459
+ "system.sort_relevance": "Relevance",
460
+ "system.sort_newest_first": "Newest first",
461
+ "system.sort_price_low_to_high": "Price: Low → High",
462
+ "system.sort_price_high_to_low": "Price: High → Low",
463
+ "system.no_results_found": "No results found",
464
+ "system.no_results_description": "We can't find any item matching your search.",
465
+ "system.clear_search": "Clear search",
466
+ "system.no_products_available": "No products available",
467
+ "system.original_price": "Original price:",
468
+ "system.price": "Price:",
469
+ "system.letters_only": "Only letters are allowed.",
470
+ "system.numbers_only": "Only numbers are allowed."
471
+ },
472
+ customSelectors: {
473
+ quantity: y.quantity ?? null,
474
+ addToCartButton: y.add_to_cart_button ?? null,
475
+ variantPicker: y.variant_picker ?? null,
476
+ price: y.price ?? null,
477
+ priceCompare: y.price_compare ?? null
478
+ },
479
+ shopCustomStyles: _?.shop_custom_styles ?? "",
480
+ featureFlags: v,
481
+ brandColors: _?.brand_colors ?? null
482
+ };
483
+ }, D = (e) => JSON.parse(e).amount / 1e6, O = async (e, t, n = 200) => {
484
+ let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
485
+ if (r.length === 0) return [];
486
+ let i = [];
487
+ for (let e = 0; e < r.length; e += 250) i.push(r.slice(e, e + 250));
488
+ return (await Promise.all(i.map((t) => e.query("\n query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {\n nodes(ids: $mediaImageIds) {\n ... on MediaImage {\n id\n image {\n url(transform: { maxWidth: $size, maxHeight: $size })\n }\n }\n }\n }\n ", { variables: {
489
+ mediaImageIds: t,
490
+ size: n
491
+ } })))).flatMap((e) => e.nodes).flatMap((e) => e?.image ? [{
492
+ gid: e.id,
493
+ url: e.image.url
494
+ }] : []);
495
+ }, k = (e) => [
496
+ ...A(e),
497
+ ...ee(e),
498
+ ...te(e),
499
+ ...ne(e),
500
+ ...re(e),
501
+ ...ie(e),
502
+ ...ae(e),
503
+ ...oe(e),
504
+ ...se(e),
505
+ ...ce(e),
506
+ ...j(e),
507
+ ...M(e),
508
+ ...N(e)
509
+ ].filter((e) => e != null && !e.includes("placeholder")), A = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ee = (e) => e.dealBars.flatMap((e) => e.dealBarType === g.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), te = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ne = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), re = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ie = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
510
+ let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
511
+ return [...e, ...n];
512
+ }, []) : [], ae = (e) => {
513
+ if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
514
+ let t = e.collectionBreaks.mediaImageGID;
515
+ return t ? [t] : [];
516
+ }, oe = (e) => e.progressiveGifts ? [
517
+ ...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
518
+ e.progressiveGifts.style?.lockedMediaImageGID,
519
+ e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
520
+ ].filter((e) => e != null) : [], se = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ce = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), j = (e) => {
521
+ let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
522
+ return n ? [...t, n] : t;
523
+ }, M = (e) => (e.badges || []).flatMap((e) => e.badgeType === "custom" && e.imageGID ? [e.imageGID] : []), N = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], P = (e) => {
524
+ let t = [
525
+ ...F(e),
526
+ ...I(e),
527
+ ...L(e),
528
+ ...R(e),
529
+ ...z(e),
530
+ ...B(e),
531
+ ...V(e),
532
+ ...H(e)
533
+ ];
534
+ return Array.from(new Set(t.filter((e) => e != null)));
535
+ }, F = (e) => e.dealBars.flatMap(({ freeGifts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), I = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => e ? e.flatMap((e) => e.products ? e.products.map((e) => e.id) : []) : []).filter((e) => e != null), L = (e) => e.progressiveGiftsEnabled && e.progressiveGifts?.gifts.map((e) => e.productGID).filter((e) => e != null) || [], R = (e) => e.dealBars.flatMap(({ upsells: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null), z = (e) => e.dealBars.filter((e) => e.dealBarType === g.Bundle).flatMap(({ bundleProducts: e }) => e ? e.map((e) => e.productGID) : []).filter((e) => e != null).filter((e) => e !== "default"), B = (e) => e.dealBars.filter((e) => e.dealBarType === g.MixAndMatch).flatMap(({ bundleProducts: e }) => e ? e.flatMap((e) => [e.productGID, ...e.selectedProducts?.map((e) => e.id) ?? []]) : []).filter((e) => e != null).filter((e) => e !== "default"), V = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((e) => e.productGID).filter((e) => e != null), H = (e) => e.dealBars.filter((e) => e.dealBarType === g.Sku).flatMap(({ productGID: e }) => e ? [e] : []), U = class extends Error {
536
+ constructor({ status: e, operationName: t, graphqlErrors: n }) {
537
+ let r = n.length ? `: ${n.join("; ")}` : "";
538
+ super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
539
+ }
540
+ }, W = async (e, t) => {
541
+ let n = await e.text();
542
+ if (!n) throw Error("Empty graphql response");
543
+ let r;
544
+ try {
545
+ r = JSON.parse(n);
546
+ } catch (n) {
547
+ throw e.ok ? n : new U({
548
+ status: e.status,
549
+ operationName: t,
550
+ graphqlErrors: []
551
+ });
552
+ }
553
+ if (!e.ok || r.data === null || r.data === void 0) throw new U({
554
+ status: e.status,
555
+ operationName: t,
556
+ graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
557
+ });
558
+ return r.data;
559
+ }, G = class {
560
+ constructor(e, t) {
561
+ this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
562
+ }
563
+ async query(e, t) {
564
+ let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
565
+ return i && (r += `?operation_name=${i}`), W(await fetch(r, {
566
+ method: "POST",
567
+ headers: {
568
+ "Content-Type": "application/json",
569
+ "X-Shopify-Storefront-Access-Token": this.storefrontAccessToken
570
+ },
571
+ body: JSON.stringify({
572
+ query: e,
573
+ variables: n
574
+ })
575
+ }), i);
576
+ }
577
+ }, le = (e, t) => {
578
+ let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
579
+ for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
580
+ let i = e.filter((e) => e.blockVisibility === "selected-collections");
581
+ for (let e of i) t.collectionIds.some((t) => e.selectedCollectionIds.map(Number).includes(t)) && n.push(e);
582
+ let a = e.filter((e) => e.blockVisibility === "excluded-products");
583
+ for (let e of a) !e.excludedProductIds.map(Number).includes(t.id) && !(e.excludedCollectionIds || []).some((e) => t.collectionIds.includes(e)) && n.push(e);
584
+ let o = e.filter((e) => e.blockVisibility === "all-products");
585
+ for (let e of o) n.push(e);
586
+ return n;
587
+ }, ue = async (e, t, { country: n, language: r }) => {
588
+ let i = t.collectionBreaks;
589
+ if (!t.collectionBreaksEnabled || !i) return;
590
+ let a;
591
+ a = i.visibility === "deal-products" ? await _(e, {
592
+ country: n,
593
+ language: r,
594
+ blockVisibility: t.blockVisibility,
595
+ excludedProductGIDs: (t.excludedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
596
+ selectedProductGIDs: (t.selectedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
597
+ selectedCollectionGIDs: (t.selectedCollectionIds || []).map((e) => `gid://shopify/Collection/${e}`)
598
+ }) : await _(e, {
599
+ country: n,
600
+ language: r,
601
+ blockVisibility: i.visibility,
602
+ excludedProductGIDs: (i.excludedProducts || []).map(({ id: e }) => e),
603
+ selectedProductGIDs: (i.selectedProducts || []).map(({ id: e }) => e),
604
+ selectedCollectionGIDs: (i.selectedCollections || []).map(({ id: e }) => e)
605
+ });
606
+ let o = await y(e, {
607
+ country: n,
608
+ language: r,
609
+ productIds: a.map((e) => Number(e.split("/").pop())),
610
+ useExternalMetafieldNamespace: !0
611
+ });
612
+ return o = o.filter((e) => e.availableForSale), o;
613
+ }, de = ({ language: e, dealBlockId: t }) => {
614
+ let n = {
615
+ "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
616
+ "system.invalid_variant": "Sorry, this is not currently available.",
617
+ "system.unavailable_option_value": "Unavailable",
618
+ "system.confirm": "Confirm",
619
+ "system.cancel": "Cancel",
620
+ "system.free": "FREE",
621
+ "system.search": "Search",
622
+ "system.quantity": "Quantity",
623
+ "system.subscription_plan": "Subscription plan",
624
+ "system.remove": "Remove",
625
+ "system.sort_by": "Sort by",
626
+ "system.sort_relevance": "Relevance",
627
+ "system.sort_newest_first": "Newest first",
628
+ "system.sort_price_low_to_high": "Price: Low → High",
629
+ "system.sort_price_high_to_low": "Price: High → Low",
630
+ "system.no_results_found": "No results found",
631
+ "system.no_results_description": "We can't find any item matching your search.",
632
+ "system.clear_search": "Clear search",
633
+ "system.no_products_available": "No products available",
634
+ "system.original_price": "Original price:",
635
+ "system.price": "Price:",
636
+ "system.letters_only": "Only letters are allowed.",
637
+ "system.numbers_only": "Only numbers are allowed.",
638
+ "system.personalisation_required_alert": "Please add personalisation for every item to continue."
639
+ }, r = e ? fe(e) : void 0;
640
+ return {
641
+ ...n,
642
+ ...r?.system,
643
+ ...r?.dealBlocks[t]
644
+ };
747
645
  }, fe = (e) => {
748
- var t, a, r;
749
- return e.progressiveGifts ? [
750
- ...((t = e.progressiveGifts.gifts) == null ? void 0 : t.map((s) => s.mediaImageGID)) || [],
751
- (a = e.progressiveGifts.style) == null ? void 0 : a.lockedMediaImageGID,
752
- (r = e.progressiveGifts.dealBarStyle) == null ? void 0 : r.lockedMediaImageGID
753
- ].filter((s) => s != null) : [];
754
- }, ge = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((t) => [t.mediaImageGID, t.badgeImageGID]).filter((t) => t != null), ye = (e) => e.dealBars.map((t) => {
755
- var a;
756
- return (a = t.productPersonalisation) == null ? void 0 : a.mediaImageGID;
757
- }).filter((t) => t != null), he = (e) => {
758
- var r, s;
759
- const t = e.dealBars.map((l) => {
760
- var o;
761
- return (o = l.highlights) == null ? void 0 : o.customIconGID;
762
- }).filter((l) => l != null), a = (s = (r = e.subscriptions) == null ? void 0 : r.highlights) == null ? void 0 : s.customIconGID;
763
- return a ? [...t, a] : t;
764
- }, be = (e) => (e.badges || []).flatMap(
765
- (t) => t.badgeType === "custom" && t.imageGID ? [t.imageGID] : []
766
- ), ve = (e) => !e.savingsSummaryEnabled || !e.savingsSummary ? [] : e.savingsSummary.customIconGID ? [e.savingsSummary.customIconGID] : [], _e = (e) => {
767
- const t = [
768
- ...Ie(e),
769
- ...Pe(e),
770
- ...Se(e),
771
- ...ke(e),
772
- ...we(e),
773
- ...$e(e),
774
- ...Ne(e),
775
- ...De(e)
776
- ];
777
- return Array.from(new Set(t.filter((a) => a != null)));
778
- }, Ie = (e) => e.dealBars.flatMap(
779
- ({ freeGifts: t }) => t ? t.map((a) => a.productGID) : []
780
- ).filter((t) => t != null), Pe = (e) => e.dealBars.flatMap(
781
- ({ multipleGiftsSelectors: t }) => t ? t.flatMap(
782
- (a) => a.products ? a.products.map((r) => r.id) : []
783
- ) : []
784
- ).filter((t) => t != null), Se = (e) => {
785
- var t;
786
- return e.progressiveGiftsEnabled ? ((t = e.progressiveGifts) == null ? void 0 : t.gifts.map((a) => a.productGID).filter((a) => a != null)) || [] : [];
787
- }, ke = (e) => e.dealBars.flatMap(({ upsells: t }) => t ? t.map((a) => a.productGID) : []).filter((t) => t != null), we = (e) => e.dealBars.filter((t) => t.dealBarType === k.Bundle).flatMap(
788
- ({ bundleProducts: t }) => t ? t.map((a) => a.productGID) : []
789
- ).filter((t) => t != null).filter((t) => t !== "default"), $e = (e) => e.dealBars.filter((t) => t.dealBarType === k.MixAndMatch).flatMap(
790
- ({ bundleProducts: t }) => t ? t.flatMap((a) => {
791
- var r;
792
- return [
793
- a.productGID,
794
- ...((r = a.selectedProducts) == null ? void 0 : r.map((s) => s.id)) ?? []
795
- ];
796
- }) : []
797
- ).filter((t) => t != null).filter((t) => t !== "default"), Ne = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.map((t) => t.productGID).filter((t) => t != null), De = (e) => e.dealBars.filter((t) => t.dealBarType === k.Sku).flatMap(({ productGID: t }) => t ? [t] : []);
798
- class O extends Error {
799
- constructor({
800
- status: t,
801
- operationName: a,
802
- graphqlErrors: r
803
- }) {
804
- const s = r.length ? `: ${r.join("; ")}` : "";
805
- super(
806
- `Storefront API ${a ?? "query"} failed (HTTP ${t})${s}`
807
- ), this.name = "StorefrontApiError", this.status = t, this.operationName = a, this.graphqlErrors = r;
808
- }
809
- }
810
- const Ae = async (e, t) => {
811
- const a = await e.text();
812
- if (!a)
813
- throw new Error("Empty graphql response");
814
- let r;
815
- try {
816
- r = JSON.parse(a);
817
- } catch (s) {
818
- throw e.ok ? s : new O({
819
- status: e.status,
820
- operationName: t,
821
- graphqlErrors: []
822
- });
823
- }
824
- if (!e.ok || r.data === null || r.data === void 0)
825
- throw new O({
826
- status: e.status,
827
- operationName: t,
828
- graphqlErrors: (r.errors ?? []).map(({ message: s }) => s).filter(Boolean)
829
- });
830
- return r.data;
831
- };
832
- class xe {
833
- constructor(t, a) {
834
- this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = a, this.shopifyDomain = t;
835
- }
836
- async query(t, a) {
837
- var i;
838
- const r = (a == null ? void 0 : a.variables) ?? {};
839
- let s = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;
840
- const l = (i = t.match(/query\s+(\w+)/)) == null ? void 0 : i[1];
841
- l && (s += `?operation_name=${l}`);
842
- const o = await fetch(s, {
843
- method: "POST",
844
- headers: {
845
- "Content-Type": "application/json",
846
- "X-Shopify-Storefront-Access-Token": this.storefrontAccessToken
847
- },
848
- body: JSON.stringify({
849
- query: t,
850
- variables: r
851
- })
852
- });
853
- return Ae(o, l);
854
- }
855
- }
856
- const Ee = async (e, t, { country: a, language: r }) => {
857
- const s = t.collectionBreaks;
858
- if (!t.collectionBreaksEnabled || !s) return;
859
- let l;
860
- s.visibility === "deal-products" ? l = await T(e, {
861
- country: a,
862
- language: r,
863
- blockVisibility: t.blockVisibility,
864
- excludedProductGIDs: (t.excludedProductIds || []).map(
865
- (i) => `gid://shopify/Product/${i}`
866
- ),
867
- selectedProductGIDs: (t.selectedProductIds || []).map(
868
- (i) => `gid://shopify/Product/${i}`
869
- ),
870
- selectedCollectionGIDs: (t.selectedCollectionIds || []).map(
871
- (i) => `gid://shopify/Collection/${i}`
872
- )
873
- }) : l = await T(e, {
874
- country: a,
875
- language: r,
876
- blockVisibility: s.visibility,
877
- excludedProductGIDs: (s.excludedProducts || []).map(
878
- ({ id: i }) => i
879
- ),
880
- selectedProductGIDs: (s.selectedProducts || []).map(
881
- ({ id: i }) => i
882
- ),
883
- selectedCollectionGIDs: (s.selectedCollections || []).map(
884
- ({ id: i }) => i
885
- )
886
- });
887
- let o = await A(e, {
888
- country: a,
889
- language: r,
890
- productIds: l.map((i) => Number(i.split("/").pop())),
891
- useExternalMetafieldNamespace: !0
892
- });
893
- return o = o.filter(
894
- (i) => i.availableForSale
895
- ), o;
896
- }, Be = ({
897
- language: e,
898
- dealBlockId: t
899
- }) => {
900
- const a = {
901
- "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
902
- "system.invalid_variant": "Sorry, this is not currently available.",
903
- "system.unavailable_option_value": "Unavailable",
904
- "system.confirm": "Confirm",
905
- "system.cancel": "Cancel",
906
- "system.free": "FREE",
907
- "system.search": "Search",
908
- "system.quantity": "Quantity",
909
- "system.subscription_plan": "Subscription plan",
910
- "system.remove": "Remove",
911
- "system.sort_by": "Sort by",
912
- "system.sort_relevance": "Relevance",
913
- "system.sort_newest_first": "Newest first",
914
- "system.sort_price_low_to_high": "Price: Low → High",
915
- "system.sort_price_high_to_low": "Price: High → Low",
916
- "system.no_results_found": "No results found",
917
- "system.no_results_description": "We can't find any item matching your search.",
918
- "system.clear_search": "Clear search",
919
- "system.no_products_available": "No products available",
920
- "system.original_price": "Original price:",
921
- "system.price": "Price:",
922
- "system.letters_only": "Only letters are allowed.",
923
- "system.numbers_only": "Only numbers are allowed.",
924
- "system.personalisation_required_alert": "Please add personalisation for every item to continue."
925
- }, r = e ? Ge(e) : void 0;
926
- return {
927
- ...a,
928
- ...r == null ? void 0 : r.system,
929
- ...r == null ? void 0 : r.dealBlocks[t]
930
- };
931
- }, Ge = (e) => {
932
- var s;
933
- if (typeof document > "u") return;
934
- const t = document.querySelector("script#kaching-bundles-translations");
935
- if (!(t != null && t.textContent)) return;
936
- let a;
937
- try {
938
- a = JSON.parse(t.textContent);
939
- } catch {
940
- return;
941
- }
942
- const r = V(e);
943
- return (s = a.find(
944
- (l) => V(l.locale) === r
945
- )) == null ? void 0 : s.translations;
946
- }, V = (e) => e.toLowerCase().replace(/_/g, "-"), Ce = "2026-07", Te = async (e, {
947
- productId: t,
948
- dealBlockId: a,
949
- country: r = void 0,
950
- language: s = void 0
951
- }) => {
952
- var l, o;
953
- try {
954
- const i = [Number(t.split("/").pop())], d = new Me(e);
955
- r = r || ((l = d.i18n) == null ? void 0 : l.country), s = s || ((o = d.i18n) == null ? void 0 : o.language);
956
- const u = await se(d, {
957
- language: s,
958
- country: r,
959
- useExternalMetafieldNamespace: !0
960
- });
961
- d.shopifyDomain = u.shopifyDomain;
962
- const c = u.storefrontAccessToken ? new xe(
963
- u.shopifyDomain,
964
- u.storefrontAccessToken
965
- ) : d, [p, g] = await Promise.all([
966
- A(c, {
967
- country: r,
968
- language: s,
969
- productIds: i,
970
- useExternalMetafieldNamespace: !0
971
- }),
972
- Z(c, {
973
- useExternalMetafieldNamespace: !0,
974
- useMetaobjects: u.featureFlags.storefront_metaobjects
975
- })
976
- ]), y = p[0];
977
- if (!y)
978
- return null;
979
- const h = H(g, y);
980
- let n;
981
- if (a ? (n = h.find(
982
- (P) => P.id === a || P.nanoId === a
983
- ), n || (n = h[0])) : n = h[0], !n)
984
- return null;
985
- const m = le(n), b = _e(n), [I, _, f, v] = await Promise.all([
986
- A(c, {
987
- country: r,
988
- language: s,
989
- productIds: b,
990
- useExternalMetafieldNamespace: !0
991
- }),
992
- ne(c, m, 300),
993
- Ee(c, n, {
994
- country: r,
995
- language: s
996
- }),
997
- Be({ language: s, dealBlockId: n.id })
998
- ]);
999
- return {
1000
- product: y,
1001
- dealBlock: n,
1002
- config: u,
1003
- otherProducts: I,
1004
- mediaImages: _,
1005
- collectionBreaksProducts: f ?? [],
1006
- translations: v
1007
- };
1008
- } catch (i) {
1009
- return console.error(i), null;
1010
- }
1011
- };
1012
- class Me {
1013
- constructor(t) {
1014
- this.storefront = t, this.shopifyDomain = "";
1015
- }
1016
- async query(t, a) {
1017
- var r;
1018
- if ("query" in this.storefront && "i18n" in this.storefront)
1019
- return await this.storefront.query(t, a);
1020
- if ("graphql" in this.storefront) {
1021
- const s = await this.storefront.graphql(t, a);
1022
- if ((r = s.errors) != null && r.length)
1023
- throw new Error(
1024
- s.errors.map((l) => l.message).join(`
1025
- `)
1026
- );
1027
- return s.data;
1028
- }
1029
- if ("request" in this.storefront)
1030
- return (await this.storefront.request(t, a)).data;
1031
- if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
1032
- const s = await fetch(
1033
- `https://${this.storefront.shopifyDomain}/api/${Ce}/graphql.json`,
1034
- {
1035
- body: JSON.stringify({
1036
- query: t,
1037
- variables: a == null ? void 0 : a.variables
1038
- }),
1039
- headers: {
1040
- "Content-Type": "application/json",
1041
- "X-Shopify-Storefront-Access-Token": this.storefront.storefrontAccessToken
1042
- },
1043
- method: "POST"
1044
- }
1045
- );
1046
- if (!s.ok)
1047
- throw new Error(s.statusText);
1048
- return (await s.json()).data;
1049
- } else {
1050
- const s = await fetch(this.storefront.getStorefrontApiUrl(), {
1051
- body: JSON.stringify({
1052
- query: t,
1053
- variables: a == null ? void 0 : a.variables
1054
- }),
1055
- headers: this.storefront.getPublicTokenHeaders(),
1056
- method: "POST"
1057
- });
1058
- if (!s.ok)
1059
- throw new Error(s.statusText);
1060
- return (await s.json()).data;
1061
- }
1062
- }
1063
- get i18n() {
1064
- if ("i18n" in this.storefront)
1065
- return this.storefront.i18n;
1066
- }
1067
- }
1068
- const at = Te, $ = "kaching-bundles-block", U = 1e4, qe = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", je = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", N = /* @__PURE__ */ new WeakSet(), Oe = async (e) => {
1069
- const t = e.document;
1070
- if (!e.customElements.get($)) {
1071
- if (N.has(t))
1072
- return x(e, $);
1073
- N.add(t);
1074
- try {
1075
- await Fe(e);
1076
- } catch (a) {
1077
- throw N.delete(t), a;
1078
- }
1079
- }
1080
- }, Ve = () => typeof window < "u" && typeof window.__KACHING_DEV__ < "u", Ue = () => Ve() ? qe : je, Fe = (e) => {
1081
- const t = e.document;
1082
- return new Promise((a, r) => {
1083
- const s = Ue();
1084
- if (t.querySelector(
1085
- `script[src="${s}"]`
1086
- )) {
1087
- x(e, $).then(a).catch(r);
1088
- return;
1089
- }
1090
- const o = t.createElement("script");
1091
- o.src = s, o.onload = () => x(e, $).then(a).catch(r), o.onerror = () => r(new Error("Failed to load script")), t.head.appendChild(o);
1092
- });
1093
- }, x = (e, t) => new Promise((a, r) => {
1094
- if (e.customElements.get(t)) {
1095
- a();
1096
- return;
1097
- }
1098
- Promise.race([
1099
- e.customElements.whenDefined(t),
1100
- new Promise(
1101
- (s, l) => setTimeout(
1102
- () => l(
1103
- new Error(
1104
- `Custom element "${t}" failed to register within ${U}ms`
1105
- )
1106
- ),
1107
- U
1108
- )
1109
- )
1110
- ]).then(() => a()).catch(r);
646
+ if (typeof document > "u") return;
647
+ let t = document.querySelector("script#kaching-bundles-translations");
648
+ if (!t?.textContent) return;
649
+ let n;
650
+ try {
651
+ n = JSON.parse(t.textContent);
652
+ } catch {
653
+ return;
654
+ }
655
+ let r = K(e);
656
+ return n.find((e) => K(e.locale) === r)?.translations;
657
+ }, K = (e) => e.toLowerCase().replace(/_/g, "-"), pe = "2026-07", me = async (e, { productId: t, dealBlockId: n, country: r = void 0, language: i = void 0 }) => {
658
+ try {
659
+ let a = [Number(t.split("/").pop())], o = new he(e);
660
+ r ||= o.i18n?.country, i ||= o.i18n?.language;
661
+ let s = await E(o, {
662
+ language: i,
663
+ country: r,
664
+ useExternalMetafieldNamespace: !0
665
+ });
666
+ o.shopifyDomain = s.shopifyDomain;
667
+ let c = s.storefrontAccessToken ? new G(s.shopifyDomain, s.storefrontAccessToken) : o, [l, u] = await Promise.all([y(c, {
668
+ country: r,
669
+ language: i,
670
+ productIds: a,
671
+ useExternalMetafieldNamespace: !0
672
+ }), p(c, {
673
+ useExternalMetafieldNamespace: !0,
674
+ useMetaobjects: s.featureFlags.storefront_metaobjects
675
+ })]), d = l[0];
676
+ if (!d) return null;
677
+ let f = le(u, d), m;
678
+ if (n ? (m = f.find((e) => e.id === n || e.nanoId === n), m ||= f[0]) : m = f[0], !m) return null;
679
+ let h = k(m), g = P(m), [_, v, b, x] = await Promise.all([
680
+ y(c, {
681
+ country: r,
682
+ language: i,
683
+ productIds: g,
684
+ useExternalMetafieldNamespace: !0
685
+ }),
686
+ O(c, h, 300),
687
+ ue(c, m, {
688
+ country: r,
689
+ language: i
690
+ }),
691
+ de({
692
+ language: i,
693
+ dealBlockId: m.id
694
+ })
695
+ ]);
696
+ return {
697
+ product: d,
698
+ dealBlock: m,
699
+ config: s,
700
+ otherProducts: _,
701
+ mediaImages: v,
702
+ collectionBreaksProducts: b ?? [],
703
+ translations: x
704
+ };
705
+ } catch (e) {
706
+ return console.error(e), null;
707
+ }
708
+ }, he = class {
709
+ constructor(e) {
710
+ this.storefront = e, this.shopifyDomain = "";
711
+ }
712
+ async query(e, t) {
713
+ if ("query" in this.storefront && "i18n" in this.storefront) return await this.storefront.query(e, t);
714
+ if ("graphql" in this.storefront) {
715
+ let n = await this.storefront.graphql(e, t);
716
+ if (n.errors?.length) throw Error(n.errors.map((e) => e.message).join("\n"));
717
+ return n.data;
718
+ }
719
+ if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
720
+ if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
721
+ let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${pe}/graphql.json`, {
722
+ body: JSON.stringify({
723
+ query: e,
724
+ variables: t?.variables
725
+ }),
726
+ headers: {
727
+ "Content-Type": "application/json",
728
+ "X-Shopify-Storefront-Access-Token": this.storefront.storefrontAccessToken
729
+ },
730
+ method: "POST"
731
+ });
732
+ if (!n.ok) throw Error(n.statusText);
733
+ return (await n.json()).data;
734
+ }
735
+ {
736
+ let n = await fetch(this.storefront.getStorefrontApiUrl(), {
737
+ body: JSON.stringify({
738
+ query: e,
739
+ variables: t?.variables
740
+ }),
741
+ headers: this.storefront.getPublicTokenHeaders(),
742
+ method: "POST"
743
+ });
744
+ if (!n.ok) throw Error(n.statusText);
745
+ return (await n.json()).data;
746
+ }
747
+ }
748
+ get i18n() {
749
+ if ("i18n" in this.storefront) return this.storefront.i18n;
750
+ }
751
+ }, ge = me, q = "kaching-bundles-block", J = 1e4, _e = "https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js", ve = "https://bundles-integrations.kachingappz.app/kaching-bundles-block.js", Y = /* @__PURE__ */ new WeakSet(), ye = async (e) => {
752
+ let t = e.document;
753
+ if (!e.customElements.get(q)) {
754
+ if (Y.has(t)) return X(e, q);
755
+ Y.add(t);
756
+ try {
757
+ await Se(e);
758
+ } catch (e) {
759
+ throw Y.delete(t), e;
760
+ }
761
+ }
762
+ }, be = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, xe = () => be() ? _e : ve, Se = (e) => {
763
+ let t = e.document;
764
+ return new Promise((n, r) => {
765
+ let i = xe();
766
+ if (t.querySelector(`script[src="${i}"]`)) {
767
+ X(e, q).then(n).catch(r);
768
+ return;
769
+ }
770
+ let a = t.createElement("script");
771
+ a.src = i, a.onload = () => X(e, q).then(n).catch(r), a.onerror = () => r(/* @__PURE__ */ Error("Failed to load script")), t.head.appendChild(a);
772
+ });
773
+ }, X = (e, t) => new Promise((n, r) => {
774
+ 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 ${J}ms`)), J))]).then(() => n()).catch(r);
1111
775
  });
1112
- var E = /* @__PURE__ */ ((e) => (e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e))(E || {});
1113
- const S = "a-f\\d", Le = `#?[${S}]{3}[${S}]?`, Re = `#?[${S}]{6}([${S}]{2})?`, Je = new RegExp(`[^#${S}]`, "gi"), ze = new RegExp(`^${Le}$|^${Re}$`, "i");
1114
- function Qe(e, t = {}) {
1115
- if (typeof e != "string" || Je.test(e) || !ze.test(e))
1116
- throw new TypeError("Expected a valid hex string");
1117
- e = e.replace(/^#/, "");
1118
- let a = 1;
1119
- e.length === 8 && (a = Number.parseInt(e.slice(6, 8), 16) / 255, e = e.slice(0, 6)), e.length === 4 && (a = 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]);
1120
- const r = Number.parseInt(e, 16), s = r >> 16, l = r >> 8 & 255, o = r & 255, i = typeof t.alpha == "number" ? t.alpha : a;
1121
- if (t.format === "array")
1122
- return [s, l, o, i];
1123
- if (t.format === "css") {
1124
- const d = i === 1 ? "" : ` / ${Number((i * 100).toFixed(2))}%`;
1125
- return `rgb(${s} ${l} ${o}${d})`;
1126
- }
1127
- return { red: s, green: l, blue: o, alpha: i };
776
+ [
777
+ "primaryBackground",
778
+ "secondaryBackground",
779
+ "primaryText",
780
+ "secondaryText",
781
+ "border",
782
+ "overlay",
783
+ "primaryAccent",
784
+ "primaryAccentText",
785
+ "badgeBackground",
786
+ "badgeText",
787
+ "error"
788
+ ].map((e) => `brand_${e}`);
789
+ var Z = /* @__PURE__ */ function(e) {
790
+ return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
791
+ }({}), Q = "a-f\\d", Ce = `#?[${Q}]{3}[${Q}]?`, we = `#?[${Q}]{6}([${Q}]{2})?`, Te = RegExp(`[^#${Q}]`, "gi"), Ee = RegExp(`^${Ce}$|^${we}$`, "i");
792
+ function De(e, t = {}) {
793
+ if (typeof e != "string" || Te.test(e) || !Ee.test(e)) throw TypeError("Expected a valid hex string");
794
+ e = e.replace(/^#/, "");
795
+ let n = 1;
796
+ 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]);
797
+ let r = Number.parseInt(e, 16), i = r >> 16, a = r >> 8 & 255, o = r & 255, s = typeof t.alpha == "number" ? t.alpha : n;
798
+ return t.format === "array" ? [
799
+ i,
800
+ a,
801
+ o,
802
+ s
803
+ ] : t.format === "css" ? `rgb(${i} ${a} ${o}${s === 1 ? "" : ` / ${Number((s * 100).toFixed(2))}%`})` : {
804
+ red: i,
805
+ green: a,
806
+ blue: o,
807
+ alpha: s
808
+ };
1128
809
  }
1129
- const He = ({ price: e }) => ({
1130
- id: 123,
1131
- handle: "123",
1132
- url: null,
1133
- availableForSale: !0,
1134
- requiresSellingPlan: !1,
1135
- title: "",
1136
- image: null,
1137
- selectedVariantId: 456,
1138
- collectionIds: [],
1139
- options: [],
1140
- sellingPlans: [],
1141
- variants: [
1142
- {
1143
- id: 456,
1144
- availableForSale: !0,
1145
- price: Math.round((e ?? 10) * 100),
1146
- compareAtPrice: null,
1147
- options: [],
1148
- imageId: null,
1149
- image: null,
1150
- sellingPlans: [],
1151
- inventoryManagement: null,
1152
- inventoryPolicy: null,
1153
- inventoryQuantity: 50,
1154
- unitPriceMeasurement: null
1155
- }
1156
- ],
1157
- metafields: {
1158
- text: null,
1159
- text2: null,
1160
- text3: null,
1161
- text4: null
1162
- },
1163
- isNativeBundle: !1
1164
- }), Ke = () => ({
1165
- shopifyDomain: "",
1166
- moneyFormat: "${{amount_with_comma_separator}}",
1167
- locale: "en",
1168
- liquidLocale: "en",
1169
- country: "US",
1170
- marketId: 0,
1171
- productId: null,
1172
- storefrontAccessToken: null,
1173
- includeSellingPlans: !1,
1174
- includeAvailableQuantity: !1,
1175
- customApiHost: null,
1176
- keepQuantityInput: !1,
1177
- ignoreDeselect: !1,
1178
- ignoreUnitPrice: !1,
1179
- requireCustomerLogin: !1,
1180
- abTestsRunning: !1,
1181
- webPixel: !1,
1182
- b2bCustomer: !1,
1183
- isLoggedIn: !1,
1184
- preview: !1,
1185
- previewAlerts: !1,
1186
- previewScratchOff: !1,
1187
- currencyRate: 1,
1188
- defaultTranslations: {
1189
- "system.out_of_stock": "",
1190
- "system.invalid_variant": "",
1191
- "system.unavailable_option_value": "",
1192
- "system.confirm": "",
1193
- "system.cancel": "",
1194
- "system.free": "",
1195
- "system.search": "",
1196
- "system.quantity": "",
1197
- "system.subscription_plan": "",
1198
- "system.remove": "",
1199
- "system.sort_by": "",
1200
- "system.sort_relevance": "",
1201
- "system.sort_newest_first": "",
1202
- "system.sort_price_low_to_high": "",
1203
- "system.sort_price_high_to_low": "",
1204
- "system.no_results_found": "",
1205
- "system.no_results_description": "",
1206
- "system.clear_search": "",
1207
- "system.no_products_available": "",
1208
- "system.original_price": "",
1209
- "system.price": "",
1210
- "system.letters_only": "",
1211
- "system.numbers_only": ""
1212
- },
1213
- customSelectors: {
1214
- quantity: null,
1215
- addToCartButton: null,
1216
- variantPicker: null
1217
- },
1218
- shopCustomStyles: "",
1219
- featureFlags: {}
1220
- }), We = ({
1221
- color: e,
1222
- cornerRadius: t
1223
- }) => {
1224
- const a = {
1225
- id: "123",
1226
- nanoId: "123",
1227
- blockName: "Bundle",
1228
- discountName: "",
1229
- blockTitle: "BUNDLE & SAVE",
1230
- blockLayout: "vertical",
1231
- blockVisibility: "all-products",
1232
- marketId: null,
1233
- currency: null,
1234
- excludedProductIds: [],
1235
- excludedCollectionIds: [],
1236
- selectedProductIds: [],
1237
- selectedCollectionIds: [],
1238
- excludeB2bCustomers: !1,
1239
- excludePos: !1,
1240
- startTimestamp: 175811496e4,
1241
- endTimestamp: null,
1242
- differentVariantsEnabled: !0,
1243
- hideVariantPicker: !1,
1244
- showPricesPerItem: !1,
1245
- showBothPrices: !1,
1246
- useProductCompareAtPrice: !0,
1247
- showPricesWithoutDecimals: !1,
1248
- priceRounding: !1,
1249
- priceRoundingPrecision: ".00",
1250
- updateNativePrice: !1,
1251
- updateNativePriceType: "item",
1252
- skipCart: !1,
1253
- showVariantsForSingleQuantity: !0,
1254
- preselectedDealBarId: "1f-9",
1255
- defaultVariantsV2: [],
1256
- collectionBreaksEnabled: !1,
1257
- collectionBreaks: null,
1258
- chooseProductModal: null,
1259
- timerEnabled: !1,
1260
- timer: null,
1261
- subscriptionsEnabled: !1,
1262
- subscriptions: null,
1263
- stickyAtcEnabled: !1,
1264
- stickyAtc: null,
1265
- progressiveGiftsEnabled: !1,
1266
- progressiveGifts: null,
1267
- checkboxUpsellsEnabled: !1,
1268
- checkboxUpsells: null,
1269
- lowStockAlertEnabled: !1,
1270
- lowStockAlert: null,
1271
- dealBars: [
1272
- {
1273
- id: "PfFU",
1274
- dealBarType: E.QuantityBreak,
1275
- title: "1 pack",
1276
- subtitle: "Standard price",
1277
- label: "",
1278
- quantity: 1,
1279
- discountType: "default",
1280
- discountValue: "",
1281
- badgeStyle: "simple",
1282
- badgeText: "",
1283
- badgeImageGID: null,
1284
- mediaImageGID: null,
1285
- freeGifts: [],
1286
- multipleGiftsSelectors: [],
1287
- upsells: [],
1288
- showAsSoldOutEnabled: !1,
1289
- showAsSoldOut: null,
1290
- productPersonalisation: null
1291
- },
1292
- {
1293
- id: "1f-9",
1294
- dealBarType: E.QuantityBreak,
1295
- title: "2 pack",
1296
- subtitle: "You save {{saved_percentage}}",
1297
- label: "SAVE {{saved_total}}",
1298
- quantity: 2,
1299
- discountType: "percentage",
1300
- discountValue: "15",
1301
- badgeStyle: "most-popular",
1302
- badgeText: "",
1303
- badgeImageGID: null,
1304
- mediaImageGID: null,
1305
- freeGifts: [],
1306
- multipleGiftsSelectors: [],
1307
- upsells: [],
1308
- showAsSoldOutEnabled: !1,
1309
- showAsSoldOut: null,
1310
- productPersonalisation: null
1311
- }
1312
- ],
1313
- badgesEnabled: !0,
1314
- badges: [
1315
- {
1316
- id: "bdg1",
1317
- attachedTo: { type: "dealBar", dealBarId: "1f-9" },
1318
- text: "MOST POPULAR",
1319
- colors: null,
1320
- badgeType: "most-popular",
1321
- size: 90
1322
- }
1323
- ],
1324
- cornerRadius: t ?? 8,
1325
- spacing: 1,
1326
- colors: {
1327
- background: {
1328
- red: 255,
1329
- green: 255,
1330
- blue: 255,
1331
- alpha: 1
1332
- },
1333
- selectedBackground: {
1334
- red: 255,
1335
- green: 255,
1336
- blue: 255,
1337
- alpha: 1
1338
- },
1339
- border: {
1340
- red: 0,
1341
- green: 0,
1342
- blue: 0,
1343
- alpha: 1
1344
- },
1345
- blockTitle: {
1346
- red: 0,
1347
- green: 0,
1348
- blue: 0,
1349
- alpha: 1
1350
- },
1351
- title: {
1352
- red: 0,
1353
- green: 0,
1354
- blue: 0,
1355
- alpha: 1
1356
- },
1357
- subtitle: {
1358
- red: 85,
1359
- green: 85,
1360
- blue: 85,
1361
- alpha: 1
1362
- },
1363
- price: {
1364
- red: 0,
1365
- green: 0,
1366
- blue: 0,
1367
- alpha: 1
1368
- },
1369
- fullPrice: {
1370
- red: 85,
1371
- green: 85,
1372
- blue: 85,
1373
- alpha: 1
1374
- },
1375
- labelBackground: {
1376
- red: 238,
1377
- green: 238,
1378
- blue: 238,
1379
- alpha: 1
1380
- },
1381
- label: {
1382
- red: 0,
1383
- green: 0,
1384
- blue: 0,
1385
- alpha: 1
1386
- },
1387
- badgeBackground: {
1388
- red: 255,
1389
- green: 17,
1390
- blue: 17,
1391
- alpha: 1
1392
- },
1393
- badgeText: {
1394
- red: 255,
1395
- green: 255,
1396
- blue: 255,
1397
- alpha: 1
1398
- },
1399
- freeGiftBackground: {
1400
- red: 0,
1401
- green: 0,
1402
- blue: 0,
1403
- alpha: 0.3
1404
- },
1405
- freeGiftText: {
1406
- red: 0,
1407
- green: 0,
1408
- blue: 0,
1409
- alpha: 1
1410
- },
1411
- freeGiftSelectedBackground: {
1412
- red: 0,
1413
- green: 0,
1414
- blue: 0,
1415
- alpha: 1
1416
- },
1417
- freeGiftSelectedText: {
1418
- red: 255,
1419
- green: 255,
1420
- blue: 255,
1421
- alpha: 1
1422
- },
1423
- upsellBackground: {
1424
- red: 0,
1425
- green: 0,
1426
- blue: 0,
1427
- alpha: 0.2
1428
- },
1429
- upsellText: {
1430
- red: 0,
1431
- green: 0,
1432
- blue: 0,
1433
- alpha: 1
1434
- },
1435
- upsellSelectedBackground: {
1436
- red: 0,
1437
- green: 0,
1438
- blue: 0,
1439
- alpha: 0.2
1440
- },
1441
- upsellSelectedText: {
1442
- red: 0,
1443
- green: 0,
1444
- blue: 0,
1445
- alpha: 1
1446
- }
1447
- },
1448
- fonts: {
1449
- blockTitle: {
1450
- size: "14",
1451
- style: "bold"
1452
- },
1453
- title: {
1454
- size: "20",
1455
- style: "bold"
1456
- },
1457
- subtitle: {
1458
- size: "14",
1459
- style: "regular"
1460
- },
1461
- label: {
1462
- size: "12",
1463
- style: "regular"
1464
- },
1465
- freeGift: {
1466
- size: "13",
1467
- style: "bold"
1468
- },
1469
- upsell: {
1470
- size: "13",
1471
- style: "bold"
1472
- },
1473
- unitLabel: {
1474
- size: "14",
1475
- style: "regular"
1476
- }
1477
- },
1478
- swatchOptions: [],
1479
- swatchSize: 18,
1480
- swatchShape: "circle",
1481
- imageSize: 48,
1482
- imageCornerRadius: 6
1483
- };
1484
- return e !== void 0 && (a.colors.border = { ...Qe(e), alpha: 1 }), a;
1485
- }, st = ({
1486
- data: e,
1487
- selectedVariantId: t,
1488
- preview: a,
1489
- onLinesChange: r,
1490
- targetWindow: s
1491
- }) => {
1492
- const l = B(null), [o, i] = z(!1), d = B(!1);
1493
- D(() => {
1494
- if (!l.current || o) return;
1495
- (async () => {
1496
- await Oe(s ?? window), i(!0);
1497
- })();
1498
- }, [o, s]), D(() => {
1499
- const c = l.current;
1500
- if (!o || !c) return;
1501
- const p = () => {
1502
- const y = c.items().map((h) => ({
1503
- merchandiseId: `gid://shopify/ProductVariant/${h.id}`,
1504
- quantity: h.quantity,
1505
- attributes: Object.entries(h.properties).map(([n, m]) => ({
1506
- key: n,
1507
- value: String(m)
1508
- })),
1509
- sellingPlanId: h.selling_plan ? `gid://shopify/SellingPlan/${h.selling_plan}` : void 0
1510
- }));
1511
- r == null || r(y);
1512
- };
1513
- return d.current || (typeof c.items == "function" ? p() : c.addEventListener("kaching-bundles-block-loaded", p), d.current = !0), c.addEventListener("variants-changed", p), () => {
1514
- c.removeEventListener("kaching-bundles-block-loaded", p), c.removeEventListener("variants-changed", p);
1515
- };
1516
- }, [o, r]);
1517
- const u = e ? Ye(e, t) : a ? Ze(a) : null;
1518
- return Xe(() => {
1519
- const c = l.current;
1520
- if (!(!c || !u))
1521
- for (const [p, g] of Object.entries(u.jsonAttributes))
1522
- c.getAttribute(p) !== g && c.setAttribute(p, g);
1523
- }), u ? /* @__PURE__ */ J(
1524
- "kaching-bundles-block",
1525
- {
1526
- ref: l,
1527
- "deal-block-id": u.dealBlockId,
1528
- ...u.jsonAttributes,
1529
- "current-variant-id": u.currentVariantId
1530
- }
1531
- ) : null;
1532
- }, Xe = typeof window > "u" ? D : Q, Ye = ({
1533
- config: e,
1534
- dealBlock: t,
1535
- product: a,
1536
- otherProducts: r,
1537
- mediaImages: s,
1538
- collectionBreaksProducts: l,
1539
- translations: o
1540
- }, i) => ({
1541
- dealBlockId: t.id,
1542
- currentVariantId: i ? i.split("/").pop() : String(a.variants[0].id),
1543
- jsonAttributes: {
1544
- config: JSON.stringify(e),
1545
- "deal-block": JSON.stringify(t),
1546
- "media-images": JSON.stringify(s),
1547
- product: JSON.stringify(a),
1548
- "other-products": JSON.stringify(r),
1549
- "collection-breaks-products": JSON.stringify(l),
1550
- translations: JSON.stringify(o)
1551
- }
1552
- }), Ze = ({
1553
- cornerRadius: e,
1554
- color: t,
1555
- price: a
1556
- }) => {
1557
- const r = He({ price: a }), s = Ke(), l = We({ color: t, cornerRadius: e });
1558
- return {
1559
- dealBlockId: l.id,
1560
- currentVariantId: String(r.variants[0].id),
1561
- jsonAttributes: {
1562
- config: JSON.stringify(s),
1563
- "deal-block": JSON.stringify(l),
1564
- "media-images": JSON.stringify([]),
1565
- product: JSON.stringify(r),
1566
- "other-products": JSON.stringify([]),
1567
- "collection-breaks-products": JSON.stringify([]),
1568
- translations: JSON.stringify({})
1569
- }
1570
- };
1571
- };
1572
- export {
1573
- st as KachingBundle,
1574
- at as fetchKachingBundlesData
810
+ // src/react/preview.ts
811
+ var $ = ({ price: e }) => ({
812
+ id: 123,
813
+ handle: "123",
814
+ url: null,
815
+ availableForSale: !0,
816
+ requiresSellingPlan: !1,
817
+ title: "",
818
+ image: null,
819
+ selectedVariantId: 456,
820
+ collectionIds: [],
821
+ options: [],
822
+ sellingPlans: [],
823
+ variants: [{
824
+ id: 456,
825
+ availableForSale: !0,
826
+ price: Math.round((e ?? 10) * 100),
827
+ compareAtPrice: null,
828
+ options: [],
829
+ imageId: null,
830
+ image: null,
831
+ sellingPlans: [],
832
+ inventoryManagement: null,
833
+ inventoryPolicy: null,
834
+ inventoryQuantity: 50,
835
+ unitPriceMeasurement: null
836
+ }],
837
+ metafields: {
838
+ text: null,
839
+ text2: null,
840
+ text3: null,
841
+ text4: null
842
+ },
843
+ isNativeBundle: !1
844
+ }), Oe = () => ({
845
+ shopifyDomain: "",
846
+ moneyFormat: "${{amount_with_comma_separator}}",
847
+ locale: "en",
848
+ liquidLocale: "en",
849
+ country: "US",
850
+ marketId: 0,
851
+ productId: null,
852
+ storefrontAccessToken: null,
853
+ includeSellingPlans: !1,
854
+ includeAvailableQuantity: !1,
855
+ customApiHost: null,
856
+ keepQuantityInput: !1,
857
+ ignoreDeselect: !1,
858
+ ignoreUnitPrice: !1,
859
+ requireCustomerLogin: !1,
860
+ abTestsRunning: !1,
861
+ webPixel: !1,
862
+ b2bCustomer: !1,
863
+ isLoggedIn: !1,
864
+ preview: !1,
865
+ previewAlerts: !1,
866
+ previewScratchOff: !1,
867
+ currencyRate: 1,
868
+ defaultTranslations: {
869
+ "system.out_of_stock": "",
870
+ "system.invalid_variant": "",
871
+ "system.unavailable_option_value": "",
872
+ "system.confirm": "",
873
+ "system.cancel": "",
874
+ "system.free": "",
875
+ "system.search": "",
876
+ "system.quantity": "",
877
+ "system.subscription_plan": "",
878
+ "system.remove": "",
879
+ "system.sort_by": "",
880
+ "system.sort_relevance": "",
881
+ "system.sort_newest_first": "",
882
+ "system.sort_price_low_to_high": "",
883
+ "system.sort_price_high_to_low": "",
884
+ "system.no_results_found": "",
885
+ "system.no_results_description": "",
886
+ "system.clear_search": "",
887
+ "system.no_products_available": "",
888
+ "system.original_price": "",
889
+ "system.price": "",
890
+ "system.letters_only": "",
891
+ "system.numbers_only": ""
892
+ },
893
+ customSelectors: {
894
+ quantity: null,
895
+ addToCartButton: null,
896
+ variantPicker: null
897
+ },
898
+ shopCustomStyles: "",
899
+ featureFlags: {}
900
+ }), ke = ({ color: e, cornerRadius: t }) => {
901
+ let n = {
902
+ id: "123",
903
+ nanoId: "123",
904
+ blockName: "Bundle",
905
+ discountName: "",
906
+ blockTitle: "BUNDLE & SAVE",
907
+ blockLayout: "vertical",
908
+ blockVisibility: "all-products",
909
+ marketId: null,
910
+ currency: null,
911
+ excludedProductIds: [],
912
+ excludedCollectionIds: [],
913
+ selectedProductIds: [],
914
+ selectedCollectionIds: [],
915
+ excludeB2bCustomers: !1,
916
+ excludePos: !1,
917
+ startTimestamp: 175811496e4,
918
+ endTimestamp: null,
919
+ differentVariantsEnabled: !0,
920
+ hideVariantPicker: !1,
921
+ showPricesPerItem: !1,
922
+ showBothPrices: !1,
923
+ useProductCompareAtPrice: !0,
924
+ showPricesWithoutDecimals: !1,
925
+ priceRounding: !1,
926
+ priceRoundingPrecision: ".00",
927
+ updateNativePrice: !1,
928
+ updateNativePriceType: "item",
929
+ skipCart: !1,
930
+ showVariantsForSingleQuantity: !0,
931
+ preselectedDealBarId: "1f-9",
932
+ defaultVariantsV2: [],
933
+ collectionBreaksEnabled: !1,
934
+ collectionBreaks: null,
935
+ chooseProductModal: null,
936
+ timerEnabled: !1,
937
+ timer: null,
938
+ subscriptionsEnabled: !1,
939
+ subscriptions: null,
940
+ stickyAtcEnabled: !1,
941
+ stickyAtc: null,
942
+ progressiveGiftsEnabled: !1,
943
+ progressiveGifts: null,
944
+ checkboxUpsellsEnabled: !1,
945
+ checkboxUpsells: null,
946
+ lowStockAlertEnabled: !1,
947
+ lowStockAlert: null,
948
+ dealBars: [{
949
+ id: "PfFU",
950
+ dealBarType: Z.QuantityBreak,
951
+ title: "1 pack",
952
+ subtitle: "Standard price",
953
+ label: "",
954
+ quantity: 1,
955
+ discountType: "default",
956
+ discountValue: "",
957
+ badgeStyle: "simple",
958
+ badgeText: "",
959
+ badgeImageGID: null,
960
+ mediaImageGID: null,
961
+ freeGifts: [],
962
+ multipleGiftsSelectors: [],
963
+ upsells: [],
964
+ showAsSoldOutEnabled: !1,
965
+ showAsSoldOut: null,
966
+ productPersonalisation: null
967
+ }, {
968
+ id: "1f-9",
969
+ dealBarType: Z.QuantityBreak,
970
+ title: "2 pack",
971
+ subtitle: "You save {{saved_percentage}}",
972
+ label: "SAVE {{saved_total}}",
973
+ quantity: 2,
974
+ discountType: "percentage",
975
+ discountValue: "15",
976
+ badgeStyle: "most-popular",
977
+ badgeText: "",
978
+ badgeImageGID: null,
979
+ mediaImageGID: null,
980
+ freeGifts: [],
981
+ multipleGiftsSelectors: [],
982
+ upsells: [],
983
+ showAsSoldOutEnabled: !1,
984
+ showAsSoldOut: null,
985
+ productPersonalisation: null
986
+ }],
987
+ badgesEnabled: !0,
988
+ badges: [{
989
+ id: "bdg1",
990
+ attachedTo: {
991
+ type: "dealBar",
992
+ dealBarId: "1f-9"
993
+ },
994
+ text: "MOST POPULAR",
995
+ colors: null,
996
+ badgeType: "most-popular",
997
+ size: 90
998
+ }],
999
+ cornerRadius: t ?? 8,
1000
+ spacing: 1,
1001
+ colors: {
1002
+ background: {
1003
+ red: 255,
1004
+ green: 255,
1005
+ blue: 255,
1006
+ alpha: 1
1007
+ },
1008
+ selectedBackground: {
1009
+ red: 255,
1010
+ green: 255,
1011
+ blue: 255,
1012
+ alpha: 1
1013
+ },
1014
+ border: {
1015
+ red: 0,
1016
+ green: 0,
1017
+ blue: 0,
1018
+ alpha: 1
1019
+ },
1020
+ blockTitle: {
1021
+ red: 0,
1022
+ green: 0,
1023
+ blue: 0,
1024
+ alpha: 1
1025
+ },
1026
+ title: {
1027
+ red: 0,
1028
+ green: 0,
1029
+ blue: 0,
1030
+ alpha: 1
1031
+ },
1032
+ subtitle: {
1033
+ red: 85,
1034
+ green: 85,
1035
+ blue: 85,
1036
+ alpha: 1
1037
+ },
1038
+ price: {
1039
+ red: 0,
1040
+ green: 0,
1041
+ blue: 0,
1042
+ alpha: 1
1043
+ },
1044
+ fullPrice: {
1045
+ red: 85,
1046
+ green: 85,
1047
+ blue: 85,
1048
+ alpha: 1
1049
+ },
1050
+ labelBackground: {
1051
+ red: 238,
1052
+ green: 238,
1053
+ blue: 238,
1054
+ alpha: 1
1055
+ },
1056
+ label: {
1057
+ red: 0,
1058
+ green: 0,
1059
+ blue: 0,
1060
+ alpha: 1
1061
+ },
1062
+ badgeBackground: {
1063
+ red: 255,
1064
+ green: 17,
1065
+ blue: 17,
1066
+ alpha: 1
1067
+ },
1068
+ badgeText: {
1069
+ red: 255,
1070
+ green: 255,
1071
+ blue: 255,
1072
+ alpha: 1
1073
+ },
1074
+ freeGiftBackground: {
1075
+ red: 0,
1076
+ green: 0,
1077
+ blue: 0,
1078
+ alpha: .3
1079
+ },
1080
+ freeGiftText: {
1081
+ red: 0,
1082
+ green: 0,
1083
+ blue: 0,
1084
+ alpha: 1
1085
+ },
1086
+ freeGiftSelectedBackground: {
1087
+ red: 0,
1088
+ green: 0,
1089
+ blue: 0,
1090
+ alpha: 1
1091
+ },
1092
+ freeGiftSelectedText: {
1093
+ red: 255,
1094
+ green: 255,
1095
+ blue: 255,
1096
+ alpha: 1
1097
+ },
1098
+ upsellBackground: {
1099
+ red: 0,
1100
+ green: 0,
1101
+ blue: 0,
1102
+ alpha: .2
1103
+ },
1104
+ upsellText: {
1105
+ red: 0,
1106
+ green: 0,
1107
+ blue: 0,
1108
+ alpha: 1
1109
+ },
1110
+ upsellSelectedBackground: {
1111
+ red: 0,
1112
+ green: 0,
1113
+ blue: 0,
1114
+ alpha: .2
1115
+ },
1116
+ upsellSelectedText: {
1117
+ red: 0,
1118
+ green: 0,
1119
+ blue: 0,
1120
+ alpha: 1
1121
+ }
1122
+ },
1123
+ fonts: {
1124
+ blockTitle: {
1125
+ size: "14",
1126
+ style: "bold"
1127
+ },
1128
+ title: {
1129
+ size: "20",
1130
+ style: "bold"
1131
+ },
1132
+ subtitle: {
1133
+ size: "14",
1134
+ style: "regular"
1135
+ },
1136
+ label: {
1137
+ size: "12",
1138
+ style: "regular"
1139
+ },
1140
+ freeGift: {
1141
+ size: "13",
1142
+ style: "bold"
1143
+ },
1144
+ upsell: {
1145
+ size: "13",
1146
+ style: "bold"
1147
+ },
1148
+ unitLabel: {
1149
+ size: "14",
1150
+ style: "regular"
1151
+ }
1152
+ },
1153
+ swatchOptions: [],
1154
+ swatchSize: 18,
1155
+ swatchShape: "circle",
1156
+ imageSize: 48,
1157
+ imageCornerRadius: 6
1158
+ };
1159
+ return e !== void 0 && (n.colors.border = {
1160
+ ...De(e),
1161
+ alpha: 1
1162
+ }), n;
1163
+ }, Ae = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1164
+ let l = n(null), [u, d] = r(!1), f = n(!1);
1165
+ e(() => {
1166
+ l.current && !u && (async () => {
1167
+ await ye(c ?? window), d(!0);
1168
+ })();
1169
+ }, [u, c]), e(() => {
1170
+ let e = l.current;
1171
+ if (!u || !e) return;
1172
+ let t = () => {
1173
+ let t = e.items().map((e) => ({
1174
+ merchandiseId: `gid://shopify/ProductVariant/${e.id}`,
1175
+ quantity: e.quantity,
1176
+ attributes: Object.entries(e.properties).map(([e, t]) => ({
1177
+ key: e,
1178
+ value: String(t)
1179
+ })),
1180
+ sellingPlanId: e.selling_plan ? `gid://shopify/SellingPlan/${e.selling_plan}` : void 0
1181
+ }));
1182
+ s?.(t);
1183
+ };
1184
+ return f.current ||= (typeof e.items == "function" ? t() : e.addEventListener("kaching-bundles-block-loaded", t), !0), e.addEventListener("variants-changed", t), () => {
1185
+ e.removeEventListener("kaching-bundles-block-loaded", t), e.removeEventListener("variants-changed", t);
1186
+ };
1187
+ }, [u, s]);
1188
+ let p = t ? Me(t, a) : o ? Ne(o) : null;
1189
+ return je(() => {
1190
+ let e = l.current;
1191
+ if (e && p) for (let [t, n] of Object.entries(p.jsonAttributes)) e.getAttribute(t) !== n && e.setAttribute(t, n);
1192
+ }), p ? /* @__PURE__ */ i("kaching-bundles-block", {
1193
+ ref: l,
1194
+ "deal-block-id": p.dealBlockId,
1195
+ ...p.jsonAttributes,
1196
+ "current-variant-id": p.currentVariantId
1197
+ }) : null;
1198
+ }, je = typeof window > "u" ? e : t, Me = ({ config: e, dealBlock: t, product: n, otherProducts: r, mediaImages: i, collectionBreaksProducts: a, translations: o }, s) => ({
1199
+ dealBlockId: t.id,
1200
+ currentVariantId: s ? s.split("/").pop() : String(n.variants[0].id),
1201
+ jsonAttributes: {
1202
+ config: JSON.stringify(e),
1203
+ "deal-block": JSON.stringify(t),
1204
+ "media-images": JSON.stringify(i),
1205
+ product: JSON.stringify(n),
1206
+ "other-products": JSON.stringify(r),
1207
+ "collection-breaks-products": JSON.stringify(a),
1208
+ translations: JSON.stringify(o)
1209
+ }
1210
+ }), Ne = ({ cornerRadius: e, color: t, price: n }) => {
1211
+ let r = $({ price: n }), i = Oe(), a = ke({
1212
+ color: t,
1213
+ cornerRadius: e
1214
+ });
1215
+ return {
1216
+ dealBlockId: a.id,
1217
+ currentVariantId: String(r.variants[0].id),
1218
+ jsonAttributes: {
1219
+ config: JSON.stringify(i),
1220
+ "deal-block": JSON.stringify(a),
1221
+ "media-images": JSON.stringify([]),
1222
+ product: JSON.stringify(r),
1223
+ "other-products": JSON.stringify([]),
1224
+ "collection-breaks-products": JSON.stringify([]),
1225
+ translations: JSON.stringify({})
1226
+ }
1227
+ };
1575
1228
  };
1229
+ export { Ae as KachingBundle, ge as fetchKachingBundlesData };