{"version":3,"file":"use-color.mjs","sources":["../../../../../../theme/src/hooks/use-color.ts"],"sourcesContent":["import { useTheme } from '@fusion-ui-vue/theme'\nimport { computed } from 'vue'\nimport type { AcceptableColor } from '../core'\n\n/**\n * The function to compute color from props\n * The props.color can be \"primary\" | \"secondary\" | \"tertiary\" | \"error\" | (theme: Theme) => string | \"string\"\n * Use this function to get the final color value\n * @param {T extends { [k: string]: AcceptableColor | any }} props The props of component\n * @param {keyof T | undefined | null} key The key of props\n * Set the key to null or undefined to use default color\n * @param {[string]} defaultColor The default color\n * @return Return the computed string. The value can be CSS variable or color in hex\n */\nexport const useColor = <T extends { [k: string]: AcceptableColor | any }>(\n  props: T,\n  key: keyof T | undefined | null,\n  defaultColor?: string\n) => {\n  const theme = useTheme()\n  return computed(() => {\n    if (!key || !(key in props)) {\n      return defaultColor ?? null\n    }\n\n    const color: AcceptableColor = props?.[key]\n\n    if (typeof color === 'function') {\n      return color(theme.value)\n    }\n    if (typeof color === 'string' && color in theme.value.palette) {\n      const _color = color.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()\n      return `var(--md-sys-color-${_color})`\n    }\n    return color\n  })\n}\n"],"names":[],"mappings":";;;;AAcO,MAAM,QAAW,GAAA,CACtB,KACA,EAAA,GAAA,EACA,YACG,KAAA;AACH,EAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,EAAA,OAAO,SAAS,MAAM;AACpB,IAAA,IAAI,CAAC,GAAA,IAAO,EAAE,GAAA,IAAO,KAAQ,CAAA,EAAA;AAC3B,MAAA,OAAO,YAAgB,IAAA,IAAA,GAAA,YAAA,GAAA,IAAA,CAAA;AAAA,KACzB;AAEA,IAAA,MAAM,QAAyB,KAAQ,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,CAAA,CAAA;AAEvC,IAAI,IAAA,OAAO,UAAU,UAAY,EAAA;AAC/B,MAAO,OAAA,KAAA,CAAM,MAAM,KAAK,CAAA,CAAA;AAAA,KAC1B;AACA,IAAA,IAAI,OAAO,KAAU,KAAA,QAAA,IAAY,KAAS,IAAA,KAAA,CAAM,MAAM,OAAS,EAAA;AAC7D,MAAA,MAAM,SAAS,KAAM,CAAA,OAAA,CAAQ,iBAAmB,EAAA,OAAO,EAAE,WAAY,EAAA,CAAA;AACrE,MAAA,OAAO,sBAAsB,MAAM,CAAA,CAAA,CAAA,CAAA;AAAA,KACrC;AACA,IAAO,OAAA,KAAA,CAAA;AAAA,GACR,CAAA,CAAA;AACH;;;;"}