labellife-design-tool 2.5.2 → 2.5.4

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.
@@ -413,6 +413,35 @@ function coverFitSize(boxWidth, boxHeight, naturalWidth, naturalHeight) {
413
413
  };
414
414
  }
415
415
 
416
+ // Minimum axis-aligned (pre-rotation) box size that, once rotated by rotationDeg around
417
+ // its own center, still fully covers a boxWidth x boxHeight area. Used so "Fit to page"
418
+ // can keep an image's existing rotation instead of resetting it — the unrotated image is
419
+ // sized against this larger box instead of the page itself.
420
+ function rotatedCoverBox(boxWidth, boxHeight, rotationDeg) {
421
+ var rad = rotationDeg * Math.PI / 180;
422
+ var cos = Math.abs(Math.cos(rad));
423
+ var sin = Math.abs(Math.sin(rad));
424
+ return {
425
+ width: boxWidth * cos + boxHeight * sin,
426
+ height: boxWidth * sin + boxHeight * cos
427
+ };
428
+ }
429
+
430
+ // Top-left (x, y) position such that a width x height rect, rotated by rotationDeg using
431
+ // Konva's convention (rotation pivots around (x, y), i.e. the rect's own pre-rotation
432
+ // top-left corner, not its center), ends up centered within a boxWidth x boxHeight area.
433
+ function centerRotatedPosition(boxWidth, boxHeight, width, height, rotationDeg) {
434
+ var rad = rotationDeg * Math.PI / 180;
435
+ var cos = Math.cos(rad);
436
+ var sin = Math.sin(rad);
437
+ var halfWidth = width / 2;
438
+ var halfHeight = height / 2;
439
+ return {
440
+ x: boxWidth / 2 - (halfWidth * cos - halfHeight * sin),
441
+ y: boxHeight / 2 - (halfWidth * sin + halfHeight * cos)
442
+ };
443
+ }
444
+
416
445
  var SliderRow = function SliderRow(_ref) {
417
446
  var label = _ref.label,
418
447
  value = _ref.value,
@@ -1239,27 +1268,32 @@ var ImageToolbar = observer(function (_ref5) {
1239
1268
  // smallest size that fully covers the page, centered. No crop is applied — if the
1240
1269
  // aspect ratio doesn't match the page, the image simply overflows the page bounds
1241
1270
  // on two sides (same as manually resizing it to cover), rather than permanently
1242
- // cropping away image data.
1271
+ // cropping away image data. Existing rotation is kept as-is (not reset) — the fit is
1272
+ // computed against the larger box a rotated rect needs to still cover the (unrotated)
1273
+ // page, so a rotated image stays rotated and centered instead of flying off-canvas.
1274
+ var rotation = element.rotation || 0;
1243
1275
  var updates = {
1244
1276
  cropX: 0,
1245
1277
  cropY: 0,
1246
1278
  cropWidth: 1,
1247
1279
  cropHeight: 1
1248
1280
  };
1281
+ var required = rotatedCoverBox(store.width, store.height, rotation);
1249
1282
  if (element._naturalWidth && element._naturalHeight) {
1250
- var _coverFitSize = coverFitSize(store.width, store.height, element._naturalWidth, element._naturalHeight),
1283
+ var _coverFitSize = coverFitSize(required.width, required.height, element._naturalWidth, element._naturalHeight),
1251
1284
  width = _coverFitSize.width,
1252
1285
  height = _coverFitSize.height;
1253
1286
  updates.width = width;
1254
1287
  updates.height = height;
1255
- updates.x = (store.width - width) / 2;
1256
- updates.y = (store.height - height) / 2;
1257
1288
  } else {
1258
- updates.x = 0;
1259
- updates.y = 0;
1260
- updates.width = store.width;
1261
- updates.height = store.height;
1289
+ updates.width = required.width;
1290
+ updates.height = required.height;
1262
1291
  }
1292
+ var _centerRotatedPositio = centerRotatedPosition(store.width, store.height, updates.width, updates.height, rotation),
1293
+ x = _centerRotatedPositio.x,
1294
+ y = _centerRotatedPositio.y;
1295
+ updates.x = x;
1296
+ updates.y = y;
1263
1297
  element.set(updates);
1264
1298
  store.history.addUndoState();
1265
1299
  };