@dotss/tictoccroc 0.11.0 → 0.11.2

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,58 +1,59 @@
1
- import e from "./CarouselSlide/index.mjs";
2
- import { Children as t, cloneElement as n, isValidElement as r, useCallback as i, useEffect as a, useRef as o, useState as s } from "react";
3
- import { Flexbox as c } from "@dotss/ui";
4
- import l from "@dotss/ui/core/useTheme";
5
- import { jsx as u, jsxs as d } from "react/jsx-runtime";
1
+ import { getCarouselSwipeDelta as e } from "./Carousel.utils.mjs";
2
+ import t from "./CarouselSlide/index.mjs";
3
+ import { Children as n, cloneElement as r, isValidElement as i, useCallback as a, useEffect as o, useRef as s, useState as c } from "react";
4
+ import { Flexbox as l } from "@dotss/ui";
5
+ import u from "@dotss/ui/core/useTheme";
6
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
6
7
  //#region shared/components/Carousel/Carousel.tsx
7
- var f = 5;
8
- function p({ children: p, spacing: m = 2, edgeSpacing: h = 4, rowCount: g = 2, step: _ = 1, renderPagination: v, ...y }) {
9
- let { spacing: b } = l(), [x, S] = s(1), [C, w] = s(1), [T, E] = s(0), D = o(null), O = o(null), k = o(null), A = o(0), j = o(0), M = o(0), N = o(!1), P = o(!0), F = o(0), I = b.content(m), L = b.content(h), R = t.toArray(p).filter(r).filter((t) => t.type === e), z = R.length, B = (e, t) => {
10
- A.current = e, j.current = t;
11
- }, V = () => {
12
- if (!O.current || !N.current) return;
13
- let e = (k.current?.offsetWidth || 0) * .01, t = -M.current >= e && x + 1 <= C, n = -M.current <= -e && x - 1 >= 1, r = Math.abs(M.current) >= f;
14
- N.current = !1, P.current = !r, M.current = 0;
15
- let i = x;
16
- t ? i = x + 1 : n && (i = x - 1), O.current.style.transition = "transform 0.2s", O.current.style.cursor = "grab", H(i);
17
- }, H = i((e, t = 0) => {
18
- if (!O.current) return;
19
- S(e);
20
- let n = e === 1, r = e === C, i = (D.current?.offsetWidth || 0) - L, a = (k.current?.children[0]?.clientWidth || 0) + I, o = (i - a * Math.floor(i / a) - I) / 2, s = a * (e - 1) - o;
21
- n ? O.current.style.transform = `translate3d(${t}px, 0, 0)` : r ? O.current.style.transform = `translate3d(${-(s - o) + t}px, 0, 0)` : O.current.style.transform = `translate3d(${-s + t}px, 0, 0)`;
8
+ var p = 5;
9
+ function m({ children: m, spacing: h = 2, edgeSpacing: g = 4, rowCount: _ = 2, step: v = 1, renderPagination: y, ...b }) {
10
+ let { spacing: x } = u(), [S, C] = c(1), [w, T] = c(1), [E, D] = c(0), O = s(null), k = s(null), A = s(null), j = s(0), M = s(0), N = s(0), P = s(!1), F = s(!0), I = s(0), L = x.content(h), R = x.content(g), z = n.toArray(m).filter(i).filter((e) => e.type === t), B = z.length, V = (e, t) => {
11
+ j.current = e, M.current = t;
12
+ }, H = () => {
13
+ if (!k.current || !P.current) return;
14
+ let e = (A.current?.offsetWidth || 0) * .01, t = -N.current >= e && S + 1 <= w, n = -N.current <= -e && S - 1 >= 1, r = Math.abs(N.current) >= p;
15
+ P.current = !1, F.current = !r, N.current = 0;
16
+ let i = S;
17
+ t ? i = S + 1 : n && (i = S - 1), k.current.style.transition = "transform 0.2s", k.current.style.cursor = "grab", U(i);
18
+ }, U = a((e, t = 0) => {
19
+ if (!k.current) return;
20
+ C(e);
21
+ let n = e === 1, r = e === w, i = (O.current?.offsetWidth || 0) - R, a = (A.current?.children[0]?.clientWidth || 0) + L, o = (i - a * Math.floor(i / a) - L) / 2, s = a * (e - 1) - o;
22
+ n ? k.current.style.transform = `translate3d(${t}px, 0, 0)` : r ? k.current.style.transform = `translate3d(${-(s - o) + t}px, 0, 0)` : k.current.style.transform = `translate3d(${-s + t}px, 0, 0)`;
22
23
  }, [
24
+ R,
23
25
  L,
24
- I,
25
- C
26
- ]), U = (e) => B(e.touches[0].clientX, e.touches[0].clientY), W = (e) => {
27
- N.current = !0, B(e.clientX, e.clientY);
28
- }, G = (e) => {
29
- O.current && (O.current.style.transition = "transform 0.2s", O.current.style.cursor = "grab", H(e));
30
- }, K = (e) => (t) => {
26
+ w
27
+ ]), W = (e) => V(e.touches[0].clientX, e.touches[0].clientY), G = (e) => {
28
+ P.current = !0, V(e.clientX, e.clientY);
29
+ }, K = (e) => {
30
+ k.current && (k.current.style.transition = "transform 0.2s", k.current.style.cursor = "grab", U(e));
31
+ }, q = (e) => (t) => {
31
32
  t.stopPropagation();
32
- let n = Array.from(k.current?.children || []).indexOf(t.currentTarget), r = (D.current?.offsetWidth || 0) - L * 2, i = (k.current?.children[0]?.clientWidth || 0) + I, a = Math.floor(r / (i / _)) * g, o = (x - 1) * a, s = o + a - 1, c = k.current?.children.length || 0, l = n % g, u = Math.floor(n / g), d = n;
33
+ let n = Array.from(A.current?.children || []).indexOf(t.currentTarget), r = (O.current?.offsetWidth || 0) - R * 2, i = (A.current?.children[0]?.clientWidth || 0) + L, a = Math.floor(r / (i / v)) * _, o = (S - 1) * a, s = o + a - 1, c = A.current?.children.length || 0, l = n % _, u = Math.floor(n / _), d = n;
33
34
  switch (t.key) {
34
35
  case "ArrowRight": {
35
36
  t.preventDefault();
36
- let e = (u + 1) * g + l;
37
+ let e = (u + 1) * _ + l;
37
38
  e < c && (d = e);
38
39
  break;
39
40
  }
40
41
  case "ArrowLeft": {
41
42
  t.preventDefault();
42
- let e = (u - 1) * g + l;
43
+ let e = (u - 1) * _ + l;
43
44
  e >= 0 && (d = e);
44
45
  break;
45
46
  }
46
47
  case "ArrowDown": {
47
48
  t.preventDefault();
48
49
  let e = n + 1;
49
- e < c && e % g > l && (d = e);
50
+ e < c && e % _ > l && (d = e);
50
51
  break;
51
52
  }
52
53
  case "ArrowUp": {
53
54
  t.preventDefault();
54
55
  let e = n - 1;
55
- e >= 0 && e % g < l && (d = e);
56
+ e >= 0 && e % _ < l && (d = e);
56
57
  break;
57
58
  }
58
59
  case "Enter":
@@ -62,124 +63,129 @@ function p({ children: p, spacing: m = 2, edgeSpacing: h = 4, rowCount: g = 2, s
62
63
  default: return;
63
64
  }
64
65
  if (d >= o && d <= s) {
65
- (k.current?.children[d])?.focus();
66
+ (A.current?.children[d])?.focus();
66
67
  return;
67
68
  }
68
- d >= 0 && d < c && (F.current = requestAnimationFrame(() => {
69
- (k.current?.children[d])?.focus();
69
+ d >= 0 && d < c && (I.current = requestAnimationFrame(() => {
70
+ (A.current?.children[d])?.focus();
70
71
  })), e?.(t);
71
- }, q = (e) => {
72
- e.propertyName === "transform" && (P.current = !0);
73
- }, J = (e) => (t) => {
74
- E(Number(t.currentTarget.getAttribute("aria-posinset")) - 1), e?.(t);
72
+ }, J = (e) => {
73
+ e.propertyName === "transform" && (F.current = !0);
74
+ }, Y = (e) => (t) => {
75
+ D(Number(t.currentTarget.getAttribute("aria-posinset")) - 1), e?.(t);
75
76
  };
76
- return a(() => {
77
- let e = () => H(x);
77
+ return o(() => {
78
+ let e = () => U(S);
78
79
  return e(), window.addEventListener("resize", e), () => {
79
80
  window.removeEventListener("resize", e);
80
81
  };
81
- }, [H, x]), a(() => {
82
+ }, [U, S]), o(() => {
82
83
  let e = () => {
83
- let e = (D.current?.offsetWidth || 0) - L * 2, t = (k.current?.children[0]?.clientWidth || 0) + I, n = Math.floor(e / (t / _)), r = Math.ceil(z / (g || 1)), i = Math.max(r - (n - 1), 1);
84
- S((e) => e > i ? i : e), w(i);
84
+ let e = (O.current?.offsetWidth || 0) - R * 2, t = (A.current?.children[0]?.clientWidth || 0) + L, n = Math.floor(e / (t / v)), r = Math.ceil(B / (_ || 1)), i = Math.max(r - (n - 1), 1);
85
+ C((e) => e > i ? i : e), T(i);
85
86
  };
86
87
  return e(), window.addEventListener("resize", e), () => {
87
88
  window.removeEventListener("resize", e);
88
89
  };
89
90
  }, [
91
+ R,
90
92
  L,
91
- I,
92
- z,
93
+ B,
94
+ v,
93
95
  _,
94
- g,
95
- p
96
- ]), a(() => {
97
- let e = O.current, t = (t, n, r) => {
98
- if (!e || C <= 1) return;
99
- e.style.transition = "none", e.style.cursor = "grabbing", M.current = t - A.current;
100
- let i = n - j.current;
101
- N.current = N.current || Math.abs(M.current) > 5 && Math.abs(i) < 10, N.current && (r.cancelable && (r.stopPropagation(), r.preventDefault()), e.style.transition = "none", e.style.cursor = "grabbing", H(x, M.current));
102
- }, n = (e) => t(e.touches[0].clientX, e.touches[0].clientY, e), r = (e) => {
103
- N.current && t(e.clientX, e.clientY, e);
96
+ m
97
+ ]), o(() => {
98
+ let t = k.current, n = (n, r, i) => {
99
+ if (!t || w <= 1) return;
100
+ t.style.transition = "none", t.style.cursor = "grabbing", N.current = n - j.current;
101
+ let a = r - M.current;
102
+ P.current = P.current || Math.abs(N.current) > 5 && Math.abs(a) < 10, P.current && (i.cancelable && (i.stopPropagation(), i.preventDefault()), t.style.transition = "none", t.style.cursor = "grabbing", U(S, e({
103
+ fingerDeltaX: N.current,
104
+ page: S,
105
+ totalPages: w,
106
+ width: O.current?.offsetWidth ?? 0
107
+ })));
108
+ }, r = (e) => n(e.touches[0].clientX, e.touches[0].clientY, e), i = (e) => {
109
+ P.current && n(e.clientX, e.clientY, e);
104
110
  };
105
- return e && (e.addEventListener("mousemove", r), e.addEventListener("touchmove", n)), () => {
106
- e && (e.removeEventListener("mousemove", r), e.removeEventListener("touchmove", n));
111
+ return t && (t.addEventListener("mousemove", i), t.addEventListener("touchmove", r)), () => {
112
+ t && (t.removeEventListener("mousemove", i), t.removeEventListener("touchmove", r));
107
113
  };
108
114
  }, [
109
- H,
110
- x,
111
- C
112
- ]), a(() => () => {
113
- F.current && cancelAnimationFrame(F.current);
114
- }, []), a(() => {
115
- let e = k.current, t = (e) => {
116
- P.current || (e.stopPropagation(), e.preventDefault());
115
+ U,
116
+ S,
117
+ w
118
+ ]), o(() => () => {
119
+ I.current && cancelAnimationFrame(I.current);
120
+ }, []), o(() => {
121
+ let e = A.current, t = (e) => {
122
+ F.current || (e.stopPropagation(), e.preventDefault());
117
123
  };
118
124
  return e?.addEventListener("click", t), () => {
119
125
  e?.removeEventListener("click", t);
120
126
  };
121
- }, []), /* @__PURE__ */ d(c, {
127
+ }, []), /* @__PURE__ */ f(l, {
122
128
  flexDirection: "column",
123
129
  role: "list",
124
130
  "aria-roledescription": "carousel",
125
131
  "aria-label": "슬라이더",
126
132
  flexGrow: 1,
127
- ...y,
133
+ ...b,
128
134
  inlineCSS: {
129
135
  width: "100%",
130
- ...y?.inlineCSS
136
+ ...b?.inlineCSS
131
137
  },
132
- children: [/* @__PURE__ */ u(c, {
133
- ref: D,
138
+ children: [/* @__PURE__ */ d(l, {
139
+ ref: O,
134
140
  inlineCSS: { overflow: "hidden" },
135
- children: /* @__PURE__ */ u(c, {
136
- ref: O,
137
- onMouseDown: W,
138
- onMouseUp: V,
139
- onMouseLeave: V,
140
- onTouchStart: U,
141
- onTouchEnd: V,
142
- onTouchCancel: V,
143
- onTransitionEnd: q,
141
+ children: /* @__PURE__ */ d(l, {
142
+ ref: k,
143
+ onMouseDown: G,
144
+ onMouseUp: H,
145
+ onMouseLeave: H,
146
+ onTouchStart: W,
147
+ onTouchEnd: H,
148
+ onTouchCancel: H,
149
+ onTransitionEnd: J,
144
150
  inlineCSS: {
145
- gap: I,
146
- paddingLeft: L,
147
- paddingRight: L,
151
+ gap: L,
152
+ paddingLeft: R,
153
+ paddingRight: R,
148
154
  transition: "transform 0.2s",
149
155
  transform: "translate3d(0, 0, 0)",
150
156
  cursor: "grab"
151
157
  },
152
- children: /* @__PURE__ */ u(c, {
153
- ref: k,
158
+ children: /* @__PURE__ */ d(l, {
159
+ ref: A,
154
160
  inlineCSS: {
155
- gap: I,
161
+ gap: L,
156
162
  display: "grid",
157
163
  gridTemplateRows: "min-content",
158
164
  transform: "translate3d(0, 0, 0)"
159
165
  },
160
- children: t.map(R, (e, t) => n(e, {
166
+ children: n.map(z, (e, t) => r(e, {
161
167
  role: "listitem",
162
- tabIndex: t === T ? 0 : -1,
168
+ tabIndex: t === E ? 0 : -1,
163
169
  "aria-roledescription": "slide",
164
- "aria-label": `${z}개 중 ${t + 1}번째 슬라이드`,
170
+ "aria-label": `${B}개 중 ${t + 1}번째 슬라이드`,
165
171
  "aria-posinset": t + 1,
166
- "aria-setsize": z,
167
- onKeyDown: K(e.props.onKeyDown),
168
- onFocus: J(e.props.onFocus),
172
+ "aria-setsize": B,
173
+ onKeyDown: q(e.props.onKeyDown),
174
+ onFocus: Y(e.props.onFocus),
169
175
  ...e.props,
170
176
  style: {
171
177
  ...e.props?.style,
172
- gridRow: `${t % g + 1} / ${t % g + 1}`
178
+ gridRow: `${t % _ + 1} / ${t % _ + 1}`
173
179
  }
174
180
  }))
175
181
  })
176
182
  })
177
- }), typeof v == "function" && v({
178
- page: x,
179
- totalPages: C,
180
- onChange: G
183
+ }), typeof y == "function" && y({
184
+ page: S,
185
+ totalPages: w,
186
+ onChange: K
181
187
  })]
182
188
  });
183
189
  }
184
190
  //#endregion
185
- export { p as default };
191
+ export { m as default };
@@ -0,0 +1,8 @@
1
+ export declare const EDGE_RESISTANCE = 0.55;
2
+ export declare function addDamping(distance: number, maxDistance: number, constant?: number): number;
3
+ export declare function getCarouselSwipeDelta({ fingerDeltaX, page, totalPages, width }: {
4
+ fingerDeltaX: number;
5
+ page: number;
6
+ totalPages: number;
7
+ width: number;
8
+ }): number;
@@ -0,0 +1,12 @@
1
+ //#region shared/components/Carousel/Carousel.utils.tsx
2
+ var e = .55;
3
+ function t(t, n, r = e) {
4
+ if (t === 0 || n <= 0) return 0;
5
+ let i = Math.abs(t), a = i * n * r / (n + r * i);
6
+ return Math.sign(t) * a;
7
+ }
8
+ function n({ fingerDeltaX: e, page: n, totalPages: r, width: i }) {
9
+ return !(n === 1 && e > 0) && !(n === r && e < 0) ? e : t(e, i);
10
+ }
11
+ //#endregion
12
+ export { e as EDGE_RESISTANCE, t as addDamping, n as getCarouselSwipeDelta };
@@ -1,6 +1,6 @@
1
1
  import { FlexboxProps } from 'node_modules/@dotss/ui/Flexbox/Flexbox';
2
- export type BotMessageType = 'TEACHER_INQUIRED' | 'PARENT_CHANGED_OFFER_SCHEDULE' | 'PARENT_CHANGED_MATCHING_SCHEDULE' | 'TEACHER_APPLIED' | 'PARENT_SENT_OFFER' | 'KOK_MATCHING_SUCCEEDED' | 'APPLICATION_MATCHING_SUCCEEDED' | 'ASSIGNMENT_MATCHING_SUCCEEDED' | 'PARENT_REJECTED_APPLICATION' | 'TEACHER_REFUSED_OFFER' | 'PARENT_CANCELED_MATCHING' | 'TEACHER_CANCELED_MATCHING' | 'TEACHER_COMPLETED_CARE' | 'ADMIN_CANCELED_MATCHING' | 'AUTO_MATCHING_SUCCEEDED' | 'PLAY_CONTENT_RECOMMENDED' | 'PARENT_REQUESTED_MATCHING_SCHEDULE_CHANGE' | 'TEACHER_ACCEPTED_MATCHING_SCHEDULE_CHANGE' | 'TEACHER_REFUSED_MATCHING_SCHEDULE_CHANGE' | 'MATCHING_SCHEDULE_CHANGE_EXPIRED' | 'ADMIN_CANCELED_OFFER' | 'TEACHER_BECAME_ROOKIE';
3
- export type BotMessageCtaType = 'MY_CLASS_CHECK' | 'OFFER_CHECK' | 'CHANGE_INFO_CHECK' | 'MY_APPLICATION_INFO_VIEW' | 'CARE_NOTE_CHECK' | 'TEACHER_SELECTION' | 'PLAY_CONTENT_EXPLORE' | 'ACTIVITY_GUIDEBOOK_VIEW';
2
+ export type BotMessageType = 'TEACHER_INQUIRED' | 'PARENT_CHANGED_OFFER_SCHEDULE' | 'PARENT_CHANGED_MATCHING_SCHEDULE' | 'TEACHER_APPLIED' | 'PARENT_SENT_OFFER' | 'KOK_MATCHING_SUCCEEDED' | 'APPLICATION_MATCHING_SUCCEEDED' | 'ASSIGNMENT_MATCHING_SUCCEEDED' | 'PARENT_REJECTED_APPLICATION' | 'TEACHER_REFUSED_OFFER' | 'PARENT_CANCELED_MATCHING' | 'TEACHER_CANCELED_MATCHING' | 'TEACHER_COMPLETED_CARE' | 'ADMIN_CANCELED_MATCHING' | 'AUTO_MATCHING_SUCCEEDED' | 'PLAY_CONTENT_RECOMMENDED' | 'PARENT_REQUESTED_MATCHING_SCHEDULE_CHANGE' | 'TEACHER_ACCEPTED_MATCHING_SCHEDULE_CHANGE' | 'TEACHER_REFUSED_MATCHING_SCHEDULE_CHANGE' | 'MATCHING_SCHEDULE_CHANGE_EXPIRED' | 'ADMIN_CANCELED_OFFER' | 'TEACHER_BECAME_ROOKIE' | 'TEACHER_INTRO_NOT_WRITTEN_1_HOUR' | 'TEACHER_INTRO_NOT_WRITTEN_1_DAY' | 'TEACHER_INTRO_NOT_WRITTEN_3_DAY' | 'TEACHER_CONTRACT_NOT_SIGNED_IMMEDIATE' | 'TEACHER_CONTRACT_NOT_SIGNED_1_HOUR' | 'TEACHER_CONTRACT_NOT_SIGNED_1_DAY' | 'TEACHER_CONTRACT_NOT_SIGNED_3_DAY';
3
+ export type BotMessageCtaType = 'MY_CLASS_CHECK' | 'OFFER_CHECK' | 'CHANGE_INFO_CHECK' | 'MY_APPLICATION_INFO_VIEW' | 'CARE_NOTE_CHECK' | 'TEACHER_SELECTION' | 'PLAY_CONTENT_EXPLORE' | 'ACTIVITY_GUIDEBOOK_VIEW' | 'INTRO_WRITE' | 'CONTRACT_SIGN';
4
4
  export type BotMessageCtaTargetTable = 'OFFER' | 'MATCHING';
5
5
  export type BotMessageSubCtaTargetTable = 'OFFER' | 'MATCHING';
6
6
  export interface BotMessageProps extends Omit<FlexboxProps, 'id' | 'title'> {
@@ -1,3 +1,3 @@
1
1
  import { BotMessageCtaType, BotMessageProps } from '.';
2
- export declare function getCtaButtonText(ctaType?: BotMessageCtaType | null): "" | "내 수업 확인하기" | "공고 확인하기" | "변경 내용 확인하기" | "나의 지원 내역 보러가기" | "돌봄노트 확인하기" | "선생님 선택하러 가기" | "놀이콘텐츠 둘러보기" | "활동 가이드북 보기";
2
+ export declare function getCtaButtonText(ctaType?: BotMessageCtaType | null): "" | "내 수업 확인하기" | "공고 확인하기" | "변경 내용 확인하기" | "나의 지원 내역 보러가기" | "돌봄노트 확인하기" | "선생님 선택하러 가기" | "놀이콘텐츠 둘러보기" | "활동 가이드북 보기" | "자기소개 작성하기" | "계약서 서명하기";
3
3
  export declare function getBotMessageLabel({ title, content, regDatetime }: Pick<BotMessageProps, 'title' | 'content' | 'regDatetime'>): string;
@@ -10,6 +10,8 @@ function t(e) {
10
10
  case "TEACHER_SELECTION": return "선생님 선택하러 가기";
11
11
  case "PLAY_CONTENT_EXPLORE": return "놀이콘텐츠 둘러보기";
12
12
  case "ACTIVITY_GUIDEBOOK_VIEW": return "활동 가이드북 보기";
13
+ case "INTRO_WRITE": return "자기소개 작성하기";
14
+ case "CONTRACT_SIGN": return "계약서 서명하기";
13
15
  default: return "";
14
16
  }
15
17
  }
@@ -1,116 +1,117 @@
1
1
  import e from "./SwiperBlock/index.mjs";
2
2
  import t from "../MediaDialog/MediaBlock/index.mjs";
3
- import { createSwipeEvent as n } from "./Swiper.utils.mjs";
4
- import { Children as r, cloneElement as i, isValidElement as a, useCallback as o, useEffect as s, useRef as c, useState as l } from "react";
5
- import { Flexbox as u } from "@dotss/ui";
6
- import { jsxs as d } from "react/jsx-runtime";
3
+ import { createSwipeEvent as n, getSwipingTranslateX as r } from "./Swiper.utils.mjs";
4
+ import { Children as i, cloneElement as a, isValidElement as o, useCallback as s, useEffect as c, useRef as l, useState as u } from "react";
5
+ import { Flexbox as d } from "@dotss/ui";
6
+ import { jsxs as f } from "react/jsx-runtime";
7
7
  //#region shared/components/Swiper/Swiper.tsx
8
- function f({ children: f, initialPage: p = 0, onSwipe: m, onSwiping: h, loop: g = !1, disableSwipe: _ = !1, renderPagination: v, inlineCSS: y, autoSwipe: b = !1, autoSwipeInterval: x = 3e3, autoSwipeDuration: S = 1e3, ...C }) {
9
- let [w, T] = l(p), [E, D] = l(1), O = c(null), k = c(0), A = c(0), j = c(0), M = c(0), N = c(!1), P = c(!0), F = c(""), I = c(p), L = c(!1), R = c(null), z = r.count(f), B = r.toArray(f).filter(a).filter((n) => n.type === e || n.type === t), V = z > 1 && !_, H = r.toArray(B?.[0]).filter(a).filter((n) => n.type === e || n.type === t), U = r.toArray(B?.[B?.length - 1]).filter(a).filter((n) => n.type === e || n.type === t), W = (e, t, n) => {
10
- !O.current || !V || (F.current = O.current.style.transform, A.current = e, k.current = e + O.current.offsetWidth * (n + 1), j.current = t);
11
- }, G = o((e, t, r, { isAutoSwiped: i = !1, shouldFocus: a = !1 } = {}) => {
12
- if (!O.current || !V || !N.current || !P.current) return;
13
- P.current = !1, O.current.style.transition = i ? `transform ${S}ms` : "transform 0.2s", O.current.style.cursor = "grab", R.current &&= (O.current.removeEventListener("transitionend", R.current), null);
14
- let o = t || w, s = r || k.current - O.current.offsetWidth * (o + 1) - e, c = O.current.offsetWidth * .1;
8
+ function p({ children: p, initialPage: m = 0, onSwipe: h, onSwiping: g, loop: _ = !1, disableSwipe: v = !1, renderPagination: y, inlineCSS: b, autoSwipe: x = !1, autoSwipeInterval: S = 3e3, autoSwipeDuration: C = 1e3, ...w }) {
9
+ let [T, E] = u(m), [D, O] = u(1), k = l(null), A = l(0), j = l(0), M = l(0), N = l(0), P = l(!1), F = l(!0), I = l(""), L = l(m), R = l(!1), z = l(null), B = i.count(p), V = i.toArray(p).filter(o).filter((n) => n.type === e || n.type === t), H = B > 1 && !v, U = i.toArray(V?.[0]).filter(o).filter((n) => n.type === e || n.type === t), W = i.toArray(V?.[V?.length - 1]).filter(o).filter((n) => n.type === e || n.type === t), G = (e, t, n) => {
10
+ !k.current || !H || (I.current = k.current.style.transform, j.current = e, A.current = e + k.current.offsetWidth * (n + 1), M.current = t);
11
+ }, K = s((e, t, r, { isAutoSwiped: i = !1, shouldFocus: a = !1 } = {}) => {
12
+ if (!k.current || !H || !P.current || !F.current) return;
13
+ F.current = !1, k.current.style.transition = i ? `transform ${C}ms` : "transform 0.2s", k.current.style.cursor = "grab", z.current &&= (k.current.removeEventListener("transitionend", z.current), null);
14
+ let o = t || T, s = r || A.current - k.current.offsetWidth * (o + 1) - e, c = k.current.offsetWidth * .1;
15
15
  if (Math.abs(s) < c && !t) {
16
- O.current.style.transform = F.current, N.current = !1, P.current = !0, m?.(n({
17
- realPage: I.current,
18
- totalPages: E,
19
- lastPage: I.current,
16
+ k.current.style.transform = I.current, P.current = !1, F.current = !0, h?.(n({
17
+ realPage: L.current,
18
+ totalPages: D,
19
+ lastPage: L.current,
20
20
  isLoop: !1
21
21
  }));
22
22
  return;
23
23
  }
24
- let l = s <= -c && o - 1 < 0, u = s >= c && o + 1 === E, d = s >= c && o + 1 < E, f = s <= -c && o - 1 >= 0;
24
+ let l = _ && s <= -c && o - 1 < 0, u = _ && s >= c && o + 1 === D, d = s >= c && o + 1 < D, f = s <= -c && o - 1 >= 0;
25
25
  if (l) {
26
- I.current = E - 1, m?.(n({
27
- realPage: I.current,
28
- totalPages: E,
26
+ L.current = D - 1, h?.(n({
27
+ realPage: L.current,
28
+ totalPages: D,
29
29
  lastPage: 0,
30
30
  isLoop: !0
31
- })), O.current.style.transform = "translate3d(0, 0, 0)", R.current = (e) => {
31
+ })), k.current.style.transform = "translate3d(0, 0, 0)", z.current = (e) => {
32
32
  if (e.propertyName === "transform") {
33
- if (!O.current) return;
34
- if (O.current.style.transition = "none", O.current.style.transform = `translate3d(calc(-100% * ${E}), 0, 0)`, T(E - 1), N.current = !1, P.current = !0, a) (O.current?.children)?.[E]?.focus();
33
+ if (!k.current) return;
34
+ if (k.current.style.transition = "none", k.current.style.transform = `translate3d(calc(-100% * ${D}), 0, 0)`, E(D - 1), P.current = !1, F.current = !0, a) (k.current?.children)?.[D]?.focus();
35
35
  else {
36
36
  if (i) return;
37
37
  document.activeElement?.blur();
38
38
  }
39
39
  }
40
- }, O.current.addEventListener("transitionend", R.current);
40
+ }, k.current.addEventListener("transitionend", z.current);
41
41
  return;
42
42
  } else if (u) {
43
- I.current = 0, m?.(n({
44
- realPage: I.current,
45
- totalPages: E,
46
- lastPage: E - 1,
43
+ L.current = 0, h?.(n({
44
+ realPage: L.current,
45
+ totalPages: D,
46
+ lastPage: D - 1,
47
47
  isLoop: !0
48
- })), O.current.style.transform = `translate3d(calc(-100% * ${o + 2}), 0, 0)`, R.current = (e) => {
48
+ })), k.current.style.transform = `translate3d(calc(-100% * ${o + 2}), 0, 0)`, z.current = (e) => {
49
49
  if (e.propertyName === "transform") {
50
- if (!O.current) return;
51
- if (O.current.style.transition = "none", O.current.style.transform = "translate3d(-100%, 0, 0)", T(0), N.current = !1, P.current = !0, a) (O.current?.children)?.[1]?.focus();
50
+ if (!k.current) return;
51
+ if (k.current.style.transition = "none", k.current.style.transform = "translate3d(-100%, 0, 0)", E(0), P.current = !1, F.current = !0, a) (k.current?.children)?.[1]?.focus();
52
52
  else {
53
53
  if (i) return;
54
54
  document.activeElement?.blur();
55
55
  }
56
56
  }
57
- }, O.current.addEventListener("transitionend", R.current);
57
+ }, k.current.addEventListener("transitionend", z.current);
58
58
  return;
59
59
  }
60
- d ? (I.current = o + 1, m?.(n({
61
- realPage: I.current,
62
- totalPages: E,
60
+ d ? (L.current = o + 1, h?.(n({
61
+ realPage: L.current,
62
+ totalPages: D,
63
63
  lastPage: o,
64
64
  isLoop: !0
65
- })), T(I.current), O.current.style.transform = `translate3d(calc(-100% * ${o + 2}), 0, 0)`) : f ? (I.current = o - 1, m?.(n({
66
- realPage: I.current,
67
- totalPages: E,
65
+ })), E(L.current), k.current.style.transform = `translate3d(calc(-100% * ${o + 2}), 0, 0)`) : f ? (L.current = o - 1, h?.(n({
66
+ realPage: L.current,
67
+ totalPages: D,
68
68
  lastPage: o,
69
69
  isLoop: !1
70
- })), T(I.current), O.current.style.transform = `translate3d(calc(-100% * ${o}), 0, 0)`) : (m?.(n({
71
- realPage: I.current,
72
- totalPages: E,
73
- lastPage: I.current,
70
+ })), E(L.current), k.current.style.transform = `translate3d(calc(-100% * ${o}), 0, 0)`) : (h?.(n({
71
+ realPage: L.current,
72
+ totalPages: D,
73
+ lastPage: L.current,
74
74
  isLoop: !1
75
- })), O.current.style.transform = F.current), R.current = (e) => {
75
+ })), k.current.style.transform = I.current), z.current = (e) => {
76
76
  if (e.propertyName === "transform") {
77
- N.current = !1, P.current = !0;
78
- let e = Array.from(O.current?.children ?? []).find((e) => e.getAttribute("aria-current") === "page");
77
+ P.current = !1, F.current = !0;
78
+ let e = Array.from(k.current?.children ?? []).find((e) => e.getAttribute("aria-current") === "page");
79
79
  if (a && e) e.focus();
80
80
  else {
81
81
  if (i) return;
82
82
  document.activeElement?.blur();
83
83
  }
84
84
  }
85
- }, O.current.addEventListener("transitionend", R.current);
85
+ }, k.current.addEventListener("transitionend", z.current);
86
86
  }, [
87
- w,
88
- E,
89
- m,
90
- V,
91
- S
92
- ]), K = (e) => {
93
- N.current = !0, W(e.clientX, e.clientY, I.current);
94
- }, q = (e) => G(e.clientX), J = (e) => {
95
- W(e.touches[0].clientX, e.touches[0].clientY, I.current);
96
- }, Y = (e) => G(e.changedTouches[0].clientX), X = (e) => {
97
- N.current = !0;
87
+ T,
88
+ D,
89
+ h,
90
+ H,
91
+ C,
92
+ _
93
+ ]), q = (e) => {
94
+ P.current = !0, G(e.clientX, e.clientY, L.current);
95
+ }, J = (e) => K(e.clientX), Y = (e) => {
96
+ G(e.touches[0].clientX, e.touches[0].clientY, L.current);
97
+ }, X = (e) => K(e.changedTouches[0].clientX), Z = (e) => {
98
+ P.current = !0;
98
99
  let t = e - 1;
99
- T(t <= 0 ? 0 : t), G(0, e);
100
- }, Z = (e) => (t) => {
100
+ E(t <= 0 ? 0 : t), K(0, e);
101
+ }, Q = (e) => (t) => {
101
102
  switch (t.key) {
102
103
  case "ArrowRight": {
103
- if (t.preventDefault(), N.current || !P.current) return;
104
- let e = I.current === E - 1;
105
- if (!g && e) return;
106
- N.current = !0, G(0, I.current, (O.current?.offsetWidth ?? 0) * .1, { shouldFocus: !0 });
104
+ if (t.preventDefault(), P.current || !F.current) return;
105
+ let e = L.current === D - 1;
106
+ if (!_ && e) return;
107
+ P.current = !0, K(0, L.current, (k.current?.offsetWidth ?? 0) * .1, { shouldFocus: !0 });
107
108
  break;
108
109
  }
109
110
  case "ArrowLeft": {
110
- if (t.preventDefault(), N.current || !P.current) return;
111
- let e = I.current === 0;
112
- if (!g && e) return;
113
- N.current = !0, G(0, I.current, -((O.current?.offsetWidth ?? 0) * .1), { shouldFocus: !0 });
111
+ if (t.preventDefault(), P.current || !F.current) return;
112
+ let e = L.current === 0;
113
+ if (!_ && e) return;
114
+ P.current = !0, K(0, L.current, -((k.current?.offsetWidth ?? 0) * .1), { shouldFocus: !0 });
114
115
  break;
115
116
  }
116
117
  case "Enter":
@@ -122,90 +123,90 @@ function f({ children: f, initialPage: p = 0, onSwipe: m, onSwiping: h, loop: g
122
123
  }
123
124
  e?.(t);
124
125
  };
125
- return s(() => {
126
- let e = O.current, t = (e, t, r) => {
127
- if (!(!O.current || !V || !P.current) && (M.current = e - k.current, N.current = N.current || Math.abs(M.current) > 5 && Math.abs(t - j.current) < 5, N.current)) {
128
- let t = A.current < e, i = A.current > e;
129
- if (!g && t && I.current === 0) {
130
- N.current = !1;
131
- return;
132
- }
133
- if (!g && i && I.current === E - 1) {
134
- N.current = !1;
135
- return;
136
- }
137
- r.cancelable && r.preventDefault(), h?.(n({
138
- realPage: I.current,
139
- totalPages: E,
140
- lastPage: I.current,
126
+ return c(() => {
127
+ let e = k.current, t = (e, t, i) => {
128
+ if (!(!k.current || !H || !F.current) && (N.current = e - A.current, P.current = P.current || Math.abs(N.current) > 5 && Math.abs(t - M.current) < 5, P.current)) {
129
+ i.cancelable && i.preventDefault(), g?.(n({
130
+ realPage: L.current,
131
+ totalPages: D,
132
+ lastPage: L.current,
141
133
  isLoop: !1
142
- })), O.current.style.transition = "none", O.current.style.cursor = "grabbing", O.current.style.transform = `translate3d(${M.current}px, 0, 0)`;
134
+ }));
135
+ let t = r({
136
+ rawTranslateX: N.current,
137
+ fingerDeltaX: e - j.current,
138
+ page: L.current,
139
+ totalPages: D,
140
+ width: k.current.offsetWidth,
141
+ loop: _
142
+ });
143
+ k.current.style.transition = "none", k.current.style.cursor = "grabbing", k.current.style.transform = `translate3d(${t}px, 0, 0)`;
143
144
  }
144
- }, r = (e) => {
145
- N.current && t(e.clientX, e.clientY, e);
146
- }, i = (e) => t(e.touches[0].clientX, e.touches[0].clientY, e);
147
- return e && (e.addEventListener("mousemove", r), e.addEventListener("touchmove", i)), () => {
148
- e && (e.removeEventListener("mousemove", r), e.removeEventListener("touchmove", i));
145
+ }, i = (e) => {
146
+ P.current && t(e.clientX, e.clientY, e);
147
+ }, a = (e) => t(e.touches[0].clientX, e.touches[0].clientY, e);
148
+ return e && (e.addEventListener("mousemove", i), e.addEventListener("touchmove", a)), () => {
149
+ e && (e.removeEventListener("mousemove", i), e.removeEventListener("touchmove", a));
149
150
  };
150
151
  }, [
151
- V,
152
- h,
152
+ H,
153
153
  g,
154
- E
155
- ]), s(() => {
156
- let e = O.current, t = (e) => {
157
- P.current || (e.stopPropagation(), e.preventDefault());
154
+ _,
155
+ D
156
+ ]), c(() => {
157
+ let e = k.current, t = (e) => {
158
+ F.current || (e.stopPropagation(), e.preventDefault());
158
159
  };
159
160
  return e?.addEventListener("click", t), () => {
160
161
  e?.removeEventListener("click", t);
161
162
  };
162
- }, []), s(() => {
163
- let e = O.current;
163
+ }, []), c(() => {
164
+ let e = k.current;
164
165
  return () => {
165
- R.current && e && (e.removeEventListener("transitionend", R.current), R.current = null);
166
+ z.current && e && (e.removeEventListener("transitionend", z.current), z.current = null);
166
167
  };
167
- }, []), s(() => {
168
- D(z);
169
- }, [z]), s(() => {
170
- O.current && !L.current && (L.current = !0, O.current.style.transition = "none", O.current.style.transform = `translate3d(calc(-100% * ${z < p + 1 ? z : p + 1}), 0, 0)`);
171
- }, [p, z]), s(() => {
172
- if (b) {
168
+ }, []), c(() => {
169
+ O(B);
170
+ }, [B]), c(() => {
171
+ k.current && !R.current && (R.current = !0, k.current.style.transition = "none", k.current.style.transform = `translate3d(calc(-100% * ${B < m + 1 ? B : m + 1}), 0, 0)`);
172
+ }, [m, B]), c(() => {
173
+ if (x) {
173
174
  let e = setInterval(() => {
174
- N.current || !P.current || O.current && (!g && I.current === E - 1 || document.activeElement && O.current && O.current.contains(document.activeElement) || (N.current = !0, G(0, I.current, (O.current.offsetWidth ?? 0) * .1, { isAutoSwiped: !0 })));
175
- }, x);
175
+ P.current || !F.current || k.current && (!_ && L.current === D - 1 || document.activeElement && k.current && k.current.contains(document.activeElement) || (P.current = !0, K(0, L.current, (k.current.offsetWidth ?? 0) * .1, { isAutoSwiped: !0 })));
176
+ }, S);
176
177
  return () => {
177
178
  clearInterval(e);
178
179
  };
179
180
  }
180
181
  }, [
181
- b,
182
182
  x,
183
- g,
184
- E,
185
- G
186
- ]), /* @__PURE__ */ d(u, {
183
+ S,
184
+ _,
185
+ D,
186
+ K
187
+ ]), /* @__PURE__ */ f(d, {
187
188
  flexGrow: 1,
188
189
  role: "list",
189
190
  "aria-roledescription": "carousel",
190
191
  "aria-label": "슬라이더",
191
- ...C,
192
+ ...w,
192
193
  inlineCSS: {
193
194
  width: "100%",
194
195
  position: "relative",
195
- ...y
196
+ ...b
196
197
  },
197
- children: [/* @__PURE__ */ d(u, {
198
- ref: O,
198
+ children: [/* @__PURE__ */ f(d, {
199
+ ref: k,
199
200
  flexGrow: 1,
200
- onMouseDown: K,
201
- onMouseUp: q,
202
- onMouseLeave: q,
203
- onTouchStart: J,
204
- onTouchEnd: Y,
205
- onTouchCancel: Y,
201
+ onMouseDown: q,
202
+ onMouseUp: J,
203
+ onMouseLeave: J,
204
+ onTouchStart: Y,
205
+ onTouchEnd: X,
206
+ onTouchCancel: X,
206
207
  inlineCSS: {
207
- "& > div:first-of-type": { visibility: g ? "visible" : "hidden" },
208
- "& > div:last-of-type": { visibility: g ? "visible" : "hidden" }
208
+ "& > div:first-of-type": { visibility: _ ? "visible" : "hidden" },
209
+ "& > div:last-of-type": { visibility: _ ? "visible" : "hidden" }
209
210
  },
210
211
  style: {
211
212
  transition: "transform 0.2s",
@@ -213,27 +214,27 @@ function f({ children: f, initialPage: p = 0, onSwipe: m, onSwiping: h, loop: g
213
214
  cursor: "grab"
214
215
  },
215
216
  children: [
216
- U,
217
- B.map((e, t) => i(e, {
217
+ W,
218
+ V.map((e, t) => a(e, {
218
219
  role: "listitem",
219
- tabIndex: t === w ? 0 : -1,
220
- onKeyDown: Z(e.props.onKeyDown),
220
+ tabIndex: t === T ? 0 : -1,
221
+ onKeyDown: Q(e.props.onKeyDown),
221
222
  "aria-roledescription": "slide",
222
- "aria-hidden": t !== w,
223
- "aria-current": t === w ? "page" : void 0,
224
- "aria-label": `${E}개 중 ${t + 1}번째 슬라이드`,
223
+ "aria-hidden": t !== T,
224
+ "aria-current": t === T ? "page" : void 0,
225
+ "aria-label": `${D}개 중 ${t + 1}번째 슬라이드`,
225
226
  "aria-posinset": t + 1,
226
- "aria-setsize": E,
227
+ "aria-setsize": D,
227
228
  ...e.props
228
229
  })),
229
- H
230
+ U
230
231
  ]
231
- }), typeof v == "function" && v({
232
- page: w,
233
- totalPages: E,
234
- onChange: X
232
+ }), typeof y == "function" && y({
233
+ page: T,
234
+ totalPages: D,
235
+ onChange: Z
235
236
  })]
236
237
  });
237
238
  }
238
239
  //#endregion
239
- export { f as default };
240
+ export { p as default };
@@ -1,3 +1,13 @@
1
+ export declare const EDGE_RESISTANCE = 0.35;
2
+ export declare function addDamping(distance: number, maxDistance: number, constant?: number): number;
3
+ export declare function getSwipingTranslateX({ rawTranslateX, fingerDeltaX, page, totalPages, width, loop }: {
4
+ rawTranslateX: number;
5
+ fingerDeltaX: number;
6
+ page: number;
7
+ totalPages: number;
8
+ width: number;
9
+ loop: boolean;
10
+ }): number;
1
11
  export declare function createSwipeEvent({ realPage, totalPages, lastPage, isLoop }: {
2
12
  realPage: number;
3
13
  totalPages: number;
@@ -1,5 +1,16 @@
1
1
  //#region shared/components/Swiper/Swiper.utils.ts
2
- function e({ realPage: e, totalPages: t, lastPage: n, isLoop: r }) {
2
+ var e = .35;
3
+ function t(t, n, r = e) {
4
+ if (t === 0 || n <= 0) return 0;
5
+ let i = Math.abs(t), a = i * n * r / (n + r * i);
6
+ return Math.sign(t) * a;
7
+ }
8
+ function n({ rawTranslateX: e, fingerDeltaX: n, page: r, totalPages: i, width: a, loop: o }) {
9
+ if (o) return e;
10
+ let s = r === 0 && n > 0, c = r === i - 1 && n < 0;
11
+ return !s && !c ? e : -a * (r + 1) + t(n, a);
12
+ }
13
+ function r({ realPage: e, totalPages: t, lastPage: n, isLoop: r }) {
3
14
  return r ? {
4
15
  isFirstPage: e === 0,
5
16
  isLastPage: e === t - 1,
@@ -17,4 +28,4 @@ function e({ realPage: e, totalPages: t, lastPage: n, isLoop: r }) {
17
28
  };
18
29
  }
19
30
  //#endregion
20
- export { e as createSwipeEvent };
31
+ export { e as EDGE_RESISTANCE, t as addDamping, r as createSwipeEvent, n as getSwipingTranslateX };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dotss/tictoccroc",
3
3
  "type": "module",
4
- "version": "0.11.0",
4
+ "version": "0.11.2",
5
5
  "description": "Tictoccroc shared components, hooks, utils, and APIs for Dotss",
6
6
  "main": "./dist/index.mjs",
7
7
  "module": "./dist/index.mjs",