@rolster/react-components 18.23.6 → 18.23.8
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 +45 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +45 -26
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.d.ts +1 -0
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.js.map +1 -1
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.d.ts +2 -1
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js +45 -26
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -1
- package/dist/esm/components/organisms/ImageEditorModal/ImageEditorModal.d.ts +1 -1
- package/dist/esm/controllers/ImageEditorController.d.ts +1 -0
- package/dist/esm/controllers/ImageEditorController.js +1 -1
- package/dist/esm/controllers/ImageEditorController.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,11 +3330,22 @@ 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
|
-
const [selection, setSelection] = require$$0.useState(props.
|
|
3348
|
+
const [selection, setSelection] = require$$0.useState(props.selection ?? 60);
|
|
3336
3349
|
const [labels, setLabels] = require$$0.useState({
|
|
3337
3350
|
actionRestore: reactI18n('editorImageActionRestore'),
|
|
3338
3351
|
actionSelect: reactI18n('editorImageActionSelect')
|
|
@@ -3348,6 +3361,9 @@ function RlsImageEditor(props) {
|
|
|
3348
3361
|
const refPicture = require$$0.useRef(null);
|
|
3349
3362
|
const image = require$$0.useRef(new Image());
|
|
3350
3363
|
const originalImage = require$$0.useRef();
|
|
3364
|
+
const ratio = require$$0.useMemo(() => {
|
|
3365
|
+
return props.ratio || '1:1';
|
|
3366
|
+
}, [props.ratio]);
|
|
3351
3367
|
const getCropProperties = require$$0.useCallback(() => {
|
|
3352
3368
|
return {
|
|
3353
3369
|
height: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetHeight),
|
|
@@ -3373,7 +3389,7 @@ function RlsImageEditor(props) {
|
|
|
3373
3389
|
refOverlayLeft.current.style.width = `calc(${left}px)`;
|
|
3374
3390
|
}, []);
|
|
3375
3391
|
const refreshSelectionFromWidth = require$$0.useCallback((rateSelection) => {
|
|
3376
|
-
const ratioFactor = getRatioFactor(
|
|
3392
|
+
const ratioFactor = getRatioFactor(ratio);
|
|
3377
3393
|
const _ratio = rateSelection * ratioFactor;
|
|
3378
3394
|
const offsetWidth = refImage.current?.offsetWidth || 0;
|
|
3379
3395
|
const offsetHeight = refImage.current?.offsetHeight || 0;
|
|
@@ -3384,22 +3400,24 @@ function RlsImageEditor(props) {
|
|
|
3384
3400
|
width = height / ratioFactor;
|
|
3385
3401
|
}
|
|
3386
3402
|
return { height, width };
|
|
3387
|
-
}, [
|
|
3403
|
+
}, [ratio]);
|
|
3388
3404
|
const refreshSelectionFromHeight = require$$0.useCallback((rateSelection) => {
|
|
3389
|
-
const ratioFactor = getRatioFactor(
|
|
3390
|
-
const _ratio = rateSelection
|
|
3405
|
+
const ratioFactor = getRatioFactor(ratio);
|
|
3406
|
+
const _ratio = rateSelection / ratioFactor;
|
|
3391
3407
|
const offsetWidth = refImage.current?.offsetWidth || 0;
|
|
3392
3408
|
const offsetHeight = refImage.current?.offsetHeight || 0;
|
|
3393
3409
|
let height = (offsetHeight * rateSelection) / 100;
|
|
3394
3410
|
let width = (offsetHeight * _ratio) / 100;
|
|
3395
3411
|
if (width > offsetWidth) {
|
|
3396
3412
|
width = offsetWidth;
|
|
3397
|
-
height = width
|
|
3413
|
+
height = width * ratioFactor;
|
|
3398
3414
|
}
|
|
3399
3415
|
return { height, width };
|
|
3400
|
-
}, [
|
|
3416
|
+
}, [ratio]);
|
|
3401
3417
|
const refreshSelectionStyle = require$$0.useCallback((rateSelection) => {
|
|
3402
|
-
if (
|
|
3418
|
+
if (refSelection.current &&
|
|
3419
|
+
image.current.width > 0 &&
|
|
3420
|
+
image.current.height > 0) {
|
|
3403
3421
|
const { height, width } = image.current.width >= image.current.height
|
|
3404
3422
|
? refreshSelectionFromHeight(rateSelection)
|
|
3405
3423
|
: refreshSelectionFromWidth(rateSelection);
|
|
@@ -3407,17 +3425,17 @@ function RlsImageEditor(props) {
|
|
|
3407
3425
|
refSelection.current.style.height = `${height}px`;
|
|
3408
3426
|
if (refSelection.current.offsetLeft + width >
|
|
3409
3427
|
refImage.current.offsetWidth) {
|
|
3410
|
-
const
|
|
3411
|
-
refSelection.current.style.left = `${
|
|
3428
|
+
const left = refImage.current.offsetWidth - width;
|
|
3429
|
+
refSelection.current.style.left = `${left < 0 ? 0 : left}px`;
|
|
3412
3430
|
}
|
|
3413
3431
|
if (refSelection.current.offsetTop + height >
|
|
3414
3432
|
refImage.current.offsetHeight) {
|
|
3415
|
-
const
|
|
3416
|
-
refSelection.current.style.top = `${
|
|
3433
|
+
const top = refImage.current.offsetHeight - height;
|
|
3434
|
+
refSelection.current.style.top = `${top < 0 ? 0 : top}px`;
|
|
3417
3435
|
}
|
|
3418
3436
|
refreshOverlaysStyle();
|
|
3419
3437
|
}
|
|
3420
|
-
}, [
|
|
3438
|
+
}, [ratio]);
|
|
3421
3439
|
const setImageStyle = require$$0.useCallback((width, height) => {
|
|
3422
3440
|
refImage.current.style.width = width;
|
|
3423
3441
|
refImage.current.style.height = height;
|
|
@@ -3426,7 +3444,7 @@ function RlsImageEditor(props) {
|
|
|
3426
3444
|
}, []);
|
|
3427
3445
|
const refreshImageStyle = require$$0.useCallback(() => {
|
|
3428
3446
|
if (image.current.width <= 0 || image.current.height <= 0) {
|
|
3429
|
-
return setImageStyle('
|
|
3447
|
+
return setImageStyle('0px', '0px');
|
|
3430
3448
|
}
|
|
3431
3449
|
const height = (refBody.current.offsetWidth * image.current.height) /
|
|
3432
3450
|
image.current.width;
|
|
@@ -3436,16 +3454,17 @@ function RlsImageEditor(props) {
|
|
|
3436
3454
|
const width = (refBody.current.offsetHeight * image.current.width) /
|
|
3437
3455
|
image.current.height;
|
|
3438
3456
|
return setImageStyle(`${width}px`, '100%');
|
|
3439
|
-
}, []);
|
|
3457
|
+
}, [ratio]);
|
|
3440
3458
|
require$$0.useEffect(() => {
|
|
3441
3459
|
image.current.onload = () => {
|
|
3442
3460
|
const context = refCanvas.current.getContext('2d', {
|
|
3443
3461
|
willReadFrequently: true
|
|
3444
3462
|
});
|
|
3445
|
-
|
|
3446
|
-
refCanvas.current.
|
|
3447
|
-
|
|
3448
|
-
|
|
3463
|
+
const { height, width } = calculateImgDimension(image.current, props.maxDimension || 500);
|
|
3464
|
+
refCanvas.current.width = width;
|
|
3465
|
+
refCanvas.current.height = height;
|
|
3466
|
+
context?.drawImage(image.current, 0, 0, width, height);
|
|
3467
|
+
originalImage.current = context?.getImageData(0, 0, width, height);
|
|
3449
3468
|
refreshImageStyle();
|
|
3450
3469
|
refreshSelectionStyle(selection);
|
|
3451
3470
|
};
|
|
@@ -3466,7 +3485,7 @@ function RlsImageEditor(props) {
|
|
|
3466
3485
|
}, [props.src]);
|
|
3467
3486
|
require$$0.useEffect(() => {
|
|
3468
3487
|
refreshSelectionStyle(selection);
|
|
3469
|
-
}, [selection]);
|
|
3488
|
+
}, [ratio, selection]);
|
|
3470
3489
|
const onResizeElement = require$$0.useCallback(() => {
|
|
3471
3490
|
refreshSelectionStyle(selection);
|
|
3472
3491
|
}, [selection]);
|
|
@@ -3479,7 +3498,7 @@ function RlsImageEditor(props) {
|
|
|
3479
3498
|
const onCropImage = require$$0.useCallback(() => {
|
|
3480
3499
|
const cropProps = getCropProperties();
|
|
3481
3500
|
const width = props.maxWidth || cropProps.width;
|
|
3482
|
-
const height = width * getRatioFactor(
|
|
3501
|
+
const height = width * getRatioFactor(ratio);
|
|
3483
3502
|
refPicture.current.width = width;
|
|
3484
3503
|
refPicture.current.height = height;
|
|
3485
3504
|
const context = refPicture.current.getContext('2d');
|
|
@@ -3499,7 +3518,7 @@ function RlsImageEditor(props) {
|
|
|
3499
3518
|
}
|
|
3500
3519
|
}, props.mimeType || 'image/jpeg', props.quality || 1);
|
|
3501
3520
|
}, [
|
|
3502
|
-
|
|
3521
|
+
ratio,
|
|
3503
3522
|
props.mimeType,
|
|
3504
3523
|
props.onValue,
|
|
3505
3524
|
props.formControl,
|
|
@@ -3512,7 +3531,7 @@ function RlsImageEditor(props) {
|
|
|
3512
3531
|
context?.putImageData(originalImage.current, 0, 0);
|
|
3513
3532
|
}
|
|
3514
3533
|
}, []);
|
|
3515
|
-
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:
|
|
3534
|
+
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 })] }));
|
|
3516
3535
|
}
|
|
3517
3536
|
|
|
3518
3537
|
function RlsImageEditorModal(props) {
|
|
@@ -3566,7 +3585,7 @@ function useImageEditorController(options) {
|
|
|
3566
3585
|
setSrcEditor(undefined);
|
|
3567
3586
|
}, []);
|
|
3568
3587
|
const RlsImageEditorChooser = require$$0.useMemo(() => {
|
|
3569
|
-
return (srcEditor && (jsxRuntimeExports.jsx(RlsImageEditorModal, { visible: true, src: srcEditor, formControl: options.formControl, maxWidth: options.maxWidth, quality: options.quality, ratio: options.ratio, onValue: onEditorValue, children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "danger", onClick: onCancel, disabled: options.disabled, children: labels.actionCancel }) })));
|
|
3588
|
+
return (srcEditor && (jsxRuntimeExports.jsx(RlsImageEditorModal, { visible: true, src: srcEditor, formControl: options.formControl, maxWidth: options.maxWidth, quality: options.quality, ratio: options.ratio, selection: options.selection, onValue: onEditorValue, children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "danger", onClick: onCancel, disabled: options.disabled, children: labels.actionCancel }) })));
|
|
3570
3589
|
}, [
|
|
3571
3590
|
srcEditor,
|
|
3572
3591
|
labels,
|