labellife-design-tool 2.3.6 → 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) {
@@ -11319,7 +11579,7 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11319
11579
  case 'radio':
11320
11580
  {
11321
11581
  var otherSelected = value === '__custom__';
11322
- return /*#__PURE__*/jsxs(Box, {
11582
+ return /*#__PURE__*/jsx(Box, {
11323
11583
  sx: {
11324
11584
  mt: 1,
11325
11585
  flex: 1,
@@ -11340,7 +11600,7 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11340
11600
  background: '#aaa'
11341
11601
  }
11342
11602
  },
11343
- children: [/*#__PURE__*/jsxs(RadioGroup, {
11603
+ children: /*#__PURE__*/jsxs(RadioGroup, {
11344
11604
  value: value,
11345
11605
  onChange: function onChange(e) {
11346
11606
  return setValue(e.target.value);
@@ -11348,7 +11608,73 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11348
11608
  sx: {
11349
11609
  gap: 1
11350
11610
  },
11351
- children: [options.map(function (opt) {
11611
+ children: [/*#__PURE__*/jsxs(Box, {
11612
+ sx: {
11613
+ display: 'flex',
11614
+ flexDirection: 'column'
11615
+ },
11616
+ children: [/*#__PURE__*/jsx(FormControlLabel, {
11617
+ value: "__custom__",
11618
+ control: /*#__PURE__*/jsx(Radio, {
11619
+ sx: {
11620
+ color: '#d0d5dd',
11621
+ '&.Mui-checked': {
11622
+ color: accentColor
11623
+ }
11624
+ }
11625
+ }),
11626
+ label: /*#__PURE__*/jsx(Typography, {
11627
+ sx: {
11628
+ fontSize: 18
11629
+ },
11630
+ children: t('inputFieldsDialog.other', 'Other')
11631
+ }),
11632
+ sx: {
11633
+ m: 0,
11634
+ border: '1px solid',
11635
+ borderColor: otherSelected ? accentColor : '#d0d5dd',
11636
+ borderRadius: otherSelected ? '8px 8px 0 0' : '8px',
11637
+ borderBottom: otherSelected ? 'none' : undefined,
11638
+ px: 2,
11639
+ py: 0.75,
11640
+ transition: 'border-color 0.15s ease, border-radius 0.15s ease',
11641
+ backgroundColor: otherSelected ? 'rgba(13,131,205,0.04)' : 'transparent',
11642
+ '&:hover': {
11643
+ borderColor: accentColor,
11644
+ backgroundColor: 'rgba(13,131,205,0.03)'
11645
+ }
11646
+ }
11647
+ }), otherSelected && /*#__PURE__*/jsx(TextField, {
11648
+ autoFocus: true,
11649
+ fullWidth: true,
11650
+ value: customRadioValue,
11651
+ onChange: function onChange(e) {
11652
+ return setCustomRadioValue(e.target.value);
11653
+ },
11654
+ onKeyDown: function onKeyDown(e) {
11655
+ if (e.key === 'Enter' && customRadioValue.trim()) handleSubmit();
11656
+ },
11657
+ placeholder: t('inputFieldsDialog.otherPlaceholder', 'Type your answer…'),
11658
+ sx: {
11659
+ '& .MuiOutlinedInput-root': {
11660
+ borderRadius: '0 0 8px 8px',
11661
+ fontSize: 18,
11662
+ '& fieldset': {
11663
+ borderColor: accentColor,
11664
+ borderTopColor: 'transparent'
11665
+ },
11666
+ '&:hover fieldset': {
11667
+ borderColor: accentColor,
11668
+ borderTopColor: 'transparent'
11669
+ },
11670
+ '&.Mui-focused fieldset': {
11671
+ borderColor: accentColor,
11672
+ borderTopColor: 'transparent'
11673
+ }
11674
+ }
11675
+ }
11676
+ })]
11677
+ }), options.map(function (opt) {
11352
11678
  return /*#__PURE__*/jsx(FormControlLabel, {
11353
11679
  value: opt,
11354
11680
  control: /*#__PURE__*/jsx(Radio, {
@@ -11380,68 +11706,8 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11380
11706
  }
11381
11707
  }
11382
11708
  }, opt);
11383
- }), /*#__PURE__*/jsx(FormControlLabel, {
11384
- value: "__custom__",
11385
- control: /*#__PURE__*/jsx(Radio, {
11386
- sx: {
11387
- color: '#d0d5dd',
11388
- '&.Mui-checked': {
11389
- color: accentColor
11390
- }
11391
- }
11392
- }),
11393
- label: /*#__PURE__*/jsx(Typography, {
11394
- sx: {
11395
- fontSize: 18
11396
- },
11397
- children: t('inputFieldsDialog.other', 'Other')
11398
- }),
11399
- sx: {
11400
- m: 0,
11401
- border: '1px solid',
11402
- borderColor: otherSelected ? accentColor : '#d0d5dd',
11403
- borderRadius: otherSelected ? '8px 8px 0 0' : '8px',
11404
- borderBottom: otherSelected ? 'none' : undefined,
11405
- px: 2,
11406
- py: 0.75,
11407
- transition: 'border-color 0.15s ease, border-radius 0.15s ease',
11408
- backgroundColor: otherSelected ? 'rgba(13,131,205,0.04)' : 'transparent',
11409
- '&:hover': {
11410
- borderColor: accentColor,
11411
- backgroundColor: 'rgba(13,131,205,0.03)'
11412
- }
11413
- }
11414
11709
  })]
11415
- }), otherSelected && /*#__PURE__*/jsx(TextField, {
11416
- autoFocus: true,
11417
- fullWidth: true,
11418
- value: customRadioValue,
11419
- onChange: function onChange(e) {
11420
- return setCustomRadioValue(e.target.value);
11421
- },
11422
- onKeyDown: function onKeyDown(e) {
11423
- if (e.key === 'Enter' && customRadioValue.trim()) handleSubmit();
11424
- },
11425
- placeholder: t('inputFieldsDialog.otherPlaceholder', 'Type your answer…'),
11426
- sx: {
11427
- '& .MuiOutlinedInput-root': {
11428
- borderRadius: '0 0 8px 8px',
11429
- fontSize: 18,
11430
- '& fieldset': {
11431
- borderColor: accentColor,
11432
- borderTopColor: 'transparent'
11433
- },
11434
- '&:hover fieldset': {
11435
- borderColor: accentColor,
11436
- borderTopColor: 'transparent'
11437
- },
11438
- '&.Mui-focused fieldset': {
11439
- borderColor: accentColor,
11440
- borderTopColor: 'transparent'
11441
- }
11442
- }
11443
- }
11444
- })]
11710
+ })
11445
11711
  });
11446
11712
  }
11447
11713
  case 'list':