labellife-design-tool 2.2.9 → 2.3.1

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.
@@ -1,6 +1,6 @@
1
1
  import React, { useState, useCallback, memo, useRef, useEffect } from 'react';
2
2
  import { observer } from 'mobx-react-lite';
3
- import { Autocomplete, TextField, Divider, Tooltip, IconButton, ToggleButtonGroup, ToggleButton, Button, Menu, MenuItem, ListItemIcon, ListItemText, Box, Typography, Slider, Popover, Select, CircularProgress } from '@mui/material';
3
+ import { Autocomplete, TextField, Divider, Tooltip, IconButton, ToggleButtonGroup, ToggleButton, Button, Menu, MenuItem, ListItemIcon, ListItemText, Box, Typography, Popover, Slider, Select, CircularProgress } from '@mui/material';
4
4
  import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
5
5
  import FileUploadIcon from '@mui/icons-material/FileUpload';
6
6
  import UndoIcon from '@mui/icons-material/Undo';
@@ -23,6 +23,15 @@ import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
23
23
  import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome';
24
24
  import SwapHorizIcon from '@mui/icons-material/SwapHoriz';
25
25
  import SwapVertIcon from '@mui/icons-material/SwapVert';
26
+ import OpenWithIcon from '@mui/icons-material/OpenWith';
27
+ import '@mui/icons-material/AlignHorizontalLeft';
28
+ import '@mui/icons-material/AlignHorizontalCenter';
29
+ import '@mui/icons-material/AlignHorizontalRight';
30
+ import '@mui/icons-material/AlignVerticalTop';
31
+ import '@mui/icons-material/AlignVerticalCenter';
32
+ import '@mui/icons-material/AlignVerticalBottom';
33
+ import VerticalAlignTopIcon from '@mui/icons-material/VerticalAlignTop';
34
+ import VerticalAlignBottomIcon from '@mui/icons-material/VerticalAlignBottom';
26
35
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
27
36
 
28
37
  function _arrayLikeToArray(r, a) {
@@ -384,6 +393,21 @@ if (typeof window !== 'undefined' && !window[INPUT_FIELDS_CONFIG_KEY]) {
384
393
  }
385
394
 
386
395
  var _excluded = ["fontFamily"];
396
+ var _positionMenuItemSx = {
397
+ textTransform: 'none',
398
+ fontSize: 12,
399
+ fontWeight: 400,
400
+ color: '#333',
401
+ justifyContent: 'flex-start',
402
+ px: 1,
403
+ py: 0.6,
404
+ minWidth: 0,
405
+ '&:hover': {
406
+ backgroundColor: 'rgba(13,131,205,0.08)'
407
+ }
408
+ };
409
+
410
+ // ── Font preview: lightweight Google Font subsets for dropdown ──
387
411
  var _fontPreviewLoaded = new Set();
388
412
  function loadFontPreview(fontFamily) {
389
413
  if (_fontPreviewLoaded.has(fontFamily)) return;
@@ -1064,10 +1088,270 @@ var LineToolbar = observer(function (_ref7) {
1064
1088
  });
1065
1089
  });
1066
1090
 
