@twick/2d 0.15.20 → 0.15.21

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
@@ -9294,7 +9294,11 @@ var TxtLeaf = class extends Shape {
9294
9294
  }
9295
9295
  const fontOffset = context.measureText("").fontBoundingBoxAscent;
9296
9296
  const parentRect = this.element.getBoundingClientRect();
9297
- const { width, height } = this.size();
9297
+ const fullRange = document.createRange();
9298
+ fullRange.selectNodeContents(this.element);
9299
+ const fullRect = fullRange.getBoundingClientRect();
9300
+ const centerX = (fullRect.left + fullRect.right) / 2;
9301
+ const centerY = (fullRect.top + fullRect.bottom) / 2;
9298
9302
  const range = document.createRange();
9299
9303
  let line = "";
9300
9304
  const lineRect = new BBox17();
@@ -9304,8 +9308,8 @@ var TxtLeaf = class extends Shape {
9304
9308
  }
9305
9309
  range.selectNodeContents(childNode);
9306
9310
  const rangeRect = range.getBoundingClientRect();
9307
- const x = width / -2 + rangeRect.left - parentRect.left;
9308
- const y = height / -2 + rangeRect.top - parentRect.top + fontOffset;
9311
+ const x = rangeRect.left - centerX;
9312
+ const y = rangeRect.top - centerY + fontOffset;
9309
9313
  if (lineRect.y === y) {
9310
9314
  lineRect.width += rangeRect.width;
9311
9315
  line += childNode.textContent;