@anu3ev/fabric-image-editor 0.8.22 → 0.8.24
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 +207 -70
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -10785,11 +10785,14 @@ var pa = {
|
|
|
10785
10785
|
});
|
|
10786
10786
|
}
|
|
10787
10787
|
_applyPostStyleLayout({ textbox: e, placement: t, style: n, styleMaps: r, contentUpdate: i, contentPlacement: a, syncLineStylesWithText: o }) {
|
|
10788
|
-
let s = e.text ?? "", c = this._hasBackgroundStyleUpdate({ style: n }), l = this.
|
|
10788
|
+
let s = e.text ?? "", c = this._hasBackgroundStyleUpdate({ style: n }), l = this._shouldRefreshDimensions({
|
|
10789
|
+
contentUpdate: i,
|
|
10790
|
+
styleMaps: r
|
|
10791
|
+
}), u = this._resolveShouldAutoExpand({
|
|
10789
10792
|
textbox: e,
|
|
10790
10793
|
style: n,
|
|
10791
10794
|
styleMaps: r,
|
|
10792
|
-
|
|
10795
|
+
shouldRefreshDimensions: l
|
|
10793
10796
|
});
|
|
10794
10797
|
c && (e.dirty = !0), this._applyAutoExpandPreference({
|
|
10795
10798
|
textbox: e,
|
|
@@ -10802,7 +10805,8 @@ var pa = {
|
|
|
10802
10805
|
}), this.runtime.normalizeTextboxAfterContentChange({
|
|
10803
10806
|
textbox: e,
|
|
10804
10807
|
placement: t,
|
|
10805
|
-
shouldAutoExpand:
|
|
10808
|
+
shouldAutoExpand: u,
|
|
10809
|
+
shouldRefreshDimensions: l
|
|
10806
10810
|
}), a && this.runtime.restoreTextboxContentPlacement({
|
|
10807
10811
|
textbox: e,
|
|
10808
10812
|
contentPlacement: a
|
|
@@ -10822,14 +10826,16 @@ var pa = {
|
|
|
10822
10826
|
e.radiusBottomLeft
|
|
10823
10827
|
].some((e) => e !== void 0);
|
|
10824
10828
|
}
|
|
10825
|
-
_resolveShouldAutoExpand({ textbox: e, style: t, styleMaps: n,
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10829
|
+
_resolveShouldAutoExpand({ textbox: e, style: t, styleMaps: n, shouldRefreshDimensions: r }) {
|
|
10830
|
+
return (t.autoExpand ?? e.autoExpand) !== !1 && !Object.prototype.hasOwnProperty.call(n.updates, "width") && r;
|
|
10831
|
+
}
|
|
10832
|
+
_shouldRefreshDimensions({ contentUpdate: e, styleMaps: t }) {
|
|
10833
|
+
return e.hasTextUpdate || e.uppercaseChanged || aa({ stylesList: [
|
|
10834
|
+
t.updates,
|
|
10835
|
+
t.selectionStyles,
|
|
10836
|
+
t.lineSelectionStyles,
|
|
10837
|
+
t.wholeTextStyles
|
|
10831
10838
|
] });
|
|
10832
|
-
return i !== !1 && !Object.prototype.hasOwnProperty.call(n.updates, "width") && (r.hasTextUpdate || r.uppercaseChanged || a);
|
|
10833
10839
|
}
|
|
10834
10840
|
_applyAutoExpandPreference({ textbox: e, autoExpand: t }) {
|
|
10835
10841
|
if (t !== void 0) {
|
|
@@ -11176,11 +11182,12 @@ var Wa = class {
|
|
|
11176
11182
|
this._syncLineStylesWithText({ textbox: n });
|
|
11177
11183
|
return;
|
|
11178
11184
|
}
|
|
11179
|
-
this._normalizeTextboxAfterContentChange({
|
|
11185
|
+
this._syncLineStylesWithText({ textbox: n }), this._normalizeTextboxAfterContentChange({
|
|
11180
11186
|
textbox: n,
|
|
11181
11187
|
placement: u,
|
|
11182
|
-
shouldAutoExpand: c
|
|
11183
|
-
|
|
11188
|
+
shouldAutoExpand: c,
|
|
11189
|
+
shouldRefreshDimensions: !0
|
|
11190
|
+
});
|
|
11184
11191
|
}, this._handleTextEditingExited = (t) => {
|
|
11185
11192
|
let { target: n } = t;
|
|
11186
11193
|
if (!e._isTextbox(n)) return;
|
|
@@ -11371,19 +11378,23 @@ var Wa = class {
|
|
|
11371
11378
|
let n = t.split("\n").length, { textLines: r } = e;
|
|
11372
11379
|
return Array.isArray(r) && r.length > n;
|
|
11373
11380
|
}
|
|
11374
|
-
_normalizeTextboxAfterContentChange({ textbox: e, placement: t, shouldAutoExpand: n, clampToMontage: r = !0 }) {
|
|
11375
|
-
let
|
|
11376
|
-
n && (
|
|
11381
|
+
_normalizeTextboxAfterContentChange({ textbox: e, placement: t, shouldAutoExpand: n, clampToMontage: r = !0, shouldRefreshDimensions: i = !1 }) {
|
|
11382
|
+
let a = !1;
|
|
11383
|
+
n && (a = this._autoExpandTextboxWidth(e, {
|
|
11377
11384
|
placement: t ?? void 0,
|
|
11378
11385
|
clampToMontage: r
|
|
11379
11386
|
}));
|
|
11380
|
-
let
|
|
11381
|
-
|
|
11382
|
-
|
|
11383
|
-
|
|
11387
|
+
let o = !1, s = !1;
|
|
11388
|
+
if (!a && i) {
|
|
11389
|
+
let t = e.width ?? 0, n = e.height ?? 0;
|
|
11390
|
+
e.initDimensions(), o = Math.abs((e.width ?? 0) - t) > .01 || Math.abs((e.height ?? 0) - n) > .01;
|
|
11391
|
+
}
|
|
11392
|
+
a || (s = oa({ textbox: e }));
|
|
11393
|
+
let c = !1;
|
|
11394
|
+
return !a && t && (this.editor.canvasManager.applyObjectPlacement({
|
|
11384
11395
|
object: e,
|
|
11385
11396
|
placement: t
|
|
11386
|
-
}),
|
|
11397
|
+
}), c = !0), (a || o || s) && (e.dirty = !0), (a || o || s || c) && e.setCoords(), a || o || s;
|
|
11387
11398
|
}
|
|
11388
11399
|
_restoreTextboxContentPlacement({ textbox: e, contentPlacement: t }) {
|
|
11389
11400
|
let n = na({
|
|
@@ -11588,7 +11599,12 @@ var Wa = class {
|
|
|
11588
11599
|
}), g = !!m.positionsNormalized, _ = !1, v = !1;
|
|
11589
11600
|
i.suspendHistory();
|
|
11590
11601
|
try {
|
|
11591
|
-
let r = await t._enlivenObjects(
|
|
11602
|
+
let r = await t._enlivenObjects({
|
|
11603
|
+
objects: l,
|
|
11604
|
+
baseWidth: m.baseWidth,
|
|
11605
|
+
baseHeight: m.baseHeight,
|
|
11606
|
+
useRelativePositions: g
|
|
11607
|
+
});
|
|
11592
11608
|
if (!r.length) return a.emitWarning({
|
|
11593
11609
|
origin: "TemplateManager",
|
|
11594
11610
|
method: "applyTemplate",
|
|
@@ -11659,63 +11675,184 @@ var Wa = class {
|
|
|
11659
11675
|
static _getBoundingRect(e) {
|
|
11660
11676
|
return e.getBoundingRect(!1, !0);
|
|
11661
11677
|
}
|
|
11662
|
-
static async _enlivenObjects(e) {
|
|
11678
|
+
static async _enlivenObjects({ objects: e, baseWidth: n, baseHeight: r, useRelativePositions: i }) {
|
|
11663
11679
|
return (await Promise.all(e.map(async (e) => {
|
|
11664
11680
|
if (t._hasSerializedSvgMarkup(e)) {
|
|
11665
|
-
let
|
|
11666
|
-
if (
|
|
11667
|
-
revived:
|
|
11668
|
-
serialized: e
|
|
11669
|
-
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
|
|
11675
|
-
|
|
11681
|
+
let a = await t._reviveSvgObject(e);
|
|
11682
|
+
if (a) return t._restoreImageScale({
|
|
11683
|
+
revived: a,
|
|
11684
|
+
serialized: e,
|
|
11685
|
+
baseWidth: n,
|
|
11686
|
+
baseHeight: r,
|
|
11687
|
+
useRelativePositions: i
|
|
11688
|
+
}), a;
|
|
11689
|
+
}
|
|
11690
|
+
let a = (await w.enlivenObjects([e]))?.[0];
|
|
11691
|
+
return a ? (t._restoreImageScale({
|
|
11692
|
+
revived: a,
|
|
11693
|
+
serialized: e,
|
|
11694
|
+
baseWidth: n,
|
|
11695
|
+
baseHeight: r,
|
|
11696
|
+
useRelativePositions: i
|
|
11697
|
+
}), a) : null;
|
|
11676
11698
|
}))).filter((e) => !!e);
|
|
11677
11699
|
}
|
|
11678
|
-
static _restoreImageScale({ revived: e, serialized: n }) {
|
|
11700
|
+
static _restoreImageScale({ revived: e, serialized: n, baseWidth: r, baseHeight: i, useRelativePositions: a }) {
|
|
11679
11701
|
if ((typeof e.type == "string" ? e.type.toLowerCase() : "") !== "image") return;
|
|
11680
|
-
let
|
|
11702
|
+
let o = e, s = t._createImageRestorePlan({
|
|
11703
|
+
image: o,
|
|
11704
|
+
serialized: n
|
|
11705
|
+
});
|
|
11706
|
+
if (!s.hasIntrinsicSize) {
|
|
11707
|
+
o.set(s.nextProps);
|
|
11708
|
+
return;
|
|
11709
|
+
}
|
|
11710
|
+
let c = t._resolveImageTemplateCenter({
|
|
11711
|
+
image: o,
|
|
11712
|
+
serialized: n,
|
|
11713
|
+
plan: s,
|
|
11714
|
+
baseWidth: r,
|
|
11715
|
+
baseHeight: i,
|
|
11716
|
+
useRelativePositions: a
|
|
11717
|
+
});
|
|
11718
|
+
o.set(s.nextProps), t._restoreImageTemplateCenter({
|
|
11719
|
+
image: o,
|
|
11720
|
+
center: c,
|
|
11721
|
+
baseWidth: r,
|
|
11722
|
+
baseHeight: i,
|
|
11723
|
+
useRelativePositions: a
|
|
11724
|
+
});
|
|
11725
|
+
}
|
|
11726
|
+
static _createImageRestorePlan({ image: e, serialized: n }) {
|
|
11727
|
+
let { width: r, height: i } = t._getImageIntrinsicSize({ image: e }), { width: a, height: o, scaleX: s, scaleY: c, customData: l } = n, u = W({
|
|
11728
|
+
value: a,
|
|
11729
|
+
fallback: r
|
|
11730
|
+
}), d = W({
|
|
11731
|
+
value: o,
|
|
11732
|
+
fallback: i
|
|
11733
|
+
}), f = W({
|
|
11734
|
+
value: s,
|
|
11735
|
+
fallback: e.scaleX || 1
|
|
11736
|
+
}), p = W({
|
|
11737
|
+
value: c,
|
|
11738
|
+
fallback: e.scaleY || 1
|
|
11739
|
+
}), m = t._resolveImageFit({ customData: l });
|
|
11740
|
+
return {
|
|
11741
|
+
nextProps: t._resolveImageRestoreProps({
|
|
11742
|
+
imageFit: m,
|
|
11743
|
+
intrinsicWidth: r,
|
|
11744
|
+
intrinsicHeight: i,
|
|
11745
|
+
targetWidth: u,
|
|
11746
|
+
targetHeight: d,
|
|
11747
|
+
baseScaleX: f,
|
|
11748
|
+
baseScaleY: p
|
|
11749
|
+
}),
|
|
11750
|
+
targetWidth: u,
|
|
11751
|
+
targetHeight: d,
|
|
11752
|
+
baseScaleX: f,
|
|
11753
|
+
baseScaleY: p,
|
|
11754
|
+
hasIntrinsicSize: r > 0 && i > 0
|
|
11755
|
+
};
|
|
11756
|
+
}
|
|
11757
|
+
static _getImageIntrinsicSize({ image: e }) {
|
|
11758
|
+
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
11759
|
naturalWidth: 0,
|
|
11682
11760
|
naturalHeight: 0,
|
|
11683
11761
|
width: 0,
|
|
11684
11762
|
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
|
-
|
|
11763
|
+
};
|
|
11764
|
+
return {
|
|
11765
|
+
width: W({
|
|
11766
|
+
value: n || i || e.width,
|
|
11767
|
+
fallback: 0
|
|
11768
|
+
}),
|
|
11769
|
+
height: W({
|
|
11770
|
+
value: r || a || e.height,
|
|
11771
|
+
fallback: 0
|
|
11772
|
+
})
|
|
11773
|
+
};
|
|
11774
|
+
}
|
|
11775
|
+
static _resolveImageRestoreProps({ imageFit: e, intrinsicWidth: n, intrinsicHeight: r, targetWidth: i, targetHeight: a, baseScaleX: o, baseScaleY: s }) {
|
|
11776
|
+
let c = i * o, l = a * s, u = n > 0, d = r > 0, f = {};
|
|
11777
|
+
return u && (f.width = n), d && (f.height = r), !u || !d ? f : e === "stretch" ? (t._applyStretchedImageScale({
|
|
11778
|
+
nextProps: f,
|
|
11779
|
+
intrinsicWidth: n,
|
|
11780
|
+
intrinsicHeight: r,
|
|
11781
|
+
targetDisplayWidth: c,
|
|
11782
|
+
targetDisplayHeight: l
|
|
11783
|
+
}), f) : (t._applyContainedImageScale({
|
|
11784
|
+
nextProps: f,
|
|
11785
|
+
intrinsicWidth: n,
|
|
11786
|
+
intrinsicHeight: r,
|
|
11787
|
+
targetDisplayWidth: c,
|
|
11788
|
+
targetDisplayHeight: l
|
|
11789
|
+
}), f);
|
|
11790
|
+
}
|
|
11791
|
+
static _applyStretchedImageScale({ nextProps: e, intrinsicWidth: t, intrinsicHeight: n, targetDisplayWidth: r, targetDisplayHeight: i }) {
|
|
11792
|
+
let a = r > 0 ? r / t : null, o = i > 0 ? i / n : null;
|
|
11793
|
+
a && a > 0 && (e.scaleX = a), o && o > 0 && (e.scaleY = o);
|
|
11794
|
+
}
|
|
11795
|
+
static _applyContainedImageScale({ nextProps: e, intrinsicWidth: t, intrinsicHeight: n, targetDisplayWidth: r, targetDisplayHeight: i }) {
|
|
11796
|
+
if (r <= 0 || i <= 0) return;
|
|
11797
|
+
let a = Math.min(r / t, i / n);
|
|
11798
|
+
Number.isFinite(a) && a > 0 && (e.scaleX = a, e.scaleY = a);
|
|
11799
|
+
}
|
|
11800
|
+
static _resolveImageTemplateCenter({ image: e, serialized: n, plan: r, baseWidth: i, baseHeight: a, useRelativePositions: o }) {
|
|
11801
|
+
let s = {
|
|
11802
|
+
left: e.left,
|
|
11803
|
+
top: e.top,
|
|
11804
|
+
width: e.width,
|
|
11805
|
+
height: e.height,
|
|
11806
|
+
scaleX: e.scaleX,
|
|
11807
|
+
scaleY: e.scaleY
|
|
11808
|
+
}, c = t._resolveTemplatePlacement({
|
|
11809
|
+
image: e,
|
|
11810
|
+
serialized: n,
|
|
11811
|
+
baseWidth: i,
|
|
11812
|
+
baseHeight: a,
|
|
11813
|
+
useRelativePositions: o
|
|
11814
|
+
});
|
|
11815
|
+
e.set({
|
|
11816
|
+
left: c.x,
|
|
11817
|
+
top: c.y,
|
|
11818
|
+
width: r.targetWidth,
|
|
11819
|
+
height: r.targetHeight,
|
|
11820
|
+
scaleX: r.baseScaleX,
|
|
11821
|
+
scaleY: r.baseScaleY
|
|
11822
|
+
});
|
|
11823
|
+
let l = e.getPointByOrigin("center", "center");
|
|
11824
|
+
return e.set(s), {
|
|
11825
|
+
x: l.x,
|
|
11826
|
+
y: l.y
|
|
11827
|
+
};
|
|
11828
|
+
}
|
|
11829
|
+
static _resolveTemplatePlacement({ image: e, serialized: t, baseWidth: n, baseHeight: r, useRelativePositions: i }) {
|
|
11830
|
+
let a = W({
|
|
11831
|
+
value: t.left,
|
|
11832
|
+
fallback: e.left || 0
|
|
11833
|
+
}), o = W({
|
|
11834
|
+
value: t.top,
|
|
11835
|
+
fallback: e.top || 0
|
|
11836
|
+
});
|
|
11837
|
+
return i ? {
|
|
11838
|
+
x: a * (n || 1),
|
|
11839
|
+
y: o * (r || 1)
|
|
11840
|
+
} : {
|
|
11841
|
+
x: a,
|
|
11842
|
+
y: o
|
|
11843
|
+
};
|
|
11844
|
+
}
|
|
11845
|
+
static _restoreImageTemplateCenter({ image: e, center: t, baseWidth: n, baseHeight: r, useRelativePositions: i }) {
|
|
11846
|
+
e.setPositionByOrigin(new m(t.x, t.y), "center", "center"), i && e.set({
|
|
11847
|
+
left: W({
|
|
11848
|
+
value: e.left,
|
|
11849
|
+
fallback: 0
|
|
11850
|
+
}) / (n || 1),
|
|
11851
|
+
top: W({
|
|
11852
|
+
value: e.top,
|
|
11853
|
+
fallback: 0
|
|
11854
|
+
}) / (r || 1)
|
|
11855
|
+
});
|
|
11719
11856
|
}
|
|
11720
11857
|
static _resolveImageFit({ customData: e }) {
|
|
11721
11858
|
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.24",
|
|
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": [
|