@occluze/tether 0.9.4 → 0.9.6

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.
Files changed (46) hide show
  1. package/README.md +2 -2
  2. package/dist/esm/astro.js +1 -1
  3. package/dist/esm/chunks/{account-2467DHLU.js → account-GZLRHV5Z.js} +1 -1
  4. package/dist/esm/chunks/{account-pages-X7U3E7D7.js → account-pages-32IFOHYU.js} +1 -1
  5. package/dist/esm/chunks/{analytics-TF7M4KI2.js → analytics-OIQ4TFGM.js} +1 -1
  6. package/dist/esm/chunks/chunk-33IQL4XN.js +1 -0
  7. package/dist/esm/chunks/{chunk-I7XE7GQR.js → chunk-AMCCY6T4.js} +1 -1
  8. package/dist/esm/chunks/chunk-COXH5OXQ.js +1 -0
  9. package/dist/esm/chunks/{chunk-646NGAEM.js → chunk-DQJRQBJG.js} +1 -1
  10. package/dist/esm/chunks/chunk-ESYKAFMU.js +1 -0
  11. package/dist/esm/chunks/chunk-HO6SNO3A.js +1 -0
  12. package/dist/esm/chunks/{chunk-UM37ZVSP.js → chunk-HZYW2TS3.js} +1 -1
  13. package/dist/esm/chunks/{chunk-EYVBEFKK.js → chunk-JJVUNGJZ.js} +1 -1
  14. package/dist/esm/chunks/{chunk-F3OXGENC.js → chunk-KW7UPDXI.js} +1 -1
  15. package/dist/esm/chunks/chunk-LZINCBME.js +1 -0
  16. package/dist/esm/chunks/{chunk-6FWNC7QH.js → chunk-NOTL72DB.js} +1 -1
  17. package/dist/esm/chunks/{chunk-4QINHHE4.js → chunk-TES2AUFT.js} +1 -1
  18. package/dist/esm/chunks/{chunk-HEK66LYK.js → chunk-TUVLYVMF.js} +1 -1
  19. package/dist/esm/chunks/{chunk-AHYDU7Z6.js → chunk-U5BYAOTP.js} +1 -1
  20. package/dist/esm/chunks/{chunk-B2X6ZOKA.js → chunk-UDJ62MPR.js} +1 -1
  21. package/dist/esm/chunks/chunk-UU2VVXU2.js +1 -0
  22. package/dist/esm/chunks/{diagnose-AOSBLXOJ.js → diagnose-QTIUBMXT.js} +1 -1
  23. package/dist/esm/chunks/extras-56DC6CHI.js +1 -0
  24. package/dist/esm/chunks/{lists-UJMD7BCQ.js → lists-SE5VBQ4K.js} +1 -1
  25. package/dist/esm/chunks/{markets-ui-PTAY3FHU.js → markets-ui-GQOUGLUL.js} +1 -1
  26. package/dist/esm/chunks/{search-G2SRQXDG.js → search-ZAB5GJOK.js} +1 -1
  27. package/dist/esm/index.js +1 -1
  28. package/dist/esm/server.js +1 -1
  29. package/dist/tether.extras.js +32 -10
  30. package/dist/tether.extras.min.js +1 -1
  31. package/dist/tether.js +72 -38
  32. package/dist/tether.min.js +1 -1
  33. package/dist/tether.min.js.map +3 -3
  34. package/dist/types/src/cart/store.d.ts +1 -1
  35. package/dist/types/src/cart.d.ts +1 -1
  36. package/dist/types/src/dom.d.ts +7 -5
  37. package/dist/types/src/extras.d.ts +2 -0
  38. package/dist/types/src/version.d.ts +1 -1
  39. package/package.json +1 -1
  40. package/dist/esm/chunks/chunk-5TS6IBBB.js +0 -1
  41. package/dist/esm/chunks/chunk-67MCLHFS.js +0 -1
  42. package/dist/esm/chunks/chunk-C2GKO34C.js +0 -1
  43. package/dist/esm/chunks/chunk-KIZBET7N.js +0 -1
  44. package/dist/esm/chunks/chunk-UJYL5G7T.js +0 -1
  45. package/dist/esm/chunks/chunk-YW3ZIFWB.js +0 -1
  46. package/dist/esm/chunks/extras-THTXX76O.js +0 -1
