{"version":3,"file":"agnostic.mjs","names":[],"sources":["../../../src/theme/agnostic.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 { useNeedleTheme } from './ThemeProvider';\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction defaultStringToJson(path: string, json: any = {}, theme: string): any {\n  const parts = path.split('.');\n  let part;\n  while ((part = parts.shift())) {\n    if (typeof json[part] !== 'object') {\n      return json[part];\n    }\n    json = json[part];\n    // Specific for theme tokens\n    if (part === 'theme') {\n      json = json[theme];\n    }\n  }\n}\n\nconst useN = (\n  path: string,\n  stringToJson = defaultStringToJson,\n): string | void => {\n  const { theme, tokens } = useNeedleTheme();\n  if (!tokens) {\n    console.error(\n      'design tokens not found, you need to set the design tokens in the NeedleThemeProvider',\n    );\n    return;\n  }\n  const value = stringToJson(path, tokens, theme);\n  if (!value) {\n    console.warn(\n      `design token value \"${path}\" not found, are you sure the string path is correct?`,\n    );\n  }\n  return value;\n};\n\n// React will complain if we don't use the prefix \"use\" for\n// holding the useNeedleTheme function call. \"useToken\" is exported as \"n\" for convenience.\nexport const useToken = useN;\nexport { useToken as n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAS,oBAAoB,MAAc,OAAY,CAAC,GAAG,OAAoB;CAC7E,MAAM,QAAQ,KAAK,MAAM,GAAG;CAC5B,IAAI;CACJ,OAAQ,OAAO,MAAM,MAAM,GAAI;EAC7B,IAAI,OAAO,KAAK,UAAU,UACxB,OAAO,KAAK;EAEd,OAAO,KAAK;EAEZ,IAAI,SAAS,SACX,OAAO,KAAK;CAEhB;AACF;AAEA,MAAM,QACJ,MACA,eAAe,wBACG;CAClB,MAAM,EAAE,OAAO,WAAW,eAAe;CACzC,IAAI,CAAC,QAAQ;EACX,QAAQ,MACN,uFACF;EACA;CACF;CACA,MAAM,QAAQ,aAAa,MAAM,QAAQ,KAAK;CAC9C,IAAI,CAAC,OACH,QAAQ,KACN,uBAAuB,KAAK,sDAC9B;CAEF,OAAO;AACT;AAIA,MAAa,WAAW"}