{"_id":"@crafter/mermaid-layout","_rev":"8-ee603a6fad978abd70f4f5048c689d73","name":"@crafter/mermaid-layout","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.1":{"name":"@crafter/mermaid-layout","version":"0.0.1","_id":"@crafter/mermaid-layout@0.0.1","maintainers":[{"name":"raillyhugo_","email":"railly_2009@hotmail.com"}],"dist":{"shasum":"51ebddc7cbbdf7da2f0bfcc7dcc4d6038716970b","tarball":"https://registry.npmjs.org/@crafter/mermaid-layout/-/mermaid-layout-0.0.1.tgz","fileCount":5,"integrity":"sha512-u4zc1iwBEF08QM2Zc93iP44KWePOMOSFXGr0sVQdMbdgzBCNikqgKx6Tys41I0C9zBfq3Ji9gTPx9wloqk9toA==","signatures":[{"sig":"MEUCIHWDlpCQG1syTpuxiqbvPWvhYxT/Rdid7TTAI2hvxNi6AiEA0WBh1XRf5yaMySOnQfZU0DbCT9oIkvNXYSISosm2qmw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":126489},"main":"./src/index.ts","type":"module","types":"./src/index.ts","exports":{".":{"bun":"./src/index.ts","types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"67933593e38dc834b0611f683ca1da6b6e08fa53","scripts":{"test":"bun test src/","build":"tsup"},"_npmUser":{"name":"raillyhugo_","email":"railly_2009@hotmail.com"},"_npmVersion":"10.9.2","description":"Zero-dependency layout engine for Mermaid diagrams. Implements the Sugiyama hierarchical layout algorithm from scratch.","directories":{},"_nodeVersion":"22.14.0","dependencies":{"@crafter/mermaid-parser":"workspace:*"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mermaid-layout_0.0.1_1770395711117_0.1291401684762432","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@crafter/mermaid-layout","version":"0.0.2","_id":"@crafter/mermaid-layout@0.0.2","maintainers":[{"name":"raillyhugo_","email":"railly_2009@hotmail.com"},{"name":"jibaru","email":"ignacioruedaboada@gmail.com"},{"name":"cris-fast","email":"cristian.correa.cs@gmail.com"}],"dist":{"shasum":"6314fd96e01e035d13354e59f6cb1a5b89687847","tarball":"https://registry.npmjs.org/@crafter/mermaid-layout/-/mermaid-layout-0.0.2.tgz","fileCount":5,"integrity":"sha512-bXPgxpbCiDTuiYTwjp7Mzx1G2KLGT8tr5jYTPyYl55wZOFkerT5JrWjbRS7FwpdY1Npu2s/E+FdjvpLW5GKPkw==","signatures":[{"sig":"MEUCIQCmu1vZLH0DR3DPwflMe/NSGJoAr8Mr6DJK52X2o/l+BwIgclY4CYdcDqOCeqa24e56RdA4R8xH8fchoM7nSoG6Lmo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":248236},"main":"./src/index.ts","type":"module","types":"./src/index.ts","exports":{".":{"bun":"./src/index.ts","types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"03381fd83ed25b249862d4b4d5a8b005dde621ab","scripts":{"test":"bun test src/","build":"tsup"},"_npmUser":{"name":"raillyhugo_","email":"railly_2009@hotmail.com"},"_npmVersion":"10.9.2","description":"Zero-dependency layout engine for Mermaid diagrams. Implements the Sugiyama hierarchical layout algorithm from scratch.","directories":{},"_nodeVersion":"22.14.0","dependencies":{"@crafter/mermaid-parser":"workspace:*"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mermaid-layout_0.0.2_1773298061719_0.4290721670438029","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"@crafter/mermaid-layout","version":"0.0.3","_id":"@crafter/mermaid-layout@0.0.3","maintainers":[{"name":"raillyhugo_","email":"railly_2009@hotmail.com"},{"name":"jibaru","email":"ignacioruedaboada@gmail.com"},{"name":"cris-fast","email":"cristian.correa.cs@gmail.com"}],"dist":{"shasum":"dddee689345a4f80360d49d8ca2aaac017f10ca6","tarball":"https://registry.npmjs.org/@crafter/mermaid-layout/-/mermaid-layout-0.0.3.tgz","fileCount":5,"integrity":"sha512-T9NGOvUrtWajPkTzWhYvzVOABNBlKtzTpqFt0TeG3d5YgAW9AG4ZXr1E9c8a4++Kzh9EKX1UL0xK1Yr0/T+HIg==","signatures":[{"sig":"MEQCIFvIuNPpTtlOjnKHD5upSNVMq0XQ66XOBOv8fthToh5vAiAWZ2vj/jcaWq8VWMpJxvbhzzBcW62NhX8XTWCfyendzQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":248230},"main":"./src/index.ts","type":"module","types":"./src/index.ts","exports":{".":{"bun":"./src/index.ts","types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"03381fd83ed25b249862d4b4d5a8b005dde621ab","scripts":{"test":"bun test src/","build":"tsup"},"_npmUser":{"name":"raillyhugo_","email":"railly_2009@hotmail.com"},"_npmVersion":"10.9.2","description":"Zero-dependency layout engine for Mermaid diagrams. Implements the Sugiyama hierarchical layout algorithm from scratch.","directories":{},"_nodeVersion":"22.14.0","dependencies":{"@crafter/mermaid-parser":"0.0.3"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mermaid-layout_0.0.3_1773298246409_0.8523158240757798","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"@crafter/mermaid-layout","version":"0.0.4","_id":"@crafter/mermaid-layout@0.0.4","maintainers":[{"name":"raillyhugo_","email":"railly_2009@hotmail.com"},{"name":"jibaru","email":"ignacioruedaboada@gmail.com"},{"name":"cris-fast","email":"cristian.correa.cs@gmail.com"}],"homepage":"https://github.com/crafter-station/mermaid#readme","bugs":{"url":"https://github.com/crafter-station/mermaid/issues"},"dist":{"shasum":"c97d49a1dfcb085694b01e49270e44a58c099709","tarball":"https://registry.npmjs.org/@crafter/mermaid-layout/-/mermaid-layout-0.0.4.tgz","fileCount":5,"integrity":"sha512-y/ZjIu4k2NNdhDs1xjfXHR9m+lrfKQc0KDFgCkzfH4Eff2GUYAitbcUWMKdCfZ0Hgszdq+4veFw/kNeoMZfDaw==","signatures":[{"sig":"MEYCIQCVQPqmIO4m94fzBmW6qcJJPF42XTY3DtNi7J30toZonwIhAPztqtiu999WWYMdSUJfYW267i1TUU4wcyVc+ODKdbq/","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@crafter%2fmermaid-layout@0.0.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":248649},"main":"./src/index.ts","type":"module","types":"./src/index.ts","exports":{".":{"bun":"./src/index.ts","types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"a5b105412a714d3fe3681114d867f16c6603e9d5","scripts":{"test":"bun test src/","build":"tsup","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3c0f41c6-b621-419c-8167-c7b9e86d9573"}},"repository":{"url":"git+https://github.com/crafter-station/mermaid.git","type":"git","directory":"packages/layout"},"_npmVersion":"12.0.1","description":"Zero-dependency layout engine for Mermaid diagrams. Implements the Sugiyama hierarchical layout algorithm from scratch.","directories":{},"_nodeVersion":"24.18.0","dependencies":{"@crafter/mermaid-parser":"workspace:*"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mermaid-layout_0.0.4_1784827755855_0.1463120853270108","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-02-06T16:35:11.034Z","modified":"2026-09-06T05:34:07.178Z","0.0.1":"2026-02-06T16:35:11.264Z","0.0.2":"2026-03-12T06:47:41.864Z","0.0.3":"2026-03-12T06:50:46.605Z","0.0.4":"2026-07-23T17:29:15.994Z"},"bugs":{"url":"https://github.com/crafter-station/mermaid/issues"},"homepage":"https://github.com/crafter-station/mermaid#readme","repository":{"url":"git+https://github.com/crafter-station/mermaid.git","type":"git","directory":"packages/layout"},"description":"Zero-dependency layout engine for Mermaid diagrams. Implements the Sugiyama hierarchical layout algorithm from scratch.","maintainers":[{"email":"railly_2009@hotmail.com","name":"raillyhugo_"},{"email":"ignacioruedaboada@gmail.com","name":"jibaru"},{"email":"cristian.correa.cs@gmail.com","name":"cris-fast"},{"email":"shiara.arauzo@gmail.com","name":"shiaraarauzo"},{"email":"hi@cueva.io","name":"cuevaio"}],"readme":"# @crafter/mermaid-layout\n\nZero-dependency layout engine for Mermaid diagrams. Implements the Sugiyama hierarchical layout algorithm from scratch.\n\n## Features\n\n- Zero dependencies\n- Sugiyama hierarchical layout (Flowchart, Class, ER diagrams)\n- Column-based sequence diagram layout\n- Orthogonal edge routing\n- Shape-aware boundary clipping\n- Deterministic output\n\n## Usage\n\n```typescript\nimport { layout } from \"@crafter/mermaid-layout\";\nimport { parse } from \"@crafter/mermaid-parser\";\n\nconst code = `\nflowchart TD\n  A[Start] --> B[Process]\n  B --> C[End]\n`;\n\nconst result = parse(code);\nif (result.ast) {\n  const positioned = layout(result.ast, {\n    direction: \"TB\",\n    nodeSpacing: 50,\n    layerSpacing: 100,\n    padding: 20,\n  });\n\n  console.log(positioned.nodes);\n  console.log(positioned.edges);\n}\n```\n\n## API\n\n### `layout(ast: DiagramAST, options?: LayoutOptions): PositionedGraph`\n\nMain layout function. Accepts a parsed AST from `@crafter/mermaid-parser` and returns positioned nodes, edges, and groups.\n\n#### Options\n\n```typescript\ninterface LayoutOptions {\n  direction?: \"TD\" | \"TB\" | \"LR\" | \"BT\" | \"RL\";\n  nodeSpacing?: number;\n  layerSpacing?: number;\n  padding?: number;\n}\n```\n\n#### Output\n\n```typescript\ninterface PositionedGraph {\n  width: number;\n  height: number;\n  nodes: PositionedNode[];\n  edges: PositionedEdge[];\n  groups: PositionedGroup[];\n}\n```\n\n## Algorithm\n\n### Sugiyama Layout (4 phases)\n\n1. **Cycle Removal**: DFS-based greedy cycle breaking\n2. **Layer Assignment**: Longest-path layering + virtual node insertion\n3. **Crossing Minimization**: Barycenter heuristic (24 iterations)\n4. **Coordinate Assignment**: Position refinement with neighbor attraction\n\n### Edge Routing\n\n- Orthogonal routing (90-degree bends)\n- Shape-aware boundary clipping (rectangle, diamond, circle, hexagon, etc.)\n- Label positioning at edge midpoint\n\n### Text Metrics\n\nCharacter-count heuristic calibrated for web fonts:\n- Normal: 0.52 ratio\n- Medium: 0.55 ratio\n- Bold: 0.58 ratio\n\n## Supported Diagrams\n\n- Flowchart (TD, TB, LR, BT, RL)\n- Sequence (column-based)\n- Class (hierarchical)\n- ER (hierarchical)\n\n## Architecture\n\n```\nsrc/\n├── types.ts              # Layout types\n├── graph.ts              # Directed graph data structure\n├── text-metrics.ts       # Text width estimation\n├── edge-routing.ts       # Edge routing utilities\n├── sugiyama/\n│   ├── cycle-removal.ts  # Phase 1\n│   ├── layer-assign.ts   # Phase 2\n│   ├── crossing-min.ts   # Phase 3\n│   ├── coordinate.ts     # Phase 4\n│   └── index.ts          # Orchestrator\n└── index.ts              # Main entry point\n```\n\n## Performance\n\n- O(V + E) cycle removal\n- O(V + E) layer assignment\n- O(E²) crossing minimization (worst case, typically much better)\n- O(V) coordinate assignment\n\nDeterministic output ensures same input always produces same layout.\n","readmeFilename":"README.md"}