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/esm/index.js CHANGED
@@ -31,6 +31,7 @@ import NumbersIcon from '@mui/icons-material/Numbers';
31
31
  import RadioButtonCheckedIcon from '@mui/icons-material/RadioButtonChecked';
32
32
  import FormatListBulletedIcon from '@mui/icons-material/FormatListBulleted';
33
33
  import AddIcon from '@mui/icons-material/Add';
34
+ import '@mui/icons-material/AspectRatio';
34
35
  import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
35
36
  import FileUploadIcon from '@mui/icons-material/FileUpload';
36
37
  import UndoIcon from '@mui/icons-material/Undo';
@@ -8155,6 +8156,265 @@ var InputFieldsSection = {
8155
8156
  Panel: InputFieldsPanelContent
8156
8157
  };
8157
8158
 
8159
+ function toPx(value, unit) {
8160
+ var dpi = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 96;
8161
+ var v = Number(value);
8162
+ if (!v) return 0;
8163
+ switch ((unit || 'px').toLowerCase()) {
8164
+ case 'mm':
8165
+ return Math.round(v * dpi / 25.4);
8166
+ case 'cm':
8167
+ return Math.round(v * dpi / 2.54);
8168
+ case 'in':
8169
+ return Math.round(v * dpi);
8170
+ default:
8171
+ return Math.round(v);
8172
+ }
8173
+ }
8174
+ function scaleElements(children, ratioX, ratioY) {
8175
+ children.forEach(function (el) {
8176
+ var updates = {
8177
+ x: el.x * ratioX,
8178
+ y: el.y * ratioY,
8179
+ width: el.width * ratioX,
8180
+ height: el.height * ratioY
8181
+ };
8182
+ if (el.type === 'text') {
8183
+ updates.fontSize = el.fontSize * Math.min(ratioX, ratioY);
8184
+ }
8185
+ el.set(updates);
8186
+ if (el.type === 'group' && Array.isArray(el.children)) {
8187
+ scaleElements(el.children, ratioX, ratioY);
8188
+ }
8189
+ });
8190
+ }
8191
+ observer(function (_ref2) {
8192
+ var store = _ref2.store,
8193
+ fetchSizes = _ref2.fetchSizes;
8194
+ var _useState = useState(String(store.width)),
8195
+ _useState2 = _slicedToArray(_useState, 2),
8196
+ width = _useState2[0],
8197
+ setWidth = _useState2[1];
8198
+ var _useState3 = useState(String(store.height)),
8199
+ _useState4 = _slicedToArray(_useState3, 2),
8200
+ height = _useState4[0],
8201
+ setHeight = _useState4[1];
8202
+ var _useState5 = useState(false),
8203
+ _useState6 = _slicedToArray(_useState5, 2),
8204
+ scaleContent = _useState6[0],
8205
+ setScaleContent = _useState6[1];
8206
+ var _useState7 = useState([]),
8207
+ _useState8 = _slicedToArray(_useState7, 2),
8208
+ sizes = _useState8[0],
8209
+ setSizes = _useState8[1];
8210
+ var _useState9 = useState(false),
8211
+ _useState0 = _slicedToArray(_useState9, 2),
8212
+ loadingSizes = _useState0[0],
8213
+ setLoadingSizes = _useState0[1];
8214
+ var _useState1 = useState(false),
8215
+ _useState10 = _slicedToArray(_useState1, 2),
8216
+ sizesError = _useState10[0],
8217
+ setSizesError = _useState10[1];
8218
+
8219
+ // Keep inputs in sync when store dimensions change externally
8220
+ useEffect(function () {
8221
+ setWidth(String(store.width));
8222
+ setHeight(String(store.height));
8223
+ }, [store.width, store.height]);
8224
+ useEffect(function () {
8225
+ if (!fetchSizes) return;
8226
+ setLoadingSizes(true);
8227
+ setSizesError(false);
8228
+ fetchSizes().then(function (res) {
8229
+ var _res$data;
8230
+ return setSizes(((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.sizes) || []);
8231
+ })["catch"](function () {
8232
+ return setSizesError(true);
8233
+ })["finally"](function () {
8234
+ return setLoadingSizes(false);
8235
+ });
8236
+ }, []);
8237
+ var wNum = parseInt(width, 10);
8238
+ var hNum = parseInt(height, 10);
8239
+ var isValid = wNum > 0 && hNum > 0 && Number.isFinite(wNum) && Number.isFinite(hNum);
8240
+ var handleResize = function handleResize() {
8241
+ if (!isValid || !store.activePage) return;
8242
+ if (scaleContent) {
8243
+ var ratioX = wNum / store.width;
8244
+ var ratioY = hNum / store.height;
8245
+ scaleElements(store.activePage.children, ratioX, ratioY);
8246
+ }
8247
+ store.setSize(wNum, hNum);
8248
+ };
8249
+ var handlePresetClick = function handlePresetClick(size) {
8250
+ var dpi = size.dpi || 96;
8251
+ var w = toPx(size.width, size.unit, dpi);
8252
+ var h = toPx(size.height, size.unit, dpi);
8253
+ if (w > 0) setWidth(String(w));
8254
+ if (h > 0) setHeight(String(h));
8255
+ };
8256
+ return /*#__PURE__*/jsxs(Box, {
8257
+ sx: {
8258
+ p: 2,
8259
+ display: 'flex',
8260
+ flexDirection: 'column',
8261
+ gap: 2
8262
+ },
8263
+ children: [/*#__PURE__*/jsxs(Box, {
8264
+ children: [/*#__PURE__*/jsx(Typography, {
8265
+ sx: {
8266
+ fontWeight: 600,
8267
+ fontSize: 14,
8268
+ mb: 0.5
8269
+ },
8270
+ children: "Resize Canvas"
8271
+ }), /*#__PURE__*/jsxs(Typography, {
8272
+ sx: {
8273
+ fontSize: 12,
8274
+ color: '#888'
8275
+ },
8276
+ children: ["Current: ", store.width, " \xD7 ", store.height, " px"]
8277
+ })]
8278
+ }), /*#__PURE__*/jsxs(Box, {
8279
+ sx: {
8280
+ display: 'flex',
8281
+ gap: 1.5
8282
+ },
8283
+ children: [/*#__PURE__*/jsx(TextField, {
8284
+ label: "Width (px)",
8285
+ type: "number",
8286
+ size: "small",
8287
+ value: width,
8288
+ onChange: function onChange(e) {
8289
+ return setWidth(e.target.value);
8290
+ },
8291
+ inputProps: {
8292
+ min: 1,
8293
+ step: 1
8294
+ },
8295
+ error: !!width && (isNaN(wNum) || wNum <= 0),
8296
+ sx: {
8297
+ flex: 1
8298
+ }
8299
+ }), /*#__PURE__*/jsx(TextField, {
8300
+ label: "Height (px)",
8301
+ type: "number",
8302
+ size: "small",
8303
+ value: height,
8304
+ onChange: function onChange(e) {
8305
+ return setHeight(e.target.value);
8306
+ },
8307
+ inputProps: {
8308
+ min: 1,
8309
+ step: 1
8310
+ },
8311
+ error: !!height && (isNaN(hNum) || hNum <= 0),
8312
+ sx: {
8313
+ flex: 1
8314
+ }
8315
+ })]
8316
+ }), /*#__PURE__*/jsx(FormControlLabel, {
8317
+ control: /*#__PURE__*/jsx(Switch, {
8318
+ checked: scaleContent,
8319
+ onChange: function onChange(e) {
8320
+ return setScaleContent(e.target.checked);
8321
+ },
8322
+ size: "small"
8323
+ }),
8324
+ label: /*#__PURE__*/jsx(Typography, {
8325
+ sx: {
8326
+ fontSize: 13
8327
+ },
8328
+ children: "Scale content"
8329
+ })
8330
+ }), /*#__PURE__*/jsx(Button, {
8331
+ variant: "contained",
8332
+ disabled: !isValid || !store.activePage,
8333
+ onClick: handleResize,
8334
+ sx: {
8335
+ textTransform: 'uppercase',
8336
+ fontWeight: 700,
8337
+ letterSpacing: 1,
8338
+ backgroundColor: '#0d83cd',
8339
+ '&:hover': {
8340
+ backgroundColor: '#0a6fad'
8341
+ },
8342
+ '&.Mui-disabled': {
8343
+ opacity: 0.5
8344
+ }
8345
+ },
8346
+ children: "Resize"
8347
+ }), /*#__PURE__*/jsx(Divider, {}), /*#__PURE__*/jsx(Typography, {
8348
+ sx: {
8349
+ fontWeight: 600,
8350
+ fontSize: 13,
8351
+ color: '#555'
8352
+ },
8353
+ children: "Preset sizes"
8354
+ }), loadingSizes && /*#__PURE__*/jsx(Box, {
8355
+ sx: {
8356
+ display: 'flex',
8357
+ justifyContent: 'center',
8358
+ py: 2
8359
+ },
8360
+ children: /*#__PURE__*/jsx(CircularProgress, {
8361
+ size: 22
8362
+ })
8363
+ }), sizesError && /*#__PURE__*/jsx(Typography, {
8364
+ sx: {
8365
+ fontSize: 12,
8366
+ color: '#c44'
8367
+ },
8368
+ children: "Could not load sizes."
8369
+ }), !loadingSizes && !sizesError && sizes.length === 0 && /*#__PURE__*/jsx(Typography, {
8370
+ sx: {
8371
+ fontSize: 12,
8372
+ color: '#aaa'
8373
+ },
8374
+ children: "No sizes available."
8375
+ }), !loadingSizes && !sizesError && sizes.map(function (size) {
8376
+ var dpi = size.dpi || 96;
8377
+ toPx(size.width, size.unit, dpi);
8378
+ toPx(size.height, size.unit, dpi);
8379
+ var dimLabel = size.width && size.height ? "".concat(size.width, " \xD7 ").concat(size.height, " ").concat((size.unit || 'px').toUpperCase()) : null;
8380
+ return /*#__PURE__*/jsxs(Box, {
8381
+ onClick: function onClick() {
8382
+ return handlePresetClick(size);
8383
+ },
8384
+ sx: {
8385
+ display: 'flex',
8386
+ alignItems: 'center',
8387
+ justifyContent: 'space-between',
8388
+ px: 1.5,
8389
+ py: 0.75,
8390
+ borderRadius: '6px',
8391
+ cursor: 'pointer',
8392
+ border: '1px solid #e8e8e8',
8393
+ '&:hover': {
8394
+ backgroundColor: '#f0f7fd',
8395
+ borderColor: '#0d83cd'
8396
+ },
8397
+ transition: 'all 0.12s ease'
8398
+ },
8399
+ children: [/*#__PURE__*/jsx(Typography, {
8400
+ sx: {
8401
+ fontSize: 13,
8402
+ fontWeight: 500
8403
+ },
8404
+ children: size.name
8405
+ }), dimLabel && /*#__PURE__*/jsx(Typography, {
8406
+ sx: {
8407
+ fontSize: 11,
8408
+ color: '#888',
8409
+ fontFamily: 'monospace'
8410
+ },
8411
+ children: dimLabel
8412
+ })]
8413
+ }, size.id);
8414
+ })]
8415
+ });
8416
+ });
8417
+
8158
8418
  var GOOGLE_FONTS_API = 'https://www.googleapis.com/webfonts/v1/webfonts';
8159
8419
  var cachedFonts = null;
8160
8420
  function fetchGoogleFonts(_x) {