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 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) {