@fengwk/kchart 0.1.1 → 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.
- package/CHANGELOG.md +35 -0
- package/README.md +31 -2
- package/README.zh-CN.md +31 -2
- package/dist/esm/_virtual/_kchart-families.js +2 -1
- package/dist/esm/chart/composition.js +7 -5
- package/dist/esm/chart/maps.js +9 -7
- package/dist/esm/chart/mindmap.js +19 -5
- package/dist/esm/chart/multivariate.js +49 -14
- package/dist/esm/chart/relations.js +15 -7
- package/dist/esm/chart/spec.js +5 -2
- package/dist/esm/core/context.js +29 -10
- package/dist/esm/core/scene.js +238 -21
- package/dist/esm/core/text.js +1 -1
- package/dist/esm/diagram/block.js +287 -295
- package/dist/esm/diagram/blocks.js +541 -605
- package/dist/esm/diagram/board-paint.js +594 -0
- package/dist/esm/diagram/board-route.js +60 -0
- package/dist/esm/diagram/c4.js +75 -35
- package/dist/esm/diagram/class.js +3 -2
- package/dist/esm/diagram/cynefin.js +55 -9
- package/dist/esm/diagram/eventmodeling.js +4 -2
- package/dist/esm/diagram/gantt.js +37 -15
- package/dist/esm/diagram/gitgraph.js +26 -5
- package/dist/esm/diagram/graph-layout.js +39 -2
- package/dist/esm/diagram/graph-route.js +296 -38
- package/dist/esm/diagram/info.js +32 -0
- package/dist/esm/diagram/journey.js +5 -5
- package/dist/esm/diagram/kanban.js +3 -3
- package/dist/esm/diagram/layers.js +9 -7
- package/dist/esm/diagram/mindmap.js +5 -1
- package/dist/esm/diagram/numeric-composition.js +24 -4
- package/dist/esm/diagram/numeric-model.js +1 -1
- package/dist/esm/diagram/numeric-radar.js +25 -7
- package/dist/esm/diagram/numeric-sankey.js +4 -3
- package/dist/esm/diagram/numeric-xy.js +12 -2
- package/dist/esm/diagram/packet.js +4 -4
- package/dist/esm/diagram/quadrant.js +12 -5
- package/dist/esm/diagram/railroad-parse.js +20 -10
- package/dist/esm/diagram/railroad.js +1 -1
- package/dist/esm/diagram/registry.js +46 -8
- package/dist/esm/diagram/sequence.js +43 -6
- package/dist/esm/diagram/swimlane.js +2 -2
- package/dist/esm/diagram/time.js +3 -3
- package/dist/esm/diagram/timeline.js +5 -5
- package/dist/esm/diagram/treeview.js +5 -3
- package/dist/esm/diagram/venn.js +35 -15
- package/dist/esm/diagram/wardley.js +61 -26
- package/dist/esm/diagram/zenuml.js +338 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/mermaid.d.ts +1 -1
- package/dist/esm/mermaid.js +2 -1
- package/dist/esm/node.js +8 -2
- package/dist/esm/src/families.js +6 -1
- package/dist/units/chart/composition.js +1 -1
- package/dist/units/chart/maps.js +1 -1
- package/dist/units/chart/mindmap.js +1 -1
- package/dist/units/chart/multivariate.js +1 -1
- package/dist/units/chart/relations.js +1 -1
- package/dist/units/chart/spec.js +1 -1
- package/dist/units/core/context.js +1 -1
- package/dist/units/core/scene.js +1 -1
- package/dist/units/core/text.js +1 -1
- package/dist/units/diagram/block.js +2 -2
- package/dist/units/diagram/blocks.js +2 -2
- package/dist/units/diagram/board-paint.js +1 -0
- package/dist/units/diagram/board-route.js +1 -0
- package/dist/units/diagram/c4.js +1 -1
- package/dist/units/diagram/class.js +2 -2
- package/dist/units/diagram/cynefin.js +2 -2
- package/dist/units/diagram/eventmodeling.js +1 -1
- package/dist/units/diagram/gantt.js +3 -3
- package/dist/units/diagram/gitgraph.js +2 -1
- package/dist/units/diagram/graph-layout.js +1 -1
- package/dist/units/diagram/graph-route.js +1 -1
- package/dist/units/diagram/info.js +2 -0
- package/dist/units/diagram/journey.js +3 -3
- package/dist/units/diagram/kanban.js +1 -1
- package/dist/units/diagram/layers.js +1 -1
- package/dist/units/diagram/mindmap.js +1 -1
- package/dist/units/diagram/numeric-composition.js +1 -1
- package/dist/units/diagram/numeric-model.js +1 -1
- package/dist/units/diagram/numeric-radar.js +2 -2
- package/dist/units/diagram/numeric-sankey.js +1 -1
- package/dist/units/diagram/numeric-xy.js +1 -1
- package/dist/units/diagram/packet.js +1 -1
- package/dist/units/diagram/quadrant.js +1 -1
- package/dist/units/diagram/railroad-parse.js +2 -2
- package/dist/units/diagram/railroad.js +1 -1
- package/dist/units/diagram/registry.js +2 -2
- package/dist/units/diagram/sequence.js +1 -1
- package/dist/units/diagram/swimlane.js +2 -2
- package/dist/units/diagram/time.js +1 -1
- package/dist/units/diagram/timeline.js +1 -1
- package/dist/units/diagram/treeview.js +1 -1
- package/dist/units/diagram/venn.js +1 -1
- package/dist/units/diagram/wardley.js +4 -4
- package/dist/units/diagram/zenuml.js +2 -0
- package/dist/units.json +79 -51
- package/package.json +1 -1
- package/dist/esm/diagram/relations.js +0 -966
- package/dist/units/diagram/relations.js +0 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
KChartUnits["diagram/registry"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var
|
|
2
|
-
`).entries()){let a=i.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g,``),o=/^\s*(classDef|style|linkStyle|click|href|callback)\s/i.exec(a)||/::icon\s*\(/i.exec(a),s=e.firstLine+r;if(o){let r=o[1]||`::icon`;t.push((0,n.error)(e.lang,s,`不支持 Mermaid 写法「${r}」`,`Unsupported Mermaid syntax "${r}"`,`移除样式、链接或回调写法;颜色由主题决定`,`Remove styles, links, or callbacks; colors are controlled by the theme`,i.toLowerCase().indexOf(r.toLowerCase())+1))}else!e.kind.toLowerCase().startsWith(`classdiagram`)&&/^\s*class\s+\S+\s+\S+/i.test(a)&&t.push((0,n.error)(e.lang,s,`不支持 Mermaid 样式类声明`,`Mermaid style-class declarations are not supported`,`使用 ::: 状态分类;不要声明通用样式类`,`Use ::: status classes; generic style classes are unsupported`,i.search(/\S/)+1))}return t}function
|
|
1
|
+
KChartUnits["diagram/registry"]=(function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=new Set([`securitylevel`,`startonload`,`loglevel`,`deterministicids`,`deterministicidseed`,`maxtextsize`,`maxedges`,`suppresserrorrendering`,`htmllabels`,`markdownautowrap`,`arrowmarkerabsolute`,`secure`,`dompurifyconfig`,`fontfamily`,`fontsize`]),l=new Map([[`look`,`classic`],[`layout`,`dagre`],[`theme`,`default`]]);function u(e,n){let r=(n?.honoredConfig??[]).map(e=>e.toLowerCase()),i=[];function a(t,n=``){for(let[o,s]of Object.entries(t)){let t=n+o,u=t.toLowerCase();c.has(u)||r.some(e=>u===e||u.startsWith(`${e}.`))||(s&&typeof s==`object`&&!Array.isArray(s)?a(s,`${t}.`):(typeof s!=`string`||l.get(u)!==s.toLowerCase())&&i.push([t,e.configLines[u]??1]))}}a(e.config);let o=e.errors.find(e=>e.code===`IGNORED_CONFIG`);if(!i.length)return o;i.sort((e,t)=>e[1]-t[1]);let s=i.map(([e])=>e).join(`, `);return o?{...o,line:Math.min(o.line,i[0][1]),message:`${o.message}, ${s}`}:(0,t.ignoredConfigWarning)(e.lang,i[0][1],s)}function d(e){if(e.syntax!==`mermaid`)return[];let t=[];for(let[r,i]of e.body.split(`
|
|
2
|
+
`).entries()){let a=i.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g,``),o=/^\s*(classDef|style|linkStyle|click|href|callback)\s/i.exec(a)||/::icon\s*\(/i.exec(a),s=e.firstLine+r;if(o){let r=o[1]||`::icon`;t.push((0,n.error)(e.lang,s,`不支持 Mermaid 写法「${r}」`,`Unsupported Mermaid syntax "${r}"`,`移除样式、链接或回调写法;颜色由主题决定`,`Remove styles, links, or callbacks; colors are controlled by the theme`,i.toLowerCase().indexOf(r.toLowerCase())+1))}else!e.kind.toLowerCase().startsWith(`classdiagram`)&&/^\s*class\s+\S+\s+\S+/i.test(a)&&t.push((0,n.error)(e.lang,s,`不支持 Mermaid 样式类声明`,`Mermaid style-class declarations are not supported`,`使用 ::: 状态分类;不要声明通用样式类`,`Use ::: status classes; generic style classes are unsupported`,i.search(/\S/)+1))}return t}function f(e,c){if(!e||typeof e!=`object`||!Array.isArray(c))throw TypeError(`Invalid diagram registry configuration`);let l=new Map,f=new Map;for(let e of c){if(!e||typeof e.kind!=`string`||!e.kind||typeof e.syntax!=`string`||!e.syntax||!Array.isArray(e.aliases)||typeof e.topic!=`string`)throw TypeError(`Invalid diagram type descriptor`);let t=e.kind.toLowerCase();if(l.has(t))throw TypeError(`Duplicate diagram type: ${e.kind}`);l.set(t,e);for(let t of[e.kind,...e.aliases]){if(typeof t!=`string`||!t.trim())throw TypeError(`Invalid diagram alias: ${t}`);let n=t.toLowerCase();if(f.has(n))throw TypeError(`Duplicate diagram alias: ${t}`);f.set(n,e)}}let p=(e,t,n=`BAD_DIAGRAM`)=>({code:e.code||n,line:e.line??1,column:e.column??1,message:e.message||`无效的结构图`,fix:e.fix||`修正结构图声明后重试`,topic:e.topic||t?.topic||`diagram`,severity:e.severity===`warning`?`warning`:`error`}),m=(e,t)=>(e||[]).map(e=>p(e,t)),h=(...e)=>{let t=new Set;return e.flat().filter(e=>{let n=JSON.stringify([e.code,e.line,e.column,e.message,e.fix,e.topic,e.severity]);return!t.has(n)&&(t.add(n),!0)})},g=e=>e.headerLine||e.firstLine||1;function _(r,i={}){i={...i,lang:i.lang||(0,t.inferLang)(r)};let a=i.syntax||`mermaid`;if(/^mermaid$/i.test(a)&&String(r??``).length>5e4)return{info:null,type:null,model:null,diagnostics:m([(0,n.error)(i.lang,1,`Mermaid 源码最多 50000 个字符`,`Mermaid source is limited to 50,000 characters`,`请拆分图表`,`Split the diagram`)],null)};let o=(0,t.prepareSource)(r,{syntax:a,lang:i.lang,keepsTrailingComments:t=>e[f.get(t.toLowerCase())?.kind]?.trailingComments===!1,site:i[t.siteConfig]}),s=String(o.kind||``).toLowerCase(),c=f.get(s)||l.get(s),_=c&&e[c.kind],v=_?.optionMode===`raw`?{options:o.options||Object.create(null),errors:[]}:(0,t.parseOptions)(o.params,{lang:i.lang,line:o.headerLine||o.firstLine}),y={...o,...v.options?{options:v.options}:{},kind:c?.kind||o.kind,syntax:a,lang:i.lang},b=u(y,_),x=o.errors.filter(e=>e.code!==`IGNORED_CONFIG`),S=_&&_.acceptsPresentation!==!0?d(y):[],C=m(h(x,b?[b]:[],S,v.errors||[]),c);if(!c){if(C.some(n.blocking))return{info:y,type:null,model:null,diagnostics:C};let e=o.kind||o.body.trim().split(/\s+/)[0].slice(0,40)||a,t=s.endsWith(`-beta`)?s.slice(0,-5):`${s}-beta`,r=a===`mermaid`&&s&&f.get(t),c=r?.syntax===`mermaid`&&[r.kind,...r.aliases].find(e=>e.toLowerCase()===t),l=(0,n.error)(i.lang,g(o),`未知结构图类型「${e}」`,`Unknown diagram type "${e}"`,c?`将头行关键字改为「${c}」`:`使用已声明的结构图类型`,c?`Use "${c}" as the header keyword`:`Use a supported diagram type`);return{info:y,type:null,model:null,diagnostics:[...C,p(l)]}}if(String(c.syntax).toLowerCase()!==String(a).toLowerCase()){let e=p((0,n.error)(i.lang,g(o),`图类型「${o.kind}」不支持语法「${a}」`,`Diagram type "${o.kind}" does not use ${a} syntax`,`使用 ${c.syntax} 语法`,`Use ${c.syntax} syntax`),c);return{info:y,type:c,model:null,diagnostics:h(C,[e])}}if(C.some(n.blocking))return{info:y,type:c,model:null,diagnostics:C};if(!_){let e=(0,n.error)(i.lang,g(o),`已知图类型「${c.kind}」尚未装入`,`Diagram type "${c.kind}" is not loaded`,`重新组装并装入该图类型`,`Load this diagram type before rendering`);return{info:y,type:c,model:null,diagnostics:[...C,p(e,c)]}}if(typeof _.parse!=`function`)throw TypeError(`Missing parser for diagram: ${c.kind}`);let w=_.parse(o.body,y);if(!w||!Array.isArray(w.errors))throw TypeError(`Invalid parser result for diagram: ${c.kind}`);let T=!w.errors.some(n.blocking)&&typeof _.validate==`function`&&_.validate(w.model,y)||[];if(!Array.isArray(T))throw TypeError(`Invalid validation result for diagram: ${c.kind}`);return{info:y,type:c,model:w.model,diagnostics:h(C,m(w.errors,c),m(T,c))}}function v(e,t={}){try{return _(e,t)}catch(e){if(!(e instanceof s.ExpectedDiagnostic))throw e;return{info:null,type:null,model:null,diagnostics:m(e.errors,null)}}}function y(e,t={}){return v(e,t).diagnostics}function b(t,c={}){let l=v(t,c);if(l.diagnostics.some(n.blocking))return{svg:null,scene:null,diagnostics:l.diagnostics};try{let t=e[l.type.kind];if(typeof t.layout!=`function`)throw TypeError(`Missing layout for diagram: ${l.type.kind}`);let s=Math.max(1,Number(c.width)||800),u=c.compact===!0,d=u?Math.min(s,720):s,f=(0,r.createContext)({...c,width:d,compact:u,lang:l.info.lang}),p=(0,n.measureOf)(f),g={...c,frame:c.frame??!0},_=g.frame===!1,v=u&&_,y=v?{...g,frame:!0}:g,b=t.layout(l.model,{width:d,compact:u,embedHeading:_,lang:f.lang,measure:p,ctx:f,renderOptions:y},l.info),x=h(l.diagnostics,m(b?.errors,l.type));if(x.some(n.blocking))return{svg:null,scene:null,diagnostics:x};let S=b?.scene||(typeof t.scene==`function`?t.scene(b,f,l.info):null);if(!S||!Number.isFinite(S.width)||!Number.isFinite(S.height)||!Array.isArray(S.children))throw TypeError(`Invalid scene for diagram: ${l.type.kind}`);let C=l.info.title||S.heading,w=[];if(v&&(C||S.subtitle)){let e=(e,t,n)=>(0,o.wrapText)(e,Math.max(14,d-4),f.font(t,n),(e,t)=>f.measureInk(e,t.size,t.weight),{bounded:!0}),t=C?e(C,16,650):[];t.length&&w.push(f.textLines(0,0,t,{size:16,weight:650,leading:22,fill:f.color(`fg`),meta:{kind:`diagram-title`}})),S.subtitle&&w.push(f.textLines(0,t.length*22,e(S.subtitle,12,400),{size:12,weight:400,leading:18,fill:f.color(`muted`)}))}let T=w.length?(0,i.el)(`g`,{},w):null,E=u?(0,i.cropInk)(S,v?f.measureInk:f.measureRendered,{fullText:v,heading:T}):(0,i.containText)(S,f.measure,{blockPadding:4}),D=u?E.width:Math.max(s,E.width),O=Math.max(0,(D-E.width)/2),k=O?[(0,i.el)(`g`,{transform:`translate(${O} 0)`},E.children)]:E.children,A=E.anchor?{...E.anchor,x:E.anchor.x+O}:E.anchor,j=l.info.accTitle||l.info.title||E.title||l.type.kind,M={...E,width:D,children:k,...A?{anchor:A}:{},title:j,...l.info.accDescr===void 0?{}:{description:l.info.accDescr},heading:C};return{svg:(0,a.renderScene)(M,g),scene:M,diagnostics:x}}catch(e){if(!(e instanceof s.ExpectedDiagnostic))throw e;return{svg:null,scene:null,diagnostics:h(l.diagnostics,m(e.errors,l.type))}}}return Object.freeze({parse:v,check:y,diagram:b})}return e.createDiagramApi=f,e})({},KChartUnits[`diagram/source`],KChartUnits[`diagram/support`],KChartUnits[`core/context`],KChartUnits[`core/scene`],KChartUnits[`core/svg`],KChartUnits[`core/text`],KChartUnits[`core/diagnostics`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/sequence"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=Object.freeze({participants:300,messages:500,fragmentDepth:32,lines:4}),o=new Set([`else`,`and`,`option`]),s=new Set([`actor`,`boundary`,`collections`,`control`,`database`,`entity`,`participant`,`queue`]),c=new Map;for(let[e,t,n]of[[`->>`,`arrow`],[`->`,`none`],[`-x`,`cross`],[`-)`,`open`],[`<<->>`,`arrow`,`arrow`],[`-|\\`,`top`],[`-|/`,`bottom`],[`-\\\\`,`stick-top`],[`-//`,`stick-bottom`],[`/|-`,`none`,`top`],[`\\|-`,`none`,`bottom`],[`//-`,`none`,`stick-top`],[`\\\\-`,`none`,`stick-bottom`]])for(let r of[!1,!0]){let i=r?e.replace(`-`,`--`):e,a=t===`cross`?`lost`:t===`open`?`async`:r?`return`:`sync`;c.set(i,{token:i,head:t,start:n,dashed:r,style:a})}var l=new RegExp([...c.keys()].sort((e,t)=>t.length-e.length).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`),`i`),u=e=>/^[^\s<>::,;@()+]+$/.test(e),d=(e,t,n,r,a,o)=>(0,i.error)(e,t,n,r,a,o),f=/^(?:rgba?|hsla?)\([^)]*\)/i;function p(e){let t=[],n=0;for(let r of e.matchAll(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|&?#(?:x[\da-f]+|\w+);|&\w+;|%%|#|;/gi))if(!(r[0]===`#`&&/^\s*link\s+[^\s:]+\s*:[^@]*@\s*\S*$/i.test(e.slice(n,r.index)))&&(r[0]===`;`||r[0]===`#`||r[0]===`%%`)){if(t.push(e.slice(n,r.index)),r[0]!==`;`)return t;n=r.index+1}return t.push(e.slice(n)),t}function m(e=``){let t=e.matchAll(/(?:^|,)\s*["']?(type|alias|icon)["']?\s*:\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^,]+)\s*(?=,|$)/g);return Object.fromEntries(Array.from(t,([,e,t])=>{if(t=t.trim(),t.startsWith(`"`))try{return[e,JSON.parse(t)]}catch{}return[e,t.replace(/^(["'])(.*)\1$/,`$2`)]}))}function h(e,h){let{lang:g,options:_={},firstLine:v}=h,y=(0,r.presentation)({lang:g}),b=new Map,x=new Map,S=[];for(let e of Object.keys(_))S.push(d(g,v-1,`sequenceDiagram 不支持选项「${e}」`,`Unsupported sequenceDiagram option: ${e}`,`删掉第一行的选项`,`Remove the option from the first line`));let C=[],w=new Map,T=[],E=[],D=0,O,k,A,j=new Set,M=(e,t,...n)=>{j.has(e)||(j.add(e),S.push((0,i.warning)(e,g,t,...n)))},N=e=>{let t=`${e.code}:${e.message}`;j.has(t)||(j.add(t),S.push(e))},P=(e,t)=>{let{text:r,icon:i,diagnostics:a}=(0,n.normalizeLabel)(e.replace(/^(?:no)?wrap\s*:\s*/i,``),{lang:g,line:t});return a.forEach(N),{text:r,icon:i}},F=(e,t)=>{let[n,...r]=e.split(`:::`);return r.length&&y.addClasses(n,r,t),n},I=({id:e,line:t},n,r)=>S.push(d(g,t,`${e}:${n}`,`${e}: ${r}`,`修正下一条消息的参与者`,`Correct the participants in the next message`));function L(e,t,n=e){if(w.has(e))return w.get(e);if(C.length>=a.participants)return S.push(d(g,t,`参与者超过 ${a.participants} 个`,`More than ${a.participants} participants`,`删到 ${a.participants} 个参与者,或拆成两张图`,`Keep at most ${a.participants} participants, or split the diagram`)),null;let r={id:e,name:n,kind:`participant`,line:t,index:C.length};return C.push(r),w.set(e,r),r}function R(e){let t=E.at(-1);t?(E.pop(),T.push({type:`end`,line:e,target:t})):S.push(d(g,e,`end 没有对应的开始语句`,`end has no matching start`,`删掉这个 end,或在它前面补上片段、rect 或 box`,`Remove this end, or add the fragment, rect, or box it closes`))}let z=String(e).split(`
|
|
2
|
-
`);function B(e,n){if(!e.trim()||e.trimStart().startsWith(`%%`))return;if(/^\s*\t|^\s+\t/.test(e)||e.includes(` `)){S.push(d(g,n,`时序图语句不能使用 Tab`,`Tabs are not allowed in sequence statements`,`把 Tab 换成空格`,`Replace tabs with spaces`));return}let p=e.trim(),h=/^title(?:\s*:\s*|\s+)(.+)$/i.exec(p);if(h){O=P(h[1],n).text;return}let _=/^(link|links|properties|details)\s+([^\s:]+)\s*:\s*(.*)$/i.exec(p);if(_){let[,e,t,i]=_;if(M(`IGNORED_INTERACTION`,n,`已省略参与者菜单和详情界面;仅保留首个安全链接`,`Participant menus and details are omitted; only the first safe URL is kept`,`把其他必要链接放在图外`,`Put other essential links outside the diagram`),!b.has(t)){let n=[];if(e.toLowerCase()===`link`){let e=/^(.*?)@\s*(.+)$/.exec(i);e&&(n=[[e[1].trim(),e[2]]])}else if(e.toLowerCase()===`links`)try{let e=JSON.parse(i);e&&typeof e==`object`&&!Array.isArray(e)&&(n=Object.entries(e))}catch{}for(let[e,i]of n){let n=typeof i==`string`&&(0,r.safeHref)(i.trim());if(n){b.set(t,{href:n,tooltip:e});break}}}return}if(y.accept(p,n))return;let v=/^(?:(create)\s+)?(participant|actor)\s+([^\s@]+)(?:\s*@\{([^}]*)\})?(?:\s+as\s+(.+))?$/i.exec(p);if(v){let[,e,r,a,o,c]=v,[,l,f]=/^(.*?)::icon\(([^)]+)\)$/.exec(a)??[],p=F(l??a,n),h=m(o);if(!u(p)){S.push(d(g,n,`参与者 ID 无效`,`Invalid participant id`,`写成 participant ID as 名称`,`Write participant ID as Name`));return}if(e&&(w.has(p)||k)){I({id:p,line:n},`重复创建或已有待创建的参与者`,`Duplicate or already pending creation`);return}let _=L(p,n);if(!_)return;let y=h.type||r.toLowerCase();s.has(y)||M(`DIAGRAM_HINT`,n,`未知参与者类型,使用普通方框`,`Unknown participant type; using a standard participant`,`检查 type`,`Check the type value`);let{text:b,icon:x}=P(c||h.alias||p,n),C=f||h.icon,D=C?(0,t.resolveIconRef)(C):null;C&&!D&&N((0,i.warning)(`IGNORED_ASSET`,g,n,`未知图标 ${C}`,`Unknown icon ${C}`,`使用内置图标`,`Use a supported icon`)),Object.assign(_,{name:b,icon:D||x,kind:s.has(y)?y:`participant`,declared:!0,line:n}),e&&(k={id:p,line:n}),E.at(-1)?.type===`box`&&E.at(-1).members.push(p),T.push({type:`participant`,id:p,line:n});return}let C=/^destroy\s+(\S+)$/i.exec(p);if(C){let e=C[1];!w.has(e)||A?I({id:e,line:n},`未知参与者或已有待销毁的参与者`,`Unknown participant or already pending destruction`):A={id:e,line:n};return}let j=/^autonumber(?:\s+(off|[+-]?\d+(?:\.\d+)?)(?:\s+([+-]?\d+(?:\.\d+)?))?)?$/i.exec(p);if(j){T.push({type:`numbering`,start:j[1]?.toLowerCase()===`off`?null:Number(j[1]??1),step:Number(j[2]??1),line:n});return}if(/^activate\s+(\S+)$/i.test(p)||/^deactivate\s+(\S+)$/i.test(p)){let[,e,t]=/^(activate|deactivate)\s+(\S+)$/i.exec(p);if(!L(t,n))return;T.push({type:e.toLowerCase(),id:t,line:n});return}let z=/^Note\s+(over\s+(\S+?)(?:\s*,\s*(\S+))?|left\s+of\s+(\S+)|right\s+of\s+(\S+))\s*:\s*(.*)$/i.exec(p);if(z){let e=z[2]?[z[2],z[3]].filter(Boolean):[z[4]||z[5]];if(e.some(e=>!L(e,n)))return;T.push({type:`note`,place:z[2]?`over`:z[4]?`left`:`right`,ids:e,...P(z[6].trim(),n),line:n});return}let B=/^(alt|opt|loop|par_over|par|critical|break|rect|box|else|and|option|end)(?:\s+(.*)|$)/i.exec(p);if(B){let e=B[1].toLowerCase().replace(`par_over`,`par`),t=(B[2]||``).trim(),i,s;if(e===`box`||e===`rect`){i=f.exec(t)?.[0]||/^transparent\b/i.exec(t)?.[0];let e=t.split(/\s/,1)[0];!i&&((0,r.roleOfColor)(e)||/^(?:black|white|(?:light|dark|slate|dim)?gr[ae]y|silver)$/i.test(e))&&(i=e),i&&(s=(0,r.roleOfColor)(i),s||/^transparent$/i.test(i)||x.has(i)||x.set(i,n),t=t.slice(i.length).trim())}if(e===`end`){t&&S.push(d(g,n,`end 后面不能再写内容`,`end cannot have trailing text`,`这一行只写 end`,`Leave only end on this line`)),R(n);return}let{text:c,icon:l}=P(t,n);if(o.has(e)){let t=E.at(-1),r={else:[`alt`],and:[`par`],option:[`critical`]}[e];if(!t||!r.includes(t.keyword)){S.push(d(g,n,`「${e}」不能出现在当前片段里`,`"${e}" is not valid in the current fragment`,`把它放到对应的 ${r.join(`/`)} 片段中`,`Place it inside ${r.join(`/`)} before end`));return}T.push({type:`section`,keyword:e,text:c,icon:l,line:n,owner:t}),t.sections.push({keyword:e,text:c,icon:l,line:n});return}if(E.length>=a.fragmentDepth){S.push(d(g,n,`组合片段最多嵌套 ${a.fragmentDepth} 层`,`Fragments nest at most ${a.fragmentDepth} levels`,`把内层片段拆到另一张图`,`Move the inner fragment to another diagram`));return}let u={type:e===`box`?`box`:e===`rect`?`rect`:`fragment`,keyword:e,text:c,icon:l,color:i,status:s,line:n,kind:e===`box`||e===`rect`?e:`fragment`,sections:[],members:[]};T.push(u),E.push(u);return}let V=Array.from(p.matchAll(/:::[\w-]+|:/g)).find(e=>e[0]===`:`)?.index,H=V!==void 0,U=H?p.slice(0,V):p,W=l.exec(U);if(W?.index>0){let e=c.get(W[0].toLowerCase()),t=/^(.*?)\s*(\(\))?\s*(\+)?$/.exec(U.slice(0,W.index).trim()),r=/^([+-])?\s*(\(\))?\s*(.*?)\s*(\+)?$/.exec(U.slice(W.index+W[0].length).trim()),[,i,o,s]=t,l=F(i,n),[,f,m,h,_]=r,v=f||s||_||(h.endsWith(`-`)&&!w.has(h)?`-`:``),y=F(v===`-`&&!f&&h.endsWith(`-`)?h.slice(0,-1):h,n);if(!u(l)||!u(y)){S.push(d(g,n,`消息的参与者写法无效`,`Invalid message participants`,`写成 A->>B: 消息,自调用写成 A->>A: 消息`,`Write A->>B: message, or A->>A: message for a self call`));return}if(!L(l,n)||!L(y,n))return;let b,x;if(k?(k.id===y?b=y:I(k,`下一条消息必须发给新参与者`,`The next message must target the new participant`),k=void 0):A&&=(A.id===l||A.id===y?x=A.id:I(A,`下一条消息必须涉及待销毁的参与者`,`The next message must involve the destroyed participant`),void 0),D+=1,D>a.messages){S.push(d(g,n,`消息超过 ${a.messages} 条`,`More than ${a.messages} messages`,`删到 ${a.messages} 条,或拆成两张图`,`Keep at most ${a.messages} messages, or split the diagram`));return}let C=v===`+`?y:``,E=v===`-`?l:``;T.push({type:`message`,from:l,to:y,style:e.style,arrow:e,centralStart:!!o,centralEnd:!!m,create:b,destroy:x,...P(H?p.slice(V+1).trim():``,n),line:n,activate:!!C,deactivate:!!E,activateOn:C,deactivateOn:E})}else S.push(d(g,n,`无法识别的语句「${p.slice(0,40)}」`,`Unrecognized statement: ${p.slice(0,40)}`,`改成 participant、消息、Note、片段、rect、box 或 end`,`Use participant, a message, Note, a fragment, rect, box, or end`))}z.forEach((e,t)=>{if(!(/^\s*(?:style|classDef|linkStyle)\s/i.test(e)&&y.accept(e,v+t)))for(let n of p(e))B(n,v+t)});for(let e of[k,A])e&&I(e,`缺少后续消息`,`Missing a following message`);for(let e of E)S.push(d(g,e.line,`「${e.keyword}」缺少 end`,`"${e.keyword}" is missing end`,`在第 ${z.length?v+z.length-1:e.line} 行后补上 end`,`Add end after the block`));let V=new Map;for(let e of T){if(e.type===`activate`&&V.set(e.id,(V.get(e.id)||0)+1),e.type===`message`&&e.activateOn&&V.set(e.activateOn,(V.get(e.activateOn)||0)+1),e.type===`deactivate`||e.type===`message`&&e.deactivateOn){let t=e.type===`deactivate`?e.id:e.deactivateOn,n=(V.get(t)||0)-1;n<0&&S.push(d(g,e.line,`「${t}」的激活条没有配对的开始`,`Activation of "${t}" has no matching start`,`在这条之前写 activate ${t},或给进入消息加 +`,`Write activate ${t} before this line, or add + to the incoming message`)),V.set(t,Math.max(0,n))}e.destroy&&V.delete(e.destroy)}C.length||S.push(d(g,v,`图中没有参与者`,`The diagram has no participants`,`写 participant,或写一条 A->>B: 消息`,`Add a participant or a message such as A->>B: text`));for(let e of C)e.status=y.statusOf(e.id),e.link=b.get(e.id)??y.linkOf(e.id);let H=0;for(let e of T)e.type===`message`&&(e.status=y.edgeStatusOf(H++));if(S.push(...y.diagnostics()),x.size){let e=[...x.keys()].join(`, `);S.push((0,i.warning)(`IGNORED_STYLE`,g,x.values().next().value,`区段颜色使用中性色:${e}`,`Region colors rendered as neutral: ${e}`,`使用有彩度的颜色`,`Use chromatic colors`))}return{model:{type:`sequence`,participants:C,statements:T,title:O,messages:D},errors:S}}var g=20,_=36,v=12,y=e=>e.icon?g:0;function b(e,{measure:t,width:n,lang:r},o={}){let s=o.config?.sequence,c=s?.mirrorActors!==!1,l=[],u=e.participants.map(e=>({...e})),f=e=>u.find(t=>t.id===e),p=(e,n,r)=>{let o=(0,i.wrapText)(e,168,n,t).slice(0,a.lines);return{lines:o,w:(0,i.snap)(Math.max(64,(0,i.maxWidthOf)(o,n,t)+24)),h:(0,i.snap)(Math.max(32,o.length*18+14+(r?24:0)))}};for(let e of u){let n=e.kind!==`participant`||!!e.icon;e.head=p(e.name,i.FONT.title,n),e.foot={...e.head},(0,i.wrapText)(e.name,168,i.FONT.title,t).length>a.lines&&l.push(d(r,e.line,`参与者「${e.name}」超过 ${a.lines} 行`,`Participant "${e.name}" exceeds ${a.lines} lines`,`缩短名称,说明移到图外`,`Shorten the name and move the description outside`))}let m=(Math.max(320,n)-16)/(u.length+1),h=Math.round(Math.max(96,Math.min(200,m))),g=Math.round(Math.max(96,Math.min(180,m))),v=[],b=[],x=e=>{v.push(e)},S=s?.showSequenceNumbers===!0?1:null,C=1,w=(e,n)=>{let r=e.text||e.icon?(0,i.wrapText)(e.text,Math.max(1,n-y(e)),i.FONT.label,t):[],a=(r.length?r.length*16+8:0)+(e.ordinal?16:0),o=e.create?f(e.create).head.h/2:0,s=e.from===e.to?e.ordinal?12:r.length?0:8:0,c=Math.max(a+(r.length?2:10)+s,o+8),l=(0,i.snap)(Math.max(a+20,c+o+12));Object.assign(e,{lines:r,h:l,lineOffset:c,textW:Math.max((0,i.maxWidthOf)(r,i.FONT.label,t)+y(e),t(e.ordinal,i.FONT.label))})};for(let n of e.statements)if(n.type===`box`||n.type===`rect`||n.type===`fragment`){let e=n.type===`box`||n.type===`rect`&&!n.text&&!n.icon?8:28;x({...n,kind:`open`,h:e,depth:b.length}),b.push(v.at(-1))}else if(n.type===`section`)x({...n,host:b.at(-1),kind:`section`,h:28});else if(n.type===`end`){let e=b.pop();x({...n,kind:`close`,h:12,depth:b.length}),e&&(e.close=v.at(-1))}else if(n.type===`note`){let e=i.FONT.label,o=n.place===`over`?Math.abs(f(n.ids[0]).index-f(n.ids.at(-1)).index):0,s=Math.max(g,Math.min(180,o*132)),c=(0,i.wrapText)(n.text,s,e,t);c.length>a.lines&&l.push(d(r,n.line,`注释超过 ${a.lines} 行`,`Note exceeds ${a.lines} lines`,`缩短注释,或拆成多条 Note`,`Shorten the note or split it into several Note lines`));let u=c.slice(0,a.lines);x({...n,kind:`note`,lines:u,h:(0,i.snap)(Math.max(u.length,+!!n.icon)*16+16),textW:(0,i.maxWidthOf)(u,e,t)+y(n)})}else if(n.type===`participant`)x({...n,kind:`participant`,h:0});else if(n.type===`activate`||n.type===`deactivate`)x({...n,kind:n.type,h:8});else if(n.type===`numbering`)S=n.start,C=n.step;else if(n.type===`message`){let e=S==null?``:String(Number(S.toPrecision(15)));S!=null&&(S+=C);let t={...n,kind:`message`,ordinal:e},r=Math.abs(f(n.from).index-f(n.to).index);w(t,r?Math.max(h,Math.min(200,r*132)):Math.min(168,h)),x(t)}if(l.length)return{width:n,height:0,errors:l};let T=u.length,E=new Map(v.map((e,t)=>[e,t])),D=new Map;for(let e of v){if(e.kind!==`open`||!e.close)continue;let t=[];for(let n=E.get(e)+1;n<E.get(e.close);n+=1)t.push(v[n]);D.set(e,t)}let O=e=>{let t=e.map(e=>f(e).index);return[Math.min(...t),Math.max(...t)]};for(let e of v){if(e.kind!==`open`)continue;let t=e.type===`box`?[...e.members||[]]:[];if(e.type!==`box`)for(let n of D.get(e)||[])(n.kind===`message`||n.kind===`note`)&&t.push(...n.kind===`note`?n.ids:[n.from,n.to]);let n=[...new Set(t)];n.length?[e.lo,e.hi]=O(n):(e.lo=0,e.hi=T-1)}if(l.length)return{width:n,height:0,errors:l};let k=u.map(e=>Math.max(e.head.w,e.foot.w)/2),A=Array(T+1).fill(0),j=Array(T+1).fill(0),M=(e,t)=>{e>=0&&e<=T&&(A[e]=Math.max(A[e],t))},N=(e,t,n)=>{let r=t-e;for(let i=e+1;i<=t;i+=1)M(i,n/r)};u.forEach((e,t)=>{M(t,k[t]+12),M(t+1,k[t]+12),j[t]=Math.max(j[t],k[t]+12),j[t+1]=Math.max(j[t+1],k[t]+12),t>0&&(M(t,k[t-1]+k[t]+16),j[t]=Math.max(j[t],k[t-1]+k[t]+16))});for(let e=1;e<T;e+=1)j[e]=Math.max(j[e],24);let P=new Map,F=[...k];for(let e of v){let t=e.activateOn||e.type===`activate`&&e.id,n=e.deactivateOn||e.type===`deactivate`&&e.id;if(t){let e=P.get(t)||0;P.set(t,e+1);let n=f(t).index;F[n]=Math.max(F[n],5+e*7)}n&&P.set(n,(P.get(n)||1)-1),e.destroy&&P.delete(e.destroy)}for(let e=0;e<T;e+=1)F[e]>k[e]&&M(e,F[e]+(e>0?k[e-1]+16:12));for(let e of v)if(e.kind===`note`){if(e.place!==`over`)M(e.place===`left`?f(e.ids[0]).index:f(e.ids.at(-1)).index+1,e.textW+28);else{let[t,n]=O(e.ids);t===n?M(n+1,e.textW+44):N(t,n,e.textW+28)}}let I=e=>_+(e.create?f(e.create).head.w/2:0);for(let e of v)if(e.kind===`message`){let[t,n]=O([e.from,e.to]);if(t===n)M(t+1,e.textW+60);else{let r=A.slice(t+1,n+1).reduce((e,t)=>e+t,0),i=e.textW+I(e)-r;if(i>0)for(let e=t+1;e<=n;e++)A[e]+=i/(n-t)}}let L=A.map((e,t)=>Math.max(e,j[t])),R=()=>{let e=[],t=L[0];for(let n=0;n<T;n+=1)e.push(t),t+=L[n+1];return e},z=(e,t)=>{let n=t[f(e.ids[0]).index],r=t[f(e.ids.at(-1)).index],a=(0,i.snap)(e.textW+16),o=e.h-8;if(e.place===`over`&&n!==r){let e=Math.max(a,Math.abs(n-r)+24);return{x:(n+r-e)/2,w:e,h:o}}return{x:e.place===`left`?n-a-16:n+16,w:a,h:o}},B=e=>[e.keyword,e.text].filter(Boolean).join(` `),V=e=>e.type===`fragment`?`${e.keyword}${e.text?` [${e.text}]`:``}`:e.text,H=e=>{let n=new Map;for(let t of v)t.kind===`note`&&n.set(t,z(t,e));let r=new Map;for(let a=v.length-1;a>=0;--a){let o=v[a];if(o.kind!==`open`||o.lo==null)continue;let s=18+o.depth*12,c=e[o.lo]-(o.type===`box`?k[o.lo]+4:s),l=e[o.hi]+(o.type===`box`?k[o.hi]+4:s);for(let t of D.get(o)||[])if(t.kind===`message`){let n=e[f(t.from).index],r=e[f(t.to).index];if(t.create){let e=f(t.create).head.w/2;c=Math.min(c,r-e-8),l=Math.max(l,r+e+8)}if(n===r)l=Math.max(l,n+52+t.textW+8);else{let e=(n+r)/2;c=Math.min(c,e-t.textW/2-4),l=Math.max(l,e+t.textW/2+4)}}else if(t.kind===`note`&&n.has(t)){let e=n.get(t);c=Math.min(c,e.x),l=Math.max(l,e.x+e.w)}else t.kind===`open`&&r.has(t)&&(c=Math.min(c,r.get(t).left-6),l=Math.max(l,r.get(t).right+6));let u=[t(V(o),i.FONT.label)+y(o),...o.sections.map(e=>t(B(e),i.FONT.label)+y(e))];l=Math.max(l,c+20+Math.max(...u)),r.set(o,{left:c,right:l})}let a=e[0]-F[0],o=e[T-1]+k[T-1];for(let e of r.values())a=Math.min(a,e.left),o=Math.max(o,e.right);for(let e of n.values())a=Math.min(a,e.x),o=Math.max(o,e.x+e.w);for(let t of v){if(t.kind!==`message`)continue;let n=e[f(t.from).index],r=e[f(t.to).index];if(n===r)o=Math.max(o,n+52+t.textW+8);else{let e=(n+r)/2;a=Math.min(a,e-t.textW/2-4),o=Math.max(o,e+t.textW/2+4)}}return{notes:n,frames:r,left:a,right:o}},U=R(),W=H(U);for(let e=0;e<4;e+=1){let e=Math.floor(n)-16-(W.right-W.left);if(e<1)break;let t=Math.min(e/(T+1),128);if(t<1)break;for(let e=0;e<=T;e+=1)L[e]+=t;U=R(),W=H(U)}for(let e of v)if(e.kind===`message`){let[t,n]=O([e.from,e.to]);t!==n&&w(e,U[n]-U[t]-I(e)+1e-6),e.lines.length>a.lines&&l.push(d(r,e.line,`消息「${e.text}」超过 ${a.lines} 行`,`Message "${e.text}" exceeds ${a.lines} lines`,`缩短消息,说明移到图外`,`Shorten the message and move details outside`))}if(l.length)return{width:n,height:0,errors:l};W=H(U);let ee=8-W.left;U=U.map(e=>e+ee),W=H(U),u.forEach((e,t)=>{e.x=U[t]});for(let[e,t]of W.notes)e.note=t;for(let[e,t]of W.frames)e.left=t.left,e.right=t.right;let G=W.right,te=v.some(e=>e.type===`box`),K=(0,i.snap)(8+Math.max(36,...u.map(e=>e.head.h))+12),q=K+(te?28:8),J=q;for(let e of v)e.y=J,J+=e.h;let ne=c?(0,i.snap)(Math.max(...u.map(e=>e.foot.h))+12):0,Y=J+8,re=Y+ne+8;for(let e of v){if(e.kind!==`open`||!e.close)continue;let t=e.type===`box`?K+20:e.y,n=(e.type===`box`?Y+4:e.close.y+e.close.h)-t;e.box={x:e.left,y:t,w:e.right-e.left,h:n}}for(let e of v)e.note&&(e.note.y=e.y+4);let X=[],Z=new Map(u.map(e=>[e.id,[]])),ie=e=>e.y+e.lineOffset,ae=new Map,oe=new Map,se=(e,t)=>{let n=Z.get(e),r={id:e,x:f(e).x-5-n.length*7,y:t,h:0};n.push(r),X.push(r)},Q=(e,t,n=16)=>{let r=Z.get(e).pop();r&&(r.h=Math.max(n,t-r.y))};for(let e of v){if(e.type===`activate`&&se(e.id,e.y+4),e.type===`deactivate`&&Q(e.id,e.y+4),e.kind!==`message`)continue;let t=ie(e);if(e.create&&ae.set(e.create,t),e.destroy&&oe.set(e.destroy,t),e.activateOn&&se(e.activateOn,t+(e.create?f(e.create).head.h/2:0)),e.fromBar=Z.get(e.from).at(-1),e.toBar=Z.get(e.to).at(-1),e.deactivateOn&&e.destroy!==e.deactivateOn&&Q(e.deactivateOn,t+8),e.destroy)for(;Z.get(e.destroy).length;)Q(e.destroy,t,0)}let ce=[...X].sort((e,t)=>e.x-t.x),le=(e,t,n)=>{let r=e.x+8;for(let e of ce){if(e.y>t+18||e.y+e.h<t)continue;let i=e.x+16;e.x<r+n&&i>r&&(r=i)}return r};for(let e of v){if(e.kind===`open`&&e.box&&e.type!==`box`){let n=V(e);if(!n&&!e.icon)continue;let r=t(n,i.FONT.label)+y(e);e.labelX=le(e.box,e.box.y,r),e.box.w=Math.max(e.box.w,e.labelX+r+12-e.box.x),G=Math.max(G,e.box.x+e.box.w)}if(e.kind===`section`){let{host:n}=e;if(!n?.box)continue;let r=t(B(e),i.FONT.label)+y(e);e.labelX=le(n.box,e.y,r),n.box.w=Math.max(n.box.w,e.labelX+r+12-n.box.x),G=Math.max(G,n.box.x+n.box.w)}}for(let e of u){let t=ae.get(e.id),n=oe.get(e.id);e.head.x=e.x-e.head.w/2,e.head.y=t==null?8:t-e.head.h/2,e.life={x:e.x,y1:t==null?q-4:t+e.head.h/2,y2:n??Y},e.destroyed=n!=null,e.destroyed||!c?e.foot=null:(e.foot.x=e.x-e.foot.w/2,e.foot.y=Y+8);for(let t of Z.get(e.id))t.h=Math.max(0,e.life.y2-t.y)}let $=(0,i.snap)(G+8),ue=$<=n?Math.floor(n):$;return($>n*2||u.length>60||e.messages>200)&&l.push((0,i.warning)(`LARGE_DIAGRAM`,r,u[0].line,`时序图较大,可滚动查看`,`Large sequence diagram; scroll to view it`,`可将时序图拆分`,`Consider splitting the diagram`)),{type:`sequence`,width:ue,height:(0,i.snap)(re),actors:u,events:v,activations:X,errors:l,title:e.title}}function x(e,t){let n=(0,i.appearance)(t),r=[],a=(e,n,r,i)=>{let[a,o,s,c]=e.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c);return t.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`},e.elements.map(({tag:n,attrs:r})=>t.shape(n,{...r,...e.set===`simple`?{fill:i}:{fill:`none`,stroke:i,"stroke-width":1.7,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))},o=(e,{x:r,y:o,lines:s,icon:c,meta:l,font:u=i.FONT.label,anchor:d=`middle`,lineHeight:f=16,fill:p=n.fg2,underline:m=!1})=>{let h=s.length?s:[``],_=o-(h.length-1)/2*f,v=[];if(c){let e=d===`middle`,n=e?t.measure(h[0],u.size,u.weight):0;v.push(a(c,e?r-n/2-(h[0]?2:0):r+8,_,p)),r+=e?g/2:g}h.forEach((e,n)=>{if(!e)return;let i=t.text(r,_+n*f,e,{anchor:d,size:u.size,weight:u.weight,fill:p,"dominant-baseline":`central`,...m?{"text-decoration":`underline`}:{}});v.push(l?{...i,meta:l}:i)}),v.length&&e.push(t.el(`g`,{},v))},s=(e,n,r,i,a={})=>t.line(e,n,r,i,a),c={arrow:`M1 1 L8 5 L1 9 Z`,open:`M1 1 L8 5 L1 9`,cross:`M1 1 L9 9 M1 9 L9 1`,top:`M1 1 L8 5 H1 Z`,bottom:`M1 9 L8 5 H1 Z`,"stick-top":`M1 1 L8 5`,"stick-bottom":`M1 9 L8 5`},l=(e,t)=>`seq-arrow${e===`arrow`?``:`-${e}`}${t?`-${t}`:``}`,u=e=>e?.replace(/top|bottom/,e=>e===`top`?`bottom`:`top`),d=new Map;for(let r of e.events)if(r.arrow)for(let e of[r.arrow.head,u(r.arrow.start)]){if(!c[e])continue;let i=l(e,r.status),a=n[r.status]??n.fg3;d.has(i)||d.set(i,t.el(`marker`,{id:i,viewBox:`0 0 10 10`,refX:e===`cross`?5:8,refY:5,markerWidth:10,markerHeight:10,orient:`auto-start-reverse`,markerUnits:`userSpaceOnUse`},[t.path(c[e],{fill:c[e].endsWith(`Z`)?a:`none`,stroke:a,"stroke-width":1.2})]))}d.size&&r.push(t.el(`defs`,{},[...d.values()]));let f={actor:`M12 1 a3 3 0 1 0 .01 0 M12 7 v7 m-6-4 h12 m-6 4 l-5 6 m5-6 l5 6`,boundary:`M16 3 a7 7 0 1 0 .01 0 M9 10 H3 M3 4 v12`,control:`M12 4 a7 7 0 1 0 .01 0 M15 1 l-4 3 4 3`,entity:`M12 2 a7 7 0 1 0 .01 0 M5 17 h14`,database:`M4 5 a8 3 0 1 0 16 0 a8 3 0 1 0-16 0 v12 a8 3 0 0 0 16 0 V5 M4 11 a8 3 0 0 0 16 0`,queue:`M19 3 a3 7 0 1 0 0 14 a3 7 0 1 0 0-14 H5 a3 7 0 0 0 0 14 h14`,collections:`M7 4 V2 h14 v13 h-3 M3 6 h14 v13 H3 Z`},p=t.frameTone(n.accent),m=t.frameTone(n.tones[1]),h=e=>{if(!e.box)return;let{x:i,y:a,w:s,h:c}=e.box,l=[],u=e.type===`box`,d=e.type===`rect`&&e.color,f=n[e.status],h=f?t.frameTone(f):e.color?n.line:m,g=/^transparent$/i.test(e.color)?`none`:d?f||n.fg4:e.type===`rect`?t.tint(n.bg,p,n.soft):u?t.tint(n.bg,e.color&&!f?n.fg4:h,.08):t.mix(n.bg,n.fg4,.07),_=d?`none`:e.type===`rect`?p:u?h:n.line;if(l.push(t.rect(i,a,s,c,{fill:g,stroke:_,...d?{"fill-opacity":.1}:e.type===`rect`?{"stroke-opacity":.45}:{},"stroke-width":1,rx:n.smallRadius,...u?{"stroke-dasharray":`5 4`}:{}})),u)(e.text||e.icon)&&o(r,{x:i+s/2,y:a-10,lines:[e.text],icon:e.icon});else if(e.type!==`rect`||e.text||e.icon){let t=e.type===`rect`?e.text:e.keyword+(e.text?` [`+e.text+`]`:``);o(l,{x:e.labelX??i+8,y:a+12,lines:[t],icon:e.icon,anchor:`start`})}r.push({...t.el(`g`,{},l),meta:{kind:`frame`,id:`sequence-frame-${e.y}`}})};for(let t of e.events)t.kind===`open`&&h(t);for(let t of e.actors)r.push(s(t.life.x,t.life.y1,t.life.x,t.life.y2,{stroke:n.line2,"stroke-width":1}));for(let i of e.activations)i.h>0&&r.push(t.rect(i.x,i.y,10,i.h,{fill:t.tint(n.bg,p,.28),stroke:p,"stroke-opacity":.45,"stroke-width":1}));let _=t=>e.actors.find(e=>e.id===t),y=[],b=e.events.filter(e=>e.kind===`open`&&e.type===`box`).map(e=>e.box);for(let i of e.events){if(i.kind===`section`){let{host:e}=i;if(!e?.box)continue;r.push(s(e.box.x,i.y+4,e.box.x+e.box.w,i.y+4,{stroke:n.line,"stroke-dasharray":`3 3`})),o(r,{x:i.labelX??e.box.x+8,y:i.y+14,lines:[[i.keyword,i.text].filter(Boolean).join(` `)],icon:i.icon,anchor:`start`})}if(i.kind===`note`){let{x:e,y:a,w:s,h:c}=i.note,l=[];l.push(t.rect(e,a,s,c,{fill:n.surface,stroke:n.line2,"stroke-width":1,rx:n.smallRadius}));let u=i.place===`over`&&i.ids[0]!==i.ids.at(-1);o(l,{x:u?e+s/2:e+8,y:a+c/2,lines:i.lines,icon:i.icon,anchor:u?`middle`:`start`}),r.push(t.el(`g`,{},l))}if(i.kind!==`message`)continue;let e=_(i.from),a=_(i.to),c=i.y+i.lineOffset,d=e===a,f=a.x>=e.x?1:-1,{head:p,start:m,dashed:h}=i.arrow,g=n[i.status]??n.fg3,x={stroke:g,"stroke-width":1.5,"stroke-linecap":`butt`,...h?{"stroke-dasharray":`5 4`}:{},...m?{"marker-start":`url(#${l(u(m),i.status)})`}:{},...p===`none`?{}:{"marker-end":`url(#${l(p,i.status)})`}},S=i.centralStart?e.x:i.fromBar?i.fromBar.x+(f>0?10:0):e.x+f*(d?6:8),C=d?c-14:c,w=d?c+4:c,T=i.create&&w>=a.head.y&&w<=a.head.y+a.head.h,E=i.centralEnd&&!i.create,D=T?f>0?a.head.x:a.head.x+a.head.w:E||p===`cross`&&i.destroy===a.id?a.x:!i.create&&i.toBar?i.toBar.x+(d||f<0?10:0):a.x-(d?-1:f)*v,O=S+(i.centralStart&&m?f*7:0),k=D-(E&&p!==`none`?(d?-1:f)*7:0),A=d?t.path(`M${O} ${C} h${40+S-O} v18 H${k}`,{fill:`none`,...x}):s(O,c,k,c,x);(T?y:r).push({...A,meta:{kind:`message`,from:e.id,to:a.id}});let j=(e,n)=>r.push(t.el(`circle`,{cx:e,cy:n,r:3.5,fill:g}));i.centralStart&&j(S,C),E&&j(D,w);let M=d?e.x+52:i.create?(S+D)/2:(e.x+a.x)/2,N=d?c-20-(i.lines.length-1)*8:c-i.lines.length*8-10,P=c-(i.lines.length*16+(d?28:18)),F=d?M:M-i.textW/2,I=F+i.textW,L=(i.ordinal?P:N-(i.lines.length-1)*8)-7,R=(i.lines.length?N+(i.lines.length-1)*8:P)+7;i.textW&&b.some(e=>e.y<R&&e.y+e.h>L&&[e.x,e.x+e.w].some(e=>F-2<e&&e<I+2))&&r.push(t.rect(F-4,L,i.textW+8,R-L,{fill:n.bg,rx:n.smallRadius}));let z={kind:`message-label`,from:e.id,to:a.id};if((i.lines.length||i.icon)&&o(r,{x:M,y:N,lines:i.lines,icon:i.icon,meta:z,anchor:d?`start`:`middle`}),i.ordinal&&o(r,{x:M,y:P,lines:[i.ordinal],meta:z,anchor:d?`start`:`middle`,fill:n.fg3}),i.destroy&&(p!==`cross`||i.destroy!==a.id)){let e=_(i.destroy).x;r.push(t.path(`M${e-4} ${c-4} l8 8 m0 -8 l-8 8`,{fill:`none`,stroke:n.fg3,"stroke-width":1.5}))}}for(let s of e.actors)for(let e of[s.head,s.foot].filter(Boolean)){let c=[],l=f[s.kind],u=n[s.status];c.push(t.rect(e.x,e.y,e.w,e.h,{fill:u?t.tint(n.surface,u,.12):n.surface,stroke:u?t.frameTone(u):n.line,"stroke-width":1,rx:n.smallRadius})),s.icon?c.push(a(s.icon,s.x,e.y+16,n.fg3)):l&&c.push(t.path(l,{transform:`translate(${s.x-12} ${e.y+6})`,fill:`none`,stroke:n.fg3,"stroke-width":1.3,"stroke-linecap":`round`,"stroke-linejoin":`round`})),o(c,{x:s.x,y:e.y+e.h/2+(l||s.icon?12:0),lines:e.lines,font:i.FONT.title,lineHeight:18,fill:n.fg1,underline:!!s.link});let d={...t.el(`g`,{},c),meta:{kind:`participant`,id:s.id}};r.push(s.link?t.link(s.link.href,[d],s.link):d)}return r.push(...y),{width:e.width,height:e.height,children:r,title:e.title,heading:e.title}}var S={sequenceDiagram:{parse:h,layout:b,scene:x,acceptsPresentation:!0,honoredConfig:[`sequence.mirrorActors`,`sequence.showSequenceNumbers`]}};return e.LIMITS=a,e.implementations=S,e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
2
|
+
`);function B(e,n){if(!e.trim()||e.trimStart().startsWith(`%%`))return;if(/^\s*\t|^\s+\t/.test(e)||e.includes(` `)){S.push(d(g,n,`时序图语句不能使用 Tab`,`Tabs are not allowed in sequence statements`,`把 Tab 换成空格`,`Replace tabs with spaces`));return}let p=e.trim(),h=/^title(?:\s*:\s*|\s+)(.+)$/i.exec(p);if(h){O=P(h[1],n).text;return}let _=/^(link|links|properties|details)\s+([^\s:]+)\s*:\s*(.*)$/i.exec(p);if(_){let[,e,t,i]=_;if(M(`IGNORED_INTERACTION`,n,`已省略参与者菜单和详情界面;仅保留首个安全链接`,`Participant menus and details are omitted; only the first safe URL is kept`,`把其他必要链接放在图外`,`Put other essential links outside the diagram`),!b.has(t)){let n=[];if(e.toLowerCase()===`link`){let e=/^(.*?)@\s*(.+)$/.exec(i);e&&(n=[[e[1].trim(),e[2]]])}else if(e.toLowerCase()===`links`)try{let e=JSON.parse(i);e&&typeof e==`object`&&!Array.isArray(e)&&(n=Object.entries(e))}catch{}for(let[e,i]of n){let n=typeof i==`string`&&(0,r.safeHref)(i.trim());if(n){b.set(t,{href:n,tooltip:e});break}}}return}if(y.accept(p,n))return;let v=/^(?:(create)\s+)?(participant|actor)\s+([^\s@]+)(?:\s*@\{([^}]*)\})?(?:\s+as\s+(.+))?$/i.exec(p);if(v){let[,e,r,a,o,c]=v,[,l,f]=/^(.*?)::icon\(([^)]+)\)$/.exec(a)??[],p=F(l??a,n),h=m(o);if(!u(p)){S.push(d(g,n,`参与者 ID 无效`,`Invalid participant id`,`写成 participant ID as 名称`,`Write participant ID as Name`));return}if(e&&(w.has(p)||k)){I({id:p,line:n},`重复创建或已有待创建的参与者`,`Duplicate or already pending creation`);return}let _=L(p,n);if(!_)return;let y=h.type||r.toLowerCase();s.has(y)||M(`DIAGRAM_HINT`,n,`未知参与者类型,使用普通方框`,`Unknown participant type; using a standard participant`,`检查 type`,`Check the type value`);let{text:b,icon:x}=P(c||h.alias||p,n),C=f||h.icon,D=C?(0,t.resolveIconRef)(C):null;C&&!D&&N((0,i.warning)(`IGNORED_ASSET`,g,n,`未知图标 ${C}`,`Unknown icon ${C}`,`使用内置图标`,`Use a supported icon`)),Object.assign(_,{name:b,icon:D||x,kind:s.has(y)?y:`participant`,declared:!0,line:n}),e&&(k={id:p,line:n}),E.at(-1)?.type===`box`&&E.at(-1).members.push(p),T.push({type:`participant`,id:p,line:n});return}let C=/^destroy\s+(\S+)$/i.exec(p);if(C){let e=C[1];!w.has(e)||A?I({id:e,line:n},`未知参与者或已有待销毁的参与者`,`Unknown participant or already pending destruction`):A={id:e,line:n};return}let j=/^autonumber(?:\s+(off|[+-]?\d+(?:\.\d+)?)(?:\s+([+-]?\d+(?:\.\d+)?))?)?$/i.exec(p);if(j){T.push({type:`numbering`,start:j[1]?.toLowerCase()===`off`?null:Number(j[1]??1),step:Number(j[2]??1),line:n});return}if(/^activate\s+(\S+)$/i.test(p)||/^deactivate\s+(\S+)$/i.test(p)){let[,e,t]=/^(activate|deactivate)\s+(\S+)$/i.exec(p);if(!L(t,n))return;T.push({type:e.toLowerCase(),id:t,line:n});return}let z=/^Note\s+(over\s+(\S+?)(?:\s*,\s*(\S+))?|left\s+of\s+(\S+)|right\s+of\s+(\S+))\s*:\s*(.*)$/i.exec(p);if(z){let e=z[2]?[z[2],z[3]].filter(Boolean):[z[4]||z[5]];if(e.some(e=>!L(e,n)))return;T.push({type:`note`,place:z[2]?`over`:z[4]?`left`:`right`,ids:e,...P(z[6].trim(),n),line:n});return}let B=/^(alt|opt|loop|par_over|par|critical|break|rect|box|else|and|option|end)(?:\s+(.*)|$)/i.exec(p);if(B){let e=B[1].toLowerCase().replace(`par_over`,`par`),t=(B[2]||``).trim(),i,s;if(e===`box`||e===`rect`){i=f.exec(t)?.[0]||/^transparent\b/i.exec(t)?.[0];let e=t.split(/\s/,1)[0];!i&&((0,r.roleOfColor)(e)||/^(?:black|white|(?:light|dark|slate|dim)?gr[ae]y|silver)$/i.test(e))&&(i=e),i&&(s=(0,r.roleOfColor)(i),s||/^transparent$/i.test(i)||x.has(i)||x.set(i,n),t=t.slice(i.length).trim())}if(e===`end`){t&&S.push(d(g,n,`end 后面不能再写内容`,`end cannot have trailing text`,`这一行只写 end`,`Leave only end on this line`)),R(n);return}let{text:c,icon:l}=P(t,n);if(o.has(e)){let t=E.at(-1),r={else:[`alt`],and:[`par`],option:[`critical`]}[e];if(!t||!r.includes(t.keyword)){S.push(d(g,n,`「${e}」不能出现在当前片段里`,`"${e}" is not valid in the current fragment`,`把它放到对应的 ${r.join(`/`)} 片段中`,`Place it inside ${r.join(`/`)} before end`));return}T.push({type:`section`,keyword:e,text:c,icon:l,line:n,owner:t}),t.sections.push({keyword:e,text:c,icon:l,line:n});return}if(E.length>=a.fragmentDepth){S.push(d(g,n,`组合片段最多嵌套 ${a.fragmentDepth} 层`,`Fragments nest at most ${a.fragmentDepth} levels`,`把内层片段拆到另一张图`,`Move the inner fragment to another diagram`));return}let u={type:e===`box`?`box`:e===`rect`?`rect`:`fragment`,keyword:e,text:c,icon:l,color:i,status:s,line:n,kind:e===`box`||e===`rect`?e:`fragment`,sections:[],members:[]};T.push(u),E.push(u);return}let V=Array.from(p.matchAll(/:::[\w-]+|:/g)).find(e=>e[0]===`:`)?.index,H=V!==void 0,U=H?p.slice(0,V):p,W=l.exec(U);if(W?.index>0){let e=c.get(W[0].toLowerCase()),t=/^(.*?)\s*(\(\))?\s*(\+)?$/.exec(U.slice(0,W.index).trim()),r=/^([+-])?\s*(\(\))?\s*(.*?)\s*(\+)?$/.exec(U.slice(W.index+W[0].length).trim()),[,i,o,s]=t,l=F(i,n),[,f,m,h,_]=r,v=f||s||_||(h.endsWith(`-`)&&!w.has(h)?`-`:``),y=F(v===`-`&&!f&&h.endsWith(`-`)?h.slice(0,-1):h,n);if(!u(l)||!u(y)){S.push(d(g,n,`消息的参与者写法无效`,`Invalid message participants`,`写成 A->>B: 消息,自调用写成 A->>A: 消息`,`Write A->>B: message, or A->>A: message for a self call`));return}if(!L(l,n)||!L(y,n))return;let b,x;if(k?(k.id===y?b=y:I(k,`下一条消息必须发给新参与者`,`The next message must target the new participant`),k=void 0):A&&=(A.id===l||A.id===y?x=A.id:I(A,`下一条消息必须涉及待销毁的参与者`,`The next message must involve the destroyed participant`),void 0),D+=1,D>a.messages){S.push(d(g,n,`消息超过 ${a.messages} 条`,`More than ${a.messages} messages`,`删到 ${a.messages} 条,或拆成两张图`,`Keep at most ${a.messages} messages, or split the diagram`));return}let C=v===`+`?y:``,E=v===`-`?l:``;T.push({type:`message`,from:l,to:y,style:e.style,arrow:e,centralStart:!!o,centralEnd:!!m,create:b,destroy:x,...P(H?p.slice(V+1).trim():``,n),line:n,activate:!!C,deactivate:!!E,activateOn:C,deactivateOn:E})}else S.push(d(g,n,`无法识别的语句「${p.slice(0,40)}」`,`Unrecognized statement: ${p.slice(0,40)}`,`改成 participant、消息、Note、片段、rect、box 或 end`,`Use participant, a message, Note, a fragment, rect, box, or end`))}z.forEach((e,t)=>{if(!(/^\s*(?:style|classDef|linkStyle)\s/i.test(e)&&y.accept(e,v+t)))for(let n of p(e))B(n,v+t)});for(let e of[k,A])e&&I(e,`缺少后续消息`,`Missing a following message`);for(let e of E)S.push(d(g,e.line,`「${e.keyword}」缺少 end`,`"${e.keyword}" is missing end`,`在第 ${z.length?v+z.length-1:e.line} 行后补上 end`,`Add end after the block`));let V=new Map;for(let e of T){if(e.type===`activate`&&V.set(e.id,(V.get(e.id)||0)+1),e.type===`message`&&e.activateOn&&V.set(e.activateOn,(V.get(e.activateOn)||0)+1),e.type===`deactivate`||e.type===`message`&&e.deactivateOn){let t=e.type===`deactivate`?e.id:e.deactivateOn,n=(V.get(t)||0)-1;n<0&&S.push(d(g,e.line,`「${t}」的激活条没有配对的开始`,`Activation of "${t}" has no matching start`,`在这条之前写 activate ${t},或给进入消息加 +`,`Write activate ${t} before this line, or add + to the incoming message`)),V.set(t,Math.max(0,n))}e.destroy&&V.delete(e.destroy)}C.length||S.push(d(g,v,`图中没有参与者`,`The diagram has no participants`,`写 participant,或写一条 A->>B: 消息`,`Add a participant or a message such as A->>B: text`));for(let e of C)e.status=y.statusOf(e.id),e.link=b.get(e.id)??y.linkOf(e.id);let H=0;for(let e of T)e.type===`message`&&(e.status=y.edgeStatusOf(H++));if(S.push(...y.diagnostics()),x.size){let e=[...x.keys()].join(`, `);S.push((0,i.warning)(`IGNORED_STYLE`,g,x.values().next().value,`区段颜色使用中性色:${e}`,`Region colors rendered as neutral: ${e}`,`使用有彩度的颜色`,`Use chromatic colors`))}return{model:{type:`sequence`,participants:C,statements:T,title:O,messages:D},errors:S}}var g=20,_=36,v=12,y=e=>e.icon?g:0;function b(e,{measure:t,width:n,lang:r,compact:o},s={}){let c=s.config?.sequence,l=c?.mirrorActors!==!1,u=[],f=e.participants.map(e=>({...e})),p=e=>f.find(t=>t.id===e),m=(e,n,r)=>{let o=(0,i.wrapText)(e,168,n,t).slice(0,a.lines);return{lines:o,w:(0,i.snap)(Math.max(64,(0,i.maxWidthOf)(o,n,t)+24)),h:(0,i.snap)(Math.max(32,o.length*18+14+(r?24:0)))}};for(let e of f){let n=e.kind!==`participant`||!!e.icon;e.head=m(e.name,i.FONT.title,n),e.foot={...e.head},(0,i.wrapText)(e.name,168,i.FONT.title,t).length>a.lines&&u.push(d(r,e.line,`参与者「${e.name}」超过 ${a.lines} 行`,`Participant "${e.name}" exceeds ${a.lines} lines`,`缩短名称,说明移到图外`,`Shorten the name and move the description outside`))}let h=(Math.max(320,n)-16)/(f.length+1),g=Math.round(Math.max(96,Math.min(200,h))),v=Math.round(Math.max(96,Math.min(180,h))),b=[],x=[],S=e=>{b.push(e)},C=c?.showSequenceNumbers===!0?1:null,w=1,T=(e,n)=>{let r=e.text||e.icon?(0,i.wrapText)(e.text,Math.max(1,n-y(e)),i.FONT.label,t):[],a=(r.length?r.length*16+8:0)+(e.ordinal?16:0),o=e.create?p(e.create).head.h/2:0,s=e.from===e.to?e.ordinal?12:r.length?0:8:0,c=Math.max(a+(r.length?2:10)+s,o+8),l=(0,i.snap)(Math.max(a+20,c+o+12));Object.assign(e,{lines:r,h:l,lineOffset:c,textW:Math.max((0,i.maxWidthOf)(r,i.FONT.label,t)+y(e),t(e.ordinal,i.FONT.label))})};for(let n of e.statements)if(n.type===`box`||n.type===`rect`||n.type===`fragment`){let e=n.type===`box`||n.type===`rect`&&!n.text&&!n.icon?8:28;S({...n,kind:`open`,h:e,depth:x.length}),x.push(b.at(-1))}else if(n.type===`section`)S({...n,host:x.at(-1),kind:`section`,h:28});else if(n.type===`end`){let e=x.pop();S({...n,kind:`close`,h:12,depth:x.length}),e&&(e.close=b.at(-1))}else if(n.type===`note`){let e=i.FONT.label,o=n.place===`over`?Math.abs(p(n.ids[0]).index-p(n.ids.at(-1)).index):0,s=Math.max(v,Math.min(180,o*132)),c=(0,i.wrapText)(n.text,s,e,t);c.length>a.lines&&u.push(d(r,n.line,`注释超过 ${a.lines} 行`,`Note exceeds ${a.lines} lines`,`缩短注释,或拆成多条 Note`,`Shorten the note or split it into several Note lines`));let l=c.slice(0,a.lines);S({...n,kind:`note`,lines:l,h:(0,i.snap)(Math.max(l.length,+!!n.icon)*16+16),textW:(0,i.maxWidthOf)(l,e,t)+y(n)})}else if(n.type===`participant`)S({...n,kind:`participant`,h:0});else if(n.type===`activate`||n.type===`deactivate`)S({...n,kind:n.type,h:8});else if(n.type===`numbering`)C=n.start,w=n.step;else if(n.type===`message`){let e=C==null?``:String(Number(C.toPrecision(15)));C!=null&&(C+=w);let t={...n,kind:`message`,ordinal:e},r=Math.abs(p(n.from).index-p(n.to).index);T(t,r?Math.max(g,Math.min(200,r*132)):Math.min(168,g)),S(t)}if(u.length)return{width:n,height:0,errors:u};let E=f.length,D=new Map(b.map((e,t)=>[e,t])),O=new Map;for(let e of b){if(e.kind!==`open`||!e.close)continue;let t=[];for(let n=D.get(e)+1;n<D.get(e.close);n+=1)t.push(b[n]);O.set(e,t)}let k=e=>{let t=e.map(e=>p(e).index);return[Math.min(...t),Math.max(...t)]};for(let e of b){if(e.kind!==`open`)continue;let t=e.type===`box`?[...e.members||[]]:[];if(e.type!==`box`)for(let n of O.get(e)||[])(n.kind===`message`||n.kind===`note`)&&t.push(...n.kind===`note`?n.ids:[n.from,n.to]);let n=[...new Set(t)];n.length?[e.lo,e.hi]=k(n):(e.lo=0,e.hi=E-1)}if(u.length)return{width:n,height:0,errors:u};let A=f.map(e=>Math.max(e.head.w,e.foot.w)/2),j=Array(E+1).fill(0),M=Array(E+1).fill(0),N=(e,t)=>{e>=0&&e<=E&&(j[e]=Math.max(j[e],t))},P=(e,t,n)=>{let r=t-e;for(let i=e+1;i<=t;i+=1)N(i,n/r)};f.forEach((e,t)=>{N(t,A[t]+12),N(t+1,A[t]+12),M[t]=Math.max(M[t],A[t]+12),M[t+1]=Math.max(M[t+1],A[t]+12),t>0&&(N(t,A[t-1]+A[t]+16),M[t]=Math.max(M[t],A[t-1]+A[t]+16))});for(let e=1;e<E;e+=1)M[e]=Math.max(M[e],24);let F=new Map,I=[...A];for(let e of b){let t=e.activateOn||e.type===`activate`&&e.id,n=e.deactivateOn||e.type===`deactivate`&&e.id;if(t){let e=F.get(t)||0;F.set(t,e+1);let n=p(t).index;I[n]=Math.max(I[n],5+e*7)}n&&F.set(n,(F.get(n)||1)-1),e.destroy&&F.delete(e.destroy)}for(let e=0;e<E;e+=1)I[e]>A[e]&&N(e,I[e]+(e>0?A[e-1]+16:12));for(let e of b)if(e.kind===`note`){if(e.place!==`over`)N(e.place===`left`?p(e.ids[0]).index:p(e.ids.at(-1)).index+1,e.textW+28);else{let[t,n]=k(e.ids);t===n?N(n+1,e.textW+44):P(t,n,e.textW+28)}}let L=e=>_+(e.create?p(e.create).head.w/2:0);for(let e of b)if(e.kind===`message`){let[t,n]=k([e.from,e.to]);if(t===n)N(t+1,e.textW+60);else{let r=j.slice(t+1,n+1).reduce((e,t)=>e+t,0),i=e.textW+L(e)-r;if(i>0)for(let e=t+1;e<=n;e++)j[e]+=i/(n-t)}}let R=j.map((e,t)=>Math.max(e,M[t])),z=()=>{let e=[],t=R[0];for(let n=0;n<E;n+=1)e.push(t),t+=R[n+1];return e},B=(e,t)=>{let n=t[p(e.ids[0]).index],r=t[p(e.ids.at(-1)).index],a=(0,i.snap)(e.textW+16),o=e.h-8;if(e.place===`over`&&n!==r){let e=Math.max(a,Math.abs(n-r)+24);return{x:(n+r-e)/2,w:e,h:o}}return{x:e.place===`left`?n-a-16:n+16,w:a,h:o}},V=e=>[e.keyword,e.text].filter(Boolean).join(` `),H=e=>e.type===`fragment`?`${e.keyword}${e.text?` [${e.text}]`:``}`:e.text,U=e=>{let n=new Map;for(let t of b)t.kind===`note`&&n.set(t,B(t,e));let r=new Map;for(let a=b.length-1;a>=0;--a){let o=b[a];if(o.kind!==`open`||o.lo==null)continue;let s=18+o.depth*12,c=e[o.lo]-(o.type===`box`?A[o.lo]+4:s),l=e[o.hi]+(o.type===`box`?A[o.hi]+4:s);for(let t of O.get(o)||[])if(t.kind===`message`){let n=e[p(t.from).index],r=e[p(t.to).index];if(t.create){let e=p(t.create).head.w/2;c=Math.min(c,r-e-8),l=Math.max(l,r+e+8)}if(n===r)l=Math.max(l,n+52+t.textW+8);else{let e=(n+r)/2;c=Math.min(c,e-t.textW/2-4),l=Math.max(l,e+t.textW/2+4)}}else if(t.kind===`note`&&n.has(t)){let e=n.get(t);c=Math.min(c,e.x),l=Math.max(l,e.x+e.w)}else t.kind===`open`&&r.has(t)&&(c=Math.min(c,r.get(t).left-6),l=Math.max(l,r.get(t).right+6));let u=[t(H(o),i.FONT.label)+y(o),...o.sections.map(e=>t(V(e),i.FONT.label)+y(e))];l=Math.max(l,c+20+Math.max(...u)),r.set(o,{left:c,right:l})}let a=e[0]-I[0],o=e[E-1]+A[E-1];for(let e of r.values())a=Math.min(a,e.left),o=Math.max(o,e.right);for(let e of n.values())a=Math.min(a,e.x),o=Math.max(o,e.x+e.w);for(let t of b){if(t.kind!==`message`)continue;let n=e[p(t.from).index],r=e[p(t.to).index];if(n===r)o=Math.max(o,n+52+t.textW+8);else{let e=(n+r)/2;a=Math.min(a,e-t.textW/2-4),o=Math.max(o,e+t.textW/2+4)}}return{notes:n,frames:r,left:a,right:o}},W=z(),G=U(W);for(let e=0;!o&&e<4;e+=1){let e=Math.floor(n)-16-(G.right-G.left);if(e<1)break;let t=Math.min(e/(E+1),128);if(t<1)break;for(let e=0;e<=E;e+=1)R[e]+=t;W=z(),G=U(W)}for(let e of b)if(e.kind===`message`){let[t,n]=k([e.from,e.to]);t!==n&&T(e,W[n]-W[t]-L(e)+1e-6),e.lines.length>a.lines&&u.push(d(r,e.line,`消息「${e.text}」超过 ${a.lines} 行`,`Message "${e.text}" exceeds ${a.lines} lines`,`缩短消息,说明移到图外`,`Shorten the message and move details outside`))}if(u.length)return{width:n,height:0,errors:u};G=U(W);let ee=8-G.left;W=W.map(e=>e+ee),G=U(W),f.forEach((e,t)=>{e.x=W[t]});for(let[e,t]of G.notes)e.note=t;for(let[e,t]of G.frames)e.left=t.left,e.right=t.right;let K=G.right,te=b.some(e=>e.type===`box`),ne=(0,i.snap)(8+Math.max(36,...f.map(e=>e.head.h))+12),q=ne+(te?28:8),J=q;for(let e of b)e.y=J,J+=e.h;let re=l?(0,i.snap)(Math.max(...f.map(e=>e.foot.h))+12):0,Y=J+8,ie=Y+re+8;for(let e of b){if(e.kind!==`open`||!e.close)continue;let t=e.type===`box`?ne+20:e.y,n=(e.type===`box`?Y+4:e.close.y+e.close.h)-t;e.box={x:e.left,y:t,w:e.right-e.left,h:n}}for(let e of b)e.note&&(e.note.y=e.y+4);let X=[],Z=new Map(f.map(e=>[e.id,[]])),ae=e=>e.y+e.lineOffset,Q=new Map,oe=new Map,se=(e,t)=>{let n=Z.get(e),r={id:e,x:p(e).x-5-n.length*7,y:t,h:0};n.push(r),X.push(r)},$=(e,t,n=16)=>{let r=Z.get(e).pop();r&&(r.h=Math.max(n,t-r.y))};for(let e of b){if(e.type===`activate`&&se(e.id,e.y+4),e.type===`deactivate`&&$(e.id,e.y+4),e.kind!==`message`)continue;let t=ae(e);if(e.create&&Q.set(e.create,t),e.destroy&&oe.set(e.destroy,t),e.activateOn&&se(e.activateOn,t+(e.create?p(e.create).head.h/2:0)),e.fromBar=Z.get(e.from).at(-1),e.toBar=Z.get(e.to).at(-1),e.deactivateOn&&e.destroy!==e.deactivateOn&&$(e.deactivateOn,t+8),e.destroy)for(;Z.get(e.destroy).length;)$(e.destroy,t,0)}let ce=[...X];if(e.zenuml)for(let e of f){let t=Q.get(e.id),n=t==null?q-4:t+e.head.h/2;ce.push({x:e.x-1,y:n,h:Y-n})}let le=ce.sort((e,t)=>e.x-t.x),ue=(e,t,n)=>{let r=e.x+8;for(let e of le){if(e.y>t+18||e.y+e.h<t)continue;let i=e.x+16;e.x<r+n&&i>r&&(r=i)}return r};for(let e of b){if(e.kind===`open`&&e.box&&e.type!==`box`){let n=H(e);if(!n&&!e.icon)continue;let r=t(n,i.FONT.label)+y(e);e.labelX=ue(e.box,e.box.y,r),e.box.w=Math.max(e.box.w,e.labelX+r+12-e.box.x),K=Math.max(K,e.box.x+e.box.w)}if(e.kind===`section`){let{host:n}=e;if(!n?.box)continue;let r=t(V(e),i.FONT.label)+y(e);e.labelX=ue(n.box,e.y,r),n.box.w=Math.max(n.box.w,e.labelX+r+12-n.box.x),K=Math.max(K,n.box.x+n.box.w)}}for(let e of f){let t=Q.get(e.id),n=oe.get(e.id);e.head.x=e.x-e.head.w/2,e.head.y=t==null?8:t-e.head.h/2,e.life={x:e.x,y1:t==null?q-4:t+e.head.h/2,y2:n??Y},e.destroyed=n!=null,e.destroyed||!l?e.foot=null:(e.foot.x=e.x-e.foot.w/2,e.foot.y=Y+8);for(let t of Z.get(e.id))t.h=Math.max(0,e.life.y2-t.y)}let de=(0,i.snap)(K+8),fe=!o&&de<=n?Math.floor(n):de;return(de>n*2||f.length>60||e.messages>200)&&u.push((0,i.warning)(`LARGE_DIAGRAM`,r,f[0].line,`时序图较大,可滚动查看`,`Large sequence diagram; scroll to view it`,`可将时序图拆分`,`Consider splitting the diagram`)),{type:`sequence`,width:fe,height:(0,i.snap)(ie),actors:f,events:b,activations:X,errors:u,title:e.title,...e.zenuml?{zenuml:!0}:{}}}function x(e,t){let n=(0,i.appearance)(t),r=[],a=(e,n,r,i)=>{let[a,o,s,c]=e.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c);return t.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`},e.elements.map(({tag:n,attrs:r})=>t.shape(n,{...r,...e.set===`simple`?{fill:i}:{fill:`none`,stroke:i,"stroke-width":1.7,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))},o=(e,{x:r,y:o,lines:s,icon:c,meta:l,font:u=i.FONT.label,anchor:d=`middle`,lineHeight:f=16,fill:p=n.fg2,underline:m=!1})=>{let h=s.length?s:[``],_=o-(h.length-1)/2*f,v=[];if(c){let e=d===`middle`,n=e?t.measure(h[0],u.size,u.weight):0;v.push(a(c,e?r-n/2-(h[0]?2:0):r+8,_,p)),r+=e?g/2:g}h.forEach((e,n)=>{if(!e)return;let i=t.text(r,_+n*f,e,{anchor:d,size:u.size,weight:u.weight,fill:p,"dominant-baseline":`central`,...m?{"text-decoration":`underline`}:{}});v.push(l?{...i,meta:l}:i)}),v.length&&e.push(t.el(`g`,{},v))},s=(e,n,r,i,a={})=>t.line(e,n,r,i,a),c={arrow:`M1 1 L8 5 L1 9 Z`,open:`M1 1 L8 5 L1 9`,cross:`M1 1 L9 9 M1 9 L9 1`,top:`M1 1 L8 5 H1 Z`,bottom:`M1 9 L8 5 H1 Z`,"stick-top":`M1 1 L8 5`,"stick-bottom":`M1 9 L8 5`},l=(e,t)=>`seq-arrow${e===`arrow`?``:`-${e}`}${t?`-${t}`:``}`,u=e=>e?.replace(/top|bottom/,e=>e===`top`?`bottom`:`top`),d=new Map;for(let r of e.events)if(r.arrow)for(let e of[r.arrow.head,u(r.arrow.start)]){if(!c[e])continue;let i=l(e,r.status),a=n[r.status]??n.fg3;d.has(i)||d.set(i,t.el(`marker`,{id:i,viewBox:`0 0 10 10`,refX:e===`cross`?5:8,refY:5,markerWidth:10,markerHeight:10,orient:`auto-start-reverse`,markerUnits:`userSpaceOnUse`},[t.path(c[e],{fill:c[e].endsWith(`Z`)?a:`none`,stroke:a,"stroke-width":1.2})]))}d.size&&r.push(t.el(`defs`,{},[...d.values()]));let f={actor:`M12 1 a3 3 0 1 0 .01 0 M12 7 v7 m-6-4 h12 m-6 4 l-5 6 m5-6 l5 6`,boundary:`M16 3 a7 7 0 1 0 .01 0 M9 10 H3 M3 4 v12`,control:`M12 4 a7 7 0 1 0 .01 0 M15 1 l-4 3 4 3`,entity:`M12 2 a7 7 0 1 0 .01 0 M5 17 h14`,database:`M4 5 a8 3 0 1 0 16 0 a8 3 0 1 0-16 0 v12 a8 3 0 0 0 16 0 V5 M4 11 a8 3 0 0 0 16 0`,queue:`M19 3 a3 7 0 1 0 0 14 a3 7 0 1 0 0-14 H5 a3 7 0 0 0 0 14 h14`,collections:`M7 4 V2 h14 v13 h-3 M3 6 h14 v13 H3 Z`},p=t.frameTone(n.accent),m=t.frameTone(n.tones[1]),h=e=>{if(!e.box)return;let{x:i,y:a,w:s,h:c}=e.box,l=[],u=e.type===`box`,d=e.type===`rect`&&e.color,f=n[e.status],h=f?t.frameTone(f):e.color?n.line:m,g=/^transparent$/i.test(e.color)?`none`:d?f||n.fg4:e.type===`rect`?t.tint(n.bg,p,n.soft):u?t.tint(n.bg,e.color&&!f?n.fg4:h,.08):t.mix(n.bg,n.fg4,.07),_=d?`none`:e.type===`rect`?p:u?h:n.line;if(l.push(t.rect(i,a,s,c,{fill:g,stroke:_,...d?{"fill-opacity":.1}:e.type===`rect`?{"stroke-opacity":.45}:{},"stroke-width":1,rx:n.smallRadius,...u?{"stroke-dasharray":`5 4`}:{}})),u)(e.text||e.icon)&&o(r,{x:i+s/2,y:a-10,lines:[e.text],icon:e.icon});else if(e.type!==`rect`||e.text||e.icon){let t=e.type===`rect`?e.text:e.keyword+(e.text?` [`+e.text+`]`:``);o(l,{x:e.labelX??i+8,y:a+12,lines:[t],icon:e.icon,anchor:`start`})}r.push({...t.el(`g`,{},l),meta:{kind:`frame`,id:`sequence-frame-${e.y}`}})};for(let t of e.events)t.kind===`open`&&h(t);let _=r.length,y=[];if(!e.zenuml)for(let t of e.actors)r.push(s(t.life.x,t.life.y1,t.life.x,t.life.y2,{stroke:n.line2,"stroke-width":1}));for(let i of e.activations)i.h>0&&r.push(t.rect(i.x,i.y,10,i.h,{fill:t.tint(n.bg,p,.28),stroke:p,"stroke-opacity":.45,"stroke-width":1}));let b=t=>e.actors.find(e=>e.id===t),x=[],S=e.events.filter(e=>e.kind===`open`&&e.type===`box`).map(e=>e.box);for(let i of e.events){if(i.kind===`section`){let{host:e}=i;if(!e?.box)continue;r.push(s(e.box.x,i.y+4,e.box.x+e.box.w,i.y+4,{stroke:n.line,"stroke-dasharray":`3 3`})),o(r,{x:i.labelX??e.box.x+8,y:i.y+14,lines:[[i.keyword,i.text].filter(Boolean).join(` `)],icon:i.icon,anchor:`start`})}if(i.kind===`note`){let{x:e,y:a,w:s,h:c}=i.note,l=[];l.push(t.rect(e,a,s,c,{fill:n.surface,stroke:n.line2,"stroke-width":1,rx:n.smallRadius}));let u=i.place===`over`&&i.ids[0]!==i.ids.at(-1);o(l,{x:u?e+s/2:e+8,y:a+c/2,lines:i.lines,icon:i.icon,anchor:u?`middle`:`start`}),r.push(t.el(`g`,{},l))}if(i.kind!==`message`)continue;let a=b(i.from),c=b(i.to),d=i.y+i.lineOffset,f=a===c,p=c.x>=a.x?1:-1,{head:m,start:h,dashed:g}=i.arrow,_=n[i.status]??n.fg3,C={stroke:_,"stroke-width":1.5,"stroke-linecap":`butt`,...g?{"stroke-dasharray":`5 4`}:{},...h?{"marker-start":`url(#${l(u(h),i.status)})`}:{},...m===`none`?{}:{"marker-end":`url(#${l(m,i.status)})`}},w=i.centralStart?a.x:i.fromBar?i.fromBar.x+(p>0?10:0):a.x+p*(f?6:8),T=f?d-14:d,E=f?d+4:d,D=i.create&&E>=c.head.y&&E<=c.head.y+c.head.h,O=i.centralEnd&&!i.create,k=D?p>0?c.head.x:c.head.x+c.head.w:O||m===`cross`&&i.destroy===c.id?c.x:!i.create&&i.toBar?i.toBar.x+(f||p<0?10:0):c.x-(f?-1:p)*v,A=w+(i.centralStart&&h?p*7:0),j=k-(O&&m!==`none`?(f?-1:p)*7:0),M=f?t.path(`M${A} ${T} h${40+w-A} v18 H${j}`,{fill:`none`,...C}):s(A,d,j,d,C);(D?x:r).push({...M,meta:{kind:`message`,from:a.id,to:c.id}});let N=(e,n)=>r.push(t.el(`circle`,{cx:e,cy:n,r:3.5,fill:_}));i.centralStart&&N(w,T),O&&N(k,E);let P=f?a.x+52:i.create?(w+k)/2:(a.x+c.x)/2,F=f?d-20-(i.lines.length-1)*8:d-i.lines.length*8-10,I=d-(i.lines.length*16+(f?28:18)),L=f?P:P-i.textW/2,R=L+i.textW,z=(i.ordinal?I:F-(i.lines.length-1)*8)-7,B=(i.lines.length?F+(i.lines.length-1)*8:I)+7;e.zenuml&&i.textW&&y.push({left:L-2,right:R+2,top:z-2,bottom:B+2}),i.textW&&S.some(e=>e.y<B&&e.y+e.h>z&&[e.x,e.x+e.w].some(e=>L-2<e&&e<R+2))&&r.push(t.rect(L-4,z,i.textW+8,B-z,{fill:n.bg,rx:n.smallRadius}));let V={kind:`message-label`,from:a.id,to:c.id};if((i.lines.length||i.icon)&&o(r,{x:P,y:F,lines:i.lines,icon:i.icon,meta:V,anchor:f?`start`:`middle`}),i.ordinal&&o(r,{x:P,y:I,lines:[i.ordinal],meta:V,anchor:f?`start`:`middle`,fill:n.fg3}),i.destroy&&(m!==`cross`||i.destroy!==c.id)){let e=b(i.destroy).x;r.push(t.path(`M${e-4} ${d-4} l8 8 m0 -8 l-8 8`,{fill:`none`,stroke:n.fg3,"stroke-width":1.5}))}}for(let s of e.actors)for(let e of[s.head,s.foot].filter(Boolean)){let c=[],l=f[s.kind],u=n[s.status];c.push(t.rect(e.x,e.y,e.w,e.h,{fill:u?t.tint(n.surface,u,.12):n.surface,stroke:u?t.frameTone(u):n.line,"stroke-width":1,rx:n.smallRadius})),s.icon?c.push(a(s.icon,s.x,e.y+16,n.fg3)):l&&c.push(t.path(l,{transform:`translate(${s.x-12} ${e.y+6})`,fill:`none`,stroke:n.fg3,"stroke-width":1.3,"stroke-linecap":`round`,"stroke-linejoin":`round`})),o(c,{x:s.x,y:e.y+e.h/2+(l||s.icon?12:0),lines:e.lines,font:i.FONT.title,lineHeight:18,fill:n.fg1,underline:!!s.link});let d={...t.el(`g`,{},c),meta:{kind:`participant`,id:s.id}};r.push(s.link?t.link(s.link.href,[d],s.link):d)}if(r.push(...x),e.zenuml){let t=[];for(let{life:{x:r,y1:i,y2:a}}of e.actors){let e=i,o=i=>{i>e&&t.push(s(r,e,r,i,{stroke:n.fg3,"stroke-width":1,"stroke-dasharray":`4 4`}))};for(let t of y)r>=t.left&&r<=t.right&&t.bottom>e&&t.top<a&&(o(t.top),e=t.bottom);o(a)}r.splice(_,0,...t)}return{width:e.width,height:e.height,children:r,title:e.title,heading:e.title}}var S={sequenceDiagram:{parse:h,layout:b,scene:x,acceptsPresentation:!0,honoredConfig:[`sequence.mirrorActors`,`sequence.showSequenceNumbers`]}};return e.LIMITS=a,e.implementations=S,e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -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
|
|
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:
|
|
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
|
|
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
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}){let a=Math.max(240,r-48),o=q(e.sets,1),s=J(K(e.sets,1,o)),c=Math.max(56,Math.min(a/Math.max(1,s.w),k/Math.max(1,s.h))),l=se(K(e.sets,c,o),e),u=null;for(let n=0;n<=ee&&(u=Q(t=>K(e.sets,c,t),l,t,o),!(u.worst>=0));n+=1){let t=c*O;if(J(K(e.sets,t,o)).w>a*2)break;c=t}let d=u.rings,f=[];for(let e of l)e.block.room>=0||f.push({region:e,rows:[...e.block.labels,...e.block.items]});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,icon:t.icon,link:t.link,status:t.status}]});let m=[];f.length&&m.push((0,n.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,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 h=l.filter(e=>e.block.h>0&&e.block.room>=0);for(let e of h)ce(e);return $({mode:`rings`,rings:d,regions:h,plot:J(d),rows:h.flatMap(e=>e.rows),shelf:f,notes:m},e,{measure:t,width:r})}function ue(e,{measure:t,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 c=new Set(o.map(e=>e.key));for(let t of e.texts)c.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,n.wrapText)(e,140,r,(e,n)=>t(e,n));for(let e of o){let n=(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=n(e.titles,M),e.captionLines=e.caption?d(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 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+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 C=[(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: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:t,width:r})}function $(e,t,{measure:r,width:i}){let a=t.title?(0,n.wrapText)(t.title,Math.max(160,Math.min(i-48,480)),j,(e,t)=>r(e,t)):[],l=a.length?a.length*s+c: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],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}));d.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-_}}),p=Math.max(p,i+s.length*u),f=Math.max(f,n+c),a=Math.max(a,s.length*u),n+=c+g}}let m=Math.max(e.plot.x+e.plot.w,f)-e.plot.x,v=Math.max(m,...a.map(e=>r(e,j))),b=o+(v-m)/2-e.plot.x,x=o+l-e.plot.y,S=Math.ceil(p-e.plot.y+l+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;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:a.length?{lines:a,x:o+v/2,top:34}:null,rings:e.rings||[],regions:e.regions||[],panels:e.panels||[],rows:e.rows,shelf:d,notes:e.notes,anchor:{x:o+v/2,y:o+l+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`;if(!e.sets.length)return{width:i,height:0,errors:[]};let o=e.sets.length<=te?le(e,{measure:r,width:i,lang:a}):ue(e,{measure:r,width:i,lang:a}),s=[...o.notes],c=e.sets.length+e.unions.length+e.texts.length;return c>A?s.push((0,n.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,n.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 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.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,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`]);
|
|
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`]);
|