agentic-mermaid 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/CHANGELOG.md +144 -4
  2. package/LICENSES/Apache-2.0.txt +202 -0
  3. package/README.md +25 -32
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/dist/agent-core.d.ts +463 -0
  6. package/dist/agent-core.js +397 -0
  7. package/dist/agent.d.ts +73 -1868
  8. package/dist/agent.js +336 -37325
  9. package/dist/agentic-mermaid-mcp.js +7 -38399
  10. package/dist/am.js +33632 -40445
  11. package/dist/chunk-4QECACIA.js +4702 -0
  12. package/dist/chunk-CDPKJ2BQ.js +37 -0
  13. package/dist/chunk-QKDLMOJJ.js +3487 -0
  14. package/dist/chunk-WI35L7IR.js +615 -0
  15. package/dist/chunk-WN3YDOBG.js +149 -0
  16. package/dist/chunk-ZYMMKQ3I.js +62637 -0
  17. package/dist/index-D54dqSdC.d.ts +6777 -0
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +310 -33014
  20. package/dist/mcp-cli-SBQSTJFC.js +17 -0
  21. package/docs/README.md +14 -6
  22. package/docs/schemas/style-spec.schema.json +1221 -30
  23. package/examples/styles/catalog.json +54 -0
  24. package/examples/styles/cloudflare-workers-inspired-prototype.mmd +9 -0
  25. package/examples/styles/cloudflare-workers-inspired-prototype.style.json +110 -0
  26. package/examples/styles/cupertino-prototype.mmd +10 -0
  27. package/examples/styles/cupertino-prototype.style.json +63 -0
  28. package/examples/styles/mid-century-report.style.json +2 -2
  29. package/examples/styles/star-chart-atlas.style.json +2 -1
  30. package/examples/styles/transit-route-map.style.json +2 -2
  31. package/examples/styles/vercel-inspired-prototype.mmd +6 -0
  32. package/examples/styles/vercel-inspired-prototype.style.json +87 -0
  33. package/package.json +68 -43
  34. package/server.json +2 -2
  35. package/skills/agentic-mermaid-diagram-workflow/SKILL.md +17 -36
  36. package/skills/agentic-mermaid-diagram-workflow/references/cli.md +4 -5
  37. package/skills/agentic-mermaid-diagram-workflow/references/code-mode.md +15 -31
  38. package/skills/agentic-mermaid-diagram-workflow/references/sequence.md +10 -14
  39. package/skills/agentic-mermaid-live-editor/SKILL.md +100 -206
  40. package/AGENT_NATIVE.md +0 -607
  41. package/Instructions_for_agents.md +0 -89
  42. package/TODO.md +0 -684
  43. package/assets/hero.png +0 -0
  44. package/dist/index-wjRjbsP-.d.ts +0 -1102
  45. package/docs/agent-api-cookbook.md +0 -308
  46. package/docs/agent-mutation-policy.md +0 -104
  47. package/docs/agent-workflow-examples.md +0 -46
  48. package/docs/api.md +0 -211
  49. package/docs/ascii.md +0 -103
  50. package/docs/assets/improvements/box-start-connector.png +0 -0
  51. package/docs/assets/improvements/comment-dropped-lint.png +0 -0
  52. package/docs/assets/improvements/er-content-loss.png +0 -0
  53. package/docs/assets/improvements/fan-in-trunks.png +0 -0
  54. package/docs/assets/improvements/gantt-family.png +0 -0
  55. package/docs/assets/improvements/gantt-milestone-clamp.png +0 -0
  56. package/docs/assets/improvements/gantt-verify-seam.png +0 -0
  57. package/docs/assets/improvements/subgraph-container-edges.png +0 -0
  58. package/docs/assets/improvements/wrapper-frontmatter.png +0 -0
  59. package/docs/assets/improvements/wrapper-init-directive.png +0 -0
  60. package/docs/assets/improvements/wrapper-leading-comment.png +0 -0
  61. package/docs/assets/style-cookbook/mid-century-report.png +0 -0
  62. package/docs/assets/style-cookbook/star-chart-atlas.png +0 -0
  63. package/docs/assets/style-cookbook/transit-route-map.png +0 -0
  64. package/docs/comparison.md +0 -94
  65. package/docs/config.md +0 -105
  66. package/docs/contributing/adding-diagram-types.md +0 -144
  67. package/docs/contributing/diagram-family-citizenship.matrix.json +0 -2127
  68. package/docs/contributing/diagram-family-citizenship.md +0 -82
  69. package/docs/contributing/harvesting-upstream-tests.md +0 -126
  70. package/docs/contributing/lessons-learned.md +0 -276
  71. package/docs/contributing/releasing.md +0 -82
  72. package/docs/contributing/visual-review-evidence.md +0 -53
  73. package/docs/custom-style-cookbook.md +0 -154
  74. package/docs/design/families/README.md +0 -26
  75. package/docs/design/families/architecture-beta.md +0 -48
  76. package/docs/design/families/flowchart-parser-conformance.md +0 -22
  77. package/docs/design/families/gantt-research.md +0 -137
  78. package/docs/design/families/gantt.md +0 -329
  79. package/docs/design/families/journey-agentic-cards-before.png +0 -0
  80. package/docs/design/families/journey-experience-curve-implementation.png +0 -0
  81. package/docs/design/families/journey-mermaid-classic-implementation.png +0 -0
  82. package/docs/design/families/journey-mermaid-classic-prototype.png +0 -0
  83. package/docs/design/families/journey-mermaid-classic-prototype.svg +0 -163
  84. package/docs/design/families/journey-mermaid-classic-prototype.svg.png +0 -0
  85. package/docs/design/families/journey-migration-parity.md +0 -439
  86. package/docs/design/families/journey-section-overlap-after.png +0 -0
  87. package/docs/design/families/journey-section-overlap-before.png +0 -0
  88. package/docs/design/families/journey-usage-research.md +0 -423
  89. package/docs/design/families/journey.md +0 -153
  90. package/docs/design/families/xychart.md +0 -85
  91. package/docs/design/system/README.md +0 -45
  92. package/docs/design/system/abstraction-audit.md +0 -224
  93. package/docs/design/system/abstraction-recommendations.md +0 -655
  94. package/docs/design/system/architecture.mmd +0 -29
  95. package/docs/design/system/architecture.svg +0 -137
  96. package/docs/design/system/layout-guarantees-and-robustness.md +0 -351
  97. package/docs/design/system/layout-rubric.md +0 -138
  98. package/docs/design/system/route-contracts.md +0 -848
  99. package/docs/design/system/source-preservation-ladder.md +0 -52
  100. package/docs/design/system/styles-rollout.md +0 -216
  101. package/docs/design/system/ugly-layouts.md +0 -119
  102. package/docs/diagram-families.md +0 -193
  103. package/docs/features.md +0 -147
  104. package/docs/fork-differences.md +0 -130
  105. package/docs/getting-started.md +0 -175
  106. package/docs/issue-derived-test-cases.md +0 -156
  107. package/docs/layout-characterization/README.md +0 -245
  108. package/docs/layout-characterization/contact-sheet-families.md +0 -498
  109. package/docs/layout-characterization/contact-sheet.md +0 -638
  110. package/docs/layout-characterization/properties.md +0 -281
  111. package/docs/layout-characterization/visual-quality.md +0 -160
  112. package/docs/layout-characterization/visual-snapshots/architecture.svg +0 -79
  113. package/docs/layout-characterization/visual-snapshots/class.svg +0 -60
  114. package/docs/layout-characterization/visual-snapshots/er.svg +0 -61
  115. package/docs/layout-characterization/visual-snapshots/flowchart.svg +0 -58
  116. package/docs/layout-characterization/visual-snapshots/gantt.svg +0 -52
  117. package/docs/layout-characterization/visual-snapshots/journey.svg +0 -98
  118. package/docs/layout-characterization/visual-snapshots/pie.svg +0 -36
  119. package/docs/layout-characterization/visual-snapshots/quadrant.svg +0 -47
  120. package/docs/layout-characterization/visual-snapshots/sequence.svg +0 -59
  121. package/docs/layout-characterization/visual-snapshots/state.svg +0 -52
  122. package/docs/layout-characterization/visual-snapshots/timeline.svg +0 -64
  123. package/docs/layout-characterization/visual-snapshots/xychart.svg +0 -97
  124. package/docs/mcp-code-mode-rationale.md +0 -101
  125. package/docs/mcp-http-transport.md +0 -223
  126. package/docs/mermaid-layout-complaints.md +0 -837
  127. package/docs/mutation-testing.md +0 -206
  128. package/docs/project/divergences.md +0 -98
  129. package/docs/project/dogfooding-docs-strategy.md +0 -66
  130. package/docs/project/hosted-mcp-cloudflare-plan.md +0 -338
  131. package/docs/project/lessons-learned.md +0 -1019
  132. package/docs/project/remove-role-styling-plan.md +0 -176
  133. package/docs/quality.md +0 -215
  134. package/docs/react.md +0 -97
  135. package/docs/style-authoring.md +0 -133
  136. package/docs/testing-strategy.md +0 -335
  137. package/docs/theming.md +0 -162
  138. package/examples/agent-improve-auth-flow.ts +0 -206
  139. package/examples/agent-loop.ts +0 -53
  140. package/examples/mcp-vs-cli-complex-diagrams.ts +0 -133
  141. package/llms.txt +0 -104
  142. package/skill-evals/README.md +0 -77
  143. package/skill-evals/fixtures/architecture-cache/input.mmd +0 -5
  144. package/skill-evals/fixtures/class-payment/input.mmd +0 -4
  145. package/skill-evals/fixtures/er-orders/input.mmd +0 -10
  146. package/skill-evals/fixtures/flowchart-cache/input.mmd +0 -3
  147. package/skill-evals/fixtures/gantt-release/input.mmd +0 -7
  148. package/skill-evals/fixtures/journey-checkout/input.mmd +0 -6
  149. package/skill-evals/fixtures/pie-exports/input.mmd +0 -5
  150. package/skill-evals/fixtures/quadrant-priorities/input.mmd +0 -11
  151. package/skill-evals/fixtures/sequence-retry/input.mmd +0 -8
  152. package/skill-evals/fixtures/state-lifecycle/input.mmd +0 -5
  153. package/skill-evals/fixtures/timeline-release/input.mmd +0 -6
  154. package/skill-evals/fixtures/xychart-growth/input.mmd +0 -5
  155. package/skill-evals/shared-benchmark.json +0 -510
  156. package/src/agent/analyze.ts +0 -157
  157. package/src/agent/apply.ts +0 -146
  158. package/src/agent/architecture-body.ts +0 -458
  159. package/src/agent/certificates.ts +0 -110
  160. package/src/agent/class-body.ts +0 -319
  161. package/src/agent/core.ts +0 -207
  162. package/src/agent/create.ts +0 -106
  163. package/src/agent/describe.ts +0 -368
  164. package/src/agent/er-body.ts +0 -224
  165. package/src/agent/facts.ts +0 -360
  166. package/src/agent/families-builtin.ts +0 -920
  167. package/src/agent/families.ts +0 -232
  168. package/src/agent/family-layouts.ts +0 -832
  169. package/src/agent/flowchart-body.ts +0 -372
  170. package/src/agent/flowchart-unsupported.ts +0 -243
  171. package/src/agent/font-coverage.ts +0 -288
  172. package/src/agent/gantt-body.ts +0 -495
  173. package/src/agent/index.ts +0 -10
  174. package/src/agent/journey-body.ts +0 -374
  175. package/src/agent/label-metrics.ts +0 -28
  176. package/src/agent/layout-to-rendered.ts +0 -63
  177. package/src/agent/mutate.ts +0 -97
  178. package/src/agent/mutation-ops.ts +0 -51
  179. package/src/agent/op-schema.ts +0 -443
  180. package/src/agent/parse.ts +0 -223
  181. package/src/agent/pie-body.ts +0 -270
  182. package/src/agent/png.ts +0 -171
  183. package/src/agent/quadrant-body.ts +0 -336
  184. package/src/agent/quality.ts +0 -363
  185. package/src/agent/readability-audit.ts +0 -92
  186. package/src/agent/rendered-route-audit.ts +0 -61
  187. package/src/agent/sequence-body.ts +0 -345
  188. package/src/agent/serialize.ts +0 -214
  189. package/src/agent/state-body.ts +0 -589
  190. package/src/agent/structural-count.ts +0 -150
  191. package/src/agent/timeline-body.ts +0 -280
  192. package/src/agent/trace-log.ts +0 -43
  193. package/src/agent/types.ts +0 -995
  194. package/src/agent/verify.ts +0 -603
  195. package/src/agent/xychart-body.ts +0 -472
  196. package/src/architecture/config.ts +0 -282
  197. package/src/architecture/layout.ts +0 -496
  198. package/src/architecture/parser.ts +0 -375
  199. package/src/architecture/renderer.ts +0 -611
  200. package/src/architecture/types.ts +0 -113
  201. package/src/ascii/ansi.ts +0 -423
  202. package/src/ascii/architecture.ts +0 -210
  203. package/src/ascii/canvas.ts +0 -443
  204. package/src/ascii/class-diagram.ts +0 -697
  205. package/src/ascii/converter.ts +0 -475
  206. package/src/ascii/draw.ts +0 -1693
  207. package/src/ascii/edge-bundling.ts +0 -328
  208. package/src/ascii/edge-routing.ts +0 -330
  209. package/src/ascii/er-diagram.ts +0 -439
  210. package/src/ascii/gantt.ts +0 -276
  211. package/src/ascii/grid.ts +0 -747
  212. package/src/ascii/index.ts +0 -196
  213. package/src/ascii/journey.ts +0 -169
  214. package/src/ascii/meta.ts +0 -244
  215. package/src/ascii/multiline-utils.ts +0 -80
  216. package/src/ascii/pathfinder.ts +0 -301
  217. package/src/ascii/pie.ts +0 -67
  218. package/src/ascii/quadrant.ts +0 -158
  219. package/src/ascii/reverse.ts +0 -216
  220. package/src/ascii/sequence.ts +0 -499
  221. package/src/ascii/shapes/circle.ts +0 -27
  222. package/src/ascii/shapes/corners.ts +0 -143
  223. package/src/ascii/shapes/diamond.ts +0 -27
  224. package/src/ascii/shapes/hexagon.ts +0 -27
  225. package/src/ascii/shapes/index.ts +0 -106
  226. package/src/ascii/shapes/rectangle.ts +0 -168
  227. package/src/ascii/shapes/rounded.ts +0 -27
  228. package/src/ascii/shapes/special.ts +0 -332
  229. package/src/ascii/shapes/stadium.ts +0 -110
  230. package/src/ascii/shapes/state.ts +0 -192
  231. package/src/ascii/shapes/types.ts +0 -73
  232. package/src/ascii/timeline.ts +0 -141
  233. package/src/ascii/types.ts +0 -312
  234. package/src/ascii/validate.ts +0 -120
  235. package/src/ascii/width.ts +0 -81
  236. package/src/ascii/wrap.ts +0 -131
  237. package/src/ascii/xychart.ts +0 -919
  238. package/src/browser.ts +0 -29
  239. package/src/class/layout.ts +0 -240
  240. package/src/class/parser.ts +0 -332
  241. package/src/class/renderer.ts +0 -638
  242. package/src/class/types.ts +0 -129
  243. package/src/cli/agent-instructions.ts +0 -1
  244. package/src/cli/am-bin.ts +0 -6
  245. package/src/cli/exit-codes.ts +0 -18
  246. package/src/cli/index.ts +0 -1132
  247. package/src/cli/init-agent.ts +0 -147
  248. package/src/cli/run-entrypoint.ts +0 -10
  249. package/src/color-resolver.ts +0 -152
  250. package/src/elk-instance.ts +0 -114
  251. package/src/er/layout.ts +0 -187
  252. package/src/er/parser.ts +0 -226
  253. package/src/er/renderer.ts +0 -792
  254. package/src/er/types.ts +0 -99
  255. package/src/family-rubric.ts +0 -425
  256. package/src/font-manifest.ts +0 -31
  257. package/src/gantt/layout.ts +0 -365
  258. package/src/gantt/parser.ts +0 -282
  259. package/src/gantt/pipeline.ts +0 -27
  260. package/src/gantt/renderer.ts +0 -414
  261. package/src/gantt/schedule.ts +0 -513
  262. package/src/gantt/types.ts +0 -255
  263. package/src/index.ts +0 -368
  264. package/src/journey/layout.ts +0 -554
  265. package/src/journey/parse-core.ts +0 -251
  266. package/src/journey/parser.ts +0 -101
  267. package/src/journey/renderer.ts +0 -917
  268. package/src/journey/types.ts +0 -144
  269. package/src/layout/geometry.ts +0 -182
  270. package/src/layout/pass.ts +0 -142
  271. package/src/layout/passes/index.ts +0 -3916
  272. package/src/layout-engine.ts +0 -1565
  273. package/src/layout-rubric.ts +0 -659
  274. package/src/mcp/artifacts.ts +0 -137
  275. package/src/mcp/dynamic-harness.ts +0 -31
  276. package/src/mcp/dynamic-modules.d.ts +0 -7
  277. package/src/mcp/facade.ts +0 -608
  278. package/src/mcp/harness-runtime.ts +0 -203
  279. package/src/mcp/hosted-server.ts +0 -468
  280. package/src/mcp/mcp-bin.ts +0 -3
  281. package/src/mcp/mcp-cli.ts +0 -82
  282. package/src/mcp/protocol.ts +0 -13
  283. package/src/mcp/sandbox.ts +0 -195
  284. package/src/mcp/sdk-decl.ts +0 -391
  285. package/src/mcp/server.ts +0 -362
  286. package/src/mcp/tool-surface.ts +0 -146
  287. package/src/mermaid-source.ts +0 -655
  288. package/src/multiline-utils.ts +0 -228
  289. package/src/parser.ts +0 -1031
  290. package/src/pie/layout.ts +0 -168
  291. package/src/pie/parser.ts +0 -136
  292. package/src/pie/renderer.ts +0 -234
  293. package/src/pie/types.ts +0 -82
  294. package/src/quadrant/layout.ts +0 -191
  295. package/src/quadrant/parser.ts +0 -183
  296. package/src/quadrant/renderer.ts +0 -322
  297. package/src/quadrant/types.ts +0 -113
  298. package/src/render-family-hooks.ts +0 -244
  299. package/src/renderer.ts +0 -1099
  300. package/src/route-contracts.ts +0 -2723
  301. package/src/scene/backend.ts +0 -76
  302. package/src/scene/fidelity.ts +0 -183
  303. package/src/scene/hybrid-backend.ts +0 -174
  304. package/src/scene/ir.ts +0 -181
  305. package/src/scene/marks.ts +0 -127
  306. package/src/scene/rough-backend.ts +0 -378
  307. package/src/scene/seed.ts +0 -46
  308. package/src/scene/style-registry.ts +0 -556
  309. package/src/sequence/layout.ts +0 -456
  310. package/src/sequence/parser.ts +0 -255
  311. package/src/sequence/renderer.ts +0 -604
  312. package/src/sequence/types.ts +0 -154
  313. package/src/shape-clipping.ts +0 -351
  314. package/src/shared/accessibility-directives.ts +0 -22
  315. package/src/shared/batched.ts +0 -61
  316. package/src/shared/color-math.ts +0 -93
  317. package/src/shared/svg-a11y.ts +0 -29
  318. package/src/shared/syntax-error.ts +0 -17
  319. package/src/shared/unicode-ranges.ts +0 -135
  320. package/src/styles.ts +0 -318
  321. package/src/svg-paths.ts +0 -28
  322. package/src/text-metrics.ts +0 -248
  323. package/src/theme.ts +0 -710
  324. package/src/timeline/layout.ts +0 -381
  325. package/src/timeline/parser.ts +0 -215
  326. package/src/timeline/renderer.ts +0 -538
  327. package/src/timeline/types.ts +0 -105
  328. package/src/types.ts +0 -462
  329. package/src/website-worker-modules.d.ts +0 -18
  330. package/src/xychart/axis-utils.ts +0 -109
  331. package/src/xychart/colors.ts +0 -124
  332. package/src/xychart/config.ts +0 -88
  333. package/src/xychart/layout.ts +0 -656
  334. package/src/xychart/parser.ts +0 -504
  335. package/src/xychart/renderer.ts +0 -640
  336. package/src/xychart/types.ts +0 -282
