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