leafer-draw 1.4.2 → 1.5.0

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/web.cjs CHANGED
@@ -2166,13 +2166,14 @@ function toChar(data, charX, rowData, isOverflow) {
2166
2166
  }
2167
2167
 
2168
2168
  function layoutText(drawData, style) {
2169
- const { rows, bounds } = drawData;
2169
+ const { rows, bounds } = drawData, countRows = rows.length;
2170
2170
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
2171
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2171
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2172
2172
  let starY = __baseLine;
2173
2173
  if (__clipText && realHeight > height) {
2174
2174
  realHeight = Math.max(height, __lineHeight);
2175
- drawData.overflow = rows.length;
2175
+ if (countRows > 1)
2176
+ drawData.overflow = countRows;
2176
2177
  }
2177
2178
  else if (height || autoSizeAlign) {
2178
2179
  switch (verticalAlign) {
@@ -2184,7 +2185,7 @@ function layoutText(drawData, style) {
2184
2185
  }
2185
2186
  starY += y;
2186
2187
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2187
- for (let i = 0, len = rows.length; i < len; i++) {
2188
+ for (let i = 0, len = countRows; i < len; i++) {
2188
2189
  row = rows[i];
2189
2190
  row.x = x;
2190
2191
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -2253,7 +2254,7 @@ function clipText(drawData, style, x, width) {
2253
2254
  if (i === end && charRight < right) {
2254
2255
  break;
2255
2256
  }
2256
- else if (charRight < right && char.char !== ' ') {
2257
+ else if ((charRight < right && char.char !== ' ') || !i) {
2257
2258
  row.data.splice(i + 1);
2258
2259
  row.width -= char.width;
2259
2260
  break;