@travel-match/ui 0.2.0 → 0.4.0

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 (54) hide show
  1. package/dist/components/CtaSentence/CtaSentence.cjs +1 -1
  2. package/dist/components/CtaSentence/CtaSentence.cjs.map +1 -1
  3. package/dist/components/CtaSentence/CtaSentence.js +142 -69
  4. package/dist/components/CtaSentence/CtaSentence.js.map +1 -1
  5. package/dist/components/HeroColumns/heroMotion.cjs +1 -1
  6. package/dist/components/HeroColumns/heroMotion.cjs.map +1 -1
  7. package/dist/components/HeroColumns/heroMotion.js +7 -44
  8. package/dist/components/HeroColumns/heroMotion.js.map +1 -1
  9. package/dist/components/HeroMap/HeroMap.cjs +1 -1
  10. package/dist/components/HeroMap/HeroMap.cjs.map +1 -1
  11. package/dist/components/HeroMap/HeroMap.js +58 -67
  12. package/dist/components/HeroMap/HeroMap.js.map +1 -1
  13. package/dist/components/HeroSwitcher/HeroSwitcher.cjs +1 -1
  14. package/dist/components/HeroSwitcher/HeroSwitcher.cjs.map +1 -1
  15. package/dist/components/HeroSwitcher/HeroSwitcher.js +85 -92
  16. package/dist/components/HeroSwitcher/HeroSwitcher.js.map +1 -1
  17. package/dist/components/HowItWorksSteps/HowItWorksSteps.cjs +1 -1
  18. package/dist/components/HowItWorksSteps/HowItWorksSteps.cjs.map +1 -1
  19. package/dist/components/HowItWorksSteps/HowItWorksSteps.js +84 -102
  20. package/dist/components/HowItWorksSteps/HowItWorksSteps.js.map +1 -1
  21. package/dist/components/LogoAnimation/LogoAnimation.cjs +2 -0
  22. package/dist/components/LogoAnimation/LogoAnimation.cjs.map +1 -0
  23. package/dist/components/LogoAnimation/LogoAnimation.js +202 -0
  24. package/dist/components/LogoAnimation/LogoAnimation.js.map +1 -0
  25. package/dist/components/LogoAnimation/LogoAnimationArtwork.cjs +2 -0
  26. package/dist/components/LogoAnimation/LogoAnimationArtwork.cjs.map +1 -0
  27. package/dist/components/LogoAnimation/LogoAnimationArtwork.js +57 -0
  28. package/dist/components/LogoAnimation/LogoAnimationArtwork.js.map +1 -0
  29. package/dist/components/LogoAnimation/motion.cjs +2 -0
  30. package/dist/components/LogoAnimation/motion.cjs.map +1 -0
  31. package/dist/components/LogoAnimation/motion.js +180 -0
  32. package/dist/components/LogoAnimation/motion.js.map +1 -0
  33. package/dist/components/PackageAnimation/PackageAnimation.cjs +1 -1
  34. package/dist/components/PackageAnimation/PackageAnimation.cjs.map +1 -1
  35. package/dist/components/PackageAnimation/PackageAnimation.js +31 -40
  36. package/dist/components/PackageAnimation/PackageAnimation.js.map +1 -1
  37. package/dist/components/PartnerCarousel/PartnerCarousel.cjs +1 -1
  38. package/dist/components/PartnerCarousel/PartnerCarousel.cjs.map +1 -1
  39. package/dist/components/PartnerCarousel/PartnerCarousel.js +94 -101
  40. package/dist/components/PartnerCarousel/PartnerCarousel.js.map +1 -1
  41. package/dist/components/PartnerCarousel/autoplay.cjs +1 -1
  42. package/dist/components/PartnerCarousel/autoplay.cjs.map +1 -1
  43. package/dist/components/PartnerCarousel/autoplay.js +13 -9
  44. package/dist/components/PartnerCarousel/autoplay.js.map +1 -1
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.d.cts +62 -55
  47. package/dist/index.d.ts +62 -55
  48. package/dist/index.js +100 -99
  49. package/dist/styles.css +1 -1
  50. package/package.json +1 -1
  51. package/dist/components/PartnerCarousel/AutoplayToggle.cjs +0 -2
  52. package/dist/components/PartnerCarousel/AutoplayToggle.cjs.map +0 -1
  53. package/dist/components/PartnerCarousel/AutoplayToggle.js +0 -36
  54. package/dist/components/PartnerCarousel/AutoplayToggle.js.map +0 -1
