@anu3ev/fabric-image-editor 0.8.10 → 0.8.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/main.js +252 -228
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -3322,7 +3322,7 @@ var Nt = class {
3322
3322
  });
3323
3323
  let r = new e(t, { canvas: a });
3324
3324
  a.setActiveObject(r);
3325
- } else this._fitSingleObject(s, n);
3325
+ } else this._fitSingleObject(s, n), s instanceof e && i && this._materializeFittedSelection({ selection: s });
3326
3326
  a.renderAll(), r || o.saveState(), a.fire("editor:object-fitted", {
3327
3327
  object: s,
3328
3328
  type: n,
@@ -3336,7 +3336,26 @@ var Nt = class {
3336
3336
  v = t === "contain" ? Math.min(g / m, _ / h) : Math.max(g / m, _ / h), e.set({
3337
3337
  scaleX: o * v,
3338
3338
  scaleY: s * v
3339
- }), n.centerObjectToMontageArea({ object: e });
3339
+ }), n.centerObjectToMontageArea({ object: e }), this._materializeFittedObject({ object: e }) || e.setCoords?.();
3340
+ }
3341
+ _materializeFittedObject({ object: e }) {
3342
+ let { shapeManager: t, textManager: n } = this.editor, r = { target: e };
3343
+ e.shapeComposite === !0 && (r.textScale = Math.abs(e.scaleX ?? 1) || 1);
3344
+ let i = n.commitStandaloneTextScale({ target: e }), a = t.commitRehydratedShapeLayout(r);
3345
+ return i || a;
3346
+ }
3347
+ _requiresFittedObjectMaterialization({ object: e }) {
3348
+ let t = e.type === "textbox" || e.type === "background-textbox", n = "shapeComposite" in e && e.shapeComposite === !0;
3349
+ return t || n;
3350
+ }
3351
+ _materializeFittedSelection({ selection: t }) {
3352
+ let { canvas: n } = this.editor, r = t.getObjects();
3353
+ if (!r.some((e) => this._requiresFittedObjectMaterialization({ object: e }))) return;
3354
+ n.discardActiveObject(), r.forEach((e) => {
3355
+ this._materializeFittedObject({ object: e }) || e.setCoords?.();
3356
+ });
3357
+ let i = new e(r, { canvas: n });
3358
+ n.setActiveObject(i);
3340
3359
  }
