Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@appmate/wishlist

Package Overview
Dependencies
Maintainers
1
Versions
214
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appmate/wishlist - npm Package Compare versions

Comparing version 4.25.14 to 4.25.15

15

components/button.js

@@ -1,6 +0,11 @@

import{LitElement as h,html as r}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{FloatingUiController as u}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/controllers.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/components/counter.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/components/icon.js";var l=class extends h{constructor(){super(...arguments);this.text="";this.hint="";this.selected=!1;this.disabled=!1;this.showIcon=!1;this.showText=!1;this.iconUnstyled=!1;this.fullWidth=!1;this.alignSelf="center";this.alignContent="center";this.floatingUi=new u(this);this.getCounterFloating=()=>{var o,e,n,i;if(!((o=this.counter)!=null&&o.floating))return;let t=((n=(e=this.counter)==null?void 0:e.floating)==null?void 0:n.reference)==="icon"?(i=this.iconElement)!=null?i:this:this;return{...this.counter.floating,reference:t}}}get iconElement(){return this.querySelector(".wk-icon")}render(){var n,i,s,a;let t=(n=this.alignSelf)!=null?n:"center",o=(i=this.alignContent)!=null?i:"center",e=["wk-button",`wk-align-${t}`,`wk-align-content-${o}`,this.selected&&"wk-selected",this.fullWidth&&"wk-full-width"].filter(c=>!!c).join(" ");return this.href?r`
<a href=${this.href} aria-label=${(s=this.hint)!=null?s:""} class=${e}>
import{LitElement as h,html as o}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{FloatingUiController as u}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/controllers.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/components/counter.js";import"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/components/icon.js";var l=class extends h{constructor(){super(...arguments);this.text="";this.hint="";this.selected=!1;this.disabled=!1;this.showIcon=!1;this.showText=!1;this.iconUnstyled=!1;this.fullWidth=!1;this.alignSelf="center";this.alignContent="center";this.floatingUi=new u(this);this.getCounterFloating=()=>{var i,e,n,r;if(!((i=this.counter)!=null&&i.floating))return;let t=((n=(e=this.counter)==null?void 0:e.floating)==null?void 0:n.reference)==="icon"?(r=this.iconElement)!=null?r:this:this;return{...this.counter.floating,reference:t}}}get iconElement(){return this.querySelector(".wk-icon")}render(){var n,r,s,a;let t=(n=this.alignSelf)!=null?n:"center",i=(r=this.alignContent)!=null?r:"center",e=["wk-button",`wk-align-${t}`,`wk-align-content-${i}`,this.selected&&"wk-selected",this.fullWidth&&"wk-full-width"].filter(c=>!!c).join(" ");return this.href?o`
<a
href=${this.href}
aria-label=${(s=this.hint)!=null?s:""}
class=${e}
rel="noopener noreferrer nofollow"
>
${this.renderIcon()}${this.renderText()}${this.renderCounter()}
</a>
`:r`
`:o`
<button

@@ -14,3 +19,3 @@ type="button"

</button>
`}renderIcon(){if(!(!this.showIcon||!this.icon))return r`
`}renderIcon(){if(!(!this.showIcon||!this.icon))return o`
<wk-icon

@@ -21,3 +26,3 @@ class="wk-icon"

></wk-icon>
`}renderText(){if(this.showText)return r`<span class="wk-text">${this.text}</span>`}renderCounter(){var t;if(this.counter&&!(this.counter.hideWhenZero&&!this.counter.value))return r`
`}renderText(){if(this.showText)return o`<span class="wk-text">${this.text}</span>`}renderCounter(){var t;if(this.counter&&!(this.counter.hideWhenZero&&!this.counter.value))return o`
<wk-counter

@@ -24,0 +29,0 @@ .value=${(t=this.counter)==null?void 0:t.value}

@@ -1,1 +0,1 @@

import{LitElement as s,html as a}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{FloatingUiController as l}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/controllers.js";var t=class extends s{constructor(){super(...arguments);this.value=0;this.showNumber=!1;this.showBrackets=!1;this.floatingUi=new l(this)}render(){let e=this.showNumber?this.value:"",o=["wk-counter",this.showBrackets&&"wk-brackets",this.floating&&"wk-bubble",this.floating&&!this.showNumber&&"wk-dot"].filter(r=>!!r).join(" ");return a`<span class=${o}>${e}</span>`}createRenderRoot(){return this}};t.properties={value:{type:Number},floating:{type:Object},showNumber:{type:Boolean,attribute:"show-number"},showBrackets:{type:Boolean,attribute:"show-brackets"}};customElements.get("wk-counter")||customElements.define("wk-counter",t);export{t as Counter};
import{LitElement as s,html as a}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{FloatingUiController as l}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/controllers.js";var t=class extends s{constructor(){super(...arguments);this.value=0;this.showNumber=!1;this.showBrackets=!1;this.floatingUi=new l(this)}render(){let e=this.showNumber?this.value:"",o=["wk-counter",this.showBrackets&&"wk-brackets",this.floating&&"wk-bubble",this.floating&&!this.showNumber&&"wk-dot"].filter(r=>!!r).join(" ");return a`<span class=${o}>${e}</span>`}createRenderRoot(){return this}};t.properties={value:{type:Number},floating:{type:Object},showNumber:{type:Boolean,attribute:"show-number"},showBrackets:{type:Boolean,attribute:"show-brackets"}};customElements.get("wk-counter")||customElements.define("wk-counter",t);export{t as Counter};

@@ -1,2 +0,2 @@

import{LitElement as l,html as s}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{Icon as a}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/components/icon.js";var i=class extends l{constructor(){super();this.icon="caret"}get app(){if(!window.WishlistKing)throw new Error("Wishlist King SDK not initialized");return window.WishlistKing}render(){if(!this.option)return;let t=this.option,e=`options[${this.option.name}]`,n=`${this.app.utils.url.handlelize(this.id)}-select`;return s`
import{LitElement as l,html as s}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{Icon as a}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/components/icon.js";var i=class extends l{constructor(){super();this.icon="caret"}get app(){if(!window.WishlistKing)throw new Error("Wishlist King SDK not initialized");return window.WishlistKing}render(){if(!this.option)return;let t=this.option,e=`options[${this.option.name}]`,n=`${this.app.utils.url.handlelize(this.id)}-select`;return s`
<div class="wk-option-select">

@@ -3,0 +3,0 @@ <label class="wk-label" for=${n}>${t.name}</label>

@@ -1,2 +0,2 @@

