@anu3ev/fabric-image-editor 0.1.57 → 0.1.59
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 +412 -415
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2,38 +2,38 @@ var fe = Object.defineProperty, je = Object.defineProperties;
|
|
|
2
2
|
var be = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var H = Object.getOwnPropertySymbols;
|
|
4
4
|
var ce = Object.prototype.hasOwnProperty, de = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var re = (
|
|
5
|
+
var re = (c, e, t) => e in c ? fe(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t, p = (c, e) => {
|
|
6
6
|
for (var t in e || (e = {}))
|
|
7
|
-
ce.call(e, t) && re(
|
|
7
|
+
ce.call(e, t) && re(c, t, e[t]);
|
|
8
8
|
if (H)
|
|
9
9
|
for (var t of H(e))
|
|
10
|
-
de.call(e, t) && re(
|
|
11
|
-
return
|
|
12
|
-
}, le = (
|
|
13
|
-
var Y = (
|
|
10
|
+
de.call(e, t) && re(c, t, e[t]);
|
|
11
|
+
return c;
|
|
12
|
+
}, le = (c, e) => je(c, be(e));
|
|
13
|
+
var Y = (c, e) => {
|
|
14
14
|
var t = {};
|
|
15
|
-
for (var s in
|
|
16
|
-
ce.call(
|
|
17
|
-
if (
|
|
18
|
-
for (var s of H(
|
|
19
|
-
e.indexOf(s) < 0 && de.call(
|
|
15
|
+
for (var s in c)
|
|
16
|
+
ce.call(c, s) && e.indexOf(s) < 0 && (t[s] = c[s]);
|
|
17
|
+
if (c != null && H)
|
|
18
|
+
for (var s of H(c))
|
|
19
|
+
e.indexOf(s) < 0 && de.call(c, s) && (t[s] = c[s]);
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
-
var I = (
|
|
23
|
-
var
|
|
22
|
+
var I = (c, e, t) => new Promise((s, n) => {
|
|
23
|
+
var i = (d) => {
|
|
24
24
|
try {
|
|
25
|
-
o(t.next(
|
|
25
|
+
o(t.next(d));
|
|
26
26
|
} catch (r) {
|
|
27
|
-
|
|
27
|
+
n(r);
|
|
28
28
|
}
|
|
29
|
-
}, a = (
|
|
29
|
+
}, a = (d) => {
|
|
30
30
|
try {
|
|
31
|
-
o(t.throw(
|
|
31
|
+
o(t.throw(d));
|
|
32
32
|
} catch (r) {
|
|
33
|
-
|
|
33
|
+
n(r);
|
|
34
34
|
}
|
|
35
|
-
}, o = (
|
|
36
|
-
o((t = t.apply(
|
|
35
|
+
}, o = (d) => d.done ? s(d.value) : Promise.resolve(d.value).then(i, a);
|
|
36
|
+
o((t = t.apply(c, e)).next());
|
|
37
37
|
});
|
|
38
38
|
import { ActiveSelection as v, util as R, controlsUtils as pe, InteractiveFabricObject as ye, loadSVGFromURL as Ie, FabricImage as Z, Point as _, Rect as ve, Circle as Ae, Triangle as Se, Group as X, Canvas as Ce, Pattern as Ne } from "fabric";
|
|
39
39
|
import { create as De } from "jsondiffpatch";
|
|
@@ -71,15 +71,15 @@ class z {
|
|
|
71
71
|
adaptCanvasToContainerOnResize: e,
|
|
72
72
|
canvasDragging: t,
|
|
73
73
|
mouseWheelZooming: s,
|
|
74
|
-
bringToFrontOnSelection:
|
|
75
|
-
copyObjectsByHotkey:
|
|
74
|
+
bringToFrontOnSelection: n,
|
|
75
|
+
copyObjectsByHotkey: i,
|
|
76
76
|
pasteImageFromClipboard: a,
|
|
77
77
|
undoRedoByHotKeys: o,
|
|
78
|
-
selectAllByHotkey:
|
|
78
|
+
selectAllByHotkey: d,
|
|
79
79
|
deleteObjectsByHotkey: r,
|
|
80
80
|
resetObjectFitByDoubleClick: l
|
|
81
81
|
} = this.options;
|
|
82
|
-
t && (this.canvas.on("mouse:down", this.handleCanvasDragStartBound), this.canvas.on("mouse:move", this.handleCanvasDraggingBound), this.canvas.on("mouse:up", this.handleCanvasDragEndBound), document.addEventListener("keydown", this.handleSpaceKeyDownBound, { capture: !0 }), document.addEventListener("keyup", this.handleSpaceKeyUpBound, { capture: !0 })), s && this.canvas.on("mouse:wheel", this.handleMouseWheelZoomBound),
|
|
82
|
+
t && (this.canvas.on("mouse:down", this.handleCanvasDragStartBound), this.canvas.on("mouse:move", this.handleCanvasDraggingBound), this.canvas.on("mouse:up", this.handleCanvasDragEndBound), document.addEventListener("keydown", this.handleSpaceKeyDownBound, { capture: !0 }), document.addEventListener("keyup", this.handleSpaceKeyUpBound, { capture: !0 })), s && this.canvas.on("mouse:wheel", this.handleMouseWheelZoomBound), n && (this.canvas.on("selection:created", this.handleBringToFrontBound), this.canvas.on("selection:updated", this.handleBringToFrontBound)), l && this.canvas.on("mouse:dblclick", this.handleResetObjectFitBound), e && window.addEventListener("resize", this.handleContainerResizeBound, { capture: !0 }), i && document.addEventListener("keydown", this.handleCopyEventBound, { capture: !0 }), a && document.addEventListener("paste", this.handlePasteEventBound, { capture: !0 }), o && (document.addEventListener("keydown", this.handleUndoRedoEventBound, { capture: !0 }), document.addEventListener("keyup", this.handleUndoRedoKeyUpBound, { capture: !0 })), d && document.addEventListener("keydown", this.handleSelectAllEventBound, { capture: !0 }), r && document.addEventListener("keydown", this.handleDeleteObjectsEventBound, { capture: !0 }), this.canvas.on("object:modified", this.handleObjectModifiedHistoryBound), this.canvas.on("object:rotating", this.handleObjectRotatingHistoryBound), this.canvas.on("object:added", this.handleObjectAddedHistoryBound), this.canvas.on("object:removed", this.handleObjectRemovedHistoryBound), this.canvas.on("object:added", this.handleOverlayUpdateBound), this.canvas.on("selection:created", this.handleOverlayUpdateBound), this.canvas.on("selection:created", this.handleLockedSelectionBound), this.canvas.on("selection:updated", this.handleLockedSelectionBound);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* При массовом выделении объектов удаляем из него залоченные.
|
|
@@ -89,19 +89,19 @@ class z {
|
|
|
89
89
|
*/
|
|
90
90
|
_filterLockedSelection({ selected: e, e: t }) {
|
|
91
91
|
if (!(e != null && e.length) || !(t instanceof MouseEvent) || e.length === 1 || !e.some((a) => a.locked)) return;
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
92
|
+
const n = e.filter((a) => !a.locked);
|
|
93
|
+
if (n.length === 0) {
|
|
94
94
|
this.canvas.discardActiveObject();
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
if (
|
|
98
|
-
this.canvas.setActiveObject(
|
|
97
|
+
if (n.length === 1) {
|
|
98
|
+
this.canvas.setActiveObject(n[0]);
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
const
|
|
101
|
+
const i = new v(n, {
|
|
102
102
|
canvas: this.canvas
|
|
103
103
|
});
|
|
104
|
-
this.canvas.setActiveObject(
|
|
104
|
+
this.canvas.setActiveObject(i), this.canvas.requestRenderAll();
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* Обработчики для сохранения состояния редактора в истории.
|
|
@@ -142,8 +142,8 @@ class z {
|
|
|
142
142
|
* @param event.code — код клавиши
|
|
143
143
|
*/
|
|
144
144
|
handleCopyEvent(e) {
|
|
145
|
-
const { ctrlKey: t, metaKey: s, code:
|
|
146
|
-
!t && !s ||
|
|
145
|
+
const { ctrlKey: t, metaKey: s, code: n } = e;
|
|
146
|
+
!t && !s || n !== "KeyC" || (e.preventDefault(), this.editor.clipboardManager.copy());
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* Обработчик вставки объекта или изображения из буфера обмена.
|
|
@@ -161,8 +161,8 @@ class z {
|
|
|
161
161
|
*/
|
|
162
162
|
handleUndoRedoEvent(e) {
|
|
163
163
|
return I(this, null, function* () {
|
|
164
|
-
const { ctrlKey: t, metaKey: s, code:
|
|
165
|
-
!t && !s ||
|
|
164
|
+
const { ctrlKey: t, metaKey: s, code: n, repeat: i } = e;
|
|
165
|
+
!t && !s || i || !/Mac/i.test(navigator.userAgent) && this.isUndoRedoKeyPressed || (n === "KeyZ" ? (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.undo()) : n === "KeyY" && (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.redo()));
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
@@ -181,8 +181,8 @@ class z {
|
|
|
181
181
|
* @param event.code — код клавиши
|
|
182
182
|
*/
|
|
183
183
|
handleSelectAllEvent(e) {
|
|
184
|
-
const { ctrlKey: t, metaKey: s, code:
|
|
185
|
-
!t && !s ||
|
|
184
|
+
const { ctrlKey: t, metaKey: s, code: n } = e;
|
|
185
|
+
!t && !s || n !== "KeyA" || (e.preventDefault(), this.editor.selectionManager.selectAll());
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
188
188
|
* Обработчик для удаления объектов (Delete).
|
|
@@ -200,8 +200,8 @@ class z {
|
|
|
200
200
|
*/
|
|
201
201
|
handleSpaceKeyDown(e) {
|
|
202
202
|
if (e.code !== "Space") return;
|
|
203
|
-
const { canvas: t, editor: s, isSpacePressed:
|
|
204
|
-
|
|
203
|
+
const { canvas: t, editor: s, isSpacePressed: n, isDragging: i } = this;
|
|
204
|
+
n || i || (this.isSpacePressed = !0, e.preventDefault(), t.set({
|
|
205
205
|
selection: !1,
|
|
206
206
|
defaultCursor: "grab"
|
|
207
207
|
}), t.setCursor("grab"), s.canvasManager.getObjects().forEach((a) => {
|
|
@@ -299,9 +299,9 @@ class z {
|
|
|
299
299
|
*/
|
|
300
300
|
static debounce(e, t) {
|
|
301
301
|
let s = null;
|
|
302
|
-
return function(...
|
|
302
|
+
return function(...n) {
|
|
303
303
|
s !== null && clearTimeout(s), s = setTimeout(() => {
|
|
304
|
-
e.apply(this,
|
|
304
|
+
e.apply(this, n);
|
|
305
305
|
}, t);
|
|
306
306
|
};
|
|
307
307
|
}
|
|
@@ -324,11 +324,11 @@ class Ee {
|
|
|
324
324
|
return this.loaders[e] ? (this.cache.has(e) || this.cache.set(e, this.loaders[e]()), this.cache.get(e)) : Promise.reject(new Error(`Unknown module "${e}"`));
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
function Oe(
|
|
327
|
+
function Oe(c) {
|
|
328
328
|
return new Worker(
|
|
329
329
|
"" + new URL("assets/worker-Cmho-Hr0.js", import.meta.url).href,
|
|
330
330
|
{
|
|
331
|
-
name:
|
|
331
|
+
name: c == null ? void 0 : c.name
|
|
332
332
|
}
|
|
333
333
|
);
|
|
334
334
|
}
|
|
@@ -351,12 +351,12 @@ class Te {
|
|
|
351
351
|
* @returns
|
|
352
352
|
*/
|
|
353
353
|
_handleMessage({ data: e }) {
|
|
354
|
-
const { requestId: t, success: s, data:
|
|
354
|
+
const { requestId: t, success: s, data: n, error: i } = e, a = this._callbacks.get(t);
|
|
355
355
|
if (!a) {
|
|
356
356
|
console.warn(`No callback found for requestId: ${t}`);
|
|
357
357
|
return;
|
|
358
358
|
}
|
|
359
|
-
s ? a.resolve(
|
|
359
|
+
s ? a.resolve(n) : a.reject(new Error(i)), this._callbacks.delete(t);
|
|
360
360
|
}
|
|
361
361
|
/**
|
|
362
362
|
* Универсальный метод отправки команды в воркер
|
|
@@ -366,9 +366,9 @@ class Te {
|
|
|
366
366
|
* @returns Promise, который будет выполнен, когда воркер вернет ответ
|
|
367
367
|
*/
|
|
368
368
|
post(e, t, s = []) {
|
|
369
|
-
const
|
|
370
|
-
return new Promise((
|
|
371
|
-
this._callbacks.set(
|
|
369
|
+
const n = `${e}:${L(8)}`;
|
|
370
|
+
return new Promise((i, a) => {
|
|
371
|
+
this._callbacks.set(n, { resolve: i, reject: a }), this.worker.postMessage({ action: e, payload: t, requestId: n }, s);
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
/**
|
|
@@ -379,23 +379,23 @@ class Te {
|
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
const N = 12, ke = 2, Q = 8, J = 20, xe = 100, $ = 20, K = 8, Be = 100, q = 32, ee = 1, Ze = "#2B2D33", te = "#3D8BF4", se = "#FFFFFF";
|
|
382
|
-
function W(
|
|
383
|
-
const
|
|
384
|
-
|
|
382
|
+
function W(c, e, t, s, n) {
|
|
383
|
+
const i = N, a = ke;
|
|
384
|
+
c.save(), c.translate(e, t), c.rotate(R.degreesToRadians(n.angle)), c.fillStyle = se, c.strokeStyle = te, c.lineWidth = ee, c.beginPath(), c.roundRect(-12 / 2, -12 / 2, i, i, a), c.fill(), c.stroke(), c.restore();
|
|
385
385
|
}
|
|
386
|
-
function he(
|
|
387
|
-
const
|
|
388
|
-
|
|
386
|
+
function he(c, e, t, s, n) {
|
|
387
|
+
const i = Q, a = J, o = xe;
|
|
388
|
+
c.save(), c.translate(e, t), c.rotate(R.degreesToRadians(n.angle)), c.fillStyle = se, c.strokeStyle = te, c.lineWidth = ee, c.beginPath(), c.roundRect(-8 / 2, -20 / 2, i, a, o), c.fill(), c.stroke(), c.restore();
|
|
389
389
|
}
|
|
390
|
-
function ge(
|
|
391
|
-
const
|
|
392
|
-
|
|
390
|
+
function ge(c, e, t, s, n) {
|
|
391
|
+
const i = $, a = K, o = Be;
|
|
392
|
+
c.save(), c.translate(e, t), c.rotate(R.degreesToRadians(n.angle)), c.fillStyle = se, c.strokeStyle = te, c.lineWidth = ee, c.beginPath(), c.roundRect(-20 / 2, -8 / 2, i, a, o), c.fill(), c.stroke(), c.restore();
|
|
393
393
|
}
|
|
394
394
|
const Ue = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", ue = new Image();
|
|
395
395
|
ue.src = Ue;
|
|
396
|
-
function ze(
|
|
396
|
+
function ze(c, e, t, s, n) {
|
|
397
397
|
const a = q / 2;
|
|
398
|
-
|
|
398
|
+
c.save(), c.translate(e, t), c.rotate(R.degreesToRadians(n.angle)), c.fillStyle = Ze, c.beginPath(), c.arc(0, 0, a, 0, 2 * Math.PI), c.fill(), c.drawImage(ue, -16 / 2, -16 / 2, a, a), c.restore();
|
|
399
399
|
}
|
|
400
400
|
const Re = {
|
|
401
401
|
// Угловые точки
|
|
@@ -476,7 +476,7 @@ class He {
|
|
|
476
476
|
sizeY: s.sizeY,
|
|
477
477
|
offsetX: s.offsetX,
|
|
478
478
|
offsetY: s.offsetY
|
|
479
|
-
}), t === "mtr" && (e[t].cursorStyle = "grab", e[t].mouseDownHandler = (
|
|
479
|
+
}), t === "mtr" && (e[t].cursorStyle = "grab", e[t].mouseDownHandler = (i, a, o, d) => {
|
|
480
480
|
var l;
|
|
481
481
|
(l = a.target.canvas) == null || l.setCursor("grabbing");
|
|
482
482
|
});
|
|
@@ -560,29 +560,31 @@ const Ye = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj
|
|
|
560
560
|
sendBackwards: Fe
|
|
561
561
|
},
|
|
562
562
|
handlers: {
|
|
563
|
-
copyPaste: (
|
|
564
|
-
yield
|
|
563
|
+
copyPaste: (c) => I(void 0, null, function* () {
|
|
564
|
+
yield c.clipboardManager.copy(), yield c.clipboardManager.paste(), c.clipboardManager.clipboard && c.canvas.fire("editor:object-duplicated", {
|
|
565
|
+
object: c.clipboardManager.clipboard
|
|
566
|
+
});
|
|
565
567
|
}),
|
|
566
|
-
delete: (
|
|
567
|
-
|
|
568
|
+
delete: (c) => {
|
|
569
|
+
c.deletionManager.deleteSelectedObjects();
|
|
568
570
|
},
|
|
569
|
-
lock: (
|
|
570
|
-
|
|
571
|
+
lock: (c) => {
|
|
572
|
+
c.objectLockManager.lockObject();
|
|
571
573
|
},
|
|
572
|
-
unlock: (
|
|
573
|
-
|
|
574
|
+
unlock: (c) => {
|
|
575
|
+
c.objectLockManager.unlockObject();
|
|
574
576
|
},
|
|
575
|
-
bringForward: (
|
|
576
|
-
|
|
577
|
+
bringForward: (c) => {
|
|
578
|
+
c.layerManager.bringForward();
|
|
577
579
|
},
|
|
578
|
-
bringToFront: (
|
|
579
|
-
|
|
580
|
+
bringToFront: (c) => {
|
|
581
|
+
c.layerManager.bringToFront();
|
|
580
582
|
},
|
|
581
|
-
sendToBack: (
|
|
582
|
-
|
|
583
|
+
sendToBack: (c) => {
|
|
584
|
+
c.layerManager.sendToBack();
|
|
583
585
|
},
|
|
584
|
-
sendBackwards: (
|
|
585
|
-
|
|
586
|
+
sendBackwards: (c) => {
|
|
587
|
+
c.layerManager.sendBackwards();
|
|
586
588
|
}
|
|
587
589
|
}
|
|
588
590
|
};
|
|
@@ -608,11 +610,11 @@ class Qe {
|
|
|
608
610
|
_createDOM() {
|
|
609
611
|
const { style: e } = this.config;
|
|
610
612
|
this.el = document.createElement("div"), Object.assign(this.el.style, e), this.canvas.wrapperEl.appendChild(this.el), this._onBtnOver = (t) => {
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
+
const n = t.target.closest("button");
|
|
614
|
+
n && Object.assign(n.style, this.config.btnHover);
|
|
613
615
|
}, this._onBtnOut = (t) => {
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
+
const n = t.target.closest("button");
|
|
617
|
+
n && Object.assign(n.style, this.config.btnStyle);
|
|
616
618
|
}, this.el.addEventListener("mouseover", this._onBtnOver), this.el.addEventListener("mouseout", this._onBtnOut);
|
|
617
619
|
}
|
|
618
620
|
/**
|
|
@@ -624,11 +626,11 @@ class Qe {
|
|
|
624
626
|
_renderButtons(e) {
|
|
625
627
|
this.el.innerHTML = "";
|
|
626
628
|
for (const t of e) {
|
|
627
|
-
const { name: s, handle:
|
|
628
|
-
|
|
629
|
+
const { name: s, handle: n } = t, { icons: i = {}, btnStyle: a, handlers: o = {} } = this.config, d = document.createElement("button");
|
|
630
|
+
d.innerHTML = i[n] ? `<img src="${i[n]}" title="${s}" />` : s, Object.assign(d.style, a), d.onclick = () => {
|
|
629
631
|
var r;
|
|
630
|
-
return (r = o[
|
|
631
|
-
}, this.el.appendChild(
|
|
632
|
+
return (r = o[n]) == null ? void 0 : r.call(o, this.editor);
|
|
633
|
+
}, this.el.appendChild(d);
|
|
632
634
|
}
|
|
633
635
|
}
|
|
634
636
|
/**
|
|
@@ -684,9 +686,9 @@ class Qe {
|
|
|
684
686
|
this.el.style.display = "none";
|
|
685
687
|
return;
|
|
686
688
|
}
|
|
687
|
-
const { el: t, config: s, canvas:
|
|
689
|
+
const { el: t, config: s, canvas: n } = this;
|
|
688
690
|
e.setCoords();
|
|
689
|
-
const
|
|
691
|
+
const i = n.getZoom(), [, , , , a, o] = n.viewportTransform, { x: d } = e.getCenterPoint(), { top: r, height: l } = e.getBoundingRect(), g = d * i + a - t.offsetWidth / 2, u = s.offsetTop || 0, m = (r + l) * i + o + u;
|
|
690
692
|
Object.assign(t.style, {
|
|
691
693
|
left: `${g}px`,
|
|
692
694
|
top: `${m}px`,
|
|
@@ -766,10 +768,10 @@ class Je {
|
|
|
766
768
|
*/
|
|
767
769
|
getFullState() {
|
|
768
770
|
const { baseState: e, currentIndex: t, patches: s } = this;
|
|
769
|
-
let
|
|
770
|
-
for (let
|
|
771
|
-
|
|
772
|
-
return console.log("getFullState state",
|
|
771
|
+
let n = JSON.parse(JSON.stringify(e));
|
|
772
|
+
for (let i = 0; i < t; i += 1)
|
|
773
|
+
n = this.diffPatcher.patch(n, s[i].diff);
|
|
774
|
+
return console.log("getFullState state", n), n;
|
|
773
775
|
}
|
|
774
776
|
/**
|
|
775
777
|
* Сохраняем текущее состояние в виде диффа от последнего сохранённого полного состояния.
|
|
@@ -813,12 +815,12 @@ class Je {
|
|
|
813
815
|
return I(this, null, function* () {
|
|
814
816
|
if (!e) return;
|
|
815
817
|
console.log("loadStateFromFullState fullState", e);
|
|
816
|
-
const { canvas: t, canvasManager: s, interactionBlocker:
|
|
818
|
+
const { canvas: t, canvasManager: s, interactionBlocker: n } = this.editor, { width: i, height: a } = t;
|
|
817
819
|
yield t.loadFromJSON(e);
|
|
818
820
|
const o = t.getObjects().find((r) => r.id === "montage-area");
|
|
819
|
-
o && (this.editor.montageArea = o, (
|
|
820
|
-
const
|
|
821
|
-
|
|
821
|
+
o && (this.editor.montageArea = o, (i !== t.getWidth() || a !== t.getHeight()) && s.updateCanvas());
|
|
822
|
+
const d = t.getObjects().find((r) => r.id === "overlay-mask");
|
|
823
|
+
d && (n.overlayMask = d, n.overlayMask.visible = !1), t.renderAll(), t.fire("editor:history-state-loaded", {
|
|
822
824
|
fullState: e,
|
|
823
825
|
currentIndex: this.currentIndex,
|
|
824
826
|
totalChangesCount: this.totalChangesCount,
|
|
@@ -925,10 +927,10 @@ class D {
|
|
|
925
927
|
const {
|
|
926
928
|
source: t,
|
|
927
929
|
scale: s = `image-${this.options.scaleType}`,
|
|
928
|
-
withoutSave:
|
|
930
|
+
withoutSave: n = !1
|
|
929
931
|
} = e;
|
|
930
932
|
if (!t) return null;
|
|
931
|
-
const { canvas:
|
|
933
|
+
const { canvas: i, montageArea: a, transformManager: o, historyManager: d, errorManager: r } = this.editor, l = yield this.getContentType(t), h = D.getFormatFromContentType(l), { acceptContentTypes: g, acceptFormats: u } = this;
|
|
932
934
|
if (!this.isAllowedContentType(l)) {
|
|
933
935
|
const m = `Неверный contentType для изображения: ${l}. Ожидается один из: ${this.acceptContentTypes.join(", ")}.`;
|
|
934
936
|
return r.emitError({
|
|
@@ -939,7 +941,7 @@ class D {
|
|
|
939
941
|
data: { source: t, format: h, contentType: l, acceptContentTypes: g, acceptFormats: u }
|
|
940
942
|
}), null;
|
|
941
943
|
}
|
|
942
|
-
|
|
944
|
+
d.suspendHistory();
|
|
943
945
|
try {
|
|
944
946
|
let m, M;
|
|
945
947
|
if (t instanceof File)
|
|
@@ -978,24 +980,24 @@ class D {
|
|
|
978
980
|
const { width: b, height: S } = a, w = this.calculateScaleFactor({ imageObject: M, scaleType: s });
|
|
979
981
|
s === "image-contain" && w < 1 ? o.fitObject({ object: M, type: "contain", withoutSave: !0 }) : s === "image-cover" && (f > b || j > S) && o.fitObject({ object: M, type: "cover", withoutSave: !0 });
|
|
980
982
|
}
|
|
981
|
-
|
|
983
|
+
i.add(M), i.centerObject(M), i.setActiveObject(M), i.renderAll(), d.resumeHistory(), n || d.saveState();
|
|
982
984
|
const A = {
|
|
983
985
|
image: M,
|
|
984
986
|
format: h,
|
|
985
987
|
contentType: l,
|
|
986
988
|
scale: s,
|
|
987
|
-
withoutSave:
|
|
989
|
+
withoutSave: n,
|
|
988
990
|
source: t
|
|
989
991
|
};
|
|
990
|
-
return
|
|
992
|
+
return i.fire("editor:image-imported", A), A;
|
|
991
993
|
} catch (m) {
|
|
992
994
|
return r.emitError({
|
|
993
995
|
origin: "ImageManager",
|
|
994
996
|
method: "importImage",
|
|
995
997
|
code: "IMPORT_FAILED",
|
|
996
998
|
message: `Ошибка импорта изображения: ${m.message}`,
|
|
997
|
-
data: { source: t, format: h, contentType: l, scale: s, withoutSave:
|
|
998
|
-
}),
|
|
999
|
+
data: { source: t, format: h, contentType: l, scale: s, withoutSave: n }
|
|
1000
|
+
}), d.resumeHistory(), null;
|
|
999
1001
|
}
|
|
1000
1002
|
});
|
|
1001
1003
|
}
|
|
@@ -1011,7 +1013,7 @@ class D {
|
|
|
1011
1013
|
return I(this, null, function* () {
|
|
1012
1014
|
let s = `Размер изображения больше максимального размера канваса, поэтому оно будет уменьшено до максимальных размеров c сохранением пропорций: ${O}x${T}`;
|
|
1013
1015
|
t === "min" && (s = `Размер изображения меньше минимального размера канваса, поэтому оно будет увеличено до минимальных размеров c сохранением пропорций: ${x}x${B}`);
|
|
1014
|
-
const
|
|
1016
|
+
const n = {
|
|
1015
1017
|
dataURL: e,
|
|
1016
1018
|
sizeType: t,
|
|
1017
1019
|
maxWidth: O,
|
|
@@ -1024,8 +1026,8 @@ class D {
|
|
|
1024
1026
|
method: "resizeImageToBoundaries",
|
|
1025
1027
|
code: "IMAGE_RESIZE_WARNING",
|
|
1026
1028
|
message: s,
|
|
1027
|
-
data:
|
|
1028
|
-
}), this.editor.workerManager.post("resizeImage",
|
|
1029
|
+
data: n
|
|
1030
|
+
}), this.editor.workerManager.post("resizeImage", n);
|
|
1029
1031
|
});
|
|
1030
1032
|
}
|
|
1031
1033
|
/**
|
|
@@ -1044,9 +1046,9 @@ class D {
|
|
|
1044
1046
|
const {
|
|
1045
1047
|
fileName: t = "image.png",
|
|
1046
1048
|
contentType: s = "image/png",
|
|
1047
|
-
exportAsBase64:
|
|
1048
|
-
exportAsBlob:
|
|
1049
|
-
} = e, { canvas: a, montageArea: o, workerManager:
|
|
1049
|
+
exportAsBase64: n = !1,
|
|
1050
|
+
exportAsBlob: i = !1
|
|
1051
|
+
} = e, { canvas: a, montageArea: o, workerManager: d } = this.editor;
|
|
1050
1052
|
try {
|
|
1051
1053
|
const r = s === "application/pdf", l = r ? "image/jpg" : s, h = D.getFormatFromContentType(l);
|
|
1052
1054
|
o.setCoords();
|
|
@@ -1060,8 +1062,8 @@ class D {
|
|
|
1060
1062
|
f.dispose();
|
|
1061
1063
|
const C = {
|
|
1062
1064
|
image: D._exportSVGStringAsFile(y, {
|
|
1063
|
-
exportAsBase64:
|
|
1064
|
-
exportAsBlob:
|
|
1065
|
+
exportAsBase64: n,
|
|
1066
|
+
exportAsBlob: i,
|
|
1065
1067
|
fileName: t
|
|
1066
1068
|
}),
|
|
1067
1069
|
format: "svg",
|
|
@@ -1075,7 +1077,7 @@ class D {
|
|
|
1075
1077
|
C ? y(C) : k(new Error("Failed to create Blob from canvas"));
|
|
1076
1078
|
});
|
|
1077
1079
|
});
|
|
1078
|
-
if (f.dispose(),
|
|
1080
|
+
if (f.dispose(), i) {
|
|
1079
1081
|
const y = {
|
|
1080
1082
|
image: b,
|
|
1081
1083
|
format: h,
|
|
@@ -1084,7 +1086,7 @@ class D {
|
|
|
1084
1086
|
};
|
|
1085
1087
|
return a.fire("editor:canvas-exported", y), y;
|
|
1086
1088
|
}
|
|
1087
|
-
const S = yield createImageBitmap(b), w = yield
|
|
1089
|
+
const S = yield createImageBitmap(b), w = yield d.post(
|
|
1088
1090
|
"toDataURL",
|
|
1089
1091
|
{ format: h, quality: 1, bitmap: S },
|
|
1090
1092
|
[S]
|
|
@@ -1095,7 +1097,7 @@ class D {
|
|
|
1095
1097
|
unit: "mm",
|
|
1096
1098
|
format: [k, C]
|
|
1097
1099
|
});
|
|
1098
|
-
if (G.addImage(String(w), "JPG", 0, 0, k, C),
|
|
1100
|
+
if (G.addImage(String(w), "JPG", 0, 0, k, C), n) {
|
|
1099
1101
|
const oe = {
|
|
1100
1102
|
image: G.output("datauristring"),
|
|
1101
1103
|
format: "pdf",
|
|
@@ -1112,7 +1114,7 @@ class D {
|
|
|
1112
1114
|
};
|
|
1113
1115
|
return a.fire("editor:canvas-exported", ae), ae;
|
|
1114
1116
|
}
|
|
1115
|
-
if (
|
|
1117
|
+
if (n) {
|
|
1116
1118
|
const y = {
|
|
1117
1119
|
image: w,
|
|
1118
1120
|
format: h,
|
|
@@ -1121,20 +1123,20 @@ class D {
|
|
|
1121
1123
|
};
|
|
1122
1124
|
return a.fire("editor:canvas-exported", y), y;
|
|
1123
1125
|
}
|
|
1124
|
-
const E = h === "svg" && !A ? t.replace(/\.[^/.]+$/, ".png") : t,
|
|
1126
|
+
const E = h === "svg" && !A ? t.replace(/\.[^/.]+$/, ".png") : t, ie = {
|
|
1125
1127
|
image: new File([b], E, { type: l }),
|
|
1126
1128
|
format: h,
|
|
1127
1129
|
contentType: l,
|
|
1128
1130
|
fileName: E
|
|
1129
1131
|
};
|
|
1130
|
-
return a.fire("editor:canvas-exported",
|
|
1132
|
+
return a.fire("editor:canvas-exported", ie), ie;
|
|
1131
1133
|
} catch (r) {
|
|
1132
1134
|
return this.editor.errorManager.emitError({
|
|
1133
1135
|
origin: "ImageManager",
|
|
1134
1136
|
method: "exportCanvasAsImageFile",
|
|
1135
1137
|
code: "IMAGE_EXPORT_FAILED",
|
|
1136
1138
|
message: `Ошибка экспорта изображения: ${r.message}`,
|
|
1137
|
-
data: { contentType: s, fileName: t, exportAsBase64:
|
|
1139
|
+
data: { contentType: s, fileName: t, exportAsBase64: n, exportAsBlob: i }
|
|
1138
1140
|
}), null;
|
|
1139
1141
|
}
|
|
1140
1142
|
});
|
|
@@ -1155,23 +1157,23 @@ class D {
|
|
|
1155
1157
|
const {
|
|
1156
1158
|
object: t,
|
|
1157
1159
|
fileName: s = "image.png",
|
|
1158
|
-
contentType:
|
|
1159
|
-
exportAsBase64:
|
|
1160
|
+
contentType: n = "image/png",
|
|
1161
|
+
exportAsBase64: i = !1,
|
|
1160
1162
|
exportAsBlob: a = !1
|
|
1161
|
-
} = e, { canvas: o, workerManager:
|
|
1163
|
+
} = e, { canvas: o, workerManager: d } = this.editor, r = t || o.getActiveObject();
|
|
1162
1164
|
if (!r)
|
|
1163
1165
|
return this.editor.errorManager.emitError({
|
|
1164
1166
|
origin: "ImageManager",
|
|
1165
1167
|
method: "exportObjectAsImageFile",
|
|
1166
1168
|
code: "NO_OBJECT_SELECTED",
|
|
1167
1169
|
message: "Не выбран объект для экспорта",
|
|
1168
|
-
data: { contentType:
|
|
1170
|
+
data: { contentType: n, fileName: s, exportAsBase64: i, exportAsBlob: a }
|
|
1169
1171
|
}), null;
|
|
1170
1172
|
try {
|
|
1171
|
-
const l = D.getFormatFromContentType(
|
|
1173
|
+
const l = D.getFormatFromContentType(n);
|
|
1172
1174
|
if (l === "svg") {
|
|
1173
1175
|
const M = r.toSVG(), f = D._exportSVGStringAsFile(M, {
|
|
1174
|
-
exportAsBase64:
|
|
1176
|
+
exportAsBase64: i,
|
|
1175
1177
|
exportAsBlob: a,
|
|
1176
1178
|
fileName: s
|
|
1177
1179
|
}), j = {
|
|
@@ -1183,8 +1185,8 @@ class D {
|
|
|
1183
1185
|
};
|
|
1184
1186
|
return o.fire("editor:object-exported", j), j;
|
|
1185
1187
|
}
|
|
1186
|
-
if (
|
|
1187
|
-
const M = yield createImageBitmap(r.getElement()), f = yield
|
|
1188
|
+
if (i && r instanceof Z) {
|
|
1189
|
+
const M = yield createImageBitmap(r.getElement()), f = yield d.post(
|
|
1188
1190
|
"toDataURL",
|
|
1189
1191
|
{
|
|
1190
1192
|
format: l,
|
|
@@ -1196,7 +1198,7 @@ class D {
|
|
|
1196
1198
|
object: r,
|
|
1197
1199
|
image: f,
|
|
1198
1200
|
format: l,
|
|
1199
|
-
contentType:
|
|
1201
|
+
contentType: n,
|
|
1200
1202
|
fileName: s
|
|
1201
1203
|
};
|
|
1202
1204
|
return o.fire("editor:object-exported", j), j;
|
|
@@ -1211,16 +1213,16 @@ class D {
|
|
|
1211
1213
|
object: r,
|
|
1212
1214
|
image: g,
|
|
1213
1215
|
format: l,
|
|
1214
|
-
contentType:
|
|
1216
|
+
contentType: n,
|
|
1215
1217
|
fileName: s
|
|
1216
1218
|
};
|
|
1217
1219
|
return o.fire("editor:object-exported", M), M;
|
|
1218
1220
|
}
|
|
1219
|
-
const u = new File([g], s, { type:
|
|
1221
|
+
const u = new File([g], s, { type: n }), m = {
|
|
1220
1222
|
object: r,
|
|
1221
1223
|
image: u,
|
|
1222
1224
|
format: l,
|
|
1223
|
-
contentType:
|
|
1225
|
+
contentType: n,
|
|
1224
1226
|
fileName: s
|
|
1225
1227
|
};
|
|
1226
1228
|
return o.fire("editor:object-exported", m), m;
|
|
@@ -1230,7 +1232,7 @@ class D {
|
|
|
1230
1232
|
method: "exportObjectAsImageFile",
|
|
1231
1233
|
code: "IMAGE_EXPORT_FAILED",
|
|
1232
1234
|
message: `Ошибка экспорта объекта: ${l.message}`,
|
|
1233
|
-
data: { contentType:
|
|
1235
|
+
data: { contentType: n, fileName: s, exportAsBase64: i, exportAsBlob: a }
|
|
1234
1236
|
}), null;
|
|
1235
1237
|
}
|
|
1236
1238
|
});
|
|
@@ -1297,11 +1299,11 @@ class D {
|
|
|
1297
1299
|
getContentTypeFromExtension(e) {
|
|
1298
1300
|
var t;
|
|
1299
1301
|
try {
|
|
1300
|
-
const
|
|
1302
|
+
const n = (t = new URL(e).pathname.split(".").pop()) == null ? void 0 : t.toLowerCase(), i = {};
|
|
1301
1303
|
return this.acceptContentTypes.forEach((a) => {
|
|
1302
1304
|
const o = D.getFormatFromContentType(a);
|
|
1303
|
-
o && (
|
|
1304
|
-
}),
|
|
1305
|
+
o && (i[o] = a);
|
|
1306
|
+
}), n && i[n] || "application/octet-stream";
|
|
1305
1307
|
} catch (s) {
|
|
1306
1308
|
return console.warn("Не удалось определить расширение из URL:", e, s), "application/octet-stream";
|
|
1307
1309
|
}
|
|
@@ -1319,8 +1321,8 @@ class D {
|
|
|
1319
1321
|
}) {
|
|
1320
1322
|
const { montageArea: s } = this.editor;
|
|
1321
1323
|
if (!s || !e) return 1;
|
|
1322
|
-
const
|
|
1323
|
-
return t === "contain" || t === "image-contain" ? Math.min(
|
|
1324
|
+
const n = s.width, i = s.height, { width: a, height: o } = e;
|
|
1325
|
+
return t === "contain" || t === "image-contain" ? Math.min(n / a, i / o) : t === "cover" || t === "image-cover" ? Math.max(n / a, i / o) : 1;
|
|
1324
1326
|
}
|
|
1325
1327
|
/**
|
|
1326
1328
|
* Преобразует SVG-строку в Blob, файл, или base64
|
|
@@ -1336,9 +1338,9 @@ class D {
|
|
|
1336
1338
|
static _exportSVGStringAsFile(e, {
|
|
1337
1339
|
exportAsBase64: t,
|
|
1338
1340
|
exportAsBlob: s,
|
|
1339
|
-
fileName:
|
|
1341
|
+
fileName: n = "image.svg"
|
|
1340
1342
|
} = {}) {
|
|
1341
|
-
return s ? new Blob([e], { type: "image/svg+xml" }) : t ? `data:image/svg+xml;base64,${window.btoa(encodeURIComponent(e))}` : new File([e],
|
|
1343
|
+
return s ? new Blob([e], { type: "image/svg+xml" }) : t ? `data:image/svg+xml;base64,${window.btoa(encodeURIComponent(e))}` : new File([e], n.replace(/\.[^/.]+$/, ".svg"), { type: "image/svg+xml" });
|
|
1342
1344
|
}
|
|
1343
1345
|
/**
|
|
1344
1346
|
* Извлекает чистый формат (subtype) из contentType,
|
|
@@ -1369,25 +1371,25 @@ class tt {
|
|
|
1369
1371
|
* @param options.adaptCanvasToContainer - Адаптировать канвас к контейнеру
|
|
1370
1372
|
* @fires editor:resolution-width-changed
|
|
1371
1373
|
*/
|
|
1372
|
-
setResolutionWidth(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer:
|
|
1374
|
+
setResolutionWidth(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer: n } = {}) {
|
|
1373
1375
|
var m;
|
|
1374
1376
|
if (!e) return;
|
|
1375
1377
|
const {
|
|
1376
|
-
canvas:
|
|
1378
|
+
canvas: i,
|
|
1377
1379
|
montageArea: a,
|
|
1378
1380
|
options: { canvasBackstoreWidth: o }
|
|
1379
|
-
} = this.editor, { width:
|
|
1380
|
-
if (!o || o === "auto" ||
|
|
1381
|
-
const M = l /
|
|
1381
|
+
} = this.editor, { width: d, height: r } = a, l = Math.max(Math.min(Number(e), O), x);
|
|
1382
|
+
if (!o || o === "auto" || n ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreWidth(Number(o)) : this.setCanvasBackstoreWidth(l), a.set({ width: l }), (m = i.clipPath) == null || m.set({ width: l }), t) {
|
|
1383
|
+
const M = l / d, f = r * M;
|
|
1382
1384
|
this.setResolutionHeight(f);
|
|
1383
1385
|
return;
|
|
1384
1386
|
}
|
|
1385
|
-
const { left: h, top: g } = this.getObjectDefaultCoords(a), u =
|
|
1386
|
-
|
|
1387
|
+
const { left: h, top: g } = this.getObjectDefaultCoords(a), u = i.getZoom();
|
|
1388
|
+
i.setViewportTransform([u, 0, 0, u, h, g]), this.centerMontageArea(), s || this.editor.historyManager.saveState(), i.fire("editor:resolution-width-changed", {
|
|
1387
1389
|
width: l,
|
|
1388
1390
|
preserveProportional: t,
|
|
1389
1391
|
withoutSave: s,
|
|
1390
|
-
adaptCanvasToContainer:
|
|
1392
|
+
adaptCanvasToContainer: n
|
|
1391
1393
|
});
|
|
1392
1394
|
}
|
|
1393
1395
|
/**
|
|
@@ -1399,25 +1401,25 @@ class tt {
|
|
|
1399
1401
|
* @param options.adaptCanvasToContainer - Адаптировать канвас к контейнеру
|
|
1400
1402
|
* @fires editor:resolution-height-changed
|
|
1401
1403
|
*/
|
|
1402
|
-
setResolutionHeight(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer:
|
|
1404
|
+
setResolutionHeight(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer: n } = {}) {
|
|
1403
1405
|
var m;
|
|
1404
1406
|
if (!e) return;
|
|
1405
1407
|
const {
|
|
1406
|
-
canvas:
|
|
1408
|
+
canvas: i,
|
|
1407
1409
|
montageArea: a,
|
|
1408
1410
|
options: { canvasBackstoreHeight: o }
|
|
1409
|
-
} = this.editor, { width:
|
|
1410
|
-
if (!o || o === "auto" ||
|
|
1411
|
-
const M = l / r, f =
|
|
1411
|
+
} = this.editor, { width: d, height: r } = a, l = Math.max(Math.min(Number(e), T), B);
|
|
1412
|
+
if (!o || o === "auto" || n ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreHeight(Number(o)) : this.setCanvasBackstoreHeight(l), a.set({ height: l }), (m = i.clipPath) == null || m.set({ height: l }), t) {
|
|
1413
|
+
const M = l / r, f = d * M;
|
|
1412
1414
|
this.setResolutionWidth(f);
|
|
1413
1415
|
return;
|
|
1414
1416
|
}
|
|
1415
|
-
const { left: h, top: g } = this.getObjectDefaultCoords(a), u =
|
|
1416
|
-
|
|
1417
|
+
const { left: h, top: g } = this.getObjectDefaultCoords(a), u = i.getZoom();
|
|
1418
|
+
i.setViewportTransform([u, 0, 0, u, h, g]), this.centerMontageArea(), s || this.editor.historyManager.saveState(), i.fire("editor:resolution-height-changed", {
|
|
1417
1419
|
height: l,
|
|
1418
1420
|
preserveProportional: t,
|
|
1419
1421
|
withoutSave: s,
|
|
1420
|
-
adaptCanvasToContainer:
|
|
1422
|
+
adaptCanvasToContainer: n
|
|
1421
1423
|
});
|
|
1422
1424
|
}
|
|
1423
1425
|
/**
|
|
@@ -1425,17 +1427,17 @@ class tt {
|
|
|
1425
1427
|
* и устанавливает правильный viewportTransform.
|
|
1426
1428
|
*/
|
|
1427
1429
|
centerMontageArea() {
|
|
1428
|
-
var
|
|
1429
|
-
const { canvas: e, montageArea: t } = this.editor, s = e.getWidth(),
|
|
1430
|
+
var d;
|
|
1431
|
+
const { canvas: e, montageArea: t } = this.editor, s = e.getWidth(), n = e.getHeight(), i = e.getZoom(), a = new _(s / 2, n / 2);
|
|
1430
1432
|
t.set({
|
|
1431
1433
|
left: s / 2,
|
|
1432
|
-
top:
|
|
1433
|
-
}), (
|
|
1434
|
+
top: n / 2
|
|
1435
|
+
}), (d = e.clipPath) == null || d.set({
|
|
1434
1436
|
left: s / 2,
|
|
1435
|
-
top:
|
|
1437
|
+
top: n / 2
|
|
1436
1438
|
}), e.renderAll();
|
|
1437
1439
|
const o = e.viewportTransform;
|
|
1438
|
-
o[4] = s / 2 - a.x *
|
|
1440
|
+
o[4] = s / 2 - a.x * i, o[5] = n / 2 - a.y * i, e.setViewportTransform(o), e.renderAll();
|
|
1439
1441
|
}
|
|
1440
1442
|
/**
|
|
1441
1443
|
* Метод для получения координат объекта с учетом текущего зума
|
|
@@ -1451,8 +1453,8 @@ class tt {
|
|
|
1451
1453
|
code: "NO_ACTIVE_OBJECT",
|
|
1452
1454
|
message: "Не выбран объект для получения координат"
|
|
1453
1455
|
}), { left: 0, top: 0 };
|
|
1454
|
-
const { width:
|
|
1455
|
-
return { left: o, top:
|
|
1456
|
+
const { width: n, height: i } = s, a = t.getZoom(), o = (n - n * a) / 2, d = (i - i * a) / 2;
|
|
1457
|
+
return { left: o, top: d };
|
|
1456
1458
|
}
|
|
1457
1459
|
/**
|
|
1458
1460
|
* Устанавливаем ширину канваса в backstore (для экспорта)
|
|
@@ -1477,8 +1479,8 @@ class tt {
|
|
|
1477
1479
|
* с учётом минимальных и максимальных значений.
|
|
1478
1480
|
*/
|
|
1479
1481
|
adaptCanvasToContainer() {
|
|
1480
|
-
const { canvas: e } = this.editor, t = e.editorContainer, s = t.clientWidth,
|
|
1481
|
-
console.log("adaptCanvasToContainer newWidth",
|
|
1482
|
+
const { canvas: e } = this.editor, t = e.editorContainer, s = t.clientWidth, n = t.clientHeight, i = Math.max(Math.min(s, O), x), a = Math.max(Math.min(n, T), B);
|
|
1483
|
+
console.log("adaptCanvasToContainer newWidth", i), console.log("adaptCanvasToContainer newHeight", a), e.setDimensions({ width: i, height: a }, { backstoreOnly: !0 });
|
|
1482
1484
|
}
|
|
1483
1485
|
/**
|
|
1484
1486
|
* Обновляет размеры канваса без изменения позиций объектов.
|
|
@@ -1491,12 +1493,12 @@ class tt {
|
|
|
1491
1493
|
montageArea: t,
|
|
1492
1494
|
montageArea: {
|
|
1493
1495
|
width: s,
|
|
1494
|
-
height:
|
|
1496
|
+
height: n
|
|
1495
1497
|
}
|
|
1496
|
-
} = this.editor,
|
|
1497
|
-
this.setResolutionWidth(s, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.setResolutionHeight(
|
|
1498
|
-
const o = t.left -
|
|
1499
|
-
if (o !== 0 ||
|
|
1498
|
+
} = this.editor, i = t.left, a = t.top;
|
|
1499
|
+
this.setResolutionWidth(s, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.setResolutionHeight(n, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.centerMontageArea();
|
|
1500
|
+
const o = t.left - i, d = t.top - a;
|
|
1501
|
+
if (o !== 0 || d !== 0) {
|
|
1500
1502
|
const r = e.getActiveObject(), l = [];
|
|
1501
1503
|
if ((r == null ? void 0 : r.type) === "activeselection") {
|
|
1502
1504
|
const h = r;
|
|
@@ -1505,7 +1507,7 @@ class tt {
|
|
|
1505
1507
|
if (e.getObjects().forEach((h) => {
|
|
1506
1508
|
h.id === "montage-area" || h.id === "overlay-mask" || (h.set({
|
|
1507
1509
|
left: h.left + o,
|
|
1508
|
-
top: h.top +
|
|
1510
|
+
top: h.top + d
|
|
1509
1511
|
}), h.setCoords());
|
|
1510
1512
|
}), l.length > 0)
|
|
1511
1513
|
if (l.length === 1)
|
|
@@ -1519,7 +1521,7 @@ class tt {
|
|
|
1519
1521
|
}
|
|
1520
1522
|
e.renderAll(), e.fire("editor:canvas-updated", {
|
|
1521
1523
|
width: s,
|
|
1522
|
-
height:
|
|
1524
|
+
height: n
|
|
1523
1525
|
});
|
|
1524
1526
|
}
|
|
1525
1527
|
/**
|
|
@@ -1534,11 +1536,11 @@ class tt {
|
|
|
1534
1536
|
* @param zoom — текущее значение zoom (например, 1, 1.2, 2 и т.д.)
|
|
1535
1537
|
*/
|
|
1536
1538
|
updateCssDimensionsForZoom(e) {
|
|
1537
|
-
const { canvas: t, montageArea: s } = this.editor,
|
|
1539
|
+
const { canvas: t, montageArea: s } = this.editor, n = s.width * e, i = s.height * e, a = t.wrapperEl.parentNode;
|
|
1538
1540
|
if (!(a instanceof HTMLElement)) return;
|
|
1539
|
-
const o =
|
|
1541
|
+
const o = n <= a.clientWidth ? "100%" : n, d = i <= a.clientHeight ? "100%" : i;
|
|
1540
1542
|
t.setDimensions(
|
|
1541
|
-
{ width: o, height:
|
|
1543
|
+
{ width: o, height: d },
|
|
1542
1544
|
{ cssOnly: !0 }
|
|
1543
1545
|
);
|
|
1544
1546
|
}
|
|
@@ -1625,19 +1627,19 @@ class tt {
|
|
|
1625
1627
|
*/
|
|
1626
1628
|
setDisplayDimension({ element: e = "canvas", dimension: t, value: s } = {}) {
|
|
1627
1629
|
if (!s) return;
|
|
1628
|
-
const { canvas:
|
|
1630
|
+
const { canvas: n, options: { editorContainer: i } } = this.editor, a = [];
|
|
1629
1631
|
switch (e) {
|
|
1630
1632
|
case "canvas":
|
|
1631
|
-
a.push(
|
|
1633
|
+
a.push(n.lowerCanvasEl, n.upperCanvasEl);
|
|
1632
1634
|
break;
|
|
1633
1635
|
case "wrapper":
|
|
1634
|
-
a.push(
|
|
1636
|
+
a.push(n.wrapperEl);
|
|
1635
1637
|
break;
|
|
1636
1638
|
case "container":
|
|
1637
|
-
a.push(
|
|
1639
|
+
a.push(i);
|
|
1638
1640
|
break;
|
|
1639
1641
|
default:
|
|
1640
|
-
a.push(
|
|
1642
|
+
a.push(n.lowerCanvasEl, n.upperCanvasEl);
|
|
1641
1643
|
}
|
|
1642
1644
|
const o = t === "width" ? "width" : "height";
|
|
1643
1645
|
if (typeof s == "string") {
|
|
@@ -1647,10 +1649,10 @@ class tt {
|
|
|
1647
1649
|
return;
|
|
1648
1650
|
}
|
|
1649
1651
|
if (isNaN(s)) return;
|
|
1650
|
-
const
|
|
1652
|
+
const d = `${s}px`;
|
|
1651
1653
|
a.forEach((r) => {
|
|
1652
|
-
r.style[o] =
|
|
1653
|
-
}),
|
|
1654
|
+
r.style[o] = d;
|
|
1655
|
+
}), n.fire(`editor:display-${e}-${o}-changed`, {
|
|
1654
1656
|
element: e,
|
|
1655
1657
|
value: s
|
|
1656
1658
|
});
|
|
@@ -1665,14 +1667,14 @@ class tt {
|
|
|
1665
1667
|
*/
|
|
1666
1668
|
scaleMontageAreaToImage({ object: e, preserveAspectRatio: t, withoutSave: s } = {}) {
|
|
1667
1669
|
const {
|
|
1668
|
-
canvas:
|
|
1669
|
-
montageArea:
|
|
1670
|
+
canvas: n,
|
|
1671
|
+
montageArea: i,
|
|
1670
1672
|
transformManager: a,
|
|
1671
1673
|
options: {
|
|
1672
1674
|
montageAreaWidth: o,
|
|
1673
|
-
montageAreaHeight:
|
|
1675
|
+
montageAreaHeight: d
|
|
1674
1676
|
}
|
|
1675
|
-
} = this.editor, r = e ||
|
|
1677
|
+
} = this.editor, r = e || n.getActiveObject();
|
|
1676
1678
|
if (!r || r.type !== "image" && r.format !== "svg") return;
|
|
1677
1679
|
const { width: l, height: h } = r;
|
|
1678
1680
|
let g = Math.min(l, O), u = Math.min(h, T);
|
|
@@ -1680,10 +1682,10 @@ class tt {
|
|
|
1680
1682
|
const {
|
|
1681
1683
|
width: m,
|
|
1682
1684
|
height: M
|
|
1683
|
-
} =
|
|
1685
|
+
} = i, f = l / m, j = h / M, A = Math.max(f, j);
|
|
1684
1686
|
g = m * A, u = M * A;
|
|
1685
1687
|
}
|
|
1686
|
-
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(u, { withoutSave: !0 }), (l > o || h >
|
|
1688
|
+
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(u, { withoutSave: !0 }), (l > o || h > d) && a.calculateAndApplyDefaultZoom(), a.resetObject(r, { withoutSave: !0 }), n.centerObject(r), n.renderAll(), s || this.editor.historyManager.saveState(), n.fire("editor:montage-area-scaled-to-image", {
|
|
1687
1689
|
object: r,
|
|
1688
1690
|
width: g,
|
|
1689
1691
|
height: u,
|
|
@@ -1709,13 +1711,13 @@ class tt {
|
|
|
1709
1711
|
const {
|
|
1710
1712
|
canvas: t,
|
|
1711
1713
|
transformManager: s,
|
|
1712
|
-
historyManager:
|
|
1714
|
+
historyManager: n,
|
|
1713
1715
|
options: {
|
|
1714
|
-
montageAreaWidth:
|
|
1716
|
+
montageAreaWidth: i,
|
|
1715
1717
|
montageAreaHeight: a
|
|
1716
1718
|
}
|
|
1717
1719
|
} = this.editor;
|
|
1718
|
-
s.resetZoom(), this.setResolutionWidth(
|
|
1720
|
+
s.resetZoom(), this.setResolutionWidth(i, { withoutSave: !0 }), this.setResolutionHeight(a, { withoutSave: !0 }), t.renderAll(), s.resetObjects(), e || n.saveState(), t.fire("editor:default-scale-set");
|
|
1719
1721
|
}
|
|
1720
1722
|
/**
|
|
1721
1723
|
* Получение всех объектов внутри монтажной области редактора
|
|
@@ -1723,7 +1725,7 @@ class tt {
|
|
|
1723
1725
|
*/
|
|
1724
1726
|
getObjects() {
|
|
1725
1727
|
const { canvas: e, montageArea: t, interactionBlocker: { overlayMask: s } } = this.editor;
|
|
1726
|
-
return e.getObjects().filter((
|
|
1728
|
+
return e.getObjects().filter((i) => i.id !== t.id && i.id !== (s == null ? void 0 : s.id));
|
|
1727
1729
|
}
|
|
1728
1730
|
}
|
|
1729
1731
|
class st {
|
|
@@ -1738,8 +1740,8 @@ class st {
|
|
|
1738
1740
|
* @param scale - Желаемый масштаб относительно размеров контейнера редактора.
|
|
1739
1741
|
*/
|
|
1740
1742
|
calculateAndApplyDefaultZoom(e = this.options.defaultScale) {
|
|
1741
|
-
const { canvas: t } = this.editor, s = t.editorContainer,
|
|
1742
|
-
this.defaultZoom = Math.min(
|
|
1743
|
+
const { canvas: t } = this.editor, s = t.editorContainer, n = s.clientWidth, i = s.clientHeight, { width: a, height: o } = this.editor.montageArea, d = n / a * e, r = i / o * e;
|
|
1744
|
+
this.defaultZoom = Math.min(d, r);
|
|
1743
1745
|
const { defaultZoom: l, maxZoomFactor: h, minZoom: g, maxZoom: u } = this;
|
|
1744
1746
|
this.minZoom = Math.min(l / h, g), this.maxZoom = Math.max(l * h, u), this.setZoom();
|
|
1745
1747
|
}
|
|
@@ -1755,14 +1757,14 @@ class st {
|
|
|
1755
1757
|
zoom(e = qe, t = {}) {
|
|
1756
1758
|
var g, u;
|
|
1757
1759
|
if (!e) return;
|
|
1758
|
-
const { minZoom: s, maxZoom:
|
|
1760
|
+
const { minZoom: s, maxZoom: n } = this, { canvas: i } = this.editor, a = i.getZoom(), o = i.getCenterPoint(), d = (g = t.pointX) != null ? g : o.x, r = (u = t.pointY) != null ? u : o.y, l = new _(d, r);
|
|
1759
1761
|
let h = Number((a + Number(e)).toFixed(2));
|
|
1760
|
-
h >
|
|
1762
|
+
h > n && (h = n), h < s && (h = s), i.zoomToPoint(l, h), console.log({
|
|
1761
1763
|
currentZoom: a,
|
|
1762
1764
|
zoom: h,
|
|
1763
1765
|
point: l
|
|
1764
|
-
}),
|
|
1765
|
-
currentZoom:
|
|
1766
|
+
}), i.fire("editor:zoom-changed", {
|
|
1767
|
+
currentZoom: i.getZoom(),
|
|
1766
1768
|
zoom: h,
|
|
1767
1769
|
point: l
|
|
1768
1770
|
});
|
|
@@ -1773,12 +1775,12 @@ class st {
|
|
|
1773
1775
|
* @fires editor:zoom-changed
|
|
1774
1776
|
*/
|
|
1775
1777
|
setZoom(e = this.defaultZoom) {
|
|
1776
|
-
const { minZoom: t, maxZoom: s } = this, { canvas:
|
|
1778
|
+
const { minZoom: t, maxZoom: s } = this, { canvas: n } = this.editor, i = new _(n.getCenterPoint());
|
|
1777
1779
|
let a = e;
|
|
1778
|
-
e > s && (a = s), e < t && (a = t),
|
|
1779
|
-
currentZoom:
|
|
1780
|
+
e > s && (a = s), e < t && (a = t), n.zoomToPoint(i, a), n.fire("editor:zoom-changed", {
|
|
1781
|
+
currentZoom: n.getZoom(),
|
|
1780
1782
|
zoom: a,
|
|
1781
|
-
point:
|
|
1783
|
+
point: i
|
|
1782
1784
|
});
|
|
1783
1785
|
}
|
|
1784
1786
|
/**
|
|
@@ -1800,11 +1802,11 @@ class st {
|
|
|
1800
1802
|
* @fires editor:object-rotated
|
|
1801
1803
|
*/
|
|
1802
1804
|
rotate(e = et, { withoutSave: t } = {}) {
|
|
1803
|
-
const { canvas: s, historyManager:
|
|
1804
|
-
if (!
|
|
1805
|
-
const a =
|
|
1806
|
-
|
|
1807
|
-
object:
|
|
1805
|
+
const { canvas: s, historyManager: n } = this.editor, i = s.getActiveObject();
|
|
1806
|
+
if (!i) return;
|
|
1807
|
+
const a = i.angle + e;
|
|
1808
|
+
i.rotate(a), i.setCoords(), s.renderAll(), t || n.saveState(), s.fire("editor:object-rotated", {
|
|
1809
|
+
object: i,
|
|
1808
1810
|
withoutSave: t,
|
|
1809
1811
|
angle: a
|
|
1810
1812
|
});
|
|
@@ -1816,9 +1818,9 @@ class st {
|
|
|
1816
1818
|
* @fires editor:object-flipped-x
|
|
1817
1819
|
*/
|
|
1818
1820
|
flipX({ withoutSave: e } = {}) {
|
|
1819
|
-
const { canvas: t, historyManager: s } = this.editor,
|
|
1820
|
-
|
|
1821
|
-
object:
|
|
1821
|
+
const { canvas: t, historyManager: s } = this.editor, n = t.getActiveObject();
|
|
1822
|
+
n && (n.flipX = !n.flipX, t.renderAll(), e || s.saveState(), t.fire("editor:object-flipped-x", {
|
|
1823
|
+
object: n,
|
|
1822
1824
|
withoutSave: e
|
|
1823
1825
|
}));
|
|
1824
1826
|
}
|
|
@@ -1829,9 +1831,9 @@ class st {
|
|
|
1829
1831
|
* @fires editor:object-flipped-y
|
|
1830
1832
|
*/
|
|
1831
1833
|
flipY({ withoutSave: e } = {}) {
|
|
1832
|
-
const { canvas: t, historyManager: s } = this.editor,
|
|
1833
|
-
|
|
1834
|
-
object:
|
|
1834
|
+
const { canvas: t, historyManager: s } = this.editor, n = t.getActiveObject();
|
|
1835
|
+
n && (n.flipY = !n.flipY, t.renderAll(), e || s.saveState(), t.fire("editor:object-flipped-y", {
|
|
1836
|
+
object: n,
|
|
1835
1837
|
withoutSave: e
|
|
1836
1838
|
}));
|
|
1837
1839
|
}
|
|
@@ -1848,10 +1850,10 @@ class st {
|
|
|
1848
1850
|
opacity: t = 1,
|
|
1849
1851
|
withoutSave: s
|
|
1850
1852
|
} = {}) {
|
|
1851
|
-
const { canvas:
|
|
1853
|
+
const { canvas: n, historyManager: i } = this.editor, a = e || n.getActiveObject();
|
|
1852
1854
|
a && (a instanceof v ? a.getObjects().forEach((o) => {
|
|
1853
1855
|
o.set("opacity", t);
|
|
1854
|
-
}) : a.set("opacity", t),
|
|
1856
|
+
}) : a.set("opacity", t), n.renderAll(), s || i.saveState(), n.fire("editor:object-opacity-changed", {
|
|
1855
1857
|
object: a,
|
|
1856
1858
|
opacity: t,
|
|
1857
1859
|
withoutSave: s
|
|
@@ -1872,24 +1874,24 @@ class st {
|
|
|
1872
1874
|
object: e,
|
|
1873
1875
|
type: t = this.options.scaleType,
|
|
1874
1876
|
withoutSave: s,
|
|
1875
|
-
fitAsOneObject:
|
|
1877
|
+
fitAsOneObject: n
|
|
1876
1878
|
} = {}) {
|
|
1877
|
-
const { canvas:
|
|
1879
|
+
const { canvas: i, historyManager: a } = this.editor, o = e || i.getActiveObject();
|
|
1878
1880
|
if (o) {
|
|
1879
|
-
if (o instanceof v && !
|
|
1880
|
-
const
|
|
1881
|
-
|
|
1881
|
+
if (o instanceof v && !n) {
|
|
1882
|
+
const d = o.getObjects();
|
|
1883
|
+
i.discardActiveObject(), d.forEach((l) => {
|
|
1882
1884
|
this._fitSingleObject(l, t);
|
|
1883
1885
|
});
|
|
1884
|
-
const r = new v(
|
|
1885
|
-
|
|
1886
|
+
const r = new v(d, { canvas: i });
|
|
1887
|
+
i.setActiveObject(r);
|
|
1886
1888
|
} else
|
|
1887
1889
|
this._fitSingleObject(o, t);
|
|
1888
|
-
|
|
1890
|
+
i.renderAll(), s || a.saveState(), i.fire("editor:object-fitted", {
|
|
1889
1891
|
object: o,
|
|
1890
1892
|
type: t,
|
|
1891
1893
|
withoutSave: s,
|
|
1892
|
-
fitAsOneObject:
|
|
1894
|
+
fitAsOneObject: n
|
|
1893
1895
|
});
|
|
1894
1896
|
}
|
|
1895
1897
|
}
|
|
@@ -1900,11 +1902,11 @@ class st {
|
|
|
1900
1902
|
* @private
|
|
1901
1903
|
*/
|
|
1902
1904
|
_fitSingleObject(e, t) {
|
|
1903
|
-
const { canvas: s, montageArea:
|
|
1905
|
+
const { canvas: s, montageArea: n } = this.editor, { width: i, height: a, scaleX: o = 1, scaleY: d = 1, angle: r = 0 } = e, l = i * Math.abs(o), h = a * Math.abs(d), g = r * Math.PI / 180, u = Math.abs(Math.cos(g)), m = Math.abs(Math.sin(g)), M = l * u + h * m, f = l * m + h * u, j = n.width, A = n.height;
|
|
1904
1906
|
let b;
|
|
1905
1907
|
t === "contain" ? b = Math.min(j / M, A / f) : b = Math.max(j / M, A / f), e.set({
|
|
1906
1908
|
scaleX: o * b,
|
|
1907
|
-
scaleY:
|
|
1909
|
+
scaleY: d * b
|
|
1908
1910
|
}), s.centerObject(e);
|
|
1909
1911
|
}
|
|
1910
1912
|
/**
|
|
@@ -1925,12 +1927,12 @@ class st {
|
|
|
1925
1927
|
*/
|
|
1926
1928
|
resetObject(e, { alwaysFitObject: t = !1, withoutSave: s = !1 } = {}) {
|
|
1927
1929
|
const {
|
|
1928
|
-
canvas:
|
|
1929
|
-
montageArea:
|
|
1930
|
+
canvas: n,
|
|
1931
|
+
montageArea: i,
|
|
1930
1932
|
imageManager: a,
|
|
1931
1933
|
historyManager: o,
|
|
1932
|
-
options: { scaleType:
|
|
1933
|
-
} = this.editor, r = e ||
|
|
1934
|
+
options: { scaleType: d }
|
|
1935
|
+
} = this.editor, r = e || n.getActiveObject();
|
|
1934
1936
|
if (!r || r.locked) return;
|
|
1935
1937
|
if (o.suspendHistory(), r.type === "image" || r.format === "svg" || r.set({
|
|
1936
1938
|
scaleX: 1,
|
|
@@ -1941,20 +1943,20 @@ class st {
|
|
|
1941
1943
|
}), t)
|
|
1942
1944
|
this.fitObject({ object: r, withoutSave: !0, fitAsOneObject: !0 });
|
|
1943
1945
|
else {
|
|
1944
|
-
const { width: h, height: g } =
|
|
1946
|
+
const { width: h, height: g } = i, { width: u, height: m } = r, M = a.calculateScaleFactor({
|
|
1945
1947
|
imageObject: r,
|
|
1946
|
-
scaleType:
|
|
1948
|
+
scaleType: d
|
|
1947
1949
|
});
|
|
1948
|
-
|
|
1950
|
+
d === "contain" && M < 1 || d === "cover" && (u > h || m > g) ? this.fitObject({ object: r, withoutSave: !0, fitAsOneObject: !0 }) : r.set({ scaleX: 1, scaleY: 1 });
|
|
1949
1951
|
}
|
|
1950
|
-
r.set({ flipX: !1, flipY: !1, angle: 0 }),
|
|
1952
|
+
r.set({ flipX: !1, flipY: !1, angle: 0 }), n.centerObject(r), n.renderAll(), o.resumeHistory(), s || o.saveState(), n.fire("editor:object-reset", {
|
|
1951
1953
|
object: r,
|
|
1952
1954
|
withoutSave: s,
|
|
1953
1955
|
alwaysFitObject: t
|
|
1954
1956
|
});
|
|
1955
1957
|
}
|
|
1956
1958
|
}
|
|
1957
|
-
class
|
|
1959
|
+
class nt {
|
|
1958
1960
|
constructor({ editor: e }) {
|
|
1959
1961
|
this.editor = e, this.isBlocked = !1, this.overlayMask = null, this._createOverlay();
|
|
1960
1962
|
}
|
|
@@ -1984,8 +1986,8 @@ class it {
|
|
|
1984
1986
|
const { canvas: e, montageArea: t, historyManager: s } = this.editor;
|
|
1985
1987
|
if (!t || !this.overlayMask) return;
|
|
1986
1988
|
s.suspendHistory(), t.setCoords();
|
|
1987
|
-
const { left:
|
|
1988
|
-
this.overlayMask.set({ left:
|
|
1989
|
+
const { left: n, top: i, width: a, height: o } = t.getBoundingRect();
|
|
1990
|
+
this.overlayMask.set({ left: n, top: i, width: a, height: o }), e.discardActiveObject(), this.editor.layerManager.bringToFront(this.overlayMask, { withoutSave: !0 }), s.resumeHistory();
|
|
1989
1991
|
}
|
|
1990
1992
|
/**
|
|
1991
1993
|
* Выключает редактор:
|
|
@@ -1996,8 +1998,8 @@ class it {
|
|
|
1996
1998
|
block() {
|
|
1997
1999
|
if (this.isBlocked || !this.overlayMask) return;
|
|
1998
2000
|
const { canvas: e, canvasManager: t, historyManager: s } = this.editor;
|
|
1999
|
-
s.suspendHistory(), this.isBlocked = !0, e.discardActiveObject(), e.selection = !1, e.skipTargetFind = !0, t.getObjects().forEach((
|
|
2000
|
-
|
|
2001
|
+
s.suspendHistory(), this.isBlocked = !0, e.discardActiveObject(), e.selection = !1, e.skipTargetFind = !0, t.getObjects().forEach((n) => {
|
|
2002
|
+
n.evented = !1, n.selectable = !1;
|
|
2001
2003
|
}), e.upperCanvasEl.style.pointerEvents = "none", e.lowerCanvasEl.style.pointerEvents = "none", this.overlayMask.visible = !0, this.refresh(), e.fire("editor:disabled"), s.resumeHistory();
|
|
2002
2004
|
}
|
|
2003
2005
|
/**
|
|
@@ -2006,8 +2008,8 @@ class it {
|
|
|
2006
2008
|
unblock() {
|
|
2007
2009
|
if (!this.isBlocked || !this.overlayMask) return;
|
|
2008
2010
|
const { canvas: e, canvasManager: t, historyManager: s } = this.editor;
|
|
2009
|
-
s.suspendHistory(), this.isBlocked = !1, e.selection = !0, e.skipTargetFind = !1, t.getObjects().forEach((
|
|
2010
|
-
|
|
2011
|
+
s.suspendHistory(), this.isBlocked = !1, e.selection = !0, e.skipTargetFind = !1, t.getObjects().forEach((n) => {
|
|
2012
|
+
n.evented = !0, n.selectable = !0;
|
|
2011
2013
|
}), e.upperCanvasEl.style.pointerEvents = "", e.lowerCanvasEl.style.pointerEvents = "", this.overlayMask.visible = !1, e.requestRenderAll(), e.fire("editor:enabled"), s.resumeHistory();
|
|
2012
2014
|
}
|
|
2013
2015
|
}
|
|
@@ -2023,13 +2025,13 @@ class P {
|
|
|
2023
2025
|
* @fires editor:object-bring-to-front
|
|
2024
2026
|
*/
|
|
2025
2027
|
bringToFront(e, { withoutSave: t } = {}) {
|
|
2026
|
-
const { canvas: s, historyManager:
|
|
2027
|
-
|
|
2028
|
-
const
|
|
2029
|
-
|
|
2028
|
+
const { canvas: s, historyManager: n } = this.editor;
|
|
2029
|
+
n.suspendHistory();
|
|
2030
|
+
const i = e || s.getActiveObject();
|
|
2031
|
+
i && (i instanceof v ? i.getObjects().forEach((a) => {
|
|
2030
2032
|
s.bringObjectToFront(a);
|
|
2031
|
-
}) : s.bringObjectToFront(
|
|
2032
|
-
object:
|
|
2033
|
+
}) : s.bringObjectToFront(i), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:object-bring-to-front", {
|
|
2034
|
+
object: i,
|
|
2033
2035
|
withoutSave: t
|
|
2034
2036
|
}));
|
|
2035
2037
|
}
|
|
@@ -2041,11 +2043,11 @@ class P {
|
|
|
2041
2043
|
* @fires editor:object-bring-forward
|
|
2042
2044
|
*/
|
|
2043
2045
|
bringForward(e, { withoutSave: t } = {}) {
|
|
2044
|
-
const { canvas: s, historyManager:
|
|
2045
|
-
|
|
2046
|
-
const
|
|
2047
|
-
|
|
2048
|
-
object:
|
|
2046
|
+
const { canvas: s, historyManager: n } = this.editor;
|
|
2047
|
+
n.suspendHistory();
|
|
2048
|
+
const i = e || s.getActiveObject();
|
|
2049
|
+
i && (i instanceof v ? P._moveSelectionForward(s, i) : s.bringObjectForward(i), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:object-bring-forward", {
|
|
2050
|
+
object: i,
|
|
2049
2051
|
withoutSave: t
|
|
2050
2052
|
}));
|
|
2051
2053
|
}
|
|
@@ -2059,20 +2061,20 @@ class P {
|
|
|
2059
2061
|
sendToBack(e, { withoutSave: t } = {}) {
|
|
2060
2062
|
const {
|
|
2061
2063
|
canvas: s,
|
|
2062
|
-
montageArea:
|
|
2063
|
-
historyManager:
|
|
2064
|
+
montageArea: n,
|
|
2065
|
+
historyManager: i,
|
|
2064
2066
|
interactionBlocker: { overlayMask: a }
|
|
2065
2067
|
} = this.editor;
|
|
2066
|
-
|
|
2068
|
+
i.suspendHistory();
|
|
2067
2069
|
const o = e || s.getActiveObject();
|
|
2068
2070
|
if (o) {
|
|
2069
2071
|
if (o instanceof v) {
|
|
2070
|
-
const
|
|
2071
|
-
for (let r =
|
|
2072
|
-
s.sendObjectToBack(
|
|
2072
|
+
const d = o.getObjects();
|
|
2073
|
+
for (let r = d.length - 1; r >= 0; r -= 1)
|
|
2074
|
+
s.sendObjectToBack(d[r]);
|
|
2073
2075
|
} else
|
|
2074
2076
|
s.sendObjectToBack(o);
|
|
2075
|
-
s.sendObjectToBack(
|
|
2077
|
+
s.sendObjectToBack(n), a && s.sendObjectToBack(a), s.renderAll(), i.resumeHistory(), t || i.saveState(), s.fire("editor:object-send-to-back", {
|
|
2076
2078
|
object: o,
|
|
2077
2079
|
withoutSave: t
|
|
2078
2080
|
});
|
|
@@ -2087,59 +2089,57 @@ class P {
|
|
|
2087
2089
|
sendBackwards(e, { withoutSave: t } = {}) {
|
|
2088
2090
|
const {
|
|
2089
2091
|
canvas: s,
|
|
2090
|
-
montageArea:
|
|
2091
|
-
historyManager:
|
|
2092
|
+
montageArea: n,
|
|
2093
|
+
historyManager: i,
|
|
2092
2094
|
interactionBlocker: { overlayMask: a }
|
|
2093
2095
|
} = this.editor;
|
|
2094
|
-
|
|
2096
|
+
i.suspendHistory();
|
|
2095
2097
|
const o = e || s.getActiveObject();
|
|
2096
|
-
o && (o instanceof v ? P._moveSelectionBackwards(s, o) : s.sendObjectBackwards(o), s.sendObjectToBack(
|
|
2098
|
+
o && (o instanceof v ? P._moveSelectionBackwards(s, o) : s.sendObjectBackwards(o), s.sendObjectToBack(n), a && s.sendObjectToBack(a), s.renderAll(), i.resumeHistory(), t || i.saveState(), s.fire("editor:object-send-backwards", {
|
|
2097
2099
|
object: o,
|
|
2098
2100
|
withoutSave: t
|
|
2099
2101
|
}));
|
|
2100
2102
|
}
|
|
2101
2103
|
/**
|
|
2102
|
-
* Сдвигает выделенные объекты на один уровень вверх
|
|
2104
|
+
* Сдвигает выделенные объекты на один уровень вверх - каждый объект поднимается
|
|
2105
|
+
* на одну позицию выше относительно своей текущей позиции
|
|
2103
2106
|
* @param canvas - экземпляр холста
|
|
2104
2107
|
* @param activeSelection - активное выделение
|
|
2105
2108
|
*/
|
|
2106
2109
|
static _moveSelectionForward(e, t) {
|
|
2107
|
-
const s = e.getObjects(),
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
const r = s.indexOf(c.obj);
|
|
2118
|
-
r < a && (e.moveObjectTo(c.obj, a), a = r);
|
|
2110
|
+
const s = e.getObjects(), n = t.getObjects();
|
|
2111
|
+
if (!n.some((o) => {
|
|
2112
|
+
const d = s.indexOf(o);
|
|
2113
|
+
for (let r = d + 1; r < s.length; r += 1)
|
|
2114
|
+
if (!n.includes(s[r]))
|
|
2115
|
+
return !0;
|
|
2116
|
+
return !1;
|
|
2117
|
+
})) return;
|
|
2118
|
+
n.map((o) => ({ obj: o, index: s.indexOf(o) })).sort((o, d) => d.index - o.index).forEach((o) => {
|
|
2119
|
+
e.bringObjectForward(o.obj);
|
|
2119
2120
|
});
|
|
2120
2121
|
}
|
|
2121
2122
|
/**
|
|
2122
|
-
* Сдвигает выделенные объекты на один уровень вниз
|
|
2123
|
+
* Сдвигает выделенные объекты на один уровень вниз - каждый объект опускается
|
|
2124
|
+
* на одну позицию ниже относительно своей текущей позиции
|
|
2123
2125
|
* @param canvas - экземпляр холста
|
|
2124
2126
|
* @param activeSelection - активное выделение
|
|
2125
2127
|
*/
|
|
2126
2128
|
static _moveSelectionBackwards(e, t) {
|
|
2127
|
-
const s = e.getObjects(),
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
const r = s.indexOf(c.obj);
|
|
2138
|
-
r > a && (e.moveObjectTo(c.obj, a), a = r);
|
|
2129
|
+
const s = e.getObjects(), n = t.getObjects();
|
|
2130
|
+
if (!n.some((o) => {
|
|
2131
|
+
const d = s.indexOf(o);
|
|
2132
|
+
for (let r = d - 1; r >= 0; r -= 1)
|
|
2133
|
+
if (!n.includes(s[r]))
|
|
2134
|
+
return !0;
|
|
2135
|
+
return !1;
|
|
2136
|
+
})) return;
|
|
2137
|
+
n.map((o) => ({ obj: o, index: s.indexOf(o) })).sort((o, d) => o.index - d.index).forEach((o) => {
|
|
2138
|
+
e.sendObjectBackwards(o.obj);
|
|
2139
2139
|
});
|
|
2140
2140
|
}
|
|
2141
2141
|
}
|
|
2142
|
-
class
|
|
2142
|
+
class it {
|
|
2143
2143
|
/**
|
|
2144
2144
|
* Менеджер фигур для редактора.
|
|
2145
2145
|
* @param options - Опции и настройки менеджера фигур.
|
|
@@ -2163,13 +2163,13 @@ class nt {
|
|
|
2163
2163
|
* @param flags.withoutSelection - Не выделять объект
|
|
2164
2164
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2165
2165
|
*/
|
|
2166
|
-
addRectangle(l = {}, { withoutSelection:
|
|
2166
|
+
addRectangle(l = {}, { withoutSelection: d, withoutAdding: r } = {}) {
|
|
2167
2167
|
var h = l, {
|
|
2168
2168
|
id: e = `rect-${L()}`,
|
|
2169
2169
|
left: t,
|
|
2170
2170
|
top: s,
|
|
2171
|
-
width:
|
|
2172
|
-
height:
|
|
2171
|
+
width: n = 100,
|
|
2172
|
+
height: i = 100,
|
|
2173
2173
|
fill: a = "blue"
|
|
2174
2174
|
} = h, o = Y(h, [
|
|
2175
2175
|
"id",
|
|
@@ -2183,11 +2183,11 @@ class nt {
|
|
|
2183
2183
|
id: e,
|
|
2184
2184
|
left: t,
|
|
2185
2185
|
top: s,
|
|
2186
|
-
width:
|
|
2187
|
-
height:
|
|
2186
|
+
width: n,
|
|
2187
|
+
height: i,
|
|
2188
2188
|
fill: a
|
|
2189
2189
|
}, o));
|
|
2190
|
-
return !t && !s && g.centerObject(u), r || (g.add(u),
|
|
2190
|
+
return !t && !s && g.centerObject(u), r || (g.add(u), d || g.setActiveObject(u), g.renderAll()), u;
|
|
2191
2191
|
}
|
|
2192
2192
|
/**
|
|
2193
2193
|
* Добавление круга
|
|
@@ -2205,13 +2205,13 @@ class nt {
|
|
|
2205
2205
|
* @param flags.withoutSelection - Не выделять объект
|
|
2206
2206
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2207
2207
|
*/
|
|
2208
|
-
addCircle(r = {}, { withoutSelection: o, withoutAdding:
|
|
2208
|
+
addCircle(r = {}, { withoutSelection: o, withoutAdding: d } = {}) {
|
|
2209
2209
|
var l = r, {
|
|
2210
2210
|
id: e = `circle-${L()}`,
|
|
2211
2211
|
left: t,
|
|
2212
2212
|
top: s,
|
|
2213
|
-
radius:
|
|
2214
|
-
fill:
|
|
2213
|
+
radius: n = 50,
|
|
2214
|
+
fill: i = "green"
|
|
2215
2215
|
} = l, a = Y(l, [
|
|
2216
2216
|
"id",
|
|
2217
2217
|
"left",
|
|
@@ -2223,10 +2223,10 @@ class nt {
|
|
|
2223
2223
|
id: e,
|
|
2224
2224
|
left: t,
|
|
2225
2225
|
top: s,
|
|
2226
|
-
fill:
|
|
2227
|
-
radius:
|
|
2226
|
+
fill: i,
|
|
2227
|
+
radius: n
|
|
2228
2228
|
}, a));
|
|
2229
|
-
return !t && !s && h.centerObject(g),
|
|
2229
|
+
return !t && !s && h.centerObject(g), d || (h.add(g), o || h.setActiveObject(g), h.renderAll()), g;
|
|
2230
2230
|
}
|
|
2231
2231
|
/**
|
|
2232
2232
|
* Добавление треугольника
|
|
@@ -2245,13 +2245,13 @@ class nt {
|
|
|
2245
2245
|
* @param flags.withoutSelection - Не выделять объект
|
|
2246
2246
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2247
2247
|
*/
|
|
2248
|
-
addTriangle(l = {}, { withoutSelection:
|
|
2248
|
+
addTriangle(l = {}, { withoutSelection: d, withoutAdding: r } = {}) {
|
|
2249
2249
|
var h = l, {
|
|
2250
2250
|
id: e = `triangle-${L()}`,
|
|
2251
2251
|
left: t,
|
|
2252
2252
|
top: s,
|
|
2253
|
-
width:
|
|
2254
|
-
height:
|
|
2253
|
+
width: n = 100,
|
|
2254
|
+
height: i = 100,
|
|
2255
2255
|
fill: a = "yellow"
|
|
2256
2256
|
} = h, o = Y(h, [
|
|
2257
2257
|
"id",
|
|
@@ -2266,10 +2266,10 @@ class nt {
|
|
|
2266
2266
|
left: t,
|
|
2267
2267
|
top: s,
|
|
2268
2268
|
fill: a,
|
|
2269
|
-
width:
|
|
2270
|
-
height:
|
|
2269
|
+
width: n,
|
|
2270
|
+
height: i
|
|
2271
2271
|
}, o));
|
|
2272
|
-
return !t && !s && g.centerObject(u), r || (g.add(u),
|
|
2272
|
+
return !t && !s && g.centerObject(u), r || (g.add(u), d || g.setActiveObject(u), g.renderAll()), u;
|
|
2273
2273
|
}
|
|
2274
2274
|
}
|
|
2275
2275
|
class at {
|
|
@@ -2285,59 +2285,56 @@ class at {
|
|
|
2285
2285
|
* @fires editor:object-copied
|
|
2286
2286
|
*/
|
|
2287
2287
|
copy() {
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2288
|
+
return I(this, null, function* () {
|
|
2289
|
+
const { canvas: e, errorManager: t } = this.editor, s = e.getActiveObject();
|
|
2290
|
+
if (!s) return;
|
|
2291
|
+
try {
|
|
2292
|
+
const g = yield s.clone(["format"]);
|
|
2293
|
+
this.clipboard = g, e.fire("editor:object-copied", { object: g });
|
|
2294
|
+
} catch (g) {
|
|
2295
|
+
t.emitError({
|
|
2296
|
+
origin: "ClipboardManager",
|
|
2297
|
+
method: "copy",
|
|
2298
|
+
code: "CLONE_FAILED",
|
|
2299
|
+
message: "Ошибка клонирования объекта",
|
|
2300
|
+
data: g
|
|
2301
|
+
});
|
|
2302
|
+
return;
|
|
2303
|
+
}
|
|
2304
|
+
if (typeof ClipboardItem == "undefined" || !navigator.clipboard) {
|
|
2303
2305
|
t.emitWarning({
|
|
2304
2306
|
origin: "ClipboardManager",
|
|
2305
2307
|
method: "copy",
|
|
2306
|
-
code: "
|
|
2307
|
-
|
|
2308
|
-
|
|
2308
|
+
code: "CLIPBOARD_NOT_SUPPORTED",
|
|
2309
|
+
// eslint-disable-next-line max-len
|
|
2310
|
+
message: "ClipboardManager. navigator.clipboard не поддерживается в этом браузере или отсутствует соединение по HTTPS-протоколу."
|
|
2311
|
+
});
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
if (s.type !== "image") {
|
|
2315
|
+
const g = `application/image-editor:${JSON.stringify(s.toObject(["format"]))}`;
|
|
2316
|
+
navigator.clipboard.writeText(g).catch((u) => {
|
|
2317
|
+
t.emitWarning({
|
|
2318
|
+
origin: "ClipboardManager",
|
|
2319
|
+
method: "copy",
|
|
2320
|
+
code: "CLIPBOARD_WRITE_TEXT_FAILED",
|
|
2321
|
+
message: `Ошибка записи текстового объекта в буфер обмена: ${u.message}`,
|
|
2322
|
+
data: u
|
|
2323
|
+
});
|
|
2324
|
+
});
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
const i = s.toCanvasElement().toDataURL(), a = i.slice(5).split(";")[0], o = i.split(",")[1], d = atob(o), r = new Uint8Array(d.length);
|
|
2328
|
+
for (let g = 0; g < d.length; g += 1)
|
|
2329
|
+
r[g] = d.charCodeAt(g);
|
|
2330
|
+
const l = new Blob([r.buffer], { type: a }), h = new ClipboardItem({ [a]: l });
|
|
2331
|
+
navigator.clipboard.write([h]).catch((g) => {
|
|
2332
|
+
t.emitWarning({
|
|
2333
|
+
origin: "ClipboardManager",
|
|
2334
|
+
method: "copy",
|
|
2335
|
+
code: "CLIPBOARD_WRITE_IMAGE_FAILED",
|
|
2336
|
+
message: `Ошибка записи изображения в буфер обмена: ${g.message}`
|
|
2309
2337
|
});
|
|
2310
|
-
}), this._cloneAndFire(e, s);
|
|
2311
|
-
return;
|
|
2312
|
-
}
|
|
2313
|
-
const n = s.toCanvasElement().toDataURL(), a = n.slice(5).split(";")[0], o = n.split(",")[1], c = atob(o), r = new Uint8Array(c.length);
|
|
2314
|
-
for (let g = 0; g < c.length; g += 1)
|
|
2315
|
-
r[g] = c.charCodeAt(g);
|
|
2316
|
-
const l = new Blob([r.buffer], { type: a }), h = new ClipboardItem({ [a]: l });
|
|
2317
|
-
navigator.clipboard.write([h]).catch((g) => {
|
|
2318
|
-
t.emitWarning({
|
|
2319
|
-
origin: "ClipboardManager",
|
|
2320
|
-
method: "copy",
|
|
2321
|
-
code: "CLIPBOARD_WRITE_IMAGE_FAILED",
|
|
2322
|
-
message: `Ошибка записи изображения в буфер обмена: ${g.message}`
|
|
2323
|
-
});
|
|
2324
|
-
}), this._cloneAndFire(e, s);
|
|
2325
|
-
}
|
|
2326
|
-
/**
|
|
2327
|
-
* Клонирует объект и вызывает событие 'editor:object-copied'.
|
|
2328
|
-
* @param canvas - экземпляр canvas
|
|
2329
|
-
* @param object - активный объект
|
|
2330
|
-
*/
|
|
2331
|
-
_cloneAndFire(e, t) {
|
|
2332
|
-
t.clone(["format"]).then((s) => {
|
|
2333
|
-
this.clipboard = s, e.fire("editor:object-copied", { object: s });
|
|
2334
|
-
}).catch((s) => {
|
|
2335
|
-
this.editor.errorManager.emitError({
|
|
2336
|
-
origin: "ClipboardManager",
|
|
2337
|
-
method: "_cloneAndFire",
|
|
2338
|
-
code: "CLONE_FAILED",
|
|
2339
|
-
message: "Ошибка клонирования объекта",
|
|
2340
|
-
data: s
|
|
2341
2338
|
});
|
|
2342
2339
|
});
|
|
2343
2340
|
}
|
|
@@ -2350,19 +2347,19 @@ class at {
|
|
|
2350
2347
|
handlePasteEvent({ clipboardData: e }) {
|
|
2351
2348
|
var a;
|
|
2352
2349
|
if (!((a = e == null ? void 0 : e.items) != null && a.length)) return;
|
|
2353
|
-
const { imageManager: t } = this.editor, { items: s } = e,
|
|
2354
|
-
if (
|
|
2355
|
-
const o =
|
|
2350
|
+
const { imageManager: t } = this.editor, { items: s } = e, n = s[s.length - 1];
|
|
2351
|
+
if (n.type !== "text/html") {
|
|
2352
|
+
const o = n.getAsFile();
|
|
2356
2353
|
if (!o) return;
|
|
2357
|
-
const
|
|
2358
|
-
|
|
2354
|
+
const d = new FileReader();
|
|
2355
|
+
d.onload = (r) => {
|
|
2359
2356
|
r.target && this.editor.imageManager.importImage({ source: r.target.result });
|
|
2360
|
-
},
|
|
2357
|
+
}, d.readAsDataURL(o);
|
|
2361
2358
|
return;
|
|
2362
2359
|
}
|
|
2363
|
-
const
|
|
2364
|
-
if (
|
|
2365
|
-
const r = new DOMParser().parseFromString(
|
|
2360
|
+
const i = e.getData("text/html");
|
|
2361
|
+
if (i) {
|
|
2362
|
+
const r = new DOMParser().parseFromString(i, "text/html").querySelector("img");
|
|
2366
2363
|
if (r != null && r.src) {
|
|
2367
2364
|
t.importImage({ source: r.src });
|
|
2368
2365
|
return;
|
|
@@ -2403,7 +2400,7 @@ class F {
|
|
|
2403
2400
|
* @fires editor:object-locked
|
|
2404
2401
|
*/
|
|
2405
2402
|
lockObject({ object: e, skipInnerObjects: t, withoutSave: s } = {}) {
|
|
2406
|
-
const { canvas:
|
|
2403
|
+
const { canvas: n, historyManager: i } = this.editor, a = e || n.getActiveObject();
|
|
2407
2404
|
if (!a || a.locked) return;
|
|
2408
2405
|
const o = {
|
|
2409
2406
|
lockMovementX: !0,
|
|
@@ -2417,7 +2414,7 @@ class F {
|
|
|
2417
2414
|
};
|
|
2418
2415
|
a.set(o), !t && F._isGroupOrSelection(a) && a.getObjects().forEach((r) => {
|
|
2419
2416
|
r.set(o);
|
|
2420
|
-
}),
|
|
2417
|
+
}), n.renderAll(), s || i.saveState(), n.fire("editor:object-locked", {
|
|
2421
2418
|
object: a,
|
|
2422
2419
|
skipInnerObjects: t,
|
|
2423
2420
|
withoutSave: s
|
|
@@ -2431,8 +2428,8 @@ class F {
|
|
|
2431
2428
|
* @fires editor:object-unlocked
|
|
2432
2429
|
*/
|
|
2433
2430
|
unlockObject({ object: e, withoutSave: t } = {}) {
|
|
2434
|
-
const { canvas: s, historyManager:
|
|
2435
|
-
if (!
|
|
2431
|
+
const { canvas: s, historyManager: n } = this.editor, i = e || s.getActiveObject();
|
|
2432
|
+
if (!i) return;
|
|
2436
2433
|
const a = {
|
|
2437
2434
|
lockMovementX: !1,
|
|
2438
2435
|
lockMovementY: !1,
|
|
@@ -2443,10 +2440,10 @@ class F {
|
|
|
2443
2440
|
lockSkewingY: !1,
|
|
2444
2441
|
locked: !1
|
|
2445
2442
|
};
|
|
2446
|
-
|
|
2443
|
+
i.set(a), F._isGroupOrSelection(i) && i.getObjects().forEach((o) => {
|
|
2447
2444
|
o.set(a);
|
|
2448
|
-
}), s.renderAll(), t ||
|
|
2449
|
-
object:
|
|
2445
|
+
}), s.renderAll(), t || n.saveState(), s.fire("editor:object-unlocked", {
|
|
2446
|
+
object: i,
|
|
2450
2447
|
withoutSave: t
|
|
2451
2448
|
});
|
|
2452
2449
|
}
|
|
@@ -2469,13 +2466,13 @@ class ot {
|
|
|
2469
2466
|
object: e,
|
|
2470
2467
|
withoutSave: t
|
|
2471
2468
|
} = {}) {
|
|
2472
|
-
const { canvas: s, historyManager:
|
|
2473
|
-
|
|
2474
|
-
const
|
|
2475
|
-
if (!
|
|
2476
|
-
const a =
|
|
2477
|
-
a.forEach((
|
|
2478
|
-
object:
|
|
2469
|
+
const { canvas: s, historyManager: n } = this.editor;
|
|
2470
|
+
n.suspendHistory();
|
|
2471
|
+
const i = e || s.getActiveObject();
|
|
2472
|
+
if (!i || !(i instanceof v)) return;
|
|
2473
|
+
const a = i.getObjects(), o = new X(a);
|
|
2474
|
+
a.forEach((d) => s.remove(d)), o.set("id", `${o.type}-${L()}`), s.add(o), s.setActiveObject(o), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:objects-grouped", {
|
|
2475
|
+
object: i,
|
|
2479
2476
|
group: o,
|
|
2480
2477
|
withoutSave: t
|
|
2481
2478
|
});
|
|
@@ -2491,17 +2488,17 @@ class ot {
|
|
|
2491
2488
|
object: e,
|
|
2492
2489
|
withoutSave: t
|
|
2493
2490
|
} = {}) {
|
|
2494
|
-
const { canvas: s, historyManager:
|
|
2495
|
-
|
|
2496
|
-
const
|
|
2497
|
-
if (!(
|
|
2498
|
-
const a =
|
|
2499
|
-
s.remove(
|
|
2491
|
+
const { canvas: s, historyManager: n } = this.editor;
|
|
2492
|
+
n.suspendHistory();
|
|
2493
|
+
const i = e || s.getActiveObject();
|
|
2494
|
+
if (!(i instanceof X)) return;
|
|
2495
|
+
const a = i.removeAll();
|
|
2496
|
+
s.remove(i), a.forEach((d) => s.add(d));
|
|
2500
2497
|
const o = new v(a, {
|
|
2501
2498
|
canvas: s
|
|
2502
2499
|
});
|
|
2503
|
-
s.setActiveObject(o), s.renderAll(),
|
|
2504
|
-
object:
|
|
2500
|
+
s.setActiveObject(o), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:objects-ungrouped", {
|
|
2501
|
+
object: i,
|
|
2505
2502
|
selection: o,
|
|
2506
2503
|
withoutSave: t
|
|
2507
2504
|
});
|
|
@@ -2518,8 +2515,8 @@ class rt {
|
|
|
2518
2515
|
selectAll() {
|
|
2519
2516
|
const { canvas: e, canvasManager: t, objectLockManager: s } = this.editor;
|
|
2520
2517
|
e.discardActiveObject();
|
|
2521
|
-
const
|
|
2522
|
-
|
|
2518
|
+
const n = t.getObjects(), i = n.some((o) => o.locked), a = n.length > 1 ? new v(t.getObjects(), { canvas: e }) : n[0];
|
|
2519
|
+
i && s.lockObject({ object: a, skipInnerObjects: !0, withoutSave: !0 }), e.setActiveObject(a), e.requestRenderAll(), e.fire("editor:all-objects-selected", { selected: a });
|
|
2523
2520
|
}
|
|
2524
2521
|
}
|
|
2525
2522
|
class ct {
|
|
@@ -2537,14 +2534,14 @@ class ct {
|
|
|
2537
2534
|
objects: e,
|
|
2538
2535
|
withoutSave: t
|
|
2539
2536
|
} = {}) {
|
|
2540
|
-
const { canvas: s, historyManager:
|
|
2541
|
-
a != null && a.length && (
|
|
2537
|
+
const { canvas: s, historyManager: n, groupingManager: i } = this.editor, a = (e || s.getActiveObjects()).filter((o) => !o.locked);
|
|
2538
|
+
a != null && a.length && (n.suspendHistory(), a.forEach((o) => {
|
|
2542
2539
|
if (o.type === "group" && o.format !== "svg") {
|
|
2543
|
-
|
|
2540
|
+
i.ungroup({ object: o, withoutSave: t }), this.deleteSelectedObjects();
|
|
2544
2541
|
return;
|
|
2545
2542
|
}
|
|
2546
2543
|
s.remove(o);
|
|
2547
|
-
}), s.discardActiveObject(), s.renderAll(),
|
|
2544
|
+
}), s.discardActiveObject(), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:objects-deleted", {
|
|
2548
2545
|
objects: a,
|
|
2549
2546
|
withoutSave: t
|
|
2550
2547
|
}));
|
|
@@ -2638,20 +2635,20 @@ class V {
|
|
|
2638
2635
|
* @param options.message — текст ошибки (опционально, если не передан, то используется код ошибки)
|
|
2639
2636
|
* @fires editor:error
|
|
2640
2637
|
*/
|
|
2641
|
-
emitError({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, data:
|
|
2638
|
+
emitError({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, data: n, message: i }) {
|
|
2642
2639
|
if (!V.isValidErrorCode(s)) {
|
|
2643
2640
|
console.warn("Неизвестный код ошибки: ", { code: s, origin: e, method: t });
|
|
2644
2641
|
return;
|
|
2645
2642
|
}
|
|
2646
2643
|
if (!s) return;
|
|
2647
|
-
const a =
|
|
2648
|
-
console.error(`${e}. ${t}. ${s}. ${a}`,
|
|
2644
|
+
const a = i || s;
|
|
2645
|
+
console.error(`${e}. ${t}. ${s}. ${a}`, n);
|
|
2649
2646
|
const o = {
|
|
2650
2647
|
code: s,
|
|
2651
2648
|
origin: e,
|
|
2652
2649
|
method: t,
|
|
2653
2650
|
message: a,
|
|
2654
|
-
data:
|
|
2651
|
+
data: n
|
|
2655
2652
|
};
|
|
2656
2653
|
this._buffer.push(p({
|
|
2657
2654
|
type: "editor:error"
|
|
@@ -2667,19 +2664,19 @@ class V {
|
|
|
2667
2664
|
* @param options.message — текст предупреждения (опционально, если не передан, то используется код предупреждения)
|
|
2668
2665
|
* @fires editor:warning
|
|
2669
2666
|
*/
|
|
2670
|
-
emitWarning({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, message:
|
|
2667
|
+
emitWarning({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, message: n, data: i }) {
|
|
2671
2668
|
if (!V.isValidErrorCode(s)) {
|
|
2672
2669
|
console.warn("Неизвестный код предупреждения: ", { code: s, origin: e, method: t });
|
|
2673
2670
|
return;
|
|
2674
2671
|
}
|
|
2675
|
-
const a =
|
|
2676
|
-
console.warn(`${e}. ${t}. ${s}. ${a}`,
|
|
2672
|
+
const a = n || s;
|
|
2673
|
+
console.warn(`${e}. ${t}. ${s}. ${a}`, i);
|
|
2677
2674
|
const o = {
|
|
2678
2675
|
code: s,
|
|
2679
2676
|
origin: e,
|
|
2680
2677
|
method: t,
|
|
2681
2678
|
message: a,
|
|
2682
|
-
data:
|
|
2679
|
+
data: i
|
|
2683
2680
|
};
|
|
2684
2681
|
this._buffer.push(p({
|
|
2685
2682
|
type: "editor:warning"
|
|
@@ -2694,7 +2691,7 @@ class V {
|
|
|
2694
2691
|
return e ? Object.values(dt).some((t) => Object.values(t).includes(e)) : !1;
|
|
2695
2692
|
}
|
|
2696
2693
|
}
|
|
2697
|
-
class
|
|
2694
|
+
class ne {
|
|
2698
2695
|
/**
|
|
2699
2696
|
* Конструктор класса ImageEditor.
|
|
2700
2697
|
* @param canvasId - идентификатор канваса, в котором будет создан редактор
|
|
@@ -2714,15 +2711,15 @@ class ie {
|
|
|
2714
2711
|
editorContainerWidth: e,
|
|
2715
2712
|
editorContainerHeight: t,
|
|
2716
2713
|
canvasWrapperWidth: s,
|
|
2717
|
-
canvasWrapperHeight:
|
|
2718
|
-
canvasCSSWidth:
|
|
2714
|
+
canvasWrapperHeight: n,
|
|
2715
|
+
canvasCSSWidth: i,
|
|
2719
2716
|
canvasCSSHeight: a,
|
|
2720
2717
|
initialImage: o,
|
|
2721
|
-
initialStateJSON:
|
|
2718
|
+
initialStateJSON: d,
|
|
2722
2719
|
scaleType: r,
|
|
2723
2720
|
_onReadyCallback: l
|
|
2724
2721
|
} = this.options;
|
|
2725
|
-
if (He.apply(), this.canvas = new Ce(this.containerId, this.options), this.moduleLoader = new Ee(), this.workerManager = new Te(), this.errorManager = new V({ editor: this }), this.historyManager = new Je({ editor: this }), this.toolbar = new Qe({ editor: this }), this.transformManager = new st({ editor: this }), this.canvasManager = new tt({ editor: this }), this.imageManager = new D({ editor: this }), this.layerManager = new P({ editor: this }), this.shapeManager = new
|
|
2722
|
+
if (He.apply(), this.canvas = new Ce(this.containerId, this.options), this.moduleLoader = new Ee(), this.workerManager = new Te(), this.errorManager = new V({ editor: this }), this.historyManager = new Je({ editor: this }), this.toolbar = new Qe({ editor: this }), this.transformManager = new st({ editor: this }), this.canvasManager = new tt({ editor: this }), this.imageManager = new D({ editor: this }), this.layerManager = new P({ editor: this }), this.shapeManager = new it({ editor: this }), this.interactionBlocker = new nt({ editor: this }), this.clipboardManager = new at({ editor: this }), this.objectLockManager = new F({ editor: this }), this.groupingManager = new ot({ editor: this }), this.selectionManager = new rt({ editor: this }), this.deletionManager = new ct({ editor: this }), this._createMontageArea(), this._createClippingArea(), this.listeners = new z({ editor: this, options: this.options }), this.canvasManager.setEditorContainerWidth(e), this.canvasManager.setEditorContainerHeight(t), this.canvasManager.setCanvasWrapperWidth(s), this.canvasManager.setCanvasWrapperHeight(n), this.canvasManager.setCanvasCSSWidth(i), this.canvasManager.setCanvasCSSHeight(a), o != null && o.source) {
|
|
2726
2723
|
const {
|
|
2727
2724
|
source: h,
|
|
2728
2725
|
scale: g = `image-${r}`,
|
|
@@ -2731,7 +2728,7 @@ class ie {
|
|
|
2731
2728
|
yield this.imageManager.importImage({ source: h, scale: g, withoutSave: u });
|
|
2732
2729
|
} else
|
|
2733
2730
|
this.canvasManager.setDefaultScale({ withoutSave: !0 });
|
|
2734
|
-
|
|
2731
|
+
d && this.historyManager.loadStateFromFullState(d), this.historyManager.saveState(), console.log("editor:ready"), this.canvas.fire("editor:ready", this), typeof l == "function" && l(this);
|
|
2735
2732
|
});
|
|
2736
2733
|
}
|
|
2737
2734
|
/**
|
|
@@ -2745,7 +2742,7 @@ class ie {
|
|
|
2745
2742
|
this.montageArea = this.shapeManager.addRectangle({
|
|
2746
2743
|
width: e,
|
|
2747
2744
|
height: t,
|
|
2748
|
-
fill:
|
|
2745
|
+
fill: ne._createMosaicPattern(),
|
|
2749
2746
|
stroke: null,
|
|
2750
2747
|
strokeWidth: 0,
|
|
2751
2748
|
selectable: !1,
|
|
@@ -2889,15 +2886,15 @@ const lt = {
|
|
|
2889
2886
|
deleteObjectsByHotkey: !0,
|
|
2890
2887
|
resetObjectFitByDoubleClick: !0
|
|
2891
2888
|
};
|
|
2892
|
-
function bt(
|
|
2893
|
-
const t = p(p({}, lt), e), s = document.getElementById(
|
|
2889
|
+
function bt(c, e = {}) {
|
|
2890
|
+
const t = p(p({}, lt), e), s = document.getElementById(c);
|
|
2894
2891
|
if (!s)
|
|
2895
|
-
return Promise.reject(new Error(`Контейнер с ID "${
|
|
2896
|
-
const
|
|
2897
|
-
return
|
|
2898
|
-
t._onReadyCallback =
|
|
2899
|
-
const a = new
|
|
2900
|
-
window[
|
|
2892
|
+
return Promise.reject(new Error(`Контейнер с ID "${c}" не найден.`));
|
|
2893
|
+
const n = document.createElement("canvas");
|
|
2894
|
+
return n.id = `${c}-canvas`, s.appendChild(n), t.editorContainer = s, new Promise((i) => {
|
|
2895
|
+
t._onReadyCallback = i;
|
|
2896
|
+
const a = new ne(n.id, t);
|
|
2897
|
+
window[c] = a;
|
|
2901
2898
|
});
|
|
2902
2899
|
}
|
|
2903
2900
|
export {
|