3341
3360
  resetObjects() {
3342
3361
  this.editor.canvasManager.getObjects().forEach((e) => {
@@ -8558,7 +8577,21 @@ var bi = class {
8558
8577
  }
8559
8578
  return null;
8560
8579
  }
8561
- }, ki = class {
8580
+ }, ki = ({ rootObject: t, enableEvented: n = !0 }) => {
8581
+ let r = [{
8582
+ object: t,
8583
+ enableEvented: n
8584
+ }];
8585
+ for (let t = 0; t < r.length; t += 1) {
8586
+ let n = r[t], i = { id: `${n.object.type}-${O()}` };
8587
+ n.enableEvented && (i.evented = !0), n.object.set(i);
8588
+ let a = null, o = !1;
8589
+ if (n.object instanceof e ? (a = n.object.getObjects(), o = !0) : n.object instanceof l && (a = n.object.getObjects()), a) for (let e = 0; e < a.length; e += 1) r.push({
8590
+ object: a[e],
8591
+ enableEvented: o
8592
+ });
8593
+ }
8594
+ }, Ai = class {
8562
8595
  constructor({ editor: e }) {
8563
8596
  this.editor = e, this.clipboard = null;
8564
8597
  }
@@ -8661,16 +8694,6 @@ var bi = class {
8661
8694
  }
8662
8695
  r.commitStandaloneTextScale({ target: t }), n.commitRehydratedShapeLayout({ target: t });
8663
8696
  }
8664
- _materializeCloneIdentity({ clonedObject: t, enableEvented: n = !0 }) {
8665
- t.set({ id: `${t.type}-${O()}` }), n && t.set({ evented: !0 });
8666
- let r = t instanceof e;
8667
- (r || t instanceof l) && t.getObjects().forEach((e) => {
8668
- this._materializeCloneIdentity({
8669
- clonedObject: e,
8670
- enableEvented: r
8671
- });
8672
- });
8673
- }
8674
8697
  async _handleImageImport(e) {
8675
8698
  let { canvas: t, errorManager: n } = this.editor, r = !1, i = !1, a = null, o = null, s = new Promise((e, t) => {
8676
8699
  a = (t) => {
@@ -8691,6 +8714,10 @@ var bi = class {
8691
8714
  }
8692
8715
  try {
8693
8716
  let t = await s;
8717
+ if (t === null) {
8718
+ await this._importExternalImage({ source: e });
8719
+ return;
8720
+ }
8694
8721
  await this._importExternalImage({
8695
8722
  source: e,
8696
8723
  importOptions: t
@@ -8722,7 +8749,7 @@ var bi = class {
8722
8749
  if (!n || n.locked) return !1;
8723
8750
  try {
8724
8751
  let e = await n.clone(Ot);
8725
- return this._materializeCloneIdentity({ clonedObject: e }), e.set({
8752
+ return ki({ rootObject: e }), e.set({
8726
8753
  left: e.left + 10,
8727
8754
  top: e.top + 10
8728
8755
  }), this._materializeCloneGeometry({ clonedObject: e }), this._addClonedObjectToCanvas(e), t.fire("editor:object-duplicated", {
@@ -8789,7 +8816,7 @@ var bi = class {
8789
8816
  if (!this.clipboard) return !1;
8790
8817
  try {
8791
8818
  let t = await this.clipboard.clone(Ot);
8792
- return e.discardActiveObject(), this._materializeCloneIdentity({ clonedObject: t }), t.set({
8819
+ return e.discardActiveObject(), ki({ rootObject: t }), t.set({
8793
8820
  left: t.left + 10,
8794
8821
  top: t.top + 10
8795
8822
  }), this._materializeCloneGeometry({ clonedObject: t }), this._addClonedObjectToCanvas(t), e.fire("editor:object-pasted", {
@@ -8808,7 +8835,7 @@ var bi = class {
8808
8835
  }), !1;
8809
8836
  }
8810
8837
  }
8811
- }, Ai = class t {
8838
+ }, ji = class t {
8812
8839
  constructor({ editor: e }) {
8813
8840
  this.editor = e;
8814
8841
  }
@@ -8873,7 +8900,7 @@ var bi = class {
8873
8900
  !(n instanceof v) || !n.isEditing || n.exitEditing();
8874
8901
  }
8875
8902
  }
8876
- }, ji = class {
8903
+ }, Mi = class {
8877
8904
  constructor({ editor: e }) {
8878
8905
  this.editor = e;
8879
8906
  }
@@ -8939,7 +8966,7 @@ var bi = class {
8939
8966
  i.resumeHistory(), n || i.saveState();
8940
8967
  }
8941
8968
  }
8942
- }, Mi = class t {
8969
+ }, Ni = class t {
8943
8970
  constructor({ editor: e }) {
8944
8971
  this.lastSelection = [], this.isCtrlSelectionBoxActive = !1, this.isSelectionMergeInProgress = !1, this.editor = e, this.selectionKey = this._resolveSelectionKey(), this.handleTextEditingEnteredBound = this._handleTextEditingEntered.bind(this), this.handleTextEditingExitedBound = this._handleTextEditingExited.bind(this), this.handleLockedSelectionBound = this._filterLockedSelection.bind(this), this.handleSelectionMergeBound = this._handleSelectionMerge.bind(this), this.handleSelectionChangeBound = this._handleSelectionChange.bind(this), this.handleSelectionClearedBound = this._handleSelectionCleared.bind(this), this.handleSelectionBoxStartBound = this._handleSelectionBoxStart.bind(this), this.handleSelectionBoxEndBound = this._handleSelectionBoxEnd.bind(this), this._applySelectionKey({ selectionKey: this.selectionKey }), this._bindEvents();
8945
8972
  }
@@ -9133,7 +9160,7 @@ var bi = class {
9133
9160
  let { options: e } = this.editor, { selectionKey: t } = e;
9134
9161
  return t === void 0 ? ["ctrlKey", "metaKey"] : t;
9135
9162
  }
9136
- }, Ni = class e {
9163
+ }, Pi = class e {
9137
9164
  constructor({ editor: e }) {
9138
9165
  this.editor = e;
9139
9166
  }
@@ -9173,7 +9200,7 @@ var bi = class {
9173
9200
  };
9174
9201
  return i.fire("editor:objects-deleted", l), l;
9175
9202
  }
9176
- }, Pi = {
9203
+ }, Fi = {
9177
9204
  IMAGE_MANAGER: {
9178
9205
  INVALID_CONTENT_TYPE: "INVALID_CONTENT_TYPE",
9179
9206
  INVALID_SOURCE_TYPE: "INVALID_SOURCE_TYPE",
@@ -9211,7 +9238,7 @@ var bi = class {
9211
9238
  INVALID_TARGET: "TEMPLATE_INVALID_TARGET",
9212
9239
  APPLY_FAILED: "TEMPLATE_APPLY_FAILED"
9213
9240
  }
9214
- }, Fi = class e {
9241
+ }, Ii = class e {
9215
9242
  constructor({ editor: e }) {
9216
9243
  this._buffer = [], this.editor = e;
9217
9244
  }
@@ -9269,9 +9296,9 @@ var bi = class {
9269
9296
  }), this.editor.canvas.fire("editor:warning", s);
9270
9297
  }
9271
9298
  static isValidErrorCode(e) {
9272
- return e ? Object.values(Pi).some((t) => Object.values(t).includes(e)) : !1;
9299
+ return e ? Object.values(Fi).some((t) => Object.values(t).includes(e)) : !1;
9273
9300
  }
9274
- }, Ii = class {
9301
+ }, Li = class {
9275
9302
  constructor({ editor: e }) {
9276
9303
  this.currentBounds = null, this.editor = e;
9277
9304
  }
@@ -9320,32 +9347,32 @@ var bi = class {
9320
9347
  updateBounds() {
9321
9348
  this.currentBounds = this.calculatePanBounds();
9322
9349
  }
9323
- }, Li = ({ textbox: e }) => {
9350
+ }, Ri = ({ textbox: e }) => {
9324
9351
  if (!e.isEditing) return null;
9325
9352
  let t = e.selectionStart ?? 0, n = e.selectionEnd ?? t;
9326
9353
  return t === n ? null : {
9327
9354
  start: Math.min(t, n),
9328
9355
  end: Math.max(t, n)
9329
9356
  };
9330
- }, Ri = ({ textbox: e }) => {
9357
+ }, zi = ({ textbox: e }) => {
9331
9358
  let t = e.text?.length ?? 0;
9332
9359
  return t <= 0 ? null : {
9333
9360
  start: 0,
9334
9361
  end: t
9335
9362
  };
9336
- }, zi = ({ textbox: e, range: t }) => {
9363
+ }, Bi = ({ textbox: e, range: t }) => {
9337
9364
  if (!t) return !1;
9338
9365
  let n = e.text?.length ?? 0;
9339
9366
  return n <= 0 ? !1 : t.start <= 0 && t.end >= n;
9340
- }, Bi = ({ textbox: e, styles: t, range: n }) => {
9367
+ }, Vi = ({ textbox: e, styles: t, range: n }) => {
9341
9368
  if (!t || !Object.keys(t).length) return !1;
9342
9369
  let { start: r, end: i } = n;
9343
9370
  return i <= r ? !1 : (e.setSelectionStyles(t, r, i), !0);
9344
- }, Vi = ({ textbox: e, range: t, property: n }) => {
9371
+ }, Hi = ({ textbox: e, range: t, property: n }) => {
9345
9372
  if (!t) return;
9346
9373
  let r = e.getSelectionStyles(t.start, t.end, !0);
9347
9374
  if (r.length) return r[0]?.[n];
9348
- }, Hi = ({ strokeColor: e, width: t }) => t <= 0 ? null : e ?? "#000000", Ui = ({ width: e = 0 }) => e ? Math.max(0, e) : 0, Wi = ({ value: e }) => typeof e == "string" ? e.toLocaleUpperCase() : "", Gi = ({ value: e, min: t, max: n }) => Math.min(Math.max(e, t), n), Ki = class e extends v {
9375
+ }, Ui = ({ strokeColor: e, width: t }) => t <= 0 ? null : e ?? "#000000", Wi = ({ width: e = 0 }) => e ? Math.max(0, e) : 0, Gi = ({ value: e }) => typeof e == "string" ? e.toLocaleUpperCase() : "", Ki = ({ value: e, min: t, max: n }) => Math.min(Math.max(e, t), n), qi = class e extends v {
9349
9376
  static {
9350
9377
  this.type = "background-textbox";
9351
9378
  }
@@ -9489,7 +9516,7 @@ var bi = class {
9489
9516
  this._removeShadow(e);
9490
9517
  }
9491
9518
  _getDecorationColorAt(e, t) {
9492
- let n = this.getValueOfPropertyAt(e, t, "strokeWidth"), r = Ui({ width: typeof n == "number" && Number.isFinite(n) ? n : 0 }), i = this.getValueOfPropertyAt(e, t, "stroke"), a = i == null ? null : Hi({
9519
+ let n = this.getValueOfPropertyAt(e, t, "strokeWidth"), r = Wi({ width: typeof n == "number" && Number.isFinite(n) ? n : 0 }), i = this.getValueOfPropertyAt(e, t, "stroke"), a = i == null ? null : Ui({
9493
9520
  strokeColor: i,
9494
9521
  width: r
9495
9522
  });
@@ -9505,22 +9532,22 @@ var bi = class {
9505
9532
  _getCornerRadii({ width: e, height: t }) {
9506
9533
  let n = e / 2, r = t / 2, i = Math.min(n, r);
9507
9534
  return {
9508
- bottomLeft: Gi({
9535
+ bottomLeft: Ki({
9509
9536
  value: this.radiusBottomLeft ?? 0,
9510
9537
  min: 0,
9511
9538
  max: i
9512
9539
  }),
9513
- bottomRight: Gi({
9540
+ bottomRight: Ki({
9514
9541
  value: this.radiusBottomRight ?? 0,
9515
9542
  min: 0,
9516
9543
  max: i
9517
9544
  }),
9518
- topLeft: Gi({
9545
+ topLeft: Ki({
9519
9546
  value: this.radiusTopLeft ?? 0,
9520
9547
  min: 0,
9521
9548
  max: i
9522
9549
  }),
9523
- topRight: Gi({
9550
+ topRight: Ki({
9524
9551
  value: this.radiusTopRight ?? 0,
9525
9552
  min: 0,
9526
9553
  max: i
@@ -9538,7 +9565,7 @@ var bi = class {
9538
9565
  _getEffectiveBackgroundFill() {
9539
9566
  let e = this.backgroundColor;
9540
9567
  if (!e) return null;
9541
- let t = Gi({
9568
+ let t = Ki({
9542
9569
  value: this.backgroundOpacity ?? 1,
9543
9570
  min: 0,
9544
9571
  max: 1
@@ -9551,19 +9578,19 @@ var bi = class {
9551
9578
  return r.setAlpha(t), r.toRgba();
9552
9579
  }
9553
9580
  static _renderRoundedRect({ ctx: e, height: t, left: n, radii: r, top: i, width: a }) {
9554
- let o = n + a, s = i + t, { topLeft: c, topRight: l, bottomRight: u, bottomLeft: d } = r, f = Gi({
9581
+ let o = n + a, s = i + t, { topLeft: c, topRight: l, bottomRight: u, bottomLeft: d } = r, f = Ki({
9555
9582
  value: c,
9556
9583
  min: 0,
9557
9584
  max: a
9558
- }), p = Gi({
9585
+ }), p = Ki({
9559
9586
  value: l,
9560
9587
  min: 0,
9561
9588
  max: a
9562
- }), m = Gi({
9589
+ }), m = Ki({
9563
9590
  value: u,
9564
9591
  min: 0,
9565
9592
  max: a
9566
- }), h = Gi({
9593
+ }), h = Ki({
9567
9594
  value: d,
9568
9595
  min: 0,
9569
9596
  max: a
@@ -9574,20 +9601,20 @@ var bi = class {
9574
9601
  let { width: e = 0, height: t = 0 } = this, n = Math.round(e), r = Math.round(t);
9575
9602
  n !== e && (this.width = Math.max(0, n)), r !== t && (this.height = Math.max(0, r));
9576
9603
  }
9577
- }, qi = () => {
9578
- b?.setClass && b.setClass(Ki, "background-textbox");
9579
- }, Ji = ({ transform: e }) => {
9604
+ }, Ji = () => {
9605
+ b?.setClass && b.setClass(qi, "background-textbox");
9606
+ }, Yi = ({ transform: e }) => {
9580
9607
  let { corner: t = "", action: n = "" } = e;
9581
9608
  return {
9582
9609
  isCornerHandle: t === "tl" || t === "tr" || t === "bl" || t === "br" || n === "scale",
9583
9610
  isHorizontalHandle: t === "ml" || t === "mr" || n === "scaleX",
9584
9611
  isVerticalHandle: t === "mt" || t === "mb" || n === "scaleY"
9585
9612
  };
9586
- }, Yi = ({ textbox: e, transform: t, appliedWidth: n }) => {
9613
+ }, Xi = ({ textbox: e, transform: t, appliedWidth: n }) => {
9587
9614
  t.scaleX = 1, t.scaleY = 1;
9588
9615
  let r = t.original;
9589
9616
  r && (r.scaleX = 1, r.scaleY = 1, r.width = n, r.height = e.height, r.left = e.left, r.top = e.top);
9590
- }, Xi = ({ textbox: e, transform: t, scenePoint: n }) => {
9617
+ }, Zi = ({ textbox: e, transform: t, scenePoint: n }) => {
9591
9618
  let { x: r, y: i } = e._getTransformedDimensions();
9592
9619
  if (r <= 0 || i <= 0) return null;
9593
9620
  let a = x.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);
@@ -9597,27 +9624,27 @@ var bi = class {
9597
9624
  stepScaleX: l,
9598
9625
  stepScaleY: u
9599
9626
  };
9600
- }, Zi = 1e-4;
9601
- function Qi(e) {
9627
+ }, Qi = 1e-4;
9628
+ function $i(e) {
9602
9629
  return !!e && e instanceof v;
9603
9630
  }
9604
- function $i(e) {
9605
- if (!Qi(e)) return !1;
9631
+ function ea(e) {
9632
+ if (!$i(e)) return !1;
9606
9633
  let t = e.group;
9607
9634
  return e.shapeNodeType === "text" && t?.shapeComposite === !0;
9608
9635
  }
9609
- var ea = class {
9636
+ var ta = class {
9610
9637
  constructor({ canvas: t, canvasManager: n, persistScaledTextbox: r }) {
9611
9638
  this.handleMouseMove = (e) => {
9612
9639
  let t = this.canvas._currentTransform;
9613
9640
  if (!t) return;
9614
9641
  let { target: n } = t;
9615
- if (!Qi(n) || $i(n)) return;
9642
+ if (!$i(n) || ea(n)) return;
9616
9643
  let r = this.scalingState.get(n);
9617
9644
  if (!r || !e.e) return;
9618
- let { isCornerHandle: i, isHorizontalHandle: a, isVerticalHandle: o } = Ji({ transform: t });
9645
+ let { isCornerHandle: i, isHorizontalHandle: a, isVerticalHandle: o } = Yi({ transform: t });
9619
9646
  if (!a && !o && !i) return;
9620
- let s = Xi({
9647
+ let s = Zi({
9621
9648
  textbox: n,
9622
9649
  transform: t,
9623
9650
  scenePoint: this.canvas.getScenePoint(e.e)
@@ -9640,18 +9667,18 @@ var ea = class {
9640
9667
  }, j = r.lastAllowedScaleX, M = r.lastAllowedScaleY;
9641
9668
  if (i) {
9642
9669
  let e = Math.max(r.minimumProportionalScale, r.lastAllowedScaleX * Math.sqrt(u * d)), t = c || l ? r.minimumProportionalScale : e;
9643
- if (Math.abs(t - r.lastAllowedScaleX) <= Zi) return;
9670
+ if (Math.abs(t - r.lastAllowedScaleX) <= Qi) return;
9644
9671
  j = t, M = t;
9645
9672
  } else {
9646
9673
  if (a) {
9647
9674
  let e = r.lastAllowedScaleX * u, t = c ? r.minimumWidthScale : Math.max(r.minimumWidthScale, e);
9648
- Math.abs(t - r.lastAllowedScaleX) > Zi && (j = t);
9675
+ Math.abs(t - r.lastAllowedScaleX) > Qi && (j = t);
9649
9676
  }
9650
9677
  if (o) {
9651
9678
  let e = r.lastAllowedScaleY * d, t = l ? r.minimumFontScale : Math.max(r.minimumFontScale, e);
9652
- Math.abs(t - r.lastAllowedScaleY) > Zi && (M = t);
9679
+ Math.abs(t - r.lastAllowedScaleY) > Qi && (M = t);
9653
9680
  }
9654
- if (Math.abs(j - r.lastAllowedScaleX) <= Zi && Math.abs(M - r.lastAllowedScaleY) <= Zi) return;
9681
+ if (Math.abs(j - r.lastAllowedScaleX) <= Qi && Math.abs(M - r.lastAllowedScaleY) <= Qi) return;
9655
9682
  }
9656
9683
  let { appliedWidth: N, dimensionsRounded: P } = kn({
9657
9684
  textbox: n,
@@ -9667,7 +9694,7 @@ var ea = class {
9667
9694
  shouldDisableAutoExpandOnHorizontalChange: a,
9668
9695
  shouldRoundDimensions: !i
9669
9696
  });
9670
- Yi({
9697
+ Xi({
9671
9698
  textbox: n,
9672
9699
  transform: t,
9673
9700
  appliedWidth: N
@@ -9688,12 +9715,12 @@ var ea = class {
9688
9715
  }), this.canvas.requestRenderAll();
9689
9716
  }, this.handleObjectScaling = (t) => {
9690
9717
  let { target: n, transform: r } = t;
9691
- if (n instanceof e || !Qi(n) || $i(n) || !r) return;
9718
+ if (n instanceof e || !$i(n) || ea(n) || !r) return;
9692
9719
  n.isScaling = !0;
9693
9720
  let i = this._ensureScalingState({
9694
9721
  textbox: n,
9695
9722
  transform: r
9696
- }), { startBase: a } = i, { width: o, fontSize: s } = a, { isCornerHandle: c, isHorizontalHandle: l, isVerticalHandle: u } = Ji({ transform: r }), d = r.corner ?? "", f = c || u;
9723
+ }), { startBase: a } = i, { width: o, fontSize: s } = a, { isCornerHandle: c, isHorizontalHandle: l, isVerticalHandle: u } = Yi({ transform: r }), d = r.corner ?? "", f = c || u;
9697
9724
  if (!l && !u && !c) return;
9698
9725
  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({
9699
9726
  object: n,
@@ -9722,7 +9749,7 @@ var ea = class {
9722
9749
  shouldDisableAutoExpandOnHorizontalChange: l,
9723
9750
  shouldRoundDimensions: !c
9724
9751
  });
9725
- Yi({
9752
+ Xi({
9726
9753
  textbox: n,
9727
9754
  transform: r,
9728
9755
  appliedWidth: L
@@ -9755,7 +9782,7 @@ var ea = class {
9755
9782
  let { target: n } = t;
9756
9783
  if (n instanceof e) {
9757
9784
  let t = n.getObjects();
9758
- if (!t.some((e) => Qi(e))) return;
9785
+ if (!t.some((e) => $i(e))) return;
9759
9786
  let { scaleX: r = 1, scaleY: i = 1 } = n;
9760
9787
  if (Math.abs(r - 1) < .01 && Math.abs(i - 1) < .01) return;
9761
9788
  this.canvas.discardActiveObject(), t.forEach((e) => {
@@ -9765,7 +9792,7 @@ var ea = class {
9765
9792
  this.canvas.setActiveObject(a), this.canvas.requestRenderAll();
9766
9793
  return;
9767
9794
  }
9768
- if (!Qi(n) || $i(n)) return;
9795
+ if (!$i(n) || ea(n)) return;
9769
9796
  n.isScaling = !1;
9770
9797
  let r = this.scalingState.get(n);
9771
9798
  if (this.scalingState.delete(n), !r?.hasScalingChange) return;
@@ -9790,7 +9817,7 @@ var ea = class {
9790
9817
  }, this.canvas = t, this.canvasManager = n, this.persistScaledTextbox = r, this.scalingState = /* @__PURE__ */ new WeakMap();
9791
9818
  }
9792
9819
  commitStandaloneTextScale({ target: e, shouldDisableAutoExpandOnHorizontalChange: t = !1 }) {
9793
- if (!Qi(e) || $i(e)) return !1;
9820
+ if (!$i(e) || ea(e)) return !1;
9794
9821
  let n = Math.abs(e.scaleX ?? 1) || 1, r = Math.abs(e.scaleY ?? 1) || 1;
9795
9822
  if (!(Math.abs(n - 1) > .01 || Math.abs(r - 1) > .01)) return !1;
9796
9823
  let i = En({ textbox: e }), a = this.canvasManager.getObjectPlacement({ object: e });
@@ -9864,7 +9891,7 @@ var ea = class {
9864
9891
  originY: a
9865
9892
  });
9866
9893
  }
9867
- }, ta = class e {
9894
+ }, na = class e {
9868
9895
  constructor({ editor: t }) {
9869
9896
  this._handleTextEditingEntered = (t) => {
9870
9897
  this.isTextEditingActive = !0;
@@ -9877,7 +9904,7 @@ var ea = class {
9877
9904
  if (!e._isTextbox(n)) return;
9878
9905
  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 });
9879
9906
  if (s) {
9880
- let e = Wi({ value: l });
9907
+ let e = Gi({ value: l });
9881
9908
  e !== i && n.set({ text: e }), n.textCaseRaw = l;
9882
9909
  } else n.textCaseRaw = i;
9883
9910
  if (!r && o === void 0 && (n.autoExpand = !0), r) {
@@ -9922,7 +9949,7 @@ var ea = class {
9922
9949
  transform: r,
9923
9950
  event: i ?? null
9924
9951
  });
9925
- }, this.editor = t, this.canvas = t.canvas, this.fonts = t.options.fonts ?? [], this.scalingController = new ea({
9952
+ }, this.editor = t, this.canvas = t.canvas, this.fonts = t.options.fonts ?? [], this.scalingController = new ta({
9926
9953
  canvas: t.canvas,
9927
9954
  canvasManager: t.canvasManager,
9928
9955
  persistScaledTextbox: ({ target: e, style: t }) => {
@@ -9931,12 +9958,12 @@ var ea = class {
9931
9958
  style: t
9932
9959
  });
9933
9960
  }
9934
- }), this.editingPlacementState = /* @__PURE__ */ new WeakMap(), this.isTextEditingActive = !1, this._bindEvents(), qi();
9961
+ }), this.editingPlacementState = /* @__PURE__ */ new WeakMap(), this.isTextEditingActive = !1, this._bindEvents(), Ji();
9935
9962
  }
9936
9963
  addText({ id: t = `background-textbox-${O()}`, 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: D = !1, withoutSave: k = !1, withoutAdding: A = !1, emitLifecycleEvents: j = !0 } = {}) {
9937
9964
  let { canvasManager: M, historyManager: N } = this.editor, { canvas: P } = this;
9938
9965
  N.suspendHistory();
9939
- let F = i ?? this._getDefaultFontFamily(), I = Ui({ width: m }), L = Hi({
9966
+ let F = i ?? this._getDefaultFontFamily(), I = Wi({ width: m }), L = Ui({
9940
9967
  strokeColor: p,
9941
9968
  width: I
9942
9969
  }), ee = {
@@ -9965,11 +9992,11 @@ var ea = class {
9965
9992
  radiusBottomRight: w,
9966
9993
  radiusBottomLeft: T,
9967
9994
  ...E
9968
- }, R = new Ki(n, ee), te = r !== !1;
9995
+ }, R = new qi(n, ee), te = r !== !1;
9969
9996
  R.autoExpand = te;
9970
9997
  let ne = E.left !== void 0 || E.top !== void 0;
9971
9998
  if (R.textCaseRaw = R.text ?? "", l) {
9972
- let e = Wi({ value: R.textCaseRaw });
9999
+ let e = Gi({ value: R.textCaseRaw });
9973
10000
  e !== R.text && R.set({ text: e });
9974
10001
  }
9975
10002
  Tn({ textbox: R }) && (R.dirty = !0);
@@ -10019,37 +10046,37 @@ var ea = class {
10019
10046
  top: R,
10020
10047
  originX: te,
10021
10048
  originY: ne
10022
- }), B = a === void 0 ? Li({ textbox: c }) : Yt({
10049
+ }), B = a === void 0 ? Ri({ textbox: c }) : Yt({
10023
10050
  text: l,
10024
10051
  range: a
10025
10052
  }), ae = B ? Xt({
10026
10053
  textbox: c,
10027
10054
  range: B
10028
- }) : null, V = {}, oe = {}, H = {}, U, se, W, G, K = zi({
10055
+ }) : null, V = {}, oe = {}, H = {}, U, se, W, G, K = Bi({
10029
10056
  textbox: c,
10030
10057
  range: B
10031
- }), ce = zi({
10058
+ }), ce = Bi({
10032
10059
  textbox: c,
10033
10060
  range: ae
10034
10061
  }), le = !B || K, ue = le || ce, q = !B;
10035
10062
  if (g !== void 0 && (ae && (oe.fontFamily = g), ue && (z.fontFamily = g, q && (H.fontFamily = g))), _ !== void 0 && (ae && (oe.fontSize = _), ue && (z.fontSize = _, q && (H.fontSize = _))), v !== void 0 && (U = v ? "bold" : "normal", B && (V.fontWeight = U), le && (z.fontWeight = U, q && (H.fontWeight = U))), y !== void 0 && (se = y ? "italic" : "normal", B && (V.fontStyle = se), le && (z.fontStyle = se, q && (H.fontStyle = se))), b !== void 0 && (B && (V.underline = b), le && (z.underline = b, q && (H.underline = b))), S !== void 0 && (B && (V.linethrough = S), le && (z.linethrough = S, q && (H.linethrough = S))), C !== void 0 && (z.textAlign = C), w !== void 0 && (B && (V.fill = w), le && (z.fill = w, q && (H.fill = w))), T !== void 0 || E !== void 0) {
10036
- let e = B ? Vi({
10063
+ let e = B ? Hi({
10037
10064
  textbox: c,
10038
10065
  range: B,
10039
10066
  property: "strokeWidth"
10040
- }) : void 0, t = B ? Vi({
10067
+ }) : void 0, t = B ? Hi({
10041
10068
  textbox: c,
10042
10069
  range: B,
10043
10070
  property: "stroke"
10044
10071
  }) : void 0, n = typeof e == "number" ? e : void 0, r = typeof t == "string" ? t : void 0, i = typeof c.stroke == "string" ? c.stroke : void 0;
10045
- G = Ui({ width: E ?? n ?? c.strokeWidth ?? 0 }), W = Hi({
10072
+ G = Wi({ width: E ?? n ?? c.strokeWidth ?? 0 }), W = Ui({
10046
10073
  strokeColor: T ?? r ?? i,
10047
10074
  width: G
10048
10075
  }), B && (V.stroke = W, V.strokeWidth = G), le && (z.stroke = W, z.strokeWidth = G, q && (H.stroke = W, H.strokeWidth = G));
10049
10076
  }
10050
10077
  D !== void 0 && (z.opacity = D), O !== void 0 && (z.backgroundColor = O), k !== void 0 && (z.backgroundOpacity = k), A !== void 0 && (z.paddingTop = A), j !== void 0 && (z.paddingRight = j), M !== void 0 && (z.paddingBottom = M), N !== void 0 && (z.paddingLeft = N), P !== void 0 && (z.radiusTopLeft = P), F !== void 0 && (z.radiusTopRight = F), I !== void 0 && (z.radiusBottomRight = I), L !== void 0 && (z.radiusBottomLeft = L);
10051
10078
  let de = c.textCaseRaw ?? l, fe = !!c.uppercase, pe = m !== void 0, me = pe ? m ?? "" : de, he = x ?? fe, ge = he !== fe, _e = c.text ?? "";
10052
- pe || ge ? (z.text = he ? Wi({ value: me }) : me, c.textCaseRaw = me) : c.textCaseRaw === void 0 && (c.textCaseRaw = de);
10079
+ pe || ge ? (z.text = he ? Gi({ value: me }) : me, c.textCaseRaw = me) : c.textCaseRaw === void 0 && (c.textCaseRaw = de);
10053
10080
  let ve = wn({ stylesList: [
10054
10081
  z,
10055
10082
  V,
@@ -10073,19 +10100,19 @@ var ea = class {
10073
10100
  })), c.uppercase = he, c.set(z);
10074
10101
  let Ee = !1;
10075
10102
  if (B) {
10076
- let e = Bi({
10103
+ let e = Vi({
10077
10104
  textbox: c,
10078
10105
  styles: V,
10079
10106
  range: B
10080
- }), t = ae ? Bi({
10107
+ }), t = ae ? Vi({
10081
10108
  textbox: c,
10082
10109
  styles: oe,
10083
10110
  range: ae
10084
10111
  }) : !1;
10085
10112
  Ee = e || t;
10086
10113
  } else if (Object.keys(H).length) {
10087
- let e = Ri({ textbox: c });
10088
- e && (Ee = Bi({
10114
+ let e = zi({ textbox: c });
10115
+ e && (Ee = Vi({
10089
10116
  textbox: c,
10090
10117
  styles: H,
10091
10118
  range: e
@@ -10335,7 +10362,7 @@ var ea = class {
10335
10362
  _getDefaultFontFamily() {
10336
10363
  return this.fonts[0]?.family ?? "Arial";
10337
10364
  }
10338
- }, na = ({ x1: e, y1: t, x2: n, y2: r }) => (Math.atan2(r - t, n - e) * 180 / Math.PI + 360) % 360, ra = (e) => {
10365
+ }, ra = ({ x1: e, y1: t, x2: n, y2: r }) => (Math.atan2(r - t, n - e) * 180 / Math.PI + 360) % 360, ia = (e) => {
10339
10366
  if (!e || typeof e != "object") return null;
10340
10367
  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) => ({
10341
10368
  color: typeof e.color == "string" ? e.color : "#000000",
@@ -10346,7 +10373,7 @@ var ea = class {
10346
10373
  let { x1: e, y1: t, x2: r, y2: i } = n;
10347
10374
  if (typeof e == "number" && typeof t == "number" && typeof r == "number" && typeof i == "number") return {
10348
10375
  type: "linear",
10349
- angle: na({
10376
+ angle: ra({
10350
10377
  x1: e,
10351
10378
  y1: t,
10352
10379
  x2: r,
@@ -10374,7 +10401,7 @@ var ea = class {
10374
10401
  };
10375
10402
  }
10376
10403
  return null;
10377
- }, ia = "_templateAnchorX", aa = "_templateAnchorY", oa = class t {
10404
+ }, aa = "_templateAnchorX", oa = "_templateAnchorY", sa = class t {
10378
10405
  constructor({ editor: e }) {
10379
10406
  this.editor = e;
10380
10407
  }
@@ -10383,7 +10410,7 @@ var ea = class {
10383
10410
  if (!p.length) return s.emitWarning({
10384
10411
  origin: "TemplateManager",
10385
10412
  method: "serializeSelection",
10386
- code: Pi.TEMPLATE_MANAGER.NO_OBJECTS_SELECTED,
10413
+ code: Fi.TEMPLATE_MANAGER.NO_OBJECTS_SELECTED,
10387
10414
  message: "Нет объектов для сериализации шаблона"
10388
10415
  }), null;
10389
10416
  let m = t._getBounds(o), h = t._getMontageSize({
@@ -10412,14 +10439,14 @@ var ea = class {
10412
10439
  if (!l?.length) return a.emitWarning({
10413
10440
  origin: "TemplateManager",
10414
10441
  method: "applyTemplate",
10415
- code: Pi.TEMPLATE_MANAGER.INVALID_TEMPLATE,
10442
+ code: Fi.TEMPLATE_MANAGER.INVALID_TEMPLATE,
10416
10443
  message: "Шаблон не содержит объектов"
10417
10444
  }), null;
10418
10445
  let f = t._getBounds(r);
10419
10446
  if (!f) return a.emitWarning({
10420
10447
  origin: "TemplateManager",
10421
10448
  method: "applyTemplate",
10422
- code: Pi.TEMPLATE_MANAGER.INVALID_TARGET,
10449
+ code: Fi.TEMPLATE_MANAGER.INVALID_TARGET,
10423
10450
  message: "Не удалось определить границы монтажной области"
10424
10451
  }), null;
10425
10452
  let p = t._getMontageSize({
@@ -10438,7 +10465,7 @@ var ea = class {
10438
10465
  if (!r.length) return a.emitWarning({
10439
10466
  origin: "TemplateManager",
10440
10467
  method: "applyTemplate",
10441
- code: Pi.TEMPLATE_MANAGER.INVALID_TEMPLATE,
10468
+ code: Fi.TEMPLATE_MANAGER.INVALID_TEMPLATE,
10442
10469
  message: "Не удалось создать объекты шаблона"
10443
10470
  }), null;
10444
10471
  let { backgroundObject: i, contentObjects: u } = t._extractBackgroundObject(r);
@@ -10460,10 +10487,7 @@ var ea = class {
10460
10487
  }), c.commitStandaloneTextScale({ target: e }), s.commitRehydratedShapeLayout({
10461
10488
  target: e,
10462
10489
  textScale: h
10463
- }), Bt({ object: e }), e.set({
10464
- id: `${e.type}-${O()}`,
10465
- evented: !0
10466
- }), n.add(e), e));
10490
+ }), Bt({ object: e }), ki({ rootObject: e }), n.add(e), e));
10467
10491
  return !d.length && !v ? null : (_ = d.length > 0 || v, d.length && t._activateObjects({
10468
10492
  canvas: n,
10469
10493
  objects: d
@@ -10476,7 +10500,7 @@ var ea = class {
10476
10500
  return a.emitError({
10477
10501
  origin: "TemplateManager",
10478
10502
  method: "applyTemplate",
10479
- code: Pi.TEMPLATE_MANAGER.APPLY_FAILED,
10503
+ code: Fi.TEMPLATE_MANAGER.APPLY_FAILED,
10480
10504
  message: "Ошибка применения шаблона",
10481
10505
  data: {
10482
10506
  templateId: d,
@@ -10633,8 +10657,8 @@ var ea = class {
10633
10657
  baseHeight: a,
10634
10658
  scale: n,
10635
10659
  useRelativePositions: o,
10636
- anchorX: t._resolveAnchor(s, ia),
10637
- anchorY: t._resolveAnchor(s, aa)
10660
+ anchorX: t._resolveAnchor(s, aa),
10661
+ anchorY: t._resolveAnchor(s, oa)
10638
10662
  })
10639
10663
  }), h = f * n, g = p * n, _ = e.originX ?? "center", v = e.originY ?? "center";
10640
10664
  e.set({
@@ -10709,7 +10733,7 @@ var ea = class {
10709
10733
  });
10710
10734
  if (!i || !a) return;
10711
10735
  e.setCoords();
10712
- let o = e, s = t._resolveAnchor(o, ia), c = typeof e.left == "number" ? e.left : null, l = e.originX ?? "center", u = e.originY ?? "center", d = e.getPointByOrigin(l, u), f = t._getBoundingRect(e), p = f.left + f.width / 2, m = f.left + f.width;
10736
+ let o = e, s = t._resolveAnchor(o, aa), c = typeof e.left == "number" ? e.left : null, l = e.originX ?? "center", u = e.originY ?? "center", d = e.getPointByOrigin(l, u), f = t._getBoundingRect(e), p = f.left + f.width / 2, m = f.left + f.width;
10713
10737
  e.set("width", i), e.initDimensions();
10714
10738
  let h = t._getLongestLineWidth({
10715
10739
  textbox: e,
@@ -10738,10 +10762,10 @@ var ea = class {
10738
10762
  x: (p.left - o) / d,
10739
10763
  y: (p.top - s) / f
10740
10764
  }, h = (u.left - o) / d, g = (u.top - s) / f, _ = h + u.width / d, v = g + u.height / f;
10741
- return a[ia] = t._detectAnchor({
10765
+ return a[aa] = t._detectAnchor({
10742
10766
  start: h,
10743
10767
  end: _
10744
- }), a[aa] = t._detectAnchor({
10768
+ }), a[oa] = t._detectAnchor({
10745
10769
  start: g,
10746
10770
  end: v
10747
10771
  }), a.left = m.x, a.top = m.y, a;
@@ -10766,7 +10790,7 @@ var ea = class {
10766
10790
  withoutSave: !0
10767
10791
  }), !0;
10768
10792
  if (a === "gradient") {
10769
- let e = ra(r);
10793
+ let e = ia(r);
10770
10794
  if (e) return n.setGradientBackground({
10771
10795
  gradient: e,
10772
10796
  customData: o,
@@ -10787,7 +10811,7 @@ var ea = class {
10787
10811
  r.emitWarning({
10788
10812
  origin: "TemplateManager",
10789
10813
  method: "applyTemplate",
10790
- code: Pi.TEMPLATE_MANAGER.APPLY_FAILED,
10814
+ code: Fi.TEMPLATE_MANAGER.APPLY_FAILED,
10791
10815
  message: "Не удалось применить фон из шаблона",
10792
10816
  data: e
10793
10817
  });
@@ -10823,29 +10847,29 @@ var ea = class {
10823
10847
  enlivenObjectEnlivables(e) {
10824
10848
  return w.enlivenObjectEnlivables(e);
10825
10849
  }
10826
- }, sa = "#3D8BF4", ca = .5, la = ({ distance: e }) => Number.isFinite(e) ? Math.round(Math.max(0, e)) : 0, ua = ({ firstDistance: e, secondDistance: t }) => {
10827
- let n = la({ distance: e }), r = la({ distance: t });
10850
+ }, ca = "#3D8BF4", la = .5, ua = ({ distance: e }) => Number.isFinite(e) ? Math.round(Math.max(0, e)) : 0, da = ({ firstDistance: e, secondDistance: t }) => {
10851
+ let n = ua({ distance: e }), r = ua({ distance: t });
10828
10852
  return {
10829
10853
  firstDisplayDistance: n,
10830
10854
  secondDisplayDistance: r,
10831
10855
  displayDistanceDiff: Math.abs(n - r),
10832
10856
  commonDisplayDistance: Math.max(n, r)
10833
10857
  };
10834
- }, da = ({ firstStart: e, firstEnd: t, secondStart: n, secondEnd: r }) => Math.min(t, r) - Math.max(e, n), fa = ({ step: e }) => {
10858
+ }, fa = ({ firstStart: e, firstEnd: t, secondStart: n, secondEnd: r }) => Math.min(t, r) - Math.max(e, n), pa = ({ step: e }) => {
10835
10859
  let t = Math.abs(e).toString(), n = t.indexOf(".");
10836
10860
  return n === -1 ? 0 : t.slice(n + 1).length;
10837
- }, pa = ({ value: e, step: t }) => {
10861
+ }, ma = ({ value: e, step: t }) => {
10838
10862
  if (t === 0) return e;
10839
- let n = fa({ step: t }), r = Math.round(e / t) * t;
10863
+ let n = pa({ step: t }), r = Math.round(e / t) * t;
10840
10864
  return Number(r.toFixed(n));
10841
- }, ma = ({ value: e, step: t }) => {
10865
+ }, ha = ({ value: e, step: t }) => {
10842
10866
  if (t === 0) return !0;
10843
- let n = pa({
10867
+ let n = ma({
10844
10868
  value: e,
10845
10869
  step: t
10846
- }), r = 10 ** -(fa({ step: t }) + 4);
10870
+ }), r = 10 ** -(pa({ step: t }) + 4);
10847
10871
  return Math.abs(n - e) <= r;
10848
- }, ha = ({ bounds: e, axis: t }) => {
10872
+ }, ga = ({ bounds: e, axis: t }) => {
10849
10873
  let { left: n = 0, right: r = 0, top: i = 0, bottom: a = 0 } = e;
10850
10874
  return t === "vertical" ? {
10851
10875
  start: i,
@@ -10854,7 +10878,7 @@ var ea = class {
10854
10878
  start: n,
10855
10879
  end: r
10856
10880
  };
10857
- }, ga = ({ items: e, axis: t }) => {
10881
+ }, _a = ({ items: e, axis: t }) => {
10858
10882
  for (let n = 1; n < e.length; n += 1) {
10859
10883
  let r = e[n], { bounds: i } = r, a = i[t], o = n - 1;
10860
10884
  for (; o >= 0;) {
@@ -10864,10 +10888,10 @@ var ea = class {
10864
10888
  }
10865
10889
  e[o + 1] = r;
10866
10890
  }
10867
- }, _a = ({ items: e, index: t, axis: n, direction: r }) => {
10891
+ }, va = ({ items: e, index: t, axis: n, direction: r }) => {
10868
10892
  let i = e[t];
10869
10893
  if (!i) return null;
10870
- let { bounds: a } = i, { start: o, end: s } = ha({
10894
+ let { bounds: a } = i, { start: o, end: s } = ga({
10871
10895
  bounds: a,
10872
10896
  axis: n
10873
10897
  });
@@ -10875,7 +10899,7 @@ var ea = class {
10875
10899
  for (let r = t - 1; r >= 0; --r) {
10876
10900
  let t = e[r];
10877
10901
  if (!t) continue;
10878
- let { bounds: i } = t, { end: a } = ha({
10902
+ let { bounds: i } = t, { end: a } = ga({
10879
10903
  bounds: i,
10880
10904
  axis: n
10881
10905
  });
@@ -10886,26 +10910,26 @@ var ea = class {
10886
10910
  for (let r = t + 1; r < e.length; r += 1) {
10887
10911
  let t = e[r];
10888
10912
  if (!t) continue;
10889
- let { bounds: i } = t, { start: a } = ha({
10913
+ let { bounds: i } = t, { start: a } = ga({
10890
10914
  bounds: i,
10891
10915
  axis: n
10892
10916
  });
10893
10917
  if (a - s >= 0) return r;
10894
10918
  }
10895
10919
  return null;
10896
- }, va = ({ items: e }) => {
10920
+ }, ya = ({ items: e }) => {
10897
10921
  for (let t = 0; t < e.length; t += 1) {
10898
10922
  let { isActive: n } = e[t];
10899
10923
  if (n) return t;
10900
10924
  }
10901
10925
  return -1;
10902
- }, ya = ({ patternAxis: e, activeRangeStart: t, activeRangeEnd: n, tolerance: r = 0 }) => {
10926
+ }, ba = ({ patternAxis: e, activeRangeStart: t, activeRangeEnd: n, tolerance: r = 0 }) => {
10903
10927
  let i = Math.min(t, n), a = Math.max(t, n);
10904
10928
  return e >= i - r && e <= a + r;
10905
- }, ba = ({ patternStart: e, patternEnd: t, activeStart: n, activeEnd: r }) => t <= n ? "before" : e >= r ? "after" : null, xa = ({ baseOption: e, candidateOption: t }) => {
10929
+ }, xa = ({ patternStart: e, patternEnd: t, activeStart: n, activeEnd: r }) => t <= n ? "before" : e >= r ? "after" : null, Sa = ({ baseOption: e, candidateOption: t }) => {
10906
10930
  let { delta: n, guide: { distance: r } } = e, { delta: i, guide: { distance: a } } = t;
10907
10931
  return n === i && r === a;
10908
- }, Sa = ({ options: e }) => {
10932
+ }, Ca = ({ options: e }) => {
10909
10933
  let t = e[0];
10910
10934
  for (let n = 1; n < e.length; n += 1) {
10911
10935
  let r = e[n];
@@ -10916,11 +10940,11 @@ var ea = class {
10916
10940
  r.diff === t.diff && Math.abs(r.delta) < Math.abs(t.delta) && (t = r);
10917
10941
  }
10918
10942
  return t;
10919
- }, Ca = ({ currentOption: e, nextOption: t }) => {
10943
+ }, wa = ({ currentOption: e, nextOption: t }) => {
10920
10944
  if (!e) return !0;
10921
10945
  let { contextDistance: n, diff: r, delta: i } = e, { contextDistance: a, diff: o, delta: s } = t;
10922
10946
  return a < n ? !0 : a > n ? !1 : o < r ? !0 : o > r ? !1 : Math.abs(s) < Math.abs(i);
10923
- }, wa = ({ options: e }) => {
10947
+ }, Ta = ({ options: e }) => {
10924
10948
  let t = [], n = null, r = null;
10925
10949
  for (let i of e) {
10926
10950
  let { kind: e, side: a } = i;
@@ -10928,18 +10952,18 @@ var ea = class {
10928
10952
  t.push(i);
10929
10953
  continue;
10930
10954
  }
10931
- a === "before" && Ca({
10955
+ a === "before" && wa({
10932
10956
  currentOption: n,
10933
10957
  nextOption: i
10934
- }) && (n = i), a === "after" && Ca({
10958
+ }) && (n = i), a === "after" && wa({
10935
10959
  currentOption: r,
10936
10960
  nextOption: i
10937
10961
  }) && (r = i);
10938
10962
  }
10939
10963
  return n && t.push(n), r && t.push(r), t;
10940
- }, Ta = ({ options: e, side: t, baseOption: n }) => {
10964
+ }, Ea = ({ options: e, side: t, baseOption: n }) => {
10941
10965
  let r = null;
10942
- for (let i of e) if (i.side === t && xa({
10966
+ for (let i of e) if (i.side === t && Sa({
10943
10967
  baseOption: n,
10944
10968
  candidateOption: i
10945
10969
  })) {
@@ -10950,63 +10974,63 @@ var ea = class {
10950
10974
  !r || i.diff !== r.diff || Math.abs(i.delta) < Math.abs(r.delta) && (r = i);
10951
10975
  }
10952
10976
  return r;
10953
- }, Ea = ({ option: e }) => {
10977
+ }, Da = ({ option: e }) => {
10954
10978
  let { side: t, kind: n, guide: { distance: r } } = e;
10955
10979
  return {
10956
10980
  side: t,
10957
10981
  kind: n,
10958
10982
  distance: r
10959
10983
  };
10960
- }, Da = ({ option: e, context: t }) => {
10984
+ }, Oa = ({ option: e, context: t }) => {
10961
10985
  let { side: n, kind: r, distance: i } = t, { side: a, kind: o, guide: { distance: s } } = e;
10962
10986
  return n !== a || r !== o ? !1 : Math.abs(s - i) <= 1;
10963
- }, Oa = ({ options: e, context: t }) => {
10987
+ }, ka = ({ options: e, context: t }) => {
10964
10988
  if (!t) return null;
10965
- for (let n of e) if (Da({
10989
+ for (let n of e) if (Oa({
10966
10990
  option: n,
10967
10991
  context: t
10968
10992
  })) return n;
10969
10993
  return null;
10970
- }, ka = ({ options: e, bestOption: t, previousContext: n, switchDistance: r = 0 }) => {
10971
- let i = Oa({
10994
+ }, Aa = ({ options: e, bestOption: t, previousContext: n, switchDistance: r = 0 }) => {
10995
+ let i = ka({
10972
10996
  options: e,
10973
10997
  context: n
10974
10998
  });
10975
10999
  if (!i) return t;
10976
11000
  let a = Math.max(0, r);
10977
11001
  return a === 0 || Math.abs(t.delta - i.delta) >= a ? t : i;
10978
- }, Aa = ({ guides: e, seenGuideKeys: t, guide: n }) => {
11002
+ }, ja = ({ guides: e, seenGuideKeys: t, guide: n }) => {
10979
11003
  let { type: r, axis: i, refStart: a, refEnd: o, activeStart: s, activeEnd: c, distance: l } = n, u = `${r}:${i}:${a}:${o}:${s}:${c}:${l}`;
10980
11004
  t.has(u) || (t.add(u), e.push(n));
10981
- }, ja = ({ options: e, previousContext: t = null, switchDistance: n = 0 }) => {
11005
+ }, Ma = ({ options: e, previousContext: t = null, switchDistance: n = 0 }) => {
10982
11006
  if (!e.length) return {
10983
11007
  delta: 0,
10984
11008
  guides: [],
10985
11009
  context: null
10986
11010
  };
10987
- let r = wa({ options: e }), i = [];
11011
+ let r = Ta({ options: e }), i = [];
10988
11012
  for (let e of r) e.kind === "reference" && i.push(e);
10989
- let a = i.length > 0, o = a ? i : r, s = ka({
11013
+ let a = i.length > 0, o = a ? i : r, s = Aa({
10990
11014
  options: o,
10991
- bestOption: Sa({ options: o }),
11015
+ bestOption: Ca({ options: o }),
10992
11016
  previousContext: t,
10993
11017
  switchDistance: n
10994
- }), c = Ta({
11018
+ }), c = Ea({
10995
11019
  options: o,
10996
11020
  side: "before",
10997
11021
  baseOption: s
10998
- }), l = Ta({
11022
+ }), l = Ea({
10999
11023
  options: o,
11000
11024
  side: "after",
11001
11025
  baseOption: s
11002
- }), u = Ta({
11026
+ }), u = Ea({
11003
11027
  options: a ? r : o,
11004
11028
  side: "center",
11005
11029
  baseOption: s
11006
11030
  }), d = [];
11007
11031
  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);
11008
11032
  let f = [], p = /* @__PURE__ */ new Set();
11009
- for (let e of d) Aa({
11033
+ for (let e of d) ja({
11010
11034
  guides: f,
11011
11035
  seenGuideKeys: p,
11012
11036
  guide: e.guide
@@ -11014,15 +11038,15 @@ var ea = class {
11014
11038
  return {
11015
11039
  delta: s.delta,
11016
11040
  guides: f,
11017
- context: Ea({ option: s })
11041
+ context: Da({ option: s })
11018
11042
  };
11019
- }, Ma = ({ activeStart: e, activeEnd: t, targetGap: n, beforeEdge: r, afterEdge: i, threshold: a, step: o }) => {
11020
- let s = n - (e - r), c = pa({
11043
+ }, Na = ({ activeStart: e, activeEnd: t, targetGap: n, beforeEdge: r, afterEdge: i, threshold: a, step: o }) => {
11044
+ let s = n - (e - r), c = ma({
11021
11045
  value: s,
11022
11046
  step: o
11023
11047
  }), l = Math.max(1, Math.ceil(a / Math.max(o, 1))), u = null;
11024
11048
  for (let d = -l; d <= l; d += 1) {
11025
- let l = c + d * o, f = e + l, p = t + l, m = f - r, h = i - p, { displayDistanceDiff: g, commonDisplayDistance: _ } = ua({
11049
+ let l = c + d * o, f = e + l, p = t + l, m = f - r, h = i - p, { displayDistanceDiff: g, commonDisplayDistance: _ } = da({
11026
11050
  firstDistance: m,
11027
11051
  secondDistance: h
11028
11052
  });
@@ -11037,13 +11061,13 @@ var ea = class {
11037
11061
  });
11038
11062
  }
11039
11063
  return u;
11040
- }, Na = ({ currentGap: e, referenceGap: t }) => {
11041
- let { secondDisplayDistance: n, displayDistanceDiff: r } = ua({
11064
+ }, Pa = ({ currentGap: e, referenceGap: t }) => {
11065
+ let { secondDisplayDistance: n, displayDistanceDiff: r } = da({
11042
11066
  firstDistance: e,
11043
11067
  secondDistance: t
11044
11068
  });
11045
11069
  return r > 1 ? null : n;
11046
- }, Pa = ({ anchors: e, positions: t, threshold: n }) => {
11070
+ }, Fa = ({ anchors: e, positions: t, threshold: n }) => {
11047
11071
  let r = 0, i = n + 1, a = null;
11048
11072
  for (let o of t) for (let t of e) {
11049
11073
  let e = Math.abs(t - o);
@@ -11053,8 +11077,8 @@ var ea = class {
11053
11077
  delta: r,
11054
11078
  guidePosition: a
11055
11079
  };
11056
- }, Fa = ({ activeBounds: e, threshold: t, anchors: n }) => {
11057
- let { left: r, right: i, centerX: a, top: o, bottom: s, centerY: c } = e, l = Pa({
11080
+ }, Ia = ({ activeBounds: e, threshold: t, anchors: n }) => {
11081
+ let { left: r, right: i, centerX: a, top: o, bottom: s, centerY: c } = e, l = Fa({
11058
11082
  anchors: n.vertical,
11059
11083
  positions: [
11060
11084
  r,
@@ -11062,7 +11086,7 @@ var ea = class {
11062
11086
  i
11063
11087
  ],
11064
11088
  threshold: t
11065
- }), u = Pa({
11089
+ }), u = Fa({
11066
11090
  anchors: n.horizontal,
11067
11091
  positions: [
11068
11092
  o,
@@ -11082,11 +11106,11 @@ var ea = class {
11082
11106
  deltaY: u.delta,
11083
11107
  guides: d
11084
11108
  };
11085
- }, Ia = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
11109
+ }, La = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
11086
11110
  let { centerX: o, top: s, bottom: c, left: l, right: u } = e, d = [];
11087
11111
  for (let e of t) {
11088
11112
  let { left: t, right: n } = e;
11089
- da({
11113
+ fa({
11090
11114
  firstStart: t,
11091
11115
  firstEnd: n,
11092
11116
  secondStart: l,
@@ -11106,22 +11130,22 @@ var ea = class {
11106
11130
  f.push({
11107
11131
  bounds: e,
11108
11132
  isActive: !0
11109
- }), ga({
11133
+ }), _a({
11110
11134
  items: f,
11111
11135
  axis: "top"
11112
11136
  });
11113
- let p = va({ items: f });
11137
+ let p = ya({ items: f });
11114
11138
  if (p === -1) return {
11115
11139
  delta: 0,
11116
11140
  guides: [],
11117
11141
  context: null
11118
11142
  };
11119
- let m = [], h = c - s, g = _a({
11143
+ let m = [], h = c - s, g = va({
11120
11144
  items: f,
11121
11145
  index: p,
11122
11146
  axis: "vertical",
11123
11147
  direction: "prev"
11124
- }), _ = _a({
11148
+ }), _ = va({
11125
11149
  items: f,
11126
11150
  index: p,
11127
11151
  axis: "vertical",
@@ -11130,19 +11154,19 @@ var ea = class {
11130
11154
  if (v && y) {
11131
11155
  let { bounds: e } = v, { bounds: t } = y, { bottom: r } = e, { top: i } = t, a = i - r - h;
11132
11156
  if (a >= 0) {
11133
- let e = pa({
11157
+ let e = ma({
11134
11158
  value: a / 2,
11135
11159
  step: 1
11136
11160
  }), t = s - r, l = i - c, u = Math.abs(t - e), d = Math.abs(l - e);
11137
11161
  if (Math.max(u, d) <= n) {
11138
- let t = Ma({
11162
+ let t = Na({
11139
11163
  activeStart: s,
11140
11164
  activeEnd: c,
11141
11165
  targetGap: e,
11142
11166
  beforeEdge: r,
11143
11167
  afterEdge: i,
11144
11168
  threshold: n,
11145
- step: ca
11169
+ step: la
11146
11170
  });
11147
11171
  if (t) {
11148
11172
  let { delta: e, distance: n, diff: i, activeStart: a, activeEnd: s } = t, c = {
@@ -11179,16 +11203,16 @@ var ea = class {
11179
11203
  }
11180
11204
  for (let e of r) {
11181
11205
  let { axis: t, start: r, end: i, distance: a } = e;
11182
- if (!ma({
11206
+ if (!ha({
11183
11207
  value: a,
11184
11208
  step: .5
11185
- }) || !ya({
11209
+ }) || !ba({
11186
11210
  patternAxis: t,
11187
11211
  activeRangeStart: l,
11188
11212
  activeRangeEnd: u,
11189
11213
  tolerance: n
11190
11214
  })) continue;
11191
- let d = ba({
11215
+ let d = xa({
11192
11216
  patternStart: r,
11193
11217
  patternEnd: i,
11194
11218
  activeStart: s,
@@ -11196,12 +11220,12 @@ var ea = class {
11196
11220
  });
11197
11221
  if (d) {
11198
11222
  if (b !== null && S && d === "before" && Math.abs(b - a) <= n) {
11199
- let e = pa({
11223
+ let e = ma({
11200
11224
  value: a - b,
11201
11225
  step: 1
11202
11226
  }), t = s + e, { bottom: c } = S, l = t - c, u = Math.abs(l - a);
11203
11227
  if (u > n) continue;
11204
- let d = Na({
11228
+ let d = Pa({
11205
11229
  currentGap: l,
11206
11230
  referenceGap: a
11207
11231
  });
@@ -11225,12 +11249,12 @@ var ea = class {
11225
11249
  });
11226
11250
  }
11227
11251
  if (x !== null && C && d === "after" && Math.abs(x - a) <= n) {
11228
- let e = pa({
11252
+ let e = ma({
11229
11253
  value: x - a,
11230
11254
  step: 1
11231
11255
  }), t = c + e, { top: s } = C, l = s - t, u = Math.abs(l - a);
11232
11256
  if (u > n) continue;
11233
- let d = Na({
11257
+ let d = Pa({
11234
11258
  currentGap: l,
11235
11259
  referenceGap: a
11236
11260
  });
@@ -11255,16 +11279,16 @@ var ea = class {
11255
11279
  }
11256
11280
  }
11257
11281
  }
11258
- return ja({
11282
+ return Ma({
11259
11283
  options: m,
11260
11284
  previousContext: i,
11261
11285
  switchDistance: a
11262
11286
  });
11263
- }, La = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
11287
+ }, Ra = ({ activeBounds: e, candidates: t, threshold: n, patterns: r, previousContext: i = null, switchDistance: a = 0 }) => {
11264
11288
  let { centerY: o, left: s, right: c, top: l, bottom: u } = e, d = [];
11265
11289
  for (let e of t) {
11266
11290
  let { top: t, bottom: n } = e;
11267
- da({
11291
+ fa({
11268
11292
  firstStart: t,
11269
11293
  firstEnd: n,
11270
11294
  secondStart: l,
@@ -11284,22 +11308,22 @@ var ea = class {
11284
11308
  f.push({
11285
11309
  bounds: e,
11286
11310
  isActive: !0
11287
- }), ga({
11311
+ }), _a({
11288
11312
  items: f,
11289
11313
  axis: "left"
11290
11314
  });
11291
- let p = va({ items: f });
11315
+ let p = ya({ items: f });
11292
11316
  if (p === -1) return {
11293
11317
  delta: 0,
11294
11318
  guides: [],
11295
11319
  context: null
11296
11320
  };
11297
- let m = [], h = c - s, g = _a({
11321
+ let m = [], h = c - s, g = va({
11298
11322
  items: f,
11299
11323
  index: p,
11300
11324
  axis: "horizontal",
11301
11325
  direction: "prev"
11302
- }), _ = _a({
11326
+ }), _ = va({
11303
11327
  items: f,
11304
11328
  index: p,
11305
11329
  axis: "horizontal",
@@ -11308,19 +11332,19 @@ var ea = class {
11308
11332
  if (v && y) {
11309
11333
  let { bounds: e } = v, { bounds: t } = y, { right: r } = e, { left: i } = t, a = i - r - h;
11310
11334
  if (a >= 0) {
11311
- let e = pa({
11335
+ let e = ma({
11312
11336
  value: a / 2,
11313
11337
  step: 1
11314
11338
  }), t = s - r, l = i - c, u = Math.abs(t - e), d = Math.abs(l - e);
11315
11339
  if (Math.max(u, d) <= n) {
11316
- let t = Ma({
11340
+ let t = Na({
11317
11341
  activeStart: s,
11318
11342
  activeEnd: c,
11319
11343
  targetGap: e,
11320
11344
  beforeEdge: r,
11321
11345
  afterEdge: i,
11322
11346
  threshold: n,
11323
- step: ca
11347
+ step: la
11324
11348
  });
11325
11349
  if (t) {
11326
11350
  let { delta: e, distance: n, diff: i, activeStart: a, activeEnd: s } = t, c = {
@@ -11357,16 +11381,16 @@ var ea = class {
11357
11381
  }
11358
11382
  for (let e of r) {
11359
11383
  let { axis: t, start: r, end: i, distance: a } = e;
11360
- if (!ma({
11384
+ if (!ha({
11361
11385
  value: a,
11362
11386
  step: .5
11363
- }) || !ya({
11387
+ }) || !ba({
11364
11388
  patternAxis: t,
11365
11389
  activeRangeStart: l,
11366
11390
  activeRangeEnd: u,
11367
11391
  tolerance: n
11368
11392
  })) continue;
11369
- let d = ba({
11393
+ let d = xa({
11370
11394
  patternStart: r,
11371
11395
  patternEnd: i,
11372
11396
  activeStart: s,
@@ -11374,12 +11398,12 @@ var ea = class {
11374
11398
  });
11375
11399
  if (d) {
11376
11400
  if (b !== null && S && d === "before" && Math.abs(b - a) <= n) {
11377
- let e = pa({
11401
+ let e = ma({
11378
11402
  value: a - b,
11379
11403
  step: 1
11380
11404
  }), t = s + e, { right: c } = S, l = t - c, u = Math.abs(l - a);
11381
11405
  if (u > n) continue;
11382
- let d = Na({
11406
+ let d = Pa({
11383
11407
  currentGap: l,
11384
11408
  referenceGap: a
11385
11409
  });
@@ -11403,12 +11427,12 @@ var ea = class {
11403
11427
  });
11404
11428
  }
11405
11429
  if (x !== null && C && d === "after" && Math.abs(x - a) <= n) {
11406
- let e = pa({
11430
+ let e = ma({
11407
11431
  value: x - a,
11408
11432
  step: 1
11409
11433
  }), t = c + e, { left: s } = C, l = s - t, u = Math.abs(l - a);
11410
11434
  if (u > n) continue;
11411
- let d = Na({
11435
+ let d = Pa({
11412
11436
  currentGap: l,
11413
11437
  referenceGap: a
11414
11438
  });
@@ -11433,20 +11457,20 @@ var ea = class {
11433
11457
  }
11434
11458
  }
11435
11459
  }
11436
- return ja({
11460
+ return Ma({
11437
11461
  options: m,
11438
11462
  previousContext: i,
11439
11463
  switchDistance: a
11440
11464
  });
11441
- }, Ra = ({ activeBounds: e, candidates: t, threshold: n, spacingPatterns: r, previousContexts: i, switchDistance: a = 0 }) => {
11442
- let { vertical: o = null, horizontal: s = null } = i ?? {}, c = Ia({
11465
+ }, za = ({ activeBounds: e, candidates: t, threshold: n, spacingPatterns: r, previousContexts: i, switchDistance: a = 0 }) => {
11466
+ let { vertical: o = null, horizontal: s = null } = i ?? {}, c = La({
11443
11467
  activeBounds: e,
11444
11468
  candidates: t,
11445
11469
  threshold: n,
11446
11470
  patterns: r.vertical,
11447
11471
  previousContext: o,
11448
11472
  switchDistance: a
11449
- }), l = La({
11473
+ }), l = Ra({
11450
11474
  activeBounds: e,
11451
11475
  candidates: t,
11452
11476
  threshold: n,
@@ -11465,14 +11489,14 @@ var ea = class {
11465
11489
  horizontal: l.context
11466
11490
  }
11467
11491
  };
11468
- }, za = ({ context: e, x: t, y: n, width: r, height: i, radius: a }) => {
11492
+ }, Ba = ({ context: e, x: t, y: n, width: r, height: i, radius: a }) => {
11469
11493
  let o = Math.min(a, r / 2, i / 2);
11470
11494
  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();
11471
- }, Ba = ({ 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 }) => {
11495
+ }, Va = ({ 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 }) => {
11472
11496
  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;
11473
11497
  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";
11474
11498
  let S = e.measureText(a).width + _ * 2, C = g + _ * 2, w = b - S / 2, T = x - C / 2;
11475
- e.beginPath(), za({
11499
+ e.beginPath(), Ba({
11476
11500
  context: e,
11477
11501
  x: w,
11478
11502
  y: T,
@@ -11480,11 +11504,11 @@ var ea = class {
11480
11504
  height: C,
11481
11505
  radius: v
11482
11506
  }), e.fill(), e.fillStyle = c, e.fillText(a, b, x), e.restore();
11483
- }, Va = ({ context: e, guide: t, zoom: n }) => {
11484
- let { type: r, axis: i, refStart: a, refEnd: o, activeStart: s, activeEnd: c, distance: l } = t, u = la({ distance: l }).toString();
11507
+ }, Ha = ({ context: e, guide: t, zoom: n }) => {
11508
+ let { type: r, axis: i, refStart: a, refEnd: o, activeStart: s, activeEnd: c, distance: l } = t, u = ua({ distance: l }).toString();
11485
11509
  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();
11486
- let d = sa;
11487
- Ba({
11510
+ let d = ca;
11511
+ Va({
11488
11512
  context: e,
11489
11513
  type: r,
11490
11514
  axis: i,
@@ -11494,7 +11518,7 @@ var ea = class {
11494
11518
  zoom: n,
11495
11519
  color: d,
11496
11520
  lineWidth: 1
11497
- }), Ba({
11521
+ }), Va({
11498
11522
  context: e,
11499
11523
  type: r,
11500
11524
  axis: i,
@@ -11505,10 +11529,10 @@ var ea = class {
11505
11529
  color: d,
11506
11530
  lineWidth: 1
11507
11531
  });
11508
- }, Ha = ({ anchors: e, bounds: t }) => {
11532
+ }, Ua = ({ anchors: e, bounds: t }) => {
11509
11533
  let { left: n, right: r, centerX: i, top: a, bottom: o, centerY: s } = t;
11510
11534
  e.vertical.push(n, i, r), e.horizontal.push(a, s, o);
11511
- }, Ua = ({ bounds: e, type: t, primaryStart: n, primaryEnd: r }) => {
11535
+ }, Wa = ({ bounds: e, type: t, primaryStart: n, primaryEnd: r }) => {
11512
11536
  let i = [], a = n === "top" ? "left" : "top", o = r === "bottom" ? "right" : "bottom", s = [...e].sort((e, t) => e[n] - t[n]);
11513
11537
  for (let e = 0; e < s.length; e += 1) {
11514
11538
  let c = s[e], l = null, u = Infinity;
@@ -11529,35 +11553,35 @@ var ea = class {
11529
11553
  });
11530
11554
  }
11531
11555
  return i;
11532
- }, Wa = ({ bounds: e }) => ({
11533
- vertical: Ua({
11556
+ }, Ga = ({ bounds: e }) => ({
11557
+ vertical: Wa({
11534
11558
  bounds: e,
11535
11559
  axis: "centerX",
11536
11560
  type: "vertical",
11537
11561
  primaryStart: "top",
11538
11562
  primaryEnd: "bottom"
11539
11563
  }),
11540
- horizontal: Ua({
11564
+ horizontal: Wa({
11541
11565
  bounds: e,
11542
11566
  axis: "centerY",
11543
11567
  type: "horizontal",
11544
11568
  primaryStart: "left",
11545
11569
  primaryEnd: "right"
11546
11570
  })
11547
- }), Ga = [
11571
+ }), Ka = [
11548
11572
  "montage-area",
11549
11573
  "background",
11550
11574
  "interaction-blocker"
11551
- ], Ka = ({ activeObject: t }) => {
11575
+ ], qa = ({ activeObject: t }) => {
11552
11576
  let n = /* @__PURE__ */ new Set();
11553
11577
  return t ? (n.add(t), t instanceof e && t.getObjects().forEach((e) => n.add(e)), n) : n;
11554
- }, qa = ({ object: e, excluded: t, ignoredIds: n = Ga }) => {
11578
+ }, Ja = ({ object: e, excluded: t, ignoredIds: n = Ka }) => {
11555
11579
  if (t.has(e)) return !0;
11556
11580
  let { visible: r = !0 } = e;
11557
11581
  if (!r) return !0;
11558
11582
  let { id: i } = e;
11559
11583
  return !!(i && n.includes(i));
11560
- }, Ja = class e {
11584
+ }, Ya = class e {
11561
11585
  constructor({ editor: e }) {
11562
11586
  this.anchors = {
11563
11587
  vertical: [],
@@ -11610,7 +11634,7 @@ var ea = class {
11610
11634
  this._clearSpacingContexts(), this._clearGuides();
11611
11635
  return;
11612
11636
  }
11613
- let { canvas: o } = this, s = o.getZoom() || 1, c = 5 / s, { deltaX: l, deltaY: u } = Fa({
11637
+ let { canvas: o } = this, s = o.getZoom() || 1, c = 5 / s, { deltaX: l, deltaY: u } = Ia({
11614
11638
  activeBounds: a,
11615
11639
  threshold: c,
11616
11640
  anchors: this.anchors
@@ -11622,7 +11646,7 @@ var ea = class {
11622
11646
  top: t + u
11623
11647
  }), n.setCoords(), a = Vt({ object: n }) ?? a;
11624
11648
  }
11625
- let d = this._resolveCurrentTargetBounds({ activeObject: n }), f = this.spacingContexts.vertical || this.spacingContexts.horizontal ? 10 / s : c, p = Ra({
11649
+ let d = this._resolveCurrentTargetBounds({ activeObject: n }), f = this.spacingContexts.vertical || this.spacingContexts.horizontal ? 10 / s : c, p = za({
11626
11650
  activeBounds: a,
11627
11651
  candidates: d,
11628
11652
  threshold: f,
@@ -11643,11 +11667,11 @@ var ea = class {
11643
11667
  target: n,
11644
11668
  transform: i
11645
11669
  });
11646
- let h = Vt({ object: n }) ?? a, g = Fa({
11670
+ let h = Vt({ object: n }) ?? a, g = Ia({
11647
11671
  activeBounds: h,
11648
11672
  threshold: c,
11649
11673
  anchors: this.anchors
11650
- }), _ = Ra({
11674
+ }), _ = za({
11651
11675
  activeBounds: h,
11652
11676
  candidates: d,
11653
11677
  threshold: c,
@@ -11878,9 +11902,9 @@ var ea = class {
11878
11902
  let { canvas: e, guideBounds: t } = this, n = e.getSelectionContext();
11879
11903
  if (!n) return;
11880
11904
  let { left: r, right: i, top: a, bottom: o } = t ?? this._calculateViewportBounds(), { viewportTransform: s } = e, c = e.getZoom() || 1;
11881
- n.save(), Array.isArray(s) && n.transform(...s), n.lineWidth = 1 / c, n.strokeStyle = sa, n.setLineDash([4, 4]);
11905
+ n.save(), Array.isArray(s) && n.transform(...s), n.lineWidth = 1 / c, n.strokeStyle = ca, n.setLineDash([4, 4]);
11882
11906
  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();
11883
- for (let e of this.activeSpacingGuides) Va({
11907
+ for (let e of this.activeSpacingGuides) Ha({
11884
11908
  context: n,
11885
11909
  guide: e,
11886
11910
  zoom: c
@@ -12091,14 +12115,14 @@ var ea = class {
12091
12115
  }, r = [];
12092
12116
  for (let e of t) {
12093
12117
  let t = Vt({ object: e });
12094
- t && (Ha({
12118
+ t && (Ua({
12095
12119
  anchors: n,
12096
12120
  bounds: t
12097
12121
  }), r.push(t));
12098
12122
  }
12099
12123
  let { montageArea: i } = this.editor, a = Vt({ object: i });
12100
12124
  if (a) {
12101
- Ha({
12125
+ Ua({
12102
12126
  anchors: n,
12103
12127
  bounds: a
12104
12128
  });
@@ -12110,12 +12134,12 @@ var ea = class {
12110
12134
  bottom: i
12111
12135
  };
12112
12136
  } else this.guideBounds = this._calculateViewportBounds();
12113
- this.anchors = n, this.spacingPatterns = Wa({ bounds: r }), this.cachedTargetBounds = r;
12137
+ this.anchors = n, this.spacingPatterns = Ga({ bounds: r }), this.cachedTargetBounds = r;
12114
12138
  }
12115
12139
  _collectTargets({ activeObject: e }) {
12116
- let t = Ka({ activeObject: e }), n = [];
12140
+ let t = qa({ activeObject: e }), n = [];
12117
12141
  return this.canvas.forEachObject((e) => {
12118
- qa({
12142
+ Ja({
12119
12143
  object: e,
12120
12144
  excluded: t
12121
12145
  }) || n.push(e);
@@ -12138,7 +12162,7 @@ var ea = class {
12138
12162
  bottom: (r - s) / a
12139
12163
  };
12140
12164
  }
12141
- }, Ya = "#3D8BF4", Xa = class e {
12165
+ }, Xa = "#3D8BF4", Za = class e {
12142
12166
  constructor({ editor: e }) {
12143
12167
  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();
12144
12168
  }
@@ -12231,8 +12255,8 @@ var ea = class {
12231
12255
  this.isTargetMontageArea = l, this.activeGuides = d, this._hideToolbar(), n.requestRenderAll();
12232
12256
  }
12233
12257
  static _resolveTarget({ event: e, activeObject: t }) {
12234
- let { target: n } = e, r = Ka({ activeObject: t });
12235
- return n && !qa({
12258
+ let { target: n } = e, r = qa({ activeObject: t });
12259
+ return n && !Ja({
12236
12260
  object: n,
12237
12261
  excluded: r
12238
12262
  }) ? n : null;
@@ -12349,18 +12373,18 @@ var ea = class {
12349
12373
  let { canvas: e } = this, t = e.getSelectionContext();
12350
12374
  if (!t) return;
12351
12375
  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;
12352
- t.save(), Array.isArray(n) && t.transform(...n), t.lineWidth = 1 / r, t.strokeStyle = Ya, t.setLineDash([]);
12376
+ t.save(), Array.isArray(n) && t.transform(...n), t.lineWidth = 1 / r, t.strokeStyle = Xa, t.setLineDash([]);
12353
12377
  for (let e of this.activeGuides) {
12354
12378
  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;
12355
- t.beginPath(), n === "vertical" ? (t.moveTo(i, a), t.lineTo(i, c)) : (t.moveTo(a, i), t.lineTo(c, i)), t.stroke(), Ba({
12379
+ t.beginPath(), n === "vertical" ? (t.moveTo(i, a), t.lineTo(i, c)) : (t.moveTo(a, i), t.lineTo(c, i)), t.stroke(), Va({
12356
12380
  context: t,
12357
12381
  type: n,
12358
12382
  axis: i,
12359
12383
  start: a,
12360
12384
  end: c,
12361
- text: la({ distance: l }).toString(),
12385
+ text: ua({ distance: l }).toString(),
12362
12386
  zoom: r,
12363
- color: Ya,
12387
+ color: Xa,
12364
12388
  lineWidth: 1,
12365
12389
  offsetAlongAxis: d,
12366
12390
  offsetPerpendicular: 0
@@ -12378,13 +12402,13 @@ var ea = class {
12378
12402
  let { toolbar: e } = this.editor;
12379
12403
  e?.showAfterTemporary?.(), this.isToolbarHidden = !1;
12380
12404
  }
12381
- }, Za = class e {
12405
+ }, Qa = class e {
12382
12406
  constructor(e, t) {
12383
12407
  this.options = t, this.containerId = e, this.editorId = `${e}-${O()}`, this.init();
12384
12408
  }
12385
12409
  async init() {
12386
12410
  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;
12387
- if (U.apply(), this.canvas = new t(this.containerId, this.options), this.moduleLoader = new j(), this.workerManager = new N(), this.errorManager = new Fi({ editor: this }), this.historyManager = new Ct({ editor: this }), this.toolbar = new Je({ editor: this }), this.transformManager = new Pt({ editor: this }), this.zoomManager = new Ft({ editor: this }), this.canvasManager = new Nt({ editor: this }), this.imageManager = new kt({ editor: this }), this.layerManager = new Kt({ editor: this }), this.shapeManager = new Oi({ editor: this }), this.interactionBlocker = new Wt({ editor: this }), this.backgroundManager = new Gt({ editor: this }), this.clipboardManager = new ki({ editor: this }), this.objectLockManager = new Ai({ editor: this }), this.groupingManager = new ji({ editor: this }), this.selectionManager = new Mi({ editor: this }), this.deletionManager = new Ni({ editor: this }), this.panConstraintManager = new Ii({ editor: this }), this.snappingManager = new Ja({ editor: this }), this.measurementManager = new Xa({ editor: this }), this.fontManager = new se(this.options.fonts ?? []), this.textManager = new ta({ editor: this }), this.templateManager = new oa({ editor: this }), u && (this.angleIndicator = new Ze({ editor: this })), this._createMontageArea(), this._createClippingArea(), this.interactionBlocker.ensureOverlay(), this.listeners = new A({
12411
+ if (U.apply(), this.canvas = new t(this.containerId, this.options), this.moduleLoader = new j(), this.workerManager = new N(), this.errorManager = new Ii({ editor: this }), this.historyManager = new Ct({ editor: this }), this.toolbar = new Je({ editor: this }), this.transformManager = new Pt({ editor: this }), this.zoomManager = new Ft({ editor: this }), this.canvasManager = new Nt({ editor: this }), this.imageManager = new kt({ editor: this }), this.layerManager = new Kt({ editor: this }), this.shapeManager = new Oi({ editor: this }), this.interactionBlocker = new Wt({ editor: this }), this.backgroundManager = new Gt({ editor: this }), this.clipboardManager = new Ai({ editor: this }), this.objectLockManager = new ji({ editor: this }), this.groupingManager = new Mi({ editor: this }), this.selectionManager = new Ni({ editor: this }), this.deletionManager = new Pi({ editor: this }), this.panConstraintManager = new Li({ editor: this }), this.snappingManager = new Ya({ editor: this }), this.measurementManager = new Za({ editor: this }), this.fontManager = new se(this.options.fonts ?? []), this.textManager = new na({ editor: this }), this.templateManager = new sa({ editor: this }), u && (this.angleIndicator = new Ze({ editor: this })), this._createMontageArea(), this._createClippingArea(), this.interactionBlocker.ensureOverlay(), this.listeners = new A({
12388
12412
  editor: this,
12389
12413
  options: this.options
12390
12414
  }), 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) {
@@ -12492,7 +12516,7 @@ var ea = class {
12492
12516
  "U+A640-A69F",
12493
12517
  "U+FE2E-FE2F",
12494
12518
  "U+2116"
12495
- ].join(", "), Qa = {
12519
+ ].join(", "), $a = {
12496
12520
  preserveObjectStacking: !0,
12497
12521
  controlsAboveOverlay: !0,
12498
12522
  centeredRotation: !0,
@@ -13346,20 +13370,20 @@ var ea = class {
13346
13370
  };
13347
13371
  //#endregion
13348
13372
  //#region src/main.ts
13349
- function $a(e, t = {}) {
13373
+ function eo(e, t = {}) {
13350
13374
  let n = {
13351
- ...Qa,
13375
+ ...$a,
13352
13376
  ...t
13353
13377
  }, r = document.getElementById(e);
13354
13378
  if (!r) return Promise.reject(/* @__PURE__ */ Error(`Контейнер с ID "${e}" не найден.`));
13355
13379
  let i = document.createElement("canvas");
13356
13380
  return i.id = `${e}-canvas`, r.appendChild(i), n.editorContainer = r, new Promise((t) => {
13357
13381
  n._onReadyCallback = t;
13358
- let r = new Za(i.id, n);
13382
+ let r = new Qa(i.id, n);
13359
13383
  window[e] = r;
13360
13384
  });
13361
13385
  }
13362
13386
  //#endregion
13363
- export { $a as default };
13387
+ export { eo as default };
13364
13388
 
13365
13389
  //# sourceMappingURL=main.js.map