@fengwk/kchart 0.1.0 → 0.2.0

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 (103) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +31 -2
  3. package/README.zh-CN.md +31 -2
  4. package/dist/esm/_virtual/_kchart-families.js +2 -1
  5. package/dist/esm/assets/themes/cloudmusic.js +1 -1
  6. package/dist/esm/chart/composition.js +7 -5
  7. package/dist/esm/chart/maps.js +9 -7
  8. package/dist/esm/chart/mindmap.js +19 -5
  9. package/dist/esm/chart/multivariate.js +99 -49
  10. package/dist/esm/chart/relations.js +15 -7
  11. package/dist/esm/chart/spec.js +11 -4
  12. package/dist/esm/core/context.js +29 -10
  13. package/dist/esm/core/scene.js +238 -21
  14. package/dist/esm/core/text.js +1 -1
  15. package/dist/esm/diagram/block.js +287 -295
  16. package/dist/esm/diagram/blocks.js +541 -605
  17. package/dist/esm/diagram/board-paint.js +594 -0
  18. package/dist/esm/diagram/board-route.js +60 -0
  19. package/dist/esm/diagram/c4.js +75 -35
  20. package/dist/esm/diagram/class.js +3 -2
  21. package/dist/esm/diagram/cynefin.js +55 -9
  22. package/dist/esm/diagram/eventmodeling.js +21 -10
  23. package/dist/esm/diagram/gantt.js +37 -15
  24. package/dist/esm/diagram/gitgraph.js +26 -5
  25. package/dist/esm/diagram/graph-layout.js +39 -2
  26. package/dist/esm/diagram/graph-route.js +296 -38
  27. package/dist/esm/diagram/info.js +32 -0
  28. package/dist/esm/diagram/journey.js +5 -5
  29. package/dist/esm/diagram/kanban.js +3 -3
  30. package/dist/esm/diagram/layers.js +9 -7
  31. package/dist/esm/diagram/mindmap.js +5 -1
  32. package/dist/esm/diagram/numeric-composition.js +24 -4
  33. package/dist/esm/diagram/numeric-model.js +1 -1
  34. package/dist/esm/diagram/numeric-radar.js +25 -7
  35. package/dist/esm/diagram/numeric-sankey.js +4 -3
  36. package/dist/esm/diagram/numeric-xy.js +14 -4
  37. package/dist/esm/diagram/packet.js +4 -4
  38. package/dist/esm/diagram/quadrant.js +12 -5
  39. package/dist/esm/diagram/railroad-parse.js +20 -10
  40. package/dist/esm/diagram/railroad.js +1 -1
  41. package/dist/esm/diagram/registry.js +46 -8
  42. package/dist/esm/diagram/sequence.js +43 -6
  43. package/dist/esm/diagram/swimlane.js +2 -2
  44. package/dist/esm/diagram/time.js +3 -3
  45. package/dist/esm/diagram/timeline.js +5 -5
  46. package/dist/esm/diagram/treeview.js +5 -3
  47. package/dist/esm/diagram/venn.js +117 -149
  48. package/dist/esm/diagram/wardley.js +61 -26
  49. package/dist/esm/diagram/zenuml.js +338 -0
  50. package/dist/esm/index.d.ts +3 -1
  51. package/dist/esm/mermaid.d.ts +1 -1
  52. package/dist/esm/mermaid.js +2 -1
  53. package/dist/esm/node.js +8 -2
  54. package/dist/esm/src/families.js +6 -1
  55. package/dist/units/chart/composition.js +1 -1
  56. package/dist/units/chart/maps.js +1 -1
  57. package/dist/units/chart/mindmap.js +1 -1
  58. package/dist/units/chart/multivariate.js +1 -1
  59. package/dist/units/chart/relations.js +1 -1
  60. package/dist/units/chart/spec.js +1 -1
  61. package/dist/units/core/context.js +1 -1
  62. package/dist/units/core/scene.js +1 -1
  63. package/dist/units/core/text.js +1 -1
  64. package/dist/units/core/theme.js +1 -1
  65. package/dist/units/diagram/block.js +2 -2
  66. package/dist/units/diagram/blocks.js +2 -2
  67. package/dist/units/diagram/board-paint.js +1 -0
  68. package/dist/units/diagram/board-route.js +1 -0
  69. package/dist/units/diagram/c4.js +1 -1
  70. package/dist/units/diagram/class.js +2 -2
  71. package/dist/units/diagram/cynefin.js +2 -2
  72. package/dist/units/diagram/eventmodeling.js +4 -4
  73. package/dist/units/diagram/gantt.js +3 -3
  74. package/dist/units/diagram/gitgraph.js +2 -1
  75. package/dist/units/diagram/graph-layout.js +1 -1
  76. package/dist/units/diagram/graph-route.js +1 -1
  77. package/dist/units/diagram/info.js +2 -0
  78. package/dist/units/diagram/journey.js +3 -3
  79. package/dist/units/diagram/kanban.js +1 -1
  80. package/dist/units/diagram/layers.js +1 -1
  81. package/dist/units/diagram/mindmap.js +1 -1
  82. package/dist/units/diagram/numeric-composition.js +1 -1
  83. package/dist/units/diagram/numeric-model.js +1 -1
  84. package/dist/units/diagram/numeric-radar.js +2 -2
  85. package/dist/units/diagram/numeric-sankey.js +1 -1
  86. package/dist/units/diagram/numeric-xy.js +1 -1
  87. package/dist/units/diagram/packet.js +1 -1
  88. package/dist/units/diagram/quadrant.js +1 -1
  89. package/dist/units/diagram/railroad-parse.js +2 -2
  90. package/dist/units/diagram/railroad.js +1 -1
  91. package/dist/units/diagram/registry.js +2 -2
  92. package/dist/units/diagram/sequence.js +1 -1
  93. package/dist/units/diagram/swimlane.js +2 -2
  94. package/dist/units/diagram/time.js +1 -1
  95. package/dist/units/diagram/timeline.js +1 -1
  96. package/dist/units/diagram/treeview.js +1 -1
  97. package/dist/units/diagram/venn.js +2 -2
  98. package/dist/units/diagram/wardley.js +4 -4
  99. package/dist/units/diagram/zenuml.js +2 -0
  100. package/dist/units.json +82 -52
  101. package/package.json +1 -1
  102. package/dist/esm/diagram/relations.js +0 -966
  103. package/dist/units/diagram/relations.js +0 -3
