import { svg } from "lit";
var TickmarkType = /* @__PURE__ */ ((TickmarkType2) => {
  TickmarkType2["zeroLineThick"] = "zeroLineThick";
  TickmarkType2["zeroLine"] = "zeroLine";
  TickmarkType2["main"] = "main";
  TickmarkType2["primary"] = "primary";
  TickmarkType2["secondary"] = "secondary";
  TickmarkType2["tertiary"] = "tertiary";
  TickmarkType2["textOnly"] = "textOnly";
  return TickmarkType2;
})(TickmarkType || {});
var TickmarkStyle = /* @__PURE__ */ ((TickmarkStyle2) => {
  TickmarkStyle2["regular"] = "regular";
  TickmarkStyle2["enhanced"] = "enhanced";
  return TickmarkStyle2;
})(TickmarkStyle || {});
function tickmarkColor(style, tickmarkType) {
  if (style === "regular") {
    return "var(--instrument-tick-mark-tertiary-color)";
  } else {
    if (tickmarkType === "tertiary") {
      return "var(--instrument-tick-mark-secondary-color)";
    }
    return "var(--instrument-tick-mark-primary-color)";
  }
}
function tickmark(angle, {
  size,
  style,
  scale,
  text,
  inside,
  textRadius,
  rotation,
  maxDigits,
  color,
  radiusOffset = 0
}) {
  if (scale === Infinity || scale < 0) {
    throw new Error("Tick scale is not valid");
  }
  const rOff = radiusOffset;
  let innerRadius;
  let outerRadius;
  textRadius = textRadius + (3 / scale + 3) * (inside ? -1 : 1);
  const rad = angle * Math.PI / 180;
  if (size === "primary") {
    innerRadius = 328 / 2 + rOff;
    outerRadius = 368 / 2 + rOff;
  } else if (size === "secondary") {
    innerRadius = 328 / 2 + rOff;
    outerRadius = 344 / 2 + rOff;
  } else if (size === "main" || size === "zeroLine") {
    innerRadius = 320 / 2 + rOff;
    outerRadius = 368 / 2 + rOff;
  } else if (size === "zeroLineThick") {
    innerRadius = 224 / 2 + rOff;
    outerRadius = 368 / 2 + rOff;
  } else if (size === "tertiary") {
    innerRadius = 328 / 2 + rOff;
    outerRadius = 336 / 2 + rOff;
  } else {
    return [textSvg(text ?? "", angle, inside, scale, textRadius)];
  }
  if (inside) {
    const outerRingRadius = 368 / 2 + rOff;
    const ring2Radius = 320 / 2 + rOff;
    const tickLength = outerRadius - innerRadius;
    const gapFromRingEdge = Math.max(0, innerRadius - ring2Radius);
    outerRadius = outerRingRadius - gapFromRingEdge;
    innerRadius = outerRadius - tickLength;
  }
  const colorName = color ?? tickmarkColor(style, size);
  const x1 = Math.sin(rad) * innerRadius;
  const y1 = -Math.cos(rad) * innerRadius;
  const x2 = Math.sin(rad) * outerRadius;
  const y2 = -Math.cos(rad) * outerRadius;
  const strokeWidth = size === "zeroLine" || size === "zeroLineThick" ? 4 : 1;
  const tick = svg`<line x1=${x1} y1=${y1} x2=${x2} y2=${y2} stroke=${colorName} stroke-width=${strokeWidth} vector-effect="non-scaling-stroke"/>`;
  if (text) {
    if (rotation === void 0) {
      return [tick, textSvg(text, angle, inside, scale, textRadius)];
    } else {
      const newRadius = textRadius + (4 / scale + 5) * (inside ? -1 : 1) * maxDigits / 2;
      const textX = Math.sin(rad) * newRadius;
      const textY = -Math.cos(rad) * newRadius;
      return [
        tick,
        svg`<text x=${textX} y=${textY} class="label rotate ${inside ? "inside" : ""}" transform="rotate(${-rotation})" transform-origin="${textX} ${textY}">${text}</text>`
      ];
    }
  }
  return tick;
}
function textSvg(text, angle, inside, scale, textRadius) {
  let positionClass;
  if (angle === 0) {
    positionClass = "top";
  } else if (angle < 180 && angle > 0) {
    positionClass = "right";
  } else if (angle === 180) {
    positionClass = "bottom";
  } else {
    positionClass = "left";
  }
  const rad = angle * Math.PI / 180;
  const insideGain = inside ? -1 : 1;
  const yOffset = 7 / scale * insideGain;
  const xOffset = 6 / scale * insideGain;
  let textX = Math.sin(rad) * (textRadius + xOffset);
  if (angle > 180) {
    textX += 4 / scale * insideGain;
  } else if (angle < 180 && angle > 0) {
    textX -= 4 / scale * insideGain;
  }
  const textY = -Math.cos(rad) * (textRadius + yOffset);
  return svg`<text x=${textX} y=${textY} class="label ${positionClass} ${inside ? "inside" : ""}">${text}</text>`;
}
export {
  TickmarkStyle,
  TickmarkType,
  tickmark,
  tickmarkColor
};
//# sourceMappingURL=tickmark.js.map