@@ -1,4 +1,4 @@
1
- import{e as E}from"./chunk-646NGAEM.js";import{a as M}from"./chunk-UJYL5G7T.js";import{b as h,e as A}from"./chunk-UM37ZVSP.js";import{c as D}from"./chunk-I7XE7GQR.js";import"./chunk-6FWNC7QH.js";import{d as P,e as $,i as v,m as p,n as l,o as m,q as d,y as S}from"./chunk-67MCLHFS.js";import{C as w,c as k,x as a}from"./chunk-YW3ZIFWB.js";var R=new Set(["in-stock","out-of-stock","backorder","low-stock","plenty-in-stock","on-sale","not-on-sale","has-variants","single-variant","subscription-available","subscription-unavailable","subscription-only","one-time-available","subscription-selected","one-time-selected","has-savings","loading","ready","error","not-found","cart-empty","cart-filled","cart-has-subscription","cart-no-subscription","cart-has-discount","cart-error","cart-warning","list-empty","list-filled","search-empty","search-results","logged-in","logged-out","orders-empty","orders-loading","addresses-loading","addresses-empty","addresses-error","subscriptions-loading","subscriptions-empty","subscriptions-error"]),N=new Set(["title","description","description-text","vendor","type","handle","published-at","price","total-price","compare-at-price","unit-price","min-price","max-price","discount-percentage","discount-amount","variant-title","variant-id","sku","barcode","stock","quantity","featured-image","variant-image","images","tags","link","url","one-time-price","subscription-price","subscription-savings","subscription-savings-amount","checkout-charge","plan-name","plan-description","plan-group","option-value","swatch","image"]),x=new Set(`account account-bind account-link account-login account-logout add-label add-to-cart adding-text
1
+ import{e as E}from"./chunk-DQJRQBJG.js";import{a as M}from"./chunk-UU2VVXU2.js";import{b as h,e as A}from"./chunk-HZYW2TS3.js";import{c as D}from"./chunk-AMCCY6T4.js";import"./chunk-NOTL72DB.js";import{d as P,e as $,i as v,m as p,n as l,o as m,q as d,y as S}from"./chunk-HO6SNO3A.js";import{C as w,c as k,x as a}from"./chunk-ESYKAFMU.js";var R=new Set(["in-stock","out-of-stock","backorder","low-stock","plenty-in-stock","on-sale","not-on-sale","has-variants","single-variant","subscription-available","subscription-unavailable","subscription-only","one-time-available","subscription-selected","one-time-selected","has-savings","loading","ready","error","not-found","cart-empty","cart-filled","cart-has-subscription","cart-no-subscription","cart-has-discount","cart-error","cart-warning","list-empty","list-filled","search-empty","search-results","logged-in","logged-out","orders-empty","orders-loading","addresses-loading","addresses-empty","addresses-error","subscriptions-loading","subscriptions-empty","subscriptions-error"]),N=new Set(["title","description","description-text","vendor","type","handle","published-at","price","total-price","compare-at-price","unit-price","min-price","max-price","discount-percentage","discount-amount","variant-title","variant-id","sku","barcode","stock","quantity","featured-image","variant-image","images","tags","link","url","one-time-price","subscription-price","subscription-savings","subscription-savings-amount","checkout-charge","plan-name","plan-description","plan-group","option-value","swatch","image"]),x=new Set(`account account-bind account-link account-login account-logout add-label add-to-cart adding-text
2
2
  always-enabled bind cart-checkout-charge cart-clear cart-close cart-count cart-discounts cart-drawer cart-label cart-lines
3
3
  cart-note cart-open cart-subtotal cart-total cart-warning checkout code collection collection-bind countries country
4
4
  country-bind country-label country-select default-plan default-purchase discount discount-code discount-form discount-input
@@ -0,0 +1 @@
1
+ import{c as S}from"./chunk-UDJ62MPR.js";import{a as k,b as E}from"./chunk-TUVLYVMF.js";import{a as v}from"./chunk-33IQL4XN.js";import{h as p}from"./chunk-COXH5OXQ.js";import"./chunk-KW7UPDXI.js";import"./chunk-DQJRQBJG.js";import"./chunk-UU2VVXU2.js";import"./chunk-HZYW2TS3.js";import"./chunk-AMCCY6T4.js";import"./chunk-NOTL72DB.js";import{P as w,S as b,a as f,n as u,o as g,p as y,q as h,u as c}from"./chunk-HO6SNO3A.js";import{E as d,F as s,x as l}from"./chunk-ESYKAFMU.js";function C(t,e){let r=b(w(t,"line-attributes"));return e?[{key:"_group",value:e},...r]:r}async function _(t){let e=t.closest(u("group"));if(!e)return null;let r=g(e,"group"),n=C(e,r),i=h(e,u("product")).flatMap(o=>{let a=v.get(o);if(!a?.variant?.availableForSale||a.quantity<=0)return[];let m=a.getLine();return m?[{...m,attributes:[...m.attributes??[],...n]}]:[]});if(!i.length)return d("group-add: nothing selected"),null;try{let o=await p.add(i);return c("group-added",{group:r,lines:i},e),o}catch(o){return s(o,"group add"),null}}function I(t,e,r){t.classList.toggle("is-invalid",r),r?e?.setAttribute("aria-invalid","true"):e?.removeAttribute("aria-invalid")}async function q(t,e,r){try{await p.applyDiscount(r),I(t,e,!1),c("discount-applied",{code:r},t),e&&(e.value="")}catch(n){I(t,e,!0),n instanceof f&&n.code==="INVALID_DISCOUNT"?c("discount-invalid",{code:r},t):s(n,"discount")}}function N(t){if(t.key===l.storageKey||t.key===`${l.storageKey}:seen`){p.init().catch(n=>{s(n,"cart from another tab")});return}if(t.key!==k()||!t.newValue)return;let e=E(t.newValue);if(!e)return;let r={language:e.language??null,locale:e.locale,remember:!1};S(e.country,r).catch(n=>{s(n,"market from another tab")})}var L=new WeakMap,A=t=>t.split("/").pop()??t;function M(t){try{window.history.replaceState(window.history.state,"",t)}catch{}}function $(t,{variant:e,sellingPlanId:r}){let n=`${e.id}|${r??""}`,i=L.get(t);if(L.set(t,n),!i||i===n)return;let o=l.variantUrl&&document.querySelector(u("product"))===t;if(!y(t,"variant-url")&&!o)return;let a=new URL(window.location.href);a.searchParams.set("variant",A(e.id)),r?a.searchParams.set("selling_plan",A(r)):a.searchParams.delete("selling_plan"),M(a)}export{_ as addGroup,q as applyDiscountCode,N as onStorage,$ as writeVariantUrl};
@@ -1 +1 @@
1
- import{a as R}from"./chunk-C2GKO34C.js";import"./chunk-UJYL5G7T.js";import{b as w,d as I,g as T}from"./chunk-UM37ZVSP.js";import{a as H,b as m,d as h}from"./chunk-I7XE7GQR.js";import{c as q,h as x,i as M,j as F}from"./chunk-6FWNC7QH.js";import{F as v,G as E,I as f,M as K,O as A,R as O,a as P,i as a,m as $,n as c,o as s,p as d,r as N,u,x as b,z as k}from"./chunk-67MCLHFS.js";import{F as L,b as l,x as y}from"./chunk-YW3ZIFWB.js";var U="url:",W=`query TetherCollection($handle:String!,$first:Int!,$after:String,$sortKey:ProductCollectionSortKeys,$reverse:Boolean,$filters:[ProductFilter!]){collection(handle:$handle){${q()} products(first:$first,after:$after,sortKey:$sortKey,reverse:$reverse,filters:$filters){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}}`,j="query TetherSearch($first:Int!,$after:String,$query:String,$sortKey:ProductSortKeys,$reverse:Boolean){products(first:$first,after:$after,query:$query,sortKey:$sortKey,reverse:$reverse){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}";async function z({collection:n,query:t,first:r=y.collectionFirst,after:e=null,sortKey:o,reverse:i=!1,filters:D}={}){if(n){let S=await a(h(W),{handle:n,first:r,after:e,sortKey:o||void 0,reverse:i,filters:D??void 0},x);if(!S.collection)throw new P(`Collection not found: ${n}`,{code:"NOT_FOUND"});let{products:g,...Y}=S.collection;return g.nodes.forEach(m),{collection:Y,products:g.nodes,pageInfo:g.pageInfo}}let p=await a(h(j),{first:r,after:e,query:t||void 0,sortKey:o||void 0,reverse:i},M);return p.products.nodes.forEach(m),{collection:null,products:p.products.nodes,pageInfo:p.products.pageInfo}}async function X(n,t="RELATED"){let r=H(typeof n=="object"?n?.id:n);if(!r)throw new P("No product for recommendations",{code:"NOT_FOUND"});let e=r.startsWith("gid://"),i=(await a(h(`query TetherRecs(${e?"$id: ID!":"$handle: String!"},$intent:ProductRecommendationIntent){productRecommendations(${e?"productId: $id":"productHandle: $handle"},intent:$intent){...TetherProduct}}`),e?{id:r,intent:t}:{handle:r,intent:t},F)).productRecommendations??[];return i.forEach(m),i}var Z=n=>n instanceof window.Element,_=(n,t)=>O(n,"limit",{min:1,max:250,fallback:t}),G=n=>n==="COMPLEMENTARY"?"COMPLEMENTARY":"RELATED",C=class{constructor(t){l(this,"root");l(this,"products",[]);l(this,"pageInfo",null);l(this,"collection",null);l(this,"loadToken",0);this.root=t,t.addEventListener("click",r=>{if(!Z(r.target))return;let e=r.target.closest(c("load-more"));e?.closest(R())===t&&(r.preventDefault(),A(e,()=>this.load(!0)))})}$(t){return N(this.root,t,R())}options(){let{root:t}=this,r={reverse:s(t,"reverse")==="true",first:_(t,y.collectionFirst)},e=s(t,"sort");if(e&&(r.sortKey=e),d(t,"collection"))return r.collection=s(t,"collection")??"",r;let o=s(t,"products")??"";return r.query=o.startsWith(U)?new URL(window.location.href).searchParams.get(o.slice(U.length))||"":o,r}async loadRecommendations(){let{key:t}=w(this.root,window.location,"recommendations"),r=this.root.closest(c("product"));return!t&&r&&({key:t}=w(r)),X(t,G(s(this.root,"intent")))}async load(t=!1){this.loadToken+=1;let r=this.loadToken,e=()=>r!==this.loadToken;try{if(d(this.root,"recommendations")){let o=await this.loadRecommendations();if(e())return;this.products=o.slice(0,_(this.root,o.length))}else{let o=await z({...this.options(),after:t?this.pageInfo?.endCursor??null:null});if(e())return;this.collection=o.collection,this.pageInfo=o.pageInfo,this.products=t?[...this.products,...o.products]:o.products}this.render(),T(this.root,"ready"),u("list-ready",{products:this.products,collection:this.collection},this.root)}catch(o){if(e())return;t||T(this.root,I(o)?"not-found":"error",o),I(o)&&d(this.root,"recommendations")||L(o,"list load failed"),u("error",{error:o,context:"list"},this.root)}}render(){let{collection:t}=this;this.$(c("collection-bind")).forEach(e=>{switch(s(e,"collection-bind")??""){case"title":E(e,t?.title??"");break;case"description":v(e,t?.descriptionHtml);break;case"image":b(e,t?.image?.url,t?.image?.altText||t?.title);break;case"count":E(e,this.products.length);break}}),this.$(c("list")).forEach(e=>{k(e,this.products,(o,i)=>{o.setAttribute($("product"),i.handle),o.removeAttribute($("state"))}),u("list-rendered",{container:e},this.root)});let r=this.products.length===0;this.$(c("show")).forEach(e=>{let o=s(e,"show");o==="list-empty"&&f(e,r),o==="list-filled"&&f(e,!r)}),this.$(c("load-more")).forEach(e=>{f(e,!!this.pageInfo?.hasNextPage)}),K("list")}},Q=new WeakMap;function ct(n){let t=Q.get(n);return t||(t=new C(n),Q.set(n,t)),t.load()}export{z as getProducts,X as getRecommendations,ct as loadList};
1
+ import{a as R}from"./chunk-LZINCBME.js";import"./chunk-UU2VVXU2.js";import{b as w,d as I,g as T}from"./chunk-HZYW2TS3.js";import{a as H,b as m,d as h}from"./chunk-AMCCY6T4.js";import{c as q,h as x,i as M,j as F}from"./chunk-NOTL72DB.js";import{F as v,G as E,I as f,M as K,O as A,R as O,a as P,i as a,m as $,n as c,o as s,p as d,r as N,u,x as b,z as k}from"./chunk-HO6SNO3A.js";import{F as L,b as l,x as y}from"./chunk-ESYKAFMU.js";var U="url:",W=`query TetherCollection($handle:String!,$first:Int!,$after:String,$sortKey:ProductCollectionSortKeys,$reverse:Boolean,$filters:[ProductFilter!]){collection(handle:$handle){${q()} products(first:$first,after:$after,sortKey:$sortKey,reverse:$reverse,filters:$filters){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}}`,j="query TetherSearch($first:Int!,$after:String,$query:String,$sortKey:ProductSortKeys,$reverse:Boolean){products(first:$first,after:$after,query:$query,sortKey:$sortKey,reverse:$reverse){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}";async function z({collection:n,query:t,first:r=y.collectionFirst,after:e=null,sortKey:o,reverse:i=!1,filters:D}={}){if(n){let S=await a(h(W),{handle:n,first:r,after:e,sortKey:o||void 0,reverse:i,filters:D??void 0},x);if(!S.collection)throw new P(`Collection not found: ${n}`,{code:"NOT_FOUND"});let{products:g,...Y}=S.collection;return g.nodes.forEach(m),{collection:Y,products:g.nodes,pageInfo:g.pageInfo}}let p=await a(h(j),{first:r,after:e,query:t||void 0,sortKey:o||void 0,reverse:i},M);return p.products.nodes.forEach(m),{collection:null,products:p.products.nodes,pageInfo:p.products.pageInfo}}async function X(n,t="RELATED"){let r=H(typeof n=="object"?n?.id:n);if(!r)throw new P("No product for recommendations",{code:"NOT_FOUND"});let e=r.startsWith("gid://"),i=(await a(h(`query TetherRecs(${e?"$id: ID!":"$handle: String!"},$intent:ProductRecommendationIntent){productRecommendations(${e?"productId: $id":"productHandle: $handle"},intent:$intent){...TetherProduct}}`),e?{id:r,intent:t}:{handle:r,intent:t},F)).productRecommendations??[];return i.forEach(m),i}var Z=n=>n instanceof window.Element,_=(n,t)=>O(n,"limit",{min:1,max:250,fallback:t}),G=n=>n==="COMPLEMENTARY"?"COMPLEMENTARY":"RELATED",C=class{constructor(t){l(this,"root");l(this,"products",[]);l(this,"pageInfo",null);l(this,"collection",null);l(this,"loadToken",0);this.root=t,t.addEventListener("click",r=>{if(!Z(r.target))return;let e=r.target.closest(c("load-more"));e?.closest(R())===t&&(r.preventDefault(),A(e,()=>this.load(!0)))})}$(t){return N(this.root,t,R())}options(){let{root:t}=this,r={reverse:s(t,"reverse")==="true",first:_(t,y.collectionFirst)},e=s(t,"sort");if(e&&(r.sortKey=e),d(t,"collection"))return r.collection=s(t,"collection")??"",r;let o=s(t,"products")??"";return r.query=o.startsWith(U)?new URL(window.location.href).searchParams.get(o.slice(U.length))||"":o,r}async loadRecommendations(){let{key:t}=w(this.root,window.location,"recommendations"),r=this.root.closest(c("product"));return!t&&r&&({key:t}=w(r)),X(t,G(s(this.root,"intent")))}async load(t=!1){this.loadToken+=1;let r=this.loadToken,e=()=>r!==this.loadToken;try{if(d(this.root,"recommendations")){let o=await this.loadRecommendations();if(e())return;this.products=o.slice(0,_(this.root,o.length))}else{let o=await z({...this.options(),after:t?this.pageInfo?.endCursor??null:null});if(e())return;this.collection=o.collection,this.pageInfo=o.pageInfo,this.products=t?[...this.products,...o.products]:o.products}this.render(),T(this.root,"ready"),u("list-ready",{products:this.products,collection:this.collection},this.root)}catch(o){if(e())return;t||T(this.root,I(o)?"not-found":"error",o),I(o)&&d(this.root,"recommendations")||L(o,"list load failed"),u("error",{error:o,context:"list"},this.root)}}render(){let{collection:t}=this;this.$(c("collection-bind")).forEach(e=>{switch(s(e,"collection-bind")??""){case"title":E(e,t?.title??"");break;case"description":v(e,t?.descriptionHtml);break;case"image":b(e,t?.image?.url,t?.image?.altText||t?.title);break;case"count":E(e,this.products.length);break}}),this.$(c("list")).forEach(e=>{k(e,this.products,(o,i)=>{o.setAttribute($("product"),i.handle),o.removeAttribute($("state"))}),u("list-rendered",{container:e},this.root)});let r=this.products.length===0;this.$(c("show")).forEach(e=>{let o=s(e,"show");o==="list-empty"&&f(e,r),o==="list-filled"&&f(e,!r)}),this.$(c("load-more")).forEach(e=>{f(e,!!this.pageInfo?.hasNextPage)}),K("list")}},Q=new WeakMap;function ct(n){let t=Q.get(n);return t||(t=new C(n),Q.set(n,t)),t.load()}export{z as getProducts,X as getRecommendations,ct as loadList};
@@ -1 +1 @@
1
- import{a as E,c as P,d as k,e as T,f as p,g as A}from"./chunk-EYVBEFKK.js";import{a as I}from"./chunk-C2GKO34C.js";import{d as F,e as x}from"./chunk-HEK66LYK.js";import"./chunk-5TS6IBBB.js";import{h as u}from"./chunk-KIZBET7N.js";import"./chunk-F3OXGENC.js";import"./chunk-646NGAEM.js";import"./chunk-UJYL5G7T.js";import"./chunk-UM37ZVSP.js";import{e as w}from"./chunk-I7XE7GQR.js";import"./chunk-6FWNC7QH.js";import{a as L,d as h,i as b,m as s,n as C,o as v,u as z}from"./chunk-67MCLHFS.js";import{F as y,o as f,p as g,x as a}from"./chunk-YW3ZIFWB.js";var _="{name} ({currency})",j="name",d=null;function B(){d=null}var D="query TetherLocalization{localization{country{isoCode name currency{isoCode symbol}}language{isoCode name}availableCountries{isoCode name currency{isoCode symbol}availableLanguages{isoCode name}}}}",O={isoCode:"string",name:"string",currency:"object"},H=h({localization:{country:O,availableCountries:[O]}});function R(){return d??(d=b(D,{},H).then(e=>e.localization,e=>{throw d=null,e})),d}function U(e,n){switch(n){case"name":return e.name;case"code":return e.isoCode;case"currency":return e.currency.isoCode;case"symbol":return e.currency.symbol;default:return""}}var Y=(e,n)=>e.replace(/\{(name|code|currency|symbol)\}/g,(o,i)=>U(n,i));function q(e,n,o){let i=e.getAttribute(s("country-label"))||_,r=(e.getAttribute(s("countries"))||"").toUpperCase().split(/[\s,]+/).filter(Boolean),c=r.length?r.map(t=>n.find(l=>l.isoCode===t)).filter(t=>t!==void 0):n;e.replaceChildren(...c.map(t=>new Option(Y(i,t),t.isoCode))),e.value=o,e.value!==o&&(e.selectedIndex=-1),e.disabled=c.length<2&&!e.hasAttribute(s("always-enabled"))}function $(e,n,o){let i=(a.country||o.country.isoCode).toUpperCase(),r=[...o.availableCountries].sort((t,l)=>t.name.localeCompare(l.name,a.locale||void 0)),c=r.find(t=>t.isoCode===i)??o.country;e.forEach(t=>{q(t,r,i)}),n.forEach(t=>{t.textContent=U(c,v(t,"country-bind")||j)})}function S(e=document){let n=p(e,`select${C("country-select")}`),o=p(e,C("country-bind"));return!n.length&&!o.length?Promise.resolve():R().then(i=>{$(n,o,i)}).catch(i=>{y(i,"country select")})}var Q=e=>Object.values(a.markets?.locales??{}).find(n=>f(n.country)===e);function V(e,n){return e!==void 0?g(e):n?n.language?g(n.language):void 0:a.language}function Z(e){w();let n=[];return u.id()&&n.push(u.setBuyerIdentity({countryCode:e},{create:!1}).catch(o=>{y(o,"cart country")})),T(),k.forEach(o=>n.push(o.load())),P.forEach(o=>{o.closest(I())||(E.delete(o),A(o))}),n}async function re(e,{language:n,locale:o,remember:i=!0}={}){let r=f(e);if(!r)throw new L(`Not a country code: ${e}`,{code:"INVALID_COUNTRY"});let c=Q(r),t=o||c?.locale,l=t||a.locale,m=V(n,c),M=r!==a.country||m!==a.language||l!==a.locale;if(a.country=r,a.language=m||void 0,a.locale=l,i&&x({country:r,language:m,locale:t}),!M)return S(),u.state;n!==void 0&&B();let N=Z(r);return S(),z("country-changed",{country:r,language:a.language}),await Promise.all(N),u.state}export{F as detectMarket,R as getLocalization,S as renderCountrySelects,re as setCountry};
1
+ import{a as E,c as P,d as k,e as T,f as p,g as A}from"./chunk-JJVUNGJZ.js";import{a as I}from"./chunk-LZINCBME.js";import{d as F,e as x}from"./chunk-TUVLYVMF.js";import"./chunk-33IQL4XN.js";import{h as u}from"./chunk-COXH5OXQ.js";import"./chunk-KW7UPDXI.js";import"./chunk-DQJRQBJG.js";import"./chunk-UU2VVXU2.js";import"./chunk-HZYW2TS3.js";import{e as w}from"./chunk-AMCCY6T4.js";import"./chunk-NOTL72DB.js";import{a as L,d as h,i as b,m as s,n as C,o as v,u as z}from"./chunk-HO6SNO3A.js";import{F as y,o as f,p as g,x as a}from"./chunk-ESYKAFMU.js";var _="{name} ({currency})",j="name",d=null;function B(){d=null}var D="query TetherLocalization{localization{country{isoCode name currency{isoCode symbol}}language{isoCode name}availableCountries{isoCode name currency{isoCode symbol}availableLanguages{isoCode name}}}}",O={isoCode:"string",name:"string",currency:"object"},H=h({localization:{country:O,availableCountries:[O]}});function R(){return d??(d=b(D,{},H).then(e=>e.localization,e=>{throw d=null,e})),d}function U(e,n){switch(n){case"name":return e.name;case"code":return e.isoCode;case"currency":return e.currency.isoCode;case"symbol":return e.currency.symbol;default:return""}}var Y=(e,n)=>e.replace(/\{(name|code|currency|symbol)\}/g,(o,i)=>U(n,i));function q(e,n,o){let i=e.getAttribute(s("country-label"))||_,r=(e.getAttribute(s("countries"))||"").toUpperCase().split(/[\s,]+/).filter(Boolean),c=r.length?r.map(t=>n.find(l=>l.isoCode===t)).filter(t=>t!==void 0):n;e.replaceChildren(...c.map(t=>new Option(Y(i,t),t.isoCode))),e.value=o,e.value!==o&&(e.selectedIndex=-1),e.disabled=c.length<2&&!e.hasAttribute(s("always-enabled"))}function $(e,n,o){let i=(a.country||o.country.isoCode).toUpperCase(),r=[...o.availableCountries].sort((t,l)=>t.name.localeCompare(l.name,a.locale||void 0)),c=r.find(t=>t.isoCode===i)??o.country;e.forEach(t=>{q(t,r,i)}),n.forEach(t=>{t.textContent=U(c,v(t,"country-bind")||j)})}function S(e=document){let n=p(e,`select${C("country-select")}`),o=p(e,C("country-bind"));return!n.length&&!o.length?Promise.resolve():R().then(i=>{$(n,o,i)}).catch(i=>{y(i,"country select")})}var Q=e=>Object.values(a.markets?.locales??{}).find(n=>f(n.country)===e);function V(e,n){return e!==void 0?g(e):n?n.language?g(n.language):void 0:a.language}function Z(e){w();let n=[];return u.id()&&n.push(u.setBuyerIdentity({countryCode:e},{create:!1}).catch(o=>{y(o,"cart country")})),T(),k.forEach(o=>n.push(o.load())),P.forEach(o=>{o.closest(I())||(E.delete(o),A(o))}),n}async function re(e,{language:n,locale:o,remember:i=!0}={}){let r=f(e);if(!r)throw new L(`Not a country code: ${e}`,{code:"INVALID_COUNTRY"});let c=Q(r),t=o||c?.locale,l=t||a.locale,m=V(n,c),M=r!==a.country||m!==a.language||l!==a.locale;if(a.country=r,a.language=m||void 0,a.locale=l,i&&x({country:r,language:m,locale:t}),!M)return S(),u.state;n!==void 0&&B();let N=Z(r);return S(),z("country-changed",{country:r,language:a.language}),await Promise.all(N),u.state}export{F as detectMarket,R as getLocalization,S as renderCountrySelects,re as setCountry};
@@ -1 +1 @@
1
- import{f as k}from"./chunk-EYVBEFKK.js";import"./chunk-C2GKO34C.js";import"./chunk-5TS6IBBB.js";import"./chunk-KIZBET7N.js";import"./chunk-F3OXGENC.js";import"./chunk-646NGAEM.js";import"./chunk-UJYL5G7T.js";import"./chunk-UM37ZVSP.js";import"./chunk-I7XE7GQR.js";import"./chunk-6FWNC7QH.js";import{B as q,D as v,G as R,I as d,R as p,c as T,d as I,i as L,m as w,n as o,o as m,q as h,u as x,x as C,z as M}from"./chunk-67MCLHFS.js";import{D as E,F as A,b as s,x as u}from"./chunk-YW3ZIFWB.js";var U=I({predictiveSearch:T({products:[{priceRange:"object"}],collections:["object"],queries:[{text:"string"}]})}),D="query TetherPredictive($q:String!,$limit:Int!){predictiveSearch(query:$q,limit:$limit,limitScope:EACH,types:[PRODUCT,COLLECTION,QUERY]){products{id handle title availableForSale featuredImage{url altText}priceRange{minVariantPrice{amount currencyCode}}}collections{handle title image{url altText}}queries{text}}}",V=6,F=10,O=2,_="/search",g=new WeakSet,$=0,b=new Set,P=a=>a.tagName==="A"?a:a.querySelector("a");function f(a,t){h(a,o("search-bind")).forEach(e=>{let i=m(e,"search-bind");i==="image"?C(e,t.image?.url,t.image?.altText||t.title):(i==="title"||i==="price"||i==="text")&&t[i]!=null&&R(e,t[i])})}function H(a,t){let e=P(a);e&&(t&&e.setAttribute("href",t),e.setAttribute("role","option"))}var y=class{constructor(t,e,i){s(this,"root");s(this,"input");s(this,"results");s(this,"limit");s(this,"minCharacters");s(this,"resultsId");s(this,"searchNumber",0);s(this,"timer");s(this,"lastTerm","");s(this,"cache",new Map);s(this,"listening",new window.AbortController);this.root=t,this.input=e,this.results=i,this.limit=p(t,"search-limit",{min:1,max:F,fallback:V}),this.minCharacters=p(t,"search-min",{min:1,fallback:O}),i.id||($+=1,i.id=`${u.prefix}-search-${$}`),this.resultsId=i.id,this.setUpAria(),this.listen(),b.add(this)}stop(){this.listening.abort(),clearTimeout(this.timer),b.delete(this),g.delete(this.root)}setUpAria(){this.input.setAttribute("role","combobox"),this.input.setAttribute("aria-autocomplete","list"),this.input.setAttribute("aria-controls",this.resultsId),this.input.setAttribute("aria-expanded","false"),this.input.setAttribute("autocomplete","off"),this.results.hasAttribute("role")||this.results.setAttribute("role","listbox"),this.results.hidden=!0}listen(){let{signal:t}=this.listening;this.input.addEventListener("input",()=>{let e=this.input.value.trim();e!==this.lastTerm&&(this.lastTerm=e,clearTimeout(this.timer),this.timer=setTimeout(()=>void this.search(e),u.searchDelay))},{signal:t}),this.input.addEventListener("focus",()=>{this.input.value.trim().length>=this.minCharacters&&this.options().length&&this.open(!0)},{signal:t}),this.input.addEventListener("keydown",e=>{this.onKeydown(e)},{signal:t}),document.addEventListener("click",e=>{if(!this.root.isConnected){this.stop();return}this.root.contains(e.target)||this.open(!1)},{signal:t})}setState(t){this.root.setAttribute(w("search-state"),t)}open(t){this.root.classList.toggle("is-open",t),this.results.hidden=!t,this.input.setAttribute("aria-expanded",String(t)),t||this.input.removeAttribute("aria-activedescendant")}options(){return h(this.results,'[role="option"]')}async fetchResults(t){let e=this.cache.get(t);if(e)return e;let i=await L(D,{q:t,limit:this.limit},U);return this.cache.set(t,i.predictiveSearch),i.predictiveSearch}async search(t){this.searchNumber+=1;let e=this.searchNumber;if(t.length<this.minCharacters){this.open(!1),this.setState("idle");return}this.setState("loading");try{let i=await this.fetchResults(t);e===this.searchNumber&&this.render(i,t)}catch(i){if(e!==this.searchNumber){E("a superseded search failed",i);return}this.setState("error"),A(i,"search")}}fillList(t,e,i){h(this.results,o(t)).forEach(l=>{M(l,e,i),d(l,e.length>0)})}queryUrl(t){let e=this.root.getAttribute("action")||_,i=e.includes("?")?"&":"?";return`${e}${i}${this.input.name||"q"}=${encodeURIComponent(t)}`}render(t,e){let i=t?.products??[],l=t?.collections??[],c=(t?.queries??[]).filter(n=>n.text.toLowerCase()!==e.toLowerCase());this.fillList("search-products",i,(n,r)=>{let N=v(r.priceRange.minVariantPrice);f(n,{title:r.title,price:N,image:r.featuredImage}),H(n,q(r.handle,r.id)),n.classList.toggle("is-sold-out",!r.availableForSale)}),this.fillList("search-collections",l,(n,r)=>{f(n,{title:r.title,image:r.image}),H(n,`${(u.collectionPath||"/collection").replace(/\/$/,"")}/${r.handle}`)}),this.fillList("search-queries",c,(n,r)=>{f(n,{text:r.text}),P(n)?.setAttribute("href",this.queryUrl(r.text))});let S=i.length+l.length+c.length;this.showCount(S),this.setState(S?"ready":"empty"),this.open(!0),x("search",{term:e,products:i,collections:l,queries:c},this.root)}showCount(t){h(this.root,o("show")).forEach(e=>{let i=m(e,"show");i==="search-empty"&&d(e,t===0),i==="search-results"&&d(e,t>0)}),this.options().forEach((e,i)=>{e.id||(e.id=`${this.resultsId}-${i}`),e.setAttribute("aria-selected","false")}),this.input.removeAttribute("aria-activedescendant")}highlight(t,e){t.forEach((l,c)=>{l.setAttribute("aria-selected",String(c===e))});let i=t[e];i&&(this.input.setAttribute("aria-activedescendant",i.id),i.scrollIntoView?.({block:"nearest"}))}onKeydown(t){let e=this.options(),i=e.findIndex(l=>l.getAttribute("aria-selected")==="true");t.key==="ArrowDown"&&e.length?(t.preventDefault(),this.open(!0),this.highlight(e,(i+1)%e.length)):t.key==="ArrowUp"&&e.length?(t.preventDefault(),this.highlight(e,i<=0?e.length-1:i-1)):t.key==="Enter"&&i>=0?(t.preventDefault(),e[i]?.click()):t.key==="Escape"&&this.open(!1)}};function Y(a=document){b.forEach(t=>{t.root.isConnected||t.stop()});for(let t of k(a,o("search"))){if(g.has(t))continue;g.add(t);let e=t.querySelector(o("search-input"))??t.querySelector("input"),i=t.querySelector(o("search-results"));e&&i&&new y(t,e,i)}}export{Y as mountSearch};
1
+ import{f as k}from"./chunk-JJVUNGJZ.js";import"./chunk-LZINCBME.js";import"./chunk-33IQL4XN.js";import"./chunk-COXH5OXQ.js";import"./chunk-KW7UPDXI.js";import"./chunk-DQJRQBJG.js";import"./chunk-UU2VVXU2.js";import"./chunk-HZYW2TS3.js";import"./chunk-AMCCY6T4.js";import"./chunk-NOTL72DB.js";import{B as q,D as v,G as R,I as d,R as p,c as T,d as I,i as L,m as w,n as o,o as m,q as h,u as x,x as C,z as M}from"./chunk-HO6SNO3A.js";import{D as E,F as A,b as s,x as u}from"./chunk-ESYKAFMU.js";var U=I({predictiveSearch:T({products:[{priceRange:"object"}],collections:["object"],queries:[{text:"string"}]})}),D="query TetherPredictive($q:String!,$limit:Int!){predictiveSearch(query:$q,limit:$limit,limitScope:EACH,types:[PRODUCT,COLLECTION,QUERY]){products{id handle title availableForSale featuredImage{url altText}priceRange{minVariantPrice{amount currencyCode}}}collections{handle title image{url altText}}queries{text}}}",V=6,F=10,O=2,_="/search",g=new WeakSet,$=0,b=new Set,P=a=>a.tagName==="A"?a:a.querySelector("a");function f(a,t){h(a,o("search-bind")).forEach(e=>{let i=m(e,"search-bind");i==="image"?C(e,t.image?.url,t.image?.altText||t.title):(i==="title"||i==="price"||i==="text")&&t[i]!=null&&R(e,t[i])})}function H(a,t){let e=P(a);e&&(t&&e.setAttribute("href",t),e.setAttribute("role","option"))}var y=class{constructor(t,e,i){s(this,"root");s(this,"input");s(this,"results");s(this,"limit");s(this,"minCharacters");s(this,"resultsId");s(this,"searchNumber",0);s(this,"timer");s(this,"lastTerm","");s(this,"cache",new Map);s(this,"listening",new window.AbortController);this.root=t,this.input=e,this.results=i,this.limit=p(t,"search-limit",{min:1,max:F,fallback:V}),this.minCharacters=p(t,"search-min",{min:1,fallback:O}),i.id||($+=1,i.id=`${u.prefix}-search-${$}`),this.resultsId=i.id,this.setUpAria(),this.listen(),b.add(this)}stop(){this.listening.abort(),clearTimeout(this.timer),b.delete(this),g.delete(this.root)}setUpAria(){this.input.setAttribute("role","combobox"),this.input.setAttribute("aria-autocomplete","list"),this.input.setAttribute("aria-controls",this.resultsId),this.input.setAttribute("aria-expanded","false"),this.input.setAttribute("autocomplete","off"),this.results.hasAttribute("role")||this.results.setAttribute("role","listbox"),this.results.hidden=!0}listen(){let{signal:t}=this.listening;this.input.addEventListener("input",()=>{let e=this.input.value.trim();e!==this.lastTerm&&(this.lastTerm=e,clearTimeout(this.timer),this.timer=setTimeout(()=>void this.search(e),u.searchDelay))},{signal:t}),this.input.addEventListener("focus",()=>{this.input.value.trim().length>=this.minCharacters&&this.options().length&&this.open(!0)},{signal:t}),this.input.addEventListener("keydown",e=>{this.onKeydown(e)},{signal:t}),document.addEventListener("click",e=>{if(!this.root.isConnected){this.stop();return}this.root.contains(e.target)||this.open(!1)},{signal:t})}setState(t){this.root.setAttribute(w("search-state"),t)}open(t){this.root.classList.toggle("is-open",t),this.results.hidden=!t,this.input.setAttribute("aria-expanded",String(t)),t||this.input.removeAttribute("aria-activedescendant")}options(){return h(this.results,'[role="option"]')}async fetchResults(t){let e=this.cache.get(t);if(e)return e;let i=await L(D,{q:t,limit:this.limit},U);return this.cache.set(t,i.predictiveSearch),i.predictiveSearch}async search(t){this.searchNumber+=1;let e=this.searchNumber;if(t.length<this.minCharacters){this.open(!1),this.setState("idle");return}this.setState("loading");try{let i=await this.fetchResults(t);e===this.searchNumber&&this.render(i,t)}catch(i){if(e!==this.searchNumber){E("a superseded search failed",i);return}this.setState("error"),A(i,"search")}}fillList(t,e,i){h(this.results,o(t)).forEach(l=>{M(l,e,i),d(l,e.length>0)})}queryUrl(t){let e=this.root.getAttribute("action")||_,i=e.includes("?")?"&":"?";return`${e}${i}${this.input.name||"q"}=${encodeURIComponent(t)}`}render(t,e){let i=t?.products??[],l=t?.collections??[],c=(t?.queries??[]).filter(n=>n.text.toLowerCase()!==e.toLowerCase());this.fillList("search-products",i,(n,r)=>{let N=v(r.priceRange.minVariantPrice);f(n,{title:r.title,price:N,image:r.featuredImage}),H(n,q(r.handle,r.id)),n.classList.toggle("is-sold-out",!r.availableForSale)}),this.fillList("search-collections",l,(n,r)=>{f(n,{title:r.title,image:r.image}),H(n,`${(u.collectionPath||"/collection").replace(/\/$/,"")}/${r.handle}`)}),this.fillList("search-queries",c,(n,r)=>{f(n,{text:r.text}),P(n)?.setAttribute("href",this.queryUrl(r.text))});let S=i.length+l.length+c.length;this.showCount(S),this.setState(S?"ready":"empty"),this.open(!0),x("search",{term:e,products:i,collections:l,queries:c},this.root)}showCount(t){h(this.root,o("show")).forEach(e=>{let i=m(e,"show");i==="search-empty"&&d(e,t===0),i==="search-results"&&d(e,t>0)}),this.options().forEach((e,i)=>{e.id||(e.id=`${this.resultsId}-${i}`),e.setAttribute("aria-selected","false")}),this.input.removeAttribute("aria-activedescendant")}highlight(t,e){t.forEach((l,c)=>{l.setAttribute("aria-selected",String(c===e))});let i=t[e];i&&(this.input.setAttribute("aria-activedescendant",i.id),i.scrollIntoView?.({block:"nearest"}))}onKeydown(t){let e=this.options(),i=e.findIndex(l=>l.getAttribute("aria-selected")==="true");t.key==="ArrowDown"&&e.length?(t.preventDefault(),this.open(!0),this.highlight(e,(i+1)%e.length)):t.key==="ArrowUp"&&e.length?(t.preventDefault(),this.highlight(e,i<=0?e.length-1:i-1)):t.key==="Enter"&&i>=0?(t.preventDefault(),e[i]?.click()):t.key==="Escape"&&this.open(!1)}};function Y(a=document){b.forEach(t=>{t.root.isConnected||t.stop()});for(let t of k(a,o("search"))){if(g.has(t))continue;g.add(t);let e=t.querySelector(o("search-input"))??t.querySelector("input"),i=t.querySelector(o("search-results"));e&&i&&new y(t,e,i)}}export{Y as mountSearch};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{a as at,b as ct,c as ut}from"./chunks/chunk-AHYDU7Z6.js";import{b as C,d as A,e as k,f as p,g as nt,h as ot,i as rt,j as S,k as x}from"./chunks/chunk-EYVBEFKK.js";import{a as dt,b as mt}from"./chunks/chunk-C2GKO34C.js";import{a as it,b as st,c as h}from"./chunks/chunk-B2X6ZOKA.js";import"./chunks/chunk-HEK66LYK.js";import{a as et}from"./chunks/chunk-5TS6IBBB.js";import{a as K,e as Z,h as s}from"./chunks/chunk-KIZBET7N.js";import"./chunks/chunk-F3OXGENC.js";import{l as Q}from"./chunks/chunk-646NGAEM.js";import{a as u,b as lt}from"./chunks/chunk-UJYL5G7T.js";import{b as tt}from"./chunks/chunk-UM37ZVSP.js";import{a as W,b as X,c as Y,e as J}from"./chunks/chunk-I7XE7GQR.js";import"./chunks/chunk-6FWNC7QH.js";import{D as j,L as w,O as f,Q as z,a as P,f as G,k as U,m as d,n as i,s as q,t as y,u as E,v as B}from"./chunks/chunk-67MCLHFS.js";import{B as _,C as v,D as L,E as F,F as a,e as $,x as c,y as V}from"./chunks/chunk-YW3ZIFWB.js";function ft(t){let e=[],n=new window.AbortController,o={signal:n.signal};return q.forEach(r=>{document.addEventListener(`${c.prefix}:${r}`,g=>e.push(g),o)}),document.addEventListener("astro:page-load",r=>e.push(r),o),t().then(r=>r.startAnalytics(e)).catch(r=>{n.abort(),e.length=0,a(r,"analytics")}),e}var M="0.9.4";var It=["account-login","account-bind","account-link","orders","order","addresses","subscriptions","profile-form","address-form"],Nt=()=>[...It.map(t=>`[${d(t)}]`),`[${d("show")}^="logged-"]`].join(",");function Ot(){return!!Z(at())}function pt(t){!c.account||!(p(t,Nt()).length>0||ut(new URLSearchParams(window.location.search).get("account"))||Ot())||u("account").then(n=>n.mountAccount(t)).catch(n=>{a(n,"account")})}function l(t){return(...e)=>u("account").then(n=>{let o=n[t];return o(...e)})}var gt={login:l("login"),logout:l("logout"),isLoggedIn:l("isLoggedIn"),customer:l("customer"),orders:l("orders"),order:l("order"),updateProfile:l("updateProfile"),addresses:l("addresses"),saveAddress:l("saveAddress"),deleteAddress:l("deleteAddress"),subscriptions:l("subscriptions"),subscriptionAction:l("subscriptionAction"),requestReturn:l("requestReturn"),render:l("render"),mountAccount:l("mountAccount")};var yt=()=>`data-${c.prefix}-key`,Et=t=>t instanceof window.Element;function ht(t){let e=t.closest(`[${yt()}]`),n=e?.getAttribute(yt());return e&&n?{line:e,id:n}:null}function b(t,e){t.catch(n=>{a(n,e)})}function Dt(t,e){let n=ht(e);if(!n?.line.closest(i("cart-lines")))return;let{line:o,id:r}=n;if(e.closest(i("line-remove"))){t.preventDefault(),o.classList.add("is-busy"),b(s.removeLine(r),"cart line");return}let g=Rt(e);!g||!s.lines.some(Mt=>Mt.id===r)||(t.preventDefault(),b(s.changeQuantity(r,g),"cart line"))}function Rt(t){return t.closest(i("line-plus"))?1:t.closest(i("line-minus"))?-1:0}function Ht(t){let{target:e}=t;if(!Et(e))return;if(e.closest(i("cart-open"))){t.preventDefault(),s.toggle();return}if(e.closest(i("cart-close"))){t.preventDefault(),s.close();return}let n=e.closest(i("cart-clear"));if(n){t.preventDefault(),f(n,()=>s.clear().catch(r=>{a(r,"cart clear")}));return}let o=e.closest(i("checkout"));if(o){t.preventDefault(),f(o,()=>s.checkout());return}Dt(t,e)}function vt(t,e,n){t.classList.add("is-busy"),t.setAttribute("aria-busy","true"),b(e,n)}function $t(t,{line:e,id:n}){let o=t.value.trim();if(z.test(o)){vt(e,s.updateLine(n,Number(o)),"cart line");return}let r=s.lines.find(g=>g.id===n);r&&(t.value=String(s.quantityOf(r)))}function Vt(t){let{target:e}=t;if(!Et(e))return;let n=ht(e);n&&e instanceof window.HTMLInputElement&&e.matches(i("line","quantity"))?$t(e,n):n&&e instanceof window.HTMLSelectElement&&e.matches(i("line-plan"))?vt(n.line,s.updateLine(n.id,{sellingPlanId:e.value||null}),"cart line plan"):_t(e)&&e.matches(i("cart-note"))&&b(s.setNote(e.value),"cart note")}var _t=t=>t instanceof window.HTMLInputElement||t instanceof window.HTMLTextAreaElement||t instanceof window.HTMLSelectElement;function Ft(t){if(s.isOpen()){if(t.key==="Escape"){s.close();return}K(t)}}function Pt(){document.addEventListener("click",Ht),document.addEventListener("change",Vt),document.addEventListener("keydown",Ft)}var I=t=>t instanceof window.Element;function Gt(t){let e=t.querySelector(i("discount-input"))??t.querySelector("input");return e instanceof window.HTMLInputElement?e:null}function wt(t,e,n){t.classList.toggle("is-invalid",n),n?e?.setAttribute("aria-invalid","true"):e?.removeAttribute("aria-invalid")}async function Ut(t,e,n){try{await s.applyDiscount(n),wt(t,e,!1),E("discount-applied",{code:n},t),e&&(e.value="")}catch(o){wt(t,e,!0),o instanceof P&&o.code==="INVALID_DISCOUNT"?E("discount-invalid",{code:n},t):a(o,"discount")}}function qt(t){let{target:e}=t,n=I(e)?e.closest(i("discount-form")):null;if(!n)return;t.preventDefault();let o=Gt(n),r=o?.value.trim();r&&f(n,()=>Ut(n,o,r))}function Bt(t){let{target:e}=t;if(!I(e))return;let n=e.closest(i("discount-form"));n&&(n.classList.remove("is-invalid"),e.removeAttribute("aria-invalid"))}function jt(t){let{target:e}=t,n=I(e)?e.closest(i("discount-remove")):null;if(!n)return;t.preventDefault();let o=n.closest(i("discount-code"))?.getAttribute(d("discount-code"));o&&s.removeDiscount(o).catch(r=>{a(r,"discount")})}function At(){document.addEventListener("submit",qt,!0),document.addEventListener("input",Bt),document.addEventListener("click",jt)}var N=t=>u("extras").then(e=>e.addGroup(t)),O=t=>{a(t,"extras")};function zt(t){let{target:e}=t,n=e instanceof window.Element?e.closest(i("group-add")):null;n&&(t.preventDefault(),f(n,()=>N(n)).catch(O))}function Qt(t){!c.domain||!t.key?.startsWith(`${c.prefix}:`)||u("extras").then(e=>{e.onStorage(t)}).catch(O)}function Kt(t){if(!y(t,"variant-changed"))return;let{target:e}=t;e instanceof window.Element&&(!c.variantUrl&&!e.hasAttribute(d("variant-url"))||u("extras").then(n=>{n.writeVariantUrl(e,t.detail)}).catch(O))}function bt(){document.addEventListener("click",zt),window.addEventListener("storage",Qt),document.addEventListener(`${c.prefix}:variant-changed`,Kt)}var D=null;function Tt(){D=document.body}async function Wt(t){await t.ready();let e=st();if(!e){D!==document.body&&t.mount(document);return}try{await h(e.country,{language:e.language??null,locale:e.locale,remember:!1})}catch(n){a(n,"country")}t.mount(document)}function Xt(t){document.addEventListener("astro:page-load",()=>{Wt(t).catch(e=>{a(e,"page mount")})}),document.addEventListener("astro:before-swap",()=>{D=null,t.unmount()})}function Yt(t){let{target:e}=t;!(e instanceof window.HTMLSelectElement)||!e.matches(i("country-select"))||e.value&&h(e.value).catch(n=>{a(n,"country")})}function Jt(){ot(),A.forEach(t=>{t.root.getAttribute(d("state"))==="error"&&t.load()})}function Lt(t){c.astro&&Xt(t),document.addEventListener("change",Yt),window.addEventListener("online",Jt)}var Zt=50;function te(){let t=w("TETHER_CONFIG");return typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t)):{}}var m=null,R=null,ee=null,Ct=!1;function ne(t){let e=0;return p(t,dt()).forEach(n=>{if(C.has(n))return;C.add(n),e++;let o=mt(n);A.add(o),n.addEventListener(`${c.prefix}:list-rendered`,r=>{y(r,"list-rendered")&&T(r.detail.container)}),rt(o.load())}),e}function oe(t){p(t,`${i("country-select")},${i("country-bind")}`).length&&u("markets").then(e=>e.renderCountrySelects(t)).catch(e=>{a(e,"markets")}),pt(t),p(t,i("search")).length&&u("search").then(e=>{e.mountSearch(t)}).catch(e=>{a(e,"search")})}function kt(t){let e=ne(t);return p(t,i("product")).forEach(n=>{nt(n)&&e++}),oe(t),e}function T(t=document){if(!v())return 0;t===document&&Tt(),k(),x(t.ownerDocument??document);let e=kt(t);return S(),s.render(),L(`mounted ${e} scope(s)`,t),e}function re(t){let e=t.filter(o=>o.isConnected&&!t.some(r=>r!==o&&r.contains(o)));if(!e.length||!v())return;k(),e.forEach(o=>{x(o)});let n=e.reduce((o,r)=>o+kt(r),0);S(),s.render(),L(`mounted ${n} scope(s) in ${e.length} added element(s)`)}function St(){s.close()}function ie(t){let e=t?.closest(i("product"));return e?et.get(e)??null:null}function se(){Ct||(Ct=!0,Pt(),At(),bt(),Lt({ready:()=>m??Promise.resolve(null),mount:T,unmount:St}))}async function ae(t){let e=c.country,n=t?.buyerIdentity.countryCode;if(!t||!e||!n||n===e)return t;try{return await s.setBuyerIdentity({countryCode:e},{create:!1})}catch(o){return a(o,"cart country"),t}}function xt(t={}){return m&&!Object.keys(t).length?m:(_({...te(),...t}),v()?(ct(),se(),c.observe&&ce(),c.analytics&&(ee??(ee=ft(()=>u("analytics")))),m=it(t).then(()=>s.init()).then(ae).then(e=>(E("ready",{cart:e}),H)),m):(F("TETHER_CONFIG is missing domain or token. Tether is idle."),m=Promise.resolve(null),m))}function ce(){if(R||typeof MutationObserver>"u")return;let t,e=new Set;R=new MutationObserver(n=>{n.forEach(o=>{o.addedNodes.forEach(r=>{r instanceof window.Element&&e.add(r)})}),clearTimeout(t),t=setTimeout(()=>{let o=[...e];e.clear(),re(o)},Zt)}),R.observe(document.body,{childList:!0,subtree:!0})}var ue=t=>u("markets").then(e=>e.detectMarket(t??c.markets)),le=t=>u("lists").then(e=>e.getProducts(t)),de=(t,e)=>u("lists").then(n=>n.getRecommendations(t,e)),me=()=>u("markets").then(t=>t.getLocalization()),fe=t=>u("diagnose").then(e=>e.diagnose({...t,version:M}));function pe(t,e){let n=`${c.prefix}:${t}`,o=r=>{y(r,t)&&e(r.detail,r)};return document.addEventListener(n,o),()=>{document.removeEventListener(n,o)}}var ge={VERSION:M,init:xt,mount:T,unmount:St,get config(){return V},get ready(){return m??Promise.resolve(null)},query:U,withContext:G,cart:s,getProduct:Y,getProducts:le,getRecommendations:de,getScope:ie,addGroup:N,account:gt,primeProduct:X,normalizeProductKey:W,clearProductCache:J,formatMoney:j,imageUrl:B,plans:Q,TetherError:P,resolveProductKey:tt,setCountry:h,detectMarket:ue,getLocalization:me,diagnose:fe,on:pe},ye={__core:lt,__parts:{}},H=Object.assign(ge,ye),pn=H;function Ee(){Reflect.set(window,"Tether",H);let t=w("TETHER_CONFIG");if(!t||$(t,"autoMount")===!1||w("TETHER_INTEGRATION"))return;let e=()=>{xt().then(()=>T(document)).catch(n=>{a(n,"init")})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}typeof window<"u"&&typeof document<"u"&&Ee();export{M as VERSION,N as addGroup,H as api,pn as default,ie as getScope,xt as init,T as mount,h as setCountry,St as unmount};
1
+ import{a as at,b as ct,c as ut}from"./chunks/chunk-U5BYAOTP.js";import{b as C,d as P,e as T,f as g,g as nt,h as ot,i as rt,j as L,k}from"./chunks/chunk-JJVUNGJZ.js";import{a as dt,b as mt}from"./chunks/chunk-LZINCBME.js";import{a as it,b as st,c as h}from"./chunks/chunk-UDJ62MPR.js";import"./chunks/chunk-TUVLYVMF.js";import{a as et}from"./chunks/chunk-33IQL4XN.js";import{a as K,e as Z,h as s}from"./chunks/chunk-COXH5OXQ.js";import"./chunks/chunk-KW7UPDXI.js";import{l as Q}from"./chunks/chunk-DQJRQBJG.js";import{a as u,b as lt}from"./chunks/chunk-UU2VVXU2.js";import{b as tt}from"./chunks/chunk-HZYW2TS3.js";import{a as W,b as X,c as Y,e as J}from"./chunks/chunk-AMCCY6T4.js";import"./chunks/chunk-NOTL72DB.js";import{D as j,L as v,O as p,Q as z,a as F,f as G,k as _,m,n as i,s as q,t as y,u as U,v as B}from"./chunks/chunk-HO6SNO3A.js";import{B as $,C as E,D as b,E as V,F as a,e as D,x as c,y as H}from"./chunks/chunk-ESYKAFMU.js";function ft(t){let e=[],n=new window.AbortController,o={signal:n.signal};return q.forEach(r=>{document.addEventListener(`${c.prefix}:${r}`,d=>e.push(d),o)}),document.addEventListener("astro:page-load",r=>e.push(r),o),t().then(r=>r.startAnalytics(e)).catch(r=>{n.abort(),e.length=0,a(r,"analytics")}),e}var S="0.9.6";var Mt=["account-login","account-bind","account-link","orders","order","addresses","subscriptions","profile-form","address-form"],Nt=()=>[...Mt.map(t=>`[${m(t)}]`),`[${m("show")}^="logged-"]`].join(",");function Ot(){return!!Z(at())}function pt(t){!c.account||!(g(t,Nt()).length>0||ut(new URLSearchParams(window.location.search).get("account"))||Ot())||u("account").then(n=>n.mountAccount(t)).catch(n=>{a(n,"account")})}function l(t){return(...e)=>u("account").then(n=>{let o=n[t];return o(...e)})}var gt={login:l("login"),logout:l("logout"),isLoggedIn:l("isLoggedIn"),customer:l("customer"),orders:l("orders"),order:l("order"),updateProfile:l("updateProfile"),addresses:l("addresses"),saveAddress:l("saveAddress"),deleteAddress:l("deleteAddress"),subscriptions:l("subscriptions"),subscriptionAction:l("subscriptionAction"),requestReturn:l("requestReturn"),render:l("render"),mountAccount:l("mountAccount")};var yt=()=>`data-${c.prefix}-key`,ht=t=>t instanceof window.Element;function Et(t){let e=t.closest(`[${yt()}]`),n=e?.getAttribute(yt());return e&&n?{line:e,id:n}:null}function w(t,e){t.catch(n=>{a(n,e)})}function It(t,e){let n=Et(e);if(!n?.line.closest(i("cart-lines")))return;let{line:o,id:r}=n;if(e.closest(i("line-remove"))){t.preventDefault(),o.classList.add("is-busy"),w(s.removeLine(r),"cart line");return}let d=Rt(e);!d||!s.lines.some(xt=>xt.id===r)||(t.preventDefault(),w(s.changeQuantity(r,d),"cart line"))}function Rt(t){return t.closest(i("line-plus"))?1:t.closest(i("line-minus"))?-1:0}function Dt(t){let{target:e}=t;if(!ht(e))return;if(e.closest(i("cart-open"))){t.preventDefault(),s.toggle();return}if(e.closest(i("cart-close"))){t.preventDefault(),s.close();return}let n=e.closest(i("cart-clear"));if(n){t.preventDefault(),p(n,()=>s.clear().catch(r=>{a(r,"cart clear")}));return}let o=e.closest(i("checkout"));if(o){t.preventDefault(),p(o,()=>s.checkout());return}It(t,e)}function vt(t,e,n){t.classList.add("is-busy"),t.setAttribute("aria-busy","true"),w(e,n)}function Ht(t,{line:e,id:n}){let o=t.value.trim();if(z.test(o)){vt(e,s.updateLine(n,Number(o)),"cart line");return}let r=s.lines.find(d=>d.id===n);r&&(t.value=String(s.quantityOf(r)))}function $t(t){let{target:e}=t;if(!ht(e))return;let n=Et(e);n&&e instanceof window.HTMLInputElement&&e.matches(i("line","quantity"))?Ht(e,n):n&&e instanceof window.HTMLSelectElement&&e.matches(i("line-plan"))?vt(n.line,s.updateLine(n.id,{sellingPlanId:e.value||null}),"cart line plan"):Vt(e)&&e.matches(i("cart-note"))&&w(s.setNote(e.value),"cart note")}var Vt=t=>t instanceof window.HTMLInputElement||t instanceof window.HTMLTextAreaElement||t instanceof window.HTMLSelectElement;function Ft(t){if(s.isOpen()){if(t.key==="Escape"){s.close();return}K(t)}}function Pt(){document.addEventListener("click",Dt),document.addEventListener("change",$t),document.addEventListener("keydown",Ft)}var x=t=>t instanceof window.Element;function Gt(t){let e=t.querySelector(i("discount-input"))??t.querySelector("input");return e instanceof window.HTMLInputElement?e:null}function _t(t){let{target:e}=t,n=x(e)?e.closest(i("discount-form")):null;if(!n)return;t.preventDefault();let o=Gt(n),r=o?.value.trim();r&&p(n,()=>u("extras").then(d=>d.applyDiscountCode(n,o,r))).catch(d=>{a(d,"discount")})}function qt(t){let{target:e}=t;if(!x(e))return;let n=e.closest(i("discount-form"));n&&(n.classList.remove("is-invalid"),e.removeAttribute("aria-invalid"))}function Ut(t){let{target:e}=t,n=x(e)?e.closest(i("discount-remove")):null;if(!n)return;t.preventDefault();let o=n.closest(i("discount-code"))?.getAttribute(m("discount-code"));o&&s.removeDiscount(o).catch(r=>{a(r,"discount")})}function wt(){document.addEventListener("submit",_t,!0),document.addEventListener("input",qt),document.addEventListener("click",Ut)}var M=t=>u("extras").then(e=>e.addGroup(t)),N=t=>{a(t,"extras")};function Bt(t){let{target:e}=t,n=e instanceof window.Element?e.closest(i("group-add")):null;n&&(t.preventDefault(),p(n,()=>M(n)).catch(N))}function jt(t){!c.domain||!t.key?.startsWith(`${c.prefix}:`)||u("extras").then(e=>{e.onStorage(t)}).catch(N)}function zt(t){if(!y(t,"variant-changed"))return;let{target:e}=t;e instanceof window.Element&&(!c.variantUrl&&!e.hasAttribute(m("variant-url"))||u("extras").then(n=>{n.writeVariantUrl(e,t.detail)}).catch(N))}function At(){document.addEventListener("click",Bt),window.addEventListener("storage",jt),document.addEventListener(`${c.prefix}:variant-changed`,zt)}var O=null;function bt(){O=document.body}async function Qt(t){await t.ready();let e=st();if(!e){O!==document.body&&t.mount(document);return}try{await h(e.country,{language:e.language??null,locale:e.locale,remember:!1})}catch(n){a(n,"country")}t.mount(document)}function Kt(t){document.addEventListener("astro:page-load",()=>{Qt(t).catch(e=>{a(e,"page mount")})}),document.addEventListener("astro:before-swap",()=>{O=null,t.unmount()})}function Wt(t){let{target:e}=t;!(e instanceof window.HTMLSelectElement)||!e.matches(i("country-select"))||e.value&&h(e.value).catch(n=>{a(n,"country")})}function Xt(){ot(),P.forEach(t=>{t.root.getAttribute(m("state"))==="error"&&t.load()})}function Ct(t){c.astro&&Kt(t),document.addEventListener("change",Wt),window.addEventListener("online",Xt)}var Yt=50;function Jt(){let t=v("TETHER_CONFIG");return typeof t=="object"&&t!==null?Object.fromEntries(Object.entries(t)):{}}var f=null,I=null,Zt=null,Tt=!1;function te(t){let e=0;return g(t,dt()).forEach(n=>{if(C.has(n))return;C.add(n),e++;let o=mt(n);P.add(o),n.addEventListener(`${c.prefix}:list-rendered`,r=>{y(r,"list-rendered")&&A(r.detail.container)}),rt(o.load())}),e}function ee(t){g(t,`${i("country-select")},${i("country-bind")}`).length&&u("markets").then(e=>e.renderCountrySelects(t)).catch(e=>{a(e,"markets")}),pt(t),g(t,i("search")).length&&u("search").then(e=>{e.mountSearch(t)}).catch(e=>{a(e,"search")})}function Lt(t){let e=te(t);return g(t,i("product")).forEach(n=>{nt(n)&&e++}),ee(t),e}function A(t=document){if(!E())return 0;t===document&&bt(),T(),k(t.ownerDocument??document);let e=Lt(t);return L(),s.render(),b(`mounted ${e} scope(s)`,t),e}function ne(t){let e=t.filter(o=>o.isConnected&&!t.some(r=>r!==o&&r.contains(o)));if(!e.length||!E())return;T(),e.forEach(o=>{k(o)});let n=e.reduce((o,r)=>o+Lt(r),0);L(),s.render(),b(`mounted ${n} scope(s) in ${e.length} added element(s)`)}function kt(){s.close()}function oe(t){let e=t?.closest(i("product"));return e?et.get(e)??null:null}function re(){Tt||(Tt=!0,Pt(),wt(),At(),Ct({ready:()=>f??Promise.resolve(null),mount:A,unmount:kt}))}async function ie(t){let e=c.country,n=t?.buyerIdentity.countryCode;if(!t||!e||!n||n===e)return t;try{return await s.setBuyerIdentity({countryCode:e},{create:!1})}catch(o){return a(o,"cart country"),t}}function St(t={}){return f&&!Object.keys(t).length?f:($({...Jt(),...t}),E()?(ct(),re(),c.observe&&se(),c.analytics&&(Zt??(Zt=ft(()=>u("analytics")))),f=it(t).then(()=>s.init()).then(ie).then(e=>(U("ready",{cart:e}),R)),f):(V("TETHER_CONFIG is missing domain or token. Tether is idle."),f=Promise.resolve(null),f))}function se(){if(I||typeof MutationObserver>"u")return;let t,e=new Set;I=new MutationObserver(n=>{n.forEach(o=>{o.addedNodes.forEach(r=>{r instanceof window.Element&&e.add(r)})}),clearTimeout(t),t=setTimeout(()=>{let o=[...e];e.clear(),ne(o)},Yt)}),I.observe(document.body,{childList:!0,subtree:!0})}var ae=t=>u("markets").then(e=>e.detectMarket(t??c.markets)),ce=t=>u("lists").then(e=>e.getProducts(t)),ue=(t,e)=>u("lists").then(n=>n.getRecommendations(t,e)),le=()=>u("markets").then(t=>t.getLocalization()),de=t=>u("diagnose").then(e=>e.diagnose({...t,version:S}));function me(t,e){let n=`${c.prefix}:${t}`,o=r=>{y(r,t)&&e(r.detail,r)};return document.addEventListener(n,o),()=>{document.removeEventListener(n,o)}}var fe={VERSION:S,init:St,mount:A,unmount:kt,get config(){return H},get ready(){return f??Promise.resolve(null)},query:_,withContext:G,cart:s,getProduct:Y,getProducts:ce,getRecommendations:ue,getScope:oe,addGroup:M,account:gt,primeProduct:X,normalizeProductKey:W,clearProductCache:J,formatMoney:j,imageUrl:B,plans:Q,TetherError:F,resolveProductKey:tt,setCountry:h,detectMarket:ae,getLocalization:le,diagnose:de,on:me},pe={__core:lt,__parts:{}},R=Object.assign(fe,pe),mn=R;function ge(){Reflect.set(window,"Tether",R);let t=v("TETHER_CONFIG");if(!t||D(t,"autoMount")===!1||v("TETHER_INTEGRATION"))return;let e=()=>{St().then(()=>A(document)).catch(n=>{a(n,"init")})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e,{once:!0}):e()}typeof window<"u"&&typeof document<"u"&&ge();export{S as VERSION,M as addGroup,R as api,mn as default,oe as getScope,St as init,A as mount,h as setCountry,kt as unmount};
@@ -1,2 +1,2 @@
1
- import{b as Q,f as G,g as H}from"./chunks/chunk-F3OXGENC.js";import{e as O,f as v,g as w,i as F,l as q}from"./chunks/chunk-646NGAEM.js";import{a as M,c as T,e as V,g as J,h as B,i as K,j}from"./chunks/chunk-6FWNC7QH.js";import{C as D,a as y,c as k,d as I,f as ot,h as E,j as _,v as L}from"./chunks/chunk-67MCLHFS.js";import{E as U,q as $,t as x,u as S,v as C,w as g,z as A}from"./chunks/chunk-YW3ZIFWB.js";function z(t,e={}){if(!t)return null;let{variant:r,sellingPlan:a,defaultPurchase:c=g.defaultPurchase,lowStock:u=g.lowStock}=e,d=G(t,{variant:r,sellingPlan:a,defaultPurchase:c}),n=H(t,{...d,quantity:1},u);if(!n)throw new y(`Product ${t.handle} has no variants`);let{selected:l,line:p}=n,i=(o,s)=>!Q(t,l,o,s);return{variant:n.variant,selected:l,purchase:n.purchase.kind,plan:p.kind==="subscription"?n.plan:null,plans:O(t).map(o=>({id:o.id,name:o.name,price:w(n.variant,o.id),savings:F(n.variant,o.id).percentage,selected:p.kind==="subscription"&&o.id===p.planId,available:!!v(n.variant,o.id)})),savings:n.savings.percentage,price:n.price,compareAtPrice:n.compareAtPrice,available:n.variant.availableForSale,show:n.show,unavailable:Object.fromEntries(t.options.map(o=>[o.name,o.optionValues.map(s=>s.name).filter(s=>i(o.name,s))])),isUnavailable:i}}var it=500,at=100,st=100,lt="query TetherServerProductById($id:ID!){node(id:$id){... on Product{...TetherProduct}}}",ct="query TetherServerProduct($handle:String!){product(handle:$handle){...TetherProduct}}",ut=()=>`query TetherServerCollection($handle:String!,$first:Int!,$after:String,$sortKey:ProductCollectionSortKeys,$reverse:Boolean,$filters:[ProductFilter!]){collection(handle:$handle){${T()} products(first:$first,after:$after,sortKey:$sortKey,reverse:$reverse,filters:$filters){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}}`,dt="query TetherServerProducts($first:Int!,$after:String,$query:String,$sortKey:ProductSortKeys,$reverse:Boolean){products(first:$first,after:$after,query:$query,sortKey:$sortKey,reverse:$reverse){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}",ft=()=>`query TetherServerCollections($first:Int!,$after:String){collections(first:$first,after:$after){nodes{${T()}}pageInfo{hasNextPage endCursor}}}`,pt=t=>`query TetherServerRecs(${t?"$id: ID!":"$handle: String!"},$intent:ProductRecommendationIntent){productRecommendations(${t?"productId: $id":"productHandle: $handle"},intent:$intent){...TetherProduct}}`,mt=I({product:k(V)}),gt=I({node:k(J)}),yt=I({collections:{nodes:[{handle:"string"}],pageInfo:{hasNextPage:"boolean"}}});async function Pt(t){let e=[],r=null;for(let a=0;a<st;a++){let c=await E(t,ft(),{first:at,after:r},yt);if(e.push(...c.collections.nodes),!c.collections.pageInfo.hasNextPage)break;r=c.collections.pageInfo.endCursor}return e}function Y(t,e){let r=(i,o,s)=>E(t,f=>`${i}
1
+ import{b as Q,f as G,g as H}from"./chunks/chunk-KW7UPDXI.js";import{e as O,f as v,g as w,i as F,l as q}from"./chunks/chunk-DQJRQBJG.js";import{a as M,c as T,e as V,g as J,h as B,i as K,j}from"./chunks/chunk-NOTL72DB.js";import{C as D,a as y,c as k,d as I,f as ot,h as E,j as _,v as L}from"./chunks/chunk-HO6SNO3A.js";import{E as U,q as $,t as x,u as S,v as C,w as g,z as A}from"./chunks/chunk-ESYKAFMU.js";function z(t,e={}){if(!t)return null;let{variant:r,sellingPlan:a,defaultPurchase:c=g.defaultPurchase,lowStock:u=g.lowStock}=e,d=G(t,{variant:r,sellingPlan:a,defaultPurchase:c}),n=H(t,{...d,quantity:1},u);if(!n)throw new y(`Product ${t.handle} has no variants`);let{selected:l,line:p}=n,i=(o,s)=>!Q(t,l,o,s);return{variant:n.variant,selected:l,purchase:n.purchase.kind,plan:p.kind==="subscription"?n.plan:null,plans:O(t).map(o=>({id:o.id,name:o.name,price:w(n.variant,o.id),savings:F(n.variant,o.id).percentage,selected:p.kind==="subscription"&&o.id===p.planId,available:!!v(n.variant,o.id)})),savings:n.savings.percentage,price:n.price,compareAtPrice:n.compareAtPrice,available:n.variant.availableForSale,show:n.show,unavailable:Object.fromEntries(t.options.map(o=>[o.name,o.optionValues.map(s=>s.name).filter(s=>i(o.name,s))])),isUnavailable:i}}var it=500,at=100,st=100,lt="query TetherServerProductById($id:ID!){node(id:$id){... on Product{...TetherProduct}}}",ct="query TetherServerProduct($handle:String!){product(handle:$handle){...TetherProduct}}",ut=()=>`query TetherServerCollection($handle:String!,$first:Int!,$after:String,$sortKey:ProductCollectionSortKeys,$reverse:Boolean,$filters:[ProductFilter!]){collection(handle:$handle){${T()} products(first:$first,after:$after,sortKey:$sortKey,reverse:$reverse,filters:$filters){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}}`,dt="query TetherServerProducts($first:Int!,$after:String,$query:String,$sortKey:ProductSortKeys,$reverse:Boolean){products(first:$first,after:$after,query:$query,sortKey:$sortKey,reverse:$reverse){nodes{...TetherProduct}pageInfo{hasNextPage endCursor}}}",ft=()=>`query TetherServerCollections($first:Int!,$after:String){collections(first:$first,after:$after){nodes{${T()}}pageInfo{hasNextPage endCursor}}}`,pt=t=>`query TetherServerRecs(${t?"$id: ID!":"$handle: String!"},$intent:ProductRecommendationIntent){productRecommendations(${t?"productId: $id":"productHandle: $handle"},intent:$intent){...TetherProduct}}`,mt=I({product:k(V)}),gt=I({node:k(J)}),yt=I({collections:{nodes:[{handle:"string"}],pageInfo:{hasNextPage:"boolean"}}});async function Pt(t){let e=[],r=null;for(let a=0;a<st;a++){let c=await E(t,ft(),{first:at,after:r},yt);if(e.push(...c.collections.nodes),!c.collections.pageInfo.hasNextPage)break;r=c.collections.pageInfo.endCursor}return e}function Y(t,e){let r=(i,o,s)=>E(t,f=>`${i}
2
2
  ${M(t,f)}`,o,s);async function a(i){let o=C(i);if(!o)return null;if(o.startsWith("gid://")){let{node:f}=await r(lt,{id:o},gt);return f?.id?f:null}return(await r(ct,{handle:o},mt)).product}async function c(i,{first:o=e,after:s=null,sortKey:f,reverse:m=!1,filters:b}){let h=await r(ut(),{handle:i,first:o,after:s,sortKey:f||void 0,reverse:m,filters:b??void 0},B);if(!h.collection)return{collection:null,products:[],pageInfo:{hasNextPage:!1,endCursor:null}};let{products:P,...rt}=h.collection;return{collection:rt,products:P.nodes,pageInfo:P.pageInfo}}async function u(i={}){let{collection:o,query:s,first:f=e,after:m=null,sortKey:b,reverse:h=!1}=i;if(o)return c(o,i);let P=await r(dt,{first:f,after:m,query:s||void 0,sortKey:b||void 0,reverse:h},K);return{collection:null,products:P.products.nodes,pageInfo:P.products.pageInfo}}async function d(i={}){let o=[],s=null;for(let f=0;f<it;f++){let m=await u({...i,first:e,after:s});if(o.push(...m.products),!m.pageInfo.hasNextPage)break;s=m.pageInfo.endCursor}return o}async function n(i,o={}){let s=await u({...o,collection:i});return s.collection?{...s.collection,products:s.products,pageInfo:s.pageInfo}:null}async function l(i,o="RELATED"){let s=C(typeof i=="object"?i?.id:i);if(!s)throw new y("No product for recommendations",{code:"NOT_FOUND"});let f=s.startsWith("gid://");return(await r(pt(f),f?{id:s,intent:o}:{handle:s,intent:o},j)).productRecommendations??[]}return{getProduct:a,getProducts:u,allProducts:d,getCollection:n,allCollections:()=>Pt(t),getRecommendations:l}}var X={size:"https://schema.org/size",color:"https://schema.org/color",colour:"https://schema.org/color",material:"https://schema.org/material"},R=t=>JSON.stringify(t).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029");function W(t){return JSON.parse(JSON.stringify(t))}var Z=t=>t.split("/").pop()??t;function ht(t){return t.availableForSale?t.currentlyNotInStock?"https://schema.org/BackOrder":"https://schema.org/InStock":"https://schema.org/OutOfStock"}function St(t,e){if(!t.requiresSellingPlan)return e.price;let r=O(t).find(a=>v(e,a.id));return(r&&w(e,r.id))??e.price}function tt(t,e,r){let a=St(t,e),c=r?.includes("?")?"&":"?";return{"@type":"Offer",price:a.amount,priceCurrency:a.currencyCode,availability:ht(e),url:r?`${r}${c}variant=${Z(e.id)}`:void 0}}function Ct(t,e,r,a){let c=e.selectedOptions.flatMap(u=>{let d=X[u.name.toLowerCase()];return d?[[d.split("/").pop()??d,u.value]]:[]});return{"@type":"Product",name:`${t.title} - ${e.title}`,sku:e.sku||void 0,image:e.image?.url||a[0],...Object.fromEntries(c),offers:tt(t,e,r)}}function It(t,{url:e},r){if(e)return e;let a=S(r.productPath,t.handle,t.id);if(!(!r.siteUrl||!a))return new URL(a,r.siteUrl).toString()}function N(t,e,r){if(!t)return null;let a=It(t,e,r),c=t.images.nodes.map(i=>i.url).filter(Boolean),u=e.brand||t.vendor,d=u?{"@type":"Brand",name:u}:void 0,n=t.description.trim()||void 0,l=t.variants.nodes;if(l.length<=1){let[i]=l;return W({"@context":"https://schema.org","@type":"Product",name:t.title,description:n,url:a,image:c,sku:i?.sku||void 0,brand:d,offers:i?tt(t,i,a):void 0})}let p=t.options.map(i=>X[i.name.toLowerCase()]).filter(Boolean);return W({"@context":"https://schema.org","@type":"ProductGroup",name:t.title,description:n,url:a,productGroupID:Z(t.id),image:c,brand:d,variesBy:[...new Set(p)],hasVariant:l.map(i=>Ct(t,i,a,c))})}var et=25,vt=2,wt=1;function bt(t,{productPath:e=g.productPath,id:r}={}){return S(e,t,r)}function nt(t,e){for(let r of e){let a=t[r];if(typeof a=="string"&&a)return a}return""}function $t(t){let e={};for(let[u,d]of Object.entries(t))Object.hasOwn(g,u)&&(e[u]=d);let r=typeof t.domain=="string"&&t.domain?t.domain:"",a=typeof t.token=="string"&&t.token?t.token:"",c={...A({...e,domain:r||nt(t,$.domain),token:a||nt(t,$.token)}),pageSize:kt(t.pageSize)};return t.fetch&&(c.fetch=t.fetch),t.siteUrl!==void 0&&(c.siteUrl=t.siteUrl),c}function kt(t){return typeof t=="number"&&Number.isInteger(t)&&t>=1&&t<=250?t:(t!==void 0&&U(`invalid pageSize ${JSON.stringify(t)}: using ${String(et)}`),et)}function Et(t,e){return{...t,description:"",descriptionHtml:"",images:{nodes:t.images.nodes.slice(0,Math.max(1,e))},variants:{nodes:t.variants.nodes.map(r=>({...r,image:null}))}}}function zt(t={}){let e=$t(t);if(!e.domain||!e.token)throw new y("createStorefront needs domain and token: pass them, or import.meta.env with PUBLIC_SHOPIFY_DOMAIN and PUBLIC_SHOPIFY_STOREFRONT_TOKEN",{code:"NOT_CONFIGURED"});let r=Y(e,e.pageSize),a={productPath:e.productPath,siteUrl:e.siteUrl};function c(n,{card:l=!1,images:p=vt}={}){let i=(Array.isArray(n)?n:[n]).filter(s=>s!=null),o={v:wt,at:new Date().toISOString(),country:e.country||null,language:e.language||null,products:l?i.map(s=>Et(s,p)):i};return`<script type="application/json" data-tether-hydrate>${R(o)}<\/script>`}function u(n,l={}){return n?`<script type="application/ld+json">${R(N(n,l,a))}<\/script>`:""}function d(n,l={}){return z(n,{defaultPurchase:e.defaultPurchase,lowStock:e.lowStock,...l})}return{config:e,query:(n,l,p)=>_(e,n,l,p),...r,hydrate:c,formatMoney:(n,l=e.locale)=>x(n,l),formatPercent:(n,l=e.locale)=>D(n,l),imageUrl:L,jsonLd:u,jsonLdData:(n,l={})=>N(n,l,a),initialState:d,productUrl:(n,l={})=>bt(n,{productPath:e.productPath,...l}),plans:q}}export{y as TetherError,zt as createStorefront,x as formatMoney,D as formatPercent,L as imageUrl,z as initialState,q as plans,C as productKey,bt as productUrl,ot as withContext};
@@ -9,6 +9,7 @@
9
9
  var extras_exports = {};
10
10
  __export(extras_exports, {
11
11
  addGroup: () => addGroup,
12
+ applyDiscountCode: () => applyDiscountCode,
12
13
  onStorage: () => onStorage,
13
14
  writeVariantUrl: () => writeVariantUrl
14
15
  });
@@ -17,25 +18,29 @@
17
18
  var m = window.Tether.__core["config.ts"];
18
19
  var [cfg, isConfigured, log, MARKET_SOURCES, parseMarkets, reportError, warn] = m;
19
20
 
21
+ // tether-core:client.ts
22
+ var m2 = window.Tether.__core["client.ts"];
23
+ var [endpoint, gql, matches, orNull, shaped, TetherError, withTimeout] = m2;
24
+
20
25
  // tether-core:dom.ts
21
- var m2 = window.Tether.__core["dom.ts"];
22
- var [ANALYTICS_EVENTS, attr, attributesFromJson, busy, emit, formatDate, formatMoney, get, has, hasTemplate, integerAttribute, isOwnEvent, notifyLayoutChanged, parseJSONAttr, productUrl, qsa, repeat, scoped, sel, setImage, setStoreHtml, setText, show] = m2;
26
+ var m3 = window.Tether.__core["dom.ts"];
27
+ var [ANALYTICS_EVENTS, attr, attributesFromJson, busy, emit, formatDate, formatMoney, get, has, hasTemplate, integerAttribute, isOwnEvent, notifyLayoutChanged, parseJSONAttr, productUrl, qsa, repeat, scoped, sel, setImage, setStoreHtml, setText, show] = m3;
23
28
 
24
29
  // tether-core:product.ts
25
- var m3 = window.Tether.__core["product.ts"];
26
- var [scopes] = m3;
30
+ var m4 = window.Tether.__core["product.ts"];
31
+ var [scopes] = m4;
27
32
 
28
33
  // tether-core:cart.ts
29
- var m4 = window.Tether.__core["cart.ts"];
30
- var [Cart] = m4;
34
+ var m5 = window.Tether.__core["cart.ts"];
35
+ var [Cart] = m5;
31
36
 
32
37
  // tether-core:page-market.ts
33
- var m5 = window.Tether.__core["page-market.ts"];
34
- var [setCountry] = m5;
38
+ var m6 = window.Tether.__core["page-market.ts"];
39
+ var [setCountry] = m6;
35
40
 
36
41
  // tether-core:market-codes.ts
37
- var m6 = window.Tether.__core["market-codes.ts"];
38
- var [toCountry, toLanguage] = m6;
42
+ var m7 = window.Tether.__core["market-codes.ts"];
43
+ var [toCountry, toLanguage] = m7;
39
44
 
40
45
  // src/markets.ts
41
46
  var storageKey = () => `${cfg.prefix}:market:${cfg.domain}`;
@@ -89,6 +94,23 @@
89
94
  return null;
90
95
  }
91
96
  }
97
+ function markInvalid(form, input, invalid) {
98
+ form.classList.toggle("is-invalid", invalid);
99
+ if (invalid) input?.setAttribute("aria-invalid", "true");
100
+ else input?.removeAttribute("aria-invalid");
101
+ }
102
+ async function applyDiscountCode(form, input, code) {
103
+ try {
104
+ await Cart.applyDiscount(code);
105
+ markInvalid(form, input, false);
106
+ emit("discount-applied", { code }, form);
107
+ if (input) input.value = "";
108
+ } catch (error) {
109
+ markInvalid(form, input, true);
110
+ if (error instanceof TetherError && error.code === "INVALID_DISCOUNT") emit("discount-invalid", { code }, form);
111
+ else reportError(error, "discount");
112
+ }
113
+ }
92
114
  function onStorage(event) {
93
115
  if (event.key === cfg.storageKey || event.key === `${cfg.storageKey}:seen`) {
94
116
  Cart.init().catch((error) => {
@@ -1 +1 @@
1
- (()=>{var N=Object.defineProperty;var R=(e,t)=>{for(var n in t)N(e,n,{get:t[n],enumerable:!0})};var f={};R(f,{addGroup:()=>q,onStorage:()=>j,writeVariantUrl:()=>V});var O=window.Tether.__core["config.ts"],[u,Y,Z,P,I,i,p]=O;var v=window.Tether.__core["dom.ts"],[Q,X,m,ee,y,te,ne,k,w,re,oe,ae,ue,h,ce,S,ie,se,s,le,ge,de,fe]=v;var U=window.Tether.__core["product.ts"],[C]=U;var K=window.Tether.__core["cart.ts"],[d]=K;var H=window.Tether.__core["page-market.ts"],[M]=H;var F=window.Tether.__core["market-codes.ts"],[x,b]=F;var E=()=>`${u.prefix}:market:${u.domain}`;function $(e){try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return null;throw t}}function D(e){if(typeof e!="object"||e===null)return null;let t=x(Reflect.get(e,"country"));if(!t)return null;let n=Reflect.get(e,"locale");return{country:t,language:b(Reflect.get(e,"language"))??void 0,locale:typeof n=="string"&&n?n:void 0}}var T=e=>D($(e));function J(e,t){let n=m(h(e,"line-attributes"));return t?[{key:"_group",value:t},...n]:n}async function q(e){let t=e.closest(s("group"));if(!t)return null;let n=k(t,"group"),r=J(t,n),c=S(t,s("product")).flatMap(a=>{let o=C.get(a);if(!o?.variant?.availableForSale||o.quantity<=0)return[];let g=o.getLine();return g?[{...g,attributes:[...g.attributes??[],...r]}]:[]});if(!c.length)return p("group-add: nothing selected"),null;try{let a=await d.add(c);return y("group-added",{group:n,lines:c},t),a}catch(a){return i(a,"group add"),null}}function j(e){if(e.key===u.storageKey||e.key===`${u.storageKey}:seen`){d.init().catch(r=>{i(r,"cart from another tab")});return}if(e.key!==E()||!e.newValue)return;let t=T(e.newValue);if(!t)return;let n={language:t.language??null,locale:t.locale,remember:!1};M(t.country,n).catch(r=>{i(r,"market from another tab")})}var _=new WeakMap,L=e=>e.split("/").pop()??e;function z(e){try{window.history.replaceState(window.history.state,"",e)}catch{}}function V(e,{variant:t,sellingPlanId:n}){let r=`${t.id}|${n??""}`,c=_.get(e);if(_.set(e,r),!c||c===r)return;let a=u.variantUrl&&document.querySelector(s("product"))===e;if(!w(e,"variant-url")&&!a)return;let o=new URL(window.location.href);o.searchParams.set("variant",L(t.id)),n?o.searchParams.set("selling_plan",L(n)):o.searchParams.delete("selling_plan"),z(o)}function l(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function W(e){return l(e)&&l(e.__core)&&l(e.__parts)}function A(e,t){let n=Reflect.get(window,"Tether");if(!W(n))throw new Error(`tether.${e}.js runs after the Tether script, which loads it, and needs its window.Tether`);n.__parts[e]=t}A("extras",f);})();
1
+ (()=>{var v=Object.defineProperty;var R=(e,t)=>{for(var n in t)v(e,n,{get:t[n],enumerable:!0})};var p={};R(p,{addGroup:()=>V,applyDiscountCode:()=>W,onStorage:()=>G,writeVariantUrl:()=>Z});var O=window.Tether.__core["config.ts"],[i,X,ee,P,U,u,m]=O;var D=window.Tether.__core["client.ts"],[ne,re,oe,ae,ie,y,ce]=D;var H=window.Tether.__core["dom.ts"],[se,le,w,ge,s,de,fe,k,h,pe,me,ye,we,C,ke,S,he,Ce,l,Se,Me,xe,be]=H;var K=window.Tether.__core["product.ts"],[M]=K;var F=window.Tether.__core["cart.ts"],[g]=F;var $=window.Tether.__core["page-market.ts"],[x]=$;var q=window.Tether.__core["market-codes.ts"],[b,E]=q;var T=()=>`${i.prefix}:market:${i.domain}`;function J(e){try{return JSON.parse(e)}catch(t){if(t instanceof SyntaxError)return null;throw t}}function j(e){if(typeof e!="object"||e===null)return null;let t=b(Reflect.get(e,"country"));if(!t)return null;let n=Reflect.get(e,"locale");return{country:t,language:E(Reflect.get(e,"language"))??void 0,locale:typeof n=="string"&&n?n:void 0}}var _=e=>j(J(e));function z(e,t){let n=w(C(e,"line-attributes"));return t?[{key:"_group",value:t},...n]:n}async function V(e){let t=e.closest(l("group"));if(!t)return null;let n=k(t,"group"),r=z(t,n),c=S(t,l("product")).flatMap(a=>{let o=M.get(a);if(!o?.variant?.availableForSale||o.quantity<=0)return[];let f=o.getLine();return f?[{...f,attributes:[...f.attributes??[],...r]}]:[]});if(!c.length)return m("group-add: nothing selected"),null;try{let a=await g.add(c);return s("group-added",{group:n,lines:c},t),a}catch(a){return u(a,"group add"),null}}function L(e,t,n){e.classList.toggle("is-invalid",n),n?t?.setAttribute("aria-invalid","true"):t?.removeAttribute("aria-invalid")}async function W(e,t,n){try{await g.applyDiscount(n),L(e,t,!1),s("discount-applied",{code:n},e),t&&(t.value="")}catch(r){L(e,t,!0),r instanceof y&&r.code==="INVALID_DISCOUNT"?s("discount-invalid",{code:n},e):u(r,"discount")}}function G(e){if(e.key===i.storageKey||e.key===`${i.storageKey}:seen`){g.init().catch(r=>{u(r,"cart from another tab")});return}if(e.key!==T()||!e.newValue)return;let t=_(e.newValue);if(!t)return;let n={language:t.language??null,locale:t.locale,remember:!1};x(t.country,n).catch(r=>{u(r,"market from another tab")})}var A=new WeakMap,N=e=>e.split("/").pop()??e;function Y(e){try{window.history.replaceState(window.history.state,"",e)}catch{}}function Z(e,{variant:t,sellingPlanId:n}){let r=`${t.id}|${n??""}`,c=A.get(e);if(A.set(e,r),!c||c===r)return;let a=i.variantUrl&&document.querySelector(l("product"))===e;if(!h(e,"variant-url")&&!a)return;let o=new URL(window.location.href);o.searchParams.set("variant",N(t.id)),n?o.searchParams.set("selling_plan",N(n)):o.searchParams.delete("selling_plan"),Y(o)}function d(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function B(e){return d(e)&&d(e.__core)&&d(e.__parts)}function I(e,t){let n=Reflect.get(window,"Tether");if(!B(n))throw new Error(`tether.${e}.js runs after the Tether script, which loads it, and needs its window.Tether`);n.__parts[e]=t}I("extras",p);})();
package/dist/tether.js CHANGED
@@ -319,14 +319,20 @@
319
319
  }
320
320
  var readOnlyViews = /* @__PURE__ */ new WeakMap();
321
321
  var READ_ONLY = {
322
- get(object, key) {
323
- const value = Reflect.get(object, key);
324
- return typeof value === "object" && value !== null ? readOnlyView(value) : value;
322
+ get: (object, key) => viewOf(Reflect.get(object, key)),
323
+ // A descriptor's value is the view too, so `Object.getOwnPropertyDescriptor` doesn't hand out the live object.
324
+ getOwnPropertyDescriptor(object, key) {
325
+ const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
326
+ if (descriptor) descriptor.value = viewOf(descriptor.value);
327
+ return descriptor;
325
328
  },
326
329
  set: (_object, key) => refuseChange(key),
327
330
  deleteProperty: (_object, key) => refuseChange(key),
328
331
  defineProperty: (_object, key) => refuseChange(key)
329
332
  };
333
+ function viewOf(value) {
334
+ return typeof value === "object" && value !== null ? readOnlyView(value) : value;
335
+ }
330
336
  function readOnlyView(target) {
331
337
  let view = readOnlyViews.get(target);
332
338
  if (!view) {
@@ -1190,17 +1196,36 @@
1190
1196
  function setSelected(el, selected) {
1191
1197
  el.classList.toggle("is-selected", selected);
1192
1198
  const state = chosenState(el);
1193
- if (state === "aria-pressed" && el.tagName !== "BUTTON" && !isInput(el)) el.setAttribute("role", "button");
1199
+ if (state === "aria-pressed" && el.tagName !== "BUTTON" && !isInput(el)) {
1200
+ el.setAttribute("role", "button");
1201
+ if (!el.hasAttribute("tabindex")) el.setAttribute("tabindex", "0");
1202
+ }
1194
1203
  if (state) el.setAttribute(state, String(selected));
1195
1204
  if (isInput(el) && el.matches(CHECKABLE)) el.checked = selected;
1196
1205
  const input = el.querySelector(CHECKABLE);
1197
1206
  if (input && isInput(input)) input.checked = selected;
1198
1207
  }
1199
- function setUnavailable(el, unavailable) {
1208
+ var UNAVAILABLE_NOTE = "tether-unavailable";
1209
+ function describeUnavailable(control, unavailable) {
1210
+ if (unavailable && !document.getElementById(UNAVAILABLE_NOTE)) {
1211
+ const note = document.createElement("span");
1212
+ note.id = UNAVAILABLE_NOTE;
1213
+ note.hidden = true;
1214
+ note.textContent = "Unavailable";
1215
+ document.body.append(note);
1216
+ }
1217
+ const ids = (control.getAttribute("aria-describedby") ?? "").split(" ").filter((id) => id && id !== UNAVAILABLE_NOTE);
1218
+ if (unavailable) ids.push(UNAVAILABLE_NOTE);
1219
+ if (ids.length) control.setAttribute("aria-describedby", ids.join(" "));
1220
+ else control.removeAttribute("aria-describedby");
1221
+ }
1222
+ function setUnavailable(el, unavailable, choosing) {
1200
1223
  el.classList.toggle("is-unavailable", unavailable);
1201
1224
  const isControl = chosenState(el) !== null || isInput(el);
1202
1225
  const control = isControl ? el : el.querySelector(CHECKABLE);
1203
- control?.setAttribute("aria-disabled", String(unavailable));
1226
+ if (!control) return;
1227
+ if (choosing === "picks-closest") describeUnavailable(control, unavailable);
1228
+ else control.setAttribute("aria-disabled", String(unavailable));
1204
1229
  }
1205
1230
  var layoutTimer;
1206
1231
  var pageGlobal = (name) => Reflect.get(window, name);
@@ -1505,6 +1530,13 @@
1505
1530
  var announcedOpen = false;
1506
1531
  var returnFocus = null;
1507
1532
  var classWatcher = null;
1533
+ function callHook(hook2, drawers2, name) {
1534
+ try {
1535
+ hook2?.(drawers2);
1536
+ } catch (error) {
1537
+ reportError(error, name);
1538
+ }
1539
+ }
1508
1540
  var isFocusable = (el) => el !== null && "focus" in el;
1509
1541
  var focusables = (drawer) => qsa(drawer, FOCUSABLE).filter((el) => el.offsetParent !== null || el === document.activeElement);
1510
1542
  var drawers = () => qsa(document, sel("cart-drawer"));
@@ -1556,7 +1588,7 @@
1556
1588
  focusInto(first);
1557
1589
  }, FOCUS_AFTER_OPEN_MS);
1558
1590
  }
1559
- cfg.onCartOpen?.(opened);
1591
+ callHook(cfg.onCartOpen, opened, "onCartOpen");
1560
1592
  emit("cart-toggled", { open: true });
1561
1593
  }
1562
1594
  function announceClosed(all, hadFocus) {
@@ -1564,7 +1596,7 @@
1564
1596
  syncDrawerAria();
1565
1597
  if (hadFocus && returnFocus?.isConnected) returnFocus.focus({ preventScroll: true });
1566
1598
  returnFocus = null;
1567
- cfg.onCartClose?.(all);
1599
+ callHook(cfg.onCartClose, all, "onCartClose");
1568
1600
  emit("cart-toggled", { open: false });
1569
1601
  }
1570
1602
  function openCart() {
@@ -2380,10 +2412,9 @@
2380
2412
  const tab = target === "_blank" ? window.open("", "_blank") : null;
2381
2413
  if (tab) detachOpenerIfAllowed(tab);
2382
2414
  try {
2383
- const url2 = await runInOrder(async () => {
2384
- const cartId = cartToCheckOut();
2385
- return cartId && checkoutUrl(cartId);
2386
- });
2415
+ await runInOrder(() => Promise.resolve());
2416
+ const cartId = cartToCheckOut();
2417
+ const url2 = cartId && await checkoutUrl(cartId);
2387
2418
  if (!url2) {
2388
2419
  tab?.close();
2389
2420
  return null;
@@ -2628,10 +2659,11 @@
2628
2659
  /**
2629
2660
  * Adds a code. A code Shopify doesn't accept is removed again, so it doesn't warn on every later change.
2630
2661
  *
2631
- * @throws {TetherError} `INVALID_DISCOUNT` (rejected) when Shopify doesn't accept the code.
2662
+ * @throws {TetherError} `INVALID_DISCOUNT` (rejected) when Shopify doesn't accept the code, or it is blank.
2632
2663
  */
2633
2664
  async applyDiscount(typed) {
2634
2665
  const code = typed.trim();
2666
+ if (!code) throw new TetherError("No discount code", { code: "INVALID_DISCOUNT" });
2635
2667
  const cart = await Cart.setDiscountCodes((current) => [.../* @__PURE__ */ new Set([...current, code])]);
2636
2668
  const wanted = code.toLowerCase();
2637
2669
  const applied = (cart?.discountCodes ?? []).find((discount) => discount.code.toLowerCase() === wanted);
@@ -2902,7 +2934,7 @@
2902
2934
  const value = get(node, "option-value") ?? "";
2903
2935
  setSelected(node, view.selected[name] === value);
2904
2936
  const unavailable = !isValueAvailable(product, view.selected, name, value);
2905
- setUnavailable(node, unavailable);
2937
+ setUnavailable(node, unavailable, "picks-closest");
2906
2938
  node.setAttribute("data-unavailable", unavailable ? "true" : "false");
2907
2939
  });
2908
2940
  });
@@ -2922,12 +2954,16 @@
2922
2954
  }
2923
2955
  const mode = get(el, "purchase");
2924
2956
  setSelected(el, mode === purchase.kind);
2925
- setUnavailable(el, mode === "subscription" ? !view.subscriptionAvailable : scope.product.requiresSellingPlan);
2957
+ setUnavailable(
2958
+ el,
2959
+ mode === "subscription" ? !view.subscriptionAvailable : scope.product.requiresSellingPlan,
2960
+ "does-nothing"
2961
+ );
2926
2962
  });
2927
2963
  scope.$(sel("plan-value")).forEach((node) => {
2928
2964
  const planId = get(node, "plan-value") ?? "";
2929
2965
  setSelected(node, line.kind === "subscription" && planId === line.planId);
2930
- setUnavailable(node, !allocationFor(variant, planId));
2966
+ setUnavailable(node, !allocationFor(variant, planId), "does-nothing");
2931
2967
  const plan = scope.plans.find((candidate) => candidate.id === planId);
2932
2968
  const texts = planBindTexts(variant, planId, plan, FORMAT);
2933
2969
  qsa(node, sel("plan-bind")).forEach((el) => {
@@ -3047,6 +3083,14 @@
3047
3083
  onAddClick(scope, add);
3048
3084
  }
3049
3085
  }
3086
+ function onKeydown(event, target) {
3087
+ const { key } = event;
3088
+ const presses = key === " " || key === "Enter" && !target.matches("a[href]");
3089
+ const pressable = `:is(${sel("option-value")},${sel("plan-value")},${sel("purchase")})[role=button]:not(button,input)`;
3090
+ if (!presses || event.defaultPrevented || !target.matches(pressable)) return;
3091
+ event.preventDefault();
3092
+ target.click();
3093
+ }
3050
3094
  var purchaseKind = (value) => value === "subscription" ? "subscription" : "one-time";
3051
3095
  function onChange(scope, target) {
3052
3096
  const value = isField(target) ? target.value : "";
@@ -3067,6 +3111,9 @@
3067
3111
  scope.root.addEventListener("click", (event) => {
3068
3112
  if (isElement(event.target)) onClick(scope, event, event.target);
3069
3113
  });
3114
+ scope.root.addEventListener("keydown", (event) => {
3115
+ if (event.target instanceof window.HTMLElement) onKeydown(event, event.target);
3116
+ });
3070
3117
  scope.root.addEventListener("change", (event) => {
3071
3118
  const { target } = event;
3072
3119
  if (isElement(target) && target.closest(productSelector()) === scope.root) onChange(scope, target);
@@ -3543,7 +3590,7 @@
3543
3590
  }
3544
3591
 
3545
3592
  // src/part-integrity.ts
3546
- var PART_INTEGRITY = { "tether.diagnose.js": "sha384-CqtXzvWbLD8aIgyTM43+KMXEFA7r7lhG+0XyQAw3Sp7B5qrzPsxlA9QfzBjoPqZz", "tether.markets.js": "sha384-WjowbRhM7OzzZOrCPZWSZqN7EjIiiR7u9cGmdI+9kgFVgmEQS8lVGWjgx+8jILOf", "tether.search.js": "sha384-fLQ7eKc5XOv0Cg2FfrZyeFAkRR4wDMjUWFpwvKrfPRnT2NvTuhKg80+KVu8Qce/G", "tether.lists.js": "sha384-l2uyr96zTetjo2WWhGsBamd1ZYkC3OB3G3+OScLEvxdok0c8k9GXLAh1WRALUr4S", "tether.extras.js": "sha384-/SMjz6qCFAOV0wwvEVNhQxtT/1pyx4hRxDJHOxHB6M3uclAvItSULKZqJvaehH+i", "tether.account.js": "sha384-XUPSX/7R9chq2KlQ1RzLiV7jYcWGe7o5tj4rLZMnf8MEa2aDOOCW2269Bj/ZkbmX", "tether.account-pages.js": "sha384-ND3kIaRypgnHG3QMDb8CqDxt7fuukDCdHsIAHoOUUsz3+FjvBqXgRDV4Mjp6x8jr", "tether.analytics.js": "sha384-jnLesn/+edWBSPuXLj7VX1kSAGwEqtb0VbHjuU//ofqgxkndHlDFsS8Bc8htlGt8" };
3593
+ var PART_INTEGRITY = { "tether.diagnose.js": "sha384-CqtXzvWbLD8aIgyTM43+KMXEFA7r7lhG+0XyQAw3Sp7B5qrzPsxlA9QfzBjoPqZz", "tether.markets.js": "sha384-WjowbRhM7OzzZOrCPZWSZqN7EjIiiR7u9cGmdI+9kgFVgmEQS8lVGWjgx+8jILOf", "tether.search.js": "sha384-fLQ7eKc5XOv0Cg2FfrZyeFAkRR4wDMjUWFpwvKrfPRnT2NvTuhKg80+KVu8Qce/G", "tether.lists.js": "sha384-l2uyr96zTetjo2WWhGsBamd1ZYkC3OB3G3+OScLEvxdok0c8k9GXLAh1WRALUr4S", "tether.extras.js": "sha384-qx7paZ/rjwtn1Yy9TgszulmBuJsIQ9y4eZ590AArnZ+IDB8IzwJ5dNOFJ+yMHPdb", "tether.account.js": "sha384-XUPSX/7R9chq2KlQ1RzLiV7jYcWGe7o5tj4rLZMnf8MEa2aDOOCW2269Bj/ZkbmX", "tether.account-pages.js": "sha384-ND3kIaRypgnHG3QMDb8CqDxt7fuukDCdHsIAHoOUUsz3+FjvBqXgRDV4Mjp6x8jr", "tether.analytics.js": "sha384-jnLesn/+edWBSPuXLj7VX1kSAGwEqtb0VbHjuU//ofqgxkndHlDFsS8Bc8htlGt8" };
3547
3594
 
3548
3595
  // src/part-registry.ts
3549
3596
  function isTetherInternals(value) {
@@ -3551,7 +3598,7 @@
3551
3598
  }
3552
3599
 
3553
3600
  // src/version.ts
3554
- var VERSION = "0.9.4";
3601
+ var VERSION = "0.9.6";
3555
3602
 
3556
3603
  // src/lazy-iife.ts
3557
3604
  var coreModules = {
@@ -3878,7 +3925,7 @@
3878
3925
  }
3879
3926
  }
3880
3927
  var hasValue = (target) => target instanceof window.HTMLInputElement || target instanceof window.HTMLTextAreaElement || target instanceof window.HTMLSelectElement;
3881
- function onKeydown(event) {
3928
+ function onKeydown2(event) {
3882
3929
  if (!Cart.isOpen()) return;
3883
3930
  if (event.key === "Escape") {
3884
3931
  Cart.close();
@@ -3889,7 +3936,7 @@
3889
3936
  function bindCartControls() {
3890
3937
  document.addEventListener("click", onClick2);
3891
3938
  document.addEventListener("change", onChange2);
3892
- document.addEventListener("keydown", onKeydown);
3939
+ document.addEventListener("keydown", onKeydown2);
3893
3940
  }
3894
3941
 
3895
3942
  // src/controls/discount.ts
@@ -3898,23 +3945,6 @@
3898
3945
  const input = form.querySelector(sel("discount-input")) ?? form.querySelector("input");
3899
3946
  return input instanceof window.HTMLInputElement ? input : null;
3900
3947
  }
3901
- function markInvalid(form, input, invalid) {
3902
- form.classList.toggle("is-invalid", invalid);
3903
- if (invalid) input?.setAttribute("aria-invalid", "true");
3904
- else input?.removeAttribute("aria-invalid");
3905
- }
3906
- async function applyCode(form, input, code) {
3907
- try {
3908
- await Cart.applyDiscount(code);
3909
- markInvalid(form, input, false);
3910
- emit("discount-applied", { code }, form);
3911
- if (input) input.value = "";
3912
- } catch (error) {
3913
- markInvalid(form, input, true);
3914
- if (error instanceof TetherError && error.code === "INVALID_DISCOUNT") emit("discount-invalid", { code }, form);
3915
- else reportError(error, "discount");
3916
- }
3917
- }
3918
3948
  function onSubmit(event) {
3919
3949
  const { target } = event;
3920
3950
  const form = isElement3(target) ? target.closest(sel("discount-form")) : null;
@@ -3923,7 +3953,11 @@
3923
3953
  const input = codeInputOf(form);
3924
3954
  const code = input?.value.trim();
3925
3955
  if (!code) return;
3926
- void busy(form, () => applyCode(form, input, code));
3956
+ busy(form, () => loadPart("extras").then((part) => part.applyDiscountCode(form, input, code))).catch(
3957
+ (error) => {
3958
+ reportError(error, "discount");
3959
+ }
3960
+ );
3927
3961
  }
3928
3962
  function onInput(event) {
3929
3963
  const { target } = event;