wimui 0.63.5 → 0.64.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.
- package/dist/components/data-display/Carousel/Carousel.cjs +1 -1
- package/dist/components/data-display/Carousel/Carousel.d.ts +2 -0
- package/dist/components/data-display/Carousel/Carousel.js +119 -98
- package/dist/components/media/Lightbox/Lightbox.cjs +1 -1
- package/dist/components/media/Lightbox/Lightbox.js +134 -116
- package/dist/components/navigation/CommandPalette/command-palette.module.cjs +1 -1
- package/dist/components/navigation/CommandPalette/command-palette.module.js +1 -1
- package/dist/i18n/generated/components.cjs +1 -1
- package/dist/i18n/generated/components.d.ts +1 -1
- package/dist/i18n/generated/components.js +9 -3
- package/dist/llms-full.txt +2 -2
- package/dist/llms.txt +1 -1
- package/dist/locales/en/components.json +3 -1
- package/dist/locales/ja/components.json +3 -1
- package/dist/locales/pt/components.json +3 -1
- package/dist/styles.css +1 -1
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +2 -2
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../i18n/useWimTranslation.cjs"),r=require("../../../i18n/generated/components.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../i18n/useWimTranslation.cjs"),r=require("../../../hooks/useMergedRef.cjs"),i=require("../../layout/VisuallyHidden/VisuallyHidden.cjs"),ee=require("../../../i18n/generated/components.cjs"),a=require("../../../icon/chevron-left.cjs"),te=require("../../../icon/chevron-right.cjs"),o=require("../../media/Icon/Icon.cjs"),s=require("./carousel.module.cjs");let c=require("react");c=e.__toESM(c,1);let l=require("classnames");l=e.__toESM(l,1);let u=require("react/jsx-runtime");var d=(e,t)=>typeof e==`number`?e:e?t>=1280&&e.xl?e.xl:t>=1024&&e.lg?e.lg:t>=768&&e.md?e.md:t>=640&&e.sm?e.sm:e.base||1:1,f=(0,c.forwardRef)(({children:e,autoPlay:f=!1,interval:p=5e3,showIndicators:m=!0,showControls:ne=!0,controlsPlacement:re=`overlay`,loop:h=!0,slidesToShow:g=1,aspectRatio:_,objectFit:v=`cover`,labels:y,className:b,asChild:x,...ie},ae)=>{let oe=x?t.Root:`div`,{t:S}=n.useWimTranslation(ee.componentsNs),C={slideLabel:e=>S(`carousel.slide`,{number:e}),prevSlide:S(`carousel.prev_slide`),nextSlide:S(`carousel.next_slide`),goToSlide:e=>S(`carousel.go_to_slide`,{number:e}),slideStatus:(e,t)=>S(`carousel.slide_status`,{current:e,total:t}),...y},w=x&&c.default.isValidElement(e)?e.props.children:e,T=(0,c.useMemo)(()=>c.default.Children.toArray(w),[w]),E=T.length,[D,O]=(0,c.useState)(typeof window<`u`?window.innerWidth:0),[k,A]=(0,c.useState)(h?E:0),[j,M]=(0,c.useState)(!1),[N,P]=(0,c.useState)(!1),F=d(g,D),I=(0,c.useRef)(null),L=(0,c.useRef)(null),R=(0,c.useRef)(null),z=(0,c.useRef)(null),B=(0,c.useRef)(null),V=(0,c.useRef)(null),H=(0,c.useRef)(null),U=r.useMergedRef(ae,H);(0,c.useEffect)(()=>{let e=()=>O(window.innerWidth);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let W=(0,c.useMemo)(()=>!h||E===0?T:[...T,...T,...T],[T,h,E]),G=(0,c.useCallback)(()=>{if(!j){if(!h){A(e=>Math.min(e+1,E-F));return}M(!0),A(e=>e+1)}},[j,h,E,F]),K=(0,c.useCallback)(()=>{if(!j){if(!h){A(e=>Math.max(e-1,0));return}M(!0),A(e=>e-1)}},[j,h]),se=e=>{j||(h?(M(!0),A(e+E)):A(e))},ce=()=>{h&&(M(!1),k>=E*2?A(k-E):k<E&&A(k+E))};(0,c.useEffect)(()=>(f&&!N&&E>F&&(I.current=window.setInterval(G,p)),()=>{I.current&&window.clearInterval(I.current)}),[f,p,G,E,F,N]);let[le,ue]=(0,c.useState)(``),q=h?k%E:k,J=h?E-1:Math.max(E-F,0),Y=e=>{j||e===q||ue(C.slideStatus(e+1,E))},de=e=>{Y(e),se(e)},X=()=>{let e=h?(q-1+E)%E:Math.max(q-1,0);Y(e),!h&&e===0&&document.activeElement===B.current&&H.current?.focus(),K()},Z=()=>{let e=h?(q+1)%E:Math.min(q+1,J);Y(e),!h&&e===J&&document.activeElement===V.current&&H.current?.focus(),G()},fe=e=>{e.key===`ArrowLeft`?X():e.key===`ArrowRight`&&Z()},pe=e=>{R.current=e.targetTouches[0].clientX},me=e=>{z.current=e.targetTouches[0].clientX},he=()=>{if(!R.current||!z.current)return;let e=R.current-z.current;e>50?G():e<-50&&K(),R.current=null,z.current=null};if(E===0)return null;let Q=100/F,ge=-k*Q,$=(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(i.VisuallyHidden,{role:`status`,"aria-atomic":`true`,children:le}),(0,u.jsx)(`div`,{className:s.default.viewport,children:(0,u.jsx)(`div`,{ref:L,className:(0,l.default)(s.default.track,j&&s.default.transition),style:{transform:`translateX(${ge}%)`},onTransitionEnd:ce,onTouchStart:pe,onTouchMove:me,onTouchEnd:he,children:W.map((e,t)=>(0,u.jsx)(`div`,{className:(0,l.default)(s.default.item,_&&s.default.hasAspectRatio),style:{flex:`0 0 ${Q}%`,width:`${Q}%`,..._?{aspectRatio:_,"--wim-carousel-object-fit":v}:{}},role:`group`,"aria-roledescription":S(`carousel.slide_roledescription`),"aria-label":C.slideLabel(t%E+1),children:e},t))})}),ne&&E>F&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`button`,{ref:B,className:(0,l.default)(s.default.control,s.default.prev),onClick:X,"aria-label":C.prevSlide,disabled:!h&&k===0,children:(0,u.jsx)(o.Icon,{component:a.default,size:`md`})}),(0,u.jsx)(`button`,{ref:V,className:(0,l.default)(s.default.control,s.default.next),onClick:Z,"aria-label":C.nextSlide,disabled:!h&&k>=E-F,children:(0,u.jsx)(o.Icon,{component:te.default,size:`md`})})]}),m&&E>1&&(0,u.jsx)(`div`,{className:s.default.indicators,children:T.map((e,t)=>{let n=h?k%E===t:k===t;return(0,u.jsx)(`button`,{className:(0,l.default)(s.default.indicator,n&&s.default.active),onClick:()=>de(t),"aria-label":C.goToSlide(t+1),"aria-current":n?`true`:`false`},t)})})]});return(0,u.jsx)(oe,{ref:U,className:(0,l.default)(`wim-carousel`,s.default.root,re===`outside`&&s.default.controlsOutside,b),onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1),onFocus:()=>P(!0),onBlur:()=>P(!1),onKeyDown:fe,tabIndex:0,role:`region`,"aria-roledescription":S(`carousel.roledescription`),...ie,children:x?(0,u.jsx)(t.Slottable,{child:e,children:()=>$}):$})});f.displayName=`Carousel`,exports.Carousel=f;
|
|
@@ -11,6 +11,8 @@ export type CarouselLabels = {
|
|
|
11
11
|
prevSlide?: string;
|
|
12
12
|
nextSlide?: string;
|
|
13
13
|
goToSlide?: (number: number) => string;
|
|
14
|
+
/** Announced to screen readers when the user changes the slide. Receives the slide number and the slide count. */
|
|
15
|
+
slideStatus?: (current: number, total: number) => string;
|
|
14
16
|
};
|
|
15
17
|
export type CarouselProps = {
|
|
16
18
|
/** Content of the carousel */
|
|
@@ -1,163 +1,184 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Root as e, Slottable as t } from "../../../node_modules/@radix-ui/react-slot/dist/index.js";
|
|
3
3
|
import { useWimTranslation as n } from "../../../i18n/useWimTranslation.js";
|
|
4
|
-
import {
|
|
5
|
-
import te from "
|
|
6
|
-
import r from "../../../
|
|
4
|
+
import { useMergedRef as ee } from "../../../hooks/useMergedRef.js";
|
|
5
|
+
import { VisuallyHidden as te } from "../../layout/VisuallyHidden/VisuallyHidden.js";
|
|
6
|
+
import { componentsNs as r } from "../../../i18n/generated/components.js";
|
|
7
|
+
import ne from "../../../icon/chevron-left.js";
|
|
8
|
+
import re from "../../../icon/chevron-right.js";
|
|
7
9
|
import { Icon as i } from "../../media/Icon/Icon.js";
|
|
8
10
|
import a from "./carousel.module.js";
|
|
9
11
|
import o, { forwardRef as s, useCallback as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
10
12
|
import p from "classnames";
|
|
11
13
|
import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
12
14
|
//#region src/components/data-display/Carousel/Carousel.tsx
|
|
13
|
-
var
|
|
14
|
-
let
|
|
15
|
-
slideLabel: (e) =>
|
|
16
|
-
prevSlide:
|
|
17
|
-
nextSlide:
|
|
18
|
-
goToSlide: (e) =>
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
var ie = (e, t) => typeof e == "number" ? e : e ? t >= 1280 && e.xl ? e.xl : t >= 1024 && e.lg ? e.lg : t >= 768 && e.md ? e.md : t >= 640 && e.sm ? e.sm : e.base || 1 : 1, _ = s(({ children: s, autoPlay: _ = !1, interval: v = 5e3, showIndicators: ae = !0, showControls: oe = !0, controlsPlacement: se = "overlay", loop: y = !0, slidesToShow: ce = 1, aspectRatio: b, objectFit: le = "cover", labels: ue, className: x, asChild: S, ...C }, w) => {
|
|
16
|
+
let de = S ? e : "div", { t: T } = n(r), E = {
|
|
17
|
+
slideLabel: (e) => T("carousel.slide", { number: e }),
|
|
18
|
+
prevSlide: T("carousel.prev_slide"),
|
|
19
|
+
nextSlide: T("carousel.next_slide"),
|
|
20
|
+
goToSlide: (e) => T("carousel.go_to_slide", { number: e }),
|
|
21
|
+
slideStatus: (e, t) => T("carousel.slide_status", {
|
|
22
|
+
current: e,
|
|
23
|
+
total: t
|
|
24
|
+
}),
|
|
25
|
+
...ue
|
|
26
|
+
}, D = S && o.isValidElement(s) ? s.props.children : s, O = u(() => o.Children.toArray(D), [D]), k = O.length, [fe, A] = f(typeof window < "u" ? window.innerWidth : 0), [j, M] = f(y ? k : 0), [N, P] = f(!1), [F, I] = f(!1), L = ie(ce, fe), R = d(null), z = d(null), B = d(null), V = d(null), H = d(null), U = d(null), W = d(null), pe = ee(w, W);
|
|
21
27
|
l(() => {
|
|
22
|
-
let e = () =>
|
|
28
|
+
let e = () => A(window.innerWidth);
|
|
23
29
|
return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
24
30
|
}, []);
|
|
25
|
-
let
|
|
26
|
-
...
|
|
27
|
-
...
|
|
28
|
-
...
|
|
31
|
+
let me = u(() => !y || k === 0 ? O : [
|
|
32
|
+
...O,
|
|
33
|
+
...O,
|
|
34
|
+
...O
|
|
29
35
|
], [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
]),
|
|
34
|
-
if (!
|
|
35
|
-
if (!
|
|
36
|
-
|
|
36
|
+
O,
|
|
37
|
+
y,
|
|
38
|
+
k
|
|
39
|
+
]), G = c(() => {
|
|
40
|
+
if (!N) {
|
|
41
|
+
if (!y) {
|
|
42
|
+
M((e) => Math.min(e + 1, k - L));
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
P(!0), M((e) => e + 1);
|
|
40
46
|
}
|
|
41
47
|
}, [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
]),
|
|
47
|
-
if (!
|
|
48
|
-
if (!
|
|
49
|
-
|
|
48
|
+
N,
|
|
49
|
+
y,
|
|
50
|
+
k,
|
|
51
|
+
L
|
|
52
|
+
]), K = c(() => {
|
|
53
|
+
if (!N) {
|
|
54
|
+
if (!y) {
|
|
55
|
+
M((e) => Math.max(e - 1, 0));
|
|
50
56
|
return;
|
|
51
57
|
}
|
|
52
|
-
|
|
58
|
+
P(!0), M((e) => e - 1);
|
|
53
59
|
}
|
|
54
|
-
}, [
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
|
|
60
|
+
}, [N, y]), he = (e) => {
|
|
61
|
+
N || (y ? (P(!0), M(e + k)) : M(e));
|
|
62
|
+
}, ge = () => {
|
|
63
|
+
y && (P(!1), j >= k * 2 ? M(j - k) : j < k && M(j + k));
|
|
58
64
|
};
|
|
59
|
-
l(() => (
|
|
60
|
-
|
|
65
|
+
l(() => (_ && !F && k > L && (R.current = window.setInterval(G, v)), () => {
|
|
66
|
+
R.current && window.clearInterval(R.current);
|
|
61
67
|
}), [
|
|
68
|
+
_,
|
|
62
69
|
v,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
V
|
|
70
|
+
G,
|
|
71
|
+
k,
|
|
72
|
+
L,
|
|
73
|
+
F
|
|
68
74
|
]);
|
|
69
|
-
let
|
|
70
|
-
e
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
q.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let e =
|
|
78
|
-
|
|
75
|
+
let [_e, ve] = f(""), q = y ? j % k : j, J = y ? k - 1 : Math.max(k - L, 0), Y = (e) => {
|
|
76
|
+
N || e === q || ve(E.slideStatus(e + 1, k));
|
|
77
|
+
}, ye = (e) => {
|
|
78
|
+
Y(e), he(e);
|
|
79
|
+
}, X = () => {
|
|
80
|
+
let e = y ? (q - 1 + k) % k : Math.max(q - 1, 0);
|
|
81
|
+
Y(e), !y && e === 0 && document.activeElement === H.current && W.current?.focus(), K();
|
|
82
|
+
}, Z = () => {
|
|
83
|
+
let e = y ? (q + 1) % k : Math.min(q + 1, J);
|
|
84
|
+
Y(e), !y && e === J && document.activeElement === U.current && W.current?.focus(), G();
|
|
85
|
+
}, be = (e) => {
|
|
86
|
+
e.key === "ArrowLeft" ? X() : e.key === "ArrowRight" && Z();
|
|
87
|
+
}, xe = (e) => {
|
|
88
|
+
B.current = e.targetTouches[0].clientX;
|
|
89
|
+
}, Se = (e) => {
|
|
90
|
+
V.current = e.targetTouches[0].clientX;
|
|
91
|
+
}, Ce = () => {
|
|
92
|
+
if (!B.current || !V.current) return;
|
|
93
|
+
let e = B.current - V.current;
|
|
94
|
+
e > 50 ? G() : e < -50 && K(), B.current = null, V.current = null;
|
|
79
95
|
};
|
|
80
|
-
if (
|
|
81
|
-
let Q = 100 /
|
|
96
|
+
if (k === 0) return null;
|
|
97
|
+
let Q = 100 / L, we = -j * Q, $ = /* @__PURE__ */ g(m, { children: [
|
|
98
|
+
/* @__PURE__ */ h(te, {
|
|
99
|
+
role: "status",
|
|
100
|
+
"aria-atomic": "true",
|
|
101
|
+
children: _e
|
|
102
|
+
}),
|
|
82
103
|
/* @__PURE__ */ h("div", {
|
|
83
104
|
className: a.viewport,
|
|
84
105
|
children: /* @__PURE__ */ h("div", {
|
|
85
|
-
ref:
|
|
86
|
-
className: p(a.track,
|
|
87
|
-
style: { transform: `translateX(${
|
|
88
|
-
onTransitionEnd:
|
|
89
|
-
onTouchStart:
|
|
90
|
-
onTouchMove:
|
|
91
|
-
onTouchEnd:
|
|
92
|
-
children:
|
|
93
|
-
className: p(a.item,
|
|
106
|
+
ref: z,
|
|
107
|
+
className: p(a.track, N && a.transition),
|
|
108
|
+
style: { transform: `translateX(${we}%)` },
|
|
109
|
+
onTransitionEnd: ge,
|
|
110
|
+
onTouchStart: xe,
|
|
111
|
+
onTouchMove: Se,
|
|
112
|
+
onTouchEnd: Ce,
|
|
113
|
+
children: me.map((e, t) => /* @__PURE__ */ h("div", {
|
|
114
|
+
className: p(a.item, b && a.hasAspectRatio),
|
|
94
115
|
style: {
|
|
95
116
|
flex: `0 0 ${Q}%`,
|
|
96
117
|
width: `${Q}%`,
|
|
97
|
-
...
|
|
98
|
-
aspectRatio:
|
|
99
|
-
"--wim-carousel-object-fit":
|
|
118
|
+
...b ? {
|
|
119
|
+
aspectRatio: b,
|
|
120
|
+
"--wim-carousel-object-fit": le
|
|
100
121
|
} : {}
|
|
101
122
|
},
|
|
102
123
|
role: "group",
|
|
103
|
-
"aria-roledescription":
|
|
104
|
-
"aria-label":
|
|
124
|
+
"aria-roledescription": T("carousel.slide_roledescription"),
|
|
125
|
+
"aria-label": E.slideLabel(t % k + 1),
|
|
105
126
|
children: e
|
|
106
127
|
}, t))
|
|
107
128
|
})
|
|
108
129
|
}),
|
|
109
|
-
|
|
130
|
+
oe && k > L && /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("button", {
|
|
131
|
+
ref: H,
|
|
110
132
|
className: p(a.control, a.prev),
|
|
111
133
|
onClick: X,
|
|
112
|
-
"aria-label":
|
|
113
|
-
disabled: !
|
|
114
|
-
tabIndex: -1,
|
|
134
|
+
"aria-label": E.prevSlide,
|
|
135
|
+
disabled: !y && j === 0,
|
|
115
136
|
children: /* @__PURE__ */ h(i, {
|
|
116
|
-
component:
|
|
137
|
+
component: ne,
|
|
117
138
|
size: "md"
|
|
118
139
|
})
|
|
119
140
|
}), /* @__PURE__ */ h("button", {
|
|
141
|
+
ref: U,
|
|
120
142
|
className: p(a.control, a.next),
|
|
121
|
-
onClick:
|
|
122
|
-
"aria-label":
|
|
123
|
-
disabled: !
|
|
124
|
-
tabIndex: -1,
|
|
143
|
+
onClick: Z,
|
|
144
|
+
"aria-label": E.nextSlide,
|
|
145
|
+
disabled: !y && j >= k - L,
|
|
125
146
|
children: /* @__PURE__ */ h(i, {
|
|
126
|
-
component:
|
|
147
|
+
component: re,
|
|
127
148
|
size: "md"
|
|
128
149
|
})
|
|
129
150
|
})] }),
|
|
130
|
-
|
|
151
|
+
ae && k > 1 && /* @__PURE__ */ h("div", {
|
|
131
152
|
className: a.indicators,
|
|
132
|
-
children:
|
|
133
|
-
let n =
|
|
153
|
+
children: O.map((e, t) => {
|
|
154
|
+
let n = y ? j % k === t : j === t;
|
|
134
155
|
return /* @__PURE__ */ h("button", {
|
|
135
156
|
className: p(a.indicator, n && a.active),
|
|
136
|
-
onClick: () =>
|
|
137
|
-
"aria-label":
|
|
157
|
+
onClick: () => ye(t),
|
|
158
|
+
"aria-label": E.goToSlide(t + 1),
|
|
138
159
|
"aria-current": n ? "true" : "false"
|
|
139
160
|
}, t);
|
|
140
161
|
})
|
|
141
162
|
})
|
|
142
163
|
] });
|
|
143
|
-
return /* @__PURE__ */ h(
|
|
144
|
-
ref:
|
|
145
|
-
className: p("wim-carousel", a.root,
|
|
146
|
-
onMouseEnter: () =>
|
|
147
|
-
onMouseLeave: () =>
|
|
148
|
-
onFocus: () =>
|
|
149
|
-
onBlur: () =>
|
|
150
|
-
onKeyDown:
|
|
164
|
+
return /* @__PURE__ */ h(de, {
|
|
165
|
+
ref: pe,
|
|
166
|
+
className: p("wim-carousel", a.root, se === "outside" && a.controlsOutside, x),
|
|
167
|
+
onMouseEnter: () => I(!0),
|
|
168
|
+
onMouseLeave: () => I(!1),
|
|
169
|
+
onFocus: () => I(!0),
|
|
170
|
+
onBlur: () => I(!1),
|
|
171
|
+
onKeyDown: be,
|
|
151
172
|
tabIndex: 0,
|
|
152
173
|
role: "region",
|
|
153
|
-
"aria-roledescription":
|
|
154
|
-
...
|
|
155
|
-
children:
|
|
174
|
+
"aria-roledescription": T("carousel.roledescription"),
|
|
175
|
+
...C,
|
|
176
|
+
children: S ? /* @__PURE__ */ h(t, {
|
|
156
177
|
child: s,
|
|
157
178
|
children: () => $
|
|
158
179
|
}) : $
|
|
159
180
|
});
|
|
160
181
|
});
|
|
161
|
-
|
|
182
|
+
_.displayName = "Carousel";
|
|
162
183
|
//#endregion
|
|
163
|
-
export {
|
|
184
|
+
export { _ as Carousel };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../i18n/useWimTranslation.cjs"),r=require("../../_internal/OverlayBase.cjs"),i=require("../../../i18n/generated/components.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../node_modules/@radix-ui/react-slot/dist/index.cjs"),n=require("../../../i18n/useWimTranslation.cjs"),r=require("../../_internal/OverlayBase.cjs"),i=require("../../layout/VisuallyHidden/VisuallyHidden.cjs"),a=require("../../../i18n/generated/components.cjs"),o=require("../../../icon/chevron-left.cjs"),s=require("../../../icon/chevron-right.cjs"),c=require("../../../icon/close.cjs"),l=require("../../../icon/minus.cjs"),u=require("../../../icon/plus.cjs"),d=require("../Icon/Icon.cjs"),f=require("./lightbox.module.cjs");let p=require("react");p=e.__toESM(p,1);let m=require("classnames");m=e.__toESM(m,1);let h=require("react/jsx-runtime");var g=(0,p.createContext)(void 0),_=()=>{let e=(0,p.useContext)(g);if(!e)throw Error(`Lightbox components must be used within Lightbox`);return e},v=({children:e,open:t,onOpenChange:n,defaultOpen:r=!1,defaultIndex:i=0})=>{let[a,o]=(0,p.useState)(r),[s,c]=(0,p.useState)(i),[l,u]=(0,p.useState)([]),d=t!==void 0,f=d?t:a,m=(0,p.useCallback)(e=>{d||o(e),n?.(e)},[d,n]),_=(0,p.useCallback)(e=>{let t=-1;return u(n=>(t=n.length,[...n,e])),t},[]),v=(0,p.useCallback)(e=>{},[]);return(0,h.jsx)(g.Provider,{value:{open:f,setOpen:m,currentIndex:s,setCurrentIndex:c,items:l,setItems:u,registerItem:_,unregisterItem:v},children:e})},y=({children:e,className:r,onClick:i,asChild:o=!1,index:s,src:c,alt:l,caption:u,...d})=>{let{setOpen:p,setCurrentIndex:g,items:v,setItems:y}=_(),{t:b}=n.useWimTranslation(a.componentsNs),x=e=>{if(i?.(e),s!==void 0)g(s);else if(c){let e=v.findIndex(e=>e.src===c);if(e!==-1)g(e);else{let e=v.length;y(e=>[...e,{src:c,alt:l,caption:u}]),g(e)}}p(!0)},S=o?t.Root:`button`,C=s===void 0?void 0:v[s]?.alt,w=d[`aria-label`]!==void 0||d[`aria-labelledby`]!==void 0,T=l??C,E=w?void 0:T?b(`lightbox.open_named`,{name:T}):b(`lightbox.open`);return(0,h.jsx)(S,{type:`button`,className:(0,m.default)(f.default.trigger,r),onClick:x,"aria-label":E,...d,children:(0,h.jsx)(t.Slottable,{children:e})})},b=({className:e,showCloseButton:t=!0,showNavigation:g=!0,showCounter:v=!0,closeOnOverlayClick:y=!0,...b})=>{let{open:x,setOpen:S,currentIndex:C,setCurrentIndex:w,items:T}=_(),{t:E}=n.useWimTranslation(a.componentsNs),[D,O]=(0,p.useState)(1),[k,A]=(0,p.useState)(``);!x&&k&&A(``);let j=(0,p.useCallback)(e=>{let t=T[e],n=t?.title||t?.alt,r=E(`lightbox.image_status`,{current:e+1,total:T.length});A(n?`${r}: ${n}`:r),w(e),O(1)},[T,w,E]),M=(0,p.useCallback)(()=>{j((C-1+T.length)%T.length)},[C,T.length,j]),N=(0,p.useCallback)(()=>{j((C+1)%T.length)},[C,T.length,j]),P=()=>{O(e=>e===1?2:1)};(0,p.useEffect)(()=>{if(!x)return;let e=e=>{e.key===`ArrowLeft`&&M(),e.key===`ArrowRight`&&N(),e.key===`Escape`&&S(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x,M,N,S]);let F=T[C];return F?(0,h.jsx)(r.OverlayBase,{...b,open:x,onOpenChange:S,closeOnOverlayClick:y,overlayClassName:f.default.overlay,className:(0,m.default)(`wim-lightbox`,f.default.contentRoot,e),"aria-label":b[`aria-labelledby`]?void 0:b[`aria-label`]??(F.title||F.alt||E(`lightbox.dialog`)),transitionProps:{preset:`fade`,enter:f.default.contentEnter,enterFrom:f.default.contentEnterFrom,enterTo:f.default.contentEnterTo},children:(0,h.jsxs)(`div`,{className:f.default.container,children:[(0,h.jsx)(i.VisuallyHidden,{role:`status`,"aria-atomic":`true`,children:k}),(0,h.jsxs)(`div`,{className:f.default.header,children:[v&&T.length>1&&(0,h.jsx)(`div`,{className:f.default.counter,children:E(`lightbox.counter`,{current:C+1,total:T.length})}),(0,h.jsxs)(`div`,{className:f.default.controls,children:[(0,h.jsx)(`button`,{className:f.default.iconButton,onClick:P,"aria-label":E(D>1?`lightbox.zoom_out`:`lightbox.zoom_in`),children:D>1?(0,h.jsx)(d.Icon,{component:l.default}):(0,h.jsx)(d.Icon,{component:u.default})}),t&&(0,h.jsx)(`button`,{className:f.default.iconButton,onClick:()=>S(!1),"aria-label":E(`lightbox.close`),children:(0,h.jsx)(d.Icon,{component:c.default})})]})]}),(0,h.jsxs)(`div`,{className:f.default.viewport,children:[g&&T.length>1&&(0,h.jsx)(`button`,{className:(0,m.default)(f.default.navButton,f.default.prev),onClick:M,"aria-label":E(`lightbox.previous`),children:(0,h.jsx)(d.Icon,{component:o.default})}),(0,h.jsx)(`div`,{className:f.default.mediaWrapper,style:{transform:`scale(${D})`},children:(0,h.jsx)(`img`,{src:F.src,alt:F.alt||``,className:f.default.image})}),g&&T.length>1&&(0,h.jsx)(`button`,{className:(0,m.default)(f.default.navButton,f.default.next),onClick:N,"aria-label":E(`lightbox.next`),children:(0,h.jsx)(d.Icon,{component:s.default})})]}),(F.title||F.caption)&&(0,h.jsxs)(`div`,{className:f.default.footer,children:[F.title&&(0,h.jsx)(`h3`,{className:f.default.title,children:F.title}),F.caption&&(0,h.jsx)(`p`,{className:f.default.caption,children:F.caption})]})]})}):null},x=({items:e,children:t})=>{let{setItems:n}=_();return(0,p.useEffect)(()=>{n(e)},[e,n]),(0,h.jsx)(`div`,{className:f.default.gallery,children:t})},S=v;S.Trigger=y,S.Content=b,S.Gallery=x,S.displayName=`Lightbox`,y.displayName=`Lightbox.Trigger`,b.displayName=`Lightbox.Content`,x.displayName=`Lightbox.Gallery`,exports.Lightbox=v,exports.LightboxContent=b,exports.LightboxGallery=x,exports.LightboxRoot=S,exports.default=S,exports.LightboxTrigger=y,exports.useLightbox=_;
|