@kachingappz/bundles-js 1.1.2 → 1.1.3

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,50 @@
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
+ }, g = async (e, { country: t, language: n, blockVisibility: r, excludedProductGIDs: i, selectedProductGIDs: a, selectedCollectionGIDs: o, limit: s = 1e3 }) => {
37
+ switch (r) {
38
+ case "selected-products": return a.slice(0, s);
39
+ case "all-products":
40
+ case "excluded-products": {
41
+ let a = f({
42
+ country: t,
43
+ language: n
44
+ }), o = [], c = null;
45
+ for (; o.length < s;) {
46
+ let t = Math.min(s - o.length, 250), n = await e.query(`
47
+ query FetchProductGIDs($limit: Int!, $cursor: String) ${a} {
136
48
  products(first: $limit, after: $cursor) {
137
49
  nodes {
138
50
  id
@@ -143,27 +55,25 @@ const H = (e, t) => {
143
55
  }
144
56
  }
145
57
  }
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} {
58
+ `, { variables: {
59
+ limit: t,
60
+ cursor: c
61
+ } });
62
+ if (o.push(...n.products.nodes.map((e) => e.id)), !n.products.pageInfo.hasNextPage) break;
63
+ c = n.products.pageInfo.endCursor;
64
+ }
65
+ if (r === "excluded-products") {
66
+ let e = new Set(i);
67
+ o = o.filter((t) => !e.has(t));
68
+ }
69
+ return o;
70
+ }
71
+ case "selected-collections": {
72
+ let r = f({
73
+ country: t,
74
+ language: n
75
+ }), i = (await e.query(`
76
+ query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${r} {
167
77
  nodes(ids: $collectionGIDs) {
168
78
  ... on Collection {
169
79
  products(first: $limit) {
@@ -174,77 +84,23 @@ const H = (e, t) => {
174
84
  }
175
85
  }
176
86
  }
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} {
87
+ `, { variables: {
88
+ collectionGIDs: o,
89
+ limit: Math.min(s, 250)
90
+ } })).nodes.filter((e) => e !== null).flatMap((e) => e.products.nodes.map((e) => e.id));
91
+ return Array.from(new Set(i)).slice(0, s);
92
+ }
93
+ }
94
+ }, _ = "\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", v = async (e, { country: t, language: n, productIds: r, includeSellingPlans: i = !0, includeAvailableQuantity: a = !0, includeProductRating: o = !1, useExternalMetafieldNamespace: s = !1, batchSize: c = 250, onBatchError: l, variantImageTransform: u = {
95
+ maxWidth: 200,
96
+ maxHeight: 200
97
+ } }) => {
98
+ if (!r.length) return [];
99
+ let d = r.map((e) => typeof e == "string" && e.startsWith("gid://") ? e : `gid://shopify/Product/${e}`), p = f({
100
+ country: t,
101
+ language: n
102
+ }), m = `
103
+ query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $includeProductRating: Boolean!, $metafieldNamespace: String!, $variantImageTransform: ImageTransformInput) ${p} {
248
104
  shop {
249
105
  currencyRateConstant: metafield(namespace: $metafieldNamespace, key: "currency_rate_constant") {
250
106
  value
@@ -278,7 +134,7 @@ const H = (e, t) => {
278
134
  }
279
135
  variants(first: 250) {
280
136
  nodes {
281
- ${L}
137
+ ${_}
282
138
  }
283
139
  }
284
140
  collections(first: 50) {
@@ -298,6 +154,12 @@ const H = (e, t) => {
298
154
  metafield4: metafield(namespace: $metafieldNamespace, key: "text4") {
299
155
  value
300
156
  }
157
+ reviewsRating: metafield(namespace: "reviews", key: "rating") @include(if: $includeProductRating) {
158
+ value
159
+ }
160
+ reviewsRatingCount: metafield(namespace: "reviews", key: "rating_count") @include(if: $includeProductRating) {
161
+ value
162
+ }
301
163
  requiresSellingPlan
302
164
  sellingPlanGroups(first: 100) @include(if: $includeSellingPlans) {
303
165
  nodes {
@@ -330,90 +192,50 @@ const H = (e, t) => {
330
192
  }
331
193
  }
332
194
  }
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
- `
195
+ `, h = s ? "app--2935586817--kaching_bundles" : "$app:kaching_bundles", g = [], v = Math.min(c, 250);
196
+ for (let e = 0; e < d.length; e += v) g.push(d.slice(e, e + v));
197
+ let x = 1, S = async (t) => {
198
+ let n = await e.query(m, { variables: {
199
+ productGIDs: t,
200
+ includeSellingPlans: i,
201
+ includeAvailableQuantity: a,
202
+ includeProductRating: o,
203
+ metafieldNamespace: h,
204
+ variantImageTransform: u
205
+ } });
206
+ return n.shop.currencyRateConstant && (x = JSON.parse(n.shop.currencyRateConstant.value).amount / 1e6), n;
207
+ }, C;
208
+ if (l) {
209
+ let e = await Promise.allSettled(g.map(S));
210
+ for (let t of e) t.status === "rejected" && l(t.reason instanceof Error ? t.reason : Error(String(t.reason)));
211
+ C = e.filter((e) => e.status === "fulfilled").flatMap((e) => e.value.nodes);
212
+ } else C = (await Promise.all(g.map(S))).flatMap((e) => e.nodes);
213
+ let w = C.filter((e) => e != null);
214
+ if (l) {
215
+ let t = await Promise.allSettled(w.map(async (t) => b(await y(e, t, {
216
+ includeSellingPlans: i,
217
+ includeAvailableQuantity: a,
218
+ variantImageTransform: u
219
+ }, p), e.shopifyDomain, x))), n = [];
220
+ for (let e of t) e.status === "fulfilled" ? n.push(e.value) : l(e.reason instanceof Error ? e.reason : Error(String(e.reason)));
221
+ return n;
222
+ }
223
+ return (await Promise.all(w.map((t) => y(e, t, {
224
+ includeSellingPlans: i,
225
+ includeAvailableQuantity: a,
226
+ variantImageTransform: u
227
+ }, p)))).map((t) => b(t, e.shopifyDomain, x));
228
+ }, y = async (e, t, n, r = "") => {
229
+ if (t.variants.nodes.length < 250) return t;
230
+ let i = /* @__PURE__ */ new Set(), a = [], o = [], s = async (s) => {
231
+ let c = !0, l = null;
232
+ for (; c;) {
233
+ let { nodes: u, pageInfo: d } = (await e.query(`
412
234
  query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $variantImageTransform: ImageTransformInput) ${r} {
413
235
  product(id: $productGID) {
414
236
  variants(first: 250, after: $cursor, reverse: $reverse) {
415
237
  nodes {
416
- ${L}
238
+ ${_}
417
239
  }
418
240
  pageInfo {
419
241
  endCursor
@@ -422,169 +244,129 @@ const H = (e, t) => {
422
244
  }
423
245
  }
424
246
  }
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} {
247
+ `, { variables: {
248
+ productGID: t.id,
249
+ cursor: l,
250
+ reverse: s,
251
+ ...n
252
+ } })).product.variants;
253
+ for (let e of u) {
254
+ if (i.has(e.id)) {
255
+ c = !1;
256
+ break;
257
+ }
258
+ i.add(e.id), s ? o.push(e) : a.push(e);
259
+ }
260
+ d.hasNextPage || (c = !1), l = d.endCursor;
261
+ }
262
+ };
263
+ return await Promise.all([s(!1), s(!0)]), t.variants.nodes = [...a, ...o.reverse()], t;
264
+ }, b = (e, t, n) => {
265
+ let r = e.variants.nodes.map(({ unitPriceMeasurement: e, ...t }) => ({
266
+ id: Number(t.id.split("/").pop()),
267
+ availableForSale: t.availableForSale,
268
+ price: Math.round(Number(t.price.amount) * 100),
269
+ compareAtPrice: t.compareAtPrice ? Math.round(Number(t.compareAtPrice.amount) * 100) : null,
270
+ options: t.selectedOptions.map((e) => e.value),
271
+ imageId: t.image ? Number(t.image.id.split("/").pop()) : null,
272
+ image: t.image?.url || null,
273
+ sellingPlans: t.sellingPlanAllocations?.nodes.map((e) => ({
274
+ id: Number(e.sellingPlan.id.split("/").pop()),
275
+ price: e.priceAdjustments.length > 0 ? Math.round(Number(e.priceAdjustments[0].price.amount) * 100) : Math.round(Number(t.price.amount) * 100),
276
+ compareAtPrice: e.priceAdjustments.length > 0 ? Math.round(Number(e.priceAdjustments[0].compareAtPrice.amount) * 100) : Math.round(Number(t.price.amount) * 100),
277
+ perDeliveryPrice: e.priceAdjustments.length > 0 ? Math.round(Number(e.priceAdjustments[0].perDeliveryPrice.amount) * 100) : Math.round(Number(t.price.amount) * 100)
278
+ })) || [],
279
+ inventoryManagement: null,
280
+ inventoryPolicy: null,
281
+ inventoryQuantity: t.quantityAvailable ?? null,
282
+ unitPriceMeasurement: e?.quantityUnit && e?.referenceUnit ? {
283
+ quantityValue: e.quantityValue,
284
+ quantityUnit: e.quantityUnit.toLowerCase(),
285
+ referenceValue: e.referenceValue,
286
+ referenceUnit: e.referenceUnit.toLowerCase()
287
+ } : null
288
+ })), i = e.options.map((e, t) => {
289
+ let n = e.optionValues.map((e) => ({
290
+ id: Number(e.id.split("/").pop()),
291
+ defaultName: e.name,
292
+ name: e.name,
293
+ swatch: {
294
+ color: e.swatch?.color || null,
295
+ image: e.swatch?.image?.previewImage?.url || null
296
+ }
297
+ }));
298
+ return {
299
+ defaultName: e.name,
300
+ name: e.name,
301
+ position: t + 1,
302
+ optionValues: C(n, t, r)
303
+ };
304
+ }), a = (e) => {
305
+ let t = e.priceAdjustments[0];
306
+ if (!t) return null;
307
+ let n = t.adjustmentValue;
308
+ switch (n.__typename) {
309
+ case "SellingPlanPercentagePriceAdjustment": return {
310
+ type: "percentage",
311
+ value: n.adjustmentPercentage
312
+ };
313
+ case "SellingPlanFixedAmountPriceAdjustment": return {
314
+ type: "fixed_amount",
315
+ value: o(n.adjustmentAmount.amount)
316
+ };
317
+ case "SellingPlanFixedPriceAdjustment": return {
318
+ type: "price",
319
+ value: o(n.price.amount)
320
+ };
321
+ default: throw Error(`Unknown price adjustment type: ${n.__typename}`);
322
+ }
323
+ }, o = (e) => n === 1 ? Number(e) * 100 : Math.round(Number(e) * 100 * n), s = e.sellingPlanGroups?.nodes.flatMap((e) => e.sellingPlans.nodes.map((e) => ({
324
+ id: Number(e.id.split("/").pop()),
325
+ name: e.name,
326
+ priceAdjustment: a(e)
327
+ }))) || [], c = e.variants.nodes.some((e) => e.requiresComponents);
328
+ return {
329
+ id: Number(e.id.split("/").pop()),
330
+ handle: e.handle,
331
+ url: e.onlineStoreUrl || `https://${t}/products/${e.handle}`,
332
+ availableForSale: e.availableForSale,
333
+ createdAt: e.createdAt,
334
+ title: e.title,
335
+ image: e.featuredImage?.url || null,
336
+ collectionIds: e.collections.nodes.map((e) => Number(e.id.split("/").pop())),
337
+ options: i,
338
+ selectedVariantId: Number(e.variants.nodes[0].id.split("/").pop()),
339
+ variants: r,
340
+ requiresSellingPlan: e.requiresSellingPlan,
341
+ sellingPlans: s,
342
+ isNativeBundle: c,
343
+ metafields: {
344
+ text: e.metafield?.value || null,
345
+ text2: e.metafield2?.value || null,
346
+ text3: e.metafield3?.value || null,
347
+ text4: e.metafield4?.value || null
348
+ },
349
+ rating: x(e.reviewsRating, e.reviewsRatingCount)
350
+ };
351
+ }, x = (e, t) => {
352
+ if (!e) return null;
353
+ let n = S(e.value);
354
+ if (n === null) return null;
355
+ let r = Number(t?.value);
356
+ return {
357
+ value: n,
358
+ count: Number.isInteger(r) && r > 0 ? r : null
359
+ };
360
+ }, S = (e) => {
361
+ try {
362
+ let { value: t, scale_max: n } = JSON.parse(e), r = Number(t) / Number(n) * 5;
363
+ return Number.isFinite(r) && r > 0 ? Math.min(5, r) : null;
364
+ } catch {
365
+ return null;
366
+ }
367
+ }, C = (e, t, n) => e.filter((e) => n.filter((n) => n.options[t] === e.name).length > 0), w = "app--2935586817", ee = async (e, { language: t, country: n, useExternalMetafieldNamespace: r }) => {
368
+ let i = r ? `${w}--kaching_bundles` : "$app:kaching_bundles", o = r ? w : "$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(`
369
+ query config($metafieldNamespace: String!, $settingsNamespace: String!) ${s} {
588
370
  localization {
589
371
  country {
590
372
  currency {
@@ -608,968 +390,833 @@ const H = (e, t) => {
608
390
  }
609
391
  }
610
392
  }
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
- );
393
+ `, { variables: {
394
+ metafieldNamespace: i,
395
+ settingsNamespace: o
396
+ } }), h = c === u ? l : a(c, {
397
+ language: t,
398
+ country: n
399
+ }), g = d ? T(d.value) : 1, _ = m ? JSON.parse(m.value) : null, v = _?.feature_flags ?? {}, y = _?.custom_selectors ?? {};
400
+ return {
401
+ shopifyDomain: p.host,
402
+ moneyFormat: h,
403
+ locale: t?.toLowerCase() || "en",
404
+ liquidLocale: t?.toLowerCase() || "en",
405
+ country: n ?? "US",
406
+ currencyRate: g,
407
+ marketId: 0,
408
+ productId: null,
409
+ storefrontAccessToken: _?.storefront_access_token ?? null,
410
+ includeSellingPlans: _?.include_selling_plans ?? !1,
411
+ includeAvailableQuantity: _?.include_available_quantity ?? !1,
412
+ customApiHost: _?.custom_api_host ?? null,
413
+ keepQuantityInput: _?.keep_quantity_input ?? !1,
414
+ ignoreDeselect: _?.ignore_deselect ?? !1,
415
+ ignoreUnitPrice: _?.ignore_unit_price ?? !1,
416
+ requireCustomerLogin: _?.require_customer_login ?? !1,
417
+ abTestsRunning: _?.ab_tests_running ?? !1,
418
+ webPixel: _?.web_pixel ?? !1,
419
+ b2bCustomer: !1,
420
+ isLoggedIn: !1,
421
+ preview: !1,
422
+ previewAlerts: !1,
423
+ previewScratchOff: !1,
424
+ defaultTranslations: {
425
+ "system.out_of_stock": "Out of stock",
426
+ "system.invalid_variant": "Invalid variant",
427
+ "system.unavailable_option_value": "Unavailable option value",
428
+ "system.confirm": "Confirm",
429
+ "system.cancel": "Cancel",
430
+ "system.free": "FREE",
431
+ "system.search": "Search",
432
+ "system.quantity": "Quantity",
433
+ "system.subscription_plan": "Subscription plan",
434
+ "system.remove": "Remove",
435
+ "system.sort_by": "Sort by",
436
+ "system.sort_relevance": "Relevance",
437
+ "system.sort_newest_first": "Newest first",
438
+ "system.sort_price_low_to_high": "Price: Low → High",
439
+ "system.sort_price_high_to_low": "Price: High → Low",
440
+ "system.no_results_found": "No results found",
441
+ "system.no_results_description": "We can't find any item matching your search.",
442
+ "system.clear_search": "Clear search",
443
+ "system.no_products_available": "No products available",
444
+ "system.original_price": "Original price:",
445
+ "system.price": "Price:",
446
+ "system.letters_only": "Only letters are allowed.",
447
+ "system.numbers_only": "Only numbers are allowed."
448
+ },
449
+ customSelectors: {
450
+ quantity: y.quantity ?? null,
451
+ addToCartButton: y.add_to_cart_button ?? null,
452
+ variantPicker: y.variant_picker ?? null,
453
+ price: y.price ?? null,
454
+ priceCompare: y.price_compare ?? null
455
+ },
456
+ shopCustomStyles: _?.shop_custom_styles ?? "",
457
+ featureFlags: v,
458
+ brandColors: _?.brand_colors ?? null
459
+ };
460
+ }, T = (e) => JSON.parse(e).amount / 1e6, te = async (e, t, n = 200) => {
461
+ let r = [...new Set(t.filter(Boolean).filter((e) => !e.startsWith("placeholder")))];
462
+ if (r.length === 0) return [];
463
+ let i = [];
464
+ for (let e = 0; e < r.length; e += 250) i.push(r.slice(e, e + 250));
465
+ 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: {
466
+ mediaImageIds: t,
467
+ size: n
468
+ } })))).flatMap((e) => e.nodes).flatMap((e) => e?.image ? [{
469
+ gid: e.id,
470
+ url: e.image.url
471
+ }] : []);
715
472
  };
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] : [];
473
+ [
474
+ "primaryBackground",
475
+ "secondaryBackground",
476
+ "primaryText",
477
+ "secondaryText",
478
+ "border",
479
+ "overlay",
480
+ "primaryAccent",
481
+ "primaryAccentText",
482
+ "badgeBackground",
483
+ "badgeText",
484
+ "error"
485
+ ].map((e) => `brand_${e}`);
486
+ var E = /* @__PURE__ */ function(e) {
487
+ return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
488
+ }({}), ne = (e) => [
489
+ ...re(e),
490
+ ...ie(e),
491
+ ...ae(e),
492
+ ...oe(e),
493
+ ...se(e),
494
+ ...ce(e),
495
+ ...D(e),
496
+ ...O(e),
497
+ ...k(e),
498
+ ...A(e),
499
+ ...j(e),
500
+ ...M(e),
501
+ ...N(e)
502
+ ].filter((e) => e != null && !e.includes("placeholder")), re = (e) => e.dealBars.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), ie = (e) => e.dealBars.flatMap((e) => e.dealBarType === E.Bundle ? e.bundleProducts.map((e) => e.mediaImageGID) : []).filter((e) => e != null), ae = (e) => e.dealBars.map(({ freeGifts: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), oe = (e) => e.dealBars.flatMap(({ multipleGiftsSelectors: e }) => (e || []).map((e) => e.mediaImageGID)).filter((e) => e != null), se = (e) => e.dealBars.map(({ upsells: e }) => (e || []).map((e) => e.mediaImageGID)).reduce((e, t) => e.concat(t), []).filter((e) => e != null), ce = (e) => e.swatchOptions ? e.swatchOptions.reduce((e, t) => {
503
+ let n = t.images.map((e) => e.mediaImageGID).filter((e) => e != null);
504
+ return [...e, ...n];
505
+ }, []) : [], D = (e) => {
506
+ if (!e.collectionBreaksEnabled || !e.collectionBreaks) return [];
507
+ let t = e.collectionBreaks.mediaImageGID;
508
+ return t ? [t] : [];
509
+ }, O = (e) => e.progressiveGifts ? [
510
+ ...e.progressiveGifts.gifts?.map((e) => e.mediaImageGID) || [],
511
+ e.progressiveGifts.style?.lockedMediaImageGID,
512
+ e.progressiveGifts.dealBarStyle?.lockedMediaImageGID
513
+ ].filter((e) => e != null) : [], k = (e) => !e.checkboxUpsellsEnabled || !e.checkboxUpsells ? [] : e.checkboxUpsells.upsells.flatMap((e) => [e.mediaImageGID, e.badgeImageGID]).filter((e) => e != null), A = (e) => e.dealBars.map((e) => e.productPersonalisation?.mediaImageGID).filter((e) => e != null), j = (e) => {
514
+ let t = e.dealBars.map((e) => e.highlights?.customIconGID).filter((e) => e != null), n = e.subscriptions?.highlights?.customIconGID;
515
+ return n ? [...t, n] : t;
516
+ }, 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) => {
517
+ let t = [
518
+ ...F(e),
519
+ ...I(e),
520
+ ...L(e),
521
+ ...R(e),
522
+ ...z(e),
523
+ ...B(e),
524
+ ...V(e),
525
+ ...H(e)
526
+ ];
527
+ return Array.from(new Set(t.filter((e) => e != null)));
528
+ }, 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 === E.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 === E.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 === E.Sku).flatMap(({ productGID: e }) => e ? [e] : []), U = class extends Error {
529
+ constructor({ status: e, operationName: t, graphqlErrors: n }) {
530
+ let r = n.length ? `: ${n.join("; ")}` : "";
531
+ super(`Storefront API ${t ?? "query"} failed (HTTP ${e})${r}`), this.name = "StorefrontApiError", this.status = e, this.operationName = t, this.graphqlErrors = n;
532
+ }
533
+ }, W = async (e, t) => {
534
+ let n = await e.text();
535
+ if (!n) throw Error("Empty graphql response");
536
+ let r;
537
+ try {
538
+ r = JSON.parse(n);
539
+ } catch (n) {
540
+ throw e.ok ? n : new U({
541
+ status: e.status,
542
+ operationName: t,
543
+ graphqlErrors: []
544
+ });
545
+ }
546
+ if (!e.ok || r.data === null || r.data === void 0) throw new U({
547
+ status: e.status,
548
+ operationName: t,
549
+ graphqlErrors: (r.errors ?? []).map(({ message: e }) => e).filter(Boolean)
550
+ });
551
+ return r.data;
552
+ }, G = class {
553
+ constructor(e, t) {
554
+ this.storefrontApiVersion = "2026-07", this.storefrontAccessToken = t, this.shopifyDomain = e;
555
+ }
556
+ async query(e, t) {
557
+ let n = t?.variables ?? {}, r = `https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`, i = e.match(/query\s+(\w+)/)?.[1];
558
+ return i && (r += `?operation_name=${i}`), W(await fetch(r, {
559
+ method: "POST",
560
+ headers: {
561
+ "Content-Type": "application/json",
562
+ "X-Shopify-Storefront-Access-Token": this.storefrontAccessToken
563
+ },
564
+ body: JSON.stringify({
565
+ query: e,
566
+ variables: n
567
+ })
568
+ }), i);
569
+ }
570
+ }, le = (e, t) => {
571
+ let n = [], r = e.filter((e) => e.blockVisibility === "selected-products");
572
+ for (let e of r) e.selectedProductIds.map(Number).includes(t.id) && n.push(e);
573
+ let i = e.filter((e) => e.blockVisibility === "selected-collections");
574
+ for (let e of i) t.collectionIds.some((t) => e.selectedCollectionIds.map(Number).includes(t)) && n.push(e);
575
+ let a = e.filter((e) => e.blockVisibility === "excluded-products");
576
+ for (let e of a) !e.excludedProductIds.map(Number).includes(t.id) && !(e.excludedCollectionIds || []).some((e) => t.collectionIds.includes(e)) && n.push(e);
577
+ let o = e.filter((e) => e.blockVisibility === "all-products");
578
+ for (let e of o) n.push(e);
579
+ return n;
580
+ }, ue = async (e, t, { country: n, language: r }) => {
581
+ let i = t.collectionBreaks;
582
+ if (!t.collectionBreaksEnabled || !i) return;
583
+ let a;
584
+ a = i.visibility === "deal-products" ? await g(e, {
585
+ country: n,
586
+ language: r,
587
+ blockVisibility: t.blockVisibility,
588
+ excludedProductGIDs: (t.excludedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
589
+ selectedProductGIDs: (t.selectedProductIds || []).map((e) => `gid://shopify/Product/${e}`),
590
+ selectedCollectionGIDs: (t.selectedCollectionIds || []).map((e) => `gid://shopify/Collection/${e}`)
591
+ }) : await g(e, {
592
+ country: n,
593
+ language: r,
594
+ blockVisibility: i.visibility,
595
+ excludedProductGIDs: (i.excludedProducts || []).map(({ id: e }) => e),
596
+ selectedProductGIDs: (i.selectedProducts || []).map(({ id: e }) => e),
597
+ selectedCollectionGIDs: (i.selectedCollections || []).map(({ id: e }) => e)
598
+ });
599
+ let o = await v(e, {
600
+ country: n,
601
+ language: r,
602
+ productIds: a.map((e) => Number(e.split("/").pop())),
603
+ useExternalMetafieldNamespace: !0
604
+ });
605
+ return o = o.filter((e) => e.availableForSale), o;
606
+ }, de = ({ language: e, dealBlockId: t }) => {
607
+ let n = {
608
+ "system.out_of_stock": "There's not enough items in our stock, please select smaller bundle.",
609
+ "system.invalid_variant": "Sorry, this is not currently available.",
610
+ "system.unavailable_option_value": "Unavailable",
611
+ "system.confirm": "Confirm",
612
+ "system.cancel": "Cancel",
613
+ "system.free": "FREE",
614
+ "system.search": "Search",
615
+ "system.quantity": "Quantity",
616
+ "system.subscription_plan": "Subscription plan",
617
+ "system.remove": "Remove",
618
+ "system.sort_by": "Sort by",
619
+ "system.sort_relevance": "Relevance",
620
+ "system.sort_newest_first": "Newest first",
621
+ "system.sort_price_low_to_high": "Price: Low → High",
622
+ "system.sort_price_high_to_low": "Price: High → Low",
623
+ "system.no_results_found": "No results found",
624
+ "system.no_results_description": "We can't find any item matching your search.",
625
+ "system.clear_search": "Clear search",
626
+ "system.no_products_available": "No products available",
627
+ "system.original_price": "Original price:",
628
+ "system.price": "Price:",
629
+ "system.letters_only": "Only letters are allowed.",
630
+ "system.numbers_only": "Only numbers are allowed.",
631
+ "system.personalisation_required_alert": "Please add personalisation for every item to continue."
632
+ }, r = e ? fe(e) : void 0;
633
+ return {
634
+ ...n,
635
+ ...r?.system,
636
+ ...r?.dealBlocks[t]
637
+ };
747
638
  }, 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);
