@anu3ev/fabric-image-editor 0.1.11 → 0.1.12

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 +68 -54
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -440,9 +440,9 @@ class Re {
440
440
  this.worker.terminate();
441
441
  }
442
442
  }
443
- var p = 12, Ve = 2, G = 8, X = 20, Fe = 100, Q = 20, J = 8, Ge = 100, K = 32, $ = 1, Xe = "#2B2D33", q = "#3D8BF4", ee = "#FFFFFF";
443
+ var b = 12, Ve = 2, G = 8, X = 20, Fe = 100, Q = 20, J = 8, Ge = 100, K = 32, $ = 1, Xe = "#2B2D33", q = "#3D8BF4", ee = "#FFFFFF";
444
444
  function U(o, e, t, a, r) {
445
- var n = p, i = Ve;
445
+ var n = b, i = Ve;
446
446
  o.save(), o.translate(e, t), o.rotate(z.degreesToRadians(r.angle)), o.fillStyle = ee, o.strokeStyle = q, o.lineWidth = $, o.beginPath(), o.roundRect(-12 / 2, -12 / 2, n, n, i), o.fill(), o.stroke(), o.restore();
447
447
  }
448
448
  function he(o, e, t, a, r) {
@@ -463,29 +463,29 @@ var Ke = {
463
463
  // Угловые точки
464
464
  tl: {
465
465
  render: U,
466
- sizeX: p,
467
- sizeY: p,
466
+ sizeX: b,
467
+ sizeY: b,
468
468
  offsetX: 0,
469
469
  offsetY: 0
470
470
  },
471
471
  tr: {
472
472
  render: U,
473
- sizeX: p,
474
- sizeY: p,
473
+ sizeX: b,
474
+ sizeY: b,
475
475
  offsetX: 0,
476
476
  offsetY: 0
477
477
  },
478
478
  bl: {
479
479
  render: U,
480
- sizeX: p,
481
- sizeY: p,
480
+ sizeX: b,
481
+ sizeY: b,
482
482
  offsetX: 0,
483
483
  offsetY: 0
484
484
  },
485
485
  br: {
486
486
  render: U,
487
- sizeX: p,
488
- sizeY: p,
487
+ sizeX: b,
488
+ sizeY: b,
489
489
  offsetX: 0,
490
490
  offsetY: 0
491
491
  },
@@ -890,7 +890,7 @@ class ht {
890
890
  var {
891
891
  editor: t
892
892
  } = e;
893
- this.editor = t, this.canvas = t.canvas, this._historySuspendCount = 0, this.baseState = null, this.patches = [], this.currentIndex = 0, this.maxHistoryLength = t.options.maxHistoryLength, this._createDiffPatcher();
893
+ this.editor = t, this.canvas = t.canvas, this._historySuspendCount = 0, this.baseState = null, this.patches = [], this.currentIndex = 0, this.maxHistoryLength = t.options.maxHistoryLength, this.totalChangesCount = 0, this.baseStateChangesCount = 0, this._createDiffPatcher();
894
894
  }
895
895
  /** Проверка, нужно ли пропускать сохранение истории */
896
896
  get skipHistory() {
@@ -918,6 +918,20 @@ class ht {
918
918
  resumeHistory() {
919
919
  this._historySuspendCount = Math.max(0, this._historySuspendCount - 1);
920
920
  }
921
+ /**
922
+ * Проверяет, есть ли в редакторе несохранённые изменения
923
+ * @returns {boolean}
924
+ */
925
+ hasUnsavedChanges() {
926
+ return this.totalChangesCount > 0;
927
+ }
928
+ /**
929
+ * Получает текущую позицию в общей истории изменений
930
+ * @returns {number}
931
+ */
932
+ getCurrentChangePosition() {
933
+ return this.baseStateChangesCount + this.currentIndex;
934
+ }
921
935
  /**
922
936
  * Получаем полное состояние, применяя все диффы к базовому состоянию.
923
937
  */
@@ -946,7 +960,7 @@ class ht {
946
960
  console.log("Нет изменений для сохранения.");
947
961
  return;
948
962
  }
949
- console.log("baseState", this.baseState), this.currentIndex < this.patches.length && this.patches.splice(this.currentIndex), console.log("diff", a), this.patches.push(a), this.currentIndex += 1, this.patches.length > this.maxHistoryLength && (this.baseState = this.diffPatcher.patch(this.baseState, this.patches[0]), this.patches.shift(), this.currentIndex -= 1), console.log("Состояние сохранено. Текущий индекс истории:", this.currentIndex);
963
+ 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(a), this.currentIndex += 1, this.patches.length > this.maxHistoryLength && (this.baseState = this.diffPatcher.patch(this.baseState, this.patches[0]), this.patches.shift(), this.currentIndex -= 1, this.baseStateChangesCount += 1), console.log("Состояние сохранено. Текущий индекс истории:", this.currentIndex);
950
964
  }
951
965
  }
952
966
  /**
@@ -980,7 +994,7 @@ class ht {
980
994
  }
981
995
  e.suspendHistory();
982
996
  try {
983
- e.currentIndex -= 1;
997
+ e.currentIndex -= 1, e.totalChangesCount -= 1;
984
998
  var t = e.getFullState();
985
999
  yield e.loadStateFromFullState(t), console.log("Undo выполнен. Текущий индекс истории:", e.currentIndex), e.canvas.fire("editor:undo");
986
1000
  } catch (a) {
@@ -1007,7 +1021,7 @@ class ht {
1007
1021
  }
1008
1022
  e.suspendHistory();
1009
1023
  try {
1010
- e.currentIndex += 1;
1024
+ e.currentIndex += 1, e.totalChangesCount += 1;
1011
1025
  var t = e.getFullState();
1012
1026
  console.log("fullState", t), yield e.loadStateFromFullState(t), console.log("Redo выполнен. Текущий индекс истории:", e.currentIndex), e.canvas.fire("editor:redo");
1013
1027
  } catch (a) {
@@ -1021,7 +1035,7 @@ class ht {
1021
1035
  })();
1022
1036
  }
1023
1037
  }
1024
- var gt = 0.1, vt = 2, mt = 0.1, ft = 90, k = 16, x = 16, D = 4096, C = 4096;
1038
+ var gt = 0.1, vt = 2, mt = 0.1, ft = 90, k = 16, x = 16, N = 4096, D = 4096;
1025
1039
  function Me(o, e, t, a, r, n, i) {
1026
1040
  try {
1027
1041
  var s = o[n](i), c = s.value;
@@ -1109,9 +1123,9 @@ class L {
1109
1123
  });
1110
1124
  var {
1111
1125
  width: f,
1112
- height: b
1126
+ height: p
1113
1127
  } = h;
1114
- if (b > C || f > D) {
1128
+ if (p > D || f > N) {
1115
1129
  var y = yield t.resizeImageToBoundaries(h._element.src, "max"), S = URL.createObjectURL(y);
1116
1130
  t._createdBlobUrls.push(S), h = yield de.fromURL(S, {
1117
1131
  crossOrigin: "anonymous"
@@ -1134,7 +1148,7 @@ class L {
1134
1148
  object: h,
1135
1149
  type: "contain",
1136
1150
  withoutSave: !0
1137
- }) : r === "image-cover" && (f > O || b > A) && u.fitObject({
1151
+ }) : r === "image-cover" && (f > O || p > A) && u.fitObject({
1138
1152
  object: h,
1139
1153
  type: "cover",
1140
1154
  withoutSave: !0
@@ -1160,14 +1174,14 @@ class L {
1160
1174
  resizeImageToBoundaries(e) {
1161
1175
  var t = arguments, a = this;
1162
1176
  return P(function* () {
1163
- var r = t.length > 1 && t[1] !== void 0 ? t[1] : "max", n = "Размер изображения больше максимального размера канваса, поэтому оно будет уменьшено до максимальных размеров: ".concat(D, "x").concat(C);
1177
+ var r = t.length > 1 && t[1] !== void 0 ? t[1] : "max", n = "Размер изображения больше максимального размера канваса, поэтому оно будет уменьшено до максимальных размеров: ".concat(N, "x").concat(D);
1164
1178
  console.warn("importImage. ".concat(n)), a.editor.canvas.fire("editor:warning", {
1165
1179
  message: n
1166
1180
  });
1167
1181
  var i = yield a.editor.workerManager.post("resizeImage", {
1168
1182
  dataURL: e,
1169
- maxWidth: D,
1170
- maxHeight: C,
1183
+ maxWidth: N,
1184
+ maxHeight: D,
1171
1185
  sizeType: r
1172
1186
  });
1173
1187
  return i;
@@ -1205,14 +1219,14 @@ class L {
1205
1219
  height: j
1206
1220
  } = c.getBoundingRect(), f = yield s.clone(["id", "format", "locked"]);
1207
1221
  ["image/jpg", "image/jpeg"].includes(d) && (f.backgroundColor = "#ffffff");
1208
- var b = f.getObjects().find((N) => N.id === c.id);
1209
- b.visible = !1, f.viewportTransform = [1, 0, 0, 1, -g, -v], f.setDimensions({
1222
+ var p = f.getObjects().find((C) => C.id === c.id);
1223
+ p.visible = !1, f.viewportTransform = [1, 0, 0, 1, -g, -v], f.setDimensions({
1210
1224
  width: m,
1211
1225
  height: j
1212
1226
  }, {
1213
1227
  backstoreOnly: !0
1214
1228
  }), f.renderAll();
1215
- var y = f.getObjects().filter((N) => N.format).every((N) => N.format === "svg");
1229
+ var y = f.getObjects().filter((C) => C.format).every((C) => C.format === "svg");
1216
1230
  if (h === "svg" && y) {
1217
1231
  var S = f.toSVG();
1218
1232
  f.dispose();
@@ -1228,8 +1242,8 @@ class L {
1228
1242
  };
1229
1243
  return s.fire("editor:canvas-exported", A), A;
1230
1244
  }
1231
- var w = yield new Promise((N) => {
1232
- f.getElement().toBlob(N);
1245
+ var w = yield new Promise((C) => {
1246
+ f.getElement().toBlob(C);
1233
1247
  });
1234
1248
  if (f.dispose(), i) {
1235
1249
  var T = {
@@ -1252,18 +1266,18 @@ class L {
1252
1266
  format: [H, W]
1253
1267
  });
1254
1268
  if (_.addImage(re, "JPG", 0, 0, H, W), n) {
1255
- var Ne = _.output("datauristring"), ie = {
1256
- image: Ne,
1269
+ var Ce = _.output("datauristring"), ie = {
1270
+ image: Ce,
1257
1271
  format: "pdf",
1258
1272
  contentType: "application/pdf",
1259
1273
  fileName: a
1260
1274
  };
1261
1275
  return s.fire("editor:canvas-exported", ie), ie;
1262
1276
  }
1263
- var De = _.output("blob"), Ce = new File([De], a, {
1277
+ var Ne = _.output("blob"), De = new File([Ne], a, {
1264
1278
  type: "application/pdf"
1265
1279
  }), oe = {
1266
- image: Ce,
1280
+ image: De,
1267
1281
  format: "pdf",
1268
1282
  contentType: "application/pdf",
1269
1283
  fileName: a
@@ -1345,8 +1359,8 @@ class L {
1345
1359
  };
1346
1360
  return c.fire("editor:object-exported", f), f;
1347
1361
  }
1348
- var b = l.toCanvasElement(), y = yield new Promise((w) => {
1349
- b.toBlob(w);
1362
+ var p = l.toCanvasElement(), y = yield new Promise((w) => {
1363
+ p.toBlob(w);
1350
1364
  });
1351
1365
  if (s) {
1352
1366
  var S = {
@@ -1465,7 +1479,7 @@ class Mt {
1465
1479
  } = this.editor, {
1466
1480
  width: c,
1467
1481
  height: u
1468
- } = i, l = Number(Math.max(Math.min(e, D), k));
1482
+ } = i, l = Number(Math.max(Math.min(e, N), k));
1469
1483
  if (!s || s === "auto" || r ? this.adaptCanvasToContainer() : s ? this.setCanvasBackstoreWidth(s) : this.setCanvasBackstoreWidth(l), i.set({
1470
1484
  width: l
1471
1485
  }), n.clipPath.set({
@@ -1508,7 +1522,7 @@ class Mt {
1508
1522
  } = this.editor, {
1509
1523
  width: c,
1510
1524
  height: u
1511
- } = i, l = Number(Math.max(Math.min(e, C), x));
1525
+ } = i, l = Number(Math.max(Math.min(e, D), x));
1512
1526
  if (!s || s === "auto" || r ? this.adaptCanvasToContainer() : s ? this.setCanvasBackstoreHeight(s) : this.setCanvasBackstoreHeight(l), i.set({
1513
1527
  height: l
1514
1528
  }), n.clipPath.set({
@@ -1570,7 +1584,7 @@ class Mt {
1570
1584
  }
1571
1585
  setCanvasBackstoreWidth(e) {
1572
1586
  if (!(!e || typeof e != "number")) {
1573
- var t = Math.max(Math.min(e, D), k);
1587
+ var t = Math.max(Math.min(e, N), k);
1574
1588
  this.editor.canvas.setDimensions({
1575
1589
  width: t
1576
1590
  }, {
@@ -1580,7 +1594,7 @@ class Mt {
1580
1594
  }
1581
1595
  setCanvasBackstoreHeight(e) {
1582
1596
  if (!(!e || typeof e != "number")) {
1583
- var t = Math.max(Math.min(e, C), x);
1597
+ var t = Math.max(Math.min(e, D), x);
1584
1598
  this.editor.canvas.setDimensions({
1585
1599
  height: t
1586
1600
  }, {
@@ -1591,7 +1605,7 @@ class Mt {
1591
1605
  adaptCanvasToContainer() {
1592
1606
  var {
1593
1607
  canvas: e
1594
- } = this.editor, t = e.editorContainer, a = t.clientWidth, r = t.clientHeight, n = Math.max(Math.min(a, D), k), i = Math.max(Math.min(r, C), x);
1608
+ } = this.editor, t = e.editorContainer, a = t.clientWidth, r = t.clientHeight, n = Math.max(Math.min(a, N), k), i = Math.max(Math.min(r, D), x);
1595
1609
  console.log("adaptCanvasToContainer newWidth", n), console.log("adaptCanvasToContainer newHeight", i), e.setDimensions({
1596
1610
  width: n,
1597
1611
  height: i
@@ -1758,12 +1772,12 @@ class Mt {
1758
1772
  message: h
1759
1773
  });
1760
1774
  }
1761
- var g = Math.min(l, D), v = Math.min(d, C);
1775
+ var g = Math.min(l, N), v = Math.min(d, D);
1762
1776
  if (t) {
1763
1777
  var {
1764
1778
  width: m,
1765
1779
  height: j
1766
- } = n, f = l / m, b = d / j, y = Math.max(f, b);
1780
+ } = n, f = l / m, p = d / j, y = Math.max(f, p);
1767
1781
  g = m * y, v = j * y;
1768
1782
  }
1769
1783
  this.setResolutionWidth(g, {
@@ -2353,7 +2367,7 @@ class Y {
2353
2367
  e.moveObjectTo(r[i], n - 1);
2354
2368
  }
2355
2369
  }
2356
- var pt = ["id", "left", "top", "width", "height", "fill"], bt = ["id", "left", "top", "radius", "fill"], It = ["id", "left", "top", "width", "height", "fill"];
2370
+ var bt = ["id", "left", "top", "width", "height", "fill"], pt = ["id", "left", "top", "radius", "fill"], It = ["id", "left", "top", "width", "height", "fill"];
2357
2371
  function je(o, e) {
2358
2372
  var t = Object.keys(o);
2359
2373
  if (Object.getOwnPropertySymbols) {
@@ -2394,14 +2408,14 @@ function wt(o, e) {
2394
2408
  }
2395
2409
  function F(o, e) {
2396
2410
  if (o == null) return {};
2397
- var t, a, r = Nt(o, e);
2411
+ var t, a, r = Ct(o, e);
2398
2412
  if (Object.getOwnPropertySymbols) {
2399
2413
  var n = Object.getOwnPropertySymbols(o);
2400
2414
  for (a = 0; a < n.length; a++) t = n[a], e.indexOf(t) === -1 && {}.propertyIsEnumerable.call(o, t) && (r[t] = o[t]);
2401
2415
  }
2402
2416
  return r;
2403
2417
  }
2404
- function Nt(o, e) {
2418
+ function Ct(o, e) {
2405
2419
  if (o == null) return {};
2406
2420
  var t = {};
2407
2421
  for (var a in o) if ({}.hasOwnProperty.call(o, a)) {
@@ -2410,7 +2424,7 @@ function Nt(o, e) {
2410
2424
  }
2411
2425
  return t;
2412
2426
  }
2413
- class Dt {
2427
+ class Nt {
2414
2428
  /**
2415
2429
  * @param {object} options
2416
2430
  * @param {ImageEditor} options.editor - экземпляр редактора с доступом к canvas
@@ -2444,7 +2458,7 @@ class Dt {
2444
2458
  width: n = 100,
2445
2459
  height: i = 100,
2446
2460
  fill: s = "blue"
2447
- } = e, c = F(e, pt), {
2461
+ } = e, c = F(e, bt), {
2448
2462
  withoutSelection: u,
2449
2463
  withoutAdding: l
2450
2464
  } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, {
@@ -2480,7 +2494,7 @@ class Dt {
2480
2494
  top: r,
2481
2495
  radius: n = 50,
2482
2496
  fill: i = "green"
2483
- } = e, s = F(e, bt), {
2497
+ } = e, s = F(e, pt), {
2484
2498
  withoutSelection: c,
2485
2499
  withoutAdding: u
2486
2500
  } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, {
@@ -2541,7 +2555,7 @@ function ye(o, e, t, a, r, n, i) {
2541
2555
  }
2542
2556
  s.done ? e(c) : Promise.resolve(c).then(a, r);
2543
2557
  }
2544
- function pe(o) {
2558
+ function be(o) {
2545
2559
  return function() {
2546
2560
  var e = this, t = arguments;
2547
2561
  return new Promise(function(a, r) {
@@ -2556,7 +2570,7 @@ function pe(o) {
2556
2570
  });
2557
2571
  };
2558
2572
  }
2559
- class Ct {
2573
+ class Dt {
2560
2574
  /**
2561
2575
  * @param {object} options
2562
2576
  * @param {ImageEditor} options.editor - экземпляр редактора с доступом к canvas
@@ -2573,7 +2587,7 @@ class Ct {
2573
2587
  */
2574
2588
  copy() {
2575
2589
  var e = this;
2576
- return pe(function* () {
2590
+ return be(function* () {
2577
2591
  var {
2578
2592
  canvas: t
2579
2593
  } = e.editor, a = t.getActiveObject();
@@ -2617,7 +2631,7 @@ class Ct {
2617
2631
  */
2618
2632
  paste() {
2619
2633
  var e = this;
2620
- return pe(function* () {
2634
+ return be(function* () {
2621
2635
  var {
2622
2636
  canvas: t
2623
2637
  } = e.editor;
@@ -2849,7 +2863,7 @@ class Et {
2849
2863
  }), a.discardActiveObject(), a.renderAll(), r.resumeHistory(), t || r.saveState(), a.fire("editor:objects-deleted"));
2850
2864
  }
2851
2865
  }
2852
- function be(o, e, t, a, r, n, i) {
2866
+ function pe(o, e, t, a, r, n, i) {
2853
2867
  try {
2854
2868
  var s = o[n](i), c = s.value;
2855
2869
  } catch (u) {
@@ -2863,10 +2877,10 @@ function kt(o) {
2863
2877
  return new Promise(function(a, r) {
2864
2878
  var n = o.apply(e, t);
2865
2879
  function i(c) {
2866
- be(n, a, r, i, s, "next", c);
2880
+ pe(n, a, r, i, s, "next", c);
2867
2881
  }
2868
2882
  function s(c) {
2869
- be(n, a, r, i, s, "throw", c);
2883
+ pe(n, a, r, i, s, "throw", c);
2870
2884
  }
2871
2885
  i(void 0);
2872
2886
  });
@@ -2910,11 +2924,11 @@ class te {
2910
2924
  editor: e
2911
2925
  }), e.layerManager = new Y({
2912
2926
  editor: e
2913
- }), e.shapeManager = new Dt({
2927
+ }), e.shapeManager = new Nt({
2914
2928
  editor: e
2915
2929
  }), e.interactionBlocker = new yt({
2916
2930
  editor: e
2917
- }), e.clipboardManager = new Ct({
2931
+ }), e.clipboardManager = new Dt({
2918
2932
  editor: e
2919
2933
  }), e.objectLockManager = new Lt({
2920
2934
  editor: e
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anu3ev/fabric-image-editor",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
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": [