Repository: excalidraw/excalidraw
File: src/element/textElement.ts (TypeScript)

Code before:
    return boundTextElementHeight + BOUND_TEXT_PADDING * 8 * 2;
  }
  if (containerType === "diamond") {
    return 2 * (boundTextElementHeight + BOUND_TEXT_PADDING * 2);
  }
  return boundTextElementHeight + BOUND_TEXT_PADDING * 2;
};

export const computeContainerWidthForBoundText = (
  boundTextElementWidth: number,
  containerType: typeof VALID_CONTAINER_TYPES[number],
) => {
  if (containerType === "ellipse") {
    return Math.round(
      ((boundTextElementWidth + BOUND_TEXT_PADDING * 2) / Math.sqrt(2)) * 2,
    );
  }
  if (containerType === "arrow") {
    return boundTextElementWidth + BOUND_TEXT_PADDING * 8 * 2;
  }
  if (containerType === "diamond") {
    return 2 * (boundTextElementWidth + BOUND_TEXT_PADDING * 2);
  }
  return boundTextElementWidth + BOUND_TEXT_PADDING * 2;
};

export const getMaxContainerWidth = (container: ExcalidrawElement) => {
  const width = getContainerDims(container).width;
  if (isArrowElement(container)) {
    const containerWidth = width - BOUND_TEXT_PADDING * 8 * 2;
    if (containerWidth <= 0) {
      const boundText = getBoundTextElement(container);
      if (boundText) {
        return boundText.width;
      }
      return BOUND_TEXT_PADDING * 8 * 2;
    }
    return containerWidth;
  }

  if (container.type === "ellipse") {
    // The width of the largest rectangle inscribed inside an ellipse is
    // Math.round((ellipse.width / 2) * Math.sqrt(2)) which is derived from
    // equation of an ellipse -https://github.com/excalidraw/excalidraw/pull/6172
    return Math.round((width / 2) * Math.sqrt(2)) - BOUND_TEXT_PADDING * 2;
  }
  if (container.type === "diamond") {
    // The width of the largest rectangle inscribed inside a rhombus is
    // Math.round(width / 2) - https://github.com/excalidraw/excalidraw/pull/6265
    return Math.round(width / 2) - BOUND_TEXT_PADDING * 2;
  }

Review comment (suggestion):
why not use it as `computeContainerForBoundText` and pass `boundTextElementWidth`/`boundTextElementHeight`as needed, 
as both functions are functionally doing the same

Code after:
    return dimension + padding * 8;
  }
  if (containerType === "diamond") {
    return 2 * (dimension + padding);
  }
  return dimension + padding;
};

export const getMaxContainerWidth = (container: ExcalidrawElement) => {
  const width = getContainerDims(container).width;
  if (isArrowElement(container)) {
    const containerWidth = width - BOUND_TEXT_PADDING * 8 * 2;
    if (containerWidth <= 0) {
      const boundText = getBoundTextElement(container);
      if (boundText) {
        return boundText.width;
      }
      return BOUND_TEXT_PADDING * 8 * 2;
    }
    return containerWidth;
  }

  if (container.type === "ellipse") {
    // The width of the largest rectangle inscribed inside an ellipse is
    // Math.round((ellipse.width / 2) * Math.sqrt(2)) which is derived from
    // equation of an ellipse -https://github.com/excalidraw/excalidraw/pull/6172
    return Math.round((width / 2) * Math.sqrt(2)) - BOUND_TEXT_PADDING * 2;
  }
  if (container.type === "diamond") {
    // The width of the largest rectangle inscribed inside a rhombus is
    // Math.round(width / 2) - https://github.com/excalidraw/excalidraw/pull/6265
    return Math.round(width / 2) - BOUND_TEXT_PADDING * 2;
  }
  return width - BOUND_TEXT_PADDING * 2;
};

export const getMaxContainerHeight = (container: ExcalidrawElement) => {
  const height = getContainerDims(container).height;
  if (isArrowElement(container)) {
    const containerHeight = height - BOUND_TEXT_PADDING * 8 * 2;
    if (containerHeight <= 0) {
      const boundText = getBoundTextElement(container);
      if (boundText) {
        return boundText.height;
      }
      return BOUND_TEXT_PADDING * 8 * 2;
    }
    return height;
  }
  if (container.type === "ellipse") {
    // The height of the largest rectangle inscribed inside an ellipse is