import chroma from "chroma-js";
import { kebabCase } from "lodash-es";
import { c as css } from "./twind.DdSZmZu6.js";
/*! Upstart.gg - Copyright (C) 2024 Flippable - https://github.com/upstart-gg/upstart/blob/main/LICENSE */
var baseColors = {
  primary: "Primary color",
  secondary: "Secondary color",
  accent: "Accent color",
  neutral: "Neutral color",
  base100: "Base color",
  base200: "Base (level 2)",
  base300: "Base (level 3)"
};
var shadeNumbers = [900, 800, 700, 600, 500, 400, 300, 200, 100, 50];
var semanticAliases = {
  100: "subtle",
  300: "light",
  700: "dark"
};
function isStandardColor(color) {
  if (typeof color !== "string") {
    return false;
  }
  return color.startsWith("oklch") || color.startsWith("oklab") || color.startsWith("rgb") || color.startsWith("hsl") || color.startsWith("#") || color.startsWith("var(--");
}
function propToStyle(prop, cssAttr) {
  if (typeof prop === "undefined") {
    return void 0;
  }
  return isStandardColor(prop) || typeof prop === "number" ? css({ [cssAttr]: prop }) : prop;
}
function getContrastingTextColor(backgroundColor, contrastThreshold = 3.5) {
  const bgColor = chroma(backgroundColor);
  const white = "#ffffff";
  const black = "#000000";
  const contrastWithWhite = chroma.contrast(bgColor, white);
  const contrastWithBlack = chroma.contrast(bgColor, black);
  if (contrastWithWhite >= contrastThreshold && contrastWithBlack >= contrastThreshold) {
    return white;
  }
  if (contrastWithWhite >= contrastThreshold) {
    return white;
  }
  if (contrastWithBlack >= contrastThreshold) {
    return black;
  }
  return contrastWithWhite >= contrastWithBlack ? white : black;
}
function propToClass(value, classPrefix) {
  if (typeof value === "undefined") {
    return void 0;
  }
  return isStandardColor(value) || typeof value === "number" ? `${classPrefix}-[${value}]` : value;
}
function generateColorsVars(theme) {
  const shades = {};
  const colorNames = Object.keys(baseColors);
  colorNames.forEach((_colorName) => {
    const color = theme.colors[_colorName];
    const colorName = kebabCase(_colorName);
    shades[`color-${colorName}`] = color;
    shades[`color-${colorName}-500`] = color;
    const contentColor = getContrastingTextColor(color);
    shades[`color-${colorName}-content`] = contentColor;
    shades[`color-${colorName}-500-content`] = contentColor;
    const baseColor = chroma(color);
    const darkest = baseColor.darken(2.5);
    const lightest = baseColor.brighten(3.5);
    const colorScale = chroma.scale([lightest, baseColor, darkest]).domain([50, 500, 900]).mode("oklch");
    if (!colorName.startsWith("base")) {
      shadeNumbers.forEach((shade) => {
        if (shade === 500) {
          return;
        }
        const varName = `color-${colorName}-${shade}`;
        const shadedColor = colorScale(shade);
        shades[varName] = shadedColor.css("oklch");
        const contentColor2 = getContrastingTextColor(shadedColor);
        shades[`color-${colorName}-${shade}-content`] = contentColor2;
        if (semanticAliases[shade]) {
          shades[`color-${colorName}-${semanticAliases[shade]}`] = shades[varName];
          shades[`color-${colorName}-${semanticAliases[shade]}-content`] = contentColor2;
        }
      });
    }
  });
  return shades;
}
export {
  propToStyle as a,
  getContrastingTextColor as b,
  baseColors as c,
  generateColorsVars as g,
  isStandardColor as i,
  propToClass as p
};
//# sourceMappingURL=color-system.CS_rItCW.js.map
