@dropins/storefront-pdp 0.2.3-alpha6 → 0.2.3-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,13 +15,15 @@ type DefaultSlotContext = {
15
15
  valid: boolean;
16
16
  };
17
17
  export type CarouselConfig = {
18
- mobile?: boolean;
19
- controls?: 'thumbnailsRow' | 'thumbnailsColumn' | 'dots' | null;
18
+ controls?: {
19
+ desktop?: 'thumbnailsRow' | 'thumbnailsColumn' | 'dots' | null;
20
+ mobile?: 'dots' | 'thumbnailsRow' | null;
21
+ };
20
22
  arrowsOnMainImage?: boolean;
21
23
  loopable?: boolean;
22
24
  peak?: {
23
- mobile: boolean;
24
25
  desktop: boolean;
26
+ mobile: boolean;
25
27
  };
26
28
  gap?: 'small' | 'medium' | 'large' | null;
27
29
  thumbnailsLoadingMode?: 'lazy' | 'eager';
@@ -1 +1 @@
1
- import*as se from"@dropins/tools/preact-compat.js";import{useState as K,Children as re,useRef as ye,useMemo as ve,useEffect as C,useCallback as Q}from"@dropins/tools/preact-compat.js";import{debounce as ge,classes as g,VComponent as T,toLanguageTag as Ne,Slot as z}from"@dropins/tools/lib.js";import{Button as we,Icon as be,Price as Se,Picker as Ve,ColorSwatch as He,ImageSwatch as qe,TextSwatch as ze,Incrementer as Ge,Breadcrumbs as je,Image as Ie}from"@dropins/tools/components.js";import{jsxs as M,jsx as r,Fragment as Pe}from"@dropins/tools/preact-jsx-runtime.js";import{useText as V}from"@dropins/tools/i18n.js";import{c as $e,d as Oe}from"../chunks/getRefinedProduct.js";import{events as Fe}from"@dropins/tools/event-bus.js";import{c as Be}from"../chunks/initialize.js";import"@dropins/tools/fetch-graphql.js";const Ke=e=>se.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},se.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),Qe=e=>se.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},se.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 5.64001L5.62988 18.37",stroke:"currentColor"}),se.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 18.37L5.62988 5.64001",stroke:"currentColor"})),me=({show:e=1,scrollbar:o=!1,peak:p=!1,arrows:b=!1,controls:s="dots",arrowsOnMainImage:P=!1,loop:u=!1,gap:A=null,direction:l="horizontal",width:ee="100%",height:d="100%",defaultIndex:v=0,className:U,children:H,thumbnails:X=null,isZoomed:N,...w})=>{const m=V("PDP.Carousel.label").label,n=V("PDP.Carousel.Slide.label").label,D=V("PDP.Carousel.Previous.label").label,R=V("PDP.Carousel.Next.label").label,y=V("PDP.Carousel.Controls.label").label,Z=V("PDP.Carousel.Controls.Button.label").label,[t,te]=K(()=>ke(e)),O=Math.ceil(re.toArray(H).length/t),G={small:16,medium:24,large:64},W=p?24:0,j=A?G[A]:0,I=re.toArray(H).length%t,ne=16,Y=2,le="32",[E,J]=K(u?v+1:v),q=ye([]),[F,he]=K(0),[ie,pe]=K(0),oe=ve(()=>re.toArray(X),[X]),c=ve(()=>{const a=re.toArray(H).reduce((i,L,S)=>S%t===0?[...i,[L]]:[...i.slice(0,-1),[...i[i.length-1],L]],[]);return!u||a.length===1?a:u&&re.toArray(H).length%t===0?[a[O-1]].concat(a).concat([a[0],a[1]]):[re.toArray(H).slice(-t)].concat(a).concat([a[0],a[1]])},[H,t,O,u]),_=ye(null),f=ye(null),h=s==="thumbnailsRow"||s==="thumbnailsColumn";C(()=>{const a=document.body,i=ge(()=>{var x,Ae;he(((x=_.current)==null?void 0:x.offsetWidth)??0),pe(((Ae=_.current)==null?void 0:Ae.offsetHeight)??0);const S=window.innerWidth,B=ke(e,S);B!==t&&te(B)},50),L=new ResizeObserver(i);return L.observe(a),()=>{L.unobserve(a)}},[t,e]);const $=Q(a=>{const i=u?a-1:a,L=q==null?void 0:q.current[0],S=(L==null?void 0:L.offsetWidth)+ne,B=(L==null?void 0:L.offsetHeight)+ne,x=f.current;s==="thumbnailsRow"&&(x!=null&&x.offsetWidth)&&(S*(i+1)>x.offsetWidth&&(x.style.scrollBehavior="smooth",x.scrollLeft=(i+Y)*S),x.scrollLeft>S*i&&(x.style.scrollBehavior="smooth",x.scrollLeft=(i-Y)*S)),s==="thumbnailsColumn"&&(x!=null&&x.offsetHeight)&&(B*(i+1)>x.offsetHeight&&(x.style.scrollBehavior="smooth",x.scrollTop=(i+Y)*B),x.scrollTop>B*i&&(x.style.scrollBehavior="smooth",x.scrollTop=(i-Y)*B))},[s,u]),k=Q((a,i,L)=>{(s==="thumbnailsRow"||s==="thumbnailsColumn")&&$(a);const S=_.current,B=W?S.offsetWidth-W:S.offsetWidth-W+j;if(!Array.from(S.querySelectorAll("[data-index]")).filter(_e=>{const de=Number(_e.getAttribute("data-index"));return!isNaN(de)&&de>-1})[a])return;if(L){const _e=a===0?O:0,de=B*(O+(I||t)/t);if(S.scrollLeft>=0&&S.scrollLeft<B-5){k(1,!0);return}if(S.scrollLeft>de-B&&S.scrollLeft<=de){k(O,!0);return}S.style.scrollBehavior="auto",S.scrollLeft=_e===0?0:de,k(_e===0?1:O,!0);return}const Ue=(S.offsetWidth-j)/t*c[a].length-W;S.style.scrollBehavior=i?"smooth":"auto",S.scrollLeft=c[a].length===t?B*a:B*(a-1)+Ue},[j,O,W,t,I,c,$,s]),ce=Q(()=>{if(u){const i=E-1;k(i,!0,E===1);return}const a=E<=0?0:E-1;k(a,!0)},[E,k,u]),ae=Q(()=>{const a=c.length-1;if(u){const L=E+1;k(L,!0,E===O);return}const i=E>=a?a:E+1;k(i,!0)},[c.length,u,E,k,O]);C(()=>{const a=i=>{i.key==="ArrowLeft"&&(i.preventDefault(),ce()),i.key==="ArrowRight"&&(i.preventDefault(),ae())};return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[ae,ce]),C(()=>{k(u?v+1:v,!1)},[v,k,u]);const fe=ge(()=>{const a=_.current,i=W?a.offsetWidth-W:a.offsetWidth-W+j,L=a.scrollLeft/i,S=Math.round(L)-L<1?Math.round(L):Math.ceil(L);if(h&&$(S),u){const B=i*(O+(I||t)/t);if(Math.ceil(a.scrollLeft)>=Math.ceil(B)-5){a.style.scrollBehavior="auto",a.scrollLeft=a.offsetWidth*1+(Math.ceil(a.scrollLeft)-Math.ceil(B)-W);return}if(a.scrollLeft===0){a.style.scrollBehavior="auto",a.scrollLeft=B-a.offsetWidth+W;return}}E!==S&&J(S)},100);C(()=>{const a=_.current;return a==null||a.addEventListener("scroll",fe),()=>{a==null||a.removeEventListener("scroll",fe)}},[fe]);const ue=(a,i,L)=>r(we,{className:g([["pdp-carousel__button",!a],[`pdp-carousel__button--${i}`,!a],[`pdp-carousel__button--${s}`,a]]),style:{"--height":`${ie}px`},variant:"tertiary","aria-label":i==="next"?R:D,onClick:L,disabled:u?!1:i==="next"?E>=c.length-1:E<1,children:r(be,{className:g([["pdp-carousel__button__icon",!a],[`pdp-carousel__button__icon--${i}`,!a],[`pdp-carousel__button__icon--${s}--${i}`,a]]),size:le,source:Ke})}),Le=b&&c.length!=1&&ue(h,"prev",ce),De=b&&c.length!=1&&ue(h,"next",ae),We=b&&c.length!=1&&ue(!1,"prev",ce),Te=b&&c.length!=1&&ue(!1,"next",ae);return M("div",{role:"region","aria-roledescription":m,className:g(["pdp-carousel",["pdp-carousel--main-image-controls",P],["pdp-carousel--arrows",b&&!h],[`pdp-carousel--${s}`,h],U]),style:{"--flex-carousel":s==="thumbnailsColumn"?"row-reverse":"column","--gap":h?"0":"var(--spacing-small)","--width":ee},...w,children:[r("div",{ref:_,className:g(["pdp-carousel__wrapper",`pdp-carousel__wrapper--${l}`,["pdp-carousel__wrapper--scrollbar",o],["pdp-carousel__wrapper--peak",p]]),style:{"--total-width":s==="thumbnailsColumn"?"81.6%":"100%","--height":s==="thumbnailsColumn"?"auto":d,"--gap":A?`var(--spacing-${A})`:"0px","--per-page":t},tabIndex:0,children:c.map((a,i)=>{const L=a.length<t;return r("div",{role:"group","aria-roledescription":n,"data-index":i,className:g(["pdp-carousel__slide",`pdp-carousel__slide--${l}`,["pdp-carousel__slide--active",E===i],["pdp-carousel__slide--orphan",L]]),style:{"--length":a.length},children:a},i)})}),!h&&M(Pe,{children:[Le,De]}),h&&P&&M(Pe,{children:[We,Te]}),s&&c.length!=1&&M("div",{className:g([[`pdp-carousel__controls__container--${s}`,h],["pdp-carousel__controls__container--no-arrows",!b||P]]),style:{"--width":s==="thumbnailsRow"?`${F}px`:ee,"--height":`${ie}px`,"--nr-thumbnails":oe.length},children:[(h||N)&&!P&&Le,r("div",{ref:f,className:g([[`pdp-carousel__controls__wrapper--${s}`,h],["pdp-carousel__controls__wrapper",h]]),children:r("div",{role:"group","aria-label":y,className:g(["pdp-carousel__controls",[`pdp-carousel__controls--${s}`,h]]),children:(u?c.slice(0,O):c).map((a,i)=>{const L=u?O:c.length,S=u?E-1===i:E===i;return h?M("label",{className:g(["pdp-carousel__thumbnail__container"]),ref:B=>{B&&(q.current[i]=B)},children:[r("input",{type:"radio",name:"carousel-thumbnails","aria-label":Z.replace("{key}",String(i+1)).replace("{total}",String(L)),checked:S&&F!==0,onChange:()=>{k(u?i+1:i,!0)},...w,className:g(["pdp-carousel__thumbnail",["pdp-carousel__thumbnail--selected",S&&F!==0]])}),r("span",{className:g(["pdp-carousel__thumbnail__span"]),children:oe[i]})]},i):r("button",{"aria-label":Z.replace("{key}",String(i+1)).replace("{total}",String(L)),onClick:()=>{k(u?i+1:i,!0)},className:g(["pdp-carousel__controls__button",["pdp-carousel__controls__button--active",S]])},i)})})}),(h||N)&&!P&&De]})]})};function ke(e,o=0){if(typeof e=="number")return e;const{small:p,medium:b,large:s}=e,P=786;return o>1024?s:o>P?b:p}const Xe=({title:e,breadcrumbs:o,galleryContent:p,infoContent:b,productContent:s,sku:P,outOfStock:u,shortDescription:A,description:l,attributes:ee,images:d,options:v,price:U,specialPrice:H,className:X,children:N,quantity:w,actions:m,carouselConfig:n,...D})=>{var j,I,ne,Y,le,E;const R=V("PDP.Product.RegularPrice.label").label,y=V("PDP.Product.SpecialPrice.label").label,Z=V("PDP.Product.OutOfStock.label").label,t=V("PDP.Product.Image.label").label,[te,O]=K(null),G=d!=null&&d.length?d.map((J,q)=>{var F;return r(T,{node:J,loading:q===0?"eager":"lazy",alt:((F=e==null?void 0:e.props)==null?void 0:F.children)&&(t==null?void 0:t.replace("{product}",e.props.children.toString()).replace("{key}",String(q+1)).replace("{total}",String(d.length))),onClick:()=>O(q)},q)}):r("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0}),W=(j=n==null?void 0:n.thumbnails)!=null&&j.length?n.thumbnails.map((J,q)=>{var F;return r(T,{node:J,loading:(n==null?void 0:n.thumbnailsLoadingMode)||"lazy",alt:((F=e==null?void 0:e.props)==null?void 0:F.children)&&(t==null?void 0:t.replace("{product}",e.props.children.toString()).replace("{key}",String(q+1)).replace("{total}",String(d.length)))},q)}):r("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0});return M("div",{...D,className:g(["pdp-product",X]),children:[o&&r(T,{node:o,className:"pdp-product__breadcrumbs"}),M("div",{className:"pdp-product__column-container pdp-product__gallery-column",children:[r("div",{className:"pdp-product__column-body",children:n!=null&&n.controls?r(me,{className:"pdp-product__overlay__carousel",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?n.controls:"dots",arrowsOnMainImage:n==null?void 0:n.arrowsOnMainImage,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,peak:((I=n==null?void 0:n.thumbnails)==null?void 0:I.length)>1&&((ne=n==null?void 0:n.peak)==null?void 0:ne.desktop)||!1,gap:(n==null?void 0:n.gap)||null,width:"100%",height:"100%",defaultIndex:te||0,thumbnails:W,children:G}):r(Ze,{className:"pdp-product__images",gap:"small",children:G})}),p&&r(T,{node:p,className:"pdp-product__gallery-content"})]}),M("div",{className:"pdp-product__column-container pdp-product__content-column",children:[M("div",{className:"pdp-product__column-body",children:[M("div",{className:"pdp-product__header",children:[e&&r(T,{node:e,className:"pdp-product__title"}),P&&r(T,{node:P,className:"pdp-product__sku"})]}),M("div",{className:"pdp-product__prices",children:[H&&r(T,{node:H,className:g(["pdp-product__price-special","pdp-product__price"]),"aria-label":y,role:"text"}),U&&r(T,{node:U,className:g(["pdp-product__price-regular","pdp-product__price--grey"]),"aria-label":R,role:"text"})]}),n!=null&&n.mobile?r(me,{className:"pdp-product__images pdp-product__images--carousel pdp-product__images--carousel--thumbnails",width:"100%",height:"auto",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"thumbnailsRow":null,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,peak:((Y=n==null?void 0:n.thumbnails)==null?void 0:Y.length)>1&&((le=n==null?void 0:n.peak)==null?void 0:le.mobile)||!1,gap:(n==null?void 0:n.gap)||null,thumbnails:W,children:G}):r(me,{className:"pdp-product__images pdp-product__images--carousel",peak:((E=n==null?void 0:n.peak)==null?void 0:E.mobile)&&(d==null?void 0:d.length)>1,gap:(n==null?void 0:n.gap)||null,width:"100%",height:"auto",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"dots":null,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,children:G}),M("div",{className:g(["pdp-product__actions",["pdp-product__actions--out-of-stock",u]]),children:[u&&r("div",{className:"pdp-product__out-of-stock__text",children:Z}),v&&r(T,{node:v,className:g(["pdp-product__options"])}),w&&r("div",{className:"pdp-product__quantity",children:r(T,{node:w})}),m&&r(T,{node:m,className:g(["pdp-product__buttons"])})]}),A&&r(T,{node:A,className:g(["pdp-product__short_description"])}),l&&r(T,{node:l,className:g(["pdp-product__description"])}),ee?r("div",{className:"pdp-product__attributes",children:ee}):null]}),b&&r(T,{node:b,className:"pdp-product__info-content"})]}),s&&r(T,{node:s,className:"pdp-product__content"}),te===null?null:r(Je,{className:"pdp-product__overlay",onClose:()=>O(null),centered:!0,children:r(me,{className:"pdp-product__overlay__carousel",arrows:(d==null?void 0:d.length)>1,width:"100%",height:"100%",defaultIndex:te||0,loop:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"dots":null,isZoomed:!0,children:G})})]})},Ze=({children:e,gap:o=null,className:p,style:b,...s})=>{const P=re.count(e);return r("div",{...s,className:g(["pdp-gallery-grid",p]),style:{"--gap":o?`var(--spacing-${o})`:"0px",...b},children:re.map(e,(u,A)=>r("div",{className:"pdp-gallery-grid__item",children:r(T,{node:u,loading:A===0?"eager":"lazy"},u.props.src)},P+A))})},xe=({amount:e,currency:o,locale:p,variant:b,sale:s,minimumAmount:P,maximumAmount:u,className:A,...l})=>r(Pe,{children:e||P===u?r("div",{className:"pdp-price-range",...l,children:r(Se,{amount:e||P,currency:o,locale:p,variant:b,sale:s,className:A})}):M("div",{className:"pdp-price-range",...l,children:[r(Se,{amount:P,currency:o,locale:p,className:A}),r("span",{className:"pdp-price-range__label",children:"-"}),r(Se,{amount:u,currency:o,locale:p,className:A})]})}),Je=({centered:e,onClose:o,className:p,children:b,...s})=>{const P=V("PDP.Overlay.Close.label").label,u=Q(()=>{o==null||o()},[o]);return C(()=>{const A=l=>{l.key==="Escape"&&u()};return document.addEventListener("keydown",A),()=>{document.removeEventListener("keydown",A)}},[u]),C(()=>{const A=document.scrollingElement,l=A.style.overflow;return A.style.overflow="hidden",()=>{A.style.overflow=l}},[]),M("div",{...s,className:g(["pdp-overlay",["pdp-overlay--centered",e],p]),children:[r("div",{className:"pdp-overlay__content",children:b}),r(we,{"aria-label":P,variant:"tertiary",className:"pdp-overlay__close-button",onClick:u,icon:r(Qe,{})})]})},Ye=["text","image","color","dropdown"],Ce=e=>e.map(o=>({...o,text:o.label,disabled:!o.inStock})),et=({options:e,hideSelectedValue:o,onValues:p,onErrors:b,defaultOptions:s,selectionsToUpdate:P,className:u,children:A,...l})=>{const ee=V("PDP.Swatches.Required.label").label,[d,v]=K(()=>e==null?void 0:e.reduce((w,m)=>{const{items:n}=m,D=n==null?void 0:n.find(y=>s==null?void 0:s.includes(y.id)),R=n==null?void 0:n.find(y=>y.selected);return D?{...w,[m.id]:{label:D.label,value:D.id}}:R?{...w,[m.id]:{label:R.label,value:R.id}}:w},{}));C(()=>{P==null||P.forEach(N=>{v(w=>{var D;const m=(D=N==null?void 0:N.items)==null?void 0:D.find(R=>R.selected);return m?{...w,[N.id]:{label:m==null?void 0:m.label,value:m==null?void 0:m.id}}:w})})},[P,v]),ve(()=>{const N=e==null?void 0:e.reduce((w,m)=>{var n;return(n=m==null?void 0:m.items)==null||n.forEach(D=>{var y;const R=((y=d[m.id])==null?void 0:y.value)===D.id;m.required&&!R&&(w[m.id]=ee)}),w},{});return b==null||b(N),N},[d]);const U=Q((N,w,m)=>{v(n=>{const D={...n,[N]:{label:w,value:m}};return p==null||p(D,m),D})},[p]),H=(N,w)=>{var n;const m=((n=w.selectedOptions[0])==null?void 0:n.label)??"";U(N,m,w.value)},X=Q(({items:N,id:w,required:m,type:n,selected:D,label:R})=>r("div",{className:g(["pdp-swatches__options"]),children:(n==null?void 0:n.toLowerCase())==="dropdown"?r(Ve,{"aria-label":R,handleSelect:y=>H(w,y.target),options:Ce(N),value:D}):N==null?void 0:N.map(y=>{const Z={key:y.id,id:y.id,name:w,value:y.value,label:y.label,groupAriaLabel:R,selected:D===y.id,outOfStock:!y.inStock,required:m===null?!0:m,onValue:()=>{U(w,y.label,y.id)}};switch(n){case"text":return r(ze,{...Z,label:y.label});case"image":return r(qe,{...Z,src:y.value,alt:y.label});case"color":return r(He,{...Z,size:"large",color:y.value});default:return console.warn(`Invalid swatch type ${n}`),null}})}),[U]);return r("div",{...l,className:g(["pdp-swatches",u]),children:e==null?void 0:e.map(({type:N,label:w,id:m,multiple:n,required:D,items:R})=>{var y;if(!N){console.warn("Bundle product not supported on UI.");return}return Ye.includes(N)||console.warn(`Invalid swatch type ${N}`),n&&console.warn("Multiple selection swatches are not currently supported."),M("div",{id:`swatch-item-${m}`,"data-slot-key":`product-swatch--${m}`,className:"pdp-swatches__field",children:[r("div",{className:"pdp-swatches__field__label",children:d[m]?o?`${w}`:`${w}: ${d[m].label}`:w}),r(X,{id:m,type:N,required:D,items:R,label:w,selected:(y=d[m])==null?void 0:y.value})]},`swatch-item-${m}`)})})};function tt(e,o="en_US"){if(!Re(e))throw Error("Invalid date string");return e.split(" ")[1]||(e=`${e} 00:00:00`),new Date(e).toLocaleDateString(Ne(o)).toString()}function Re(e){if(![/^\d{4}-\d{2}-\d{2}$/,/^\d{1,2}\/\d{1,2}\/\d{4}$/,/^\d{2}\/\d{2}\/\d{4}$/,/^\d{4}\/\d{2}\/\d{2}$/,/^\d{1,2}\.\d{1,2}\.\d{4}$/,/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/].some(b=>b.test(e)))return!1;const p=new Date(e);return!isNaN(p.getTime())}function rt(e){const o=new URLSearchParams(window.location.search);Object.entries(e).forEach(([b,s])=>{s===null?o.delete(b):o.set(b,String(s))});let p=window.location.pathname;p+=`?${o.toString()}`,p+=window.location.hash,window.history.replaceState({},"",p)}function nt(){const e=new URLSearchParams(window.location.search),o={};return e.forEach((p,b)=>{o[b]=p}),o}function lt(e){var o,p,b,s,P,u,A,l;return{productId:Number(e==null?void 0:e.externalId),name:e==null?void 0:e.name,sku:e==null?void 0:e.sku,topLevelSku:e==null?void 0:e.externalParentId,specialToDate:void 0,specialFromDate:void 0,newToDate:void 0,newFromDate:void 0,createdAt:void 0,updatedAt:void 0,manufacturer:void 0,countryOfManufacture:void 0,categories:void 0,productType:void 0,pricing:{regularPrice:((p=(o=e==null?void 0:e.prices)==null?void 0:o.regular)==null?void 0:p.amount)||0,minimalPrice:void 0,maximalPrice:void 0,specialPrice:(s=(b=e==null?void 0:e.prices)==null?void 0:b.final)==null?void 0:s.amount,tierPricing:void 0,currencyCode:((u=(P=e==null?void 0:e.prices)==null?void 0:P.final)==null?void 0:u.currency)||"USD"},canonicalUrl:e==null?void 0:e.url,mainImageUrl:(l=(A=e==null?void 0:e.images)==null?void 0:A[0])==null?void 0:l.url}}const ct={PRODUCT_CONTEXT:"productContext"},at={PRODUCT_PAGE_VIEW:"product-page-view"};function Me(){return window.adobeDataLayer=window.adobeDataLayer||[],window.adobeDataLayer}function dt(e,o){const p=Me();p.push({[e]:null}),p.push({[e]:o})}function it(e,o){Me().push(b=>{const s=b.getState?b.getState():{};b.push({event:e,eventInfo:{...s,...o}})})}function Ee(e){const o=lt(e);dt(ct.PRODUCT_CONTEXT,o),it(at.PRODUCT_PAGE_VIEW)}const ot=({sku:e,hideSku:o,hideQuantity:p,hideShortDescription:b,hideDescription:s,hideAttributes:P,hideURLParams:u,hideSelectedOptionValue:A,slots:l,children:ee,initialData:d,carousel:v,optionsConfig:U,useACDL:H,onAddToCart:X,...N})=>{var he,ie,pe,oe;const w=V("PDP.Product.AddToCart.label").label,m=V("PDP.Product.Incrementer.label").label,n=V("PDP.Product.Details.label").label,[D,R]=K(Be.getConfig().defaultLocale||"en-US"),[y,Z]=K(),[t=null,te]=K(d),[O,G]=K(()=>{const c={sku:e,quantity:1};return t!=null&&t.optionUIDs&&(c.optionsUIDs=t.optionUIDs),c}),[W,j]=K(()=>{var c,_;return!(t!=null&&t.options&&((c=t==null?void 0:t.options)==null?void 0:c.length)>0&&((_=t==null?void 0:t.optionUIDs)==null?void 0:_.length)!==(t==null?void 0:t.options.length))}),I={data:t,values:O,valid:W};C(()=>{const c=Fe.on("locale",_=>{_!==D&&(R(_),$e(e).then(te))});return()=>{c==null||c.off()}},[D,e]),C(()=>{H&&d&&Object.keys(d).length>0&&Ee(d)},[d]);const ne=Q(c=>{G(_=>({..._,...c}))},[]),Y=Q(c=>{var f;let _=Object.keys(c).map(h=>c[h].value).filter(h=>h!==void 0);u||rt({optionsUIDs:_.join(",")}),G(h=>({...h,optionsUIDs:_})),j((_==null?void 0:_.length)===((f=t==null?void 0:t.options)==null?void 0:f.length)),Oe(e,_,U==null?void 0:U.anchorOptions).then(h=>{var $;te(h),($=U==null?void 0:U.anchorOptions)!=null&&$.length&&le(h,_),H&&(h==null?void 0:h.sku)!==e&&Ee(h)})},[e]),le=Q((c,_)=>{var $;const f=(c==null?void 0:c.optionUIDs)??[];_.every(k=>f.includes(k))||(Z(c==null?void 0:c.options),G(k=>({...k,optionsUIDs:f})),j((f==null?void 0:f.length)===(($=c==null?void 0:c.options)==null?void 0:$.length)))},[e]),E=Q(c=>{Object.keys(c).length!==0&&j(!1)},[]),J=ve(()=>{var c;return(c=t==null?void 0:t.attributes)==null?void 0:c.map(({label:_,value:f},h)=>{const $=Re(f)?tt(f,D):f.toString();return M("li",{children:[_,": ",r("span",{dangerouslySetInnerHTML:{__html:$}})]},h)})},[t==null?void 0:t.attributes,D]),q=!p&&(t!=null&&t.inStock)?r(z,{name:"Quantity",slot:l==null?void 0:l.Quantity,context:{...I},children:r(Ge,{name:"quantity",defaultValue:O.quantity.toString(),min:1,"aria-label":m,className:"pdp-product__quantity",onValue:c=>{ne({quantity:Number(c)})}},"quantity")}):void 0,F=()=>{if(t!=null&&t.options)return r(z,{name:"Options",slot:l==null?void 0:l.Options,context:{...I},children:r(et,{options:t.options,defaultOptions:O.optionsUIDs,selectionsToUpdate:y,hideSelectedValue:A,onValues:Y,onErrors:E})})};return r("div",{...N,children:r(Xe,{title:r(z,{name:"Title",slot:l==null?void 0:l.Title,context:{...I},children:t==null?void 0:t.name}),sku:o?void 0:r(z,{name:"SKU",slot:l==null?void 0:l.SKU,context:{...I},children:t==null?void 0:t.sku}),options:F(),breadcrumbs:(l==null?void 0:l.Breadcrumbs)&&r(z,{name:"Breadcrumbs",slot:l==null?void 0:l.Breadcrumbs,context:{...I,setSeparator(c){this._registerMethod((..._)=>{const f=c(..._),h=f&&r(be,{source:f});this._setProps($=>({...$,separator:h}))})},appendLink(c){this._registerMethod((..._)=>{const{text:f,...h}=c(..._),$=r("a",{...h,children:f});this._setProps(k=>({...k,categories:[...k.categories||[],$]}))})},appendHTMLElement(c){this._registerMethod((..._)=>{const f=c(..._),h=this._htmlElementToVNode(f);this._setProps($=>({...$,categories:[...$.categories||[],h]}))})}},render:({separator:c,categories:_})=>r(je,{separator:c,categories:_})}),quantity:q,actions:r(z,{name:"Actions",slot:l==null?void 0:l.Actions,context:{...I,appendButton(c){this._registerMethod((..._)=>{const f=c(..._);if(!f)return;const{text:h,icon:$,...k}=f,ce=r(we,{type:"button",...k,icon:$&&r(be,{source:$}),children:h});this._setProps(ae=>({children:[...ae.children||[],ce]}))})}},children:!(l!=null&&l.Actions)&&r(we,{size:"medium",type:"submit",icon:r(be,{source:"Cart"}),disabled:!(t!=null&&t.inStock)||!W,"aria-label":w,onClick:()=>X==null?void 0:X(O),children:w})}),shortDescription:b?void 0:r(z,{name:"ShortDescription",slot:l==null?void 0:l.ShortDescription,context:{...I},children:r("div",{dangerouslySetInnerHTML:{__html:(t==null?void 0:t.shortDescription)??""}})}),description:s?void 0:r(z,{name:"Description",slot:l==null?void 0:l.Description,context:{...I},children:r("div",{dangerouslySetInnerHTML:{__html:(t==null?void 0:t.description)??""}})}),images:((he=t==null?void 0:t.images)==null?void 0:he.map(({label:c,url:_})=>{var f,h;return r(Ie,{title:c,alt:c,src:_,width:((f=v==null?void 0:v.imageParams)==null?void 0:f.width)??960,height:((h=v==null?void 0:v.imageParams)==null?void 0:h.height)??1191,params:(v==null?void 0:v.imageParams)??{width:960}},_)}))??[],specialPrice:(ie=t==null?void 0:t.prices)!=null&&ie.visible?r(z,{name:"SpecialPrice",slot:l==null?void 0:l.SpecialPrice,context:{...I},children:r(xe,{...t.prices.final,locale:Ne(D)})}):void 0,price:(pe=t==null?void 0:t.prices)!=null&&pe.visible&&t.prices.regular&&t.prices.final.amount!==(t==null?void 0:t.prices.regular.amount)?r(z,{name:"RegularPrice",slot:l==null?void 0:l.RegularPrice,context:{...I},children:r(xe,{...t.prices.regular,locale:Ne(D)})}):void 0,carouselConfig:{...v,thumbnails:v?((oe=t==null?void 0:t.images)==null?void 0:oe.map(({label:c,url:_})=>{var f,h;return r(Ie,{title:c,alt:c,src:_,width:((f=v==null?void 0:v.thumbnailParams)==null?void 0:f.width)??200,height:((h=v==null?void 0:v.thumbnailParams)==null?void 0:h.height)??248,params:(v==null?void 0:v.thumbnailParams)??{width:200}},_)}))??[]:[]},outOfStock:!(t!=null&&t.inStock),attributes:P?void 0:r(z,{name:"Attributes",slot:l==null?void 0:l.Attributes,context:{...I},children:J!=null&&J.length?M(Pe,{children:[n,r("ul",{children:J})]}):null}),galleryContent:(l==null?void 0:l.GalleryContent)&&r(z,{name:"GalleryContent",slot:l.GalleryContent,context:{...I}}),infoContent:(l==null?void 0:l.InfoContent)&&r(z,{name:"InfoContent",slot:l.InfoContent,context:{...I}}),productContent:(l==null?void 0:l.Content)&&r(z,{name:"Content",slot:l.Content,context:{...I}})})})};ot.getInitialData=async function({sku:e,optionsConfig:o}){var b,s,P,u,A,l;const p=((b=nt().optionsUIDs)==null?void 0:b.split(","))||((l=(A=(u=(P=(s=Be)==null?void 0:s.getConfig())==null?void 0:P.models)==null?void 0:u.ProductDetails)==null?void 0:A.initialData)==null?void 0:l.optionsUIDs);return p!=null&&p.length?await Oe(e,p,o==null?void 0:o.anchorOptions):await $e(e)};export{ot as ProductDetails,ot as default};
1
+ import*as pe from"@dropins/tools/preact-compat.js";import{useState as J,Children as de,useRef as ye,useMemo as ve,useEffect as te,useCallback as Y}from"@dropins/tools/preact-compat.js";import{debounce as Le,classes as E,VComponent as H,toLanguageTag as Ne,Slot as G}from"@dropins/tools/lib.js";import{Button as we,Icon as be,Price as Se,Picker as We,ColorSwatch as Ue,ImageSwatch as He,TextSwatch as Ve,Incrementer as qe,Breadcrumbs as je,Image as De}from"@dropins/tools/components.js";import{jsxs as U,jsx as t,Fragment as Pe}from"@dropins/tools/preact-jsx-runtime.js";import{useText as z}from"@dropins/tools/i18n.js";import{c as xe,d as $e}from"../chunks/getRefinedProduct.js";import{events as Ge}from"@dropins/tools/event-bus.js";import{c as Oe}from"../chunks/initialize.js";import"@dropins/tools/fetch-graphql.js";const ze=e=>pe.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},pe.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),Fe=e=>pe.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},pe.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 5.64001L5.62988 18.37",stroke:"currentColor"}),pe.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 18.37L5.62988 5.64001",stroke:"currentColor"})),Ke=24,ge=16,_e=2,Qe="32";var Be=(e=>(e[e.small=16]="small",e[e.medium=24]="medium",e[e.large=64]="large",e))(Be||{});const me=({show:e=1,scrollbar:o=!1,peak:p=!1,arrows:_=!1,controls:s="dots",arrowsOnMainImage:y=!1,loop:h=!1,gap:P=null,direction:l="horizontal",width:le="100%",height:d="100%",defaultIndex:b=0,className:V,children:q,thumbnails:C=null,isZoomed:S,...f})=>{const u=z("PDP.Carousel.label").label,n=z("PDP.Carousel.Slide.label").label,L=z("PDP.Carousel.Previous.label").label,M=z("PDP.Carousel.Next.label").label,A=z("PDP.Carousel.Controls.Button.label").label,[g,r]=J(()=>ke(e)),O=Math.ceil(de.count(q)/g),R=p?Ke:0,j=P?Be[P]:0,X=de.count(q)%g,[k,B]=J(h?b+1:b),ne=ye([]),[ce,he]=J(0),[ie,re]=J(0),oe=ve(()=>de.toArray(C),[C]),$=ve(()=>{const c=de.toArray(q).reduce((i,N,D)=>D%g===0?[...i,[N]]:[...i.slice(0,-1),[...i[i.length-1],N]],[]);return!h||c.length===1?c:h&&de.count(q)%g===0?[c[O-1]].concat(c).concat([c[0],c[1]]):[de.toArray(q).slice(-g)].concat(c).concat([c[0],c[1]])},[q,g,O,h]),F=ye(null),K=ye(null),I=s==="thumbnailsRow"||s==="thumbnailsColumn";te(()=>{const c=document.body,i=Le(()=>{var T,ee;he(((T=F.current)==null?void 0:T.offsetWidth)??0),re(((ee=F.current)==null?void 0:ee.offsetHeight)??0);const D=window.innerWidth,W=ke(e,D);W!==g&&r(W)},50),N=new ResizeObserver(i);return N.observe(c),()=>{N.unobserve(c)}},[g,e]);const ae=Y(c=>{const i=h?c-1:c,N=ne==null?void 0:ne.current[0],D=(N==null?void 0:N.offsetWidth)+ge,W=(N==null?void 0:N.offsetHeight)+ge,T=K.current,ee=s==="thumbnailsRow",Ae=s==="thumbnailsColumn",se=ee?T==null?void 0:T.offsetWidth:T==null?void 0:T.offsetHeight,Q=ee?D:W;(ee||Ae)&&se&&(Q*(i+1)>se&&(T.style.scrollBehavior="smooth",ee?T.scrollLeft=(i+_e)*Q:T.scrollTop=(i+_e)*Q),(ee?T.scrollLeft:T.scrollTop)>Q*i&&(T.style.scrollBehavior="smooth",ee?T.scrollLeft=(i-_e)*Q:T.scrollTop=(i-_e)*Q))},[s,h]);te(()=>{ae(k)},[k,ae]);const a=Y((c,i,N)=>{I&&ae(c);const D=F.current,W=R?D.offsetWidth-R:D.offsetWidth-R+j;if(!Array.from(D.querySelectorAll("[data-index]")).filter(se=>{const Q=Number(se.getAttribute("data-index"));return!isNaN(Q)&&Q>-1})[c])return;if(N){const se=c===0?O:0,Q=W*(O+(X||g)/g);if(D.scrollLeft>=0&&D.scrollLeft<W-5){a(1,!0);return}if(D.scrollLeft>Q-W&&D.scrollLeft<=Q){a(O,!0);return}D.style.scrollBehavior="auto",D.scrollLeft=se===0?0:Q,a(se===0?1:O,!0);return}const Ae=(D.offsetWidth-j)/g*$[c].length-R;D.style.scrollBehavior=i?"smooth":"auto",D.scrollLeft=$[c].length===g?W*c:W*(c-1)+Ae},[j,O,R,g,X,$,ae,s]),m=Y(()=>{if(h){const i=k-1;a(i,!0,k===1);return}const c=k<=0?0:k-1;a(c,!0)},[k,a,h]),v=Y(()=>{const c=$.length-1;if(h){const N=k+1;a(N,!0,k===O);return}const i=k>=c?c:k+1;a(i,!0)},[$.length,h,k,a,O]);te(()=>{const c=i=>{i.key==="ArrowLeft"&&(i.preventDefault(),m()),i.key==="ArrowRight"&&(i.preventDefault(),v())};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c)}},[v,m]),te(()=>{a(h?b+1:b,!1)},[b,a,h]);const w=Le(()=>{const c=F.current,i=R?c.offsetWidth-R:c.offsetWidth-R+j,N=c.scrollLeft/i,D=Math.round(N)-N<1?Math.round(N):Math.ceil(N);if(I&&ae(D),h){const W=i*(O+(X||g)/g);if(Math.ceil(c.scrollLeft)>=Math.ceil(W)-5){c.style.scrollBehavior="auto",c.scrollLeft=c.offsetWidth*1+(Math.ceil(c.scrollLeft)-Math.ceil(W)-R);return}if(c.scrollLeft===0){c.style.scrollBehavior="auto",c.scrollLeft=W-c.offsetWidth+R;return}}k!==D&&B(D)},100);te(()=>{const c=F.current;return c==null||c.addEventListener("scroll",w),()=>{c==null||c.removeEventListener("scroll",w)}},[w]);const x=(c,i,N)=>t(we,{className:E([["pdp-carousel__button",!c],[`pdp-carousel__button--${i}`,!c],[`pdp-carousel__button--${s}`,c]]),style:{"--height":`${ie}px`},variant:"tertiary","aria-label":i==="next"?M:L,onClick:N,disabled:h?!1:i==="next"?k>=$.length-1:k<1,children:t(be,{className:E([["pdp-carousel__button__icon",!c],[`pdp-carousel__button__icon--${i}`,!c],[`pdp-carousel__button__icon--${s}--${i}`,c]]),size:Qe,source:ze})}),Z=_&&$.length!=1&&x(I,"prev",m),ue=_&&$.length!=1&&x(I,"next",v),fe=_&&$.length!=1&&x(!1,"prev",m),Te=_&&$.length!=1&&x(!1,"next",v);return U("div",{role:"region","aria-roledescription":u,className:E(["pdp-carousel",["pdp-carousel--main-image-controls",y],["pdp-carousel--arrows",_&&!I],[`pdp-carousel--${s}`,I],V]),style:{"--flex-carousel":s==="thumbnailsColumn"?"row-reverse":"column","--gap":I?"0":"var(--spacing-small)","--width":le},...f,children:[t("div",{ref:F,className:E(["pdp-carousel__wrapper",`pdp-carousel__wrapper--${l}`,["pdp-carousel__wrapper--scrollbar",o],["pdp-carousel__wrapper--peak",p]]),style:{"--total-width":s==="thumbnailsColumn"?"81.6%":"100%","--height":s==="thumbnailsColumn"?"auto":d,"--gap":P?`var(--spacing-${P})`:"0px","--per-page":g},tabIndex:0,children:$.map((c,i)=>{const N=c.length<g;return t("div",{role:"group","aria-roledescription":n,"data-index":i,className:E(["pdp-carousel__slide",`pdp-carousel__slide--${l}`,["pdp-carousel__slide--active",k===i],["pdp-carousel__slide--orphan",N]]),style:{"--length":c.length},children:c},i)})}),!I&&U(Pe,{children:[Z,ue]}),I&&y&&U(Pe,{children:[fe,Te]}),s&&$.length!=1&&U("div",{className:E([[`pdp-carousel__controls__container--${s}`,I],["pdp-carousel__controls__container--no-arrows",!_||y]]),style:{"--width":s==="thumbnailsRow"?`${ce}px`:le,"--height":`${ie}px`,"--nr-thumbnails":oe.length},children:[(I||S)&&!y&&Z,t("div",{ref:K,className:E([[`pdp-carousel__controls__wrapper--${s}`,I],["pdp-carousel__controls__wrapper",I]]),children:t("div",{role:"group","aria-label":A,className:E(["pdp-carousel__controls",[`pdp-carousel__controls--${s}`,I]]),children:(h?$.slice(0,O):$).map((c,i)=>{const N=h?O:$.length,D=h?k-1===i:k===i;return I?U("label",{className:E(["pdp-carousel__thumbnail__container"]),ref:W=>{W&&(ne.current[i]=W)},children:[t("input",{type:"radio",name:"carousel-thumbnails","aria-label":A.replace("{key}",String(i+1)).replace("{total}",String(N)),checked:D&&ce!==0,onChange:()=>{a(h?i+1:i,!0)},...f,className:E(["pdp-carousel__thumbnail",["pdp-carousel__thumbnail--selected",D&&ce!==0]])}),t("span",{className:E(["pdp-carousel__thumbnail__span"]),children:oe[i]})]},i):t("button",{"aria-label":A.replace("{key}",String(i+1)).replace("{total}",String(N)),onClick:()=>{a(h?i+1:i,!0)},className:E(["pdp-carousel__controls__button",["pdp-carousel__controls__button--active",D]])},i)})})}),(I||S)&&!y&&ue]})]})};function ke(e,o=0){if(typeof e=="number")return e;const{small:p,medium:_,large:s}=e,h=[{breakpoint:1024,value:s},{breakpoint:786,value:_},{breakpoint:0,value:p}].find(({breakpoint:P})=>o>P);return h?h.value:p}const Xe=({title:e,breadcrumbs:o,galleryContent:p,infoContent:_,productContent:s,sku:y,outOfStock:h,shortDescription:P,description:l,attributes:le,images:d,options:b,price:V,specialPrice:q,className:C,children:S,quantity:f,actions:u,carouselConfig:n,...L})=>{var k,B,ne,ce,he,ie,re,oe,$;const M=z("PDP.Product.RegularPrice.label").label,A=z("PDP.Product.SpecialPrice.label").label,g=z("PDP.Product.OutOfStock.label").label,r=z("PDP.Product.Image.label").label,[O,R]=J(null),j=d!=null&&d.length?d.map((F,K)=>{var I;return t(H,{node:F,loading:K===0?"eager":"lazy",alt:((I=e==null?void 0:e.props)==null?void 0:I.children)&&(r==null?void 0:r.replace("{product}",e.props.children.toString()).replace("{key}",String(K+1)).replace("{total}",String(d.length))),onClick:()=>R(K)},K)}):t("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0}),X=(k=n==null?void 0:n.thumbnails)!=null&&k.length?n.thumbnails.map((F,K)=>{var I;return t(H,{node:F,loading:(n==null?void 0:n.thumbnailsLoadingMode)||"lazy",alt:((I=e==null?void 0:e.props)==null?void 0:I.children)&&(r==null?void 0:r.replace("{product}",e.props.children.toString()).replace("{key}",String(K+1)).replace("{total}",String(d.length)))},K)}):t("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0});return U("div",{...L,className:E(["pdp-product",C]),children:[o&&t(H,{node:o,className:"pdp-product__breadcrumbs"}),U("div",{className:"pdp-product__column-container pdp-product__gallery-column",children:[t("div",{className:"pdp-product__column-body",children:(B=n==null?void 0:n.controls)!=null&&B.desktop?t(me,{className:"pdp-product__overlay__carousel",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?n.controls.desktop:"dots",arrowsOnMainImage:n==null?void 0:n.arrowsOnMainImage,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,peak:((ne=n==null?void 0:n.thumbnails)==null?void 0:ne.length)>1&&((ce=n==null?void 0:n.peak)==null?void 0:ce.desktop)||!1,gap:(n==null?void 0:n.gap)||null,width:"100%",height:"100%",defaultIndex:O||0,thumbnails:X,children:j}):t(Ze,{className:"pdp-product__images",gap:"small",children:j})}),p&&t(H,{node:p,className:"pdp-product__gallery-content"})]}),U("div",{className:"pdp-product__column-container pdp-product__content-column",children:[U("div",{className:"pdp-product__column-body",children:[U("div",{className:"pdp-product__header",children:[e&&t(H,{node:e,className:"pdp-product__title"}),y&&t(H,{node:y,className:"pdp-product__sku"})]}),U("div",{className:"pdp-product__prices",children:[q&&t(H,{node:q,className:E(["pdp-product__price-special","pdp-product__price"]),"aria-label":A,role:"text"}),V&&t(H,{node:V,className:E(["pdp-product__price-regular","pdp-product__price--grey"]),"aria-label":M,role:"text"})]}),(he=n==null?void 0:n.controls)!=null&&he.mobile&&((ie=n==null?void 0:n.controls)==null?void 0:ie.mobile)==="thumbnailsRow"?t(me,{className:"pdp-product__images pdp-product__images--carousel pdp-product__images--carousel--thumbnails",width:"100%",height:"auto",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"thumbnailsRow":null,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,peak:((re=n==null?void 0:n.thumbnails)==null?void 0:re.length)>1&&((oe=n==null?void 0:n.peak)==null?void 0:oe.mobile)||!1,gap:(n==null?void 0:n.gap)||null,thumbnails:X,children:j}):t(me,{className:"pdp-product__images pdp-product__images--carousel",peak:(($=n==null?void 0:n.peak)==null?void 0:$.mobile)&&(d==null?void 0:d.length)>1,gap:(n==null?void 0:n.gap)||null,width:"100%",height:"auto",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"dots":null,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,children:j}),U("div",{className:E(["pdp-product__actions",["pdp-product__actions--out-of-stock",h]]),children:[h&&t("div",{className:"pdp-product__out-of-stock__text",children:g}),b&&t(H,{node:b,className:E(["pdp-product__options"])}),f&&t("div",{className:"pdp-product__quantity",children:t(H,{node:f})}),u&&t(H,{node:u,className:E(["pdp-product__buttons"])})]}),P&&t(H,{node:P,className:E(["pdp-product__short_description"])}),l&&t(H,{node:l,className:E(["pdp-product__description"])}),le?t("div",{className:"pdp-product__attributes",children:le}):null]}),_&&t(H,{node:_,className:"pdp-product__info-content"})]}),s&&t(H,{node:s,className:"pdp-product__content"}),O===null?null:t(Je,{className:"pdp-product__overlay",onClose:()=>R(null),centered:!0,children:t(me,{className:"pdp-product__overlay__carousel",arrows:(d==null?void 0:d.length)>1,width:"100%",height:"100%",defaultIndex:O||0,loop:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"dots":null,isZoomed:!0,children:j})})]})},Ze=({children:e,gap:o=null,className:p,style:_,...s})=>{const y=de.count(e);return t("div",{...s,className:E(["pdp-gallery-grid",p]),style:{"--gap":o?`var(--spacing-${o})`:"0px",..._},children:de.map(e,(h,P)=>t("div",{className:"pdp-gallery-grid__item",children:t(H,{node:h,loading:P===0?"eager":"lazy"},h.props.src)},y+P))})},Ie=({amount:e,currency:o,locale:p,variant:_,sale:s,minimumAmount:y,maximumAmount:h,className:P,...l})=>t(Pe,{children:e||y===h?t("div",{className:"pdp-price-range",...l,children:t(Se,{amount:e||y,currency:o,locale:p,variant:_,sale:s,className:P})}):U("div",{className:"pdp-price-range",...l,children:[t(Se,{amount:y,currency:o,locale:p,className:P}),t("span",{className:"pdp-price-range__label",children:"-"}),t(Se,{amount:h,currency:o,locale:p,className:P})]})}),Je=({centered:e,onClose:o,className:p,children:_,...s})=>{const y=z("PDP.Overlay.Close.label").label,h=Y(()=>{o==null||o()},[o]);return te(()=>{const P=l=>{l.key==="Escape"&&h()};return document.addEventListener("keydown",P),()=>{document.removeEventListener("keydown",P)}},[h]),te(()=>{const P=document.scrollingElement,l=P.style.overflow;return P.style.overflow="hidden",()=>{P.style.overflow=l}},[]),U("div",{...s,className:E(["pdp-overlay",["pdp-overlay--centered",e],p]),children:[t("div",{className:"pdp-overlay__content",children:_}),t(we,{"aria-label":y,variant:"tertiary",className:"pdp-overlay__close-button",onClick:h,icon:t(Fe,{})})]})},Ye=["text","image","color","dropdown"],Ce=e=>e.map(o=>({...o,text:o.label,disabled:!o.inStock})),et=({options:e,hideSelectedValue:o,onValues:p,onErrors:_,defaultOptions:s,selectionsToUpdate:y,className:h,children:P,...l})=>{const le=z("PDP.Swatches.Required.label").label,[d,b]=J(()=>e==null?void 0:e.reduce((f,u)=>{const{items:n}=u,L=n==null?void 0:n.find(A=>s==null?void 0:s.includes(A.id)),M=n==null?void 0:n.find(A=>A.selected);return L?{...f,[u.id]:{label:L.label,value:L.id}}:M?{...f,[u.id]:{label:M.label,value:M.id}}:f},{}));te(()=>{y==null||y.forEach(S=>{b(f=>{var L;const u=(L=S==null?void 0:S.items)==null?void 0:L.find(M=>M.selected);return u?{...f,[S.id]:{label:u==null?void 0:u.label,value:u==null?void 0:u.id}}:f})})},[y,b]),ve(()=>{const S=e==null?void 0:e.reduce((f,u)=>{var n;return(n=u==null?void 0:u.items)==null||n.forEach(L=>{var A;const M=((A=d[u.id])==null?void 0:A.value)===L.id;u.required&&!M&&(f[u.id]=le)}),f},{});return _==null||_(S),S},[d]);const V=Y((S,f,u)=>{b(n=>{const L={...n,[S]:{label:f,value:u}};return p==null||p(L,u),L})},[p]),q=(S,f)=>{var n;const u=((n=f.selectedOptions[0])==null?void 0:n.label)??"";V(S,u,f.value)},C=Y(({items:S,id:f,required:u,type:n,selected:L,label:M})=>t("div",{className:E(["pdp-swatches__options"]),children:(n==null?void 0:n.toLowerCase())==="dropdown"?t(We,{"aria-label":M,handleSelect:A=>q(f,A.target),options:Ce(S),value:L}):S==null?void 0:S.map(A=>{const g={key:A.id,id:A.id,name:f,value:A.value,label:A.label,groupAriaLabel:M,selected:L===A.id,outOfStock:!A.inStock,required:u===null?!0:u,onValue:()=>{V(f,A.label,A.id)}};switch(n){case"text":return t(Ve,{...g,label:A.label});case"image":return t(He,{...g,src:A.value,alt:A.label});case"color":return t(Ue,{...g,size:"large",color:A.value});default:return console.warn(`Invalid swatch type ${n}`),null}})}),[V]);return t("div",{...l,className:E(["pdp-swatches",h]),children:e==null?void 0:e.map(({type:S,label:f,id:u,multiple:n,required:L,items:M})=>{var A;if(!S){console.warn("Bundle product not supported on UI.");return}return Ye.includes(S)||console.warn(`Invalid swatch type ${S}`),n&&console.warn("Multiple selection swatches are not currently supported."),U("div",{id:`swatch-item-${u}`,"data-slot-key":`product-swatch--${u}`,className:"pdp-swatches__field",children:[t("div",{className:"pdp-swatches__field__label",children:d[u]?o?`${f}`:`${f}: ${d[u].label}`:f}),t(C,{id:u,type:S,required:L,items:M,label:f,selected:(A=d[u])==null?void 0:A.value})]},`swatch-item-${u}`)})})};function tt(e,o="en_US"){if(!Me(e))throw Error("Invalid date string");return e.split(" ")[1]||(e=`${e} 00:00:00`),new Date(e).toLocaleDateString(Ne(o)).toString()}function Me(e){if(![/^\d{4}-\d{2}-\d{2}$/,/^\d{1,2}\/\d{1,2}\/\d{4}$/,/^\d{2}\/\d{2}\/\d{4}$/,/^\d{4}\/\d{2}\/\d{2}$/,/^\d{1,2}\.\d{1,2}\.\d{4}$/,/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/].some(_=>_.test(e)))return!1;const p=new Date(e);return!isNaN(p.getTime())}function nt(e){const o=new URLSearchParams(window.location.search);Object.entries(e).forEach(([_,s])=>{s===null?o.delete(_):o.set(_,String(s))});let p=window.location.pathname;p+=`?${o.toString()}`,p+=window.location.hash,window.history.replaceState({},"",p)}function rt(){const e=new URLSearchParams(window.location.search),o={};return e.forEach((p,_)=>{o[_]=p}),o}function lt(e){var o,p,_,s,y,h,P,l;return{productId:Number(e==null?void 0:e.externalId),name:e==null?void 0:e.name,sku:e==null?void 0:e.sku,topLevelSku:e==null?void 0:e.externalParentId,specialToDate:void 0,specialFromDate:void 0,newToDate:void 0,newFromDate:void 0,createdAt:void 0,updatedAt:void 0,manufacturer:void 0,countryOfManufacture:void 0,categories:void 0,productType:void 0,pricing:{regularPrice:((p=(o=e==null?void 0:e.prices)==null?void 0:o.regular)==null?void 0:p.amount)||0,minimalPrice:void 0,maximalPrice:void 0,specialPrice:(s=(_=e==null?void 0:e.prices)==null?void 0:_.final)==null?void 0:s.amount,tierPricing:void 0,currencyCode:((h=(y=e==null?void 0:e.prices)==null?void 0:y.final)==null?void 0:h.currency)||"USD"},canonicalUrl:e==null?void 0:e.url,mainImageUrl:(l=(P=e==null?void 0:e.images)==null?void 0:P[0])==null?void 0:l.url}}const ct={PRODUCT_CONTEXT:"productContext"},at={PRODUCT_PAGE_VIEW:"product-page-view"};function Re(){return window.adobeDataLayer=window.adobeDataLayer||[],window.adobeDataLayer}function dt(e,o){const p=Re();p.push({[e]:null}),p.push({[e]:o})}function it(e,o){Re().push(_=>{const s=_.getState?_.getState():{};_.push({event:e,eventInfo:{...s,...o}})})}function Ee(e){const o=lt(e);dt(ct.PRODUCT_CONTEXT,o),it(at.PRODUCT_PAGE_VIEW)}const ot=({sku:e,hideSku:o,hideQuantity:p,hideShortDescription:_,hideDescription:s,hideAttributes:y,hideURLParams:h,hideSelectedOptionValue:P,slots:l,children:le,initialData:d,carousel:b,optionsConfig:V,useACDL:q,onAddToCart:C,...S})=>{var F,K,I,ae;const f=z("PDP.Product.AddToCart.label").label,u=z("PDP.Product.Incrementer.label").label,n=z("PDP.Product.Details.label").label,[L,M]=J(Oe.getConfig().defaultLocale||"en-US"),[A,g]=J(),[r=null,O]=J(d),[R,j]=J(()=>{const a={sku:e,quantity:1};return r!=null&&r.optionUIDs&&(a.optionsUIDs=r.optionUIDs),a}),[X,k]=J(()=>{var a,m;return!(r!=null&&r.options&&((a=r==null?void 0:r.options)==null?void 0:a.length)>0&&((m=r==null?void 0:r.optionUIDs)==null?void 0:m.length)!==(r==null?void 0:r.options.length))}),B={data:r,values:R,valid:X};te(()=>{const a=Ge.on("locale",m=>{m!==L&&(M(m),xe(e).then(O))});return()=>{a==null||a.off()}},[L,e]),te(()=>{q&&d&&Object.keys(d).length>0&&Ee(d)},[d]);const ne=Y(a=>{j(m=>({...m,...a}))},[]),ce=Y(a=>{var v;let m=Object.keys(a).map(w=>a[w].value).filter(w=>w!==void 0);h||nt({optionsUIDs:m.join(",")}),j(w=>({...w,optionsUIDs:m})),k((m==null?void 0:m.length)===((v=r==null?void 0:r.options)==null?void 0:v.length)),$e(e,m,V==null?void 0:V.anchorOptions).then(w=>{var x;O(w),(x=V==null?void 0:V.anchorOptions)!=null&&x.length&&he(w,m),q&&(w==null?void 0:w.sku)!==e&&Ee(w)})},[e]),he=Y((a,m)=>{var x;const v=(a==null?void 0:a.optionUIDs)??[];m.every(Z=>v.includes(Z))||(g(a==null?void 0:a.options),j(Z=>({...Z,optionsUIDs:v})),k((v==null?void 0:v.length)===((x=a==null?void 0:a.options)==null?void 0:x.length)))},[e]),ie=Y(a=>{Object.keys(a).length!==0&&k(!1)},[]),re=ve(()=>{var a;return(a=r==null?void 0:r.attributes)==null?void 0:a.map(({label:m,value:v},w)=>{const x=Me(v)?tt(v,L):v.toString();return U("li",{children:[m,": ",t("span",{dangerouslySetInnerHTML:{__html:x}})]},w)})},[r==null?void 0:r.attributes,L]),oe=!p&&(r!=null&&r.inStock)?t(G,{name:"Quantity",slot:l==null?void 0:l.Quantity,context:{...B},children:t(qe,{name:"quantity",defaultValue:R.quantity.toString(),min:1,"aria-label":u,className:"pdp-product__quantity",onValue:a=>{ne({quantity:Number(a)})}},"quantity")}):void 0,$=()=>{if(r!=null&&r.options)return t(G,{name:"Options",slot:l==null?void 0:l.Options,context:{...B},children:t(et,{options:r.options,defaultOptions:R.optionsUIDs,selectionsToUpdate:A,hideSelectedValue:P,onValues:ce,onErrors:ie})})};return t("div",{...S,children:t(Xe,{title:t(G,{name:"Title",slot:l==null?void 0:l.Title,context:{...B},children:r==null?void 0:r.name}),sku:o?void 0:t(G,{name:"SKU",slot:l==null?void 0:l.SKU,context:{...B},children:r==null?void 0:r.sku}),options:$(),breadcrumbs:(l==null?void 0:l.Breadcrumbs)&&t(G,{name:"Breadcrumbs",slot:l==null?void 0:l.Breadcrumbs,context:{...B,setSeparator(a){this._registerMethod((...m)=>{const v=a(...m),w=v&&t(be,{source:v});this._setProps(x=>({...x,separator:w}))})},appendLink(a){this._registerMethod((...m)=>{const{text:v,...w}=a(...m),x=t("a",{...w,children:v});this._setProps(Z=>({...Z,categories:[...Z.categories||[],x]}))})},appendHTMLElement(a){this._registerMethod((...m)=>{const v=a(...m),w=this._htmlElementToVNode(v);this._setProps(x=>({...x,categories:[...x.categories||[],w]}))})}},render:({separator:a,categories:m})=>t(je,{separator:a,categories:m})}),quantity:oe,actions:t(G,{name:"Actions",slot:l==null?void 0:l.Actions,context:{...B,appendButton(a){this._registerMethod((...m)=>{const v=a(...m);if(!v)return;const{text:w,icon:x,...Z}=v,ue=t(we,{type:"button",...Z,icon:x&&t(be,{source:x}),children:w});this._setProps(fe=>({children:[...fe.children||[],ue]}))})}},children:!(l!=null&&l.Actions)&&t(we,{size:"medium",type:"submit",icon:t(be,{source:"Cart"}),disabled:!(r!=null&&r.inStock)||!X,"aria-label":f,onClick:()=>C==null?void 0:C(R),children:f})}),shortDescription:_?void 0:t(G,{name:"ShortDescription",slot:l==null?void 0:l.ShortDescription,context:{...B},children:t("div",{dangerouslySetInnerHTML:{__html:(r==null?void 0:r.shortDescription)??""}})}),description:s?void 0:t(G,{name:"Description",slot:l==null?void 0:l.Description,context:{...B},children:t("div",{dangerouslySetInnerHTML:{__html:(r==null?void 0:r.description)??""}})}),images:((F=r==null?void 0:r.images)==null?void 0:F.map(({label:a,url:m})=>{var v,w;return t(De,{title:a,alt:a,src:m,width:((v=b==null?void 0:b.imageParams)==null?void 0:v.width)??960,height:((w=b==null?void 0:b.imageParams)==null?void 0:w.height)??1191,params:(b==null?void 0:b.imageParams)??{width:960}},m)}))??[],specialPrice:(K=r==null?void 0:r.prices)!=null&&K.visible?t(G,{name:"SpecialPrice",slot:l==null?void 0:l.SpecialPrice,context:{...B},children:t(Ie,{...r.prices.final,locale:Ne(L)})}):void 0,price:(I=r==null?void 0:r.prices)!=null&&I.visible&&r.prices.regular&&r.prices.final.amount!==(r==null?void 0:r.prices.regular.amount)?t(G,{name:"RegularPrice",slot:l==null?void 0:l.RegularPrice,context:{...B},children:t(Ie,{...r.prices.regular,locale:Ne(L)})}):void 0,carouselConfig:{...b,thumbnails:b&&Object.keys(b).length?((ae=r==null?void 0:r.images)==null?void 0:ae.map(({label:a,url:m})=>{var v,w;return t(De,{title:a,alt:a,src:m,width:((v=b==null?void 0:b.thumbnailParams)==null?void 0:v.width)??200,height:((w=b==null?void 0:b.thumbnailParams)==null?void 0:w.height)??248,params:(b==null?void 0:b.thumbnailParams)??{width:200}},m)}))??[]:[]},outOfStock:!(r!=null&&r.inStock),attributes:y?void 0:t(G,{name:"Attributes",slot:l==null?void 0:l.Attributes,context:{...B},children:re!=null&&re.length?U(Pe,{children:[n,t("ul",{children:re})]}):null}),galleryContent:(l==null?void 0:l.GalleryContent)&&t(G,{name:"GalleryContent",slot:l.GalleryContent,context:{...B}}),infoContent:(l==null?void 0:l.InfoContent)&&t(G,{name:"InfoContent",slot:l.InfoContent,context:{...B}}),productContent:(l==null?void 0:l.Content)&&t(G,{name:"Content",slot:l.Content,context:{...B}})})})};ot.getInitialData=async function({sku:e,optionsConfig:o}){var _,s,y,h,P,l;const p=((_=rt().optionsUIDs)==null?void 0:_.split(","))||((l=(P=(h=(y=(s=Oe)==null?void 0:s.getConfig())==null?void 0:y.models)==null?void 0:h.ProductDetails)==null?void 0:P.initialData)==null?void 0:l.optionsUIDs);return p!=null&&p.length?await $e(e,p,o==null?void 0:o.anchorOptions):await xe(e)};export{ot as ProductDetails,ot as default};
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/storefront-pdp", "version": "0.2.3-alpha6", "@dropins/tools": "0.25.0"}
1
+ {"name": "@dropins/storefront-pdp", "version": "0.2.3-beta1", "@dropins/tools": "0.25.0"}