@kachingappz/bundles-js 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/bundles-js.iife.js +15 -15
- package/dist/bundles-js.js +371 -417
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ npm install @kachingappz/bundles-js
|
|
|
35
35
|
| `selected-variant-id` | No | Currently selected variant ID (plain ID or full GID) |
|
|
36
36
|
| `country` | No | Country code for localization (e.g. `US`) |
|
|
37
37
|
| `language` | No | Language code for localization (e.g. `EN`) |
|
|
38
|
+
| `deal-bars-only` | No | Show only deal bars, hiding title, timer, gifts, upsells, etc. |
|
|
38
39
|
| `demo` | No | Render with placeholder data (no credentials needed) |
|
|
39
40
|
|
|
40
41
|
## Events
|
package/dist/bundles-js.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){"use strict";const
|
|
1
|
+
(function(){"use strict";const N={config:{shopifyDomain:"",moneyFormat:"${{amount}}",locale:"en",country:"US",currencyRate:1,marketId:0,productId:null,storefrontAccessToken:null,accessScopes:[],customApiHost:null,keepQuantityInput:!1,ignoreDeselect:!1,ignoreUnitPrice:!1,requireCustomerLogin:!1,abTestsRunning:!1,webPixel:!1,b2bCustomer:!1,isLoggedIn:!1,preview:!0,previewAlerts:!1,defaultTranslations:{"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"},customSelectors:{quantity:null,addToCartButton:null,variantPicker:null,price:null,priceCompare:null},featureFlags:{},shopCustomStyles:""},dealBlock:{id:"example",nanoId:"example",blockName:"Bundle",discountName:"",blockTitle:"BUNDLE & SAVE",blockLayout:"vertical",blockVisibility:"all-products",marketId:null,currency:null,excludeB2bCustomers:!1,excludePos:!1,startTimestamp:0,endTimestamp:null,differentVariantsEnabled:!0,hideVariantPicker:!0,disableVariantOptionSync:!1,hideUnavailableOptions:!1,showPricesPerItem:!1,showBothPrices:!1,unitLabel:"",useProductCompareAtPrice:!0,showPricesWithoutDecimals:!1,priceRounding:!1,priceRoundingPrecision:".00",updateNativePrice:!1,updateNativePriceType:"item",skipCart:!1,showVariantsForSingleQuantity:!1,preselectedDealBarId:"duo",cornerRadius:8,spacing:1,selectedProductIds:[],selectedCollectionIds:[],excludedProductIds:[],excludedCollectionIds:[],colors:{background:{red:255,green:255,blue:255,alpha:1},selectedBackground:{red:255,green:255,blue:255,alpha:1},border:{red:0,green:0,blue:0,alpha:1},blockTitle:{red:0,green:0,blue:0,alpha:1},title:{red:0,green:0,blue:0,alpha:1},subtitle:{red:85,green:85,blue:85,alpha:1},price:{red:0,green:0,blue:0,alpha:1},fullPrice:{red:85,green:85,blue:85,alpha:1},labelBackground:{red:238,green:238,blue:238,alpha:1},label:{red:0,green:0,blue:0,alpha:1},badgeBackground:{red:0,green:0,blue:0,alpha:1},badgeText:{red:255,green:255,blue:255,alpha:1},freeGiftBackground:{red:0,green:0,blue:0,alpha:.3},freeGiftText:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedBackground:{red:0,green:0,blue:0,alpha:1},freeGiftSelectedText:{red:255,green:255,blue:255,alpha:1},upsellBackground:{red:0,green:0,blue:0,alpha:.2},upsellText:{red:0,green:0,blue:0,alpha:1},upsellSelectedBackground:{red:0,green:0,blue:0,alpha:.2},upsellSelectedText:{red:0,green:0,blue:0,alpha:1}},fonts:{blockTitle:{size:"14",style:"bold"},title:{size:"20",style:"medium"},subtitle:{size:"14",style:"regular"},label:{size:"12",style:"regular"},freeGift:{size:"13",style:"bold"},upsell:{size:"13",style:"bold"},unitLabel:{size:"14",style:"regular"}},dealBars:[{id:"single",dealBarType:"quantity-break",quantitySelector:!1,title:"Single",subtitle:"Standard price",label:"",quantity:1,discountType:"default",discountValue:"",badgeStyle:"simple",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null},{id:"duo",dealBarType:"quantity-break",quantitySelector:!1,title:"Duo",subtitle:"You save 20%",label:"SAVE $32",quantity:2,discountType:"percentage",discountValue:"20",badgeStyle:"most-popular",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null},{id:"trio",dealBarType:"quantity-break",quantitySelector:!1,title:"Trio",subtitle:"You save 25%",label:"SAVE $60",quantity:3,discountType:"percentage",discountValue:"25",badgeStyle:"simple",badgeText:"",badgeImageGID:null,mediaImageGID:null,freeGifts:[],multipleGiftsSelectors:[],upsells:[],showAsSoldOutEnabled:!1,showAsSoldOut:null,productPersonalisation:null,highlights:null,sellingPlanEnabled:!1,sellingPlanGid:null}],swatchOptions:[],swatchSize:18,swatchShape:"circle",imageSize:48,imageCornerRadius:6,defaultVariantsV2:[],collectionBreaksEnabled:!1,collectionBreaks:null,chooseProductModal:null,timerEnabled:!1,timer:null,subscriptionsEnabled:!1,subscriptions:null,stickyAtcEnabled:!1,stickyAtc:null,progressiveGiftsEnabled:!1,progressiveGifts:null,checkboxUpsellsEnabled:!1,checkboxUpsells:null,customStylesEnabled:!1,shopCustomStyles:"",customStyles:"",lowStockAlertEnabled:!1,lowStockAlert:null},product:{id:1,handle:"example-product",url:null,availableForSale:!0,title:"Example product",image:null,collectionIds:[],options:[],selectedVariantId:1,variants:[{id:1,availableForSale:!0,price:8e3,compareAtPrice:null,options:["Default Title"],imageId:null,image:null,unitPriceMeasurement:null,sellingPlans:[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:50}],metafields:{text:null,text2:null,text3:null,text4:null},requiresSellingPlan:!1,sellingPlans:[],isNativeBundle:!1},otherProducts:[],mediaImages:[],collectionBreaksProducts:[],translations:{}},v=({country:t,language:e})=>{const l=[];return t&&l.push(`country: ${t}`),e&&l.push(`language: ${e}`),l.length>0?`@inContext(${l.join(", ")})`:""},x=async(t,{useExternalMetafieldNamespace:e,useMetaobjects:l})=>l?T(t):B(t),B=async(t,e)=>{var a;const l=(a=(await t.query(`
|
|
2
2
|
query FetchDealBlocks($metafieldNamespace: String!) {
|
|
3
3
|
shop {
|
|
4
4
|
metafield(namespace: $metafieldNamespace, key: "deal_blocks") {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
`,{variables:{metafieldNamespace:"app--2935586817--kaching_bundles"}})).shop.metafield)==null?void 0:
|
|
9
|
+
`,{variables:{metafieldNamespace:"app--2935586817--kaching_bundles"}})).shop.metafield)==null?void 0:a.value;return l?JSON.parse(l):[]},T=async(t,e)=>{const l="app--2935586817--deal_block",a=[];let i=null;for(;;){const o=await t.query(`
|
|
10
10
|
query FetchDealBlockMetaobjects($type: String!, $cursor: String) {
|
|
11
11
|
metaobjects(type: $type, first: 250, after: $cursor) {
|
|
12
12
|
nodes {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
`,{variables:{type:
|
|
24
|
+
`,{variables:{type:l,cursor:i}});for(const c of o.metaobjects.nodes){const s=c.fields.find(d=>d.key==="settings");s!=null&&s.value&&a.push(JSON.parse(s.value))}if(!o.metaobjects.pageInfo.hasNextPage)break;i=o.metaobjects.pageInfo.endCursor}return a},S="app--2935586817",q=async(t,{language:e,country:l,useExternalMetafieldNamespace:a})=>{const i=`${S}--kaching_bundles`,o=S,{shop:{moneyFormat:c,currencyRateConstant:s,primaryDomain:d,settingsMetafield:p}}=await t.query(`
|
|
25
25
|
query config($metafieldNamespace: String!, $settingsNamespace: String!) {
|
|
26
26
|
shop {
|
|
27
27
|
moneyFormat
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
`,{variables:{metafieldNamespace:
|
|
39
|
+
`,{variables:{metafieldNamespace:i,settingsNamespace:o}}),m=s?M(s.value):1,n=p?JSON.parse(p.value):null,u=(n==null?void 0:n.feature_flags)??{},r=(n==null?void 0:n.custom_selectors)??{};return{shopifyDomain:d.host,moneyFormat:c,locale:(e==null?void 0:e.toLowerCase())||"en",liquidLocale:(e==null?void 0:e.toLowerCase())||"en",country:l??"US",currencyRate:m,marketId:0,productId:null,storefrontAccessToken:(n==null?void 0:n.storefront_access_token)??null,accessScopes:(n==null?void 0:n.access_scopes)??[],customApiHost:(n==null?void 0:n.custom_api_host)??null,keepQuantityInput:(n==null?void 0:n.keep_quantity_input)??!1,ignoreDeselect:(n==null?void 0:n.ignore_deselect)??!1,ignoreUnitPrice:(n==null?void 0:n.ignore_unit_price)??!1,requireCustomerLogin:(n==null?void 0:n.require_customer_login)??!1,abTestsRunning:(n==null?void 0:n.ab_tests_running)??!1,webPixel:(n==null?void 0:n.web_pixel)??!1,b2bCustomer:!1,isLoggedIn:!1,preview:!1,previewAlerts:!1,defaultTranslations:{"system.out_of_stock":"Out of stock","system.invalid_variant":"Invalid variant","system.unavailable_option_value":"Unavailable option value","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"},customSelectors:{quantity:r.quantity??null,addToCartButton:r.add_to_cart_button??null,variantPicker:r.variant_picker??null,price:r.price??null,priceCompare:r.price_compare??null},shopCustomStyles:(n==null?void 0:n.shop_custom_styles)??"",featureFlags:u}},M=t=>JSON.parse(t).amount/1e6,L=async(t,e,l=200)=>(e=e.filter(Boolean).filter(a=>!a.startsWith("placeholder")),e.length===0?[]:(await t.query(`
|
|
40
40
|
query FetchMediaImages($mediaImageIds: [ID!]!, $size: Int!) {
|
|
41
41
|
nodes(ids: $mediaImageIds) {
|
|
42
42
|
... on MediaImage {
|
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
`,{variables:{mediaImageIds:e,size:
|
|
51
|
-
query FetchProductGIDs($limit: Int!) ${
|
|
50
|
+
`,{variables:{mediaImageIds:e,size:l}})).nodes.filter(Boolean).map(a=>({gid:a.id,url:a.image.url}))),E=async(t,{country:e,language:l,blockVisibility:a,excludedProductGIDs:i,selectedProductGIDs:o,selectedCollectionGIDs:c,limit:s=250})=>{switch(a){case"selected-products":return o.slice(0,s);case"all-products":case"excluded-products":{const d=v({country:e,language:l});let p=(await t.query(`
|
|
51
|
+
query FetchProductGIDs($limit: Int!) ${d} {
|
|
52
52
|
products(first: $limit) {
|
|
53
53
|
nodes {
|
|
54
54
|
id
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
`,{variables:{limit:
|
|
59
|
-
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${
|
|
58
|
+
`,{variables:{limit:s}})).products.nodes.map(m=>m.id);return a==="excluded-products"&&(p=p.filter(m=>!i.includes(m))),p}case"selected-collections":{const d=v({country:e,language:l}),p=(await t.query(`
|
|
59
|
+
query FetchCollectionProductGIDs($collectionGIDs: [ID!]!, $limit: Int!) ${d} {
|
|
60
60
|
nodes(ids: $collectionGIDs) {
|
|
61
61
|
... on Collection {
|
|
62
62
|
products(first: $limit) {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
`,{variables:{collectionGIDs:c,limit:
|
|
70
|
+
`,{variables:{collectionGIDs:c,limit:s}})).nodes.filter(m=>m!==null).flatMap(m=>m.products.nodes.map(n=>n.id));return Array.from(new Set(p)).slice(0,s)}}},A=`
|
|
71
71
|
id
|
|
72
72
|
availableForSale
|
|
73
73
|
price {
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
quantityAvailable @include(if: $includeAvailableQuantity)
|
|
107
|
-
`,P=async(t,{country:e,language:
|
|
108
|
-
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${
|
|
107
|
+
`,P=async(t,{country:e,language:l,productIds:a,includeSellingPlans:i=!0,includeAvailableQuantity:o=!0,useExternalMetafieldNamespace:c=!1})=>{if(!a.length)return[];const s=a.map(m=>typeof m=="string"&&m.startsWith("gid://")?m:`gid://shopify/Product/${m}`),d=v({country:e,language:l});let p=(await t.query(`
|
|
108
|
+
query FetchProducts($productGIDs: [ID!]!, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!, $metafieldNamespace: String!) ${d} {
|
|
109
109
|
nodes(ids: $productGIDs) {
|
|
110
110
|
... on Product {
|
|
111
111
|
id
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
}
|
|
135
135
|
variants(first: 250) {
|
|
136
136
|
nodes {
|
|
137
|
-
${
|
|
137
|
+
${A}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
collections(first: 50) {
|
|
@@ -186,12 +186,12 @@
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
`,{variables:{productGIDs:
|
|
189
|
+
`,{variables:{productGIDs:s,includeSellingPlans:i,includeAvailableQuantity:o,metafieldNamespace:c?"app--2935586817--kaching_bundles":"$app:kaching_bundles"}})).nodes.filter(m=>m!=null);return p=await Promise.all(p.map(m=>O(t,m,{includeSellingPlans:i,includeAvailableQuantity:o}))),p.map(U)},O=async(t,e,l)=>{if(e.variants.nodes.length<250)return e;const a=new Set,i=[],o=[],c=async s=>{let d=!0,p=null;for(;d;){const m=await t.query(`
|
|
190
190
|
query($productGID: ID!, $cursor: String, $reverse: Boolean, $includeSellingPlans: Boolean!, $includeAvailableQuantity: Boolean!) {
|
|
191
191
|
product(id: $productGID) {
|
|
192
192
|
variants(first: 250, after: $cursor, reverse: $reverse) {
|
|
193
193
|
nodes {
|
|
194
|
-
${
|
|
194
|
+
${A}
|
|
195
195
|
}
|
|
196
196
|
pageInfo {
|
|
197
197
|
endCursor
|
|
@@ -200,4 +200,4 @@
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
`,{variables:{productGID:e.id,cursor:p,reverse:n,...s}}),{nodes:i,pageInfo:d}=u.product.variants;for(const o of i){if(l.has(o.id)){m=!1;break}l.add(o.id),n?r.push(o):a.push(o)}d.hasNextPage||(m=!1),p=d.endCursor}};return await Promise.all([c(!1),c(!0)]),e.variants.nodes=[...a,...r.reverse()],e},j=t=>{var c,n,m,p,u,i;const e=t.variants.nodes.map(({unitPriceMeasurement:d,...o})=>{var h,f;return{id:Number(o.id.split("/").pop()),availableForSale:o.availableForSale,price:Math.round(Number(o.price.amount)*100),compareAtPrice:o.compareAtPrice?Math.round(Number(o.compareAtPrice.amount)*100):null,options:o.selectedOptions.map(g=>g.value),imageId:o.image?Number(o.image.id.split("/").pop()):null,image:((h=o.image)==null?void 0:h.url)||null,sellingPlans:((f=o.sellingPlanAllocations)==null?void 0:f.nodes.map(g=>({id:Number(g.sellingPlan.id.split("/").pop()),price:g.priceAdjustments.length>0?Math.round(Number(g.priceAdjustments[0].price.amount)*100):Math.round(Number(o.price.amount)*100)})))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:o.quantityAvailable??null,unitPriceMeasurement:d!=null&&d.quantityUnit&&(d!=null&&d.referenceUnit)?{quantityValue:d.quantityValue,quantityUnit:d.quantityUnit.toLowerCase(),referenceValue:d.referenceValue,referenceUnit:d.referenceUnit.toLowerCase()}:null}}),s=t.options.map((d,o)=>{const h=d.optionValues.map(f=>{var g,b,y,v;return{id:Number(f.id.split("/").pop()),defaultName:f.name,name:f.name,swatch:{color:((g=f.swatch)==null?void 0:g.color)||null,image:((v=(y=(b=f.swatch)==null?void 0:b.image)==null?void 0:y.previewImage)==null?void 0:v.url)||null}}});return{defaultName:d.name,name:d.name,position:o+1,optionValues:L(h,o,e)}}),l=d=>{const o=d.priceAdjustments[0];if(!o)return null;const h=o.adjustmentValue;switch(h.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:h.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:Number(h.adjustmentAmount.amount)*100};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:Number(h.price.amount)*100};default:throw new Error(`Unknown price adjustment type: ${h.__typename}`)}},a=((c=t.sellingPlanGroups)==null?void 0:c.nodes.flatMap(d=>d.sellingPlans.nodes.map(o=>({id:Number(o.id.split("/").pop()),name:o.name,priceAdjustment:l(o)}))))||[],r=t.variants.nodes.some(d=>d.requiresComponents);return{id:Number(t.id.split("/").pop()),handle:t.handle,url:t.onlineStoreUrl,availableForSale:t.availableForSale,createdAt:t.createdAt,title:t.title,image:((n=t.featuredImage)==null?void 0:n.url)||null,collectionIds:t.collections.nodes.map(d=>Number(d.id.split("/").pop())),options:s,selectedVariantId:Number(t.variants.nodes[0].id.split("/").pop()),variants:e,requiresSellingPlan:t.requiresSellingPlan,sellingPlans:a,isNativeBundle:r,metafields:{text:((m=t.metafield)==null?void 0:m.value)||null,text2:((p=t.metafield2)==null?void 0:p.value)||null,text3:((u=t.metafield3)==null?void 0:u.value)||null,text4:((i=t.metafield4)==null?void 0:i.value)||null}}},L=(t,e,s)=>t.filter(l=>s.filter(a=>a.options[e]===l.name).length>0),U=(t,e)=>{const s=[],l=t.filter(n=>n.blockVisibility==="selected-products");for(const n of l)n.selectedProductIds.map(Number).includes(e.id)&&s.push(n);const a=t.filter(n=>n.blockVisibility==="selected-collections");for(const n of a)e.collectionIds.some(m=>n.selectedCollectionIds.map(Number).includes(m))&&s.push(n);const r=t.filter(n=>n.blockVisibility==="excluded-products");for(const n of r)!n.excludedProductIds.map(Number).includes(e.id)&&!(n.excludedCollectionIds||[]).some(m=>e.collectionIds.includes(m))&&s.push(n);const c=t.filter(n=>n.blockVisibility==="all-products");for(const n of c)s.push(n);return s},V=t=>[...F(t),...R(t),...z(t),...H(t),...J(t),...Q(t),...X(t),...W(t),...K(t),...Y(t)].filter(e=>e!=null&&!e.includes("placeholder")),F=t=>t.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),R=t=>t.dealBars.map(({freeGifts:e})=>(e||[]).map(s=>s.mediaImageGID)).reduce((e,s)=>e.concat(s),[]).filter(e=>e!=null),z=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(s=>s.mediaImageGID)).filter(e=>e!=null),H=t=>t.dealBars.map(({upsells:e})=>(e||[]).map(s=>s.mediaImageGID)).reduce((e,s)=>e.concat(s),[]).filter(e=>e!=null),J=t=>t.swatchOptions?t.swatchOptions.reduce((e,s)=>{const l=s.images.map(a=>a.mediaImageGID).filter(a=>a!=null);return[...e,...l]},[]):[],Q=t=>{if(!t.collectionBreaksEnabled||!t.collectionBreaks)return[];const e=t.collectionBreaks.mediaImageGID;return e?[e]:[]},X=t=>{var e,s,l;return t.progressiveGifts?[...((e=t.progressiveGifts.gifts)==null?void 0:e.map(a=>a.mediaImageGID))||[],(s=t.progressiveGifts.style)==null?void 0:s.lockedMediaImageGID,(l=t.progressiveGifts.dealBarStyle)==null?void 0:l.lockedMediaImageGID].filter(a=>a!=null):[]},W=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.mediaImageGID).filter(e=>e!=null),K=t=>t.dealBars.map(e=>{var s;return(s=e.productPersonalisation)==null?void 0:s.mediaImageGID}).filter(e=>e!=null),Y=t=>t.dealBars.map(e=>{var s;return(s=e.highlights)==null?void 0:s.customIconGID}).filter(e=>e!=null),Z=t=>{const e=[...ee(t),...te(t),...se(t),...le(t),...ne(t),...ae(t),...ie(t)];return Array.from(new Set(e.filter(s=>s!=null)))},ee=t=>t.dealBars.flatMap(({freeGifts:e})=>e?e.map(s=>s.productGID):[]).filter(e=>e!=null),te=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(s=>s.products?s.products.map(l=>l.id):[]):[]).filter(e=>e!=null),se=t=>{var e;return t.progressiveGiftsEnabled?((e=t.progressiveGifts)==null?void 0:e.gifts.map(s=>s.productGID).filter(s=>s!=null))||[]:[]},le=t=>t.dealBars.flatMap(({upsells:e})=>e?e.map(s=>s.productGID):[]).filter(e=>e!=null),ne=t=>t.dealBars.filter(e=>e.dealBarType==="bundle").flatMap(({bundleProducts:e})=>e?e.map(s=>s.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),ae=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),ie=t=>t.dealBars.filter(e=>e.dealBarType==="sku").flatMap(({productGID:e})=>e?[e]:[]);class re{constructor(e,s){this.storefrontApiVersion="2025-10",this.storefrontAccessToken=s,this.shopifyDomain=e}async query(e,s){var n;const l=(s==null?void 0:s.variables)??{};let a=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const r=(n=e.match(/query\s+(\w+)/))==null?void 0:n[1];r&&(a+=`?operation_name=${r}`);const c=await(await fetch(a,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:l})})).text();if(!c)throw new Error("Empty graphql response");return JSON.parse(c).data}}const oe=async(t,e,{country:s,language:l})=>{const a=e.collectionBreaks;if(!e.collectionBreaksEnabled||!a)return;let r;a.visibility==="deal-products"?r=await E(t,{country:s,language:l,blockVisibility:e.blockVisibility,excludedProductGIDs:(e.excludedProductIds||[]).map(n=>`gid://shopify/Product/${n}`),selectedProductGIDs:(e.selectedProductIds||[]).map(n=>`gid://shopify/Product/${n}`),selectedCollectionGIDs:(e.selectedCollectionIds||[]).map(n=>`gid://shopify/Collection/${n}`)}):r=await E(t,{country:s,language:l,blockVisibility:a.visibility,excludedProductGIDs:(a.excludedProducts||[]).map(({id:n})=>n),selectedProductGIDs:(a.selectedProducts||[]).map(({id:n})=>n),selectedCollectionGIDs:(a.selectedCollections||[]).map(({id:n})=>n)}),r=r.slice(0,250);let c=await P(t,{country:s,language:l,productIds:r.map(n=>Number(n.split("/").pop())),useExternalMetafieldNamespace:!0});return c=c.filter(n=>n.availableForSale),c},ce=()=>({"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"}),ue="2025-10",de=async(t,{productId:e,dealBlockId:s,country:l=void 0,language:a=void 0})=>{var r,c;try{const n=[Number(e.split("/").pop())],m=new me(t);l=l||((r=m.i18n)==null?void 0:r.country),a=a||((c=m.i18n)==null?void 0:c.language);const p=await B(m,{language:a,country:l,useExternalMetafieldNamespace:!0}),u=p.storefrontAccessToken?new re(p.shopifyDomain,p.storefrontAccessToken):m,[i,d]=await Promise.all([P(u,{country:l,language:a,productIds:n,useExternalMetafieldNamespace:!0}),G(u,{useExternalMetafieldNamespace:!0,useMetaobjects:p.featureFlags.storefront_metaobjects})]),o=i[0];if(!o)return null;const h=U(d,o);let f;if(s?(f=h.find(N=>N.id===s||N.nanoId===s),f||(f=h[0])):f=h[0],!f)return null;const g=V(f),b=Z(f),[y,v,ve,Ie]=await Promise.all([P(u,{country:l,language:a,productIds:b,useExternalMetafieldNamespace:!0}),M(u,g,300),oe(u,f,{country:l,language:a}),ce()]);return{product:o,dealBlock:f,config:p,otherProducts:y,mediaImages:v,collectionBreaksProducts:ve??[],translations:Ie}}catch(n){return console.error(n),null}};class me{constructor(e){this.storefront=e}async query(e,s){if("query"in this.storefront&&"i18n"in this.storefront)return await this.storefront.query(e,s);if("request"in this.storefront)return(await this.storefront.request(e,s)).data;if("shopifyDomain"in this.storefront&&"storefrontAccessToken"in this.storefront){const l=await fetch(`https://${this.storefront.shopifyDomain}/api/${ue}/graphql.json`,{body:JSON.stringify({query:e,variables:s==null?void 0:s.variables}),headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefront.storefrontAccessToken},method:"POST"});if(!l.ok)throw new Error(l.statusText);return(await l.json()).data}else{const l=await fetch(this.storefront.getStorefrontApiUrl(),{body:JSON.stringify({query:e,variables:s==null?void 0:s.variables}),headers:this.storefront.getPublicTokenHeaders(),method:"POST"});if(!l.ok)throw new Error(l.statusText);return(await l.json()).data}}get i18n(){if("i18n"in this.storefront)return this.storefront.i18n}}const _="kaching-bundles-block",A=1e4,pe="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",fe="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",S=new WeakSet,D=async t=>{const e=t.document;if(!t.customElements.get(_)){if(S.has(e))return C(t,_);S.add(e);try{await be(t)}catch(s){throw S.delete(e),s}}},he=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",ge=()=>he()?pe:fe,be=t=>{const e=t.document;return new Promise((s,l)=>{const a=ge();if(e.querySelector(`script[src="${a}"]`)){s();return}const c=e.createElement("script");c.src=a,c.onload=()=>C(t,_).then(s).catch(l),c.onerror=()=>l(new Error("Failed to load script")),e.head.appendChild(c)})},C=(t,e)=>new Promise((s,l)=>{if(t.customElements.get(e)){s();return}Promise.race([t.customElements.whenDefined(e),new Promise((a,r)=>setTimeout(()=>r(new Error(`Custom element "${e}" failed to register within ${A}ms`)),A))]).then(()=>s()).catch(l)});class ye extends HTMLElement{constructor(){super(...arguments),this.innerElement=null,this.handleItemsChanged=null,this.currentProductId=null}static get observedAttributes(){return["selected-variant-id","product-id"]}async connectedCallback(){await this.initialize()}async initialize(){var r,c;if(this.hasAttribute("demo")){this.cleanup(),await D(window),this.renderInnerElement($);return}const e=this.getAttribute("shop-domain"),s=this.getAttribute("storefront-token"),l=this.getAttribute("product-id");if(!e||!s||!l||l===this.currentProductId)return;this.currentProductId=l,this.cleanup();const[a]=await Promise.all([de({shopifyDomain:e,storefrontAccessToken:s},{productId:l,dealBlockId:this.getAttribute("deal-block-id")??void 0,country:((r=this.getAttribute("country"))==null?void 0:r.toUpperCase())??void 0,language:((c=this.getAttribute("language"))==null?void 0:c.toUpperCase())??void 0}),D(window)]);!a||l!==this.currentProductId||this.renderInnerElement(a)}renderInnerElement(e){const{config:s,dealBlock:l,product:a,otherProducts:r,mediaImages:c,collectionBreaksProducts:n,translations:m}=e;this.innerElement=document.createElement("kaching-bundles-block"),this.innerElement.setAttribute("deal-block-id",l.id),this.innerElement.setAttribute("config",JSON.stringify(s)),this.innerElement.setAttribute("deal-block",JSON.stringify(l)),this.innerElement.setAttribute("media-images",JSON.stringify(c??[])),this.innerElement.setAttribute("product",JSON.stringify(a)),this.innerElement.setAttribute("other-products",JSON.stringify(r??[])),this.innerElement.setAttribute("collection-breaks-products",JSON.stringify(n??[])),this.innerElement.setAttribute("translations",JSON.stringify(m??{}));const p=this.getAttribute("selected-variant-id");this.innerElement.setAttribute("current-variant-id",String(p?p.split("/").pop():a.variants[0].id)),this.appendChild(this.innerElement);const u=()=>{const i=this.innerElement.items();i&&this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:i},bubbles:!0}))};this.handleItemsChanged=i=>{i.stopPropagation(),u()},this.innerElement.addEventListener("kaching-bundles-block-loaded",()=>{this.innerElement.addEventListener("items-changed",this.handleItemsChanged),u(),this.dispatchEvent(new CustomEvent("loaded",{bubbles:!0}))},{once:!0})}cleanup(){this.handleItemsChanged&&this.innerElement&&(this.innerElement.removeEventListener("items-changed",this.handleItemsChanged),this.handleItemsChanged=null),this.innerElement&&(this.innerElement.remove(),this.innerElement=null)}attributeChangedCallback(e,s,l){s!==l&&(e==="product-id"?this.initialize():e==="selected-variant-id"&&this.innerElement&&l&&this.innerElement.setAttribute("current-variant-id",l.includes("/")?String(l.split("/").pop()):l))}items(){return this.innerElement?this.innerElement.items():[]}disconnectedCallback(){this.cleanup(),this.currentProductId=null}}customElements.define("kaching-bundle-component",ye)})();
|
|
203
|
+
`,{variables:{productGID:e.id,cursor:p,reverse:s,...l}}),{nodes:n,pageInfo:u}=m.product.variants;for(const r of n){if(a.has(r.id)){d=!1;break}a.add(r.id),s?o.push(r):i.push(r)}u.hasNextPage||(d=!1),p=u.endCursor}};return await Promise.all([c(!1),c(!0)]),e.variants.nodes=[...i,...o.reverse()],e},U=t=>{var c,s,d,p,m,n;const e=t.variants.nodes.map(({unitPriceMeasurement:u,...r})=>{var f,g;return{id:Number(r.id.split("/").pop()),availableForSale:r.availableForSale,price:Math.round(Number(r.price.amount)*100),compareAtPrice:r.compareAtPrice?Math.round(Number(r.compareAtPrice.amount)*100):null,options:r.selectedOptions.map(h=>h.value),imageId:r.image?Number(r.image.id.split("/").pop()):null,image:((f=r.image)==null?void 0:f.url)||null,sellingPlans:((g=r.sellingPlanAllocations)==null?void 0:g.nodes.map(h=>({id:Number(h.sellingPlan.id.split("/").pop()),price:h.priceAdjustments.length>0?Math.round(Number(h.priceAdjustments[0].price.amount)*100):Math.round(Number(r.price.amount)*100)})))||[],inventoryManagement:null,inventoryPolicy:null,inventoryQuantity:r.quantityAvailable??null,unitPriceMeasurement:u!=null&&u.quantityUnit&&(u!=null&&u.referenceUnit)?{quantityValue:u.quantityValue,quantityUnit:u.quantityUnit.toLowerCase(),referenceValue:u.referenceValue,referenceUnit:u.referenceUnit.toLowerCase()}:null}}),l=t.options.map((u,r)=>{const f=u.optionValues.map(g=>{var h,b,y,I;return{id:Number(g.id.split("/").pop()),defaultName:g.name,name:g.name,swatch:{color:((h=g.swatch)==null?void 0:h.color)||null,image:((I=(y=(b=g.swatch)==null?void 0:b.image)==null?void 0:y.previewImage)==null?void 0:I.url)||null}}});return{defaultName:u.name,name:u.name,position:r+1,optionValues:V(f,r,e)}}),a=u=>{const r=u.priceAdjustments[0];if(!r)return null;const f=r.adjustmentValue;switch(f.__typename){case"SellingPlanPercentagePriceAdjustment":return{type:"percentage",value:f.adjustmentPercentage};case"SellingPlanFixedAmountPriceAdjustment":return{type:"fixed_amount",value:Number(f.adjustmentAmount.amount)*100};case"SellingPlanFixedPriceAdjustment":return{type:"price",value:Number(f.price.amount)*100};default:throw new Error(`Unknown price adjustment type: ${f.__typename}`)}},i=((c=t.sellingPlanGroups)==null?void 0:c.nodes.flatMap(u=>u.sellingPlans.nodes.map(r=>({id:Number(r.id.split("/").pop()),name:r.name,priceAdjustment:a(r)}))))||[],o=t.variants.nodes.some(u=>u.requiresComponents);return{id:Number(t.id.split("/").pop()),handle:t.handle,url:t.onlineStoreUrl,availableForSale:t.availableForSale,createdAt:t.createdAt,title:t.title,image:((s=t.featuredImage)==null?void 0:s.url)||null,collectionIds:t.collections.nodes.map(u=>Number(u.id.split("/").pop())),options:l,selectedVariantId:Number(t.variants.nodes[0].id.split("/").pop()),variants:e,requiresSellingPlan:t.requiresSellingPlan,sellingPlans:i,isNativeBundle:o,metafields:{text:((d=t.metafield)==null?void 0:d.value)||null,text2:((p=t.metafield2)==null?void 0:p.value)||null,text3:((m=t.metafield3)==null?void 0:m.value)||null,text4:((n=t.metafield4)==null?void 0:n.value)||null}}},V=(t,e,l)=>t.filter(a=>l.filter(i=>i.options[e]===a.name).length>0),F=(t,e)=>{const l=[],a=t.filter(s=>s.blockVisibility==="selected-products");for(const s of a)s.selectedProductIds.map(Number).includes(e.id)&&l.push(s);const i=t.filter(s=>s.blockVisibility==="selected-collections");for(const s of i)e.collectionIds.some(d=>s.selectedCollectionIds.map(Number).includes(d))&&l.push(s);const o=t.filter(s=>s.blockVisibility==="excluded-products");for(const s of o)!s.excludedProductIds.map(Number).includes(e.id)&&!(s.excludedCollectionIds||[]).some(d=>e.collectionIds.includes(d))&&l.push(s);const c=t.filter(s=>s.blockVisibility==="all-products");for(const s of c)l.push(s);return l},j=t=>[...z(t),...R(t),...H(t),...J(t),...Q(t),...X(t),...W(t),...K(t),...Y(t),...Z(t)].filter(e=>e!=null&&!e.includes("placeholder")),z=t=>t.dealBars.flatMap(e=>[e.mediaImageGID,e.badgeImageGID]).filter(e=>e!=null),R=t=>t.dealBars.map(({freeGifts:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),H=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>(e||[]).map(l=>l.mediaImageGID)).filter(e=>e!=null),J=t=>t.dealBars.map(({upsells:e})=>(e||[]).map(l=>l.mediaImageGID)).reduce((e,l)=>e.concat(l),[]).filter(e=>e!=null),Q=t=>t.swatchOptions?t.swatchOptions.reduce((e,l)=>{const a=l.images.map(i=>i.mediaImageGID).filter(i=>i!=null);return[...e,...a]},[]):[],X=t=>{if(!t.collectionBreaksEnabled||!t.collectionBreaks)return[];const e=t.collectionBreaks.mediaImageGID;return e?[e]:[]},W=t=>{var e,l,a;return t.progressiveGifts?[...((e=t.progressiveGifts.gifts)==null?void 0:e.map(i=>i.mediaImageGID))||[],(l=t.progressiveGifts.style)==null?void 0:l.lockedMediaImageGID,(a=t.progressiveGifts.dealBarStyle)==null?void 0:a.lockedMediaImageGID].filter(i=>i!=null):[]},K=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.mediaImageGID).filter(e=>e!=null),Y=t=>t.dealBars.map(e=>{var l;return(l=e.productPersonalisation)==null?void 0:l.mediaImageGID}).filter(e=>e!=null),Z=t=>t.dealBars.map(e=>{var l;return(l=e.highlights)==null?void 0:l.customIconGID}).filter(e=>e!=null),ee=t=>{const e=[...te(t),...le(t),...se(t),...ae(t),...ne(t),...ie(t),...re(t)];return Array.from(new Set(e.filter(l=>l!=null)))},te=t=>t.dealBars.flatMap(({freeGifts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),le=t=>t.dealBars.flatMap(({multipleGiftsSelectors:e})=>e?e.flatMap(l=>l.products?l.products.map(a=>a.id):[]):[]).filter(e=>e!=null),se=t=>{var e;return t.progressiveGiftsEnabled?((e=t.progressiveGifts)==null?void 0:e.gifts.map(l=>l.productGID).filter(l=>l!=null))||[]:[]},ae=t=>t.dealBars.flatMap(({upsells:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null),ne=t=>t.dealBars.filter(e=>e.dealBarType==="bundle").flatMap(({bundleProducts:e})=>e?e.map(l=>l.productGID):[]).filter(e=>e!=null).filter(e=>e!=="default"),ie=t=>!t.checkboxUpsellsEnabled||!t.checkboxUpsells?[]:t.checkboxUpsells.upsells.map(e=>e.productGID).filter(e=>e!=null),re=t=>t.dealBars.filter(e=>e.dealBarType==="sku").flatMap(({productGID:e})=>e?[e]:[]);class w{constructor(e,l){this.storefrontApiVersion="2025-10",this.storefrontAccessToken=l,this.shopifyDomain=e}async query(e,l){var s;const a=(l==null?void 0:l.variables)??{};let i=`https://${this.shopifyDomain}/api/${this.storefrontApiVersion}/graphql.json`;const o=(s=e.match(/query\s+(\w+)/))==null?void 0:s[1];o&&(i+=`?operation_name=${o}`);const c=await(await fetch(i,{method:"POST",headers:{"Content-Type":"application/json","X-Shopify-Storefront-Access-Token":this.storefrontAccessToken},body:JSON.stringify({query:e,variables:a})})).text();if(!c)throw new Error("Empty graphql response");return JSON.parse(c).data}}const oe=async(t,e,{country:l,language:a})=>{const i=e.collectionBreaks;if(!e.collectionBreaksEnabled||!i)return;let o;i.visibility==="deal-products"?o=await E(t,{country:l,language:a,blockVisibility:e.blockVisibility,excludedProductGIDs:(e.excludedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedProductGIDs:(e.selectedProductIds||[]).map(s=>`gid://shopify/Product/${s}`),selectedCollectionGIDs:(e.selectedCollectionIds||[]).map(s=>`gid://shopify/Collection/${s}`)}):o=await E(t,{country:l,language:a,blockVisibility:i.visibility,excludedProductGIDs:(i.excludedProducts||[]).map(({id:s})=>s),selectedProductGIDs:(i.selectedProducts||[]).map(({id:s})=>s),selectedCollectionGIDs:(i.selectedCollections||[]).map(({id:s})=>s)}),o=o.slice(0,250);let c=await P(t,{country:l,language:a,productIds:o.map(s=>Number(s.split("/").pop())),useExternalMetafieldNamespace:!0});return c=c.filter(s=>s.availableForSale),c},ce=()=>({"system.out_of_stock":"There's not enough items in our stock, please select smaller bundle.","system.invalid_variant":"Sorry, this is not currently available.","system.unavailable_option_value":"Unavailable","system.confirm":"Confirm","system.cancel":"Cancel","system.free":"FREE","system.search":"Search","system.sort_by":"Sort by","system.sort_relevance":"Relevance","system.sort_newest_first":"Newest first","system.sort_price_low_to_high":"Price: Low → High","system.sort_price_high_to_low":"Price: High → Low","system.no_results_found":"No results found","system.no_results_description":"We can't find any item matching your search.","system.clear_search":"Clear search","system.no_products_available":"No products available"}),ue=async(t,{productId:e,dealBlockId:l,country:a,language:i})=>{try{const o=[Number(e.split("/").pop())],c=new w(t.shopifyDomain,t.storefrontAccessToken),s=await q(c,{language:i,country:a,useExternalMetafieldNamespace:!0}),d=s.storefrontAccessToken?new w(s.shopifyDomain,s.storefrontAccessToken):c,[p,m]=await Promise.all([P(d,{country:a,language:i,productIds:o,useExternalMetafieldNamespace:!0}),x(d,{useExternalMetafieldNamespace:!0,useMetaobjects:s.featureFlags.storefront_metaobjects})]),n=p[0];if(!n)return null;const u=F(m,n);let r;if(l?(r=u.find($=>$.id===l||$.nanoId===l),r||(r=u[0])):r=u[0],!r)return null;const f=j(r),g=ee(r),[h,b,y,I]=await Promise.all([P(d,{country:a,language:i,productIds:g,useExternalMetafieldNamespace:!0}),L(d,f,300),oe(d,r,{country:a,language:i}),ce()]);return{product:n,dealBlock:r,config:s,otherProducts:h,mediaImages:b,collectionBreaksProducts:y??[],translations:I}}catch(o){return console.error(o),null}},_="kaching-bundles-block",D=1e4,de="https://bundles-integrations-dev.kachingappz.dev/kaching-bundles-block.js",me="https://bundles-integrations.kachingappz.app/kaching-bundles-block.js",k=new WeakSet,C=async t=>{const e=t.document;if(!t.customElements.get(_)){if(k.has(e))return G(t,_);k.add(e);try{await ge(t)}catch(l){throw k.delete(e),l}}},pe=()=>typeof window<"u"&&typeof window.__KACHING_DEV__<"u",fe=()=>pe()?de:me,ge=t=>{const e=t.document;return new Promise((l,a)=>{const i=fe();if(e.querySelector(`script[src="${i}"]`)){l();return}const c=e.createElement("script");c.src=i,c.onload=()=>G(t,_).then(l).catch(a),c.onerror=()=>a(new Error("Failed to load script")),e.head.appendChild(c)})},G=(t,e)=>new Promise((l,a)=>{if(t.customElements.get(e)){l();return}Promise.race([t.customElements.whenDefined(e),new Promise((i,o)=>setTimeout(()=>o(new Error(`Custom element "${e}" failed to register within ${D}ms`)),D))]).then(()=>l()).catch(a)});class he extends HTMLElement{constructor(){super(...arguments),this.innerElement=null,this.handleItemsChanged=null,this.initializeId=0}static get observedAttributes(){return["selected-variant-id","product-id"]}async connectedCallback(){await this.initialize()}async initialize(){var c,s;const e=++this.initializeId;if(this.cleanup(),this.hasAttribute("demo")){if(await C(window),e!==this.initializeId)return;this.renderInnerElement(N);return}const l=this.getAttribute("shop-domain"),a=this.getAttribute("storefront-token"),i=this.getAttribute("product-id");if(!l||!a||!i)return;const[o]=await Promise.all([ue({shopifyDomain:l,storefrontAccessToken:a},{productId:i,dealBlockId:this.getAttribute("deal-block-id")??void 0,country:((c=this.getAttribute("country"))==null?void 0:c.toUpperCase())??void 0,language:((s=this.getAttribute("language"))==null?void 0:s.toUpperCase())??void 0}),C(window)]);!o||e!==this.initializeId||this.renderInnerElement(o)}renderInnerElement(e){const{config:l,dealBlock:a,product:i,otherProducts:o,mediaImages:c,collectionBreaksProducts:s,translations:d}=e;this.innerElement=document.createElement("kaching-bundles-block"),this.innerElement.setAttribute("deal-block-id",a.id),this.innerElement.setAttribute("config",JSON.stringify(l)),this.innerElement.setAttribute("deal-block",JSON.stringify(a)),this.innerElement.setAttribute("media-images",JSON.stringify(c??[])),this.innerElement.setAttribute("product",JSON.stringify(i)),this.innerElement.setAttribute("other-products",JSON.stringify(o??[])),this.innerElement.setAttribute("collection-breaks-products",JSON.stringify(s??[])),this.innerElement.setAttribute("translations",JSON.stringify(d??{}));const p=this.getAttribute("selected-variant-id");this.innerElement.setAttribute("current-variant-id",String(p?p.split("/").pop():i.variants[0].id)),this.hasAttribute("deal-bars-only")&&this.innerElement.setAttribute("deal-bars-only",""),this.appendChild(this.innerElement);const m=()=>{const n=this.innerElement.items();n&&this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:n},bubbles:!0}))};this.handleItemsChanged=n=>{n.stopPropagation(),m()},this.innerElement.addEventListener("kaching-bundles-block-loaded",()=>{this.innerElement.addEventListener("items-changed",this.handleItemsChanged),m(),this.dispatchEvent(new CustomEvent("loaded",{bubbles:!0}))},{once:!0})}cleanup(){this.handleItemsChanged&&this.innerElement&&(this.innerElement.removeEventListener("items-changed",this.handleItemsChanged),this.handleItemsChanged=null),this.innerElement&&(this.innerElement.remove(),this.innerElement=null)}attributeChangedCallback(e,l,a){l!==a&&(e==="product-id"?this.initialize():e==="selected-variant-id"&&this.innerElement&&a&&this.innerElement.setAttribute("current-variant-id",a.includes("/")?String(a.split("/").pop()):a))}items(){return this.innerElement?this.innerElement.items():[]}disconnectedCallback(){this.cleanup(),this.initializeId++}}customElements.define("kaching-bundle-component",he)})();
|