@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.js CHANGED
@@ -2750,45 +2750,16 @@ const clearFontCacheAndRerender = (canvas) => {
2750
2750
  if (beforeMetrics.length > 0) {
2751
2751
  logUnderlineDebug("before-rerender", beforeMetrics);
2752
2752
  }
2753
- const fixTextbox = (obj) => {
2754
- var _a, _b, _c;
2753
+ const markDirty = (obj) => {
2754
+ var _a;
2755
2755
  if (obj instanceof fabric.Textbox) {
2756
- const savedWidth = obj.width;
2757
- const savedScaleX = obj.scaleX;
2758
- const savedScaleY = obj.scaleY;
2759
- obj._forceClearCache = true;
2760
- obj.initDimensions();
2761
- if (savedWidth != null) {
2762
- obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY });
2763
- obj._forceClearCache = true;
2764
- obj.initDimensions();
2765
- obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY, dirty: true });
2766
- }
2767
- if (obj.underline) {
2768
- const lineWidths = obj.__lineWidths;
2769
- logUnderlineDebug("textbox-rerender", {
2770
- id: getObjectId(obj) ?? null,
2771
- text: (obj.text || "").slice(0, 120),
2772
- fontFamily: obj.fontFamily,
2773
- fontSize: obj.fontSize,
2774
- savedWidth,
2775
- finalWidth: obj.width ?? null,
2776
- finalHeight: obj.height ?? null,
2777
- scaleX: obj.scaleX,
2778
- scaleY: obj.scaleY,
2779
- lineCount: ((_a = obj.textLines) == null ? void 0 : _a.length) ?? 0,
2780
- maxLineWidth: lineWidths && lineWidths.length > 0 ? Math.max(...lineWidths) : null
2781
- });
2782
- }
2783
- (_b = obj._clearCache) == null ? void 0 : _b.call(obj);
2784
- obj.setCoords();
2756
+ obj.dirty = true;
2785
2757
  } else if (obj instanceof fabric.Group) {
2786
- (_c = obj._objects) == null ? void 0 : _c.forEach(fixTextbox);
2758
+ (_a = obj._objects) == null ? void 0 : _a.forEach(markDirty);
2787
2759
  obj.dirty = true;
2788
- obj.setCoords();
2789
2760
  }
2790
2761
  };
2791
- canvas.getObjects().forEach(fixTextbox);
2762
+ canvas.getObjects().forEach(markDirty);
2792
2763
  const afterMetrics = canvas.getObjects().flatMap(collectUnderlineMetrics);
2793
2764
  if (afterMetrics.length > 0) {
2794
2765
  logUnderlineDebug("after-rerender", afterMetrics);
@@ -12755,8 +12726,33 @@ class PixldocsRenderer {
12755
12726
  clearFabricCharCache();
12756
12727
  clearMeasurementCache();
12757
12728
  };
12729
+ const resyncTextboxWidths = (obj) => {
12730
+ if (obj instanceof fabric.Textbox) {
12731
+ const savedWidth = Math.max(1, obj.width ?? 0);
12732
+ const savedScaleX = obj.scaleX ?? 1;
12733
+ const savedScaleY = obj.scaleY ?? 1;
12734
+ obj.initDimensions();
12735
+ if (Math.abs((obj.width ?? 0) - savedWidth) > 0.01) {
12736
+ obj.width = savedWidth;
12737
+ }
12738
+ if (Math.abs((obj.scaleX ?? 1) - savedScaleX) > 0.01) {
12739
+ obj.scaleX = savedScaleX;
12740
+ }
12741
+ if (Math.abs((obj.scaleY ?? 1) - savedScaleY) > 0.01) {
12742
+ obj.scaleY = savedScaleY;
12743
+ }
12744
+ obj.setCoords();
12745
+ obj.dirty = true;
12746
+ return;
12747
+ }
12748
+ if (obj instanceof fabric.Group) {
12749
+ obj.getObjects().forEach(resyncTextboxWidths);
12750
+ obj.dirty = true;
12751
+ }
12752
+ };
12758
12753
  clearTextMetricCaches();
12759
12754
  await waitForPaint();
12755
+ fabricInstance.getObjects().forEach(resyncTextboxWidths);
12760
12756
  (_a = fabricInstance.calcOffset) == null ? void 0 : _a.call(fabricInstance);
12761
12757
  (_b = fabricInstance.renderAll) == null ? void 0 : _b.call(fabricInstance);
12762
12758
  (_c = fabricInstance.requestRenderAll) == null ? void 0 : _c.call(fabricInstance);