@anu3ev/fabric-image-editor 0.5.28 → 0.5.29
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 +46 -39
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -35,7 +35,7 @@ var Z = (d, t, e) => new Promise((n, s) => {
|
|
|
35
35
|
}, a = (r) => r.done ? n(r.value) : Promise.resolve(r.value).then(o, i);
|
|
36
36
|
a((e = e.apply(d, t)).next());
|
|
37
37
|
});
|
|
38
|
-
import { ActiveSelection as X, Textbox as dt, util as
|
|
38
|
+
import { ActiveSelection as X, Textbox as dt, util as ft, controlsUtils as He, InteractiveFabricObject as Ze, Point as at, FitContentLayout as Ge, loadSVGFromURL as An, FabricImage as Xt, Gradient as Ve, Rect as jn, Circle as In, Triangle as Cn, Group as Nt, Color as Tn, classRegistry as Xe, loadSVGFromString as On, Canvas as En, Pattern as Ln } from "fabric";
|
|
39
39
|
import { create as Dn } from "jsondiffpatch";
|
|
40
40
|
import _n from "diff-match-patch";
|
|
41
41
|
var xn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", tt = function() {
|
|
@@ -503,52 +503,52 @@ class Nn {
|
|
|
503
503
|
this.worker.terminate();
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
|
-
const
|
|
506
|
+
const mt = 12, Bn = 2, Ae = 8, je = 20, zn = 100, Ie = 20, Ce = 8, Pn = 100, he = 32, Re = 1, Fn = "#2B2D33", ke = "#3D8BF4", Ne = "#FFFFFF";
|
|
507
507
|
function ae(d, t, e, n, s) {
|
|
508
|
-
const o =
|
|
509
|
-
d.save(), d.translate(t, e), d.rotate(
|
|
508
|
+
const o = mt, i = Bn;
|
|
509
|
+
d.save(), d.translate(t, e), d.rotate(ft.degreesToRadians(s.angle)), d.fillStyle = Ne, d.strokeStyle = ke, d.lineWidth = Re, d.beginPath(), d.roundRect(-o / 2, -o / 2, o, o, i), d.fill(), d.stroke(), d.restore();
|
|
510
510
|
}
|
|
511
511
|
function qe(d, t, e, n, s) {
|
|
512
512
|
const o = Ae, i = je, a = zn;
|
|
513
|
-
d.save(), d.translate(t, e), d.rotate(
|
|
513
|
+
d.save(), d.translate(t, e), d.rotate(ft.degreesToRadians(s.angle)), d.fillStyle = Ne, d.strokeStyle = ke, d.lineWidth = Re, d.beginPath(), d.roundRect(-o / 2, -i / 2, o, i, a), d.fill(), d.stroke(), d.restore();
|
|
514
514
|
}
|
|
515
515
|
function Je(d, t, e, n, s) {
|
|
516
516
|
const o = Ie, i = Ce, a = Pn;
|
|
517
|
-
d.save(), d.translate(t, e), d.rotate(
|
|
517
|
+
d.save(), d.translate(t, e), d.rotate(ft.degreesToRadians(s.angle)), d.fillStyle = Ne, d.strokeStyle = ke, d.lineWidth = Re, d.beginPath(), d.roundRect(-o / 2, -i / 2, o, i, a), d.fill(), d.stroke(), d.restore();
|
|
518
518
|
}
|
|
519
519
|
const Wn = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", pn = new Image();
|
|
520
520
|
pn.src = Wn;
|
|
521
521
|
function Un(d, t, e, n, s) {
|
|
522
522
|
const i = he / 2;
|
|
523
|
-
d.save(), d.translate(t, e), d.rotate(
|
|
523
|
+
d.save(), d.translate(t, e), d.rotate(ft.degreesToRadians(s.angle)), d.fillStyle = Fn, d.beginPath(), d.arc(0, 0, i, 0, 2 * Math.PI), d.fill(), d.drawImage(pn, -i / 2, -i / 2, i, i), d.restore();
|
|
524
524
|
}
|
|
525
525
|
const Yn = {
|
|
526
526
|
// Угловые точки
|
|
527
527
|
tl: {
|
|
528
528
|
render: ae,
|
|
529
|
-
sizeX:
|
|
530
|
-
sizeY:
|
|
529
|
+
sizeX: mt,
|
|
530
|
+
sizeY: mt,
|
|
531
531
|
offsetX: 0,
|
|
532
532
|
offsetY: 0
|
|
533
533
|
},
|
|
534
534
|
tr: {
|
|
535
535
|
render: ae,
|
|
536
|
-
sizeX:
|
|
537
|
-
sizeY:
|
|
536
|
+
sizeX: mt,
|
|
537
|
+
sizeY: mt,
|
|
538
538
|
offsetX: 0,
|
|
539
539
|
offsetY: 0
|
|
540
540
|
},
|
|
541
541
|
bl: {
|
|
542
542
|
render: ae,
|
|
543
|
-
sizeX:
|
|
544
|
-
sizeY:
|
|
543
|
+
sizeX: mt,
|
|
544
|
+
sizeY: mt,
|
|
545
545
|
offsetX: 0,
|
|
546
546
|
offsetY: 0
|
|
547
547
|
},
|
|
548
548
|
br: {
|
|
549
549
|
render: ae,
|
|
550
|
-
sizeX:
|
|
551
|
-
sizeY:
|
|
550
|
+
sizeX: mt,
|
|
551
|
+
sizeY: mt,
|
|
552
552
|
offsetX: 0,
|
|
553
553
|
offsetY: 0
|
|
554
554
|
},
|
|
@@ -1838,7 +1838,7 @@ const es = 0.1, ns = 2, tn = 0.1, ss = 90, Ft = 16, Wt = 16, Ot = 4096, Et = 409
|
|
|
1838
1838
|
"radiusBottomLeft",
|
|
1839
1839
|
"lineFontDefaults"
|
|
1840
1840
|
], is = 50;
|
|
1841
|
-
class
|
|
1841
|
+
class yt {
|
|
1842
1842
|
constructor({ editor: t }) {
|
|
1843
1843
|
this.editor = t, this.options = t.options, this._createdBlobUrls = [], this.acceptContentTypes = this.editor.options.acceptContentTypes, this.acceptFormats = this.getAllowedFormatsFromContentTypes();
|
|
1844
1844
|
}
|
|
@@ -1867,7 +1867,7 @@ class mt {
|
|
|
1867
1867
|
customData: c = null
|
|
1868
1868
|
} = t;
|
|
1869
1869
|
if (!e) return null;
|
|
1870
|
-
const { canvas: l, montageArea: h, transformManager: u, historyManager: f, errorManager: p } = this.editor, m = yield this.getContentType(e), g =
|
|
1870
|
+
const { canvas: l, montageArea: h, transformManager: u, historyManager: f, errorManager: p } = this.editor, m = yield this.getContentType(e), g = yt.getFormatFromContentType(m), { acceptContentTypes: v, acceptFormats: M } = this;
|
|
1871
1871
|
if (!this.isAllowedContentType(m)) {
|
|
1872
1872
|
const C = `Неверный contentType для изображения: ${m}. Ожидается один из: ${this.acceptContentTypes.join(", ")}.`;
|
|
1873
1873
|
return p.emitError({
|
|
@@ -1918,7 +1918,7 @@ class mt {
|
|
|
1918
1918
|
}), null;
|
|
1919
1919
|
if (this._createdBlobUrls.push(C), g === "svg") {
|
|
1920
1920
|
const b = yield An(C);
|
|
1921
|
-
y =
|
|
1921
|
+
y = ft.groupSVGElements(b.objects, b.options);
|
|
1922
1922
|
} else
|
|
1923
1923
|
y = yield Xt.fromURL(C, { crossOrigin: "anonymous" });
|
|
1924
1924
|
const { width: w, height: j } = y;
|
|
@@ -2024,7 +2024,7 @@ class mt {
|
|
|
2024
2024
|
exportAsBlob: o = !1
|
|
2025
2025
|
} = t, { canvas: i, montageArea: a, workerManager: r, interactionBlocker: c } = this.editor;
|
|
2026
2026
|
try {
|
|
2027
|
-
const l = n === "application/pdf", h = l ? "image/jpg" : n, u =
|
|
2027
|
+
const l = n === "application/pdf", h = l ? "image/jpg" : n, u = yt.getFormatFromContentType(h);
|
|
2028
2028
|
a.setCoords();
|
|
2029
2029
|
const { left: f, top: p, width: m, height: g } = a.getBoundingRect(), v = yield i.clone(["id", "format", "locked"]);
|
|
2030
2030
|
v.enableRetinaScaling = !1, ["image/jpg", "image/jpeg"].includes(h) && (v.backgroundColor = "#ffffff");
|
|
@@ -2039,7 +2039,7 @@ class mt {
|
|
|
2039
2039
|
const S = v.toSVG();
|
|
2040
2040
|
v.dispose();
|
|
2041
2041
|
const O = {
|
|
2042
|
-
image:
|
|
2042
|
+
image: yt._exportSVGStringAsFile(S, {
|
|
2043
2043
|
exportAsBase64: s,
|
|
2044
2044
|
exportAsBlob: o,
|
|
2045
2045
|
fileName: e
|
|
@@ -2148,9 +2148,9 @@ class mt {
|
|
|
2148
2148
|
data: { contentType: s, fileName: n, exportAsBase64: o, exportAsBlob: i }
|
|
2149
2149
|
}), null;
|
|
2150
2150
|
try {
|
|
2151
|
-
const l =
|
|
2151
|
+
const l = yt.getFormatFromContentType(s);
|
|
2152
2152
|
if (l === "svg") {
|
|
2153
|
-
const m = c.toSVG(), g =
|
|
2153
|
+
const m = c.toSVG(), g = yt._exportSVGStringAsFile(m, {
|
|
2154
2154
|
exportAsBase64: o,
|
|
2155
2155
|
exportAsBlob: i,
|
|
2156
2156
|
fileName: n
|
|
@@ -2228,7 +2228,7 @@ class mt {
|
|
|
2228
2228
|
* @returns массив допустимых форматов изображений
|
|
2229
2229
|
*/
|
|
2230
2230
|
getAllowedFormatsFromContentTypes() {
|
|
2231
|
-
return this.acceptContentTypes.map((t) =>
|
|
2231
|
+
return this.acceptContentTypes.map((t) => yt.getFormatFromContentType(t)).filter((t) => t);
|
|
2232
2232
|
}
|
|
2233
2233
|
/**
|
|
2234
2234
|
* Проверяет, является ли contentType допустимым типом изображения.
|
|
@@ -2281,7 +2281,7 @@ class mt {
|
|
|
2281
2281
|
try {
|
|
2282
2282
|
const s = (e = new URL(t).pathname.split(".").pop()) == null ? void 0 : e.toLowerCase(), o = {};
|
|
2283
2283
|
return this.acceptContentTypes.forEach((i) => {
|
|
2284
|
-
const a =
|
|
2284
|
+
const a = yt.getFormatFromContentType(i);
|
|
2285
2285
|
a && (o[a] = i);
|
|
2286
2286
|
}), s && o[s] || "application/octet-stream";
|
|
2287
2287
|
} catch (n) {
|
|
@@ -4623,7 +4623,7 @@ const ms = ({ textbox: d }) => {
|
|
|
4623
4623
|
);
|
|
4624
4624
|
if (n.length)
|
|
4625
4625
|
return (s = n[0]) == null ? void 0 : s[e];
|
|
4626
|
-
}, Ee = ({ strokeColor: d, width: t }) => t <= 0 ? null : d != null ? d : "#000000", Le = ({ width: d = 0 }) => d ? Math.max(0, d) : 0, Me = ({ value: d }) => typeof d == "string" ? d.toLocaleUpperCase() : "",
|
|
4626
|
+
}, Ee = ({ strokeColor: d, width: t }) => t <= 0 ? null : d != null ? d : "#000000", Le = ({ width: d = 0 }) => d ? Math.max(0, d) : 0, Me = ({ value: d }) => typeof d == "string" ? d.toLocaleUpperCase() : "", pt = ({
|
|
4627
4627
|
value: d,
|
|
4628
4628
|
min: t,
|
|
4629
4629
|
max: e
|
|
@@ -4779,10 +4779,10 @@ const ms = ({ textbox: d }) => {
|
|
|
4779
4779
|
var i, a, r, c;
|
|
4780
4780
|
const n = t / 2, s = e / 2, o = Math.min(n, s);
|
|
4781
4781
|
return {
|
|
4782
|
-
bottomLeft:
|
|
4783
|
-
bottomRight:
|
|
4784
|
-
topLeft:
|
|
4785
|
-
topRight:
|
|
4782
|
+
bottomLeft: pt({ value: (i = this.radiusBottomLeft) != null ? i : 0, min: 0, max: o }),
|
|
4783
|
+
bottomRight: pt({ value: (a = this.radiusBottomRight) != null ? a : 0, min: 0, max: o }),
|
|
4784
|
+
topLeft: pt({ value: (r = this.radiusTopLeft) != null ? r : 0, min: 0, max: o }),
|
|
4785
|
+
topRight: pt({ value: (c = this.radiusTopRight) != null ? c : 0, min: 0, max: o })
|
|
4786
4786
|
};
|
|
4787
4787
|
}
|
|
4788
4788
|
_getPadding() {
|
|
@@ -4798,7 +4798,7 @@ const ms = ({ textbox: d }) => {
|
|
|
4798
4798
|
var s;
|
|
4799
4799
|
const t = this.backgroundColor;
|
|
4800
4800
|
if (!t) return null;
|
|
4801
|
-
const e =
|
|
4801
|
+
const e = pt({ value: (s = this.backgroundOpacity) != null ? s : 1, min: 0, max: 1 });
|
|
4802
4802
|
let n;
|
|
4803
4803
|
try {
|
|
4804
4804
|
n = new Tn(t);
|
|
@@ -4826,7 +4826,7 @@ const ms = ({ textbox: d }) => {
|
|
|
4826
4826
|
topRight: l,
|
|
4827
4827
|
bottomRight: h,
|
|
4828
4828
|
bottomLeft: u
|
|
4829
|
-
} = s, f =
|
|
4829
|
+
} = s, f = pt({ value: c, min: 0, max: i }), p = pt({ value: l, min: 0, max: i }), m = pt({ value: h, min: 0, max: i }), g = pt({ value: u, min: 0, max: i });
|
|
4830
4830
|
t.beginPath(), t.moveTo(n + f, o), t.lineTo(a - p, o), t.quadraticCurveTo(a, o, a, o + p), t.lineTo(a, r - m), t.quadraticCurveTo(a, r, a - m, r), t.lineTo(n + g, r), t.quadraticCurveTo(n, r, n, r - g), t.lineTo(n, o + f), t.quadraticCurveTo(n, o, n + f, o), t.closePath();
|
|
4831
4831
|
}
|
|
4832
4832
|
/**
|
|
@@ -5247,8 +5247,8 @@ class st {
|
|
|
5247
5247
|
const ut = (Zt = s.width) != null ? Zt : I, Qt = ut !== At;
|
|
5248
5248
|
let jt = v;
|
|
5249
5249
|
Qt && (y || j) && (vt === "right" ? jt = rt - ut : vt === "center" && (jt = ct - ut / 2)), s.set({ left: jt }), i.baseLeft = jt, o.scaleX = 1, o.scaleY = 1;
|
|
5250
|
-
const { original:
|
|
5251
|
-
|
|
5250
|
+
const { original: gt } = o;
|
|
5251
|
+
gt && (gt.scaleX = 1, gt.scaleY = 1, gt.width = ut, gt.height = s.height, gt.left = jt), s.setCoords(), this.canvas.requestRenderAll(), i.baseWidth = ut, i.baseFontSize = (Gt = s.fontSize) != null ? Gt : O, i.baseStyles = JSON.parse(JSON.stringify((Vt = s.styles) != null ? Vt : {})), i.baseLineFontDefaults = an({
|
|
5252
5252
|
lineFontDefaults: s.lineFontDefaults
|
|
5253
5253
|
}), i.basePadding = {
|
|
5254
5254
|
top: G.top,
|
|
@@ -5614,8 +5614,8 @@ class st {
|
|
|
5614
5614
|
Q,
|
|
5615
5615
|
$
|
|
5616
5616
|
]
|
|
5617
|
-
}), { autoExpand:
|
|
5618
|
-
$t ? i.autoExpand = m !== !1 :
|
|
5617
|
+
}), { autoExpand: gt } = i, $t = m !== void 0, te = (m != null ? m : gt) !== !1;
|
|
5618
|
+
$t ? i.autoExpand = m !== !1 : gt === void 0 && (i.autoExpand = !0);
|
|
5619
5619
|
const ee = Object.prototype.hasOwnProperty.call(_, "width"), ne = te && !ee && (Lt || Ut || jt);
|
|
5620
5620
|
let xt = !1;
|
|
5621
5621
|
ne && (xt = this._autoExpandTextboxWidth(i, {
|
|
@@ -5637,6 +5637,13 @@ class st {
|
|
|
5637
5637
|
selectionStyles: L && Object.keys(G).length ? G : void 0
|
|
5638
5638
|
}), i;
|
|
5639
5639
|
}
|
|
5640
|
+
/**
|
|
5641
|
+
* Преобразует стили из массивного формата Fabric в объектный.
|
|
5642
|
+
*/
|
|
5643
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5644
|
+
stylesFromArray(t, e) {
|
|
5645
|
+
return ft.stylesFromArray(t, e);
|
|
5646
|
+
}
|
|
5640
5647
|
/**
|
|
5641
5648
|
* Уничтожает менеджер и снимает слушатели.
|
|
5642
5649
|
*/
|
|
@@ -6284,7 +6291,7 @@ class H {
|
|
|
6284
6291
|
if (i)
|
|
6285
6292
|
return H._restoreImageScale({ revived: i, serialized: n }), i;
|
|
6286
6293
|
}
|
|
6287
|
-
const s = yield
|
|
6294
|
+
const s = yield ft.enlivenObjects([n]), o = s == null ? void 0 : s[0];
|
|
6288
6295
|
return o ? (H._restoreImageScale({ revived: o, serialized: n }), o) : null;
|
|
6289
6296
|
})))).filter((n) => !!n);
|
|
6290
6297
|
});
|
|
@@ -6354,7 +6361,7 @@ class H {
|
|
|
6354
6361
|
const e = typeof t.svgMarkup == "string" ? t.svgMarkup : null;
|
|
6355
6362
|
if (!e) return null;
|
|
6356
6363
|
try {
|
|
6357
|
-
const n = yield On(e), s =
|
|
6364
|
+
const n = yield On(e), s = ft.groupSVGElements(n.objects, n.options), o = yield ft.enlivenObjectEnlivables(
|
|
6358
6365
|
H._prepareSerializableProps(t)
|
|
6359
6366
|
);
|
|
6360
6367
|
return s.set(o), s.setCoords(), s;
|
|
@@ -6718,7 +6725,7 @@ class H {
|
|
|
6718
6725
|
*/
|
|
6719
6726
|
// eslint-disable-next-line class-methods-use-this
|
|
6720
6727
|
enlivenObjectEnlivables(t) {
|
|
6721
|
-
return
|
|
6728
|
+
return ft.enlivenObjectEnlivables(t);
|
|
6722
6729
|
}
|
|
6723
6730
|
}
|
|
6724
6731
|
const Ns = 5, mn = "#3D8BF4", De = 1, de = 1, dn = ({
|
|
@@ -7763,7 +7770,7 @@ class Pe {
|
|
|
7763
7770
|
showRotationAngle: l,
|
|
7764
7771
|
_onReadyCallback: h
|
|
7765
7772
|
} = this.options;
|
|
7766
|
-
if (lt.apply(), this.canvas = new En(this.containerId, this.options), this.moduleLoader = new Rn(), this.workerManager = new Nn(), this.errorManager = new Jt({ editor: this }), this.historyManager = new K({ editor: this }), this.toolbar = new Qn({ editor: this }), this.transformManager = new cs({ editor: this }), this.zoomManager = new ls({ editor: this }), this.canvasManager = new rs({ editor: this }), this.imageManager = new
|
|
7773
|
+
if (lt.apply(), this.canvas = new En(this.containerId, this.options), this.moduleLoader = new Rn(), this.workerManager = new Nn(), this.errorManager = new Jt({ editor: this }), this.historyManager = new K({ editor: this }), this.toolbar = new Qn({ editor: this }), this.transformManager = new cs({ editor: this }), this.zoomManager = new ls({ editor: this }), this.canvasManager = new rs({ editor: this }), this.imageManager = new yt({ editor: this }), this.layerManager = new ue({ editor: this }), this.shapeManager = new hs({ editor: this }), this.interactionBlocker = new ds({ editor: this }), this.backgroundManager = new Bt({ editor: this }), this.clipboardManager = new us({ editor: this }), this.objectLockManager = new fe({ editor: this }), this.groupingManager = new fs({ editor: this }), this.selectionManager = new gs({ editor: this }), this.deletionManager = new ze({ editor: this }), this.panConstraintManager = new ps({ editor: this }), this.snappingManager = new pe({ editor: this }), this.measurementManager = new zt({ editor: this }), this.fontManager = new Te((u = this.options.fonts) != null ? u : []), this.textManager = new st({ editor: this }), this.templateManager = new H({ editor: this }), l && (this.angleIndicator = new Be({ editor: this })), this._createMontageArea(), this._createClippingArea(), this.listeners = new xe({ editor: this, options: this.options }), this.canvasManager.setEditorContainerWidth(t), this.canvasManager.setEditorContainerHeight(e), this.canvasManager.setCanvasWrapperWidth(n), this.canvasManager.setCanvasWrapperHeight(s), this.canvasManager.setCanvasCSSWidth(o), this.canvasManager.setCanvasCSSHeight(i), this.canvasManager.updateCanvas(), this.zoomManager.calculateAndApplyDefaultZoom(), yield this.fontManager.loadFonts(), a != null && a.source) {
|
|
7767
7774
|
const f = a, {
|
|
7768
7775
|
source: p,
|
|
7769
7776
|
scale: m = `image-${c}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anu3ev/fabric-image-editor",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.29",
|
|
4
4
|
"description": "JavaScript image editor 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": [
|