All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.chunks.mermaid.core.diagram-QS5GVLUX.mjs.map Maven / Gradle / Ivy

Go to download

Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.

There is a newer version: 11.4.0
Show newest version
{
  "version": 3,
  "sources": ["../../../src/diagrams/packet/db.ts", "../../../src/diagrams/packet/parser.ts", "../../../src/diagrams/packet/renderer.ts", "../../../src/diagrams/packet/styles.ts", "../../../src/diagrams/packet/diagram.ts"],
  "sourcesContent": ["import { getConfig as commonGetConfig } from '../../config.js';\nimport type { PacketDiagramConfig } from '../../config.type.js';\nimport DEFAULT_CONFIG from '../../defaultConfig.js';\nimport { cleanAndMerge } from '../../utils.js';\nimport {\n  clear as commonClear,\n  getAccDescription,\n  getAccTitle,\n  getDiagramTitle,\n  setAccDescription,\n  setAccTitle,\n  setDiagramTitle,\n} from '../common/commonDb.js';\nimport type { PacketDB, PacketData, PacketWord } from './types.js';\n\nconst defaultPacketData: PacketData = {\n  packet: [],\n};\n\nlet data: PacketData = structuredClone(defaultPacketData);\n\nconst DEFAULT_PACKET_CONFIG: Required = DEFAULT_CONFIG.packet;\n\nconst getConfig = (): Required => {\n  const config = cleanAndMerge({\n    ...DEFAULT_PACKET_CONFIG,\n    ...commonGetConfig().packet,\n  });\n  if (config.showBits) {\n    config.paddingY += 10;\n  }\n  return config;\n};\n\nconst getPacket = (): PacketWord[] => data.packet;\n\nconst pushWord = (word: PacketWord) => {\n  if (word.length > 0) {\n    data.packet.push(word);\n  }\n};\n\nconst clear = () => {\n  commonClear();\n  data = structuredClone(defaultPacketData);\n};\n\nexport const db: PacketDB = {\n  pushWord,\n  getPacket,\n  getConfig,\n  clear,\n  setAccTitle,\n  getAccTitle,\n  setDiagramTitle,\n  getDiagramTitle,\n  getAccDescription,\n  setAccDescription,\n};\n", "import type { Packet } from '@mermaid-js/parser';\nimport { parse } from '@mermaid-js/parser';\nimport type { ParserDefinition } from '../../diagram-api/types.js';\nimport { log } from '../../logger.js';\nimport { populateCommonDb } from '../common/populateCommonDb.js';\nimport { db } from './db.js';\nimport type { PacketBlock, PacketWord } from './types.js';\n\nconst maxPacketSize = 10_000;\n\nconst populate = (ast: Packet) => {\n  populateCommonDb(ast, db);\n  let lastByte = -1;\n  let word: PacketWord = [];\n  let row = 1;\n  const { bitsPerRow } = db.getConfig();\n  for (let { start, end, label } of ast.blocks) {\n    if (end && end < start) {\n      throw new Error(`Packet block ${start} - ${end} is invalid. End must be greater than start.`);\n    }\n    if (start !== lastByte + 1) {\n      throw new Error(\n        `Packet block ${start} - ${end ?? start} is not contiguous. It should start from ${\n          lastByte + 1\n        }.`\n      );\n    }\n    lastByte = end ?? start;\n    log.debug(`Packet block ${start} - ${lastByte} with label ${label}`);\n\n    while (word.length <= bitsPerRow + 1 && db.getPacket().length < maxPacketSize) {\n      const [block, nextBlock] = getNextFittingBlock({ start, end, label }, row, bitsPerRow);\n      word.push(block);\n      if (block.end + 1 === row * bitsPerRow) {\n        db.pushWord(word);\n        word = [];\n        row++;\n      }\n      if (!nextBlock) {\n        break;\n      }\n      ({ start, end, label } = nextBlock);\n    }\n  }\n  db.pushWord(word);\n};\n\nconst getNextFittingBlock = (\n  block: PacketBlock,\n  row: number,\n  bitsPerRow: number\n): [Required, PacketBlock | undefined] => {\n  if (block.end === undefined) {\n    block.end = block.start;\n  }\n\n  if (block.start > block.end) {\n    throw new Error(`Block start ${block.start} is greater than block end ${block.end}.`);\n  }\n\n  if (block.end + 1 <= row * bitsPerRow) {\n    return [block as Required, undefined];\n  }\n\n  return [\n    {\n      start: block.start,\n      end: row * bitsPerRow - 1,\n      label: block.label,\n    },\n    {\n      start: row * bitsPerRow,\n      end: block.end,\n      label: block.label,\n    },\n  ];\n};\n\nexport const parser: ParserDefinition = {\n  parse: async (input: string): Promise => {\n    const ast: Packet = await parse('packet', input);\n    log.debug(ast);\n    populate(ast);\n  },\n};\n", "import type { Diagram } from '../../Diagram.js';\nimport type { PacketDiagramConfig } from '../../config.type.js';\nimport type { DiagramRenderer, DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';\nimport { selectSvgElement } from '../../rendering-util/selectSvgElement.js';\nimport { configureSvgSize } from '../../setupGraphViewbox.js';\nimport type { PacketDB, PacketWord } from './types.js';\n\nconst draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {\n  const db = diagram.db as PacketDB;\n  const config = db.getConfig();\n  const { rowHeight, paddingY, bitWidth, bitsPerRow } = config;\n  const words = db.getPacket();\n  const title = db.getDiagramTitle();\n  const totalRowHeight = rowHeight + paddingY;\n  const svgHeight = totalRowHeight * (words.length + 1) - (title ? 0 : rowHeight);\n  const svgWidth = bitWidth * bitsPerRow + 2;\n  const svg: SVG = selectSvgElement(id);\n\n  svg.attr('viewbox', `0 0 ${svgWidth} ${svgHeight}`);\n  configureSvgSize(svg, svgHeight, svgWidth, config.useMaxWidth);\n\n  for (const [word, packet] of words.entries()) {\n    drawWord(svg, packet, word, config);\n  }\n\n  svg\n    .append('text')\n    .text(title)\n    .attr('x', svgWidth / 2)\n    .attr('y', svgHeight - totalRowHeight / 2)\n    .attr('dominant-baseline', 'middle')\n    .attr('text-anchor', 'middle')\n    .attr('class', 'packetTitle');\n};\n\nconst drawWord = (\n  svg: SVG,\n  word: PacketWord,\n  rowNumber: number,\n  { rowHeight, paddingX, paddingY, bitWidth, bitsPerRow, showBits }: Required\n) => {\n  const group: SVGGroup = svg.append('g');\n  const wordY = rowNumber * (rowHeight + paddingY) + paddingY;\n  for (const block of word) {\n    const blockX = (block.start % bitsPerRow) * bitWidth + 1;\n    const width = (block.end - block.start + 1) * bitWidth - paddingX;\n    // Block rectangle\n    group\n      .append('rect')\n      .attr('x', blockX)\n      .attr('y', wordY)\n      .attr('width', width)\n      .attr('height', rowHeight)\n      .attr('class', 'packetBlock');\n\n    // Block label\n    group\n      .append('text')\n      .attr('x', blockX + width / 2)\n      .attr('y', wordY + rowHeight / 2)\n      .attr('class', 'packetLabel')\n      .attr('dominant-baseline', 'middle')\n      .attr('text-anchor', 'middle')\n      .text(block.label);\n\n    if (!showBits) {\n      continue;\n    }\n    // Start byte count\n    const isSingleBlock = block.end === block.start;\n    const bitNumberY = wordY - 2;\n    group\n      .append('text')\n      .attr('x', blockX + (isSingleBlock ? width / 2 : 0))\n      .attr('y', bitNumberY)\n      .attr('class', 'packetByte start')\n      .attr('dominant-baseline', 'auto')\n      .attr('text-anchor', isSingleBlock ? 'middle' : 'start')\n      .text(block.start);\n\n    // Draw end byte count if it is not the same as start byte count\n    if (!isSingleBlock) {\n      group\n        .append('text')\n        .attr('x', blockX + width)\n        .attr('y', bitNumberY)\n        .attr('class', 'packetByte end')\n        .attr('dominant-baseline', 'auto')\n        .attr('text-anchor', 'end')\n        .text(block.end);\n    }\n  }\n};\nexport const renderer: DiagramRenderer = { draw };\n", "import type { DiagramStylesProvider } from '../../diagram-api/types.js';\nimport { cleanAndMerge } from '../../utils.js';\nimport type { PacketStyleOptions } from './types.js';\n\nconst defaultPacketStyleOptions: PacketStyleOptions = {\n  byteFontSize: '10px',\n  startByteColor: 'black',\n  endByteColor: 'black',\n  labelColor: 'black',\n  labelFontSize: '12px',\n  titleColor: 'black',\n  titleFontSize: '14px',\n  blockStrokeColor: 'black',\n  blockStrokeWidth: '1',\n  blockFillColor: '#efefef',\n};\n\nexport const styles: DiagramStylesProvider = ({ packet }: { packet?: PacketStyleOptions } = {}) => {\n  const options = cleanAndMerge(defaultPacketStyleOptions, packet);\n\n  return `\n\t.packetByte {\n\t\tfont-size: ${options.byteFontSize};\n\t}\n\t.packetByte.start {\n\t\tfill: ${options.startByteColor};\n\t}\n\t.packetByte.end {\n\t\tfill: ${options.endByteColor};\n\t}\n\t.packetLabel {\n\t\tfill: ${options.labelColor};\n\t\tfont-size: ${options.labelFontSize};\n\t}\n\t.packetTitle {\n\t\tfill: ${options.titleColor};\n\t\tfont-size: ${options.titleFontSize};\n\t}\n\t.packetBlock {\n\t\tstroke: ${options.blockStrokeColor};\n\t\tstroke-width: ${options.blockStrokeWidth};\n\t\tfill: ${options.blockFillColor};\n\t}\n\t`;\n};\n\nexport default styles;\n", "import type { DiagramDefinition } from '../../diagram-api/types.js';\nimport { db } from './db.js';\nimport { parser } from './parser.js';\nimport { renderer } from './renderer.js';\nimport { styles } from './styles.js';\n\nexport const diagram: DiagramDefinition = {\n  parser,\n  db,\n  renderer,\n  styles,\n};\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAM,oBAAgC;AAAA,EACpC,QAAQ,CAAC;AACX;AAEA,IAAI,OAAmB,gBAAgB,iBAAiB;AAExD,IAAM,wBAAuD,sBAAe;AAE5E,IAAMA,aAAY,6BAAqC;AACrD,QAAM,SAAS,cAAc;AAAA,IAC3B,GAAG;AAAA,IACH,GAAG,UAAgB,EAAE;AAAA,EACvB,CAAC;AACD,MAAI,OAAO,UAAU;AACnB,WAAO,YAAY;AAAA,EACrB;AACA,SAAO;AACT,GATkB;AAWlB,IAAM,YAAY,6BAAoB,KAAK,QAAzB;AAElB,IAAM,WAAW,wBAAC,SAAqB;AACrC,MAAI,KAAK,SAAS,GAAG;AACnB,SAAK,OAAO,KAAK,IAAI;AAAA,EACvB;AACF,GAJiB;AAMjB,IAAMC,SAAQ,6BAAM;AAClB,QAAY;AACZ,SAAO,gBAAgB,iBAAiB;AAC1C,GAHc;AAKP,IAAM,KAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,WAAAD;AAAA,EACA,OAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACzDA,SAAS,aAAa;AAOtB,IAAM,gBAAgB;AAEtB,IAAM,WAAW,wBAAC,QAAgB;AAChC,mBAAiB,KAAK,EAAE;AACxB,MAAI,WAAW;AACf,MAAI,OAAmB,CAAC;AACxB,MAAI,MAAM;AACV,QAAM,EAAE,WAAW,IAAI,GAAG,UAAU;AACpC,WAAS,EAAE,OAAO,K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