@anu3ev/fabric-image-editor 0.8.22 → 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 +175 -49
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -11588,7 +11588,12 @@ var Wa = class {
|
|
|
11588
11588
|
}), g = !!m.positionsNormalized, _ = !1, v = !1;
|
|
11589
11589
|
i.suspendHistory();
|
|
11590
11590
|
try {
|
|
11591
|
-
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
|
+
});
|
|
11592
11597
|
if (!r.length) return a.emitWarning({
|
|
11593
11598
|
origin: "TemplateManager",
|
|
11594
11599
|
method: "applyTemplate",
|
|
@@ -11659,63 +11664,184 @@ var Wa = class {
|
|
|
11659
11664
|
static _getBoundingRect(e) {
|
|
11660
11665
|
return e.getBoundingRect(!1, !0);
|
|
11661
11666
|
}
|
|
11662
|
-
static async _enlivenObjects(e) {
|
|
11667
|
+
static async _enlivenObjects({ objects: e, baseWidth: n, baseHeight: r, useRelativePositions: i }) {
|
|
11663
11668
|
return (await Promise.all(e.map(async (e) => {
|
|
11664
11669
|
if (t._hasSerializedSvgMarkup(e)) {
|
|
11665
|
-
let
|
|
11666
|
-
if (
|
|
11667
|
-
revived:
|
|
11668
|
-
serialized: e
|
|
11669
|
-
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
|
|
11675
|
-
|
|
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;
|
|
11676
11687
|
}))).filter((e) => !!e);
|
|
11677
11688
|
}
|
|
11678
|
-
static _restoreImageScale({ revived: e, serialized: n }) {
|
|
11689
|
+
static _restoreImageScale({ revived: e, serialized: n, baseWidth: r, baseHeight: i, useRelativePositions: a }) {
|
|
11679
11690
|
if ((typeof e.type == "string" ? e.type.toLowerCase() : "") !== "image") return;
|
|
11680
|
-
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 : {
|
|
11681
11748
|
naturalWidth: 0,
|
|
11682
11749
|
naturalHeight: 0,
|
|
11683
11750
|
width: 0,
|
|
11684
11751
|
height: 0
|
|
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
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
|
|
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
|
+
});
|
|
11719
11845
|
}
|
|
11720
11846
|
static _resolveImageFit({ customData: e }) {
|
|
11721
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": [
|