@@ -1,2 +1,2 @@
1
- "use client";const e=require("../../utils/cn.cjs"),t=require("../Pagination/Pagination.cjs"),n=require("./AutoplayToggle.cjs"),r=require("./autoplay.cjs");;/* empty css */let i=require("react"),a=require("react/jsx-runtime");var o=700,s=e=>e<.5?2*e*e:1-(-2*e+2)**2/2,c=typeof window>`u`?i.useEffect:i.useLayoutEffect,l=(e,t)=>`${e+1} of ${t}`,u=(e,t)=>`Slide ${e} of ${t}`,d=e=>e?.setAttribute(`inert`,``),f=(0,i.forwardRef)(function({children:f,value:p,defaultValue:m=0,onValueChange:h,autoPlay:g=!0,interval:_=3e3,paused:v=!1,loop:y=!0,controls:b=!0,getSlideLabel:x=l,getPageLabel:S=u,paginationLabel:C=`Slides`,pauseLabel:w=`Pause the slide show`,playLabel:T=`Play the slide show`,className:E,...D},O){let k=i.Children.toArray(f),A=k.length,j=y&&A>2,M=(0,i.useRef)(null),N=(0,i.useRef)(null),[P,F]=r.useIndexState(p,m,h,A),[I,L]=(0,i.useState)(A),R=j?A:Math.max(1,Math.min(I,A)),z=(0,i.useRef)(P),B=(0,i.useRef)(0),V=(0,i.useRef)(!1),H=(0,i.useRef)(void 0),U=(0,i.useCallback)(()=>{let e=N.current?.querySelectorAll(`.tm-partner-carousel__slide`);return!e||e.length<2?0:e[1].offsetLeft-e[0].offsetLeft},[]),W=(0,i.useCallback)(()=>{V.current&&(cancelAnimationFrame(B.current),V.current=!1,N.current&&(N.current.style.scrollSnapType=``))},[]),G=(0,i.useCallback)(()=>{let e=N.current,t=U();if(!e||t<=0||V.current)return;let n=Math.round(e.scrollLeft/t);j&&n>=A&&(n-=A,e.scrollLeft=n*t);let r=Math.max(0,Math.min(n,R-1));r!==z.current&&(z.current=r,F(r))},[A,U,j,R,F]),K=(0,i.useCallback)((e,t)=>{let n=N.current,r=U();if(!n||r<=0)return;W();let i=n.scrollLeft,a=Math.min(e*r,n.scrollWidth-n.clientWidth),c=typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;if(!t||c||Math.abs(a-i)<1){n.scrollLeft=a,G();return}V.current=!0,n.style.scrollSnapType=`none`;let l=performance.now(),u=e=>{let t=Math.min(1,(e-l)/o);n.scrollLeft=i+(a-i)*s(t),t<1?B.current=requestAnimationFrame(u):(V.current=!1,n.style.scrollSnapType=``,G())};B.current=requestAnimationFrame(u)},[U,G,W]),q=(0,i.useCallback)((e,t={})=>{let n=N.current,r=U(),i=e;if(t.forward&&j&&n&&r>0){let e=Math.round(n.scrollLeft/r);e>=A&&(e-=A,n.scrollLeft=e*r),i=e+1}z.current=e,t.silent||F(e),K(i,t.animate??!0)},[A,U,j,K,F]);c(()=>(z.current>0&&K(z.current,!1),()=>{cancelAnimationFrame(B.current),clearTimeout(H.current)}),[]),(0,i.useEffect)(()=>{P!==z.current&&q(P,{silent:!0})},[P,q]),(0,i.useEffect)(()=>{let e=N.current;if(!e)return;let t=()=>{let t=U();if(t<=0)return L(A);L(Math.ceil((e.scrollWidth-e.clientWidth)/t-.05)+1)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[A,U,j]);let{running:J,userPaused:Y,toggle:X,interactionProps:Z}=r.useAutoplay({enabled:g&&R>1,paused:v,delay:_+o,onTick:()=>q((z.current+1)%R,{forward:!0}),rootRef:M,resetKey:P}),Q=()=>{if(V.current)return;let e=N.current,t=U();if(!e||t<=0)return;let n=Math.round(e.scrollLeft/t),r=Math.max(0,Math.min(j?n%A:n,R-1));r!==z.current&&(z.current=r,F(r)),clearTimeout(H.current),H.current=setTimeout(G,140)},{onPointerEnter:$,onPointerLeave:ee,onFocus:te,onBlur:ne}=Z;return(0,a.jsxs)(`section`,{ref:e=>{M.current=e,typeof O==`function`?O(e):O&&(O.current=e)},className:e.cn(`tm-partner-carousel`,E),"aria-roledescription":`carousel`,"data-autoplay":J?`running`:g?`paused`:void 0,...D,onPointerEnter:e=>{D.onPointerEnter?.(e),$(e)},onPointerLeave:e=>{D.onPointerLeave?.(e),ee()},onFocus:e=>{D.onFocus?.(e),te()},onBlur:e=>{D.onBlur?.(e),ne(e)},children:[(0,a.jsx)(`div`,{ref:N,className:`tm-partner-carousel__viewport`,onScroll:Q,onPointerDown:W,onTouchStart:W,onWheel:W,onKeyDown:e=>{(e.key.startsWith(`Arrow`)||e.key===`Home`||e.key===`End`)&&W()},children:(0,a.jsxs)(`div`,{className:`tm-partner-carousel__track`,children:[k.map((e,t)=>(0,a.jsx)(`div`,{className:`tm-partner-carousel__slide`,role:`group`,"aria-roledescription":`slide`,"aria-label":x(t,A),children:e},t)),j?k.map((e,t)=>(0,a.jsx)(`div`,{ref:d,className:`tm-partner-carousel__slide`,"data-clone":``,"aria-hidden":`true`,children:e},`clone-${t}`)):null]})}),b&&R>1?(0,a.jsxs)(`div`,{className:`tm-partner-carousel__controls`,children:[(0,a.jsx)(t.Pagination,{page:P+1,pageCount:R,onPageChange:e=>q(e-1),getPageLabel:S,"aria-label":C}),g?(0,a.jsx)(n.AutoplayToggle,{className:`tm-partner-carousel__toggle`,paused:Y,pauseLabel:w,playLabel:T,onClick:X}):null]}):null]})});exports.PartnerCarousel=f;
1
+ "use client";const e=require("../../utils/cn.cjs"),t=require("../Pagination/Pagination.cjs"),n=require("./autoplay.cjs");;/* empty css */let r=require("react"),i=require("react/jsx-runtime");var a=700,o=e=>e<.5?2*e*e:1-(-2*e+2)**2/2,s=typeof window>`u`?r.useEffect:r.useLayoutEffect,c=(e,t)=>`${e+1} of ${t}`,l=(e,t)=>`Slide ${e} of ${t}`,u=e=>e?.setAttribute(`inert`,``),d=(0,r.forwardRef)(function({children:d,value:f,defaultValue:p=0,onValueChange:m,autoPlay:h=!0,interval:g=3e3,paused:_=!1,loop:v=!0,controls:y=!0,getSlideLabel:b=c,getPageLabel:x=l,paginationLabel:S=`Slides`,className:C,...w},T){let E=r.Children.toArray(d),D=E.length,O=v&&D>2,k=(0,r.useRef)(null),A=(0,r.useRef)(null),[j,M]=n.useIndexState(f,p,m,D),[N,P]=(0,r.useState)(D),F=O?D:Math.max(1,Math.min(N,D)),I=(0,r.useRef)(j),L=(0,r.useRef)(0),R=(0,r.useRef)(!1),z=(0,r.useRef)(void 0),B=(0,r.useCallback)(()=>{let e=A.current?.querySelectorAll(`.tm-partner-carousel__slide`);return!e||e.length<2?0:e[1].offsetLeft-e[0].offsetLeft},[]),V=(0,r.useCallback)(()=>{R.current&&(cancelAnimationFrame(L.current),R.current=!1,A.current&&(A.current.style.scrollSnapType=``))},[]),H=(0,r.useCallback)(()=>{let e=A.current,t=B();if(!e||t<=0||R.current)return;let n=Math.round(e.scrollLeft/t);O&&n>=D&&(n-=D,e.scrollLeft=n*t);let r=Math.max(0,Math.min(n,F-1));r!==I.current&&(I.current=r,M(r))},[D,B,O,F,M]),U=(0,r.useCallback)((e,t)=>{let n=A.current,r=B();if(!n||r<=0)return;V();let i=n.scrollLeft,s=Math.min(e*r,n.scrollWidth-n.clientWidth),c=typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;if(!t||c||Math.abs(s-i)<1){n.scrollLeft=s,H();return}R.current=!0,n.style.scrollSnapType=`none`;let l=performance.now(),u=e=>{let t=Math.min(1,(e-l)/a);n.scrollLeft=i+(s-i)*o(t),t<1?L.current=requestAnimationFrame(u):(R.current=!1,n.style.scrollSnapType=``,H())};L.current=requestAnimationFrame(u)},[B,H,V]),W=(0,r.useCallback)((e,t={})=>{let n=A.current,r=B(),i=e;if(t.forward&&O&&n&&r>0){let e=Math.round(n.scrollLeft/r);e>=D&&(e-=D,n.scrollLeft=e*r),i=e+1}I.current=e,t.silent||M(e),U(i,t.animate??!0)},[D,B,O,U,M]);s(()=>(I.current>0&&U(I.current,!1),()=>{cancelAnimationFrame(L.current),clearTimeout(z.current)}),[]),(0,r.useEffect)(()=>{j!==I.current&&W(j,{silent:!0})},[j,W]),(0,r.useEffect)(()=>{let e=A.current;if(!e)return;let t=()=>{let t=B();if(t<=0)return P(D);P(Math.ceil((e.scrollWidth-e.clientWidth)/t-.05)+1)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[D,B,O]);let{running:G,interactionProps:K}=n.useAutoplay({enabled:h&&F>1,paused:_,delay:g+a,onTick:()=>W((I.current+1)%F,{forward:!0}),rootRef:k,resetKey:j}),q=()=>{if(R.current)return;let e=A.current,t=B();if(!e||t<=0)return;let n=Math.round(e.scrollLeft/t),r=Math.max(0,Math.min(O?n%D:n,F-1));r!==I.current&&(I.current=r,M(r)),clearTimeout(z.current),z.current=setTimeout(H,140)},{onPointerEnter:J,onPointerLeave:Y,onFocus:X,onBlur:Z}=K;return(0,i.jsxs)(`section`,{ref:e=>{k.current=e,typeof T==`function`?T(e):T&&(T.current=e)},className:e.cn(`tm-partner-carousel`,C),"aria-roledescription":`carousel`,"data-autoplay":G?`running`:h?`paused`:void 0,...w,onPointerEnter:e=>{w.onPointerEnter?.(e),J(e)},onPointerLeave:e=>{w.onPointerLeave?.(e),Y()},onFocus:e=>{w.onFocus?.(e),X(e)},onBlur:e=>{w.onBlur?.(e),Z(e)},children:[(0,i.jsx)(`div`,{ref:A,className:`tm-partner-carousel__viewport`,onScroll:q,onPointerDown:V,onTouchStart:V,onWheel:V,onKeyDown:e=>{(e.key.startsWith(`Arrow`)||e.key===`Home`||e.key===`End`)&&V()},children:(0,i.jsxs)(`div`,{className:`tm-partner-carousel__track`,children:[E.map((e,t)=>(0,i.jsx)(`div`,{className:`tm-partner-carousel__slide`,role:`group`,"aria-roledescription":`slide`,"aria-label":b(t,D),children:e},t)),O?E.map((e,t)=>(0,i.jsx)(`div`,{ref:u,className:`tm-partner-carousel__slide`,"data-clone":``,"aria-hidden":`true`,children:e},`clone-${t}`)):null]})}),y&&F>1?(0,i.jsx)(`div`,{className:`tm-partner-carousel__controls`,children:(0,i.jsx)(t.Pagination,{page:j+1,pageCount:F,onPageChange:e=>W(e-1),getPageLabel:x,"aria-label":S})}):null]})});exports.PartnerCarousel=d;
2
2
  //# sourceMappingURL=PartnerCarousel.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"PartnerCarousel.cjs","names":["useEffect","useLayoutEffect","Children","useRef","useIndexState","useState","useCallback","useAutoplay","cn","Pagination","AutoplayToggle","require_cn","require_Pagination","require_AutoplayToggle","require_autoplay","react","react_jsx_runtime","SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","children","looping","loop","rootRef","viewportRef","setIndex","value","defaultValue","onValueChange","stops","setStops","shown","frame","animating","settleTimer","getStep","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","autoPlay","interval","handleScroll","interactionProps","node","ref","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","paginationLabel","userPaused","toggle"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { AutoplayToggle } from './AutoplayToggle';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself. Stops for hover, focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay (the pause control stays available). */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots and, with `autoPlay`, the pause / play button. */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n /** Name of the pause button — translate it. */\n pauseLabel?: string;\n /** Name of the play button — translate it. */\n playLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n pauseLabel = 'Pause the slide show',\n playLabel = 'Play the slide show',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, userPaused, toggle, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus();\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n {autoPlay ? <AutoplayToggle className=\"tm-partner-carousel__toggle\" paused={userPaused} pauseLabel={pauseLabel} playLabel={playLabel} onClick={toggle} /> : null}\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":"A,sPAQA,IAAMiB,EAAiB,IAEjBC,EAAa,GAAeC,EAAI,GAAM,EAAIA,EAAIA,EAAI,GAAK,GAAKA,EAAI,IAAM,EAAI,EAC1EC,EAA4B,OAAO,OAAW,IAAcpB,EAAAA,UAAYC,EAAAA,gBAmCxEoB,GAAqB,EAAe,IAAkB,GAAGC,EAAQ,EAAE,MAAMC,IACzEC,GAAoB,EAAc,IAAsB,SAASC,EAAK,MAAMC,IAC5EC,EAAY,GAAgCC,GAAS,aAAa,QAAS,EAAE,EAQtEC,GAAkC,EAAAd,EAAA,WAAA,CAA8C,SAC3F,CACE,WACA,QACA,eAAe,EACf,gBACA,WAAW,GACX,WAAW,IACX,SAAS,GACT,OAAO,GACP,WAAW,GACX,gBAAgBM,EAChB,eAAeG,EACf,kBAAkB,SAClB,aAAa,uBACb,YAAY,sBACZ,YACA,GAAGM,GAEL,EACA,CACA,IAAMC,EAAS7B,EAAAA,SAAS,QAAQ8B,CAAQ,EAClCT,EAAQQ,EAAO,OACfE,EAAUC,GAAQX,EAAQ,EAE1BY,GAAA,EAAUhC,EAAAA,OAAAA,CAA2B,IAAI,EACzCiC,GAAA,EAAcjC,EAAAA,OAAAA,CAA8B,IAAI,EAChD,CAACmB,EAAOe,GAAYjC,EAAAA,cAAckC,EAAOC,EAAcC,EAAejB,CAAK,EAE3E,CAACkB,EAAOC,IAAA,EAAYrC,EAAAA,SAAAA,CAASkB,CAAK,EAClCG,EAAYO,EAAUV,EAAQ,KAAK,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AAf,EAAA,IAAA,CAAC,MAAD,CAAwB,IAAKW,EAAU,UAAU,6BAA6B,aAAW,GAAG,cAAY,OACrG,SAAAwD,CACE,EAFK,SAASD,GAEd,CACN,EACD,IACD,C,EACF,CAAA,EAEJE,GAAY1D,EAAY,GACvB,EAAAV,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,gCAAf,SAAA,EACE,EAAAA,EAAA,IAAA,CAACP,EAAAA,WAAD,CAAY,KAAMa,EAAQ,EAAc,YAAW,aAAe,GAASyC,EAAKtC,EAAO,CAAC,EAAiB,eAAc,aAAY4D,CAAkB,CAAA,EACpJjB,GAAW,EAAApD,EAAA,IAAA,CAACN,EAAAA,eAAD,CAAgB,UAAU,8BAA8B,OAAQ4E,EAAwB,aAAuB,YAAW,QAASC,CAAS,CAAA,EAAI,IACzJ,CACH,CAAA,EAAA,IACG,C,EAEb,CAAC,E"}
1
+ {"version":3,"file":"PartnerCarousel.cjs","names":["useEffect","useLayoutEffect","Children","useRef","useIndexState","useState","useCallback","useAutoplay","cn","Pagination","require_cn","require_Pagination","require_autoplay","react","react_jsx_runtime","SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","children","looping","loop","rootRef","viewportRef","setIndex","value","defaultValue","onValueChange","stops","setStops","shown","frame","animating","settleTimer","getStep","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","autoPlay","interval","handleScroll","interactionProps","node","ref","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","paginationLabel"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself, in an endless loop. Holds for hover, keyboard focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay from outside; it carries on once this is `false` again. */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots. */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":"A,oNAOA,IAAMe,EAAiB,IAEjBC,EAAa,GAAeC,EAAI,GAAM,EAAIA,EAAIA,EAAI,GAAK,GAAKA,EAAI,IAAM,EAAI,EAC1EC,EAA4B,OAAO,OAAW,IAAclB,EAAAA,UAAYC,EAAAA,gBA+BxEkB,GAAqB,EAAe,IAAkB,GAAGC,EAAQ,EAAE,MAAMC,IACzEC,GAAoB,EAAc,IAAsB,SAASC,EAAK,MAAMC,IAC5EC,EAAY,GAAgCC,GAAS,aAAa,QAAS,EAAE,EAQtEC,GAAkC,EAAAd,EAAA,WAAA,CAA8C,SAC3F,CACE,WACA,QACA,eAAe,EACf,gBACA,WAAW,GACX,WAAW,IACX,SAAS,GACT,OAAO,GACP,WAAW,GACX,gBAAgBM,EAChB,eAAeG,EACf,kBAAkB,SAClB,YACA,GAAGM,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AM,IAAI,WAAW,OAAO,GAAKA,EAAM,MAAQ,QAAUA,EAAM,MAAQ,QAAO3B,EAAc,CAClG,EAEA,UAAA,EAAAjC,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,6BAAf,SAAA,CACGe,EAAO,KAAK,EAAO,KAClB,EAAAf,EAAA,IAAA,CAAC,MAAD,CAAa,UAAU,6BAA6B,KAAK,QAAQ,uBAAqB,QAAQ,aAAYiE,EAAcC,EAAG3D,CAAK,EAC7H,SAAA4D,CACE,EAFKD,CAEL,CACN,EAEAjD,EACGF,EAAO,KAAK,EAAO,KACjB,EAAAf,EAAA,IAAA,CAAC,MAAD,CAAwB,IAAKW,EAAU,UAAU,6BAA6B,aAAW,GAAG,cAAY,OACrG,SAAAwD,CACE,EAFK,SAASD,GAEd,CACN,EACD,IACD,C,EACF,CAAA,EAEJE,GAAY1D,EAAY,GACvB,EAAAV,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,gCACb,UAAA,EAAAA,EAAA,IAAA,CAACL,EAAAA,WAAD,CAAY,KAAMW,EAAQ,EAAc,YAAW,aAAe,GAASyC,EAAKtC,EAAO,CAAC,EAAiB,eAAc,aAAY4D,CAAkB,CAAA,CAClJ,CAAA,EACH,IACG,C,EAEb,CAAC,E"}
@@ -1,162 +1,155 @@
1
1
  "use client";
2
2
  import { cn as e } from "../../utils/cn.js";
3
3
  import { Pagination as t } from "../Pagination/Pagination.js";
4
- import { AutoplayToggle as n } from "./AutoplayToggle.js";
5
- import { useAutoplay as r, useIndexState as i } from "./autoplay.js";
4
+ import { useAutoplay as n, useIndexState as r } from "./autoplay.js";
6
5
  /* empty css */
7
- import { Children as a, forwardRef as o, useCallback as s, useEffect as c, useLayoutEffect as l, useRef as u, useState as d } from "react";
8
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
6
+ import { Children as i, forwardRef as a, useCallback as o, useEffect as s, useLayoutEffect as c, useRef as l, useState as u } from "react";
7
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
9
8
  // src/components/PartnerCarousel/PartnerCarousel.tsx
10
- var m = 700, h = (e) => e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2, g = typeof window > "u" ? c : l, _ = (e, t) => `${e + 1} of ${t}`, v = (e, t) => `Slide ${e} of ${t}`, y = (e) => e?.setAttribute("inert", ""), b = /* @__PURE__ */ o(function({ children: o, value: l, defaultValue: b = 0, onValueChange: x, autoPlay: S = !0, interval: C = 3e3, paused: w = !1, loop: T = !0, controls: E = !0, getSlideLabel: D = _, getPageLabel: O = v, paginationLabel: k = "Slides", pauseLabel: A = "Pause the slide show", playLabel: j = "Play the slide show", className: M, ...N }, P) {
11
- let F = a.toArray(o), I = F.length, L = T && I > 2, R = u(null), z = u(null), [B, V] = i(l, b, x, I), [H, U] = d(I), W = L ? I : Math.max(1, Math.min(H, I)), G = u(B), K = u(0), q = u(!1), J = u(void 0), Y = s(() => {
12
- let e = z.current?.querySelectorAll(".tm-partner-carousel__slide");
9
+ var p = 700, m = (e) => e < .5 ? 2 * e * e : 1 - (-2 * e + 2) ** 2 / 2, h = typeof window > "u" ? s : c, g = (e, t) => `${e + 1} of ${t}`, _ = (e, t) => `Slide ${e} of ${t}`, v = (e) => e?.setAttribute("inert", ""), y = /* @__PURE__ */ a(function({ children: a, value: c, defaultValue: y = 0, onValueChange: b, autoPlay: x = !0, interval: S = 3e3, paused: C = !1, loop: w = !0, controls: T = !0, getSlideLabel: E = g, getPageLabel: D = _, paginationLabel: O = "Slides", className: k, ...A }, j) {
10
+ let M = i.toArray(a), N = M.length, P = w && N > 2, F = l(null), I = l(null), [L, R] = r(c, y, b, N), [z, B] = u(N), V = P ? N : Math.max(1, Math.min(z, N)), H = l(L), U = l(0), W = l(!1), G = l(void 0), K = o(() => {
11
+ let e = I.current?.querySelectorAll(".tm-partner-carousel__slide");
13
12
  return !e || e.length < 2 ? 0 : e[1].offsetLeft - e[0].offsetLeft;
14
- }, []), X = s(() => {
15
- q.current && (cancelAnimationFrame(K.current), q.current = !1, z.current && (z.current.style.scrollSnapType = ""));
16
- }, []), Z = s(() => {
17
- let e = z.current, t = Y();
18
- if (!e || t <= 0 || q.current) return;
13
+ }, []), q = o(() => {
14
+ W.current && (cancelAnimationFrame(U.current), W.current = !1, I.current && (I.current.style.scrollSnapType = ""));
15
+ }, []), J = o(() => {
16
+ let e = I.current, t = K();
17
+ if (!e || t <= 0 || W.current) return;
19
18
  let n = Math.round(e.scrollLeft / t);
20
- L && n >= I && (n -= I, e.scrollLeft = n * t);
21
- let r = Math.max(0, Math.min(n, W - 1));
22
- r !== G.current && (G.current = r, V(r));
19
+ P && n >= N && (n -= N, e.scrollLeft = n * t);
20
+ let r = Math.max(0, Math.min(n, V - 1));
21
+ r !== H.current && (H.current = r, R(r));
23
22
  }, [
24
- I,
25
- Y,
26
- L,
27
- W,
28
- V
29
- ]), Q = s((e, t) => {
30
- let n = z.current, r = Y();
23
+ N,
24
+ K,
25
+ P,
26
+ V,
27
+ R
28
+ ]), Y = o((e, t) => {
29
+ let n = I.current, r = K();
31
30
  if (!n || r <= 0) return;
32
- X();
31
+ q();
33
32
  let i = n.scrollLeft, a = Math.min(e * r, n.scrollWidth - n.clientWidth), o = typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
34
33
  if (!t || o || Math.abs(a - i) < 1) {
35
- n.scrollLeft = a, Z();
34
+ n.scrollLeft = a, J();
36
35
  return;
37
36
  }
38
- q.current = !0, n.style.scrollSnapType = "none";
37
+ W.current = !0, n.style.scrollSnapType = "none";
39
38
  let s = performance.now(), c = (e) => {
40
- let t = Math.min(1, (e - s) / m);
41
- n.scrollLeft = i + (a - i) * h(t), t < 1 ? K.current = requestAnimationFrame(c) : (q.current = !1, n.style.scrollSnapType = "", Z());
39
+ let t = Math.min(1, (e - s) / p);
40
+ n.scrollLeft = i + (a - i) * m(t), t < 1 ? U.current = requestAnimationFrame(c) : (W.current = !1, n.style.scrollSnapType = "", J());
42
41
  };
43
- K.current = requestAnimationFrame(c);
42
+ U.current = requestAnimationFrame(c);
44
43
  }, [
45
- Y,
46
- Z,
47
- X
48
- ]), $ = s((e, t = {}) => {
49
- let n = z.current, r = Y(), i = e;
50
- if (t.forward && L && n && r > 0) {
44
+ K,
45
+ J,
46
+ q
47
+ ]), X = o((e, t = {}) => {
48
+ let n = I.current, r = K(), i = e;
49
+ if (t.forward && P && n && r > 0) {
51
50
  let e = Math.round(n.scrollLeft / r);
52
- e >= I && (e -= I, n.scrollLeft = e * r), i = e + 1;
51
+ e >= N && (e -= N, n.scrollLeft = e * r), i = e + 1;
53
52
  }
54
- G.current = e, t.silent || V(e), Q(i, t.animate ?? !0);
53
+ H.current = e, t.silent || R(e), Y(i, t.animate ?? !0);
55
54
  }, [
56
- I,
55
+ N,
56
+ K,
57
+ P,
57
58
  Y,
58
- L,
59
- Q,
60
- V
59
+ R
61
60
  ]);
62
- g(() => (G.current > 0 && Q(G.current, !1), () => {
63
- cancelAnimationFrame(K.current), clearTimeout(J.current);
64
- }), []), c(() => {
65
- B !== G.current && $(B, { silent: !0 });
66
- }, [B, $]), c(() => {
67
- let e = z.current;
61
+ h(() => (H.current > 0 && Y(H.current, !1), () => {
62
+ cancelAnimationFrame(U.current), clearTimeout(G.current);
63
+ }), []), s(() => {
64
+ L !== H.current && X(L, { silent: !0 });
65
+ }, [L, X]), s(() => {
66
+ let e = I.current;
68
67
  if (!e) return;
69
68
  let t = () => {
70
- let t = Y();
71
- if (t <= 0) return U(I);
72
- U(Math.ceil((e.scrollWidth - e.clientWidth) / t - .05) + 1);
69
+ let t = K();
70
+ if (t <= 0) return B(N);
71
+ B(Math.ceil((e.scrollWidth - e.clientWidth) / t - .05) + 1);
73
72
  };
74
73
  if (t(), typeof ResizeObserver > "u") return;
75
74
  let n = new ResizeObserver(t);
76
75
  return n.observe(e), () => n.disconnect();
77
76
  }, [
78
- I,
79
- Y,
80
- L
77
+ N,
78
+ K,
79
+ P
81
80
  ]);
82
- let { running: ee, userPaused: te, toggle: ne, interactionProps: re } = r({
83
- enabled: S && W > 1,
84
- paused: w,
85
- delay: C + m,
86
- onTick: () => $((G.current + 1) % W, { forward: !0 }),
87
- rootRef: R,
88
- resetKey: B
89
- }), ie = () => {
90
- if (q.current) return;
91
- let e = z.current, t = Y();
81
+ let { running: Z, interactionProps: Q } = n({
82
+ enabled: x && V > 1,
83
+ paused: C,
84
+ delay: S + p,
85
+ onTick: () => X((H.current + 1) % V, { forward: !0 }),
86
+ rootRef: F,
87
+ resetKey: L
88
+ }), $ = () => {
89
+ if (W.current) return;
90
+ let e = I.current, t = K();
92
91
  if (!e || t <= 0) return;
93
- let n = Math.round(e.scrollLeft / t), r = Math.max(0, Math.min(L ? n % I : n, W - 1));
94
- r !== G.current && (G.current = r, V(r)), clearTimeout(J.current), J.current = setTimeout(Z, 140);
95
- }, { onPointerEnter: ae, onPointerLeave: oe, onFocus: se, onBlur: ce } = re;
96
- return /* @__PURE__ */ p("section", {
92
+ let n = Math.round(e.scrollLeft / t), r = Math.max(0, Math.min(P ? n % N : n, V - 1));
93
+ r !== H.current && (H.current = r, R(r)), clearTimeout(G.current), G.current = setTimeout(J, 140);
94
+ }, { onPointerEnter: ee, onPointerLeave: te, onFocus: ne, onBlur: re } = Q;
95
+ return /* @__PURE__ */ f("section", {
97
96
  ref: (e) => {
98
- R.current = e, typeof P == "function" ? P(e) : P && (P.current = e);
97
+ F.current = e, typeof j == "function" ? j(e) : j && (j.current = e);
99
98
  },
100
- className: e("tm-partner-carousel", M),
99
+ className: e("tm-partner-carousel", k),
101
100
  "aria-roledescription": "carousel",
102
- "data-autoplay": ee ? "running" : S ? "paused" : void 0,
103
- ...N,
101
+ "data-autoplay": Z ? "running" : x ? "paused" : void 0,
102
+ ...A,
104
103
  onPointerEnter: (e) => {
105
- N.onPointerEnter?.(e), ae(e);
104
+ A.onPointerEnter?.(e), ee(e);
106
105
  },
107
106
  onPointerLeave: (e) => {
108
- N.onPointerLeave?.(e), oe();
107
+ A.onPointerLeave?.(e), te();
109
108
  },
110
109
  onFocus: (e) => {
111
- N.onFocus?.(e), se();
110
+ A.onFocus?.(e), ne(e);
112
111
  },
113
112
  onBlur: (e) => {
114
- N.onBlur?.(e), ce(e);
113
+ A.onBlur?.(e), re(e);
115
114
  },
116
- children: [/* @__PURE__ */ f("div", {
117
- ref: z,
115
+ children: [/* @__PURE__ */ d("div", {
116
+ ref: I,
118
117
  className: "tm-partner-carousel__viewport",
119
- onScroll: ie,
120
- onPointerDown: X,
121
- onTouchStart: X,
122
- onWheel: X,
118
+ onScroll: $,
119
+ onPointerDown: q,
120
+ onTouchStart: q,
121
+ onWheel: q,
123
122
  onKeyDown: (e) => {
124
- (e.key.startsWith("Arrow") || e.key === "Home" || e.key === "End") && X();
123
+ (e.key.startsWith("Arrow") || e.key === "Home" || e.key === "End") && q();
125
124
  },
126
- children: /* @__PURE__ */ p("div", {
125
+ children: /* @__PURE__ */ f("div", {
127
126
  className: "tm-partner-carousel__track",
128
- children: [F.map((e, t) => /* @__PURE__ */ f("div", {
127
+ children: [M.map((e, t) => /* @__PURE__ */ d("div", {
129
128
  className: "tm-partner-carousel__slide",
130
129
  role: "group",
131
130
  "aria-roledescription": "slide",
132
- "aria-label": D(t, I),
131
+ "aria-label": E(t, N),
133
132
  children: e
134
- }, t)), L ? F.map((e, t) => /* @__PURE__ */ f("div", {
135
- ref: y,
133
+ }, t)), P ? M.map((e, t) => /* @__PURE__ */ d("div", {
134
+ ref: v,
136
135
  className: "tm-partner-carousel__slide",
137
136
  "data-clone": "",
138
137
  "aria-hidden": "true",
139
138
  children: e
140
139
  }, `clone-${t}`)) : null]
141
140
  })
142
- }), E && W > 1 ? /* @__PURE__ */ p("div", {
141
+ }), T && V > 1 ? /* @__PURE__ */ d("div", {
143
142
  className: "tm-partner-carousel__controls",
144
- children: [/* @__PURE__ */ f(t, {
145
- page: B + 1,
146
- pageCount: W,
147
- onPageChange: (e) => $(e - 1),
148
- getPageLabel: O,
149
- "aria-label": k
150
- }), S ? /* @__PURE__ */ f(n, {
151
- className: "tm-partner-carousel__toggle",
152
- paused: te,
153
- pauseLabel: A,
154
- playLabel: j,
155
- onClick: ne
156
- }) : null]
143
+ children: /* @__PURE__ */ d(t, {
144
+ page: L + 1,
145
+ pageCount: V,
146
+ onPageChange: (e) => X(e - 1),
147
+ getPageLabel: D,
148
+ "aria-label": O
149
+ })
157
150
  }) : null]
158
151
  });
159
152
  });
160
- export { b as PartnerCarousel };
153
+ export { y as PartnerCarousel };
161
154
 
162
155
  //# sourceMappingURL=PartnerCarousel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PartnerCarousel.js","names":["SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","useEffect","useLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","Children","children","looping","loop","rootRef","useRef","viewportRef","setIndex","useIndexState","value","defaultValue","onValueChange","stops","setStops","useState","shown","frame","animating","settleTimer","getStep","useCallback","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","useAutoplay","autoPlay","interval","handleScroll","interactionProps","node","ref","cn","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","Pagination","paginationLabel","AutoplayToggle","userPaused","toggle"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { AutoplayToggle } from './AutoplayToggle';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself. Stops for hover, focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay (the pause control stays available). */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots and, with `autoPlay`, the pause / play button. */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n /** Name of the pause button — translate it. */\n pauseLabel?: string;\n /** Name of the play button — translate it. */\n playLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n pauseLabel = 'Pause the slide show',\n playLabel = 'Play the slide show',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, userPaused, toggle, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus();\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n {autoPlay ? <AutoplayToggle className=\"tm-partner-carousel__toggle\" paused={userPaused} pauseLabel={pauseLabel} playLabel={playLabel} onClick={toggle} /> : null}\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":";;;;;;;;;AAQA,IAAMA,IAAiB,KAEjBC,KAAa,MAAeC,IAAI,KAAM,IAAIA,IAAIA,IAAI,KAAK,KAAKA,IAAI,MAAM,IAAI,GAC1EC,IAA4B,OAAO,SAAW,MAAcC,IAAYC,GAmCxEC,KAAqB,GAAe,MAAkB,GAAGC,IAAQ,EAAE,MAAMC,KACzEC,KAAoB,GAAc,MAAsB,SAASC,EAAK,MAAMC,KAC5EC,KAAY,MAAgCC,GAAS,aAAa,SAAS,EAAE,GAQtEC,IAAkC,kBAA8C,SAC3F,EACE,aACA,UACA,kBAAe,GACf,kBACA,cAAW,IACX,cAAW,KACX,YAAS,IACT,UAAO,IACP,cAAW,IACX,mBAAgBR,GAChB,kBAAeG,GACf,qBAAkB,UAClB,gBAAa,wB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D,EAAcC,GAAGlE,CAAK;KAC7H,UAAAmE;IACE,GAFKD,CAEL,CACN,GAEAvD,IACGH,EAAO,KAAK,GAAO,MACjB,kBAAC,OAAD;KAAwB,KAAKJ;KAAU,WAAU;KAA6B,cAAW;KAAG,eAAY;KACrG,UAAA+D;IACE,GAFK,SAASD,GAEd,CACN,IACD,IACD;;EACF,CAAA,GAEJE,KAAYjE,IAAY,IACvB,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,kBAACkE,GAAD;IAAY,MAAMtE,IAAQ;IAAc;IAAW,eAAe,MAAS8C,EAAK3C,IAAO,CAAC;IAAiB;IAAc,cAAYoE;GAAkB,CAAA,GACpJnB,IAAW,kBAACoB,GAAD;IAAgB,WAAU;IAA8B,QAAQC;IAAwB;IAAuB;IAAW,SAASC;GAAS,CAAA,IAAI,IACzJ;EACH,CAAA,IAAA,IACG;;AAEb,CAAC"}
1
+ {"version":3,"file":"PartnerCarousel.js","names":["SLIDE_DURATION","easeInOut","t","useIsomorphicLayoutEffect","useEffect","useLayoutEffect","defaultSlideLabel","index","count","defaultPageLabel","page","pageCount","setInert","element","PartnerCarousel","props","slides","Children","children","looping","loop","rootRef","useRef","viewportRef","setIndex","useIndexState","value","defaultValue","onValueChange","stops","setStops","useState","shown","frame","animating","settleTimer","getStep","useCallback","items","stopAnimation","settle","viewport","step","position","next","scrollToPosition","from","to","reduced","animate","start","run","now","goTo","options","current","measure","observer","useAutoplay","autoPlay","interval","handleScroll","interactionProps","node","ref","cn","className","running","event","onPointerEnter","onPointerLeave","onFocus","onBlur","getSlideLabel","i","slide","controls","Pagination","paginationLabel"],"sources":["../../../src/components/PartnerCarousel/PartnerCarousel.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { cn } from '../../utils/cn';\nimport { Pagination } from '../Pagination';\nimport { useAutoplay, useIndexState } from './autoplay';\nimport './PartnerCarousel.css';\n\n/** Figma prototype: Smart animate, ease in and out, 700ms. */\nconst SLIDE_DURATION = 700;\n/** CSS `ease-in-out` of the prototype, closely approximated (quadratic) for the scripted scroll. */\nconst easeInOut = (t: number) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\nexport interface PartnerCarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'onChange' | 'defaultValue'> {\n /** The slides: one element per slide, normally `PartnerCard`s. Any number. */\n children?: ReactNode;\n /** Name of the carousel region, e.g. \"Partner agencies\" — translate it. */\n 'aria-label'?: string;\n /** Index (0-based) of the first slide in view — Figma \"Slide\". Makes the carousel controlled. */\n value?: number;\n /** Slide shown first when uncontrolled. */\n defaultValue?: number;\n /** Called with the new index when the carousel moves (swipe, dots or autoplay). */\n onValueChange?: (value: number) => void;\n /** Moves one slide at a time by itself, in an endless loop. Holds for hover, keyboard focus, a hidden tab, an off-screen carousel and reduced motion. */\n autoPlay?: boolean;\n /** Time a slide rests before the next move, in ms (Figma: 3000). */\n interval?: number;\n /** Holds the autoplay from outside; it carries on once this is `false` again. */\n paused?: boolean;\n /** After the last slide the first one follows seamlessly, as in the Figma prototype. Needs more than two slides. */\n loop?: boolean;\n /** Shows the dots. */\n controls?: boolean;\n /** Accessible name of a slide — translate it. */\n getSlideLabel?: (index: number, count: number) => string;\n /** Accessible name of a dot — translate it. */\n getPageLabel?: (page: number, pageCount: number) => string;\n /** Name of the dots navigation — translate it. */\n paginationLabel?: string;\n}\n\nconst defaultSlideLabel = (index: number, count: number) => `${index + 1} of ${count}`;\nconst defaultPageLabel = (page: number, pageCount: number) => `Slide ${page} of ${pageCount}`;\nconst setInert = (element: HTMLElement | null) => element?.setAttribute('inert', '');\n\n/**\n * Carousel of partner cards (Figma component set \"Home / Partner carousel\"): a native scroll-snap track — so touch\n * swipe, trackpad and keyboard scrolling work by themselves — with dots, autoplay and a seamless loop.\n * Two slides per view; containers narrower than 768px show one 300px slide with the next one peeking, like\n * \"Mobile / Home / Partner carousel\".\n */\nexport const PartnerCarousel = /* @__PURE__ */ forwardRef<HTMLElement, PartnerCarouselProps>(function PartnerCarousel(\n {\n children,\n value,\n defaultValue = 0,\n onValueChange,\n autoPlay = true,\n interval = 3000,\n paused = false,\n loop = true,\n controls = true,\n getSlideLabel = defaultSlideLabel,\n getPageLabel = defaultPageLabel,\n paginationLabel = 'Slides',\n className,\n ...props\n },\n ref,\n) {\n const slides = Children.toArray(children);\n const count = slides.length;\n const looping = loop && count > 2;\n\n const rootRef = useRef<HTMLElement | null>(null);\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const [index, setIndex] = useIndexState(value, defaultValue, onValueChange, count);\n // Without the loop the last slides share one view, so there are fewer stops than slides (measured below).\n const [stops, setStops] = useState(count);\n const pageCount = looping ? count : Math.max(1, Math.min(stops, count));\n\n /** The index the track currently shows or is animating to. */\n const shown = useRef(index);\n const frame = useRef(0);\n const animating = useRef(false);\n const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n /** Distance between two neighbouring slides; 0 when there is no layout (tests, hidden). */\n const getStep = useCallback(() => {\n const items = viewportRef.current?.querySelectorAll<HTMLElement>('.tm-partner-carousel__slide');\n if (!items || items.length < 2) return 0;\n return (items[1] as HTMLElement).offsetLeft - (items[0] as HTMLElement).offsetLeft;\n }, []);\n\n const stopAnimation = useCallback(() => {\n if (!animating.current) return;\n cancelAnimationFrame(frame.current);\n animating.current = false;\n if (viewportRef.current) viewportRef.current.style.scrollSnapType = '';\n }, []);\n\n /** After a move: leave the cloned slides for their originals and report where the track rests. */\n const settle = useCallback(() => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0 || animating.current) return;\n let position = Math.round(viewport.scrollLeft / step);\n if (looping && position >= count) {\n position -= count;\n viewport.scrollLeft = position * step;\n }\n const next = Math.max(0, Math.min(position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n }, [count, getStep, looping, pageCount, setIndex]);\n\n /** Scrolls to a track position (slide number, clones included) with the Figma timing. */\n const scrollToPosition = useCallback(\n (position: number, animate: boolean) => {\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n stopAnimation();\n const from = viewport.scrollLeft;\n const to = Math.min(position * step, viewport.scrollWidth - viewport.clientWidth);\n const reduced = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n if (!animate || reduced || Math.abs(to - from) < 1) {\n viewport.scrollLeft = to;\n settle();\n return;\n }\n // Scroll snapping would fight a scripted scroll, so it is switched off for its duration.\n animating.current = true;\n viewport.style.scrollSnapType = 'none';\n const start = performance.now();\n const run = (now: number) => {\n const t = Math.min(1, (now - start) / SLIDE_DURATION);\n viewport.scrollLeft = from + (to - from) * easeInOut(t);\n if (t < 1) {\n frame.current = requestAnimationFrame(run);\n return;\n }\n animating.current = false;\n viewport.style.scrollSnapType = '';\n settle();\n };\n frame.current = requestAnimationFrame(run);\n },\n [getStep, settle, stopAnimation],\n );\n\n /** Shows a slide. `forward` keeps moving right through the clones, so the loop never rewinds. */\n const goTo = useCallback(\n (next: number, options: { forward?: boolean; animate?: boolean; silent?: boolean } = {}) => {\n const viewport = viewportRef.current;\n const step = getStep();\n let position = next;\n if (options.forward && looping && viewport && step > 0) {\n let current = Math.round(viewport.scrollLeft / step);\n if (current >= count) {\n current -= count;\n viewport.scrollLeft = current * step;\n }\n position = current + 1;\n }\n shown.current = next;\n if (!options.silent) setIndex(next);\n scrollToPosition(position, options.animate ?? true);\n },\n [count, getStep, looping, scrollToPosition, setIndex],\n );\n\n // Start at the requested slide without animating.\n useIsomorphicLayoutEffect(() => {\n if (shown.current > 0) scrollToPosition(shown.current, false);\n return () => {\n cancelAnimationFrame(frame.current);\n clearTimeout(settleTimer.current);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // A controlled `value` (or a shrinking list) that differs from what the track shows moves the track.\n useEffect(() => {\n if (index !== shown.current) goTo(index, { silent: true });\n }, [index, goTo]);\n\n // Count the stops of a carousel that does not loop.\n useEffect(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const measure = () => {\n const step = getStep();\n if (step <= 0) return setStops(count);\n setStops(Math.ceil((viewport.scrollWidth - viewport.clientWidth) / step - 0.05) + 1);\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(viewport);\n return () => observer.disconnect();\n }, [count, getStep, looping]);\n\n const { running, interactionProps } = useAutoplay({\n enabled: autoPlay && pageCount > 1,\n paused,\n delay: interval + SLIDE_DURATION,\n onTick: () => goTo((shown.current + 1) % pageCount, { forward: true }),\n rootRef,\n resetKey: index,\n });\n\n const handleScroll = () => {\n if (animating.current) return;\n const viewport = viewportRef.current;\n const step = getStep();\n if (!viewport || step <= 0) return;\n // The dots follow a swipe while it happens…\n const position = Math.round(viewport.scrollLeft / step);\n const next = Math.max(0, Math.min(looping ? position % count : position, pageCount - 1));\n if (next !== shown.current) {\n shown.current = next;\n setIndex(next);\n }\n // …and once it rests the track leaves the clones (`scrollend` is not available everywhere).\n clearTimeout(settleTimer.current);\n settleTimer.current = setTimeout(settle, 140);\n };\n\n const { onPointerEnter, onPointerLeave, onFocus, onBlur } = interactionProps;\n\n return (\n <section\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-partner-carousel', className)}\n aria-roledescription=\"carousel\"\n data-autoplay={running ? 'running' : autoPlay ? 'paused' : undefined}\n {...props}\n onPointerEnter={(event) => {\n props.onPointerEnter?.(event);\n onPointerEnter(event);\n }}\n onPointerLeave={(event) => {\n props.onPointerLeave?.(event);\n onPointerLeave();\n }}\n onFocus={(event) => {\n props.onFocus?.(event);\n onFocus(event);\n }}\n onBlur={(event) => {\n props.onBlur?.(event);\n onBlur(event);\n }}\n >\n <div\n ref={viewportRef}\n className=\"tm-partner-carousel__viewport\"\n onScroll={handleScroll}\n // The user takes over: a scripted move must not fight a swipe, the wheel or the keyboard.\n onPointerDown={stopAnimation}\n onTouchStart={stopAnimation}\n onWheel={stopAnimation}\n onKeyDown={(event) => {\n if (event.key.startsWith('Arrow') || event.key === 'Home' || event.key === 'End') stopAnimation();\n }}\n >\n <div className=\"tm-partner-carousel__track\">\n {slides.map((slide, i) => (\n <div key={i} className=\"tm-partner-carousel__slide\" role=\"group\" aria-roledescription=\"slide\" aria-label={getSlideLabel(i, count)}>\n {slide}\n </div>\n ))}\n {/* Copies of the slides that close the loop; assistive technology and the keyboard skip them. */}\n {looping\n ? slides.map((slide, i) => (\n <div key={`clone-${i}`} ref={setInert} className=\"tm-partner-carousel__slide\" data-clone=\"\" aria-hidden=\"true\">\n {slide}\n </div>\n ))\n : null}\n </div>\n </div>\n\n {controls && pageCount > 1 ? (\n <div className=\"tm-partner-carousel__controls\">\n <Pagination page={index + 1} pageCount={pageCount} onPageChange={(page) => goTo(page - 1)} getPageLabel={getPageLabel} aria-label={paginationLabel} />\n </div>\n ) : null}\n </section>\n );\n});\n"],"mappings":";;;;;;;;AAOA,IAAMA,IAAiB,KAEjBC,KAAa,MAAeC,IAAI,KAAM,IAAIA,IAAIA,IAAI,KAAK,KAAKA,IAAI,MAAM,IAAI,GAC1EC,IAA4B,OAAO,SAAW,MAAcC,IAAYC,GA+BxEC,KAAqB,GAAe,MAAkB,GAAGC,IAAQ,EAAE,MAAMC,KACzEC,KAAoB,GAAc,MAAsB,SAASC,EAAK,MAAMC,KAC5EC,KAAY,MAAgCC,GAAS,aAAa,SAAS,EAAE,GAQtEC,IAAkC,kBAA8C,SAC3F,EACE,aACA,UACA,kBAAe,GACf,kBACA,cAAW,IACX,cAAW,KACX,YAAS,IACT,UAAO,IACP,cAAW,IACX,mBAAgBR,GAChB,kBAAeG,GACf,qBAAkB,UAClB,cACA,GAAGM,KAEL,GACA;CACA,IAAMC,IAASC,EAAS,QAAQC,CAAQ,GAClCV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,MACjB,kBAAC,OAAD;KAAwB,KAAKJ;KAAU,WAAU;KAA6B,cAAW;KAAG,eAAY;KACrG,UAAA+D;IACE,GAFK,SAASD,GAEd,CACN,IACD,IACD;;EACF,CAAA,GAEJE,KAAYjE,IAAY,IACvB,kBAAC,OAAD;GAAK,WAAU;GACb,UAAA,kBAACkE,GAAD;IAAY,MAAMtE,IAAQ;IAAc;IAAW,eAAe,MAAS8C,EAAK3C,IAAO,CAAC;IAAiB;IAAc,cAAYoE;GAAkB,CAAA;EAClJ,CAAA,IACH,IACG;;AAEb,CAAC"}
@@ -1,2 +1,2 @@
1
- "use client";let e=require("react");function t(){let[t,n]=(0,e.useState)(!1);return(0,e.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-reduced-motion: reduce)`),t=()=>n(e.matches);return t(),e.addEventListener?.(`change`,t),()=>e.removeEventListener?.(`change`,t)},[]),t}function n(t){let[n,r]=(0,e.useState)(!0);return(0,e.useEffect)(()=>{let e=t.current;if(!e||typeof IntersectionObserver>`u`)return;let n=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(t.isIntersecting)});return n.observe(e),()=>n.disconnect()},[t]),n}function r(){let[t,n]=(0,e.useState)(!0);return(0,e.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>n(document.visibilityState!==`hidden`);return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),t}function i({enabled:i,paused:a=!1,delay:o,onTick:s,rootRef:c,resetKey:l,ignoreInteraction:u=!1}){let d=t(),f=n(c),p=r(),[m,h]=(0,e.useState)(!1),[g,_]=(0,e.useState)(!1),[v,y]=(0,e.useState)(!1),b=i&&!a&&!v&&!d&&f&&p&&!(!u&&(m||g)),x=(0,e.useRef)(s);return(0,e.useEffect)(()=>{x.current=s}),(0,e.useEffect)(()=>{if(!b)return;let e=setTimeout(()=>x.current(),Math.max(0,o));return()=>clearTimeout(e)},[b,o,l]),{running:b,userPaused:v,toggle:(0,e.useCallback)(()=>y(e=>!e),[]),reducedMotion:d,interactionProps:{onPointerEnter:(0,e.useCallback)(e=>{e.pointerType!==`touch`&&h(!0)},[]),onPointerLeave:(0,e.useCallback)(()=>h(!1),[]),onFocus:(0,e.useCallback)(()=>_(!0),[]),onBlur:(0,e.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||_(!1)},[])}}}function a(t,n,r,i){let[a,o]=(0,e.useState)(n),s=(e=>i>0?Math.max(0,Math.min(Math.round(e),i-1)):0)(t??a),c=(0,e.useRef)(r);return(0,e.useEffect)(()=>{c.current=r}),[s,(0,e.useCallback)(e=>{o(e),c.current?.(e)},[])]}exports.useAutoplay=i,exports.useInView=n,exports.useIndexState=a,exports.usePageVisible=r,exports.usePrefersReducedMotion=t;
1
+ "use client";let e=require("react");function t(){let[t,n]=(0,e.useState)(!1);return(0,e.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-reduced-motion: reduce)`),t=()=>n(e.matches);return t(),e.addEventListener?.(`change`,t),()=>e.removeEventListener?.(`change`,t)},[]),t}function n(t){let[n,r]=(0,e.useState)(!0);return(0,e.useEffect)(()=>{let e=t.current;if(!e||typeof IntersectionObserver>`u`)return;let n=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(t.isIntersecting)});return n.observe(e),()=>n.disconnect()},[t]),n}function r(){let[t,n]=(0,e.useState)(!0);return(0,e.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>n(document.visibilityState!==`hidden`);return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),t}function i({enabled:i,paused:a=!1,delay:o,onTick:s,rootRef:c,resetKey:l,ignoreInteraction:u=!1}){let d=t(),f=n(c),p=r(),[m,h]=(0,e.useState)(!1),[g,_]=(0,e.useState)(!1),v=i&&!a&&!d&&f&&p&&!(!u&&(m||g)),y=(0,e.useRef)(s);return(0,e.useEffect)(()=>{y.current=s}),(0,e.useEffect)(()=>{if(!v)return;let e=setTimeout(()=>y.current(),Math.max(0,o));return()=>clearTimeout(e)},[v,o,l]),{running:v,reducedMotion:d,interactionProps:{onPointerEnter:(0,e.useCallback)(e=>{e.pointerType!==`touch`&&h(!0)},[]),onPointerLeave:(0,e.useCallback)(()=>h(!1),[]),onFocus:(0,e.useCallback)(e=>{let t=!0;try{e&&(t=e.target.matches(`:focus-visible`))}catch{}t&&_(!0)},[]),onBlur:(0,e.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||_(!1)},[])}}}function a(t,n,r,i){let[a,o]=(0,e.useState)(n),s=(e=>i>0?Math.max(0,Math.min(Math.round(e),i-1)):0)(t??a),c=(0,e.useRef)(r);return(0,e.useEffect)(()=>{c.current=r}),[s,(0,e.useCallback)(e=>{o(e),c.current?.(e)},[])]}exports.useAutoplay=i,exports.useInView=n,exports.useIndexState=a,exports.usePageVisible=r,exports.usePrefersReducedMotion=t;
2
2
  //# sourceMappingURL=autoplay.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"autoplay.cjs","names":["useState","useRef","useCallback","react","usePrefersReducedMotion","reduced","setReduced","query","update","useInView","inView","setInView","element","ref","observer","entry","entries","usePageVisible","visible","setVisible","useAutoplay","reducedMotion","rootRef","pageVisible","hovered","setHovered","focused","setFocused","userPaused","setUserPaused","running","enabled","paused","ignoreInteraction","tick","onTick","id","delay","resetKey","value","event","useIndexState","inner","setInner","defaultValue","current","count","n","changed","onValueChange","next"],"sources":["../../../src/components/PartnerCarousel/autoplay.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, type FocusEvent, type PointerEvent, type RefObject } from 'react';\n\n/** `true` while the user asks the system for reduced motion. Starts `false` so server and client markup agree. */\nexport function usePrefersReducedMotion(): boolean {\n const [reduced, setReduced] = useState(false);\n useEffect(() => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n const query = window.matchMedia('(prefers-reduced-motion: reduce)');\n const update = () => setReduced(query.matches);\n update();\n query.addEventListener?.('change', update);\n return () => query.removeEventListener?.('change', update);\n }, []);\n return reduced;\n}\n\n/** `false` while the element is scrolled out of the viewport. Without IntersectionObserver it counts as visible. */\nexport function useInView(ref: RefObject<Element | null>): boolean {\n const [inView, setInView] = useState(true);\n useEffect(() => {\n const element = ref.current;\n if (!element || typeof IntersectionObserver === 'undefined') return;\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setInView(entry.isIntersecting);\n });\n observer.observe(element);\n return () => observer.disconnect();\n }, [ref]);\n return inView;\n}\n\n/** `false` while the browser tab is hidden. */\nexport function usePageVisible(): boolean {\n const [visible, setVisible] = useState(true);\n useEffect(() => {\n if (typeof document === 'undefined') return;\n const update = () => setVisible(document.visibilityState !== 'hidden');\n update();\n document.addEventListener('visibilitychange', update);\n return () => document.removeEventListener('visibilitychange', update);\n }, []);\n return visible;\n}\n\nexport interface UseAutoplayOptions {\n /** The component's `autoPlay` prop. */\n enabled: boolean;\n /** The component's `paused` prop. */\n paused?: boolean;\n /** Milliseconds between two ticks. */\n delay: number;\n /** Moves to the next state. */\n onTick: () => void;\n /** Root element: the loop stops while it is off-screen. */\n rootRef: RefObject<Element | null>;\n /** Restarts the countdown whenever it changes (pass the current step). */\n resetKey?: unknown;\n /** Keep running while the pointer is over the component or focus is inside it (decorative animations only). */\n ignoreInteraction?: boolean;\n}\n\nexport interface UseAutoplayResult {\n /** The loop is ticking right now. */\n running: boolean;\n /** The user stopped the loop with the pause control. */\n userPaused: boolean;\n /** Handler for the pause / play control. */\n toggle: () => void;\n /** The user asked for reduced motion: nothing plays by itself. */\n reducedMotion: boolean;\n /** Spread on the root: pauses while a mouse hovers it or focus is inside. */\n interactionProps: {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => void;\n onPointerLeave: () => void;\n onFocus: () => void;\n onBlur: (event: FocusEvent<HTMLElement>) => void;\n };\n}\n\n/**\n * Shared autoplay loop of the animated components: ticks every `delay` ms, and stops for reduced motion, a hidden tab,\n * an off-screen root, a hovering mouse, focus inside the root, the `paused` prop and the user's pause control.\n */\nexport function useAutoplay({ enabled, paused = false, delay, onTick, rootRef, resetKey, ignoreInteraction = false }: UseAutoplayOptions): UseAutoplayResult {\n const reducedMotion = usePrefersReducedMotion();\n const inView = useInView(rootRef);\n const pageVisible = usePageVisible();\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const [userPaused, setUserPaused] = useState(false);\n\n const interacting = !ignoreInteraction && (hovered || focused);\n const running = enabled && !paused && !userPaused && !reducedMotion && inView && pageVisible && !interacting;\n\n const tick = useRef(onTick);\n useEffect(() => {\n tick.current = onTick;\n });\n\n useEffect(() => {\n if (!running) return;\n const id = setTimeout(() => tick.current(), Math.max(0, delay));\n return () => clearTimeout(id);\n }, [running, delay, resetKey]);\n\n const toggle = useCallback(() => setUserPaused((value) => !value), []);\n const onPointerEnter = useCallback((event: PointerEvent<HTMLElement>) => {\n // Touch has no hover: a tap must not leave the loop paused.\n if (event.pointerType !== 'touch') setHovered(true);\n }, []);\n const onPointerLeave = useCallback(() => setHovered(false), []);\n const onFocus = useCallback(() => setFocused(true), []);\n const onBlur = useCallback((event: FocusEvent<HTMLElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setFocused(false);\n }, []);\n\n return { running, userPaused, toggle, reducedMotion, interactionProps: { onPointerEnter, onPointerLeave, onFocus, onBlur } };\n}\n\n/** Controlled / uncontrolled 0-based index, kept inside `0 … count - 1`. */\nexport function useIndexState(value: number | undefined, defaultValue: number, onValueChange: ((value: number) => void) | undefined, count: number) {\n const [inner, setInner] = useState(defaultValue);\n const clamp = (n: number) => (count > 0 ? Math.max(0, Math.min(Math.round(n), count - 1)) : 0);\n const current = clamp(value ?? inner);\n const changed = useRef(onValueChange);\n useEffect(() => {\n changed.current = onValueChange;\n });\n const set = useCallback(\n (next: number) => {\n setInner(next);\n changed.current?.(next);\n },\n [],\n );\n return [current, set] as const;\n}\n"],"mappings":"A,oCAGA,SA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AGA,SAAgBc,EAAc,EAA2B,EAAsB,EAAsD,EAAe,CAClJ,GAAM,CAACC,EAAOC,IAAA,EAAY3C,EAAAA,SAAAA,CAAS4C,CAAY,EAEzCC,GADS,GAAeC,EAAQ,EAAI,KAAK,IAAI,EAAG,KAAK,IAAI,KAAK,MAAMC,CAAC,EAAGD,EAAQ,CAAC,CAAC,EAAI,EAC5E,CAAMP,GAASG,CAAK,EAC9BM,GAAA,EAAU/C,EAAAA,OAAAA,CAAOgD,CAAa,EAWpC,OAVA,EAAA9C,EAAA,UAAA,KAAgB,CACd,EAAQ,QAAU8C,CACpB,CAAC,EAQM,CAACJ,GAAA,EAPI3C,EAAAA,YAAAA,CACT,GAAiB,CAChByC,EAASO,CAAI,EACbF,EAAQ,UAAUE,CAAI,CACxB,EACA,CAAC,CAEc,CAAG,CACtB,C"}
1
+ {"version":3,"file":"autoplay.cjs","names":["useState","useRef","useCallback","react","usePrefersReducedMotion","reduced","setReduced","query","update","useInView","inView","setInView","element","ref","observer","entry","entries","usePageVisible","visible","setVisible","useAutoplay","reducedMotion","rootRef","pageVisible","hovered","setHovered","focused","setFocused","running","enabled","paused","ignoreInteraction","tick","onTick","id","delay","resetKey","event","keyboard","useIndexState","inner","setInner","defaultValue","current","count","n","value","changed","onValueChange","next"],"sources":["../../../src/components/PartnerCarousel/autoplay.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, type FocusEvent, type PointerEvent, type RefObject } from 'react';\n\n/** `true` while the user asks the system for reduced motion. Starts `false` so server and client markup agree. */\nexport function usePrefersReducedMotion(): boolean {\n const [reduced, setReduced] = useState(false);\n useEffect(() => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n const query = window.matchMedia('(prefers-reduced-motion: reduce)');\n const update = () => setReduced(query.matches);\n update();\n query.addEventListener?.('change', update);\n return () => query.removeEventListener?.('change', update);\n }, []);\n return reduced;\n}\n\n/** `false` while the element is scrolled out of the viewport. Without IntersectionObserver it counts as visible. */\nexport function useInView(ref: RefObject<Element | null>): boolean {\n const [inView, setInView] = useState(true);\n useEffect(() => {\n const element = ref.current;\n if (!element || typeof IntersectionObserver === 'undefined') return;\n const observer = new IntersectionObserver((entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setInView(entry.isIntersecting);\n });\n observer.observe(element);\n return () => observer.disconnect();\n }, [ref]);\n return inView;\n}\n\n/** `false` while the browser tab is hidden. */\nexport function usePageVisible(): boolean {\n const [visible, setVisible] = useState(true);\n useEffect(() => {\n if (typeof document === 'undefined') return;\n const update = () => setVisible(document.visibilityState !== 'hidden');\n update();\n document.addEventListener('visibilitychange', update);\n return () => document.removeEventListener('visibilitychange', update);\n }, []);\n return visible;\n}\n\nexport interface UseAutoplayOptions {\n /** The component's `autoPlay` prop. */\n enabled: boolean;\n /** The component's `paused` prop. */\n paused?: boolean;\n /** Milliseconds between two ticks. */\n delay: number;\n /** Moves to the next state. */\n onTick: () => void;\n /** Root element: the loop stops while it is off-screen. */\n rootRef: RefObject<Element | null>;\n /** Restarts the countdown whenever it changes (pass the current step). */\n resetKey?: unknown;\n /** Keep running while the pointer is over the component or focus is inside it (decorative animations only). */\n ignoreInteraction?: boolean;\n}\n\nexport interface UseAutoplayResult {\n /** The loop is ticking right now. */\n running: boolean;\n /** The user asked for reduced motion: nothing plays by itself. */\n reducedMotion: boolean;\n /**\n * Spread on the root: holds the loop while a mouse hovers it or keyboard focus is inside. Pass the focus event to\n * `onFocus`: focus left behind by a click or a tap then does not hold the loop (without the event every focus does).\n */\n interactionProps: {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => void;\n onPointerLeave: () => void;\n onFocus: (event?: FocusEvent<HTMLElement>) => void;\n onBlur: (event: FocusEvent<HTMLElement>) => void;\n };\n}\n\n/**\n * Shared autoplay loop of the animated components: ticks every `delay` ms, forever. It holds for reduced motion, a\n * hidden tab, an off-screen root, a hovering mouse, keyboard focus inside the root and the `paused` prop, and carries\n * on by itself as soon as none of them applies — there is no pause control and nothing the user does ends the loop.\n */\nexport function useAutoplay({ enabled, paused = false, delay, onTick, rootRef, resetKey, ignoreInteraction = false }: UseAutoplayOptions): UseAutoplayResult {\n const reducedMotion = usePrefersReducedMotion();\n const inView = useInView(rootRef);\n const pageVisible = usePageVisible();\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n\n const interacting = !ignoreInteraction && (hovered || focused);\n const running = enabled && !paused && !reducedMotion && inView && pageVisible && !interacting;\n\n const tick = useRef(onTick);\n useEffect(() => {\n tick.current = onTick;\n });\n\n useEffect(() => {\n if (!running) return;\n const id = setTimeout(() => tick.current(), Math.max(0, delay));\n return () => clearTimeout(id);\n }, [running, delay, resetKey]);\n\n const onPointerEnter = useCallback((event: PointerEvent<HTMLElement>) => {\n // Touch has no hover: a tap must not leave the loop paused.\n if (event.pointerType !== 'touch') setHovered(true);\n }, []);\n const onPointerLeave = useCallback(() => setHovered(false), []);\n const onFocus = useCallback((event?: FocusEvent<HTMLElement>) => {\n // Keyboard focus only: the focus a click or a tap leaves on a dot or a card must not hold the loop until the next blur.\n let keyboard = true;\n try {\n if (event) keyboard = event.target.matches(':focus-visible');\n } catch {\n /* :focus-visible unsupported — treat every focus as keyboard focus */\n }\n if (keyboard) setFocused(true);\n }, []);\n const onBlur = useCallback((event: FocusEvent<HTMLElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setFocused(false);\n }, []);\n\n return { running, reducedMotion, interactionProps: { onPointerEnter, onPointerLeave, onFocus, onBlur } };\n}\n\n/** Controlled / uncontrolled 0-based index, kept inside `0 … count - 1`. */\nexport function useIndexState(value: number | undefined, defaultValue: number, onValueChange: ((value: number) => void) | undefined, count: number) {\n const [inner, setInner] = useState(defaultValue);\n const clamp = (n: number) => (count > 0 ? Math.max(0, Math.min(Math.round(n), count - 1)) : 0);\n const current = clamp(value ?? inner);\n const changed = useRef(onValueChange);\n useEffect(() => {\n changed.current = onValueChange;\n });\n const set = useCallback(\n (next: number) => {\n setInner(next);\n changed.current?.(next);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AAE,CACzG,CAGA,SAAgBY,EAAc,EAA2B,EAAsB,EAAsD,EAAe,CAClJ,GAAM,CAACC,EAAOC,IAAA,EAAYzC,EAAAA,SAAAA,CAAS0C,CAAY,EAEzCC,GADS,GAAeC,EAAQ,EAAI,KAAK,IAAI,EAAG,KAAK,IAAI,KAAK,MAAMC,CAAC,EAAGD,EAAQ,CAAC,CAAC,EAAI,EAC5E,CAAME,GAASN,CAAK,EAC9BO,GAAA,EAAU9C,EAAAA,OAAAA,CAAO+C,CAAa,EAWpC,OAVA,EAAA7C,EAAA,UAAA,KAAgB,CACd,EAAQ,QAAU6C,CACpB,CAAC,EAQM,CAACL,GAAA,EAPIzC,EAAAA,YAAAA,CACT,GAAiB,CAChBuC,EAASQ,CAAI,EACbF,EAAQ,UAAUE,CAAI,CACxB,EACA,CAAC,CAEc,CAAG,CACtB,C"}
@@ -30,28 +30,32 @@ function o() {
30
30
  }, []), e;
31
31
  }
32
32
  function s({ enabled: s, paused: c = !1, delay: l, onTick: u, rootRef: d, resetKey: f, ignoreInteraction: p = !1 }) {
33
- let m = i(), h = a(d), g = o(), [_, v] = r(!1), [y, b] = r(!1), [x, S] = r(!1), C = s && !c && !x && !m && h && g && !(!p && (_ || y)), w = n(u);
33
+ let m = i(), h = a(d), g = o(), [_, v] = r(!1), [y, b] = r(!1), x = s && !c && !m && h && g && !(!p && (_ || y)), S = n(u);
34
34
  return t(() => {
35
- w.current = u;
35
+ S.current = u;
36
36
  }), t(() => {
37
- if (!C) return;
38
- let e = setTimeout(() => w.current(), Math.max(0, l));
37
+ if (!x) return;
38
+ let e = setTimeout(() => S.current(), Math.max(0, l));
39
39
  return () => clearTimeout(e);
40
40
  }, [
41
- C,
41
+ x,
42
42
  l,
43
43
  f
44
44
  ]), {
45
- running: C,
46
- userPaused: x,
47
- toggle: e(() => S((e) => !e), []),
45
+ running: x,
48
46
  reducedMotion: m,
49
47
  interactionProps: {
50
48
  onPointerEnter: e((e) => {
51
49
  e.pointerType !== "touch" && v(!0);
52
50
  }, []),
53
51
  onPointerLeave: e(() => v(!1), []),
54
- onFocus: e(() => b(!0), []),
52
+ onFocus: e((e) => {
53
+ let t = !0;
54
+ try {
55
+ e && (t = e.target.matches(":focus-visible"));
56
+ } catch {}
57
+ t && b(!0);
58
+ }, []),
55
59
  onBlur: e((e) => {
56
60
  e.currentTarget.contains(e.relatedTarget) || b(!1);
57
61
  }, [])