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,IAAI,EACJ,IACE,EAAmB,OAAO,EAAO,GAEjC,EAAM,KAAK,GAAG,mCAAuC,EAAU,YACjE,CAAE,MAAO,GAEP,OADA,EAAM,QAAQ,EAAO,EAAU,aACxB,CACT,CAEA,EAAU,CACR,KAAM,QACN,MAAO,kBACP,IAAK,EAET,CAIA,OAFA,EAAO,SAAS,OAAO,EAAO,EAAG,GAE1B,CAAI,GAEf,CAYA,SAAS,UAAU,EAAK,EAAO,GAC7B,OACS,MAAM,EAAK,OADhB,EACwB,CAAC,EAAM,EAAO,IAAW,wBAAwB,EAAM,EAAO,EAAQ,GAGxE,GAAQ,oBAAoB,EAAM,GAC9D,CAYA,SAAS,WAAW,EAAK,EAAO,GAC9B,OACS,MAAM,EAAK,QADhB,EACyB,CAAC,EAAM,EAAO,IAAW,wBAAwB,EAAM,EAAO,EAAQ,GAGxE,GAAQ,oBAAoB,EAAM,GAC/D,CAeA,SAAS,QAAQ,EAAU,CAAC,GAC1B,MAAM,EAAa,EAAQ,SAAU,EAQrC,OAAO,SAAqB,EAAK,EAAO,GAKtC,OAJA,eAAe,EAAK,EAAO,GAC3B,UAAU,EAAK,EAAO,GACtB,WAAW,EAAK,EAAO,GAEH,mBAAT,EACF,EAAK,KAAM,EAAK,GAGlB,CACT,CACF,CAEA,OAAO,QAAU","file":"/npm/remark-mermaid@0.2.0/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/remark-mermaid@0.2.0/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const fs = require('fs-extra');\nconst visit = require('unist-util-visit');\nconst utils = require('./utils');\n\nconst render = utils.render;\nconst renderFromFile = utils.renderFromFile;\nconst getDestinationDir = utils.getDestinationDir;\nconst createMermaidDiv = utils.createMermaidDiv;\n\nconst PLUGIN_NAME = 'remark-mermaid';\n\n/**\n * Is this title `mermaid:`?\n *\n * @param  {string} title\n * @return {boolean}\n */\nconst isMermaid = title => title === 'mermaid:';\n\n/**\n * Given a node which contains a `url` property (eg. Link or Image), follow\n * the link, generate a graph and then replace the link with the link to the\n * generated graph. Checks to ensure node has a title of `mermaid:` before doing.\n *\n * @param   {object}  node\n * @param   {vFile}   vFile\n * @return {object}\n */\nfunction replaceUrlWithGraph(node, vFile) {\n  const { title, url, position } = node;\n  const { destinationDir } = vFile.data;\n\n  // If the node isn't mermaid, ignore it.\n  if (!isMermaid(title)) {\n    return node;\n  }\n\n  try {\n    // eslint-disable-next-line no-param-reassign\n    node.url = renderFromFile(`${vFile.dirname}/${url}`, destinationDir);\n\n    vFile.info('mermaid link replaced with link to graph', position, PLUGIN_NAME);\n  } catch (error) {\n    vFile.message(error, position, PLUGIN_NAME);\n  }\n\n  return node;\n}\n\n/**\n * Given a link to a mermaid diagram, grab the contents from the link and put it\n * into a div that Mermaid JS can act upon.\n *\n * @param  {object}   node\n * @param  {integer}  index\n * @param  {object}   parent\n * @param  {vFile}    vFile\n * @return {object}\n */\nfunction replaceLinkWithEmbedded(node, index, parent, vFile) {\n  const { title, url, position } = node;\n  let newNode;\n\n  // If the node isn't mermaid, ignore it.\n  if (!isMermaid(title)) {\n    return node;\n  }\n\n  try {\n    const value = fs.readFileSync(`${vFile.dirname}/${url}`, { encoding: 'utf-8' });\n\n    newNode = createMermaidDiv(value);\n    parent.children.splice(index, 1, newNode);\n    vFile.info('mermaid link replaced with div', position, PLUGIN_NAME);\n  } catch (error) {\n    vFile.message(error, position, PLUGIN_NAME);\n    return node;\n  }\n\n  return node;\n}\n\n/**\n * Given the MDAST ast, look for all fenced codeblocks that have a language of\n * `mermaid` and pass that to mermaid.cli to render the image. Replaces the\n * codeblocks with an image of the rendered graph.\n *\n * @param {object}  ast\n * @param {vFile}   vFile\n * @param {boolean} isSimple\n * @return {function}\n */\nfunction visitCodeBlock(ast, vFile, isSimple) {\n  return visit(ast, 'code', (node, index, parent) => {\n    const { lang, value, position } = node;\n    const destinationDir = getDestinationDir(vFile);\n    let newNode;\n\n    // If this codeblock is not mermaid, bail.\n    if (lang !== 'mermaid') {\n      return node;\n    }\n\n    // Are we just transforming to a <div>, or replacing with an image?\n    if (isSimple) {\n      newNode = createMermaidDiv(value);\n\n      vFile.info(`${lang} code block replaced with div`, position, PLUGIN_NAME);\n\n    // Otherwise, let's try and generate a graph!\n    } else {\n      let graphSvgFilename;\n      try {\n        graphSvgFilename = render(value, destinationDir);\n\n        vFile.info(`${lang} code block replaced with graph`, position, PLUGIN_NAME);\n      } catch (error) {\n        vFile.message(error, position, PLUGIN_NAME);\n        return node;\n      }\n\n      newNode = {\n        type: 'image',\n        title: '`mermaid` image',\n        url: graphSvgFilename,\n      };\n    }\n\n    parent.children.splice(index, 1, newNode);\n\n    return node;\n  });\n}\n\n/**\n * If links have a title attribute called `mermaid:`, follow the link and\n * depending on `isSimple`, either generate and link to the graph, or simply\n * wrap the graph contents in a div.\n *\n * @param {object}  ast\n * @param {vFile}   vFile\n * @param {boolean} isSimple\n * @return {function}\n */\nfunction visitLink(ast, vFile, isSimple) {\n  if (isSimple) {\n    return visit(ast, 'link', (node, index, parent) => replaceLinkWithEmbedded(node, index, parent, vFile));\n  }\n\n  return visit(ast, 'link', node => replaceUrlWithGraph(node, vFile));\n}\n\n/**\n * If images have a title attribute called `mermaid:`, follow the link and\n * depending on `isSimple`, either generate and link to the graph, or simply\n * wrap the graph contents in a div.\n *\n * @param {object}  ast\n * @param {vFile}   vFile\n * @param {boolean} isSimple\n * @return {function}\n */\nfunction visitImage(ast, vFile, isSimple) {\n  if (isSimple) {\n    return visit(ast, 'image', (node, index, parent) => replaceLinkWithEmbedded(node, index, parent, vFile));\n  }\n\n  return visit(ast, 'image', node => replaceUrlWithGraph(node, vFile));\n}\n\n/**\n * Returns the transformer which acts on the MDAST tree and given VFile.\n *\n * If `options.simple` is passed as a truthy value, the plugin will convert\n * to `<div class=\"mermaid\">` rather than a SVG image.\n *\n * @link https://github.com/unifiedjs/unified#function-transformernode-file-next\n * @link https://github.com/syntax-tree/mdast\n * @link https://github.com/vfile/vfile\n *\n * @param {object} options\n * @return {function}\n */\nfunction mermaid(options = {}) {\n  const simpleMode = options.simple || false;\n\n  /**\n   * @param {object} ast MDAST\n   * @param {vFile} vFile\n   * @param {function} next\n   * @return {object}\n   */\n  return function transformer(ast, vFile, next) {\n    visitCodeBlock(ast, vFile, simpleMode);\n    visitLink(ast, vFile, simpleMode);\n    visitImage(ast, vFile, simpleMode);\n\n    if (typeof next === 'function') {\n      return next(null, ast, vFile);\n    }\n\n    return ast;\n  };\n}\n\nmodule.exports = mermaid;\n"]}