@@ -1,917 +0,0 @@
1
- import type {
2
- PositionedJourneyActor,
3
- PositionedJourneyActorDot,
4
- PositionedJourneyDiagram,
5
- PositionedJourneyScoreGuide,
6
- PositionedJourneyScoreMarker,
7
- PositionedJourneySection,
8
- PositionedJourneyTask,
9
- PositionedJourneyTrack,
10
- } from './types.ts'
11
- import type { RenderContext } from '../types.ts'
12
- import type { DiagramColors } from '../theme.ts'
13
- import { svgOpenTag, buildStyleBlock, buildShadowDefs, resolveColors } from '../theme.ts'
14
- import { resolveJourneyStyle, resolveJourneyVisualConfig } from './layout.ts'
15
- import type { JourneyVisualConfig } from './layout.ts'
16
- import { buildAccessibilityAttrs } from '../shared/svg-a11y.ts'
17
- import { escapeAttr, renderMultilineText, escapeXml } from '../multiline-utils.ts'
18
- import { applyTextTransform } from '../styles.ts'
19
- import type { ResolvedRenderStyle } from '../styles.ts'
20
- import type { SceneDoc, SceneNode, SemanticChannels } from '../scene/ir.ts'
21
- import { hashId } from '../scene/seed.ts'
22
- import * as marks from '../scene/marks.ts'
23
- import { DefaultBackend } from '../scene/backend.ts'
24
- import { getSeriesColor, hexToHsl, hslToHex, isDarkBackground } from '../xychart/colors.ts'
25
- import { isHexColor, tryParseHex, wcagContrastRatio } from '../shared/color-math.ts'
26
- import { contrastTextColor } from '../color-resolver.ts'
27
-
28
- // ============================================================================
29
- // Journey diagram SVG renderer
30
- //
31
- // Visual language:
32
- // - Mermaid-style left-to-right experience curve
33
- // - horizontal section spans over task columns
34
- // - actor legend plus compact per-task participation dots
35
- // - score-positioned sentiment marks on a progression baseline
36
- // - root SVG accessibility metadata sourced from Mermaid accTitle/accDescr
37
- // ============================================================================
38
-
39
- const JY = {
40
- titleFontSize: 18,
41
- titleFontWeight: 600,
42
- sectionFontSize: 12,
43
- sectionFontWeight: 600,
44
- taskFontSize: 13,
45
- taskFontWeight: 500,
46
- actorFontSize: 11,
47
- actorFontWeight: 600,
48
- legendDotRadius: 5,
49
- legendLabelGap: 12,
50
- legendTitleGap: 26,
51
- } as const
52
-
53
- /** Journey scores are on a 1..5 scale; channels carry them normalized. */
54
- const JOURNEY_MAX_SCORE = 5
55
-
56
- interface JourneyPaints {
57
- arrow: string
58
- nodeFill: string
59
- nodeStroke: string
60
- groupFill: string
61
- groupStroke: string
62
- groupText: string
63
- titleColor: string
64
- sectionFills: string[]
65
- sectionBands: string[]
66
- sectionStrokes: string[]
67
- sectionTextColors: string[]
68
- actorColors: string[]
69
- scoreFaceFill: string
70
- scoreFaceStroke: string
71
- scoreFaceInk: string
72
- }
73
-
74
- /**
75
- * Render a positioned journey diagram as an SVG string.
76
- */
77
- export function renderJourneySvg(
78
- ctx: RenderContext<PositionedJourneyDiagram>,
79
- ): string {
80
- return DefaultBackend.render(lowerJourneyScene(ctx), { seed: 0 })
81
- }
82
-
83
- /**
84
- * Lower a positioned journey diagram to the SceneGraph IR.
85
- */
86
- export function lowerJourneyScene(
87
- ctx: RenderContext<PositionedJourneyDiagram>,
88
- ): SceneDoc {
89
- const { positioned: diagram, colors, options } = ctx
90
- const font = colors.font ?? 'Inter'
91
- const transparent = options.transparent ?? false
92
- const parts: SceneNode[] = []
93
- const style = resolveJourneyStyle(options)
94
- const visual = resolveJourneyVisualConfig(options)
95
- const paints = journeyPaints(style, visual, colors, {
96
- sectionCount: diagram.sections.length,
97
- actorCount: diagram.actors.length,
98
- })
99
-
100
- const accessibility = buildJourneyAccessibility(diagram)
101
- const uid = journeyNamespace(diagram)
102
- const arrowMarkerId = `${uid}-arrowhead`
103
- const titleId = `${uid}-title`
104
- const descId = `${uid}-desc`
105
- const curveMarkers = options.journey?.experienceCurve !== false
106
- ? diagram.sections.flatMap(section => section.tasks.map(task => task.marker))
107
- : []
108
- const drawCurve = curveMarkers.length >= 2
109
- const journeyCss = journeyStyles(style, visual, paints, drawCurve)
110
-
111
- parts.push(marks.prelude(
112
- {
113
- id: 'prelude',
114
- width: diagram.width,
115
- height: diagram.height,
116
- colors,
117
- transparent,
118
- font,
119
- hasMonoFont: false,
120
- extraCss: journeyCss,
121
- },
122
- openJourneySvgTag(diagram, colors, transparent, accessibility, titleId, descId, options.mermaidConfig?.journey?.useMaxWidth === true),
123
- ))
124
- if (accessibility.title) {
125
- parts.push(marks.raw({ id: 'a11y-title', role: 'chrome' },
126
- `<title id="${titleId}">${escapeXml(accessibility.title)}</title>`))
127
- }
128
- if (accessibility.description) {
129
- parts.push(marks.raw({ id: 'a11y-desc', role: 'chrome' },
130
- `<desc id="${descId}">${escapeXml(accessibility.description)}</desc>`))
131
- }
132
- parts.push(marks.raw({ id: 'style', role: 'chrome' },
133
- buildStyleBlock(font, false, colors.shadow, colors.embedFontImport)))
134
- parts.push(marks.raw({ id: 'defs', role: 'defs' }, buildJourneyDefs(colors, paints, arrowMarkerId)))
135
- parts.push(marks.raw({ id: 'journey-style', role: 'chrome' }, journeyCss))
136
-
137
- parts.push(renderScoreGuide(diagram.scoreGuide, style, arrowMarkerId))
138
-
139
- if (diagram.actors.length > 0) {
140
- parts.push(renderActorLegend(diagram.actors, style, paints))
141
- }
142
-
143
- diagram.sections.forEach((section, index) => {
144
- if (section.framed) {
145
- parts.push(renderSectionFrame(section, style, paints, index))
146
- }
147
- })
148
-
149
- // The experience curve is the journey's trajectory made visible: a smooth
150
- // line through the score markers in task order, beneath the faces. Upstream
151
- // Mermaid positions faces but never connects them; render(source,
152
- // { journey: { experienceCurve: false } }) restores that classic look.
153
- if (drawCurve) {
154
- parts.push(renderExperienceCurve(curveMarkers, style, paints))
155
- }
156
-
157
- for (const section of diagram.sections) {
158
- for (const task of section.tasks) {
159
- parts.push(renderTask(task, section.label, style, paints))
160
- }
161
- }
162
-
163
- if (diagram.title) {
164
- parts.push(marks.text(
165
- {
166
- id: 'title',
167
- role: 'title',
168
- text: diagram.title.text,
169
- x: diagram.title.x,
170
- y: diagram.title.y,
171
- fontSize: visual.titleFontSize,
172
- anchor: 'middle',
173
- paint: { fill: paints.titleColor },
174
- },
175
- renderMultilineText(
176
- diagram.title.text,
177
- diagram.title.x,
178
- diagram.title.y,
179
- visual.titleFontSize,
180
- `class="journey-title" text-anchor="middle" font-size="${escapeAttr(visual.titleFontSizeCss)}" font-weight="${JY.titleFontWeight}"${visual.titleFontFamily ? ` font-family="${escapeAttr(visual.titleFontFamily)}"` : ''}`,
181
- ),
182
- ))
183
- }
184
-
185
- parts.push(marks.raw({ id: 'svg-close', role: 'chrome' }, '</svg>'))
186
-
187
- return { family: 'journey', width: diagram.width, height: diagram.height, colors, parts }
188
- }
189
-
190
- function journeyNamespace(diagram: PositionedJourneyDiagram): string {
191
- const semanticParts = diagram.sections.flatMap(section => [
192
- section.id,
193
- section.label ?? '',
194
- ...section.tasks.flatMap(task => [
195
- task.id,
196
- task.text,
197
- String(task.score),
198
- ...task.actors,
199
- ]),
200
- ])
201
- return `journey-${hashId(
202
- diagram.width,
203
- diagram.height,
204
- diagram.title?.text ?? '',
205
- diagram.accessibilityTitle ?? '',
206
- diagram.accessibilityDescription ?? '',
207
- ...semanticParts,
208
- )}`
209
- }
210
-
211
- function buildJourneyAccessibility(diagram: PositionedJourneyDiagram): {
212
- title?: string
213
- description?: string
214
- } {
215
- return {
216
- title: diagram.accessibilityTitle ?? diagram.title?.text,
217
- description: diagram.accessibilityDescription,
218
- }
219
- }
220
-
221
- function openJourneySvgTag(
222
- diagram: PositionedJourneyDiagram,
223
- colors: DiagramColors,
224
- transparent: boolean,
225
- accessibility: { title?: string; description?: string },
226
- titleId: string,
227
- descId: string,
228
- useMaxWidth: boolean,
229
- ): string {
230
- // Mermaid's useMaxWidth contract (same shape as the xychart renderer):
231
- // a responsive width capped at the natural size, viewBox preserving aspect.
232
- return svgOpenTag(diagram.width, diagram.height, colors, transparent, {
233
- ...(useMaxWidth ? { width: '100%', height: '100%', style: `max-width:${diagram.width}px` } : {}),
234
- attrs: buildAccessibilityAttrs(accessibility.title, accessibility.description, titleId, descId, 'user journey'),
235
- })
236
- }
237
-
238
- function buildJourneyDefs(colors: DiagramColors, paints: JourneyPaints, arrowMarkerId: string): string {
239
- const defs = [
240
- buildShadowDefs(colors),
241
- ` <marker id="${escapeAttr(arrowMarkerId)}" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto">
242
- <path d="M0,0 L10,4 L0,8 Z" fill="${paints.arrow}" />
243
- </marker>`,
244
- ].filter(Boolean)
245
-
246
- return `<defs>\n${defs.join('\n')}\n</defs>`
247
- }
248
-
249
- function journeyStyles(style: ResolvedRenderStyle, visual: JourneyVisualConfig, paints: JourneyPaints, drawCurve: boolean): string {
250
- const sectionPalette = sectionPaletteCss(paints)
251
- const sectionBandPalette = sectionBandPaletteCss(paints)
252
- const sectionLabelPalette = sectionLabelPaletteCss(paints)
253
- const actorPalette = actorPaletteCss(paints)
254
-
255
- return `<style>
256
- .journey-title { fill: ${paints.titleColor}; }
257
- .journey-section-bg { fill: ${paints.groupFill}; stroke: ${paints.groupStroke}; stroke-width: ${style.groupLineWidth}; }
258
- ${sectionPalette}
259
- .journey-section-label-band { fill: ${paints.sectionBands[0]}; stroke: none; }
260
- ${sectionBandPalette}
261
- .journey-section-label { fill: ${paints.sectionTextColors[0] ?? 'var(--_text)'}; }
262
- ${sectionLabelPalette}
263
- .journey-task-box { fill: ${paints.nodeFill}; stroke: ${paints.nodeStroke}; stroke-width: ${style.nodeLineWidth}; }
264
- .journey-task-text { fill: ${style.nodeTextColor ?? 'var(--_text)'};${visual.taskFontFamily ? ` font-family: ${visual.taskFontFamily};` : ''} }
265
- .journey-track { stroke: color-mix(in srgb, ${paints.nodeStroke} 78%, var(--bg)); stroke-width: ${style.lineWidth}; stroke-dasharray: 4 7; }${drawCurve ? `
266
- .journey-curve { fill: none; stroke: color-mix(in srgb, ${paints.arrow} 55%, var(--bg)); stroke-width: ${Math.max(2, style.lineWidth * 2)}; stroke-linecap: round; }` : ''}
267
- .journey-guide { stroke: color-mix(in srgb, ${paints.nodeStroke} 62%, var(--bg)); stroke-width: 1; }
268
- .journey-score-label { fill: ${style.edgeTextColor ?? 'var(--_text-sec)'}; }
269
- .journey-baseline { stroke: ${paints.arrow}; stroke-width: ${Math.max(2, style.lineWidth * 2)}; }
270
- .journey-score-face { fill: ${paints.scoreFaceFill}; stroke: ${paints.scoreFaceStroke}; stroke-width: 1.2; }
271
- .journey-face-eye { fill: ${paints.scoreFaceInk}; }
272
- .journey-face-mouth { fill: none; stroke: ${paints.scoreFaceInk}; stroke-width: 1.6; stroke-linecap: round; }
273
- .journey-actor-legend-title { fill: ${paints.groupText}; }
274
- .journey-actor-legend-text { fill: ${paints.groupText}; }
275
- .journey-actor-dot { stroke: var(--bg); stroke-width: 1; }
276
- ${actorPalette}
277
- </style>`
278
- }
279
-
280
- function renderExperienceCurve(
281
- markers: PositionedJourneyScoreMarker[],
282
- style: ResolvedRenderStyle,
283
- paints: JourneyPaints,
284
- ): SceneNode {
285
- const points = markers.map(marker => ({ x: marker.cx, y: marker.cy }))
286
- const d = smoothCurvePath(points)
287
- return marks.connector(
288
- {
289
- id: 'experience-curve',
290
- role: 'series',
291
- geometry: { kind: 'path', d, points },
292
- lineStyle: 'solid',
293
- paint: {
294
- stroke: `color-mix(in srgb, ${paints.arrow} 55%, var(--bg))`,
295
- strokeWidth: String(Math.max(2, style.lineWidth * 2)),
296
- },
297
- },
298
- `<path class="journey-curve" d="${d}" />`,
299
- )
300
- }
301
-
302
- /** Cubic segments with horizontal tangents at each marker: smooth, monotone
303
- * between neighbors (no overshoot past a score line), and deterministic. */
304
- function smoothCurvePath(points: Array<{ x: number; y: number }>): string {
305
- const first = points[0]!
306
- let d = `M${first.x},${first.y}`
307
- for (let i = 1; i < points.length; i++) {
308
- const from = points[i - 1]!
309
- const to = points[i]!
310
- const dx = (to.x - from.x) / 3
311
- d += ` C${from.x + dx},${from.y} ${to.x - dx},${to.y} ${to.x},${to.y}`
312
- }
313
- return d
314
- }
315
-
316
- function renderScoreGuide(guide: PositionedJourneyScoreGuide, style: ResolvedRenderStyle, arrowMarkerId: string): SceneNode {
317
- const children: Array<{ node: SceneNode; indent: number }> = []
318
-
319
- for (const tick of guide.ticks) {
320
- children.push({
321
- indent: 2,
322
- node: marks.connector(
323
- {
324
- id: `score-guide:${tick.score}`,
325
- role: 'grid',
326
- geometry: { kind: 'line', x1: tick.x1, y1: tick.y, x2: tick.x2, y2: tick.y },
327
- lineStyle: 'solid',
328
- paint: {
329
- stroke: `color-mix(in srgb, ${style.nodeBorderColor ?? 'var(--_node-stroke)'} 62%, var(--bg))`,
330
- strokeWidth: '1',
331
- },
332
- channels: { value: tick.score / JOURNEY_MAX_SCORE },
333
- },
334
- `<line class="journey-guide" x1="${tick.x1}" y1="${tick.y}" x2="${tick.x2}" y2="${tick.y}" />`,
335
- ),
336
- })
337
-
338
- children.push({
339
- indent: 2,
340
- node: marks.text(
341
- {
342
- id: `score-label:${tick.score}`,
343
- role: 'axis',
344
- text: String(tick.score),
345
- x: tick.labelX,
346
- y: tick.labelY,
347
- fontSize: style.edgeLabelFontSize,
348
- anchor: 'end',
349
- paint: { fill: style.edgeTextColor ?? 'var(--_text-sec)' },
350
- channels: { value: tick.score / JOURNEY_MAX_SCORE },
351
- },
352
- renderMultilineText(
353
- String(tick.score),
354
- tick.labelX,
355
- tick.labelY,
356
- style.edgeLabelFontSize,
357
- `class="journey-score-label" text-anchor="end" font-size="${style.edgeLabelFontSize}" font-weight="${style.edgeLabelFontWeight}"${letterAttr(style.edgeLetterSpacing)}`,
358
- ),
359
- ),
360
- })
361
- }
362
-
363
- const baseline = guide.baseline
364
- children.push({
365
- indent: 2,
366
- node: marks.connector(
367
- {
368
- id: 'journey-baseline',
369
- role: 'rail',
370
- geometry: { kind: 'line', x1: baseline.x1, y1: baseline.y1, x2: baseline.x2, y2: baseline.y2 },
371
- lineStyle: 'solid',
372
- paint: {
373
- stroke: style.edgeStrokeColor ?? 'var(--_arrow)',
374
- strokeWidth: String(Math.max(2, style.lineWidth * 2)),
375
- },
376
- endMarker: { id: arrowMarkerId, shape: 'arrow' },
377
- },
378
- `<line class="journey-baseline" x1="${baseline.x1}" y1="${baseline.y1}" x2="${baseline.x2}" y2="${baseline.y2}" marker-end="url(#${escapeAttr(arrowMarkerId)})" />`,
379
- ),
380
- })
381
-
382
- return marks.group({
383
- id: 'score-guide',
384
- role: 'grid',
385
- open: `<g class="journey-score-guide" data-score-min="1" data-score-max="5">`,
386
- close: '</g>',
387
- children,
388
- })
389
- }
390
-
391
- function renderActorLegend(actors: PositionedJourneyActor[], style: ResolvedRenderStyle, paints: JourneyPaints): SceneNode {
392
- const first = actors[0]!
393
- const titleX = first.x - JY.legendDotRadius
394
- const titleY = first.y - JY.legendTitleGap
395
- const title = applyTextTransform('Actors', style.groupTextTransform)
396
- const children: Array<{ node: SceneNode; indent: number }> = [
397
- {
398
- indent: 2,
399
- node: marks.text(
400
- {
401
- id: 'actor-legend-title',
402
- role: 'legend',
403
- text: title,
404
- x: titleX,
405
- y: titleY,
406
- fontSize: style.groupHeaderFontSize,
407
- anchor: 'start',
408
- paint: { fill: style.groupTextColor ?? 'var(--_text-sec)' },
409
- },
410
- renderMultilineText(
411
- title,
412
- titleX,
413
- titleY,
414
- style.groupHeaderFontSize,
415
- `class="journey-actor-legend-title" text-anchor="start" font-size="${style.groupHeaderFontSize}" font-weight="${style.groupHeaderFontWeight}"${letterAttr(style.groupLetterSpacing)}`,
416
- ),
417
- ),
418
- },
419
- ]
420
-
421
- for (const actor of actors) {
422
- children.push({
423
- indent: 2,
424
- node: marks.shape(
425
- {
426
- id: `actor-legend-dot:${actor.label}`,
427
- role: 'actor',
428
- geometry: { kind: 'circle', cx: actor.x, cy: actor.y, r: JY.legendDotRadius },
429
- paint: { fill: actorFill(actor.colorIndex, paints), stroke: 'var(--bg)', strokeWidth: '1' },
430
- channels: { category: actor.label },
431
- },
432
- `<circle class="journey-actor-dot ${actorClass(actor.colorIndex, paints)}" data-actor="${escapeAttr(actor.label)}" cx="${actor.x}" cy="${actor.y}" r="${JY.legendDotRadius}" />`,
433
- ),
434
- })
435
-
436
- children.push({
437
- indent: 2,
438
- node: marks.text(
439
- {
440
- id: `actor-legend-label:${actor.label}`,
441
- role: 'legend',
442
- text: actor.label,
443
- x: actor.x + JY.legendDotRadius + JY.legendLabelGap,
444
- y: actor.y,
445
- fontSize: style.edgeLabelFontSize,
446
- anchor: 'start',
447
- paint: { fill: style.groupTextColor ?? 'var(--_text-sec)' },
448
- channels: { category: actor.label },
449
- },
450
- renderMultilineText(
451
- actor.label,
452
- actor.x + JY.legendDotRadius + JY.legendLabelGap,
453
- actor.y,
454
- style.edgeLabelFontSize,
455
- `class="journey-actor-legend-text" text-anchor="start" font-size="${style.edgeLabelFontSize}" font-weight="${style.edgeLabelFontWeight}"${letterAttr(style.edgeLetterSpacing)}`,
456
- ),
457
- ),
458
- })
459
- }
460
-
461
- return marks.group({
462
- id: 'actor-legend',
463
- role: 'legend',
464
- open: `<g class="journey-actor-legend">`,
465
- close: '</g>',
466
- children,
467
- })
468
- }
469
-
470
- function renderSectionFrame(section: PositionedJourneySection, style: ResolvedRenderStyle, paints: JourneyPaints, sectionIndex: number): SceneNode {
471
- const name = section.label ?? section.id
472
- const labelAttr = section.label ? ` data-label="${escapeAttr(section.label)}"` : ''
473
- const children: Array<{ node: SceneNode; indent: number }> = []
474
-
475
- children.push({
476
- indent: 2,
477
- node: marks.shape(
478
- {
479
- id: `section-bg:${name}`,
480
- role: 'section',
481
- geometry: { kind: 'rect', x: section.x, y: section.y, width: section.width, height: section.height, rx: style.groupCornerRadius, ry: style.groupCornerRadius },
482
- paint: {
483
- fill: sectionFill(sectionIndex, paints),
484
- stroke: sectionStroke(sectionIndex, paints),
485
- strokeWidth: String(style.groupLineWidth),
486
- },
487
- },
488
- `<rect class="journey-section-bg journey-section-${sectionIndex % paints.sectionFills.length}" x="${section.x}" y="${section.y}" width="${section.width}" height="${section.height}" rx="${style.groupCornerRadius}" ry="${style.groupCornerRadius}" />`,
489
- ),
490
- })
491
-
492
- if (section.label) {
493
- children.push({
494
- indent: 2,
495
- node: renderSectionLabelBand(section, style, paints, sectionIndex),
496
- })
497
- children.push({
498
- indent: 2,
499
- node: marks.text(
500
- {
501
- id: `section-label:${name}`,
502
- role: 'group-header',
503
- text: section.label,
504
- x: section.labelX,
505
- y: section.labelY,
506
- fontSize: style.groupHeaderFontSize,
507
- anchor: 'middle',
508
- paint: { fill: sectionTextColor(sectionIndex, paints) },
509
- },
510
- renderMultilineText(
511
- section.label,
512
- section.labelX,
513
- section.labelY,
514
- style.groupHeaderFontSize,
515
- `class="journey-section-label journey-section-label-${sectionIndex % paints.sectionTextColors.length}" text-anchor="middle" font-size="${style.groupHeaderFontSize}" font-weight="${style.groupHeaderFontWeight}"${style.groupFont ? ` font-family="${escapeAttr(style.groupFont)}"` : ''}${letterAttr(style.groupLetterSpacing)}`,
516
- ),
517
- ),
518
- })
519
- }
520
-
521
- return marks.group({
522
- id: `section:${name}`,
523
- role: 'section',
524
- open: `<g class="journey-section" data-id="${escapeAttr(section.id)}"${labelAttr}>`,
525
- close: '</g>',
526
- children,
527
- channels: { category: name },
528
- })
529
- }
530
-
531
- function renderSectionLabelBand(section: PositionedJourneySection, style: ResolvedRenderStyle, paints: JourneyPaints, sectionIndex: number): SceneNode {
532
- const bandInset = Math.min(6, Math.max(3, section.height / 6))
533
- const bandHeight = Math.max(18, Math.min(section.height - bandInset * 2, style.groupHeaderFontSize + style.groupPaddingY))
534
- const bandX = section.x + bandInset
535
- const bandY = section.labelY - bandHeight / 2
536
- const bandWidth = Math.max(0, section.width - bandInset * 2)
537
- const radius = Math.min(style.groupCornerRadius, bandHeight / 2)
538
-
539
- return marks.shape(
540
- {
541
- id: `section-band:${section.label ?? section.id}`,
542
- role: 'group-header',
543
- geometry: { kind: 'rect', x: bandX, y: bandY, width: bandWidth, height: bandHeight, rx: radius, ry: radius },
544
- paint: { fill: sectionHeaderFill(sectionIndex, paints), stroke: 'none' },
545
- channels: { category: section.label ?? section.id },
546
- },
547
- `<rect class="journey-section-label-band journey-section-band-${sectionIndex % paints.sectionBands.length}" x="${bandX}" y="${bandY}" width="${bandWidth}" height="${bandHeight}" rx="${radius}" ry="${radius}" />`,
548
- )
549
- }
550
-
551
- function renderTask(task: PositionedJourneyTask, sectionLabel: string | undefined, style: ResolvedRenderStyle, paints: JourneyPaints): SceneNode {
552
- const sectionAttr = sectionLabel ? ` data-section="${escapeAttr(sectionLabel)}"` : ''
553
- const actorAttr = task.actors.length > 0 ? ` data-actors="${escapeAttr(task.actors.join(', '))}"` : ''
554
- const value = task.score / JOURNEY_MAX_SCORE
555
- const channels: SemanticChannels = sectionLabel ? { value, category: sectionLabel } : { value }
556
- const children: Array<{ node: SceneNode; indent: number }> = [
557
- { indent: 2, node: renderTrack(task.track, task, style, paints) },
558
- { indent: 2, node: renderTaskBox(task, style, paints, channels) },
559
- { indent: 2, node: renderTaskLabel(task, style, channels) },
560
- ]
561
-
562
- for (const dot of task.actorDots) {
563
- children.push({ indent: 2, node: renderActorDot(dot, task.text, paints) })
564
- }
565
-
566
- children.push({ indent: 2, node: renderScoreMarker(task.marker, task.text, paints, channels) })
567
-
568
- return marks.group({
569
- id: `task:${task.text}`,
570
- role: 'task',
571
- open: `<g class="journey-task" data-id="${escapeAttr(task.id)}" data-score="${task.score}"${sectionAttr}${actorAttr}>`,
572
- close: '</g>',
573
- children,
574
- channels,
575
- })
576
- }
577
-
578
- function renderTrack(track: PositionedJourneyTrack, task: PositionedJourneyTask, style: ResolvedRenderStyle, paints: JourneyPaints): SceneNode {
579
- return marks.connector(
580
- {
581
- id: `track:${task.text}`,
582
- role: 'marker-line',
583
- geometry: { kind: 'line', x1: track.x, y1: track.y1, x2: track.x, y2: track.y2 },
584
- lineStyle: 'dashed',
585
- paint: {
586
- stroke: `color-mix(in srgb, ${paints.nodeStroke} 78%, var(--bg))`,
587
- strokeWidth: String(style.lineWidth),
588
- strokeDasharray: '4 7',
589
- },
590
- channels: { value: task.score / JOURNEY_MAX_SCORE },
591
- },
592
- `<line class="journey-track" x1="${track.x}" y1="${track.y1}" x2="${track.x}" y2="${track.y2}" />`,
593
- )
594
- }
595
-
596
- function renderTaskBox(task: PositionedJourneyTask, style: ResolvedRenderStyle, paints: JourneyPaints, channels: SemanticChannels): SceneNode {
597
- return marks.shape(
598
- {
599
- id: `task-box:${task.text}`,
600
- role: 'task',
601
- geometry: { kind: 'rect', x: task.x, y: task.y, width: task.width, height: task.height, rx: style.cornerRadius ?? 0, ry: style.cornerRadius ?? 0 },
602
- paint: {
603
- fill: paints.nodeFill,
604
- stroke: paints.nodeStroke,
605
- strokeWidth: String(style.nodeLineWidth),
606
- },
607
- channels,
608
- },
609
- `<rect class="journey-task-box" x="${task.x}" y="${task.y}" width="${task.width}" height="${task.height}" rx="${style.cornerRadius ?? 0}" ry="${style.cornerRadius ?? 0}" />`,
610
- )
611
- }
612
-
613
- function renderTaskLabel(task: PositionedJourneyTask, style: ResolvedRenderStyle, channels: SemanticChannels): SceneNode {
614
- return marks.text(
615
- {
616
- id: `task-label:${task.text}`,
617
- role: 'label',
618
- text: task.text,
619
- x: task.textX,
620
- y: task.textY,
621
- fontSize: style.nodeLabelFontSize,
622
- anchor: 'middle',
623
- paint: { fill: style.nodeTextColor ?? 'var(--_text)' },
624
- channels,
625
- },
626
- renderMultilineText(
627
- task.text,
628
- task.textX,
629
- task.textY,
630
- style.nodeLabelFontSize,
631
- `class="journey-task-text" text-anchor="middle" font-size="${style.nodeLabelFontSize}" font-weight="${style.nodeLabelFontWeight}"${letterAttr(style.nodeLetterSpacing)}`,
632
- ),
633
- )
634
- }
635
-
636
- function renderActorDot(dot: PositionedJourneyActorDot, taskText: string, paints: JourneyPaints): SceneNode {
637
- return marks.shape(
638
- {
639
- id: `actor-dot:${taskText}:${dot.label}`,
640
- role: 'actor',
641
- geometry: { kind: 'circle', cx: dot.x, cy: dot.y, r: dot.r },
642
- paint: { fill: actorFill(dot.colorIndex, paints), stroke: 'var(--bg)', strokeWidth: '1' },
643
- channels: { category: dot.label },
644
- },
645
- `<circle class="journey-actor-dot ${actorClass(dot.colorIndex, paints)}" data-actor="${escapeAttr(dot.label)}" cx="${dot.x}" cy="${dot.y}" r="${dot.r}" />`,
646
- )
647
- }
648
-
649
- function renderScoreMarker(marker: PositionedJourneyScoreMarker, taskText: string, paints: JourneyPaints, channels: SemanticChannels): SceneNode {
650
- const eyeY = marker.cy - 4.5
651
- const leftEyeX = marker.cx - 5.5
652
- const rightEyeX = marker.cx + 5.5
653
- const mouth = mouthPath(marker)
654
-
655
- return marks.group({
656
- id: `score-marker:${taskText}`,
657
- role: 'score',
658
- open: `<g class="journey-score-marker" data-score="${marker.score}">`,
659
- close: '</g>',
660
- children: [
661
- {
662
- indent: 2,
663
- node: marks.shape(
664
- {
665
- id: `score-face:${taskText}`,
666
- role: 'score',
667
- geometry: { kind: 'circle', cx: marker.cx, cy: marker.cy, r: marker.r },
668
- paint: { fill: paints.scoreFaceFill, stroke: paints.scoreFaceStroke, strokeWidth: '1.2' },
669
- channels,
670
- },
671
- `<circle class="journey-score-face" cx="${marker.cx}" cy="${marker.cy}" r="${marker.r}" />`,
672
- ),
673
- },
674
- {
675
- indent: 2,
676
- node: marks.shape(
677
- {
678
- id: `score-eye-left:${taskText}`,
679
- role: 'score',
680
- geometry: { kind: 'circle', cx: leftEyeX, cy: eyeY, r: 2 },
681
- paint: { fill: paints.scoreFaceInk },
682
- channels,
683
- },
684
- `<circle class="journey-face-eye" cx="${leftEyeX}" cy="${eyeY}" r="2" />`,
685
- ),
686
- },
687
- {
688
- indent: 2,
689
- node: marks.shape(
690
- {
691
- id: `score-eye-right:${taskText}`,
692
- role: 'score',
693
- geometry: { kind: 'circle', cx: rightEyeX, cy: eyeY, r: 2 },
694
- paint: { fill: paints.scoreFaceInk },
695
- channels,
696
- },
697
- `<circle class="journey-face-eye" cx="${rightEyeX}" cy="${eyeY}" r="2" />`,
698
- ),
699
- },
700
- {
701
- indent: 2,
702
- node: marks.shape(
703
- {
704
- id: `score-mouth:${taskText}`,
705
- role: 'score',
706
- geometry: { kind: 'path', d: mouth },
707
- paint: { fill: 'none', stroke: paints.scoreFaceInk, strokeWidth: '1.6' },
708
- channels,
709
- },
710
- `<path class="journey-face-mouth" d="${mouth}" />`,
711
- ),
712
- },
713
- ],
714
- channels,
715
- })
716
- }
717
-
718
- function mouthPath(marker: PositionedJourneyScoreMarker): string {
719
- const cx = marker.cx
720
- const cy = marker.cy
721
-
722
- if (marker.score >= 5) return `M${cx - 8},${cy + 4} Q${cx},${cy + 13} ${cx + 8},${cy + 4}`
723
- if (marker.score >= 4) return `M${cx - 8},${cy + 5} Q${cx},${cy + 11} ${cx + 8},${cy + 5}`
724
- if (marker.score === 3) return `M${cx - 8},${cy + 6} L${cx + 8},${cy + 6}`
725
- if (marker.score === 2) return `M${cx - 8},${cy + 10} Q${cx},${cy + 2} ${cx + 8},${cy + 10}`
726
- return `M${cx - 9},${cy + 11} Q${cx},${cy} ${cx + 9},${cy + 11}`
727
- }
728
-
729
- interface JourneyPaintCounts {
730
- sectionCount: number
731
- actorCount: number
732
- }
733
-
734
- function journeyPaints(
735
- style: ResolvedRenderStyle,
736
- visual: JourneyVisualConfig,
737
- colors: DiagramColors,
738
- counts: JourneyPaintCounts,
739
- ): JourneyPaints {
740
- const arrow = style.edgeStrokeColor ?? 'var(--_arrow)'
741
- const nodeFill = style.nodeFillColor ?? 'var(--_node-fill)'
742
- const nodeStroke = style.nodeBorderColor ?? 'var(--_node-stroke)'
743
- const groupFill = style.groupFillColor ?? `color-mix(in srgb, ${arrow} 8%, var(--bg))`
744
- const groupStroke = style.groupBorderColor ?? 'var(--_node-stroke)'
745
- const groupText = style.groupTextColor ?? 'var(--_text-sec)'
746
- const sectionBases = paletteBases(arrow, colors, style, counts.sectionCount)
747
- const configuredSectionCount = Math.max(
748
- visual.sectionFills.length,
749
- visual.sectionColours.length,
750
- Math.min(sectionBases.length, Math.max(counts.sectionCount, 1)),
751
- )
752
- const sectionFills = Array.from({ length: configuredSectionCount }, (_unused, index) => {
753
- const explicitFill = visual.sectionFills[index % visual.sectionFills.length]
754
- return explicitFill ?? style.groupFillColor ?? `color-mix(in srgb, ${sectionBases[index % sectionBases.length]} ${index === 0 ? 8 : 9}%, var(--bg))`
755
- })
756
- // An explicit Mermaid sectionFill is used as-authored for the label band
757
- // (Mermaid semantics: the header band IS the section color), so Mermaid's
758
- // stock sectionColours stay readable on it.
759
- const sectionBands = Array.from({ length: configuredSectionCount }, (_unused, index) => {
760
- const explicitFill = visual.sectionFills[index % visual.sectionFills.length]
761
- return explicitFill
762
- ?? style.groupHeaderFillColor
763
- ?? `color-mix(in srgb, ${sectionBases[index % sectionBases.length]} ${index === 0 ? 14 : 16}%, var(--bg))`
764
- })
765
- const sectionStrokes = Array.from({ length: configuredSectionCount }, (_unused, index) => {
766
- const explicitFill = visual.sectionFills[index % visual.sectionFills.length]
767
- return explicitFill
768
- ? `color-mix(in srgb, ${explicitFill} ${index === 0 ? 42 : 38}%, var(--bg))`
769
- : style.groupBorderColor ?? `color-mix(in srgb, ${sectionBases[index % sectionBases.length]} ${index === 0 ? 42 : 38}%, var(--bg))`
770
- })
771
- const sectionTextColors = Array.from({ length: configuredSectionCount }, (_unused, index) =>
772
- contrastGuardedLabelColor(
773
- visual.sectionColours.length > 0 ? visual.sectionColours[index % visual.sectionColours.length] : undefined,
774
- sectionBands[index]!,
775
- style.groupTextColor ?? 'var(--_text)',
776
- ),
777
- )
778
- const actorColors = visual.actorColours.length > 0
779
- ? visual.actorColours
780
- : actorPalette(arrow, colors, style, counts.actorCount)
781
-
782
- return {
783
- arrow,
784
- nodeFill,
785
- nodeStroke,
786
- groupFill,
787
- groupStroke,
788
- groupText,
789
- titleColor: visual.titleColor ?? style.groupTextColor ?? style.nodeTextColor ?? 'var(--_text)',
790
- sectionFills,
791
- sectionBands,
792
- sectionStrokes,
793
- sectionTextColors,
794
- actorColors,
795
- scoreFaceFill: `color-mix(in srgb, ${arrow} 22%, var(--bg))`,
796
- scoreFaceStroke: arrow,
797
- scoreFaceInk: style.edgeTextColor ?? style.nodeTextColor ?? 'var(--_text)',
798
- }
799
- }
800
-
801
- function paletteBases(arrow: string, colors: DiagramColors, style: ResolvedRenderStyle, sectionCount: number): string[] {
802
- const series = concreteSeriesColors(colors, style, Math.max(6, sectionCount))
803
- if (series) return series
804
- return [
805
- arrow,
806
- 'var(--line, var(--_line))',
807
- 'var(--accent, var(--_arrow))',
808
- 'var(--muted, var(--_text-sec))',
809
- 'var(--border, var(--_node-stroke))',
810
- 'var(--fg)',
811
- ]
812
- }
813
-
814
- /** Explicit label color wins only when it clears WCAG AA (4.5:1) against the
815
- * band; otherwise flip to the band's black/white contrast color. Non-hex
816
- * bands (derived color-mix paints) are contrast-safe by construction, so the
817
- * explicit/fallback color passes through untouched there. */
818
- function contrastGuardedLabelColor(explicit: string | undefined, band: string, fallback: string): string {
819
- if (!tryParseHex(band)) return explicit ?? fallback
820
- if (explicit) {
821
- const ratio = wcagContrastRatio(explicit, band)
822
- if (ratio === null || ratio >= 4.5) return explicit
823
- }
824
- return contrastTextColor(band) ?? explicit ?? fallback
825
- }
826
-
827
- /** Actor identity is carried by 4px dots, where only hue differences read.
828
- * Derived actor colors therefore rotate hue (golden-angle steps from the
829
- * accent) at fixed saturation/lightness, sized to the actual actor count —
830
- * two actors can never share a color because the palette ran out. */
831
- function actorPalette(arrow: string, colors: DiagramColors, style: ResolvedRenderStyle, actorCount: number): string[] {
832
- const count = Math.max(actorCount, 1)
833
- if (isHexColor(colors.bg) && isHexColor(colors.fg)) {
834
- const resolved = resolveColors(colors)
835
- const accent = firstHexColor(style.edgeStrokeColor, colors.accent, resolved.arrow)
836
- if (accent) {
837
- const [accentHue, accentSat] = hexToHsl(accent)
838
- const dark = isDarkBackground(colors.bg)
839
- // Neutral accents (the default gray theme) have no meaningful hue, so
840
- // anchor the wheel on the indigo family the derived palettes lean on.
841
- const baseHue = accentSat < 20 ? 230 : accentHue
842
- const saturation = Math.min(72, Math.max(42, accentSat < 20 ? 46 : accentSat))
843
- const lightness = dark ? 64 : 38
844
- return Array.from({ length: count }, (_unused, index) =>
845
- hslToHex((baseHue + index * 137.508) % 360, saturation, lightness))
846
- }
847
- }
848
- const fallback = [
849
- arrow,
850
- 'var(--line, var(--_line))',
851
- 'var(--accent, var(--_arrow))',
852
- 'var(--muted, var(--_text-sec))',
853
- 'var(--border, var(--_node-stroke))',
854
- 'var(--fg)',
855
- 'color-mix(in srgb, var(--accent, var(--_arrow)) 62%, var(--bg))',
856
- 'color-mix(in srgb, var(--line, var(--_line)) 72%, var(--bg))',
857
- ]
858
- return fallback.slice(0, Math.max(count <= fallback.length ? count : fallback.length, 1))
859
- }
860
-
861
- function concreteSeriesColors(colors: DiagramColors, style: ResolvedRenderStyle, count: number): string[] | undefined {
862
- if (!isHexColor(colors.bg) || !isHexColor(colors.fg)) return undefined
863
- const resolved = resolveColors(colors)
864
- const accent = firstHexColor(style.edgeStrokeColor, colors.accent, resolved.arrow)
865
- if (!accent) return undefined
866
- return Array.from({ length: count }, (_unused, index) => getSeriesColor(index, accent, colors.bg))
867
- }
868
-
869
- function firstHexColor(...values: Array<string | undefined>): string | undefined {
870
- return values.find((value): value is string => value !== undefined && isHexColor(value))
871
- }
872
-
873
- function actorClass(index: number, paints: JourneyPaints): string {
874
- return `journey-actor-${index % paints.actorColors.length}`
875
- }
876
-
877
- function actorFill(index: number, paints: JourneyPaints): string {
878
- return paints.actorColors[index % paints.actorColors.length]!
879
- }
880
-
881
- function sectionFill(index: number, paints: JourneyPaints): string {
882
- return paints.sectionFills[index % paints.sectionFills.length]!
883
- }
884
-
885
- function sectionHeaderFill(index: number, paints: JourneyPaints): string {
886
- return paints.sectionBands[index % paints.sectionBands.length]!
887
- }
888
-
889
- function sectionStroke(index: number, paints: JourneyPaints): string {
890
- return paints.sectionStrokes[index % paints.sectionStrokes.length]!
891
- }
892
-
893
- function sectionTextColor(index: number, paints: JourneyPaints): string {
894
- return paints.sectionTextColors[index % paints.sectionTextColors.length]!
895
- }
896
-
897
- function sectionPaletteCss(paints: JourneyPaints): string {
898
- return paints.sectionFills.map((f, index) =>
899
- ` .journey-section-${index} { fill: ${f}; stroke: ${paints.sectionStrokes[index]!}; }`,
900
- ).join('\n')
901
- }
902
-
903
- function sectionBandPaletteCss(paints: JourneyPaints): string {
904
- return paints.sectionBands.map((f, index) => ` .journey-section-band-${index} { fill: ${f}; }`).join('\n')
905
- }
906
-
907
- function sectionLabelPaletteCss(paints: JourneyPaints): string {
908
- return paints.sectionTextColors.map((fill, index) => ` .journey-section-label-${index} { fill: ${fill}; }`).join('\n')
909
- }
910
-
911
- function actorPaletteCss(paints: JourneyPaints): string {
912
- return paints.actorColors.map((fill, index) => ` .journey-actor-${index} { fill: ${fill}; }`).join('\n')
913
- }
914
-
915
- function letterAttr(value: number): string {
916
- return value !== 0 ? ` letter-spacing="${value}"` : ''
917
- }