{"version":3,"file":"CodeHighlightProvider.cjs","names":["plainTextAdapter"],"sources":["../../src/CodeHighlightProvider/CodeHighlightProvider.tsx"],"sourcesContent":["import { createContext, use, useEffect, useMemo, useState } from 'react';\nimport { plainTextAdapter } from './adapters/plain-text-adapter';\n\ninterface HighlighterInput {\n  colorScheme: 'light' | 'dark' | (string & {});\n  code: string;\n  language?: string;\n}\n\ntype Highlighter = (input: HighlighterInput) => {\n  /** Highlighted code (html markup) */\n  highlightedCode: string;\n\n  /** `true` if the code is represented with html string, `false` for plain text string */\n  isHighlighted: boolean;\n\n  /** Props to pass down to `<code>` tag */\n  codeElementProps?: Record<string, any>;\n};\n\nexport interface CodeHighlightAdapter {\n  loadContext?: () => Promise<any>;\n  getHighlighter: (ctx: any) => Highlighter;\n}\n\ninterface CodeHighlightProviderContext {\n  adapter: CodeHighlightAdapter;\n  highlight: Highlighter;\n}\n\nexport const CodeHighlightContext = createContext<CodeHighlightProviderContext>({\n  adapter: plainTextAdapter,\n  highlight: plainTextAdapter.getHighlighter(null),\n});\n\nexport interface CodeHighlightAdapterProviderProps {\n  adapter: CodeHighlightAdapter;\n  children: React.ReactNode;\n}\n\nexport function CodeHighlightAdapterProvider({\n  adapter,\n  children,\n}: CodeHighlightAdapterProviderProps) {\n  const [ctx, setCtx] = useState<any>(null);\n  const highlight = useMemo(() => adapter.getHighlighter(ctx), [adapter, ctx]);\n\n  useEffect(() => {\n    if (adapter.loadContext) {\n      adapter.loadContext().then(setCtx);\n    }\n  }, [adapter]);\n\n  return <CodeHighlightContext value={{ adapter, highlight }}>{children}</CodeHighlightContext>;\n}\n\nexport function useHighlight() {\n  const ctx = use(CodeHighlightContext);\n  return ctx?.highlight || plainTextAdapter.getHighlighter(null);\n}\n"],"mappings":";;;;;AA8BA,MAAa,wBAAA,GAAA,MAAA,eAAmE;CAC9E,SAASA,2BAAAA;CACT,WAAWA,2BAAAA,iBAAiB,eAAe,IAAI;AACjD,CAAC;AAOD,SAAgB,6BAA6B,EAC3C,SACA,YACoC;CACpC,MAAM,CAAC,KAAK,WAAA,GAAA,MAAA,UAAwB,IAAI;CACxC,MAAM,aAAA,GAAA,MAAA,eAA0B,QAAQ,eAAe,GAAG,GAAG,CAAC,SAAS,GAAG,CAAC;CAE3E,CAAA,GAAA,MAAA,iBAAgB;EACd,IAAI,QAAQ,aACV,QAAQ,YAAY,EAAE,KAAK,MAAM;CAErC,GAAG,CAAC,OAAO,CAAC;CAEZ,OAAO,iBAAA,GAAA,kBAAA,KAAC,sBAAD;EAAsB,OAAO;GAAE;GAAS;EAAU;EAAI;CAA+B,CAAA;AAC9F;AAEA,SAAgB,eAAe;CAE7B,QAAA,GAAA,MAAA,KADgB,oBACP,GAAG,aAAaA,2BAAAA,iBAAiB,eAAe,IAAI;AAC/D"}