@tedi-design-system/react 19.2.0-rc.5 → 19.2.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle-stats.html +1 -1
- package/package.json +1 -1
- package/src/tedi/components/content/carousel/components/carousel-indicators/carousel-indicators.cjs.js +1 -1
- package/src/tedi/components/content/carousel/components/carousel-indicators/carousel-indicators.es.js +18 -18
- package/src/tedi/components/content/carousel/use-carousel.cjs.js +1 -1
- package/src/tedi/components/content/carousel/use-carousel.d.ts +2 -1
- package/src/tedi/components/content/carousel/use-carousel.es.js +177 -163
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tedi-design-system/react",
|
|
3
|
-
"version": "19.2.0-rc.
|
|
3
|
+
"version": "19.2.0-rc.6",
|
|
4
4
|
"description": "TEDI Design System React component library — accessible, reusable UI components. Docs & live examples: https://storybook.tedi.ee/react/rc/",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("../../../../../../../external/classnames/index.cjs.js"),v=require("react"),i=require("../../../../base/typography/text/text.cjs.js"),u=require("../../../../buttons/button/button.cjs.js"),l=require("../../carousel.module.scss.cjs.js"),p=require("../../carousel-context.cjs.js"),j=require("../../../../../providers/label-provider/use-labels.cjs.js"),d=v.forwardRef(({withArrows:n=!1,variant:b="dots",className:x},f)=>{const{getLabel:r}=j.useLabels(),t=p.useCarouselContext(),{positions:s,activePositionIndex:a}=t;return e.jsxs("div",{ref:f,className:c.default(l.default["tedi-carousel__indicators"],x),children:[n&&e.jsx(u.Button,{visualType:"neutral",icon:"arrow_back",disabled:!t.canPrev,onClick:t.prev,children:r("carousel.move-back")}),b==="dots"?s.map((m,o)=>e.jsx("button",{type:"button","aria-label":r("carousel.show-slide",o+1),"aria-current":o===a?"true":void 0,className:c.default(l.default["tedi-carousel__indicator"],{[l.default["tedi-carousel__indicator--active"]]:o===a}),onClick:()=>t.goToIndex(m,{focusSlide:!0})},o)):s.length>0&&e.jsxs("div",{children:[e.jsx(i.Text,{element:"span",modifiers:"bold",color:"brand",children:a+1}),e.jsx(i.Text,{element:"span",color:"tertiary",children:` / ${s.length}`})]}),n&&e.jsx(u.Button,{visualType:"neutral",icon:"arrow_forward",disabled:!t.canNext,onClick:t.next,children:r("carousel.move-forward")})]})});d.displayName="CarouselIndicators";exports.CarouselIndicators=d;
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { jsxs as c, jsx as e } from "react/jsx-runtime";
|
|
2
2
|
import n from "../../../../../../../external/classnames/index.es.js";
|
|
3
|
-
import { forwardRef as
|
|
3
|
+
import { forwardRef as v } from "react";
|
|
4
4
|
import { Text as d } from "../../../../base/typography/text/text.es.js";
|
|
5
5
|
import { Button as m } from "../../../../buttons/button/button.es.js";
|
|
6
|
-
import
|
|
7
|
-
import { useCarouselContext as
|
|
6
|
+
import i from "../../carousel.module.scss.es.js";
|
|
7
|
+
import { useCarouselContext as h } from "../../carousel-context.es.js";
|
|
8
8
|
import { useLabels as _ } from "../../../../../providers/label-provider/use-labels.es.js";
|
|
9
|
-
const C =
|
|
10
|
-
({ withArrows:
|
|
11
|
-
const { getLabel: a } = _(),
|
|
12
|
-
return /* @__PURE__ */ c("div", { ref:
|
|
13
|
-
|
|
14
|
-
u === "dots" ?
|
|
9
|
+
const C = v(
|
|
10
|
+
({ withArrows: l = !1, variant: u = "dots", className: p }, f) => {
|
|
11
|
+
const { getLabel: a } = _(), o = h(), { positions: t, activePositionIndex: s } = o;
|
|
12
|
+
return /* @__PURE__ */ c("div", { ref: f, className: n(i["tedi-carousel__indicators"], p), children: [
|
|
13
|
+
l && /* @__PURE__ */ e(m, { visualType: "neutral", icon: "arrow_back", disabled: !o.canPrev, onClick: o.prev, children: a("carousel.move-back") }),
|
|
14
|
+
u === "dots" ? t.map((b, r) => /* @__PURE__ */ e(
|
|
15
15
|
"button",
|
|
16
16
|
{
|
|
17
17
|
type: "button",
|
|
18
|
-
"aria-label": a("carousel.show-slide",
|
|
19
|
-
"aria-current":
|
|
20
|
-
className: n(
|
|
21
|
-
[
|
|
18
|
+
"aria-label": a("carousel.show-slide", r + 1),
|
|
19
|
+
"aria-current": r === s ? "true" : void 0,
|
|
20
|
+
className: n(i["tedi-carousel__indicator"], {
|
|
21
|
+
[i["tedi-carousel__indicator--active"]]: r === s
|
|
22
22
|
}),
|
|
23
|
-
onClick: () =>
|
|
23
|
+
onClick: () => o.goToIndex(b, { focusSlide: !0 })
|
|
24
24
|
},
|
|
25
|
-
|
|
26
|
-
)) : t > 0 && /* @__PURE__ */ c("div", { children: [
|
|
25
|
+
r
|
|
26
|
+
)) : t.length > 0 && /* @__PURE__ */ c("div", { children: [
|
|
27
27
|
/* @__PURE__ */ e(d, { element: "span", modifiers: "bold", color: "brand", children: s + 1 }),
|
|
28
|
-
/* @__PURE__ */ e(d, { element: "span", color: "tertiary", children: ` / ${t}` })
|
|
28
|
+
/* @__PURE__ */ e(d, { element: "span", color: "tertiary", children: ` / ${t.length}` })
|
|
29
29
|
] }),
|
|
30
|
-
|
|
30
|
+
l && /* @__PURE__ */ e(m, { visualType: "neutral", icon: "arrow_forward", disabled: !o.canNext, onClick: o.next, children: a("carousel.move-forward") })
|
|
31
31
|
] });
|
|
32
32
|
}
|
|
33
33
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),Ne=require("../../../helpers/hooks/use-breakpoint.cjs.js"),le=require("./carousel-utils.cjs.js"),_e=require("../../../providers/label-provider/use-labels.cjs.js"),ve={slidesPerView:{xs:1},gap:{xs:1},fade:!1,transitionMs:400,loop:!0,centered:!1},Fe=.3,Ve=1e-6,F=(S,b)=>(S%b+b)%b,Q=(S,b)=>S.reduce((I,d,$)=>Math.abs(d-b)<Math.abs(S[I]-b)?$:I,0),Xe=S=>{const{getLabel:b}=_e.useLabels(),I=Ne.default(),[d,$]=t.useState(ve),[s,fe]=t.useState(0),[m,C]=t.useState(0),[R,Z]=t.useState(0),[ee,x]=t.useState(!1),[E,de]=t.useState(0),[te,me]=t.useState(16),[he,Me]=t.useState(""),V=t.useRef(null),re=t.useRef(null),ne=t.useRef([]),L=t.useRef(!1),N=t.useRef(!1),G=t.useRef(!1),U=t.useRef(0),X=t.useRef(0),se=t.useRef(0),q=t.useRef(0),H=t.useRef(0),W=t.useRef(),_=t.useRef(0),ce=t.useRef(!0),h=t.useRef(m),oe=t.useRef(R);t.useEffect(()=>{h.current=m},[m]),t.useEffect(()=>{oe.current=R},[R]);const l=t.useMemo(()=>le.resolveBreakpointValue(d.slidesPerView,I),[d.slidesPerView,I]),T=t.useMemo(()=>le.resolveBreakpointValue(d.gap,I),[d.gap,I]),D=t.useMemo(()=>T*te,[T,te]),r=d.loop,u=t.useMemo(()=>{const e=Math.max(0,s-l),n=Math.round(e);return Math.abs(e-n)<Ve?n:e},[s,l]),f=t.useMemo(()=>{if(!s)return[];if(r)return Array.from({length:s},(c,o)=>o);const e=Math.floor(u),n=Array.from({length:e+1},(c,o)=>o);return u>e&&n.push(u),n},[s,r,u]),P=t.useCallback(e=>r?e:Math.min(Math.max(e,0),u),[r,u]),p=r?s:0,pe=t.useMemo(()=>f.length?r?F(Math.floor(m),s):Q(f,m):0,[f,m,s,r]),O=r?m-R+p:Math.ceil(m),be=s>0&&(r||m>0),Re=s>0&&(r||m<u);t.useLayoutEffect(()=>{r||(clearTimeout(W.current),_.current=0,h.current=P(h.current),C(e=>P(e)))},[r,u,P]);const ge=t.useMemo(()=>{if(!s)return[];if(!r)return Array.from({length:s},(c,o)=>o);const e=2*p+Math.ceil(l),n=R-p;return Array.from({length:e},(c,o)=>F(n+o,s))},[s,p,l,R,r]),Ce=t.useMemo(()=>`0 0 calc((100% - ${(l-1)*T}rem) / ${l})`,[l,T]),ke=t.useMemo(()=>{if(!E)return{gap:`${T}rem`,transform:"translate3d(0,0,0)",transition:"none"};const e=D*(l-1),n=(E-e)/l,c=r?m-R+p:m,o=d.centered?(E-n)/2:0,i=-c*(n+D)+o;return{gap:`${T}rem`,transform:`translate3d(${i}px, 0, 0)`,transition:ee?`transform ${d.transitionMs}ms ease`:"none"}},[E,T,D,l,m,R,p,ee,d.transitionMs,d.centered,r]),Se=t.useCallback(e=>{if(!r)return e+1>m&&e<m+l;const n=Math.ceil(l);return e>=O&&e<O+n},[l,O,r,m]),xe=t.useCallback((e,n,c)=>{const o=[e];if(d.fade){const i=d.fade==="both"||d.fade!=="right"&&l<=1;o.push(i?c:n)}return o.join(" ")},[d.fade,l]),we=t.useCallback((e,n)=>{ne.current[e]=n},[]),y=t.useCallback(()=>{setTimeout(()=>{if(!ce.current||!s)return;const e=r?F(Math.floor(h.current),s):Math.min(Math.max(Math.ceil(h.current),0),s-1);Me(b("carousel.slide",e+1,s))},100)},[b,s,r]),z=t.useCallback(()=>{L.current=!0,setTimeout(()=>{L.current=!1},d.transitionMs)},[d.transitionMs]),ae=t.useCallback(()=>{setTimeout(()=>{var n;const e=r?h.current-oe.current+p:Math.ceil(h.current);(n=ne.current[e])==null||n.focus({preventScroll:!0})})},[p,r]),K=t.useCallback(()=>{!s||L.current||!r&&h.current>=u||(x(!0),C(e=>r?e+1:f.find(n=>n>e)??u),z(),y())},[s,r,u,f,z,y]),Y=t.useCallback(()=>{!s||L.current||!r&&h.current<=0||(x(!0),C(e=>r?e-1:[...f].reverse().find(n=>n<e)??0),z(),y())},[s,r,f,z,y]),B=t.useCallback((e,n)=>{if(!(!s||L.current)){if(x(!0),r){const c=F(Math.floor(h.current),s),i=F(e,s)-c;C(a=>a+i)}else C(P(e));n!=null&&n.focusSlide?G.current=!0:y()}},[s,r,P,y]),Ie=t.useCallback(e=>{e.target!==re.current||e.propertyName!=="transform"||N.current||(x(!1),Z(Math.floor(h.current)),G.current&&(G.current=!1,ae()))},[ae]),Te=t.useCallback(()=>{const e=V.current;e&&(e.scrollLeft=0,e.scrollTop=0)},[]),A=t.useCallback(()=>(E-D*(l-1))/l+D,[E,D,l]),Pe=t.useCallback(e=>{if(!s)return;const n=Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:e.shiftKey?e.deltaY:0;if(!n)return;const c=A();if(!c)return;const o=n/c;_.current+=o;const i=p*.9,a=r?R-i:0,M=r?R+i:u,v=h.current+o,w=Math.min(Math.max(v,a),M),j=w!==v;x(!1),C(w),clearTimeout(W.current),W.current=setTimeout(()=>{x(!0);const ue=Math.sign(_.current),ie=Math.abs(_.current)>Fe,g=h.current;let k;r?(k=Math.round(g),ie&&(k=ue>0?Math.ceil(g):Math.floor(g)),j&&(g<=a&&(k=Math.ceil(a)),g>=M&&(k=Math.floor(M)))):j&&g>=M?k=M:j&&g<=a?k=a:ie?k=ue>0?f.find(J=>J>=g)??M:[...f].reverse().find(J=>J<=g)??a:k=f[Q(f,g)];const Le=Math.min(Math.max(k,a),M);C(Le),_.current=0},120)},[s,A,p,R,r,u,f]),Ee=t.useCallback(e=>{switch(e.key){case"ArrowRight":case"PageDown":e.preventDefault(),K();break;case"ArrowLeft":case"PageUp":e.preventDefault(),Y();break;case"Home":e.preventDefault(),B(0);break;case"End":e.preventDefault(),B(r?s-1:u);break}},[K,Y,B,s,r,u]),De=t.useCallback(e=>{var n;s&&((n=V.current)==null||n.setPointerCapture(e.pointerId),N.current=!0,x(!1),U.current=e.clientX,X.current=h.current,se.current=e.timeStamp,q.current=e.clientX,H.current=e.timeStamp,r&&Z(Math.floor(h.current)))},[s,r]),ye=t.useCallback(e=>{if(!N.current)return;const n=A();if(!n)return;const c=e.clientX-U.current;if(Number.isNaN(c))return;q.current=e.clientX,H.current=e.timeStamp;const o=c/n,i=X.current-o,a=p*.9,M=Math.floor(X.current),v=r?M-a:0,w=r?M+a:u;C(Math.min(Math.max(i,v),w))},[A,p,r,u]),Ae=t.useCallback(()=>{if(!N.current)return;N.current=!1,x(!0);const e=A(),n=h.current,c=X.current,o=r?Math.round(c):c;let i=r?Math.round(n):f[Q(f,n)];const a=H.current-se.current,M=a>0&&e?-(q.current-U.current)/e/a:0;Math.abs(M)>.0015&&i===o&&(r?i=o+Math.sign(M):M>0?i=f.find(w=>w>c)??u:i=[...f].reverse().find(w=>w<c)??0),C(P(i))},[A,P,r,f,u]);return t.useEffect(()=>{const e=V.current;if(!e)return;const n=a=>{de(a),me(parseFloat(getComputedStyle(document.documentElement).fontSize)||16)},c=getComputedStyle(e),o=(parseFloat(c.paddingLeft)||0)+(parseFloat(c.paddingRight)||0);n(e.clientWidth-o);const i=new ResizeObserver(([a])=>{a&&n(a.contentRect.width)});return i.observe(e),()=>i.disconnect()},[]),t.useEffect(()=>()=>{ce.current=!1,clearTimeout(W.current)},[]),{viewportRef:V,trackRef:re,setSlideRef:we,setConfig:$,setSlidesCount:fe,slidesCount:s,positions:f,activePositionIndex:pe,canPrev:be,canNext:Re,renderedIndices:ge,renderedActiveIndex:O,slideFlex:Ce,trackStyle:ke,contentClassName:xe,isSlideVisible:Se,announcement:he,regionLabel:(S==null?void 0:S.trim())||b("carousel"),slideLabel:e=>b("carousel.slide",e,s),next:K,prev:Y,goToIndex:B,onTransitionEnd:Ie,onScroll:Te,onWheel:Pe,onKeyDown:Ee,onPointerDown:De,onPointerMove:ye,onPointerUp:Ae}};exports.useCarousel=Xe;
|
|
@@ -23,7 +23,8 @@ export interface CarouselApi {
|
|
|
23
23
|
setConfig: (config: CarouselConfig) => void;
|
|
24
24
|
setSlidesCount: (count: number) => void;
|
|
25
25
|
slidesCount: number;
|
|
26
|
-
|
|
26
|
+
positions: number[];
|
|
27
|
+
activePositionIndex: number;
|
|
27
28
|
canPrev: boolean;
|
|
28
29
|
canNext: boolean;
|
|
29
30
|
renderedIndices: number[];
|
|
@@ -1,230 +1,244 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import
|
|
3
|
-
import { resolveBreakpointValue as
|
|
4
|
-
import { useLabels as
|
|
5
|
-
const
|
|
1
|
+
import { useState as k, useRef as p, useEffect as K, useMemo as b, useCallback as f, useLayoutEffect as Vt } from "react";
|
|
2
|
+
import Wt from "../../../helpers/hooks/use-breakpoint.es.js";
|
|
3
|
+
import { resolveBreakpointValue as ht } from "./carousel-utils.es.js";
|
|
4
|
+
import { useLabels as vt } from "../../../providers/label-provider/use-labels.es.js";
|
|
5
|
+
const Ot = {
|
|
6
6
|
slidesPerView: { xs: 1 },
|
|
7
7
|
gap: { xs: 1 },
|
|
8
8
|
fade: !1,
|
|
9
9
|
transitionMs: 400,
|
|
10
10
|
loop: !0,
|
|
11
11
|
centered: !1
|
|
12
|
-
},
|
|
13
|
-
|
|
12
|
+
}, zt = 0.3, $t = 1e-6, v = (T, x) => (T % x + x) % x, rt = (T, x) => T.reduce(
|
|
13
|
+
(D, d, U) => Math.abs(d - x) < Math.abs(T[D] - x) ? U : D,
|
|
14
|
+
0
|
|
15
|
+
), Ut = (T) => {
|
|
16
|
+
const { getLabel: x } = vt(), D = Wt(), [d, U] = k(Ot), [n, pt] = k(0), [m, R] = k(0), [w, nt] = k(0), [st, C] = k(!1), [N, Mt] = k(0), [ot, gt] = k(16), [xt, wt] = k(""), O = p(null), ct = p(null), at = p([]), F = p(!1), X = p(!1), Y = p(!1), j = p(0), z = p(0), it = p(0), q = p(0), J = p(0), $ = p(), V = p(0), ut = p(!0), h = p(m), lt = p(w);
|
|
14
17
|
K(() => {
|
|
15
|
-
|
|
16
|
-
}, [
|
|
17
|
-
|
|
18
|
-
}, [
|
|
19
|
-
const
|
|
20
|
-
() =>
|
|
21
|
-
[
|
|
22
|
-
),
|
|
23
|
-
|
|
18
|
+
h.current = m;
|
|
19
|
+
}, [m]), K(() => {
|
|
20
|
+
lt.current = w;
|
|
21
|
+
}, [w]);
|
|
22
|
+
const u = b(
|
|
23
|
+
() => ht(d.slidesPerView, D),
|
|
24
|
+
[d.slidesPerView, D]
|
|
25
|
+
), A = b(() => ht(d.gap, D), [d.gap, D]), y = b(() => A * ot, [A, ot]), e = d.loop, a = b(() => {
|
|
26
|
+
const t = Math.max(0, n - u), r = Math.round(t);
|
|
27
|
+
return Math.abs(t - r) < $t ? r : t;
|
|
28
|
+
}, [n, u]), l = b(() => {
|
|
29
|
+
if (!n) return [];
|
|
30
|
+
if (e) return Array.from({ length: n }, (s, o) => o);
|
|
31
|
+
const t = Math.floor(a), r = Array.from({ length: t + 1 }, (s, o) => o);
|
|
32
|
+
return a > t && r.push(a), r;
|
|
33
|
+
}, [n, e, a]), E = f(
|
|
34
|
+
(t) => e ? t : Math.min(Math.max(t, 0), a),
|
|
24
35
|
[e, a]
|
|
25
|
-
),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!n) return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
), g = e ? n : 0, It = b(() => l.length ? e ? v(Math.floor(m), n) : rt(l, m) : 0, [l, m, n, e]), B = e ? m - w + g : Math.ceil(m), Rt = n > 0 && (e || m > 0), St = n > 0 && (e || m < a);
|
|
37
|
+
Vt(() => {
|
|
38
|
+
e || (clearTimeout($.current), V.current = 0, h.current = E(h.current), R((t) => E(t)));
|
|
39
|
+
}, [e, a, E]);
|
|
40
|
+
const bt = b(() => {
|
|
41
|
+
if (!n) return [];
|
|
42
|
+
if (!e) return Array.from({ length: n }, (s, o) => o);
|
|
43
|
+
const t = 2 * g + Math.ceil(u), r = w - g;
|
|
44
|
+
return Array.from({ length: t }, (s, o) => v(r + o, n));
|
|
45
|
+
}, [n, g, u, w, e]), Tt = b(
|
|
46
|
+
() => `0 0 calc((100% - ${(u - 1) * A}rem) / ${u})`,
|
|
47
|
+
[u, A]
|
|
48
|
+
), Ct = b(() => {
|
|
49
|
+
if (!N)
|
|
50
|
+
return { gap: `${A}rem`, transform: "translate3d(0,0,0)", transition: "none" };
|
|
51
|
+
const t = y * (u - 1), r = (N - t) / u, s = e ? m - w + g : m, o = d.centered ? (N - r) / 2 : 0, i = -s * (r + y) + o;
|
|
40
52
|
return {
|
|
41
|
-
gap: `${
|
|
53
|
+
gap: `${A}rem`,
|
|
42
54
|
transform: `translate3d(${i}px, 0, 0)`,
|
|
43
|
-
transition:
|
|
55
|
+
transition: st ? `transform ${d.transitionMs}ms ease` : "none"
|
|
44
56
|
};
|
|
45
57
|
}, [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
]),
|
|
58
|
+
N,
|
|
59
|
+
A,
|
|
60
|
+
y,
|
|
61
|
+
u,
|
|
62
|
+
m,
|
|
63
|
+
w,
|
|
64
|
+
g,
|
|
65
|
+
st,
|
|
66
|
+
d.transitionMs,
|
|
67
|
+
d.centered,
|
|
68
|
+
e
|
|
69
|
+
]), Pt = f(
|
|
58
70
|
(t) => {
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
if (!e) return t + 1 > m && t < m + u;
|
|
72
|
+
const r = Math.ceil(u);
|
|
73
|
+
return t >= B && t < B + r;
|
|
61
74
|
},
|
|
62
|
-
[
|
|
63
|
-
),
|
|
64
|
-
(t, r,
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
const i =
|
|
68
|
-
|
|
75
|
+
[u, B, e, m]
|
|
76
|
+
), kt = f(
|
|
77
|
+
(t, r, s) => {
|
|
78
|
+
const o = [t];
|
|
79
|
+
if (d.fade) {
|
|
80
|
+
const i = d.fade === "both" || d.fade !== "right" && u <= 1;
|
|
81
|
+
o.push(i ? s : r);
|
|
69
82
|
}
|
|
70
|
-
return
|
|
83
|
+
return o.join(" ");
|
|
71
84
|
},
|
|
72
|
-
[
|
|
73
|
-
),
|
|
74
|
-
|
|
75
|
-
}, []),
|
|
85
|
+
[d.fade, u]
|
|
86
|
+
), Dt = f((t, r) => {
|
|
87
|
+
at.current[t] = r;
|
|
88
|
+
}, []), L = f(() => {
|
|
76
89
|
setTimeout(() => {
|
|
77
|
-
if (!
|
|
78
|
-
const t =
|
|
79
|
-
|
|
90
|
+
if (!ut.current || !n) return;
|
|
91
|
+
const t = e ? v(Math.floor(h.current), n) : Math.min(Math.max(Math.ceil(h.current), 0), n - 1);
|
|
92
|
+
wt(x("carousel.slide", t + 1, n));
|
|
80
93
|
}, 100);
|
|
81
|
-
}, [x,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
}, [
|
|
94
|
+
}, [x, n, e]), G = f(() => {
|
|
95
|
+
F.current = !0, setTimeout(() => {
|
|
96
|
+
F.current = !1;
|
|
97
|
+
}, d.transitionMs);
|
|
98
|
+
}, [d.transitionMs]), ft = f(() => {
|
|
86
99
|
setTimeout(() => {
|
|
87
100
|
var r;
|
|
88
|
-
const t =
|
|
89
|
-
(r =
|
|
101
|
+
const t = e ? h.current - lt.current + g : Math.ceil(h.current);
|
|
102
|
+
(r = at.current[t]) == null || r.focus({ preventScroll: !0 });
|
|
90
103
|
});
|
|
91
|
-
}, [
|
|
92
|
-
!
|
|
93
|
-
}, [e,
|
|
94
|
-
!
|
|
95
|
-
}, [e,
|
|
104
|
+
}, [g, e]), Q = f(() => {
|
|
105
|
+
!n || F.current || !e && h.current >= a || (C(!0), R((t) => e ? t + 1 : l.find((r) => r > t) ?? a), G(), L());
|
|
106
|
+
}, [n, e, a, l, G, L]), Z = f(() => {
|
|
107
|
+
!n || F.current || !e && h.current <= 0 || (C(!0), R((t) => e ? t - 1 : [...l].reverse().find((r) => r < t) ?? 0), G(), L());
|
|
108
|
+
}, [n, e, l, G, L]), H = f(
|
|
96
109
|
(t, r) => {
|
|
97
|
-
if (!(!
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
100
|
-
|
|
110
|
+
if (!(!n || F.current)) {
|
|
111
|
+
if (C(!0), e) {
|
|
112
|
+
const s = v(Math.floor(h.current), n), i = v(t, n) - s;
|
|
113
|
+
R((c) => c + i);
|
|
101
114
|
} else
|
|
102
|
-
|
|
103
|
-
r != null && r.focusSlide ?
|
|
115
|
+
R(E(t));
|
|
116
|
+
r != null && r.focusSlide ? Y.current = !0 : L();
|
|
104
117
|
}
|
|
105
118
|
},
|
|
106
|
-
[
|
|
107
|
-
),
|
|
119
|
+
[n, e, E, L]
|
|
120
|
+
), At = f(
|
|
108
121
|
(t) => {
|
|
109
|
-
t.target !==
|
|
122
|
+
t.target !== ct.current || t.propertyName !== "transform" || X.current || (C(!1), nt(Math.floor(h.current)), Y.current && (Y.current = !1, ft()));
|
|
110
123
|
},
|
|
111
|
-
[
|
|
112
|
-
),
|
|
113
|
-
const t =
|
|
124
|
+
[ft]
|
|
125
|
+
), Et = f(() => {
|
|
126
|
+
const t = O.current;
|
|
114
127
|
t && (t.scrollLeft = 0, t.scrollTop = 0);
|
|
115
|
-
}, []),
|
|
128
|
+
}, []), _ = f(() => (N - y * (u - 1)) / u + y, [N, y, u]), Nt = f(
|
|
116
129
|
(t) => {
|
|
117
|
-
if (!
|
|
130
|
+
if (!n) return;
|
|
118
131
|
const r = Math.abs(t.deltaX) > Math.abs(t.deltaY) ? t.deltaX : t.shiftKey ? t.deltaY : 0;
|
|
119
132
|
if (!r) return;
|
|
120
|
-
const
|
|
121
|
-
if (!
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const i =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
let
|
|
129
|
-
Math.
|
|
130
|
-
const
|
|
131
|
-
|
|
133
|
+
const s = _();
|
|
134
|
+
if (!s) return;
|
|
135
|
+
const o = r / s;
|
|
136
|
+
V.current += o;
|
|
137
|
+
const i = g * 0.9, c = e ? w - i : 0, M = e ? w + i : a, W = h.current + o, P = Math.min(Math.max(W, c), M), tt = P !== W;
|
|
138
|
+
C(!1), R(P), clearTimeout($.current), $.current = setTimeout(() => {
|
|
139
|
+
C(!0);
|
|
140
|
+
const dt = Math.sign(V.current), mt = Math.abs(V.current) > zt, I = h.current;
|
|
141
|
+
let S;
|
|
142
|
+
e ? (S = Math.round(I), mt && (S = dt > 0 ? Math.ceil(I) : Math.floor(I)), tt && (I <= c && (S = Math.ceil(c)), I >= M && (S = Math.floor(M)))) : tt && I >= M ? S = M : tt && I <= c ? S = c : mt ? S = dt > 0 ? l.find((et) => et >= I) ?? M : [...l].reverse().find((et) => et <= I) ?? c : S = l[rt(l, I)];
|
|
143
|
+
const Xt = Math.min(Math.max(S, c), M);
|
|
144
|
+
R(Xt), V.current = 0;
|
|
132
145
|
}, 120);
|
|
133
146
|
},
|
|
134
|
-
[
|
|
135
|
-
),
|
|
147
|
+
[n, _, g, w, e, a, l]
|
|
148
|
+
), yt = f(
|
|
136
149
|
(t) => {
|
|
137
150
|
switch (t.key) {
|
|
138
151
|
case "ArrowRight":
|
|
139
152
|
case "PageDown":
|
|
140
|
-
t.preventDefault(),
|
|
153
|
+
t.preventDefault(), Q();
|
|
141
154
|
break;
|
|
142
155
|
case "ArrowLeft":
|
|
143
156
|
case "PageUp":
|
|
144
|
-
t.preventDefault(),
|
|
157
|
+
t.preventDefault(), Z();
|
|
145
158
|
break;
|
|
146
159
|
case "Home":
|
|
147
|
-
t.preventDefault(),
|
|
160
|
+
t.preventDefault(), H(0);
|
|
148
161
|
break;
|
|
149
162
|
case "End":
|
|
150
|
-
t.preventDefault(),
|
|
163
|
+
t.preventDefault(), H(e ? n - 1 : a);
|
|
151
164
|
break;
|
|
152
165
|
}
|
|
153
166
|
},
|
|
154
|
-
[
|
|
155
|
-
),
|
|
167
|
+
[Q, Z, H, n, e, a]
|
|
168
|
+
), Lt = f(
|
|
156
169
|
(t) => {
|
|
157
170
|
var r;
|
|
158
|
-
|
|
171
|
+
n && ((r = O.current) == null || r.setPointerCapture(t.pointerId), X.current = !0, C(!1), j.current = t.clientX, z.current = h.current, it.current = t.timeStamp, q.current = t.clientX, J.current = t.timeStamp, e && nt(Math.floor(h.current)));
|
|
159
172
|
},
|
|
160
|
-
[
|
|
161
|
-
),
|
|
173
|
+
[n, e]
|
|
174
|
+
), _t = f(
|
|
162
175
|
(t) => {
|
|
163
|
-
if (!
|
|
164
|
-
const r =
|
|
176
|
+
if (!X.current) return;
|
|
177
|
+
const r = _();
|
|
165
178
|
if (!r) return;
|
|
166
|
-
const
|
|
167
|
-
if (Number.isNaN(
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
179
|
+
const s = t.clientX - j.current;
|
|
180
|
+
if (Number.isNaN(s)) return;
|
|
181
|
+
q.current = t.clientX, J.current = t.timeStamp;
|
|
182
|
+
const o = s / r, i = z.current - o, c = g * 0.9, M = Math.floor(z.current), W = e ? M - c : 0, P = e ? M + c : a;
|
|
183
|
+
R(Math.min(Math.max(i, W), P));
|
|
171
184
|
},
|
|
172
|
-
[
|
|
173
|
-
), Ft =
|
|
174
|
-
if (!
|
|
175
|
-
|
|
176
|
-
const t =
|
|
177
|
-
let
|
|
178
|
-
const
|
|
179
|
-
Math.abs(
|
|
180
|
-
}, [
|
|
185
|
+
[_, g, e, a]
|
|
186
|
+
), Ft = f(() => {
|
|
187
|
+
if (!X.current) return;
|
|
188
|
+
X.current = !1, C(!0);
|
|
189
|
+
const t = _(), r = h.current, s = z.current, o = e ? Math.round(s) : s;
|
|
190
|
+
let i = e ? Math.round(r) : l[rt(l, r)];
|
|
191
|
+
const c = J.current - it.current, M = c > 0 && t ? -(q.current - j.current) / t / c : 0;
|
|
192
|
+
Math.abs(M) > 15e-4 && i === o && (e ? i = o + Math.sign(M) : M > 0 ? i = l.find((P) => P > s) ?? a : i = [...l].reverse().find((P) => P < s) ?? 0), R(E(i));
|
|
193
|
+
}, [_, E, e, l, a]);
|
|
181
194
|
return K(() => {
|
|
182
|
-
const t =
|
|
195
|
+
const t = O.current;
|
|
183
196
|
if (!t) return;
|
|
184
|
-
const r = (
|
|
185
|
-
|
|
186
|
-
},
|
|
187
|
-
r(t.clientWidth -
|
|
188
|
-
const i = new ResizeObserver(([
|
|
189
|
-
|
|
197
|
+
const r = (c) => {
|
|
198
|
+
Mt(c), gt(parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
|
|
199
|
+
}, s = getComputedStyle(t), o = (parseFloat(s.paddingLeft) || 0) + (parseFloat(s.paddingRight) || 0);
|
|
200
|
+
r(t.clientWidth - o);
|
|
201
|
+
const i = new ResizeObserver(([c]) => {
|
|
202
|
+
c && r(c.contentRect.width);
|
|
190
203
|
});
|
|
191
204
|
return i.observe(t), () => i.disconnect();
|
|
192
205
|
}, []), K(
|
|
193
206
|
() => () => {
|
|
194
|
-
|
|
207
|
+
ut.current = !1, clearTimeout($.current);
|
|
195
208
|
},
|
|
196
209
|
[]
|
|
197
210
|
), {
|
|
198
|
-
viewportRef:
|
|
199
|
-
trackRef:
|
|
200
|
-
setSlideRef:
|
|
201
|
-
setConfig:
|
|
202
|
-
setSlidesCount:
|
|
203
|
-
slidesCount:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
211
|
+
viewportRef: O,
|
|
212
|
+
trackRef: ct,
|
|
213
|
+
setSlideRef: Dt,
|
|
214
|
+
setConfig: U,
|
|
215
|
+
setSlidesCount: pt,
|
|
216
|
+
slidesCount: n,
|
|
217
|
+
positions: l,
|
|
218
|
+
activePositionIndex: It,
|
|
219
|
+
canPrev: Rt,
|
|
220
|
+
canNext: St,
|
|
221
|
+
renderedIndices: bt,
|
|
222
|
+
renderedActiveIndex: B,
|
|
223
|
+
slideFlex: Tt,
|
|
224
|
+
trackStyle: Ct,
|
|
225
|
+
contentClassName: kt,
|
|
226
|
+
isSlideVisible: Pt,
|
|
227
|
+
announcement: xt,
|
|
228
|
+
regionLabel: (T == null ? void 0 : T.trim()) || x("carousel"),
|
|
229
|
+
slideLabel: (t) => x("carousel.slide", t, n),
|
|
230
|
+
next: Q,
|
|
231
|
+
prev: Z,
|
|
232
|
+
goToIndex: H,
|
|
233
|
+
onTransitionEnd: At,
|
|
234
|
+
onScroll: Et,
|
|
235
|
+
onWheel: Nt,
|
|
236
|
+
onKeyDown: yt,
|
|
237
|
+
onPointerDown: Lt,
|
|
238
|
+
onPointerMove: _t,
|
|
225
239
|
onPointerUp: Ft
|
|
226
240
|
};
|
|
227
241
|
};
|
|
228
242
|
export {
|
|
229
|
-
|
|
243
|
+
Ut as useCarousel
|
|
230
244
|
};
|