"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var resolve_color_to_display_hex_exports = {};
__export(resolve_color_to_display_hex_exports, {
  resolveColorToDisplayHex: () => resolveColorToDisplayHex
});
module.exports = __toCommonJS(resolve_color_to_display_hex_exports);
var import_theme_utils = require("./../ricos-styles/themeStrategy/theme-utils.js");
var import_theme_color_token = require(".//theme-color-token.js");
var import_wix_rich_content_common = require("./../wix-rich-content-common/index.js");
const stripAlphaSafely = (color) => color.startsWith("#") || (0, import_theme_color_token.isThemeColorToken)(color) ? (0, import_wix_rich_content_common.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 : (0, import_wix_rich_content_common.getHexColorFromAlpha)(hex) ?? hex).toUpperCase();
  if (!containerElement) {
    return normalizedColor.startsWith("#") ? finalize(normalizedColor) : void 0;
  }
  try {
    return finalize((0, import_theme_utils.anyCssColorToHex)(normalizedColor, containerElement));
  } catch {
    return normalizedColor.startsWith("#") ? finalize(normalizedColor) : void 0;
  }
};
//# sourceMappingURL=resolve-color-to-display-hex.js.map
