@anu3ev/fabric-image-editor 0.1.39 → 0.1.40

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.
Files changed (2) hide show
  1. package/dist/main.js +173 -131
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -1,24 +1,24 @@
1
1
  var Le = Object.defineProperty;
2
- var X = Object.getOwnPropertySymbols;
2
+ var G = Object.getOwnPropertySymbols;
3
3
  var Me = Object.prototype.hasOwnProperty, fe = Object.prototype.propertyIsEnumerable;
4
4
  var me = (o, e, t) => e in o ? Le(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, C = (o, e) => {
5
5
  for (var t in e || (e = {}))
6
6
  Me.call(e, t) && me(o, t, e[t]);
7
- if (X)
8
- for (var t of X(e))
7
+ if (G)
8
+ for (var t of G(e))
9
9
  fe.call(e, t) && me(o, t, e[t]);
10
10
  return o;
11
11
  };
12
- var Q = (o, e) => {
12
+ var X = (o, e) => {
13
13
  var t = {};
14
14
  for (var a in o)
15
15
  Me.call(o, a) && e.indexOf(a) < 0 && (t[a] = o[a]);
16
- if (o != null && X)
17
- for (var a of X(o))
16
+ if (o != null && G)
17
+ for (var a of G(o))
18
18
  e.indexOf(a) < 0 && fe.call(o, a) && (t[a] = o[a]);
19
19
  return t;
20
20
  };
21
- var H = (o, e, t) => new Promise((a, r) => {
21
+ var Q = (o, e, t) => new Promise((a, r) => {
22
22
  var i = (c) => {
23
23
  try {
24
24
  s(t.next(c));
@@ -34,11 +34,11 @@ var H = (o, e, t) => new Promise((a, r) => {
34
34
  }, s = (c) => c.done ? a(c.value) : Promise.resolve(c.value).then(i, n);
35
35
  s((t = t.apply(o, e)).next());
36
36
  });
37
- import { ActiveSelection as W, util as _, controlsUtils as Ee, InteractiveFabricObject as Oe, loadSVGFromURL as Te, FabricImage as q, Point as ke, Rect as xe, Circle as Be, Triangle as Ze, Group as ze, Canvas as Ue, Pattern as Ye } from "fabric";
38
- import { create as He } from "jsondiffpatch";
39
- var Pe = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", S = function() {
37
+ import { ActiveSelection as H, util as P, controlsUtils as Ee, InteractiveFabricObject as Oe, loadSVGFromURL as Te, FabricImage as q, Point as ke, Rect as xe, Circle as Be, Triangle as Ze, Group as ze, Canvas as Ue, Pattern as Ye } from "fabric";
38
+ import { create as _e } from "jsondiffpatch";
39
+ var Re = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", A = function() {
40
40
  for (var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 21, t = "", a = crypto.getRandomValues(new Uint8Array(e |= 0)); e--; )
41
- t += Pe[a[e] & 63];
41
+ t += Re[a[e] & 63];
42
42
  return t;
43
43
  };
44
44
  class R {
@@ -95,7 +95,7 @@ class R {
95
95
  this.canvas.setActiveObject(r[0]);
96
96
  return;
97
97
  }
98
- const i = new W(r, {
98
+ const i = new H(r, {
99
99
  canvas: this.canvas
100
100
  });
101
101
  this.canvas.setActiveObject(i), this.canvas.requestRenderAll();
@@ -157,9 +157,9 @@ class R {
157
157
  * @param {String} event.code — код клавиши
158
158
  */
159
159
  handleUndoRedoEvent(e) {
160
- return H(this, null, function* () {
160
+ return Q(this, null, function* () {
161
161
  const { ctrlKey: t, metaKey: a, code: r, repeat: i } = e;
162
- !t && !a || i || this.isUndoRedoKeyPressed || (r === "KeyZ" ? (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.undo()) : r === "KeyY" && (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.redo()));
162
+ !t && !a || i || !/Mac/i.test(navigator.userAgent) && this.isUndoRedoKeyPressed || (r === "KeyZ" ? (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.undo()) : r === "KeyY" && (e.preventDefault(), this.isUndoRedoKeyPressed = !0, yield this.editor.historyManager.redo()));
163
163
  });
164
164
  }
165
165
  /**
@@ -168,7 +168,7 @@ class R {
168
168
  * @param {String} event.code — код клавиши
169
169
  */
170
170
  handleUndoRedoKeyUp({ code: e }) {
171
- (e === "KeyZ" || e === "KeyY") && (this.isUndoRedoKeyPressed = !1);
171
+ ["KeyZ", "KeyY"].includes(e) && (this.isUndoRedoKeyPressed = !1);
172
172
  }
173
173
  /**
174
174
  * Обработчик для выделения всех объектов (Ctrl+A).
@@ -304,7 +304,7 @@ class R {
304
304
  };
305
305
  }
306
306
  }
307
- class Re {
307
+ class He {
308
308
  /**
309
309
  * @description Класс для динамической загрузки внешних модулей.
310
310
  */
@@ -322,7 +322,7 @@ class Re {
322
322
  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 "'.concat(e, '"')));
323
323
  }
324
324
  }
325
- class We {
325
+ class Pe {
326
326
  /**
327
327
  * @param {string|URL} [scriptUrl] — URL скрипта воркера.
328
328
  * По-умолчанию использует файл рядом с этим модулем
@@ -362,7 +362,7 @@ class We {
362
362
  * @returns {Promise<any>}
363
363
  */
364
364
  post(e, t) {
365
- var a = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [], r = "".concat(e, ":").concat(S(8));
365
+ var a = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [], r = "".concat(e, ":").concat(A(8));
366
366
  return new Promise((i, n) => {
367
367
  this._callbacks.set(r, {
368
368
  resolve: i,
@@ -381,24 +381,24 @@ class We {
381
381
  this.worker.terminate();
382
382
  }
383
383
  }
384
- var I = 12, _e = 2, te = 8, ae = 20, Fe = 100, re = 20, ie = 8, Ve = 100, ne = 32, se = 1, Ge = "#2B2D33", oe = "#3D8BF4", ce = "#FFFFFF";
384
+ var I = 12, We = 2, te = 8, ae = 20, Fe = 100, re = 20, ie = 8, Ve = 100, ne = 32, se = 1, Ge = "#2B2D33", oe = "#3D8BF4", ce = "#FFFFFF";
385
385
  function J(o, e, t, a, r) {
386
- var i = I, n = _e;
387
- o.save(), o.translate(e, t), o.rotate(_.degreesToRadians(r.angle)), o.fillStyle = ce, o.strokeStyle = oe, o.lineWidth = se, o.beginPath(), o.roundRect(-12 / 2, -12 / 2, i, i, n), o.fill(), o.stroke(), o.restore();
386
+ var i = I, n = We;
387
+ o.save(), o.translate(e, t), o.rotate(P.degreesToRadians(r.angle)), o.fillStyle = ce, o.strokeStyle = oe, o.lineWidth = se, o.beginPath(), o.roundRect(-12 / 2, -12 / 2, i, i, n), o.fill(), o.stroke(), o.restore();
388
388
  }
389
389
  function je(o, e, t, a, r) {
390
390
  var i = te, n = ae, s = Fe;
391
- o.save(), o.translate(e, t), o.rotate(_.degreesToRadians(r.angle)), o.fillStyle = ce, o.strokeStyle = oe, o.lineWidth = se, o.beginPath(), o.roundRect(-8 / 2, -20 / 2, i, n, s), o.fill(), o.stroke(), o.restore();
391
+ o.save(), o.translate(e, t), o.rotate(P.degreesToRadians(r.angle)), o.fillStyle = ce, o.strokeStyle = oe, o.lineWidth = se, o.beginPath(), o.roundRect(-8 / 2, -20 / 2, i, n, s), o.fill(), o.stroke(), o.restore();
392
392
  }
393
393
  function ye(o, e, t, a, r) {
394
394
  var i = re, n = ie, s = Ve;
395
- o.save(), o.translate(e, t), o.rotate(_.degreesToRadians(r.angle)), o.fillStyle = ce, o.strokeStyle = oe, o.lineWidth = se, o.beginPath(), o.roundRect(-20 / 2, -8 / 2, i, n, s), o.fill(), o.stroke(), o.restore();
395
+ o.save(), o.translate(e, t), o.rotate(P.degreesToRadians(r.angle)), o.fillStyle = ce, o.strokeStyle = oe, o.lineWidth = se, o.beginPath(), o.roundRect(-20 / 2, -8 / 2, i, n, s), o.fill(), o.stroke(), o.restore();
396
396
  }
397
- var Xe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", Ae = new Image();
398
- Ae.src = Xe;
397
+ var Xe = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE4Ljc1IDQuMzc1djMuNzVhLjYyNS42MjUgMCAwIDEtLjYyNS42MjVoLTMuNzVhLjYyNS42MjUgMCAwIDEgMC0xLjI1aDIuMTRsLTIuMDc3LTEuOTAzLS4wMi0uMDE5YTYuMjUgNi4yNSAwIDEgMC0uMTMgOC45NjcuNjI2LjYyNiAwIDAgMSAuODYuOTA5QTcuNDU2IDcuNDU2IDAgMCAxIDEwIDE3LjVoLS4xMDNhNy41IDcuNSAwIDEgMSA1LjM5Ni0xMi44MTJMMTcuNSA2LjcwM1Y0LjM3NWEuNjI1LjYyNSAwIDAgMSAxLjI1IDBaIi8+PC9zdmc+", Se = new Image();
398
+ Se.src = Xe;
399
399
  function Qe(o, e, t, a, r) {
400
400
  var i = ne, n = i / 2;
401
- o.save(), o.translate(e, t), o.rotate(_.degreesToRadians(r.angle)), o.fillStyle = Ge, o.beginPath(), o.arc(0, 0, n, 0, 2 * Math.PI), o.fill(), o.drawImage(Ae, -16 / 2, -16 / 2, n, n), o.restore();
401
+ o.save(), o.translate(e, t), o.rotate(P.degreesToRadians(r.angle)), o.fillStyle = Ge, o.beginPath(), o.arc(0, 0, n, 0, 2 * Math.PI), o.fill(), o.drawImage(Se, -16 / 2, -16 / 2, n, n), o.restore();
402
402
  }
403
403
  var Je = {
404
404
  // Угловые точки
@@ -511,7 +511,7 @@ function st(o) {
511
511
  });
512
512
  };
513
513
  }
514
- const P = {
514
+ const _ = {
515
515
  style: {
516
516
  position: "absolute",
517
517
  display: "none",
@@ -662,11 +662,11 @@ class dt {
662
662
  if (this.options = t.options, !!this.options.showToolbar) {
663
663
  this.editor = t, this.canvas = t.canvas;
664
664
  var a = this.options.toolbar || {};
665
- this.config = j(j(j({}, P), a), {}, {
666
- style: j(j({}, P.style), a.style || {}),
667
- btnStyle: j(j({}, P.btnStyle), a.btnStyle || {}),
668
- icons: j(j({}, P.icons), a.icons || {}),
669
- handlers: j(j({}, P.handlers), a.handlers || {})
665
+ this.config = j(j(j({}, _), a), {}, {
666
+ style: j(j({}, _.style), a.style || {}),
667
+ btnStyle: j(j({}, _.btnStyle), a.btnStyle || {}),
668
+ icons: j(j({}, _.icons), a.icons || {}),
669
+ handlers: j(j({}, _.handlers), a.handlers || {})
670
670
  }), this.currentTarget = null, this.currentLocked = null, 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 = () => {
671
671
  this.el.style.display = "none";
672
672
  }, this._createDOM(), this._bindEvents();
@@ -844,7 +844,7 @@ class lt {
844
844
  return this.patches[this.currentIndex - 1] || null;
845
845
  }
846
846
  _createDiffPatcher() {
847
- this.diffPatcher = He({
847
+ this.diffPatcher = _e({
848
848
  objectHash(e) {
849
849
  return [e.id, e.format, e.locked, e.left, e.top, e.width, e.height, e.flipX, e.flipY, e.scaleX, e.scaleY, e.angle, e.opacity].join("-");
850
850
  },
@@ -908,7 +908,7 @@ class lt {
908
908
  return;
909
909
  }
910
910
  console.log("baseState", this.baseState), this.currentIndex < this.patches.length && this.patches.splice(this.currentIndex), console.log("diff", a), this.totalChangesCount += 1, this.patches.push({
911
- id: S(),
911
+ id: A(),
912
912
  diff: a
913
913
  }), 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);
914
914
  }
@@ -1002,7 +1002,7 @@ class lt {
1002
1002
  }
1003
1003
  }
1004
1004
  const ht = 0.1, gt = 2, vt = 0.1, mt = 90, k = 16, x = 16, E = 4096, O = 4096;
1005
- function Se(o, e, t, a, r, i, n) {
1005
+ function Ae(o, e, t, a, r, i, n) {
1006
1006
  try {
1007
1007
  var s = o[i](n), c = s.value;
1008
1008
  } catch (u) {
@@ -1016,16 +1016,16 @@ function T(o) {
1016
1016
  return new Promise(function(a, r) {
1017
1017
  var i = o.apply(e, t);
1018
1018
  function n(c) {
1019
- Se(i, a, r, n, s, "next", c);
1019
+ Ae(i, a, r, n, s, "next", c);
1020
1020
  }
1021
1021
  function s(c) {
1022
- Se(i, a, r, n, s, "throw", c);
1022
+ Ae(i, a, r, n, s, "throw", c);
1023
1023
  }
1024
1024
  n(void 0);
1025
1025
  });
1026
1026
  };
1027
1027
  }
1028
- class w {
1028
+ class D {
1029
1029
  /**
1030
1030
  * @param {object} options
1031
1031
  * @param {ImageEditor} options.editor - экземпляр редактора с доступом к canvas
@@ -1063,7 +1063,7 @@ class w {
1063
1063
  transformManager: c,
1064
1064
  historyManager: u,
1065
1065
  errorManager: d
1066
- } = t.editor, l = yield t.getContentType(a), h = w.getFormatFromContentType(l), {
1066
+ } = t.editor, l = yield t.getContentType(a), h = D.getFormatFromContentType(l), {
1067
1067
  acceptContentTypes: g,
1068
1068
  acceptFormats: M
1069
1069
  } = t;
@@ -1089,13 +1089,13 @@ class w {
1089
1089
  if (a instanceof File)
1090
1090
  f = URL.createObjectURL(a);
1091
1091
  else if (typeof a == "string") {
1092
- var A = yield fetch(a, {
1092
+ var S = yield fetch(a, {
1093
1093
  mode: "cors"
1094
- }), D = yield A.blob({
1094
+ }), N = yield S.blob({
1095
1095
  type: l,
1096
1096
  quality: 1
1097
1097
  });
1098
- f = URL.createObjectURL(D);
1098
+ f = URL.createObjectURL(N);
1099
1099
  } else
1100
1100
  return d.emitError({
1101
1101
  origin: "ImageManager",
@@ -1111,8 +1111,8 @@ class w {
1111
1111
  }
1112
1112
  }), null;
1113
1113
  if (t._createdBlobUrls.push(f), h === "svg") {
1114
- var N = yield Te(f);
1115
- v = _.groupSVGElements(N.objects, N.options);
1114
+ var w = yield Te(f);
1115
+ v = P.groupSVGElements(w.objects, w.options);
1116
1116
  } else
1117
1117
  v = yield q.fromURL(f, {
1118
1118
  crossOrigin: "anonymous"
@@ -1127,19 +1127,19 @@ class w {
1127
1127
  crossOrigin: "anonymous"
1128
1128
  });
1129
1129
  } else if (y < x || L < k) {
1130
- var F = yield t.resizeImageToBoundaries(v._element.src, "min"), Z = URL.createObjectURL(F);
1130
+ var W = yield t.resizeImageToBoundaries(v._element.src, "min"), Z = URL.createObjectURL(W);
1131
1131
  t._createdBlobUrls.push(Z), v = yield q.fromURL(Z, {
1132
1132
  crossOrigin: "anonymous"
1133
1133
  });
1134
1134
  }
1135
- if (v.set("id", "".concat(v.type, "-").concat(S())), v.set("format", h), r === "scale-montage")
1135
+ if (v.set("id", "".concat(v.type, "-").concat(A())), v.set("format", h), r === "scale-montage")
1136
1136
  t.editor.canvasManager.scaleMontageAreaToImage({
1137
1137
  object: v,
1138
1138
  withoutSave: !0
1139
1139
  });
1140
1140
  else {
1141
1141
  var {
1142
- width: V,
1142
+ width: F,
1143
1143
  height: z
1144
1144
  } = s, U = t.calculateScaleFactor({
1145
1145
  imageObject: v,
@@ -1149,14 +1149,14 @@ class w {
1149
1149
  object: v,
1150
1150
  type: "contain",
1151
1151
  withoutSave: !0
1152
- }) : r === "image-cover" && (L > V || y > z) && c.fitObject({
1152
+ }) : r === "image-cover" && (L > F || y > z) && c.fitObject({
1153
1153
  object: v,
1154
1154
  type: "cover",
1155
1155
  withoutSave: !0
1156
1156
  });
1157
1157
  }
1158
1158
  n.add(v), n.centerObject(v), n.setActiveObject(v), n.renderAll(), u.resumeHistory(), i || u.saveState();
1159
- var G = {
1159
+ var V = {
1160
1160
  image: v,
1161
1161
  format: h,
1162
1162
  contentType: l,
@@ -1164,7 +1164,7 @@ class w {
1164
1164
  withoutSave: i,
1165
1165
  source: a
1166
1166
  };
1167
- return n.fire("editor:image-imported", G), G;
1167
+ return n.fire("editor:image-imported", V), V;
1168
1168
  } catch (Y) {
1169
1169
  return d.emitError({
1170
1170
  origin: "ImageManager",
@@ -1237,7 +1237,7 @@ class w {
1237
1237
  workerManager: u
1238
1238
  } = t.editor;
1239
1239
  try {
1240
- var d = r === "application/pdf", l = d ? "image/jpg" : r, h = w.getFormatFromContentType(l);
1240
+ var d = r === "application/pdf", l = d ? "image/jpg" : r, h = D.getFormatFromContentType(l);
1241
1241
  c.setCoords();
1242
1242
  var {
1243
1243
  left: g,
@@ -1246,18 +1246,18 @@ class w {
1246
1246
  height: f
1247
1247
  } = c.getBoundingRect(), v = yield s.clone(["id", "format", "locked"]);
1248
1248
  ["image/jpg", "image/jpeg"].includes(l) && (v.backgroundColor = "#ffffff");
1249
- var A = v.getObjects().find((b) => b.id === c.id);
1250
- A.visible = !1, v.viewportTransform = [1, 0, 0, 1, -g, -M], v.setDimensions({
1249
+ var S = v.getObjects().find((b) => b.id === c.id);
1250
+ S.visible = !1, v.viewportTransform = [1, 0, 0, 1, -g, -M], v.setDimensions({
1251
1251
  width: m,
1252
1252
  height: f
1253
1253
  }, {
1254
1254
  backstoreOnly: !0
1255
1255
  }), v.renderAll();
1256
- var D = v.getObjects().filter((b) => b.format).every((b) => b.format === "svg");
1257
- if (h === "svg" && D) {
1258
- var N = v.toSVG();
1256
+ var N = v.getObjects().filter((b) => b.format).every((b) => b.format === "svg");
1257
+ if (h === "svg" && N) {
1258
+ var w = v.toSVG();
1259
1259
  v.dispose();
1260
- var L = w._exportSVGStringAsFile(N, {
1260
+ var L = D._exportSVGStringAsFile(w, {
1261
1261
  exportAsBase64: i,
1262
1262
  exportAsBlob: n,
1263
1263
  fileName: a
@@ -1281,13 +1281,13 @@ class w {
1281
1281
  };
1282
1282
  return s.fire("editor:canvas-exported", B), B;
1283
1283
  }
1284
- var F = yield createImageBitmap(p), Z = yield u.post("toDataURL", {
1284
+ var W = yield createImageBitmap(p), Z = yield u.post("toDataURL", {
1285
1285
  format: h,
1286
1286
  quality: 1,
1287
- bitmap: F
1288
- }, [F]);
1287
+ bitmap: W
1288
+ }, [W]);
1289
1289
  if (d) {
1290
- var V = 0.264583, z = m * V, U = f * V, G = (yield t.editor.moduleLoader.loadModule("jspdf")).jsPDF, Y = new G({
1290
+ var F = 0.264583, z = m * F, U = f * F, V = (yield t.editor.moduleLoader.loadModule("jspdf")).jsPDF, Y = new V({
1291
1291
  orientation: z > U ? "landscape" : "portrait",
1292
1292
  unit: "mm",
1293
1293
  format: [z, U]
@@ -1301,10 +1301,10 @@ class w {
1301
1301
  };
1302
1302
  return s.fire("editor:canvas-exported", de), de;
1303
1303
  }
1304
- var we = Y.output("blob"), De = new File([we], a, {
1304
+ var De = Y.output("blob"), Ne = new File([De], a, {
1305
1305
  type: "application/pdf"
1306
1306
  }), le = {
1307
- image: De,
1307
+ image: Ne,
1308
1308
  format: "pdf",
1309
1309
  contentType: "application/pdf",
1310
1310
  fileName: a
@@ -1320,10 +1320,10 @@ class w {
1320
1320
  };
1321
1321
  return s.fire("editor:canvas-exported", he), he;
1322
1322
  }
1323
- var ge = h === "svg" && !D ? a.replace(/\.[^/.]+$/, ".png") : a, Ne = new File([p], ge, {
1323
+ var ge = h === "svg" && !N ? a.replace(/\.[^/.]+$/, ".png") : a, we = new File([p], ge, {
1324
1324
  type: l
1325
1325
  }), ve = {
1326
- image: Ne,
1326
+ image: we,
1327
1327
  format: h,
1328
1328
  contentType: l,
1329
1329
  fileName: ge
@@ -1383,7 +1383,7 @@ class w {
1383
1383
  }
1384
1384
  }), "";
1385
1385
  try {
1386
- var l = w.getFormatFromContentType(i);
1386
+ var l = D.getFormatFromContentType(i);
1387
1387
  if (l === "svg") {
1388
1388
  var h = d.toSVG(), g = t._exportSVGStringAsFile(h, {
1389
1389
  exportAsBase64: n,
@@ -1410,19 +1410,19 @@ class w {
1410
1410
  };
1411
1411
  return c.fire("editor:object-exported", v), v;
1412
1412
  }
1413
- var A = d.toCanvasElement(), D = yield new Promise((p) => {
1414
- A.toBlob(p);
1413
+ var S = d.toCanvasElement(), N = yield new Promise((p) => {
1414
+ S.toBlob(p);
1415
1415
  });
1416
1416
  if (s) {
1417
- var N = {
1418
- image: D,
1417
+ var w = {
1418
+ image: N,
1419
1419
  format: l,
1420
1420
  contentType: i,
1421
1421
  fileName: r
1422
1422
  };
1423
- return c.fire("editor:object-exported", N), N;
1423
+ return c.fire("editor:object-exported", w), w;
1424
1424
  }
1425
- var L = new File([D], r, {
1425
+ var L = new File([N], r, {
1426
1426
  type: i
1427
1427
  }), y = {
1428
1428
  image: L,
@@ -1482,7 +1482,7 @@ class w {
1482
1482
  * @returns {string[]} - массив допустимых форматов изображений
1483
1483
  */
1484
1484
  getAllowedFormatsFromContentTypes() {
1485
- return this.acceptContentTypes.map((e) => w.getFormatFromContentType(e)).filter((e) => e);
1485
+ return this.acceptContentTypes.map((e) => D.getFormatFromContentType(e)).filter((e) => e);
1486
1486
  }
1487
1487
  /**
1488
1488
  * Извлекает чистый формат (subtype) из contentType,
@@ -1551,7 +1551,7 @@ class w {
1551
1551
  try {
1552
1552
  var t, a = new URL(e), r = (t = a.pathname.split(".").pop()) === null || t === void 0 ? void 0 : t.toLowerCase(), i = {};
1553
1553
  return this.acceptContentTypes.forEach((n) => {
1554
- var s = w.getFormatFromContentType(n);
1554
+ var s = D.getFormatFromContentType(n);
1555
1555
  s && (i[s] = n);
1556
1556
  }), i[r] || "application/octet-stream";
1557
1557
  } catch (n) {
@@ -1959,8 +1959,8 @@ class Mt {
1959
1959
  var {
1960
1960
  width: M,
1961
1961
  height: m
1962
- } = i, f = d / M, v = l / m, A = Math.max(f, v);
1963
- h = M * A, g = m * A;
1962
+ } = i, f = d / M, v = l / m, S = Math.max(f, v);
1963
+ h = M * S, g = m * S;
1964
1964
  }
1965
1965
  this.setResolutionWidth(h, {
1966
1966
  withoutSave: !0
@@ -2234,7 +2234,7 @@ class ft {
2234
2234
  });
2235
2235
  h.scale(g), i.centerObject(h);
2236
2236
  });
2237
- var d = new W(u, {
2237
+ var d = new H(u, {
2238
2238
  canvas: i
2239
2239
  });
2240
2240
  i.setActiveObject(d);
@@ -2588,13 +2588,13 @@ class yt {
2588
2588
  */
2589
2589
  addRectangle(d = {}, { withoutSelection: c, withoutAdding: u } = {}) {
2590
2590
  var l = d, {
2591
- id: e = `rect-${S()}`,
2591
+ id: e = `rect-${A()}`,
2592
2592
  left: t,
2593
2593
  top: a,
2594
2594
  width: r = 100,
2595
2595
  height: i = 100,
2596
2596
  fill: n = "blue"
2597
- } = l, s = Q(l, [
2597
+ } = l, s = X(l, [
2598
2598
  "id",
2599
2599
  "left",
2600
2600
  "top",
@@ -2630,12 +2630,12 @@ class yt {
2630
2630
  */
2631
2631
  addCircle(u = {}, { withoutSelection: s, withoutAdding: c } = {}) {
2632
2632
  var d = u, {
2633
- id: e = `circle-${S()}`,
2633
+ id: e = `circle-${A()}`,
2634
2634
  left: t,
2635
2635
  top: a,
2636
2636
  radius: r = 50,
2637
2637
  fill: i = "green"
2638
- } = d, n = Q(d, [
2638
+ } = d, n = X(d, [
2639
2639
  "id",
2640
2640
  "left",
2641
2641
  "top",
@@ -2670,13 +2670,13 @@ class yt {
2670
2670
  */
2671
2671
  addTriangle(d = {}, { withoutSelection: c, withoutAdding: u } = {}) {
2672
2672
  var l = d, {
2673
- id: e = `triangle-${S()}`,
2673
+ id: e = `triangle-${A()}`,
2674
2674
  left: t,
2675
2675
  top: a,
2676
2676
  width: r = 100,
2677
2677
  height: i = 100,
2678
2678
  fill: n = "yellow"
2679
- } = l, s = Q(l, [
2679
+ } = l, s = X(l, [
2680
2680
  "id",
2681
2681
  "left",
2682
2682
  "top",
@@ -2708,48 +2708,69 @@ class pt {
2708
2708
  * @fires editor:object-copied
2709
2709
  */
2710
2710
  copy() {
2711
- return H(this, null, function* () {
2712
- const { canvas: e } = this.editor, t = e.getActiveObject();
2713
- if (t)
2714
- try {
2715
- const a = yield t.clone(["format"]);
2716
- if (this.clipboard = a, typeof ClipboardItem == "undefined" || !navigator.clipboard) {
2717
- console.warn(
2718
- // eslint-disable-next-line max-len
2719
- "ClipboardManager. navigator.clipboard не поддерживается в этом браузере или отсутствует соединение по HTTPS-протоколу."
2720
- ), e.fire("editor:object-copied", { object: a });
2721
- return;
2722
- }
2723
- if (this.clipboard.type !== "image") {
2724
- yield navigator.clipboard.writeText(`application/image-editor:${JSON.stringify(a)}`), e.fire("editor:object-copied", { object: a });
2725
- return;
2726
- }
2727
- const r = a.toCanvasElement(), i = yield new Promise((s) => {
2728
- r.toBlob(s);
2729
- });
2730
- if (!i) return;
2731
- const n = new ClipboardItem({ [i.type]: i });
2732
- yield navigator.clipboard.write([n]), e.fire("editor:object-copied", { object: a });
2733
- } catch (a) {
2734
- if (!(a instanceof Error)) return;
2735
- const r = "ClipboardManager. Ошибка записи в системный буфер обмена:";
2736
- console.error(r, a), e.fire("editor:error", {
2737
- message: `${r} ${a.message}`
2738
- });
2739
- }
2711
+ const { canvas: e, errorManager: t } = this.editor, a = e.getActiveObject();
2712
+ if (!a) return;
2713
+ if (typeof ClipboardItem == "undefined" || !navigator.clipboard)
2714
+ return t.emitWarning({
2715
+ origin: "ClipboardManager",
2716
+ method: "copy",
2717
+ code: "CLIPBOARD_NOT_SUPPORTED",
2718
+ message: "ClipboardManager. navigator.clipboard не поддерживается в этом браузере или отсутствует соединение по HTTPS-протоколу."
2719
+ }), this._cloneAndFire(e, a);
2720
+ if (a.type !== "image") {
2721
+ const h = `application/image-editor:${JSON.stringify(a.toObject(["format"]))}`;
2722
+ return navigator.clipboard.writeText(h).catch((g) => {
2723
+ t.emitWarning({
2724
+ origin: "ClipboardManager",
2725
+ method: "copy",
2726
+ code: "CLIPBOARD_WRITE_TEXT_FAILED",
2727
+ message: `Ошибка записи текстового объекта в буфер обмена: ${g.message}`,
2728
+ data: g
2729
+ });
2730
+ }), this._cloneAndFire(e, a);
2731
+ }
2732
+ const i = a.toCanvasElement().toDataURL(), n = i.slice(5).split(";")[0], s = i.split(",")[1], c = atob(s), u = new Uint8Array(c.length);
2733
+ for (let h = 0; h < c.length; h++)
2734
+ u[h] = c.charCodeAt(h);
2735
+ const d = new Blob([u.buffer], { type: n }), l = new ClipboardItem({ [n]: d });
2736
+ navigator.clipboard.write([l]).catch((h) => {
2737
+ t.emitWarning({
2738
+ origin: "ClipboardManager",
2739
+ method: "copy",
2740
+ code: "CLIPBOARD_WRITE_IMAGE_FAILED",
2741
+ message: `Ошибка записи изображения в буфер обмена: ${h.message}`
2742
+ });
2743
+ }), this._cloneAndFire(e, a);
2744
+ }
2745
+ /**
2746
+ * Клонирует объект и вызывает событие 'editor:object-copied'.
2747
+ * @param canvas - экземпляр canvas
2748
+ * @param object - активный объект
2749
+ */
2750
+ _cloneAndFire(e, t) {
2751
+ t.clone(["format"]).then((a) => {
2752
+ this.clipboard = a, e.fire("editor:object-copied", { object: a });
2753
+ }).catch((a) => {
2754
+ this.editor.errorManager.emitError({
2755
+ origin: "ClipboardManager",
2756
+ method: "_cloneAndFire",
2757
+ code: "CLONE_FAILED",
2758
+ message: "ClipboardManager. Ошибка клонирования объекта",
2759
+ data: a
2760
+ });
2740
2761
  });
2741
2762
  }
2742
2763
  /**
2743
- * Обработчик вставки объекта или изображения из буфера обмена.
2744
- * @param {Object} event — объект события
2745
- * @param {Object} event.clipboardData — данные из буфера обмена
2746
- * @param {Array} event.clipboardData.items — элементы буфера обмена
2747
- */
2764
+ * Обработчик вставки объекта или изображения из буфера обмена.
2765
+ * @param {Object} event — объект события
2766
+ * @param {Object} event.clipboardData — данные из буфера обмена
2767
+ * @param {Array} event.clipboardData.items — элементы буфера обмена
2768
+ */
2748
2769
  handlePasteEvent({ clipboardData: e }) {
2749
2770
  var n;
2750
2771
  if (!((n = e == null ? void 0 : e.items) != null && n.length)) return;
2751
2772
  const { imageManager: t } = this.editor, { items: a } = e, r = a[a.length - 1];
2752
- if (console.log("handlePasteEvent clipboardData", e), console.log("handlePasteEvent lastItem", r), r.type !== "text/html") {
2773
+ if (r.type !== "text/html") {
2753
2774
  const s = r.getAsFile();
2754
2775
  if (!s) return;
2755
2776
  const c = new FileReader();
@@ -2773,16 +2794,16 @@ class pt {
2773
2794
  * @fires editor:object-pasted
2774
2795
  */
2775
2796
  paste() {
2776
- return H(this, null, function* () {
2797
+ return Q(this, null, function* () {
2777
2798
  const { canvas: e } = this.editor;
2778
2799
  if (!this.clipboard) return;
2779
2800
  const t = yield this.clipboard.clone(["format"]);
2780
2801
  e.discardActiveObject(), t.set({
2781
- id: `${t.type}-${S()}`,
2802
+ id: `${t.type}-${A()}`,
2782
2803
  left: t.left + 10,
2783
2804
  top: t.top + 10,
2784
2805
  evented: !0
2785
- }), t instanceof W ? (t.canvas = e, t.forEachObject((a) => {
2806
+ }), t instanceof H ? (t.canvas = e, t.forEachObject((a) => {
2786
2807
  e.add(a);
2787
2808
  })) : e.add(t), e.setActiveObject(t), e.requestRenderAll(), e.fire("editor:object-pasted", { object: t });
2788
2809
  });
@@ -2901,7 +2922,7 @@ class It {
2901
2922
  var i = e || a.getActiveObject();
2902
2923
  if (i && i.type === "activeselection") {
2903
2924
  var n = i.getObjects(), s = new ze(n);
2904
- n.forEach((c) => a.remove(c)), s.set("id", "".concat(s.type, "-").concat(S())), a.add(s), a.setActiveObject(s), a.renderAll(), r.resumeHistory(), t || r.saveState(), a.fire("editor:objects-grouped", {
2925
+ n.forEach((c) => a.remove(c)), s.set("id", "".concat(s.type, "-").concat(A())), a.add(s), a.setActiveObject(s), a.renderAll(), r.resumeHistory(), t || r.saveState(), a.fire("editor:objects-grouped", {
2905
2926
  object: i,
2906
2927
  group: s,
2907
2928
  withoutSave: t
@@ -2928,7 +2949,7 @@ class It {
2928
2949
  if (!(!i || i.type !== "group")) {
2929
2950
  var n = i.removeAll();
2930
2951
  a.remove(i), n.forEach((c) => a.add(c));
2931
- var s = new W(n, {
2952
+ var s = new H(n, {
2932
2953
  canvas: a
2933
2954
  });
2934
2955
  a.setActiveObject(s), a.renderAll(), r.resumeHistory(), t || r.saveState(), a.fire("editor:objects-ungrouped", {
@@ -2939,7 +2960,7 @@ class It {
2939
2960
  }
2940
2961
  }
2941
2962
  }
2942
- class St {
2963
+ class At {
2943
2964
  /**
2944
2965
  * @param {object} options
2945
2966
  * @param {ImageEditor} options.editor - экземпляр редактора с доступом к canvas
@@ -2961,7 +2982,7 @@ class St {
2961
2982
  objectLockManager: a
2962
2983
  } = this.editor;
2963
2984
  e.discardActiveObject();
2964
- var r = t.getObjects(), i = r.some((s) => s.locked), n = r.length > 1 ? new W(t.getObjects(), {
2985
+ var r = t.getObjects(), i = r.some((s) => s.locked), n = r.length > 1 ? new H(t.getObjects(), {
2965
2986
  canvas: e
2966
2987
  }) : r[0];
2967
2988
  i && a.lockObject({
@@ -2973,7 +2994,7 @@ class St {
2973
2994
  });
2974
2995
  }
2975
2996
  }
2976
- class At {
2997
+ class St {
2977
2998
  /**
2978
2999
  * @param {object} options
2979
3000
  * @param {ImageEditor} options.editor - экземпляр редактора с доступом к canvas
@@ -3038,6 +3059,27 @@ var Ct = {
3038
3059
  * Ошибка при экспорте изображения
3039
3060
  */
3040
3061
  IMAGE_EXPORT_FAILED: "IMAGE_EXPORT_FAILED"
3062
+ },
3063
+ /**
3064
+ * Коды ошибок и предупреждений для ClipboardManager.
3065
+ */
3066
+ CLIPBOARD_CODES: {
3067
+ /**
3068
+ * Буфер обмена не поддерживается в браузере или отсутствует HTTPS-соединение.
3069
+ */
3070
+ CLIPBOARD_NOT_SUPPORTED: "CLIPBOARD_NOT_SUPPORTED",
3071
+ /**
3072
+ * Ошибка записи текстового объекта в буфер обмена.
3073
+ */
3074
+ CLIPBOARD_WRITE_TEXT_FAILED: "CLIPBOARD_WRITE_TEXT_FAILED",
3075
+ /**
3076
+ * Ошибка записи изображения в буфер обмена.
3077
+ */
3078
+ CLIPBOARD_WRITE_IMAGE_FAILED: "CLIPBOARD_WRITE_IMAGE_FAILED",
3079
+ /**
3080
+ * Ошибка клонирования объекта.
3081
+ */
3082
+ CLONE_FAILED: "CLONE_FAILED"
3041
3083
  }
3042
3084
  };
3043
3085
  class $ {
@@ -3120,10 +3162,10 @@ class ue {
3120
3162
  constructor(e, t) {
3121
3163
  this.options = t;
3122
3164
  const { defaultScale: a, minZoom: r, maxZoom: i } = t;
3123
- this.containerId = e, this.editorId = `${e}-${S()}`, this.clipboard = null, this.defaultZoom = a, this.minZoom = r || ht, this.maxZoom = i || gt, this.init();
3165
+ this.containerId = e, this.editorId = `${e}-${A()}`, this.clipboard = null, this.defaultZoom = a, this.minZoom = r || ht, this.maxZoom = i || gt, this.init();
3124
3166
  }
3125
3167
  init() {
3126
- return H(this, null, function* () {
3168
+ return Q(this, null, function* () {
3127
3169
  const {
3128
3170
  editorContainerWidth: e,
3129
3171
  editorContainerHeight: t,
@@ -3136,7 +3178,7 @@ class ue {
3136
3178
  scaleType: u,
3137
3179
  _onReadyCallback: d
3138
3180
  } = this.options;
3139
- if (Ke.apply(), this.canvas = new Ue(this.containerId, this.options), this.moduleLoader = new Re(), this.workerManager = new We(), this.errorManager = new $({ editor: this }), this.historyManager = new lt({ editor: this }), this.toolbar = new dt({ editor: this }), this.transformManager = new ft({ editor: this }), this.canvasManager = new Mt({ editor: this }), this.imageManager = new w({ editor: this }), this.layerManager = new K({ editor: this }), this.shapeManager = new yt({ editor: this }), this.interactionBlocker = new jt({ editor: this }), this.clipboardManager = new pt({ editor: this }), this.objectLockManager = new bt({ editor: this }), this.groupingManager = new It({ editor: this }), this.selectionManager = new St({ editor: this }), this.deletionManager = new At({ editor: this }), this._createMontageArea(), this._createClippingArea(), this.listeners = new R({ editor: this, options: this.options }), this.canvasManager.setEditorContainerWidth(e), this.canvasManager.setEditorContainerHeight(t), this.canvasManager.setCanvasWrapperWidth(a), this.canvasManager.setCanvasWrapperHeight(r), this.canvasManager.setCanvasCSSWidth(i), this.canvasManager.setCanvasCSSHeight(n), s != null && s.source) {
3181
+ if (Ke.apply(), this.canvas = new Ue(this.containerId, this.options), this.moduleLoader = new He(), this.workerManager = new Pe(), this.errorManager = new $({ editor: this }), this.historyManager = new lt({ editor: this }), this.toolbar = new dt({ editor: this }), this.transformManager = new ft({ editor: this }), this.canvasManager = new Mt({ editor: this }), this.imageManager = new D({ editor: this }), this.layerManager = new K({ editor: this }), this.shapeManager = new yt({ editor: this }), this.interactionBlocker = new jt({ editor: this }), this.clipboardManager = new pt({ editor: this }), this.objectLockManager = new bt({ editor: this }), this.groupingManager = new It({ editor: this }), this.selectionManager = new At({ editor: this }), this.deletionManager = new St({ editor: this }), this._createMontageArea(), this._createClippingArea(), this.listeners = new R({ editor: this, options: this.options }), this.canvasManager.setEditorContainerWidth(e), this.canvasManager.setEditorContainerHeight(t), this.canvasManager.setCanvasWrapperWidth(a), this.canvasManager.setCanvasWrapperHeight(r), this.canvasManager.setCanvasCSSWidth(i), this.canvasManager.setCanvasCSSHeight(n), s != null && s.source) {
3140
3182
  const {
3141
3183
  source: l,
3142
3184
  scale: h = `image-${u}`,
@@ -3206,7 +3248,7 @@ class ue {
3206
3248
  });
3207
3249
  }
3208
3250
  }
3209
- const wt = {
3251
+ const Dt = {
3210
3252
  /**
3211
3253
  * Опции редактора
3212
3254
  */
@@ -3295,7 +3337,7 @@ const wt = {
3295
3337
  resetObjectFitByDoubleClick: !0
3296
3338
  };
3297
3339
  function Et(o, e = {}) {
3298
- const t = C(C({}, wt), e), a = document.getElementById(o);
3340
+ const t = C(C({}, Dt), e), a = document.getElementById(o);
3299
3341
  if (!a)
3300
3342
  return Promise.reject(new Error(`Контейнер с ID "${o}" не найден.`));
3301
3343
  const r = document.createElement("canvas");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anu3ev/fabric-image-editor",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "JavaScript image editor built on FabricJS, allowing you to create instances with an integrated montage area and providing an API to modify and manage state.",
5
5
  "module": "dist/main.js",
6
6
  "files": [
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "type": "module",
10
10
  "scripts": {
11
- "dev": "vite",
11
+ "dev": "vite --config vite.config.dev.js",
12
12
  "dev:build": "vite build --watch --mode development --config vite.config.dev.js",
13
13
  "prebuild": "npm install",
14
14
  "build": "vite build --config vite.config.prod.js",