@anu3ev/fabric-image-editor 0.1.69 → 0.1.71
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 +692 -562
- package/package.json +2 -1
package/dist/main.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var ye = Object.defineProperty, Ie = Object.defineProperties;
|
|
2
|
+
var ve = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var Y = Object.getOwnPropertySymbols;
|
|
4
4
|
var le = Object.prototype.hasOwnProperty, he = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var de = (r, e, t) => e in r ?
|
|
5
|
+
var de = (r, e, t) => e in r ? ye(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
|
le.call(e, t) && de(r, t, e[t]);
|
|
8
8
|
if (Y)
|
|
9
9
|
for (var t of Y(e))
|
|
10
10
|
he.call(e, t) && de(r, t, e[t]);
|
|
11
11
|
return r;
|
|
12
|
-
}, ge = (r, e) =>
|
|
13
|
-
var
|
|
12
|
+
}, ge = (r, e) => Ie(r, ve(e));
|
|
13
|
+
var P = (r, e) => {
|
|
14
14
|
var t = {};
|
|
15
15
|
for (var s in r)
|
|
16
16
|
le.call(r, s) && e.indexOf(s) < 0 && (t[s] = r[s]);
|
|
@@ -19,31 +19,31 @@ var _ = (r, e) => {
|
|
|
19
19
|
e.indexOf(s) < 0 && he.call(r, s) && (t[s] = r[s]);
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
-
var
|
|
23
|
-
var
|
|
22
|
+
var j = (r, e, t) => new Promise((s, n) => {
|
|
23
|
+
var a = (d) => {
|
|
24
24
|
try {
|
|
25
25
|
o(t.next(d));
|
|
26
26
|
} catch (c) {
|
|
27
27
|
n(c);
|
|
28
28
|
}
|
|
29
|
-
},
|
|
29
|
+
}, i = (d) => {
|
|
30
30
|
try {
|
|
31
31
|
o(t.throw(d));
|
|
32
32
|
} catch (c) {
|
|
33
33
|
n(c);
|
|
34
34
|
}
|
|
35
|
-
}, o = (d) => d.done ? s(d.value) : Promise.resolve(d.value).then(
|
|
35
|
+
}, o = (d) => d.done ? s(d.value) : Promise.resolve(d.value).then(a, i);
|
|
36
36
|
o((t = t.apply(r, e)).next());
|
|
37
37
|
});
|
|
38
|
-
import { ActiveSelection as y, util as H, controlsUtils as
|
|
39
|
-
import { create as
|
|
40
|
-
import
|
|
41
|
-
var
|
|
38
|
+
import { ActiveSelection as y, util as H, controlsUtils as Ae, InteractiveFabricObject as Se, loadSVGFromURL as Ce, FabricImage as U, Point as F, Rect as De, Circle as Le, Triangle as Ne, Group as J, Canvas as Ee, Pattern as we } from "fabric";
|
|
39
|
+
import { create as Oe } from "jsondiffpatch";
|
|
40
|
+
import Te from "diff-match-patch";
|
|
41
|
+
var ke = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", D = 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 += ke[s[e] & 63];
|
|
44
44
|
return t;
|
|
45
45
|
};
|
|
46
|
-
class
|
|
46
|
+
class Z {
|
|
47
47
|
/**
|
|
48
48
|
* Конструктор принимает редактор и опции.
|
|
49
49
|
* @param params
|
|
@@ -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 =
|
|
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();
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Инициализация всех обработчиков согласно опциям.
|
|
@@ -72,14 +72,14 @@ class z {
|
|
|
72
72
|
canvasDragging: t,
|
|
73
73
|
mouseWheelZooming: s,
|
|
74
74
|
bringToFrontOnSelection: n,
|
|
75
|
-
copyObjectsByHotkey:
|
|
76
|
-
pasteImageFromClipboard:
|
|
75
|
+
copyObjectsByHotkey: a,
|
|
76
|
+
pasteImageFromClipboard: i,
|
|
77
77
|
undoRedoByHotKeys: o,
|
|
78
78
|
selectAllByHotkey: d,
|
|
79
79
|
deleteObjectsByHotkey: c,
|
|
80
|
-
resetObjectFitByDoubleClick:
|
|
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), n && (this.canvas.on("selection:created", this.handleBringToFrontBound), this.canvas.on("selection:updated", this.handleBringToFrontBound)),
|
|
82
|
+
t && (this.canvas.on("mouse:down", this.handleCanvasDragStartBound), this.canvas.on("mouse:move", this.handleCanvasDraggingBound), this.canvas.on("mouse:up", this.handleCanvasDragEndBound), document.addEventListener("keydown", this.handleSpaceKeyDownBound, { capture: !0 }), document.addEventListener("keyup", this.handleSpaceKeyUpBound, { capture: !0 })), s && this.canvas.on("mouse:wheel", this.handleMouseWheelZoomBound), n && (this.canvas.on("selection:created", this.handleBringToFrontBound), this.canvas.on("selection:updated", this.handleBringToFrontBound)), h && this.canvas.on("mouse:dblclick", this.handleResetObjectFitBound), e && window.addEventListener("resize", this.handleContainerResizeBound, { capture: !0 }), a && document.addEventListener("keydown", this.handleCopyEventBound, { capture: !0 }), i && document.addEventListener("paste", this.handlePasteEventBound, { capture: !0 }), o && (document.addEventListener("keydown", this.handleUndoRedoEventBound, { capture: !0 }), document.addEventListener("keyup", this.handleUndoRedoKeyUpBound, { capture: !0 })), d && document.addEventListener("keydown", this.handleSelectAllEventBound, { capture: !0 }), c && document.addEventListener("keydown", this.handleDeleteObjectsEventBound, { capture: !0 }), this.canvas.on("object:modified", this.handleObjectModifiedHistoryBound), this.canvas.on("object:rotating", this.handleObjectRotatingHistoryBound), this.canvas.on("object:added", this.handleObjectAddedHistoryBound), this.canvas.on("object:removed", this.handleObjectRemovedHistoryBound), this.canvas.on("object:added", this.handleOverlayUpdateBound), this.canvas.on("selection:created", this.handleOverlayUpdateBound), this.canvas.on("selection:created", this.handleLockedSelectionBound), this.canvas.on("selection:updated", this.handleLockedSelectionBound);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* При массовом выделении объектов удаляем из него залоченные.
|
|
@@ -90,7 +90,7 @@ class z {
|
|
|
90
90
|
_filterLockedSelection({ selected: e, e: t }) {
|
|
91
91
|
if (!(e != null && e.length) || !(t instanceof MouseEvent) || e.length === 1) return;
|
|
92
92
|
const { lockedObjects: s, unlockedObjects: n } = e.reduce(
|
|
93
|
-
(
|
|
93
|
+
(i, o) => o.locked ? (i.lockedObjects.push(o), i) : (i.unlockedObjects.push(o), i),
|
|
94
94
|
{ lockedObjects: [], unlockedObjects: [] }
|
|
95
95
|
);
|
|
96
96
|
if (s.length === 0) return;
|
|
@@ -98,22 +98,22 @@ class z {
|
|
|
98
98
|
if (n.length === 1)
|
|
99
99
|
this.canvas.setActiveObject(n[0]);
|
|
100
100
|
else {
|
|
101
|
-
const
|
|
101
|
+
const i = new y(n, {
|
|
102
102
|
canvas: this.canvas
|
|
103
103
|
});
|
|
104
|
-
this.canvas.setActiveObject(
|
|
104
|
+
this.canvas.setActiveObject(i);
|
|
105
105
|
}
|
|
106
106
|
this.canvas.requestRenderAll();
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const a = new y(e, {
|
|
110
110
|
canvas: this.canvas
|
|
111
111
|
});
|
|
112
112
|
this.editor.objectLockManager.lockObject({
|
|
113
|
-
object:
|
|
113
|
+
object: a,
|
|
114
114
|
skipInnerObjects: !0,
|
|
115
115
|
withoutSave: !0
|
|
116
|
-
}), this.canvas.setActiveObject(
|
|
116
|
+
}), this.canvas.setActiveObject(a), this.canvas.requestRenderAll();
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Обработчики для сохранения состояния редактора в истории.
|
|
@@ -172,9 +172,9 @@ class z {
|
|
|
172
172
|
* @param event.code — код клавиши
|
|
173
173
|
*/
|
|
174
174
|
handleUndoRedoEvent(e) {
|
|
175
|
-
return
|
|
176
|
-
const { ctrlKey: t, metaKey: s, code: n, repeat:
|
|
177
|
-
this._shouldIgnoreKeyboardEvent(e) || !t && !s ||
|
|
175
|
+
return j(this, null, function* () {
|
|
176
|
+
const { ctrlKey: t, metaKey: s, code: n, repeat: a } = e;
|
|
177
|
+
this._shouldIgnoreKeyboardEvent(e) || !t && !s || a || !/Mac/i.test(navigator.userAgent) && this.isUndoRedoKeyPressed || (n === "KeyZ" ? (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.undo()) : n === "KeyY" && (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.redo()));
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
@@ -213,11 +213,11 @@ class z {
|
|
|
213
213
|
*/
|
|
214
214
|
handleSpaceKeyDown(e) {
|
|
215
215
|
if (e.code !== "Space" || this._shouldIgnoreKeyboardEvent(e)) return;
|
|
216
|
-
const { canvas: t, editor: s, isSpacePressed: n, isDragging:
|
|
217
|
-
if (n ||
|
|
216
|
+
const { canvas: t, editor: s, isSpacePressed: n, isDragging: a } = this;
|
|
217
|
+
if (n || a) return;
|
|
218
218
|
this.isSpacePressed = !0, e.preventDefault();
|
|
219
|
-
const
|
|
220
|
-
|
|
219
|
+
const i = t.getActiveObject() || null;
|
|
220
|
+
i instanceof y ? this.savedSelection = i.getObjects().slice() : i && (this.savedSelection = [i]), t.discardActiveObject(), t.set({
|
|
221
221
|
selection: !1,
|
|
222
222
|
defaultCursor: "grab"
|
|
223
223
|
}), t.setCursor("grab"), s.canvasManager.getObjects().forEach((o) => {
|
|
@@ -256,8 +256,8 @@ class z {
|
|
|
256
256
|
t.setActiveObject(e[0]);
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
259
|
-
const n = e.filter((
|
|
260
|
-
t.setActiveObject(
|
|
259
|
+
const n = e.filter((i) => s.canvasManager.getObjects().includes(i)), a = new y(n, { canvas: t });
|
|
260
|
+
t.setActiveObject(a);
|
|
261
261
|
}
|
|
262
262
|
// --- Обработчики для событий canvas (Fabric) ---
|
|
263
263
|
/**
|
|
@@ -313,7 +313,7 @@ class z {
|
|
|
313
313
|
*/
|
|
314
314
|
handleResetObjectFit(e) {
|
|
315
315
|
const t = e == null ? void 0 : e.target;
|
|
316
|
-
t && this.editor.transformManager.resetObject(t);
|
|
316
|
+
t && this.editor.transformManager.resetObject({ object: t });
|
|
317
317
|
}
|
|
318
318
|
/**
|
|
319
319
|
* Проверяет, должно ли событие клавиатуры быть проигнорировано
|
|
@@ -326,18 +326,18 @@ class z {
|
|
|
326
326
|
if (!t) return !1;
|
|
327
327
|
const s = ["input", "textarea", "select"], n = t.tagName.toLowerCase();
|
|
328
328
|
if (s.includes(n) || t.contentEditable === "true") return !0;
|
|
329
|
-
const { keyboardIgnoreSelectors:
|
|
330
|
-
if (
|
|
331
|
-
for (const
|
|
329
|
+
const { keyboardIgnoreSelectors: a } = this.options;
|
|
330
|
+
if (a != null && a.length)
|
|
331
|
+
for (const i of a)
|
|
332
332
|
try {
|
|
333
|
-
if (t.matches && t.matches(
|
|
333
|
+
if (t.matches && t.matches(i) || t.closest && t.closest(i))
|
|
334
334
|
return !0;
|
|
335
335
|
} catch (o) {
|
|
336
336
|
this.editor.errorManager.emitWarning({
|
|
337
337
|
origin: "Listeners",
|
|
338
338
|
method: "_shouldIgnoreKeyboardEvent",
|
|
339
339
|
code: "INVALID_SELECTOR",
|
|
340
|
-
message: `Invalid keyboard ignore selector: "${
|
|
340
|
+
message: `Invalid keyboard ignore selector: "${i}". Error: ${o.message}`,
|
|
341
341
|
data: o
|
|
342
342
|
});
|
|
343
343
|
}
|
|
@@ -364,7 +364,7 @@ class z {
|
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
|
-
class
|
|
367
|
+
class xe {
|
|
368
368
|
/**
|
|
369
369
|
* Класс для динамической загрузки внешних модулей.
|
|
370
370
|
*/
|
|
@@ -382,7 +382,7 @@ class ke {
|
|
|
382
382
|
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}"`));
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
-
function
|
|
385
|
+
function Be(r) {
|
|
386
386
|
return new Worker(
|
|
387
387
|
"" + new URL("assets/worker-CN39s7P7.js", import.meta.url).href,
|
|
388
388
|
{
|
|
@@ -390,13 +390,13 @@ function xe(r) {
|
|
|
390
390
|
}
|
|
391
391
|
);
|
|
392
392
|
}
|
|
393
|
-
class
|
|
393
|
+
class _e {
|
|
394
394
|
/**
|
|
395
395
|
* @param scriptUrl — URL скрипта воркера.
|
|
396
396
|
* По-умолчанию использует DefaultWorker из соседнего файла
|
|
397
397
|
*/
|
|
398
398
|
constructor(e) {
|
|
399
|
-
e ? this.worker = new Worker(e, { type: "module" }) : this.worker = new
|
|
399
|
+
e ? this.worker = new Worker(e, { type: "module" }) : this.worker = new Be(), this._callbacks = /* @__PURE__ */ new Map(), this.worker.onmessage = this._handleMessage.bind(this);
|
|
400
400
|
}
|
|
401
401
|
/**
|
|
402
402
|
* Обработчик сообщений от воркера
|
|
@@ -409,12 +409,12 @@ class Be {
|
|
|
409
409
|
* @returns
|
|
410
410
|
*/
|
|
411
411
|
_handleMessage({ data: e }) {
|
|
412
|
-
const { requestId: t, success: s, data: n, error:
|
|
413
|
-
if (!
|
|
412
|
+
const { requestId: t, success: s, data: n, error: a } = e, i = this._callbacks.get(t);
|
|
413
|
+
if (!i) {
|
|
414
414
|
console.warn(`No callback found for requestId: ${t}`);
|
|
415
415
|
return;
|
|
416
416
|
}
|
|
417
|
-
s ?
|
|
417
|
+
s ? i.resolve(n) : i.reject(new Error(a)), this._callbacks.delete(t);
|
|
418
418
|
}
|
|
419
419
|
/**
|
|
420
420
|
* Универсальный метод отправки команды в воркер
|
|
@@ -424,9 +424,9 @@ class Be {
|
|
|
424
424
|
* @returns Promise, который будет выполнен, когда воркер вернет ответ
|
|
425
425
|
*/
|
|
426
426
|
post(e, t, s = []) {
|
|
427
|
-
const n = `${e}:${
|
|
428
|
-
return new Promise((
|
|
429
|
-
this._callbacks.set(n, { resolve:
|
|
427
|
+
const n = `${e}:${D(8)}`;
|
|
428
|
+
return new Promise((a, i) => {
|
|
429
|
+
this._callbacks.set(n, { resolve: a, reject: i }), this.worker.postMessage({ action: e, payload: t, requestId: n }, s);
|
|
430
430
|
});
|
|
431
431
|
}
|
|
432
432
|
/**
|
|
@@ -436,26 +436,26 @@ class Be {
|
|
|
436
436
|
this.worker.terminate();
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
const N = 12,
|
|
439
|
+
const N = 12, Re = 2, K = 8, q = 20, Ue = 100, ee = 20, te = 8, ze = 100, V = 32, se = 1, Ze = "#2B2D33", ne = "#3D8BF4", ae = "#FFFFFF";
|
|
440
440
|
function W(r, e, t, s, n) {
|
|
441
|
-
const
|
|
442
|
-
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle =
|
|
441
|
+
const a = N, i = Re;
|
|
442
|
+
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle = ae, r.strokeStyle = ne, r.lineWidth = se, r.beginPath(), r.roundRect(-a / 2, -a / 2, a, a, i), r.fill(), r.stroke(), r.restore();
|
|
443
443
|
}
|
|
444
444
|
function ue(r, e, t, s, n) {
|
|
445
|
-
const
|
|
446
|
-
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle =
|
|
445
|
+
const a = K, i = q, o = Ue;
|
|
446
|
+
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle = ae, r.strokeStyle = ne, r.lineWidth = se, r.beginPath(), r.roundRect(-a / 2, -i / 2, a, i, o), r.fill(), r.stroke(), r.restore();
|
|
447
447
|
}
|
|
448
448
|
function Me(r, e, t, s, n) {
|
|
449
|
-
const
|
|
450
|
-
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle =
|
|
449
|
+
const a = ee, i = te, o = ze;
|
|
450
|
+
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle = ae, r.strokeStyle = ne, r.lineWidth = se, r.beginPath(), r.roundRect(-a / 2, -i / 2, a, i, o), r.fill(), r.stroke(), r.restore();
|
|
451
451
|
}
|
|
452
|
-
const He = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+",
|
|
453
|
-
|
|
452
|
+
const He = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", je = new Image();
|
|
453
|
+
je.src = He;
|
|
454
454
|
function Ye(r, e, t, s, n) {
|
|
455
|
-
const
|
|
456
|
-
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle =
|
|
455
|
+
const i = V / 2;
|
|
456
|
+
r.save(), r.translate(e, t), r.rotate(H.degreesToRadians(n.angle)), r.fillStyle = Ze, r.beginPath(), r.arc(0, 0, i, 0, 2 * Math.PI), r.fill(), r.drawImage(je, -i / 2, -i / 2, i, i), r.restore();
|
|
457
457
|
}
|
|
458
|
-
const
|
|
458
|
+
const Pe = {
|
|
459
459
|
// Угловые точки
|
|
460
460
|
tl: {
|
|
461
461
|
render: W,
|
|
@@ -518,30 +518,30 @@ const _e = {
|
|
|
518
518
|
// Специальный «rotate» контрол
|
|
519
519
|
mtr: {
|
|
520
520
|
render: Ye,
|
|
521
|
-
sizeX:
|
|
522
|
-
sizeY:
|
|
521
|
+
sizeX: V,
|
|
522
|
+
sizeY: V,
|
|
523
523
|
offsetX: 0,
|
|
524
|
-
offsetY: -
|
|
524
|
+
offsetY: -V
|
|
525
525
|
}
|
|
526
526
|
};
|
|
527
527
|
class We {
|
|
528
528
|
static apply() {
|
|
529
|
-
const e =
|
|
530
|
-
Object.entries(
|
|
529
|
+
const e = Ae.createObjectDefaultControls();
|
|
530
|
+
Object.entries(Pe).forEach(([t, s]) => {
|
|
531
531
|
Object.assign(e[t], {
|
|
532
532
|
render: s.render,
|
|
533
533
|
sizeX: s.sizeX,
|
|
534
534
|
sizeY: s.sizeY,
|
|
535
535
|
offsetX: s.offsetX,
|
|
536
536
|
offsetY: s.offsetY
|
|
537
|
-
}), t === "mtr" && (e[t].cursorStyle = "grab", e[t].mouseDownHandler = (
|
|
538
|
-
var
|
|
539
|
-
(
|
|
537
|
+
}), t === "mtr" && (e[t].cursorStyle = "grab", e[t].mouseDownHandler = (a, i, o, d) => {
|
|
538
|
+
var h;
|
|
539
|
+
(h = i.target.canvas) == null || h.setCursor("grabbing");
|
|
540
540
|
});
|
|
541
|
-
}),
|
|
541
|
+
}), Se.ownDefaults.controls = e;
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
|
-
const
|
|
544
|
+
const Fe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNNi44NzUgMi41YS42MjUuNjI1IDAgMCAwLS42MjUuNjI0VjYuMjVIMy4x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NEU0MCIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNOC4xMjUgMS4yNUExLjg3NSAxLjg3NSAwIDAgMCA2LjI1IDMuMTI1di42MjVIMy4xMjVhLjYyNS42MjUgMCAwIDAgMCAxLjI1aC42MjV2MTEuMjVBMS4yNSAxLjI1IDAgMCAwIDUgMTcuNWgxMGExLjI1IDEuMjUgMCAwIDAgMS4yNS0xLjI1VjVoLjYyNWEuNjI1LjYyNSAwIDAgMCAwLTEuMjVIMTMuNzV2LS42MjVhMS44NzUgMS44NzUgMCAwIDAtMS44NzUtMS44NzVoLTMuNzVabTQuMzc1IDIuNXYtLjYyNWEuNjI1LjYyNSAwIDAgMC0uNjI1LS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDAtLjYyNS42MjV2LjYyNWg1Wk01IDE2LjI1VjVoMTB2MTEuMjVINVpNOC4xMjUgNy41Yy4zNDUgMCAuNjI1LjI4LjYyNS42MjV2NWEuNjI1LjYyNSAwIDEgMS0xLjI1IDB2LTVjMC0uMzQ1LjI4LS42MjUuNjI1LS42MjVabTQuMzc1IDUuNjI1di01YS42MjUuNjI1IDAgMCAwLTEuMjUgMHY1YS42MjUuNjI1IDAgMSAwIDEuMjUgMFoiIGNsaXAtcnVsZT0iZXZlbm9kZCIvPjwvc3ZnPg==", z = {
|
|
545
545
|
style: {
|
|
546
546
|
position: "absolute",
|
|
547
547
|
display: "none",
|
|
@@ -608,20 +608,18 @@ const Pe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj
|
|
|
608
608
|
],
|
|
609
609
|
offsetTop: 50,
|
|
610
610
|
icons: {
|
|
611
|
-
copyPaste:
|
|
612
|
-
delete:
|
|
613
|
-
lock:
|
|
614
|
-
unlock:
|
|
615
|
-
bringToFront:
|
|
616
|
-
sendToBack:
|
|
617
|
-
bringForward:
|
|
618
|
-
sendBackwards:
|
|
611
|
+
copyPaste: Fe,
|
|
612
|
+
delete: Ke,
|
|
613
|
+
lock: Ve,
|
|
614
|
+
unlock: Ge,
|
|
615
|
+
bringToFront: $e,
|
|
616
|
+
sendToBack: Je,
|
|
617
|
+
bringForward: Xe,
|
|
618
|
+
sendBackwards: Qe
|
|
619
619
|
},
|
|
620
620
|
handlers: {
|
|
621
|
-
copyPaste: (r) =>
|
|
622
|
-
|
|
623
|
-
object: r.clipboardManager.clipboard
|
|
624
|
-
});
|
|
621
|
+
copyPaste: (r) => j(null, null, function* () {
|
|
622
|
+
r.clipboardManager.copyPaste();
|
|
625
623
|
}),
|
|
626
624
|
delete: (r) => {
|
|
627
625
|
r.deletionManager.deleteSelectedObjects();
|
|
@@ -646,18 +644,18 @@ const Pe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj
|
|
|
646
644
|
}
|
|
647
645
|
}
|
|
648
646
|
};
|
|
649
|
-
class
|
|
647
|
+
class qe {
|
|
650
648
|
constructor({ editor: e }) {
|
|
651
649
|
this.currentTarget = null, this.currentLocked = !1, this.isTransforming = !1, this.editor = e, this.canvas = e.canvas, this.options = e.options, this._initToolbar();
|
|
652
650
|
}
|
|
653
651
|
_initToolbar() {
|
|
654
652
|
if (!this.options.showToolbar) return;
|
|
655
653
|
const e = this.options.toolbar || {};
|
|
656
|
-
this.config = ge(p(p({},
|
|
657
|
-
style: p(p({},
|
|
658
|
-
btnStyle: p(p({},
|
|
659
|
-
icons: p(p({},
|
|
660
|
-
handlers: p(p({},
|
|
654
|
+
this.config = ge(p(p({}, z), e), {
|
|
655
|
+
style: p(p({}, z.style), e.style || {}),
|
|
656
|
+
btnStyle: p(p({}, z.btnStyle), e.btnStyle || {}),
|
|
657
|
+
icons: p(p({}, z.icons), e.icons || {}),
|
|
658
|
+
handlers: p(p({}, z.handlers), e.handlers || {})
|
|
661
659
|
}), this.currentTarget = null, this.currentLocked = !1, this.isTransforming = !1, this._onMouseDown = this._handleMouseDown.bind(this), this._onObjectMoving = this._startTransform.bind(this), this._onObjectScaling = this._startTransform.bind(this), this._onObjectRotating = this._startTransform.bind(this), this._onMouseUp = this._endTransform.bind(this), this._onObjectModified = this._endTransform.bind(this), this._onSelectionChange = this._updateToolbar.bind(this), this._onSelectionClear = () => {
|
|
662
660
|
this.el.style.display = "none";
|
|
663
661
|
}, this._createDOM(), this._bindEvents();
|
|
@@ -684,8 +682,8 @@ class Ke {
|
|
|
684
682
|
_renderButtons(e) {
|
|
685
683
|
this.el.innerHTML = "";
|
|
686
684
|
for (const t of e) {
|
|
687
|
-
const { name: s, handle: n } = t, { icons:
|
|
688
|
-
d.innerHTML =
|
|
685
|
+
const { name: s, handle: n } = t, { icons: a = {}, btnStyle: i, handlers: o = {} } = this.config, d = document.createElement("button");
|
|
686
|
+
d.innerHTML = a[n] ? `<img src="${a[n]}" title="${s}" />` : s, Object.assign(d.style, i), d.onclick = () => {
|
|
689
687
|
var c;
|
|
690
688
|
return (c = o[n]) == null ? void 0 : c.call(o, this.editor);
|
|
691
689
|
}, d.onmousedown = (c) => {
|
|
@@ -748,10 +746,10 @@ class Ke {
|
|
|
748
746
|
}
|
|
749
747
|
const { el: t, config: s, canvas: n } = this;
|
|
750
748
|
e.setCoords();
|
|
751
|
-
const
|
|
749
|
+
const a = n.getZoom(), [, , , , i, o] = n.viewportTransform, { x: d } = e.getCenterPoint(), { top: c, height: h } = e.getBoundingRect(), g = d * a + i - t.offsetWidth / 2, M = s.offsetTop || 0, f = (c + h) * a + o + M;
|
|
752
750
|
Object.assign(t.style, {
|
|
753
751
|
left: `${g}px`,
|
|
754
|
-
top: `${
|
|
752
|
+
top: `${f}px`,
|
|
755
753
|
display: "flex"
|
|
756
754
|
});
|
|
757
755
|
}
|
|
@@ -762,7 +760,7 @@ class Ke {
|
|
|
762
760
|
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();
|
|
763
761
|
}
|
|
764
762
|
}
|
|
765
|
-
class
|
|
763
|
+
class et {
|
|
766
764
|
constructor({ editor: e }) {
|
|
767
765
|
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();
|
|
768
766
|
}
|
|
@@ -774,7 +772,7 @@ class qe {
|
|
|
774
772
|
return this.patches[this.currentIndex - 1] || null;
|
|
775
773
|
}
|
|
776
774
|
_createDiffPatcher() {
|
|
777
|
-
this.diffPatcher =
|
|
775
|
+
this.diffPatcher = Oe({
|
|
778
776
|
objectHash(e) {
|
|
779
777
|
const t = e;
|
|
780
778
|
return [
|
|
@@ -798,7 +796,7 @@ class qe {
|
|
|
798
796
|
includeValueOnMove: !1
|
|
799
797
|
},
|
|
800
798
|
textDiff: {
|
|
801
|
-
diffMatchPatch:
|
|
799
|
+
diffMatchPatch: Te,
|
|
802
800
|
minLength: 60
|
|
803
801
|
}
|
|
804
802
|
});
|
|
@@ -829,8 +827,8 @@ class qe {
|
|
|
829
827
|
getFullState() {
|
|
830
828
|
const { baseState: e, currentIndex: t, patches: s } = this;
|
|
831
829
|
let n = JSON.parse(JSON.stringify(e));
|
|
832
|
-
for (let
|
|
833
|
-
n = this.diffPatcher.patch(n, s[
|
|
830
|
+
for (let a = 0; a < t; a += 1)
|
|
831
|
+
n = this.diffPatcher.patch(n, s[a].diff);
|
|
834
832
|
return console.log("getFullState state", n), n;
|
|
835
833
|
}
|
|
836
834
|
/**
|
|
@@ -864,7 +862,7 @@ class qe {
|
|
|
864
862
|
console.log("Нет изменений для сохранения.");
|
|
865
863
|
return;
|
|
866
864
|
}
|
|
867
|
-
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:
|
|
865
|
+
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: D(), 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);
|
|
868
866
|
}
|
|
869
867
|
/**
|
|
870
868
|
* Функция загрузки состояния в канвас.
|
|
@@ -872,13 +870,13 @@ class qe {
|
|
|
872
870
|
* @fires editor:history-state-loaded
|
|
873
871
|
*/
|
|
874
872
|
loadStateFromFullState(e) {
|
|
875
|
-
return
|
|
873
|
+
return j(this, null, function* () {
|
|
876
874
|
if (!e) return;
|
|
877
875
|
console.log("loadStateFromFullState fullState", e);
|
|
878
|
-
const { canvas: t, canvasManager: s, interactionBlocker: n } = this.editor, { width:
|
|
876
|
+
const { canvas: t, canvasManager: s, interactionBlocker: n } = this.editor, { width: a, height: i } = t;
|
|
879
877
|
yield t.loadFromJSON(e);
|
|
880
878
|
const o = t.getObjects().find((c) => c.id === "montage-area");
|
|
881
|
-
o && (this.editor.montageArea = o, (
|
|
879
|
+
o && (this.editor.montageArea = o, (a !== t.getWidth() || i !== t.getHeight()) && s.updateCanvas());
|
|
882
880
|
const d = t.getObjects().find((c) => c.id === "overlay-mask");
|
|
883
881
|
d && (n.overlayMask = d, n.overlayMask.visible = !1), t.renderAll(), t.fire("editor:history-state-loaded", {
|
|
884
882
|
fullState: e,
|
|
@@ -895,7 +893,7 @@ class qe {
|
|
|
895
893
|
* @fires editor:undo
|
|
896
894
|
*/
|
|
897
895
|
undo() {
|
|
898
|
-
return
|
|
896
|
+
return j(this, null, function* () {
|
|
899
897
|
if (!this.skipHistory) {
|
|
900
898
|
if (this.currentIndex <= 0) {
|
|
901
899
|
console.log("Нет предыдущих состояний для отмены.");
|
|
@@ -932,7 +930,7 @@ class qe {
|
|
|
932
930
|
* @fires editor:redo
|
|
933
931
|
*/
|
|
934
932
|
redo() {
|
|
935
|
-
return
|
|
933
|
+
return j(this, null, function* () {
|
|
936
934
|
if (!this.skipHistory) {
|
|
937
935
|
if (this.currentIndex >= this.patches.length) {
|
|
938
936
|
console.log("Нет состояний для повтора.");
|
|
@@ -965,8 +963,8 @@ class qe {
|
|
|
965
963
|
});
|
|
966
964
|
}
|
|
967
965
|
}
|
|
968
|
-
const
|
|
969
|
-
class
|
|
966
|
+
const tt = 0.1, st = 2, nt = 0.1, at = 90, _ = 16, R = 16, O = 4096, T = 4096, me = "application/image-editor:";
|
|
967
|
+
class E {
|
|
970
968
|
constructor({ editor: e }) {
|
|
971
969
|
this.editor = e, this.options = e.options, this._createdBlobUrls = [], this.acceptContentTypes = this.editor.options.acceptContentTypes, this.acceptFormats = this.getAllowedFormatsFromContentTypes();
|
|
972
970
|
}
|
|
@@ -983,81 +981,83 @@ class D {
|
|
|
983
981
|
* @returns возвращает Promise с объектом изображения или null в случае ошибки
|
|
984
982
|
*/
|
|
985
983
|
importImage(e) {
|
|
986
|
-
return
|
|
984
|
+
return j(this, null, function* () {
|
|
987
985
|
const {
|
|
988
986
|
source: t,
|
|
989
987
|
scale: s = `image-${this.options.scaleType}`,
|
|
990
|
-
withoutSave: n = !1
|
|
988
|
+
withoutSave: n = !1,
|
|
989
|
+
fromClipboard: a = !1
|
|
991
990
|
} = e;
|
|
992
991
|
if (!t) return null;
|
|
993
|
-
const { canvas: i, montageArea:
|
|
992
|
+
const { canvas: i, montageArea: o, transformManager: d, historyManager: c, errorManager: h } = this.editor, l = yield this.getContentType(t), g = E.getFormatFromContentType(l), { acceptContentTypes: M, acceptFormats: f } = this;
|
|
994
993
|
if (!this.isAllowedContentType(l)) {
|
|
995
994
|
const m = `Неверный contentType для изображения: ${l}. Ожидается один из: ${this.acceptContentTypes.join(", ")}.`;
|
|
996
|
-
return
|
|
995
|
+
return h.emitError({
|
|
997
996
|
origin: "ImageManager",
|
|
998
997
|
method: "importImage",
|
|
999
998
|
code: "INVALID_CONTENT_TYPE",
|
|
1000
999
|
message: m,
|
|
1001
|
-
data: { source: t, format:
|
|
1000
|
+
data: { source: t, format: g, contentType: l, acceptContentTypes: M, acceptFormats: f, fromClipboard: a }
|
|
1002
1001
|
}), null;
|
|
1003
1002
|
}
|
|
1004
|
-
|
|
1003
|
+
c.suspendHistory();
|
|
1005
1004
|
try {
|
|
1006
|
-
let m,
|
|
1005
|
+
let m, u;
|
|
1007
1006
|
if (t instanceof File)
|
|
1008
1007
|
m = URL.createObjectURL(t);
|
|
1009
1008
|
else if (typeof t == "string") {
|
|
1010
|
-
const
|
|
1011
|
-
m = URL.createObjectURL(
|
|
1009
|
+
const C = yield (yield fetch(t, { mode: "cors" })).blob();
|
|
1010
|
+
m = URL.createObjectURL(C);
|
|
1012
1011
|
} else
|
|
1013
|
-
return
|
|
1012
|
+
return h.emitError({
|
|
1014
1013
|
origin: "ImageManager",
|
|
1015
1014
|
method: "importImage",
|
|
1016
1015
|
code: "INVALID_SOURCE_TYPE",
|
|
1017
1016
|
message: "Неверный тип источника изображения. Ожидается URL или объект File.",
|
|
1018
|
-
data: { source: t, format:
|
|
1017
|
+
data: { source: t, format: g, contentType: l, acceptContentTypes: M, acceptFormats: f, fromClipboard: a }
|
|
1019
1018
|
}), null;
|
|
1020
|
-
if (this._createdBlobUrls.push(m),
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1019
|
+
if (this._createdBlobUrls.push(m), g === "svg") {
|
|
1020
|
+
const v = yield Ce(m);
|
|
1021
|
+
u = H.groupSVGElements(v.objects, v.options);
|
|
1023
1022
|
} else
|
|
1024
|
-
|
|
1025
|
-
const { width:
|
|
1026
|
-
if (
|
|
1027
|
-
const
|
|
1028
|
-
let
|
|
1029
|
-
if (
|
|
1030
|
-
const w = yield this.resizeImageToBoundaries(
|
|
1031
|
-
this._createdBlobUrls.push(
|
|
1032
|
-
} else if (
|
|
1033
|
-
const w = yield this.resizeImageToBoundaries(
|
|
1034
|
-
this._createdBlobUrls.push(
|
|
1023
|
+
u = yield U.fromURL(m, { crossOrigin: "anonymous" });
|
|
1024
|
+
const { width: b, height: A } = u;
|
|
1025
|
+
if (u instanceof U) {
|
|
1026
|
+
const v = u.getElement();
|
|
1027
|
+
let C = "";
|
|
1028
|
+
if (v instanceof HTMLImageElement ? C = v.src : v instanceof HTMLCanvasElement && (C = v.toDataURL()), A > T || b > O) {
|
|
1029
|
+
const w = yield this.resizeImageToBoundaries(C, "max"), k = URL.createObjectURL(w);
|
|
1030
|
+
this._createdBlobUrls.push(k), u = yield U.fromURL(k, { crossOrigin: "anonymous" });
|
|
1031
|
+
} else if (A < R || b < _) {
|
|
1032
|
+
const w = yield this.resizeImageToBoundaries(C, "min"), k = URL.createObjectURL(w);
|
|
1033
|
+
this._createdBlobUrls.push(k), u = yield U.fromURL(k, { crossOrigin: "anonymous" });
|
|
1035
1034
|
}
|
|
1036
1035
|
}
|
|
1037
|
-
if (
|
|
1038
|
-
this.editor.canvasManager.scaleMontageAreaToImage({ object:
|
|
1036
|
+
if (u.set("id", `${u.type}-${D()}`), u.set("format", g), s === "scale-montage")
|
|
1037
|
+
this.editor.canvasManager.scaleMontageAreaToImage({ object: u, withoutSave: !0 });
|
|
1039
1038
|
else {
|
|
1040
|
-
const { width:
|
|
1041
|
-
s === "image-contain" && w < 1 ?
|
|
1039
|
+
const { width: v, height: C } = o, w = this.calculateScaleFactor({ imageObject: u, scaleType: s });
|
|
1040
|
+
s === "image-contain" && w < 1 ? d.fitObject({ object: u, type: "contain", withoutSave: !0 }) : s === "image-cover" && (b > v || A > C) && d.fitObject({ object: u, type: "cover", withoutSave: !0 });
|
|
1042
1041
|
}
|
|
1043
|
-
i.add(
|
|
1044
|
-
const
|
|
1045
|
-
image:
|
|
1046
|
-
format:
|
|
1042
|
+
i.add(u), i.centerObject(u), i.setActiveObject(u), i.renderAll(), c.resumeHistory(), n || c.saveState();
|
|
1043
|
+
const S = {
|
|
1044
|
+
image: u,
|
|
1045
|
+
format: g,
|
|
1047
1046
|
contentType: l,
|
|
1048
1047
|
scale: s,
|
|
1049
1048
|
withoutSave: n,
|
|
1050
|
-
source: t
|
|
1049
|
+
source: t,
|
|
1050
|
+
fromClipboard: a
|
|
1051
1051
|
};
|
|
1052
|
-
return i.fire("editor:image-imported",
|
|
1052
|
+
return i.fire("editor:image-imported", S), S;
|
|
1053
1053
|
} catch (m) {
|
|
1054
|
-
return
|
|
1054
|
+
return h.emitError({
|
|
1055
1055
|
origin: "ImageManager",
|
|
1056
1056
|
method: "importImage",
|
|
1057
1057
|
code: "IMPORT_FAILED",
|
|
1058
1058
|
message: `Ошибка импорта изображения: ${m.message}`,
|
|
1059
|
-
data: { source: t, format:
|
|
1060
|
-
}),
|
|
1059
|
+
data: { source: t, format: g, contentType: l, scale: s, withoutSave: n, fromClipboard: a }
|
|
1060
|
+
}), c.resumeHistory(), null;
|
|
1061
1061
|
}
|
|
1062
1062
|
});
|
|
1063
1063
|
}
|
|
@@ -1070,16 +1070,16 @@ class D {
|
|
|
1070
1070
|
* @returns возвращает Promise с Blob-объектом уменьшенного изображения
|
|
1071
1071
|
*/
|
|
1072
1072
|
resizeImageToBoundaries(e, t = "max") {
|
|
1073
|
-
return
|
|
1073
|
+
return j(this, null, function* () {
|
|
1074
1074
|
let s = `Размер изображения больше максимального размера канваса, поэтому оно будет уменьшено до максимальных размеров c сохранением пропорций: ${O}x${T}`;
|
|
1075
|
-
t === "min" && (s = `Размер изображения меньше минимального размера канваса, поэтому оно будет увеличено до минимальных размеров c сохранением пропорций: ${
|
|
1075
|
+
t === "min" && (s = `Размер изображения меньше минимального размера канваса, поэтому оно будет увеличено до минимальных размеров c сохранением пропорций: ${_}x${R}`);
|
|
1076
1076
|
const n = {
|
|
1077
1077
|
dataURL: e,
|
|
1078
1078
|
sizeType: t,
|
|
1079
1079
|
maxWidth: O,
|
|
1080
1080
|
maxHeight: T,
|
|
1081
|
-
minWidth:
|
|
1082
|
-
minHeight:
|
|
1081
|
+
minWidth: _,
|
|
1082
|
+
minHeight: R
|
|
1083
1083
|
};
|
|
1084
1084
|
return this.editor.errorManager.emitWarning({
|
|
1085
1085
|
origin: "ImageManager",
|
|
@@ -1102,101 +1102,101 @@ class D {
|
|
|
1102
1102
|
* @fires editor:canvas-exported
|
|
1103
1103
|
*/
|
|
1104
1104
|
exportCanvasAsImageFile() {
|
|
1105
|
-
return
|
|
1105
|
+
return j(this, arguments, function* (e = {}) {
|
|
1106
1106
|
const {
|
|
1107
1107
|
fileName: t = "image.png",
|
|
1108
1108
|
contentType: s = "image/png",
|
|
1109
1109
|
exportAsBase64: n = !1,
|
|
1110
|
-
exportAsBlob:
|
|
1111
|
-
} = e, { canvas:
|
|
1110
|
+
exportAsBlob: a = !1
|
|
1111
|
+
} = e, { canvas: i, montageArea: o, workerManager: d } = this.editor;
|
|
1112
1112
|
try {
|
|
1113
|
-
const c = s === "application/pdf",
|
|
1113
|
+
const c = s === "application/pdf", h = c ? "image/jpg" : s, l = E.getFormatFromContentType(h);
|
|
1114
1114
|
o.setCoords();
|
|
1115
|
-
const { left: g, top:
|
|
1116
|
-
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
const A =
|
|
1120
|
-
if (
|
|
1121
|
-
const I =
|
|
1122
|
-
|
|
1123
|
-
const
|
|
1124
|
-
image:
|
|
1115
|
+
const { left: g, top: M, width: f, height: m } = o.getBoundingRect(), u = yield i.clone(["id", "format", "locked"]);
|
|
1116
|
+
u.enableRetinaScaling = !1, ["image/jpg", "image/jpeg"].includes(h) && (u.backgroundColor = "#ffffff");
|
|
1117
|
+
const b = u.getObjects().find((I) => I.id === o.id);
|
|
1118
|
+
b && (b.visible = !1), u.viewportTransform = [1, 0, 0, 1, -g, -M], u.setDimensions({ width: f, height: m }, { backstoreOnly: !0 }), u.renderAll();
|
|
1119
|
+
const A = u.getObjects().filter((I) => I.format).every((I) => I.format === "svg");
|
|
1120
|
+
if (l === "svg" && A) {
|
|
1121
|
+
const I = u.toSVG();
|
|
1122
|
+
u.dispose();
|
|
1123
|
+
const L = {
|
|
1124
|
+
image: E._exportSVGStringAsFile(I, {
|
|
1125
1125
|
exportAsBase64: n,
|
|
1126
|
-
exportAsBlob:
|
|
1126
|
+
exportAsBlob: a,
|
|
1127
1127
|
fileName: t
|
|
1128
1128
|
}),
|
|
1129
1129
|
format: "svg",
|
|
1130
1130
|
contentType: "image/svg+xml",
|
|
1131
1131
|
fileName: t.replace(/\.[^/.]+$/, ".svg")
|
|
1132
1132
|
};
|
|
1133
|
-
return
|
|
1133
|
+
return i.fire("editor:canvas-exported", L), L;
|
|
1134
1134
|
}
|
|
1135
|
-
const
|
|
1136
|
-
|
|
1137
|
-
|
|
1135
|
+
const S = yield new Promise((I, x) => {
|
|
1136
|
+
u.getElement().toBlob((L) => {
|
|
1137
|
+
L ? I(L) : x(new Error("Failed to create Blob from canvas"));
|
|
1138
1138
|
});
|
|
1139
1139
|
});
|
|
1140
|
-
if (
|
|
1140
|
+
if (u.dispose(), a) {
|
|
1141
1141
|
const I = {
|
|
1142
|
-
image:
|
|
1143
|
-
format:
|
|
1144
|
-
contentType:
|
|
1142
|
+
image: S,
|
|
1143
|
+
format: l,
|
|
1144
|
+
contentType: h,
|
|
1145
1145
|
fileName: t
|
|
1146
1146
|
};
|
|
1147
|
-
return
|
|
1147
|
+
return i.fire("editor:canvas-exported", I), I;
|
|
1148
1148
|
}
|
|
1149
|
-
const
|
|
1149
|
+
const v = yield createImageBitmap(S), C = yield d.post(
|
|
1150
1150
|
"toDataURL",
|
|
1151
|
-
{ format:
|
|
1152
|
-
[
|
|
1151
|
+
{ format: l, quality: 1, bitmap: v },
|
|
1152
|
+
[v]
|
|
1153
1153
|
);
|
|
1154
1154
|
if (c) {
|
|
1155
|
-
const
|
|
1156
|
-
orientation:
|
|
1155
|
+
const x = f * 0.264583, L = m * 0.264583, be = (yield this.editor.moduleLoader.loadModule("jspdf")).jsPDF, $ = new be({
|
|
1156
|
+
orientation: x > L ? "landscape" : "portrait",
|
|
1157
1157
|
unit: "mm",
|
|
1158
|
-
format: [
|
|
1158
|
+
format: [x, L]
|
|
1159
1159
|
});
|
|
1160
|
-
if (
|
|
1160
|
+
if ($.addImage(String(C), "JPG", 0, 0, x, L), n) {
|
|
1161
1161
|
const ce = {
|
|
1162
|
-
image:
|
|
1162
|
+
image: $.output("datauristring"),
|
|
1163
1163
|
format: "pdf",
|
|
1164
1164
|
contentType: "application/pdf",
|
|
1165
1165
|
fileName: t
|
|
1166
1166
|
};
|
|
1167
|
-
return
|
|
1167
|
+
return i.fire("editor:canvas-exported", ce), ce;
|
|
1168
1168
|
}
|
|
1169
|
-
const
|
|
1170
|
-
image: new File([
|
|
1169
|
+
const pe = $.output("blob"), re = {
|
|
1170
|
+
image: new File([pe], t, { type: "application/pdf" }),
|
|
1171
1171
|
format: "pdf",
|
|
1172
1172
|
contentType: "application/pdf",
|
|
1173
1173
|
fileName: t
|
|
1174
1174
|
};
|
|
1175
|
-
return
|
|
1175
|
+
return i.fire("editor:canvas-exported", re), re;
|
|
1176
1176
|
}
|
|
1177
1177
|
if (n) {
|
|
1178
1178
|
const I = {
|
|
1179
|
-
image:
|
|
1180
|
-
format:
|
|
1181
|
-
contentType:
|
|
1179
|
+
image: C,
|
|
1180
|
+
format: l,
|
|
1181
|
+
contentType: h,
|
|
1182
1182
|
fileName: t
|
|
1183
1183
|
};
|
|
1184
|
-
return
|
|
1184
|
+
return i.fire("editor:canvas-exported", I), I;
|
|
1185
1185
|
}
|
|
1186
|
-
const
|
|
1187
|
-
image: new File([
|
|
1188
|
-
format:
|
|
1189
|
-
contentType:
|
|
1190
|
-
fileName:
|
|
1186
|
+
const w = l === "svg" && !A ? t.replace(/\.[^/.]+$/, ".png") : t, oe = {
|
|
1187
|
+
image: new File([S], w, { type: h }),
|
|
1188
|
+
format: l,
|
|
1189
|
+
contentType: h,
|
|
1190
|
+
fileName: w
|
|
1191
1191
|
};
|
|
1192
|
-
return
|
|
1192
|
+
return i.fire("editor:canvas-exported", oe), oe;
|
|
1193
1193
|
} catch (c) {
|
|
1194
1194
|
return this.editor.errorManager.emitError({
|
|
1195
1195
|
origin: "ImageManager",
|
|
1196
1196
|
method: "exportCanvasAsImageFile",
|
|
1197
1197
|
code: "IMAGE_EXPORT_FAILED",
|
|
1198
1198
|
message: `Ошибка экспорта изображения: ${c.message}`,
|
|
1199
|
-
data: { contentType: s, fileName: t, exportAsBase64: n, exportAsBlob:
|
|
1199
|
+
data: { contentType: s, fileName: t, exportAsBase64: n, exportAsBlob: a }
|
|
1200
1200
|
}), null;
|
|
1201
1201
|
}
|
|
1202
1202
|
});
|
|
@@ -1213,13 +1213,13 @@ class D {
|
|
|
1213
1213
|
* @fires editor:object-exported
|
|
1214
1214
|
*/
|
|
1215
1215
|
exportObjectAsImageFile() {
|
|
1216
|
-
return
|
|
1216
|
+
return j(this, arguments, function* (e = {}) {
|
|
1217
1217
|
const {
|
|
1218
1218
|
object: t,
|
|
1219
1219
|
fileName: s = "image.png",
|
|
1220
1220
|
contentType: n = "image/png",
|
|
1221
|
-
exportAsBase64:
|
|
1222
|
-
exportAsBlob:
|
|
1221
|
+
exportAsBase64: a = !1,
|
|
1222
|
+
exportAsBlob: i = !1
|
|
1223
1223
|
} = e, { canvas: o, workerManager: d } = this.editor, c = t || o.getActiveObject();
|
|
1224
1224
|
if (!c)
|
|
1225
1225
|
return this.editor.errorManager.emitError({
|
|
@@ -1227,74 +1227,74 @@ class D {
|
|
|
1227
1227
|
method: "exportObjectAsImageFile",
|
|
1228
1228
|
code: "NO_OBJECT_SELECTED",
|
|
1229
1229
|
message: "Не выбран объект для экспорта",
|
|
1230
|
-
data: { contentType: n, fileName: s, exportAsBase64:
|
|
1230
|
+
data: { contentType: n, fileName: s, exportAsBase64: a, exportAsBlob: i }
|
|
1231
1231
|
}), null;
|
|
1232
1232
|
try {
|
|
1233
|
-
const
|
|
1234
|
-
if (
|
|
1235
|
-
const
|
|
1236
|
-
exportAsBase64:
|
|
1237
|
-
exportAsBlob:
|
|
1233
|
+
const h = E.getFormatFromContentType(n);
|
|
1234
|
+
if (h === "svg") {
|
|
1235
|
+
const m = c.toSVG(), u = E._exportSVGStringAsFile(m, {
|
|
1236
|
+
exportAsBase64: a,
|
|
1237
|
+
exportAsBlob: i,
|
|
1238
1238
|
fileName: s
|
|
1239
|
-
}),
|
|
1239
|
+
}), b = {
|
|
1240
1240
|
object: c,
|
|
1241
|
-
image:
|
|
1242
|
-
format:
|
|
1241
|
+
image: u,
|
|
1242
|
+
format: h,
|
|
1243
1243
|
contentType: "image/svg+xml",
|
|
1244
1244
|
fileName: s.replace(/\.[^/.]+$/, ".svg")
|
|
1245
1245
|
};
|
|
1246
|
-
return o.fire("editor:object-exported",
|
|
1246
|
+
return o.fire("editor:object-exported", b), b;
|
|
1247
1247
|
}
|
|
1248
|
-
if (
|
|
1249
|
-
const
|
|
1248
|
+
if (a && c instanceof U) {
|
|
1249
|
+
const m = yield createImageBitmap(c.getElement()), u = yield d.post(
|
|
1250
1250
|
"toDataURL",
|
|
1251
1251
|
{
|
|
1252
|
-
format:
|
|
1252
|
+
format: h,
|
|
1253
1253
|
quality: 1,
|
|
1254
|
-
bitmap:
|
|
1254
|
+
bitmap: m
|
|
1255
1255
|
},
|
|
1256
|
-
[
|
|
1257
|
-
),
|
|
1256
|
+
[m]
|
|
1257
|
+
), b = {
|
|
1258
1258
|
object: c,
|
|
1259
|
-
image:
|
|
1260
|
-
format:
|
|
1259
|
+
image: u,
|
|
1260
|
+
format: h,
|
|
1261
1261
|
contentType: n,
|
|
1262
1262
|
fileName: s
|
|
1263
1263
|
};
|
|
1264
|
-
return o.fire("editor:object-exported",
|
|
1264
|
+
return o.fire("editor:object-exported", b), b;
|
|
1265
1265
|
}
|
|
1266
|
-
const
|
|
1266
|
+
const l = c.toCanvasElement({
|
|
1267
1267
|
enableRetinaScaling: !1
|
|
1268
|
-
}), g = yield new Promise((
|
|
1269
|
-
|
|
1270
|
-
|
|
1268
|
+
}), g = yield new Promise((m, u) => {
|
|
1269
|
+
l.toBlob((b) => {
|
|
1270
|
+
b ? m(b) : u(new Error("Failed to create Blob from canvas"));
|
|
1271
1271
|
});
|
|
1272
1272
|
});
|
|
1273
|
-
if (
|
|
1274
|
-
const
|
|
1273
|
+
if (i) {
|
|
1274
|
+
const m = {
|
|
1275
1275
|
object: c,
|
|
1276
1276
|
image: g,
|
|
1277
|
-
format:
|
|
1277
|
+
format: h,
|
|
1278
1278
|
contentType: n,
|
|
1279
1279
|
fileName: s
|
|
1280
1280
|
};
|
|
1281
|
-
return o.fire("editor:object-exported",
|
|
1281
|
+
return o.fire("editor:object-exported", m), m;
|
|
1282
1282
|
}
|
|
1283
|
-
const
|
|
1283
|
+
const M = new File([g], s, { type: n }), f = {
|
|
1284
1284
|
object: c,
|
|
1285
|
-
image:
|
|
1286
|
-
format:
|
|
1285
|
+
image: M,
|
|
1286
|
+
format: h,
|
|
1287
1287
|
contentType: n,
|
|
1288
1288
|
fileName: s
|
|
1289
1289
|
};
|
|
1290
|
-
return o.fire("editor:object-exported",
|
|
1291
|
-
} catch (
|
|
1290
|
+
return o.fire("editor:object-exported", f), f;
|
|
1291
|
+
} catch (h) {
|
|
1292
1292
|
return this.editor.errorManager.emitError({
|
|
1293
1293
|
origin: "ImageManager",
|
|
1294
1294
|
method: "exportObjectAsImageFile",
|
|
1295
1295
|
code: "IMAGE_EXPORT_FAILED",
|
|
1296
|
-
message: `Ошибка экспорта объекта: ${
|
|
1297
|
-
data: { contentType: n, fileName: s, exportAsBase64:
|
|
1296
|
+
message: `Ошибка экспорта объекта: ${h.message}`,
|
|
1297
|
+
data: { contentType: n, fileName: s, exportAsBase64: a, exportAsBlob: i }
|
|
1298
1298
|
}), null;
|
|
1299
1299
|
}
|
|
1300
1300
|
});
|
|
@@ -1310,7 +1310,7 @@ class D {
|
|
|
1310
1310
|
* @returns массив допустимых форматов изображений
|
|
1311
1311
|
*/
|
|
1312
1312
|
getAllowedFormatsFromContentTypes() {
|
|
1313
|
-
return this.acceptContentTypes.map((e) =>
|
|
1313
|
+
return this.acceptContentTypes.map((e) => E.getFormatFromContentType(e)).filter((e) => e);
|
|
1314
1314
|
}
|
|
1315
1315
|
/**
|
|
1316
1316
|
* Проверяет, является ли contentType допустимым типом изображения.
|
|
@@ -1326,7 +1326,7 @@ class D {
|
|
|
1326
1326
|
* @public
|
|
1327
1327
|
*/
|
|
1328
1328
|
getContentType(e) {
|
|
1329
|
-
return
|
|
1329
|
+
return j(this, null, function* () {
|
|
1330
1330
|
return typeof e == "string" ? this.getContentTypeFromUrl(e) : e.type || "application/octet-stream";
|
|
1331
1331
|
});
|
|
1332
1332
|
}
|
|
@@ -1337,7 +1337,7 @@ class D {
|
|
|
1337
1337
|
* @public
|
|
1338
1338
|
*/
|
|
1339
1339
|
getContentTypeFromUrl(e) {
|
|
1340
|
-
return
|
|
1340
|
+
return j(this, null, function* () {
|
|
1341
1341
|
if (e.startsWith("data:")) {
|
|
1342
1342
|
const t = e.match(/^data:([^;]+)/);
|
|
1343
1343
|
return t ? t[1] : "application/octet-stream";
|
|
@@ -1361,11 +1361,11 @@ class D {
|
|
|
1361
1361
|
getContentTypeFromExtension(e) {
|
|
1362
1362
|
var t;
|
|
1363
1363
|
try {
|
|
1364
|
-
const n = (t = new URL(e).pathname.split(".").pop()) == null ? void 0 : t.toLowerCase(),
|
|
1365
|
-
return this.acceptContentTypes.forEach((
|
|
1366
|
-
const o =
|
|
1367
|
-
o && (
|
|
1368
|
-
}), n &&
|
|
1364
|
+
const n = (t = new URL(e).pathname.split(".").pop()) == null ? void 0 : t.toLowerCase(), a = {};
|
|
1365
|
+
return this.acceptContentTypes.forEach((i) => {
|
|
1366
|
+
const o = E.getFormatFromContentType(i);
|
|
1367
|
+
o && (a[o] = i);
|
|
1368
|
+
}), n && a[n] || "application/octet-stream";
|
|
1369
1369
|
} catch (s) {
|
|
1370
1370
|
return console.warn("Не удалось определить расширение из URL:", e, s), "application/octet-stream";
|
|
1371
1371
|
}
|
|
@@ -1383,8 +1383,8 @@ class D {
|
|
|
1383
1383
|
}) {
|
|
1384
1384
|
const { montageArea: s } = this.editor;
|
|
1385
1385
|
if (!s || !e) return 1;
|
|
1386
|
-
const n = s.width,
|
|
1387
|
-
return t === "contain" || t === "image-contain" ? Math.min(n /
|
|
1386
|
+
const n = s.width, a = s.height, { width: i, height: o } = e;
|
|
1387
|
+
return t === "contain" || t === "image-contain" ? Math.min(n / i, a / o) : t === "cover" || t === "image-cover" ? Math.max(n / i, a / o) : 1;
|
|
1388
1388
|
}
|
|
1389
1389
|
/**
|
|
1390
1390
|
* Преобразует SVG-строку в Blob, файл, или base64
|
|
@@ -1416,11 +1416,11 @@ class D {
|
|
|
1416
1416
|
return t ? t[1] : "";
|
|
1417
1417
|
}
|
|
1418
1418
|
}
|
|
1419
|
-
const
|
|
1420
|
-
function
|
|
1419
|
+
const B = (r, e, t) => Math.max(Math.min(r, t), e), fe = (r, e) => r * e, it = (r, e) => new F(r / 2, e / 2);
|
|
1420
|
+
function ot(r) {
|
|
1421
1421
|
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";
|
|
1422
1422
|
}
|
|
1423
|
-
class
|
|
1423
|
+
class rt {
|
|
1424
1424
|
/**
|
|
1425
1425
|
* @param options
|
|
1426
1426
|
* @param options.editor – экземпляр редактора
|
|
@@ -1445,21 +1445,21 @@ class ot {
|
|
|
1445
1445
|
* @fires editor:resolution-width-changed
|
|
1446
1446
|
*/
|
|
1447
1447
|
setResolutionWidth(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer: n } = {}) {
|
|
1448
|
-
var
|
|
1448
|
+
var f;
|
|
1449
1449
|
if (!e) return;
|
|
1450
1450
|
const {
|
|
1451
|
-
canvas:
|
|
1452
|
-
montageArea:
|
|
1451
|
+
canvas: a,
|
|
1452
|
+
montageArea: i,
|
|
1453
1453
|
options: { canvasBackstoreWidth: o }
|
|
1454
|
-
} = this.editor, { width: d, height: c } =
|
|
1455
|
-
if (!o || o === "auto" || n ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreWidth(Number(o)) : this.setCanvasBackstoreWidth(
|
|
1456
|
-
const
|
|
1457
|
-
this.setResolutionHeight(
|
|
1454
|
+
} = this.editor, { width: d, height: c } = i, h = B(Number(e), _, O);
|
|
1455
|
+
if (!o || o === "auto" || n ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreWidth(Number(o)) : this.setCanvasBackstoreWidth(h), i.set({ width: h }), (f = a.clipPath) == null || f.set({ width: h }), t) {
|
|
1456
|
+
const m = h / d, u = fe(c, m);
|
|
1457
|
+
this.setResolutionHeight(u);
|
|
1458
1458
|
return;
|
|
1459
1459
|
}
|
|
1460
|
-
const { left:
|
|
1461
|
-
|
|
1462
|
-
width:
|
|
1460
|
+
const { left: l, top: g } = this.getObjectDefaultCoords(i), M = a.getZoom();
|
|
1461
|
+
a.setViewportTransform([M, 0, 0, M, l, g]), this.centerMontageArea(), s || this.editor.historyManager.saveState(), a.fire("editor:resolution-width-changed", {
|
|
1462
|
+
width: h,
|
|
1463
1463
|
preserveProportional: t,
|
|
1464
1464
|
withoutSave: s,
|
|
1465
1465
|
adaptCanvasToContainer: n
|
|
@@ -1475,21 +1475,21 @@ class ot {
|
|
|
1475
1475
|
* @fires editor:resolution-height-changed
|
|
1476
1476
|
*/
|
|
1477
1477
|
setResolutionHeight(e, { preserveProportional: t, withoutSave: s, adaptCanvasToContainer: n } = {}) {
|
|
1478
|
-
var
|
|
1478
|
+
var f;
|
|
1479
1479
|
if (!e) return;
|
|
1480
1480
|
const {
|
|
1481
|
-
canvas:
|
|
1482
|
-
montageArea:
|
|
1481
|
+
canvas: a,
|
|
1482
|
+
montageArea: i,
|
|
1483
1483
|
options: { canvasBackstoreHeight: o }
|
|
1484
|
-
} = this.editor, { width: d, height: c } =
|
|
1485
|
-
if (!o || o === "auto" || n ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreHeight(Number(o)) : this.setCanvasBackstoreHeight(
|
|
1486
|
-
const
|
|
1487
|
-
this.setResolutionWidth(
|
|
1484
|
+
} = this.editor, { width: d, height: c } = i, h = B(Number(e), R, T);
|
|
1485
|
+
if (!o || o === "auto" || n ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreHeight(Number(o)) : this.setCanvasBackstoreHeight(h), i.set({ height: h }), (f = a.clipPath) == null || f.set({ height: h }), t) {
|
|
1486
|
+
const m = h / c, u = fe(d, m);
|
|
1487
|
+
this.setResolutionWidth(u);
|
|
1488
1488
|
return;
|
|
1489
1489
|
}
|
|
1490
|
-
const { left:
|
|
1491
|
-
|
|
1492
|
-
height:
|
|
1490
|
+
const { left: l, top: g } = this.getObjectDefaultCoords(i), M = a.getZoom();
|
|
1491
|
+
a.setViewportTransform([M, 0, 0, M, l, g]), this.centerMontageArea(), s || this.editor.historyManager.saveState(), a.fire("editor:resolution-height-changed", {
|
|
1492
|
+
height: h,
|
|
1493
1493
|
preserveProportional: t,
|
|
1494
1494
|
withoutSave: s,
|
|
1495
1495
|
adaptCanvasToContainer: n
|
|
@@ -1501,7 +1501,7 @@ class ot {
|
|
|
1501
1501
|
*/
|
|
1502
1502
|
centerMontageArea() {
|
|
1503
1503
|
var d;
|
|
1504
|
-
const { canvas: e, montageArea: t } = this.editor, s = e.getWidth(), n = e.getHeight(),
|
|
1504
|
+
const { canvas: e, montageArea: t } = this.editor, s = e.getWidth(), n = e.getHeight(), a = e.getZoom(), i = it(s, n);
|
|
1505
1505
|
t.set({
|
|
1506
1506
|
left: s / 2,
|
|
1507
1507
|
top: n / 2
|
|
@@ -1510,7 +1510,7 @@ class ot {
|
|
|
1510
1510
|
top: n / 2
|
|
1511
1511
|
}), e.renderAll();
|
|
1512
1512
|
const o = e.viewportTransform;
|
|
1513
|
-
o[4] = s / 2 -
|
|
1513
|
+
o[4] = s / 2 - i.x * a, o[5] = n / 2 - i.y * a, e.setViewportTransform(o), e.renderAll();
|
|
1514
1514
|
}
|
|
1515
1515
|
/**
|
|
1516
1516
|
* Метод для получения координат объекта с учетом текущего зума
|
|
@@ -1526,7 +1526,7 @@ class ot {
|
|
|
1526
1526
|
code: "NO_ACTIVE_OBJECT",
|
|
1527
1527
|
message: "Не выбран объект для получения координат"
|
|
1528
1528
|
}), { left: 0, top: 0 };
|
|
1529
|
-
const { width: n, height:
|
|
1529
|
+
const { width: n, height: a } = s, i = t.getZoom(), o = (n - n * i) / 2, d = (a - a * i) / 2;
|
|
1530
1530
|
return { left: o, top: d };
|
|
1531
1531
|
}
|
|
1532
1532
|
/**
|
|
@@ -1534,7 +1534,7 @@ class ot {
|
|
|
1534
1534
|
*/
|
|
1535
1535
|
setCanvasBackstoreWidth(e) {
|
|
1536
1536
|
if (!e || typeof e != "number") return;
|
|
1537
|
-
const t =
|
|
1537
|
+
const t = B(e, _, O);
|
|
1538
1538
|
this.editor.canvas.setDimensions({ width: t }, { backstoreOnly: !0 });
|
|
1539
1539
|
}
|
|
1540
1540
|
/**
|
|
@@ -1543,7 +1543,7 @@ class ot {
|
|
|
1543
1543
|
*/
|
|
1544
1544
|
setCanvasBackstoreHeight(e) {
|
|
1545
1545
|
if (!e || typeof e != "number") return;
|
|
1546
|
-
const t =
|
|
1546
|
+
const t = B(e, R, T);
|
|
1547
1547
|
this.editor.canvas.setDimensions({ height: t }, { backstoreOnly: !0 });
|
|
1548
1548
|
}
|
|
1549
1549
|
/**
|
|
@@ -1552,8 +1552,8 @@ class ot {
|
|
|
1552
1552
|
* с учётом минимальных и максимальных значений.
|
|
1553
1553
|
*/
|
|
1554
1554
|
adaptCanvasToContainer() {
|
|
1555
|
-
const { canvas: e } = this.editor, t = this.getEditorContainer(), s = t.clientWidth, n = t.clientHeight,
|
|
1556
|
-
e.setDimensions({ width:
|
|
1555
|
+
const { canvas: e } = this.editor, t = this.getEditorContainer(), s = t.clientWidth, n = t.clientHeight, a = B(s, _, O), i = B(n, R, T);
|
|
1556
|
+
e.setDimensions({ width: a, height: i }, { backstoreOnly: !0 });
|
|
1557
1557
|
}
|
|
1558
1558
|
/**
|
|
1559
1559
|
* Обновляет размеры канваса без изменения позиций объектов.
|
|
@@ -1568,28 +1568,28 @@ class ot {
|
|
|
1568
1568
|
width: s,
|
|
1569
1569
|
height: n
|
|
1570
1570
|
}
|
|
1571
|
-
} = this.editor,
|
|
1571
|
+
} = this.editor, a = t.left, i = t.top;
|
|
1572
1572
|
this.setResolutionWidth(s, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.setResolutionHeight(n, { adaptCanvasToContainer: !0, withoutSave: !0 }), this.centerMontageArea();
|
|
1573
|
-
const o = t.left -
|
|
1573
|
+
const o = t.left - a, d = t.top - i;
|
|
1574
1574
|
if (o !== 0 || d !== 0) {
|
|
1575
|
-
const c = e.getActiveObject(),
|
|
1575
|
+
const c = e.getActiveObject(), h = [];
|
|
1576
1576
|
if ((c == null ? void 0 : c.type) === "activeselection") {
|
|
1577
|
-
const
|
|
1578
|
-
|
|
1577
|
+
const l = c;
|
|
1578
|
+
h.push(...l.getObjects()), e.discardActiveObject();
|
|
1579
1579
|
}
|
|
1580
|
-
if (e.getObjects().forEach((
|
|
1581
|
-
|
|
1582
|
-
left:
|
|
1583
|
-
top:
|
|
1584
|
-
}),
|
|
1585
|
-
}),
|
|
1586
|
-
if (
|
|
1587
|
-
e.setActiveObject(
|
|
1580
|
+
if (e.getObjects().forEach((l) => {
|
|
1581
|
+
l.id === "montage-area" || l.id === "overlay-mask" || (l.set({
|
|
1582
|
+
left: l.left + o,
|
|
1583
|
+
top: l.top + d
|
|
1584
|
+
}), l.setCoords());
|
|
1585
|
+
}), h.length > 0)
|
|
1586
|
+
if (h.length === 1)
|
|
1587
|
+
e.setActiveObject(h[0]);
|
|
1588
1588
|
else {
|
|
1589
|
-
const
|
|
1589
|
+
const l = new y(h, {
|
|
1590
1590
|
canvas: e
|
|
1591
1591
|
});
|
|
1592
|
-
e.setActiveObject(
|
|
1592
|
+
e.setActiveObject(l);
|
|
1593
1593
|
}
|
|
1594
1594
|
}
|
|
1595
1595
|
e.renderAll(), e.fire("editor:canvas-updated", {
|
|
@@ -1704,32 +1704,32 @@ class ot {
|
|
|
1704
1704
|
*/
|
|
1705
1705
|
setDisplayDimension({ element: e = "canvas", dimension: t, value: s } = {}) {
|
|
1706
1706
|
if (!s) return;
|
|
1707
|
-
const { canvas: n } = this.editor,
|
|
1707
|
+
const { canvas: n } = this.editor, a = [];
|
|
1708
1708
|
switch (e) {
|
|
1709
1709
|
case "canvas":
|
|
1710
|
-
|
|
1710
|
+
a.push(n.lowerCanvasEl, n.upperCanvasEl);
|
|
1711
1711
|
break;
|
|
1712
1712
|
case "wrapper":
|
|
1713
|
-
|
|
1713
|
+
a.push(n.wrapperEl);
|
|
1714
1714
|
break;
|
|
1715
1715
|
case "container":
|
|
1716
|
-
|
|
1716
|
+
a.push(this.getEditorContainer());
|
|
1717
1717
|
break;
|
|
1718
1718
|
default:
|
|
1719
|
-
|
|
1719
|
+
a.push(n.lowerCanvasEl, n.upperCanvasEl);
|
|
1720
1720
|
}
|
|
1721
|
-
const
|
|
1721
|
+
const i = t === "width" ? "width" : "height";
|
|
1722
1722
|
if (typeof s == "string") {
|
|
1723
|
-
|
|
1724
|
-
d.style[
|
|
1723
|
+
a.forEach((d) => {
|
|
1724
|
+
d.style[i] = s;
|
|
1725
1725
|
});
|
|
1726
1726
|
return;
|
|
1727
1727
|
}
|
|
1728
1728
|
if (isNaN(s)) return;
|
|
1729
1729
|
const o = `${s}px`;
|
|
1730
|
-
|
|
1731
|
-
d.style[
|
|
1732
|
-
}), n.fire(`editor:display-${e}-${
|
|
1730
|
+
a.forEach((d) => {
|
|
1731
|
+
d.style[i] = o;
|
|
1732
|
+
}), n.fire(`editor:display-${e}-${i}-changed`, {
|
|
1733
1733
|
element: e,
|
|
1734
1734
|
value: s
|
|
1735
1735
|
});
|
|
@@ -1745,27 +1745,27 @@ class ot {
|
|
|
1745
1745
|
scaleMontageAreaToImage({ object: e, preserveAspectRatio: t, withoutSave: s } = {}) {
|
|
1746
1746
|
const {
|
|
1747
1747
|
canvas: n,
|
|
1748
|
-
montageArea:
|
|
1749
|
-
transformManager:
|
|
1748
|
+
montageArea: a,
|
|
1749
|
+
transformManager: i,
|
|
1750
1750
|
options: {
|
|
1751
1751
|
montageAreaWidth: o,
|
|
1752
1752
|
montageAreaHeight: d
|
|
1753
1753
|
}
|
|
1754
1754
|
} = this.editor, c = e || n.getActiveObject();
|
|
1755
|
-
if (!
|
|
1756
|
-
const { width:
|
|
1757
|
-
let g = Math.min(
|
|
1755
|
+
if (!ot(c)) return;
|
|
1756
|
+
const { width: h, height: l } = c;
|
|
1757
|
+
let g = Math.min(h, O), M = Math.min(l, T);
|
|
1758
1758
|
if (t) {
|
|
1759
1759
|
const {
|
|
1760
|
-
width:
|
|
1761
|
-
height:
|
|
1762
|
-
} =
|
|
1763
|
-
g =
|
|
1760
|
+
width: f,
|
|
1761
|
+
height: m
|
|
1762
|
+
} = a, u = h / f, b = l / m, A = Math.max(u, b);
|
|
1763
|
+
g = f * A, M = m * A;
|
|
1764
1764
|
}
|
|
1765
|
-
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(
|
|
1765
|
+
this.setResolutionWidth(g, { withoutSave: !0 }), this.setResolutionHeight(M, { withoutSave: !0 }), (h > o || l > d) && i.calculateAndApplyDefaultZoom(), i.resetObject({ object: c, withoutSave: !0 }), n.centerObject(c), n.renderAll(), s || this.editor.historyManager.saveState(), n.fire("editor:montage-area-scaled-to-image", {
|
|
1766
1766
|
object: c,
|
|
1767
1767
|
width: g,
|
|
1768
|
-
height:
|
|
1768
|
+
height: M,
|
|
1769
1769
|
preserveAspectRatio: t,
|
|
1770
1770
|
withoutSave: s
|
|
1771
1771
|
});
|
|
@@ -1790,11 +1790,11 @@ class ot {
|
|
|
1790
1790
|
transformManager: s,
|
|
1791
1791
|
historyManager: n,
|
|
1792
1792
|
options: {
|
|
1793
|
-
montageAreaWidth:
|
|
1794
|
-
montageAreaHeight:
|
|
1793
|
+
montageAreaWidth: a,
|
|
1794
|
+
montageAreaHeight: i
|
|
1795
1795
|
}
|
|
1796
1796
|
} = this.editor;
|
|
1797
|
-
s.resetZoom(), this.setResolutionWidth(
|
|
1797
|
+
s.resetZoom(), this.setResolutionWidth(a, { withoutSave: !0 }), this.setResolutionHeight(i, { withoutSave: !0 }), t.renderAll(), s.resetObjects(), e || n.saveState(), t.fire("editor:default-scale-set");
|
|
1798
1798
|
}
|
|
1799
1799
|
/**
|
|
1800
1800
|
* Получение всех объектов внутри монтажной области редактора
|
|
@@ -1802,12 +1802,12 @@ class ot {
|
|
|
1802
1802
|
*/
|
|
1803
1803
|
getObjects() {
|
|
1804
1804
|
const { canvas: e, montageArea: t, interactionBlocker: { overlayMask: s } } = this.editor;
|
|
1805
|
-
return e.getObjects().filter((
|
|
1805
|
+
return e.getObjects().filter((a) => a.id !== t.id && a.id !== (s == null ? void 0 : s.id));
|
|
1806
1806
|
}
|
|
1807
1807
|
}
|
|
1808
|
-
class
|
|
1808
|
+
class ct {
|
|
1809
1809
|
constructor({ editor: e }) {
|
|
1810
|
-
this.editor = e, this.options = e.options, this.minZoom = this.options.minZoom ||
|
|
1810
|
+
this.editor = e, this.options = e.options, this.minZoom = this.options.minZoom || tt, this.maxZoom = this.options.maxZoom || st, this.defaultZoom = this.options.defaultScale;
|
|
1811
1811
|
}
|
|
1812
1812
|
/**
|
|
1813
1813
|
* Метод рассчитывает и применяет зум по умолчанию для монтажной области редактора.
|
|
@@ -1817,7 +1817,7 @@ class rt {
|
|
|
1817
1817
|
* @param scale - Желаемый масштаб относительно размеров контейнера редактора.
|
|
1818
1818
|
*/
|
|
1819
1819
|
calculateAndApplyDefaultZoom(e = this.options.defaultScale) {
|
|
1820
|
-
const { canvas: t } = this.editor, s = t.editorContainer, n = s.clientWidth,
|
|
1820
|
+
const { canvas: t } = this.editor, s = t.editorContainer, n = s.clientWidth, a = s.clientHeight, { width: i, height: o } = this.editor.montageArea, d = n / i * e, c = a / o * e;
|
|
1821
1821
|
this.defaultZoom = Math.min(d, c), this.setZoom();
|
|
1822
1822
|
}
|
|
1823
1823
|
/**
|
|
@@ -1829,15 +1829,15 @@ class rt {
|
|
|
1829
1829
|
* @fires editor:zoom-changed
|
|
1830
1830
|
* Если передавать координаты курсора, то нужно быть аккуратнее, так как юзер может выйти за пределы рабочей области
|
|
1831
1831
|
*/
|
|
1832
|
-
zoom(e =
|
|
1833
|
-
var g,
|
|
1832
|
+
zoom(e = nt, t = {}) {
|
|
1833
|
+
var g, M;
|
|
1834
1834
|
if (!e) return;
|
|
1835
|
-
const { minZoom: s, maxZoom: n } = this, { canvas:
|
|
1836
|
-
let
|
|
1837
|
-
|
|
1838
|
-
currentZoom:
|
|
1839
|
-
zoom:
|
|
1840
|
-
point:
|
|
1835
|
+
const { minZoom: s, maxZoom: n } = this, { canvas: a } = this.editor, i = a.getZoom(), o = a.getCenterPoint(), d = (g = t.pointX) != null ? g : o.x, c = (M = t.pointY) != null ? M : o.y, h = new F(d, c);
|
|
1836
|
+
let l = Number((i + Number(e)).toFixed(2));
|
|
1837
|
+
l > n && (l = n), l < s && (l = s), a.zoomToPoint(h, l), a.fire("editor:zoom-changed", {
|
|
1838
|
+
currentZoom: a.getZoom(),
|
|
1839
|
+
zoom: l,
|
|
1840
|
+
point: h
|
|
1841
1841
|
});
|
|
1842
1842
|
}
|
|
1843
1843
|
/**
|
|
@@ -1846,12 +1846,12 @@ class rt {
|
|
|
1846
1846
|
* @fires editor:zoom-changed
|
|
1847
1847
|
*/
|
|
1848
1848
|
setZoom(e = this.defaultZoom) {
|
|
1849
|
-
const { minZoom: t, maxZoom: s } = this, { canvas: n } = this.editor,
|
|
1850
|
-
let
|
|
1851
|
-
e > s && (
|
|
1849
|
+
const { minZoom: t, maxZoom: s } = this, { canvas: n } = this.editor, a = new F(n.getCenterPoint());
|
|
1850
|
+
let i = e;
|
|
1851
|
+
e > s && (i = s), e < t && (i = t), n.zoomToPoint(a, i), n.fire("editor:zoom-changed", {
|
|
1852
1852
|
currentZoom: n.getZoom(),
|
|
1853
|
-
zoom:
|
|
1854
|
-
point:
|
|
1853
|
+
zoom: i,
|
|
1854
|
+
point: a
|
|
1855
1855
|
});
|
|
1856
1856
|
}
|
|
1857
1857
|
/**
|
|
@@ -1859,7 +1859,7 @@ class rt {
|
|
|
1859
1859
|
* @fires editor:zoom-changed
|
|
1860
1860
|
*/
|
|
1861
1861
|
resetZoom() {
|
|
1862
|
-
const { canvas: e } = this.editor, t = new
|
|
1862
|
+
const { canvas: e } = this.editor, t = new F(e.getCenterPoint());
|
|
1863
1863
|
e.zoomToPoint(t, this.defaultZoom), this.editor.canvas.fire("editor:zoom-changed", {
|
|
1864
1864
|
currentZoom: e.getZoom(),
|
|
1865
1865
|
point: t
|
|
@@ -1872,14 +1872,14 @@ class rt {
|
|
|
1872
1872
|
* @param options.withoutSave - Не сохранять состояние
|
|
1873
1873
|
* @fires editor:object-rotated
|
|
1874
1874
|
*/
|
|
1875
|
-
rotate(e =
|
|
1876
|
-
const { canvas: s, historyManager: n } = this.editor,
|
|
1877
|
-
if (!
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
object:
|
|
1875
|
+
rotate(e = at, { withoutSave: t } = {}) {
|
|
1876
|
+
const { canvas: s, historyManager: n } = this.editor, a = s.getActiveObject();
|
|
1877
|
+
if (!a) return;
|
|
1878
|
+
const i = a.angle + e;
|
|
1879
|
+
a.rotate(i), a.setCoords(), s.renderAll(), t || n.saveState(), s.fire("editor:object-rotated", {
|
|
1880
|
+
object: a,
|
|
1881
1881
|
withoutSave: t,
|
|
1882
|
-
angle:
|
|
1882
|
+
angle: i
|
|
1883
1883
|
});
|
|
1884
1884
|
}
|
|
1885
1885
|
/**
|
|
@@ -1921,11 +1921,11 @@ class rt {
|
|
|
1921
1921
|
opacity: t = 1,
|
|
1922
1922
|
withoutSave: s
|
|
1923
1923
|
} = {}) {
|
|
1924
|
-
const { canvas: n, historyManager:
|
|
1925
|
-
|
|
1924
|
+
const { canvas: n, historyManager: a } = this.editor, i = e || n.getActiveObject();
|
|
1925
|
+
i && (i instanceof y ? i.getObjects().forEach((o) => {
|
|
1926
1926
|
o.set("opacity", t);
|
|
1927
|
-
}) :
|
|
1928
|
-
object:
|
|
1927
|
+
}) : i.set("opacity", t), n.renderAll(), s || a.saveState(), n.fire("editor:object-opacity-changed", {
|
|
1928
|
+
object: i,
|
|
1929
1929
|
opacity: t,
|
|
1930
1930
|
withoutSave: s
|
|
1931
1931
|
}));
|
|
@@ -1947,18 +1947,18 @@ class rt {
|
|
|
1947
1947
|
withoutSave: s,
|
|
1948
1948
|
fitAsOneObject: n
|
|
1949
1949
|
} = {}) {
|
|
1950
|
-
const { canvas:
|
|
1950
|
+
const { canvas: a, historyManager: i } = this.editor, o = e || a.getActiveObject();
|
|
1951
1951
|
if (o) {
|
|
1952
1952
|
if (o instanceof y && !n) {
|
|
1953
1953
|
const d = o.getObjects();
|
|
1954
|
-
|
|
1955
|
-
this._fitSingleObject(
|
|
1954
|
+
a.discardActiveObject(), d.forEach((h) => {
|
|
1955
|
+
this._fitSingleObject(h, t);
|
|
1956
1956
|
});
|
|
1957
|
-
const c = new y(d, { canvas:
|
|
1958
|
-
|
|
1957
|
+
const c = new y(d, { canvas: a });
|
|
1958
|
+
a.setActiveObject(c);
|
|
1959
1959
|
} else
|
|
1960
1960
|
this._fitSingleObject(o, t);
|
|
1961
|
-
|
|
1961
|
+
a.renderAll(), s || i.saveState(), a.fire("editor:object-fitted", {
|
|
1962
1962
|
object: o,
|
|
1963
1963
|
type: t,
|
|
1964
1964
|
withoutSave: s,
|
|
@@ -1973,11 +1973,11 @@ class rt {
|
|
|
1973
1973
|
* @private
|
|
1974
1974
|
*/
|
|
1975
1975
|
_fitSingleObject(e, t) {
|
|
1976
|
-
const { canvas: s, montageArea: n } = this.editor, { width:
|
|
1977
|
-
let
|
|
1978
|
-
t === "contain" ?
|
|
1979
|
-
scaleX: o *
|
|
1980
|
-
scaleY: d *
|
|
1976
|
+
const { canvas: s, montageArea: n } = this.editor, { width: a, height: i, scaleX: o = 1, scaleY: d = 1, angle: c = 0 } = e, h = a * Math.abs(o), l = i * Math.abs(d), g = c * Math.PI / 180, M = Math.abs(Math.cos(g)), f = Math.abs(Math.sin(g)), m = h * M + l * f, u = h * f + l * M, b = n.width, A = n.height;
|
|
1977
|
+
let S;
|
|
1978
|
+
t === "contain" ? S = Math.min(b / m, A / u) : S = Math.max(b / m, A / u), e.set({
|
|
1979
|
+
scaleX: o * S,
|
|
1980
|
+
scaleY: d * S
|
|
1981
1981
|
}), s.centerObject(e);
|
|
1982
1982
|
}
|
|
1983
1983
|
/**
|
|
@@ -1985,22 +1985,22 @@ class rt {
|
|
|
1985
1985
|
*/
|
|
1986
1986
|
resetObjects() {
|
|
1987
1987
|
this.editor.canvasManager.getObjects().forEach((e) => {
|
|
1988
|
-
this.resetObject(e);
|
|
1988
|
+
this.resetObject({ object: e });
|
|
1989
1989
|
});
|
|
1990
1990
|
}
|
|
1991
1991
|
/**
|
|
1992
1992
|
* Сброс масштаба объекта до дефолтного
|
|
1993
|
-
* @param object
|
|
1994
1993
|
* @param options
|
|
1994
|
+
* @param options.object - Объект, который нужно сбросить. Если не передан, то сбрасывается активный объект
|
|
1995
1995
|
* @param options.withoutSave - Не сохранять состояние
|
|
1996
1996
|
* @param options.alwaysFitObject - вписывать объект в рабочую область даже если он меньше рабочей области
|
|
1997
1997
|
* @fires editor:object-reset
|
|
1998
1998
|
*/
|
|
1999
|
-
resetObject(e,
|
|
1999
|
+
resetObject({ object: e, alwaysFitObject: t = !1, withoutSave: s = !1 } = {}) {
|
|
2000
2000
|
const {
|
|
2001
2001
|
canvas: n,
|
|
2002
|
-
montageArea:
|
|
2003
|
-
imageManager:
|
|
2002
|
+
montageArea: a,
|
|
2003
|
+
imageManager: i,
|
|
2004
2004
|
historyManager: o,
|
|
2005
2005
|
options: { scaleType: d }
|
|
2006
2006
|
} = this.editor, c = e || n.getActiveObject();
|
|
@@ -2014,11 +2014,11 @@ class rt {
|
|
|
2014
2014
|
}), t)
|
|
2015
2015
|
this.fitObject({ object: c, withoutSave: !0, fitAsOneObject: !0 });
|
|
2016
2016
|
else {
|
|
2017
|
-
const { width:
|
|
2017
|
+
const { width: l, height: g } = a, { width: M, height: f } = c, m = i.calculateScaleFactor({
|
|
2018
2018
|
imageObject: c,
|
|
2019
2019
|
scaleType: d
|
|
2020
2020
|
});
|
|
2021
|
-
d === "contain" &&
|
|
2021
|
+
d === "contain" && m < 1 || d === "cover" && (M > l || f > g) ? this.fitObject({ object: c, withoutSave: !0, fitAsOneObject: !0 }) : c.set({ scaleX: 1, scaleY: 1 });
|
|
2022
2022
|
}
|
|
2023
2023
|
c.set({ flipX: !1, flipY: !1, angle: 0 }), n.centerObject(c), n.renderAll(), o.resumeHistory(), s || o.saveState(), n.fire("editor:object-reset", {
|
|
2024
2024
|
object: c,
|
|
@@ -2027,7 +2027,7 @@ class rt {
|
|
|
2027
2027
|
});
|
|
2028
2028
|
}
|
|
2029
2029
|
}
|
|
2030
|
-
class
|
|
2030
|
+
class dt {
|
|
2031
2031
|
constructor({ editor: e }) {
|
|
2032
2032
|
this.editor = e, this.isBlocked = !1, this.overlayMask = null, this._createOverlay();
|
|
2033
2033
|
}
|
|
@@ -2057,8 +2057,8 @@ class ct {
|
|
|
2057
2057
|
const { canvas: e, montageArea: t, historyManager: s } = this.editor;
|
|
2058
2058
|
if (!t || !this.overlayMask) return;
|
|
2059
2059
|
s.suspendHistory(), t.setCoords();
|
|
2060
|
-
const { left: n, top:
|
|
2061
|
-
this.overlayMask.set({ left: n, top:
|
|
2060
|
+
const { left: n, top: a, width: i, height: o } = t.getBoundingRect();
|
|
2061
|
+
this.overlayMask.set({ left: n, top: a, width: i, height: o }), e.discardActiveObject(), this.editor.layerManager.bringToFront(this.overlayMask, { withoutSave: !0 }), s.resumeHistory();
|
|
2062
2062
|
}
|
|
2063
2063
|
/**
|
|
2064
2064
|
* Выключает редактор:
|
|
@@ -2084,7 +2084,7 @@ class ct {
|
|
|
2084
2084
|
}), e.upperCanvasEl.style.pointerEvents = "", e.lowerCanvasEl.style.pointerEvents = "", this.overlayMask.visible = !1, e.requestRenderAll(), e.fire("editor:enabled"), s.resumeHistory();
|
|
2085
2085
|
}
|
|
2086
2086
|
}
|
|
2087
|
-
class
|
|
2087
|
+
class G {
|
|
2088
2088
|
constructor({ editor: e }) {
|
|
2089
2089
|
this.editor = e;
|
|
2090
2090
|
}
|
|
@@ -2098,11 +2098,11 @@ class V {
|
|
|
2098
2098
|
bringToFront(e, { withoutSave: t } = {}) {
|
|
2099
2099
|
const { canvas: s, historyManager: n } = this.editor;
|
|
2100
2100
|
n.suspendHistory();
|
|
2101
|
-
const
|
|
2102
|
-
|
|
2103
|
-
s.bringObjectToFront(
|
|
2104
|
-
}) : s.bringObjectToFront(
|
|
2105
|
-
object:
|
|
2101
|
+
const a = e || s.getActiveObject();
|
|
2102
|
+
a && (a instanceof y ? a.getObjects().forEach((i) => {
|
|
2103
|
+
s.bringObjectToFront(i);
|
|
2104
|
+
}) : s.bringObjectToFront(a), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:object-bring-to-front", {
|
|
2105
|
+
object: a,
|
|
2106
2106
|
withoutSave: t
|
|
2107
2107
|
}));
|
|
2108
2108
|
}
|
|
@@ -2116,9 +2116,9 @@ class V {
|
|
|
2116
2116
|
bringForward(e, { withoutSave: t } = {}) {
|
|
2117
2117
|
const { canvas: s, historyManager: n } = this.editor;
|
|
2118
2118
|
n.suspendHistory();
|
|
2119
|
-
const
|
|
2120
|
-
|
|
2121
|
-
object:
|
|
2119
|
+
const a = e || s.getActiveObject();
|
|
2120
|
+
a && (a instanceof y ? G._moveSelectionForward(s, a) : s.bringObjectForward(a), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:object-bring-forward", {
|
|
2121
|
+
object: a,
|
|
2122
2122
|
withoutSave: t
|
|
2123
2123
|
}));
|
|
2124
2124
|
}
|
|
@@ -2133,10 +2133,10 @@ class V {
|
|
|
2133
2133
|
const {
|
|
2134
2134
|
canvas: s,
|
|
2135
2135
|
montageArea: n,
|
|
2136
|
-
historyManager:
|
|
2137
|
-
interactionBlocker: { overlayMask:
|
|
2136
|
+
historyManager: a,
|
|
2137
|
+
interactionBlocker: { overlayMask: i }
|
|
2138
2138
|
} = this.editor;
|
|
2139
|
-
|
|
2139
|
+
a.suspendHistory();
|
|
2140
2140
|
const o = e || s.getActiveObject();
|
|
2141
2141
|
if (o) {
|
|
2142
2142
|
if (o instanceof y) {
|
|
@@ -2145,7 +2145,7 @@ class V {
|
|
|
2145
2145
|
s.sendObjectToBack(d[c]);
|
|
2146
2146
|
} else
|
|
2147
2147
|
s.sendObjectToBack(o);
|
|
2148
|
-
s.sendObjectToBack(n),
|
|
2148
|
+
s.sendObjectToBack(n), i && s.sendObjectToBack(i), s.renderAll(), a.resumeHistory(), t || a.saveState(), s.fire("editor:object-send-to-back", {
|
|
2149
2149
|
object: o,
|
|
2150
2150
|
withoutSave: t
|
|
2151
2151
|
});
|
|
@@ -2161,12 +2161,12 @@ class V {
|
|
|
2161
2161
|
const {
|
|
2162
2162
|
canvas: s,
|
|
2163
2163
|
montageArea: n,
|
|
2164
|
-
historyManager:
|
|
2165
|
-
interactionBlocker: { overlayMask:
|
|
2164
|
+
historyManager: a,
|
|
2165
|
+
interactionBlocker: { overlayMask: i }
|
|
2166
2166
|
} = this.editor;
|
|
2167
|
-
|
|
2167
|
+
a.suspendHistory();
|
|
2168
2168
|
const o = e || s.getActiveObject();
|
|
2169
|
-
o && (o instanceof y ?
|
|
2169
|
+
o && (o instanceof y ? G._moveSelectionBackwards(s, o) : s.sendObjectBackwards(o), s.sendObjectToBack(n), i && s.sendObjectToBack(i), s.renderAll(), a.resumeHistory(), t || a.saveState(), s.fire("editor:object-send-backwards", {
|
|
2170
2170
|
object: o,
|
|
2171
2171
|
withoutSave: t
|
|
2172
2172
|
}));
|
|
@@ -2210,7 +2210,7 @@ class V {
|
|
|
2210
2210
|
});
|
|
2211
2211
|
}
|
|
2212
2212
|
}
|
|
2213
|
-
class
|
|
2213
|
+
class lt {
|
|
2214
2214
|
/**
|
|
2215
2215
|
* Менеджер фигур для редактора.
|
|
2216
2216
|
* @param options - Опции и настройки менеджера фигур.
|
|
@@ -2234,15 +2234,15 @@ class dt {
|
|
|
2234
2234
|
* @param flags.withoutSelection - Не выделять объект
|
|
2235
2235
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2236
2236
|
*/
|
|
2237
|
-
addRectangle(
|
|
2238
|
-
var
|
|
2239
|
-
id: e = `rect-${
|
|
2237
|
+
addRectangle(h = {}, { withoutSelection: d, withoutAdding: c } = {}) {
|
|
2238
|
+
var l = h, {
|
|
2239
|
+
id: e = `rect-${D()}`,
|
|
2240
2240
|
left: t,
|
|
2241
2241
|
top: s,
|
|
2242
2242
|
width: n = 100,
|
|
2243
|
-
height:
|
|
2244
|
-
fill:
|
|
2245
|
-
} =
|
|
2243
|
+
height: a = 100,
|
|
2244
|
+
fill: i = "blue"
|
|
2245
|
+
} = l, o = P(l, [
|
|
2246
2246
|
"id",
|
|
2247
2247
|
"left",
|
|
2248
2248
|
"top",
|
|
@@ -2250,15 +2250,15 @@ class dt {
|
|
|
2250
2250
|
"height",
|
|
2251
2251
|
"fill"
|
|
2252
2252
|
]);
|
|
2253
|
-
const { canvas: g } = this.editor,
|
|
2253
|
+
const { canvas: g } = this.editor, M = new De(p({
|
|
2254
2254
|
id: e,
|
|
2255
2255
|
left: t,
|
|
2256
2256
|
top: s,
|
|
2257
2257
|
width: n,
|
|
2258
|
-
height:
|
|
2259
|
-
fill:
|
|
2258
|
+
height: a,
|
|
2259
|
+
fill: i
|
|
2260
2260
|
}, o));
|
|
2261
|
-
return !t && !s && g.centerObject(
|
|
2261
|
+
return !t && !s && g.centerObject(M), c || (g.add(M), d || g.setActiveObject(M), g.renderAll()), M;
|
|
2262
2262
|
}
|
|
2263
2263
|
/**
|
|
2264
2264
|
* Добавление круга
|
|
@@ -2277,27 +2277,27 @@ class dt {
|
|
|
2277
2277
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2278
2278
|
*/
|
|
2279
2279
|
addCircle(c = {}, { withoutSelection: o, withoutAdding: d } = {}) {
|
|
2280
|
-
var
|
|
2281
|
-
id: e = `circle-${
|
|
2280
|
+
var h = c, {
|
|
2281
|
+
id: e = `circle-${D()}`,
|
|
2282
2282
|
left: t,
|
|
2283
2283
|
top: s,
|
|
2284
2284
|
radius: n = 50,
|
|
2285
|
-
fill:
|
|
2286
|
-
} =
|
|
2285
|
+
fill: a = "green"
|
|
2286
|
+
} = h, i = P(h, [
|
|
2287
2287
|
"id",
|
|
2288
2288
|
"left",
|
|
2289
2289
|
"top",
|
|
2290
2290
|
"radius",
|
|
2291
2291
|
"fill"
|
|
2292
2292
|
]);
|
|
2293
|
-
const { canvas:
|
|
2293
|
+
const { canvas: l } = this.editor, g = new Le(p({
|
|
2294
2294
|
id: e,
|
|
2295
2295
|
left: t,
|
|
2296
2296
|
top: s,
|
|
2297
|
-
fill:
|
|
2297
|
+
fill: a,
|
|
2298
2298
|
radius: n
|
|
2299
|
-
},
|
|
2300
|
-
return !t && !s &&
|
|
2299
|
+
}, i));
|
|
2300
|
+
return !t && !s && l.centerObject(g), d || (l.add(g), o || l.setActiveObject(g), l.renderAll()), g;
|
|
2301
2301
|
}
|
|
2302
2302
|
/**
|
|
2303
2303
|
* Добавление треугольника
|
|
@@ -2316,15 +2316,15 @@ class dt {
|
|
|
2316
2316
|
* @param flags.withoutSelection - Не выделять объект
|
|
2317
2317
|
* @param flags.withoutAdding - Не добавлять объект в canvas
|
|
2318
2318
|
*/
|
|
2319
|
-
addTriangle(
|
|
2320
|
-
var
|
|
2321
|
-
id: e = `triangle-${
|
|
2319
|
+
addTriangle(h = {}, { withoutSelection: d, withoutAdding: c } = {}) {
|
|
2320
|
+
var l = h, {
|
|
2321
|
+
id: e = `triangle-${D()}`,
|
|
2322
2322
|
left: t,
|
|
2323
2323
|
top: s,
|
|
2324
2324
|
width: n = 100,
|
|
2325
|
-
height:
|
|
2326
|
-
fill:
|
|
2327
|
-
} =
|
|
2325
|
+
height: a = 100,
|
|
2326
|
+
fill: i = "yellow"
|
|
2327
|
+
} = l, o = P(l, [
|
|
2328
2328
|
"id",
|
|
2329
2329
|
"left",
|
|
2330
2330
|
"top",
|
|
@@ -2332,18 +2332,18 @@ class dt {
|
|
|
2332
2332
|
"height",
|
|
2333
2333
|
"fill"
|
|
2334
2334
|
]);
|
|
2335
|
-
const { canvas: g } = this.editor,
|
|
2335
|
+
const { canvas: g } = this.editor, M = new Ne(p({
|
|
2336
2336
|
id: e,
|
|
2337
2337
|
left: t,
|
|
2338
2338
|
top: s,
|
|
2339
|
-
fill:
|
|
2339
|
+
fill: i,
|
|
2340
2340
|
width: n,
|
|
2341
|
-
height:
|
|
2341
|
+
height: a
|
|
2342
2342
|
}, o));
|
|
2343
|
-
return !t && !s && g.centerObject(
|
|
2343
|
+
return !t && !s && g.centerObject(M), c || (g.add(M), d || g.setActiveObject(M), g.renderAll()), M;
|
|
2344
2344
|
}
|
|
2345
2345
|
}
|
|
2346
|
-
class
|
|
2346
|
+
class ht {
|
|
2347
2347
|
/**
|
|
2348
2348
|
* @param options
|
|
2349
2349
|
* @param options.editor - экземпляр редактора с доступом к canvas
|
|
@@ -2352,76 +2352,166 @@ class lt {
|
|
|
2352
2352
|
this.editor = e, this.clipboard = null;
|
|
2353
2353
|
}
|
|
2354
2354
|
/**
|
|
2355
|
-
*
|
|
2355
|
+
* Синхронное копирование объекта в системный буфер обмена
|
|
2356
2356
|
* @fires editor:object-copied
|
|
2357
2357
|
*/
|
|
2358
2358
|
copy() {
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2359
|
+
const { canvas: e } = this.editor, t = e.getActiveObject();
|
|
2360
|
+
!t || t.locked || (this._cloneToInternalClipboard(t), this._copyToSystemClipboard(t).catch((s) => {
|
|
2361
|
+
this.editor.errorManager.emitWarning({
|
|
2362
|
+
origin: "ClipboardManager",
|
|
2363
|
+
method: "copy",
|
|
2364
|
+
code: "COPY_FAILED",
|
|
2365
|
+
message: "Ошибка копирования объекта в системный буфер обмена",
|
|
2366
|
+
data: s
|
|
2367
|
+
});
|
|
2368
|
+
}));
|
|
2369
|
+
}
|
|
2370
|
+
/**
|
|
2371
|
+
* Асинхронное клонирование для внутреннего буфера
|
|
2372
|
+
*/
|
|
2373
|
+
_cloneToInternalClipboard(e) {
|
|
2374
|
+
return j(this, null, function* () {
|
|
2375
|
+
const { canvas: t, errorManager: s } = this.editor;
|
|
2362
2376
|
try {
|
|
2363
|
-
const
|
|
2364
|
-
this.clipboard =
|
|
2365
|
-
} catch (
|
|
2366
|
-
|
|
2377
|
+
const n = yield e.clone(["format"]);
|
|
2378
|
+
this.clipboard = n, t.fire("editor:object-copied", { object: n });
|
|
2379
|
+
} catch (n) {
|
|
2380
|
+
s.emitError({
|
|
2367
2381
|
origin: "ClipboardManager",
|
|
2368
|
-
method: "
|
|
2382
|
+
method: "_cloneToInternalClipboard",
|
|
2369
2383
|
code: "CLONE_FAILED",
|
|
2370
|
-
message: "Ошибка клонирования объекта",
|
|
2371
|
-
data:
|
|
2384
|
+
message: "Ошибка клонирования объекта для внутреннего буфера",
|
|
2385
|
+
data: n
|
|
2372
2386
|
});
|
|
2373
|
-
return;
|
|
2374
2387
|
}
|
|
2375
|
-
|
|
2376
|
-
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
/**
|
|
2391
|
+
* Копирование в системный буфер обмена
|
|
2392
|
+
*/
|
|
2393
|
+
_copyToSystemClipboard(e) {
|
|
2394
|
+
return j(this, null, function* () {
|
|
2395
|
+
const { errorManager: t } = this.editor;
|
|
2396
|
+
if (typeof ClipboardItem == "undefined" || !navigator.clipboard)
|
|
2397
|
+
return t.emitWarning({
|
|
2377
2398
|
origin: "ClipboardManager",
|
|
2378
|
-
method: "
|
|
2399
|
+
method: "_copyToSystemClipboard",
|
|
2379
2400
|
code: "CLIPBOARD_NOT_SUPPORTED",
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2401
|
+
message: "navigator.clipboard не поддерживается в этом браузере или отсутствует HTTPS-соединение."
|
|
2402
|
+
}), !1;
|
|
2403
|
+
try {
|
|
2404
|
+
const s = e.toObject(["format"]), n = JSON.stringify(s);
|
|
2405
|
+
return e.type === "image" ? this._copyImageToClipboard(e, n) : this._copyTextToClipboard(n);
|
|
2406
|
+
} catch (s) {
|
|
2407
|
+
return t.emitError({
|
|
2408
|
+
origin: "ClipboardManager",
|
|
2409
|
+
method: "_copyToSystemClipboard",
|
|
2410
|
+
code: "COPY_FAILED",
|
|
2411
|
+
message: "Ошибка копирования объекта",
|
|
2412
|
+
data: s
|
|
2413
|
+
}), !1;
|
|
2384
2414
|
}
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2415
|
+
});
|
|
2416
|
+
}
|
|
2417
|
+
/**
|
|
2418
|
+
* Копирование изображения в буфер обмена
|
|
2419
|
+
*/
|
|
2420
|
+
_copyImageToClipboard(e, t) {
|
|
2421
|
+
return j(this, null, function* () {
|
|
2422
|
+
try {
|
|
2423
|
+
const n = e.toCanvasElement({ enableRetinaScaling: !1 }).toDataURL(), a = n.slice(5).split(";")[0], i = n.split(",")[1], o = atob(i), d = new Uint8Array(o.length);
|
|
2424
|
+
for (let l = 0; l < o.length; l += 1)
|
|
2425
|
+
d[l] = o.charCodeAt(l);
|
|
2426
|
+
const c = new Blob([d.buffer], { type: a }), h = new ClipboardItem({ [a]: c });
|
|
2427
|
+
return yield navigator.clipboard.write([h]), console.info("Image copied to clipboard successfully"), !0;
|
|
2428
|
+
} catch (s) {
|
|
2429
|
+
return this.editor.errorManager.emitWarning({
|
|
2430
|
+
origin: "ClipboardManager",
|
|
2431
|
+
method: "_copyImageToClipboard",
|
|
2432
|
+
code: "CLIPBOARD_WRITE_IMAGE_FAILED",
|
|
2433
|
+
message: `Ошибка записи изображения в буфер обмена, выполняется fallback к текстовому копированию: ${s}`,
|
|
2434
|
+
data: s
|
|
2435
|
+
}), this._copyTextToClipboard(t);
|
|
2436
|
+
}
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Копирование текста в буфер обмена
|
|
2441
|
+
*/
|
|
2442
|
+
_copyTextToClipboard(e) {
|
|
2443
|
+
return j(this, null, function* () {
|
|
2444
|
+
try {
|
|
2445
|
+
const t = `${me}${e}`;
|
|
2446
|
+
return yield navigator.clipboard.writeText(t), console.info("Text copied to clipboard successfully"), !0;
|
|
2447
|
+
} catch (t) {
|
|
2448
|
+
const { errorManager: s } = this.editor;
|
|
2449
|
+
return s.emitWarning({
|
|
2450
|
+
origin: "ClipboardManager",
|
|
2451
|
+
method: "_copyTextToClipboard",
|
|
2452
|
+
code: "CLIPBOARD_WRITE_TEXT_FAILED",
|
|
2453
|
+
message: `Ошибка записи текста в буфер обмена: ${t}`,
|
|
2454
|
+
data: t
|
|
2455
|
+
}), !1;
|
|
2456
|
+
}
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
/**
|
|
2460
|
+
* Добавляет клонированный объект на canvas с учетом типа объекта
|
|
2461
|
+
* @param clonedObject - клонированный объект для добавления
|
|
2462
|
+
*/
|
|
2463
|
+
_addClonedObjectToCanvas(e) {
|
|
2464
|
+
const { canvas: t, historyManager: s } = this.editor;
|
|
2465
|
+
if (t.discardActiveObject(), e instanceof y) {
|
|
2466
|
+
s.suspendHistory(), e.canvas = t, e.forEachObject((n) => {
|
|
2467
|
+
t.add(n);
|
|
2468
|
+
}), t.setActiveObject(e), t.requestRenderAll(), s.resumeHistory(), s.saveState();
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
t.add(e), t.setActiveObject(e), t.requestRenderAll();
|
|
2472
|
+
}
|
|
2473
|
+
/**
|
|
2474
|
+
* Обработка импорта изображения из буфера обмена
|
|
2475
|
+
* @param source - источник изображения (data URL или URL)
|
|
2476
|
+
*/
|
|
2477
|
+
_handleImageImport(e) {
|
|
2478
|
+
return j(this, null, function* () {
|
|
2479
|
+
var s;
|
|
2480
|
+
const { image: t } = (s = yield this.editor.imageManager.importImage({
|
|
2481
|
+
source: e,
|
|
2482
|
+
fromClipboard: !0
|
|
2483
|
+
})) != null ? s : {};
|
|
2484
|
+
t && this.editor.canvas.fire("editor:object-pasted", { object: t });
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Создать копию объекта - копирует и сразу вставляет
|
|
2489
|
+
* @param objectToCopy - объект для копирования (если не указан, используется активный объект)
|
|
2490
|
+
* @fires editor:object-copied
|
|
2491
|
+
* @fires editor:object-pasted
|
|
2492
|
+
*/
|
|
2493
|
+
copyPaste(e) {
|
|
2494
|
+
return j(this, null, function* () {
|
|
2495
|
+
const { canvas: t } = this.editor, s = e || t.getActiveObject();
|
|
2496
|
+
if (!s || s.locked) return !1;
|
|
2497
|
+
try {
|
|
2498
|
+
const n = yield s.clone(["format"]);
|
|
2499
|
+
return n.set({
|
|
2500
|
+
id: `${n.type}-${D()}`,
|
|
2501
|
+
left: n.left + 10,
|
|
2502
|
+
top: n.top + 10,
|
|
2503
|
+
evented: !0
|
|
2504
|
+
}), this._addClonedObjectToCanvas(n), t.fire("editor:object-duplicated", { object: n }), !0;
|
|
2505
|
+
} catch (n) {
|
|
2506
|
+
const { errorManager: a } = this.editor;
|
|
2507
|
+
return a.emitError({
|
|
2508
|
+
origin: "ClipboardManager",
|
|
2509
|
+
method: "copyPaste",
|
|
2510
|
+
code: "COPY_PASTE_FAILED",
|
|
2511
|
+
message: "Ошибка создания копии объекта",
|
|
2512
|
+
data: n
|
|
2513
|
+
}), !1;
|
|
2401
2514
|
}
|
|
2402
|
-
const i = s.toCanvasElement({
|
|
2403
|
-
enableRetinaScaling: !1
|
|
2404
|
-
}).toDataURL(), a = i.slice(5).split(";")[0], o = i.split(",")[1], d = atob(o), c = new Uint8Array(d.length);
|
|
2405
|
-
for (let g = 0; g < d.length; g += 1)
|
|
2406
|
-
c[g] = d.charCodeAt(g);
|
|
2407
|
-
const l = new Blob([c.buffer], { type: a }), h = new ClipboardItem({ [a]: l });
|
|
2408
|
-
navigator.clipboard.write([h]).catch((g) => {
|
|
2409
|
-
if (g.name === "NotAllowedError") {
|
|
2410
|
-
console.info("Clipboard access denied, object copied to internal clipboard only");
|
|
2411
|
-
return;
|
|
2412
|
-
}
|
|
2413
|
-
const u = `${$}${JSON.stringify(s.toObject(["format"]))}`;
|
|
2414
|
-
navigator.clipboard.writeText(u).catch((m) => {
|
|
2415
|
-
t.emitWarning({
|
|
2416
|
-
origin: "ClipboardManager",
|
|
2417
|
-
method: "copy",
|
|
2418
|
-
code: "CLIPBOARD_WRITE_IMAGE_FAILED",
|
|
2419
|
-
// eslint-disable-next-line max-len
|
|
2420
|
-
message: `Ошибка записи изображения в буфер обмена: ${g.message}. Fallback также не удался: ${m.message}`,
|
|
2421
|
-
data: { originalError: g, fallbackError: m }
|
|
2422
|
-
});
|
|
2423
|
-
});
|
|
2424
|
-
});
|
|
2425
2515
|
});
|
|
2426
2516
|
}
|
|
2427
2517
|
/**
|
|
@@ -2431,30 +2521,46 @@ class lt {
|
|
|
2431
2521
|
* @param event.clipboardData.items — элементы буфера обмена
|
|
2432
2522
|
*/
|
|
2433
2523
|
handlePasteEvent(t) {
|
|
2434
|
-
return
|
|
2435
|
-
var
|
|
2436
|
-
if (!((
|
|
2524
|
+
return j(this, arguments, function* ({ clipboardData: e }) {
|
|
2525
|
+
var d;
|
|
2526
|
+
if (!((d = e == null ? void 0 : e.items) != null && d.length)) {
|
|
2437
2527
|
this.paste();
|
|
2438
2528
|
return;
|
|
2439
2529
|
}
|
|
2440
2530
|
const s = e.getData("text/plain");
|
|
2441
|
-
if (s && s.startsWith(
|
|
2531
|
+
if (s && s.startsWith(me)) {
|
|
2442
2532
|
this.paste();
|
|
2443
2533
|
return;
|
|
2444
2534
|
}
|
|
2445
|
-
const {
|
|
2446
|
-
if (a.type !== "text/html" &&
|
|
2447
|
-
const
|
|
2448
|
-
|
|
2449
|
-
h.target && this.
|
|
2450
|
-
|
|
2535
|
+
const { items: n } = e, a = n[n.length - 1], i = a.getAsFile();
|
|
2536
|
+
if (a.type !== "text/html" && i) {
|
|
2537
|
+
const c = new FileReader();
|
|
2538
|
+
c.onload = (h) => {
|
|
2539
|
+
h.target && this._handleImageImport(h.target.result).catch((l) => {
|
|
2540
|
+
this.editor.errorManager.emitError({
|
|
2541
|
+
origin: "ClipboardManager",
|
|
2542
|
+
method: "handlePasteEvent",
|
|
2543
|
+
code: "PASTE_IMAGE_FAILED",
|
|
2544
|
+
message: "Ошибка вставки изображения из буфера обмена",
|
|
2545
|
+
data: l
|
|
2546
|
+
});
|
|
2547
|
+
});
|
|
2548
|
+
}, c.readAsDataURL(i);
|
|
2451
2549
|
return;
|
|
2452
2550
|
}
|
|
2453
|
-
const
|
|
2454
|
-
if (
|
|
2455
|
-
const
|
|
2456
|
-
if (
|
|
2457
|
-
|
|
2551
|
+
const o = e.getData("text/html");
|
|
2552
|
+
if (o) {
|
|
2553
|
+
const l = new DOMParser().parseFromString(o, "text/html").querySelector("img");
|
|
2554
|
+
if (l != null && l.src) {
|
|
2555
|
+
this._handleImageImport(l.src).catch((g) => {
|
|
2556
|
+
this.editor.errorManager.emitError({
|
|
2557
|
+
origin: "ClipboardManager",
|
|
2558
|
+
method: "handlePasteEvent",
|
|
2559
|
+
code: "PASTE_HTML_IMAGE_FAILED",
|
|
2560
|
+
message: "Ошибка вставки изображения из HTML",
|
|
2561
|
+
data: g
|
|
2562
|
+
});
|
|
2563
|
+
});
|
|
2458
2564
|
return;
|
|
2459
2565
|
}
|
|
2460
2566
|
}
|
|
@@ -2462,26 +2568,35 @@ class lt {
|
|
|
2462
2568
|
});
|
|
2463
2569
|
}
|
|
2464
2570
|
/**
|
|
2465
|
-
* Вставка объекта
|
|
2571
|
+
* Вставка объекта из внутреннего буфера
|
|
2466
2572
|
* @fires editor:object-pasted
|
|
2467
2573
|
*/
|
|
2468
2574
|
paste() {
|
|
2469
|
-
return
|
|
2575
|
+
return j(this, null, function* () {
|
|
2470
2576
|
const { canvas: e } = this.editor;
|
|
2471
|
-
if (!this.clipboard) return;
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
e.
|
|
2480
|
-
}
|
|
2577
|
+
if (!this.clipboard) return !1;
|
|
2578
|
+
try {
|
|
2579
|
+
const t = yield this.clipboard.clone(["format"]);
|
|
2580
|
+
return e.discardActiveObject(), t.set({
|
|
2581
|
+
id: `${t.type}-${D()}`,
|
|
2582
|
+
left: t.left + 10,
|
|
2583
|
+
top: t.top + 10,
|
|
2584
|
+
evented: !0
|
|
2585
|
+
}), this._addClonedObjectToCanvas(t), e.fire("editor:object-pasted", { object: t }), !0;
|
|
2586
|
+
} catch (t) {
|
|
2587
|
+
const { errorManager: s } = this.editor;
|
|
2588
|
+
return s.emitError({
|
|
2589
|
+
origin: "ClipboardManager",
|
|
2590
|
+
method: "paste",
|
|
2591
|
+
code: "PASTE_FAILED",
|
|
2592
|
+
message: "Ошибка вставки объекта",
|
|
2593
|
+
data: t
|
|
2594
|
+
}), !1;
|
|
2595
|
+
}
|
|
2481
2596
|
});
|
|
2482
2597
|
}
|
|
2483
2598
|
}
|
|
2484
|
-
class
|
|
2599
|
+
class X {
|
|
2485
2600
|
constructor({ editor: e }) {
|
|
2486
2601
|
this.editor = e;
|
|
2487
2602
|
}
|
|
@@ -2494,8 +2609,8 @@ class G {
|
|
|
2494
2609
|
* @fires editor:object-locked
|
|
2495
2610
|
*/
|
|
2496
2611
|
lockObject({ object: e, skipInnerObjects: t, withoutSave: s } = {}) {
|
|
2497
|
-
const { canvas: n, historyManager:
|
|
2498
|
-
if (!
|
|
2612
|
+
const { canvas: n, historyManager: a } = this.editor, i = e || n.getActiveObject();
|
|
2613
|
+
if (!i || i.locked) return;
|
|
2499
2614
|
const o = {
|
|
2500
2615
|
lockMovementX: !0,
|
|
2501
2616
|
lockMovementY: !0,
|
|
@@ -2506,10 +2621,10 @@ class G {
|
|
|
2506
2621
|
lockSkewingY: !0,
|
|
2507
2622
|
locked: !0
|
|
2508
2623
|
};
|
|
2509
|
-
|
|
2624
|
+
i.set(o), !t && X._isGroupOrSelection(i) && i.getObjects().forEach((c) => {
|
|
2510
2625
|
c.set(o);
|
|
2511
|
-
}), n.renderAll(), s ||
|
|
2512
|
-
object:
|
|
2626
|
+
}), n.renderAll(), s || a.saveState(), n.fire("editor:object-locked", {
|
|
2627
|
+
object: i,
|
|
2513
2628
|
skipInnerObjects: t,
|
|
2514
2629
|
withoutSave: s
|
|
2515
2630
|
});
|
|
@@ -2522,9 +2637,9 @@ class G {
|
|
|
2522
2637
|
* @fires editor:object-unlocked
|
|
2523
2638
|
*/
|
|
2524
2639
|
unlockObject({ object: e, withoutSave: t } = {}) {
|
|
2525
|
-
const { canvas: s, historyManager: n } = this.editor,
|
|
2526
|
-
if (!
|
|
2527
|
-
const
|
|
2640
|
+
const { canvas: s, historyManager: n } = this.editor, a = e || s.getActiveObject();
|
|
2641
|
+
if (!a) return;
|
|
2642
|
+
const i = {
|
|
2528
2643
|
lockMovementX: !1,
|
|
2529
2644
|
lockMovementY: !1,
|
|
2530
2645
|
lockRotation: !1,
|
|
@@ -2534,10 +2649,10 @@ class G {
|
|
|
2534
2649
|
lockSkewingY: !1,
|
|
2535
2650
|
locked: !1
|
|
2536
2651
|
};
|
|
2537
|
-
|
|
2538
|
-
o.set(
|
|
2652
|
+
a.set(i), X._isGroupOrSelection(a) && a.getObjects().forEach((o) => {
|
|
2653
|
+
o.set(i);
|
|
2539
2654
|
}), s.renderAll(), t || n.saveState(), s.fire("editor:object-unlocked", {
|
|
2540
|
-
object:
|
|
2655
|
+
object: a,
|
|
2541
2656
|
withoutSave: t
|
|
2542
2657
|
});
|
|
2543
2658
|
}
|
|
@@ -2545,7 +2660,7 @@ class G {
|
|
|
2545
2660
|
return e instanceof y || e instanceof J;
|
|
2546
2661
|
}
|
|
2547
2662
|
}
|
|
2548
|
-
class
|
|
2663
|
+
class gt {
|
|
2549
2664
|
constructor({ editor: e }) {
|
|
2550
2665
|
this.editor = e;
|
|
2551
2666
|
}
|
|
@@ -2562,11 +2677,11 @@ class ht {
|
|
|
2562
2677
|
} = {}) {
|
|
2563
2678
|
const { canvas: s, historyManager: n } = this.editor;
|
|
2564
2679
|
n.suspendHistory();
|
|
2565
|
-
const
|
|
2566
|
-
if (!
|
|
2567
|
-
const
|
|
2568
|
-
|
|
2569
|
-
object:
|
|
2680
|
+
const a = e || s.getActiveObject();
|
|
2681
|
+
if (!a || !(a instanceof y)) return;
|
|
2682
|
+
const i = a.getObjects(), o = new J(i);
|
|
2683
|
+
i.forEach((d) => s.remove(d)), o.set("id", `${o.type}-${D()}`), s.add(o), s.setActiveObject(o), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:objects-grouped", {
|
|
2684
|
+
object: a,
|
|
2570
2685
|
group: o,
|
|
2571
2686
|
withoutSave: t
|
|
2572
2687
|
});
|
|
@@ -2584,21 +2699,21 @@ class ht {
|
|
|
2584
2699
|
} = {}) {
|
|
2585
2700
|
const { canvas: s, historyManager: n } = this.editor;
|
|
2586
2701
|
n.suspendHistory();
|
|
2587
|
-
const
|
|
2588
|
-
if (!(
|
|
2589
|
-
const
|
|
2590
|
-
s.remove(
|
|
2591
|
-
const o = new y(
|
|
2702
|
+
const a = e || s.getActiveObject();
|
|
2703
|
+
if (!(a instanceof J)) return;
|
|
2704
|
+
const i = a.removeAll();
|
|
2705
|
+
s.remove(a), i.forEach((d) => s.add(d));
|
|
2706
|
+
const o = new y(i, {
|
|
2592
2707
|
canvas: s
|
|
2593
2708
|
});
|
|
2594
2709
|
s.setActiveObject(o), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:objects-ungrouped", {
|
|
2595
|
-
object:
|
|
2710
|
+
object: a,
|
|
2596
2711
|
selection: o,
|
|
2597
2712
|
withoutSave: t
|
|
2598
2713
|
});
|
|
2599
2714
|
}
|
|
2600
2715
|
}
|
|
2601
|
-
class
|
|
2716
|
+
class ut {
|
|
2602
2717
|
constructor({ editor: e }) {
|
|
2603
2718
|
this.editor = e;
|
|
2604
2719
|
}
|
|
@@ -2609,11 +2724,11 @@ class gt {
|
|
|
2609
2724
|
selectAll() {
|
|
2610
2725
|
const { canvas: e, canvasManager: t, objectLockManager: s } = this.editor;
|
|
2611
2726
|
e.discardActiveObject();
|
|
2612
|
-
const n = t.getObjects(),
|
|
2613
|
-
|
|
2727
|
+
const n = t.getObjects(), a = n.some((o) => o.locked), i = n.length > 1 ? new y(t.getObjects(), { canvas: e }) : n[0];
|
|
2728
|
+
a && s.lockObject({ object: i, skipInnerObjects: !0, withoutSave: !0 }), e.setActiveObject(i), e.requestRenderAll(), e.fire("editor:all-objects-selected", { selected: i });
|
|
2614
2729
|
}
|
|
2615
2730
|
}
|
|
2616
|
-
class
|
|
2731
|
+
class Mt {
|
|
2617
2732
|
constructor({ editor: e }) {
|
|
2618
2733
|
this.editor = e;
|
|
2619
2734
|
}
|
|
@@ -2628,20 +2743,20 @@ class ut {
|
|
|
2628
2743
|
objects: e,
|
|
2629
2744
|
withoutSave: t
|
|
2630
2745
|
} = {}) {
|
|
2631
|
-
const { canvas: s, historyManager: n, groupingManager:
|
|
2632
|
-
|
|
2746
|
+
const { canvas: s, historyManager: n, groupingManager: a } = this.editor, i = (e || s.getActiveObjects()).filter((o) => !o.locked);
|
|
2747
|
+
i != null && i.length && (n.suspendHistory(), i.forEach((o) => {
|
|
2633
2748
|
if (o.type === "group" && o.format !== "svg") {
|
|
2634
|
-
|
|
2749
|
+
a.ungroup({ object: o, withoutSave: t }), this.deleteSelectedObjects();
|
|
2635
2750
|
return;
|
|
2636
2751
|
}
|
|
2637
2752
|
s.remove(o);
|
|
2638
2753
|
}), s.discardActiveObject(), s.renderAll(), n.resumeHistory(), t || n.saveState(), s.fire("editor:objects-deleted", {
|
|
2639
|
-
objects:
|
|
2754
|
+
objects: i,
|
|
2640
2755
|
withoutSave: t
|
|
2641
2756
|
}));
|
|
2642
2757
|
}
|
|
2643
2758
|
}
|
|
2644
|
-
const
|
|
2759
|
+
const mt = {
|
|
2645
2760
|
IMAGE_MANAGER: {
|
|
2646
2761
|
/**
|
|
2647
2762
|
* Некорректный Content-Type изображения
|
|
@@ -2687,7 +2802,23 @@ const Mt = {
|
|
|
2687
2802
|
/**
|
|
2688
2803
|
* Ошибка клонирования объекта.
|
|
2689
2804
|
*/
|
|
2690
|
-
CLONE_FAILED: "CLONE_FAILED"
|
|
2805
|
+
CLONE_FAILED: "CLONE_FAILED",
|
|
2806
|
+
/**
|
|
2807
|
+
* Ошибка копирования объекта.
|
|
2808
|
+
*/
|
|
2809
|
+
COPY_FAILED: "COPY_FAILED",
|
|
2810
|
+
/**
|
|
2811
|
+
* Ошибка вставки изображения из буфера обмена.
|
|
2812
|
+
*/
|
|
2813
|
+
PASTE_IMAGE_FAILED: "PASTE_IMAGE_FAILED",
|
|
2814
|
+
/**
|
|
2815
|
+
* Ошибка вставки HTML-изображения из буфера обмена.
|
|
2816
|
+
*/
|
|
2817
|
+
PASTE_HTML_IMAGE_FAILED: "PASTE_HTML_IMAGE_FAILED",
|
|
2818
|
+
/**
|
|
2819
|
+
* Ошибка вставки объекта из буфера обмена.
|
|
2820
|
+
*/
|
|
2821
|
+
PASTE_FAILED: "PASTE_FAILED"
|
|
2691
2822
|
},
|
|
2692
2823
|
/**
|
|
2693
2824
|
* Коды ошибок и предупреждений для CanvasManager.
|
|
@@ -2703,7 +2834,7 @@ const Mt = {
|
|
|
2703
2834
|
REDO_ERROR: "REDO_ERROR"
|
|
2704
2835
|
}
|
|
2705
2836
|
};
|
|
2706
|
-
class
|
|
2837
|
+
class Q {
|
|
2707
2838
|
constructor({ editor: e }) {
|
|
2708
2839
|
this._buffer = [], this.editor = e;
|
|
2709
2840
|
}
|
|
@@ -2729,19 +2860,19 @@ class X {
|
|
|
2729
2860
|
* @param options.message — текст ошибки (опционально, если не передан, то используется код ошибки)
|
|
2730
2861
|
* @fires editor:error
|
|
2731
2862
|
*/
|
|
2732
|
-
emitError({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, data: n, message:
|
|
2733
|
-
if (!
|
|
2863
|
+
emitError({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, data: n, message: a }) {
|
|
2864
|
+
if (!Q.isValidErrorCode(s)) {
|
|
2734
2865
|
console.warn("Неизвестный код ошибки: ", { code: s, origin: e, method: t });
|
|
2735
2866
|
return;
|
|
2736
2867
|
}
|
|
2737
2868
|
if (!s) return;
|
|
2738
|
-
const
|
|
2739
|
-
console.error(`${e}. ${t}. ${s}. ${
|
|
2869
|
+
const i = a || s;
|
|
2870
|
+
console.error(`${e}. ${t}. ${s}. ${i}`, n);
|
|
2740
2871
|
const o = {
|
|
2741
2872
|
code: s,
|
|
2742
2873
|
origin: e,
|
|
2743
2874
|
method: t,
|
|
2744
|
-
message:
|
|
2875
|
+
message: i,
|
|
2745
2876
|
data: n
|
|
2746
2877
|
};
|
|
2747
2878
|
this._buffer.push(p({
|
|
@@ -2758,19 +2889,19 @@ class X {
|
|
|
2758
2889
|
* @param options.message — текст предупреждения (опционально, если не передан, то используется код предупреждения)
|
|
2759
2890
|
* @fires editor:warning
|
|
2760
2891
|
*/
|
|
2761
|
-
emitWarning({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, message: n, data:
|
|
2762
|
-
if (!
|
|
2892
|
+
emitWarning({ origin: e = "ImageEditor", method: t = "Unknown Method", code: s, message: n, data: a }) {
|
|
2893
|
+
if (!Q.isValidErrorCode(s)) {
|
|
2763
2894
|
console.warn("Неизвестный код предупреждения: ", { code: s, origin: e, method: t });
|
|
2764
2895
|
return;
|
|
2765
2896
|
}
|
|
2766
|
-
const
|
|
2767
|
-
console.warn(`${e}. ${t}. ${s}. ${
|
|
2897
|
+
const i = n || s;
|
|
2898
|
+
console.warn(`${e}. ${t}. ${s}. ${i}`, a);
|
|
2768
2899
|
const o = {
|
|
2769
2900
|
code: s,
|
|
2770
2901
|
origin: e,
|
|
2771
2902
|
method: t,
|
|
2772
|
-
message:
|
|
2773
|
-
data:
|
|
2903
|
+
message: i,
|
|
2904
|
+
data: a
|
|
2774
2905
|
};
|
|
2775
2906
|
this._buffer.push(p({
|
|
2776
2907
|
type: "editor:warning"
|
|
@@ -2782,17 +2913,17 @@ class X {
|
|
|
2782
2913
|
* @returns true, если код допустим, иначе false
|
|
2783
2914
|
*/
|
|
2784
2915
|
static isValidErrorCode(e) {
|
|
2785
|
-
return e ? Object.values(
|
|
2916
|
+
return e ? Object.values(mt).some((t) => Object.values(t).includes(e)) : !1;
|
|
2786
2917
|
}
|
|
2787
2918
|
}
|
|
2788
|
-
class
|
|
2919
|
+
class ie {
|
|
2789
2920
|
/**
|
|
2790
2921
|
* Конструктор класса ImageEditor.
|
|
2791
2922
|
* @param canvasId - идентификатор канваса, в котором будет создан редактор
|
|
2792
2923
|
* @param options - опции и настройки редактора
|
|
2793
2924
|
*/
|
|
2794
2925
|
constructor(e, t) {
|
|
2795
|
-
this.options = t, this.containerId = e, this.editorId = `${e}-${
|
|
2926
|
+
this.options = t, this.containerId = e, this.editorId = `${e}-${D()}`, this.clipboard = null, this.init();
|
|
2796
2927
|
}
|
|
2797
2928
|
/**
|
|
2798
2929
|
* Инициализация редактора.
|
|
@@ -2800,29 +2931,29 @@ class ae {
|
|
|
2800
2931
|
* @fires editor:ready
|
|
2801
2932
|
*/
|
|
2802
2933
|
init() {
|
|
2803
|
-
return
|
|
2934
|
+
return j(this, null, function* () {
|
|
2804
2935
|
const {
|
|
2805
2936
|
editorContainerWidth: e,
|
|
2806
2937
|
editorContainerHeight: t,
|
|
2807
2938
|
canvasWrapperWidth: s,
|
|
2808
2939
|
canvasWrapperHeight: n,
|
|
2809
|
-
canvasCSSWidth:
|
|
2810
|
-
canvasCSSHeight:
|
|
2940
|
+
canvasCSSWidth: a,
|
|
2941
|
+
canvasCSSHeight: i,
|
|
2811
2942
|
initialImage: o,
|
|
2812
2943
|
initialStateJSON: d,
|
|
2813
2944
|
scaleType: c,
|
|
2814
|
-
_onReadyCallback:
|
|
2945
|
+
_onReadyCallback: h
|
|
2815
2946
|
} = this.options;
|
|
2816
|
-
if (We.apply(), this.canvas = new
|
|
2947
|
+
if (We.apply(), this.canvas = new Ee(this.containerId, this.options), this.moduleLoader = new xe(), this.workerManager = new _e(), this.errorManager = new Q({ editor: this }), this.historyManager = new et({ editor: this }), this.toolbar = new qe({ editor: this }), this.transformManager = new ct({ editor: this }), this.canvasManager = new rt({ editor: this }), this.imageManager = new E({ editor: this }), this.layerManager = new G({ editor: this }), this.shapeManager = new lt({ editor: this }), this.interactionBlocker = new dt({ editor: this }), this.clipboardManager = new ht({ editor: this }), this.objectLockManager = new X({ editor: this }), this.groupingManager = new gt({ editor: this }), this.selectionManager = new ut({ 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(n), this.canvasManager.setCanvasCSSWidth(a), this.canvasManager.setCanvasCSSHeight(i), o != null && o.source) {
|
|
2817
2948
|
const {
|
|
2818
|
-
source:
|
|
2949
|
+
source: l,
|
|
2819
2950
|
scale: g = `image-${c}`,
|
|
2820
|
-
withoutSave:
|
|
2951
|
+
withoutSave: M = !0
|
|
2821
2952
|
} = o;
|
|
2822
|
-
yield this.imageManager.importImage({ source:
|
|
2953
|
+
yield this.imageManager.importImage({ source: l, scale: g, withoutSave: M });
|
|
2823
2954
|
} else
|
|
2824
2955
|
this.canvasManager.setDefaultScale({ withoutSave: !0 });
|
|
2825
|
-
d && this.historyManager.loadStateFromFullState(d), this.historyManager.saveState(), console.log("editor:ready"), this.canvas.fire("editor:ready", this), typeof
|
|
2956
|
+
d && this.historyManager.loadStateFromFullState(d), this.historyManager.saveState(), console.log("editor:ready"), this.canvas.fire("editor:ready", this), typeof h == "function" && h(this);
|
|
2826
2957
|
});
|
|
2827
2958
|
}
|
|
2828
2959
|
/**
|
|
@@ -2836,7 +2967,7 @@ class ae {
|
|
|
2836
2967
|
this.montageArea = this.shapeManager.addRectangle({
|
|
2837
2968
|
width: e,
|
|
2838
2969
|
height: t,
|
|
2839
|
-
fill:
|
|
2970
|
+
fill: ie._createMosaicPattern(),
|
|
2840
2971
|
stroke: null,
|
|
2841
2972
|
strokeWidth: 0,
|
|
2842
2973
|
selectable: !1,
|
|
@@ -2892,7 +3023,7 @@ class ae {
|
|
|
2892
3023
|
});
|
|
2893
3024
|
}
|
|
2894
3025
|
}
|
|
2895
|
-
const
|
|
3026
|
+
const ft = {
|
|
2896
3027
|
/**
|
|
2897
3028
|
* Опции редактора
|
|
2898
3029
|
*/
|
|
@@ -2964,7 +3095,6 @@ const mt = {
|
|
|
2964
3095
|
defaultScale: 0.5,
|
|
2965
3096
|
minZoom: 0.1,
|
|
2966
3097
|
maxZoom: 2,
|
|
2967
|
-
maxZoomFactor: 2,
|
|
2968
3098
|
zoomRatio: 0.1,
|
|
2969
3099
|
overlayMaskColor: "rgba(136, 136, 136, 0.6)",
|
|
2970
3100
|
/*
|
|
@@ -2983,14 +3113,14 @@ const mt = {
|
|
|
2983
3113
|
keyboardIgnoreSelectors: []
|
|
2984
3114
|
};
|
|
2985
3115
|
function At(r, e = {}) {
|
|
2986
|
-
const t = p(p({},
|
|
3116
|
+
const t = p(p({}, ft), e), s = document.getElementById(r);
|
|
2987
3117
|
if (!s)
|
|
2988
3118
|
return Promise.reject(new Error(`Контейнер с ID "${r}" не найден.`));
|
|
2989
3119
|
const n = document.createElement("canvas");
|
|
2990
|
-
return n.id = `${r}-canvas`, s.appendChild(n), t.editorContainer = s, new Promise((
|
|
2991
|
-
t._onReadyCallback =
|
|
2992
|
-
const
|
|
2993
|
-
window[r] =
|
|
3120
|
+
return n.id = `${r}-canvas`, s.appendChild(n), t.editorContainer = s, new Promise((a) => {
|
|
3121
|
+
t._onReadyCallback = a;
|
|
3122
|
+
const i = new ie(n.id, t);
|
|
3123
|
+
window[r] = i;
|
|
2994
3124
|
});
|
|
2995
3125
|
}
|
|
2996
3126
|
export {
|