@pixldocs/canvas-renderer 0.5.33 → 0.5.35

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/index.cjs CHANGED
@@ -2769,45 +2769,16 @@ const clearFontCacheAndRerender = (canvas) => {
2769
2769
  if (beforeMetrics.length > 0) {
2770
2770
  logUnderlineDebug("before-rerender", beforeMetrics);
2771
2771
  }
2772
- const fixTextbox = (obj) => {
2773
- var _a, _b, _c;
2772
+ const markDirty = (obj) => {
2773
+ var _a;
2774
2774
  if (obj instanceof fabric__namespace.Textbox) {
2775
- const savedWidth = obj.width;
2776
- const savedScaleX = obj.scaleX;
2777
- const savedScaleY = obj.scaleY;
2778
- obj._forceClearCache = true;
2779
- obj.initDimensions();
2780
- if (savedWidth != null) {
2781
- obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY });
2782
- obj._forceClearCache = true;
2783
- obj.initDimensions();
2784
- obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY, dirty: true });
2785
- }
2786
- if (obj.underline) {
2787
- const lineWidths = obj.__lineWidths;
2788
- logUnderlineDebug("textbox-rerender", {
2789
- id: getObjectId(obj) ?? null,
2790
- text: (obj.text || "").slice(0, 120),
2791
- fontFamily: obj.fontFamily,
2792
- fontSize: obj.fontSize,
2793
- savedWidth,
2794
- finalWidth: obj.width ?? null,
2795
- finalHeight: obj.height ?? null,
2796
- scaleX: obj.scaleX,
2797
- scaleY: obj.scaleY,
2798
- lineCount: ((_a = obj.textLines) == null ? void 0 : _a.length) ?? 0,
2799
- maxLineWidth: lineWidths && lineWidths.length > 0 ? Math.max(...lineWidths) : null
2800
- });
2801
- }
2802
- (_b = obj._clearCache) == null ? void 0 : _b.call(obj);
2803
- obj.setCoords();
2775
+ obj.dirty = true;
2804
2776
  } else if (obj instanceof fabric__namespace.Group) {
2805
- (_c = obj._objects) == null ? void 0 : _c.forEach(fixTextbox);
2777
+ (_a = obj._objects) == null ? void 0 : _a.forEach(markDirty);
2806
2778
  obj.dirty = true;
2807
- obj.setCoords();
2808
2779
  }
2809
2780
  };
2810
- canvas.getObjects().forEach(fixTextbox);
2781
+ canvas.getObjects().forEach(markDirty);
2811
2782
  const afterMetrics = canvas.getObjects().flatMap(collectUnderlineMetrics);
2812
2783
  if (afterMetrics.length > 0) {
2813
2784
  logUnderlineDebug("after-rerender", afterMetrics);
@@ -12774,8 +12745,33 @@ class PixldocsRenderer {
12774
12745
  clearFabricCharCache();
12775
12746
  clearMeasurementCache();
12776
12747
  };
12748
+ const resyncTextboxWidths = (obj) => {
12749
+ if (obj instanceof fabric__namespace.Textbox) {
12750
+ const savedWidth = Math.max(1, obj.width ?? 0);
12751
+ const savedScaleX = obj.scaleX ?? 1;
12752
+ const savedScaleY = obj.scaleY ?? 1;
12753
+ obj.initDimensions();
12754
+ if (Math.abs((obj.width ?? 0) - savedWidth) > 0.01) {
12755
+ obj.width = savedWidth;
12756
+ }
12757
+ if (Math.abs((obj.scaleX ?? 1) - savedScaleX) > 0.01) {
12758
+ obj.scaleX = savedScaleX;
12759
+ }
12760
+ if (Math.abs((obj.scaleY ?? 1) - savedScaleY) > 0.01) {
12761
+ obj.scaleY = savedScaleY;
12762
+ }
12763
+ obj.setCoords();
12764
+ obj.dirty = true;
12765
+ return;
12766
+ }
12767
+ if (obj instanceof fabric__namespace.Group) {
12768
+ obj.getObjects().forEach(resyncTextboxWidths);
12769
+ obj.dirty = true;
12770
+ }
12771
+ };
12777
12772
  clearTextMetricCaches();
12778
12773
  await waitForPaint();
12774
+ fabricInstance.getObjects().forEach(resyncTextboxWidths);
12779
12775
  (_a = fabricInstance.calcOffset) == null ? void 0 : _a.call(fabricInstance);
12780
12776
  (_b = fabricInstance.renderAll) == null ? void 0 : _b.call(fabricInstance);
12781
12777
  (_c = fabricInstance.requestRenderAll) == null ? void 0 : _c.call(fabricInstance);