{"id":51136168,"url":"https://github.com/contember/mermaid-parser-bundle","last_synced_at":"2026-06-25T18:01:45.885Z","repository":{"id":353568733,"uuid":"1219941748","full_name":"contember/mermaid-parser-bundle","owner":"contember","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-24T12:45:34.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-24T14:29:26.788Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/contember.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-24T11:32:28.000Z","updated_at":"2026-04-24T12:45:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/contember/mermaid-parser-bundle","commit_stats":null,"previous_names":["contember/mermaid-parser-bundle"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/contember/mermaid-parser-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contember%2Fmermaid-parser-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contember%2Fmermaid-parser-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contember%2Fmermaid-parser-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contember%2Fmermaid-parser-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/contember","download_url":"https://codeload.github.com/contember/mermaid-parser-bundle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contember%2Fmermaid-parser-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34786238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-25T02:00:05.521Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-25T18:01:44.828Z","updated_at":"2026-06-25T18:01:45.859Z","avatar_url":"https://github.com/contember.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mermaid-parser-bundle\n\nA zero-dependency ESM bundle of [mermaid](https://github.com/mermaid-js/mermaid)'s\nparsers. All 34 diagram types, no renderer code — no d3, no cytoscape, no\nkatex, no roughjs.\n\n```bash\nnpm install mermaid-parser-bundle\n```\n\n```ts\nimport { parse } from 'mermaid-parser-bundle';\n\nconst { type, db } = await parse('flowchart TD\\n  A --\u003e B\\n  B --\u003e C');\n// type → 'flowchart-v2'\n// db   → the populated FlowDB instance (vertices, edges, subgraphs, …)\n```\n\n## Sizes\n\n**Install footprint** — what `npm install \u003cpkg\u003e` adds to your project\n(`scripts/measure-install.sh` reproduces this on any machine):\n\n| Package                                    | `node_modules`           | Transitive deps |\n| ------------------------------------------ | ------------------------ | --------------- |\n| `mermaid`                                  | 114 MB                   | 76              |\n| **`mermaid-parser-bundle`**                | **1.1 MB**               | **0** (zero)    |\n\n**Bundle size after tree-shake** — if you already ship mermaid and bundle\nit with esbuild/rolldown:\n\n| Bundled entry                                          | Raw          | Gzip        |\n| ------------------------------------------------------ | ------------ | ----------- |\n| `import { parse } from 'mermaid'` (esbuild tree-shake) | 3 114 KB     | 858 KB      |\n| **`import { parse } from 'mermaid-parser-bundle'`**    | **1 093 KB** | **282 KB**  |\n\nCovers every diagram mermaid registers via `addDiagrams()`:\nflowchart, sequence, class, state, er, gantt, pie, journey, gitGraph, mindmap,\nc4, requirement, quadrantChart, xychart, sankey, block, timeline, kanban,\npacket, info, treemap, treeView, radar, wardley, ishikawa, venn, architecture,\neventmodeling, swimlane, railroad, railroad-ebnf, railroad-abnf, railroad-peg,\ncynefin.\n\n`swimlane` reuses flowchart's grammar + `FlowDB` (it only swaps the layout\nengine at render time). `flowchartElk` shares the `flowchart-v2` grammar (they\ndiffer only in renderer) and `error` isn't a user-written type, so neither\nneeds its own entry.\n\n## Development\n\nThis repo builds from mermaid's upstream source. We clone it into `mermaid-src/`\n(gitignored), apply a pile of esbuild aliases and auto-stubs to collapse every\nrender-only module, and produce a single self-contained ESM file.\n\nPrereqs: **Node ≥ 20**, **pnpm** (for mermaid's monorepo — `corepack enable` is\nenough), **npm** (for this repo).\n\n```bash\n# one-time: clone + install mermaid-src, run Langium codegen\nnpm run setup\n\n# install this package's build deps\nnpm install\n\n# bake the defaultConfig JSON + bundle\nnpm run build\n\n# parse a sample of every diagram\nnpm test\n```\n\nOutputs:\n- `dist/index.mjs`       — minified bundle (the published artifact)\n- `dist/index.unmin.mjs` — unminified for inspection\n- `dist/index.d.ts`      — TypeScript types\n- `dist/index.meta.json` — esbuild metafile (feed it to\n  [esbuild analyzer](https://esbuild.github.io/analyze/) for a flame graph)\n\n### Pinning the mermaid version\n\n`scripts/setup-mermaid-src.sh` checks out a pinned mermaid commit (defaults to\n`180b3831e`, ≈ `mermaid@11.15.0`). `MERMAID_REF` accepts a tag, branch, or SHA:\n\n```bash\nMERMAID_REF=mermaid@11.15.0 npm run setup\n```\n\n### How the bundling works\n\n1. **Bypass `*Diagram.ts`.** Every `*Diagram.ts` in mermaid source drags its\n   renderer in via a top-level import. Our `src/entry-b.ts` sidesteps that\n   file entirely and hand-wires the exact `parser` + `db` modules each diagram\n   actually needs.\n2. **Alias render-only npm deps.** d3, cytoscape, katex, roughjs, marked,\n   stylis, khroma, @iconify/utils, @upsetjs/venn.js, dompurify, d3-sankey all\n   become tiny proxy stubs. `es-toolkit/compat` is replaced by a ~1 KB\n   native-JS shim (mermaid only uses `clone`/`merge`/`memoize`/`isEmpty`\n   from it, but the real module pulls in ~35 KB of lodash-es).\n3. **Auto-stub render-only internals.** An esbuild plugin reads the real\n   source of each targeted module, walks every `export …`, `export * from …`,\n   and CommonJS `exports.X =` form (including transitive barrel re-exports),\n   and returns a synthetic module whose every named export is bound to a\n   no-op Proxy. The Proxy handles `Symbol.toPrimitive` / `Symbol.iterator` /\n   `then` so template literals and `for..of` loops over stubbed values don't\n   explode. Applied to:\n     - `rendering-util/**`, `themes/**`, `svgDrawCommon`, `populateCommonDb`,\n       `errors`, and the render-heavy chart builders in xychart /\n       quadrant-chart / wardley / state\n     - Langium's LSP-only subsystems: `lsp/**`, `validation/**`, `jsdoc.js`,\n       the LSP-focused files under `workspace/**` and `references/**`\n     - Crucially, `workspace/file-system-provider.js`, `ast-node-locator.js`,\n       and all of `serializer/**` are **not** stubbed — they run during\n       grammar init; stub them and parsers crash with \"No main rule\n       available\"\n   Everything reachable only from these modules — including vscode-language-\n   server-protocol and most of vscode-jsonrpc — tree-shakes out for free.\n4. **`.jison` files** compile on-the-fly via the same Jison plugin mermaid\n   uses in its own build.\n5. **`config.schema.yaml?only-defaults=true`** is pre-computed once by\n   `scripts/gen-defaults.mts` (which shells into mermaid-src to run its own\n   `jsonSchema.ts` with Ajv) and inlined as JSON at bundle time.\n6. **`injected.includeLargeFeatures` / `injected.version`** are replaced via\n   esbuild `define`, mirroring mermaid's own esbuild config.\n\n### Bundle budget\n\n| Slice                                          | Size    |\n| ---------------------------------------------- | ------- |\n| Jison grammars (20 diagrams)                   | 343 KB  |\n| `@mermaid-js/parser` (15 Langium grammars + AST) | 205 KB  |\n| chevrotain (Langium's parser engine)           | 115 KB  |\n| Langium runtime (core parse only)              | 97 KB   |\n| Mermaid utilities                              | 92 KB   |\n| Mermaid `src/*` other                          | 80 KB   |\n| Mermaid DBs                                    | 73 KB   |\n| js-yaml                                        | 39 KB   |\n| vscode-languageserver-types / vscode-uri (types only) | 34 KB |\n\n### Trimming further\n\n- **Want only a subset of diagrams?** Delete the entries you don't need from\n  the `DIAGRAMS` array in `src/entry-b.ts` and rebuild.\n- The largest remaining slices are the Jison grammars (immutable without\n  upstream changes) and chevrotain (Langium's parser engine). `js-yaml`\n  (39 KB) is the only realistic target — a minimal YAML subset parser would\n  suffice if you only care about flowchart's `@{ shape: … }` node-data and\n  frontmatter.\n\n## License\n\nMIT — see [LICENSE](./LICENSE). The produced bundle inlines source from\nmermaid-js/mermaid (MIT) and its transitive dependencies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontember%2Fmermaid-parser-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcontember%2Fmermaid-parser-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontember%2Fmermaid-parser-bundle/lists"}