@rolster/react-components 18.21.46 → 18.22.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.
Files changed (43) hide show
  1. package/dist/cjs/assets/{index-CaA_sxmM.css → index-PeMi6MeC.css} +197 -0
  2. package/dist/cjs/index.js +438 -5
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/es/assets/{index-CaA_sxmM.css → index-PeMi6MeC.css} +197 -0
  5. package/dist/es/index.js +434 -6
  6. package/dist/es/index.js.map +1 -1
  7. package/dist/esm/components/molecules/Slider/Slider.css +60 -0
  8. package/dist/esm/components/molecules/Slider/Slider.css.map +1 -0
  9. package/dist/esm/components/molecules/Slider/Slider.d.ts +14 -0
  10. package/dist/esm/components/molecules/Slider/Slider.js +60 -0
  11. package/dist/esm/components/molecules/Slider/Slider.js.map +1 -0
  12. package/dist/esm/components/molecules/index.d.ts +1 -0
  13. package/dist/esm/components/molecules/index.js +1 -0
  14. package/dist/esm/components/molecules/index.js.map +1 -1
  15. package/dist/esm/components/organisms/ImageChooser/ImageChooser.css +37 -0
  16. package/dist/esm/components/organisms/ImageChooser/ImageChooser.css.map +1 -0
  17. package/dist/esm/components/organisms/ImageChooser/ImageChooser.d.ts +11 -0
  18. package/dist/esm/components/organisms/ImageChooser/ImageChooser.js +62 -0
  19. package/dist/esm/components/organisms/ImageChooser/ImageChooser.js.map +1 -0
  20. package/dist/esm/components/organisms/ImageEditor/ImageEditor.css +97 -0
  21. package/dist/esm/components/organisms/ImageEditor/ImageEditor.css.map +1 -0
  22. package/dist/esm/components/organisms/ImageEditor/ImageEditor.d.ts +20 -0
  23. package/dist/esm/components/organisms/ImageEditor/ImageEditor.js +201 -0
  24. package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -0
  25. package/dist/esm/components/organisms/Modal/Modal.d.ts +2 -1
  26. package/dist/esm/components/organisms/Modal/Modal.js +5 -5
  27. package/dist/esm/components/organisms/Modal/Modal.js.map +1 -1
  28. package/dist/esm/components/organisms/index.d.ts +2 -0
  29. package/dist/esm/components/organisms/index.js +2 -0
  30. package/dist/esm/components/organisms/index.js.map +1 -1
  31. package/dist/esm/controllers/RelocationOnComponentController.d.ts +8 -0
  32. package/dist/esm/controllers/RelocationOnComponentController.js +93 -0
  33. package/dist/esm/controllers/RelocationOnComponentController.js.map +1 -0
  34. package/dist/esm/controllers/ResizeController.d.ts +15 -0
  35. package/dist/esm/controllers/ResizeController.js +29 -0
  36. package/dist/esm/controllers/ResizeController.js.map +1 -0
  37. package/dist/esm/controllers/index.d.ts +2 -0
  38. package/dist/esm/controllers/index.js +2 -0
  39. package/dist/esm/controllers/index.js.map +1 -1
  40. package/dist/esm/i18n.d.ts +3 -0
  41. package/dist/esm/i18n.js +6 -0
  42. package/dist/esm/i18n.js.map +1 -1
  43. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -2281,6 +2281,61 @@ function RlsPickerYear({ date: _date, disabled, formControl, maxDate, minDate, o
2281
2281
  return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-year", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-picker-year__header", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-year__action rls-picker-year__action--prev", children: jsxRuntimeExports.jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onClickPrev, disabled: !template.canPrevious || disabled }) }), jsxRuntimeExports.jsxs("label", { className: "rls-title-bold", children: [template.minRange, " - ", template.maxRange] }), jsxRuntimeExports.jsx("div", { className: "rls-picker-year__action rls-picker-year__action--next", children: jsxRuntimeExports.jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onClickNext, disabled: !template.canNext || disabled }) })] }), jsxRuntimeExports.jsx("div", { className: "rls-picker-year__component", children: component })] }));
2282
2282
  }
2283
2283
 
2284
+ function calculateInitialValue(value, minValue, maxValue) {
2285
+ return minValue > value ? minValue : maxValue < value ? maxValue : value;
2286
+ }
2287
+ function calculateInitialRate(value, minValue, maxValue) {
2288
+ const rateMax = maxValue - minValue;
2289
+ const rateValue = value - minValue;
2290
+ return Math.ceil((rateValue / rateMax) * 100);
2291
+ }
2292
+ function RlsSlider(props) {
2293
+ const minValue = require$$0.useMemo(() => {
2294
+ return props.minValue ?? 0;
2295
+ }, [props.minValue]);
2296
+ const maxValue = require$$0.useMemo(() => {
2297
+ return props.maxValue ?? 100;
2298
+ }, [props.maxValue]);
2299
+ const [value, setValue] = require$$0.useState(calculateInitialValue(props.formControl?.value ?? props.value ?? 0, minValue, maxValue));
2300
+ const [rate, setRate] = require$$0.useState(calculateInitialRate(value, minValue, maxValue));
2301
+ const refComponent = require$$0.useRef(null);
2302
+ const refTrack = require$$0.useRef(null);
2303
+ const refTrackOn = require$$0.useRef(null);
2304
+ const refThumb = require$$0.useRef(null);
2305
+ const className = require$$0.useMemo(() => {
2306
+ return renderClassStatus('rls-slider', {
2307
+ complet: value === maxValue,
2308
+ disabled: props.disabled,
2309
+ empty: value === minValue
2310
+ });
2311
+ }, [value, minValue, maxValue, props.disabled]);
2312
+ require$$0.useEffect(() => {
2313
+ const valueInitial = props.formControl?.value ?? props.value ?? 0;
2314
+ refThumb.current.style.left = `${rate}%`;
2315
+ refTrackOn.current.style.width = `${rate}%`;
2316
+ if (valueInitial !== value) {
2317
+ props.formControl?.setValue(value);
2318
+ props.onValue && props.onValue(value);
2319
+ }
2320
+ }, []);
2321
+ const calculateValueWithRate = require$$0.useCallback((rate) => {
2322
+ const value = Math.ceil(((maxValue - minValue) * rate) / 100);
2323
+ refThumb.current.style.left = `${rate}%`;
2324
+ refTrackOn.current.style.width = `${rate}%`;
2325
+ const sliderValue = value + minValue;
2326
+ setRate(rate);
2327
+ setValue(sliderValue);
2328
+ props.formControl?.setValue(sliderValue);
2329
+ props.onValue && props.onValue(sliderValue);
2330
+ }, [minValue, maxValue, props.formControl, props.onValue]);
2331
+ const onClickTrack = require$$0.useCallback((event) => {
2332
+ const { left, width } = refTrack.current.getBoundingClientRect();
2333
+ const rate = Math.ceil(((event.clientX - left) / width) * 100);
2334
+ calculateValueWithRate(rate);
2335
+ }, [minValue, maxValue]);
2336
+ return (jsxRuntimeExports.jsxs("div", { className: className, children: [props.children && (jsxRuntimeExports.jsx("span", { className: "rls-slider__label", children: props.children })), jsxRuntimeExports.jsxs("div", { className: "rls-slider__body", children: [props.prefixIcon && jsxRuntimeExports.jsx(RlsIcon, { value: props.prefixIcon }), jsxRuntimeExports.jsxs("div", { ref: refComponent, className: "rls-slider__component", children: [jsxRuntimeExports.jsx("div", { ref: refTrack, className: "rls-slider__track", onClick: onClickTrack, children: jsxRuntimeExports.jsx("div", { ref: refTrackOn, className: "rls-slider__track__on" }) }), jsxRuntimeExports.jsxs("div", { ref: refThumb, className: "rls-slider__thumb", children: [rate, "%"] })] })] })] }));
2337
+ }
2338
+
2284
2339
  function RlsToolbar({ actions, children, subtitle }) {
2285
2340
  return (jsxRuntimeExports.jsxs("div", { className: "rls-toolbar", children: [jsxRuntimeExports.jsxs("div", { className: "rls-toolbar__description", children: [children && jsxRuntimeExports.jsx("label", { className: "rls-toolbar__title", children: children }), subtitle && (jsxRuntimeExports.jsx("label", { className: "rls-toolbar__subtitle smalltext-semibold", children: subtitle }))] }), actions && (jsxRuntimeExports.jsx("div", { className: "rls-toolbar__actions", children: actions.map((action, index) => (jsxRuntimeExports.jsx("div", { children: action }, index))) }))] }));
2286
2341
  }
@@ -2298,6 +2353,9 @@ const reactI18n = i18n.i18n({
2298
2353
  dateActionCancel: 'Cancelar',
2299
2354
  dateActionSelect: 'Establecer',
2300
2355
  dateActionToday: 'Hoy',
2356
+ chooserImageActionCancel: 'Cancelar',
2357
+ editorImageActionRestore: 'Restaurar',
2358
+ editorImageActionSelect: 'Seleccionar',
2301
2359
  listEmptyDescription: 'Lo sentimos, en el momento no hay elementos en el listado',
2302
2360
  listEmptyTitle: 'Selección no disponible',
2303
2361
  listInputPlaceholder: 'Escriba palabre clave para filtrar...'
@@ -2307,6 +2365,9 @@ const reactI18n = i18n.i18n({
2307
2365
  dateActionCancel: 'Cancel',
2308
2366
  dateActionSelect: 'Select',
2309
2367
  dateActionToday: 'Today',
2368
+ chooserImageActionCancel: 'Cancel',
2369
+ editorImageActionRestore: 'Restore',
2370
+ editorImageActionSelect: 'Select',
2310
2371
  listEmptyDescription: 'Sorry, there are currently no items in the list',
2311
2372
  listEmptyTitle: 'Selection not available',
2312
2373
  listInputPlaceholder: 'Enter keyword to filter...'
@@ -2562,6 +2623,126 @@ function useListController(props) {
2562
2623
  };
2563
2624
  }
2564
2625
 
2626
+ function useRelocationOnComponent({ container, element, onDrag }) {
2627
+ const position = require$$0.useRef({ x: 0, y: 0 });
2628
+ const dragOffset = require$$0.useRef({ x: 0, y: 0 });
2629
+ const dragging = require$$0.useRef(false);
2630
+ const getClientX = require$$0.useCallback((positionX) => {
2631
+ let clientX = position.current.x + positionX - dragOffset.current.x;
2632
+ if (clientX < 0) {
2633
+ clientX = 0;
2634
+ }
2635
+ else {
2636
+ const width = clientX + element.current.offsetWidth;
2637
+ if (width > container.current.offsetWidth) {
2638
+ clientX = container.current.offsetWidth - element.current.offsetWidth;
2639
+ }
2640
+ }
2641
+ return clientX;
2642
+ }, []);
2643
+ const getClientY = require$$0.useCallback((positionY) => {
2644
+ let clientY = position.current.y + positionY - dragOffset.current.y;
2645
+ if (clientY < 0) {
2646
+ clientY = 0;
2647
+ }
2648
+ else {
2649
+ const height = clientY + element.current.offsetHeight;
2650
+ if (height > container.current.offsetHeight) {
2651
+ clientY = container.current.offsetHeight - element.current.offsetHeight;
2652
+ }
2653
+ }
2654
+ return clientY;
2655
+ }, []);
2656
+ const start = require$$0.useCallback((positionX, positionY) => {
2657
+ dragOffset.current = {
2658
+ x: positionX,
2659
+ y: positionY
2660
+ };
2661
+ position.current = {
2662
+ x: element.current.offsetLeft,
2663
+ y: element.current.offsetTop
2664
+ };
2665
+ dragging.current = true;
2666
+ }, []);
2667
+ const relocation = require$$0.useCallback((positionX, positionY) => {
2668
+ const clientX = getClientX(positionX);
2669
+ const clientY = getClientY(positionY);
2670
+ element.current.style.top = `${clientY}px`;
2671
+ element.current.style.left = `${clientX}px`;
2672
+ onDrag && onDrag();
2673
+ }, []);
2674
+ require$$0.useEffect(() => {
2675
+ const mousedown = (event) => {
2676
+ start(event.clientX, event.clientY);
2677
+ };
2678
+ const mousemove = (event) => {
2679
+ if (dragging.current) {
2680
+ relocation(event.clientX, event.clientY);
2681
+ event.preventDefault();
2682
+ }
2683
+ };
2684
+ const mouseup = () => {
2685
+ dragging.current = false;
2686
+ };
2687
+ const touchstart = (event) => {
2688
+ if (event.touches[0]) {
2689
+ start(event.touches[0].clientX, event.touches[0].clientY);
2690
+ }
2691
+ };
2692
+ const touchmove = (event) => {
2693
+ if (event.touches[0] && dragging.current) {
2694
+ relocation(event.touches[0].clientX, event.touches[0].clientY);
2695
+ event.preventDefault();
2696
+ }
2697
+ };
2698
+ const touchend = () => {
2699
+ dragging.current = false;
2700
+ };
2701
+ element.current.addEventListener('mousedown', mousedown);
2702
+ element.current.addEventListener('mousemove', mousemove);
2703
+ element.current.addEventListener('mouseup', mouseup);
2704
+ element.current.addEventListener('touchstart', touchstart);
2705
+ element.current.addEventListener('touchmove', touchmove);
2706
+ element.current.addEventListener('touchend', touchend);
2707
+ return () => {
2708
+ element.current?.removeEventListener('mousedown', mousedown);
2709
+ element.current?.removeEventListener('mousemove', mousemove);
2710
+ element.current?.removeEventListener('mouseup', mouseup);
2711
+ element.current?.removeEventListener('touchstart', touchstart);
2712
+ element.current?.removeEventListener('touchmove', touchmove);
2713
+ element.current?.removeEventListener('touchend', touchend);
2714
+ };
2715
+ }, []);
2716
+ }
2717
+
2718
+ function useResize(props) {
2719
+ const { refElement, onResize } = props;
2720
+ const dimension = require$$0.useRef({ height: 0, width: 0 });
2721
+ const observer = require$$0.useCallback((entries) => {
2722
+ const { height, width } = entries[0].contentRect;
2723
+ onResize &&
2724
+ onResize({
2725
+ current: dimension.current,
2726
+ dimension: {
2727
+ height,
2728
+ width
2729
+ }
2730
+ });
2731
+ dimension.current = { height, width };
2732
+ }, []);
2733
+ require$$0.useEffect(() => {
2734
+ dimension.current = {
2735
+ height: refElement.current.offsetHeight,
2736
+ width: refElement.current.offsetWidth
2737
+ };
2738
+ const resizeObserver = new ResizeObserver(observer);
2739
+ resizeObserver.observe(refElement.current);
2740
+ return () => {
2741
+ resizeObserver.disconnect();
2742
+ };
2743
+ }, []);
2744
+ }
2745
+
2565
2746
  const DURATION_ANIMATION$1 = 240;
2566
2747
  const MAX_ELEMENTS = 6;
2567
2748
  function useFieldAutocomplete(props) {
@@ -2741,11 +2922,11 @@ function RlsFieldAutocomplete(props) {
2741
2922
  return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
2742
2923
  }
2743
2924
 
2744
- function RlsModal({ children, overflow, visible, rlsTheme }) {
2745
- const className = require$$0.useMemo(() => {
2746
- return renderClassStatus('rls-modal', { overflow, visible });
2747
- }, [overflow, visible]);
2748
- return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-modal__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-modal__backdrop" })] }), document.body);
2925
+ function RlsModal({ children, className, overflow, visible, rlsTheme }) {
2926
+ const classNameModal = require$$0.useMemo(() => {
2927
+ return renderClassStatus('rls-modal', { overflow, visible }, className);
2928
+ }, [className, overflow, visible]);
2929
+ return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: classNameModal, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-modal__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-modal__backdrop" })] }), document.body);
2749
2930
  }
2750
2931
 
2751
2932
  const formatTitle = '{dw}, {mx} {dd} de {aa}';
@@ -3136,6 +3317,253 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
3136
3317
  return (jsxRuntimeExports.jsx("div", { className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-form-navigation__body", children: children }) }));
3137
3318
  }
3138
3319
 
3320
+ function getRatioFactor(ratio) {
3321
+ switch (ratio) {
3322
+ case '16:9':
3323
+ return 9 / 16;
3324
+ case '8:5':
3325
+ return 5 / 8;
3326
+ case '4:3':
3327
+ return 3 / 4;
3328
+ case '3:4':
3329
+ return 4 / 3;
3330
+ case '3:2':
3331
+ return 2 / 3;
3332
+ default:
3333
+ return 1;
3334
+ }
3335
+ }
3336
+ function simpleThreeRule(value1, value2, proportion) {
3337
+ return (value2 * proportion) / value1;
3338
+ }
3339
+ function RlsImageEditor(props) {
3340
+ const [selection, setSelection] = require$$0.useState(props.rateSelection ?? 60);
3341
+ const [labels, setLabels] = require$$0.useState({
3342
+ actionRestore: reactI18n('editorImageActionRestore'),
3343
+ actionSelect: reactI18n('editorImageActionSelect')
3344
+ });
3345
+ const refBody = require$$0.useRef(null);
3346
+ const refImage = require$$0.useRef(null);
3347
+ const refSelection = require$$0.useRef(null);
3348
+ const refOverlayTop = require$$0.useRef(null);
3349
+ const refOverlayBottom = require$$0.useRef(null);
3350
+ const refOverlayLeft = require$$0.useRef(null);
3351
+ const refOverlayRight = require$$0.useRef(null);
3352
+ const refCanvas = require$$0.useRef(null);
3353
+ const refPicture = require$$0.useRef(null);
3354
+ const image = require$$0.useRef(new Image());
3355
+ const originalImage = require$$0.useRef();
3356
+ const getCropProperties = require$$0.useCallback(() => {
3357
+ return {
3358
+ height: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetHeight),
3359
+ left: simpleThreeRule(refImage.current.offsetWidth, image.current.width, refSelection.current.offsetLeft),
3360
+ top: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetTop),
3361
+ width: simpleThreeRule(refImage.current.offsetWidth, image.current.width, refSelection.current.offsetWidth)
3362
+ };
3363
+ }, []);
3364
+ const refreshOverlaysStyle = require$$0.useCallback(() => {
3365
+ const width = refSelection.current.offsetWidth;
3366
+ const height = refSelection.current.offsetHeight;
3367
+ const top = refSelection.current.offsetTop;
3368
+ const left = refSelection.current.offsetLeft;
3369
+ refOverlayTop.current.style.width = `${width}px`;
3370
+ refOverlayTop.current.style.bottom = `calc(100% - ${top}px)`;
3371
+ refOverlayTop.current.style.left = `${left}px`;
3372
+ refOverlayRight.current.style.left = `calc(${width + left}px)`;
3373
+ refOverlayRight.current.style.width = `calc(100% - ${width + left}px)`;
3374
+ refOverlayBottom.current.style.width = `${width}px`;
3375
+ refOverlayBottom.current.style.top = `calc(${height + top}px)`;
3376
+ refOverlayBottom.current.style.left = `${left}px`;
3377
+ refOverlayLeft.current.style.right = `calc(100% - ${left}px)`;
3378
+ refOverlayLeft.current.style.width = `calc(${left}px)`;
3379
+ }, []);
3380
+ const refreshSelectionFromWidth = require$$0.useCallback((rateSelection) => {
3381
+ const _ratio = rateSelection * getRatioFactor(props.ratio || '1:1');
3382
+ let width = (refImage.current.offsetWidth * rateSelection) / 100;
3383
+ let height = (refImage.current.offsetWidth * _ratio) / 100;
3384
+ if (height > refImage.current.offsetHeight) {
3385
+ height = refImage.current.offsetHeight;
3386
+ width =
3387
+ (height * refImage.current.offsetHeight) /
3388
+ refImage.current.offsetHeight;
3389
+ }
3390
+ return { height, width };
3391
+ }, [props.ratio]);
3392
+ const refreshSelectionFromHeight = require$$0.useCallback((rateSelection) => {
3393
+ const _ratio = rateSelection * getRatioFactor(props.ratio || '1:1');
3394
+ let height = (refImage.current.offsetHeight * rateSelection) / 100;
3395
+ let width = (refImage.current.offsetHeight * _ratio) / 100;
3396
+ if (width > refImage.current.offsetWidth) {
3397
+ width = refImage.current.offsetWidth;
3398
+ height =
3399
+ (width * refImage.current.offsetWidth) / refImage.current.offsetWidth;
3400
+ }
3401
+ return { height, width };
3402
+ }, [props.ratio]);
3403
+ const refreshSelectionStyle = require$$0.useCallback((rateSelection) => {
3404
+ if (image.current.width > 0 && image.current.height > 0) {
3405
+ const { height, width } = image.current.width >= image.current.height
3406
+ ? refreshSelectionFromHeight(rateSelection)
3407
+ : refreshSelectionFromWidth(rateSelection);
3408
+ refSelection.current.style.width = `${width}px`;
3409
+ refSelection.current.style.height = `${height}px`;
3410
+ if (refSelection.current.offsetLeft + width >
3411
+ refImage.current.offsetWidth) {
3412
+ const selectionLeft = refImage.current.offsetWidth - width;
3413
+ refSelection.current.style.left = `${selectionLeft}px`;
3414
+ }
3415
+ if (refSelection.current.offsetTop + height >
3416
+ refImage.current.offsetHeight) {
3417
+ const selectionTop = refImage.current.offsetHeight - height;
3418
+ refSelection.current.style.top = `${selectionTop}px`;
3419
+ }
3420
+ refreshOverlaysStyle();
3421
+ }
3422
+ }, [props.ratio]);
3423
+ const setImageStyle = require$$0.useCallback((width, height) => {
3424
+ refImage.current.style.width = width;
3425
+ refImage.current.style.height = height;
3426
+ refCanvas.current.style.width = width;
3427
+ refCanvas.current.style.height = height;
3428
+ }, []);
3429
+ const refreshImageStyle = require$$0.useCallback(() => {
3430
+ if (image.current.width <= 0 || image.current.height <= 0) {
3431
+ return setImageStyle('0%', '0%');
3432
+ }
3433
+ const height = (refBody.current.offsetWidth * image.current.height) /
3434
+ image.current.width;
3435
+ if (height <= refBody.current.offsetHeight) {
3436
+ return setImageStyle('100%', `${height}px`);
3437
+ }
3438
+ const width = (refBody.current.offsetHeight * image.current.width) /
3439
+ image.current.height;
3440
+ return setImageStyle(`${width}px`, '100%');
3441
+ }, []);
3442
+ require$$0.useEffect(() => {
3443
+ image.current.onload = () => {
3444
+ const context = refCanvas.current.getContext('2d', {
3445
+ willReadFrequently: true
3446
+ });
3447
+ refCanvas.current.width = image.current.width;
3448
+ refCanvas.current.height = image.current.height;
3449
+ context?.drawImage(image.current, 0, 0, image.current.width, image.current.height);
3450
+ originalImage.current = context?.getImageData(0, 0, refCanvas.current.width, refCanvas.current.height);
3451
+ refreshImageStyle();
3452
+ refreshSelectionStyle(selection);
3453
+ };
3454
+ const unsubscription = i18n.i18nSubscribe(() => {
3455
+ setLabels({
3456
+ actionRestore: reactI18n('editorImageActionRestore'),
3457
+ actionSelect: reactI18n('editorImageActionSelect')
3458
+ });
3459
+ });
3460
+ window.addEventListener('resize', refreshImageStyle);
3461
+ return () => {
3462
+ window.removeEventListener('resize', refreshImageStyle);
3463
+ unsubscription();
3464
+ };
3465
+ }, []);
3466
+ require$$0.useEffect(() => {
3467
+ image.current.src = props.src || '';
3468
+ }, [props.src]);
3469
+ require$$0.useEffect(() => {
3470
+ refreshSelectionStyle(selection);
3471
+ }, [selection]);
3472
+ const onResizeElement = require$$0.useCallback(() => {
3473
+ refreshSelectionStyle(selection);
3474
+ }, [selection]);
3475
+ useRelocationOnComponent({
3476
+ container: refImage,
3477
+ element: refSelection,
3478
+ onDrag: refreshOverlaysStyle
3479
+ });
3480
+ useResize({ refElement: refImage, onResize: onResizeElement });
3481
+ const onCropImage = require$$0.useCallback(() => {
3482
+ const cropProps = getCropProperties();
3483
+ const width = cropProps.width;
3484
+ const height = width * getRatioFactor(props.ratio || '1:1');
3485
+ refPicture.current.width = width;
3486
+ refPicture.current.height = height;
3487
+ const context = refPicture.current.getContext('2d');
3488
+ context?.drawImage(refCanvas.current, cropProps.left, cropProps.top, cropProps.width, cropProps.height, 0, 0, width, height);
3489
+ refPicture.current.toBlob((blob) => {
3490
+ if (blob) {
3491
+ const reader = new FileReader();
3492
+ reader.readAsDataURL(blob);
3493
+ reader.onloadend = function () {
3494
+ const value = {
3495
+ base64: reader.result,
3496
+ blob
3497
+ };
3498
+ props.onValue && props.onValue(value);
3499
+ props.formControl?.setValue(value);
3500
+ };
3501
+ }
3502
+ }, props.mimeType || 'image/jpeg', 1);
3503
+ }, [props.ratio, props.mimeType, props.onValue, props.formControl]);
3504
+ const onRestore = require$$0.useCallback(() => {
3505
+ const context = refCanvas.current.getContext('2d');
3506
+ if (originalImage.current) {
3507
+ context?.putImageData(originalImage.current, 0, 0);
3508
+ }
3509
+ }, []);
3510
+ 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: 50, maxValue: 100, 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 })] }));
3511
+ }
3512
+
3513
+ const mimeTypeSupports = [
3514
+ 'image/png',
3515
+ 'image/jpg',
3516
+ 'image/jpeg',
3517
+ 'image/bmp',
3518
+ 'image/webp',
3519
+ 'image/gif',
3520
+ 'image/svg+xml'
3521
+ ];
3522
+ function RlsImageChooser(props) {
3523
+ const refInput = require$$0.useRef(null);
3524
+ const [labels, setLabels] = require$$0.useState({
3525
+ actionCancel: reactI18n('chooserImageActionCancel')
3526
+ });
3527
+ const [src, setSrc] = require$$0.useState();
3528
+ const [srcEditor, setSrcEditor] = require$$0.useState();
3529
+ const onSelect = require$$0.useCallback(() => {
3530
+ refInput.current.click();
3531
+ }, []);
3532
+ const processImage = require$$0.useCallback((file) => {
3533
+ const reader = new FileReader();
3534
+ reader.onload = function () {
3535
+ setSrcEditor(reader.result);
3536
+ refInput.current.value = '';
3537
+ };
3538
+ reader.readAsDataURL(file);
3539
+ }, []);
3540
+ require$$0.useEffect(() => {
3541
+ refInput.current.onchange = () => {
3542
+ if (refInput.current.files &&
3543
+ mimeTypeSupports.includes(refInput.current.files[0].type)) {
3544
+ processImage(refInput.current.files[0]);
3545
+ }
3546
+ };
3547
+ return i18n.i18nSubscribe(() => {
3548
+ setLabels({
3549
+ actionCancel: reactI18n('chooserImageActionCancel')
3550
+ });
3551
+ });
3552
+ }, []);
3553
+ require$$0.useEffect(() => {
3554
+ props.src && setSrc(props.src);
3555
+ }, [props.src]);
3556
+ const onEditorValue = require$$0.useCallback((image) => {
3557
+ setSrc(image.base64);
3558
+ setSrcEditor(undefined);
3559
+ props.onValue && props.onValue(image);
3560
+ }, [props.onValue]);
3561
+ const onCancel = require$$0.useCallback(() => {
3562
+ setSrcEditor(undefined);
3563
+ }, []);
3564
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-image-chooser", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-chooser__avatar", onClick: onSelect, children: src && jsxRuntimeExports.jsx("img", { src: src }) }), srcEditor && (jsxRuntimeExports.jsx(RlsModal, { className: "rls-image-chooser__modal", visible: true, children: jsxRuntimeExports.jsx(RlsImageEditor, { src: srcEditor, formControl: props.formControl, onValue: onEditorValue, children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "danger", onClick: onCancel, disabled: props.disabled, children: labels.actionCancel }) }) })), jsxRuntimeExports.jsx("input", { ref: refInput, type: "file", disabled: props.disabled })] }));
3565
+ }
3566
+
3139
3567
  const DURATION_ANIMATION = 240;
