labellife-design-tool 2.4.4 → 2.4.6

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.
@@ -394,6 +394,25 @@ if (typeof window !== 'undefined' && !window[INPUT_FIELDS_CONFIG_KEY]) {
394
394
  window[INPUT_FIELDS_CONFIG_KEY] = {};
395
395
  }
396
396
 
397
+ // Cover-fit SIZE (no cropping) for an image of natural size over a box of given size.
398
+ // The image is scaled to the smallest size that fully covers the box, preserving aspect
399
+ // ratio — one dimension matches the box, the other is larger and overflows the box
400
+ // (centered overflow on both sides).
401
+ function coverFitSize(boxWidth, boxHeight, naturalWidth, naturalHeight) {
402
+ var boxAspect = boxWidth / boxHeight;
403
+ var imgAspect = naturalWidth / naturalHeight;
404
+ if (imgAspect > boxAspect) {
405
+ return {
406
+ width: boxHeight * imgAspect,
407
+ height: boxHeight
408
+ };
409
+ }
410
+ return {
411
+ width: boxWidth,
412
+ height: boxWidth / imgAspect
413
+ };
414
+ }
415
+
397
416
  var SliderRow = function SliderRow(_ref) {
398
417
  var label = _ref.label,
399
418
  value = _ref.value,
@@ -1161,7 +1180,7 @@ var toolbarBtnSx = {
1161
1180
 
1162
1181
  // Image-specific toolbar
1163
1182
  var ImageToolbar = observer(function (_ref5) {
1164
- var _store$_toolbarPanel5, _store$_toolbarPanel6;
1183
+ var _store$_toolbarPanel6, _store$_toolbarPanel7;
1165
1184
  var element = _ref5.element,
1166
1185
  store = _ref5.store;
1167
1186
  var _useState = useState(null),
@@ -1183,6 +1202,11 @@ var ImageToolbar = observer(function (_ref5) {
1183
1202
  setFlipAnchor(null);
1184
1203
  };
1185
1204
  var handleCrop = function handleCrop() {
1205
+ var _store$_toolbarPanel3;
1206
+ if (((_store$_toolbarPanel3 = store._toolbarPanel) === null || _store$_toolbarPanel3 === void 0 ? void 0 : _store$_toolbarPanel3.type) === 'crop') {
1207
+ store.closeToolbarPanel();
1208
+ return;
1209
+ }
1186
1210
  if (!element._naturalWidth || !element._naturalHeight) return;
1187
1211
  element.enterCropMode();
1188
1212
  if (element._cropModeEnabled) {
@@ -1190,17 +1214,37 @@ var ImageToolbar = observer(function (_ref5) {
1190
1214
  }
1191
1215
  };
1192
1216
  var handleFitToPage = function handleFitToPage() {
1193
- element.set({
1194
- x: 0,
1195
- y: 0,
1196
- width: store.width,
1197
- height: store.height
1198
- });
1217
+ // Cover-fit: scale the photo (preserving aspect ratio, never stretched) to the
1218
+ // smallest size that fully covers the page, centered. No crop is applied — if the
1219
+ // aspect ratio doesn't match the page, the image simply overflows the page bounds
1220
+ // on two sides (same as manually resizing it to cover), rather than permanently
1221
+ // cropping away image data.
1222
+ var updates = {
1223
+ cropX: 0,
1224
+ cropY: 0,
1225
+ cropWidth: 1,
1226
+ cropHeight: 1
1227
+ };
1228
+ if (element._naturalWidth && element._naturalHeight) {
1229
+ var _coverFitSize = coverFitSize(store.width, store.height, element._naturalWidth, element._naturalHeight),
1230
+ width = _coverFitSize.width,
1231
+ height = _coverFitSize.height;
1232
+ updates.width = width;
1233
+ updates.height = height;
1234
+ updates.x = (store.width - width) / 2;
1235
+ updates.y = (store.height - height) / 2;
1236
+ } else {
1237
+ updates.x = 0;
1238
+ updates.y = 0;
1239
+ updates.width = store.width;
1240
+ updates.height = store.height;
1241
+ }
1242
+ element.set(updates);
1199
1243
  store.history.addUndoState();
1200
1244
  };
1201
1245
  var handleEffects = function handleEffects() {
1202
- var _store$_toolbarPanel3;
1203
- if (((_store$_toolbarPanel3 = store._toolbarPanel) === null || _store$_toolbarPanel3 === void 0 ? void 0 : _store$_toolbarPanel3.type) === 'effects') {
1246
+ var _store$_toolbarPanel4;
1247
+ if (((_store$_toolbarPanel4 = store._toolbarPanel) === null || _store$_toolbarPanel4 === void 0 ? void 0 : _store$_toolbarPanel4.type) === 'effects') {
1204
1248
  store.closeToolbarPanel();
1205
1249
  } else {
1206
1250
  store.openToolbarPanel('effects');
@@ -1213,8 +1257,8 @@ var ImageToolbar = observer(function (_ref5) {
1213
1257
  });
1214
1258
  store.history.addUndoState();
1215
1259
  } else {
1216
- var _store$_toolbarPanel4;
1217
- if (((_store$_toolbarPanel4 = store._toolbarPanel) === null || _store$_toolbarPanel4 === void 0 ? void 0 : _store$_toolbarPanel4.type) === 'mask') {
1260
+ var _store$_toolbarPanel5;
1261
+ if (((_store$_toolbarPanel5 = store._toolbarPanel) === null || _store$_toolbarPanel5 === void 0 ? void 0 : _store$_toolbarPanel5.type) === 'mask') {
1218
1262
  store.closeToolbarPanel();
1219
1263
  } else {
1220
1264
  store.openToolbarPanel('mask');
@@ -1292,7 +1336,7 @@ var ImageToolbar = observer(function (_ref5) {
1292
1336
  })]
1293
1337
  }), /*#__PURE__*/jsx(Button, {
1294
1338
  size: "small",
1295
- sx: _objectSpread2(_objectSpread2({}, toolbarBtnSx), ((_store$_toolbarPanel5 = store._toolbarPanel) === null || _store$_toolbarPanel5 === void 0 ? void 0 : _store$_toolbarPanel5.type) === 'effects' ? {
1339
+ sx: _objectSpread2(_objectSpread2({}, toolbarBtnSx), ((_store$_toolbarPanel6 = store._toolbarPanel) === null || _store$_toolbarPanel6 === void 0 ? void 0 : _store$_toolbarPanel6.type) === 'effects' ? {
1296
1340
  backgroundColor: '#e3f2fd',
1297
1341
  color: '#0d83cd'
1298
1342
  } : {}),
@@ -1312,7 +1356,7 @@ var ImageToolbar = observer(function (_ref5) {
1312
1356
  size: "small",
1313
1357
  sx: _objectSpread2(_objectSpread2(_objectSpread2({}, toolbarBtnSx), hasMask ? {
1314
1358
  color: '#d32f2f'
1315
- } : {}), ((_store$_toolbarPanel6 = store._toolbarPanel) === null || _store$_toolbarPanel6 === void 0 ? void 0 : _store$_toolbarPanel6.type) === 'mask' ? {
1359
+ } : {}), ((_store$_toolbarPanel7 = store._toolbarPanel) === null || _store$_toolbarPanel7 === void 0 ? void 0 : _store$_toolbarPanel7.type) === 'mask' ? {
1316
1360
  backgroundColor: '#e3f2fd',
1317
1361
  color: '#0d83cd'
1318
1362
  } : {}),