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