@anu3ev/fabric-image-editor 0.8.21 → 0.8.23
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.
- package/dist/main.js +184 -52
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -9802,6 +9802,12 @@ var pa = {
|
|
|
9802
9802
|
}
|
|
9803
9803
|
return n instanceof l ? [n] : null;
|
|
9804
9804
|
}
|
|
9805
|
+
_materializeUngroupedObject({ object: e }) {
|
|
9806
|
+
let { shapeManager: t, textManager: n } = this.editor, r = { target: e };
|
|
9807
|
+
e.shapeComposite === !0 && (r.textScale = Math.abs(e.scaleX ?? 1) || 1);
|
|
9808
|
+
let i = n.commitStandaloneTextScale({ target: e }), a = t.commitRehydratedShapeLayout(r);
|
|
9809
|
+
!i && !a && e.setCoords();
|
|
9810
|
+
}
|
|
9805
9811
|
group({ target: e, withoutSave: t = !1 } = {}) {
|
|
9806
9812
|
let { canvas: n, historyManager: r } = this.editor, i = this._getObjectsToGroup(e);
|
|
9807
9813
|
if (!i) return null;
|
|
@@ -9827,7 +9833,7 @@ var pa = {
|
|
|
9827
9833
|
a.forEach((e) => {
|
|
9828
9834
|
let n = e.removeAll();
|
|
9829
9835
|
r.remove(e), n.forEach((e) => {
|
|
9830
|
-
r.add(e), t.push(e);
|
|
9836
|
+
this._materializeUngroupedObject({ object: e }), r.add(e), t.push(e);
|
|
9831
9837
|
});
|
|
9832
9838
|
});
|
|
9833
9839
|
let o = new e(t, { canvas: r });
|
|
@@ -10041,11 +10047,11 @@ var pa = {
|
|
|
10041
10047
|
this.editor = e;
|
|
10042
10048
|
}
|
|
10043
10049
|
static _isUngroupableGroup(e) {
|
|
10044
|
-
return e
|
|
10050
|
+
return e instanceof l && e.format !== "svg";
|
|
10045
10051
|
}
|
|
10046
10052
|
_handleGroupDeletion(e) {
|
|
10047
10053
|
let { groupingManager: t } = this.editor, { ungroupedObjects: n = [] } = t.ungroup({
|
|
10048
|
-
|
|
10054
|
+
target: e,
|
|
10049
10055
|
withoutSave: !0
|
|
10050
10056
|
}) ?? {};
|
|
10051
10057
|
return this.deleteSelectedObjects({
|
|
@@ -11582,7 +11588,12 @@ var Wa = class {
|
|
|
11582
11588
|
}), g = !!m.positionsNormalized, _ = !1, v = !1;
|
|
11583
11589
|
i.suspendHistory();
|
|
11584
11590
|
try {
|
|
11585
|
-
let r = await t._enlivenObjects(
|
|
11591
|
+
let r = await t._enlivenObjects({
|
|
11592
|
+
objects: l,
|
|
11593
|
+
baseWidth: m.baseWidth,
|
|
11594
|
+
baseHeight: m.baseHeight,
|
|
11595
|
+
useRelativePositions: g
|
|
11596
|
+
});
|
|
11586
11597
|
if (!r.length) return a.emitWarning({
|
|
11587
11598
|
origin: "TemplateManager",
|
|
11588
11599
|
method: "applyTemplate",
|
|
@@ -11653,63 +11664,184 @@ var Wa = class {
|
|
|
11653
11664
|
static _getBoundingRect(e) {
|
|
11654
11665
|
return e.getBoundingRect(!1, !0);
|
|
11655
11666
|
}
|
|
11656
|
-
static async _enlivenObjects(e) {
|
|
11667
|
+
static async _enlivenObjects({ objects: e, baseWidth: n, baseHeight: r, useRelativePositions: i }) {
|
|
11657
11668
|
return (await Promise.all(e.map(async (e) => {
|
|
11658
11669
|
if (t._hasSerializedSvgMarkup(e)) {
|
|
11659
|
-
let
|
|
11660
|
-
if (
|
|
11661
|
-
revived:
|
|
11662
|
-
serialized: e
|
|
11663
|
-
|
|
11664
|
-
|
|
11665
|
-
|
|
11666
|
-
|
|
11667
|
-
|
|
11668
|
-
|
|
11669
|
-
|
|
11670
|
+
let a = await t._reviveSvgObject(e);
|
|
11671
|
+
if (a) return t._restoreImageScale({
|
|
11672
|
+
revived: a,
|
|
11673
|
+
serialized: e,
|
|
11674
|
+
baseWidth: n,
|
|
11675
|
+
baseHeight: r,
|
|
11676
|
+
useRelativePositions: i
|
|
11677
|
+
}), a;
|
|
11678
|
+
}
|
|
11679
|
+
let a = (await w.enlivenObjects([e]))?.[0];
|
|
11680
|
+
return a ? (t._restoreImageScale({
|
|
11681
|
+
revived: a,
|
|
11682
|
+
serialized: e,
|
|
11683
|
+
baseWidth: n,
|
|
11684
|
+
baseHeight: r,
|
|
11685
|
+
useRelativePositions: i
|
|
11686
|
+
}), a) : null;
|
|
11670
11687
|
}))).filter((e) => !!e);
|
|
11671
11688
|
}
|
|
11672
|
-
static _restoreImageScale({ revived: e, serialized: n }) {
|
|
11689
|
+
static _restoreImageScale({ revived: e, serialized: n, baseWidth: r, baseHeight: i, useRelativePositions: a }) {
|
|
11673
11690
|
if ((typeof e.type == "string" ? e.type.toLowerCase() : "") !== "image") return;
|
|
11674
|
-
let
|
|
11691
|
+
let o = e, s = t._createImageRestorePlan({
|
|
11692
|
+
image: o,
|
|
11693
|
+
serialized: n
|
|
11694
|
+
});
|
|
11695
|
+
if (!s.hasIntrinsicSize) {
|
|
11696
|
+
o.set(s.nextProps);
|
|
11697
|
+
return;
|
|
11698
|
+
}
|
|
11699
|
+
let c = t._resolveImageTemplateCenter({
|
|
11700
|
+
image: o,
|
|
11701
|
+
serialized: n,
|
|
11702
|
+
plan: s,
|
|
11703
|
+
baseWidth: r,
|
|
11704
|
+
baseHeight: i,
|
|
11705
|
+
useRelativePositions: a
|
|
11706
|
+
});
|
|
11707
|
+
o.set(s.nextProps), t._restoreImageTemplateCenter({
|
|
11708
|
+
image: o,
|
|
11709
|
+
center: c,
|
|
11710
|
+
baseWidth: r,
|
|
11711
|
+
baseHeight: i,
|
|
11712
|
+
useRelativePositions: a
|
|
11713
|
+
});
|
|
11714
|
+
}
|
|
11715
|
+
static _createImageRestorePlan({ image: e, serialized: n }) {
|
|
11716
|
+
let { width: r, height: i } = t._getImageIntrinsicSize({ image: e }), { width: a, height: o, scaleX: s, scaleY: c, customData: l } = n, u = W({
|
|
11717
|
+
value: a,
|
|
11718
|
+
fallback: r
|
|
11719
|
+
}), d = W({
|
|
11720
|
+
value: o,
|
|
11721
|
+
fallback: i
|
|
11722
|
+
}), f = W({
|
|
11723
|
+
value: s,
|
|
11724
|
+
fallback: e.scaleX || 1
|
|
11725
|
+
}), p = W({
|
|
11726
|
+
value: c,
|
|
11727
|
+
fallback: e.scaleY || 1
|
|
11728
|
+
}), m = t._resolveImageFit({ customData: l });
|
|
11729
|
+
return {
|
|
11730
|
+
nextProps: t._resolveImageRestoreProps({
|
|
11731
|
+
imageFit: m,
|
|
11732
|
+
intrinsicWidth: r,
|
|
11733
|
+
intrinsicHeight: i,
|
|
11734
|
+
targetWidth: u,
|
|
11735
|
+
targetHeight: d,
|
|
11736
|
+
baseScaleX: f,
|
|
11737
|
+
baseScaleY: p
|
|
11738
|
+
}),
|
|
11739
|
+
targetWidth: u,
|
|
11740
|
+
targetHeight: d,
|
|
11741
|
+
baseScaleX: f,
|
|
11742
|
+
baseScaleY: p,
|
|
11743
|
+
hasIntrinsicSize: r > 0 && i > 0
|
|
11744
|
+
};
|
|
11745
|
+
}
|
|
11746
|
+
static _getImageIntrinsicSize({ image: e }) {
|
|
11747
|
+
let t = "getElement" in e && typeof e.getElement == "function" ? e.getElement() : null, { naturalWidth: n = 0, naturalHeight: r = 0, width: i = 0, height: a = 0 } = t instanceof HTMLImageElement ? t : {
|
|
11675
11748
|
naturalWidth: 0,
|
|
11676
11749
|
naturalHeight: 0,
|
|
11677
11750
|
width: 0,
|
|
11678
11751
|
height: 0
|
|
11679
|
-
}
|
|
11680
|
-
|
|
11681
|
-
|
|
11682
|
-
|
|
11683
|
-
|
|
11684
|
-
|
|
11685
|
-
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
|
|
11706
|
-
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
|
|
11752
|
+
};
|
|
11753
|
+
return {
|
|
11754
|
+
width: W({
|
|
11755
|
+
value: n || i || e.width,
|
|
11756
|
+
fallback: 0
|
|
11757
|
+
}),
|
|
11758
|
+
height: W({
|
|
11759
|
+
value: r || a || e.height,
|
|
11760
|
+
fallback: 0
|
|
11761
|
+
})
|
|
11762
|
+
};
|
|
11763
|
+
}
|
|
11764
|
+
static _resolveImageRestoreProps({ imageFit: e, intrinsicWidth: n, intrinsicHeight: r, targetWidth: i, targetHeight: a, baseScaleX: o, baseScaleY: s }) {
|
|
11765
|
+
let c = i * o, l = a * s, u = n > 0, d = r > 0, f = {};
|
|
11766
|
+
return u && (f.width = n), d && (f.height = r), !u || !d ? f : e === "stretch" ? (t._applyStretchedImageScale({
|
|
11767
|
+
nextProps: f,
|
|
11768
|
+
intrinsicWidth: n,
|
|
11769
|
+
intrinsicHeight: r,
|
|
11770
|
+
targetDisplayWidth: c,
|
|
11771
|
+
targetDisplayHeight: l
|
|
11772
|
+
}), f) : (t._applyContainedImageScale({
|
|
11773
|
+
nextProps: f,
|
|
11774
|
+
intrinsicWidth: n,
|
|
11775
|
+
intrinsicHeight: r,
|
|
11776
|
+
targetDisplayWidth: c,
|
|
11777
|
+
targetDisplayHeight: l
|
|
11778
|
+
}), f);
|
|
11779
|
+
}
|
|
11780
|
+
static _applyStretchedImageScale({ nextProps: e, intrinsicWidth: t, intrinsicHeight: n, targetDisplayWidth: r, targetDisplayHeight: i }) {
|
|
11781
|
+
let a = r > 0 ? r / t : null, o = i > 0 ? i / n : null;
|
|
11782
|
+
a && a > 0 && (e.scaleX = a), o && o > 0 && (e.scaleY = o);
|
|
11783
|
+
}
|
|
11784
|
+
static _applyContainedImageScale({ nextProps: e, intrinsicWidth: t, intrinsicHeight: n, targetDisplayWidth: r, targetDisplayHeight: i }) {
|
|
11785
|
+
if (r <= 0 || i <= 0) return;
|
|
11786
|
+
let a = Math.min(r / t, i / n);
|
|
11787
|
+
Number.isFinite(a) && a > 0 && (e.scaleX = a, e.scaleY = a);
|
|
11788
|
+
}
|
|
11789
|
+
static _resolveImageTemplateCenter({ image: e, serialized: n, plan: r, baseWidth: i, baseHeight: a, useRelativePositions: o }) {
|
|
11790
|
+
let s = {
|
|
11791
|
+
left: e.left,
|
|
11792
|
+
top: e.top,
|
|
11793
|
+
width: e.width,
|
|
11794
|
+
height: e.height,
|
|
11795
|
+
scaleX: e.scaleX,
|
|
11796
|
+
scaleY: e.scaleY
|
|
11797
|
+
}, c = t._resolveTemplatePlacement({
|
|
11798
|
+
image: e,
|
|
11799
|
+
serialized: n,
|
|
11800
|
+
baseWidth: i,
|
|
11801
|
+
baseHeight: a,
|
|
11802
|
+
useRelativePositions: o
|
|
11803
|
+
});
|
|
11804
|
+
e.set({
|
|
11805
|
+
left: c.x,
|
|
11806
|
+
top: c.y,
|
|
11807
|
+
width: r.targetWidth,
|
|
11808
|
+
height: r.targetHeight,
|
|
11809
|
+
scaleX: r.baseScaleX,
|
|
11810
|
+
scaleY: r.baseScaleY
|
|
11811
|
+
});
|
|
11812
|
+
let l = e.getPointByOrigin("center", "center");
|
|
11813
|
+
return e.set(s), {
|
|
11814
|
+
x: l.x,
|
|
11815
|
+
y: l.y
|
|
11816
|
+
};
|
|
11817
|
+
}
|
|
11818
|
+
static _resolveTemplatePlacement({ image: e, serialized: t, baseWidth: n, baseHeight: r, useRelativePositions: i }) {
|
|
11819
|
+
let a = W({
|
|
11820
|
+
value: t.left,
|
|
11821
|
+
fallback: e.left || 0
|
|
11822
|
+
}), o = W({
|
|
11823
|
+
value: t.top,
|
|
11824
|
+
fallback: e.top || 0
|
|
11825
|
+
});
|
|
11826
|
+
return i ? {
|
|
11827
|
+
x: a * (n || 1),
|
|
11828
|
+
y: o * (r || 1)
|
|
11829
|
+
} : {
|
|
11830
|
+
x: a,
|
|
11831
|
+
y: o
|
|
11832
|
+
};
|
|
11833
|
+
}
|
|
11834
|
+
static _restoreImageTemplateCenter({ image: e, center: t, baseWidth: n, baseHeight: r, useRelativePositions: i }) {
|
|
11835
|
+
e.setPositionByOrigin(new m(t.x, t.y), "center", "center"), i && e.set({
|
|
11836
|
+
left: W({
|
|
11837
|
+
value: e.left,
|
|
11838
|
+
fallback: 0
|
|
11839
|
+
}) / (n || 1),
|
|
11840
|
+
top: W({
|
|
11841
|
+
value: e.top,
|
|
11842
|
+
fallback: 0
|
|
11843
|
+
}) / (r || 1)
|
|
11844
|
+
});
|
|
11713
11845
|
}
|
|
11714
11846
|
static _resolveImageFit({ customData: e }) {
|
|
11715
11847
|
if (!e || typeof e != "object") return "contain";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anu3ev/fabric-image-editor",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.23",
|
|
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": [
|