PageSourceSearch

https://www.allbirds.co.uk/cdn/shop/t/3608/assets/use-focus-management.js

js allbirds.co.uk collected 2026-09-24 19:57:32 UTC 5,119 bytes, 1 lines download raw bytes

1import{r as c,w as _,o as B,x as H}from"./vue.esm-bundler.js";import{e as T}from"./ScrollTrigger.js";const j=c(null);function K(){return{clearPrediction:()=>{j.value=null},predictedItemCount:j,setPrediction:v=>{j.value=v}}}const A=new Map,x={CART_UPDATED:"cart:updated"},M=(o,r)=>{A.get(o)?.forEach(v=>v(r))},q=(o,r)=>(A.has(o)||A.set(o,new Set),A.get(o).add(r),()=>A.get(o)?.delete(r)),C=window.Shopify.routes.root,P={"Content-Type":"application/json"},F="POST",i=c(null),f=c(!1);function G(){const{clearPrediction:o,setPrediction:r}=K(),v=(t,e)=>{const n=parseInt(e);return t.variant_id===n||t.id===n||t.variant_id===e||t.id===e},h=async(t=!1)=>i.value&&!t?i.value:(f.value=!0,fetch(`${C}cart.js`).then(e=>{if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return e.json()}).then(e=>(i.value=e,e)).catch(e=>{throw i.value=null,e}).finally(()=>{f.value=!1})),L=async t=>{try{const e=await fetch(`${C}cart/update.js`,{body:JSON.stringify({attributes:t}),headers:P,method:F});if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);const n=await e.json();return i.value?i.value.attributes={...i.value.attributes,...n.attributes}:i.value=n,i.value||n}catch(e){throw T("[Allbirds composable] - useCart - addAttributes - Failed to update cart attributes",{attributes:t},e),e}},m=async(t,e=1,n,u={})=>{const{skipPrediction:d=!1}=u,p=i.value?.items?.length||0;if(!d){const b=i.value?.items?.find($=>v($,t));r(b?p:p+1)}const D=[{id:t,properties:n,quantity:e}];try{return await E({items:D})}finally{d||o()}},E=async t=>{f.value=!0;try{await fetch(`${C}cart/add.js`,{body:JSON.stringify(t),headers:P,method:F});const e=await h(!0);return M(x.CART_UPDATED,e),e}catch(e){throw T("[Allbirds composable] - useCart - addToCart - Failed to add to cart",{items:t},e),e}finally{f.value=!1}},S=async t=>{f.value=!0;try{await fetch(`${C}cart/update.js`,{body:JSON.stringify(t),headers:P,method:F});const e=await h(!0);return M(x.CART_UPDATED,e),e}catch(e){throw T("[Allbirds composable] - useCart - updateCart - Failed to update cart",{updates:t},e),e}finally{f.value=!1}},w=async(t,e=1,n={})=>{const{skipPrediction:u=!1}=n;if(!u&&e===0){const p=i.value?.items?.length||0;r(p-1)}const d={[t]:e};try{return await S({updates:d})}finally{!u&&e===0&&o()}};return{addAttributes:L,addSingleVariant:m,addToCart:E,cart:i,clearCart:async()=>{f.value=!0;try{return await(await fetch(`${C}cart/clear.js`,{headers:P,method:F})).json()}catch(t){throw T("[Allbirds composable] - useCart - clearCart - Failed to clear cart",{},t),t}finally{f.value=!1}},getCart:h,isLoading:f,removeLineItem:async(t,e={})=>w(t,0,e),updateCart:S,updateCartLineProperties:async(t,e,n)=>{const u={line:t+1,properties:n,quantity:e};try{return await fetch(`${C}cart/change.js`,{body:JSON.stringify(u),headers:P,method:F}),await h(!0)}catch(d){throw T("[Allbirds composable] - useCart - updateCartLineProperties - Failed to update cart line properties",{index:t,properties:n},d),d}},updateSingleLineItem:w}}const I=c(!1);function Q(){const o=()=>{I.value=!0},r=()=>{I.value=!1};return{closeDrawer:r,isOpen:I,openDrawer:o,toggleDrawer:()=>{I.value?r():o()}}}function W(o){const{containerRef:r,focusFirstOnActivate:v=c(!1),focusTriggerElementRef:h=c(null),initialFocusSelector:L=null,isActive:m=c(!0),onElementActivated:E=null,shouldRestoreFocus:S=c(!0),trapFocus:w=!1}=o,l=c([]),g=c(-1),O=c(!1),t=()=>r.value?Array.from(r.value.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')).filter(s=>{const y=s.getBoundingClientRect();return s.offsetParent!==null&&window.getComputedStyle(s).visibility!=="hidden"&&window.getComputedStyle(s).display!=="none"&&y.width>0&&y.height>0}):[],e=()=>{l.value=t()},n=a=>{a>=0&&a<l.value.length&&(l.value[a].focus(),g.value=a)},u=()=>{e(),n(0)},d=()=>{e(),n(l.value.length-1)},p=()=>{if(e(),!(!l.value.length||!v.value)){if(L){const a=r.value?.querySelector(L),s=l.value.findIndex(y=>y===a);if(s!==-1){n(s);return}}u()}},D=()=>{h.value&&h.value.focus()},b=a=>{const{key:s}=a;if(!(!m.value||!r.value)&&((s==="Enter"||s===" ")&&E&&E(a),s==="Tab")){if(e(),l.value.length===0)return;const y=document.activeElement,R=r.value.contains(y);g.value=l.value.findIndex(V=>V===y),a.shiftKey?(!R||g.value===0)&&w&&(a.preventDefault(),d()):R?g.value===l.value.length-1&&w&&(a.preventDefault(),u()):w&&(a.preventDefault(),u())}},$=()=>{const a=r.value;a&&a.addEventListener("keydown",b,!0)},k=()=>{const a=r.value;a&&a.removeEventListener("keydown",b,!0)},U=()=>{m.value=!0},J=()=>{m.value=!1};return _(m,(a,s)=>{a?setTimeout(()=>{r.value&&(p(),$())},100):(k(),s&&S.value&&D())},{immediate:!1}),_(r,(a,s)=>{m.value&&(s&&s.removeEventListener("keydown",b,!0),a?(a.addEventListener("keydown",b,!0),e()):l.value=[])}),B(()=>{m.value&&r.value&&(p(),$()),O.value=!0}),H(()=>{k()}),{activateFocusManagement:U,currentFocusIndex:g,deactivateFocusManagement:J,focusableElements:l,focusElementByIndex:n,focusFirstElement:u,focusLastElement:d,restoreFocus:D,updateFocusableElements:e}}export{x as C,W as a,Q as b,K as c,q as o,G as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.