@@ -1,2 +1,2 @@
1
- KChartUnits["diagram/swimlane"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r={lanes:6,nodes:30,edges:50,backEdges:3,lines:3,labelWidth:208},i=36,a=10,o=28,s=16,c=12,l=24,u=4,d=12,f=12,p=12,m=24,h=10,g=5,_=4,v=8,y=8,b=44,ee=40,te=40,x=(e,n,r,i,a,o)=>(0,t.error)(e,n,r,i,a,o);function ne(e,t,n){let r=e.LR===!0?`LR`:e.TB===!0?`TB`:null,i=t.find(e=>/^direction\s+/i.test(e.text)),a=i?i.text.replace(/^direction\s+/i,``).trim().toUpperCase():null,o=a===`TD`?`TB`:a;if(r&&o&&r!==o)return{error:x(n.lang,i.line,`泳道方向声明冲突`,`Conflicting swimlane directions`,`只保留 swimlane LR/TB 或正文 direction 其中一种`,`Keep either swimlane LR/TB or one direction statement`)};let s=r||o||`TB`;return[`TB`,`LR`].includes(s)?{direction:s,line:i}:{error:x(n.lang,i?.line||n.firstLine-1,`泳道只支持 TB 或 LR`,`Swimlanes only support TB or LR`,`改成 swimlane、swimlane LR 或 direction TB/LR`,`Use swimlane, swimlane LR, or direction TB/LR`)}}function S(e,i={}){let a={...i,lang:i.lang||`zh`,firstLine:i.firstLine||1,options:i.options||{}},o=[],{lang:s}=a;for(let e of Object.keys(a.options))[`LR`,`TB`].includes(e)||o.push(x(s,a.firstLine-1,`swimlane 不支持选项「${e}」`,`Unsupported swimlane option: ${e}`,`只使用 swimlane、swimlane LR 或 swimlane TB`,`Use only swimlane, swimlane LR, or swimlane TB`));let c=String(e).split(`
2
- `).map((e,t)=>({raw:e,line:a.firstLine+t})).filter(e=>e.raw.trim()&&!e.raw.trimStart().startsWith(`%%`));c.some(e=>/^\s*\t/.test(e.raw))&&o.push(x(s,c.find(e=>/^\s*\t/.test(e.raw)).line,`缩进不能使用 Tab`,`Tabs are not allowed in indentation`,`把 Tab 换成空格`,`Replace tabs with spaces`));let l=c.filter(e=>!/^\s*\t/.test(e.raw)).map(e=>({...e,indent:e.raw.match(/^ */)[0].length,text:e.raw.trim()})),u=ne(a.options,l,a);u.error&&o.push(u.error);let d=[],f=new Map,p=new Map,m=[],h=null,g=null;for(let e of l)if(!/^direction\b/i.test(e.text)){if(/^lane\s+/i.test(e.text)){e.indent!==0&&o.push(x(s,e.line,`lane 必须写在顶层`,`lane must be at the top level`,`去掉 lane 前面的缩进`,`Remove indentation before lane`));let t=e.text.replace(/^lane\s+/i,``).trim();(!t||f.has(t))&&o.push(x(s,e.line,`泳道名称无效或重复:${t||`(空)`}`,`Invalid or duplicate lane: ${t||`(empty)`}`,`给每条泳道一个不重复的名称`,`Give each lane a unique name`)),h={id:`lane-${d.length}`,name:t,line:e.line},d.push(h),f.set(t,h),g=null}else h&&e.indent>0?(g??=e.indent,e.indent!==g&&o.push(x(s,e.line,`同一泳道内的缩进不一致`,`Inconsistent indentation inside a lane`,`把这一行缩进改为 ${g} 个空格`,`Indent this line with ${g} spaces`)),m.push(e)):e.indent===0?(h=null,m.push(e)):o.push(x(s,e.line,`节点必须写在 lane 下面`,`A node must be indented under a lane`,`先声明 lane,再缩进写节点`,`Declare a lane, then indent its nodes`))}d.length||o.push(x(s,a.firstLine,`图中没有泳道`,`Swimlane diagram has no lanes`,`添加 lane 名称和缩进的节点`,`Add lane names and indented nodes`)),d.length>r.lanes&&o.push(x(s,d[r.lanes].line,`最多 ${r.lanes} 条泳道`,`At most ${r.lanes} lanes`,`把流程拆成两张泳道图`,`Split the flow into two swimlane diagrams`));let _=(0,n.parseFlow)(m.map(({text:e,line:t})=>({text:e,line:t})),{direction:u.direction||`TB`});o.push(..._.errors.filter(e=>!/超过上限/.test(e.message)));let v=_.model,y=new Map,b=null;for(let e of l)if(/^lane\s+/i.test(e.text)&&e.indent===0)b=d.find(t=>t.line===e.line);else if(!b||e.indent===0)b=null;else for(let t of e.text.matchAll(/(?:^|[\s&])([A-Za-z_][\w-]*)\s*[\[\(\{>]/g)){let n=t[1];y.has(n)&&y.get(n)!==b.id?o.push(x(s,e.line,`节点 ${n} 重复归属`,`Node ${n} belongs to more than one lane`,`只在一条泳道里定义这个节点`,`Define this node in only one lane`)):y.set(n,b.id)}let ee=new Set;l.forEach(e=>{e.indent>0&&ee.add(e.line)});for(let e of v.nodes)if(!ee.has(e.line))o.push(x(s,e.line,`节点 ${e.id} 没有泳道`,`Node ${e.id} has no lane`,`把节点定义缩进到对应 lane 下面`,`Indent the node definition under its lane`));else if(p.has(e.id))o.push(x(s,e.line,`节点 ${e.id} 重复归属`,`Node ${e.id} belongs to more than one lane`,`只在一条泳道里定义这个节点`,`Define this node in only one lane`));else{let t=[...d].reverse().find(t=>t.line<e.line);p.set(e.id,t?.id||null)}return v.nodes.length>r.nodes&&o.push(x(s,v.nodes[r.nodes].line,`最多 ${r.nodes} 个节点`,`At most ${r.nodes} nodes`,`拆成总图和局部图`,`Split into an overview and a detail diagram`)),v.edges.length>r.edges&&o.push(x(s,v.edges[r.edges].line,`最多 ${r.edges} 条连线`,`At most ${r.edges} edges`,`拆成总图和局部图`,`Split into an overview and a detail diagram`)),{model:{type:`swimlane`,direction:u.direction||`TB`,lanes:d.map(e=>({...e,nodes:v.nodes.filter(t=>p.get(t.id)===e.id).map(e=>e.id)})),nodes:v.nodes.map(e=>({id:e.id,label:(0,t.labelText)(e.label),shape:e.shape,class:e.class||null,lane:p.get(e.id)||null,line:e.line})),edges:v.edges.map(e=>({id:`e${e.seq}`,from:e.from,to:e.to,label:(0,t.labelText)(e.label),style:e.style,line:e.line}))},errors:o}}function re(e,t){let n=new Map(e.map(e=>[e.id,[]]));t.forEach((e,t)=>n.get(e.from)?.push({edge:e,index:t}));for(let e of n.values())e.sort((e,t)=>e.index-t.index);let r=new Set,i=new Set,a=[],o=e=>{r.add(e),i.add(e);for(let t of n.get(e)||[])i.has(t.edge.to)?a.push(t.edge):r.has(t.edge.to)||o(t.edge.to);i.delete(e)};for(let t of e)r.has(t.id)||o(t.id);return a}function ie(e,t,n){let r=new Map(e.map(e=>[e.id,0])),i=new Map(e.map(e=>[e.id,[]]));for(let e of t)n.has(e)||(r.set(e.to,r.get(e.to)+1),i.get(e.from).push(e.to));let a=new Map(e.map(e=>[e.id,0])),o=e.filter(e=>r.get(e.id)===0).map(e=>e.id),s=new Set;for(;o.length;){let e=o.shift();if(!s.has(e)){s.add(e);for(let t of i.get(e))a.set(t,Math.max(a.get(t),a.get(e)+1)),r.set(t,r.get(t)-1),r.get(t)===0&&o.push(t)}}return a}function C(e){let t=[];for(let n=1;n<e.length;n+=1){let[r,i]=[e[n-1],e[n]];(r.x!==i.x||r.y!==i.y)&&t.push({x:Math.min(r.x,i.x),y:Math.min(r.y,i.y),w:Math.abs(i.x-r.x),h:Math.abs(i.y-r.y)})}return t}function ae(e){let t=[];for(let n of e)if(!(t.length&&t[t.length-1].x===n.x&&t[t.length-1].y===n.y)){for(;t.length>1&&(t[t.length-2].x===t[t.length-1].x&&t[t.length-1].x===n.x||t[t.length-2].y===t[t.length-1].y&&t[t.length-1].y===n.y);)t.pop();t.push(n)}return t}function oe(e){let t=[];for(let n of e)for(let e of C(n.points))e.w===0&&t.push({edge:n,x:e.x,lo:e.y,hi:e.y+e.h});let n=new Map(e.map(e=>[e,[]]));for(let r of e)for(let e of C(r.points))if(e.h===0)for(let i of t)i.edge!==r&&e.x+g<i.x&&i.x<e.x+e.w-g&&i.lo+g<e.y&&e.y<i.hi-g&&n.get(r).push({x:i.x,y:e.y});return n}function se(e,t){let n=[`M${e[0].x} ${e[0].y}`];for(let r=1;r<e.length;r+=1){let[i,a]=[e[r-1],e[r]];if(i.y===a.y){let e=a.x>i.x?1:-1,r=t.filter(t=>t.y===i.y&&(t.x-i.x)*e>0&&(a.x-t.x)*e>0).sort((t,n)=>(t.x-n.x)*e);for(let t of r)n.push(`L${t.x-e*g} ${t.y}`),n.push(`A${g} ${g} 0 0 ${+(e>0)} ${t.x+e*g} ${t.y}`)}n.push(`L${a.x} ${a.y}`)}return n.join(` `)}var ce=(e,t)=>Math.max(t,e?24+(e-1)*d:0);function le(e){let t=[];for(let n of[...e].sort((e,t)=>e.lo-t.lo||e.hi-t.hi||e.index-t.index)){let e=0;for(;(t[e]||[]).some(e=>e.lo<=n.hi&&n.lo<=e.hi);)e+=1;(t[e]||=[]).push(n),n.track=e}return t.length}function ue(e,t){let n=new Map;for(let e of t)n.has(e.from)||n.set(e.from,[]),n.get(e.from).push(e);let r=new Map,i=[],a=null,o=e=>{r.set(e,1);for(let t of n.get(e)||[]){if(r.get(t.to)===1){let e=i.findIndex(e=>e.from===t.to);a=[...i.slice(e<0?i.length:e),t];return}if(r.has(t.to)||(i.push(t),o(t.to),i.pop()),a)return}r.set(e,2)};for(let t of e)if(r.has(t)||o(t),a)break;return a}function w(e,{measure:n,width:g,lang:ne}){let S=e.direction===`LR`,w=e=>S?e.h:e.w,T=e=>S?e.w:e.h,E=(e,t)=>S?{x:t,y:e}:{x:e,y:t},D=(e,t,n,r,i)=>({width:g,height:0,errors:[x(ne,e,t,n,r,i)]}),de=re(e.nodes,e.edges);if(de.length>r.backEdges)return D(de[r.backEdges].line,`回边最多 ${r.backEdges} 条`,`At most ${r.backEdges} back edges`,`减少回环,或拆成两张图`,`Reduce loops or split into two diagrams`);let O=new Set(de),fe=ie(e.nodes,e.edges,O);if([...fe.values()].some(e=>!Number.isFinite(e)))return D(e.nodes[0]?.line||1,`步序无法确定`,`Node steps cannot be resolved`,`检查节点归属与连线`,`Check node ownership and edges`);let pe=new Map(e.edges.map(r=>{let i=e.mermaid&&r.icon;if(!r.label&&!i)return[r.id,null];let a=(0,t.wrapText)(r.label??``,120,t.FONT.label,n),o=(0,t.snap)((0,t.maxWidthOf)(a,t.FONT.label,n)+12+(i?18:0)),s=(0,t.snap)(a.length*16+8);return[r.id,{lines:a,w:o,h:s,cross:S?s:o,along:S?o:s}]})),k=new Map,me=(e,t,n,r)=>{let i=`${e}|${t}`;k.has(i)||k.set(i,[]),k.get(i).push({edge:n,end:r})};for(let t of e.edges){let e=O.has(t)?-1:1;me(t.from,e,t,`out`),me(t.to,-e,t,`in`)}let he=e=>{if(e.length<2)return p;let t=e.filter(e=>e.end===`out`&&pe.get(e.edge.id)).map(e=>pe.get(e.edge.id).cross);if(!t.length)return p;let n=Math.max(...t);return Math.max(p,t.length>1?n+v:n/2+v)},ge=e=>Math.max(32,...[-1,1].map(t=>{let n=k.get(`${e}|${t}`)||[];return n.length<2?0:20+(n.length-1)*he(n)})),A=[];for(let i of e.nodes){let a=e.mermaid&&i.shape===`diamond`,c=a?88:r.labelWidth,l=(0,t.wrapText)(i.label,c,t.FONT.body,n),u=(a&&l.length>r.lines?(0,t.wrapText)(i.label,r.labelWidth,t.FONT.body,n):l).slice(0,r.lines+1);if(u.length>r.lines)return D(i.line,`节点「${i.label}」超过 ${r.lines} 行`,`Node label exceeds ${r.lines} lines: ${i.label}`,`缩短标签或把说明移到图外`,`Shorten the label or move the description outside`);let d=(0,t.maxWidthOf)(u,t.FONT.body,n)+(e.mermaid&&i.icon?22:0),f=u.length*20,p=i.shape===`diamond`,m=ge(i.id);if(a||e.mermaid&&i.shape===`circle`){let e=(0,t.snap)(Math.max(m,a?d+f+16:Math.hypot(d+16,f+12)));A.push({...i,lines:u,diamond:p,step:fe.get(i.id),w:e,h:e});continue}let h=(p?d*1.7:d)+o,g=(p?f*1.7:f)+s;A.push({id:i.id,label:i.label,shape:i.shape,class:i.class||null,lane:i.lane,line:i.line,lines:u,diamond:p,step:fe.get(i.id),w:(0,t.snap)(S?h:Math.max(h,m)),h:(0,t.snap)(S?Math.max(g,m):g)})}if(!A.length)return D(e.nodes[0]?.line||1,`图中没有节点`,`Swimlane diagram has no nodes`,`在泳道下缩进写节点`,`Indent nodes under a lane`);let j=Math.max(...A.map(e=>e.step)),_e=e.lanes.length,M=new Map(A.map(e=>[e.id,e])),N=new Map(e.lanes.map((e,t)=>[e.id,t])),P=e.lanes.map(e=>({lane:e,columns:Array.from({length:j+1},()=>[])}));for(let e of A)P[N.get(e.lane)]?.columns[e.step].push(e);for(let r of P){r.rooms=r.columns.map(e=>e.reduce((e,t)=>e+w(t),0)+a*Math.max(0,e.length-1));let i=S?0:n(r.lane.name,t.FONT.title)+12,o=S?24*(e.nested?.filter(e=>e.lane===r.lane.id).length||0):0;r.size=(0,t.snap)(Math.max(0,...r.rooms,i,S?ee:b)+12+o*2)}let ve=0,ye=P.map((e,t)=>{t&&(ve+=c);let n=ve;return ve+=e.size,n}),be=e=>ye[N.get(e.lane)]+e.outset+w(e)/2,xe=new Map(A.map(e=>[e.id,[]]));for(let t of e.edges)O.has(t)||xe.get(t.to).push(M.get(t.from));let Se=(e,t,n)=>{let r=Math.round((e.size-e.rooms[n])/2);for(let e of t)e.outset=r,r+=w(e)+a};for(let e=0;e<=j;e+=1)for(let t of P){let n=t.columns[e];if(Se(t,n,e),n.length<2)continue;let r=new Map(n.map(e=>{let t=xe.get(e.id);return[e,t.length?t.reduce((e,t)=>e+be(t),0)/t.length:be(e)]}));n.sort((e,t)=>r.get(e)-r.get(t)||A.indexOf(e)-A.indexOf(t)),Se(t,n,e)}let F=Array.from({length:j+1},(e,n)=>(0,t.snap)(Math.max(te,...A.filter(e=>e.step===n).map(T))+12)),I=e.edges.map((e,t)=>{let n=M.get(e.from),r=M.get(e.to),i=O.has(e);return{edge:e,index:t,from:n,to:r,isBack:i,label:pe.get(e.id),laneFrom:N.get(n.lane),laneTo:N.get(r.lane),outBand:i?n.step-1:n.step,inBand:i?r.step:r.step-1,outSide:i?-1:1,inSide:i?1:-1,port:{out:0,in:0}}}),L=I.find(e=>e.outBand<0||e.inBand<0);if(L)return D(L.edge.line,`连线 ${L.edge.from} → ${L.edge.to} 无法在泳道网格内走线`,`Edge ${L.edge.from} → ${L.edge.to} cannot be routed on the lane grid`,`把首行的自环拆成两个节点,或让回边指向更晚的步骤`,`Split the self loop on the first row into two nodes, or point the back edge at a later step`);let Ce=new Map(I.map(e=>[e.edge,e])),R=e=>e.outset+w(e)/2,we=(e,t)=>A.some(n=>n.lane===e.from.lane&&n!==e.from&&n!==e.to&&n.step>Math.min(e.from.step,e.to.step)&&n.step<Math.max(e.from.step,e.to.step)&&t>n.outset-p&&t<n.outset+w(n)+p),Te=e=>e.laneFrom===e.laneTo&&R(e.from)===R(e.to)&&!we(e,R(e.from)),Ee=new Map;for(let[t,n]of k){let r=M.get(t.slice(0,t.lastIndexOf(`|`))),i=n.map(({edge:e,end:t})=>({plan:Ce.get(e),end:t})),a=e=>be(e.end===`out`?e.plan.to:e.plan.from);i.sort((e,t)=>a(e)-a(t)||e.plan.index-t.plan.index||(e.end===`out`?-1:1));let o=i.findIndex(e=>Te(e.plan)&&!e.plan.isBack)>=0?i.findIndex(e=>Te(e.plan)&&!e.plan.isBack):i.findIndex(e=>Te(e.plan));e.mermaid&&o<0&&i.length>1&&i.every(({plan:e,end:t})=>t===`out`&&!e.label&&e.laneFrom!==e.laneTo)&&new Set(i.map(({plan:e})=>e.laneTo)).size===i.length&&(o=i.findIndex(({plan:e})=>Math.abs(e.laneTo-e.laneFrom)===1));let s=w(r)/2-h,c=o>=0?Math.max(o,i.length-1-o):(i.length-1)/2,l=i.length<2?0:Math.round(Math.max(he(n),Math.min(m,s/c))),u=o>=0?o:(i.length-1)/2,d=r.outset+h/2,f=r.outset+w(r)-h/2,p=Math.round(R(r)-u*l);if(e.mermaid&&o>=0&&(p<d||p+(i.length-1)*l>f)){let e=Math.min(o?(R(r)-d)/o:1/0,o<i.length-1?(f-R(r))/(i.length-1-o):1/0);i.forEach((t,n)=>{t.plan.port[t.end]=Math.round(R(r)+(n-o)*Math.min(l,e))});let t={items:i,lo:d,hi:f};for(let e of i)Ee.set(`${e.plan.index}|${e.end}`,t);continue}p=Math.min(Math.max(p,Math.ceil(d)),Math.floor(f-(i.length-1)*l)),i.forEach((e,t)=>{e.plan.port[e.end]=p+t*l});let g={items:i,lo:d,hi:f};for(let e of i)Ee.set(`${e.plan.index}|${e.end}`,g)}let De=(e,t)=>Ee.get(`${e.index}|${t}`),Oe=()=>!1,ke=(e,t)=>{if(!t||e.items.some(({plan:e})=>e.kind===`straight`))return!1;let n=e.items.map(({plan:e,end:n})=>e.port[n]+t);return n.some(t=>t<e.lo||t>e.hi)||e.items.some(({plan:e,end:t},r)=>Oe(e,t,n[r]))?!1:(e.items.forEach(({plan:e,end:t},r)=>{e.port[t]=n[r]}),!0)},Ae=e=>e.laneFrom===e.laneTo&&e.port.out===e.port.in&&!we(e,e.port.out);for(let e of I)Ae(e)&&(e.kind=`straight`);for(let e of I){if(e.kind||e.laneFrom!==e.laneTo)continue;let t=e.port.in-e.port.out;Math.abs(t)>=p||we(e,e.port.out)||(ke(De(e,`in`),-t)||ke(De(e,`out`),t))&&(e.kind=`straight`)}for(let e of I)e.kind||(e.kind=e.outBand===e.inBand?`jump`:`bend`,e.kind===`bend`&&(e.corridor=e.laneFrom===e.laneTo?(e.port.out+e.port.in)/2<P[e.laneFrom].size/2?e.laneFrom:e.laneFrom+1:Math.max(e.laneFrom,e.laneTo)));let z=new Map;for(let e of I)e.kind===`bend`&&(e.rail={index:e.index,lo:Math.min(e.outBand,e.inBand),hi:Math.max(e.outBand,e.inBand)},z.has(e.corridor)||z.set(e.corridor,[]),z.get(e.corridor).push(e.rail));let B=Array.from({length:_e+1},(e,t)=>ce(le(z.get(t)||[]),t===0||t===_e?u:c)),V=B[0],H=P.map((e,t)=>{t&&(V+=B[t]);let n=V;return V+=e.size,n}),je=V+B[_e],Me=e=>e<=0?0:H[e-1]+P[e-1].size,U=e=>Me(e.corridor)+f+e.rail.track*d,W=(e,t)=>H[t===`out`?e.laneFrom:e.laneTo]+e.port[t],G=new Map,Ne=(e,t)=>{G.has(e)||G.set(e,[]),G.get(e).push(t)};for(let e of I)if(e.kind===`jump`){let t={plan:e,index:e.index,ends:[`out`,`in`]};e.runs={out:t,in:t},Ne(e.outBand,t)}else e.kind===`bend`&&(e.runs={out:{plan:e,index:e.index,ends:[`out`],rail:!0},in:{plan:e,index:e.index,ends:[`in`],rail:!0}},Ne(e.outBand,e.runs.out),Ne(e.inBand,e.runs.in));let K=(e,t)=>(t===`out`?e.outSide:e.inSide)>0?`upper`:`lower`,Pe=e=>I.filter(t=>t.kind===`straight`&&e>=Math.min(t.outBand,t.inBand)&&e<=Math.max(t.outBand,t.inBand)),Fe=e=>e.flatMap(e=>e.ends.map(t=>({run:e,plan:e.plan,end:t,at:W(e.plan,t),cls:K(e.plan,t)}))),Ie=e=>(G.get(e)||[]).filter(e=>e.after).map(e=>e.jog),Le=e=>I.filter(t=>t.kind===`bend`&&e>=t.rail.lo&&e<=t.rail.hi).map(U);Oe=(e,t,n)=>Ie(t===`out`?e.outBand:e.inBand).some(r=>Math.abs(r-(H[t===`out`?e.laneFrom:e.laneTo]+n))<p);let Re=e=>{let t=G.get(e)||[],n=Fe(t),r=[];for(let e=0;e<n.length;e+=1)for(let t=e+1;t<n.length;t+=1){let[i,a]=[n[e],n[t]];i.run===a.run||Math.abs(i.at-a.at)>=p||(i.cls===a.cls?r.push({kind:`apart`,a:i,b:a}):r.push({kind:`order`,upper:i.cls===`upper`?i:a,lower:i.cls===`upper`?a:i}))}for(let t of Pe(e))for(let e of n)e.plan!==t&&Math.abs(e.at-W(t,`out`))<p&&r.push({kind:`apart`,a:{at:W(t,`out`)},b:e});return r},q=e=>e.kind===`order`?`o|${e.upper.plan.index}|${e.upper.end}|${e.lower.plan.index}|${e.lower.end}`:`a|${e.a.plan?.index??`s`}|${e.a.end??``}|${e.b.plan.index}|${e.b.end}`,J=(e,t)=>{let n=t+p-e.at,r=t-p-e.at;return(Math.abs(n)<=Math.abs(r)?[n,r]:[r,n]).some(t=>ke(De(e.plan,e.end),t))},ze=new Set,Y=new Set,Be=e=>{let t=Re(e).filter(e=>e.kind===`order`&&!ze.has(q(e))).map(e=>({from:e.upper.run,to:e.lower.run,item:e}));for(let n of G.get(e)||[])n.after&&t.push({from:n,to:n.after,item:null});return t},Ve=(e,t)=>{let{plan:n}=e,r=e.ends.find(e=>K(n,e)===`upper`),i=e.ends.find(e=>K(n,e)===`lower`);if(!r||!i)return!1;let[a,o]=[Math.min(W(n,r),W(n,i)),Math.max(W(n,r),W(n,i))],s=[a,o,...Fe(G.get(t)).map(e=>e.at),...Pe(t).map(e=>W(e,`out`)),...Ie(t),...Le(t)].filter(e=>e>=a&&e<=o).sort((e,t)=>e-t),c=null;for(let e=1;e<s.length;e+=1){let t=s[e]-s[e-1];t>=24&&(!c||t>c.gap)&&(c={gap:t,x:Math.round((s[e]+s[e-1])/2)})}if(!c)return!1;let l={plan:n,index:n.index,ends:[i],jog:c.x},u={plan:n,index:n.index,ends:[r],jog:c.x,after:l},d=G.get(t);return d.splice(d.indexOf(e),1,u,l),n.runs={[r]:u,[i]:l},!0},He=e=>Math.abs(W(e.plan,`out`)-W(e.plan,`in`)),Ue=[...G.keys()].sort((e,t)=>e-t);for(let e=0;e<96;e+=1){let e=null,t=null,n=null;for(let r of Ue){if(e=Re(r).find(e=>e.kind===`apart`&&!Y.has(q(e))),e)break;if(t=ue(G.get(r),Be(r)),t){n=r;break}}if(e){Y.add(q(e)),!J(e.b,e.a.at)&&e.a.plan&&J(e.a,e.b.at);continue}if(!t)break;let r=t.filter(e=>e.item).map(e=>e.item),i=r.find(e=>!Y.has(q(e)));i?(Y.add(q(i)),J(i.lower,i.upper.at)||J(i.upper,i.lower.at)):[...new Set(t.flatMap(e=>[e.from,e.to]))].filter(e=>e.ends.length===2).sort((e,t)=>He(t)-He(e)||e.index-t.index).some(e=>Ve(e,n))||ze.add(q(r[0]))}let X=[];for(let t of I){if(!t.label)continue;let n=t.outBand,r=!t.isBack,i=W(t,`out`),a=t.label.cross,o=Math.max(1,Math.ceil((8+t.label.along-f)/d)),s=[...Fe(G.get(n)||[]).filter(e=>e.plan!==t&&e.cls===(r?`upper`:`lower`)).map(e=>e.at),...Pe(n).filter(e=>e!==t).map(e=>W(e,`out`)),...I.filter(e=>e.kind===`bend`&&e!==t&&n>=e.rail.lo&&n<=e.rail.hi).map(U)],c=X.filter(e=>e.band===n&&e.top===r),l=e=>e>=0&&e+a<=je&&s.every(t=>t<e-2||t>e+a+2)&&c.every(t=>t.hi+4<=e||e+a+4<=t.lo),u=Math.round(i-a/2),p=Math.max(0,Math.floor(a/2-y)),m=u;for(let e=0;e<=p;e+=2){if(l(u-e)){m=u-e;break}if(l(u+e)){m=u+e;break}}if(e.mermaid){let e=[i+v,i-a-v].find(l);e!=null&&(m=e)}X.push({plan:t,band:n,top:r,m:o,lo:m,hi:m+a})}let We=new Map;for(let e=0;e<=j;e+=1){let t=G.get(e)||[],n=X.filter(t=>t.band===e&&t.top),r=X.filter(t=>t.band===e&&!t.top);if(!t.length&&!X.some(t=>t.band===e))continue;let i=new Map(t.map(e=>[e,new Set]));for(let t of Be(e))i.get(t.to).add(t.from);for(let e of t){let t=e.ends.map(t=>W(e.plan,t));e.rail&&t.push(U(e.plan)),e.jog!=null&&t.push(e.jog),e.lo=Math.min(...t),e.hi=Math.max(...t)}let a=[],o=new Set(t),s=(e,t)=>e.lo-t.lo||e.hi-t.hi||e.index-t.index;for(;o.size;){let e=[...o].filter(e=>[...i.get(e)].every(e=>!o.has(e))),t=(e.length?e:[...o]).sort(s)[0];a.push(t),o.delete(t)}let c=[],l=(e,t,n,r)=>(c[e]||=[]).push({lo:t,hi:n,owner:r});for(let e of n)for(let t=0;t<e.m;t+=1)l(t,e.lo,e.hi,e.plan);for(let e of a){let t=0;for(let n of i.get(e))n.track!=null&&(t=Math.max(t,n.track+1));for(let r of n){let n=e.ends.some(t=>K(e.plan,t)===`lower`&&W(e.plan,t)>=r.lo-2&&W(e.plan,t)<=r.hi+2);(r.plan===e.plan||n)&&(t=Math.max(t,r.m))}let r=t;for(;(c[r]||[]).some(t=>t.owner!==e.plan&&t.lo<=e.hi&&e.lo<=t.hi);)r+=1;l(r,e.lo,e.hi,e.plan),e.track=r}let u=c.length,d=Math.max(0,...r.map(e=>e.m));We.set(e,u+d)}let Ge=Array.from({length:j+1},(e,t)=>ce(We.get(t)||0,l)),Ke=S?(0,t.snap)(Math.max(i,...e.lanes.map(e=>n(e.name,t.FONT.title)+24))):i+24*(e.nested?.length||0),qe=Array.from({length:j+1},(e,t)=>(t&&(Ke+=Ge[t-1]+F[t-1]),Ke)),Je=qe[j]+F[j]+(We.has(j)?Ge[j]:0),Ye=S?Math.max((0,t.snap)(g),Je):je,Xe=S?je:Je,Z=e=>qe[e]+F[e],Q=(e,t)=>Z(e)+f+t*d;for(let e of A){e.cross=H[N.get(e.lane)]+e.outset,e.along=qe[e.step]+Math.round((F[e.step]-T(e))/2);let t=E(e.cross,e.along);e.x=t.x,e.y=t.y}let Ze=(t,n,r)=>{let i=Math.abs(n-(t.cross+w(t)/2)),a=w(t)/2,o=e.mermaid&&t.shape===`circle`?a:0,s=t.diamond?Math.min(T(t)/2,i*T(t)/w(t)):o?a-Math.sqrt(Math.max(0,a*a-i*i)):0;return E(n,Math.round(r>0?t.along+T(t)-s:t.along+s))},$=I.map(e=>{let t=W(e,`out`),n=W(e,`in`),r=[];if(e.kind===`jump`&&e.runs.out===e.runs.in){let i=Q(e.outBand,e.runs.out.track);r.push(E(t,i),E(n,i))}else if(e.kind===`jump`){let i=Q(e.outBand,e.runs.out.track),a=Q(e.outBand,e.runs.in.track);r.push(E(t,i),E(e.runs.out.jog,i),E(e.runs.out.jog,a),E(n,a))}else if(e.kind===`bend`){let i=U(e),a=Q(e.outBand,e.runs.out.track),o=Q(e.inBand,e.runs.in.track);r.push(E(t,a),E(i,a),E(i,o),E(n,o))}return{id:e.edge.id,from:e.edge.from,to:e.edge.to,style:e.edge.style,line:e.edge.line,back:e.isBack,points:ae([Ze(e.from,t,e.outSide),...r,Ze(e.to,n,e.inSide)]),label:null}});if(e.mermaid)for(let e of I){if(!e.from.diamond||e.to.shape!==`rect`||e.isBack||e.laneFrom===e.laneTo||e.kind!==`jump`)continue;let t=Math.sign(e.laneTo-e.laneFrom),n=e.from.along+T(e.from)/2,r=e.to.along,i=e.from.cross+(t>0?w(e.from):0),a=e.to.cross+w(e.to)/2,o=Math.max(e.laneFrom,e.laneTo),s=H[o]-B[o]/2;if(r-n<=8||(s-i)*t<4||(a-s)*t<4||!A.every(t=>t===e.from||t===e.to||t.along+T(t)<n-4||t.along>r+4||t.cross+w(t)<Math.min(i,a)-4||t.cross>Math.max(i,a)+4))continue;let c=[E(i,n),E(s,n),E(s,r-8),E(a,r-8),E(a,r)],l=(e,t)=>e.w===0&&t.w===0&&e.x===t.x&&Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)>4||e.h===0&&t.h===0&&e.y===t.y&&Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x)>4;$.some((t,n)=>n!==e.index&&C(t.points).some(e=>C(c).some(t=>l(t,e))))||($[e.index].points=c,e.sideBranch={sourceAlong:n,rail:s})}let Qe=oe($);for(let e of $)e.hops=Qe.get(e)||[],e.d=se(e.points,e.hops);for(let e of X){let{label:t}=e.plan,n=e.top?Z(e.band)+_:Z(e.band)+Ge[e.band]-_-t.along,r=e.plan.sideBranch?E(e.plan.sideBranch.rail-t.cross/2,e.plan.sideBranch.sourceAlong+v):E(e.lo,n);$[e.plan.index].label={x:r.x,y:r.y,w:t.w,h:t.h,lines:t.lines}}let $e=e.lanes.map((e,t)=>S?{id:e.id,name:e.name,line:e.line,nodes:e.nodes,x:0,y:H[t],w:Ye,h:P[t].size}:{id:e.id,name:e.name,line:e.line,nodes:e.nodes,x:H[t],y:0,w:P[t].size,h:Xe});if(e.reverse){let e=S?`x`:`y`,t=S?`w`:`h`,n=S?Ye:Xe;for(let r of[...A,...$.map(e=>e.label).filter(Boolean)])r[e]=n-r[e]-r[t];for(let t of $){for(let r of[...t.points,...t.hops])r[e]=n-r[e];t.d=se(t.points,t.hops)}}return{type:`swimlane`,direction:e.direction,width:Ye,height:Xe,lanes:$e,nodes:A,edges:$,errors:[],model:e}}function T(e,t,n,r,i){let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=14/Math.max(s,c);return e.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`},t.elements.map(({tag:n,attrs:r})=>e.shape(n,{...r,...t.set===`simple`?{fill:i}:{fill:`none`,stroke:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))}var E=(e,t,n)=>t?.link?e.link(t.link.href,[n],t.link):n;function D(e,n){let r=e.model,i=r?.mermaid,a=new Map(r?.edges.map(e=>[e.id,e])),o=new Map(i?r.nodes.map(e=>[e.id,e]):[]),s=(0,t.appearance)(n),c=Array.from({length:6},(e,t)=>n.frameTone(n.color(`tone${t+1}`))),l=`swimlane-arrow`,u=[n.el(`defs`,{},[n.el(`marker`,{id:l,viewBox:`0 0 8 8`,refX:7,refY:4,markerWidth:8,markerHeight:8,markerUnits:`userSpaceOnUse`,orient:i?`auto-start-reverse`:`auto`},[n.path(`M0 0 L8 4 L0 8 Z`,{fill:s.fg4})])])];for(let[a,o]of e.lanes.entries()){let l=i&&r.lanes[a],d=s[l?.class]||c[a%c.length],f=n.el(`g`,{},[n.rect(o.x,o.y,o.w,o.h,{fill:n.tint(s.bg,d,.07),stroke:n.tint(s.bg,d,.45),"stroke-width":1,rx:s.radius}),n.text(e.direction===`LR`?r?.reverse?o.w-12:12:o.x+o.w/2,e.direction===`LR`?o.y+o.h/2:r?.reverse?o.h-18:18,o.name,{size:t.FONT.title.size,weight:t.FONT.title.weight,fill:s.fg1,anchor:e.direction===`LR`?r?.reverse?`end`:`start`:`middle`,"dominant-baseline":`central`})]);f.meta={lane:o.id,...i?{kind:`frame`,id:o.id}:{}},u.push(E(n,l,f))}if(i){let i=new Map(e.nodes.map(e=>[e.id,e])),a=r.nested.filter(e=>e.nodes.length);for(let[r,o]of a.entries()){let c=o.nodes.map(e=>i.get(e)),l=e.lanes.find(e=>e.id===o.lane),d=Math.min(...c.map(e=>e.x))-4,f=Math.min(...c.map(e=>e.y))-14-a.slice(r+1).filter(e=>e.lane===o.lane).length*20,p=Math.max(l.y+2,f-8),m=n.measure(o.title,t.FONT.label.size,600)+12,h=Math.min(l.x+l.w-d-2,Math.max(m,...c.map(e=>e.x+e.w+4-d))),g=Math.max(...c.map(e=>e.y+e.h+4-p));u.push(n.rect(d,p,h,g,{fill:s.surface2,stroke:s.line2,rx:s.smallRadius,meta:{kind:`frame`,id:o.id}})),u.push(n.text(d+6,p+9,o.title,{size:t.FONT.label.size,weight:600,anchor:`start`,"dominant-baseline":`central`,fill:s.fg2}))}}for(let t of e.edges){let e=a.get(t.id);i&&t.style===`invisible`||u.push(E(n,e,n.path(t.d,{fill:`none`,stroke:i&&s[e.status]||s.fg4,"stroke-width":i&&t.style===`bold`?2.5:1.25,"stroke-linejoin":`round`,...t.style===`dashed`?{"stroke-dasharray":`5 4`}:{},...!i||e.endArrow?{"marker-end":`url(#${l})`}:{},...i&&e.startArrow?{"marker-start":`url(#${l})`}:{},meta:{edge:t.id,back:t.back,...i?{kind:`edge`,from:t.from,to:t.to,...e.status?{status:e.status}:{}}:{}}})))}for(let r of e.nodes){let a=c[Math.max(0,e.lanes.findIndex(e=>e.id===r.lane))%c.length],l=r.class&&s[r.class]?s[r.class]:n.tint(s.bg,a,.4),d=i&&r.shape===`circle`?n.shape(`circle`,{cx:r.x+r.w/2,cy:r.y+r.h/2,r:r.w/2,fill:s.node,stroke:l,"stroke-width":1}):r.shape===`diamond`?n.shape(`polygon`,{points:`${r.x+r.w/2},${r.y} ${r.x+r.w},${r.y+r.h/2} ${r.x+r.w/2},${r.y+r.h} ${r.x},${r.y+r.h/2}`,fill:s.node,stroke:l,"stroke-width":1},{node:r.id,shape:r.shape,...r.class?{status:r.class}:{}}):n.rect(r.x,r.y,r.w,r.h,{fill:s.node,stroke:l,"stroke-width":1,rx:i&&r.shape===`stadium`?r.h/2:i&&r.shape===`rect`?0:s.smallRadius,meta:{node:r.id,shape:r.shape,...r.class?{status:r.class}:{}}});i&&(d.meta={...d.meta,kind:`node`,id:r.id});let f=t.statusMarks[r.class],p=o.get(r.id),m=p?.icon,h=[];if(m){let e=Math.max(0,...r.lines.map(e=>n.measure(e,t.FONT.body.size,t.FONT.body.weight))),i=r.x+r.w/2-(e/2+2),a=r.y+r.h/2;h.push(T(n,m,i,a,l))}u.push(E(n,p,n.el(`g`,{},[d,...h,...r.lines.map((e,i)=>n.text(r.x+r.w/2+(m?11:0),r.y+r.h/2+(i-(r.lines.length-1)/2)*20,e,{size:t.FONT.body.size,fill:s.fg1,anchor:`middle`,"dominant-baseline":`central`,meta:{node:r.id}})),...f?[n.text(r.x+8,r.y+9,f,{size:12,weight:600,fill:l,anchor:`middle`,"dominant-baseline":`central`,meta:{node:r.id,status:r.class}})]:[]])))}for(let r of e.edges.filter(e=>e.label)){let e=i&&a.get(r.id),o=e?.icon,c=n.el(`g`,{},[n.rect(r.label.x,r.label.y,r.label.w,r.label.h,{fill:s.surface}),...o?[T(n,o,r.label.x+12,r.label.y+r.label.h/2,s.fg2)]:[],...r.label.lines.map((e,i)=>n.text(r.label.x+r.label.w/2+(o?9:0),r.label.y+r.label.h/2+(i-(r.label.lines.length-1)/2)*16,e,{size:t.FONT.label.size,fill:s.fg2,anchor:`middle`,"dominant-baseline":`central`}))]);c.meta={label:r.id,...i?{kind:`edge-label-group`,from:r.from,to:r.to}:{}},u.push(E(n,e,c))}return{width:e.width,height:e.height,children:u}}return e.implementations={swimlane:{parse:S,layout:w,scene:D}},e.layout=w,e.scene=D,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/graph-parse`]);
1
+ KChartUnits["diagram/swimlane"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r={lanes:6,nodes:30,edges:50,backEdges:3,lines:3,labelWidth:208},i=36,a=10,o=28,s=16,c=12,l=24,u=4,d=12,f=12,p=12,m=24,h=10,g=5,_=4,v=8,y=8,b=44,ee=40,te=40,x=(e,n,r,i,a,o)=>(0,t.error)(e,n,r,i,a,o);function ne(e,t,n){let r=e.LR===!0?`LR`:e.TB===!0?`TB`:null,i=t.find(e=>/^direction\s+/i.test(e.text)),a=i?i.text.replace(/^direction\s+/i,``).trim().toUpperCase():null,o=a===`TD`?`TB`:a;if(r&&o&&r!==o)return{error:x(n.lang,i.line,`泳道方向声明冲突`,`Conflicting swimlane directions`,`只保留 swimlane LR/TB 或正文 direction 其中一种`,`Keep either swimlane LR/TB or one direction statement`)};let s=r||o||`TB`;return[`TB`,`LR`].includes(s)?{direction:s,line:i}:{error:x(n.lang,i?.line||n.firstLine-1,`泳道只支持 TB 或 LR`,`Swimlanes only support TB or LR`,`改成 swimlane、swimlane LR 或 direction TB/LR`,`Use swimlane, swimlane LR, or direction TB/LR`)}}function re(e,i={}){let a={...i,lang:i.lang||`zh`,firstLine:i.firstLine||1,options:i.options||{}},o=[],{lang:s}=a;for(let e of Object.keys(a.options))[`LR`,`TB`].includes(e)||o.push(x(s,a.firstLine-1,`swimlane 不支持选项「${e}」`,`Unsupported swimlane option: ${e}`,`只使用 swimlane、swimlane LR 或 swimlane TB`,`Use only swimlane, swimlane LR, or swimlane TB`));let c=String(e).split(`
2
+ `).map((e,t)=>({raw:e,line:a.firstLine+t})).filter(e=>e.raw.trim()&&!e.raw.trimStart().startsWith(`%%`));c.some(e=>/^\s*\t/.test(e.raw))&&o.push(x(s,c.find(e=>/^\s*\t/.test(e.raw)).line,`缩进不能使用 Tab`,`Tabs are not allowed in indentation`,`把 Tab 换成空格`,`Replace tabs with spaces`));let l=c.filter(e=>!/^\s*\t/.test(e.raw)).map(e=>({...e,indent:e.raw.match(/^ */)[0].length,text:e.raw.trim()})),u=ne(a.options,l,a);u.error&&o.push(u.error);let d=[],f=new Map,p=new Map,m=[],h=null,g=null;for(let e of l)if(!/^direction\b/i.test(e.text)){if(/^lane\s+/i.test(e.text)){e.indent!==0&&o.push(x(s,e.line,`lane 必须写在顶层`,`lane must be at the top level`,`去掉 lane 前面的缩进`,`Remove indentation before lane`));let t=e.text.replace(/^lane\s+/i,``).trim();(!t||f.has(t))&&o.push(x(s,e.line,`泳道名称无效或重复:${t||`(空)`}`,`Invalid or duplicate lane: ${t||`(empty)`}`,`给每条泳道一个不重复的名称`,`Give each lane a unique name`)),h={id:`lane-${d.length}`,name:t,line:e.line},d.push(h),f.set(t,h),g=null}else h&&e.indent>0?(g??=e.indent,e.indent!==g&&o.push(x(s,e.line,`同一泳道内的缩进不一致`,`Inconsistent indentation inside a lane`,`把这一行缩进改为 ${g} 个空格`,`Indent this line with ${g} spaces`)),m.push(e)):e.indent===0?(h=null,m.push(e)):o.push(x(s,e.line,`节点必须写在 lane 下面`,`A node must be indented under a lane`,`先声明 lane,再缩进写节点`,`Declare a lane, then indent its nodes`))}d.length||o.push(x(s,a.firstLine,`图中没有泳道`,`Swimlane diagram has no lanes`,`添加 lane 名称和缩进的节点`,`Add lane names and indented nodes`)),d.length>r.lanes&&o.push(x(s,d[r.lanes].line,`最多 ${r.lanes} 条泳道`,`At most ${r.lanes} lanes`,`把流程拆成两张泳道图`,`Split the flow into two swimlane diagrams`));let _=(0,n.parseFlow)(m.map(({text:e,line:t})=>({text:e,line:t})),{direction:u.direction||`TB`});o.push(..._.errors.filter(e=>!/超过上限/.test(e.message)));let v=_.model,y=new Map,b=null;for(let e of l)if(/^lane\s+/i.test(e.text)&&e.indent===0)b=d.find(t=>t.line===e.line);else if(!b||e.indent===0)b=null;else for(let t of e.text.matchAll(/(?:^|[\s&])([A-Za-z_][\w-]*)\s*[\[\(\{>]/g)){let n=t[1];y.has(n)&&y.get(n)!==b.id?o.push(x(s,e.line,`节点 ${n} 重复归属`,`Node ${n} belongs to more than one lane`,`只在一条泳道里定义这个节点`,`Define this node in only one lane`)):y.set(n,b.id)}let ee=new Set;l.forEach(e=>{e.indent>0&&ee.add(e.line)});for(let e of v.nodes)if(!ee.has(e.line))o.push(x(s,e.line,`节点 ${e.id} 没有泳道`,`Node ${e.id} has no lane`,`把节点定义缩进到对应 lane 下面`,`Indent the node definition under its lane`));else if(p.has(e.id))o.push(x(s,e.line,`节点 ${e.id} 重复归属`,`Node ${e.id} belongs to more than one lane`,`只在一条泳道里定义这个节点`,`Define this node in only one lane`));else{let t=[...d].reverse().find(t=>t.line<e.line);p.set(e.id,t?.id||null)}return v.nodes.length>r.nodes&&o.push(x(s,v.nodes[r.nodes].line,`最多 ${r.nodes} 个节点`,`At most ${r.nodes} nodes`,`拆成总图和局部图`,`Split into an overview and a detail diagram`)),v.edges.length>r.edges&&o.push(x(s,v.edges[r.edges].line,`最多 ${r.edges} 条连线`,`At most ${r.edges} edges`,`拆成总图和局部图`,`Split into an overview and a detail diagram`)),{model:{type:`swimlane`,direction:u.direction||`TB`,lanes:d.map(e=>({...e,nodes:v.nodes.filter(t=>p.get(t.id)===e.id).map(e=>e.id)})),nodes:v.nodes.map(e=>({id:e.id,label:(0,t.labelText)(e.label),shape:e.shape,class:e.class||null,lane:p.get(e.id)||null,line:e.line})),edges:v.edges.map(e=>({id:`e${e.seq}`,from:e.from,to:e.to,label:(0,t.labelText)(e.label),style:e.style,line:e.line}))},errors:o}}function ie(e,t){let n=new Map(e.map(e=>[e.id,[]]));t.forEach((e,t)=>n.get(e.from)?.push({edge:e,index:t}));for(let e of n.values())e.sort((e,t)=>e.index-t.index);let r=new Set,i=new Set,a=[],o=e=>{r.add(e),i.add(e);for(let t of n.get(e)||[])i.has(t.edge.to)?a.push(t.edge):r.has(t.edge.to)||o(t.edge.to);i.delete(e)};for(let t of e)r.has(t.id)||o(t.id);return a}function ae(e,t,n){let r=new Map(e.map(e=>[e.id,0])),i=new Map(e.map(e=>[e.id,[]]));for(let e of t)n.has(e)||(r.set(e.to,r.get(e.to)+1),i.get(e.from).push(e.to));let a=new Map(e.map(e=>[e.id,0])),o=e.filter(e=>r.get(e.id)===0).map(e=>e.id),s=new Set;for(;o.length;){let e=o.shift();if(!s.has(e)){s.add(e);for(let t of i.get(e))a.set(t,Math.max(a.get(t),a.get(e)+1)),r.set(t,r.get(t)-1),r.get(t)===0&&o.push(t)}}return a}function S(e){let t=[];for(let n=1;n<e.length;n+=1){let[r,i]=[e[n-1],e[n]];(r.x!==i.x||r.y!==i.y)&&t.push({x:Math.min(r.x,i.x),y:Math.min(r.y,i.y),w:Math.abs(i.x-r.x),h:Math.abs(i.y-r.y)})}return t}function oe(e){let t=[];for(let n of e)if(!(t.length&&t[t.length-1].x===n.x&&t[t.length-1].y===n.y)){for(;t.length>1&&(t[t.length-2].x===t[t.length-1].x&&t[t.length-1].x===n.x||t[t.length-2].y===t[t.length-1].y&&t[t.length-1].y===n.y);)t.pop();t.push(n)}return t}function se(e){let t=[];for(let n of e)for(let e of S(n.points))e.w===0&&t.push({edge:n,x:e.x,lo:e.y,hi:e.y+e.h});let n=new Map(e.map(e=>[e,[]]));for(let r of e)for(let e of S(r.points))if(e.h===0)for(let i of t)i.edge!==r&&e.x+g<i.x&&i.x<e.x+e.w-g&&i.lo+g<e.y&&e.y<i.hi-g&&n.get(r).push({x:i.x,y:e.y});return n}function ce(e,t){let n=[`M${e[0].x} ${e[0].y}`];for(let r=1;r<e.length;r+=1){let[i,a]=[e[r-1],e[r]];if(i.y===a.y){let e=a.x>i.x?1:-1,r=t.filter(t=>t.y===i.y&&(t.x-i.x)*e>0&&(a.x-t.x)*e>0).sort((t,n)=>(t.x-n.x)*e);for(let t of r)n.push(`L${t.x-e*g} ${t.y}`),n.push(`A${g} ${g} 0 0 ${+(e>0)} ${t.x+e*g} ${t.y}`)}n.push(`L${a.x} ${a.y}`)}return n.join(` `)}var le=(e,t)=>Math.max(t,e?24+(e-1)*d:0);function ue(e){let t=[];for(let n of[...e].sort((e,t)=>e.lo-t.lo||e.hi-t.hi||e.index-t.index)){let e=0;for(;(t[e]||[]).some(e=>e.lo<=n.hi&&n.lo<=e.hi);)e+=1;(t[e]||=[]).push(n),n.track=e}return t.length}function de(e,t){let n=new Map;for(let e of t)n.has(e.from)||n.set(e.from,[]),n.get(e.from).push(e);let r=new Map,i=[],a=null,o=e=>{r.set(e,1);for(let t of n.get(e)||[]){if(r.get(t.to)===1){let e=i.findIndex(e=>e.from===t.to);a=[...i.slice(e<0?i.length:e),t];return}if(r.has(t.to)||(i.push(t),o(t.to),i.pop()),a)return}r.set(e,2)};for(let t of e)if(r.has(t)||o(t),a)break;return a}function C(e,{measure:n,width:g,lang:ne,compact:re}){let C=e.direction===`LR`,w=e=>C?e.h:e.w,T=e=>C?e.w:e.h,E=(e,t)=>C?{x:t,y:e}:{x:e,y:t},D=(e,t,n,r,i)=>({width:g,height:0,errors:[x(ne,e,t,n,r,i)]}),fe=ie(e.nodes,e.edges);if(fe.length>r.backEdges)return D(fe[r.backEdges].line,`回边最多 ${r.backEdges} 条`,`At most ${r.backEdges} back edges`,`减少回环,或拆成两张图`,`Reduce loops or split into two diagrams`);let O=new Set(fe),pe=ae(e.nodes,e.edges,O);if([...pe.values()].some(e=>!Number.isFinite(e)))return D(e.nodes[0]?.line||1,`步序无法确定`,`Node steps cannot be resolved`,`检查节点归属与连线`,`Check node ownership and edges`);let me=new Map(e.edges.map(r=>{let i=e.mermaid&&r.icon;if(!r.label&&!i)return[r.id,null];let a=(0,t.wrapText)(r.label??``,120,t.FONT.label,n),o=(0,t.snap)((0,t.maxWidthOf)(a,t.FONT.label,n)+12+(i?18:0)),s=(0,t.snap)(a.length*16+8);return[r.id,{lines:a,w:o,h:s,cross:C?s:o,along:C?o:s}]})),k=new Map,he=(e,t,n,r)=>{let i=`${e}|${t}`;k.has(i)||k.set(i,[]),k.get(i).push({edge:n,end:r})};for(let t of e.edges){let e=O.has(t)?-1:1;he(t.from,e,t,`out`),he(t.to,-e,t,`in`)}let ge=e=>{if(e.length<2)return p;let t=e.filter(e=>e.end===`out`&&me.get(e.edge.id)).map(e=>me.get(e.edge.id).cross);if(!t.length)return p;let n=Math.max(...t);return Math.max(p,t.length>1?n+v:n/2+v)},_e=e=>Math.max(32,...[-1,1].map(t=>{let n=k.get(`${e}|${t}`)||[];return n.length<2?0:20+(n.length-1)*ge(n)})),A=[];for(let i of e.nodes){let a=e.mermaid&&i.shape===`diamond`,c=a?88:r.labelWidth,l=(0,t.wrapText)(i.label,c,t.FONT.body,n),u=(a&&l.length>r.lines?(0,t.wrapText)(i.label,r.labelWidth,t.FONT.body,n):l).slice(0,r.lines+1);if(u.length>r.lines)return D(i.line,`节点「${i.label}」超过 ${r.lines} 行`,`Node label exceeds ${r.lines} lines: ${i.label}`,`缩短标签或把说明移到图外`,`Shorten the label or move the description outside`);let d=(0,t.maxWidthOf)(u,t.FONT.body,n)+(e.mermaid&&i.icon?22:0),f=u.length*20,p=i.shape===`diamond`,m=_e(i.id);if(a||e.mermaid&&i.shape===`circle`){let e=(0,t.snap)(Math.max(m,a?d+f+16:Math.hypot(d+16,f+12)));A.push({...i,lines:u,diamond:p,step:pe.get(i.id),w:e,h:e});continue}let h=(p?d*1.7:d)+o,g=(p?f*1.7:f)+s;A.push({id:i.id,label:i.label,shape:i.shape,class:i.class||null,lane:i.lane,line:i.line,lines:u,diamond:p,step:pe.get(i.id),w:(0,t.snap)(C?h:Math.max(h,m)),h:(0,t.snap)(C?Math.max(g,m):g)})}if(!A.length)return D(e.nodes[0]?.line||1,`图中没有节点`,`Swimlane diagram has no nodes`,`在泳道下缩进写节点`,`Indent nodes under a lane`);let j=Math.max(...A.map(e=>e.step)),ve=e.lanes.length,M=new Map(A.map(e=>[e.id,e])),N=new Map(e.lanes.map((e,t)=>[e.id,t])),P=e.lanes.map(e=>({lane:e,columns:Array.from({length:j+1},()=>[])}));for(let e of A)P[N.get(e.lane)]?.columns[e.step].push(e);for(let r of P){r.rooms=r.columns.map(e=>e.reduce((e,t)=>e+w(t),0)+a*Math.max(0,e.length-1));let i=C?0:n(r.lane.name,t.FONT.title)+12,o=C?24*(e.nested?.filter(e=>e.lane===r.lane.id).length||0):0;r.size=(0,t.snap)(Math.max(0,...r.rooms,i,C?ee:b)+12+o*2)}let ye=0,be=P.map((e,t)=>{t&&(ye+=c);let n=ye;return ye+=e.size,n}),xe=e=>be[N.get(e.lane)]+e.outset+w(e)/2,Se=new Map(A.map(e=>[e.id,[]]));for(let t of e.edges)O.has(t)||Se.get(t.to).push(M.get(t.from));let Ce=(e,t,n)=>{let r=Math.round((e.size-e.rooms[n])/2);for(let e of t)e.outset=r,r+=w(e)+a};for(let e=0;e<=j;e+=1)for(let t of P){let n=t.columns[e];if(Ce(t,n,e),n.length<2)continue;let r=new Map(n.map(e=>{let t=Se.get(e.id);return[e,t.length?t.reduce((e,t)=>e+xe(t),0)/t.length:xe(e)]}));n.sort((e,t)=>r.get(e)-r.get(t)||A.indexOf(e)-A.indexOf(t)),Ce(t,n,e)}let F=Array.from({length:j+1},(e,n)=>(0,t.snap)(Math.max(te,...A.filter(e=>e.step===n).map(T))+12)),I=e.edges.map((e,t)=>{let n=M.get(e.from),r=M.get(e.to),i=O.has(e);return{edge:e,index:t,from:n,to:r,isBack:i,label:me.get(e.id),laneFrom:N.get(n.lane),laneTo:N.get(r.lane),outBand:i?n.step-1:n.step,inBand:i?r.step:r.step-1,outSide:i?-1:1,inSide:i?1:-1,port:{out:0,in:0}}}),L=I.find(e=>e.outBand<0||e.inBand<0);if(L)return D(L.edge.line,`连线 ${L.edge.from} → ${L.edge.to} 无法在泳道网格内走线`,`Edge ${L.edge.from} → ${L.edge.to} cannot be routed on the lane grid`,`把首行的自环拆成两个节点,或让回边指向更晚的步骤`,`Split the self loop on the first row into two nodes, or point the back edge at a later step`);let we=new Map(I.map(e=>[e.edge,e])),R=e=>e.outset+w(e)/2,Te=(e,t)=>A.some(n=>n.lane===e.from.lane&&n!==e.from&&n!==e.to&&n.step>Math.min(e.from.step,e.to.step)&&n.step<Math.max(e.from.step,e.to.step)&&t>n.outset-p&&t<n.outset+w(n)+p),Ee=e=>e.laneFrom===e.laneTo&&R(e.from)===R(e.to)&&!Te(e,R(e.from)),De=new Map;for(let[t,n]of k){let r=M.get(t.slice(0,t.lastIndexOf(`|`))),i=n.map(({edge:e,end:t})=>({plan:we.get(e),end:t})),a=e=>xe(e.end===`out`?e.plan.to:e.plan.from);i.sort((e,t)=>a(e)-a(t)||e.plan.index-t.plan.index||(e.end===`out`?-1:1));let o=i.findIndex(e=>Ee(e.plan)&&!e.plan.isBack)>=0?i.findIndex(e=>Ee(e.plan)&&!e.plan.isBack):i.findIndex(e=>Ee(e.plan));e.mermaid&&o<0&&i.length>1&&i.every(({plan:e,end:t})=>t===`out`&&!e.label&&e.laneFrom!==e.laneTo)&&new Set(i.map(({plan:e})=>e.laneTo)).size===i.length&&(o=i.findIndex(({plan:e})=>Math.abs(e.laneTo-e.laneFrom)===1));let s=w(r)/2-h,c=o>=0?Math.max(o,i.length-1-o):(i.length-1)/2,l=i.length<2?0:Math.round(Math.max(ge(n),Math.min(m,s/c))),u=o>=0?o:(i.length-1)/2,d=r.outset+h/2,f=r.outset+w(r)-h/2,p=Math.round(R(r)-u*l);if(e.mermaid&&o>=0&&(p<d||p+(i.length-1)*l>f)){let e=Math.min(o?(R(r)-d)/o:1/0,o<i.length-1?(f-R(r))/(i.length-1-o):1/0);i.forEach((t,n)=>{t.plan.port[t.end]=Math.round(R(r)+(n-o)*Math.min(l,e))});let t={items:i,lo:d,hi:f};for(let e of i)De.set(`${e.plan.index}|${e.end}`,t);continue}p=Math.min(Math.max(p,Math.ceil(d)),Math.floor(f-(i.length-1)*l)),i.forEach((e,t)=>{e.plan.port[e.end]=p+t*l});let g={items:i,lo:d,hi:f};for(let e of i)De.set(`${e.plan.index}|${e.end}`,g)}let Oe=(e,t)=>De.get(`${e.index}|${t}`),ke=()=>!1,Ae=(e,t)=>{if(!t||e.items.some(({plan:e})=>e.kind===`straight`))return!1;let n=e.items.map(({plan:e,end:n})=>e.port[n]+t);return n.some(t=>t<e.lo||t>e.hi)||e.items.some(({plan:e,end:t},r)=>ke(e,t,n[r]))?!1:(e.items.forEach(({plan:e,end:t},r)=>{e.port[t]=n[r]}),!0)},je=e=>e.laneFrom===e.laneTo&&e.port.out===e.port.in&&!Te(e,e.port.out);for(let e of I)je(e)&&(e.kind=`straight`);for(let e of I){if(e.kind||e.laneFrom!==e.laneTo)continue;let t=e.port.in-e.port.out;Math.abs(t)>=p||Te(e,e.port.out)||(Ae(Oe(e,`in`),-t)||Ae(Oe(e,`out`),t))&&(e.kind=`straight`)}for(let e of I)e.kind||(e.kind=e.outBand===e.inBand?`jump`:`bend`,e.kind===`bend`&&(e.corridor=e.laneFrom===e.laneTo?(e.port.out+e.port.in)/2<P[e.laneFrom].size/2?e.laneFrom:e.laneFrom+1:Math.max(e.laneFrom,e.laneTo)));let z=new Map;for(let e of I)e.kind===`bend`&&(e.rail={index:e.index,lo:Math.min(e.outBand,e.inBand),hi:Math.max(e.outBand,e.inBand)},z.has(e.corridor)||z.set(e.corridor,[]),z.get(e.corridor).push(e.rail));let B=Array.from({length:ve+1},(e,t)=>le(ue(z.get(t)||[]),t===0||t===ve?u:c)),V=B[0],H=P.map((e,t)=>{t&&(V+=B[t]);let n=V;return V+=e.size,n}),Me=V+B[ve],Ne=e=>e<=0?0:H[e-1]+P[e-1].size,U=e=>Ne(e.corridor)+f+e.rail.track*d,W=(e,t)=>H[t===`out`?e.laneFrom:e.laneTo]+e.port[t],G=new Map,Pe=(e,t)=>{G.has(e)||G.set(e,[]),G.get(e).push(t)};for(let e of I)if(e.kind===`jump`){let t={plan:e,index:e.index,ends:[`out`,`in`]};e.runs={out:t,in:t},Pe(e.outBand,t)}else e.kind===`bend`&&(e.runs={out:{plan:e,index:e.index,ends:[`out`],rail:!0},in:{plan:e,index:e.index,ends:[`in`],rail:!0}},Pe(e.outBand,e.runs.out),Pe(e.inBand,e.runs.in));let K=(e,t)=>(t===`out`?e.outSide:e.inSide)>0?`upper`:`lower`,Fe=e=>I.filter(t=>t.kind===`straight`&&e>=Math.min(t.outBand,t.inBand)&&e<=Math.max(t.outBand,t.inBand)),Ie=e=>e.flatMap(e=>e.ends.map(t=>({run:e,plan:e.plan,end:t,at:W(e.plan,t),cls:K(e.plan,t)}))),Le=e=>(G.get(e)||[]).filter(e=>e.after).map(e=>e.jog),Re=e=>I.filter(t=>t.kind===`bend`&&e>=t.rail.lo&&e<=t.rail.hi).map(U);ke=(e,t,n)=>Le(t===`out`?e.outBand:e.inBand).some(r=>Math.abs(r-(H[t===`out`?e.laneFrom:e.laneTo]+n))<p);let ze=e=>{let t=G.get(e)||[],n=Ie(t),r=[];for(let e=0;e<n.length;e+=1)for(let t=e+1;t<n.length;t+=1){let[i,a]=[n[e],n[t]];i.run===a.run||Math.abs(i.at-a.at)>=p||(i.cls===a.cls?r.push({kind:`apart`,a:i,b:a}):r.push({kind:`order`,upper:i.cls===`upper`?i:a,lower:i.cls===`upper`?a:i}))}for(let t of Fe(e))for(let e of n)e.plan!==t&&Math.abs(e.at-W(t,`out`))<p&&r.push({kind:`apart`,a:{at:W(t,`out`)},b:e});return r},q=e=>e.kind===`order`?`o|${e.upper.plan.index}|${e.upper.end}|${e.lower.plan.index}|${e.lower.end}`:`a|${e.a.plan?.index??`s`}|${e.a.end??``}|${e.b.plan.index}|${e.b.end}`,J=(e,t)=>{let n=t+p-e.at,r=t-p-e.at;return(Math.abs(n)<=Math.abs(r)?[n,r]:[r,n]).some(t=>Ae(Oe(e.plan,e.end),t))},Be=new Set,Y=new Set,Ve=e=>{let t=ze(e).filter(e=>e.kind===`order`&&!Be.has(q(e))).map(e=>({from:e.upper.run,to:e.lower.run,item:e}));for(let n of G.get(e)||[])n.after&&t.push({from:n,to:n.after,item:null});return t},He=(e,t)=>{let{plan:n}=e,r=e.ends.find(e=>K(n,e)===`upper`),i=e.ends.find(e=>K(n,e)===`lower`);if(!r||!i)return!1;let[a,o]=[Math.min(W(n,r),W(n,i)),Math.max(W(n,r),W(n,i))],s=[a,o,...Ie(G.get(t)).map(e=>e.at),...Fe(t).map(e=>W(e,`out`)),...Le(t),...Re(t)].filter(e=>e>=a&&e<=o).sort((e,t)=>e-t),c=null;for(let e=1;e<s.length;e+=1){let t=s[e]-s[e-1];t>=24&&(!c||t>c.gap)&&(c={gap:t,x:Math.round((s[e]+s[e-1])/2)})}if(!c)return!1;let l={plan:n,index:n.index,ends:[i],jog:c.x},u={plan:n,index:n.index,ends:[r],jog:c.x,after:l},d=G.get(t);return d.splice(d.indexOf(e),1,u,l),n.runs={[r]:u,[i]:l},!0},Ue=e=>Math.abs(W(e.plan,`out`)-W(e.plan,`in`)),We=[...G.keys()].sort((e,t)=>e-t);for(let e=0;e<96;e+=1){let e=null,t=null,n=null;for(let r of We){if(e=ze(r).find(e=>e.kind===`apart`&&!Y.has(q(e))),e)break;if(t=de(G.get(r),Ve(r)),t){n=r;break}}if(e){Y.add(q(e)),!J(e.b,e.a.at)&&e.a.plan&&J(e.a,e.b.at);continue}if(!t)break;let r=t.filter(e=>e.item).map(e=>e.item),i=r.find(e=>!Y.has(q(e)));i?(Y.add(q(i)),J(i.lower,i.upper.at)||J(i.upper,i.lower.at)):[...new Set(t.flatMap(e=>[e.from,e.to]))].filter(e=>e.ends.length===2).sort((e,t)=>Ue(t)-Ue(e)||e.index-t.index).some(e=>He(e,n))||Be.add(q(r[0]))}let X=[];for(let t of I){if(!t.label)continue;let n=t.outBand,r=!t.isBack,i=W(t,`out`),a=t.label.cross,o=Math.max(1,Math.ceil((8+t.label.along-f)/d)),s=[...Ie(G.get(n)||[]).filter(e=>e.plan!==t&&e.cls===(r?`upper`:`lower`)).map(e=>e.at),...Fe(n).filter(e=>e!==t).map(e=>W(e,`out`)),...I.filter(e=>e.kind===`bend`&&e!==t&&n>=e.rail.lo&&n<=e.rail.hi).map(U)],c=X.filter(e=>e.band===n&&e.top===r),l=e=>e>=0&&e+a<=Me&&s.every(t=>t<e-2||t>e+a+2)&&c.every(t=>t.hi+4<=e||e+a+4<=t.lo),u=Math.round(i-a/2),p=Math.max(0,Math.floor(a/2-y)),m=u;for(let e=0;e<=p;e+=2){if(l(u-e)){m=u-e;break}if(l(u+e)){m=u+e;break}}if(e.mermaid){let e=[i+v,i-a-v].find(l);e!=null&&(m=e)}X.push({plan:t,band:n,top:r,m:o,lo:m,hi:m+a})}let Ge=new Map;for(let e=0;e<=j;e+=1){let t=G.get(e)||[],n=X.filter(t=>t.band===e&&t.top),r=X.filter(t=>t.band===e&&!t.top);if(!t.length&&!X.some(t=>t.band===e))continue;let i=new Map(t.map(e=>[e,new Set]));for(let t of Ve(e))i.get(t.to).add(t.from);for(let e of t){let t=e.ends.map(t=>W(e.plan,t));e.rail&&t.push(U(e.plan)),e.jog!=null&&t.push(e.jog),e.lo=Math.min(...t),e.hi=Math.max(...t)}let a=[],o=new Set(t),s=(e,t)=>e.lo-t.lo||e.hi-t.hi||e.index-t.index;for(;o.size;){let e=[...o].filter(e=>[...i.get(e)].every(e=>!o.has(e))),t=(e.length?e:[...o]).sort(s)[0];a.push(t),o.delete(t)}let c=[],l=(e,t,n,r)=>(c[e]||=[]).push({lo:t,hi:n,owner:r});for(let e of n)for(let t=0;t<e.m;t+=1)l(t,e.lo,e.hi,e.plan);for(let e of a){let t=0;for(let n of i.get(e))n.track!=null&&(t=Math.max(t,n.track+1));for(let r of n){let n=e.ends.some(t=>K(e.plan,t)===`lower`&&W(e.plan,t)>=r.lo-2&&W(e.plan,t)<=r.hi+2);(r.plan===e.plan||n)&&(t=Math.max(t,r.m))}let r=t;for(;(c[r]||[]).some(t=>t.owner!==e.plan&&t.lo<=e.hi&&e.lo<=t.hi);)r+=1;l(r,e.lo,e.hi,e.plan),e.track=r}let u=c.length,d=Math.max(0,...r.map(e=>e.m));Ge.set(e,u+d)}let Z=Array.from({length:j+1},(e,t)=>le(Ge.get(t)||0,l)),Ke=C?(0,t.snap)(Math.max(i,...e.lanes.map(e=>n(e.name,t.FONT.title)+24))):i+24*(e.nested?.length||0),qe=Array.from({length:j+1},(e,t)=>(t&&(Ke+=Z[t-1]+F[t-1]),Ke)),Je=qe[j]+F[j]+(Ge.has(j)?Z[j]:0),Ye=C?Math.max(re?0:(0,t.snap)(g),Je):Me,Xe=C?Me:Je,Ze=e=>qe[e]+F[e],Q=(e,t)=>Ze(e)+f+t*d;for(let e of A){e.cross=H[N.get(e.lane)]+e.outset,e.along=qe[e.step]+Math.round((F[e.step]-T(e))/2);let t=E(e.cross,e.along);e.x=t.x,e.y=t.y}let Qe=(t,n,r)=>{let i=Math.abs(n-(t.cross+w(t)/2)),a=w(t)/2,o=e.mermaid&&t.shape===`circle`?a:0,s=t.diamond?Math.min(T(t)/2,i*T(t)/w(t)):o?a-Math.sqrt(Math.max(0,a*a-i*i)):0;return E(n,Math.round(r>0?t.along+T(t)-s:t.along+s))},$=I.map(e=>{let t=W(e,`out`),n=W(e,`in`),r=[];if(e.kind===`jump`&&e.runs.out===e.runs.in){let i=Q(e.outBand,e.runs.out.track);r.push(E(t,i),E(n,i))}else if(e.kind===`jump`){let i=Q(e.outBand,e.runs.out.track),a=Q(e.outBand,e.runs.in.track);r.push(E(t,i),E(e.runs.out.jog,i),E(e.runs.out.jog,a),E(n,a))}else if(e.kind===`bend`){let i=U(e),a=Q(e.outBand,e.runs.out.track),o=Q(e.inBand,e.runs.in.track);r.push(E(t,a),E(i,a),E(i,o),E(n,o))}return{id:e.edge.id,from:e.edge.from,to:e.edge.to,style:e.edge.style,line:e.edge.line,back:e.isBack,points:oe([Qe(e.from,t,e.outSide),...r,Qe(e.to,n,e.inSide)]),label:null}});if(e.mermaid)for(let e of I){if(!e.from.diamond||e.to.shape!==`rect`||e.isBack||e.laneFrom===e.laneTo||e.kind!==`jump`)continue;let t=Math.sign(e.laneTo-e.laneFrom),n=e.from.along+T(e.from)/2,r=e.to.along,i=e.from.cross+(t>0?w(e.from):0),a=e.to.cross+w(e.to)/2,o=Math.max(e.laneFrom,e.laneTo),s=H[o]-B[o]/2;if(r-n<=8||(s-i)*t<4||(a-s)*t<4||!A.every(t=>t===e.from||t===e.to||t.along+T(t)<n-4||t.along>r+4||t.cross+w(t)<Math.min(i,a)-4||t.cross>Math.max(i,a)+4))continue;let c=[E(i,n),E(s,n),E(s,r-8),E(a,r-8),E(a,r)],l=(e,t)=>e.w===0&&t.w===0&&e.x===t.x&&Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)>4||e.h===0&&t.h===0&&e.y===t.y&&Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x)>4;$.some((t,n)=>n!==e.index&&S(t.points).some(e=>S(c).some(t=>l(t,e))))||($[e.index].points=c,e.sideBranch={sourceAlong:n,rail:s})}let $e=se($);for(let e of $)e.hops=$e.get(e)||[],e.d=ce(e.points,e.hops);for(let e of X){let{label:t}=e.plan,n=e.top?Ze(e.band)+_:Ze(e.band)+Z[e.band]-_-t.along,r=e.plan.sideBranch?E(e.plan.sideBranch.rail-t.cross/2,e.plan.sideBranch.sourceAlong+v):E(e.lo,n);$[e.plan.index].label={x:r.x,y:r.y,w:t.w,h:t.h,lines:t.lines}}let et=e.lanes.map((e,t)=>C?{id:e.id,name:e.name,line:e.line,nodes:e.nodes,x:0,y:H[t],w:Ye,h:P[t].size}:{id:e.id,name:e.name,line:e.line,nodes:e.nodes,x:H[t],y:0,w:P[t].size,h:Xe});if(e.reverse){let e=C?`x`:`y`,t=C?`w`:`h`,n=C?Ye:Xe;for(let r of[...A,...$.map(e=>e.label).filter(Boolean)])r[e]=n-r[e]-r[t];for(let t of $){for(let r of[...t.points,...t.hops])r[e]=n-r[e];t.d=ce(t.points,t.hops)}}return{type:`swimlane`,direction:e.direction,width:Ye,height:Xe,lanes:et,nodes:A,edges:$,errors:[],model:e}}function w(e,t,n,r,i){let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=14/Math.max(s,c);return e.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`},t.elements.map(({tag:n,attrs:r})=>e.shape(n,{...r,...t.set===`simple`?{fill:i}:{fill:`none`,stroke:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))}var T=(e,t,n)=>t?.link?e.link(t.link.href,[n],t.link):n;function E(e,n){let r=e.model,i=r?.mermaid,a=new Map(r?.edges.map(e=>[e.id,e])),o=new Map(i?r.nodes.map(e=>[e.id,e]):[]),s=(0,t.appearance)(n),c=Array.from({length:6},(e,t)=>n.frameTone(n.color(`tone${t+1}`))),l=`swimlane-arrow`,u=[n.el(`defs`,{},[n.el(`marker`,{id:l,viewBox:`0 0 8 8`,refX:7,refY:4,markerWidth:8,markerHeight:8,markerUnits:`userSpaceOnUse`,orient:i?`auto-start-reverse`:`auto`},[n.path(`M0 0 L8 4 L0 8 Z`,{fill:s.fg4})])])];for(let[a,o]of e.lanes.entries()){let l=i&&r.lanes[a],d=s[l?.class]||c[a%c.length],f=n.el(`g`,{},[n.rect(o.x,o.y,o.w,o.h,{fill:n.tint(s.bg,d,.07),stroke:n.tint(s.bg,d,.45),"stroke-width":1,rx:s.radius}),n.text(e.direction===`LR`?r?.reverse?o.w-12:12:o.x+o.w/2,e.direction===`LR`?o.y+o.h/2:r?.reverse?o.h-18:18,o.name,{size:t.FONT.title.size,weight:t.FONT.title.weight,fill:s.fg1,anchor:e.direction===`LR`?r?.reverse?`end`:`start`:`middle`,"dominant-baseline":`central`})]);f.meta={lane:o.id,...i?{kind:`frame`,id:o.id}:{}},u.push(T(n,l,f))}if(i){let i=new Map(e.nodes.map(e=>[e.id,e])),a=r.nested.filter(e=>e.nodes.length);for(let[r,o]of a.entries()){let c=o.nodes.map(e=>i.get(e)),l=e.lanes.find(e=>e.id===o.lane),d=Math.min(...c.map(e=>e.x))-4,f=Math.min(...c.map(e=>e.y))-14-a.slice(r+1).filter(e=>e.lane===o.lane).length*20,p=Math.max(l.y+2,f-8),m=n.measure(o.title,t.FONT.label.size,600)+12,h=Math.min(l.x+l.w-d-2,Math.max(m,...c.map(e=>e.x+e.w+4-d))),g=Math.max(...c.map(e=>e.y+e.h+4-p));u.push(n.rect(d,p,h,g,{fill:s.surface2,stroke:s.line2,rx:s.smallRadius,meta:{kind:`frame`,id:o.id}})),u.push(n.text(d+6,p+9,o.title,{size:t.FONT.label.size,weight:600,anchor:`start`,"dominant-baseline":`central`,fill:s.fg2}))}}for(let t of e.edges){let e=a.get(t.id);i&&t.style===`invisible`||u.push(T(n,e,n.path(t.d,{fill:`none`,stroke:i&&s[e.status]||s.fg4,"stroke-width":i&&t.style===`bold`?2.5:1.25,"stroke-linejoin":`round`,...t.style===`dashed`?{"stroke-dasharray":`5 4`}:{},...!i||e.endArrow?{"marker-end":`url(#${l})`}:{},...i&&e.startArrow?{"marker-start":`url(#${l})`}:{},meta:{edge:t.id,back:t.back,...i?{kind:`edge`,from:t.from,to:t.to,...e.status?{status:e.status}:{}}:{}}})))}for(let r of e.nodes){let a=c[Math.max(0,e.lanes.findIndex(e=>e.id===r.lane))%c.length],l=r.class&&s[r.class]?s[r.class]:n.tint(s.bg,a,.4),d=i&&r.shape===`circle`?n.shape(`circle`,{cx:r.x+r.w/2,cy:r.y+r.h/2,r:r.w/2,fill:s.node,stroke:l,"stroke-width":1}):r.shape===`diamond`?n.shape(`polygon`,{points:`${r.x+r.w/2},${r.y} ${r.x+r.w},${r.y+r.h/2} ${r.x+r.w/2},${r.y+r.h} ${r.x},${r.y+r.h/2}`,fill:s.node,stroke:l,"stroke-width":1},{node:r.id,shape:r.shape,...r.class?{status:r.class}:{}}):n.rect(r.x,r.y,r.w,r.h,{fill:s.node,stroke:l,"stroke-width":1,rx:i&&r.shape===`stadium`?r.h/2:i&&r.shape===`rect`?0:s.smallRadius,meta:{node:r.id,shape:r.shape,...r.class?{status:r.class}:{}}});i&&(d.meta={...d.meta,kind:`node`,id:r.id});let f=t.statusMarks[r.class],p=o.get(r.id),m=p?.icon,h=[];if(m){let e=Math.max(0,...r.lines.map(e=>n.measure(e,t.FONT.body.size,t.FONT.body.weight))),i=r.x+r.w/2-(e/2+2),a=r.y+r.h/2;h.push(w(n,m,i,a,l))}u.push(T(n,p,n.el(`g`,{},[d,...h,...r.lines.map((e,i)=>n.text(r.x+r.w/2+(m?11:0),r.y+r.h/2+(i-(r.lines.length-1)/2)*20,e,{size:t.FONT.body.size,fill:s.fg1,anchor:`middle`,"dominant-baseline":`central`,meta:{node:r.id}})),...f?[n.text(r.x+8,r.y+9,f,{size:12,weight:600,fill:l,anchor:`middle`,"dominant-baseline":`central`,meta:{node:r.id,status:r.class}})]:[]])))}for(let r of e.edges.filter(e=>e.label)){let e=i&&a.get(r.id),o=e?.icon,c=n.el(`g`,{},[n.rect(r.label.x,r.label.y,r.label.w,r.label.h,{fill:s.surface}),...o?[w(n,o,r.label.x+12,r.label.y+r.label.h/2,s.fg2)]:[],...r.label.lines.map((e,i)=>n.text(r.label.x+r.label.w/2+(o?9:0),r.label.y+r.label.h/2+(i-(r.label.lines.length-1)/2)*16,e,{size:t.FONT.label.size,fill:s.fg2,anchor:`middle`,"dominant-baseline":`central`}))]);c.meta={label:r.id,...i?{kind:`edge-label-group`,from:r.from,to:r.to}:{}},u.push(T(n,e,c))}return{width:e.width,height:e.height,children:u}}return e.implementations={swimlane:{parse:re,layout:C,scene:E}},e.layout=C,e.scene=E,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/graph-parse`]);
@@ -1,3 +1,3 @@
1
1
  KChartUnits["diagram/time"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=80,r=240,i=4095,a=[],o=(e,n,r)=>(0,t.error)(e,n,`无法识别或处理语句「${String(r).slice(0,36)}」`,`Unrecognized or invalid statement: ${String(r).slice(0,36)}`,`修正这条语句或移除不支持的语法`,`Fix this statement or remove unsupported syntax`),s=e=>{if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return NaN;let[t,n,r]=e.split(`-`).map(Number);if(t<1)return NaN;let i=new Date(0);i.setUTCHours(0,0,0,0),i.setUTCFullYear(t,n-1,r);let a=new Date(i.getTime());return a.getUTCFullYear()===t&&a.getUTCMonth()===n-1&&a.getUTCDate()===r?i.getTime():NaN},c=(e,t)=>{if(!Number.isSafeInteger(Number(t)))return``;let n=s(e)+Number(t)*864e5;if(!Number.isFinite(n))return``;let r=new Date(n),i=r.getUTCFullYear();return!Number.isFinite(r.getTime())||i<1||i>9999?``:`${String(i).padStart(4,`0`)}-${String(r.getUTCMonth()+1).padStart(2,`0`)}-${String(r.getUTCDate()).padStart(2,`0`)}`},l=`(?:"(?:[^"\\\\]|\\\\.)*"|[\\w.-]+)`;function u(e,t,a){let{lang:u,options:d={},firstLine:f=2}=t,p=[],m=String(e).replace(/\r\n?/g,`
2
2
  `).split(`
3
- `);for(let e of Object.keys(d))p.push(o(u,t.headerLine||f-1,`option ${e}`));m.length>r&&p.push(o(u,f+r,`scope exceeds ${r} lines`));let h={type:a,title:t.title||``,items:[],sections:[],branches:a===`gitGraph`?[{name:`main`,head:``}]:[],fields:[],commits:[],config:{}},g=``,_=`main`,v=null,y=0,b=e=>y>=n?(p.push(o(u,e,`scope exceeds ${n} items`)),!1):(y+=1,!0),x=(e,t)=>{b(e)&&h.items.push({...t,line:e,section:g,branch:_})},S=e=>e?.startsWith(`"`)?e.slice(1,-1).replace(/\\(.)/g,`$1`):e;if(m.slice(0,r).forEach((e,t)=>{let n=f+t,r=e.trim();if(r&&!r.startsWith(`%%`)){if(/^(title|accTitle|accDescr)(?:\s*:|\s+)/i.test(r)){let e=r.replace(/^[^:\s]+\s*:?[ \t]*/,``);/^title/i.test(r)?h.title=e:p.push(o(u,n,r))}else{if(a===`gantt`){let e;if(e=/^dateFormat\s+(\S+)$/i.exec(r)){e[1]===`YYYY-MM-DD`?h.config.dateFormat=e[1]:p.push(o(u,n,r));return}if(e=/^axisFormat\s+(\S+)$/i.exec(r)){e[1]===`%Y-%m`?h.config.axisFormat=e[1]:p.push(o(u,n,r));return}if(/^(?:excludes|tickInterval|todayMarker)\b/i.test(r)){p.push(o(u,n,r));return}if(/^section\s+/i.test(r)){g=r.replace(/^section\s+/i,``).trim(),h.sections.push(g);return}if(e=/^(.+?)\s*:\s*(.*?)\s*$/.exec(r),e){let t=e[1].trim(),i=e[2].split(`,`).map(e=>e.trim()).filter(Boolean),a=[],l=``,d=``,f=``,m=``,h=``;for(let e of i)/^(done|active|crit|milestone)$/i.test(e)?a.push(e.toLowerCase()):/^after\s+/i.test(e)?(m&&p.push(o(u,n,r)),m=e.replace(/^after\s+/i,``).trim()):/^\d+d$/i.test(e)?(h&&p.push(o(u,n,r)),h=e.toLowerCase()):Number.isFinite(s(e))?d?f?p.push(o(u,n,r)):f=e:d=e:/^\d{4}/.test(e)?p.push(o(u,n,r)):!l&&/^[\w.-]+$/.test(e)?l=e:p.push(o(u,n,r));!d&&!m&&p.push(o(u,n,r)),f&&s(f)<s(d)&&p.push(o(u,n,r)),h&&!d&&!m&&p.push(o(u,n,r)),h&&d&&!f&&(f=c(d,Number.parseInt(h,10)),f||p.push(o(u,n,r))),x(n,{name:t,id:l,flags:a,start:d,end:f||d,milestone:a.includes(`milestone`),depends:m,duration:h});return}}else if(a===`timeline`){if(/^section\s+/i.test(r)){g=r.slice(8).trim(),h.sections.push(g);return}if(r.startsWith(`:`)){h.items.length?h.items.at(-1).events.push(r.slice(1).trim()):p.push(o(u,n,r));return}let e=/^(.+?)\s*:\s*(.+)$/.exec(r);if(e){x(n,{label:e[1].trim(),events:e[2].split(`:`).map(e=>e.trim()).filter(Boolean)});return}}else if(a===`journey`){if(/^section\s+/i.test(r)){g=r.slice(8).trim(),h.sections.push(g);return}let e=/^(.+?)\s*:\s*(\d+)\s*:\s*(.*)$/.exec(r);if(e){let t=Number(e[2]);t<1||t>5?p.push(o(u,n,r)):x(n,{name:e[1].trim(),score:t,actors:e[3].split(`,`).map(e=>e.trim()).filter(Boolean)});return}}else if(a===`gitGraph`){let e;if(e=RegExp(`^commit(?:\\s+id:\\s*(${l}))?(?:\\s+tag:\\s*(${l}))?(?:\\s+type:\\s*(NORMAL|REVERSE|HIGHLIGHT))?$`,`i`).exec(r)){let t=S(e[1])||`commit-${h.commits.length+1}`,r={id:t,tag:S(e[2])||``,commitType:(e[3]||`NORMAL`).toUpperCase(),branch:_,parents:[],line:n},i=h.branches.find(e=>e.name===_)?.head;i&&r.parents.push(i),h.commits.some(e=>e.id===t)&&p.push(o(u,n,`duplicate commit ${t}`)),h.commits.push(r),x(n,{action:`commit`,id:t,tag:r.tag,commitType:r.commitType});let a=h.branches.find(e=>e.name===_);a&&(a.head=t);return}if(e=/^branch\s+([\w.-]+)$/i.exec(r)){let t=S(e[1]),i=_;h.branches.some(e=>e.name===t)?p.push(o(u,n,r)):(h.branches.push({name:t,head:h.branches.find(e=>e.name===_)?.head||``}),_=t),x(n,{action:`branch`,name:t,from:i});return}if(e=/^checkout\s+([\w.-]+)$/i.exec(r)){let t=S(e[1]);h.branches.some(e=>e.name===t)?_=t:p.push(o(u,n,r)),x(n,{action:`checkout`,name:t});return}if(e=RegExp(`^merge\\s+([\\w.-]+)(?:\\s+id:\\s*(`+l+`))?$`,`i`).exec(r)){let t=S(e[1]),i=h.branches.find(e=>e.name===t),a=h.branches.find(e=>e.name===_);if(!i||t===_||!i.head||!a?.head)p.push(o(u,n,r));else{let r=S(e[2])||`merge-${h.commits.length+1}`;if(h.commits.some(e=>e.id===r))p.push(o(u,n,`duplicate commit ${r}`));else{let e={id:r,tag:``,commitType:`NORMAL`,branch:_,parents:[a.head,i.head],line:n,merge:t};h.commits.push(e),a.head=r,x(n,{action:`merge`,id:r,name:t,parents:e.parents})}}return}}else if(a===`kanban`){let t=e.match(/^[ ]*/)[0].length;if(/\t/.test(e)){p.push(o(u,n,r));return}if(t===0){let e=/^([\w.-]+)\[([^\]]+)\]$/.exec(r);if(!e||h.sections.some(t=>t.id===e[1])){p.push(o(u,n,r));return}if(!b(n))return;h.sections.push({id:e[1],name:e[2].trim(),line:n}),g=e[1],v=null;return}if(!g){p.push(o(u,n,r));return}let i=/^([\w.-]+)\[([^\]]+)\]$/.exec(r);if(!i||h.items.some(e=>e.id===i[1])||(v??=t,t!==v)){p.push(o(u,n,r));return}x(n,{id:i[1],name:i[2].trim()});return}else if(a===`packet-beta`){let e=/^(\d+)-(\d+)\s*:\s*"((?:[^"\\]|\\.)*)"\s*$/.exec(r);if(e){let t=Number(e[1]),a=Number(e[2]);!Number.isSafeInteger(t)||!Number.isSafeInteger(a)||t>a||a>i||h.fields.some(e=>t<=e.end&&a>=e.start)?p.push(o(u,n,r)):b(n)&&h.fields.push({start:t,end:a,name:e[3].replace(/\\(.)/g,`$1`),line:n});return}if(/^\+\d+\s*:/.test(r)){p.push(o(u,n,r));return}}else if(a===`quadrantChart`){let e;if(e=/^([xy])-axis\s+(.+)$/i.exec(r)){let t=`${e[1].toLowerCase()}axis`;if(h[t])p.push(o(u,n,r));else{let i=e[2].split(/\s*-->\s*/);i.length!==2||i.some(e=>!e.trim())?p.push(o(u,n,r)):h[t]=i.map(e=>e.trim())}return}if(e=/^quadrant-([1-4])\s+(.+)$/i.exec(r)){let t=`quadrant${e[1]}`;h[t]?p.push(o(u,n,r)):h[t]=e[2].trim();return}if(e=/^(.+?)\s*:\s*([\d.]+)\s*,\s*([\d.]+)\s*$/.exec(r)){let t=Number(e[2]),i=Number(e[3]);!Number.isFinite(t)||!Number.isFinite(i)||t<0||t>1||i<0||i>1?p.push(o(u,n,r)):x(n,{name:e[1].trim(),x:t,y:i});return}}p.push(o(u,n,r))}}}),a===`gantt`){let e=new Map,t=new Map;for(let n of h.items)n.id&&e.has(n.id)&&p.push(o(u,n.line,`duplicate task ID ${n.id}`)),n.id&&e.set(n.id,n),t.has(n.name)||t.set(n.name,[]),t.get(n.name).push(n);let n=n=>e.get(n)||(t.get(n)?.length===1?t.get(n)[0]:void 0),r=new Set,i=new Set,a=e=>{if(!i.has(e)){if(r.has(e))p.push(o(u,e.line,`dependency cycle ${e.name}`));else{if(r.add(e),e.depends){let t=n(e.depends);t?(a(t),!e.start&&t.end&&(e.start=t.end),e.start?e.duration&&!e.end&&(e.end=c(e.start,Number.parseInt(e.duration,10)),e.end||p.push(o(u,e.line,e.name))):p.push(o(u,e.line,`unresolved start ${e.name}`))):p.push(o(u,e.line,`after ${e.depends}`))}e.start&&!e.end&&(e.end=e.start),e.start&&e.end&&s(e.end)<s(e.start)&&p.push(o(u,e.line,e.name)),r.delete(e),i.add(e)}}};h.items.forEach(a)}return a===`gitGraph`&&!h.commits.length&&p.push(o(u,f,`gitGraph needs a commit`)),h.items.length||h.fields.length||a===`kanban`&&h.sections.length||p.push(o(u,f,`empty diagram`)),{model:h,errors:p}}var d=(e,t,n,r,i=13,a=e.color(`ink`),o=`start`,s=400)=>e.text(n,r,t,{size:i,fill:a,anchor:o,weight:s,"dominant-baseline":`middle`}),f=(e,t,n,r)=>e.wrap(String(t),Math.max(r,n),r,400);function p(e,{measure:t,width:n,ctx:r,renderOptions:i}){let a=!i?.frame&&!!e.title,o=[`gantt`,`journey`].includes(e.type)?14:0,c=i?.frame?54:(a?54:24)+o,l=/^en\b/i.test(r.lang||`zh`)?{done:`done`,active:`in progress`,crit:`critical`,milestone:`milestone`}:{done:`已完成`,active:`进行中`,crit:`关键`,milestone:`里程碑`},u=e=>(e.flags||[]).map(e=>l[e]||e).join(` · `),p={gantt:()=>e.items.flatMap(e=>[e.name,e.section||``,u(e)]),journey:()=>e.items.flatMap(e=>[e.section||``,e.name]),gitGraph:()=>e.branches.map(e=>e.name),quadrantChart:()=>e.yaxis||[]}[e.type]?.()??[],m=Math.max(0,...p.map(e=>t(e,{size:13,weight:400}))),h=Math.max(24,m+24),g=e.type===`timeline`||e.type===`kanban`?0:300,_=Math.max(g,n-h-24),v={ink:r.color(`ink`),accent:r.color(`accent`),muted:r.color(`muted`),grid:r.color(`grid`),bg:r.color(`bg`)},y={width:Math.max(n,h+_+24),height:180,title:e.title||e.type,description:`Mermaid ${e.type}`,children:[]},b=r.el,x=(e,t,n,i=13,a=v.ink,o=`start`,s=400)=>y.children.push(d(r,e,t,n,i,a,o,s)),S=(e,t,n,r,i=v.bg,a=v.grid,o=4)=>y.children.push(b(`rect`,{x:e,y:t,width:n,height:r,fill:i,stroke:a,rx:o})),C=(e,t,n,r,i=v.grid,a=1)=>y.children.push(b(`line`,{x1:e,y1:t,x2:n,y2:r,stroke:i,"stroke-width":a}));if(a?x(e.title,22,24,17,v.ink,`start`,650):i?.frame&&(y.heading=e.title||void 0),e.type===`gantt`){let t=[],n;for(let r of e.items)r.section&&r.section!==n&&t.push({header:r.section,h:30}),n=r.section,t.push({task:r,h:54});y.height=c+t.reduce((e,t)=>e+t.h,0)+30;let r=e.items.filter(e=>e.start),i=r.flatMap(e=>[s(e.start),s(e.end)]),a=new Date(Math.min(...i));a.setUTCDate(1);let o=a.getTime(),l=Math.max(...i),d=Math.max(864e5,l-o),f=e=>h+(s(e)-o)/d*_;if(r.length){let e=new Date(o),t=0;for(;e.getTime()<=l&&t++<240;){let t=h+(e.getTime()-o)/d*_;C(t,c-8,t,y.height-18),x(`${String(e.getUTCFullYear()).padStart(4,`0`)}-${String(e.getUTCMonth()+1).padStart(2,`0`)}`,t+2,c-18,12,v.muted),e.setUTCMonth(e.getUTCMonth()+1)}}let p=c;for(let e of t){if(e.header){x(e.header,12,p+15,13,v.muted,`start`,600),p+=e.h;continue}let{task:t}=e,n=u(t);if(x(t.name,12,p+(n?8:14),13),n&&x(n,12,p+26,12,v.muted),t.start){let e=f(t.start),n=f(t.end);t.milestone?y.children.push(b(`polygon`,{points:`${e},${p+5} ${e+9},${p+14} ${e},${p+23} ${e-9},${p+14}`,fill:v.accent})):S(e,p+3,Math.max(4,n-e),22,t.flags.includes(`crit`)?v.accent:v.ink,`none`,4)}p+=e.h}}else if(e.type===`timeline`){let t=Math.max(1,e.items.length),n=Math.max(180,_/t),i=c+18,a=e.items.map(e=>({title:f(r,e.label,n-20,13),events:f(r,e.events.join(` · `),n-20,12)})),o=Math.max(82,...a.map(e=>e.title.length*16+e.events.length*16+28));y.width=Math.max(y.width,h+t*n+24),y.height=c+o+45,C(h,i,h+t*n,i,v.grid,2),e.items.forEach((t,r)=>{let o=h+(r+.5)*n,s=i+18,c=a[r];y.children.push(b(`circle`,{cx:o,cy:i,r:5,fill:v.accent})),t.section&&t.section!==e.items[r-1]?.section&&x(t.section,o,s,12,v.muted,`middle`),c.title.forEach((e,t)=>x(e,o,s+20+t*16,13,v.ink,`middle`,600)),c.events.forEach((e,t)=>x(e,o,s+24+c.title.length*16+t*16,12,v.muted,`middle`))})}else if(e.type===`journey`){let n=[],r;for(let t of e.items)t.section&&t.section!==r&&n.push({header:t.section,h:30}),r=t.section,n.push({item:t,h:62});y.height=c+n.reduce((e,t)=>e+t.h,0)+12;let i=Math.max(0,...e.items.map(e=>t(e.actors.join(`, `),{size:12,weight:400})))+20,a=Math.max(_,i),o=h,s=a/4;y.width=Math.max(y.width,h+a+24);for(let e=1;e<=5;e++)x(String(e),o+(e-1)*s,c-10,12,v.muted,`middle`);let l=c;for(let e of n){if(e.header){x(e.header,12,l+15,13,v.muted,`start`,600),l+=e.h;continue}let{item:t}=e;x(t.name,12,l+16,13),C(o,l+16,o+a,l+16,v.grid);for(let e=1;e<=5;e++)y.children.push(b(`circle`,{cx:o+(e-1)*s,cy:l+16,r:3+(e===t.score?3:0),fill:e<=t.score?v.accent:v.bg,stroke:v.accent}));t.actors.length&&x(t.actors.join(`, `),o,l+39,12,v.muted),l+=e.h}}else if(e.type===`kanban`){let n=e.sections,i=Math.max(0,...n.map(e=>t(e.name,{size:14,weight:650})+30)),a=Math.max(160,(_+10)/n.length,i);y.width=Math.max(y.width,h+a*n.length-10+24);let o=new Map(e.items.map(e=>[e.id,f(r,e.name,a-44,13)])),s=Math.max(52,...[...o.values()].map(e=>e.length*17+30)),l=Math.max(1,...n.map(t=>e.items.filter(e=>e.section===t.id).length));y.height=c+50+l*s,n.forEach((t,n)=>{let r=h+n*a;S(r,c,a-10,y.height-c-20,`transparent`,v.grid,6),x(t.name,r+10,c+18,14,v.ink,`start`,650),e.items.filter(e=>e.section===t.id).forEach((e,t)=>{let n=c+38+t*s,i=o.get(e.id);S(r+6,n,a-22,s-10);let l=n+(s-10)/2-(i.length-1)*8.5;i.forEach((e,t)=>x(e,r+16,l+t*17,13))})})}else if(e.type===`packet-beta`){let n=Math.max(1,...e.fields.map(e=>Math.floor(e.end/32)+1)),i=Array.from({length:n},(t,n)=>e.fields.filter(e=>e.start<=n*32+31&&e.end>=n*32).map(e=>{let t=Math.max(e.start,n*32),r=Math.min(e.end,n*32+31);return{start:t,end:r,bits:r-t+1,name:e.name}})),a=Math.ceil(Math.max(24,...i.flat().map(e=>t(String(e.end),{size:12,weight:400})+12))),o=Math.max(_/32,...i.flat().map(e=>a/e.bits)),s=o*32;y.width=Math.max(y.width,h+s+24);let l=c;i.forEach((e,t)=>{let n=e.map(e=>{let n=e.bits*o;return{x:h+(e.start-t*32)*o,w:n,lines:f(r,`${e.name} ${e.start}-${e.end}`,n-12,12)}}),i=Math.max(34,...n.map(e=>16+e.lines.length*16));for(let{x:e,w:t,lines:r}of n)S(e,l,t,i,v.bg,v.grid,0),r.forEach((t,n)=>x(t,e+6,l+16+n*16,12));C(h,l+i+2,h+s,l+i+2);for(let e of[0,7,15,23,31])x(String(t*32+e),h+(e+.5)*o,l+i+23,12,v.muted,`middle`);l+=i+48}),y.height=l+25}else if(e.type===`quadrantChart`){let n=h,r=c,i=[{name:e.quadrant1,right:!0,top:!0},{name:e.quadrant2,right:!1,top:!0},{name:e.quadrant3,right:!1,top:!1},{name:e.quadrant4,right:!0,top:!1}],a=e=>t(e,{size:12,weight:400}),o=Math.max(_,...i.filter(e=>e.name).map(e=>2*(a(e.name)+16)),...e.items.map(e=>(a(e.name)+16)/Math.max(e.x,1-e.x)),(e.xaxis||[]).reduce((e,t)=>e+a(t),24));y.width=Math.max(y.width,n+o+24),y.height=r+270+62,S(n,r,o,270,`transparent`,v.grid,0),C(n+o/2,r,n+o/2,r+270),C(n,r+135,n+o,r+135);for(let e of i)e.name&&x(e.name,e.right?n+o-8:n+8,e.top?r+16:r+270-16,12,v.muted,e.right?`end`:`start`);x(e.xaxis?.[0]||``,n,r+270+20,12,v.muted),x(e.xaxis?.[1]||``,n+o,r+270+20,12,v.muted,`end`),x(e.yaxis?.[0]||``,n-8,r+270,12,v.muted,`end`),x(e.yaxis?.[1]||``,n-8,r,12,v.muted,`end`),e.items.forEach(e=>{let t=n+e.x*o,i=r+(1-e.y)*270,a=e.x>.5?-1:1;y.children.push(b(`circle`,{cx:t,cy:i,r:5,fill:v.accent})),x(e.name,t+a*8,i,12,v.ink,a<0?`end`:`start`)})}else if(e.type===`gitGraph`){let n=e.commits,r=e.branches,i=new Map([[`main`,0]]);r.forEach(e=>{i.has(e.name)||i.set(e.name,i.size)});let a=Math.max(90,...n.map(e=>t(e.tag||e.id,{size:12,weight:400})+24)),o=Math.max(0,i.size-1),s=e=>c+22+(i.get(e)||0)*58,l=e=>h+70+n.findIndex(t=>t.id===e)*a;y.height=c+22+o*58+40,y.width=Math.max(y.width,h+110+n.length*a),r.forEach(e=>{let t=s(e.name);x(e.name,12,t,12,v.muted),C(h,t,h+Math.max(_,n.length*a),t,v.grid)}),n.forEach(e=>e.parents.forEach(t=>{let r=n.find(e=>e.id===t);r&&C(l(t),s(r.branch),l(e.id),s(e.branch),v.accent,2)})),n.forEach(e=>{let t=l(e.id),n=s(e.branch);y.children.push(b(`circle`,{cx:t,cy:n,r:8,fill:e.commitType===`HIGHLIGHT`?v.accent:v.bg,stroke:v.accent,"stroke-width":2})),x(e.tag||e.id,t,n+20,12,v.ink,`middle`)})}else y.height=c+e.items.length*54+30;return{width:y.width,height:y.height,scene:y,items:e.items,errors:[]}}return e.implementations=Object.fromEntries(a.map(e=>[e,{parse:(t,n)=>u(t,n,e),layout:p}])),e})({},KChartUnits[`diagram/support`]);
3
+ `);for(let e of Object.keys(d))p.push(o(u,t.headerLine||f-1,`option ${e}`));m.length>r&&p.push(o(u,f+r,`scope exceeds ${r} lines`));let h={type:a,title:t.title||``,items:[],sections:[],branches:a===`gitGraph`?[{name:`main`,head:``}]:[],fields:[],commits:[],config:{}},g=``,_=`main`,v=null,y=0,b=e=>y>=n?(p.push(o(u,e,`scope exceeds ${n} items`)),!1):(y+=1,!0),x=(e,t)=>{b(e)&&h.items.push({...t,line:e,section:g,branch:_})},S=e=>e?.startsWith(`"`)?e.slice(1,-1).replace(/\\(.)/g,`$1`):e;if(m.slice(0,r).forEach((e,t)=>{let n=f+t,r=e.trim();if(r&&!r.startsWith(`%%`)){if(/^(title|accTitle|accDescr)(?:\s*:|\s+)/i.test(r)){let e=r.replace(/^[^:\s]+\s*:?[ \t]*/,``);/^title/i.test(r)?h.title=e:p.push(o(u,n,r))}else{if(a===`gantt`){let e;if(e=/^dateFormat\s+(\S+)$/i.exec(r)){e[1]===`YYYY-MM-DD`?h.config.dateFormat=e[1]:p.push(o(u,n,r));return}if(e=/^axisFormat\s+(\S+)$/i.exec(r)){e[1]===`%Y-%m`?h.config.axisFormat=e[1]:p.push(o(u,n,r));return}if(/^(?:excludes|tickInterval|todayMarker)\b/i.test(r)){p.push(o(u,n,r));return}if(/^section\s+/i.test(r)){g=r.replace(/^section\s+/i,``).trim(),h.sections.push(g);return}if(e=/^(.+?)\s*:\s*(.*?)\s*$/.exec(r),e){let t=e[1].trim(),i=e[2].split(`,`).map(e=>e.trim()).filter(Boolean),a=[],l=``,d=``,f=``,m=``,h=``;for(let e of i)/^(done|active|crit|milestone)$/i.test(e)?a.push(e.toLowerCase()):/^after\s+/i.test(e)?(m&&p.push(o(u,n,r)),m=e.replace(/^after\s+/i,``).trim()):/^\d+d$/i.test(e)?(h&&p.push(o(u,n,r)),h=e.toLowerCase()):Number.isFinite(s(e))?d?f?p.push(o(u,n,r)):f=e:d=e:/^\d{4}/.test(e)?p.push(o(u,n,r)):!l&&/^[\w.-]+$/.test(e)?l=e:p.push(o(u,n,r));!d&&!m&&p.push(o(u,n,r)),f&&s(f)<s(d)&&p.push(o(u,n,r)),h&&!d&&!m&&p.push(o(u,n,r)),h&&d&&!f&&(f=c(d,Number.parseInt(h,10)),f||p.push(o(u,n,r))),x(n,{name:t,id:l,flags:a,start:d,end:f||d,milestone:a.includes(`milestone`),depends:m,duration:h});return}}else if(a===`timeline`){if(/^section\s+/i.test(r)){g=r.slice(8).trim(),h.sections.push(g);return}if(r.startsWith(`:`)){h.items.length?h.items.at(-1).events.push(r.slice(1).trim()):p.push(o(u,n,r));return}let e=/^(.+?)\s*:\s*(.+)$/.exec(r);if(e){x(n,{label:e[1].trim(),events:e[2].split(`:`).map(e=>e.trim()).filter(Boolean)});return}}else if(a===`journey`){if(/^section\s+/i.test(r)){g=r.slice(8).trim(),h.sections.push(g);return}let e=/^(.+?)\s*:\s*(\d+)\s*:\s*(.*)$/.exec(r);if(e){let t=Number(e[2]);t<1||t>5?p.push(o(u,n,r)):x(n,{name:e[1].trim(),score:t,actors:e[3].split(`,`).map(e=>e.trim()).filter(Boolean)});return}}else if(a===`gitGraph`){let e;if(e=RegExp(`^commit(?:\\s+id:\\s*(${l}))?(?:\\s+tag:\\s*(${l}))?(?:\\s+type:\\s*(NORMAL|REVERSE|HIGHLIGHT))?$`,`i`).exec(r)){let t=S(e[1])||`commit-${h.commits.length+1}`,r={id:t,tag:S(e[2])||``,commitType:(e[3]||`NORMAL`).toUpperCase(),branch:_,parents:[],line:n},i=h.branches.find(e=>e.name===_)?.head;i&&r.parents.push(i),h.commits.some(e=>e.id===t)&&p.push(o(u,n,`duplicate commit ${t}`)),h.commits.push(r),x(n,{action:`commit`,id:t,tag:r.tag,commitType:r.commitType});let a=h.branches.find(e=>e.name===_);a&&(a.head=t);return}if(e=/^branch\s+([\w.-]+)$/i.exec(r)){let t=S(e[1]),i=_;h.branches.some(e=>e.name===t)?p.push(o(u,n,r)):(h.branches.push({name:t,head:h.branches.find(e=>e.name===_)?.head||``}),_=t),x(n,{action:`branch`,name:t,from:i});return}if(e=/^checkout\s+([\w.-]+)$/i.exec(r)){let t=S(e[1]);h.branches.some(e=>e.name===t)?_=t:p.push(o(u,n,r)),x(n,{action:`checkout`,name:t});return}if(e=RegExp(`^merge\\s+([\\w.-]+)(?:\\s+id:\\s*(`+l+`))?$`,`i`).exec(r)){let t=S(e[1]),i=h.branches.find(e=>e.name===t),a=h.branches.find(e=>e.name===_);if(!i||t===_||!i.head||!a?.head)p.push(o(u,n,r));else{let r=S(e[2])||`merge-${h.commits.length+1}`;if(h.commits.some(e=>e.id===r))p.push(o(u,n,`duplicate commit ${r}`));else{let e={id:r,tag:``,commitType:`NORMAL`,branch:_,parents:[a.head,i.head],line:n,merge:t};h.commits.push(e),a.head=r,x(n,{action:`merge`,id:r,name:t,parents:e.parents})}}return}}else if(a===`kanban`){let t=e.match(/^[ ]*/)[0].length;if(/\t/.test(e)){p.push(o(u,n,r));return}if(t===0){let e=/^([\w.-]+)\[([^\]]+)\]$/.exec(r);if(!e||h.sections.some(t=>t.id===e[1])){p.push(o(u,n,r));return}if(!b(n))return;h.sections.push({id:e[1],name:e[2].trim(),line:n}),g=e[1],v=null;return}if(!g){p.push(o(u,n,r));return}let i=/^([\w.-]+)\[([^\]]+)\]$/.exec(r);if(!i||h.items.some(e=>e.id===i[1])||(v??=t,t!==v)){p.push(o(u,n,r));return}x(n,{id:i[1],name:i[2].trim()});return}else if(a===`packet-beta`){let e=/^(\d+)-(\d+)\s*:\s*"((?:[^"\\]|\\.)*)"\s*$/.exec(r);if(e){let t=Number(e[1]),a=Number(e[2]);!Number.isSafeInteger(t)||!Number.isSafeInteger(a)||t>a||a>i||h.fields.some(e=>t<=e.end&&a>=e.start)?p.push(o(u,n,r)):b(n)&&h.fields.push({start:t,end:a,name:e[3].replace(/\\(.)/g,`$1`),line:n});return}if(/^\+\d+\s*:/.test(r)){p.push(o(u,n,r));return}}else if(a===`quadrantChart`){let e;if(e=/^([xy])-axis\s+(.+)$/i.exec(r)){let t=`${e[1].toLowerCase()}axis`;if(h[t])p.push(o(u,n,r));else{let i=e[2].split(/\s*-->\s*/);i.length!==2||i.some(e=>!e.trim())?p.push(o(u,n,r)):h[t]=i.map(e=>e.trim())}return}if(e=/^quadrant-([1-4])\s+(.+)$/i.exec(r)){let t=`quadrant${e[1]}`;h[t]?p.push(o(u,n,r)):h[t]=e[2].trim();return}if(e=/^(.+?)\s*:\s*([\d.]+)\s*,\s*([\d.]+)\s*$/.exec(r)){let t=Number(e[2]),i=Number(e[3]);!Number.isFinite(t)||!Number.isFinite(i)||t<0||t>1||i<0||i>1?p.push(o(u,n,r)):x(n,{name:e[1].trim(),x:t,y:i});return}}p.push(o(u,n,r))}}}),a===`gantt`){let e=new Map,t=new Map;for(let n of h.items)n.id&&e.has(n.id)&&p.push(o(u,n.line,`duplicate task ID ${n.id}`)),n.id&&e.set(n.id,n),t.has(n.name)||t.set(n.name,[]),t.get(n.name).push(n);let n=n=>e.get(n)||(t.get(n)?.length===1?t.get(n)[0]:void 0),r=new Set,i=new Set,a=e=>{if(!i.has(e)){if(r.has(e))p.push(o(u,e.line,`dependency cycle ${e.name}`));else{if(r.add(e),e.depends){let t=n(e.depends);t?(a(t),!e.start&&t.end&&(e.start=t.end),e.start?e.duration&&!e.end&&(e.end=c(e.start,Number.parseInt(e.duration,10)),e.end||p.push(o(u,e.line,e.name))):p.push(o(u,e.line,`unresolved start ${e.name}`))):p.push(o(u,e.line,`after ${e.depends}`))}e.start&&!e.end&&(e.end=e.start),e.start&&e.end&&s(e.end)<s(e.start)&&p.push(o(u,e.line,e.name)),r.delete(e),i.add(e)}}};h.items.forEach(a)}return a===`gitGraph`&&!h.commits.length&&p.push(o(u,f,`gitGraph needs a commit`)),h.items.length||h.fields.length||a===`kanban`&&h.sections.length||p.push(o(u,f,`empty diagram`)),{model:h,errors:p}}var d=(e,t,n,r,i=13,a=e.color(`ink`),o=`start`,s=400)=>e.text(n,r,t,{size:i,fill:a,anchor:o,weight:s,"dominant-baseline":`middle`}),f=(e,t,n,r)=>e.wrap(String(t),Math.max(r,n),r,400);function p(e,{measure:t,width:n,ctx:r,renderOptions:i,embedHeading:a}){let o=!i?.frame&&!a&&!!e.title,c=[`gantt`,`journey`].includes(e.type)?14:0,l=i?.frame?54:(o?54:24)+c,u=/^en\b/i.test(r.lang||`zh`)?{done:`done`,active:`in progress`,crit:`critical`,milestone:`milestone`}:{done:`已完成`,active:`进行中`,crit:`关键`,milestone:`里程碑`},p=e=>(e.flags||[]).map(e=>u[e]||e).join(` · `),m={gantt:()=>e.items.flatMap(e=>[e.name,e.section||``,p(e)]),journey:()=>e.items.flatMap(e=>[e.section||``,e.name]),gitGraph:()=>e.branches.map(e=>e.name),quadrantChart:()=>e.yaxis||[]}[e.type]?.()??[],h=Math.max(0,...m.map(e=>t(e,{size:13,weight:400}))),g=Math.max(24,h+24),_=e.type===`timeline`||e.type===`kanban`?0:300,v=Math.max(_,n-g-24),y={ink:r.color(`ink`),accent:r.color(`accent`),muted:r.color(`muted`),grid:r.color(`grid`),bg:r.color(`bg`)},b={width:Math.max(n,g+v+24),height:180,title:e.title||e.type,description:`Mermaid ${e.type}`,children:[]},x=r.el,S=(e,t,n,i=13,a=y.ink,o=`start`,s=400)=>b.children.push(d(r,e,t,n,i,a,o,s)),C=(e,t,n,r,i=y.bg,a=y.grid,o=4)=>b.children.push(x(`rect`,{x:e,y:t,width:n,height:r,fill:i,stroke:a,rx:o})),w=(e,t,n,r,i=y.grid,a=1)=>b.children.push(x(`line`,{x1:e,y1:t,x2:n,y2:r,stroke:i,"stroke-width":a}));if(o?S(e.title,22,24,17,y.ink,`start`,650):(i?.frame||a)&&(b.heading=e.title||void 0),e.type===`gantt`){let t=[],n;for(let r of e.items)r.section&&r.section!==n&&t.push({header:r.section,h:30}),n=r.section,t.push({task:r,h:54});b.height=l+t.reduce((e,t)=>e+t.h,0)+30;let r=e.items.filter(e=>e.start),i=r.flatMap(e=>[s(e.start),s(e.end)]),a=new Date(Math.min(...i));a.setUTCDate(1);let o=a.getTime(),c=Math.max(...i),u=Math.max(864e5,c-o),d=e=>g+(s(e)-o)/u*v;if(r.length){let e=new Date(o),t=0;for(;e.getTime()<=c&&t++<240;){let t=g+(e.getTime()-o)/u*v;w(t,l-8,t,b.height-18),S(`${String(e.getUTCFullYear()).padStart(4,`0`)}-${String(e.getUTCMonth()+1).padStart(2,`0`)}`,t+2,l-18,12,y.muted),e.setUTCMonth(e.getUTCMonth()+1)}}let f=l;for(let e of t){if(e.header){S(e.header,12,f+15,13,y.muted,`start`,600),f+=e.h;continue}let{task:t}=e,n=p(t);if(S(t.name,12,f+(n?8:14),13),n&&S(n,12,f+26,12,y.muted),t.start){let e=d(t.start),n=d(t.end);t.milestone?b.children.push(x(`polygon`,{points:`${e},${f+5} ${e+9},${f+14} ${e},${f+23} ${e-9},${f+14}`,fill:y.accent})):C(e,f+3,Math.max(4,n-e),22,t.flags.includes(`crit`)?y.accent:y.ink,`none`,4)}f+=e.h}}else if(e.type===`timeline`){let t=Math.max(1,e.items.length),n=Math.max(180,v/t),i=l+18,a=e.items.map(e=>({title:f(r,e.label,n-20,13),events:f(r,e.events.join(` · `),n-20,12)})),o=Math.max(82,...a.map(e=>e.title.length*16+e.events.length*16+28));b.width=Math.max(b.width,g+t*n+24),b.height=l+o+45,w(g,i,g+t*n,i,y.grid,2),e.items.forEach((t,r)=>{let o=g+(r+.5)*n,s=i+18,c=a[r];b.children.push(x(`circle`,{cx:o,cy:i,r:5,fill:y.accent})),t.section&&t.section!==e.items[r-1]?.section&&S(t.section,o,s,12,y.muted,`middle`),c.title.forEach((e,t)=>S(e,o,s+20+t*16,13,y.ink,`middle`,600)),c.events.forEach((e,t)=>S(e,o,s+24+c.title.length*16+t*16,12,y.muted,`middle`))})}else if(e.type===`journey`){let n=[],r;for(let t of e.items)t.section&&t.section!==r&&n.push({header:t.section,h:30}),r=t.section,n.push({item:t,h:62});b.height=l+n.reduce((e,t)=>e+t.h,0)+12;let i=Math.max(0,...e.items.map(e=>t(e.actors.join(`, `),{size:12,weight:400})))+20,a=Math.max(v,i),o=g,s=a/4;b.width=Math.max(b.width,g+a+24);for(let e=1;e<=5;e++)S(String(e),o+(e-1)*s,l-10,12,y.muted,`middle`);let c=l;for(let e of n){if(e.header){S(e.header,12,c+15,13,y.muted,`start`,600),c+=e.h;continue}let{item:t}=e;S(t.name,12,c+16,13),w(o,c+16,o+a,c+16,y.grid);for(let e=1;e<=5;e++)b.children.push(x(`circle`,{cx:o+(e-1)*s,cy:c+16,r:3+(e===t.score?3:0),fill:e<=t.score?y.accent:y.bg,stroke:y.accent}));t.actors.length&&S(t.actors.join(`, `),o,c+39,12,y.muted),c+=e.h}}else if(e.type===`kanban`){let n=e.sections,i=Math.max(0,...n.map(e=>t(e.name,{size:14,weight:650})+30)),a=Math.max(160,(v+10)/n.length,i);b.width=Math.max(b.width,g+a*n.length-10+24);let o=new Map(e.items.map(e=>[e.id,f(r,e.name,a-44,13)])),s=Math.max(52,...[...o.values()].map(e=>e.length*17+30)),c=Math.max(1,...n.map(t=>e.items.filter(e=>e.section===t.id).length));b.height=l+50+c*s,n.forEach((t,n)=>{let r=g+n*a;C(r,l,a-10,b.height-l-20,`transparent`,y.grid,6),S(t.name,r+10,l+18,14,y.ink,`start`,650),e.items.filter(e=>e.section===t.id).forEach((e,t)=>{let n=l+38+t*s,i=o.get(e.id);C(r+6,n,a-22,s-10);let c=n+(s-10)/2-(i.length-1)*8.5;i.forEach((e,t)=>S(e,r+16,c+t*17,13))})})}else if(e.type===`packet-beta`){let n=Math.max(1,...e.fields.map(e=>Math.floor(e.end/32)+1)),i=Array.from({length:n},(t,n)=>e.fields.filter(e=>e.start<=n*32+31&&e.end>=n*32).map(e=>{let t=Math.max(e.start,n*32),r=Math.min(e.end,n*32+31);return{start:t,end:r,bits:r-t+1,name:e.name}})),a=Math.ceil(Math.max(24,...i.flat().map(e=>t(String(e.end),{size:12,weight:400})+12))),o=Math.max(v/32,...i.flat().map(e=>a/e.bits)),s=o*32;b.width=Math.max(b.width,g+s+24);let c=l;i.forEach((e,t)=>{let n=e.map(e=>{let n=e.bits*o;return{x:g+(e.start-t*32)*o,w:n,lines:f(r,`${e.name} ${e.start}-${e.end}`,n-12,12)}}),i=Math.max(34,...n.map(e=>16+e.lines.length*16));for(let{x:e,w:t,lines:r}of n)C(e,c,t,i,y.bg,y.grid,0),r.forEach((t,n)=>S(t,e+6,c+16+n*16,12));w(g,c+i+2,g+s,c+i+2);for(let e of[0,7,15,23,31])S(String(t*32+e),g+(e+.5)*o,c+i+23,12,y.muted,`middle`);c+=i+48}),b.height=c+25}else if(e.type===`quadrantChart`){let n=g,r=l,i=[{name:e.quadrant1,right:!0,top:!0},{name:e.quadrant2,right:!1,top:!0},{name:e.quadrant3,right:!1,top:!1},{name:e.quadrant4,right:!0,top:!1}],a=e=>t(e,{size:12,weight:400}),o=Math.max(v,...i.filter(e=>e.name).map(e=>2*(a(e.name)+16)),...e.items.map(e=>(a(e.name)+16)/Math.max(e.x,1-e.x)),(e.xaxis||[]).reduce((e,t)=>e+a(t),24));b.width=Math.max(b.width,n+o+24),b.height=r+270+62,C(n,r,o,270,`transparent`,y.grid,0),w(n+o/2,r,n+o/2,r+270),w(n,r+135,n+o,r+135);for(let e of i)e.name&&S(e.name,e.right?n+o-8:n+8,e.top?r+16:r+270-16,12,y.muted,e.right?`end`:`start`);S(e.xaxis?.[0]||``,n,r+270+20,12,y.muted),S(e.xaxis?.[1]||``,n+o,r+270+20,12,y.muted,`end`),S(e.yaxis?.[0]||``,n-8,r+270,12,y.muted,`end`),S(e.yaxis?.[1]||``,n-8,r,12,y.muted,`end`),e.items.forEach(e=>{let t=n+e.x*o,i=r+(1-e.y)*270,a=e.x>.5?-1:1;b.children.push(x(`circle`,{cx:t,cy:i,r:5,fill:y.accent})),S(e.name,t+a*8,i,12,y.ink,a<0?`end`:`start`)})}else if(e.type===`gitGraph`){let n=e.commits,r=e.branches,i=new Map([[`main`,0]]);r.forEach(e=>{i.has(e.name)||i.set(e.name,i.size)});let a=Math.max(90,...n.map(e=>t(e.tag||e.id,{size:12,weight:400})+24)),o=Math.max(0,i.size-1),s=e=>l+22+(i.get(e)||0)*58,c=e=>g+70+n.findIndex(t=>t.id===e)*a;b.height=l+22+o*58+40,b.width=Math.max(b.width,g+110+n.length*a),r.forEach(e=>{let t=s(e.name);S(e.name,12,t,12,y.muted),w(g,t,g+Math.max(v,n.length*a),t,y.grid)}),n.forEach(e=>e.parents.forEach(t=>{let r=n.find(e=>e.id===t);r&&w(c(t),s(r.branch),c(e.id),s(e.branch),y.accent,2)})),n.forEach(e=>{let t=c(e.id),n=s(e.branch);b.children.push(x(`circle`,{cx:t,cy:n,r:8,fill:e.commitType===`HIGHLIGHT`?y.accent:y.bg,stroke:y.accent,"stroke-width":2})),S(e.tag||e.id,t,n+20,12,y.ink,`middle`)})}else b.height=l+e.items.length*54+30;return{width:b.width,height:b.height,scene:b,items:e.items,errors:[]}}return e.implementations=Object.fromEntries(a.map(e=>[e,{parse:(t,n)=>u(t,n,e),layout:p}])),e})({},KChartUnits[`diagram/support`]);
@@ -1,2 +1,2 @@
1
1
  KChartUnits["diagram/timeline"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e,a){let{lang:o,firstLine:s=2}=a,c=[],l=[],u=[{name:``,items:[]}],d=(0,r.presentation)({lang:o}),f=new Set,p=(a.params?.trim()||`LR`).toUpperCase(),m=(e,t,n)=>c.push((0,i.error)(o,e,t,n,`使用 timeline [LR|TD] 和「时段 : 事件」`,`Use timeline [LR|TD] and “period : event”`)),h=e=>{f.has(e.message)||(f.add(e.message),c.push(e))},g=(e,r,a)=>{let s=e.replace(/:::[\w-]+/g,``).trim(),c,l=/\s*::icon\(([^)]+)\)\s*$/i.exec(s);l&&(c=l[1],s=s.slice(0,l.index).trimEnd()),s=s.replace(/(?<![\w:/.-])(?:logos|mdi|tabler|simple-icons):[a-z\d-]+/gi,e=>(c??=e,``));let u=(0,n.normalizeLabel)(s,{lang:o,line:a});u.diagnostics.forEach(h);let d=c?(0,t.resolveIconRef)(c):null;return c&&!d&&h((0,i.warning)(`IGNORED_ASSET`,o,a,`未知图标 ${c}`,`Unknown icon ${c}`,`使用内置图标或注册图标集`,`Use a built-in icon or register its icon set`)),{text:u.text,icon:u.icon??d,id:r,line:a}};[`LR`,`TD`].includes(p)||m(a.headerLine,`时间线方向必须是 LR 或 TD`,`Timeline direction must be LR or TD`);let _={text:a.title||``,line:a.configLines?.title??a.headerLine??s},v={type:`timeline`,title:``,direction:p,items:l,sections:u,firstLine:s,config:a.config?.timeline||{}};if(e.length>2e5)return m(s,`时间线源码超过 200000 字符,请拆分`,`Timeline exceeds 200,000 characters; split the diagram`),{model:v,errors:c};for(let[t,n]of e.split(`
2
- `).entries()){let e=t+s,r=n.trim();if(!r||r.startsWith(`#`)||r.startsWith(`%%`)||d.accept(r,e))continue;let i=/^(title|section)(?:\s*:\s*|\s+)(.+)$/i.exec(r);if(i){if(i[1].toLowerCase()===`title`)_={text:i[2],line:e};else{let t=g(i[2],null,e);u.push({name:t.text,icon:t.icon,items:[]})}continue}let a=r.split(/\s*:(?=\s|$)/),o=a.shift();if(o.trim()){let t=`period:${l.length}`,n=g(o,t,e);n.events=[],n.eventDetails=[],y(o,t,e),n.index=l.length,l.push(n),u.at(-1).items.push(n)}if(!l.length)m(e,`事件前必须先声明时段`,`Declare a period before its events`);else{let t=l.at(-1);for(let n of a){let r=n.trim();if(!r)continue;let i=`${t.id}:event:${t.events.length}`,a=g(r,i,e);y(r,i,e),t.events.push(a.text),t.eventDetails.push(a)}}}function y(e,t,n){let r=[...e.matchAll(/:::([\w-]+)/g)].map(e=>e[1]);r.length&&d.addClasses(t,r,n)}l.length||m(s,`缺少时段`,`Expected a timeline period`);let b=l.reduce((e,t)=>e+1+t.events.length,0);b>2e3&&m(s,`时间线有 ${b} 个条目,超过 2000,请拆分`,`Timeline has ${b} entries (limit 2,000); split the diagram`);for(let e of l){e.status=d.statusOf(e.id),e.link=d.linkOf(e.id);for(let t of e.eventDetails)t.status=d.statusOf(t.id),t.link=d.linkOf(t.id)}let x=g(_.text,null,_.line);return v.title=a.title=x.text,v.titleIcon=x.icon,c.push(...d.diagnostics()),v.count=b,{model:v,errors:c}}function o(e,{width:t,ctx:n,measure:r,renderOptions:a}){let{design:o}=n,{items:s,config:c,sections:l}=e,u=e.direction===`TD`,d=(e,t,n)=>Number.isFinite(Number(e))?Math.max(n,Number(e)):t,f=d(c.leftMargin,24,24),p=d(c.padding,12,12),m={...i.FONT.body,size:d(c.taskFontSize,13,12)},h={...m,weight:600},g=m.size+5,_=l.reduce((e,t)=>e+(t.name||t.icon||t.items.length?Math.max(1,t.items.length):0),0),v=u?Math.max(184,p*2+100):Math.max(184,p*2+100,(t-f-24)/_),y=u?Math.max(204,t-f-v-76,p*2+100):v-2*p-14,b=u?f+v+y+76:f+v*_+24,x=[],S={width:b,height:0,title:e.title,children:x,...a?.frame?{heading:e.title||void 0}:{}},C=(e,t,r)=>x.push({...n.el(e,t),...r?{meta:r}:{}}),w=(e,t,r,i,a,o=`start`,s)=>x.push(n.text(t,r,e,{...i,fill:a,anchor:o,"dominant-baseline":`central`},s)),T=(e,t,n)=>(0,i.wrapText)(e,t,n,r),E=(e,t,n,r,i,a,o=g)=>e.forEach((e,s)=>w(e,t,n+s*o,r,i,a)),D=(e,t,n,r,i,a)=>C(`line`,{x1:e,y1:t,x2:n,y2:r,stroke:i,"stroke-width":2,...a?{"stroke-dasharray":`4 4`}:{}}),O=(e,t,r,i,a,o,s)=>({...n.el(`rect`,{x:e,y:t,width:r,height:i,fill:a,stroke:o,rx:6,"stroke-width":1.5}),...s?{meta:s}:{}}),k=e=>n.color(`tone${c.disableMulticolor?1:1+e%6}`),A=(e,t,r,i)=>{if(!e)return null;let[a,o,s,c]=e.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c),u=e.set!==`tabler`;return n.el(`g`,{transform:`translate(${t-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},e.elements.map(({tag:e,attrs:t})=>n.shape(e,t)))},j=(e,t)=>e&&o[e]||t,M=e.titleIcon?22:0,N=!a?.frame&&(e.title||e.titleIcon)?T(e.title,b-48-M,i.FONT.title):[];N.length&&e.titleIcon&&x.push(A(e.titleIcon,32,24,o.fg1)),E(N,24+M,24,i.FONT.title,o.fg1,`start`,20);let P=N.length?24+N.length*20:24,F=l.filter(e=>e.name||e.icon||e.items.length).map((e,t)=>({...e,index:t,width:u?b-f-24:Math.max(v,v*e.items.length)})),I=e=>T(e.name,e.width-2*p-(e.icon?22:0),i.FONT.body),L=s.map(e=>({label:T(e.text,v-2*p-12-(e.icon?22:0),h),events:e.events.map((t,n)=>T(t,y-(u?2*p:0)-(e.eventDetails[n].icon?22:0),m))})),R=new Map(s.map((e,t)=>[e,L[t]])),z=(e,t,r,i,a,s,c,l,u=!1)=>{let d=e.status?n.tint(o.bg,s,.12):o.bg,f=O(t,r,i,a,d,s,{kind:`node`,id:e.id}),m=t+p,h=e.icon?A(e.icon,m+8,r+p+g/2,s):null,_=e.icon?m+16+6:u?t+i/2:t+p,v=l.map((t,i)=>n.text(_,r+p+g/2+i*g,t,{...c,fill:o.fg1,anchor:u&&!e.icon?`middle`:`start`,"dominant-baseline":`central`}));e.link?x.push(n.link(e.link.href,[f,...h?[h]:[],...v],e.link)):x.push(f,...h?[h]:[],...v)};if(u){let e=f+v+12,t=x.length,r=[],a=P;for(let t of F){let s=a,c=k(t.index),l=t.name||t.icon?I(t):[];l.length&&(t.icon&&x.push(A(t.icon,f+p+8,a+14,c)),E(l,f+p+(t.icon?22:0),a+14,i.FONT.body,o.fg1),a+=l.length*g+12);for(let r of t.items){let{label:i,events:o}=R.get(r),s=i.length*g+2*p,l=o.reduce((e,t)=>e+t.length*g+2*p+8,0),u=a+s/2,d=j(r.status,t.name?c:k(r.index));D(e-22,u,e,u,d,!0),C(`circle`,{cx:e,cy:u,r:5,fill:d}),z(r,f,a,v-10,s,d,h,i);let _=a;for(let[t]of r.events.entries()){let i=r.eventDetails[t],a=o[t],s=a.length*g+2*p,c=j(i.status,n.color(`grid`));D(e+5,_+s/2,e+24,_+s/2,c,!0),z(i,e+24,_,y,s,c,m,a),_+=s+8}a+=Math.max(s,l)+12}if(l.length){let e=O(f-8,s,t.width+8,a-s,n.tint(o.bg,c,.08),`none`,{kind:`frame`,id:`section:${t.index}`});r.push(e)}a+=12}D(e,P,e,a-20,n.color(`grid`));let s=x.pop();x.splice(t,0,...r,s),S.height=a+8}else{let e=P+Math.max(0,...F.map(e=>e.name||e.icon?I(e).length*g+14:0))+8,t=e+18,r=Math.max(...L.map(e=>e.label.length))*g+2*p,a=Math.max(0,...L.map(e=>e.events.reduce((e,t)=>e+g*t.length+8,0)));S.height=t+r+a+32;let s=f;for(let e of F){let t=k(e.index);(e.name||e.icon)&&(C(`rect`,{x:s,y:P-8,width:e.width-5,height:S.height-P-6,fill:n.tint(o.bg,t,.08),stroke:`none`},{kind:`frame`,id:`section:${e.index}`}),e.icon&&x.push(A(e.icon,s+p+8,P+6,t)),E(I(e),s+p+(e.icon?22:0),P+6,i.FONT.body,o.fg1)),s+=e.width}D(f,e,b-24,e,n.color(`grid`)),s=f;for(let i of F)if(!i.items.length)s+=v;else for(let a of i.items){let{label:c,events:l}=R.get(a),u=j(a.status,k(i.name?i.index:a.index));C(`circle`,{cx:s+v/2,cy:e,r:5,fill:u}),z(a,s+6,t,v-16,r,u,h,c,!0);let d=t+r+15;for(let[e]of a.events.entries()){let t=a.eventDetails[e],r=l[e],i=j(t.status,u);C(`circle`,{cx:s+p+2,cy:d,r:2.5,fill:i});let c=r.map((e,r)=>n.text(s+p+14+(t.icon?22:0),d+r*g,e,{...m,fill:o.fg2,"dominant-baseline":`central`}));t.icon&&c.unshift(A(t.icon,s+p+14+8,d,i)),x.push(...t.link?[n.link(t.link.href,c,t.link)]:c),d+=r.length*g+8}s+=v}}let B=S.width>2*t||e.count>60?[(0,i.warning)(`LARGE_DIAGRAM`,n.lang,e.firstLine,`时间线较大,可滚动查看`,`Large timeline; scroll to view`,`可拆成多张时间线`,`Consider splitting the timeline`)]:[];return{width:S.width,height:S.height,scene:S,errors:B}}return e.implementations={timeline:{optionMode:`raw`,parse:a,layout:o,acceptsPresentation:!0,honoredConfig:[`timeline.leftMargin`,`timeline.taskFontSize`,`timeline.padding`,`timeline.disableMulticolor`]}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
2
+ `).entries()){let e=t+s,r=n.trim();if(!r||r.startsWith(`#`)||r.startsWith(`%%`)||d.accept(r,e))continue;let i=/^(title|section)(?:\s*:\s*|\s+)(.+)$/i.exec(r);if(i){if(i[1].toLowerCase()===`title`)_={text:i[2],line:e};else{let t=g(i[2],null,e);u.push({name:t.text,icon:t.icon,items:[]})}continue}let a=r.split(/\s*:(?=\s|$)/),o=a.shift();if(o.trim()){let t=`period:${l.length}`,n=g(o,t,e);n.events=[],n.eventDetails=[],y(o,t,e),n.index=l.length,l.push(n),u.at(-1).items.push(n)}if(!l.length)m(e,`事件前必须先声明时段`,`Declare a period before its events`);else{let t=l.at(-1);for(let n of a){let r=n.trim();if(!r)continue;let i=`${t.id}:event:${t.events.length}`,a=g(r,i,e);y(r,i,e),t.events.push(a.text),t.eventDetails.push(a)}}}function y(e,t,n){let r=[...e.matchAll(/:::([\w-]+)/g)].map(e=>e[1]);r.length&&d.addClasses(t,r,n)}l.length||m(s,`缺少时段`,`Expected a timeline period`);let b=l.reduce((e,t)=>e+1+t.events.length,0);b>2e3&&m(s,`时间线有 ${b} 个条目,超过 2000,请拆分`,`Timeline has ${b} entries (limit 2,000); split the diagram`);for(let e of l){e.status=d.statusOf(e.id),e.link=d.linkOf(e.id);for(let t of e.eventDetails)t.status=d.statusOf(t.id),t.link=d.linkOf(t.id)}let x=g(_.text,null,_.line);return v.title=a.title=x.text,v.titleIcon=x.icon,c.push(...d.diagnostics()),v.count=b,{model:v,errors:c}}function o(e,{width:t,ctx:n,measure:r,renderOptions:a,compact:o,embedHeading:s}){let{design:c}=n,{items:l,config:u,sections:d}=e,f=e.direction===`TD`,p=(e,t,n)=>Number.isFinite(Number(e))?Math.max(n,Number(e)):t,m=p(u.leftMargin,24,24),h=p(u.padding,12,12),g={...i.FONT.body,size:p(u.taskFontSize,13,12)},_={...g,weight:600},v=g.size+5,y=d.reduce((e,t)=>e+(t.name||t.icon||t.items.length?Math.max(1,t.items.length):0),0),b=f?Math.max(184,h*2+100):Math.max(184,h*2+100,o?0:(t-m-24)/y),x=f?Math.max(204,o?0:t-m-b-76,h*2+100):b-2*h-14,S=f?m+b+x+76:m+b*y+24,C=[],w={width:S,height:0,title:e.title,children:C,...a?.frame||s?{heading:e.title||void 0}:{}},T=(e,t,r)=>C.push({...n.el(e,t),...r?{meta:r}:{}}),E=(e,t,r,i,a,o=`start`,s)=>C.push(n.text(t,r,e,{...i,fill:a,anchor:o,"dominant-baseline":`central`},s)),D=(e,t,n)=>(0,i.wrapText)(e,t,n,r),O=(e,t,n,r,i,a,o=v)=>e.forEach((e,s)=>E(e,t,n+s*o,r,i,a)),k=(e,t,n,r,i,a)=>T(`line`,{x1:e,y1:t,x2:n,y2:r,stroke:i,"stroke-width":2,...a?{"stroke-dasharray":`4 4`}:{}}),A=(e,t,r,i,a,o,s)=>({...n.el(`rect`,{x:e,y:t,width:r,height:i,fill:a,stroke:o,rx:6,"stroke-width":1.5}),...s?{meta:s}:{}}),j=e=>n.color(`tone${u.disableMulticolor?1:1+e%6}`),M=(e,t,r,i)=>{if(!e)return null;let[a,o,s,c]=e.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c),u=e.set!==`tabler`;return n.el(`g`,{transform:`translate(${t-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},e.elements.map(({tag:e,attrs:t})=>n.shape(e,t)))},N=(e,t)=>e&&c[e]||t,P=e.titleIcon?22:0,F=!a?.frame&&!s&&(e.title||e.titleIcon)?D(e.title,S-48-P,i.FONT.title):[];F.length&&e.titleIcon&&C.push(M(e.titleIcon,32,24,c.fg1)),O(F,24+P,24,i.FONT.title,c.fg1,`start`,20);let I=F.length?24+F.length*20:24,L=d.filter(e=>e.name||e.icon||e.items.length).map((e,t)=>({...e,index:t,width:f?S-m-24:Math.max(b,b*e.items.length)})),R=e=>D(e.name,e.width-2*h-(e.icon?22:0),i.FONT.body),z=l.map(e=>({label:D(e.text,b-2*h-12-(e.icon?22:0),_),events:e.events.map((t,n)=>D(t,x-(f?2*h:0)-(e.eventDetails[n].icon?22:0),g))})),B=new Map(l.map((e,t)=>[e,z[t]])),V=(e,t,r,i,a,o,s,l,u=!1)=>{let d=e.status?n.tint(c.bg,o,.12):c.bg,f=A(t,r,i,a,d,o,{kind:`node`,id:e.id}),p=t+h,m=e.icon?M(e.icon,p+8,r+h+v/2,o):null,g=e.icon?p+16+6:u?t+i/2:t+h,_=l.map((t,i)=>n.text(g,r+h+v/2+i*v,t,{...s,fill:c.fg1,anchor:u&&!e.icon?`middle`:`start`,"dominant-baseline":`central`}));e.link?C.push(n.link(e.link.href,[f,...m?[m]:[],..._],e.link)):C.push(f,...m?[m]:[],..._)};if(f){let e=m+b+12,t=C.length,r=[],a=I;for(let t of L){let o=a,s=j(t.index),l=t.name||t.icon?R(t):[];l.length&&(t.icon&&C.push(M(t.icon,m+h+8,a+14,s)),O(l,m+h+(t.icon?22:0),a+14,i.FONT.body,c.fg1),a+=l.length*v+12);for(let r of t.items){let{label:i,events:o}=B.get(r),c=i.length*v+2*h,l=o.reduce((e,t)=>e+t.length*v+2*h+8,0),u=a+c/2,d=N(r.status,t.name?s:j(r.index));k(e-22,u,e,u,d,!0),T(`circle`,{cx:e,cy:u,r:5,fill:d}),V(r,m,a,b-10,c,d,_,i);let f=a;for(let[t]of r.events.entries()){let i=r.eventDetails[t],a=o[t],s=a.length*v+2*h,c=N(i.status,n.color(`grid`));k(e+5,f+s/2,e+24,f+s/2,c,!0),V(i,e+24,f,x,s,c,g,a),f+=s+8}a+=Math.max(c,l)+12}if(l.length){let e=A(m-8,o,t.width+8,a-o,n.tint(c.bg,s,.08),`none`,{kind:`frame`,id:`section:${t.index}`});r.push(e)}a+=12}k(e,I,e,a-20,n.color(`grid`));let o=C.pop();C.splice(t,0,...r,o),w.height=a+8}else{let e=I+Math.max(0,...L.map(e=>e.name||e.icon?R(e).length*v+14:0))+8,t=e+18,r=Math.max(...z.map(e=>e.label.length))*v+2*h,a=Math.max(0,...z.map(e=>e.events.reduce((e,t)=>e+v*t.length+8,0)));w.height=t+r+a+32;let o=m;for(let e of L){let t=j(e.index);(e.name||e.icon)&&(T(`rect`,{x:o,y:I-8,width:e.width-5,height:w.height-I-6,fill:n.tint(c.bg,t,.08),stroke:`none`},{kind:`frame`,id:`section:${e.index}`}),e.icon&&C.push(M(e.icon,o+h+8,I+6,t)),O(R(e),o+h+(e.icon?22:0),I+6,i.FONT.body,c.fg1)),o+=e.width}k(m,e,S-24,e,n.color(`grid`)),o=m;for(let i of L)if(!i.items.length)o+=b;else for(let a of i.items){let{label:s,events:l}=B.get(a),u=N(a.status,j(i.name?i.index:a.index));T(`circle`,{cx:o+b/2,cy:e,r:5,fill:u}),V(a,o+6,t,b-16,r,u,_,s,!0);let d=t+r+15;for(let[e]of a.events.entries()){let t=a.eventDetails[e],r=l[e],i=N(t.status,u);T(`circle`,{cx:o+h+2,cy:d,r:2.5,fill:i});let s=r.map((e,r)=>n.text(o+h+14+(t.icon?22:0),d+r*v,e,{...g,fill:c.fg2,"dominant-baseline":`central`}));t.icon&&s.unshift(M(t.icon,o+h+14+8,d,i)),C.push(...t.link?[n.link(t.link.href,s,t.link)]:s),d+=r.length*v+8}o+=b}}let H=w.width>2*t||e.count>60?[(0,i.warning)(`LARGE_DIAGRAM`,n.lang,e.firstLine,`时间线较大,可滚动查看`,`Large timeline; scroll to view`,`可拆成多张时间线`,`Consider splitting the timeline`)]:[];return{width:w.width,height:w.height,scene:w,errors:H}}return e.implementations={timeline:{optionMode:`raw`,parse:a,layout:o,acceptsPresentation:!0,honoredConfig:[`timeline.leftMargin`,`timeline.taskFontSize`,`timeline.padding`,`timeline.disableMulticolor`]}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
@@ -1,2 +1,2 @@
1
1
  KChartUnits["diagram/treeview"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=[`rowIndent`,`paddingX`,`paddingY`,`lineThickness`,`showIcons`,`filenameIcons`,`extensionIcons`].map(e=>`treeView.${e}`),s=(e,t,n,r)=>typeof e==`number`&&Number.isFinite(e)?Math.max(n,Math.min(r,e)):t,c=/^([ \t│┃]*)(?:[├└┣┗])[─━]*[ \t]*/,l=/[ \t]+(?=:::[ \t]*[A-Za-z_]|icon\(|##)/,u=/^(?:\p{Emoji_Presentation}|\p{Extended_Pictographic}\uFE0F|[0-9#*]\uFE0F?\u20E3)/u,d=24,f=24,p=e=>e.replaceAll(` `,` `).length;function m(e,{firstLine:a=2,headerLine:o=1,lang:s,params:d,config:f}){let m=[],h=[{id:`root`,label:`/`,directory:!0,depth:0,description:``}],g=(0,r.presentation)({lang:s}),_=f?.treeView??{},v=new Set,y=e=>{v.has(e.message)||(v.add(e.message),m.push(e))},b=(e,t)=>{let r=(0,n.normalizeLabel)(e,{lang:s,line:t});return r.diagnostics.forEach(y),r},x=String(e).split(`
2
- `).map((e,t)=>({raw:e,line:a+t})).filter(({raw:e,line:t})=>e.trim()&&!e.trimStart().startsWith(`%%`)&&!g.accept(e,t)),S=x.map(({raw:e})=>e.match(c)).find(e=>e&&p(e[1]))?.[1],C=x.some(({raw:e})=>c.test(e)),w=[],T,E=(e,n,r)=>m.push((0,t.error)(s,e,n,r,`检查树节点声明`,`Check the tree node declaration`));d?.trim()&&E(o,`树视图表头不接受参数`,`Tree view header takes no parameters`);for(let{raw:e,line:n}of x){let r=e.trim(),a=r.match(/^title(?:\s*:\s*|\s+)(.*)/i);if(a){T=b(a[1],n).text;continue}let o=C?e.match(c):null;if(C&&/^[\s│┃]+$/.test(e))continue;if(C&&!o&&/^[ \t│┃]/.test(e)){E(n,`缩进缺少树线前缀`,`Unexpected indentation without box-drawing characters`);continue}if(o&&!e.slice(o[0].length).trim()){E(n,`树线后缺少文件或目录名`,`Empty node: expected a filename or directory name after the box-drawing prefix`);continue}let d=o?Math.round(p(o[1])/(S?p(S):4))+1:p(e.match(/^[ \t]*/)[0]),f=o?e.slice(o[0].length).trim():r,m=f.match(/^(?:"([^"]*)"|'([^']*)')/),v=f.search(l),x=m?m[1]??m[2]:(v<0?f:f.slice(0,v)).trimEnd();f=m?f.slice(m[0].length).trimStart():v<0?``:f.slice(v).trimStart();let D=``,O=!1,k,A=b(x,n),j=A.text.endsWith(`/`),M=j&&A.text!==`/`?A.text.slice(0,-1):A.text;for(;f;){let e=f.match(/^:::[ \t]*([A-Za-z_][\w-]*)/),t=f.match(/^icon\(([\w-]*(?::[\w-]+)?)\)/);if(f.startsWith(`##`)){D=b(f.slice(2),n).text;break}if(e)e[1]===`highlight`?O=!0:g.addClasses(M,[e[1]],n);else if(t)k=t[1]||`none`;else{E(n,`无法识别树节点注解`,`Unrecognized tree node annotation`);break}f=f.slice((e||t)[0].length).trimStart()}for(;w.length&&d<=w.at(-1).indent;)w.pop();let N=/\.[^.\/]+$/.exec(M)?.[0],P=_.filenameIcons?.[M]??(!j&&N?_.extensionIcons?.[N]:void 0),F=k??(A.icon?void 0:typeof P==`string`?P:void 0),I=u.test(M)?null:(0,i.resolveIconRef)(j?`tabler:folder`:`tabler:file`),L=A.icon??I;F===`none`?L=null:F&&(L=(0,i.resolveIconRef)(F),L||=(y((0,t.warning)(`IGNORED_ASSET`,s,n,`未知图标 ${F}`,`Unknown icon ${F}`,`使用内置或已注册的图标`,`Use a built-in or registered icon`)),I));let R={id:`row-${n}`,parent:w.at(-1)?.id??`root`,depth:w.length+1,indent:d,line:n,directory:j,label:M,description:D,highlight:O,icon:k,glyph:_.showIcons===!1?null:L};if(h.push(R),w.push(R),h.length>2001){E(n,`树节点最多支持 2000 个`,`Tree view supports at most 2,000 entries`);break}}return h[0].glyph=_.showIcons===!1?null:(0,i.resolveIconRef)(`tabler:folder`),h.forEach((e,t)=>{e.status=g.statusOf(e.label),e.link=g.linkOf(e.label),t&&(e.edgeStatus=g.edgeStatusOf(t-1))}),{model:{rows:h,title:T,headerLine:o,settings:_},errors:[...m,...g.diagnostics()]}}function h(e,{width:n,measure:r,lang:i}){let a=Math.max(120,n-48),{settings:o}=e,c=s(s(o.rowIndent,10,4,90)+s(o.paddingX,14,4,24),f,12,96),l=s(o.paddingY,4,4,20),u=s(o.lineThickness,1,1,3),p,m;for(let i of[220,190,160,140,120])if(p=e.rows.map(e=>{let n={...t.FONT.body,weight:e.directory?650:400},a=(0,t.wrapText)(e.label,i,n,r),o=e.description?(0,t.wrapText)(e.description,240,t.FONT.label,r):[],s=d+c*e.depth,l=s+(e.glyph?20:0);return{...e,font:n,lines:a,notes:o,x:s,textX:l,labelEnd:l+(0,t.maxWidthOf)(a,n,r)}}),m=Math.max(...p.map(e=>e.labelEnd)),m+d<=n)break;let h=Math.max(0,...p.map(e=>(0,t.maxWidthOf)(e.notes,t.FONT.label,r))),g=!h||m+16+h+d<=n+240,_=e.title?(0,t.wrapText)(e.title,a,t.FONT.title,r):[],v=d+(_.length?_.length*19+12:0),y=Math.max(m,d+(0,t.maxWidthOf)(_,t.FONT.title,r));for(let e of p){let n=e.lines.length*17,i=e.notes.length*16;e.top=v,e.h=Math.max(24,(g?Math.max(n,i):n+(i?i+4:0))+l*2),e.labelY=g?v+e.h/2:v+l+n/2,e.noteY=g?e.labelY:v+l+4+n+i/2,e.noteX=g?m+16:e.x,i&&(y=Math.max(y,e.noteX+(0,t.maxWidthOf)(e.notes,t.FONT.label,r))),v+=e.h}let b=Math.ceil(y+d+8),x=p.length>61||b>n*2?[(0,t.warning)(`LARGE_DIAGRAM`,i,e.headerLine,`树视图较大`,`This tree view is large`,`考虑拆分为多个树视图`,`Consider splitting it into smaller trees`)]:[];return{rows:p,title:_,width:b,height:v+d,right:y,lineThickness:u,errors:x}}function g(e,n){let r=(0,t.appearance)(n),{rows:i,right:o}=e,s=new Map(i.map(e=>[e.id,e])),c=new Map,l=[],u=[];for(let d of i){let i=s.get(d.parent);if(i){let t=i.x+4,a=c.get(i.id)??i.top+i.h,o=d.labelY;l.push(n.path(`M${t} ${a} V${o-2} Q${t} ${o} ${t+2} ${o} H${d.x-5}`,{fill:`none`,stroke:d.edgeStatus?n.frameTone(r[d.edgeStatus]):r.fg4,"stroke-width":e.lineThickness,meta:{kind:`edge`,from:i.id,to:d.id}})),c.set(i.id,o)}let f=d.x-3,p=d.top+1,m=d.h-2,h=r[d.status]??(d.highlight?r.warn:null),g=[n.rect(f,p,(h?o+8:d.labelEnd+3)-f,m,{fill:h?n.tint(r.bg,h,.12):`none`,...h?{stroke:n.frameTone(h),rx:3}:{},meta:{kind:`node`,id:d.id}})];d.glyph&&g.push((0,a.labelIcon)(n,d.glyph,d.x+7,d.labelY,14,r.fg3)),g.push((0,t.textBlock)(n,{x:d.textX,y:d.labelY,lines:d.lines,font:d.font,anchor:`start`,lineHeight:17,fill:d.parent?r.fg1:n.color(`muted`)})),u.push(...d.link?[n.link(d.link.href,g,d.link)]:g),d.notes.length&&u.push((0,t.textBlock)(n,{x:d.noteX,y:d.noteY,lines:d.notes,font:t.FONT.label,anchor:`start`,lineHeight:16,fill:n.color(`muted`)}))}return e.title.length&&u.push((0,t.textBlock)(n,{x:d,y:d+e.title.length*19/2,lines:e.title,font:t.FONT.title,anchor:`start`,lineHeight:19})),{width:e.width,height:e.height,children:[...l,...u]}}return e.implementations={"treeView-beta":{optionMode:`raw`,acceptsPresentation:!0,honoredConfig:o,parse:m,layout:h,scene:g}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`core/icons`],KChartUnits[`diagram/tree-family-icon`]);
2
+ `).map((e,t)=>({raw:e,line:a+t})).filter(({raw:e,line:t})=>e.trim()&&!e.trimStart().startsWith(`%%`)&&!g.accept(e,t)),S=x.map(({raw:e})=>e.match(c)).find(e=>e&&p(e[1]))?.[1],C=x.some(({raw:e})=>c.test(e)),w=[],T,E=(e,n,r)=>m.push((0,t.error)(s,e,n,r,`检查树节点声明`,`Check the tree node declaration`));d?.trim()&&E(o,`树视图表头不接受参数`,`Tree view header takes no parameters`);for(let{raw:e,line:n}of x){let r=e.trim(),a=r.match(/^title(?:\s*:\s*|\s+)(.*)/i);if(a){T=b(a[1],n).text;continue}let o=C?e.match(c):null;if(C&&/^[\s│┃]+$/.test(e))continue;if(C&&!o&&/^[ \t│┃]/.test(e)){E(n,`缩进缺少树线前缀`,`Unexpected indentation without box-drawing characters`);continue}if(o&&!e.slice(o[0].length).trim()){E(n,`树线后缺少文件或目录名`,`Empty node: expected a filename or directory name after the box-drawing prefix`);continue}let d=o?Math.round(p(o[1])/(S?p(S):4))+1:p(e.match(/^[ \t]*/)[0]),f=o?e.slice(o[0].length).trim():r,m=f.match(/^(?:"([^"]*)"|'([^']*)')/),v=f.search(l),x=m?m[1]??m[2]:(v<0?f:f.slice(0,v)).trimEnd();f=m?f.slice(m[0].length).trimStart():v<0?``:f.slice(v).trimStart();let D=``,O=!1,k,A=b(x,n),j=A.text.endsWith(`/`),M=j&&A.text!==`/`?A.text.slice(0,-1):A.text;for(;f;){let e=f.match(/^:::[ \t]*([A-Za-z_][\w-]*)/),t=f.match(/^icon\(([\w-]*(?::[\w-]+)?)\)/);if(f.startsWith(`##`)){D=b(f.slice(2),n).text;break}if(e)e[1]===`highlight`?O=!0:g.addClasses(M,[e[1]],n);else if(t)k=t[1]||`none`;else{E(n,`无法识别树节点注解`,`Unrecognized tree node annotation`);break}f=f.slice((e||t)[0].length).trimStart()}for(;w.length&&d<=w.at(-1).indent;)w.pop();let N=/\.[^.\/]+$/.exec(M)?.[0],P=_.filenameIcons?.[M]??(!j&&N?_.extensionIcons?.[N]:void 0),F=k??(A.icon?void 0:typeof P==`string`?P:void 0),I=u.test(M)?null:(0,i.resolveIconRef)(j?`tabler:folder`:`tabler:file`),L=A.icon??I;F===`none`?L=null:F&&(L=(0,i.resolveIconRef)(F),L||=(y((0,t.warning)(`IGNORED_ASSET`,s,n,`未知图标 ${F}`,`Unknown icon ${F}`,`使用内置或已注册的图标`,`Use a built-in or registered icon`)),I));let R={id:`row-${n}`,parent:w.at(-1)?.id??`root`,depth:w.length+1,indent:d,line:n,directory:j,label:M,description:D,highlight:O,icon:k,glyph:_.showIcons===!1?null:L};if(h.push(R),w.push(R),h.length>2001){E(n,`树节点最多支持 2000 个`,`Tree view supports at most 2,000 entries`);break}}return h[0].glyph=_.showIcons===!1?null:(0,i.resolveIconRef)(`tabler:folder`),h.forEach((e,t)=>{e.status=g.statusOf(e.label),e.link=g.linkOf(e.label),t&&(e.edgeStatus=g.edgeStatusOf(t-1))}),{model:{rows:h,title:T,headerLine:o,settings:_},errors:[...m,...g.diagnostics()]}}function h(e,{width:n,measure:r,lang:i,embedHeading:a}){let o=Math.max(120,n-48),{settings:c}=e,l=s(s(c.rowIndent,10,4,90)+s(c.paddingX,14,4,24),f,12,96),u=s(c.paddingY,4,4,20),p=s(c.lineThickness,1,1,3),m,h;for(let i of[220,190,160,140,120])if(m=e.rows.map(e=>{let n={...t.FONT.body,weight:e.directory?650:400},a=(0,t.wrapText)(e.label,i,n,r),o=e.description?(0,t.wrapText)(e.description,240,t.FONT.label,r):[],s=d+l*e.depth,c=s+(e.glyph?20:0);return{...e,font:n,lines:a,notes:o,x:s,textX:c,labelEnd:c+(0,t.maxWidthOf)(a,n,r)}}),h=Math.max(...m.map(e=>e.labelEnd)),h+d<=n)break;let g=Math.max(0,...m.map(e=>(0,t.maxWidthOf)(e.notes,t.FONT.label,r))),_=!g||h+16+g+d<=n+240,v=!a&&e.title?(0,t.wrapText)(e.title,o,t.FONT.title,r):[],y=d+(v.length?v.length*19+12:0),b=Math.max(h,d+(0,t.maxWidthOf)(v,t.FONT.title,r));for(let e of m){let n=e.lines.length*17,i=e.notes.length*16;e.top=y,e.h=Math.max(24,(_?Math.max(n,i):n+(i?i+4:0))+u*2),e.labelY=_?y+e.h/2:y+u+n/2,e.noteY=_?e.labelY:y+u+4+n+i/2,e.noteX=_?h+16:e.x,i&&(b=Math.max(b,e.noteX+(0,t.maxWidthOf)(e.notes,t.FONT.label,r))),y+=e.h}let x=Math.ceil(b+d+8),S=m.length>61||x>n*2?[(0,t.warning)(`LARGE_DIAGRAM`,i,e.headerLine,`树视图较大`,`This tree view is large`,`考虑拆分为多个树视图`,`Consider splitting it into smaller trees`)]:[];return{rows:m,title:v,...a?{heading:e.title}:{},width:x,height:y+d,right:b,lineThickness:p,errors:S}}function g(e,n){let r=(0,t.appearance)(n),{rows:i,right:o}=e,s=new Map(i.map(e=>[e.id,e])),c=new Map,l=[],u=[];for(let d of i){let i=s.get(d.parent);if(i){let t=i.x+4,a=c.get(i.id)??i.top+i.h,o=d.labelY;l.push(n.path(`M${t} ${a} V${o-2} Q${t} ${o} ${t+2} ${o} H${d.x-5}`,{fill:`none`,stroke:d.edgeStatus?n.frameTone(r[d.edgeStatus]):r.fg4,"stroke-width":e.lineThickness,meta:{kind:`edge`,from:i.id,to:d.id}})),c.set(i.id,o)}let f=d.x-3,p=d.top+1,m=d.h-2,h=r[d.status]??(d.highlight?r.warn:null),g=[n.rect(f,p,(h?o+8:d.labelEnd+3)-f,m,{fill:h?n.tint(r.bg,h,.12):`none`,...h?{stroke:n.frameTone(h),rx:3}:{},meta:{kind:`node`,id:d.id}})];d.glyph&&g.push((0,a.labelIcon)(n,d.glyph,d.x+7,d.labelY,14,r.fg3)),g.push((0,t.textBlock)(n,{x:d.textX,y:d.labelY,lines:d.lines,font:d.font,anchor:`start`,lineHeight:17,fill:d.parent?r.fg1:n.color(`muted`)})),u.push(...d.link?[n.link(d.link.href,g,d.link)]:g),d.notes.length&&u.push((0,t.textBlock)(n,{x:d.noteX,y:d.noteY,lines:d.notes,font:t.FONT.label,anchor:`start`,lineHeight:16,fill:n.color(`muted`)}))}return e.title.length&&u.push((0,t.textBlock)(n,{x:d,y:d+e.title.length*19/2,lines:e.title,font:t.FONT.title,anchor:`start`,lineHeight:19})),{width:e.width,height:e.height,children:[...l,...u],...e.heading?{heading:e.heading}:{}}}return e.implementations={"treeView-beta":{optionMode:`raw`,acceptsPresentation:!0,honoredConfig:o,parse:m,layout:h,scene:g}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`core/icons`],KChartUnits[`diagram/tree-family-icon`]);
@@ -1,2 +1,2 @@
1
- KChartUnits["diagram/venn"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=24,o=20,s=12,c=18,l=16,u=4,d=12,f=10,p=4,m=2,h=26,g=28,_=8,v=14,y=16,b=168,x=3,S=12,C=10,w=1.5,T=17,E=1.12,D=6,O=460,ee=60,k=3,A=.55,te=.55,j={size:t.FONT.title.size,weight:t.FONT.title.weight},M={size:t.FONT.title.size,weight:t.FONT.title.weight},N={size:t.FONT.label.size,weight:t.FONT.label.weight};function P(e){let t=!1;for(let n=0;n<e.length;n+=1)if(e[n]===`"`)t=!t;else if(!t&&e[n]===`%`&&e[n+1]===`%`)return e.slice(0,n);return e}var F=/^"([^"]*)"|^([A-Za-z_][\w-]*)/,I=/^[ \t]*/;function L(e,t){let n=t+I.exec(e.slice(t))[0].length,r=F.exec(e.slice(n));return r?{id:r[1]??r[2],at:n+r[0].length}:null}function R(e){let t=/^[A-Za-z][\w-]*/.exec(e);return t?{word:t[0].toLowerCase(),at:t[0].length}:{word:``,at:0}}function z(e,t){let n=[],r=t;for(;;){let t=L(e,r);if(!t||/^\s*:/.test(e.slice(t.at)))break;n.push(t.id);let i=t.at+I.exec(e.slice(t.at))[0].length;if(e[i]!==`,`){r=t.at;break}r=i+1}let i=n.length?r:t;return{ids:n,at:i+I.exec(e.slice(i))[0].length}}function B(e,t){let n=/^\[([^\]]*)\]/.exec(e.slice(t));if(!n)return{label:null,at:t};let r=n[1];return r.length>=2&&r.startsWith(`"`)&&r.endsWith(`"`)&&(r=r.slice(1,-1)),{label:r.trim(),at:t+n[0].length}}function V(e,t){let n=/^:\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))/.exec(e.slice(t));return n?{size:Number(n[1]),at:t+n[0].length}:{size:null,at:t}}function ne(e,i={}){let a=i.lang||`zh`,o=Number.isInteger(i.firstLine)?i.firstLine:2,s=Number.isInteger(i.headerLine)?i.headerLine:Math.max(1,o-1),c=[],l=(0,r.presentation)({lang:a}),u=new Set,d=[],f=[],p=[],m=new Map,h=``,g=s,_=null,v=!1,y=(e,n,r,i,o)=>c.push((0,t.error)(a,e,n,r,i,o)),b=e=>y(e,`无法识别这一行`,`Unrecognized line`,`使用 set、union、text、title 或 style`,`Use set, union, text, title, or style`),x=e=>y(e,`text 前缺少 set 或 union`,`A text line needs an owning set or union`,`把 text 缩进到 set/union 下面,或先写集合 id`,`Indent text under a set/union, or name the set first`),S=typeof i.params==`string`?i.params.trim():``;S&&y(s,`venn-beta 头行不能带内容「${S}」`,`Unexpected text after "venn-beta": ${S}`,`把内容写成 set、union 或 text 行`,`Move the text into set, union, or text lines`);for(let e of Object.keys(i.options||{}))y(s,`venn-beta 不支持选项「${e}」`,`Unsupported venn-beta option: ${e}`,`删除这个选项`,`Remove this option`);let w=(e,t)=>{let r=(0,n.normalizeLabel)(e,{lang:a,line:t});for(let e of r.diagnostics){let t=`${e.code}:${e.message}`;u.has(t)||(u.add(t),c.push(e))}return{text:r.text,icon:r.icon}},T=(e,t,n,r)=>{if(!e)return b(r),!1;if(m.has(e))return y(r,`集合「${e}」重复定义`,`Duplicate set identifier: ${e}`,`把同一个集合合并成一行 set`,`Merge the duplicate into a single set line`),!1;let i=t?w(t,r):{text:``,icon:null};return d.push({id:e,label:i.text,icon:i.icon,size:n??C,tone:d.length%6+1,line:r}),m.set(e,d.at(-1)),_={ids:[e]},!0},E=(e,t,n,r)=>{let i=e.filter((t,n)=>e.indexOf(t)===n);if(i.length<2)return y(r,`union 至少需要两个集合`,`A union needs at least two sets`,`写成 union A,B 或列更多集合`,`Write union A,B or list more sets`),!1;let a=i.filter(e=>!m.has(e));if(a.length)return y(r,`union 引用了未定义的集合「${a.join(`、`)}」`,`Unknown set identifier: ${a.join(`, `)}`,`先用 set 声明集合,再写 union`,`Declare each set with set before the union`),!1;let o=[...i].sort(),s=t?w(t,r):{text:``,icon:null};return f.push({ids:o,label:s.text,icon:s.icon,size:n??C/i.length**2,line:r}),_={ids:o},!0},D=(e,t,n,r)=>{let i=n.filter((e,t)=>n.indexOf(e)===t);if(!i.length){x(r);return}let a=w(t||e,r);p.push({id:e,label:a.text,icon:a.icon,ids:[...i].sort(),key:[...i].sort().join(`|`),line:r})};for(let[t,n]of String(e??``).split(`
2
- `).entries()){let e=o+t,r=P(n).trim();if(!r)continue;let i=/^[ \t]/.test(n),a=/^style\s+/i.exec(r);if(a){let t=z(r,a[0].length);if(t.ids.length>1){l.accept(`style ${JSON.stringify([...t.ids].sort().join(`|`))} ${r.slice(t.at).trimStart()}`,e);continue}}if(l.accept(r,e))continue;let s=R(r),c=r.slice(s.at);if(v&&i&&s.word===`text`){let t=L(c,0),n=B(c,t?t.at:0);if(!t||c.slice(n.at).trim()){b(e);continue}_?D(t.id,n.label,_.ids,e):x(e)}else if(i||(v=!1),s.word===`title`){let t=c.trim();if(!t){y(e,`title 后面缺少标题文字`,`title needs a heading after it`,`写成 title 标题文字`,`Write title followed by the heading`);continue}h=w(t.replace(/^"(.*)"$/,`$1`).trim(),e).text,g=e}else if(s.word===`set`){let t=L(c,0);if(!t){b(e);continue}let n=B(c,t.at),r=V(c,n.at);if(c.slice(r.at).trim()){b(e);continue}T(t.id,n.label,r.size,e)&&(v=!0)}else if(s.word===`union`){let t=z(c,0),n=B(c,t.at),r=V(c,n.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}E(t.ids,n.label,r.size,e)&&(v=!0)}else if(s.word===`text`){let t=z(c,0),n=L(c,t.at),r=B(c,n?n.at:t.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}n?D(n.id,r.label,t.ids,e):D(t.ids[0],r.label,_?_.ids:[],e)}else b(e)}c.push(...l.diagnostics()),d.length||y(o,`文氏图没有任何 set`,`A Venn diagram needs at least one set`,`至少写一行 set`,`Write at least one set line`);let O=(e,t)=>({...e,status:l.statusOf(t),link:l.linkOf(t)});for(let e of d)Object.assign(e,O({},e.id));for(let e of f)Object.assign(e,O({},e.ids.join(`|`)));for(let e of p)Object.assign(e,O({},e.id));return{model:{kind:`venn-beta`,title:h,titleLine:g,sets:d,unions:f,texts:p},errors:c}}function H(e,t,n,r){let i=1/0;for(let r of n)i=Math.min(i,r.r-Math.hypot(e-r.cx,t-r.cy));for(let n of r)i=Math.min(i,Math.hypot(e-n.cx,t-n.cy)-n.r);return i}function U(e,t,n=3,r=16){let i=e.reduce((e,t)=>e+t.cx,0)/e.length,a=e.reduce((e,t)=>e+t.cy,0)/e.length,o={x:i,y:a,value:H(i,a,e,t)},s=Math.max(...e.map(e=>e.r));for(let i=0;i<n;i+=1){let n=o;for(let i=-r/2;i<=r/2;i+=1)for(let c=-r/2;c<=r/2;c+=1){let l=n.x+i*s/(r/2),u=n.y+c*s/(r/2),d=H(l,u,e,t);(d>o.value+1e-9||Math.abs(d-o.value)<=1e-9&&Math.abs(u-a)<Math.abs(o.y-a)-1e-9)&&(o={x:l,y:u,value:d})}s/=r/4}return o}function W(e,t){let n=e.map(e=>Number.isFinite(e.size)?Math.max(0,e.size):C),r=Math.max(0,...n);return n.map(e=>t*(r>0?Math.max(.3,Math.sqrt(e/r)):1))}function G(e,t,n){let r=W(e,t),i=e.map((e,t)=>({id:e.id,label:e.label,icon:e.icon,tone:e.tone,status:e.status,link:e.link,line:e.line,r:r[t],cx:0,cy:0}));if(i.length===1)return i;if(i.length===2){let e=Math.min(r[0],r[1]),t=Math.abs(r[0]-r[1])+.25*e,a=r[0]+r[1]-.1*e,o=t+Math.min(1,Math.max(0,n))*(a-t);return i[0].cx=-o/2,i[1].cx=o/2,i}let a=i.map((e,t)=>({index:t,r:e.r})).sort((e,t)=>t.r-e.r||t.index-e.index)[0].index,o=[0,1,2].filter(e=>e!==a).sort((e,t)=>e-t),s=(te+Math.min(1,Math.max(0,n))*.7)*(r.reduce((e,t)=>e+t,0)/3),c=[];return c[a]=-Math.PI/2,c[o[0]]=5*Math.PI/6,c[o[1]]=Math.PI/6,i.forEach((e,t)=>{e.cx=Math.cos(c[t])*s,e.cy=Math.sin(c[t])*s}),i}function K(e,t){if(e.length<=1)return .5;let n=W(e,t);if(e.length===2){let e=Math.min(n[0],n[1]),t=Math.abs(n[0]-n[1])+.25*e,r=n[0]+n[1]-.1*e;return r>t?Math.min(1,Math.max(0,(n[0]+n[1]-A*e-t)/(r-t))):.5}return .44999999999999996/.7}function q(e){let t=Math.min(...e.map(e=>e.cx-e.r)),n=Math.max(...e.map(e=>e.cx+e.r)),r=Math.min(...e.map(e=>e.cy-e.r)),i=Math.max(...e.map(e=>e.cy+e.r));return{x:t,y:r,w:n-t,h:i-r}}function J(e,n){let r=e.kind===`set`?d:f,i=e.kind===`set`?0:14,a=[...e.labels.map(e=>e.text),...e.items.map(e=>e.text)],o=e.kind===`set`?M:N,s=Math.max(0,...a.flatMap(e=>String(e).split(/\s+/).filter(Boolean).map(e=>n(e,o)))),m=Math.max(48,s+2,(e.clear-r)*2-20-i),h=(e,r)=>(0,t.wrapText)(e,m,r,(e,t)=>n(e,t)),g=e.kind===`set`?M:N,_=[];for(let t of e.labels)for(let e of h(t.text,g))_.push({text:e,font:g,icon:t.icon,link:t.link});let v=[];for(let t of e.items)for(let e of h(t.text,N))v.push({text:e,font:N,icon:t.icon,link:t.link,status:t.status});let y=e=>e.length?Math.max(...e.map(e=>n(e.text,e.font)+(e.icon?18:0))):0,b=_.length?y(_)+i:0,x=_.length*((e.kind===`set`?c:l)+4/_.length),S=y(v),C=v.length*l,w=Math.max(b,S),T=x+(v.length?(_.length?u:0)+C:0),E={labels:_,items:v,slack:r,pad:i,labelW:b,labelH:x,itemW:S,itemH:C,w,h:T,chip:e.kind!==`set`&&_.length>0};return E.room=T?Y(e,w,T)-p:1/0,E.fits=E.room>=-.5,E}function Y(e,t,n){let r=1/0;for(let[i,a]of[[-1,-1],[1,-1],[1,1],[-1,1],[0,-1],[1,0],[0,1],[-1,0]])r=Math.min(r,H(e.x+i*t/2,e.y+a*n/2,e.inside,e.outside));return r}function X(e,t){let n=new Map;for(let e of t.texts){let t=n.get(e.key)||[];t.push(e),n.set(e.key,t)}let r=[];for(let t of e)r.push({key:t.id,kind:`set`,ids:[t.id],line:t.line,tone:t.tone,labels:[{text:t.label||t.id,icon:t.icon,line:t.line,link:t.link}],items:(n.get(t.id)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),texts:n.get(t.id)||[]});let i=new Map;for(let a of t.unions){let t=a.ids.join(`|`),o=i.get(t);if(o){a.label&&o.labels.push({text:a.label,line:a.line});continue}let s={key:t,kind:`union`,ids:a.ids,line:a.line,tone:e.find(e=>e.id===a.ids[0])?.tone||1,labels:a.label?[{text:a.label,icon:a.icon,line:a.line,link:a.link}]:[],items:(n.get(t)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),status:a.status,link:a.link,texts:n.get(t)||[]};i.set(t,s),r.push(s)}return Z(r,e),r}function Z(e,t){for(let n of e)n.inside=n.ids.map(e=>t.find(t=>t.id===e)).filter(Boolean),n.outside=t.filter(e=>!n.inside.includes(e))}function Q(e,t,n){let r=1/0;for(let i of e){let e=U(i.inside,i.outside,n?2:3,n?10:16);i.x=e.x,i.y=e.y,i.clear=e.value,i.block=J(i,t),r=Math.min(r,i.block.room)}return r}function re(e,t,n,r){let i=[];for(let e=0;e<T;e+=1)i.push(e/16);i.sort((e,t)=>Math.abs(e-r)-Math.abs(t-r)||t-e);let a=null;for(let r of i){Z(t,e(r));let i=Q(t,n,!0);if((!a||i>a.worst+1e-9)&&(a={spread:r,worst:i}),i>=0)return Z(t,e(r)),Q(t,n,!1),{rings:e(r),worst:i}}return Z(t,e(a.spread)),{rings:e(a.spread),worst:Q(t,n,!1)}}function ie(e){let t=e.block,n=e.y-t.h/2,r=e.kind===`set`?c:l;e.rows=[],e.chip=null,t.labels.length&&(e.chip={x:e.x-t.labelW/2,y:n,w:t.labelW,h:t.labelH},t.labels.forEach((t,i)=>e.rows.push({text:t.text,font:t.font,icon:t.icon,link:t.link,status:t.status,x:e.x,y:n+m+(i+.5)*r,anchor:`middle`})));let i=n+t.labelH+(t.labels.length&&t.items.length?u:0);t.items.forEach((t,n)=>e.rows.push({text:t.text,font:t.font,icon:t.icon,link:t.link,status:t.status,x:e.x,anchor:`middle`,y:i+(n+.5)*l}))}function ae(e,{measure:n,width:r,lang:i}){let a=Math.max(240,r-48),o=K(e.sets,1),s=q(G(e.sets,1,o)),c=Math.max(56,Math.min(a/Math.max(1,s.w),O/Math.max(1,s.h))),l=X(G(e.sets,c,o),e),u=null;for(let t=0;t<=D&&(u=re(t=>G(e.sets,c,t),l,n,o),!(u.worst>=0));t+=1){let t=c*E;if(q(G(e.sets,t,o)).w>a*2)break;c=t}let d=u.rings,f=[];for(let e of l)e.block.fits||(f.push({region:e,rows:[...e.block.labels,...e.block.items]}),e.block={...e.block,labels:[],labelW:0,labelH:0,chip:!1});let p=new Set(l.map(e=>e.key));for(let t of e.texts)p.has(t.key)||f.push({region:{x:null,y:null,tone:1,line:t.line,caption:t.ids.join(` ∩ `)},rows:[{text:t.label,font:N}]});let m=[];f.length&&m.push((0,t.warning)(`DIAGRAM_HINT`,i,f[0].region.line??e.sets[0].line,`有 ${f.length} 个标签放不进所属区域,已排在图下方并用引线指向该区域`,`${f.length} label(s) do not fit their region and moved below the plot with a leader`,`缩短标签,或减少同一区域的 text`,`Shorten the labels, or use fewer text nodes per region`));for(let e of l)if(!(e.texts.length<=S)){m.push((0,t.warning)(`DIAGRAM_HINT`,i,e.texts[S].line,`「${e.key}」区域有 ${e.texts.length} 个 text,超过 ${S} 个后很难阅读`,`Region "${e.key}" holds ${e.texts.length} text nodes; more than ${S} is hard to read`,`把说明移到图外,或拆成多张图`,`Move details outside, or split the diagram`));break}let h=l.filter(e=>e.block.h>0||e.block.labels.length);for(let e of h)ie(e);return $({mode:`rings`,rings:d,regions:h,plot:q(d),rows:h.flatMap(e=>e.rows),shelf:f,notes:m},e,{measure:n,width:r})}function oe(e,{measure:n,width:r,lang:i}){let a=new Map;for(let t of e.texts){let e=a.get(t.key)||[];e.push(t),a.set(t.key,e)}let o=[];for(let t of e.sets)o.push({kind:`set`,key:t.id,tone:t.tone,status:t.status,link:t.link,line:t.line,titles:[{...t,label:t.label||t.id}],caption:``,items:a.get(t.id)||[]});let s=new Map;for(let t of e.unions){let n=t.ids.join(`|`),r=s.get(n);if(r){t.label&&r.titles.push(t);continue}let i={kind:`union`,key:n,tone:e.sets.find(e=>e.id===t.ids[0])?.tone||1,status:t.status,link:t.link,line:t.line,titles:t.label||t.icon?[t]:[],caption:t.ids.join(` ∩ `),items:a.get(n)||[]};s.set(n,i),o.push(i)}let u=new Set(o.map(e=>e.key));for(let t of e.texts)u.has(t.key)||o.push({kind:`loose`,key:t.key,tone:1,line:t.line,titles:[t],caption:t.ids.join(` ∩ `),items:[]});let d=(e,r)=>(0,t.wrapText)(e,140,r,(e,t)=>n(e,t));for(let e of o){let t=(e,t)=>e.flatMap(e=>d(e.label,t).map((n,r)=>({text:n,font:t,status:e.status,link:e.link,icon:r===0?e.icon:null})));e.header=t(e.titles,M),e.captionLines=e.caption?d(e.caption,N):[],e.itemLines=t(e.items,N);let r=[...e.header.map(e=>n(e.text,e.font)+(e.icon?18:0)),...e.captionLines.map(e=>n(e,N)),...e.itemLines.map(e=>n(e.text,e.font)+(e.icon?18:0))];e.w=Math.max(b,Math.ceil(Math.max(0,...r)+28)),e.h=28+e.header.length*c+(e.captionLines.length?4+e.captionLines.length*l:0)+(e.itemLines.length?6+e.itemLines.length*l:0)}let f=Math.max(...o.map(e=>e.w)),p=Math.max(240,r-48),m=Math.min(x,o.length);for(;m>1&&m*f+(m-1)*y>p*2;)--m;let h=Math.ceil(o.length/m),g=[];o.forEach((e,t)=>{e.column=t%m,e.row=Math.floor(t/m),g[e.row]=Math.max(g[e.row]||0,e.h)});let _=[],S=0;for(let e=0;e<h;e+=1)_[e]=S,S+=g[e]+y;o.forEach(e=>{e.w=f,e.x=e.column*(f+y),e.y=_[e.row],e.rows=[];let t=e.y+v;for(let n of e.header)e.rows.push({...n,x:e.x+v,y:t+c/2,anchor:`start`}),t+=c;if(e.captionLines.length){t+=4;for(let n of e.captionLines)e.rows.push({text:n,font:N,x:e.x+v,y:t+l/2,anchor:`start`}),t+=l}if(e.itemLines.length){t+=6;for(let n of e.itemLines)e.rows.push({...n,x:e.x+v,y:t+l/2,anchor:`start`}),t+=l}});let C=[(0,t.warning)(`DIAGRAM_HINT`,i,e.sets[0].line,`${e.sets.length} 个集合画成圆环后重叠区无法阅读,已改用分区面板`,`${e.sets.length} sets would leave unreadable overlaps; drawn as a region grid instead`,`集合减到 3 个可获得圆环布局,或接受分区面板`,`Keep three sets for rings, or accept the region grid`)];return $({mode:`grid`,panels:o,plot:{x:0,y:0,w:m*f+(m-1)*y,h:S-y},rows:o.flatMap(e=>e.rows),shelf:[],notes:C},e,{measure:n,width:r})}function $(e,n,{measure:r,width:i}){let c=n.title?(0,t.wrapText)(n.title,Math.max(160,Math.min(i-48,480)),j,(e,t)=>r(e,t)):[],u=c.length?c.length*o+s:0,d=[],f=e.plot.x+e.plot.w,p=e.plot.y+e.plot.h;if(e.shelf.length){let t=Math.max(e.plot.w,240),n=e.plot.x,i=e.plot.y+e.plot.h+h,a=0;for(let o of e.shelf){let s=[...o.region.caption?[{text:o.region.caption,font:N,kind:`caption`}]:[],...o.rows.map(e=>({...e,kind:e.font===M?`label`:`item`}))],c=Math.max(0,...s.map(e=>r(e.text,e.font)));n>e.plot.x&&n+c>e.plot.x+t&&(n=e.plot.x,i+=a+y/2,a=0);let u=s.map((e,t)=>({text:e.text,font:e.font,kind:e.kind,x:n,y:i+(t+.5)*l}));d.push({lines:u,tone:o.region.tone,from:o.region.x==null?null:{x:o.region.x,y:o.region.y},to:{x:n+c/2,y:i-_}}),p=Math.max(p,i+s.length*l),f=Math.max(f,n+c),a=Math.max(a,s.length*l),n+=c+g}}let m=Math.max(e.plot.x+e.plot.w,f)-e.plot.x,v=Math.max(m,...c.map(e=>r(e,j))),b=a+(v-m)/2-e.plot.x,x=a+u-e.plot.y,S=Math.ceil(p-e.plot.y+u+48),C=Math.ceil(v+48);for(let t of e.rings||[])t.cx+=b,t.cy+=x;for(let t of e.panels||[])t.x+=b,t.y+=x;for(let t of e.rows)t.x+=b,t.y+=x;for(let t of e.regions||[])t.x+=b,t.y+=x,t.chip&&(t.chip.x+=b,t.chip.y+=x);for(let e of d){for(let t of e.lines)t.x+=b,t.y+=x;e.from&&={x:e.from.x+b,y:e.from.y+x},e.to={x:e.to.x+b,y:e.to.y+x}}return{width:C,height:S,mode:e.mode,title:c.length?{lines:c,x:a+v/2,top:34}:null,rings:e.rings||[],regions:e.regions||[],panels:e.panels||[],rows:e.rows,shelf:d,notes:e.notes,anchor:{x:a+v/2,y:a+u+e.plot.h/2}}}function se(e,n={}){let r=n.measure||t.fallbackMeasure,i=Math.max(1,Number(n.width)||800),a=n.lang||`zh`;if(!e.sets.length)return{width:i,height:0,errors:[]};let o=e.sets.length<=k?ae(e,{measure:r,width:i,lang:a}):oe(e,{measure:r,width:i,lang:a}),s=[...o.notes],c=e.sets.length+e.unions.length+e.texts.length;return c>ee?s.push((0,t.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图有 ${c} 个元素,建议拆分`,`The Venn diagram has ${c} parts; consider splitting it`,`按集合拆成多张图`,`Split the diagram by set`)):o.width>i*2&&s.push((0,t.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图需要 ${o.width}px 宽,超过图框两倍`,`The Venn diagram needs ${o.width}px, more than twice the frame`,`加宽图框,或拆分文氏图`,`Widen the frame, or split the diagram`)),{...o,errors:s}}function ce(e,n){let r=(0,t.appearance)(n),a=n.color(`bg`),s=e=>n.frameTone(n.color(`tone${(e-1)%6+1}`)),c=e=>{let t=e.status?n.textColor(r[e.status]):e.kind===`caption`?r.fg3:e.font===M?r.fg1:r.fg2,a=[n.text(e.x+(e.icon?e.anchor===`middle`?9:18:0),e.y,e.text,{anchor:e.anchor,size:e.font.size,weight:e.font.weight,"dominant-baseline":`central`,fill:t})];if(e.icon){let r=e.anchor===`middle`?e.x-n.measure(e.text,e.font.size,e.font.weight)/2-3:e.x+6;a.unshift((0,i.labelIcon)(n,e.icon,r,e.y,12,t))}return e.link?n.link(e.link.href,a,e.link):n.el(`g`,{},a)},l=[];if(e.mode===`rings`){for(let t of e.rings)l.push(n.circle(t.cx,t.cy,t.r,{fill:t.status?n.frameTone(r[t.status]):s(t.tone),"fill-opacity":.1}));for(let t of e.rings)l.push(n.circle(t.cx,t.cy,t.r,{fill:`none`,stroke:t.status?n.frameTone(r[t.status]):s(t.tone),"stroke-width":w,meta:{kind:`node`,id:t.id,label:t.id}}));for(let t of e.regions)t.chip&&l.push(n.rect(t.chip.x,t.chip.y,t.chip.w,t.chip.h,{rx:r.smallRadius,fill:t.status?n.tint(a,r[t.status],.12):a}));for(let t of e.rows)l.push(c(t));for(let t of e.shelf){t.from&&l.push(n.line(t.from.x,t.from.y,t.to.x,t.to.y,{stroke:n.tint(a,s(t.tone),.55),"stroke-width":1,"stroke-dasharray":`3 3`}));for(let e of t.lines)l.push(c(e))}}else for(let t of e.panels){let e=t.status?n.frameTone(r[t.status]):s(t.tone);l.push(n.rect(t.x,t.y,t.w,t.h,{rx:r.radius,fill:n.tint(a,e,t.kind===`set`?.07:.04),stroke:n.tint(a,e,.45),"stroke-width":1,...t.kind===`set`?{}:{"stroke-dasharray":`5 4`},meta:{kind:t.kind===`set`?`node`:`frame`,id:t.key,label:t.key}}));for(let e of t.rows)l.push(c(e))}return e.title&&e.title.lines.forEach((t,i)=>l.push(n.text(e.title.x,e.title.top+i*o,t,{anchor:`middle`,size:j.size,weight:j.weight,fill:r.fg1,"dominant-baseline":`central`}))),{width:e.width,height:e.height,title:e.title?e.title.lines.join(` `):void 0,children:l,anchor:e.anchor}}return e.implementations={"venn-beta":{acceptsPresentation:!0,parse:ne,layout:se,scene:ce}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/tree-family-icon`]);
1
+ KChartUnits["diagram/venn"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=24,s=20,c=12,l=18,u=16,d=4,f=12,p=10,m=4,h=26,g=28,_=8,v=14,y=16,b=168,x=3,S=12,C=10,w=1.5,T=.1,E=4.5,D=17,O=1.12,ee=6,k=460,A=60,te=3,ne=.55,re=.55,j={size:n.FONT.title.size,weight:n.FONT.title.weight},M={size:n.FONT.title.size,weight:n.FONT.title.weight},N={size:n.FONT.label.size,weight:n.FONT.label.weight},P={...N,weight:600};function F(e){let t=!1;for(let n=0;n<e.length;n+=1)if(e[n]===`"`)t=!t;else if(!t&&e[n]===`%`&&e[n+1]===`%`)return e.slice(0,n);return e}var I=/^"([^"]*)"|^([A-Za-z_][\w-]*)/,L=/^[ \t]*/;function R(e,t){let n=t+L.exec(e.slice(t))[0].length,r=I.exec(e.slice(n));return r?{id:r[1]??r[2],at:n+r[0].length}:null}function ie(e){let t=/^[A-Za-z][\w-]*/.exec(e);return t?{word:t[0].toLowerCase(),at:t[0].length}:{word:``,at:0}}function z(e,t){let n=[],r=t;for(;;){let t=R(e,r);if(!t||/^\s*:/.test(e.slice(t.at)))break;n.push(t.id);let i=t.at+L.exec(e.slice(t.at))[0].length;if(e[i]!==`,`){r=t.at;break}r=i+1}let i=n.length?r:t;return{ids:n,at:i+L.exec(e.slice(i))[0].length}}function B(e,t){let n=/^\[([^\]]*)\]/.exec(e.slice(t));if(!n)return{label:null,at:t};let r=n[1];return r.length>=2&&r.startsWith(`"`)&&r.endsWith(`"`)&&(r=r.slice(1,-1)),{label:r.trim(),at:t+n[0].length}}function V(e,t){let n=/^:\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))/.exec(e.slice(t));return n?{size:Number(n[1]),at:t+n[0].length}:{size:null,at:t}}function H(e,t={}){let a=t.lang||`zh`,o=Number.isInteger(t.firstLine)?t.firstLine:2,s=Number.isInteger(t.headerLine)?t.headerLine:Math.max(1,o-1),c=[],l=(0,i.presentation)({lang:a}),u=new Set,d=[],f=[],p=[],m=new Map,h=``,g=s,_=null,v=!1,y=(e,t,r,i,o)=>c.push((0,n.error)(a,e,t,r,i,o)),b=e=>y(e,`无法识别这一行`,`Unrecognized line`,`使用 set、union、text、title 或 style`,`Use set, union, text, title, or style`),x=e=>y(e,`text 前缺少 set 或 union`,`A text line needs an owning set or union`,`把 text 缩进到 set/union 下面,或先写集合 id`,`Indent text under a set/union, or name the set first`),S=typeof t.params==`string`?t.params.trim():``;S&&y(s,`venn-beta 头行不能带内容「${S}」`,`Unexpected text after "venn-beta": ${S}`,`把内容写成 set、union 或 text 行`,`Move the text into set, union, or text lines`);for(let e of Object.keys(t.options||{}))y(s,`venn-beta 不支持选项「${e}」`,`Unsupported venn-beta option: ${e}`,`删除这个选项`,`Remove this option`);let w=(e,t)=>{let n=(0,r.normalizeLabel)(e,{lang:a,line:t});for(let e of n.diagnostics){let t=`${e.code}:${e.message}`;u.has(t)||(u.add(t),c.push(e))}return{text:n.text,icon:n.icon}},T=(e,t,n,r)=>{if(!e)return b(r),!1;if(m.has(e))return y(r,`集合「${e}」重复定义`,`Duplicate set identifier: ${e}`,`把同一个集合合并成一行 set`,`Merge the duplicate into a single set line`),!1;let i=t?w(t,r):{text:``,icon:null};return d.push({id:e,label:i.text,icon:i.icon,size:n??C,tone:d.length%6+1,line:r}),m.set(e,d.at(-1)),_={ids:[e]},!0},E=(e,t,n,r)=>{let i=e.filter((t,n)=>e.indexOf(t)===n);if(i.length<2)return y(r,`union 至少需要两个集合`,`A union needs at least two sets`,`写成 union A,B 或列更多集合`,`Write union A,B or list more sets`),!1;let a=i.filter(e=>!m.has(e));if(a.length)return y(r,`union 引用了未定义的集合「${a.join(`、`)}」`,`Unknown set identifier: ${a.join(`, `)}`,`先用 set 声明集合,再写 union`,`Declare each set with set before the union`),!1;let o=[...i].sort(),s=t?w(t,r):{text:``,icon:null};return f.push({ids:o,label:s.text,icon:s.icon,size:n??C/i.length**2,line:r}),_={ids:o},!0},D=(e,t,n,r)=>{let i=n.filter((e,t)=>n.indexOf(e)===t);if(!i.length){x(r);return}let a=w(t||e,r);p.push({id:e,label:a.text,icon:a.icon,ids:[...i].sort(),key:[...i].sort().join(`|`),line:r})};for(let[t,n]of String(e??``).split(`
2
+ `).entries()){let e=o+t,r=F(n).trim();if(!r)continue;let i=/^[ \t]/.test(n),a=/^style\s+/i.exec(r);if(a){let t=z(r,a[0].length);if(t.ids.length>1){l.accept(`style ${JSON.stringify([...t.ids].sort().join(`|`))} ${r.slice(t.at).trimStart()}`,e);continue}}if(l.accept(r,e))continue;let s=ie(r),c=r.slice(s.at);if(v&&i&&s.word===`text`){let t=R(c,0),n=B(c,t?t.at:0);if(!t||c.slice(n.at).trim()){b(e);continue}_?D(t.id,n.label,_.ids,e):x(e)}else if(i||(v=!1),s.word===`title`){let t=c.trim();if(!t){y(e,`title 后面缺少标题文字`,`title needs a heading after it`,`写成 title 标题文字`,`Write title followed by the heading`);continue}h=w(t.replace(/^"(.*)"$/,`$1`).trim(),e).text,g=e}else if(s.word===`set`){let t=R(c,0);if(!t){b(e);continue}let n=B(c,t.at),r=V(c,n.at);if(c.slice(r.at).trim()){b(e);continue}T(t.id,n.label,r.size,e)&&(v=!0)}else if(s.word===`union`){let t=z(c,0),n=B(c,t.at),r=V(c,n.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}E(t.ids,n.label,r.size,e)&&(v=!0)}else if(s.word===`text`){let t=z(c,0),n=R(c,t.at),r=B(c,n?n.at:t.at);if(!t.ids.length||c.slice(r.at).trim()){b(e);continue}n?D(n.id,r.label,t.ids,e):D(t.ids[0],r.label,_?_.ids:[],e)}else b(e)}c.push(...l.diagnostics()),d.length||y(o,`文氏图没有任何 set`,`A Venn diagram needs at least one set`,`至少写一行 set`,`Write at least one set line`);let O=(e,t)=>({...e,status:l.statusOf(t),link:l.linkOf(t)});for(let e of d)Object.assign(e,O({},e.id));for(let e of f)Object.assign(e,O({},e.ids.join(`|`)));for(let e of p)Object.assign(e,O({},e.id));return{model:{kind:`venn-beta`,title:h,titleLine:g,sets:d,unions:f,texts:p},errors:c}}function U(e,t,n,r){let i=1/0;for(let r of n)i=Math.min(i,r.r-Math.hypot(e-r.cx,t-r.cy));for(let n of r)i=Math.min(i,Math.hypot(e-n.cx,t-n.cy)-n.r);return i}function W(e,t,n=3,r=16){let i=e.reduce((e,t)=>e+t.cx,0)/e.length,a=e.reduce((e,t)=>e+t.cy,0)/e.length,o={x:i,y:a,value:U(i,a,e,t)},s=Math.max(...e.map(e=>e.r));for(let i=0;i<n;i+=1){let n=o;for(let i=-r/2;i<=r/2;i+=1)for(let c=-r/2;c<=r/2;c+=1){let l=n.x+i*s/(r/2),u=n.y+c*s/(r/2),d=U(l,u,e,t);(d>o.value+1e-9||Math.abs(d-o.value)<=1e-9&&Math.abs(u-a)<Math.abs(o.y-a)-1e-9)&&(o={x:l,y:u,value:d})}s/=r/4}return o}function G(e,t){let n=e.map(e=>Number.isFinite(e.size)?Math.max(0,e.size):C),r=Math.max(0,...n);return n.map(e=>t*(r>0?Math.max(.3,Math.sqrt(e/r)):1))}function K(e,t,n){let r=G(e,t),i=e.map((e,t)=>({id:e.id,label:e.label,icon:e.icon,tone:e.tone,status:e.status,link:e.link,line:e.line,r:r[t],cx:0,cy:0}));if(i.length===1)return i;if(i.length===2){let e=Math.min(r[0],r[1]),t=Math.abs(r[0]-r[1])+.25*e,a=r[0]+r[1]-.1*e,o=t+Math.min(1,Math.max(0,n))*(a-t);return i[0].cx=-o/2,i[1].cx=o/2,i}let a=i.map((e,t)=>({index:t,r:e.r})).sort((e,t)=>t.r-e.r||t.index-e.index)[0].index,o=[0,1,2].filter(e=>e!==a).sort((e,t)=>e-t),s=(re+Math.min(1,Math.max(0,n))*.7)*(r.reduce((e,t)=>e+t,0)/3),c=[];return c[a]=-Math.PI/2,c[o[0]]=5*Math.PI/6,c[o[1]]=Math.PI/6,i.forEach((e,t)=>{e.cx=Math.cos(c[t])*s,e.cy=Math.sin(c[t])*s}),i}function q(e,t){if(e.length<=1)return .5;let n=G(e,t);if(e.length===2){let e=Math.min(n[0],n[1]),t=Math.abs(n[0]-n[1])+.25*e,r=n[0]+n[1]-.1*e;return r>t?Math.min(1,Math.max(0,(n[0]+n[1]-ne*e-t)/(r-t))):.5}return .44999999999999996/.7}function J(e){let t=Math.min(...e.map(e=>e.cx-e.r)),n=Math.max(...e.map(e=>e.cx+e.r)),r=Math.min(...e.map(e=>e.cy-e.r)),i=Math.max(...e.map(e=>e.cy+e.r));return{x:t,y:r,w:n-t,h:i-r}}function ae(e,t){let r=e.kind===`set`?f:p,i=e.kind===`set`?M:P,a=(e,n)=>Math.max(0,...e.flatMap(({text:e})=>String(e).split(/\s+/).filter(Boolean).map(e=>t(e,n)))),o=Math.max(48,a(e.labels,i)+2,a(e.items,N)+2,(e.clear-r)*2-20),s=(e,r,i)=>e.flatMap(e=>(0,n.wrapText)(e.text,o,r,t).map(t=>({text:t,font:r,icon:e.icon,link:e.link,status:e.status||i}))),c=s(e.labels,i,e.status),h=s(e.items,N,c.length?null:e.status),g=c.length*(e.kind===`set`?l:u),_=Math.max(0,...[...c,...h].map(e=>Y(e,t))),v=g+(c.length&&h.length?d:0)+h.length*u;return{labels:c,items:h,labelH:g,w:_,h:v,room:v?oe(e,_,v)-m:1/0}}function Y(e,t){return t(e.text,e.font)+(e.icon?18:0)}function oe(e,t,n){let r=1/0;for(let i of e.inside)r=Math.min(r,i.r-Math.hypot(Math.abs(e.x-i.cx)+t/2,Math.abs(e.y-i.cy)+n/2));for(let i of e.outside)r=Math.min(r,Math.hypot(Math.max(0,Math.abs(e.x-i.cx)-t/2),Math.max(0,Math.abs(e.y-i.cy)-n/2))-i.r);return r}function se(e,t){let n=new Map;for(let e of t.texts){let t=n.get(e.key)||[];t.push(e),n.set(e.key,t)}let r=[];for(let t of e)r.push({key:t.id,kind:`set`,ids:[t.id],line:t.line,tone:t.tone,labels:[{text:t.label||t.id,icon:t.icon,line:t.line,link:t.link}],items:(n.get(t.id)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),texts:n.get(t.id)||[]});let i=new Map;for(let a of t.unions){let t=a.ids.join(`|`),o=i.get(t),s=a.label||a.icon?[{text:a.label,icon:a.icon,line:a.line,link:a.link}]:[];if(o){o.labels.push(...s);continue}let c={key:t,kind:`union`,ids:a.ids,line:a.line,tone:e.find(e=>e.id===a.ids[0])?.tone||1,labels:s,items:(n.get(t)||[]).map(e=>({text:e.label,icon:e.icon,link:e.link,status:e.status})),status:a.status,link:a.link,texts:n.get(t)||[]};i.set(t,c),r.push(c)}return X(r,e),r}function X(e,t){for(let n of e)n.inside=n.ids.map(e=>t.find(t=>t.id===e)).filter(Boolean),n.outside=t.filter(e=>!n.inside.includes(e))}function Z(e,t,n){let r=1/0;for(let i of e){let e=W(i.inside,i.outside,n?2:3,n?10:16);i.x=e.x,i.y=e.y,i.clear=e.value,i.block=ae(i,t),r=Math.min(r,i.block.room)}return r}function Q(e,t,n,r){let i=[];for(let e=0;e<D;e+=1)i.push(e/16);i.sort((e,t)=>Math.abs(e-r)-Math.abs(t-r)||t-e);let a=null;for(let r of i){let i=e(r);X(t,i);let o=Z(t,n,!0),s=o>=0?Z(t,n,!1):o;if(s>=0)return{rings:i,worst:s};(!a||s>a.worst+1e-9)&&(a={spread:r,worst:s})}let o=e(a.spread);return X(t,o),{rings:o,worst:Z(t,n,!1)}}function ce(e){let t=e.block,n=e.y-t.h/2,r=e.kind===`set`?l:u;e.rows=t.labels.map((t,i)=>({...t,x:e.x,y:n+(i+.5)*r,anchor:`middle`}));let i=n+t.labelH+(t.labels.length&&t.items.length?d:0);t.items.forEach((t,n)=>e.rows.push({...t,x:e.x,anchor:`middle`,y:i+(n+.5)*u}))}function le(e,{measure:t,width:r,lang:i,compact:a,embedHeading:o}){let s=a?560:Math.max(240,r-48),c=q(e.sets,1),l=J(K(e.sets,1,c)),u=Math.max(0,...[...e.sets.map(e=>e.label||e.id),...e.unions.map(e=>e.label),...e.texts.map(e=>e.label)].map(e=>t(e,M))),d=Math.min(520,260+Math.min(100,(e.unions.length+e.texts.length)*8)+Math.min(80,Math.max(0,e.sets.length-2)*30)+Math.min(80,u*.25)),f=a?Math.max(56,Math.min(d/Math.max(1,l.w),320/Math.max(1,l.h))):Math.max(56,Math.min(s/Math.max(1,l.w),k/Math.max(1,l.h))),p=se(K(e.sets,f,c),e),m=null;for(let n=0;n<=ee&&(m=Q(t=>K(e.sets,f,t),p,t,c),!(m.worst>=0));n+=1){let t=f*O;if(J(K(e.sets,t,c)).w>s*2)break;f=t}let h=m.rings,g=[];for(let e of p)e.block.room>=0||g.push({region:e,rows:[...e.block.labels,...e.block.items]});let _=new Set(p.map(e=>e.key));for(let t of e.texts)_.has(t.key)||g.push({region:{x:null,y:null,tone:1,line:t.line,caption:t.ids.join(` ∩ `)},rows:[{text:t.label,font:N,icon:t.icon,link:t.link,status:t.status}]});let v=[];g.length&&v.push((0,n.warning)(`DIAGRAM_HINT`,i,g[0].region.line??e.sets[0].line,`有 ${g.length} 个标签放不进所属区域,已排在图下方并用引线指向该区域`,`${g.length} label(s) do not fit their region and moved below the plot with a leader`,`缩短标签,或减少同一区域的 text`,`Shorten the labels, or use fewer text nodes per region`));for(let e of p)if(!(e.texts.length<=S)){v.push((0,n.warning)(`DIAGRAM_HINT`,i,e.texts[S].line,`「${e.key}」区域有 ${e.texts.length} 个 text,超过 ${S} 个后很难阅读`,`Region "${e.key}" holds ${e.texts.length} text nodes; more than ${S} is hard to read`,`把说明移到图外,或拆成多张图`,`Move details outside, or split the diagram`));break}let y=p.filter(e=>e.block.h>0&&e.block.room>=0);for(let e of y)ce(e);return $({mode:`rings`,rings:h,regions:y,plot:J(h),rows:y.flatMap(e=>e.rows),shelf:g,notes:v},e,{measure:t,width:r,compact:a,embedHeading:o})}function ue(e,{measure:t,width:r,lang:i,compact:a,embedHeading:o}){let s=new Map;for(let t of e.texts){let e=s.get(t.key)||[];e.push(t),s.set(t.key,e)}let c=[];for(let t of e.sets)c.push({kind:`set`,key:t.id,tone:t.tone,status:t.status,link:t.link,line:t.line,titles:[{...t,label:t.label||t.id}],caption:``,items:s.get(t.id)||[]});let d=new Map;for(let t of e.unions){let n=t.ids.join(`|`),r=d.get(n);if(r){t.label&&r.titles.push(t);continue}let i={kind:`union`,key:n,tone:e.sets.find(e=>e.id===t.ids[0])?.tone||1,status:t.status,link:t.link,line:t.line,titles:t.label||t.icon?[t]:[],caption:t.ids.join(` ∩ `),items:s.get(n)||[]};d.set(n,i),c.push(i)}let f=new Set(c.map(e=>e.key));for(let t of e.texts)f.has(t.key)||c.push({kind:`loose`,key:t.key,tone:1,line:t.line,titles:[t],caption:t.ids.join(` ∩ `),items:[]});let p=(e,r)=>(0,n.wrapText)(e,140,r,(e,n)=>t(e,n));for(let e of c){let n=(e,t)=>e.flatMap(e=>p(e.label,t).map((n,r)=>({text:n,font:t,status:e.status,link:e.link,icon:r===0?e.icon:null})));e.header=n(e.titles,M),e.captionLines=e.caption?p(e.caption,N):[],e.itemLines=n(e.items,N);let r=[...e.header.map(e=>t(e.text,e.font)+(e.icon?18:0)),...e.captionLines.map(e=>t(e,N)),...e.itemLines.map(e=>t(e.text,e.font)+(e.icon?18:0))];e.w=Math.max(b,Math.ceil(Math.max(0,...r)+28)),e.h=28+e.header.length*l+(e.captionLines.length?4+e.captionLines.length*u:0)+(e.itemLines.length?6+e.itemLines.length*u:0)}let m=Math.max(...c.map(e=>e.w)),h=a?520:Math.max(240,r-48),g=Math.min(x,c.length);if(!a)for(;g>1&&g*m+(g-1)*y>h*2;)--g;let _=Math.ceil(c.length/g),S=[];c.forEach((e,t)=>{e.column=t%g,e.row=Math.floor(t/g),S[e.row]=Math.max(S[e.row]||0,e.h)});let C=[],w=0;for(let e=0;e<_;e+=1)C[e]=w,w+=S[e]+y;c.forEach(e=>{e.w=m,e.x=e.column*(m+y),e.y=C[e.row],e.rows=[];let t=e.y+v;for(let n of e.header)e.rows.push({...n,x:e.x+v,y:t+l/2,anchor:`start`}),t+=l;if(e.captionLines.length){t+=4;for(let n of e.captionLines)e.rows.push({text:n,font:N,x:e.x+v,y:t+u/2,anchor:`start`}),t+=u}if(e.itemLines.length){t+=6;for(let n of e.itemLines)e.rows.push({...n,x:e.x+v,y:t+u/2,anchor:`start`}),t+=u}});let T=[(0,n.warning)(`DIAGRAM_HINT`,i,e.sets[0].line,`${e.sets.length} 个集合画成圆环后重叠区无法阅读,已改用分区面板`,`${e.sets.length} sets would leave unreadable overlaps; drawn as a region grid instead`,`集合减到 3 个可获得圆环布局,或接受分区面板`,`Keep three sets for rings, or accept the region grid`)];return $({mode:`grid`,panels:c,plot:{x:0,y:0,w:g*m+(g-1)*y,h:w-y},rows:c.flatMap(e=>e.rows),shelf:[],notes:T},e,{measure:t,width:r,compact:a,embedHeading:o})}function $(e,t,{measure:r,width:i,compact:a,embedHeading:l}){let d=t.title?(0,n.wrapText)(t.title,a?480:Math.max(160,Math.min(i-48,480)),j,(e,t)=>r(e,t)):[],f=!l&&d.length?d.length*s+c:0,p=[],m=e.plot.x+e.plot.w,v=e.plot.y+e.plot.h;if(e.shelf.length){let t=Math.max(e.plot.w,240),n=e.plot.x,i=e.plot.y+e.plot.h+h,a=0;for(let o of e.shelf){let s=[...o.region.caption?[{text:o.region.caption,font:N,kind:`caption`}]:[],...o.rows],c=Math.max(0,...s.map(e=>Y(e,r)));n>e.plot.x&&n+c>e.plot.x+t&&(n=e.plot.x,i+=a+y/2,a=0);let l=s.map((e,t)=>({...e,anchor:`start`,x:n,y:i+(t+.5)*u}));p.push({lines:l,tone:o.region.tone,from:o.region.x==null?null:{x:o.region.x,y:o.region.y},to:{x:n+c/2,y:i-_}}),v=Math.max(v,i+s.length*u),m=Math.max(m,n+c),a=Math.max(a,s.length*u),n+=c+g}}let b=Math.max(e.plot.x+e.plot.w,m)-e.plot.x,x=Math.max(b,...(l?[]:d).map(e=>r(e,j))),S=o+(x-b)/2-e.plot.x,C=o+f-e.plot.y,w=Math.ceil(v-e.plot.y+f+48),T=Math.ceil(x+48);for(let t of e.rings||[])t.cx+=S,t.cy+=C;for(let t of e.panels||[])t.x+=S,t.y+=C;for(let t of e.rows)t.x+=S,t.y+=C;for(let t of e.regions||[])t.x+=S,t.y+=C;for(let e of p){for(let t of e.lines)t.x+=S,t.y+=C;e.from&&={x:e.from.x+S,y:e.from.y+C},e.to={x:e.to.x+S,y:e.to.y+C}}return{width:T,height:w,mode:e.mode,title:d.length?{lines:d,x:o+x/2,top:34}:null,...l?{embedHeading:l,heading:t.title}:{},rings:e.rings||[],regions:e.regions||[],panels:e.panels||[],rows:e.rows,shelf:p,notes:e.notes,anchor:{x:o+x/2,y:o+f+e.plot.h/2}}}function de(e,t={}){let r=t.measure||n.fallbackMeasure,i=Math.max(1,Number(t.width)||800),a=t.lang||`zh`,o=t.compact===!0,{embedHeading:s}=t;if(!e.sets.length)return{width:i,height:0,errors:[]};let c=e.sets.length<=te?le(e,{measure:r,width:i,lang:a,compact:o,embedHeading:s}):ue(e,{measure:r,width:i,lang:a,compact:o,embedHeading:s}),l=[...c.notes],u=e.sets.length+e.unions.length+e.texts.length;return u>A?l.push((0,n.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图有 ${u} 个元素,建议拆分`,`The Venn diagram has ${u} parts; consider splitting it`,`按集合拆成多张图`,`Split the diagram by set`)):c.width>i*2&&l.push((0,n.warning)(`LARGE_DIAGRAM`,a,e.sets[0].line,`文氏图需要 ${c.width}px 宽,超过图框两倍`,`The Venn diagram needs ${c.width}px, more than twice the frame`,`加宽图框,或拆分文氏图`,`Widen the frame, or split the diagram`)),{...c,errors:l}}function fe(e,r){let i=(0,n.appearance)(r),o=r.color(`bg`),c=e=>r.frameTone(r.color(`tone${(e-1)%6+1}`)),l=(e,n)=>{let o=e.status?r.textColor(i[e.status]):e.kind===`caption`?i.fg3:e.font===M?i.fg1:i.fg2;if(n&&(0,t.contrast)(o,n)<E){let e=r.textOn(n);(0,t.contrast)(e,n)<E&&(e=(0,t.contrast)(`#000000`,n)>=E?`#000000`:`#ffffff`),o=(0,t.pushContrast)(o,e,n,E)}let s=[r.text(e.x+(e.icon?e.anchor===`middle`?9:18:0),e.y,e.text,{anchor:e.anchor,size:e.font.size,weight:e.font.weight,"dominant-baseline":`central`,fill:o})];if(e.icon){let t=e.anchor===`middle`?e.x-r.measure(e.text,e.font.size,e.font.weight)/2-3:e.x+6;s.unshift((0,a.labelIcon)(r,e.icon,t,e.y,12,o))}return e.link?r.link(e.link.href,s,e.link):r.el(`g`,{},s)},u=[];if(e.mode===`rings`){let t=e.rings.map(e=>e.status?r.frameTone(i[e.status]):c(e.tone));for(let[n,i]of e.rings.entries())u.push(r.circle(i.cx,i.cy,i.r,{fill:t[n],"fill-opacity":T}));for(let[n,i]of e.rings.entries())u.push(r.circle(i.cx,i.cy,i.r,{fill:`none`,stroke:t[n],"stroke-width":w,meta:{kind:`node`,id:i.id,label:i.id}}));for(let n of e.regions){let i=e.rings.reduce((e,i,a)=>n.ids.includes(i.id)?r.mix(e,t[a],T):e,o);for(let e of n.rows)u.push(l(e,i))}for(let t of e.shelf){t.from&&u.push(r.line(t.from.x,t.from.y,t.to.x,t.to.y,{stroke:r.tint(o,c(t.tone),.55),"stroke-width":1,"stroke-dasharray":`3 3`}));for(let e of t.lines)u.push(l(e,o))}}else for(let t of e.panels){let e=t.status?r.frameTone(i[t.status]):c(t.tone);u.push(r.rect(t.x,t.y,t.w,t.h,{rx:i.radius,fill:r.tint(o,e,t.kind===`set`?.07:.04),stroke:r.tint(o,e,.45),"stroke-width":1,...t.kind===`set`?{}:{"stroke-dasharray":`5 4`},meta:{kind:t.kind===`set`?`node`:`frame`,id:t.key,label:t.key}}));for(let e of t.rows)u.push(l(e))}return!e.embedHeading&&e.title&&e.title.lines.forEach((t,n)=>u.push(r.text(e.title.x,e.title.top+n*s,t,{anchor:`middle`,size:j.size,weight:j.weight,fill:i.fg1,"dominant-baseline":`central`}))),{width:e.width,height:e.height,title:e.title?e.title.lines.join(` `):void 0,...e.embedHeading?{heading:e.heading}:{},children:u,anchor:e.anchor}}return e.implementations={"venn-beta":{acceptsPresentation:!0,parse:H,layout:de,scene:fe}},e})({},KChartUnits[`core/color`],KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/tree-family-icon`]);
@@ -1,4 +1,4 @@
1
- KChartUnits["diagram/wardley"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=String.raw`\d+\.\d+`,i=String.raw`\d+(?:\.\d+)?`,a=String.raw`"(?:\\.|[^"\\])*"`,o=String.raw`(?:${a}|[A-Za-z_](?:[\w()&]|-(?![-.>]))*(?:[ \t]+[A-Za-z(](?:[\w()&]|-(?![-.>]))*)*)`,s=e=>String.raw`\[\s*(${e})\s*,\s*(${e})\s*\]`,c=String.raw`(?:\s+label\s*${s(`-?\\d+`)})?`,l=new RegExp(String.raw`^size\s*${s(`\\d+`)}$`),u=new RegExp(String.raw`^(component|anchor|note|accelerator|deaccelerator)\s+(${o})\s*${s(r)}${c}(?:\s+\((build|buy|outsource|market)\))?(?:\s+(inertia|\(inertia\)))?$`),d=new RegExp(String.raw`^component\s+(${o})\s*\[\s*(${r})\s*\]${c}$`),f=new RegExp(String.raw`^(${o})(?:\s*@\s*(${r}))?(?:\s*/\s*(${o}))?$`),p=new RegExp(String.raw`^pipeline\s+(${o})\s*\{$`),m=new RegExp(String.raw`^evolve\s+(${o})\s+(${r})$`),h=new RegExp(String.raw`^annotation\s+(\d+)\s*,\s*${s(i)}\s+(${a})$`),g=new RegExp(String.raw`^annotations\s*${s(i)}$`),_=new RegExp(String.raw`^(${o})\s*(\+<>|\+>|\+<)?\s*(-->|-\.->|->|>|\+'([^']*)'(<>|<|>))?\s*(${o})\s*(\+<>|\+>|\+<)?\s*(?:;\s*(.+))?$`),v=[[`起源`,`Genesis`],[`定制`,`Custom Built`],[`产品`,`Product`],[`商品`,`Commodity`]],y={visibility:[`可见度`,`Visibility`],evolution:[`演化`,`Evolution`],annotations:[`注释`,`Annotations`],build:[`自建`,`build`],buy:[`采购`,`buy`],outsource:[`外包`,`outsource`],market:[`市场`,`market`]},b=(e,n)=>(0,t.message)(e,...y[n]),x={build:`B`,buy:`Y`,outsource:`O`,market:`M`},S={build:`tone1`,buy:`tone2`,outsource:`tone3`,market:`tone4`},C=e=>e.startsWith(`"`)?e.slice(1,-1).replace(/\\(["\\])/g,`$1`):e;function w(e,{lang:r,firstLine:i=2,title:a=``,headerLine:o=1}={}){let s={type:`wardley`,title:a,size:null,stages:v.map(e=>({name:e[+!!(0,t.isEn)(r)],secondName:null,boundary:null})),nodes:[],pipelines:[],links:[],trends:[],notes:[],annotations:[],annotationBox:null,forces:[]},c=[],y=new Set,b=new Map,x=(0,n.mapLabels)(r,e=>c.push(e)),S=(e,t)=>x(C(e),t);a&&({text:s.title,icon:s.titleIcon}=x(a,o));let w=(e,n,i)=>c.push((0,t.error)(r,e,n,i,`检查 Wardley 地图语法`,`Check Wardley map syntax`)),T=(e,n,i,a)=>{y.has(e)||(y.add(e),c.push((0,t.warning)(`DIAGRAM_HINT`,r,n,i,a)))},E=(e,t)=>{let n=Number(e);return n>100&&w(t,`坐标超出 0–100 范围`,`Coordinate is outside 0–100`),n<=1?n*100:n},D=(e,t,n)=>({visibility:E(e,n),evolution:E(t,n)}),O=(e,t)=>e==null?null:{dx:+e,dy:+t},k=e=>{let t=b.get(e.id);t?(t.visibility!==e.visibility||t.evolution!==e.evolution)&&w(e.line,`「${e.id}」有不同的坐标`,`Conflicting coordinates for "${e.id}"`):(b.set(e.id,e),s.nodes.push(e))};if(e.length>2e5)return w(i,`地图源文本过长`,`Map source exceeds 200,000 characters`),{model:s,errors:c};let A=[],j=null,M=!1;for(let[t,n]of e.split(`
2
- `).entries()){let e=n.match(/^(?:"(?:\\.|[^"\\])*"|\+'[^']*'|%(?!%)|[^"%])*/)[0].trim(),r=i+t;if(!e)continue;let o;if(j){if(e===`}`)j.children.length||w(r,`演进管道没有组件`,`Pipeline needs at least one component`),j=null;else if(o=d.exec(e)){let[,e,t,n,i]=o,{text:a,icon:s}=S(e,r);j.children.push({id:`${j.parent}_${C(e)}`,name:C(e),label:a,icon:s,evolution:E(t,r),labelOffset:O(n,i),kind:`pipeline`,parent:j.parent,line:r})}else w(r,`无效的演进管道组件`,`Invalid pipeline component`)}else if(M)e.includes(`}`)&&(M=!1);else if(o=/^title\s*:?[ \t]+(.+)$/.exec(e))a||({text:s.title,icon:s.titleIcon}=S(o[1],r));else if(/^acc(?:Title|Descr)\s*:/.test(e))continue;else if(/^accDescr\s*\{/.test(e))M=!e.includes(`}`);else if(o=l.exec(e))s.size={width:Number(o[1]),height:Number(o[2])},Object.values(s.size).some(e=>e>16e3)&&w(r,`地图尺寸超过 16000 像素`,`Map size exceeds 16,000 pixels`);else if(e.startsWith(`evolution `)){let t=e.slice(10).match(/"(?:\\.|[^"\\])*"|->|[^"-]+|-/g)||[],n=[``];for(let e of t)e===`->`?n.push(``):n[n.length-1]+=e;let i=n.map(e=>f.exec(e.trim()));if(i.length<2||i.some(e=>!e))w(r,`无效的演进阶段`,`Invalid evolution stages`);else{s.stages=i.map(([,e,t,n])=>{let i=S(e,r),a=n?S(n,r):null;return{name:i.text,icon:i.icon,secondName:a?.text??null,secondIcon:a?.icon,boundary:t==null?null:E(t,r)}});let e=s.stages.map(e=>e.boundary);if(e.some(e=>e!==null)&&(e.some((t,n)=>t===null||t<=(e[n-1]??0))||e.at(-1)!==100)){T(`stages`,r,`阶段边界不完整或未递增至 100;使用等宽阶段`,`Incomplete or unordered stage boundaries; using equal bands`);for(let e of s.stages)e.boundary=null}}}else if(o=u.exec(e)){let[,e,t,n,i,a,c,l,u]=o,{text:d,icon:f}=S(t,r),p=D(n,i,r);e!==`component`&&(a!=null||l||u)||e===`note`&&!t.startsWith(`"`)?w(r,`无效的装饰或备注`,`Invalid decorator or note`):e===`note`?s.notes.push({text:d,icon:f,...p,line:r}):e.endsWith(`accelerator`)?s.forces.push({kind:e,name:d,icon:f,...p,line:r}):k({id:C(t),label:d,icon:f,kind:e,...p,labelOffset:O(a,c),strategy:l??null,inertia:!!u,line:r})}else if(o=p.exec(e))j={parent:C(o[1]),children:[],line:r},s.pipelines.push(j);else if(o=m.exec(e))s.trends.push({nodeId:C(o[1]),targetEvolution:E(o[2],r),line:r});else if(o=h.exec(e))s.annotations.push({number:o[1],...D(o[2],o[3],r),...S(o[4],r),line:r});else if(o=g.exec(e))s.annotationBox?T(`box`,r,`只使用第一个注释框`,`Only the first annotation box is used`):s.annotationBox=D(o[1],o[2],r);else if((o=_.exec(e))&&(o[2]||o[3]||o[7]||o[8]||o[1].startsWith(`"`)||o[6].startsWith(`"`))){let[,e,t,n,i,a,c,l,u]=o,d=t||l||a&&`+${a}`,{text:f,icon:p}=S(i??u??``,r);s.links.push({from:C(e),to:C(c),dashed:n===`-.->`,flow:{"+>":`forward`,"+<":`backward`,"+<>":`bidirectional`}[d]||`none`,label:f,icon:p,line:r})}else A.push({text:e,line:r})}j&&w(j.line,`演进管道缺少结束括号`,`Unclosed pipeline`);for(let e of s.pipelines){let t=b.get(e.parent);if(t?.kind!==`component`)w(e.line,`管道父级「${e.parent}」不是组件`,`Pipeline parent "${e.parent}" is not a component`);else for(let n of e.children)k({...n,visibility:t.visibility})}let N=new Map;for(let e of s.nodes)e.parent&&!N.has(e.name)&&N.set(e.name,e.id);let P=e=>b.has(e)?e:N.get(e)??e;for(let{text:e,line:t}of A){let n;for(let{index:t,0:r}of e.matchAll(/\s+/g)){let i=e.slice(0,t),a=e.slice(t+r.length);if(b.has(P(i))&&b.has(P(a))){n=[i,a];break}}n?s.links.push({from:n[0],to:n[1],dashed:!1,flow:`none`,label:``,line:t}):w(t,`无法识别 Wardley 地图语句`,`Unrecognized Wardley map statement`)}s.links.sort((e,t)=>e.line-t.line);for(let e of s.links)e.from=P(e.from),e.to=P(e.to),b.has(e.from)&&b.has(e.to)||w(e.line,`依赖引用未定义的节点`,`Dependency references an undefined node`);for(let e of s.trends)e.nodeId=P(e.nodeId),b.has(e.nodeId)||T(`trend`,e.line,`演进引用未定义的组件`,`Evolution references an undefined component`);return(s.nodes.length>300||s.links.length+s.trends.length>600)&&w(i,`地图超过 300 个节点或 600 条连线,请拆分`,`Split maps exceeding 300 nodes or 600 connections`),{model:s,errors:c}}var T=(e,t,n,r)=>({x:e,y:t,w:n,h:r}),E=(e,t,n,r)=>T(e-n/2,t-r/2,n,r),D=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h,O=(e,t)=>T(e.x-t,e.y-t,e.w+t*2,e.h+t*2),k=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y);function A(e,t,n){let r=0,i=1;for(let[a,o]of[[`x`,`w`],[`y`,`h`]]){let s=t[a]-e[a];if(!s){if(e[a]<n[a]||e[a]>n[a]+n[o])return!1;continue}let c=(n[a]-e[a])/s,l=(n[a]+n[o]-e[a])/s;if(r=Math.max(r,Math.min(c,l)),i=Math.min(i,Math.max(c,l)),r>i)return!1}return[r,i]}var j=(e,t,n)=>!!A(e,t,n);function M(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=i*i+a*a;if(!o)return[];let s=n.map(n=>A(e,t,n)).filter(Boolean);for(let t of r){if(!t.every(t=>Math.abs(i*(t.y-e.y)-a*(t.x-e.x))<1e-5))continue;let[n,r]=t.map(t=>(i*(t.x-e.x)+a*(t.y-e.y))/o).sort((e,t)=>e-t);n<1&&r>0&&s.push([Math.max(0,n),Math.min(1,r)])}let c=0,l=[];for(let[e,t]of[...s.sort((e,t)=>e[0]-t[0]),[1,1]])e-c>1e-7&&l.push([c,e]),c=Math.max(c,t);return l.map(t=>t.map(t=>({x:e.x+t*i,y:e.y+t*a})))}var N=(e,t,n)=>{let r=n/(k(e,t)||1);return{x:e.x+(t.x-e.x)*r,y:e.y+(t.y-e.y)*r}},P=(e,t,n,r)=>{let i=N(n,t,7),a=i.y-n.y,o=n.x-i.x;return e.path(`M${n.x} ${n.y} L${i.x+a*.48} ${i.y+o*.48} L${i.x-a*.48} ${i.y-o*.48} Z`,{fill:r})};function F(e,{width:r,lang:i,ctx:a},o={}){let s=(0,t.appearance)(a),c=a.color(`muted`),l=a.color(`grid`),u=s.fg4,d=(0,n.mapConfig)(o.config,`wardley`),f=e.stages.map(e=>[{text:e.name+(e.secondName===null?``:` /`),icons:[e.icon].filter(Boolean)},...e.secondName===null?[]:[{text:e.secondName,icons:[e.secondIcon].filter(Boolean)}]].flatMap(({text:e,icons:t})=>e.split(`
3
- `).map((e,n)=>({text:e,icons:n===0?t:[]})))),p=e=>e?20:0,m=({text:e,icons:n})=>a.measure(e,t.FONT.label.size,400)+n.length*20,h=e.stages.map((e,t)=>(e.boundary??100*(t+1)/f.length)/100),g=e=>h[e]-(h[e-1]||0),_=Math.max(...f.map((e,t)=>(Math.max(...e.map(m))+22)/g(t))),v=(e,t)=>typeof e==`number`&&Number.isFinite(e)?Math.max(0,Math.min(16e3,e)):t,y=Math.max(96+_,420,v(e.size?.width??(0,n.mapConfig)(d,`width`),900)),C=y-48,w=C-48,A=f.map((t,n)=>{if(t.length!==2||e.stages[n].secondName===null||[e.stages[n].name,e.stages[n].secondName].some(e=>e.includes(`
4
- `)))return t;let r={text:t.map(e=>e.text).join(` `),icons:t.flatMap(e=>e.icons)};return m(r)+22<=w*g(n)?[r]:t}),F=e.title||e.titleIcon?a.wrap(e.title,w-p(e.titleIcon),t.FONT.title.size,t.FONT.title.weight):[],I=48+Math.max(0,F.length-1)*16,L=Math.max(0,...A.map(e=>e.length-2))*16,R=Math.max(I+212+L,v(e.size?.height??(0,n.mapConfig)(d,`height`),600)),z=R-86-L,ee=z-I,B=({evolution:e,visibility:t})=>({x:48+w*e/100,y:z-ee*t/100}),V=new Map(e.nodes.map(e=>[e.id,{...e,...B(e),r:e.strategy?10:5}])),H=[],te=[],U=[],W=[],G=[],ne=[],K=[],q=[],J=[],re=e.annotations.slice().sort((e,t)=>Number(e.number)-Number(t.number)),Y=(e,t={})=>({stroke:e,"stroke-width":1,...t}),ie=(e,t,n,r)=>a.line(e.x,e.y,t.x,t.y,Y(n,r)),ae=(e,t)=>{ne.push(ie(e,t,s.fg4,{"stroke-dasharray":`2 3`,meta:{kind:`leader`}})),J.push([e,t])},X=(e,n,r,i=t.FONT.label,o=s.fg1,c=`middle`,l)=>(0,t.textBlock)(a,{x:e,y:n,lines:r,font:i,fill:o,anchor:c,lineHeight:16,meta:l}),Z=(e,t,r,i,o,c=s.fg1,l=`middle`)=>{if(!i)return X(e,t,r,o,c,l);let u=Math.max(0,...r.map(e=>a.measure(e,o.size,o.weight))),d=p(i);return a.el(`g`,{},[X(e+d*(l===`middle`?.5:1),t,r,o,c,l),(0,n.mapIcon)(a,i,e-(l===`middle`?(u+d)/2:0)+7,t,c)])},Q={...t.FONT.label,weight:650},oe=[],se=[];for(let t of e.pipelines){let e=V.get(t.parent),n=t.children.map(e=>V.get(e.id)).filter(Boolean).sort((e,t)=>e.x-t.x);if(!e||!n.length)continue;let r=n[0].x-16,i=n.at(-1).x-r+16;e.x=r+i/2,e.y-=25,e.square=!0,te.push(a.rect(r,n[0].y-15,i,30,{rx:s.smallRadius,fill:a.tint(s.bg,a.frameTone(a.color(`tone1`)),.07),stroke:a.tint(s.bg,a.frameTone(a.color(`tone1`)),.45),meta:{kind:`frame`,id:t.parent}})),se.push({children:n,bottom:n[0].y+15});for(let e=1;e<n.length;e++)oe.push({from:n[e-1].id,to:n[e].id,dashed:!0})}for(let e of V.values())K.push(E(e.x,e.y,e.r*2,e.r*2)),e.inertia&&K.push(E(e.x+e.r+6,e.y,3,20));let ce=(e,t)=>{let n=B(e),r=[n];for(let e of[t+5,22,32,46,64])for(let[t,i]of[[0,-1],[1,0],[-1,0],[0,1],[1,-1],[-1,-1],[1,1],[-1,1]])r.push({x:n.x+t*e,y:n.y+i*e});let i=[...K,...q],{x:a,y:o}=r.find(e=>{let r=O(E(e.x,e.y,t*2,t*2),3);return!i.some(e=>D(r,e))&&!J.some(([e,t])=>j(e,t,r))&&(e===n||!q.some(t=>j(n,e,O(t,2))))})||n;return K.push(E(a,o,t*2,t*2)),(a!==n.x||o!==n.y)&&ae(n,N({x:a,y:o},n,t)),{...e,x:a,y:o,radius:t}},le=e.forces.map(e=>{let t=B(e);return K.push(E(t.x,t.y,40,20)),{...e,...t}}),$=R;function ue(e,n,r={}){let{font:i=t.FONT.label,fill:o=s.fg1,radius:c=6,preferred:u,fixed:d,plate:f,meta:m,icon:h,clearance:g=2}=r,_=a.wrap(e,Math.min(260,w/2)-p(h),i.size,i.weight),v=Math.max(..._.map(e=>a.measure(e,i.size,i.weight)))+p(h)+(f?14:4),b=_.length*16+(f?6:2),x=c+v/2+6,S=c+b/2+6,C=u?[u]:[];for(let e of[0,12,26,44,68,98,136]){let t=[[x+e,-e/4],[x+e,-S-e/2],[-x-e,0],[0,S+e],[0,-S-e],[-x-e,-S-e/2],[x+e,S+e/2],[-x-e,S+e/2]];r.above&&t.unshift(t.splice(4,1)[0]);for(let[e,r]of t)C.push({x:n.x+e,y:n.y+r})}let T=e=>{if(k(n,e)<=Math.hypot(x,S)+10)return null;let t=Math.min((v/2+1)/Math.abs(e.x-n.x),(b/2+1)/Math.abs(e.y-n.y));return[N(n,e,c+3),N(e,n,k(n,e)*t)]},A=d||C.find(e=>{let{x:t,y:n}=e,r=T(e);if(r&&[...K,...q].some(e=>j(...r,O(e,2))))return!1;let i=O(E(t,n,v,b),g);return i.x>31&&i.x+i.w<y-8&&i.y>I-20&&i.y+i.h<z+9&&!K.some(e=>D(i,e))&&!q.some(e=>D(i,e))&&!J.some(([e,t])=>j(e,t,i))}),M=!d&&A&&T(A);M&&ae(...M),A||(A={x:48+v/2,y:$+b/2+4},$+=b+8);let{x:P,y:F}=A,L=E(P,F,v,b);q.push(L);let R=Z(P,F,_,h,i,o);d&&J.some(([e,t])=>j(e,t,L))&&G.push(a.rect(L.x,L.y,L.w,L.h,{fill:s.bg,rx:s.smallRadius})),G.push(f?{...a.el(`g`,{},[a.rect(L.x,L.y,L.w,L.h,{fill:s.bg,stroke:l,rx:s.smallRadius}),R]),...m?{meta:m}:{}}:R)}let de=[],fe=[],pe=[...V.values()].map(e=>({id:e.id,...O(E(e.x,e.y,e.r*2,e.r*2),2)}));function me(e,t,n,r=!1){let i=r?s.danger:c,o=k(e,t),l=(e,t)=>e.r?Math.min(o/2,(e.square||e.kind===`anchor`?e.r*o/Math.max(Math.abs(e.x-t.x),Math.abs(e.y-t.y),1e-9):e.r)+1):0,u=N(e,t,l(e,t)),d=N(t,e,l(t,e)),f=M(u,d,pe.filter(n=>n.id!==e.id&&n.id!==t.id),fe);fe.push(...f),J.push(...f);let p=f.map(([e,t])=>`M${e.x} ${e.y} L${t.x} ${t.y}`).join(` `);if(p){let o=a.path(p,{fill:`none`,...Y(i,{"stroke-width":r?1.5:1.2,...n.dashed||r?{"stroke-dasharray":r?`5 4`:`3 4`}:{},meta:{kind:`edge`,from:e.id,to:t.id??`trend:${e.id}`}})}),s=f.length!==1||k(f[0][0],u)>1e-5||k(f[0][1],d)>1e-5;U.push(!r&&s?a.titled(o,`${e.label} → ${t.label}`):o)}(r||n.flow===`forward`||n.flow===`bidirectional`)&&U.push(P(a,u,d,i)),(n.flow===`backward`||n.flow===`bidirectional`)&&U.push(P(a,d,u,i)),(n.label||n.icon)&&de.push({link:n,point:N(u,d,k(u,d)/2)})}let he=[...oe,...e.links].map(e=>({link:e,a:V.get(e.from),b:V.get(e.to)})).filter(({a:e,b:t})=>e&&t&&e.parent!==t.id&&t.parent!==e.id);he.sort((e,t)=>k(e.a,e.b)-k(t.a,t.b));for(let{a:e,b:t,link:n}of he)me(e,t,n);for(let{nodeId:t,targetEvolution:n}of e.trends){let e=V.get(t);e&&me(e,{x:B({evolution:n,visibility:e.visibility}).x,y:e.y},{},!0)}F.length&&H.push(Z(y/2,23+(F.length-1)*8,F,e.titleIcon,t.FONT.title)),H.push(a.line(48,I,48,z,Y(u)),a.line(48,z,C,z,Y(u)));let ge=(I+z)/2;H.push(a.el(`g`,{transform:`rotate(-90 18 ${ge})`},[X(18,ge,[b(i,`visibility`)],Q,s.fg2)])),H.push(X((48+C)/2,z+64+L,[b(i,`evolution`)],Q,s.fg2)),A.forEach((e,r)=>{let i=48+w*(h[r-1]||0),o=48+w*h[r];r&&H.push(a.line(i,I,i,z,Y(l)));let c=(i+o)/2;e.forEach(({text:e,icons:r},i)=>{let o=z+25+i*16;H.push(X(c+r.length*10,o,[e],t.FONT.label,s.fg2)),r.forEach((t,i)=>H.push((0,n.mapIcon)(a,t,c-m({text:e,icons:r})/2+i*20+7,o,s.fg2)))})});let _e=e=>{let n=e.labelOffset&&{x:e.x+e.labelOffset.dx,y:e.y+e.labelOffset.dy},r=e.kind===`anchor`||e.square;ue(e.label,e,{radius:e.r,fixed:n,icon:e.icon,above:r,font:r?Q:t.FONT.label})};for(let e of V.values())e.labelOffset&&_e(e);let ve=new Set;for(let e of se){let n=e.children.filter(e=>!e.labelOffset).map(e=>{let t=Math.min(260,w/2)-p(e.icon),n=a.wrap(e.label,t,12);return{node:e,rows:n,w:Math.max(...n.map(e=>a.measure(e,12,400)))+p(e.icon)+8}});if(!n.length)continue;let r=Math.max(...n.map(e=>e.rows.length))*16,i=n.reduce((e,t)=>e+t.w,0),o=48,s=i,c=n.map(({node:e,w:t})=>{let n=Math.max(o,Math.min(e.x-t/2,C-s));return s-=t,o=n+t,n+t/2}),l=e.bottom+8+r/2,u=e=>n.map(({w:t},n)=>E(c[n],e,t,r)),d=l;for(;d+r/2<z&&u(d).some(e=>[...K,...q].some(t=>D(e,t))||J.some(([t,n])=>j(t,n,e)));)d+=12;(d+r/2>=z||i>w)&&(d=$+r/2+4,$+=r+8),q.push(...u(d)),n.forEach(({node:e,rows:n},i)=>{ve.add(e.id),G.push(Z(c[i],d-(r-n.length*16)/2,n,e.icon,t.FONT.label))})}let ye=re.map(e=>ce(e,Math.max(9,a.measure(e.number,12,650)/2+4))),be=e.notes.map(e=>ce(e,2));for(let{link:e,point:t}of de)ue(e.label,t,{plate:!0,above:!0,radius:0,icon:e.icon,meta:{kind:`edge-label-group`,from:e.from,to:e.to}});for(let e of V.values()){let{x:t,y:n,r,id:i,strategy:o,inertia:l,square:u}=e,d=e.kind===`anchor`,f={kind:`node`,id:i},p=a.frameTone(a.color(S[o]||`tone1`)),m={fill:d?s.fg1:o?a.tint(s.bg,p,.16):s.node,stroke:a.frameTone(c),"stroke-width":1.4,meta:f};u?W.push(a.rect(t-r,n-r,2*r,2*r,{...m,rx:2})):d?W.push(a.rect(t-r,n-r,2*r,2*r,{...m,rx:3})):W.push(a.circle(t,n,r,m)),o&&W.push(a.titled(X(t,n,[x[o]],Q,a.textOn(m.fill)),o)),l&&W.push(a.rect(t+r+4.5,n-10,3,20,{rx:1,fill:c})),!e.labelOffset&&!ve.has(i)&&_e(e)}for(let e of be)W.push(a.circle(e.x,e.y,2,{fill:c})),ue(e.text,e,{plate:!0,radius:2,clearance:12,fill:s.fg2,icon:e.icon});for(let e of le){let t=e.kind===`accelerator`?1:-1,n=[[-20,-5],[6,-5],[6,-10],[20,0],[6,10],[6,5],[-20,5]].map(([n,r])=>`${e.x+n*t},${e.y+r}`);W.push(a.shape(`polygon`,{points:n.join(` `),fill:s.node,stroke:c,"stroke-width":1.3})),ue(e.name,e,{preferred:{x:e.x,y:e.y+24},radius:20,icon:e.icon})}for(let e of ye)W.push(a.circle(e.x,e.y,e.radius,{fill:s.bg,stroke:c,"stroke-width":1.4})),W.push(X(e.x,e.y,[e.number],Q));if(re.length){let n=re.flatMap(({number:e,text:t,icon:n})=>a.wrap(`${e}. ${t}`,Math.min(270,w/2)-p(n),12).map((e,t)=>({row:e,icon:t===0?n:null}))),o=Math.max(...n.map(({row:e,icon:t})=>a.measure(e,12,400)+p(t)))+28,c=n.length*16+35,u=e.annotationBox?B(e.annotationBox):{x:C,y:z},d=T(Math.max(34,Math.min(y-o-10,u.x)),Math.min(z-c-5,u.y),o,c),f=r>=480&&d.y>=I&&![...K,...q].some(e=>D(O(d,4),e))&&!J.some(([e,t])=>j(e,t,O(d,3))),m=f?d:T(48,$,o,c);f||($+=c+8),G.push(a.rect(m.x,m.y,m.w,m.h,{rx:s.radius,fill:s.node,stroke:l,meta:{kind:`frame`,id:`annotations`}}),X(m.x+14,m.y+14,[b(i,`annotations`)],Q,s.fg1,`start`),...n.map(({row:e,icon:n},r)=>Z(m.x+14,m.y+35+r*16,[e],n,t.FONT.label,s.fg2,`start`)))}let xe=Object.keys(x).filter(t=>e.nodes.some(e=>e.strategy===t));if(xe.length){let e=a.wrap(xe.map(e=>`${x[e]} · ${b(i,e)}`).join(` / `),w,12);G.push(X(48,$+e.length*8,e,t.FONT.label,s.fg2,`start`)),$+=e.length*16+8}let Se=y>r*2||V.size>60?[(0,t.warning)(`LARGE_DIAGRAM`,i,o.headerLine||1,`地图较大,可拆成多张地图`,`Large map; consider splitting it into smaller maps`)]:[];return{scene:{width:y,height:$+8,title:e.title||void 0,children:[...H,...te,...U,...ne,...W,...G]},errors:Se}}return e.implementations={"wardley-beta":{parse:w,layout:F,honoredConfig:[`wardley.width`,`wardley.height`]}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/map-label`]);
1
+ KChartUnits["diagram/wardley"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=String.raw`\d+\.\d+`,i=String.raw`\d+(?:\.\d+)?`,a=String.raw`"(?:\\.|[^"\\])*"`,o=String.raw`(?:${a}|[A-Za-z_](?:[\w()&]|-(?![-.>]))*(?:[ \t]+[A-Za-z(](?:[\w()&]|-(?![-.>]))*)*)`,s=e=>String.raw`\[\s*(${e})\s*,\s*(${e})\s*\]`,c=String.raw`(?:\s+label\s*${s(`-?\\d+`)})?`,l=new RegExp(String.raw`^size\s*${s(`\\d+`)}$`),u=new RegExp(String.raw`^(component|anchor|note|accelerator|deaccelerator)\s+(${o})\s*${s(r)}${c}(?:\s+\((build|buy|outsource|market)\))?(?:\s+(inertia|\(inertia\)))?$`),d=new RegExp(String.raw`^component\s+(${o})\s*\[\s*(${r})\s*\]${c}$`),f=new RegExp(String.raw`^(${o})(?:\s*@\s*(${r}))?(?:\s*/\s*(${o}))?$`),p=new RegExp(String.raw`^pipeline\s+(${o})\s*\{$`),m=new RegExp(String.raw`^evolve\s+(${o})\s+(${r})$`),h=new RegExp(String.raw`^annotation\s+(\d+)\s*,\s*${s(i)}\s+(${a})$`),g=new RegExp(String.raw`^annotations\s*${s(i)}$`),_=new RegExp(String.raw`^(${o})\s*(\+<>|\+>|\+<)?\s*(-->|-\.->|->|>|\+'([^']*)'(<>|<|>))?\s*(${o})\s*(\+<>|\+>|\+<)?\s*(?:;\s*(.+))?$`),v=[[`起源`,`Genesis`],[`定制`,`Custom Built`],[`产品`,`Product`],[`商品`,`Commodity`]],y={visibility:[`可见度`,`Visibility`],evolution:[`演化`,`Evolution`],annotations:[`注释`,`Annotations`],build:[`自建`,`build`],buy:[`采购`,`buy`],outsource:[`外包`,`outsource`],market:[`市场`,`market`]},b=(e,n)=>(0,t.message)(e,...y[n]),x={build:`B`,buy:`Y`,outsource:`O`,market:`M`},S={build:`tone1`,buy:`tone2`,outsource:`tone3`,market:`tone4`},C=e=>e.startsWith(`"`)?e.slice(1,-1).replace(/\\(["\\])/g,`$1`):e;function w(e,{lang:r,firstLine:i=2,title:a=``,headerLine:o=1}={}){let s={type:`wardley`,title:a,size:null,stages:v.map(e=>({name:e[+!!(0,t.isEn)(r)],secondName:null,boundary:null})),nodes:[],pipelines:[],links:[],trends:[],notes:[],annotations:[],annotationBox:null,forces:[]},c=[],y=new Set,b=new Map,x=(0,n.mapLabels)(r,e=>c.push(e)),S=(e,t)=>x(C(e),t);a&&({text:s.title,icon:s.titleIcon}=x(a,o));let w=(e,n,i,a,o)=>c.push((0,t.error)(r,e,n,i,a,o)),T=(e,n,i,a,o,s)=>{y.has(e)||(y.add(e),c.push((0,t.warning)(`DIAGRAM_HINT`,r,n,i,a,o,s)))},E=(e,t)=>{let n=Number(e);return n>100&&w(t,`坐标超出 0–100 范围`,`Coordinate is outside 0–100`,`使用 0.0–1.0 的比例或 0.0–100.0 的百分数,例如 0.3`,`Use a decimal fraction from 0.0 to 1.0 or a percentage up to 100.0, such as 0.3`),n<=1?n*100:n},D=(e,t,n)=>({visibility:E(e,n),evolution:E(t,n)}),O=(e,t)=>e==null?null:{dx:+e,dy:+t},k=e=>{let t=b.get(e.id);t?(t.visibility!==e.visibility||t.evolution!==e.evolution)&&w(e.line,`「${e.id}」有不同的坐标`,`Conflicting coordinates for "${e.id}"`,`保留一处声明,或给不同的节点使用不同的名称`,`Keep one declaration or give distinct nodes different names`):(b.set(e.id,e),s.nodes.push(e))};if(e.length>2e5)return w(i,`地图源文本过长`,`Map source exceeds 200,000 characters`,`拆成多张地图,每张最多 200,000 个字符`,`Split into maps of at most 200,000 characters each`),{model:s,errors:c};let A=[],j=null,M=!1;for(let[t,n]of e.split(`
2
+ `).entries()){let e=n.match(/^(?:"(?:\\.|[^"\\])*"|\+'[^']*'|%(?!%)|[^"%])*/)[0].trim(),r=i+t;if(!e)continue;let o;if(j){if(e===`}`)j.children.length||w(r,`演进管道没有组件`,`Pipeline needs at least one component`,`在 } 前添加组件,例如 component Child [0.4]`,`Add a component before }, for example component Child [0.4]`),j=null;else if(o=d.exec(e)){let[,e,t,n,i]=o,{text:a,icon:s}=S(e,r);j.children.push({id:`${j.parent}_${C(e)}`,name:C(e),label:a,icon:s,evolution:E(t,r),labelOffset:O(n,i),kind:`pipeline`,parent:j.parent,line:r})}else w(r,`无效的演进管道组件`,`Invalid pipeline component`,`管道内只填写演进坐标,例如 component Child [0.4]`,`Use one evolution coordinate inside a pipeline, as in component Child [0.4]`)}else if(M)e.includes(`}`)&&(M=!1);else if(o=/^title\s*:?[ \t]+(.+)$/.exec(e))a||({text:s.title,icon:s.titleIcon}=S(o[1],r));else if(/^acc(?:Title|Descr)\s*:/.test(e))continue;else if(/^accDescr\s*\{/.test(e))M=!e.includes(`}`);else if(o=l.exec(e))s.size={width:Number(o[1]),height:Number(o[2])},Object.values(s.size).some(e=>e>16e3)&&w(r,`地图尺寸超过 16000 像素`,`Map size exceeds 16,000 pixels`,`减小 size [宽, 高],两项均不得超过 16000`,`Reduce both dimensions in size [width, height] to at most 16000`);else if(e.startsWith(`evolution `)){let t=e.slice(10).match(/"(?:\\.|[^"\\])*"|->|[^"-]+|-/g)||[],n=[``];for(let e of t)e===`->`?n.push(``):n[n.length-1]+=e;let i=n.map(e=>f.exec(e.trim()));if(i.length<2||i.some(e=>!e))w(r,`无效的演进阶段`,`Invalid evolution stages`,`用 -> 分隔至少两个阶段,例如 evolution Genesis -> Product`,`Separate at least two stages with ->, as in evolution Genesis -> Product`);else{s.stages=i.map(([,e,t,n])=>{let i=S(e,r),a=n?S(n,r):null;return{name:i.text,icon:i.icon,secondName:a?.text??null,secondIcon:a?.icon,boundary:t==null?null:E(t,r)}});let e=s.stages.map(e=>e.boundary);if(e.some(e=>e!==null)&&(e.some((t,n)=>t===null||t<=(e[n-1]??0))||e.at(-1)!==100)){T(`stages`,r,`阶段边界不完整或未递增至 100;使用等宽阶段`,`Incomplete or unordered stage boundaries; using equal bands`,`为每个阶段写递增边界,例如 evolution Genesis @ 0.4 -> Product @ 1.0`,`Give each stage an increasing boundary, as in evolution Genesis @ 0.4 -> Product @ 1.0`);for(let e of s.stages)e.boundary=null}}}else if(o=u.exec(e)){let[,e,t,n,i,a,c,l,u]=o,{text:d,icon:f}=S(t,r),p=D(n,i,r);e!==`component`&&(a!=null||l||u)||e===`note`&&!t.startsWith(`"`)?w(r,`无效的装饰或备注`,`Invalid decorator or note`,`只给 component 添加装饰;备注使用 note "文字" [0.3, 0.2]`,`Apply decorators only to component; write notes as note "Text" [0.3, 0.2]`):e===`note`?s.notes.push({text:d,icon:f,...p,line:r}):e.endsWith(`accelerator`)?s.forces.push({kind:e,name:d,icon:f,...p,line:r}):k({id:C(t),label:d,icon:f,kind:e,...p,labelOffset:O(a,c),strategy:l??null,inertia:!!u,line:r})}else if(o=p.exec(e))j={parent:C(o[1]),children:[],line:r},s.pipelines.push(j);else if(o=m.exec(e))s.trends.push({nodeId:C(o[1]),targetEvolution:E(o[2],r),line:r});else if(o=h.exec(e))s.annotations.push({number:o[1],...D(o[2],o[3],r),...S(o[4],r),line:r});else if(o=g.exec(e))s.annotationBox?T(`box`,r,`只使用第一个注释框`,`Only the first annotation box is used`,`只保留一条 annotations [x, y] 语句`,`Keep only one annotations [x, y] statement`):s.annotationBox=D(o[1],o[2],r);else if((o=_.exec(e))&&(o[2]||o[3]||o[7]||o[8]||o[1].startsWith(`"`)||o[6].startsWith(`"`))){let[,e,t,n,i,a,c,l,u]=o,d=t||l||a&&`+${a}`,{text:f,icon:p}=S(i??u??``,r);s.links.push({from:C(e),to:C(c),dashed:n===`-.->`,flow:{"+>":`forward`,"+<":`backward`,"+<>":`bidirectional`}[d]||`none`,label:f,icon:p,line:r})}else A.push({text:e,line:r})}j&&w(j.line,`演进管道缺少结束括号`,`Unclosed pipeline`,`在管道的最后一个组件之后单独写一行 }`,`Add } on its own line after the last pipeline component`);for(let e of s.pipelines){let t=b.get(e.parent);if(t?.kind!==`component`)w(e.line,`管道父级「${e.parent}」不是组件`,`Pipeline parent "${e.parent}" is not a component`,`先声明同名 component,例如 component Parent [0.3, 0.2]`,`Declare a component with the same name, as in component Parent [0.3, 0.2]`);else for(let n of e.children)k({...n,visibility:t.visibility})}let N=new Map;for(let e of s.nodes)e.parent&&!N.has(e.name)&&N.set(e.name,e.id);let P=e=>b.has(e)?e:N.get(e)??e;for(let{text:e,line:t}of A){let n;for(let{index:t,0:r}of e.matchAll(/\s+/g)){let i=e.slice(0,t),a=e.slice(t+r.length);if(b.has(P(i))&&b.has(P(a))){n=[i,a];break}}n?s.links.push({from:n[0],to:n[1],dashed:!1,flow:`none`,label:``,line:t}):w(t,`无法识别 Wardley 地图语句`,`Unrecognized Wardley map statement`,`用 component "需求" [0.3, 0.2] 声明组件;连线使用 "需求" --> "网关",名称外不要加方括号`,`Declare components as component "Demand" [0.3, 0.2]; link them as "Demand" --> "Gateway" without square brackets around names`)}s.links.sort((e,t)=>e.line-t.line);for(let e of s.links){e.from=P(e.from),e.to=P(e.to);let t=[e.from,e.to].find(e=>!b.has(e));t!==void 0&&w(e.line,`依赖引用未定义的节点「${t}」`,`Dependency references undefined node "${t}"`,`声明同名组件,例如 component Gateway [0.4, 0.3],或更正连线端点名称`,`Declare a matching component, as in component Gateway [0.4, 0.3], or correct the endpoint name`)}for(let e of s.trends)e.nodeId=P(e.nodeId),b.has(e.nodeId)||T(`trend`,e.line,`演进引用未定义的组件`,`Evolution references an undefined component`,`将 evolve 后的名称改为已声明的组件,例如 evolve Gateway 0.7`,`Use a declared component name after evolve, as in evolve Gateway 0.7`);return(s.nodes.length>300||s.links.length+s.trends.length>600)&&w(i,`地图超过 300 个节点或 600 条连线,请拆分`,`Map exceeds 300 nodes or 600 connections`,`按主题拆分地图,每张最多 300 个节点、600 条连线`,`Split the map by topic into maps of at most 300 nodes and 600 connections`),{model:s,errors:c}}var T=(e,t,n,r)=>({x:e,y:t,w:n,h:r}),E=(e,t,n,r)=>T(e-n/2,t-r/2,n,r),D=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h,O=(e,t)=>T(e.x-t,e.y-t,e.w+t*2,e.h+t*2),k=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y);function A(e,t,n){let r=0,i=1;for(let[a,o]of[[`x`,`w`],[`y`,`h`]]){let s=t[a]-e[a];if(!s){if(e[a]<n[a]||e[a]>n[a]+n[o])return!1;continue}let c=(n[a]-e[a])/s,l=(n[a]+n[o]-e[a])/s;if(r=Math.max(r,Math.min(c,l)),i=Math.min(i,Math.max(c,l)),r>i)return!1}return[r,i]}var j=(e,t,n)=>!!A(e,t,n);function M(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=i*i+a*a;if(!o)return[];let s=n.map(n=>A(e,t,n)).filter(Boolean);for(let t of r){if(!t.every(t=>Math.abs(i*(t.y-e.y)-a*(t.x-e.x))<1e-5))continue;let[n,r]=t.map(t=>(i*(t.x-e.x)+a*(t.y-e.y))/o).sort((e,t)=>e-t);n<1&&r>0&&s.push([Math.max(0,n),Math.min(1,r)])}let c=0,l=[];for(let[e,t]of[...s.sort((e,t)=>e[0]-t[0]),[1,1]])e-c>1e-7&&l.push([c,e]),c=Math.max(c,t);return l.map(t=>t.map(t=>({x:e.x+t*i,y:e.y+t*a})))}var N=(e,t,n)=>{let r=n/(k(e,t)||1);return{x:e.x+(t.x-e.x)*r,y:e.y+(t.y-e.y)*r}},P=(e,t,n,r)=>{let i=N(n,t,7),a=i.y-n.y,o=n.x-i.x;return e.path(`M${n.x} ${n.y} L${i.x+a*.48} ${i.y+o*.48} L${i.x-a*.48} ${i.y-o*.48} Z`,{fill:r})};function F(e,{width:r,lang:i,ctx:a,compact:o=!1,embedHeading:s},c={}){let l=(0,t.appearance)(a),u=a.color(`muted`),d=a.color(`grid`),f=l.fg4,p=o?{...t.FONT.title,size:13}:t.FONT.title,m=(0,n.mapConfig)(c.config,`wardley`),h=e.stages.map(e=>[{text:e.name+(e.secondName===null?``:` /`),icons:[e.icon].filter(Boolean)},...e.secondName===null?[]:[{text:e.secondName,icons:[e.secondIcon].filter(Boolean)}]].flatMap(({text:e,icons:t})=>e.split(`
3
+ `).map((e,n)=>({text:e,icons:n===0?t:[]})))),g=e=>e?20:0,_=({text:e,icons:n})=>a.measure(e,t.FONT.label.size,400)+n.length*20,v=e.stages.map((e,t)=>(e.boundary??100*(t+1)/h.length)/100),y=e=>v[e]-(v[e-1]||0),C=Math.max(...h.map((e,t)=>(Math.max(...e.map(_))+22)/y(t))),w=(e,t)=>typeof e==`number`&&Number.isFinite(e)?Math.max(0,Math.min(16e3,e)):t,A=Math.max(96+C,Math.min(720,540+e.nodes.length*4+e.links.length*2)),F=o?A:Math.max(96+C,420,w(e.size?.width??(0,n.mapConfig)(m,`width`),900)),I=F-48,L=I-48,R=h.map((t,n)=>{if(t.length!==2||e.stages[n].secondName===null||[e.stages[n].name,e.stages[n].secondName].some(e=>e.includes(`
4
+ `)))return t;let r={text:t.map(e=>e.text).join(` `),icons:t.flatMap(e=>e.icons)};return _(r)+22<=L*y(n)?[r]:t}),z=!s&&(e.title||e.titleIcon)?a.wrap(e.title,L-g(e.titleIcon),p.size,p.weight):[],B=48+Math.max(0,z.length-1)*16,ee=Math.max(0,...R.map(e=>e.length-2))*16,te=Math.max(B+212+ee,Math.min(540,400+e.nodes.length*2+e.links.length)),ne=o?te:Math.max(B+212+ee,w(e.size?.height??(0,n.mapConfig)(m,`height`),600)),V=ne-86-ee,re=V-B,H=({evolution:e,visibility:t})=>({x:48+L*e/100,y:V-re*t/100}),U=new Map(e.nodes.map(e=>[e.id,{...e,...H(e),r:e.strategy?10:5}])),W=[],ie=[],ae=[],G=[],K=[],oe=[],q=[],J=[],Y=[],se=e.annotations.slice().sort((e,t)=>Number(e.number)-Number(t.number)),X=(e,t={})=>({stroke:e,"stroke-width":1,...t}),ce=(e,t,n,r)=>a.line(e.x,e.y,t.x,t.y,X(n,r)),le=(e,t)=>{oe.push(ce(e,t,l.fg4,{"stroke-dasharray":`2 3`,meta:{kind:`leader`}})),Y.push([e,t])},Z=(e,n,r,i=t.FONT.label,o=l.fg1,s=`middle`,c)=>(0,t.textBlock)(a,{x:e,y:n,lines:r,font:i,fill:o,anchor:s,lineHeight:16,meta:c}),ue=(e,t,r,i,o,s=l.fg1,c=`middle`)=>{if(!i)return Z(e,t,r,o,s,c);let u=Math.max(0,...r.map(e=>a.measure(e,o.size,o.weight))),d=g(i);return a.el(`g`,{},[Z(e+d*(c===`middle`?.5:1),t,r,o,s,c),(0,n.mapIcon)(a,i,e-(c===`middle`?(u+d)/2:0)+7,t,s)])},Q={...t.FONT.label,weight:650},de=[],fe=[];for(let t of e.pipelines){let e=U.get(t.parent),n=t.children.map(e=>U.get(e.id)).filter(Boolean).sort((e,t)=>e.x-t.x);if(!e||!n.length)continue;let r=n[0].x-16,i=n.at(-1).x-r+16;e.x=r+i/2,e.y-=25,e.square=!0,ie.push(a.rect(r,n[0].y-15,i,30,{rx:l.smallRadius,fill:a.tint(l.bg,a.frameTone(a.color(`tone1`)),.07),stroke:a.tint(l.bg,a.frameTone(a.color(`tone1`)),.45),meta:{kind:`frame`,id:t.parent}})),fe.push({children:n,bottom:n[0].y+15});for(let e=1;e<n.length;e++)de.push({from:n[e-1].id,to:n[e].id,dashed:!0})}for(let e of U.values())q.push(E(e.x,e.y,e.r*2,e.r*2)),e.inertia&&q.push(E(e.x+e.r+6,e.y,3,20));let pe=(e,t)=>{let n=H(e),r=[n];for(let e of[t+5,22,32,46,64])for(let[t,i]of[[0,-1],[1,0],[-1,0],[0,1],[1,-1],[-1,-1],[1,1],[-1,1]])r.push({x:n.x+t*e,y:n.y+i*e});let i=[...q,...J],{x:a,y:o}=r.find(e=>{let r=O(E(e.x,e.y,t*2,t*2),3);return!i.some(e=>D(r,e))&&!Y.some(([e,t])=>j(e,t,r))&&(e===n||!J.some(t=>j(n,e,O(t,2))))})||n;return q.push(E(a,o,t*2,t*2)),(a!==n.x||o!==n.y)&&le(n,N({x:a,y:o},n,t)),{...e,x:a,y:o,radius:t}},me=e.forces.map(e=>{let t=H(e);return q.push(E(t.x,t.y,40,20)),{...e,...t}}),$=ne;function he(e,n,r={}){let{font:i=t.FONT.label,fill:s=l.fg1,radius:c=6,preferred:u,fixed:f,plate:p,meta:m,icon:h,clearance:_=2}=r,v=a.wrap(e,Math.min(260,L/2)-g(h),i.size,i.weight),y=Math.max(...v.map(e=>a.measure(e,i.size,i.weight)))+g(h)+(p?14:4),b=v.length*16+(p?6:2),x=c+y/2+6,S=c+b/2+6,C=u?[u]:[];for(let e of[0,12,26,44,68,98,136]){let t=[[x+e,-e/4],[x+e,-S-e/2],[-x-e,0],[0,S+e],[0,-S-e],[-x-e,-S-e/2],[x+e,S+e/2],[-x-e,S+e/2]];r.above&&t.unshift(t.splice(4,1)[0]);for(let[e,r]of t)C.push({x:n.x+e,y:n.y+r})}let w=e=>{if(k(n,e)<=Math.hypot(x,S)+10)return null;let t=Math.min((y/2+1)/Math.abs(e.x-n.x),(b/2+1)/Math.abs(e.y-n.y));return[N(n,e,c+3),N(e,n,k(n,e)*t)]},T=f&&o&&(()=>{let e=[[0,0],[0,-1],[1,0],[-1,0],[0,1],[1,-1],[-1,-1],[1,1],[-1,1]],t=[f];for(let n of[12,24,36,52,72])for(let[r,i]of e.slice(1))t.push({x:f.x+r*n,y:f.y+i*n});return t.find(({x:e,y:t})=>{let n=O(E(e,t,y,b),_);return n.x>31&&n.x+n.w<F-8&&n.y>B-20&&n.y+n.h<V+9&&!q.some(e=>D(n,e))&&!J.some(e=>D(n,e))})})()||f||C.find(e=>{let{x:t,y:n}=e,r=w(e);if(r&&[...q,...J].some(e=>j(...r,O(e,2))))return!1;let i=O(E(t,n,y,b),_);return i.x>31&&i.x+i.w<F-8&&i.y>B-20&&i.y+i.h<V+9&&!q.some(e=>D(i,e))&&!J.some(e=>D(i,e))&&!Y.some(([e,t])=>j(e,t,i))}),A=!f&&T&&w(T);A&&le(...A),T||(T={x:48+y/2,y:$+b/2+4},$+=b+8);let{x:M,y:P}=T,I=E(M,P,y,b);J.push(I);let R=ue(M,P,v,h,i,s);f&&Y.some(([e,t])=>j(e,t,I))&&K.push(a.rect(I.x,I.y,I.w,I.h,{fill:l.bg,rx:l.smallRadius})),K.push(p?{...a.el(`g`,{},[a.rect(I.x,I.y,I.w,I.h,{fill:l.bg,stroke:d,rx:l.smallRadius}),R]),...m?{meta:m}:{}}:R)}let ge=[],_e=[],ve=[...U.values()].map(e=>({id:e.id,...O(E(e.x,e.y,e.r*2,e.r*2),2)}));function ye(e,t,n,r=!1){let i=r?l.danger:u,o=k(e,t),s=(e,t)=>e.r?Math.min(o/2,(e.square||e.kind===`anchor`?e.r*o/Math.max(Math.abs(e.x-t.x),Math.abs(e.y-t.y),1e-9):e.r)+1):0,c=N(e,t,s(e,t)),d=N(t,e,s(t,e)),f=M(c,d,ve.filter(n=>n.id!==e.id&&n.id!==t.id),_e);_e.push(...f),Y.push(...f);let p=f.map(([e,t])=>`M${e.x} ${e.y} L${t.x} ${t.y}`).join(` `);if(p){let o=a.path(p,{fill:`none`,...X(i,{"stroke-width":r?1.5:1.2,...n.dashed||r?{"stroke-dasharray":r?`5 4`:`3 4`}:{},meta:{kind:`edge`,from:e.id,to:t.id??`trend:${e.id}`}})}),s=f.length!==1||k(f[0][0],c)>1e-5||k(f[0][1],d)>1e-5;ae.push(!r&&s?a.titled(o,`${e.label} → ${t.label}`):o)}(r||n.flow===`forward`||n.flow===`bidirectional`)&&ae.push(P(a,c,d,i)),(n.flow===`backward`||n.flow===`bidirectional`)&&ae.push(P(a,d,c,i)),(n.label||n.icon)&&ge.push({link:n,point:N(c,d,k(c,d)/2)})}let be=[...de,...e.links].map(e=>({link:e,a:U.get(e.from),b:U.get(e.to)})).filter(({a:e,b:t})=>e&&t&&e.parent!==t.id&&t.parent!==e.id);be.sort((e,t)=>k(e.a,e.b)-k(t.a,t.b));for(let{a:e,b:t,link:n}of be)ye(e,t,n);for(let{nodeId:t,targetEvolution:n}of e.trends){let e=U.get(t);e&&ye(e,{x:H({evolution:n,visibility:e.visibility}).x,y:e.y},{},!0)}z.length&&W.push(ue(F/2,23+(z.length-1)*8,z,e.titleIcon,p)),W.push(a.line(48,B,48,V,X(f)),a.line(48,V,I,V,X(f)));let xe=(B+V)/2;W.push(a.el(`g`,{transform:`rotate(-90 18 ${xe})`},[Z(18,xe,[b(i,`visibility`)],Q,l.fg2)])),W.push(Z((48+I)/2,V+64+ee,[b(i,`evolution`)],Q,l.fg2)),R.forEach((e,r)=>{let i=48+L*(v[r-1]||0),o=48+L*v[r];r&&W.push(a.line(i,B,i,V,X(d)));let s=(i+o)/2;e.forEach(({text:e,icons:r},i)=>{let o=V+25+i*16;W.push(Z(s+r.length*10,o,[e],t.FONT.label,l.fg2)),r.forEach((t,i)=>W.push((0,n.mapIcon)(a,t,s-_({text:e,icons:r})/2+i*20+7,o,l.fg2)))})});let Se=e=>{let n=e.labelOffset&&{x:e.x+e.labelOffset.dx,y:e.y+e.labelOffset.dy},r=e.kind===`anchor`||e.square;he(e.label,e,{radius:e.r,fixed:n,icon:e.icon,above:r,font:r?Q:t.FONT.label})};for(let e of U.values())e.labelOffset&&Se(e);let Ce=new Set;for(let e of fe){let n=e.children.filter(e=>!e.labelOffset).map(e=>{let t=Math.min(260,L/2)-g(e.icon),n=a.wrap(e.label,t,12);return{node:e,rows:n,w:Math.max(...n.map(e=>a.measure(e,12,400)))+g(e.icon)+8}});if(!n.length)continue;let r=Math.max(...n.map(e=>e.rows.length))*16,i=n.reduce((e,t)=>e+t.w,0),o=48,s=i,c=n.map(({node:e,w:t})=>{let n=Math.max(o,Math.min(e.x-t/2,I-s));return s-=t,o=n+t,n+t/2}),l=e.bottom+8+r/2,u=e=>n.map(({w:t},n)=>E(c[n],e,t,r)),d=l;for(;d+r/2<V&&u(d).some(e=>[...q,...J].some(t=>D(e,t))||Y.some(([t,n])=>j(t,n,e)));)d+=12;(d+r/2>=V||i>L)&&(d=$+r/2+4,$+=r+8),J.push(...u(d)),n.forEach(({node:e,rows:n},i)=>{Ce.add(e.id),K.push(ue(c[i],d-(r-n.length*16)/2,n,e.icon,t.FONT.label))})}let we=se.map(e=>pe(e,Math.max(9,a.measure(e.number,12,650)/2+4))),Te=e.notes.map(e=>pe(e,2));for(let{link:e,point:t}of ge)he(e.label,t,{plate:!0,above:!0,radius:0,icon:e.icon,meta:{kind:`edge-label-group`,from:e.from,to:e.to}});for(let e of U.values()){let{x:t,y:n,r,id:i,strategy:o,inertia:s,square:c}=e,d=e.kind===`anchor`,f={kind:`node`,id:i},p=a.frameTone(a.color(S[o]||`tone1`)),m={fill:d?l.fg1:o?a.tint(l.bg,p,.16):l.node,stroke:a.frameTone(u),"stroke-width":1.4,meta:f};c?G.push(a.rect(t-r,n-r,2*r,2*r,{...m,rx:2})):d?G.push(a.rect(t-r,n-r,2*r,2*r,{...m,rx:3})):G.push(a.circle(t,n,r,m)),o&&G.push(a.titled(Z(t,n,[x[o]],Q,a.textOn(m.fill)),o)),s&&G.push(a.rect(t+r+4.5,n-10,3,20,{rx:1,fill:u})),!e.labelOffset&&!Ce.has(i)&&Se(e)}for(let e of Te)G.push(a.circle(e.x,e.y,2,{fill:u})),he(e.text,e,{plate:!0,radius:2,clearance:12,fill:l.fg2,icon:e.icon});for(let e of me){let t=e.kind===`accelerator`?1:-1,n=[[-20,-5],[6,-5],[6,-10],[20,0],[6,10],[6,5],[-20,5]].map(([n,r])=>`${e.x+n*t},${e.y+r}`);G.push(a.shape(`polygon`,{points:n.join(` `),fill:l.node,stroke:u,"stroke-width":1.3})),he(e.name,e,{preferred:{x:e.x,y:e.y+24},radius:20,icon:e.icon})}for(let e of we)G.push(a.circle(e.x,e.y,e.radius,{fill:l.bg,stroke:u,"stroke-width":1.4})),G.push(Z(e.x,e.y,[e.number],Q));if(se.length){let n=se.flatMap(({number:e,text:t,icon:n})=>a.wrap(`${e}. ${t}`,Math.min(270,L/2)-g(n),12).map((e,t)=>({row:e,icon:t===0?n:null}))),o=Math.max(...n.map(({row:e,icon:t})=>a.measure(e,12,400)+g(t)))+28,s=n.length*16+35,c=e.annotationBox?H(e.annotationBox):{x:I,y:V},u=T(Math.max(34,Math.min(F-o-10,c.x)),Math.min(V-s-5,c.y),o,s),f=r>=480&&u.y>=B&&![...q,...J].some(e=>D(O(u,4),e))&&!Y.some(([e,t])=>j(e,t,O(u,3))),p=f?u:T(48,$,o,s);f||($+=s+8),K.push(a.rect(p.x,p.y,p.w,p.h,{rx:l.radius,fill:l.node,stroke:d,meta:{kind:`frame`,id:`annotations`}}),Z(p.x+14,p.y+14,[b(i,`annotations`)],Q,l.fg1,`start`),...n.map(({row:e,icon:n},r)=>ue(p.x+14,p.y+35+r*16,[e],n,t.FONT.label,l.fg2,`start`)))}let Ee=Object.keys(x).filter(t=>e.nodes.some(e=>e.strategy===t));if(Ee.length){let e=a.wrap(Ee.map(e=>`${x[e]} · ${b(i,e)}`).join(` / `),L,12);K.push(Z(48,$+e.length*8,e,t.FONT.label,l.fg2,`start`)),$+=e.length*16+8}let De=F>r*2||U.size>60?[(0,t.warning)(`LARGE_DIAGRAM`,i,c.headerLine||1,`地图较大,可在图框内滚动`,`Large map; scroll inside the frame`,`按主题拆分组件及其依赖`,`Split components and their dependencies into maps by topic`)]:[];return{scene:{width:F,height:$+8,title:e.title||void 0,...s?{heading:e.title}:{},children:[...W,...ie,...ae,...oe,...G,...K]},errors:De}}return e.implementations={"wardley-beta":{parse:w,layout:F,honoredConfig:[`wardley.width`,`wardley.height`]}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/map-label`]);
@@ -0,0 +1,2 @@
1
+ KChartUnits["diagram/zenuml"]=(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=`[\\p{L}\\p{N}_$][\\p{L}\\p{N}_$-]*`,a=RegExp(`^(?:@(\\w+)\\s+)?(${i})(?:\\s+as\\s+(.+))?$`,`u`),o=RegExp(`^@(\\w+)\\s*\\(\\s*(${i})\\s*\\)$`,`u`),s=RegExp(`^(${i}?)\\s*(-->>|-->|->>|->|<<--|<--|<-|==>|=>|\\.\\.>)\\s*(${i})\\s*:\\s*(.*)$`,`u`),c=RegExp(`^(?:(?:[\\w.$<>\\[\\]]+\\s+)?(${i})\\s*=\\s*)?(?:(${i}?)\\s*->\\s*)?(${i})\\.(${i})(?:\\s*\\((.*)\\))?$`,`u`),l=RegExp(`^new\\s+(${i})(?:\\s*\\((.*)\\))?$`,`u`),u=/^(while|for|foreach|loop|if|opt|par|try|else\s+if|else|catch|finally)\s*(?:\((.*)\))?$/iu,d=new Set([`actor`,`boundary`,`control`,`entity`,`database`,`collections`,`queue`,`participant`]),f=`:starter`,p=240,m=40;function h(e,t){let n=[];for(let[r,i]of e.entries()){let e=t+r,a=i.trim(),o=0,s=``,c=0,l=t=>{t.trim()&&n.push({text:t.trim(),line:e})};if(/^title\s/i.test(a))l(a);else{for(let e=0;e<a.length;e++){let t=a[e];if(s)t===`\\`?e++:t===s&&(s=``);else if(t===`"`||t===`'`&&c)s=t;else if(t===`(`)c++;else if(t===`)`)c=Math.max(0,c-1);else if(!c){if(t===`:`)break;if(t===`/`&&a[e+1]===`/`){l(a.slice(o,e)),l(a.slice(e)),o=a.length;break}`{};`.includes(t)&&(l(a.slice(o,e)),t!==`;`&&l(t),o=e+1)}}l(a.slice(o))}}return n}function g(e,i){let{lang:g=`zh`,firstLine:_=2}=i,v=new Map,y=[],b=[],x=[],S=new Set,C=i.title||``,w=[],T,E,D=0,O=(e,n,r,i,a)=>b.push((0,t.error)(g,e,n,r,i,a)),k=(e,t)=>O(e,`无法识别 ZenUML 语句:「${t}」`,`Unrecognized ZenUML statement: "${t}"`,`例如:@Actor Client、Client->API: 请求 或 API.call()`,`For example: @Actor Client, Client->API: request, or API.call()`),A=(e,t)=>(v.has(e)||v.set(e,{id:e,name:e===f?``:e,kind:e===f?`actor`:`participant`,line:t}),v.get(e)),j=()=>x.findLast(e=>e.call),M=e=>{let t=x.at(-1);if(t?.keyword===`par`&&t.units++){let n={type:`section`,keyword:``,line:e};t.event.sections.push(n),y.push(n)}},N=(e,t,r)=>{let i=(0,n.stripEmphasis)(w.join(`
2
+ `));i&&y.push({type:`note`,place:`over`,ids:e===t?[e]:[e,t],text:i,line:r}),w=[]},P=(e,t,n,r,i={})=>{A(e,r).used=!0,A(t,r).used=!0,D++,y.push({type:`message`,from:e,to:t,text:n,line:r,arrow:{head:`open`,dashed:!1},...i})},F=(e,t,n,r)=>P(e,t,n,r,{arrow:{head:`open`,dashed:!0}}),I=(e,t)=>{e.assignment&&F(e.to,e.from,e.assignment,t),y.push({type:`deactivate`,id:e.to,line:t})},L=e=>O(e,`ZenUML 语句缺少花括号块`,`ZenUML statement is missing a brace block`,`在语句后添加 { … }`,`Add { … } after the statement`),R=e=>O(e,`回复注解后缺少消息`,`Expected a message after the reply annotation`,`写成 @return A->B: 结果`,`Write @return A->B: result`);for(let e of Object.keys(i.options||{}))O(_-1,`ZenUML 头行不接受选项「${e}」`,`The ZenUML header does not accept option "${e}"`,`头行只保留 zenuml`,`Use only zenuml on the header line`);let z=String(e).split(/\r\n?|\n/u);z.length>p&&O(_+p,`ZenUML 正文超过 ${p} 行`,`ZenUML body exceeds ${p} lines`,`拆分为多张图`,`Split into several diagrams`);let B=h(z.slice(0,p),_);for(let e=0;e<B.length;e++){let{text:t,line:n}=B[e];if(t.startsWith(`//`)){w.push(t.slice(2).trim());continue}let i=t,p=/^@(?:return|reply)(?:\s+(.*))?$/iu.exec(t);if(p){if(T&&R(T),T=n,!p[1])continue;i=p[1]}let m=s.exec(i),h=!!T;if(T&&!m&&R(T),T=void 0,m){let[,e,t,r,i]=m;if(t!==`->`){let a=`${e}->${r}: ${i}`;O(n,`ZenUML 消息箭头写法无效:「${t}」`,`Invalid ZenUML message arrow "${t}"`,`异步消息用 ${a};回复用 @return ${a} 或调用块内的 return`,`For an async message use ${a}; for a reply use @return ${a} or return inside a call block`)}else M(n),N(e,r,n),h?F(e,r,i,n):P(e,r,i,n)}else if(i===`}`){let t=x.at(-1);if(!t)O(n,`ZenUML 多余的 }`,`Unexpected } in ZenUML`,`删除多余的 }`,`Remove the unmatched }`);else if(t.call)x.pop(),I(t,n);else{let r=B.slice(e+1).find(e=>!e.text.startsWith(`//`)),i=r&&u.exec(r.text)?.[1].toLowerCase().replace(/\s+/g,` `);t.keyword===`if`&&t.branch!==`else`&&(i===`else`||i===`else if`)||t.keyword===`try`&&t.branch!==`finally`&&(i===`catch`||i===`finally`)?t.awaitingBranch=!0:(x.pop(),y.push({type:`end`,line:n}))}}else if(m=u.exec(i)){let t=m[1].toLowerCase().replace(/\s+/g,` `),a=m[2]?.trim()||``,o=x.at(-1),s=/^(else|catch|finally)/u.test(t);if(B[e+1]?.text!==`{`)L(n);else if(s&&!o?.awaitingBranch)k(n,i);else if(x.length>=r.LIMITS.fragmentDepth&&!s)O(n,`ZenUML 块嵌套过深`,`ZenUML blocks are nested too deeply`,`减少块的嵌套层数`,`Reduce block nesting`);else if(e++,s){let e={type:`section`,keyword:t,text:a,line:n};o.event.sections.push(e),y.push(e),Object.assign(o,{branch:t,awaitingBranch:!1})}else{M(n);let e={type:`fragment`,keyword:t===`if`?`alt`:/^(while|for|foreach)$/u.test(t)?`loop`:t,text:a,sections:[],line:n};y.push(e),x.push({event:e,keyword:t,line:n,units:0})}}else if(m=/^return(?:\s+(.*))?$/u.exec(i)){let e=j();e?(M(n),N(e.to,e.from,n),F(e.to,e.from,m[1]||``,n)):O(n,`return 应放在 ZenUML 同步调用块内`,`Put return inside a ZenUML synchronous call block`,`在调用的 { … } 内使用 return,或用 @return A->B: 结果`,`Use return inside the call’s { … }, or use @return A->B: result`)}else if(m=l.exec(i)){let[,e,t]=m,r=j()?.to||f;A(e,n).used||r===e?O(n,`应在首次使用「${e}」前创建它`,`Create "${e}" before its first message`,`将 new 移到该参与者的其他消息前`,`Move new before other messages involving this participant`):(M(n),N(r,e,n),P(r,e,t?.trim()?`«${t.trim()}»`:`«create»`,n,{create:e,activateOn:e,arrow:{head:`open`,dashed:!0}}),I({to:e},n))}else if(m=c.exec(i)){let[,t,i,a,o,s]=m,c=i||j()?.to||f;M(n),N(c,a,n),P(c,a,s===void 0?o:`${o}(${s})`,n,{activateOn:a,arrow:{head:`arrow`,dashed:!1}});let l={call:!0,from:c,to:a,assignment:t,line:n};B[e+1]?.text===`{`?x.length>=r.LIMITS.fragmentDepth?O(n,`ZenUML 块嵌套过深`,`ZenUML blocks are nested too deeply`,`减少块的嵌套层数`,`Reduce block nesting`):(e++,x.push(l)):I(l,n)}else if(m=/^title\s+(.+)$/iu.exec(i))C?O(n,`ZenUML 标题重复`,`Duplicate ZenUML title`,`只保留一个 title 或前置元数据标题`,`Keep one title statement or front-matter title`):C=m[1];else if(!/^@(?:startuml|enduml)$/iu.test(i)){if(m=o.exec(i)){let e=`@${m[1]} ${m[2]}`;O(n,`ZenUML 参与者注解写法无效:「${i}」`,`Invalid ZenUML participant annotation "${i}"`,`去掉括号,写成 ${e}`,`Remove the parentheses: ${e}`)}else if(m=a.exec(i)){let[,e,t,r]=m,i=A(t,n),a=e?.toLowerCase()||`participant`;i.declared?O(n,`ZenUML 参与者「${t}」重复声明`,`Duplicate ZenUML participant "${t}"`,`删除重复声明`,`Remove the duplicate declaration`):Object.assign(i,{declared:!0,name:r?.replace(/^(["'])(.*)\1$/u,`$2`)||t,kind:d.has(a)?a:`participant`,line:n}),d.has(a)||(S.add(`@${e}`),E??=n)}else k(n,i)}w=[]}T&&R(T);for(let e of x)O(e.line,`ZenUML 块缺少 }`,`ZenUML block is missing }`,`添加匹配的 }`,`Add a matching }`);!v.size&&!b.length&&O(_,`ZenUML 缺少参与者`,`ZenUML needs at least one participant`,`添加参与者 Client 或消息 Client->API: 请求`,`Add a participant Client or a message Client->API: request`);let V=[...v.values()];if(V.length>m&&O(V[m].line,`ZenUML 参与者超过 ${m} 个`,`ZenUML has more than ${m} participants`,`拆分为多张图`,`Split into several diagrams`),S.size){let e=[...S].join(`, `);b.push((0,t.warning)(`DIAGRAM_HINT`,g,E,`以下注解使用普通参与者外观:${e}`,`Using standard participants for these annotations: ${e}`,`如需图标,使用受支持的参与者类型`,`Use a supported participant type if an icon is needed`))}return v.has(f)&&V.unshift(V.splice(V.indexOf(v.get(f)),1)[0]),V.forEach((e,t)=>{e.index=t}),{model:{type:`sequence`,title:C,participants:V,statements:y,messages:D,zenuml:!0},errors:b}}var _=r.implementations.sequenceDiagram;return e.implementations={zenuml:{parse:g,layout:(e,t,n)=>_.layout(e,{...t,compact:!0},{...n,config:{sequence:{mirrorActors:!1}}}),scene:_.scene}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/emphasis`],KChartUnits[`diagram/sequence`]);