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/cjs/index.js CHANGED
@@ -33,6 +33,7 @@ var NumbersIcon = require('@mui/icons-material/Numbers');
33
33
  var RadioButtonCheckedIcon = require('@mui/icons-material/RadioButtonChecked');
34
34
  var FormatListBulletedIcon = require('@mui/icons-material/FormatListBulleted');
35
35
  var AddIcon = require('@mui/icons-material/Add');
36
+ require('@mui/icons-material/AspectRatio');
36
37
  var ArrowDropDownIcon = require('@mui/icons-material/ArrowDropDown');
37
38
  var FileUploadIcon = require('@mui/icons-material/FileUpload');
38
39
  var UndoIcon = require('@mui/icons-material/Undo');
@@ -8157,6 +8158,265 @@ var InputFieldsSection = {
8157
8158
  Panel: InputFieldsPanelContent
8158
8159
  };
8159
8160
 
8161
+ function toPx(value, unit) {
8162
+ var dpi = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 96;
8163
+ var v = Number(value);
8164
+ if (!v) return 0;
8165
+ switch ((unit || 'px').toLowerCase()) {
8166
+ case 'mm':
8167
+ return Math.round(v * dpi / 25.4);
8168
+ case 'cm':
8169
+ return Math.round(v * dpi / 2.54);
8170
+ case 'in':
8171
+ return Math.round(v * dpi);
8172
+ default:
8173
+ return Math.round(v);
8174
+ }
8175
+ }
8176
+ function scaleElements(children, ratioX, ratioY) {
8177
+ children.forEach(function (el) {
8178
+ var updates = {
8179
+ x: el.x * ratioX,
8180
+ y: el.y * ratioY,
8181
+ width: el.width * ratioX,
8182
+ height: el.height * ratioY
8183
+ };
8184
+ if (el.type === 'text') {
8185
+ updates.fontSize = el.fontSize * Math.min(ratioX, ratioY);
8186
+ }
8187
+ el.set(updates);
8188
+ if (el.type === 'group' && Array.isArray(el.children)) {
8189
+ scaleElements(el.children, ratioX, ratioY);
8190
+ }
8191
+ });
8192
+ }
8193
+ mobxReactLite.observer(function (_ref2) {
8194
+ var store = _ref2.store,
8195
+ fetchSizes = _ref2.fetchSizes;
8196
+ var _useState = React.useState(String(store.width)),
8197
+ _useState2 = _slicedToArray(_useState, 2),
8198
+ width = _useState2[0],
8199
+ setWidth = _useState2[1];
8200
+ var _useState3 = React.useState(String(store.height)),
8201
+ _useState4 = _slicedToArray(_useState3, 2),
8202
+ height = _useState4[0],
8203
+ setHeight = _useState4[1];
8204
+ var _useState5 = React.useState(false),
8205
+ _useState6 = _slicedToArray(_useState5, 2),
8206
+ scaleContent = _useState6[0],
8207
+ setScaleContent = _useState6[1];
8208
+ var _useState7 = React.useState([]),
8209
+ _useState8 = _slicedToArray(_useState7, 2),
8210
+ sizes = _useState8[0],
8211
+ setSizes = _useState8[1];
8212
+ var _useState9 = React.useState(false),
8213
+ _useState0 = _slicedToArray(_useState9, 2),
8214
+ loadingSizes = _useState0[0],
8215
+ setLoadingSizes = _useState0[1];
8216
+ var _useState1 = React.useState(false),
8217
+ _useState10 = _slicedToArray(_useState1, 2),
8218
+ sizesError = _useState10[0],
8219
+ setSizesError = _useState10[1];
8220
+
8221
+ // Keep inputs in sync when store dimensions change externally
8222
+ React.useEffect(function () {
8223
+ setWidth(String(store.width));
8224
+ setHeight(String(store.height));
8225
+ }, [store.width, store.height]);
8226
+ React.useEffect(function () {
8227
+ if (!fetchSizes) return;
8228
+ setLoadingSizes(true);
8229
+ setSizesError(false);
8230
+ fetchSizes().then(function (res) {
8231
+ var _res$data;
8232
+ return setSizes(((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.sizes) || []);
8233
+ })["catch"](function () {
8234
+ return setSizesError(true);
8235
+ })["finally"](function () {
8236
+ return setLoadingSizes(false);
8237
+ });
8238
+ }, []);
8239
+ var wNum = parseInt(width, 10);
8240
+ var hNum = parseInt(height, 10);
8241
+ var isValid = wNum > 0 && hNum > 0 && Number.isFinite(wNum) && Number.isFinite(hNum);
8242
+ var handleResize = function handleResize() {
8243
+ if (!isValid || !store.activePage) return;
8244
+ if (scaleContent) {
8245
+ var ratioX = wNum / store.width;
8246
+ var ratioY = hNum / store.height;
8247
+ scaleElements(store.activePage.children, ratioX, ratioY);
8248
+ }
8249
+ store.setSize(wNum, hNum);
8250
+ };
8251
+ var handlePresetClick = function handlePresetClick(size) {
8252
+ var dpi = size.dpi || 96;
8253
+ var w = toPx(size.width, size.unit, dpi);
8254
+ var h = toPx(size.height, size.unit, dpi);
8255
+ if (w > 0) setWidth(String(w));
8256
+ if (h > 0) setHeight(String(h));
8257
+ };
8258
+ return /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
8259
+ sx: {
8260
+ p: 2,
8261
+ display: 'flex',
8262
+ flexDirection: 'column',
8263
+ gap: 2
8264
+ },
8265
+ children: [/*#__PURE__*/jsxRuntime.jsxs(material.Box, {
8266
+ children: [/*#__PURE__*/jsxRuntime.jsx(material.Typography, {
8267
+ sx: {
8268
+ fontWeight: 600,
8269
+ fontSize: 14,
8270
+ mb: 0.5
8271
+ },
8272
+ children: "Resize Canvas"
8273
+ }), /*#__PURE__*/jsxRuntime.jsxs(material.Typography, {
8274
+ sx: {
8275
+ fontSize: 12,
8276
+ color: '#888'
8277
+ },
8278
+ children: ["Current: ", store.width, " \xD7 ", store.height, " px"]
8279
+ })]
8280
+ }), /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
8281
+ sx: {
8282
+ display: 'flex',
8283
+ gap: 1.5
8284
+ },
8285
+ children: [/*#__PURE__*/jsxRuntime.jsx(material.TextField, {
8286
+ label: "Width (px)",
8287
+ type: "number",
8288
+ size: "small",
8289
+ value: width,
8290
+ onChange: function onChange(e) {
8291
+ return setWidth(e.target.value);
8292
+ },
8293
+ inputProps: {
8294
+ min: 1,
8295
+ step: 1
8296
+ },
8297
+ error: !!width && (isNaN(wNum) || wNum <= 0),
8298
+ sx: {
8299
+ flex: 1
8300
+ }
8301
+ }), /*#__PURE__*/jsxRuntime.jsx(material.TextField, {
8302
+ label: "Height (px)",
8303
+ type: "number",
8304
+ size: "small",
8305
+ value: height,
8306
+ onChange: function onChange(e) {
8307
+ return setHeight(e.target.value);
8308
+ },
8309
+ inputProps: {
8310
+ min: 1,
8311
+ step: 1
8312
+ },
8313
+ error: !!height && (isNaN(hNum) || hNum <= 0),
8314
+ sx: {
8315
+ flex: 1
8316
+ }
8317
+ })]
8318
+ }), /*#__PURE__*/jsxRuntime.jsx(material.FormControlLabel, {
8319
+ control: /*#__PURE__*/jsxRuntime.jsx(material.Switch, {
8320
+ checked: scaleContent,
8321
+ onChange: function onChange(e) {
8322
+ return setScaleContent(e.target.checked);
8323
+ },
8324
+ size: "small"
8325
+ }),
8326
+ label: /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
8327
+ sx: {
8328
+ fontSize: 13
8329
+ },
8330
+ children: "Scale content"
8331
+ })
8332
+ }), /*#__PURE__*/jsxRuntime.jsx(material.Button, {
8333
+ variant: "contained",
8334
+ disabled: !isValid || !store.activePage,
8335
+ onClick: handleResize,
8336
+ sx: {
8337
+ textTransform: 'uppercase',
8338
+ fontWeight: 700,
8339
+ letterSpacing: 1,
8340
+ backgroundColor: '#0d83cd',
8341
+ '&:hover': {
8342
+ backgroundColor: '#0a6fad'
8343
+ },
8344
+ '&.Mui-disabled': {
8345
+ opacity: 0.5
8346
+ }
8347
+ },
8348
+ children: "Resize"
8349
+ }), /*#__PURE__*/jsxRuntime.jsx(material.Divider, {}), /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
8350
+ sx: {
8351
+ fontWeight: 600,
8352
+ fontSize: 13,
8353
+ color: '#555'
8354
+ },
8355
+ children: "Preset sizes"
8356
+ }), loadingSizes && /*#__PURE__*/jsxRuntime.jsx(material.Box, {
8357
+ sx: {
8358
+ display: 'flex',
8359
+ justifyContent: 'center',
8360
+ py: 2
8361
+ },
8362
+ children: /*#__PURE__*/jsxRuntime.jsx(material.CircularProgress, {
8363
+ size: 22
8364
+ })
8365
+ }), sizesError && /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
8366
+ sx: {
8367
+ fontSize: 12,
8368
+ color: '#c44'
8369
+ },
8370
+ children: "Could not load sizes."
8371
+ }), !loadingSizes && !sizesError && sizes.length === 0 && /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
8372
+ sx: {
8373
+ fontSize: 12,
8374
+ color: '#aaa'
8375
+ },
8376
+ children: "No sizes available."
8377
+ }), !loadingSizes && !sizesError && sizes.map(function (size) {
8378
+ var dpi = size.dpi || 96;
8379
+ toPx(size.width, size.unit, dpi);
8380
+ toPx(size.height, size.unit, dpi);
8381
+ var dimLabel = size.width && size.height ? "".concat(size.width, " \xD7 ").concat(size.height, " ").concat((size.unit || 'px').toUpperCase()) : null;
8382
+ return /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
8383
+ onClick: function onClick() {
8384
+ return handlePresetClick(size);
8385
+ },
8386
+ sx: {
8387
+ display: 'flex',
8388
+ alignItems: 'center',
8389
+ justifyContent: 'space-between',
8390
+ px: 1.5,
8391
+ py: 0.75,
8392
+ borderRadius: '6px',
8393
+ cursor: 'pointer',
8394
+ border: '1px solid #e8e8e8',
8395
+ '&:hover': {
8396
+ backgroundColor: '#f0f7fd',
8397
+ borderColor: '#0d83cd'
8398
+ },
8399
+ transition: 'all 0.12s ease'
8400
+ },
8401
+ children: [/*#__PURE__*/jsxRuntime.jsx(material.Typography, {
8402
+ sx: {
8403
+ fontSize: 13,
8404
+ fontWeight: 500
8405
+ },
8406
+ children: size.name
8407
+ }), dimLabel && /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
8408
+ sx: {
8409
+ fontSize: 11,
8410
+ color: '#888',
8411
+ fontFamily: 'monospace'
8412
+ },
8413
+ children: dimLabel
8414
+ })]
8415
+ }, size.id);
8416
+ })]
8417
+ });
8418
+ });
8419
+
8160
8420
  var GOOGLE_FONTS_API = 'https://www.googleapis.com/webfonts/v1/webfonts';
