@anu3ev/fabric-image-editor 0.9.4 → 0.9.5

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.
Files changed (2) hide show
  1. package/dist/main.js +59 -47
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -2322,8 +2322,15 @@ var tt = class e extends l {
2322
2322
  _hideIndicator() {
2323
2323
  this.indicator.hide();
2324
2324
  }
2325
- static _resolveDisplaySize({ target: e }) {
2326
- let t = Math.abs(e.getScaledWidth()), n = Math.abs(e.getScaledHeight());
2325
+ static _resolveDisplaySize({ target: t }) {
2326
+ let n = t.getObjectDisplaySize?.();
2327
+ return n ? e._normalizeDisplaySize({ size: n }) : e._normalizeDisplaySize({ size: {
2328
+ width: t.getScaledWidth(),
2329
+ height: t.getScaledHeight()
2330
+ } });
2331
+ }
2332
+ static _normalizeDisplaySize({ size: e }) {
2333
+ let t = Math.abs(e.width), n = Math.abs(e.height);
2327
2334
  return !Number.isFinite(t) || !Number.isFinite(n) ? null : {
2328
2335
  height: n,
2329
2336
  width: t
@@ -14419,76 +14426,85 @@ function ks({ value: e, min: t, max: n }) {
14419
14426
  return Math.max(t, Math.min(n, e));
14420
14427
  }
14421
14428
  //#endregion
14429
+ //#region src/editor/crop-manager/domain/crop-frame-size.ts
14430
+ function As({ frame: e, scaleX: t = e.scaleX ?? 1, scaleY: n = e.scaleY ?? 1 }) {
14431
+ let r = Math.abs(e.cropSourceScaleX ?? 1) || 1, i = Math.abs(e.cropSourceScaleY ?? 1) || 1;
14432
+ return {
14433
+ width: Math.max(1, e.width * Math.abs(t) / r),
14434
+ height: Math.max(1, e.height * Math.abs(n) / i)
14435
+ };
14436
+ }
14437
+ //#endregion
14422
14438
  //#region src/editor/crop-manager/interaction/crop-controls.ts
14423
- var As = [
14439
+ var js = [
14424
14440
  "tl",
14425
14441
  "tr",
14426
14442
  "bl",
14427
14443
  "br"
14428
- ], js = [
14444
+ ], Ms = [
14429
14445
  "ml",
14430
14446
  "mr",
14431
14447
  "mt",
14432
14448
  "mb"
14433
14449
  ];
14434
- function Ms({ transform: e }) {
14450
+ function Ns({ transform: e }) {
14435
14451
  let { originX: t, originY: n } = e;
14436
14452
  return (t === "center" || t === .5) && (n === "center" || n === .5);
14437
14453
  }
14438
- function Ns({ transform: e, x: t, y: n }) {
14454
+ function Ps({ transform: e, x: t, y: n }) {
14439
14455
  let r = e, { target: i } = r, { scaleX: a = 1, scaleY: o = 1 } = i, s = x.getLocalPoint(r, r.originX, r.originY, t, n);
14440
- return Is({ transform: r }), Bs({
14456
+ return Ls({ transform: r }), Vs({
14441
14457
  transform: r,
14442
14458
  localPoint: s
14443
14459
  }), a !== i.scaleX || o !== i.scaleY;
14444
14460
  }
14445
- function Ps({ transform: e, x: t, y: n }) {
14461
+ function Fs({ transform: e, x: t, y: n }) {
14446
14462
  let r = e, { target: i } = r, { scaleX: a = 1, scaleY: o = 1 } = i, s = x.getLocalPoint(r, r.originX, r.originY, t, n);
14447
- return Is({ transform: r }), Us({
14463
+ return Ls({ transform: r }), Ws({
14448
14464
  transform: r,
14449
14465
  localPoint: s
14450
14466
  }), a !== i.scaleX || o !== i.scaleY;
14451
14467
  }
14452
- function Fs({ transform: e, axis: t, x: n, y: r }) {
14468
+ function Is({ transform: e, axis: t, x: n, y: r }) {
14453
14469
  let i = e, { target: a } = i, o = t === "x" ? a.scaleX ?? 1 : a.scaleY ?? 1, s = x.getLocalPoint(i, i.originX, i.originY, n, r);
14454
- return Is({ transform: i }), Vs({
14470
+ return Ls({ transform: i }), Hs({
14455
14471
  transform: i,
14456
14472
  axis: t,
14457
14473
  localPoint: s
14458
14474
  }), t === "x" ? o !== a.scaleX : o !== a.scaleY;
14459
14475
  }
14460
- function Is({ transform: e }) {
14461
- let { signX: t, signY: n } = Ls({ controlKey: e.corner });
14476
+ function Ls({ transform: e }) {
14477
+ let { signX: t, signY: n } = Rs({ controlKey: e.corner });
14462
14478
  e.signX === void 0 && (e.signX = t), e.signY === void 0 && (e.signY = n);
14463
14479
  }
14464
- function Ls({ controlKey: e }) {
14480
+ function Rs({ controlKey: e }) {
14465
14481
  return {
14466
- signX: Rs({ controlKey: e }),
14467
- signY: zs({ controlKey: e })
14482
+ signX: zs({ controlKey: e }),
14483
+ signY: Bs({ controlKey: e })
14468
14484
  };
14469
14485
  }
14470
- function Rs({ controlKey: e }) {
14486
+ function zs({ controlKey: e }) {
14471
14487
  return e === "tl" || e === "bl" || e === "ml" ? -1 : 1;
14472
14488
  }
14473
- function zs({ controlKey: e }) {
14489
+ function Bs({ controlKey: e }) {
14474
14490
  return e === "tl" || e === "tr" || e === "mt" ? -1 : 1;
14475
14491
  }
14476
- function Bs({ transform: e, localPoint: t }) {
14477
- let { target: n } = e, r = Hs({
14492
+ function Vs({ transform: e, localPoint: t }) {
14493
+ let { target: n } = e, r = Us({
14478
14494
  transform: e,
14479
14495
  axis: "x",
14480
14496
  localPoint: t
14481
- }), i = Hs({
14497
+ }), i = Us({
14482
14498
  transform: e,
14483
14499
  axis: "y",
14484
14500
  localPoint: t
14485
14501
  });
14486
14502
  n.lockScalingX || n.set("scaleX", r), n.lockScalingY || n.set("scaleY", i);
14487
14503
  }
14488
- function Vs({ transform: e, axis: t, localPoint: n }) {
14504
+ function Hs({ transform: e, axis: t, localPoint: n }) {
14489
14505
  let { target: r } = e;
14490
14506
  if (t === "x" && r.lockScalingX || t === "y" && r.lockScalingY) return;
14491
- let i = Hs({
14507
+ let i = Us({
14492
14508
  transform: e,
14493
14509
  axis: t,
14494
14510
  localPoint: n
@@ -14499,7 +14515,7 @@ function Vs({ transform: e, axis: t, localPoint: n }) {
14499
14515
  }
14500
14516
  r.set("scaleY", i);
14501
14517
  }
14502
- function Hs({ transform: e, axis: t, localPoint: n }) {
14518
+ function Us({ transform: e, axis: t, localPoint: n }) {
14503
14519
  let { target: r } = e, i = r._getTransformedDimensions(), a = Js({ target: r }), o = t === "x" ? r.scaleX ?? 1 : r.scaleY ?? 1, s = t === "x" ? n.x : n.y, c = t === "x" ? i.x : i.y, l = t === "x" ? a.minScaleX : a.minScaleY, u = t === "x" ? a.maxScaleX : a.maxScaleY;
14504
14520
  if (Ys({
14505
14521
  transform: e,
@@ -14507,19 +14523,19 @@ function Hs({ transform: e, axis: t, localPoint: n }) {
14507
14523
  localPoint: n
14508
14524
  })) return l;
14509
14525
  let d = Math.abs((s || 0) * o / c);
14510
- return Ms({ transform: e }) && (d *= 2), $s({
14526
+ return Ns({ transform: e }) && (d *= 2), $s({
14511
14527
  value: d,
14512
14528
  min: l,
14513
14529
  max: u
14514
14530
  });
14515
14531
  }
14516
- function Us({ transform: e, localPoint: t }) {
14532
+ function Ws({ transform: e, localPoint: t }) {
14517
14533
  let { target: n } = e;
14518
14534
  if (n.lockScalingX || n.lockScalingY) return;
14519
- let r = Ks({
14535
+ let r = qs({
14520
14536
  target: n,
14521
14537
  transform: e,
14522
- scale: Ws({
14538
+ scale: Gs({
14523
14539
  transform: e,
14524
14540
  localPoint: t,
14525
14541
  dimensions: n._getTransformedDimensions()
@@ -14531,22 +14547,22 @@ function Us({ transform: e, localPoint: t }) {
14531
14547
  });
14532
14548
  n.set("scaleX", r.scaleX), n.set("scaleY", r.scaleY);
14533
14549
  }
14534
- function Ws({ transform: e, localPoint: t, dimensions: n }) {
14550
+ function Gs({ transform: e, localPoint: t, dimensions: n }) {
14535
14551
  let r = "gestureScale" in e && typeof e.gestureScale == "number" ? e.gestureScale : null;
14536
14552
  if (r !== null) return r;
14537
- let i = Math.abs(t.x) + Math.abs(t.y), a = Gs({
14553
+ let i = Math.abs(t.x) + Math.abs(t.y), a = Ks({
14538
14554
  transform: e,
14539
14555
  dimensions: n
14540
14556
  }), o = a > 0 ? i / a : 1;
14541
- return Ms({ transform: e }) && (o *= 2), o;
14557
+ return Ns({ transform: e }) && (o *= 2), o;
14542
14558
  }
14543
- function Gs({ transform: e, dimensions: t }) {
14559
+ function Ks({ transform: e, dimensions: t }) {
14544
14560
  let { target: n, original: r } = e, i = n.scaleX ?? 1, a = n.scaleY ?? 1;
14545
14561
  return Math.abs(t.x * r.scaleX / i) + Math.abs(t.y * r.scaleY / a);
14546
14562
  }
14547
- function Ks({ target: e, transform: t, scale: n, forceMinimum: r }) {
14548
- let i = qs({
14549
- target: e,
14563
+ function qs({ target: e, transform: t, scale: n, forceMinimum: r }) {
14564
+ let i = As({
14565
+ frame: e,
14550
14566
  scaleX: t.original.scaleX,
14551
14567
  scaleY: t.original.scaleY
14552
14568
  }), a = Math.max(ds / i.width, fs / i.height), o = Math.min(ps / i.width, ms / i.height), s = r ? a : $s({
@@ -14559,13 +14575,6 @@ function Ks({ target: e, transform: t, scale: n, forceMinimum: r }) {
14559
14575
  scaleY: t.original.scaleY * s
14560
14576
  };
14561
14577
  }
14562
- function qs({ target: e, scaleX: t, scaleY: n }) {
14563
- let r = e, i = Math.abs(r.cropSourceScaleX ?? 1) || 1, a = Math.abs(r.cropSourceScaleY ?? 1) || 1;
14564
- return {
14565
- width: Math.max(1, e.width * Math.abs(t) / i),
14566
- height: Math.max(1, e.height * Math.abs(n) / a)
14567
- };
14568
- }
14569
14578
  function Js({ target: e }) {
14570
14579
  let t = e, n = Math.abs(t.cropSourceScaleX ?? 1) || 1, r = Math.abs(t.cropSourceScaleY ?? 1) || 1, i = Math.max(1, e.width), a = Math.max(1, e.height);
14571
14580
  return {
@@ -14593,11 +14602,11 @@ function Xs({ transform: e, localPoint: t }) {
14593
14602
  });
14594
14603
  }
14595
14604
  function Zs() {
14596
- let e = x.wrapWithFireEvent("scaling", x.wrapWithFixedAnchor((e, t, n, r) => Ns({
14605
+ let e = x.wrapWithFireEvent("scaling", x.wrapWithFixedAnchor((e, t, n, r) => Ps({
14597
14606
  transform: t,
14598
14607
  x: n,
14599
14608
  y: r
14600
- }))), t = x.wrapWithFireEvent("scaling", x.wrapWithFixedAnchor((e, t, n, r) => Ps({
14609
+ }))), t = x.wrapWithFireEvent("scaling", x.wrapWithFixedAnchor((e, t, n, r) => Fs({
14601
14610
  transform: t,
14602
14611
  x: n,
14603
14612
  y: r
@@ -14605,7 +14614,7 @@ function Zs() {
14605
14614
  return (n, r, i, a) => n.shiftKey ? e(n, r, i, a) : t(n, r, i, a);
14606
14615
  }
14607
14616
  function Qs({ axis: e }) {
14608
- return x.wrapWithFireEvent("scaling", x.wrapWithFixedAnchor((t, n, r, i) => Fs({
14617
+ return x.wrapWithFireEvent("scaling", x.wrapWithFixedAnchor((t, n, r, i) => Is({
14609
14618
  transform: n,
14610
14619
  axis: e,
14611
14620
  x: r,
@@ -14624,13 +14633,13 @@ function ec({ control: e, actionHandler: t }) {
14624
14633
  }
14625
14634
  function tc({ target: e }) {
14626
14635
  let t = { ...e.controls }, n = !1, r = Zs(), i = Qs({ axis: "x" }), a = Qs({ axis: "y" });
14627
- As.forEach((i) => {
14636
+ js.forEach((i) => {
14628
14637
  let a = e.controls[i];
14629
14638
  a && (a.cropResizeControl || (t[i] = ec({
14630
14639
  control: a,
14631
14640
  actionHandler: r
14632
14641
  }), n = !0));
14633
- }), js.forEach((r) => {
14642
+ }), Ms.forEach((r) => {
14634
14643
  let o = e.controls[r];
14635
14644
  o && (o.cropResizeControl || (t[r] = ec({
14636
14645
  control: o,
@@ -14652,6 +14661,9 @@ var nc = "rgba(47, 128, 237, 0.42)", rc = class extends _ {
14652
14661
  height: this.height
14653
14662
  });
14654
14663
  }
14664
+ getObjectDisplaySize() {
14665
+ return As({ frame: this });
14666
+ }
14655
14667
  };
14656
14668
  function ic({ source: e, cropSize: t, showGrid: n }) {
14657
14669
  let r = e.getCenterPoint(), i = e.scaleX ?? 1, a = e.scaleY ?? 1, o = new rc({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anu3ev/fabric-image-editor",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "TypeScript image editor library built on FabricJS, allowing you to create instances with an integrated montage area and providing an API to modify and manage state.",
5
5
  "module": "dist/main.js",
6
6
  "files": [