@fengwk/kchart 0.0.0-stage → 0.1.1
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 +17 -0
- package/LICENSE +21 -0
- package/NOTICE.md +11 -0
- package/README.md +68 -2
- package/README.zh-CN.md +69 -0
- package/dist/LICENSE +21 -0
- package/dist/NOTICE.md +11 -0
- package/dist/assets/ICONS-LICENSE.txt +53 -0
- package/dist/assets/maps/LICENSE.md +75 -0
- package/dist/assets/maps/METADATA.md +9 -0
- package/dist/assets/maps/REGIONS.md +28 -0
- package/dist/assets/maps/us-states.geojson +1 -0
- package/dist/assets/maps/world.geojson +1 -0
- package/dist/esm/_virtual/_kchart-families.js +48 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +12 -0
- package/dist/esm/assets/icons.js +11 -0
- package/dist/esm/assets/maps/us-states.js +3 -0
- package/dist/esm/assets/maps/world.js +3 -0
- package/dist/esm/assets/themes/claude.js +69 -0
- package/dist/esm/assets/themes/cloudmusic.js +62 -0
- package/dist/esm/assets/themes/kanagawa.js +67 -0
- package/dist/esm/assets/themes/obsidian.js +67 -0
- package/dist/esm/assets/themes/paper.js +61 -0
- package/dist/esm/assets/themes/terminal.js +60 -0
- package/dist/esm/assets/themes/tokyo.js +62 -0
- package/dist/esm/chart/basic.js +1313 -0
- package/dist/esm/chart/catalog.js +476 -0
- package/dist/esm/chart/composition.js +844 -0
- package/dist/esm/chart/context.js +189 -0
- package/dist/esm/chart/distribution.js +442 -0
- package/dist/esm/chart/fields.js +67 -0
- package/dist/esm/chart/maps.js +563 -0
- package/dist/esm/chart/mindmap.js +629 -0
- package/dist/esm/chart/multivariate.js +1229 -0
- package/dist/esm/chart/registry.js +108 -0
- package/dist/esm/chart/relations.js +949 -0
- package/dist/esm/chart/spec.js +1415 -0
- package/dist/esm/chart/stat-compare.js +302 -0
- package/dist/esm/chart/stat-trend.js +181 -0
- package/dist/esm/chart/statistics.js +1007 -0
- package/dist/esm/chart/unit-variants.js +645 -0
- package/dist/esm/chart/variants.js +552 -0
- package/dist/esm/core/color.js +197 -0
- package/dist/esm/core/context.js +256 -0
- package/dist/esm/core/diagnostics.js +23 -0
- package/dist/esm/core/format.js +167 -0
- package/dist/esm/core/geometry.js +130 -0
- package/dist/esm/core/icon-data.js +5 -0
- package/dist/esm/core/icons.js +173 -0
- package/dist/esm/core/scale.js +112 -0
- package/dist/esm/core/scene.js +234 -0
- package/dist/esm/core/svg.js +89 -0
- package/dist/esm/core/text.js +184 -0
- package/dist/esm/core/theme.js +318 -0
- package/dist/esm/diagram/agentflow.js +596 -0
- package/dist/esm/diagram/architecture.js +729 -0
- package/dist/esm/diagram/block.js +988 -0
- package/dist/esm/diagram/blocks.js +687 -0
- package/dist/esm/diagram/c4.js +1002 -0
- package/dist/esm/diagram/class.js +1158 -0
- package/dist/esm/diagram/cynefin.js +749 -0
- package/dist/esm/diagram/emphasis.js +7 -0
- package/dist/esm/diagram/er.js +657 -0
- package/dist/esm/diagram/eventmodeling.js +948 -0
- package/dist/esm/diagram/gantt-date.js +323 -0
- package/dist/esm/diagram/gantt.js +661 -0
- package/dist/esm/diagram/gitgraph.js +472 -0
- package/dist/esm/diagram/graph-layout.js +4046 -0
- package/dist/esm/diagram/graph-parse.js +1366 -0
- package/dist/esm/diagram/graph-route.js +490 -0
- package/dist/esm/diagram/graph.js +553 -0
- package/dist/esm/diagram/ishikawa.js +496 -0
- package/dist/esm/diagram/journey.js +512 -0
- package/dist/esm/diagram/kanban.js +280 -0
- package/dist/esm/diagram/label.js +56 -0
- package/dist/esm/diagram/layers.js +385 -0
- package/dist/esm/diagram/map-label.js +44 -0
- package/dist/esm/diagram/mindmap.js +277 -0
- package/dist/esm/diagram/numeric-composition.js +78 -0
- package/dist/esm/diagram/numeric-model.js +86 -0
- package/dist/esm/diagram/numeric-parse.js +205 -0
- package/dist/esm/diagram/numeric-radar.js +355 -0
- package/dist/esm/diagram/numeric-sankey.js +201 -0
- package/dist/esm/diagram/numeric-xy.js +422 -0
- package/dist/esm/diagram/packet.js +175 -0
- package/dist/esm/diagram/presentation.js +252 -0
- package/dist/esm/diagram/quadrant.js +297 -0
- package/dist/esm/diagram/railroad-parse.js +465 -0
- package/dist/esm/diagram/railroad.js +294 -0
- package/dist/esm/diagram/registry.js +296 -0
- package/dist/esm/diagram/relations.js +966 -0
- package/dist/esm/diagram/requirement.js +341 -0
- package/dist/esm/diagram/sequence.js +1228 -0
- package/dist/esm/diagram/shapes.js +366 -0
- package/dist/esm/diagram/source.js +538 -0
- package/dist/esm/diagram/support.js +153 -0
- package/dist/esm/diagram/swimlane-mermaid.js +140 -0
- package/dist/esm/diagram/swimlane.js +1186 -0
- package/dist/esm/diagram/time.js +748 -0
- package/dist/esm/diagram/timeline.js +376 -0
- package/dist/esm/diagram/tree-family-icon.js +22 -0
- package/dist/esm/diagram/treeview.js +293 -0
- package/dist/esm/diagram/usecase.js +852 -0
- package/dist/esm/diagram/venn.js +1038 -0
- package/dist/esm/diagram/wardley.js +838 -0
- package/dist/esm/index.d.ts +133 -0
- package/dist/esm/index.js +92 -0
- package/dist/esm/interaction.js +561 -0
- package/dist/esm/mermaid.d.ts +28 -0
- package/dist/esm/mermaid.js +70 -0
- package/dist/esm/node.d.ts +68 -0
- package/dist/esm/node.js +373 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/page-api.js +65 -0
- package/dist/esm/runtime.js +352 -0
- package/dist/esm/src/families.js +209 -0
- package/dist/page-api.js +1 -0
- package/dist/units/chart/basic.js +1 -0
- package/dist/units/chart/catalog.js +1 -0
- package/dist/units/chart/composition.js +1 -0
- package/dist/units/chart/context.js +1 -0
- package/dist/units/chart/distribution.js +1 -0
- package/dist/units/chart/fields.js +1 -0
- package/dist/units/chart/maps.js +1 -0
- package/dist/units/chart/mindmap.js +1 -0
- package/dist/units/chart/multivariate.js +1 -0
- package/dist/units/chart/registry.js +1 -0
- package/dist/units/chart/relations.js +1 -0
- package/dist/units/chart/spec.js +3 -0
- package/dist/units/chart/stat-compare.js +1 -0
- package/dist/units/chart/stat-trend.js +1 -0
- package/dist/units/chart/statistics.js +1 -0
- package/dist/units/chart/unit-variants.js +1 -0
- package/dist/units/chart/variants.js +1 -0
- package/dist/units/core/color.js +1 -0
- package/dist/units/core/context.js +1 -0
- package/dist/units/core/diagnostics.js +1 -0
- package/dist/units/core/format.js +1 -0
- package/dist/units/core/geometry.js +1 -0
- package/dist/units/core/icon-data.js +1 -0
- package/dist/units/core/icons.js +1 -0
- package/dist/units/core/scale.js +1 -0
- package/dist/units/core/scene.js +1 -0
- package/dist/units/core/svg.js +1 -0
- package/dist/units/core/text.js +2 -0
- package/dist/units/core/theme.js +1 -0
- package/dist/units/diagram/agentflow.js +12 -0
- package/dist/units/diagram/architecture.js +4 -0
- package/dist/units/diagram/block.js +2 -0
- package/dist/units/diagram/blocks.js +2 -0
- package/dist/units/diagram/c4.js +6 -0
- package/dist/units/diagram/class.js +5 -0
- package/dist/units/diagram/cynefin.js +4 -0
- package/dist/units/diagram/emphasis.js +1 -0
- package/dist/units/diagram/er.js +9 -0
- package/dist/units/diagram/eventmodeling.js +5 -0
- package/dist/units/diagram/gantt-date.js +1 -0
- package/dist/units/diagram/gantt.js +3 -0
- package/dist/units/diagram/gitgraph.js +2 -0
- package/dist/units/diagram/graph-layout.js +4 -0
- package/dist/units/diagram/graph-parse.js +9 -0
- package/dist/units/diagram/graph-route.js +1 -0
- package/dist/units/diagram/graph.js +1 -0
- package/dist/units/diagram/ishikawa.js +2 -0
- package/dist/units/diagram/journey.js +5 -0
- package/dist/units/diagram/kanban.js +2 -0
- package/dist/units/diagram/label.js +4 -0
- package/dist/units/diagram/layers.js +1 -0
- package/dist/units/diagram/map-label.js +1 -0
- package/dist/units/diagram/mindmap.js +2 -0
- package/dist/units/diagram/numeric-composition.js +1 -0
- package/dist/units/diagram/numeric-model.js +1 -0
- package/dist/units/diagram/numeric-parse.js +2 -0
- package/dist/units/diagram/numeric-radar.js +3 -0
- package/dist/units/diagram/numeric-sankey.js +2 -0
- package/dist/units/diagram/numeric-xy.js +2 -0
- package/dist/units/diagram/packet.js +2 -0
- package/dist/units/diagram/presentation.js +2 -0
- package/dist/units/diagram/quadrant.js +2 -0
- package/dist/units/diagram/railroad-parse.js +4 -0
- package/dist/units/diagram/railroad.js +1 -0
- package/dist/units/diagram/registry.js +2 -0
- package/dist/units/diagram/relations.js +3 -0
- package/dist/units/diagram/requirement.js +3 -0
- package/dist/units/diagram/sequence.js +2 -0
- package/dist/units/diagram/shapes.js +60 -0
- package/dist/units/diagram/source.js +20 -0
- package/dist/units/diagram/support.js +3 -0
- package/dist/units/diagram/swimlane-mermaid.js +3 -0
- package/dist/units/diagram/swimlane.js +2 -0
- package/dist/units/diagram/time.js +3 -0
- package/dist/units/diagram/timeline.js +2 -0
- package/dist/units/diagram/tree-family-icon.js +1 -0
- package/dist/units/diagram/treeview.js +2 -0
- package/dist/units/diagram/usecase.js +3 -0
- package/dist/units/diagram/venn.js +2 -0
- package/dist/units/diagram/wardley.js +4 -0
- package/dist/units/interaction.js +1 -0
- package/dist/units/runtime.js +1 -0
- package/dist/units.json +712 -0
- package/package.json +30 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
KChartUnits["diagram/graph-layout"]=(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i={...t.FONT,frame:{size:13,weight:600},erHead:{size:14,weight:600},erAttr:{size:13,weight:400},erKey:{size:12,weight:400}},a=14,o=16,s=e=>e===`new`?`+ `:e===`info`?`~ `:e===`ok`?`= `:``;function c(e,t){let n=e.titleLines.length*19,r=e.descLines.length*17,i=e.descLines.length?7:0,a=t.y+Math.max(10,(t.h-n-i-r)/2);return{titleY:a+n/2,descY:e.descLines.length?a+n+i+r/2:null}}var l=(e,t)=>e.kind===`real`&&t.kind===`real`?28:e.kind===`label`||t.kind===`label`?18:20;function u(e){let t=new Map(e.subgraphs.map(e=>[e.id,e]));if(![...t.values()].some(e=>e.view===`collapsed`))return e;let n=new Map([...e.nodes,...e.subgraphs].map(e=>[e.id,e])),r=new Map;for(let e of n.values()){let n=e.view===`collapsed`?e.id:null;for(let r=e.parent;r;r=t.get(r)?.parent)t.get(r)?.view===`collapsed`&&(n=r);n!=null&&r.set(e.id,n)}let i=e.nodes.filter(e=>!r.has(e.id));for(let e of t.values())r.get(e.id)===e.id&&i.push({...e,label:e.title,shape:`rounded`,kind:`collapsed`});let a=e.subgraphs.filter(e=>!r.has(e.id)),o=e.edges.flatMap(e=>{let t=r.get(e.from)??e.from,n=r.get(e.to)??e.to;return t===n&&r.has(t)?[]:[{...e,from:t,to:n,fromFrame:e.fromFrame&&!r.has(t),toFrame:e.toFrame&&!r.has(n)}]});return{...e,nodes:i,subgraphs:a,edges:o}}function d(e){let t=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),n=e.edges.filter(e=>e.style!==`invisible`).map(e=>e.segments),r=0;for(let e=0;e<n.length;e+=1)for(let i=e+1;i<n.length;i+=1)for(let a of n[e])for(let e of n[i])t(a.p0,a.p1,e.p0)*t(a.p0,a.p1,e.p1)<-1e-6&&t(e.p0,e.p1,a.p0)*t(e.p0,e.p1,a.p1)<-1e-6&&(r+=1);return r}function f(e,t,n){let r=e.direction===`LR`||e.direction===`RL`,i=new Map([...e.nodes,...e.frames].map(e=>[e.id,r?e.y+e.h/2:e.x+e.w/2]));return new Map(n.map(n=>{let r=e.model.edges.flatMap(e=>e.from===n&&!t.has(e.to)?[e.to]:e.to===n&&!t.has(e.from)?[e.from]:[]).map(e=>i.get(e)).filter(Number.isFinite);return[n,r.length?r.reduce((e,t)=>e+t,0)/r.length:i.get(n)]}))}var p=60,m=12;function h(e,t){if(!e.blocks?.length||e.nodes.length>p)return e;let n=new Map(e.model.nodes.map(e=>[e.id,e.seq])),r=e,i=d(e),a=new Map,o=0;for(let s of e.blocks){if(!i)break;let e=s.members.filter(e=>n.has(e));if(e.length<2)continue;let c=f(r,new Set(s.members),e),l=e.map(e=>n.get(e)).sort((e,t)=>e-t),u=new Set([e.slice().sort((e,t)=>(a.get(e)??n.get(e))-(a.get(t)??n.get(t))).join(`
|
|
2
|
+
`)]);for(let s of[1,-1]){let f=e.slice().sort((e,t)=>c.get(e)-c.get(t)||s*(n.get(e)-n.get(t)));if(u.has(f.join(`
|
|
3
|
+
`))||o>=m)continue;u.add(f.join(`
|
|
4
|
+
`)),o+=1;let p=new Map(a);f.forEach((e,t)=>p.set(e,l[t]));let h=t(p);if(!h.blocks)continue;let g=d(h);g<i&&({best:r,score:i,hints:a}={best:h,score:g,hints:p})}}return r}function g(e,r={},i={}){let a=t=>{let a=_(e,r,i,!0,t);return(0,n.repairRoutes)(a),a},o=e.type===`er`?_(e,r,i):h(a(null),a);return e.type!==`er`&&(0,n.placeGraphLabels)(o,r.measure??t.fallbackMeasure),delete o.blocks,e.type!==`er`&&(e.nodes.length>60||o.width>(r.width??1/0)*2)&&(o.errors=[(0,t.warning)(`LARGE_DIAGRAM`,r.lang??i.lang,i.headerLine??1,`图较大,可在框内滚动`,`Large diagram; scroll within the frame`,`考虑拆成多张图`,`Consider splitting the diagram`)]),o}function _(e,r,a,s=!0,c=null){let l=u(e),d=new Map(l.subgraphs.map(e=>[e.id,e])),f=new Set(l.subgraphs.filter(e=>e.kind===`divider`).map(e=>e.parent)),p=new Set,m=new Set,h=new Map,g=[...l.nodes],y=[...l.edges],b=r.measure??t.fallbackMeasure,x=(e,t)=>{for(let n=e.parent;n;n=d.get(n)?.parent)if(n===t.id)return!0;return!1},S=[...g,...l.subgraphs],C=new Set(S.map(e=>e.parent)),w=s&&l.type===`flowchart`&&g.length>0&&g.every(e=>e.parent!=null),T=Object.entries(a.config??{}).find(([e])=>e.toLowerCase()===`flowchart`)?.[1],E=Object.entries(T??{}).some(([e,t])=>e.toLowerCase()===`inheritdir`&&t===!0),D=new Map;for(let e of[...d.values()].sort((e,t)=>e.depth-t.depth||e.seq-t.seq)){let n=w&&!e.parent;if(p.has(e.id)||C.has(e.id)&&!(n||e.dir||E||e.kind===`composite`||e.kind===`divider`||f.has(e.id)))continue;let o=new Set(C.has(e.id)?S.filter(t=>x(t,e)).map(e=>e.id):[]),s=y.some(e=>o.has(e.from)!==o.has(e.to));if(s&&!n)continue;for(let t of o)D.set(t,e.id);let u=t=>t.parent===e.id?{...t,parent:null}:t,d=e=>c?.has(e.id)?{...e,orderSeq:c.get(e.id)}:e,v=y.filter(e=>o.has(e.from)&&o.has(e.to)),T=!s&&e.dir?e.dir:l.type===`flowchart`&&(E||s)?l.direction:`TB`,O=_({...l,direction:T,nodes:g.filter(e=>o.has(e.id)).map(u).map(d),subgraphs:l.subgraphs.filter(e=>o.has(e.id)).map(u),edges:v},r,a,!1),k=e.title?(0,t.wrapText)(e.title,200,i.frame,b):e.icon?[``]:[],A=(e.desc??[]).flatMap(e=>(0,t.wrapText)(e,180,i.body,b)),j=Math.max((0,t.maxWidthOf)(k,i.frame,b)+(e.icon?22:0),(0,t.maxWidthOf)(A,i.body,b)),M=k.length*17+(A.length?4+A.length*16:0),N=M?M+8:0,P=Math.max(O.width,j+32),F=O.height+N;h.set(e.id,{frame:e,inner:O,lines:k,descLines:A,titleW:j,titleH:M,titleBand:N,w:P,h:F,members:o,whole:n});for(let e of o)p.add(e);for(let e of v)m.add(e)}if(!h.size)return v(l,r);let O=e=>h.has(e),k=new Map,A=y.filter(e=>!m.has(e)).map(e=>{let t=D.get(e.from)??e.from,n=D.get(e.to)??e.to;return(t!==e.from||n!==e.to)&&k.set(e.seq,e),{...e,from:t,to:n,fromFrame:e.fromFrame&&!O(t),toFrame:e.toFrame&&!O(n)}}),j=g.filter(e=>!p.has(e.id)),M=[...h.values()].map(({frame:e,w:t,h:n})=>({...e,label:``,block:{w:t,h:n},shape:`rect`})),N=!j.length&&!A.length&&M.every(e=>e.kind===`divider`&&!e.parent),P=l.direction===`TB`||l.direction===`BT`,F=o,I=N?M.sort((e,t)=>e.seq-t.seq).map(({id:e,block:{w:t,h:n}})=>{let r={id:e,x:P?F:o,y:P?o:F,w:t,h:n};return F+=(P?t:n)+o,r}):[],L=N?{type:l.type,direction:l.direction,edges:[],frames:[],labels:[],ranks:[],nodes:I,width:P?F:Math.max(...I.map(e=>e.w))+32,height:P?Math.max(...I.map(e=>e.h))+32:F}:v({...l,nodes:[...j,...M],subgraphs:l.subgraphs.filter(e=>!p.has(e.id)&&!O(e.id)),edges:A},r),R=[];for(let e of L.nodes){let t=h.get(e.id);if(!t){R.push(e);continue}let{frame:n,inner:r,lines:i,descLines:a,titleW:o,titleH:s,titleBand:c,w:l,h:u}=t,d=e.x+(l-r.width)/2,f=e.y+c,p=e=>e&&{...e,x:e.x+d,y:e.y+f},m=e=>e.parent==null?n.id:e.parent;L.frames.push({...n,x:e.x,y:e.y,w:l,h:u,lines:i,descLines:a,titleRect:{x:e.x+16,y:e.y+10,w:o,h:s}}),L.frames.push(...r.frames.map(e=>({...p(e),parent:m(e),titleRect:p(e.titleRect)}))),R.push(...r.nodes.map(e=>({...p(e),parent:m(e),titleY:e.titleY+f,descY:e.descY==null?null:e.descY+f}))),L.labels.push(...r.labels.map(p)),L.edges.push(...r.edges.map(e=>({...e,start:p(e.start),end:p(e.end),labelRect:p(e.labelRect),segments:e.segments.map(({p0:e,c1:t,c2:n,p1:r})=>({p0:p(e),c1:p(t),c2:p(n),p1:p(r)}))})))}for(let e of L.edges)O(e.from)&&(e.fromFrame=!0),O(e.to)&&(e.toFrame=!0);let z={...L,nodes:R,model:l};return k.size&&((0,n.repairRoutes)(z,k),[...k].some(([e,t])=>!z.edges.some(n=>n.id===e&&n.from===t.from&&n.to===t.to)))?_(e,r,a,!1):(w&&(z.blocks=[...h.values()].filter(e=>e.whole).map(({frame:e,members:t})=>({id:e.id,members:[...t]}))),z)}function v(e,{measure:n=t.fallbackMeasure,lang:u,ctx:d,renderOptions:f}={}){let p=t.DIRECTIONS.includes(e.direction)?e.direction:`TB`,m=p===`LR`||p===`RL`,h=new Map,g={id:null,model:null,parent:null,children:[],seq:-1,depth:0,title:``,titleLines:[],descLines:[],titleW:0,titleBand:0},_=[],v=new Map,y=new Map,b=[];for(let t of e.edges)t.from===t.to&&!t.fromFrame&&!t.toFrame&&(y.has(t.from)||y.set(t.from,[]),y.get(t.from).push(t));let x=a=>{let o=e.type===`flowchart`&&(0,r.flowOutlineName)(a.shape),c=o&&(0,r.shapeGlyphBox)(o,1,1,p),l=!c||a.explicitLabel||a.label!==a.id?(e.mermaid?``:s(a.class))+(a.label??a.id):``,u=l?(0,t.wrapText)(l,a.kind===`er`?180:200,i.title,n):[],d=[];for(let e of a.desc||[])d.push(...(0,t.wrapText)(e,200,i.body,n));let f,h,g=null;if(a.kind===`start`)f=14,h=14;else if(a.kind===`end`)f=18,h=18;else if(a.kind===`choice`)f=34,h=34;else if(a.kind===`fork`||a.kind===`join`)f=m?10:70,h=m?70:10;else if(a.kind===`er`){let e=u,r=(0,t.maxWidthOf)(e,i.erHead,n),o=Math.max(36,...a.fields.map(e=>(0,t.maxWidthOf)((0,t.wrapText)(e.type,80,i.erAttr,n),i.erAttr,n))),s=Math.max(24,...a.fields.map(e=>(0,t.maxWidthOf)([e.keys.join(` `)],i.erKey,n))),c=Math.max(60,216-o-24-s),l=a.fields.map(e=>{let r=(0,t.wrapText)(e.type,80,i.erAttr,n),a=(0,t.wrapText)(e.name,c,i.erAttr,n),o=e.keys.join(` `),s=Math.max(r.length,a.length)*17+8;return{...e,typeLines:r,nameLines:a,keyText:o,rowH:s}}),d=Math.max(60,...l.map(e=>(0,t.maxWidthOf)(e.nameLines,i.erAttr,n)));f=Math.max(132,24+Math.max(r,o+12+d+12+s));let p=e.length*19+14;h=p+l.reduce((e,t)=>e+t.rowH,0)+6,g={headLines:e,typeW:o,nameW:d,keyW:s,headerH:p,rows:l,pad:12}}else{let e=(0,t.maxWidthOf)(u,i.title,n),s=(0,t.maxWidthOf)(d,i.body,n);if(f=Math.max(64,Math.max(e,s)+28),h=20+u.length*19+(d.length?5+d.length*17:0),h=Math.max(40,h)+(a.kind===`collapsed`?20:0)+(a.icon?(a.iconHeight??16)+8:0),a.icon&&a.iconHeight&&(f=Math.max(f,a.iconHeight+28)),o)[f,h]=(0,r.shapeSize)(o,f,h,p,u.length>0),c&&u.length&&(h=Math.max(h,u.length*19+12));else if(a.shape===`diamond`)f*=1.7,h*=1.7;else if(a.shape===`circle`){let e=Math.max(48,Math.max(f,h)*1.3);f=e,h=e}else a.shape===`hexagon`?f+=34:a.shape===`cylinder`&&(h+=12)}a.block&&({w:f,h}=a.block);let _=y.get(a.id)||[],v=0,b=[];if(_.length){let e=_.map(e=>e.label?(0,t.maxWidthOf)((0,t.wrapText)(e.label,120,i.label,n),i.label,n):0);v=26+Math.max(0,...e)+Math.max(0,_.length-1)*12,b=_.map((r,a)=>({edge:r,width:e[a],lines:r.label?(0,t.wrapText)(r.label,120,i.label,n):[],index:a}))}let x=m?h:f,S=m?f:h;return{kind:`real`,node:a,id:a.id,seq:a.orderSeq??a.seq,tw:f,th:h,bw:x+v,bh:S,offsetCross:v?-v/2:0,titleLines:u,descLines:d,er:g,loopExtra:v,loopLabels:b,selfLoops:_,parent:a.parent||null,cluster:null,up:[],down:[],rank:0}};for(let t of e.nodes){let e=x(t);_.push(e),v.set(t.id,e)}let S=new Map(e.nodes.map(e=>[e.id,e]));if(!_.length)return{type:e.type,direction:p,width:32,height:32,nodes:[],labels:[],frames:[],edges:[],ranks:[],warnings:[`图里没有节点`],model:e};let C=(e,r)=>{e.titleLines=(0,t.wrapText)(e.title,r,i.frame,n),!e.titleLines.length&&e.model.icon&&(e.titleLines=[``]),e.titleW=(0,t.maxWidthOf)(e.titleLines,i.frame,n)+(e.model.icon?22:0),e.titleBand=10+e.titleLines.length*17+(e.descLines.length?4+e.descLines.length*16:0)+8};for(let r of e.subgraphs){let e={id:r.id,model:r,parent:null,children:[],seq:r.seq,depth:r.depth,title:r.title??r.id,titleLines:[],descLines:[],class:r.class||null};for(let a of r.desc||[])e.descLines.push(...(0,t.wrapText)(a,180,i.body,n));e.descW=(0,t.maxWidthOf)(e.descLines,i.body,n),C(e,200),h.set(e.id,e)}for(let e of h.values())e.parent=(e.model.parent?h.get(e.model.parent):g)||g,e.parent.children.push(e);let w=e=>{e.children.sort((e,t)=>e.seq-t.seq);for(let t of e.children)w(t)};w(g);for(let e of _)e.cluster=e.parent&&h.get(e.parent)||g;let T=(e,t)=>{for(let n=e;n;n=n.parent)if(n===t)return!0;return!1},E=e=>_.filter(t=>T(t.cluster,e)),D=e=>h.has(e)&&!S.has(e),O=e=>{let t=[];for(let n=e;n;n=n.parent)t.push(n);return t},k=t=>{let n=E(t);if(!n.length)return null;let r=n.find(e=>e.node.kind===`start`&&e.parent===t.id);if(r)return r;let i=new Set(n.map(e=>e.id)),a=t=>e.edges.some(e=>e.to===t&&i.has(e.from)&&!e.toFrame&&!e.fromFrame);return n.find(e=>!a(e.id))||n[0]},A=t=>{let n=E(t);if(!n.length)return null;let r=n.find(e=>e.node.kind===`end`&&e.parent===t.id);if(r)return r;let i=new Set(n.map(e=>e.id)),a=t=>e.edges.some(e=>e.from===t&&i.has(e.to)&&!e.toFrame&&!e.fromFrame),o=[...n].reverse();return o.find(e=>!a(e.id))||o[0]},j=[];for(let t of e.edges){let e=D(t.from),n=D(t.to);if(t.fromFrame=e,t.toFrame=n,t.from===t.to&&e&&n){t.skip=!0,b.push(`自环子图 ${t.from} 暂不绘制`);continue}if(t.from===t.to&&!e&&!n)continue;let r=e?A(h.get(t.from)):v.get(t.from),i=n?k(h.get(t.to)):v.get(t.to);if(!r||!i){t.skip=!0,e&&!E(h.get(t.from)).length&&b.push(`空子图 ${t.from} 的连线已跳过`),n&&!E(h.get(t.to)).length&&b.push(`空子图 ${t.to} 的连线已跳过`);continue}if(r===i){t.skip=!0;continue}let a=O(e?h.get(t.from).parent:v.get(t.from).cluster),o=O(n?h.get(t.to).parent:v.get(t.to).cluster),s=new Set(o),c=a.find(e=>s.has(e))||g;j.push({edge:t,fromItem:r,toItem:i,fromFrame:e,toFrame:n,owner:c,minlen:1+(t.extra||0),reversed:!1,chain:null,start:null,end:null,segments:[]})}let M=[..._];for(let e of h.values())_.some(t=>T(t.cluster,e))||b.push(`空子图 ${e.id} 未绘制`);let N=new Map(_.map(e=>[e,[]])),P=new Map(_.map(e=>[e,[]]));for(let e of j)N.get(e.fromItem).push(e),P.get(e.toItem).push(e);let F=new Map,I=e=>{F.set(e,1);for(let t of N.get(e)){let e=t.toItem,n=F.get(e)||0;n===1?t.reversed=!0:n===0&&I(e)}F.set(e,2)};for(let e of _)F.get(e)||I(e);for(let e of j)if(e.reversed){let t=e.fromItem;e.fromItem=e.toItem,e.toItem=t}for(let e of _)N.set(e,[]),P.set(e,[]);for(let e of j)N.get(e.fromItem).push(e),P.get(e.toItem).push(e);let L=new Map(_.map(e=>[e,0]));for(let e of j)L.set(e.toItem,L.get(e.toItem)+1);let R=_.filter(e=>L.get(e)===0),z=[];for(;R.length;){let e=R.shift();z.push(e);for(let t of N.get(e))L.set(t.toItem,L.get(t.toItem)-1),L.get(t.toItem)===0&&R.push(t.toItem)}if(z.length<_.length)for(let e of _)z.includes(e)||z.push(e);let B=new Map(_.map(e=>[e,0]));for(let e of z)for(let t of N.get(e))B.set(t.toItem,Math.max(B.get(t.toItem),B.get(e)+t.minlen));let ee=e=>e.edge.label?2:1,te=e=>{if(!e.length)return 0;let t=[...e].sort((e,t)=>e.value-t.value||e.weight-t.weight),n=t.reduce((e,t)=>e+t.weight,0),r=0,i=t[0].value;for(let e of t)if(r+=e.weight,r>=n/2-1e-9){i=e.value;break}r=0;let a=t[t.length-1].value;for(let e of t)if(r+=e.weight,r>n/2+1e-9){a=e.value;break}return(i+a)/2};for(let e=0;e<4;e+=1){let t=e%2?[...z].reverse():z;for(let e of t){let t=P.get(e).map(e=>B.get(e.fromItem)+e.minlen),n=N.get(e).map(e=>B.get(e.toItem)-e.minlen),r=t.length?Math.max(...t):0,i=n.length?Math.min(...n):1/0;if(i<r)continue;let a=[...P.get(e).map(e=>({value:B.get(e.fromItem)+e.minlen,weight:ee(e)})),...N.get(e).map(e=>({value:B.get(e.toItem)-e.minlen,weight:ee(e)}))],o=Math.round(te(a)),s=Math.max(r,Math.min(i,Number.isFinite(o)?o:r));B.set(e,s)}}let ne=Math.min(..._.map(e=>B.get(e)));Number.isFinite(ne)||(ne=0);for(let e of _)e.rank=(B.get(e)-ne)*2;let V=new Map;for(let e of h.values()){let t=_.filter(t=>T(t.cluster,e));t.length&&V.set(e.id,{top:Math.min(...t.map(e=>e.rank)),bottom:Math.max(...t.map(e=>e.rank))})}let re=1e5,ie=[];for(let e of j){let r=e.fromItem,a=e.toItem,o=a.rank-r.rank;if(o<=0){e.edge.skip=!0;continue}let s=[r],c=e.edge.label||e.edge.icon?r.rank+Math.max(1,Math.floor(o/2)):-1;if(e.edge.label&&(e.fromFrame||e.toFrame)){let t=[],n=e.reversed?e.toFrame:e.fromFrame,i=e.reversed?e.fromFrame:e.toFrame,o=e.reversed?e.edge.to:e.edge.from,s=e.reversed?e.edge.from:e.edge.to;if(n){let e=V.get(o);e&&a.rank<e.top?t.push(a.rank+Math.max(1,Math.floor((e.top-a.rank)/2))):e&&a.rank>e.bottom&&t.push(e.bottom+Math.max(1,Math.floor((a.rank-e.bottom)/2)))}if(i){let e=V.get(s);e&&r.rank<e.top?t.push(r.rank+Math.max(1,Math.floor((e.top-r.rank)/2))):e&&r.rank>e.bottom&&t.push(e.bottom+Math.max(1,Math.floor((r.rank-e.bottom)/2)))}let l=t.filter(e=>e>r.rank&&e<a.rank);l.length&&(c=l[0])}for(let o=r.rank+1;o<a.rank;o+=1){let r=o===c,a=4,l=4,u=[];r&&(u=(0,t.wrapText)(e.edge.label,160,i.label,n),!u.length&&e.edge.icon&&(u=[``]),a=Math.max(26,(0,t.maxWidthOf)(u,i.label,n)+10+(e.edge.icon?22:0)),l=Math.max(18,u.length*16+6));let d={kind:r?`label`:`dummy`,id:`@@${e.edge.seq}:${o}`,seq:re++,rank:o,edge:e.edge,owner:e.owner,cluster:e.owner,tw:a,th:l,bw:m?l:a,bh:m?a:l,labelLines:u,offsetCross:0,up:[],down:[]};ie.push(d),s.push(d),M.push(d)}s.push(a),e.chain=s;for(let e=0;e<s.length-1;e+=1)s[e].down.push(s[e+1]),s[e+1].up.push(s[e])}let H=new Map;for(let e of M)H.has(e.rank)||H.set(e.rank,[]),H.get(e.rank).push(e);for(let[e,t]of H)t.sort((e,t)=>e.seq-t.seq),H.set(e,t);let U=Math.max(...H.keys()),ae=(e,t)=>(H.get(t)||[]).filter(t=>T(t.cluster,e)),oe=(e,t)=>{let n=V.get(e.id);return!!n&&t>=n.top&&t<=n.bottom},se=(e,t,n)=>{let r=(H.get(t)||[]).filter(t=>t.cluster===e),i=e.children.filter(e=>oe(e,t)),a=new Map;for(let e of i){let r=ae(e,t);if(r.length){a.set(e,r.reduce((e,t)=>e+(n.get(t)??0),0)/r.length);continue}let i=V.get(e.id),o=0;for(let r=1;i&&r<=i.bottom-i.top;r+=1){let a=[t-r,t+r].filter(e=>e>=i.top&&e<=i.bottom).map(t=>(H.get(t)||[]).filter(t=>T(t.cluster,e))).find(e=>e.length>0);if(!a)continue;let s=a.map(e=>n.get(e)).filter(e=>e!=null);if(s.length)o=s.reduce((e,t)=>e+t,0)/s.length;else{let e=H.get(a[0].rank)||[];o=a.reduce((t,n)=>t+e.indexOf(n),0)/a.length}break}a.set(e,o)}r.sort((e,t)=>(n.get(e)??0)-(n.get(t)??0)||e.seq-t.seq);let o=Array.from({length:i.length+1},()=>[]);for(let e of r){let t=0;for(let r of i)(n.get(e)??0)>(a.get(r)??0)&&(t+=1);e.gapIndex=t,o[t].push(e)}let s=[];for(let e=0;e<=i.length;e+=1)s.push(...o[e]),e<i.length&&s.push(...se(i[e],t,n));return s},ce=(e,t)=>{let n=H.get(e)||[];if(!n.length)return;let r=new Map(n.map((e,t)=>[e,t])),i=H.get(t===`up`?e-1:e+1)||[],a=new Map(i.map((e,t)=>[e,t])),o=new Map;for(let e of n){let n=(t===`up`?e.up:e.down).map(e=>a.get(e)).filter(e=>e!=null);o.set(e,n.length?n.reduce((e,t)=>e+t,0)/n.length:r.get(e)??0)}let s=se(g,e,o);s.length===n.length&&H.set(e,s)};for(let e=0;e<4;e+=1){for(let e=1;e<=U;e+=1)ce(e,`up`);for(let e=U-1;e>=0;--e)ce(e,`down`)}let le=e=>{let t=H.get(e)||[],n=H.get(e+1)||[],r=new Map(t.map((e,t)=>[e,t])),i=new Map(n.map((e,t)=>[e,t])),a=[];for(let n of t)for(let t of n.down)t.rank===e+1&&a.push([r.get(n),i.get(t)]);return a},W=e=>{if(e<0||e>=U)return 0;let t=le(e),n=0;for(let e=0;e<t.length;e+=1)for(let r=e+1;r<t.length;r+=1)(t[e][0]-t[r][0])*(t[e][1]-t[r][1])<0&&(n+=1);return n};for(let e=0;e<2;e+=1)for(let e=0;e<=U;e+=1){let t=H.get(e);if(t)for(let n=0;n<t.length-1;n+=1){let r=t[n],i=t[n+1];if(r.cluster!==i.cluster||(r.gapIndex||0)!==(i.gapIndex||0))continue;let a=W(e-1)+W(e);t[n]=i,t[n+1]=r,W(e-1)+W(e)<a||(t[n]=r,t[n+1]=i)}}for(let e=0;e<2;e+=1)for(let e=0;e<=U;e+=1){let t=H.get(e);if(t)for(let n=0;n<t.length-1;n+=1){let r=t[n],i=t[n+1];if(r.kind!==`node`||i.kind!==`node`||r.cluster!==i.cluster||(r.gapIndex||0)!==(i.gapIndex||0)||r.seq<i.seq)continue;let a=W(e-1)+W(e);t[n]=i,t[n+1]=r,W(e-1)+W(e)<=a||(t[n]=r,t[n+1]=i)}}let ue=(e,t)=>{let n=[];e.children.forEach((e,r)=>{oe(e,t)&&n.push(r)});let r=[];for(let t=0;t<=n.length;t+=1)r.push({gStart:t===0?0:n[t-1]+1,gEnd:t===n.length?e.children.length:n[t],leftChild:t===0?null:n[t-1],rightChild:t===n.length?null:n[t]});return r},de=e=>e.reduce((t,n,r)=>t+n.bw+(r?l(e[r-1],n):0),0),fe=e=>{for(let t of e.children)fe(t);let t=e.children,n=Array.from({length:t.length+1},()=>0),r=[],i=[];for(let[t,n]of H){let a=ue(e,t),o=new Map;for(let t of n){if(t.cluster!==e)continue;let n=t.gapIndex||0;o.has(n)||o.set(n,[]),o.get(n).push(t)}for(let[e,t]of o){let n={...a[e]||a[a.length-1],natural:de(t)};n.gStart===n.gEnd?r.push(n):i.push(n)}}for(let e of r)n[e.gStart]=Math.max(n[e.gStart],e.natural);let a=e=>{let r=0,i=0;for(let t=e.gStart;t<=e.gEnd;t+=1)n[t]<=0||(r+=n[t],i+=1);for(let n=e.gStart;n<e.gEnd;n+=1)r+=t[n].width,i+=1;return r+20*Math.max(0,i-1)},o=i.map(e=>({...e,span:a(e)})).sort((e,t)=>e.span-t.span||e.gStart-t.gStart||e.gEnd-t.gEnd||e.natural-t.natural);for(let e of o)for(let t=0;t<8;t+=1){let t=a(e);if(e.natural<=t+1e-9)break;let r=e.gEnd-e.gStart+1,i=(e.natural-t)/r;for(let t=e.gStart;t<=e.gEnd;t+=1)n[t]+=i}let s=[];for(let e=0;e<=t.length;e+=1)n[e]>0&&s.push({kind:`gap`,gap:e,width:n[e]}),e<t.length&&s.push({kind:`child`,child:t[e],width:t[e].width});let c=s.reduce((e,t,n)=>e+t.width+(n?20:0),0);e!==g&&c>200&&C(e,c);let l;if(e===g)l=c;else{let t=m?e.titleBand:0,n=m||c>200?0:e.titleW+28;l=Math.max(c+28+t,n)}e.contentWidth=c,e.gapWidths=n,e.slots=s,e.width=l};fe(g);let pe=(e,t)=>{e.left=t;let n=e===g?0:a,r=m&&e!==g?e.titleBand:0,i=t+n+r,o=e.width-n*2-r;e.innerLeft=i;let s=i+Math.max(0,(o-e.contentWidth)/2),c=s,u=c+e.contentWidth;e.slots.forEach((t,n)=>{t.left=s,t.kind===`child`&&pe(t.child,s),s+=t.width+(n<e.slots.length-1?20:0)});for(let[t,n]of H){let r=ue(e,t),i=new Map;for(let t of n){if(t.cluster!==e)continue;let n=t.gapIndex||0;i.has(n)||i.set(n,[]),i.get(n).push(t)}for(let[t,n]of i){let i=r[t]||r[r.length-1],a=i.leftChild==null?null:e.children[i.leftChild],o=i.rightChild==null?null:e.children[i.rightChild],s=a?a.left+a.width+20:c,d=Math.max(s,o?o.left-20:u),f=de(n),p=s+Math.max(0,(d-s-f)/2);n.forEach((e,t)=>{e.slotLeft=s,e.slotRight=d,e.centerX=p+e.bw/2,t<n.length-1&&(p+=e.bw+l(e,n[t+1]))})}}};pe(g,0);let G=e=>e.centerX+(e.offsetCross||0),K=[];for(let[e,t]of H){let n=new Map;for(let e of t){let t=`${e.cluster.id??`@root`}#${e.gapIndex||0}`;n.has(t)||n.set(t,[]),n.get(t).push(e)}for(let t of n.values())K.push({rank:e,items:t})}for(let e=0;e<8;e+=1){let t=e%2==0,n=t?[...H.keys()].sort((e,t)=>e-t):[...H.keys()].sort((e,t)=>t-e);for(let e of n)for(let n of K){if(n.rank!==e)continue;let r=n.items,i=r.map(e=>{let n=(t?e.up:e.down).map(G);return n.length?n.reduce((e,t)=>e+t,0)/n.length-(e.offsetCross||0):e.centerX}),a=r[0].slotLeft;for(let e=0;e<r.length;e+=1){let t=r[e],n=(e===0?t.slotLeft:a)+t.bw/2,o=t.slotRight-t.bw/2,s=Number.isFinite(i[e])?i[e]:n;s=Math.max(n,Math.min(o,s)),t.centerX=s,a=s+t.bw/2+(e<r.length-1?l(t,r[e+1]):0)}let o=r[r.length-1].slotRight;for(let e=r.length-1;e>=0;--e){let t=r[e],n=(e===r.length-1?t.slotRight:o)-t.bw/2,i=t.slotLeft+t.bw/2;t.centerX=Math.max(i,Math.min(n,t.centerX)),o=t.centerX-t.bw/2-(e>0?l(r[e-1],t):0)}}}let me=(e,t)=>{let n=e.kind!==`real`,r=t.kind!==`real`;return n&&r?8:n||r?2:1},he=new Map;for(let e of K)e.items.forEach((t,n)=>he.set(t,{group:e,index:n}));let ge=e=>{let t=he.get(e),n=t.group.items,r=e.slotLeft+e.bw/2,i=e.slotRight-e.bw/2;if(t.index>0){let i=n[t.index-1];r=Math.max(r,i.centerX+i.bw/2+l(i,e)+e.bw/2)}if(t.index<n.length-1){let r=n[t.index+1];i=Math.min(i,r.centerX-r.bw/2-l(e,r)-e.bw/2)}return r<=i?{min:r,max:i}:{min:e.centerX,max:e.centerX}},_e=e=>{let t=[...e].sort((e,t)=>e.value-t.value||t.weight-e.weight),n=t.reduce((e,t)=>e+t.weight,0),r=0;for(let e of t)if(r+=e.weight,r>=n/2-1e-9)return e.value;return t[t.length-1].value},ve=(e,t)=>Math.max(t.min,Math.min(t.max,e)),ye=(e,t)=>{let n=t+(e.offsetCross||0),r=0;for(let t of e.up)r+=me(e,t)*Math.abs(n-G(t));for(let t of e.down)r+=me(e,t)*Math.abs(n-G(t));return r},be=(e,t)=>{let n=0;for(let r=0;r<e.length-1;r+=1){let i=e[r],a=e[r+1],o=t&&t.has(i)?t.get(i):G(i),s=t&&t.has(a)?t.get(a):G(a);n+=me(i,a)*Math.abs(o-s)}return n},xe=e=>{let t=[...e.up,...e.down];if(!t.length)return!1;let n=_e(t.map(t=>({value:G(t),weight:me(e,t)}))),r=ve(n-(e.offsetCross||0),ge(e));if(Math.abs(r-e.centerX)<.01)return!1;let i=ye(e,e.centerX);return ye(e,r)>i-.01?!1:(e.centerX=r,!0)},Se=e=>{let t=-1/0,n=1/0;for(let r of e){let e=ge(r);if(t=Math.max(t,e.min),n=Math.min(n,e.max),t>n+1e-9)return null}return{min:t,max:n}},Ce=e=>{let t=e.chain;if(!t||t.length<3)return!1;let n=t.slice(1,-1);if(!n.every(e=>he.has(e)))return!1;let r=be(t,null),i=Se(n);if(i){let e=G(t[0]),a=G(t[t.length-1]),o=n.reduce((e,t)=>e+G(t),0)/n.length,s={min:Math.max(i.min,Math.min(e,a)),max:Math.min(i.max,Math.max(e,a))},c;c=s.min<=s.max?ve(o,s):i.max<Math.min(e,a)?i.max:i.min;let l=new Map(n.map(e=>[e,c]));if(be(t,l)>r-.01)return!1;for(let e of n)e.centerX=c;return!0}let a=0;for(;a<n.length&&Se(n.slice(0,a+1));)a+=1;let o=0;for(;o<n.length&&Se(n.slice(n.length-o-1));)o+=1;a+o>n.length&&(a>=o?o=n.length-a:a=n.length-o);let s=!1,c=(e,r)=>{if(e.length<2)return!1;let i=Se(e);if(!i)return!1;let a=n.indexOf(e[0]),o=a>0?n[a-1]:n[a+e.length],s=[{value:G(r),weight:2}];o&&s.push({value:G(o),weight:8});let c=ve(_e(s),i),l=new Map(e.map(e=>[e,c]));if(be(t,l)>be(t,null)-.01)return!1;for(let t of e)t.centerX=c;return!0};return a>=2&&(s=c(n.slice(0,a),t[0])||s),o>=2&&(s=c(n.slice(n.length-o),t[t.length-1])||s),s};for(let e=0;e<40;e+=1){let e=!1;for(let[,t]of[...H.entries()].sort((e,t)=>e[0]-t[0]))for(let n of t)xe(n)&&(e=!0);for(let t of j)Ce(t)&&(e=!0);if(!e)break}let we=new Map;for(let e of j)if(e.chain)for(let t of e.chain)we.set(t,e);let Te=new Map;for(let e of _)Te.has(e.rank)||Te.set(e.rank,[]),Te.get(e.rank).push(e);let Ee=e=>{if(!e.length)return;let t=e[0].slotLeft;for(let n=0;n<e.length;n+=1){let r=e[n],i=(n===0?r.slotLeft:t)+r.bw/2,a=r.slotRight-r.bw/2;r.centerX=Math.max(i,Math.min(a,r.centerX)),t=r.centerX+r.bw/2+(n<e.length-1?l(r,e[n+1]):0)}let n=e[e.length-1].slotRight;for(let t=e.length-1;t>=0;--t){let r=e[t],i=(t===e.length-1?r.slotRight:n)-r.bw/2,a=r.slotLeft+r.bw/2;r.centerX=Math.max(a,Math.min(i,r.centerX)),n=r.centerX-r.bw/2-(t>0?l(e[t-1],r):0)}};for(let e=0;e<4;e+=1){for(let e of ie)if(e.kind===`dummy`)for(let t of[e.rank-1,e.rank+1]){let n=(t<e.rank?e.up:e.down).filter(e=>e.rank===t);if(n.length)for(let r of Te.get(t)||[]){if(n.includes(r))continue;let t=r.centerX+(r.offsetCross||0),i=(m?r.th:r.tw)/2+14;if(Math.abs(e.centerX-t)>=i)continue;let a=n.map(e=>e.centerX+(e.offsetCross||0)).reduce((e,t)=>e+t,0)/n.length<t?t-i:t+i,o=we.get(e),s=o&&o.chain?o.chain.slice(1,-1):[e],c=Se(s);if(!c)continue;let l=ve(a,c);if(!(Math.abs(l-e.centerX)<.01))for(let e of s)e.centerX=l}}for(let e of K)Ee(e.items)}if(e.type===`er`)for(let e=0;e<40;e+=1){let e=!1;for(let[,t]of[...H.entries()].sort((e,t)=>e[0]-t[0]))for(let n of t)xe(n)&&(e=!0);for(let t of j)Ce(t)&&(e=!0);if(!e)break}else{let e=new Map;for(let t of H.values())for(let n of t)e.set(n,n.centerX);{let e=(e,t)=>`${e.seq}>${t.seq}`,t=new Map;for(let n of j)if(n.chain)for(let r=0;r+1<n.chain.length;r+=1)t.set(e(n.chain[r],n.chain[r+1]),n);let n=e=>!!(e&&e.reversed),r=e=>{let t=e&&e.edge?e.edge.style:null;return t===`dotted`?2:+(t===`dashed`)},i=[...H.keys()].sort((e,t)=>e-t),a=e=>e.up.filter(t=>t.rank===e.rank-1),o=e=>e.down.filter(t=>t.rank===e.rank+1),s=new Map;for(let e of i)for(let t of H.get(e)||[]){let e=a(t);s.set(t,e.length?Math.max(...e.map(e=>s.get(e)+1)):0)}let c=new Map;for(let e of[...i].reverse())for(let t of H.get(e)||[]){let e=o(t);c.set(t,e.length?Math.max(...e.map(e=>c.get(e)+1)):0)}let u=Math.max(0,...c.values()),d=(e,t)=>s.get(e)+1+c.get(t)>=u?0:1,f=new Map,p=new Map;for(let o of i)if(o!==0)for(let i of H.get(o)||[]){let s=a(i);if(!s.length){f.set(i,null);continue}let c=s.filter(r=>!n(t.get(e(r,i)))).map(n=>{let a=t.get(e(n,i));return{up:n,style:r(a),crit:d(n,i),x:G(n),seq:n.seq}});if(!c.length){f.set(i,null);continue}let l=Math.min(...c.map(e=>e.style)),u=c.filter(e=>e.style===l),m=Math.min(...u.map(e=>e.crit)),h=u.filter(e=>e.crit===m);if(h.length>=4&&h.length%2==0){let e=H.get(o-1)||[];p.set(i,h.map(e=>e.up).sort((t,n)=>e.indexOf(t)-e.indexOf(n))),f.set(i,null);continue}let g=h.map(e=>e.x).sort((e,t)=>e-t),_=g.length%2?g[(g.length-1)/2]:(g[g.length/2-1]+g[g.length/2])/2;h.sort((e,t)=>Math.abs(e.x-_)-Math.abs(t.x-_)||e.seq-t.seq),f.set(i,h[0].up)}let h=new Map;for(let e of i)(H.get(e)||[]).forEach((e,t)=>h.set(e,t));let v=[],y=new Set,b=new Map,x=new Map;for(let a of i){if(a===0)continue;let i=(H.get(a)||[]).map(i=>{let a=f.get(i),o=a?t.get(e(a,i)):null;return{item:i,up:a&&!n(o)?a:null,style:r(o),crit:a?d(a,i):1}}),o=new Map;for(let e of i)e.up&&(o.has(e.up)||o.set(e.up,[]),o.get(e.up).push(e));for(let[e,t]of o){let n=Math.min(...t.map(e=>e.crit)),r=Math.min(...t.filter(e=>e.crit===n).map(e=>e.style)),i=t.filter(e=>e.crit===n&&e.style===r).sort((e,t)=>h.get(e.item)-h.get(t.item));if(i.length>=4&&i.length%2==0){x.set(e,i.map(e=>e.item));continue}let a=(i.length-1)/2;i.forEach((e,t)=>b.set(e.item,Math.abs(t-a)))}i.sort((e,t)=>e.crit-t.crit||e.style-t.style||G(e.up||e.item)-G(t.up||t.item)||(b.get(e.item)??0)-(b.get(t.item)??0)||e.item.seq-t.item.seq);for(let e of i){let{item:t,up:n}=e;if(!n||y.has(n)||x.has(n))continue;let r=h.get(n),i=h.get(t),a=!1;for(let[e,n]of v)if(n.rank===t.rank&&(h.get(e)-r)*(h.get(n)-i)<0){a=!0;break}a||(v.push([n,t]),y.add(n))}}let S=new Map(v.map(([e,t])=>[t,e])),C=new Map;for(let e of i)for(let t of H.get(e)||[]){let e=S.get(t);if(e&&C.has(e)){let n=C.get(e);n.items.push(t),C.set(t,n)}else C.set(t,{id:C.size,items:[t]})}let w=e=>({x:e.centerX+(e.offsetCross||0)-(m?e.th:e.tw)/2,w:m?e.th:e.tw}),T=e=>{let t=e.items.map(G).sort((e,t)=>e-t),n=t.length%2?t[(t.length-1)/2]:(t[t.length/2-1]+t[t.length/2])/2,r=e.items.map(e=>e.rank),i=Math.min(...r),a=Math.max(...r);for(let t of _){if(t.rank<=i||t.rank>=a||e.items.includes(t))continue;let r=w(t);if(n>r.x-8&&n<r.x+r.w+8)return!0}return!1};for(let e of[...new Set(C.values())])if(!(e.items.length<2||!T(e)))for(let t of e.items)C.set(t,{id:C.size,items:[t]});for(let e of j){if(!e.chain||e.chain.length<3)continue;let t=[],n=()=>{if(t.length>1){let e=C.get(t[0]);for(let n of t.slice(1)){let t=C.get(n);if(t&&t!==e){for(let n of t.items)C.set(n,e),e.items.push(n);t.items=[]}}}t=[]};for(let r of e.chain.slice(1,-1))r.kind===`dummy`?(t.length&&r.rank!==t[t.length-1].rank+1&&n(),t.push(r)):n();n()}let E=[...new Set(C.values())],D=new Map(E.map((e,t)=>[e,t])),O=new Map;for(let e of K){let t=[];for(let n of e.items){let e=C.get(n);e&&(t.length&&t[t.length-1].block===e||t.push({block:e,item:n}))}for(let e=1;e<t.length;e+=1){let n=t[e-1],r=t[e],i=n.item.bw/2+l(n.item,r.item)+r.item.bw/2,a=`${D.get(n.block)}>${D.get(r.block)}`,o=O.get(a);o?o.sep=Math.max(o.sep,i):O.set(a,{a:n.block,b:r.block,sep:i})}}let k=[...O.values()],A=e=>{let t=-1/0,n=1/0,r=[];for(let i of e.items)i.cluster&&i.cluster!==g&&(t=Math.max(t,i.slotLeft+i.bw/2-(i.offsetCross||0)),n=Math.min(n,i.slotRight-i.bw/2-(i.offsetCross||0))),r.push(G(i));if(t>n+.01)return null;r.sort((e,t)=>e-t);let i=r.length%2?r[(r.length-1)/2]:(r[r.length/2-1]+r[r.length/2])/2;return{min:t,max:n,mid:i}},M=new Map;for(let e of E){let t=A(e);if(t)M.set(e,t);else for(let t of e.items)C.delete(t)}let N=new Map;for(let[e,t]of M)N.set(e,Math.max(t.min,Math.min(t.max,t.mid)));let P=k.filter(e=>M.has(e.a)&&M.has(e.b)&&e.a!==e.b),F=(e,t)=>{let n=M.get(e);n&&N.set(e,Math.max(n.min,Math.min(n.max,t)))},I=new Map(E.map(e=>[e,[]])),L=new Map(E.map(e=>[e,0]));for(let e of P)I.get(e.a).push(e),L.set(e.b,L.get(e.b)+1);let R=E.filter(e=>M.has(e)&&L.get(e)===0);R.sort((e,t)=>N.get(e)-N.get(t));let z=[];for(;R.length;){let e=R.shift();z.push(e);for(let t of I.get(e))L.set(t.b,L.get(t.b)-1),L.get(t.b)===0&&R.push(t.b)}if(z.length<E.length){let e=E.filter(e=>!z.includes(e));e.sort((e,t)=>N.get(e)-N.get(t)),z.push(...e)}for(let e of z){let t=N.get(e);for(let n of P)n.b===e&&(t=Math.max(t,N.get(n.a)+n.sep));F(e,t)}for(let e=z.length-1;e>=0;--e){let t=z[e],n=M.get(t);if(!n)continue;let r=Math.max(n.min,Math.min(n.max,N.get(t)));if(r!==N.get(t)){N.set(t,r);for(let e of P)e.b===t&&(N.set(e.a,Math.min(N.get(e.a),r-e.sep)),F(e.a,N.get(e.a)))}}for(let[e,t]of M){let n=Math.max(t.min,Math.min(t.max,N.get(e)));for(let t of e.items)t.centerX=n-(t.offsetCross||0)}for(let e of i)for(let t of H.get(e)||[]){let e=x.get(t)||p.get(t),n=e&&C.get(t);if(!n||!M.has(n))continue;let r=e.length/2,i=(G(e[r-1])+G(e[r]))/2,a=M.get(n),o=a.min,s=a.max;for(let e of n.items){let{group:t,index:r}=he.get(e)||{};if(!t)continue;let i=t.items.slice(0,r).reverse().find(e=>!n.items.includes(e)),a=t.items.slice(r+1).find(e=>!n.items.includes(e)),c=e.offsetCross||0;i&&(o=Math.max(o,i.centerX+i.bw/2+l(i,e)+e.bw/2+c)),a&&(s=Math.min(s,a.centerX-a.bw/2-l(e,a)-e.bw/2+c))}if(o>s+.01)continue;let c=Math.max(o,Math.min(s,i));for(let e of n.items)e.centerX=c-(e.offsetCross||0)}}if([...H.values()].some(e=>{let t=e.filter(e=>e.kind===`real`).map(e=>({x:e.centerX+(e.offsetCross||0),w:m?e.th:e.tw})).sort((e,t)=>e.x-t.x);return t.some((e,n)=>n>0&&e.x-t[n-1].x<(e.w+t[n-1].w)/2+2)}))for(let[t,n]of e)t.centerX=n}let De=e.type===`er`?null:(()=>{let o=(e,t,n)=>Math.max(t,Math.min(n,e)),s=.5522847498,c=e=>e===`top`||e===`bottom`,l=e=>{if(e.kind===`real`){let t=m?e.th:e.tw,n=m?e.tw:e.th;return{x:e.centerX+(e.offsetCross||0)-t/2,y:e.cy-n/2,w:t,h:n}}return{x:e.centerX-e.bw/2,y:e.cy-e.bh/2,w:e.bw,h:e.bh}},u=t=>{let n=t.node||{};if(n.kind===`choice`)return`diamond`;if(n.kind===`note`)return`flow:note`;if(n.kind===`start`||n.kind===`end`)return`circle`;let i=e.type===`flowchart`&&(0,r.flowOutlineName)(n.shape);return i?`flow:${i}`:n.shape||`rect`},d=e=>!!e&&[`diamond`,`flow:diam`,`flow:choice`].includes(u(e)),f=new Map,v=(e,t,n)=>{let i=`${e}:${t}:${n}`;if(!f.has(i)){let a=(0,r.shapeOutline)(e,m?n:t,m?t:n,p);f.set(i,a.map(([e,t])=>p===`BT`?[e,n-t]:p===`LR`?[t,e]:p===`RL`?[t,n-e]:[e,t]))}return f.get(i)},y=(e,t,n,i)=>{if(t.startsWith(`flow:`)){let a=c(n)?i-e.x:i+e.h/2,o=(0,r.outlinePort)(v(t.slice(5),e.w,e.h),n,a);return{x:e.x+o.x,y:e.y+o.y}}let a=e.x+e.w/2,s=e.y+e.h/2,l=e.w/2,u=e.h/2;if(c(n)){let r=o(i,a-l*.96,a+l*.96),c=n===`top`?e.y:e.y+e.h;if(t===`diamond`){let e=Math.min(l*.96,Math.abs(r-a));c=s+(n===`top`?-1:1)*u*(1-e/l)}else if(t===`circle`){let e=Math.min(l*.96,Math.abs(r-a));c=s+(n===`top`?-1:1)*u*Math.sqrt(Math.max(0,1-(e/l)**2))}else if(t===`hexagon`){let e=l-Math.min(16,l*.35),t=Math.abs(r-a);if(t>e){let r=Math.min(1,(t-e)/Math.max(1,l-e));c=s+(n===`top`?-1:1)*u*r}}return{x:r,y:c}}let d=o(i,-u*.96,u*.96),f=n===`left`?e.x:e.x+e.w;if(t===`diamond`){let e=Math.min(u*.82,Math.abs(d));f=a+(n===`left`?-1:1)*l*(1-e/u)}else if(t===`circle`){let e=Math.min(u*.84,Math.abs(d));f=a+(n===`left`?-1:1)*l*Math.sqrt(Math.max(0,1-(e/u)**2))}else if(t===`hexagon`){let t=Math.min(16,u*.35),r=Math.abs(d)/Math.max(1,u);f=n===`left`?e.x+t*r:e.x+e.w-t*r}return{x:f,y:s+d}},b=(e,t,n,r)=>y({x:e.x,y:-e.h/2,w:e.w,h:e.h},t,n,r).x,x=e=>e.rect||(e.left==null?null:{x:e.left,y:0,w:e.width||1,h:1}),S=e=>e.isFrame?x(e.cluster):l(e.item),C=e=>{let t=S(e);return t.x+t.w/2},w=[];for(let e of j){if(!e.chain||!e.chain.length)continue;let t=e.chain,n=t[0],r=t[t.length-1],i=e.reversed?e.toFrame:e.fromFrame,a=e.reversed?e.fromFrame:e.toFrame,o=e.reversed?e.edge.to:e.edge.from,s=e.reversed?e.edge.from:e.edge.to,c=i?V.get(o):null,l=a?V.get(s):null;if(i&&!c||a&&!l)continue;let d=(e,t,n,r)=>{let i=e?h.get(t):null;return e&&!x(i)?null:{isFrame:e,id:t,item:n,cluster:i,shape:e?`rect`:u(n),rankTop:e?r.top:n.rank,rankBottom:e?r.bottom:n.rank}},f=d(i,o,n,c),p=d(a,s,r,l);if(!f||!p)continue;f.down=!0,p.down=!1;let m=(e,t)=>e>=t.top&&e<=t.bottom,g=t=>{for(let n of h.values()){let r=V.get(n.id);if(r&&!T(e.owner,n)&&m(t.rank,r))return!0}return!1},_={le:e,lowEnd:f,highEnd:p,mids:t.slice(1,-1).filter(e=>!(i&&m(e.rank,c)||a&&m(e.rank,l)||g(e))),kind:e.reversed?`back`:`forward`,srcEnd:e.reversed?p:f,tgtEnd:e.reversed?f:p,stops:[],lanes:[],tracks:[],seq:e.edge.seq};w.push(_)}let E=new Map,D=new Map,O=(e,t,n)=>{e.has(t)||e.set(t,[]),e.get(t).push(n)};for(let e of w)e.kind===`forward`&&(e.srcEnd.isFrame||O(E,e.srcEnd.item,e),e.tgtEnd.isFrame||O(D,e.tgtEnd.item,e));let k=e=>e.mids.filter(e=>e.kind!==`label`),A=(e,t)=>{let n=k(e);if(t===`src`){let t=n[0];return t?t.centerX:C(e.tgtEnd)}let r=n[n.length-1];return r?r.centerX:C(e.srcEnd)},N=(e,t)=>t.rankBottom<e.rankTop?`top`:t.rankTop>e.rankBottom?`bottom`:C(t)<C(e)?`left`:`right`,P=(e,t,n)=>{if(!c(t))return 0;let r=S(e);return o(n,r.x+12,r.x+r.w-12)};for(let e of w){let t=e.srcEnd,n=e.tgtEnd;if(e.kind===`back`){let r=e=>{let r=e===`right`?1:-1,i=0;for(let a of[t,n]){let n=a===t?a.rankTop-.5:a.rankBottom+.5,o=C(a);for(let e of w){if(e.kind!==`forward`||e.srcEnd.rankBottom>=n||e.tgtEnd.rankTop<=n)continue;let t=[{rank:e.srcEnd.rankBottom,x:C(e.srcEnd)},...k(e).map(e=>({rank:e.rank,x:e.centerX})),{rank:e.tgtEnd.rankTop,x:C(e.tgtEnd)}];for(let e=1;e<t.length;e+=1)t[e-1].rank>=n||t[e].rank<=n||Math.max(r*(t[e-1].x-o),r*(t[e].x-o))>8&&(i+=1)}e===`right`&&a.item?.selfLoops?.length&&(i+=2)}return i},i=r(`left`)<r(`right`)?`left`:`right`;t.side=i,n.side=i,t.pref=0,n.pref=0,e.backSide=i}else{if(t.isFrame)t.side=N(t,n),t.pref=P(t,t.side,A(e,`src`));else if(d(t.item)){let r=S(t),i=C(n);i>r.x+16&&i<r.x+r.w-16?(t.side=`bottom`,t.hardCross=r.x+r.w/2,t.pref=A(e,`src`)):(t.side=i<r.x+r.w/2?`left`:`right`,t.hardCross=0,t.pref=0)}else t.side=`bottom`,t.pref=A(e,`src`);if(n.isFrame)n.side=N(n,t),n.pref=P(n,n.side,A(e,`tgt`));else if(d(n.item)){let r=S(n),i=C(t),a=r.x+r.w/2,o=t.isFrame?null:S(t);o&&d(t.item)&&(t.side===`right`&&a>o.x+o.w+16||t.side===`left`&&a<o.x-16)||i>r.x+16&&i<r.x+r.w-16?(n.side=`top`,n.hardCross=a,n.pref=A(e,`tgt`)):(n.side=i<r.x+r.w/2?`left`:`right`,n.hardCross=0,n.pref=0)}else n.side=`top`,n.pref=A(e,`tgt`)}}let F=e=>b(S(e),e.shape,e.side,0)+(e.side===`left`?-10:10);for(let e of w)e.kind!==`forward`||k(e).length||(!c(e.srcEnd.side)&&e.tgtEnd.side===`top`&&e.tgtEnd.hardCross==null&&(e.tgtEnd.pref=F(e.srcEnd),e.tgtEnd.outward=e.srcEnd.side===`left`?-1:1),!c(e.tgtEnd.side)&&e.srcEnd.side===`bottom`&&(e.srcEnd.pref=F(e.tgtEnd)));for(let[e,t]of D){let n=l(e),r=t.filter(e=>e.tgtEnd.side===`top`),i=Math.max(1,Math.floor((n.w-4)/16)+1);if(r.length<=i)continue;let a=n.x+n.w/2;r.sort((e,t)=>Math.abs(A(e,`tgt`)-a)-Math.abs(A(t,`tgt`)-a)||e.seq-t.seq),r.slice(i).forEach(e=>{e.tgtEnd.side=A(e,`tgt`)<a?`left`:`right`,e.tgtEnd.hardCross=0,e.tgtEnd.pref=0})}let I=(e,t)=>{if(t&&t.hardCross!=null)return 0;if(t&&t.isFrame)return 1;if(e.kind===`back`)return 6;let n=e.le.edge.style||`solid`,r=!!(e.mids&&e.mids.length);return n===`solid`||n===`bold`?r?2:3:r?4:5},L=[];for(let e of w)for(let t of[e.srcEnd,e.tgtEnd])L.push({route:e,end:t,side:t.side,isFrame:t.isFrame,rect:S(t),id:t.id,seq:e.seq,prio:I(e,t)});let R=[];for(let e of _)for(let r of e.selfLoops||[]){let a={item:e,edge:r,index:R.length},o=l(e),s=u(e);a.labelLines=r.label?(0,t.wrapText)(r.label,120,i.label,n):r.icon?[``]:[],a.labelW=a.labelLines.length?(0,t.maxWidthOf)(a.labelLines,i.label,n)+10+(r.icon?22:0):0,a.labelH=a.labelLines.length?Math.max(18,a.labelLines.length*16+6):0;let c=Math.max(8,(a.labelH+6)/2);a.upper={loop:a,side:`right`,isFrame:!1,rect:o,shape:s,id:e.id,want:-c,seq:r.seq,order:0},a.lower={loop:a,side:`right`,isFrame:!1,rect:o,shape:s,id:e.id,want:c,seq:r.seq,order:1},L.push(a.upper,a.lower),R.push(a)}let z=new Map;for(let e of L){let t=`${e.isFrame?`F`:`N`}${e.id}|${e.side}`;z.has(t)||z.set(t,[]),z.get(t).push(e)}let B=new Map,ee=e=>{let t=e[0].side,n=e[0].rect,r=c(t),i=r?n.w:n.h,a=e[0].isFrame?12:0,s=Math.max(0,Math.min((r?.3:.4)*i,i/2-a)),l=r?n.x+n.w/2:0,u=l-s,d=l+s,f=e.length,p=f>1?Math.min(16,2*s/Math.max(1,f-1)):16,m=e.map(e=>({request:e,fixed:e.end&&e.end.hardCross!=null?e.end.hardCross:null,want:e.end?e.end.hardCross==null?e.end.pref==null?l:e.end.pref:e.end.hardCross:e.want,pos:null,pinned:!1}));if(f>1){let e=new Map;for(let t of m){if(t.fixed==null)continue;let n=Math.round(t.fixed*2)/2;e.set(n,(e.get(n)||[]).concat(t))}for(let t of e.values())if(!(t.length<2))for(let e of t)e.fixed=null,e.want=e.request.end?e.request.end.pref==null?l:e.request.end.pref:e.request.want}let h=e=>o(e,u,d),g=(e,t)=>m.every(n=>n===t||n.pos==null||Math.abs(n.pos-e)>=p-.01),_=e=>!r&&e.request.end?e.request.end.down?1:-1:0,v=e=>(t,n)=>_(e)?(n-t)*_(e):t-n;for(let e of m)e.fixed!=null&&(e.pos=h(e.fixed),e.pinned=!0);let y=m.filter(e=>e.fixed==null).sort((e,t)=>(e.request.prio??3)-(t.request.prio??3)||e.want-t.want||e.request.seq-t.request.seq||(e.request.order??0)-(t.request.order??0));for(let e of y)e.want<u-.01||e.want>d+.01||g(e.want,e)&&(e.pos=e.want,e.pinned=!0);let b=!1;for(let e of y){if(e.pos!=null)continue;let t=[h(e.want),u,d];for(let e of m)e.pos!=null&&t.push(h(e.pos-p),h(e.pos+p));let n=t.filter(t=>g(t,e)),r=e.request.end&&e.request.end.outward;if(r){let t=e.want-r*10,i=t=>m.some(n=>n!==e&&n.pos!=null&&(n.pos-e.want)*r>.01&&(t-n.pos)*r>.01),a=n.filter(t=>(t-e.want)*r>=-.01),o=a.filter(e=>!i(e)),s=n.filter(n=>(n-e.want)*r<-.01&&(n-t)*r>=3.99);o.length?n=o:s.length?n=s:a.length&&(n=a)}if(!n.length){b=!0;break}n.sort((t,n)=>Math.abs(t-e.want)-Math.abs(n-e.want)||v(e)(t,n)),e.pos=n[0]}if(b){let e=m.slice().sort((e,t)=>e.want-t.want||_(e)-_(t)||e.request.seq-t.request.seq),t=Math.min(s,16*(f-1)/2);e.forEach((e,n)=>{e.pos=f===1?h(l):l-t+2*t*n/(f-1)})}for(let e of m)e.pos??=h(e.want);let x=new Map;for(let e of m){let t=Math.round(e.pos);x.set(t,(x.get(t)||[]).concat(e))}for(let e of x.values()){if(e.length<2)continue;let t=Math.min(16,2*s/Math.max(1,e.length-1)),n=l-t*(e.length-1)/2;e.slice().sort((e,t)=>e.want-t.want||_(e)-_(t)||e.request.seq-t.request.seq).forEach((e,r)=>{e.pos=h(n+r*t)})}if(!r&&f>1){let e=t===`left`?n.x:n.x+n.w,r=t=>{let{route:n,end:r,loop:i}=t.request;return i||!n||n.kind!==`forward`?null:Math.abs((r===n.srcEnd?A(n,`src`):A(n,`tgt`))-e)};for(let e of[-1,1]){let t=m.filter(t=>t.fixed==null&&_(t)===e&&r(t)!=null);if(t.length<2)continue;let n=t.map(e=>e.pos).sort((t,n)=>(t-n)*e);t.sort((e,t)=>r(t)-r(e)||e.request.seq-t.request.seq).forEach((e,t)=>{e.pos=n[t]})}}if(r&&f>1&&m.some(e=>m.some(t=>e.want<t.want-.5&&e.pos>t.pos+.01))){let e=m.slice().sort((e,t)=>e.want-t.want||e.request.seq-t.request.seq||(e.request.order??0)-(t.request.order??0)),t=[],n=[],r=u;for(let i of e)i.fixed==null?n.push(i):(t.push({items:n,lo:r,hi:i.pos-p}),n=[],r=i.pos+p);if(t.push({items:n,lo:r,hi:d}),t.some(e=>e.items.length&&e.lo+(e.items.length-1)*p>e.hi+.01)){let t=Math.min(s,p*(f-1)/2);e.forEach((e,n)=>{e.pos=l-t+2*t*n/(f-1)})}else for(let e of t){let t=e.items.length;if(!t)continue;let n=[];e.items.forEach((e,t)=>{for(n.push({sum:e.want-t*p,count:1});n.length>1;){let e=n[n.length-1],t=n[n.length-2];if(t.sum/t.count<=e.sum/e.count)break;n.pop(),t.sum+=e.sum,t.count+=e.count}});let r=e.hi-(t-1)*p,i=0;for(let t of n){let n=Math.max(e.lo,Math.min(r,t.sum/t.count));for(let r=0;r<t.count;r+=1,i+=1)e.items[i].pos=n+i*p}}}for(let e of m)e.request.pos=e.pos,e.request.end&&(e.request.end.pos=e.pos,B.set(e.request.end,{items:m,gap:p,min:u,max:d,item:e}))};for(let e of z.values())ee(e);let te=(e,t)=>{let n=B.get(e);if(!n||e.isFrame||e.hardCross!=null||!c(e.side)||!Number.isFinite(t)||t<n.min-.01||t>n.max+.01)return!1;for(let e of n.items)if(e!==n.item&&e.pos!=null&&(Math.abs(e.pos-t)<n.gap-.01||e.want<n.item.want-.5&&e.pos>t||e.want>n.item.want+.5&&e.pos<t))return!1;return n.item.pos=t,e.pos=t,!0},ne=e=>{if(e.kind!==`forward`||e.lanes.length<2)return!1;let t=e.lanes.length-1,n=[{end:e.srcEnd,lane:e.lanes[1],mate:e.tgtEnd},{end:e.tgtEnd,lane:e.lanes[t-1],mate:e.srcEnd}],r=!1;for(let{end:t,lane:i,mate:a}of n){if(!c(t.side))continue;let n=i-t.pos;Math.abs(n)<.01||(te(t,i)?r=!0:Math.abs(n)>=16.49||(te(t,t.pos-Math.sign(n)*(16.5-Math.abs(n)))||e.lanes.length===2&&te(a,t.pos))&&(r=!0))}return r},re=e=>c(e.side)?e.pos:b(S(e),e.shape,e.side,e.pos)+(e.side===`left`?-10:10),ie=[],H=e=>{let t=e.backSide,n=Math.min(e.tgtEnd.rankTop,e.srcEnd.rankBottom),r=Math.max(e.tgtEnd.rankBottom,e.srcEnd.rankTop),i=t===`right`?-1/0:1/0;for(let e of M){if(e.rank<n||e.rank>r)continue;let a=l(e);Number.isFinite(a.x)&&Number.isFinite(a.w)&&(i=t===`right`?Math.max(i,a.x+a.w):Math.min(i,a.x))}for(let e of h.values()){let a=x(e);a&&Number.isFinite(a.x)&&Number.isFinite(a.w)&&(e.bottomRank<n||e.topRank>r||(i=t===`right`?Math.max(i,a.x+a.w):Math.min(i,a.x)))}Number.isFinite(i)||(i=0);let a=Math.max(12,e.mids.reduce((e,t)=>t.kind===`label`?Math.max(e,t.bw/2+2):e,0)),o=i+(t===`right`?14:-14);for(let e=0;e<8;e+=1){let e=!1;for(let i of ie)i.side!==t||i.hi<=n||i.lo>=r||Math.abs(i.x-o)<a+i.need&&(o=i.x+(t===`right`?1:-1)*(a+i.need),e=!0);if(!e)break}return ie.push({side:t,lo:n,hi:r,x:o,need:a}),o},ae=(e,t)=>{let n=re(e.srcEnd),r=re(e.tgtEnd),i=Math.max(0,t.centerX-Math.max(n,r))+Math.max(0,Math.min(n,r)-t.centerX);if(!w.some(t=>t!==e&&t.lowEnd.id===e.lowEnd.id&&t.highEnd.id===e.highEnd.id)&&i>t.bw*2)return!1;if(Math.abs(n-r)<t.bw+2&&i<=t.bw&&w.some(e=>e.kind===`back`&&e.tgtEnd.rankBottom<t.rank&&e.srcEnd.rankTop>t.rank))return!0;for(let n of[e.srcEnd,e.tgtEnd])if(c(n.side)){for(let r of w)if(r!==e&&r.kind===`forward`){for(let e of[r.srcEnd,r.tgtEnd])if(e.id===n.id&&e.side===n.side&&Math.abs(e.pos-n.pos)<t.bw/2+5)return!0}}return!1};for(let e of w)e.kind===`forward`?e.stops=[{end:e.srcEnd},...e.mids.filter(t=>t.kind!==`label`||ae(e,t)).map(e=>({mid:e})),{end:e.tgtEnd}]:(e.channelX=H(e),e.stops=[{end:e.srcEnd},{channel:e.channelX},{end:e.tgtEnd}]);let oe=()=>{for(let e of w){if(e.lanes=e.stops.map(e=>e.end?re(e.end):e.mid?e.mid.centerX:e.channel),e.kind===`forward`&&e.lanes.length===2&&!c(e.srcEnd.side)&&!c(e.tgtEnd.side)){let[t,n]=e.lanes;(e.srcEnd.side===`right`?n>t:n<t)&&Math.abs(t-n)<16&&(e.lanes[0]=n)}if(e.kind===`forward`&&e.lanes.length===2&&!c(e.srcEnd.side)&&c(e.tgtEnd.side)&&!e.srcEnd.isFrame){let[t,n]=e.lanes,r=e.srcEnd.side===`right`?n>t:n<t,i=Math.min(t,n),a=Math.max(t,n),o=e.tgtEnd.side===`top`&&!e.tgtEnd.isFrame&&d(e.tgtEnd.item),s=(o?M:_).some(t=>{if(t===e.srcEnd.item||t.rank!==e.srcEnd.item.rank)return!1;let n=l(t);return n.x<a+8&&n.x+n.w>i-8});r&&(a-i<=32||o)&&!s&&(e.lanes[0]=n);let c=e.srcEnd.side===`right`?1:-1,u=t-c*10;!r&&(n-u)*c>=3.99&&(e.lanes[0]=n)}if(e.kind===`forward`&&e.lanes.length>=2&&c(e.srcEnd.side)&&!c(e.tgtEnd.side)&&!e.tgtEnd.isFrame){let t=e.lanes.length-1,n=e.lanes[t-1],r=e.lanes[t],i=e.tgtEnd.side===`right`?n>r:n<r,a=Math.min(n,r),o=Math.max(n,r),s=M.some(t=>{if(t===e.tgtEnd.item||t.rank!==e.tgtEnd.item.rank)return!1;let n=l(t);return n.x<o+8&&n.x+n.w>a-8});i&&!s&&(e.lanes[t]=n)}if(e.kind===`back`)for(let t of[0,e.lanes.length-1])Math.abs(e.lanes[t]-e.channelX)<16&&(e.lanes[t]=e.channelX)}for(let e of w){if(e.kind!==`forward`)continue;let t=e.stops.slice(1,-1);if(!t.length||t.some(e=>!e.mid||e.mid.kind!==`dummy`))continue;let n=e.lanes[1];if(e.lanes.slice(1,-1).some(e=>Math.abs(e-n)>.01))continue;let r=[e.lanes.at(-1),e.lanes[0]];for(let i of r){if(Math.abs(i-n)<.01||Math.abs(i-n)>=16)continue;let r=_.some(t=>{if(t.rank<=e.srcEnd.rankBottom||t.rank>=e.tgtEnd.rankTop)return!1;let n=l(t);return i>n.x-8&&i<n.x+n.w+8}),a=t.some(({mid:e})=>e.cluster&&e.cluster!==g&&(i<e.slotLeft||i>e.slotRight));if(!(r||a)){for(let t=1;t<e.lanes.length-1;t+=1)e.lanes[t]=i;break}}}};oe();for(let e=0;e<4;e+=1){let e=!1;for(let t of w)ne(t)&&(e=!0);if(!e)break;oe()}let se=new Map,ce=(e,t,n)=>{if(!Number.isFinite(e)||e<0||e>U-1)return null;se.has(e)||se.set(e,[]);let r={gap:e,route:t,index:n,y:null};return se.get(e).push(r),r},le=(e,t)=>t.end?t.end.isFrame?t.end===e.srcEnd?t.end.rankBottom:t.end.rankTop-1:t.end.item.rank:t.mid.rank;for(let e of w)if(e.tracks=[],e.kind===`forward`)for(let t=0;t+1<e.lanes.length;t+=1)Math.abs(e.lanes[t+1]-e.lanes[t])<.01?e.tracks.push(null):e.tracks.push(ce(le(e,e.stops[t]),e,t));else{let t=e.srcEnd.rankTop-1,n=e.tgtEnd.rankBottom,r,i;t===n?(i=ce(n,e,1),r=ce(t,e,0)):(r=ce(t,e,0),i=ce(n,e,1)),e.tracks=[r,i],t===n&&r&&i&&(r.after=i)}let W=e=>{let{route:t,index:n}=e,r=t.lanes;return t.kind===`forward`?{up:r[n],down:r[n+1]}:n===0?{up:r[1],down:r[0]}:{up:r[2],down:r[1]}},ue=e=>{let t=e.length;if(t<2)return;let n=e.map(e=>{let{up:t,down:n}=W(e);return{up:t,down:n,lo:Math.min(t,n),hi:Math.max(t,n)}}),r=(e,t)=>e>t.lo+.5&&e<t.hi-.5,i=n.map(e=>n.map(t=>e===t?0:Number(r(t.up,e))+Number(r(e.down,t)))),a=new Map(e.map((e,t)=>[e,t])),o=e.map(e=>e.after&&a.has(e.after)?a.get(e.after):-1),s=e=>e.reduce((t,n,r)=>t+e.slice(r+1).reduce((e,t)=>e+i[n][t],0),0),c=e.map((e,t)=>t);if(s(c)===0)return;let l;if(t<=12){let e=(1<<t)-1,n=new Float64Array(1<<t).fill(1/0);n[e]=0;let r=(e,t)=>!(e&1<<t)&&(o[t]<0||e&1<<o[t]),a=(e,n)=>{let r=0;for(let a=0;a<t;a+=1)e&1<<a&&(r+=i[a][n]);return r};for(let i=e-1;i>=0;--i)for(let e=0;e<t;e+=1)r(i,e)&&(n[i]=Math.min(n[i],a(i,e)+n[i|1<<e]));l=[];for(let i=0;i!==e;){let e=-1;for(let o=0;o<t&&e<0;o+=1)r(i,o)&&a(i,o)+n[i|1<<o]===n[i]&&(e=o);if(e<0)return;l.push(e),i|=1<<e}}else{l=c.slice();for(let e=0,n=!0;n&&e<t;e+=1){n=!1;for(let e=0;e+1<l.length;e+=1){let t=l[e],r=l[e+1];o[r]===t||i[r][t]>=i[t][r]||(l[e]=r,l[e+1]=t,n=!0)}}}if(s(l)>=s(c))return;let u=l.map(t=>e[t]);e.splice(0,t,...u)};for(let e of se.values())ue(e);let de=(e,t)=>({p0:e,p1:t,c1:{x:e.x+(t.x-e.x)/3,y:e.y+(t.y-e.y)/3},c2:{x:e.x+(t.x-e.x)*2/3,y:e.y+(t.y-e.y)*2/3},kind:`line`}),fe=(e,t,n,r,i)=>({p0:e,p1:t,c1:n,c2:r,kind:i}),pe=e=>{let t=[];for(let n of e){let e=t[t.length-1];if(!(e&&Math.abs(e.x-n.x)<.01&&Math.abs(e.y-n.y)<.01))for(t.push(n);t.length>=3;){let e=t[t.length-1],n=t[t.length-2],r=t[t.length-3],i=Math.abs(r.x-n.x)<.01&&Math.abs(n.x-e.x)<.01,a=Math.abs(r.y-n.y)<.01&&Math.abs(n.y-e.y)<.01;if(!i&&!a)break;t.splice(t.length-2,1)}}return t},G=e=>{let t=[];for(let n=0;n+1<e.length;n+=1){let r=e[n],i=e[n+1],a=Math.abs(r.y-i.y)<.01,o=Math.abs(r.x-i.x)<.01;(a||o)&&(Math.hypot(i.x-r.x,i.y-r.y)<.01||t.push({horizontal:a,a:r,b:i}))}return t},K=(e,t)=>{let n=[],r=(e,r)=>{let i=Math.hypot(r.x-e.x,r.y-e.y);if(i<.01)return;if(!(Math.abs(e.y-r.y)<.01)||!t||!t.length){n.push(de(e,r));return}let a=Math.sign(r.x-e.x)||1,o=t=>(t.x-e.x)*a,c=t.filter(t=>Math.abs(t.y-e.y)<.01&&o(t)>11&&o(t)<i-5-6).sort((e,t)=>o(e)-o(t)),l=e;for(let e of c){if(o(l)>o(e)-5-1)continue;let t={x:e.x-a*5,y:e.y},r={x:e.x+a*5,y:e.y},i={x:e.x,y:e.y-5};n.push(de(l,t)),n.push(fe(t,i,{x:t.x,y:t.y-5*s},{x:i.x-a*5*s,y:i.y},`jump`)),n.push(fe(i,r,{x:i.x+a*5*s,y:i.y},{x:r.x,y:r.y-5*s},`jump`)),l=r}Math.hypot(r.x-l.x,r.y-l.y)>.01&&n.push(de(l,r))},i=pe(e);if(i.length<2)return n;let a=i[0];for(let e=1;e+1<i.length;e+=1){let t=i[e],o=i[e+1],c=Math.hypot(t.x-a.x,t.y-a.y),l=Math.hypot(o.x-t.x,o.y-t.y);if(c<.01||l<.01)continue;let u=Math.min(6,c/2,l/2);if(u<.5){r(a,t),a=t;continue}let d={x:(t.x-a.x)/c,y:(t.y-a.y)/c},f={x:(o.x-t.x)/l,y:(o.y-t.y)/l},p={x:t.x-d.x*u,y:t.y-d.y*u},m={x:t.x+f.x*u,y:t.y+f.y*u};r(a,p),n.push(fe(p,m,{x:p.x+d.x*u*s,y:p.y+d.y*u*s},{x:m.x-f.x*u*s,y:m.y-f.y*u*s},`corner`)),a=m}return r(a,i[i.length-1]),n},me=(e,t)=>{let n=S(e);if(e.isFrame&&!c(e.side)){let r=t?S(t):null,i=r?r.y+r.h/2:n.y+n.h/2,a=Math.max(0,n.h/2-16);return y(n,e.shape,e.side,o(i-(n.y+n.h/2),-a,a))}return y(n,e.shape,e.side,e.pos)},he=(e,t)=>e.end?me(e.end,t).y:e.mid?e.mid.cy:null,ge=e=>{let t=[];for(let n of e){let e=t[t.length-1];e&&Math.abs(e.x-n.x)>.01&&Math.abs(e.y-n.y)>.01&&t.push({x:e.x,y:n.y}),t.push(n)}return t},_e=e=>{let t=[],n=me(e.srcEnd,e.tgtEnd),r=me(e.tgtEnd,e.srcEnd);t.push(n);let i=e.lanes[0];c(e.srcEnd.side)||t.push({x:i,y:n.y});for(let n=0;n+1<e.lanes.length;n+=1){let r=Math.abs(e.lanes[n+1]-i)<1?i:e.lanes[n+1];if(Math.abs(r-i)>.01){let a=e.tracks[n],o=a?a.y:null;if(o==null){let t=t=>t.end?t.end===e.srcEnd?e.tgtEnd:e.srcEnd:null,r=he(e.stops[n],t(e.stops[n])),i=he(e.stops[n+1],t(e.stops[n+1]));o=r!=null&&i!=null?(r+i)/2:(r??i??0)+20}t.push({x:i,y:o}),t.push({x:r,y:o})}i=r}return c(e.tgtEnd.side)?Math.abs(r.x-i)>.01&&Math.abs(r.x-i)<1.5&&(r.x=i):t.push({x:i,y:r.y}),t.push(r),pe(ge(t))},ve=e=>{let t=e.visualRect;if(!t)return null;let n=e.titleLines.length*17+(e.descLines.length?4+e.descLines.length*16:0),r={x:t.x+a,y:t.y+10,w:Math.max(e.titleW,e.descW||0,1),h:Math.max(n,1)};return p===`BT`?{x:r.x,y:Ke-r.y-r.h,w:r.w,h:r.h}:p===`LR`?{x:r.y,y:r.x,w:r.h,h:r.w}:p===`RL`?{x:r.y,y:Ge-r.x-r.w,w:r.h,h:r.w}:r},ye=(e,t)=>G(t).some(t=>{let n=Math.min(t.a.x,t.b.x),r=Math.max(t.a.x,t.b.x),i=Math.min(t.a.y,t.b.y),a=Math.max(t.a.y,t.b.y);return!(r<e.x+.5||n>e.x+e.w-.5||a<e.y+.5||i>e.y+e.h-.5)});return{routes:w,loops:R,gapTracks:se,build:()=>{for(let e of w)e.points=_e(e);let e=R.map(e=>{let t=l(e.item),n=u(e.item),r=y(t,n,`right`,e.upper.pos??-8),i=y(t,n,`right`,e.lower.pos??8),a=Math.max(24,e.labelW/2+12),o=Math.max(t.x+t.w+a,r.x+a,i.x+a),s=pe([r,{x:o,y:r.y},{x:o,y:i.y},i]),c=e.labelLines,d=null;return c.length&&(d={x:o-e.labelW/2,y:(r.y+i.y)/2-e.labelH/2,w:e.labelW,h:e.labelH}),e.points=s,e.labelRect=d,e}),t=[];for(let e of w)for(let n of G(e.points))t.push({run:n,key:e});for(let n of e)for(let e of G(n.points))t.push({run:e,key:n});let n=new Map,r=[];for(let e of t)r.push(e.run.a,e.run.b);for(let{run:e,key:i}of t){if(!e.horizontal)continue;let a=Math.min(e.a.x,e.b.x),o=Math.max(e.a.x,e.b.x),s=e.a.y,c=[];for(let e of t){if(e.key===i||e.run.horizontal)continue;let t=e.run.a.x;if(t<a+5+14||t>o-5-14)continue;let n=Math.min(e.run.a.y,e.run.b.y),l=Math.max(e.run.a.y,e.run.b.y);s<n+5+10||s>l-5-10||r.some(e=>Math.hypot(e.x-t,e.y-s)<20)||c.push({x:t,y:s})}if(!c.length)continue;let l=n.get(i)||[];n.set(i,l.concat(c))}let i=new Map(w.map(e=>[e.le.edge.seq,e])),a=new Map;for(let e of M){if(e.kind!==`label`)continue;let t=i.get(e.edge.seq);t&&a.set(e,t)}let o=new Map,s=(e,t)=>{let n=1-t,r=n*n*n,i=3*n*n*t,a=3*n*t*t,o=t*t*t;return{x:r*e.p0.x+i*e.c1.x+a*e.c2.x+o*e.p1.x,y:r*e.p0.y+i*e.c1.y+a*e.c2.y+o*e.p1.y}},c=new Map(w.map(e=>[e,K(e.points,n.get(e)||[])])),d=[...h.values()].map(e=>e.rect).filter(Boolean),f=[];for(let e of h.values()){let t=ve(e);t&&f.push(t)}let p=(t,n,r)=>{for(let e of _)if(Z(r,l(e),2))return!1;for(let[e,n]of o)if(e!==t&&Z(r,n,3))return!1;for(let t of e)if(t.labelRect&&Z(r,t.labelRect,3))return!1;for(let e of f)if(Z(r,e,2))return!1;for(let e of d)if(Z(r,e,1)&&!(r.x>=e.x-.5&&r.y>=e.y-.5&&r.x+r.w<=e.x+e.w+.5&&r.y+r.h<=e.y+e.h+.5))return!1;for(let e of w)if(e!==n){if(ye(r,e.points))return!1;for(let t of c.get(e)||[])if(t.kind!==`line`)for(let e=0;e<=12;e+=1){let n=s(t,e/12);if(n.x>r.x-1&&n.x<r.x+r.w+1&&n.y>r.y-1&&n.y<r.y+r.h+1)return!1}}for(let t of e)if(ye(r,t.points))return!1;return!0};for(let[e,t]of a){let n=e.bw,r=e.bh,i={x:t.kind===`back`?t.channelX:e.centerX,y:e.cy},a=null,l=1/0,u=null,d=1/0,f=t.points.slice(1,-1);for(let o of G(t.points)){let s=Math.hypot(o.b.x-o.a.x,o.b.y-o.a.y),c=Math.max(1,Math.ceil(s/6));for(let s=0;s<=c;s+=1){let m=s/c,h=o.a.x+(o.b.x-o.a.x)*m,g=o.a.y+(o.b.y-o.a.y)*m,_=f.some(e=>Math.hypot(e.x-h,e.y-g)<6+r/2+2),v=Math.hypot(h-i.x,g-i.y)+(_?14:0),y={x:h-n/2,y:g-r/2,w:n,h:r};v<d&&(u=y,d=v),v>=l||p(e,t,y)&&(a=y,l=v)}}let m=a||u;if(!m)continue;let h=c.get(t)||[],g=null,_=1/0;for(let e of h){let t=Math.hypot(e.p1.x-e.p0.x,e.p1.y-e.p0.y),i=Math.max(8,Math.min(80,Math.ceil(t/2)));for(let t=0;t<=i;t+=1){let a=s(e,t/i),o=Math.hypot(a.x-(m.x+n/2),a.y-(m.y+r/2));o<_&&(_=o,g=a)}}g&&_>.05&&_<8&&(m.x+=g.x-(m.x+n/2),m.y+=g.y-(m.y+r/2)),o.set(e,m)}for(let[e,t]of a){let n=o.get(e);if(!n)continue;let r=c.get(t)||[],i=null,a=1/0;for(let e of r){let t=Math.hypot(e.p1.x-e.p0.x,e.p1.y-e.p0.y),r=Math.max(8,Math.min(80,Math.ceil(t/2)));for(let t=0;t<=r;t+=1){let o=s(e,t/r),c=Math.hypot(o.x-(n.x+n.w/2),o.y-(n.y+n.h/2));c<a&&(a=c,i=o)}}!i||a<=.05||a>24||(n.x+=i.x-(n.x+n.w/2),n.y+=i.y-(n.y+n.h/2))}return{routes:w.map(e=>({le:e.le,start:e.points[0],end:e.points[e.points.length-1],points:e.points,segments:K(e.points,n.get(e)||[])})),loops:e.map(e=>({edge:e.edge,item:e.item,start:e.points[0],end:e.points[e.points.length-1],points:e.points,segments:K(e.points,n.get(e)||[]),labelRect:e.labelRect,labelLines:e.labelLines})),labels:o}}}})(),Oe=e=>(H.get(e)||[]).reduce((e,t)=>Math.max(e,t.bh),0),q=e=>(H.get(e)||[]).some(e=>e.kind===`real`),ke=e=>(H.get(e)||[]).some(e=>e.kind===`label`),Ae=(t,n)=>e.type===`er`&&(q(t)||q(n))?q(t)&&q(n)?60:38:q(t)&&q(n)?34:q(t)||q(n)?20:(ke(t)||ke(n),16),je=e=>e===g?0:m?12:e.titleBand,Me=e=>e===g?0:12;for(let e of h.values()){let t=_.filter(t=>T(t.cluster,e));t.length?(e.topRank=Math.min(...t.map(e=>e.rank)),e.bottomRank=Math.max(...t.map(e=>e.rank))):(e.topRank=1/0,e.bottomRank=-1/0)}let Ne=e=>{let t=0;for(let n of e.children)n.topRank===e.topRank&&Number.isFinite(n.topRank)&&(t=Math.max(t,Ne(n)));return je(e)+t},Pe=e=>{let t=0;for(let n of e.children)n.bottomRank===e.bottomRank&&Number.isFinite(n.bottomRank)&&(t=Math.max(t,Pe(n)));return Me(e)+t},Fe=new Map;for(let e=0;e<U;e+=1){let t=[...h.values()].filter(t=>t.topRank===e+1).reduce((e,t)=>Math.max(e,Ne(t)),0),n=[...h.values()].filter(t=>t.bottomRank===e).reduce((e,t)=>Math.max(e,Pe(t)),0);Fe.set(e,Math.max(t,n))}let Ie=new Map;for(let e of j){if(!e.fromItem||!e.toItem)continue;let t=Math.min(e.fromItem.rank,e.toItem.rank),n=Math.max(e.fromItem.rank,e.toItem.rank),r=e.edge.from,i=e.edge.to,a=r<i?`${r}<->${i}`:`${i}<->${r}`;for(let e=t;e<n;e+=1){Ie.has(e)||Ie.set(e,new Map);let t=Ie.get(e);t.set(a,(t.get(a)||0)+1)}}for(let[e,t]of Ie){let n=Math.max(...t.values());n<=3||Fe.set(e,Math.max(Fe.get(e)||0,(n-3)*24))}let Le=new Map([[0,0]]);for(let e=1;e<=U;e+=1)Le.set(e,Le.get(e-1)+Oe(e-1)/2+Ae(e-1,e)+(Fe.get(e-1)||0)+Oe(e)/2);for(let e of M)e.cy=Le.get(e.rank);let Re=e=>{for(let t of e.children)Re(t);if(e===g){e.rect=null;return}let t=M.filter(t=>T(t.cluster,e));if(!t.length){e.rect=null;return}let n=Math.min(...t.map(e=>e.cy-e.bh/2)),r=Math.max(...t.map(e=>e.cy+e.bh/2));for(let t of e.children)t.rect&&(n=Math.min(n,t.rect.y),r=Math.max(r,t.rect.y+t.rect.h));e.rect={x:e.left,y:n-je(e),w:e.width,h:r+Me(e)-(n-je(e))}};if(Re(g),De){let e=e=>{let t=-1/0,n=1/0;for(let n of H.get(e)||[])t=Math.max(t,n.cy+n.bh/2);for(let t of H.get(e+1)||[])n=Math.min(n,t.cy-t.bh/2);for(let r of h.values())r.rect&&(r.topRank===e+1&&(n=Math.min(n,r.rect.y-6)),r.bottomRank===e&&(t=Math.max(t,r.rect.y+r.rect.h+6)));return{lo:t,hi:n}},t=e=>(e.length-1)*12+32;for(let n=0;n<10;n+=1){let n=!1;for(let r=0;r<U;r+=1){let i=De.gapTracks.get(r);if(!i||!i.length)continue;let a=e(r),o=t(i);if(!(a.hi-a.lo>=o-1e-6)){Fe.set(r,(Fe.get(r)||0)+(o-(a.hi-a.lo))+2),n=!0,Le.set(0,0);for(let e=1;e<=U;e+=1)Le.set(e,Le.get(e-1)+Oe(e-1)/2+Ae(e-1,e)+(Fe.get(e-1)||0)+Oe(e)/2);for(let e of M)e.cy=Le.get(e.rank);Re(g)}}if(!n)break}let n=new Map;for(let[t,r]of De.gapTracks){let i=e(t);n.set(t,i);let a=Math.max(12,Math.min(16,(i.hi-i.lo-32)/Math.max(1,r.length-1))),o=(r.length-1)*a,s=i.lo+Math.max(16,(i.hi-i.lo-o)/2);r.forEach((e,t)=>{e.y=s+t*a})}let r=[];for(let[e,t]of De.gapTracks)for(let n of t)r.push({gap:e,track:n});r.sort((e,t)=>e.track.y-t.track.y);for(let e=1;e<r.length;e+=1){let t=r[e-1].track,i=r[e],a=12-(i.track.y-t.y);if(a<=.01)continue;let o=n.get(i.gap);if(!o)continue;let s=Math.min(o.hi-6,i.track.y+a);i.track.y=Math.max(i.track.y,s)}}let J=[];for(let e of _){let t=m?e.th:e.tw,n=m?e.tw:e.th;e.tbVisual={x:e.centerX+(e.offsetCross||0)-t/2,y:e.cy-n/2,w:t,h:n},J.push(e.tbVisual)}let Y=ie.filter(e=>e.kind===`label`);for(let e of Y){let t=m?e.th:e.tw,n=m?e.tw:e.th;e.tbVisual={x:e.centerX-t/2,y:e.cy-n/2,w:t,h:n},J.push(e.tbVisual)}for(let e of M)J.push({x:e.centerX-e.bw/2,y:e.cy-e.bh/2,w:e.bw,h:e.bh});for(let e of h.values())e.rect&&J.push(e.rect);let ze=Math.min(...J.map(e=>e.x)),Be=Math.min(...J.map(e=>e.y)),Ve=Math.max(...J.map(e=>e.x+e.w)),He=Math.max(...J.map(e=>e.y+e.h)),Ue=-ze,We=-Be,Ge=Ve-ze,Ke=He-Be,qe=(e,t)=>{let n=e+Ue,r=t+We;return p===`BT`?{x:n,y:Ke-r}:p===`LR`?{x:r,y:n}:p===`RL`?{x:Ge-r,y:n}:{x:n,y:r}},Je=e=>{let t=e.x+Ue,n=e.y+We;t+e.w;let r=n+e.h;return p===`BT`?{x:t,y:Ke-r,w:e.w,h:e.h}:p===`LR`?{x:n,y:t,w:e.h,h:e.w}:p===`RL`?{x:Ge-r,y:t,w:e.h,h:e.w}:{x:t,y:n,w:e.w,h:e.h}},Ye=new Map;for(let e of _){let t=Je(e.tbVisual);e.visualRect=t;let n=qe(e.centerX+(e.offsetCross||0),e.cy);e.vx=n.x,e.vy=n.y,Ye.set(e.node.id,{item:e,rect:t})}let Xe=new Map;for(let e of Y){let t=Je(e.tbVisual);e.visualRect=t;let n=qe(e.centerX,e.cy);e.vx=n.x,e.vy=n.y,Xe.set(e,{item:e,rect:t})}for(let e of ie){if(e.kind===`label`)continue;let t=qe(e.centerX,e.cy);e.vx=t.x,e.vy=t.y}let Ze=new Map;for(let e of h.values()){if(!e.rect)continue;let t=Je(e.rect),n=e.titleLines.length*17+(e.descLines.length?4+e.descLines.length*16:0),r={x:t.x+a,y:t.y+10,w:Math.max(e.titleW,e.descW||0,1),h:Math.max(n,1)};e.visualRect=t,e.visualTitleRect=r,Ze.set(e.id,{cluster:e,rect:t,titleRect:r})}let X=[],Qe=(e,t,n)=>Math.max(t,Math.min(n,e)),$e=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),Z=(e,t,n=0)=>e.x<t.x+t.w+n&&e.x+e.w+n>t.x&&e.y<t.y+t.h+n&&e.y+e.h+n>t.y;if(De){let e=De.build(),t=e=>qe(e.x,e.y),n=e=>e.map(e=>({p0:t(e.p0),p1:t(e.p1),c1:t(e.c1),c2:t(e.c2),kind:e.kind}));for(let r of e.routes){let{le:e}=r;e.start=t(r.start),e.end=t(r.end),e.points=r.points.map(t),e.segments=n(r.segments)}for(let[t,n]of e.labels)t.visualRect=Je(n),t.vx=t.visualRect.x+t.visualRect.w/2,t.vy=t.visualRect.y+t.visualRect.h/2;X=e.loops.map(e=>({edge:e.edge,item:e.item,start:t(e.start),end:t(e.end),points:e.points.map(t),segments:n(e.segments),labelRect:e.labelRect?Je(e.labelRect):null,labelLines:e.labelLines}))}else{let r=(e,t)=>m?t.x>=e.x?`right`:`left`:t.y>=e.y?`bottom`:`top`,a=(e,t,n)=>{let r=e.visualRect,i=r.x+r.w/2,a=r.y+r.h/2,o=r.w/2,s=r.h/2,c=e.node.shape,l=c===`diamond`||e.node.kind===`choice`,u=c===`circle`||e.node.kind===`start`||e.node.kind===`end`;if(t===`top`||t===`bottom`){let e=Qe(n,i-o*.96,i+o*.96),d=t===`top`?r.y:r.y+r.h;if(l){let n=Math.min(o*.96,Math.abs(e-i));d=a+(t===`top`?-1:1)*s*(1-n/o)}else if(u){let n=Math.min(o*.96,Math.abs(e-i)),r=s*Math.sqrt(Math.max(0,1-(n/o)**2));d=a+(t===`top`?-1:1)*r}else if(c===`hexagon`){let n=o-Math.min(16,o*.35),r=Math.abs(e-i);if(r>n){let e=Math.min(1,(r-n)/Math.max(1,o-n));d=a+(t===`top`?-1:1)*s*e}}return{x:e,y:d}}let d=Qe(n,a-s*.96,a+s*.96),f=t===`left`?r.x:r.x+r.w;if(l){let e=Math.min(s*.82,Math.abs(d-a));f=i+(t===`left`?-1:1)*o*(1-e/s)}else if(u){let e=Math.min(s*.84,Math.abs(d-a)),n=o*Math.sqrt(Math.max(0,1-(e/s)**2));f=i+(t===`left`?-1:1)*n}else if(c===`hexagon`){let e=Math.min(16,s*.35),n=Math.abs(d-a)/Math.max(1,s);f=t===`left`?r.x+e*n:r.x+r.w-e*n}return{x:f,y:d}},o=(e,t,n)=>{if(t===`top`||t===`bottom`){let r=e.x+e.w/2;return{x:Qe(n,r-e.w*.48,r+e.w*.48),y:t===`top`?e.y:e.y+e.h}}let r=e.y+e.h/2,i=Qe(n,r-e.h*.48,r+e.h*.48);return{x:t===`left`?e.x:e.x+e.w,y:i}},s=(e,t,n,i)=>{let a=V.get(e);return a?t<a.top?m?`left`:`top`:t>a.bottom?m?`right`:`bottom`:r(i,n):r(i,n)},c=[];for(let e of j){if(!e.chain)continue;let t=e.chain[0],n=e.chain[e.chain.length-1],i=e.reversed?e.toFrame:e.fromFrame,a=e.reversed?e.fromFrame:e.toFrame,o=e.reversed?e.edge.to:e.edge.from,l=e.reversed?e.edge.from:e.edge.to,u=i?V.get(o):null,d=a?V.get(l):null,f=e.chain.slice(1,-1),p=i?$e(Ze.get(o).rect):{x:t.visualRect.x+t.visualRect.w/2,y:t.visualRect.y+t.visualRect.h/2},m=a?$e(Ze.get(l).rect):{x:n.visualRect.x+n.visualRect.w/2,y:n.visualRect.y+n.visualRect.h/2},h=f.length?{x:f[0].vx,y:f[0].vy}:{x:n.vx,y:n.vy},g=f.length?{x:f[f.length-1].vx,y:f[f.length-1].vy}:{x:t.vx,y:t.vy},_=i?s(o,n.rank,h,p):r(p,h),v=a?s(l,t.rank,g,m):r(m,g),y=f.filter(e=>!(i&&((_===`top`||_===`left`)&&e.rank>=u.top||(_===`bottom`||_===`right`)&&e.rank<=u.bottom)||a&&((v===`top`||v===`left`)&&e.rank>=d.top||(v===`bottom`||v===`right`)&&e.rank<=d.bottom)));e.filteredMids=y;let b=y.length?{x:y[0].vx,y:y[0].vy}:{x:n.vx,y:n.vy},x=y.length?{x:y[y.length-1].vx,y:y[y.length-1].vy}:{x:t.vx,y:t.vy},S=_===`top`||_===`bottom`?b.x:b.y,C=v===`top`||v===`bottom`?x.x:x.y;e.lowReq={le:e,role:`low`,id:o,isFrame:i,side:_,cross:S,item:i?null:t,rect:i?Ze.get(o).rect:null,center:p,edgeSeq:e.edge.seq},e.highReq={le:e,role:`high`,id:l,isFrame:a,side:v,cross:C,item:a?null:n,rect:a?Ze.get(l).rect:null,center:m,edgeSeq:e.edge.seq},c.push(e.lowReq,e.highReq)}let l=new Map;for(let e of c){let t=`${e.isFrame?`F`:`N`}:${e.id}:${e.side}`;l.has(t)||l.set(t,[]),l.get(t).push(e)}let u=e.type===`er`?28:12,d=new Map;for(let e of l.values()){let t=e[0];if(t.isFrame||e.length<2)continue;let n=t.item;if(n.cluster&&n.cluster!==g)continue;let r=t.side===`left`||t.side===`right`,i=r?n.visualRect.h:n.visualRect.w,a=Math.max(i,(e.length-1)*u/.96),o=d.get(n)||{w:n.visualRect.w,h:n.visualRect.h};r?o.h=Math.max(o.h,a):o.w=Math.max(o.w,a),d.set(n,o)}for(let[e,t]of d){let n=e.visualRect;if(t.w<=n.w+.1&&t.h<=n.h+.1)continue;let r={x:n.x-(t.w-n.w)/2,y:n.y-(t.h-n.h)/2,w:t.w,h:t.h};_.some(t=>t!==e&&Z(r,t.visualRect,4))||(e.visualRect=r)}for(let e of c)e.isFrame||(e.center=$e(e.item.visualRect));for(let e of l.values()){e.sort((e,t)=>e.cross-t.cross||e.edgeSeq-t.edgeSeq||(e.role===`low`?-1:1));let t=e.length,n=e[0],r=n.isFrame?n.side===`top`||n.side===`bottom`?n.rect.w:n.rect.h:n.side===`top`||n.side===`bottom`?n.item.visualRect.w:n.item.visualRect.h,i=n.side===`top`||n.side===`bottom`?n.center.x:n.center.y,s=t===1?0:Math.min(r*.96,u*(t-1));e.forEach((e,n)=>{let r=t===1?i:i-s/2+s*n/(t-1);e.port=e.isFrame?o(e.rect,e.side,r):a(e.item,e.side,r)})}let f=e=>{let t=[];for(let n=0;n<e.length-1;n+=1){let r=e[n],i=e[n+1];if(Math.hypot(i.x-r.x,i.y-r.y)<.01)continue;let a,o;if(m){let e=(r.x+i.x)/2;a={x:e,y:r.y},o={x:e,y:i.y}}else{let e=(r.y+i.y)/2;a={x:r.x,y:e},o={x:i.x,y:e}}t.push({p0:r,p1:i,c1:a,c2:o})}return t},h=(e,t)=>({x:e.x+(t===`right`?18:t===`left`?-18:0),y:e.y+(t===`bottom`?18:t===`top`?-18:0)}),v=(e,t)=>({p0:e,p1:t,c1:{x:e.x+(t.x-e.x)/3,y:e.y+(t.y-e.y)/3},c2:{x:e.x+(t.x-e.x)*2/3,y:e.y+(t.y-e.y)*2/3}});for(let t of j){if(!t.chain||!t.lowReq)continue;let n=t.filteredMids.map(e=>({x:e.vx,y:e.vy}));if(e.type===`er`){let e=h(t.lowReq.port,t.lowReq.side),r=h(t.highReq.port,t.highReq.side),i=[v(t.lowReq.port,e),...f([e,...n,r]),v(r,t.highReq.port)];t.start=t.reversed?t.highReq.port:t.lowReq.port,t.end=t.reversed?t.lowReq.port:t.highReq.port,t.segments=t.reversed?i.reverse().map(({p0:e,p1:t,c1:n,c2:r})=>({p0:t,p1:e,c1:r,c2:n})):i;continue}let r=[t.lowReq.port,...n,t.highReq.port],i=t.reversed?[...r].reverse():r;t.start=i[0],t.end=i[i.length-1],t.segments=f(i)}X=[];for(let e of _)if(e.selfLoops.length)for(let r of e.selfLoops){let o=e.visualRect,s=o.x+o.w/2,c=o.y+o.h/2,l=r.label?(0,t.maxWidthOf)((0,t.wrapText)(r.label,120,i.label,n),i.label,n):0,u=r.label?(0,t.wrapText)(r.label,120,i.label,n):[],d=u.length?u.length*16+6:0,f=p===`LR`||p===`RL`?Math.max(16,u.length?(d+12)/1.5:16):Math.max(16,u.length?(l+22)/1.5:16),m,h,g,_;if(p===`LR`||p===`RL`){let t=p===`LR`,n=t?`bottom`:`top`,r=t?o.y+o.h:o.y;m=a(e,n,s-8),h=a(e,n,s+8),_=t?r+f*.75:r-f*.75,g=[{p0:m,p1:h,c1:{x:s-8,y:t?r+f:r-f},c2:{x:s+8,y:t?r+f:r-f}}]}else{let t=o.x+o.w;m=a(e,`right`,c-8),h=a(e,`right`,c+8),_=t+f*.75,g=[{p0:m,p1:h,c1:{x:t+f,y:c-8},c2:{x:t+f,y:c+8}}]}let v=null;u.length&&(v=p===`LR`||p===`RL`?{x:s-(l+10)/2,y:_-d/2,w:l+10,h:d}:{x:_-(l+10)/2,y:c-d/2,w:l+10,h:d}),X.push({edge:r,item:e,start:m,end:h,segments:g,labelRect:v,labelLines:u})}let y=new Map;for(let e of j){let t=e.chain?e.chain.find(e=>e.kind===`label`):null;t&&y.set(t,e)}let b=(e,t)=>{let n=1-t;return{x:n*n*n*e.p0.x+3*n*n*t*e.c1.x+3*n*t*t*e.c2.x+t*t*t*e.p1.x,y:n*n*n*e.p0.y+3*n*n*t*e.c1.y+3*n*t*t*e.c2.y+t*t*t*e.p1.y}},x=[];for(let e of j)e.segments&&e.segments.length&&x.push({le:e,segments:e.segments});for(let e of X)x.push({loop:e,segments:e.segments});let S=(e,t,n)=>{for(let t of _)if(Z(e,t.visualRect,2))return!1;for(let n of Y)if(n!==t&&Z(e,n.visualRect,2))return!1;for(let t of X)if(t.labelRect&&Z(e,t.labelRect,2))return!1;for(let t of Ze.values())if(t.titleRect&&Z(e,t.titleRect,2))return!1;for(let t of x)if(!(t.le===n||t.loop))for(let n of t.segments)for(let t=0;t<=48;t+=1){let r=b(n,t/48);if(r.x>e.x+.5&&r.x<e.x+e.w-.5&&r.y>e.y+.5&&r.y<e.y+e.h-.5)return!1}return!0};if(!De){let e=[...Y].sort((e,t)=>e.edge.seq-t.edge.seq);for(let t of e){let e=y.get(t);if(!e||!e.segments||!e.segments.length)continue;let n=t.visualRect;if(S(n,t,e))continue;let r=n.w,i=n.h,a=[];for(let t of e.segments)for(let e=6;e<=44;e+=1){let n=b(t,e/50);a.push({x:n.x-r/2,y:n.y-i/2,w:r,h:i})}let o=null,s=1/0;for(let r of a){if(!S(r,t,e))continue;let i=Math.hypot(r.x-n.x,r.y-n.y);i<s&&(o=r,s=i)}o&&(t.visualRect=o,t.vx=o.x+r/2,t.vy=o.y+i/2)}}}let Q=[];for(let e of _)Q.push(e.visualRect);for(let e of Y)Q.push(e.visualRect);for(let e of h.values())e.visualRect&&Q.push(e.visualRect),e.visualTitleRect&&Q.push(e.visualTitleRect);for(let e of j)if(e.segments)for(let t of e.segments)Q.push({x:t.p0.x,y:t.p0.y,w:0,h:0}),Q.push({x:t.p1.x,y:t.p1.y,w:0,h:0}),Q.push({x:t.c1.x,y:t.c1.y,w:0,h:0}),Q.push({x:t.c2.x,y:t.c2.y,w:0,h:0});for(let e of X){for(let t of e.segments)Q.push({x:t.p0.x,y:t.p0.y,w:0,h:0}),Q.push({x:t.p1.x,y:t.p1.y,w:0,h:0}),Q.push({x:t.c1.x,y:t.c1.y,w:0,h:0}),Q.push({x:t.c2.x,y:t.c2.y,w:0,h:0});e.labelRect&&Q.push(e.labelRect)}let et=Math.min(...Q.map(e=>e.x)),tt=Math.min(...Q.map(e=>e.y)),nt=Math.max(...Q.map(e=>e.x+e.w)),rt=Math.max(...Q.map(e=>e.y+e.h)),it=o-et,at=o-tt,ot=Math.ceil(nt-et+32),st=Math.ceil(rt-tt+32),$=e=>({x:e.x+it,y:e.y+at}),ct=e=>({x:e.x+it,y:e.y+at,w:e.w,h:e.h});for(let e of _){e.visualRect=ct(e.visualRect);let t=$({x:e.vx,y:e.vy});e.vx=t.x,e.vy=t.y}for(let e of Y){e.visualRect=ct(e.visualRect);let t=$({x:e.vx,y:e.vy});e.vx=t.x,e.vy=t.y}for(let e of ie){if(e.kind===`label`)continue;let t=$({x:e.vx,y:e.vy});e.vx=t.x,e.vy=t.y}for(let e of h.values())e.visualRect&&=ct(e.visualRect),e.visualTitleRect&&=ct(e.visualTitleRect);for(let e of j)e.start=e.start?$(e.start):null,e.end=e.end?$(e.end):null,e.segments=e.segments.map(e=>({p0:$(e.p0),p1:$(e.p1),c1:$(e.c1),c2:$(e.c2),...e.kind===void 0?{}:{kind:e.kind}}));for(let e of X)e.start=$(e.start),e.end=$(e.end),e.segments=e.segments.map(e=>({p0:$(e.p0),p1:$(e.p1),c1:$(e.c1),c2:$(e.c2),...e.kind===void 0?{}:{kind:e.kind}})),e.labelRect&&=ct(e.labelRect);let lt=_.map(e=>{let t=c(e,e.visualRect);return{id:e.node.id,kind:e.node.kind,shape:e.node.shape,direction:p,class:e.node.class,label:e.node.label,lines:e.titleLines,descLines:e.descLines,er:e.er,parent:e.parent,x:e.visualRect.x,y:e.visualRect.y,w:e.visualRect.w,h:e.visualRect.h,titleY:t.titleY,descY:t.descY}}),ut=Y.map(e=>({id:e.id,edge:e.edge.seq,lines:e.labelLines,x:e.visualRect.x,y:e.visualRect.y,w:e.visualRect.w,h:e.visualRect.h}));for(let e of X)e.labelRect&&ut.push({id:`@@self:${e.edge.seq}`,edge:e.edge.seq,lines:e.labelLines,x:e.labelRect.x,y:e.labelRect.y,w:e.labelRect.w,h:e.labelRect.h});let dt=[...h.values()].filter(e=>e.visualRect).map(e=>({id:e.id,title:e.title,class:e.class,kind:e.model.kind,parent:e.model.parent||null,lines:e.titleLines,descLines:e.descLines,x:e.visualRect.x,y:e.visualRect.y,w:e.visualRect.w,h:e.visualRect.h,titleRect:e.visualTitleRect})),ft=[];for(let e of j){let t=e.chain.find(e=>e.kind===`label`);ft.push({id:e.edge.seq,from:e.edge.from,to:e.edge.to,fromFrame:e.fromFrame,toFrame:e.toFrame,label:e.edge.label,reversed:e.reversed,style:e.edge.style,startArrow:e.edge.startArrow,endArrow:e.edge.endArrow,startMark:e.edge.startMark,endMark:e.edge.endMark,animated:e.edge.anim?.animate,startCard:e.edge.startCard||null,endCard:e.edge.endCard||null,start:e.start,end:e.end,segments:e.segments,labelRect:t?t.visualRect:null,labelLines:t?t.labelLines:[],self:!1})}for(let e of X)ft.push({id:e.edge.seq,from:e.edge.from,to:e.edge.to,fromFrame:!1,toFrame:!1,label:e.edge.label,style:e.edge.style,startArrow:e.edge.startArrow,endArrow:e.edge.endArrow,startMark:e.edge.startMark,endMark:e.edge.endMark,animated:e.edge.anim?.animate,startCard:null,endCard:null,start:e.start,end:e.end,segments:e.segments,labelRect:e.labelRect,labelLines:e.labelLines,self:!0});return{type:e.type,direction:p,width:ot,height:st,nodes:lt,labels:ut,frames:dt,edges:ft,ranks:[...H.entries()].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({rank:e,items:t.map(e=>e.id)})),warnings:b,model:e}}return e.layoutGraph=g,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/graph-route`],KChartUnits[`diagram/shapes`]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
KChartUnits["diagram/graph-parse"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o={nodes:30,edges:50,subgraphDepth:3,stateDepth:3},s={...o,nodes:300,edges:420},c=Object.keys(t.statusMarks),l=e=>{let t=String(e??``).trim();return t.length>=2&&(t[0]===`"`&&t.endsWith(`"`)||t[0]===`'`&&t.endsWith(`'`))&&(t=t.slice(1,-1)),t.replace(/\\"/g,`"`).replace(/\\'/g,`'`)};function u(e){return(0,t.labelText)(e).trim()}function d(e,t=!1){let n=[],r=0,i=!1,a=!1,o=0;for(let s=0;s<e.length;s+=1){let c=e[s];c===`"`&&e[s-1]!==`\\`?i=!i:i||(t&&c===`|`&&r===0&&(a=!a),a||(`[({`.includes(c)||t&&c===`>`&&/[^\s\-=]/.test(e[s-1]??``)&&e.indexOf(`]`,s)!==-1?r+=1:`]})`.includes(c)?r=Math.max(0,r-1):c===`;`&&r===0&&(n.push(e.slice(o,s)),o=s+1)))}return n.push(e.slice(o)),n}function f(e){let n=String(e||``).toUpperCase();return n===`TD`?{direction:`TB`}:t.DIRECTIONS.includes(n)?{direction:n}:{error:`不支持的方向:${e}`}}function p(e,t,n){let r=null;for(let i=t;i<e.length;i+=1){let a=e[i];if(r)a===r&&e[i-1]!==`\\`&&(r=null);else if(a===`"`||a===`'`&&(i===t||/[\s:]/.test(e[i-1])))r=a;else if(e.startsWith(n,i))return i}return-1}function m(e,t,n){let r=(r,i,a,o=!1)=>{let s=p(e,t+r,i);if(s<0)return{error:`unterminated`,end:e.length};let c=e.slice(t+r,s);if(o){if(a={"//":`lean-r`,"\\\\":`lean-l`,"/\\":`trap-b`,"\\/":`trap-t`}[c[0]+c.at(-1)],!a)return{error:`unterminated`,end:s+1};c=c.slice(1,-1)}let u=a===`rect`&&/^\|[^|]*\|/.exec(c);return u&&(c=c.slice(u[0].length)),{shape:a,props:!!u,label:n(l(c)),end:s+i.length}},i=e[t];return i===`[`?e[t+1]===`[`?r(2,`]]`,`subroutine`):e[t+1]===`(`?r(2,`)]`,`cylinder`):e[t+1]===`/`||e[t+1]===`\\`?r(1,`]`,`rect`,!0):r(1,`]`,`rect`):i===`(`?e.startsWith(`(((`,t)?r(3,`)))`,`dbl-circ`):e.startsWith(`(-`,t)?r(2,`-)`,`circle`):e[t+1]===`(`?r(2,`))`,`circle`):e[t+1]===`[`?r(2,`])`,`stadium`):r(1,`)`,`round`):i===`{`?e[t+1]===`{`?r(2,`}}`,`hexagon`):r(1,`}`,`diamond`):i===`>`?r(1,`]`,`odd`):null}function h(e,t,n){let r=t;for(;r<e.length&&/\s/.test(e[r]);)r+=1;if(r>=e.length)return null;if(e.startsWith(`@{`,r))return{error:`shape`,end:r+2};if(e[r]===`&`)return null;let i=r;for(;r<e.length;){let t=e[r];if(/\s/.test(t)||`[](){}|;<>@`.includes(t)||e.startsWith(`:::`,r)||/^(?:--|==|-\.|~~~)/.test(e.slice(r))||r>i&&/^[ox](?:--|==|-\.)/.test(e.slice(r)))break;r+=1}let a=e.slice(i,r);if(!a)return null;if(e.startsWith(`@{`,r)){let t=p(e,r+2,`}`);if(t<0)return{id:a,error:`unterminated`,end:e.length};let n=Object.create(null),i=e.slice(r+2,t),o=/\s*([\w-]+)\s*:\s*(\|[^\n]*\n[\s\S]*?(?=,\s*[\w-]+\s*:|$)|"(?:\\.|[^"\\])*"|'(?:''|[^'])*'|[^,]*?)\s*(?:,|$)/gy;for(;o.lastIndex<i.length&&i.slice(o.lastIndex).trim();){let e=o.exec(i);if(!e)return{id:a,error:`metadata`,end:t+1};let r=e[2];n[e[1]]=/^\|\s*\n/.test(r)?r.replace(/^\|[^\n]*\n/,``).split(`
|
|
2
|
+
`).map(e=>e.trim()).join(`
|
|
3
|
+
`):l(r).replace(/''/g,`'`)}return{id:a,metadata:n,end:t+1}}let o=null,s=null,c=null,u=m(e,r,n);u&&(u.error?c=u.error:(o=u.shape,s=u.label),r=u.end);let d=null;if(e.startsWith(`:::`,r)){r+=3;let t=r;for(;r<e.length&&!/[\s&;]/.test(e[r]);)r+=1;d=e.slice(t,r),d||(c=`class-empty`)}return{id:a,shape:o,label:s,cls:d,props:u?.props,error:c,end:r}}function g(e,t,n){let r=[],i=t;for(;;){for(;i<e.length&&/\s/.test(e[i]);)i+=1;if(i>=e.length)break;let t=h(e,i,n);if(!t)return null;for(r.push(t),i=t.end;i<e.length&&/\s/.test(e[i]);)i+=1;if(e[i]===`&`)i+=1;else break}return r.length?{tokens:r,end:i}:null}var _={"<":`point`,">":`point`,o:`circle`,x:`cross`},v=/^([<ox]?)(-{2,}|={2,}|-?\.+-|~{3,})([>ox]?)/,y=/"(?:\\.|[^"\\])*"|[^|]*/y;function b(e,t,n){let r=/^[^\s"\[\](){}|@]+@(?=[<xo.\-=~])/.exec(e.slice(t)),i=r?.[0].slice(0,-1)??null,a=t+(r?.[0].length??0),o=e.slice(a),s=v.exec(o),c=/^([<ox]?)(--|==|-\.)(?![-=.>])/.exec(o);if(!s&&!c)return null;let[,u,d,f=``]=s||c,p=null,m=a+(s||c)[0].length,h=d[0]===`~`?`invisible`:d.includes(`.`)?`dashed`:d[0]===`=`?`bold`:`solid`;if(c&&!o.slice(c[0].length).trimStart().startsWith(`|`)&&(!f||/[ox]/.test(f))){let e=o.slice(c[0].length),t=h===`dashed`?/\.+-[>ox]?/:h===`bold`?/={2,}[>ox]?/:/-{2,}[>ox]?/,n=/^\s*("(?:\\.|[^"\\])*"|[^"[\]{}|]+?)(?=\s*(?:--|==|\.+-))/.exec(e),r=n&&RegExp(`^\\s*(${t.source})`).exec(e.slice(n[0].length));if(r&&n[1].trim()){if(p=n[1],u=c[1],[,,d,f]=v.exec(r[1]),u&&_[u]!==_[f])return null;m=a+c[0].length+n[0].length+r[0].length}}if(!s&&p==null)return null;let g=m+/^\s*/.exec(e.slice(m))[0].length;if(e[g]===`|`&&p==null){y.lastIndex=g+1;let t=y.exec(e);if(e[y.lastIndex]!==`|`)return null;p=t[0],m=y.lastIndex+1}let b=h===`invisible`?`none`:_[f]||`none`,x=_[u]===b?b:`none`,S=h===`dashed`?d.split(`.`).length-1:d.length-1-(b===`none`)+(u&&x===`none`?1:0);return{id:i,style:h,startMark:x,endMark:b,startArrow:x!==`none`,endArrow:b!==`none`,extra:Math.max(0,Math.min(10,S)-1),label:p==null?null:n(l(p)),end:m}}function x(e,t,n){let r=e.trim(),i=/^([^\s[\]]+)\s*\[([\s\S]*)\]\s*$/.exec(r);return i?{id:i[1],title:n(l(i[2]))||i[1]}:/^(["'])/.test(r)&&/["']$/.test(r)?{id:t,title:n(l(r))}:{id:r&&!/\s/.test(r)?r:t,title:n(r)}}function S(e,r,i=`TB`,a,l){let d=l?s:o,p=l?e=>String(e).trim():u,m={type:`flowchart`,direction:`TB`,nodes:[],edges:[],subgraphs:[]},h=new Map,_=new Map,v=[],y=new Map,S=new Set;for(let t of e){let e=/^subgraph\b\s*(.*)$/.exec(t.text);if(!e)continue;let n=x(e[1],`subGraph${y.size}`,p);y.set(t,n),S.add(n.id)}let C=new Map,w=0,T=0,E=!1,D=!1,O=()=>v.length?v[v.length-1].id:null,k=(e,t,n)=>r.push({line:e,message:t,fix:n}),A=(e,t)=>c.includes(e)?e:(k(t,`未知分类:${e}`,`可用分类:${c.join(`、`)}`),null),j=new Set,M=(e,i)=>{if(e.error===`shape`||e.error===`metadata`)return k(i,`无法解析形状属性`,`使用 A@{ shape: rect, label: "文字" }`),null;if(e.metadata&&S.has(e.id)&&`view`in e.metadata)return C.set(e.id,e.metadata.view),{id:e.id,frame:!0};if(e.metadata){let{shape:o,label:s,...c}=e.metadata;if(o!==void 0&&(e.shape=(0,n.shapeName)(o),!e.shape))return k(i,`No such shape: ${o}`,`使用 Mermaid 的小写形状名称`),null;s!==void 0&&(e.label=p(s)),l&&`icon`in c&&(e.iconRef=c.icon,e.shape||=`icon`,e.iconPosition=c.pos,e.iconHeight=Number(c.h)>0?Math.min(256,Number(c.h)):48,e.iconForm=c.form),(`img`in c||!l&&`icon`in c)&&!j.has(`asset`)&&(j.add(`asset`),r.push((0,t.warning)(`IGNORED_ASSET`,a,i,`忽略图标或远程图片`,`Ignored icon or remote image`)));let u=Object.keys(c).filter(e=>![`img`,`icon`,`form`,`pos`,`w`,`h`,`constraint`].includes(e));for(let e of u)j.has(e)||(j.add(e),r.push((0,t.warning)(`IGNORED_CONFIG`,a,i,`忽略属性 ${e}`,`Ignored property ${e}`)))}if(e.error===`unterminated`)return k(i,`节点 ${e.id} 的形状没有结束的括号`,`补上缺少的 ]、) 或 }`),null;if(l&&e.cls&&l.addClasses(e.id,e.cls.split(`,`),i),e.props&&!j.has(`node-props`)&&(j.add(`node-props`),r.push((0,t.warning)(`IGNORED_CONFIG`,a,i,`忽略方框内的属性`,`Ignored bracketed node properties`))),e.error===`class-empty`&&k(i,`节点 ${e.id} 的 ::: 后面缺少分类名`,`可用分类:${c.join(`、`)}`),S.has(e.id)&&!e.shape)return{id:e.id,frame:!0};let o=h.get(e.id);if(o?o.parent==null&&O()!=null&&(o.parent=O()):(o={id:e.id,label:e.id,shape:`rect`,class:null,parent:O(),seq:w++,line:i},h.set(e.id,o),m.nodes.push(o),m.nodes.length===d.nodes+1&&!E&&(E=!0,k(i,`节点 ${m.nodes.length} 个,超过上限 ${d.nodes}`,`拆成总图和局部图`))),e.shape&&(o.shape=e.shape),e.iconRef&&(o.iconRef=e.iconRef,o.iconPosition=e.iconPosition,o.iconHeight=e.iconHeight,o.iconForm=e.iconForm,e.label==null&&!o.explicitLabel&&(o.label=``)),e.label!=null&&(o.label=e.label,o.explicitLabel=!0),!l&&e.cls){let t=A(e.cls,i);t&&(o.class=t)}return{id:o.id,node:o}},N=new Map,P=[],F=(e,t,n,r,i)=>{let a=i||null;if(a&&N.has(a)){let n=0;do a=`L_${e.id}_${t.id}_${n++}`;while(N.has(a))}let o={id:a,seq:T++,from:e.id,to:t.id,fromFrame:!!e.frame,toFrame:!!t.frame,label:n.label,style:n.style,startArrow:n.startArrow,endArrow:n.endArrow,startMark:n.startMark,endMark:n.endMark,extra:n.extra,line:r};a&&N.set(a,o),m.edges.push(o),m.edges.length===d.edges+1&&!D&&(D=!0,k(r,`连线 ${m.edges.length} 条,超过上限 ${d.edges}`,`拆成总图和局部图`))},I=0,L=!1;for(let t of e.slice(1)){let e=t.text,n=t.line,r=y.get(t);if(I){r?I+=1:e===`end`&&--I;continue}if(r){if(v.length+1>o.subgraphDepth){L||k(n,`子图嵌套 ${v.length+1} 层,超过上限 ${o.subgraphDepth} 层`,`拆成总图和局部图`),L=!0,I=1;continue}if(_.has(r.id)){v.push(_.get(r.id));continue}let e={id:r.id,title:r.title,parent:O(),depth:v.length+1,seq:w++,line:n};_.set(e.id,e),m.subgraphs.push(e),v.push(e);continue}if(e===`end`){if(!v.length){k(n,`end 没有对应的 subgraph`,`删除多余的 end`);continue}v.pop();continue}if(/^direction\b/i.test(e)){let t=e.replace(/^direction\b/i,``).trim().split(/\s/)[0],r=f(t);r.error?k(n,r.error,`方向用 TB、TD、BT、LR、RL`):v.length?v.at(-1).dir=r.direction:i=r.direction;continue}if(l?.accept(e,n))continue;if(/^(classDef|style|linkStyle)\b/i.test(e)){k(n,`不支持 ${e.split(/\s+/)[0]}`,`颜色由主题决定,删掉这一行;节点分类用 :::new 等`);continue}if(/^(click|call)\b/i.test(e)){k(n,`不支持 ${e.split(/\s+/)[0]}`,`删掉交互语句`);continue}if(/^class\s+/i.test(e)){let t=/^class\s+([^\s]+)\s+([A-Za-z_]\w*)\s*$/i.exec(e);if(!t){k(n,`class 写法不对`,`写成 class A,B ok`);continue}let r=A(t[2],n);for(let e of t[1].split(`,`).map(e=>e.trim()).filter(Boolean)){let t=h.get(e);if(t)r&&(t.class=r);else if(_.has(e))r&&(_.get(e).class=r);else{let t=M({id:e},n);t?.node&&r&&(t.node.class=r)}}continue}if(/^(classDiagram|stateDiagram|erDiagram|flowchart|graph)\b/i.test(e)){k(n,`无法解析的语句:${e}`,`检查 Mermaid 语法;图类型只能声明一次`);continue}let a=g(e,0,p);if(!a){k(n,`无法解析的语句:${e}`,`检查节点 id、形状括号与连线写法`);continue}let s=a.end,[c]=a.tokens;if(s===e.length&&a.tokens.length===1&&c.metadata&&(N.has(c.id)||[`animate`,`animation`,`curve`,`step`].some(e=>e in c.metadata))){P.push({...c,line:n});continue}let u=a.tokens.map(e=>M(e,n)).filter(Boolean);for(;s<e.length;){for(;s<e.length&&/\s/.test(e[s]);)s+=1;if(s>=e.length)break;let t=b(e,s,p);if(!t){k(n,`无法解析的连线:${e.slice(s)}`,`连线写成 -->、-.->、==>、--- 等;标签用 |文字| 或 -- 文字 -->`);break}s=t.end;let r=g(e,s,p);if(!r){k(n,`连线后面缺少节点`,`在连线运算符后写节点 id`);break}s=r.end;let i=r.tokens.map(e=>M(e,n)).filter(Boolean);for(let e of u)for(let r of i)F(e,r,t,n,e===u.at(-1)&&r===i[0]?t.id:null);u=i}}for(let{id:e,metadata:n,line:i}of P){let o=N.get(e);if(!o){r.push((0,t.warning)(`DIAGRAM_HINT`,a,i,`未找到连线 ${e}`,`Unknown edge ${e}`));continue}let{animate:s,animation:c,step:l,curve:u}=n;o.anim={animate:s==null?!!c:s===`true`,animation:c,step:Number(l)||null,curve:u},(o.anim.animate||l||u)&&!j.has(`edge-motion`)&&(j.add(`edge-motion`),r.push((0,t.warning)(`IGNORED_CONFIG`,a,i,`连线采用静态正交绘制`,`Edges use static orthogonal routes`)))}v.length&&!L&&k(e[e.length-1].line,`subgraph 没有结束的 end`,`补上 end`);for(let[e,t]of C){let n=_.get(e);n&&[`collapsed`,`expanded`].includes(t)&&(n.view=t)}for(let e of m.nodes)_.has(e.id)&&(e.conflict=!0);return m.direction=i,m.nodes.sort((e,t)=>e.seq-t.seq),m.subgraphs.sort((e,t)=>e.seq-t.seq),m}function C(e,n,r,i){let{text:a,line:o}=e[0];/^flowchart-elk\b/.test(a)&&n.push((0,t.warning)(`IGNORED_CONFIG`,r,o,`使用 KChart 布局代替 ELK`,`Using KChart layout instead of ELK`));let s=`TB`,c=/^(?:flowchart|graph)(?:-elk)?\b(?:\s+(.*))?$/.exec(a);if(c?.[1]){let t=c[1],n={"<":`RL`,">":`LR`,"^":`BT`,v:`TB`,BR:`TB`},r=Object.hasOwn(n,t)?{direction:n[t]}:t===t.toUpperCase()?f(t):null;r?.direction?s=r.direction:e=[e[0],{text:t,line:e[0].line},...e.slice(1)]}return S(e,n,s,r,i)}function w(e,t){let n=e.trim(),r=`state`,i=/<<(choice|fork|join)>>\s*$/i.exec(n);return i&&(r=i[1].toLowerCase(),n=n.slice(0,i.index).trim()),i=/\[\[(choice|fork|join)\]\]\s*$/i.exec(n),i&&(r=i[1].toLowerCase(),n=n.slice(0,i.index).trim()),i=/^"([\s\S]*)"\s+as\s+([^\s:]+)(?:\s*:\s*(.*))?$/i.exec(n),i?{id:i[2],label:t(i[1]),kind:r,desc:i[3]==null?null:t(i[3])}:{id:n,label:null,kind:r}}function T(e,n,r,i){let a=i?s:o,d=i?e=>String(e).trim():u,p=e[0].text,m={type:`state`,direction:`TB`,nodes:[],edges:[],subgraphs:[]},h=`TB`,g=/^stateDiagram(?:-v2)?\b\s*([A-Za-z]*)/i.exec(p);if(g&&g[1]){let t=f(g[1]);t.error?n.push({line:e[0].line,message:t.error,fix:`方向用 TB、TD、BT、LR、RL`}):h=t.direction}let _=new Map,v=new Map,y=[],b=new Set,x=new Map,S=e=>(x.has(e)||x.set(e,{label:null,desc:[],class:null}),x.get(e));for(let t of e){let e=/^state\s+(.+?)\s*\{\s*$/i.exec(t.text);if(!e)continue;let n=w(e[1],d);n.id&&b.add(n.id)}let C=0,T=0,E=!1,D=!1,O=new Map,k=[],A=()=>{let e=y.at(-1)?.id??null;return O.get(e)?.id??e},j=(e,t,r)=>n.push({line:e,message:t,fix:r}),M=(e,t)=>c.includes(e)?e:(j(t,`未知分类:${e}`,`可用分类:${c.join(`、`)}`),null),N=()=>m.nodes.filter(e=>!e.pseudo).length,P=(e,t,{label:n=null,kind:r=`state`}={})=>{if(b.has(e)||v.has(e))return null;let i=_.get(e);return i?(n!=null&&(i.label=n),r!==`state`&&(i.kind=r),i.parent==null&&A()!=null&&(i.parent=A())):(i={id:e,label:n??e,kind:r===`state`?`state`:r,desc:[],class:null,parent:A(),seq:C++,line:t},_.set(e,i),m.nodes.push(i),N()===a.nodes+1&&!E&&(E=!0,j(t,`状态 ${N()} 个,超过上限 ${a.nodes}`,`拆成总图和局部图`))),i},F=(e,t)=>{let n=A(),r=`@@${e}:${n??`@root`}`,i=_.get(r);return i||(i={id:r,label:``,kind:e,desc:[],class:null,parent:n,seq:C++,line:t,pseudo:!0},_.set(r,i),m.nodes.push(i)),i},I=(e,t,n,r,i=!1)=>{m.edges.push({seq:T++,from:e,to:t,fromFrame:!1,toFrame:!1,label:n==null?null:d(l(n)),style:i?`dashed`:`solid`,startArrow:!1,endArrow:!i,endMark:i?`none`:`barb`,extra:0,line:r}),m.edges.length===a.edges+1&&!D&&(D=!0,j(r,`连线 ${m.edges.length} 条,超过上限 ${a.edges}`,`拆成总图和局部图`))},L=new Set,R=0,z=!1;for(let a of e.slice(1)){let e=a.text,s=a.line;if(R){/^state\s+.+\{\s*$/i.test(e)?R+=1:e===`}`&&--R;continue}if(/^direction\b/i.test(e)){let t=f(e.replace(/^direction\b/i,``).trim());t.error?j(s,t.error,`方向用 TB、TD、BT、LR、RL`):y.length?(O.get(y.at(-1).id)??y.at(-1)).dir=t.direction:h=t.direction;continue}if(/^\}\s*$/.test(e)){if(!y.length){j(s,`} 没有对应的 state {`,`删除多余的 }`);continue}y.pop();continue}if(e===`--`){let e=y.at(-1);if(!e){j(s,`-- 只能放在复合状态中`,`将分区放入 state A { … }`);continue}let t=()=>{let t={id:`@@region:${C}`,title:``,parent:e.id,depth:e.depth+1,seq:C++,line:s,kind:`divider`};return m.subgraphs.push(t),O.set(e.id,t),t};if(!O.has(e.id)){let n=t();for(let t of[...m.nodes,...m.subgraphs])t!==n&&t.parent===e.id&&(t.parent=n.id)}t();continue}if(/^note\b/i.test(e)){let t=/^note\s+(left|right)\s+of\s+([^\s:]+)(?:\s*:\s*([\s\S]*)|\n([\s\S]*))$/i.exec(e),n=/^note\s+"([\s\S]*)"\s+as\s+(\S+)$/i.exec(e);if(!t&&!n){j(s,`无法解析状态图 note`,`使用 note left of A: 说明,或用 end note 结束多行说明`);continue}let r=n?n[2]:`@@note:${C}`;t&&P(t[2],s);let i=P(r,s,{kind:`note`,label:d(t?t[3]??t[4]:n[1])});i&&t&&(k.push({node:i,target:t[2]}),t[1].toLowerCase()===`left`?I(r,t[2],null,s,!0):I(t[2],r,null,s,!0));continue}if(/^(hide\s+empty\s+description|scale\s+\d+(?:\.\d+)?\s+width)$/i.exec(e)){let i=e.split(/\s/)[0].toLowerCase();L.has(i)||(L.add(i),n.push((0,t.warning)(`IGNORED_CONFIG`,r,s,`忽略状态图 ${i} 语句`,`Ignored state diagram ${i} statement`)));continue}if(i?.accept(e,s))continue;if(/^(classDef|style|linkStyle)\b/i.test(e)){j(s,`不支持 ${e.split(/\s+/)[0]}`,`颜色由主题决定,删掉这一行;节点分类用 :::warn 等`);continue}if(/^(click|call)\b/i.test(e)){j(s,`不支持 ${e.split(/\s+/)[0]}`,`删掉交互语句`);continue}if(/^class\s+/i.test(e)){let t=/^class\s+([^\s]+)\s+([A-Za-z_]\w*)\s*$/i.exec(e);if(!t){j(s,`class 写法不对`,`写成 class A danger`);continue}let n=M(t[2],s);for(let e of t[1].split(`,`).map(e=>e.trim()).filter(Boolean)){if(v.has(e)){n&&(v.get(e).class=n);continue}if(b.has(e)){n&&(S(e).class=n);continue}let t=_.get(e)||P(e,s);t&&n&&(t.class=n)}continue}if(/^state\b/i.test(e)){let t=/^state\s+(.+?)\s*\{\s*$/i.exec(e);if(t){let e=w(t[1],d);if(!e.id){j(s,`state { 缺少 id`,`写成 state A {`);continue}if(v.has(e.id)){j(s,`复合状态 id 重复:${e.id}`,`换一个 id`);continue}if(y.length+1>o.stateDepth){z||j(s,`复合状态嵌套 ${y.length+1} 层,超过上限 ${o.stateDepth} 层`,`拆成平级状态或拆成两张图`),z=!0,R=1;continue}let n=_.get(e.id),r=S(e.id),i=e.label||r.label,a=i||r.desc[0];if(!a&&n&&n.label!==n.id&&(a=n.label),n){_.delete(e.id);let t=m.nodes.indexOf(n);t>=0&&m.nodes.splice(t,1)}let c={id:e.id,title:a||e.id,parent:A(),depth:y.length+1,seq:C++,line:s,kind:`composite`,desc:[...e.desc==null?[]:[e.desc],...r.desc.slice(+!i)],class:r.class};v.set(c.id,c),m.subgraphs.push(c),y.push(c);continue}let n=w(e.replace(/^state\b/i,``),d);if(!n.id){j(s,`state 缺少 id`,`写成 state A 或 state "名称" as A`);continue}if(b.has(n.id)){n.label&&(S(n.id).label=n.label,v.has(n.id)&&(v.get(n.id).title=n.label));continue}let r=P(n.id,s,{label:n.label,kind:n.kind});r&&n.desc!=null&&r.desc.push(n.desc);continue}let c=/^(.+?)\s*-->\s*(.+)$/.exec(e);if(c){let e=e=>{let t=e.trim(),n=null,r=t.indexOf(`:::`);return r>=0&&(n=t.slice(r+3).trim(),t=t.slice(0,r).trim()),{id:t,cls:n}},t=e(c[1]),n=/(?<!:):(?!:)/.exec(c[2])?.index??-1,r=e(n<0?c[2]:c[2].slice(0,n)),a=n<0?null:c[2].slice(n+1).trim();if(!t.id||!r.id){j(s,`状态转移缺少起点或终点`,`写成 A --> B : 说明`);continue}if(i)for(let e of[t,r])e.cls&&i.addClasses(e.id,e.cls.split(`,`),s);let o=!i&&t.cls?M(t.cls,s):null,l=!i&&r.cls?M(r.cls,s):null,u,d;if(t.id===`[*]`)u=F(`start`,s).id;else{let e=P(t.id,s);e&&o&&(e.class=o),u=t.id}if(r.id===`[*]`)d=F(`end`,s).id;else{let e=P(r.id,s);e&&l&&(e.class=l),d=r.id}I(u,d,a,s);continue}let l=/^([^\s:]+)\s*:\s*(.+)$/.exec(e);if(l){let e=l[1],t=d(l[2]);if(v.has(e))v.get(e).desc.push(t);else if(b.has(e))S(e).desc.push(t);else{let n=_.get(e)||P(e,s);n&&n.desc.push(t)}continue}if(/^(stateDiagram|flowchart|graph|erDiagram)\b/i.test(e)){j(s,`图类型只能声明一次`,`删掉重复的声明`);continue}let u=i&&/^([^\s:{}]+):::(\S+)$/.exec(e);u?(P(u[1],s),i.addClasses(u[1],u[2].split(`,`),s)):/^[^\s:{}]+$/.test(e)?P(e,s):j(s,`无法解析的语句:${e}`,`检查状态名、转移箭头与 : 说明的写法`)}for(let{node:e,target:t}of k)e.parent=(_.get(t)??v.get(t))?.parent??null;let B=new Set([...m.nodes,...m.subgraphs].map(e=>e.parent));m.subgraphs=m.subgraphs.filter(e=>e.kind!==`divider`||B.has(e.id));for(let e of m.nodes)e.kind===`state`&&e.desc.length===1&&e.label===e.id&&(e.label=e.desc.pop());y.length&&!z&&j(e[e.length-1].line,`复合状态没有结束的 }`,`补上 }`);for(let e of m.edges)e.fromFrame=v.has(e.from)&&!_.has(e.from),e.toFrame=v.has(e.to)&&!_.has(e.to);return m.direction=h,m.nodes.sort((e,t)=>e.seq-t.seq),m.subgraphs.sort((e,t)=>e.seq-t.seq),m}function E(e,t){let n=e[0].text,r={type:`er`,direction:`TB`,nodes:[],edges:[],subgraphs:[]},i=`TB`,a=/^erDiagram\b\s*([A-Za-z]*)/i.exec(n);if(a&&a[1]){let n=f(a[1]);n.error?t.push({line:e[0].line,message:n.error,fix:`方向用 TB、TD、BT、LR、RL`}):i=n.direction}let s=new Map,c=0,d=0,p=!1,m=!1,h=(e,n,r)=>t.push({line:e,message:n,fix:r}),g=(e,t,n=null)=>{let i=s.get(e);return i?n&&(i.label=n):(i={id:e,label:n||e,kind:`er`,shape:`er`,fields:[],class:null,parent:null,seq:c++,line:t},s.set(e,i),r.nodes.push(i),r.nodes.length===o.nodes+1&&!p&&(p=!0,h(t,`实体 ${r.nodes.length} 个,超过上限 ${o.nodes}`,`拆成总图和局部图`))),i},_=(e,t,n)=>{let r=t.trim();if(!r)return;let i=null,a=/"([^"]*)"\s*$/.exec(r);a&&(i=a[1],r=r.slice(0,a.index).trim());let o=r.split(/\s+/);if(o.length<2){h(n,`实体 ${e.id} 的属性写法不对:${t}`,`写成 type name PK|FK|UK "注释"`);return}let s=o.slice(2).join(` `).split(`,`).map(e=>e.trim()).filter(Boolean);for(let e of s)[`PK`,`FK`,`UK`].includes(e)||h(n,`属性键只能是 PK、FK、UK,收到:${e}`,`删掉未知的键标记,或改成 PK/FK/UK`);e.fields.push({type:o[0],name:o[1],keys:s.filter(e=>[`PK`,`FK`,`UK`].includes(e)),comment:i})},v=(e,t,n,i,a,s,c)=>{g(e,c),g(t,c),r.edges.push({seq:d++,from:e,to:t,fromFrame:!1,toFrame:!1,label:s==null?null:u(l(s)),startCard:n,endCard:i,style:a===`..`?`dashed`:`solid`,startArrow:!1,endArrow:!1,extra:0,line:c}),r.edges.length===o.edges+1&&!m&&(m=!0,h(c,`关系 ${r.edges.length} 条,超过上限 ${o.edges}`,`拆成总图和局部图`))};for(let t=1;t<e.length;t+=1){let n=e[t],r=n.text,a=n.line;if(/^direction\b/i.test(r)){let e=f(r.replace(/^direction\b/i,``).trim());e.error?h(a,e.error,`方向用 TB、TD、BT、LR、RL`):i=e.direction;continue}if(/^(classDef|style|linkStyle)\b/i.test(r)){h(a,`ER 图不支持 ${r.split(/\s+/)[0]}`,`颜色由主题决定,删掉这一行`);continue}let o=/^([^\s{}[\]]+)\s*(?:\["([^"]*)"\])?\s*\{\s*$/.exec(r);if(o){let n=g(o[1],a,o[2]||null),r=!1;for(t+=1;t<e.length;t+=1){let i=e[t];if(/^\}\s*$/.test(i.text)){r=!0;break}_(n,i.text,i.line)}r||h(a,`实体 ${n.id} 的属性块没有结束的 }`,`补一个 }`);continue}let s=/^([^\s{}[\]]+)\s*\["([^"]*)"\]\s*$/.exec(r);if(s){g(s[1],a,s[2]);continue}let c=/^(\S+)\s+(\|\||\|o|\}o|\}\|)\s*(--|\.\.)\s*(\|\||o\||o\{|\|\{)\s+(\S+)\s*(?::\s*(.*))?$/.exec(r);c?v(c[1],c[5],c[2],c[4],c[3],c[6],a):/^\}\s*$/.test(r)?h(a,`没有对应的实体 {`,`删除多余的 }`):/^(erDiagram|flowchart|graph|stateDiagram)\b/i.test(r)?h(a,`图类型只能声明一次`,`删掉重复的声明`):h(a,`无法解析的语句:${r}`,`实体写成 ENTITY { … };关系写成 A ||--o{ B : 标签`)}return r.direction=i,r.nodes.sort((e,t)=>e.seq-t.seq),r}function D(e,{direction:n=`TB`}={}){let r=[],i=t.DIRECTIONS.includes(n)?n:`TB`,a=S([{text:`flowchart`,line:0},...e],r,i);return{ok:r.length===0,errors:r,model:a}}function O(e,t,n){let r=n?.startsWith(`statediagram`),i=n===`flowchart`,a=String(e??``).replace(/\r\n?/g,`
|
|
4
|
+
`).split(`
|
|
5
|
+
`),o=[];for(let e=0;e<a.length;e+=1){let n=a[e],s=t+e;if(i)for(let t of n.matchAll(/"(?:\\.|[^"\\])*"|'(?:''|[^'])*'|@\{/g)){if(t[0]!==`@{`||p(n,t.index+2,`}`)>=0)continue;let r=a.slice(e).join(`
|
|
6
|
+
`),i=p(r,t.index+2,`}`);i>=0&&(e+=r.slice(0,i).split(`
|
|
7
|
+
`).length-1,n=r.slice(0,i+1)+a[e].slice(i-r.lastIndexOf(`
|
|
8
|
+
`,i)));break}if(r&&/^\s*note\s+(left|right)\s+of\s+[^\s:]+\s*$/i.test(n)){let t=a.findIndex((t,n)=>n>e&&/^\s*end\s+note\s*$/i.test(t));if(t!==-1){o.push({text:[n.trim(),...a.slice(e+1,t).map(e=>e.trim())].join(`
|
|
9
|
+
`),line:s}),e=t;continue}}for(let e of d(n,i)){let t=e.trim();r&&/^state\s+.+?\{\s*\}\s*$/i.test(t)?o.push({text:t.slice(0,-1).trim(),line:s},{text:`}`,line:s}):t&&!/^\s*%%/.test(t)&&!/^acc(Title|Descr)\s*:/i.test(t)&&o.push({text:t,line:s})}}return o}function k(e,n={}){let o=String(n.kind||``).toLowerCase(),s=String(n.header||``),c=Number.isFinite(n.headerLine)?n.headerLine:Math.max(1,(n.firstLine||2)-1),l=Number.isFinite(n.firstLine)?n.firstLine:c+1,u=[...O(s,c),...O(e,l,o)],d=[],f=n.syntax===`mermaid`&&o!==`erdiagram`?(0,r.presentation)(n):null;if(!u.length)return{model:null,errors:[{line:c,column:1,message:`图源码为空`,fix:`写 flowchart、stateDiagram-v2 或 erDiagram 开头的图`}]};let p=u[0].text,m;if(o===`flowchart`?m=C(u,d,n.lang,f):o===`statediagram-v2`||o===`statediagram`?m=T(u,d,n.lang,f):o===`erdiagram`?m=E(u,d):d.push({line:u[0].line,column:1,message:`不支持的图类型:`+p.split(/\s+/)[0],fix:`使用 flowchart、stateDiagram-v2 或 erDiagram 图型`}),m&&f){m.mermaid=!0;let e=new Set,r=t=>{let n=`${t.code}:${t.message}`;e.has(n)||(e.add(n),d.push(t))},o=(e,t,a)=>{let o=(0,i.normalizeLabel)(e,{lang:n.lang,line:t});return o.diagnostics.forEach(r),a&&o.icon&&(a.icon??=o.icon),o.text};for(let e of[...m.nodes,...m.subgraphs]){e.class=f.statusOf(e.id),e.link=f.linkOf(e.id),e.iconRef&&(e.icon=(0,a.resolveIconRef)(e.iconRef),e.icon||r((0,t.warning)(`IGNORED_ASSET`,n.lang,e.line,`未知图标 ${e.iconRef}`,`Unknown icon ${e.iconRef}`)));let i=Object.hasOwn(e,`title`)?`title`:`label`;e[i]=o(e[i],e.line,e),e.desc&&=e.desc.map(t=>o(t,e.line))}for(let e of m.edges)e.status=f.edgeStatusOf(e.seq)??(e.id?f.statusOf(e.id):null),e.label!=null&&(e.label=o(e.label,e.line,e));d.push(...f.diagnostics())}return{model:m||null,errors:d.map(e=>({column:1,...e}))}}return e.parseFlow=D,e.parseGraph=k,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/shapes`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/label`],KChartUnits[`core/icons`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/graph-route"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=12,r=8,i=4,a=[`top`,`right`,`bottom`,`left`],o=e=>e===`top`||e===`bottom`,s=(e,t)=>Math.abs(e.x-t.x)+Math.abs(e.y-t.y),c=({x:e,y:t,w:n,h:r},i)=>({x:e-i,y:t-i,w:n+i*2,h:r+i*2}),l=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h;function u(e,t,n){let r=0,i=1,a=t.x-e.x;if(Math.abs(a)<1e-8){if(e.x<=n.x||e.x>=n.x+n.w)return!1}else{let t=(n.x-e.x)/a,o=(n.x+n.w-e.x)/a;if(r=Math.max(r,Math.min(t,o)),i=Math.min(i,Math.max(t,o)),r>=i)return!1}let o=t.y-e.y;if(Math.abs(o)<1e-8){if(e.y<=n.y||e.y>=n.y+n.h)return!1}else{let t=(n.y-e.y)/o,a=(n.y+n.h-e.y)/o;if(r=Math.max(r,Math.min(t,a)),i=Math.min(i,Math.max(t,a)),r>=i)return!1}return r<i}function d(e,n,r,i=0){let a=o(n),s=n===`top`||n===`left`?-1:1,c=!e.frame&&(r===`flowchart`?(0,t.flowOutlineName)(e.shape):e.kind===`choice`?`diam`:e.kind===`start`||e.kind===`end`?`circle`:e.kind===`state`?`rounded`:e.kind===`note`?`note`:null),l=a?{x:e.w/2,y:s<0?0:e.h}:{x:s<0?0:e.w,y:e.h/2};a?l.x+=e.w*i:l.y+=e.h*i;let u=c?(0,t.outlinePort)((0,t.shapeOutline)(c,e.w,e.h,e.direction),n,a?l.x:l.y):l,d={x:e.x+u.x,y:e.y+u.y};return{port:d,stub:a?{x:d.x,y:e.y+(s<0?-10:e.h+10)}:{x:e.x+(s<0?-10:e.w+10),y:d.y}}}function f(e,t){return{p0:e,c1:e,c2:t,p1:t}}function p(e,t,n,r,i=1,a=4){let o=(e,t)=>Math.abs(e-t)<.01,s=o(e.x,t.x)&&o(n.x,r.x)&&Math.abs(e.x-n.x)<i-.001?`y`:o(e.y,t.y)&&o(n.y,r.y)&&Math.abs(e.y-n.y)<i-.001?`x`:null;return s&&Math.min(Math.max(e[s],t[s]),Math.max(n[s],r[s]))-Math.max(Math.min(e[s],t[s]),Math.min(n[s],r[s]))>a}function m(e,t){let n=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);return n(e.p0,e.p1,t.p0)*n(e.p0,e.p1,t.p1)<-1e-6&&n(t.p0,t.p1,e.p0)*n(t.p0,t.p1,e.p1)<-1e-6}function h(e,t,n,r,o,h,g,_,v,y,b,x=[],S={x:[],y:[]}){let C=null,w=1/0,T={};for(let[e,t]of[[`x`,`w`],[`y`,`h`]]){let i=y.filter(({p0:t,p1:n})=>t[e]===n[e]).flatMap(({p0:t})=>[t[e]-8,t[e]+8]),a=v?r.filter(({p0:t,p1:n})=>Math.abs(t[e]-n[e])<.01).flatMap(({p0:t})=>[t[e]-12,t[e]+12]):[];T[e]=[...new Set([6,h[t]-6,...a,...i,...n.flatMap(n=>[n[e]-1,n[e]+n[t]+1])])].filter(e=>e>=4&&e<=h[t]-4)}let E=new Map,D=(e,t,n,r)=>{let i=(e[n]+t[n])/2;if(!E.has(n+i)){let e=i>=4&&i<=h[r]-4&&!T[n].includes(i)?[i,...T[n]]:T[n].slice();E.set(n+i,e.sort((e,t)=>Math.abs(e-i)-Math.abs(t-i)||e-t).slice(0,28))}return E.get(n+i)},O=(e,t)=>!n.some(n=>u(e,t,n)),k=c(e,4),A=c(t,4),j=(a,c,T,E,j)=>{let{port:M,stub:N}=d(e,a,o,T),{port:P,stub:F}=d(t,c,o,E);if(!O(M,N)||!O(F,P)||b.some(e=>s(e.end,P)<8)||s(M,N)+s(N,F)+s(F,P)>=w)return;let I=a=>{let o=[M,N,...a,F,P].filter((e,t,n)=>!t||s(e,n[t-1])>.001),c=0;for(let e=1;e<o.length;e++){let t=o[e-2],n=o[e-1],r=o[e];if(t&&(t.x===n.x&&n.x===r.x||t.y===n.y&&n.y===r.y)&&s(t,n)+s(n,r)>s(t,r)+.001)return;c+=s(n,r)}let d=o.filter((e,t)=>!t||t===o.length-1||Math.abs(s(o[t-1],e)+s(e,o[t+1])-s(o[t-1],o[t+1]))>.001||o[t-1].x!==o[t+1].x&&o[t-1].y!==o[t+1].y),h=c+(d.length-2)*16;if(h>=w)return;for(let e=2;e<o.length-1;e++)if(u(o[e-1],o[e],k)||u(o[e-1],o[e],A)||!O(o[e-1],o[e]))return;let S=d.slice(1).map((e,t)=>f(d[t],e));if(S.some(({p0:e,p1:t})=>r.some(n=>p(e,t,n.p0,n.p1,v?12:1,v?8:4))||x.some(n=>p(e,t,n.p0,n.p1,i,4))||y.some(n=>p(e,t,n.p0,n.p1,8,12))||b.some(n=>n.segments.some(n=>m({p0:e,p1:t},n)||p(e,t,n.p0,n.p1,8,8)))))return;let T=g;if(g){let r=e=>({...g,x:e.x-g.w/2,y:e.y-g.h/2}),i=r=>![e,t,...n].some(e=>l(r,e)),a=d.slice(1).map((e,t)=>[d[t],e]).sort(([e,t],[n,r])=>s(n,r)-s(e,t));T=null;for(let[e,t]of a){for(let n of[.5,.35,.65]){let a=r({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n});if(i(a)){T=a;break}}if(T)break}if(!T&&_&&i(g)&&(T=g),!T)return}C={start:M,end:P,labelRect:T,segments:S},w=h};(N.x===F.x||N.y===F.y)&&I([]),I([{x:N.x,y:F.y}]),I([{x:F.x,y:N.y}]);let L=s(M,N)+s(F,P)-.01,R=D(N,F,`x`,`w`),z=D(N,F,`y`,`h`);for(let e of R)L+Math.abs(N.x-e)+Math.abs(N.y-F.y)+Math.abs(e-F.x)<w&&I([{x:e,y:N.y},{x:e,y:F.y}]);for(let e of z)L+Math.abs(N.y-e)+Math.abs(N.x-F.x)+Math.abs(e-F.y)<w&&I([{x:N.x,y:e},{x:F.x,y:e}]);if(j&&!C){let e=(e,t,n)=>D(e,e,t,n).slice(0,7),t=e(N,`x`,`w`),n=e(F,`x`,`w`),r=e(N,`y`,`h`),i=e(F,`y`,`h`),a=(e,t,n)=>[...new Set([...S[t].filter(e=>e>=4&&e<=h[n]-4),...e.slice(0,8)])];for(let e of a(z,`y`,`h`))for(let r of t)for(let t of n)L+Math.abs(N.x-r)+Math.abs(N.y-e)+Math.abs(r-t)+Math.abs(e-F.y)+Math.abs(t-F.x)>=w||I([{x:r,y:N.y},{x:r,y:e},{x:t,y:e},{x:t,y:F.y}]);for(let e of a(R,`x`,`w`))for(let t of r)for(let n of i)L+Math.abs(N.y-t)+Math.abs(N.x-e)+Math.abs(t-n)+Math.abs(e-F.x)+Math.abs(n-F.y)>=w||I([{x:N.x,y:t},{x:e,y:t},{x:e,y:n},{x:F.x,y:n}])}};for(let e of a)for(let t of a)j(e,t,0,0,!1);for(let e of[-.2,.2,-.35,.35]){if(C)break;for(let t of a)for(let n of a)for(let[r,i]of[[e,0],[0,e],[e,e]])j(t,n,r,i,!1)}for(let e of[0,-.2,.2]){if(C)break;for(let t of a)for(let n of a)j(t,n,e,e,!0)}return C}var g=({p0:e,c1:t,c2:n,p1:r},i)=>{let a=1-i,o=o=>a**3*e[o]+3*a*a*i*t[o]+3*a*i*i*n[o]+i**3*r[o];return{x:o(`x`),y:o(`y`)}};function _({x:e,y:t,w:n,h:r}){let i={x:e,y:t},a={x:e+n,y:t},o={x:e+n,y:t+r},s={x:e,y:t+r};return[f(i,a),f(a,o),f(o,s),f(s,i)]}function v(e,t=new Map){let n=new Map(e.nodes.map(e=>[e.id,e])),r=new Map(e.frames.map(e=>[e.id,{...e,frame:!0}])),i=e=>n.get(e)??r.get(e),a=e=>{let t=new Set([e.id]);for(let n=e.parent;n;n=r.get(n)?.parent)t.add(n);return t},o=n.size>30,l=new Set(t.keys()),d=[],f=e.direction,v=e=>f===`LR`?e.x:f===`RL`?-e.x:f===`BT`?-e.y:e.y,y=e=>e.reversed||e.start&&e.end&&v(e.start)>v(e.end)+1,b=[...e.edges].sort((e,t)=>Number(!!y(e))-Number(!!y(t))),x=[...r.values()].flatMap(_),S=new Map([...n.values()].map(e=>[e.id,_(e)]));for(let f of b){if(f.style===`invisible`||f.self||!f.segments?.length)continue;let v=t.get(f.id),b=i(v?.from??f.from),C=i(v?.to??f.to);if(!b||!C||b===C)continue;let w=new Set([...a(b),...a(C)]),T=[...n.values(),...r.values()].filter(e=>!w.has(e.id)),E=!!y(f),D=T.map(e=>c(e,e.frame?5:8)),O=[...r.values()].flatMap(e=>e.titleRect&&e.titleRect.w&&e.titleRect.h?[c(e.titleRect,5)]:[]),k=[...T.map(e=>c(e,1.5)),...O],A=()=>e.edges.filter(e=>e!==f&&e.style!==`invisible`&&!l.has(e.id)).flatMap(e=>e.segments),j=E?A():null,M=C.kind===`end`?e.edges.filter(e=>e!==f&&e.to===C.id&&e.end&&(s(e.start,e.end)>s(f.start,f.end)||s(e.start,e.end)===s(f.start,f.end)&&e.id<f.id)):[],N=(e,t)=>S.get(t.id)?.some(t=>p(e.p0,e.p1,t.p0,t.p1,8,8)),P=!!v||f.segments.some(e=>T.some(t=>!t.frame&&N(e,t))||j?.some(t=>p(e.p0,e.p1,t.p0,t.p1,12,8))||x.some(t=>p(e.p0,e.p1,t.p0,t.p1,8,12))||M.some(t=>t.segments.some(t=>m(e,t)||p(e.p0,e.p1,t.p0,t.p1,8,8))));if(!P)for(let e of f.segments){let t=e.p0;for(let n=1;n<=5;n++){let r=g(e,n/5);if(k.some(e=>u(t,r,e))){P=!0;break}t=r}if(P)break}if(!P&&o){let e=[..._(b),..._(C),...d];P=f.segments.some(t=>e.some(e=>p(t.p0,t.p1,e.p0,e.p1)))}if(!P){o&&d.push(...f.segments);continue}let F=e.edges.filter(e=>e!==f&&e.labelRect).map(e=>c(e.labelRect,2)),I=E?[]:e.edges.filter(e=>e!==f&&e.style!==`invisible`&&!l.has(e.id)&&!y(e)).flatMap(e=>e.segments),L={x:[],y:[]};for(let{p0:e,p1:t}of f.segments)Math.abs(e.x-t.x)<.01&&L.x.push(e.x),Math.abs(e.y-t.y)<.01&&L.y.push(e.y);let R=t=>h(b,C,[...D,...O,...F],j??A(),e.type,{w:e.width,h:e.height},f.labelRect,!v,E,x,M,t,L),z=I.length&&R(I)||R([]);z&&(l.delete(f.id),Object.assign(f,z,{from:b.id,to:C.id,fromFrame:b.frame===!0,toFrame:C.frame===!0})),o&&d.push(...f.segments)}return e}function y(e,n){let{nodes:r,frames:i,edges:a,width:o,height:s}=e,d=i.map(e=>e.titleRect).filter(e=>e?.w&&e.h),p=a.map(e=>e.style===`invisible`?[]:e.segments.flatMap(e=>[`x`,`y`].some(t=>[e.c1,e.c2,e.p1].every(n=>Math.abs(n[t]-e.p0[t])<1e-8))?[e]:Array.from({length:12},(t,n)=>f(g(e,n/12),g(e,(n+1)/12))))),m=(e,t)=>e.some(e=>u(e.p0,e.p1,t)),h=e=>e.x>=0&&e.y>=0&&e.x+e.w<=o&&e.y+e.h<=s;if(a.forEach((t,n)=>{let i=t.labelRect;if(!i||!p[n].length)return;let o={x:i.x+i.w/2,y:i.y+i.h/2},s=[...r,...d,...a.flatMap(e=>e!==t&&e.labelRect?[e.labelRect]:[])],c=null,u=1/0;for(let{p0:e,p1:t}of p[n]){let r=t.x-e.x,a=t.y-e.y,d=Math.hypot(r,a);if(!d)continue;let f=Math.min(1,Math.max(0,((o.x-e.x)*r+(o.y-e.y)*a)/(d*d))),g=Math.min(128,Math.ceil(d/5));for(let t of[f,...Array.from({length:g},(e,t)=>(t+.5)/g)]){let d={x:e.x+r*t,y:e.y+a*t},f=Math.hypot(d.x-o.x,d.y-o.y);if(f>=u)continue;let g={...i,x:d.x-i.w/2,y:d.y-i.h/2};!h(g)||s.some(e=>l(g,e))||p.some((e,t)=>t!==n&&m(e,g))||(c=g,u=f)}}if(c){t.labelRect=c;let n=e.labels.find(e=>e.edge===t.id);n&&Object.assign(n,c)}}),e.type===`flowchart`)for(let e of r){let i=(0,t.shapeGlyphBox)((0,t.flowOutlineName)(e.shape),e.w,e.h,e.direction);if(!i||!e.lines.length)continue;let o=Math.max(...e.lines.map(e=>n(e,{size:14,weight:600}))),s=e.lines.length*19,u=t=>({x:t,y:e.y+(e.h-s)/2,w:o,h:s}),d=t=>!h(t)||p.some(e=>m(e,c(t,2)))||r.some(n=>n!==e&&l(t,n))||a.some(e=>e.labelRect&&l(t,e.labelRect));e.glyphLabelLeft=d(u(e.x+i.x+i.w+8))&&!d(u(e.x+i.x-8-o))}}return e.TRACK_CLEAR=r,e.TRACK_GAP=n,e.placeGraphLabels=y,e.repairRoutes=v,e})({},KChartUnits[`diagram/shapes`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/graph"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=(e,t,n={},r)=>({...e.path(t,n),...r?{meta:r}:{}}),s=(e,t,n,r,i,a)=>e.text(t,n,r,{"dominant-baseline":`central`,...i,meta:a}),c=(e,t,n,r={})=>({...e.el(`g`,r,t),...n?{meta:n}:{}}),l=(e,t)=>t?{...e.el(`title`),text:String(t)}:null,u=e=>e.map(([e,t])=>`${e},${t}`).join(` `);function d(e,t){let n=(t,n,r=`M0 0 L8 4 L0 8 Z`)=>({tag:`marker`,attrs:{id:t,viewBox:`0 0 8 8`,refX:8,refY:4,markerWidth:8,markerHeight:8,markerUnits:`userSpaceOnUse`,orient:`auto-start-reverse`},children:[e.path(r,{fill:n})]}),r=[`circle`,4,8,3],i=[`line`,`M4 2 V14`],a=[`line`,`M12 2 V14`],o=[`line`,`M15 2 L9 8 L15 14 M9 8 H15`],s=Object.entries({"zero-one":[r,a],"exactly-one":[i,a],"zero-many":[r,o],"one-many":[i,o]}).map(([n,r])=>({tag:`marker`,attrs:{id:`graph-card-${n}`,viewBox:`0 0 16 16`,refX:16,refY:8,markerWidth:16,markerHeight:16,markerUnits:`userSpaceOnUse`,orient:`auto-start-reverse`},children:r.map(([n,...r])=>n===`circle`?e.circle(...r,{fill:t.surface,stroke:t.fg4,"stroke-width":1.4}):e.path(r[0],{fill:`none`,stroke:t.fg4,"stroke-width":1.4}))}));return e.el(`defs`,{},[n(`graph-arrow`,t.fg4),n(`graph-arrow-bold`,t.fg3),n(`graph-barb`,t.fg4,`M0 0 L8 4 L0 8 L2 4 Z`),...s,...[`circle`,`cross`].map(n=>({tag:`marker`,attrs:{id:`graph-${n}`,viewBox:`0 0 10 10`,refX:9,refY:5,markerWidth:10,markerHeight:10,markerUnits:`userSpaceOnUse`,orient:`auto-start-reverse`},children:[n===`circle`?e.circle(5,5,3.375,{fill:t.surface,stroke:t.fg4,"stroke-width":1.25}):e.path(`M2 2 L8.5 8 M2 8 L8.5 2`,{fill:`none`,stroke:t.fg4,"stroke-width":1.25})]}))])}function f(e){return e===`|o`||e===`o|`?`zero-one`:e===`||`?`exactly-one`:e===`}o`||e===`o{`?`zero-many`:e===`}|`||e===`|{`?`one-many`:null}function p(e,t,n,r){if(!e.segments?.length||e.style===`invisible`)return null;let a=(0,i.cubicPath)(e.segments),s=t.get(e.from)?.kind===`er`||t.get(e.to)?.kind===`er`,u=e.style===`bold`,d={fill:`none`,stroke:r[e.status]??(u?r.fg3:r.fg4),"stroke-width":u?2:1.25,...e.style===`dashed`||e.animated?{"stroke-dasharray":`5 4`}:{}};if(s){let t=e.startCard&&f(e.startCard),n=e.endCard&&f(e.endCard);t&&(d[`marker-start`]=`url(#graph-card-${t})`),n&&(d[`marker-end`]=`url(#graph-card-${n})`)}else for(let t of[`start`,`end`]){let n=e[`${t}Mark`]??(e[`${t}Arrow`]?`point`:`none`);n!==`none`&&(d[`marker-${t}`]=`url(#graph-${n===`point`?`arrow${u?`-bold`:``}`:n})`)}return c(n,[l(n,`${e.from} → ${e.to}${e.label?`:${e.label}`:``}`),o(n,a,d,{kind:`edge`,from:e.from,to:e.to,...e.status?{status:e.status}:{}})],{kind:`edge-group`})}function m(e,t,{x:n,y:r,w:i,h:s,direction:c},l,d){let f=(0,a.shapeGlyphBox)(t,i,s,c),p=[`fork`,`f-circ`,`anchor`].includes(t)?d.fg3:l.fill,m=f&&l.stroke===d.line2?d.fg4:l.stroke,h=t===`text`||t===`icon`||[`brace`,`brace-r`,`braces`].includes(t)?{fill:`none`,stroke:`none`}:{...l,fill:p,stroke:m,...t===`datastore`?{"stroke-dasharray":`${i} ${s}`}:{}},g=[e.shape(`polygon`,{points:u((0,a.shapeOutline)(t,i,s,c).map(([e,t])=>[n+e,r+t])),...h})];f&&(n+=f.x,r+=f.y,{w:i,h:s}=f);let _=(e,t)=>`${n+i*e} ${r+s*t}`,v=t=>g.push(o(e,t,{fill:`none`,stroke:m,"stroke-width":1.25})),y=(e,t,n,r)=>`M${_(e,t)} L${_(n,r)}`;if(t===`fr-rect`&&v(y(.1,0,.1,1)+y(.9,0,.9,1)),[`win-pane`,`lin-rect`,`lin-doc`].includes(t)&&v(y(.11,0,.11,t===`lin-doc`?.95:1)),[`win-pane`,`div-rect`,`browser`,`console`].includes(t)&&v(y(0,.22,1,.22)),t===`browser`)for(let t of[10,16,22])g.push(e.circle(n+t,r+s*.11,1.4,{fill:l.stroke}));if(t===`console`&&v(`M${_(.08,.06)} L${_(.13,.11)} L${_(.08,.16)} ${y(.15,.16,.21,.16)}`),[`cyl`,`lin-cyl`,`bucket`].includes(t)&&(v(`M${_(0,.12)} A${i/2} ${s*.12} 0 0 0 ${_(1,.12)}`),t===`lin-cyl`&&v(`M${_(0,.19)} A${i/2} ${s*.12} 0 0 0 ${_(1,.19)}`)),t===`h-cyl`&&v(`M${_(.12,0)} A${i*.12} ${s/2} 0 0 1 ${_(.12,1)}`),t===`tag-rect`||t===`tag-doc`){let e=Math.min(14,s*.24),n=t===`tag-doc`?.9:1,r=1-e/i;v(y(r,t===`tag-doc`?n+.09*Math.sin(r*2*Math.PI):n,1,n-e/s))}if(t===`note`){let e=Math.min(12,i/3,s/3);v(`M${n+i-e} ${r} v${e} h${e}`)}if(t===`docs`||t===`st-rect`){let e=(t===`docs`?.9:1)*(s-10);for(let t of[1,2]){let a=t*5,o=n+i-a;v(`M${n+10-a} ${r+a} H${o} V${r+a+e}`)}}(t===`dbl-circ`||t===`fr-circ`)&&g.push(e.circle(n+i/2,r+s/2,i/2-5,{fill:t===`fr-circ`?d.fg4:`none`,stroke:l.stroke})),t===`cross-circ`&&v(y(.16,.16,.84,.84)+y(.84,.16,.16,.84));let b=e=>{let t=e?.94:.06,n=e?.06:-.06;v(`M${_(t-n,.04)} Q${_(t,.04)} ${_(t,.25)} Q${_(t,.5)} ${_(t+n,.5)} Q${_(t,.5)} ${_(t,.75)} Q${_(t,.96)} ${_(t-n,.96)}`)};return(t===`brace`||t===`braces`)&&b(!1),(t===`brace-r`||t===`braces`)&&b(!0),g}function h(e,t,n,r){let{x:i,y:s,w:c,h:l}=n,d=t.node,f=d.class===`ext`?r.line2:d.class&&r[d.class]?r[d.class]:r.line2,p={fill:d.class===`ext`?`none`:d.class&&r[d.class]?e.mix(r.node,r[d.class],r.soft):r.node,stroke:f,"stroke-width":1.25,...d.class===`ext`?{"stroke-dasharray":`4 3`}:{}},h=t.flowchart&&(0,a.flowOutlineName)(d.shape);if(h)return m(e,h,n,p,r);if(d.kind===`note`)return m(e,`note`,n,{...p,fill:e.mix(r.node,r.warn,r.soft)},r);if(d.kind===`start`)return[e.circle(i+c/2,s+l/2,Math.min(c,l)/2,{fill:r.fg2,stroke:`none`})];if(d.kind===`end`)return[e.circle(i+c/2,s+l/2,Math.min(c,l)/2,{fill:r.node,stroke:r.fg2,"stroke-width":1.5}),e.circle(i+c/2,s+l/2,Math.min(c,l)/2-4,{fill:r.fg2,stroke:`none`})];if(d.kind===`choice`||d.shape===`diamond`)return[e.shape(`polygon`,{points:u([[i+c/2,s],[i+c,s+l/2],[i+c/2,s+l],[i,s+l/2]]),...p})];if(d.kind===`fork`||d.kind===`join`)return[e.rect(i,s,c,l,{...p,fill:r.fg3,rx:2})];if(d.shape===`circle`)return[e.shape(`ellipse`,{cx:i+c/2,cy:s+l/2,rx:c/2,ry:l/2,...p})];if(d.shape===`hexagon`)return[e.shape(`polygon`,{points:u([[i+16,s],[i+c-16,s],[i+c,s+l/2],[i+c-16,s+l],[i+16,s+l],[i,s+l/2]]),...p})];if(d.shape===`stadium`)return[e.rect(i,s,c,l,{...p,rx:l/2})];if(d.shape===`cylinder`)return[o(e,`M${i} ${s+6} C${i} ${s-6*.2} ${i+c} ${s-6*.2} ${i+c} ${s+6} V${s+l-6} C${i+c} ${s+l+6*.2} ${i} ${s+l+6*.2} ${i} ${s+l-6} Z`,p),o(e,`M${i} ${s+6} C${i} ${s+12} ${i+c} ${s+12} ${i+c} ${s+6}`,p)];let g=d.kind===`state`?8:d.shape===`round`?11:3,_=e.rect(i,s,c,l,{...p,rx:g});return d.shape===`subroutine`?[_,o(e,`M${i+9} ${s+4} V${s+l-4} M${i+c-9} ${s+4} V${s+l-4}`,{fill:`none`,stroke:f,"stroke-width":1.25})]:[_]}function g(e,t,n,r,i,a=16){let[o,s,c,l]=t.viewBox.split(/\s+/).map(Number),u=a/Math.max(c,l);return e.el(`g`,{transform:`translate(${n-(o+c/2)*u} ${r-(s+l/2)*u}) scale(${u})`},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,t,n)=>t?.link?e.link(t.link.href,[n],t.link):n;function v(e,n,r,i){let u=n.node,d=[l(e,u.label||u.id),...h(e,n,r,i)],f={kind:u.kind===`collapsed`?`frame`:`node`,id:u.id,...u.class?{status:u.class}:{}};if(u.kind===`start`||u.kind===`end`||u.kind===`choice`||u.kind===`fork`||u.kind===`join`)return c(e,d,f);if(u.kind===`er`&&r.er){let t=r.er,n=t.pad,a=r.y+t.headerH;for(let[n,a]of t.headLines.entries())d.push(s(e,r.x+r.w/2,r.y+7+(n+.5)*19,a,{anchor:`middle`,size:14,weight:600,fill:i.fg1},{kind:`node-label`,id:u.id}));d.push(o(e,`M${r.x+1} ${a} H${r.x+r.w-1}`,{stroke:i.line2,"stroke-width":1}));let p=a+2;for(let a of t.rows){let o=[];a.comment&&o.push(l(e,`${a.name}${a.keys.length?` · ${a.keys.join(` `)}`:``}:${a.comment}`));let f=p+a.rowH/2;a.typeLines.forEach((t,c)=>o.push(s(e,r.x+n,f+(c-(a.typeLines.length-1)/2)*17,t,{anchor:`start`,size:13,fill:i.fg3},{kind:`attribute-type`,entity:u.id,attribute:a.name}))),a.nameLines.forEach((c,l)=>o.push(s(e,r.x+n+t.typeW+12,f+(l-(a.nameLines.length-1)/2)*17,c,{anchor:`start`,size:13,fill:i.fg2},{kind:`attribute`,entity:u.id,attribute:a.name}))),a.keyText&&o.push(s(e,r.x+r.w-n,f,a.keyText,{anchor:`end`,size:12,fill:i.fg3},{kind:`attribute-key`,entity:u.id,attribute:a.name})),d.push(c(e,o,{kind:`attribute-row`,entity:u.id,attribute:a.name})),p+=a.rowH}return c(e,d,f)}let p=n.titleLines||[],m=n.descLines||[],_=p.length*19,v=m.length*17,y=m.length?7:0,b=u.kind===`collapsed`,x=n.flowchart&&(0,a.flowOutlineName)(u.shape),S=x&&(0,a.shapeGlyphBox)(x,r.w,r.h,r.direction),C=u.iconHeight??16,w=u.icon?C+8:0,T=u.iconPosition===`t`&&_>0,E=S?r.y+(r.h-_)/2:r.y+Math.max(10,(r.h-_-y-v-(b?20:0)-w)/2)+(T?0:w);if(u.icon){let t=r.x+r.w/2,n=T?E+_+w/2:E-w/2,a={fill:i.surface,stroke:i[u.class]??i.line2,"stroke-width":1};u.iconForm===`circle`?d.push(e.circle(t,n,w/2,a)):[`square`,`rounded`].includes(u.iconForm)&&d.push(e.rect(t-w/2,n-w/2,w,w,{...a,rx:u.iconForm===`rounded`?8:0})),d.push(g(e,u.icon,t,n,i.fg3,C))}let D=S?r.x+S.x+(r.glyphLabelLeft?-8:S.w+8):r.x+r.w/2;if(b){let t=r.y+r.h-20;d.push(o(e,`M${r.x} ${t} H${r.x+r.w}`,{fill:`none`,stroke:i.line2,"stroke-dasharray":`4 3`}));for(let n of[-5,0,5])d.push(e.circle(r.x+r.w/2+n,t+10,1.25,{fill:i.fg4}))}return p.forEach((n,a)=>d.push(s(e,D,E+a*19+9.5,n,{anchor:S?r.glyphLabelLeft?`end`:`start`:`middle`,size:t.FONT.title.size,weight:u.kind===`note`?t.FONT.body.weight:t.FONT.title.weight,fill:i.fg1},{kind:`node-label`,id:u.id}))),m.forEach((n,a)=>d.push(s(e,r.x+r.w/2,E+_+y+a*17+8.5,n,{anchor:`middle`,size:t.FONT.body.size,fill:i.fg3},{kind:`node-description`,id:u.id}))),c(e,d,f)}function y(e,n,r={}){let i=(0,t.appearance)(n),a=e.model||{},o=new Map((a.nodes||[]).map(e=>[e.id,e])),l=new Map((a.edges||[]).map(e=>[e.seq,e])),u=new Map((a.subgraphs||[]).map(e=>[e.id,e])),f=[],m=[],h=[],y=[],b=[];for(let t of e.frames||[]){let e={fill:t.kind===`divider`?i.node:i.surface,stroke:t.class&&i[t.class]?i[t.class]:i.line2,"stroke-width":1,"stroke-dasharray":`5 4`},r=[n.rect(t.x,t.y,t.w,t.h,{...e,rx:6})],a=u.get(t.id);if(f.push(_(n,a,c(n,r,{kind:`frame`,id:t.id,...t.class?{status:t.class}:{}}))),t.lines?.length){let e=t.titleRect,r=[n.rect(e.x-3,e.y-3,e.w+6,e.h+6,{fill:i.surface,rx:2})];a?.icon&&r.push(g(n,a.icon,e.x+8,e.y+8.5,i.fg3)),t.lines.forEach((o,c)=>r.push(s(n,e.x+(a?.icon?22:0),e.y+(c+.5)*17,o,{anchor:`start`,size:13,weight:600,fill:i.fg3},{kind:`frame-title`,id:t.id}))),(t.descLines||[]).forEach((a,o)=>r.push(s(n,e.x,e.y+t.lines.length*17+4+o*16+8,a,{anchor:`start`,size:13,fill:i.fg3},{kind:`frame-description`,id:t.id}))),b.push(_(n,a,c(n,r,{kind:`frame-title-group`,id:t.id})))}}for(let t of e.edges||[]){let e=p({...t,status:l.get(t.id)?.status},o,n,i);if(e&&m.push(e),t.labelRect&&t.labelLines?.length){let e=t.labelRect,r=[n.rect(e.x,e.y,e.w,e.h,{fill:i.surface,rx:3})],a=l.get(t.id)?.icon;a&&r.push(g(n,a,e.x+13,e.y+e.h/2,i.fg3)),t.labelLines.forEach((o,c)=>r.push(s(n,e.x+e.w/2+(a?11:0),e.y+e.h/2+(c-(t.labelLines.length-1)/2)*16,o,{anchor:`middle`,size:12,fill:i.fg3},{kind:`edge-label`}))),y.push(c(n,r,{kind:`edge-label-group`,from:t.from,to:t.to}))}}for(let t of e.nodes||[]){let e=o.get(t.id);e&&h.push(_(n,e,v(n,{node:e,flowchart:a.type===`flowchart`,titleLines:t.lines,descLines:t.descLines},t,i)))}let x=[d(n,i),...f,c(n,m,{kind:`edges`}),c(n,h,{kind:`nodes`}),c(n,y,{kind:`edge-labels`}),c(n,b,{kind:`frame-titles`})];return{width:e.width,height:e.height,children:x,...r.title?{title:r.title}:{}}}return e.implementations=Object.fromEntries([`flowchart`,`stateDiagram-v2`].map(e=>[e,{optionMode:`raw`,acceptsPresentation:!0,honoredConfig:[`flowchart.inheritDir`],parse:(e,t)=>(0,n.parseGraph)(e,t),layout:(e,t,n)=>(0,r.layoutGraph)(e,t,n),scene:y}])),e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/graph-parse`],KChartUnits[`diagram/graph-layout`],KChartUnits[`core/geometry`],KChartUnits[`diagram/shapes`]);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
KChartUnits["diagram/ishikawa"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=Math.cos(82*Math.PI/180)/Math.sin(82*Math.PI/180),s=a.FONT.label.size,c=15,l=18,u=16,d=96,f=44,p=10,m=72,h=30,g=12,_=34,v=44,y=18,b=26,x=18,S=18,ee=14,C=122,w=30,T=24,E=24,D=2e3,O=60,k=[220,190,160,140,120];function A(e,t={}){let o=t.lang||`zh`,s=Number.isInteger(t.firstLine)?t.firstLine:2,c=Number.isInteger(t.headerLine)?t.headerLine:Math.max(1,s-1),l=[],u=[],d=(0,i.presentation)({lang:o}),f=new Set,p=e=>{f.has(e.message)||(f.add(e.message),l.push(e))},m=(e,t)=>{let i=[];e=e.replace(/(?<![\w:/.-])(?:logos|mdi|tabler|simple-icons):[a-z\d-]+/gi,e=>(i.push(e),``));let s=(0,r.normalizeLabel)(e,{lang:o,line:t});s.diagnostics.forEach(p);let c=s.icon;for(let e of i){let r=(0,n.resolveIconRef)(e);c??=r,r||p((0,a.warning)(`IGNORED_ASSET`,o,t,`未知图标 ${e}`,`Unknown icon ${e}`,`使用内置图标`,`Use a supported icon`))}return{label:s.text,icon:c}};typeof t.params==`string`&&t.params.trim()&&!d.accept(t.params.trim(),c)&&u.push({indent:0,text:t.params.trim(),line:c});for(let[t,n]of String(e??``).split(`
|
|
2
|
+
`).entries()){if(!n.trim()||/^\s*%%/.test(n))continue;let e=s+t;if(d.accept(n.trim(),e))continue;let r=/^[^\S\n]*/.exec(n)[0].length;u.push({indent:r,text:n.slice(r).trim(),line:e})}let h=u[0];if(!h)return l.push((0,a.error)(o,c,`鱼骨图缺少问题(第一行)`,`Ishikawa diagram has no problem line`,`先写问题,再逐层缩进写原因`,`Write the problem first, then indent its causes`)),{model:{kind:`ishikawa`,title:``,root:{id:`root`,label:``,line:c,children:[]},count:0},errors:l};let g=u.slice(1),_={id:`root`,...m(h.text,h.line),line:h.line,children:[]},v=g.length?g[0].indent:0,y=[{level:0,node:_}],b=1;for(let e of g){if(b>=D){l.push((0,a.error)(o,e.line,`鱼骨图最多 ${D} 个原因`,`An Ishikawa diagram can contain at most ${D} causes`,`拆分鱼骨图,不要删除原因`,`Split the diagram without dropping causes`));break}let t=Math.max(1,e.indent-v+1);for(;y.length>1&&y[y.length-1].level>=t;)y.pop();let n={id:`n${b}`,...m(e.text,e.line),line:e.line,children:[]};y[y.length-1].node.children.push(n),y.push({level:t,node:n}),b+=1}let x=e=>{e.status=d.statusOf(e.id),e.link=d.linkOf(e.id),e.children.forEach(x)};return x(_),l.push(...d.diagnostics()),{model:{kind:`ishikawa`,title:_.label,root:_,count:b},errors:l}}function j(e,t){let n=t;for(let[t,r]of e.entries())r.s=n+r.h/2,n+=r.h,r.children.length&&(n=j(r.children,n+S)),t<e.length-1&&(n+=x);return n}function M(e,{cap:t,lang:n,measure:r,width:i}){let u=[],p=(e,t)=>Math.max(0,r(e,t)),x=(e,n)=>(0,a.wrapText)(e,t,n,(e,t)=>r(e,t)),S={size:a.FONT.title.size,weight:a.FONT.title.weight},D={size:s,weight:400},k={size:s,weight:600},A=x(e.root.label,S),M=e=>e?20:0,P=Math.max(d,Math.ceil(Math.max(0,...A.map(e=>p(e,S)))+32+M(e.root.icon))),F=Math.max(f,A.length*l+28);A.length>4&&u.push((0,a.warning)(`DIAGRAM_HINT`,n,e.root.line,`问题换成 ${A.length} 行,鱼头会很高`,`The problem label wraps to ${A.length} lines and makes a tall head`,`缩短问题描述`,`Shorten the problem statement`));let I={root:e.root.status},L=(e,t)=>{let n=x(e.label,D);I[e.id]=e.status;let r={id:e.id,line:e.line,depth:t,icon:e.icon,status:e.status,link:e.link,lines:n,children:[]};return r.h=n.length*c,r.w=Math.max(0,...n.map(e=>p(e,D)))+M(e.icon),r.children=(e.children||[]).map(e=>L(e,t+1)),r},R=e.root.children.map((e,t)=>{I[e.id]=e.status;let n=x(e.label,k);return{id:e.id,line:e.line,icon:e.icon,status:e.status,link:e.link,index:t,dir:t%2==0?-1:1,lines:n,chipW:Math.max(m,Math.ceil(Math.max(0,...n.map(e=>p(e,k)))+20+M(e.icon))),chipH:Math.max(h,n.length*c+12),children:(e.children||[]).map(e=>L(e,2))}});for(let e of R){let t=j(e.dir<0?[...e.children].reverse():e.children,b);e.reach=Math.max(C,t+ee+e.chipH)}let z=[R.filter(e=>e.dir<0),R.filter(e=>e.dir>0)];for(let e of z){if(!e.length)continue;let t=Math.max(...e.map(e=>e.reach));for(let n of e)n.reach=t}for(let e of R){let t=(n,r)=>{if(n.depth%2==0)n.y0=n.s,n.x0=r===e?-o*n.s:r.x1-o*(n.s-r.y1),n.run=n.children.length?Math.max(v,y*n.children.length):_,n.x1=n.x0-n.run,n.y1=n.s;else{let e=r.children.length,t=r.children.indexOf(n);n.y0=r.y1,n.x0=r.x1+(r.x0-r.x1)*(t+1)/(e+1);let i=n.children.length?Math.max(n.s,...n.children.map(N)):n.s;n.y1=i,n.x1=n.x0-o*(i-n.y0)}n.children.forEach(e=>t(e,n))};e.children.forEach(n=>t(n,e));let n=e=>Math.min(e.x1-g-e.w,e.x0,e.x1,...e.children.map(n)),r=e.children.map(n),i=-o*e.reach;e.leftRel=Math.min(i-e.chipW/2,...r),e.rightRel=Math.max(0,i+e.chipW/2)}for(let e of z){let t=Math.max(0,...e.slice(1).map((t,n)=>t.rightRel-e[n].leftRel+w));e.forEach((n,r)=>{n.ax=r?e[r-1].ax-t:-(n.rightRel+T)})}let B=R.length?Math.min(...R.map(e=>e.ax+Math.min(e.leftRel,-26))):-26,V=Math.min(B,0,...R.map(e=>e.ax+e.leftRel)),H=Math.max(P,...R.map(e=>e.ax+e.rightRel)),U=Math.max(0,...z[0].map(e=>e.reach)),W=Math.max(0,...z[1].map(e=>e.reach)),G=Math.min(-F/2,-U),K=Math.max(F/2,W),q=E-V,J=E-G,Y=(e,t,n)=>[q+e,J+n*t],X=[],Z=[],Q=[];for(let e of R){X.push({id:`${e.id}-bone`,from:e.id,to:`root`,main:!0,points:[Y(e.ax-o*(e.reach-e.chipH),e.reach-e.chipH,e.dir),Y(e.ax,0,1)]}),Z.push({id:e.id,line:e.line,tone:e.index%6,lines:e.lines,icon:e.icon,status:e.status,link:e.link,x:q+e.ax-o*e.reach-e.chipW/2,y:J+(e.dir<0?-e.reach:e.reach-e.chipH),w:e.chipW,h:e.chipH});let t=n=>{X.push({id:`${n.id}-bone`,from:n.parent||e.id,to:n.id,main:!1,points:[Y(e.ax+n.x0,n.y0,e.dir),Y(e.ax+n.x1,n.y1,e.dir)]}),Q.push({id:n.id,line:n.line,lines:n.lines,icon:n.icon,side:e.dir,status:n.status,link:n.link,x:q+e.ax+n.x1-g,y:J+e.dir*n.s}),n.children.forEach(t)};for(let n of e.children){n.parent=e.id;let r=(e,t)=>{e.parent=t.id,e.children.forEach(t=>r(t,e))};r(n,e),t(n)}}e.count>O&&u.push((0,a.warning)(`LARGE_DIAGRAM`,n,e.root.line,`鱼骨图有 ${e.count} 个原因,建议拆分`,`The Ishikawa diagram has ${e.count} causes; consider splitting it`,`按类别拆成多张鱼骨图`,`Split the diagram by category`));let $=Math.ceil(H-V+48);return e.count<=O&&$>i*2&&u.push((0,a.warning)(`LARGE_DIAGRAM`,n,e.root.line,`鱼骨图需要 ${$}px 宽,超过图框两倍`,`The Ishikawa diagram needs ${$}px, more than twice the frame`,`加宽图框或拆分鱼骨图`,`Widen the frame or split the diagram`)),{width:$,height:Math.ceil(K-G+48),cap:t,nodeStatus:I,errors:u,head:{x:q,y:J-F/2,w:P,h:F,lines:A,icon:e.root.icon,link:e.root.link},spine:{x1:q+B,y1:J,x2:q,y2:J},bones:X,chips:Z,labels:Q}}var N=e=>Math.max(e.s,...e.children.map(N));function P(e,t={}){let n=t.measure||a.fallbackMeasure,r=Math.max(1,Number(t.width)||800),i=t.lang||`zh`,o=null;for(let t of k)if(o=M(e,{cap:t,lang:i,measure:n,width:r}),o.width<=r)break;return o}function F(e,n){let r=(0,a.appearance)(n),i=n.frameTone(n.color(`fg`)),o=n.frameTone(n.color(`accent`),!0),d=Array.from({length:6},(e,t)=>n.frameTone(n.color(`tone${t+1}`))),f=`ishikawa-arrow`,m=`url(#${f})`,h=[n.el(`defs`,{},[n.el(`marker`,{id:f,viewBox:`0 0 8 8`,refX:8,refY:4,markerWidth:8,markerHeight:8,markerUnits:`userSpaceOnUse`,orient:`auto`},[n.path(`M0 0 L8 4 L0 8 Z`,{fill:i})])])];h.push(...e.bones.map(t=>n.path(`M${t.points[0][0]} ${t.points[0][1]} L${t.points[1][0]} ${t.points[1][1]}`,{fill:`none`,stroke:t.main?i:e.nodeStatus?.[t.to]?n.frameTone(r[e.nodeStatus[t.to]]):r.fg4,"stroke-width":t.main?2:1.4,"stroke-linecap":`round`,...t.main?{"marker-end":m}:{},meta:{kind:`edge`,from:t.from,to:t.to}}))),h.push(n.line(e.spine.x1,e.spine.y1,e.spine.x2,e.spine.y2,{stroke:i,"stroke-width":2,"stroke-linecap":`round`,"marker-end":m,meta:{kind:`edge`,from:`root`,to:`root`}}));for(let i of e.chips){let e=d[i.tone],a=i.status?n.tint(r.bg,r[i.status],.12):n.tint(r.bg,e,.07),o=n.el(`g`,{},[n.rect(i.x,i.y,i.w,i.h,{rx:r.radius,fill:a,stroke:i.status?r[i.status]:n.tint(r.bg,e,.45),"stroke-width":1,meta:{kind:`node`,id:i.id,label:i.id}}),...i.icon?[(0,t.labelIcon)(n,i.icon,i.x+p+7,i.y+i.h/2,14,r.fg3)]:[],...i.lines.map((e,t)=>n.text(i.x+i.w/2+(i.icon?10:0),i.y+i.h/2+(t-(i.lines.length-1)/2)*c,e,{size:s,weight:600,fill:r.fg1,anchor:`middle`,"dominant-baseline":`central`}))]);h.push(i.link?n.link(i.link.href,[o],i.link):o)}for(let i of e.labels){let e=i.icon?Math.max(0,...i.lines.map(e=>n.measure(e,s,400))):0,a=n.el(`g`,{},[...i.icon?[(0,t.labelIcon)(n,i.icon,i.x-e-12,i.y,14,r.fg3)]:[],...i.lines.map((e,t)=>n.text(i.x,i.y+(t-(i.lines.length-1)/2)*c,e,{size:s,weight:400,fill:i.status?n.textColor(r[i.status]):r.fg2,anchor:`end`,"dominant-baseline":`central`}))]);h.push(i.link?n.link(i.link.href,[a],i.link):a)}let g=e.nodeStatus?.root,_=g?n.tint(r.bg,r[g],.12):n.tint(r.bg,o,.12),v=n.el(`g`,{},[n.rect(e.head.x,e.head.y,e.head.w,e.head.h,{rx:Math.min(e.head.h/2,r.radius+10),fill:_,stroke:g?r[g]:n.tint(r.bg,o,.5),"stroke-width":1.5,meta:{kind:`node`,id:`root`,label:`root`}}),...e.head.icon?[(0,t.labelIcon)(n,e.head.icon,e.head.x+u+7,e.head.y+e.head.h/2,14,r.fg3)]:[],...e.head.lines.map((t,r)=>n.text(e.head.x+e.head.w/2+(e.head.icon?10:0),e.head.y+e.head.h/2+(r-(e.head.lines.length-1)/2)*l,t,{size:a.FONT.title.size,weight:a.FONT.title.weight,fill:n.textOn(_),anchor:`middle`,"dominant-baseline":`central`}))]);return h.push(e.head.link?n.link(e.head.link.href,[v],e.head.link):v),{width:e.width,height:e.height,title:e.head.lines.join(` `),children:h,anchor:{x:e.head.x+e.head.w/2,y:e.head.y+e.head.h/2}}}return e.implementations={ishikawa:{optionMode:`raw`,parse:A,layout:P,scene:F,acceptsPresentation:!0,honoredConfig:[]}},e})({},KChartUnits[`diagram/tree-family-icon`],KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
KChartUnits["diagram/journey"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=60,o=2e3,s=[`journey`],c=new Map([[`taskfontsize`,`taskFontSize`],[`maxlabelwidth`,`maxLabelWidth`],[`titlefontsize`,`titleFontSize`],[`leftmargin`,`leftMargin`]]),l=new Set([`actorcolours`,`sectionfills`,`sectioncolours`,`titlecolor`]),u=e=>String(e).toLowerCase().replace(/[-_]/g,``),d=9,f=14,p=5,m={labelX:12,labelPad:12,plotGap:6,right:16,band:10,bottom:16,row:48,chipR:4,chipGap:6};m.chip=m.chipR*2+m.chipGap;var h=(e,t,r,i,a,o)=>(0,n.error)(e,t,r,i,a,o),g=(e,t,n,r)=>{if(e==null||e===``)return t;if(typeof e==`number`)return Number.isFinite(e)?Math.min(r,Math.max(n,e)):t;let i=/^([+-]?\d*\.?\d+)\s*(px|pt|ex|em|rem)?$/i.exec(String(e).trim());if(!i)return t;let a={px:1,pt:4/3,ex:4,em:12,rem:12}[(i[2]||`px`).toLowerCase()];return Math.min(r,Math.max(n,Number(i[1])*a))};function _(e){let t=``;for(let n=0;n<e.length;n+=1){let r=e[n];if(t)r===t&&(t=``);else if(r===`"`||r===`'`)t=r;else if(r===`%`&&e[n+1]===`%`||r===`#`&&!/^#[\w]+;/.test(e.slice(n)))return e.slice(0,n).trimEnd()}return e}var v=e=>e.replace(/(?:&#?|#)[\w]+;/g,``).includes(`;`);function y(e,t,r,i){let a=e?.config?.journey,o={};if(!a||typeof a!=`object`||Array.isArray(a))return o;let s=[],d=[];for(let[e,t]of Object.entries(a)){let n=u(e);c.has(n)?o[c.get(n)]=t:l.has(n)?s.push(e):d.push(e)}return s.length&&i.push((0,n.warning)(`IGNORED_STYLE`,t,r,`旅程图颜色由主题决定,已忽略配置:${s.join(`, `)}`,`Journey colors come from the theme; ignored: ${s.join(`, `)}`,`改用主题调色板`,`Use the theme palette`)),d.length&&i.push((0,n.warning)(`IGNORED_CONFIG`,t,r,`旅程图不支持这些配置,已忽略:${d.join(`, `)}`,`Ignored journey config: ${d.join(`, `)}`,`移除这些配置项`,`Remove these config keys`)),o}function b(e,a={}){let s=a.lang||`zh`,c=Number.isInteger(a.firstLine)?a.firstLine:2,l=[];if(e.length>2e5)return{model:null,errors:[h(s,c,`旅程图源码超过 200000 字符`,`Journey source exceeds 200,000 characters`,`拆分旅程图`,`Split the journey`)]};let u=y(a,s,a.headerLine||Math.max(1,c-1),l),d={taskFontSize:g(u.taskFontSize,n.FONT.body.size,12,20),maxLabelWidth:g(u.maxLabelWidth,360,120,640),titleFontSize:g(u.titleFontSize,n.FONT.title.size,12,28),leftMargin:g(u.leftMargin,0,0,480)},f=[],p=[{name:``,tasks:[]}],m=(0,i.presentation)({lang:s}),b=new Set,x=e=>e.forEach(e=>{e.code===`IGNORED_ASSET`&&b.has(e.message)||(l.push(e),e.code===`IGNORED_ASSET`&&b.add(e.message))}),S=(e,t)=>{let n,i=e=>(n??=e,``),a=e.replace(/::icon\(([^)]+)\)/gi,(e,t)=>i(t.trim())).replace(/(?<![\w:/.-])(?:logos|mdi|tabler|simple-icons):[a-z\d-]+/gi,i),o=(0,r.normalizeLabel)(a,{lang:s,line:t});return x(o.diagnostics),{text:o.text,icon:(n?C(n,t):null)||o.icon}},C=(e,r)=>{let i=(0,t.resolveIconRef)(e);return i||x([(0,n.warning)(`IGNORED_ASSET`,s,r,`未知图标 ${e}`,`Unknown icon ${e}`,`使用内置图标`,`Use a built-in icon`)]),i},w=a.title||``,T=a.headerLine||Math.max(1,c-1),E=!1,D=!1,O=Object.keys(a.options||{});O.length&&l.push((0,n.warning)(`IGNORED_CONFIG`,s,a.headerLine||Math.max(1,c-1),`旅程图标题行不接受选项,已忽略:${O.join(`, `)}`,`Journey header options are ignored: ${O.join(`, `)}`,`只保留 journey 关键字`,`Keep only the journey keyword`));let k=String(e??``).replace(/\r\n?/g,`
|
|
2
|
+
`).split(`
|
|
3
|
+
`);for(let e=0;e<k.length;e+=1){let t=c+e,r=k[e].trim();if(m.accept(r,t))continue;let i=_(r).trim();if(!i||i.startsWith(`%%`))continue;if(v(i)){l.push(h(s,t,`分号不能用于分隔旅程图语句`,`Semicolons cannot separate journey statements`,`每行只写一条语句`,`Write one statement per line`));continue}let a;if(a=/^title(?:\s*:|\s+)(.*)$/i.exec(i)){w=a[1].trim(),T=t;continue}if(/^title$/i.test(i))continue;if(/^section\b/i.test(i)){let e=/^section\s+(.+)$/i.exec(i);if(!e||!e[1].trim()){l.push(h(s,t,`分组名不能为空`,`A section name must be non-empty`,`写成「section 名称」`,`Write "section name"`));continue}let n=S(e[1].trim(),t);p.push({name:n.text,icon:n.icon,tasks:[],line:t});continue}let u=[],d=i.replace(/:::([\w-]+)/g,(e,t)=>(u.push(t),``)),g=[...d.matchAll(/::icon\([^)]+\)|(?<![\w:/.-])(?:fa[bsrlk]?|logos|mdi|tabler|simple-icons):[a-z\d-]+|(:)/gi)].find(e=>e[1])?.index,y=g==null?``:d.slice(0,g).trim();if(!y){l.push(h(s,t,`旅程任务需要写成「任务名: 评分: 参与者」`,`A journey task reads "task name: score: actors"`,`在冒号前写任务名`,`Write the task name before the colon`));continue}let[,b,x=``]=/^\s*([^:]*?)(?:\s*:\s*(.*))?$/.exec(d.slice(g+1)),C=b.trim()?Number(b):NaN,O=x.split(`,`).map(e=>S(e.trim(),t)),A=[...new Set(O.map(e=>e.text).filter(Boolean))];if(!Number.isFinite(C)){l.push(h(s,t,`评分「${b}」不是数字`,`Score "${b}" is not a number`,`用 1–5 的整数评分`,`Use a whole score from 1 to 5`));continue}if(C<1||C>5){l.push(h(s,t,`评分 ${C} 超出 1–5 的范围`,`Score ${C} is outside 1–5`,`把评分改为 1 到 5`,`Use a score from 1 to 5`));continue}if(!Number.isInteger(C)&&!E&&(E=!0,l.push((0,n.warning)(`DIAGRAM_HINT`,s,t,`评分 ${C} 不是整数,已按原值绘制`,`Score ${C} is not whole; drawn as written`,`使用 1–5 的整数评分`,`Use whole scores from 1 to 5`))),f.length>=o){D||(D=!0,l.push(h(s,t,`旅程图最多 ${o} 个任务`,`A journey can contain at most ${o} tasks`,`把旅程拆成两张图`,`Split the journey into two diagrams`)));continue}let j=S(y,t),M=`task:${f.length}`;u.length&&m.addClasses(M,u,t);let N={id:M,name:j.text,icon:j.icon,score:C,actors:A,actorLabels:O,line:t};f.push(N),p.at(-1).tasks.push(N)}let A=S(w,T);w=A.text,a.title=w,!f.length&&!l.some(e=>e.severity!==`warning`)&&l.push(h(s,c,`旅程图中没有任务`,`Journey has no tasks`,`添加「任务名: 评分: 参与者」`,`Add "task name: score: actors"`));let j=[...new Set(f.flatMap(e=>e.actors))],M=new Map,N=new Map;for(let e of f)for(let t of e.actorLabels)t.text&&(t.icon&&!M.has(t.text)&&M.set(t.text,t.icon),N.has(t.text)||N.set(t.text,m.linkOf(t.text)));for(let e of f)e.status=m.statusOf(e.id),e.link=m.linkOf(e.id);for(let e of p)e.status=m.statusOf(e.name),e.link=m.linkOf(e.name);return l.push(...m.diagnostics()),{model:{type:`journey`,title:w,titleIcon:A.icon,titleLink:m.linkOf(w),tasks:f,sections:p,actors:j,actorIcons:Object.fromEntries(M),actorLinks:Object.fromEntries(N),actorStatuses:Object.fromEntries(j.map(e=>[e,m.statusOf(e)])),config:d},errors:l}}function x(e,t,n,r,i=f,a=e.color(`fg`)){if(!t)return null;let[o,s,c,l]=t.viewBox.split(/\s+/).map(Number),u=i/Math.max(c,l),d=t.set===`tabler`;return e.el(`g`,{transform:`translate(${n+(i-c*u)/2} ${r+(i-l*u)/2}) scale(${u}) translate(${-o} ${-s})`,fill:d?`none`:a,stroke:d?a:`none`,"stroke-width":1.8,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function S(e,t={}){let{width:r=800,ctx:i,renderOptions:o={}}=t;if(!i)throw TypeError(`journey layout needs a theme context`);let s=(0,n.appearance)(i),c=t.measure||((e,t)=>i.measure(e,t.size,t.weight)),l=i.color(`bg`),u=i.color(`accent`),h=i.color(`grid`),g=i.color(`fg`),_=i.color(`muted`),v=e.config||{},y={size:v.taskFontSize||n.FONT.body.size,weight:n.FONT.body.weight},b={size:n.FONT.label.size,weight:n.FONT.label.weight},S=(0,n.isEn)(i.lang)?`Score`:`评分`,C=v.titleFontSize||n.FONT.title.size,w=v.maxLabelWidth||360,{tasks:T,actors:E}=e,D=e.sections.filter(e=>e.name||e.icon||e.tasks.length),O=new Map(E.map((e,t)=>[e,t])),k=(e,t)=>e?[i.link(e.href,t,e)]:t,A=e=>e?18:0,j=[],M=[],N=(e,t)=>({size:e,weight:t}),P=(e,t)=>c(e,t),F=t=>{let n=O.get(t),r=e.actorStatuses?.[t];return i.tint(l,r?i.design[r]:i.color(`tone${n%6+1}`),.8)},I=new Map(T.map(e=>[e,i.wrap(e.name,Math.max(40,w-A(e.icon)),y.size,y.weight)])),ee=e=>e.actors.length?(e.actors.length-1)*m.chip+m.chipR*2:0,te=Math.max(0,...T.map(e=>A(e.icon)+Math.max(0,...I.get(e).map(e=>P(e,y)))+(e.actors.length?10+ee(e):0))),L=N(n.FONT.body.size,600),ne=Math.max(0,...D.flatMap(e=>e.name.split(`
|
|
4
|
+
`).map((t,n)=>P(t,L)+(n===0?A(e.icon):0)))),R=y.size+5,z=Math.max(v.leftMargin||0,m.labelX+Math.max(te,ne,P(S,b))+m.labelPad+d+m.plotGap),B=Math.max(140,r-z-m.right),V=z,H=z+B,U=B/4,W=Math.ceil(Math.max(r,H+m.right)),G=!!e.title&&!o?.frame;if(G){let t=i.text(m.labelX+A(e.titleIcon),C+12,e.title,{size:C,weight:600,fill:g}),n=[...e.titleIcon?[x(i,e.titleIcon,m.labelX,C+12-f/2)]:[],t];j.push(...k(e.titleLink,[i.el(`g`,{},n)]))}let K=G?12+C+18:16,q=Math.max(120,H-m.labelX),J=[],Y=[],X=0,Z=0;for(let t of E){let n=i.wrap(t,Math.max(40,q-13-A(e.actorIcons?.[t])),b.size,b.weight),r=13+A(e.actorIcons?.[t])+Math.max(0,...n.map(e=>P(e,b)));Y.length&&X+r>q&&(J.push({items:Y,height:Z}),Y=[],X=0,Z=0),Y.push({name:t,lines:n,width:r}),X+=r+14,Z=Math.max(Z,n.length*15)}Y.length&&J.push({items:Y,height:Z});for(let t of J){let n=m.labelX;for(let r of t.items){let t=e.actorIcons?.[r.name],a=A(t),o=i.titled(i.circle(n+m.chipR,K+8,m.chipR,{fill:F(r.name),stroke:l,"stroke-width":1}),r.name);j.push(...k(e.actorLinks?.[r.name],[o])),t&&j.push(x(i,t,n+13,K+1)),r.lines.forEach((t,o)=>j.push(...k(e.actorLinks?.[r.name],[i.text(n+13+a,K+8+o*15,t,{...b,fill:_,"dominant-baseline":`middle`})]))),n+=r.width+a+14}K+=t.height+(J.length>1?4:0)}J.length&&(K+=10);let Q=K+8;j.push(i.text(m.labelX,Q,S,{...b,fill:_,"dominant-baseline":`middle`}));for(let e=1;e<=p;e+=1)j.push(i.text(V+(e-1)*U,Q,String(e),{...b,fill:_,anchor:`middle`,"dominant-baseline":`middle`}));K=Q+14;let $=[];for(let[e,t]of D.entries()){let n=t.name||t.icon?t.name.split(`
|
|
5
|
+
`):[],r=K,i=r+(n.length?10+18*n.length:0),a=t.tasks.map(e=>{let t=I.get(e),n=Math.max(m.row,t.length*R+24),r={task:e,lines:t,y:i,height:n,mid:i+n/2};return i+=n,r});$.push({group:t,index:e,y:r,height:i-r,sectionLines:n,rows:a}),K=i+m.band}let re=$.length?K-m.band:K;for(let e of $){if(!e.group.name)continue;let t=e.group.status?i.design[e.group.status]:i.color(`tone${e.index%6+1}`);j.push(i.rect(8,e.y,H+m.labelPad-8,e.height,{rx:s.radius,fill:i.tint(l,t,.06),meta:{kind:`frame`,id:`section:${e.index}`,...e.group.status?{status:e.group.status}:{}}}))}for(let t of $){t.sectionLines.forEach((e,n)=>{let r=n===0?A(t.group.icon):0,a=i.text(m.labelX+r,t.y+15+n*18,e,{...L,fill:_,"dominant-baseline":`middle`}),o=[...n===0&&t.group.icon?[x(i,t.group.icon,m.labelX,t.y+8)]:[],a];j.push(...k(t.group.link,o))});for(let{task:n,lines:r,mid:a}of t.rows){let t=A(n.icon);if(n.icon&&j.push(x(i,n.icon,m.labelX,a-f/2)),r.forEach((e,o)=>j.push(...k(n.link,[i.text(m.labelX+t,a+(o-(r.length-1)/2)*R,e,{...y,fill:g,"dominant-baseline":`middle`})]))),n.actors.length){let o=m.labelX+t+Math.max(0,...r.map(e=>P(e,y)))+10+m.chipR;n.actors.forEach((t,n)=>{let r=i.titled(i.circle(o+n*m.chip,a,m.chipR,{fill:F(t),stroke:l,"stroke-width":1}),t);j.push(...k(e.actorLinks?.[t],[r]))})}j.push(i.line(V,a,H,a,{stroke:h,"stroke-width":1}));let o=V+(n.score-1)*U,s=n.status?i.design[n.status]:u,c=i.circle(o,a,d,{fill:i.tint(l,s,.06),stroke:s,"stroke-width":1.4,role:`img`,"aria-label":`${n.name}: ${S} ${n.score}/${p}`,meta:{kind:`node`,id:n.id,...n.status?{status:n.status}:{}}});j.push(...k(n.link,[c]));for(let e of[-3,3])j.push(i.circle(o+e,a-2.5,1.2,{fill:_}));let v=n.score>3?`M${o-4} ${a+2} Q${o} ${a+7} ${o+4} ${a+2}`:n.score<3?`M${o-4} ${a+5.5} Q${o} ${a+.5} ${o+4} ${a+5.5}`:`M${o-4} ${a+3.5} L${o+4} ${a+3.5}`;j.push(i.path(v,{fill:`none`,stroke:u,"stroke-width":1.4,"stroke-linecap":`round`}))}}let ie=Math.ceil(Math.max(160,re+m.bottom));return T.length>a?M.push((0,n.warning)(`LARGE_DIAGRAM`,t.lang||i.lang||`zh`,T[a].line,`旅程图有 ${T.length} 个任务,建议拆分`,`The journey has ${T.length} tasks; consider splitting it`,`按阶段拆成两张旅程图`,`Split the journey by stage`)):W>r*2&&M.push((0,n.warning)(`LARGE_DIAGRAM`,t.lang||i.lang||`zh`,1,`旅程图比给定宽度宽很多`,`The journey is much wider than the requested width`,`缩小任务名或拆分旅程图`,`Shorten task names or split the journey`)),{width:W,height:ie,scene:{width:W,height:ie,children:j,...e.title?{title:e.title}:{},...o?.frame&&e.title?{heading:e.title}:{}},errors:M}}return e.implementations={journey:{parse:b,layout:S,honoredConfig:s,acceptsPresentation:!0}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`]);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
KChartUnits["diagram/kanban"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=new Map([[`Very High`,`danger`],[`High`,`warn`],[`Medium`,null],[`Low`,`info`],[`Very Low`,`info`]]),o=[[`((`,`))`],[`{{`,`}}`],[`))`,`((`],[`-)`,`(-`],[`(-`,`-)`],[`[`,`]`],[`(`,`)`],[`)`,`(`]],s=[`kanban.sectionWidth`,`kanban.padding`,`kanban.ticketBaseUrl`];function c(e){let t=new Map,n=/\s*([\w-]+)\s*:\s*("(?:\\.|[^"\\])*"|'(?:''|[^'])*'|[^,]+?)\s*(,|$)/y,r=0;for(;r<e.length;){n.lastIndex=r;let i=n.exec(e);if(!i)return null;let a=i[2].trim();t.set(i[1],a.startsWith(`"`)?a.slice(1,-1).replace(/\\(.)/g,`$1`):a.startsWith(`'`)?a.slice(1,-1).replace(/''/g,`'`):a),r=n.lastIndex}return t}function l(e,{lang:s,firstLine:l=2,title:u=``,config:d,options:f={}}){let p=[],m=[],h=new Map,g=new Set,_=(0,r.presentation)({lang:s}),v=e=>{g.has(e.message)||(g.add(e.message),m.push(e))},y=(e,t)=>{let r=(0,n.normalizeLabel)(e,{lang:s,line:t});return r.diagnostics.forEach(v),r},b=(e,t,n)=>m.push((0,i.error)(s,e,t,n,`修正列或卡片声明`,`Fix the column or card declaration`));Object.keys(f).length&&b(l-1,`kanban 不接受标题行选项`,`Unexpected kanban header option`);let x,S,C=0;for(let[n,r]of e.split(`
|
|
2
|
+
`).entries()){let e=l+n,u=r.trim();if(!u||u.startsWith(`%%`)||_.accept(u,e))continue;let d=/\s*(?:::icon\(([^()]+)\)|:::([\w-]+))$/,f,m,g=[];for(;f=d.exec(u);)f[2]?g.unshift(f[2]):m??=f[1].trim(),u=u.slice(0,f.index).trimEnd();if(!u&&(g.length||m)&&S){let n=S.cards.at(-1)||S;_.addClasses(n.key,g,e),m&&(n.icon=(0,t.resolveIconRef)(m)),m&&!n.icon&&v((0,i.warning)(`IGNORED_ASSET`,s,e,`未知图标 ${m}`,`Unknown icon ${m}`));continue}let w=/\s*@\{([\s\S]*)\}\s*$/.exec(u),T=w?c(w[1].trim()):new Map;w&&(u=u.slice(0,w.index).trimEnd());let E=u.search(/[\[({)]|-\)/),D=o.find(([e,t])=>E>=0&&u.slice(E).startsWith(e)&&u.endsWith(t));if(!T||!D&&(E>=0||!/^\S+$/.test(u))||/:::/.test(u.slice(0,E<0?u.length:E))){b(e,`无效的看板条目`,`Invalid kanban item`);continue}let O=D?u.slice(0,E).trim():u,k=y(T.get(`label`)??(D?u.slice(E+D[0].length,-D[1].length):O),e);m??=T.get(`icon`);let A=m&&(0,t.resolveIconRef)(m)||k.icon;m&&!(0,t.resolveIconRef)(m)&&v((0,i.warning)(`IGNORED_ASSET`,s,e,`未知图标 ${m}`,`Unknown icon ${m}`));let j=O||`kanban-item-${e}`;g.length&&_.addClasses(j,g,e);let M={id:O,key:j,label:k.text,icon:A},N=r.search(/\S/);if(x??=N,N<x){b(e,`缩进小于首列的 ${x} 个空格`,`Indentation is shallower than the first column (${x})`);continue}if(++C>2e3){b(e,`看板超过 2000 个条目,请拆分图表`,`Board exceeds 2000 items; split the diagram`);break}if(N===x){p.push(S={...M,cards:[],ids:new Set});continue}if(O&&S.ids.has(O)){b(e,`本列的卡片 ID 重复:${O}`,`Duplicate card ID in this column: ${O}`);continue}O&&S.ids.add(O);let P=T.get(`priority`);P&&!a.has(P)&&!h.has(P)&&h.set(P,e),S.cards.push({...M,line:e,ticket:y(T.get(`ticket`),e).text,assigned:y(T.get(`assigned`),e).text,priority:P})}for(let e of p)for(let t of[e,...e.cards])t.status=_.statusOf(t.key),t.link=_.linkOf(t.key);if(m.push(..._.diagnostics()),p.length||b(l,`缺少看板列`,`Expected at least one column`),h.size){let e=[...h.keys()].join(`, `);m.push((0,i.warning)(`DIAGRAM_HINT`,s,h.values().next().value,`未知优先级:${e}`,`Unknown priorities: ${e}`,`使用标准优先级`,`Use a standard priority`))}return{model:{type:`kanban`,columns:p,title:u,count:C,config:d?.kanban||{}},errors:m}}function u(e,t,n,r,i){let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c),u=t.set===`simple`;return e.el(`g`,{transform:`translate(${n-a*l} ${r-o*l}) scale(${l})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function d(e,{width:t,ctx:n,renderOptions:o},s={}){let{columns:c,config:l,title:d,count:f}=e,p=(0,i.appearance)(n),m=Math.max(180,Math.min(560,Number(l.sectionWidth)||220)),h=Math.max(8,Math.min(28,Number(l.padding)||10)),g=c.length*(m+14)-14,_=Math.max(t,g+36),v=(_-g)/2,y=d&&!o?.frame,b=y?52:18,x=m-2*h,S=x-24,C=c.map(e=>n.wrap(e.label,x-(e.icon?22:0),i.FONT.title.size,i.FONT.title.weight)),w=Math.max(...C.map(e=>e.length))*18+22,T=[],E=[];y&&T.push(n.text(v,32,d,{...i.FONT.title,fill:p.fg1}));let D=c.map((e,t)=>{let o=v+t*(m+14),s=o+h,c=b+w,d=[...n.textLines(s+(e.icon?22:0),b+24,C[t],{...i.FONT.title,leading:18,fill:p.fg1}).children??[]];return e.icon&&d.push(u(n,e.icon,s,b+11,p[e.status]||p.fg1)),T.push(...e.link?[n.link(e.link.href,d,e.link)]:d),e.cards.forEach((e,o)=>{let d=T.length,f=e.icon?22:0,m=n.wrap(e.label,S-f,i.FONT.body.size),h=[e.ticket,e.assigned].map(e=>n.measure(e,i.FONT.label.size)),g=h[0]+h[1]+12<=S,_=e.ticket?n.wrap(e.ticket,S,i.FONT.label.size):[],v=e.assigned?n.wrap(e.assigned,S,i.FONT.label.size):[],y=g?Math.max(_.length,v.length):_.length+v.length,b=22+m.length*17+(y?5+y*16:0),C=c+17+m.length*17+5;T.push(n.rect(s,c,x,b,{rx:p.smallRadius,fill:e.status?n.tint(p.surface,p[e.status],.1):p.surface,stroke:p[e.status]||p.line,meta:{kind:`node`,id:`${t}:${o}`}}));let w=a.get(e.priority);if(w&&T.push(n.rect(s+1,c+7,4,b-14,{rx:2,fill:p[w],opacity:e.priority===`Very Low`?.4:1})),e.icon&&T.push(u(n,e.icon,s+12,c+6,p[e.status]||p.fg1)),T.push(...n.textLines(s+12+f,c+17,m,{...i.FONT.body,leading:17,fill:p.fg1}).children??[]),_.length){let t=n.textLines(s+12,C,_,i.FONT.label),a=typeof l.ticketBaseUrl==`string`&&l.ticketBaseUrl.replaceAll(`#TICKET#`,()=>encodeURIComponent(e.ticket)),o=a&&/^https?:\/\//i.test(a)&&(0,r.safeHref)(a);o&&!e.link?T.push(n.link(o,[t])):(T.push(t),a&&!o&&!E.some(e=>e.code===`IGNORED_INTERACTION`)&&E.push((0,i.warning)(`IGNORED_INTERACTION`,n.lang,e.line,`工单链接未启用`,`Ticket links are unavailable`,`使用安全的 HTTP(S) 工单地址`,`Use a safe HTTP(S) ticket URL`)))}T.push(...n.textLines(s+x-12,C+(g?0:_.length*16),v,{...i.FONT.label,anchor:`end`}).children??[]),e.link&&T.push(n.link(e.link.href,T.splice(d),e.link)),c+=b+8}),{x:o,h:c-b+h-(e.cards.length?8:0)}}),O=Math.max(...D.map(e=>e.h));T.unshift(...D.map(({x:e},t)=>n.rect(e,b,m,O,{rx:6,stroke:n.frameTone(p[c[t].status]||p.line),fill:`transparent`,meta:{kind:`frame`,id:`column:${t}`}})));let k=b+O+18;return(_>t*2||f>60)&&E.push((0,i.warning)(`LARGE_DIAGRAM`,n.lang,s.headerLine||1,`看板较大`,`Large kanban board`,`考虑拆分图表`,`Consider splitting the diagram`)),{width:_,height:k,scene:{width:_,height:k,children:T,title:d,heading:d},errors:E}}return e.implementations={kanban:{parse:l,layout:d,honoredConfig:s,acceptsPresentation:!0}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
KChartUnits["diagram/label"]=(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=new Map(`AElig:c6 Aacute:c1 Acirc:c2 Agrave:c0 Alpha:391 Aring:c5 Atilde:c3 Auml:c4 Beta:392 Ccedil:c7 Chi:3a7 Dagger:2021 Delta:394 ETH:d0 Eacute:c9 Ecirc:ca Egrave:c8 Epsilon:395 Eta:397 Euml:cb Gamma:393 Iacute:cd Icirc:ce Igrave:cc Iota:399 Iuml:cf Kappa:39a Lambda:39b Mu:39c Ntilde:d1 Nu:39d OElig:152 Oacute:d3 Ocirc:d4 Ograve:d2 Omega:3a9 Omicron:39f Oslash:d8 Otilde:d5 Ouml:d6 Phi:3a6 Pi:3a0 Prime:2033 Psi:3a8 Rho:3a1 Scaron:160 Sigma:3a3 THORN:de Tau:3a4 Theta:398 Uacute:da Ucirc:db Ugrave:d9 Upsilon:3a5 Uuml:dc Xi:39e Yacute:dd Yuml:178 Zeta:396
|
|
2
|
+
aacute:e1 acirc:e2 acute:b4 aelig:e6 agrave:e0 alefsym:2135 alpha:3b1 amp:26 and:2227 ang:2220 apos:27 aring:e5 asymp:2248 atilde:e3 auml:e4 bdquo:201e beta:3b2 brvbar:a6 bull:2022 cap:2229 ccedil:e7 cedil:b8 cent:a2 chi:3c7 circ:2c6 clubs:2663 cong:2245 copy:a9 crarr:21b5 cup:222a curren:a4 dArr:21d3 dagger:2020 darr:2193 deg:b0 delta:3b4 diams:2666 divide:f7 eacute:e9 ecirc:ea egrave:e8 empty:2205 emsp:2003 ensp:2002 epsilon:3b5 equiv:2261 eta:3b7 eth:f0 euml:eb euro:20ac exist:2203 fnof:192 forall:2200 frac12:bd frac14:bc frac34:be frasl:2044 gamma:3b3 ge:2265 gt:3e hArr:21d4 harr:2194 hearts:2665 hellip:2026 iacute:ed icirc:ee iexcl:a1 igrave:ec image:2111 infin:221e int:222b iota:3b9 iquest:bf isin:2208 iuml:ef kappa:3ba lArr:21d0 lambda:3bb lang:27e8 laquo:ab larr:2190 lceil:2308 ldquo:201c le:2264 lfloor:230a lowast:2217 loz:25ca lrm:200e lsaquo:2039 lsquo:2018 lt:3c macr:af mdash:2014 micro:b5 middot:b7 minus:2212 mu:3bc nabla:2207 nbsp:a0 ndash:2013 ne:2260 ni:220b not:ac notin:2209 nsub:2284 ntilde:f1 nu:3bd oacute:f3 ocirc:f4 oelig:153 ograve:f2 oline:203e omega:3c9 omicron:3bf oplus:2295 or:2228 ordf:aa ordm:ba oslash:f8 otilde:f5 otimes:2297 ouml:f6 para:b6 part:2202 permil:2030 perp:22a5 phi:3c6 pi:3c0 piv:3d6 plusmn:b1 pound:a3 prime:2032 prod:220f prop:221d psi:3c8 quot:22 rArr:21d2 radic:221a rang:27e9 raquo:bb rarr:2192 rceil:2309 rdquo:201d real:211c reg:ae rfloor:230b rho:3c1 rlm:200f rsaquo:203a rsquo:2019 sbquo:201a scaron:161 sdot:22c5 sect:a7 shy:ad sigma:3c3 sigmaf:3c2 sim:223c spades:2660 sub:2282 sube:2286 sum:2211 sup:2283 sup1:b9 sup2:b2 sup3:b3 supe:2287 szlig:df tau:3c4 there4:2234 theta:3b8 thetasym:3d1 thinsp:2009 thorn:fe tilde:2dc times:d7 trade:2122 uArr:21d1 uacute:fa uarr:2191 ucirc:fb ugrave:f9 uml:a8 upsih:3d2 upsilon:3c5 uuml:fc weierp:2118 xi:3be yacute:fd yen:a5 yuml:ff zeta:3b6 zwj:200d zwnj:200c
|
|
3
|
+
AMP:26 LT:3c GT:3e QUOT:22 COPY:a9 REG:ae NewLine:a Tab:9 num:23 colon:3a semi:3b sol:2f bsol:5c dollar:24 check:2713 checkmark:2713 cross:2717 star:2606 starf:2605 RightArrow:2192 LeftArrow:2190`.split(/\s+/).map(e=>{let[t,n]=e.split(`:`);return[t,Number.parseInt(n,16)]})),a=e=>e.replace(/(?:&#([0-9]+|[xX][\da-fA-F]+)|#([0-9]+)|[&#]([a-zA-Z][a-zA-Z\d]*));/g,(e,t,n,r)=>{let a=t??n,o=r?i.get(r):/^[xX]/.test(a)?Number.parseInt(a.slice(1),16):Number(a);return o===void 0?e:!o||o>1114111||o>=55296&&o<=57343?`�`:String.fromCodePoint(o)}),o=/<\/?(br|img|b|i|u|em|strong|small|sup|sub|span|code|mark|font|s|del|ins|kbd|a)(?=[\s/>])(?:"[^"]*"|'[^']*'|[^<>"'])*>/gi,s=/(?<![\w:-])fa[bsrlk]?:fa-[a-z\d]+(?:-[a-z\d]+)*/gi;function c(e,{lang:i,line:c=1}={}){let l=[],u=new Set,d=null,f=!1,p=(e,t,r)=>{u.has(e)||(u.add(e),l.push((0,n.warning)(`IGNORED_ASSET`,i,c,t,r,`改用纯文本或内置图标`,`Use plain text or a supported icon`)))},m=String(e??``),h=/^(?:"`([\s\S]*)`"|`([\s\S]*)`)$/.exec(m);return h&&(m=(0,r.stripEmphasis)(h[1]??h[2])),{text:m.split(/(\$\$[\s\S]*?\$\$)/).map((e,n)=>n%2?(p(`math`,`数学公式保留为 TeX 文本`,`Math shown as TeX source`),e.slice(2,-2)):a(e.replace(o,(e,t)=>(t=t.toLowerCase(),t===`img`&&p(`image`,`已移除标签中的图片`,`Removed an image from the label`),t===`br`?`
|
|
4
|
+
`:``))).replace(s,e=>{let n=(0,t.resolveIconRef)(e);return f||=(d=n,!0),n||p(e.toLowerCase(),`未知图标 ${e}`,`Unknown icon ${e}`),``})).join(``).replace(/^[ \t]+|[ \t]+$/g,``),icon:d,diagnostics:l}}return e.normalizeLabel=c,e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/support`],KChartUnits[`diagram/emphasis`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/layers"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n={layers:8,groups:6,items:30,labelWidth:208},r=12,i=12,a=8,o=32,s=56,c=40,l=(e,n,r,i,a=`拆成两张图,或把说明移到图外`,o=`Split into two diagrams, or move descriptions outside the diagram`)=>(0,t.error)(e,n,r,i,a,o);function u(e,r){let i={...r,lang:r.lang,firstLine:r.firstLine,options:r.options||{}},{items:a,errors:o}=(0,t.parseIndented)(e,i),{lang:s,options:c}=i;for(let e of Object.keys(c))o.push(l(s,i.firstLine-1,`layers 不支持选项「${e}」`,`Unsupported layers option: ${e}`,`移除这个选项`,`Remove this option`));let u=a.map(e=>/[::]/.test(e.text.split(`|`)[0])||!e.text.includes(`|`)&&e.children.some(e=>/^[^::>]+>/.test(e.text)));u.some(Boolean)&&u.some(e=>!e)&&o.push(l(s,a[u.findIndex(e=>e!==u[0])].line,`顶层不能混用层与分组`,`Do not mix layers and groups at the top level`,`顶层全部写成层,或全部写成分组`,`Use only layers or only groups at the top level`));function d(e,t){return e.split(/[,,]/).map(e=>{let n=e.trim(),r=n.match(/^([+~=])\s*/)?.[1]||``;return n&&n.replace(/^[+~=]\s*/,``)||o.push(l(s,t,`能力项名称不能为空`,`Capability labels cannot be empty`,`删除空项或补上名称`,`Remove the empty item or add a label`)),{label:r?`${r} ${n.replace(/^[+~=]\s*/,``)}`:n,mark:r,tone:{"+":`new`,"~":`info`,"=":`ok`}[r]||``,line:t}})}function f(e){let t=e.text.split(/[::]/),r=t.shift().trim(),i=r.match(/\s*\{(db|ext)\}$/)?.[1]||``,a=r.replace(/\s*\{(db|ext)\}$/,``).trim();(!a||/[{}|>]/.test(a))&&o.push(l(s,e.line,`分组名称或标志无效`,`Invalid group name or flag`,`使用「名称 {db}: 项, 项」或普通名称`,`Use "Name {db}: item, item" or a plain name`));let c={title:a,flag:i,line:e.line,items:[],categories:[]};if(t.length)c.items=d(t.join(`:`),e.line),e.children.length&&o.push(l(s,e.children[0].line,`行内能力项不能再带子项`,`Inline capabilities cannot have children`,`改成分类行写法,或删除子项`,`Use category rows, or remove the children`));else{e.children.length||o.push(l(s,e.line,`分组中没有能力项`,`Group has no capabilities`,`在名称后加「: 项, 项」,或添加分类行`,`Add ": item, item" or category rows`));for(let t of e.children){let e=t.text.match(/^(.+?)\s*>\s*(.+)$/);if(!e||t.children.length){o.push(l(s,t.children[0]?.line||t.line,`分类行写法无效`,`Invalid category row`,`使用「- 分类 > 项, 项」,不嵌套子项`,`Use "- Category > item, item" without nesting`));continue}let n={label:e[1].trim(),line:t.line,items:d(e[2],t.line)};c.categories.push(n),c.items.push(...n.items)}}return c.items.length>n.items&&o.push(l(s,e.line,`每组最多 ${n.items} 项`,`At most ${n.items} capabilities per group`)),c}let p=!u.some(Boolean),m=p?a.map(e=>{let[t,...r]=e.text.split(`|`).map(e=>e.trim());return(!t||/[{}>]/.test(t))&&o.push(l(s,e.line,`层名称无效`,`Invalid layer name`,`使用「- 层名 | 说明」`,`Use "- Layer | description"`)),e.children.length||o.push(l(s,e.line,`层中没有分组`,`Layer has no groups`,`给这一层添加分组和能力项`,`Add groups and capabilities to this layer`)),e.children.length>n.groups&&o.push(l(s,e.line,`每层最多 ${n.groups} 组`,`At most ${n.groups} groups per layer`)),{title:t,description:r.join(` | `),line:e.line,groups:e.children.map(f)}}):[],h=p?[]:a.map(f);return a.length||o.push(l(s,i.firstLine,`图中没有条目`,`Diagram is empty`,`添加层、分组与能力项`,`Add layers, groups and capabilities`)),p&&m.length>n.layers&&o.push(l(s,a[n.layers].line,`最多 ${n.layers} 层`,`At most ${n.layers} layers`)),{model:{type:`layers`,layered:p,layers:m,groups:h},errors:o}}function d(e,{measure:u,width:d,lang:f}){let p=[],m=[],h=[],g=[],_=e.layered?e.layers.flatMap(e=>e.groups):e.groups;for(let e of _)for(let r of e.items)u(r.label.replace(/^[+~=]\s*/,``),t.FONT.body)>n.labelWidth&&p.push(l(f,r.line,`能力项「${r.label}」过长`,`Capability label is too long: ${r.label}`,`把说明移到图外,名称缩短至约 16 个汉字`,`Move descriptions outside; shorten the label to about 16 CJK characters`));if(p.length)return{width:d,height:0,errors:p};let v=(e,n)=>(0,t.snap)(Math.max(e.flag===`db`?80:64,...e.items.map(e=>u(e.label,t.FONT.body)+n))),y=(e,t)=>e.flag===`db`?Math.max(1,Math.round((t*o+(t-1)*a)/64)):t,b=(e,t)=>Math.max(1,Math.ceil(e.items.length/y(e,t))),x=e=>(0,t.snap)(Math.max(0,...e.categories.map(e=>u(e.label,t.FONT.body)))+16);function S(e,n,r){let i;if(e.categories.length)i=x(e)+a+Math.max(...e.categories.map(e=>e.items.reduce((e,n)=>e+(0,t.snap)(Math.max(64,u(n.label,t.FONT.body)+r)),0)+a*(e.items.length-1)));else{let t=b(e,n);i=t*v(e,r)+a*(t-1)}return(0,t.snap)(Math.max(i,u(e.title,t.FONT.title))+24)}let C=(e,t)=>52+(e.categories.length?e.categories.length*(e.flag===`db`?s:o)+(e.categories.length-1)*a:y(e,t)*(e.flag===`db`?s:o)+(y(e,t)-1)*a),w=(e,t,n)=>e.reduce((e,r)=>e+S(r,t,n),0)+r*(e.length-1);function T(e,t,n){let r=Math.max(0,n-e.reduce((e,t)=>e+t,0)),i=t.reduce((e,t)=>e+t,0),a=e.map((e,n)=>e+Math.floor(r*t[n]/i/4)*4);return a[a.length-1]+=n-a.reduce((e,t)=>e+t,0),a}let E=0;function D(e,n,r,l,d,f,p){let h={...e,x:n,y:r,w:l,h:d,rows:f,color:p,id:`group-${E++}`,nodes:[],categoryNodes:[]};m.push(h);let _=(t,n,r,i,a,o=!1)=>{let s={...t,x:n,y:r,w:i,h:a,shape:!o&&e.flag===`db`?`db`:`rect`,group:h.id,category:o,color:p};g.push(s),(o?h.categoryNodes:h.nodes).push(s)},v=l-24;if(e.categories.length){let l=x(e),d=e.flag===`db`?s:o;e.categories.forEach((e,o)=>{let s=r+c+o*(d+a);_({label:e.label,line:e.line},n+i,s,l,d,!0);let f=e.items.map(e=>(0,t.snap)(Math.max(64,u(e.label,t.FONT.body)+16))),p=T(f,f.map(e=>e+8),v-l-a*e.items.length),m=n+i+l+a;e.items.forEach((e,t)=>{_(e,m,s,p[t],d),m+=p[t]+a})})}else{let t=b(e,f),u=e.flag===`db`?s:o,d=Math.ceil(e.items.length/t),p=r+c;for(let r=0;r<d;r+=1){let o=e.items.slice(r*t,(r+1)*t),s=e.flag===`db`,c=s?t:o.length,d=Math.floor((v-(c-1)*a)/c/4)*4,f=n+i+(s?Math.floor((v-(o.length*d+(o.length-1)*a))/8)*4:0);o.forEach((e,t)=>{let c=!s&&t===o.length-1?n+l-i-f:d;_(e,f,p+r*(u+a),c,u),f+=d+a})}}return h}let O=Math.floor(d),k=4;if(e.layered){let i=e=>u(e.title,t.FONT.title)+16,a=e=>e.description?Math.min(120,u(e.description,t.FONT.label)+8):0,o=(0,t.snap)(Math.max(80,...e.layers.map(e=>Math.max(i(e),a(e))))),s=Math.min(o,160);o>160&&e.layers.some(e=>i(e)>160)&&p.push(l(f,e.layers.find(e=>i(e)>160).line,`层名称过长`,`Layer name is too long`,`缩短层名,把说明放在「|」之后`,`Shorten the name; put descriptions after "|"`));let c=4+s+r;for(let t of e.layers)O=Math.max(O,c+w(t.groups,n.items*2,16)+4);let d=O-c-4;for(let i of e.layers){let e=1;for(;e<n.items*2&&w(i.groups,e,16)>d;)e+=1;let a=T(i.groups.map(t=>S(t,e,16)),i.groups.map(t=>S(t,e,24)),d-r*(i.groups.length-1)),o=i.description?(0,t.wrapText)(i.description,s-8,t.FONT.label,u):[],l=Math.max(...i.groups.map(t=>C(t,e)),32+o.length*16),f=h.length%6+1;h.push({...i,x:4,y:k,w:s,h:l,rows:e,color:f,descriptionLines:o});let p=c;i.groups.forEach((t,n)=>{D(t,p,k,a[n],l,e,f),p+=a[n]+r}),k+=l+16}}else{for(let t of e.groups)O=Math.max(O,S(t,n.items*2,16)+8);let t=O-8,i=new Map(e.groups.map(e=>{let r=1;for(;!e.categories.length&&r<n.items*2&&S(e,r,16)>t;)r+=1;return[e,r]})),a=e=>i.get(e),o=[],s=[];for(let n of e.groups)s.length&&s.reduce((e,t)=>e+S(t,a(t),16),0)+r*s.length+S(n,a(n),16)>t&&(o.push(s),s=[]),s.push(n);s.length&&o.push(s);for(let n of o){let i=T(n.map(e=>S(e,a(e),16)),n.map(e=>S(e,a(e),24)),t-r*(n.length-1)),o=Math.max(...n.map(e=>C(e,a(e)))),s=4;n.forEach((t,n)=>{D(t,s,k,i[n],o,a(t),e.groups.indexOf(t)%6+1),s+=i[n]+r}),k+=o+16}}return{type:`layers`,width:O,height:k-12,layers:h,groups:m,nodes:g,errors:p}}function f(e,n){let r=[],i=(0,t.appearance)(n),a=e=>n.frameTone(n.color(`tone${e}`)),o=(e,t,r,i,a)=>n.text(e,t,r,{size:i.size,weight:i.weight,fill:a,anchor:`middle`,"dominant-baseline":`central`}),s=(e,r)=>{let a=e.tone&&e.label.match(/^([+~=])\s/);if(!a)return o(e.x+e.w/2,r,e.label,t.FONT.body,i.fg1);let s=e.x+e.w/2-n.measure(e.label,t.FONT.body.size,t.FONT.body.weight)/2,c=n.measure(a[1],t.FONT.body.size,t.FONT.body.weight);return n.el(`g`,{},[n.text(s,r,a[1],{size:t.FONT.body.size,weight:t.FONT.body.weight,fill:i[e.tone],anchor:`start`,"dominant-baseline":`central`}),n.text(s+c,r,e.label.slice(1),{size:t.FONT.body.size,weight:t.FONT.body.weight,fill:i.fg1,anchor:`start`,"dominant-baseline":`central`})])};for(let s of e.groups){let e=a(s.color),c=n.tint(i.bg,e,.07),l=n.tint(i.bg,e,.45);r.push(n.rect(s.x,s.y,s.w,s.h,{rx:i.radius,fill:c,stroke:l,"stroke-width":1,"stroke-dasharray":s.flag===`ext`?`5 4`:void 0,meta:{kind:`layers`,group:s.id,role:`group`}})),r.push(o(s.x+s.w/2,s.y+20,s.title,t.FONT.title,i.fg1))}for(let n of e.layers){let e=n.y+n.h/2,a=n.descriptionLines.length*16,s=e-(20+(a?a+4:0))/2;r.push(o(n.x+n.w/2,s+10,n.title,t.FONT.title,i.fg1)),n.descriptionLines.forEach((e,a)=>r.push(o(n.x+n.w/2,s+20+4+(a+.5)*16,e,t.FONT.label,i.fg2)))}for(let t of e.nodes){let e=t.tone?i[t.tone]:a(t.color),o=t.tone?n.mix:n.tint,c=t.category?o(i.bg,e,.08):i.node,l=o(i.bg,e,.4),u={fill:c,stroke:l,"stroke-width":1,"stroke-dasharray":t.category?`5 4`:void 0,meta:{kind:`layers`,group:t.group,line:t.line,role:t.category?`category`:`capability`}};if(t.shape===`db`){let{x:e,y:i,w:a,h:o}=t;r.push(n.path(`M${e} ${i+8} a${a/2} 8 0 0 1 ${a} 0 V${i+o-8} a${a/2} 8 0 0 1 ${-a} 0 Z`,{...u,meta:{...u.meta,shape:`database`}})),r.push(n.path(`M${e} ${i+8} a${a/2} 8 0 0 0 ${a} 0`,{fill:`none`,stroke:l,"stroke-width":1,meta:{...u.meta,role:`database-rim`}}))}else r.push(n.rect(t.x,t.y,t.w,t.h,{rx:i.smallRadius,...u}));r.push(s(t,t.y+t.h/2+(t.shape===`db`?4:0)))}return{width:e.width,height:e.height,children:r}}return e.implementations={layers:{parse:u,layout:d,scene:f}},e.limits=n,e})({},KChartUnits[`diagram/support`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/map-label"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function n(e,n){let r=new Set;return(i,a)=>{let{text:o,icon:s,diagnostics:c}=(0,t.normalizeLabel)(i,{lang:e,line:a});for(let e of c){let t=`${e.code}:${e.message}`;r.has(t)||(r.add(t),n(e))}return{text:o,icon:s}}}function r(e,t,n,r,i){let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=14/Math.max(s,c),u=t.set===`simple`;return e.el(`g`,{transform:`translate(${n} ${r}) scale(${l}) translate(${-a-s/2} ${-o-c/2})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function i(e,t){return Object.entries(e??{}).find(([e])=>e.toLowerCase()===t.toLowerCase())?.[1]}return e.mapConfig=i,e.mapIcon=r,e.mapLabels=n,e})({},KChartUnits[`diagram/label`]);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
KChartUnits["diagram/mindmap"]=(function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=2e3,l=100,u=[`bilateral`,`right`,`left`,`radial`,`org`,`brace`,`fishbone`,`timeline`],d=new Set([`tidy-tree`,`dagre`,`elk`,`cose-bilkent`]),f=[[`((`,`))`,`circle`],[`))`,`((`,`bang`],[`{{`,`}}`,`hexagon`],[`-)`,`(-`,`cloud`],[`(-`,`-)`,`cloud`],[`[`,`]`,`rect`],[`(`,`)`,`rounded`],[`)`,`(`,`cloud`]],p=/[()[\]{}]|-\)|\(-/,m=e=>e.length>1&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e;function h(e){let t=e.trim(),n=t.search(p);if(n<0)return{label:m(t).trim(),shape:`none`};for(let[e,r,i]of f)if(!(!t.startsWith(e,n)||!t.endsWith(r)||t.length<n+e.length+r.length))return{label:m(t.slice(n+e.length,t.length-r.length).trim()).trim(),shape:i};return{label:t,shape:``}}function g(e,n,r,i){let a=[];for(let[o,s]of e.entries()){if(!s.trim()||s.trimStart().startsWith(`%%`))continue;let e=n+o;if(/^[ \t]*\t/.test(s)){i.push((0,t.error)(r,e,`缩进不能使用 Tab`,`Tabs are not allowed in indentation`,`把 Tab 换成空格`,`Replace tabs with spaces`));continue}let c=s.match(/^ */)[0].length;a.push({text:s.slice(c).trimEnd(),line:e,indent:c})}return a}function _(e,a={}){let f=a.lang||`zh`,m=Number.isInteger(a.firstLine)?a.firstLine:2,_=a.headerLine||m-1,v=[],y=(e,n,r,i=`修正脑图语法后重试`,a=`Correct the mindmap syntax and try again`,o=1)=>{v.push((0,t.error)(f,e,n,r,i,a,o))},b=String(e??``).split(`
|
|
2
|
+
`),x=(0,n.presentation)({lang:f}),S=new Set,C=new Map,w=e=>{S.has(e.message)||(S.add(e.message),v.push(e))},T=new Map,E=-1;for(let e=0;e<b.length;e+=1){let n=b[e].trim();if(n&&!n.startsWith(`%%`)){if(x.accept(n,m+e))b[e]=``;else if(/^(?::::|::icon\b)/i.test(n)){b[e]=``;let r=/^:::\s*([\w-]+(?:\s+[\w-]+)*)$/.exec(n)?.[1],a=/^::icon\(\s*([^()]+?)\s*\)$/i.exec(n)?.[1];if(E<0||!r&&!a)y(m+e,`脑图装饰无效或前面缺少节点`,`Malformed mindmap decoration or missing preceding node`);else{let n=T.get(E)||{classes:[]};r&&n.classes.push(...r.split(/\s+/)),a&&(n.icon=(0,i.resolveIconRef)(a),n.icon||w((0,t.warning)(`IGNORED_ASSET`,f,m+e,`未知图标 ${a}`,`Unknown icon ${a}`,`改用内置图标`,`Use a supported icon`))),T.set(E,n)}}else E=e}}let D=g(b,m,f,v),O=[],k=[],A=new Map,j=0,M=0;for(let e of D){for(;k.length&&e.indent<=k.at(-1).indent;)k.pop();let t=k.at(-1)?.node??null,n=k.length;M=Math.max(M,n+1);let{label:i,shape:a}=h(e.text),o=(a===`none`?``:e.text.split(p,1)[0].trim())||i,s=(0,r.normalizeLabel)(i,{lang:f,line:e.line});s.diagnostics.forEach(w);let u=s.text||(s.icon?o||` `:``);j+=1,j===2001&&y(e.line,`脑图超过安全上限 ${c} 个节点`,`Mindmap exceeds the safety cap of ${c} nodes`,`拆分脑图后重试`,`Split the mindmap and try again`),n>=l&&y(e.line,`脑图超过安全深度上限 ${l} 层`,`Mindmap exceeds the safety depth cap of ${l}`,`拆分脑图或降低层级`,`Split the mindmap or reduce its depth`),/:::(?:[\w-]+)?|::icon\(/i.test(e.text)&&y(e.line,`不支持行内节点装饰`,`Inline node decorations are unsupported`,`在节点下一行使用受控 :::状态 标记`,`Use a supported :::status marker on the next line`),u||y(e.line,`节点名称不能为空`,`Node label cannot be empty`);let d={label:u,children:[]};a&&(d.shape=a);let g=T.get(e.line-m);g?.classes.length&&x.addClasses(o,g.classes,e.line),C.set(d,{id:o,icon:g?.icon||s.icon});let _=t?t.children.length:O.length;A.set(t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`,e.line);let v=t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`;t?t.children.push(d):O.length?(y(e.line,`mindmap 只能有一个根节点:「${u}」没有父节点`,`A mindmap can have only one root: "${u}" has no parent`,`把该节点缩进到更浅一级的节点下面`,`Indent this node under a shallower node`),O[0].children.push(d)):O.push(d),k.push({indent:e.indent,node:d,path:v})}O.length||y(m,`脑图中没有节点`,`Mindmap is empty`,`保留一个根节点并将其他节点缩进到它下面`,`Keep one root node and indent all other nodes beneath it`);let N=a.config?.layout??a.config?.mindmap?.layoutAlgorithm??(typeof a.layout==`string`?a.layout:a.layout?.config?.layout??a.layout?.layout),P=`bilateral`;if(N!=null&&N!==``){let e=String(N).toLowerCase();d.has(e)?P=`bilateral`:u.includes(e)?P=e:v.push((0,t.warning)(`IGNORED_CONFIG`,f,_,`脑图布局「${N}」不生效;按 bilateral 排版`,`Mindmap layout "${N}" is not honored; laid out as bilateral`,`改用 bilateral、right、left、radial、org、brace、fishbone 或 timeline`,`Use bilateral, right, left, radial, org, brace, fishbone, or timeline`))}for(let e of Object.keys(a.options||{}))y(_,`脑图头行不支持选项「${e}」`,`Mindmap header option is unsupported: ${e}`,`移除头行选项,使用 config.layout 指定布局`,`Remove the header option; use config.layout to choose a layout`);let F=O[0]||{label:``};A.has(`/roots/0`)&&A.set(`/data`,A.get(`/roots/0`)),v.push(...x.diagnostics());for(let[e,{id:t,icon:n}]of C){let r=x.statusOf(t);r&&(e.status=r),e[s.mindmapPresentation]={icon:n,link:x.linkOf(t)}}let I={chart:`mindmap`,data:F,layout:P,[s.mindmapPresentation]:!0,[o.sizeBudget]:{nodes:2001,depth:101}};Object.defineProperties(I,{nodeCount:{value:j},maxDepth:{value:M}}),a.title&&(I.title=a.title);let L=(0,o.validate)(I);for(let e of L.errors){let n=``,r=m;for(let t of e.path.split(`/`).slice(1))n+=`/${t}`,A.has(n)&&(r=A.get(n));v.push({...(0,t.error)(f,r,e.message,e.message,e.fix,e.fix),code:e.code,path:e.path})}return{model:I,errors:v}}var v=(0,a.createRegistry)(o.validate);v.register(`mindmap`,a.layouts.get(`mindmap`));function y(e,n={},r={}){let i=e.nodeCount>80&&e.layout!==`radial`,a=v.layout(i?{...e,layout:`radial`}:e,n.renderOptions||n),o=n.width||800,s=e.nodeCount>60||e.maxDepth>5||a.width>o*2?[(0,t.warning)(`LARGE_DIAGRAM`,r.lang||n.lang||`zh`,r.firstLine||1,i?`大型脑图使用径向布局以避免重叠`:`脑图较大,可在图内滚动查看`,i?`Large mindmap uses radial layout to avoid overlaps`:`Large mindmap; scroll within the figure`,`拆分脑图以便阅读`,`Split the mindmap for readability`)]:[];return{width:a.width,height:a.height,scene:a,errors:s}}return e.implementations={mindmap:{acceptsPresentation:!0,honoredConfig:[`layout`,`mindmap.layoutAlgorithm`],parse:_,layout:y,scene:e=>e.scene}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/label`],KChartUnits[`core/icons`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`],KChartUnits[`chart/mindmap`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/numeric-composition"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function s(e,t,r,i){return{...i,parse:e,validate:(e,i)=>(0,n.validateWith)(t(e,i),i,t=>r(e,t.path)),layout:(e,i,a)=>(0,n.renderWith)(t(e,a),i,a,t=>r(e,t.path))}}var c=s(t.parsePie,e=>({chart:`pie`,title:e.title||void 0,sliceLabels:!0,data:e.rows.map(({category:e,value:t})=>({category:e,value:t})),encode:{category:`category`,value:`value`},[r.compositionPresentation]:{labelRadius:e.labelRadius}}),(e,t)=>t===`/title`?e.titleLine:e.rows[Number(t?.split(`/`)[2])]?.line||e.rows[0]?.line,{optionMode:`raw`,honoredConfig:[`pie.textPosition`]}),l=(e,n)=>({chart:`treemap`,title:e.title||void 0,data:e.data,fields:e.valueField?{value:e.valueField}:void 0,[r.compositionPresentation]:{showValues:n.config?.treemap?.showValues!==!1,prefix:e.prefix,namedRoot:e.namedRoot},[a.sizeBudget]:{nodes:t.TREEMAP_MAX_NODES+1,depth:t.TREEMAP_MAX_DEPTH+1}}),u=(e,t)=>{if(t===`/title`)return e.titleLine;for(let n=t;n;n=n.slice(0,n.lastIndexOf(`/`))){if(e.treeLines[n])return e.treeLines[n];if(!n.includes(`/`))break}return null},d=(0,i.createRegistry)(a.validate);return d.register(`treemap`,i.layouts.get(`treemap`)),e.implementations={pie:c,treemap:{parse:t.parseTreemap,acceptsPresentation:!0,honoredConfig:[`treemap.showValues`,`treemap.valueFormat`],validate(e,t){let r=l(e,t);return(0,n.diagnostics)((0,a.validate)(r).errors,t,t=>u(e,t.path))},layout(e,t,r){let i=l(e,r),a=(0,n.renderWith)(i,t,r,t=>u(e,t.path),d.layout);return a.scene&&(e.nodeCount>60||e.depth>5||a.width>t.width*2)&&a.errors.push((0,o.warning)(`LARGE_DIAGRAM`,r.lang,r.headerLine,`矩形树图较大,可滚动查看`,`Large treemap; scroll to view it`,`考虑拆分图表`,`Consider splitting the chart`)),a}}},e})({},KChartUnits[`diagram/numeric-parse`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/composition`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`],KChartUnits[`diagram/support`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/numeric-model"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e,n,r){return e.map(e=>(0,t.error)(n.lang,r(e)||n.firstLine,e.message||`KChart 声明无效`,e.message||`Invalid KChart declaration`,e.fix||`修正图表声明`,e.fix||`Correct the chart declaration`))}function s(e,t,n){return o((0,r.validate)(e).errors,t,n)}function c(e,t){if(t.renderOptions?.frame)return e;let{ctx:n}=t,r=e.heading||``,i=e.subtitle||``;if(!r&&!i)return e;let a=Math.max(24,e.width-32),o=[],s=16,c=e.width,l=(e,t,r)=>{if(!e)return;let i=n.wrap(e,a,t,r),l=t+6;c=Math.max(c,32+Math.max(0,...i.map(e=>n.measure(e,t,r)))),o.push(n.textLines(16,s+t,i,{leading:l,size:t,weight:r,fill:n.color(r>400?`fg`:`muted`)})),s+=i.length*l+6};return l(r,16,650),l(i,12,400),s+=8,{...e,width:c,height:e.height+s,children:[...o,n.el(`g`,{transform:`translate(0 ${s})`},e.children)]}}function l(e,t,n,r,s=i.layout){let l={...t.renderOptions,width:t.width,lang:n.lang,...!t.renderOptions?.measure&&t.measure?{measure:(e,n=12,r=400)=>t.measure(e,{size:n,weight:r})}:{}};try{let n=c(s(e,l),t);return{width:n.width,height:n.height,scene:n,errors:[]}}catch(e){if(!(e instanceof a.ExpectedDiagnostic))throw e;return{width:t.width,height:0,errors:o(e.errors||[],n,r)}}}function u(e,r,i,a){let{text:o,icon:s,diagnostics:c}=(0,n.normalizeLabel)(e,{lang:r.lang,line:i});s&&c.push((0,t.warning)(`IGNORED_ASSET`,r.lang,i,`数值图标签仅绘制文字,不绘制图标`,`Numeric chart labels show text only; icons are omitted`,`改用纯文本标签`,`Use a text label`));for(let e of c)a.some(t=>t.message===e.message)||a.push(e);return o.trim()||String(e)}return e.diagnostics=o,e.numericLabel=u,e.renderWith=l,e.validateWith=s,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`chart/spec`],KChartUnits[`chart/registry`],KChartUnits[`core/diagnostics`]);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
KChartUnits["diagram/numeric-parse"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=(e,n,r,i)=>(0,t.error)(e.lang,n,r,i,`修正图表语法`,`Correct the chart syntax`),o=e=>e.replace(/^(["'])(.*)\1$/,`$2`),s=e=>/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$/i.test(e)&&Number.isFinite(Number(e)),c=201,l=100,u=(e,t)=>e.split(`
|
|
2
|
+
`).map((e,n)=>({raw:e,text:e.trim(),line:t+n})).filter(e=>e.text&&!e.text.startsWith(`%%`));function d(e,n){let i=[],c=[],l=new Set,d=[],f=n.headerLine||n.firstLine-1,p=(n.params||``).trim(),m=/^showData\b/i.test(p)||n.options?.showData===!0,h=p.replace(/^showData\b\s*/i,``),g=null,_=null,v=(e,t)=>{g===null?(g=(0,r.numericLabel)(o(e),n,t,i),_=t):i.push(a(n,t,`pie 只能有一个 title`,`Pie accepts only one title`))};/^title\s+\S/i.test(h)?v(h.replace(/^title\s+/i,``),f):h&&i.push(a(n,f,`pie 只支持 showData 和 title`,`Pie only supports showData and title`));for(let{text:t,line:f}of u(e,n.firstLine)){if(/^title\s+/i.test(t)){v(t.replace(/^title\s+/i,``),f);continue}let e=/^(.+?)\s*:\s*(\S+)$/.exec(t),u=e&&(0,r.numericLabel)(o(e[1]),n,f,i);!u||!s(e[2])||+e[2]<0?i.push(a(n,f,`pie 数据必须是非负有限数值及非空标签`,`Pie sections require a label and a finite nonnegative value`)):l.has(u)?d.push({label:u,line:f}):(l.add(u),c.push({category:u,value:+e[2],line:f}))}if(c.length||i.push(a(n,n.firstLine,`pie 至少需要一条数据`,`Pie requires at least one section`)),d.length){let e=[...new Set(d.map(e=>e.label))].join(`, `);i.push((0,t.warning)(`DIAGRAM_HINT`,n.lang,d[0].line,`pie 重复标签仅保留首次值:${e}`,`Pie keeps the first value for duplicate labels: ${e}`,`删除重复条目`,`Remove duplicate sections`))}if(c.length>60&&i.push((0,t.warning)(`LARGE_DIAGRAM`,n.lang,c[60].line,`饼图条目较多,建议拆分图表`,`Large pie chart; consider splitting it`,`请拆分图表`,`Split the chart`)),c.length>6){let e=c.splice(5),r=e.reduce((e,t)=>e+t.value,0),o=e.map(e=>e.category).join(`, `),s=`${/^en/i.test(n.lang)?`Other`:`其他`} (${o})`;for(;l.has(s);)s+=`*`;r>0||i.push(a(n,e[0].line,`pie 合并项的总值必须大于零`,`The combined pie section must have a positive total`)),c.push({category:s,value:r,line:e[0].line}),i.push((0,t.warning)(`DIAGRAM_HINT`,n.lang,e[0].line,`pie 已将其余条目合并为其他:${o}`,`Pie combines remaining sections as Other: ${o}`,`如需分别展示,请拆分图表`,`Split the chart to show these sections separately`))}let y=n.config?.pie?.textPosition,b=Number.isFinite(y)?Math.max(.5,Math.min(.95,y)):.72;return y!==void 0&&y!==b&&i.push((0,t.warning)(`IGNORED_CONFIG`,n.lang,n.configLines?.[`pie.textposition`]||f,`pie.textPosition 调整为 ${b}`,`pie.textPosition adjusted to ${b}`,`使用 0.5 至 0.95`,`Use a value from 0.5 to 0.95`)),{model:{chart:`pie`,title:g,titleLine:_,showData:m,rows:c,labelRadius:b},errors:i}}function f(e,c){let l=[],d=[],f=[],p=[],m=new Map,h=0,g=(0,n.presentation)({lang:c.lang}),_=null,v=null;for(let e of Object.keys(c.options||{}))l.push(a(c,c.headerLine,`treemap 不支持选项 ${e}`,`Unsupported treemap option ${e}`));for(let{raw:n,text:i,line:y}of u(e,c.firstLine)){if(g.accept(i,y))continue;if(/^title\s+/i.test(i)){_===null?(_=(0,r.numericLabel)(o(i.replace(/^title\s+/i,``)),c,y,l),v=y):l.push(a(c,y,`treemap 只能有一个 title`,`Treemap accepts only one title`));continue}let e=n.match(/^[ \t]*/)[0];if(e.includes(` `)){l.push((0,t.error)(c.lang,y,`treemap 缩进不能使用 Tab`,`Treemap indentation cannot use tabs`,`用空格缩进`,`Indent with spaces`,e.indexOf(` `)+1));continue}let u=/:::\s*([\w-]+)\s*$/.exec(i),b=u?i.slice(0,u.index).trimEnd():i,x=/^("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^:,]+?)(?:\s*[:,]\s*(.+))?$/.exec(b),S=x&&o(x[1].trim());if(!S||/:::|[{}]/.test(S)){l.push(a(c,y,`treemap 节点名称无效`,`Invalid treemap node name`));continue}h+=1,h===202&&l.push(a(c,y,`treemap 超过安全上限 201 个节点`,`Treemap exceeds the safety cap of 201 nodes; split the diagram`));let C={label:(0,r.numericLabel)(S,c,y,l),children:[],line:y};if(u&&g.addClasses(S,[u[1]],y),m.set(C,S),x[2]!==void 0){let e=x[2].replace(/[_,]/g,``);!s(e)||Number(e)<0||x[2].includes(`:::`)?l.push(a(c,y,`treemap 权重必须是非负有限数`,`Treemap weights must be finite and nonnegative`)):C.value=Number(e)}let w=e.length;for(;f.length&&w<=f.at(-1).indent;)f.pop();let T=f.length;T&&p[T]!==void 0&&p[T]!==w&&l.push(a(c,y,`treemap 同级缩进不一致`,`Treemap sibling indentation must match`)),p[T]??=w,(T?f.at(-1).node.children:d).push(C),f.push({indent:w,node:C})}d.length||l.push(a(c,c.firstLine,`treemap 需要至少一个根节点`,`Treemap requires at least one root`));let y=d.length===1?d[0]:{label:`Treemap`,children:d,line:c.firstLine},b={},x=0,S=(e,t,n)=>{x=Math.max(x,n),b[t]=e.line,n>100?l.push(a(c,e.line,`treemap 超过安全深度上限 100 层`,`Treemap exceeds the safety depth cap of 100; split the diagram`)):(e.children.forEach((e,r)=>S(e,`${t}/children/${r}`,n+1)),e.children.length&&e.value!==void 0&&l.push(a(c,e.line,`有子项的 treemap 节点不能同时指定权重`,`Treemap sections with children cannot have weights`)),!e.children.length&&e.value===void 0&&l.push(a(c,e.line,`treemap 叶节点必须指定权重`,`Treemap leaves require a weight`)),delete e.line)};d.length&&S(y,`/data`,1);for(let[e,t]of m)e[i.compositionPresentation]={status:g.statusOf(t),link:g.linkOf(t)};l.push(...g.diagnostics());let C=c.config?.treemap?.valueFormat,w;if(C!==void 0&&C!==`,`){let e=/^(\$)?(?:,)?(?:\.([0-6]))?(%|f)?$/.exec(typeof C==`string`?C:``);C===`$0,0`?w={unit:`$`,decimals:0}:e&&C?w={...e[1]&&e[3]!==`%`?{unit:`$`}:{},...e[2]?{decimals:+e[2]}:{},...e[3]===`%`?{format:`percent`}:{}}:l.push((0,t.warning)(`IGNORED_CONFIG`,c.lang,c.configLines?.[`treemap.valueformat`]||c.firstLine,`未识别 treemap.valueFormat ${C}`,`Unsupported treemap.valueFormat ${C}`,`使用默认数字格式`,`Use the default number format`))}return{model:{chart:`treemap`,title:_,titleLine:v,treeLines:b,data:y,nodeCount:h,depth:x,namedRoot:d.length===1&&y.children.length>0,valueField:w,prefix:w?.format===`percent`&&C.startsWith(`$`)?`$`:``},errors:l}}return e.TREEMAP_MAX_DEPTH=l,e.TREEMAP_MAX_NODES=c,e.parsePie=d,e.parseTreemap=f,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/composition`]);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
KChartUnits["diagram/numeric-radar"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=24,i=3,a=6,o=2,s=8,c=5,l=e=>{let t=String(e).trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1).replace(/\\([\\"'])/g,`$1`):t},u=e=>/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(String(e).trim())?Number(e):null,d=(e,n,r,i,a=`修正 Mermaid radar 语法`,o=`Correct the Mermaid radar syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),f=(e,n,r,i,a,o)=>(0,t.warning)(`DIAGRAM_HINT`,e.lang,n,r,i,a,o);function p(e,t){let n=[],r=null,i=0,a=0;return String(e).split(`
|
|
2
|
+
`).forEach((e,o)=>{let s=e.trim();(r!==null||s&&!s.startsWith(`%%`))&&(r===null&&(i=t+o,r=``),r+=(r?`
|
|
3
|
+
`:``)+s,a=Math.max(0,a+(s.match(/\{/g)||[]).length-(s.match(/\}/g)||[]).length),a||(n.push({text:r,line:i}),r=null))}),r!==null&&n.push({text:r,line:i}),n}function m(e){let t=[],n=``,r=``,i=0;for(let a of e)r?(n+=a,a===r&&(r=``)):a===`"`||a===`'`?(r=a,n+=a):((a===`[`||a===`{`)&&(i+=1),(a===`]`||a===`}`)&&--i,a===`,`&&i===0?(t.push(n.trim()),n=``):n+=a);return t.push(n.trim()),t}var h=`(?:\\[\\s*(?:"((?:[^"\\\\]|\\\\.)*)"|'((?:[^'\\\\]|\\\\.)*)'|([^\\]]*))\\s*\\])?`,g=`[\\p{L}\\p{N}_][\\p{L}\\p{N}_.-]*`,_=RegExp(`^(${g})\\s*${h}$`,`u`),v=RegExp(`^(${g})\\s*${h}\\s*\\{([\\s\\S]*)\\}$`,`u`),y=RegExp(`^(${g})\\s*:?\\s*([-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+))$`,`u`),b=(e,t)=>{let n=[e[2],e[3],e[4]].find(e=>e!==void 0);return(n===void 0?t:l(n))||t};function x(e){let t=String(e.params||``).replace(/\s*:\s*$/,``).trim();return t?d(e,e.headerLine||e.firstLine,`radar-beta 不支持头行选项「${t}」`,`radar-beta does not accept header options: ${t}`,`把选项写成独立语句(max、min、ticks、showLegend、graticule)`,`Write options as their own statements`):null}function S(e,t,r,i,a){for(let o of m(t.replace(/^axis\s+/i,``))){let t=_.exec(o);if(!t){a.push(d(e,r,`无法识别 radar 维度「${o}」`,`Unrecognized radar axis "${o}"`,'使用 `axis 名称` 或 `axis 名称["显示名"]`','Use `axis name` or `axis name["Label"]`'));continue}let s=t[1];i.some(e=>e.id===s)?a.push(d(e,r,`radar 维度「${s}」重复`,`Duplicate radar axis "${s}"`,`每个维度只声明一次`,`Declare each axis once`)):i.push({id:s,label:(0,n.numericLabel)(b(t,s),e,r,a),line:r})}}function C(e,t,r,i,a){for(let o of m(t.replace(/^curve\s+/i,``))){let t=v.exec(o);if(!t){a.push(d(e,r,`无法识别 radar 曲线「${o}」`,`Unrecognized radar curve "${o}"`,'使用 `curve 名称["显示名"]{值, 值}` 或 `curve 名称{维度: 值}`','Use `curve name["Label"]{value, value}` or `curve name{axis: value}`'));continue}let s=t[1],c=[],l=t[5].split(/[,\n]/).map(e=>e.trim()).filter(Boolean),f=!1;for(let t of l){let n=u(t);if(n!==null){c.push({axis:null,value:n});continue}let i=y.exec(t);i?c.push({axis:i[1],value:Number(i[2])}):(a.push(d(e,r,`radar 曲线「${s}」的值「${t}」无效`,`Invalid value "${t}" in radar curve "${s}"`,"曲线值必须是数值,或 `维度名: 数值`","Curve values must be numbers or `axis: number` pairs")),f=!0)}f||i.push({id:s,label:(0,n.numericLabel)(b(t,s),e,r,a),entries:c,line:r})}}function w(e,t,n,r){return t.flatMap(t=>{let i=t.entries.filter(e=>e.axis!==null);if(!i.length)return[{...t,values:t.entries.map(e=>e.value)}];if(i.length!==t.entries.length)return r.push(d(e,t.line,`radar 曲线「${t.label}」不能混用按位和按维度取值`,`Radar curve "${t.label}" mixes positional and named values`,`整条曲线统一使用一种写法`,`Use one value form for the whole curve`)),[];let a=i.filter(e=>!n.some(t=>t.id===e.axis));if(a.length)return r.push(d(e,t.line,`radar 曲线「${t.label}」引用了未声明的维度「${a[0].axis}」`,`Radar curve "${t.label}" references undeclared axis "${a[0].axis}"`,`先声明该维度,或删去这一项`,`Declare the axis first, or remove that entry`)),[];let o=n.filter(e=>!i.some(t=>t.axis===e.id));return o.length?(r.push(d(e,t.line,`radar 曲线「${t.label}」缺少维度「${o.map(e=>e.id).join(`、`)}」的值`,`Radar curve "${t.label}" is missing values for ${o.map(e=>e.id).join(`, `)}`,"为每个维度各写一个 `维度名: 数值`","Give one `axis: number` entry per axis")),[]):[{...t,values:n.map(e=>i.find(t=>t.axis===e.id).value)}]})}function T(e,t,n,r,i){for(let a of m(t)){let t=/^(showLegend|ticks|max|min|graticule)\s+(\S+)$/i.exec(a);if(!t){i.push(d(e,n,`无法识别 radar 语句「${a}」`,`Unrecognized radar statement "${a}"`,`支持 axis、curve、max、min、ticks、showLegend、graticule`,`Supported: axis, curve, max, min, ticks, showLegend, graticule`));continue}let o=t[1].toLowerCase(),s=t[2];if(o===`showlegend`){if(!/^(true|false)$/i.test(s)){i.push(d(e,n,`showLegend 只接受 true 或 false`,`showLegend accepts only true or false`));continue}r.showLegend=s.toLowerCase()===`true`,r.line??=n;continue}if(o===`graticule`){if(!/^(circle|polygon)$/i.test(s)){i.push(d(e,n,`graticule 只接受 circle 或 polygon`,`graticule accepts only circle or polygon`));continue}r.graticule=s.toLowerCase(),r.line??=n;continue}let c=u(s);c===null?i.push(d(e,n,`radar ${o} 值「${s}」无效`,`Invalid radar ${o} value "${s}"`)):(r[o]=c,r.line??=n)}}var E=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return;let n=Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase());return n===void 0?void 0:e[n]},D=(e,t)=>{let n=E(e,t);return typeof n==`boolean`?n:void 0},O=(e,t)=>{let n=E(e,t),r=typeof n==`number`?n:u(n??``);return r!==null&&Number.isFinite(r)?r:void 0};function k(e,t){let u=[],m=[],h=[],g={},_=x(t);_&&u.push(_);let v=null,y=null,b=null;for(let r of p(e,t.firstLine))if(/^title\s+/i.test(r.text)){if(v!==null){u.push(d(t,r.line,`radar 只能有一个 title`));continue}v=(0,n.numericLabel)(l(r.text.replace(/^title\s+/i,``)),t,r.line,u),y=r.line}else/^axis\s+/i.test(r.text)?(b??=r.line,S(t,r.text,r.line,m,u)):/^curve\s+/i.test(r.text)?C(t,r.text,r.line,h,u):T(t,r.text,r.line,g,u);let k=E(t.config,`radar`),A=O(k,`ticks`)??g.ticks??c,j=O(k,`min`)??g.min??0,M=O(k,`max`)??g.max??null,N=D(k,`showLegend`)??g.showLegend??!0,P=String(E(k,`graticule`)??g.graticule??`circle`).toLowerCase();(m.length<i||m.length>a)&&u.push(d(t,b||t.firstLine,`radar 需要 ${i}–${a} 个维度,当前 ${m.length} 个`,`Radar needs ${i}–${a} axes, got ${m.length}`,`维度必须在 ${i}–${a} 个之间;合并维度或拆分图表`,`Keep axes between ${i} and ${a}; merge dimensions or split the chart`)),!h.length&&!u.length&&u.push(d(t,t.firstLine,`radar 至少需要一条 curve`,`Radar needs at least one curve`)),M!==null&&M<=j&&u.push(d(t,g.line||t.firstLine,`radar max 必须大于 min`,`Radar max must be greater than min`));let F=w(t,h,m,u),I=F.filter(e=>e.values.length===m.length||(u.push(f(t,e.line,`radar 曲线「${e.label}」有 ${e.values.length} 个值、${m.length} 个维度,已跳过`,`Radar curve "${e.label}" has ${e.values.length} values for ${m.length} axes and was skipped`,`为每个维度写一个值`,`Give one value per axis`)),!1));F.length>r&&u.push(d(t,F[r].line,`radar 安全上限为 ${r} 条曲线,当前 ${F.length} 条`,`radar safety cap is ${r} curves; got ${F.length}`,`将曲线合并到 ${r} 条以内,或拆成多张图`,`Merge curves to stay within ${r}, or split the chart`));let L=I.flatMap(e=>e.values).filter(Number.isFinite),R=L.length?Math.max(...L):0,z=L.length?Math.min(...L):0,B=M??Math.max(R,j+1),V=j;B>V||(B=V+1),R>B&&(u.push(f(t,g.line||t.firstLine,`radar max ${B} 小于数据最大值 ${R},已扩展到 ${R}`,`Radar max ${B} is below the data maximum ${R}; extended to ${R}`,`把 max 改为不小于 ${R}`,`Set max to at least ${R}`)),B=R),z<V&&(u.push(f(t,g.line||t.firstLine,`radar min ${V} 大于数据最小值 ${z},已扩展到 ${z}`,`Radar min ${V} is above the data minimum ${z}; extended to ${z}`,`把 min 改为不大于 ${z}`,`Set min to no more than ${z}`)),V=z);let H=Math.max(o,Math.min(s,Math.round(A)));H!==A&&u.push(f(t,g.line||t.firstLine,`radar ticks ${A} 超出 ${o}–${s} 环的可读范围,按 ${H} 环绘制`,`Radar ticks ${A} is outside the readable ${o}–${s} rings; drawing ${H}`,`把 ticks 设为 ${o}–${s} 之间的整数`,`Set ticks to an integer within ${o}–${s}`));let U=m.map((e,t)=>({name:`d${t}`,label:e.label})),W=I.map(e=>Object.fromEntries([[`label`,e.label],...U.map((t,n)=>[t.name,e.values[n]])]));return{model:{chart:`radar`,title:v,titleLine:y,axisLine:b,axes:m,fields:U,rows:W,domain:[V,B],rings:H,graticule:P,showLegend:N,curveLines:I.map(e=>e.line),optionsLine:g.line||b||t.firstLine},errors:u}}function A(e){return{chart:`radar`,...e.title?{title:e.title}:{},data:e.rows,encode:{label:`label`,dimensions:e.fields.map(e=>e.name)},fields:Object.fromEntries(e.fields.map(t=>[t.name,{label:t.label,domain:e.domain}])),rings:e.rings,graticule:e.graticule,legend:e.showLegend}}function j(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=Number(n[1]);return n[0]===`title`?e.titleLine:n[0]===`data`&&Number.isInteger(r)&&e.curveLines[r]?e.curveLines[r]:n[0]===`fields`||n[0]===`encode`?e.axisLine:[`rings`,`graticule`,`legend`].includes(n[0])?e.optionsLine:e.axisLine||e.curveLines[0]||e.optionsLine}var M=(e,t)=>(0,n.validateWith)(A(e),t,t=>j(e,t)),N=(e,r,i)=>{let a=(0,n.renderWith)(A(e),r,i,t=>j(e,t));return a.scene&&(e.rows.length>12||a.width>r.width*2)&&a.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,e.curveLines[0]||e.optionsLine,`radar 有 ${e.rows.length} 条曲线,图表较大,可滚动查看`,`The radar chart has ${e.rows.length} curves and is large; scroll to view`,`按主题拆分为多张雷达图`,`Split the curves into smaller radar charts by topic`)),a},P=Object.freeze([`radar.ticks`,`radar.min`,`radar.max`,`radar.showLegend`,`radar.graticule`]),F={"radar-beta":{parse:k,validate:M,layout:N,optionMode:`raw`,honoredConfig:P}};return e.honoredConfig=P,e.implementations=F,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`]);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
KChartUnits["diagram/numeric-sankey"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=600,c=500,l=60,u=120,d=(e,n,r,i,a=`修正 Mermaid sankey 语法`,o=`Correct the Mermaid sankey syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),f=e=>{let t=[],n=``,r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(r)o===`"`&&e[a+1]===`"`?(n+=`"`,a+=1):o===`"`?(r=!1,i=!0):n+=o;else if(o===`"`){if(n.trim()||i)return null;n=``,r=!0}else if(o===`,`)t.push(n.trim()),n=``,i=!1;else if(i&&!/\s/.test(o))return null;else n+=o}return r?null:(t.push(n.trim()),t)},p=e=>{let t=Number.parseFloat(e);return Number.isFinite(t)?t:null},m=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return;let n=Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase());return n===void 0?void 0:e[n]},h=(e,t)=>{let n=m(e,t);return typeof n==`boolean`?n:void 0};function g(e,t){let a=[],o=[],l=[],u=(0,r.presentation)({lang:t.lang}),g=String(t.params||Object.keys(t.options||{}).join(` `)).replace(/\s*:\s*$/,``).trim();g&&a.push(d(t,t.headerLine||t.firstLine,`sankey 不支持头行选项「${g}」`,`sankey does not accept header options: ${g}`,`把配置写在前言区 sankey: 下`,`Put options under front matter sankey:`)),String(e).split(`
|
|
2
|
+
`).forEach((e,n)=>{let r=e.trim(),i=t.firstLine+n;if(!r||r.startsWith(`%%`)||u.accept(r,i))return;let s=f(r);if(!s){a.push(d(t,i,`sankey CSV 引号格式错误`,`Malformed sankey CSV quoting`,`用成对的 " 包住含逗号的名称,字段内引号写作 ""`,`Wrap names that contain commas in " and write inner quotes as ""`));return}if(s.length!==3){a.push(d(t,i,`sankey 每行必须是 Source,Target,Value 三列,本行 ${s.length} 列`,`Each sankey row needs exactly 3 columns, got ${s.length}`,`每行只写来源、目标、数值三列`,`Write source, target and value only`));return}let[c,m]=[s[0],s[1]],h=p(s[2]);if(!c||!m)a.push(d(t,i,`sankey 来源与目标不能为空`,`Sankey source and target must not be empty`));else if(h===null||h<=0)a.push(d(t,i,`sankey 流量必须为正有限数,本行「${s[2]}」`,`Sankey value must be a positive finite number, got "${s[2]}"`,`把数值改为大于 0 的有限数`,`Use a positive finite number`));else{for(let e of[c,m])l.includes(e)||l.push(e);o.push({id:`edge-${o.length+1}`,source:c,target:m,value:h,line:i})}}),!o.length&&!a.length&&a.push(d(t,t.firstLine,`sankey 至少需要一条有效流量 CSV 记录`,`Sankey needs at least one valid CSV flow record`)),l.length>s&&a.push(d(t,t.firstLine,`sankey 超过安全上限 ${s} 个节点(当前 ${l.length})`,`Sankey exceeds the safety cap of ${s} nodes (got ${l.length})`,`拆分图表后重试`,`Split the diagram and try again`)),o.length>c&&a.push(d(t,t.firstLine,`sankey 超过 Mermaid maxEdges 安全上限 ${c} 条流量(当前 ${o.length})`,`Sankey exceeds the Mermaid maxEdges safety cap of ${c} flows (got ${o.length})`,`拆分图表后重试`,`Split the diagram and try again`));let v=h(m(t.config,`sankey`),`showValues`)??!0;return{model:{chart:`sankey`,nodes:l.map(e=>({id:e,label:(0,n.numericLabel)(e,t,o.find(t=>t.source===e||t.target===e)?.line,a),[i.sankeyPresentation]:{status:u.statusOf(e),link:u.linkOf(e)}})),edges:o.map((e,t)=>({...e,[i.sankeyPresentation]:u.edgeStatusOf(t)})),showValues:v,unit:_(t)},errors:[...a,...u.diagnostics()]}}function _(e){let t=m(e.config,`sankey`),n=m(t,`prefix`),r=m(t,`suffix`);if(n===void 0&&r===void 0)return;let i=e=>e==null?``:String(e),[a,o]=[i(n),i(r)];return/^[\p{L}\p{Sc}%‰°]*\p{Sc}?[\p{L}\p{Sc}%‰°]*$/u.test(`${a}${o}`)&&`${a}${o}`?`${a}${o}`:void 0}function v(e){return{chart:`sankey`,tolerant:!0,[i.sankeyPresentation]:!0,[o.sizeBudget]:{nodes:s,edges:c},data:{nodes:e.nodes,edges:e.edges.map(({line:e,...t})=>t)},layout:`right`,showValues:e.showValues,...e.unit?{unit:e.unit}:{}}}function y(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>n[n.indexOf(e)+1],i=Number(r(`edges`));if(Number.isInteger(i)&&e.edges[i])return e.edges[i].line;let a=Number(r(`nodes`));if(Number.isInteger(a)&&e.nodes[a]){let t=e.nodes[a].id;return e.edges.find(e=>e.source===t||e.target===t)?.line}return e.edges[0]?.line}function b(e,t){let r=(0,n.validateWith)(v(e),t,t=>y(e,t));if(r.length||e.nodes.length<=l&&e.edges.length<=u)return r;let i=new Map(e.nodes.map(e=>[e.id,0])),a=new Map(e.nodes.map(e=>[e.id,[]])),o=new Map(e.nodes.map(e=>[e.id,0]));for(let{source:t,target:n}of e.edges)a.get(t).push(n),i.set(n,i.get(n)+1);let s=e.nodes.map(e=>e.id).filter(e=>!i.get(e));for(let e of s)for(let t of a.get(e))o.set(t,Math.max(o.get(t),o.get(e)+1)),i.set(t,i.get(t)-1),i.get(t)||s.push(t);let c=1e3,f=0;for(let{source:n,target:r,line:i}of e.edges)if(f+=o.get(r)-o.get(n),f>c)return[d(t,i,`桑基图最多支持 ${c} 个跨阶段流量分段`,`Sankey supports at most ${c} flow segments across stages`,`请按阶段拆分图表`,`Split the chart by stage`)];return r}var x=(0,a.createRegistry)(o.validate);x.register(`sankey`,a.layouts.get(`sankey`));var S=(e,r,i)=>{let a=(0,n.renderWith)(v(e),r,i,t=>y(e,t),x.layout);return a.scene&&(a.width>r.width*2||e.nodes.length>l||e.edges.length>u)&&a.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,i.headerLine,`桑基图较大,可滚动查看`,`Large Sankey diagram; scroll to view it`,`考虑拆分图表`,`Consider splitting the diagram`)),a},C=Object.freeze([`sankey.showValues`,`sankey.prefix`,`sankey.suffix`]),w={sankey:{parse:g,validate:b,layout:S,optionMode:`raw`,acceptsPresentation:!0,honoredConfig:C}};return e.honoredConfig=C,e.implementations=w,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`diagram/presentation`],KChartUnits[`chart/relations`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`]);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
KChartUnits["diagram/numeric-xy"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=`[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)`;RegExp(`^${a}$`);var o=RegExp(`^(.*?)\\s*(${a})\\s*-->\\s*(${a})\\s*$`),s=/^(.*?)\s*\[([^\]]*)\]\s*$/,c=/^(bar|line)\b([\s\S]*)$/i,l=RegExp(`^(${a})\\s*(?:"((?:[^"\\\\]|\\\\.)*)"|'((?:[^'\\\\]|\\\\.)*)')?$`),u=/^\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^\s[\]"]+))?\s*\[([\s\S]*)\]\s*$/,d=6,f=24,p=120,m=(e,n,r,i,a=`修正 Mermaid xychart 语法`,o=`Correct the Mermaid xychart syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),h=(e,n,r,i,a,o=`检查图表声明`,s=`Check the chart declaration`)=>e.push((0,t.warning)(`DIAGRAM_HINT`,n.lang,r,i,a,o,s)),g=e=>/^en(?:-|$)/i.test(String(e||``)),_=e=>String(e).replace(/\\([\\"'])/g,`$1`),v=e=>{let t=String(e).trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?_(t.slice(1,-1)):t},y=(e,t,n)=>[e,t,n].find(e=>e!==void 0);function b(e,t=`,`){let n=[],r=``,i=``,a=0;for(let o of String(e))i?(r+=o,o===i&&(i=``)):o===`"`||o===`'`?(i=o,r+=o):((o===`[`||o===`{`)&&(a+=1),(o===`]`||o===`}`)&&--a,o===t&&a===0?(n.push(r.trim()),r=``):r+=o);return n.push(r.trim()),n}function x(e,t){let n=[];return String(e).split(`
|
|
2
|
+
`).forEach((e,r)=>{let i=e.trim();if(i&&!i.startsWith(`%%`))for(let e of b(i,`;`))e&&n.push({text:e,line:t+r})}),n}function S(e,t){let n=null;for(let r of String(e.params||``).split(/\s+/).filter(Boolean))/^(?:horizontal|vertical)$/i.test(r)?n=r.toLowerCase():t.push(m(e,e.headerLine||e.firstLine,`xychart 不支持头行选项「${r}」`,`xychart does not accept header options: ${r}`,`头行只接受 horizontal 或 vertical`,`Only horizontal or vertical is allowed after the header`));return n}function C(e,t,n,r){let i=[];for(let a of b(e)){let e=l.exec(a);if(!e)return r.push(m(t,n,`数据点「${a}」须为数值,可带一个引号标签`,`Data point "${a}" must be a number, optionally with a quoted label`,'写成 `12` 或 `12 "标签"`','Write `12` or `12 "Label"`')),null;let o=y(e[2],e[3],void 0);i.push({value:Number(e[1]),label:o===void 0?null:_(o)||null})}return i}function w(e,t,n,r){let i=s.exec(t);if(i){let t=i[1].trim()?v(i[1]):null,a=b(i[2]);return!a.length||a.some(e=>!e)?(r.push(m(e,n,`x-axis 需要非空类别列表`,`x-axis needs a non-empty category list`,`去掉空类别或多余的逗号`,`Remove empty categories or extra commas`)),{title:t,data:null}):{title:t,data:{kind:`band`,categories:a.map(v)}}}let a=o.exec(t);if(a&&!/-$/.test(a[1])){let e=Number(a[2]),t=Number(a[3]);return{title:a[1].trim()?v(a[1]):null,data:{kind:`linear`,min:e,max:t}}}return{title:t?v(t):null,data:null}}function T(e,t,n,r){let i=new Map,a=[],o=!1;for(let e of r){let t=(i.get(e)||0)+1;i.set(e,t),t===1?a.push(e):(o=!0,a.push(`${e} (${t})`))}return o&&h(e,t,n,`x-axis 类别名重复,已按出现顺序加序号区分`,`Duplicate x-axis categories were numbered in source order`,`让每个类别名唯一`,`Give every category a unique name`),a}function E(e,t,n){let r=e=>String(Number(e.toPrecision(12)));if(n<=0)return[];if(n===1)return[r(e)];let i=(t-e)/(n-1);return Array.from({length:n},(t,n)=>r(e+n*i))}function D(e,t,n,r){let i=c.exec(t),a=i[1].toLowerCase(),o=u.exec(i[2]);if(!o)return r.push(m(e,n,`无法识别 ${a} 数据「${t}」`,`Unrecognized ${a} data "${t}"`,`写成 \`${a} [值, 值]\` 或 \`${a} "名称" [值, 值]\``,`Write \`${a} [value, value]\` or \`${a} "Name" [value, value]\``)),null;let s=C(o[4],e,n,r);if(!s)return null;let l=y(o[1],o[2],o[3]);return{type:a,name:l===void 0?null:_(l),points:s,line:n}}function O(e,t){let r=[],i=null,a=null,o=null,s=null,l=null,u=null,d=null,g=null,_=[],y=S(t,r);for(let f of x(e,t.firstLine))if(/^title\b/i.test(f.text)){let e=f.text.replace(/^title\b/i,``).trim();if(!e){r.push(m(t,f.line,`title 需要标题文字`,`title needs some text`));continue}if(i!==null){r.push(m(t,f.line,`xychart 只能有一个 title`,`xychart accepts one title`));continue}i=(0,n.numericLabel)(v(e),t,f.line,r),a=f.line}else if(/^x-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^x-axis\b/i,``).trim(),f.line,r);e.title!==null&&(o!==null&&h(r,t,f.line,`xychart 重复的 x-axis,只保留最后一条`,`Duplicate x-axis; the last one is used`),o=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&(l&&h(r,t,f.line,`xychart 重复的 x-axis 数据,只保留最后一条`,`Duplicate x-axis data; the last one is used`),l=e.data,u=f.line),u??=f.line}else if(/^y-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^y-axis\b/i,``).trim(),f.line,r);d??=f.line,e.title!==null&&(s!==null&&h(r,t,f.line,`xychart 重复的 y-axis,只保留最后一条`,`Duplicate y-axis; the last one is used`),s=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&e.data.kind===`linear`?(g&&h(r,t,f.line,`xychart 重复的 y-axis 范围,只保留最后一条`,`Duplicate y-axis range; the last one is used`),g=[e.data.min,e.data.max]):e.data?.kind===`band`&&r.push(m(t,f.line,"y-axis 只接受数值范围 `min --> max`","y-axis accepts only a numeric range `min --> max`",'改成 `y-axis "标题" 0 --> 100`','Use `y-axis "Title" 0 --> 100`'))}else if(c.test(f.text)){let e=D(t,f.text,f.line,r);e&&_.push(e)}else r.push(m(t,f.line,`无法识别 xychart 语句「${f.text}」`,`Unrecognized xychart statement "${f.text}"`,`支持 title、x-axis、y-axis、bar、line`,`Supported: title, x-axis, y-axis, bar, line`));_.length||r.push(m(t,t.firstLine,`xychart 至少需要一条 bar 或 line 数据`,`xychart needs at least one bar or line plot`)),_.length>f&&r.push(m(t,_[f].line,`xychart 安全上限为 ${f} 条数据序列,当前 ${_.length} 条`,`xychart safety cap is ${f} plots; got ${_.length}`,`将数据序列合并到 ${f} 条以内,或拆成多张图`,`Merge series to stay within ${f} plots, or split the chart`));let b=_.length===1&&_[0].name,C=_.some(e=>e.type===`line`&&e.points.some(e=>e.label)),O=_.length>1||b&&!(_[0].type===`line`&&_[0].points.some(e=>e.label))?`combo`:_[0]?.type===`bar`?`column`:`line`,k=u||_[0]?.line||t.firstLine,A=_.map(e=>e.points.length),j=l?.kind===`band`?l.categories.length:Math.max(0,...A);j>p&&O!==`column`&&r.push(m(t,k,`xychart 最多支持 ${p} 个横轴类别`,`xychart supports at most ${p} x-axis categories`,`按横轴范围拆分图表`,`Split the chart by x-axis range`));let M;M=l?.kind===`band`?T(r,t,k,l.categories.map(e=>(0,n.numericLabel)(e,t,k,r))):l?.kind===`linear`?E(l.min,l.max,j):Array.from({length:j},(e,t)=>String(t+1));let N=_.map(e=>{let i=e.points.length>M.length,a=O===`combo`||e.type===`line`?null:0;return i?h(r,t,e.line,`数据点数 ${e.points.length} 多于类别数 ${M.length},多余的点已略去`,`${e.points.length} points exceed ${M.length} categories; extra points were dropped`,`补齐 x-axis 类别或删去多余的点`,`Add x-axis categories or remove the extra points`):e.points.length<M.length&&a===0&&h(r,t,e.line,`bar 数据点数少于类别数,缺少的点按 0 绘制`,`The bar plot has fewer points than categories; missing points are drawn as 0`,`补齐数据点`,`Provide a value for every category`),{type:e.type,name:e.name&&(0,n.numericLabel)(e.name,t,e.line,r),line:e.line,values:M.map((t,n)=>e.points[n]?.value??a),pointLabels:M.map((i,a)=>{let o=e.points[a]?.label;return o?(0,n.numericLabel)(o,t,e.line,r):null})}});O===`combo`&&C&&h(r,t,_[0].line,`组合图中的数据点标签未绘制`,`Point labels are not drawn on a combined chart`,`把该序列拆成单独的 line 图,或删去标签`,`Split that plot into a line-only chart or drop the labels`),O!==`combo`&&N[0]?.name&&C&&h(r,t,_[0].line,`单序列折线的名称「${N[0].name}」未作为图例绘制`,`The name "${N[0].name}" of this single line is not drawn as a legend`,`需要图例时不要同时使用数据点标签`,`Do not combine point labels with a series name if the legend matters`);let P=_.find(e=>e.type===`bar`&&e.points.some(e=>e.label));P&&h(r,t,P.line,`bar 的数据点标签被忽略(Mermaid 也只对 line 绘制点标签)`,`Point labels on a bar plot are ignored (Mermaid draws them on line plots only)`,`改用 line 绘制带标签的序列`,`Use line for a labeled series`);let F=_.flatMap(e=>e.points.map(e=>e.value)),I=Math.min(...F),L=Math.max(...F),R=null;return g&&(g[1]>g[0]?R=[g[0],g[1]]:h(r,t,d,`y-axis 范围 ${g[0]} --> ${g[1]} 不是递增区间,已改为按数据取值`,`y-axis range ${g[0]} --> ${g[1]} is not increasing; derived from data instead`,"把范围写成 `小值 --> 大值`","Write the range as `low --> high`")),R&&(R[0]>I&&(h(r,t,d,`y-axis 最小值 ${R[0]} 高于数据最小值 ${I},已扩展到 ${I}`,`y-axis minimum ${R[0]} is above the data minimum ${I}; extended to ${I}`,`把最小值改为不大于 ${I}`,`Set the minimum to at most ${I}`),R[0]=I),R[1]<L&&(h(r,t,d,`y-axis 最大值 ${R[1]} 低于数据最大值 ${L},已扩展到 ${L}`,`y-axis maximum ${R[1]} is below the data maximum ${L}; extended to ${L}`,`把最大值改为不小于 ${L}`,`Set the maximum to at least ${L}`),R[1]=L),_.some(e=>e.type===`bar`)&&(R[0]>0||R[1]<0)&&(h(r,t,d,`柱形 y 轴已自动包含 0 基线(${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`The bar y-axis now includes the zero baseline (${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`把 y-axis 范围写成包含 0 的区间`,`Declare a y-axis range that includes 0`),R=[Math.min(0,R[0]),Math.max(0,R[1])])),y===`horizontal`&&h(r,t,t.headerLine||t.firstLine,`xychart horizontal 暂不支持,按纵向绘制`,`Horizontal xychart is not supported yet; drawing vertically`,"改成 `xychart` 或 `xychart vertical`","Use `xychart` or `xychart vertical`"),l?.kind===`linear`&&new Set(M).size!==M.length&&h(r,t,k,`数值 x 轴 ${l.min} --> ${l.max} 的刻度有重复,类别名已加序号`,`The numeric x-axis ${l.min} --> ${l.max} produces repeated ticks; categories were numbered`,`扩大范围或减少数据点`,`Widen the range or use fewer points`),{model:{chart:O,title:i,titleLine:a,xLabel:o,yLabel:s,xLine:u,yLine:d,yDomain:R,categories:M,datasets:N,horizontal:y===`horizontal`},errors:r}}function k(e,t,n=0){let a=g(t?.lang),o=[e.xLabel,e.yLabel].filter(Boolean).join(` · `)||void 0,s=e.yDomain?{domain:e.yDomain}:{};if(e.chart===`combo`){let t=e.categories.map((t,n)=>Object.fromEntries([[`category`,t],...e.datasets.map((e,t)=>[`v${t}`,e.values[n]])]));return{chart:`combo`,[i.diagramCombo]:{index:n},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:t,encode:{category:`category`},layers:e.datasets.map((e,t)=>({mark:e.type===`bar`?`column`:`line`,field:`v${t}`,axis:`left`})),fields:Object.fromEntries(e.datasets.map((e,t)=>[`v${t}`,{label:e.name||(a?`Series ${t+1}`:`系列 ${t+1}`),...s}]))}}let c=e.datasets[0],l=c.pointLabels.some(Boolean),u=e.categories.map((e,t)=>({category:e,value:c.values[t],...l?{id:String(t)}:{}}));return{chart:e.chart,...e.chart===`line`?{[r.diagramLine]:!0}:{},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:u,encode:{category:`category`,value:`value`,...l?{id:`id`}:{}},fields:{value:{...s,...c.name?{label:c.name}:{}}},...l?{annotations:c.pointLabels.flatMap((e,t)=>e?[{kind:`note`,field:`value`,record:String(t),text:e}]:[])}:{}}}function A(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>{let t=/^v(\d+)$/.exec(String(e||``));return t?Number(t[1]):null};if(n[0]===`title`)return e.titleLine;if(n[0]===`subtitle`)return e.xLine||e.yLine;if(n[0]===`layers`)return e.datasets[Number(n[1])]?.line||e.datasets[0]?.line;if(n[0]===`fields`){let t=r(n[1]);return(t===null?null:e.datasets[t]?.line)||e.yLine||e.datasets[0]?.line}if(n[0]===`encode`)return e.xLine||e.datasets[0]?.line;if(n[0]===`annotations`)return e.datasets[0]?.line;if(n[0]===`data`){let t=r(n[2]);return(t===null?null:e.datasets[t]?.line)||e.datasets[0]?.line}return e.datasets[0]?.line}function j(e,t){if(e.datasets.length<=d)return[e];let n=e.datasets.flatMap(e=>e.values.filter(Number.isFinite)),r=e.datasets.some(e=>e.type===`bar`)?[0]:[],i=Math.min(...n,...r),a=Math.max(...n,...r),o=e.yDomain??[i,a>i?a:i+1],s=[];for(let n=0;n<e.datasets.length;n+=d)s.push({...e,yDomain:o,title:n?null:e.title,datasets:e.datasets.slice(n,n+d).map((e,r)=>({...e,name:e.name||`${g(t.lang)?`Series `:`系列 `}${n+r+1}`}))});return s}return e.implementations={xychart:{parse:O,validate:(e,t)=>j(e,t).flatMap(e=>(0,n.validateWith)(k(e,t),t,t=>A(e,t))),layout:(e,r,i)=>{let a=j(e,i).map((e,t)=>(0,n.renderWith)(k(e,i,t),r,i,t=>A(e,t)));if(a.some(e=>!e.scene))return a.find(e=>!e.scene);let o=a[0];if(a.length>1){let e=0,t=a.map(({scene:t})=>{let n=r.ctx.el(`g`,{transform:`translate(${e} 0)`},t.children);return e+=t.width+24,n});o.width=e-24,o.height=Math.max(...a.map(e=>e.height)),o.scene={...o.scene,width:o.width,height:o.height,children:t}}return(e.categories.length>60||o.width>r.width*2||a.length>1)&&o.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,e.xLine||e.datasets[0]?.line||i.firstLine,a.length>1?`XY 图按数据序列分栏,可横向滚动`:`XY 图较大,可滚动查看`,a.length>1?`XY series are arranged in panels; scroll horizontally`:`Large XY chart; scroll to view it`,`按数据序列或横轴范围拆分图表`,`Split the chart by series or x-axis range`)),o},optionMode:`raw`}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/basic`],KChartUnits[`chart/multivariate`]);
|