import{LitElement as s,html as o}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{FloatingUiController as r}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/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`
import{LitElement as s,html as o}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{FloatingUiController as r}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/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}>

@@ -3,0 +3,0 @@ <div class="wk-text">${this.getText()}</div>

@@ -1,1 +0,1 @@

function j(e){return e.split("-")[1]}function st(e){return e==="y"?"height":"width"}function k(e){return e.split("-")[0]}function N(e){return["top","bottom"].includes(k(e))?"x":"y"}function yt(e,t,i){let{reference:n,floating:s}=e,a=n.x+n.width/2-s.width/2,r=n.y+n.height/2-s.height/2,o=N(t),c=st(o),f=n[c]/2-s[c]/2,u=o==="x",l;switch(k(t)){case"top":l={x:a,y:n.y-s.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-s.width,y:r};break;default:l={x:n.x,y:n.y}}switch(j(t)){case"start":l[o]-=f*(i&&u?-1:1);break;case"end":l[o]+=f*(i&&u?-1:1)}return l}var xt=async(e,t,i)=>{let{placement:n="bottom",strategy:s="absolute",middleware:a=[],platform:r}=i,o=a.filter(Boolean),c=await(r.isRTL==null?void 0:r.isRTL(t)),f=await r.getElementRects({reference:e,floating:t,strategy:s}),{x:u,y:l}=yt(f,n,c),d=n,h={},p=0;for(let m=0;m<o.length;m++){let{name:g,fn:y}=o[m],{x:w,y:x,data:E,reset:b}=await y({x:u,y:l,initialPlacement:n,placement:d,strategy:s,middlewareData:h,rects:f,platform:r,elements:{reference:e,floating:t}});u=w!=null?w:u,l=x!=null?x:l,h={...h,[g]:{...h[g],...E}},b&&p<=50&&(p++,typeof b=="object"&&(b.placement&&(d=b.placement),b.rects&&(f=b.rects===!0?await r.getElementRects({reference:e,floating:t,strategy:s}):b.rects),{x:u,y:l}=yt(f,d,c)),m=-1)}return{x:u,y:l,placement:d,strategy:s,middlewareData:h}};function vt(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 U(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:s,platform:a,rects:r,elements:o,strategy:c}=e,{boundary:f="clippingAncestors",rootBoundary:u="viewport",elementContext:l="floating",altBoundary:d=!1,padding:h=0}=t,p=vt(h),m=o[d?l==="floating"?"reference":"floating":l],g=U(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(o.floating)),boundary:f,rootBoundary:u,strategy:c})),y=l==="floating"?{...r.floating,x:n,y:s}:r.reference,w=await(a.getOffsetParent==null?void 0:a.getOffsetParent(o.floating)),x=await(a.isElement==null?void 0:a.isElement(w))&&await(a.getScale==null?void 0:a.getScale(w))||{x:1,y:1},E=U(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({rect:y,offsetParent:w,strategy:c}):y);return{top:(g.top-E.top+p.top)/x.y,bottom:(E.bottom-g.bottom+p.bottom)/x.y,left:(g.left-E.left+p.left)/x.x,right:(E.right-g.right+p.right)/x.x}}var kt=Math.min,zt=Math.max;function ot(e,t,i){return zt(e,kt(t,i))}var at=e=>({name:"arrow",options:e,async fn(t){let{element:i,padding:n=0}=e||{},{x:s,y:a,placement:r,rects:o,platform:c,elements:f}=t;if(i==null)return{};let u=vt(n),l={x:s,y:a},d=N(r),h=st(d),p=await c.getDimensions(i),m=d==="y",g=m?"top":"left",y=m?"bottom":"right",w=m?"clientHeight":"clientWidth",x=o.reference[h]+o.reference[d]-l[d]-o.floating[h],E=l[d]-o.reference[d],b=await(c.getOffsetParent==null?void 0:c.getOffsetParent(i)),W=b?b[w]:0;W&&await(c.isElement==null?void 0:c.isElement(b))||(W=f.floating[w]||o.floating[h]);let D=x/2-E/2,H=u[g],B=W-p[h]-u[y],A=W/2-p[h]/2+D,v=ot(H,A,B),I=j(r)!=null&&A!=v&&o.reference[h]/2-(A<H?u[g]:u[y])-p[h]/2<0;return{[d]:l[d]-(I?A<H?H-A:B-A:0),data:{[d]:v,centerOffset:A-v}}}}),Mt=["top","right","bottom","left"],Qt=Mt.reduce((e,t)=>e.concat(t,t+"-start",t+"-end"),[]),Bt={left:"right",right:"left",bottom:"top",top:"bottom"};function J(e){return e.replace(/left|right|bottom|top/g,t=>Bt[t])}function qt(e,t,i){i===void 0&&(i=!1);let n=j(e),s=N(e),a=st(s),r=s==="x"?n===(i?"end":"start")?"right":"left":n==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(r=J(r)),{main:r,cross:J(r)}}var Ut={start:"end",end:"start"};function nt(e){return e.replace(/start|end/g,t=>Ut[t])}var lt=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var i;let{placement:n,middlewareData:s,rects:a,initialPlacement:r,platform:o,elements:c}=t,{mainAxis:f=!0,crossAxis:u=!0,fallbackPlacements:l,fallbackStrategy:d="bestFit",fallbackAxisSideDirection:h="none",flipAlignment:p=!0,...m}=e,g=k(n),y=k(r)===r,w=await(o.isRTL==null?void 0:o.isRTL(c.floating)),x=l||(y||!p?[J(r)]:function(v){let I=J(v);return[nt(v),I,nt(I)]}(r));l||h==="none"||x.push(...function(v,I,V,L){let F=j(v),C=function(q,it,Dt){let gt=["left","right"],wt=["right","left"],Ht=["top","bottom"],Vt=["bottom","top"];switch(q){case"top":case"bottom":return Dt?it?wt:gt:it?gt:wt;case"left":case"right":return it?Ht:Vt;default:return[]}}(k(v),V==="start",L);return F&&(C=C.map(q=>q+"-"+F),I&&(C=C.concat(C.map(nt)))),C}(r,p,h,w));let E=[r,...x],b=await rt(t,m),W=[],D=((i=s.flip)==null?void 0:i.overflows)||[];if(f&&W.push(b[g]),u){let{main:v,cross:I}=qt(n,a,w);W.push(b[v],b[I])}if(D=[...D,{placement:n,overflows:W}],!W.every(v=>v<=0)){var H,B;let v=(((H=s.flip)==null?void 0:H.index)||0)+1,I=E[v];if(I)return{data:{index:v,overflows:D},reset:{placement:I}};let V=(B=D.filter(L=>L.overflows[0]<=0).sort((L,F)=>L.overflows[1]-F.overflows[1])[0])==null?void 0:B.placement;if(!V)switch(d){case"bestFit":{var A;let L=(A=D.map(F=>[F.placement,F.overflows.filter(C=>C>0).reduce((C,q)=>C+q,0)]).sort((F,C)=>F[1]-C[1])[0])==null?void 0:A[0];L&&(V=L);break}case"initialPlacement":V=r}if(n!==V)return{reset:{placement:V}}}return{}}}};var Q=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){let{x:i,y:n}=t,s=await async function(a,r){let{placement:o,platform:c,elements:f}=a,u=await(c.isRTL==null?void 0:c.isRTL(f.floating)),l=k(o),d=j(o),h=N(o)==="x",p=["left","top"].includes(l)?-1:1,m=u&&h?-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 d&&typeof x=="number"&&(w=d==="end"?-1*x:x),h?{x:w*m,y:y*p}:{x:y*p,y:w*m}}(t,e);return{x:i+s.x,y:n+s.y,data:s}}}};function jt(e){return e==="x"?"y":"x"}var ct=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){let{x:i,y:n,placement:s}=t,{mainAxis:a=!0,crossAxis:r=!1,limiter:o={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=N(k(s)),d=jt(l),h=f[l],p=f[d];if(a){let g=l==="y"?"bottom":"right";h=ot(h+u[l==="y"?"top":"left"],h,h-u[g])}if(r){let g=d==="y"?"bottom":"right";p=ot(p+u[d==="y"?"top":"left"],p,p-u[g])}let m=o.fn({...t,[l]:h,[d]: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 O(e){return S(e).getComputedStyle(e)}function Rt(e){return e instanceof S(e).Node}function _(e){return Rt(e)?(e.nodeName||"").toLowerCase():""}var G;function Pt(){if(G)return G;let e=navigator.userAgentData;return e&&Array.isArray(e.brands)?(G=e.brands.map(t=>t.brand+"/"+t.version).join(" "),G):navigator.userAgent}function P(e){return e instanceof S(e).HTMLElement}function R(e){return e instanceof S(e).Element}function bt(e){return typeof ShadowRoot=="undefined"?!1:e instanceof S(e).ShadowRoot||e instanceof ShadowRoot}function tt(e){let{overflow:t,overflowX:i,overflowY:n,display:s}=O(e);return/auto|scroll|overlay|hidden|clip/.test(t+n+i)&&!["inline","contents"].includes(s)}function Nt(e){return["table","td","th"].includes(_(e))}function ft(e){let t=/firefox/i.test(Pt()),i=O(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(s=>i.willChange.includes(s))||["paint","layout","strict","content"].some(s=>{let a=i.contain;return a!=null&&a.includes(s)})}function ht(){return/^((?!chrome|android).)*safari/i.test(Pt())}function ut(e){return["html","body","#document"].includes(_(e))}var Et=Math.min,$=Math.max,Z=Math.round;function At(e){let t=O(e),i=parseFloat(t.width),n=parseFloat(t.height),s=P(e),a=s?e.offsetWidth:i,r=s?e.offsetHeight:n,o=Z(i)!==a||Z(n)!==r;return o&&(i=a,n=r),{width:i,height:n,fallback:o}}function Ot(e){return R(e)?e:e.contextElement}var Wt={x:1,y:1};function M(e){let t=Ot(e);if(!P(t))return Wt;let i=t.getBoundingClientRect(),{width:n,height:s,fallback:a}=At(t),r=(a?Z(i.width):i.width)/n,o=(a?Z(i.height):i.height)/s;return r&&Number.isFinite(r)||(r=1),o&&Number.isFinite(o)||(o=1),{x:r,y:o}}function z(e,t,i,n){var s,a;t===void 0&&(t=!1),i===void 0&&(i=!1);let r=e.getBoundingClientRect(),o=Ot(e),c=Wt;t&&(n?R(n)&&(c=M(n)):c=M(e));let f=o?S(o):window,u=ht()&&i,l=(r.left+(u&&((s=f.visualViewport)==null?void 0:s.offsetLeft)||0))/c.x,d=(r.top+(u&&((a=f.visualViewport)==null?void 0:a.offsetTop)||0))/c.y,h=r.width/c.x,p=r.height/c.y;if(o){let m=S(o),g=n&&R(n)?S(n):n,y=m.frameElement;for(;y&&n&&g!==m;){let w=M(y),x=y.getBoundingClientRect(),E=getComputedStyle(y);x.x+=(y.clientLeft+parseFloat(E.paddingLeft))*w.x,x.y+=(y.clientTop+parseFloat(E.paddingTop))*w.y,l*=w.x,d*=w.y,h*=w.x,p*=w.y,l+=x.x,d+=x.y,y=S(y).frameElement}}return U({width:h,height:p,x:l,y:d})}function T(e){return((Rt(e)?e.ownerDocument:e.document)||window.document).documentElement}function et(e){return R(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Ft(e){return z(T(e)).left+et(e).scrollLeft}function X(e){if(_(e)==="html")return e;let t=e.assignedSlot||e.parentNode||bt(e)&&e.host||T(e);return bt(t)?t.host:t}function Lt(e){let t=X(e);return ut(t)?t.ownerDocument.body:P(t)&&tt(t)?t:Lt(t)}function K(e,t){var i;t===void 0&&(t=[]);let n=Lt(e),s=n===((i=e.ownerDocument)==null?void 0:i.body),a=S(n);return s?t.concat(a,a.visualViewport||[],tt(n)?n:[]):t.concat(n,K(n))}function St(e,t,i){let n;if(t==="viewport")n=function(r,o){let c=S(r),f=T(r),u=c.visualViewport,l=f.clientWidth,d=f.clientHeight,h=0,p=0;if(u){l=u.width,d=u.height;let m=ht();(!m||m&&o==="fixed")&&(h=u.offsetLeft,p=u.offsetTop)}return{width:l,height:d,x:h,y:p}}(e,i);else if(t==="document")n=function(r){let o=T(r),c=et(r),f=r.ownerDocument.body,u=$(o.scrollWidth,o.clientWidth,f.scrollWidth,f.clientWidth),l=$(o.scrollHeight,o.clientHeight,f.scrollHeight,f.clientHeight),d=-c.scrollLeft+Ft(r),h=-c.scrollTop;return O(f).direction==="rtl"&&(d+=$(o.clientWidth,f.clientWidth)-u),{width:u,height:l,x:d,y:h}}(T(e));else if(R(t))n=function(r,o){let c=z(r,!0,o==="fixed"),f=c.top+r.clientTop,u=c.left+r.clientLeft,l=P(r)?M(r):{x:1,y:1};return{width:r.clientWidth*l.x,height:r.clientHeight*l.y,x:u*l.x,y:f*l.y}}(t,i);else{let r={...t};if(ht()){var s,a;let o=S(e);r.x-=((s=o.visualViewport)==null?void 0:s.offsetLeft)||0,r.y-=((a=o.visualViewport)==null?void 0:a.offsetTop)||0}n=r}return U(n)}function Ct(e,t){return P(e)&&O(e).position!=="fixed"?t?t(e):e.offsetParent:null}function It(e,t){let i=S(e);if(!P(e))return i;let n=Ct(e,t);for(;n&&Nt(n)&&O(n).position==="static";)n=Ct(n,t);return n&&(_(n)==="html"||_(n)==="body"&&O(n).position==="static"&&!ft(n))?i:n||function(s){let a=X(s);for(;P(a)&&!ut(a);){if(ft(a))return a;a=X(a)}return null}(e)||i}function $t(e,t,i){let n=P(t),s=T(t),a=z(e,!0,i==="fixed",t),r={scrollLeft:0,scrollTop:0},o={x:0,y:0};if(n||!n&&i!=="fixed")if((_(t)!=="body"||tt(s))&&(r=et(t)),P(t)){let c=z(t,!0);o.x=c.x+t.clientLeft,o.y=c.y+t.clientTop}else s&&(o.x=Ft(s));return{x:a.left+r.scrollLeft-o.x,y:a.top+r.scrollTop-o.y,width:a.width,height:a.height}}var Kt={getClippingRect:function(e){let{element:t,boundary:i,rootBoundary:n,strategy:s}=e,a=i==="clippingAncestors"?function(f,u){let l=u.get(f);if(l)return l;let d=K(f).filter(g=>R(g)&&_(g)!=="body"),h=null,p=O(f).position==="fixed",m=p?X(f):f;for(;R(m)&&!ut(m);){let g=O(m),y=ft(m);g.position==="fixed"&&(h=null),(p?y||h:y||g.position!=="static"||!h||!["absolute","fixed"].includes(h.position))?h=g:d=d.filter(w=>w!==m),m=X(m)}return u.set(f,d),d}(t,this._c):[].concat(i),r=[...a,n],o=r[0],c=r.reduce((f,u)=>{let l=St(t,u,s);return f.top=$(l.top,f.top),f.right=Et(l.right,f.right),f.bottom=Et(l.bottom,f.bottom),f.left=$(l.left,f.left),f},St(t,o,s));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,s=P(i),a=T(i);if(i===a)return t;let r={scrollLeft:0,scrollTop:0},o={x:1,y:1},c={x:0,y:0};if((s||!s&&n!=="fixed")&&((_(i)!=="body"||tt(a))&&(r=et(i)),P(i))){let f=z(i);o=M(i),c.x=f.x+i.clientLeft,c.y=f.y+i.clientTop}return{width:t.width*o.x,height:t.height*o.y,x:t.x*o.x-r.scrollLeft*o.x+c.x,y:t.y*o.y-r.scrollTop*o.y+c.y}},isElement:R,getDimensions:function(e){return At(e)},getOffsetParent:It,getDocumentElement:T,getScale:M,async getElementRects(e){let{reference:t,floating:i,strategy:n}=e,s=this.getOffsetParent||It,a=this.getDimensions;return{reference:$t(t,await s(i),n),floating:{x:0,y:0,...await a(i)}}},getClientRects:e=>Array.from(e.getClientRects()),isRTL:e=>O(e).direction==="rtl"};function Tt(e,t,i,n){n===void 0&&(n={});let{ancestorScroll:s=!0,ancestorResize:a=!0,elementResize:r=!0,animationFrame:o=!1}=n,c=s&&!o,f=c||a?[...R(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;r&&(l=new ResizeObserver(()=>{i()}),R(e)&&!o&&l.observe(e),R(e)||!e.contextElement||o||l.observe(e.contextElement),l.observe(t));let d=o?z(e):null;return o&&function h(){let p=z(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,o&&cancelAnimationFrame(u)}}var _t=(e,t,i)=>{let n=new Map,s={platform:Kt,...i},a={...s.platform,_c:n};return xt(e,t,{...s,platform:a})};var dt=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.host.floating&&!this._floating&&this.float(this.host.floating),this._floating&&this.updatePosition()}hostResized(){this._floating&&this.updatePosition()}float(t){var c;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:s=!1,shift:a=!1,animationFrame:r=!1}=this._settings,o=this.getOffsetSetting();Object.assign(this.host.style,{position:(c=i.strategy)!=null?c:"absolute",top:"0",left:"0",transition:"none",transform:"translate3d(0,0,0)"}),i.inset&&!n?this._middleware.push(Q(({rects:f,placement:u})=>{var l,d,h,p,m,g;return u.includes("top")||u.includes("bottom")?{mainAxis:-f.floating.height-((l=o==null?void 0:o.mainAxis)!=null?l:0),crossAxis:(d=o==null?void 0:o.crossAxis)!=null?d:0,alignmentAxis:(h=o==null?void 0:o.alignmentAxis)!=null?h:0}:{mainAxis:-f.floating.width-((p=o==null?void 0:o.mainAxis)!=null?p:0),crossAxis:(m=o==null?void 0:o.crossAxis)!=null?m:0,alignmentAxis:(g=o==null?void 0:o.alignmentAxis)!=null?g:0}})):o&&this._middleware.push(Q(o)),s&&this._middleware.push(lt()),a&&this._middleware.push(ct()),n&&(this.arrowEl=document.createElement("div"),this.arrowEl.classList.add("wk-arrow"),this._middleware.push(at({element:this.arrowEl}))),this.cleanupAutoUpdate=Tt(this._reference,this.host,()=>{this.updatePosition()},{animationFrame:r}),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,s;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),(s=this._resizeObserver)==null||s.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:{};_t(this._reference,this.host,{middleware:this._middleware,strategy:t,placement:i}).then(({x:s,y:a,placement:r,middlewareData:o})=>{if(o.arrow&&this.arrowEl){let{x:c,y:f}=o.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(s)}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,s;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:(s=(n=window.visualViewport)==null?void 0:n.height)!=null?s:0}}}}};var pt=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 s=this.host.app.utils.product.getVariantOptions({variant:n});this.updateFormState({options:s,autoSelect:i})}updateFormState({options:t,change:i,autoSelect:n=!1}){if(!this.product)throw new Error("Product not set");let{hasSelection:s,optionsWithValues:a,selectedOptions:r,selectedVariant:o,hasOnlyDefaultVariant:c}=this.host.app.utils.product.getFormState({product:this.product,options:t,change:i,autoSelect:n});this.hasSelection=s,this.optionsWithValues=a,this.selectedOptions=r,this.selectedVariant=o,this.hasOnlyDefaultVariant=c,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,quantity:n,sectionsToRender:s,sectionsUrl:a="/"}){if(!this.selectedVariant)throw new Error("No variant selected");let r=this.host.querySelector("form");if(!r)throw new Error("Form not found");return this.submitting=!0,this.host.app.addToCart({wishlistId:t,wishlistItemId:i,variantId:this.selectedVariant.id,quantity:n!=null?n:this.host.app.utils.product.getFormQuantity({form:r}),sectionsToRender:s,sectionsUrl:a}).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 Xt,distinctUntilChanged as Yt,map as Y,of as Jt}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var mt=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),cart:t.cart}}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:s,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(Y(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(Y(s=>({productInfo:s}))))}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(Y(s=>({wishlistItem:s}))))}return this.stateConfig.cart&&t.push(this.app.state.observeShopifyCart().pipe(Y(i=>({cart:i})))),t.length||t.push(Jt({})),Xt(t).pipe(Y(i=>i.reduce((n,s)=>s.wishlist?{...n,wishlist:s.wishlist}:s.wishlistItem?{...n,wishlistItem:s.wishlistItem}:s.productInfo?{...n,productInfo:s.productInfo}:s.cart?{...n,cart:s.cart}:n,{})),Yt((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{dt as FloatingUiController,pt as ProductFormController,mt as WishlistStateController};
var G=Math.min,yt=Math.max;var zt={left:"right",right:"left",bottom:"top",top:"bottom"},Bt={start:"end",end:"start"};function Z(e,t,i){return yt(e,G(t,i))}function D(e,t){return typeof e=="function"?e(t):e}function W(e){return e.split("-")[0]}function k(e){return e.split("-")[1]}function lt(e){return e==="x"?"y":"x"}function tt(e){return e==="y"?"height":"width"}function N(e){return["top","bottom"].includes(W(e))?"y":"x"}function et(e){return lt(N(e))}function vt(e,t,i){i===void 0&&(i=!1);let n=k(e),o=et(e),s=tt(o),r=o==="x"?n===(i?"end":"start")?"right":"left":n==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(r=Y(r)),[r,Y(r)]}function bt(e){let t=Y(e);return[Q(e),t,Q(t)]}function Q(e){return e.replace(/start|end/g,t=>Bt[t])}function jt(e,t,i){let n=["left","right"],o=["right","left"],s=["top","bottom"],r=["bottom","top"];switch(e){case"top":case"bottom":return i?t?o:n:t?n:o;case"left":case"right":return t?s:r;default:return[]}}function St(e,t,i,n){let o=k(e),s=jt(W(e),i==="start",n);return o&&(s=s.map(r=>r+"-"+o),t&&(s=s.concat(s.map(Q)))),s}function Y(e){return e.replace(/left|right|bottom|top/g,t=>zt[t])}function qt(e){return{top:0,right:0,bottom:0,left:0,...e}}function at(e){return typeof e!="number"?qt(e):{top:e,right:e,bottom:e,left:e}}function H(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}function At(e,t,i){let{reference:n,floating:o}=e,s=N(t),r=et(t),l=tt(r),h=W(t),a=s==="y",u=n.x+n.width/2-o.width/2,c=n.y+n.height/2-o.height/2,d=n[l]/2-o[l]/2,f;switch(h){case"top":f={x:u,y:n.y-o.height};break;case"bottom":f={x:u,y:n.y+n.height};break;case"right":f={x:n.x+n.width,y:c};break;case"left":f={x:n.x-o.width,y:c};break;default:f={x:n.x,y:n.y}}switch(k(t)){case"start":f[r]-=d*(i&&a?-1:1);break;case"end":f[r]+=d*(i&&a?-1:1);break}return f}var Ct=async(e,t,i)=>{let{placement:n="bottom",strategy:o="absolute",middleware:s=[],platform:r}=i,l=s.filter(Boolean),h=await(r.isRTL==null?void 0:r.isRTL(t)),a=await r.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:c}=At(a,n,h),d=n,f={},m=0;for(let p=0;p<l.length;p++){let{name:g,fn:w}=l[p],{x,y,data:b,reset:v}=await w({x:u,y:c,initialPlacement:n,placement:d,strategy:o,middlewareData:f,rects:a,platform:r,elements:{reference:e,floating:t}});if(u=x!=null?x:u,c=y!=null?y:c,f={...f,[g]:{...f[g],...b}},v&&m<=50){m++,typeof v=="object"&&(v.placement&&(d=v.placement),v.rects&&(a=v.rects===!0?await r.getElementRects({reference:e,floating:t,strategy:o}):v.rects),{x:u,y:c}=At(a,d,h)),p=-1;continue}}return{x:u,y:c,placement:d,strategy:o,middlewareData:f}};async function ct(e,t){var i;t===void 0&&(t={});let{x:n,y:o,platform:s,rects:r,elements:l,strategy:h}=e,{boundary:a="clippingAncestors",rootBoundary:u="viewport",elementContext:c="floating",altBoundary:d=!1,padding:f=0}=D(t,e),m=at(f),g=l[d?c==="floating"?"reference":"floating":c],w=H(await s.getClippingRect({element:(i=await(s.isElement==null?void 0:s.isElement(g)))==null||i?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:a,rootBoundary:u,strategy:h})),x=c==="floating"?{...r.floating,x:n,y:o}:r.reference,y=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),b=await(s.isElement==null?void 0:s.isElement(y))?await(s.getScale==null?void 0:s.getScale(y))||{x:1,y:1}:{x:1,y:1},v=H(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({rect:x,offsetParent:y,strategy:h}):x);return{top:(w.top-v.top+m.top)/b.y,bottom:(v.bottom-w.bottom+m.bottom)/b.y,left:(w.left-v.left+m.left)/b.x,right:(v.right-w.right+m.right)/b.x}}var ft=e=>({name:"arrow",options:e,async fn(t){let{x:i,y:n,placement:o,rects:s,platform:r,elements:l}=t,{element:h,padding:a=0}=D(e,t)||{};if(h==null)return{};let u=at(a),c={x:i,y:n},d=et(o),f=tt(d),m=await r.getDimensions(h),p=d==="y",g=p?"top":"left",w=p?"bottom":"right",x=p?"clientHeight":"clientWidth",y=s.reference[f]+s.reference[d]-c[d]-s.floating[f],b=c[d]-s.reference[d],v=await(r.getOffsetParent==null?void 0:r.getOffsetParent(h)),O=v?v[x]:0;(!O||!await(r.isElement==null?void 0:r.isElement(v)))&&(O=l.floating[x]||s.floating[f]);let V=y/2-b/2,B=O/2-m[f]/2-1,j=G(u[g],B),q=G(u[w],B),C=j,U=O-m[f]-q,S=O/2-m[f]/2+V,I=Z(C,S,U),F=k(o)!=null&&S!=I&&s.reference[f]/2-(S<C?j:q)-m[f]/2<0?S<C?C-S:U-S:0;return{[d]:c[d]-F,data:{[d]:I,centerOffset:S-I+F}}}});var ht=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var i;let{placement:n,middlewareData:o,rects:s,initialPlacement:r,platform:l,elements:h}=t,{mainAxis:a=!0,crossAxis:u=!0,fallbackPlacements:c,fallbackStrategy:d="bestFit",fallbackAxisSideDirection:f="none",flipAlignment:m=!0,...p}=D(e,t),g=W(n),w=W(r)===r,x=await(l.isRTL==null?void 0:l.isRTL(h.floating)),y=c||(w||!m?[Y(r)]:bt(r));!c&&f!=="none"&&y.push(...St(r,m,f,x));let b=[r,...y],v=await ct(t,p),O=[],V=((i=o.flip)==null?void 0:i.overflows)||[];if(a&&O.push(v[g]),u){let C=vt(n,s,x);O.push(v[C[0]],v[C[1]])}if(V=[...V,{placement:n,overflows:O}],!O.every(C=>C<=0)){var B,j;let C=(((B=o.flip)==null?void 0:B.index)||0)+1,U=b[C];if(U)return{data:{index:C,overflows:V},reset:{placement:U}};let S=(j=V.filter(I=>I.overflows[0]<=0).sort((I,_)=>I.overflows[1]-_.overflows[1])[0])==null?void 0:j.placement;if(!S)switch(d){case"bestFit":{var q;let I=(q=V.map(_=>[_.placement,_.overflows.filter(F=>F>0).reduce((F,kt)=>F+kt,0)]).sort((_,F)=>_[1]-F[1])[0])==null?void 0:q[0];I&&(S=I);break}case"initialPlacement":S=r;break}if(n!==S)return{reset:{placement:S}}}return{}}}};async function Ut(e,t){let{placement:i,platform:n,elements:o}=e,s=await(n.isRTL==null?void 0:n.isRTL(o.floating)),r=W(i),l=k(i),h=N(i)==="y",a=["left","top"].includes(r)?-1:1,u=s&&h?-1:1,c=D(t,e),{mainAxis:d,crossAxis:f,alignmentAxis:m}=typeof c=="number"?{mainAxis:c,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...c};return l&&typeof m=="number"&&(f=l==="end"?m*-1:m),h?{x:f*u,y:d*a}:{x:d*a,y:f*u}}var it=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){let{x:i,y:n}=t,o=await Ut(t,e);return{x:i+o.x,y:n+o.y,data:o}}}},dt=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){let{x:i,y:n,placement:o}=t,{mainAxis:s=!0,crossAxis:r=!1,limiter:l={fn:g=>{let{x:w,y:x}=g;return{x:w,y:x}}},...h}=D(e,t),a={x:i,y:n},u=await ct(t,h),c=N(W(o)),d=lt(c),f=a[d],m=a[c];if(s){let g=d==="y"?"top":"left",w=d==="y"?"bottom":"right",x=f+u[g],y=f-u[w];f=Z(x,f,y)}if(r){let g=c==="y"?"top":"left",w=c==="y"?"bottom":"right",x=m+u[g],y=m-u[w];m=Z(x,m,y)}let p=l.fn({...t,[d]:f,[c]:m});return{...p,data:{x:p.x-i,y:p.y-n}}}}};function A(e){var t;return((t=e.ownerDocument)==null?void 0:t.defaultView)||window}function R(e){return A(e).getComputedStyle(e)}function Ft(e){return e instanceof A(e).Node}function T(e){return Ft(e)?(e.nodeName||"").toLowerCase():""}var nt;function Wt(){if(nt)return nt;let e=navigator.userAgentData;return e&&Array.isArray(e.brands)?(nt=e.brands.map(t=>t.brand+"/"+t.version).join(" "),nt):navigator.userAgent}function E(e){return e instanceof A(e).HTMLElement}function P(e){return e instanceof A(e).Element}function Pt(e){return typeof ShadowRoot=="undefined"?!1:e instanceof A(e).ShadowRoot||e instanceof ShadowRoot}function st(e){let{overflow:t,overflowX:i,overflowY:n,display:o}=R(e);return/auto|scroll|overlay|hidden|clip/.test(t+n+i)&&!["inline","contents"].includes(o)}function Yt(e){return["table","td","th"].includes(T(e))}function ut(e){let t=/firefox/i.test(Wt()),i=R(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 s=i.contain;return s!=null&&s.includes(o)})}function mt(){return/^((?!chrome|android).)*safari/i.test(Wt())}function pt(e){return["html","body","#document"].includes(T(e))}var Et=Math.min,X=Math.max,ot=Math.round;function Lt(e){let t=R(e),i=parseFloat(t.width),n=parseFloat(t.height),o=E(e),s=o?e.offsetWidth:i,r=o?e.offsetHeight:n,l=ot(i)!==s||ot(n)!==r;return l&&(i=s,n=r),{width:i,height:n,fallback:l}}function Tt(e){return P(e)?e:e.contextElement}var Vt={x:1,y:1};function z(e){let t=Tt(e);if(!E(t))return Vt;let i=t.getBoundingClientRect(),{width:n,height:o,fallback:s}=Lt(t),r=(s?ot(i.width):i.width)/n,l=(s?ot(i.height):i.height)/o;return r&&Number.isFinite(r)||(r=1),l&&Number.isFinite(l)||(l=1),{x:r,y:l}}function M(e,t,i,n){var o,s;t===void 0&&(t=!1),i===void 0&&(i=!1);let r=e.getBoundingClientRect(),l=Tt(e),h=Vt;t&&(n?P(n)&&(h=z(n)):h=z(e));let a=l?A(l):window,u=mt()&&i,c=(r.left+(u&&((o=a.visualViewport)==null?void 0:o.offsetLeft)||0))/h.x,d=(r.top+(u&&((s=a.visualViewport)==null?void 0:s.offsetTop)||0))/h.y,f=r.width/h.x,m=r.height/h.y;if(l){let p=A(l),g=n&&P(n)?A(n):n,w=p.frameElement;for(;w&&n&&g!==p;){let x=z(w),y=w.getBoundingClientRect(),b=getComputedStyle(w);y.x+=(w.clientLeft+parseFloat(b.paddingLeft))*x.x,y.y+=(w.clientTop+parseFloat(b.paddingTop))*x.y,c*=x.x,d*=x.y,f*=x.x,m*=x.y,c+=y.x,d+=y.y,w=A(w).frameElement}}return H({width:f,height:m,x:c,y:d})}function L(e){return((Ft(e)?e.ownerDocument:e.document)||window.document).documentElement}function rt(e){return P(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function _t(e){return M(L(e)).left+rt(e).scrollLeft}function K(e){if(T(e)==="html")return e;let t=e.assignedSlot||e.parentNode||Pt(e)&&e.host||L(e);return Pt(t)?t.host:t}function Ht(e){let t=K(e);return pt(t)?t.ownerDocument.body:E(t)&&st(t)?t:Ht(t)}function $(e,t){var i;t===void 0&&(t=[]);let n=Ht(e),o=n===((i=e.ownerDocument)==null?void 0:i.body),s=A(n);return o?t.concat(s,s.visualViewport||[],st(n)?n:[]):t.concat(n,$(n))}function Ot(e,t,i){let n;if(t==="viewport")n=function(r,l){let h=A(r),a=L(r),u=h.visualViewport,c=a.clientWidth,d=a.clientHeight,f=0,m=0;if(u){c=u.width,d=u.height;let p=mt();(!p||p&&l==="fixed")&&(f=u.offsetLeft,m=u.offsetTop)}return{width:c,height:d,x:f,y:m}}(e,i);else if(t==="document")n=function(r){let l=L(r),h=rt(r),a=r.ownerDocument.body,u=X(l.scrollWidth,l.clientWidth,a.scrollWidth,a.clientWidth),c=X(l.scrollHeight,l.clientHeight,a.scrollHeight,a.clientHeight),d=-h.scrollLeft+_t(r),f=-h.scrollTop;return R(a).direction==="rtl"&&(d+=X(l.clientWidth,a.clientWidth)-u),{width:u,height:c,x:d,y:f}}(L(e));else if(P(t))n=function(r,l){let h=M(r,!0,l==="fixed"),a=h.top+r.clientTop,u=h.left+r.clientLeft,c=E(r)?z(r):{x:1,y:1};return{width:r.clientWidth*c.x,height:r.clientHeight*c.y,x:u*c.x,y:a*c.y}}(t,i);else{let r={...t};if(mt()){var o,s;let l=A(e);r.x-=((o=l.visualViewport)==null?void 0:o.offsetLeft)||0,r.y-=((s=l.visualViewport)==null?void 0:s.offsetTop)||0}n=r}return H(n)}function It(e,t){return E(e)&&R(e).position!=="fixed"?t?t(e):e.offsetParent:null}function Rt(e,t){let i=A(e);if(!E(e))return i;let n=It(e,t);for(;n&&Yt(n)&&R(n).position==="static";)n=It(n,t);return n&&(T(n)==="html"||T(n)==="body"&&R(n).position==="static"&&!ut(n))?i:n||function(o){let s=K(o);for(;E(s)&&!pt(s);){if(ut(s))return s;s=K(s)}return null}(e)||i}function Nt(e,t,i){let n=E(t),o=L(t),s=M(e,!0,i==="fixed",t),r={scrollLeft:0,scrollTop:0},l={x:0,y:0};if(n||!n&&i!=="fixed")if((T(t)!=="body"||st(o))&&(r=rt(t)),E(t)){let h=M(t,!0);l.x=h.x+t.clientLeft,l.y=h.y+t.clientTop}else o&&(l.x=_t(o));return{x:s.left+r.scrollLeft-l.x,y:s.top+r.scrollTop-l.y,width:s.width,height:s.height}}var Xt={getClippingRect:function(e){let{element:t,boundary:i,rootBoundary:n,strategy:o}=e,s=i==="clippingAncestors"?function(a,u){let c=u.get(a);if(c)return c;let d=$(a).filter(g=>P(g)&&T(g)!=="body"),f=null,m=R(a).position==="fixed",p=m?K(a):a;for(;P(p)&&!pt(p);){let g=R(p),w=ut(p);g.position==="fixed"&&(f=null),(m?w||f:w||g.position!=="static"||!f||!["absolute","fixed"].includes(f.position))?f=g:d=d.filter(x=>x!==p),p=K(p)}return u.set(a,d),d}(t,this._c):[].concat(i),r=[...s,n],l=r[0],h=r.reduce((a,u)=>{let c=Ot(t,u,o);return a.top=X(c.top,a.top),a.right=Et(c.right,a.right),a.bottom=Et(c.bottom,a.bottom),a.left=X(c.left,a.left),a},Ot(t,l,o));return{width:h.right-h.left,height:h.bottom-h.top,x:h.left,y:h.top}},convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{rect:t,offsetParent:i,strategy:n}=e,o=E(i),s=L(i);if(i===s)return t;let r={scrollLeft:0,scrollTop:0},l={x:1,y:1},h={x:0,y:0};if((o||!o&&n!=="fixed")&&((T(i)!=="body"||st(s))&&(r=rt(i)),E(i))){let a=M(i);l=z(i),h.x=a.x+i.clientLeft,h.y=a.y+i.clientTop}return{width:t.width*l.x,height:t.height*l.y,x:t.x*l.x-r.scrollLeft*l.x+h.x,y:t.y*l.y-r.scrollTop*l.y+h.y}},isElement:P,getDimensions:function(e){return Lt(e)},getOffsetParent:Rt,getDocumentElement:L,getScale:z,async getElementRects(e){let{reference:t,floating:i,strategy:n}=e,o=this.getOffsetParent||Rt,s=this.getDimensions;return{reference:Nt(t,await o(i),n),floating:{x:0,y:0,...await s(i)}}},getClientRects:e=>Array.from(e.getClientRects()),isRTL:e=>R(e).direction==="rtl"};function Mt(e,t,i,n){n===void 0&&(n={});let{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:r=!0,animationFrame:l=!1}=n,h=o&&!l,a=h||s?[...P(e)?$(e):e.contextElement?$(e.contextElement):[],...$(t)]:[];a.forEach(f=>{h&&f.addEventListener("scroll",i,{passive:!0}),s&&f.addEventListener("resize",i)});let u,c=null;r&&(c=new ResizeObserver(()=>{i()}),P(e)&&!l&&c.observe(e),P(e)||!e.contextElement||l||c.observe(e.contextElement),c.observe(t));let d=l?M(e):null;return l&&function f(){let m=M(e);!d||m.x===d.x&&m.y===d.y&&m.width===d.width&&m.height===d.height||i(),d=m,u=requestAnimationFrame(f)}(),i(),()=>{var f;a.forEach(m=>{h&&m.removeEventListener("scroll",i),s&&m.removeEventListener("resize",i)}),(f=c)==null||f.disconnect(),c=null,l&&cancelAnimationFrame(u)}}var Dt=(e,t,i)=>{let n=new Map,o={platform:Xt,...i},s={...o.platform,_c:n};return Ct(e,t,{...o,platform:s})};var gt=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.host.floating&&!this._floating&&this.float(this.host.floating),this._floating&&this.updatePosition()}hostResized(){this._floating&&this.updatePosition()}float(t){var h;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:s=!1,animationFrame:r=!1}=this._settings,l=this.getOffsetSetting();Object.assign(this.host.style,{position:(h=i.strategy)!=null?h:"absolute",top:"0",left:"0",transition:"none",transform:"translate3d(0,0,0)"}),i.inset&&!n?this._middleware.push(it(({rects:a,placement:u})=>{var c,d,f,m,p,g;return u.includes("top")||u.includes("bottom")?{mainAxis:-a.floating.height-((c=l==null?void 0:l.mainAxis)!=null?c:0),crossAxis:(d=l==null?void 0:l.crossAxis)!=null?d:0,alignmentAxis:(f=l==null?void 0:l.alignmentAxis)!=null?f:0}:{mainAxis:-a.floating.width-((m=l==null?void 0:l.mainAxis)!=null?m:0),crossAxis:(p=l==null?void 0:l.crossAxis)!=null?p:0,alignmentAxis:(g=l==null?void 0:l.alignmentAxis)!=null?g:0}})):l&&this._middleware.push(it(l)),o&&this._middleware.push(ht()),s&&this._middleware.push(dt()),n&&(this.arrowEl=document.createElement("div"),this.arrowEl.classList.add("wk-arrow"),this._middleware.push(ft({element:this.arrowEl}))),this.cleanupAutoUpdate=Mt(this._reference,this.host,()=>{this.updatePosition()},{animationFrame:r}),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:{};Dt(this._reference,this.host,{middleware:this._middleware,strategy:t,placement:i}).then(({x:o,y:s,placement:r,middlewareData:l})=>{if(l.arrow&&this.arrowEl){let{x:h,y:a}=l.arrow,u={top:"bottom",right:"left",bottom:"top",left:"right"}[r.split("-")[0]],c={bottom:"0deg",left:"90deg",top:"180deg",right:"270deg"}[r.split("-")[0]];Object.assign(this.arrowEl.style,{left:h!=null?`${h}px`:"",top:a!=null?`${a}px`:"",right:"",bottom:"",[u]:"-5px",transform:`rotate(${c})`})}Object.assign(this.host.style,{transform:`translate3d(${Math.round(o)}px,${Math.round(s)}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 wt=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(s=>s.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:s,selectedOptions:r,selectedVariant:l,hasOnlyDefaultVariant:h}=this.host.app.utils.product.getFormState({product:this.product,options:t,change:i,autoSelect:n});this.hasSelection=o,this.optionsWithValues=s,this.selectedOptions=r,this.selectedVariant=l,this.hasOnlyDefaultVariant=h,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,quantity:n,sectionsToRender:o,sectionsUrl:s="/"}){if(!this.selectedVariant)throw new Error("No variant selected");let r=this.host.querySelector("form");if(!r)throw new Error("Form not found");return this.submitting=!0,this.host.app.addToCart({wishlistId:t,wishlistItemId:i,variantId:this.selectedVariant.id,quantity:n!=null?n:this.host.app.utils.product.getFormQuantity({form:r}),sectionsToRender:o,sectionsUrl:s}).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 Kt,map as J,of as Jt}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";var xt=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),cart:t.cart}}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:s}=this.hostDataset;return{params:{wishlistId:i,productHandle:n,variantId:s?parseInt(s):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(J(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(J(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(J(o=>({wishlistItem:o}))))}return this.stateConfig.cart&&t.push(this.app.state.observeShopifyCart().pipe(J(i=>({cart:i})))),t.length||t.push(Jt({})),$t(t).pipe(J(i=>i.reduce((n,o)=>o.wishlist?{...n,wishlist:o.wishlist}:o.wishlistItem?{...n,wishlistItem:o.wishlistItem}:o.productInfo?{...n,productInfo:o.productInfo}:o.cart?{...n,cart:o.cart}:n,{})),Kt((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{gt as FloatingUiController,wt as ProductFormController,xt as WishlistStateController};
{
"name": "@appmate/wishlist",
"version": "4.25.14",
"version": "4.25.15",
"description": "Wishlist King SDK",

@@ -5,0 +5,0 @@ "main": "wishlist-app.js",

@@ -1,1 +0,1 @@

var x=(a=21)=>crypto.getRandomValues(new Uint8Array(a)).reduce((t,e)=>(e&=63,e<36?t+=e.toString(36):e<62?t+=(e-26).toString(36).toUpperCase():e>62?t+="-":t+="_",t),"");var c=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 c;if(typeof t=="object")return this.searchByStyle(t,this.element,i=>i.parentElement,e);let s=this.element.closest(t);return s?new c(s):new c}find(t){var s;let e=(s=this.element)==null?void 0:s.querySelector(t);return e?new c(e):new c}searchByStyle(t,e,s,i=5){if(i<0||!e)return null;let r=getComputedStyle(e);if(Object.entries(t).every(([l,h])=>r.getPropertyValue(l)===h))return new c(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("wk-skip")).forEach(s=>{s instanceof Element&&this.scan(s)})}),this.observer.observe(document,{subtree:!0,childList:!0,attributes:!1})}watch(t,e){let s={target:t,callback:e};this.subscriber.push(s),D(s,this.routeUtil.parse(window.location.pathname))&&this.scan(document)}shouldSkip(t,{skipHidden:e}){return e&&t instanceof HTMLElement?t.offsetParent===null:!1}scan(t){t&&this.subscriber.filter(e=>D(e,this.routeUtil.parse(window.location.pathname))).forEach(e=>{let s=t instanceof Element&&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("wk-skip")){e.setAttribute("wk-skip","");let s=new c(e);t.callback(s)}}};function D({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 N=[{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:"challenge",match:a=>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:"search",match:a=>a.includes("/search")},{pageType:"home",match:a=>a.length<4}],g=class{constructor({wishlistUrl:t}){this.wishlistUrl=t}parse(t){for(let e of N)if(e.match(t,{wishlistUrl:this.wishlistUrl}))return{pageType:e.pageType};return{pageType:"unknown"}}};var w=class{constructor(t){this.locale={};var e;this.initLocale((e=t==null?void 0:t.locale)!=null?e:{})}initLocale(t){this.locale=this.decodeLocale(t)}decodeHtmlEntities(t){return t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&#39;/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,h])=>n.replace(new RegExp(`{{\\s*${l}\\s*}}`,"g"),h),r):r:`translation missing: ${t}`}};var m=class{constructor({rootUrl:t,wishlistUrl:e}){this._rootUrl=t,this.route=new g({wishlistUrl:e}),this.observer=new u({routeUtil:this.route}),this.locale=new w,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,e){var i;let s=null;if(t&&(t instanceof URL&&(t=t.pathname),s=new URLSearchParams(t.split("?")[1]).get("variant")),!s&&e)try{s=new FormData((i=e.element)!=null?i:e).get("id")}catch(r){console.warn("Failed to parse variant from product form.",r)}return s}translate(t,e){return this.locale.translate(t,e)}createComponent(t,e){var i;let s=document.createElement(t);if(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])=>{if(r==="floating"&&o){let n=o,l=(n==null?void 0:n.reference)instanceof c?n.reference.element:n.reference;if(typeof l=="object"&&"id"in l){l.setAttribute("wk-id",x()),s[r]={...n,reference:`[wk-id="${l.getAttribute("wk-id")}"]`};return}}s[r]=o}),(i=e==null?void 0:e.wrap)!=null&&i.name){let r=this.createElement(e.wrap.name,e.wrap.props,s);return r.setAttribute("wk-skip",""),r}return 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 f=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 j=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 f,this.theme=new m({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl}),this.initDevMode();let{stylesheets:s,scripts:i,iconSetUrl:r,localeUrl:o}=this.parseDependencies(t);this.initStyles({stylesheets:s,iconSetUrl:r,localeUrl:o}),this.initScripts(i),this.initLoginActionQueue(),(this.hasSession||this.settings.general.appLoading==="EAGER")&&this.load(),window.WishlistKing=this,this.events.publish({name:"wk:app:created",data:{}})}get loaded(){return this._loaded}get state(){return y(this._state)}get apis(){return y(this._apis)}get utils(){return y(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.25.14/state.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/api.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/utils.js")]);this.initUtils({MoneyUtil:r,UrlUtil:o,ProductUtil:n}),this.initApis({WishlistApi:s,ShopifyApi:e,TrackingApi:i}),await this.initState({WishlistState:t}),this.initCustomerSession(),this.initUrlChangeEvents(),this.trackCurrentPage(),this._loaded=!0,this.events.publish({name:"wk:app:loaded",data:{}})})()}initUtils({UrlUtil:t,MoneyUtil:e,ProductUtil:s}){this._utils={url:new t({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl,shopDomain:this.config.shop.domain,placeholderImageUrl:this.config.products.fallbackImage,fileUrl:this.routes.fileUrl}),money:new e({moneyFormat:this.config.shop.moneyFormat,moneyFormatWithCurrency:this.config.shop.moneyFormatWithCurrency}),product:new s}}initApis({WishlistApi:t,ShopifyApi:e,TrackingApi:s}){var i,r,o;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(),productMetafields:this.config.products.metafields}),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,customerEmail:(o=this.config.customer.email)!=null?o:void 0,sessionId:this.getSessionId(),utils:this.utils,theme:this.theme,settings:this.settings})}}initState({WishlistState:t}){return this._state=new t({wishlistApi:this.apis.wishlist,shopifyApi:this.apis.shopify,settings:this.settings,events:this.events,utils:this.utils}),this._state.init()}async initStyles({stylesheets:t,iconSetUrl:e,localeUrl:s}){if(!(t!=null&&t.length)&&!e){this.onStylesLoaded();return}try{await Promise.all([...(t!=null?t:[]).map(i=>new Promise((r,o)=>{let n=document.createElement("link");n.rel="stylesheet",n.href=i,n.onload=r,n.onerror=o,document.head.appendChild(n)})),e?Promise.all([import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/components/icon.js"),import(e)]).then(([{Icon:i},{icons:r}])=>{if(typeof r!="object")throw new Error("Icon set must export icons object.");i.addIcons(r)}):Promise.resolve(),s?fetch(s).then(i=>i.json()).then(i=>{this.theme.locale.initLocale(i)}):Promise.resolve()]),this.onStylesLoaded()}catch(i){console.warn(i),this.events.publish({name:"wk:app:load-styles:error",data:{}})}}async initScripts(t){if(!(t!=null&&t.length)){this.initDefaultEventSubscribers(),this.events.publish({name:"wk:app:load-scripts:success",data:{}});return}try{await Promise.all(t.map(e=>import(e).then(({setup:s})=>{typeof s=="function"&&s({app:this})}))),t.some(e=>e.includes("event-subscribers.js"))||this.initDefaultEventSubscribers(),this.events.publish({name:"wk:app:load-scripts:success",data:{}})}catch(e){console.warn(e),this.events.publish({name:"wk:app:load-scripts:error",data:{}})}}initDefaultEventSubscribers(){this.events.subscribe("wk:wishlist:login-required",t=>{window.location.href=this.routes.accountLoginUrl}),this.events.subscribe("wk:customer:login",t=>{if(t.data.pending)switch(t.data.pending.action){case"wishlist:add":this.addWishlistItem(t.data.pending)}}),this.events.subscribe("wk:customer:logout",async t=>{this.clearCustomerSession()})}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",data:{}})}async initLoginActionQueue(){let t=!!window.localStorage.getItem("wk_logged_in");if(this.events.subscribe("wk:wishlist:login-required",e=>{var i;let s=["wishlist:add","wishlist:view"];(i=e.data)!=null&&i.action&&s.includes(e.data.action)&&window.localStorage.setItem("wk_pending",JSON.stringify({...e.data}))}),!t&&this.isLoggedIn){window.localStorage.setItem("wk_logged_in","1"),await this.load(),await this.loadWishlist({wishlistId:"mine",strategy:"cache-or-network"});let e=this.getPendingWishlistAction();this.events.publish({name:"wk:customer:login",data:{pending:e}})}else t&&!this.isLoggedIn&&(await this.load(),window.localStorage.removeItem("wk_logged_in"),this.events.publish({name:"wk:customer:logout",data:{}}));["challenge","account"].includes(this.theme.getPageType())||window.localStorage.removeItem("wk_pending")}async initCustomerSession(){this.hasSession||(await this.clearCustomerSession(),this.events.once("wk:app:init-sid",t=>{var e,s;(e=t.data)!=null&&e.sessionId&&this.setSessionId((s=t.data)==null?void 0:s.sessionId)}))}async clearCustomerSession(){window.localStorage.removeItem("wk_session_id"),window.localStorage.removeItem("wk_pending"),await this.state.promise.clearCache()}getPendingWishlistAction(){try{let t=window.localStorage.getItem("wk_pending");if(t)return JSON.parse(t)}catch(t){console.warn("Could not parse pending wishlist action",t)}}initUrlChangeEvents(){let t=({productHandle:s,variantId:i})=>{this.events.publish({name:"wk:product:change-variant:success",data:{productHandle:s,variantId:i}})},e=s=>(...i)=>{var d;let r=s.apply(history,i),o=typeof i[2]=="string"?i[2]:(d=i[2])==null?void 0:d.toString();if(!o)return r;o.startsWith("?")&&(o=window.location.pathname+o);let n=`${window.location.protocol}//${window.location.host}`,l=new URL(o,n),h=this.theme.getProductHandle(l),p=l.searchParams.get("variant");if(!h)return r;t({productHandle:h,variantId:p?parseInt(p):void 0})};history.replaceState=e(history.replaceState),history.pushState=e(history.pushState)}parseConfig({config:t}){var e,s,i,r,o,n,l,h;return{customer:{id:t.customerId?t.customerId:null,email:(e=t.customerEmail)!=null?e:""},shop:{name:(s=t.shopName)!=null?s:"",domain:(i=t.shopDomain)!=null?i:"",permanentDomain:(r=t.shopPermanentDomain)!=null?r:"",moneyFormat:(o=t.shopMoneyFormat)!=null?o:"",moneyFormatWithCurrency:(n=t.shopMoneyFormatWithCurrency)!=null?n:"",customerAccountsEnabled:t.shopCustomerAccountsEnabled?t.shopCustomerAccountsEnabled==="true":!1},routes:{apiHost:(l=t.apiHost)!=null?l:"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",metafields:!!t.productMetafields}}}parseSettings({settings:t}){var e,s,i,r,o,n,l,h,p,d,b,v,U,S,W,k,E,P,T,I,A,L,M,R,_,C,H;return{general:{appLoading:(s=(e=t==null?void 0:t.general)==null?void 0:e.appLoading)!=null?s:"LAZY",wishlistAccessMode:(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:(h=(l=t==null?void 0:t.general)==null?void 0:l.wishlistPath)!=null?h:"/apps/wishlist"},money:{withCurrency:(d=(p=t==null?void 0:t.money)==null?void 0:p.withCurrency)!=null?d:!1},integrations:{googleAnalytics:{enabled:(U=(v=(b=t.integrations)==null?void 0:b.googleAnalytics)==null?void 0:v.enabled)!=null?U:!1,tracker:(k=(W=(S=t.integrations)==null?void 0:S.googleAnalytics)==null?void 0:W.tracker)!=null?k:""},klaviyo:{enabled:(T=(P=(E=t.integrations)==null?void 0:E.klaviyo)==null?void 0:P.enabled)!=null?T:!1},metaPixel:{enabled:(L=(A=(I=t.integrations)==null?void 0:I.metaPixel)==null?void 0:A.enabled)!=null?L:!1},wishlistAnalytics:{enabled:(_=(R=(M=t.integrations)==null?void 0:M.metaPixel)==null?void 0:R.enabled)!=null?_:!0}},cache:{wishlist:{ttl:6e4},wishlistItem:{ttl:6e4},productInfo:{ttl:6e4},product:{ttl:3e4},cart:{ttl:1e3}},colorMap:(C=t.colorMap)!=null?C:{},collectionButtons:(H=t.collectionButtons)!=null?H:{}}}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"}}parseDependencies(t){let e=this.isDevMode();return t.map(s=>this.parseDependencyUrl({url:s,noCache:e})).reduce(({stylesheets:s,scripts:i,iconSetUrl:r,localeUrl:o},n)=>{let[l]=n.split("?");return l.endsWith(".css")?s.push(n):l.endsWith("icons.js")?r=n:l.endsWith(".js")?i.push(n):l.endsWith(".json")&&(o=n),{stylesheets:s,scripts:i,iconSetUrl:r,localeUrl:o}},{stylesheets:[],scripts:[],iconSetUrl:"",localeUrl:""})}parseDependencyUrl({url:t,noCache:e}){return e&&!t.includes("/_templates/")?t.replace("cdn.appmate.io","storage.googleapis.com/appmate-cdn").replace(/v=\d*/,`v=${Date.now()}`):t}isDevMode(){if(!!!document.getElementById("preview-bar-iframe"))return!1;let e=window.localStorage.getItem("wk_dev_mode");return e?Date.now()-parseInt(e)<8*36e5:!1}initDevMode(){window.location.search.includes("wk_dev_mode=on")?window.localStorage.setItem("wk_dev_mode",Date.now().toString()):window.location.search.includes("wk_dev_mode=off")&&window.localStorage.removeItem("wk_dev_mode"),this.isDevMode()&&window.addEventListener("message",t=>{switch(t.data){case"WK_THEME_RELOAD":window.localStorage.setItem("wk_dev_mode",Date.now().toString()),window.location.reload();break}},!1)}},y=a=>{if(!a)throw new Error("Wishlist app not loaded.");return a};export{j as WishlistApp};
var x=(a=21)=>crypto.getRandomValues(new Uint8Array(a)).reduce((t,e)=>(e&=63,e<36?t+=e.toString(36):e<62?t+=(e-26).toString(36).toUpperCase():e>62?t+="-":t+="_",t),"");var c=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 c;if(typeof t=="object")return this.searchByStyle(t,this.element,i=>i.parentElement,e);let s=this.element.closest(t);return s?new c(s):new c}find(t){var s;let e=(s=this.element)==null?void 0:s.querySelector(t);return e?new c(e):new c}searchByStyle(t,e,s,i=5){if(i<0||!e)return null;let r=getComputedStyle(e);if(Object.entries(t).every(([l,h])=>r.getPropertyValue(l)===h))return new c(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("wk-skip")).forEach(s=>{s instanceof Element&&this.scan(s)})}),this.observer.observe(document,{subtree:!0,childList:!0,attributes:!1})}watch(t,e){let s={target:t,callback:e};this.subscriber.push(s),D(s,this.routeUtil.parse(window.location.pathname))&&this.scan(document)}shouldSkip(t,{skipHidden:e}){return e&&t instanceof HTMLElement?t.offsetParent===null:!1}scan(t){t&&this.subscriber.filter(e=>D(e,this.routeUtil.parse(window.location.pathname))).forEach(e=>{let s=t instanceof Element&&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("wk-skip")){e.setAttribute("wk-skip","");let s=new c(e);t.callback(s)}}};function D({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 N=[{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:"challenge",match:a=>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:"search",match:a=>a.includes("/search")},{pageType:"home",match:a=>a.length<4}],g=class{constructor({wishlistUrl:t}){this.wishlistUrl=t}parse(t){for(let e of N)if(e.match(t,{wishlistUrl:this.wishlistUrl}))return{pageType:e.pageType};return{pageType:"unknown"}}};var w=class{constructor(t){this.locale={};var e;this.initLocale((e=t==null?void 0:t.locale)!=null?e:{})}initLocale(t){this.locale=this.decodeLocale(t)}decodeHtmlEntities(t){return t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&#39;/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,h])=>n.replace(new RegExp(`{{\\s*${l}\\s*}}`,"g"),h),r):r:`translation missing: ${t}`}};var m=class{constructor({rootUrl:t,wishlistUrl:e}){this._rootUrl=t,this.route=new g({wishlistUrl:e}),this.observer=new u({routeUtil:this.route}),this.locale=new w,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,e){var i;let s=null;if(t&&(t instanceof URL&&(t=t.pathname),s=new URLSearchParams(t.split("?")[1]).get("variant")),!s&&e)try{s=new FormData((i=e.element)!=null?i:e).get("id")}catch(r){console.warn("Failed to parse variant from product form.",r)}return s}translate(t,e){return this.locale.translate(t,e)}createComponent(t,e){var i;let s=document.createElement(t);if(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])=>{if(r==="floating"&&o){let n=o,l=(n==null?void 0:n.reference)instanceof c?n.reference.element:n.reference;if(typeof l=="object"&&"id"in l){l.setAttribute("wk-id",x()),s[r]={...n,reference:`[wk-id="${l.getAttribute("wk-id")}"]`};return}}s[r]=o}),(i=e==null?void 0:e.wrap)!=null&&i.name){let r=this.createElement(e.wrap.name,e.wrap.props,s);return r.setAttribute("wk-skip",""),r}return 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 f=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 j=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 f,this.theme=new m({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl}),this.initDevMode();let{stylesheets:s,scripts:i,iconSetUrl:r,localeUrl:o}=this.parseDependencies(t);this.initStyles({stylesheets:s,iconSetUrl:r,localeUrl:o}),this.initScripts(i),this.initLoginActionQueue(),(this.hasSession||this.settings.general.appLoading==="EAGER")&&this.load(),window.WishlistKing=this,this.events.publish({name:"wk:app:created",data:{}})}get loaded(){return this._loaded}get state(){return y(this._state)}get apis(){return y(this._apis)}get utils(){return y(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.25.15/state.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/api.js"),import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/utils.js")]);this.initUtils({MoneyUtil:r,UrlUtil:o,ProductUtil:n}),this.initApis({WishlistApi:s,ShopifyApi:e,TrackingApi:i}),await this.initState({WishlistState:t}),this.initCustomerSession(),this.initUrlChangeEvents(),this.trackCurrentPage(),this._loaded=!0,this.events.publish({name:"wk:app:loaded",data:{}})})()}initUtils({UrlUtil:t,MoneyUtil:e,ProductUtil:s}){this._utils={url:new t({rootUrl:this.routes.rootUrl,wishlistUrl:this.routes.wishlistUrl,shopDomain:this.config.shop.domain,placeholderImageUrl:this.config.products.fallbackImage,fileUrl:this.routes.fileUrl}),money:new e({moneyFormat:this.config.shop.moneyFormat,moneyFormatWithCurrency:this.config.shop.moneyFormatWithCurrency}),product:new s}}initApis({WishlistApi:t,ShopifyApi:e,TrackingApi:s}){var i,r,o;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(),productMetafields:this.config.products.metafields}),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,customerEmail:(o=this.config.customer.email)!=null?o:void 0,sessionId:this.getSessionId(),utils:this.utils,theme:this.theme,settings:this.settings})}}initState({WishlistState:t}){return this._state=new t({wishlistApi:this.apis.wishlist,shopifyApi:this.apis.shopify,settings:this.settings,events:this.events,utils:this.utils}),this._state.init()}async initStyles({stylesheets:t,iconSetUrl:e,localeUrl:s}){if(!(t!=null&&t.length)&&!e){this.onStylesLoaded();return}try{await Promise.all([...(t!=null?t:[]).map(i=>new Promise((r,o)=>{let n=document.createElement("link");n.rel="stylesheet",n.href=i,n.onload=r,n.onerror=o,document.head.appendChild(n)})),e?Promise.all([import("https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/components/icon.js"),import(e)]).then(([{Icon:i},{icons:r}])=>{if(typeof r!="object")throw new Error("Icon set must export icons object.");i.addIcons(r)}):Promise.resolve(),s?fetch(s).then(i=>i.json()).then(i=>{this.theme.locale.initLocale(i)}):Promise.resolve()]),this.onStylesLoaded()}catch(i){console.warn(i),this.events.publish({name:"wk:app:load-styles:error",data:{}})}}async initScripts(t){if(!(t!=null&&t.length)){this.initDefaultEventSubscribers(),this.events.publish({name:"wk:app:load-scripts:success",data:{}});return}try{await Promise.all(t.map(e=>import(e).then(({setup:s})=>{typeof s=="function"&&s({app:this})}))),t.some(e=>e.includes("event-subscribers.js"))||this.initDefaultEventSubscribers(),this.events.publish({name:"wk:app:load-scripts:success",data:{}})}catch(e){console.warn(e),this.events.publish({name:"wk:app:load-scripts:error",data:{}})}}initDefaultEventSubscribers(){this.events.subscribe("wk:wishlist:login-required",t=>{window.location.href=this.routes.accountLoginUrl}),this.events.subscribe("wk:customer:login",t=>{if(t.data.pending)switch(t.data.pending.action){case"wishlist:add":this.addWishlistItem(t.data.pending)}}),this.events.subscribe("wk:customer:logout",async t=>{this.clearCustomerSession()})}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",data:{}})}async initLoginActionQueue(){let t=!!window.localStorage.getItem("wk_logged_in");if(this.events.subscribe("wk:wishlist:login-required",e=>{var i;let s=["wishlist:add","wishlist:view"];(i=e.data)!=null&&i.action&&s.includes(e.data.action)&&window.localStorage.setItem("wk_pending",JSON.stringify({...e.data}))}),!t&&this.isLoggedIn){window.localStorage.setItem("wk_logged_in","1"),await this.load(),await this.loadWishlist({wishlistId:"mine",strategy:"cache-or-network"});let e=this.getPendingWishlistAction();this.events.publish({name:"wk:customer:login",data:{pending:e}})}else t&&!this.isLoggedIn&&(await this.load(),window.localStorage.removeItem("wk_logged_in"),this.events.publish({name:"wk:customer:logout",data:{}}));["challenge","account"].includes(this.theme.getPageType())||window.localStorage.removeItem("wk_pending")}async initCustomerSession(){this.hasSession||(await this.clearCustomerSession(),this.events.once("wk:app:init-sid",t=>{var e,s;(e=t.data)!=null&&e.sessionId&&this.setSessionId((s=t.data)==null?void 0:s.sessionId)}))}async clearCustomerSession(){window.localStorage.removeItem("wk_session_id"),window.localStorage.removeItem("wk_pending"),await this.state.promise.clearCache()}getPendingWishlistAction(){try{let t=window.localStorage.getItem("wk_pending");if(t)return JSON.parse(t)}catch(t){console.warn("Could not parse pending wishlist action",t)}}initUrlChangeEvents(){let t=({productHandle:s,variantId:i})=>{this.events.publish({name:"wk:product:change-variant:success",data:{productHandle:s,variantId:i}})},e=s=>(...i)=>{var d;let r=s.apply(history,i),o=typeof i[2]=="string"?i[2]:(d=i[2])==null?void 0:d.toString();if(!o)return r;o.startsWith("?")&&(o=window.location.pathname+o);let n=`${window.location.protocol}//${window.location.host}`,l=new URL(o,n),h=this.theme.getProductHandle(l),p=l.searchParams.get("variant");if(!h)return r;t({productHandle:h,variantId:p?parseInt(p):void 0})};history.replaceState=e(history.replaceState),history.pushState=e(history.pushState)}parseConfig({config:t}){var e,s,i,r,o,n,l,h;return{customer:{id:t.customerId?t.customerId:null,email:(e=t.customerEmail)!=null?e:""},shop:{name:(s=t.shopName)!=null?s:"",domain:(i=t.shopDomain)!=null?i:"",permanentDomain:(r=t.shopPermanentDomain)!=null?r:"",moneyFormat:(o=t.shopMoneyFormat)!=null?o:"",moneyFormatWithCurrency:(n=t.shopMoneyFormatWithCurrency)!=null?n:"",customerAccountsEnabled:t.shopCustomerAccountsEnabled?t.shopCustomerAccountsEnabled==="true":!1},routes:{apiHost:(l=t.apiHost)!=null?l:"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",metafields:!!t.productMetafields}}}parseSettings({settings:t}){var e,s,i,r,o,n,l,h,p,d,b,v,U,S,W,k,E,P,T,I,A,L,M,R,_,C,H;return{general:{appLoading:(s=(e=t==null?void 0:t.general)==null?void 0:e.appLoading)!=null?s:"LAZY",wishlistAccessMode:(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:(h=(l=t==null?void 0:t.general)==null?void 0:l.wishlistPath)!=null?h:"/apps/wishlist"},money:{withCurrency:(d=(p=t==null?void 0:t.money)==null?void 0:p.withCurrency)!=null?d:!1},integrations:{googleAnalytics:{enabled:(U=(v=(b=t.integrations)==null?void 0:b.googleAnalytics)==null?void 0:v.enabled)!=null?U:!1,tracker:(k=(W=(S=t.integrations)==null?void 0:S.googleAnalytics)==null?void 0:W.tracker)!=null?k:""},klaviyo:{enabled:(T=(P=(E=t.integrations)==null?void 0:E.klaviyo)==null?void 0:P.enabled)!=null?T:!1},metaPixel:{enabled:(L=(A=(I=t.integrations)==null?void 0:I.metaPixel)==null?void 0:A.enabled)!=null?L:!1},wishlistAnalytics:{enabled:(_=(R=(M=t.integrations)==null?void 0:M.metaPixel)==null?void 0:R.enabled)!=null?_:!0}},cache:{wishlist:{ttl:6e4},wishlistItem:{ttl:6e4},productInfo:{ttl:6e4},product:{ttl:3e4},cart:{ttl:1e3}},colorMap:(C=t.colorMap)!=null?C:{},collectionButtons:(H=t.collectionButtons)!=null?H:{}}}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"}}parseDependencies(t){let e=this.isDevMode();return t.map(s=>this.parseDependencyUrl({url:s,noCache:e})).reduce(({stylesheets:s,scripts:i,iconSetUrl:r,localeUrl:o},n)=>{let[l]=n.split("?");return l.endsWith(".css")?s.push(n):l.endsWith("icons.js")?r=n:l.endsWith(".js")?i.push(n):l.endsWith(".json")&&(o=n),{stylesheets:s,scripts:i,iconSetUrl:r,localeUrl:o}},{stylesheets:[],scripts:[],iconSetUrl:"",localeUrl:""})}parseDependencyUrl({url:t,noCache:e}){return e&&!t.includes("/_templates/")?t.replace("cdn.appmate.io","storage.googleapis.com/appmate-cdn").replace(/v=\d*/,`v=${Date.now()}`):t}isDevMode(){if(!!!document.getElementById("preview-bar-iframe"))return!1;let e=window.localStorage.getItem("wk_dev_mode");return e?Date.now()-parseInt(e)<8*36e5:!1}initDevMode(){window.location.search.includes("wk_dev_mode=on")?window.localStorage.setItem("wk_dev_mode",Date.now().toString()):window.location.search.includes("wk_dev_mode=off")&&window.localStorage.removeItem("wk_dev_mode"),this.isDevMode()&&window.addEventListener("message",t=>{switch(t.data){case"WK_THEME_RELOAD":window.localStorage.setItem("wk_dev_mode",Date.now().toString()),window.location.reload();break}},!1)}},y=a=>{if(!a)throw new Error("Wishlist app not loaded.");return a};export{j 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.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.25.14/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.host.setAttribute("wk-skip",""),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:loaded",()=>{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 Element?{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.25.15/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.host.setAttribute("wk-skip",""),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:loaded",()=>{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 Element?{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 @@

import{delayWhen as d,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 u}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";import{LitElement as y}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{unsafeHTML as p}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{WishlistStateController as v}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.14/controllers.js";var a=class extends y{constructor(){super();this.connected=!1;this.cleanupMethods=[];this.eventPending=!1;this.firstConnect=!0;this.loadWithoutSession=!1;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,i){super.attributeChangedCallback(t,e,i),this.connected&&this.app.loaded&&this.initState()}appReadyCallback(){this.dataset.productHandle&&this.app.events.subscribe("wk:product:change-variant:success",t=>{var e,i;this.dataset.productHandle===((e=t.data)==null?void 0:e.productHandle)&&((i=t.data)!=null&&i.variantId)&&(this.dataset.variantId=t.data.variantId.toString())})}async connect(){if(!this.connected){if(!window.WishlistKing){window.document.addEventListener("wk:app:created",()=>{this.connect()},{once:!0});return}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||this.loadWithoutSession?(await this.app.load(),this.init()):(this.initFallbackState(),this.app.events.once("wk:app:loaded",()=>{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")?p(i):i}formatMoney(t,e){var i;return this.app.utils.money.formatMoney(t,{withCurrency:(i=e==null?void 0:e.withCurrency)!=null?i:this.app.settings.money.withCurrency})}renderMoney(t,e){return p(this.formatMoney(t,e))}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){t.wishlist&&(this.wishlist=t.wishlist),t.wishlistItem&&(this.wishlistItem=t.wishlistItem),t.productInfo&&(this.productInfo=t.productInfo),t.cart&&(this.cart=t.cart)}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 c(this,t).pipe(u(s=>{this.eventPending&&s.preventDefault()}),h(()=>!this.eventPending),u(()=>{this.eventPending=!0}),b(s=>s.target instanceof HTMLElement?{event:s,target:i?s.target.closest(i):s.currentTarget}:{event:s,target:null}),h(({target:s})=>!!s),d(s=>this.app.hasSession?l(s):o(this.app.load())),m(({event:s,target:n})=>{let r=e.bind(this)(s,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},cart:{state:!0},loadWithoutSession:{type:Boolean,attribute:"load-without-session"}};export{a as WishlistElement};
import{delayWhen as d,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 u}from"https://cdn.jsdelivr.net/npm/rxjs@7.8.0/+esm";import{LitElement as y}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{unsafeHTML as p}from"https://cdn.jsdelivr.net/gh/lit/dist@2.7.4/all/lit-all.min.js";import{WishlistStateController as v}from"https://cdn.jsdelivr.net/npm/@appmate/wishlist@4.25.15/controllers.js";var a=class extends y{constructor(){super();this.connected=!1;this.cleanupMethods=[];this.eventPending=!1;this.firstConnect=!0;this.loadWithoutSession=!1;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,i){super.attributeChangedCallback(t,e,i),this.connected&&this.app.loaded&&this.initState()}appReadyCallback(){this.dataset.productHandle&&this.app.events.subscribe("wk:product:change-variant:success",t=>{var e,i;this.dataset.productHandle===((e=t.data)==null?void 0:e.productHandle)&&((i=t.data)!=null&&i.variantId)&&(this.dataset.variantId=t.data.variantId.toString())})}async connect(){if(!this.connected){if(!window.WishlistKing){window.document.addEventListener("wk:app:created",()=>{this.connect()},{once:!0});return}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||this.loadWithoutSession?(await this.app.load(),this.init()):(this.initFallbackState(),this.app.events.once("wk:app:loaded",()=>{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")?p(i):i}formatMoney(t,e){var i;return this.app.utils.money.formatMoney(t,{withCurrency:(i=e==null?void 0:e.withCurrency)!=null?i:this.app.settings.money.withCurrency})}renderMoney(t,e){return p(this.formatMoney(t,e))}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){t.wishlist&&(this.wishlist=t.wishlist),t.wishlistItem&&(this.wishlistItem=t.wishlistItem),t.productInfo&&(this.productInfo=t.productInfo),t.cart&&(this.cart=t.cart)}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 c(this,t).pipe(u(s=>{this.eventPending&&s.preventDefault()}),h(()=>!this.eventPending),u(()=>{this.eventPending=!0}),b(s=>s.target instanceof HTMLElement?{event:s,target:i?s.target.closest(i):s.currentTarget}:{event:s,target:null}),h(({target:s})=>!!s),d(s=>this.app.hasSession?l(s):o(this.app.load())),m(({event:s,target:n})=>{let r=e.bind(this)(s,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},cart:{state:!0},loadWithoutSession:{type:Boolean,attribute:"load-without-session"}};export{a as WishlistElement};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc