{"version":3,"file":"atomico-use-remark.cjs","sources":["../src/index.ts"],"sourcesContent":["import { h, useState, useMemo } from \"atomico\";\nimport { Plugin, unified } from \"unified\";\nimport remarkParse from \"remark-parse\";\nimport remarkRehype from \"remark-rehype\";\nimport { Root, toH } from \"hast-to-hyperscript\";\n\nconst rehypeVdom: Plugin<any[], Root, ReturnType<typeof h>> = function () {\n  Object.assign(this, {\n    Compiler: (tree: Root) => {\n      return toH(h, tree);\n    },\n  });\n};\n\ninterface RemarkHookOptions {\n  remarkPlugins: Plugin[];\n  rehypePlugins: Plugin[];\n}\n\nconst defaultHookOptions: RemarkHookOptions = {\n  remarkPlugins: [],\n  rehypePlugins: [],\n};\n\nexport function useRemark(\n  initialContent = \"\",\n  options: Partial<RemarkHookOptions> = defaultHookOptions\n) {\n  const [content, setContent] = useState(initialContent);\n\n  const remarkProcessor = useMemo(\n    () =>\n      unified()\n        .use(remarkParse)\n        .use(options.remarkPlugins || defaultHookOptions.remarkPlugins)\n        .use(remarkRehype)\n        .use(options.rehypePlugins || defaultHookOptions.rehypePlugins)\n        .use(rehypeVdom),\n    [JSON.stringify(options)]\n  );\n\n  const vfile = useMemo(\n    () => remarkProcessor.processSync(content),\n    [remarkProcessor, content]\n  );\n\n  const tree = vfile.result;\n\n  return [tree, setContent, vfile] as const;\n}\n"],"names":["rehypeVdom","Object","assign","this","Compiler","tree","toH","h","defaultHookOptions","remarkPlugins","rehypePlugins","initialContent","options","useState","content","setContent","remarkProcessor","useMemo","unified","use","remarkParse","remarkRehype","JSON","stringify","vfile","processSync","result"],"mappings":"wPAMMA,EAAwD,WAC5DC,OAAOC,OAAOC,KAAM,CAClBC,SAAU,SAACC,GACT,OAAOC,MAAIC,IAAGF,OAUdG,EAAwC,CAC5CC,cAAe,GACfC,cAAe,+BAIfC,EACAC,YADAD,IAAAA,EAAiB,aACjBC,IAAAA,EAAsCJ,GAEtC,MAA8BK,WAASF,GAAhCG,OAASC,OAEVC,EAAkBC,UACtB,kBACEC,YACGC,IAAIC,WACJD,IAAIP,EAAQH,eAAiBD,EAAmBC,eAChDU,IAAIE,WACJF,IAAIP,EAAQF,eAAiBF,EAAmBE,eAChDS,IAAInB,IACT,CAACsB,KAAKC,UAAUX,KAGZY,EAAQP,UACZ,kBAAMD,EAAgBS,YAAYX,IAClC,CAACE,EAAiBF,IAKpB,MAAO,CAFMU,EAAME,OAELX,EAAYS"}