@anu3ev/fabric-image-editor 0.7.3 → 0.7.4

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 CHANGED
@@ -252,10 +252,10 @@ var M = class {
252
252
  }, N = "#2B2D33", P = "#3D8BF4", F = "#FFFFFF";
253
253
  //#endregion
254
254
  //#region src/editor/customized-controls/renderers.ts
255
- function ee(e, t, n, r, i) {
255
+ function I(e, t, n, r, i) {
256
256
  e.save(), e.translate(t, n), e.rotate(C.degreesToRadians(i.angle)), e.fillStyle = F, e.strokeStyle = P, e.lineWidth = 1, e.beginPath(), e.roundRect(-12 / 2, -12 / 2, 12, 12, 2), e.fill(), e.stroke(), e.restore();
257
257
  }
258
- function I(e, t, n, r, i) {
258
+ function ee(e, t, n, r, i) {
259
259
  e.save(), e.translate(t, n), e.rotate(C.degreesToRadians(i.angle)), e.fillStyle = F, e.strokeStyle = P, e.lineWidth = 1, e.beginPath(), e.roundRect(-8 / 2, -20 / 2, 8, 20, 100), e.fill(), e.stroke(), e.restore();
260
260
  }
261
261
  function L(e, t, n, r, i) {
@@ -270,42 +270,42 @@ function R(e, t, n, r, i) {
270
270
  //#region src/editor/customized-controls/default-controls.ts
271
271
  var re = {
272
272
  tl: {
273
- render: ee,
273
+ render: I,
274
274
  sizeX: 12,
275
275
  sizeY: 12,
276
276
  offsetX: 0,
277
277
  offsetY: 0
278
278
  },
279
279
  tr: {
280
- render: ee,
280
+ render: I,
281
281
  sizeX: 12,
282
282
  sizeY: 12,
283
283
  offsetX: 0,
284
284
  offsetY: 0
285
285
  },
286
286
  bl: {
287
- render: ee,
287
+ render: I,
288
288
  sizeX: 12,
289
289
  sizeY: 12,
290
290
  offsetX: 0,
291
291
  offsetY: 0
292
292
  },
293
293
  br: {
294
- render: ee,
294
+ render: I,
295
295
  sizeX: 12,
296
296
  sizeY: 12,
297
297
  offsetX: 0,
298
298
  offsetY: 0
299
299
  },
300
300
  ml: {
301
- render: I,
301
+ render: ee,
302
302
  sizeX: 8,
303
303
  sizeY: 20,
304
304
  offsetX: 0,
305
305
  offsetY: 0
306
306
  },
307
307
  mr: {
308
- render: I,
308
+ render: ee,
309
309
  sizeX: 8,
310
310
  sizeY: 20,
311
311
  offsetX: 0,
@@ -345,7 +345,8 @@ var re = {
345
345
  Object.entries(re).forEach(([t, n]) => {
346
346
  let r = e[t];
347
347
  r && (Object.assign(r, n), t === "mtr" && (r.cursorStyle = "grab", r.mouseDownHandler = (e, t, n, r) => {
348
- (t?.target)?.canvas?.setCursor("grabbing");
348
+ let i = t?.target;
349
+ !i || i.locked || i.lockRotation || i.canvas?.setCursor("grabbing");
349
350
  }));
350
351
  });
351
352
  }
@@ -801,12 +802,12 @@ var re = {
801
802
  "pointer-events": "none",
802
803
  "white-space": "nowrap",
803
804
  "box-shadow": "0 2px 8px rgba(0, 0, 0, 0.2)"
804
- }, H = "fabric-editor-angle-indicator", U = class e {
805
+ }, oe = "fabric-editor-angle-indicator", se = class e {
805
806
  constructor({ editor: e }) {
806
807
  this.isActive = !1, this.currentAngle = 0, this.editor = e, this.canvas = e.canvas, this.options = e.options, this._createDOM(), this._bindEvents();
807
808
  }
808
809
  _createDOM() {
809
- this.el = document.createElement("div"), this.el.className = H, Object.entries(V).forEach(([e, t]) => {
810
+ this.el = document.createElement("div"), this.el.className = oe, Object.entries(V).forEach(([e, t]) => {
810
811
  this.el.style.setProperty(e, t);
811
812
  }), this.canvas.wrapperEl.appendChild(this.el);
812
813
  }
@@ -851,44 +852,44 @@ var re = {
851
852
  destroy() {
852
853
  this.canvas && (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:cleared", this._onSelectionCleared)), this.el?.parentNode && this.el.parentNode.removeChild(this.el), this.el = null, this.editor = null, this.canvas = null, this.options = null;
853
854
  }
854
- }, oe = /* @__PURE__ */ "id.backgroundId.customData.backgroundType.format.contentType.width.height.originX.originY.locked.editable.evented.selectable.lockMovementX.lockMovementY.lockRotation.lockScalingX.lockScalingY.lockSkewingX.lockSkewingY.styles.lineFontDefaults.textCaseRaw.uppercase.autoExpand.linethrough.underline.fontStyle.fontWeight.backgroundOpacity.paddingTop.paddingRight.paddingBottom.paddingLeft.radiusTopLeft.radiusTopRight.radiusBottomRight.radiusBottomLeft.shapeComposite.shapePresetKey.shapeBaseWidth.shapeBaseHeight.shapeManualBaseWidth.shapeManualBaseHeight.shapeTextAutoExpand.shapeAlignHorizontal.shapeAlignVertical.shapePaddingTop.shapePaddingRight.shapePaddingBottom.shapePaddingLeft.shapeFill.shapeStroke.shapeStrokeWidth.shapeStrokeDashArray.shapeOpacity.shapeRounding.shapeNodeType".split(".");
855
+ }, ce = /* @__PURE__ */ "id.backgroundId.customData.backgroundType.format.contentType.width.height.originX.originY.locked.editable.evented.selectable.lockMovementX.lockMovementY.lockRotation.lockScalingX.lockScalingY.lockSkewingX.lockSkewingY.styles.lineFontDefaults.textCaseRaw.uppercase.autoExpand.linethrough.underline.fontStyle.fontWeight.backgroundOpacity.paddingTop.paddingRight.paddingBottom.paddingLeft.radiusTopLeft.radiusTopRight.radiusBottomRight.radiusBottomLeft.shapeComposite.shapePresetKey.shapeBaseWidth.shapeBaseHeight.shapeManualBaseWidth.shapeManualBaseHeight.shapeTextAutoExpand.shapeAlignHorizontal.shapeAlignVertical.shapePaddingTop.shapePaddingRight.shapePaddingBottom.shapePaddingLeft.shapeFill.shapeStroke.shapeStrokeWidth.shapeStrokeDashArray.shapeOpacity.shapeRounding.shapeNodeType".split(".");
855
856
  //#endregion
856
857
  //#region src/editor/history-manager/diff-normalization.ts
857
- function se({ state: e }) {
858
+ function le({ state: e }) {
858
859
  return JSON.parse(JSON.stringify(e));
859
860
  }
860
- function ce({ value: e }) {
861
+ function H({ value: e }) {
861
862
  if (Array.isArray(e)) {
862
863
  let t = [];
863
- for (let n = 0; n < e.length; n += 1) t.push(ce({ value: e[n] }));
864
+ for (let n = 0; n < e.length; n += 1) t.push(H({ value: e[n] }));
864
865
  return t;
865
866
  }
866
867
  if (e && typeof e == "object") {
867
868
  let t = {}, n = Object.keys(e).sort();
868
869
  for (let r = 0; r < n.length; r += 1) {
869
870
  let i = n[r];
870
- t[i] = ce({ value: e[i] });
871
+ t[i] = H({ value: e[i] });
871
872
  }
872
873
  return t;
873
874
  }
874
875
  return e;
875
876
  }
876
- function le({ value: e }) {
877
- let t = ce({ value: e });
877
+ function ue({ value: e }) {
878
+ let t = H({ value: e });
878
879
  return JSON.stringify(t);
879
880
  }
880
- function ue({ prevState: e, nextState: t }) {
881
- return le({ value: e }) === le({ value: t });
881
+ function de({ prevState: e, nextState: t }) {
882
+ return ue({ value: e }) === ue({ value: t });
882
883
  }
883
- function de({ objects: e, id: t }) {
884
+ function fe({ objects: e, id: t }) {
884
885
  for (let n = 0; n < e.length; n += 1) {
885
886
  let r = e[n];
886
887
  if (r.id === t) return r;
887
888
  }
888
889
  return null;
889
890
  }
890
- function fe({ objects: e }) {
891
- let t = de({
891
+ function pe({ objects: e }) {
892
+ let t = fe({
892
893
  objects: e,
893
894
  id: "montage-area"
894
895
  });
@@ -902,7 +903,7 @@ function fe({ objects: e }) {
902
903
  height: r
903
904
  };
904
905
  }
905
- function pe({ objects: e }) {
906
+ function me({ objects: e }) {
906
907
  let t = [], n = [...e];
907
908
  for (let e = 0; e < n.length; e += 1) {
908
909
  let r = n[e];
@@ -912,20 +913,20 @@ function pe({ objects: e }) {
912
913
  }
913
914
  return t;
914
915
  }
915
- function me({ objects: e }) {
916
- let t = pe({ objects: e });
916
+ function he({ objects: e }) {
917
+ let t = me({ objects: e });
917
918
  for (let e = 0; e < t.length; e += 1) {
918
919
  let n = t[e], { type: r, backgroundOpacity: i, backgroundColor: a, textBackgroundColor: o } = n, s = typeof i == "number" ? i : 0, c = typeof a == "string" ? a : "", l = typeof o == "string" ? o : "", u = r === "textbox" || r === "background-textbox", d = c.length > 0 || l.length > 0;
919
920
  u && (s > 0 && d || (n.backgroundColor = null, n.textBackgroundColor = null));
920
921
  }
921
922
  }
922
- function he({ prevState: e, nextState: t }) {
923
- let { width: n, height: r, objects: i } = e, { objects: a } = t, { width: o, height: s } = fe({ objects: i }), { width: c, height: l } = fe({ objects: a });
923
+ function ge({ prevState: e, nextState: t }) {
924
+ let { width: n, height: r, objects: i } = e, { objects: a } = t, { width: o, height: s } = pe({ objects: i }), { width: c, height: l } = pe({ objects: a });
924
925
  o !== c || s !== l || (t.width = n, t.height = r);
925
926
  }
926
- function ge({ prevState: e, nextState: t }) {
927
- let n = se({ state: e }), r = se({ state: t });
928
- return me({ objects: n.objects }), me({ objects: r.objects }), he({
927
+ function _e({ prevState: e, nextState: t }) {
928
+ let n = le({ state: e }), r = le({ state: t });
929
+ return he({ objects: n.objects }), he({ objects: r.objects }), ge({
929
930
  prevState: n,
930
931
  nextState: r
931
932
  }), {
@@ -935,10 +936,10 @@ function ge({ prevState: e, nextState: t }) {
935
936
  }
936
937
  //#endregion
937
938
  //#region src/editor/history-manager/load-state.ts
938
- function _e({ customData: e }) {
939
+ function ve({ customData: e }) {
939
940
  return JSON.parse(JSON.stringify(e));
940
941
  }
941
- function ve({ state: e }) {
942
+ function ye({ state: e }) {
942
943
  let t = JSON.parse(JSON.stringify(e)), n = (t.objects ?? []).filter((e) => e.id !== "overlay-mask");
943
944
  t.objects = n;
944
945
  for (let e = 0; e < n.length; e += 1) {
@@ -947,7 +948,7 @@ function ve({ state: e }) {
947
948
  }
948
949
  return t;
949
950
  }
950
- function ye({ state: e, canvas: t }) {
951
+ function be({ state: e, canvas: t }) {
951
952
  let { objects: n = [] } = e, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
952
953
  for (let e = 0; e < n.length; e += 1) {
953
954
  let { customData: t, id: a } = n[e];
@@ -962,23 +963,23 @@ function ye({ state: e, canvas: t }) {
962
963
  let a = t.getObjects?.() ?? [];
963
964
  for (let e = 0; e < a.length; e += 1) {
964
965
  let t = a[e], { id: n } = t, o;
965
- typeof n == "string" && (o = r.get(n)), o ||= i.get(e), o && (t.customData = _e({ customData: o }));
966
+ typeof n == "string" && (o = r.get(n)), o ||= i.get(e), o && (t.customData = ve({ customData: o }));
966
967
  }
967
968
  }
968
969
  //#endregion
969
970
  //#region src/editor/history-manager/snapshot-interactivity.ts
970
- function be({ object: e }) {
971
+ function xe({ object: e }) {
971
972
  return typeof e.getObjects == "function" ? e.getObjects() : [];
972
973
  }
973
- function xe({ objects: e }) {
974
+ function Se({ objects: e }) {
974
975
  for (let t = 0; t < e.length; t += 1) if (e[t].isEditing) return !0;
975
976
  return !1;
976
977
  }
977
- function Se({ object: e }) {
978
+ function Ce({ object: e }) {
978
979
  let t = typeof e.type == "string" ? e.type.toLowerCase() : "";
979
980
  return t === "textbox" || t === "background-textbox" || typeof e.isEditing == "boolean";
980
981
  }
981
- function Ce({ object: e, withEvented: t = !1 }) {
982
+ function we({ object: e, withEvented: t = !1 }) {
982
983
  let n = {
983
984
  object: e,
984
985
  lockMovementX: e.lockMovementX,
@@ -987,68 +988,68 @@ function Ce({ object: e, withEvented: t = !1 }) {
987
988
  };
988
989
  return t && (n.evented = e.evented), n;
989
990
  }
990
- function we({ object: e, snapshotStates: t }) {
991
- return e.shapeComposite !== !0 || !xe({ objects: be({ object: e }) }) ? !1 : (t.push(Ce({ object: e })), e.lockMovementX = !1, e.lockMovementY = !1, e.selectable = !0, !0);
992
- }
993
991
  function Te({ object: e, snapshotStates: t }) {
994
- if (!Se({ object: e })) return !1;
992
+ return e.shapeComposite !== !0 || !Se({ objects: xe({ object: e }) }) ? !1 : (t.push(we({ object: e })), e.lockMovementX = !1, e.lockMovementY = !1, e.selectable = !0, !0);
993
+ }
994
+ function Ee({ object: e, snapshotStates: t }) {
995
+ if (!Ce({ object: e })) return !1;
995
996
  let n = e.group, { isEditing: r } = e, i = n?.shapeComposite === !0, a = !!n?.locked;
996
- return !i || a || !r ? !1 : (t.push(Ce({
997
+ return !i || a || !r ? !1 : (t.push(we({
997
998
  object: e,
998
999
  withEvented: !0
999
1000
  })), e.lockMovementX = !1, e.lockMovementY = !1, e.selectable = !1, e.evented = !1, !0);
1000
1001
  }
1001
- function Ee({ object: e, snapshotStates: t }) {
1002
- if (!Se({ object: e })) return !1;
1002
+ function De({ object: e, snapshotStates: t }) {
1003
+ if (!Ce({ object: e })) return !1;
1003
1004
  let n = !!e.lockMovementX, r = !!e.lockMovementY;
1004
- return !n && !r ? !1 : (t.push(Ce({ object: e })), e.lockMovementX = !1, e.lockMovementY = !1, e.selectable = !0, !0);
1005
+ return !n && !r ? !1 : (t.push(we({ object: e })), e.lockMovementX = !1, e.lockMovementY = !1, e.selectable = !0, !0);
1005
1006
  }
1006
- function De({ objects: e }) {
1007
+ function Oe({ objects: e }) {
1007
1008
  let t = [];
1008
1009
  for (let n = 0; n < e.length; n += 1) {
1009
1010
  let r = e[n];
1010
- r.locked || we({
1011
+ r.locked || Te({
1011
1012
  object: r,
1012
1013
  snapshotStates: t
1013
- }) || Te({
1014
+ }) || Ee({
1014
1015
  object: r,
1015
1016
  snapshotStates: t
1016
- }) || Ee({
1017
+ }) || De({
1017
1018
  object: r,
1018
1019
  snapshotStates: t
1019
1020
  });
1020
1021
  }
1021
1022
  return t;
1022
1023
  }
1023
- function Oe({ canvas: e }) {
1024
+ function ke({ canvas: e }) {
1024
1025
  let t = [...e.getObjects?.() ?? []], n = [];
1025
1026
  for (let e = 0; e < t.length; e += 1) {
1026
1027
  let r = t[e];
1027
1028
  n.push(r);
1028
- let i = be({ object: r });
1029
+ let i = xe({ object: r });
1029
1030
  for (let e = 0; e < i.length; e += 1) t.push(i[e]);
1030
1031
  }
1031
1032
  return n;
1032
1033
  }
1033
- function ke({ snapshotStates: e }) {
1034
+ function Ae({ snapshotStates: e }) {
1034
1035
  for (let t = 0; t < e.length; t += 1) {
1035
1036
  let { object: n, lockMovementX: r, lockMovementY: i, selectable: a, evented: o } = e[t];
1036
1037
  n.lockMovementX = r, n.lockMovementY = i, n.selectable = a, o !== void 0 && (n.evented = o);
1037
1038
  }
1038
1039
  }
1039
- function Ae({ canvas: e, callback: t }) {
1040
- let n = De({ objects: Oe({ canvas: e }) });
1040
+ function je({ canvas: e, callback: t }) {
1041
+ let n = Oe({ objects: ke({ canvas: e }) });
1041
1042
  try {
1042
1043
  return t();
1043
1044
  } finally {
1044
- ke({ snapshotStates: n });
1045
+ Ae({ snapshotStates: n });
1045
1046
  }
1046
1047
  }
1047
1048
  //#endregion
1048
1049
  //#region src/editor/history-manager/index.ts
1049
- var je = class {
1050
+ var Me = class {
1050
1051
  constructor({ editor: e }) {
1051
- this.editor = e, this.canvas = e.canvas, this._isSavingState = !1, this._historySuspendCount = 0, this._isActionInProgress = !1, this._actionSnapshot = null, this._actionReason = null, this._pendingSaveTimeoutId = null, this._pendingSaveReason = null, this._hasDeferredSaveAfterUnblock = !1, this.baseState = null, this.patches = [], this.currentIndex = 0, this.maxHistoryLength = e.options.maxHistoryLength, this.totalChangesCount = 0, this.baseStateChangesCount = 0, this._createDiffPatcher();
1052
+ this.editor = e, this.canvas = e.canvas, this._isSavingState = !1, this._historySuspendCount = 0, this._isActionInProgress = !1, this._actionSnapshot = null, this._actionReason = null, this._pendingSaveTimeoutId = null, this._pendingSaveReason = null, this._pendingCommittedState = null, this._pendingCommittedStateReason = null, this._hasDeferredSaveAfterUnblock = !1, this.baseState = null, this.patches = [], this.currentIndex = 0, this.maxHistoryLength = e.options.maxHistoryLength, this.totalChangesCount = 0, this.baseStateChangesCount = 0, this._createDiffPatcher();
1052
1053
  }
1053
1054
  get skipHistory() {
1054
1055
  return this._historySuspendCount > 0 || this._isSavingState;
@@ -1086,10 +1087,11 @@ var je = class {
1086
1087
  scheduleSaveState({ delayMs: e, reason: t }) {
1087
1088
  this._clearPendingSave(), this._pendingSaveReason = t, this._pendingSaveTimeoutId = setTimeout(this._handlePendingSaveTimeout.bind(this), e);
1088
1089
  }
1089
- flushPendingSave() {
1090
- if (this._pendingSaveTimeoutId === null) return !1;
1091
- let e = this._pendingSaveReason;
1092
- return this._clearPendingSave(), this._finalizePendingSave({ reason: e }), !0;
1090
+ flushPendingSave({ reason: e } = {}) {
1091
+ return this._pendingSaveTimeoutId === null || e && this._pendingSaveReason !== e ? !1 : (this._clearPendingSave(), this.saveState(), !0);
1092
+ }
1093
+ stageCurrentStateForPendingSave({ reason: e }) {
1094
+ this.skipHistory || (this._pendingCommittedState = this._captureCurrentState(), this._pendingCommittedStateReason = e);
1093
1095
  }
1094
1096
  hasUnsavedChanges() {
1095
1097
  return this.totalChangesCount > 0;
@@ -1113,22 +1115,17 @@ var je = class {
1113
1115
  return console.log("getFullState state", r), r;
1114
1116
  }
1115
1117
  _captureCurrentState() {
1116
- return Ae({
1118
+ return je({
1117
1119
  canvas: this.canvas,
1118
1120
  callback: () => this._serializeCanvasState()
1119
1121
  });
1120
1122
  }
1121
1123
  _serializeCanvasState() {
1122
1124
  let { canvas: e } = this;
1123
- return e.toDatalessObject([...oe]);
1125
+ return e.toDatalessObject([...ce]);
1124
1126
  }
1125
1127
  _handlePendingSaveTimeout() {
1126
- if (this._pendingSaveTimeoutId === null) return;
1127
- let e = this._pendingSaveReason;
1128
- this._pendingSaveTimeoutId = null, this._pendingSaveReason = null, this._finalizePendingSave({ reason: e });
1129
- }
1130
- _finalizePendingSave({ reason: e }) {
1131
- e === "text-edit" && this._deactivateTextEditing(), this.saveState();
1128
+ this._pendingSaveTimeoutId !== null && (this._pendingSaveTimeoutId = null, this._pendingSaveReason = null, this.saveState());
1132
1129
  }
1133
1130
  _deactivateTextEditing() {
1134
1131
  let { textManager: e } = this.editor;
@@ -1138,6 +1135,17 @@ var je = class {
1138
1135
  let { _pendingSaveTimeoutId: e } = this;
1139
1136
  e !== null && (clearTimeout(e), this._pendingSaveTimeoutId = null, this._pendingSaveReason = null);
1140
1137
  }
1138
+ _clearPendingCommittedState() {
1139
+ this._pendingCommittedState = null, this._pendingCommittedStateReason = null;
1140
+ }
1141
+ _consumePendingCommittedState({ reason: e } = {}) {
1142
+ if (!this._pendingCommittedState || e && this._pendingCommittedStateReason !== e) return null;
1143
+ let t = {
1144
+ state: this._pendingCommittedState,
1145
+ reason: this._pendingCommittedStateReason
1146
+ };
1147
+ return this._clearPendingCommittedState(), t;
1148
+ }
1141
1149
  _clearPendingAction() {
1142
1150
  this._isActionInProgress = !1, this._actionSnapshot = null, this._actionReason = null;
1143
1151
  }
@@ -1145,13 +1153,38 @@ var je = class {
1145
1153
  let { _isActionInProgress: e, _actionSnapshot: t } = this;
1146
1154
  if (!e || !t) return !1;
1147
1155
  let n = this._actionReason;
1148
- this._clearPendingSave(), this._clearPendingAction(), this.suspendHistory();
1156
+ this._clearPendingSave(), this._clearPendingCommittedState(), this._clearPendingAction(), this.suspendHistory();
1149
1157
  try {
1150
1158
  return await this.loadStateFromFullState(t), n === "text-edit" && this._deactivateTextEditing(), !0;
1151
1159
  } finally {
1152
1160
  this.resumeHistory();
1153
1161
  }
1154
1162
  }
1163
+ _saveSerializedState({ currentStateObj: e }) {
1164
+ if (!this.baseState) {
1165
+ this.baseState = e, this.patches = [], this.currentIndex = 0, console.log("Базовое состояние сохранено.");
1166
+ return;
1167
+ }
1168
+ let { prevState: t, nextState: n } = _e({
1169
+ prevState: this.getFullState(),
1170
+ nextState: e
1171
+ }), r = this.diffPatcher.diff(t, n);
1172
+ if (console.log("normalizedPrevState", t), console.log("normalizedCurrentState", n), !r) {
1173
+ console.log("Нет изменений для сохранения.");
1174
+ return;
1175
+ }
1176
+ if (de({
1177
+ prevState: t,
1178
+ nextState: n
1179
+ })) {
1180
+ console.log("statesEqual. Нет изменений для сохранения.");
1181
+ return;
1182
+ }
1183
+ console.log("baseState", this.baseState), this.currentIndex < this.patches.length && this.patches.splice(this.currentIndex), console.log("diff", r), this.totalChangesCount += 1, this.patches.push({
1184
+ id: D(),
1185
+ diff: r
1186
+ }), this.currentIndex += 1, this.patches.length > this.maxHistoryLength && (this.baseState = this.diffPatcher.patch(this.baseState, this.patches[0].diff), this.patches.shift(), --this.currentIndex, this.baseStateChangesCount += 1), console.log("Состояние сохранено. Текущий индекс истории:", this.currentIndex);
1187
+ }
1155
1188
  saveState() {
1156
1189
  if (console.log("saveState"), !this.skipHistory) {
1157
1190
  if (this._isUiBlocked()) {
@@ -1160,33 +1193,13 @@ var je = class {
1160
1193
  }
1161
1194
  this._isSavingState = !0, console.time("saveState");
1162
1195
  try {
1163
- let e = Ae({
1196
+ let e = this._consumePendingCommittedState();
1197
+ e && (this._pendingSaveTimeoutId !== null && this._pendingSaveReason === e.reason && this._clearPendingSave(), e.reason === "text-edit" && this._deactivateTextEditing(), this._saveSerializedState({ currentStateObj: e.state }));
1198
+ let t = je({
1164
1199
  canvas: this.canvas,
1165
- callback: () => this.canvas.toDatalessObject([...oe])
1200
+ callback: () => this.canvas.toDatalessObject([...ce])
1166
1201
  });
1167
- if (console.timeEnd("saveState"), !this.baseState) {
1168
- this.baseState = e, this.patches = [], this.currentIndex = 0, console.log("Базовое состояние сохранено.");
1169
- return;
1170
- }
1171
- let { prevState: t, nextState: n } = ge({
1172
- prevState: this.getFullState(),
1173
- nextState: e
1174
- }), r = this.diffPatcher.diff(t, n);
1175
- if (console.log("normalizedPrevState", t), console.log("normalizedCurrentState", n), !r) {
1176
- console.log("Нет изменений для сохранения.");
1177
- return;
1178
- }
1179
- if (ue({
1180
- prevState: t,
1181
- nextState: n
1182
- })) {
1183
- console.log("statesEqual. Нет изменений для сохранения.");
1184
- return;
1185
- }
1186
- console.log("baseState", this.baseState), this.currentIndex < this.patches.length && this.patches.splice(this.currentIndex), console.log("diff", r), this.totalChangesCount += 1, this.patches.push({
1187
- id: D(),
1188
- diff: r
1189
- }), this.currentIndex += 1, this.patches.length > this.maxHistoryLength && (this.baseState = this.diffPatcher.patch(this.baseState, this.patches[0].diff), this.patches.shift(), --this.currentIndex, this.baseStateChangesCount += 1), console.log("Состояние сохранено. Текущий индекс истории:", this.currentIndex);
1202
+ console.timeEnd("saveState"), this._saveSerializedState({ currentStateObj: t });
1190
1203
  } finally {
1191
1204
  this._isSavingState = !1;
1192
1205
  }
@@ -1197,8 +1210,8 @@ var je = class {
1197
1210
  console.log("loadStateFromFullState fullState", e);
1198
1211
  let { canvas: t, canvasManager: n, interactionBlocker: r, backgroundManager: i, zoomManager: a, panConstraintManager: o } = this.editor, { width: s, height: c } = t, { width: l, height: u } = this.editor.montageArea;
1199
1212
  r.overlayMask = null;
1200
- let d = ve({ state: e });
1201
- await t.loadFromJSON(d), ye({
1213
+ let d = ye({ state: e });
1214
+ await t.loadFromJSON(d), be({
1202
1215
  state: e,
1203
1216
  canvas: t
1204
1217
  });
@@ -1280,7 +1293,7 @@ var je = class {
1280
1293
  }
1281
1294
  }
1282
1295
  }
1283
- }, Me = .1, Ne = 4096, Pe = 4096, Fe = "application/image-editor:", Ie = /* @__PURE__ */ "customData.backgroundType.format.contentType.width.height.originX.originY.locked.editable.evented.selectable.lockMovementX.lockMovementY.lockRotation.lockScalingX.lockScalingY.lockSkewingX.lockSkewingY.styles.lineFontDefaults.textCaseRaw.uppercase.autoExpand.linethrough.underline.fontStyle.fontWeight.backgroundOpacity.paddingTop.paddingRight.paddingBottom.paddingLeft.radiusTopLeft.radiusTopRight.radiusBottomRight.radiusBottomLeft.shapeComposite.shapePresetKey.shapeBaseWidth.shapeBaseHeight.shapeManualBaseWidth.shapeManualBaseHeight.shapeTextAutoExpand.shapeAlignHorizontal.shapeAlignVertical.shapePaddingTop.shapePaddingRight.shapePaddingBottom.shapePaddingLeft.shapeFill.shapeStroke.shapeStrokeWidth.shapeStrokeDashArray.shapeOpacity.shapeRounding.shapeNodeType".split("."), Le = class e {
1296
+ }, Ne = .1, Pe = 4096, Fe = 4096, Ie = "application/image-editor:", Le = /* @__PURE__ */ "customData.backgroundType.format.contentType.width.height.originX.originY.locked.editable.evented.selectable.lockMovementX.lockMovementY.lockRotation.lockScalingX.lockScalingY.lockSkewingX.lockSkewingY.styles.lineFontDefaults.textCaseRaw.uppercase.autoExpand.linethrough.underline.fontStyle.fontWeight.backgroundOpacity.paddingTop.paddingRight.paddingBottom.paddingLeft.radiusTopLeft.radiusTopRight.radiusBottomRight.radiusBottomLeft.shapeComposite.shapePresetKey.shapeBaseWidth.shapeBaseHeight.shapeManualBaseWidth.shapeManualBaseHeight.shapeTextAutoExpand.shapeAlignHorizontal.shapeAlignVertical.shapePaddingTop.shapePaddingRight.shapePaddingBottom.shapePaddingLeft.shapeFill.shapeStroke.shapeStrokeWidth.shapeStrokeDashArray.shapeOpacity.shapeRounding.shapeNodeType".split("."), Re = class e {
1284
1297
  constructor({ editor: e }) {
1285
1298
  this.editor = e, this.options = e.options, this._createdBlobUrls = [], this.acceptContentTypes = this.editor.options.acceptContentTypes, this.acceptFormats = this.getAllowedFormatsFromContentTypes();
1286
1299
  }
@@ -1477,7 +1490,7 @@ var je = class {
1477
1490
  }
1478
1491
  }
1479
1492
  async resizeImageToBoundaries(e) {
1480
- let { dataURL: t, sizeType: n = "max", contentType: r = "image/png", quality: i = 1, maxWidth: a = Ne, maxHeight: o = Pe, minWidth: s = 16, minHeight: c = 16, asBase64: l = !1, emitMessage: u = !0 } = e, { errorManager: d, workerManager: f } = this.editor, p = {
1493
+ let { dataURL: t, sizeType: n = "max", contentType: r = "image/png", quality: i = 1, maxWidth: a = Pe, maxHeight: o = Fe, minWidth: s = 16, minHeight: c = 16, asBase64: l = !1, emitMessage: u = !0 } = e, { errorManager: d, workerManager: f } = this.editor, p = {
1481
1494
  dataURL: t,
1482
1495
  sizeType: n,
1483
1496
  contentType: r,
@@ -1753,11 +1766,11 @@ var je = class {
1753
1766
  let t = e.match(/^[^/]+\/([^+;]+)/);
1754
1767
  return t ? t[1] : "";
1755
1768
  }
1756
- }, Re = (e, t, n) => Math.max(Math.min(e, n), t), ze = (e, t) => e * t;
1757
- function Be(e) {
1769
+ }, ze = (e, t, n) => Math.max(Math.min(e, n), t), Be = (e, t) => e * t;
1770
+ function Ve(e) {
1758
1771
  return (e?.type === "image" || e?.format === "svg") && typeof e?.width == "number" && typeof e?.height == "number";
1759
1772
  }
1760
- var Ve = class {
1773
+ var He = class {
1761
1774
  constructor({ editor: e }) {
1762
1775
  this.editor = e;
1763
1776
  }
@@ -1767,7 +1780,7 @@ var Ve = class {
1767
1780
  }
1768
1781
  getVisibleCenterPoint() {
1769
1782
  let { canvas: e } = this.editor, t = e.getZoom(), n = e.viewportTransform, r = e.getWidth(), i = e.getHeight(), a = this.getMontageAreaSceneBounds(), o = (r / 2 - n[4]) / t, s = (i / 2 - n[5]) / t;
1770
- return new p(Re(o, a.left, a.right), Re(s, a.top, a.bottom));
1783
+ return new p(ze(o, a.left, a.right), ze(s, a.top, a.bottom));
1771
1784
  }
1772
1785
  getMontageAreaSceneCenter() {
1773
1786
  let { montageArea: e } = this.editor;
@@ -1846,9 +1859,9 @@ var Ve = class {
1846
1859
  }
1847
1860
  setResolutionWidth(e, { preserveProportional: t, withoutSave: n, adaptCanvasToContainer: r } = {}) {
1848
1861
  if (!e) return;
1849
- let { canvas: i, montageArea: a, options: { canvasBackstoreWidth: o } } = this.editor, { width: s, height: c } = a, l = Re(Number(e), 16, Ne);
1862
+ let { canvas: i, montageArea: a, options: { canvasBackstoreWidth: o } } = this.editor, { width: s, height: c } = a, l = ze(Number(e), 16, Pe);
1850
1863
  if (!o || o === "auto" || r ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreWidth(Number(o)) : this.setCanvasBackstoreWidth(l), a.set({ width: l }), this.placeMontageAreaAtCanonicalScenePosition(), t) {
1851
- let e = ze(c, l / s);
1864
+ let e = Be(c, l / s);
1852
1865
  this.setResolutionHeight(e, {
1853
1866
  withoutSave: n,
1854
1867
  adaptCanvasToContainer: r
@@ -1864,9 +1877,9 @@ var Ve = class {
1864
1877
  }
1865
1878
  setResolutionHeight(e, { preserveProportional: t, withoutSave: n, adaptCanvasToContainer: r } = {}) {
1866
1879
  if (!e) return;
1867
- let { canvas: i, montageArea: a, options: { canvasBackstoreHeight: o } } = this.editor, { width: s, height: c } = a, l = Re(Number(e), 16, Pe);
1880
+ let { canvas: i, montageArea: a, options: { canvasBackstoreHeight: o } } = this.editor, { width: s, height: c } = a, l = ze(Number(e), 16, Fe);
1868
1881
  if (!o || o === "auto" || r ? this.adaptCanvasToContainer() : o ? this.setCanvasBackstoreHeight(Number(o)) : this.setCanvasBackstoreHeight(l), a.set({ height: l }), this.placeMontageAreaAtCanonicalScenePosition(), t) {
1869
- let e = ze(s, l / c);
1882
+ let e = Be(s, l / c);
1870
1883
  this.setResolutionWidth(e, {
1871
1884
  withoutSave: n,
1872
1885
  adaptCanvasToContainer: r
@@ -1893,16 +1906,16 @@ var Ve = class {
1893
1906
  }
1894
1907
  setCanvasBackstoreWidth(e) {
1895
1908
  if (!e || typeof e != "number") return;
1896
- let t = Re(e, 16, Ne);
1909
+ let t = ze(e, 16, Pe);
1897
1910
  this.editor.canvas.setDimensions({ width: t }, { backstoreOnly: !0 });
1898
1911
  }
1899
1912
  setCanvasBackstoreHeight(e) {
1900
1913
  if (!e || typeof e != "number") return;
1901
- let t = Re(e, 16, Pe);
1914
+ let t = ze(e, 16, Fe);
1902
1915
  this.editor.canvas.setDimensions({ height: t }, { backstoreOnly: !0 });
1903
1916
  }
1904
1917
  adaptCanvasToContainer() {
1905
- let { canvas: e } = this.editor, t = this.getEditorContainer(), n = t.clientWidth, r = t.clientHeight, i = Re(n, 16, Ne), a = Re(r, 16, Pe);
1918
+ let { canvas: e } = this.editor, t = this.getEditorContainer(), n = t.clientWidth, r = t.clientHeight, i = ze(n, 16, Pe), a = ze(r, 16, Fe);
1906
1919
  e.setDimensions({
1907
1920
  width: i,
1908
1921
  height: a
@@ -1990,8 +2003,8 @@ var Ve = class {
1990
2003
  }
1991
2004
  scaleMontageAreaToImage({ object: e, preserveAspectRatio: t, withoutSave: n } = {}) {
1992
2005
  let { canvas: r, montageArea: i, transformManager: a } = this.editor, o = e || r.getActiveObject();
1993
- if (!Be(o)) return;
1994
- let { width: s, height: c } = o, l = Math.min(s, Ne), u = Math.min(c, Pe);
2006
+ if (!Ve(o)) return;
2007
+ let { width: s, height: c } = o, l = Math.min(s, Pe), u = Math.min(c, Fe);
1995
2008
  if (t) {
1996
2009
  let { width: e, height: t } = i, n = s / e, r = c / t, a = Math.max(n, r);
1997
2010
  l = e * a, u = t * a;
@@ -2019,7 +2032,7 @@ var Ve = class {
2019
2032
  let { canvas: e, montageArea: t, interactionBlocker: { overlayMask: n }, backgroundManager: { backgroundObject: r } } = this.editor;
2020
2033
  return e.getObjects().filter((e) => e.id !== t.id && e.id !== n?.id && e.id !== r?.id);
2021
2034
  }
2022
- }, He = class {
2035
+ }, Ue = class {
2023
2036
  constructor({ editor: e }) {
2024
2037
  this.editor = e, this.options = e.options;
2025
2038
  }
@@ -2127,7 +2140,7 @@ var Ve = class {
2127
2140
  });
2128
2141
  }
2129
2142
  }
2130
- }, Ue = class {
2143
+ }, We = class {
2131
2144
  constructor({ editor: e }) {
2132
2145
  this.editor = e, this.options = e.options, this.minZoom = this.options.minZoom || .1, this.maxZoom = this.options.maxZoom || 2, this.defaultZoom = this._normalizeDefaultZoom(this.options.defaultScale);
2133
2146
  }
@@ -2181,7 +2194,7 @@ var Ve = class {
2181
2194
  y: Math.abs(T) > Math.abs(d) ? d : T
2182
2195
  };
2183
2196
  }
2184
- _applyViewportCentering(e, t = !1, n = Me) {
2197
+ _applyViewportCentering(e, t = !1, n = Ne) {
2185
2198
  let { canvas: r } = this.editor, i = this._getScaledMontageDimensions(e), a = r.getWidth(), o = r.getHeight(), s = i.width > a || i.height > o, c = this._calculateFitZoom(), l = e - c;
2186
2199
  if (!(!s || l) && !t) return !1;
2187
2200
  let u = r.viewportTransform, d = this._calculateTargetViewportPosition(e);
@@ -2230,7 +2243,7 @@ var Ve = class {
2230
2243
  pointY: u.y
2231
2244
  });
2232
2245
  }
2233
- zoom(e = Me, t = {}) {
2246
+ zoom(e = Ne, t = {}) {
2234
2247
  if (!e) return;
2235
2248
  let { minZoom: n, maxZoom: r } = this, { canvas: i } = this.editor, a = e < 0, o = i.getZoom(), s = i.getCenterPoint(), c = new p(t.pointX ?? s.x, t.pointY ?? s.y);
2236
2249
  this.editor.montageArea.setCoords(), this.editor.canvas.requestRenderAll();
@@ -2256,30 +2269,30 @@ var Ve = class {
2256
2269
  point: r
2257
2270
  }), this.editor.panConstraintManager.updateBounds();
2258
2271
  }
2259
- }, W = ({ value: e, fallback: t = 0 }) => typeof e == "number" && Number.isFinite(e) ? e : typeof t == "number" && Number.isFinite(t) ? t : 0, We = ({ value: e, dimension: t, useRelativePositions: n }) => {
2260
- let r = W({ value: e });
2272
+ }, U = ({ value: e, fallback: t = 0 }) => typeof e == "number" && Number.isFinite(e) ? e : typeof t == "number" && Number.isFinite(t) ? t : 0, Ge = ({ value: e, dimension: t, useRelativePositions: n }) => {
2273
+ let r = U({ value: e });
2261
2274
  return n ? r : r / (t || 1);
2262
- }, Ge = ({ object: e, baseWidth: t, baseHeight: n, useRelativePositions: r }) => ({
2263
- x: We({
2275
+ }, Ke = ({ object: e, baseWidth: t, baseHeight: n, useRelativePositions: r }) => ({
2276
+ x: Ge({
2264
2277
  value: e.left,
2265
2278
  dimension: t,
2266
2279
  useRelativePositions: r
2267
2280
  }),
2268
- y: We({
2281
+ y: Ge({
2269
2282
  value: e.top,
2270
2283
  dimension: n,
2271
2284
  useRelativePositions: r
2272
2285
  })
2273
- }), Ke = ({ normalizedX: e, normalizedY: t, bounds: n }) => {
2286
+ }), qe = ({ normalizedX: e, normalizedY: t, bounds: n }) => {
2274
2287
  let { left: r, top: i, width: a, height: o } = n;
2275
2288
  return new p(r + e * a, i + t * o);
2276
- }, qe = ({ object: e }) => {
2289
+ }, Je = ({ object: e }) => {
2277
2290
  let { left: t = 0, top: n = 0, width: r = 0, height: i = 0, scaleX: a = 1, scaleY: o = 1, strokeWidth: s = 0, strokeUniform: c = !1 } = e, l = typeof e.type == "string" ? e.type.toLowerCase() : "", u = e instanceof _ || l === "textbox" || l === "background-textbox", d = c ? 0 : s, f = r + d, p = i + d, m = {
2278
2291
  left: Math.round(t),
2279
2292
  top: Math.round(n)
2280
2293
  };
2281
2294
  u || (f > 0 && (m.scaleX = Math.max(1, Math.round(f * a)) / f), p > 0 && (m.scaleY = Math.max(1, Math.round(p * o)) / p)), e.set(m), e.setCoords();
2282
- }, Je = ({ object: e }) => {
2295
+ }, W = ({ object: e }) => {
2283
2296
  if (!e) return null;
2284
2297
  try {
2285
2298
  e.setCoords();
@@ -2304,7 +2317,7 @@ function Ye({ canvas: e, object: t, left: n, top: r, centerPoint: i, flags: a })
2304
2317
  let n = i ?? e.getCenterPoint();
2305
2318
  t.setPositionByOrigin(n, "center", "center"), t.setCoords();
2306
2319
  }
2307
- return qe({ object: t }), s ? t : (e.add(t), o || e.setActiveObject(t), e.renderAll(), t);
2320
+ return Je({ object: t }), s ? t : (e.add(t), o || e.setActiveObject(t), e.renderAll(), t);
2308
2321
  }
2309
2322
  var Xe = ({ canvas: e, options: t = {}, centerPoint: n, flags: r = {} }) => {
2310
2323
  let { id: i = `rect-${D()}`, left: a, top: o, width: s = 100, height: c = 100, fill: l = "blue", ...u } = t;
@@ -2697,46 +2710,46 @@ var Xe = ({ canvas: e, options: t = {}, centerPoint: n, flags: r = {} }) => {
2697
2710
  this.editor = e;
2698
2711
  }
2699
2712
  bringToFront(t, { withoutSave: n } = {}) {
2700
- let { canvas: r, historyManager: i } = this.editor;
2701
- i.suspendHistory();
2702
- let a = t || r.getActiveObject();
2703
- a && (a instanceof e ? a.getObjects().forEach((e) => {
2713
+ let { canvas: r, historyManager: i, textManager: a } = this.editor;
2714
+ n || a.exitActiveTextEditing(), i.suspendHistory();
2715
+ let o = t || r.getActiveObject();
2716
+ o && (o instanceof e ? o.getObjects().forEach((e) => {
2704
2717
  r.bringObjectToFront(e);
2705
- }) : r.bringObjectToFront(a), r.renderAll(), i.resumeHistory(), n || i.saveState(), r.fire("editor:object-bring-to-front", {
2706
- object: a,
2718
+ }) : r.bringObjectToFront(o), r.renderAll(), i.resumeHistory(), n || i.saveState(), r.fire("editor:object-bring-to-front", {
2719
+ object: o,
2707
2720
  withoutSave: n
2708
2721
  }));
2709
2722
  }
2710
2723
  bringForward(n, { withoutSave: r } = {}) {
2711
- let { canvas: i, historyManager: a } = this.editor;
2712
- a.suspendHistory();
2713
- let o = n || i.getActiveObject();
2714
- o && (o instanceof e ? t._moveSelectionForward(i, o) : i.bringObjectForward(o), i.renderAll(), a.resumeHistory(), r || a.saveState(), i.fire("editor:object-bring-forward", {
2715
- object: o,
2724
+ let { canvas: i, historyManager: a, textManager: o } = this.editor;
2725
+ r || o.exitActiveTextEditing(), a.suspendHistory();
2726
+ let s = n || i.getActiveObject();
2727
+ s && (s instanceof e ? t._moveSelectionForward(i, s) : i.bringObjectForward(s), i.renderAll(), a.resumeHistory(), r || a.saveState(), i.fire("editor:object-bring-forward", {
2728
+ object: s,
2716
2729
  withoutSave: r
2717
2730
  }));
2718
2731
  }
2719
2732
  sendToBack(t, { withoutSave: n } = {}) {
2720
- let { canvas: r, montageArea: i, historyManager: a, interactionBlocker: { overlayMask: o }, backgroundManager: { backgroundObject: s } } = this.editor;
2721
- a.suspendHistory();
2722
- let c = t || r.getActiveObject();
2723
- if (c) {
2724
- if (c instanceof e) {
2725
- let e = c.getObjects();
2733
+ let { canvas: r, montageArea: i, historyManager: a, textManager: o, interactionBlocker: { overlayMask: s }, backgroundManager: { backgroundObject: c } } = this.editor;
2734
+ n || o.exitActiveTextEditing(), a.suspendHistory();
2735
+ let l = t || r.getActiveObject();
2736
+ if (l) {
2737
+ if (l instanceof e) {
2738
+ let e = l.getObjects();
2726
2739
  for (let t = e.length - 1; t >= 0; --t) r.sendObjectToBack(e[t]);
2727
- } else r.sendObjectToBack(c);
2728
- s && r.sendObjectToBack(s), r.sendObjectToBack(i), o && r.sendObjectToBack(o), r.renderAll(), a.resumeHistory(), n || a.saveState(), r.fire("editor:object-send-to-back", {
2729
- object: c,
2740
+ } else r.sendObjectToBack(l);
2741
+ c && r.sendObjectToBack(c), r.sendObjectToBack(i), s && r.sendObjectToBack(s), r.renderAll(), a.resumeHistory(), n || a.saveState(), r.fire("editor:object-send-to-back", {
2742
+ object: l,
2730
2743
  withoutSave: n
2731
2744
  });
2732
2745
  }
2733
2746
  }
2734
2747
  sendBackwards(n, { withoutSave: r } = {}) {
2735
- let { canvas: i, montageArea: a, historyManager: o, interactionBlocker: { overlayMask: s }, backgroundManager: { backgroundObject: c } } = this.editor;
2736
- o.suspendHistory();
2737
- let l = n || i.getActiveObject();
2738
- l && (l instanceof e ? t._moveSelectionBackwards(i, l) : i.sendObjectBackwards(l), c && i.sendObjectToBack(c), i.sendObjectToBack(a), s && i.sendObjectToBack(s), i.renderAll(), o.resumeHistory(), r || o.saveState(), i.fire("editor:object-send-backwards", {
2739
- object: l,
2748
+ let { canvas: i, montageArea: a, historyManager: o, textManager: s, interactionBlocker: { overlayMask: c }, backgroundManager: { backgroundObject: l } } = this.editor;
2749
+ r || s.exitActiveTextEditing(), o.suspendHistory();
2750
+ let u = n || i.getActiveObject();
2751
+ u && (u instanceof e ? t._moveSelectionBackwards(i, u) : i.sendObjectBackwards(u), l && i.sendObjectToBack(l), i.sendObjectToBack(a), c && i.sendObjectToBack(c), i.renderAll(), o.resumeHistory(), r || o.saveState(), i.fire("editor:object-send-backwards", {
2752
+ object: u,
2740
2753
  withoutSave: r
2741
2754
  }));
2742
2755
  }
@@ -4086,14 +4099,15 @@ var dn = ({ group: e }) => {
4086
4099
  subTargetCheck: !0
4087
4100
  });
4088
4101
  }, fn = ({ text: e }) => {
4102
+ let t = !!(e.locked || e.group?.locked);
4089
4103
  e.set({
4090
4104
  hasBorders: !1,
4091
4105
  hasControls: !1,
4092
4106
  evented: !1,
4093
4107
  selectable: !1,
4094
- lockMovementX: !1,
4095
- lockMovementY: !1,
4096
- editable: !0,
4108
+ lockMovementX: t,
4109
+ lockMovementY: t,
4110
+ editable: !t,
4097
4111
  autoExpand: !1,
4098
4112
  shapeNodeType: "text"
4099
4113
  }), e.setCoords();
@@ -4897,15 +4911,21 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
4897
4911
  }
4898
4912
  enterTextEditing({ group: e }) {
4899
4913
  let { text: t } = Y({ group: e });
4900
- t && (this._enterTextEditingInteractionMode({
4901
- group: e,
4902
- text: t
4903
- }), t.set({
4904
- evented: !0,
4905
- selectable: !0,
4906
- lockMovementX: !0,
4907
- lockMovementY: !0
4908
- }), this.canvas.setActiveObject(t), t.isEditing || (t.enterEditing(), t.selectAll()), this.canvas.requestRenderAll());
4914
+ if (t) {
4915
+ if (e.locked || t.locked) {
4916
+ fn({ text: t }), this.canvas.requestRenderAll();
4917
+ return;
4918
+ }
4919
+ this._enterTextEditingInteractionMode({
4920
+ group: e,
4921
+ text: t
4922
+ }), t.set({
4923
+ evented: !0,
4924
+ selectable: !0,
4925
+ lockMovementX: !0,
4926
+ lockMovementY: !0
4927
+ }), this.canvas.setActiveObject(t), t.isEditing || (t.enterEditing(), t.selectAll()), this.canvas.requestRenderAll();
4928
+ }
4909
4929
  }
4910
4930
  _enterTextEditingInteractionMode({ group: e, text: t }) {
4911
4931
  this.editingInteractionState.has(e) || this.editingInteractionState.set(e, {
@@ -5081,7 +5101,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5081
5101
  l !== void 0 && (M = Math.max(1, l)), l === void 0 && C && !w && (M = Math.max(1, x.width));
5082
5102
  let N = Math.max(1, u ?? r.shapeManualBaseHeight ?? S), { shape: P, text: F } = Y({ group: r });
5083
5103
  if (!P || !F) return null;
5084
- let ee = {
5104
+ let I = {
5085
5105
  angle: 0,
5086
5106
  skewX: 0,
5087
5107
  skewY: 0,
@@ -5094,20 +5114,20 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5094
5114
  top: 0,
5095
5115
  originX: "left",
5096
5116
  originY: "top"
5097
- }, I = this._createTextNode({
5117
+ }, ee = this._createTextNode({
5098
5118
  text: F.textCaseRaw ?? F.text ?? "",
5099
5119
  textStyle: this._resolveCurrentTextStyle({ textNode: F }),
5100
5120
  width: Math.max(1, F.width ?? x.width),
5101
5121
  align: D
5102
5122
  });
5103
- I.set(ee), this._applyTextUpdates({
5104
- textNode: I,
5123
+ ee.set(I), this._applyTextUpdates({
5124
+ textNode: ee,
5105
5125
  text: f,
5106
5126
  textStyle: p,
5107
5127
  align: D
5108
5128
  });
5109
5129
  let L = this._resolveShapeLayoutWidth({
5110
- text: I,
5130
+ text: ee,
5111
5131
  currentWidth: x.width,
5112
5132
  manualWidth: M,
5113
5133
  shapeTextAutoExpandEnabled: w,
@@ -5122,7 +5142,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5122
5142
  }), ne = r.getObjects().indexOf(P);
5123
5143
  if (ne < 0) return null;
5124
5144
  let R = () => {
5125
- this._detachShapeGroupAutoLayout({ group: r }), F.set(ee), this._applyTextUpdates({
5145
+ this._detachShapeGroupAutoLayout({ group: r }), F.set(I), this._applyTextUpdates({
5126
5146
  textNode: F,
5127
5147
  text: f,
5128
5148
  textStyle: p,
@@ -5621,7 +5641,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5621
5641
  async _cloneToInternalClipboard(e) {
5622
5642
  let { canvas: t, errorManager: n } = this.editor;
5623
5643
  try {
5624
- let n = await e.clone(Ie);
5644
+ let n = await e.clone(Le);
5625
5645
  this.clipboard = n, t.fire("editor:object-copied", { object: n });
5626
5646
  } catch (e) {
5627
5647
  n.emitError({
@@ -5642,7 +5662,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5642
5662
  message: "navigator.clipboard не поддерживается в этом браузере или отсутствует HTTPS-соединение."
5643
5663
  }), !1;
5644
5664
  try {
5645
- let t = e.toObject(Ie), n = JSON.stringify(t);
5665
+ let t = e.toObject(Le), n = JSON.stringify(t);
5646
5666
  return e.type === "image" ? this._copyImageToClipboard(e, n) : this._copyTextToClipboard(n);
5647
5667
  } catch (e) {
5648
5668
  return t.emitError({
@@ -5672,7 +5692,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5672
5692
  }
5673
5693
  async _copyTextToClipboard(e) {
5674
5694
  try {
5675
- let t = `${Fe}${e}`;
5695
+ let t = `${Ie}${e}`;
5676
5696
  return await navigator.clipboard.writeText(t), console.info("Text copied to clipboard successfully"), !0;
5677
5697
  } catch (e) {
5678
5698
  let { errorManager: t } = this.editor;
@@ -5757,7 +5777,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5757
5777
  let { canvas: n } = this.editor, r = t || n.getActiveObject();
5758
5778
  if (!r || r.locked) return !1;
5759
5779
  try {
5760
- let t = await r.clone(Ie);
5780
+ let t = await r.clone(Le);
5761
5781
  return t instanceof e && t.forEachObject((e) => {
5762
5782
  e.set({
5763
5783
  id: `${e.type}-${D()}`,
@@ -5831,7 +5851,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5831
5851
  let { canvas: t } = this.editor;
5832
5852
  if (!this.clipboard) return !1;
5833
5853
  try {
5834
- let n = await this.clipboard.clone(Ie);
5854
+ let n = await this.clipboard.clone(Le);
5835
5855
  return t.discardActiveObject(), n instanceof e && n.forEachObject((e) => {
5836
5856
  e.set({
5837
5857
  id: `${e.type}-${D()}`,
@@ -5863,9 +5883,9 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5863
5883
  this.editor = e;
5864
5884
  }
5865
5885
  lockObject({ object: e, skipInnerObjects: n, withoutSave: r } = {}) {
5866
- let { canvas: i, historyManager: a } = this.editor, o = e || i.getActiveObject();
5867
- if (!o || o.locked) return;
5868
- let s = {
5886
+ let { canvas: i, historyManager: a } = this.editor, o = e || i.getActiveObject(), s = En({ target: o }) ?? o;
5887
+ if (!s || s.locked) return;
5888
+ let c = {
5869
5889
  lockMovementX: !0,
5870
5890
  lockMovementY: !0,
5871
5891
  lockRotation: !0,
@@ -5875,19 +5895,19 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5875
5895
  lockSkewingY: !0,
5876
5896
  editable: !1,
5877
5897
  locked: !0
5878
- };
5879
- o.set(s), !n && t._isGroupOrSelection(o) && o.getObjects().forEach((e) => {
5880
- e.set(s);
5881
- }), o instanceof _ && o.isEditing && o.exitEditing(), i.renderAll(), r || a.saveState(), i.fire("editor:object-locked", {
5882
- object: o,
5898
+ }, l = n ? [s] : t._collectLockTargets({ object: s });
5899
+ t._exitEditingInTextboxes({ objects: l });
5900
+ for (let e = 0; e < l.length; e += 1) l[e].set(c);
5901
+ i.renderAll(), r || a.saveState(), i.fire("editor:object-locked", {
5902
+ object: s,
5883
5903
  skipInnerObjects: n,
5884
5904
  withoutSave: r
5885
5905
  });
5886
5906
  }
5887
5907
  unlockObject({ object: e, withoutSave: n } = {}) {
5888
- let { canvas: r, historyManager: i } = this.editor, a = e || r.getActiveObject();
5889
- if (!a) return;
5890
- let o = {
5908
+ let { canvas: r, historyManager: i } = this.editor, a = e || r.getActiveObject(), o = En({ target: a }) ?? a;
5909
+ if (!o) return;
5910
+ let s = {
5891
5911
  lockMovementX: !1,
5892
5912
  lockMovementY: !1,
5893
5913
  lockRotation: !1,
@@ -5897,17 +5917,32 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5897
5917
  lockSkewingY: !1,
5898
5918
  editable: !0,
5899
5919
  locked: !1
5900
- };
5901
- a.set(o), t._isGroupOrSelection(a) && a.getObjects().forEach((e) => {
5902
- e.set(o);
5903
- }), r.renderAll(), n || i.saveState(), r.fire("editor:object-unlocked", {
5904
- object: a,
5920
+ }, c = t._collectLockTargets({ object: o });
5921
+ for (let e = 0; e < c.length; e += 1) c[e].set(s);
5922
+ r.renderAll(), n || i.saveState(), r.fire("editor:object-unlocked", {
5923
+ object: o,
5905
5924
  withoutSave: n
5906
5925
  });
5907
5926
  }
5908
5927
  static _isGroupOrSelection(t) {
5909
5928
  return t instanceof e || t instanceof l;
5910
5929
  }
5930
+ static _collectLockTargets({ object: e }) {
5931
+ let n = [e];
5932
+ if (!t._isGroupOrSelection(e)) return n;
5933
+ let r = e.getObjects();
5934
+ for (let e = 0; e < r.length; e += 1) {
5935
+ let i = r[e], a = t._collectLockTargets({ object: i });
5936
+ for (let e = 0; e < a.length; e += 1) n.push(a[e]);
5937
+ }
5938
+ return n;
5939
+ }
5940
+ static _exitEditingInTextboxes({ objects: e }) {
5941
+ for (let t = 0; t < e.length; t += 1) {
5942
+ let n = e[t];
5943
+ !(n instanceof _) || !n.isEditing || n.exitEditing();
5944
+ }
5945
+ }
5911
5946
  }, Zn = class {
5912
5947
  constructor({ editor: e }) {
5913
5948
  this.editor = e;
@@ -6187,24 +6222,26 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6187
6222
  }), [e, ...n];
6188
6223
  }
6189
6224
  deleteSelectedObjects({ objects: t, withoutSave: n = !1, _isRecursiveCall: r = !1 } = {}) {
6190
- let { canvas: i, historyManager: a } = this.editor, o = (t || i.getActiveObjects()).filter((e) => !e.locked);
6191
- if (!o?.length) return null;
6225
+ let { canvas: i, historyManager: a, textManager: o } = this.editor;
6226
+ !r && !n && o.exitActiveTextEditing();
6227
+ let s = (t || i.getActiveObjects()).filter((e) => !e.locked);
6228
+ if (!s?.length) return null;
6192
6229
  r || a.suspendHistory();
6193
- let s = [];
6194
- if (o.forEach((t) => {
6230
+ let c = [];
6231
+ if (s.forEach((t) => {
6195
6232
  if (e._isUngroupableGroup(t)) {
6196
6233
  let e = this._handleGroupDeletion(t);
6197
- s.push(...e);
6234
+ c.push(...e);
6198
6235
  return;
6199
6236
  }
6200
- i.remove(t), s.push(t);
6237
+ i.remove(t), c.push(t);
6201
6238
  }), r) return null;
6202
6239
  i.discardActiveObject(), i.renderAll(), a.resumeHistory(), n || a.saveState();
6203
- let c = {
6204
- objects: s,
6240
+ let l = {
6241
+ objects: c,
6205
6242
  withoutSave: n
6206
6243
  };
6207
- return i.fire("editor:objects-deleted", c), c;
6244
+ return i.fire("editor:objects-deleted", l), l;
6208
6245
  }
6209
6246
  }, er = {
6210
6247
  IMAGE_MANAGER: {
@@ -6418,7 +6455,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6418
6455
  super(e, t), this.backgroundOpacity = t.backgroundOpacity ?? 1, this.lineFontDefaults = t.lineFontDefaults ?? void 0, this.paddingTop = t.paddingTop ?? 0, this.paddingRight = t.paddingRight ?? 0, this.paddingBottom = t.paddingBottom ?? 0, this.paddingLeft = t.paddingLeft ?? 0, this.radiusTopLeft = t.radiusTopLeft ?? 0, this.radiusTopRight = t.radiusTopRight ?? 0, this.radiusBottomRight = t.radiusBottomRight ?? 0, this.radiusBottomLeft = t.radiusBottomLeft ?? 0, this._roundDimensions();
6419
6456
  }
6420
6457
  initDimensions() {
6421
- super.initDimensions(), this._roundDimensions();
6458
+ super.initDimensions(), this.shouldRoundDimensionsOnInit !== !1 && this._roundDimensions();
6422
6459
  }
6423
6460
  _getLeftOffset() {
6424
6461
  let { width: e } = this._getBackgroundDimensions(), { left: t } = this._getPadding();
@@ -6664,10 +6701,431 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6664
6701
  let s = e[o];
6665
6702
  if (!s) continue;
6666
6703
  let c = { ...s };
6667
- typeof s.fontSize == "number" && (c.fontSize = Math.max(1, s.fontSize * t), i = !0), n[o] = c, r = !0;
6704
+ if (typeof s.fontSize == "number") {
6705
+ let e = Math.min(8, s.fontSize);
6706
+ c.fontSize = Math.max(e, s.fontSize * t), i = !0;
6707
+ }
6708
+ n[o] = c, r = !0;
6668
6709
  }
6669
6710
  if (!(!r || !i)) return n;
6670
- }, yr = ({ textbox: e }) => {
6711
+ }, yr = ({ textbox: e, text: t }) => {
6712
+ let { textLines: n } = e, r = Array.isArray(n) && n.length > 0 ? n.length : Math.max(t.split("\n").length, 1), i = 0;
6713
+ for (let t = 0; t < r; t += 1) {
6714
+ let n = e.getLineWidth(t);
6715
+ n > i && (i = n);
6716
+ }
6717
+ return i;
6718
+ }, br = ({ textbox: e, montageLeft: t, montageRight: n }) => {
6719
+ e.setCoords();
6720
+ let r = e.getBoundingRect(!1, !0), i = r.left ?? 0, a = i + (r.width ?? 0), o = n - t;
6721
+ if (o > 0 && (r.width ?? 0) >= o - .01) return !1;
6722
+ let s = 0;
6723
+ return i < t ? s = t - i : a > n && (s = n - a), Math.abs(s) <= .01 ? !1 : (e.set({ left: (e.left ?? 0) + s }), !0);
6724
+ }, xr = ({ rawValue: e, calculatedValue: t }) => typeof e == "number" ? e : typeof t == "number" ? t : 0, Sr = ({ stylesList: e }) => {
6725
+ let t = e.length;
6726
+ if (!t) return !1;
6727
+ for (let n = 0; n < t; n += 1) {
6728
+ let t = e[n];
6729
+ if (!t) continue;
6730
+ let { fontFamily: r, fontSize: i, fontWeight: a, fontStyle: o, lineHeight: s, charSpacing: c } = t;
6731
+ if (r !== void 0 || i !== void 0 || a !== void 0 || o !== void 0 || s !== void 0 || c !== void 0) return !0;
6732
+ }
6733
+ return !1;
6734
+ }, Cr = ({ textbox: e }) => {
6735
+ let { width: t, height: n, calcTextWidth: r, calcTextHeight: i } = e, a = typeof r == "function" ? r.call(e) : void 0, o = typeof i == "function" ? i.call(e) : void 0, s = xr({
6736
+ rawValue: t,
6737
+ calculatedValue: a
6738
+ }), c = xr({
6739
+ rawValue: n,
6740
+ calculatedValue: o
6741
+ }), l = Number.isFinite(s) ? Math.round(s) : null, u = Number.isFinite(c) ? Math.round(c) : null, d = {};
6742
+ return l !== null && l !== s && (d.width = Math.max(0, l)), u !== null && u !== c && (d.height = Math.max(0, u)), Object.keys(d).length ? (e.set(d), !0) : !1;
6743
+ }, wr = ({ textbox: e }) => {
6744
+ let t = e.width ?? e.calcTextWidth(), n = e.fontSize ?? 16, { styles: r = {} } = e, { lineFontDefaults: i } = e, { paddingTop: a = 0, paddingRight: o = 0, paddingBottom: s = 0, paddingLeft: c = 0 } = e, { radiusTopLeft: l = 0, radiusTopRight: u = 0, radiusBottomRight: d = 0, radiusBottomLeft: f = 0 } = e;
6745
+ return {
6746
+ width: t,
6747
+ fontSize: n,
6748
+ padding: {
6749
+ top: a,
6750
+ right: o,
6751
+ bottom: s,
6752
+ left: c
6753
+ },
6754
+ radii: {
6755
+ topLeft: l,
6756
+ topRight: u,
6757
+ bottomRight: d,
6758
+ bottomLeft: f
6759
+ },
6760
+ styles: JSON.parse(JSON.stringify(r)),
6761
+ lineFontDefaults: _r({ lineFontDefaults: i })
6762
+ };
6763
+ }, Tr = ({ base: e }) => {
6764
+ let t = 1 / Math.max(1, e.width), n = [e.fontSize];
6765
+ Object.values(e.styles).forEach((e) => {
6766
+ Object.values(e).forEach((e) => {
6767
+ let { fontSize: t } = e;
6768
+ typeof t != "number" || !Number.isFinite(t) || t <= 0 || n.push(t);
6769
+ });
6770
+ }), Object.values(e.lineFontDefaults ?? {}).forEach((e) => {
6771
+ let { fontSize: t } = e;
6772
+ typeof t != "number" || !Number.isFinite(t) || t <= 0 || n.push(t);
6773
+ });
6774
+ let r = n.reduce((e, t) => Math.max(e, Math.min(8, t) / t), 0);
6775
+ return {
6776
+ widthScale: t,
6777
+ fontScale: r,
6778
+ proportionalScale: Math.max(t, r)
6779
+ };
6780
+ }, Er = ({ textbox: e, canvasManager: t, base: n, widthScale: r, heightScale: i, placement: a, shouldScaleFontSize: o, shouldScalePadding: s, shouldScaleRadii: c, shouldDisableAutoExpandOnHorizontalChange: l = !1, shouldRoundDimensions: u = !0 }) => {
6781
+ let { width: d, fontSize: f, padding: p, radii: m, styles: h, lineFontDefaults: g } = n, _ = Math.max(1, d * r), v = u ? Math.max(1, Math.round(_)) : _, y = Math.max(Math.min(8, f), f * i), b = Object.keys(h).length > 0, x;
6782
+ if (o && b) {
6783
+ let e = {};
6784
+ Object.entries(h).forEach(([t, n]) => {
6785
+ if (!n) return;
6786
+ let r = {};
6787
+ Object.entries(n).forEach(([e, t]) => {
6788
+ if (!t) return;
6789
+ let n = { ...t };
6790
+ if (typeof t.fontSize == "number") {
6791
+ let e = Math.min(8, t.fontSize);
6792
+ n.fontSize = Math.max(e, t.fontSize * i);
6793
+ }
6794
+ r[e] = n;
6795
+ }), Object.keys(r).length && (e[t] = r);
6796
+ }), Object.keys(e).length && (x = e);
6797
+ }
6798
+ let S;
6799
+ o && (S = vr({
6800
+ lineFontDefaults: g,
6801
+ scale: i
6802
+ }));
6803
+ let C = s ? {
6804
+ top: Math.max(0, p.top * i),
6805
+ right: Math.max(0, p.right * i),
6806
+ bottom: Math.max(0, p.bottom * i),
6807
+ left: Math.max(0, p.left * i)
6808
+ } : p, w = c ? {
6809
+ topLeft: Math.max(0, m.topLeft * i),
6810
+ topRight: Math.max(0, m.topRight * i),
6811
+ bottomRight: Math.max(0, m.bottomRight * i),
6812
+ bottomLeft: Math.max(0, m.bottomLeft * i)
6813
+ } : m, T = e.width ?? d, E = Math.abs(v - T) > mr;
6814
+ l && E && (e.autoExpand = !1), x && (e.styles = x), S && (e.lineFontDefaults = S), e.set({
6815
+ width: v,
6816
+ fontSize: o ? y : f,
6817
+ paddingTop: C.top,
6818
+ paddingRight: C.right,
6819
+ paddingBottom: C.bottom,
6820
+ paddingLeft: C.left,
6821
+ radiusTopLeft: w.topLeft,
6822
+ radiusTopRight: w.topRight,
6823
+ radiusBottomRight: w.bottomRight,
6824
+ radiusBottomLeft: w.bottomLeft,
6825
+ scaleX: 1,
6826
+ scaleY: 1
6827
+ });
6828
+ let D = e.shouldRoundDimensionsOnInit;
6829
+ e.shouldRoundDimensionsOnInit = u;
6830
+ try {
6831
+ e.initDimensions();
6832
+ } finally {
6833
+ e.shouldRoundDimensionsOnInit = D;
6834
+ }
6835
+ let O = u ? Cr({ textbox: e }) : !1;
6836
+ return O && (e.dirty = !0), t.applyObjectPlacement({
6837
+ object: e,
6838
+ placement: a
6839
+ }), e.setCoords(), {
6840
+ appliedWidth: e.width ?? v,
6841
+ dimensionsRounded: O
6842
+ };
6843
+ }, Dr = ({ transform: e }) => {
6844
+ let { corner: t = "", action: n = "" } = e;
6845
+ return {
6846
+ isCornerHandle: t === "tl" || t === "tr" || t === "bl" || t === "br" || n === "scale",
6847
+ isHorizontalHandle: t === "ml" || t === "mr" || n === "scaleX",
6848
+ isVerticalHandle: t === "mt" || t === "mb" || n === "scaleY"
6849
+ };
6850
+ }, Or = ({ textbox: e, transform: t, appliedWidth: n }) => {
6851
+ t.scaleX = 1, t.scaleY = 1;
6852
+ let { original: r } = t;
6853
+ r && (r.scaleX = 1, r.scaleY = 1, r.width = n, r.height = e.height, r.left = e.left, r.top = e.top);
6854
+ }, kr = ({ textbox: e, transform: t, scenePoint: n }) => {
6855
+ let { x: r, y: i } = e._getTransformedDimensions();
6856
+ if (r <= 0 || i <= 0) return null;
6857
+ let a = b.getLocalPoint(t, t.originX, t.originY, n.x, n.y), o = t, s = typeof o.signX == "number" && a.x * o.signX <= 0, c = typeof o.signY == "number" && a.y * o.signY <= 0, l = Math.abs(a.x / r), u = Math.abs(a.y / i);
6858
+ return (t.originX === "center" || t.originX === .5) && (t.originY === "center" || t.originY === .5) && (l *= 2, u *= 2), {
6859
+ passedOriginX: s,
6860
+ passedOriginY: c,
6861
+ stepScaleX: l,
6862
+ stepScaleY: u
6863
+ };
6864
+ }, Ar = 1e-4;
6865
+ function jr(e) {
6866
+ return !!e && e instanceof _;
6867
+ }
6868
+ function Mr(e) {
6869
+ if (!jr(e)) return !1;
6870
+ let t = e.group;
6871
+ return e.shapeNodeType === "text" && t?.shapeComposite === !0;
6872
+ }
6873
+ var Nr = class {
6874
+ constructor({ canvas: t, canvasManager: n, persistScaledTextbox: r }) {
6875
+ this.handleMouseMove = (e) => {
6876
+ let t = this.canvas._currentTransform;
6877
+ if (!t) return;
6878
+ let { target: n } = t;
6879
+ if (!jr(n) || Mr(n)) return;
6880
+ let r = this.scalingState.get(n);
6881
+ if (!r || !e.e) return;
6882
+ let { isCornerHandle: i, isHorizontalHandle: a, isVerticalHandle: o } = Dr({ transform: t });
6883
+ if (!a && !o && !i) return;
6884
+ let s = kr({
6885
+ textbox: n,
6886
+ transform: t,
6887
+ scenePoint: this.canvas.getScenePoint(e.e)
6888
+ });
6889
+ if (!s) return;
6890
+ let { passedOriginX: c, passedOriginY: l, stepScaleX: u, stepScaleY: d } = s, f = t.originX ?? n.originX ?? "center", p = t.originY ?? n.originY ?? "center", m = this.canvasManager.getObjectPlacement({
6891
+ object: n,
6892
+ originX: f,
6893
+ originY: p
6894
+ }), { paddingTop: h = 0, paddingRight: g = 0, paddingBottom: _ = 0, paddingLeft: v = 0, radiusTopLeft: y = 0, radiusTopRight: b = 0, radiusBottomRight: x = 0, radiusBottomLeft: S = 0, fontSize: C, width: w } = n, { width: T, fontSize: E } = r.startBase, D = w ?? T, O = C ?? E, k = {
6895
+ top: h,
6896
+ right: g,
6897
+ bottom: _,
6898
+ left: v
6899
+ }, A = {
6900
+ topLeft: y,
6901
+ topRight: b,
6902
+ bottomRight: x,
6903
+ bottomLeft: S
6904
+ }, j = r.lastAllowedScaleX, M = r.lastAllowedScaleY;
6905
+ if (i) {
6906
+ let e = Math.max(r.minimumProportionalScale, r.lastAllowedScaleX * Math.sqrt(u * d)), t = c || l ? r.minimumProportionalScale : e;
6907
+ if (Math.abs(t - r.lastAllowedScaleX) <= Ar) return;
6908
+ j = t, M = t;
6909
+ } else {
6910
+ if (a) {
6911
+ let e = r.lastAllowedScaleX * u, t = c ? r.minimumWidthScale : Math.max(r.minimumWidthScale, e);
6912
+ Math.abs(t - r.lastAllowedScaleX) > Ar && (j = t);
6913
+ }
6914
+ if (o) {
6915
+ let e = r.lastAllowedScaleY * d, t = l ? r.minimumFontScale : Math.max(r.minimumFontScale, e);
6916
+ Math.abs(t - r.lastAllowedScaleY) > Ar && (M = t);
6917
+ }
6918
+ if (Math.abs(j - r.lastAllowedScaleX) <= Ar && Math.abs(M - r.lastAllowedScaleY) <= Ar) return;
6919
+ }
6920
+ let { appliedWidth: N, dimensionsRounded: P } = Er({
6921
+ textbox: n,
6922
+ canvasManager: this.canvasManager,
6923
+ base: r.startBase,
6924
+ widthScale: j,
6925
+ heightScale: M,
6926
+ placement: m,
6927
+ shouldScaleFontSize: i || o,
6928
+ shouldScalePadding: i || o,
6929
+ shouldScaleRadii: i || o,
6930
+ shouldDisableAutoExpandOnHorizontalChange: a,
6931
+ shouldRoundDimensions: !i
6932
+ });
6933
+ Or({
6934
+ textbox: n,
6935
+ transform: t,
6936
+ appliedWidth: N
6937
+ }), this._updateScalingStateAfterLiveCommit({
6938
+ textbox: n,
6939
+ state: r,
6940
+ appliedWidth: N,
6941
+ previousFontSize: O,
6942
+ previousPadding: k,
6943
+ previousRadii: A,
6944
+ previousWidth: D,
6945
+ dimensionsRounded: P,
6946
+ isCornerHandle: i,
6947
+ isHorizontalHandle: a,
6948
+ isVerticalHandle: o,
6949
+ originX: f,
6950
+ originY: p
6951
+ }), this.canvas.requestRenderAll();
6952
+ }, this.handleObjectScaling = (t) => {
6953
+ let { target: n, transform: r } = t;
6954
+ if (n instanceof e || !jr(n) || Mr(n) || !r) return;
6955
+ n.isScaling = !0;
6956
+ let i = this._ensureScalingState({
6957
+ textbox: n,
6958
+ transform: r
6959
+ }), { startBase: a } = i, { width: o, fontSize: s } = a, { isCornerHandle: c, isHorizontalHandle: l, isVerticalHandle: u } = Dr({ transform: r }), d = r.corner ?? "", f = c || u;
6960
+ if (!l && !u && !c) return;
6961
+ let p = n.scaleX ?? r.scaleX ?? 1, m = n.scaleY ?? r.scaleY ?? 1, h = Math.abs(p) || 1, g = Math.abs(m) || 1, _ = r.originX ?? n.originX ?? "center", v = r.originY ?? n.originY ?? "center", y = this.canvasManager.getObjectPlacement({
6962
+ object: n,
6963
+ originX: _,
6964
+ originY: v
6965
+ }), { paddingTop: b = 0, paddingRight: x = 0, paddingBottom: S = 0, paddingLeft: C = 0, radiusTopLeft: w = 0, radiusTopRight: T = 0, radiusBottomRight: E = 0, radiusBottomLeft: D = 0, fontSize: O, width: k } = n, A = c || u, j = c || u, M = k ?? o, N = i.lastAllowedScaleX, P = i.lastAllowedScaleY, F = y, I = !0;
6966
+ if (c) {
6967
+ let e = Math.sqrt(h * g), t = i.lastAllowedScaleX * e, n = p < 0 || m < 0, r = _ !== i.startTransformOriginX || v !== i.startTransformOriginY, a = d !== i.startTransformCorner;
6968
+ if (n || r || a) N = i.lastAllowedScaleX, P = i.lastAllowedScaleY, F = i.lastAllowedPlacement, I = !1;
6969
+ else {
6970
+ let e = Math.max(i.minimumProportionalScale, t);
6971
+ N = e, P = e;
6972
+ }
6973
+ } else l && (N = Math.max(i.minimumWidthScale, i.lastAllowedScaleX * h)), u && (P = Math.max(i.minimumFontScale, i.lastAllowedScaleY * g));
6974
+ let { appliedWidth: ee, dimensionsRounded: L } = Er({
6975
+ textbox: n,
6976
+ canvasManager: this.canvasManager,
6977
+ base: a,
6978
+ widthScale: N,
6979
+ heightScale: P,
6980
+ placement: F,
6981
+ shouldScaleFontSize: f,
6982
+ shouldScalePadding: A,
6983
+ shouldScaleRadii: j,
6984
+ shouldDisableAutoExpandOnHorizontalChange: l,
6985
+ shouldRoundDimensions: !c
6986
+ });
6987
+ Or({
6988
+ textbox: n,
6989
+ transform: r,
6990
+ appliedWidth: ee
6991
+ }), this.canvas.requestRenderAll(), I && this._updateScalingStateAfterLiveCommit({
6992
+ textbox: n,
6993
+ state: i,
6994
+ appliedWidth: ee,
6995
+ previousFontSize: O ?? s,
6996
+ previousPadding: {
6997
+ top: b,
6998
+ right: x,
6999
+ bottom: S,
7000
+ left: C
7001
+ },
7002
+ previousRadii: {
7003
+ topLeft: w,
7004
+ topRight: T,
7005
+ bottomRight: E,
7006
+ bottomLeft: D
7007
+ },
7008
+ previousWidth: M,
7009
+ dimensionsRounded: L,
7010
+ isCornerHandle: c,
7011
+ isHorizontalHandle: l,
7012
+ isVerticalHandle: u,
7013
+ originX: _,
7014
+ originY: v
7015
+ });
7016
+ }, this.handleObjectModified = (t) => {
7017
+ let { target: n } = t;
7018
+ if (n instanceof e) {
7019
+ let t = n.getObjects();
7020
+ if (!t.some((e) => jr(e))) return;
7021
+ let { scaleX: r = 1, scaleY: i = 1 } = n;
7022
+ if (Math.abs(r - 1) < .01 && Math.abs(i - 1) < .01) return;
7023
+ this.canvas.discardActiveObject(), t.forEach((e) => {
7024
+ this.commitStandaloneTextScale({ target: e }), e.setCoords();
7025
+ });
7026
+ let a = new e(t, { canvas: this.canvas });
7027
+ this.canvas.setActiveObject(a), this.canvas.requestRenderAll();
7028
+ return;
7029
+ }
7030
+ if (!jr(n) || Mr(n)) return;
7031
+ n.isScaling = !1;
7032
+ let r = this.scalingState.get(n);
7033
+ if (this.scalingState.delete(n), !r?.hasScalingChange) return;
7034
+ let i = n.width ?? n.calcTextWidth(), { fontSize: a, styles: o } = r.startBase, s = n.fontSize ?? a ?? 16, c = Object.keys(o).length > 0, { paddingTop: l = 0, paddingRight: u = 0, paddingBottom: d = 0, paddingLeft: f = 0, radiusTopLeft: p = 0, radiusTopRight: m = 0, radiusBottomRight: h = 0, radiusBottomLeft: g = 0 } = n, _ = {
7035
+ width: i,
7036
+ paddingTop: l,
7037
+ paddingRight: u,
7038
+ paddingBottom: d,
7039
+ paddingLeft: f,
7040
+ radiusTopLeft: p,
7041
+ radiusTopRight: m,
7042
+ radiusBottomRight: h,
7043
+ radiusBottomLeft: g
7044
+ };
7045
+ c || (_.fontSize = s), this.persistScaledTextbox({
7046
+ target: n,
7047
+ style: _
7048
+ }), n.set({
7049
+ scaleX: 1,
7050
+ scaleY: 1
7051
+ }), n.setCoords();
7052
+ }, this.canvas = t, this.canvasManager = n, this.persistScaledTextbox = r, this.scalingState = /* @__PURE__ */ new WeakMap();
7053
+ }
7054
+ commitStandaloneTextScale({ target: e, shouldDisableAutoExpandOnHorizontalChange: t = !1 }) {
7055
+ if (!jr(e) || Mr(e)) return !1;
7056
+ let n = Math.abs(e.scaleX ?? 1) || 1, r = Math.abs(e.scaleY ?? 1) || 1;
7057
+ if (!(Math.abs(n - 1) > .01 || Math.abs(r - 1) > .01)) return !1;
7058
+ let i = wr({ textbox: e }), a = this.canvasManager.getObjectPlacement({ object: e });
7059
+ return Er({
7060
+ textbox: e,
7061
+ canvasManager: this.canvasManager,
7062
+ base: i,
7063
+ widthScale: n,
7064
+ heightScale: r,
7065
+ placement: a,
7066
+ shouldScaleFontSize: !0,
7067
+ shouldScalePadding: !0,
7068
+ shouldScaleRadii: !0,
7069
+ shouldDisableAutoExpandOnHorizontalChange: t
7070
+ }), !0;
7071
+ }
7072
+ _ensureScalingState({ textbox: e, transform: t }) {
7073
+ let n = this.scalingState.get(e);
7074
+ if (!n) {
7075
+ let r = wr({ textbox: e }), i = Tr({ base: r }), a = t.original?.originX ?? t.originX ?? e.originX ?? "center", o = t.original?.originY ?? t.originY ?? e.originY ?? "center";
7076
+ n = {
7077
+ startBase: r,
7078
+ startTransformCorner: typeof t.corner == "string" ? t.corner : null,
7079
+ startTransformOriginX: a,
7080
+ startTransformOriginY: o,
7081
+ lastAllowedScaleX: 1,
7082
+ lastAllowedScaleY: 1,
7083
+ lastAllowedPlacement: this.canvasManager.getObjectPlacement({
7084
+ object: e,
7085
+ originX: a,
7086
+ originY: o
7087
+ }),
7088
+ minimumWidthScale: i.widthScale,
7089
+ minimumFontScale: i.fontScale,
7090
+ minimumProportionalScale: i.proportionalScale,
7091
+ hasScalingChange: !1
7092
+ }, this.scalingState.set(e, n);
7093
+ }
7094
+ return n;
7095
+ }
7096
+ _updateScalingStateAfterLiveCommit({ textbox: e, state: t, appliedWidth: n, previousFontSize: r, previousPadding: i, previousRadii: a, previousWidth: o, dimensionsRounded: s, isCornerHandle: c, isHorizontalHandle: l, isVerticalHandle: u, originX: d, originY: f }) {
7097
+ let { width: p, fontSize: m } = t.startBase, h = e.fontSize ?? m, g = {
7098
+ top: e.paddingTop ?? 0,
7099
+ right: e.paddingRight ?? 0,
7100
+ bottom: e.paddingBottom ?? 0,
7101
+ left: e.paddingLeft ?? 0
7102
+ }, _ = {
7103
+ topLeft: e.radiusTopLeft ?? 0,
7104
+ topRight: e.radiusTopRight ?? 0,
7105
+ bottomRight: e.radiusBottomRight ?? 0,
7106
+ bottomLeft: e.radiusBottomLeft ?? 0
7107
+ }, v = Math.abs(n - o) > mr, y = Math.abs(h - r) > mr, b = Math.abs(g.top - i.top) > .01 || Math.abs(g.right - i.right) > .01 || Math.abs(g.bottom - i.bottom) > .01 || Math.abs(g.left - i.left) > .01, x = Math.abs(_.topLeft - a.topLeft) > .01 || Math.abs(_.topRight - a.topRight) > .01 || Math.abs(_.bottomRight - a.bottomRight) > .01 || Math.abs(_.bottomLeft - a.bottomLeft) > .01, S = t.lastAllowedScaleX, C = t.lastAllowedScaleY;
7108
+ if (c) {
7109
+ let e = h / Math.max(1, m);
7110
+ S = e, C = e;
7111
+ } else l ? S = n / Math.max(1, p) : u && (C = h / Math.max(1, m));
7112
+ this._storeLastAllowedScalingState({
7113
+ textbox: e,
7114
+ state: t,
7115
+ widthScale: S,
7116
+ heightScale: C,
7117
+ originX: d,
7118
+ originY: f
7119
+ }), t.hasScalingChange = t.hasScalingChange || v || y || b || x || s;
7120
+ }
7121
+ _storeLastAllowedScalingState({ textbox: e, state: t, widthScale: n, heightScale: r, originX: i, originY: a }) {
7122
+ t.lastAllowedScaleX = n, t.lastAllowedScaleY = r, t.lastAllowedPlacement = this.canvasManager.getObjectPlacement({
7123
+ object: e,
7124
+ originX: i,
7125
+ originY: a
7126
+ });
7127
+ }
7128
+ }, Pr = ({ textbox: e }) => {
6671
7129
  let t = e.text ?? "";
6672
7130
  if (!t.length) return [];
6673
7131
  let n = t.split("\n"), r = [], i = 0;
@@ -6679,7 +7137,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6679
7137
  });
6680
7138
  }
6681
7139
  return r;
6682
- }, br = ({ range: e, text: t }) => {
7140
+ }, Fr = ({ range: e, text: t }) => {
6683
7141
  if (!e) return null;
6684
7142
  let n = t.length;
6685
7143
  if (n <= 0) return null;
@@ -6688,8 +7146,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6688
7146
  start: l,
6689
7147
  end: u
6690
7148
  };
6691
- }, xr = ({ textbox: e, range: t }) => {
6692
- let n = yr({ textbox: e });
7149
+ }, Ir = ({ textbox: e, range: t }) => {
7150
+ let n = Pr({ textbox: e });
6693
7151
  if (!n.length) return t;
6694
7152
  let { start: r } = t, { end: i } = t;
6695
7153
  for (let e = 0; e < n.length; e += 1) {
@@ -6702,7 +7160,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6702
7160
  start: r,
6703
7161
  end: i
6704
7162
  };
6705
- }, Sr = ({ textbox: e, range: t }) => {
7163
+ }, Lr = ({ textbox: e, range: t }) => {
6706
7164
  let n = e.text ?? "";
6707
7165
  if (!n.length) return [];
6708
7166
  let { start: r, end: i } = t, a = n.split("\n"), o = [], s = 0;
@@ -6711,7 +7169,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6711
7169
  i > n && r < c && o.push(e), s = c + 1;
6712
7170
  }
6713
7171
  return o;
6714
- }, Cr = ({ textbox: e, range: t }) => {
7172
+ }, Rr = ({ textbox: e, range: t }) => {
6715
7173
  let n = e.text ?? "";
6716
7174
  if (!n.length) return [];
6717
7175
  let { start: r, end: i } = t, a = n.split("\n"), o = [], s = 0;
@@ -6720,63 +7178,31 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6720
7178
  r <= n && i >= c && o.push(e), s = c + 1;
6721
7179
  }
6722
7180
  return o;
6723
- }, wr = ({ previous: e, next: t }) => {
7181
+ }, zr = ({ previous: e, next: t }) => {
6724
7182
  let n = Math.min(e.length, t.length);
6725
7183
  for (let r = 0; r < n; r += 1) if (e[r] !== t[r]) return r;
6726
7184
  return n;
6727
- }, Tr = ({ text: e, charIndex: t }) => {
7185
+ }, Br = ({ text: e, charIndex: t }) => {
6728
7186
  let n = Math.max(0, Math.min(t, e.length)), r = 0;
6729
7187
  for (let t = 0; t < n; t += 1) e[t] === "\n" && (r += 1);
6730
7188
  return r;
6731
- }, Er = ({ text: e, lineIndex: t }) => {
7189
+ }, Vr = ({ text: e, lineIndex: t }) => {
6732
7190
  if (t <= 0) return 0;
6733
7191
  let n = 0;
6734
7192
  for (let r = 0; r < e.length; r += 1) if (e[r] === "\n" && (n += 1, n === t)) return r + 1;
6735
7193
  return e.length;
6736
- }, Dr = ({ textbox: e, text: t }) => {
6737
- let { textLines: n } = e, r = Array.isArray(n) && n.length > 0 ? n.length : Math.max(t.split("\n").length, 1), i = 0;
6738
- for (let t = 0; t < r; t += 1) {
6739
- let n = e.getLineWidth(t);
6740
- n > i && (i = n);
6741
- }
6742
- return i;
6743
- }, Or = ({ textbox: e, montageLeft: t, montageRight: n }) => {
6744
- e.setCoords();
6745
- let r = e.getBoundingRect(!1, !0), i = r.left ?? 0, a = i + (r.width ?? 0), o = n - t;
6746
- if (o > 0 && (r.width ?? 0) >= o - .01) return !1;
6747
- let s = 0;
6748
- return i < t ? s = t - i : a > n && (s = n - a), Math.abs(s) <= .01 ? !1 : (e.set({ left: (e.left ?? 0) + s }), !0);
6749
- }, kr = ({ rawValue: e, calculatedValue: t }) => typeof e == "number" ? e : typeof t == "number" ? t : 0, Ar = ({ stylesList: e }) => {
6750
- let t = e.length;
6751
- if (!t) return !1;
6752
- for (let n = 0; n < t; n += 1) {
6753
- let t = e[n];
6754
- if (!t) continue;
6755
- let { fontFamily: r, fontSize: i, fontWeight: a, fontStyle: o, lineHeight: s, charSpacing: c } = t;
6756
- if (r !== void 0 || i !== void 0 || a !== void 0 || o !== void 0 || s !== void 0 || c !== void 0) return !0;
6757
- }
6758
- return !1;
6759
- }, jr = ({ textbox: e }) => {
6760
- let { width: t, height: n, calcTextWidth: r, calcTextHeight: i } = e, a = typeof r == "function" ? r.call(e) : void 0, o = typeof i == "function" ? i.call(e) : void 0, s = kr({
6761
- rawValue: t,
6762
- calculatedValue: a
6763
- }), c = kr({
6764
- rawValue: n,
6765
- calculatedValue: o
6766
- }), l = Number.isFinite(s) ? Math.round(s) : null, u = Number.isFinite(c) ? Math.round(c) : null, d = {};
6767
- return l !== null && l !== s && (d.width = Math.max(0, l)), u !== null && u !== c && (d.height = Math.max(0, u)), Object.keys(d).length ? (e.set(d), !0) : !1;
6768
- }, Mr = class t {
6769
- constructor({ editor: n }) {
6770
- this._handleTextEditingEntered = (e) => {
7194
+ }, Hr = class e {
7195
+ constructor({ editor: t }) {
7196
+ this._handleTextEditingEntered = (t) => {
6771
7197
  this.isTextEditingActive = !0;
6772
- let { target: n } = e;
6773
- if (!t._isTextbox(n)) return;
7198
+ let { target: n } = t;
7199
+ if (!e._isTextbox(n)) return;
6774
7200
  let { canvasManager: r, historyManager: i } = this.editor;
6775
- i.beginAction({ reason: "text-edit" }), !t._isShapeOwnedTextbox(n) && this._ensureEditingPlacementState().set(n, r.getObjectPlacement({ object: n }));
6776
- }, this._handleTextChanged = (e) => {
6777
- let { target: n } = e;
6778
- if (!t._isTextbox(n) || this.lineDefaultsSyncing.has(n)) return;
6779
- let r = t._isShapeOwnedTextbox(n), { text: i = "", uppercase: a, autoExpand: o } = n, s = !!a, c = o !== !1, l = i.toLocaleLowerCase(), u = r ? null : this.editingPlacementState?.get(n) ?? this.editor.canvasManager.getObjectPlacement({ object: n });
7201
+ i.beginAction({ reason: "text-edit" }), !e._isShapeOwnedTextbox(n) && this._ensureEditingPlacementState().set(n, r.getObjectPlacement({ object: n }));
7202
+ }, this._handleTextChanged = (t) => {
7203
+ let { target: n } = t;
7204
+ if (!e._isTextbox(n) || this.lineDefaultsSyncing.has(n)) return;
7205
+ let r = e._isShapeOwnedTextbox(n), { text: i = "", uppercase: a, autoExpand: o } = n, s = !!a, c = o !== !1, l = i.toLocaleLowerCase(), u = r ? null : this.editingPlacementState?.get(n) ?? this.editor.canvasManager.getObjectPlacement({ object: n });
6780
7206
  if (s) {
6781
7207
  let e = ur({ value: l });
6782
7208
  e !== i && n.set({ text: e }), n.textCaseRaw = l;
@@ -6790,24 +7216,24 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6790
7216
  placement: u,
6791
7217
  shouldAutoExpand: c
6792
7218
  }), this._syncLineFontDefaultsOnTextChanged({ textbox: n });
6793
- }, this._handleTextEditingExited = (e) => {
6794
- let { target: n } = e;
6795
- if (!t._isTextbox(n)) return;
6796
- let r = t._isShapeOwnedTextbox(n);
7219
+ }, this._handleTextEditingExited = (t) => {
7220
+ let { target: n } = t;
7221
+ if (!e._isTextbox(n)) return;
7222
+ let r = e._isShapeOwnedTextbox(n);
6797
7223
  this.editingPlacementState?.delete(n);
6798
7224
  let i = n.text ?? "";
6799
- n.uppercase ? n.textCaseRaw = n.textCaseRaw ?? i.toLocaleLowerCase() : n.textCaseRaw = i, r || (jr({ textbox: n }) && (n.setCoords(), n.dirty = !0, this.canvas.requestRenderAll()), n.locked || n.set({
7225
+ n.uppercase ? n.textCaseRaw = n.textCaseRaw ?? i.toLocaleLowerCase() : n.textCaseRaw = i, r || (Cr({ textbox: n }) && (n.setCoords(), n.dirty = !0, this.canvas.requestRenderAll()), n.locked || n.set({
6800
7226
  lockMovementX: !1,
6801
7227
  lockMovementY: !1
6802
7228
  }));
6803
7229
  let { historyManager: a } = this.editor;
6804
- a.endAction({ reason: "text-edit" }), a.scheduleSaveState({
7230
+ a.endAction({ reason: "text-edit" }), a.stageCurrentStateForPendingSave({ reason: "text-edit" }), a.scheduleSaveState({
6805
7231
  delayMs: 50,
6806
7232
  reason: "text-edit"
6807
7233
  });
6808
- }, this._handleObjectResizing = (e) => {
6809
- let { target: n, transform: r, e: i } = e;
6810
- if (!t._isTextbox(n) || t._isShapeOwnedTextbox(n)) return;
7234
+ }, this._handleObjectResizing = (t) => {
7235
+ let { target: n, transform: r, e: i } = t;
7236
+ if (!e._isTextbox(n) || e._isShapeOwnedTextbox(n)) return;
6811
7237
  n.autoExpand = !1;
6812
7238
  let { paddingLeft: a = 0, paddingRight: o = 0 } = n, s = a + o;
6813
7239
  if (s !== 0) {
@@ -6823,109 +7249,25 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6823
7249
  transform: r,
6824
7250
  event: i ?? null
6825
7251
  });
6826
- }, this._handleObjectScaling = (n) => {
6827
- let { target: r, transform: i } = n;
6828
- if (r instanceof e || !t._isTextbox(r) || t._isShapeOwnedTextbox(r) || !i) return;
6829
- let { canvasManager: a } = this.editor;
6830
- r.isScaling = !0;
6831
- let o = this._ensureScalingState(r), { baseWidth: s, baseFontSize: c, basePadding: l, baseRadii: u, baseStyles: d, baseLineFontDefaults: f } = o, p = (typeof i.original?.width == "number" ? i.original.width : void 0) ?? s, m = i.corner ?? "", h = i.action ?? "", g = ["ml", "mr"].includes(m) || h === "scaleX", _ = ["mt", "mb"].includes(m) || h === "scaleY", v = [
6832
- "tl",
6833
- "tr",
6834
- "bl",
6835
- "br"
6836
- ].includes(m) || h === "scale", y = v || _;
6837
- if (!g && !_ && !v) return;
6838
- let b = Math.abs(r.scaleX ?? i.scaleX ?? 1) || 1, x = Math.abs(r.scaleY ?? i.scaleY ?? 1) || 1, S = Math.max(1, p * b), C = Math.max(1, Math.round(S)), w = Math.max(1, c * x), { paddingTop: T = 0, paddingRight: E = 0, paddingBottom: D = 0, paddingLeft: O = 0, radiusTopLeft: k = 0, radiusTopRight: A = 0, radiusBottomRight: j = 0, radiusBottomLeft: M = 0, fontSize: N, width: P } = r, F = v || _, ee = v || _, I = F ? {
6839
- top: Math.max(0, l.top * x),
6840
- right: Math.max(0, l.right * x),
6841
- bottom: Math.max(0, l.bottom * x),
6842
- left: Math.max(0, l.left * x)
6843
- } : l, L = ee ? {
6844
- topLeft: Math.max(0, u.topLeft * x),
6845
- topRight: Math.max(0, u.topRight * x),
6846
- bottomRight: Math.max(0, u.bottomRight * x),
6847
- bottomLeft: Math.max(0, u.bottomLeft * x)
6848
- } : u, te = a.getObjectPlacement({
6849
- object: r,
6850
- originX: i.originX ?? r.originX,
6851
- originY: i.originY ?? r.originY
6852
- }), ne = P ?? p, R = C !== ne, re = Math.abs(w - (N ?? c)) > mr, z = Math.abs(I.top - T) > .01 || Math.abs(I.right - E) > .01 || Math.abs(I.bottom - D) > .01 || Math.abs(I.left - O) > .01, ie = Math.abs(L.topLeft - k) > .01 || Math.abs(L.topRight - A) > .01 || Math.abs(L.bottomRight - j) > .01 || Math.abs(L.bottomLeft - M) > .01;
6853
- if (!R && !re && !z && !ie) {
6854
- r.set({
6855
- scaleX: 1,
6856
- scaleY: 1
6857
- }), i.scaleX = 1, i.scaleY = 1;
6858
- return;
6859
- }
6860
- let { appliedWidth: B, dimensionsRounded: ae } = this._commitStandaloneTextboxScale({
6861
- textbox: r,
6862
- base: {
6863
- baseWidth: p,
6864
- baseFontSize: c,
6865
- basePadding: l,
6866
- baseRadii: u,
6867
- baseStyles: d,
6868
- baseLineFontDefaults: f
6869
- },
6870
- widthScale: b,
6871
- heightScale: x,
6872
- placement: te,
6873
- shouldScaleFontSize: y,
6874
- shouldScalePadding: F,
6875
- shouldScaleRadii: ee,
6876
- shouldDisableAutoExpandOnHorizontalChange: g
6877
- }), V = B !== ne;
6878
- i.scaleX = 1, i.scaleY = 1;
6879
- let { original: H } = i;
6880
- H && (H.scaleX = 1, H.scaleY = 1, H.width = B, H.height = r.height, H.left = r.left, H.top = r.top), this.canvas.requestRenderAll();
6881
- let U = t._captureTextScaleBase({ textbox: r });
6882
- o.baseWidth = U.baseWidth, o.baseFontSize = U.baseFontSize, o.baseStyles = U.baseStyles, o.baseLineFontDefaults = U.baseLineFontDefaults, o.basePadding = U.basePadding, o.baseRadii = U.baseRadii, o.hasWidthChange = V || re || z || ie || ae;
6883
- }, this._handleObjectModified = (n) => {
6884
- let { target: r } = n;
6885
- if (r instanceof e) {
6886
- let n = r.getObjects();
6887
- if (!n.some((e) => t._isTextbox(e))) return;
6888
- let { scaleX: i = 1, scaleY: a = 1 } = r;
6889
- if (Math.abs(i - 1) < .01 && Math.abs(a - 1) < .01) return;
6890
- this.canvas.discardActiveObject(), n.forEach((e) => {
6891
- this.commitStandaloneTextScale({ target: e }), e.setCoords();
7252
+ }, this.editor = t, this.canvas = t.canvas, this.fonts = t.options.fonts ?? [], this.scalingController = new Nr({
7253
+ canvas: t.canvas,
7254
+ canvasManager: t.canvasManager,
7255
+ persistScaledTextbox: ({ target: e, style: t }) => {
7256
+ this.updateText({
7257
+ target: e,
7258
+ style: t
6892
7259
  });
6893
- let o = new e(n, { canvas: this.canvas });
6894
- this.canvas.setActiveObject(o), this.canvas.requestRenderAll();
6895
- return;
6896
7260
  }
6897
- if (!t._isTextbox(r) || t._isShapeOwnedTextbox(r)) return;
6898
- r.isScaling = !1;
6899
- let i = this.scalingState.get(r);
6900
- if (this.scalingState.delete(r), !i?.hasWidthChange) return;
6901
- let a = r.width ?? r.calcTextWidth(), o = r.fontSize ?? i?.baseFontSize ?? 16, s = !!(i.baseStyles && Object.keys(i.baseStyles).length), { paddingTop: c = 0, paddingRight: l = 0, paddingBottom: u = 0, paddingLeft: d = 0, radiusTopLeft: f = 0, radiusTopRight: p = 0, radiusBottomRight: m = 0, radiusBottomLeft: h = 0 } = r, g = {
6902
- width: a,
6903
- paddingTop: c,
6904
- paddingRight: l,
6905
- paddingBottom: u,
6906
- paddingLeft: d,
6907
- radiusTopLeft: f,
6908
- radiusTopRight: p,
6909
- radiusBottomRight: m,
6910
- radiusBottomLeft: h
6911
- };
6912
- s || (g.fontSize = o), this.updateText({
6913
- target: r,
6914
- style: g
6915
- }), r.set({
6916
- scaleX: 1,
6917
- scaleY: 1
6918
- }), r.setCoords();
6919
- }, this.editor = n, this.canvas = n.canvas, this.fonts = n.options.fonts ?? [], this.scalingState = /* @__PURE__ */ new WeakMap(), this.editingPlacementState = /* @__PURE__ */ new WeakMap(), this.lineDefaultsSyncing = /* @__PURE__ */ new WeakSet(), this.isTextEditingActive = !1, this._bindEvents(), pr();
7261
+ }), this.editingPlacementState = /* @__PURE__ */ new WeakMap(), this.lineDefaultsSyncing = /* @__PURE__ */ new WeakSet(), this.isTextEditingActive = !1, this._bindEvents(), pr();
6920
7262
  }
6921
- addText({ id: e = `text-${D()}`, text: n = "Новый текст", autoExpand: r = !0, fontFamily: i, fontSize: a = 48, bold: o = !1, italic: s = !1, underline: c = !1, uppercase: l = !1, strikethrough: u = !1, align: d = "left", color: f = "#000000", strokeColor: p, strokeWidth: m = 0, opacity: h = 1, backgroundColor: g, backgroundOpacity: _ = 1, paddingTop: v = 0, paddingRight: y = 0, paddingBottom: b = 0, paddingLeft: x = 0, radiusTopLeft: S = 0, radiusTopRight: C = 0, radiusBottomRight: w = 0, radiusBottomLeft: T = 0, ...E } = {}, { withoutSelection: O = !1, withoutSave: k = !1, withoutAdding: A = !1 } = {}) {
7263
+ addText({ id: t = `text-${D()}`, text: n = "Новый текст", autoExpand: r = !0, fontFamily: i, fontSize: a = 48, bold: o = !1, italic: s = !1, underline: c = !1, uppercase: l = !1, strikethrough: u = !1, align: d = "left", color: f = "#000000", strokeColor: p, strokeWidth: m = 0, opacity: h = 1, backgroundColor: g, backgroundOpacity: _ = 1, paddingTop: v = 0, paddingRight: y = 0, paddingBottom: b = 0, paddingLeft: x = 0, radiusTopLeft: S = 0, radiusTopRight: C = 0, radiusBottomRight: w = 0, radiusBottomLeft: T = 0, ...E } = {}, { withoutSelection: O = !1, withoutSave: k = !1, withoutAdding: A = !1 } = {}) {
6922
7264
  let { canvasManager: j, historyManager: M } = this.editor, { canvas: N } = this;
6923
7265
  M.suspendHistory();
6924
- let P = i ?? this._getDefaultFontFamily(), F = lr({ width: m }), ee = cr({
7266
+ let P = i ?? this._getDefaultFontFamily(), F = lr({ width: m }), I = cr({
6925
7267
  strokeColor: p,
6926
7268
  width: F
6927
- }), I = {
6928
- id: e,
7269
+ }), ee = {
7270
+ id: t,
6929
7271
  fontFamily: P,
6930
7272
  fontSize: a,
6931
7273
  fontWeight: o ? "bold" : "normal",
@@ -6935,7 +7277,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6935
7277
  linethrough: u,
6936
7278
  textAlign: d,
6937
7279
  fill: f,
6938
- stroke: ee,
7280
+ stroke: I,
6939
7281
  strokeWidth: F,
6940
7282
  strokeUniform: !0,
6941
7283
  opacity: h,
@@ -6950,14 +7292,14 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6950
7292
  radiusBottomRight: w,
6951
7293
  radiusBottomLeft: T,
6952
7294
  ...E
6953
- }, L = new fr(n, I), te = r !== !1;
7295
+ }, L = new fr(n, ee), te = r !== !1;
6954
7296
  L.autoExpand = te;
6955
7297
  let ne = E.left !== void 0 || E.top !== void 0;
6956
7298
  if (L.textCaseRaw = L.text ?? "", l) {
6957
7299
  let e = ur({ value: L.textCaseRaw });
6958
7300
  e !== L.text && L.set({ text: e });
6959
7301
  }
6960
- jr({ textbox: L }) && (L.dirty = !0);
7302
+ Cr({ textbox: L }) && (L.dirty = !0);
6961
7303
  let R;
6962
7304
  ne && (R = j.resolveObjectPlacement({
6963
7305
  object: L,
@@ -6967,7 +7309,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6967
7309
  originY: E.originY,
6968
7310
  fallbackPoint: j.getMontageAreaSceneCenter()
6969
7311
  }));
6970
- let re = te && t._hasWrappedLinesBeyondExplicitBreaks(L);
7312
+ let re = te && e._hasWrappedLinesBeyondExplicitBreaks(L);
6971
7313
  return (ne || re) && this._normalizeTextboxAfterContentChange({
6972
7314
  textbox: L,
6973
7315
  placement: R,
@@ -6976,14 +7318,14 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6976
7318
  }), R || j.centerObjectToMontageArea({ object: L }), A || N.add(L), O || N.setActiveObject(L), N.requestRenderAll(), M.resumeHistory(), k || M.saveState(), N.fire("editor:text-added", {
6977
7319
  textbox: L,
6978
7320
  options: {
6979
- ...I,
7321
+ ...ee,
6980
7322
  text: n,
6981
7323
  bold: o,
6982
7324
  italic: s,
6983
7325
  strikethrough: u,
6984
7326
  align: d,
6985
7327
  color: f,
6986
- strokeColor: ee,
7328
+ strokeColor: I,
6987
7329
  strokeWidth: F
6988
7330
  },
6989
7331
  flags: {
@@ -6993,36 +7335,36 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6993
7335
  }
6994
7336
  }), L;
6995
7337
  }
6996
- updateText({ target: e, style: n = {}, withoutSave: r, skipRender: i, selectionRange: a } = {}) {
6997
- let o = this._resolveTextObject(e);
7338
+ updateText({ target: t, style: n = {}, withoutSave: r, skipRender: i, selectionRange: a } = {}) {
7339
+ let o = this._resolveTextObject(t);
6998
7340
  if (!o) return null;
6999
7341
  let { text: s = "" } = o, { historyManager: c } = this.editor, { canvasManager: l } = this.editor, { canvas: u } = this;
7000
7342
  c.suspendHistory();
7001
- let d = t._getSnapshot(o), { text: f, autoExpand: p, fontFamily: m, fontSize: h, bold: g, italic: _, underline: v, uppercase: y, strikethrough: b, align: x, color: S, strokeColor: C, strokeWidth: w, opacity: T, backgroundColor: E, backgroundOpacity: D, paddingTop: O, paddingRight: k, paddingBottom: A, paddingLeft: j, radiusTopLeft: M, radiusTopRight: N, radiusBottomRight: P, radiusBottomLeft: F, left: ee, top: I, originX: L, originY: te, ...ne } = n, R = { ...ne }, re = l.resolveObjectPlacement({
7343
+ let d = e._getSnapshot(o), { text: f, autoExpand: p, fontFamily: m, fontSize: h, bold: g, italic: _, underline: v, uppercase: y, strikethrough: b, align: x, color: S, strokeColor: C, strokeWidth: w, opacity: T, backgroundColor: E, backgroundOpacity: D, paddingTop: O, paddingRight: k, paddingBottom: A, paddingLeft: j, radiusTopLeft: M, radiusTopRight: N, radiusBottomRight: P, radiusBottomLeft: F, left: I, top: ee, originX: L, originY: te, ...ne } = n, R = { ...ne }, re = l.resolveObjectPlacement({
7002
7344
  object: o,
7003
- left: ee,
7004
- top: I,
7345
+ left: I,
7346
+ top: ee,
7005
7347
  originX: L,
7006
7348
  originY: te
7007
- }), z = a === void 0 ? rr({ textbox: o }) : br({
7349
+ }), z = a === void 0 ? rr({ textbox: o }) : Fr({
7008
7350
  text: s,
7009
7351
  range: a
7010
- }), ie = z ? xr({
7352
+ }), ie = z ? Ir({
7011
7353
  textbox: o,
7012
7354
  range: z
7013
- }) : null, B = {}, ae = {}, V = {}, H, U, oe = ar({
7355
+ }) : null, B = {}, ae = {}, V = {}, oe, se, ce = ar({
7014
7356
  textbox: o,
7015
7357
  range: z
7016
- }), se = !z || oe, ce = !z;
7017
- if (m !== void 0 && (ie && (ae.fontFamily = m), se && (R.fontFamily = m, ce && (V.fontFamily = m))), h !== void 0 && (ie && (ae.fontSize = h), se && (R.fontSize = h, ce && (V.fontSize = h))), g !== void 0) {
7358
+ }), le = !z || ce, H = !z;
7359
+ if (m !== void 0 && (ie && (ae.fontFamily = m), le && (R.fontFamily = m, H && (V.fontFamily = m))), h !== void 0 && (ie && (ae.fontSize = h), le && (R.fontSize = h, H && (V.fontSize = h))), g !== void 0) {
7018
7360
  let e = g ? "bold" : "normal";
7019
- z && (B.fontWeight = e), se && (R.fontWeight = e, ce && (V.fontWeight = e));
7361
+ z && (B.fontWeight = e), le && (R.fontWeight = e, H && (V.fontWeight = e));
7020
7362
  }
7021
7363
  if (_ !== void 0) {
7022
7364
  let e = _ ? "italic" : "normal";
7023
- z && (B.fontStyle = e), se && (R.fontStyle = e, ce && (V.fontStyle = e));
7365
+ z && (B.fontStyle = e), le && (R.fontStyle = e, H && (V.fontStyle = e));
7024
7366
  }
7025
- if (v !== void 0 && (z && (B.underline = v), se && (R.underline = v, ce && (V.underline = v))), b !== void 0 && (z && (B.linethrough = b), se && (R.linethrough = b, ce && (V.linethrough = b))), x !== void 0 && (R.textAlign = x), S !== void 0 && (z && (B.fill = S), se && (R.fill = S, ce && (V.fill = S))), C !== void 0 || w !== void 0) {
7367
+ if (v !== void 0 && (z && (B.underline = v), le && (R.underline = v, H && (V.underline = v))), b !== void 0 && (z && (B.linethrough = b), le && (R.linethrough = b, H && (V.linethrough = b))), x !== void 0 && (R.textAlign = x), S !== void 0 && (z && (B.fill = S), le && (R.fill = S, H && (V.fill = S))), C !== void 0 || w !== void 0) {
7026
7368
  let e = z ? sr({
7027
7369
  textbox: o,
7028
7370
  range: z,
@@ -7032,15 +7374,15 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7032
7374
  range: z,
7033
7375
  property: "stroke"
7034
7376
  }) : void 0;
7035
- U = lr({ width: w ?? e ?? o.strokeWidth ?? 0 }), H = cr({
7377
+ se = lr({ width: w ?? e ?? o.strokeWidth ?? 0 }), oe = cr({
7036
7378
  strokeColor: C ?? t ?? o.stroke ?? void 0,
7037
- width: U
7038
- }), z && (B.stroke = H, B.strokeWidth = U), se && (R.stroke = H, R.strokeWidth = U, ce && (V.stroke = H, V.strokeWidth = U));
7379
+ width: se
7380
+ }), z && (B.stroke = oe, B.strokeWidth = se), le && (R.stroke = oe, R.strokeWidth = se, H && (V.stroke = oe, V.strokeWidth = se));
7039
7381
  }
7040
7382
  T !== void 0 && (R.opacity = T), E !== void 0 && (R.backgroundColor = E), D !== void 0 && (R.backgroundOpacity = D), O !== void 0 && (R.paddingTop = O), k !== void 0 && (R.paddingRight = k), A !== void 0 && (R.paddingBottom = A), j !== void 0 && (R.paddingLeft = j), M !== void 0 && (R.radiusTopLeft = M), N !== void 0 && (R.radiusTopRight = N), P !== void 0 && (R.radiusBottomRight = P), F !== void 0 && (R.radiusBottomLeft = F);
7041
- let le = o.textCaseRaw ?? s, ue = !!o.uppercase, de = f !== void 0, fe = de ? f ?? "" : le, pe = y ?? ue, me = pe !== ue;
7042
- de || me ? (R.text = pe ? ur({ value: fe }) : fe, o.textCaseRaw = fe) : o.textCaseRaw === void 0 && (o.textCaseRaw = le), o.uppercase = pe, o.set(R);
7043
- let he = !1;
7383
+ let ue = o.textCaseRaw ?? s, de = !!o.uppercase, fe = f !== void 0, pe = fe ? f ?? "" : ue, me = y ?? de, he = me !== de;
7384
+ fe || he ? (R.text = me ? ur({ value: pe }) : pe, o.textCaseRaw = pe) : o.textCaseRaw === void 0 && (o.textCaseRaw = ue), o.uppercase = me, o.set(R);
7385
+ let ge = !1;
7044
7386
  if (z) {
7045
7387
  let e = or({
7046
7388
  textbox: o,
@@ -7051,22 +7393,22 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7051
7393
  styles: ae,
7052
7394
  range: ie
7053
7395
  }) : !1;
7054
- he = e || t;
7396
+ ge = e || t;
7055
7397
  } else if (Object.keys(V).length) {
7056
7398
  let e = ir({ textbox: o });
7057
- e && (he = or({
7399
+ e && (ge = or({
7058
7400
  textbox: o,
7059
7401
  styles: V,
7060
7402
  range: e
7061
7403
  }));
7062
7404
  }
7063
- let ge = he && Ar({ stylesList: [
7405
+ let _e = ge && Sr({ stylesList: [
7064
7406
  B,
7065
7407
  ae,
7066
7408
  V
7067
7409
  ] });
7068
- if (he && (o.dirty = !0), ie && (m !== void 0 || h !== void 0)) {
7069
- let e = Sr({
7410
+ if (ge && (o.dirty = !0), ie && (m !== void 0 || h !== void 0)) {
7411
+ let e = Lr({
7070
7412
  textbox: o,
7071
7413
  range: ie
7072
7414
  }), t = {};
@@ -7077,92 +7419,85 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7077
7419
  });
7078
7420
  }
7079
7421
  if (z && (S !== void 0 || C !== void 0 || w !== void 0)) {
7080
- let e = Cr({
7422
+ let e = Rr({
7081
7423
  textbox: o,
7082
7424
  range: z
7083
7425
  }), t = {};
7084
- S !== void 0 && (t.fill = S), (C !== void 0 || w !== void 0) && (H === null && (t.stroke = null), H != null && (t.stroke = H)), hr({
7426
+ S !== void 0 && (t.fill = S), (C !== void 0 || w !== void 0) && (oe === null && (t.stroke = null), oe != null && (t.stroke = oe)), hr({
7085
7427
  textbox: o,
7086
7428
  lineIndices: e,
7087
7429
  updates: t
7088
7430
  });
7089
7431
  }
7090
- ge && (o.initDimensions(), o.dirty = !0), (E !== void 0 || D !== void 0 || O !== void 0 || k !== void 0 || A !== void 0 || j !== void 0 || M !== void 0 || N !== void 0 || P !== void 0 || F !== void 0) && (o.dirty = !0);
7091
- let _e = Ar({ stylesList: [
7432
+ _e && (o.initDimensions(), o.dirty = !0), (E !== void 0 || D !== void 0 || O !== void 0 || k !== void 0 || A !== void 0 || j !== void 0 || M !== void 0 || N !== void 0 || P !== void 0 || F !== void 0) && (o.dirty = !0);
7433
+ let ve = Sr({ stylesList: [
7092
7434
  R,
7093
7435
  B,
7094
7436
  ae,
7095
7437
  V
7096
- ] }), { autoExpand: ve } = o, ye = p !== void 0, be = Object.prototype.hasOwnProperty.call(R, "width"), xe = (p ?? ve) !== !1;
7097
- ye ? o.autoExpand = p !== !1 : ve === void 0 && (o.autoExpand = !0);
7098
- let Se = xe && !be && (de || me || _e);
7438
+ ] }), { autoExpand: ye } = o, be = p !== void 0, xe = Object.prototype.hasOwnProperty.call(R, "width"), Se = (p ?? ye) !== !1;
7439
+ be ? o.autoExpand = p !== !1 : ye === void 0 && (o.autoExpand = !0);
7440
+ let Ce = Se && !xe && (fe || he || ve);
7099
7441
  this._normalizeTextboxAfterContentChange({
7100
7442
  textbox: o,
7101
7443
  placement: re,
7102
- shouldAutoExpand: Se
7444
+ shouldAutoExpand: Ce
7103
7445
  }), o.setCoords();
7104
- let Ce = {
7446
+ let we = {
7105
7447
  withoutSave: !!r,
7106
7448
  skipRender: !!i
7107
- }, we = !!z && Object.keys(B).length > 0, Te = {
7449
+ }, Te = !!z && Object.keys(B).length > 0, Ee = {
7108
7450
  textbox: o,
7109
- target: e,
7451
+ target: t,
7110
7452
  style: n,
7111
- options: Ce,
7453
+ options: we,
7112
7454
  updates: R,
7113
7455
  selectionRange: z ?? void 0,
7114
- selectionStyles: we ? B : void 0
7456
+ selectionStyles: Te ? B : void 0
7115
7457
  };
7116
- u.fire("editor:before:text-updated", Te), i || u.requestRenderAll();
7117
- let Ee = t._getSnapshot(o);
7458
+ u.fire("editor:before:text-updated", Ee), i || u.requestRenderAll();
7459
+ let De = e._getSnapshot(o);
7118
7460
  c.resumeHistory(), r || c.saveState();
7119
- let De = {
7120
- ...Te,
7461
+ let Oe = {
7462
+ ...Ee,
7121
7463
  before: d,
7122
- after: Ee
7464
+ after: De
7123
7465
  };
7124
- return u.fire("editor:text-updated", De), o;
7466
+ return u.fire("editor:text-updated", Oe), o;
7125
7467
  }
7126
7468
  stylesFromArray(e, t) {
7127
7469
  return C.stylesFromArray(e, t);
7128
7470
  }
7471
+ exitActiveTextEditing() {
7472
+ let t = this.canvas.getActiveObject();
7473
+ return !e._isTextbox(t) || !t.isEditing ? !1 : (t.exitEditing(), this.canvas.requestRenderAll(), !0);
7474
+ }
7129
7475
  destroy() {
7130
7476
  let { canvas: e } = this;
7131
- e.off("object:scaling", this._handleObjectScaling), e.off("object:resizing", this._handleObjectResizing), e.off("object:modified", this._handleObjectModified), e.off("text:editing:exited", this._handleTextEditingExited), e.off("text:editing:entered", this._handleTextEditingEntered), e.off("text:changed", this._handleTextChanged);
7132
- }
7133
- commitStandaloneTextScale({ target: e, shouldDisableAutoExpandOnHorizontalChange: n = !1 }) {
7134
- if (!t._isTextbox(e) || t._isShapeOwnedTextbox(e)) return !1;
7135
- let r = Math.abs(e.scaleX ?? 1) || 1, i = Math.abs(e.scaleY ?? 1) || 1;
7136
- if (!(Math.abs(r - 1) > .01 || Math.abs(i - 1) > .01)) return !1;
7137
- let a = t._captureTextScaleBase({ textbox: e }), o = this.editor.canvasManager.getObjectPlacement({ object: e });
7138
- return this._commitStandaloneTextboxScale({
7139
- textbox: e,
7140
- base: a,
7141
- widthScale: r,
7142
- heightScale: i,
7143
- placement: o,
7144
- shouldScaleFontSize: !0,
7145
- shouldScalePadding: !0,
7146
- shouldScaleRadii: !0,
7147
- shouldDisableAutoExpandOnHorizontalChange: n
7148
- }), !0;
7477
+ e.off("object:scaling", this.scalingController.handleObjectScaling), e.off("object:resizing", this._handleObjectResizing), e.off("object:modified", this.scalingController.handleObjectModified), e.off("mouse:move", this.scalingController.handleMouseMove), e.off("text:editing:exited", this._handleTextEditingExited), e.off("text:editing:entered", this._handleTextEditingEntered), e.off("text:changed", this._handleTextChanged);
7149
7478
  }
7150
- _resolveTextObject(e) {
7151
- if (e instanceof _) return e;
7479
+ commitStandaloneTextScale({ target: e, shouldDisableAutoExpandOnHorizontalChange: t = !1 }) {
7480
+ return this.scalingController.commitStandaloneTextScale({
7481
+ target: e,
7482
+ shouldDisableAutoExpandOnHorizontalChange: t
7483
+ });
7484
+ }
7485
+ _resolveTextObject(t) {
7486
+ if (t instanceof _) return t;
7152
7487
  let { canvas: n } = this;
7153
- if (!e) {
7154
- let e = n.getActiveObject();
7155
- return t._isTextbox(e) ? e : null;
7488
+ if (!t) {
7489
+ let t = n.getActiveObject();
7490
+ return e._isTextbox(t) ? t : null;
7156
7491
  }
7157
- return typeof e == "string" ? n.getObjects().find((n) => t._isTextbox(n) && n.id === e) ?? null : null;
7492
+ return typeof t == "string" ? n.getObjects().find((n) => e._isTextbox(n) && n.id === t) ?? null : null;
7158
7493
  }
7159
7494
  static _isTextbox(e) {
7160
7495
  return !!e && e instanceof _;
7161
7496
  }
7162
- static _isShapeOwnedTextbox(e) {
7163
- if (!t._isTextbox(e)) return !1;
7164
- let n = e.group;
7165
- return e.shapeNodeType === "text" && n?.shapeComposite === !0;
7497
+ static _isShapeOwnedTextbox(t) {
7498
+ if (!e._isTextbox(t)) return !1;
7499
+ let n = t.group;
7500
+ return t.shapeNodeType === "text" && n?.shapeComposite === !0;
7166
7501
  }
7167
7502
  static _hasWrappedLinesBeyondExplicitBreaks(e) {
7168
7503
  let t = typeof e.text == "string" ? e.text : "";
@@ -7170,80 +7505,6 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7170
7505
  let n = t.split("\n").length, { textLines: r } = e;
7171
7506
  return Array.isArray(r) && r.length > n;
7172
7507
  }
7173
- static _captureTextScaleBase({ textbox: e }) {
7174
- let t = e.width ?? e.calcTextWidth(), n = e.fontSize ?? 16, { styles: r = {} } = e, { lineFontDefaults: i } = e, { paddingTop: a = 0, paddingRight: o = 0, paddingBottom: s = 0, paddingLeft: c = 0 } = e, { radiusTopLeft: l = 0, radiusTopRight: u = 0, radiusBottomRight: d = 0, radiusBottomLeft: f = 0 } = e;
7175
- return {
7176
- baseWidth: t,
7177
- baseFontSize: n,
7178
- basePadding: {
7179
- top: a,
7180
- right: o,
7181
- bottom: s,
7182
- left: c
7183
- },
7184
- baseRadii: {
7185
- topLeft: l,
7186
- topRight: u,
7187
- bottomRight: d,
7188
- bottomLeft: f
7189
- },
7190
- baseStyles: JSON.parse(JSON.stringify(r)),
7191
- baseLineFontDefaults: _r({ lineFontDefaults: i })
7192
- };
7193
- }
7194
- _commitStandaloneTextboxScale({ textbox: e, base: t, widthScale: n, heightScale: r, placement: i, shouldScaleFontSize: a, shouldScalePadding: o, shouldScaleRadii: s, shouldDisableAutoExpandOnHorizontalChange: c = !1 }) {
7195
- let { baseWidth: l, baseFontSize: u, basePadding: d, baseRadii: f, baseStyles: p, baseLineFontDefaults: m } = t, h = Math.max(1, l * n), g = Math.max(1, Math.round(h)), _ = Math.max(1, u * r), v = Object.keys(p).length > 0, y;
7196
- if (a && v) {
7197
- let e = {};
7198
- Object.entries(p).forEach(([t, n]) => {
7199
- if (!n) return;
7200
- let i = {};
7201
- Object.entries(n).forEach(([e, t]) => {
7202
- if (!t) return;
7203
- let n = { ...t };
7204
- typeof t.fontSize == "number" && (n.fontSize = Math.max(1, t.fontSize * r)), i[e] = n;
7205
- }), Object.keys(i).length && (e[t] = i);
7206
- }), Object.keys(e).length && (y = e);
7207
- }
7208
- let b;
7209
- a && (b = vr({
7210
- lineFontDefaults: m,
7211
- scale: r
7212
- }));
7213
- let x = o ? {
7214
- top: Math.max(0, d.top * r),
7215
- right: Math.max(0, d.right * r),
7216
- bottom: Math.max(0, d.bottom * r),
7217
- left: Math.max(0, d.left * r)
7218
- } : d, S = s ? {
7219
- topLeft: Math.max(0, f.topLeft * r),
7220
- topRight: Math.max(0, f.topRight * r),
7221
- bottomRight: Math.max(0, f.bottomRight * r),
7222
- bottomLeft: Math.max(0, f.bottomLeft * r)
7223
- } : f, C = g !== (e.width ?? l);
7224
- c && C && (e.autoExpand = !1), y && (e.styles = y), b && (e.lineFontDefaults = b), e.set({
7225
- width: g,
7226
- fontSize: a ? _ : u,
7227
- paddingTop: x.top,
7228
- paddingRight: x.right,
7229
- paddingBottom: x.bottom,
7230
- paddingLeft: x.left,
7231
- radiusTopLeft: S.topLeft,
7232
- radiusTopRight: S.topRight,
7233
- radiusBottomRight: S.bottomRight,
7234
- radiusBottomLeft: S.bottomLeft,
7235
- scaleX: 1,
7236
- scaleY: 1
7237
- }), e.initDimensions();
7238
- let w = jr({ textbox: e });
7239
- return w && (e.dirty = !0), this.editor.canvasManager.applyObjectPlacement({
7240
- object: e,
7241
- placement: i
7242
- }), e.setCoords(), {
7243
- appliedWidth: e.width ?? g,
7244
- dimensionsRounded: w
7245
- };
7246
- }
7247
7508
  _normalizeTextboxAfterContentChange({ textbox: e, placement: t, shouldAutoExpand: n, clampToMontage: r = !0 }) {
7248
7509
  let i = !1;
7249
7510
  n && (i = this._autoExpandTextboxWidth(e, {
@@ -7251,7 +7512,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7251
7512
  clampToMontage: r
7252
7513
  }));
7253
7514
  let a = !1;
7254
- i || (a = jr({ textbox: e }));
7515
+ i || (a = Cr({ textbox: e }));
7255
7516
  let o = !1;
7256
7517
  return !i && t && (this.editor.canvasManager.applyObjectPlacement({
7257
7518
  object: e,
@@ -7260,20 +7521,20 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7260
7521
  }
7261
7522
  _bindEvents() {
7262
7523
  let { canvas: e } = this;
7263
- e.on("object:scaling", this._handleObjectScaling), e.on("object:resizing", this._handleObjectResizing), e.on("object:modified", this._handleObjectModified), e.on("text:editing:entered", this._handleTextEditingEntered), e.on("text:editing:exited", this._handleTextEditingExited), e.on("text:changed", this._handleTextChanged);
7524
+ e.on("object:scaling", this.scalingController.handleObjectScaling), e.on("object:resizing", this._handleObjectResizing), e.on("object:modified", this.scalingController.handleObjectModified), e.on("mouse:move", this.scalingController.handleMouseMove), e.on("text:editing:entered", this._handleTextEditingEntered), e.on("text:editing:exited", this._handleTextEditingExited), e.on("text:changed", this._handleTextChanged);
7264
7525
  }
7265
7526
  _syncLineFontDefaultsOnTextChanged({ textbox: e }) {
7266
7527
  let { text: t = "", lineFontDefaults: n, styles: r, fontFamily: i, fontSize: a, fill: o, stroke: s, selectionStart: c, isEditing: l } = e, u = t, d = e.__lineDefaultsPrevText ?? u, f = d.split("\n"), p = u.split("\n"), m = f.length, h = p.length - m, g = n, _ = !1, v = !1, y = typeof o == "string" ? o : void 0, b = typeof s == "string" ? s : void 0;
7267
7528
  if (h !== 0 && n && Object.keys(n).length) {
7268
- let e = wr({
7529
+ let e = zr({
7269
7530
  previous: d,
7270
7531
  next: u
7271
- }), t = Tr({
7532
+ }), t = Br({
7272
7533
  text: d,
7273
7534
  charIndex: e
7274
7535
  });
7275
7536
  if (h > 0) {
7276
- let r = Er({
7537
+ let r = Vr({
7277
7538
  text: d,
7278
7539
  lineIndex: t
7279
7540
  }), i = t + 1;
@@ -7354,16 +7615,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7354
7615
  if (!Number.isFinite(f) || f <= 0) return !1;
7355
7616
  let p = a.split("\n").length, m = !1;
7356
7617
  Math.abs((e.width ?? 0) - f) > .01 && (e.set({ width: f }), m = !0), e.initDimensions();
7357
- let { textLines: h } = e, g = Array.isArray(h) && h.length > p, _ = Math.ceil(Dr({
7618
+ let { textLines: h } = e, g = Array.isArray(h) && h.length > p, _ = Math.ceil(yr({
7358
7619
  textbox: e,
7359
7620
  text: a
7360
7621
  })), v = Math.min(e.minWidth ?? 1, f), y = Math.min(f, Math.max(_, v));
7361
- g && (y = f), Math.abs((e.width ?? 0) - y) > .01 && (e.set({ width: y }), e.initDimensions(), m = !0), jr({ textbox: e }) && (m = !0), t && r.applyObjectPlacement({
7622
+ g && (y = f), Math.abs((e.width ?? 0) - y) > .01 && (e.set({ width: y }), e.initDimensions(), m = !0), Cr({ textbox: e }) && (m = !0), t && r.applyObjectPlacement({
7362
7623
  object: e,
7363
7624
  placement: t
7364
7625
  });
7365
7626
  let b = !1;
7366
- return n && (b = Or({
7627
+ return n && (b = br({
7367
7628
  textbox: e,
7368
7629
  montageLeft: o,
7369
7630
  montageRight: o + s
@@ -7372,13 +7633,6 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7372
7633
  _ensureEditingPlacementState() {
7373
7634
  return this.editingPlacementState ||= /* @__PURE__ */ new WeakMap(), this.editingPlacementState;
7374
7635
  }
7375
- _ensureScalingState(e) {
7376
- let n = this.scalingState.get(e);
7377
- return n || (n = {
7378
- ...t._captureTextScaleBase({ textbox: e }),
7379
- hasWidthChange: !1
7380
- }, this.scalingState.set(e, n)), n;
7381
- }
7382
7636
  static _getSnapshot(e) {
7383
7637
  let t = ({ snapshot: e, entries: t }) => {
7384
7638
  Object.entries(t).forEach(([t, n]) => {
@@ -7428,7 +7682,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7428
7682
  _getDefaultFontFamily() {
7429
7683
  return this.fonts[0]?.family ?? "Arial";
7430
7684
  }
7431
- }, Nr = ({ x1: e, y1: t, x2: n, y2: r }) => (Math.atan2(r - t, n - e) * 180 / Math.PI + 360) % 360, Pr = (e) => {
7685
+ }, Ur = ({ x1: e, y1: t, x2: n, y2: r }) => (Math.atan2(r - t, n - e) * 180 / Math.PI + 360) % 360, Wr = (e) => {
7432
7686
  if (!e || typeof e != "object") return null;
7433
7687
  let { type: t, coords: n, colorStops: r } = e, i = Array.isArray(r) ? r : [], a = i[0], o = i[i.length - 1], s = typeof a?.color == "string" ? a.color : void 0, c = typeof o?.color == "string" ? o.color : s, l = typeof a?.offset == "number" ? a.offset * 100 : void 0, u = typeof o?.offset == "number" ? o.offset * 100 : void 0, d = i.map((e) => ({
7434
7688
  color: typeof e.color == "string" ? e.color : "#000000",
@@ -7439,7 +7693,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7439
7693
  let { x1: e, y1: t, x2: r, y2: i } = n;
7440
7694
  if (typeof e == "number" && typeof t == "number" && typeof r == "number" && typeof i == "number") return {
7441
7695
  type: "linear",
7442
- angle: Nr({
7696
+ angle: Ur({
7443
7697
  x1: e,
7444
7698
  y1: t,
7445
7699
  x2: r,
@@ -7467,7 +7721,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7467
7721
  };
7468
7722
  }
7469
7723
  return null;
7470
- }, Fr = "_templateAnchorX", Ir = "_templateAnchorY", Lr = class t {
7724
+ }, Gr = "_templateAnchorX", Kr = "_templateAnchorY", qr = class t {
7471
7725
  constructor({ editor: e }) {
7472
7726
  this.editor = e;
7473
7727
  }
@@ -7550,7 +7804,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7550
7804
  baseWidth: f.baseWidth,
7551
7805
  baseHeight: f.baseHeight,
7552
7806
  useRelativePositions: m
7553
- }), this.editor.textManager?.commitStandaloneTextScale({ target: e }), qe({ object: e }), e.set({
7807
+ }), this.editor.textManager?.commitStandaloneTextScale({ target: e }), Je({ object: e }), e.set({
7554
7808
  id: `${e.type}-${D()}`,
7555
7809
  evented: !0
7556
7810
  }), n.add(e), e));
@@ -7618,22 +7872,22 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7618
7872
  naturalHeight: 0,
7619
7873
  width: 0,
7620
7874
  height: 0
7621
- }, m = W({
7875
+ }, m = U({
7622
7876
  value: u || f || c.width,
7623
7877
  fallback: 0
7624
- }), h = W({
7878
+ }), h = U({
7625
7879
  value: d || p || c.height,
7626
7880
  fallback: 0
7627
- }), g = W({
7881
+ }), g = U({
7628
7882
  value: r,
7629
7883
  fallback: m
7630
- }), _ = W({
7884
+ }), _ = U({
7631
7885
  value: i,
7632
7886
  fallback: h
7633
- }), v = W({
7887
+ }), v = U({
7634
7888
  value: a,
7635
7889
  fallback: c.scaleX || 1
7636
- }), y = W({
7890
+ }), y = U({
7637
7891
  value: o,
7638
7892
  fallback: c.scaleY || 1
7639
7893
  }), b = g * v, x = _ * y, S = m > 0, C = h > 0, w = b > 0, T = x > 0, E = t._resolveImageFit({ customData: s }), D = {};
@@ -7700,18 +7954,18 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7700
7954
  }
7701
7955
  }
7702
7956
  _transformObject({ object: e, scale: n, bounds: r, baseWidth: i, baseHeight: a, useRelativePositions: o }) {
7703
- let s = e, { x: c, y: l } = Ge({
7957
+ let s = e, { x: c, y: l } = Ke({
7704
7958
  object: e,
7705
7959
  baseWidth: i,
7706
7960
  baseHeight: a,
7707
7961
  useRelativePositions: o
7708
- }), { scaleX: u, scaleY: d } = e, f = W({
7962
+ }), { scaleX: u, scaleY: d } = e, f = U({
7709
7963
  value: u,
7710
7964
  fallback: 1
7711
- }), p = W({
7965
+ }), p = U({
7712
7966
  value: d,
7713
7967
  fallback: 1
7714
- }), m = Ke({
7968
+ }), m = qe({
7715
7969
  normalizedX: c,
7716
7970
  normalizedY: l,
7717
7971
  bounds: t._getPositioningBounds({
@@ -7720,8 +7974,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7720
7974
  baseHeight: a,
7721
7975
  scale: n,
7722
7976
  useRelativePositions: o,
7723
- anchorX: t._resolveAnchor(s, Fr),
7724
- anchorY: t._resolveAnchor(s, Ir)
7977
+ anchorX: t._resolveAnchor(s, Gr),
7978
+ anchorY: t._resolveAnchor(s, Kr)
7725
7979
  })
7726
7980
  }), h = f * n, g = p * n, _ = e.originX ?? "center", v = e.originY ?? "center";
7727
7981
  e.set({
@@ -7735,7 +7989,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7735
7989
  originX: _,
7736
7990
  originY: v
7737
7991
  }
7738
- }), delete s[Fr], delete s[Ir];
7992
+ }), delete s[Gr], delete s[Kr];
7739
7993
  }
7740
7994
  static _getPositioningBounds({ bounds: e, baseWidth: n, baseHeight: r, scale: i, useRelativePositions: a, anchorX: o, anchorY: s }) {
7741
7995
  if (!a) return e;
@@ -7787,19 +8041,19 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7787
8041
  if (!(e instanceof _)) return;
7788
8042
  let r = typeof e.text == "string" ? e.text : "";
7789
8043
  if (!r) return;
7790
- let i = W({
8044
+ let i = U({
7791
8045
  value: this.editor?.montageArea?.width,
7792
8046
  fallback: 0
7793
- }), { width: a = 0 } = e, o = W({
8047
+ }), { width: a = 0 } = e, o = U({
7794
8048
  value: n,
7795
8049
  fallback: 0
7796
- }), s = W({
8050
+ }), s = U({
7797
8051
  value: a,
7798
8052
  fallback: 0
7799
8053
  });
7800
8054
  if (!i || !s || !o) return;
7801
8055
  e.setCoords();
7802
- let c = e, l = t._resolveAnchor(c, Fr), u = typeof c.left == "number" ? c.left : null, d = e.originX ?? "center", f = e.originY ?? "center", p = e.getPointByOrigin(d, f), m = e.getBoundingRect(!1, !0), h = m.left + m.width;
8056
+ let c = e, l = t._resolveAnchor(c, Gr), u = typeof c.left == "number" ? c.left : null, d = e.originX ?? "center", f = e.originY ?? "center", p = e.getPointByOrigin(d, f), m = e.getBoundingRect(!1, !0), h = m.left + m.width;
7803
8057
  e.set("width", i), e.initDimensions();
7804
8058
  let g = t._getLongestLineWidth({
7805
8059
  textbox: e,
@@ -7818,7 +8072,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7818
8072
  return i;
7819
8073
  }
7820
8074
  _serializeObject({ object: e, bounds: n, baseWidth: r, baseHeight: i }) {
7821
- let a = e.toDatalessObject([...oe]);
8075
+ let a = e.toDatalessObject([...ce]);
7822
8076
  if (t._isSvgObject(e)) {
7823
8077
  let n = t._extractSvgMarkup(e);
7824
8078
  n && (a.svgMarkup = n, delete a.objects, delete a.path);
@@ -7828,10 +8082,10 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7828
8082
  x: (p.left - o) / d,
7829
8083
  y: (p.top - s) / f
7830
8084
  }, h = (u.left - o) / d, g = (u.top - s) / f, _ = h + u.width / d, v = g + u.height / f;
7831
- return a[Fr] = t._detectAnchor({
8085
+ return a[Gr] = t._detectAnchor({
7832
8086
  start: h,
7833
8087
  end: _
7834
- }), a[Ir] = t._detectAnchor({
8088
+ }), a[Kr] = t._detectAnchor({
7835
8089
  start: g,
7836
8090
  end: v
7837
8091
  }), a.left = m.x, a.top = m.y, a;
@@ -7856,7 +8110,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7856
8110
  withoutSave: !0
7857
8111
  }), !0;
7858
8112
  if (a === "gradient") {
7859
- let e = Pr(r);
8113
+ let e = Wr(r);
7860
8114
  if (e) return n.setGradientBackground({
7861
8115
  gradient: e,
7862
8116
  customData: o,
@@ -7913,29 +8167,29 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7913
8167
  enlivenObjectEnlivables(e) {
7914
8168
  return C.enlivenObjectEnlivables(e);
7915
8169
  }
7916
- }, Rr = "#3D8BF4", zr = .5, Br = ({ distance: e }) => Number.isFinite(e) ? Math.round(Math.max(0, e)) : 0, Vr = ({ firstDistance: e, secondDistance: t }) => {
7917
- let n = Br({ distance: e }), r = Br({ distance: t });
8170
+ }, Jr = "#3D8BF4", Yr = .5, Xr = ({ distance: e }) => Number.isFinite(e) ? Math.round(Math.max(0, e)) : 0, Zr = ({ firstDistance: e, secondDistance: t }) => {
8171
+ let n = Xr({ distance: e }), r = Xr({ distance: t });
7918
8172
  return {
7919
8173
  firstDisplayDistance: n,
7920
8174
  secondDisplayDistance: r,
7921
8175
  displayDistanceDiff: Math.abs(n - r),
7922
8176
  commonDisplayDistance: Math.max(n, r)
7923
8177
  };
7924
- }, Hr = ({ firstStart: e, firstEnd: t, secondStart: n, secondEnd: r }) => Math.min(t, r) - Math.max(e, n), Ur = ({ step: e }) => {
8178
+ }, Qr = ({ firstStart: e, firstEnd: t, secondStart: n, secondEnd: r }) => Math.min(t, r) - Math.max(e, n), $r = ({ step: e }) => {
7925
8179
  let t = Math.abs(e).toString(), n = t.indexOf(".");
7926
8180
  return n === -1 ? 0 : t.slice(n + 1).length;
7927
- }, Wr = ({ value: e, step: t }) => {
8181
+ }, ei = ({ value: e, step: t }) => {
7928
8182
  if (t === 0) return e;
7929
- let n = Ur({ step: t }), r = Math.round(e / t) * t;
8183
+ let n = $r({ step: t }), r = Math.round(e / t) * t;
7930
8184
  return Number(r.toFixed(n));
7931
- }, Gr = ({ value: e, step: t }) => {
8185
+ }, ti = ({ value: e, step: t }) => {
7932
8186
  if (t === 0) return !0;
7933
- let n = Wr({
8187
+ let n = ei({
7934
8188
  value: e,
7935
8189
  step: t
7936
- }), r = 10 ** -(Ur({ step: t }) + 4);
8190
+ }), r = 10 ** -($r({ step: t }) + 4);
7937
8191
  return Math.abs(n - e) <= r;
7938
- }, Kr = ({ bounds: e, axis: t }) => {
8192
+ }, ni = ({ bounds: e, axis: t }) => {
7939
8193
  let { left: n = 0, right: r = 0, top: i = 0, bottom: a = 0 } = e;
7940
8194
  return t === "vertical" ? {
7941
8195
  start: i,
@@ -7944,7 +8198,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7944
8198
  start: n,
7945
8199
  end: r
7946
8200
  };
7947
- }, qr = ({ items: e, axis: t }) => {
8201
+ }, ri = ({ items: e, axis: t }) => {
7948
8202
  for (let n = 1; n < e.length; n += 1) {
7949
8203
  let r = e[n], { bounds: i } = r, a = i[t], o = n - 1;
7950
8204
  for (; o >= 0;) {
@@ -7954,10 +8208,10 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7954
8208
  }
7955
8209
  e[o + 1] = r;
7956
8210
  }
7957
- }, Jr = ({ items: e, index: t, axis: n, direction: r }) => {
8211
+ }, ii = ({ items: e, index: t, axis: n, direction: r }) => {
7958
8212
  let i = e[t];
7959
8213
  if (!i) return null;
7960
- let { bounds: a } = i, { start: o, end: s } = Kr({
8214
+ let { bounds: a } = i, { start: o, end: s } = ni({
7961
8215
  bounds: a,
7962
8216
  axis: n
7963
8217
  });
@@ -7965,7 +8219,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7965
8219
  for (let r = t - 1; r >= 0; --r) {
7966
8220
  let t = e[r];
7967
8221
  if (!t) continue;
7968
- let { bounds: i } = t, { end: a } = Kr({
8222
+ let { bounds: i } = t, { end: a } = ni({
7969
8223
  bounds: i,
7970
8224
  axis: n
7971
8225
  });
@@ -7976,26 +8230,26 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7976
8230
  for (let r = t + 1; r < e.length; r += 1) {
7977
8231
  let t = e[r];
7978
8232
  if (!t) continue;
7979
- let { bounds: i } = t, { start: a } = Kr({
8233
+ let { bounds: i } = t, { start: a } = ni({
7980
8234
  bounds: i,
7981
8235
  axis: n
7982
8236
  });
7983
8237
  if (a - s >= 0) return r;
7984
8238
  }
7985
8239
  return null;
7986
- }, Yr = ({ items: e }) => {
8240
+ }, ai = ({ items: e }) => {
7987
8241
  for (let t = 0; t < e.length; t += 1) {
7988
8242
  let { isActive: n } = e[t];
7989
8243
  if (n) return t;
7990
8244
  }
7991
8245
  return -1;
7992
- }, Xr = ({ patternAxis: e, activeRangeStart: t, activeRangeEnd: n, tolerance: r = 0 }) => {
8246
+ }, oi = ({ patternAxis: e, activeRangeStart: t, activeRangeEnd: n, tolerance: r = 0 }) => {
7993
8247
  let i = Math.min(t, n), a = Math.max(t, n);
7994
8248
  return e >= i - r && e <= a + r;
7995
- }, Zr = ({ patternStart: e, patternEnd: t, activeStart: n, activeEnd: r }) => t <= n ? "before" : e >= r ? "after" : null, Qr = ({ baseOption: e, candidateOption: t }) => {
8249
+ }, si = ({ patternStart: e, patternEnd: t, activeStart: n, activeEnd: r }) => t <= n ? "before" : e >= r ? "after" : null, ci = ({ baseOption: e, candidateOption: t }) => {
7996
8250
  let { delta: n, guide: { distance: r } } = e, { delta: i, guide: { distance: a } } = t;
7997
8251
  return n === i && r === a;
7998
- }, $r = ({ options: e }) => {
8252
+ }, li = ({ options: e }) => {
7999
8253
  let t = e[0];
8000
8254
  for (let n = 1; n < e.length; n += 1) {
8001
8255
  let r = e[n];
@@ -8006,11 +8260,11 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8006
8260
  r.diff === t.diff && Math.abs(r.delta) < Math.abs(t.delta) && (t = r);
8007
8261
  }
8008
8262
  return t;
8009
- }, ei = ({ currentOption: e, nextOption: t }) => {
8263
+ }, ui = ({ currentOption: e, nextOption: t }) => {
8010
8264
  if (!e) return !0;
8011
8265
  let { contextDistance: n, diff: r, delta: i } = e, { contextDistance: a, diff: o, delta: s } = t;
8012
8266
  return a < n ? !0 : a > n ? !1 : o < r ? !0 : o > r ? !1 : Math.abs(s) < Math.abs(i);
8013
- }, ti = ({ options: e }) => {
8267
+ }, di = ({ options: e }) => {
8014
8268
  let t = [], n = null, r = null;
8015
8269
  for (let i of e) {
8016
8270
  let { kind: e, side: a } = i;
@@ -8018,18 +8272,18 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8018
8272
  t.push(i);
8019
8273
  continue;
8020
8274
  }
8021
- a === "before" && ei({
8275
+ a === "before" && ui({
8022
8276
  currentOption: n,
8023
8277
  nextOption: i
8024
- }) && (n = i), a === "after" && ei({
8278
+ }) && (n = i), a === "after" && ui({
8025
8279
  currentOption: r,
8026
8280
  nextOption: i
8027
8281
  }) && (r = i);
8028
8282
  }
8029
8283
  return n && t.push(n), r && t.push(r), t;
8030
- }, ni = ({ options: e, side: t, baseOption: n }) => {
8284
+ }, fi = ({ options: e, side: t, baseOption: n }) => {
8031
8285
  let r = null;
8032
- for (let i of e) if (i.side === t && Qr({
8286
+ for (let i of e) if (i.side === t && ci({
8033
8287
  baseOption: n,
8034
8288
  candidateOption: i
8035
8289
  })) {
@@ -8040,63 +8294,63 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8040
8294
  !r || i.diff !== r.diff || Math.abs(i.delta) < Math.abs(r.delta) && (r = i);
8041
8295
  }
8042
8296
  return r;
8043
- }, ri = ({ option: e }) => {
8297
+ }, pi = ({ option: e }) => {
8044
8298
  let { side: t, kind: n, guide: { distance: r } } = e;
8045
8299
  return {
8046
8300
  side: t,
8047
8301
  kind: n,
8048
8302
  distance: r
8049
8303
  };
8050
- }, ii = ({ option: e, context: t }) => {
8304
+ }, mi = ({ option: e, context: t }) => {
8051
8305
  let { side: n, kind: r, distance: i } = t, { side: a, kind: o, guide: { distance: s } } = e;
8052
8306
  return n !== a || r !== o ? !1 : Math.abs(s - i) <= 1;
8053
- }, ai = ({ options: e, context: t }) => {
8307
+ }, hi = ({ options: e, context: t }) => {
8054
8308
  if (!t) return null;
8055
- for (let n of e) if (ii({
8309
+ for (let n of e) if (mi({
8056
8310
  option: n,
8057
8311
  context: t
8058
8312
  })) return n;
8059
8313
  return null;
8060
- }, oi = ({ options: e, bestOption: t, previousContext: n, switchDistance: r = 0 }) => {
8061
- let i = ai({
8314
+ }, gi = ({ options: e, bestOption: t, previousContext: n, switchDistance: r = 0 }) => {
8315
+ let i = hi({
8062
8316
  options: e,
8063
8317
  context: n
8064
8318
  });
8065
8319
  if (!i) return t;
8066
8320
  let a = Math.max(0, r);
8067
8321
  return a === 0 || Math.abs(t.delta - i.delta) >= a ? t : i;
8068
- }, si = ({ guides: e, seenGuideKeys: t, guide: n }) => {
8322
+ }, _i = ({ guides: e, seenGuideKeys: t, guide: n }) => {
8069
8323
  let { type: r, axis: i, refStart: a, refEnd: o, activeStart: s, activeEnd: c, distance: l } = n, u = `${r}:${i}:${a}:${o}:${s}:${c}:${l}`;
8070
8324
  t.has(u) || (t.add(u), e.push(n));
8071
- }, ci = ({ options: e, previousContext: t = null, switchDistance: n = 0 }) => {
8325
+ }, vi = ({ options: e, previousContext: t = null, switchDistance: n = 0 }) => {
8072
8326
  if (!e.length) return {
8073
8327
  delta: 0,
8074
8328
  guides: [],
8075
8329
  context: null
8076
8330
  };
8077
- let r = ti({ options: e }), i = [];
8331
+ let r = di({ options: e }), i = [];
8078
8332
  for (let e of r) e.kind === "reference" && i.push(e);
8079
- let a = i.length > 0, o = a ? i : r, s = oi({
8333
+ let a = i.length > 0, o = a ? i : r, s = gi({
8080
8334
  options: o,
8081
- bestOption: $r({ options: o }),
8335
+ bestOption: li({ options: o }),
8082
8336
  previousContext: t,
8083
8337
  switchDistance: n
8084
- }), c = ni({
8338
+ }), c = fi({
8085
8339
  options: o,
8086
8340
  side: "before",
8087
8341
  baseOption: s
8088
- }), l = ni({
8342
+ }), l = fi({
8089
8343
  options: o,
8090
8344
  side: "after",
8091
8345
  baseOption: s
8092
- }), u = ni({
8346
+ }), u = fi({
8093
8347
  options: a ? r : o,
8094
8348
  side: "center",
8095
8349
  baseOption: s
8096
8350
  }), d = [];
8097
8351
  c && l ? d.push(c, l) : (d.push(s), s.side === "before" && l && d.push(l), s.side === "after" && c && d.push(c), s.side === "center" && (c && !l && d.push(c), l && !c && d.push(l)), a && s.side === "before" && !l && u && d.push(u), a && s.side === "after" && !c && u && d.push(u)), !d.length && u && d.push(u);
8098
8352
  let f = [], p = /* @__PURE__ */ new Set();
8099
- for (let e of d) si({
8353
+ for (let e of d) _i({
8100
8354
  guides: f,
8101
8355
  seenGuideKeys: p,
8102
8356
  guide: e.guide
@@ -8104,15 +8358,15 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8104
8358
  return {
8105
8359
  delta: s.delta,
8106
8360
  guides: f,
8107
- context: ri({ option: s })
8361
+ context: pi({ option: s })
8108
8362
  };
8109
- }, li = ({ activeStart: e, activeEnd: t, targetGap: n, beforeEdge: r, afterEdge: i, threshold: a, step: o }) => {
8110
- let s = n - (e - r), c = Wr({
8363
+ }, yi = ({ activeStart: e, activeEnd: t, targetGap: n, beforeEdge: r, afterEdge: i, threshold: a, step: o }) => {
8364
+ let s = n - (e - r), c = ei({
8111
8365
  value: s,
8112
8366
  step: o
8113
8367
  }), l = Math.max(1, Math.ceil(a / Math.max(o, 1))), u = null;
8114
8368
  for (let d = -l; d <= l; d += 1) {
8115
- let l = c + d * o, f = e + l, p = t + l, m = f - r, h = i - p, { displayDistanceDiff: g, commonDisplayDistance: _ } = Vr({
8369
+ let l = c + d * o, f = e + l, p = t + l, m = f - r, h = i - p, { displayDistanceDiff: g, commonDisplayDistance: _ } = Zr({
8116
8370
  firstDistance: m,
8117
8371
  secondDistance: h
8118
8372
  });
@@ -8127,13 +8381,13 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8127
8381
  });
8128
8382
  }
8129
8383
  return u;
8130
- }, ui = ({ currentGap: e, referenceGap: t }) => {
8131
- let { secondDisplayDistance: n, displayDistanceDiff: r } = Vr({
8384
+ }, bi = ({ currentGap: e, referenceGap: t }) => {
8385
+ let { secondDisplayDistance: n, displayDistanceDiff: r } = Zr({
8132
8386
  firstDistance: e,
8133
8387
  secondDistance: t
8134
8388
  });
8135
8389
  return r > 1 ? null : n;
8136
- }, di = ({ anchors: e, positions: t, threshold: n }) => {
8390
+ }, xi = ({ anchors: e, positions: t, threshold: n }) => {
8137
8391
  let r = 0, i = n + 1, a = null;
8138
8392
  for (let o of t) for (let t of e) {
8139
8393
  let e = Math.abs(t - o);
@@ -8143,8 +8397,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8143
8397
  delta: r,
8144
8398
  guidePosition: a
8145
8399
  };
8146
- }, fi = ({ activeBounds: e, threshold: t, anchors: n }) => {
8147
- let { left: r, right: i, centerX: a, top: o, bottom: s, centerY: c } = e, l = di({
8400
+ }, Si = ({ activeBounds: e, threshold: t, anchors: n }) => {
8401
+ let { left: r, right: i, centerX: a, top: o, bottom: s, centerY: c } = e, l = xi({
8148
8402
  anchors: n.vertical,
8149
8403
  positions: [
8150
8404
  r,
@@ -8152,7 +8406,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8152
8406
  i
8153
8407
  ],
8154
8408
  threshold: t
8155
- }), u = di({
8409
+ }), u = xi({
8156
8410
  anchors: n.horizontal,
8157
8411
  positions: [
8158
8412
  o,
@@ -8172,11 +8426,11 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8172
8426
  deltaY: u.delta,
8173
8427
  guides: d
8174
8428
  };
8175
- }, pi = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
8429
+ }, Ci = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
8176
8430
  let { centerX: o, top: s, bottom: c, left: l, right: u } = e, d = [];
8177
8431
  for (let e of t) {
8178
8432
  let { left: t, right: n } = e;
8179
- Hr({
8433
+ Qr({
8180
8434
  firstStart: t,
8181
8435
  firstEnd: n,
8182
8436
  secondStart: l,
@@ -8196,22 +8450,22 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8196
8450
  f.push({
8197
8451
  bounds: e,
8198
8452
  isActive: !0
8199
- }), qr({
8453
+ }), ri({
8200
8454
  items: f,
8201
8455
  axis: "top"
8202
8456
  });
8203
- let p = Yr({ items: f });
8457
+ let p = ai({ items: f });
8204
8458
  if (p === -1) return {
8205
8459
  delta: 0,
8206
8460
  guides: [],
8207
8461
  context: null
8208
8462
  };
8209
- let m = [], h = c - s, g = Jr({
8463
+ let m = [], h = c - s, g = ii({
8210
8464
  items: f,
8211
8465
  index: p,
8212
8466
  axis: "vertical",
8213
8467
  direction: "prev"
8214
- }), _ = Jr({
8468
+ }), _ = ii({
8215
8469
  items: f,
8216
8470
  index: p,
8217
8471
  axis: "vertical",
@@ -8220,19 +8474,19 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8220
8474
  if (v && y) {
8221
8475
  let { bounds: e } = v, { bounds: t } = y, { bottom: r } = e, { top: i } = t, a = i - r - h;
8222
8476
  if (a >= 0) {
8223
- let e = Wr({
8477
+ let e = ei({
8224
8478
  value: a / 2,
8225
8479
  step: 1
8226
8480
  }), t = s - r, l = i - c, u = Math.abs(t - e), d = Math.abs(l - e);
8227
8481
  if (Math.max(u, d) <= n) {
8228
- let t = li({
8482
+ let t = yi({
8229
8483
  activeStart: s,
8230
8484
  activeEnd: c,
8231
8485
  targetGap: e,
8232
8486
  beforeEdge: r,
8233
8487
  afterEdge: i,
8234
8488
  threshold: n,
8235
- step: zr
8489
+ step: Yr
8236
8490
  });
8237
8491
  if (t) {
8238
8492
  let { delta: e, distance: n, diff: i, activeStart: a, activeEnd: s } = t, c = {
@@ -8269,16 +8523,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8269
8523
  }
8270
8524
  for (let e of r) {
8271
8525
  let { axis: t, start: r, end: i, distance: a } = e;
8272
- if (!Gr({
8526
+ if (!ti({
8273
8527
  value: a,
8274
8528
  step: .5
8275
- }) || !Xr({
8529
+ }) || !oi({
8276
8530
  patternAxis: t,
8277
8531
  activeRangeStart: l,
8278
8532
  activeRangeEnd: u,
8279
8533
  tolerance: n
8280
8534
  })) continue;
8281
- let d = Zr({
8535
+ let d = si({
8282
8536
  patternStart: r,
8283
8537
  patternEnd: i,
8284
8538
  activeStart: s,
@@ -8286,12 +8540,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8286
8540
  });
8287
8541
  if (d) {
8288
8542
  if (b !== null && S && d === "before" && Math.abs(b - a) <= n) {
8289
- let e = Wr({
8543
+ let e = ei({
8290
8544
  value: a - b,
8291
8545
  step: 1
8292
8546
  }), t = s + e, { bottom: c } = S, l = t - c, u = Math.abs(l - a);
8293
8547
  if (u > n) continue;
8294
- let d = ui({
8548
+ let d = bi({
8295
8549
  currentGap: l,
8296
8550
  referenceGap: a
8297
8551
  });
@@ -8315,12 +8569,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8315
8569
  });
8316
8570
  }
8317
8571
  if (x !== null && C && d === "after" && Math.abs(x - a) <= n) {
8318
- let e = Wr({
8572
+ let e = ei({
8319
8573
  value: x - a,
8320
8574
  step: 1
8321
8575
  }), t = c + e, { top: s } = C, l = s - t, u = Math.abs(l - a);
8322
8576
  if (u > n) continue;
8323
- let d = ui({
8577
+ let d = bi({
8324
8578
  currentGap: l,
8325
8579
  referenceGap: a
8326
8580
  });
@@ -8345,16 +8599,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8345
8599
  }
8346
8600
  }
8347
8601
  }
8348
- return ci({
8602
+ return vi({
8349
8603
  options: m,
8350
8604
  previousContext: i,
8351
8605
  switchDistance: a
8352
8606
  });
8353
- }, mi = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
8607
+ }, wi = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
8354
8608
  let { centerY: o, left: s, right: c, top: l, bottom: u } = e, d = [];
8355
8609
  for (let e of t) {
8356
8610
  let { top: t, bottom: n } = e;
8357
- Hr({
8611
+ Qr({
8358
8612
  firstStart: t,
8359
8613
  firstEnd: n,
8360
8614
  secondStart: l,
@@ -8374,22 +8628,22 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8374
8628
  f.push({
8375
8629
  bounds: e,
8376
8630
  isActive: !0
8377
- }), qr({
8631
+ }), ri({
8378
8632
  items: f,
8379
8633
  axis: "left"
8380
8634
  });
8381
- let p = Yr({ items: f });
8635
+ let p = ai({ items: f });
8382
8636
  if (p === -1) return {
8383
8637
  delta: 0,
8384
8638
  guides: [],
8385
8639
  context: null
8386
8640
  };
8387
- let m = [], h = c - s, g = Jr({
8641
+ let m = [], h = c - s, g = ii({
8388
8642
  items: f,
8389
8643
  index: p,
8390
8644
  axis: "horizontal",
8391
8645
  direction: "prev"
8392
- }), _ = Jr({
8646
+ }), _ = ii({
8393
8647
  items: f,
8394
8648
  index: p,
8395
8649
  axis: "horizontal",
@@ -8398,19 +8652,19 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8398
8652
  if (v && y) {
8399
8653
  let { bounds: e } = v, { bounds: t } = y, { right: r } = e, { left: i } = t, a = i - r - h;
8400
8654
  if (a >= 0) {
8401
- let e = Wr({
8655
+ let e = ei({
8402
8656
  value: a / 2,
8403
8657
  step: 1
8404
8658
  }), t = s - r, l = i - c, u = Math.abs(t - e), d = Math.abs(l - e);
8405
8659
  if (Math.max(u, d) <= n) {
8406
- let t = li({
8660
+ let t = yi({
8407
8661
  activeStart: s,
8408
8662
  activeEnd: c,
8409
8663
  targetGap: e,
8410
8664
  beforeEdge: r,
8411
8665
  afterEdge: i,
8412
8666
  threshold: n,
8413
- step: zr
8667
+ step: Yr
8414
8668
  });
8415
8669
  if (t) {
8416
8670
  let { delta: e, distance: n, diff: i, activeStart: a, activeEnd: s } = t, c = {
@@ -8447,16 +8701,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8447
8701
  }
8448
8702
  for (let e of r) {
8449
8703
  let { axis: t, start: r, end: i, distance: a } = e;
8450
- if (!Gr({
8704
+ if (!ti({
8451
8705
  value: a,
8452
8706
  step: .5
8453
- }) || !Xr({
8707
+ }) || !oi({
8454
8708
  patternAxis: t,
8455
8709
  activeRangeStart: l,
8456
8710
  activeRangeEnd: u,
8457
8711
  tolerance: n
8458
8712
  })) continue;
8459
- let d = Zr({
8713
+ let d = si({
8460
8714
  patternStart: r,
8461
8715
  patternEnd: i,
8462
8716
  activeStart: s,
@@ -8464,12 +8718,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8464
8718
  });
8465
8719
  if (d) {
8466
8720
  if (b !== null && S && d === "before" && Math.abs(b - a) <= n) {
8467
- let e = Wr({
8721
+ let e = ei({
8468
8722
  value: a - b,
8469
8723
  step: 1
8470
8724
  }), t = s + e, { right: c } = S, l = t - c, u = Math.abs(l - a);
8471
8725
  if (u > n) continue;
8472
- let d = ui({
8726
+ let d = bi({
8473
8727
  currentGap: l,
8474
8728
  referenceGap: a
8475
8729
  });
@@ -8493,12 +8747,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8493
8747
  });
8494
8748
  }
8495
8749
  if (x !== null && C && d === "after" && Math.abs(x - a) <= n) {
8496
- let e = Wr({
8750
+ let e = ei({
8497
8751
  value: x - a,
8498
8752
  step: 1
8499
8753
  }), t = c + e, { left: s } = C, l = s - t, u = Math.abs(l - a);
8500
8754
  if (u > n) continue;
8501
- let d = ui({
8755
+ let d = bi({
8502
8756
  currentGap: l,
8503
8757
  referenceGap: a
8504
8758
  });
@@ -8523,20 +8777,20 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8523
8777
  }
8524
8778
  }
8525
8779
  }
8526
- return ci({
8780
+ return vi({
8527
8781
  options: m,
8528
8782
  previousContext: i,
8529
8783
  switchDistance: a
8530
8784
  });
8531
- }, hi = ({ activeBounds: e, candidates: t, threshold: n, spacingPatterns: r, previousContexts: i, switchDistance: a = 0 }) => {
8532
- let { vertical: o = null, horizontal: s = null } = i ?? {}, c = pi({
8785
+ }, Ti = ({ activeBounds: e, candidates: t, threshold: n, spacingPatterns: r, previousContexts: i, switchDistance: a = 0 }) => {
8786
+ let { vertical: o = null, horizontal: s = null } = i ?? {}, c = Ci({
8533
8787
  activeBounds: e,
8534
8788
  candidates: t,
8535
8789
  threshold: n,
8536
8790
  patterns: r.vertical,
8537
8791
  previousContext: o,
8538
8792
  switchDistance: a
8539
- }), l = mi({
8793
+ }), l = wi({
8540
8794
  activeBounds: e,
8541
8795
  candidates: t,
8542
8796
  threshold: n,
@@ -8555,14 +8809,14 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8555
8809
  horizontal: l.context
8556
8810
  }
8557
8811
  };
8558
- }, gi = ({ context: e, x: t, y: n, width: r, height: i, radius: a }) => {
8812
+ }, Ei = ({ context: e, x: t, y: n, width: r, height: i, radius: a }) => {
8559
8813
  let o = Math.min(a, r / 2, i / 2);
8560
8814
  e.moveTo(t + o, n), e.lineTo(t + r - o, n), e.quadraticCurveTo(t + r, n, t + r, n + o), e.lineTo(t + r, n + i - o), e.quadraticCurveTo(t + r, n + i, t + r - o, n + i), e.lineTo(t + o, n + i), e.quadraticCurveTo(t, n + i, t, n + i - o), e.lineTo(t, n + o), e.quadraticCurveTo(t, n, t + o, n), e.closePath();
8561
- }, _i = ({ context: e, type: t, axis: n, start: r, end: i, text: a, zoom: o, color: s, textColor: c = "#ffffff", fontFamily: l = "sans-serif", lineWidth: u = 1, padding: d = 4, radius: f = 4, offsetAlongAxis: p = 0, offsetPerpendicular: m = 0 }) => {
8815
+ }, Di = ({ context: e, type: t, axis: n, start: r, end: i, text: a, zoom: o, color: s, textColor: c = "#ffffff", fontFamily: l = "sans-serif", lineWidth: u = 1, padding: d = 4, radius: f = 4, offsetAlongAxis: p = 0, offsetPerpendicular: m = 0 }) => {
8562
8816
  let h = o || 1, g = 12 / h, _ = d / h, v = f / h, y = (r + i) / 2 + p, b = t === "vertical" ? n + m : y, x = t === "vertical" ? y : n + m;
8563
8817
  e.save(), e.setLineDash([]), e.fillStyle = s, e.strokeStyle = s, e.lineWidth = u / h, e.font = `${g}px ${l}`, e.textAlign = "center", e.textBaseline = "middle";
8564
8818
  let S = e.measureText(a).width + _ * 2, C = g + _ * 2, w = b - S / 2, T = x - C / 2;
8565
- e.beginPath(), gi({
8819
+ e.beginPath(), Ei({
8566
8820
  context: e,
8567
8821
  x: w,
8568
8822
  y: T,
@@ -8570,11 +8824,11 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8570
8824
  height: C,
8571
8825
  radius: v
8572
8826
  }), e.fill(), e.fillStyle = c, e.fillText(a, b, x), e.restore();
8573
- }, vi = ({ context: e, guide: t, zoom: n }) => {
8574
- let { type: r, axis: i, refStart: a, refEnd: o, activeStart: s, activeEnd: c, distance: l } = t, u = Br({ distance: l }).toString();
8827
+ }, Oi = ({ context: e, guide: t, zoom: n }) => {
8828
+ let { type: r, axis: i, refStart: a, refEnd: o, activeStart: s, activeEnd: c, distance: l } = t, u = Xr({ distance: l }).toString();
8575
8829
  e.beginPath(), r === "vertical" ? (e.moveTo(i, a), e.lineTo(i, o), e.moveTo(i, s), e.lineTo(i, c)) : (e.moveTo(a, i), e.lineTo(o, i), e.moveTo(s, i), e.lineTo(c, i)), e.stroke();
8576
- let d = Rr;
8577
- _i({
8830
+ let d = Jr;
8831
+ Di({
8578
8832
  context: e,
8579
8833
  type: r,
8580
8834
  axis: i,
@@ -8584,7 +8838,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8584
8838
  zoom: n,
8585
8839
  color: d,
8586
8840
  lineWidth: 1
8587
- }), _i({
8841
+ }), Di({
8588
8842
  context: e,
8589
8843
  type: r,
8590
8844
  axis: i,
@@ -8595,10 +8849,10 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8595
8849
  color: d,
8596
8850
  lineWidth: 1
8597
8851
  });
8598
- }, yi = ({ anchors: e, bounds: t }) => {
8852
+ }, ki = ({ anchors: e, bounds: t }) => {
8599
8853
  let { left: n, right: r, centerX: i, top: a, bottom: o, centerY: s } = t;
8600
8854
  e.vertical.push(n, i, r), e.horizontal.push(a, s, o);
8601
- }, bi = ({ bounds: e, type: t, primaryStart: n, primaryEnd: r }) => {
8855
+ }, Ai = ({ bounds: e, type: t, primaryStart: n, primaryEnd: r }) => {
8602
8856
  let i = [], a = n === "top" ? "left" : "top", o = r === "bottom" ? "right" : "bottom", s = [...e].sort((e, t) => e[n] - t[n]);
8603
8857
  for (let e = 0; e < s.length; e += 1) {
8604
8858
  let c = s[e], l = null, u = Infinity;
@@ -8619,35 +8873,35 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8619
8873
  });
8620
8874
  }
8621
8875
  return i;
8622
- }, xi = ({ bounds: e }) => ({
8623
- vertical: bi({
8876
+ }, ji = ({ bounds: e }) => ({
8877
+ vertical: Ai({
8624
8878
  bounds: e,
8625
8879
  axis: "centerX",
8626
8880
  type: "vertical",
8627
8881
  primaryStart: "top",
8628
8882
  primaryEnd: "bottom"
8629
8883
  }),
8630
- horizontal: bi({
8884
+ horizontal: Ai({
8631
8885
  bounds: e,
8632
8886
  axis: "centerY",
8633
8887
  type: "horizontal",
8634
8888
  primaryStart: "left",
8635
8889
  primaryEnd: "right"
8636
8890
  })
8637
- }), Si = [
8891
+ }), Mi = [
8638
8892
  "montage-area",
8639
8893
  "background",
8640
8894
  "interaction-blocker"
8641
- ], Ci = ({ activeObject: t }) => {
8895
+ ], Ni = ({ activeObject: t }) => {
8642
8896
  let n = /* @__PURE__ */ new Set();
8643
8897
  return t ? (n.add(t), t instanceof e && t.getObjects().forEach((e) => n.add(e)), n) : n;
8644
- }, wi = ({ object: e, excluded: t, ignoredIds: n = Si }) => {
8898
+ }, Pi = ({ object: e, excluded: t, ignoredIds: n = Mi }) => {
8645
8899
  if (t.has(e)) return !0;
8646
8900
  let { visible: r = !0 } = e;
8647
8901
  if (!r) return !0;
8648
8902
  let { id: i } = e;
8649
8903
  return !!(i && n.includes(i));
8650
- }, Ti = class e {
8904
+ }, Fi = class e {
8651
8905
  constructor({ editor: e }) {
8652
8906
  this.anchors = {
8653
8907
  vertical: [],
@@ -8695,12 +8949,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8695
8949
  target: n,
8696
8950
  transform: i
8697
8951
  }), !this.anchors.vertical.length && !this.anchors.horizontal.length && this._cacheAnchors({ activeObject: n });
8698
- let a = Je({ object: n });
8952
+ let a = W({ object: n });
8699
8953
  if (!a) {
8700
8954
  this._clearSpacingContexts(), this._clearGuides();
8701
8955
  return;
8702
8956
  }
8703
- let { canvas: o } = this, s = o.getZoom() || 1, c = 5 / s, { deltaX: l, deltaY: u } = fi({
8957
+ let { canvas: o } = this, s = o.getZoom() || 1, c = 5 / s, { deltaX: l, deltaY: u } = Si({
8704
8958
  activeBounds: a,
8705
8959
  threshold: c,
8706
8960
  anchors: this.anchors
@@ -8710,9 +8964,9 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8710
8964
  n.set({
8711
8965
  left: e + l,
8712
8966
  top: t + u
8713
- }), n.setCoords(), a = Je({ object: n }) ?? a;
8967
+ }), n.setCoords(), a = W({ object: n }) ?? a;
8714
8968
  }
8715
- let d = this._resolveCurrentTargetBounds({ activeObject: n }), f = this.spacingContexts.vertical || this.spacingContexts.horizontal ? 10 / s : c, p = hi({
8969
+ let d = this._resolveCurrentTargetBounds({ activeObject: n }), f = this.spacingContexts.vertical || this.spacingContexts.horizontal ? 10 / s : c, p = Ti({
8716
8970
  activeBounds: a,
8717
8971
  candidates: d,
8718
8972
  threshold: f,
@@ -8727,17 +8981,17 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8727
8981
  n.set({
8728
8982
  left: e + p.deltaX,
8729
8983
  top: t + p.deltaY
8730
- }), n.setCoords(), a = Je({ object: n }) ?? a;
8984
+ }), n.setCoords(), a = W({ object: n }) ?? a;
8731
8985
  }
8732
8986
  m || e._applyMovementStep({
8733
8987
  target: n,
8734
8988
  transform: i
8735
8989
  });
8736
- let h = Je({ object: n }) ?? a, g = fi({
8990
+ let h = W({ object: n }) ?? a, g = Si({
8737
8991
  activeBounds: h,
8738
8992
  threshold: c,
8739
8993
  anchors: this.anchors
8740
- }), _ = hi({
8994
+ }), _ = Ti({
8741
8995
  activeBounds: h,
8742
8996
  candidates: d,
8743
8997
  threshold: c,
@@ -8777,7 +9031,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8777
9031
  }
8778
9032
  let { anchors: l } = this, { vertical: u, horizontal: d } = l;
8779
9033
  !u.length && !d.length && this._cacheAnchors({ activeObject: n });
8780
- let f = Je({ object: n });
9034
+ let f = W({ object: n });
8781
9035
  if (!f) {
8782
9036
  this._clearGuides();
8783
9037
  return;
@@ -8901,7 +9155,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8901
9155
  }
8902
9156
  let { anchors: a } = this, { vertical: o, horizontal: s } = a;
8903
9157
  !o.length && !s.length && this._cacheAnchors({ activeObject: t });
8904
- let c = Je({ object: t });
9158
+ let c = W({ object: t });
8905
9159
  if (!c) {
8906
9160
  this._clearGuides();
8907
9161
  return;
@@ -8968,9 +9222,9 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8968
9222
  let { canvas: e, guideBounds: t } = this, n = e.getSelectionContext();
8969
9223
  if (!n) return;
8970
9224
  let { left: r, right: i, top: a, bottom: o } = t ?? this._calculateViewportBounds(), { viewportTransform: s } = e, c = e.getZoom() || 1;
8971
- n.save(), Array.isArray(s) && n.transform(...s), n.lineWidth = 1 / c, n.strokeStyle = Rr, n.setLineDash([4, 4]);
9225
+ n.save(), Array.isArray(s) && n.transform(...s), n.lineWidth = 1 / c, n.strokeStyle = Jr, n.setLineDash([4, 4]);
8972
9226
  for (let e of this.activeGuides) n.beginPath(), e.type === "vertical" ? (n.moveTo(e.position, a), n.lineTo(e.position, o)) : (n.moveTo(r, e.position), n.lineTo(i, e.position)), n.stroke();
8973
- for (let e of this.activeSpacingGuides) vi({
9227
+ for (let e of this.activeSpacingGuides) Oi({
8974
9228
  context: n,
8975
9229
  guide: e,
8976
9230
  zoom: c
@@ -9180,15 +9434,15 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9180
9434
  horizontal: []
9181
9435
  }, r = [];
9182
9436
  for (let e of t) {
9183
- let t = Je({ object: e });
9184
- t && (yi({
9437
+ let t = W({ object: e });
9438
+ t && (ki({
9185
9439
  anchors: n,
9186
9440
  bounds: t
9187
9441
  }), r.push(t));
9188
9442
  }
9189
- let { montageArea: i } = this.editor, a = Je({ object: i });
9443
+ let { montageArea: i } = this.editor, a = W({ object: i });
9190
9444
  if (a) {
9191
- yi({
9445
+ ki({
9192
9446
  anchors: n,
9193
9447
  bounds: a
9194
9448
  });
@@ -9200,12 +9454,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9200
9454
  bottom: i
9201
9455
  };
9202
9456
  } else this.guideBounds = this._calculateViewportBounds();
9203
- this.anchors = n, this.spacingPatterns = xi({ bounds: r }), this.cachedTargetBounds = r;
9457
+ this.anchors = n, this.spacingPatterns = ji({ bounds: r }), this.cachedTargetBounds = r;
9204
9458
  }
9205
9459
  _collectTargets({ activeObject: e }) {
9206
- let t = Ci({ activeObject: e }), n = [];
9460
+ let t = Ni({ activeObject: e }), n = [];
9207
9461
  return this.canvas.forEachObject((e) => {
9208
- wi({
9462
+ Pi({
9209
9463
  object: e,
9210
9464
  excluded: t
9211
9465
  }) || n.push(e);
@@ -9214,7 +9468,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9214
9468
  _resolveCurrentTargetBounds({ activeObject: e }) {
9215
9469
  let t = this._collectTargets({ activeObject: e }), n = [];
9216
9470
  for (let e of t) {
9217
- let t = Je({ object: e });
9471
+ let t = W({ object: e });
9218
9472
  t && n.push(t);
9219
9473
  }
9220
9474
  return n;
@@ -9228,7 +9482,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9228
9482
  bottom: (r - s) / a
9229
9483
  };
9230
9484
  }
9231
- }, Ei = "#3D8BF4", Di = class e {
9485
+ }, Ii = "#3D8BF4", Li = class e {
9232
9486
  constructor({ editor: e }) {
9233
9487
  this.activeGuides = [], this.isAltPressed = !1, this.pendingEvent = null, this.frameRequest = null, this.isToolbarHidden = !1, this.isTargetMontageArea = !1, this.lastMouseEvent = null, this.editor = e, this.canvas = e.canvas, this._onMouseMove = this._handleMouseMove.bind(this), this._onBeforeRender = this._handleBeforeRender.bind(this), this._onAfterRender = this._handleAfterRender.bind(this), this._onSelectionCleared = this._handleSelectionCleared.bind(this), this._onKeyDown = this._handleKeyDown.bind(this), this._onKeyUp = this._handleKeyUp.bind(this), this._onWindowBlur = this._handleWindowBlur.bind(this), this._bindEvents();
9234
9488
  }
@@ -9292,7 +9546,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9292
9546
  this._clearGuides();
9293
9547
  return;
9294
9548
  }
9295
- let a = Je({ object: i });
9549
+ let a = W({ object: i });
9296
9550
  if (!a) {
9297
9551
  this._clearGuides();
9298
9552
  return;
@@ -9300,7 +9554,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9300
9554
  let o = e._resolveTarget({
9301
9555
  event: t,
9302
9556
  activeObject: i
9303
- }), { montageArea: s } = r, c = o ?? s, l = c === s, u = Je({ object: c });
9557
+ }), { montageArea: s } = r, c = o ?? s, l = c === s, u = W({ object: c });
9304
9558
  if (!u) {
9305
9559
  this._clearGuides();
9306
9560
  return;
@@ -9321,8 +9575,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9321
9575
  this.isTargetMontageArea = l, this.activeGuides = d, this._hideToolbar(), n.requestRenderAll();
9322
9576
  }
9323
9577
  static _resolveTarget({ event: e, activeObject: t }) {
9324
- let { target: n } = e, r = Ci({ activeObject: t });
9325
- return n && !wi({
9578
+ let { target: n } = e, r = Ni({ activeObject: t });
9579
+ return n && !Pi({
9326
9580
  object: n,
9327
9581
  excluded: r
9328
9582
  }) ? n : null;
@@ -9439,18 +9693,18 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9439
9693
  let { canvas: e } = this, t = e.getSelectionContext();
9440
9694
  if (!t) return;
9441
9695
  let { viewportTransform: n } = e, r = e.getZoom() || 1, i = this.activeGuides.some((e) => e.type === "vertical"), a = this.activeGuides.some((e) => e.type === "horizontal"), o = i && a && !this.isTargetMontageArea, s = o ? 12 / r : 0;
9442
- t.save(), Array.isArray(n) && t.transform(...n), t.lineWidth = 1 / r, t.strokeStyle = Ei, t.setLineDash([]);
9696
+ t.save(), Array.isArray(n) && t.transform(...n), t.lineWidth = 1 / r, t.strokeStyle = Ii, t.setLineDash([]);
9443
9697
  for (let e of this.activeGuides) {
9444
9698
  let { type: n, axis: i, start: a, end: c, distance: l } = e, u = Math.abs(c - a), d = o ? (a <= c ? -1 : 1) * (u / 2 + s) : 0;
9445
- t.beginPath(), n === "vertical" ? (t.moveTo(i, a), t.lineTo(i, c)) : (t.moveTo(a, i), t.lineTo(c, i)), t.stroke(), _i({
9699
+ t.beginPath(), n === "vertical" ? (t.moveTo(i, a), t.lineTo(i, c)) : (t.moveTo(a, i), t.lineTo(c, i)), t.stroke(), Di({
9446
9700
  context: t,
9447
9701
  type: n,
9448
9702
  axis: i,
9449
9703
  start: a,
9450
9704
  end: c,
9451
- text: Br({ distance: l }).toString(),
9705
+ text: Xr({ distance: l }).toString(),
9452
9706
  zoom: r,
9453
- color: Ei,
9707
+ color: Ii,
9454
9708
  lineWidth: 1,
9455
9709
  offsetAlongAxis: d,
9456
9710
  offsetPerpendicular: 0
@@ -9468,13 +9722,13 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9468
9722
  let { toolbar: e } = this.editor;
9469
9723
  e?.showAfterTemporary?.(), this.isToolbarHidden = !1;
9470
9724
  }
9471
- }, Oi = class e {
9725
+ }, Ri = class e {
9472
9726
  constructor(e, t) {
9473
9727
  this.options = t, this.containerId = e, this.editorId = `${e}-${D()}`, this.init();
9474
9728
  }
9475
9729
  async init() {
9476
9730
  let { editorContainerWidth: e, editorContainerHeight: n, canvasWrapperWidth: r, canvasWrapperHeight: i, canvasCSSWidth: a, canvasCSSHeight: o, initialImage: s, initialState: c, scaleType: l, showRotationAngle: u, _onReadyCallback: d } = this.options;
9477
- if (z.apply(), this.canvas = new t(this.containerId, this.options), this.moduleLoader = new A(), this.workerManager = new M(), this.errorManager = new tr({ editor: this }), this.historyManager = new je({ editor: this }), this.toolbar = new ae({ editor: this }), this.transformManager = new He({ editor: this }), this.zoomManager = new Ue({ editor: this }), this.canvasManager = new Ve({ editor: this }), this.imageManager = new Le({ editor: this }), this.layerManager = new $e({ editor: this }), this.shapeManager = new Jn({ editor: this }), this.interactionBlocker = new Ze({ editor: this }), this.backgroundManager = new Qe({ editor: this }), this.clipboardManager = new Yn({ editor: this }), this.objectLockManager = new Xn({ editor: this }), this.groupingManager = new Zn({ editor: this }), this.selectionManager = new Qn({ editor: this }), this.deletionManager = new $n({ editor: this }), this.panConstraintManager = new nr({ editor: this }), this.snappingManager = new Ti({ editor: this }), this.measurementManager = new Di({ editor: this }), this.fontManager = new ie(this.options.fonts ?? []), this.textManager = new Mr({ editor: this }), this.templateManager = new Lr({ editor: this }), u && (this.angleIndicator = new U({ editor: this })), this._createMontageArea(), this._createClippingArea(), this.interactionBlocker.ensureOverlay(), this.listeners = new k({
9731
+ if (z.apply(), this.canvas = new t(this.containerId, this.options), this.moduleLoader = new A(), this.workerManager = new M(), this.errorManager = new tr({ editor: this }), this.historyManager = new Me({ editor: this }), this.toolbar = new ae({ editor: this }), this.transformManager = new Ue({ editor: this }), this.zoomManager = new We({ editor: this }), this.canvasManager = new He({ editor: this }), this.imageManager = new Re({ editor: this }), this.layerManager = new $e({ editor: this }), this.shapeManager = new Jn({ editor: this }), this.interactionBlocker = new Ze({ editor: this }), this.backgroundManager = new Qe({ editor: this }), this.clipboardManager = new Yn({ editor: this }), this.objectLockManager = new Xn({ editor: this }), this.groupingManager = new Zn({ editor: this }), this.selectionManager = new Qn({ editor: this }), this.deletionManager = new $n({ editor: this }), this.panConstraintManager = new nr({ editor: this }), this.snappingManager = new Fi({ editor: this }), this.measurementManager = new Li({ editor: this }), this.fontManager = new ie(this.options.fonts ?? []), this.textManager = new Hr({ editor: this }), this.templateManager = new qr({ editor: this }), u && (this.angleIndicator = new se({ editor: this })), this._createMontageArea(), this._createClippingArea(), this.interactionBlocker.ensureOverlay(), this.listeners = new k({
9478
9732
  editor: this,
9479
9733
  options: this.options
9480
9734
  }), this.canvasManager.setEditorContainerWidth(e), this.canvasManager.setEditorContainerHeight(n), this.canvasManager.setCanvasWrapperWidth(r), this.canvasManager.setCanvasWrapperHeight(i), this.canvasManager.setCanvasCSSWidth(a), this.canvasManager.setCanvasCSSHeight(o), this.canvasManager.updateCanvas(), this.zoomManager.calculateAndApplyDefaultZoom(), await this.fontManager.loadFonts(), c) {
@@ -9582,7 +9836,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9582
9836
  "U+A640-A69F",
9583
9837
  "U+FE2E-FE2F",
9584
9838
  "U+2116"
9585
- ].join(", "), ki = {
9839
+ ].join(", "), zi = {
9586
9840
  preserveObjectStacking: !0,
9587
9841
  controlsAboveOverlay: !0,
9588
9842
  centeredRotation: !0,
@@ -10436,20 +10690,20 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
10436
10690
  };
10437
10691
  //#endregion
10438
10692
  //#region src/main.ts
10439
- function Ai(e, t = {}) {
10693
+ function Bi(e, t = {}) {
10440
10694
  let n = {
10441
- ...ki,
10695
+ ...zi,
10442
10696
  ...t
10443
10697
  }, r = document.getElementById(e);
10444
10698
  if (!r) return Promise.reject(/* @__PURE__ */ Error(`Контейнер с ID "${e}" не найден.`));
10445
10699
  let i = document.createElement("canvas");
10446
10700
  return i.id = `${e}-canvas`, r.appendChild(i), n.editorContainer = r, new Promise((t) => {
10447
10701
  n._onReadyCallback = t;
10448
- let r = new Oi(i.id, n);
10702
+ let r = new Ri(i.id, n);
10449
10703
  window[e] = r;
10450
10704
  });
10451
10705
  }
10452
10706
  //#endregion
10453
- export { Ai as default };
10707
+ export { Bi as default };
10454
10708
 
10455
10709
  //# sourceMappingURL=main.js.map