@anu3ev/fabric-image-editor 0.5.1 → 0.5.2
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 +32 -23
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -35,7 +35,7 @@ var _ = (h, t, e) => new Promise((s, o) => {
|
|
|
35
35
|
}, a = (r) => r.done ? s(r.value) : Promise.resolve(r.value).then(n, i);
|
|
36
36
|
a((e = e.apply(h, t)).next());
|
|
37
37
|
});
|
|
38
|
-
import { ActiveSelection as B, Textbox as st, util as
|
|
38
|
+
import { ActiveSelection as B, Textbox as st, util as rt, controlsUtils as Re, InteractiveFabricObject as _e, Point as $, FitContentLayout as Ne, loadSVGFromURL as ds, FabricImage as kt, Gradient as ke, Rect as ls, Circle as hs, Triangle as us, Group as wt, Color as gs, classRegistry as Be, loadSVGFromString as fs, Canvas as ps, Pattern as ms } from "fabric";
|
|
39
39
|
import { create as ys } from "jsondiffpatch";
|
|
40
40
|
import vs from "diff-match-patch";
|
|
41
41
|
var bs = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", Y = function() {
|
|
@@ -466,21 +466,21 @@ class Ss {
|
|
|
466
466
|
const it = 12, As = 2, ce = 8, de = 20, js = 100, le = 20, he = 8, Is = 100, Xt = 32, pe = 1, Cs = "#2B2D33", me = "#3D8BF4", ye = "#FFFFFF";
|
|
467
467
|
function Zt(h, t, e, s, o) {
|
|
468
468
|
const n = it, i = As;
|
|
469
|
-
h.save(), h.translate(t, e), h.rotate(
|
|
469
|
+
h.save(), h.translate(t, e), h.rotate(rt.degreesToRadians(o.angle)), h.fillStyle = ye, h.strokeStyle = me, h.lineWidth = pe, h.beginPath(), h.roundRect(-n / 2, -n / 2, n, n, i), h.fill(), h.stroke(), h.restore();
|
|
470
470
|
}
|
|
471
471
|
function xe(h, t, e, s, o) {
|
|
472
472
|
const n = ce, i = de, a = js;
|
|
473
|
-
h.save(), h.translate(t, e), h.rotate(
|
|
473
|
+
h.save(), h.translate(t, e), h.rotate(rt.degreesToRadians(o.angle)), h.fillStyle = ye, h.strokeStyle = me, h.lineWidth = pe, h.beginPath(), h.roundRect(-n / 2, -i / 2, n, i, a), h.fill(), h.stroke(), h.restore();
|
|
474
474
|
}
|
|
475
475
|
function ze(h, t, e, s, o) {
|
|
476
476
|
const n = le, i = he, a = Is;
|
|
477
|
-
h.save(), h.translate(t, e), h.rotate(
|
|
477
|
+
h.save(), h.translate(t, e), h.rotate(rt.degreesToRadians(o.angle)), h.fillStyle = ye, h.strokeStyle = me, h.lineWidth = pe, h.beginPath(), h.roundRect(-n / 2, -i / 2, n, i, a), h.fill(), h.stroke(), h.restore();
|
|
478
478
|
}
|
|
479
479
|
const Ts = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", $e = new Image();
|
|
480
480
|
$e.src = Ts;
|
|
481
481
|
function Es(h, t, e, s, o) {
|
|
482
482
|
const i = Xt / 2;
|
|
483
|
-
h.save(), h.translate(t, e), h.rotate(
|
|
483
|
+
h.save(), h.translate(t, e), h.rotate(rt.degreesToRadians(o.angle)), h.fillStyle = Cs, h.beginPath(), h.arc(0, 0, i, 0, 2 * Math.PI), h.fill(), h.drawImage($e, -i / 2, -i / 2, i, i), h.restore();
|
|
484
484
|
}
|
|
485
485
|
const Os = {
|
|
486
486
|
// Угловые точки
|
|
@@ -1585,7 +1585,7 @@ class at {
|
|
|
1585
1585
|
}), null;
|
|
1586
1586
|
if (this._createdBlobUrls.push(v), f === "svg") {
|
|
1587
1587
|
const S = yield ds(v);
|
|
1588
|
-
b =
|
|
1588
|
+
b = rt.groupSVGElements(S.objects, S.options);
|
|
1589
1589
|
} else
|
|
1590
1590
|
b = yield kt.fromURL(v, { crossOrigin: "anonymous" });
|
|
1591
1591
|
const { width: I, height: y } = b;
|
|
@@ -4488,11 +4488,11 @@ class q {
|
|
|
4488
4488
|
scaleX: 1,
|
|
4489
4489
|
scaleY: 1
|
|
4490
4490
|
});
|
|
4491
|
-
const
|
|
4492
|
-
let
|
|
4493
|
-
_t && (I || w) && (Tt === "right" ?
|
|
4491
|
+
const ct = (je = o.width) != null ? je : C, _t = Math.abs(ct - Jt) > J;
|
|
4492
|
+
let dt = m;
|
|
4493
|
+
_t && (I || w) && (Tt === "right" ? dt = Et - ct : Tt === "center" && (dt = Ot - ct / 2)), o.set({ left: dt }), i.baseLeft = dt, n.scaleX = 1, n.scaleY = 1;
|
|
4494
4494
|
const { original: ot } = n;
|
|
4495
|
-
ot && (ot.scaleX = 1, ot.scaleY = 1, ot.width =
|
|
4495
|
+
ot && (ot.scaleX = 1, ot.scaleY = 1, ot.width = ct, ot.height = o.height, ot.left = dt), o.setCoords(), this.canvas.requestRenderAll(), i.baseWidth = ct, i.baseFontSize = (Ie = o.fontSize) != null ? Ie : j, i.baseStyles = JSON.parse(JSON.stringify((Ce = o.styles) != null ? Ce : {})), i.basePadding = {
|
|
4496
4496
|
top: z.top,
|
|
4497
4497
|
right: z.right,
|
|
4498
4498
|
bottom: z.bottom,
|
|
@@ -4663,7 +4663,7 @@ class q {
|
|
|
4663
4663
|
* @param options.skipRender — не вызывать перерисовку канваса
|
|
4664
4664
|
*/
|
|
4665
4665
|
updateText({ target: t, style: e = {}, withoutSave: s, skipRender: o } = {}) {
|
|
4666
|
-
var Rt,
|
|
4666
|
+
var Rt, ct, _t, dt, ot, Nt;
|
|
4667
4667
|
const n = this._resolveTextObject(t);
|
|
4668
4668
|
if (!n) return null;
|
|
4669
4669
|
const { historyManager: i } = this.editor, { canvas: a } = this;
|
|
@@ -4726,7 +4726,7 @@ class q {
|
|
|
4726
4726
|
R && (H.fontStyle = W), z && (L.fontStyle = W, U && (V.fontStyle = W));
|
|
4727
4727
|
}
|
|
4728
4728
|
if (f !== void 0 && (R && (H.underline = f), z && (L.underline = f, U && (V.underline = f))), m !== void 0 && (R && (H.linethrough = m), z && (L.linethrough = m, U && (V.linethrough = m))), v !== void 0 && (L.textAlign = v), b !== void 0 && (R && (H.fill = b), z && (L.fill = b, U && (V.fill = b))), I !== void 0 || y !== void 0) {
|
|
4729
|
-
const W = R ? We({ textbox: n, range: R, property: "strokeWidth" }) : void 0, yt = R ? We({ textbox: n, range: R, property: "stroke" }) : void 0, Yt = (
|
|
4729
|
+
const W = R ? We({ textbox: n, range: R, property: "strokeWidth" }) : void 0, yt = R ? We({ textbox: n, range: R, property: "stroke" }) : void 0, Yt = (ct = (Rt = y != null ? y : W) != null ? Rt : n.strokeWidth) != null ? ct : 0, ht = Ge({ width: Yt }), Ft = (dt = (_t = I != null ? I : yt) != null ? _t : n.stroke) != null ? dt : void 0, vt = Ze({
|
|
4730
4730
|
strokeColor: Ft,
|
|
4731
4731
|
width: ht
|
|
4732
4732
|
});
|
|
@@ -5089,7 +5089,7 @@ const tt = ({
|
|
|
5089
5089
|
} catch (s) {
|
|
5090
5090
|
return null;
|
|
5091
5091
|
}
|
|
5092
|
-
},
|
|
5092
|
+
}, lt = ({
|
|
5093
5093
|
object: h
|
|
5094
5094
|
}) => {
|
|
5095
5095
|
if (!h) return null;
|
|
@@ -5314,7 +5314,7 @@ class D {
|
|
|
5314
5314
|
if (i)
|
|
5315
5315
|
return D._restoreImageScale({ revived: i, serialized: s }), i;
|
|
5316
5316
|
}
|
|
5317
|
-
const o = yield
|
|
5317
|
+
const o = yield rt.enlivenObjects([s]), n = o == null ? void 0 : o[0];
|
|
5318
5318
|
return n ? (D._restoreImageScale({ revived: n, serialized: s }), n) : null;
|
|
5319
5319
|
})))).filter((s) => !!s);
|
|
5320
5320
|
});
|
|
@@ -5359,7 +5359,7 @@ class D {
|
|
|
5359
5359
|
const e = typeof t.svgMarkup == "string" ? t.svgMarkup : null;
|
|
5360
5360
|
if (!e) return null;
|
|
5361
5361
|
try {
|
|
5362
|
-
const s = yield fs(e), o =
|
|
5362
|
+
const s = yield fs(e), o = rt.groupSVGElements(s.objects, s.options), n = yield rt.enlivenObjectEnlivables(
|
|
5363
5363
|
D._prepareSerializableProps(t)
|
|
5364
5364
|
);
|
|
5365
5365
|
return o.set(n), o.setCoords(), o;
|
|
@@ -5677,6 +5677,15 @@ class D {
|
|
|
5677
5677
|
const s = t;
|
|
5678
5678
|
return typeof s.src == "string" ? s.src : null;
|
|
5679
5679
|
}
|
|
5680
|
+
/**
|
|
5681
|
+
* Оживляет сериализованный объект, восстанавливая вложенные описания (градиенты, клиппаты и т.д.).
|
|
5682
|
+
* @param serialized - исходное сериализованное описание Fabric-объекта
|
|
5683
|
+
* @returns оживлённый объект с восстановленными вложенными структурами
|
|
5684
|
+
*/
|
|
5685
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5686
|
+
enlivenObjectEnlivables(t) {
|
|
5687
|
+
return rt.enlivenObjectEnlivables(t);
|
|
5688
|
+
}
|
|
5680
5689
|
}
|
|
5681
5690
|
const uo = 5, ts = "#3D8BF4", ge = 1, Ve = ({
|
|
5682
5691
|
anchors: h,
|
|
@@ -6188,7 +6197,7 @@ class wo {
|
|
|
6188
6197
|
return;
|
|
6189
6198
|
}
|
|
6190
6199
|
!this.anchors.vertical.length && !this.anchors.horizontal.length && this._cacheAnchors({ activeObject: e });
|
|
6191
|
-
let o =
|
|
6200
|
+
let o = lt({ object: e });
|
|
6192
6201
|
if (!o) {
|
|
6193
6202
|
this._clearGuides();
|
|
6194
6203
|
return;
|
|
@@ -6203,9 +6212,9 @@ class wo {
|
|
|
6203
6212
|
e.set({
|
|
6204
6213
|
left: m + c,
|
|
6205
6214
|
top: v + d
|
|
6206
|
-
}), e.setCoords(), o = (f =
|
|
6215
|
+
}), e.setCoords(), o = (f = lt({ object: e })) != null ? f : o;
|
|
6207
6216
|
}
|
|
6208
|
-
const u = this.cachedTargetBounds.length ? this.cachedTargetBounds : this._collectTargets({ activeObject: e }).map((m) =>
|
|
6217
|
+
const u = this.cachedTargetBounds.length ? this.cachedTargetBounds : this._collectTargets({ activeObject: e }).map((m) => lt({ object: m })).filter((m) => !!m), g = mo({
|
|
6209
6218
|
activeBounds: o,
|
|
6210
6219
|
candidates: u,
|
|
6211
6220
|
threshold: a,
|
|
@@ -6216,7 +6225,7 @@ class wo {
|
|
|
6216
6225
|
e.set({
|
|
6217
6226
|
left: m + g.deltaX,
|
|
6218
6227
|
top: v + g.deltaY
|
|
6219
|
-
}), e.setCoords(), o = (p =
|
|
6228
|
+
}), e.setCoords(), o = (p = lt({ object: e })) != null ? p : o;
|
|
6220
6229
|
}
|
|
6221
6230
|
this._applyGuides({
|
|
6222
6231
|
guides: l,
|
|
@@ -6286,10 +6295,10 @@ class wo {
|
|
|
6286
6295
|
_cacheAnchors({ activeObject: t }) {
|
|
6287
6296
|
const e = this._collectTargets({ activeObject: t }), s = { vertical: [], horizontal: [] }, o = [];
|
|
6288
6297
|
for (const a of e) {
|
|
6289
|
-
const r =
|
|
6298
|
+
const r = lt({ object: a });
|
|
6290
6299
|
r && (Xe({ anchors: s, bounds: r }), o.push(r));
|
|
6291
6300
|
}
|
|
6292
|
-
const { montageArea: n } = this.editor, i =
|
|
6301
|
+
const { montageArea: n } = this.editor, i = lt({ object: n });
|
|
6293
6302
|
if (i) {
|
|
6294
6303
|
Xe({ anchors: s, bounds: i });
|
|
6295
6304
|
const { left: a, right: r, top: c, bottom: d } = i;
|
|
@@ -6438,7 +6447,7 @@ class At {
|
|
|
6438
6447
|
this._clearGuides();
|
|
6439
6448
|
return;
|
|
6440
6449
|
}
|
|
6441
|
-
const n =
|
|
6450
|
+
const n = lt({ object: o });
|
|
6442
6451
|
if (!n) {
|
|
6443
6452
|
this._clearGuides();
|
|
6444
6453
|
return;
|
|
@@ -6446,7 +6455,7 @@ class At {
|
|
|
6446
6455
|
const i = At._resolveTarget({
|
|
6447
6456
|
event: t,
|
|
6448
6457
|
activeObject: o
|
|
6449
|
-
}), { montageArea: a } = s, r = i != null ? i : a, c = r === a, d =
|
|
6458
|
+
}), { montageArea: a } = s, r = i != null ? i : a, c = r === a, d = lt({ object: r });
|
|
6450
6459
|
if (!d) {
|
|
6451
6460
|
this._clearGuides();
|
|
6452
6461
|
return;
|
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.2",
|
|
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": [
|