@hai-dev/ui-kit 1.0.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 +73 -0
- package/dist/Button-BjNjCLw8.js +6428 -0
- package/dist/DialogTitle-1A3dJ174.js +3258 -0
- package/dist/assets/error-upload-dialog.css +1 -0
- package/dist/assets/photo-crop-uploader.css +1 -0
- package/dist/assets/upload-button.css +1 -0
- package/dist/assets/upload-dialog.css +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/photo-crop-uploader/components/error-upload-dialog/error-upload-dialog.d.ts +3 -0
- package/dist/components/photo-crop-uploader/components/error-upload-dialog/error-upload-dialog.js +33 -0
- package/dist/components/photo-crop-uploader/components/error-upload-dialog/index.d.ts +1 -0
- package/dist/components/photo-crop-uploader/components/error-upload-dialog/index.js +4 -0
- package/dist/components/photo-crop-uploader/components/error-upload-dialog/types.d.ts +9 -0
- package/dist/components/photo-crop-uploader/components/error-upload-dialog/types.js +1 -0
- package/dist/components/photo-crop-uploader/components/index.d.ts +3 -0
- package/dist/components/photo-crop-uploader/components/index.js +8 -0
- package/dist/components/photo-crop-uploader/components/upload-button/constants.d.ts +3 -0
- package/dist/components/photo-crop-uploader/components/upload-button/constants.js +6 -0
- package/dist/components/photo-crop-uploader/components/upload-button/index.d.ts +1 -0
- package/dist/components/photo-crop-uploader/components/upload-button/index.js +4 -0
- package/dist/components/photo-crop-uploader/components/upload-button/types.d.ts +12 -0
- package/dist/components/photo-crop-uploader/components/upload-button/types.js +1 -0
- package/dist/components/photo-crop-uploader/components/upload-button/upload-button.d.ts +3 -0
- package/dist/components/photo-crop-uploader/components/upload-button/upload-button.js +90 -0
- package/dist/components/photo-crop-uploader/components/upload-dialog/index.d.ts +1 -0
- package/dist/components/photo-crop-uploader/components/upload-dialog/index.js +4 -0
- package/dist/components/photo-crop-uploader/components/upload-dialog/types.d.ts +27 -0
- package/dist/components/photo-crop-uploader/components/upload-dialog/types.js +1 -0
- package/dist/components/photo-crop-uploader/components/upload-dialog/upload-dialog.d.ts +3 -0
- package/dist/components/photo-crop-uploader/components/upload-dialog/upload-dialog.js +123 -0
- package/dist/components/photo-crop-uploader/constants.d.ts +41 -0
- package/dist/components/photo-crop-uploader/constants.js +64 -0
- package/dist/components/photo-crop-uploader/errors/index.d.ts +2 -0
- package/dist/components/photo-crop-uploader/errors/index.js +6 -0
- package/dist/components/photo-crop-uploader/errors/photo-file.error.d.ts +7 -0
- package/dist/components/photo-crop-uploader/errors/photo-file.error.js +15 -0
- package/dist/components/photo-crop-uploader/errors/photo-size.error.d.ts +10 -0
- package/dist/components/photo-crop-uploader/errors/photo-size.error.js +19 -0
- package/dist/components/photo-crop-uploader/index.d.ts +1 -0
- package/dist/components/photo-crop-uploader/index.js +4 -0
- package/dist/components/photo-crop-uploader/locale.d.ts +2 -0
- package/dist/components/photo-crop-uploader/locale.js +47 -0
- package/dist/components/photo-crop-uploader/photo-crop-uploader.d.ts +3 -0
- package/dist/components/photo-crop-uploader/photo-crop-uploader.js +143 -0
- package/dist/components/photo-crop-uploader/photo-crop-uploder.stories.d.ts +7 -0
- package/dist/components/photo-crop-uploader/types.d.ts +33 -0
- package/dist/components/photo-crop-uploader/types.js +1 -0
- package/dist/components/photo-crop-uploader/utils/get-croped-photo.d.ts +4 -0
- package/dist/components/photo-crop-uploader/utils/get-croped-photo.js +26 -0
- package/dist/components/photo-crop-uploader/utils/get-photo-crop.d.ts +2 -0
- package/dist/components/photo-crop-uploader/utils/get-photo-crop.js +18 -0
- package/dist/components/photo-crop-uploader/utils/index.d.ts +4 -0
- package/dist/components/photo-crop-uploader/utils/index.js +10 -0
- package/dist/components/photo-crop-uploader/utils/read-photo.d.ts +3 -0
- package/dist/components/photo-crop-uploader/utils/read-photo.js +51 -0
- package/dist/components/photo-crop-uploader/utils/validate-photo-file.d.ts +3 -0
- package/dist/components/photo-crop-uploader/utils/validate-photo-file.js +24 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +6 -0
- package/dist/index-BiffjjQq.js +431 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +26 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import p, { PureComponent as H, createRef as k } from "react";
|
|
2
|
+
var X = Object.defineProperty, $ = (s, t, e) => t in s ? X(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, u = (s, t, e) => $(s, typeof t != "symbol" ? t + "" : t, e);
|
|
3
|
+
const E = {
|
|
4
|
+
x: 0,
|
|
5
|
+
y: 0,
|
|
6
|
+
width: 0,
|
|
7
|
+
height: 0,
|
|
8
|
+
unit: "px"
|
|
9
|
+
}, R = (s, t, e) => Math.min(Math.max(s, t), e), P = (...s) => s.filter((t) => t && typeof t == "string").join(" "), Y = (s, t) => s === t || s.width === t.width && s.height === t.height && s.x === t.x && s.y === t.y && s.unit === t.unit;
|
|
10
|
+
function N(s, t, e, o) {
|
|
11
|
+
const i = C(s, e, o);
|
|
12
|
+
return s.width && (i.height = i.width / t), s.height && (i.width = i.height * t), i.y + i.height > o && (i.height = o - i.y, i.width = i.height * t), i.x + i.width > e && (i.width = e - i.x, i.height = i.width / t), s.unit === "%" ? f(i, e, o) : i;
|
|
13
|
+
}
|
|
14
|
+
function O(s, t, e) {
|
|
15
|
+
const o = C(s, t, e);
|
|
16
|
+
return o.x = (t - o.width) / 2, o.y = (e - o.height) / 2, s.unit === "%" ? f(o, t, e) : o;
|
|
17
|
+
}
|
|
18
|
+
function f(s, t, e) {
|
|
19
|
+
return s.unit === "%" ? { ...E, ...s, unit: "%" } : {
|
|
20
|
+
unit: "%",
|
|
21
|
+
x: s.x ? s.x / t * 100 : 0,
|
|
22
|
+
y: s.y ? s.y / e * 100 : 0,
|
|
23
|
+
width: s.width ? s.width / t * 100 : 0,
|
|
24
|
+
height: s.height ? s.height / e * 100 : 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function C(s, t, e) {
|
|
28
|
+
return s.unit ? s.unit === "px" ? { ...E, ...s, unit: "px" } : {
|
|
29
|
+
unit: "px",
|
|
30
|
+
x: s.x ? s.x * t / 100 : 0,
|
|
31
|
+
y: s.y ? s.y * e / 100 : 0,
|
|
32
|
+
width: s.width ? s.width * t / 100 : 0,
|
|
33
|
+
height: s.height ? s.height * e / 100 : 0
|
|
34
|
+
} : { ...E, ...s, unit: "px" };
|
|
35
|
+
}
|
|
36
|
+
function _(s, t, e, o, i, n = 0, a = 0, l = o, h = i) {
|
|
37
|
+
const r = { ...s };
|
|
38
|
+
let c = Math.min(n, o), w = Math.min(a, i), g = Math.min(l, o), d = Math.min(h, i);
|
|
39
|
+
t && (t > 1 ? (c = a ? a * t : c, w = c / t, g = l * t) : (w = n ? n / t : w, c = w * t, d = h / t)), r.y < 0 && (r.height = Math.max(r.height + r.y, w), r.y = 0), r.x < 0 && (r.width = Math.max(r.width + r.x, c), r.x = 0);
|
|
40
|
+
const m = o - (r.x + r.width);
|
|
41
|
+
m < 0 && (r.x = Math.min(r.x, o - c), r.width += m);
|
|
42
|
+
const x = i - (r.y + r.height);
|
|
43
|
+
if (x < 0 && (r.y = Math.min(r.y, i - w), r.height += x), r.width < c && ((e === "sw" || e == "nw") && (r.x -= c - r.width), r.width = c), r.height < w && ((e === "nw" || e == "ne") && (r.y -= w - r.height), r.height = w), r.width > g && ((e === "sw" || e == "nw") && (r.x -= g - r.width), r.width = g), r.height > d && ((e === "nw" || e == "ne") && (r.y -= d - r.height), r.height = d), t) {
|
|
44
|
+
const b = r.width / r.height;
|
|
45
|
+
if (b < t) {
|
|
46
|
+
const D = Math.max(r.width / t, w);
|
|
47
|
+
(e === "nw" || e == "ne") && (r.y -= D - r.height), r.height = D;
|
|
48
|
+
} else if (b > t) {
|
|
49
|
+
const D = Math.max(r.height * t, c);
|
|
50
|
+
(e === "sw" || e == "nw") && (r.x -= D - r.width), r.width = D;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return r;
|
|
54
|
+
}
|
|
55
|
+
function S(s, t, e, o) {
|
|
56
|
+
const i = { ...s };
|
|
57
|
+
return t === "ArrowLeft" ? o === "nw" ? (i.x -= e, i.y -= e, i.width += e, i.height += e) : o === "w" ? (i.x -= e, i.width += e) : o === "sw" ? (i.x -= e, i.width += e, i.height += e) : o === "ne" ? (i.y += e, i.width -= e, i.height -= e) : o === "e" ? i.width -= e : o === "se" && (i.width -= e, i.height -= e) : t === "ArrowRight" && (o === "nw" ? (i.x += e, i.y += e, i.width -= e, i.height -= e) : o === "w" ? (i.x += e, i.width -= e) : o === "sw" ? (i.x += e, i.width -= e, i.height -= e) : o === "ne" ? (i.y -= e, i.width += e, i.height += e) : o === "e" ? i.width += e : o === "se" && (i.width += e, i.height += e)), t === "ArrowUp" ? o === "nw" ? (i.x -= e, i.y -= e, i.width += e, i.height += e) : o === "n" ? (i.y -= e, i.height += e) : o === "ne" ? (i.y -= e, i.width += e, i.height += e) : o === "sw" ? (i.x += e, i.width -= e, i.height -= e) : o === "s" ? i.height -= e : o === "se" && (i.width -= e, i.height -= e) : t === "ArrowDown" && (o === "nw" ? (i.x += e, i.y += e, i.width -= e, i.height -= e) : o === "n" ? (i.y += e, i.height -= e) : o === "ne" ? (i.y += e, i.width -= e, i.height -= e) : o === "sw" ? (i.x -= e, i.width += e, i.height += e) : o === "s" ? i.height += e : o === "se" && (i.width += e, i.height += e)), i;
|
|
58
|
+
}
|
|
59
|
+
const M = { capture: !0, passive: !1 };
|
|
60
|
+
let K = 0;
|
|
61
|
+
const v = class y extends H {
|
|
62
|
+
constructor() {
|
|
63
|
+
super(...arguments), u(this, "docMoveBound", !1), u(this, "mouseDownOnCrop", !1), u(this, "dragStarted", !1), u(this, "evData", {
|
|
64
|
+
startClientX: 0,
|
|
65
|
+
startClientY: 0,
|
|
66
|
+
startCropX: 0,
|
|
67
|
+
startCropY: 0,
|
|
68
|
+
clientX: 0,
|
|
69
|
+
clientY: 0,
|
|
70
|
+
isResize: !0
|
|
71
|
+
}), u(this, "componentRef", k()), u(this, "mediaRef", k()), u(this, "resizeObserver"), u(this, "initChangeCalled", !1), u(this, "instanceId", `rc-${K++}`), u(this, "state", {
|
|
72
|
+
cropIsActive: !1,
|
|
73
|
+
newCropIsBeingDrawn: !1
|
|
74
|
+
}), u(this, "onCropPointerDown", (t) => {
|
|
75
|
+
const { crop: e, disabled: o } = this.props, i = this.getBox();
|
|
76
|
+
if (!e)
|
|
77
|
+
return;
|
|
78
|
+
const n = C(e, i.width, i.height);
|
|
79
|
+
if (o)
|
|
80
|
+
return;
|
|
81
|
+
t.cancelable && t.preventDefault(), this.bindDocMove(), this.componentRef.current.focus({ preventScroll: !0 });
|
|
82
|
+
const a = t.target.dataset.ord, l = !!a;
|
|
83
|
+
let h = t.clientX, r = t.clientY, c = n.x, w = n.y;
|
|
84
|
+
if (a) {
|
|
85
|
+
const g = t.clientX - i.x, d = t.clientY - i.y;
|
|
86
|
+
let m = 0, x = 0;
|
|
87
|
+
a === "ne" || a == "e" ? (m = g - (n.x + n.width), x = d - n.y, c = n.x, w = n.y + n.height) : a === "se" || a === "s" ? (m = g - (n.x + n.width), x = d - (n.y + n.height), c = n.x, w = n.y) : a === "sw" || a == "w" ? (m = g - n.x, x = d - (n.y + n.height), c = n.x + n.width, w = n.y) : (a === "nw" || a == "n") && (m = g - n.x, x = d - n.y, c = n.x + n.width, w = n.y + n.height), h = c + i.x + m, r = w + i.y + x;
|
|
88
|
+
}
|
|
89
|
+
this.evData = {
|
|
90
|
+
startClientX: h,
|
|
91
|
+
startClientY: r,
|
|
92
|
+
startCropX: c,
|
|
93
|
+
startCropY: w,
|
|
94
|
+
clientX: t.clientX,
|
|
95
|
+
clientY: t.clientY,
|
|
96
|
+
isResize: l,
|
|
97
|
+
ord: a
|
|
98
|
+
}, this.mouseDownOnCrop = !0, this.setState({ cropIsActive: !0 });
|
|
99
|
+
}), u(this, "onComponentPointerDown", (t) => {
|
|
100
|
+
const { crop: e, disabled: o, locked: i, keepSelection: n, onChange: a } = this.props, l = this.getBox();
|
|
101
|
+
if (o || i || n && e)
|
|
102
|
+
return;
|
|
103
|
+
t.cancelable && t.preventDefault(), this.bindDocMove(), this.componentRef.current.focus({ preventScroll: !0 });
|
|
104
|
+
const h = t.clientX - l.x, r = t.clientY - l.y, c = {
|
|
105
|
+
unit: "px",
|
|
106
|
+
x: h,
|
|
107
|
+
y: r,
|
|
108
|
+
width: 0,
|
|
109
|
+
height: 0
|
|
110
|
+
};
|
|
111
|
+
this.evData = {
|
|
112
|
+
startClientX: t.clientX,
|
|
113
|
+
startClientY: t.clientY,
|
|
114
|
+
startCropX: h,
|
|
115
|
+
startCropY: r,
|
|
116
|
+
clientX: t.clientX,
|
|
117
|
+
clientY: t.clientY,
|
|
118
|
+
isResize: !0
|
|
119
|
+
}, this.mouseDownOnCrop = !0, a(C(c, l.width, l.height), f(c, l.width, l.height)), this.setState({ cropIsActive: !0, newCropIsBeingDrawn: !0 });
|
|
120
|
+
}), u(this, "onDocPointerMove", (t) => {
|
|
121
|
+
const { crop: e, disabled: o, onChange: i, onDragStart: n } = this.props, a = this.getBox();
|
|
122
|
+
if (o || !e || !this.mouseDownOnCrop)
|
|
123
|
+
return;
|
|
124
|
+
t.cancelable && t.preventDefault(), this.dragStarted || (this.dragStarted = !0, n && n(t));
|
|
125
|
+
const { evData: l } = this;
|
|
126
|
+
l.clientX = t.clientX, l.clientY = t.clientY;
|
|
127
|
+
let h;
|
|
128
|
+
l.isResize ? h = this.resizeCrop() : h = this.dragCrop(), Y(e, h) || i(
|
|
129
|
+
C(h, a.width, a.height),
|
|
130
|
+
f(h, a.width, a.height)
|
|
131
|
+
);
|
|
132
|
+
}), u(this, "onComponentKeyDown", (t) => {
|
|
133
|
+
const { crop: e, disabled: o, onChange: i, onComplete: n } = this.props;
|
|
134
|
+
if (o)
|
|
135
|
+
return;
|
|
136
|
+
const a = t.key;
|
|
137
|
+
let l = !1;
|
|
138
|
+
if (!e)
|
|
139
|
+
return;
|
|
140
|
+
const h = this.getBox(), r = this.makePixelCrop(h), c = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? y.nudgeStepLarge : t.shiftKey ? y.nudgeStepMedium : y.nudgeStep;
|
|
141
|
+
if (a === "ArrowLeft" ? (r.x -= c, l = !0) : a === "ArrowRight" ? (r.x += c, l = !0) : a === "ArrowUp" ? (r.y -= c, l = !0) : a === "ArrowDown" && (r.y += c, l = !0), l) {
|
|
142
|
+
t.cancelable && t.preventDefault(), r.x = R(r.x, 0, h.width - r.width), r.y = R(r.y, 0, h.height - r.height);
|
|
143
|
+
const w = C(r, h.width, h.height), g = f(r, h.width, h.height);
|
|
144
|
+
i(w, g), n && n(w, g);
|
|
145
|
+
}
|
|
146
|
+
}), u(this, "onHandlerKeyDown", (t, e) => {
|
|
147
|
+
const {
|
|
148
|
+
aspect: o = 0,
|
|
149
|
+
crop: i,
|
|
150
|
+
disabled: n,
|
|
151
|
+
minWidth: a = 0,
|
|
152
|
+
minHeight: l = 0,
|
|
153
|
+
maxWidth: h,
|
|
154
|
+
maxHeight: r,
|
|
155
|
+
onChange: c,
|
|
156
|
+
onComplete: w
|
|
157
|
+
} = this.props, g = this.getBox();
|
|
158
|
+
if (n || !i)
|
|
159
|
+
return;
|
|
160
|
+
if (t.key === "ArrowUp" || t.key === "ArrowDown" || t.key === "ArrowLeft" || t.key === "ArrowRight")
|
|
161
|
+
t.stopPropagation(), t.preventDefault();
|
|
162
|
+
else
|
|
163
|
+
return;
|
|
164
|
+
const d = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? y.nudgeStepLarge : t.shiftKey ? y.nudgeStepMedium : y.nudgeStep, m = C(i, g.width, g.height), x = S(m, t.key, d, e), b = _(
|
|
165
|
+
x,
|
|
166
|
+
o,
|
|
167
|
+
e,
|
|
168
|
+
g.width,
|
|
169
|
+
g.height,
|
|
170
|
+
a,
|
|
171
|
+
l,
|
|
172
|
+
h,
|
|
173
|
+
r
|
|
174
|
+
);
|
|
175
|
+
if (!Y(i, b)) {
|
|
176
|
+
const D = f(b, g.width, g.height);
|
|
177
|
+
c(b, D), w && w(b, D);
|
|
178
|
+
}
|
|
179
|
+
}), u(this, "onDocPointerDone", (t) => {
|
|
180
|
+
const { crop: e, disabled: o, onComplete: i, onDragEnd: n } = this.props, a = this.getBox();
|
|
181
|
+
this.unbindDocMove(), !(o || !e) && this.mouseDownOnCrop && (this.mouseDownOnCrop = !1, this.dragStarted = !1, n && n(t), i && i(C(e, a.width, a.height), f(e, a.width, a.height)), this.setState({ cropIsActive: !1, newCropIsBeingDrawn: !1 }));
|
|
182
|
+
}), u(this, "onDragFocus", () => {
|
|
183
|
+
var t;
|
|
184
|
+
(t = this.componentRef.current) == null || t.scrollTo(0, 0);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
get document() {
|
|
188
|
+
return document;
|
|
189
|
+
}
|
|
190
|
+
// We unfortunately get the bounding box every time as x+y changes
|
|
191
|
+
// due to scrolling.
|
|
192
|
+
getBox() {
|
|
193
|
+
const t = this.mediaRef.current;
|
|
194
|
+
if (!t)
|
|
195
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
196
|
+
const { x: e, y: o, width: i, height: n } = t.getBoundingClientRect();
|
|
197
|
+
return { x: e, y: o, width: i, height: n };
|
|
198
|
+
}
|
|
199
|
+
componentDidUpdate(t) {
|
|
200
|
+
const { crop: e, onComplete: o } = this.props;
|
|
201
|
+
if (o && !t.crop && e) {
|
|
202
|
+
const { width: i, height: n } = this.getBox();
|
|
203
|
+
i && n && o(C(e, i, n), f(e, i, n));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
componentWillUnmount() {
|
|
207
|
+
this.resizeObserver && this.resizeObserver.disconnect(), this.unbindDocMove();
|
|
208
|
+
}
|
|
209
|
+
bindDocMove() {
|
|
210
|
+
this.docMoveBound || (this.document.addEventListener("pointermove", this.onDocPointerMove, M), this.document.addEventListener("pointerup", this.onDocPointerDone, M), this.document.addEventListener("pointercancel", this.onDocPointerDone, M), this.docMoveBound = !0);
|
|
211
|
+
}
|
|
212
|
+
unbindDocMove() {
|
|
213
|
+
this.docMoveBound && (this.document.removeEventListener("pointermove", this.onDocPointerMove, M), this.document.removeEventListener("pointerup", this.onDocPointerDone, M), this.document.removeEventListener("pointercancel", this.onDocPointerDone, M), this.docMoveBound = !1);
|
|
214
|
+
}
|
|
215
|
+
getCropStyle() {
|
|
216
|
+
const { crop: t } = this.props;
|
|
217
|
+
if (t)
|
|
218
|
+
return {
|
|
219
|
+
top: `${t.y}${t.unit}`,
|
|
220
|
+
left: `${t.x}${t.unit}`,
|
|
221
|
+
width: `${t.width}${t.unit}`,
|
|
222
|
+
height: `${t.height}${t.unit}`
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
dragCrop() {
|
|
226
|
+
const { evData: t } = this, e = this.getBox(), o = this.makePixelCrop(e), i = t.clientX - t.startClientX, n = t.clientY - t.startClientY;
|
|
227
|
+
return o.x = R(t.startCropX + i, 0, e.width - o.width), o.y = R(t.startCropY + n, 0, e.height - o.height), o;
|
|
228
|
+
}
|
|
229
|
+
getPointRegion(t, e, o, i) {
|
|
230
|
+
const { evData: n } = this, a = n.clientX - t.x, l = n.clientY - t.y;
|
|
231
|
+
let h;
|
|
232
|
+
i && e ? h = e === "nw" || e === "n" || e === "ne" : h = l < n.startCropY;
|
|
233
|
+
let r;
|
|
234
|
+
return o && e ? r = e === "nw" || e === "w" || e === "sw" : r = a < n.startCropX, r ? h ? "nw" : "sw" : h ? "ne" : "se";
|
|
235
|
+
}
|
|
236
|
+
resolveMinDimensions(t, e, o = 0, i = 0) {
|
|
237
|
+
const n = Math.min(o, t.width), a = Math.min(i, t.height);
|
|
238
|
+
return !e || !n && !a ? [n, a] : e > 1 ? n ? [n, n / e] : [a * e, a] : a ? [a * e, a] : [n, n / e];
|
|
239
|
+
}
|
|
240
|
+
resizeCrop() {
|
|
241
|
+
const { evData: t } = this, { aspect: e = 0, maxWidth: o, maxHeight: i } = this.props, n = this.getBox(), [a, l] = this.resolveMinDimensions(n, e, this.props.minWidth, this.props.minHeight);
|
|
242
|
+
let h = this.makePixelCrop(n);
|
|
243
|
+
const r = this.getPointRegion(n, t.ord, a, l), c = t.ord || r;
|
|
244
|
+
let w = t.clientX - t.startClientX, g = t.clientY - t.startClientY;
|
|
245
|
+
(a && c === "nw" || c === "w" || c === "sw") && (w = Math.min(w, -a)), (l && c === "nw" || c === "n" || c === "ne") && (g = Math.min(g, -l));
|
|
246
|
+
const d = {
|
|
247
|
+
unit: "px",
|
|
248
|
+
x: 0,
|
|
249
|
+
y: 0,
|
|
250
|
+
width: 0,
|
|
251
|
+
height: 0
|
|
252
|
+
};
|
|
253
|
+
r === "ne" ? (d.x = t.startCropX, d.width = w, e ? (d.height = d.width / e, d.y = t.startCropY - d.height) : (d.height = Math.abs(g), d.y = t.startCropY - d.height)) : r === "se" ? (d.x = t.startCropX, d.y = t.startCropY, d.width = w, e ? d.height = d.width / e : d.height = g) : r === "sw" ? (d.x = t.startCropX + w, d.y = t.startCropY, d.width = Math.abs(w), e ? d.height = d.width / e : d.height = g) : r === "nw" && (d.x = t.startCropX + w, d.width = Math.abs(w), e ? (d.height = d.width / e, d.y = t.startCropY - d.height) : (d.height = Math.abs(g), d.y = t.startCropY + g));
|
|
254
|
+
const m = _(
|
|
255
|
+
d,
|
|
256
|
+
e,
|
|
257
|
+
r,
|
|
258
|
+
n.width,
|
|
259
|
+
n.height,
|
|
260
|
+
a,
|
|
261
|
+
l,
|
|
262
|
+
o,
|
|
263
|
+
i
|
|
264
|
+
);
|
|
265
|
+
return e || y.xyOrds.indexOf(c) > -1 ? h = m : y.xOrds.indexOf(c) > -1 ? (h.x = m.x, h.width = m.width) : y.yOrds.indexOf(c) > -1 && (h.y = m.y, h.height = m.height), h.x = R(h.x, 0, n.width - h.width), h.y = R(h.y, 0, n.height - h.height), h;
|
|
266
|
+
}
|
|
267
|
+
renderCropSelection() {
|
|
268
|
+
const {
|
|
269
|
+
ariaLabels: t = y.defaultProps.ariaLabels,
|
|
270
|
+
disabled: e,
|
|
271
|
+
locked: o,
|
|
272
|
+
renderSelectionAddon: i,
|
|
273
|
+
ruleOfThirds: n,
|
|
274
|
+
crop: a
|
|
275
|
+
} = this.props, l = this.getCropStyle();
|
|
276
|
+
if (a)
|
|
277
|
+
return /* @__PURE__ */ p.createElement(
|
|
278
|
+
"div",
|
|
279
|
+
{
|
|
280
|
+
style: l,
|
|
281
|
+
className: "ReactCrop__crop-selection",
|
|
282
|
+
onPointerDown: this.onCropPointerDown,
|
|
283
|
+
"aria-label": t.cropArea,
|
|
284
|
+
tabIndex: 0,
|
|
285
|
+
onKeyDown: this.onComponentKeyDown,
|
|
286
|
+
role: "group"
|
|
287
|
+
},
|
|
288
|
+
!e && !o && /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__drag-elements", onFocus: this.onDragFocus }, /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__drag-bar ord-n", "data-ord": "n" }), /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__drag-bar ord-e", "data-ord": "e" }), /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__drag-bar ord-s", "data-ord": "s" }), /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__drag-bar ord-w", "data-ord": "w" }), /* @__PURE__ */ p.createElement(
|
|
289
|
+
"div",
|
|
290
|
+
{
|
|
291
|
+
className: "ReactCrop__drag-handle ord-nw",
|
|
292
|
+
"data-ord": "nw",
|
|
293
|
+
tabIndex: 0,
|
|
294
|
+
"aria-label": t.nwDragHandle,
|
|
295
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "nw"),
|
|
296
|
+
role: "button"
|
|
297
|
+
}
|
|
298
|
+
), /* @__PURE__ */ p.createElement(
|
|
299
|
+
"div",
|
|
300
|
+
{
|
|
301
|
+
className: "ReactCrop__drag-handle ord-n",
|
|
302
|
+
"data-ord": "n",
|
|
303
|
+
tabIndex: 0,
|
|
304
|
+
"aria-label": t.nDragHandle,
|
|
305
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "n"),
|
|
306
|
+
role: "button"
|
|
307
|
+
}
|
|
308
|
+
), /* @__PURE__ */ p.createElement(
|
|
309
|
+
"div",
|
|
310
|
+
{
|
|
311
|
+
className: "ReactCrop__drag-handle ord-ne",
|
|
312
|
+
"data-ord": "ne",
|
|
313
|
+
tabIndex: 0,
|
|
314
|
+
"aria-label": t.neDragHandle,
|
|
315
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "ne"),
|
|
316
|
+
role: "button"
|
|
317
|
+
}
|
|
318
|
+
), /* @__PURE__ */ p.createElement(
|
|
319
|
+
"div",
|
|
320
|
+
{
|
|
321
|
+
className: "ReactCrop__drag-handle ord-e",
|
|
322
|
+
"data-ord": "e",
|
|
323
|
+
tabIndex: 0,
|
|
324
|
+
"aria-label": t.eDragHandle,
|
|
325
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "e"),
|
|
326
|
+
role: "button"
|
|
327
|
+
}
|
|
328
|
+
), /* @__PURE__ */ p.createElement(
|
|
329
|
+
"div",
|
|
330
|
+
{
|
|
331
|
+
className: "ReactCrop__drag-handle ord-se",
|
|
332
|
+
"data-ord": "se",
|
|
333
|
+
tabIndex: 0,
|
|
334
|
+
"aria-label": t.seDragHandle,
|
|
335
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "se"),
|
|
336
|
+
role: "button"
|
|
337
|
+
}
|
|
338
|
+
), /* @__PURE__ */ p.createElement(
|
|
339
|
+
"div",
|
|
340
|
+
{
|
|
341
|
+
className: "ReactCrop__drag-handle ord-s",
|
|
342
|
+
"data-ord": "s",
|
|
343
|
+
tabIndex: 0,
|
|
344
|
+
"aria-label": t.sDragHandle,
|
|
345
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "s"),
|
|
346
|
+
role: "button"
|
|
347
|
+
}
|
|
348
|
+
), /* @__PURE__ */ p.createElement(
|
|
349
|
+
"div",
|
|
350
|
+
{
|
|
351
|
+
className: "ReactCrop__drag-handle ord-sw",
|
|
352
|
+
"data-ord": "sw",
|
|
353
|
+
tabIndex: 0,
|
|
354
|
+
"aria-label": t.swDragHandle,
|
|
355
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "sw"),
|
|
356
|
+
role: "button"
|
|
357
|
+
}
|
|
358
|
+
), /* @__PURE__ */ p.createElement(
|
|
359
|
+
"div",
|
|
360
|
+
{
|
|
361
|
+
className: "ReactCrop__drag-handle ord-w",
|
|
362
|
+
"data-ord": "w",
|
|
363
|
+
tabIndex: 0,
|
|
364
|
+
"aria-label": t.wDragHandle,
|
|
365
|
+
onKeyDown: (h) => this.onHandlerKeyDown(h, "w"),
|
|
366
|
+
role: "button"
|
|
367
|
+
}
|
|
368
|
+
)),
|
|
369
|
+
i && /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__selection-addon", onPointerDown: (h) => h.stopPropagation() }, i(this.state)),
|
|
370
|
+
n && /* @__PURE__ */ p.createElement(p.Fragment, null, /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__rule-of-thirds-hz" }), /* @__PURE__ */ p.createElement("div", { className: "ReactCrop__rule-of-thirds-vt" }))
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
makePixelCrop(t) {
|
|
374
|
+
const e = { ...E, ...this.props.crop || {} };
|
|
375
|
+
return C(e, t.width, t.height);
|
|
376
|
+
}
|
|
377
|
+
render() {
|
|
378
|
+
const { aspect: t, children: e, circularCrop: o, className: i, crop: n, disabled: a, locked: l, style: h, ruleOfThirds: r } = this.props, { cropIsActive: c, newCropIsBeingDrawn: w } = this.state, g = n ? this.renderCropSelection() : null, d = P(
|
|
379
|
+
"ReactCrop",
|
|
380
|
+
i,
|
|
381
|
+
c && "ReactCrop--active",
|
|
382
|
+
a && "ReactCrop--disabled",
|
|
383
|
+
l && "ReactCrop--locked",
|
|
384
|
+
w && "ReactCrop--new-crop",
|
|
385
|
+
n && t && "ReactCrop--fixed-aspect",
|
|
386
|
+
n && o && "ReactCrop--circular-crop",
|
|
387
|
+
n && r && "ReactCrop--rule-of-thirds",
|
|
388
|
+
!this.dragStarted && n && !n.width && !n.height && "ReactCrop--invisible-crop",
|
|
389
|
+
o && "ReactCrop--no-animate"
|
|
390
|
+
);
|
|
391
|
+
return /* @__PURE__ */ p.createElement("div", { ref: this.componentRef, className: d, style: h }, /* @__PURE__ */ p.createElement("div", { ref: this.mediaRef, className: "ReactCrop__child-wrapper", onPointerDown: this.onComponentPointerDown }, e), n ? /* @__PURE__ */ p.createElement("svg", { className: "ReactCrop__crop-mask", width: "100%", height: "100%" }, /* @__PURE__ */ p.createElement("defs", null, /* @__PURE__ */ p.createElement("mask", { id: `hole-${this.instanceId}` }, /* @__PURE__ */ p.createElement("rect", { width: "100%", height: "100%", fill: "white" }), o ? /* @__PURE__ */ p.createElement(
|
|
392
|
+
"ellipse",
|
|
393
|
+
{
|
|
394
|
+
cx: `${n.x + n.width / 2}${n.unit}`,
|
|
395
|
+
cy: `${n.y + n.height / 2}${n.unit}`,
|
|
396
|
+
rx: `${n.width / 2}${n.unit}`,
|
|
397
|
+
ry: `${n.height / 2}${n.unit}`,
|
|
398
|
+
fill: "black"
|
|
399
|
+
}
|
|
400
|
+
) : /* @__PURE__ */ p.createElement(
|
|
401
|
+
"rect",
|
|
402
|
+
{
|
|
403
|
+
x: `${n.x}${n.unit}`,
|
|
404
|
+
y: `${n.y}${n.unit}`,
|
|
405
|
+
width: `${n.width}${n.unit}`,
|
|
406
|
+
height: `${n.height}${n.unit}`,
|
|
407
|
+
fill: "black"
|
|
408
|
+
}
|
|
409
|
+
))), /* @__PURE__ */ p.createElement("rect", { fill: "black", fillOpacity: 0.5, width: "100%", height: "100%", mask: `url(#hole-${this.instanceId})` })) : void 0, g);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
u(v, "xOrds", ["e", "w"]), u(v, "yOrds", ["n", "s"]), u(v, "xyOrds", ["nw", "ne", "se", "sw"]), u(v, "nudgeStep", 1), u(v, "nudgeStepMedium", 10), u(v, "nudgeStepLarge", 100), u(v, "defaultProps", {
|
|
413
|
+
ariaLabels: {
|
|
414
|
+
cropArea: "Use the arrow keys to move the crop selection area",
|
|
415
|
+
nwDragHandle: "Use the arrow keys to move the north west drag handle to change the crop selection area",
|
|
416
|
+
nDragHandle: "Use the up and down arrow keys to move the north drag handle to change the crop selection area",
|
|
417
|
+
neDragHandle: "Use the arrow keys to move the north east drag handle to change the crop selection area",
|
|
418
|
+
eDragHandle: "Use the up and down arrow keys to move the east drag handle to change the crop selection area",
|
|
419
|
+
seDragHandle: "Use the arrow keys to move the south east drag handle to change the crop selection area",
|
|
420
|
+
sDragHandle: "Use the up and down arrow keys to move the south drag handle to change the crop selection area",
|
|
421
|
+
swDragHandle: "Use the arrow keys to move the south west drag handle to change the crop selection area",
|
|
422
|
+
wDragHandle: "Use the up and down arrow keys to move the west drag handle to change the crop selection area"
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
let B = v;
|
|
426
|
+
export {
|
|
427
|
+
N as B,
|
|
428
|
+
C as D,
|
|
429
|
+
O as L,
|
|
430
|
+
B as S
|
|
431
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PhotoCropUploader } from './components';
|
|
2
|
+
export type { Locale } from './types';
|
|
3
|
+
export type { PhotoDataUrl, PhotoFileSize, PhotoExtension, PhotoMimeType, PhotoFileOptions, PhotoCropUploaderProps, } from './components/photo-crop-uploader/types';
|
|
4
|
+
export { EN_LOCALE, RU_LOCALE, BYTE_TO_KILOBYTE } from './constants';
|
|
5
|
+
export { JPG_IMAGE_EXT, JPEG_IMAGE_EXT, PNG_IMAGE_EXT, SVG_IMAGE_EXT, BMP_IMAGE_EXT, GIF_IMAGE_EXT, WEBP_IMAGE_EXT, ICO_IMAGE_EXT, BMP_IMAGE_TYPE, GIF_IMAGE_TYPE, ICO_IMAGE_TYPE, JPEG_IMAGE_TYPE, JPG_IMAGE_TYPE, MICROSOFT_ICO_IMAGE_TYPE, PNG_IMAGE_TYPE, SVG_IMAGE_TYPE, WEBP_IMAGE_TYPE, } from './components/photo-crop-uploader/constants';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BYTE_TO_KILOBYTE as G, EN_LOCALE as I, RU_LOCALE as T } from "./constants.js";
|
|
2
|
+
import { BMP_IMAGE_EXT as P, BMP_IMAGE_TYPE as A, GIF_IMAGE_EXT as Y, GIF_IMAGE_TYPE as o, ICO_IMAGE_EXT as O, ICO_IMAGE_TYPE as r, JPEG_IMAGE_EXT as X, JPEG_IMAGE_TYPE as C, JPG_IMAGE_EXT as B, JPG_IMAGE_TYPE as p, MICROSOFT_ICO_IMAGE_TYPE as L, PNG_IMAGE_EXT as e, PNG_IMAGE_TYPE as t, SVG_IMAGE_EXT as J, SVG_IMAGE_TYPE as f, WEBP_IMAGE_EXT as m, WEBP_IMAGE_TYPE as x } from "./components/photo-crop-uploader/constants.js";
|
|
3
|
+
import { PhotoCropUploader as N } from "./components/photo-crop-uploader/photo-crop-uploader.js";
|
|
4
|
+
export {
|
|
5
|
+
P as BMP_IMAGE_EXT,
|
|
6
|
+
A as BMP_IMAGE_TYPE,
|
|
7
|
+
G as BYTE_TO_KILOBYTE,
|
|
8
|
+
I as EN_LOCALE,
|
|
9
|
+
Y as GIF_IMAGE_EXT,
|
|
10
|
+
o as GIF_IMAGE_TYPE,
|
|
11
|
+
O as ICO_IMAGE_EXT,
|
|
12
|
+
r as ICO_IMAGE_TYPE,
|
|
13
|
+
X as JPEG_IMAGE_EXT,
|
|
14
|
+
C as JPEG_IMAGE_TYPE,
|
|
15
|
+
B as JPG_IMAGE_EXT,
|
|
16
|
+
p as JPG_IMAGE_TYPE,
|
|
17
|
+
L as MICROSOFT_ICO_IMAGE_TYPE,
|
|
18
|
+
e as PNG_IMAGE_EXT,
|
|
19
|
+
t as PNG_IMAGE_TYPE,
|
|
20
|
+
N as PhotoCropUploader,
|
|
21
|
+
T as RU_LOCALE,
|
|
22
|
+
J as SVG_IMAGE_EXT,
|
|
23
|
+
f as SVG_IMAGE_TYPE,
|
|
24
|
+
m as WEBP_IMAGE_EXT,
|
|
25
|
+
x as WEBP_IMAGE_TYPE
|
|
26
|
+
};
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hai-dev/ui-kit",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Vladislav Knitrunov",
|
|
7
|
+
"email": "kingvlad3008@gmail.com",
|
|
8
|
+
"url": "https://gitlab.com/kingvlad3008"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "vite",
|
|
18
|
+
"build": "tsc -b && vite build",
|
|
19
|
+
"prepublishOnly": "npm run build",
|
|
20
|
+
"lint": "eslint .",
|
|
21
|
+
"preview": "vite preview",
|
|
22
|
+
"storybook": "storybook dev -p 6006",
|
|
23
|
+
"build-storybook": "storybook build",
|
|
24
|
+
"prepare": "husky"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@emotion/react": "^11.14.0",
|
|
28
|
+
"@emotion/styled": "^11.14.1",
|
|
29
|
+
"@mui/material": "^7.3.2",
|
|
30
|
+
"@types/node": "^24.5.2",
|
|
31
|
+
"classnames": "^2.5.1",
|
|
32
|
+
"react": "^19.1.1",
|
|
33
|
+
"react-dom": "^19.1.1",
|
|
34
|
+
"react-image-crop": "^11.0.10",
|
|
35
|
+
"sass": "^1.93.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@emotion/react": "^11.14.0",
|
|
39
|
+
"@emotion/styled": "^11.14.1",
|
|
40
|
+
"@eslint/js": "^9.36.0",
|
|
41
|
+
"@mui/material": "^7.3.2",
|
|
42
|
+
"@storybook/addon-docs": "9.1.8",
|
|
43
|
+
"@storybook/addon-onboarding": "9.1.8",
|
|
44
|
+
"@storybook/react-vite": "9.1.8",
|
|
45
|
+
"@types/node": "^24.5.2",
|
|
46
|
+
"@types/react": "^19.1.13",
|
|
47
|
+
"@types/react-dom": "^19.1.9",
|
|
48
|
+
"@vitejs/plugin-react": "^5.0.3",
|
|
49
|
+
"classnames": "^2.5.1",
|
|
50
|
+
"eslint": "^9.36.0",
|
|
51
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
52
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
53
|
+
"eslint-plugin-storybook": "9.1.8",
|
|
54
|
+
"glob": "^11.0.3",
|
|
55
|
+
"globals": "^16.4.0",
|
|
56
|
+
"react": "^19.1.1",
|
|
57
|
+
"react-dom": "^19.1.1",
|
|
58
|
+
"react-image-crop": "^11.0.10",
|
|
59
|
+
"sass": "^1.93.1",
|
|
60
|
+
"storybook": "9.1.8",
|
|
61
|
+
"typescript": "~5.8.3",
|
|
62
|
+
"typescript-eslint": "^8.44.0",
|
|
63
|
+
"vite": "^7.1.7",
|
|
64
|
+
"vite-plugin-dts": "^4.5.4",
|
|
65
|
+
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
66
|
+
"@commitlint/cli": "^20.0.0",
|
|
67
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
68
|
+
"husky": "^9.1.7"
|
|
69
|
+
},
|
|
70
|
+
"sideEffects": [
|
|
71
|
+
"**/*.css"
|
|
72
|
+
]
|
|
73
|
+
}
|