@anu3ev/fabric-image-editor 0.7.2 → 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
  }
@@ -1048,7 +1049,7 @@ function je({ canvas: e, callback: t }) {
1048
1049
  //#region src/editor/history-manager/index.ts
1049
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 Me = 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;
@@ -1123,12 +1125,7 @@ var Me = class {
1123
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 Me = 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 Me = 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 Me = class {
1160
1193
  }
1161
1194
  this._isSavingState = !0, console.time("saveState");
1162
1195
  try {
1163
- let e = je({
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
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 } = _e({
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 (de({
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
  }
@@ -1205,7 +1218,11 @@ var Me = class {
1205
1218
  let f = t.getObjects().find((e) => e.id === "montage-area"), p = !1, m = !1;
1206
1219
  f && (this.editor.montageArea = f, n.placeMontageAreaAtCanonicalScenePosition(), p = f.width !== l || f.height !== u, m = s !== t.getWidth() || c !== t.getHeight());
1207
1220
  let h = t.getObjects().find((e) => e.id === "background");
1208
- h ? i.backgroundObject = h : i.removeBackground({ withoutSave: !0 }), f && (r.ensureOverlay(), m ? n.updateCanvas() : p ? (a.calculateAndApplyDefaultZoom(), n.refreshMontageDerivedState()) : (a.updateDefaultZoom(), n.centerViewportToMontageArea(), n.refreshMontageDerivedState(), o.updateBounds())), t.renderAll(), t.fire("editor:history-state-loaded", {
1221
+ h ? i.backgroundObject = h : i.removeBackground({ withoutSave: !0 });
1222
+ let { textManager: g } = this.editor;
1223
+ g && t.getObjects().forEach((e) => {
1224
+ g.commitStandaloneTextScale({ target: e });
1225
+ }), f && (r.ensureOverlay(), m ? n.updateCanvas() : p ? (a.calculateAndApplyDefaultZoom(), n.refreshMontageDerivedState()) : (a.updateDefaultZoom(), n.centerViewportToMontageArea(), n.refreshMontageDerivedState(), o.updateBounds())), t.renderAll(), t.fire("editor:history-state-loaded", {
1209
1226
  fullState: e,
1210
1227
  currentIndex: this.currentIndex,
1211
1228
  totalChangesCount: this.totalChangesCount,
@@ -2270,11 +2287,11 @@ var He = class {
2270
2287
  let { left: r, top: i, width: a, height: o } = n;
2271
2288
  return new p(r + e * a, i + t * o);
2272
2289
  }, Je = ({ object: e }) => {
2273
- 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 = e.type === "Textbox", u = c ? 0 : s, d = r + u, f = i + u, p = {
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 = {
2274
2291
  left: Math.round(t),
2275
2292
  top: Math.round(n)
2276
2293
  };
2277
- l || (d > 0 && (p.scaleX = Math.max(1, Math.round(d * a)) / d), f > 0 && (p.scaleY = Math.max(1, Math.round(f * o)) / f)), e.set(p), e.setCoords();
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();
2278
2295
  }, W = ({ object: e }) => {
2279
2296
  if (!e) return null;
2280
2297
  try {
@@ -2693,46 +2710,46 @@ var Xe = ({ canvas: e, options: t = {}, centerPoint: n, flags: r = {} }) => {
2693
2710
  this.editor = e;
2694
2711
  }
2695
2712
  bringToFront(t, { withoutSave: n } = {}) {
2696
- let { canvas: r, historyManager: i } = this.editor;
2697
- i.suspendHistory();
2698
- let a = t || r.getActiveObject();
2699
- 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) => {
2700
2717
  r.bringObjectToFront(e);
2701
- }) : r.bringObjectToFront(a), r.renderAll(), i.resumeHistory(), n || i.saveState(), r.fire("editor:object-bring-to-front", {
2702
- object: a,
2718
+ }) : r.bringObjectToFront(o), r.renderAll(), i.resumeHistory(), n || i.saveState(), r.fire("editor:object-bring-to-front", {
2719
+ object: o,
2703
2720
  withoutSave: n
2704
2721
  }));
2705
2722
  }
2706
2723
  bringForward(n, { withoutSave: r } = {}) {
2707
- let { canvas: i, historyManager: a } = this.editor;
2708
- a.suspendHistory();
2709
- let o = n || i.getActiveObject();
2710
- o && (o instanceof e ? t._moveSelectionForward(i, o) : i.bringObjectForward(o), i.renderAll(), a.resumeHistory(), r || a.saveState(), i.fire("editor:object-bring-forward", {
2711
- 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,
2712
2729
  withoutSave: r
2713
2730
  }));
2714
2731
  }
2715
2732
  sendToBack(t, { withoutSave: n } = {}) {
2716
- let { canvas: r, montageArea: i, historyManager: a, interactionBlocker: { overlayMask: o }, backgroundManager: { backgroundObject: s } } = this.editor;
2717
- a.suspendHistory();
2718
- let c = t || r.getActiveObject();
2719
- if (c) {
2720
- if (c instanceof e) {
2721
- 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();
2722
2739
  for (let t = e.length - 1; t >= 0; --t) r.sendObjectToBack(e[t]);
2723
- } else r.sendObjectToBack(c);
2724
- 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", {
2725
- 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,
2726
2743
  withoutSave: n
2727
2744
  });
2728
2745
  }
2729
2746
  }
2730
2747
  sendBackwards(n, { withoutSave: r } = {}) {
2731
- let { canvas: i, montageArea: a, historyManager: o, interactionBlocker: { overlayMask: s }, backgroundManager: { backgroundObject: c } } = this.editor;
2732
- o.suspendHistory();
2733
- let l = n || i.getActiveObject();
2734
- 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", {
2735
- 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,
2736
2753
  withoutSave: r
2737
2754
  }));
2738
2755
  }
@@ -4082,14 +4099,15 @@ var dn = ({ group: e }) => {
4082
4099
  subTargetCheck: !0
4083
4100
  });
4084
4101
  }, fn = ({ text: e }) => {
4102
+ let t = !!(e.locked || e.group?.locked);
4085
4103
  e.set({
4086
4104
  hasBorders: !1,
4087
4105
  hasControls: !1,
4088
4106
  evented: !1,
4089
4107
  selectable: !1,
4090
- lockMovementX: !1,
4091
- lockMovementY: !1,
4092
- editable: !0,
4108
+ lockMovementX: t,
4109
+ lockMovementY: t,
4110
+ editable: !t,
4093
4111
  autoExpand: !1,
4094
4112
  shapeNodeType: "text"
4095
4113
  }), e.setCoords();
@@ -4893,15 +4911,21 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
4893
4911
  }
4894
4912
  enterTextEditing({ group: e }) {
4895
4913
  let { text: t } = Y({ group: e });
4896
- t && (this._enterTextEditingInteractionMode({
4897
- group: e,
4898
- text: t
4899
- }), t.set({
4900
- evented: !0,
4901
- selectable: !0,
4902
- lockMovementX: !0,
4903
- lockMovementY: !0
4904
- }), 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
+ }
4905
4929
  }
4906
4930
  _enterTextEditingInteractionMode({ group: e, text: t }) {
4907
4931
  this.editingInteractionState.has(e) || this.editingInteractionState.set(e, {
@@ -5077,7 +5101,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5077
5101
  l !== void 0 && (M = Math.max(1, l)), l === void 0 && C && !w && (M = Math.max(1, x.width));
5078
5102
  let N = Math.max(1, u ?? r.shapeManualBaseHeight ?? S), { shape: P, text: F } = Y({ group: r });
5079
5103
  if (!P || !F) return null;
5080
- let ee = {
5104
+ let I = {
5081
5105
  angle: 0,
5082
5106
  skewX: 0,
5083
5107
  skewY: 0,
@@ -5090,20 +5114,20 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5090
5114
  top: 0,
5091
5115
  originX: "left",
5092
5116
  originY: "top"
5093
- }, I = this._createTextNode({
5117
+ }, ee = this._createTextNode({
5094
5118
  text: F.textCaseRaw ?? F.text ?? "",
5095
5119
  textStyle: this._resolveCurrentTextStyle({ textNode: F }),
5096
5120
  width: Math.max(1, F.width ?? x.width),
5097
5121
  align: D
5098
5122
  });
5099
- I.set(ee), this._applyTextUpdates({
5100
- textNode: I,
5123
+ ee.set(I), this._applyTextUpdates({
5124
+ textNode: ee,
5101
5125
  text: f,
5102
5126
  textStyle: p,
5103
5127
  align: D
5104
5128
  });
5105
5129
  let L = this._resolveShapeLayoutWidth({
5106
- text: I,
5130
+ text: ee,
5107
5131
  currentWidth: x.width,
5108
5132
  manualWidth: M,
5109
5133
  shapeTextAutoExpandEnabled: w,
@@ -5118,7 +5142,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5118
5142
  }), ne = r.getObjects().indexOf(P);
5119
5143
  if (ne < 0) return null;
5120
5144
  let R = () => {
5121
- this._detachShapeGroupAutoLayout({ group: r }), F.set(ee), this._applyTextUpdates({
5145
+ this._detachShapeGroupAutoLayout({ group: r }), F.set(I), this._applyTextUpdates({
5122
5146
  textNode: F,
5123
5147
  text: f,
5124
5148
  textStyle: p,
@@ -5691,6 +5715,18 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5691
5715
  }
5692
5716
  n.add(t), n.setActiveObject(t), n.requestRenderAll();
5693
5717
  }
5718
+ _commitStandaloneTextScaleOnClone({ clonedObject: t }) {
5719
+ let { textManager: n } = this.editor;
5720
+ if (n) {
5721
+ if (t instanceof e) {
5722
+ t.forEachObject((e) => {
5723
+ n.commitStandaloneTextScale({ target: e });
5724
+ }), t.setCoords();
5725
+ return;
5726
+ }
5727
+ n.commitStandaloneTextScale({ target: t });
5728
+ }
5729
+ }
5694
5730
  async _handleImageImport(e) {
5695
5731
  let { canvas: t, errorManager: n } = this.editor, r = !1, i = !1, a = null, o = null, s = new Promise((e, t) => {
5696
5732
  a = (t) => {
@@ -5752,7 +5788,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5752
5788
  left: t.left + 10,
5753
5789
  top: t.top + 10,
5754
5790
  evented: !0
5755
- }), this._addClonedObjectToCanvas(t), n.fire("editor:object-duplicated", {
5791
+ }), this._commitStandaloneTextScaleOnClone({ clonedObject: t }), this._addClonedObjectToCanvas(t), n.fire("editor:object-duplicated", {
5756
5792
  targetObject: r,
5757
5793
  clonedObject: t
5758
5794
  }), !0;
@@ -5826,7 +5862,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5826
5862
  left: n.left + 10,
5827
5863
  top: n.top + 10,
5828
5864
  evented: !0
5829
- }), this._addClonedObjectToCanvas(n), t.fire("editor:object-pasted", {
5865
+ }), this._commitStandaloneTextScaleOnClone({ clonedObject: n }), this._addClonedObjectToCanvas(n), t.fire("editor:object-pasted", {
5830
5866
  fromInternalClipboard: !0,
5831
5867
  clipboardObject: this.clipboard,
5832
5868
  object: n
@@ -5847,9 +5883,9 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5847
5883
  this.editor = e;
5848
5884
  }
5849
5885
  lockObject({ object: e, skipInnerObjects: n, withoutSave: r } = {}) {
5850
- let { canvas: i, historyManager: a } = this.editor, o = e || i.getActiveObject();
5851
- if (!o || o.locked) return;
5852
- 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 = {
5853
5889
  lockMovementX: !0,
5854
5890
  lockMovementY: !0,
5855
5891
  lockRotation: !0,
@@ -5859,19 +5895,19 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5859
5895
  lockSkewingY: !0,
5860
5896
  editable: !1,
5861
5897
  locked: !0
5862
- };
5863
- o.set(s), !n && t._isGroupOrSelection(o) && o.getObjects().forEach((e) => {
5864
- e.set(s);
5865
- }), o instanceof _ && o.isEditing && o.exitEditing(), i.renderAll(), r || a.saveState(), i.fire("editor:object-locked", {
5866
- 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,
5867
5903
  skipInnerObjects: n,
5868
5904
  withoutSave: r
5869
5905
  });
5870
5906
  }
5871
5907
  unlockObject({ object: e, withoutSave: n } = {}) {
5872
- let { canvas: r, historyManager: i } = this.editor, a = e || r.getActiveObject();
5873
- if (!a) return;
5874
- 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 = {
5875
5911
  lockMovementX: !1,
5876
5912
  lockMovementY: !1,
5877
5913
  lockRotation: !1,
@@ -5881,17 +5917,32 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
5881
5917
  lockSkewingY: !1,
5882
5918
  editable: !0,
5883
5919
  locked: !1
5884
- };
5885
- a.set(o), t._isGroupOrSelection(a) && a.getObjects().forEach((e) => {
5886
- e.set(o);
5887
- }), r.renderAll(), n || i.saveState(), r.fire("editor:object-unlocked", {
5888
- 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,
5889
5924
  withoutSave: n
5890
5925
  });
5891
5926
  }
5892
5927
  static _isGroupOrSelection(t) {
5893
5928
  return t instanceof e || t instanceof l;
5894
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
+ }
5895
5946
  }, Zn = class {
5896
5947
  constructor({ editor: e }) {
5897
5948
  this.editor = e;
@@ -6171,24 +6222,26 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6171
6222
  }), [e, ...n];
6172
6223
  }
6173
6224
  deleteSelectedObjects({ objects: t, withoutSave: n = !1, _isRecursiveCall: r = !1 } = {}) {
6174
- let { canvas: i, historyManager: a } = this.editor, o = (t || i.getActiveObjects()).filter((e) => !e.locked);
6175
- 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;
6176
6229
  r || a.suspendHistory();
6177
- let s = [];
6178
- if (o.forEach((t) => {
6230
+ let c = [];
6231
+ if (s.forEach((t) => {
6179
6232
  if (e._isUngroupableGroup(t)) {
6180
6233
  let e = this._handleGroupDeletion(t);
6181
- s.push(...e);
6234
+ c.push(...e);
6182
6235
  return;
6183
6236
  }
6184
- i.remove(t), s.push(t);
6237
+ i.remove(t), c.push(t);
6185
6238
  }), r) return null;
6186
6239
  i.discardActiveObject(), i.renderAll(), a.resumeHistory(), n || a.saveState();
6187
- let c = {
6188
- objects: s,
6240
+ let l = {
6241
+ objects: c,
6189
6242
  withoutSave: n
6190
6243
  };
6191
- return i.fire("editor:objects-deleted", c), c;
6244
+ return i.fire("editor:objects-deleted", l), l;
6192
6245
  }
6193
6246
  }, er = {
6194
6247
  IMAGE_MANAGER: {
@@ -6402,7 +6455,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6402
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();
6403
6456
  }
6404
6457
  initDimensions() {
6405
- super.initDimensions(), this._roundDimensions();
6458
+ super.initDimensions(), this.shouldRoundDimensionsOnInit !== !1 && this._roundDimensions();
6406
6459
  }
6407
6460
  _getLeftOffset() {
6408
6461
  let { width: e } = this._getBackgroundDimensions(), { left: t } = this._getPadding();
@@ -6648,10 +6701,431 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6648
6701
  let s = e[o];
6649
6702
  if (!s) continue;
6650
6703
  let c = { ...s };
6651
- 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;
6652
6709
  }
6653
6710
  if (!(!r || !i)) return n;
6654
- }, 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 }) => {
6655
7129
  let t = e.text ?? "";
6656
7130
  if (!t.length) return [];
6657
7131
  let n = t.split("\n"), r = [], i = 0;
@@ -6663,7 +7137,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6663
7137
  });
6664
7138
  }
6665
7139
  return r;
6666
- }, br = ({ range: e, text: t }) => {
7140
+ }, Fr = ({ range: e, text: t }) => {
6667
7141
  if (!e) return null;
6668
7142
  let n = t.length;
6669
7143
  if (n <= 0) return null;
@@ -6672,8 +7146,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6672
7146
  start: l,
6673
7147
  end: u
6674
7148
  };
6675
- }, xr = ({ textbox: e, range: t }) => {
6676
- let n = yr({ textbox: e });
7149
+ }, Ir = ({ textbox: e, range: t }) => {
7150
+ let n = Pr({ textbox: e });
6677
7151
  if (!n.length) return t;
6678
7152
  let { start: r } = t, { end: i } = t;
6679
7153
  for (let e = 0; e < n.length; e += 1) {
@@ -6686,7 +7160,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6686
7160
  start: r,
6687
7161
  end: i
6688
7162
  };
6689
- }, Sr = ({ textbox: e, range: t }) => {
7163
+ }, Lr = ({ textbox: e, range: t }) => {
6690
7164
  let n = e.text ?? "";
6691
7165
  if (!n.length) return [];
6692
7166
  let { start: r, end: i } = t, a = n.split("\n"), o = [], s = 0;
@@ -6695,7 +7169,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6695
7169
  i > n && r < c && o.push(e), s = c + 1;
6696
7170
  }
6697
7171
  return o;
6698
- }, Cr = ({ textbox: e, range: t }) => {
7172
+ }, Rr = ({ textbox: e, range: t }) => {
6699
7173
  let n = e.text ?? "";
6700
7174
  if (!n.length) return [];
6701
7175
  let { start: r, end: i } = t, a = n.split("\n"), o = [], s = 0;
@@ -6704,63 +7178,31 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6704
7178
  r <= n && i >= c && o.push(e), s = c + 1;
6705
7179
  }
6706
7180
  return o;
6707
- }, wr = ({ previous: e, next: t }) => {
7181
+ }, zr = ({ previous: e, next: t }) => {
6708
7182
  let n = Math.min(e.length, t.length);
6709
7183
  for (let r = 0; r < n; r += 1) if (e[r] !== t[r]) return r;
6710
7184
  return n;
6711
- }, Tr = ({ text: e, charIndex: t }) => {
7185
+ }, Br = ({ text: e, charIndex: t }) => {
6712
7186
  let n = Math.max(0, Math.min(t, e.length)), r = 0;
6713
7187
  for (let t = 0; t < n; t += 1) e[t] === "\n" && (r += 1);
6714
7188
  return r;
6715
- }, Er = ({ text: e, lineIndex: t }) => {
7189
+ }, Vr = ({ text: e, lineIndex: t }) => {
6716
7190
  if (t <= 0) return 0;
6717
7191
  let n = 0;
6718
7192
  for (let r = 0; r < e.length; r += 1) if (e[r] === "\n" && (n += 1, n === t)) return r + 1;
6719
7193
  return e.length;
6720
- }, Dr = ({ textbox: e, text: t }) => {
6721
- let { textLines: n } = e, r = Array.isArray(n) && n.length > 0 ? n.length : Math.max(t.split("\n").length, 1), i = 0;
6722
- for (let t = 0; t < r; t += 1) {
6723
- let n = e.getLineWidth(t);
6724
- n > i && (i = n);
6725
- }
6726
- return i;
6727
- }, Or = ({ textbox: e, montageLeft: t, montageRight: n }) => {
6728
- e.setCoords();
6729
- let r = e.getBoundingRect(!1, !0), i = r.left ?? 0, a = i + (r.width ?? 0), o = n - t;
6730
- if (o > 0 && (r.width ?? 0) >= o - .01) return !1;
6731
- let s = 0;
6732
- return i < t ? s = t - i : a > n && (s = n - a), Math.abs(s) <= .01 ? !1 : (e.set({ left: (e.left ?? 0) + s }), !0);
6733
- }, kr = ({ rawValue: e, calculatedValue: t }) => typeof e == "number" ? e : typeof t == "number" ? t : 0, Ar = ({ stylesList: e }) => {
6734
- let t = e.length;
6735
- if (!t) return !1;
6736
- for (let n = 0; n < t; n += 1) {
6737
- let t = e[n];
6738
- if (!t) continue;
6739
- let { fontFamily: r, fontSize: i, fontWeight: a, fontStyle: o, lineHeight: s, charSpacing: c } = t;
6740
- if (r !== void 0 || i !== void 0 || a !== void 0 || o !== void 0 || s !== void 0 || c !== void 0) return !0;
6741
- }
6742
- return !1;
6743
- }, jr = ({ textbox: e }) => {
6744
- 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({
6745
- rawValue: t,
6746
- calculatedValue: a
6747
- }), c = kr({
6748
- rawValue: n,
6749
- calculatedValue: o
6750
- }), l = Number.isFinite(s) ? Math.round(s) : null, u = Number.isFinite(c) ? Math.round(c) : null, d = {};
6751
- 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;
6752
- }, Mr = class t {
6753
- constructor({ editor: n }) {
6754
- this._handleTextEditingEntered = (e) => {
7194
+ }, Hr = class e {
7195
+ constructor({ editor: t }) {
7196
+ this._handleTextEditingEntered = (t) => {
6755
7197
  this.isTextEditingActive = !0;
6756
- let { target: n } = e;
6757
- if (!t._isTextbox(n)) return;
7198
+ let { target: n } = t;
7199
+ if (!e._isTextbox(n)) return;
6758
7200
  let { canvasManager: r, historyManager: i } = this.editor;
6759
- i.beginAction({ reason: "text-edit" }), !t._isShapeOwnedTextbox(n) && this._ensureEditingPlacementState().set(n, r.getObjectPlacement({ object: n }));
6760
- }, this._handleTextChanged = (e) => {
6761
- let { target: n } = e;
6762
- if (!t._isTextbox(n) || this.lineDefaultsSyncing.has(n)) return;
6763
- 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 });
6764
7206
  if (s) {
6765
7207
  let e = ur({ value: l });
6766
7208
  e !== i && n.set({ text: e }), n.textCaseRaw = l;
@@ -6774,24 +7216,24 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6774
7216
  placement: u,
6775
7217
  shouldAutoExpand: c
6776
7218
  }), this._syncLineFontDefaultsOnTextChanged({ textbox: n });
6777
- }, this._handleTextEditingExited = (e) => {
6778
- let { target: n } = e;
6779
- if (!t._isTextbox(n)) return;
6780
- 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);
6781
7223
  this.editingPlacementState?.delete(n);
6782
7224
  let i = n.text ?? "";
6783
- 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({
6784
7226
  lockMovementX: !1,
6785
7227
  lockMovementY: !1
6786
7228
  }));
6787
7229
  let { historyManager: a } = this.editor;
6788
- a.endAction({ reason: "text-edit" }), a.scheduleSaveState({
7230
+ a.endAction({ reason: "text-edit" }), a.stageCurrentStateForPendingSave({ reason: "text-edit" }), a.scheduleSaveState({
6789
7231
  delayMs: 50,
6790
7232
  reason: "text-edit"
6791
7233
  });
6792
- }, this._handleObjectResizing = (e) => {
6793
- let { target: n, transform: r, e: i } = e;
6794
- 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;
6795
7237
  n.autoExpand = !1;
6796
7238
  let { paddingLeft: a = 0, paddingRight: o = 0 } = n, s = a + o;
6797
7239
  if (s !== 0) {
@@ -6807,173 +7249,25 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6807
7249
  transform: r,
6808
7250
  event: i ?? null
6809
7251
  });
6810
- }, this._handleObjectScaling = (n) => {
6811
- let { target: r, transform: i } = n;
6812
- if (r instanceof e || !t._isTextbox(r) || t._isShapeOwnedTextbox(r) || !i) return;
6813
- let { canvasManager: a } = this.editor;
6814
- r.isScaling = !0;
6815
- 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 = [
6816
- "tl",
6817
- "tr",
6818
- "bl",
6819
- "br"
6820
- ].includes(m) || h === "scale", y = v || _;
6821
- if (!g && !_ && !v) return;
6822
- 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 ? {
6823
- top: Math.max(0, l.top * x),
6824
- right: Math.max(0, l.right * x),
6825
- bottom: Math.max(0, l.bottom * x),
6826
- left: Math.max(0, l.left * x)
6827
- } : l, L = ee ? {
6828
- topLeft: Math.max(0, u.topLeft * x),
6829
- topRight: Math.max(0, u.topRight * x),
6830
- bottomRight: Math.max(0, u.bottomRight * x),
6831
- bottomLeft: Math.max(0, u.bottomLeft * x)
6832
- } : u, te = Object.keys(d).length > 0, ne;
6833
- if (y && te) {
6834
- let e = {};
6835
- Object.entries(d).forEach(([t, n]) => {
6836
- if (!n) return;
6837
- let r = {};
6838
- Object.entries(n).forEach(([e, t]) => {
6839
- if (!t) return;
6840
- let n = { ...t };
6841
- typeof t.fontSize == "number" && (n.fontSize = Math.max(1, t.fontSize * x)), r[e] = n;
6842
- }), Object.keys(r).length && (e[t] = r);
6843
- }), Object.keys(e).length && (ne = e);
6844
- }
6845
- let R;
6846
- y && (R = vr({
6847
- lineFontDefaults: f,
6848
- scale: x
6849
- }));
6850
- let re = a.getObjectPlacement({
6851
- object: r,
6852
- originX: i.originX ?? r.originX,
6853
- originY: i.originY ?? r.originY
6854
- }), z = P ?? p, ie = C !== z, B = Math.abs(w - (N ?? c)) > mr, ae = Math.abs(I.top - T) > .01 || Math.abs(I.right - E) > .01 || Math.abs(I.bottom - D) > .01 || Math.abs(I.left - O) > .01, V = Math.abs(L.topLeft - k) > .01 || Math.abs(L.topRight - A) > .01 || Math.abs(L.bottomRight - j) > .01 || Math.abs(L.bottomLeft - M) > .01;
6855
- if (!ie && !B && !ae && !V) {
6856
- r.set({
6857
- scaleX: 1,
6858
- scaleY: 1
6859
- }), i.scaleX = 1, i.scaleY = 1;
6860
- return;
6861
- }
6862
- g && ie && (r.autoExpand = !1), ne && (r.styles = ne), R && (r.lineFontDefaults = R), r.set({
6863
- width: C,
6864
- fontSize: y ? w : c,
6865
- paddingTop: I.top,
6866
- paddingRight: I.right,
6867
- paddingBottom: I.bottom,
6868
- paddingLeft: I.left,
6869
- radiusTopLeft: L.topLeft,
6870
- radiusTopRight: L.topRight,
6871
- radiusBottomRight: L.bottomRight,
6872
- radiusBottomLeft: L.bottomLeft,
6873
- scaleX: 1,
6874
- scaleY: 1
6875
- });
6876
- let oe = !1;
6877
- if (y && r.autoExpand !== !1) {
6878
- let e = this._getTextboxUnwrappedWidth({ textbox: r });
6879
- e !== null && Math.abs((r.width ?? 0) - e) > .01 && (r.set({ width: e }), r.initDimensions(), oe = !0);
6880
- } else r.initDimensions();
6881
- let se = jr({ textbox: r });
6882
- (se || oe) && (r.dirty = !0), a.applyObjectPlacement({
6883
- object: r,
6884
- placement: re
6885
- });
6886
- let ce = r.width ?? C, le = ce !== z;
6887
- i.scaleX = 1, i.scaleY = 1;
6888
- let { original: H } = i;
6889
- H && (H.scaleX = 1, H.scaleY = 1, H.width = ce, H.height = r.height, H.left = r.left, H.top = r.top), r.setCoords(), this.canvas.requestRenderAll(), o.baseWidth = ce, o.baseFontSize = r.fontSize ?? w, o.baseStyles = JSON.parse(JSON.stringify(r.styles ?? {})), o.baseLineFontDefaults = _r({ lineFontDefaults: r.lineFontDefaults }), o.basePadding = {
6890
- top: I.top,
6891
- right: I.right,
6892
- bottom: I.bottom,
6893
- left: I.left
6894
- }, o.baseRadii = {
6895
- topLeft: L.topLeft,
6896
- topRight: L.topRight,
6897
- bottomRight: L.bottomRight,
6898
- bottomLeft: L.bottomLeft
6899
- }, o.hasWidthChange = le || B || ae || V || oe || se;
6900
- }, this._handleObjectModified = (n) => {
6901
- let { target: r } = n;
6902
- if (r instanceof e) {
6903
- let n = r.getObjects();
6904
- if (!n.some((e) => t._isTextbox(e))) return;
6905
- let { scaleX: i = 1, scaleY: a = 1 } = r;
6906
- if (Math.abs(i - 1) < .01 && Math.abs(a - 1) < .01) return;
6907
- this.canvas.discardActiveObject(), n.forEach((e) => {
6908
- if (t._isTextbox(e)) {
6909
- let t = e.scaleX ?? 1, n = e.scaleY ?? 1, r = (e.fontSize ?? 16) * n, i = (e.width ?? 0) * t, a = n, { paddingTop: o = 0, paddingRight: s = 0, paddingBottom: c = 0, paddingLeft: l = 0, radiusTopLeft: u = 0, radiusTopRight: d = 0, radiusBottomRight: f = 0, radiusBottomLeft: p = 0, styles: m } = e, h = {
6910
- paddingTop: Math.max(0, o * a),
6911
- paddingRight: Math.max(0, s * a),
6912
- paddingBottom: Math.max(0, c * a),
6913
- paddingLeft: Math.max(0, l * a)
6914
- }, g = {
6915
- radiusTopLeft: Math.max(0, u * a),
6916
- radiusTopRight: Math.max(0, d * a),
6917
- radiusBottomRight: Math.max(0, f * a),
6918
- radiusBottomLeft: Math.max(0, p * a)
6919
- }, _ = m;
6920
- m && Object.keys(m).length > 0 && (_ = JSON.parse(JSON.stringify(m)), Object.values(_).forEach((e) => {
6921
- Object.values(e).forEach((e) => {
6922
- typeof e.fontSize == "number" && (e.fontSize = Math.max(1, e.fontSize * a));
6923
- });
6924
- }));
6925
- let v = vr({
6926
- lineFontDefaults: e.lineFontDefaults,
6927
- scale: a
6928
- }), y = {
6929
- fontSize: r,
6930
- width: i,
6931
- scaleX: 1,
6932
- scaleY: 1,
6933
- ...h,
6934
- ...g,
6935
- styles: _
6936
- };
6937
- v && (y.lineFontDefaults = v), e.set(y), jr({ textbox: e });
6938
- }
6939
- 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
6940
7259
  });
6941
- let o = new e(n, { canvas: this.canvas });
6942
- this.canvas.setActiveObject(o), this.canvas.requestRenderAll();
6943
- return;
6944
7260
  }
6945
- if (!t._isTextbox(r) || t._isShapeOwnedTextbox(r)) return;
6946
- r.isScaling = !1;
6947
- let i = this.scalingState.get(r);
6948
- if (this.scalingState.delete(r), !i?.hasWidthChange) return;
6949
- 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 = {
6950
- width: a,
6951
- paddingTop: c,
6952
- paddingRight: l,
6953
- paddingBottom: u,
6954
- paddingLeft: d,
6955
- radiusTopLeft: f,
6956
- radiusTopRight: p,
6957
- radiusBottomRight: m,
6958
- radiusBottomLeft: h
6959
- };
6960
- s || (g.fontSize = o), this.updateText({
6961
- target: r,
6962
- style: g
6963
- }), r.set({
6964
- scaleX: 1,
6965
- scaleY: 1
6966
- }), r.setCoords();
6967
- }, 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();
6968
7262
  }
6969
- 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 } = {}) {
6970
7264
  let { canvasManager: j, historyManager: M } = this.editor, { canvas: N } = this;
6971
7265
  M.suspendHistory();
6972
- let P = i ?? this._getDefaultFontFamily(), F = lr({ width: m }), ee = cr({
7266
+ let P = i ?? this._getDefaultFontFamily(), F = lr({ width: m }), I = cr({
6973
7267
  strokeColor: p,
6974
7268
  width: F
6975
- }), I = {
6976
- id: e,
7269
+ }), ee = {
7270
+ id: t,
6977
7271
  fontFamily: P,
6978
7272
  fontSize: a,
6979
7273
  fontWeight: o ? "bold" : "normal",
@@ -6983,7 +7277,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6983
7277
  linethrough: u,
6984
7278
  textAlign: d,
6985
7279
  fill: f,
6986
- stroke: ee,
7280
+ stroke: I,
6987
7281
  strokeWidth: F,
6988
7282
  strokeUniform: !0,
6989
7283
  opacity: h,
@@ -6998,14 +7292,14 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
6998
7292
  radiusBottomRight: w,
6999
7293
  radiusBottomLeft: T,
7000
7294
  ...E
7001
- }, L = new fr(n, I), te = r !== !1;
7295
+ }, L = new fr(n, ee), te = r !== !1;
7002
7296
  L.autoExpand = te;
7003
7297
  let ne = E.left !== void 0 || E.top !== void 0;
7004
7298
  if (L.textCaseRaw = L.text ?? "", l) {
7005
7299
  let e = ur({ value: L.textCaseRaw });
7006
7300
  e !== L.text && L.set({ text: e });
7007
7301
  }
7008
- jr({ textbox: L }) && (L.dirty = !0);
7302
+ Cr({ textbox: L }) && (L.dirty = !0);
7009
7303
  let R;
7010
7304
  ne && (R = j.resolveObjectPlacement({
7011
7305
  object: L,
@@ -7015,7 +7309,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7015
7309
  originY: E.originY,
7016
7310
  fallbackPoint: j.getMontageAreaSceneCenter()
7017
7311
  }));
7018
- let re = te && t._hasWrappedLinesBeyondExplicitBreaks(L);
7312
+ let re = te && e._hasWrappedLinesBeyondExplicitBreaks(L);
7019
7313
  return (ne || re) && this._normalizeTextboxAfterContentChange({
7020
7314
  textbox: L,
7021
7315
  placement: R,
@@ -7024,14 +7318,14 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7024
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", {
7025
7319
  textbox: L,
7026
7320
  options: {
7027
- ...I,
7321
+ ...ee,
7028
7322
  text: n,
7029
7323
  bold: o,
7030
7324
  italic: s,
7031
7325
  strikethrough: u,
7032
7326
  align: d,
7033
7327
  color: f,
7034
- strokeColor: ee,
7328
+ strokeColor: I,
7035
7329
  strokeWidth: F
7036
7330
  },
7037
7331
  flags: {
@@ -7041,21 +7335,21 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7041
7335
  }
7042
7336
  }), L;
7043
7337
  }
7044
- updateText({ target: e, style: n = {}, withoutSave: r, skipRender: i, selectionRange: a } = {}) {
7045
- let o = this._resolveTextObject(e);
7338
+ updateText({ target: t, style: n = {}, withoutSave: r, skipRender: i, selectionRange: a } = {}) {
7339
+ let o = this._resolveTextObject(t);
7046
7340
  if (!o) return null;
7047
7341
  let { text: s = "" } = o, { historyManager: c } = this.editor, { canvasManager: l } = this.editor, { canvas: u } = this;
7048
7342
  c.suspendHistory();
7049
- 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({
7050
7344
  object: o,
7051
- left: ee,
7052
- top: I,
7345
+ left: I,
7346
+ top: ee,
7053
7347
  originX: L,
7054
7348
  originY: te
7055
- }), z = a === void 0 ? rr({ textbox: o }) : br({
7349
+ }), z = a === void 0 ? rr({ textbox: o }) : Fr({
7056
7350
  text: s,
7057
7351
  range: a
7058
- }), ie = z ? xr({
7352
+ }), ie = z ? Ir({
7059
7353
  textbox: o,
7060
7354
  range: z
7061
7355
  }) : null, B = {}, ae = {}, V = {}, oe, se, ce = ar({
@@ -7108,13 +7402,13 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7108
7402
  range: e
7109
7403
  }));
7110
7404
  }
7111
- let _e = ge && Ar({ stylesList: [
7405
+ let _e = ge && Sr({ stylesList: [
7112
7406
  B,
7113
7407
  ae,
7114
7408
  V
7115
7409
  ] });
7116
7410
  if (ge && (o.dirty = !0), ie && (m !== void 0 || h !== void 0)) {
7117
- let e = Sr({
7411
+ let e = Lr({
7118
7412
  textbox: o,
7119
7413
  range: ie
7120
7414
  }), t = {};
@@ -7125,7 +7419,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7125
7419
  });
7126
7420
  }
7127
7421
  if (z && (S !== void 0 || C !== void 0 || w !== void 0)) {
7128
- let e = Cr({
7422
+ let e = Rr({
7129
7423
  textbox: o,
7130
7424
  range: z
7131
7425
  }), t = {};
@@ -7136,7 +7430,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7136
7430
  });
7137
7431
  }
7138
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);
7139
- let ve = Ar({ stylesList: [
7433
+ let ve = Sr({ stylesList: [
7140
7434
  R,
7141
7435
  B,
7142
7436
  ae,
@@ -7154,7 +7448,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7154
7448
  skipRender: !!i
7155
7449
  }, Te = !!z && Object.keys(B).length > 0, Ee = {
7156
7450
  textbox: o,
7157
- target: e,
7451
+ target: t,
7158
7452
  style: n,
7159
7453
  options: we,
7160
7454
  updates: R,
@@ -7162,7 +7456,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7162
7456
  selectionStyles: Te ? B : void 0
7163
7457
  };
7164
7458
  u.fire("editor:before:text-updated", Ee), i || u.requestRenderAll();
7165
- let De = t._getSnapshot(o);
7459
+ let De = e._getSnapshot(o);
7166
7460
  c.resumeHistory(), r || c.saveState();
7167
7461
  let Oe = {
7168
7462
  ...Ee,
@@ -7174,26 +7468,36 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7174
7468
  stylesFromArray(e, t) {
7175
7469
  return C.stylesFromArray(e, t);
7176
7470
  }
7471
+ exitActiveTextEditing() {
7472
+ let t = this.canvas.getActiveObject();
7473
+ return !e._isTextbox(t) || !t.isEditing ? !1 : (t.exitEditing(), this.canvas.requestRenderAll(), !0);
7474
+ }
7177
7475
  destroy() {
7178
7476
  let { canvas: e } = this;
7179
- 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);
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);
7180
7478
  }
7181
- _resolveTextObject(e) {
7182
- 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;
7183
7487
  let { canvas: n } = this;
7184
- if (!e) {
7185
- let e = n.getActiveObject();
7186
- return t._isTextbox(e) ? e : null;
7488
+ if (!t) {
7489
+ let t = n.getActiveObject();
7490
+ return e._isTextbox(t) ? t : null;
7187
7491
  }
7188
- 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;
7189
7493
  }
7190
7494
  static _isTextbox(e) {
7191
7495
  return !!e && e instanceof _;
7192
7496
  }
7193
- static _isShapeOwnedTextbox(e) {
7194
- if (!t._isTextbox(e)) return !1;
7195
- let n = e.group;
7196
- 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;
7197
7501
  }
7198
7502
  static _hasWrappedLinesBeyondExplicitBreaks(e) {
7199
7503
  let t = typeof e.text == "string" ? e.text : "";
@@ -7208,49 +7512,29 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7208
7512
  clampToMontage: r
7209
7513
  }));
7210
7514
  let a = !1;
7211
- i || (a = jr({ textbox: e }));
7515
+ i || (a = Cr({ textbox: e }));
7212
7516
  let o = !1;
7213
7517
  return !i && t && (this.editor.canvasManager.applyObjectPlacement({
7214
7518
  object: e,
7215
7519
  placement: t
7216
7520
  }), o = !0), (i || a) && (e.dirty = !0), (i || a || o) && e.setCoords(), i || a;
7217
7521
  }
7218
- _getTextboxUnwrappedWidth({ textbox: e }) {
7219
- let t = typeof e.text == "string" ? e.text : "";
7220
- if (!t.length) return null;
7221
- e.initDimensions();
7222
- let n = e, { _textLines: r, _unwrappedTextLines: i, __lineWidths: a, __charBounds: o } = n;
7223
- if (!Array.isArray(i) || i.length === 0) {
7224
- let n = Math.ceil(Dr({
7225
- textbox: e,
7226
- text: t
7227
- }));
7228
- return Number.isFinite(n) ? Math.max(n, e.minWidth ?? 1) : null;
7229
- }
7230
- n._textLines = i, n.__lineWidths = [], n.__charBounds = [];
7231
- try {
7232
- let t = Math.ceil(e.calcTextWidth());
7233
- return Number.isFinite(t) ? Math.max(t, e.minWidth ?? 1) : null;
7234
- } finally {
7235
- n._textLines = r, n.__lineWidths = a ?? [], n.__charBounds = o ?? [];
7236
- }
7237
- }
7238
7522
  _bindEvents() {
7239
7523
  let { canvas: e } = this;
7240
- 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);
7241
7525
  }
7242
7526
  _syncLineFontDefaultsOnTextChanged({ textbox: e }) {
7243
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;
7244
7528
  if (h !== 0 && n && Object.keys(n).length) {
7245
- let e = wr({
7529
+ let e = zr({
7246
7530
  previous: d,
7247
7531
  next: u
7248
- }), t = Tr({
7532
+ }), t = Br({
7249
7533
  text: d,
7250
7534
  charIndex: e
7251
7535
  });
7252
7536
  if (h > 0) {
7253
- let r = Er({
7537
+ let r = Vr({
7254
7538
  text: d,
7255
7539
  lineIndex: t
7256
7540
  }), i = t + 1;
@@ -7331,16 +7615,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7331
7615
  if (!Number.isFinite(f) || f <= 0) return !1;
7332
7616
  let p = a.split("\n").length, m = !1;
7333
7617
  Math.abs((e.width ?? 0) - f) > .01 && (e.set({ width: f }), m = !0), e.initDimensions();
7334
- 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({
7335
7619
  textbox: e,
7336
7620
  text: a
7337
7621
  })), v = Math.min(e.minWidth ?? 1, f), y = Math.min(f, Math.max(_, v));
7338
- 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({
7339
7623
  object: e,
7340
7624
  placement: t
7341
7625
  });
7342
7626
  let b = !1;
7343
- return n && (b = Or({
7627
+ return n && (b = br({
7344
7628
  textbox: e,
7345
7629
  montageLeft: o,
7346
7630
  montageRight: o + s
@@ -7349,32 +7633,6 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7349
7633
  _ensureEditingPlacementState() {
7350
7634
  return this.editingPlacementState ||= /* @__PURE__ */ new WeakMap(), this.editingPlacementState;
7351
7635
  }
7352
- _ensureScalingState(e) {
7353
- let t = this.scalingState.get(e);
7354
- if (!t) {
7355
- let n = e.width ?? e.calcTextWidth(), r = e.fontSize ?? 16, { styles: i = {} } = e, { lineFontDefaults: a } = e, { paddingTop: o = 0, paddingRight: s = 0, paddingBottom: c = 0, paddingLeft: l = 0 } = e, { radiusTopLeft: u = 0, radiusTopRight: d = 0, radiusBottomRight: f = 0, radiusBottomLeft: p = 0 } = e;
7356
- t = {
7357
- baseWidth: n,
7358
- baseFontSize: r,
7359
- basePadding: {
7360
- top: o,
7361
- right: s,
7362
- bottom: c,
7363
- left: l
7364
- },
7365
- baseRadii: {
7366
- topLeft: u,
7367
- topRight: d,
7368
- bottomRight: f,
7369
- bottomLeft: p
7370
- },
7371
- baseStyles: JSON.parse(JSON.stringify(i)),
7372
- baseLineFontDefaults: _r({ lineFontDefaults: a }),
7373
- hasWidthChange: !1
7374
- }, this.scalingState.set(e, t);
7375
- }
7376
- return t;
7377
- }
7378
7636
  static _getSnapshot(e) {
7379
7637
  let t = ({ snapshot: e, entries: t }) => {
7380
7638
  Object.entries(t).forEach(([t, n]) => {
@@ -7424,7 +7682,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7424
7682
  _getDefaultFontFamily() {
7425
7683
  return this.fonts[0]?.family ?? "Arial";
7426
7684
  }
7427
- }, 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) => {
7428
7686
  if (!e || typeof e != "object") return null;
7429
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) => ({
7430
7688
  color: typeof e.color == "string" ? e.color : "#000000",
@@ -7435,7 +7693,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7435
7693
  let { x1: e, y1: t, x2: r, y2: i } = n;
7436
7694
  if (typeof e == "number" && typeof t == "number" && typeof r == "number" && typeof i == "number") return {
7437
7695
  type: "linear",
7438
- angle: Nr({
7696
+ angle: Ur({
7439
7697
  x1: e,
7440
7698
  y1: t,
7441
7699
  x2: r,
@@ -7463,7 +7721,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7463
7721
  };
7464
7722
  }
7465
7723
  return null;
7466
- }, Fr = "_templateAnchorX", Ir = "_templateAnchorY", Lr = class t {
7724
+ }, Gr = "_templateAnchorX", Kr = "_templateAnchorY", qr = class t {
7467
7725
  constructor({ editor: e }) {
7468
7726
  this.editor = e;
7469
7727
  }
@@ -7546,7 +7804,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7546
7804
  baseWidth: f.baseWidth,
7547
7805
  baseHeight: f.baseHeight,
7548
7806
  useRelativePositions: m
7549
- }), Je({ object: e }), e.set({
7807
+ }), this.editor.textManager?.commitStandaloneTextScale({ target: e }), Je({ object: e }), e.set({
7550
7808
  id: `${e.type}-${D()}`,
7551
7809
  evented: !0
7552
7810
  }), n.add(e), e));
@@ -7716,8 +7974,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7716
7974
  baseHeight: a,
7717
7975
  scale: n,
7718
7976
  useRelativePositions: o,
7719
- anchorX: t._resolveAnchor(s, Fr),
7720
- anchorY: t._resolveAnchor(s, Ir)
7977
+ anchorX: t._resolveAnchor(s, Gr),
7978
+ anchorY: t._resolveAnchor(s, Kr)
7721
7979
  })
7722
7980
  }), h = f * n, g = p * n, _ = e.originX ?? "center", v = e.originY ?? "center";
7723
7981
  e.set({
@@ -7731,7 +7989,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7731
7989
  originX: _,
7732
7990
  originY: v
7733
7991
  }
7734
- }), delete s[Fr], delete s[Ir];
7992
+ }), delete s[Gr], delete s[Kr];
7735
7993
  }
7736
7994
  static _getPositioningBounds({ bounds: e, baseWidth: n, baseHeight: r, scale: i, useRelativePositions: a, anchorX: o, anchorY: s }) {
7737
7995
  if (!a) return e;
@@ -7795,7 +8053,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7795
8053
  });
7796
8054
  if (!i || !s || !o) return;
7797
8055
  e.setCoords();
7798
- 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;
7799
8057
  e.set("width", i), e.initDimensions();
7800
8058
  let g = t._getLongestLineWidth({
7801
8059
  textbox: e,
@@ -7824,10 +8082,10 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7824
8082
  x: (p.left - o) / d,
7825
8083
  y: (p.top - s) / f
7826
8084
  }, h = (u.left - o) / d, g = (u.top - s) / f, _ = h + u.width / d, v = g + u.height / f;
7827
- return a[Fr] = t._detectAnchor({
8085
+ return a[Gr] = t._detectAnchor({
7828
8086
  start: h,
7829
8087
  end: _
7830
- }), a[Ir] = t._detectAnchor({
8088
+ }), a[Kr] = t._detectAnchor({
7831
8089
  start: g,
7832
8090
  end: v
7833
8091
  }), a.left = m.x, a.top = m.y, a;
@@ -7852,7 +8110,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7852
8110
  withoutSave: !0
7853
8111
  }), !0;
7854
8112
  if (a === "gradient") {
7855
- let e = Pr(r);
8113
+ let e = Wr(r);
7856
8114
  if (e) return n.setGradientBackground({
7857
8115
  gradient: e,
7858
8116
  customData: o,
@@ -7909,29 +8167,29 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7909
8167
  enlivenObjectEnlivables(e) {
7910
8168
  return C.enlivenObjectEnlivables(e);
7911
8169
  }
7912
- }, Rr = "#3D8BF4", zr = .5, Br = ({ distance: e }) => Number.isFinite(e) ? Math.round(Math.max(0, e)) : 0, Vr = ({ firstDistance: e, secondDistance: t }) => {
7913
- 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 });
7914
8172
  return {
7915
8173
  firstDisplayDistance: n,
7916
8174
  secondDisplayDistance: r,
7917
8175
  displayDistanceDiff: Math.abs(n - r),
7918
8176
  commonDisplayDistance: Math.max(n, r)
7919
8177
  };
7920
- }, 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 }) => {
7921
8179
  let t = Math.abs(e).toString(), n = t.indexOf(".");
7922
8180
  return n === -1 ? 0 : t.slice(n + 1).length;
7923
- }, Wr = ({ value: e, step: t }) => {
8181
+ }, ei = ({ value: e, step: t }) => {
7924
8182
  if (t === 0) return e;
7925
- let n = Ur({ step: t }), r = Math.round(e / t) * t;
8183
+ let n = $r({ step: t }), r = Math.round(e / t) * t;
7926
8184
  return Number(r.toFixed(n));
7927
- }, Gr = ({ value: e, step: t }) => {
8185
+ }, ti = ({ value: e, step: t }) => {
7928
8186
  if (t === 0) return !0;
7929
- let n = Wr({
8187
+ let n = ei({
7930
8188
  value: e,
7931
8189
  step: t
7932
- }), r = 10 ** -(Ur({ step: t }) + 4);
8190
+ }), r = 10 ** -($r({ step: t }) + 4);
7933
8191
  return Math.abs(n - e) <= r;
7934
- }, Kr = ({ bounds: e, axis: t }) => {
8192
+ }, ni = ({ bounds: e, axis: t }) => {
7935
8193
  let { left: n = 0, right: r = 0, top: i = 0, bottom: a = 0 } = e;
7936
8194
  return t === "vertical" ? {
7937
8195
  start: i,
@@ -7940,7 +8198,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7940
8198
  start: n,
7941
8199
  end: r
7942
8200
  };
7943
- }, qr = ({ items: e, axis: t }) => {
8201
+ }, ri = ({ items: e, axis: t }) => {
7944
8202
  for (let n = 1; n < e.length; n += 1) {
7945
8203
  let r = e[n], { bounds: i } = r, a = i[t], o = n - 1;
7946
8204
  for (; o >= 0;) {
@@ -7950,10 +8208,10 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7950
8208
  }
7951
8209
  e[o + 1] = r;
7952
8210
  }
7953
- }, Jr = ({ items: e, index: t, axis: n, direction: r }) => {
8211
+ }, ii = ({ items: e, index: t, axis: n, direction: r }) => {
7954
8212
  let i = e[t];
7955
8213
  if (!i) return null;
7956
- let { bounds: a } = i, { start: o, end: s } = Kr({
8214
+ let { bounds: a } = i, { start: o, end: s } = ni({
7957
8215
  bounds: a,
7958
8216
  axis: n
7959
8217
  });
@@ -7961,7 +8219,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7961
8219
  for (let r = t - 1; r >= 0; --r) {
7962
8220
  let t = e[r];
7963
8221
  if (!t) continue;
7964
- let { bounds: i } = t, { end: a } = Kr({
8222
+ let { bounds: i } = t, { end: a } = ni({
7965
8223
  bounds: i,
7966
8224
  axis: n
7967
8225
  });
@@ -7972,26 +8230,26 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
7972
8230
  for (let r = t + 1; r < e.length; r += 1) {
7973
8231
  let t = e[r];
7974
8232
  if (!t) continue;
7975
- let { bounds: i } = t, { start: a } = Kr({
8233
+ let { bounds: i } = t, { start: a } = ni({
7976
8234
  bounds: i,
7977
8235
  axis: n
7978
8236
  });
7979
8237
  if (a - s >= 0) return r;
7980
8238
  }
7981
8239
  return null;
7982
- }, Yr = ({ items: e }) => {
8240
+ }, ai = ({ items: e }) => {
7983
8241
  for (let t = 0; t < e.length; t += 1) {
7984
8242
  let { isActive: n } = e[t];
7985
8243
  if (n) return t;
7986
8244
  }
7987
8245
  return -1;
7988
- }, Xr = ({ patternAxis: e, activeRangeStart: t, activeRangeEnd: n, tolerance: r = 0 }) => {
8246
+ }, oi = ({ patternAxis: e, activeRangeStart: t, activeRangeEnd: n, tolerance: r = 0 }) => {
7989
8247
  let i = Math.min(t, n), a = Math.max(t, n);
7990
8248
  return e >= i - r && e <= a + r;
7991
- }, 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 }) => {
7992
8250
  let { delta: n, guide: { distance: r } } = e, { delta: i, guide: { distance: a } } = t;
7993
8251
  return n === i && r === a;
7994
- }, $r = ({ options: e }) => {
8252
+ }, li = ({ options: e }) => {
7995
8253
  let t = e[0];
7996
8254
  for (let n = 1; n < e.length; n += 1) {
7997
8255
  let r = e[n];
@@ -8002,11 +8260,11 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8002
8260
  r.diff === t.diff && Math.abs(r.delta) < Math.abs(t.delta) && (t = r);
8003
8261
  }
8004
8262
  return t;
8005
- }, ei = ({ currentOption: e, nextOption: t }) => {
8263
+ }, ui = ({ currentOption: e, nextOption: t }) => {
8006
8264
  if (!e) return !0;
8007
8265
  let { contextDistance: n, diff: r, delta: i } = e, { contextDistance: a, diff: o, delta: s } = t;
8008
8266
  return a < n ? !0 : a > n ? !1 : o < r ? !0 : o > r ? !1 : Math.abs(s) < Math.abs(i);
8009
- }, ti = ({ options: e }) => {
8267
+ }, di = ({ options: e }) => {
8010
8268
  let t = [], n = null, r = null;
8011
8269
  for (let i of e) {
8012
8270
  let { kind: e, side: a } = i;
@@ -8014,18 +8272,18 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8014
8272
  t.push(i);
8015
8273
  continue;
8016
8274
  }
8017
- a === "before" && ei({
8275
+ a === "before" && ui({
8018
8276
  currentOption: n,
8019
8277
  nextOption: i
8020
- }) && (n = i), a === "after" && ei({
8278
+ }) && (n = i), a === "after" && ui({
8021
8279
  currentOption: r,
8022
8280
  nextOption: i
8023
8281
  }) && (r = i);
8024
8282
  }
8025
8283
  return n && t.push(n), r && t.push(r), t;
8026
- }, ni = ({ options: e, side: t, baseOption: n }) => {
8284
+ }, fi = ({ options: e, side: t, baseOption: n }) => {
8027
8285
  let r = null;
8028
- for (let i of e) if (i.side === t && Qr({
8286
+ for (let i of e) if (i.side === t && ci({
8029
8287
  baseOption: n,
8030
8288
  candidateOption: i
8031
8289
  })) {
@@ -8036,63 +8294,63 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8036
8294
  !r || i.diff !== r.diff || Math.abs(i.delta) < Math.abs(r.delta) && (r = i);
8037
8295
  }
8038
8296
  return r;
8039
- }, ri = ({ option: e }) => {
8297
+ }, pi = ({ option: e }) => {
8040
8298
  let { side: t, kind: n, guide: { distance: r } } = e;
8041
8299
  return {
8042
8300
  side: t,
8043
8301
  kind: n,
8044
8302
  distance: r
8045
8303
  };
8046
- }, ii = ({ option: e, context: t }) => {
8304
+ }, mi = ({ option: e, context: t }) => {
8047
8305
  let { side: n, kind: r, distance: i } = t, { side: a, kind: o, guide: { distance: s } } = e;
8048
8306
  return n !== a || r !== o ? !1 : Math.abs(s - i) <= 1;
8049
- }, ai = ({ options: e, context: t }) => {
8307
+ }, hi = ({ options: e, context: t }) => {
8050
8308
  if (!t) return null;
8051
- for (let n of e) if (ii({
8309
+ for (let n of e) if (mi({
8052
8310
  option: n,
8053
8311
  context: t
8054
8312
  })) return n;
8055
8313
  return null;
8056
- }, oi = ({ options: e, bestOption: t, previousContext: n, switchDistance: r = 0 }) => {
8057
- let i = ai({
8314
+ }, gi = ({ options: e, bestOption: t, previousContext: n, switchDistance: r = 0 }) => {
8315
+ let i = hi({
8058
8316
  options: e,
8059
8317
  context: n
8060
8318
  });
8061
8319
  if (!i) return t;
8062
8320
  let a = Math.max(0, r);
8063
8321
  return a === 0 || Math.abs(t.delta - i.delta) >= a ? t : i;
8064
- }, si = ({ guides: e, seenGuideKeys: t, guide: n }) => {
8322
+ }, _i = ({ guides: e, seenGuideKeys: t, guide: n }) => {
8065
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}`;
8066
8324
  t.has(u) || (t.add(u), e.push(n));
8067
- }, ci = ({ options: e, previousContext: t = null, switchDistance: n = 0 }) => {
8325
+ }, vi = ({ options: e, previousContext: t = null, switchDistance: n = 0 }) => {
8068
8326
  if (!e.length) return {
8069
8327
  delta: 0,
8070
8328
  guides: [],
8071
8329
  context: null
8072
8330
  };
8073
- let r = ti({ options: e }), i = [];
8331
+ let r = di({ options: e }), i = [];
8074
8332
  for (let e of r) e.kind === "reference" && i.push(e);
8075
- let a = i.length > 0, o = a ? i : r, s = oi({
8333
+ let a = i.length > 0, o = a ? i : r, s = gi({
8076
8334
  options: o,
8077
- bestOption: $r({ options: o }),
8335
+ bestOption: li({ options: o }),
8078
8336
  previousContext: t,
8079
8337
  switchDistance: n
8080
- }), c = ni({
8338
+ }), c = fi({
8081
8339
  options: o,
8082
8340
  side: "before",
8083
8341
  baseOption: s
8084
- }), l = ni({
8342
+ }), l = fi({
8085
8343
  options: o,
8086
8344
  side: "after",
8087
8345
  baseOption: s
8088
- }), u = ni({
8346
+ }), u = fi({
8089
8347
  options: a ? r : o,
8090
8348
  side: "center",
8091
8349
  baseOption: s
8092
8350
  }), d = [];
8093
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);
8094
8352
  let f = [], p = /* @__PURE__ */ new Set();
8095
- for (let e of d) si({
8353
+ for (let e of d) _i({
8096
8354
  guides: f,
8097
8355
  seenGuideKeys: p,
8098
8356
  guide: e.guide
@@ -8100,15 +8358,15 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8100
8358
  return {
8101
8359
  delta: s.delta,
8102
8360
  guides: f,
8103
- context: ri({ option: s })
8361
+ context: pi({ option: s })
8104
8362
  };
8105
- }, li = ({ activeStart: e, activeEnd: t, targetGap: n, beforeEdge: r, afterEdge: i, threshold: a, step: o }) => {
8106
- 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({
8107
8365
  value: s,
8108
8366
  step: o
8109
8367
  }), l = Math.max(1, Math.ceil(a / Math.max(o, 1))), u = null;
8110
8368
  for (let d = -l; d <= l; d += 1) {
8111
- 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({
8112
8370
  firstDistance: m,
8113
8371
  secondDistance: h
8114
8372
  });
@@ -8123,13 +8381,13 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8123
8381
  });
8124
8382
  }
8125
8383
  return u;
8126
- }, ui = ({ currentGap: e, referenceGap: t }) => {
8127
- let { secondDisplayDistance: n, displayDistanceDiff: r } = Vr({
8384
+ }, bi = ({ currentGap: e, referenceGap: t }) => {
8385
+ let { secondDisplayDistance: n, displayDistanceDiff: r } = Zr({
8128
8386
  firstDistance: e,
8129
8387
  secondDistance: t
8130
8388
  });
8131
8389
  return r > 1 ? null : n;
8132
- }, di = ({ anchors: e, positions: t, threshold: n }) => {
8390
+ }, xi = ({ anchors: e, positions: t, threshold: n }) => {
8133
8391
  let r = 0, i = n + 1, a = null;
8134
8392
  for (let o of t) for (let t of e) {
8135
8393
  let e = Math.abs(t - o);
@@ -8139,8 +8397,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8139
8397
  delta: r,
8140
8398
  guidePosition: a
8141
8399
  };
8142
- }, fi = ({ activeBounds: e, threshold: t, anchors: n }) => {
8143
- 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({
8144
8402
  anchors: n.vertical,
8145
8403
  positions: [
8146
8404
  r,
@@ -8148,7 +8406,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8148
8406
  i
8149
8407
  ],
8150
8408
  threshold: t
8151
- }), u = di({
8409
+ }), u = xi({
8152
8410
  anchors: n.horizontal,
8153
8411
  positions: [
8154
8412
  o,
@@ -8168,11 +8426,11 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8168
8426
  deltaY: u.delta,
8169
8427
  guides: d
8170
8428
  };
8171
- }, 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 }) => {
8172
8430
  let { centerX: o, top: s, bottom: c, left: l, right: u } = e, d = [];
8173
8431
  for (let e of t) {
8174
8432
  let { left: t, right: n } = e;
8175
- Hr({
8433
+ Qr({
8176
8434
  firstStart: t,
8177
8435
  firstEnd: n,
8178
8436
  secondStart: l,
@@ -8192,22 +8450,22 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8192
8450
  f.push({
8193
8451
  bounds: e,
8194
8452
  isActive: !0
8195
- }), qr({
8453
+ }), ri({
8196
8454
  items: f,
8197
8455
  axis: "top"
8198
8456
  });
8199
- let p = Yr({ items: f });
8457
+ let p = ai({ items: f });
8200
8458
  if (p === -1) return {
8201
8459
  delta: 0,
8202
8460
  guides: [],
8203
8461
  context: null
8204
8462
  };
8205
- let m = [], h = c - s, g = Jr({
8463
+ let m = [], h = c - s, g = ii({
8206
8464
  items: f,
8207
8465
  index: p,
8208
8466
  axis: "vertical",
8209
8467
  direction: "prev"
8210
- }), _ = Jr({
8468
+ }), _ = ii({
8211
8469
  items: f,
8212
8470
  index: p,
8213
8471
  axis: "vertical",
@@ -8216,19 +8474,19 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8216
8474
  if (v && y) {
8217
8475
  let { bounds: e } = v, { bounds: t } = y, { bottom: r } = e, { top: i } = t, a = i - r - h;
8218
8476
  if (a >= 0) {
8219
- let e = Wr({
8477
+ let e = ei({
8220
8478
  value: a / 2,
8221
8479
  step: 1
8222
8480
  }), t = s - r, l = i - c, u = Math.abs(t - e), d = Math.abs(l - e);
8223
8481
  if (Math.max(u, d) <= n) {
8224
- let t = li({
8482
+ let t = yi({
8225
8483
  activeStart: s,
8226
8484
  activeEnd: c,
8227
8485
  targetGap: e,
8228
8486
  beforeEdge: r,
8229
8487
  afterEdge: i,
8230
8488
  threshold: n,
8231
- step: zr
8489
+ step: Yr
8232
8490
  });
8233
8491
  if (t) {
8234
8492
  let { delta: e, distance: n, diff: i, activeStart: a, activeEnd: s } = t, c = {
@@ -8265,16 +8523,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8265
8523
  }
8266
8524
  for (let e of r) {
8267
8525
  let { axis: t, start: r, end: i, distance: a } = e;
8268
- if (!Gr({
8526
+ if (!ti({
8269
8527
  value: a,
8270
8528
  step: .5
8271
- }) || !Xr({
8529
+ }) || !oi({
8272
8530
  patternAxis: t,
8273
8531
  activeRangeStart: l,
8274
8532
  activeRangeEnd: u,
8275
8533
  tolerance: n
8276
8534
  })) continue;
8277
- let d = Zr({
8535
+ let d = si({
8278
8536
  patternStart: r,
8279
8537
  patternEnd: i,
8280
8538
  activeStart: s,
@@ -8282,12 +8540,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8282
8540
  });
8283
8541
  if (d) {
8284
8542
  if (b !== null && S && d === "before" && Math.abs(b - a) <= n) {
8285
- let e = Wr({
8543
+ let e = ei({
8286
8544
  value: a - b,
8287
8545
  step: 1
8288
8546
  }), t = s + e, { bottom: c } = S, l = t - c, u = Math.abs(l - a);
8289
8547
  if (u > n) continue;
8290
- let d = ui({
8548
+ let d = bi({
8291
8549
  currentGap: l,
8292
8550
  referenceGap: a
8293
8551
  });
@@ -8311,12 +8569,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8311
8569
  });
8312
8570
  }
8313
8571
  if (x !== null && C && d === "after" && Math.abs(x - a) <= n) {
8314
- let e = Wr({
8572
+ let e = ei({
8315
8573
  value: x - a,
8316
8574
  step: 1
8317
8575
  }), t = c + e, { top: s } = C, l = s - t, u = Math.abs(l - a);
8318
8576
  if (u > n) continue;
8319
- let d = ui({
8577
+ let d = bi({
8320
8578
  currentGap: l,
8321
8579
  referenceGap: a
8322
8580
  });
@@ -8341,16 +8599,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8341
8599
  }
8342
8600
  }
8343
8601
  }
8344
- return ci({
8602
+ return vi({
8345
8603
  options: m,
8346
8604
  previousContext: i,
8347
8605
  switchDistance: a
8348
8606
  });
8349
- }, 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 }) => {
8350
8608
  let { centerY: o, left: s, right: c, top: l, bottom: u } = e, d = [];
8351
8609
  for (let e of t) {
8352
8610
  let { top: t, bottom: n } = e;
8353
- Hr({
8611
+ Qr({
8354
8612
  firstStart: t,
8355
8613
  firstEnd: n,
8356
8614
  secondStart: l,
@@ -8370,22 +8628,22 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8370
8628
  f.push({
8371
8629
  bounds: e,
8372
8630
  isActive: !0
8373
- }), qr({
8631
+ }), ri({
8374
8632
  items: f,
8375
8633
  axis: "left"
8376
8634
  });
8377
- let p = Yr({ items: f });
8635
+ let p = ai({ items: f });
8378
8636
  if (p === -1) return {
8379
8637
  delta: 0,
8380
8638
  guides: [],
8381
8639
  context: null
8382
8640
  };
8383
- let m = [], h = c - s, g = Jr({
8641
+ let m = [], h = c - s, g = ii({
8384
8642
  items: f,
8385
8643
  index: p,
8386
8644
  axis: "horizontal",
8387
8645
  direction: "prev"
8388
- }), _ = Jr({
8646
+ }), _ = ii({
8389
8647
  items: f,
8390
8648
  index: p,
8391
8649
  axis: "horizontal",
@@ -8394,19 +8652,19 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8394
8652
  if (v && y) {
8395
8653
  let { bounds: e } = v, { bounds: t } = y, { right: r } = e, { left: i } = t, a = i - r - h;
8396
8654
  if (a >= 0) {
8397
- let e = Wr({
8655
+ let e = ei({
8398
8656
  value: a / 2,
8399
8657
  step: 1
8400
8658
  }), t = s - r, l = i - c, u = Math.abs(t - e), d = Math.abs(l - e);
8401
8659
  if (Math.max(u, d) <= n) {
8402
- let t = li({
8660
+ let t = yi({
8403
8661
  activeStart: s,
8404
8662
  activeEnd: c,
8405
8663
  targetGap: e,
8406
8664
  beforeEdge: r,
8407
8665
  afterEdge: i,
8408
8666
  threshold: n,
8409
- step: zr
8667
+ step: Yr
8410
8668
  });
8411
8669
  if (t) {
8412
8670
  let { delta: e, distance: n, diff: i, activeStart: a, activeEnd: s } = t, c = {
@@ -8443,16 +8701,16 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8443
8701
  }
8444
8702
  for (let e of r) {
8445
8703
  let { axis: t, start: r, end: i, distance: a } = e;
8446
- if (!Gr({
8704
+ if (!ti({
8447
8705
  value: a,
8448
8706
  step: .5
8449
- }) || !Xr({
8707
+ }) || !oi({
8450
8708
  patternAxis: t,
8451
8709
  activeRangeStart: l,
8452
8710
  activeRangeEnd: u,
8453
8711
  tolerance: n
8454
8712
  })) continue;
8455
- let d = Zr({
8713
+ let d = si({
8456
8714
  patternStart: r,
8457
8715
  patternEnd: i,
8458
8716
  activeStart: s,
@@ -8460,12 +8718,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8460
8718
  });
8461
8719
  if (d) {
8462
8720
  if (b !== null && S && d === "before" && Math.abs(b - a) <= n) {
8463
- let e = Wr({
8721
+ let e = ei({
8464
8722
  value: a - b,
8465
8723
  step: 1
8466
8724
  }), t = s + e, { right: c } = S, l = t - c, u = Math.abs(l - a);
8467
8725
  if (u > n) continue;
8468
- let d = ui({
8726
+ let d = bi({
8469
8727
  currentGap: l,
8470
8728
  referenceGap: a
8471
8729
  });
@@ -8489,12 +8747,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8489
8747
  });
8490
8748
  }
8491
8749
  if (x !== null && C && d === "after" && Math.abs(x - a) <= n) {
8492
- let e = Wr({
8750
+ let e = ei({
8493
8751
  value: x - a,
8494
8752
  step: 1
8495
8753
  }), t = c + e, { left: s } = C, l = s - t, u = Math.abs(l - a);
8496
8754
  if (u > n) continue;
8497
- let d = ui({
8755
+ let d = bi({
8498
8756
  currentGap: l,
8499
8757
  referenceGap: a
8500
8758
  });
@@ -8519,20 +8777,20 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8519
8777
  }
8520
8778
  }
8521
8779
  }
8522
- return ci({
8780
+ return vi({
8523
8781
  options: m,
8524
8782
  previousContext: i,
8525
8783
  switchDistance: a
8526
8784
  });
8527
- }, hi = ({ activeBounds: e, candidates: t, threshold: n, spacingPatterns: r, previousContexts: i, switchDistance: a = 0 }) => {
8528
- 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({
8529
8787
  activeBounds: e,
8530
8788
  candidates: t,
8531
8789
  threshold: n,
8532
8790
  patterns: r.vertical,
8533
8791
  previousContext: o,
8534
8792
  switchDistance: a
8535
- }), l = mi({
8793
+ }), l = wi({
8536
8794
  activeBounds: e,
8537
8795
  candidates: t,
8538
8796
  threshold: n,
@@ -8551,14 +8809,14 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8551
8809
  horizontal: l.context
8552
8810
  }
8553
8811
  };
8554
- }, 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 }) => {
8555
8813
  let o = Math.min(a, r / 2, i / 2);
8556
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();
8557
- }, _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 }) => {
8558
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;
8559
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";
8560
8818
  let S = e.measureText(a).width + _ * 2, C = g + _ * 2, w = b - S / 2, T = x - C / 2;
8561
- e.beginPath(), gi({
8819
+ e.beginPath(), Ei({
8562
8820
  context: e,
8563
8821
  x: w,
8564
8822
  y: T,
@@ -8566,11 +8824,11 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8566
8824
  height: C,
8567
8825
  radius: v
8568
8826
  }), e.fill(), e.fillStyle = c, e.fillText(a, b, x), e.restore();
8569
- }, vi = ({ context: e, guide: t, zoom: n }) => {
8570
- 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();
8571
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();
8572
- let d = Rr;
8573
- _i({
8830
+ let d = Jr;
8831
+ Di({
8574
8832
  context: e,
8575
8833
  type: r,
8576
8834
  axis: i,
@@ -8580,7 +8838,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8580
8838
  zoom: n,
8581
8839
  color: d,
8582
8840
  lineWidth: 1
8583
- }), _i({
8841
+ }), Di({
8584
8842
  context: e,
8585
8843
  type: r,
8586
8844
  axis: i,
@@ -8591,10 +8849,10 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8591
8849
  color: d,
8592
8850
  lineWidth: 1
8593
8851
  });
8594
- }, yi = ({ anchors: e, bounds: t }) => {
8852
+ }, ki = ({ anchors: e, bounds: t }) => {
8595
8853
  let { left: n, right: r, centerX: i, top: a, bottom: o, centerY: s } = t;
8596
8854
  e.vertical.push(n, i, r), e.horizontal.push(a, s, o);
8597
- }, bi = ({ bounds: e, type: t, primaryStart: n, primaryEnd: r }) => {
8855
+ }, Ai = ({ bounds: e, type: t, primaryStart: n, primaryEnd: r }) => {
8598
8856
  let i = [], a = n === "top" ? "left" : "top", o = r === "bottom" ? "right" : "bottom", s = [...e].sort((e, t) => e[n] - t[n]);
8599
8857
  for (let e = 0; e < s.length; e += 1) {
8600
8858
  let c = s[e], l = null, u = Infinity;
@@ -8615,35 +8873,35 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8615
8873
  });
8616
8874
  }
8617
8875
  return i;
8618
- }, xi = ({ bounds: e }) => ({
8619
- vertical: bi({
8876
+ }, ji = ({ bounds: e }) => ({
8877
+ vertical: Ai({
8620
8878
  bounds: e,
8621
8879
  axis: "centerX",
8622
8880
  type: "vertical",
8623
8881
  primaryStart: "top",
8624
8882
  primaryEnd: "bottom"
8625
8883
  }),
8626
- horizontal: bi({
8884
+ horizontal: Ai({
8627
8885
  bounds: e,
8628
8886
  axis: "centerY",
8629
8887
  type: "horizontal",
8630
8888
  primaryStart: "left",
8631
8889
  primaryEnd: "right"
8632
8890
  })
8633
- }), Si = [
8891
+ }), Mi = [
8634
8892
  "montage-area",
8635
8893
  "background",
8636
8894
  "interaction-blocker"
8637
- ], Ci = ({ activeObject: t }) => {
8895
+ ], Ni = ({ activeObject: t }) => {
8638
8896
  let n = /* @__PURE__ */ new Set();
8639
8897
  return t ? (n.add(t), t instanceof e && t.getObjects().forEach((e) => n.add(e)), n) : n;
8640
- }, wi = ({ object: e, excluded: t, ignoredIds: n = Si }) => {
8898
+ }, Pi = ({ object: e, excluded: t, ignoredIds: n = Mi }) => {
8641
8899
  if (t.has(e)) return !0;
8642
8900
  let { visible: r = !0 } = e;
8643
8901
  if (!r) return !0;
8644
8902
  let { id: i } = e;
8645
8903
  return !!(i && n.includes(i));
8646
- }, Ti = class e {
8904
+ }, Fi = class e {
8647
8905
  constructor({ editor: e }) {
8648
8906
  this.anchors = {
8649
8907
  vertical: [],
@@ -8696,7 +8954,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8696
8954
  this._clearSpacingContexts(), this._clearGuides();
8697
8955
  return;
8698
8956
  }
8699
- 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({
8700
8958
  activeBounds: a,
8701
8959
  threshold: c,
8702
8960
  anchors: this.anchors
@@ -8708,7 +8966,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8708
8966
  top: t + u
8709
8967
  }), n.setCoords(), a = W({ object: n }) ?? a;
8710
8968
  }
8711
- 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({
8712
8970
  activeBounds: a,
8713
8971
  candidates: d,
8714
8972
  threshold: f,
@@ -8729,11 +8987,11 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8729
8987
  target: n,
8730
8988
  transform: i
8731
8989
  });
8732
- let h = W({ object: n }) ?? a, g = fi({
8990
+ let h = W({ object: n }) ?? a, g = Si({
8733
8991
  activeBounds: h,
8734
8992
  threshold: c,
8735
8993
  anchors: this.anchors
8736
- }), _ = hi({
8994
+ }), _ = Ti({
8737
8995
  activeBounds: h,
8738
8996
  candidates: d,
8739
8997
  threshold: c,
@@ -8964,9 +9222,9 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
8964
9222
  let { canvas: e, guideBounds: t } = this, n = e.getSelectionContext();
8965
9223
  if (!n) return;
8966
9224
  let { left: r, right: i, top: a, bottom: o } = t ?? this._calculateViewportBounds(), { viewportTransform: s } = e, c = e.getZoom() || 1;
8967
- 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]);
8968
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();
8969
- for (let e of this.activeSpacingGuides) vi({
9227
+ for (let e of this.activeSpacingGuides) Oi({
8970
9228
  context: n,
8971
9229
  guide: e,
8972
9230
  zoom: c
@@ -9144,7 +9402,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9144
9402
  return !Number.isFinite(a) || a <= 0 ? null : Math.max(1, Math.round(a));
9145
9403
  }
9146
9404
  static _shouldApplyPixelScalingStep({ target: e }) {
9147
- return !(e instanceof a);
9405
+ let t = typeof e.type == "string" ? e.type.toLowerCase() : "", n = e instanceof _ || t === "textbox" || t === "background-textbox";
9406
+ return !(e instanceof a) && !n;
9148
9407
  }
9149
9408
  static _applyMovementStep({ target: e, transform: t }) {
9150
9409
  let { left: n = 0, top: r = 0 } = e, i = Math.round(n / 1) * 1, a = Math.round(r / 1) * 1, o = typeof t?.original?.left == "number" ? t.original.left : null, s = typeof t?.original?.top == "number" ? t.original.top : null, c = o === null || o !== n, l = s === null || s !== r, u = {};
@@ -9176,14 +9435,14 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9176
9435
  }, r = [];
9177
9436
  for (let e of t) {
9178
9437
  let t = W({ object: e });
9179
- t && (yi({
9438
+ t && (ki({
9180
9439
  anchors: n,
9181
9440
  bounds: t
9182
9441
  }), r.push(t));
9183
9442
  }
9184
9443
  let { montageArea: i } = this.editor, a = W({ object: i });
9185
9444
  if (a) {
9186
- yi({
9445
+ ki({
9187
9446
  anchors: n,
9188
9447
  bounds: a
9189
9448
  });
@@ -9195,12 +9454,12 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9195
9454
  bottom: i
9196
9455
  };
9197
9456
  } else this.guideBounds = this._calculateViewportBounds();
9198
- this.anchors = n, this.spacingPatterns = xi({ bounds: r }), this.cachedTargetBounds = r;
9457
+ this.anchors = n, this.spacingPatterns = ji({ bounds: r }), this.cachedTargetBounds = r;
9199
9458
  }
9200
9459
  _collectTargets({ activeObject: e }) {
9201
- let t = Ci({ activeObject: e }), n = [];
9460
+ let t = Ni({ activeObject: e }), n = [];
9202
9461
  return this.canvas.forEachObject((e) => {
9203
- wi({
9462
+ Pi({
9204
9463
  object: e,
9205
9464
  excluded: t
9206
9465
  }) || n.push(e);
@@ -9223,7 +9482,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9223
9482
  bottom: (r - s) / a
9224
9483
  };
9225
9484
  }
9226
- }, Ei = "#3D8BF4", Di = class e {
9485
+ }, Ii = "#3D8BF4", Li = class e {
9227
9486
  constructor({ editor: e }) {
9228
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();
9229
9488
  }
@@ -9316,8 +9575,8 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9316
9575
  this.isTargetMontageArea = l, this.activeGuides = d, this._hideToolbar(), n.requestRenderAll();
9317
9576
  }
9318
9577
  static _resolveTarget({ event: e, activeObject: t }) {
9319
- let { target: n } = e, r = Ci({ activeObject: t });
9320
- return n && !wi({
9578
+ let { target: n } = e, r = Ni({ activeObject: t });
9579
+ return n && !Pi({
9321
9580
  object: n,
9322
9581
  excluded: r
9323
9582
  }) ? n : null;
@@ -9434,18 +9693,18 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9434
9693
  let { canvas: e } = this, t = e.getSelectionContext();
9435
9694
  if (!t) return;
9436
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;
9437
- 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([]);
9438
9697
  for (let e of this.activeGuides) {
9439
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;
9440
- 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({
9441
9700
  context: t,
9442
9701
  type: n,
9443
9702
  axis: i,
9444
9703
  start: a,
9445
9704
  end: c,
9446
- text: Br({ distance: l }).toString(),
9705
+ text: Xr({ distance: l }).toString(),
9447
9706
  zoom: r,
9448
- color: Ei,
9707
+ color: Ii,
9449
9708
  lineWidth: 1,
9450
9709
  offsetAlongAxis: d,
9451
9710
  offsetPerpendicular: 0
@@ -9463,13 +9722,13 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9463
9722
  let { toolbar: e } = this.editor;
9464
9723
  e?.showAfterTemporary?.(), this.isToolbarHidden = !1;
9465
9724
  }
9466
- }, Oi = class e {
9725
+ }, Ri = class e {
9467
9726
  constructor(e, t) {
9468
9727
  this.options = t, this.containerId = e, this.editorId = `${e}-${D()}`, this.init();
9469
9728
  }
9470
9729
  async init() {
9471
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;
9472
- 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 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 se({ 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({
9473
9732
  editor: this,
9474
9733
  options: this.options
9475
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) {
@@ -9577,7 +9836,7 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
9577
9836
  "U+A640-A69F",
9578
9837
  "U+FE2E-FE2F",
9579
9838
  "U+2116"
9580
- ].join(", "), ki = {
9839
+ ].join(", "), zi = {
9581
9840
  preserveObjectStacking: !0,
9582
9841
  controlsAboveOverlay: !0,
9583
9842
  centeredRotation: !0,
@@ -10431,20 +10690,20 @@ var Vn = ({ group: e, shape: t, text: n, width: r, height: i, padding: a, alignH
10431
10690
  };
10432
10691
  //#endregion
10433
10692
  //#region src/main.ts
10434
- function Ai(e, t = {}) {
10693
+ function Bi(e, t = {}) {
10435
10694
  let n = {
10436
- ...ki,
10695
+ ...zi,
10437
10696
  ...t
10438
10697
  }, r = document.getElementById(e);
10439
10698
  if (!r) return Promise.reject(/* @__PURE__ */ Error(`Контейнер с ID "${e}" не найден.`));
10440
10699
  let i = document.createElement("canvas");
10441
10700
  return i.id = `${e}-canvas`, r.appendChild(i), n.editorContainer = r, new Promise((t) => {
10442
10701
  n._onReadyCallback = t;
10443
- let r = new Oi(i.id, n);
10702
+ let r = new Ri(i.id, n);
10444
10703
  window[e] = r;
10445
10704
  });
10446
10705
  }
10447
10706
  //#endregion
10448
- export { Ai as default };
10707
+ export { Bi as default };
10449
10708
 
10450
10709
  //# sourceMappingURL=main.js.map