@appmate/wishlist
Advanced tools
Comparing version 4.18.5 to 4.19.0
@@ -7,2 +7,2 @@ var K=Object.create;var M=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var G=(s,i)=>()=>(i||s((i={exports:{}}).exports,i),i.exports);var J=(s,i,e,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of H(i))!z.call(s,r)&&r!==e&&M(s,r,{get:()=>i[r],enumerable:!(t=B(i,r))||t.enumerable});return s};var Q=(s,i,e)=>(e=s!=null?K($(s)):{},J(i||!s||!s.__esModule?M(e,"default",{value:s,enumerable:!0}):e,s));var j=G((De,C)=>{"use strict";var oe=function(){function s(e,t){if(typeof e!="function")throw new TypeError("DataLoader must be constructed with a function which accepts "+("Array<key> and returns Promise<Array<value>>, but got: "+e+"."));this._batchLoadFn=e,this._maxBatchSize=pe(t),this._batchScheduleFn=de(t),this._cacheKeyFn=ue(t),this._cacheMap=me(t),this._batch=null}var i=s.prototype;return i.load=function(t){if(t==null)throw new TypeError("The loader.load() function must be called with a value, "+("but got: "+String(t)+"."));var r=he(this),n=this._cacheMap,a=this._cacheKeyFn(t);if(n){var o=n.get(a);if(o){var h=r.cacheHits||(r.cacheHits=[]);return new Promise(function(c){h.push(function(){c(o)})})}}r.keys.push(t);var l=new Promise(function(c,w){r.callbacks.push({resolve:c,reject:w})});return n&&n.set(a,l),l},i.loadMany=function(t){if(!O(t))throw new TypeError("The loader.loadMany() function must be called with Array<key> "+("but got: "+t+"."));for(var r=[],n=0;n<t.length;n++)r.push(this.load(t[n]).catch(function(a){return a}));return Promise.all(r)},i.clear=function(t){var r=this._cacheMap;if(r){var n=this._cacheKeyFn(t);r.delete(n)}return this},i.clearAll=function(){var t=this._cacheMap;return t&&t.clear(),this},i.prime=function(t,r){var n=this._cacheMap;if(n){var a=this._cacheKeyFn(t);if(n.get(a)===void 0){var o;r instanceof Error?(o=Promise.reject(r),o.catch(function(){})):o=Promise.resolve(r),n.set(a,o)}}return this},s}(),ce=typeof process=="object"&&typeof process.nextTick=="function"?function(s){I||(I=Promise.resolve()),I.then(function(){process.nextTick(s)})}:typeof setImmediate=="function"?function(s){setImmediate(s)}:function(s){setTimeout(s)},I;function he(s){var i=s._batch;if(i!==null&&!i.hasDispatched&&i.keys.length<s._maxBatchSize&&(!i.cacheHits||i.cacheHits.length<s._maxBatchSize))return i;var e={hasDispatched:!1,keys:[],callbacks:[]};return s._batch=e,s._batchScheduleFn(function(){le(s,e)}),e}function le(s,i){if(i.hasDispatched=!0,i.keys.length===0){P(i);return}var e=s._batchLoadFn(i.keys);if(!e||typeof e.then!="function")return F(s,i,new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did "+("not return a Promise: "+String(e)+".")));e.then(function(t){if(!O(t))throw new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did "+("not return a Promise of an Array: "+String(t)+"."));if(t.length!==i.keys.length)throw new TypeError("DataLoader must be constructed with a function which accepts Array<key> and returns Promise<Array<value>>, but the function did not return a Promise of an Array of the same length as the Array of keys."+(` | ||
Values: | ||
`+String(t)));P(i);for(var r=0;r<i.callbacks.length;r++){var n=t[r];n instanceof Error?i.callbacks[r].reject(n):i.callbacks[r].resolve(n)}}).catch(function(t){F(s,i,t)})}function F(s,i,e){P(i);for(var t=0;t<i.keys.length;t++)s.clear(i.keys[t]),i.callbacks[t].reject(e)}function P(s){if(s.cacheHits)for(var i=0;i<s.cacheHits.length;i++)s.cacheHits[i]()}function pe(s){var i=!s||s.batch!==!1;if(!i)return 1;var e=s&&s.maxBatchSize;if(e===void 0)return 1/0;if(typeof e!="number"||e<1)throw new TypeError("maxBatchSize must be a positive number: "+e);return e}function de(s){var i=s&&s.batchScheduleFn;if(i===void 0)return ce;if(typeof i!="function")throw new TypeError("batchScheduleFn must be a function: "+i);return i}function ue(s){var i=s&&s.cacheKeyFn;if(i===void 0)return function(e){return e};if(typeof i!="function")throw new TypeError("cacheKeyFn must be a function: "+i);return i}function me(s){var i=!s||s.cache!==!1;if(!i)return null;var e=s&&s.cacheMap;if(e===void 0)return new Map;if(e!==null){var t=["get","set","delete","clear"],r=t.filter(function(n){return e&&typeof e[n]!="function"});if(r.length!==0)throw new TypeError("Custom cacheMap missing methods: "+r.join(", "))}return e}function O(s){return typeof s=="object"&&s!==null&&typeof s.length=="number"&&(s.length===0||s.length>0&&Object.prototype.hasOwnProperty.call(s,s.length-1))}C.exports=oe});import{of as U}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var{ga:u}=window,m=class{constructor({tracker:i}){this.tracker=i||"t0",this.eventNames=new Map([["addToWishlist","WK Added Product"],["removeFromWishlist","WK Removed Product"],["addToCart","WK Added to Cart"],["shareWishlist","WK Shared Wishlist"],["clearWishlist","WK Cleared Wishlist"]])}track({eventName:i,product:e,variant:t,quantity:r=1}){var a;let n=this.eventNames.get(i);return!n||!(u!=null&&u.loaded)||!e?U(!1):(u(`${this.tracker}.ec:addProduct`,{id:(a=(t==null?void 0:t.sku)||(t==null?void 0:t.id))!=null?a:e.id,name:e.title,category:e.type,brand:e.vendor,variant:t==null?void 0:t.title,quantity:r}),u(`${this.tracker}.send`,{eventAction:n,hitType:"event",eventCategory:"Wishlist",eventLabel:"Wishlist King"}),U(!0))}};import{of as R}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var f=class{constructor({urlUtil:i,moneyUtil:e}){this.urlUtil=i,this.moneyUtil=e,this.eventNames=new Map([["addToWishlist","Added To Wishlist"],["removeFromWishlist","Removed From Wishlist"],["clearWishlist","Cleared Wishlist"]])}track({eventName:i,wishlist:e,product:t,variant:r,quantity:n=1}){let a=this.eventNames.get(i);return!a||!e||!t?R(!1):(window._learnq||(window._learnq=[]),window._learnq.push(["track",a,{URL:this.urlUtil.getVariantUrl(t.url,r==null?void 0:r.id),Name:t.title,ProductID:t.id,VariantID:r==null?void 0:r.id,SKU:r==null?void 0:r.sku,Tags:t.tags,Brand:t.vendor,ImageURL:this.urlUtil.getImageUrl(t,{width:1e3}),Price:r==null?void 0:r.price,PriceFormatted:r?this.moneyUtil.formatMoney(r.price):null,CompareAtPrice:r==null?void 0:r.compare_at_price,CompareAtPriceFormatted:r!=null&&r.compare_at_price?this.moneyUtil.formatMoney(r.compare_at_price):null,Quantity:n,WishlistUrl:this.urlUtil.getPublicWishlistUrl(e.id)}]),R(!0))}};import{of as L}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var{fbq:N}=window,g=class{constructor({currency:i}){this.currency=i,this.eventNames=new Map([["addToWishlist","AddToWishlist"]])}track({eventName:i,product:e,variant:t}){let r=this.eventNames.get(i);return!r||typeof N!="function"||!e?L(!1):(N("track",r,{value:t==null?void 0:t.price,currency:this.currency,content_ids:[e.id],content_name:[e.title,t==null?void 0:t.title].filter(n=>!!n).join(" - "),content_category:e.type,content_type:"product_group",num_items:1}),L(!0))}};import{catchError as X,map as Y,of as _}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";import{fromFetch as Z}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/fetch/+esm";var d=class{constructor({host:i,shop:e,sessionId:t,customerId:r}){this.host=i,this.shop=e,this.customerId=r,this.sessionId=t,this.eventNames=new Map([["viewWishlist","wishlist_viewed"],["addToCart","product_added_to_cart"],["shareWishlist","wishlist_shared"]])}setSessionId(i){this.sessionId=i}track({eventName:i,wishlist:e,product:t,variant:r,quantity:n,source:a}){var h,l;if(!this.sessionId)return _(!1);let o=this.eventNames.get(i);return!o||!e?_(!1):Z(this.host+"/notify",{method:"POST",headers:{"content-type":"application/json","x-appmate-shp":this.shop,"x-appmate-sid":(h=this.sessionId)!=null?h:"","x-appmate-cid":(l=this.customerId)!=null?l:""},body:JSON.stringify({event:o,wid:e.publicId,pid:t==null?void 0:t.id,vid:r==null?void 0:r.id,qty:n,src:a})}).pipe(Y(()=>!0),X(()=>_(!1)))}getQuerystring(i){if(!i)return"";let e=new URLSearchParams;return Object.entries(i).forEach(([t,r])=>{Array.isArray(r)?r.forEach(n=>e.append(t,n)):r&&e.append(t,r)}),"?"+e.toString()}};import{fromFetch as ee}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/fetch/+esm";import{switchMap as te}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var p=class{constructor(i){this.host=i.host,this.headers={"content-type":"application/json"}}fetch({path:i,method:e="GET",query:t,body:r,headers:n={}}){return ee(this.host+i+this.getQuerystring(t),{method:e,headers:{...this.headers,...n},body:r}).pipe(te(a=>{if(a.ok)return a.json();throw Error(`Error ${a.status}`)}))}getQuerystring(i){if(!i)return"";let e=new URLSearchParams;return Object.entries(i).forEach(([t,r])=>{Array.isArray(r)?r.forEach(n=>e.append(t,n)):r&&e.append(t,r)}),"?"+e.toString()}get({path:i,query:e,headers:t}){return this.fetch({method:"GET",path:i,query:e,headers:t})}post({path:i,query:e,body:t,headers:r}){return this.fetch({method:"POST",path:i,query:e,body:t?JSON.stringify(t):void 0,headers:r})}put({path:i,query:e,body:t,headers:r}){return this.fetch({method:"PUT",path:i,query:e,body:t?JSON.stringify(t):void 0,headers:r})}delete({path:i,query:e,body:t,headers:r}){return this.fetch({method:"DELETE",path:i,query:e,body:t?JSON.stringify(t):void 0,headers:r})}};import{shareReplay as ie,tap as re}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var T=class extends p{constructor(){super(...arguments);this.pendingProducts=new Map}loadProduct({productHandle:e}){let t=`/products/${e}.js`,r=this.pendingProducts.get(t);if(r)return r;let n=this.get({path:t}).pipe(re(()=>{this.pendingProducts.delete(t)}),ie());return this.pendingProducts.set(t,n),n}addToCart(e){return this.post({path:"/cart/add.js",body:e})}};import{forkJoin as se,lastValueFrom as ne,of as ae}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var v=class{constructor({settings:i,events:e,notifyHost:t,utils:r,theme:n,shop:a,sessionId:o,customerId:h}){this.utils=r,this.theme=n,this.services=[],i.integrations.wishlistAnalytics.enabled&&this.services.push(new d({host:t,shop:a,customerId:h,sessionId:o})),i.integrations.klaviyo.enabled&&this.services.push(new f({urlUtil:this.utils.url,moneyUtil:this.utils.money})),i.integrations.metaPixel.enabled&&this.services.push(new g({currency:window.Shopify.currency.active})),i.integrations.googleAnalytics.enabled&&this.services.push(new m({tracker:i.integrations.googleAnalytics.tracker}));let l=this.theme.getPageType(),c=w=>y=>{var W,A,x,E;return ne(this.track({eventName:w,source:l,wishlist:(W=y.data)==null?void 0:W.wishlist,product:(A=y.data)==null?void 0:A.product,variant:(x=y.data)==null?void 0:x.variant,quantity:(E=y.data)==null?void 0:E.quantity}))};e.subscribeMany({"wk:wishlist:add-to-cart:success":c("addToCart"),"wk:wishlist:add:success":c("addToWishlist"),"wk:wishlist:change-variant:success":c("changeVariant"),"wk:wishlist:clear:success":c("clearWishlist"),"wk:wishlist:remove:success":c("removeFromWishlist"),"wk:wishlist:share:success":c("shareWishlist"),"wk:wishlist:page-view":c("viewWishlist")})}track(i){return this.services.length?se(this.services.map(e=>e.track(i))):ae([])}setSessionId(i){let e=this.services.find(t=>t instanceof d);e&&e.setSessionId(i)}};var k=Q(j());import{defer as q,from as D,lastValueFrom as V,shareReplay as b,switchMap as fe,tap as ge}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var S=class extends p{constructor(e){super(e);this.headers={"content-type":"application/json","x-appmate-api":"2022-11"},e.shop&&(this.headers["x-appmate-shp"]=e.shop),e.sessionId&&(this.headers["x-appmate-sid"]=e.sessionId),e.customerId&&(this.headers["x-appmate-cid"]=e.customerId.toString()),e.trackingSource&&(this.headers["x-appmate-src"]=e.trackingSource),this.wishlistLoader=this.createWishlistLoader(),this.wishlistItemLoader=this.createWishlistItemLoader()}get hasSession(){return!!this.headers["x-appmate-sid"]||!!this.headers["x-appmate-cid"]}setSessionId(e){this.headers["x-appmate-sid"]=e}createWishlistLoader(){return new k.default(async e=>{let t=await Promise.all(e.map(r=>V(this.get({path:`/wishlists/${r}`})))).then(r=>r.map(n=>n.wishlist));return e.map(r=>{var n;return(n=t.find(a=>r==="mine"?a.isMine:a.publicId===r))!=null?n:new Error("Wishlist not found")})},{cache:!0,batchScheduleFn:e=>setTimeout(e,250)})}createWishlistItemLoader(){return new k.default(async e=>{let t=e.map(n=>n.split("-")).reduce((n,[a,o])=>(n[a]||(n[a]=[]),n[a].push(o),n),{}),r=await Promise.all(Object.entries(t).map(([n,a])=>V(this.get({path:`/wishlists/${n}/items`,headers:{"x-appmate-ids":a.join(",")}})))).then(n=>n.flatMap(a=>a.items));return e.map(n=>{var o;let[,a]=n.split("-");return(o=r.find(h=>h.id===a))!=null?o:new Error("Wishlist item not found")})},{cache:!0,batchScheduleFn:e=>setTimeout(e,250)})}loadWishlist({wishlistId:e}){return D(q(()=>this.wishlistLoader.load(e).then(t=>({wishlist:t}))))}loadWishlistItem({wishlistId:e,wishlistItemId:t}){return D(q(()=>this.wishlistItemLoader.load([e,t].join("-")).then(({selectedVariantId:r,...n})=>({wishlistItem:n}))))}addItem({productId:e,variantId:t}){if(typeof e=="string"&&(e=parseInt(e)),typeof t=="string"&&(t=parseInt(t)),!this.hasSession&&this._pendingSessionId)return this._pendingSessionId.pipe(fe(()=>this.addItem({productId:e,variantId:t})));let r=this.post({path:"/wishlists/mine/items",body:{productId:e,variantId:t}}).pipe(ge(n=>{n.sessionId&&(this.setSessionId(n.sessionId),this._pendingSessionId=void 0)}),b());return this.hasSession||(this._pendingSessionId=r),r}updateItem({wishlistItemId:e,changes:t}){return this.put({path:"/wishlists/mine/items",body:{changes:{...t,wishlistItemId:e}}}).pipe(b())}removeItem({wishlistId:e,wishlistItemId:t}){return this.delete({path:`/wishlists/${e}/items`,body:{wishlistItemId:t}}).pipe(b())}clearWishlist(){return this.delete({path:"/wishlists/mine"}).pipe(b())}};export{m as GoogleAnalytics,f as KlaviyoTracking,g as MetaPixel,d as NotifyApi,p as RestApi,T as ShopifyApi,v as TrackingApi,S as WishlistApi}; | ||
`+String(t)));P(i);for(var r=0;r<i.callbacks.length;r++){var n=t[r];n instanceof Error?i.callbacks[r].reject(n):i.callbacks[r].resolve(n)}}).catch(function(t){F(s,i,t)})}function F(s,i,e){P(i);for(var t=0;t<i.keys.length;t++)s.clear(i.keys[t]),i.callbacks[t].reject(e)}function P(s){if(s.cacheHits)for(var i=0;i<s.cacheHits.length;i++)s.cacheHits[i]()}function pe(s){var i=!s||s.batch!==!1;if(!i)return 1;var e=s&&s.maxBatchSize;if(e===void 0)return 1/0;if(typeof e!="number"||e<1)throw new TypeError("maxBatchSize must be a positive number: "+e);return e}function de(s){var i=s&&s.batchScheduleFn;if(i===void 0)return ce;if(typeof i!="function")throw new TypeError("batchScheduleFn must be a function: "+i);return i}function ue(s){var i=s&&s.cacheKeyFn;if(i===void 0)return function(e){return e};if(typeof i!="function")throw new TypeError("cacheKeyFn must be a function: "+i);return i}function me(s){var i=!s||s.cache!==!1;if(!i)return null;var e=s&&s.cacheMap;if(e===void 0)return new Map;if(e!==null){var t=["get","set","delete","clear"],r=t.filter(function(n){return e&&typeof e[n]!="function"});if(r.length!==0)throw new TypeError("Custom cacheMap missing methods: "+r.join(", "))}return e}function O(s){return typeof s=="object"&&s!==null&&typeof s.length=="number"&&(s.length===0||s.length>0&&Object.prototype.hasOwnProperty.call(s,s.length-1))}C.exports=oe});import{of as U}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var{ga:u}=window,m=class{constructor({tracker:i}){this.tracker=i||"t0",this.eventNames=new Map([["addToWishlist","WK Added Product"],["removeFromWishlist","WK Removed Product"],["addToCart","WK Added to Cart"],["shareWishlist","WK Shared Wishlist"],["clearWishlist","WK Cleared Wishlist"]])}track({eventName:i,product:e,variant:t,quantity:r=1}){var a;let n=this.eventNames.get(i);return!n||!(u!=null&&u.loaded)||!e?U(!1):(u(`${this.tracker}.ec:addProduct`,{id:(a=(t==null?void 0:t.sku)||(t==null?void 0:t.id))!=null?a:e.id,name:e.title,category:e.type,brand:e.vendor,variant:t==null?void 0:t.title,quantity:r}),u(`${this.tracker}.send`,{eventAction:n,hitType:"event",eventCategory:"Wishlist",eventLabel:"Wishlist King"}),U(!0))}};import{of as R}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var f=class{constructor({urlUtil:i,moneyUtil:e}){this.urlUtil=i,this.moneyUtil=e,this.eventNames=new Map([["addToWishlist","Added To Wishlist"],["removeFromWishlist","Removed From Wishlist"],["clearWishlist","Cleared Wishlist"]])}track({eventName:i,wishlist:e,product:t,variant:r,quantity:n=1}){let a=this.eventNames.get(i);return!a||!e||!t?R(!1):(window._learnq||(window._learnq=[]),window._learnq.push(["track",a,{URL:this.urlUtil.getVariantUrl(t.url,r==null?void 0:r.id),Name:t.title,ProductID:t.id,VariantID:r==null?void 0:r.id,SKU:r==null?void 0:r.sku,Tags:t.tags,Brand:t.vendor,ImageURL:this.urlUtil.getImageUrl(t,{width:1e3}),Price:r==null?void 0:r.price,PriceFormatted:r?this.moneyUtil.formatMoney(r.price):null,CompareAtPrice:r==null?void 0:r.compare_at_price,CompareAtPriceFormatted:r!=null&&r.compare_at_price?this.moneyUtil.formatMoney(r.compare_at_price):null,Quantity:n,WishlistUrl:this.urlUtil.getPublicWishlistUrl(e.id)}]),R(!0))}};import{of as L}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var{fbq:N}=window,g=class{constructor({currency:i}){this.currency=i,this.eventNames=new Map([["addToWishlist","AddToWishlist"]])}track({eventName:i,product:e,variant:t}){let r=this.eventNames.get(i);return!r||typeof N!="function"||!e?L(!1):(N("track",r,{value:t==null?void 0:t.price,currency:this.currency,content_ids:[e.id],content_name:[e.title,t==null?void 0:t.title].filter(n=>!!n).join(" - "),content_category:e.type,content_type:"product_group",num_items:1}),L(!0))}};import{catchError as X,map as Y,of as _}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";import{fromFetch as Z}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/fetch/+esm";var d=class{constructor({host:i,shop:e,sessionId:t,customerId:r}){this.host=i,this.shop=e,this.customerId=r,this.sessionId=t,this.eventNames=new Map([["viewWishlist","wishlist_viewed"],["addToCart","product_added_to_cart"],["shareWishlist","wishlist_shared"]])}setSessionId(i){this.sessionId=i}track({eventName:i,wishlist:e,product:t,variant:r,quantity:n,source:a}){var h,l;if(!this.sessionId)return _(!1);let o=this.eventNames.get(i);return!o||!e?_(!1):Z(this.host+"/notify",{method:"POST",headers:{"content-type":"application/json","x-appmate-shp":this.shop,"x-appmate-sid":(h=this.sessionId)!=null?h:"","x-appmate-cid":(l=this.customerId)!=null?l:""},body:JSON.stringify({event:o,wid:e.publicId,pid:t==null?void 0:t.id,vid:r==null?void 0:r.id,qty:n,src:a})}).pipe(Y(()=>!0),X(()=>_(!1)))}getQuerystring(i){if(!i)return"";let e=new URLSearchParams;return Object.entries(i).forEach(([t,r])=>{Array.isArray(r)?r.forEach(n=>e.append(t,n)):r&&e.append(t,r)}),"?"+e.toString()}};import{fromFetch as ee}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/fetch/+esm";import{switchMap as te}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var p=class{constructor(i){this.host=i.host,this.headers={"content-type":"application/json"}}fetch({path:i,method:e="GET",query:t,body:r,headers:n={}}){return ee(this.host+i+this.getQuerystring(t),{method:e,headers:{...this.headers,...n},body:r}).pipe(te(a=>{if(a.ok)return a.json();throw Error(`Error ${a.status}`)}))}getQuerystring(i){if(!i)return"";let e=new URLSearchParams;return Object.entries(i).forEach(([t,r])=>{Array.isArray(r)?r.forEach(n=>e.append(t,n)):r&&e.append(t,r)}),"?"+e.toString()}get({path:i,query:e,headers:t}){return this.fetch({method:"GET",path:i,query:e,headers:t})}post({path:i,query:e,body:t,headers:r}){return this.fetch({method:"POST",path:i,query:e,body:t?JSON.stringify(t):void 0,headers:r})}put({path:i,query:e,body:t,headers:r}){return this.fetch({method:"PUT",path:i,query:e,body:t?JSON.stringify(t):void 0,headers:r})}delete({path:i,query:e,body:t,headers:r}){return this.fetch({method:"DELETE",path:i,query:e,body:t?JSON.stringify(t):void 0,headers:r})}};import{shareReplay as ie,tap as re}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var T=class extends p{constructor(){super(...arguments);this.pendingProducts=new Map}loadProduct({productHandle:e}){let t=`/products/${e}.js`,r=this.pendingProducts.get(t);if(r)return r;let n=this.get({path:t}).pipe(re(()=>{this.pendingProducts.delete(t)}),ie());return this.pendingProducts.set(t,n),n}addToCart(e){return this.post({path:"/cart/add.js",body:e})}};import{forkJoin as se,lastValueFrom as ne,of as ae}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var v=class{constructor({settings:i,events:e,notifyHost:t,utils:r,theme:n,shop:a,sessionId:o,customerId:h}){this.utils=r,this.theme=n,this.services=[],i.integrations.wishlistAnalytics.enabled&&this.services.push(new d({host:t,shop:a,customerId:h,sessionId:o})),i.integrations.klaviyo.enabled&&this.services.push(new f({urlUtil:this.utils.url,moneyUtil:this.utils.money})),i.integrations.metaPixel.enabled&&this.services.push(new g({currency:window.Shopify.currency.active})),i.integrations.googleAnalytics.enabled&&this.services.push(new m({tracker:i.integrations.googleAnalytics.tracker}));let l=this.theme.getPageType(),c=w=>y=>{var W,A,x,E;return ne(this.track({eventName:w,source:l,wishlist:(W=y.data)==null?void 0:W.wishlist,product:(A=y.data)==null?void 0:A.product,variant:(x=y.data)==null?void 0:x.variant,quantity:(E=y.data)==null?void 0:E.quantity}))};e.subscribeMany({"wk:wishlist:add-to-cart:success":c("addToCart"),"wk:wishlist:add:success":c("addToWishlist"),"wk:wishlist:change-variant:success":c("changeVariant"),"wk:wishlist:clear:success":c("clearWishlist"),"wk:wishlist:remove:success":c("removeFromWishlist"),"wk:wishlist:share:success":c("shareWishlist"),"wk:wishlist:page-view":c("viewWishlist")})}track(i){return this.services.length?se(this.services.map(e=>e.track(i))):ae([])}setSessionId(i){let e=this.services.find(t=>t instanceof d);e&&e.setSessionId(i)}};var k=Q(j());import{defer as q,from as D,lastValueFrom as V,shareReplay as b,switchMap as fe,tap as ge}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var S=class extends p{constructor(e){super(e);this.headers={"content-type":"application/json","x-appmate-api":"2022-11"},e.shop&&(this.headers["x-appmate-shp"]=e.shop),e.sessionId&&(this.headers["x-appmate-sid"]=e.sessionId),e.customerId&&(this.headers["x-appmate-cid"]=e.customerId.toString()),e.trackingSource&&(this.headers["x-appmate-src"]=e.trackingSource),this.wishlistLoader=this.createWishlistLoader(),this.wishlistItemLoader=this.createWishlistItemLoader()}get hasSession(){return!!this.headers["x-appmate-sid"]||!!this.headers["x-appmate-cid"]}setSessionId(e){this.headers["x-appmate-sid"]=e}createWishlistLoader(){return new k.default(async e=>{let t=await Promise.all(e.map(r=>V(this.get({path:`/wishlists/${r}`})))).then(r=>r.map(n=>n.wishlist));return e.map(r=>{var n;return(n=t.find(a=>r==="mine"?a.isMine:a.publicId===r))!=null?n:new Error("Wishlist not found")})},{cache:!0,batchScheduleFn:e=>setTimeout(e,250)})}createWishlistItemLoader(){return new k.default(async e=>{let t=e.map(n=>n.split("-")).reduce((n,[a,o])=>(n[a]||(n[a]=[]),n[a].push(o),n),{}),r=await Promise.all(Object.entries(t).map(([n,a])=>V(this.get({path:`/wishlists/${n}/items`,headers:{"x-appmate-ids":a.join(",")}})))).then(n=>n.flatMap(a=>a.items));return e.map(n=>{var o;let[,a]=n.split("-");return(o=r.find(h=>h.id===a))!=null?o:new Error("Wishlist item not found")})},{cache:!0,batchScheduleFn:e=>setTimeout(e,250)})}loadWishlist({wishlistId:e}){return D(q(()=>this.wishlistLoader.load(e).then(t=>({wishlist:t}))))}loadWishlistItem({wishlistId:e,wishlistItemId:t}){return D(q(()=>this.wishlistItemLoader.load([e,t].join("-")).then(({selectedVariantId:r,...n})=>({wishlistItem:n}))))}addItem({productId:e,variantId:t}){if(typeof e=="string"&&(e=parseInt(e)),typeof t=="string"&&(t=parseInt(t)),!this.hasSession&&this._pendingSessionId)return this._pendingSessionId.pipe(fe(()=>this.addItem({productId:e,variantId:t})));let r=this.post({path:"/wishlists/mine/items",body:{productId:e,variantId:t}}).pipe(ge(n=>{n.sessionId&&(this.setSessionId(n.sessionId),this._pendingSessionId=void 0)}),b());return this.hasSession||(this._pendingSessionId=r),r}updateItem({wishlistItemId:e,changes:t}){return this.put({path:"/wishlists/mine/items",body:{changes:{...t,wishlistItemId:e}}}).pipe(b())}removeItem({wishlistId:e,wishlistItemId:t}){return this.delete({path:`/wishlists/${e}/items`,body:{wishlistItemId:t}}).pipe(b())}clearWishlist(){return this.delete({path:"/wishlists/mine"}).pipe(b())}};export{m as GoogleAnalytics,f as KlaviyoTracking,g as MetaPixel,d as NotifyApi,p as RestApi,T as ShopifyApi,v as TrackingApi,S as WishlistApi}; |
@@ -1,1 +0,1 @@ | ||
var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var r=(p,n,i,o)=>{for(var t=o>1?void 0:o?y(n,i):n,l=p.length-1,s;l>=0;l--)(s=p[l])&&(t=(o?s(n,i,t):s(t))||t);return o&&t&&m(n,i,t),t};import{LitElement as c}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{customElement as g,property as a}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{html as h}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/+esm";import{FloatingUiController as u}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/controllers.js";var e=class extends c{constructor(){super(...arguments);this.text="";this.layout="text-only";this.parentheses=!1;this.floatingUi=new u(this)}render(){var t,l;let i=(t=this.layout)!=null&&t.includes("text")?this.text:"",o=["wk-badge",!!this.parentheses&&"wk-parentheses",((l=this.layout)==null?void 0:l.includes("pill"))&&"wk-pill"].filter(s=>!!s).join(" ");return h`<span class=${o}>${i}</span>`}createRenderRoot(){return this}};r([a({type:String})],e.prototype,"text",2),r([a({type:String})],e.prototype,"layout",2),r([a({type:Boolean})],e.prototype,"parentheses",2),r([a({type:Object})],e.prototype,"floating",2),e=r([g("wk-badge")],e);export{e as Badge}; | ||
import{LitElement as r,html as a}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";import{FloatingUiController as s}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/controllers.js";var t=class extends r{constructor(){super(...arguments);this.text="";this.layout="text-only";this.parentheses=!1;this.floatingUi=new s(this)}render(){var e,l;let o=(e=this.layout)!=null&&e.includes("text")?this.text:"",n=["wk-badge",!!this.parentheses&&"wk-parentheses",((l=this.layout)==null?void 0:l.includes("pill"))&&"wk-pill"].filter(i=>!!i).join(" ");return a`<span class=${n}>${o}</span>`}createRenderRoot(){return this}};t.properties={text:{type:String},layout:{type:String},parentheses:{type:Boolean},floating:{type:Object}};customElements.get("wk-badge")||customElements.define("wk-badge",t);export{t as Badge}; |
@@ -1,10 +0,10 @@ | ||
var u=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var r=(o,n,e,i)=>{for(var l=i>1?void 0:i?c(n,e):n,s=o.length-1,g;s>=0;s--)(g=o[s])&&(l=(i?g(n,e,l):g(l))||l);return i&&l&&u(n,e,l),l};import{LitElement as y}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{customElement as x,property as a}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{html as d}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/+esm";var h=Number.isNaN||function(n){return typeof n=="number"&&n!==n};function p(o,n){return!!(o===n||h(o)&&h(n))}function m(o,n){if(o.length!==n.length)return!1;for(var e=0;e<o.length;e++)if(!p(o[e],n[e]))return!1;return!0}function f(o,n){n===void 0&&(n=m);var e=null;function i(){for(var l=[],s=0;s<arguments.length;s++)l[s]=arguments[s];if(e&&e.lastThis===this&&n(l,e.lastArgs))return e.lastResult;var g=o.apply(this,l);return e={lastResult:g,lastArgs:l,lastThis:this},g}return i.clear=function(){e=null},i}import{FloatingUiController as $}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/controllers.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/components/badge.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/components/icon.js";var t=class extends y{constructor(){super(...arguments);this.text="";this.hint="";this.selected=!1;this.disabled=!1;this.layout="icon-and-text";this.outline=!1;this.fullWidth=!1;this.alignment="center";this.badgeParentheses=!1;this.badgeHidden=!1;this.badgeHiddenIfEmpty=!1;this.floatingUi=new $(this);this.getBadgeFloating=f((e,i)=>{if(!(!e||!i))return{...e,reference:i}})}render(){var l,s,g;let i=["wk-button",`wk-align-${(l=this.alignment)!=null?l:"center"}`,this.selected&&"wk-selected",this.outline&&"wk-outline",this.fullWidth&&"wk-full-width"].filter(b=>!!b).join(" ");return this.href?d` | ||
<a href=${this.href} aria-label=${(s=this.hint)!=null?s:""} class=${i}> | ||
import{LitElement as b,html as l}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";var g=Number.isNaN||function(e){return typeof e=="number"&&e!==e};function h(i,e){return!!(i===e||g(i)&&g(e))}function f(i,e){if(i.length!==e.length)return!1;for(var t=0;t<i.length;t++)if(!h(i[t],e[t]))return!1;return!0}function d(i,e){e===void 0&&(e=f);var t=null;function n(){for(var a=[],r=0;r<arguments.length;r++)a[r]=arguments[r];if(t&&t.lastThis===this&&e(a,t.lastArgs))return t.lastResult;var o=i.apply(this,a);return t={lastResult:o,lastArgs:a,lastThis:this},o}return n.clear=function(){t=null},n}import{FloatingUiController as c}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/controllers.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/components/badge.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/components/icon.js";var s=class extends b{constructor(){super(...arguments);this.text="";this.hint="";this.selected=!1;this.disabled=!1;this.layout="icon-and-text";this.outline=!1;this.fullWidth=!1;this.alignment="center";this.badgeParentheses=!1;this.badgeHidden=!1;this.badgeHiddenIfEmpty=!1;this.floatingUi=new c(this);this.getBadgeFloating=d((t,n)=>{if(!(!t||!n))return{...t,reference:n}})}render(){var a,r,o;let n=["wk-button",`wk-align-${(a=this.alignment)!=null?a:"center"}`,this.selected&&"wk-selected",this.outline&&"wk-outline",this.fullWidth&&"wk-full-width"].filter(u=>!!u).join(" ");return this.href?l` | ||
<a href=${this.href} aria-label=${(r=this.hint)!=null?r:""} class=${n}> | ||
${this.renderIcon()}${this.renderText()}${this.renderBadge()} | ||
</a> | ||
`:d` | ||
`:l` | ||
<button | ||
type="button" | ||
aria-label=${(g=this.hint)!=null?g:""} | ||
class=${i} | ||
aria-label=${(o=this.hint)!=null?o:""} | ||
class=${n} | ||
?disabled=${this.disabled} | ||
@@ -14,3 +14,3 @@ > | ||
</button> | ||
`}renderIcon(){var i;let e=(i=this.layout)!=null?i:"icon-and-text";if(!(!(e!=null&&e.includes("icon"))||!this.icon))return d`<wk-icon icon=${this.icon} class="wk-icon"></wk-icon>`}renderText(){var i;let e=(i=this.layout)!=null?i:"icon-and-text";if(!!(e!=null&&e.includes("text")))return d`<span class="wk-text">${this.text}</span>`}renderBadge(){if(!(!this.badgeLayout||this.badgeHidden||this.badgeText===void 0)&&!(this.badgeHiddenIfEmpty&&(!this.badgeText||parseInt(this.badgeText)===0)))return d`<wk-badge | ||
`}renderIcon(){var n;let t=(n=this.layout)!=null?n:"icon-and-text";if(!(!(t!=null&&t.includes("icon"))||!this.icon))return l`<wk-icon icon=${this.icon} class="wk-icon"></wk-icon>`}renderText(){var n;let t=(n=this.layout)!=null?n:"icon-and-text";if(t!=null&&t.includes("text"))return l`<span class="wk-text">${this.text}</span>`}renderBadge(){if(!(!this.badgeLayout||this.badgeHidden||this.badgeText===void 0)&&!(this.badgeHiddenIfEmpty&&(!this.badgeText||parseInt(this.badgeText)===0)))return l`<wk-badge | ||
.text=${this.badgeText} | ||
@@ -20,2 +20,2 @@ .layout=${this.badgeLayout} | ||
.floating=${this.getBadgeFloating(this.badgeFloating,this)} | ||
></wk-badge>`}createRenderRoot(){return this}};r([a({type:String})],t.prototype,"href",2),r([a({type:String})],t.prototype,"text",2),r([a({type:String})],t.prototype,"hint",2),r([a({type:Boolean})],t.prototype,"selected",2),r([a({type:Boolean})],t.prototype,"disabled",2),r([a({type:String})],t.prototype,"layout",2),r([a({type:String})],t.prototype,"icon",2),r([a({type:Boolean})],t.prototype,"outline",2),r([a({type:Boolean,attribute:"full-width"})],t.prototype,"fullWidth",2),r([a({type:String})],t.prototype,"alignment",2),r([a({type:Object})],t.prototype,"floating",2),r([a({type:String,attribute:"badge-text"})],t.prototype,"badgeText",2),r([a({type:String,attribute:"badge-layout"})],t.prototype,"badgeLayout",2),r([a({type:Boolean,attribute:"badge-parentheses"})],t.prototype,"badgeParentheses",2),r([a({type:Boolean,attribute:"badge-hidden"})],t.prototype,"badgeHidden",2),r([a({type:Boolean,attribute:"badge-hidden-if-empty"})],t.prototype,"badgeHiddenIfEmpty",2),r([a({type:Object,attribute:"badge-floating"})],t.prototype,"badgeFloating",2),t=r([x("wk-button")],t);export{t as Button}; | ||
></wk-badge>`}createRenderRoot(){return this}};s.properties={href:{type:String},text:{type:String},hint:{type:String},selected:{type:Boolean},disabled:{type:Boolean},layout:{type:String},icon:{type:String},outline:{type:Boolean},fullWidth:{type:Boolean,attribute:"full-width"},alignment:{type:String},floating:{type:Object},badgeText:{type:String,attribute:"badge-text"},badgeLayout:{type:String,attribute:"badge-layout"},badgeParentheses:{type:Boolean,attribute:"badge-parentheses"},badgeHidden:{type:Boolean,attribute:"badge-hidden"},badgeHiddenIfEmpty:{type:Boolean,attribute:"badge-hidden-if-empty"},badgeFloating:{type:Object,attribute:"badge-floating"}};customElements.get("wk-button")||customElements.define("wk-button",s);export{s as Button}; |
@@ -1,1 +0,1 @@ | ||
var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var c=(g,r,i,s)=>{for(var n=s>1?void 0:s?m(r,i):r,e=g.length-1,o;e>=0;e--)(o=g[e])&&(n=(s?o(r,i,n):o(n))||n);return s&&n&&d(r,i,n),n};import{LitElement as p}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{customElement as f,property as l}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{svg as a,unsafeStatic as u}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/static/+esm";var t=class extends p{constructor(){super();this.icon="";this.classList.add("wk-icon")}static addIcons(i){this.icons={...this.icons,...i}}render(){var s;if(!this.icon)return a`<svg><!-- icon not defined --></svg>`;let i=(s=t.icons[this.icon])!=null?s:a`<svg><!-- icon not found --></svg>`;return a`${u(i)}`}createRenderRoot(){return this}};t.icons={},c([l({type:String})],t.prototype,"icon",2),t=c([f("wk-icon")],t);export{t as Icon}; | ||
import{LitElement as o}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";import{unsafeHTML as e}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";var n=class extends o{constructor(){super();this.icon="";this.classList.add("wk-icon")}static addIcons(i){this.icons={...this.icons,...i}}render(){var s;if(!this.icon)return e("<svg><!-- icon not defined --></svg>");let i=(s=n.icons[this.icon])!=null?s:e("<svg><!-- icon not found --></svg>");return e(`${i}`)}createRenderRoot(){return this}},t=n;t.properties={icon:{type:String}},t.icons={};customElements.get("wk-icon")||customElements.define("wk-icon",t);export{t as Icon}; |
@@ -1,12 +0,12 @@ | ||
var m=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=(l,n,r,e)=>{for(var t=e>1?void 0:e?u(n,r):n,i=l.length-1,o;i>=0;i--)(o=l[i])&&(t=(e?o(n,r,t):o(t))||t);return e&&t&&m(n,r,t),t};import{LitElement as h}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{customElement as w,property as p}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{html as d}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/+esm";import{Icon as $}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/components/icon.js";var s=class extends h{constructor(){super();this.icon="caret"}render(){var i;if(!this.option)return;let r=`options[${this.option.name}]`,e=`${this.id}-select`,t=["wk-option-select",((i=this.option)==null?void 0:i.values.length)===1&&"wk-single-option"].filter(o=>!!o).join(" ");return d` | ||
<div class=${t}> | ||
<label class="wk-label" for=${e}>${this.option.name}</label> | ||
import{LitElement as r,html as n}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";import{Icon as a}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/components/icon.js";var e=class extends r{constructor(){super();this.icon="caret"}render(){var i;if(!this.option)return;let c=`options[${this.option.name}]`,o=`${this.id}-select`,l=["wk-option-select",((i=this.option)==null?void 0:i.values.length)===1&&"wk-single-option"].filter(t=>!!t).join(" ");return n` | ||
<div class=${l}> | ||
<label class="wk-label" for=${o}>${this.option.name}</label> | ||
<div class="wk-control"> | ||
<select id=${e} class="wk-input" name=${r}> | ||
${this.option.values.map(o=>{var a;return d` | ||
<select id=${o} class="wk-input" name=${c}> | ||
${this.option.values.map(t=>{var s;return n` | ||
<option | ||
value=${o} | ||
?selected=${o===((a=this.option)==null?void 0:a.selectedValue)} | ||
value=${t} | ||
?selected=${t===((s=this.option)==null?void 0:s.selectedValue)} | ||
> | ||
${o} | ||
${t} | ||
</option> | ||
@@ -23,6 +23,6 @@ `})} | ||
</div> | ||
`}createRenderRoot(){return this}};c([p({type:String})],s.prototype,"icon",2),c([p({type:Object})],s.prototype,"option",2),s=c([w("wk-option-select")],s);$.addIcons({caret:` | ||
`}createRenderRoot(){return this}};e.properties={icon:{type:String},option:{type:Object}};a.addIcons({caret:` | ||
<svg aria-hidden="true" focusable="false" role="presentation" viewBox="0 0 24 24"> | ||
<path d="M6 9l6 6 6-6" /> | ||
</svg> | ||
`});export{s as OptionSelect}; | ||
`});customElements.get("wk-option-select")||customElements.define("wk-option-select",e);export{e as OptionSelect}; |
@@ -1,85 +0,6 @@ | ||
var p=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var r=(a,n,t,o)=>{for(var i=o>1?void 0:o?c(n,t):n,s=a.length-1,d;s>=0;s--)(d=a[s])&&(i=(o?d(n,t,i):d(i))||i);return o&&i&&p(n,t,i),i};import{LitElement as u,css as w}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{customElement as m,state as v,property as l}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{html as f}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/+esm";import{FloatingUiController as g}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/controllers.js";var e=class extends u{constructor(){super(...arguments);this.text="";this.autoShow=!1;this.autoHide=!1;this.floatingUi=new g(this)}get added(){return!!this.parentElement}get showing(){return this.transition==="show"}get hiding(){return this.transition==="hide"}render(){var o;let t=["wk-popover",this.transition?`wk-${this.transition}`:"",this.elementClass].filter(i=>!!i).join(" ");return f` | ||
import{LitElement as s,html as o}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";import{FloatingUiController as r}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/controllers.js";var n=class extends s{constructor(){super(...arguments);this.text="";this.autoShow=!1;this.autoHide=!1;this.floatingUi=new r(this)}get added(){return!!this.parentElement}get showing(){return this.transition==="show"}get hiding(){return this.transition==="hide"}render(){var e;let t=["wk-popover",this.transition?`wk-${this.transition}`:"",this.elementClass].filter(i=>!!i).join(" ");return o` | ||
<div class=${t}> | ||
<div class="wk-text">${this.getText()}</div> | ||
${(o=this.floatingUi)==null?void 0:o.arrowEl} | ||
${(e=this.floatingUi)==null?void 0:e.arrowEl} | ||
</div> | ||
`}firstUpdated(){this.autoShow!==!1&&(this._autoShowTimer=setTimeout(()=>this.show(),(this.autoShow===!0?0:this.autoShow)*1e3)),this.autoHide!==!1&&(this._autoHideTimer=setTimeout(()=>this.hide(),(this.autoHide===!0?2:this.autoHide)*1e3))}add(t=document.body){this.added||t.appendChild(this)}show(t){if(this.showing)return;this.clearAllTimer(),this.added||this.add(),requestAnimationFrame(()=>{this.transition="show"});let o=()=>{this.removeEventListener("transitionend",o),this.removeEventListener("transitioncancel",i),t==null||t()},i=()=>{this.removeEventListener("transitionend",o),this.removeEventListener("transitioncancel",i)};this.addEventListener("transitionend",o),this.addEventListener("transitioncancel",i)}hide(){if(!this.showing)return;this.clearAllTimer(),requestAnimationFrame(()=>{this.transition="hide"});let t=()=>{this.removeEventListener("transitionend",t),this.removeEventListener("transitioncancel",o),this.remove()},o=()=>{this.removeEventListener("transitionend",t),this.removeEventListener("transitioncancel",o)};this.addEventListener("transitionend",t),this.addEventListener("transitioncancel",o)}remove(){this.parentElement&&this.parentElement.removeChild(this),this.transition=void 0,this.dispatchEvent(new Event("removed"))}clearAllTimer(){this._autoShowTimer&&(clearTimeout(this._autoShowTimer),this._autoShowTimer=void 0),this._autoHideTimer&&(clearTimeout(this._autoHideTimer),this._autoHideTimer=void 0)}getText(){return typeof this.text=="function"?this.text():this.text}createRenderRoot(){return this}};r([l({attribute:!1})],e.prototype,"text",2),r([v()],e.prototype,"transition",2),r([l({type:Object})],e.prototype,"floating",2),e=r([m("wk-popover")],e);var x=w` | ||
wk-popover { | ||
--text-color: white; | ||
--background-color: black; | ||
--font-size: 100%; | ||
--font-weight: normal; | ||
--padding: 10px; | ||
--border-radius: 5px; | ||
--box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5); | ||
--tooltip-text-color: white; | ||
--tooltip-background-color: black; | ||
--tooltip-font-size: 100%; | ||
--tooltip-font-weight: normal; | ||
--tooltip-padding: 10px; | ||
--tooltip-border-radius: 5px; | ||
--tooltip-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5); | ||
--notification-text-color: white; | ||
--notification-background-color: black; | ||
--notification-font-size: 120%; | ||
--notification-font-weight: 500; | ||
--notification-padding: 10px; | ||
--notification-border-radius: 0px; | ||
--notification-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5); | ||
} | ||
wk-popover .wk-popover { | ||
position: relative; | ||
color: var(--text-color); | ||
background-color: var(--background-color); | ||
font-size: var(--font-size); | ||
font-weight: var(--font-weight); | ||
padding: var(--padding); | ||
border-radius: var(--border-radius); | ||
opacity: 0; | ||
transition: 0.25s opacity; | ||
pointer-events: none; | ||
box-shadow: var(--box-shadow); | ||
} | ||
wk-popover .wk-tooltip { | ||
--text-color: var(--tooltip-text-color); | ||
--background-color: var(--tooltip-background-color); | ||
--font-size: var(--tooltip-font-size); | ||
--font-weight: var(--tooltip-font-weight); | ||
--padding: var(--tooltip-padding); | ||
--border-radius: var(--tooltip-border-radius); | ||
--box-shadow: var(--tooltip-box-shadow); | ||
} | ||
wk-popover .wk-notification { | ||
--text-color: var(--notification-text-color); | ||
--background-color: var(--notification-background-color); | ||
--font-size: var(--notification-font-size); | ||
--font-weight: var(--notification-font-weight); | ||
--padding: var(--notification-padding); | ||
--border-radius: var(--notification-border-radius); | ||
--box-shadow: var(--notification-box-shadow); | ||
} | ||
wk-popover .wk-popover.wk-show { | ||
opacity: 1; | ||
} | ||
wk-popover .wk-popover.wk-hide { | ||
opacity: 0; | ||
} | ||
wk-popover .wk-arrow, | ||
wk-popover .wk-arrow:empty { | ||
position: absolute; | ||
display: block; | ||
width: 0; | ||
height: 0; | ||
border-style: solid; | ||
border-width: 0 5px 5px 5px; | ||
border-color: transparent transparent var(--background-color) transparent; | ||
} | ||
`,h=document.createElement("style");h.textContent=x.cssText;document.head.appendChild(h);export{e as Popover}; | ||
`}firstUpdated(){this.autoShow!==!1&&(this._autoShowTimer=setTimeout(()=>this.show(),(this.autoShow===!0?0:this.autoShow)*1e3)),this.autoHide!==!1&&(this._autoHideTimer=setTimeout(()=>this.hide(),(this.autoHide===!0?2:this.autoHide)*1e3))}add(t=document.body){this.added||t.appendChild(this)}show(t){if(this.showing)return;this.clearAllTimer(),this.added||this.add(),requestAnimationFrame(()=>{this.transition="show"});let e=()=>{this.removeEventListener("transitionend",e),this.removeEventListener("transitioncancel",i),t==null||t()},i=()=>{this.removeEventListener("transitionend",e),this.removeEventListener("transitioncancel",i)};this.addEventListener("transitionend",e),this.addEventListener("transitioncancel",i)}hide(){if(!this.showing)return;this.clearAllTimer(),requestAnimationFrame(()=>{this.transition="hide"});let t=()=>{this.removeEventListener("transitionend",t),this.removeEventListener("transitioncancel",e),this.remove()},e=()=>{this.removeEventListener("transitionend",t),this.removeEventListener("transitioncancel",e)};this.addEventListener("transitionend",t),this.addEventListener("transitioncancel",e)}remove(){this.parentElement&&this.parentElement.removeChild(this),this.transition=void 0,this.dispatchEvent(new Event("removed"))}clearAllTimer(){this._autoShowTimer&&(clearTimeout(this._autoShowTimer),this._autoShowTimer=void 0),this._autoHideTimer&&(clearTimeout(this._autoHideTimer),this._autoHideTimer=void 0)}getText(){return typeof this.text=="function"?this.text():this.text}createRenderRoot(){return this}};n.properties={text:{attribute:!1},transition:{state:!0},floating:{type:Object}};customElements.get("wk-popover")||customElements.define("wk-popover",n);export{n as Popover}; |
@@ -1,3 +0,3 @@ | ||
var p=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var t=(r,o,a,s)=>{for(var l=s>1?void 0:s?c(o,a):o,n=r.length-1,d;n>=0;n--)(d=r[n])&&(l=(s?d(o,a,l):d(l))||l);return s&&l&&p(o,a,l),l};import{LitElement as g}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{customElement as b,property as i}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{html as m}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/+esm";import{styleMap as u}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/directives/style-map/+esm";var e=class extends g{constructor(){super();this.label="";this.name="";this.value="";this.selected=!1;this.disabled=!1;this.unavailable=!1}render(){let a=`wk-radio__${this.name}`,s=["wk-swatch",(this.disabled||this.unavailable)&&"wk-disabled",this.selected&&"wk-selected",this.color&&"wk-has-color",this.image&&"wk-has-image"].filter(l=>!!l).join(" ");return m` | ||
<div class=${s}> | ||
import{LitElement as i,html as l}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";var t=class extends i{constructor(){super();this.label="";this.name="";this.value="";this.selected=!1;this.disabled=!1;this.unavailable=!1}render(){let a=`wk-radio__${this.name}`,e=["wk-swatch",(this.disabled||this.unavailable)&&"wk-disabled",this.selected&&"wk-selected",this.color&&"wk-has-color",this.image&&"wk-has-image"].filter(s=>!!s).join(" ");return l` | ||
<div class=${e}> | ||
${this.renderLabel()} | ||
@@ -14,6 +14,6 @@ <input | ||
</div> | ||
`}renderLabel(){let a=`wk-radio__${this.name}`,s={backgroundColor:this.color?this.color:void 0,backgroundImage:this.image?`url(${this.image})`:void 0};return m` | ||
<label class="wk-label" style=${u(s)} for=${a} | ||
`}renderLabel(){let a=`wk-radio__${this.name}`,e={};return this.color&&(e.backgroundColor=this.color),this.image&&(e.backgroundImage=`url(${this.image})`),l` | ||
<label class="wk-label" .style=${e} for=${a} | ||
>${this.label}</label | ||
> | ||
`}createRenderRoot(){return this}};t([i({type:String})],e.prototype,"label",2),t([i({type:String})],e.prototype,"name",2),t([i({type:String})],e.prototype,"value",2),t([i({type:Boolean})],e.prototype,"selected",2),t([i({type:Boolean})],e.prototype,"disabled",2),t([i({type:Boolean})],e.prototype,"unavailable",2),t([i({type:String})],e.prototype,"image",2),t([i({type:String})],e.prototype,"color",2),e=t([b("wk-swatch")],e);export{e as Swatch}; | ||
`}createRenderRoot(){return this}};t.properties={label:{type:String},name:{type:String},value:{type:String},selected:{type:Boolean},disabled:{type:Boolean},unavailable:{type:Boolean},image:{type:String},color:{type:String}};customElements.get("wk-swatch")||customElements.define("wk-swatch",t);export{t as Swatch}; |
@@ -1,2 +0,2 @@ | ||
var p=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var o=(l,n,e,t)=>{for(var s=t>1?void 0:t?m(n,e):n,r=l.length-1,a;r>=0;r--)(a=l[r])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&p(n,e,s),s};import{LitElement as d}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{html as h}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/+esm";import{customElement as f,property as c}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{Swatch as b}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/components/swatch.js";var i=class extends d{constructor(){super();this.label="";this.name="";this.options=[]}connectedCallback(){super.connectedCallback();for(let e of this.children)e instanceof b&&this.options.push(e);this.innerHTML=""}render(){let e=["wk-swatches",this.options.length===1&&"wk-single-option"].filter(t=>!!t).join(" ");return h` | ||
import{LitElement as i,html as n}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";import{Swatch as a}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/components/swatch.js";var t=class extends i{constructor(){super();this.label="";this.name="";this.options=[]}connectedCallback(){super.connectedCallback();for(let e of this.children)e instanceof a&&this.options.push(e);this.innerHTML=""}render(){let e=["wk-swatches",this.options.length===1&&"wk-single-option"].filter(s=>!!s).join(" ");return n` | ||
<div class=${e}> | ||
@@ -6,6 +6,6 @@ <fieldset class="wk-fieldset"> | ||
<div class="wk-options"> | ||
${this.options.map(t=>Object.assign(t,{name:this.name}))} | ||
${this.options.map(s=>Object.assign(s,{name:this.name}))} | ||
</div> | ||
</fieldset> | ||
</div> | ||
`}createRenderRoot(){return this}};o([c({type:String})],i.prototype,"label",2),o([c({type:String})],i.prototype,"name",2),i=o([f("wk-swatches")],i);export{i as Swatches}; | ||
`}createRenderRoot(){return this}};t.properties={label:{type:String},name:{type:String}};customElements.get("wk-swatches")||customElements.define("wk-swatches",t);export{t as Swatches}; |
@@ -1,1 +0,1 @@ | ||
function V(e){return e.split("-")[0]}function B(e){return e.split("-")[1]}function D(e){return["top","bottom"].includes(V(e))?"x":"y"}function J(e){return e==="y"?"height":"width"}function lt(e,t,i){let{reference:n,floating:o}=e,a=n.x+n.width/2-o.width/2,s=n.y+n.height/2-o.height/2,r=D(t),c=J(r),f=n[c]/2-o[c]/2,u=r==="x",l;switch(V(t)){case"top":l={x:a,y:n.y-o.height};break;case"bottom":l={x:a,y:n.y+n.height};break;case"right":l={x:n.x+n.width,y:s};break;case"left":l={x:n.x-o.width,y:s};break;default:l={x:n.x,y:n.y}}switch(B(t)){case"start":l[r]-=f*(i&&u?-1:1);break;case"end":l[r]+=f*(i&&u?-1:1)}return l}var ct=async(e,t,i)=>{let{placement:n="bottom",strategy:o="absolute",middleware:a=[],platform:s}=i,r=a.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(t)),f=await s.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:l}=lt(f,n,c),d=n,h={},p=0;for(let m=0;m<r.length;m++){let{name:g,fn:y}=r[m],{x:v,y:x,data:I,reset:b}=await y({x:u,y:l,initialPlacement:n,placement:d,strategy:o,middlewareData:h,rects:f,platform:s,elements:{reference:e,floating:t}});u=v!=null?v:u,l=x!=null?x:l,h={...h,[g]:{...h[g],...I}},b&&p<=50&&(p++,typeof b=="object"&&(b.placement&&(d=b.placement),b.rects&&(f=b.rects===!0?await s.getElementRects({reference:e,floating:t,strategy:o}):b.rects),{x:u,y:l}=lt(f,d,c)),m=-1)}return{x:u,y:l,placement:d,strategy:o,middlewareData:h}};function ft(e){return typeof e!="number"?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(e):{top:e,right:e,bottom:e,left:e}}function _(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}async function Q(e,t){var i;t===void 0&&(t={});let{x:n,y:o,platform:a,rects:s,elements:r,strategy:c}=e,{boundary:f="clippingAncestors",rootBoundary:u="viewport",elementContext:l="floating",altBoundary:d=!1,padding:h=0}=t,p=ft(h),m=r[d?l==="floating"?"reference":"floating":l],g=_(await a.getClippingRect({element:(i=await(a.isElement==null?void 0:a.isElement(m)))==null||i?m:m.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(r.floating)),boundary:f,rootBoundary:u,strategy:c})),y=_(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({rect:l==="floating"?{...s.floating,x:n,y:o}:s.reference,offsetParent:await(a.getOffsetParent==null?void 0:a.getOffsetParent(r.floating)),strategy:c}):s[l]);return{top:g.top-y.top+p.top,bottom:y.bottom-g.bottom+p.bottom,left:g.left-y.left+p.left,right:y.right-g.right+p.right}}var Rt=Math.min,St=Math.max;function Y(e,t,i){return St(e,Rt(t,i))}var G=e=>({name:"arrow",options:e,async fn(t){let{element:i,padding:n=0}=e!=null?e:{},{x:o,y:a,placement:s,rects:r,platform:c}=t;if(i==null)return{};let f=ft(n),u={x:o,y:a},l=D(s),d=B(s),h=J(l),p=await c.getDimensions(i),m=l==="y"?"top":"left",g=l==="y"?"bottom":"right",y=r.reference[h]+r.reference[l]-u[l]-r.floating[h],v=u[l]-r.reference[l],x=await(c.getOffsetParent==null?void 0:c.getOffsetParent(i)),I=x?l==="y"?x.clientHeight||0:x.clientWidth||0:0;I===0&&(I=r.floating[h]);let b=y/2-v/2,L=f[m],F=I-p[h]-f[g],w=I/2-p[h]/2+b,E=Y(L,w,F),T=(d==="start"?f[m]:f[g])>0&&w!==E&&r.reference[h]<=r.floating[h];return{[l]:u[l]-(T?w<L?L-w:F-w:0),data:{[l]:E,centerOffset:w-E}}}}),Pt={left:"right",right:"left",bottom:"top",top:"bottom"};function M(e){return e.replace(/left|right|bottom|top/g,t=>Pt[t])}function Wt(e,t,i){i===void 0&&(i=!1);let n=B(e),o=D(e),a=J(o),s=o==="x"?n===(i?"end":"start")?"right":"left":n==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(s=M(s)),{main:s,cross:M(s)}}var At={start:"end",end:"start"};function at(e){return e.replace(/start|end/g,t=>At[t])}var Ot=["top","right","bottom","left"],zt=Ot.reduce((e,t)=>e.concat(t,t+"-start",t+"-end"),[]);var Z=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var i;let{placement:n,middlewareData:o,rects:a,initialPlacement:s,platform:r,elements:c}=t,{mainAxis:f=!0,crossAxis:u=!0,fallbackPlacements:l,fallbackStrategy:d="bestFit",flipAlignment:h=!0,...p}=e,m=V(n),g=l||(m===s||!h?[M(s)]:function(w){let E=M(w);return[at(w),E,at(E)]}(s)),y=[s,...g],v=await Q(t,p),x=[],I=((i=o.flip)==null?void 0:i.overflows)||[];if(f&&x.push(v[m]),u){let{main:w,cross:E}=Wt(n,a,await(r.isRTL==null?void 0:r.isRTL(c.floating)));x.push(v[w],v[E])}if(I=[...I,{placement:n,overflows:x}],!x.every(w=>w<=0)){var b,L;let w=((b=(L=o.flip)==null?void 0:L.index)!=null?b:0)+1,E=y[w];if(E)return{data:{index:w,overflows:I},reset:{placement:E}};let T="bottom";switch(d){case"bestFit":{var F;let st=(F=I.map(q=>[q,q.overflows.filter(H=>H>0).reduce((H,Ct)=>H+Ct,0)]).sort((q,H)=>q[1]-H[1])[0])==null?void 0:F[0].placement;st&&(T=st);break}case"initialPlacement":T=s}if(n!==T)return{reset:{placement:T}}}return{}}}};var U=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){let{x:i,y:n}=t,o=await async function(a,s){let{placement:r,platform:c,elements:f}=a,u=await(c.isRTL==null?void 0:c.isRTL(f.floating)),l=V(r),d=B(r),h=D(r)==="x",p=["left","top"].includes(l)?-1:1,m=u&&h?-1:1,g=typeof s=="function"?s(a):s,{mainAxis:y,crossAxis:v,alignmentAxis:x}=typeof g=="number"?{mainAxis:g,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...g};return d&&typeof x=="number"&&(v=d==="end"?-1*x:x),h?{x:v*m,y:y*p}:{x:y*p,y:v*m}}(t,e);return{x:i+o.x,y:n+o.y,data:o}}}};function Lt(e){return e==="x"?"y":"x"}var tt=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){let{x:i,y:n,placement:o}=t,{mainAxis:a=!0,crossAxis:s=!1,limiter:r={fn:g=>{let{x:y,y:v}=g;return{x:y,y:v}}},...c}=e,f={x:i,y:n},u=await Q(t,c),l=D(V(o)),d=Lt(l),h=f[l],p=f[d];if(a){let g=l==="y"?"bottom":"right";h=Y(h+u[l==="y"?"top":"left"],h,h-u[g])}if(s){let g=d==="y"?"bottom":"right";p=Y(p+u[d==="y"?"top":"left"],p,p-u[g])}let m=r.fn({...t,[l]:h,[d]:p});return{...m,data:{x:m.x-i,y:m.y-n}}}}};function wt(e){return e&&e.document&&e.location&&e.alert&&e.setInterval}function P(e){if(e==null)return window;if(!wt(e)){let t=e.ownerDocument;return t&&t.defaultView||window}return e}function A(e){return P(e).getComputedStyle(e)}function O(e){return wt(e)?"":e?(e.nodeName||"").toLowerCase():""}function yt(){let e=navigator.userAgentData;return e!=null&&e.brands?e.brands.map(t=>t.brand+"/"+t.version).join(" "):navigator.userAgent}function S(e){return e instanceof P(e).HTMLElement}function C(e){return e instanceof P(e).Element}function ht(e){return typeof ShadowRoot=="undefined"?!1:e instanceof P(e).ShadowRoot||e instanceof ShadowRoot}function $(e){let{overflow:t,overflowX:i,overflowY:n,display:o}=A(e);return/auto|scroll|overlay|hidden/.test(t+n+i)&&!["inline","contents"].includes(o)}function Tt(e){return["table","td","th"].includes(O(e))}function et(e){let t=/firefox/i.test(yt()),i=A(e),n=i.backdropFilter||i.WebkitBackdropFilter;return i.transform!=="none"||i.perspective!=="none"||!!n&&n!=="none"||t&&i.willChange==="filter"||t&&!!i.filter&&i.filter!=="none"||["transform","perspective"].some(o=>i.willChange.includes(o))||["paint","layout","strict","content"].some(o=>{let a=i.contain;return a!=null&&a.includes(o)})}function xt(){return!/^((?!chrome|android).)*safari/i.test(yt())}function it(e){return["html","body","#document"].includes(O(e))}var ut=Math.min,z=Math.max,j=Math.round;function R(e,t,i){var n,o,a,s;t===void 0&&(t=!1),i===void 0&&(i=!1);let r=e.getBoundingClientRect(),c=1,f=1;t&&S(e)&&(c=e.offsetWidth>0&&j(r.width)/e.offsetWidth||1,f=e.offsetHeight>0&&j(r.height)/e.offsetHeight||1);let u=C(e)?P(e):window,l=!xt()&&i,d=(r.left+(l&&(n=(o=u.visualViewport)==null?void 0:o.offsetLeft)!=null?n:0))/c,h=(r.top+(l&&(a=(s=u.visualViewport)==null?void 0:s.offsetTop)!=null?a:0))/f,p=r.width/c,m=r.height/f;return{width:p,height:m,top:h,right:d+p,bottom:h+m,left:d,x:d,y:h}}function W(e){return(t=e,(t instanceof P(t).Node?e.ownerDocument:e.document)||window.document).documentElement;var t}function K(e){return C(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function vt(e){return R(W(e)).left+K(e).scrollLeft}function Ft(e,t,i){let n=S(t),o=W(t),a=R(e,n&&function(c){let f=R(c);return j(f.width)!==c.offsetWidth||j(f.height)!==c.offsetHeight}(t),i==="fixed"),s={scrollLeft:0,scrollTop:0},r={x:0,y:0};if(n||!n&&i!=="fixed")if((O(t)!=="body"||$(o))&&(s=K(t)),S(t)){let c=R(t,!0);r.x=c.x+t.clientLeft,r.y=c.y+t.clientTop}else o&&(r.x=vt(o));return{x:a.left+s.scrollLeft-r.x,y:a.top+s.scrollTop-r.y,width:a.width,height:a.height}}function N(e){if(O(e)==="html")return e;let t=e.assignedSlot||e.parentNode||(ht(e)?e.host:null)||W(e);return ht(t)?t.host:t}function dt(e){return S(e)&&A(e).position!=="fixed"?e.offsetParent:null}function pt(e){let t=P(e),i=dt(e);for(;i&&Tt(i)&&A(i).position==="static";)i=dt(i);return i&&(O(i)==="html"||O(i)==="body"&&A(i).position==="static"&&!et(i))?t:i||function(n){let o=N(n);for(;S(o)&&!it(o);){if(et(o))return o;o=N(o)}return null}(e)||t}function mt(e){if(S(e))return{width:e.offsetWidth,height:e.offsetHeight};let t=R(e);return{width:t.width,height:t.height}}function bt(e){let t=N(e);return it(t)?e.ownerDocument.body:S(t)&&$(t)?t:bt(t)}function k(e,t){var i;t===void 0&&(t=[]);let n=bt(e),o=n===((i=e.ownerDocument)==null?void 0:i.body),a=P(n),s=o?[a].concat(a.visualViewport||[],$(n)?n:[]):n,r=t.concat(s);return o?r:r.concat(k(s))}function gt(e,t,i){return t==="viewport"?_(function(n,o){let a=P(n),s=W(n),r=a.visualViewport,c=s.clientWidth,f=s.clientHeight,u=0,l=0;if(r){c=r.width,f=r.height;let d=xt();(d||!d&&o==="fixed")&&(u=r.offsetLeft,l=r.offsetTop)}return{width:c,height:f,x:u,y:l}}(e,i)):C(t)?function(n,o){let a=R(n,!1,o==="fixed"),s=a.top+n.clientTop,r=a.left+n.clientLeft;return{top:s,left:r,x:r,y:s,right:r+n.clientWidth,bottom:s+n.clientHeight,width:n.clientWidth,height:n.clientHeight}}(t,i):_(function(n){var o;let a=W(n),s=K(n),r=(o=n.ownerDocument)==null?void 0:o.body,c=z(a.scrollWidth,a.clientWidth,r?r.scrollWidth:0,r?r.clientWidth:0),f=z(a.scrollHeight,a.clientHeight,r?r.scrollHeight:0,r?r.clientHeight:0),u=-s.scrollLeft+vt(n),l=-s.scrollTop;return A(r||a).direction==="rtl"&&(u+=z(a.clientWidth,r?r.clientWidth:0)-c),{width:c,height:f,x:u,y:l}}(W(e)))}var Ht={getClippingRect:function(e){let{element:t,boundary:i,rootBoundary:n,strategy:o}=e,a=i==="clippingAncestors"?function(f){let u=k(f).filter(h=>C(h)&&O(h)!=="body"),l=f,d=null;for(;C(l)&&!it(l);){let h=A(l);h.position==="static"&&d&&["absolute","fixed"].includes(d.position)&&!et(l)?u=u.filter(p=>p!==l):d=h,l=N(l)}return u}(t):[].concat(i),s=[...a,n],r=s[0],c=s.reduce((f,u)=>{let l=gt(t,u,o);return f.top=z(l.top,f.top),f.right=ut(l.right,f.right),f.bottom=ut(l.bottom,f.bottom),f.left=z(l.left,f.left),f},gt(t,r,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{rect:t,offsetParent:i,strategy:n}=e,o=S(i),a=W(i);if(i===a)return t;let s={scrollLeft:0,scrollTop:0},r={x:0,y:0};if((o||!o&&n!=="fixed")&&((O(i)!=="body"||$(a))&&(s=K(i)),S(i))){let c=R(i,!0);r.x=c.x+i.clientLeft,r.y=c.y+i.clientTop}return{...t,x:t.x-s.scrollLeft+r.x,y:t.y-s.scrollTop+r.y}},isElement:C,getDimensions:mt,getOffsetParent:pt,getDocumentElement:W,getElementRects:e=>{let{reference:t,floating:i,strategy:n}=e;return{reference:Ft(t,pt(i),n),floating:{...mt(i),x:0,y:0}}},getClientRects:e=>Array.from(e.getClientRects()),isRTL:e=>A(e).direction==="rtl"};function It(e,t,i,n){n===void 0&&(n={});let{ancestorScroll:o=!0,ancestorResize:a=!0,elementResize:s=!0,animationFrame:r=!1}=n,c=o&&!r,f=c||a?[...C(e)?k(e):e.contextElement?k(e.contextElement):[],...k(t)]:[];f.forEach(h=>{c&&h.addEventListener("scroll",i,{passive:!0}),a&&h.addEventListener("resize",i)});let u,l=null;if(s){let h=!0;l=new ResizeObserver(()=>{h||i(),h=!1}),C(e)&&!r&&l.observe(e),C(e)||!e.contextElement||r||l.observe(e.contextElement),l.observe(t)}let d=r?R(e):null;return r&&function h(){let p=R(e);!d||p.x===d.x&&p.y===d.y&&p.width===d.width&&p.height===d.height||i(),d=p,u=requestAnimationFrame(h)}(),i(),()=>{var h;f.forEach(p=>{c&&p.removeEventListener("scroll",i),a&&p.removeEventListener("resize",i)}),(h=l)==null||h.disconnect(),l=null,r&&cancelAnimationFrame(u)}}var Et=(e,t,i)=>ct(e,t,{platform:Ht,...i});var nt=class{constructor(t){this._middleware=[];this._floating=!1;(this.host=t).addController(this)}hostConnected(){this.host.floating&&this.float(this.host.floating)}hostDisconnected(){this.destroy()}hostUpdated(){this._floating&&this.updatePosition()}hostResized(){this._floating&&this.updatePosition()}float(t){var r;if(this._floating)return;if(this._floating=!0,this._settings=t,this._reference=this.getReference(),this._resizeObserver=new ResizeObserver(()=>this.hostResized()),!this._settings)throw new Error("Floating settings are required");if(!this._reference)throw new Error("Floating reference is required");this.host.classList.add("wk-floating");let{position:i,arrow:n=!1,flip:o=!1,shift:a=!1}=this._settings,s=this.getOffsetSetting();Object.assign(this.host.style,{position:(r=i.strategy)!=null?r:"absolute",top:"0",left:"0",transition:"none",transform:"translate3d(0,0,0)"}),i.inset&&!n?this._middleware.push(U(({rects:c,placement:f})=>{var u,l,d,h,p,m;return f.includes("top")||f.includes("bottom")?{mainAxis:-c.floating.height-((u=s==null?void 0:s.mainAxis)!=null?u:0),crossAxis:(l=s==null?void 0:s.crossAxis)!=null?l:0,alignmentAxis:(d=s==null?void 0:s.alignmentAxis)!=null?d:0}:{mainAxis:-c.floating.width-((h=s==null?void 0:s.mainAxis)!=null?h:0),crossAxis:(p=s==null?void 0:s.crossAxis)!=null?p:0,alignmentAxis:(m=s==null?void 0:s.alignmentAxis)!=null?m:0}})):s&&this._middleware.push(U(s)),o&&this._middleware.push(Z()),a&&this._middleware.push(tt()),n&&(this.arrowEl=document.createElement("div"),this.arrowEl.classList.add("wk-arrow"),this._middleware.push(G({element:this.arrowEl}))),this.cleanupAutoUpdate=It(this._reference,this.host,()=>{this.updatePosition()}),this._resizeObserver.observe(this.host)}getOffsetSetting(){var i,n;let t=(i=this._settings)==null?void 0:i.offset;if(!(!t||typeof t=="boolean"))return typeof t=="number"?{mainAxis:t,alignmentAxis:(n=this._settings)!=null&&n.position.inset?t:null}:t}destroy(){var t,i,n,o;this._floating&&(Object.assign(this.host.style,{position:"",top:"",left:"",transition:"",transform:""}),(i=(t=this.arrowEl)==null?void 0:t.parentElement)==null||i.removeChild(this.arrowEl),this.arrowEl=void 0,this._middleware=[],this.host.classList.remove("wk-floating"),(n=this.cleanupAutoUpdate)==null||n.call(this),(o=this._resizeObserver)==null||o.disconnect(),this._floating=!1)}updatePosition(){var n;if(!this._reference||!this._settings)return;let{strategy:t="absolute",placement:i="top"}=(n=this._settings.position)!=null?n:{};Et(this._reference,this.host,{middleware:this._middleware,strategy:t,placement:i}).then(({x:o,y:a,placement:s,middlewareData:r})=>{if(r.arrow&&this.arrowEl){let{x:c,y:f}=r.arrow,u={top:"bottom",right:"left",bottom:"top",left:"right"}[s.split("-")[0]],l={bottom:"0deg",left:"90deg",top:"180deg",right:"270deg"}[s.split("-")[0]];Object.assign(this.arrowEl.style,{left:c!=null?`${c}px`:"",top:f!=null?`${f}px`:"",right:"",bottom:"",[u]:"-5px",transform:`rotate(${l})`})}Object.assign(this.host.style,{transform:`translate3d(${Math.round(o)}px,${Math.round(a)}px,0)`})})}getReference(){if(!this._settings)return;let t=this._settings.reference;if(typeof t=="string"){if(t==="viewport")return this.createViewportReference();let i=document.querySelector(t);if(!i)throw new Error(`Floating reference element (${t}) not found`);return i}return t.hasOwnProperty("element")?t.element:t}createViewportReference(){return{getBoundingClientRect(){var t,i,n,o;return{x:0,y:0,top:0,left:0,bottom:0,right:0,width:(i=(t=window.visualViewport)==null?void 0:t.width)!=null?i:0,height:(o=(n=window.visualViewport)==null?void 0:n.height)!=null?o:0}}}}};var ot=class{constructor(t){this.product=null;this.selectedVariant=null;this.selectedOptions={};this.hasSelection=!1;this.optionsWithValues=[];this.hasOnlyDefaultVariant=!1;(this.host=t).addController(this)}set submitting(t){var i;(i=this.host.querySelector("form"))==null||i.classList.toggle("wk-submitting",t)}get submitting(){var t,i;return(i=(t=this.host.querySelector("form"))==null?void 0:t.classList.contains("wk-submitting"))!=null?i:!1}setProduct({product:t,selectedVariantId:i,autoSelect:n=!1}){!(t!=null&&t.variants)||(this.product=t,this.initFormState({selectedVariantId:i,autoSelect:n}))}initFormState({selectedVariantId:t,autoSelect:i}){if(!this.product)throw new Error("Product not set");let n=this.initializedVariantId!==t?this.product.variants.find(a=>a.id===t):this.selectedVariant;this.initializedVariantId=t;let o=this.host.app.utils.product.getVariantOptions({variant:n});this.updateFormState({options:o,autoSelect:i})}updateFormState({options:t,change:i,autoSelect:n=!1}){if(!this.product)throw new Error("Product not set");let{hasSelection:o,optionsWithValues:a,selectedOptions:s,selectedVariant:r}=this.host.app.utils.product.getFormState({product:this.product,options:t,change:i,autoSelect:n});this.hasSelection=o,this.optionsWithValues=a,this.selectedOptions=s,this.selectedVariant=r,this.host.requestUpdate()}changeOption({input:t,autoSelect:i=!1}){if(!this.product)throw new Error("Product not set");let n=this.getInputOption(t);if(!n)throw new Error("Cannot parse options from input");this.updateFormState({options:this.selectedOptions,change:n,autoSelect:i})}addToCart({wishlistId:t,wishlistItemId:i}){if(!this.selectedVariant)throw new Error("No variant selected");let n=this.host.querySelector("form");if(!n)throw new Error("Form not found");return this.submitting=!0,this.host.app.addToCart({wishlistId:t,wishlistItemId:i,variantId:this.selectedVariant.id,quantity:this.host.app.utils.product.getFormQuantity({form:n})}).finally(()=>{this.submitting=!1})}getInputOption(t){if(!this.product)throw new Error("Product not set");return this.host.app.utils.product.getInputOption({input:t,product:this.product})}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}};import{combineLatest as _t,distinctUntilChanged as Vt,map as X,of as Dt}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";var rt=class{constructor(t){this.stateConfig={loading:"eager"};(this.host=t).addController(this)}get app(){if(!window.WishlistKing)throw new Error("Wishlist King SDK not initialized");return window.WishlistKing}get hostDataset(){return this.host.dataset?this.host.dataset:this.host.host?this.host.host.dataset:{}}hostConnected(){}hostDisconnected(){}parseStateConfig(t){var i;return{loading:(i=t.loading)!=null?i:"eager",wishlist:this.parseWishlistStateConfig(t),wishlistItem:this.parseWishlistItemStateConfig(t),productInfo:this.parseProductInfoStateConfig(t)}}parseWishlistStateConfig({wishlist:t}){var n;let i=(n=this.hostDataset.wishlistId)!=null?n:"mine";if(!!t)return{params:{wishlistId:i}}}parseWishlistItemStateConfig({wishlistItem:t}){let{wishlistId:i="mine",wishlistItemId:n}=this.hostDataset;if(!(!t||!n))return{params:{wishlistId:i,wishlistItemId:n}}}parseProductInfoStateConfig({productInfo:t}){if(!t)return;let{wishlistId:i="mine",productHandle:n="",productId:o,variantId:a}=this.hostDataset;return{params:{wishlistId:i,productHandle:n,variantId:a?parseInt(a):void 0}}}observe(){this.stateConfig=this.parseStateConfig(this.host.getStateConfig());let t=[];if(this.stateConfig.wishlist){let{wishlistId:i="mine"}=this.stateConfig.wishlist.params;t.push(this.app.state.observeWishlist({wishlistId:i}).pipe(X(n=>({wishlist:n}))))}if(this.stateConfig.productInfo){let{productHandle:i,variantId:n}=this.stateConfig.productInfo.params;if(!i)throw new Error("Product handle is required");t.push(this.app.state.observeProductInfo({productHandle:i,variantId:n}).pipe(X(o=>({productInfo:o}))))}if(this.stateConfig.wishlistItem){let{wishlistId:i,wishlistItemId:n}=this.stateConfig.wishlistItem.params;if(!i)throw new Error("Wishlist id is required");if(!n)throw new Error("Wishlist item id is required");t.push(this.app.state.observeWishlistItem({wishlistId:i,wishlistItemId:n}).pipe(X(o=>({wishlistItem:o}))))}return t.length||t.push(Dt({})),_t(t).pipe(X(i=>i.reduce((n,o)=>o.wishlist?{...n,wishlist:o.wishlist}:o.wishlistItem?{...n,wishlistItem:o.wishlistItem}:o.productInfo?{...n,productInfo:o.productInfo}:n,{})),Vt((i,n)=>JSON.stringify(i)===JSON.stringify(n)))}getFallback(){this.stateConfig=this.parseStateConfig(this.host.getStateConfig());let t={};if(this.stateConfig.wishlist){let{wishlistId:i="mine"}=this.stateConfig.wishlist.params;t.wishlist={id:i,isMine:i==="mine",numItems:0,items:[]}}if(this.stateConfig.productInfo){let{variantId:i=0,productHandle:n}=this.stateConfig.productInfo.params;t.productInfo={productId:0,variantId:i,productHandle:n,inWishlist:!1}}if(this.stateConfig.wishlistItem){let{wishlistId:i,wishlistItemId:n}=this.stateConfig.wishlistItem.params;if(!i)throw new Error("Wishlist id is required");if(!n)throw new Error("Wishlist item id is required");t.wishlistItem={id:n,product:{id:0,handle:"",hidden:!1}}}return t}};export{nt as FloatingUiController,ot as ProductFormController,rt as WishlistStateController}; | ||
function q(e){return e.split("-")[1]}function ot(e){return e==="y"?"height":"width"}function _(e){return e.split("-")[0]}function B(e){return["top","bottom"].includes(_(e))?"x":"y"}function gt(e,t,i){let{reference:n,floating:o}=e,a=n.x+n.width/2-o.width/2,r=n.y+n.height/2-o.height/2,s=B(t),c=ot(s),f=n[c]/2-o[c]/2,u=s==="x",l;switch(_(t)){case"top":l={x:a,y:n.y-o.height};break;case"bottom":l={x:a,y:n.y+n.height};break;case"right":l={x:n.x+n.width,y:r};break;case"left":l={x:n.x-o.width,y:r};break;default:l={x:n.x,y:n.y}}switch(q(t)){case"start":l[s]-=f*(i&&u?-1:1);break;case"end":l[s]+=f*(i&&u?-1:1)}return l}var wt=async(e,t,i)=>{let{placement:n="bottom",strategy:o="absolute",middleware:a=[],platform:r}=i,s=a.filter(Boolean),c=await(r.isRTL==null?void 0:r.isRTL(t)),f=await r.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:l}=gt(f,n,c),h=n,d={},p=0;for(let m=0;m<s.length;m++){let{name:g,fn:y}=s[m],{x:w,y:x,data:b,reset:v}=await y({x:u,y:l,initialPlacement:n,placement:h,strategy:o,middlewareData:d,rects:f,platform:r,elements:{reference:e,floating:t}});u=w!=null?w:u,l=x!=null?x:l,d={...d,[g]:{...d[g],...b}},v&&p<=50&&(p++,typeof v=="object"&&(v.placement&&(h=v.placement),v.rects&&(f=v.rects===!0?await r.getElementRects({reference:e,floating:t,strategy:o}):v.rects),{x:u,y:l}=gt(f,h,c)),m=-1)}return{x:u,y:l,placement:h,strategy:o,middlewareData:d}};function yt(e){return typeof e!="number"?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(e):{top:e,right:e,bottom:e,left:e}}function M(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}async function rt(e,t){var i;t===void 0&&(t={});let{x:n,y:o,platform:a,rects:r,elements:s,strategy:c}=e,{boundary:f="clippingAncestors",rootBoundary:u="viewport",elementContext:l="floating",altBoundary:h=!1,padding:d=0}=t,p=yt(d),m=s[h?l==="floating"?"reference":"floating":l],g=M(await a.getClippingRect({element:(i=await(a.isElement==null?void 0:a.isElement(m)))==null||i?m:m.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(s.floating)),boundary:f,rootBoundary:u,strategy:c})),y=l==="floating"?{...r.floating,x:n,y:o}:r.reference,w=await(a.getOffsetParent==null?void 0:a.getOffsetParent(s.floating)),x=await(a.isElement==null?void 0:a.isElement(w))&&await(a.getScale==null?void 0:a.getScale(w))||{x:1,y:1},b=M(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({rect:y,offsetParent:w,strategy:c}):y);return{top:(g.top-b.top+p.top)/x.y,bottom:(b.bottom-g.bottom+p.bottom)/x.y,left:(g.left-b.left+p.left)/x.x,right:(b.right-g.right+p.right)/x.x}}var Dt=Math.min,kt=Math.max;function nt(e,t,i){return kt(e,Dt(t,i))}var st=e=>({name:"arrow",options:e,async fn(t){let{element:i,padding:n=0}=e||{},{x:o,y:a,placement:r,rects:s,platform:c}=t;if(i==null)return{};let f=yt(n),u={x:o,y:a},l=B(r),h=ot(l),d=await c.getDimensions(i),p=l==="y"?"top":"left",m=l==="y"?"bottom":"right",g=s.reference[h]+s.reference[l]-u[l]-s.floating[h],y=u[l]-s.reference[l],w=await(c.getOffsetParent==null?void 0:c.getOffsetParent(i)),x=w?l==="y"?w.clientHeight||0:w.clientWidth||0:0;x===0&&(x=s.floating[h]);let b=g/2-y/2,v=f[p],L=x-d[h]-f[m],E=x/2-d[h]/2+b,V=nt(v,E,L),$=q(r)!=null&&E!=V&&s.reference[h]/2-(E<v?f[p]:f[m])-d[h]/2<0;return{[l]:u[l]-($?E<v?v-E:L-E:0),data:{[l]:V,centerOffset:E-V}}}}),zt=["top","right","bottom","left"],Jt=zt.reduce((e,t)=>e.concat(t,t+"-start",t+"-end"),[]),Mt={left:"right",right:"left",bottom:"top",top:"bottom"};function X(e){return e.replace(/left|right|bottom|top/g,t=>Mt[t])}function qt(e,t,i){i===void 0&&(i=!1);let n=q(e),o=B(e),a=ot(o),r=o==="x"?n===(i?"end":"start")?"right":"left":n==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(r=X(r)),{main:r,cross:X(r)}}var Bt={start:"end",end:"start"};function it(e){return e.replace(/start|end/g,t=>Bt[t])}var at=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var i;let{placement:n,middlewareData:o,rects:a,initialPlacement:r,platform:s,elements:c}=t,{mainAxis:f=!0,crossAxis:u=!0,fallbackPlacements:l,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:d="none",flipAlignment:p=!0,...m}=e,g=_(n),y=_(r)===r,w=await(s.isRTL==null?void 0:s.isRTL(c.floating)),x=l||(y||!p?[X(r)]:function(I){let A=X(I);return[it(I),A,it(A)]}(r));l||d==="none"||x.push(...function(I,A,D,K){let T=q(I),R=function(z,et,_t){let pt=["left","right"],mt=["right","left"],Ht=["top","bottom"],Vt=["bottom","top"];switch(z){case"top":case"bottom":return _t?et?mt:pt:et?pt:mt;case"left":case"right":return et?Ht:Vt;default:return[]}}(_(I),D==="start",K);return T&&(R=R.map(z=>z+"-"+T),A&&(R=R.concat(R.map(it)))),R}(r,p,d,w));let b=[r,...x],v=await rt(t,m),L=[],E=((i=o.flip)==null?void 0:i.overflows)||[];if(f&&L.push(v[g]),u){let{main:I,cross:A}=qt(n,a,w);L.push(v[I],v[A])}if(E=[...E,{placement:n,overflows:L}],!L.every(I=>I<=0)){var V;let I=(((V=o.flip)==null?void 0:V.index)||0)+1,A=b[I];if(A)return{data:{index:I,overflows:E},reset:{placement:A}};let D="bottom";switch(h){case"bestFit":{var $;let K=($=E.map(T=>[T,T.overflows.filter(R=>R>0).reduce((R,z)=>R+z,0)]).sort((T,R)=>T[1]-R[1])[0])==null?void 0:$[0].placement;K&&(D=K);break}case"initialPlacement":D=r}if(n!==D)return{reset:{placement:D}}}return{}}}};var Y=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){let{x:i,y:n}=t,o=await async function(a,r){let{placement:s,platform:c,elements:f}=a,u=await(c.isRTL==null?void 0:c.isRTL(f.floating)),l=_(s),h=q(s),d=B(s)==="x",p=["left","top"].includes(l)?-1:1,m=u&&d?-1:1,g=typeof r=="function"?r(a):r,{mainAxis:y,crossAxis:w,alignmentAxis:x}=typeof g=="number"?{mainAxis:g,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...g};return h&&typeof x=="number"&&(w=h==="end"?-1*x:x),d?{x:w*m,y:y*p}:{x:y*p,y:w*m}}(t,e);return{x:i+o.x,y:n+o.y,data:o}}}};function Ut(e){return e==="x"?"y":"x"}var lt=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){let{x:i,y:n,placement:o}=t,{mainAxis:a=!0,crossAxis:r=!1,limiter:s={fn:g=>{let{x:y,y:w}=g;return{x:y,y:w}}},...c}=e,f={x:i,y:n},u=await rt(t,c),l=B(_(o)),h=Ut(l),d=f[l],p=f[h];if(a){let g=l==="y"?"bottom":"right";d=nt(d+u[l==="y"?"top":"left"],d,d-u[g])}if(r){let g=h==="y"?"bottom":"right";p=nt(p+u[h==="y"?"top":"left"],p,p-u[g])}let m=s.fn({...t,[l]:d,[h]:p});return{...m,data:{x:m.x-i,y:m.y-n}}}}};function S(e){var t;return((t=e.ownerDocument)==null?void 0:t.defaultView)||window}function P(e){return S(e).getComputedStyle(e)}function F(e){return St(e)?(e.nodeName||"").toLowerCase():""}var J;function Rt(){if(J)return J;let e=navigator.userAgentData;return e&&Array.isArray(e.brands)?(J=e.brands.map(t=>t.brand+"/"+t.version).join(" "),J):navigator.userAgent}function O(e){return e instanceof S(e).HTMLElement}function C(e){return e instanceof S(e).Element}function St(e){return e instanceof S(e).Node}function xt(e){return typeof ShadowRoot=="undefined"?!1:e instanceof S(e).ShadowRoot||e instanceof ShadowRoot}function G(e){let{overflow:t,overflowX:i,overflowY:n,display:o}=P(e);return/auto|scroll|overlay|hidden|clip/.test(t+n+i)&&!["inline","contents"].includes(o)}function jt(e){return["table","td","th"].includes(F(e))}function ct(e){let t=/firefox/i.test(Rt()),i=P(e),n=i.backdropFilter||i.WebkitBackdropFilter;return i.transform!=="none"||i.perspective!=="none"||!!n&&n!=="none"||t&&i.willChange==="filter"||t&&!!i.filter&&i.filter!=="none"||["transform","perspective"].some(o=>i.willChange.includes(o))||["paint","layout","strict","content"].some(o=>{let a=i.contain;return a!=null&&a.includes(o)})}function Ct(){return!/^((?!chrome|android).)*safari/i.test(Rt())}function ft(e){return["html","body","#document"].includes(F(e))}var vt=Math.min,U=Math.max,Q=Math.round;function Pt(e){let t=P(e),i=parseFloat(t.width),n=parseFloat(t.height),o=e.offsetWidth,a=e.offsetHeight,r=Q(i)!==o||Q(n)!==a;return r&&(i=o,n=a),{width:i,height:n,fallback:r}}function At(e){return C(e)?e:e.contextElement}var Ot={x:1,y:1};function k(e){let t=At(e);if(!O(t))return Ot;let i=t.getBoundingClientRect(),{width:n,height:o,fallback:a}=Pt(t),r=(a?Q(i.width):i.width)/n,s=(a?Q(i.height):i.height)/o;return r&&Number.isFinite(r)||(r=1),s&&Number.isFinite(s)||(s=1),{x:r,y:s}}function H(e,t,i,n){var o,a;t===void 0&&(t=!1),i===void 0&&(i=!1);let r=e.getBoundingClientRect(),s=At(e),c=Ot;t&&(n?C(n)&&(c=k(n)):c=k(e));let f=s?S(s):window,u=!Ct()&&i,l=(r.left+(u&&((o=f.visualViewport)==null?void 0:o.offsetLeft)||0))/c.x,h=(r.top+(u&&((a=f.visualViewport)==null?void 0:a.offsetTop)||0))/c.y,d=r.width/c.x,p=r.height/c.y;if(s){let m=S(s),g=n&&C(n)?S(n):n,y=m.frameElement;for(;y&&n&&g!==m;){let w=k(y),x=y.getBoundingClientRect(),b=getComputedStyle(y);x.x+=(y.clientLeft+parseFloat(b.paddingLeft))*w.x,x.y+=(y.clientTop+parseFloat(b.paddingTop))*w.y,l*=w.x,h*=w.y,d*=w.x,p*=w.y,l+=x.x,h+=x.y,y=S(y).frameElement}}return{width:d,height:p,top:h,right:l+d,bottom:h+p,left:l,x:l,y:h}}function W(e){return((St(e)?e.ownerDocument:e.document)||window.document).documentElement}function Z(e){return C(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Wt(e){return H(W(e)).left+Z(e).scrollLeft}function Nt(e,t,i){let n=O(t),o=W(t),a=H(e,!0,i==="fixed",t),r={scrollLeft:0,scrollTop:0},s={x:0,y:0};if(n||!n&&i!=="fixed")if((F(t)!=="body"||G(o))&&(r=Z(t)),O(t)){let c=H(t,!0);s.x=c.x+t.clientLeft,s.y=c.y+t.clientTop}else o&&(s.x=Wt(o));return{x:a.left+r.scrollLeft-s.x,y:a.top+r.scrollTop-s.y,width:a.width,height:a.height}}function N(e){if(F(e)==="html")return e;let t=e.assignedSlot||e.parentNode||(xt(e)?e.host:null)||W(e);return xt(t)?t.host:t}function bt(e){return O(e)&&P(e).position!=="fixed"?e.offsetParent:null}function Et(e){let t=S(e),i=bt(e);for(;i&&jt(i)&&P(i).position==="static";)i=bt(i);return i&&(F(i)==="html"||F(i)==="body"&&P(i).position==="static"&&!ct(i))?t:i||function(n){let o=N(n);for(;O(o)&&!ft(o);){if(ct(o))return o;o=N(o)}return null}(e)||t}function Ft(e){let t=N(e);return ft(t)?e.ownerDocument.body:O(t)&&G(t)?t:Ft(t)}function j(e,t){var i;t===void 0&&(t=[]);let n=Ft(e),o=n===((i=e.ownerDocument)==null?void 0:i.body),a=S(n);return o?t.concat(a,a.visualViewport||[],G(n)?n:[]):t.concat(n,j(n))}function It(e,t,i){return t==="viewport"?M(function(n,o){let a=S(n),r=W(n),s=a.visualViewport,c=r.clientWidth,f=r.clientHeight,u=0,l=0;if(s){c=s.width,f=s.height;let h=Ct();(h||!h&&o==="fixed")&&(u=s.offsetLeft,l=s.offsetTop)}return{width:c,height:f,x:u,y:l}}(e,i)):C(t)?function(n,o){let a=H(n,!0,o==="fixed"),r=a.top+n.clientTop,s=a.left+n.clientLeft,c=O(n)?k(n):{x:1,y:1},f=n.clientWidth*c.x,u=n.clientHeight*c.y,l=s*c.x,h=r*c.y;return{top:h,left:l,right:l+f,bottom:h+u,x:l,y:h,width:f,height:u}}(t,i):M(function(n){var o;let a=W(n),r=Z(n),s=(o=n.ownerDocument)==null?void 0:o.body,c=U(a.scrollWidth,a.clientWidth,s?s.scrollWidth:0,s?s.clientWidth:0),f=U(a.scrollHeight,a.clientHeight,s?s.scrollHeight:0,s?s.clientHeight:0),u=-r.scrollLeft+Wt(n),l=-r.scrollTop;return P(s||a).direction==="rtl"&&(u+=U(a.clientWidth,s?s.clientWidth:0)-c),{width:c,height:f,x:u,y:l}}(W(e)))}var $t={getClippingRect:function(e){let{element:t,boundary:i,rootBoundary:n,strategy:o}=e,a=i==="clippingAncestors"?function(f,u){let l=u.get(f);if(l)return l;let h=j(f).filter(g=>C(g)&&F(g)!=="body"),d=null,p=P(f).position==="fixed",m=p?N(f):f;for(;C(m)&&!ft(m);){let g=P(m),y=ct(m);(p?y||d:y||g.position!=="static"||!d||!["absolute","fixed"].includes(d.position))?d=g:h=h.filter(w=>w!==m),m=N(m)}return u.set(f,h),h}(t,this._c):[].concat(i),r=[...a,n],s=r[0],c=r.reduce((f,u)=>{let l=It(t,u,o);return f.top=U(l.top,f.top),f.right=vt(l.right,f.right),f.bottom=vt(l.bottom,f.bottom),f.left=U(l.left,f.left),f},It(t,s,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{rect:t,offsetParent:i,strategy:n}=e,o=O(i),a=W(i);if(i===a)return t;let r={scrollLeft:0,scrollTop:0},s={x:1,y:1},c={x:0,y:0};if((o||!o&&n!=="fixed")&&((F(i)!=="body"||G(a))&&(r=Z(i)),O(i))){let f=H(i);s=k(i),c.x=f.x+i.clientLeft,c.y=f.y+i.clientTop}return{width:t.width*s.x,height:t.height*s.y,x:t.x*s.x-r.scrollLeft*s.x+c.x,y:t.y*s.y-r.scrollTop*s.y+c.y}},isElement:C,getDimensions:function(e){return Pt(e)},getOffsetParent:Et,getDocumentElement:W,getScale:k,async getElementRects(e){let{reference:t,floating:i,strategy:n}=e,o=this.getOffsetParent||Et,a=this.getDimensions;return{reference:Nt(t,await o(i),n),floating:{x:0,y:0,...await a(i)}}},getClientRects:e=>Array.from(e.getClientRects()),isRTL:e=>P(e).direction==="rtl"};function Lt(e,t,i,n){n===void 0&&(n={});let{ancestorScroll:o=!0,ancestorResize:a=!0,elementResize:r=!0,animationFrame:s=!1}=n,c=o&&!s,f=c||a?[...C(e)?j(e):e.contextElement?j(e.contextElement):[],...j(t)]:[];f.forEach(d=>{c&&d.addEventListener("scroll",i,{passive:!0}),a&&d.addEventListener("resize",i)});let u,l=null;if(r){let d=!0;l=new ResizeObserver(()=>{d||i(),d=!1}),C(e)&&!s&&l.observe(e),C(e)||!e.contextElement||s||l.observe(e.contextElement),l.observe(t)}let h=s?H(e):null;return s&&function d(){let p=H(e);!h||p.x===h.x&&p.y===h.y&&p.width===h.width&&p.height===h.height||i(),h=p,u=requestAnimationFrame(d)}(),i(),()=>{var d;f.forEach(p=>{c&&p.removeEventListener("scroll",i),a&&p.removeEventListener("resize",i)}),(d=l)==null||d.disconnect(),l=null,s&&cancelAnimationFrame(u)}}var Tt=(e,t,i)=>{let n=new Map,o={platform:$t,...i},a={...o.platform,_c:n};return wt(e,t,{...o,platform:a})};var ht=class{constructor(t){this._middleware=[];this._floating=!1;(this.host=t).addController(this)}hostConnected(){this.host.floating&&this.float(this.host.floating)}hostDisconnected(){this.destroy()}hostUpdated(){this._floating&&this.updatePosition()}hostResized(){this._floating&&this.updatePosition()}float(t){var s;if(this._floating)return;if(this._floating=!0,this._settings=t,this._reference=this.getReference(),this._resizeObserver=new ResizeObserver(()=>this.hostResized()),!this._settings)throw new Error("Floating settings are required");if(!this._reference)throw new Error("Floating reference is required");this.host.classList.add("wk-floating");let{position:i,arrow:n=!1,flip:o=!1,shift:a=!1}=this._settings,r=this.getOffsetSetting();Object.assign(this.host.style,{position:(s=i.strategy)!=null?s:"absolute",top:"0",left:"0",transition:"none",transform:"translate3d(0,0,0)"}),i.inset&&!n?this._middleware.push(Y(({rects:c,placement:f})=>{var u,l,h,d,p,m;return f.includes("top")||f.includes("bottom")?{mainAxis:-c.floating.height-((u=r==null?void 0:r.mainAxis)!=null?u:0),crossAxis:(l=r==null?void 0:r.crossAxis)!=null?l:0,alignmentAxis:(h=r==null?void 0:r.alignmentAxis)!=null?h:0}:{mainAxis:-c.floating.width-((d=r==null?void 0:r.mainAxis)!=null?d:0),crossAxis:(p=r==null?void 0:r.crossAxis)!=null?p:0,alignmentAxis:(m=r==null?void 0:r.alignmentAxis)!=null?m:0}})):r&&this._middleware.push(Y(r)),o&&this._middleware.push(at()),a&&this._middleware.push(lt()),n&&(this.arrowEl=document.createElement("div"),this.arrowEl.classList.add("wk-arrow"),this._middleware.push(st({element:this.arrowEl}))),this.cleanupAutoUpdate=Lt(this._reference,this.host,()=>{this.updatePosition()}),this._resizeObserver.observe(this.host)}getOffsetSetting(){var i,n;let t=(i=this._settings)==null?void 0:i.offset;if(!(!t||typeof t=="boolean"))return typeof t=="number"?{mainAxis:t,alignmentAxis:(n=this._settings)!=null&&n.position.inset?t:null}:t}destroy(){var t,i,n,o;this._floating&&(Object.assign(this.host.style,{position:"",top:"",left:"",transition:"",transform:""}),(i=(t=this.arrowEl)==null?void 0:t.parentElement)==null||i.removeChild(this.arrowEl),this.arrowEl=void 0,this._middleware=[],this.host.classList.remove("wk-floating"),(n=this.cleanupAutoUpdate)==null||n.call(this),(o=this._resizeObserver)==null||o.disconnect(),this._floating=!1)}updatePosition(){var n;if(!this._reference||!this._settings)return;let{strategy:t="absolute",placement:i="top"}=(n=this._settings.position)!=null?n:{};Tt(this._reference,this.host,{middleware:this._middleware,strategy:t,placement:i}).then(({x:o,y:a,placement:r,middlewareData:s})=>{if(s.arrow&&this.arrowEl){let{x:c,y:f}=s.arrow,u={top:"bottom",right:"left",bottom:"top",left:"right"}[r.split("-")[0]],l={bottom:"0deg",left:"90deg",top:"180deg",right:"270deg"}[r.split("-")[0]];Object.assign(this.arrowEl.style,{left:c!=null?`${c}px`:"",top:f!=null?`${f}px`:"",right:"",bottom:"",[u]:"-5px",transform:`rotate(${l})`})}Object.assign(this.host.style,{transform:`translate3d(${Math.round(o)}px,${Math.round(a)}px,0)`})})}getReference(){if(!this._settings)return;let t=this._settings.reference;if(typeof t=="string"){if(t==="viewport")return this.createViewportReference();let i=document.querySelector(t);if(!i)throw new Error(`Floating reference element (${t}) not found`);return i}return t.hasOwnProperty("element")?t.element:t}createViewportReference(){return{getBoundingClientRect(){var t,i,n,o;return{x:0,y:0,top:0,left:0,bottom:0,right:0,width:(i=(t=window.visualViewport)==null?void 0:t.width)!=null?i:0,height:(o=(n=window.visualViewport)==null?void 0:n.height)!=null?o:0}}}}};var ut=class{constructor(t){this.product=null;this.selectedVariant=null;this.selectedOptions={};this.hasSelection=!1;this.optionsWithValues=[];this.hasOnlyDefaultVariant=!1;(this.host=t).addController(this)}set submitting(t){var i;(i=this.host.querySelector("form"))==null||i.classList.toggle("wk-submitting",t)}get submitting(){var t,i;return(i=(t=this.host.querySelector("form"))==null?void 0:t.classList.contains("wk-submitting"))!=null?i:!1}setProduct({product:t,selectedVariantId:i,autoSelect:n=!1}){t!=null&&t.variants&&(this.product=t,this.initFormState({selectedVariantId:i,autoSelect:n}))}initFormState({selectedVariantId:t,autoSelect:i}){if(!this.product)throw new Error("Product not set");let n=this.initializedVariantId!==t?this.product.variants.find(a=>a.id===t):this.selectedVariant;this.initializedVariantId=t;let o=this.host.app.utils.product.getVariantOptions({variant:n});this.updateFormState({options:o,autoSelect:i})}updateFormState({options:t,change:i,autoSelect:n=!1}){if(!this.product)throw new Error("Product not set");let{hasSelection:o,optionsWithValues:a,selectedOptions:r,selectedVariant:s}=this.host.app.utils.product.getFormState({product:this.product,options:t,change:i,autoSelect:n});this.hasSelection=o,this.optionsWithValues=a,this.selectedOptions=r,this.selectedVariant=s,this.host.requestUpdate()}changeOption({input:t,autoSelect:i=!1}){if(!this.product)throw new Error("Product not set");let n=this.getInputOption(t);if(!n)throw new Error("Cannot parse options from input");this.updateFormState({options:this.selectedOptions,change:n,autoSelect:i})}addToCart({wishlistId:t,wishlistItemId:i}){if(!this.selectedVariant)throw new Error("No variant selected");let n=this.host.querySelector("form");if(!n)throw new Error("Form not found");return this.submitting=!0,this.host.app.addToCart({wishlistId:t,wishlistItemId:i,variantId:this.selectedVariant.id,quantity:this.host.app.utils.product.getFormQuantity({form:n})}).finally(()=>{this.submitting=!1})}getInputOption(t){if(!this.product)throw new Error("Product not set");return this.host.app.utils.product.getInputOption({input:t,product:this.product})}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}};import{combineLatest as Kt,distinctUntilChanged as Xt,map as tt,of as Yt}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var dt=class{constructor(t){this.stateConfig={loading:"eager"};(this.host=t).addController(this)}get app(){if(!window.WishlistKing)throw new Error("Wishlist King SDK not initialized");return window.WishlistKing}get hostDataset(){return this.host.dataset?this.host.dataset:this.host.host?this.host.host.dataset:{}}hostConnected(){}hostDisconnected(){}parseStateConfig(t){var i;return{loading:(i=t.loading)!=null?i:"eager",wishlist:this.parseWishlistStateConfig(t),wishlistItem:this.parseWishlistItemStateConfig(t),productInfo:this.parseProductInfoStateConfig(t)}}parseWishlistStateConfig({wishlist:t}){var n;let i=(n=this.hostDataset.wishlistId)!=null?n:"mine";if(t)return{params:{wishlistId:i}}}parseWishlistItemStateConfig({wishlistItem:t}){let{wishlistId:i="mine",wishlistItemId:n}=this.hostDataset;if(!(!t||!n))return{params:{wishlistId:i,wishlistItemId:n}}}parseProductInfoStateConfig({productInfo:t}){if(!t)return;let{wishlistId:i="mine",productHandle:n="",productId:o,variantId:a}=this.hostDataset;return{params:{wishlistId:i,productHandle:n,variantId:a?parseInt(a):void 0}}}observe(){this.stateConfig=this.parseStateConfig(this.host.getStateConfig());let t=[];if(this.stateConfig.wishlist){let{wishlistId:i="mine"}=this.stateConfig.wishlist.params;t.push(this.app.state.observeWishlist({wishlistId:i}).pipe(tt(n=>({wishlist:n}))))}if(this.stateConfig.productInfo){let{productHandle:i,variantId:n}=this.stateConfig.productInfo.params;if(!i)throw new Error("Product handle is required");t.push(this.app.state.observeProductInfo({productHandle:i,variantId:n}).pipe(tt(o=>({productInfo:o}))))}if(this.stateConfig.wishlistItem){let{wishlistId:i,wishlistItemId:n}=this.stateConfig.wishlistItem.params;if(!i)throw new Error("Wishlist id is required");if(!n)throw new Error("Wishlist item id is required");t.push(this.app.state.observeWishlistItem({wishlistId:i,wishlistItemId:n}).pipe(tt(o=>({wishlistItem:o}))))}return t.length||t.push(Yt({})),Kt(t).pipe(tt(i=>i.reduce((n,o)=>o.wishlist?{...n,wishlist:o.wishlist}:o.wishlistItem?{...n,wishlistItem:o.wishlistItem}:o.productInfo?{...n,productInfo:o.productInfo}:n,{})),Xt((i,n)=>JSON.stringify(i)===JSON.stringify(n)))}getFallback(){this.stateConfig=this.parseStateConfig(this.host.getStateConfig());let t={};if(this.stateConfig.wishlist){let{wishlistId:i="mine"}=this.stateConfig.wishlist.params;t.wishlist={id:i,isMine:i==="mine",numItems:0,items:[]}}if(this.stateConfig.productInfo){let{variantId:i=0,productHandle:n}=this.stateConfig.productInfo.params;t.productInfo={productId:0,variantId:i,productHandle:n,inWishlist:!1}}if(this.stateConfig.wishlistItem){let{wishlistId:i,wishlistItemId:n}=this.stateConfig.wishlistItem.params;if(!i)throw new Error("Wishlist id is required");if(!n)throw new Error("Wishlist item id is required");t.wishlistItem={id:n,product:{id:0,handle:"",hidden:!1}}}return t}};export{ht as FloatingUiController,ut as ProductFormController,dt as WishlistStateController}; |
{ | ||
"name": "@appmate/wishlist", | ||
"version": "4.18.5", | ||
"version": "4.19.0", | ||
"description": "Wishlist King SDK", | ||
"main": "index.js", | ||
"main": "wishlist-app.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
@@ -1,1 +0,1 @@ | ||
var o=class{constructor(t){this.element=t}replace(t){var e;return(e=this.element)==null||e.replaceWith(t),t}append(t){var e;return(e=this.element)==null||e.append(t),t}prepend(t){var e;return(e=this.element)==null||e.prepend(t),t}insertBefore(t){var e;return(e=this.element)==null||e.before(t),t}insertAfter(t){var e;return(e=this.element)==null||e.after(t),t}closest(t,e=5){if(!this.element)return new o;if(typeof t=="object")return this.searchByStyle(t,this.element,a=>a.parentElement,e);let r=this.element.closest(t);return r?new o(r):new o}find(t){var r;let e=(r=this.element)==null?void 0:r.querySelector(t);return e?new o(e):new o}searchByStyle(t,e,r,a=5){if(a<0||!e)return null;let n=getComputedStyle(e);if(Object.entries(t).every(([h,d])=>n.getPropertyValue(h)===d))return new o(e);let l=r(e);return l?this.searchByStyle(t,l,r,a-1):null}};var c=class{constructor({routeUtil:t}){this.subscriber=[],this.routeUtil=t,this.observer=new MutationObserver(e=>{e.reduce((r,a)=>r.concat(Array.from(a.addedNodes)),[]).filter(r=>r instanceof Element&&!r.hasAttribute("data-appmate")).forEach(r=>this.scan(r))}),this.observer.observe(document.body,{subtree:!0,childList:!0,attributes:!1})}watch(t,e){let r={target:t,callback:e};this.subscriber.push(r),g(r,this.routeUtil.parse(window.location.pathname))&&this.scan(document.body)}shouldSkip(t,{skipHidden:e}){return e&&t instanceof HTMLElement?t.offsetParent===null:!1}scan(t){this.subscriber.filter(e=>g(e,this.routeUtil.parse(window.location.pathname))).forEach(e=>{let r=t.matches(e.target.selector)&&!this.shouldSkip(t,{skipHidden:!!e.target.skipHidden});if(r&&this.notify(e,t),r&&e.target.firstMatch)return;let a=t.querySelectorAll(e.target.selector);for(let n of a)if(!this.shouldSkip(n,{skipHidden:!!e.target.skipHidden})&&(this.notify(e,n),e.target.firstMatch))break})}notify(t,e){if(!e.hasAttribute("data-appmate")){e.setAttribute("data-appmate","");let r=new o(e);t.callback(r)}}};function g({target:s},t){if(!s.pageType)return!0;if(!t.pageType)return!1;let e=Array.isArray(s.pageType)?s.pageType:[s.pageType];return e.includes("all")?!0:e.includes(t.pageType)}var f=[{pageType:"product",match:s=>s.includes("/products/")},{pageType:"collection",match:s=>s.includes("/collections/")&&!s.includes("/products/")},{pageType:"account",match:s=>s.includes("/account/")||s.endsWith("/account")},{pageType:"blog",match:s=>s.includes("/blog/")},{pageType:"cart",match:s=>s.includes("/cart/")||s.endsWith("/cart")},{pageType:"wishlist",match:(s,{wishlistUrl:t})=>s.includes(t)},{pageType:"page",match:s=>s.includes("/pages/")},{pageType:"home",match:s=>s.length<4}],p=class{constructor({wishlistUrl:t}){this.wishlistUrl=t}parse(t){for(let e of f)if(e.match(t,{wishlistUrl:this.wishlistUrl}))return{pageType:e.pageType};return{pageType:void 0}}};var u=class{constructor(t){var e;this.locale=this.decodeLocale((e=t.locale)!=null?e:{})}decodeHtmlEntities(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'")}decodeLocale(t){let e={};for(let r in t){e[r]={};for(let a in t[r])e[r][a]=this.decodeHtmlEntities(t[r][a])}return e}translate(t,e){var i;let[r,a]=t.split("."),n=(i=this.locale[r])==null?void 0:i[a];return n?e?Object.entries(e).reduce((l,[h,d])=>l.replace(new RegExp(`{{\\s*${h}\\s*}}`,"g"),d),n):n:`translation missing: ${t}`}};var m=class{constructor({rootUrl:t,wishlistUrl:e,locale:r}){this._rootUrl=t,this.route=new p({wishlistUrl:e}),this.observer=new c({routeUtil:this.route}),this.locale=new u({locale:r}),this.watch=this.observer.watch.bind(this.observer)}getPageType(t=window.location.pathname){return this.route.parse(t).pageType}getWishlistId(t){if(!t)return null;t instanceof URL&&(t=t.pathname);let e=t.replace(this._rootUrl,"/").split("/");return e.length===4?e.pop():"mine"}getProductHandle(t){var e;return t?(t instanceof URL&&(t=t.pathname),(e=t.split("/").pop())==null?void 0:e.split("?")[0]):null}getVariantId(t){return t?(t instanceof URL&&(t=t.pathname),new URLSearchParams(t.split("?")[1]).get("variant")):null}translate(t,e){return this.locale.translate(t,e)}createComponent(t,e){var a;let r=document.createElement(t);return e!=null&&e.dataset&&Object.entries(e==null?void 0:e.dataset).forEach(([n,i])=>{!i||(typeof i=="boolean"?r.dataset[n]="":typeof i=="object"?r.dataset[n]=JSON.stringify(i):r.dataset[n]=i)}),e!=null&&e.props&&Object.entries(e==null?void 0:e.props).forEach(([n,i])=>{r[n]=i}),(a=e==null?void 0:e.wrap)!=null&&a.name?this.createElement(e.wrap.name,e.wrap.props,r):r}createHeadlessComponent(t,e){var n;let r=e.host.element?e.host.element:e.host;if(!r)throw new Error("Headless host is undefined");e.dataset&&Object.entries(e.dataset).forEach(([i,l])=>{!l||(typeof l=="boolean"?r.dataset[i]="":typeof l=="object"?r.dataset[i]=JSON.stringify(l):r.dataset[i]=l)});let a=(n=window.headlessElements)==null?void 0:n.store.get(t);if(!a)throw new Error(`Headless element not found: ${t}`);return new a(r)}createElement(t,e={},...r){let a=Object.assign(document.createElement(t),e);return r&&a.append(...r),a}};export{m as ThemeHelper}; | ||
var o=class{constructor(t){this.element=t}replace(t){var e;return(e=this.element)==null||e.replaceWith(t),t}append(t){var e;return(e=this.element)==null||e.append(t),t}prepend(t){var e;return(e=this.element)==null||e.prepend(t),t}insertBefore(t){var e;return(e=this.element)==null||e.before(t),t}insertAfter(t){var e;return(e=this.element)==null||e.after(t),t}closest(t,e=5){if(!this.element)return new o;if(typeof t=="object")return this.searchByStyle(t,this.element,a=>a.parentElement,e);let r=this.element.closest(t);return r?new o(r):new o}find(t){var r;let e=(r=this.element)==null?void 0:r.querySelector(t);return e?new o(e):new o}searchByStyle(t,e,r,a=5){if(a<0||!e)return null;let n=getComputedStyle(e);if(Object.entries(t).every(([h,d])=>n.getPropertyValue(h)===d))return new o(e);let l=r(e);return l?this.searchByStyle(t,l,r,a-1):null}};var c=class{constructor({routeUtil:t}){this.subscriber=[],this.routeUtil=t,this.observer=new MutationObserver(e=>{e.reduce((r,a)=>r.concat(Array.from(a.addedNodes)),[]).filter(r=>r instanceof Element&&!r.hasAttribute("data-appmate")).forEach(r=>this.scan(r))}),this.observer.observe(document.body,{subtree:!0,childList:!0,attributes:!1})}watch(t,e){let r={target:t,callback:e};this.subscriber.push(r),g(r,this.routeUtil.parse(window.location.pathname))&&this.scan(document.body)}shouldSkip(t,{skipHidden:e}){return e&&t instanceof HTMLElement?t.offsetParent===null:!1}scan(t){this.subscriber.filter(e=>g(e,this.routeUtil.parse(window.location.pathname))).forEach(e=>{let r=t.matches(e.target.selector)&&!this.shouldSkip(t,{skipHidden:!!e.target.skipHidden});if(r&&this.notify(e,t),r&&e.target.firstMatch)return;let a=t.querySelectorAll(e.target.selector);for(let n of a)if(!this.shouldSkip(n,{skipHidden:!!e.target.skipHidden})&&(this.notify(e,n),e.target.firstMatch))break})}notify(t,e){if(!e.hasAttribute("data-appmate")){e.setAttribute("data-appmate","");let r=new o(e);t.callback(r)}}};function g({target:s},t){if(!s.pageType)return!0;if(!t.pageType)return!1;let e=Array.isArray(s.pageType)?s.pageType:[s.pageType];return e.includes("all")?!0:e.includes(t.pageType)}var f=[{pageType:"product",match:s=>s.includes("/products/")},{pageType:"collection",match:s=>s.includes("/collections/")&&!s.includes("/products/")},{pageType:"account",match:s=>s.includes("/account/")||s.endsWith("/account")},{pageType:"blog",match:s=>s.includes("/blog/")},{pageType:"cart",match:s=>s.includes("/cart/")||s.endsWith("/cart")},{pageType:"wishlist",match:(s,{wishlistUrl:t})=>s.includes(t)},{pageType:"page",match:s=>s.includes("/pages/")},{pageType:"home",match:s=>s.length<4}],p=class{constructor({wishlistUrl:t}){this.wishlistUrl=t}parse(t){for(let e of f)if(e.match(t,{wishlistUrl:this.wishlistUrl}))return{pageType:e.pageType};return{pageType:void 0}}};var u=class{constructor(t){var e;this.locale=this.decodeLocale((e=t.locale)!=null?e:{})}decodeHtmlEntities(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'")}decodeLocale(t){let e={};for(let r in t){e[r]={};for(let a in t[r])e[r][a]=this.decodeHtmlEntities(t[r][a])}return e}translate(t,e){var i;let[r,a]=t.split("."),n=(i=this.locale[r])==null?void 0:i[a];return n?e?Object.entries(e).reduce((l,[h,d])=>l.replace(new RegExp(`{{\\s*${h}\\s*}}`,"g"),d),n):n:`translation missing: ${t}`}};var m=class{constructor({rootUrl:t,wishlistUrl:e,locale:r}){this._rootUrl=t,this.route=new p({wishlistUrl:e}),this.observer=new c({routeUtil:this.route}),this.locale=new u({locale:r}),this.watch=this.observer.watch.bind(this.observer)}getPageType(t=window.location.pathname){return this.route.parse(t).pageType}getWishlistId(t){if(!t)return null;t instanceof URL&&(t=t.pathname);let e=t.replace(this._rootUrl,"/").split("/");return e.length===4?e.pop():"mine"}getProductHandle(t){var e;return t?(t instanceof URL&&(t=t.pathname),(e=t.split("/").pop())==null?void 0:e.split("?")[0]):null}getVariantId(t){return t?(t instanceof URL&&(t=t.pathname),new URLSearchParams(t.split("?")[1]).get("variant")):null}translate(t,e){return this.locale.translate(t,e)}createComponent(t,e){var a;let r=document.createElement(t);return e!=null&&e.dataset&&Object.entries(e==null?void 0:e.dataset).forEach(([n,i])=>{i&&(typeof i=="boolean"?r.dataset[n]="":typeof i=="object"?r.dataset[n]=JSON.stringify(i):r.dataset[n]=i)}),e!=null&&e.props&&Object.entries(e==null?void 0:e.props).forEach(([n,i])=>{r[n]=i}),(a=e==null?void 0:e.wrap)!=null&&a.name?this.createElement(e.wrap.name,e.wrap.props,r):r}createHeadlessComponent(t,e){var n;let r=e.host.element?e.host.element:e.host;if(!r)throw new Error("Headless host is undefined");e.dataset&&Object.entries(e.dataset).forEach(([i,l])=>{l&&(typeof l=="boolean"?r.dataset[i]="":typeof l=="object"?r.dataset[i]=JSON.stringify(l):r.dataset[i]=l)});let a=(n=window.headlessElements)==null?void 0:n.store.get(t);if(!a)throw new Error(`Headless element not found: ${t}`);return new a(r)}createElement(t,e={},...r){let a=Object.assign(document.createElement(t),e);return r&&a.append(...r),a}};export{m as ThemeHelper}; |
@@ -1,1 +0,1 @@ | ||
var m=class{constructor(t){this.placeholderRegex=/\{\{\s*(\w+)\s*\}\}/;var r;this.moneyFormat=(r=t.moneyFormat)!=null?r:"${{amount}}",this.currencyRate=t.currencyRate,this.activeCurrency=t.activeCurrency}formatMoney(t){var r;return typeof t=="string"&&(t=parseInt(t.replace(".",""))),this.moneyFormat.replace(this.placeholderRegex,this.formatCents(t,(r=this.moneyFormat.match(this.placeholderRegex))==null?void 0:r[1]))}formatCents(t,r){switch(r){case"amount_no_decimals":return this.formatWithDelimiters(t,0);case"amount_with_comma_separator":return this.formatWithDelimiters(t,2,".",",");case"amount_no_decimals_with_comma_separator":return this.formatWithDelimiters(t,0,".",",");case"amount":default:return this.formatWithDelimiters(t,2)}}formatWithDelimiters(t,r=2,e=",",i="."){if(isNaN(t)||t==null)return"0";let n=(t/100).toFixed(r).split("."),a=n[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${e}`),s=n[1]?i+n[1]:"";return a+s}};var f=class{constructor(){}getFormState({product:t,options:r,autoSelect:e=!1,change:i}){let o=this.getSelectedOptions({product:t,options:r,change:i,autoSelect:e}),n=o&&Object.values(o).every(u=>!!u),a=this.getOptionsWithValues({product:t,selectedOptions:o});return{selectedVariant:this.getVariantByOptions({product:t,options:o}),selectedOptions:o,hasSelection:n,optionsWithValues:a,hasOnlyDefaultVariant:t.variants.length===1}}getSelectedOptions({product:t,options:r,autoSelect:e,change:i={}}){let o=Object.fromEntries(Object.entries({...r,...i}).map(([l,c],h)=>{var p;return!c&&((p=t.options[h])==null?void 0:p.values.length)===1?[l,t.options[h].values[0]]:[l,c]}));if(!e)return o;e===!0&&(e="unavailable");let n=this.getVariantByOptions({product:t,options:o});if(e==="unavailable"&&n||e==="soldout"&&(n==null?void 0:n.available))return o;let a=Object.keys(i).pop(),s=Object.fromEntries(Object.entries(o).filter(([l])=>!a||l<=a)),u=Object.fromEntries(Object.entries(o).filter(([l])=>!(l in s)));return Object.entries(u).reduce((l,[c,h])=>{var y;let p=this.getAllVariantsByOptions({product:t,options:l});return p.length?{...l,[c]:((y=p.find(O=>O.available))!=null?y:p[0])[c]}:{...l,[c]:null}},s)}getVariantOptions({variant:t}){var r,e,i;return{option1:(r=t==null?void 0:t.option1)!=null?r:null,option2:(e=t==null?void 0:t.option2)!=null?e:null,option3:(i=t==null?void 0:t.option3)!=null?i:null}}getOptionsWithValues({product:t,selectedOptions:r={}}){return t.options.map(e=>{var s;let i=`option${e.position}`,o=this.getUnavailableOptionValues({product:t,optionKey:i,selectedOptions:r,values:e.values}),n=this.getSoldoutOptionValues({product:t,optionKey:i,selectedOptions:r,values:e.values}),a=(s=r==null?void 0:r[i])!=null?s:null;return{...e,selectedValue:a,soldoutValues:n,unavailableValues:o}})}getSoldoutOptionValues({product:t,optionKey:r,values:e,selectedOptions:i={}}){let o=Object.fromEntries(Object.entries(i).filter(([n])=>n<r));return e.filter(n=>{let a=t.variants.filter(s=>this.matchesVariant({variant:s,options:{...o,[r]:n}}));return a.length?a.every(s=>!s.available):!1})}getUnavailableOptionValues({product:t,optionKey:r,values:e,selectedOptions:i={}}){let o=Object.fromEntries(Object.entries(i).filter(([n])=>n<r));return e.filter(n=>t.variants.every(a=>!this.matchesVariant({variant:a,options:{...o,[r]:n}})))}getFirstAvailableVariant({product:t}){var r;return(r=t.variants.find(e=>e.available))!=null?r:null}getSelectedVariant({product:t,variantId:r}){var e;return(e=t.variants.find(i=>i.id===r))!=null?e:null}matchesVariant({variant:t,options:r}){return(!(r!=null&&r.option1)||r.option1===t.option1)&&(!(r!=null&&r.option2)||r.option2===t.option2)&&(!(r!=null&&r.option3)||r.option3===t.option3)}getFormData({form:t,product:r}){let e=new FormData(t);return{quantity:this.getFormQuantity({form:t}),options:this.getFormOptions({formData:e,product:r})}}getFormQuantity({form:t}){var i;let e=(i=new FormData(t).get("quantity"))==null?void 0:i.toString();return e?parseInt(e):1}getVariantByOptions({product:t,options:r}){var i;let e=Object.entries(r).reduce((o,[,n],a)=>(o[a]=n,o),new Array(3).fill(null));return(i=t.variants.find(o=>e.every((n,a)=>o[`option${a+1}`]===n)))!=null?i:null}getAllVariantsByOptions({product:t,options:r}){var i;let e=Object.entries(r).reduce((o,[,n],a)=>(o[a]=n,o),new Array(3).fill(null));return(i=t.variants.filter(o=>e.every((n,a)=>!n||o[`option${a+1}`]===n)))!=null?i:[]}getFormOptions({formData:t,product:r}){return Array.from(t.entries()).reduce((e,[i,o])=>{var s;let n=(s=i.match(/\[(.*?)\]/))==null?void 0:s[1];if(!n)return e;let a=r.options.findIndex(u=>u.name===n)+1;if(a>0){let u=`option${a}`;e[u]=o.toString()||null}return e},{})}getInputOption({input:t,product:r}){var o;let e=(o=t.name.match(/\[(.*?)\]/))==null?void 0:o[1];if(!e)return null;let i=r.options.findIndex(n=>n.name===e)+1;return i>0?{[`option${i}`]:t.value.toString()}:null}};var d=class{constructor(t){this.rootUrl=t.rootUrl,this.shopDomain=t.shopDomain,this.wishlistUrl=t.wishlistUrl,this.placeholderImageUrl=t.placeholderImageUrl,this.fileUrl=t.fileUrl}getPublicWishlistUrl(t){return`https://${this.shopDomain}${this.wishlistUrl}/${t}`}getFileUrl(t=""){return`https:${this.fileUrl.split("?")[0]}${t}`}getImageUrl(t,r){var i,o;if(!t)return(i=this.placeholderImageUrl)!=null?i:"";let e=this.getImage(t);return e!=null&&e.src?this.appendSize(e.src,r):(o=this.placeholderImageUrl)!=null?o:""}getImage(t){var r,e,i,o;if(t.hasOwnProperty("sku"))return{src:(e=(r=t.featured_image)==null?void 0:r.src)!=null?e:""};if((i=t==null?void 0:t.images)!=null&&i.length){let n=t;return{src:(o=n.featured_image)!=null?o:n.images[0]}}else if(t.hasOwnProperty("src"))return{src:t.src};return null}appendSize(t,r){let e=new URL(t.startsWith("//")?`https://${t}`:t);return r!=null&&r.width&&e.searchParams.set("width",r==null?void 0:r.width.toString()),r!=null&&r.height&&e.searchParams.set("height",r==null?void 0:r.height.toString()),e.href}getVariantUrl(t,r){if(!!t)return r?t+`?variant=${r}`:t}};export{m as MoneyUtil,f as ProductUtil,d as UrlUtil}; | ||
var m=class{constructor(t){this.placeholderRegex=/\{\{\s*(\w+)\s*\}\}/;var r;this.moneyFormat=(r=t.moneyFormat)!=null?r:"${{amount}}",this.currencyRate=t.currencyRate,this.activeCurrency=t.activeCurrency}formatMoney(t){var r;return typeof t=="string"&&(t=parseInt(t.replace(".",""))),this.moneyFormat.replace(this.placeholderRegex,this.formatCents(t,(r=this.moneyFormat.match(this.placeholderRegex))==null?void 0:r[1]))}formatCents(t,r){switch(r){case"amount_no_decimals":return this.formatWithDelimiters(t,0);case"amount_with_comma_separator":return this.formatWithDelimiters(t,2,".",",");case"amount_no_decimals_with_comma_separator":return this.formatWithDelimiters(t,0,".",",");case"amount":default:return this.formatWithDelimiters(t,2)}}formatWithDelimiters(t,r=2,e=",",i="."){if(isNaN(t)||t==null)return"0";let n=(t/100).toFixed(r).split("."),a=n[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${e}`),s=n[1]?i+n[1]:"";return a+s}};var f=class{constructor(){}getFormState({product:t,options:r,autoSelect:e=!1,change:i}){let o=this.getSelectedOptions({product:t,options:r,change:i,autoSelect:e}),n=o&&Object.values(o).every(u=>!!u),a=this.getOptionsWithValues({product:t,selectedOptions:o});return{selectedVariant:this.getVariantByOptions({product:t,options:o}),selectedOptions:o,hasSelection:n,optionsWithValues:a,hasOnlyDefaultVariant:t.variants.length===1}}getSelectedOptions({product:t,options:r,autoSelect:e,change:i={}}){let o=Object.fromEntries(Object.entries({...r,...i}).map(([l,c],h)=>{var p;return!c&&((p=t.options[h])==null?void 0:p.values.length)===1?[l,t.options[h].values[0]]:[l,c]}));if(!e)return o;e===!0&&(e="unavailable");let n=this.getVariantByOptions({product:t,options:o});if(e==="unavailable"&&n||e==="soldout"&&(n!=null&&n.available))return o;let a=Object.keys(i).pop(),s=Object.fromEntries(Object.entries(o).filter(([l])=>!a||l<=a)),u=Object.fromEntries(Object.entries(o).filter(([l])=>!(l in s)));return Object.entries(u).reduce((l,[c,h])=>{var y;let p=this.getAllVariantsByOptions({product:t,options:l});return p.length?{...l,[c]:((y=p.find(O=>O.available))!=null?y:p[0])[c]}:{...l,[c]:null}},s)}getVariantOptions({variant:t}){var r,e,i;return{option1:(r=t==null?void 0:t.option1)!=null?r:null,option2:(e=t==null?void 0:t.option2)!=null?e:null,option3:(i=t==null?void 0:t.option3)!=null?i:null}}getOptionsWithValues({product:t,selectedOptions:r={}}){return t.options.map(e=>{var s;let i=`option${e.position}`,o=this.getUnavailableOptionValues({product:t,optionKey:i,selectedOptions:r,values:e.values}),n=this.getSoldoutOptionValues({product:t,optionKey:i,selectedOptions:r,values:e.values}),a=(s=r==null?void 0:r[i])!=null?s:null;return{...e,selectedValue:a,soldoutValues:n,unavailableValues:o}})}getSoldoutOptionValues({product:t,optionKey:r,values:e,selectedOptions:i={}}){let o=Object.fromEntries(Object.entries(i).filter(([n])=>n<r));return e.filter(n=>{let a=t.variants.filter(s=>this.matchesVariant({variant:s,options:{...o,[r]:n}}));return a.length?a.every(s=>!s.available):!1})}getUnavailableOptionValues({product:t,optionKey:r,values:e,selectedOptions:i={}}){let o=Object.fromEntries(Object.entries(i).filter(([n])=>n<r));return e.filter(n=>t.variants.every(a=>!this.matchesVariant({variant:a,options:{...o,[r]:n}})))}getFirstAvailableVariant({product:t}){var r;return(r=t.variants.find(e=>e.available))!=null?r:null}getSelectedVariant({product:t,variantId:r}){var e;return(e=t.variants.find(i=>i.id===r))!=null?e:null}matchesVariant({variant:t,options:r}){return(!(r!=null&&r.option1)||r.option1===t.option1)&&(!(r!=null&&r.option2)||r.option2===t.option2)&&(!(r!=null&&r.option3)||r.option3===t.option3)}getFormData({form:t,product:r}){let e=new FormData(t);return{quantity:this.getFormQuantity({form:t}),options:this.getFormOptions({formData:e,product:r})}}getFormQuantity({form:t}){var i;let e=(i=new FormData(t).get("quantity"))==null?void 0:i.toString();return e?parseInt(e):1}getVariantByOptions({product:t,options:r}){var i;let e=Object.entries(r).reduce((o,[,n],a)=>(o[a]=n,o),new Array(3).fill(null));return(i=t.variants.find(o=>e.every((n,a)=>o[`option${a+1}`]===n)))!=null?i:null}getAllVariantsByOptions({product:t,options:r}){var i;let e=Object.entries(r).reduce((o,[,n],a)=>(o[a]=n,o),new Array(3).fill(null));return(i=t.variants.filter(o=>e.every((n,a)=>!n||o[`option${a+1}`]===n)))!=null?i:[]}getFormOptions({formData:t,product:r}){return Array.from(t.entries()).reduce((e,[i,o])=>{var s;let n=(s=i.match(/\[(.*?)\]/))==null?void 0:s[1];if(!n)return e;let a=r.options.findIndex(u=>u.name===n)+1;if(a>0){let u=`option${a}`;e[u]=o.toString()||null}return e},{})}getInputOption({input:t,product:r}){var o;let e=(o=t.name.match(/\[(.*?)\]/))==null?void 0:o[1];if(!e)return null;let i=r.options.findIndex(n=>n.name===e)+1;return i>0?{[`option${i}`]:t.value.toString()}:null}};var d=class{constructor(t){this.rootUrl=t.rootUrl,this.shopDomain=t.shopDomain,this.wishlistUrl=t.wishlistUrl,this.placeholderImageUrl=t.placeholderImageUrl,this.fileUrl=t.fileUrl}getPublicWishlistUrl(t){return`https://${this.shopDomain}${this.wishlistUrl}/${t}`}getFileUrl(t=""){return`https:${this.fileUrl.split("?")[0]}${t}`}getImageUrl(t,r){var i,o;if(!t)return(i=this.placeholderImageUrl)!=null?i:"";let e=this.getImage(t);return e!=null&&e.src?this.appendSize(e.src,r):(o=this.placeholderImageUrl)!=null?o:""}getImage(t){var r,e,i,o;if(t.hasOwnProperty("sku"))return{src:(e=(r=t.featured_image)==null?void 0:r.src)!=null?e:""};if((i=t==null?void 0:t.images)!=null&&i.length){let n=t;return{src:(o=n.featured_image)!=null?o:n.images[0]}}else if(t.hasOwnProperty("src"))return{src:t.src};return null}appendSize(t,r){let e=new URL(t.startsWith("//")?`https://${t}`:t);return r!=null&&r.width&&e.searchParams.set("width",r==null?void 0:r.width.toString()),r!=null&&r.height&&e.searchParams.set("height",r==null?void 0:r.height.toString()),e.href}getVariantUrl(t,r){if(t)return r?t+`?variant=${r}`:t}};export{m as MoneyUtil,f as ProductUtil,d as UrlUtil}; |
@@ -1,1 +0,1 @@ | ||
var p=class{constructor(t){this.element=t}replace(t){var e;return(e=this.element)==null||e.replaceWith(t),t}append(t){var e;return(e=this.element)==null||e.append(t),t}prepend(t){var e;return(e=this.element)==null||e.prepend(t),t}insertBefore(t){var e;return(e=this.element)==null||e.before(t),t}insertAfter(t){var e;return(e=this.element)==null||e.after(t),t}closest(t,e=5){if(!this.element)return new p;if(typeof t=="object")return this.searchByStyle(t,this.element,i=>i.parentElement,e);let s=this.element.closest(t);return s?new p(s):new p}find(t){var s;let e=(s=this.element)==null?void 0:s.querySelector(t);return e?new p(e):new p}searchByStyle(t,e,s,i=5){if(i<0||!e)return null;let r=getComputedStyle(e);if(Object.entries(t).every(([l,c])=>r.getPropertyValue(l)===c))return new p(e);let n=s(e);return n?this.searchByStyle(t,n,s,i-1):null}};var u=class{constructor({routeUtil:t}){this.subscriber=[],this.routeUtil=t,this.observer=new MutationObserver(e=>{e.reduce((s,i)=>s.concat(Array.from(i.addedNodes)),[]).filter(s=>s instanceof Element&&!s.hasAttribute("data-appmate")).forEach(s=>this.scan(s))}),this.observer.observe(document.body,{subtree:!0,childList:!0,attributes:!1})}watch(t,e){let s={target:t,callback:e};this.subscriber.push(s),K(s,this.routeUtil.parse(window.location.pathname))&&this.scan(document.body)}shouldSkip(t,{skipHidden:e}){return e&&t instanceof HTMLElement?t.offsetParent===null:!1}scan(t){this.subscriber.filter(e=>K(e,this.routeUtil.parse(window.location.pathname))).forEach(e=>{let s=t.matches(e.target.selector)&&!this.shouldSkip(t,{skipHidden:!!e.target.skipHidden});if(s&&this.notify(e,t),s&&e.target.firstMatch)return;let i=t.querySelectorAll(e.target.selector);for(let r of i)if(!this.shouldSkip(r,{skipHidden:!!e.target.skipHidden})&&(this.notify(e,r),e.target.firstMatch))break})}notify(t,e){if(!e.hasAttribute("data-appmate")){e.setAttribute("data-appmate","");let s=new p(e);t.callback(s)}}};function K({target:a},t){if(!a.pageType)return!0;if(!t.pageType)return!1;let e=Array.isArray(a.pageType)?a.pageType:[a.pageType];return e.includes("all")?!0:e.includes(t.pageType)}var G=[{pageType:"product",match:a=>a.includes("/products/")},{pageType:"collection",match:a=>a.includes("/collections/")&&!a.includes("/products/")},{pageType:"account",match:a=>a.includes("/account/")||a.endsWith("/account")},{pageType:"blog",match:a=>a.includes("/blog/")},{pageType:"cart",match:a=>a.includes("/cart/")||a.endsWith("/cart")},{pageType:"wishlist",match:(a,{wishlistUrl:t})=>a.includes(t)},{pageType:"page",match:a=>a.includes("/pages/")},{pageType:"home",match:a=>a.length<4}],m=class{constructor({wishlistUrl:t}){this.wishlistUrl=t}parse(t){for(let e of G)if(e.match(t,{wishlistUrl:this.wishlistUrl}))return{pageType:e.pageType};return{pageType:void 0}}};var g=class{constructor(t){var e;this.locale=this.decodeLocale((e=t.locale)!=null?e:{})}decodeHtmlEntities(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'")}decodeLocale(t){let e={};for(let s in t){e[s]={};for(let i in t[s])e[s][i]=this.decodeHtmlEntities(t[s][i])}return e}translate(t,e){var o;let[s,i]=t.split("."),r=(o=this.locale[s])==null?void 0:o[i];return r?e?Object.entries(e).reduce((n,[l,c])=>n.replace(new RegExp(`{{\\s*${l}\\s*}}`,"g"),c),r):r:`translation missing: ${t}`}};var d=class{constructor({rootUrl:t,wishlistUrl:e,locale:s}){this._rootUrl=t,this.route=new m({wishlistUrl:e}),this.observer=new u({routeUtil:this.route}),this.locale=new g({locale:s}),this.watch=this.observer.watch.bind(this.observer)}getPageType(t=window.location.pathname){return this.route.parse(t).pageType}getWishlistId(t){if(!t)return null;t instanceof URL&&(t=t.pathname);let e=t.replace(this._rootUrl,"/").split("/");return e.length===4?e.pop():"mine"}getProductHandle(t){var e;return t?(t instanceof URL&&(t=t.pathname),(e=t.split("/").pop())==null?void 0:e.split("?")[0]):null}getVariantId(t){return t?(t instanceof URL&&(t=t.pathname),new URLSearchParams(t.split("?")[1]).get("variant")):null}translate(t,e){return this.locale.translate(t,e)}createComponent(t,e){var i;let s=document.createElement(t);return e!=null&&e.dataset&&Object.entries(e==null?void 0:e.dataset).forEach(([r,o])=>{!o||(typeof o=="boolean"?s.dataset[r]="":typeof o=="object"?s.dataset[r]=JSON.stringify(o):s.dataset[r]=o)}),e!=null&&e.props&&Object.entries(e==null?void 0:e.props).forEach(([r,o])=>{s[r]=o}),(i=e==null?void 0:e.wrap)!=null&&i.name?this.createElement(e.wrap.name,e.wrap.props,s):s}createHeadlessComponent(t,e){var r;let s=e.host.element?e.host.element:e.host;if(!s)throw new Error("Headless host is undefined");e.dataset&&Object.entries(e.dataset).forEach(([o,n])=>{!n||(typeof n=="boolean"?s.dataset[o]="":typeof n=="object"?s.dataset[o]=JSON.stringify(n):s.dataset[o]=n)});let i=(r=window.headlessElements)==null?void 0:r.store.get(t);if(!i)throw new Error(`Headless element not found: ${t}`);return new i(s)}createElement(t,e={},...s){let i=Object.assign(document.createElement(t),e);return s&&i.append(...s),i}};var y=class{constructor(){this.dispatcher=document}publish(t){this.dispatcher.dispatchEvent(new CustomEvent(t.name,{detail:t,bubbles:!1,cancelable:!1}))}once(t,e){let s=i=>{this.dispatcher.removeEventListener(t,s),e(i)};this.subscribe(t,s)}subscribe(t,e){this.dispatcher.addEventListener(t,s=>{let i=s;e({name:i.type,data:i.detail.data})})}subscribeMany(t){return Object.entries(t).map(([e,s])=>this.subscribe(e,s))}};window.headlessElements||(window.headlessElements={store:new Map,define(a,t){var e;(e=window.headlessElements)==null||e.store.set(a,t)}});var q=class{constructor({dependencies:t=[],...e}){this.stylesLoaded=!1;this._loaded=!1;this.addToCart=t=>this.state.promise.addToCart(t);this.addAllToCart=t=>this.state.promise.addAllToCart(t);this.addWishlistItem=t=>this.state.promise.addWishlistItem(t);this.clearWishlist=()=>this.state.promise.clearWishlist();this.loadProductInfo=t=>this.state.promise.loadProductInfo(t);this.loadShopifyProduct=t=>this.state.promise.loadShopifyProduct(t);this.loadWishlist=t=>this.state.promise.loadWishlist(t);this.loadWishlistItem=t=>this.state.promise.loadWishlistItem(t);this.publishWishlistEvent=t=>this.state.promise.publishWishlistEvent(t);this.publishWishlistProductEvent=t=>this.state.promise.publishWishlistProductEvent(t);this.removeWishlistItem=t=>this.state.promise.removeWishlistItem(t);this.shareWishlist=t=>this.state.promise.shareWishlist(t);this.updateWishlistItem=t=>this.state.promise.updateWishlistItem(t);this.config=this.parseConfig(e),this.settings=this.parseSettings(e),this.routes=this.parseRoutes(),this.customer=this.config.customer.id?{id:this.config.customer.id,email:this.config.customer.email}:null,this.events=new y,this.theme=new d({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl,locale:this.config.locale});let{stylesheets:s,scripts:i}=t.reduce(({stylesheets:r,scripts:o},n)=>{let[l]=n.split("?");return l.endsWith(".css")?r.push(n):l.endsWith(".js")&&o.push(n),{stylesheets:r,scripts:o}},{stylesheets:[],scripts:[]});this.initStyles(s),this.initScripts(i),(this.hasSession||this.settings.general.appLoading==="EAGER")&&this.load()}get loaded(){return this._loaded}get state(){return w(this._state)}get apis(){return w(this._apis)}get utils(){return w(this._utils)}get hasSession(){return!!this.getSessionId()||!!this.customer}get isLoggedIn(){var t;return!!((t=this.customer)!=null&&t.id)}getSessionId(){let t=window.localStorage.getItem("wk_session_id");if(t)return t;let e=window.localStorage.getItem("appmate-session");if(e)try{let s=JSON.parse(e).state.sid;return this.setSessionId(s)}catch(s){console.error(s)}}setSessionId(t){var e;return window.localStorage.setItem("wk_session_id",t),(e=this._apis)==null||e.tracking.setSessionId(t),t}async load(){return this._loadPromise?this._loadPromise:this._loadPromise=(async()=>{let[{WishlistState:t},{ShopifyApi:e,WishlistApi:s,TrackingApi:i},{MoneyUtil:r,UrlUtil:o,ProductUtil:n}]=await Promise.all([import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/state.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/api.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/utils.js")]);this.initUtils({MoneyUtil:r,UrlUtil:o,ProductUtil:n}),this.initApis({WishlistApi:s,ShopifyApi:e,TrackingApi:i}),this.initState({WishlistState:t}),this.initUrlChangeEvents(),this.trackCurrentPage(),this.hasSession||(await this.state.promise.clearCache(),this.events.once("wk:app:init-sid",l=>{var c,h;(c=l.data)!=null&&c.sessionId&&this.setSessionId((h=l.data)==null?void 0:h.sessionId)})),this._loaded=!0,this.events.publish({name:"wk:app:load:success"})})()}initUtils({UrlUtil:t,MoneyUtil:e,ProductUtil:s}){let i=this.config.shop.domain,r=this.config.products.fallbackImage,o=this.config.shop.moneyFormat;this._utils={url:new t({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl,shopDomain:i,placeholderImageUrl:r,fileUrl:this.routes.fileUrl}),money:new e({moneyFormat:o,currencyRate:parseFloat(window.Shopify.currency.rate),activeCurrency:window.Shopify.currency.active}),product:new s}}initApis({WishlistApi:t,ShopifyApi:e,TrackingApi:s}){var i,r;this._apis={wishlist:new t({host:this.config.routes.apiHost,shop:window.Shopify.shop,customerId:(i=this.config.customer.id)!=null?i:void 0,sessionId:this.getSessionId(),trackingSource:this.theme.getPageType()}),shopify:new e({host:window.Shopify.routes.root.substring(0,window.Shopify.routes.root.length-1)}),tracking:new s({notifyHost:this.config.routes.apiHost,events:this.events,shop:window.Shopify.shop,customerId:(r=this.config.customer.id)!=null?r:void 0,sessionId:this.getSessionId(),utils:this.utils,theme:this.theme,settings:this.settings})}}initState({WishlistState:t}){this._state=new t({wishlistApi:this.apis.wishlist,shopifyApi:this.apis.shopify,settings:this.settings,events:this.events,utils:this.utils})}async initStyles(t){if(!(t!=null&&t.length)){this.onStylesLoaded();return}try{await Promise.all(t.map(e=>new Promise((s,i)=>{let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.onload=s,r.onerror=i,document.head.appendChild(r)}))),this.onStylesLoaded()}catch(e){console.warn(e),this.events.publish({name:"wk:app:load-styles:error"})}}async initScripts(t){if(!(t!=null&&t.length)){this.events.publish({name:"wk:app:load-scripts:success"});return}try{await Promise.all(t.map(e=>import(e))),this.events.publish({name:"wk:app:load-scripts:success"})}catch(e){console.warn(e),this.events.publish({name:"wk:app:load-scripts:error"})}}trackCurrentPage(){if(this.theme.getPageType()==="wishlist"){let e=this.theme.getWishlistId(window.location.pathname);e&&this.publishWishlistEvent({eventName:"wk:wishlist:page-view",wishlistId:e})}}onStylesLoaded(){this.stylesLoaded=!0,this.events.publish({name:"wk:app:load-styles:success"})}initUrlChangeEvents(){let t=history.replaceState,e=({productHandle:s,variantId:i})=>{this.events.publish({name:"wk:product:change-variant:success",data:{productHandle:s,variantId:i}})};history.replaceState=(...s)=>{let i=`${window.location.protocol}//${window.location.host}`,r=typeof s[2]=="string"?new URL(s[2],i):s[2],o=t.apply(history,s);if(!r)return o;let n=this.theme.getProductHandle(r),l=r.searchParams.get("variant");if(!n||!l)return o;e({productHandle:n,variantId:parseInt(l)})}}parseConfig({config:t,locale:e}){var s,i,r,o,n,l,c,h;return{customer:{id:t.customerId?t.customerId:null,email:(s=t.customerEmail)!=null?s:""},shop:{name:(i=t.shopName)!=null?i:"",domain:(r=t.shopDomain)!=null?r:"",permanentDomain:(o=t.shopPermanentDomain)!=null?o:"",currency:(n=t.shopCurrency)!=null?n:"",moneyFormat:(l=t.shopMoneyFormat)!=null?l:"",customerAccountsEnabled:t.shopCustomerAccountsEnabled?t.shopCustomerAccountsEnabled==="true":!1},routes:{apiHost:(c=t.apiHost)!=null?c:"https://api.appmate.io/v2",rootUrl:window.Shopify.routes.root,fileUrl:t.fileUrl},products:{fallbackImage:(h=t.productFallbackImage)!=null?h:"//cdn.shopify.com/s/files/1/0533/2089/files/placeholder-images-image_large.png?format=webp&v=1530129081"},locale:e}}parseSettings({settings:t}){var e,s,i,r,o,n,l,c,h,f,b,E,U,T,S,W,v,P,A,I,k,R,L,H,M,C,_,N,O,x,D,j,B,V,F;return{general:{appLoading:(s=(e=t==null?void 0:t.general)==null?void 0:e.appLoading)!=null?s:"LAZY",wishlistAccessMode:this.config.customer.id?"UNRESTRICTED":(r=(i=t==null?void 0:t.general)==null?void 0:i.wishlistAccessMode)!=null?r:"UNRESTRICTED",wishlistMode:(n=(o=t==null?void 0:t.general)==null?void 0:o.wishlistMode)!=null?n:"PRODUCT",wishlistPath:(c=(l=t==null?void 0:t.general)==null?void 0:l.wishlistPath)!=null?c:"/apps/wishlist"},wishlistPage:{addToCartMode:(f=(h=t==null?void 0:t.wishlistPage)==null?void 0:h.addToCartMode)!=null?f:"KEEP_IN_WISHLIST",buyButtonType:(E=(b=t==null?void 0:t.wishlistPage)==null?void 0:b.buyButtonType)!=null?E:"ADD_TO_CART",shareButtonType:(T=(U=t==null?void 0:t.wishlistPage)==null?void 0:U.shareButtonType)!=null?T:"WEB_SHARE",loginHintType:(W=(S=t==null?void 0:t.wishlistPage)==null?void 0:S.loginHintType)!=null?W:"CALLOUT",variantAutoSelectMode:(P=(v=t==null?void 0:t.wishlistPage)==null?void 0:v.variantAutoSelectMode)!=null?P:"NEVER",variantSelctorType:(I=(A=t==null?void 0:t.wishlistPage)==null?void 0:A.variantSelctorType)!=null?I:"DROPDOWNS"},integrations:{googleAnalytics:{enabled:(L=(R=(k=t.integrations)==null?void 0:k.googleAnalytics)==null?void 0:R.enabled)!=null?L:!1,tracker:(C=(M=(H=t.integrations)==null?void 0:H.googleAnalytics)==null?void 0:M.tracker)!=null?C:""},klaviyo:{enabled:(O=(N=(_=t.integrations)==null?void 0:_.klaviyo)==null?void 0:N.enabled)!=null?O:!1},metaPixel:{enabled:(j=(D=(x=t.integrations)==null?void 0:x.metaPixel)==null?void 0:D.enabled)!=null?j:!1},wishlistAnalytics:{enabled:(F=(V=(B=t.integrations)==null?void 0:B.metaPixel)==null?void 0:V.enabled)!=null?F:!0}},cache:{wishlist:{ttl:6e4},wishlistItem:{ttl:6e4},productInfo:{ttl:6e4},product:{ttl:3e4}}}}parseRoutes(){let t=this.config.routes.rootUrl;return{rootUrl:t,fileUrl:this.config.routes.fileUrl,wishlistUrl:t+this.settings.general.wishlistPath.split("/").filter(e=>!!e).join("/"),accountUrl:t+"account",accountLoginUrl:t+"account/login",accountLogoutUrl:t+"account/logout",accountRegisterUrl:t+"account/register",accountAddressesUrl:t+"account/addresses",collectionsUrl:t+"collections",allProductsCollectionUrl:t+"collections/all",searchUrl:t+"search",predictiveSearchUrl:t+"search/suggest",cartUrl:t+"cart",cartAddUrl:t+"cart/add",cartChangeUrl:t+"cart/change",cartClearUrl:t+"cart/clear",cartUpdateUrl:t+"cart/update",productRecommendationsUrl:t+"recommendations/products"}}},w=a=>{if(!a)throw new Error("Wishlist app not loaded.");return a};export{q as WishlistApp}; | ||
var p=class{constructor(t){this.element=t}replace(t){var e;return(e=this.element)==null||e.replaceWith(t),t}append(t){var e;return(e=this.element)==null||e.append(t),t}prepend(t){var e;return(e=this.element)==null||e.prepend(t),t}insertBefore(t){var e;return(e=this.element)==null||e.before(t),t}insertAfter(t){var e;return(e=this.element)==null||e.after(t),t}closest(t,e=5){if(!this.element)return new p;if(typeof t=="object")return this.searchByStyle(t,this.element,i=>i.parentElement,e);let s=this.element.closest(t);return s?new p(s):new p}find(t){var s;let e=(s=this.element)==null?void 0:s.querySelector(t);return e?new p(e):new p}searchByStyle(t,e,s,i=5){if(i<0||!e)return null;let r=getComputedStyle(e);if(Object.entries(t).every(([l,c])=>r.getPropertyValue(l)===c))return new p(e);let n=s(e);return n?this.searchByStyle(t,n,s,i-1):null}};var u=class{constructor({routeUtil:t}){this.subscriber=[],this.routeUtil=t,this.observer=new MutationObserver(e=>{e.reduce((s,i)=>s.concat(Array.from(i.addedNodes)),[]).filter(s=>s instanceof Element&&!s.hasAttribute("data-appmate")).forEach(s=>this.scan(s))}),this.observer.observe(document.body,{subtree:!0,childList:!0,attributes:!1})}watch(t,e){let s={target:t,callback:e};this.subscriber.push(s),K(s,this.routeUtil.parse(window.location.pathname))&&this.scan(document.body)}shouldSkip(t,{skipHidden:e}){return e&&t instanceof HTMLElement?t.offsetParent===null:!1}scan(t){this.subscriber.filter(e=>K(e,this.routeUtil.parse(window.location.pathname))).forEach(e=>{let s=t.matches(e.target.selector)&&!this.shouldSkip(t,{skipHidden:!!e.target.skipHidden});if(s&&this.notify(e,t),s&&e.target.firstMatch)return;let i=t.querySelectorAll(e.target.selector);for(let r of i)if(!this.shouldSkip(r,{skipHidden:!!e.target.skipHidden})&&(this.notify(e,r),e.target.firstMatch))break})}notify(t,e){if(!e.hasAttribute("data-appmate")){e.setAttribute("data-appmate","");let s=new p(e);t.callback(s)}}};function K({target:a},t){if(!a.pageType)return!0;if(!t.pageType)return!1;let e=Array.isArray(a.pageType)?a.pageType:[a.pageType];return e.includes("all")?!0:e.includes(t.pageType)}var G=[{pageType:"product",match:a=>a.includes("/products/")},{pageType:"collection",match:a=>a.includes("/collections/")&&!a.includes("/products/")},{pageType:"account",match:a=>a.includes("/account/")||a.endsWith("/account")},{pageType:"blog",match:a=>a.includes("/blog/")},{pageType:"cart",match:a=>a.includes("/cart/")||a.endsWith("/cart")},{pageType:"wishlist",match:(a,{wishlistUrl:t})=>a.includes(t)},{pageType:"page",match:a=>a.includes("/pages/")},{pageType:"home",match:a=>a.length<4}],m=class{constructor({wishlistUrl:t}){this.wishlistUrl=t}parse(t){for(let e of G)if(e.match(t,{wishlistUrl:this.wishlistUrl}))return{pageType:e.pageType};return{pageType:void 0}}};var g=class{constructor(t){var e;this.locale=this.decodeLocale((e=t.locale)!=null?e:{})}decodeHtmlEntities(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'")}decodeLocale(t){let e={};for(let s in t){e[s]={};for(let i in t[s])e[s][i]=this.decodeHtmlEntities(t[s][i])}return e}translate(t,e){var o;let[s,i]=t.split("."),r=(o=this.locale[s])==null?void 0:o[i];return r?e?Object.entries(e).reduce((n,[l,c])=>n.replace(new RegExp(`{{\\s*${l}\\s*}}`,"g"),c),r):r:`translation missing: ${t}`}};var d=class{constructor({rootUrl:t,wishlistUrl:e,locale:s}){this._rootUrl=t,this.route=new m({wishlistUrl:e}),this.observer=new u({routeUtil:this.route}),this.locale=new g({locale:s}),this.watch=this.observer.watch.bind(this.observer)}getPageType(t=window.location.pathname){return this.route.parse(t).pageType}getWishlistId(t){if(!t)return null;t instanceof URL&&(t=t.pathname);let e=t.replace(this._rootUrl,"/").split("/");return e.length===4?e.pop():"mine"}getProductHandle(t){var e;return t?(t instanceof URL&&(t=t.pathname),(e=t.split("/").pop())==null?void 0:e.split("?")[0]):null}getVariantId(t){return t?(t instanceof URL&&(t=t.pathname),new URLSearchParams(t.split("?")[1]).get("variant")):null}translate(t,e){return this.locale.translate(t,e)}createComponent(t,e){var i;let s=document.createElement(t);return e!=null&&e.dataset&&Object.entries(e==null?void 0:e.dataset).forEach(([r,o])=>{o&&(typeof o=="boolean"?s.dataset[r]="":typeof o=="object"?s.dataset[r]=JSON.stringify(o):s.dataset[r]=o)}),e!=null&&e.props&&Object.entries(e==null?void 0:e.props).forEach(([r,o])=>{s[r]=o}),(i=e==null?void 0:e.wrap)!=null&&i.name?this.createElement(e.wrap.name,e.wrap.props,s):s}createHeadlessComponent(t,e){var r;let s=e.host.element?e.host.element:e.host;if(!s)throw new Error("Headless host is undefined");e.dataset&&Object.entries(e.dataset).forEach(([o,n])=>{n&&(typeof n=="boolean"?s.dataset[o]="":typeof n=="object"?s.dataset[o]=JSON.stringify(n):s.dataset[o]=n)});let i=(r=window.headlessElements)==null?void 0:r.store.get(t);if(!i)throw new Error(`Headless element not found: ${t}`);return new i(s)}createElement(t,e={},...s){let i=Object.assign(document.createElement(t),e);return s&&i.append(...s),i}};var y=class{constructor(){this.dispatcher=document}publish(t){this.dispatcher.dispatchEvent(new CustomEvent(t.name,{detail:t,bubbles:!1,cancelable:!1}))}once(t,e){let s=i=>{this.dispatcher.removeEventListener(t,s),e(i)};this.subscribe(t,s)}subscribe(t,e){this.dispatcher.addEventListener(t,s=>{let i=s;e({name:i.type,data:i.detail.data})})}subscribeMany(t){return Object.entries(t).map(([e,s])=>this.subscribe(e,s))}};window.headlessElements||(window.headlessElements={store:new Map,define(a,t){var e;(e=window.headlessElements)==null||e.store.set(a,t)}});var q=class{constructor({dependencies:t=[],...e}){this.stylesLoaded=!1;this._loaded=!1;this.addToCart=t=>this.state.promise.addToCart(t);this.addAllToCart=t=>this.state.promise.addAllToCart(t);this.addWishlistItem=t=>this.state.promise.addWishlistItem(t);this.clearWishlist=()=>this.state.promise.clearWishlist();this.loadProductInfo=t=>this.state.promise.loadProductInfo(t);this.loadShopifyProduct=t=>this.state.promise.loadShopifyProduct(t);this.loadWishlist=t=>this.state.promise.loadWishlist(t);this.loadWishlistItem=t=>this.state.promise.loadWishlistItem(t);this.publishWishlistEvent=t=>this.state.promise.publishWishlistEvent(t);this.publishWishlistProductEvent=t=>this.state.promise.publishWishlistProductEvent(t);this.removeWishlistItem=t=>this.state.promise.removeWishlistItem(t);this.shareWishlist=t=>this.state.promise.shareWishlist(t);this.updateWishlistItem=t=>this.state.promise.updateWishlistItem(t);this.config=this.parseConfig(e),this.settings=this.parseSettings(e),this.routes=this.parseRoutes(),this.customer=this.config.customer.id?{id:this.config.customer.id,email:this.config.customer.email}:null,this.events=new y,this.theme=new d({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl,locale:this.config.locale});let{stylesheets:s,scripts:i}=t.reduce(({stylesheets:r,scripts:o},n)=>{let[l]=n.split("?");return l.endsWith(".css")?r.push(n):l.endsWith(".js")&&o.push(n),{stylesheets:r,scripts:o}},{stylesheets:[],scripts:[]});this.initStyles(s),this.initScripts(i),(this.hasSession||this.settings.general.appLoading==="EAGER")&&this.load()}get loaded(){return this._loaded}get state(){return w(this._state)}get apis(){return w(this._apis)}get utils(){return w(this._utils)}get hasSession(){return!!this.getSessionId()||!!this.customer}get isLoggedIn(){var t;return!!((t=this.customer)!=null&&t.id)}getSessionId(){let t=window.localStorage.getItem("wk_session_id");if(t)return t;let e=window.localStorage.getItem("appmate-session");if(e)try{let s=JSON.parse(e).state.sid;return this.setSessionId(s)}catch(s){console.error(s)}}setSessionId(t){var e;return window.localStorage.setItem("wk_session_id",t),(e=this._apis)==null||e.tracking.setSessionId(t),t}async load(){return this._loadPromise?this._loadPromise:this._loadPromise=(async()=>{let[{WishlistState:t},{ShopifyApi:e,WishlistApi:s,TrackingApi:i},{MoneyUtil:r,UrlUtil:o,ProductUtil:n}]=await Promise.all([import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/state.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/api.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/utils.js")]);this.initUtils({MoneyUtil:r,UrlUtil:o,ProductUtil:n}),this.initApis({WishlistApi:s,ShopifyApi:e,TrackingApi:i}),this.initState({WishlistState:t}),this.initUrlChangeEvents(),this.trackCurrentPage(),this.hasSession||(await this.state.promise.clearCache(),this.events.once("wk:app:init-sid",l=>{var c,h;(c=l.data)!=null&&c.sessionId&&this.setSessionId((h=l.data)==null?void 0:h.sessionId)})),this._loaded=!0,this.events.publish({name:"wk:app:load:success"})})()}initUtils({UrlUtil:t,MoneyUtil:e,ProductUtil:s}){let i=this.config.shop.domain,r=this.config.products.fallbackImage,o=this.config.shop.moneyFormat;this._utils={url:new t({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl,shopDomain:i,placeholderImageUrl:r,fileUrl:this.routes.fileUrl}),money:new e({moneyFormat:o,currencyRate:parseFloat(window.Shopify.currency.rate),activeCurrency:window.Shopify.currency.active}),product:new s}}initApis({WishlistApi:t,ShopifyApi:e,TrackingApi:s}){var i,r;this._apis={wishlist:new t({host:this.config.routes.apiHost,shop:window.Shopify.shop,customerId:(i=this.config.customer.id)!=null?i:void 0,sessionId:this.getSessionId(),trackingSource:this.theme.getPageType()}),shopify:new e({host:window.Shopify.routes.root.substring(0,window.Shopify.routes.root.length-1)}),tracking:new s({notifyHost:this.config.routes.apiHost,events:this.events,shop:window.Shopify.shop,customerId:(r=this.config.customer.id)!=null?r:void 0,sessionId:this.getSessionId(),utils:this.utils,theme:this.theme,settings:this.settings})}}initState({WishlistState:t}){this._state=new t({wishlistApi:this.apis.wishlist,shopifyApi:this.apis.shopify,settings:this.settings,events:this.events,utils:this.utils})}async initStyles(t){if(!(t!=null&&t.length)){this.onStylesLoaded();return}try{await Promise.all(t.map(e=>new Promise((s,i)=>{let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.onload=s,r.onerror=i,document.head.appendChild(r)}))),this.onStylesLoaded()}catch(e){console.warn(e),this.events.publish({name:"wk:app:load-styles:error"})}}async initScripts(t){if(!(t!=null&&t.length)){this.events.publish({name:"wk:app:load-scripts:success"});return}try{await Promise.all(t.map(e=>import(e))),this.events.publish({name:"wk:app:load-scripts:success"})}catch(e){console.warn(e),this.events.publish({name:"wk:app:load-scripts:error"})}}trackCurrentPage(){if(this.theme.getPageType()==="wishlist"){let e=this.theme.getWishlistId(window.location.pathname);e&&this.publishWishlistEvent({eventName:"wk:wishlist:page-view",wishlistId:e})}}onStylesLoaded(){this.stylesLoaded=!0,this.events.publish({name:"wk:app:load-styles:success"})}initUrlChangeEvents(){let t=history.replaceState,e=({productHandle:s,variantId:i})=>{this.events.publish({name:"wk:product:change-variant:success",data:{productHandle:s,variantId:i}})};history.replaceState=(...s)=>{let i=`${window.location.protocol}//${window.location.host}`,r=typeof s[2]=="string"?new URL(s[2],i):s[2],o=t.apply(history,s);if(!r)return o;let n=this.theme.getProductHandle(r),l=r.searchParams.get("variant");if(!n||!l)return o;e({productHandle:n,variantId:parseInt(l)})}}parseConfig({config:t,locale:e}){var s,i,r,o,n,l,c,h;return{customer:{id:t.customerId?t.customerId:null,email:(s=t.customerEmail)!=null?s:""},shop:{name:(i=t.shopName)!=null?i:"",domain:(r=t.shopDomain)!=null?r:"",permanentDomain:(o=t.shopPermanentDomain)!=null?o:"",currency:(n=t.shopCurrency)!=null?n:"",moneyFormat:(l=t.shopMoneyFormat)!=null?l:"",customerAccountsEnabled:t.shopCustomerAccountsEnabled?t.shopCustomerAccountsEnabled==="true":!1},routes:{apiHost:(c=t.apiHost)!=null?c:"https://api.appmate.io/v2",rootUrl:window.Shopify.routes.root,fileUrl:t.fileUrl},products:{fallbackImage:(h=t.productFallbackImage)!=null?h:"//cdn.shopify.com/s/files/1/0533/2089/files/placeholder-images-image_large.png?format=webp&v=1530129081"},locale:e}}parseSettings({settings:t}){var e,s,i,r,o,n,l,c,h,f,b,E,U,T,S,W,v,P,A,I,k,R,L,H,M,C,_,N,O,x,D,j,B,V,F;return{general:{appLoading:(s=(e=t==null?void 0:t.general)==null?void 0:e.appLoading)!=null?s:"LAZY",wishlistAccessMode:this.config.customer.id?"UNRESTRICTED":(r=(i=t==null?void 0:t.general)==null?void 0:i.wishlistAccessMode)!=null?r:"UNRESTRICTED",wishlistMode:(n=(o=t==null?void 0:t.general)==null?void 0:o.wishlistMode)!=null?n:"PRODUCT",wishlistPath:(c=(l=t==null?void 0:t.general)==null?void 0:l.wishlistPath)!=null?c:"/apps/wishlist"},wishlistPage:{addToCartMode:(f=(h=t==null?void 0:t.wishlistPage)==null?void 0:h.addToCartMode)!=null?f:"KEEP_IN_WISHLIST",buyButtonType:(E=(b=t==null?void 0:t.wishlistPage)==null?void 0:b.buyButtonType)!=null?E:"ADD_TO_CART",shareButtonType:(T=(U=t==null?void 0:t.wishlistPage)==null?void 0:U.shareButtonType)!=null?T:"WEB_SHARE",loginHintType:(W=(S=t==null?void 0:t.wishlistPage)==null?void 0:S.loginHintType)!=null?W:"CALLOUT",variantAutoSelectMode:(P=(v=t==null?void 0:t.wishlistPage)==null?void 0:v.variantAutoSelectMode)!=null?P:"NEVER",variantSelctorType:(I=(A=t==null?void 0:t.wishlistPage)==null?void 0:A.variantSelctorType)!=null?I:"DROPDOWNS"},integrations:{googleAnalytics:{enabled:(L=(R=(k=t.integrations)==null?void 0:k.googleAnalytics)==null?void 0:R.enabled)!=null?L:!1,tracker:(C=(M=(H=t.integrations)==null?void 0:H.googleAnalytics)==null?void 0:M.tracker)!=null?C:""},klaviyo:{enabled:(O=(N=(_=t.integrations)==null?void 0:_.klaviyo)==null?void 0:N.enabled)!=null?O:!1},metaPixel:{enabled:(j=(D=(x=t.integrations)==null?void 0:x.metaPixel)==null?void 0:D.enabled)!=null?j:!1},wishlistAnalytics:{enabled:(F=(V=(B=t.integrations)==null?void 0:B.metaPixel)==null?void 0:V.enabled)!=null?F:!0}},cache:{wishlist:{ttl:6e4},wishlistItem:{ttl:6e4},productInfo:{ttl:6e4},product:{ttl:3e4}}}}parseRoutes(){let t=this.config.routes.rootUrl;return{rootUrl:t,fileUrl:this.config.routes.fileUrl,wishlistUrl:t+this.settings.general.wishlistPath.split("/").filter(e=>!!e).join("/"),accountUrl:t+"account",accountLoginUrl:t+"account/login",accountLogoutUrl:t+"account/logout",accountRegisterUrl:t+"account/register",accountAddressesUrl:t+"account/addresses",collectionsUrl:t+"collections",allProductsCollectionUrl:t+"collections/all",searchUrl:t+"search",predictiveSearchUrl:t+"search/suggest",cartUrl:t+"cart",cartAddUrl:t+"cart/add",cartChangeUrl:t+"cart/change",cartClearUrl:t+"cart/clear",cartUpdateUrl:t+"cart/update",productRecommendationsUrl:t+"recommendations/products"}}},w=a=>{if(!a)throw new Error("Wishlist app not loaded.");return a};export{q as WishlistApp}; |
@@ -1,1 +0,1 @@ | ||
import{delayWhen as p,from as a,fromEvent as o,isObservable as u,map as f,of as h}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";import{filter as l,first as b,switchMap as v,tap as c}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";import{WishlistStateController as g}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/controllers.js";var d=class{constructor(t){this.connected=!1;this.cleanupMethods=[];this.eventPending=!1;this.firstConnect=!0;if(this.host=t,this.stateCtrl=new g(this),this.host.hasAttribute("wk-headless"))throw new Error("Headless component already initialised");this.host.setAttribute("wk-headless",""),this.initEvents(),this.connect(),this.firstConnect=!1}get app(){return this.stateCtrl.app}static get observedAttributes(){return["data-wishlist-id","data-wishlist-item-id","data-product-handle","data-product-id","data-variant-id"]}addController(t){}appReadyCallback(){!this.host.dataset.productHandle||this.app.events.subscribe("wk:product:change-variant:success",t=>{var i,n,e;if(this.host.dataset.productHandle===((i=t.data)==null?void 0:i.productHandle)&&((n=t.data)==null?void 0:n.variantId)){let r=this.productInfo?this.productInfo.wishlistItemId:void 0,s=this.productInfo?this.productInfo.variantId:void 0;r&&!s&&this.app.updateWishlistItem({wishlistItemId:r,changes:{variantId:(e=t.data)==null?void 0:e.variantId}}),this.host.dataset.variantId=t.data.variantId.toString(),this.connected&&this.initState()}})}async connect(){if(!this.connected){if(!this.app.stylesLoaded){o(document,"wk:app:load-styles:success").pipe(b()).subscribe(()=>this.connect());return}this.connected=!0,this.app.loaded?this.init():this.app.hasSession?(await this.app.load(),this.init()):(this.initFallbackState(),this.app.events.once("wk:app:load:success",()=>{this.init()}))}}getStateConfig(){return{}}init(){let{loading:t}=this.getStateConfig();t==="lazy"?(this.initFallbackState(),this.initObserver()):(this.initState(),this.appReadyCallback())}updated(){}setState(t){this.wishlist=t.wishlist,this.wishlistItem=t.wishlistItem,this.productInfo=t.productInfo,this.updated()}createRenderRoot(){return this}initState(){this.subscription&&this.subscription.unsubscribe(),this.subscription=this.stateCtrl.observe().subscribe(t=>{this.setState(t)})}initFallbackState(){let t=this.stateCtrl.getFallback();t&&this.setState(t)}initObserver(){var t;(t=this.observer)==null||t.disconnect(),this.observer=new IntersectionObserver(i=>this.handleIntersect(i),{root:null,rootMargin:"0px"}),this.host.setAttribute("wk-lazy",""),this.observer.observe(this.host)}handleIntersect([t]){var i;t.isIntersecting&&(this.host.removeAttribute("wk-lazy"),(i=this.observer)==null||i.disconnect(),this.initState(),this.appReadyCallback())}getEventConfig(){return{}}initEvents(){let t=this.getEventConfig();if(!t)return;let i=Object.entries(t).map(([n,e])=>{let[r,s]=n.split(/ (.*)/s);return this.subscribeToEvent({eventName:r,selector:s,handler:e})});this.cleanupMethods.push(()=>i.forEach(n=>n.unsubscribe()))}subscribeToEvent({eventName:t,handler:i,selector:n}){return o(this.host,t).pipe(c(e=>{this.eventPending&&e.preventDefault()}),l(()=>!this.eventPending),c(()=>{this.eventPending=!0}),f(e=>e.target instanceof HTMLElement?{event:e,target:n?e.target.closest(n):e.currentTarget}:{event:e,target:null}),l(({target:e})=>!!e),p(e=>this.app.hasSession?h(e):a(this.app.load())),v(({event:e,target:r})=>{let s=i.bind(this)(e,r);return u(s)?s:typeof(s==null?void 0:s.then)=="function"?a(s):h(s)})).subscribe(()=>{this.eventPending=!1})}};export{d as WishlistElementHeadless}; | ||
import{delayWhen as p,from as a,fromEvent as o,isObservable as u,map as f,of as h}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";import{filter as l,first as b,switchMap as v,tap as c}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";import{WishlistStateController as g}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/controllers.js";var d=class{constructor(t){this.connected=!1;this.cleanupMethods=[];this.eventPending=!1;this.firstConnect=!0;if(this.host=t,this.stateCtrl=new g(this),this.host.hasAttribute("wk-headless"))throw new Error("Headless component already initialised");this.host.setAttribute("wk-headless",""),this.initEvents(),this.connect(),this.firstConnect=!1}get app(){return this.stateCtrl.app}static get observedAttributes(){return["data-wishlist-id","data-wishlist-item-id","data-product-handle","data-product-id","data-variant-id"]}addController(t){}appReadyCallback(){this.host.dataset.productHandle&&this.app.events.subscribe("wk:product:change-variant:success",t=>{var i,n,e;if(this.host.dataset.productHandle===((i=t.data)==null?void 0:i.productHandle)&&((n=t.data)!=null&&n.variantId)){let r=this.productInfo?this.productInfo.wishlistItemId:void 0,s=this.productInfo?this.productInfo.variantId:void 0;r&&!s&&this.app.updateWishlistItem({wishlistItemId:r,changes:{variantId:(e=t.data)==null?void 0:e.variantId}}),this.host.dataset.variantId=t.data.variantId.toString(),this.connected&&this.initState()}})}async connect(){if(!this.connected){if(!this.app.stylesLoaded){o(document,"wk:app:load-styles:success").pipe(b()).subscribe(()=>this.connect());return}this.connected=!0,this.app.loaded?this.init():this.app.hasSession?(await this.app.load(),this.init()):(this.initFallbackState(),this.app.events.once("wk:app:load:success",()=>{this.init()}))}}getStateConfig(){return{}}init(){let{loading:t}=this.getStateConfig();t==="lazy"?(this.initFallbackState(),this.initObserver()):(this.initState(),this.appReadyCallback())}updated(){}setState(t){this.wishlist=t.wishlist,this.wishlistItem=t.wishlistItem,this.productInfo=t.productInfo,this.updated()}createRenderRoot(){return this}initState(){this.subscription&&this.subscription.unsubscribe(),this.subscription=this.stateCtrl.observe().subscribe(t=>{this.setState(t)})}initFallbackState(){let t=this.stateCtrl.getFallback();t&&this.setState(t)}initObserver(){var t;(t=this.observer)==null||t.disconnect(),this.observer=new IntersectionObserver(i=>this.handleIntersect(i),{root:null,rootMargin:"0px"}),this.host.setAttribute("wk-lazy",""),this.observer.observe(this.host)}handleIntersect([t]){var i;t.isIntersecting&&(this.host.removeAttribute("wk-lazy"),(i=this.observer)==null||i.disconnect(),this.initState(),this.appReadyCallback())}getEventConfig(){return{}}initEvents(){let t=this.getEventConfig();if(!t)return;let i=Object.entries(t).map(([n,e])=>{let[r,s]=n.split(/ (.*)/s);return this.subscribeToEvent({eventName:r,selector:s,handler:e})});this.cleanupMethods.push(()=>i.forEach(n=>n.unsubscribe()))}subscribeToEvent({eventName:t,handler:i,selector:n}){return o(this.host,t).pipe(c(e=>{this.eventPending&&e.preventDefault()}),l(()=>!this.eventPending),c(()=>{this.eventPending=!0}),f(e=>e.target instanceof HTMLElement?{event:e,target:n?e.target.closest(n):e.currentTarget}:{event:e,target:null}),l(({target:e})=>!!e),p(e=>this.app.hasSession?h(e):a(this.app.load())),v(({event:e,target:r})=>{let s=i.bind(this)(e,r);return u(s)?s:typeof(s==null?void 0:s.then)=="function"?a(s):h(s)})).subscribe(()=>{this.eventPending=!1})}};export{d as WishlistElementHeadless}; |
@@ -1,1 +0,1 @@ | ||
var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var c=(h,a,t,e)=>{for(var i=e>1?void 0:e?y(a,t):a,s=h.length-1,n;s>=0;s--)(n=h[s])&&(i=(e?n(a,t,i):n(i))||i);return e&&i&&m(a,t,i),i};import{delayWhen as v,from as p,fromEvent as d,isObservable as I,map as S,of as u}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";import{filter as f,first as C,switchMap as k,tap as b}from"https://cdn.jsdelivr.net/npm/rxjs@7.5.7/+esm";import{state as l}from"https://cdn.jsdelivr.net/npm/@lit/reactive-element@1.4.2/decorators/+esm";import{LitElement as w}from"https://cdn.jsdelivr.net/npm/lit-element@3.2.2/lit-element/+esm";import{unsafeHTML as g}from"https://cdn.jsdelivr.net/npm/lit-html@2.4.0/directives/unsafe-html.js/+esm";import{WishlistStateController as P}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.18.5/controllers.js";var o=class extends w{constructor(){super();this.connected=!1;this.cleanupMethods=[];this.eventPending=!1;this.firstConnect=!0;this.stateCtrl=new P(this)}get app(){return this.stateCtrl.app}static get observedAttributes(){return[...super.observedAttributes,"data-wishlist-id","data-wishlist-item-id","data-product-handle","data-product-id","data-variant-id"]}attributeChangedCallback(t,e,i){super.attributeChangedCallback(t,e,i),this.connected&&this.initState()}appReadyCallback(){!this.dataset.productHandle||this.app.events.subscribe("wk:product:change-variant:success",t=>{var e,i,s;if(this.dataset.productHandle===((e=t.data)==null?void 0:e.productHandle)&&((i=t.data)==null?void 0:i.variantId)){let n=this.productInfo?this.productInfo.wishlistItemId:void 0,r=this.productInfo?this.productInfo.variantId:void 0;n&&!r&&this.app.updateWishlistItem({wishlistItemId:n,changes:{variantId:(s=t.data)==null?void 0:s.variantId}}),this.dataset.variantId=t.data.variantId.toString()}})}async connect(){if(!this.connected){if(!this.app.stylesLoaded){d(document,"wk:app:load-styles:success").pipe(C()).subscribe(()=>this.connect());return}this.connected=!0,this.app.loaded?this.init():this.app.hasSession?(await this.app.load(),this.init()):(this.initFallbackState(),this.app.events.once("wk:app:load:success",()=>{this.init()}))}}getStateConfig(){return{}}getTranslation(t,e){if(!this.app.theme)return t;let i=this.app.theme.translate(t,e);return t.endsWith("_html")?g(i):i}formatMoney(t){return this.app.utils.money.formatMoney(t)}renderMoney(t){return g(this.app.utils.money.formatMoney(t))}getProductUrl(t,e){return this.app.utils.url.getVariantUrl(t.url,e==null?void 0:e.id)}getImageUrl(t,e,i){var s;return this.app.utils.url.getImageUrl((s=e==null?void 0:e.featured_image)!=null&&s.src?e:t,i)}init(){let{loading:t}=this.getStateConfig();t==="lazy"?(this.initFallbackState(),this.initObserver()):(this.initState(),this.appReadyCallback())}setState(t){this.wishlist=t.wishlist,this.wishlistItem=t.wishlistItem,this.productInfo=t.productInfo}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.innerHTML&&this.firstConnect&&(this.innerHTML=""),this.initEvents(),this.connect(),this.firstConnect=!1}disconnectedCallback(){var t,e;super.disconnectedCallback(),this.cleanupMethods.forEach(i=>i()),this.connected=!1,(t=this.subscription)==null||t.unsubscribe(),(e=this.observer)==null||e.disconnect()}shouldUpdate(t){return this.connected?super.shouldUpdate(t):!1}initState(){this.subscription&&this.subscription.unsubscribe(),this.subscription=this.stateCtrl.observe().subscribe(t=>{this.setState(t)})}initFallbackState(){let t=this.stateCtrl.getFallback();t&&this.setState(t)}initObserver(){var t,e;(t=this.observer)==null||t.disconnect(),this.observer=new IntersectionObserver(i=>this.handleIntersect(i),{root:null,rootMargin:"0px"}),this.setAttribute("wk-lazy",""),this.observer.observe((e=this.firstElementChild)!=null?e:this)}handleIntersect([t]){var e;t.isIntersecting&&(this.removeAttribute("wk-lazy"),(e=this.observer)==null||e.disconnect(),this.initState(),this.appReadyCallback())}getEventConfig(){return{}}initEvents(){let t=this.getEventConfig();if(!t)return;let e=Object.entries(t).map(([i,s])=>{let[n,r]=i.split(/ (.*)/s);return this.subscribeToEvent({eventName:n,selector:r,handler:s})});this.cleanupMethods.push(()=>e.forEach(i=>i.unsubscribe()))}subscribeToEvent({eventName:t,handler:e,selector:i}){return d(this,t).pipe(b(s=>{this.eventPending&&s.preventDefault()}),f(()=>!this.eventPending),b(()=>{this.eventPending=!0}),S(s=>s.target instanceof HTMLElement?{event:s,target:i?s.target.closest(i):s.currentTarget}:{event:s,target:null}),f(({target:s})=>!!s),v(s=>this.app.hasSession?u(s):p(this.app.load())),k(({event:s,target:n})=>{let r=e.bind(this)(s,n);return I(r)?r:typeof(r==null?void 0:r.then)=="function"?p(r):u(r)})).subscribe(()=>{this.eventPending=!1})}};c([l()],o.prototype,"wishlist",2),c([l()],o.prototype,"productInfo",2),c([l()],o.prototype,"wishlistItem",2);export{o as WishlistElement}; | ||
import{delayWhen as u,from as o,fromEvent as c,isObservable as f,map as b,of as l}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";import{filter as h,first as g,switchMap as m,tap as p}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";import{LitElement as y}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";import{unsafeHTML as d}from"https://cdn.jsdelivr.net/gh/lit/dist@2.6.0/all/lit-all.min.js";import{WishlistStateController as v}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.19.0/controllers.js";var a=class extends y{constructor(){super();this.connected=!1;this.cleanupMethods=[];this.eventPending=!1;this.firstConnect=!0;this.stateCtrl=new v(this)}get app(){return this.stateCtrl.app}static get observedAttributes(){return[...super.observedAttributes,"data-wishlist-id","data-wishlist-item-id","data-product-handle","data-product-id","data-variant-id"]}attributeChangedCallback(t,e,s){super.attributeChangedCallback(t,e,s),this.connected&&this.initState()}appReadyCallback(){this.dataset.productHandle&&this.app.events.subscribe("wk:product:change-variant:success",t=>{var e,s,i;if(this.dataset.productHandle===((e=t.data)==null?void 0:e.productHandle)&&((s=t.data)!=null&&s.variantId)){let n=this.productInfo?this.productInfo.wishlistItemId:void 0,r=this.productInfo?this.productInfo.variantId:void 0;n&&!r&&this.app.updateWishlistItem({wishlistItemId:n,changes:{variantId:(i=t.data)==null?void 0:i.variantId}}),this.dataset.variantId=t.data.variantId.toString()}})}async connect(){if(!this.connected){if(!this.app.stylesLoaded){c(document,"wk:app:load-styles:success").pipe(g()).subscribe(()=>this.connect());return}this.connected=!0,this.app.loaded?this.init():this.app.hasSession?(await this.app.load(),this.init()):(this.initFallbackState(),this.app.events.once("wk:app:load:success",()=>{this.init()}))}}getStateConfig(){return{}}getTranslation(t,e){if(!this.app.theme)return t;let s=this.app.theme.translate(t,e);return t.endsWith("_html")?d(s):s}formatMoney(t){return this.app.utils.money.formatMoney(t)}renderMoney(t){return d(this.app.utils.money.formatMoney(t))}getProductUrl(t,e){return this.app.utils.url.getVariantUrl(t.url,e==null?void 0:e.id)}getImageUrl(t,e,s){var i;return this.app.utils.url.getImageUrl((i=e==null?void 0:e.featured_image)!=null&&i.src?e:t,s)}init(){let{loading:t}=this.getStateConfig();t==="lazy"?(this.initFallbackState(),this.initObserver()):(this.initState(),this.appReadyCallback())}setState(t){this.wishlist=t.wishlist,this.wishlistItem=t.wishlistItem,this.productInfo=t.productInfo}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.innerHTML&&this.firstConnect&&(this.innerHTML=""),this.initEvents(),this.connect(),this.firstConnect=!1}disconnectedCallback(){var t,e;super.disconnectedCallback(),this.cleanupMethods.forEach(s=>s()),this.connected=!1,(t=this.subscription)==null||t.unsubscribe(),(e=this.observer)==null||e.disconnect()}shouldUpdate(t){return this.connected?super.shouldUpdate(t):!1}initState(){this.subscription&&this.subscription.unsubscribe(),this.subscription=this.stateCtrl.observe().subscribe(t=>{this.setState(t)})}initFallbackState(){let t=this.stateCtrl.getFallback();t&&this.setState(t)}initObserver(){var t,e;(t=this.observer)==null||t.disconnect(),this.observer=new IntersectionObserver(s=>this.handleIntersect(s),{root:null,rootMargin:"0px"}),this.setAttribute("wk-lazy",""),this.observer.observe((e=this.firstElementChild)!=null?e:this)}handleIntersect([t]){var e;t.isIntersecting&&(this.removeAttribute("wk-lazy"),(e=this.observer)==null||e.disconnect(),this.initState(),this.appReadyCallback())}getEventConfig(){return{}}initEvents(){let t=this.getEventConfig();if(!t)return;let e=Object.entries(t).map(([s,i])=>{let[n,r]=s.split(/ (.*)/s);return this.subscribeToEvent({eventName:n,selector:r,handler:i})});this.cleanupMethods.push(()=>e.forEach(s=>s.unsubscribe()))}subscribeToEvent({eventName:t,handler:e,selector:s}){return c(this,t).pipe(p(i=>{this.eventPending&&i.preventDefault()}),h(()=>!this.eventPending),p(()=>{this.eventPending=!0}),b(i=>i.target instanceof HTMLElement?{event:i,target:s?i.target.closest(s):i.currentTarget}:{event:i,target:null}),h(({target:i})=>!!i),u(i=>this.app.hasSession?l(i):o(this.app.load())),m(({event:i,target:n})=>{let r=e.bind(this)(i,n);return f(r)?r:typeof(r==null?void 0:r.then)=="function"?o(r):l(r)})).subscribe(()=>{this.eventPending=!1})}};a.properties={wishlist:{state:!0},productInfo:{state:!0},wishlistItem:{state:!0}};export{a as WishlistElement}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 7 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 13 instances in 1 package
33
181888
18
771