labellife-design-tool 2.3.7 → 2.3.8

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);
@@ -5855,5 +5856,285 @@ var InputFieldsSection = {
5855
5856
  Panel: InputFieldsPanelContent
5856
5857
  };
5857
5858
 
5858
- export { BackgroundSection, DEFAULT_SECTIONS, ElementsSection, ImagesGrid, InputFieldsSection, LayersSection, SectionTab, SidePanel, TextSection, UploadSection };
5859
+ function toPx(value, unit) {
5860
+ var dpi = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 96;
5861
+ var v = Number(value);
5862
+ if (!v) return 0;
5863
+ switch ((unit || 'px').toLowerCase()) {
5864
+ case 'mm':
5865
+ return Math.round(v * dpi / 25.4);
5866
+ case 'cm':
5867
+ return Math.round(v * dpi / 2.54);
5868
+ case 'in':
5869
+ return Math.round(v * dpi);
5870
+ default:
5871
+ return Math.round(v);
5872
+ }
5873
+ }
5874
+ function ResizeTab(_ref) {
5875
+ var onClick = _ref.onClick,
5876
+ active = _ref.active;
5877
+ return /*#__PURE__*/jsx(SectionTab, {
5878
+ name: "Resize",
5879
+ onClick: onClick,
5880
+ active: active,
5881
+ children: /*#__PURE__*/jsx(AspectRatioIcon, {})
5882
+ });
5883
+ }
5884
+ function scaleElements(children, ratioX, ratioY) {
5885
+ children.forEach(function (el) {
5886
+ var updates = {
5887
+ x: el.x * ratioX,
5888
+ y: el.y * ratioY,
5889
+ width: el.width * ratioX,
5890
+ height: el.height * ratioY
5891
+ };
5892
+ if (el.type === 'text') {
5893
+ updates.fontSize = el.fontSize * Math.min(ratioX, ratioY);
5894
+ }
5895
+ el.set(updates);
5896
+ if (el.type === 'group' && Array.isArray(el.children)) {
5897
+ scaleElements(el.children, ratioX, ratioY);
5898
+ }
5899
+ });
5900
+ }
5901
+ var ResizePanelInner = observer(function (_ref2) {
5902
+ var store = _ref2.store,
5903
+ fetchSizes = _ref2.fetchSizes;
5904
+ var _useState = useState(String(store.width)),
5905
+ _useState2 = _slicedToArray(_useState, 2),
5906
+ width = _useState2[0],
5907
+ setWidth = _useState2[1];
5908
+ var _useState3 = useState(String(store.height)),
5909
+ _useState4 = _slicedToArray(_useState3, 2),
5910
+ height = _useState4[0],
5911
+ setHeight = _useState4[1];
5912
+ var _useState5 = useState(false),
5913
+ _useState6 = _slicedToArray(_useState5, 2),
5914
+ scaleContent = _useState6[0],
5915
+ setScaleContent = _useState6[1];
5916
+ var _useState7 = useState([]),
5917
+ _useState8 = _slicedToArray(_useState7, 2),
5918
+ sizes = _useState8[0],
5919
+ setSizes = _useState8[1];
5920
+ var _useState9 = useState(false),
5921
+ _useState0 = _slicedToArray(_useState9, 2),
5922
+ loadingSizes = _useState0[0],
5923
+ setLoadingSizes = _useState0[1];
5924
+ var _useState1 = useState(false),
5925
+ _useState10 = _slicedToArray(_useState1, 2),
5926
+ sizesError = _useState10[0],
5927
+ setSizesError = _useState10[1];
5928
+
5929
+ // Keep inputs in sync when store dimensions change externally
5930
+ useEffect(function () {
5931
+ setWidth(String(store.width));
5932
+ setHeight(String(store.height));
5933
+ }, [store.width, store.height]);
5934
+ useEffect(function () {
5935
+ if (!fetchSizes) return;
5936
+ setLoadingSizes(true);
5937
+ setSizesError(false);
5938
+ fetchSizes().then(function (res) {
5939
+ var _res$data;
5940
+ return setSizes(((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.sizes) || []);
5941
+ })["catch"](function () {
5942
+ return setSizesError(true);
5943
+ })["finally"](function () {
5944
+ return setLoadingSizes(false);
5945
+ });
5946
+ }, []);
5947
+ var wNum = parseInt(width, 10);
5948
+ var hNum = parseInt(height, 10);
5949
+ var isValid = wNum > 0 && hNum > 0 && Number.isFinite(wNum) && Number.isFinite(hNum);
5950
+ var handleResize = function handleResize() {
5951
+ if (!isValid || !store.activePage) return;
5952
+ if (scaleContent) {
5953
+ var ratioX = wNum / store.width;
5954
+ var ratioY = hNum / store.height;
5955
+ scaleElements(store.activePage.children, ratioX, ratioY);
5956
+ }
5957
+ store.setSize(wNum, hNum);
5958
+ };
5959
+ var handlePresetClick = function handlePresetClick(size) {
5960
+ var dpi = size.dpi || 96;
5961
+ var w = toPx(size.width, size.unit, dpi);
5962
+ var h = toPx(size.height, size.unit, dpi);
5963
+ if (w > 0) setWidth(String(w));
5964
+ if (h > 0) setHeight(String(h));
5965
+ };
5966
+ return /*#__PURE__*/jsxs(Box, {
5967
+ sx: {
5968
+ p: 2,
5969
+ display: 'flex',
5970
+ flexDirection: 'column',
5971
+ gap: 2
5972
+ },
5973
+ children: [/*#__PURE__*/jsxs(Box, {
5974
+ children: [/*#__PURE__*/jsx(Typography, {
5975
+ sx: {
5976
+ fontWeight: 600,
5977
+ fontSize: 14,
5978
+ mb: 0.5
5979
+ },
5980
+ children: "Resize Canvas"
5981
+ }), /*#__PURE__*/jsxs(Typography, {
5982
+ sx: {
5983
+ fontSize: 12,
5984
+ color: '#888'
5985
+ },
5986
+ children: ["Current: ", store.width, " \xD7 ", store.height, " px"]
5987
+ })]
5988
+ }), /*#__PURE__*/jsxs(Box, {
5989
+ sx: {
5990
+ display: 'flex',
5991
+ gap: 1.5
5992
+ },
5993
+ children: [/*#__PURE__*/jsx(TextField, {
5994
+ label: "Width (px)",
5995
+ type: "number",
5996
+ size: "small",
5997
+ value: width,
5998
+ onChange: function onChange(e) {
5999
+ return setWidth(e.target.value);
6000
+ },
6001
+ inputProps: {
6002
+ min: 1,
6003
+ step: 1
6004
+ },
6005
+ error: !!width && (isNaN(wNum) || wNum <= 0),
6006
+ sx: {
6007
+ flex: 1
6008
+ }
6009
+ }), /*#__PURE__*/jsx(TextField, {
6010
+ label: "Height (px)",
6011
+ type: "number",
6012
+ size: "small",
6013
+ value: height,
6014
+ onChange: function onChange(e) {
6015
+ return setHeight(e.target.value);
6016
+ },
6017
+ inputProps: {
6018
+ min: 1,
6019
+ step: 1
6020
+ },
6021
+ error: !!height && (isNaN(hNum) || hNum <= 0),
6022
+ sx: {
6023
+ flex: 1
6024
+ }
6025
+ })]
6026
+ }), /*#__PURE__*/jsx(FormControlLabel, {
6027
+ control: /*#__PURE__*/jsx(Switch, {
6028
+ checked: scaleContent,
6029
+ onChange: function onChange(e) {
6030
+ return setScaleContent(e.target.checked);
6031
+ },
6032
+ size: "small"
6033
+ }),
6034
+ label: /*#__PURE__*/jsx(Typography, {
6035
+ sx: {
6036
+ fontSize: 13
6037
+ },
6038
+ children: "Scale content"
6039
+ })
6040
+ }), /*#__PURE__*/jsx(Button, {
6041
+ variant: "contained",
6042
+ disabled: !isValid || !store.activePage,
6043
+ onClick: handleResize,
6044
+ sx: {
6045
+ textTransform: 'uppercase',
6046
+ fontWeight: 700,
6047
+ letterSpacing: 1,
6048
+ backgroundColor: '#0d83cd',
6049
+ '&:hover': {
6050
+ backgroundColor: '#0a6fad'
6051
+ },
6052
+ '&.Mui-disabled': {
6053
+ opacity: 0.5
6054
+ }
6055
+ },
6056
+ children: "Resize"
6057
+ }), /*#__PURE__*/jsx(Divider, {}), /*#__PURE__*/jsx(Typography, {
6058
+ sx: {
6059
+ fontWeight: 600,
6060
+ fontSize: 13,
6061
+ color: '#555'
6062
+ },
6063
+ children: "Preset sizes"
6064
+ }), loadingSizes && /*#__PURE__*/jsx(Box, {
6065
+ sx: {
6066
+ display: 'flex',
6067
+ justifyContent: 'center',
6068
+ py: 2
6069
+ },
6070
+ children: /*#__PURE__*/jsx(CircularProgress, {
6071
+ size: 22
6072
+ })
6073
+ }), sizesError && /*#__PURE__*/jsx(Typography, {
6074
+ sx: {
6075
+ fontSize: 12,
6076
+ color: '#c44'
6077
+ },
6078
+ children: "Could not load sizes."
6079
+ }), !loadingSizes && !sizesError && sizes.length === 0 && /*#__PURE__*/jsx(Typography, {
6080
+ sx: {
6081
+ fontSize: 12,
6082
+ color: '#aaa'
6083
+ },
6084
+ children: "No sizes available."
6085
+ }), !loadingSizes && !sizesError && sizes.map(function (size) {
6086
+ var dpi = size.dpi || 96;
6087
+ toPx(size.width, size.unit, dpi);
6088
+ toPx(size.height, size.unit, dpi);
6089
+ var dimLabel = size.width && size.height ? "".concat(size.width, " \xD7 ").concat(size.height, " ").concat((size.unit || 'px').toUpperCase()) : null;
6090
+ return /*#__PURE__*/jsxs(Box, {
6091
+ onClick: function onClick() {
6092
+ return handlePresetClick(size);
6093
+ },
6094
+ sx: {
6095
+ display: 'flex',
6096
+ alignItems: 'center',
6097
+ justifyContent: 'space-between',
6098
+ px: 1.5,
6099
+ py: 0.75,
6100
+ borderRadius: '6px',
6101
+ cursor: 'pointer',
6102
+ border: '1px solid #e8e8e8',
6103
+ '&:hover': {
6104
+ backgroundColor: '#f0f7fd',
6105
+ borderColor: '#0d83cd'
6106
+ },
6107
+ transition: 'all 0.12s ease'
6108
+ },
6109
+ children: [/*#__PURE__*/jsx(Typography, {
6110
+ sx: {
6111
+ fontSize: 13,
6112
+ fontWeight: 500
6113
+ },
6114
+ children: size.name
6115
+ }), dimLabel && /*#__PURE__*/jsx(Typography, {
6116
+ sx: {
6117
+ fontSize: 11,
6118
+ color: '#888',
6119
+ fontFamily: 'monospace'
6120
+ },
6121
+ children: dimLabel
6122
+ })]
6123
+ }, size.id);
6124
+ })]
6125
+ });
6126
+ });
6127
+ function createResizeSection(fetchSizes) {
6128
+ return {
6129
+ name: 'resize',
6130
+ Tab: ResizeTab,
6131
+ Panel: function Panel(props) {
6132
+ return /*#__PURE__*/jsx(ResizePanelInner, _objectSpread2(_objectSpread2({}, props), {}, {
6133
+ fetchSizes: fetchSizes
6134
+ }));
6135
+ }
6136
+ };
6137
+ }
6138
+
6139
+ export { BackgroundSection, DEFAULT_SECTIONS, ElementsSection, ImagesGrid, InputFieldsSection, LayersSection, SectionTab, SidePanel, TextSection, UploadSection, createResizeSection };
5859
6140
  //# sourceMappingURL=index.js.map