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.
@@ -28,6 +28,7 @@ import NumbersIcon from '@mui/icons-material/Numbers';
28
28
  import RadioButtonCheckedIcon from '@mui/icons-material/RadioButtonChecked';
29
29
  import FormatListBulletedIcon from '@mui/icons-material/FormatListBulleted';
30
30
  import AddIcon from '@mui/icons-material/Add';
31
+ import AspectRatioIcon from '@mui/icons-material/AspectRatio';
31
32
 
32
33
  function _arrayLikeToArray(r, a) {
33
34
  (null == a || a > r.length) && (a = r.length);
@@ -3975,6 +3976,124 @@ var ImageMaskPanel = observer(function (_ref) {
3975
3976
  });
3976
3977
  ImageMaskPanel.displayName = 'ImageMaskPanel';
3977
3978
 
3979
+ // Cover-fit crop fractions (centered) for a box of given size over an image of natural size.
3980
+ // Mirrors the existing auto-crop calculation in canvas/image-element.js.
3981
+
3982
+ // Minimum scale at which the image (rendered at naturalWidth*scale x naturalHeight*scale)
3983
+ // still fully covers rect.
3984
+ function minScaleForRect(rect, naturalWidth, naturalHeight) {
3985
+ return Math.max(rect.width / naturalWidth, rect.height / naturalHeight);
3986
+ }
3987
+
3988
+ var ImageCropPanel = observer(function (_ref) {
3989
+ var store = _ref.store;
3990
+ var panel = store._toolbarPanel;
3991
+ if (!panel || panel.type !== 'crop') return null;
3992
+ var element = store.getElementById(panel.elementId);
3993
+ if (!element || !element._cropRect) return null;
3994
+ var handleCancel = function handleCancel() {
3995
+ element.cancelCropMode();
3996
+ store.closeToolbarPanel();
3997
+ };
3998
+ var handleDone = function handleDone() {
3999
+ element.commitCropMode();
4000
+ store.closeToolbarPanel();
4001
+ store.history.addUndoState();
4002
+ };
4003
+ var handleReset = function handleReset() {
4004
+ element.resetCropToDefault();
4005
+ };
4006
+ var minScale = minScaleForRect(element._cropRect, element._cropNaturalWidth, element._cropNaturalHeight);
4007
+ var maxScale = minScale * 4;
4008
+ return /*#__PURE__*/jsxs(Box, {
4009
+ sx: {
4010
+ width: 280,
4011
+ height: '100%',
4012
+ overflowY: 'auto',
4013
+ overflowX: 'hidden',
4014
+ backgroundColor: '#fff',
4015
+ borderRight: '1px solid #e0e0e0',
4016
+ flexShrink: 0,
4017
+ p: 2
4018
+ },
4019
+ children: [/*#__PURE__*/jsxs(Box, {
4020
+ sx: {
4021
+ display: 'flex',
4022
+ alignItems: 'center',
4023
+ justifyContent: 'space-between',
4024
+ mb: 2
4025
+ },
4026
+ children: [/*#__PURE__*/jsx(Typography, {
4027
+ variant: "subtitle1",
4028
+ sx: {
4029
+ fontWeight: 600
4030
+ },
4031
+ children: t('toolbar.crop', 'Crop')
4032
+ }), /*#__PURE__*/jsx(IconButton, {
4033
+ size: "small",
4034
+ onClick: handleCancel,
4035
+ children: /*#__PURE__*/jsx(CloseIcon, {
4036
+ fontSize: "small"
4037
+ })
4038
+ })]
4039
+ }), /*#__PURE__*/jsx(Typography, {
4040
+ variant: "body2",
4041
+ sx: {
4042
+ fontWeight: 500,
4043
+ mb: 0.5
4044
+ },
4045
+ children: t('toolbar.cropZoom', 'Zoom')
4046
+ }), /*#__PURE__*/jsx(Slider, {
4047
+ size: "small",
4048
+ value: element._cropImgScale,
4049
+ onChange: function onChange(_, v) {
4050
+ return element.setCropZoom(v);
4051
+ },
4052
+ min: minScale,
4053
+ max: maxScale,
4054
+ step: (maxScale - minScale) / 100 || 0.01,
4055
+ sx: {
4056
+ mb: 3
4057
+ }
4058
+ }), /*#__PURE__*/jsx(Button, {
4059
+ fullWidth: true,
4060
+ variant: "outlined",
4061
+ size: "small",
4062
+ onClick: handleReset,
4063
+ sx: {
4064
+ textTransform: 'none',
4065
+ mb: 3
4066
+ },
4067
+ children: t('toolbar.cropReset', 'Reset')
4068
+ }), /*#__PURE__*/jsxs(Box, {
4069
+ sx: {
4070
+ display: 'flex',
4071
+ gap: 1
4072
+ },
4073
+ children: [/*#__PURE__*/jsx(Button, {
4074
+ fullWidth: true,
4075
+ variant: "outlined",
4076
+ size: "small",
4077
+ onClick: handleCancel,
4078
+ sx: {
4079
+ textTransform: 'none'
4080
+ },
4081
+ children: t('toolbar.cropCancel', 'Cancel')
4082
+ }), /*#__PURE__*/jsx(Button, {
4083
+ fullWidth: true,
4084
+ variant: "contained",
4085
+ size: "small",
4086
+ onClick: handleDone,
4087
+ sx: {
4088
+ textTransform: 'none'
4089
+ },
4090
+ children: t('toolbar.cropDone', 'Done')
4091
+ })]
4092
+ })]
4093
+ });
4094
+ });
4095
+ ImageCropPanel.displayName = 'ImageCropPanel';
4096
+
3978
4097
  var SliderRow = function SliderRow(_ref) {
3979
4098
  var label = _ref.label,
3980
4099
  value = _ref.value,
@@ -4500,6 +4619,8 @@ var SidePanel = observer(function (_ref) {
4500
4619
  });
4501
4620
  }() : store._toolbarPanel.type === 'mask' ? /*#__PURE__*/jsx(ImageMaskPanel, {
4502
4621
  store: store
4622
+ }) : store._toolbarPanel.type === 'crop' ? /*#__PURE__*/jsx(ImageCropPanel, {
4623
+ store: store
4503
4624
  }) : null : (/* Normal panel content */
4504
4625
  activeSectionObj && /*#__PURE__*/jsx(Box, {
4505
4626
  sx: {
@@ -5855,5 +5976,285 @@ var InputFieldsSection = {
5855
5976
  Panel: InputFieldsPanelContent
5856
5977
  };
5857
5978
 
5858
- export { BackgroundSection, DEFAULT_SECTIONS, ElementsSection, ImagesGrid, InputFieldsSection, LayersSection, SectionTab, SidePanel, TextSection, UploadSection };
5979
+ function toPx(value, unit) {
5980
+ var dpi = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 96;
5981
+ var v = Number(value);
5982
+ if (!v) return 0;
5983
+ switch ((unit || 'px').toLowerCase()) {
5984
+ case 'mm':
5985
+ return Math.round(v * dpi / 25.4);
5986
+ case 'cm':
5987
+ return Math.round(v * dpi / 2.54);
5988
+ case 'in':
5989
+ return Math.round(v * dpi);
5990
+ default:
5991
+ return Math.round(v);
5992
+ }
5993
+ }
5994
+ function ResizeTab(_ref) {
5995
+ var onClick = _ref.onClick,
5996
+ active = _ref.active;
5997
+ return /*#__PURE__*/jsx(SectionTab, {
5998
+ name: "Resize",
5999
+ onClick: onClick,
6000
+ active: active,
6001
+ children: /*#__PURE__*/jsx(AspectRatioIcon, {})
6002
+ });
6003
+ }
6004
+ function scaleElements(children, ratioX, ratioY) {
6005
+ children.forEach(function (el) {
6006
+ var updates = {
6007
+ x: el.x * ratioX,
6008
+ y: el.y * ratioY,
6009
+ width: el.width * ratioX,
6010
+ height: el.height * ratioY
6011
+ };
6012
+ if (el.type === 'text') {
6013
+ updates.fontSize = el.fontSize * Math.min(ratioX, ratioY);
6014
+ }
6015
+ el.set(updates);
6016
+ if (el.type === 'group' && Array.isArray(el.children)) {
6017
+ scaleElements(el.children, ratioX, ratioY);
6018
+ }
6019
+ });
6020
+ }
6021
+ var ResizePanelInner = observer(function (_ref2) {
6022
+ var store = _ref2.store,
6023
+ fetchSizes = _ref2.fetchSizes;
6024
+ var _useState = useState(String(store.width)),
6025
+ _useState2 = _slicedToArray(_useState, 2),
6026
+ width = _useState2[0],
6027
+ setWidth = _useState2[1];
6028
+ var _useState3 = useState(String(store.height)),
6029
+ _useState4 = _slicedToArray(_useState3, 2),
6030
+ height = _useState4[0],
6031
+ setHeight = _useState4[1];
6032
+ var _useState5 = useState(false),
6033
+ _useState6 = _slicedToArray(_useState5, 2),
6034
+ scaleContent = _useState6[0],
6035
+ setScaleContent = _useState6[1];
6036
+ var _useState7 = useState([]),
6037
+ _useState8 = _slicedToArray(_useState7, 2),
6038
+ sizes = _useState8[0],
6039
+ setSizes = _useState8[1];
6040
+ var _useState9 = useState(false),
6041
+ _useState0 = _slicedToArray(_useState9, 2),
6042
+ loadingSizes = _useState0[0],
6043
+ setLoadingSizes = _useState0[1];
6044
+ var _useState1 = useState(false),
6045
+ _useState10 = _slicedToArray(_useState1, 2),
6046
+ sizesError = _useState10[0],
6047
+ setSizesError = _useState10[1];
6048
+
6049
+ // Keep inputs in sync when store dimensions change externally
6050
+ useEffect(function () {
6051
+ setWidth(String(store.width));
6052
+ setHeight(String(store.height));
6053
+ }, [store.width, store.height]);
6054
+ useEffect(function () {
6055
+ if (!fetchSizes) return;
6056
+ setLoadingSizes(true);
6057
+ setSizesError(false);
6058
+ fetchSizes().then(function (res) {
6059
+ var _res$data;
6060
+ return setSizes(((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.sizes) || []);
6061
+ })["catch"](function () {
6062
+ return setSizesError(true);
6063
+ })["finally"](function () {
6064
+ return setLoadingSizes(false);
6065
+ });
6066
+ }, []);
6067
+ var wNum = parseInt(width, 10);
6068
+ var hNum = parseInt(height, 10);
6069
+ var isValid = wNum > 0 && hNum > 0 && Number.isFinite(wNum) && Number.isFinite(hNum);
6070
+ var handleResize = function handleResize() {
6071
+ if (!isValid || !store.activePage) return;
6072
+ if (scaleContent) {
6073
+ var ratioX = wNum / store.width;
6074
+ var ratioY = hNum / store.height;
6075
+ scaleElements(store.activePage.children, ratioX, ratioY);
6076
+ }
6077
+ store.setSize(wNum, hNum);
6078
+ };
6079
+ var handlePresetClick = function handlePresetClick(size) {
6080
+ var dpi = size.dpi || 96;
6081
+ var w = toPx(size.width, size.unit, dpi);
6082
+ var h = toPx(size.height, size.unit, dpi);
6083
+ if (w > 0) setWidth(String(w));
6084
+ if (h > 0) setHeight(String(h));
6085
+ };
6086
+ return /*#__PURE__*/jsxs(Box, {
6087
+ sx: {
6088
+ p: 2,
6089
+ display: 'flex',
6090
+ flexDirection: 'column',
6091
+ gap: 2
6092
+ },
6093
+ children: [/*#__PURE__*/jsxs(Box, {
6094
+ children: [/*#__PURE__*/jsx(Typography, {
6095
+ sx: {
6096
+ fontWeight: 600,
6097
+ fontSize: 14,
6098
+ mb: 0.5
6099
+ },
6100
+ children: "Resize Canvas"
6101
+ }), /*#__PURE__*/jsxs(Typography, {
6102
+ sx: {
6103
+ fontSize: 12,
6104
+ color: '#888'
6105
+ },
6106
+ children: ["Current: ", store.width, " \xD7 ", store.height, " px"]
6107
+ })]
6108
+ }), /*#__PURE__*/jsxs(Box, {
6109
+ sx: {
6110
+ display: 'flex',
6111
+ gap: 1.5
6112
+ },
6113
+ children: [/*#__PURE__*/jsx(TextField, {
6114
+ label: "Width (px)",
6115
+ type: "number",
6116
+ size: "small",
6117
+ value: width,
6118
+ onChange: function onChange(e) {
6119
+ return setWidth(e.target.value);
6120
+ },
6121
+ inputProps: {
6122
+ min: 1,
6123
+ step: 1
6124
+ },
6125
+ error: !!width && (isNaN(wNum) || wNum <= 0),
6126
+ sx: {
6127
+ flex: 1
6128
+ }
6129
+ }), /*#__PURE__*/jsx(TextField, {
6130
+ label: "Height (px)",
6131
+ type: "number",
6132
+ size: "small",
6133
+ value: height,
6134
+ onChange: function onChange(e) {
6135
+ return setHeight(e.target.value);
6136
+ },
6137
+ inputProps: {
6138
+ min: 1,
6139
+ step: 1
6140
+ },
6141
+ error: !!height && (isNaN(hNum) || hNum <= 0),
6142
+ sx: {
6143
+ flex: 1
6144
+ }
6145
+ })]
6146
+ }), /*#__PURE__*/jsx(FormControlLabel, {
6147
+ control: /*#__PURE__*/jsx(Switch, {
6148
+ checked: scaleContent,
6149
+ onChange: function onChange(e) {
6150
+ return setScaleContent(e.target.checked);
6151
+ },
6152
+ size: "small"
6153
+ }),
6154
+ label: /*#__PURE__*/jsx(Typography, {
6155
+ sx: {
6156
+ fontSize: 13
6157
+ },
6158
+ children: "Scale content"
6159
+ })
6160
+ }), /*#__PURE__*/jsx(Button, {
6161
+ variant: "contained",
6162
+ disabled: !isValid || !store.activePage,
6163
+ onClick: handleResize,
6164
+ sx: {
6165
+ textTransform: 'uppercase',
6166
+ fontWeight: 700,
6167
+ letterSpacing: 1,
6168
+ backgroundColor: '#0d83cd',
6169
+ '&:hover': {
6170
+ backgroundColor: '#0a6fad'
6171
+ },
6172
+ '&.Mui-disabled': {
6173
+ opacity: 0.5
6174
+ }
6175
+ },
6176
+ children: "Resize"
6177
+ }), /*#__PURE__*/jsx(Divider, {}), /*#__PURE__*/jsx(Typography, {
6178
+ sx: {
6179
+ fontWeight: 600,
6180
+ fontSize: 13,
6181
+ color: '#555'
6182
+ },
6183
+ children: "Preset sizes"
6184
+ }), loadingSizes && /*#__PURE__*/jsx(Box, {
6185
+ sx: {
6186
+ display: 'flex',
6187
+ justifyContent: 'center',
6188
+ py: 2
6189
+ },
6190
+ children: /*#__PURE__*/jsx(CircularProgress, {
6191
+ size: 22
6192
+ })
6193
+ }), sizesError && /*#__PURE__*/jsx(Typography, {
6194
+ sx: {
6195
+ fontSize: 12,
6196
+ color: '#c44'
6197
+ },
6198
+ children: "Could not load sizes."
6199
+ }), !loadingSizes && !sizesError && sizes.length === 0 && /*#__PURE__*/jsx(Typography, {
6200
+ sx: {
6201
+ fontSize: 12,
6202
+ color: '#aaa'
6203
+ },
6204
+ children: "No sizes available."
6205
+ }), !loadingSizes && !sizesError && sizes.map(function (size) {
6206
+ var dpi = size.dpi || 96;
6207
+ toPx(size.width, size.unit, dpi);
6208
+ toPx(size.height, size.unit, dpi);
6209
+ var dimLabel = size.width && size.height ? "".concat(size.width, " \xD7 ").concat(size.height, " ").concat((size.unit || 'px').toUpperCase()) : null;
6210
+ return /*#__PURE__*/jsxs(Box, {
6211
+ onClick: function onClick() {
6212
+ return handlePresetClick(size);
6213
+ },
6214
+ sx: {
6215
+ display: 'flex',
6216
+ alignItems: 'center',
6217
+ justifyContent: 'space-between',
6218
+ px: 1.5,
6219
+ py: 0.75,
6220
+ borderRadius: '6px',
6221
+ cursor: 'pointer',
6222
+ border: '1px solid #e8e8e8',
6223
+ '&:hover': {
6224
+ backgroundColor: '#f0f7fd',
6225
+ borderColor: '#0d83cd'
6226
+ },
6227
+ transition: 'all 0.12s ease'
6228
+ },
6229
+ children: [/*#__PURE__*/jsx(Typography, {
6230
+ sx: {
6231
+ fontSize: 13,
6232
+ fontWeight: 500
6233
+ },
6234
+ children: size.name
6235
+ }), dimLabel && /*#__PURE__*/jsx(Typography, {
6236
+ sx: {
6237
+ fontSize: 11,
6238
+ color: '#888',
6239
+ fontFamily: 'monospace'
6240
+ },
6241
+ children: dimLabel
6242
+ })]
6243
+ }, size.id);
6244
+ })]
6245
+ });
6246
+ });
6247
+ function createResizeSection(fetchSizes) {
6248
+ return {
6249
+ name: 'resize',
6250
+ Tab: ResizeTab,
6251
+ Panel: function Panel(props) {
6252
+ return /*#__PURE__*/jsx(ResizePanelInner, _objectSpread2(_objectSpread2({}, props), {}, {
6253
+ fetchSizes: fetchSizes
6254
+ }));
6255
+ }
6256
+ };
6257
+ }
6258
+
6259
+ export { BackgroundSection, DEFAULT_SECTIONS, ElementsSection, ImagesGrid, InputFieldsSection, LayersSection, SectionTab, SidePanel, TextSection, UploadSection, createResizeSection };
5859
6260
  //# sourceMappingURL=index.js.map