{"version":3,"file":"color.mjs","names":["computed","isRef","destructComputed","getForeground","isCssColor","isParsableColor","parseColor","useColor","colors","classes","styles","value","background","backgroundColor","text","a","textColor","color","caretColor","push","colorClasses","colorStyles","useTextColor","props","name","textColorClasses","textColorStyles","useBackgroundColor","backgroundColorClasses","backgroundColorStyles"],"sources":["../../src/composables/color.ts"],"sourcesContent":["// Utilities\nimport { computed, isRef } from 'vue'\nimport { destructComputed, getForeground, isCssColor, isParsableColor, parseColor } from '@/util'\n\n// Types\nimport type { CSSProperties, Ref } from 'vue'\n\ntype ColorValue = string | false | null | undefined\n\nexport interface TextColorData {\n textColorClasses: Ref\n textColorStyles: Ref\n}\n\nexport interface BackgroundColorData {\n backgroundColorClasses: Ref\n backgroundColorStyles: Ref\n}\n\n// Composables\nexport function useColor (colors: Ref<{ background?: ColorValue, text?: ColorValue }>) {\n return destructComputed(() => {\n const classes: string[] = []\n const styles: CSSProperties = {}\n\n if (colors.value.background) {\n if (isCssColor(colors.value.background)) {\n styles.backgroundColor = colors.value.background\n\n if (!colors.value.text && isParsableColor(colors.value.background)) {\n const backgroundColor = parseColor(colors.value.background)\n if (backgroundColor.a == null || backgroundColor.a === 1) {\n const textColor = getForeground(backgroundColor)\n\n styles.color = textColor\n styles.caretColor = textColor\n }\n }\n } else {\n classes.push(`bg-${colors.value.background}`)\n }\n }\n\n if (colors.value.text) {\n if (isCssColor(colors.value.text)) {\n styles.color = colors.value.text\n styles.caretColor = colors.value.text\n } else {\n classes.push(`text-${colors.value.text}`)\n }\n }\n\n return { colorClasses: classes, colorStyles: styles }\n })\n}\n\nexport function useTextColor (color: Ref): TextColorData\nexport function useTextColor , K extends string> (props: T, name: K): TextColorData\nexport function useTextColor , K extends string> (\n props: T | Ref,\n name?: K\n): TextColorData {\n const colors = computed(() => ({\n text: isRef(props) ? props.value : (name ? props[name] : null),\n }))\n\n const {\n colorClasses: textColorClasses,\n colorStyles: textColorStyles,\n } = useColor(colors)\n\n return { textColorClasses, textColorStyles }\n}\n\nexport function useBackgroundColor (color: Ref): BackgroundColorData\nexport function useBackgroundColor , K extends string> (props: T, name: K): BackgroundColorData\nexport function useBackgroundColor , K extends string> (\n props: T | Ref,\n name?: K\n): BackgroundColorData {\n const colors = computed(() => ({\n background: isRef(props) ? props.value : (name ? props[name] : null),\n }))\n\n const {\n colorClasses: backgroundColorClasses,\n colorStyles: backgroundColorStyles,\n } = useColor(colors)\n\n return { backgroundColorClasses, backgroundColorStyles }\n}\n"],"mappings":"AAAA;AACA,SAASA,QAAQ,EAAEC,KAAK,QAAQ,KAAK;AAAA,SAC5BC,gBAAgB,EAAEC,aAAa,EAAEC,UAAU,EAAEC,eAAe,EAAEC,UAAU,6BAEjF;AAeA;AACA,OAAO,SAASC,QAAQA,CAAEC,MAA2D,EAAE;EACrF,OAAON,gBAAgB,CAAC,MAAM;IAC5B,MAAMO,OAAiB,GAAG,EAAE;IAC5B,MAAMC,MAAqB,GAAG,CAAC,CAAC;IAEhC,IAAIF,MAAM,CAACG,KAAK,CAACC,UAAU,EAAE;MAC3B,IAAIR,UAAU,CAACI,MAAM,CAACG,KAAK,CAACC,UAAU,CAAC,EAAE;QACvCF,MAAM,CAACG,eAAe,GAAGL,MAAM,CAACG,KAAK,CAACC,UAAU;QAEhD,IAAI,CAACJ,MAAM,CAACG,KAAK,CAACG,IAAI,IAAIT,eAAe,CAACG,MAAM,CAACG,KAAK,CAACC,UAAU,CAAC,EAAE;UAClE,MAAMC,eAAe,GAAGP,UAAU,CAACE,MAAM,CAACG,KAAK,CAACC,UAAU,CAAC;UAC3D,IAAIC,eAAe,CAACE,CAAC,IAAI,IAAI,IAAIF,eAAe,CAACE,CAAC,KAAK,CAAC,EAAE;YACxD,MAAMC,SAAS,GAAGb,aAAa,CAACU,eAAe,CAAC;YAEhDH,MAAM,CAACO,KAAK,GAAGD,SAAS;YACxBN,MAAM,CAACQ,UAAU,GAAGF,SAAS;UAC/B;QACF;MACF,CAAC,MAAM;QACLP,OAAO,CAACU,IAAI,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