@anu3ev/fabric-image-editor 0.8.9 → 0.8.11

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 +53 -34
  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) => {
@@ -10394,16 +10413,16 @@ var ea = class {
10394
10413
  bounds: m,
10395
10414
  baseWidth: g,
10396
10415
  baseHeight: _
10397
- })), y = {
10416
+ })), y = typeof r.previewId == "string" ? r.previewId : void 0, b = {
10398
10417
  ...r,
10399
10418
  baseWidth: g,
10400
10419
  baseHeight: _,
10401
10420
  positionsNormalized: !0,
10402
- previewId: n ?? r.previewId
10421
+ previewId: n ?? y
10403
10422
  };
10404
10423
  return {
10405
10424
  id: e ?? `template-${O()}`,
10406
- meta: y,
10425
+ meta: b,
10407
10426
  objects: v
10408
10427
  };
10409
10428
  }
@@ -10494,17 +10513,20 @@ var ea = class {
10494
10513
  if (!e) return null;
10495
10514
  try {
10496
10515
  e.setCoords();
10497
- let t = e.getBoundingRect(!1, !0);
10516
+ let n = t._getBoundingRect(e);
10498
10517
  return {
10499
- left: t.left,
10500
- top: t.top,
10501
- width: t.width,
10502
- height: t.height
10518
+ left: n.left,
10519
+ top: n.top,
10520
+ width: n.width,
10521
+ height: n.height
10503
10522
  };
10504
10523
  } catch {
10505
10524
  return null;
10506
10525
  }
10507
10526
  }
10527
+ static _getBoundingRect(e) {
10528
+ return e.getBoundingRect(!1, !0);
10529
+ }
10508
10530
  static async _enlivenObjects(e) {
10509
10531
  return (await Promise.all(e.map(async (e) => {
10510
10532
  if (t._hasSerializedSvgMarkup(e)) {
@@ -10589,20 +10611,20 @@ var ea = class {
10589
10611
  return e.format === "svg";
10590
10612
  }
10591
10613
  static _extractSvgMarkup(e) {
10592
- let t = e.toSVG;
10593
- if (typeof t != "function") return null;
10614
+ let n = e.toSVG;
10615
+ if (typeof n != "function") return null;
10594
10616
  try {
10595
- let n = t.call(e);
10596
- if (!n) return null;
10597
- if (/<svg[\s>]/i.test(n)) return n;
10598
- let { width: r, height: i } = e.getBoundingRect(!1, !0), a = r || e.width || 0, o = i || e.height || 0;
10617
+ let r = n.call(e);
10618
+ if (!r) return null;
10619
+ if (/<svg[\s>]/i.test(r)) return r;
10620
+ let { width: i, height: a } = t._getBoundingRect(e), o = i || e.width || 0, s = a || e.height || 0;
10599
10621
  return `
10600
10622
  <svg
10601
10623
  xmlns="http://www.w3.org/2000/svg"
10602
- width="${a}"
10603
- height="${o}"
10604
- viewBox="0 0 ${a} ${o}">
10605
- ${n}
10624
+ width="${o}"
10625
+ height="${s}"
10626
+ viewBox="0 0 ${o} ${s}">
10627
+ ${r}
10606
10628
  </svg>
10607
10629
  `;
10608
10630
  } catch {
@@ -10645,7 +10667,7 @@ var ea = class {
10645
10667
  originX: _,
10646
10668
  originY: v
10647
10669
  }
10648
- }), delete s[ia], delete s[aa];
10670
+ }), delete s._templateAnchorX, delete s._templateAnchorY;
10649
10671
  }
10650
10672
  static _getPositioningBounds({ bounds: e, baseWidth: n, baseHeight: r, scale: i, useRelativePositions: a, anchorX: o, anchorY: s }) {
10651
10673
  if (!a) return e;
@@ -10698,26 +10720,23 @@ var ea = class {
10698
10720
  let r = typeof e.text == "string" ? e.text : "";
10699
10721
  if (!r) return;
10700
10722
  let i = It({
10701
- value: this.editor?.montageArea?.width,
10702
- fallback: 0
10703
- }), { width: a = 0 } = e, o = It({
10704
10723
  value: n,
10705
10724
  fallback: 0
10706
- }), s = It({
10707
- value: a,
10725
+ }), a = It({
10726
+ value: e.width,
10708
10727
  fallback: 0
10709
10728
  });
10710
- if (!i || !s || !o) return;
10729
+ if (!i || !a) return;
10711
10730
  e.setCoords();
10712
- let c = e, l = t._resolveAnchor(c, ia), 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;
10731
+ 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;
10713
10732
  e.set("width", i), e.initDimensions();
10714
- let g = t._getLongestLineWidth({
10733
+ let h = t._getLongestLineWidth({
10715
10734
  textbox: e,
10716
10735
  text: r
10717
- }), _ = g > s ? g + 1 : s;
10718
- if (e.set("width", _), e.initDimensions(), e.setPositionByOrigin(p, d, f), e.setCoords(), u === null) return;
10719
- let y = e.getBoundingRect(!1, !0), b = y.left + y.width, x = u;
10720
- l === "start" ? x += (m.left - y.left) / o : l === "end" && (x += (h - b) / o), c.left = x;
10736
+ }), g = h > a ? h + 1 : a;
10737
+ if (e.set("width", g), e.initDimensions(), e.setPositionByOrigin(d, l, u), e.setCoords(), c === null) return;
10738
+ let _ = t._getBoundingRect(e), y = _.left + _.width / 2, b = _.left + _.width, x = c;
10739
+ s === "start" ? x += (f.left - _.left) / i : s === "center" ? x += (p - y) / i : s === "end" && (x += (m - b) / i), e.left = x;
10721
10740
  }
10722
10741
  static _getLongestLineWidth({ textbox: e, text: t }) {
10723
10742
  let { textLines: n } = e, r = Array.isArray(n) && n.length > 0 ? n.length : Math.max(t.split("\n").length, 1), i = 0;
@@ -10734,7 +10753,7 @@ var ea = class {
10734
10753
  n && (a.svgMarkup = n, delete a.objects, delete a.path);
10735
10754
  }
10736
10755
  if (!n) return a;
10737
- let { left: o, top: s, width: c, height: l } = n, u = e.getBoundingRect(!1, !0), d = r || c || 1, f = i || l || 1, p = this.editor.canvasManager.getObjectPlacement({ object: e }), m = {
10756
+ let { left: o, top: s, width: c, height: l } = n, u = t._getBoundingRect(e), d = r || c || 1, f = i || l || 1, p = this.editor.canvasManager.getObjectPlacement({ object: e }), m = {
10738
10757
  x: (p.left - o) / d,
10739
10758
  y: (p.top - s) / f
10740
10759
  }, h = (u.left - o) / d, g = (u.top - s) / f, _ = h + u.width / d, v = g + u.height / f;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anu3ev/fabric-image-editor",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
4
4
  "description": "TypeScript image editor library built on FabricJS, allowing you to create instances with an integrated montage area and providing an API to modify and manage state.",
5
5
  "module": "dist/main.js",
6
6
  "files": [