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