@anu3ev/fabric-image-editor 0.1.72 → 0.1.73
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 +980 -683
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Ie = Object.defineProperty, ve = Object.defineProperties;
|
|
2
|
+
var Ae = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var Y = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var he = Object.prototype.hasOwnProperty, ge = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var le = (r, e, t) => e in r ? Ie(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e) => {
|
|
6
6
|
for (var t in e || (e = {}))
|
|
7
|
-
|
|
7
|
+
he.call(e, t) && le(r, t, e[t]);
|
|
8
8
|
if (Y)
|
|
9
9
|
for (var t of Y(e))
|
|
10
|
-
|
|
10
|
+
ge.call(e, t) && le(r, t, e[t]);
|
|
11
11
|
return r;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
12
|
+
}, ue = (r, e) => ve(r, Ae(e));
|
|
13
|
+
var W = (r, e) => {
|
|
14
14
|
var t = {};
|
|
15
15
|
for (var s in r)
|
|
16
|
-
|
|
16
|
+
he.call(r, s) && e.indexOf(s) < 0 && (t[s] = r[s]);
|
|
17
17
|
if (r != null && Y)
|
|
18
18
|
for (var s of Y(r))
|
|
19
|
-
e.indexOf(s) < 0 &&
|
|
19
|
+
e.indexOf(s) < 0 && ge.call(r, s) && (t[s] = r[s]);
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
-
var
|
|
23
|
-
var
|
|
22
|
+
var b = (r, e, t) => new Promise((s, a) => {
|
|
23
|
+
var n = (c) => {
|
|
24
24
|
try {
|
|
25
|
-
|
|
26
|
-
} catch (
|
|
27
|
-
|
|
25
|
+
i(t.next(c));
|
|
26
|
+
} catch (d) {
|
|
27
|
+
a(d);
|
|
28
28
|
}
|
|
29
|
-
},
|
|
29
|
+
}, o = (c) => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
32
|
-
} catch (
|
|
33
|
-
|
|
31
|
+
i(t.throw(c));
|
|
32
|
+
} catch (d) {
|
|
33
|
+
a(d);
|
|
34
34
|
}
|
|
35
|
-
},
|
|
36
|
-
|
|
35
|
+
}, i = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(n, o);
|
|
36
|
+
i((t = t.apply(r, e)).next());
|
|
37
37
|
});
|
|
38
|
-
import { ActiveSelection as y, util as
|
|
39
|
-
import { create as
|
|
40
|
-
import
|
|
41
|
-
var
|
|
38
|
+
import { ActiveSelection as y, util as P, controlsUtils as Ce, InteractiveFabricObject as Se, loadSVGFromURL as Ee, FabricImage as x, Point as V, Gradient as De, Rect as Ne, Circle as Oe, Triangle as Le, Group as J, Canvas as Te, Pattern as we } from "fabric";
|
|
39
|
+
import { create as ke } from "jsondiffpatch";
|
|
40
|
+
import Be from "diff-match-patch";
|
|
41
|
+
var _e = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", v = function() {
|
|
42
42
|
for (var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 21, t = "", s = crypto.getRandomValues(new Uint8Array(e |= 0)); e--; )
|
|
43
|
-
t +=
|
|
43
|
+
t += _e[s[e] & 63];
|
|
44
44
|
return t;
|
|
45
45
|
};
|
|
46
46
|
class Z {
|
|
@@ -61,7 +61,7 @@ class Z {
|
|
|
61
61
|
* @param params.options.adaptCanvasToContainerOnResize — адаптировать канвас к размерам контейнера при изменении размеров окна
|
|
62
62
|
*/
|
|
63
63
|
constructor({ editor: e, options: t = {} }) {
|
|
64
|
-
this.isDragging = !1, this.lastMouseX = 0, this.lastMouseY = 0, this.isUndoRedoKeyPressed = !1, this.isSpacePressed = !1, this.savedSelection = [], this.canvasDragging = !1, this.mouseWheelZooming = !1, this.bringToFrontOnSelection = !1, this.resetObjectFitByDoubleClick = !1, this.copyObjectsByHotkey = !1, this.pasteImageFromClipboard = !1, this.undoRedoByHotKeys = !1, this.selectAllByHotkey = !1, this.deleteObjectsByHotkey = !1, this.adaptCanvasToContainerOnResize = !1, this.editor = e, this.canvas = e.canvas, this.options = t, this.handleContainerResizeBound = Z.debounce(this.handleContainerResize.bind(this), 500), this.handleCopyEventBound = this.handleCopyEvent.bind(this), this.handlePasteEventBound = this.handlePasteEvent.bind(this), this.handleUndoRedoEventBound = this.handleUndoRedoEvent.bind(this), this.handleUndoRedoKeyUpBound = this.handleUndoRedoKeyUp.bind(this), this.handleSelectAllEventBound = this.handleSelectAllEvent.bind(this), this.handleDeleteObjectsEventBound = this.handleDeleteObjectsEvent.bind(this), this.handleSpaceKeyDownBound = this.handleSpaceKeyDown.bind(this), this.handleSpaceKeyUpBound = this.handleSpaceKeyUp.bind(this), this.handleObjectModifiedHistoryBound = Z.debounce(this.handleObjectModifiedHistory.bind(this), 300), this.handleObjectRotatingHistoryBound = Z.debounce(this.handleObjectRotatingHistory.bind(this), 300), this.handleObjectAddedHistoryBound = this.handleObjectAddedHistory.bind(this), this.handleObjectRemovedHistoryBound = this.handleObjectRemovedHistory.bind(this), this.handleOverlayUpdateBound = this.handleOverlayUpdate.bind(this), this.handleCanvasDragStartBound = this.handleCanvasDragStart.bind(this), this.handleCanvasDraggingBound = this.handleCanvasDragging.bind(this), this.handleCanvasDragEndBound = this.handleCanvasDragEnd.bind(this), this.handleMouseWheelZoomBound = this.handleMouseWheelZoom.bind(this), this.handleBringToFrontBound = this.handleBringToFront.bind(this), this.handleResetObjectFitBound = this.handleResetObjectFit.bind(this), this.handleLockedSelectionBound = this._filterLockedSelection.bind(this), this.init();
|
|
64
|
+
this.isDragging = !1, this.lastMouseX = 0, this.lastMouseY = 0, this.isUndoRedoKeyPressed = !1, this.isSpacePressed = !1, this.savedSelection = [], this.canvasDragging = !1, this.mouseWheelZooming = !1, this.bringToFrontOnSelection = !1, this.resetObjectFitByDoubleClick = !1, this.copyObjectsByHotkey = !1, this.pasteImageFromClipboard = !1, this.undoRedoByHotKeys = !1, this.selectAllByHotkey = !1, this.deleteObjectsByHotkey = !1, this.adaptCanvasToContainerOnResize = !1, this.editor = e, this.canvas = e.canvas, this.options = t, this.handleContainerResizeBound = Z.debounce(this.handleContainerResize.bind(this), 500), this.handleCopyEventBound = this.handleCopyEvent.bind(this), this.handlePasteEventBound = this.handlePasteEvent.bind(this), this.handleUndoRedoEventBound = this.handleUndoRedoEvent.bind(this), this.handleUndoRedoKeyUpBound = this.handleUndoRedoKeyUp.bind(this), this.handleSelectAllEventBound = this.handleSelectAllEvent.bind(this), this.handleDeleteObjectsEventBound = this.handleDeleteObjectsEvent.bind(this), this.handleSpaceKeyDownBound = this.handleSpaceKeyDown.bind(this), this.handleSpaceKeyUpBound = this.handleSpaceKeyUp.bind(this), this.handleObjectModifiedHistoryBound = Z.debounce(this.handleObjectModifiedHistory.bind(this), 300), this.handleObjectRotatingHistoryBound = Z.debounce(this.handleObjectRotatingHistory.bind(this), 300), this.handleObjectAddedHistoryBound = this.handleObjectAddedHistory.bind(this), this.handleObjectRemovedHistoryBound = this.handleObjectRemovedHistory.bind(this), this.handleOverlayUpdateBound = this.handleOverlayUpdate.bind(this), this.handleBackgroundUpdateBound = this.handleBackgroundUpdate.bind(this), this.handleCanvasDragStartBound = this.handleCanvasDragStart.bind(this), this.handleCanvasDraggingBound = this.handleCanvasDragging.bind(this), this.handleCanvasDragEndBound = this.handleCanvasDragEnd.bind(this), this.handleMouseWheelZoomBound = this.handleMouseWheelZoom.bind(this), this.handleBringToFrontBound = this.handleBringToFront.bind(this), this.handleResetObjectFitBound = this.handleResetObjectFit.bind(this), this.handleLockedSelectionBound = this._filterLockedSelection.bind(this), this.init();
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Инициализация всех обработчиков согласно опциям.
|
|
@@ -71,15 +71,15 @@ class Z {
|
|
|
71
71
|
adaptCanvasToContainerOnResize: e,
|
|
72
72
|
canvasDragging: t,
|
|
73
73
|
mouseWheelZooming: s,
|
|
74
|
-
bringToFrontOnSelection:
|
|
75
|
-
copyObjectsByHotkey:
|
|
76
|
-
pasteImageFromClipboard:
|
|
77
|
-
undoRedoByHotKeys:
|
|
78
|
-
selectAllByHotkey:
|
|
79
|
-
deleteObjectsByHotkey:
|
|
74
|
+
bringToFrontOnSelection: a,
|
|
75
|
+
copyObjectsByHotkey: n,
|
|
76
|
+
pasteImageFromClipboard: o,
|
|
77
|
+
undoRedoByHotKeys: i,
|
|
78
|
+
selectAllByHotkey: c,
|
|
79
|
+
deleteObjectsByHotkey: d,
|
|
80
80
|
resetObjectFitByDoubleClick: h
|
|
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), a && (this.canvas.on("selection:created", this.handleBringToFrontBound), this.canvas.on("selection:updated", this.handleBringToFrontBound)), h && this.canvas.on("mouse:dblclick", this.handleResetObjectFitBound), e && window.addEventListener("resize", this.handleContainerResizeBound, { capture: !0 }), n && document.addEventListener("keydown", this.handleCopyEventBound, { capture: !0 }), o && document.addEventListener("paste", this.handlePasteEventBound, { capture: !0 }), i && (document.addEventListener("keydown", this.handleUndoRedoEventBound, { capture: !0 }), document.addEventListener("keyup", this.handleUndoRedoKeyUpBound, { capture: !0 })), c && document.addEventListener("keydown", this.handleSelectAllEventBound, { capture: !0 }), d && 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), this.canvas.on("object:added", this.handleBackgroundUpdateBound), this.canvas.on("selection:created", this.handleBackgroundUpdateBound);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* При массовом выделении объектов удаляем из него залоченные.
|
|
@@ -89,31 +89,31 @@ class Z {
|
|
|
89
89
|
*/
|
|
90
90
|
_filterLockedSelection({ selected: e, e: t }) {
|
|
91
91
|
if (!(e != null && e.length) || !(t instanceof MouseEvent) || e.length === 1) return;
|
|
92
|
-
const { lockedObjects: s, unlockedObjects:
|
|
93
|
-
(
|
|
92
|
+
const { lockedObjects: s, unlockedObjects: a } = e.reduce(
|
|
93
|
+
(o, i) => i.locked ? (o.lockedObjects.push(i), o) : (o.unlockedObjects.push(i), o),
|
|
94
94
|
{ lockedObjects: [], unlockedObjects: [] }
|
|
95
95
|
);
|
|
96
96
|
if (s.length === 0) return;
|
|
97
|
-
if (
|
|
98
|
-
if (
|
|
99
|
-
this.canvas.setActiveObject(
|
|
97
|
+
if (a.length > 0) {
|
|
98
|
+
if (a.length === 1)
|
|
99
|
+
this.canvas.setActiveObject(a[0]);
|
|
100
100
|
else {
|
|
101
|
-
const
|
|
101
|
+
const o = new y(a, {
|
|
102
102
|
canvas: this.canvas
|
|
103
103
|
});
|
|
104
|
-
this.canvas.setActiveObject(
|
|
104
|
+
this.canvas.setActiveObject(o);
|
|
105
105
|
}
|
|
106
106
|
this.canvas.requestRenderAll();
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const n = new y(e, {
|
|
110
110
|
canvas: this.canvas
|
|
111
111
|
});
|
|
112
112
|
this.editor.objectLockManager.lockObject({
|
|
113
|
-
object:
|
|
113
|
+
object: n,
|
|
114
114
|
skipInnerObjects: !0,
|
|
115
115
|
withoutSave: !0
|
|
116
|
-
}), this.canvas.setActiveObject(
|
|
116
|
+
}), this.canvas.setActiveObject(n), this.canvas.requestRenderAll();
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Обработчики для сохранения состояния редактора в истории.
|
|
@@ -138,13 +138,16 @@ class Z {
|
|
|
138
138
|
const { interactionBlocker: e } = this.editor;
|
|
139
139
|
!e.isBlocked || !e.overlayMask || this.editor.interactionBlocker.refresh();
|
|
140
140
|
}
|
|
141
|
+
handleBackgroundUpdate() {
|
|
142
|
+
this.editor.historyManager.skipHistory || this.editor.backgroundManager.refresh();
|
|
143
|
+
}
|
|
141
144
|
// --- Глобальные DOM-обработчики ---
|
|
142
145
|
/**
|
|
143
146
|
* Обработчик изменения размеров окна браузера.
|
|
144
147
|
* Адаптирует канвас к размерам контейнера, сохраняя позиции объектов.
|
|
145
148
|
*/
|
|
146
149
|
handleContainerResize() {
|
|
147
|
-
this.editor.canvasManager.updateCanvas();
|
|
150
|
+
this.editor.canvasManager.updateCanvas(), this.editor.backgroundManager.refresh();
|
|
148
151
|
}
|
|
149
152
|
/**
|
|
150
153
|
* Обработчик для Ctrl+C (копирование).
|
|
@@ -154,8 +157,8 @@ class Z {
|
|
|
154
157
|
* @param event.code — код клавиши
|
|
155
158
|
*/
|
|
156
159
|
handleCopyEvent(e) {
|
|
157
|
-
const { ctrlKey: t, metaKey: s, code:
|
|
158
|
-
this._shouldIgnoreKeyboardEvent(e) || !t && !s ||
|
|
160
|
+
const { ctrlKey: t, metaKey: s, code: a } = e;
|
|
161
|
+
this._shouldIgnoreKeyboardEvent(e) || !t && !s || a !== "KeyC" || (e.preventDefault(), this.editor.clipboardManager.copy());
|
|
159
162
|
}
|
|
160
163
|
/**
|
|
161
164
|
* Обработчик вставки объекта или изображения из буфера обмена.
|
|
@@ -172,9 +175,9 @@ class Z {
|
|
|
172
175
|
* @param event.code — код клавиши
|
|
173
176
|
*/
|
|
174
177
|
handleUndoRedoEvent(e) {
|
|
175
|
-
return
|
|
176
|
-
const { ctrlKey: t, metaKey: s, code:
|
|
177
|
-
this._shouldIgnoreKeyboardEvent(e) || !t && !s ||
|
|
178
|
+
return b(this, null, function* () {
|
|
179
|
+
const { ctrlKey: t, metaKey: s, code: a, repeat: n } = e;
|
|
180
|
+
this._shouldIgnoreKeyboardEvent(e) || !t && !s || n || !/Mac/i.test(navigator.userAgent) && this.isUndoRedoKeyPressed || (a === "KeyZ" ? (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.undo()) : a === "KeyY" && (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.redo()));
|
|
178
181
|
});
|
|
179
182
|
}
|
|
180
183
|
/**
|
|
@@ -194,8 +197,8 @@ class Z {
|
|
|
194
197
|
*/
|
|
195
198
|
handleSelectAllEvent(e) {
|
|
196
199
|
if (this._shouldIgnoreKeyboardEvent(e)) return;
|
|
197
|
-
const { ctrlKey: t, metaKey: s, code:
|
|
198
|
-
!t && !s ||
|
|
200
|
+
const { ctrlKey: t, metaKey: s, code: a } = e;
|
|
201
|
+
!t && !s || a !== "KeyA" || (e.preventDefault(), this.editor.selectionManager.selectAll());
|
|
199
202
|
}
|
|
200
203
|
/**
|
|
201
204
|
* Обработчик для удаления объектов (Delete или Backspace).
|
|
@@ -213,15 +216,15 @@ class Z {
|
|
|
213
216
|
*/
|
|
214
217
|
handleSpaceKeyDown(e) {
|
|
215
218
|
if (e.code !== "Space" || this._shouldIgnoreKeyboardEvent(e)) return;
|
|
216
|
-
const { canvas: t, editor: s, isSpacePressed:
|
|
217
|
-
if (
|
|
219
|
+
const { canvas: t, editor: s, isSpacePressed: a, isDragging: n } = this;
|
|
220
|
+
if (a || n) return;
|
|
218
221
|
this.isSpacePressed = !0, e.preventDefault();
|
|
219
|
-
const
|
|
220
|
-
|
|
222
|
+
const o = t.getActiveObject() || null;
|
|
223
|
+
o instanceof y ? this.savedSelection = o.getObjects().slice() : o && (this.savedSelection = [o]), t.discardActiveObject(), t.set({
|
|
221
224
|
selection: !1,
|
|
222
225
|
defaultCursor: "grab"
|
|
223
|
-
}), t.setCursor("grab"), s.canvasManager.getObjects().forEach((
|
|
224
|
-
|
|
226
|
+
}), t.setCursor("grab"), s.canvasManager.getObjects().forEach((i) => {
|
|
227
|
+
i.set({
|
|
225
228
|
selectable: !1,
|
|
226
229
|
evented: !1
|
|
227
230
|
});
|
|
@@ -256,8 +259,8 @@ class Z {
|
|
|
256
259
|
t.setActiveObject(e[0]);
|
|
257
260
|
return;
|
|
258
261
|
}
|
|
259
|
-
const
|
|
260
|
-
t.setActiveObject(
|
|
262
|
+
const a = e.filter((o) => s.canvasManager.getObjects().includes(o)), n = new y(a, { canvas: t });
|
|
263
|
+
t.setActiveObject(n);
|
|
261
264
|
}
|
|
262
265
|
// --- Обработчики для событий canvas (Fabric) ---
|
|
263
266
|
/**
|
|
@@ -322,24 +325,24 @@ class Z {
|
|
|
322
325
|
* @returns true если событие должно быть проигнорировано
|
|
323
326
|
*/
|
|
324
327
|
_shouldIgnoreKeyboardEvent(e) {
|
|
325
|
-
const t = document.activeElement, s = e.target,
|
|
328
|
+
const t = document.activeElement, s = e.target, a = ["input", "textarea", "select"];
|
|
326
329
|
if (s) {
|
|
327
|
-
const
|
|
328
|
-
if (
|
|
330
|
+
const o = s.tagName.toLowerCase();
|
|
331
|
+
if (a.includes(o) || s.contentEditable === "true") return !0;
|
|
329
332
|
}
|
|
330
333
|
if (t && t !== s) {
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
334
|
+
const o = t.tagName.toLowerCase();
|
|
335
|
+
if (a.includes(o) || t.contentEditable === "true") return !0;
|
|
333
336
|
}
|
|
334
|
-
const
|
|
335
|
-
if (
|
|
336
|
-
let
|
|
337
|
-
|
|
338
|
-
const { keyboardIgnoreSelectors:
|
|
339
|
-
if (
|
|
340
|
-
for (const h of
|
|
337
|
+
const n = window.getSelection();
|
|
338
|
+
if (n && !n.isCollapsed && n.rangeCount > 0) {
|
|
339
|
+
let c = n.getRangeAt(0).commonAncestorContainer;
|
|
340
|
+
c.nodeType === Node.TEXT_NODE && (c = c.parentElement);
|
|
341
|
+
const { keyboardIgnoreSelectors: d } = this.options;
|
|
342
|
+
if (d != null && d.length && c)
|
|
343
|
+
for (const h of d)
|
|
341
344
|
try {
|
|
342
|
-
const l =
|
|
345
|
+
const l = c;
|
|
343
346
|
if (l.matches && l.matches(h) || l.closest && l.closest(h))
|
|
344
347
|
return !0;
|
|
345
348
|
} catch (l) {
|
|
@@ -352,7 +355,7 @@ class Z {
|
|
|
352
355
|
* Метод для удаления всех слушателей
|
|
353
356
|
*/
|
|
354
357
|
destroy() {
|
|
355
|
-
window.removeEventListener("resize", this.handleContainerResizeBound, { capture: !0 }), document.removeEventListener("keydown", this.handleCopyEventBound, { capture: !0 }), document.removeEventListener("paste", this.handlePasteEventBound, { capture: !0 }), document.removeEventListener("keydown", this.handleUndoRedoEventBound, { capture: !0 }), document.removeEventListener("keyup", this.handleUndoRedoKeyUpBound, { capture: !0 }), document.removeEventListener("keydown", this.handleSelectAllEventBound, { capture: !0 }), document.removeEventListener("keydown", this.handleDeleteObjectsEventBound, { capture: !0 }), this.options.canvasDragging && (this.canvas.off("mouse:down", this.handleCanvasDragStartBound), this.canvas.off("mouse:move", this.handleCanvasDraggingBound), this.canvas.off("mouse:up", this.handleCanvasDragEndBound), document.removeEventListener("keydown", this.handleSpaceKeyDownBound, { capture: !0 }), document.removeEventListener("keyup", this.handleSpaceKeyUpBound, { capture: !0 })), this.options.mouseWheelZooming && this.canvas.off("mouse:wheel", this.handleMouseWheelZoomBound), this.options.bringToFrontOnSelection && (this.canvas.off("selection:created", this.handleBringToFrontBound), this.canvas.off("selection:updated", this.handleBringToFrontBound)), this.options.resetObjectFitByDoubleClick && this.canvas.off("mouse:dblclick", this.handleResetObjectFitBound), this.canvas.off("object:modified", this.handleObjectModifiedHistoryBound), this.canvas.off("object:rotating", this.handleObjectRotatingHistoryBound), this.canvas.off("object:added", this.handleObjectAddedHistoryBound), this.canvas.off("object:removed", this.handleObjectRemovedHistoryBound), this.canvas.off("object:added", this.handleOverlayUpdateBound), this.canvas.off("selection:created", this.handleOverlayUpdateBound), this.canvas.off("selection:created", this.handleLockedSelectionBound), this.canvas.off("selection:updated", this.handleLockedSelectionBound);
|
|
358
|
+
window.removeEventListener("resize", this.handleContainerResizeBound, { capture: !0 }), document.removeEventListener("keydown", this.handleCopyEventBound, { capture: !0 }), document.removeEventListener("paste", this.handlePasteEventBound, { capture: !0 }), document.removeEventListener("keydown", this.handleUndoRedoEventBound, { capture: !0 }), document.removeEventListener("keyup", this.handleUndoRedoKeyUpBound, { capture: !0 }), document.removeEventListener("keydown", this.handleSelectAllEventBound, { capture: !0 }), document.removeEventListener("keydown", this.handleDeleteObjectsEventBound, { capture: !0 }), this.options.canvasDragging && (this.canvas.off("mouse:down", this.handleCanvasDragStartBound), this.canvas.off("mouse:move", this.handleCanvasDraggingBound), this.canvas.off("mouse:up", this.handleCanvasDragEndBound), document.removeEventListener("keydown", this.handleSpaceKeyDownBound, { capture: !0 }), document.removeEventListener("keyup", this.handleSpaceKeyUpBound, { capture: !0 })), this.options.mouseWheelZooming && this.canvas.off("mouse:wheel", this.handleMouseWheelZoomBound), this.options.bringToFrontOnSelection && (this.canvas.off("selection:created", this.handleBringToFrontBound), this.canvas.off("selection:updated", this.handleBringToFrontBound)), this.options.resetObjectFitByDoubleClick && this.canvas.off("mouse:dblclick", this.handleResetObjectFitBound), this.canvas.off("object:modified", this.handleObjectModifiedHistoryBound), this.canvas.off("object:rotating", this.handleObjectRotatingHistoryBound), this.canvas.off("object:added", this.handleObjectAddedHistoryBound), this.canvas.off("object:removed", this.handleObjectRemovedHistoryBound), this.canvas.off("object:added", this.handleOverlayUpdateBound), this.canvas.off("selection:created", this.handleOverlayUpdateBound), this.canvas.off("object:added", this.handleBackgroundUpdateBound), this.canvas.off("selection:created", this.handleBackgroundUpdateBound), this.canvas.off("selection:created", this.handleLockedSelectionBound), this.canvas.off("selection:updated", this.handleLockedSelectionBound);
|
|
356
359
|
}
|
|
357
360
|
/**
|
|
358
361
|
* Дебаунс для снижения частоты вызова функции.
|
|
@@ -362,9 +365,9 @@ class Z {
|
|
|
362
365
|
*/
|
|
363
366
|
static debounce(e, t) {
|
|
364
367
|
let s = null;
|
|
365
|
-
return function(...
|
|
368
|
+
return function(...a) {
|
|
366
369
|
s !== null && clearTimeout(s), s = setTimeout(() => {
|
|
367
|
-
e.apply(this,
|
|
370
|
+
e.apply(this, a);
|
|
368
371
|
}, t);
|
|
369
372
|
};
|
|
370
373
|
}
|
|
@@ -387,7 +390,7 @@ class xe {
|
|
|
387
390
|
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}"`));
|
|
388
391
|
}
|
|
389
392
|
}
|
|
390
|
-
function
|
|
393
|
+
function Re(r) {
|
|
391
394
|
return new Worker(
|
|
392
395
|
"" + new URL("assets/worker-CN39s7P7.js", import.meta.url).href,
|
|
393
396
|
{
|
|
@@ -395,13 +398,13 @@ function Be(r) {
|
|
|
395
398
|
}
|
|
396
399
|
);
|
|
397
400
|
}
|
|
398
|
-
class
|
|
401
|
+
class Ue {
|
|
399
402
|
/**
|
|
400
403
|
* @param scriptUrl — URL скрипта воркера.
|
|
401
404
|
* По-умолчанию использует DefaultWorker из соседнего файла
|
|
402
405
|
*/
|
|
403
406
|
constructor(e) {
|
|
404
|
-
e ? this.worker = new Worker(e, { type: "module" }) : this.worker = new
|
|
407
|
+
e ? this.worker = new Worker(e, { type: "module" }) : this.worker = new Re(), this._callbacks = /* @__PURE__ */ new Map(), this.worker.onmessage = this._handleMessage.bind(this);
|
|
405
408
|
}
|
|
406
409
|
/**
|
|
407
410
|
* Обработчик сообщений от воркера
|
|
@@ -414,12 +417,12 @@ class _e {
|
|
|
414
417
|
* @returns
|
|
415
418
|
*/
|
|
416
419
|
_handleMessage({ data: e }) {
|
|
417
|
-
const { requestId: t, success: s, data:
|
|
418
|
-
if (!
|
|
420
|
+
const { requestId: t, success: s, data: a, error: n } = e, o = this._callbacks.get(t);
|
|
421
|
+
if (!o) {
|
|
419
422
|
console.warn(`No callback found for requestId: ${t}`);
|
|
420
423
|
return;
|
|
421
424
|
}
|
|
422
|
-
s ?
|
|
425
|
+
s ? o.resolve(a) : o.reject(new Error(n)), this._callbacks.delete(t);
|
|
423
426
|
}
|
|
424
427
|
/**
|
|
425
428
|
* Универсальный метод отправки команды в воркер
|
|
@@ -429,9 +432,9 @@ class _e {
|
|
|
429
432
|
* @returns Promise, который будет выполнен, когда воркер вернет ответ
|
|
430
433
|
*/
|
|
431
434
|
post(e, t, s = []) {
|
|
432
|
-
const
|
|
433
|
-
return new Promise((
|
|
434
|
-
this._callbacks.set(
|
|
435
|
+
const a = `${e}:${v(8)}`;
|
|
436
|
+
return new Promise((n, o) => {
|
|
437
|
+
this._callbacks.set(a, { resolve: n, reject: o }), this.worker.postMessage({ action: e, payload: t, requestId: a }, s);
|
|
435
438
|
});
|
|
436
439
|
}
|
|
437
440
|
/**
|
|
@@ -441,112 +444,112 @@ class _e {
|
|
|
441
444
|
this.worker.terminate();
|
|
442
445
|
}
|
|
443
446
|
}
|
|
444
|
-
const
|
|
445
|
-
function
|
|
446
|
-
const
|
|
447
|
-
r.save(), r.translate(e, t), r.rotate(
|
|
447
|
+
const N = 12, He = 2, q = 8, ee = 20, ze = 100, te = 20, se = 8, Ze = 100, G = 32, ae = 1, Pe = "#2B2D33", ne = "#3D8BF4", oe = "#FFFFFF";
|
|
448
|
+
function F(r, e, t, s, a) {
|
|
449
|
+
const n = N, o = He;
|
|
450
|
+
r.save(), r.translate(e, t), r.rotate(P.degreesToRadians(a.angle)), r.fillStyle = oe, r.strokeStyle = ne, r.lineWidth = ae, r.beginPath(), r.roundRect(-n / 2, -n / 2, n, n, o), r.fill(), r.stroke(), r.restore();
|
|
448
451
|
}
|
|
449
|
-
function
|
|
450
|
-
const
|
|
451
|
-
r.save(), r.translate(e, t), r.rotate(
|
|
452
|
+
function Me(r, e, t, s, a) {
|
|
453
|
+
const n = q, o = ee, i = ze;
|
|
454
|
+
r.save(), r.translate(e, t), r.rotate(P.degreesToRadians(a.angle)), r.fillStyle = oe, r.strokeStyle = ne, r.lineWidth = ae, r.beginPath(), r.roundRect(-n / 2, -o / 2, n, o, i), r.fill(), r.stroke(), r.restore();
|
|
452
455
|
}
|
|
453
|
-
function
|
|
454
|
-
const
|
|
455
|
-
r.save(), r.translate(e, t), r.rotate(
|
|
456
|
+
function fe(r, e, t, s, a) {
|
|
457
|
+
const n = te, o = se, i = Ze;
|
|
458
|
+
r.save(), r.translate(e, t), r.rotate(P.degreesToRadians(a.angle)), r.fillStyle = oe, r.strokeStyle = ne, r.lineWidth = ae, r.beginPath(), r.roundRect(-n / 2, -o / 2, n, o, i), r.fill(), r.stroke(), r.restore();
|
|
456
459
|
}
|
|
457
|
-
const
|
|
458
|
-
je.src =
|
|
459
|
-
function
|
|
460
|
-
const
|
|
461
|
-
r.save(), r.translate(e, t), r.rotate(
|
|
460
|
+
const Ye = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", je = new Image();
|
|
461
|
+
je.src = Ye;
|
|
462
|
+
function We(r, e, t, s, a) {
|
|
463
|
+
const o = G / 2;
|
|
464
|
+
r.save(), r.translate(e, t), r.rotate(P.degreesToRadians(a.angle)), r.fillStyle = Pe, r.beginPath(), r.arc(0, 0, o, 0, 2 * Math.PI), r.fill(), r.drawImage(je, -o / 2, -o / 2, o, o), r.restore();
|
|
462
465
|
}
|
|
463
|
-
const
|
|
466
|
+
const Fe = {
|
|
464
467
|
// Угловые точки
|
|
465
468
|
tl: {
|
|
466
|
-
render:
|
|
467
|
-
sizeX:
|
|
468
|
-
sizeY:
|
|
469
|
+
render: F,
|
|
470
|
+
sizeX: N,
|
|
471
|
+
sizeY: N,
|
|
469
472
|
offsetX: 0,
|
|
470
473
|
offsetY: 0
|
|
471
474
|
},
|
|
472
475
|
tr: {
|
|
473
|
-
render:
|
|
474
|
-
sizeX:
|
|
475
|
-
sizeY:
|
|
476
|
+
render: F,
|
|
477
|
+
sizeX: N,
|
|
478
|
+
sizeY: N,
|
|
476
479
|
offsetX: 0,
|
|
477
480
|
offsetY: 0
|
|
478
481
|
},
|
|
479
482
|
bl: {
|
|
480
|
-
render:
|
|
481
|
-
sizeX:
|
|
482
|
-
sizeY:
|
|
483
|
+
render: F,
|
|
484
|
+
sizeX: N,
|
|
485
|
+
sizeY: N,
|
|
483
486
|
offsetX: 0,
|
|
484
487
|
offsetY: 0
|
|
485
488
|
},
|
|
486
489
|
br: {
|
|
487
|
-
render:
|
|
488
|
-
sizeX:
|
|
489
|
-
sizeY:
|
|
490
|
+
render: F,
|
|
491
|
+
sizeX: N,
|
|
492
|
+
sizeY: N,
|
|
490
493
|
offsetX: 0,
|
|
491
494
|
offsetY: 0
|
|
492
495
|
},
|
|
493
496
|
// Середина вертикалей
|
|
494
497
|
ml: {
|
|
495
|
-
render:
|
|
496
|
-
sizeX:
|
|
497
|
-
sizeY:
|
|
498
|
+
render: Me,
|
|
499
|
+
sizeX: q,
|
|
500
|
+
sizeY: ee,
|
|
498
501
|
offsetX: 0,
|
|
499
502
|
offsetY: 0
|
|
500
503
|
},
|
|
501
504
|
mr: {
|
|
502
|
-
render:
|
|
503
|
-
sizeX:
|
|
504
|
-
sizeY:
|
|
505
|
+
render: Me,
|
|
506
|
+
sizeX: q,
|
|
507
|
+
sizeY: ee,
|
|
505
508
|
offsetX: 0,
|
|
506
509
|
offsetY: 0
|
|
507
510
|
},
|
|
508
511
|
// Середина горизонталей
|
|
509
512
|
mt: {
|
|
510
|
-
render:
|
|
511
|
-
sizeX:
|
|
512
|
-
sizeY:
|
|
513
|
+
render: fe,
|
|
514
|
+
sizeX: te,
|
|
515
|
+
sizeY: se,
|
|
513
516
|
offsetX: 0,
|
|
514
517
|
offsetY: 0
|
|
515
518
|
},
|
|
516
519
|
mb: {
|
|
517
|
-
render:
|
|
518
|
-
sizeX:
|
|
519
|
-
sizeY:
|
|
520
|
+
render: fe,
|
|
521
|
+
sizeX: te,
|
|
522
|
+
sizeY: se,
|
|
520
523
|
offsetX: 0,
|
|
521
524
|
offsetY: 0
|
|
522
525
|
},
|
|
523
526
|
// Специальный «rotate» контрол
|
|
524
527
|
mtr: {
|
|
525
|
-
render:
|
|
526
|
-
sizeX:
|
|
527
|
-
sizeY:
|
|
528
|
+
render: We,
|
|
529
|
+
sizeX: G,
|
|
530
|
+
sizeY: G,
|
|
528
531
|
offsetX: 0,
|
|
529
|
-
offsetY: -
|
|
532
|
+
offsetY: -G
|
|
530
533
|
}
|
|
531
534
|
};
|
|
532
|
-
class
|
|
535
|
+
class Ve {
|
|
533
536
|
static apply() {
|
|
534
|
-
const e =
|
|
535
|
-
Object.entries(
|
|
537
|
+
const e = Ce.createObjectDefaultControls();
|
|
538
|
+
Object.entries(Fe).forEach(([t, s]) => {
|
|
536
539
|
Object.assign(e[t], {
|
|
537
540
|
render: s.render,
|
|
538
541
|
sizeX: s.sizeX,
|
|
539
542
|
sizeY: s.sizeY,
|
|
540
543
|
offsetX: s.offsetX,
|
|
541
544
|
offsetY: s.offsetY
|
|
542
|
-
}), t === "mtr" && (e[t].cursorStyle = "grab", e[t].mouseDownHandler = (
|
|
545
|
+
}), t === "mtr" && (e[t].cursorStyle = "grab", e[t].mouseDownHandler = (n, o, i, c) => {
|
|
543
546
|
var h;
|
|
544
|
-
(h =
|
|
547
|
+
(h = o.target.canvas) == null || h.setCursor("grabbing");
|
|
545
548
|
});
|
|
546
549
|
}), Se.ownDefaults.controls = e;
|
|
547
550
|
}
|
|
548
551
|
}
|
|
549
|
-
const
|
|
552
|
+
const Ge = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNNi44NzUgMi41YS42MjUuNjI1IDAgMCAwLS42MjUuNjI0VjYuMjVIMy4xMjVhLjYyNS42MjUgMCAwIDAtLjYyNS42MjV2MTBjMCAuMzQ1LjI4LjYyNS42MjUuNjI1aDEwYy4zNDUgMCAuNjI1LS4yOC42MjUtLjYyNXYtMy4xMjZoMy4xMjVjLjM0NSAwIC42MjUtLjI4LjYyNS0uNjI1di0xMGEuNjI1LjYyNSAwIDAgMC0uNjI1LS42MjVoLTEwWm02Ljg3NSAxMGgyLjVWMy43NUg3LjV2Mi41aDUuNjI1Yy4zNDUgMCAuNjI1LjI4LjYyNS42MjV2NS42MjRabS0xMCAzLjc1VjcuNWg4Ljc1djguNzVIMy43NVoiIGNsaXAtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==", Xe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMi41IDcuNWMwLS42OS41Ni0xLjI1IDEuMjUtMS4yNWgxMi41Yy42OSAwIDEuMjUuNTYgMS4yNSAxLjI1djguNzVjMCAuNjktLjU2IDEuMjUtMS4yNSAxLjI1SDMuNzVjLS42OSAwLTEuMjUtLjU2LTEuMjUtMS4yNVY3LjVabTEzLjc1IDBIMy43NXY4Ljc1aDEyLjVWNy41WiIgY2xpcC1ydWxlPSJldmVub2RkIi8+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMTAgMS44NzVhMi4xODggMi4xODggMCAwIDAtMi4xODggMi4xODh2Mi44MTJhLjYyNS42MjUgMCAxIDEtMS4yNSAwVjQuMDYyYTMuNDM3IDMuNDM3IDAgMSAxIDYuODc1IDB2Mi44MTNhLjYyNS42MjUgMCAxIDEtMS4yNSAwVjQuMDYyQTIuMTg4IDIuMTg4IDAgMCAwIDEwIDEuODc2WiIgY2xpcC1ydWxlPSJldmVub2RkIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTEwIDEyLjgxM2EuOTM3LjkzNyAwIDEgMCAwLTEuODc1LjkzNy45MzcgMCAwIDAgMCAxLjg3NFoiLz48L3N2Zz4=", Qe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE2LjI1IDYuMjVINy41VjQuMzc1YTIuNSAyLjUgMCAwIDEgMi41LTIuNWMxLjIgMCAyLjI4MS44NiAyLjUxMiAyYS42MjUuNjI1IDAgMCAwIDEuMjI2LS4yNWMtLjM1NC0xLjczOC0xLjkyNS0zLTMuNzM4LTNhMy43NTQgMy43NTQgMCAwIDAtMy43NSAzLjc1VjYuMjVoLTIuNUExLjI1IDEuMjUgMCAwIDAgMi41IDcuNXY4Ljc1YTEuMjUgMS4yNSAwIDAgMCAxLjI1IDEuMjVoMTIuNWExLjI1IDEuMjUgMCAwIDAgMS4yNS0xLjI1VjcuNWExLjI1IDEuMjUgMCAwIDAtMS4yNS0xLjI1Wm0wIDEwSDMuNzVWNy41aDEyLjV2OC43NVptLTUuMzEzLTQuMzc1YS45MzcuOTM3IDAgMSAxLTEuODc0IDAgLjkzNy45MzcgMCAwIDEgMS44NzQgMFoiLz48L3N2Zz4K", Ke = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTIuNSA4LjEyNSAxMCAxMi41bDcuNS00LjM3NUwxMCAzLjc1IDIuNSA4LjEyNVoiLz48cGF0aCBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik05LjY4NSAzLjIxYS42MjUuNjI1IDAgMCAxIC42MyAwbDcuNSA0LjM3NWEuNjI1LjYyNSAwIDAgMSAwIDEuMDhsLTcuNSA0LjM3NWEuNjI1LjYyNSAwIDAgMS0uNjMgMGwtNy41LTQuMzc1YS42MjUuNjI1IDAgMCAxIDAtMS4wOGw3LjUtNC4zNzVaTTMuNzQgOC4xMjUgMTAgMTEuNzc2bDYuMjYtMy42NTFMMTAgNC40NzQgMy43NCA4LjEyNVoiIGNsaXAtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTUuNCA5LjQ2YS42MjUuNjI1IDAgMCAxIC42MyAwTDEwIDExLjc3NmwzLjk3LTIuMzE2YS42MjUuNjI1IDAgMCAxIC42MyAwbDMuMjE1IDEuODc1YS42MjUuNjI1IDAgMCAxIDAgMS4wOGwtNy41IDQuMzc1YS42MjUuNjI1IDAgMCAxLS42MyAwbC03LjUtNC4zNzVhLjYyNS42MjUgMCAwIDEgMC0xLjA4TDUuNCA5LjQ2Wm0tMS42NiAyLjQxNUwxMCAxNS41MjZsNi4yNi0zLjY1MS0xLjk3NC0xLjE1MS0zLjk3MSAyLjMxNmEuNjI1LjYyNSAwIDAgMS0uNjMgMGwtMy45Ny0yLjMxNi0xLjk3NSAxLjE1MVoiIGNsaXAtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==", $e = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNOS42ODUgMy4yMWEuNjI1LjYyNSAwIDAgMSAuNjMgMGw3LjUgNC4zNzVhLjYyNS42MjUgMCAwIDEgMCAxLjA4bC03LjUgNC4zNzVhLjYyNS42MjUgMCAwIDEtLjYzIDBsLTcuNS00LjM3NWEuNjI1LjYyNSAwIDAgMSAwLTEuMDhsNy41LTQuMzc1Wk0zLjc0IDguMTI1IDEwIDExLjc3Nmw2LjI2LTMuNjUxTDEwIDQuNDc0IDMuNzQgOC4xMjVaIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01LjcxNCAxMCAxMCAxMi41bDQuMjg2LTIuNSAzLjIxNCAxLjg3NUwxMCAxNi4yNWwtNy41LTQuMzc1TDUuNzE0IDEwWiIgY2xpcC1ydWxlPSJldmVub2RkIi8+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNNS40IDkuNDZhLjYyNS42MjUgMCAwIDEgLjYzIDBMMTAgMTEuNzc2bDMuOTctMi4zMTZhLjYyNS42MjUgMCAwIDEgLjYzIDBsMy4yMTUgMS44NzVhLjYyNS42MjUgMCAwIDEgMCAxLjA4bC03LjUgNC4zNzVhLjYyNS42MjUgMCAwIDEtLjYzIDBsLTcuNS00LjM3NWEuNjI1LjYyNSAwIDAgMSAwLTEuMDhMNS40IDkuNDZabS0xLjY2IDIuNDE1TDEwIDE1LjUyNmw2LjI2LTMuNjUxLTEuOTc0LTEuMTUxLTMuOTcxIDIuMzE2YS42MjUuNjI1IDAgMCAxLS42MyAwbC0zLjk3LTIuMzE2LTEuOTc1IDEuMTUxWiIgY2xpcC1ydWxlPSJldmVub2RkIi8+PC9zdmc+", Je = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0ibTIuNSA2LjI1IDcuNSA0LjM3NSA3LjUtNC4zNzVMMTAgMS44NzUgMi41IDYuMjVaIi8+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNOS42ODUgMS4zMzVhLjYyNS42MjUgMCAwIDEgLjYzIDBsNy41IDQuMzc1YS42MjUuNjI1IDAgMCAxIDAgMS4wOGwtNy41IDQuMzc1YS42MjUuNjI1IDAgMCAxLS42MyAwbC03LjUtNC4zNzVhLjYyNS42MjUgMCAwIDEgMC0xLjA4bDcuNS00LjM3NVpNMy43NCA2LjI1IDEwIDkuOTAxbDYuMjYtMy42NTFMMTAgMi41OTkgMy43NCA2LjI1WiIgY2xpcC1ydWxlPSJldmVub2RkIi8+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNNS40IDExLjMzNWEuNjI1LjYyNSAwIDAgMSAuNjMgMEwxMCAxMy42NTFsMy45Ny0yLjMxNmEuNjI1LjYyNSAwIDAgMSAuNjMgMGwzLjIxNSAxLjg3NWEuNjI1LjYyNSAwIDAgMSAwIDEuMDhsLTcuNSA0LjM3NWEuNjI1LjYyNSAwIDAgMS0uNjMgMGwtNy41LTQuMzc1YS42MjUuNjI1IDAgMCAxIDAtMS4wOEw1LjQgMTEuMzM1Wk0zLjc0IDEzLjc1IDEwIDE3LjQwMWw2LjI2LTMuNjUxLTEuOTc0LTEuMTUxLTMuOTcxIDIuMzE2YS42MjUuNjI1IDAgMCAxLS42MyAwbC0zLjk3LTIuMzE2TDMuNzQgMTMuNzVaIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01LjQgNy41ODVhLjYyNS42MjUgMCAwIDEgLjYzIDBMMTAgOS45MDFsMy45Ny0yLjMxNmEuNjI1LjYyNSAwIDAgMSAuNjMgMGwzLjIxNSAxLjg3NWEuNjI1LjYyNSAwIDAgMSAwIDEuMDhsLTcuNSA0LjM3NWEuNjI1LjYyNSAwIDAgMS0uNjMgMGwtNy41LTQuMzc1YS42MjUuNjI1IDAgMCAxIDAtMS4wOEw1LjQgNy41ODVaTTMuNzQgMTAgMTAgMTMuNjUxIDE2LjI2IDEwbC0xLjk3NC0xLjE1MS0zLjk3MSAyLjMxNmEuNjI1LjYyNSAwIDAgMS0uNjMgMGwtMy45Ny0yLjMxNkwzLjc0IDEwWiIgY2xpcC1ydWxlPSJldmVub2RkIi8+PC9zdmc+", qe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMS45NiAxMy40MzVhLjYyNS42MjUgMCAwIDEgLjg1NS0uMjI1TDEwIDE3LjQwMWw3LjE4NS00LjE5YS42MjUuNjI1IDAgMCAxIC42MyAxLjA3OWwtNy41IDQuMzc1YS42MjUuNjI1IDAgMCAxLS42MyAwbC03LjUtNC4zNzVhLjYyNS42MjUgMCAwIDEtLjIyNS0uODU1Wk05LjY4NSAxLjMzNWEuNjI1LjYyNSAwIDAgMSAuNjMgMGw3LjUgNC4zNzVhLjYyNS42MjUgMCAwIDEgMCAxLjA4bC03LjUgNC4zNzVhLjYyNS42MjUgMCAwIDEtLjYzIDBsLTcuNS00LjM3NWEuNjI1LjYyNSAwIDAgMSAwLTEuMDhsNy41LTQuMzc1Wk0zLjc0IDYuMjUgMTAgOS45MDFsNi4yNi0zLjY1MUwxMCAyLjU5OSAzLjc0IDYuMjVaIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Im01LjcxNCAxMS44NzUgNC4yODYgMi41IDQuMjg2LTIuNUwxNy41IDEzLjc1IDEwIDE4LjEyNSAyLjUgMTMuNzVsMy4yMTQtMS44NzVaIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01LjQgMTEuMzM1YS42MjUuNjI1IDAgMCAxIC42MyAwTDEwIDEzLjY1MWwzLjk3LTIuMzE2YS42MjUuNjI1IDAgMCAxIC42MyAwbDMuMjE1IDEuODc1YS42MjUuNjI1IDAgMCAxIDAgMS4wOGwtNy41IDQuMzc1YS42MjUuNjI1IDAgMCAxLS42MyAwbC03LjUtNC4zNzVhLjYyNS42MjUgMCAwIDEgMC0xLjA4TDUuNCAxMS4zMzVaTTMuNzQgMTMuNzUgMTAgMTcuNDAxbDYuMjYtMy42NTEtMS45NzQtMS4xNTEtMy45NzEgMi4zMTZhLjYyNS42MjUgMCAwIDEtLjYzIDBsLTMuOTctMi4zMTZMMy43NCAxMy43NVoiIGNsaXAtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTUuNCA3LjU4NWEuNjI1LjYyNSAwIDAgMSAuNjMgMEwxMCA5LjkwMWwzLjk3LTIuMzE2YS42MjUuNjI1IDAgMCAxIC42MyAwbDMuMjE1IDEuODc1YS42MjUuNjI1IDAgMCAxIDAgMS4wOGwtNy41IDQuMzc1YS42MjUuNjI1IDAgMCAxLS42MyAwbC03LjUtNC4zNzVhLjYyNS42MjUgMCAwIDEgMC0xLjA4TDUuNCA3LjU4NVpNMy43NCAxMCAxMCAxMy42NTEgMTYuMjYgMTBsLTEuOTc0LTEuMTUxLTMuOTcxIDIuMzE2YS42MjUuNjI1IDAgMCAxLS42MyAwbC0zLjk3LTIuMzE2TDMuNzQgMTBaIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiLz48L3N2Zz4=", et = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI0VDNEU0MCIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNOC4xMjUgMS4yNUExLjg3NSAxLjg3NSAwIDAgMCA2LjI1IDMuMTI1di42MjVIMy4xMjVhLjYyNS42MjUgMCAwIDAgMCAxLjI1aC42MjV2MTEuMjVBMS4yNSAxLjI1IDAgMCAwIDUgMTcuNWgxMGExLjI1IDEuMjUgMCAwIDAgMS4yNS0xLjI1VjVoLjYyNWEuNjI1LjYyNSAwIDAgMCAwLTEuMjVIMTMuNzV2LS42MjVhMS44NzUgMS44NzUgMCAwIDAtMS44NzUtMS44NzVoLTMuNzVabTQuMzc1IDIuNXYtLjYyNWEuNjI1LjYyNSAwIDAgMC0uNjI1LS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDAtLjYyNS42MjV2LjYyNWg1Wk01IDE2LjI1VjVoMTB2MTEuMjVINVpNOC4xMjUgNy41Yy4zNDUgMCAuNjI1LjI4LjYyNS42MjV2NWEuNjI1LjYyNSAwIDEgMS0xLjI1IDB2LTVjMC0uMzQ1LjI4LS42MjUuNjI1LS42MjVabTQuMzc1IDUuNjI1di01YS42MjUuNjI1IDAgMCAwLTEuMjUgMHY1YS42MjUuNjI1IDAgMSAwIDEuMjUgMFoiIGNsaXAtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==", z = {
|
|
550
553
|
style: {
|
|
551
554
|
position: "absolute",
|
|
552
555
|
display: "none",
|
|
@@ -613,17 +616,17 @@ const Fe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj
|
|
|
613
616
|
],
|
|
614
617
|
offsetTop: 50,
|
|
615
618
|
icons: {
|
|
616
|
-
copyPaste:
|
|
617
|
-
delete:
|
|
618
|
-
lock:
|
|
619
|
-
unlock:
|
|
620
|
-
bringToFront:
|
|
621
|
-
sendToBack:
|
|
622
|
-
bringForward:
|
|
623
|
-
sendBackwards:
|
|
619
|
+
copyPaste: Ge,
|
|
620
|
+
delete: et,
|
|
621
|
+
lock: Xe,
|
|
622
|
+
unlock: Qe,
|
|
623
|
+
bringToFront: Je,
|
|
624
|
+
sendToBack: qe,
|
|
625
|
+
bringForward: Ke,
|
|
626
|
+
sendBackwards: $e
|
|
624
627
|
},
|
|
625
628
|
handlers: {
|
|
626
|
-
copyPaste: (r) =>
|
|
629
|
+
copyPaste: (r) => b(null, null, function* () {
|
|
627
630
|
r.clipboardManager.copyPaste();
|
|
628
631
|
}),
|
|
629
632
|
delete: (r) => {
|
|
@@ -649,14 +652,14 @@ const Fe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj
|
|
|
649
652
|
}
|
|
650
653
|
}
|
|
651
654
|
};
|
|
652
|
-
class
|
|
655
|
+
class tt {
|
|
653
656
|
constructor({ editor: e }) {
|
|
654
657
|
this.currentTarget = null, this.currentLocked = !1, this.isTransforming = !1, this.editor = e, this.canvas = e.canvas, this.options = e.options, this._initToolbar();
|
|
655
658
|
}
|
|
656
659
|
_initToolbar() {
|
|
657
660
|
if (!this.options.showToolbar) return;
|
|
658
661
|
const e = this.options.toolbar || {};
|
|
659
|
-
this.config =
|
|
662
|
+
this.config = ue(p(p({}, z), e), {
|
|
660
663
|
style: p(p({}, z.style), e.style || {}),
|
|
661
664
|
btnStyle: p(p({}, z.btnStyle), e.btnStyle || {}),
|
|
662
665
|
icons: p(p({}, z.icons), e.icons || {}),
|
|
@@ -671,11 +674,11 @@ class qe {
|
|
|
671
674
|
_createDOM() {
|
|
672
675
|
const { style: e } = this.config;
|
|
673
676
|
this.el = document.createElement("div"), Object.assign(this.el.style, e), this.canvas.wrapperEl.appendChild(this.el), this._onBtnOver = (t) => {
|
|
674
|
-
const
|
|
675
|
-
|
|
677
|
+
const a = t.target.closest("button");
|
|
678
|
+
a && Object.assign(a.style, this.config.btnHover);
|
|
676
679
|
}, this._onBtnOut = (t) => {
|
|
677
|
-
const
|
|
678
|
-
|
|
680
|
+
const a = t.target.closest("button");
|
|
681
|
+
a && Object.assign(a.style, this.config.btnStyle);
|
|
679
682
|
}, this.el.addEventListener("mouseover", this._onBtnOver), this.el.addEventListener("mouseout", this._onBtnOut);
|
|
680
683
|
}
|
|
681
684
|
/**
|
|
@@ -687,13 +690,13 @@ class qe {
|
|
|
687
690
|
_renderButtons(e) {
|
|
688
691
|
this.el.innerHTML = "";
|
|
689
692
|
for (const t of e) {
|
|
690
|
-
const { name: s, handle:
|
|
691
|
-
|
|
692
|
-
var
|
|
693
|
-
return (
|
|
694
|
-
},
|
|
695
|
-
|
|
696
|
-
},
|
|
693
|
+
const { name: s, handle: a } = t, { icons: n = {}, btnStyle: o, handlers: i = {} } = this.config, c = document.createElement("button");
|
|
694
|
+
c.innerHTML = n[a] ? `<img src="${n[a]}" title="${s}" />` : s, Object.assign(c.style, o), c.onclick = () => {
|
|
695
|
+
var d;
|
|
696
|
+
return (d = i[a]) == null ? void 0 : d.call(i, this.editor);
|
|
697
|
+
}, c.onmousedown = (d) => {
|
|
698
|
+
d.stopPropagation(), d.preventDefault();
|
|
699
|
+
}, c.ondragstart = (d) => d.preventDefault(), this.el.appendChild(c);
|
|
697
700
|
}
|
|
698
701
|
}
|
|
699
702
|
/**
|
|
@@ -749,12 +752,12 @@ class qe {
|
|
|
749
752
|
this.el.style.display = "none";
|
|
750
753
|
return;
|
|
751
754
|
}
|
|
752
|
-
const { el: t, config: s, canvas:
|
|
755
|
+
const { el: t, config: s, canvas: a } = this;
|
|
753
756
|
e.setCoords();
|
|
754
|
-
const
|
|
757
|
+
const n = a.getZoom(), [, , , , o, i] = a.viewportTransform, { x: c } = e.getCenterPoint(), { top: d, height: h } = e.getBoundingRect(), g = c * n + o - t.offsetWidth / 2, M = s.offsetTop || 0, m = (d + h) * n + i + M;
|
|
755
758
|
Object.assign(t.style, {
|
|
756
759
|
left: `${g}px`,
|
|
757
|
-
top: `${
|
|
760
|
+
top: `${m}px`,
|
|
758
761
|
display: "flex"
|
|
759
762
|
});
|
|
760
763
|
}
|
|
@@ -765,7 +768,7 @@ class qe {
|
|
|
765
768
|
this.el.removeEventListener("mouseover", this._onBtnOver), this.el.removeEventListener("mouseout", this._onBtnOut), this.canvas.off("mouse:down", this._onMouseDown), this.canvas.off("object:moving", this._onObjectMoving), this.canvas.off("object:scaling", this._onObjectScaling), this.canvas.off("object:rotating", this._onObjectRotating), this.canvas.off("mouse:up", this._onMouseUp), this.canvas.off("object:modified", this._onObjectModified), this.canvas.off("selection:created", this._onSelectionChange), this.canvas.off("selection:updated", this._onSelectionChange), this.canvas.off("after:render", this._onSelectionChange), this.canvas.off("selection:cleared", this._onSelectionClear), this.el.remove();
|
|
766
769
|
}
|
|
767
770
|
}
|
|
768
|
-
class
|
|
771
|
+
class st {
|
|
769
772
|
constructor({ editor: e }) {
|
|
770
773
|
this.editor = e, this.canvas = e.canvas, this._historySuspendCount = 0, this.baseState = null, this.patches = [], this.currentIndex = 0, this.maxHistoryLength = e.options.maxHistoryLength, this.totalChangesCount = 0, this.baseStateChangesCount = 0, this._createDiffPatcher();
|
|
771
774
|
}
|
|
@@ -777,11 +780,12 @@ class et {
|
|
|
777
780
|
return this.patches[this.currentIndex - 1] || null;
|
|
778
781
|
}
|
|
779
782
|
_createDiffPatcher() {
|
|
780
|
-
this.diffPatcher =
|
|
783
|
+
this.diffPatcher = ke({
|
|
781
784
|
objectHash(e) {
|
|
782
785
|
const t = e;
|
|
783
786
|
return [
|
|
784
787
|
t.id,
|
|
788
|
+
t.backgroundId,
|
|
785
789
|
t.format,
|
|
786
790
|
t.locked,
|
|
787
791
|
t.left,
|
|
@@ -801,7 +805,7 @@ class et {
|
|
|
801
805
|
includeValueOnMove: !1
|
|
802
806
|
},
|
|
803
807
|
textDiff: {
|
|
804
|
-
diffMatchPatch:
|
|
808
|
+
diffMatchPatch: Be,
|
|
805
809
|
minLength: 60
|
|
806
810
|
}
|
|
807
811
|
});
|
|
@@ -831,10 +835,10 @@ class et {
|
|
|
831
835
|
*/
|
|
832
836
|
getFullState() {
|
|
833
837
|
const { baseState: e, currentIndex: t, patches: s } = this;
|
|
834
|
-
let
|
|
835
|
-
for (let
|
|
836
|
-
|
|
837
|
-
return console.log("getFullState state",
|
|
838
|
+
let a = JSON.parse(JSON.stringify(e));
|
|
839
|
+
for (let n = 0; n < t; n += 1)
|
|
840
|
+
a = this.diffPatcher.patch(a, s[n].diff);
|
|
841
|
+
return console.log("getFullState state", a), a;
|
|
838
842
|
}
|
|
839
843
|
/**
|
|
840
844
|
* Сохраняем текущее состояние в виде диффа от последнего сохранённого полного состояния.
|
|
@@ -846,6 +850,8 @@ class et {
|
|
|
846
850
|
"selectable",
|
|
847
851
|
"evented",
|
|
848
852
|
"id",
|
|
853
|
+
"backgroundId",
|
|
854
|
+
"backgroundType",
|
|
849
855
|
"format",
|
|
850
856
|
"width",
|
|
851
857
|
"height",
|
|
@@ -867,7 +873,7 @@ class et {
|
|
|
867
873
|
console.log("Нет изменений для сохранения.");
|
|
868
874
|
return;
|
|
869
875
|
}
|
|
870
|
-
console.log("baseState", this.baseState), this.currentIndex < this.patches.length && this.patches.splice(this.currentIndex), console.log("diff", s), this.totalChangesCount += 1, this.patches.push({ id:
|
|
876
|
+
console.log("baseState", this.baseState), this.currentIndex < this.patches.length && this.patches.splice(this.currentIndex), console.log("diff", s), this.totalChangesCount += 1, this.patches.push({ id: v(), diff: s }), this.currentIndex += 1, this.patches.length > this.maxHistoryLength && (this.baseState = this.diffPatcher.patch(this.baseState, this.patches[0].diff), this.patches.shift(), this.currentIndex -= 1, this.baseStateChangesCount += 1), console.log("Состояние сохранено. Текущий индекс истории:", this.currentIndex);
|
|
871
877
|
}
|
|
872
878
|
/**
|
|
873
879
|
* Функция загрузки состояния в канвас.
|
|
@@ -875,15 +881,17 @@ class et {
|
|
|
875
881
|
* @fires editor:history-state-loaded
|
|
876
882
|
*/
|
|
877
883
|
loadStateFromFullState(e) {
|
|
878
|
-
return
|
|
884
|
+
return b(this, null, function* () {
|
|
879
885
|
if (!e) return;
|
|
880
886
|
console.log("loadStateFromFullState fullState", e);
|
|
881
|
-
const { canvas: t, canvasManager: s, interactionBlocker: n } = this.editor, { width:
|
|
887
|
+
const { canvas: t, canvasManager: s, interactionBlocker: a, backgroundManager: n } = this.editor, { width: o, height: i } = t;
|
|
882
888
|
yield t.loadFromJSON(e);
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
const d = t.getObjects().find((
|
|
886
|
-
d && (
|
|
889
|
+
const c = t.getObjects().find((l) => l.id === "montage-area");
|
|
890
|
+
c && (this.editor.montageArea = c, (o !== t.getWidth() || i !== t.getHeight()) && s.updateCanvas());
|
|
891
|
+
const d = t.getObjects().find((l) => l.id === "overlay-mask");
|
|
892
|
+
d && (a.overlayMask = d, a.overlayMask.visible = !1);
|
|
893
|
+
const h = t.getObjects().find((l) => l.id === "background");
|
|
894
|
+
h ? n.backgroundObject = h : n.removeBackground({ withoutSave: !0 }), t.renderAll(), t.fire("editor:history-state-loaded", {
|
|
887
895
|
fullState: e,
|
|
888
896
|
currentIndex: this.currentIndex,
|
|
889
897
|
totalChangesCount: this.totalChangesCount,
|
|
@@ -898,7 +906,7 @@ class et {
|
|
|
898
906
|
* @fires editor:undo
|
|
899
907
|
*/
|
|
900
908
|
undo() {
|
|
901
|
-
return
|
|
909
|
+
return b(this, null, function* () {
|
|
902
910
|
if (!this.skipHistory) {
|
|
903
911
|
if (this.currentIndex <= 0) {
|
|
904
912
|
console.log("Нет предыдущих состояний для отмены.");
|
|
@@ -935,7 +943,7 @@ class et {
|
|
|
935
943
|
* @fires editor:redo
|
|
936
944
|
*/
|
|
937
945
|
redo() {
|
|
938
|
-
return
|
|
946
|
+
return b(this, null, function* () {
|
|
939
947
|
if (!this.skipHistory) {
|
|
940
948
|
if (this.currentIndex >= this.patches.length) {
|
|
941
949
|
console.log("Нет состояний для повтора.");
|
|
@@ -968,8 +976,8 @@ class et {
|
|
|
968
976
|
});
|
|
969
977
|
}
|
|
970
978
|
}
|
|
971
|
-
const
|
|
972
|
-
class
|
|
979
|
+
const at = 0.1, nt = 2, ot = 0.1, it = 90, U = 16, H = 16, T = 4096, w = 4096, me = "application/image-editor:";
|
|
980
|
+
class O {
|
|
973
981
|
constructor({ editor: e }) {
|
|
974
982
|
this.editor = e, this.options = e.options, this._createdBlobUrls = [], this.acceptContentTypes = this.editor.options.acceptContentTypes, this.acceptFormats = this.getAllowedFormatsFromContentTypes();
|
|
975
983
|
}
|
|
@@ -986,83 +994,83 @@ class L {
|
|
|
986
994
|
* @returns возвращает Promise с объектом изображения или null в случае ошибки
|
|
987
995
|
*/
|
|
988
996
|
importImage(e) {
|
|
989
|
-
return
|
|
997
|
+
return b(this, null, function* () {
|
|
990
998
|
const {
|
|
991
999
|
source: t,
|
|
992
1000
|
scale: s = `image-${this.options.scaleType}`,
|
|
993
|
-
withoutSave:
|
|
994
|
-
fromClipboard:
|
|
1001
|
+
withoutSave: a = !1,
|
|
1002
|
+
fromClipboard: n = !1
|
|
995
1003
|
} = e;
|
|
996
1004
|
if (!t) return null;
|
|
997
|
-
const { canvas:
|
|
1005
|
+
const { canvas: o, montageArea: i, transformManager: c, historyManager: d, errorManager: h } = this.editor, l = yield this.getContentType(t), g = O.getFormatFromContentType(l), { acceptContentTypes: M, acceptFormats: m } = this;
|
|
998
1006
|
if (!this.isAllowedContentType(l)) {
|
|
999
|
-
const
|
|
1007
|
+
const f = `Неверный contentType для изображения: ${l}. Ожидается один из: ${this.acceptContentTypes.join(", ")}.`;
|
|
1000
1008
|
return h.emitError({
|
|
1001
1009
|
origin: "ImageManager",
|
|
1002
1010
|
method: "importImage",
|
|
1003
1011
|
code: "INVALID_CONTENT_TYPE",
|
|
1004
|
-
message:
|
|
1005
|
-
data: { source: t, format: g, contentType: l, acceptContentTypes: M, acceptFormats:
|
|
1012
|
+
message: f,
|
|
1013
|
+
data: { source: t, format: g, contentType: l, acceptContentTypes: M, acceptFormats: m, fromClipboard: n }
|
|
1006
1014
|
}), null;
|
|
1007
1015
|
}
|
|
1008
|
-
|
|
1016
|
+
d.suspendHistory();
|
|
1009
1017
|
try {
|
|
1010
|
-
let
|
|
1018
|
+
let f, u;
|
|
1011
1019
|
if (t instanceof File)
|
|
1012
|
-
|
|
1020
|
+
f = URL.createObjectURL(t);
|
|
1013
1021
|
else if (typeof t == "string") {
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1022
|
+
const E = yield (yield fetch(t, { mode: "cors" })).blob();
|
|
1023
|
+
f = URL.createObjectURL(E);
|
|
1016
1024
|
} else
|
|
1017
1025
|
return h.emitError({
|
|
1018
1026
|
origin: "ImageManager",
|
|
1019
1027
|
method: "importImage",
|
|
1020
1028
|
code: "INVALID_SOURCE_TYPE",
|
|
1021
1029
|
message: "Неверный тип источника изображения. Ожидается URL или объект File.",
|
|
1022
|
-
data: { source: t, format: g, contentType: l, acceptContentTypes: M, acceptFormats:
|
|
1030
|
+
data: { source: t, format: g, contentType: l, acceptContentTypes: M, acceptFormats: m, fromClipboard: n }
|
|
1023
1031
|
}), null;
|
|
1024
|
-
if (this._createdBlobUrls.push(
|
|
1025
|
-
const
|
|
1026
|
-
u =
|
|
1032
|
+
if (this._createdBlobUrls.push(f), g === "svg") {
|
|
1033
|
+
const A = yield Ee(f);
|
|
1034
|
+
u = P.groupSVGElements(A.objects, A.options);
|
|
1027
1035
|
} else
|
|
1028
|
-
u = yield
|
|
1029
|
-
const { width:
|
|
1030
|
-
if (u instanceof
|
|
1031
|
-
const
|
|
1032
|
-
let
|
|
1033
|
-
if (
|
|
1034
|
-
const
|
|
1035
|
-
this._createdBlobUrls.push(k), u = yield
|
|
1036
|
-
} else if (
|
|
1037
|
-
const
|
|
1038
|
-
this._createdBlobUrls.push(k), u = yield
|
|
1036
|
+
u = yield x.fromURL(f, { crossOrigin: "anonymous" });
|
|
1037
|
+
const { width: j, height: C } = u;
|
|
1038
|
+
if (u instanceof x) {
|
|
1039
|
+
const A = u.getElement();
|
|
1040
|
+
let E = "";
|
|
1041
|
+
if (A instanceof HTMLImageElement ? E = A.src : A instanceof HTMLCanvasElement && (E = A.toDataURL()), C > w || j > T) {
|
|
1042
|
+
const L = yield this.resizeImageToBoundaries(E, "max"), k = URL.createObjectURL(L);
|
|
1043
|
+
this._createdBlobUrls.push(k), u = yield x.fromURL(k, { crossOrigin: "anonymous" });
|
|
1044
|
+
} else if (C < H || j < U) {
|
|
1045
|
+
const L = yield this.resizeImageToBoundaries(E, "min"), k = URL.createObjectURL(L);
|
|
1046
|
+
this._createdBlobUrls.push(k), u = yield x.fromURL(k, { crossOrigin: "anonymous" });
|
|
1039
1047
|
}
|
|
1040
1048
|
}
|
|
1041
|
-
if (u.set("id", `${u.type}-${
|
|
1049
|
+
if (u.set("id", `${u.type}-${v()}`), u.set("format", g), s === "scale-montage")
|
|
1042
1050
|
this.editor.canvasManager.scaleMontageAreaToImage({ object: u, withoutSave: !0 });
|
|
1043
1051
|
else {
|
|
1044
|
-
const { width:
|
|
1045
|
-
s === "image-contain" &&
|
|
1052
|
+
const { width: A, height: E } = i, L = this.calculateScaleFactor({ imageObject: u, scaleType: s });
|
|
1053
|
+
s === "image-contain" && L < 1 ? c.fitObject({ object: u, type: "contain", withoutSave: !0 }) : s === "image-cover" && (j > A || C > E) && c.fitObject({ object: u, type: "cover", withoutSave: !0 });
|
|
1046
1054
|
}
|
|
1047
|
-
|
|
1055
|
+
o.add(u), o.centerObject(u), o.setActiveObject(u), o.renderAll(), d.resumeHistory(), a || d.saveState();
|
|
1048
1056
|
const S = {
|
|
1049
1057
|
image: u,
|
|
1050
1058
|
format: g,
|
|
1051
1059
|
contentType: l,
|
|
1052
1060
|
scale: s,
|
|
1053
|
-
withoutSave:
|
|
1061
|
+
withoutSave: a,
|
|
1054
1062
|
source: t,
|
|
1055
|
-
fromClipboard:
|
|
1063
|
+
fromClipboard: n
|
|
1056
1064
|
};
|
|
1057
|
-
return
|
|
1058
|
-
} catch (
|
|
1065
|
+
return o.fire("editor:image-imported", S), S;
|
|
1066
|
+
} catch (f) {
|
|
1059
1067
|
return h.emitError({
|
|
1060
1068
|
origin: "ImageManager",
|
|
1061
1069
|
method: "importImage",
|
|
1062
1070
|
code: "IMPORT_FAILED",
|
|
1063
|
-
message: `Ошибка импорта изображения: ${
|
|
1064
|
-
data: { source: t, format: g, contentType: l, scale: s, withoutSave:
|
|
1065
|
-
}),
|
|
1071
|
+
message: `Ошибка импорта изображения: ${f.message}`,
|
|
1072
|
+
data: { source: t, format: g, contentType: l, scale: s, withoutSave: a, fromClipboard: n }
|
|
1073
|
+
}), d.resumeHistory(), null;
|
|
1066
1074
|
}
|
|
1067
1075
|
});
|
|
1068
1076
|
}
|
|
@@ -1075,24 +1083,24 @@ class L {
|
|
|
1075
1083
|
* @returns возвращает Promise с Blob-объектом уменьшенного изображения
|
|
1076
1084
|
*/
|
|
1077
1085
|
resizeImageToBoundaries(e, t = "max") {
|
|
1078
|
-
return
|
|
1079
|
-
let s = `Размер изображения больше максимального размера канваса, поэтому оно будет уменьшено до максимальных размеров c сохранением пропорций: ${T}x${
|
|
1080
|
-
t === "min" && (s = `Размер изображения меньше минимального размера канваса, поэтому оно будет увеличено до минимальных размеров c сохранением пропорций: ${
|
|
1081
|
-
const
|
|
1086
|
+
return b(this, null, function* () {
|
|
1087
|
+
let s = `Размер изображения больше максимального размера канваса, поэтому оно будет уменьшено до максимальных размеров c сохранением пропорций: ${T}x${w}`;
|
|
1088
|
+
t === "min" && (s = `Размер изображения меньше минимального размера канваса, поэтому оно будет увеличено до минимальных размеров c сохранением пропорций: ${U}x${H}`);
|
|
1089
|
+
const a = {
|
|
1082
1090
|
dataURL: e,
|
|
1083
1091
|
sizeType: t,
|
|
1084
1092
|
maxWidth: T,
|
|
1085
|
-
maxHeight:
|
|
1086
|
-
minWidth:
|
|
1087
|
-
minHeight:
|
|
1093
|
+
maxHeight: w,
|
|
1094
|
+
minWidth: U,
|
|
1095
|
+
minHeight: H
|
|
1088
1096
|
};
|
|
1089
1097
|
return this.editor.errorManager.emitWarning({
|
|
1090
1098
|
origin: "ImageManager",
|
|
1091
1099
|
method: "resizeImageToBoundaries",
|
|
1092
1100
|
code: "IMAGE_RESIZE_WARNING",
|
|
1093
1101
|
message: s,
|
|
1094
|
-
data:
|
|
1095
|
-
}), this.editor.workerManager.post("resizeImage",
|
|
1102
|
+
data: a
|
|
1103
|
+
}), this.editor.workerManager.post("resizeImage", a);
|
|
1096
1104
|
});
|
|
1097
1105
|
}
|
|
1098
1106
|
/**
|
|
@@ -1107,101 +1115,101 @@ class L {
|
|
|
1107
1115
|
* @fires editor:canvas-exported
|
|
1108
1116
|
*/
|
|
1109
1117
|
exportCanvasAsImageFile() {
|
|
1110
|
-
return
|
|
1118
|
+
return b(this, arguments, function* (e = {}) {
|
|
1111
1119
|
const {
|
|
1112
1120
|
fileName: t = "image.png",
|
|
1113
1121
|
contentType: s = "image/png",
|
|
1114
|
-
exportAsBase64:
|
|
1115
|
-
exportAsBlob:
|
|
1116
|
-
} = e, { canvas:
|
|
1122
|
+
exportAsBase64: a = !1,
|
|
1123
|
+
exportAsBlob: n = !1
|
|
1124
|
+
} = e, { canvas: o, montageArea: i, workerManager: c } = this.editor;
|
|
1117
1125
|
try {
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
const { left: g, top: M, width:
|
|
1126
|
+
const d = s === "application/pdf", h = d ? "image/jpg" : s, l = O.getFormatFromContentType(h);
|
|
1127
|
+
i.setCoords();
|
|
1128
|
+
const { left: g, top: M, width: m, height: f } = i.getBoundingRect(), u = yield o.clone(["id", "format", "locked"]);
|
|
1121
1129
|
u.enableRetinaScaling = !1, ["image/jpg", "image/jpeg"].includes(h) && (u.backgroundColor = "#ffffff");
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
const
|
|
1125
|
-
if (l === "svg" &&
|
|
1130
|
+
const j = u.getObjects().find((I) => I.id === i.id);
|
|
1131
|
+
j && (j.visible = !1), u.viewportTransform = [1, 0, 0, 1, -g, -M], u.setDimensions({ width: m, height: f }, { backstoreOnly: !0 }), u.renderAll();
|
|
1132
|
+
const C = u.getObjects().filter((I) => I.format).every((I) => I.format === "svg");
|
|
1133
|
+
if (l === "svg" && C) {
|
|
1126
1134
|
const I = u.toSVG();
|
|
1127
1135
|
u.dispose();
|
|
1128
|
-
const
|
|
1129
|
-
image:
|
|
1130
|
-
exportAsBase64:
|
|
1131
|
-
exportAsBlob:
|
|
1136
|
+
const D = {
|
|
1137
|
+
image: O._exportSVGStringAsFile(I, {
|
|
1138
|
+
exportAsBase64: a,
|
|
1139
|
+
exportAsBlob: n,
|
|
1132
1140
|
fileName: t
|
|
1133
1141
|
}),
|
|
1134
1142
|
format: "svg",
|
|
1135
1143
|
contentType: "image/svg+xml",
|
|
1136
1144
|
fileName: t.replace(/\.[^/.]+$/, ".svg")
|
|
1137
1145
|
};
|
|
1138
|
-
return
|
|
1146
|
+
return o.fire("editor:canvas-exported", D), D;
|
|
1139
1147
|
}
|
|
1140
|
-
const S = yield new Promise((I,
|
|
1141
|
-
u.getElement().toBlob((
|
|
1142
|
-
|
|
1148
|
+
const S = yield new Promise((I, B) => {
|
|
1149
|
+
u.getElement().toBlob((D) => {
|
|
1150
|
+
D ? I(D) : B(new Error("Failed to create Blob from canvas"));
|
|
1143
1151
|
});
|
|
1144
1152
|
});
|
|
1145
|
-
if (u.dispose(),
|
|
1153
|
+
if (u.dispose(), n) {
|
|
1146
1154
|
const I = {
|
|
1147
1155
|
image: S,
|
|
1148
1156
|
format: l,
|
|
1149
1157
|
contentType: h,
|
|
1150
1158
|
fileName: t
|
|
1151
1159
|
};
|
|
1152
|
-
return
|
|
1160
|
+
return o.fire("editor:canvas-exported", I), I;
|
|
1153
1161
|
}
|
|
1154
|
-
const
|
|
1162
|
+
const A = yield createImageBitmap(S), E = yield c.post(
|
|
1155
1163
|
"toDataURL",
|
|
1156
|
-
{ format: l, quality: 1, bitmap:
|
|
1157
|
-
[
|
|
1164
|
+
{ format: l, quality: 1, bitmap: A },
|
|
1165
|
+
[A]
|
|
1158
1166
|
);
|
|
1159
|
-
if (
|
|
1160
|
-
const
|
|
1161
|
-
orientation:
|
|
1167
|
+
if (d) {
|
|
1168
|
+
const B = m * 0.264583, D = f * 0.264583, pe = (yield this.editor.moduleLoader.loadModule("jspdf")).jsPDF, $ = new pe({
|
|
1169
|
+
orientation: B > D ? "landscape" : "portrait",
|
|
1162
1170
|
unit: "mm",
|
|
1163
|
-
format: [
|
|
1171
|
+
format: [B, D]
|
|
1164
1172
|
});
|
|
1165
|
-
if ($.addImage(String(
|
|
1166
|
-
const
|
|
1173
|
+
if ($.addImage(String(E), "JPG", 0, 0, B, D), a) {
|
|
1174
|
+
const de = {
|
|
1167
1175
|
image: $.output("datauristring"),
|
|
1168
1176
|
format: "pdf",
|
|
1169
1177
|
contentType: "application/pdf",
|
|
1170
1178
|
fileName: t
|
|
1171
1179
|
};
|
|
1172
|
-
return
|
|
1180
|
+
return o.fire("editor:canvas-exported", de), de;
|
|
1173
1181
|
}
|
|
1174
|
-
const
|
|
1175
|
-
image: new File([
|
|
1182
|
+
const ye = $.output("blob"), ce = {
|
|
1183
|
+
image: new File([ye], t, { type: "application/pdf" }),
|
|
1176
1184
|
format: "pdf",
|
|
1177
1185
|
contentType: "application/pdf",
|
|
1178
1186
|
fileName: t
|
|
1179
1187
|
};
|
|
1180
|
-
return
|
|
1188
|
+
return o.fire("editor:canvas-exported", ce), ce;
|
|
1181
1189
|
}
|
|
1182
|
-
if (
|
|
1190
|
+
if (a) {
|
|
1183
1191
|
const I = {
|
|
1184
|
-
image:
|
|
1192
|
+
image: E,
|
|
1185
1193
|
format: l,
|
|
1186
1194
|
contentType: h,
|
|
1187
1195
|
fileName: t
|
|
1188
1196
|
};
|
|
1189
|
-
return
|
|
1197
|
+
return o.fire("editor:canvas-exported", I), I;
|
|
1190
1198
|
}
|
|
1191
|
-
const
|
|
1192
|
-
image: new File([S],
|
|
1199
|
+
const L = l === "svg" && !C ? t.replace(/\.[^/.]+$/, ".png") : t, re = {
|
|
1200
|
+
image: new File([S], L, { type: h }),
|
|
1193
1201
|
format: l,
|
|
1194
1202
|
contentType: h,
|
|
1195
|
-
fileName:
|
|
1203
|
+
fileName: L
|
|
1196
1204
|
};
|
|
1197
|
-
return
|
|
1198
|
-
} catch (
|
|
1205
|
+
return o.fire("editor:canvas-exported", re), re;
|
|
1206
|
+
} catch (d) {
|
|
1199
1207
|
return this.editor.errorManager.emitError({
|
|
1200
1208
|
origin: "ImageManager",
|
|
1201
1209
|
method: "exportCanvasAsImageFile",
|
|
1202
1210
|
code: "IMAGE_EXPORT_FAILED",
|
|
1203
|
-
message: `Ошибка экспорта изображения: ${
|
|
1204
|
-
data: { contentType: s, fileName: t, exportAsBase64:
|
|
1211
|
+
message: `Ошибка экспорта изображения: ${d.message}`,
|
|
1212
|
+
data: { contentType: s, fileName: t, exportAsBase64: a, exportAsBlob: n }
|
|
1205
1213
|
}), null;
|
|
1206
1214
|
}
|
|
1207
1215
|
});
|
|
@@ -1218,88 +1226,88 @@ class L {
|
|
|
1218
1226
|
* @fires editor:object-exported
|
|
1219
1227
|
*/
|
|
1220
1228
|
exportObjectAsImageFile() {
|
|
1221
|
-
return
|
|
1229
|
+
return b(this, arguments, function* (e = {}) {
|
|
1222
1230
|
const {
|
|
1223
1231
|
object: t,
|
|
1224
1232
|
fileName: s = "image.png",
|
|
1225
|
-
contentType:
|
|
1226
|
-
exportAsBase64:
|
|
1227
|
-
exportAsBlob:
|
|
1228
|
-
} = e, { canvas:
|
|
1229
|
-
if (!
|
|
1233
|
+
contentType: a = "image/png",
|
|
1234
|
+
exportAsBase64: n = !1,
|
|
1235
|
+
exportAsBlob: o = !1
|
|
1236
|
+
} = e, { canvas: i, workerManager: c } = this.editor, d = t || i.getActiveObject();
|
|
1237
|
+
if (!d)
|
|
1230
1238
|
return this.editor.errorManager.emitError({
|
|
1231
1239
|
origin: "ImageManager",
|
|
1232
1240
|
method: "exportObjectAsImageFile",
|
|
1233
1241
|
code: "NO_OBJECT_SELECTED",
|
|
1234
1242
|
message: "Не выбран объект для экспорта",
|
|
1235
|
-
data: { contentType:
|
|
1243
|
+
data: { contentType: a, fileName: s, exportAsBase64: n, exportAsBlob: o }
|
|
1236
1244
|
}), null;
|
|
1237
1245
|
try {
|
|
1238
|
-
const h =
|
|
1246
|
+
const h = O.getFormatFromContentType(a);
|
|
1239
1247
|
if (h === "svg") {
|
|
1240
|
-
const
|
|
1241
|
-
exportAsBase64:
|
|
1242
|
-
exportAsBlob:
|
|
1248
|
+
const f = d.toSVG(), u = O._exportSVGStringAsFile(f, {
|
|
1249
|
+
exportAsBase64: n,
|
|
1250
|
+
exportAsBlob: o,
|
|
1243
1251
|
fileName: s
|
|
1244
|
-
}),
|
|
1245
|
-
object:
|
|
1252
|
+
}), j = {
|
|
1253
|
+
object: d,
|
|
1246
1254
|
image: u,
|
|
1247
1255
|
format: h,
|
|
1248
1256
|
contentType: "image/svg+xml",
|
|
1249
1257
|
fileName: s.replace(/\.[^/.]+$/, ".svg")
|
|
1250
1258
|
};
|
|
1251
|
-
return
|
|
1259
|
+
return i.fire("editor:object-exported", j), j;
|
|
1252
1260
|
}
|
|
1253
|
-
if (
|
|
1254
|
-
const
|
|
1261
|
+
if (n && d instanceof x) {
|
|
1262
|
+
const f = yield createImageBitmap(d.getElement()), u = yield c.post(
|
|
1255
1263
|
"toDataURL",
|
|
1256
1264
|
{
|
|
1257
1265
|
format: h,
|
|
1258
1266
|
quality: 1,
|
|
1259
|
-
bitmap:
|
|
1267
|
+
bitmap: f
|
|
1260
1268
|
},
|
|
1261
|
-
[
|
|
1262
|
-
),
|
|
1263
|
-
object:
|
|
1269
|
+
[f]
|
|
1270
|
+
), j = {
|
|
1271
|
+
object: d,
|
|
1264
1272
|
image: u,
|
|
1265
1273
|
format: h,
|
|
1266
|
-
contentType:
|
|
1274
|
+
contentType: a,
|
|
1267
1275
|
fileName: s
|
|
1268
1276
|
};
|
|
1269
|
-
return
|
|
1277
|
+
return i.fire("editor:object-exported", j), j;
|
|
1270
1278
|
}
|
|
1271
|
-
const l =
|
|
1279
|
+
const l = d.toCanvasElement({
|
|
1272
1280
|
enableRetinaScaling: !1
|
|
1273
|
-
}), g = yield new Promise((
|
|
1274
|
-
l.toBlob((
|
|
1275
|
-
|
|
1281
|
+
}), g = yield new Promise((f, u) => {
|
|
1282
|
+
l.toBlob((j) => {
|
|
1283
|
+
j ? f(j) : u(new Error("Failed to create Blob from canvas"));
|
|
1276
1284
|
});
|
|
1277
1285
|
});
|
|
1278
|
-
if (
|
|
1279
|
-
const
|
|
1280
|
-
object:
|
|
1286
|
+
if (o) {
|
|
1287
|
+
const f = {
|
|
1288
|
+
object: d,
|
|
1281
1289
|
image: g,
|
|
1282
1290
|
format: h,
|
|
1283
|
-
contentType:
|
|
1291
|
+
contentType: a,
|
|
1284
1292
|
fileName: s
|
|
1285
1293
|
};
|
|
1286
|
-
return
|
|
1294
|
+
return i.fire("editor:object-exported", f), f;
|
|
1287
1295
|
}
|
|
1288
|
-
const M = new File([g], s, { type:
|
|
1289
|
-
object:
|
|
1296
|
+
const M = new File([g], s, { type: a }), m = {
|
|
1297
|
+
object: d,
|
|
1290
1298
|
image: M,
|
|
1291
1299
|
format: h,
|
|
1292
|
-
contentType:
|
|
1300
|
+
contentType: a,
|
|
1293
1301
|
fileName: s
|
|
1294
1302
|
};
|
|
1295
|
-
return
|
|
1303
|
+
return i.fire("editor:object-exported", m), m;
|
|
1296
1304
|
} catch (h) {
|
|
1297
1305
|
return this.editor.errorManager.emitError({
|
|
1298
1306
|
origin: "ImageManager",
|
|
1299
1307
|
method: "exportObjectAsImageFile",
|
|
1300
1308
|
code: "IMAGE_EXPORT_FAILED",
|
|
1301
1309
|
message: `Ошибка экспорта объекта: ${h.message}`,
|
|
1302
|
-
data: { contentType:
|
|
1310
|
+
data: { contentType: a, fileName: s, exportAsBase64: n, exportAsBlob: o }
|
|
1303
1311
|
}), null;
|
|
1304
1312
|
}
|
|
1305
1313
|
});
|
|
@@ -1315,7 +1323,7 @@ class L {
|
|
|
1315
1323
|
* @returns массив допустимых форматов изображений
|
|
1316
1324
|
*/
|
|
1317
1325
|
getAllowedFormatsFromContentTypes() {
|
|
1318
|
-
return this.acceptContentTypes.map((e) =>
|
|
1326
|
+
return this.acceptContentTypes.map((e) => O.getFormatFromContentType(e)).filter((e) => e);
|
|
1319
1327
|
}
|
|
1320
1328
|
/**
|
|
1321
1329
|
* Проверяет, является ли contentType допустимым типом изображения.
|
|
@@ -1331,7 +1339,7 @@ class L {
|
|
|
1331
1339
|
* @public
|
|
1332
1340
|
*/
|
|
1333
1341
|
getContentType(e) {
|
|
1334
|
-
return
|
|
1342
|
+
return b(this, null, function* () {
|
|
1335
1343
|
return typeof e == "string" ? this.getContentTypeFromUrl(e) : e.type || "application/octet-stream";
|
|
1336
1344
|
});
|
|
1337
1345
|
}
|
|
@@ -1342,7 +1350,7 @@ class L {
|
|
|
1342
1350
|
* @public
|
|
1343
1351
|
*/
|
|
1344
1352
|
getContentTypeFromUrl(e) {
|
|
1345
|
-
return
|
|
1353
|
+
return b(this, null, function* () {
|
|
1346
1354
|
if (e.startsWith("data:")) {
|
|
1347
1355
|
const t = e.match(/^data:([^;]+)/);
|
|
1348
1356
|
return t ? t[1] : "application/octet-stream";
|
|
@@ -1366,11 +1374,11 @@ class L {
|
|
|
1366
1374
|
getContentTypeFromExtension(e) {
|
|
1367
1375
|
var t;
|
|
1368
1376
|
try {
|
|
1369
|
-
const
|
|
1370
|
-
return this.acceptContentTypes.forEach((
|
|
1371
|
-
const
|
|
1372
|
-
|
|
1373
|
-
}),
|
|
1377
|
+
const a = (t = new URL(e).pathname.split(".").pop()) == null ? void 0 : t.toLowerCase(), n = {};
|
|
1378
|
+
return this.acceptContentTypes.forEach((o) => {
|
|
1379
|
+
const i = O.getFormatFromContentType(o);
|
|
1380
|
+
i && (n[i] = o);
|
|
1381
|
+
}), a && n[a] || "application/octet-stream";
|
|
1374
1382
|
} catch (s) {
|
|
1375
1383
|
return console.warn("Не удалось определить расширение из URL:", e, s), "application/octet-stream";
|
|
1376
1384
|
}
|
|
@@ -1388,8 +1396,8 @@ class L {
|
|
|
1388
1396
|
}) {
|
|
1389
1397
|
const { montageArea: s } = this.editor;
|
|
1390
1398
|
if (!s || !e) return 1;
|
|
1391
|
-
const
|
|
1392
|
-
return t === "contain" || t === "image-contain" ? Math.min(
|
|
1399
|
+
const a = s.width, n = s.height, { width: o, height: i } = e;
|
|
1400
|
+
return t === "contain" || t === "image-contain" ? Math.min(a / o, n / i) : t === "cover" || t === "image-cover" ? Math.max(a / o, n / i) : 1;
|
|
1393
1401
|
}
|
|
1394
1402
|
/**
|
|
1395
1403
|
* Преобразует SVG-строку в Blob, файл, или base64
|
|
@@ -1405,9 +1413,9 @@ class L {
|
|
|
1405
1413
|
static _exportSVGStringAsFile(e, {
|
|
1406
1414
|
exportAsBase64: t,
|
|
1407
1415
|
exportAsBlob: s,
|
|
1408
|
-
fileName:
|
|
1416
|
+
fileName: a = "image.svg"
|
|
1409
1417
|
} = {}) {
|
|
1410
|
-
return s ? new Blob([e], { type: "image/svg+xml" }) : t ? `data:image/svg+xml;base64,${window.btoa(encodeURIComponent(e))}` : new File([e],
|
|
1418
|
+
return s ? new Blob([e], { type: "image/svg+xml" }) : t ? `data:image/svg+xml;base64,${window.btoa(encodeURIComponent(e))}` : new File([e], a.replace(/\.[^/.]+$/, ".svg"), { type: "image/svg+xml" });
|
|
1411
1419
|
}
|
|
1412
1420
|
/**
|
|
1413
1421
|
* Извлекает чистый формат (subtype) из contentType,
|
|
@@ -1421,11 +1429,11 @@ class L {
|
|
|
1421
1429
|
return t ? t[1] : "";
|
|
1422
1430
|
}
|
|
1423
1431
|
}
|
|
1424
|
-
const
|
|
1425
|
-
function
|
|
1432
|
+
const _ = (r, e, t) => Math.max(Math.min(r, t), e), be = (r, e) => r * e, rt = (r, e) => new V(r / 2, e / 2);
|
|
1433
|
+
function ct(r) {
|
|
1426
1434
|
return ((r == null ? void 0 : r.type) === "image" || (r == null ? void 0 : r.format) === "svg") && typeof (r == null ? void 0 : r.width) == "number" && typeof (r == null ? void 0 : r.height) == "number";
|
|
1427
1435
|
}
|
|
1428
|
-
class
|
|
1436
|
+
class dt {
|
|
1429
1437
|
/**
|
|
1430
1438
|
* @param options
|
|
1431
1439
|
* @param options.editor – экземпляр редактора
|
|
@@ -1449,25 +1457,25 @@ class rt {
|
|
|
1449
1457
|
* @param options.adaptCanvasToContainer - Адаптировать канвас к контейнеру
|
|
1450
1458
|
* @fires editor:resolution-width-changed
|
|
1451
1459
|
*/
|
|
1452
|
-
setResolutionWidth(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer:
|
|
1453
|
-
var
|
|
1460
|
+
setResolutionWidth(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer: a } = {}) {
|
|
1461
|
+
var m;
|
|
1454
1462
|
if (!e) return;
|
|
1455
1463
|
const {
|
|
1456
|
-
canvas:
|
|
1457
|
-
montageArea:
|
|
1458
|
-
options: { canvasBackstoreWidth:
|
|
1459
|
-
} = this.editor, { width:
|
|
1460
|
-
if (!
|
|
1461
|
-
const
|
|
1464
|
+
canvas: n,
|
|
1465
|
+
montageArea: o,
|
|
1466
|
+
options: { canvasBackstoreWidth: i }
|
|
1467
|
+
} = this.editor, { width: c, height: d } = o, h = _(Number(e), U, T);
|
|
1468
|
+
if (!i || i === "auto" || a ? this.adaptCanvasToContainer() : i ? this.setCanvasBackstoreWidth(Number(i)) : this.setCanvasBackstoreWidth(h), o.set({ width: h }), (m = n.clipPath) == null || m.set({ width: h }), t) {
|
|
1469
|
+
const f = h / c, u = be(d, f);
|
|
1462
1470
|
this.setResolutionHeight(u);
|
|
1463
1471
|
return;
|
|
1464
1472
|
}
|
|
1465
|
-
const { left: l, top: g } = this.getObjectDefaultCoords(
|
|
1466
|
-
|
|
1473
|
+
const { left: l, top: g } = this.getObjectDefaultCoords(o), M = n.getZoom();
|
|
1474
|
+
n.setViewportTransform([M, 0, 0, M, l, g]), this.centerMontageArea(), s || this.editor.historyManager.saveState(), n.fire("editor:resolution-width-changed", {
|
|
1467
1475
|
width: h,
|
|
1468
1476
|
preserveProportional: t,
|
|
1469
1477
|
withoutSave: s,
|
|
1470
|
-
adaptCanvasToContainer:
|
|
1478
|
+
adaptCanvasToContainer: a
|
|
1471
1479
|
});
|
|
1472
1480
|
}
|
|
1473
1481
|
/**
|
|
@@ -1479,25 +1487,25 @@ class rt {
|
|
|
1479
1487
|
* @param options.adaptCanvasToContainer - Адаптировать канвас к контейнеру
|
|
1480
1488
|
* @fires editor:resolution-height-changed
|
|
1481
1489
|
*/
|
|
1482
|
-
setResolutionHeight(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer:
|
|
1483
|
-
var
|
|
1490
|
+
setResolutionHeight(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer: a } = {}) {
|
|
1491
|
+
var m;
|
|
1484
1492
|
if (!e) return;
|
|
1485
1493
|
const {
|
|
1486
|
-
canvas:
|
|
1487
|
-
montageArea:
|
|
1488
|
-
options: { canvasBackstoreHeight:
|
|
1489
|
-
} = this.editor, { width:
|
|
1490
|
-
if (!
|
|
1491
|
-
const
|
|
1494
|
+
canvas: n,
|
|
1495
|
+
montageArea: o,
|
|
1496
|
+
options: { canvasBackstoreHeight: i }
|
|
1497
|
+
} = this.editor, { width: c, height: d } = o, h = _(Number(e), H, w);
|
|
1498
|
+
if (!i || i === "auto" || a ? this.adaptCanvasToContainer() : i ? this.setCanvasBackstoreHeight(Number(i)) : this.setCanvasBackstoreHeight(h), o.set({ height: h }), (m = n.clipPath) == null || m.set({ height: h }), t) {
|
|
1499
|
+
const f = h / d, u = be(c, f);
|
|
1492
1500
|
this.setResolutionWidth(u);
|
|
1493
1501
|
return;
|
|
1494
1502
|
}
|
|
1495
|
-
const { left: l, top: g } = this.getObjectDefaultCoords(
|
|
1496
|
-
|
|
1503
|
+
const { left: l, top: g } = this.getObjectDefaultCoords(o), M = n.getZoom();
|
|
1504
|
+
n.setViewportTransform([M, 0, 0, M, l, g]), this.centerMontageArea(), s || this.editor.historyManager.saveState(), n.fire("editor:resolution-height-changed", {
|
|
1497
1505
|
height: h,
|
|
1498
1506
|
preserveProportional: t,
|
|
1499
1507
|
withoutSave: s,
|
|
1500
|
-
adaptCanvasToContainer:
|
|
1508
|
+
adaptCanvasToContainer: a
|
|
1501
1509
|
});
|
|
1502
1510
|
}
|
|
1503
1511
|
/**
|
|
@@ -1505,17 +1513,17 @@ class rt {
|
|
|
1505
1513
|
* и устанавливает правильный viewportTransform.
|
|
1506
1514
|
*/
|
|
1507
1515
|
centerMontageArea() {
|
|
1508
|
-
var
|
|
1509
|
-
const { canvas: e, montageArea: t } = this.editor, s = e.getWidth(),
|
|
1516
|
+
var c;
|
|
1517
|
+
const { canvas: e, montageArea: t } = this.editor, s = e.getWidth(), a = e.getHeight(), n = e.getZoom(), o = rt(s, a);
|
|
1510
1518
|
t.set({
|
|
1511
1519
|
left: s / 2,
|
|
1512
|
-
top:
|
|
1513
|
-
}), (
|
|
1520
|
+
top: a / 2
|
|
1521
|
+
}), (c = e.clipPath) == null || c.set({
|
|
1514
1522
|
left: s / 2,
|
|
1515
|
-
top:
|
|
1523
|
+
top: a / 2
|
|
1516
1524
|
}), e.renderAll();
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1525
|
+
const i = e.viewportTransform;
|
|
1526
|
+
i[4] = s / 2 - o.x * n, i[5] = a / 2 - o.y * n, e.setViewportTransform(i), e.renderAll();
|
|
1519
1527
|
}
|
|
1520
1528
|
/**
|
|
1521
1529
|
* Метод для получения координат объекта с учетом текущего зума
|
|
@@ -1531,15 +1539,15 @@ class rt {
|
|
|
1531
1539
|
code: "NO_ACTIVE_OBJECT",
|
|
1532
1540
|
message: "Не выбран объект для получения координат"
|
|
1533
1541
|
}), { left: 0, top: 0 };
|
|
1534
|
-
const { width:
|
|
1535
|
-
return { left:
|
|
1542
|
+
const { width: a, height: n } = s, o = t.getZoom(), i = (a - a * o) / 2, c = (n - n * o) / 2;
|
|
1543
|
+
return { left: i, top: c };
|
|
1536
1544
|
}
|
|
1537
1545
|
/**
|
|
1538
1546
|
* Устанавливаем ширину канваса в backstore (для экспорта)
|
|
1539
1547
|
*/
|
|
1540
1548
|
setCanvasBackstoreWidth(e) {
|
|
1541
1549
|
if (!e || typeof e != "number") return;
|
|
1542
|
-
const t =
|
|
1550
|
+
const t = _(e, U, T);
|
|
1543
1551
|
this.editor.canvas.setDimensions({ width: t }, { backstoreOnly: !0 });
|
|
1544
1552
|
}
|
|
1545
1553
|
/**
|
|
@@ -1548,7 +1556,7 @@ class rt {
|
|
|
1548
1556
|
*/
|
|
1549
1557
|
setCanvasBackstoreHeight(e) {
|
|
1550
1558
|
if (!e || typeof e != "number") return;
|
|
1551
|
-
const t =
|
|
1559
|
+
const t = _(e, H, w);
|
|
1552
1560
|
this.editor.canvas.setDimensions({ height: t }, { backstoreOnly: !0 });
|
|
1553
1561
|
}
|
|
1554
1562
|
/**
|
|
@@ -1557,8 +1565,8 @@ class rt {
|
|
|
1557
1565
|
* с учётом минимальных и максимальных значений.
|
|
1558
1566
|
*/
|
|
1559
1567
|
adaptCanvasToContainer() {
|
|
1560
|
-
const { canvas: e } = this.editor, t = this.getEditorContainer(), s = t.clientWidth,
|
|
1561
|
-
e.setDimensions({ width:
|
|
1568
|
+
const { canvas: e } = this.editor, t = this.getEditorContainer(), s = t.clientWidth, a = t.clientHeight, n = _(s, U, T), o = _(a, H, w);
|
|
1569
|
+
e.setDimensions({ width: n, height: o }, { backstoreOnly: !0 });
|
|
1562
1570
|
}
|
|
1563
1571
|
/**
|
|
1564
1572
|
* Обновляет размеры канваса без изменения позиций объектов.
|
|
@@ -1571,21 +1579,21 @@ class rt {
|
|
|
1571
1579
|
montageArea: t,
|
|
1572
1580
|
montageArea: {
|
|
1573
1581
|
width: s,
|
|
1574
|
-
height:
|
|
1582
|
+
height: a
|
|
1575
1583
|
}
|
|
1576
|
-
} = this.editor,
|
|
1577
|
-
this.setResolutionWidth(s, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.setResolutionHeight(
|
|
1578
|
-
const
|
|
1579
|
-
if (
|
|
1580
|
-
const
|
|
1581
|
-
if ((
|
|
1582
|
-
const l =
|
|
1584
|
+
} = this.editor, n = t.left, o = t.top;
|
|
1585
|
+
this.setResolutionWidth(s, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.setResolutionHeight(a, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.centerMontageArea();
|
|
1586
|
+
const i = t.left - n, c = t.top - o;
|
|
1587
|
+
if (i !== 0 || c !== 0) {
|
|
1588
|
+
const d = e.getActiveObject(), h = [];
|
|
1589
|
+
if ((d == null ? void 0 : d.type) === "activeselection") {
|
|
1590
|
+
const l = d;
|
|
1583
1591
|
h.push(...l.getObjects()), e.discardActiveObject();
|
|
1584
1592
|
}
|
|
1585
1593
|
if (e.getObjects().forEach((l) => {
|
|
1586
|
-
l.id === "montage-area" || l.id === "overlay-mask" || (l.set({
|
|
1587
|
-
left: l.left +
|
|
1588
|
-
top: l.top +
|
|
1594
|
+
l.id === "montage-area" || l.id === "overlay-mask" || l.id === "background" || (l.set({
|
|
1595
|
+
left: l.left + i,
|
|
1596
|
+
top: l.top + c
|
|
1589
1597
|
}), l.setCoords());
|
|
1590
1598
|
}), h.length > 0)
|
|
1591
1599
|
if (h.length === 1)
|
|
@@ -1599,7 +1607,7 @@ class rt {
|
|
|
1599
1607
|
}
|
|
1600
1608
|
e.renderAll(), e.fire("editor:canvas-updated", {
|
|
1601
1609
|
width: s,
|
|
1602
|
-
height:
|
|
1610
|
+
height: a
|
|
1603
1611
|
});
|
|
1604
1612
|
}
|
|
1605
1613
|
/**
|
|
@@ -1709,32 +1717,32 @@ class rt {
|
|
|
1709
1717
|
*/
|
|
1710
1718
|
setDisplayDimension({ element: e = "canvas", dimension: t, value: s } = {}) {
|
|
1711
1719
|
if (!s) return;
|
|
1712
|
-
const { canvas:
|
|
1720
|
+
const { canvas: a } = this.editor, n = [];
|
|
1713
1721
|
switch (e) {
|
|
1714
1722
|
case "canvas":
|
|
1715
|
-
|
|
1723
|
+
n.push(a.lowerCanvasEl, a.upperCanvasEl);
|
|
1716
1724
|
break;
|
|
1717
1725
|
case "wrapper":
|
|
1718
|
-
|
|
1726
|
+
n.push(a.wrapperEl);
|
|
1719
1727
|
break;
|
|
1720
1728
|
case "container":
|
|
1721
|
-
|
|
1729
|
+
n.push(this.getEditorContainer());
|
|
1722
1730
|
break;
|
|
1723
1731
|
default:
|
|
1724
|
-
|
|
1732
|
+
n.push(a.lowerCanvasEl, a.upperCanvasEl);
|
|
1725
1733
|
}
|
|
1726
|
-
const
|
|
1734
|
+
const o = t === "width" ? "width" : "height";
|
|
1727
1735
|
if (typeof s == "string") {
|
|
1728
|
-
|
|
1729
|
-
|
|
1736
|
+
n.forEach((c) => {
|
|
1737
|
+
c.style[o] = s;
|
|
1730
1738
|
});
|
|
1731
1739
|
return;
|
|
1732
1740
|
}
|
|
1733
1741
|
if (isNaN(s)) return;
|
|
1734
|
-
const
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
}),
|
|
1742
|
+
const i = `${s}px`;
|
|
1743
|
+
n.forEach((c) => {
|
|
1744
|
+
c.style[o] = i;
|
|
1745
|
+
}), a.fire(`editor:display-${e}-${o}-changed`, {
|
|
1738
1746
|
element: e,
|
|
1739
1747
|
value: s
|
|
1740
1748
|
});
|
|
@@ -1749,26 +1757,26 @@ class rt {
|
|
|
1749
1757
|
*/
|
|
1750
1758
|
scaleMontageAreaToImage({ object: e, preserveAspectRatio: t, withoutSave: s } = {}) {
|
|
1751
1759
|
const {
|
|
1752
|
-
canvas:
|
|
1753
|
-
montageArea:
|
|
1754
|
-
transformManager:
|
|
1760
|
+
canvas: a,
|
|
1761
|
+
montageArea: n,
|
|
1762
|
+
transformManager: o,
|
|
1755
1763
|
options: {
|
|
1756
|
-
montageAreaWidth:
|
|
1757
|
-
montageAreaHeight:
|
|
1764
|
+
montageAreaWidth: i,
|
|
1765
|
+
montageAreaHeight: c
|
|
1758
1766
|
}
|
|
1759
|
-
} = this.editor,
|
|
1760
|
-
if (!
|
|
1761
|
-
const { width: h, height: l } =
|
|
1762
|
-
let g = Math.min(h, T), M = Math.min(l,
|
|
1767
|
+
} = this.editor, d = e || a.getActiveObject();
|
|
1768
|
+
if (!ct(d)) return;
|
|
1769
|
+
const { width: h, height: l } = d;
|
|
1770
|
+
let g = Math.min(h, T), M = Math.min(l, w);
|
|
1763
1771
|
if (t) {
|
|
1764
1772
|
const {
|
|
1765
|
-
width:
|
|
1766
|
-
height:
|
|
1767
|
-
} =
|
|
1768
|
-
g =
|
|
1773
|
+
width: m,
|
|
1774
|
+
height: f
|
|
1775
|
+
} = n, u = h / m, j = l / f, C = Math.max(u, j);
|
|
1776
|
+
g = m * C, M = f * C;
|
|
1769
1777
|
}
|
|
1770
|
-
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(M, { withoutSave: !0 }), (h >
|
|
1771
|
-
object:
|
|
1778
|
+
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(M, { withoutSave: !0 }), this.editor.backgroundManager.backgroundObject && this.editor.backgroundManager.refresh(), (h > i || l > c) && o.calculateAndApplyDefaultZoom(), o.resetObject({ object: d, withoutSave: !0 }), a.centerObject(d), a.renderAll(), s || this.editor.historyManager.saveState(), a.fire("editor:montage-area-scaled-to-image", {
|
|
1779
|
+
object: d,
|
|
1772
1780
|
width: g,
|
|
1773
1781
|
height: M,
|
|
1774
1782
|
preserveAspectRatio: t,
|
|
@@ -1793,26 +1801,33 @@ class rt {
|
|
|
1793
1801
|
const {
|
|
1794
1802
|
canvas: t,
|
|
1795
1803
|
transformManager: s,
|
|
1796
|
-
historyManager:
|
|
1804
|
+
historyManager: a,
|
|
1797
1805
|
options: {
|
|
1798
|
-
montageAreaWidth:
|
|
1799
|
-
montageAreaHeight:
|
|
1806
|
+
montageAreaWidth: n,
|
|
1807
|
+
montageAreaHeight: o
|
|
1800
1808
|
}
|
|
1801
1809
|
} = this.editor;
|
|
1802
|
-
s.resetZoom(), this.setResolutionWidth(
|
|
1810
|
+
s.resetZoom(), this.setResolutionWidth(n, { withoutSave: !0 }), this.setResolutionHeight(o, { withoutSave: !0 }), t.renderAll(), s.resetObjects(), e || a.saveState(), t.fire("editor:default-scale-set");
|
|
1803
1811
|
}
|
|
1804
1812
|
/**
|
|
1805
1813
|
* Получение всех объектов внутри монтажной области редактора
|
|
1806
1814
|
* @returns массив объектов
|
|
1807
1815
|
*/
|
|
1808
1816
|
getObjects() {
|
|
1809
|
-
const {
|
|
1810
|
-
|
|
1817
|
+
const {
|
|
1818
|
+
canvas: e,
|
|
1819
|
+
montageArea: t,
|
|
1820
|
+
interactionBlocker: { overlayMask: s },
|
|
1821
|
+
backgroundManager: { backgroundObject: a }
|
|
1822
|
+
} = this.editor;
|
|
1823
|
+
return e.getObjects().filter(
|
|
1824
|
+
(o) => o.id !== t.id && o.id !== (s == null ? void 0 : s.id) && o.id !== (a == null ? void 0 : a.id)
|
|
1825
|
+
);
|
|
1811
1826
|
}
|
|
1812
1827
|
}
|
|
1813
|
-
class
|
|
1828
|
+
class lt {
|
|
1814
1829
|
constructor({ editor: e }) {
|
|
1815
|
-
this.editor = e, this.options = e.options, this.minZoom = this.options.minZoom ||
|
|
1830
|
+
this.editor = e, this.options = e.options, this.minZoom = this.options.minZoom || at, this.maxZoom = this.options.maxZoom || nt, this.defaultZoom = this.options.defaultScale;
|
|
1816
1831
|
}
|
|
1817
1832
|
/**
|
|
1818
1833
|
* Метод рассчитывает и применяет зум по умолчанию для монтажной области редактора.
|
|
@@ -1822,8 +1837,8 @@ class ct {
|
|
|
1822
1837
|
* @param scale - Желаемый масштаб относительно размеров контейнера редактора.
|
|
1823
1838
|
*/
|
|
1824
1839
|
calculateAndApplyDefaultZoom(e = this.options.defaultScale) {
|
|
1825
|
-
const { canvas: t } = this.editor, s = t.editorContainer,
|
|
1826
|
-
this.defaultZoom = Math.min(
|
|
1840
|
+
const { canvas: t } = this.editor, s = t.editorContainer, a = s.clientWidth, n = s.clientHeight, { width: o, height: i } = this.editor.montageArea, c = a / o * e, d = n / i * e;
|
|
1841
|
+
this.defaultZoom = Math.min(c, d), this.setZoom();
|
|
1827
1842
|
}
|
|
1828
1843
|
/**
|
|
1829
1844
|
* Увеличение/уменьшение масштаба
|
|
@@ -1834,13 +1849,13 @@ class ct {
|
|
|
1834
1849
|
* @fires editor:zoom-changed
|
|
1835
1850
|
* Если передавать координаты курсора, то нужно быть аккуратнее, так как юзер может выйти за пределы рабочей области
|
|
1836
1851
|
*/
|
|
1837
|
-
zoom(e =
|
|
1852
|
+
zoom(e = ot, t = {}) {
|
|
1838
1853
|
var g, M;
|
|
1839
1854
|
if (!e) return;
|
|
1840
|
-
const { minZoom: s, maxZoom:
|
|
1841
|
-
let l = Number((
|
|
1842
|
-
l >
|
|
1843
|
-
currentZoom:
|
|
1855
|
+
const { minZoom: s, maxZoom: a } = this, { canvas: n } = this.editor, o = n.getZoom(), i = n.getCenterPoint(), c = (g = t.pointX) != null ? g : i.x, d = (M = t.pointY) != null ? M : i.y, h = new V(c, d);
|
|
1856
|
+
let l = Number((o + Number(e)).toFixed(2));
|
|
1857
|
+
l > a && (l = a), l < s && (l = s), n.zoomToPoint(h, l), n.fire("editor:zoom-changed", {
|
|
1858
|
+
currentZoom: n.getZoom(),
|
|
1844
1859
|
zoom: l,
|
|
1845
1860
|
point: h
|
|
1846
1861
|
});
|
|
@@ -1851,12 +1866,12 @@ class ct {
|
|
|
1851
1866
|
* @fires editor:zoom-changed
|
|
1852
1867
|
*/
|
|
1853
1868
|
setZoom(e = this.defaultZoom) {
|
|
1854
|
-
const { minZoom: t, maxZoom: s } = this, { canvas:
|
|
1855
|
-
let
|
|
1856
|
-
e > s && (
|
|
1857
|
-
currentZoom:
|
|
1858
|
-
zoom:
|
|
1859
|
-
point:
|
|
1869
|
+
const { minZoom: t, maxZoom: s } = this, { canvas: a } = this.editor, n = new V(a.getCenterPoint());
|
|
1870
|
+
let o = e;
|
|
1871
|
+
e > s && (o = s), e < t && (o = t), a.zoomToPoint(n, o), a.fire("editor:zoom-changed", {
|
|
1872
|
+
currentZoom: a.getZoom(),
|
|
1873
|
+
zoom: o,
|
|
1874
|
+
point: n
|
|
1860
1875
|
});
|
|
1861
1876
|
}
|
|
1862
1877
|
/**
|
|
@@ -1864,7 +1879,7 @@ class ct {
|
|
|
1864
1879
|
* @fires editor:zoom-changed
|
|
1865
1880
|
*/
|
|
1866
1881
|
resetZoom() {
|
|
1867
|
-
const { canvas: e } = this.editor, t = new
|
|
1882
|
+
const { canvas: e } = this.editor, t = new V(e.getCenterPoint());
|
|
1868
1883
|
e.zoomToPoint(t, this.defaultZoom), this.editor.canvas.fire("editor:zoom-changed", {
|
|
1869
1884
|
currentZoom: e.getZoom(),
|
|
1870
1885
|
point: t
|
|
@@ -1878,13 +1893,13 @@ class ct {
|
|
|
1878
1893
|
* @fires editor:object-rotated
|
|
1879
1894
|
*/
|
|
1880
1895
|
rotate(e = it, { withoutSave: t } = {}) {
|
|
1881
|
-
const { canvas: s, historyManager:
|
|
1882
|
-
if (!
|
|
1883
|
-
const
|
|
1884
|
-
|
|
1885
|
-
object:
|
|
1896
|
+
const { canvas: s, historyManager: a } = this.editor, n = s.getActiveObject();
|
|
1897
|
+
if (!n) return;
|
|
1898
|
+
const o = n.angle + e;
|
|
1899
|
+
n.rotate(o), n.setCoords(), s.renderAll(), t || a.saveState(), s.fire("editor:object-rotated", {
|
|
1900
|
+
object: n,
|
|
1886
1901
|
withoutSave: t,
|
|
1887
|
-
angle:
|
|
1902
|
+
angle: o
|
|
1888
1903
|
});
|
|
1889
1904
|
}
|
|
1890
1905
|
/**
|
|
@@ -1894,9 +1909,9 @@ class ct {
|
|
|
1894
1909
|
* @fires editor:object-flipped-x
|
|
1895
1910
|
*/
|
|
1896
1911
|
flipX({ withoutSave: e } = {}) {
|
|
1897
|
-
const { canvas: t, historyManager: s } = this.editor,
|
|
1898
|
-
|
|
1899
|
-
object:
|
|
1912
|
+
const { canvas: t, historyManager: s } = this.editor, a = t.getActiveObject();
|
|
1913
|
+
a && (a.flipX = !a.flipX, t.renderAll(), e || s.saveState(), t.fire("editor:object-flipped-x", {
|
|
1914
|
+
object: a,
|
|
1900
1915
|
withoutSave: e
|
|
1901
1916
|
}));
|
|
1902
1917
|
}
|
|
@@ -1907,9 +1922,9 @@ class ct {
|
|
|
1907
1922
|
* @fires editor:object-flipped-y
|
|
1908
1923
|
*/
|
|
1909
1924
|
flipY({ withoutSave: e } = {}) {
|
|
1910
|
-
const { canvas: t, historyManager: s } = this.editor,
|
|
1911
|
-
|
|
1912
|
-
object:
|
|
1925
|
+
const { canvas: t, historyManager: s } = this.editor, a = t.getActiveObject();
|
|
1926
|
+
a && (a.flipY = !a.flipY, t.renderAll(), e || s.saveState(), t.fire("editor:object-flipped-y", {
|
|
1927
|
+
object: a,
|
|
1913
1928
|
withoutSave: e
|
|
1914
1929
|
}));
|
|
1915
1930
|
}
|
|
@@ -1926,11 +1941,11 @@ class ct {
|
|
|
1926
1941
|
opacity: t = 1,
|
|
1927
1942
|
withoutSave: s
|
|
1928
1943
|
} = {}) {
|
|
1929
|
-
const { canvas:
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
}) :
|
|
1933
|
-
object:
|
|
1944
|
+
const { canvas: a, historyManager: n } = this.editor, o = e || a.getActiveObject();
|
|
1945
|
+
o && (o instanceof y ? o.getObjects().forEach((i) => {
|
|
1946
|
+
i.set("opacity", t);
|
|
1947
|
+
}) : o.set("opacity", t), a.renderAll(), s || n.saveState(), a.fire("editor:object-opacity-changed", {
|
|
1948
|
+
object: o,
|
|
1934
1949
|
opacity: t,
|
|
1935
1950
|
withoutSave: s
|
|
1936
1951
|
}));
|
|
@@ -1950,24 +1965,24 @@ class ct {
|
|
|
1950
1965
|
object: e,
|
|
1951
1966
|
type: t = this.options.scaleType,
|
|
1952
1967
|
withoutSave: s,
|
|
1953
|
-
fitAsOneObject:
|
|
1968
|
+
fitAsOneObject: a
|
|
1954
1969
|
} = {}) {
|
|
1955
|
-
const { canvas:
|
|
1956
|
-
if (
|
|
1957
|
-
if (
|
|
1958
|
-
const
|
|
1959
|
-
|
|
1970
|
+
const { canvas: n, historyManager: o } = this.editor, i = e || n.getActiveObject();
|
|
1971
|
+
if (i) {
|
|
1972
|
+
if (i instanceof y && !a) {
|
|
1973
|
+
const c = i.getObjects();
|
|
1974
|
+
n.discardActiveObject(), c.forEach((h) => {
|
|
1960
1975
|
this._fitSingleObject(h, t);
|
|
1961
1976
|
});
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1977
|
+
const d = new y(c, { canvas: n });
|
|
1978
|
+
n.setActiveObject(d);
|
|
1964
1979
|
} else
|
|
1965
|
-
this._fitSingleObject(
|
|
1966
|
-
|
|
1967
|
-
object:
|
|
1980
|
+
this._fitSingleObject(i, t);
|
|
1981
|
+
n.renderAll(), s || o.saveState(), n.fire("editor:object-fitted", {
|
|
1982
|
+
object: i,
|
|
1968
1983
|
type: t,
|
|
1969
1984
|
withoutSave: s,
|
|
1970
|
-
fitAsOneObject:
|
|
1985
|
+
fitAsOneObject: a
|
|
1971
1986
|
});
|
|
1972
1987
|
}
|
|
1973
1988
|
}
|
|
@@ -1978,11 +1993,11 @@ class ct {
|
|
|
1978
1993
|
* @private
|
|
1979
1994
|
*/
|
|
1980
1995
|
_fitSingleObject(e, t) {
|
|
1981
|
-
const { canvas: s, montageArea:
|
|
1996
|
+
const { canvas: s, montageArea: a } = this.editor, { width: n, height: o, scaleX: i = 1, scaleY: c = 1, angle: d = 0 } = e, h = n * Math.abs(i), l = o * Math.abs(c), g = d * Math.PI / 180, M = Math.abs(Math.cos(g)), m = Math.abs(Math.sin(g)), f = h * M + l * m, u = h * m + l * M, j = a.width, C = a.height;
|
|
1982
1997
|
let S;
|
|
1983
|
-
t === "contain" ? S = Math.min(
|
|
1984
|
-
scaleX:
|
|
1985
|
-
scaleY:
|
|
1998
|
+
t === "contain" ? S = Math.min(j / f, C / u) : S = Math.max(j / f, C / u), e.set({
|
|
1999
|
+
scaleX: i * S,
|
|
2000
|
+
scaleY: c * S
|
|
1986
2001
|
}), s.centerObject(e);
|
|
1987
2002
|
}
|
|
1988
2003
|
/**
|
|
@@ -2003,36 +2018,36 @@ class ct {
|
|
|
2003
2018
|
*/
|
|
2004
2019
|
resetObject({ object: e, alwaysFitObject: t = !1, withoutSave: s = !1 } = {}) {
|
|
2005
2020
|
const {
|
|
2006
|
-
canvas:
|
|
2007
|
-
montageArea:
|
|
2008
|
-
imageManager:
|
|
2009
|
-
historyManager:
|
|
2010
|
-
options: { scaleType:
|
|
2011
|
-
} = this.editor,
|
|
2012
|
-
if (!
|
|
2013
|
-
if (
|
|
2021
|
+
canvas: a,
|
|
2022
|
+
montageArea: n,
|
|
2023
|
+
imageManager: o,
|
|
2024
|
+
historyManager: i,
|
|
2025
|
+
options: { scaleType: c }
|
|
2026
|
+
} = this.editor, d = e || a.getActiveObject();
|
|
2027
|
+
if (!d || d.locked) return;
|
|
2028
|
+
if (i.suspendHistory(), d.type === "image" || d.format === "svg" || d.set({
|
|
2014
2029
|
scaleX: 1,
|
|
2015
2030
|
scaleY: 1,
|
|
2016
2031
|
flipX: !1,
|
|
2017
2032
|
flipY: !1,
|
|
2018
2033
|
angle: 0
|
|
2019
2034
|
}), t)
|
|
2020
|
-
this.fitObject({ object:
|
|
2035
|
+
this.fitObject({ object: d, withoutSave: !0, fitAsOneObject: !0 });
|
|
2021
2036
|
else {
|
|
2022
|
-
const { width: l, height: g } =
|
|
2023
|
-
imageObject:
|
|
2024
|
-
scaleType:
|
|
2037
|
+
const { width: l, height: g } = n, { width: M, height: m } = d, f = o.calculateScaleFactor({
|
|
2038
|
+
imageObject: d,
|
|
2039
|
+
scaleType: c
|
|
2025
2040
|
});
|
|
2026
|
-
|
|
2041
|
+
c === "contain" && f < 1 || c === "cover" && (M > l || m > g) ? this.fitObject({ object: d, withoutSave: !0, fitAsOneObject: !0 }) : d.set({ scaleX: 1, scaleY: 1 });
|
|
2027
2042
|
}
|
|
2028
|
-
|
|
2029
|
-
object:
|
|
2043
|
+
d.set({ flipX: !1, flipY: !1, angle: 0 }), a.centerObject(d), a.renderAll(), i.resumeHistory(), s || i.saveState(), a.fire("editor:object-reset", {
|
|
2044
|
+
object: d,
|
|
2030
2045
|
withoutSave: s,
|
|
2031
2046
|
alwaysFitObject: t
|
|
2032
2047
|
});
|
|
2033
2048
|
}
|
|
2034
2049
|
}
|
|
2035
|
-
class
|
|
2050
|
+
class ht {
|
|
2036
2051
|
constructor({ editor: e }) {
|
|
2037
2052
|
this.editor = e, this.isBlocked = !1, this.overlayMask = null, this._createOverlay();
|
|
2038
2053
|
}
|
|
@@ -2062,8 +2077,8 @@ class dt {
|
|
|
2062
2077
|
const { canvas: e, montageArea: t, historyManager: s } = this.editor;
|
|
2063
2078
|
if (!t || !this.overlayMask) return;
|
|
2064
2079
|
s.suspendHistory(), t.setCoords();
|
|
2065
|
-
const { left:
|
|
2066
|
-
this.overlayMask.set({ left:
|
|
2080
|
+
const { left: a, top: n, width: o, height: i } = t.getBoundingRect();
|
|
2081
|
+
this.overlayMask.set({ left: a, top: n, width: o, height: i }), e.discardActiveObject(), this.editor.layerManager.bringToFront(this.overlayMask, { withoutSave: !0 }), s.resumeHistory();
|
|
2067
2082
|
}
|
|
2068
2083
|
/**
|
|
2069
2084
|
* Выключает редактор:
|
|
@@ -2074,8 +2089,8 @@ class dt {
|
|
|
2074
2089
|
block() {
|
|
2075
2090
|
if (this.isBlocked || !this.overlayMask) return;
|
|
2076
2091
|
const { canvas: e, canvasManager: t, historyManager: s } = this.editor;
|
|
2077
|
-
s.suspendHistory(), this.isBlocked = !0, e.discardActiveObject(), e.selection = !1, e.skipTargetFind = !0, t.getObjects().forEach((
|
|
2078
|
-
|
|
2092
|
+
s.suspendHistory(), this.isBlocked = !0, e.discardActiveObject(), e.selection = !1, e.skipTargetFind = !0, t.getObjects().forEach((a) => {
|
|
2093
|
+
a.evented = !1, a.selectable = !1;
|
|
2079
2094
|
}), e.upperCanvasEl.style.pointerEvents = "none", e.lowerCanvasEl.style.pointerEvents = "none", this.overlayMask.visible = !0, this.refresh(), e.fire("editor:disabled"), s.resumeHistory();
|
|
2080
2095
|
}
|
|
2081
2096
|
/**
|
|
@@ -2084,12 +2099,271 @@ class dt {
|
|
|
2084
2099
|
unblock() {
|
|
2085
2100
|
if (!this.isBlocked || !this.overlayMask) return;
|
|
2086
2101
|
const { canvas: e, canvasManager: t, historyManager: s } = this.editor;
|
|
2087
|
-
s.suspendHistory(), this.isBlocked = !1, e.selection = !0, e.skipTargetFind = !1, t.getObjects().forEach((
|
|
2088
|
-
|
|
2102
|
+
s.suspendHistory(), this.isBlocked = !1, e.selection = !0, e.skipTargetFind = !1, t.getObjects().forEach((a) => {
|
|
2103
|
+
a.evented = !0, a.selectable = !0;
|
|
2089
2104
|
}), e.upperCanvasEl.style.pointerEvents = "", e.lowerCanvasEl.style.pointerEvents = "", this.overlayMask.visible = !1, e.requestRenderAll(), e.fire("editor:enabled"), s.resumeHistory();
|
|
2090
2105
|
}
|
|
2091
2106
|
}
|
|
2092
|
-
class
|
|
2107
|
+
class R {
|
|
2108
|
+
constructor({ editor: e }) {
|
|
2109
|
+
this.editor = e, this.backgroundObject = null;
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Устанавливает фон сплошного цвета.
|
|
2113
|
+
* @param options - Опции для установки цвета фона
|
|
2114
|
+
* @param options.color - Цвет фона в формате HEX (например, "#FF0000")
|
|
2115
|
+
* @param options.withoutSave - Если true, не сохранять состояние в историю
|
|
2116
|
+
*/
|
|
2117
|
+
setColorBackground({
|
|
2118
|
+
color: e,
|
|
2119
|
+
withoutSave: t = !1
|
|
2120
|
+
}) {
|
|
2121
|
+
try {
|
|
2122
|
+
const { historyManager: s } = this.editor, { backgroundObject: a } = this;
|
|
2123
|
+
if (s.suspendHistory(), a && a.backgroundType === "color") {
|
|
2124
|
+
if (a.fill === e) {
|
|
2125
|
+
s.resumeHistory();
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2128
|
+
a.set({ fill: e }), a.set("backgroundId", `background-${v()}`), this.editor.canvas.requestRenderAll();
|
|
2129
|
+
} else
|
|
2130
|
+
this._removeCurrentBackground(), this._createColorBackground(e);
|
|
2131
|
+
this.editor.canvas.fire("background:changed", { type: "color", color: e }), s.resumeHistory(), t || s.saveState();
|
|
2132
|
+
} catch (s) {
|
|
2133
|
+
this.editor.errorManager.emitError({
|
|
2134
|
+
code: "BACKGROUND_CREATION_FAILED",
|
|
2135
|
+
origin: "BackgroundManager",
|
|
2136
|
+
method: "setColorBackground",
|
|
2137
|
+
message: "Не удалось установить цветовой фон",
|
|
2138
|
+
data: { error: s }
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
/**
|
|
2143
|
+
* Устанавливает градиентный фон.
|
|
2144
|
+
* @param options - Опции для установки градиентного фона
|
|
2145
|
+
* @param options.gradient - Объект с параметрами градиента
|
|
2146
|
+
* @param options.withoutSave - Если true, не сохранять состояние в историю
|
|
2147
|
+
*/
|
|
2148
|
+
setGradientBackground({
|
|
2149
|
+
gradient: e,
|
|
2150
|
+
withoutSave: t = !1
|
|
2151
|
+
}) {
|
|
2152
|
+
try {
|
|
2153
|
+
const { historyManager: s } = this.editor, { backgroundObject: a } = this;
|
|
2154
|
+
if (s.suspendHistory(), a && a.backgroundType === "gradient") {
|
|
2155
|
+
const n = R._createFabricGradient(e);
|
|
2156
|
+
if (R._isGradientEqual(a.fill, n)) {
|
|
2157
|
+
s.resumeHistory();
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2160
|
+
a.set({ fill: n }), a.set("backgroundId", `background-${v()}`), this.editor.canvas.requestRenderAll();
|
|
2161
|
+
} else
|
|
2162
|
+
this._removeCurrentBackground(), this._createGradientBackground(e);
|
|
2163
|
+
this.editor.canvas.fire("background:changed", {
|
|
2164
|
+
type: "gradient",
|
|
2165
|
+
gradientParams: e
|
|
2166
|
+
}), s.resumeHistory(), t || s.saveState();
|
|
2167
|
+
} catch (s) {
|
|
2168
|
+
this.editor.errorManager.emitError({
|
|
2169
|
+
code: "BACKGROUND_CREATION_FAILED",
|
|
2170
|
+
origin: "BackgroundManager",
|
|
2171
|
+
method: "setGradientBackground",
|
|
2172
|
+
message: "Не удалось установить градиентный фон",
|
|
2173
|
+
data: { error: s }
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* Устанавливает фон из изображения.
|
|
2179
|
+
* @param options - Опции для установки фонового изображения
|
|
2180
|
+
* @param options.imageUrl - URL изображения
|
|
2181
|
+
* @param options.withoutSave - Если true, не сохранять состояние в историю
|
|
2182
|
+
*/
|
|
2183
|
+
setImageBackground(s) {
|
|
2184
|
+
return b(this, arguments, function* ({
|
|
2185
|
+
imageUrl: e,
|
|
2186
|
+
withoutSave: t = !1
|
|
2187
|
+
}) {
|
|
2188
|
+
try {
|
|
2189
|
+
const { historyManager: a } = this.editor;
|
|
2190
|
+
a.suspendHistory(), this._removeCurrentBackground(), yield this._createImageBackground(e), this.editor.canvas.fire("background:changed", { type: "image", imageUrl: e }), a.resumeHistory(), t || a.saveState();
|
|
2191
|
+
} catch (a) {
|
|
2192
|
+
this.editor.errorManager.emitError({
|
|
2193
|
+
code: "BACKGROUND_CREATION_FAILED",
|
|
2194
|
+
origin: "BackgroundManager",
|
|
2195
|
+
method: "setImageBackground",
|
|
2196
|
+
message: "Не удалось установить изображение в качестве фона",
|
|
2197
|
+
data: { error: a }
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
/**
|
|
2203
|
+
* Удаляет текущий фон.
|
|
2204
|
+
* @param options - Опции для удаления фона
|
|
2205
|
+
* @param options.withoutSave - Если true, не сохранять состояние в историю
|
|
2206
|
+
*/
|
|
2207
|
+
removeBackground({ withoutSave: e = !1 } = {}) {
|
|
2208
|
+
try {
|
|
2209
|
+
const { historyManager: t } = this.editor;
|
|
2210
|
+
if (!this.backgroundObject) {
|
|
2211
|
+
this.editor.errorManager.emitWarning({
|
|
2212
|
+
code: "NO_BACKGROUND_TO_REMOVE",
|
|
2213
|
+
origin: "BackgroundManager",
|
|
2214
|
+
method: "removeBackground",
|
|
2215
|
+
message: "Нет фона для удаления"
|
|
2216
|
+
});
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
t.suspendHistory(), this._removeCurrentBackground(), this.editor.canvas.fire("background:removed"), t.resumeHistory(), e || t.saveState();
|
|
2220
|
+
} catch (t) {
|
|
2221
|
+
this.editor.errorManager.emitError({
|
|
2222
|
+
code: "BACKGROUND_REMOVAL_FAILED",
|
|
2223
|
+
origin: "BackgroundManager",
|
|
2224
|
+
method: "removeBackground",
|
|
2225
|
+
message: "Не удалось удалить фон",
|
|
2226
|
+
data: { error: t }
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
/**
|
|
2231
|
+
* Обновляет размеры и позицию фона согласно монтажной области.
|
|
2232
|
+
*/
|
|
2233
|
+
refresh() {
|
|
2234
|
+
const { canvas: e, montageArea: t, historyManager: s } = this.editor;
|
|
2235
|
+
if (!t || !this.backgroundObject) return;
|
|
2236
|
+
s.suspendHistory(), t.setCoords();
|
|
2237
|
+
const { left: a, top: n, width: o, height: i } = t.getBoundingRect();
|
|
2238
|
+
this.backgroundObject.set({ left: a, top: n, width: o, height: i });
|
|
2239
|
+
const c = e.getObjects(), d = c.indexOf(t), h = c.indexOf(this.backgroundObject);
|
|
2240
|
+
this.backgroundObject && h !== d + 1 && e.moveObjectTo(this.backgroundObject, d + 1), e.requestRenderAll(), s.resumeHistory();
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Создает цветовой фон.
|
|
2244
|
+
* @param color - Цвет фона в формате HEX (например, "#FF0000")
|
|
2245
|
+
*/
|
|
2246
|
+
_createColorBackground(e) {
|
|
2247
|
+
this.backgroundObject = this.editor.shapeManager.addRectangle({
|
|
2248
|
+
fill: e,
|
|
2249
|
+
selectable: !1,
|
|
2250
|
+
evented: !1,
|
|
2251
|
+
hasBorders: !1,
|
|
2252
|
+
hasControls: !1,
|
|
2253
|
+
id: "background",
|
|
2254
|
+
backgroundType: "color",
|
|
2255
|
+
backgroundId: `background-${v()}`
|
|
2256
|
+
}, { withoutSelection: !0 }), this._setupBackgroundPosition();
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* Создает градиентный фон.
|
|
2260
|
+
* @param gradient - Объект с параметрами градиента
|
|
2261
|
+
*/
|
|
2262
|
+
_createGradientBackground(e) {
|
|
2263
|
+
this.backgroundObject = this.editor.shapeManager.addRectangle({
|
|
2264
|
+
fill: "#ffffff",
|
|
2265
|
+
// временный цвет
|
|
2266
|
+
selectable: !1,
|
|
2267
|
+
evented: !1,
|
|
2268
|
+
hasBorders: !1,
|
|
2269
|
+
hasControls: !1,
|
|
2270
|
+
id: "background",
|
|
2271
|
+
backgroundType: "gradient",
|
|
2272
|
+
backgroundId: `background-${v()}`
|
|
2273
|
+
}, { withoutSelection: !0 }), this._setupBackgroundPosition();
|
|
2274
|
+
const t = R._createFabricGradient(e);
|
|
2275
|
+
this.backgroundObject.set("fill", t), this.editor.canvas.requestRenderAll();
|
|
2276
|
+
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Создает фон из изображения.
|
|
2279
|
+
* @param imageUrl - URL изображения
|
|
2280
|
+
*/
|
|
2281
|
+
_createImageBackground(e) {
|
|
2282
|
+
return b(this, null, function* () {
|
|
2283
|
+
return new Promise((t, s) => {
|
|
2284
|
+
x.fromURL(e, {
|
|
2285
|
+
crossOrigin: "anonymous"
|
|
2286
|
+
}).then((a) => {
|
|
2287
|
+
if (!a) {
|
|
2288
|
+
s(new Error("Не удалось загрузить изображение"));
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
a.set({
|
|
2292
|
+
selectable: !1,
|
|
2293
|
+
evented: !1,
|
|
2294
|
+
hasBorders: !1,
|
|
2295
|
+
hasControls: !1,
|
|
2296
|
+
id: "background",
|
|
2297
|
+
backgroundType: "image",
|
|
2298
|
+
backgroundId: `background-${v()}`
|
|
2299
|
+
}), this.editor.canvas.add(a), this.backgroundObject = a, this._setupBackgroundPosition(), t();
|
|
2300
|
+
}).catch(s);
|
|
2301
|
+
});
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* Настраивает позицию и размеры фона.
|
|
2306
|
+
*/
|
|
2307
|
+
_setupBackgroundPosition() {
|
|
2308
|
+
this.backgroundObject && this.refresh();
|
|
2309
|
+
}
|
|
2310
|
+
/**
|
|
2311
|
+
* Удаляет текущий фон.
|
|
2312
|
+
*/
|
|
2313
|
+
_removeCurrentBackground() {
|
|
2314
|
+
this.backgroundObject && (this.editor.canvas.remove(this.backgroundObject), this.backgroundObject = null, this.editor.canvas.renderAll());
|
|
2315
|
+
}
|
|
2316
|
+
/**
|
|
2317
|
+
* Создает Fabric.js градиент из параметров.
|
|
2318
|
+
* @param gradient - Объект с параметрами градиента
|
|
2319
|
+
*/
|
|
2320
|
+
static _createFabricGradient(e) {
|
|
2321
|
+
const {
|
|
2322
|
+
angle: t,
|
|
2323
|
+
startColor: s,
|
|
2324
|
+
endColor: a,
|
|
2325
|
+
startPosition: n = 0,
|
|
2326
|
+
endPosition: o = 100
|
|
2327
|
+
} = e, i = t * Math.PI / 180, c = R._angleToCoords(i), d = [
|
|
2328
|
+
{ offset: n / 100, color: s },
|
|
2329
|
+
{ offset: o / 100, color: a }
|
|
2330
|
+
];
|
|
2331
|
+
return new De({
|
|
2332
|
+
type: "linear",
|
|
2333
|
+
gradientUnits: "percentage",
|
|
2334
|
+
coords: c,
|
|
2335
|
+
colorStops: d
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Конвертирует угол в координаты для линейного градиента.
|
|
2340
|
+
* @param angle - Угол в радианах
|
|
2341
|
+
*/
|
|
2342
|
+
static _angleToCoords(e) {
|
|
2343
|
+
const t = Math.cos(e), s = Math.sin(e);
|
|
2344
|
+
return {
|
|
2345
|
+
x1: 0.5 - t * 0.5,
|
|
2346
|
+
y1: 0.5 - s * 0.5,
|
|
2347
|
+
x2: 0.5 + t * 0.5,
|
|
2348
|
+
y2: 0.5 + s * 0.5
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
/**
|
|
2352
|
+
* Сравнивает два градиента на равенство
|
|
2353
|
+
* @param gradient1 - Первый градиент
|
|
2354
|
+
* @param gradient2 - Второй градиент
|
|
2355
|
+
* @returns true если градиенты одинаковые
|
|
2356
|
+
*/
|
|
2357
|
+
static _isGradientEqual(e, t) {
|
|
2358
|
+
if (!e || !t || e.type !== "linear" || t.type !== "linear" || !(Math.abs(e.coords.x1 - t.coords.x1) < 1e-4 && Math.abs(e.coords.y1 - t.coords.y1) < 1e-4 && Math.abs(e.coords.x2 - t.coords.x2) < 1e-4 && Math.abs(e.coords.y2 - t.coords.y2) < 1e-4)) return !1;
|
|
2359
|
+
const a = e.colorStops || [], n = t.colorStops || [];
|
|
2360
|
+
return a.length !== n.length ? !1 : a.every((o, i) => {
|
|
2361
|
+
const c = n[i];
|
|
2362
|
+
return o.color === c.color && Math.abs(o.offset - c.offset) < 1e-4;
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
class X {
|
|
2093
2367
|
constructor({ editor: e }) {
|
|
2094
2368
|
this.editor = e;
|
|
2095
2369
|
}
|
|
@@ -2101,13 +2375,13 @@ class G {
|
|
|
2101
2375
|
* @fires editor:object-bring-to-front
|
|
2102
2376
|
*/
|
|
2103
2377
|
bringToFront(e, { withoutSave: t } = {}) {
|
|
2104
|
-
const { canvas: s, historyManager:
|
|
2105
|
-
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2108
|
-
s.bringObjectToFront(
|
|
2109
|
-
}) : s.bringObjectToFront(
|
|
2110
|
-
object:
|
|
2378
|
+
const { canvas: s, historyManager: a } = this.editor;
|
|
2379
|
+
a.suspendHistory();
|
|
2380
|
+
const n = e || s.getActiveObject();
|
|
2381
|
+
n && (n instanceof y ? n.getObjects().forEach((o) => {
|
|
2382
|
+
s.bringObjectToFront(o);
|
|
2383
|
+
}) : s.bringObjectToFront(n), s.renderAll(), a.resumeHistory(), t || a.saveState(), s.fire("editor:object-bring-to-front", {
|
|
2384
|
+
object: n,
|
|
2111
2385
|
withoutSave: t
|
|
2112
2386
|
}));
|
|
2113
2387
|
}
|
|
@@ -2119,11 +2393,11 @@ class G {
|
|
|
2119
2393
|
* @fires editor:object-bring-forward
|
|
2120
2394
|
*/
|
|
2121
2395
|
bringForward(e, { withoutSave: t } = {}) {
|
|
2122
|
-
const { canvas: s, historyManager:
|
|
2123
|
-
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2126
|
-
object:
|
|
2396
|
+
const { canvas: s, historyManager: a } = this.editor;
|
|
2397
|
+
a.suspendHistory();
|
|
2398
|
+
const n = e || s.getActiveObject();
|
|
2399
|
+
n && (n instanceof y ? X._moveSelectionForward(s, n) : s.bringObjectForward(n), s.renderAll(), a.resumeHistory(), t || a.saveState(), s.fire("editor:object-bring-forward", {
|
|
2400
|
+
object: n,
|
|
2127
2401
|
withoutSave: t
|
|
2128
2402
|
}));
|
|
2129
2403
|
}
|
|
@@ -2137,21 +2411,22 @@ class G {
|
|
|
2137
2411
|
sendToBack(e, { withoutSave: t } = {}) {
|
|
2138
2412
|
const {
|
|
2139
2413
|
canvas: s,
|
|
2140
|
-
montageArea:
|
|
2141
|
-
historyManager:
|
|
2142
|
-
interactionBlocker: { overlayMask:
|
|
2414
|
+
montageArea: a,
|
|
2415
|
+
historyManager: n,
|
|
2416
|
+
interactionBlocker: { overlayMask: o },
|
|
2417
|
+
backgroundManager: { backgroundObject: i }
|
|
2143
2418
|
} = this.editor;
|
|
2144
|
-
|
|
2145
|
-
const
|
|
2146
|
-
if (
|
|
2147
|
-
if (
|
|
2148
|
-
const d =
|
|
2149
|
-
for (let
|
|
2150
|
-
s.sendObjectToBack(d[
|
|
2419
|
+
n.suspendHistory();
|
|
2420
|
+
const c = e || s.getActiveObject();
|
|
2421
|
+
if (c) {
|
|
2422
|
+
if (c instanceof y) {
|
|
2423
|
+
const d = c.getObjects();
|
|
2424
|
+
for (let h = d.length - 1; h >= 0; h -= 1)
|
|
2425
|
+
s.sendObjectToBack(d[h]);
|
|
2151
2426
|
} else
|
|
2152
|
-
s.sendObjectToBack(
|
|
2153
|
-
s.sendObjectToBack(
|
|
2154
|
-
object:
|
|
2427
|
+
s.sendObjectToBack(c);
|
|
2428
|
+
i && s.sendObjectToBack(i), s.sendObjectToBack(a), o && s.sendObjectToBack(o), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:object-send-to-back", {
|
|
2429
|
+
object: c,
|
|
2155
2430
|
withoutSave: t
|
|
2156
2431
|
});
|
|
2157
2432
|
}
|
|
@@ -2165,14 +2440,15 @@ class G {
|
|
|
2165
2440
|
sendBackwards(e, { withoutSave: t } = {}) {
|
|
2166
2441
|
const {
|
|
2167
2442
|
canvas: s,
|
|
2168
|
-
montageArea:
|
|
2169
|
-
historyManager:
|
|
2170
|
-
interactionBlocker: { overlayMask:
|
|
2443
|
+
montageArea: a,
|
|
2444
|
+
historyManager: n,
|
|
2445
|
+
interactionBlocker: { overlayMask: o },
|
|
2446
|
+
backgroundManager: { backgroundObject: i }
|
|
2171
2447
|
} = this.editor;
|
|
2172
|
-
|
|
2173
|
-
const
|
|
2174
|
-
|
|
2175
|
-
object:
|
|
2448
|
+
n.suspendHistory();
|
|
2449
|
+
const c = e || s.getActiveObject();
|
|
2450
|
+
c && (c instanceof y ? X._moveSelectionBackwards(s, c) : s.sendObjectBackwards(c), i && s.sendObjectToBack(i), s.sendObjectToBack(a), o && s.sendObjectToBack(o), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:object-send-backwards", {
|
|
2451
|
+
object: c,
|
|
2176
2452
|
withoutSave: t
|
|
2177
2453
|
}));
|
|
2178
2454
|
}
|
|
@@ -2183,16 +2459,16 @@ class G {
|
|
|
2183
2459
|
* @param activeSelection - активное выделение
|
|
2184
2460
|
*/
|
|
2185
2461
|
static _moveSelectionForward(e, t) {
|
|
2186
|
-
const s = e.getObjects(),
|
|
2187
|
-
if (!
|
|
2188
|
-
const
|
|
2189
|
-
for (let
|
|
2190
|
-
if (!
|
|
2462
|
+
const s = e.getObjects(), a = t.getObjects();
|
|
2463
|
+
if (!a.some((i) => {
|
|
2464
|
+
const c = s.indexOf(i);
|
|
2465
|
+
for (let d = c + 1; d < s.length; d += 1)
|
|
2466
|
+
if (!a.includes(s[d]))
|
|
2191
2467
|
return !0;
|
|
2192
2468
|
return !1;
|
|
2193
2469
|
})) return;
|
|
2194
|
-
|
|
2195
|
-
e.bringObjectForward(
|
|
2470
|
+
a.map((i) => ({ obj: i, index: s.indexOf(i) })).sort((i, c) => c.index - i.index).forEach((i) => {
|
|
2471
|
+
e.bringObjectForward(i.obj);
|
|
2196
2472
|
});
|
|
2197
2473
|
}
|
|
2198
2474
|
/**
|
|
@@ -2202,20 +2478,20 @@ class G {
|
|
|
2202
2478
|
* @param activeSelection - активное выделение
|
|
2203
2479
|
*/
|
|
2204
2480
|
static _moveSelectionBackwards(e, t) {
|
|
2205
|
-
const s = e.getObjects(),
|
|
2206
|
-
if (!
|
|
2207
|
-
const
|
|
2208
|
-
for (let
|
|
2209
|
-
if (!
|
|
2481
|
+
const s = e.getObjects(), a = t.getObjects();
|
|
2482
|
+
if (!a.some((i) => {
|
|
2483
|
+
const c = s.indexOf(i);
|
|
2484
|
+
for (let d = c - 1; d >= 0; d -= 1)
|
|
2485
|
+
if (!a.includes(s[d]))
|
|
2210
2486
|
return !0;
|
|
2211
2487
|
return !1;
|
|
2212
2488
|
})) return;
|
|
2213
|
-
|
|
2214
|
-
e.sendObjectBackwards(
|
|
2489
|
+
a.map((i) => ({ obj: i, index: s.indexOf(i) })).sort((i, c) => i.index - c.index).forEach((i) => {
|
|
2490
|
+
e.sendObjectBackwards(i.obj);
|
|
2215
2491
|
});
|
|
2216
2492
|
}
|
|
2217
2493
|
}
|
|
2218
|
-
class
|
|
2494
|
+
class gt {
|
|
2219
2495
|
/**
|
|
2220
2496
|
* Менеджер фигур для редактора.
|
|
2221
2497
|
* @param options - Опции и настройки менеджера фигур.
|
|
@@ -2239,15 +2515,15 @@ class lt {
|
|
|
2239
2515
|
* @param flags.withoutSelection - Не выделять объект
|
|
2240
2516
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2241
2517
|
*/
|
|
2242
|
-
addRectangle(h = {}, { withoutSelection:
|
|
2518
|
+
addRectangle(h = {}, { withoutSelection: c, withoutAdding: d } = {}) {
|
|
2243
2519
|
var l = h, {
|
|
2244
|
-
id: e = `rect-${
|
|
2520
|
+
id: e = `rect-${v()}`,
|
|
2245
2521
|
left: t,
|
|
2246
2522
|
top: s,
|
|
2247
|
-
width:
|
|
2248
|
-
height:
|
|
2249
|
-
fill:
|
|
2250
|
-
} = l,
|
|
2523
|
+
width: a = 100,
|
|
2524
|
+
height: n = 100,
|
|
2525
|
+
fill: o = "blue"
|
|
2526
|
+
} = l, i = W(l, [
|
|
2251
2527
|
"id",
|
|
2252
2528
|
"left",
|
|
2253
2529
|
"top",
|
|
@@ -2255,15 +2531,15 @@ class lt {
|
|
|
2255
2531
|
"height",
|
|
2256
2532
|
"fill"
|
|
2257
2533
|
]);
|
|
2258
|
-
const { canvas: g } = this.editor, M = new
|
|
2534
|
+
const { canvas: g } = this.editor, M = new Ne(p({
|
|
2259
2535
|
id: e,
|
|
2260
2536
|
left: t,
|
|
2261
2537
|
top: s,
|
|
2262
|
-
width:
|
|
2263
|
-
height:
|
|
2264
|
-
fill:
|
|
2265
|
-
},
|
|
2266
|
-
return !t && !s && g.centerObject(M),
|
|
2538
|
+
width: a,
|
|
2539
|
+
height: n,
|
|
2540
|
+
fill: o
|
|
2541
|
+
}, i));
|
|
2542
|
+
return !t && !s && g.centerObject(M), d || (g.add(M), c || g.setActiveObject(M), g.renderAll()), M;
|
|
2267
2543
|
}
|
|
2268
2544
|
/**
|
|
2269
2545
|
* Добавление круга
|
|
@@ -2281,28 +2557,28 @@ class lt {
|
|
|
2281
2557
|
* @param flags.withoutSelection - Не выделять объект
|
|
2282
2558
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2283
2559
|
*/
|
|
2284
|
-
addCircle(
|
|
2285
|
-
var h =
|
|
2286
|
-
id: e = `circle-${
|
|
2560
|
+
addCircle(d = {}, { withoutSelection: i, withoutAdding: c } = {}) {
|
|
2561
|
+
var h = d, {
|
|
2562
|
+
id: e = `circle-${v()}`,
|
|
2287
2563
|
left: t,
|
|
2288
2564
|
top: s,
|
|
2289
|
-
radius:
|
|
2290
|
-
fill:
|
|
2291
|
-
} = h,
|
|
2565
|
+
radius: a = 50,
|
|
2566
|
+
fill: n = "green"
|
|
2567
|
+
} = h, o = W(h, [
|
|
2292
2568
|
"id",
|
|
2293
2569
|
"left",
|
|
2294
2570
|
"top",
|
|
2295
2571
|
"radius",
|
|
2296
2572
|
"fill"
|
|
2297
2573
|
]);
|
|
2298
|
-
const { canvas: l } = this.editor, g = new
|
|
2574
|
+
const { canvas: l } = this.editor, g = new Oe(p({
|
|
2299
2575
|
id: e,
|
|
2300
2576
|
left: t,
|
|
2301
2577
|
top: s,
|
|
2302
|
-
fill:
|
|
2303
|
-
radius:
|
|
2304
|
-
},
|
|
2305
|
-
return !t && !s && l.centerObject(g),
|
|
2578
|
+
fill: n,
|
|
2579
|
+
radius: a
|
|
2580
|
+
}, o));
|
|
2581
|
+
return !t && !s && l.centerObject(g), c || (l.add(g), i || l.setActiveObject(g), l.renderAll()), g;
|
|
2306
2582
|
}
|
|
2307
2583
|
/**
|
|
2308
2584
|
* Добавление треугольника
|
|
@@ -2321,15 +2597,15 @@ class lt {
|
|
|
2321
2597
|
* @param flags.withoutSelection - Не выделять объект
|
|
2322
2598
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2323
2599
|
*/
|
|
2324
|
-
addTriangle(h = {}, { withoutSelection:
|
|
2600
|
+
addTriangle(h = {}, { withoutSelection: c, withoutAdding: d } = {}) {
|
|
2325
2601
|
var l = h, {
|
|
2326
|
-
id: e = `triangle-${
|
|
2602
|
+
id: e = `triangle-${v()}`,
|
|
2327
2603
|
left: t,
|
|
2328
2604
|
top: s,
|
|
2329
|
-
width:
|
|
2330
|
-
height:
|
|
2331
|
-
fill:
|
|
2332
|
-
} = l,
|
|
2605
|
+
width: a = 100,
|
|
2606
|
+
height: n = 100,
|
|
2607
|
+
fill: o = "yellow"
|
|
2608
|
+
} = l, i = W(l, [
|
|
2333
2609
|
"id",
|
|
2334
2610
|
"left",
|
|
2335
2611
|
"top",
|
|
@@ -2337,18 +2613,18 @@ class lt {
|
|
|
2337
2613
|
"height",
|
|
2338
2614
|
"fill"
|
|
2339
2615
|
]);
|
|
2340
|
-
const { canvas: g } = this.editor, M = new
|
|
2616
|
+
const { canvas: g } = this.editor, M = new Le(p({
|
|
2341
2617
|
id: e,
|
|
2342
2618
|
left: t,
|
|
2343
2619
|
top: s,
|
|
2344
|
-
fill:
|
|
2345
|
-
width:
|
|
2346
|
-
height:
|
|
2347
|
-
},
|
|
2348
|
-
return !t && !s && g.centerObject(M),
|
|
2620
|
+
fill: o,
|
|
2621
|
+
width: a,
|
|
2622
|
+
height: n
|
|
2623
|
+
}, i));
|
|
2624
|
+
return !t && !s && g.centerObject(M), d || (g.add(M), c || g.setActiveObject(M), g.renderAll()), M;
|
|
2349
2625
|
}
|
|
2350
2626
|
}
|
|
2351
|
-
class
|
|
2627
|
+
class ut {
|
|
2352
2628
|
/**
|
|
2353
2629
|
* @param options
|
|
2354
2630
|
* @param options.editor - экземпляр редактора с доступом к canvas
|
|
@@ -2376,18 +2652,18 @@ class ht {
|
|
|
2376
2652
|
* Асинхронное клонирование для внутреннего буфера
|
|
2377
2653
|
*/
|
|
2378
2654
|
_cloneToInternalClipboard(e) {
|
|
2379
|
-
return
|
|
2655
|
+
return b(this, null, function* () {
|
|
2380
2656
|
const { canvas: t, errorManager: s } = this.editor;
|
|
2381
2657
|
try {
|
|
2382
|
-
const
|
|
2383
|
-
this.clipboard =
|
|
2384
|
-
} catch (
|
|
2658
|
+
const a = yield e.clone(["format"]);
|
|
2659
|
+
this.clipboard = a, t.fire("editor:object-copied", { object: a });
|
|
2660
|
+
} catch (a) {
|
|
2385
2661
|
s.emitError({
|
|
2386
2662
|
origin: "ClipboardManager",
|
|
2387
2663
|
method: "_cloneToInternalClipboard",
|
|
2388
2664
|
code: "CLONE_FAILED",
|
|
2389
2665
|
message: "Ошибка клонирования объекта для внутреннего буфера",
|
|
2390
|
-
data:
|
|
2666
|
+
data: a
|
|
2391
2667
|
});
|
|
2392
2668
|
}
|
|
2393
2669
|
});
|
|
@@ -2396,7 +2672,7 @@ class ht {
|
|
|
2396
2672
|
* Копирование в системный буфер обмена
|
|
2397
2673
|
*/
|
|
2398
2674
|
_copyToSystemClipboard(e) {
|
|
2399
|
-
return
|
|
2675
|
+
return b(this, null, function* () {
|
|
2400
2676
|
const { errorManager: t } = this.editor;
|
|
2401
2677
|
if (typeof ClipboardItem == "undefined" || !navigator.clipboard)
|
|
2402
2678
|
return t.emitWarning({
|
|
@@ -2406,8 +2682,8 @@ class ht {
|
|
|
2406
2682
|
message: "navigator.clipboard не поддерживается в этом браузере или отсутствует HTTPS-соединение."
|
|
2407
2683
|
}), !1;
|
|
2408
2684
|
try {
|
|
2409
|
-
const s = e.toObject(["format"]),
|
|
2410
|
-
return e.type === "image" ? this._copyImageToClipboard(e,
|
|
2685
|
+
const s = e.toObject(["format"]), a = JSON.stringify(s);
|
|
2686
|
+
return e.type === "image" ? this._copyImageToClipboard(e, a) : this._copyTextToClipboard(a);
|
|
2411
2687
|
} catch (s) {
|
|
2412
2688
|
return t.emitError({
|
|
2413
2689
|
origin: "ClipboardManager",
|
|
@@ -2423,12 +2699,12 @@ class ht {
|
|
|
2423
2699
|
* Копирование изображения в буфер обмена
|
|
2424
2700
|
*/
|
|
2425
2701
|
_copyImageToClipboard(e, t) {
|
|
2426
|
-
return
|
|
2702
|
+
return b(this, null, function* () {
|
|
2427
2703
|
try {
|
|
2428
|
-
const
|
|
2429
|
-
for (let l = 0; l <
|
|
2430
|
-
|
|
2431
|
-
const
|
|
2704
|
+
const a = e.toCanvasElement({ enableRetinaScaling: !1 }).toDataURL(), n = a.slice(5).split(";")[0], o = a.split(",")[1], i = atob(o), c = new Uint8Array(i.length);
|
|
2705
|
+
for (let l = 0; l < i.length; l += 1)
|
|
2706
|
+
c[l] = i.charCodeAt(l);
|
|
2707
|
+
const d = new Blob([c.buffer], { type: n }), h = new ClipboardItem({ [n]: d });
|
|
2432
2708
|
return yield navigator.clipboard.write([h]), console.info("Image copied to clipboard successfully"), !0;
|
|
2433
2709
|
} catch (s) {
|
|
2434
2710
|
return this.editor.errorManager.emitWarning({
|
|
@@ -2445,7 +2721,7 @@ class ht {
|
|
|
2445
2721
|
* Копирование текста в буфер обмена
|
|
2446
2722
|
*/
|
|
2447
2723
|
_copyTextToClipboard(e) {
|
|
2448
|
-
return
|
|
2724
|
+
return b(this, null, function* () {
|
|
2449
2725
|
try {
|
|
2450
2726
|
const t = `${me}${e}`;
|
|
2451
2727
|
return yield navigator.clipboard.writeText(t), console.info("Text copied to clipboard successfully"), !0;
|
|
@@ -2468,8 +2744,8 @@ class ht {
|
|
|
2468
2744
|
_addClonedObjectToCanvas(e) {
|
|
2469
2745
|
const { canvas: t, historyManager: s } = this.editor;
|
|
2470
2746
|
if (t.discardActiveObject(), e instanceof y) {
|
|
2471
|
-
s.suspendHistory(), e.canvas = t, e.forEachObject((
|
|
2472
|
-
t.add(
|
|
2747
|
+
s.suspendHistory(), e.canvas = t, e.forEachObject((a) => {
|
|
2748
|
+
t.add(a);
|
|
2473
2749
|
}), t.setActiveObject(e), t.requestRenderAll(), s.resumeHistory(), s.saveState();
|
|
2474
2750
|
return;
|
|
2475
2751
|
}
|
|
@@ -2480,7 +2756,7 @@ class ht {
|
|
|
2480
2756
|
* @param source - источник изображения (data URL или URL)
|
|
2481
2757
|
*/
|
|
2482
2758
|
_handleImageImport(e) {
|
|
2483
|
-
return
|
|
2759
|
+
return b(this, null, function* () {
|
|
2484
2760
|
var s;
|
|
2485
2761
|
const { image: t } = (s = yield this.editor.imageManager.importImage({
|
|
2486
2762
|
source: e,
|
|
@@ -2496,25 +2772,25 @@ class ht {
|
|
|
2496
2772
|
* @fires editor:object-pasted
|
|
2497
2773
|
*/
|
|
2498
2774
|
copyPaste(e) {
|
|
2499
|
-
return
|
|
2775
|
+
return b(this, null, function* () {
|
|
2500
2776
|
const { canvas: t } = this.editor, s = e || t.getActiveObject();
|
|
2501
2777
|
if (!s || s.locked) return !1;
|
|
2502
2778
|
try {
|
|
2503
|
-
const
|
|
2504
|
-
return
|
|
2505
|
-
id: `${
|
|
2506
|
-
left:
|
|
2507
|
-
top:
|
|
2779
|
+
const a = yield s.clone(["format"]);
|
|
2780
|
+
return a.set({
|
|
2781
|
+
id: `${a.type}-${v()}`,
|
|
2782
|
+
left: a.left + 10,
|
|
2783
|
+
top: a.top + 10,
|
|
2508
2784
|
evented: !0
|
|
2509
|
-
}), this._addClonedObjectToCanvas(
|
|
2510
|
-
} catch (
|
|
2511
|
-
const { errorManager:
|
|
2512
|
-
return
|
|
2785
|
+
}), this._addClonedObjectToCanvas(a), t.fire("editor:object-duplicated", { object: a }), !0;
|
|
2786
|
+
} catch (a) {
|
|
2787
|
+
const { errorManager: n } = this.editor;
|
|
2788
|
+
return n.emitError({
|
|
2513
2789
|
origin: "ClipboardManager",
|
|
2514
2790
|
method: "copyPaste",
|
|
2515
2791
|
code: "COPY_PASTE_FAILED",
|
|
2516
2792
|
message: "Ошибка создания копии объекта",
|
|
2517
|
-
data:
|
|
2793
|
+
data: a
|
|
2518
2794
|
}), !1;
|
|
2519
2795
|
}
|
|
2520
2796
|
});
|
|
@@ -2526,9 +2802,9 @@ class ht {
|
|
|
2526
2802
|
* @param event.clipboardData.items — элементы буфера обмена
|
|
2527
2803
|
*/
|
|
2528
2804
|
handlePasteEvent(t) {
|
|
2529
|
-
return
|
|
2530
|
-
var
|
|
2531
|
-
if (!((
|
|
2805
|
+
return b(this, arguments, function* ({ clipboardData: e }) {
|
|
2806
|
+
var c;
|
|
2807
|
+
if (!((c = e == null ? void 0 : e.items) != null && c.length)) {
|
|
2532
2808
|
this.paste();
|
|
2533
2809
|
return;
|
|
2534
2810
|
}
|
|
@@ -2537,10 +2813,10 @@ class ht {
|
|
|
2537
2813
|
this.paste();
|
|
2538
2814
|
return;
|
|
2539
2815
|
}
|
|
2540
|
-
const { items:
|
|
2541
|
-
if (
|
|
2542
|
-
const
|
|
2543
|
-
|
|
2816
|
+
const { items: a } = e, n = a[a.length - 1], o = n.getAsFile();
|
|
2817
|
+
if (n.type !== "text/html" && o) {
|
|
2818
|
+
const d = new FileReader();
|
|
2819
|
+
d.onload = (h) => {
|
|
2544
2820
|
h.target && this._handleImageImport(h.target.result).catch((l) => {
|
|
2545
2821
|
this.editor.errorManager.emitError({
|
|
2546
2822
|
origin: "ClipboardManager",
|
|
@@ -2550,12 +2826,12 @@ class ht {
|
|
|
2550
2826
|
data: l
|
|
2551
2827
|
});
|
|
2552
2828
|
});
|
|
2553
|
-
},
|
|
2829
|
+
}, d.readAsDataURL(o);
|
|
2554
2830
|
return;
|
|
2555
2831
|
}
|
|
2556
|
-
const
|
|
2557
|
-
if (
|
|
2558
|
-
const l = new DOMParser().parseFromString(
|
|
2832
|
+
const i = e.getData("text/html");
|
|
2833
|
+
if (i) {
|
|
2834
|
+
const l = new DOMParser().parseFromString(i, "text/html").querySelector("img");
|
|
2559
2835
|
if (l != null && l.src) {
|
|
2560
2836
|
this._handleImageImport(l.src).catch((g) => {
|
|
2561
2837
|
this.editor.errorManager.emitError({
|
|
@@ -2577,13 +2853,13 @@ class ht {
|
|
|
2577
2853
|
* @fires editor:object-pasted
|
|
2578
2854
|
*/
|
|
2579
2855
|
paste() {
|
|
2580
|
-
return
|
|
2856
|
+
return b(this, null, function* () {
|
|
2581
2857
|
const { canvas: e } = this.editor;
|
|
2582
2858
|
if (!this.clipboard) return !1;
|
|
2583
2859
|
try {
|
|
2584
2860
|
const t = yield this.clipboard.clone(["format"]);
|
|
2585
2861
|
return e.discardActiveObject(), t.set({
|
|
2586
|
-
id: `${t.type}-${
|
|
2862
|
+
id: `${t.type}-${v()}`,
|
|
2587
2863
|
left: t.left + 10,
|
|
2588
2864
|
top: t.top + 10,
|
|
2589
2865
|
evented: !0
|
|
@@ -2601,7 +2877,7 @@ class ht {
|
|
|
2601
2877
|
});
|
|
2602
2878
|
}
|
|
2603
2879
|
}
|
|
2604
|
-
class
|
|
2880
|
+
class Q {
|
|
2605
2881
|
constructor({ editor: e }) {
|
|
2606
2882
|
this.editor = e;
|
|
2607
2883
|
}
|
|
@@ -2614,9 +2890,9 @@ class X {
|
|
|
2614
2890
|
* @fires editor:object-locked
|
|
2615
2891
|
*/
|
|
2616
2892
|
lockObject({ object: e, skipInnerObjects: t, withoutSave: s } = {}) {
|
|
2617
|
-
const { canvas:
|
|
2618
|
-
if (!
|
|
2619
|
-
const
|
|
2893
|
+
const { canvas: a, historyManager: n } = this.editor, o = e || a.getActiveObject();
|
|
2894
|
+
if (!o || o.locked) return;
|
|
2895
|
+
const i = {
|
|
2620
2896
|
lockMovementX: !0,
|
|
2621
2897
|
lockMovementY: !0,
|
|
2622
2898
|
lockRotation: !0,
|
|
@@ -2626,10 +2902,10 @@ class X {
|
|
|
2626
2902
|
lockSkewingY: !0,
|
|
2627
2903
|
locked: !0
|
|
2628
2904
|
};
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
}),
|
|
2632
|
-
object:
|
|
2905
|
+
o.set(i), !t && Q._isGroupOrSelection(o) && o.getObjects().forEach((d) => {
|
|
2906
|
+
d.set(i);
|
|
2907
|
+
}), a.renderAll(), s || n.saveState(), a.fire("editor:object-locked", {
|
|
2908
|
+
object: o,
|
|
2633
2909
|
skipInnerObjects: t,
|
|
2634
2910
|
withoutSave: s
|
|
2635
2911
|
});
|
|
@@ -2642,9 +2918,9 @@ class X {
|
|
|
2642
2918
|
* @fires editor:object-unlocked
|
|
2643
2919
|
*/
|
|
2644
2920
|
unlockObject({ object: e, withoutSave: t } = {}) {
|
|
2645
|
-
const { canvas: s, historyManager:
|
|
2646
|
-
if (!
|
|
2647
|
-
const
|
|
2921
|
+
const { canvas: s, historyManager: a } = this.editor, n = e || s.getActiveObject();
|
|
2922
|
+
if (!n) return;
|
|
2923
|
+
const o = {
|
|
2648
2924
|
lockMovementX: !1,
|
|
2649
2925
|
lockMovementY: !1,
|
|
2650
2926
|
lockRotation: !1,
|
|
@@ -2654,10 +2930,10 @@ class X {
|
|
|
2654
2930
|
lockSkewingY: !1,
|
|
2655
2931
|
locked: !1
|
|
2656
2932
|
};
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
}), s.renderAll(), t ||
|
|
2660
|
-
object:
|
|
2933
|
+
n.set(o), Q._isGroupOrSelection(n) && n.getObjects().forEach((i) => {
|
|
2934
|
+
i.set(o);
|
|
2935
|
+
}), s.renderAll(), t || a.saveState(), s.fire("editor:object-unlocked", {
|
|
2936
|
+
object: n,
|
|
2661
2937
|
withoutSave: t
|
|
2662
2938
|
});
|
|
2663
2939
|
}
|
|
@@ -2665,7 +2941,7 @@ class X {
|
|
|
2665
2941
|
return e instanceof y || e instanceof J;
|
|
2666
2942
|
}
|
|
2667
2943
|
}
|
|
2668
|
-
class
|
|
2944
|
+
class Mt {
|
|
2669
2945
|
constructor({ editor: e }) {
|
|
2670
2946
|
this.editor = e;
|
|
2671
2947
|
}
|
|
@@ -2680,14 +2956,14 @@ class gt {
|
|
|
2680
2956
|
object: e,
|
|
2681
2957
|
withoutSave: t
|
|
2682
2958
|
} = {}) {
|
|
2683
|
-
const { canvas: s, historyManager:
|
|
2684
|
-
|
|
2685
|
-
const
|
|
2686
|
-
if (!
|
|
2687
|
-
const
|
|
2688
|
-
|
|
2689
|
-
object:
|
|
2690
|
-
group:
|
|
2959
|
+
const { canvas: s, historyManager: a } = this.editor;
|
|
2960
|
+
a.suspendHistory();
|
|
2961
|
+
const n = e || s.getActiveObject();
|
|
2962
|
+
if (!n || !(n instanceof y)) return;
|
|
2963
|
+
const o = n.getObjects(), i = new J(o);
|
|
2964
|
+
o.forEach((c) => s.remove(c)), i.set("id", `${i.type}-${v()}`), s.add(i), s.setActiveObject(i), s.renderAll(), a.resumeHistory(), t || a.saveState(), s.fire("editor:objects-grouped", {
|
|
2965
|
+
object: n,
|
|
2966
|
+
group: i,
|
|
2691
2967
|
withoutSave: t
|
|
2692
2968
|
});
|
|
2693
2969
|
}
|
|
@@ -2702,23 +2978,23 @@ class gt {
|
|
|
2702
2978
|
object: e,
|
|
2703
2979
|
withoutSave: t
|
|
2704
2980
|
} = {}) {
|
|
2705
|
-
const { canvas: s, historyManager:
|
|
2706
|
-
|
|
2707
|
-
const
|
|
2708
|
-
if (!(
|
|
2709
|
-
const
|
|
2710
|
-
s.remove(
|
|
2711
|
-
const
|
|
2981
|
+
const { canvas: s, historyManager: a } = this.editor;
|
|
2982
|
+
a.suspendHistory();
|
|
2983
|
+
const n = e || s.getActiveObject();
|
|
2984
|
+
if (!(n instanceof J)) return;
|
|
2985
|
+
const o = n.removeAll();
|
|
2986
|
+
s.remove(n), o.forEach((c) => s.add(c));
|
|
2987
|
+
const i = new y(o, {
|
|
2712
2988
|
canvas: s
|
|
2713
2989
|
});
|
|
2714
|
-
s.setActiveObject(
|
|
2715
|
-
object:
|
|
2716
|
-
selection:
|
|
2990
|
+
s.setActiveObject(i), s.renderAll(), a.resumeHistory(), t || a.saveState(), s.fire("editor:objects-ungrouped", {
|
|
2991
|
+
object: n,
|
|
2992
|
+
selection: i,
|
|
2717
2993
|
withoutSave: t
|
|
2718
2994
|
});
|
|
2719
2995
|
}
|
|
2720
2996
|
}
|
|
2721
|
-
class
|
|
2997
|
+
class ft {
|
|
2722
2998
|
constructor({ editor: e }) {
|
|
2723
2999
|
this.editor = e;
|
|
2724
3000
|
}
|
|
@@ -2729,11 +3005,11 @@ class ut {
|
|
|
2729
3005
|
selectAll() {
|
|
2730
3006
|
const { canvas: e, canvasManager: t, objectLockManager: s } = this.editor;
|
|
2731
3007
|
e.discardActiveObject();
|
|
2732
|
-
const
|
|
2733
|
-
|
|
3008
|
+
const a = t.getObjects(), n = a.some((i) => i.locked), o = a.length > 1 ? new y(t.getObjects(), { canvas: e }) : a[0];
|
|
3009
|
+
n && s.lockObject({ object: o, skipInnerObjects: !0, withoutSave: !0 }), e.setActiveObject(o), e.requestRenderAll(), e.fire("editor:all-objects-selected", { selected: o });
|
|
2734
3010
|
}
|
|
2735
3011
|
}
|
|
2736
|
-
class
|
|
3012
|
+
class mt {
|
|
2737
3013
|
constructor({ editor: e }) {
|
|
2738
3014
|
this.editor = e;
|
|
2739
3015
|
}
|
|
@@ -2748,20 +3024,20 @@ class Mt {
|
|
|
2748
3024
|
objects: e,
|
|
2749
3025
|
withoutSave: t
|
|
2750
3026
|
} = {}) {
|
|
2751
|
-
const { canvas: s, historyManager:
|
|
2752
|
-
|
|
2753
|
-
if (
|
|
2754
|
-
|
|
3027
|
+
const { canvas: s, historyManager: a, groupingManager: n } = this.editor, o = (e || s.getActiveObjects()).filter((i) => !i.locked);
|
|
3028
|
+
o != null && o.length && (a.suspendHistory(), o.forEach((i) => {
|
|
3029
|
+
if (i.type === "group" && i.format !== "svg") {
|
|
3030
|
+
n.ungroup({ object: i, withoutSave: t }), this.deleteSelectedObjects();
|
|
2755
3031
|
return;
|
|
2756
3032
|
}
|
|
2757
|
-
s.remove(
|
|
2758
|
-
}), s.discardActiveObject(), s.renderAll(),
|
|
2759
|
-
objects:
|
|
3033
|
+
s.remove(i);
|
|
3034
|
+
}), s.discardActiveObject(), s.renderAll(), a.resumeHistory(), t || a.saveState(), s.fire("editor:objects-deleted", {
|
|
3035
|
+
objects: o,
|
|
2760
3036
|
withoutSave: t
|
|
2761
3037
|
}));
|
|
2762
3038
|
}
|
|
2763
3039
|
}
|
|
2764
|
-
const
|
|
3040
|
+
const bt = {
|
|
2765
3041
|
IMAGE_MANAGER: {
|
|
2766
3042
|
/**
|
|
2767
3043
|
* Некорректный Content-Type изображения
|
|
@@ -2837,9 +3113,30 @@ const mt = {
|
|
|
2837
3113
|
HISTORY_MANAGER: {
|
|
2838
3114
|
UNDO_ERROR: "UNDO_ERROR",
|
|
2839
3115
|
REDO_ERROR: "REDO_ERROR"
|
|
3116
|
+
},
|
|
3117
|
+
/**
|
|
3118
|
+
* Коды ошибок и предупреждений для BackgroundManager.
|
|
3119
|
+
*/
|
|
3120
|
+
BACKGROUND_MANAGER: {
|
|
3121
|
+
/**
|
|
3122
|
+
* Ошибка создания фона.
|
|
3123
|
+
*/
|
|
3124
|
+
BACKGROUND_CREATION_FAILED: "BACKGROUND_CREATION_FAILED",
|
|
3125
|
+
/**
|
|
3126
|
+
* Ошибка удаления фона.
|
|
3127
|
+
*/
|
|
3128
|
+
BACKGROUND_REMOVAL_FAILED: "BACKGROUND_REMOVAL_FAILED",
|
|
3129
|
+
/**
|
|
3130
|
+
* Предупреждение об отсутствии фона для удаления.
|
|
3131
|
+
*/
|
|
3132
|
+
NO_BACKGROUND_TO_REMOVE: "NO_BACKGROUND_TO_REMOVE",
|
|
3133
|
+
/**
|
|
3134
|
+
* Ошибка парсинга градиента.
|
|
3135
|
+
*/
|
|
3136
|
+
INVALID_GRADIENT_FORMAT: "INVALID_GRADIENT_FORMAT"
|
|
2840
3137
|
}
|
|
2841
3138
|
};
|
|
2842
|
-
class
|
|
3139
|
+
class K {
|
|
2843
3140
|
constructor({ editor: e }) {
|
|
2844
3141
|
this._buffer = [], this.editor = e;
|
|
2845
3142
|
}
|
|
@@ -2865,24 +3162,24 @@ class Q {
|
|
|
2865
3162
|
* @param options.message — текст ошибки (опционально, если не передан, то используется код ошибки)
|
|
2866
3163
|
* @fires editor:error
|
|
2867
3164
|
*/
|
|
2868
|
-
emitError({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, data:
|
|
2869
|
-
if (!
|
|
3165
|
+
emitError({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, data: a, message: n }) {
|
|
3166
|
+
if (!K.isValidErrorCode(s)) {
|
|
2870
3167
|
console.warn("Неизвестный код ошибки: ", { code: s, origin: e, method: t });
|
|
2871
3168
|
return;
|
|
2872
3169
|
}
|
|
2873
3170
|
if (!s) return;
|
|
2874
|
-
const
|
|
2875
|
-
console.error(`${e}. ${t}. ${s}. ${
|
|
2876
|
-
const
|
|
3171
|
+
const o = n || s;
|
|
3172
|
+
console.error(`${e}. ${t}. ${s}. ${o}`, a);
|
|
3173
|
+
const i = {
|
|
2877
3174
|
code: s,
|
|
2878
3175
|
origin: e,
|
|
2879
3176
|
method: t,
|
|
2880
|
-
message:
|
|
2881
|
-
data:
|
|
3177
|
+
message: o,
|
|
3178
|
+
data: a
|
|
2882
3179
|
};
|
|
2883
3180
|
this._buffer.push(p({
|
|
2884
3181
|
type: "editor:error"
|
|
2885
|
-
},
|
|
3182
|
+
}, i)), this.editor.canvas.fire("editor:error", i);
|
|
2886
3183
|
}
|
|
2887
3184
|
/**
|
|
2888
3185
|
* Эмитит предупреждение через fabricjs
|
|
@@ -2894,23 +3191,23 @@ class Q {
|
|
|
2894
3191
|
* @param options.message — текст предупреждения (опционально, если не передан, то используется код предупреждения)
|
|
2895
3192
|
* @fires editor:warning
|
|
2896
3193
|
*/
|
|
2897
|
-
emitWarning({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, message:
|
|
2898
|
-
if (!
|
|
3194
|
+
emitWarning({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, message: a, data: n }) {
|
|
3195
|
+
if (!K.isValidErrorCode(s)) {
|
|
2899
3196
|
console.warn("Неизвестный код предупреждения: ", { code: s, origin: e, method: t });
|
|
2900
3197
|
return;
|
|
2901
3198
|
}
|
|
2902
|
-
const
|
|
2903
|
-
console.warn(`${e}. ${t}. ${s}. ${
|
|
2904
|
-
const
|
|
3199
|
+
const o = a || s;
|
|
3200
|
+
console.warn(`${e}. ${t}. ${s}. ${o}`, n);
|
|
3201
|
+
const i = {
|
|
2905
3202
|
code: s,
|
|
2906
3203
|
origin: e,
|
|
2907
3204
|
method: t,
|
|
2908
|
-
message:
|
|
2909
|
-
data:
|
|
3205
|
+
message: o,
|
|
3206
|
+
data: n
|
|
2910
3207
|
};
|
|
2911
3208
|
this._buffer.push(p({
|
|
2912
3209
|
type: "editor:warning"
|
|
2913
|
-
},
|
|
3210
|
+
}, i)), this.editor.canvas.fire("editor:warning", i);
|
|
2914
3211
|
}
|
|
2915
3212
|
/**
|
|
2916
3213
|
* Проверяет, является ли код ошибки или предупреждения допустимым
|
|
@@ -2918,17 +3215,17 @@ class Q {
|
|
|
2918
3215
|
* @returns true, если код допустим, иначе false
|
|
2919
3216
|
*/
|
|
2920
3217
|
static isValidErrorCode(e) {
|
|
2921
|
-
return e ? Object.values(
|
|
3218
|
+
return e ? Object.values(bt).some((t) => Object.values(t).includes(e)) : !1;
|
|
2922
3219
|
}
|
|
2923
3220
|
}
|
|
2924
|
-
class
|
|
3221
|
+
class ie {
|
|
2925
3222
|
/**
|
|
2926
3223
|
* Конструктор класса ImageEditor.
|
|
2927
3224
|
* @param canvasId - идентификатор канваса, в котором будет создан редактор
|
|
2928
3225
|
* @param options - опции и настройки редактора
|
|
2929
3226
|
*/
|
|
2930
3227
|
constructor(e, t) {
|
|
2931
|
-
this.options = t, this.containerId = e, this.editorId = `${e}-${
|
|
3228
|
+
this.options = t, this.containerId = e, this.editorId = `${e}-${v()}`, this.clipboard = null, this.init();
|
|
2932
3229
|
}
|
|
2933
3230
|
/**
|
|
2934
3231
|
* Инициализация редактора.
|
|
@@ -2936,29 +3233,29 @@ class ae {
|
|
|
2936
3233
|
* @fires editor:ready
|
|
2937
3234
|
*/
|
|
2938
3235
|
init() {
|
|
2939
|
-
return
|
|
3236
|
+
return b(this, null, function* () {
|
|
2940
3237
|
const {
|
|
2941
3238
|
editorContainerWidth: e,
|
|
2942
3239
|
editorContainerHeight: t,
|
|
2943
3240
|
canvasWrapperWidth: s,
|
|
2944
|
-
canvasWrapperHeight:
|
|
2945
|
-
canvasCSSWidth:
|
|
2946
|
-
canvasCSSHeight:
|
|
2947
|
-
initialImage:
|
|
2948
|
-
initialStateJSON:
|
|
2949
|
-
scaleType:
|
|
3241
|
+
canvasWrapperHeight: a,
|
|
3242
|
+
canvasCSSWidth: n,
|
|
3243
|
+
canvasCSSHeight: o,
|
|
3244
|
+
initialImage: i,
|
|
3245
|
+
initialStateJSON: c,
|
|
3246
|
+
scaleType: d,
|
|
2950
3247
|
_onReadyCallback: h
|
|
2951
3248
|
} = this.options;
|
|
2952
|
-
if (
|
|
3249
|
+
if (Ve.apply(), this.canvas = new Te(this.containerId, this.options), this.moduleLoader = new xe(), this.workerManager = new Ue(), this.errorManager = new K({ editor: this }), this.historyManager = new st({ editor: this }), this.toolbar = new tt({ editor: this }), this.transformManager = new lt({ editor: this }), this.canvasManager = new dt({ editor: this }), this.imageManager = new O({ editor: this }), this.layerManager = new X({ editor: this }), this.shapeManager = new gt({ editor: this }), this.interactionBlocker = new ht({ editor: this }), this.backgroundManager = new R({ editor: this }), this.clipboardManager = new ut({ editor: this }), this.objectLockManager = new Q({ editor: this }), this.groupingManager = new Mt({ editor: this }), this.selectionManager = new ft({ editor: this }), this.deletionManager = new mt({ 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(a), this.canvasManager.setCanvasCSSWidth(n), this.canvasManager.setCanvasCSSHeight(o), i != null && i.source) {
|
|
2953
3250
|
const {
|
|
2954
3251
|
source: l,
|
|
2955
|
-
scale: g = `image-${
|
|
3252
|
+
scale: g = `image-${d}`,
|
|
2956
3253
|
withoutSave: M = !0
|
|
2957
|
-
} =
|
|
3254
|
+
} = i;
|
|
2958
3255
|
yield this.imageManager.importImage({ source: l, scale: g, withoutSave: M });
|
|
2959
3256
|
} else
|
|
2960
3257
|
this.canvasManager.setDefaultScale({ withoutSave: !0 });
|
|
2961
|
-
|
|
3258
|
+
c && this.historyManager.loadStateFromFullState(c), this.historyManager.saveState(), console.log("editor:ready"), this.canvas.fire("editor:ready", this), typeof h == "function" && h(this);
|
|
2962
3259
|
});
|
|
2963
3260
|
}
|
|
2964
3261
|
/**
|
|
@@ -2972,7 +3269,7 @@ class ae {
|
|
|
2972
3269
|
this.montageArea = this.shapeManager.addRectangle({
|
|
2973
3270
|
width: e,
|
|
2974
3271
|
height: t,
|
|
2975
|
-
fill:
|
|
3272
|
+
fill: ie._createMosaicPattern(),
|
|
2976
3273
|
stroke: null,
|
|
2977
3274
|
strokeWidth: 0,
|
|
2978
3275
|
selectable: !1,
|
|
@@ -3028,7 +3325,7 @@ class ae {
|
|
|
3028
3325
|
});
|
|
3029
3326
|
}
|
|
3030
3327
|
}
|
|
3031
|
-
const
|
|
3328
|
+
const jt = {
|
|
3032
3329
|
/**
|
|
3033
3330
|
* Опции редактора
|
|
3034
3331
|
*/
|
|
@@ -3117,18 +3414,18 @@ const ft = {
|
|
|
3117
3414
|
resetObjectFitByDoubleClick: !0,
|
|
3118
3415
|
keyboardIgnoreSelectors: []
|
|
3119
3416
|
};
|
|
3120
|
-
function
|
|
3121
|
-
const t = p(p({},
|
|
3417
|
+
function St(r, e = {}) {
|
|
3418
|
+
const t = p(p({}, jt), e), s = document.getElementById(r);
|
|
3122
3419
|
if (!s)
|
|
3123
3420
|
return Promise.reject(new Error(`Контейнер с ID "${r}" не найден.`));
|
|
3124
|
-
const
|
|
3125
|
-
return
|
|
3126
|
-
t._onReadyCallback =
|
|
3127
|
-
const
|
|
3128
|
-
window[r] =
|
|
3421
|
+
const a = document.createElement("canvas");
|
|
3422
|
+
return a.id = `${r}-canvas`, s.appendChild(a), t.editorContainer = s, new Promise((n) => {
|
|
3423
|
+
t._onReadyCallback = n;
|
|
3424
|
+
const o = new ie(a.id, t);
|
|
3425
|
+
window[r] = o;
|
|
3129
3426
|
});
|
|
3130
3427
|
}
|
|
3131
3428
|
export {
|
|
3132
|
-
|
|
3429
|
+
St as default
|
|
3133
3430
|
};
|
|
3134
3431
|
//# sourceMappingURL=main.js.map
|