labellife-design-tool 2.3.7 → 2.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/canvas/workspace.js +229 -10
- package/dist/cjs/canvas/workspace.js.map +1 -1
- package/dist/cjs/index.js +816 -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 +402 -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 +231 -12
- package/dist/esm/canvas/workspace.js.map +1 -1
- package/dist/esm/index.js +817 -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 +402 -1
- 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
|
@@ -33,6 +33,7 @@ var NumbersIcon = require('@mui/icons-material/Numbers');
|
|
|
33
33
|
var RadioButtonCheckedIcon = require('@mui/icons-material/RadioButtonChecked');
|
|
34
34
|
var FormatListBulletedIcon = require('@mui/icons-material/FormatListBulleted');
|
|
35
35
|
var AddIcon = require('@mui/icons-material/Add');
|
|
36
|
+
require('@mui/icons-material/AspectRatio');
|
|
36
37
|
var ArrowDropDownIcon = require('@mui/icons-material/ArrowDropDown');
|
|
37
38
|
var FileUploadIcon = require('@mui/icons-material/FileUpload');
|
|
38
39
|
var UndoIcon = require('@mui/icons-material/Undo');
|
|
@@ -46,7 +47,7 @@ var FormatAlignLeftIcon = require('@mui/icons-material/FormatAlignLeft');
|
|
|
46
47
|
var FormatAlignCenterIcon = require('@mui/icons-material/FormatAlignCenter');
|
|
47
48
|
var FormatAlignRightIcon = require('@mui/icons-material/FormatAlignRight');
|
|
48
49
|
var OpacityIcon = require('@mui/icons-material/Opacity');
|
|
49
|
-
require('@mui/icons-material/Crop');
|
|
50
|
+
var CropIcon = require('@mui/icons-material/Crop');
|
|
50
51
|
var AutoAwesomeIcon = require('@mui/icons-material/AutoAwesome');
|
|
51
52
|
var SwapHorizIcon = require('@mui/icons-material/SwapHoriz');
|
|
52
53
|
var SwapVertIcon = require('@mui/icons-material/SwapVert');
|
|
@@ -632,6 +633,84 @@ var Shape = Node.named('Shape').props({
|
|
|
632
633
|
};
|
|
633
634
|
});
|
|
634
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
|
+
|
|
635
714
|
var ImageElement = Shape.named('ImageElement').props({
|
|
636
715
|
type: mobxStateTree.types.optional(mobxStateTree.types.string, 'image'),
|
|
637
716
|
src: mobxStateTree.types.optional(mobxStateTree.types.string, ''),
|
|
@@ -665,12 +744,132 @@ var ImageElement = Shape.named('ImageElement').props({
|
|
|
665
744
|
return s;
|
|
666
745
|
})["volatile"](function () {
|
|
667
746
|
return {
|
|
668
|
-
|
|
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
|
|
669
758
|
};
|
|
670
759
|
}).actions(function (self) {
|
|
671
760
|
return {
|
|
672
|
-
|
|
673
|
-
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;
|
|
674
873
|
}
|
|
675
874
|
};
|
|
676
875
|
});
|
|
@@ -1765,10 +1964,22 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
1765
1964
|
if (self._toolbarPanel) {
|
|
1766
1965
|
var stillSelected = ids.includes(self._toolbarPanel.elementId);
|
|
1767
1966
|
if (!stillSelected) {
|
|
1967
|
+
self._cancelActiveCrop();
|
|
1768
1968
|
self._toolbarPanel = null;
|
|
1769
1969
|
}
|
|
1770
1970
|
}
|
|
1771
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
|
+
},
|
|
1772
1983
|
toggleBleed: function toggleBleed(bleedVisible) {
|
|
1773
1984
|
self.bleedVisible = bleedVisible !== undefined ? bleedVisible : !self.bleedVisible;
|
|
1774
1985
|
},
|
|
@@ -1785,6 +1996,7 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
1785
1996
|
openToolbarPanel: function openToolbarPanel(type) {
|
|
1786
1997
|
var el = self.selectedElements.length === 1 ? self.selectedElements[0] : null;
|
|
1787
1998
|
if (el) {
|
|
1999
|
+
self._cancelActiveCrop();
|
|
1788
2000
|
self._toolbarPanel = {
|
|
1789
2001
|
type: type,
|
|
1790
2002
|
elementId: el.id
|
|
@@ -1792,6 +2004,7 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
1792
2004
|
}
|
|
1793
2005
|
},
|
|
1794
2006
|
closeToolbarPanel: function closeToolbarPanel() {
|
|
2007
|
+
self._cancelActiveCrop();
|
|
1795
2008
|
self._toolbarPanel = null;
|
|
1796
2009
|
},
|
|
1797
2010
|
setScale: function setScale(scale) {
|
|
@@ -6277,6 +6490,115 @@ var ImageMaskPanel = mobxReactLite.observer(function (_ref) {
|
|
|
6277
6490
|
});
|
|
6278
6491
|
ImageMaskPanel.displayName = 'ImageMaskPanel';
|
|
6279
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
|
+
|
|
6280
6602
|
var SliderRow = function SliderRow(_ref) {
|
|
6281
6603
|
var label = _ref.label,
|
|
6282
6604
|
value = _ref.value,
|
|
@@ -6802,6 +7124,8 @@ var SidePanel = mobxReactLite.observer(function (_ref) {
|
|
|
6802
7124
|
});
|
|
6803
7125
|
}() : store._toolbarPanel.type === 'mask' ? /*#__PURE__*/jsxRuntime.jsx(ImageMaskPanel, {
|
|
6804
7126
|
store: store
|
|
7127
|
+
}) : store._toolbarPanel.type === 'crop' ? /*#__PURE__*/jsxRuntime.jsx(ImageCropPanel, {
|
|
7128
|
+
store: store
|
|
6805
7129
|
}) : null : (/* Normal panel content */
|
|
6806
7130
|
activeSectionObj && /*#__PURE__*/jsxRuntime.jsx(material.Box, {
|
|
6807
7131
|
sx: {
|
|
@@ -8157,6 +8481,265 @@ var InputFieldsSection = {
|
|
|
8157
8481
|
Panel: InputFieldsPanelContent
|
|
8158
8482
|
};
|
|
8159
8483
|
|
|
8484
|
+
function toPx(value, unit) {
|
|
8485
|
+
var dpi = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 96;
|
|
8486
|
+
var v = Number(value);
|
|
8487
|
+
if (!v) return 0;
|
|
8488
|
+
switch ((unit || 'px').toLowerCase()) {
|
|
8489
|
+
case 'mm':
|
|
8490
|
+
return Math.round(v * dpi / 25.4);
|
|
8491
|
+
case 'cm':
|
|
8492
|
+
return Math.round(v * dpi / 2.54);
|
|
8493
|
+
case 'in':
|
|
8494
|
+
return Math.round(v * dpi);
|
|
8495
|
+
default:
|
|
8496
|
+
return Math.round(v);
|
|
8497
|
+
}
|
|
8498
|
+
}
|
|
8499
|
+
function scaleElements(children, ratioX, ratioY) {
|
|
8500
|
+
children.forEach(function (el) {
|
|
8501
|
+
var updates = {
|
|
8502
|
+
x: el.x * ratioX,
|
|
8503
|
+
y: el.y * ratioY,
|
|
8504
|
+
width: el.width * ratioX,
|
|
8505
|
+
height: el.height * ratioY
|
|
8506
|
+
};
|
|
8507
|
+
if (el.type === 'text') {
|
|
8508
|
+
updates.fontSize = el.fontSize * Math.min(ratioX, ratioY);
|
|
8509
|
+
}
|
|
8510
|
+
el.set(updates);
|
|
8511
|
+
if (el.type === 'group' && Array.isArray(el.children)) {
|
|
8512
|
+
scaleElements(el.children, ratioX, ratioY);
|
|
8513
|
+
}
|
|
8514
|
+
});
|
|
8515
|
+
}
|
|
8516
|
+
mobxReactLite.observer(function (_ref2) {
|
|
8517
|
+
var store = _ref2.store,
|
|
8518
|
+
fetchSizes = _ref2.fetchSizes;
|
|
8519
|
+
var _useState = React.useState(String(store.width)),
|
|
8520
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
8521
|
+
width = _useState2[0],
|
|
8522
|
+
setWidth = _useState2[1];
|
|
8523
|
+
var _useState3 = React.useState(String(store.height)),
|
|
8524
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
8525
|
+
height = _useState4[0],
|
|
8526
|
+
setHeight = _useState4[1];
|
|
8527
|
+
var _useState5 = React.useState(false),
|
|
8528
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
8529
|
+
scaleContent = _useState6[0],
|
|
8530
|
+
setScaleContent = _useState6[1];
|
|
8531
|
+
var _useState7 = React.useState([]),
|
|
8532
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
8533
|
+
sizes = _useState8[0],
|
|
8534
|
+
setSizes = _useState8[1];
|
|
8535
|
+
var _useState9 = React.useState(false),
|
|
8536
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
8537
|
+
loadingSizes = _useState0[0],
|
|
8538
|
+
setLoadingSizes = _useState0[1];
|
|
8539
|
+
var _useState1 = React.useState(false),
|
|
8540
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
8541
|
+
sizesError = _useState10[0],
|
|
8542
|
+
setSizesError = _useState10[1];
|
|
8543
|
+
|
|
8544
|
+
// Keep inputs in sync when store dimensions change externally
|
|
8545
|
+
React.useEffect(function () {
|
|
8546
|
+
setWidth(String(store.width));
|
|
8547
|
+
setHeight(String(store.height));
|
|
8548
|
+
}, [store.width, store.height]);
|
|
8549
|
+
React.useEffect(function () {
|
|
8550
|
+
if (!fetchSizes) return;
|
|
8551
|
+
setLoadingSizes(true);
|
|
8552
|
+
setSizesError(false);
|
|
8553
|
+
fetchSizes().then(function (res) {
|
|
8554
|
+
var _res$data;
|
|
8555
|
+
return setSizes(((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.sizes) || []);
|
|
8556
|
+
})["catch"](function () {
|
|
8557
|
+
return setSizesError(true);
|
|
8558
|
+
})["finally"](function () {
|
|
8559
|
+
return setLoadingSizes(false);
|
|
8560
|
+
});
|
|
8561
|
+
}, []);
|
|
8562
|
+
var wNum = parseInt(width, 10);
|
|
8563
|
+
var hNum = parseInt(height, 10);
|
|
8564
|
+
var isValid = wNum > 0 && hNum > 0 && Number.isFinite(wNum) && Number.isFinite(hNum);
|
|
8565
|
+
var handleResize = function handleResize() {
|
|
8566
|
+
if (!isValid || !store.activePage) return;
|
|
8567
|
+
if (scaleContent) {
|
|
8568
|
+
var ratioX = wNum / store.width;
|
|
8569
|
+
var ratioY = hNum / store.height;
|
|
8570
|
+
scaleElements(store.activePage.children, ratioX, ratioY);
|
|
8571
|
+
}
|
|
8572
|
+
store.setSize(wNum, hNum);
|
|
8573
|
+
};
|
|
8574
|
+
var handlePresetClick = function handlePresetClick(size) {
|
|
8575
|
+
var dpi = size.dpi || 96;
|
|
8576
|
+
var w = toPx(size.width, size.unit, dpi);
|
|
8577
|
+
var h = toPx(size.height, size.unit, dpi);
|
|
8578
|
+
if (w > 0) setWidth(String(w));
|
|
8579
|
+
if (h > 0) setHeight(String(h));
|
|
8580
|
+
};
|
|
8581
|
+
return /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
|
|
8582
|
+
sx: {
|
|
8583
|
+
p: 2,
|
|
8584
|
+
display: 'flex',
|
|
8585
|
+
flexDirection: 'column',
|
|
8586
|
+
gap: 2
|
|
8587
|
+
},
|
|
8588
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs(material.Box, {
|
|
8589
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(material.Typography, {
|
|
8590
|
+
sx: {
|
|
8591
|
+
fontWeight: 600,
|
|
8592
|
+
fontSize: 14,
|
|
8593
|
+
mb: 0.5
|
|
8594
|
+
},
|
|
8595
|
+
children: "Resize Canvas"
|
|
8596
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(material.Typography, {
|
|
8597
|
+
sx: {
|
|
8598
|
+
fontSize: 12,
|
|
8599
|
+
color: '#888'
|
|
8600
|
+
},
|
|
8601
|
+
children: ["Current: ", store.width, " \xD7 ", store.height, " px"]
|
|
8602
|
+
})]
|
|
8603
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
|
|
8604
|
+
sx: {
|
|
8605
|
+
display: 'flex',
|
|
8606
|
+
gap: 1.5
|
|
8607
|
+
},
|
|
8608
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(material.TextField, {
|
|
8609
|
+
label: "Width (px)",
|
|
8610
|
+
type: "number",
|
|
8611
|
+
size: "small",
|
|
8612
|
+
value: width,
|
|
8613
|
+
onChange: function onChange(e) {
|
|
8614
|
+
return setWidth(e.target.value);
|
|
8615
|
+
},
|
|
8616
|
+
inputProps: {
|
|
8617
|
+
min: 1,
|
|
8618
|
+
step: 1
|
|
8619
|
+
},
|
|
8620
|
+
error: !!width && (isNaN(wNum) || wNum <= 0),
|
|
8621
|
+
sx: {
|
|
8622
|
+
flex: 1
|
|
8623
|
+
}
|
|
8624
|
+
}), /*#__PURE__*/jsxRuntime.jsx(material.TextField, {
|
|
8625
|
+
label: "Height (px)",
|
|
8626
|
+
type: "number",
|
|
8627
|
+
size: "small",
|
|
8628
|
+
value: height,
|
|
8629
|
+
onChange: function onChange(e) {
|
|
8630
|
+
return setHeight(e.target.value);
|
|
8631
|
+
},
|
|
8632
|
+
inputProps: {
|
|
8633
|
+
min: 1,
|
|
8634
|
+
step: 1
|
|
8635
|
+
},
|
|
8636
|
+
error: !!height && (isNaN(hNum) || hNum <= 0),
|
|
8637
|
+
sx: {
|
|
8638
|
+
flex: 1
|
|
8639
|
+
}
|
|
8640
|
+
})]
|
|
8641
|
+
}), /*#__PURE__*/jsxRuntime.jsx(material.FormControlLabel, {
|
|
8642
|
+
control: /*#__PURE__*/jsxRuntime.jsx(material.Switch, {
|
|
8643
|
+
checked: scaleContent,
|
|
8644
|
+
onChange: function onChange(e) {
|
|
8645
|
+
return setScaleContent(e.target.checked);
|
|
8646
|
+
},
|
|
8647
|
+
size: "small"
|
|
8648
|
+
}),
|
|
8649
|
+
label: /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
|
|
8650
|
+
sx: {
|
|
8651
|
+
fontSize: 13
|
|
8652
|
+
},
|
|
8653
|
+
children: "Scale content"
|
|
8654
|
+
})
|
|
8655
|
+
}), /*#__PURE__*/jsxRuntime.jsx(material.Button, {
|
|
8656
|
+
variant: "contained",
|
|
8657
|
+
disabled: !isValid || !store.activePage,
|
|
8658
|
+
onClick: handleResize,
|
|
8659
|
+
sx: {
|
|
8660
|
+
textTransform: 'uppercase',
|
|
8661
|
+
fontWeight: 700,
|
|
8662
|
+
letterSpacing: 1,
|
|
8663
|
+
backgroundColor: '#0d83cd',
|
|
8664
|
+
'&:hover': {
|
|
8665
|
+
backgroundColor: '#0a6fad'
|
|
8666
|
+
},
|
|
8667
|
+
'&.Mui-disabled': {
|
|
8668
|
+
opacity: 0.5
|
|
8669
|
+
}
|
|
8670
|
+
},
|
|
8671
|
+
children: "Resize"
|
|
8672
|
+
}), /*#__PURE__*/jsxRuntime.jsx(material.Divider, {}), /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
|
|
8673
|
+
sx: {
|
|
8674
|
+
fontWeight: 600,
|
|
8675
|
+
fontSize: 13,
|
|
8676
|
+
color: '#555'
|
|
8677
|
+
},
|
|
8678
|
+
children: "Preset sizes"
|
|
8679
|
+
}), loadingSizes && /*#__PURE__*/jsxRuntime.jsx(material.Box, {
|
|
8680
|
+
sx: {
|
|
8681
|
+
display: 'flex',
|
|
8682
|
+
justifyContent: 'center',
|
|
8683
|
+
py: 2
|
|
8684
|
+
},
|
|
8685
|
+
children: /*#__PURE__*/jsxRuntime.jsx(material.CircularProgress, {
|
|
8686
|
+
size: 22
|
|
8687
|
+
})
|
|
8688
|
+
}), sizesError && /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
|
|
8689
|
+
sx: {
|
|
8690
|
+
fontSize: 12,
|
|
8691
|
+
color: '#c44'
|
|
8692
|
+
},
|
|
8693
|
+
children: "Could not load sizes."
|
|
8694
|
+
}), !loadingSizes && !sizesError && sizes.length === 0 && /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
|
|
8695
|
+
sx: {
|
|
8696
|
+
fontSize: 12,
|
|
8697
|
+
color: '#aaa'
|
|
8698
|
+
},
|
|
8699
|
+
children: "No sizes available."
|
|
8700
|
+
}), !loadingSizes && !sizesError && sizes.map(function (size) {
|
|
8701
|
+
var dpi = size.dpi || 96;
|
|
8702
|
+
toPx(size.width, size.unit, dpi);
|
|
8703
|
+
toPx(size.height, size.unit, dpi);
|
|
8704
|
+
var dimLabel = size.width && size.height ? "".concat(size.width, " \xD7 ").concat(size.height, " ").concat((size.unit || 'px').toUpperCase()) : null;
|
|
8705
|
+
return /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
|
|
8706
|
+
onClick: function onClick() {
|
|
8707
|
+
return handlePresetClick(size);
|
|
8708
|
+
},
|
|
8709
|
+
sx: {
|
|
8710
|
+
display: 'flex',
|
|
8711
|
+
alignItems: 'center',
|
|
8712
|
+
justifyContent: 'space-between',
|
|
8713
|
+
px: 1.5,
|
|
8714
|
+
py: 0.75,
|
|
8715
|
+
borderRadius: '6px',
|
|
8716
|
+
cursor: 'pointer',
|
|
8717
|
+
border: '1px solid #e8e8e8',
|
|
8718
|
+
'&:hover': {
|
|
8719
|
+
backgroundColor: '#f0f7fd',
|
|
8720
|
+
borderColor: '#0d83cd'
|
|
8721
|
+
},
|
|
8722
|
+
transition: 'all 0.12s ease'
|
|
8723
|
+
},
|
|
8724
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(material.Typography, {
|
|
8725
|
+
sx: {
|
|
8726
|
+
fontSize: 13,
|
|
8727
|
+
fontWeight: 500
|
|
8728
|
+
},
|
|
8729
|
+
children: size.name
|
|
8730
|
+
}), dimLabel && /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
|
|
8731
|
+
sx: {
|
|
8732
|
+
fontSize: 11,
|
|
8733
|
+
color: '#888',
|
|
8734
|
+
fontFamily: 'monospace'
|
|
8735
|
+
},
|
|
8736
|
+
children: dimLabel
|
|
8737
|
+
})]
|
|
8738
|
+
}, size.id);
|
|
8739
|
+
})]
|
|
8740
|
+
});
|
|
8741
|
+
});
|
|
8742
|
+
|
|
8160
8743
|
var GOOGLE_FONTS_API = 'https://www.googleapis.com/webfonts/v1/webfonts';
|
|
8161
8744
|
var cachedFonts = null;
|
|
8162
8745
|
function fetchGoogleFonts(_x) {
|
|
@@ -8621,6 +9204,13 @@ var ImageToolbar = mobxReactLite.observer(function (_ref5) {
|
|
|
8621
9204
|
store.history.addUndoState();
|
|
8622
9205
|
setFlipAnchor(null);
|
|
8623
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
|
+
};
|
|
8624
9214
|
var handleFitToPage = function handleFitToPage() {
|
|
8625
9215
|
element.set({
|
|
8626
9216
|
x: 0,
|
|
@@ -8750,6 +9340,16 @@ var ImageToolbar = mobxReactLite.observer(function (_ref5) {
|
|
|
8750
9340
|
} : {}),
|
|
8751
9341
|
onClick: handleMask,
|
|
8752
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')
|
|
8753
9353
|
})]
|
|
8754
9354
|
});
|
|
8755
9355
|
});
|
|
@@ -9919,6 +10519,159 @@ var ZoomButtons = mobxReactLite.observer(function (_ref) {
|
|
|
9919
10519
|
});
|
|
9920
10520
|
ZoomButtons.displayName = 'ZoomButtons';
|
|
9921
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
|
+
var handleRectDragEnd = function handleRectDragEnd(e) {
|
|
10561
|
+
var node = e.target;
|
|
10562
|
+
element.setCropRectAndClamp({
|
|
10563
|
+
x: node.x(),
|
|
10564
|
+
y: node.y(),
|
|
10565
|
+
width: rect.width,
|
|
10566
|
+
height: rect.height
|
|
10567
|
+
});
|
|
10568
|
+
};
|
|
10569
|
+
|
|
10570
|
+
// Shared by both the live (onTransform) and final (onTransformEnd) handlers: reads the
|
|
10571
|
+
// Konva node's current scale, bakes it into width/height, resets the node's scale back to
|
|
10572
|
+
// 1 (required for the Transformer to keep computing subsequent ticks correctly within the
|
|
10573
|
+
// same drag), and pushes the new rect through the model so the image/mask stay in sync.
|
|
10574
|
+
var applyRectTransform = function applyRectTransform() {
|
|
10575
|
+
var node = rectRef.current;
|
|
10576
|
+
var scaleX = node.scaleX();
|
|
10577
|
+
var scaleY = node.scaleY();
|
|
10578
|
+
var newRect = {
|
|
10579
|
+
x: node.x(),
|
|
10580
|
+
y: node.y(),
|
|
10581
|
+
width: Math.max(MIN_RECT_SIZE, rect.width * scaleX),
|
|
10582
|
+
height: Math.max(MIN_RECT_SIZE, rect.height * scaleY)
|
|
10583
|
+
};
|
|
10584
|
+
node.scaleX(1);
|
|
10585
|
+
node.scaleY(1);
|
|
10586
|
+
node.width(newRect.width);
|
|
10587
|
+
node.height(newRect.height);
|
|
10588
|
+
element.setCropRectAndClamp(newRect);
|
|
10589
|
+
};
|
|
10590
|
+
var handleRectTransform = function handleRectTransform() {
|
|
10591
|
+
return applyRectTransform();
|
|
10592
|
+
};
|
|
10593
|
+
var handleRectTransformEnd = function handleRectTransformEnd() {
|
|
10594
|
+
return applyRectTransform();
|
|
10595
|
+
};
|
|
10596
|
+
|
|
10597
|
+
// Dim mask: four rects framing the hole over `rect`.
|
|
10598
|
+
var vx = rect.x - VIEWPORT_PAD;
|
|
10599
|
+
var vy = rect.y - VIEWPORT_PAD;
|
|
10600
|
+
var vw = rect.width + VIEWPORT_PAD * 2;
|
|
10601
|
+
var vh = rect.height + VIEWPORT_PAD * 2;
|
|
10602
|
+
return /*#__PURE__*/jsxRuntime.jsxs(reactKonva.Group, {
|
|
10603
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(reactKonva.Image, {
|
|
10604
|
+
name: "display-only crop-interactive",
|
|
10605
|
+
image: image,
|
|
10606
|
+
x: offset.x,
|
|
10607
|
+
y: offset.y,
|
|
10608
|
+
width: natW * scale,
|
|
10609
|
+
height: natH * scale,
|
|
10610
|
+
draggable: true,
|
|
10611
|
+
onDragMove: handleImageDragMove,
|
|
10612
|
+
onDragEnd: handleImageDragEnd
|
|
10613
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
|
|
10614
|
+
name: "display-only",
|
|
10615
|
+
x: vx,
|
|
10616
|
+
y: vy,
|
|
10617
|
+
width: vw,
|
|
10618
|
+
height: rect.y - vy,
|
|
10619
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10620
|
+
listening: false
|
|
10621
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
|
|
10622
|
+
name: "display-only",
|
|
10623
|
+
x: vx,
|
|
10624
|
+
y: rect.y + rect.height,
|
|
10625
|
+
width: vw,
|
|
10626
|
+
height: vy + vh - (rect.y + rect.height),
|
|
10627
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10628
|
+
listening: false
|
|
10629
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
|
|
10630
|
+
name: "display-only",
|
|
10631
|
+
x: vx,
|
|
10632
|
+
y: rect.y,
|
|
10633
|
+
width: rect.x - vx,
|
|
10634
|
+
height: rect.height,
|
|
10635
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10636
|
+
listening: false
|
|
10637
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
|
|
10638
|
+
name: "display-only",
|
|
10639
|
+
x: rect.x + rect.width,
|
|
10640
|
+
y: rect.y,
|
|
10641
|
+
width: vx + vw - (rect.x + rect.width),
|
|
10642
|
+
height: rect.height,
|
|
10643
|
+
fill: "rgba(0,0,0,0.55)",
|
|
10644
|
+
listening: false
|
|
10645
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
|
|
10646
|
+
name: "display-only crop-interactive",
|
|
10647
|
+
ref: rectRef,
|
|
10648
|
+
x: rect.x,
|
|
10649
|
+
y: rect.y,
|
|
10650
|
+
width: rect.width,
|
|
10651
|
+
height: rect.height,
|
|
10652
|
+
stroke: "#ffffff",
|
|
10653
|
+
strokeWidth: 1.5,
|
|
10654
|
+
draggable: true,
|
|
10655
|
+
onDragEnd: handleRectDragEnd,
|
|
10656
|
+
onTransform: handleRectTransform,
|
|
10657
|
+
onTransformEnd: handleRectTransformEnd
|
|
10658
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactKonva.Transformer, {
|
|
10659
|
+
ref: transformerRef,
|
|
10660
|
+
rotateEnabled: false,
|
|
10661
|
+
anchorSize: 8,
|
|
10662
|
+
anchorCornerRadius: 2,
|
|
10663
|
+
borderStroke: "#0d83cd",
|
|
10664
|
+
anchorStroke: "#0d83cd",
|
|
10665
|
+
anchorFill: "#ffffff",
|
|
10666
|
+
boundBoxFunc: function boundBoxFunc(oldBox, newBox) {
|
|
10667
|
+
if (newBox.width < MIN_RECT_SIZE || newBox.height < MIN_RECT_SIZE) return oldBox;
|
|
10668
|
+
return newBox;
|
|
10669
|
+
}
|
|
10670
|
+
})]
|
|
10671
|
+
});
|
|
10672
|
+
});
|
|
10673
|
+
CropEditor.displayName = 'CropEditor';
|
|
10674
|
+
|
|
9922
10675
|
var SepiaFilter = function SepiaFilter(imageData) {
|
|
9923
10676
|
var data = imageData.data;
|
|
9924
10677
|
for (var i = 0; i < data.length; i += 4) {
|
|
@@ -9956,7 +10709,8 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
9956
10709
|
var onSelect = _ref.onSelect,
|
|
9957
10710
|
onTransformEnd = _ref.onTransformEnd,
|
|
9958
10711
|
onDragEnd = _ref.onDragEnd,
|
|
9959
|
-
groupChild = _ref.groupChild
|
|
10712
|
+
groupChild = _ref.groupChild,
|
|
10713
|
+
store = _ref.store;
|
|
9960
10714
|
var imageRef = React.useRef(null);
|
|
9961
10715
|
var groupRef = React.useRef(null);
|
|
9962
10716
|
var _useState = React.useState(null),
|
|
@@ -9978,6 +10732,7 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
9978
10732
|
img.crossOrigin = 'anonymous';
|
|
9979
10733
|
img.onload = function () {
|
|
9980
10734
|
setImage(img);
|
|
10735
|
+
element.setNaturalSize(img.naturalWidth, img.naturalHeight);
|
|
9981
10736
|
};
|
|
9982
10737
|
img.onerror = function () {
|
|
9983
10738
|
console.warn('Failed to load image:', element.src.substring(0, 100));
|
|
@@ -10012,6 +10767,20 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
10012
10767
|
}
|
|
10013
10768
|
}, [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]);
|
|
10014
10769
|
if (!element.visible) return null;
|
|
10770
|
+
if (element._cropModeEnabled) {
|
|
10771
|
+
return /*#__PURE__*/jsxRuntime.jsx(CropEditor, {
|
|
10772
|
+
element: element,
|
|
10773
|
+
image: image
|
|
10774
|
+
});
|
|
10775
|
+
}
|
|
10776
|
+
var handleDblClick = function handleDblClick() {
|
|
10777
|
+
if (!store || groupChild) return;
|
|
10778
|
+
element.enterCropMode();
|
|
10779
|
+
if (element._cropModeEnabled) {
|
|
10780
|
+
store.selectElements([element.id]);
|
|
10781
|
+
store.openToolbarPanel('crop');
|
|
10782
|
+
}
|
|
10783
|
+
};
|
|
10015
10784
|
var handleDragEnd = function handleDragEnd(e) {
|
|
10016
10785
|
var target = groupRef.current || e.target;
|
|
10017
10786
|
element.set({
|
|
@@ -10252,6 +11021,8 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
10252
11021
|
onDragEnd: handleDragEnd,
|
|
10253
11022
|
onTransform: handleTransform,
|
|
10254
11023
|
onTransformEnd: handleTransformEnd,
|
|
11024
|
+
onDblClick: handleDblClick,
|
|
11025
|
+
onDblTap: handleDblClick,
|
|
10255
11026
|
children: [imageNode, hasBorder && /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
|
|
10256
11027
|
x: 0,
|
|
10257
11028
|
y: 0,
|
|
@@ -11052,7 +11823,8 @@ var ElementRenderer = mobxReactLite.observer(function (_ref) {
|
|
|
11052
11823
|
onSelect = _ref.onSelect,
|
|
11053
11824
|
onTransformEnd = _ref.onTransformEnd,
|
|
11054
11825
|
onDragEnd = _ref.onDragEnd,
|
|
11055
|
-
groupChild = _ref.groupChild
|
|
11826
|
+
groupChild = _ref.groupChild,
|
|
11827
|
+
store = _ref.store;
|
|
11056
11828
|
var Renderer = ELEMENT_RENDERERS[element.type];
|
|
11057
11829
|
if (!Renderer) {
|
|
11058
11830
|
console.warn("No renderer for element type: ".concat(element.type));
|
|
@@ -11069,7 +11841,8 @@ var ElementRenderer = mobxReactLite.observer(function (_ref) {
|
|
|
11069
11841
|
onSelect: onSelect,
|
|
11070
11842
|
onTransformEnd: onTransformEnd,
|
|
11071
11843
|
onDragEnd: onDragEnd,
|
|
11072
|
-
groupChild: groupChild
|
|
11844
|
+
groupChild: groupChild,
|
|
11845
|
+
store: store
|
|
11073
11846
|
}, extra));
|
|
11074
11847
|
});
|
|
11075
11848
|
ElementRenderer.displayName = 'ElementRenderer';
|
|
@@ -12237,10 +13010,11 @@ var SelectionTransformer = mobxReactLite.observer(function (_ref5) {
|
|
|
12237
13010
|
var transformerRef = React.useRef(null);
|
|
12238
13011
|
var selectedIds = _toConsumableArray(store.selectedElementsIds);
|
|
12239
13012
|
|
|
12240
|
-
// Filter out line elements
|
|
13013
|
+
// Filter out line elements (custom endpoint handles) and elements mid-crop
|
|
13014
|
+
// (CropEditor renders its own Transformer bound to the crop rect instead).
|
|
12241
13015
|
var nonLineIds = selectedIds.filter(function (id) {
|
|
12242
13016
|
var el = store.getElementById(id);
|
|
12243
|
-
return el && el.type !== 'line';
|
|
13017
|
+
return el && el.type !== 'line' && !el._cropModeEnabled;
|
|
12244
13018
|
});
|
|
12245
13019
|
var allText = nonLineIds.length === 1 && function () {
|
|
12246
13020
|
var el = store.getElementById(nonLineIds[0]);
|
|
@@ -12354,7 +13128,25 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
|
|
|
12354
13128
|
}
|
|
12355
13129
|
}, [stageRef.current]);
|
|
12356
13130
|
var handleStageMouseDown = React.useCallback(function (e) {
|
|
12357
|
-
var _target$attrs, _e$evt, _e$evt2;
|
|
13131
|
+
var _store$_toolbarPanel, _target$attrs, _e$evt, _e$evt2;
|
|
13132
|
+
// Clicking anywhere outside the crop rect / pannable image / resize
|
|
13133
|
+
// handles while cropping finishes the crop (like Polotno), then falls
|
|
13134
|
+
// through to the click's normal handling (select whatever was actually
|
|
13135
|
+
// clicked, or deselect).
|
|
13136
|
+
if (((_store$_toolbarPanel = store._toolbarPanel) === null || _store$_toolbarPanel === void 0 ? void 0 : _store$_toolbarPanel.type) === 'crop') {
|
|
13137
|
+
var _e$target$getParent, _e$target;
|
|
13138
|
+
var croppingEl = store.getElementById(store._toolbarPanel.elementId);
|
|
13139
|
+
var isCropInteractive = typeof e.target.hasName === 'function' && e.target.hasName('crop-interactive');
|
|
13140
|
+
// Konva's Transformer adds its resize handles as direct children of
|
|
13141
|
+
// itself, so a handle's parent's className is 'Transformer' — this
|
|
13142
|
+
// catches drags on the crop rect's resize/rotate handles.
|
|
13143
|
+
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';
|
|
13144
|
+
if (croppingEl && croppingEl._cropModeEnabled && !isCropInteractive && !isTransformerHandle) {
|
|
13145
|
+
croppingEl.commitCropMode();
|
|
13146
|
+
store.closeToolbarPanel();
|
|
13147
|
+
store.history.addUndoState();
|
|
13148
|
+
}
|
|
13149
|
+
}
|
|
12358
13150
|
var target = e.target;
|
|
12359
13151
|
|
|
12360
13152
|
// Click on empty area or background -> deselect
|
|
@@ -12403,12 +13195,21 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
|
|
|
12403
13195
|
// Keyboard shortcuts
|
|
12404
13196
|
React.useEffect(function () {
|
|
12405
13197
|
var handleKeyDown = function handleKeyDown(e) {
|
|
13198
|
+
var _store$_toolbarPanel2;
|
|
12406
13199
|
// Only handle if stage container or body is focused
|
|
12407
13200
|
var target = e.target;
|
|
12408
13201
|
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.tagName === 'SELECT') {
|
|
12409
13202
|
return;
|
|
12410
13203
|
}
|
|
12411
13204
|
|
|
13205
|
+
// Escape -> cancel crop mode if active
|
|
13206
|
+
if (e.key === 'Escape' && ((_store$_toolbarPanel2 = store._toolbarPanel) === null || _store$_toolbarPanel2 === void 0 ? void 0 : _store$_toolbarPanel2.type) === 'crop') {
|
|
13207
|
+
var el = store.getElementById(store._toolbarPanel.elementId);
|
|
13208
|
+
if (el && el.cancelCropMode) el.cancelCropMode();
|
|
13209
|
+
store.closeToolbarPanel();
|
|
13210
|
+
e.preventDefault();
|
|
13211
|
+
}
|
|
13212
|
+
|
|
12412
13213
|
// Delete / Backspace
|
|
12413
13214
|
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
12414
13215
|
var selectedIds = _toConsumableArray(store.selectedElementsIds);
|
|
@@ -12471,9 +13272,9 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
|
|
|
12471
13272
|
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'G') {
|
|
12472
13273
|
var _selectedIds3 = _toConsumableArray(store.selectedElementsIds);
|
|
12473
13274
|
if (_selectedIds3.length === 1) {
|
|
12474
|
-
var
|
|
12475
|
-
if (
|
|
12476
|
-
store.ungroupElements([
|
|
13275
|
+
var _el = store.getElementById(_selectedIds3[0]);
|
|
13276
|
+
if (_el && _el.type === 'group') {
|
|
13277
|
+
store.ungroupElements([_el.id]);
|
|
12477
13278
|
store.history.addUndoState();
|
|
12478
13279
|
e.preventDefault();
|
|
12479
13280
|
}
|
|
@@ -12569,7 +13370,8 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
|
|
|
12569
13370
|
element: element,
|
|
12570
13371
|
isSelected: store.selectedElementsIds.includes(element.id),
|
|
12571
13372
|
onTransformEnd: handleTransformEnd,
|
|
12572
|
-
onDragEnd: handleDragEnd
|
|
13373
|
+
onDragEnd: handleDragEnd,
|
|
13374
|
+
store: store
|
|
12573
13375
|
}, element.id);
|
|
12574
13376
|
}), /*#__PURE__*/jsxRuntime.jsx(PageOverlayFrame, {
|
|
12575
13377
|
store: store
|