1067
- // Common controls for all element types
1068
- var CommonControls = observer(function (_ref8) {
1091
+ // Position + alignment popover button
1092
+ var PositionButton = observer(function (_ref8) {
1069
1093
  var element = _ref8.element,
1070
1094
  store = _ref8.store;
1095
+ var _useState3 = useState(null),
1096
+ _useState4 = _slicedToArray(_useState3, 2),
1097
+ anchorEl = _useState4[0],
1098
+ setAnchorEl = _useState4[1];
1099
+ var open = Boolean(anchorEl);
1100
+ var pageW = store.width;
1101
+ var pageH = store.height;
1102
+ var alignEl = function alignEl(xVal, yVal) {
1103
+ var attrs = {};
1104
+ if (xVal !== null) attrs.x = xVal;
1105
+ if (yVal !== null) attrs.y = yVal;
1106
+ element.set(attrs);
1107
+ store.history.addUndoState();
1108
+ };
1109
+ var layer = function layer(fn) {
1110
+ fn();
1111
+ store.history.addUndoState();
1112
+ };
1113
+ return /*#__PURE__*/jsxs(Fragment, {
1114
+ children: [/*#__PURE__*/jsx(Button, {
1115
+ size: "small",
1116
+ onClick: function onClick(e) {
1117
+ return setAnchorEl(e.currentTarget);
1118
+ },
1119
+ startIcon: /*#__PURE__*/jsx(OpenWithIcon, {
1120
+ sx: {
1121
+ fontSize: '16px !important'
1122
+ }
1123
+ }),
1124
+ sx: _objectSpread2({
1125
+ textTransform: 'none',
1126
+ fontSize: 12,
1127
+ whiteSpace: 'nowrap',
1128
+ px: 1.5,
1129
+ minWidth: 'auto'
1130
+ }, open ? {
1131
+ backgroundColor: '#e3f2fd',
1132
+ color: '#0d83cd'
1133
+ } : {}),
1134
+ children: t('toolbar.position', 'Position')
1135
+ }), /*#__PURE__*/jsxs(Popover, {
1136
+ open: open,
1137
+ anchorEl: anchorEl,
1138
+ onClose: function onClose() {
1139
+ return setAnchorEl(null);
1140
+ },
1141
+ anchorOrigin: {
1142
+ vertical: 'bottom',
1143
+ horizontal: 'left'
1144
+ },
1145
+ transformOrigin: {
1146
+ vertical: 'top',
1147
+ horizontal: 'left'
1148
+ },
1149
+ slotProps: {
1150
+ paper: {
1151
+ sx: {
1152
+ mt: 0.5,
1153
+ p: 2,
1154
+ width: 300,
1155
+ borderRadius: '10px',
1156
+ boxShadow: '0 4px 20px rgba(0,0,0,0.12)'
1157
+ }
1158
+ }
1159
+ },
1160
+ children: [/*#__PURE__*/jsx(Typography, {
1161
+ variant: "caption",
1162
+ sx: {
1163
+ fontWeight: 700,
1164
+ color: '#111',
1165
+ display: 'block',
1166
+ mb: 1,
1167
+ fontSize: 12
1168
+ },
1169
+ children: t('toolbar.layering', 'Layer order')
1170
+ }), /*#__PURE__*/jsxs(Box, {
1171
+ sx: {
1172
+ display: 'grid',
1173
+ gridTemplateColumns: '1fr 1fr',
1174
+ gap: 0.5,
1175
+ mb: 2
1176
+ },
1177
+ children: [/*#__PURE__*/jsx(Button, {
1178
+ size: "small",
1179
+ startIcon: /*#__PURE__*/jsx(ArrowUpwardIcon, {}),
1180
+ onClick: function onClick() {
1181
+ return layer(function () {
1182
+ return element.moveUp();
1183
+ });
1184
+ },
1185
+ sx: _positionMenuItemSx,
1186
+ children: t('toolbar.up', 'Up')
1187
+ }), /*#__PURE__*/jsx(Button, {
1188
+ size: "small",
1189
+ startIcon: /*#__PURE__*/jsx(ArrowDownwardIcon, {}),
1190
+ onClick: function onClick() {
1191
+ return layer(function () {
1192
+ return element.moveDown();
1193
+ });
1194
+ },
1195
+ sx: _positionMenuItemSx,
1196
+ children: t('toolbar.down', 'Down')
1197
+ }), /*#__PURE__*/jsx(Button, {
1198
+ size: "small",
1199
+ startIcon: /*#__PURE__*/jsx(VerticalAlignTopIcon, {}),
1200
+ onClick: function onClick() {
1201
+ return layer(function () {
1202
+ return element.moveTop();
1203
+ });
1204
+ },
1205
+ sx: _positionMenuItemSx,
1206
+ children: t('toolbar.toForward', 'To front')
1207
+ }), /*#__PURE__*/jsx(Button, {
1208
+ size: "small",
1209
+ startIcon: /*#__PURE__*/jsx(VerticalAlignBottomIcon, {}),
1210
+ onClick: function onClick() {
1211
+ return layer(function () {
1212
+ return element.moveBottom();
1213
+ });
1214
+ },
1215
+ sx: _positionMenuItemSx,
1216
+ children: t('toolbar.toBottom', 'To back')
1217
+ })]
1218
+ }), /*#__PURE__*/jsx(Divider, {
1219
+ sx: {
1220
+ mb: 1.5
1221
+ }
1222
+ }), /*#__PURE__*/jsx(Typography, {
1223
+ variant: "caption",
1224
+ sx: {
1225
+ fontWeight: 700,
1226
+ color: '#111',
1227
+ display: 'block',
1228
+ mb: 1,
1229
+ fontSize: 12
1230
+ },
1231
+ children: t('toolbar.position', 'Position')
1232
+ }), function () {
1233
+ var cx = (pageW - element.width) / 2;
1234
+ var cy = (pageH - element.height) / 2;
1235
+ var rx = pageW - element.width;
1236
+ var by = pageH - element.height;
1237
+ var positions = [{
1238
+ label: 'Top left',
1239
+ x: 0,
1240
+ y: 0,
1241
+ row: 0,
1242
+ col: 0
1243
+ }, {
1244
+ label: 'Top center',
1245
+ x: cx,
1246
+ y: 0,
1247
+ row: 0,
1248
+ col: 1
1249
+ }, {
1250
+ label: 'Top right',
1251
+ x: rx,
1252
+ y: 0,
1253
+ row: 0,
1254
+ col: 2
1255
+ }, {
1256
+ label: 'Middle left',
1257
+ x: 0,
1258
+ y: cy,
1259
+ row: 1,
1260
+ col: 0
1261
+ }, {
1262
+ label: 'Center',
1263
+ x: cx,
1264
+ y: cy,
1265
+ row: 1,
1266
+ col: 1
1267
+ }, {
1268
+ label: 'Middle right',
1269
+ x: rx,
1270
+ y: cy,
1271
+ row: 1,
1272
+ col: 2
1273
+ }, {
1274
+ label: 'Bottom left',
1275
+ x: 0,
1276
+ y: by,
1277
+ row: 2,
1278
+ col: 0
1279
+ }, {
1280
+ label: 'Bottom center',
1281
+ x: cx,
1282
+ y: by,
1283
+ row: 2,
1284
+ col: 1
1285
+ }, {
1286
+ label: 'Bottom right',
1287
+ x: rx,
1288
+ y: by,
1289
+ row: 2,
1290
+ col: 2
1291
+ }];
1292
+ return /*#__PURE__*/jsx(Box, {
1293
+ sx: {
1294
+ display: 'grid',
1295
+ gridTemplateColumns: 'repeat(3, 1fr)',
1296
+ gap: 0.5
1297
+ },
1298
+ children: positions.map(function (_ref9) {
1299
+ var label = _ref9.label,
1300
+ x = _ref9.x,
1301
+ y = _ref9.y;
1302
+ return /*#__PURE__*/jsx(Tooltip, {
1303
+ title: label,
1304
+ placement: "top",
1305
+ children: /*#__PURE__*/jsx(IconButton, {
1306
+ size: "small",
1307
+ onClick: function onClick() {
1308
+ return alignEl(x, y);
1309
+ },
1310
+ sx: {
1311
+ borderRadius: '6px',
1312
+ border: '1px solid #e0e0e0',
1313
+ p: 0.75,
1314
+ '&:hover': {
1315
+ backgroundColor: 'rgba(13,131,205,0.08)',
1316
+ borderColor: '#0d83cd'
1317
+ }
1318
+ },
1319
+ children: /*#__PURE__*/jsx(Box, {
1320
+ sx: {
1321
+ display: 'grid',
1322
+ gridTemplateColumns: 'repeat(3, 5px)',
1323
+ gap: '2px'
1324
+ },
1325
+ children: [0, 1, 2].map(function (r) {
1326
+ return [0, 1, 2].map(function (c) {
1327
+ return /*#__PURE__*/jsx(Box, {
1328
+ sx: {
1329
+ width: 5,
1330
+ height: 5,
1331
+ borderRadius: '1px',
1332
+ backgroundColor: r === positions.find(function (p) {
1333
+ return p.label === label;
1334
+ }).row && c === positions.find(function (p) {
1335
+ return p.label === label;
1336
+ }).col ? '#0d83cd' : '#ccc'
1337
+ }
1338
+ }, "".concat(r, "-").concat(c));
1339
+ });
1340
+ })
1341
+ })
1342
+ })
1343
+ }, label);
1344
+ })
1345
+ });
1346
+ }()]
1347
+ })]
1348
+ });
1349
+ });
1350
+
1351
+ // Common controls for all element types
1352
+ var CommonControls = observer(function (_ref0) {
1353
+ var element = _ref0.element,
1354
+ store = _ref0.store;
1071
1355
  var isLocked = element.locked;
1072
1356
  var handleDuplicate = function handleDuplicate() {
1073
1357
  if (element.clone) {
@@ -1108,14 +1392,6 @@ var CommonControls = observer(function (_ref8) {
1108
1392
  var handleOpacityCommit = function handleOpacityCommit() {
1109
1393
  store.history.addUndoState();
1110
1394
  };
1111
- var handleMoveUp = function handleMoveUp() {
1112
- element.moveUp();
1113
- store.history.addUndoState();
1114
- };
1115
- var handleMoveDown = function handleMoveDown() {
1116
- element.moveDown();
1117
- store.history.addUndoState();
1118
- };
1119
1395
  return /*#__PURE__*/jsxs(Fragment, {
1120
1396
  children: [/*#__PURE__*/jsx(Tooltip, {
1121
1397
  title: t('toolbar.opacity', 'Opacity'),
@@ -1150,24 +1426,9 @@ var CommonControls = observer(function (_ref8) {
1150
1426
  sx: {
1151
1427
  mx: 0.5
1152
1428
  }
1153
- }), /*#__PURE__*/jsx(Tooltip, {
1154
- title: t('toolbar.up', 'Move up'),
1155
- children: /*#__PURE__*/jsx(IconButton, {
1156
- size: "small",
1157
- onClick: handleMoveUp,
1158
- children: /*#__PURE__*/jsx(ArrowUpwardIcon, {
1159
- fontSize: "small"
1160
- })
1161
- })
1162
- }), /*#__PURE__*/jsx(Tooltip, {
1163
- title: t('toolbar.down', 'Move down'),
1164
- children: /*#__PURE__*/jsx(IconButton, {
1165
- size: "small",
1166
- onClick: handleMoveDown,
1167
- children: /*#__PURE__*/jsx(ArrowDownwardIcon, {
1168
- fontSize: "small"
1169
- })
1170
- })
1429
+ }), /*#__PURE__*/jsx(PositionButton, {
1430
+ element: element,
1431
+ store: store
1171
1432
  }), /*#__PURE__*/jsx(Divider, {
1172
1433
  orientation: "vertical",
1173
1434
  flexItem: true,
@@ -1211,26 +1472,26 @@ var CommonControls = observer(function (_ref8) {
1211
1472
  });
1212
1473
 
1213
1474
  // Download button with format/quality popover
1214
- var DefaultDownloadButton = observer(function (_ref9) {
1215
- var store = _ref9.store;
1216
- var _useState3 = useState(null),
1217
- _useState4 = _slicedToArray(_useState3, 2),
1218
- anchorEl = _useState4[0],
1219
- setAnchorEl = _useState4[1];
1220
- var _useState5 = useState('png'),
1475
+ var DefaultDownloadButton = observer(function (_ref1) {
1476
+ var store = _ref1.store;
1477
+ var _useState5 = useState(null),
1221
1478
  _useState6 = _slicedToArray(_useState5, 2),
1222
- fileType = _useState6[0],
1223
- setFileType = _useState6[1];
1479
+ anchorEl = _useState6[0],
1480
+ setAnchorEl = _useState6[1];
1481
+ var _useState7 = useState('png'),
1482
+ _useState8 = _slicedToArray(_useState7, 2),
1483
+ fileType = _useState8[0],
1484
+ setFileType = _useState8[1];
1224
1485
  // Default quality so pixelRatio=1 (output = template's own pixel size).
1225
1486
  // qualityToPixelRatio(q) = q * 3, so q = 1/3 → pixelRatio = 1.
1226
- var _useState7 = useState(1 / 3),
1227
- _useState8 = _slicedToArray(_useState7, 2),
1228
- quality = _useState8[0],
1229
- setQuality = _useState8[1];
1230
- var _useState9 = useState(false),
1487
+ var _useState9 = useState(1 / 3),
1231
1488
  _useState0 = _slicedToArray(_useState9, 2),
1232
- exporting = _useState0[0],
1233
- setExporting = _useState0[1];
1489
+ quality = _useState0[0],
1490
+ setQuality = _useState0[1];
1491
+ var _useState1 = useState(false),
1492
+ _useState10 = _slicedToArray(_useState1, 2),
1493
+ exporting = _useState10[0],
1494
+ setExporting = _useState10[1];
1234
1495
  var open = Boolean(anchorEl);
1235
1496
  var handleClick = function handleClick(e) {
1236
1497
  setAnchorEl(e.currentTarget);
@@ -1463,15 +1724,15 @@ var DefaultDownloadButton = observer(function (_ref9) {
1463
1724
  });
1464
1725
 
1465
1726
  // Import button — loads a JSON template file into the store
1466
- var DefaultImportButton = observer(function (_ref1) {
1467
- var store = _ref1.store;
1468
- var _useState1 = useState(false),
1469
- _useState10 = _slicedToArray(_useState1, 2),
1470
- importing = _useState10[0],
1471
- setImporting = _useState10[1];
1727
+ var DefaultImportButton = observer(function (_ref11) {
1728
+ var store = _ref11.store;
1729
+ var _useState11 = useState(false),
1730
+ _useState12 = _slicedToArray(_useState11, 2),
1731
+ importing = _useState12[0],
1732
+ setImporting = _useState12[1];
1472
1733
  var fileInputRef = React.useRef(null);
1473
1734
  var handleFileChange = useCallback(/*#__PURE__*/function () {
1474
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
1735
+ var _ref12 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
1475
1736
  var _e$target$files;
1476
1737
  var file, text, jsonData, _t3;
1477
1738
  return _regenerator().w(function (_context2) {
@@ -1509,7 +1770,7 @@ var DefaultImportButton = observer(function (_ref1) {
1509
1770
  }, _callee2, null, [[2, 4, 5, 6]]);
1510
1771
  }));
1511
1772
  return function (_x) {
1512
- return _ref10.apply(this, arguments);
1773
+ return _ref12.apply(this, arguments);
1513
1774
  };
1514
1775
  }(), [store]);
1515
1776
  return /*#__PURE__*/jsxs(Fragment, {
@@ -1575,10 +1836,10 @@ var rowSx = {
1575
1836
  display: 'none'
1576
1837
  }
1577
1838
  };
1578
- var Toolbar = observer(function (_ref11) {
1579
- var store = _ref11.store,
1580
- _ref11$components = _ref11.components,
1581
- components = _ref11$components === void 0 ? {} : _ref11$components;
1839
+ var Toolbar = observer(function (_ref13) {
1840
+ var store = _ref13.store,
1841
+ _ref13$components = _ref13.components,
1842
+ components = _ref13$components === void 0 ? {} : _ref13$components;
1582
1843
  var ActionControls = components.ActionControls;
1583
1844
  var ImportButton = 'ImportButton' in components ? components.ImportButton : DefaultImportButton;
1584
1845
  var DownloadButton = 'DownloadButton' in components ? components.DownloadButton : DefaultDownloadButton;