function calcTextBounds(attrs, measureFn = measureText) {
  const fontSize = attrs['font-size'] || attrs.fontSize;
  const fontFamily = attrs['font-family'] || attrs.fontFamily;
  const textMeasure = measureFn({ text: attrs.text, fontFamily, fontSize });
  const calWidth = Math.min(attrs.maxWidth || textMeasure.width, textMeasure.width); // Use actual value if max is not set
  const x = attrs.x || 0;
  const y = attrs.y || 0;
  const dx = attrs.dx || 0;
  const dy = (attrs.dy || 0) + baselineHeuristic(attrs);

  const boundingRect = {
    x: 0,
    y: y + dy - textMeasure.height * 0.75, // Magic number for alphabetical baseline
    width: calWidth,
    height: textMeasure.height,
  };

  const anchor = attrs['text-anchor'] || attrs.anchor;

  if (anchor === 'middle') {
    boundingRect.x = x + dx - calWidth / 2;
  } else if (anchor === 'end') {
    boundingRect.x = x + dx - calWidth;
  } else {
    boundingRect.x = x + dx;
  }

  return boundingRect;
}
/**
 * Calculates the bounding rectangle of a text node.
 * The bounding rectangle is a approximate of the "em square" seen here (http://www.w3resource.com/html5-canvas/html5-canvas-text.php)
 * @ignore
 * @param {object} attrs - Text node definition
 * @param {number} [attrs.x] - X-coordinate
 * @param {number} [attrs.y] - Y-coordinate
 * @param {number} [attrs.dx] - Delta x-coordinate
 * @param {number} [attrs.dy] - Delta y-coordinate
 * @param {string} [attrs.anchor] - Text anchor
 * @param {number} [attrs.maxWidth] - Maximum allowed text width
 * @return {object} The bounding rectangle
 */
Calculates the bounding rectangle of a text node.
Calculates the bounding rectangle of a text node .
function calcTextBounds(attrs, measureFn = measureText) {
  const fontSize = attrs['font-size'] || attrs.fontSize;
  const fontFamily = attrs['font-family'] || attrs.fontFamily;
  const textMeasure = measureFn({ text: attrs.text, fontFamily, fontSize });
  const calWidth = Math.min(attrs.maxWidth || textMeasure.width, textMeasure.width); 
  const x = attrs.x || 0;
  const y = attrs.y || 0;
  const dx = attrs.dx || 0;
  const dy = (attrs.dy || 0) + baselineHeuristic(attrs);
  const boundingRect = {
    x: 0,
    y: y + dy - textMeasure.height * 0.75, 
    width: calWidth,
    height: textMeasure.height,
  };
  const anchor = attrs['text-anchor'] || attrs.anchor;
  if (anchor === 'middle') {
    boundingRect.x = x + dx - calWidth / 2;
  } else if (anchor === 'end') {
    boundingRect.x = x + dx - calWidth;
  } else {
    boundingRect.x = x + dx;
  }
  return boundingRect;
}
function calcTextBounds ( attrs , measureFn = measureText ) { const fontSize = attrs [ 'font-size' ] || attrs . fontSize ; const fontFamily = attrs [ 'font-family' ] || attrs . fontFamily ; const textMeasure = measureFn ( { text : attrs . text , fontFamily , fontSize } ) ; const calWidth = Math . min ( attrs . maxWidth || textMeasure . width , textMeasure . width ) ; const x = attrs . x || 0 ; const y = attrs . y || 0 ; const dx = attrs . dx || 0 ; const dy = ( attrs . dy || 0 ) + baselineHeuristic ( attrs ) ; const boundingRect = { x : 0 , y : y + dy - textMeasure . height * 0.75 , width : calWidth , height : textMeasure . height , } ; const anchor = attrs [ 'text-anchor' ] || attrs . anchor ; if ( anchor === 'middle' ) { boundingRect . x = x + dx - calWidth / 2 ; } else if ( anchor === 'end' ) { boundingRect . x = x + dx - calWidth ; } else { boundingRect . x = x + dx ; } return boundingRect ; }
Calculates the bounding rectangle of a text node.
Calculates the bounding rectangle of a text node .
// Use actual value if max is not set // Magic number for alphabetical baseline