8161
8421
  var cachedFonts = null;
8162
8422
  function fetchGoogleFonts(_x) {
@@ -11321,7 +11581,7 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11321
11581
  case 'radio':
11322
11582
  {
11323
11583
  var otherSelected = value === '__custom__';
11324
- return /*#__PURE__*/jsxRuntime.jsxs(material.Box, {
11584
+ return /*#__PURE__*/jsxRuntime.jsx(material.Box, {
11325
11585
  sx: {
11326
11586
  mt: 1,
11327
11587
  flex: 1,
@@ -11342,7 +11602,7 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11342
11602
  background: '#aaa'
11343
11603
  }
11344
11604
  },
11345
- children: [/*#__PURE__*/jsxRuntime.jsxs(material.RadioGroup, {
11605
+ children: /*#__PURE__*/jsxRuntime.jsxs(material.RadioGroup, {
11346
11606
  value: value,
11347
11607
  onChange: function onChange(e) {
11348
11608
  return setValue(e.target.value);
@@ -11350,7 +11610,73 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11350
11610
  sx: {
11351
11611
  gap: 1
11352
11612
  },
11353
- children: [options.map(function (opt) {
11613
+ children: [/*#__PURE__*/jsxRuntime.jsxs(material.Box, {
11614
+ sx: {
11615
+ display: 'flex',
11616
+ flexDirection: 'column'
11617
+ },
11618
+ children: [/*#__PURE__*/jsxRuntime.jsx(material.FormControlLabel, {
11619
+ value: "__custom__",
11620
+ control: /*#__PURE__*/jsxRuntime.jsx(material.Radio, {
11621
+ sx: {
11622
+ color: '#d0d5dd',
11623
+ '&.Mui-checked': {
11624
+ color: accentColor
11625
+ }
11626
+ }
11627
+ }),
11628
+ label: /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
11629
+ sx: {
11630
+ fontSize: 18
11631
+ },
11632
+ children: t('inputFieldsDialog.other', 'Other')
11633
+ }),
11634
+ sx: {
11635
+ m: 0,
11636
+ border: '1px solid',
11637
+ borderColor: otherSelected ? accentColor : '#d0d5dd',
11638
+ borderRadius: otherSelected ? '8px 8px 0 0' : '8px',
11639
+ borderBottom: otherSelected ? 'none' : undefined,
11640
+ px: 2,
11641
+ py: 0.75,
11642
+ transition: 'border-color 0.15s ease, border-radius 0.15s ease',
11643
+ backgroundColor: otherSelected ? 'rgba(13,131,205,0.04)' : 'transparent',
11644
+ '&:hover': {
11645
+ borderColor: accentColor,
11646
+ backgroundColor: 'rgba(13,131,205,0.03)'
11647
+ }
11648
+ }
11649
+ }), otherSelected && /*#__PURE__*/jsxRuntime.jsx(material.TextField, {
11650
+ autoFocus: true,
11651
+ fullWidth: true,
11652
+ value: customRadioValue,
11653
+ onChange: function onChange(e) {
11654
+ return setCustomRadioValue(e.target.value);
11655
+ },
11656
+ onKeyDown: function onKeyDown(e) {
11657
+ if (e.key === 'Enter' && customRadioValue.trim()) handleSubmit();
11658
+ },
11659
+ placeholder: t('inputFieldsDialog.otherPlaceholder', 'Type your answer…'),
11660
+ sx: {
11661
+ '& .MuiOutlinedInput-root': {
11662
+ borderRadius: '0 0 8px 8px',
11663
+ fontSize: 18,
11664
+ '& fieldset': {
11665
+ borderColor: accentColor,
11666
+ borderTopColor: 'transparent'
11667
+ },
11668
+ '&:hover fieldset': {
11669
+ borderColor: accentColor,
11670
+ borderTopColor: 'transparent'
11671
+ },
11672
+ '&.Mui-focused fieldset': {
11673
+ borderColor: accentColor,
11674
+ borderTopColor: 'transparent'
11675
+ }
11676
+ }
11677
+ }
11678
+ })]
11679
+ }), options.map(function (opt) {
11354
11680
  return /*#__PURE__*/jsxRuntime.jsx(material.FormControlLabel, {
11355
11681
  value: opt,
11356
11682
  control: /*#__PURE__*/jsxRuntime.jsx(material.Radio, {
@@ -11382,68 +11708,8 @@ var SingleFieldDialog = function SingleFieldDialog(_ref) {
11382
11708
  }
11383
11709
  }
11384
11710
  }, opt);
11385
- }), /*#__PURE__*/jsxRuntime.jsx(material.FormControlLabel, {
11386
- value: "__custom__",
11387
- control: /*#__PURE__*/jsxRuntime.jsx(material.Radio, {
11388
- sx: {
11389
- color: '#d0d5dd',
11390
- '&.Mui-checked': {
11391
- color: accentColor
11392
- }
11393
- }
11394
- }),
11395
- label: /*#__PURE__*/jsxRuntime.jsx(material.Typography, {
11396
- sx: {
11397
- fontSize: 18
11398
- },
11399
- children: t('inputFieldsDialog.other', 'Other')
11400
- }),
11401
- sx: {
11402
- m: 0,
11403
- border: '1px solid',
11404
- borderColor: otherSelected ? accentColor : '#d0d5dd',
11405
- borderRadius: otherSelected ? '8px 8px 0 0' : '8px',
11406
- borderBottom: otherSelected ? 'none' : undefined,
11407
- px: 2,
11408
- py: 0.75,
11409
- transition: 'border-color 0.15s ease, border-radius 0.15s ease',
11410
- backgroundColor: otherSelected ? 'rgba(13,131,205,0.04)' : 'transparent',
11411
- '&:hover': {
11412
- borderColor: accentColor,
11413
- backgroundColor: 'rgba(13,131,205,0.03)'
11414
- }
11415
- }
11416
11711
  })]
11417
- }), otherSelected && /*#__PURE__*/jsxRuntime.jsx(material.TextField, {
11418
- autoFocus: true,
11419
- fullWidth: true,
11420
- value: customRadioValue,
11421
- onChange: function onChange(e) {
11422
- return setCustomRadioValue(e.target.value);
11423
- },
11424
- onKeyDown: function onKeyDown(e) {
11425
- if (e.key === 'Enter' && customRadioValue.trim()) handleSubmit();
11426
- },
11427
- placeholder: t('inputFieldsDialog.otherPlaceholder', 'Type your answer…'),
11428
- sx: {
11429
- '& .MuiOutlinedInput-root': {
11430
- borderRadius: '0 0 8px 8px',
11431
- fontSize: 18,
11432
- '& fieldset': {
11433
- borderColor: accentColor,
11434
- borderTopColor: 'transparent'
11435
- },
11436
- '&:hover fieldset': {
11437
- borderColor: accentColor,
11438
- borderTopColor: 'transparent'
11439
- },
11440
- '&.Mui-focused fieldset': {
11441
- borderColor: accentColor,
11442
- borderTopColor: 'transparent'
11443
- }
11444
- }
11445
- }
11446
- })]
11712
+ })
11447
11713
  });
11448
11714
  }
11449
11715
  case 'list':