labellife-design-tool 2.3.8 → 2.4.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/dist/cjs/canvas/workspace.js +219 -10
- package/dist/cjs/canvas/workspace.js.map +1 -1
- package/dist/cjs/index.js +546 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/store.js +215 -3
- package/dist/cjs/model/store.js.map +1 -1
- package/dist/cjs/side-panel/index.js +120 -0
- package/dist/cjs/side-panel/index.js.map +1 -1
- package/dist/cjs/side-panel/side-panel.js +120 -0
- package/dist/cjs/side-panel/side-panel.js.map +1 -1
- package/dist/cjs/toolbar/toolbar.js +18 -1
- package/dist/cjs/toolbar/toolbar.js.map +1 -1
- package/dist/esm/canvas/workspace.js +221 -12
- package/dist/esm/canvas/workspace.js.map +1 -1
- package/dist/esm/index.js +547 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model/store.js +215 -3
- package/dist/esm/model/store.js.map +1 -1
- package/dist/esm/side-panel/index.js +120 -0
- package/dist/esm/side-panel/index.js.map +1 -1
- package/dist/esm/side-panel/side-panel.js +120 -0
- package/dist/esm/side-panel/side-panel.js.map +1 -1
- package/dist/esm/toolbar/toolbar.js +18 -1
- package/dist/esm/toolbar/toolbar.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -45,7 +45,7 @@ import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft';
|
|
|
45
45
|
import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter';
|
|
46
46
|
import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight';
|
|
47
47
|
import OpacityIcon from '@mui/icons-material/Opacity';
|
|
48
|
-
import '@mui/icons-material/Crop';
|
|
48
|
+
import CropIcon from '@mui/icons-material/Crop';
|
|
49
49
|
import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome';
|
|
50
50
|
import SwapHorizIcon from '@mui/icons-material/SwapHoriz';
|
|
51
51
|
import SwapVertIcon from '@mui/icons-material/SwapVert';
|
|
@@ -61,7 +61,7 @@ import VerticalAlignBottomIcon from '@mui/icons-material/VerticalAlignBottom';
|
|
|
61
61
|
import ZoomInIcon from '@mui/icons-material/ZoomIn';
|
|
62
62
|
import ZoomOutIcon from '@mui/icons-material/ZoomOut';
|
|
63
63
|
import FitScreenIcon from '@mui/icons-material/FitScreen';
|
|
64
|
-
import { Image as Image$1,
|
|
64
|
+
import { Group, Image as Image$1, Rect, Transformer, Text, Arrow, Path, RegularPolygon, Star, Circle, Line, Shape as Shape$1, Stage, Layer } from 'react-konva';
|
|
65
65
|
import Konva from 'konva';
|
|
66
66
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
|
67
67
|
|
|
@@ -631,6 +631,84 @@ var Shape = Node.named('Shape').props({
|
|
|
631
631
|
};
|
|
632
632
|
});
|
|
633
633
|
|
|
634
|
+
// Cover-fit crop fractions (centered) for a box of given size over an image of natural size.
|
|
635
|
+
// Mirrors the existing auto-crop calculation in canvas/image-element.js.
|
|
636
|
+
function coverFitCrop(boxWidth, boxHeight, naturalWidth, naturalHeight) {
|
|
637
|
+
var boxAspect = boxWidth / boxHeight;
|
|
638
|
+
var imgAspect = naturalWidth / naturalHeight;
|
|
639
|
+
if (imgAspect > boxAspect) {
|
|
640
|
+
var _cw = naturalHeight * boxAspect;
|
|
641
|
+
return {
|
|
642
|
+
cropX: (naturalWidth - _cw) / 2 / naturalWidth,
|
|
643
|
+
cropY: 0,
|
|
644
|
+
cropWidth: _cw / naturalWidth,
|
|
645
|
+
cropHeight: 1
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
var ch = naturalWidth / boxAspect;
|
|
649
|
+
return {
|
|
650
|
+
cropX: 0,
|
|
651
|
+
cropY: (naturalHeight - ch) / 2 / naturalHeight,
|
|
652
|
+
cropWidth: 1,
|
|
653
|
+
cropHeight: ch / naturalHeight
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// Whether stored crop fields represent an explicit (non-default) manual crop.
|
|
658
|
+
function hasManualCrop(cropX, cropY, cropWidth, cropHeight) {
|
|
659
|
+
return cropX !== 0 || cropY !== 0 || cropWidth !== 1 || cropHeight !== 1;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// Convert a crop (fractions of natural image size) + target rect (page units) into an
|
|
663
|
+
// image position/scale such that the crop region renders exactly under the rect.
|
|
664
|
+
function cropToImageTransform(crop, rect, naturalWidth, naturalHeight) {
|
|
665
|
+
var naturalX = crop.cropX * naturalWidth;
|
|
666
|
+
var naturalY = crop.cropY * naturalHeight;
|
|
667
|
+
var naturalW = crop.cropWidth * naturalWidth;
|
|
668
|
+
var scale = naturalW > 0 ? rect.width / naturalW : 1;
|
|
669
|
+
return {
|
|
670
|
+
scale: scale,
|
|
671
|
+
offset: {
|
|
672
|
+
x: rect.x - naturalX * scale,
|
|
673
|
+
y: rect.y - naturalY * scale
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// Inverse: given the image's page-space position/scale and a rect, compute crop fractions.
|
|
679
|
+
function rectToCrop(rect, imgOffset, imgScale, naturalWidth, naturalHeight) {
|
|
680
|
+
var naturalX = (rect.x - imgOffset.x) / imgScale;
|
|
681
|
+
var naturalY = (rect.y - imgOffset.y) / imgScale;
|
|
682
|
+
var naturalW = rect.width / imgScale;
|
|
683
|
+
var naturalH = rect.height / imgScale;
|
|
684
|
+
return {
|
|
685
|
+
cropX: naturalX / naturalWidth,
|
|
686
|
+
cropY: naturalY / naturalHeight,
|
|
687
|
+
cropWidth: naturalW / naturalWidth,
|
|
688
|
+
cropHeight: naturalH / naturalHeight
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// Minimum scale at which the image (rendered at naturalWidth*scale x naturalHeight*scale)
|
|
693
|
+
// still fully covers rect.
|
|
694
|
+
function minScaleForRect(rect, naturalWidth, naturalHeight) {
|
|
695
|
+
return Math.max(rect.width / naturalWidth, rect.height / naturalHeight);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// Clamp an image page-space offset so the image still fully covers rect at the given scale.
|
|
699
|
+
function clampImageOffset(offset, scale, rect, naturalWidth, naturalHeight) {
|
|
700
|
+
var imgW = naturalWidth * scale;
|
|
701
|
+
var imgH = naturalHeight * scale;
|
|
702
|
+
var minX = rect.x + rect.width - imgW;
|
|
703
|
+
var maxX = rect.x;
|
|
704
|
+
var minY = rect.y + rect.height - imgH;
|
|
705
|
+
var maxY = rect.y;
|
|
706
|
+
return {
|
|
707
|
+
x: Math.min(maxX, Math.max(minX, offset.x)),
|
|
708
|
+
y: Math.min(maxY, Math.max(minY, offset.y))
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
|
|
634
712
|
var ImageElement = Shape.named('ImageElement').props({
|
|
635
713
|
type: types.optional(types.string, 'image'),
|
|
636
714
|
src: types.optional(types.string, ''),
|
|
@@ -664,12 +742,132 @@ var ImageElement = Shape.named('ImageElement').props({
|
|
|
664
742
|
return s;
|
|
665
743
|
})["volatile"](function () {
|
|
666
744
|
return {
|
|
667
|
-
|
|
745
|
+
// Set once, when the image finishes loading (see canvas/image-element.js).
|
|
746
|
+
_naturalWidth: 0,
|
|
747
|
+
_naturalHeight: 0,
|
|
748
|
+
// Crop-mode editing state — all null/default when not cropping.
|
|
749
|
+
_cropModeEnabled: false,
|
|
750
|
+
_cropEntrySnapshot: null,
|
|
751
|
+
_cropRect: null,
|
|
752
|
+
_cropImgOffset: null,
|
|
753
|
+
_cropImgScale: 1,
|
|
754
|
+
_cropNaturalWidth: 0,
|
|
755
|
+
_cropNaturalHeight: 0
|
|
668
756
|
};
|
|
669
757
|
}).actions(function (self) {
|
|
670
758
|
return {
|
|
671
|
-
|
|
672
|
-
self.
|
|
759
|
+
setNaturalSize: function setNaturalSize(width, height) {
|
|
760
|
+
self._naturalWidth = width;
|
|
761
|
+
self._naturalHeight = height;
|
|
762
|
+
},
|
|
763
|
+
enterCropMode: function enterCropMode() {
|
|
764
|
+
var naturalWidth = self._naturalWidth;
|
|
765
|
+
var naturalHeight = self._naturalHeight;
|
|
766
|
+
if (!naturalWidth || !naturalHeight) return;
|
|
767
|
+
if (self.rotation !== 0 || self.flipX || self.flipY) return;
|
|
768
|
+
self._cropEntrySnapshot = {
|
|
769
|
+
x: self.x,
|
|
770
|
+
y: self.y,
|
|
771
|
+
width: self.width,
|
|
772
|
+
height: self.height,
|
|
773
|
+
cropX: self.cropX,
|
|
774
|
+
cropY: self.cropY,
|
|
775
|
+
cropWidth: self.cropWidth,
|
|
776
|
+
cropHeight: self.cropHeight
|
|
777
|
+
};
|
|
778
|
+
var rect = {
|
|
779
|
+
x: self.x,
|
|
780
|
+
y: self.y,
|
|
781
|
+
width: self.width,
|
|
782
|
+
height: self.height
|
|
783
|
+
};
|
|
784
|
+
var crop = hasManualCrop(self.cropX, self.cropY, self.cropWidth, self.cropHeight) ? {
|
|
785
|
+
cropX: self.cropX,
|
|
786
|
+
cropY: self.cropY,
|
|
787
|
+
cropWidth: self.cropWidth,
|
|
788
|
+
cropHeight: self.cropHeight
|
|
789
|
+
} : coverFitCrop(rect.width, rect.height, naturalWidth, naturalHeight);
|
|
790
|
+
var _cropToImageTransform = cropToImageTransform(crop, rect, naturalWidth, naturalHeight),
|
|
791
|
+
scale = _cropToImageTransform.scale,
|
|
792
|
+
offset = _cropToImageTransform.offset;
|
|
793
|
+
self._cropRect = rect;
|
|
794
|
+
self._cropImgOffset = offset;
|
|
795
|
+
self._cropImgScale = scale;
|
|
796
|
+
self._cropNaturalWidth = naturalWidth;
|
|
797
|
+
self._cropNaturalHeight = naturalHeight;
|
|
798
|
+
self._cropModeEnabled = true;
|
|
799
|
+
},
|
|
800
|
+
setCropRectAndClamp: function setCropRectAndClamp(rect) {
|
|
801
|
+
// Defensive guard (not in the original brief text): without this, a caller invoking
|
|
802
|
+
// this action while crop mode is inactive (e.g. enterCropMode() no-op'd because the
|
|
803
|
+
// image hadn't loaded yet) would hit minScaleForRect/clampImageOffset with
|
|
804
|
+
// _cropNaturalWidth/_cropNaturalHeight still at their 0 defaults, producing
|
|
805
|
+
// Infinity/NaN. Crop mode is only ever active with a nonzero natural size (see
|
|
806
|
+
// enterCropMode's guard above), so gating on _cropModeEnabled here is equivalent to
|
|
807
|
+
// gating on nonzero natural size, without changing behavior for the normal case.
|
|
808
|
+
if (!self._cropModeEnabled) return;
|
|
809
|
+
self._cropRect = rect;
|
|
810
|
+
var minScale = minScaleForRect(rect, self._cropNaturalWidth, self._cropNaturalHeight);
|
|
811
|
+
if (self._cropImgScale < minScale) {
|
|
812
|
+
self._cropImgScale = minScale;
|
|
813
|
+
}
|
|
814
|
+
self._cropImgOffset = clampImageOffset(self._cropImgOffset || {
|
|
815
|
+
x: rect.x,
|
|
816
|
+
y: rect.y
|
|
817
|
+
}, self._cropImgScale, rect, self._cropNaturalWidth, self._cropNaturalHeight);
|
|
818
|
+
},
|
|
819
|
+
panCropImage: function panCropImage(offset) {
|
|
820
|
+
if (!self._cropRect) return;
|
|
821
|
+
self._cropImgOffset = clampImageOffset(offset, self._cropImgScale, self._cropRect, self._cropNaturalWidth, self._cropNaturalHeight);
|
|
822
|
+
},
|
|
823
|
+
setCropZoom: function setCropZoom(scale) {
|
|
824
|
+
if (!self._cropRect) return;
|
|
825
|
+
var minScale = minScaleForRect(self._cropRect, self._cropNaturalWidth, self._cropNaturalHeight);
|
|
826
|
+
var clampedScale = Math.max(minScale, scale);
|
|
827
|
+
self._cropImgScale = clampedScale;
|
|
828
|
+
self._cropImgOffset = clampImageOffset(self._cropImgOffset || {
|
|
829
|
+
x: self._cropRect.x,
|
|
830
|
+
y: self._cropRect.y
|
|
831
|
+
}, clampedScale, self._cropRect, self._cropNaturalWidth, self._cropNaturalHeight);
|
|
832
|
+
},
|
|
833
|
+
resetCropToDefault: function resetCropToDefault() {
|
|
834
|
+
if (!self._cropRect) return;
|
|
835
|
+
var crop = coverFitCrop(self._cropRect.width, self._cropRect.height, self._cropNaturalWidth, self._cropNaturalHeight);
|
|
836
|
+
var _cropToImageTransform2 = cropToImageTransform(crop, self._cropRect, self._cropNaturalWidth, self._cropNaturalHeight),
|
|
837
|
+
scale = _cropToImageTransform2.scale,
|
|
838
|
+
offset = _cropToImageTransform2.offset;
|
|
839
|
+
self._cropImgScale = scale;
|
|
840
|
+
self._cropImgOffset = offset;
|
|
841
|
+
},
|
|
842
|
+
cancelCropMode: function cancelCropMode() {
|
|
843
|
+
if (self._cropEntrySnapshot) {
|
|
844
|
+
self.set(self._cropEntrySnapshot);
|
|
845
|
+
}
|
|
846
|
+
self._cropEntrySnapshot = null;
|
|
847
|
+
self._cropRect = null;
|
|
848
|
+
self._cropImgOffset = null;
|
|
849
|
+
self._cropImgScale = 1;
|
|
850
|
+
self._cropModeEnabled = false;
|
|
851
|
+
},
|
|
852
|
+
commitCropMode: function commitCropMode() {
|
|
853
|
+
if (self._cropRect && self._cropImgOffset) {
|
|
854
|
+
var crop = rectToCrop(self._cropRect, self._cropImgOffset, self._cropImgScale, self._cropNaturalWidth, self._cropNaturalHeight);
|
|
855
|
+
self.set({
|
|
856
|
+
x: self._cropRect.x,
|
|
857
|
+
y: self._cropRect.y,
|
|
858
|
+
width: self._cropRect.width,
|
|
859
|
+
height: self._cropRect.height,
|
|
860
|
+
cropX: crop.cropX,
|
|
861
|
+
cropY: crop.cropY,
|
|
862
|
+
cropWidth: crop.cropWidth,
|
|
863
|
+
cropHeight: crop.cropHeight
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
self._cropEntrySnapshot = null;
|
|
867
|
+
self._cropRect = null;
|
|
868
|
+
self._cropImgOffset = null;
|
|
869
|
+
self._cropImgScale = 1;
|
|
870
|
+
self._cropModeEnabled = false;
|
|
673
871
|
}
|
|
674
872
|
};
|
|
675
873
|
});
|
|
@@ -1764,10 +1962,22 @@ var Store = types.model('Store', {
|
|
|
1764
1962
|
if (self._toolbarPanel) {
|
|
1765
1963
|
var stillSelected = ids.includes(self._toolbarPanel.elementId);
|
|
1766
1964
|
if (!stillSelected) {
|
|
1965
|
+
self._cancelActiveCrop();
|
|
1767
1966
|
self._toolbarPanel = null;
|
|
1768
1967
|
}
|
|
1769
1968
|
}
|
|
1770
1969
|
},
|
|
1970
|
+
// Single choke-point for "cancel whatever element is mid-crop, if any" — must be
|
|
1971
|
+
// called before _toolbarPanel is overwritten/cleared by any path (panel switch,
|
|
1972
|
+
// panel close, or selection change) so an element can never be left stuck in
|
|
1973
|
+
// crop mode with no matching exit trigger.
|
|
1974
|
+
_cancelActiveCrop: function _cancelActiveCrop() {
|
|
1975
|
+
var _self$_toolbarPanel;
|
|
1976
|
+
if (((_self$_toolbarPanel = self._toolbarPanel) === null || _self$_toolbarPanel === void 0 ? void 0 : _self$_toolbarPanel.type) === 'crop') {
|
|
1977
|
+
var el = self.getElementById(self._toolbarPanel.elementId);
|
|
1978
|
+
if (el && el._cropModeEnabled && el.cancelCropMode) el.cancelCropMode();
|
|
1979
|
+
}
|
|
1980
|
+
},
|
|
1771
1981
|
toggleBleed: function toggleBleed(bleedVisible) {
|
|
1772
1982
|
self.bleedVisible = bleedVisible !== undefined ? bleedVisible : !self.bleedVisible;
|
|
1773
1983
|
},
|
|
@@ -1784,6 +1994,7 @@ var Store = types.model('Store', {
|
|
|
1784
1994
|
openToolbarPanel: function openToolbarPanel(type) {
|
|
1785
1995
|
var el = self.selectedElements.length === 1 ? self.selectedElements[0] : null;
|
|
1786
1996
|
if (el) {
|
|
1997
|
+
self._cancelActiveCrop();
|
|
1787
1998
|
self._toolbarPanel = {
|
|
1788
1999
|
type: type,
|
|
1789
2000
|
elementId: el.id
|
|
@@ -1791,6 +2002,7 @@ var Store = types.model('Store', {
|
|
|
1791
2002
|
}
|
|
1792
2003
|
},
|
|
1793
2004
|
closeToolbarPanel: function closeToolbarPanel() {
|
|
2005
|
+
self._cancelActiveCrop();
|
|
1794
2006
|
self._toolbarPanel = null;
|
|
1795
2007
|
},
|
|
1796
2008
|
setScale: function setScale(scale) {
|
|
@@ -6276,6 +6488,115 @@ var ImageMaskPanel = observer(function (_ref) {
|
|
|
6276
6488
|
});
|
|
6277
6489
|
ImageMaskPanel.displayName = 'ImageMaskPanel';
|
|
6278
6490
|
|
|
6491
|
+
var ImageCropPanel = observer(function (_ref) {
|
|
6492
|
+
var store = _ref.store;
|
|
6493
|
+
var panel = store._toolbarPanel;
|
|
6494
|
+
if (!panel || panel.type !== 'crop') return null;
|
|
6495
|
+
var element = store.getElementById(panel.elementId);
|
|
6496
|
+
if (!element || !element._cropRect) return null;
|
|
6497
|
+
var handleCancel = function handleCancel() {
|
|
6498
|
+
element.cancelCropMode();
|
|
6499
|
+
store.closeToolbarPanel();
|
|
6500
|
+
};
|
|
6501
|
+
var handleDone = function handleDone() {
|
|
6502
|
+
element.commitCropMode();
|
|
6503
|
+
store.closeToolbarPanel();
|
|
6504
|
+
store.history.addUndoState();
|
|
6505
|
+
};
|
|
6506
|
+
var handleReset = function handleReset() {
|
|
6507
|
+
element.resetCropToDefault();
|
|
6508
|
+
};
|
|
6509
|
+
var minScale = minScaleForRect(element._cropRect, element._cropNaturalWidth, element._cropNaturalHeight);
|
|
6510
|
+
var maxScale = minScale * 4;
|
|
6511
|
+
return /*#__PURE__*/jsxs(Box, {
|
|
6512
|
+
sx: {
|
|
6513
|
+
width: 280,
|
|
6514
|
+
height: '100%',
|
|
6515
|
+
overflowY: 'auto',
|
|
6516
|
+
overflowX: 'hidden',
|
|
6517
|
+
backgroundColor: '#fff',
|
|
6518
|
+
borderRight: '1px solid #e0e0e0',
|
|
6519
|
+
flexShrink: 0,
|
|
6520
|
+
p: 2
|
|
6521
|
+
},
|
|
6522
|
+
children: [/*#__PURE__*/jsxs(Box, {
|
|
6523
|
+
sx: {
|
|
6524
|
+
display: 'flex',
|
|
6525
|
+
alignItems: 'center',
|
|
6526
|
+
justifyContent: 'space-between',
|
|
6527
|
+
mb: 2
|
|
6528
|
+
},
|
|
6529
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
6530
|
+
variant: "subtitle1",
|
|
6531
|
+
sx: {
|
|
6532
|
+
fontWeight: 600
|
|
6533
|
+
},
|
|
6534
|
+
children: t('toolbar.crop', 'Crop')
|
|
6535
|
+
}), /*#__PURE__*/jsx(IconButton, {
|
|
6536
|
+
size: "small",
|
|
6537
|
+
onClick: handleCancel,
|
|
6538
|
+
children: /*#__PURE__*/jsx(CloseIcon, {
|
|
6539
|
+
fontSize: "small"
|
|
6540
|
+
})
|
|
6541
|
+
})]
|
|
6542
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
6543
|
+
variant: "body2",
|
|
6544
|
+
sx: {
|
|
6545
|
+
fontWeight: 500,
|
|
6546
|
+
mb: 0.5
|
|
6547
|
+
},
|
|
6548
|
+
children: t('toolbar.cropZoom', 'Zoom')
|
|
6549
|
+
}), /*#__PURE__*/jsx(Slider, {
|
|
6550
|
+
size: "small",
|
|
6551
|
+
value: element._cropImgScale,
|
|
6552
|
+
onChange: function onChange(_, v) {
|
|
6553
|
+
return element.setCropZoom(v);
|
|
6554
|
+
},
|
|
6555
|
+
min: minScale,
|
|
6556
|
+
max: maxScale,
|
|
6557
|
+
step: (maxScale - minScale) / 100 || 0.01,
|
|
6558
|
+
sx: {
|
|
6559
|
+
mb: 3
|
|
6560
|
+
}
|
|
6561
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
6562
|
+
fullWidth: true,
|
|
6563
|
+
variant: "outlined",
|
|
6564
|
+
size: "small",
|
|
6565
|
+
onClick: handleReset,
|
|
6566
|
+
sx: {
|
|
6567
|
+
textTransform: 'none',
|
|
6568
|
+
mb: 3
|
|
6569
|
+
},
|
|
6570
|
+
children: t('toolbar.cropReset', 'Reset')
|
|
6571
|
+
}), /*#__PURE__*/jsxs(Box, {
|
|
6572
|
+
sx: {
|
|
6573
|
+
display: 'flex',
|
|
6574
|
+
gap: 1
|
|
6575
|
+
},
|
|
6576
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
6577
|
+
fullWidth: true,
|
|
6578
|
+
variant: "outlined",
|
|
6579
|
+
size: "small",
|
|
6580
|
+
onClick: handleCancel,
|
|
6581
|
+
sx: {
|
|
6582
|
+
textTransform: 'none'
|
|
6583
|
+
},
|
|
6584
|
+
children: t('toolbar.cropCancel', 'Cancel')
|
|
6585
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
6586
|
+
fullWidth: true,
|
|
6587
|
+
variant: "contained",
|
|
6588
|
+
size: "small",
|
|
6589
|
+
onClick: handleDone,
|
|
6590
|
+
sx: {
|
|
6591
|
+
textTransform: 'none'
|
|
6592
|
+
},
|
|
6593
|
+
children: t('toolbar.cropDone', 'Done')
|
|
6594
|
+
})]
|
|
6595
|
+
})]
|
|
6596
|
+
});
|
|
6597
|
+
});
|
|
6598
|
+
ImageCropPanel.displayName = 'ImageCropPanel';
|
|
6599
|
+
|
|
6279
6600
|
var SliderRow = function SliderRow(_ref) {
|
|
6280
6601
|
var label = _ref.label,
|
|
6281
6602
|
value = _ref.value,
|
|
@@ -6801,6 +7122,8 @@ var SidePanel = observer(function (_ref) {
|
|
|
6801
7122
|
});
|
|
6802
7123
|
}() : store._toolbarPanel.type === 'mask' ? /*#__PURE__*/jsx(ImageMaskPanel, {
|
|
6803
7124
|
store: store
|
|
7125
|
+
}) : store._toolbarPanel.type === 'crop' ? /*#__PURE__*/jsx(ImageCropPanel, {
|
|
7126
|
+
store: store
|
|
6804
7127
|
}) : null : (/* Normal panel content */
|
|
6805
7128
|
activeSectionObj && /*#__PURE__*/jsx(Box, {
|
|
6806
7129
|
sx: {
|
|
@@ -8879,6 +9202,13 @@ var ImageToolbar = observer(function (_ref5) {
|
|
|
8879
9202
|
store.history.addUndoState();
|
|
8880
9203
|
setFlipAnchor(null);
|
|
8881
9204
|
};
|
|
9205
|
+
var handleCrop = function handleCrop() {
|
|
9206
|
+
if (!element._naturalWidth || !element._naturalHeight) return;
|
|
9207
|
+
element.enterCropMode();
|
|
9208
|
+
if (element._cropModeEnabled) {
|
|
9209
|
+
store.openToolbarPanel('crop');
|
|
9210
|
+
}
|
|
9211
|
+
};
|
|
8882
9212
|
var handleFitToPage = function handleFitToPage() {
|
|
8883
9213
|
element.set({
|
|
8884
9214
|
x: 0,
|
|
@@ -9008,6 +9338,16 @@ var ImageToolbar = observer(function (_ref5) {
|
|
|
9008
9338
|
} : {}),
|
|
9009
9339
|
onClick: handleMask,
|
|
9010
9340
|
children: hasMask ? t('toolbar.removeMask', 'Remove mask') : t('toolbar.clip', 'Apply mask')
|
|
9341
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
9342
|
+
size: "small",
|
|
9343
|
+
sx: toolbarBtnSx,
|
|
9344
|
+
startIcon: /*#__PURE__*/jsx(CropIcon, {
|
|
9345
|
+
sx: {
|
|
9346
|
+
fontSize: '16px !important'
|
|
9347
|
+
}
|
|
9348
|
+
}),
|
|
9349
|
+
onClick: handleCrop,
|
|
9350
|
+
children: t('toolbar.crop', 'Crop')
|
|
9011
9351
|
})]
|
|
9012
9352
|
});
|
|
9013
9353
|
});
|
|
@@ -10177,6 +10517,149 @@ var ZoomButtons = observer(function (_ref) {
|
|
|
10177
10517
|
});
|
|
10178
10518
|
ZoomButtons.displayName = 'ZoomButtons';
|
|
10179
10519
|
|
|
10520
|
+
// src/canvas/crop-editor.js
|
|
10521
|
+
var MIN_RECT_SIZE = 20;
|
|
10522
|
+
var VIEWPORT_PAD = 400; // page units of dim area rendered around the crop rect
|
|
10523
|
+
|
|
10524
|
+
var CropEditor = observer(function (_ref) {
|
|
10525
|
+
var element = _ref.element,
|
|
10526
|
+
image = _ref.image;
|
|
10527
|
+
var rectRef = useRef(null);
|
|
10528
|
+
var transformerRef = useRef(null);
|
|
10529
|
+
useEffect(function () {
|
|
10530
|
+
if (transformerRef.current && rectRef.current) {
|
|
10531
|
+
var _transformerRef$curre;
|
|
10532
|
+
transformerRef.current.nodes([rectRef.current]);
|
|
10533
|
+
(_transformerRef$curre = transformerRef.current.getLayer()) === null || _transformerRef$curre === void 0 || _transformerRef$curre.batchDraw();
|
|
10534
|
+
}
|
|
10535
|
+
});
|
|
10536
|
+
if (!image || !element._cropRect || !element._cropImgOffset) return null;
|
|
10537
|
+
var natW = image.naturalWidth || image.width;
|
|
10538
|
+
var natH = image.naturalHeight || image.height;
|
|
10539
|
+
var rect = element._cropRect;
|
|
10540
|
+
var offset = element._cropImgOffset;
|
|
10541
|
+
var scale = element._cropImgScale;
|
|
10542
|
+
var handleImageDragMove = function handleImageDragMove(e) {
|
|
10543
|
+
var node = e.target;
|
|
10544
|
+
var clamped = clampImageOffset({
|
|
10545
|
+
x: node.x(),
|
|
10546
|
+
y: node.y()
|
|
10547
|
+
}, scale, rect, natW, natH);
|
|
10548
|
+
node.x(clamped.x);
|
|
10549
|
+
node.y(clamped.y);
|
|
10550
|
+
};
|
|
10551
|
+
var handleImageDragEnd = function handleImageDragEnd(e) {
|
|
10552
|
+
var node = e.target;
|
|
10553
|
+
element.panCropImage({
|
|
10554
|
+
x: node.x(),
|
|
10555
|
+
y: node.y()
|
|
10556
|
+
});
|
|
10557
|
+
};
|
|
10558
|
+
|
|
10559
|
+
// Shared by both the live (onTransform) and final (onTransformEnd) handlers: reads the
|
|
10560
|
+
// Konva node's current scale, bakes it into width/height, resets the node's scale back to
|
|
10561
|
+
// 1 (required for the Transformer to keep computing subsequent ticks correctly within the
|
|
10562
|
+
// same drag), and pushes the new rect through the model so the image/mask stay in sync.
|
|
10563
|
+
var applyRectTransform = function applyRectTransform() {
|
|
10564
|
+
var node = rectRef.current;
|
|
10565
|
+
var scaleX = node.scaleX();
|
|
10566
|
+
var scaleY = node.scaleY();
|
|
10567
|
+
var newRect = {
|
|
10568
|
+
x: node.x(),
|
|
10569
|
+
y: node.y(),
|
|
10570
|
+
width: Math.max(MIN_RECT_SIZE, rect.width * scaleX),
|
|
10571
|
+
height: Math.max(MIN_RECT_SIZE, rect.height * scaleY)
|
|
10572
|
+
};
|
|
10573
|
+
node.scaleX(1);
|
|
10574
|
+
node.scaleY(1);
|
|
10575
|
+
node.width(newRect.width);
|
|
10576
|
+
node.height(newRect.height);
|
|
10577
|
+
element.setCropRectAndClamp(newRect);
|
|
10578
|
+
};
|
|
10579
|
+
var handleRectTransform = function handleRectTransform() {
|
|
10580
|
+
return applyRectTransform();
|
|
10581
|
+
};
|
|
10582
|
+
var handleRectTransformEnd = function handleRectTransformEnd() {
|
|
10583
|
+
return applyRectTransform();
|
|
10584
|
+
};
|
|
10585
|
+
|
|
10586
|
+
// Dim mask: four rects framing the hole over `rect`.
|
|
10587
|
+
var vx = rect.x - VIEWPORT_PAD;
|
|
10588
|
+
var vy = rect.y - VIEWPORT_PAD;
|
|
10589
|
+
var vw = rect.width + VIEWPORT_PAD * 2;
|
|
10590
|
+
var vh = rect.height + VIEWPORT_PAD * 2;
|
|
10591
|
+
return /*#__PURE__*/jsxs(Group, {
|
|
10592
|
+
children: [/*#__PURE__*/jsx(Image$1, {
|
|
10593
|
+
name: "display-only crop-interactive",
|
|
10594
|
+
image: image,
|
|
10595
|
+
x: offset.x,
|
|
10596
|
+
y: offset.y,
|
|
10597
|
+
width: natW * scale,
|
|
10598
|
+
height: natH * scale,
|
|
10599
|
+
draggable: true,
|
|
10600
|
+
onDragMove: handleImageDragMove,
|
|
10601
|
+
onDragEnd: handleImageDragEnd
|
|
10602
|
+
}), /*#__PURE__*/jsx(Rect, {
|
|
10603
|
+
name: "display-only",
|
|
10604
|
+
x: vx,
|
|
10605
|
+
y: vy,
|
|
10606
|
+
width: vw,
|
|
10607
|
+
height: rect.y - vy,
|
|
10608
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10609
|
+
listening: false
|
|
10610
|
+
}), /*#__PURE__*/jsx(Rect, {
|
|
10611
|
+
name: "display-only",
|
|
10612
|
+
x: vx,
|
|
10613
|
+
y: rect.y + rect.height,
|
|
10614
|
+
width: vw,
|
|
10615
|
+
height: vy + vh - (rect.y + rect.height),
|
|
10616
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10617
|
+
listening: false
|
|
10618
|
+
}), /*#__PURE__*/jsx(Rect, {
|
|
10619
|
+
name: "display-only",
|
|
10620
|
+
x: vx,
|
|
10621
|
+
y: rect.y,
|
|
10622
|
+
width: rect.x - vx,
|
|
10623
|
+
height: rect.height,
|
|
10624
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10625
|
+
listening: false
|
|
10626
|
+
}), /*#__PURE__*/jsx(Rect, {
|
|
10627
|
+
name: "display-only",
|
|
10628
|
+
x: rect.x + rect.width,
|
|
10629
|
+
y: rect.y,
|
|
10630
|
+
width: vx + vw - (rect.x + rect.width),
|
|
10631
|
+
height: rect.height,
|
|
10632
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10633
|
+
listening: false
|
|
10634
|
+
}), /*#__PURE__*/jsx(Rect, {
|
|
10635
|
+
name: "display-only crop-interactive",
|
|
10636
|
+
ref: rectRef,
|
|
10637
|
+
x: rect.x,
|
|
10638
|
+
y: rect.y,
|
|
10639
|
+
width: rect.width,
|
|
10640
|
+
height: rect.height,
|
|
10641
|
+
stroke: "#ffffff",
|
|
10642
|
+
strokeWidth: 1.5,
|
|
10643
|
+
listening: false,
|
|
10644
|
+
onTransform: handleRectTransform,
|
|
10645
|
+
onTransformEnd: handleRectTransformEnd
|
|
10646
|
+
}), /*#__PURE__*/jsx(Transformer, {
|
|
10647
|
+
ref: transformerRef,
|
|
10648
|
+
rotateEnabled: false,
|
|
10649
|
+
anchorSize: 8,
|
|
10650
|
+
anchorCornerRadius: 2,
|
|
10651
|
+
borderStroke: "#0d83cd",
|
|
10652
|
+
anchorStroke: "#0d83cd",
|
|
10653
|
+
anchorFill: "#ffffff",
|
|
10654
|
+
boundBoxFunc: function boundBoxFunc(oldBox, newBox) {
|
|
10655
|
+
if (newBox.width < MIN_RECT_SIZE || newBox.height < MIN_RECT_SIZE) return oldBox;
|
|
10656
|
+
return newBox;
|
|
10657
|
+
}
|
|
10658
|
+
})]
|
|
10659
|
+
});
|
|
10660
|
+
});
|
|
10661
|
+
CropEditor.displayName = 'CropEditor';
|
|
10662
|
+
|
|
10180
10663
|
var SepiaFilter = function SepiaFilter(imageData) {
|
|
10181
10664
|
var data = imageData.data;
|
|
10182
10665
|
for (var i = 0; i < data.length; i += 4) {
|
|
@@ -10214,7 +10697,8 @@ var ImageElementComponent = observer(function (_ref) {
|
|
|
10214
10697
|
var onSelect = _ref.onSelect,
|
|
10215
10698
|
onTransformEnd = _ref.onTransformEnd,
|
|
10216
10699
|
onDragEnd = _ref.onDragEnd,
|
|
10217
|
-
groupChild = _ref.groupChild
|
|
10700
|
+
groupChild = _ref.groupChild,
|
|
10701
|
+
store = _ref.store;
|
|
10218
10702
|
var imageRef = useRef(null);
|
|
10219
10703
|
var groupRef = useRef(null);
|
|
10220
10704
|
var _useState = useState(null),
|
|
@@ -10236,6 +10720,7 @@ var ImageElementComponent = observer(function (_ref) {
|
|
|
10236
10720
|
img.crossOrigin = 'anonymous';
|
|
10237
10721
|
img.onload = function () {
|
|
10238
10722
|
setImage(img);
|
|
10723
|
+
element.setNaturalSize(img.naturalWidth, img.naturalHeight);
|
|
10239
10724
|
};
|
|
10240
10725
|
img.onerror = function () {
|
|
10241
10726
|
console.warn('Failed to load image:', element.src.substring(0, 100));
|
|
@@ -10270,6 +10755,20 @@ var ImageElementComponent = observer(function (_ref) {
|
|
|
10270
10755
|
}
|
|
10271
10756
|
}, [image, needsCache, element.blurEnabled, element.blurRadius, element.brightnessEnabled, element.brightness, element.grayscaleEnabled, element.sepiaEnabled, element.warmEnabled, element.coldEnabled, element.cornerRadius, element.shadowEnabled, element.shadowBlur, element.shadowOffsetX, element.shadowOffsetY, element.shadowColor]);
|
|
10272
10757
|
if (!element.visible) return null;
|
|
10758
|
+
if (element._cropModeEnabled) {
|
|
10759
|
+
return /*#__PURE__*/jsx(CropEditor, {
|
|
10760
|
+
element: element,
|
|
10761
|
+
image: image
|
|
10762
|
+
});
|
|
10763
|
+
}
|
|
10764
|
+
var handleDblClick = function handleDblClick() {
|
|
10765
|
+
if (!store || groupChild) return;
|
|
10766
|
+
element.enterCropMode();
|
|
10767
|
+
if (element._cropModeEnabled) {
|
|
10768
|
+
store.selectElements([element.id]);
|
|
10769
|
+
store.openToolbarPanel('crop');
|
|
10770
|
+
}
|
|
10771
|
+
};
|
|
10273
10772
|
var handleDragEnd = function handleDragEnd(e) {
|
|
10274
10773
|
var target = groupRef.current || e.target;
|
|
10275
10774
|
element.set({
|
|
@@ -10510,6 +11009,8 @@ var ImageElementComponent = observer(function (_ref) {
|
|
|
10510
11009
|
onDragEnd: handleDragEnd,
|
|
10511
11010
|
onTransform: handleTransform,
|
|
10512
11011
|
onTransformEnd: handleTransformEnd,
|
|
11012
|
+
onDblClick: handleDblClick,
|
|
11013
|
+
onDblTap: handleDblClick,
|
|
10513
11014
|
children: [imageNode, hasBorder && /*#__PURE__*/jsx(Rect, {
|
|
10514
11015
|
x: 0,
|
|
10515
11016
|
y: 0,
|
|
@@ -11310,7 +11811,8 @@ var ElementRenderer = observer(function (_ref) {
|
|
|
11310
11811
|
onSelect = _ref.onSelect,
|
|
11311
11812
|
onTransformEnd = _ref.onTransformEnd,
|
|
11312
11813
|
onDragEnd = _ref.onDragEnd,
|
|
11313
|
-
groupChild = _ref.groupChild
|
|
11814
|
+
groupChild = _ref.groupChild,
|
|
11815
|
+
store = _ref.store;
|
|
11314
11816
|
var Renderer = ELEMENT_RENDERERS[element.type];
|
|
11315
11817
|
if (!Renderer) {
|
|
11316
11818
|
console.warn("No renderer for element type: ".concat(element.type));
|
|
@@ -11327,7 +11829,8 @@ var ElementRenderer = observer(function (_ref) {
|
|
|
11327
11829
|
onSelect: onSelect,
|
|
11328
11830
|
onTransformEnd: onTransformEnd,
|
|
11329
11831
|
onDragEnd: onDragEnd,
|
|
11330
|
-
groupChild: groupChild
|
|
11832
|
+
groupChild: groupChild,
|
|
11833
|
+
store: store
|
|
11331
11834
|
}, extra));
|
|
11332
11835
|
});
|
|
11333
11836
|
ElementRenderer.displayName = 'ElementRenderer';
|
|
@@ -12495,10 +12998,11 @@ var SelectionTransformer = observer(function (_ref5) {
|
|
|
12495
12998
|
var transformerRef = useRef(null);
|
|
12496
12999
|
var selectedIds = _toConsumableArray(store.selectedElementsIds);
|
|
12497
13000
|
|
|
12498
|
-
// Filter out line elements
|
|
13001
|
+
// Filter out line elements (custom endpoint handles) and elements mid-crop
|
|
13002
|
+
// (CropEditor renders its own Transformer bound to the crop rect instead).
|
|
12499
13003
|
var nonLineIds = selectedIds.filter(function (id) {
|
|
12500
13004
|
var el = store.getElementById(id);
|
|
12501
|
-
return el && el.type !== 'line';
|
|
13005
|
+
return el && el.type !== 'line' && !el._cropModeEnabled;
|
|
12502
13006
|
});
|
|
12503
13007
|
var allText = nonLineIds.length === 1 && function () {
|
|
12504
13008
|
var el = store.getElementById(nonLineIds[0]);
|
|
@@ -12612,7 +13116,25 @@ var Workspace = observer(function (_ref6) {
|
|
|
12612
13116
|
}
|
|
12613
13117
|
}, [stageRef.current]);
|
|
12614
13118
|
var handleStageMouseDown = useCallback(function (e) {
|
|
12615
|
-
var _target$attrs, _e$evt, _e$evt2;
|
|
13119
|
+
var _store$_toolbarPanel, _target$attrs, _e$evt, _e$evt2;
|
|
13120
|
+
// Clicking anywhere outside the crop rect / pannable image / resize
|
|
13121
|
+
// handles while cropping finishes the crop (like Polotno), then falls
|
|
13122
|
+
// through to the click's normal handling (select whatever was actually
|
|
13123
|
+
// clicked, or deselect).
|
|
13124
|
+
if (((_store$_toolbarPanel = store._toolbarPanel) === null || _store$_toolbarPanel === void 0 ? void 0 : _store$_toolbarPanel.type) === 'crop') {
|
|
13125
|
+
var _e$target$getParent, _e$target;
|
|
13126
|
+
var croppingEl = store.getElementById(store._toolbarPanel.elementId);
|
|
13127
|
+
var isCropInteractive = typeof e.target.hasName === 'function' && e.target.hasName('crop-interactive');
|
|
13128
|
+
// Konva's Transformer adds its resize handles as direct children of
|
|
13129
|
+
// itself, so a handle's parent's className is 'Transformer' — this
|
|
13130
|
+
// catches drags on the crop rect's resize/rotate handles.
|
|
13131
|
+
var isTransformerHandle = ((_e$target$getParent = (_e$target = e.target).getParent) === null || _e$target$getParent === void 0 || (_e$target$getParent = _e$target$getParent.call(_e$target)) === null || _e$target$getParent === void 0 ? void 0 : _e$target$getParent.className) === 'Transformer';
|
|
13132
|
+
if (croppingEl && croppingEl._cropModeEnabled && !isCropInteractive && !isTransformerHandle) {
|
|
13133
|
+
croppingEl.commitCropMode();
|
|
13134
|
+
store.closeToolbarPanel();
|
|
13135
|
+
store.history.addUndoState();
|
|
13136
|
+
}
|
|
13137
|
+
}
|
|
12616
13138
|
var target = e.target;
|
|
12617
13139
|
|
|
12618
13140
|
// Click on empty area or background -> deselect
|
|
@@ -12661,12 +13183,21 @@ var Workspace = observer(function (_ref6) {
|
|
|
12661
13183
|
// Keyboard shortcuts
|
|
12662
13184
|
useEffect(function () {
|
|
12663
13185
|
var handleKeyDown = function handleKeyDown(e) {
|
|
13186
|
+
var _store$_toolbarPanel2;
|
|
12664
13187
|
// Only handle if stage container or body is focused
|
|
12665
13188
|
var target = e.target;
|
|
12666
13189
|
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.tagName === 'SELECT') {
|
|
12667
13190
|
return;
|
|
12668
13191
|
}
|
|
12669
13192
|
|
|
13193
|
+
// Escape -> cancel crop mode if active
|
|
13194
|
+
if (e.key === 'Escape' && ((_store$_toolbarPanel2 = store._toolbarPanel) === null || _store$_toolbarPanel2 === void 0 ? void 0 : _store$_toolbarPanel2.type) === 'crop') {
|
|
13195
|
+
var el = store.getElementById(store._toolbarPanel.elementId);
|
|
13196
|
+
if (el && el.cancelCropMode) el.cancelCropMode();
|
|
13197
|
+
store.closeToolbarPanel();
|
|
13198
|
+
e.preventDefault();
|
|
13199
|
+
}
|
|
13200
|
+
|
|
12670
13201
|
// Delete / Backspace
|
|
12671
13202
|
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
12672
13203
|
var selectedIds = _toConsumableArray(store.selectedElementsIds);
|
|
@@ -12729,9 +13260,9 @@ var Workspace = observer(function (_ref6) {
|
|
|
12729
13260
|
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'G') {
|
|
12730
13261
|
var _selectedIds3 = _toConsumableArray(store.selectedElementsIds);
|
|
12731
13262
|
if (_selectedIds3.length === 1) {
|
|
12732
|
-
var
|
|
12733
|
-
if (
|
|
12734
|
-
store.ungroupElements([
|
|
13263
|
+
var _el = store.getElementById(_selectedIds3[0]);
|
|
13264
|
+
if (_el && _el.type === 'group') {
|
|
13265
|
+
store.ungroupElements([_el.id]);
|
|
12735
13266
|
store.history.addUndoState();
|
|
12736
13267
|
e.preventDefault();
|
|
12737
13268
|
}
|
|
@@ -12827,7 +13358,8 @@ var Workspace = observer(function (_ref6) {
|
|
|
12827
13358
|
element: element,
|
|
12828
13359
|
isSelected: store.selectedElementsIds.includes(element.id),
|
|
12829
13360
|
onTransformEnd: handleTransformEnd,
|
|
12830
|
-
onDragEnd: handleDragEnd
|
|
13361
|
+
onDragEnd: handleDragEnd,
|
|
13362
|
+
store: store
|
|
12831
13363
|
}, element.id);
|
|
12832
13364
|
}), /*#__PURE__*/jsx(PageOverlayFrame, {
|
|
12833
13365
|
store: store
|