@rolster/react-components 18.23.7 → 18.23.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +34 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +34 -17
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.d.ts +5 -0
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js +33 -16
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -3312,6 +3312,8 @@ function useResize(props) {
|
|
|
3312
3312
|
}, []);
|
|
3313
3313
|
}
|
|
3314
3314
|
|
|
3315
|
+
const minValueSlider = 50;
|
|
3316
|
+
const maxValueSlider = 100;
|
|
3315
3317
|
function getRatioFactor(ratio) {
|
|
3316
3318
|
switch (ratio) {
|
|
3317
3319
|
case '16:9':
|
|
@@ -3328,8 +3330,19 @@ function getRatioFactor(ratio) {
|
|
|
3328
3330
|
return 1;
|
|
3329
3331
|
}
|
|
3330
3332
|
}
|
|
3331
|
-
function simpleThreeRule(
|
|
3332
|
-
return (
|
|
3333
|
+
function simpleThreeRule(a1, b1, a2) {
|
|
3334
|
+
return (b1 * a2) / a1;
|
|
3335
|
+
}
|
|
3336
|
+
function calculateImgDimension(image, dimension) {
|
|
3337
|
+
let { height, width } = image;
|
|
3338
|
+
if (height > width) {
|
|
3339
|
+
height = height > dimension ? dimension : height;
|
|
3340
|
+
width = simpleThreeRule(image.height, height, width);
|
|
3341
|
+
return { height, width };
|
|
3342
|
+
}
|
|
3343
|
+
width = width > dimension ? dimension : width;
|
|
3344
|
+
height = simpleThreeRule(image.width, width, height);
|
|
3345
|
+
return { height, width };
|
|
3333
3346
|
}
|
|
3334
3347
|
function RlsImageEditor(props) {
|
|
3335
3348
|
const [selection, setSelection] = require$$0.useState(props.selection ?? 60);
|
|
@@ -3397,12 +3410,14 @@ function RlsImageEditor(props) {
|
|
|
3397
3410
|
let width = (offsetHeight * _ratio) / 100;
|
|
3398
3411
|
if (width > offsetWidth) {
|
|
3399
3412
|
width = offsetWidth;
|
|
3400
|
-
height = width
|
|
3413
|
+
height = width * ratioFactor;
|
|
3401
3414
|
}
|
|
3402
3415
|
return { height, width };
|
|
3403
3416
|
}, [ratio]);
|
|
3404
3417
|
const refreshSelectionStyle = require$$0.useCallback((rateSelection) => {
|
|
3405
|
-
if (
|
|
3418
|
+
if (refSelection.current &&
|
|
3419
|
+
image.current.width > 0 &&
|
|
3420
|
+
image.current.height > 0) {
|
|
3406
3421
|
const { height, width } = image.current.width >= image.current.height
|
|
3407
3422
|
? refreshSelectionFromHeight(rateSelection)
|
|
3408
3423
|
: refreshSelectionFromWidth(rateSelection);
|
|
@@ -3410,13 +3425,13 @@ function RlsImageEditor(props) {
|
|
|
3410
3425
|
refSelection.current.style.height = `${height}px`;
|
|
3411
3426
|
if (refSelection.current.offsetLeft + width >
|
|
3412
3427
|
refImage.current.offsetWidth) {
|
|
3413
|
-
const
|
|
3414
|
-
refSelection.current.style.left = `${
|
|
3428
|
+
const left = refImage.current.offsetWidth - width;
|
|
3429
|
+
refSelection.current.style.left = `${left < 0 ? 0 : left}px`;
|
|
3415
3430
|
}
|
|
3416
3431
|
if (refSelection.current.offsetTop + height >
|
|
3417
3432
|
refImage.current.offsetHeight) {
|
|
3418
|
-
const
|
|
3419
|
-
refSelection.current.style.top = `${
|
|
3433
|
+
const top = refImage.current.offsetHeight - height;
|
|
3434
|
+
refSelection.current.style.top = `${top < 0 ? 0 : top}px`;
|
|
3420
3435
|
}
|
|
3421
3436
|
refreshOverlaysStyle();
|
|
3422
3437
|
}
|
|
@@ -3429,7 +3444,7 @@ function RlsImageEditor(props) {
|
|
|
3429
3444
|
}, []);
|
|
3430
3445
|
const refreshImageStyle = require$$0.useCallback(() => {
|
|
3431
3446
|
if (image.current.width <= 0 || image.current.height <= 0) {
|
|
3432
|
-
return setImageStyle('
|
|
3447
|
+
return setImageStyle('0px', '0px');
|
|
3433
3448
|
}
|
|
3434
3449
|
const height = (refBody.current.offsetWidth * image.current.height) /
|
|
3435
3450
|
image.current.width;
|
|
@@ -3439,16 +3454,18 @@ function RlsImageEditor(props) {
|
|
|
3439
3454
|
const width = (refBody.current.offsetHeight * image.current.width) /
|
|
3440
3455
|
image.current.height;
|
|
3441
3456
|
return setImageStyle(`${width}px`, '100%');
|
|
3442
|
-
}, []);
|
|
3457
|
+
}, [ratio]);
|
|
3443
3458
|
require$$0.useEffect(() => {
|
|
3444
3459
|
image.current.onload = () => {
|
|
3445
3460
|
const context = refCanvas.current.getContext('2d', {
|
|
3446
3461
|
willReadFrequently: true
|
|
3447
3462
|
});
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3463
|
+
const width = image.current.width;
|
|
3464
|
+
const height = image.current.height;
|
|
3465
|
+
refCanvas.current.width = width;
|
|
3466
|
+
refCanvas.current.height = height;
|
|
3467
|
+
context?.drawImage(image.current, 0, 0, width, height);
|
|
3468
|
+
originalImage.current = context?.getImageData(0, 0, width, height);
|
|
3452
3469
|
refreshImageStyle();
|
|
3453
3470
|
refreshSelectionStyle(selection);
|
|
3454
3471
|
};
|
|
@@ -3469,7 +3486,7 @@ function RlsImageEditor(props) {
|
|
|
3469
3486
|
}, [props.src]);
|
|
3470
3487
|
require$$0.useEffect(() => {
|
|
3471
3488
|
refreshSelectionStyle(selection);
|
|
3472
|
-
}, [selection]);
|
|
3489
|
+
}, [ratio, selection]);
|
|
3473
3490
|
const onResizeElement = require$$0.useCallback(() => {
|
|
3474
3491
|
refreshSelectionStyle(selection);
|
|
3475
3492
|
}, [selection]);
|
|
@@ -3515,7 +3532,7 @@ function RlsImageEditor(props) {
|
|
|
3515
3532
|
context?.putImageData(originalImage.current, 0, 0);
|
|
3516
3533
|
}
|
|
3517
3534
|
}, []);
|
|
3518
|
-
return (jsxRuntimeExports.jsxs("div", { className: "rls-image-editor", children: [jsxRuntimeExports.jsx("div", { ref: refBody, className: "rls-image-editor__body", children: jsxRuntimeExports.jsxs("div", { ref: refImage, className: "rls-image-editor__body__image", children: [jsxRuntimeExports.jsx("div", { ref: refSelection, className: "rls-image-editor__body__selection" }), jsxRuntimeExports.jsx("div", { ref: refOverlayTop, className: "rls-image-editor__body__overlay--top" }), jsxRuntimeExports.jsx("div", { ref: refOverlayRight, className: "rls-image-editor__body__overlay--right" }), jsxRuntimeExports.jsx("div", { ref: refOverlayBottom, className: "rls-image-editor__body__overlay--bottom" }), jsxRuntimeExports.jsx("div", { ref: refOverlayLeft, className: "rls-image-editor__body__overlay--left" }), jsxRuntimeExports.jsx("canvas", { ref: refCanvas })] }) }), jsxRuntimeExports.jsxs("div", { className: "rls-image-editor__footer", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-editor__sliders", children: jsxRuntimeExports.jsx(RlsSlider, { prefixIcon: "external-link", value: selection, minValue:
|
|
3535
|
+
return (jsxRuntimeExports.jsxs("div", { className: "rls-image-editor", children: [jsxRuntimeExports.jsx("div", { ref: refBody, className: "rls-image-editor__body", children: jsxRuntimeExports.jsxs("div", { ref: refImage, className: "rls-image-editor__body__image", children: [jsxRuntimeExports.jsx("div", { ref: refSelection, className: "rls-image-editor__body__selection" }), jsxRuntimeExports.jsx("div", { ref: refOverlayTop, className: "rls-image-editor__body__overlay--top" }), jsxRuntimeExports.jsx("div", { ref: refOverlayRight, className: "rls-image-editor__body__overlay--right" }), jsxRuntimeExports.jsx("div", { ref: refOverlayBottom, className: "rls-image-editor__body__overlay--bottom" }), jsxRuntimeExports.jsx("div", { ref: refOverlayLeft, className: "rls-image-editor__body__overlay--left" }), jsxRuntimeExports.jsx("canvas", { ref: refCanvas })] }) }), jsxRuntimeExports.jsxs("div", { className: "rls-image-editor__footer", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-editor__sliders", children: jsxRuntimeExports.jsx(RlsSlider, { prefixIcon: "external-link", value: selection, minValue: minValueSlider, maxValue: maxValueSlider, onValue: setSelection, disabled: props.disabled }) }), jsxRuntimeExports.jsxs("div", { className: "rls-image-editor__actions", children: [props.children, jsxRuntimeExports.jsx(RlsButton, { type: "classic", prefixIcon: "refresh", onClick: onRestore, disabled: props.disabled, children: labels.actionRestore }), jsxRuntimeExports.jsx(RlsButton, { type: "raised", prefixIcon: "crop", onClick: onCropImage, disabled: props.disabled, children: labels.actionSelect })] })] }), jsxRuntimeExports.jsx("canvas", { ref: refPicture })] }));
|
|
3519
3536
|
}
|
|
3520
3537
|
|
|
3521
3538
|
function RlsImageEditorModal(props) {
|
|
@@ -3784,6 +3801,7 @@ exports.RlsSwitch = RlsSwitch;
|
|
|
3784
3801
|
exports.RlsSwitchControl = RlsSwitchControl;
|
|
3785
3802
|
exports.RlsTabularText = RlsTabularText;
|
|
3786
3803
|
exports.RlsToolbar = RlsToolbar;
|
|
3804
|
+
exports.calculateImgDimension = calculateImgDimension;
|
|
3787
3805
|
exports.rangeFormatTemplate = rangeFormatTemplate;
|
|
3788
3806
|
exports.renderClassStatus = renderClassStatus;
|
|
3789
3807
|
exports.setErrorsI18n = setErrorsI18n;
|