@forgedevstack/bear 1.0.8 → 1.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.
- package/README.md +11 -1
- package/dist/components/ActivityItem/ActivityItem.cjs +1 -1
- package/dist/components/ActivityItem/ActivityItem.js +1 -0
- package/dist/components/Alert/Alert.const.cjs +1 -1
- package/dist/components/Alert/Alert.const.js +3 -2
- package/dist/components/AppBar/AppBar.cjs +1 -1
- package/dist/components/AppBar/AppBar.js +3 -2
- package/dist/components/Badge/Badge.cjs +1 -1
- package/dist/components/Badge/Badge.js +15 -14
- package/dist/components/BearLogo/EmberLogo.cjs +1 -1
- package/dist/components/BearLogo/EmberLogo.js +3 -2
- package/dist/components/BottomNavigation/BottomNavigation.cjs +1 -1
- package/dist/components/BottomNavigation/BottomNavigation.js +3 -2
- package/dist/components/Button/Button.cjs +1 -1
- package/dist/components/Button/Button.js +56 -55
- package/dist/components/Button/Button.types.d.ts +7 -0
- package/dist/components/Carousel/Carousel.cjs +1 -1
- package/dist/components/Carousel/Carousel.const.cjs +1 -0
- package/dist/components/Carousel/Carousel.const.d.ts +12 -0
- package/dist/components/Carousel/Carousel.const.js +9 -0
- package/dist/components/Carousel/Carousel.d.ts +14 -3
- package/dist/components/Carousel/Carousel.js +222 -75
- package/dist/components/Carousel/Carousel.types.d.ts +32 -2
- package/dist/components/Carousel/index.d.ts +1 -1
- package/dist/components/Chip/Chip.cjs +1 -1
- package/dist/components/Chip/Chip.js +3 -2
- package/dist/components/CodeEditor/CodeEditor.cjs +5 -0
- package/dist/components/CodeEditor/CodeEditor.const.cjs +1 -0
- package/dist/components/CodeEditor/CodeEditor.const.d.ts +21 -0
- package/dist/components/CodeEditor/CodeEditor.const.js +119 -0
- package/dist/components/CodeEditor/CodeEditor.d.ts +22 -0
- package/dist/components/CodeEditor/CodeEditor.js +250 -0
- package/dist/components/CodeEditor/CodeEditor.types.d.ts +80 -0
- package/dist/components/CodeEditor/CodeEditor.utils.cjs +1 -0
- package/dist/components/CodeEditor/CodeEditor.utils.d.ts +6 -0
- package/dist/components/CodeEditor/CodeEditor.utils.js +75 -0
- package/dist/components/CodeEditor/index.d.ts +2 -0
- package/dist/components/Columns/Columns.cjs +1 -1
- package/dist/components/Columns/Columns.js +9 -8
- package/dist/components/CountdownTimer/CountdownTimer.cjs +1 -0
- package/dist/components/CountdownTimer/CountdownTimer.const.cjs +1 -0
- package/dist/components/CountdownTimer/CountdownTimer.const.d.ts +27 -0
- package/dist/components/CountdownTimer/CountdownTimer.const.js +35 -0
- package/dist/components/CountdownTimer/CountdownTimer.d.ts +7 -0
- package/dist/components/CountdownTimer/CountdownTimer.js +115 -0
- package/dist/components/CountdownTimer/CountdownTimer.types.d.ts +56 -0
- package/dist/components/CountdownTimer/index.d.ts +2 -0
- package/dist/components/Cropper/Cropper.cjs +1 -0
- package/dist/components/Cropper/Cropper.const.cjs +1 -0
- package/dist/components/Cropper/Cropper.const.d.ts +31 -0
- package/dist/components/Cropper/Cropper.const.js +33 -0
- package/dist/components/Cropper/Cropper.d.ts +21 -0
- package/dist/components/Cropper/Cropper.js +362 -0
- package/dist/components/Cropper/Cropper.types.d.ts +72 -0
- package/dist/components/Cropper/index.d.ts +2 -0
- package/dist/components/DataTable/DataTable.cjs +1 -1
- package/dist/components/DataTable/DataTable.js +5 -4
- package/dist/components/Divider/Divider.cjs +1 -1
- package/dist/components/Divider/Divider.js +15 -14
- package/dist/components/Dock/Dock.cjs +1 -0
- package/dist/components/Dock/Dock.const.cjs +1 -0
- package/dist/components/Dock/Dock.const.d.ts +25 -0
- package/dist/components/Dock/Dock.const.js +22 -0
- package/dist/components/Dock/Dock.d.ts +7 -0
- package/dist/components/Dock/Dock.js +144 -0
- package/dist/components/Dock/Dock.types.d.ts +42 -0
- package/dist/components/Dock/index.d.ts +2 -0
- package/dist/components/EmptyState/EmptyState.cjs +1 -1
- package/dist/components/EmptyState/EmptyState.js +7 -6
- package/dist/components/FileTree/FileTree.cjs +1 -0
- package/dist/components/FileTree/FileTree.d.ts +3 -0
- package/dist/components/FileTree/FileTree.js +46 -0
- package/dist/components/FileTree/FileTree.types.d.ts +30 -0
- package/dist/components/FileTree/index.d.ts +2 -0
- package/dist/components/GradientText/GradientText.cjs +1 -0
- package/dist/components/GradientText/GradientText.const.cjs +1 -0
- package/dist/components/GradientText/GradientText.const.d.ts +15 -0
- package/dist/components/GradientText/GradientText.const.js +36 -0
- package/dist/components/GradientText/GradientText.d.ts +7 -0
- package/dist/components/GradientText/GradientText.js +52 -0
- package/dist/components/GradientText/GradientText.types.d.ts +27 -0
- package/dist/components/GradientText/index.d.ts +2 -0
- package/dist/components/Highlight/Highlight.cjs +1 -1
- package/dist/components/Highlight/Highlight.const.cjs +1 -0
- package/dist/components/Highlight/Highlight.const.d.ts +8 -0
- package/dist/components/Highlight/Highlight.const.js +15 -0
- package/dist/components/Highlight/Highlight.d.ts +4 -0
- package/dist/components/Highlight/Highlight.js +32 -24
- package/dist/components/Highlight/Highlight.types.d.ts +9 -1
- package/dist/components/Highlight/index.d.ts +1 -1
- package/dist/components/Icon/Icon.cjs +1 -1
- package/dist/components/Icon/Icon.js +17 -16
- package/dist/components/Icon/index.cjs +1 -1
- package/dist/components/Icon/index.js +12 -11
- package/dist/components/Kbd/Kbd.cjs +1 -1
- package/dist/components/Kbd/Kbd.js +17 -16
- package/dist/components/Map/Map.cjs +1 -0
- package/dist/components/Map/Map.const.cjs +1 -0
- package/dist/components/Map/Map.const.d.ts +20 -0
- package/dist/components/Map/Map.const.js +26 -0
- package/dist/components/Map/Map.d.ts +20 -0
- package/dist/components/Map/Map.js +259 -0
- package/dist/components/Map/Map.types.d.ts +81 -0
- package/dist/components/Map/index.d.ts +2 -0
- package/dist/components/Marquee/Marquee.cjs +1 -0
- package/dist/components/Marquee/Marquee.const.cjs +1 -0
- package/dist/components/Marquee/Marquee.const.d.ts +11 -0
- package/dist/components/Marquee/Marquee.const.js +12 -0
- package/dist/components/Marquee/Marquee.d.ts +7 -0
- package/dist/components/Marquee/Marquee.js +106 -0
- package/dist/components/Marquee/Marquee.types.d.ts +32 -0
- package/dist/components/Marquee/index.d.ts +2 -0
- package/dist/components/Masonry/Masonry.cjs +1 -0
- package/dist/components/Masonry/Masonry.const.cjs +1 -0
- package/dist/components/Masonry/Masonry.const.d.ts +9 -0
- package/dist/components/Masonry/Masonry.const.js +9 -0
- package/dist/components/Masonry/Masonry.d.ts +7 -0
- package/dist/components/Masonry/Masonry.js +51 -0
- package/dist/components/Masonry/Masonry.types.d.ts +21 -0
- package/dist/components/Masonry/index.d.ts +2 -0
- package/dist/components/NavigableSelect/NavigableSelect.cjs +1 -0
- package/dist/components/NavigableSelect/NavigableSelect.const.cjs +1 -0
- package/dist/components/NavigableSelect/NavigableSelect.const.d.ts +23 -0
- package/dist/components/NavigableSelect/NavigableSelect.const.js +33 -0
- package/dist/components/NavigableSelect/NavigableSelect.d.ts +7 -0
- package/dist/components/NavigableSelect/NavigableSelect.js +361 -0
- package/dist/components/NavigableSelect/NavigableSelect.types.d.ts +56 -0
- package/dist/components/NavigableSelect/index.d.ts +2 -0
- package/dist/components/Progress/Progress.cjs +1 -1
- package/dist/components/Progress/Progress.js +3 -2
- package/dist/components/ResizablePanel/ResizablePanel.cjs +1 -0
- package/dist/components/ResizablePanel/ResizablePanel.const.cjs +1 -0
- package/dist/components/ResizablePanel/ResizablePanel.const.d.ts +11 -0
- package/dist/components/ResizablePanel/ResizablePanel.const.js +11 -0
- package/dist/components/ResizablePanel/ResizablePanel.d.ts +17 -0
- package/dist/components/ResizablePanel/ResizablePanel.js +70 -0
- package/dist/components/ResizablePanel/ResizablePanel.types.d.ts +21 -0
- package/dist/components/ResizablePanel/ResizablePanel.utils.cjs +1 -0
- package/dist/components/ResizablePanel/ResizablePanel.utils.d.ts +10 -0
- package/dist/components/ResizablePanel/ResizablePanel.utils.js +11 -0
- package/dist/components/ResizablePanel/index.d.ts +2 -0
- package/dist/components/ResizableTextarea/ResizableTextarea.cjs +1 -0
- package/dist/components/ResizableTextarea/ResizableTextarea.const.cjs +1 -0
- package/dist/components/ResizableTextarea/ResizableTextarea.const.d.ts +2 -0
- package/dist/components/ResizableTextarea/ResizableTextarea.const.js +5 -0
- package/dist/components/ResizableTextarea/ResizableTextarea.d.ts +3 -0
- package/dist/components/ResizableTextarea/ResizableTextarea.js +60 -0
- package/dist/components/ResizableTextarea/ResizableTextarea.types.d.ts +15 -0
- package/dist/components/ResizableTextarea/index.d.ts +2 -0
- package/dist/components/RichEditor/components/ToolbarButton/ToolbarButton.cjs +1 -1
- package/dist/components/RichEditor/components/ToolbarButton/ToolbarButton.js +3 -2
- package/dist/components/ScrollArea/ScrollArea.cjs +1 -1
- package/dist/components/ScrollArea/ScrollArea.js +3 -2
- package/dist/components/Sidebar/Sidebar.cjs +1 -1
- package/dist/components/Sidebar/Sidebar.js +13 -12
- package/dist/components/Spinner/Spinner.cjs +1 -1
- package/dist/components/Spinner/Spinner.js +3 -2
- package/dist/components/Spotlight/Spotlight.cjs +1 -0
- package/dist/components/Spotlight/Spotlight.const.cjs +1 -0
- package/dist/components/Spotlight/Spotlight.const.d.ts +18 -0
- package/dist/components/Spotlight/Spotlight.const.js +9 -0
- package/dist/components/Spotlight/Spotlight.d.ts +7 -0
- package/dist/components/Spotlight/Spotlight.js +220 -0
- package/dist/components/Spotlight/Spotlight.types.d.ts +51 -0
- package/dist/components/Spotlight/index.d.ts +2 -0
- package/dist/components/StatCard/StatCard.cjs +1 -1
- package/dist/components/StatCard/StatCard.js +9 -8
- package/dist/components/Statistic/Statistic.cjs +1 -1
- package/dist/components/Statistic/Statistic.js +7 -6
- package/dist/components/Switch/Switch.cjs +1 -1
- package/dist/components/Switch/Switch.js +11 -10
- package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.cjs +1 -1
- package/dist/components/TimePicker/components/TimePickerColumnsDropdown/TimePickerColumnsDropdown.js +16 -15
- package/dist/components/TimePicker/helpers/ClockFaceSvg.cjs +1 -1
- package/dist/components/TimePicker/helpers/ClockFaceSvg.js +13 -12
- package/dist/components/Transition/Transition.cjs +1 -0
- package/dist/components/Transition/Transition.const.cjs +1 -0
- package/dist/components/Transition/Transition.const.d.ts +15 -0
- package/dist/components/Transition/Transition.const.js +73 -0
- package/dist/components/Transition/Transition.d.ts +37 -0
- package/dist/components/Transition/Transition.js +107 -0
- package/dist/components/Transition/Transition.types.d.ts +69 -0
- package/dist/components/Transition/index.d.ts +2 -0
- package/dist/components/Typewriter/Typewriter.cjs +1 -0
- package/dist/components/Typewriter/Typewriter.const.cjs +1 -0
- package/dist/components/Typewriter/Typewriter.const.d.ts +22 -0
- package/dist/components/Typewriter/Typewriter.const.js +11 -0
- package/dist/components/Typewriter/Typewriter.d.ts +7 -0
- package/dist/components/Typewriter/Typewriter.js +88 -0
- package/dist/components/Typewriter/Typewriter.types.d.ts +32 -0
- package/dist/components/Typewriter/index.d.ts +2 -0
- package/dist/components/Typography/Typography.cjs +1 -1
- package/dist/components/Typography/Typography.const.cjs +1 -0
- package/dist/components/Typography/Typography.const.d.ts +22 -0
- package/dist/components/Typography/Typography.const.js +91 -0
- package/dist/components/Typography/Typography.js +75 -138
- package/dist/components/Typography/Typography.types.d.ts +17 -0
- package/dist/components/Watermark/Watermark.cjs +1 -0
- package/dist/components/Watermark/Watermark.const.cjs +1 -0
- package/dist/components/Watermark/Watermark.const.d.ts +30 -0
- package/dist/components/Watermark/Watermark.const.js +18 -0
- package/dist/components/Watermark/Watermark.d.ts +7 -0
- package/dist/components/Watermark/Watermark.js +96 -0
- package/dist/components/Watermark/Watermark.types.d.ts +35 -0
- package/dist/components/Watermark/index.d.ts +2 -0
- package/dist/components/index.cjs +1 -1
- package/dist/components/index.d.ts +33 -1
- package/dist/components/index.js +270 -237
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +24 -19
- package/dist/hooks/useAnimate.cjs +1 -0
- package/dist/hooks/useAnimate.d.ts +61 -0
- package/dist/hooks/useAnimate.js +125 -0
- package/dist/hooks/useResponsive.cjs +1 -0
- package/dist/hooks/useResponsive.d.ts +35 -0
- package/dist/hooks/useResponsive.js +74 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +335 -295
- package/dist/styles.css +1 -1
- package/dist/utils/createSlots.cjs +1 -0
- package/dist/utils/createSlots.d.ts +70 -0
- package/dist/utils/createSlots.js +65 -0
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { jsx as o, Fragment as J, jsxs as T } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as K, useRef as Q, useCallback as W, useState as A, useEffect as X } from "react";
|
|
3
|
+
import { cn as u } from "../../utils/cn.js";
|
|
4
|
+
import { DEFAULT_SEPARATOR as $, DEFAULT_LABELS as ee, MS_PER_SECOND as h, UPDATE_INTERVAL as re, SEPARATOR_MARGIN as ae, SIZE_DIGIT_CLASSES as v, SIZE_LABEL_CLASSES as D, SIZE_GAP_CLASSES as M, MS_PER_MINUTE as R, MS_PER_HOUR as L, MS_PER_DAY as N, PAD_LENGTH as te } from "./CountdownTimer.const.js";
|
|
5
|
+
const b = (a) => String(a).padStart(te, "0"), I = (a, t) => {
|
|
6
|
+
const e = Math.max(0, a - t);
|
|
7
|
+
return {
|
|
8
|
+
days: Math.floor(e / N),
|
|
9
|
+
hours: Math.floor(e % N / L),
|
|
10
|
+
minutes: Math.floor(e % L / R),
|
|
11
|
+
seconds: Math.floor(e % R / h),
|
|
12
|
+
totalSeconds: Math.floor(e / h),
|
|
13
|
+
isComplete: e <= 0
|
|
14
|
+
};
|
|
15
|
+
}, ie = (a) => {
|
|
16
|
+
const {
|
|
17
|
+
targetDate: t,
|
|
18
|
+
duration: e,
|
|
19
|
+
variant: _ = "default",
|
|
20
|
+
size: c = "md",
|
|
21
|
+
showDays: P = !0,
|
|
22
|
+
showHours: k = !0,
|
|
23
|
+
showMinutes: B = !0,
|
|
24
|
+
showSeconds: F = !0,
|
|
25
|
+
showLabels: U = !0,
|
|
26
|
+
showSeparator: G = !0,
|
|
27
|
+
separator: O = $,
|
|
28
|
+
labels: S,
|
|
29
|
+
onComplete: l,
|
|
30
|
+
onTick: i,
|
|
31
|
+
paused: w = !1,
|
|
32
|
+
render: E,
|
|
33
|
+
className: H,
|
|
34
|
+
style: Z,
|
|
35
|
+
testId: j
|
|
36
|
+
} = a, d = K(() => ({ ...ee, ...S }), [S]), y = Q(!1), z = W(() => t ? new Date(t).getTime() : e ? Date.now() + e * h : Date.now(), [t, e]), [m] = A(z), [s, V] = A(() => I(m, Date.now()));
|
|
37
|
+
if (X(() => {
|
|
38
|
+
if (w) return;
|
|
39
|
+
const r = () => {
|
|
40
|
+
const p = I(m, Date.now());
|
|
41
|
+
V(p), i == null || i(p), p.isComplete && !y.current && (y.current = !0, l == null || l());
|
|
42
|
+
};
|
|
43
|
+
r();
|
|
44
|
+
const f = setInterval(r, re);
|
|
45
|
+
return () => clearInterval(f);
|
|
46
|
+
}, [m, w, l, i]), E) return /* @__PURE__ */ o(J, { children: E(s) });
|
|
47
|
+
const x = v[c] ?? v.md, Y = D[c] ?? D.md, q = M[c] ?? M.md, n = [];
|
|
48
|
+
P && n.push({ value: b(s.days), label: d.days }), k && n.push({ value: b(s.hours), label: d.hours }), B && n.push({ value: b(s.minutes), label: d.minutes }), F && n.push({ value: b(s.seconds), label: d.seconds });
|
|
49
|
+
const g = _ === "card", C = _ === "flip";
|
|
50
|
+
return /* @__PURE__ */ o(
|
|
51
|
+
"div",
|
|
52
|
+
{
|
|
53
|
+
className: u("Bear-CountdownTimer", "bear-flex bear-items-center", q, H),
|
|
54
|
+
style: Z,
|
|
55
|
+
"data-testid": j,
|
|
56
|
+
role: "timer",
|
|
57
|
+
"aria-label": "Countdown timer",
|
|
58
|
+
children: n.map((r, f) => /* @__PURE__ */ T("div", { className: "Bear-CountdownTimer__segment bear-flex bear-items-center", children: [
|
|
59
|
+
f > 0 && G && !g && /* @__PURE__ */ o(
|
|
60
|
+
"span",
|
|
61
|
+
{
|
|
62
|
+
className: u(
|
|
63
|
+
"Bear-CountdownTimer__separator",
|
|
64
|
+
x,
|
|
65
|
+
ae,
|
|
66
|
+
"bear-text-gray-400 dark:bear-text-gray-500"
|
|
67
|
+
),
|
|
68
|
+
"aria-hidden": "true",
|
|
69
|
+
children: O
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ T("div", { className: "Bear-CountdownTimer__unit bear-flex bear-flex-col bear-items-center", children: [
|
|
73
|
+
/* @__PURE__ */ o(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
className: u(
|
|
77
|
+
"Bear-CountdownTimer__digit",
|
|
78
|
+
x,
|
|
79
|
+
"bear-tabular-nums bear-tracking-wider",
|
|
80
|
+
g && [
|
|
81
|
+
"bear-px-3 bear-py-2 bear-rounded-lg",
|
|
82
|
+
"bear-bg-gray-100 dark:bear-bg-gray-800",
|
|
83
|
+
"bear-border bear-border-gray-200 dark:bear-border-gray-700"
|
|
84
|
+
],
|
|
85
|
+
C && [
|
|
86
|
+
"bear-px-3 bear-py-2 bear-rounded-lg",
|
|
87
|
+
"bear-bg-gray-900 dark:bear-bg-gray-100",
|
|
88
|
+
"bear-text-white dark:bear-text-gray-900",
|
|
89
|
+
"bear-shadow-lg"
|
|
90
|
+
],
|
|
91
|
+
!g && !C && "bear-text-[var(--bear-text-primary)]"
|
|
92
|
+
),
|
|
93
|
+
children: r.value
|
|
94
|
+
}
|
|
95
|
+
),
|
|
96
|
+
U && /* @__PURE__ */ o(
|
|
97
|
+
"span",
|
|
98
|
+
{
|
|
99
|
+
className: u(
|
|
100
|
+
"Bear-CountdownTimer__label",
|
|
101
|
+
Y,
|
|
102
|
+
"bear-mt-1 bear-uppercase bear-tracking-widest",
|
|
103
|
+
"bear-text-gray-500 dark:bear-text-gray-400"
|
|
104
|
+
),
|
|
105
|
+
children: r.label
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
] })
|
|
109
|
+
] }, r.label))
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
ie as CountdownTimer
|
|
115
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type CountdownTimerVariant = 'default' | 'card' | 'minimal' | 'flip';
|
|
3
|
+
export type CountdownTimerSize = 'sm' | 'md' | 'lg' | 'xl';
|
|
4
|
+
export interface CountdownTimerProps {
|
|
5
|
+
/** Target date/time to count down to */
|
|
6
|
+
targetDate?: Date | string | number;
|
|
7
|
+
/** Duration in seconds (alternative to targetDate) */
|
|
8
|
+
duration?: number;
|
|
9
|
+
/** Visual variant */
|
|
10
|
+
variant?: CountdownTimerVariant | (string & {});
|
|
11
|
+
/** Size preset */
|
|
12
|
+
size?: CountdownTimerSize;
|
|
13
|
+
/** Whether to show days */
|
|
14
|
+
showDays?: boolean;
|
|
15
|
+
/** Whether to show hours */
|
|
16
|
+
showHours?: boolean;
|
|
17
|
+
/** Whether to show minutes */
|
|
18
|
+
showMinutes?: boolean;
|
|
19
|
+
/** Whether to show seconds */
|
|
20
|
+
showSeconds?: boolean;
|
|
21
|
+
/** Whether to show labels */
|
|
22
|
+
showLabels?: boolean;
|
|
23
|
+
/** Whether to show separator */
|
|
24
|
+
showSeparator?: boolean;
|
|
25
|
+
/** Separator character */
|
|
26
|
+
separator?: string;
|
|
27
|
+
/** Custom labels */
|
|
28
|
+
labels?: {
|
|
29
|
+
days?: string;
|
|
30
|
+
hours?: string;
|
|
31
|
+
minutes?: string;
|
|
32
|
+
seconds?: string;
|
|
33
|
+
};
|
|
34
|
+
/** Called when countdown reaches zero */
|
|
35
|
+
onComplete?: () => void;
|
|
36
|
+
/** Called every second */
|
|
37
|
+
onTick?: (remaining: CountdownTime) => void;
|
|
38
|
+
/** Whether countdown is paused */
|
|
39
|
+
paused?: boolean;
|
|
40
|
+
/** Custom renderer */
|
|
41
|
+
render?: (time: CountdownTime) => ReactNode;
|
|
42
|
+
/** Custom class name */
|
|
43
|
+
className?: string;
|
|
44
|
+
/** Custom style */
|
|
45
|
+
style?: React.CSSProperties;
|
|
46
|
+
/** Test ID */
|
|
47
|
+
testId?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface CountdownTime {
|
|
50
|
+
days: number;
|
|
51
|
+
hours: number;
|
|
52
|
+
minutes: number;
|
|
53
|
+
seconds: number;
|
|
54
|
+
totalSeconds: number;
|
|
55
|
+
isComplete: boolean;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("react"),S=require("../../utils/cn.cjs"),n=require("./Cropper.const.cjs"),ue=({src:p,crop:O,onCropChange:y,onCropComplete:v,aspectRatio:M="free",shape:I="rectangle",zoom:_,onZoomChange:N,minZoom:j=n.MIN_ZOOM,maxZoom:E=n.MAX_ZOOM,rotation:D,onRotationChange:k,showZoomSlider:o=!1,showRotationSlider:g=!1,showGrid:X=!1,gridOpacity:Y=n.DEFAULT_GRID_OPACITY,overlayColor:q=n.OVERLAY_COLOR,borderColor:B=n.BORDER_COLOR,borderWidth:V=n.BORDER_WIDTH,width:J="100%",height:K=400,className:Q,style:C,testId:Z})=>{const L=i.useRef(null),H=i.useRef(null),$=i.useRef(null),[ee,te]=i.useState(n.DEFAULT_CROP),[ae,re]=i.useState(n.DEFAULT_ZOOM),[se,ne]=i.useState(0),[f,W]=i.useState("none"),[w,P]=i.useState(null),[ie,ce]=i.useState(!1),[,le]=i.useState({w:0,h:0}),a=O??ee,x=_??ae,A=D??se,h=i.useMemo(()=>typeof M=="number"?M:n.ASPECT_RATIO_VALUES[M]??null,[M]),z=i.useCallback(e=>{O||te(e),y==null||y(e)},[O,y]),T=i.useCallback(e=>{const t=Math.max(j,Math.min(E,e));_||re(t),N==null||N(t)},[_,N,j,E]),he=i.useCallback(e=>{const t=Math.max(n.MIN_ROTATION,Math.min(n.MAX_ROTATION,e));D||ne(t),k==null||k(t)},[D,k]);i.useEffect(()=>{const e=new Image;e.crossOrigin="anonymous",e.onload=()=>{$.current=e,le({w:e.naturalWidth,h:e.naturalHeight}),ce(!0)},e.src=p},[p]);const b=i.useCallback(e=>{const t=L.current;if(!t)return e;const c=t.clientWidth,r=t.clientHeight-(o||g?60:0);let{x:l,y:m,width:u,height:d}=e;return u=Math.max(n.MIN_CROP_SIZE,u),d=Math.max(n.MIN_CROP_SIZE,d),h&&(d=u/h),l=Math.max(0,Math.min(c-u,l)),m=Math.max(0,Math.min(r-d,m)),{x:l,y:m,width:u,height:d}},[h,o,g]),G=i.useCallback(()=>{const e=H.current,t=$.current,c=L.current;if(!e||!t||!c)return"";const r=c.clientWidth,l=c.clientHeight-(o||g?60:0),m=t.naturalWidth/(r*x),u=t.naturalHeight/(l*x);e.width=a.width*m,e.height=a.height*u;const d=e.getContext("2d");return d?(I==="circle"&&(d.beginPath(),d.arc(e.width/2,e.height/2,Math.min(e.width,e.height)/2,0,Math.PI*2),d.clip()),d.drawImage(t,a.x*m,a.y*u,a.width*m,a.height*u,0,0,e.width,e.height),e.toDataURL("image/png")):""},[a,x,I,o,g]),R=i.useCallback(e=>t=>{t.preventDefault(),t.stopPropagation(),W(e),P({x:t.clientX,y:t.clientY,crop:{...a}})},[a]),de=i.useCallback(e=>{if(f==="none"||!w)return;const t=e.clientX-w.x,c=e.clientY-w.y,{crop:r}=w;let l;switch(f){case"move":l=b({...r,x:r.x+t,y:r.y+c});break;case"se":l=b({...r,width:r.width+t,height:h?(r.width+t)/h:r.height+c});break;case"sw":l=b({...r,x:r.x+t,width:r.width-t,height:h?(r.width-t)/h:r.height+c});break;case"ne":l=b({...r,y:h?r.y:r.y+c,width:r.width+t,height:h?(r.width+t)/h:r.height-c});break;case"nw":l=b({x:r.x+t,y:r.y+c,width:r.width-t,height:h?(r.width-t)/h:r.height-c});break;case"n":l=b({...r,y:r.y+c,height:r.height-c});break;case"s":l=b({...r,height:r.height+c});break;case"e":l=b({...r,width:r.width+t});break;case"w":l=b({...r,x:r.x+t,width:r.width-t});break;default:return}z(l)},[f,w,b,z,h]),U=i.useCallback(()=>{if(f!=="none"){const e=G();v==null||v(a,e)}W("none"),P(null)},[f,a,G,v]),be=i.useCallback(e=>{e.preventDefault();const t=e.deltaY>0?-n.ZOOM_STEP:n.ZOOM_STEP;T(x+t)},[x,T]),F=o||g?60:0;return s.jsxs("div",{className:S.cn("bear-relative bear-overflow-hidden bear-rounded-lg","bear-bg-gray-900 bear-select-none",Q),style:{width:J,height:K,...C},"data-testid":Z,children:[s.jsx("canvas",{ref:H,className:"bear-hidden"}),s.jsxs("div",{ref:L,className:"bear-relative bear-overflow-hidden bear-cursor-crosshair",style:{height:`calc(100% - ${F}px)`},onMouseMove:de,onMouseUp:U,onMouseLeave:U,onWheel:be,children:[ie&&s.jsx("img",{src:p,alt:"",className:"bear-absolute bear-inset-0 bear-w-full bear-h-full bear-object-contain bear-pointer-events-none",style:{transform:`scale(${x}) rotate(${A}deg)`,transition:f!=="none"?"none":"transform 0.2s ease"},draggable:!1}),s.jsxs("svg",{className:"bear-absolute bear-inset-0 bear-w-full bear-h-full bear-pointer-events-none",children:[s.jsx("defs",{children:s.jsxs("mask",{id:"crop-mask",children:[s.jsx("rect",{width:"100%",height:"100%",fill:"white"}),I==="circle"?s.jsx("ellipse",{cx:a.x+a.width/2,cy:a.y+a.height/2,rx:a.width/2,ry:a.height/2,fill:"black"}):s.jsx("rect",{x:a.x,y:a.y,width:a.width,height:a.height,fill:"black"})]})}),s.jsx("rect",{width:"100%",height:"100%",fill:q,mask:"url(#crop-mask)"})]}),s.jsx("div",{className:"bear-absolute bear-pointer-events-none",style:{left:a.x,top:a.y,width:a.width,height:a.height,border:`${V}px solid ${B}`,borderRadius:I==="circle"?"50%":0,boxShadow:"0 0 0 9999px transparent"},children:X&&s.jsxs("svg",{className:"bear-absolute bear-inset-0 bear-w-full bear-h-full",style:{opacity:Y},children:[Array.from({length:n.GRID_LINES-1}).map((e,t)=>s.jsx("line",{x1:`${(t+1)/n.GRID_LINES*100}%`,y1:"0",x2:`${(t+1)/n.GRID_LINES*100}%`,y2:"100%",stroke:"white",strokeWidth:"0.5"},`v-${t}`)),Array.from({length:n.GRID_LINES-1}).map((e,t)=>s.jsx("line",{x1:"0",y1:`${(t+1)/n.GRID_LINES*100}%`,x2:"100%",y2:`${(t+1)/n.GRID_LINES*100}%`,stroke:"white",strokeWidth:"0.5"},`h-${t}`))]})}),s.jsx("div",{className:"bear-absolute bear-cursor-move",style:{left:a.x,top:a.y,width:a.width,height:a.height},onMouseDown:R("move")}),["nw","ne","sw","se"].map(e=>{const t=e.includes("w"),c=e.includes("n");return s.jsx("div",{className:S.cn("bear-absolute bear-bg-white bear-border-2 bear-rounded-sm","bear-shadow-md bear-z-10"),style:{width:n.HANDLE_SIZE,height:n.HANDLE_SIZE,left:(t?a.x:a.x+a.width)-n.HANDLE_SIZE/2,top:(c?a.y:a.y+a.height)-n.HANDLE_SIZE/2,borderColor:"var(--bear-primary-500)",cursor:`${e}-resize`},onMouseDown:R(e)},e)}),["n","s","e","w"].map(e=>{const t=e==="n"||e==="s";return s.jsx("div",{className:"bear-absolute bear-z-10",style:{left:e==="w"?a.x-4:e==="e"?a.x+a.width-4:a.x+a.width/2-12,top:e==="n"?a.y-4:e==="s"?a.y+a.height-4:a.y+a.height/2-12,width:t?24:8,height:t?8:24,cursor:t?`${e}-resize`:`${e}-resize`},onMouseDown:R(e)},e)})]}),(o||g)&&s.jsxs("div",{className:S.cn("bear-flex bear-items-center bear-gap-4 bear-px-4","bear-bg-gray-800/90 bear-backdrop-blur-sm"),style:{height:F},children:[o&&s.jsxs("div",{className:"bear-flex bear-items-center bear-gap-2 bear-flex-1",children:[s.jsx("svg",{className:"bear-w-4 bear-h-4 bear-text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7"})}),s.jsx("input",{type:"range",min:j,max:E,step:n.ZOOM_STEP,value:x,onChange:e=>T(parseFloat(e.target.value)),className:"bear-flex-1 bear-h-1 bear-accent-pink-500"}),s.jsxs("span",{className:"bear-text-xs bear-text-gray-400 bear-w-10 bear-text-right",children:[(x*100).toFixed(0),"%"]})]}),g&&s.jsxs("div",{className:"bear-flex bear-items-center bear-gap-2 bear-flex-1",children:[s.jsx("svg",{className:"bear-w-4 bear-h-4 bear-text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),s.jsx("input",{type:"range",min:n.MIN_ROTATION,max:n.MAX_ROTATION,step:n.ROTATION_STEP,value:A,onChange:e=>he(parseFloat(e.target.value)),className:"bear-flex-1 bear-h-1 bear-accent-pink-500"}),s.jsxs("span",{className:"bear-text-xs bear-text-gray-400 bear-w-10 bear-text-right",children:[A,"°"]})]})]})]})};exports.Cropper=ue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O={x:50,y:50,width:200,height:200},_=20,T=1,R=.5,A=5,E=.1,I=-180,t=180,o=1,n="rgba(0, 0, 0, 0.6)",M="#ffffff",c=2,s=3,D=.4,L=12,N={free:null,"1:1":1,"4:3":4/3,"3:2":3/2,"16:9":16/9,"2:3":2/3,"3:4":3/4,"9:16":9/16};exports.ASPECT_RATIO_VALUES=N;exports.BORDER_COLOR=M;exports.BORDER_WIDTH=c;exports.DEFAULT_CROP=O;exports.DEFAULT_GRID_OPACITY=D;exports.DEFAULT_ZOOM=T;exports.GRID_LINES=s;exports.HANDLE_SIZE=L;exports.MAX_ROTATION=t;exports.MAX_ZOOM=A;exports.MIN_CROP_SIZE=_;exports.MIN_ROTATION=I;exports.MIN_ZOOM=R;exports.OVERLAY_COLOR=n;exports.ROTATION_STEP=o;exports.ZOOM_STEP=E;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CropArea, AspectRatioPreset } from './Cropper.types';
|
|
2
|
+
/** Default crop area */
|
|
3
|
+
export declare const DEFAULT_CROP: CropArea;
|
|
4
|
+
/** Min crop dimensions */
|
|
5
|
+
export declare const MIN_CROP_SIZE = 20;
|
|
6
|
+
/** Default zoom */
|
|
7
|
+
export declare const DEFAULT_ZOOM = 1;
|
|
8
|
+
/** Zoom range */
|
|
9
|
+
export declare const MIN_ZOOM = 0.5;
|
|
10
|
+
export declare const MAX_ZOOM = 5;
|
|
11
|
+
/** Zoom step for slider */
|
|
12
|
+
export declare const ZOOM_STEP = 0.1;
|
|
13
|
+
/** Rotation range */
|
|
14
|
+
export declare const MIN_ROTATION = -180;
|
|
15
|
+
export declare const MAX_ROTATION = 180;
|
|
16
|
+
/** Rotation step for slider */
|
|
17
|
+
export declare const ROTATION_STEP = 1;
|
|
18
|
+
/** Default overlay color */
|
|
19
|
+
export declare const OVERLAY_COLOR = "rgba(0, 0, 0, 0.6)";
|
|
20
|
+
/** Default border color */
|
|
21
|
+
export declare const BORDER_COLOR = "#ffffff";
|
|
22
|
+
/** Default border width */
|
|
23
|
+
export declare const BORDER_WIDTH = 2;
|
|
24
|
+
/** Grid line count per axis */
|
|
25
|
+
export declare const GRID_LINES = 3;
|
|
26
|
+
/** Default grid opacity */
|
|
27
|
+
export declare const DEFAULT_GRID_OPACITY = 0.4;
|
|
28
|
+
/** Handle size in px */
|
|
29
|
+
export declare const HANDLE_SIZE = 12;
|
|
30
|
+
/** Aspect ratio numeric values */
|
|
31
|
+
export declare const ASPECT_RATIO_VALUES: Record<AspectRatioPreset, number | null>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const O = {
|
|
2
|
+
x: 50,
|
|
3
|
+
y: 50,
|
|
4
|
+
width: 200,
|
|
5
|
+
height: 200
|
|
6
|
+
}, t = 20, _ = 1, n = 0.5, o = 5, c = 0.1, s = -180, R = 180, T = 1, A = "rgba(0, 0, 0, 0.6)", E = "#ffffff", I = 2, D = 3, L = 0.4, M = 12, N = {
|
|
7
|
+
free: null,
|
|
8
|
+
"1:1": 1,
|
|
9
|
+
"4:3": 4 / 3,
|
|
10
|
+
"3:2": 3 / 2,
|
|
11
|
+
"16:9": 16 / 9,
|
|
12
|
+
"2:3": 2 / 3,
|
|
13
|
+
"3:4": 3 / 4,
|
|
14
|
+
"9:16": 9 / 16
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
N as ASPECT_RATIO_VALUES,
|
|
18
|
+
E as BORDER_COLOR,
|
|
19
|
+
I as BORDER_WIDTH,
|
|
20
|
+
O as DEFAULT_CROP,
|
|
21
|
+
L as DEFAULT_GRID_OPACITY,
|
|
22
|
+
_ as DEFAULT_ZOOM,
|
|
23
|
+
D as GRID_LINES,
|
|
24
|
+
M as HANDLE_SIZE,
|
|
25
|
+
R as MAX_ROTATION,
|
|
26
|
+
o as MAX_ZOOM,
|
|
27
|
+
t as MIN_CROP_SIZE,
|
|
28
|
+
s as MIN_ROTATION,
|
|
29
|
+
n as MIN_ZOOM,
|
|
30
|
+
A as OVERLAY_COLOR,
|
|
31
|
+
T as ROTATION_STEP,
|
|
32
|
+
c as ZOOM_STEP
|
|
33
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { CropperProps } from './Cropper.types';
|
|
3
|
+
/**
|
|
4
|
+
* Cropper - Image cropping component with zoom, rotate, and aspect ratio
|
|
5
|
+
*
|
|
6
|
+
* @description
|
|
7
|
+
* Interactive image cropper with handles, zoom, rotation, grid overlay,
|
|
8
|
+
* and aspect ratio presets. Outputs cropped image as data URL.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <Cropper
|
|
13
|
+
* src="/photo.jpg"
|
|
14
|
+
* aspectRatio="16:9"
|
|
15
|
+
* showZoomSlider
|
|
16
|
+
* showGrid
|
|
17
|
+
* onCropComplete={(crop, url) => console.log(url)}
|
|
18
|
+
* />
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const Cropper: FC<CropperProps>;
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { jsxs as d, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as U, useState as f, useMemo as ve, useCallback as o, useEffect as Me } from "react";
|
|
3
|
+
import { cn as F } from "../../utils/cn.js";
|
|
4
|
+
import { DEFAULT_CROP as pe, DEFAULT_ZOOM as ke, ASPECT_RATIO_VALUES as Ne, MIN_ZOOM as Oe, MAX_ZOOM as Ie, MIN_CROP_SIZE as K, ZOOM_STEP as P, OVERLAY_COLOR as _e, BORDER_WIDTH as De, BORDER_COLOR as Le, DEFAULT_GRID_OPACITY as Ae, GRID_LINES as y, HANDLE_SIZE as _, ROTATION_STEP as Te, MAX_ROTATION as Q, MIN_ROTATION as S } from "./Cropper.const.js";
|
|
5
|
+
const Re = ({
|
|
6
|
+
src: D,
|
|
7
|
+
crop: L,
|
|
8
|
+
onCropChange: M,
|
|
9
|
+
onCropComplete: p,
|
|
10
|
+
aspectRatio: k = "free",
|
|
11
|
+
shape: N = "rectangle",
|
|
12
|
+
zoom: A,
|
|
13
|
+
onZoomChange: O,
|
|
14
|
+
minZoom: T = Oe,
|
|
15
|
+
maxZoom: E = Ie,
|
|
16
|
+
rotation: $,
|
|
17
|
+
onRotationChange: I,
|
|
18
|
+
showZoomSlider: g = !1,
|
|
19
|
+
showRotationSlider: m = !1,
|
|
20
|
+
showGrid: Z = !1,
|
|
21
|
+
gridOpacity: C = Ae,
|
|
22
|
+
overlayColor: ee = _e,
|
|
23
|
+
borderColor: te = Le,
|
|
24
|
+
borderWidth: ae = De,
|
|
25
|
+
width: re = "100%",
|
|
26
|
+
height: ie = 400,
|
|
27
|
+
className: ne,
|
|
28
|
+
style: se,
|
|
29
|
+
testId: he
|
|
30
|
+
}) => {
|
|
31
|
+
const H = U(null), Y = U(null), j = U(null), [ce, le] = f(pe), [de, be] = f(ke), [oe, ue] = f(0), [w, X] = f("none"), [v, B] = f(null), [ge, me] = f(!1), [, xe] = f({ w: 0, h: 0 }), a = L ?? ce, u = A ?? de, W = $ ?? oe, h = ve(() => typeof k == "number" ? k : Ne[k] ?? null, [k]), G = o(
|
|
32
|
+
(e) => {
|
|
33
|
+
L || le(e), M == null || M(e);
|
|
34
|
+
},
|
|
35
|
+
[L, M]
|
|
36
|
+
), R = o(
|
|
37
|
+
(e) => {
|
|
38
|
+
const t = Math.max(T, Math.min(E, e));
|
|
39
|
+
A || be(t), O == null || O(t);
|
|
40
|
+
},
|
|
41
|
+
[A, O, T, E]
|
|
42
|
+
), fe = o(
|
|
43
|
+
(e) => {
|
|
44
|
+
const t = Math.max(S, Math.min(Q, e));
|
|
45
|
+
$ || ue(t), I == null || I(t);
|
|
46
|
+
},
|
|
47
|
+
[$, I]
|
|
48
|
+
);
|
|
49
|
+
Me(() => {
|
|
50
|
+
const e = new Image();
|
|
51
|
+
e.crossOrigin = "anonymous", e.onload = () => {
|
|
52
|
+
j.current = e, xe({ w: e.naturalWidth, h: e.naturalHeight }), me(!0);
|
|
53
|
+
}, e.src = D;
|
|
54
|
+
}, [D]);
|
|
55
|
+
const l = o(
|
|
56
|
+
(e) => {
|
|
57
|
+
const t = H.current;
|
|
58
|
+
if (!t) return e;
|
|
59
|
+
const i = t.clientWidth, r = t.clientHeight - (g || m ? 60 : 0);
|
|
60
|
+
let { x: s, y: x, width: b, height: c } = e;
|
|
61
|
+
return b = Math.max(K, b), c = Math.max(K, c), h && (c = b / h), s = Math.max(0, Math.min(i - b, s)), x = Math.max(0, Math.min(r - c, x)), { x: s, y: x, width: b, height: c };
|
|
62
|
+
},
|
|
63
|
+
[h, g, m]
|
|
64
|
+
), V = o(() => {
|
|
65
|
+
const e = Y.current, t = j.current, i = H.current;
|
|
66
|
+
if (!e || !t || !i) return "";
|
|
67
|
+
const r = i.clientWidth, s = i.clientHeight - (g || m ? 60 : 0), x = t.naturalWidth / (r * u), b = t.naturalHeight / (s * u);
|
|
68
|
+
e.width = a.width * x, e.height = a.height * b;
|
|
69
|
+
const c = e.getContext("2d");
|
|
70
|
+
return c ? (N === "circle" && (c.beginPath(), c.arc(e.width / 2, e.height / 2, Math.min(e.width, e.height) / 2, 0, Math.PI * 2), c.clip()), c.drawImage(
|
|
71
|
+
t,
|
|
72
|
+
a.x * x,
|
|
73
|
+
a.y * b,
|
|
74
|
+
a.width * x,
|
|
75
|
+
a.height * b,
|
|
76
|
+
0,
|
|
77
|
+
0,
|
|
78
|
+
e.width,
|
|
79
|
+
e.height
|
|
80
|
+
), e.toDataURL("image/png")) : "";
|
|
81
|
+
}, [a, u, N, g, m]), z = o(
|
|
82
|
+
(e) => (t) => {
|
|
83
|
+
t.preventDefault(), t.stopPropagation(), X(e), B({ x: t.clientX, y: t.clientY, crop: { ...a } });
|
|
84
|
+
},
|
|
85
|
+
[a]
|
|
86
|
+
), we = o(
|
|
87
|
+
(e) => {
|
|
88
|
+
if (w === "none" || !v) return;
|
|
89
|
+
const t = e.clientX - v.x, i = e.clientY - v.y, { crop: r } = v;
|
|
90
|
+
let s;
|
|
91
|
+
switch (w) {
|
|
92
|
+
case "move":
|
|
93
|
+
s = l({
|
|
94
|
+
...r,
|
|
95
|
+
x: r.x + t,
|
|
96
|
+
y: r.y + i
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
case "se":
|
|
100
|
+
s = l({
|
|
101
|
+
...r,
|
|
102
|
+
width: r.width + t,
|
|
103
|
+
height: h ? (r.width + t) / h : r.height + i
|
|
104
|
+
});
|
|
105
|
+
break;
|
|
106
|
+
case "sw":
|
|
107
|
+
s = l({
|
|
108
|
+
...r,
|
|
109
|
+
x: r.x + t,
|
|
110
|
+
width: r.width - t,
|
|
111
|
+
height: h ? (r.width - t) / h : r.height + i
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
case "ne":
|
|
115
|
+
s = l({
|
|
116
|
+
...r,
|
|
117
|
+
y: h ? r.y : r.y + i,
|
|
118
|
+
width: r.width + t,
|
|
119
|
+
height: h ? (r.width + t) / h : r.height - i
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
case "nw":
|
|
123
|
+
s = l({
|
|
124
|
+
x: r.x + t,
|
|
125
|
+
y: r.y + i,
|
|
126
|
+
width: r.width - t,
|
|
127
|
+
height: h ? (r.width - t) / h : r.height - i
|
|
128
|
+
});
|
|
129
|
+
break;
|
|
130
|
+
case "n":
|
|
131
|
+
s = l({ ...r, y: r.y + i, height: r.height - i });
|
|
132
|
+
break;
|
|
133
|
+
case "s":
|
|
134
|
+
s = l({ ...r, height: r.height + i });
|
|
135
|
+
break;
|
|
136
|
+
case "e":
|
|
137
|
+
s = l({ ...r, width: r.width + t });
|
|
138
|
+
break;
|
|
139
|
+
case "w":
|
|
140
|
+
s = l({ ...r, x: r.x + t, width: r.width - t });
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
G(s);
|
|
146
|
+
},
|
|
147
|
+
[w, v, l, G, h]
|
|
148
|
+
), q = o(() => {
|
|
149
|
+
if (w !== "none") {
|
|
150
|
+
const e = V();
|
|
151
|
+
p == null || p(a, e);
|
|
152
|
+
}
|
|
153
|
+
X("none"), B(null);
|
|
154
|
+
}, [w, a, V, p]), ye = o(
|
|
155
|
+
(e) => {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
const t = e.deltaY > 0 ? -P : P;
|
|
158
|
+
R(u + t);
|
|
159
|
+
},
|
|
160
|
+
[u, R]
|
|
161
|
+
), J = g || m ? 60 : 0;
|
|
162
|
+
return /* @__PURE__ */ d(
|
|
163
|
+
"div",
|
|
164
|
+
{
|
|
165
|
+
className: F(
|
|
166
|
+
"bear-relative bear-overflow-hidden bear-rounded-lg",
|
|
167
|
+
"bear-bg-gray-900 bear-select-none",
|
|
168
|
+
ne
|
|
169
|
+
),
|
|
170
|
+
style: { width: re, height: ie, ...se },
|
|
171
|
+
"data-testid": he,
|
|
172
|
+
children: [
|
|
173
|
+
/* @__PURE__ */ n("canvas", { ref: Y, className: "bear-hidden" }),
|
|
174
|
+
/* @__PURE__ */ d(
|
|
175
|
+
"div",
|
|
176
|
+
{
|
|
177
|
+
ref: H,
|
|
178
|
+
className: "bear-relative bear-overflow-hidden bear-cursor-crosshair",
|
|
179
|
+
style: { height: `calc(100% - ${J}px)` },
|
|
180
|
+
onMouseMove: we,
|
|
181
|
+
onMouseUp: q,
|
|
182
|
+
onMouseLeave: q,
|
|
183
|
+
onWheel: ye,
|
|
184
|
+
children: [
|
|
185
|
+
ge && /* @__PURE__ */ n(
|
|
186
|
+
"img",
|
|
187
|
+
{
|
|
188
|
+
src: D,
|
|
189
|
+
alt: "",
|
|
190
|
+
className: "bear-absolute bear-inset-0 bear-w-full bear-h-full bear-object-contain bear-pointer-events-none",
|
|
191
|
+
style: {
|
|
192
|
+
transform: `scale(${u}) rotate(${W}deg)`,
|
|
193
|
+
transition: w !== "none" ? "none" : "transform 0.2s ease"
|
|
194
|
+
},
|
|
195
|
+
draggable: !1
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
/* @__PURE__ */ d("svg", { className: "bear-absolute bear-inset-0 bear-w-full bear-h-full bear-pointer-events-none", children: [
|
|
199
|
+
/* @__PURE__ */ n("defs", { children: /* @__PURE__ */ d("mask", { id: "crop-mask", children: [
|
|
200
|
+
/* @__PURE__ */ n("rect", { width: "100%", height: "100%", fill: "white" }),
|
|
201
|
+
N === "circle" ? /* @__PURE__ */ n(
|
|
202
|
+
"ellipse",
|
|
203
|
+
{
|
|
204
|
+
cx: a.x + a.width / 2,
|
|
205
|
+
cy: a.y + a.height / 2,
|
|
206
|
+
rx: a.width / 2,
|
|
207
|
+
ry: a.height / 2,
|
|
208
|
+
fill: "black"
|
|
209
|
+
}
|
|
210
|
+
) : /* @__PURE__ */ n("rect", { x: a.x, y: a.y, width: a.width, height: a.height, fill: "black" })
|
|
211
|
+
] }) }),
|
|
212
|
+
/* @__PURE__ */ n("rect", { width: "100%", height: "100%", fill: ee, mask: "url(#crop-mask)" })
|
|
213
|
+
] }),
|
|
214
|
+
/* @__PURE__ */ n(
|
|
215
|
+
"div",
|
|
216
|
+
{
|
|
217
|
+
className: "bear-absolute bear-pointer-events-none",
|
|
218
|
+
style: {
|
|
219
|
+
left: a.x,
|
|
220
|
+
top: a.y,
|
|
221
|
+
width: a.width,
|
|
222
|
+
height: a.height,
|
|
223
|
+
border: `${ae}px solid ${te}`,
|
|
224
|
+
borderRadius: N === "circle" ? "50%" : 0,
|
|
225
|
+
boxShadow: "0 0 0 9999px transparent"
|
|
226
|
+
},
|
|
227
|
+
children: Z && /* @__PURE__ */ d("svg", { className: "bear-absolute bear-inset-0 bear-w-full bear-h-full", style: { opacity: C }, children: [
|
|
228
|
+
Array.from({ length: y - 1 }).map((e, t) => /* @__PURE__ */ n(
|
|
229
|
+
"line",
|
|
230
|
+
{
|
|
231
|
+
x1: `${(t + 1) / y * 100}%`,
|
|
232
|
+
y1: "0",
|
|
233
|
+
x2: `${(t + 1) / y * 100}%`,
|
|
234
|
+
y2: "100%",
|
|
235
|
+
stroke: "white",
|
|
236
|
+
strokeWidth: "0.5"
|
|
237
|
+
},
|
|
238
|
+
`v-${t}`
|
|
239
|
+
)),
|
|
240
|
+
Array.from({ length: y - 1 }).map((e, t) => /* @__PURE__ */ n(
|
|
241
|
+
"line",
|
|
242
|
+
{
|
|
243
|
+
x1: "0",
|
|
244
|
+
y1: `${(t + 1) / y * 100}%`,
|
|
245
|
+
x2: "100%",
|
|
246
|
+
y2: `${(t + 1) / y * 100}%`,
|
|
247
|
+
stroke: "white",
|
|
248
|
+
strokeWidth: "0.5"
|
|
249
|
+
},
|
|
250
|
+
`h-${t}`
|
|
251
|
+
))
|
|
252
|
+
] })
|
|
253
|
+
}
|
|
254
|
+
),
|
|
255
|
+
/* @__PURE__ */ n(
|
|
256
|
+
"div",
|
|
257
|
+
{
|
|
258
|
+
className: "bear-absolute bear-cursor-move",
|
|
259
|
+
style: { left: a.x, top: a.y, width: a.width, height: a.height },
|
|
260
|
+
onMouseDown: z("move")
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
["nw", "ne", "sw", "se"].map((e) => {
|
|
264
|
+
const t = e.includes("w"), i = e.includes("n");
|
|
265
|
+
return /* @__PURE__ */ n(
|
|
266
|
+
"div",
|
|
267
|
+
{
|
|
268
|
+
className: F(
|
|
269
|
+
"bear-absolute bear-bg-white bear-border-2 bear-rounded-sm",
|
|
270
|
+
"bear-shadow-md bear-z-10"
|
|
271
|
+
),
|
|
272
|
+
style: {
|
|
273
|
+
width: _,
|
|
274
|
+
height: _,
|
|
275
|
+
left: (t ? a.x : a.x + a.width) - _ / 2,
|
|
276
|
+
top: (i ? a.y : a.y + a.height) - _ / 2,
|
|
277
|
+
borderColor: "var(--bear-primary-500)",
|
|
278
|
+
cursor: `${e}-resize`
|
|
279
|
+
},
|
|
280
|
+
onMouseDown: z(e)
|
|
281
|
+
},
|
|
282
|
+
e
|
|
283
|
+
);
|
|
284
|
+
}),
|
|
285
|
+
["n", "s", "e", "w"].map((e) => {
|
|
286
|
+
const t = e === "n" || e === "s";
|
|
287
|
+
return /* @__PURE__ */ n(
|
|
288
|
+
"div",
|
|
289
|
+
{
|
|
290
|
+
className: "bear-absolute bear-z-10",
|
|
291
|
+
style: {
|
|
292
|
+
left: e === "w" ? a.x - 4 : e === "e" ? a.x + a.width - 4 : a.x + a.width / 2 - 12,
|
|
293
|
+
top: e === "n" ? a.y - 4 : e === "s" ? a.y + a.height - 4 : a.y + a.height / 2 - 12,
|
|
294
|
+
width: t ? 24 : 8,
|
|
295
|
+
height: t ? 8 : 24,
|
|
296
|
+
cursor: t ? `${e}-resize` : `${e}-resize`
|
|
297
|
+
},
|
|
298
|
+
onMouseDown: z(e)
|
|
299
|
+
},
|
|
300
|
+
e
|
|
301
|
+
);
|
|
302
|
+
})
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
),
|
|
306
|
+
(g || m) && /* @__PURE__ */ d(
|
|
307
|
+
"div",
|
|
308
|
+
{
|
|
309
|
+
className: F(
|
|
310
|
+
"bear-flex bear-items-center bear-gap-4 bear-px-4",
|
|
311
|
+
"bear-bg-gray-800/90 bear-backdrop-blur-sm"
|
|
312
|
+
),
|
|
313
|
+
style: { height: J },
|
|
314
|
+
children: [
|
|
315
|
+
g && /* @__PURE__ */ d("div", { className: "bear-flex bear-items-center bear-gap-2 bear-flex-1", children: [
|
|
316
|
+
/* @__PURE__ */ n("svg", { className: "bear-w-4 bear-h-4 bear-text-gray-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ n("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7" }) }),
|
|
317
|
+
/* @__PURE__ */ n(
|
|
318
|
+
"input",
|
|
319
|
+
{
|
|
320
|
+
type: "range",
|
|
321
|
+
min: T,
|
|
322
|
+
max: E,
|
|
323
|
+
step: P,
|
|
324
|
+
value: u,
|
|
325
|
+
onChange: (e) => R(parseFloat(e.target.value)),
|
|
326
|
+
className: "bear-flex-1 bear-h-1 bear-accent-pink-500"
|
|
327
|
+
}
|
|
328
|
+
),
|
|
329
|
+
/* @__PURE__ */ d("span", { className: "bear-text-xs bear-text-gray-400 bear-w-10 bear-text-right", children: [
|
|
330
|
+
(u * 100).toFixed(0),
|
|
331
|
+
"%"
|
|
332
|
+
] })
|
|
333
|
+
] }),
|
|
334
|
+
m && /* @__PURE__ */ d("div", { className: "bear-flex bear-items-center bear-gap-2 bear-flex-1", children: [
|
|
335
|
+
/* @__PURE__ */ n("svg", { className: "bear-w-4 bear-h-4 bear-text-gray-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ n("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" }) }),
|
|
336
|
+
/* @__PURE__ */ n(
|
|
337
|
+
"input",
|
|
338
|
+
{
|
|
339
|
+
type: "range",
|
|
340
|
+
min: S,
|
|
341
|
+
max: Q,
|
|
342
|
+
step: Te,
|
|
343
|
+
value: W,
|
|
344
|
+
onChange: (e) => fe(parseFloat(e.target.value)),
|
|
345
|
+
className: "bear-flex-1 bear-h-1 bear-accent-pink-500"
|
|
346
|
+
}
|
|
347
|
+
),
|
|
348
|
+
/* @__PURE__ */ d("span", { className: "bear-text-xs bear-text-gray-400 bear-w-10 bear-text-right", children: [
|
|
349
|
+
W,
|
|
350
|
+
"°"
|
|
351
|
+
] })
|
|
352
|
+
] })
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
)
|
|
356
|
+
]
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
};
|
|
360
|
+
export {
|
|
361
|
+
Re as Cropper
|
|
362
|
+
};
|