"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
function roundedRect(ctx, x, y, width, height, radius) {
  if (radius === 0) {
    ctx.rect(x, y, width, height);
    return;
  }
  if (typeof radius === "number") {
    radius = { bl: radius, br: radius, tl: radius, tr: radius };
  }
  radius = {
    bl: Math.min(radius.bl, height / 2, width / 2),
    br: Math.min(radius.br, height / 2, width / 2),
    tl: Math.min(radius.tl, height / 2, width / 2),
    tr: Math.min(radius.tr, height / 2, width / 2)
  };
  ctx.moveTo(x + radius.tl, y);
  ctx.arcTo(x + width, y, x + width, y + radius.tr, radius.tr);
  ctx.arcTo(x + width, y + height, x + width - radius.br, y + height, radius.br);
  ctx.arcTo(x, y + height, x, y + height - radius.bl, radius.bl);
  ctx.arcTo(x, y, x + radius.tl, y, radius.tl);
}
function drawArrow(ctx, direction = "up", x, y, width = 8, height = 12) {
  const headDelta = width / 2;
  ctx.beginPath();
  switch (direction) {
    case "up":
      ctx.moveTo(x, y + headDelta);
      ctx.lineTo(x + headDelta, y);
      ctx.lineTo(x + width, y + headDelta);
      ctx.moveTo(x + headDelta, y);
      ctx.lineTo(x + headDelta, y + height);
      break;
    case "down":
      ctx.moveTo(x, y + height - headDelta);
      ctx.lineTo(x + headDelta, y + height);
      ctx.lineTo(x + width, y + height - headDelta);
      ctx.moveTo(x + headDelta, y);
      ctx.lineTo(x + headDelta, y + height);
      break;
  }
  ctx.closePath();
  ctx.stroke();
}
function truncate(ctx, text, _x, maxWidth, suffix = "…") {
  const ellipsisWidth = ctx.measureText(suffix).width;
  let newText = text;
  let textWidth = ctx.measureText(text).width;
  if (textWidth <= maxWidth || textWidth <= ellipsisWidth) {
    return text;
  } else {
    let leftBound = 0;
    let rightBound = text.length;
    while (leftBound < rightBound) {
      const subLength = Math.floor((leftBound + rightBound) / 2);
      newText = text.substring(0, subLength);
      textWidth = ctx.measureText(newText).width;
      if (textWidth + ellipsisWidth < maxWidth) {
        leftBound = subLength + 1;
      } else {
        rightBound = subLength;
      }
    }
    return newText + suffix;
  }
}
function drawTextWithEllipsis(ctx, text, x, y, maxWidth) {
  const ellipsisText = truncate(ctx, text, x, maxWidth);
  ctx.fillText(ellipsisText, x, y);
}
exports.drawArrow = drawArrow;
exports.drawTextWithEllipsis = drawTextWithEllipsis;
exports.roundedRect = roundedRect;
