@anu3ev/fabric-image-editor 0.9.25 → 0.9.26

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 +105 -81
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -13603,22 +13603,22 @@ var yo = class {
13603
13603
  color: d,
13604
13604
  lineWidth: 1
13605
13605
  });
13606
- }, ss = .01, cs = .1, ls = .5, us = 1e-6, ds = .02, fs = 1e-6, ps = 1;
13607
- function ms({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidth: i, effectiveHeight: a, fallbackScale: o, isUniform: s, preservePlacement: c, snapGuards: l }) {
13608
- return As({
13606
+ }, ss = .1, cs = .5, ls = 1e-6, us = .02, ds = 1e-6, fs = 1;
13607
+ function ps({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidth: i, effectiveHeight: a, fallbackScale: o, isUniform: s, preservePlacement: c, snapGuards: l }) {
13608
+ return js({
13609
13609
  target: e,
13610
13610
  snapGuards: l
13611
13611
  }) ? {
13612
13612
  scaleX: n,
13613
13613
  scaleY: r
13614
- } : gs({
13614
+ } : hs({
13615
13615
  target: e,
13616
13616
  effectiveWidth: i,
13617
13617
  effectiveHeight: a,
13618
13618
  transform: t,
13619
13619
  preservePlacement: c,
13620
13620
  snapGuards: l
13621
- }) || hs({
13621
+ }) || ms({
13622
13622
  target: e,
13623
13623
  rawScaleX: n,
13624
13624
  rawScaleY: r,
@@ -13626,7 +13626,7 @@ function ms({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidt
13626
13626
  effectiveHeight: a,
13627
13627
  preservePlacement: c,
13628
13628
  snapGuards: l
13629
- }) || (xs({
13629
+ }) || (bs({
13630
13630
  target: e,
13631
13631
  rawScaleX: n,
13632
13632
  rawScaleY: r,
@@ -13640,18 +13640,18 @@ function ms({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidt
13640
13640
  isUniform: s
13641
13641
  }),
13642
13642
  preservePlacement: c,
13643
- shouldPreferInsideCandidate: ks({
13643
+ shouldPreferInsideCandidate: As({
13644
13644
  target: e,
13645
13645
  snapGuards: l
13646
13646
  }),
13647
13647
  snapGuards: l
13648
13648
  }) ?? o);
13649
13649
  }
13650
- function hs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiveHeight: i, preservePlacement: a, snapGuards: o }) {
13651
- if (!js({
13650
+ function ms({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiveHeight: i, preservePlacement: a, snapGuards: o }) {
13651
+ if (!Ms({
13652
13652
  target: e,
13653
13653
  snapGuards: o
13654
- }) || Ms({
13654
+ }) || Ns({
13655
13655
  target: e,
13656
13656
  snapGuards: o
13657
13657
  })) return null;
@@ -13659,13 +13659,13 @@ function hs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiv
13659
13659
  scaleX: t,
13660
13660
  scaleY: n
13661
13661
  };
13662
- return !_s({
13662
+ return !gs({
13663
13663
  target: e,
13664
13664
  candidate: s,
13665
13665
  preservePlacement: a,
13666
- maxDistance: ls,
13666
+ maxDistance: cs,
13667
13667
  snapGuards: o
13668
- }) || !ys({
13668
+ }) || !vs({
13669
13669
  target: e,
13670
13670
  candidate: s,
13671
13671
  effectiveWidth: r,
@@ -13673,8 +13673,8 @@ function hs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiv
13673
13673
  snapGuards: o
13674
13674
  }) ? null : s;
13675
13675
  }
13676
- function gs({ target: e, transform: t, effectiveWidth: n, effectiveHeight: r, preservePlacement: i, snapGuards: a }) {
13677
- if (!ks({
13676
+ function hs({ target: e, transform: t, effectiveWidth: n, effectiveHeight: r, preservePlacement: i, snapGuards: a }) {
13677
+ if (!As({
13678
13678
  target: e,
13679
13679
  snapGuards: a
13680
13680
  })) return null;
@@ -13683,12 +13683,12 @@ function gs({ target: e, transform: t, effectiveWidth: n, effectiveHeight: r, pr
13683
13683
  let c = {
13684
13684
  scaleX: o,
13685
13685
  scaleY: s
13686
- }, l = _s({
13686
+ }, l = gs({
13687
13687
  target: e,
13688
13688
  candidate: c,
13689
13689
  preservePlacement: i,
13690
13690
  snapGuards: a
13691
- }), u = vs({
13691
+ }), u = _s({
13692
13692
  target: e,
13693
13693
  candidate: c,
13694
13694
  effectiveWidth: n,
@@ -13697,7 +13697,7 @@ function gs({ target: e, transform: t, effectiveWidth: n, effectiveHeight: r, pr
13697
13697
  });
13698
13698
  return !l || !u ? null : c;
13699
13699
  }
13700
- function _s({ target: e, candidate: t, preservePlacement: n, maxDistance: r = ps, snapGuards: i }) {
13700
+ function gs({ target: e, candidate: t, preservePlacement: n, maxDistance: r = fs, snapGuards: i }) {
13701
13701
  let a = Ws({
13702
13702
  target: e,
13703
13703
  candidate: t,
@@ -13710,63 +13710,91 @@ function _s({ target: e, candidate: t, preservePlacement: n, maxDistance: r = ps
13710
13710
  }) > r) return !1;
13711
13711
  return !0;
13712
13712
  }
13713
- function vs({ target: e, candidate: t, effectiveWidth: n, effectiveHeight: r, snapGuards: i }) {
13714
- for (let a of i) if (!Ts({
13713
+ function _s({ target: e, candidate: t, effectiveWidth: n, effectiveHeight: r, snapGuards: i }) {
13714
+ for (let a of i) if (!Es({
13715
13715
  target: e,
13716
13716
  displaySize: a.type === "vertical" ? Math.abs(t.scaleX) * n : Math.abs(t.scaleY) * r,
13717
13717
  snapGuard: a
13718
13718
  })) return !1;
13719
13719
  return !0;
13720
13720
  }
13721
- function ys({ target: e, candidate: t, effectiveWidth: n, effectiveHeight: r, snapGuards: i }) {
13722
- for (let a of i) if (!bs({
13721
+ function vs({ target: e, candidate: t, effectiveWidth: n, effectiveHeight: r, snapGuards: i }) {
13722
+ for (let a of i) if (!ys({
13723
13723
  target: e,
13724
13724
  displaySize: a.type === "vertical" ? Math.abs(t.scaleX) * n : Math.abs(t.scaleY) * r,
13725
13725
  snapGuard: a
13726
13726
  })) return !1;
13727
13727
  return !0;
13728
13728
  }
13729
- function bs({ target: e, displaySize: t, snapGuard: n }) {
13730
- let r = Ds({
13729
+ function ys({ target: e, displaySize: t, snapGuard: n }) {
13730
+ let r = Os({
13731
13731
  target: e,
13732
13732
  snapGuard: n
13733
13733
  });
13734
13734
  if (r === null) return !1;
13735
- let i = Math.round(r + us);
13735
+ let i = Math.round(r + ls);
13736
13736
  return Math.round(t) <= i;
13737
13737
  }
13738
- function xs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiveHeight: i, candidates: a, preservePlacement: o, shouldPreferInsideCandidate: s, snapGuards: c }) {
13739
- let l = null, u = null, d = Infinity;
13740
- for (let t of a) {
13741
- let n = Us({
13742
- target: e,
13743
- candidate: t,
13744
- preservePlacement: o,
13745
- snapGuards: c
13746
- });
13747
- if (n.state === "on-guide") {
13748
- if (!s) return t;
13749
- l ||= t;
13750
- }
13751
- n.state === "inside" && (!s && !u && (u = t), s && n.distance < d && (u = t, d = n.distance));
13752
- }
13753
- return l && Ss({
13738
+ function bs({ target: e, rawScaleX: t, rawScaleY: n, effectiveWidth: r, effectiveHeight: i, candidates: a, preservePlacement: o, shouldPreferInsideCandidate: s, snapGuards: c }) {
13739
+ if (!s) return xs({
13740
+ target: e,
13741
+ candidates: a,
13742
+ preservePlacement: o,
13743
+ snapGuards: c
13744
+ });
13745
+ let { insideCandidate: l, onGuideCandidate: u } = Ss({
13746
+ target: e,
13747
+ candidates: a,
13748
+ preservePlacement: o,
13749
+ snapGuards: c
13750
+ });
13751
+ return u && Cs({
13754
13752
  target: e,
13755
- candidate: l,
13753
+ candidate: u,
13756
13754
  rawScaleX: t,
13757
13755
  rawScaleY: n,
13758
13756
  effectiveWidth: r,
13759
13757
  effectiveHeight: i,
13760
13758
  snapGuards: c
13761
- }) ? l : u || l || null;
13759
+ }) ? u : l || u || null;
13762
13760
  }
13763
- function Ss({ target: e, candidate: t, rawScaleX: n, rawScaleY: r, effectiveWidth: i, effectiveHeight: a, snapGuards: o }) {
13761
+ function xs({ target: e, candidates: t, preservePlacement: n, snapGuards: r }) {
13762
+ let i = null;
13763
+ for (let a of t) {
13764
+ let t = Us({
13765
+ target: e,
13766
+ candidate: a,
13767
+ preservePlacement: n,
13768
+ snapGuards: r
13769
+ });
13770
+ if (t.state === "on-guide") return a;
13771
+ t.state === "inside" && !i && (i = a);
13772
+ }
13773
+ return i;
13774
+ }
13775
+ function Ss({ target: e, candidates: t, preservePlacement: n, snapGuards: r }) {
13776
+ let i = null, a = null, o = Infinity;
13777
+ for (let s of t) {
13778
+ let t = Us({
13779
+ target: e,
13780
+ candidate: s,
13781
+ preservePlacement: n,
13782
+ snapGuards: r
13783
+ });
13784
+ t.state === "on-guide" && !i && (i = s), t.state === "inside" && t.distance < o && (a = s, o = t.distance);
13785
+ }
13786
+ return {
13787
+ insideCandidate: a,
13788
+ onGuideCandidate: i
13789
+ };
13790
+ }
13791
+ function Cs({ target: e, candidate: t, rawScaleX: n, rawScaleY: r, effectiveWidth: i, effectiveHeight: a, snapGuards: o }) {
13764
13792
  for (let s of o) {
13765
13793
  let o = s.type === "vertical" ? Math.abs(t.scaleX) * i : Math.abs(t.scaleY) * a, c = s.type === "vertical" ? Math.abs(n) * i : Math.abs(r) * a;
13766
- if (!Cs({ displaySize: o }) || !ws({
13794
+ if (!ws({ displaySize: o }) || !Ts({
13767
13795
  displaySize: o,
13768
13796
  rawDisplaySize: c
13769
- }) || !Ts({
13797
+ }) || !Es({
13770
13798
  target: e,
13771
13799
  displaySize: o,
13772
13800
  snapGuard: s
@@ -13774,60 +13802,60 @@ function Ss({ target: e, candidate: t, rawScaleX: n, rawScaleY: r, effectiveWidt
13774
13802
  }
13775
13803
  return !0;
13776
13804
  }
13777
- function Cs({ displaySize: e }) {
13778
- return Math.abs(e - Math.round(e)) <= us;
13805
+ function ws({ displaySize: e }) {
13806
+ return Math.abs(e - Math.round(e)) <= ls;
13779
13807
  }
13780
- function ws({ displaySize: e, rawDisplaySize: t }) {
13781
- return Math.abs(e - t) <= ds;
13808
+ function Ts({ displaySize: e, rawDisplaySize: t }) {
13809
+ return Math.abs(e - t) <= us;
13782
13810
  }
13783
- function Ts({ target: e, displaySize: t, snapGuard: n }) {
13784
- let r = Es({
13811
+ function Es({ target: e, displaySize: t, snapGuard: n }) {
13812
+ let r = Ds({
13785
13813
  target: e,
13786
13814
  snapGuard: n
13787
13815
  });
13788
13816
  return r === null ? !1 : Math.round(t) <= r;
13789
13817
  }
13790
- function Es({ target: e, snapGuard: t }) {
13791
- let n = Ds({
13818
+ function Ds({ target: e, snapGuard: t }) {
13819
+ let n = Os({
13792
13820
  target: e,
13793
13821
  snapGuard: t
13794
13822
  });
13795
- return n === null ? null : Math.round(n + us);
13823
+ return n === null ? null : Math.round(n + ls);
13796
13824
  }
13797
- function Ds({ target: e, snapGuard: t }) {
13825
+ function Os({ target: e, snapGuard: t }) {
13798
13826
  let n = e, { cropSource: r } = n;
13799
13827
  if (!r) return null;
13800
13828
  let i = cn({ object: r });
13801
13829
  if (!i) return null;
13802
13830
  let a = t.type === "vertical" ? Math.abs(n.cropSourceScaleX ?? 1) : Math.abs(n.cropSourceScaleY ?? 1);
13803
13831
  if (!Number.isFinite(a) || a <= 0) return null;
13804
- let o = Os({
13832
+ let o = ks({
13805
13833
  sourceBounds: i,
13806
13834
  snapGuard: t
13807
13835
  });
13808
13836
  return !Number.isFinite(o) || o <= 0 ? null : o / a;
13809
13837
  }
13810
- function Os({ sourceBounds: e, snapGuard: t }) {
13838
+ function ks({ sourceBounds: e, snapGuard: t }) {
13811
13839
  let { edge: n, position: r } = t;
13812
13840
  return n === "left" ? e.right - r : n === "right" ? r - e.left : n === "top" ? e.bottom - r : r - e.top;
13813
13841
  }
13814
- function ks({ target: e, snapGuards: t }) {
13815
- return js({
13842
+ function As({ target: e, snapGuards: t }) {
13843
+ return Ms({
13816
13844
  target: e,
13817
13845
  snapGuards: t
13818
- }) ? !Ms({
13846
+ }) ? !Ns({
13819
13847
  target: e,
13820
13848
  snapGuards: t
13821
13849
  }) : !1;
13822
13850
  }
13823
- function As({ target: e, snapGuards: t }) {
13824
- if (js({
13851
+ function js({ target: e, snapGuards: t }) {
13852
+ if (Ms({
13825
13853
  target: e,
13826
13854
  snapGuards: t
13827
13855
  })) return !1;
13828
13856
  let n = G({ object: e });
13829
13857
  if (!n) return !1;
13830
- for (let e of t) if (!Is({ snapGuard: e }) || !Js({
13858
+ for (let e of t) if (!Js({
13831
13859
  bounds: n,
13832
13860
  snapGuard: e
13833
13861
  }) || !Ls({
@@ -13836,36 +13864,32 @@ function As({ target: e, snapGuards: t }) {
13836
13864
  })) return !1;
13837
13865
  return !0;
13838
13866
  }
13839
- function js({ target: e, snapGuards: t }) {
13867
+ function Ms({ target: e, snapGuards: t }) {
13840
13868
  if (typeof e.getObjectDisplaySize != "function") return !1;
13841
- let n = e, r = t.some((e) => e.type === "vertical" && !Fs({ scale: n.cropSourceScaleX })), i = t.some((e) => e.type === "horizontal" && !Fs({ scale: n.cropSourceScaleY }));
13869
+ let n = e, r = t.some((e) => e.type === "vertical" && !Is({ scale: n.cropSourceScaleX })), i = t.some((e) => e.type === "horizontal" && !Is({ scale: n.cropSourceScaleY }));
13842
13870
  return r || i;
13843
13871
  }
13844
- function Ms({ target: e, snapGuards: t }) {
13872
+ function Ns({ target: e, snapGuards: t }) {
13845
13873
  let { cropSource: n } = e;
13846
13874
  if (!n) return !1;
13847
13875
  let r = G({ object: n });
13848
- return r ? t.some((e) => Ns({
13876
+ return r ? t.some((e) => Ps({
13849
13877
  snapGuard: e,
13850
13878
  sourceBounds: r
13851
13879
  })) : !1;
13852
13880
  }
13853
- function Ns({ snapGuard: e, sourceBounds: t }) {
13881
+ function Ps({ snapGuard: e, sourceBounds: t }) {
13854
13882
  let { edge: n, position: r } = e, i = t.bottom;
13855
- return n === "left" && (i = t.left), n === "right" && (i = t.right), n === "top" && (i = t.top), Ps({
13883
+ return n === "left" && (i = t.left), n === "right" && (i = t.right), n === "top" && (i = t.top), Fs({
13856
13884
  position: r,
13857
13885
  boundary: i
13858
13886
  });
13859
13887
  }
13860
- function Ps({ position: e, boundary: t }) {
13861
- return Math.abs(e - t) <= cs;
13862
- }
13863
- function Fs({ scale: e }) {
13864
- return Math.abs(Math.abs(e ?? 1) - 1) <= fs;
13888
+ function Fs({ position: e, boundary: t }) {
13889
+ return Math.abs(e - t) <= ss;
13865
13890
  }
13866
- function Is({ snapGuard: e }) {
13867
- let t = Math.round(e.position);
13868
- return Math.abs(e.position - t) <= ss;
13891
+ function Is({ scale: e }) {
13892
+ return Math.abs(Math.abs(e ?? 1) - 1) <= ds;
13869
13893
  }
13870
13894
  function Ls({ bounds: e, snapGuard: t }) {
13871
13895
  let n = t.type === "vertical" ? e.right - e.left : e.bottom - e.top;
@@ -13985,11 +14009,11 @@ function Ks({ bounds: e, snapGuard: t }) {
13985
14009
  }
13986
14010
  function qs({ bounds: e, snapGuard: t }) {
13987
14011
  let { edge: n, position: r } = t;
13988
- return n === "left" ? e.left >= r - cs : n === "right" ? e.right <= r + cs : n === "top" ? e.top >= r - cs : e.bottom <= r + cs;
14012
+ return n === "left" ? e.left >= r - ss : n === "right" ? e.right <= r + ss : n === "top" ? e.top >= r - ss : e.bottom <= r + ss;
13989
14013
  }
13990
14014
  function Js({ bounds: e, snapGuard: t }) {
13991
14015
  let { edge: n, position: r } = t;
13992
- return n === "left" ? Math.abs(e.left - r) <= cs : n === "right" ? Math.abs(e.right - r) <= cs : n === "top" ? Math.abs(e.top - r) <= cs : Math.abs(e.bottom - r) <= cs;
14016
+ return n === "left" ? Math.abs(e.left - r) <= ss : n === "right" ? Math.abs(e.right - r) <= ss : n === "top" ? Math.abs(e.top - r) <= ss : Math.abs(e.bottom - r) <= ss;
13993
14017
  }
13994
14018
  //#endregion
13995
14019
  //#region src/editor/snapping-manager/pixel-grid.ts
@@ -14111,7 +14135,7 @@ function oc({ target: e, transform: t, rawScaleX: n, rawScaleY: r, effectiveWidt
14111
14135
  effectiveWidth: i,
14112
14136
  effectiveHeight: a
14113
14137
  });
14114
- return s.length === 0 ? c : ms({
14138
+ return s.length === 0 ? c : ps({
14115
14139
  target: e,
14116
14140
  transform: t,
14117
14141
  rawScaleX: n,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anu3ev/fabric-image-editor",
3
- "version": "0.9.25",
3
+ "version": "0.9.26",
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": [