3140
3568
  const DURATION_CHAR = 75;
3141
3569
  const DURATION_MAX = 9000;
@@ -3261,6 +3689,8 @@ exports.RlsFieldSelectTemplate = RlsFieldSelectTemplate;
3261
3689
  exports.RlsFieldText = RlsFieldText;
3262
3690
  exports.RlsFormNavigation = RlsFormNavigation;
3263
3691
  exports.RlsIcon = RlsIcon;
3692
+ exports.RlsImageChooser = RlsImageChooser;
3693
+ exports.RlsImageEditor = RlsImageEditor;
3264
3694
  exports.RlsInput = RlsInput;
3265
3695
  exports.RlsInputMoney = RlsInputMoney;
3266
3696
  exports.RlsInputNumber = RlsInputNumber;
@@ -3288,6 +3718,7 @@ exports.RlsProgressCircular = RlsProgressCircular;
3288
3718
  exports.RlsRadioButton = RlsRadioButton;
3289
3719
  exports.RlsSkeleton = RlsSkeleton;
3290
3720
  exports.RlsSkeletonText = RlsSkeletonText;
3721
+ exports.RlsSlider = RlsSlider;
3291
3722
  exports.RlsSnackbar = RlsSnackbar;
3292
3723
  exports.RlsSwitch = RlsSwitch;
3293
3724
  exports.RlsSwitchControl = RlsSwitchControl;
@@ -3301,5 +3732,7 @@ exports.useDatatable = useDatatable;
3301
3732
  exports.useFieldAutocomplete = useFieldAutocomplete;
3302
3733
  exports.useFieldSelect = useFieldSelect;
3303
3734
  exports.useListController = useListController;
3735
+ exports.useRelocationOnComponent = useRelocationOnComponent;
3736
+ exports.useResize = useResize;
3304
3737
  exports.useSnackbar = useSnackbar;
3305
3738
  //# sourceMappingURL=index.js.map