import { anyCssColorToHex } from "./../ricos-styles/themeStrategy/theme-utils.js";
import { isThemeColorToken } from ".//theme-color-token.js";
import { getHexColorFromAlpha } from "./../wix-rich-content-common/index.js";
const stripAlphaSafely = (color) => color.startsWith("#") || isThemeColorToken(color) ? getHexColorFromAlpha(color) ?? color : color;
const resolveColorToDisplayHex = (color, containerElement, { preserveAlpha = false } = {}) => {
  const normalizedColor = (preserveAlpha ? color : color && stripAlphaSafely(color))?.trim();
  if (!normalizedColor) {
    return void 0;
  }
  const finalize = (hex) => (preserveAlpha ? hex : getHexColorFromAlpha(hex) ?? hex).toUpperCase();
  if (!containerElement) {
    return normalizedColor.startsWith("#") ? finalize(normalizedColor) : void 0;
  }
  try {
    return finalize(anyCssColorToHex(normalizedColor, containerElement));
  } catch {
    return normalizedColor.startsWith("#") ? finalize(normalizedColor) : void 0;
  }
};
export {
  resolveColorToDisplayHex
};
//# sourceMappingURL=resolve-color-to-display-hex.js.map
