{"version":3,"file":"color.mjs","names":[],"sources":["../../../src/graph-label/color.ts"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\nimport { tokens } from '@neo4j-ndl/base';\nimport tinycolor from 'tinycolor2';\n\n/**\n * Takes a color string and returns color string\n * that is readable on top of that background. Prioritizes pallete\n *  text colors and uses black or white as fallback.\n */\nexport const getTextColorFromBackground = (color: string): string => {\n  return tinycolor\n    .mostReadable(\n      color,\n      [\n        tokens.theme.light.color.neutral.text.default,\n        tokens.theme.light.color.neutral.text.inverse,\n      ],\n      {\n        includeFallbackColors: true,\n      },\n    )\n    .toString();\n};\n\n/**\n * Takes a color string and returns a color string\n * that is darker or lighter depending on the given color.\n */\nexport const getHoverColor = (color: string): string => {\n  const hslColor = tinycolor(color).toHsl();\n  if (hslColor.l < 0.5) {\n    return tinycolor(color).lighten(10).toString();\n  }\n  return tinycolor(color).darken(10).toString();\n};\n\n/**\n * Returns the most readable color on the given background color\n *  as a string from a list of palette text colors\n */\nexport const getDisabledTextColor = (backgroundColor: string): string => {\n  return tinycolor\n    .mostReadable(backgroundColor, [\n      tokens.theme.light.color.neutral.text.weakest,\n      tokens.theme.light.color.neutral.text.weaker,\n      tokens.theme.light.color.neutral.text.weak,\n      tokens.theme.light.color.neutral.text.inverse,\n    ])\n    .toString();\n};\n\n/**\n * Takes a color string and returns a color string\n * that is darker or lighter depending on the given color.\n */\nexport const getDisabledColor = (color: string): string => {\n  const hslColor = tinycolor(color).toHsl();\n  if (hslColor.l < 0.5) {\n    return tinycolor(color).lighten(15).toString();\n  }\n  return tinycolor(color).darken(15).toString();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,8BAA8B,UAA0B;CACnE,OAAO,UACJ,aACC,OACA,CACE,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAK,SACtC,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAK,OACxC,GACA,EACE,uBAAuB,KACzB,CACF,CAAC,CACA,SAAS;AACd;;;;;AAMA,MAAa,iBAAiB,UAA0B;CAEtD,IADiB,UAAU,KAAK,CAAC,CAAC,MACvB,CAAC,CAAC,IAAI,IACf,OAAO,UAAU,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS;CAE/C,OAAO,UAAU,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS;AAC9C;;;;;AAMA,MAAa,wBAAwB,oBAAoC;CACvE,OAAO,UACJ,aAAa,iBAAiB;EAC7B,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAK;EACtC,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAK;EACtC,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAK;EACtC,OAAO,MAAM,MAAM,MAAM,QAAQ,KAAK;CACxC,CAAC,CAAC,CACD,SAAS;AACd;;;;;AAMA,MAAa,oBAAoB,UAA0B;CAEzD,IADiB,UAAU,KAAK,CAAC,CAAC,MACvB,CAAC,CAAC,IAAI,IACf,OAAO,UAAU,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS;CAE/C,OAAO,UAAU,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS;AAC9C"}