{"version":3,"sources":["../src/MDXProvider.ts"],"sourcesContent":["// Based on https://github.com/mdx-js/mdx/blob/main/packages/react/lib/index.js\n// since sandpack-bundler cannot import @mdx-js/react as it chokes on the\n// transitive dependency on VFile.\nimport { createContext, useContext, useMemo, createElement } from 'react';\nconst emptyComponents = {};\n\nconst MDXContext = createContext(emptyComponents);\n\n/** Merge the caller's MDX component overrides with those from the surrounding\n *  {@link MDXProvider} context (a function arg receives the parent set to merge). */\nexport function useMDXComponents(components: any) {\n  const contextComponents = useContext(MDXContext);\n\n  // Memoize to avoid unnecessary top-level context changes\n  return useMemo(\n    function () {\n      // Custom merge via a function prop\n      if (typeof components === 'function') {\n        return components(contextComponents);\n      }\n\n      return { ...contextComponents, ...components };\n    },\n    [contextComponents, components],\n  );\n}\n\n/** Provide MDX component overrides (e.g. a custom `a`/`h1`) to the rendered\n *  subtree; transformed `.mdx` modules pick them up. */\nexport function MDXProvider(properties: any) {\n  let allComponents: any;\n\n  if (properties.disableParentContext) {\n    allComponents =\n      typeof properties.components === 'function'\n        ? properties.components(emptyComponents)\n        : properties.components || emptyComponents;\n  } else {\n    allComponents = useMDXComponents(properties.components);\n  }\n\n  return createElement(MDXContext.Provider, { value: allComponents }, properties.children);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkE;AAClE,MAAM,kBAAkB,CAAC;AAEzB,MAAM,iBAAa,4BAAc,eAAe;AAIzC,SAAS,iBAAiB,YAAiB;AAChD,QAAM,wBAAoB,yBAAW,UAAU;AAG/C,aAAO;AAAA,IACL,WAAY;AAEV,UAAI,OAAO,eAAe,YAAY;AACpC,eAAO,WAAW,iBAAiB;AAAA,MACrC;AAEA,aAAO,EAAE,GAAG,mBAAmB,GAAG,WAAW;AAAA,IAC/C;AAAA,IACA,CAAC,mBAAmB,UAAU;AAAA,EAChC;AACF;AAIO,SAAS,YAAY,YAAiB;AAC3C,MAAI;AAEJ,MAAI,WAAW,sBAAsB;AACnC,oBACE,OAAO,WAAW,eAAe,aAC7B,WAAW,WAAW,eAAe,IACrC,WAAW,cAAc;AAAA,EACjC,OAAO;AACL,oBAAgB,iBAAiB,WAAW,UAAU;AAAA,EACxD;AAEA,aAAO,4BAAc,WAAW,UAAU,EAAE,OAAO,cAAc,GAAG,WAAW,QAAQ;AACzF;","names":[]}