@smwb/ui-react 2.0.1 → 2.1.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.
@@ -1,89 +1,80 @@
1
- import { jsxs as I, jsx as h } from "react/jsx-runtime";
1
+ import { jsxs as B, jsx as w } from "react/jsx-runtime";
2
2
  import '../../../assets/styles/less/components/screenDivider/screenDivider.entry.css';/* empty css */
3
- import { forwardRef as j, useRef as P, useState as y, useEffect as b, Children as X, useMemo as Y, useCallback as O } from "react";
3
+ import { forwardRef as C, useRef as O, useState as y, useEffect as b, Children as P, useMemo as U, useCallback as W } from "react";
4
4
  import D from "clsx";
5
- import { throttle as T } from "../../../utils/throttle.js";
6
- import { useForkRef as U } from "../../../hooks/useForkRef.js";
7
- const _ = (o, d) => d * (o / 100), x = (o, d) => !o && d ? 100 - d : o || 50, V = j(function({
5
+ import { throttle as X } from "../../../utils/throttle.js";
6
+ import { useForkRef as Y } from "../../../hooks/useForkRef.js";
7
+ const x = (c, d) => !c && d ? 100 - d : c || 50, Z = C(function({
8
8
  className: d,
9
9
  orientation: e = "horizontal",
10
- sizeFirst: m,
10
+ sizeFirst: f,
11
11
  sizeSecond: v,
12
- children: $,
13
- onSizeChange: a,
12
+ children: L,
13
+ onSizeChange: i,
14
14
  keyboardStep: g = 5,
15
- resizerAriaLabel: k = "Resize panels"
16
- }, A) {
17
- const p = P(null), M = U(A, p), [i, l] = y(x(m, v)), [E, L] = y(null), [f, R] = y(!1);
15
+ resizerAriaLabel: $ = "Resize panels"
16
+ }, k) {
17
+ const p = O(null), A = Y(k, p), [t, n] = y(x(f, v)), [E, R] = y(null), [m, _] = y(!1);
18
18
  b(() => {
19
- l(x(m, v));
20
- }, [m, v]);
21
- const w = X.toArray($);
22
- if (w.length > 2)
19
+ n(x(f, v));
20
+ }, [f, v]);
21
+ const h = P.toArray(L);
22
+ if (h.length > 2)
23
23
  throw new Error("Allowed not more than 2 children");
24
- const K = () => {
25
- L(p.current), R(!0);
26
- }, c = Y(
27
- () => T((r) => {
28
- if (!f) return;
29
- const n = p.current;
30
- if (!(!n || n !== E))
31
- if (e === "vertical") {
32
- let s = r.clientY - n.offsetTop;
33
- s < 0 && (s = 0);
34
- const t = s / n.clientHeight * 100;
35
- _(t, n.clientWidth) > 5 && t < 101 && l(t - 7);
36
- } else {
37
- let s = r.clientX - n.offsetLeft;
38
- s < 0 && (s = 0);
39
- const t = s / n.clientWidth * 100;
40
- _(t, n.clientWidth) > 5 && t < 101 && l(t);
41
- }
24
+ const M = () => {
25
+ R(p.current), _(!0);
26
+ }, o = U(
27
+ () => X((r) => {
28
+ if (!m) return;
29
+ const a = p.current;
30
+ if (!a || a !== E) return;
31
+ const s = a.getBoundingClientRect(), l = e === "vertical" ? s.height : s.width, j = e === "vertical" ? r.clientY - s.top : r.clientX - s.left, H = Math.max(5, Math.min(l - 5, j));
32
+ n(H / l * 100);
42
33
  }, 1e3 / 60),
43
- [f, E, e]
44
- ), u = O(() => {
45
- L(null), R(!1), document.body.removeEventListener("pointerup", u), document.body.removeEventListener("pointermove", c);
46
- }, [c]);
34
+ [m, E, e]
35
+ ), u = W(() => {
36
+ R(null), _(!1), document.body.removeEventListener("pointerup", u), document.body.removeEventListener("pointermove", o);
37
+ }, [o]);
47
38
  b(() => {
48
- a == null || a(i);
49
- }, [i, a]);
50
- const N = (r) => {
51
- const n = e === "vertical" ? "ArrowUp" : "ArrowLeft", s = e === "vertical" ? "ArrowDown" : "ArrowRight";
52
- r.key === n ? (r.preventDefault(), l((t) => Math.max(0, t - g))) : r.key === s ? (r.preventDefault(), l((t) => Math.min(100, t + g))) : r.key === "Home" ? (r.preventDefault(), l(0)) : r.key === "End" && (r.preventDefault(), l(100));
53
- }, W = e === "vertical" ? { height: `${100 - i}%` } : { width: `${100 - i}%` }, H = e === "vertical" ? { height: `${i}%` } : { width: `${i}%` };
54
- return b(() => (f ? (document.body.addEventListener("pointerup", u), document.body.addEventListener("pointermove", c), document.body.style.cursor = e === "horizontal" ? "e-resize" : "n-resize") : document.body.style.cursor = "default", () => {
55
- document.body.removeEventListener("pointerup", u), document.body.removeEventListener("pointermove", c);
56
- }), [c, u, f, e]), /* @__PURE__ */ I(
39
+ i == null || i(t);
40
+ }, [t, i]);
41
+ const K = (r) => {
42
+ const a = e === "vertical" ? "ArrowUp" : "ArrowLeft", s = e === "vertical" ? "ArrowDown" : "ArrowRight";
43
+ r.key === a ? (r.preventDefault(), n((l) => Math.max(0, l - g))) : r.key === s ? (r.preventDefault(), n((l) => Math.min(100, l + g))) : r.key === "Home" ? (r.preventDefault(), n(0)) : r.key === "End" && (r.preventDefault(), n(100));
44
+ }, N = e === "vertical" ? { height: `${100 - t}%` } : { width: `${100 - t}%` }, I = e === "vertical" ? { height: `${t}%` } : { width: `${t}%` };
45
+ return b(() => (m ? (document.body.addEventListener("pointerup", u), document.body.addEventListener("pointermove", o), document.body.style.cursor = e === "horizontal" ? "e-resize" : "n-resize") : document.body.style.cursor = "default", () => {
46
+ document.body.removeEventListener("pointerup", u), document.body.removeEventListener("pointermove", o);
47
+ }), [o, u, m, e]), /* @__PURE__ */ B(
57
48
  "div",
58
49
  {
59
50
  className: D("smwb-screen-divider__wrapper", `smwb-${e}`, d),
60
- ref: M,
51
+ ref: A,
61
52
  "data-testid": "screen-divider",
62
53
  children: [
63
- /* @__PURE__ */ h("div", { className: D("smwb-screen-divider__first", `smwb-${e}`), style: H, children: w[0] || "" }),
64
- /* @__PURE__ */ h(
54
+ /* @__PURE__ */ w("div", { className: D("smwb-screen-divider__first", `smwb-${e}`), style: I, children: h[0] || "" }),
55
+ /* @__PURE__ */ w(
65
56
  "span",
66
57
  {
67
58
  className: "smwb-screen-divider__resizer",
68
- onPointerDown: K,
59
+ onPointerDown: M,
69
60
  draggable: !1,
70
61
  role: "separator",
71
62
  "aria-orientation": e === "vertical" ? "horizontal" : "vertical",
72
- "aria-valuenow": Math.round(i),
63
+ "aria-valuenow": Math.round(t),
73
64
  "aria-valuemin": 0,
74
65
  "aria-valuemax": 100,
75
- "aria-label": k,
66
+ "aria-label": $,
76
67
  tabIndex: 0,
77
- onKeyDown: N
68
+ onKeyDown: K
78
69
  }
79
70
  ),
80
- /* @__PURE__ */ h("div", { className: D("smwb-screen-divider__second", `smwb-${e}`), style: W, children: w[1] || "" })
71
+ /* @__PURE__ */ w("div", { className: D("smwb-screen-divider__second", `smwb-${e}`), style: N, children: h[1] || "" })
81
72
  ]
82
73
  }
83
74
  );
84
75
  });
85
76
  export {
86
- V as ScreenDivider,
87
- V as default
77
+ Z as ScreenDivider,
78
+ Z as default
88
79
  };
89
80
  //# sourceMappingURL=screenDivider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"screenDivider.js","sources":["../../../../src/components/layout/screenDivider/screenDivider.tsx"],"sourcesContent":["import React, {\n Children,\n forwardRef,\n KeyboardEvent,\n PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport cn from \"clsx\";\nimport { throttle } from \"../../../utils/throttle\";\nimport { useForkRef } from \"../../../hooks/useForkRef\";\n\nexport interface ScreenDividerProps {\n sizeFirst?: number;\n sizeSecond?: number;\n className?: string;\n orientation?: \"horizontal\" | \"vertical\";\n /** Called with the first pane size (percent) whenever it changes. */\n onSizeChange?: (sizeFirst: number) => void;\n /** Step (in percent) applied on arrow-key resize. */\n keyboardStep?: number;\n /** Accessible label for the resizer handle. */\n resizerAriaLabel?: string;\n}\n\nconst toPixels = (percent: number, parentSize: number) => {\n return parentSize * (percent / 100);\n};\n\nconst getInitialDivider = (sizeFirst?: number | null, sizeSecond?: number | null) => {\n if (!sizeFirst && sizeSecond) {\n return 100 - sizeSecond;\n }\n if (sizeFirst) {\n return sizeFirst;\n }\n return 50;\n};\n\nexport const ScreenDivider = forwardRef<HTMLDivElement, PropsWithChildren<ScreenDividerProps>>(function ScreenDivider(\n {\n className,\n orientation = \"horizontal\",\n sizeFirst,\n sizeSecond,\n children,\n onSizeChange,\n keyboardStep = 5,\n resizerAriaLabel = \"Resize panels\",\n },\n ref\n) {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const forkedWrapperRef = useForkRef<HTMLDivElement>(ref, wrapperRef);\n const [divider, setDivider] = useState<number>(getInitialDivider(sizeFirst, sizeSecond));\n const [currentElement, setCurrentElement] = useState<HTMLDivElement | null>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n useEffect(() => {\n setDivider(getInitialDivider(sizeFirst, sizeSecond));\n }, [sizeFirst, sizeSecond]);\n\n const child = Children.toArray(children);\n if (child.length > 2) {\n throw new Error(\"Allowed not more than 2 children\");\n }\n\n const handleDragStart = () => {\n setCurrentElement(wrapperRef.current);\n setIsDragging(true);\n };\n\n const dragOverHandler = useMemo(\n () =>\n throttle((e: PointerEvent) => {\n if (!isDragging) return;\n\n const wrapper = wrapperRef.current;\n if (!wrapper || wrapper !== currentElement) return;\n if (orientation === \"vertical\") {\n let relativeMouseY = e.clientY - wrapper.offsetTop;\n if (relativeMouseY < 0) {\n relativeMouseY = 0;\n }\n const newDivider = (relativeMouseY / wrapper.clientHeight) * 100;\n if (toPixels(newDivider, wrapper.clientWidth) > 5 && newDivider < 101) {\n setDivider(newDivider - 7);\n }\n } else {\n let relativeMouseX = e.clientX - wrapper.offsetLeft;\n if (relativeMouseX < 0) {\n relativeMouseX = 0;\n }\n const newDivider = (relativeMouseX / wrapper.clientWidth) * 100;\n if (toPixels(newDivider, wrapper.clientWidth) > 5 && newDivider < 101) {\n setDivider(newDivider);\n }\n }\n }, 1000 / 60),\n [isDragging, currentElement, orientation]\n );\n\n const handleDragEnd = useCallback(() => {\n setCurrentElement(null);\n setIsDragging(false);\n document.body.removeEventListener(\"pointerup\", handleDragEnd);\n document.body.removeEventListener(\"pointermove\", dragOverHandler);\n }, [dragOverHandler]);\n\n useEffect(() => {\n onSizeChange?.(divider);\n }, [divider, onSizeChange]);\n\n const onResizerKeyDown = (event: KeyboardEvent<HTMLSpanElement>) => {\n const decreaseKey = orientation === \"vertical\" ? \"ArrowUp\" : \"ArrowLeft\";\n const increaseKey = orientation === \"vertical\" ? \"ArrowDown\" : \"ArrowRight\";\n\n if (event.key === decreaseKey) {\n event.preventDefault();\n setDivider((prev) => Math.max(0, prev - keyboardStep));\n } else if (event.key === increaseKey) {\n event.preventDefault();\n setDivider((prev) => Math.min(100, prev + keyboardStep));\n } else if (event.key === \"Home\") {\n event.preventDefault();\n setDivider(0);\n } else if (event.key === \"End\") {\n event.preventDefault();\n setDivider(100);\n }\n };\n\n const secondChildStyle =\n orientation === \"vertical\" ? { height: `${100 - divider}%` } : { width: `${100 - divider}%` };\n\n const firstChildStyle = orientation === \"vertical\" ? { height: `${divider}%` } : { width: `${divider}%` };\n\n useEffect(() => {\n if (isDragging) {\n document.body.addEventListener(\"pointerup\", handleDragEnd);\n document.body.addEventListener(\"pointermove\", dragOverHandler);\n document.body.style.cursor = orientation === \"horizontal\" ? \"e-resize\" : \"n-resize\";\n } else {\n document.body.style.cursor = \"default\";\n }\n\n return () => {\n document.body.removeEventListener(\"pointerup\", handleDragEnd);\n document.body.removeEventListener(\"pointermove\", dragOverHandler);\n };\n }, [dragOverHandler, handleDragEnd, isDragging, orientation]);\n\n return (\n <div\n className={cn(\"smwb-screen-divider__wrapper\", `smwb-${orientation}`, className)}\n ref={forkedWrapperRef}\n data-testid=\"screen-divider\"\n >\n <div className={cn(\"smwb-screen-divider__first\", `smwb-${orientation}`)} style={firstChildStyle}>\n {child[0] || \"\"}\n </div>\n <span\n className=\"smwb-screen-divider__resizer\"\n onPointerDown={handleDragStart}\n draggable={false}\n role=\"separator\"\n aria-orientation={orientation === \"vertical\" ? \"horizontal\" : \"vertical\"}\n aria-valuenow={Math.round(divider)}\n aria-valuemin={0}\n aria-valuemax={100}\n aria-label={resizerAriaLabel}\n tabIndex={0}\n onKeyDown={onResizerKeyDown}\n />\n <div className={cn(\"smwb-screen-divider__second\", `smwb-${orientation}`)} style={secondChildStyle}>\n {child[1] || \"\"}\n </div>\n </div>\n );\n});\n\nexport default ScreenDivider;\n"],"names":["toPixels","percent","parentSize","getInitialDivider","sizeFirst","sizeSecond","ScreenDivider","forwardRef","className","orientation","children","onSizeChange","keyboardStep","resizerAriaLabel","ref","wrapperRef","useRef","forkedWrapperRef","useForkRef","divider","setDivider","useState","currentElement","setCurrentElement","isDragging","setIsDragging","useEffect","child","Children","handleDragStart","dragOverHandler","useMemo","throttle","e","wrapper","relativeMouseY","newDivider","relativeMouseX","handleDragEnd","useCallback","onResizerKeyDown","event","decreaseKey","increaseKey","prev","secondChildStyle","firstChildStyle","jsxs","cn","jsx"],"mappings":";;;;;;AA6BA,MAAMA,IAAW,CAACC,GAAiBC,MAC1BA,KAAcD,IAAU,MAG3BE,IAAoB,CAACC,GAA2BC,MAChD,CAACD,KAAaC,IACT,MAAMA,IAEXD,KAGG,IAGIE,IAAgBC,EAAkE,SAC7F;AAAA,EACE,WAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,WAAAL;AAAA,EACA,YAAAC;AAAA,EACA,UAAAK;AAAA,EACA,cAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,kBAAAC,IAAmB;AACrB,GACAC,GACA;AACA,QAAMC,IAAaC,EAAuB,IAAI,GACxCC,IAAmBC,EAA2BJ,GAAKC,CAAU,GAC7D,CAACI,GAASC,CAAU,IAAIC,EAAiBlB,EAAkBC,GAAWC,CAAU,CAAC,GACjF,CAACiB,GAAgBC,CAAiB,IAAIF,EAAgC,IAAI,GAC1E,CAACG,GAAYC,CAAa,IAAIJ,EAAS,EAAK;AAElD,EAAAK,EAAU,MAAM;AACd,IAAAN,EAAWjB,EAAkBC,GAAWC,CAAU,CAAC;AAAA,EACrD,GAAG,CAACD,GAAWC,CAAU,CAAC;AAE1B,QAAMsB,IAAQC,EAAS,QAAQlB,CAAQ;AACvC,MAAIiB,EAAM,SAAS;AACjB,UAAM,IAAI,MAAM,kCAAkC;AAGpD,QAAME,IAAkB,MAAM;AAC5B,IAAAN,EAAkBR,EAAW,OA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AAAA,YACL,oBAAkBpB,MAAgB,aAAa,eAAe;AAAA,YAC9D,iBAAe,KAAK,MAAMU,CAAO;AAAA,YACjC,iBAAe;AAAA,YACf,iBAAe;AAAA,YACf,cAAYN;AAAA,YACZ,UAAU;AAAA,YACV,WAAW2B;AAAA,UAAA;AAAA,QAAA;AAAA,QAEb,gBAAAS,EAAC,OAAA,EAAI,WAAWD,EAAG,+BAA+B,QAAQvC,CAAW,EAAE,GAAG,OAAOoC,GAC9E,UAAAlB,EAAM,CAAC,KAAK,GAAA,CACf;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN,CAAC;"}
1
+ {"version":3,"file":"screenDivider.js","sources":["../../../../src/components/layout/screenDivider/screenDivider.tsx"],"sourcesContent":["import React, {\n Children,\n forwardRef,\n KeyboardEvent,\n PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport cn from \"clsx\";\nimport { throttle } from \"../../../utils/throttle\";\nimport { useForkRef } from \"../../../hooks/useForkRef\";\n\nexport interface ScreenDividerProps {\n sizeFirst?: number;\n sizeSecond?: number;\n className?: string;\n orientation?: \"horizontal\" | \"vertical\";\n /** Called with the first pane size (percent) whenever it changes. */\n onSizeChange?: (sizeFirst: number) => void;\n /** Step (in percent) applied on arrow-key resize. */\n keyboardStep?: number;\n /** Accessible label for the resizer handle. */\n resizerAriaLabel?: string;\n}\n\nconst getInitialDivider = (sizeFirst?: number | null, sizeSecond?: number | null) => {\n if (!sizeFirst && sizeSecond) {\n return 100 - sizeSecond;\n }\n if (sizeFirst) {\n return sizeFirst;\n }\n return 50;\n};\n\nexport const ScreenDivider = forwardRef<HTMLDivElement, PropsWithChildren<ScreenDividerProps>>(function ScreenDivider(\n {\n className,\n orientation = \"horizontal\",\n sizeFirst,\n sizeSecond,\n children,\n onSizeChange,\n keyboardStep = 5,\n resizerAriaLabel = \"Resize panels\",\n },\n ref\n) {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const forkedWrapperRef = useForkRef<HTMLDivElement>(ref, wrapperRef);\n const [divider, setDivider] = useState<number>(getInitialDivider(sizeFirst, sizeSecond));\n const [currentElement, setCurrentElement] = useState<HTMLDivElement | null>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n useEffect(() => {\n setDivider(getInitialDivider(sizeFirst, sizeSecond));\n }, [sizeFirst, sizeSecond]);\n\n const child = Children.toArray(children);\n if (child.length > 2) {\n throw new Error(\"Allowed not more than 2 children\");\n }\n\n const handleDragStart = () => {\n setCurrentElement(wrapperRef.current);\n setIsDragging(true);\n };\n\n const dragOverHandler = useMemo(\n () =>\n throttle((e: PointerEvent) => {\n if (!isDragging) return;\n const wrapper = wrapperRef.current;\n if (!wrapper || wrapper !== currentElement) return;\n // Viewport-relative rect — using offsetLeft/offsetTop here is wrong\n // because they are relative to the nearest positioned ancestor, not\n // the viewport that clientX/clientY live in (this is what made the\n // divider drift away from the cursor when the wrapper was nested).\n const rect = wrapper.getBoundingClientRect();\n const total = orientation === \"vertical\" ? rect.height : rect.width;\n const cursor = orientation === \"vertical\" ? e.clientY - rect.top : e.clientX - rect.left;\n // 5px margin on each side so neither pane fully collapses.\n const clamped = Math.max(5, Math.min(total - 5, cursor));\n setDivider((clamped / total) * 100);\n }, 1000 / 60),\n [isDragging, currentElement, orientation]\n );\n\n const handleDragEnd = useCallback(() => {\n setCurrentElement(null);\n setIsDragging(false);\n document.body.removeEventListener(\"pointerup\", handleDragEnd);\n document.body.removeEventListener(\"pointermove\", dragOverHandler);\n }, [dragOverHandler]);\n\n useEffect(() => {\n onSizeChange?.(divider);\n }, [divider, onSizeChange]);\n\n const onResizerKeyDown = (event: KeyboardEvent<HTMLSpanElement>) => {\n const decreaseKey = orientation === \"vertical\" ? \"ArrowUp\" : \"ArrowLeft\";\n const increaseKey = orientation === \"vertical\" ? \"ArrowDown\" : \"ArrowRight\";\n\n if (event.key === decreaseKey) {\n event.preventDefault();\n setDivider((prev) => Math.max(0, prev - keyboardStep));\n } else if (event.key === increaseKey) {\n event.preventDefault();\n setDivider((prev) => Math.min(100, prev + keyboardStep));\n } else if (event.key === \"Home\") {\n event.preventDefault();\n setDivider(0);\n } else if (event.key === \"End\") {\n event.preventDefault();\n setDivider(100);\n }\n };\n\n const secondChildStyle =\n orientation === \"vertical\" ? { height: `${100 - divider}%` } : { width: `${100 - divider}%` };\n\n const firstChildStyle = orientation === \"vertical\" ? { height: `${divider}%` } : { width: `${divider}%` };\n\n useEffect(() => {\n if (isDragging) {\n document.body.addEventListener(\"pointerup\", handleDragEnd);\n document.body.addEventListener(\"pointermove\", dragOverHandler);\n document.body.style.cursor = orientation === \"horizontal\" ? \"e-resize\" : \"n-resize\";\n } else {\n document.body.style.cursor = \"default\";\n }\n\n return () => {\n document.body.removeEventListener(\"pointerup\", handleDragEnd);\n document.body.removeEventListener(\"pointermove\", dragOverHandler);\n };\n }, [dragOverHandler, handleDragEnd, isDragging, orientation]);\n\n return (\n <div\n className={cn(\"smwb-screen-divider__wrapper\", `smwb-${orientation}`, className)}\n ref={forkedWrapperRef}\n data-testid=\"screen-divider\"\n >\n <div className={cn(\"smwb-screen-divider__first\", `smwb-${orientation}`)} style={firstChildStyle}>\n {child[0] || \"\"}\n </div>\n <span\n className=\"smwb-screen-divider__resizer\"\n onPointerDown={handleDragStart}\n draggable={false}\n role=\"separator\"\n aria-orientation={orientation === \"vertical\" ? \"horizontal\" : \"vertical\"}\n aria-valuenow={Math.round(divider)}\n aria-valuemin={0}\n aria-valuemax={100}\n aria-label={resizerAriaLabel}\n tabIndex={0}\n onKeyDown={onResizerKeyDown}\n />\n <div className={cn(\"smwb-screen-divider__second\", `smwb-${orientation}`)} style={secondChildStyle}>\n {child[1] || \"\"}\n </div>\n </div>\n );\n});\n\nexport default ScreenDivider;\n"],"names":["getInitialDivider","sizeFirst","sizeSecond","ScreenDivider","forwardRef","className","orientation","children","onSizeChange","keyboardStep","resizerAriaLabel","ref","wrapperRef","useRef","forkedWrapperRef","useForkRef","divider","setDivider","useState","currentElement","setCurrentElement","isDragging","setIsDragging","useEffect","child","Children","handleDragStart","dragOverHandler","useMemo","throttle","e","wrapper","rect","total","cursor","clamped","handleDragEnd","useCallback","onResizerKeyDown","event","decreaseKey","increaseKey","prev","secondChildStyle","firstChildStyle","jsxs","cn","jsx"],"mappings":";;;;;;AA6BA,MAAMA,IAAoB,CAACC,GAA2BC,MAChD,CAACD,KAAaC,IACT,MAAMA,IAEXD,KAGG,IAGIE,IAAgBC,EAAkE,SAC7F;AAAA,EACE,WAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,WAAAL;AAAA,EACA,YAAAC;AAAA,EACA,UAAAK;AAAA,EACA,cAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,kBAAAC,IAAmB;AACrB,GACAC,GACA;AACA,QAAMC,IAAaC,EAAuB,IAAI,GACxCC,IAAmBC,EAA2BJ,GAAKC,CAAU,GAC7D,CAACI,GAASC,CAAU,IAAIC,EAAiBlB,EAAkBC,GAAWC,CAAU,CAAC,GACjF,CAACiB,GAAgBC,CAAiB,IAAIF,EAAgC,IAAI,GAC1E,CAACG,GAAYC,CAAa,IAAIJ,EAAS,EAAK;AAElD,EAAAK,EAAU,MAAM;AACd,IAAAN,EAAWjB,EAAkBC,GAAWC,CAAU,CAAC;AAAA,EACrD,GAAG,CAACD,GAAWC,CAAU,CAAC;AAE1B,QAAMsB,IAAQC,EAAS,QAAQlB,CAAQ;AACvC,MAAIiB,EAAM,SAAS;AACjB,UAAM,IAAI,MAAM,kCAAkC;AAGpD,QAAME,IAAkB,MAAM;AAC5B,IAAAN,EAAkBR,EAAW,OAAO,GACpCU,EAAc,EAAI;AAAA,EACpB,GAEMK,IAAkBC;AAAA,IACtB,MACEC,EAAS,CAACC,MAAoB;AAC5B,UAAI,CAACT,EAAY;AACjB,YAAMU,IAAUnB,EAAW;AAC3B,UAAI,CAACmB,KAAWA,MAAYZ,EAAgB;AAK5C,YAAMa,IAAOD,EAAQ,sBAAA,GACfE,IAAQ3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from "react/jsx-runtime";
2
- import X, { forwardRef as pt, useState as k, useRef as y, useId as xt, useEffect as It } from "react";
3
- import v from "clsx";
4
- import { useForkRef as Mt } from "../../../hooks/useForkRef.js";
5
- import { dragPrevent as Q, getStartSlide as Nt, getSlidesToShow as St, isMouseEvent as U, coordX as V, coordY as Z, getSlideStyle as Et, isTouchEvent as yt, getSlideWidth as At, getSlideIndexForMultipleParts as H } from "./utils.js";
6
- import { useSafeLayoutEffect as z } from "../../../hooks/useSafeLayoutEffect.js";
7
- import { useEventCallback as Y } from "../../../hooks/useEventCallback.js";
8
- import { Icon as C } from "../../base/icon/icon.js";
9
- const gt = {
1
+ import { jsx as a, Fragment as ie, jsxs as j } from "react/jsx-runtime";
2
+ import O, { forwardRef as Oe, useState as x, useRef as T, useId as ze, useEffect as ue } from "react";
3
+ import m from "clsx";
4
+ import { useForkRef as Be } from "../../../hooks/useForkRef.js";
5
+ import { dragPrevent as de, getStartSlide as He, getSlidesToShow as Ke, isMouseEvent as fe, coordX as z, coordY as me, getSlideStyle as Ge, isTouchEvent as qe, getSlideWidth as Je, clamp as Qe, toCssLength as B, toCssNumber as Ue, getSlideIndexForMultipleParts as he } from "./utils.js";
6
+ import { useSafeLayoutEffect as _e } from "../../../hooks/useSafeLayoutEffect.js";
7
+ import { useEventCallback as H } from "../../../hooks/useEventCallback.js";
8
+ import { Icon as E } from "../../base/icon/icon.js";
9
+ import { Modal as Ze } from "../../feedBack/modal/modal.js";
10
+ const et = {
10
11
  isPressed: !1,
11
12
  startX: 0,
12
- startY: 0
13
- }, jt = pt(function({
14
- slidesToShow: tt = 3,
15
- startSlide: et = 0,
16
- children: h,
17
- className: st,
18
- showNavigation: rt = !0,
19
- showArrows: ot,
20
- arrowsSize: f = 30,
21
- navigationClassName: nt,
22
- onSlideChange: i,
23
- navigationDotRenderer: R,
24
- "aria-label": it = "Carousel",
25
- autoplay: D = !1,
26
- autoplayInterval: W = 4e3,
27
- pauseOnHover: b = !0
28
- }, ct) {
29
- const r = X.Children.count(h), s = St(tt, r), p = Nt(et, r), $ = ot && r > 1, [c, A] = k(p), [j, x] = k({
13
+ startY: 0,
14
+ lastX: 0,
15
+ lastT: 0,
16
+ axis: null,
17
+ dragged: !1
18
+ }, we = 8, tt = 0.4, mt = Oe(function({
19
+ slidesToShow: ve = 3,
20
+ startSlide: ge = 0,
21
+ children: w,
22
+ className: be,
23
+ showNavigation: xe = !0,
24
+ showArrows: pe,
25
+ arrowsSize: v = 30,
26
+ navigationClassName: Se,
27
+ onSlideChange: g,
28
+ navigationDotRenderer: K,
29
+ "aria-label": Ie = "Carousel",
30
+ autoplay: G = !1,
31
+ autoplayInterval: q = 4e3,
32
+ pauseOnHover: M = !0,
33
+ cellHeight: ye,
34
+ aspectRatio: Ne,
35
+ gap: Te,
36
+ maxWidth: Ee,
37
+ enableFullscreen: k = !1
38
+ }, Me) {
39
+ const s = O.Children.count(w), n = Ke(ve, s), L = He(ge, s), J = pe && s > 1, X = Math.max(0, s - n), [l, Q] = x(L), [Y, $] = x({
30
40
  animation: void 0
31
- }), g = y(null), at = y(null), lt = Mt(ct, at), a = y(null), [F, B] = k(!1), P = y(gt);
32
- z(() => {
33
- x((t) => ({
34
- ...t,
41
+ }), [ke, U] = x(0), [Le, Z] = x(!1), [h, A] = x(null), P = T(null), Xe = T(null), Ae = Be(Me, Xe), f = T(null), [ee, te] = x(!1), i = T({ ...et });
42
+ _e(() => {
43
+ $((e) => ({
44
+ ...e,
35
45
  animation: !1
36
46
  }));
37
- }, [s]), z(() => {
38
- A(p), i == null || i(p), j.animation !== void 0 && x((t) => ({
39
- ...t,
47
+ }, [n]), _e(() => {
48
+ Q(L), g == null || g(L), Y.animation !== void 0 && $((e) => ({
49
+ ...e,
40
50
  animation: !0
41
51
  }));
42
- }, [p]);
43
- const L = (t) => {
44
- Object.assign(P.current, t);
45
- }, G = Y((t) => {
46
- if (r <= 1 || !a.current)
52
+ }, [L]);
53
+ const F = (e) => {
54
+ Object.assign(i.current, e);
55
+ }, V = () => typeof performance != "undefined" ? performance.now() : Date.now(), se = (e) => {
56
+ const t = Qe(e, 0, X);
57
+ Q(t), $((r) => ({ ...r, animation: !0 })), g == null || g(t);
58
+ }, p = (e) => {
59
+ A((t) => t === null ? t : (t + e + s) % s);
60
+ }, S = T(null), Pe = (e) => {
61
+ f.current && (f.current.removeEventListener(e ? "mousemove" : "touchmove", ne), f.current.removeEventListener(e ? "mouseup" : "touchend", b), e && f.current.removeEventListener("mouseleave", b));
62
+ }, re = H((e) => {
63
+ if (!f.current)
47
64
  return;
48
- const e = U(t);
49
- if (e && t.button !== 0)
65
+ const t = fe(e);
66
+ if (t && e.button !== 0)
50
67
  return;
51
- t.stopPropagation();
52
- const l = V(t), u = Z(t);
53
- L({
68
+ e.stopPropagation();
69
+ const r = z(e), o = me(e);
70
+ F({
54
71
  isPressed: !0,
55
- startX: l,
56
- startY: u
57
- }), a.current.addEventListener(e ? "mousemove" : "touchmove", O), a.current.addEventListener(e ? "mouseup" : "touchend", _), e && a.current.addEventListener("mouseleave", _);
58
- }), O = Y((t) => {
59
- if (!g.current)
72
+ startX: r,
73
+ startY: o,
74
+ lastX: r,
75
+ lastT: V(),
76
+ axis: null,
77
+ dragged: !1
78
+ }), f.current.addEventListener(t ? "mousemove" : "touchmove", ne, { passive: !1 }), f.current.addEventListener(t ? "mouseup" : "touchend", b), t && f.current.addEventListener("mouseleave", b);
79
+ }), ne = H((e) => {
80
+ if (!P.current || !i.current.isPressed)
60
81
  return;
61
- const { isPressed: e, startX: l, startY: u } = P.current;
62
- if (!e)
63
- return;
64
- if (t.preventDefault(), t.stopPropagation(), yt(t) && t.touches.length > 1)
65
- return _(t);
66
- const o = V(t), m = Z(t), d = o - l, M = m - u, w = Math.abs(d), N = Math.abs(M);
67
- if (w < N)
68
- return;
69
- const S = g.current.offsetWidth / s, ht = s === 1 ? 1.95 : 1.4;
70
- if (w % S > S / ht) {
71
- const _t = d < 0 ? 1 : -1, wt = r - s, E = c + _t;
72
- if (E < 0 || E > wt)
82
+ if (qe(e) && e.touches.length > 1)
83
+ return b(e);
84
+ const t = z(e), r = me(e), o = t - i.current.startX, c = r - i.current.startY;
85
+ if (i.current.axis === null) {
86
+ if (Math.abs(o) < we && Math.abs(c) < we)
73
87
  return;
74
- A(E), x((bt) => ({ ...bt, animation: !0 })), L({ startX: o, startY: m }), i == null || i(E);
88
+ const u = Math.abs(o) >= Math.abs(c) ? "x" : "y";
89
+ if (F({ axis: u, dragged: !0 }), u === "y")
90
+ return b(e);
91
+ s > 1 && Z(!0);
75
92
  }
76
- }), _ = Y((t) => {
77
- if (!a.current || !P.current.isPressed)
93
+ if (i.current.axis === "x") {
94
+ if (e.preventDefault(), e.stopPropagation(), s > 1) {
95
+ const u = l <= 0, d = l >= X, _ = u && o > 0 || d && o < 0 ? o * 0.35 : o;
96
+ U(_);
97
+ }
98
+ i.current.lastX = t, i.current.lastT = V();
99
+ }
100
+ }), b = H((e) => {
101
+ if (!i.current.isPressed)
78
102
  return;
79
- L({ isPressed: !1 });
80
- const e = U(t);
81
- a.current.removeEventListener(e ? "mousemove" : "touchmove", O), a.current.removeEventListener(e ? "mouseup" : "touchend", _), e && a.current.removeEventListener("mouseleave", _);
82
- }), I = (t) => () => {
83
- A(t), x((e) => ({ ...e, animation: !0 })), i == null || i(t);
84
- }, T = (t) => {
85
- const e = s === 1, l = e ? r : Math.ceil(r / s), u = c + s, o = r - s <= c, d = (H(u, s, r, o) + t + l) % l;
86
- return e ? d : d * s;
87
- }, ut = () => {
88
- if (!rt)
89
- return /* @__PURE__ */ n(J, {});
90
- const t = r - s <= c, e = s === 1, l = e ? r : Math.ceil(r / s), u = [];
91
- for (let o = 0; o < l; o++) {
92
- let m = o, d = c;
93
- if (!e) {
94
- const q = o === l - 1, S = c + s;
95
- m = q ? r - s : o * s, d = H(S, s, r, t);
103
+ const t = fe(e);
104
+ Pe(t);
105
+ const { axis: r, dragged: o, startX: c, lastX: u, lastT: d } = i.current;
106
+ if (F({ isPressed: !1 }), Z(!1), r === "x" && o && s > 1 && P.current) {
107
+ const _ = z(e), D = _ - c, y = P.current.offsetWidth / n, R = d ? (_ - u) / Math.max(1, V() - d) : 0;
108
+ let N = y > 0 ? Math.round(-D / y) : 0;
109
+ N === 0 && Math.abs(R) > tt && (N = R < 0 ? 1 : -1), se(l + N);
110
+ }
111
+ U(0);
112
+ }), Ce = (e) => () => {
113
+ i.current.dragged || k && A(e);
114
+ }, C = (e) => () => se(e), W = (e) => {
115
+ const t = n === 1, r = t ? s : Math.ceil(s / n), o = l + n, c = s - n <= l, d = (he(o, n, s, c) + e + r) % r;
116
+ return t ? d : d * n;
117
+ }, De = () => {
118
+ if (!xe)
119
+ return /* @__PURE__ */ a(ie, {});
120
+ const e = s - n <= l, t = n === 1, r = t ? s : Math.ceil(s / n), o = [];
121
+ for (let c = 0; c < r; c++) {
122
+ let u = c, d = l;
123
+ if (!t) {
124
+ const R = c === r - 1, N = l + n;
125
+ u = R ? s - n : c * n, d = he(N, n, s, e);
96
126
  }
97
- const M = d === o, w = I(m);
98
- let N = /* @__PURE__ */ n("div", { className: v("smwb-carousel__navigation__dot", M && "current"), onClick: w }, o);
99
- R && (N = R(o, M, w)), u.push(N);
127
+ const _ = d === c, D = C(u);
128
+ let y = /* @__PURE__ */ a("div", { className: m("smwb-carousel__navigation__dot", _ && "current"), onClick: D }, c);
129
+ K && (y = K(c, _, D)), o.push(y);
100
130
  }
101
- return /* @__PURE__ */ n("div", { className: v("smwb-carousel__navigation", nt), children: u });
102
- }, dt = () => {
103
- const t = r - s, e = c > t ? t : c;
104
- return At(s) * e;
105
- }, ft = xt(), mt = Et(s), vt = {
106
- transform: `translateX(-${dt()}%)`,
107
- transition: j.animation ? "transform 500ms cubic-bezier(.1, 0, .25, 1)" : "none"
108
- };
109
- return X.useEffect(() => {
110
- Array.isArray(h) || console.error("SMWB Material: The `children` prop was passed invalidly. It should contain an array of elements.");
111
- }, [h]), It(() => {
112
- if (!D || r <= 1 || b && F)
131
+ return /* @__PURE__ */ a("div", { className: m("smwb-carousel__navigation", Se), children: o });
132
+ }, Re = () => {
133
+ const e = l > X ? X : l;
134
+ return Je(n) * e;
135
+ }, Ye = ze(), $e = Ge(n), Fe = {
136
+ transform: `translateX(calc(-${Re()}% + ${ke}px))`,
137
+ transition: Le || Y.animation === void 0 ? "none" : Y.animation ? "transform 500ms cubic-bezier(.1, 0, .25, 1)" : "none"
138
+ }, I = {}, oe = B(ye), ce = Ue(Ne), ae = B(Te), le = B(Ee);
139
+ if (oe && (I["--smwb-carousel-cell-height"] = oe), ce && (I["--smwb-carousel-aspect-ratio"] = ce), ae && (I["--smwb-carousel-gap"] = ae), le && (I["--smwb-carousel-max-width"] = le), O.useEffect(() => {
140
+ Array.isArray(w) || console.error("SMWB Material: The `children` prop was passed invalidly. It should contain an array of elements.");
141
+ }, [w]), ue(() => {
142
+ if (!G || s <= 1 || M && ee || h !== null)
143
+ return;
144
+ const e = window.setInterval(() => {
145
+ C(W(1))();
146
+ }, q);
147
+ return () => window.clearInterval(e);
148
+ }, [
149
+ G,
150
+ q,
151
+ M,
152
+ ee,
153
+ s,
154
+ l,
155
+ n,
156
+ h
157
+ ]), ue(() => {
158
+ if (h === null || s <= 1)
113
159
  return;
114
- const t = window.setInterval(() => {
115
- I(T(1))();
116
- }, W);
117
- return () => window.clearInterval(t);
118
- }, [D, W, b, F, r, c, s]), Array.isArray(h) ? /* @__PURE__ */ K(
160
+ const e = (t) => {
161
+ t.key === "ArrowLeft" ? p(-1) : t.key === "ArrowRight" && p(1);
162
+ };
163
+ return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
164
+ }, [h, s]), !Array.isArray(w))
165
+ return /* @__PURE__ */ a(ie, {});
166
+ const Ve = w, We = (e) => {
167
+ var t, r;
168
+ S.current = (r = (t = e.touches[0]) == null ? void 0 : t.clientX) != null ? r : null;
169
+ }, je = (e) => {
170
+ var r, o;
171
+ if (S.current === null || s <= 1)
172
+ return;
173
+ const t = ((o = (r = e.changedTouches[0]) == null ? void 0 : r.clientX) != null ? o : S.current) - S.current;
174
+ S.current = null, Math.abs(t) > 40 && p(t < 0 ? 1 : -1);
175
+ };
176
+ return /* @__PURE__ */ j(
119
177
  "div",
120
178
  {
121
- className: v("smwb-carousel", st),
179
+ className: m("smwb-carousel", be),
122
180
  "data-testid": "carousel",
123
- ref: lt,
181
+ ref: Ae,
124
182
  role: "region",
125
183
  "aria-roledescription": "carousel",
126
- "aria-label": it,
127
- onMouseEnter: b ? () => B(!0) : void 0,
128
- onMouseLeave: b ? () => B(!1) : void 0,
184
+ "aria-label": Ie,
185
+ style: I,
186
+ onMouseEnter: M ? () => te(!0) : void 0,
187
+ onMouseLeave: M ? () => te(!1) : void 0,
129
188
  children: [
130
- /* @__PURE__ */ K("div", { className: v("smwb-carousel__inner"), ref: g, children: [
131
- $ && /* @__PURE__ */ n(
132
- C,
189
+ /* @__PURE__ */ j("div", { className: m("smwb-carousel__inner"), ref: P, children: [
190
+ J && /* @__PURE__ */ a(
191
+ E,
133
192
  {
134
193
  name: "chevron_left",
135
- size: f,
136
- className: v("smwb-carousel__arrow", "smwb-carousel__arrow_prev"),
194
+ size: v,
195
+ className: m("smwb-carousel__arrow", "smwb-carousel__arrow_prev"),
137
196
  style: {
138
- top: `calc(50% - ${f / 2}px)`,
139
- left: -f / 2
197
+ top: `calc(50% - ${v / 2}px)`,
198
+ left: -v / 2
140
199
  },
141
- onClick: () => I(T(-1))()
200
+ onClick: () => C(W(-1))()
142
201
  }
143
202
  ),
144
- /* @__PURE__ */ n(
203
+ /* @__PURE__ */ a(
145
204
  "div",
146
205
  {
147
- ref: a,
206
+ ref: f,
148
207
  className: "smwb-carousel__track",
149
- onMouseDown: G,
150
- onTouchStart: G,
151
- onDragStart: Q,
152
- onDragEnd: Q,
153
- children: /* @__PURE__ */ n("div", { className: "smwb-carousel__layer", style: vt, children: X.Children.map(h, (t, e) => /* @__PURE__ */ n("div", { id: `${ft}${e}`, className: "smwb-carousel__slide", style: mt, children: /* @__PURE__ */ n("div", { className: "smwb-carousel__slide-inner", children: t }) }, e)) })
208
+ onMouseDown: re,
209
+ onTouchStart: re,
210
+ onDragStart: de,
211
+ onDragEnd: de,
212
+ children: /* @__PURE__ */ a("div", { className: "smwb-carousel__layer", style: Fe, children: O.Children.map(w, (e, t) => /* @__PURE__ */ a("div", { id: `${Ye}${t}`, className: "smwb-carousel__slide", style: $e, children: /* @__PURE__ */ a(
213
+ "div",
214
+ {
215
+ className: m(
216
+ "smwb-carousel__slide-inner",
217
+ k && "smwb-carousel__slide-inner_clickable"
218
+ ),
219
+ onClick: k ? Ce(t) : void 0,
220
+ children: e
221
+ }
222
+ ) }, t)) })
154
223
  }
155
224
  ),
156
- $ && /* @__PURE__ */ n(
157
- C,
225
+ J && /* @__PURE__ */ a(
226
+ E,
158
227
  {
159
228
  name: "chevron_right",
160
- size: f,
161
- className: v("smwb-carousel__arrow", "smwb-carousel__arrow_next"),
229
+ size: v,
230
+ className: m("smwb-carousel__arrow", "smwb-carousel__arrow_next"),
162
231
  style: {
163
- top: `calc(50% - ${f / 2}px)`,
164
- right: -f / 2
232
+ top: `calc(50% - ${v / 2}px)`,
233
+ right: -v / 2
165
234
  },
166
- onClick: () => I(T(1))()
235
+ onClick: () => C(W(1))()
167
236
  }
168
237
  )
169
238
  ] }),
170
- ut()
239
+ De(),
240
+ k && /* @__PURE__ */ a(
241
+ Ze,
242
+ {
243
+ open: h !== null,
244
+ size: "fullscreen",
245
+ backdrop: "darkBlured",
246
+ className: "smwb-carousel__fullscreen",
247
+ onClose: () => A(null),
248
+ "aria-label": "Image viewer",
249
+ children: h !== null && /* @__PURE__ */ j("div", { className: "smwb-carousel__fullscreen-content", children: [
250
+ s > 1 && /* @__PURE__ */ a(
251
+ E,
252
+ {
253
+ name: "chevron_left",
254
+ size: 40,
255
+ className: m("smwb-carousel__fullscreen-arrow", "smwb-carousel__fullscreen-arrow_prev"),
256
+ onClick: () => p(-1)
257
+ }
258
+ ),
259
+ /* @__PURE__ */ a(
260
+ "div",
261
+ {
262
+ className: "smwb-carousel__fullscreen-stage",
263
+ onTouchStart: We,
264
+ onTouchEnd: je,
265
+ children: Ve[h]
266
+ }
267
+ ),
268
+ s > 1 && /* @__PURE__ */ a(
269
+ E,
270
+ {
271
+ name: "chevron_right",
272
+ size: 40,
273
+ className: m("smwb-carousel__fullscreen-arrow", "smwb-carousel__fullscreen-arrow_next"),
274
+ onClick: () => p(1)
275
+ }
276
+ ),
277
+ /* @__PURE__ */ a(
278
+ E,
279
+ {
280
+ name: "close",
281
+ size: 32,
282
+ className: "smwb-carousel__fullscreen-close",
283
+ onClick: () => A(null)
284
+ }
285
+ )
286
+ ] })
287
+ }
288
+ )
171
289
  ]
172
290
  }
173
- ) : /* @__PURE__ */ n(J, {});
291
+ );
174
292
  });
175
293
  export {
176
- jt as Carousel
294
+ mt as Carousel
177
295
  };
178
296
  //# sourceMappingURL=carousel.js.map