639
+ if (typeof document > "u") return;
640
+ let t = document.querySelector("script#kaching-bundles-translations");
641
+ if (!t?.textContent) return;
642
+ let n;
643
+ try {
644
+ n = JSON.parse(t.textContent);
645
+ } catch {
646
+ return;
647
+ }
648
+ let r = K(e);
649
+ return n.find((e) => K(e.locale) === r)?.translations;
650
+ }, K = (e) => e.toLowerCase().replace(/_/g, "-"), pe = "2026-07", me = async (e, { productId: t, dealBlockId: n, country: r = void 0, language: i = void 0 }) => {
651
+ try {
652
+ let a = [Number(t.split("/").pop())], o = new he(e);
653
+ r ||= o.i18n?.country, i ||= o.i18n?.language;
654
+ let s = await ee(o, {
655
+ language: i,
656
+ country: r,
657
+ useExternalMetafieldNamespace: !0
658
+ });
659
+ o.shopifyDomain = s.shopifyDomain;
660
+ let c = s.storefrontAccessToken ? new G(s.shopifyDomain, s.storefrontAccessToken) : o, [l, u] = await Promise.all([v(c, {
661
+ country: r,
662
+ language: i,
663
+ productIds: a,
664
+ useExternalMetafieldNamespace: !0
665
+ }), p(c, {
666
+ useExternalMetafieldNamespace: !0,
667
+ useMetaobjects: s.featureFlags.storefront_metaobjects
668
+ })]), d = l[0];
669
+ if (!d) return null;
670
+ let f = le(u, d), m;
671
+ if (n ? (m = f.find((e) => e.id === n || e.nanoId === n), m ||= f[0]) : m = f[0], !m) return null;
672
+ let h = ne(m), g = P(m), [_, y, b, x] = await Promise.all([
673
+ v(c, {
674
+ country: r,
675
+ language: i,
676
+ productIds: g,
677
+ useExternalMetafieldNamespace: !0
678
+ }),
679
+ te(c, h, 300),
680
+ ue(c, m, {
681
+ country: r,
682
+ language: i
683
+ }),
684
+ de({
685
+ language: i,
686
+ dealBlockId: m.id
687
+ })
688
+ ]);
689
+ return {
690
+ product: d,
691
+ dealBlock: m,
692
+ config: s,
693
+ otherProducts: _,
694
+ mediaImages: y,
695
+ collectionBreaksProducts: b ?? [],
696
+ translations: x
697
+ };
698
+ } catch (e) {
699
+ return console.error(e), null;
700
+ }
701
+ }, he = class {
702
+ constructor(e) {
703
+ this.storefront = e, this.shopifyDomain = "";
704
+ }
705
+ async query(e, t) {
706
+ if ("query" in this.storefront && "i18n" in this.storefront) return await this.storefront.query(e, t);
707
+ if ("graphql" in this.storefront) {
708
+ let n = await this.storefront.graphql(e, t);
709
+ if (n.errors?.length) throw Error(n.errors.map((e) => e.message).join("\n"));
710
+ return n.data;
711
+ }
712
+ if ("request" in this.storefront) return (await this.storefront.request(e, t)).data;
713
+ if ("shopifyDomain" in this.storefront && "storefrontAccessToken" in this.storefront) {
714
+ let n = await fetch(`https://${this.storefront.shopifyDomain}/api/${pe}/graphql.json`, {
715
+ body: JSON.stringify({
716
+ query: e,
717
+ variables: t?.variables
718
+ }),
719
+ headers: {
720
+ "Content-Type": "application/json",
721
+ "X-Shopify-Storefront-Access-Token": this.storefront.storefrontAccessToken
722
+ },
723
+ method: "POST"
724
+ });
725
+ if (!n.ok) throw Error(n.statusText);
726
+ return (await n.json()).data;
727
+ }
728
+ {
729
+ let n = await fetch(this.storefront.getStorefrontApiUrl(), {
730
+ body: JSON.stringify({
731
+ query: e,
732
+ variables: t?.variables
733
+ }),
734
+ headers: this.storefront.getPublicTokenHeaders(),
735
+ method: "POST"
736
+ });
737
+ if (!n.ok) throw Error(n.statusText);
738
+ return (await n.json()).data;
739
+ }
740
+ }
741
+ get i18n() {
742
+ if ("i18n" in this.storefront) return this.storefront.i18n;
743
+ }
744
+ }, 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) => {
745
+ let t = e.document;
746
+ if (!e.customElements.get(q)) {
747
+ if (Y.has(t)) return X(e, q);
748
+ Y.add(t);
749
+ try {
750
+ await Se(e);
751
+ } catch (e) {
752
+ throw Y.delete(t), e;
753
+ }
754
+ }
755
+ }, be = () => typeof window < "u" && window.__KACHING_DEV__ !== void 0, xe = () => be() ? _e : ve, Se = (e) => {
756
+ let t = e.document;
757
+ return new Promise((n, r) => {
758
+ let i = xe();
759
+ if (t.querySelector(`script[src="${i}"]`)) {
760
+ X(e, q).then(n).catch(r);
761
+ return;
762
+ }
763
+ let a = t.createElement("script");
764
+ 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);
765
+ });
766
+ }, X = (e, t) => new Promise((n, r) => {
767
+ 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
768
  });
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 };
769
+ [
770
+ "primaryBackground",
771
+ "secondaryBackground",
772
+ "primaryText",
773
+ "secondaryText",
774
+ "border",
775
+ "overlay",
776
+ "primaryAccent",
777
+ "primaryAccentText",
778
+ "badgeBackground",
779
+ "badgeText",
780
+ "error"
781
+ ].map((e) => `brand_${e}`);
782
+ var Z = /* @__PURE__ */ function(e) {
783
+ return e.QuantityBreak = "quantity-break", e.Bxgy = "bxgy", e.Bundle = "bundle", e.MixAndMatch = "mix-and-match", e.Sku = "sku", e;
784
+ }({}), Q = "a-f\\d", Ce = `#?[${Q}]{3}[${Q}]?`, we = `#?[${Q}]{6}([${Q}]{2})?`, Te = RegExp(`[^#${Q}]`, "gi"), Ee = RegExp(`^${Ce}$|^${we}$`, "i");
785
+ function De(e, t = {}) {
786
+ if (typeof e != "string" || Te.test(e) || !Ee.test(e)) throw TypeError("Expected a valid hex string");
787
+ e = e.replace(/^#/, "");
788
+ let n = 1;
789
+ 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]);
790
+ let r = Number.parseInt(e, 16), i = r >> 16, a = r >> 8 & 255, o = r & 255, s = typeof t.alpha == "number" ? t.alpha : n;
791
+ return t.format === "array" ? [
792
+ i,
793
+ a,
794
+ o,
795
+ s
796
+ ] : t.format === "css" ? `rgb(${i} ${a} ${o}${s === 1 ? "" : ` / ${Number((s * 100).toFixed(2))}%`})` : {
797
+ red: i,
798
+ green: a,
799
+ blue: o,
800
+ alpha: s
801
+ };
1128
802
  }
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
803
+ // src/react/preview.ts
804
+ var $ = ({ price: e }) => ({
805
+ id: 123,
806
+ handle: "123",
807
+ url: null,
808
+ availableForSale: !0,
809
+ requiresSellingPlan: !1,
810
+ title: "",
811
+ image: null,
812
+ selectedVariantId: 456,
813
+ collectionIds: [],
814
+ options: [],
815
+ sellingPlans: [],
816
+ variants: [{
817
+ id: 456,
818
+ availableForSale: !0,
819
+ price: Math.round((e ?? 10) * 100),
820
+ compareAtPrice: null,
821
+ options: [],
822
+ imageId: null,
823
+ image: null,
824
+ sellingPlans: [],
825
+ inventoryManagement: null,
826
+ inventoryPolicy: null,
827
+ inventoryQuantity: 50,
828
+ unitPriceMeasurement: null
829
+ }],
830
+ metafields: {
831
+ text: null,
832
+ text2: null,
833
+ text3: null,
834
+ text4: null
835
+ },
836
+ isNativeBundle: !1
837
+ }), Oe = () => ({
838
+ shopifyDomain: "",
839
+ moneyFormat: "${{amount_with_comma_separator}}",
840
+ locale: "en",
841
+ liquidLocale: "en",
842
+ country: "US",
843
+ marketId: 0,
844
+ productId: null,
845
+ storefrontAccessToken: null,
846
+ includeSellingPlans: !1,
847
+ includeAvailableQuantity: !1,
848
+ customApiHost: null,
849
+ keepQuantityInput: !1,
850
+ ignoreDeselect: !1,
851
+ ignoreUnitPrice: !1,
852
+ requireCustomerLogin: !1,
853
+ abTestsRunning: !1,
854
+ webPixel: !1,
855
+ b2bCustomer: !1,
856
+ isLoggedIn: !1,
857
+ preview: !1,
858
+ previewAlerts: !1,
859
+ previewScratchOff: !1,
860
+ currencyRate: 1,
861
+ defaultTranslations: {
862
+ "system.out_of_stock": "",
863
+ "system.invalid_variant": "",
864
+ "system.unavailable_option_value": "",
865
+ "system.confirm": "",
866
+ "system.cancel": "",
867
+ "system.free": "",
868
+ "system.search": "",
869
+ "system.quantity": "",
870
+ "system.subscription_plan": "",
871
+ "system.remove": "",
872
+ "system.sort_by": "",
873
+ "system.sort_relevance": "",
874
+ "system.sort_newest_first": "",
875
+ "system.sort_price_low_to_high": "",
876
+ "system.sort_price_high_to_low": "",
877
+ "system.no_results_found": "",
878
+ "system.no_results_description": "",
879
+ "system.clear_search": "",
880
+ "system.no_products_available": "",
881
+ "system.original_price": "",
882
+ "system.price": "",
883
+ "system.letters_only": "",
884
+ "system.numbers_only": ""
885
+ },
886
+ customSelectors: {
887
+ quantity: null,
888
+ addToCartButton: null,
889
+ variantPicker: null
890
+ },
891
+ shopCustomStyles: "",
892
+ featureFlags: {}
893
+ }), ke = ({ color: e, cornerRadius: t }) => {
894
+ let n = {
895
+ id: "123",
896
+ nanoId: "123",
897
+ blockName: "Bundle",
898
+ discountName: "",
899
+ blockTitle: "BUNDLE & SAVE",
900
+ blockLayout: "vertical",
901
+ blockVisibility: "all-products",
902
+ marketId: null,
903
+ currency: null,
904
+ excludedProductIds: [],
905
+ excludedCollectionIds: [],
906
+ selectedProductIds: [],
907
+ selectedCollectionIds: [],
908
+ excludeB2bCustomers: !1,
909
+ excludePos: !1,
910
+ startTimestamp: 175811496e4,
911
+ endTimestamp: null,
912
+ differentVariantsEnabled: !0,
913
+ hideVariantPicker: !1,
914
+ showPricesPerItem: !1,
915
+ showBothPrices: !1,
916
+ useProductCompareAtPrice: !0,
917
+ showPricesWithoutDecimals: !1,
918
+ priceRounding: !1,
919
+ priceRoundingPrecision: ".00",
920
+ updateNativePrice: !1,
921
+ updateNativePriceType: "item",
922
+ skipCart: !1,
923
+ showVariantsForSingleQuantity: !0,
924
+ preselectedDealBarId: "1f-9",
925
+ defaultVariantsV2: [],
926
+ collectionBreaksEnabled: !1,
927
+ collectionBreaks: null,
928
+ chooseProductModal: null,
929
+ timerEnabled: !1,
930
+ timer: null,
931
+ subscriptionsEnabled: !1,
932
+ subscriptions: null,
933
+ stickyAtcEnabled: !1,
934
+ stickyAtc: null,
935
+ progressiveGiftsEnabled: !1,
936
+ progressiveGifts: null,
937
+ checkboxUpsellsEnabled: !1,
938
+ checkboxUpsells: null,
939
+ lowStockAlertEnabled: !1,
940
+ lowStockAlert: null,
941
+ dealBars: [{
942
+ id: "PfFU",
943
+ dealBarType: Z.QuantityBreak,
944
+ title: "1 pack",
945
+ subtitle: "Standard price",
946
+ label: "",
947
+ quantity: 1,
948
+ discountType: "default",
949
+ discountValue: "",
950
+ badgeStyle: "simple",
951
+ badgeText: "",
952
+ badgeImageGID: null,
953
+ mediaImageGID: null,
954
+ freeGifts: [],
955
+ multipleGiftsSelectors: [],
956
+ upsells: [],
957
+ showAsSoldOutEnabled: !1,
958
+ showAsSoldOut: null,
959
+ productPersonalisation: null
960
+ }, {
961
+ id: "1f-9",
962
+ dealBarType: Z.QuantityBreak,
963
+ title: "2 pack",
964
+ subtitle: "You save {{saved_percentage}}",
965
+ label: "SAVE {{saved_total}}",
966
+ quantity: 2,
967
+ discountType: "percentage",
968
+ discountValue: "15",
969
+ badgeStyle: "most-popular",
970
+ badgeText: "",
971
+ badgeImageGID: null,
972
+ mediaImageGID: null,
973
+ freeGifts: [],
974
+ multipleGiftsSelectors: [],
975
+ upsells: [],
976
+ showAsSoldOutEnabled: !1,
977
+ showAsSoldOut: null,
978
+ productPersonalisation: null
979
+ }],
980
+ badgesEnabled: !0,
981
+ badges: [{
982
+ id: "bdg1",
983
+ attachedTo: {
984
+ type: "dealBar",
985
+ dealBarId: "1f-9"
986
+ },
987
+ text: "MOST POPULAR",
988
+ colors: null,
989
+ badgeType: "most-popular",
990
+ size: 90
991
+ }],
992
+ cornerRadius: t ?? 8,
993
+ spacing: 1,
994
+ colors: {
995
+ background: {
996
+ red: 255,
997
+ green: 255,
998
+ blue: 255,
999
+ alpha: 1
1000
+ },
1001
+ selectedBackground: {
1002
+ red: 255,
1003
+ green: 255,
1004
+ blue: 255,
1005
+ alpha: 1
1006
+ },
1007
+ border: {
1008
+ red: 0,
1009
+ green: 0,
1010
+ blue: 0,
1011
+ alpha: 1
1012
+ },
1013
+ blockTitle: {
1014
+ red: 0,
1015
+ green: 0,
1016
+ blue: 0,
1017
+ alpha: 1
1018
+ },
1019
+ title: {
1020
+ red: 0,
1021
+ green: 0,
1022
+ blue: 0,
1023
+ alpha: 1
1024
+ },
1025
+ subtitle: {
1026
+ red: 85,
1027
+ green: 85,
1028
+ blue: 85,
1029
+ alpha: 1
1030
+ },
1031
+ price: {
1032
+ red: 0,
1033
+ green: 0,
1034
+ blue: 0,
1035
+ alpha: 1
1036
+ },
1037
+ fullPrice: {
1038
+ red: 85,
1039
+ green: 85,
1040
+ blue: 85,
1041
+ alpha: 1
1042
+ },
1043
+ labelBackground: {
1044
+ red: 238,
1045
+ green: 238,
1046
+ blue: 238,
1047
+ alpha: 1
1048
+ },
1049
+ label: {
1050
+ red: 0,
1051
+ green: 0,
1052
+ blue: 0,
1053
+ alpha: 1
1054
+ },
1055
+ badgeBackground: {
1056
+ red: 255,
1057
+ green: 17,
1058
+ blue: 17,
1059
+ alpha: 1
1060
+ },
1061
+ badgeText: {
1062
+ red: 255,
1063
+ green: 255,
1064
+ blue: 255,
1065
+ alpha: 1
1066
+ },
1067
+ freeGiftBackground: {
1068
+ red: 0,
1069
+ green: 0,
1070
+ blue: 0,
1071
+ alpha: .3
1072
+ },
1073
+ freeGiftText: {
1074
+ red: 0,
1075
+ green: 0,
1076
+ blue: 0,
1077
+ alpha: 1
1078
+ },
1079
+ freeGiftSelectedBackground: {
1080
+ red: 0,
1081
+ green: 0,
1082
+ blue: 0,
1083
+ alpha: 1
1084
+ },
1085
+ freeGiftSelectedText: {
1086
+ red: 255,
1087
+ green: 255,
1088
+ blue: 255,
1089
+ alpha: 1
1090
+ },
1091
+ upsellBackground: {
1092
+ red: 0,
1093
+ green: 0,
1094
+ blue: 0,
1095
+ alpha: .2
1096
+ },
1097
+ upsellText: {
1098
+ red: 0,
1099
+ green: 0,
1100
+ blue: 0,
1101
+ alpha: 1
1102
+ },
1103
+ upsellSelectedBackground: {
1104
+ red: 0,
1105
+ green: 0,
1106
+ blue: 0,
1107
+ alpha: .2
1108
+ },
1109
+ upsellSelectedText: {
1110
+ red: 0,
1111
+ green: 0,
1112
+ blue: 0,
1113
+ alpha: 1
1114
+ }
1115
+ },
1116
+ fonts: {
1117
+ blockTitle: {
1118
+ size: "14",
1119
+ style: "bold"
1120
+ },
1121
+ title: {
1122
+ size: "20",
1123
+ style: "bold"
1124
+ },
1125
+ subtitle: {
1126
+ size: "14",
1127
+ style: "regular"
1128
+ },
1129
+ label: {
1130
+ size: "12",
1131
+ style: "regular"
1132
+ },
1133
+ freeGift: {
1134
+ size: "13",
1135
+ style: "bold"
1136
+ },
1137
+ upsell: {
1138
+ size: "13",
1139
+ style: "bold"
1140
+ },
1141
+ unitLabel: {
1142
+ size: "14",
1143
+ style: "regular"
1144
+ }
1145
+ },
1146
+ swatchOptions: [],
1147
+ swatchSize: 18,
1148
+ swatchShape: "circle",
1149
+ imageSize: 48,
1150
+ imageCornerRadius: 6
1151
+ };
1152
+ return e !== void 0 && (n.colors.border = {
1153
+ ...De(e),
1154
+ alpha: 1
1155
+ }), n;
1156
+ }, Ae = ({ data: t, selectedVariantId: a, preview: o, onLinesChange: s, targetWindow: c }) => {
1157
+ let l = n(null), [u, d] = r(!1), f = n(!1);
1158
+ e(() => {
1159
+ l.current && !u && (async () => {
1160
+ await ye(c ?? window), d(!0);
1161
+ })();
1162
+ }, [u, c]), e(() => {
1163
+ let e = l.current;
1164
+ if (!u || !e) return;
1165
+ let t = () => {
1166
+ let t = e.items().map((e) => ({
1167
+ merchandiseId: `gid://shopify/ProductVariant/${e.id}`,
1168
+ quantity: e.quantity,
1169
+ attributes: Object.entries(e.properties).map(([e, t]) => ({
1170
+ key: e,
1171
+ value: String(t)
1172
+ })),
1173
+ sellingPlanId: e.selling_plan ? `gid://shopify/SellingPlan/${e.selling_plan}` : void 0
1174
+ }));
1175
+ s?.(t);
1176
+ };
1177
+ return f.current ||= (typeof e.items == "function" ? t() : e.addEventListener("kaching-bundles-block-loaded", t), !0), e.addEventListener("variants-changed", t), () => {
1178
+ e.removeEventListener("kaching-bundles-block-loaded", t), e.removeEventListener("variants-changed", t);
1179
+ };
1180
+ }, [u, s]);
1181
+ let p = t ? Me(t, a) : o ? Ne(o) : null;
1182
+ return je(() => {
1183
+ let e = l.current;
1184
+ if (e && p) for (let [t, n] of Object.entries(p.jsonAttributes)) e.getAttribute(t) !== n && e.setAttribute(t, n);
1185
+ }), p ? /* @__PURE__ */ i("kaching-bundles-block", {
1186
+ ref: l,
1187
+ "deal-block-id": p.dealBlockId,
1188
+ ...p.jsonAttributes,
1189
+ "current-variant-id": p.currentVariantId
1190
+ }) : null;
1191
+ }, je = typeof window > "u" ? e : t, Me = ({ config: e, dealBlock: t, product: n, otherProducts: r, mediaImages: i, collectionBreaksProducts: a, translations: o }, s) => ({
1192
+ dealBlockId: t.id,
1193
+ currentVariantId: s ? s.split("/").pop() : String(n.variants[0].id),
1194
+ jsonAttributes: {
1195
+ config: JSON.stringify(e),
1196
+ "deal-block": JSON.stringify(t),
1197
+ "media-images": JSON.stringify(i),
1198
+ product: JSON.stringify(n),
1199
+ "other-products": JSON.stringify(r),
1200
+ "collection-breaks-products": JSON.stringify(a),
1201
+ translations: JSON.stringify(o)
1202
+ }
1203
+ }), Ne = ({ cornerRadius: e, color: t, price: n }) => {
1204
+ let r = $({ price: n }), i = Oe(), a = ke({
1205
+ color: t,
1206
+ cornerRadius: e
1207
+ });
1208
+ return {
1209
+ dealBlockId: a.id,
1210
+ currentVariantId: String(r.variants[0].id),
1211
+ jsonAttributes: {
1212
+ config: JSON.stringify(i),
1213
+ "deal-block": JSON.stringify(a),
1214
+ "media-images": JSON.stringify([]),
1215
+ product: JSON.stringify(r),
1216
+ "other-products": JSON.stringify([]),
1217
+ "collection-breaks-products": JSON.stringify([]),
1218
+ translations: JSON.stringify({})
1219
+ }
1220
+ };
1575
1221
  };
1222
+ export { Ae as KachingBundle, ge as fetchKachingBundlesData };