@fengwk/kchart 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +31 -2
- package/README.zh-CN.md +31 -2
- package/dist/esm/_virtual/_kchart-families.js +2 -1
- package/dist/esm/chart/composition.js +7 -5
- package/dist/esm/chart/maps.js +9 -7
- package/dist/esm/chart/mindmap.js +19 -5
- package/dist/esm/chart/multivariate.js +49 -14
- package/dist/esm/chart/relations.js +15 -7
- package/dist/esm/chart/spec.js +5 -2
- package/dist/esm/core/context.js +29 -10
- package/dist/esm/core/scene.js +238 -21
- package/dist/esm/core/text.js +1 -1
- package/dist/esm/diagram/block.js +287 -295
- package/dist/esm/diagram/blocks.js +541 -605
- package/dist/esm/diagram/board-paint.js +594 -0
- package/dist/esm/diagram/board-route.js +60 -0
- package/dist/esm/diagram/c4.js +75 -35
- package/dist/esm/diagram/class.js +3 -2
- package/dist/esm/diagram/cynefin.js +55 -9
- package/dist/esm/diagram/eventmodeling.js +4 -2
- package/dist/esm/diagram/gantt.js +37 -15
- package/dist/esm/diagram/gitgraph.js +26 -5
- package/dist/esm/diagram/graph-layout.js +39 -2
- package/dist/esm/diagram/graph-route.js +296 -38
- package/dist/esm/diagram/info.js +32 -0
- package/dist/esm/diagram/journey.js +5 -5
- package/dist/esm/diagram/kanban.js +3 -3
- package/dist/esm/diagram/layers.js +9 -7
- package/dist/esm/diagram/mindmap.js +5 -1
- package/dist/esm/diagram/numeric-composition.js +24 -4
- package/dist/esm/diagram/numeric-model.js +1 -1
- package/dist/esm/diagram/numeric-radar.js +25 -7
- package/dist/esm/diagram/numeric-sankey.js +4 -3
- package/dist/esm/diagram/numeric-xy.js +12 -2
- package/dist/esm/diagram/packet.js +4 -4
- package/dist/esm/diagram/quadrant.js +12 -5
- package/dist/esm/diagram/railroad-parse.js +20 -10
- package/dist/esm/diagram/railroad.js +1 -1
- package/dist/esm/diagram/registry.js +46 -8
- package/dist/esm/diagram/sequence.js +43 -6
- package/dist/esm/diagram/swimlane.js +2 -2
- package/dist/esm/diagram/time.js +3 -3
- package/dist/esm/diagram/timeline.js +5 -5
- package/dist/esm/diagram/treeview.js +5 -3
- package/dist/esm/diagram/venn.js +35 -15
- package/dist/esm/diagram/wardley.js +61 -26
- package/dist/esm/diagram/zenuml.js +338 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/mermaid.d.ts +1 -1
- package/dist/esm/mermaid.js +2 -1
- package/dist/esm/node.js +8 -2
- package/dist/esm/src/families.js +6 -1
- package/dist/units/chart/composition.js +1 -1
- package/dist/units/chart/maps.js +1 -1
- package/dist/units/chart/mindmap.js +1 -1
- package/dist/units/chart/multivariate.js +1 -1
- package/dist/units/chart/relations.js +1 -1
- package/dist/units/chart/spec.js +1 -1
- package/dist/units/core/context.js +1 -1
- package/dist/units/core/scene.js +1 -1
- package/dist/units/core/text.js +1 -1
- package/dist/units/diagram/block.js +2 -2
- package/dist/units/diagram/blocks.js +2 -2
- package/dist/units/diagram/board-paint.js +1 -0
- package/dist/units/diagram/board-route.js +1 -0
- package/dist/units/diagram/c4.js +1 -1
- package/dist/units/diagram/class.js +2 -2
- package/dist/units/diagram/cynefin.js +2 -2
- package/dist/units/diagram/eventmodeling.js +1 -1
- package/dist/units/diagram/gantt.js +3 -3
- package/dist/units/diagram/gitgraph.js +2 -1
- package/dist/units/diagram/graph-layout.js +1 -1
- package/dist/units/diagram/graph-route.js +1 -1
- package/dist/units/diagram/info.js +2 -0
- package/dist/units/diagram/journey.js +3 -3
- package/dist/units/diagram/kanban.js +1 -1
- package/dist/units/diagram/layers.js +1 -1
- package/dist/units/diagram/mindmap.js +1 -1
- package/dist/units/diagram/numeric-composition.js +1 -1
- package/dist/units/diagram/numeric-model.js +1 -1
- package/dist/units/diagram/numeric-radar.js +2 -2
- package/dist/units/diagram/numeric-sankey.js +1 -1
- package/dist/units/diagram/numeric-xy.js +1 -1
- package/dist/units/diagram/packet.js +1 -1
- package/dist/units/diagram/quadrant.js +1 -1
- package/dist/units/diagram/railroad-parse.js +2 -2
- package/dist/units/diagram/railroad.js +1 -1
- package/dist/units/diagram/registry.js +2 -2
- package/dist/units/diagram/sequence.js +1 -1
- package/dist/units/diagram/swimlane.js +2 -2
- package/dist/units/diagram/time.js +1 -1
- package/dist/units/diagram/timeline.js +1 -1
- package/dist/units/diagram/treeview.js +1 -1
- package/dist/units/diagram/venn.js +1 -1
- package/dist/units/diagram/wardley.js +4 -4
- package/dist/units/diagram/zenuml.js +2 -0
- package/dist/units.json +79 -51
- package/package.json +1 -1
- package/dist/esm/diagram/relations.js +0 -966
- package/dist/units/diagram/relations.js +0 -3
package/dist/units/core/text.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
KChartUnits["core/text"]=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=e=>/[\u2E80-\u9FFF\uF900-\uFAFF]/.test(e),n=e=>/[\u3000-\u303F\uFF00-\uFFEF]/.test(e);function r(e,t=12,n=400){return[...String(e??``)].reduce((e,r)=>e+(/^[\u2e80-\u9fff\uf900-\ufaff\u3000-\u30ff\uac00-\ud7af]$/u.test(r)?1:.56)*t*(n>=600?1.04:1),0)}var i=new Set([...`))]]】」』〉》,,。、;;::!!??…%%`]),a=new Set([...`(([[【「『〈《`]);function o(e,t=0){for(let n=t+1;n<e.length;n+=1){let t=0;for(;e[n]&&i.has([...e[n]][0])&&t++<8;){let t=[...e[n]];e[n-1]+=t.shift(),e[n]=t.join(``)}if(!e[n])e.splice(n--,1);else for(t=0;e[n-1]&&a.has([...e[n-1]].at(-1))&&t++<8;){let t=[...e[n-1]];if(t.length<=1)break;e[n]=t.pop()+e[n],e[n-1]=t.join(``)}}return e}var s=null,c=!1;function l(){if(!c){c=!0;try{s=typeof Intl<`u`&&typeof Intl.Segmenter==`function`?new Intl.Segmenter(`zh`,{granularity:`word`}):null}catch{s=null}}return s}function u(e){let r=[],i=``,a=()=>{i&&=(r.push(i),``)},o=l();if(!o){for(let o of e)/\s/.test(o)?(a(),r.push(` `)):t(o)||n(o)?(a(),r.push(o)):i+=o;return a(),r}for(let s of o.segment(e)){let e=s.segment;if(/^\s+$/.test(e)){a(),r.push(` `);continue}let o=[...e];o.some(e=>t(e)||n(e))?(a(),s.isWordLike&&o.length>1&&o.every(t)?r.push(e):r.push(...o)):i+=e}a();for(let e=1;e<r.length;e+=1)[...r[e]].length===1&&t(r[e])&&t([...r[e-1]].at(-1))&&(r.splice(e-1,2,r[e-1]+r[e]),--e);for(let e=0;e<r.length-1;e+=1){if(!/^[\d.,%]+$/.test(r[e])||!/\d/.test(r[e]))continue;let i=+(r[e+1]===` `),a=r[e+1+i];a&&t(a[0])&&!n(a[0])&&r.splice(e,2+i,`${r[e]}${i?` `:``}${a}`)}return r}var d=.5;function f(e,n,r,i){let a=[],s={size:Number(r.size)||13,weight:Number(r.weight)||400};for(let r of String(e??``).split(`
|
|
1
|
+
KChartUnits["core/text"]=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=e=>/[\u2E80-\u9FFF\uF900-\uFAFF]/.test(e),n=e=>/[\u3000-\u303F\uFF00-\uFFEF]/.test(e);function r(e,t=12,n=400){return[...String(e??``)].reduce((e,r)=>e+(/^[\u2e80-\u9fff\uf900-\ufaff\u3000-\u30ff\uac00-\ud7af\uff01-\uff60\uffe0-\uffe6]$/u.test(r)?1:.56)*t*(n>=600?1.04:1),0)}var i=new Set([...`))]]】」』〉》,,。、;;::!!??…%%`]),a=new Set([...`(([[【「『〈《`]);function o(e,t=0){for(let n=t+1;n<e.length;n+=1){let t=0;for(;e[n]&&i.has([...e[n]][0])&&t++<8;){let t=[...e[n]];e[n-1]+=t.shift(),e[n]=t.join(``)}if(!e[n])e.splice(n--,1);else for(t=0;e[n-1]&&a.has([...e[n-1]].at(-1))&&t++<8;){let t=[...e[n-1]];if(t.length<=1)break;e[n]=t.pop()+e[n],e[n-1]=t.join(``)}}return e}var s=null,c=!1;function l(){if(!c){c=!0;try{s=typeof Intl<`u`&&typeof Intl.Segmenter==`function`?new Intl.Segmenter(`zh`,{granularity:`word`}):null}catch{s=null}}return s}function u(e){let r=[],i=``,a=()=>{i&&=(r.push(i),``)},o=l();if(!o){for(let o of e)/\s/.test(o)?(a(),r.push(` `)):t(o)||n(o)?(a(),r.push(o)):i+=o;return a(),r}for(let s of o.segment(e)){let e=s.segment;if(/^\s+$/.test(e)){a(),r.push(` `);continue}let o=[...e];o.some(e=>t(e)||n(e))?(a(),s.isWordLike&&o.length>1&&o.every(t)?r.push(e):r.push(...o)):i+=e}a();for(let e=1;e<r.length;e+=1)[...r[e]].length===1&&t(r[e])&&t([...r[e-1]].at(-1))&&(r.splice(e-1,2,r[e-1]+r[e]),--e);for(let e=0;e<r.length-1;e+=1){if(!/^[\d.,%]+$/.test(r[e])||!/\d/.test(r[e]))continue;let i=+(r[e+1]===` `),a=r[e+1+i];a&&t(a[0])&&!n(a[0])&&r.splice(e,2+i,`${r[e]}${i?` `:``}${a}`)}return r}var d=.5;function f(e,n,r,i){let a=[],s={size:Number(r.size)||13,weight:Number(r.weight)||400};for(let r of String(e??``).split(`
|
|
2
2
|
`)){if(!r){a.push(``);continue}let e=a.length,c=new Map,l=e=>(c.has(e)||c.set(e,i(e,s)),c.get(e)),f=e=>e.reduce((e,t)=>e+l(t),0),p=e=>l(e)>n+d,m=u(r).flatMap(e=>e===` `||!p(e)?[e]:e.split(/(?<=[-/])/).flatMap(e=>p(e)?[...e]:[e])),h=[[]],g=0;for(let e of m){let t=h.at(-1);e===` `?t.length&&(t.push(` `),g+=l(` `)):g+l(e)<=n+d?(t.push(e),g+=l(e)):(h.push([e]),g=l(e))}for(let e=h.length-1;e>0;--e){let r=0;for(;r<4&&[...h[e].join(``).trim()].length<=2&&h[e-1].filter(e=>e!==` `).length>1;){let i=h[e-1].length-1;for(;i>=0&&h[e-1][i]===` `;)--i;if(i<0||!t([...h[e-1][i]][0]))break;let a=[...h[e-1].slice(i),...h[e]];if(f(a)>n+d)break;h[e]=a,h[e-1]=h[e-1].slice(0,i),r+=1}}for(let e of h)a.push(e.join(``).trimEnd());a.length===e&&a.push(``),o(a,e)}return a.length?a:[``]}function p(e,t,n={},i=(e,t)=>r(e,t.size,t.weight),{bounded:a=!1}={}){if(!a)return f(e,t,n,i);let o={size:Number(n.size)||13,weight:Number(n.weight)||400},s=new Map,c=e=>(s.has(e)||s.set(e,i(e,o)),s.get(e)),l=e=>Math.max(...e.map(c)),u=t,p=f(e,u,o,c),m=l(p),h=m;for(;h>t+d&&u>o.size;){u=Math.max(o.size,u-Math.ceil(h-t));let n=f(e,u,o,c);h=l(n),h<m&&(p=n,m=h)}return p}return e.fallbackMeasure=r,e.wrapText=p,e})({});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
KChartUnits["diagram/block"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var
|
|
2
|
-
`)].entries()){O=o+t-1;let e=n,r=t=>{e=e.slice(t)},i=()=>r(e.match(/^\s*/)[0].length),a=()=>{let t=/^:(\d+)/.exec(e);return t&&r(t[0].length),t?Number(t[1]):1},l=()=>{let t=/^(?![-.])[^()[\]{}<>:=;"\s~]+?(?=$|[()[\]{}<>:=;"\s~]|--|-?\.+-|%%)/.exec(e);if(!t)return null;let n=t[0];r(n.length);let i={id:n,line:O},o=d.find(([t])=>e.startsWith(t))?.[0];if(o){r(o.length);let t=/^\s*"([^"]*)"\s*/.exec(e),n;if(t){if(r(t[0].length),n=d.find(([t,n])=>t===o&&e.startsWith(n)),!n){let t=/^(?:\)\)\)|\)\)|\)\]|\]\)|\]\]|\}\}|[)\]}])/.exec(e);t&&(n=[o,t[0],`square`])}i.label=t[1]}else if(n=d.find(([t,n])=>t===o&&e.includes(n)),n){let t=e.indexOf(n[1]);i.label=e.slice(0,t).trim(),r(t)}if(!n)return null;if(r(n[1].length),i.shape=n[2],i.shape===`arrow`){let t=/^\s*\(([^)]*)\)/.exec(e);if(i.directions=t?.[1].split(/[\s,]+/).filter(Boolean),!i.directions?.length||i.directions.some(e=>!m.has(e)))return null;r(t[0].length)}}let s=()=>{let t=/^::icon\(\s*([^()]+?)\s*\)/i.exec(e),a=/^:::([\w-]+(?:,[\w-]+)*)/.exec(e);return t?(i.iconRef=t[1],r(t[0].length)):a&&(b.set(n,b.get(n)??O),v.addClasses(n,a[1].split(`,`),O),r(a[0].length)),t||a};for(;s(););for(i.span=a();s(););return i.span>0&&i.span<=2e3?i:null},y=(e,t)=>{let n=h.get(e.id);n?(e.label!==void 0&&!n.children&&Object.assign(n,{label:e.label,labelLine:e.line,shape:e.shape,directions:e.directions}),e.iconRef&&Object.assign(n,{iconRef:e.iconRef,iconLine:e.line})):(h.set(e.id,e),t.children.push(e))};for(;e&&(i(),k=n.length-e.length+1+(t===0?Math.max(0,c.indexOf(s)):0),e&&!/^%%(?!\{)/.test(e));){if(e[0]===`;`){r(1);continue}let t=/^(style|class)\s+([^\s,]+(?:\s*,\s*[^\s,]+)*)\s+(.+)$/i.exec(e);if(t?.[1].toLowerCase()===`style`&&/^[\w-]+#[\da-f]+;?\s*$/i.test(t[3])){C(O,`已忽略缺少冒号的块图样式`,`Ignored a block style missing its colon`);break}if(t&&/^style$/i.test(t[1])){for(let e of t[2].split(/\s*,\s*/))v.accept(`style ${e} ${t[3]}`,O),b.set(e,b.get(e)??O);break}if(v.accept(e,O)){if(t)for(let e of t[2].split(/\s*,\s*/))b.set(e,b.get(e)??O);/^classDef\s+default\b/i.test(e)&&(x??=O);break}if(/^interpolate\s/i.test(e)){C(O,`已忽略插值样式;连线使用网格走线`,`Ignored interpolation; edges follow grid routes`);break}let n=u.at(-1),o=/^columns\s+(auto|\d+)(?=\s|;|$)/.exec(e),s=/^space(?=[:;\s]|$)/.exec(e),c=/^block(?:-beta)?(?=[:;\s]|$)/.exec(e),d=/^end(?=[;\s]|$)/.exec(e);if(o){r(o[0].length);let e=o[1]===`auto`?0:Number(o[1]);if(e>2e3||e===0&&o[1]!==`auto`){A(`无效的列数`,`Invalid column count`);break}n.columns=e}else if(s){r(s[0].length);let e=a();if(e>2e3){A(`占位过宽`,`Space span is too large`);break}if(D+=e,D>2e4)return A(`占位单元格过多`,`Too many space cells`),{model:null,errors:_};n.children.push({space:!0,span:e})}else if(c){r(c[0].length);let t=e[0]===`:`&&!/^:\d/.test(e);t&&r(1);let i=t?l():{id:`:block${++E}`,line:O,span:a()};if(!i||!i.span||i.span>2e3||u.length>32||h.has(i.id)){A(`无效、重复或嵌套过深的复合块`,`Invalid, duplicate or excessively nested composite block`);break}i.children=[],y(i,n),u.push(i)}else if(d){if(r(d[0].length),u.length===1){A(`end 没有对应的 block`,`No matching block for end`);break}u.pop()}else{let t=l();if(!t){A(`无法识别块图语句`,`Unrecognized block statement`);break}for(y(t,n),i();e;){let a=/^([xo<]?(?:--|==|-\.))\s*"([^"]*)"\s*/.exec(e),o=f.exec(a?e.slice(a[0].length):e);if(!o)break;r((a?.[0].length??0)+o[0].length),i();let s=l();if(!s){A(`连线缺少终点`,`Missing edge endpoint`);break}y(s,n);let c=o[0],u=!a&&/^\s+:\s+(.+)$/.exec(e);if(u&&r(u[0].length),g.push({from:t.id,to:s.id,line:O,label:a?.[2]??u?.[1]??``,arrowStart:p[c[0]],arrowEnd:p[c.at(-1)],thickness:c.includes(`==`)?2.5:1.5,pattern:c.includes(`.-`)?`dotted`:`solid`}),h.size>2e3||g.length>500)return A(`块或连线过多`,`Too many blocks or edges`),{model:null,errors:_};t=s,i()}}if(h.size>2e3)return A(`块过多`,`Too many blocks`),{model:null,errors:_}}}u.length>1&&(O=u.at(-1).line,k=1,A(`复合块缺少 end`,`Composite block is missing end`)),h.size||l.children.length||_.length||(O=o-1,k=1,A(`块图为空`,`Empty block diagram`)),_.push(...v.diagnostics());for(let e of h.values()){e.label!==void 0&&Object.assign(e,T(e.label,e.labelLine??e.line)),e.iconRef&&(e.icon=w(e.iconRef,e.iconLine??e.line)??e.icon);let t=v.statusOf(e.id);t&&e.shape===`arrow`&&!e.children?C(b.get(e.id)??x??e.line,`块箭头不应用自定义样式`,`Block arrows do not apply custom styling`):e.status=t,e.link=v.linkOf(e.id)}return g.forEach((e,t)=>Object.assign(e,T(e.label,e.line),{status:v.edgeStatusOf(t)})),{model:{root:l,edges:g,nodeCount:h.size},errors:[..._,...y.values()]}}function g(e,t,n){let r=[],o=e.columns||1/0,s=0,l=0,d=72,f,p=()=>f??={h:36,cells:[]},m=e=>{s+=e,l=Math.max(l,s),s>=o&&(r.push(f),f=void 0,s=0)};for(let r of e.children){if(r.space){for(let e=r.span;e>0;){p();let t=Math.min(e,o-s);m(t),e-=t}continue}let e=r.children?g(r,t,n):null,h=e?i.FONT.title:i.FONT.body,_=r.label??(e?``:r.id),v=_.trim()?(0,i.wrapText)(_,u-P(r.icon,[_]),h,t):[],y=(0,i.maxWidthOf)(v,h,t)+P(r.icon,v),b=Math.max(v.length*18,r.icon?c:0),x=e&&b?b+4:0,S=y+28,C=b+20,w=!e&&[`diamond`,`circle`,`doublecircle`].includes(r.shape);w?S=C=Math.ceil(r.shape===`diamond`?y+b+24:Math.hypot(y,b)+24):r.shape===`arrow`?(S+=28,C+=24):r.shape===`cylinder`?C+=12:r.shape&&![`square`,`round`,`stadium`].includes(r.shape)&&(S+=20),e&&(S=Math.max(S,e.w+2*n),C=e.h+2*n+x);let T={...r,col:s,inner:e,lines:v,font:h,title:x,textH:b,...w?{diameter:S}:{}};p().cells.push(T),f.h=Math.max(f.h,C),d=Math.max(d,Math.ceil((S-(r.span-1)*a)/r.span)),l=Math.max(l,s+r.span),m(Math.min(r.span,o-s))}f&&r.push(f);let h=r.reduce((e,t)=>e+t.h+a,-20);return{rows:r,unit:d,columns:l,w:Math.max(0,l*(d+a)-a),h:Math.max(0,h)}}function _(e,t,n,r,i,o,s){if(!e.columns)return;let c=(r+a)/e.columns;for(let r of e.rows){for(let e of r.cells){let l={...e,x:t+e.col*c,y:n,w:e.span*c-a,h:r.h};e.diameter?(l.x+=(l.w-e.diameter)/2,l.y+=(l.h-e.diameter)/2,l.w=l.h=e.diameter):!e.inner&&e.shape===`arrow`&&!e.textH&&(l.x+=(l.w-28)/2,l.y+=(l.h-28)/2,l.w=l.h=28),i.set(l.id,l),l.inner&&(o.push(l),_(l.inner,l.x+s,n+s+l.title,l.w-2*s,i,o,s))}n+=r.h+a}}var v=[[0,0],[1,0],[1,1],[0,1]],y={diamond:[[.5,0],[1,.5],[.5,1],[0,.5]],hexagon:[[.13,0],[.87,0],[1,.5],[.87,1],[.13,1],[0,.5]],notch:[[0,0],[1,0],[1,1],[0,1],[.13,.5]],leanRight:[[.13,0],[1,0],[.87,1],[0,1]],leanLeft:[[0,0],[.87,0],[1,1],[.13,1]],trapezoid:[[.13,0],[.87,0],[1,1],[0,1]],inverseTrapezoid:[[0,0],[1,0],[.87,1],[.13,1]]};function b(e){let t=y[e.shape];if(e.shape===`arrow`){let n=e.directions,r=[`up`,`right`,`down`,`left`].map((e,t)=>n.includes(e)||n.includes(t%2?`x`:`y`)),i=Math.min(.22,16/e.w),a=Math.min(.24,14/e.h),[o,s,c,l]=r.map((e,t)=>e?[a,i][t%2]:0),u=[[l,o],[1-s,o],[1-s,1-c],[l,1-c]],d=[[[.24,o],[.5,0],[.76,o]],[[1-s,.24],[1,.5],[1-s,.76]],[[.76,1-c],[.5,1],[.24,1-c]],[[l,.76],[0,.5],[l,.24]]],f=r[0]||r[2],p=r[1]||r[3];if(f&&!p){let t=Math.min(.28,12/e.w);u.forEach((e,n)=>{e[0]=n===0||n===3?t:1-t}),d[0][0][0]=0,d[0][2][0]=1,d[2][0][0]=1,d[2][2][0]=0}else if(p&&!f){let t=Math.min(.24,12/e.h);u.forEach((e,n)=>{e[1]=n<2?t:1-t}),d[1][0][1]=0,d[1][2][1]=1,d[3][0][1]=1,d[3][2][1]=0}t=u.flatMap((e,t)=>{if(!r[t])return[e];let n=u[(t+1)%4],i=d[t],a=t%2;if(p&&f)return[e,...i];let o=(e,t)=>e.map((e,n)=>n===a?e:t[n]);return[e,o(i[0],e),...i,o(i[2],n)]})}return t?.map(([t,n])=>[e.x+t*e.w,e.y+n*e.h])}var x=e=>[e.x+e.w/2,e.y+e.h/2],S=(e,t)=>e[0]*t[1]-e[1]*t[0],C=(e,t)=>[t[0]-e[0],t[1]-e[1]],w=e=>e.shape===`circle`||e.shape===`doublecircle`;function T(e,t){let n=x(e),r=C(n,t);if(w(e)){let t=1/Math.hypot(r[0]/(e.w/2),r[1]/(e.h/2));return n.map((e,n)=>e+r[n]*t)}let i=b(e)||v.map(([t,n])=>[e.x+t*e.w,e.y+n*e.h]),a=1/0;for(let[e,t]of i.entries()){let o=i[(e+1)%i.length],s=C(t,o),c=S(r,s);if(Math.abs(c)<1e-6)continue;let l=C(n,t),u=S(l,r)/c,d=S(l,s)/c;u>=0&&u<=1&&d>0&&(a=Math.min(a,d))}return Number.isFinite(a)?n.map((e,t)=>e+r[t]*a):n}var E=(e,t)=>e.x<=t.x&&e.y<=t.y&&e.x+e.w>=t.x+t.w&&e.y+e.h>=t.y+t.h,D=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h;function O([e,t],n){let r=0,i=1;for(let[a,o,s]of[[0,n.x-2,n.x+n.w+2],[1,n.y-2,n.y+n.h+2]]){let n=t[a]-e[a];if(n===0){if(e[a]<o||e[a]>s)return!1;continue}let c=(o-e[a])/n,l=(s-e[a])/n;r=Math.max(r,Math.min(c,l)),i=Math.min(i,Math.max(c,l))}return r<=i}var k=e=>e.slice(1).map((t,n)=>[e[n],t]),A=([e,t])=>Math.hypot(...C(e,t));function j(e,t,n,r,o,s,l){let u=x(t),d=x(n),f=r.filter(e=>e!==t&&e!==n&&!(e.inner&&(E(e,t)||E(e,n)))),p=e.label.trim()?(0,i.wrapText)(e.label,176,i.FONT.label,s):[],m=(0,i.maxWidthOf)(p,i.FONT.label,s)+P(e.icon,p)+12,h=Math.max(p.length*16,e.icon?c:0)+4,g=[[],[[u[0],d[1]]],[[d[0],u[1]]]];for(let e of[...new Set(r.flatMap(e=>[e.x-a/2,e.x+e.w+a/2]))])g.push([[e,u[1]],[e,d[1]]]);for(let e of[...new Set(r.flatMap(e=>[e.y-a/2,e.y+e.h+a/2]))])g.push([[u[0],e],[d[0],e]]);t===n&&g.unshift([[t.x+t.w+8,u[1]],[t.x+t.w+8,t.y-8],[u[0],t.y-8]]);let _;for(let i of g){let a=[u,...i,d].filter((e,t,n)=>!t||A([n[t-1],e])>.01);if(a.length<2)continue;let s=T(t,a[1]),c=T(n,a.at(-2));if(A([u,s])>=A([u,a[1]])||A([d,c])>=A([d,a.at(-2)]))continue;a[0]=s,a[a.length-1]=c;let g=k(a),v=g.reduce((e,t)=>e+A(t),i.length*12);if(_&&v>=_.cost)continue;if((l.left-=g.length*(f.length+1))<0)return _;if(g.some(e=>f.some(t=>O(e,t))))continue;let y;if(p.length||e.icon){for(let[e,t]of[...g].sort((e,t)=>A(t)-A(e))){let n=(e[0]+t[0]-m)/2,i=(e[1]+t[1]-h)/2;for(let e of[[0,0],[0,-h/2-4],[0,h/2+4],[-m/2-4,0],[m/2+4,0]]){let t={x:n+e[0],y:i+e[1],w:m,h};if(!r.some(e=>(!e.inner||f.includes(e))&&D(e,t))&&!o.some(e=>D(e,t))){y=t;break}}if(y)break}if(!y)continue}if(_={...e,cost:v,path:a,plate:y,lines:p},!i.length)return _}return _}function M(e,{width:t,lang:n,measure:r},a){let c=a.config?.block?.padding,l=Number.isFinite(c)&&c>=0&&c<=2e3,u=l?c:o,d=g(e.root,r,u),f=new Map,p=[],m=[],h=[],v=[];c!==void 0&&!l&&v.push((0,i.warning)(`IGNORED_CONFIG`,n,a.configLines?.[`block.padding`]??a.headerLine??1,`已忽略无效的 block.padding`,`Ignored invalid block.padding`,`使用 0 到 2000 之间的数值`,`Use a number from 0 to 2000`)),_(d,s,s,d.w,f,p,u);let y=[...f.values()],b={left:2e6};for(let t of e.edges){let e=j(t,f.get(t.from),f.get(t.to),y,h,r,b);if(b.left<0){v.push((0,i.error)(n,t.line,`块图连线过于复杂`,`Block routing is too complex`,`拆分图表`,`Split the diagram`));break}e?(m.push(e),e.plate&&h.push(e.plate)):v.push((0,i.error)(n,t.line,`无法为 ${t.from} → ${t.to} 留出连线空间`,`No clear route for ${t.from} → ${t.to}`,`增加 space 留出走线空间`,`Add space cells to make room for the edge`))}let x=d.w+48;return(x>2*t||e.nodeCount>60)&&v.push((0,i.warning)(`LARGE_DIAGRAM`,n,a.headerLine||1,`块图较大,可滚动查看`,`Large block diagram; scroll to view it`,`考虑拆分块图`,`Consider splitting the diagram`)),{width:x,height:d.h+48,pad:u,nodes:y.filter(e=>!e.inner),frames:p,edges:m,errors:v}}function N(e,t,n){let{x:r,y:i,w:a,h:o,shape:s}=t,[c,l]=x(t);if(w(t)){let t=(t,n,r)=>e.el(`ellipse`,{cx:c,cy:l,rx:t,ry:n,...r});return[t(a/2,o/2,n),...s===`doublecircle`?[t(a/2-4,o/2-4,{...n,fill:`none`})]:[]]}let u=b(t);if(u)return[e.el(`polygon`,{points:u.map(e=>e.join(`,`)).join(` `),...n})];if(s===`cylinder`)return[e.path(`M${r} ${i+7} A${a/2} 7 0 0 1 ${r+a} ${i+7} V${i+o-7} A${a/2} 7 0 0 1 ${r} ${i+o-7} Z`,n),e.path(`M${r} ${i+7} A${a/2} 7 0 0 0 ${r+a} ${i+7}`,{...n,fill:`none`})];let d=s===`stadium`?Math.min(a,o)/2:s===`round`?10:0;return[e.rect(r,i,a,o,{...n,rx:d}),...s===`subroutine`?[10,a-10].map(t=>e.path(`M${r+t} ${i} V${i+o}`,{stroke:n.stroke,fill:`none`})):[]]}function P(e,t){return e?c+(t.length?l:0):0}function F(e,{icon:t,x:n,y:r,lines:a,font:o,lineHeight:s}){let l=P(t,a),u=(0,i.textBlock)(e,{x:n+l/2,y:r,lines:a,font:o,lineHeight:s});if(!t)return u;let[d,f,p,m]=t.viewBox.split(/\s+/).map(Number),h=c/Math.max(p,m),g=n-(l+(0,i.maxWidthOf)(a,o,(t,n)=>e.measure(t,n.size,n.weight)))/2+(c-p*h)/2,_=r-m*h/2,v=e.color(`fg`),y=t.set===`tabler`,b=e.el(`g`,{transform:`translate(${g} ${_}) scale(${h}) translate(${-d} ${-f})`,fill:y?`none`:v,stroke:y?v:`none`,"stroke-width":1.8,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)));return e.el(`g`,{},[b,u])}function I(e,t){let n=t.color(`muted`),r=t.design.bg,a=(0,i.appearance)(t).node,o=(e,t)=>`block-${e}${t?`-${t}`:``}`,s=(e,n)=>t.el(`marker`,{id:e,viewBox:`0 0 10 10`,refX:9,refY:5,markerWidth:7,markerHeight:7,markerUnits:`userSpaceOnUse`,orient:`auto-start-reverse`},[n]),c=new Map,l=(e,n,i)=>{let a=o(e,n);if(!c.has(a)){let n=e===`point`?t.path(`M0 0 L10 5 L0 10 Z`,{fill:i}):e===`circle`?t.el(`circle`,{cx:5,cy:5,r:4,fill:r,stroke:i}):t.path(`M1 1 L9 9 M9 1 L1 9`,{fill:`none`,stroke:i,"stroke-width":1.8});c.set(a,s(a,n))}return`url(#${a})`},u=[],d=(e,n)=>e.link?t.link(e.link.href,[n],e.link):n;for(let[n,i]of e.frames.entries()){let{x:a,y:o,w:s,h:c,status:l}=i,f=t.frameTone(l?t.design[l]:t.color(`tone${n%6+1}`)),p=t.rect(a,o,s,c,{rx:5,fill:t.tint(r,f,.07),stroke:t.tint(r,f,.45)}),m=F(t,{...i,x:a+s/2,y:o+e.pad+i.textH/2,lineHeight:18});u.push(d(i,{...t.el(`g`,{},[p,m]),meta:{kind:`frame`,id:i.id,...l?{status:l}:{}}}))}for(let i of e.nodes){let[e,o]=x(i),{status:s}=i,c=s&&t.frameTone(t.design[s]),l=N(t,i,{fill:c?t.tint(r,c,.11):a,stroke:t.tint(r,c||n,.62),"stroke-width":1.25});l.push(F(t,{...i,x:e,y:o,lineHeight:18})),u.push(d(i,{...t.el(`g`,{},l),meta:{kind:`node`,id:i.id,...s?{status:s}:{}}}))}for(let{from:a,to:o,path:s,pattern:c,thickness:d,arrowStart:f,arrowEnd:p,plate:m,lines:h,icon:g,status:_}of e.edges){let e=_?t.frameTone(t.design[_],!0):n,v={fill:`none`,stroke:e,"stroke-width":d,"stroke-linecap":`round`,"stroke-linejoin":`round`};if(c===`dotted`&&(v[`stroke-dasharray`]=`2 4`),f&&(v[`marker-start`]=l(f,_,e)),p&&(v[`marker-end`]=l(p,_,e)),u.push({...t.path(`M${s.map(e=>e.join(` `)).join(` L`)}`,v),meta:{kind:`edge`,from:a,to:o}}),m){let{x:e,y:n,w:s,h:c}=m;u.push({...t.el(`g`,{},[t.rect(e,n,s,c,{fill:r,rx:4}),F(t,{x:e+s/2,y:n+c/2,lines:h,icon:g,font:i.FONT.label,lineHeight:16})]),meta:{kind:`edge-label-group`,from:a,to:o}})}}return c.size&&u.unshift(t.el(`defs`,{},[...c.values()])),{width:e.width,height:e.height,children:u}}return e.implementations={block:{optionMode:`raw`,parse:h,layout:M,scene:I,acceptsPresentation:!0,honoredConfig:[`block.padding`]}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
1
|
+
KChartUnits["diagram/block"]=(function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=20,l=12,u=24,d=16,f=6,p=240,m=[[`(((`,`)))`,`doublecircle`],[`((`,`))`,`circle`],[`([`,`])`,`stadium`],[`(`,`)`,`round`],[`[[`,`]]`,`subroutine`],[`[(`,`)]`,`cylinder`],[`[/`,`/]`,`leanRight`],[`[\\`,`\\]`,`leanLeft`],[`[/`,`\\]`,`trapezoid`],[`[\\`,`/]`,`inverseTrapezoid`],[`[`,`]`,`square`],[`{{`,`}}`,`hexagon`],[`{`,`}`,`diamond`],[`>`,`]`,`notch`],[`<[`,`]>`,`arrow`]],h=/^(?:[xo<]?(?:--+[-xo>]|==+[=xo>]|-?\.+-[xo>]?)|~{3,}|==|<--)/,g={">":`point`,"<":`point`,o:`circle`,x:`cross`},_=new Set([`left`,`right`,`up`,`down`,`x`,`y`]);function v(e,{lang:n,firstLine:r=2,params:i=``,header:c=`block`}){let l={children:[]},u=[l],d=new Map,f=[],p=[],v=(0,o.presentation)({lang:n}),y=new Map,b=new Map,x,S=e=>{y.has(e.message)||y.set(e.message,e)},C=(e,t,r)=>S((0,s.warning)(`IGNORED_STYLE`,n,e,t,r,`移除此样式;普通块可使用 A:::ok 标记状态`,`Remove this style; use A:::ok to mark the status of an ordinary block`)),w=(e,r)=>{let i=(0,t.resolveIconRef)(e);return i||S((0,s.warning)(`IGNORED_ASSET`,n,r,`未知图标 ${e}`,`Unknown icon ${e}`,`使用内置图标`,`Use a supported icon`)),i},T=(e,t)=>{let r,i=e.replace(/(?<![\w:/.-])(?:logos|mdi|tabler|simple-icons):[a-z\d-]+/gi,e=>{let n=w(e,t);return r??=n,``}),o=(0,a.normalizeLabel)(i,{lang:n,line:t});return o.diagnostics.forEach(S),{label:o.text,icon:o.icon??r}},E=0,D=0,O=r,k=1,A=(e,t,r,i)=>p.push((0,s.error)(n,O,e,t,r,i,k));if(e.length+i.length>2e5)return A(`块图源码过长`,`Block source is too long`,`拆分块图,使每张图的源码不超过 200,000 个字符`,`Split the source into diagrams of at most 200,000 characters`),{model:null,errors:p};for(let[t,n]of[i,...e.split(`
|
|
2
|
+
`)].entries()){O=r+t-1;let e=n,a=t=>{e=e.slice(t)},o=()=>a(e.match(/^\s*/)[0].length),s=()=>{let t=/^:(\d+)/.exec(e);return t&&a(t[0].length),t?Number(t[1]):1},l=()=>{let t=/^(?![-.])[^()[\]{}<>:=;"\s~]+?(?=$|[()[\]{}<>:=;"\s~]|--|-?\.+-|%%)/.exec(e);if(!t)return null;let n=t[0];a(n.length);let r={id:n,line:O},i=m.find(([t])=>e.startsWith(t))?.[0];if(i){a(i.length);let t=/^\s*"([^"]*)"\s*/.exec(e),n;if(t){if(a(t[0].length),n=m.find(([t,n])=>t===i&&e.startsWith(n)),!n){let t=/^(?:\)\)\)|\)\)|\)\]|\]\)|\]\]|\}\}|[)\]}])/.exec(e);t&&(n=[i,t[0],`square`])}r.label=t[1]}else if(n=m.find(([t,n])=>t===i&&e.includes(n)),n){let t=e.indexOf(n[1]);r.label=e.slice(0,t).trim(),a(t)}if(!n)return null;if(a(n[1].length),r.shape=n[2],r.shape===`arrow`){let t=/^\s*\(([^)]*)\)/.exec(e);if(r.directions=t?.[1].split(/[\s,]+/).filter(Boolean),!r.directions?.length||r.directions.some(e=>!_.has(e)))return null;a(t[0].length)}}let o=()=>{let t=/^::icon\(\s*([^()]+?)\s*\)/i.exec(e),i=/^:::([\w-]+(?:,[\w-]+)*)/.exec(e);return t?(r.iconRef=t[1],a(t[0].length)):i&&(b.set(n,b.get(n)??O),v.addClasses(n,i[1].split(`,`),O),a(i[0].length)),t||i};for(;o(););for(r.span=s();o(););return r.span>0&&r.span<=2e3?r:null},y=(e,t)=>{let n=d.get(e.id);n?(e.label!==void 0&&!n.children&&Object.assign(n,{label:e.label,labelLine:e.line,shape:e.shape,directions:e.directions}),e.iconRef&&Object.assign(n,{iconRef:e.iconRef,iconLine:e.line})):(d.set(e.id,e),t.children.push(e))};for(;e&&(o(),k=n.length-e.length+1+(t===0?Math.max(0,c.indexOf(i)):0),e&&!/^%%(?!\{)/.test(e));){if(e[0]===`;`){a(1);continue}let t=/^(style|class)\s+([^\s,]+(?:\s*,\s*[^\s,]+)*)\s+(.+)$/i.exec(e);if(t?.[1].toLowerCase()===`style`&&/^[\w-]+#[\da-f]+;?\s*$/i.test(t[3])){C(O,`已忽略缺少冒号的块图样式`,`Ignored a block style missing its colon`);break}if(t&&/^style$/i.test(t[1])){for(let e of t[2].split(/\s*,\s*/))v.accept(`style ${e} ${t[3]}`,O),b.set(e,b.get(e)??O);break}if(v.accept(e,O)){if(t)for(let e of t[2].split(/\s*,\s*/))b.set(e,b.get(e)??O);/^classDef\s+default\b/i.test(e)&&(x??=O);break}if(/^interpolate\s/i.test(e)){C(O,`已忽略插值样式;连线使用网格走线`,`Ignored interpolation; edges follow grid routes`);break}let n=u.at(-1),r=/^columns\s+(auto|\d+)(?=\s|;|$)/.exec(e),i=/^space(?=[:;\s]|$)/.exec(e),c=/^block(?:-beta)?(?=[:;\s]|$)/.exec(e),m=/^end(?=[;\s]|$)/.exec(e);if(r){a(r[0].length);let e=r[1]===`auto`?0:Number(r[1]);if(e>2e3||e===0&&r[1]!==`auto`){A(`无效的列数`,`Invalid column count`,`使用 columns auto 或指定 1–2000 列`,`Use columns auto or set a count from 1 to 2000`);break}n.columns=e}else if(i){a(i[0].length);let e=s();if(e>2e3){A(`占位过宽`,`Space span is too large`,`将 space:N 中的 N 减至 2000 以内`,`Reduce N in space:N to at most 2000`);break}if(D+=e,D>2e4)return A(`占位单元格过多`,`Too many space cells`,`减少 space:N 占位,使总数不超过 20,000`,`Reduce space:N placeholders to at most 20,000 cells in total`),{model:null,errors:p};n.children.push({space:!0,span:e})}else if(c){a(c[0].length);let t=e[0]===`:`&&!/^:\d/.test(e);t&&a(1);let r=t?l():{id:`:block${++E}`,line:O,span:s()};if(!r||!r.span||r.span>2e3||u.length>32||d.has(r.id)){!r||!r.span||r.span>2e3?A(`无效的复合块声明`,`Invalid composite block declaration`,`使用 block:Group 并用 end 结束;跨度须为 1–2000`,`Use block:Group with a matching end; keep the span between 1 and 2000`):u.length>32?A(`复合块嵌套过深`,`Composite blocks are nested too deeply`,`将嵌套层数减至 32 层以内`,`Reduce nesting to at most 32 levels`):A(`复合块标识符「${r.id}」已使用`,`Composite block ID "${r.id}" is already in use`,`为 block: 后的标识符换一个未使用的名称`,`Use a unique ID after block:`);break}r.children=[],y(r,n),u.push(r)}else if(m){if(a(m[0].length),u.length===1){A(`end 没有对应的 block`,`No matching block for end`,`删除多余的 end,或在对应的子块前添加 block:Group`,`Remove the stray end or open a group with block:Group before its children`);break}u.pop()}else{let t=l();if(!t){A(`无法识别块图语句`,`Unrecognized block statement`,`使用块声明 A["名称"]、占位 space 或连线 A --> B`,`Use a block such as A["Label"], a space placeholder, or an edge such as A --> B`);break}for(y(t,n),o();e;){let r=/^([xo<]?(?:--|==|-\.))\s*"([^"]*)"\s*/.exec(e),i=h.exec(r?e.slice(r[0].length):e);if(!i)break;a((r?.[0].length??0)+i[0].length),o();let s=l();if(!s){A(`连线缺少终点`,`Missing edge endpoint`,`在箭头后添加目标块标识符,例如 A --> B`,`Add a destination block ID after the arrow, as in A --> B`);break}y(s,n);let c=i[0],u=!r&&/^\s+:\s+(.+)$/.exec(e);if(u&&a(u[0].length),f.push({from:t.id,to:s.id,line:O,label:r?.[2]??u?.[1]??``,arrowStart:g[c[0]],arrowEnd:g[c.at(-1)],thickness:c.includes(`==`)?2.5:1.5,pattern:c.includes(`.-`)?`dotted`:`solid`}),d.size>2e3||f.length>500)return A(`块或连线过多`,`Too many blocks or edges`,`拆分为每张最多 2000 个块、500 条连线的图`,`Split into diagrams of at most 2000 blocks and 500 edges each`),{model:null,errors:p};t=s,o()}}if(d.size>2e3)return A(`块过多`,`Too many blocks`,`拆分为每张最多 2000 个块的图`,`Split into diagrams of at most 2000 blocks each`),{model:null,errors:p}}}u.length>1&&(O=u.at(-1).line,k=1,A(`复合块缺少 end`,`Composite block is missing end`,`在子块之后单独写一行 end;如果它是普通块,去掉 block: 前缀`,`Put end on its own line after the children, or remove the block: prefix for an ordinary block`)),d.size||l.children.length||p.length||(O=r-1,k=1,A(`块图为空`,`Empty block diagram`,`在头行后添加块,例如 A["名称"]`,`Add a block after the header, for example A["Label"]`)),p.push(...v.diagnostics());for(let e of d.values()){e.label!==void 0&&Object.assign(e,T(e.label,e.labelLine??e.line)),e.iconRef&&(e.icon=w(e.iconRef,e.iconLine??e.line)??e.icon);let t=v.statusOf(e.id);t&&e.shape===`arrow`&&!e.children?C(b.get(e.id)??x??e.line,`块箭头不应用自定义样式`,`Block arrows do not apply custom styling`):e.status=t,e.link=v.linkOf(e.id)}return f.forEach((e,t)=>Object.assign(e,T(e.label,e.line),{status:v.edgeStatusOf(t)})),{model:{root:l,edges:f,nodeCount:d.size},errors:[...p,...y.values()]}}function y(e,t,r,i){let a=i.get(e)??x(),o=[],l=e.columns||1/0,u=0,f=0,m=72,h,g=()=>h??={h:36,cells:[]},_=e=>{u+=e,f=Math.max(f,u),u>=l&&(o.push(h),h=void 0,u=0)};for(let a of e.children){if(a.space){for(let e=a.span;e>0;){g();let t=Math.min(e,l-u);_(t),e-=t}continue}let e=a.children?y(a,t,r,i):null,o,v,b;if(e){let i=(0,n.frameTitle)({title:a.label??``,icon:a.icon},t),s=e.gaps.inset.map((e,t)=>Math.max(e,t===0&&i.band?i.band:r)),[c,l,d,f]=s;v=Math.max(i.minW,e.w+f+l),b=e.h+c+d,o={...a,col:u,inner:e,title:i,inset:s}}else{let e=a.label??a.id,n=e.trim()?(0,s.wrapText)(e,p-j(a.icon,[e]),s.FONT.body,t):[],r=(0,s.maxWidthOf)(n,s.FONT.body,t)+j(a.icon,n),i=Math.max(n.length*18,a.icon?d:0);v=r+28,b=i+20;let c=[`diamond`,`circle`,`doublecircle`].includes(a.shape);c?v=b=Math.ceil(a.shape===`diamond`?r+i+24:Math.hypot(r,i)+24):a.shape===`arrow`?(v+=28,b+=24):a.shape===`cylinder`?b+=12:a.shape&&![`square`,`round`,`stadium`].includes(a.shape)&&(v+=20),o={...a,col:u,lines:n,font:s.FONT.body,textH:i,...c?{diameter:v}:{}}}g().cells.push(o),h.h=Math.max(h.h,b),m=Math.max(m,Math.ceil((v-(a.span-1)*c)/a.span)),f=Math.max(f,u+a.span),_(Math.min(a.span,l-u))}h&&o.push(h);let v=Array.from({length:Math.max(0,f-1)},(e,t)=>a.x.get(t)??c),S=o.slice(1).map((e,t)=>a.y.get(t)??c);return{group:e,gaps:a,rows:o,xGaps:v,yGaps:S,columns:f,w:f*m+b(v),h:b(o.map(e=>e.h))+b(S)}}var b=e=>e.reduce((e,t)=>e+t,0),x=()=>({x:new Map,y:new Map,inset:[0,0,0,0]});function S(e,t,n,r,i,a,o,s,c){if(!e.columns)return;let l=(r-b(e.xGaps))/e.columns,u=[t],d=(t,n,r,i,a,s,c=!1)=>{i>0&&o.push({group:e.group,axis:t,index:n,start:r,size:i,lo:a,hi:s,inset:c})};for(let[t,r]of e.xGaps.entries())d(`x`,t,u[t]+l,r,n,n+e.h),u.push(u[t]+l+r);c&&(d(`y`,0,c.y,n-c.y,t,t+r,!0),d(`x`,1,t+r,c.x+c.w-t-r,n,n+e.h,!0),d(`y`,2,n+e.h,c.y+c.h-n-e.h,t,t+r,!0),d(`x`,3,c.x,t-c.x,n,n+e.h,!0));for(let[c,f]of e.rows.entries()){for(let e of f.cells){let t=e.col+e.span-1,r={...e,x:u[e.col],y:n,w:u[t]-u[e.col]+l,h:f.h,...s?{parent:s}:{}};if(e.diameter?(r.x+=(r.w-e.diameter)/2,r.y+=(r.h-e.diameter)/2,r.w=r.h=e.diameter):!e.inner&&e.shape===`arrow`&&!e.textH&&(r.x+=(r.w-28)/2,r.y+=(r.h-28)/2,r.w=r.h=28),i.set(r.id,r),r.inner){a.push(r);let[t,s,,c]=e.inset;S(r.inner,r.x+c,n+t,r.w-c-s,i,a,o,r.id,r)}}let p=e.yGaps[c]??0;d(`y`,c,n+f.h,p,t,t+r),n+=f.h+p}}function C(e,t,n,r,a){let o=!1;for(let{group:s,axis:c,index:l,start:u,size:d,lo:f,hi:p,inset:m}of e){let e=c===`x`?`y`:`x`,h=c===`x`?`w`:`h`,g=u+d,_=e=>u<e&&e<g,v=d;if(!m)for(let{from:t,to:a,label:o}of n){if(!o||o[h]+2*i.TRACK_CLEAR<=v)continue;let n=c===`x`?`h`:`w`,s=r.get(t),l=r.get(a),[d,m]=s[c]<l[c]?[s,l]:[l,s];Math.abs(d[c]+d[h]-u)<.01&&Math.abs(m[c]-g)<.01&&Math.min(p,s[e]+s[n],l[e]+l[n])>Math.max(f,s[e],l[e])&&(v=o[h]+2*i.TRACK_CLEAR)}let y=[];for(let{points:n,labelRect:r}of t){if(r&&_(r[c]+r[h]/2)){let t=c===`x`?`h`:`w`,n=r[e]+r[t]/2;f<=n&&n<=p&&(v=Math.max(v,r[h]+2*i.TRACK_CLEAR))}for(let t=1;t<n.length;t++){let r=n[t-1],i=n[t];if(r[c]!==i[c]||!_(r[c]))continue;let a=Math.max(f,Math.min(r[e],i[e])),o=Math.min(p,Math.max(r[e],i[e]));o>a&&y.push([a,1],[o,-1])}}let b=0;for(let[,e]of y.sort(([e,t],[n,r])=>e-n||t-r))b+=e,b>0&&(v=Math.max(v,2*i.TRACK_CLEAR+(b-1)*i.TRACK_GAP));if(v<=d+.01)continue;let S=a.get(s)??x();a.set(s,S),m?S.inset[l]=Math.ceil(v):S[c].set(l,Math.ceil(v)),o=!0}return o}var w={diamond:[[.5,0],[1,.5],[.5,1],[0,.5]],hexagon:[[.13,0],[.87,0],[1,.5],[.87,1],[.13,1],[0,.5]],notch:[[0,0],[1,0],[1,1],[0,1],[.13,.5]],leanRight:[[.13,0],[1,0],[.87,1],[0,1]],leanLeft:[[0,0],[.87,0],[1,1],[.13,1]],trapezoid:[[.13,0],[.87,0],[1,1],[0,1]],inverseTrapezoid:[[0,0],[1,0],[.87,1],[.13,1]]};function T(e){let t=w[e.shape];if(e.shape===`arrow`){let n=e.directions,r=[`up`,`right`,`down`,`left`].map((e,t)=>n.includes(e)||n.includes(t%2?`x`:`y`)),i=Math.min(.22,16/e.w),a=Math.min(.24,14/e.h),[o,s,c,l]=r.map((e,t)=>e?[a,i][t%2]:0),u=[[l,o],[1-s,o],[1-s,1-c],[l,1-c]],d=[[[.24,o],[.5,0],[.76,o]],[[1-s,.24],[1,.5],[1-s,.76]],[[.76,1-c],[.5,1],[.24,1-c]],[[l,.76],[0,.5],[l,.24]]],f=r[0]||r[2],p=r[1]||r[3];if(f&&!p){let t=Math.min(.28,12/e.w);u.forEach((e,n)=>{e[0]=n===0||n===3?t:1-t}),d[0][0][0]=0,d[0][2][0]=1,d[2][0][0]=1,d[2][2][0]=0}else if(p&&!f){let t=Math.min(.24,12/e.h);u.forEach((e,n)=>{e[1]=n<2?t:1-t}),d[1][0][1]=0,d[1][2][1]=1,d[3][0][1]=1,d[3][2][1]=0}t=u.flatMap((e,t)=>{if(!r[t])return[e];let n=u[(t+1)%4],i=d[t],a=t%2;if(p&&f)return[e,...i];let o=(e,t)=>e.map((e,n)=>n===a?e:t[n]);return[e,o(i[0],e),...i,o(i[2],n)]})}return t?.map(([t,n])=>[e.x+t*e.w,e.y+n*e.h])}var E=e=>[e.x+e.w/2,e.y+e.h/2],D=e=>e.shape===`circle`||e.shape===`doublecircle`;function O(e){let[t,n]=E(e),r=e.x+e.w,i=e.y;return[{x:r,y:n},{x:r+12,y:n},{x:r+12,y:i-12},{x:t,y:i-12},{x:t,y:i}]}function k(e,{width:t,lang:i,measure:a},o){let c=o.config?.block?.padding,d=Number.isFinite(c)&&c>=0&&c<=2e3,f=d?c:l,p=new Map,m=[],h=[];c!==void 0&&!d&&h.push((0,s.warning)(`IGNORED_CONFIG`,i,o.configLines?.[`block.padding`]??o.headerLine??1,`已忽略无效的 block.padding`,`Ignored invalid block.padding`,`使用 0 到 2000 之间的数值`,`Use a number from 0 to 2000`));let g=e.edges.map(e=>(0,n.measureLabel)(e.label,a,e.icon)),_=e.edges.flatMap((e,t)=>e.from===e.to?[]:[{id:t,from:e.from,to:e.to,...g[t]?{label:g[t]}:{}}]),v,b,x,w,T,E;for(let t=0;t<3;t++){let i=y(e.root,a,f,p),o=[];if(v=new Map,b=[],S(i,u,u,i.w,v,b,o),x=[...v.values()].filter(e=>!e.inner),w=i.w+48,T=i.h+48,E=(0,r.routeBoard)({width:w,height:T,nodes:x,frames:b.map(e=>({...e,titleRect:(0,n.titleRect)(e,e.title)})),edges:_}),t===2||!C(o,E.edges,_,v,p))break}let D=new Map(E.edges.map(e=>[e.id,e]));return e.edges.forEach((e,t)=>{let n=D.get(t),r=g[t];if(e.from===e.to){let t=O(v.get(e.from)),n=r&&{x:t[2].x+4,y:t[2].y-r.h/2,w:r.w,h:r.h};m.push({...e,points:t,label:n?{rect:n,lines:r.lines}:null})}else n?m.push({...e,points:n.points,label:r&&n.labelRect?{rect:n.labelRect,lines:r.lines}:null}):h.push((0,s.error)(i,e.line,`无法为 ${e.from} → ${e.to} 留出连线空间`,`No clear route for ${e.from} → ${e.to}`,`增加 space 留出走线空间`,`Add space cells to make room for the edge`))}),(w>2*t||e.nodeCount>60)&&h.push((0,s.warning)(`LARGE_DIAGRAM`,i,o.headerLine||1,`块图较大,可滚动查看`,`Large block diagram; scroll to view it`,`考虑拆分块图`,`Consider splitting the diagram`)),{width:w,height:T,pad:f,nodes:x,frames:b,edges:m,errors:h}}function A(e,t,n){let{x:r,y:i,w:a,h:o,shape:s}=t,[c,l]=E(t);if(D(t)){let t=(t,n,r)=>e.el(`ellipse`,{cx:c,cy:l,rx:t,ry:n,...r});return[t(a/2,o/2,n),...s===`doublecircle`?[t(a/2-4,o/2-4,{...n,fill:`none`})]:[]]}let u=T(t);if(u)return[e.el(`polygon`,{points:u.map(e=>e.join(`,`)).join(` `),...n})];if(s===`cylinder`)return[e.path(`M${r} ${i+7} A${a/2} 7 0 0 1 ${r+a} ${i+7} V${i+o-7} A${a/2} 7 0 0 1 ${r} ${i+o-7} Z`,n),e.path(`M${r} ${i+7} A${a/2} 7 0 0 0 ${r+a} ${i+7}`,{...n,fill:`none`})];let d=s===`stadium`?Math.min(a,o)/2:s===`round`?10:0;return[e.rect(r,i,a,o,{...n,rx:d}),...s===`subroutine`?[10,a-10].map(t=>e.path(`M${r+t} ${i} V${i+o}`,{stroke:n.stroke,fill:`none`})):[]]}function j(e,t){return e?d+(t.length?f:0):0}function M(e,{icon:t,x:n,y:r,lines:i,font:a,lineHeight:o}){let c=j(t,i),l=(0,s.textBlock)(e,{x:n+c/2,y:r,lines:i,font:a,lineHeight:o});if(!t)return l;let[u,f,p,m]=t.viewBox.split(/\s+/).map(Number),h=d/Math.max(p,m),g=n-(c+(0,s.maxWidthOf)(i,a,(t,n)=>e.measure(t,n.size,n.weight)))/2+(d-p*h)/2,_=r-m*h/2,v=e.color(`fg`),y=t.set===`tabler`,b=e.el(`g`,{transform:`translate(${g} ${_}) scale(${h}) translate(${-u} ${-f})`,fill:y?`none`:v,stroke:y?v:`none`,"stroke-width":1.8,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)));return e.el(`g`,{},[b,l])}var N={point:`arrow`,circle:`circle`,cross:`cross`};function P(e,t){let r=t.color(`muted`),i=t.design.bg,a=(0,s.appearance)(t).node,o=(0,n.boardLook)(t),c=(0,n.markers)(t),l=(e,n)=>e.link?t.link(e.link.href,[n],e.link):n,u=e.frames.map(e=>({...e,style:e.status})),d=u.map(e=>l(e,(0,n.drawFrame)(t,e,o))),f=e.nodes.map(e=>{let[n,o]=E(e),{status:s}=e,c=s&&t.design[s],u=A(t,e,{fill:c?t.tint(i,c,.11):a,stroke:t.tint(i,c||r,.62),"stroke-width":1.25});return u.push(M(t,{...e,x:n,y:o,lineHeight:18})),l(e,{...t.el(`g`,{},u),meta:{kind:`node`,id:e.id,...s?{status:s}:{}}})}),p=[],m=[];for(let r of e.edges){let{from:e,to:i,pattern:a,thickness:s,arrowStart:l,arrowEnd:d,label:f,icon:h,status:g}=r,_=s>2?{...o.edge(`plain`,g),width:2.5}:o.edge(a===`dotted`?`dashed`:`plain`,g),v=e=>e&&c.url(N[e],_.stroke);if(p.push((0,n.drawEdge)(t,r,_,{start:v(l),end:v(d)})),f){let{rect:r}=f;m.push((0,n.drawLabel)(t,{from:e,to:i,rect:r,lines:f.lines,icon:h,plate:(0,n.surfaceAt)(u,o,r.x+r.w/2,r.y+r.h/2)},o))}}return{width:e.width,height:e.height,children:[...c.defs(),...d,...p,...f,...m]}}return e.implementations={block:{optionMode:`raw`,parse:v,layout:k,scene:P,acceptsPresentation:!0,honoredConfig:[`block.padding`]}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/board-paint`],KChartUnits[`diagram/board-route`],KChartUnits[`diagram/graph-route`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
KChartUnits["diagram/blocks"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var
|
|
2
|
-
`).entries()){if(!n.trim()||n.trimStart().startsWith(`%%`))continue;let e=o+t;if(/^\s*\t/.test(n)){s.push(f(i,e,`缩进不能使用 Tab`,`Tabs are not allowed in indentation`,`把 Tab 换成空格`,`Replace tabs with spaces`));continue}let a=n.match(/^ */)[0].length,p=n.slice(a).trim(),g=p.match(/^(.+?)\s*(->|~>)\s*(.+?)(?:\s*[::]\s*(.*))?$/),_=/^(row|col|box)(?:\s|$)/.test(p);for(;u.length&&a<=u.at(-1).indent;)u.pop();let v=u.at(-1);if(g&&!_&&(!v||v.kind!==`box`||v.inline)){a&&s.push(f(i,e,`关系必须写在顶格`,`Relations must start at column 0`,`去掉这一行的缩进`,`Remove the indentation from this relation`)),l.push({from:g[1].trim(),to:g[3].trim(),async:g[2]===`~>`,label:(g[4]||``).trim(),line:e});continue}if(!_&&v?.kind===`box`&&!v.inline){v.items.push(...h(p,e,i,s));continue}let y=u.length;if(d[y]??=a,d[y]!==a){s.push(f(i,e,`同级条目的缩进不一致`,`Inconsistent indentation at the same level`,`把这一行缩进改为 ${d[y]} 个空格`,`Indent this line with ${d[y]} spaces`));continue}if(u.filter(e=>e.kind===`box`).length+ +!!p.startsWith(`box`)>r.depth){s.push(f(i,e,`嵌套超过 ${r.depth} 层`,`Nesting exceeds ${r.depth} levels`,`把内层拆成另一张图`,`Split the inner level into another diagram`));continue}let b=m(p,e,a,i,s);b&&((v?v.children:c).push(b),u.push(b))}let p=[],_=[];g(c,null,(e,t)=>{e.parent=t,e.kind===`box`&&p.push(e),_.push(...e.items),e.kind!==`box`&&e.items.length&&s.push(f(i,e.line,`能力项只能写在 box 内`,`Capabilities belong inside a box`,`把这一行改成 box,或移入上一个 box`,`Change this line into a box, or move it into the previous box`)),e.children.length&&e.items.length&&s.push(f(i,e.line,`box 不能同时写行内能力项和子容器`,`A box cannot mix inline capabilities and child containers`,`改成缩进的能力项,或去掉子容器`,`Use indented capabilities, or remove the child containers`))});let v=new Map;for(let e of p){e.title||s.push(f(i,e.line,`box 名称不能为空`,`Box name cannot be empty`,`写上唯一名称`,`Add a unique name`));let t=v.get(e.title)||[];t.push(e),v.set(e.title,t)}for(let[e,t]of v)t.length>1&&s.push(f(i,t[1].line,`容器名称「${e}」重复`,`Duplicate container name: ${e}`,`改成唯一名称;关系只能指向唯一容器`,`Use a unique name; relations can only target one container`));for(let e of l)for(let t of[`from`,`to`])(v.get(e[t])||[]).length!==1&&s.push(f(i,e.line,`关系指向的容器「${e[t]}」不存在或不唯一`,`Relation target "${e[t]}" is missing or not unique`,`改成图中唯一的容器名称`,`Use the unique name of a container in this diagram`));l.length>r.edges&&s.push(f(i,l[r.edges].line,`关系最多 ${r.edges} 条`,`At most ${r.edges} relations`,`删掉次要关系,或改用泳道图、流程图`,`Remove secondary relations, or use a swimlane or flowchart`));for(let e of l)[...e.label].length>r.labelChars&&s.push(f(i,e.line,`关系标签「${e.label}」过长`,`Relation label is too long: ${e.label}`,`把标签缩到 ${r.labelChars} 个字符以内,或把说明移到图外`,`Keep the label within ${r.labelChars} characters, or move the description outside`));p.length>r.boxes&&s.push(f(i,p[r.boxes].line,`容器最多 ${r.boxes} 个`,`At most ${r.boxes} containers`,`拆成总图和分图`,`Split into an overview and detail diagrams`)),_.length>r.items&&s.push(f(i,_[r.items].line,`能力项最多 ${r.items} 个`,`At most ${r.items} capabilities`,`把说明移到图外,或拆成两张图`,`Move descriptions outside, or split into two diagrams`));for(let e of _)e.icon&&!(0,n.has)(e.icon)&&s.push(f(i,e.line,`未知图标「${e.icon}」`,`Unknown icon: ${e.icon}`,`换成图标库中的名称,例如 database`,`Use a name from the icon library`));return c.length||s.push(f(i,o,`图中没有容器`,`Diagram has no containers`,`添加 row、col 或 box`,`Add a row, col, or box`)),{model:{type:`blocks`,nodes:c,edges:l,boxes:p,items:_},errors:s}}function m(e,t,n,r,i){let a=e.match(/^(row|col|box)(?:\s+(.*))?$/);if(!a)return i.push(f(r,t,`无法识别这一行`,`Unrecognized line`,`使用 row、col、box,或「容器 -> 容器: 标签」`,`Use row, col, box, or "container -> container: label"`)),null;let o=a[1],s=(a[2]||``).trim();if(o!==`box`){let e=s.match(/^(\d+(?:\.\d+)?)(?:\s+(.*))?$/),a=e?Number(e[1]):1;return e&&!(a>0)?i.push(f(r,t,`宽度权重必须是正数`,`Width weight must be a positive number`,`写成正数,例如 col 3`,`Use a positive number, for example col 3`)):s&&!e&&i.push(f(r,t,`${o} 后面只能写宽度权重`,`Only a width weight may follow ${o}`,`删掉多余文字,或改成 box`,`Remove the extra text, or change this into a box`)),{kind:o,weight:a,explicit:!!e,indent:n,line:t,title:``,flag:``,items:[],children:[]}}let c=s,l=1,u=!1,d=s.match(/^(\d+(?:\.\d+)?)\s+(?![::\s])([\s\S]*)$/);d&&(l=Number(d[1]),u=l>0,c=d[2],u||(l=1));let p=c.search(/[::]/),m=(p<0?c:c.slice(0,p)).trim(),g=p<0?``:c.slice(p+1),_=m.match(/\s*\{(db|ext)\}\s*$/)?.[1]||``,v=m.replace(/\s*\{(db|ext)\}\s*$/,``).trim(),y=/\{(?!db\}|ext\})/.test(m)||/\}\s*\S/.test(m);(y||!v&&c)&&i.push(f(r,t,`box 写法无效`,`Invalid box syntax`,`使用「box 名称 [{db}|{ext}] [: 能力项, 能力项]」`,`Use "box Name [{db}|{ext}] [: item, item]"`));let b=g?h(g,t,r,i):[];return{kind:o,weight:l,explicit:u,indent:n,line:t,title:v,flag:y?``:_,inline:b.length>0,items:b,children:[]}}function h(e,t,n,r){return e.split(/[,,]/).map(e=>{let i=e.trim(),a=i.match(/^\[icon:([a-z0-9][\w.-]*)\]\s*/i),o=a?i.slice(a[0].length):i,s=o.match(/^([+~=])\s*/)?.[1]||``,c=o.replace(/^[+~=]\s*/,``).trim();return c||r.push(f(n,t,`能力项名称不能为空`,`Capability labels cannot be empty`,`删除空项或补上名称`,`Remove the empty item or add a label`)),/\[icon:/.test(i)&&!a&&r.push(f(n,t,`图标写法无效`,`Invalid icon syntax`,`写成 [icon:database] 名称`,`Write [icon:database] name`)),{label:s?`${s} ${c}`:c,name:c,mark:s,tone:{"+":`new`,"~":`info`,"=":`ok`}[s]||``,icon:a?.[1]||``,line:t}}).filter(e=>e.name)}function g(e,t,n){for(let r of e)n(r,t),g(r.children,r,n)}function _(e,{width:n,lang:i,measure:a}){let o=[],s=e.nodes.length===1?e.nodes[0]:{kind:`col`,weight:1,children:e.nodes,items:[],title:``,line:e.nodes[0]?.line||1},c=[],l=[],d=e=>{e.kind===`box`&&c.push(e),l.push(...e.items||[]),e.children.forEach(d)};d(s);for(let e of l)([...e.name].length>r.labelChars||a(e.name,t.FONT.body)>r.labelWidth)&&o.push(f(i,e.line,`能力项「${e.label}」过长`,`Capability label is too long: ${e.label}`,`把说明移到图外,名称缩短至约 16 个汉字`,`Move descriptions outside; shorten the label to about 16 CJK characters`));for(let e of c)a(e.title,t.FONT.title)>r.labelWidth*2&&o.push(f(i,e.line,`容器标题「${e.title}」过长`,`Container title is too long: ${e.title}`,`缩短标题,把说明放到图注`,`Shorten the title and move the description to the caption`));if(o.length)return{width:n,height:0,errors:o};let p=new Map(c.map(e=>[e.title,e])),m=e.edges.map(e=>({...e,fromBox:p.get(e.from),toBox:p.get(e.to)})),h=new Map;for(let e of m){let t=O(e.fromBox,e.toBox);h.has(t)||h.set(t,[]),h.get(t).push(e)}let g=E(s,a,h),_=Math.max(Math.floor(n),g.w+8),v=A(s,u,u,_-8,a,h),y=[],b=[];M(v,y,b);let x=[];for(let e of m){let t=F(e,y,b,a);t?x.push(t):o.push(f(i,e.line,`容器「${e.from}」与「${e.to}」之间没有可用箭头通道`,`No clear arrow lane between "${e.from}" and "${e.to}"`,`让两个容器只隔一条空间隙,并避开能力项;或改用泳道图、流程图`,`Leave one empty gap between the containers and clear of capability items, or use a swimlane or flowchart`))}return o.length?{width:_,height:v.h+8,frames:y,nodes:b,edges:x,errors:o}:{type:`blocks`,width:_,height:(0,t.snap)(v.h+8),frames:y,nodes:b,edges:x,errors:[]}}var v=(e,t,n)=>n(String(e||``),t);function y(e,n){return(0,t.snap)(Math.max(48,v(e.label,t.FONT.body,n)+16+(e.icon?28:0)))}function b(e,n){return e.length?(0,t.snap)(Math.max(72,...e.map(e=>y(e,n)))):72}function x(e,t,n){let r=Math.max(1,t),i=Math.max(1,Math.ceil(e.length/r));return{cols:r,rows:i,cell:n,width:r*n+s*(r-1),height:i*c+s*(i-1)}}function S(e,t,n){let r=b(e,t),i=Math.max(1,e.length),a=Math.min(i,Math.ceil(Math.sqrt(i))),o=null;for(let t=1;t<=i;t+=1){let c=x(e,t,r);if(c.width>n&&t!==1)break;let l=[+(Math.floor((n-s*(t-1))/t)>d),c.rows*c.cols-i,Math.abs(c.cols-c.rows),c.rows,Math.abs(c.cols-a)];(!o||C(l,o.score))&&(o={grid:c,score:l})}return o?o.grid:x(e,1,r)}function C(e,t){for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return e[n]<t[n];return!1}var w=160;function T(e,n){if(!e)return{lines:[],w:0,h:0};let i=(0,t.wrapText)(e,w,t.FONT.label,n).slice(0,r.labelLines);return{lines:i,w:(0,t.snap)((0,t.maxWidthOf)(i,t.FONT.label,n)+12),h:i.length*16+2}}function E(e,n,r){if(e.kind!==`box`&&!e.children.length&&!e.items?.length)return{w:72,h:36};if(e.kind===`box`&&e.items?.length&&!e.children.length){let r=x(e.items,1,b(e.items,n)),i=(0,t.snap)(v(e.title,t.FONT.title,n)+24);return{w:Math.max(r.width,i)+24,h:l+r.height+o,grid:r}}if(e.kind===`box`&&!e.children.length){let r=Math.max(48,(0,t.snap)(v(e.title,t.FONT.title,n))+24);return{w:(0,t.snap)(r),h:48}}let i=e.children.map(e=>({child:e,size:E(e,n,r)})),a=e.kind===`col`,s=D(e,i.map(e=>e.child),r,n),c=Math.max(72,...i.map(e=>a?e.size.w:e.size.h)),u=i.reduce((e,t)=>e+(a?t.size.h:t.size.w),0)+s.reduce((e,t)=>e+t,0),d=a?c:u,f=a?u:c;if(e.kind===`box`){let r=(0,t.snap)(v(e.title,t.FONT.title,n)+24);d=Math.max(d,r)+24,f+=48}return{w:(0,t.snap)(d),h:(0,t.snap)(f),kids:i}}function D(e,t,n,r){let o=e.kind===`col`,s=[];for(let e=0;e<t.length-1;e+=1){let c=[];for(let r of k(t[e]))for(let i of k(t[e+1]))c.push(...n.get(O(r,i))||[]);s.push(c.length?Math.max(a,...c.map(e=>{let t=T(e.label,r);return o?t.h?t.h+48:0:t.w+24})):i)}return s}function O(e,t){return[e.title,t.title].sort().join(`\0`)}function k(e,t=[]){e.kind===`box`&&t.push(e);for(let n of e.children||[])k(n,t);return t}function A(e,t,n,r,i,a,u=0){let d={...e,x:t,y:n,w:r,h:0,children:[],itemNodes:[]},f=e.kind===`box`,p=f?t+o:t,m=f?n+l:n,h=f?r-24:r,g=f?48:0;if(f&&e.items?.length&&!e.children.length){let t=S(e.items,i,h),n=t.cols,r=Math.max(t.cell,Math.floor((h-s*(n-1))/n)),a=p+Math.max(0,Math.floor((h-r*n-s*(n-1))/2));return e.items.forEach((e,t)=>d.itemNodes.push({...e,x:a+t%n*(r+s),y:m+Math.floor(t/n)*44,w:r,h:c})),d.h=Math.max(u,g+t.height),d}let _=e.children||[];if(!_.length)return d.h=Math.max(u,g),d;let v=e.kind!==`col`,y=_.map(e=>E(e,i,a)),b=D(e,_,a,i),x=y.map(e=>v?e.w:e.h),C=_.some(e=>e.explicit);if(v&&!C){let e=new Map;_.forEach((t,n)=>{t.kind===`box`&&!t.children.length&&t.items?.length&&(e.has(t.items.length)||e.set(t.items.length,[]),e.get(t.items.length).push(n))});for(let t of e.values()){if(t.length<2)continue;let e=Math.max(...t.map(e=>x[e]));for(let n of t)x[n]=e}}let w=e=>e.kind===`box`&&!e.children.length&&!e.items?.length,T=_.map((e,t)=>C?e.explicit?e.weight:1:w(e)?0:Math.max(72,x[t]));T.every(e=>e===0)&&T.fill(1);let O=b.reduce((e,t)=>e+t,0),k=v?j(x,T,Math.max(h-O,x.reduce((e,t)=>e+t,0))):x,M=_.map((e,t)=>({child:e,w:v?k[t]:h,x:v?p+k.slice(0,t).reduce((e,t)=>e+t,0)+b.slice(0,t).reduce((e,t)=>e+t,0):p}));if(v){let e=M.map(e=>A(e.child,e.x,m,e.w,i,a)),t=Math.max(u-g,...e.map(e=>e.h));return d.children=e.map((e,n)=>e.h===t?e:A(_[n],M[n].x,m,M[n].w,i,a,t)),d.h=g+t,d}let N=_.map(e=>A(e,p,m,h,i,a).h),P=Math.max(0,u-g-N.reduce((e,t)=>e+t,0)-b.reduce((e,t)=>e+t,0)),F=Math.floor(P/_.length),I=m;return _.forEach((e,t)=>{let n=F+(t===_.length-1?P-F*_.length:0),r=A(e,p,I,h,i,a,N[t]+n);d.children.push(r),I+=r.h+(b[t]||0)}),d.h=Math.max(u,g+I-m),d}function j(e,t,n){let r=e.reduce((e,t)=>e+t,0),i=Math.max(0,n-r),a=t.reduce((e,t)=>e+t,0),o=e.map((e,n)=>e+Math.floor(i*t[n]/a)),s=t.map((e,t)=>e>0?t:-1).filter(e=>e>=0),c=n-o.reduce((e,t)=>e+t,0);for(let e=0;c>0;e+=1,--c)o[s[e%s.length]]+=1;return o}function M(e,t,n){e.kind===`box`&&t.push(e);for(let t of e.itemNodes||[])n.push({...t,parent:e});for(let r of e.children||[])M(r,t,n)}function N(e,t){return e.x<=t.x+.5&&e.y<=t.y+.5&&e.x+e.w+.5>=t.x+t.w&&e.y+e.h+.5>=t.y+t.h}function P(e,t){return e.w>0&&e.h>0&&t.w>0&&t.h>0&&e.x<t.x+t.w-.5&&t.x<e.x+e.w-.5&&e.y<t.y+t.h-.5&&t.y<e.y+e.h-.5}function F(e,n,i=[],a=t.fallbackMeasure){let o=n.find(t=>t.title===e.from),s=n.find(t=>t.title===e.to);if(!o||!s||o===s)return null;let c=[];o.x+o.w<=s.x+.5&&c.push({dir:`right`,gap:{x:o.x+o.w,y:Math.max(o.y,s.y),w:s.x-(o.x+o.w),h:Math.min(o.y+o.h,s.y+s.h)-Math.max(o.y,s.y)}}),s.x+s.w<=o.x+.5&&c.push({dir:`left`,gap:{x:s.x+s.w,y:Math.max(o.y,s.y),w:o.x-(s.x+s.w),h:Math.min(o.y+o.h,s.y+s.h)-Math.max(o.y,s.y)}}),o.y+o.h<=s.y+.5&&c.push({dir:`down`,gap:{x:Math.max(o.x,s.x),y:o.y+o.h,w:Math.min(o.x+o.w,s.x+s.w)-Math.max(o.x,s.x),h:s.y-(o.y+o.h)}}),s.y+s.h<=o.y+.5&&c.push({dir:`up`,gap:{x:Math.max(o.x,s.x),y:s.y+s.h,w:Math.min(o.x+o.w,s.x+s.w)-Math.max(o.x,s.x),h:o.y-(s.y+s.h)}});let l=c.filter(e=>e.gap.w>=24&&e.gap.h>=24).map(t=>({...t,lane:L(t,n,i,o,s,e.label,a)})).filter(e=>e.lane);if(!l.length)return null;l.sort((e,t)=>I(t.lane)-I(e.lane));let{dir:u,lane:d}=l[0],f=d.x+d.w/2,p=d.y+d.h/2,m=u===`right`||u===`left`,h=m?u===`right`?`M${d.x+4} ${p} H${d.x+d.w-4}`:`M${d.x+d.w-4} ${p} H${d.x+4}`:u===`down`?`M${f} ${d.y+4} V${d.y+d.h-4}`:`M${f} ${d.y+d.h-4} V${d.y+4}`,g=T(e.label||``,a),_=Math.max(24,(m?l[0].gap.w:d.w)-8),v=e.label&&g.w>_?(0,t.wrapText)(e.label,Math.max(24,_-12),t.FONT.label,a).slice(0,r.labelLines):g.lines,y=v.length?(0,t.snap)((0,t.maxWidthOf)(v,t.FONT.label,a)+12):0,b=v.length?Math.max(18,v.length*16+2):0;return{...e,dir:u,gap:d,path:h,labelLines:v,labelX:f,labelY:p,labelBox:{x:f-y/2,y:p-b/2,w:y,h:b}}}function I(e){return e.w*e.h}function L(e,n,r,i,a,o,s){let{dir:c,gap:l}=e,u=c===`right`||c===`left`,d=u?l.h:l.w,f=u?l.w:l.h;if(f<24||d<24)return null;let p=f-8,m=Math.min(Math.max(64,s(o,t.FONT.label)+20),Math.max(24,d-12));if(p<20||m<20)return null;let h=u?{x:l.x+(l.w-p)/2,y:l.y+(l.h-m)/2,w:p,h:m}:{x:l.x+(l.w-m)/2,y:l.y+(l.h-p)/2,w:m,h:p},g=n.some(e=>e!==i&&e!==a&&P(e,h)&&!(N(e,i)&&N(e,a))),_=r.some(e=>P(e,h));return g||_?null:h}function R(e,i){let a=i.design,o=(0,t.appearance)(i),s=e=>i.frameTone(i.color(`tone${e%6+1}`)),c=[i.el(`defs`,{},[z(`blocks-arrow`,i,!1),z(`blocks-arrow-async`,i,!0)])];for(let n of e.frames){let e=s(n.line),l=i.tint(a.bg,e,.07),u=i.tint(a.bg,e,.45),d=n.flag===`db`?B(n,i,l,u):i.rect(n.x,n.y,n.w,n.h,{rx:o.radius,fill:l,stroke:u,"stroke-width":1,...n.flag===`ext`?{"stroke-dasharray":`5 4`}:{}}),f=(0,t.wrapText)(n.title,Math.max(48,n.w-24),t.FONT.title,(e,t)=>i.measure(e,t.size,t.weight)).slice(0,r.titleLines),p=n.itemNodes?.length||n.children?.length?n.y+20:n.y+n.h/2,m=[d,...f.map((e,r)=>i.text(n.x+n.w/2,p+(r-(f.length-1)/2)*18,e,{anchor:`middle`,size:t.FONT.title.size,weight:t.FONT.title.weight,fill:i.color(`fg`),"dominant-baseline":`central`}))];c.push({...i.el(`g`,{},m),meta:{kind:`container`,name:n.title,...n.flag?{flag:n.flag}:{}}})}for(let r of e.nodes){let e=r.tone?a[r.tone]:s(r.parent?.line||1),l=[i.rect(r.x,r.y,r.w,r.h,{rx:o.smallRadius,fill:o.node,stroke:(r.tone?i.mix:i.tint)(a.bg,e,.4),"stroke-width":1})];if(r.icon){let e=(0,n.geometry)(r.icon);for(let t of e?.elements||[])l.push(i.shape(t.tag,{...t.attrs,transform:`translate(${r.x+8} ${r.y+8}) scale(.8)`,fill:`none`,stroke:i.color(`muted`),"stroke-width":1.5}))}let u=r.x+r.w/2+(r.icon?12:0),d=r.y+r.h/2;if(r.mark&&r.tone){let n={x:u-i.measure(r.label,t.FONT.body.size,t.FONT.body.weight)/2,y:d,"text-anchor":`start`,"dominant-baseline":`central`,"font-size":t.FONT.body.size,"font-weight":t.FONT.body.weight,fill:i.color(`fg`)};l.push(i.el(`text`,n,[{...i.el(`tspan`,{fill:e}),text:r.mark},{...i.el(`tspan`),text:` ${r.name}`}]))}else l.push(i.text(u,d,r.label,{anchor:`middle`,size:t.FONT.body.size,fill:i.color(`fg`),"dominant-baseline":`central`}));c.push({...i.el(`g`,{},l),meta:{kind:`capability`,label:r.name,container:r.parent?.title,...r.mark?{mark:r.mark}:{}}})}for(let n of e.edges){let e={d:n.path,fill:`none`,stroke:i.color(`muted`),"stroke-width":2,"stroke-linecap":`round`,...n.async?{"stroke-dasharray":`5 4`}:{},"marker-end":`url(#${n.async?`blocks-arrow-async`:`blocks-arrow`})`},o=[i.path(n.path,e)];if(n.label){let e=n.labelLines||(0,t.wrapText)(n.label,160,t.FONT.label,(e,t)=>i.measure(e,t.size,t.weight)).slice(0,r.labelLines),{x:s,y:c,w:l,h:u}=n.labelBox;o.push(i.rect(s,c,l,u,{rx:4,fill:a.bg})),e.forEach((r,a)=>o.push(i.text(n.labelX,n.labelY+(a-(e.length-1)/2)*16,r,{anchor:`middle`,size:t.FONT.label.size,fill:i.color(`fg`),"dominant-baseline":`central`})))}c.push({...i.el(`g`,{},o),meta:{kind:`relation`,from:n.from,to:n.to,async:n.async}})}return{width:e.width,height:e.height,children:c}}function z(e,t,n){return t.el(`marker`,{id:e,viewBox:`0 0 10 10`,refX:8,refY:5,markerWidth:8,markerHeight:8,orient:`auto-start-reverse`},[t.path(`M1 1 L9 5 L1 9 Z`,{fill:t.color(`muted`),...n?{"stroke-dasharray":`5 4`}:{}})])}function B(e,t,n,r){let i=Math.min(7,Math.max(4,e.h/8)),a=e.x,o=e.y,s=e.w,c=e.h;return t.path(`M${a} ${o+i} A${s/2} ${i} 0 0 1 ${a+s} ${o+i} V${o+c-i} A${s/2} ${i} 0 0 1 ${a} ${o+c-i} Z M${a} ${o+i} A${s/2} ${i} 0 0 0 ${a+s} ${o+i}`,{fill:n,stroke:r,"stroke-width":1.5})}return e.implementations={blocks:{parse:p,layout:_,scene:R}},e})({},KChartUnits[`diagram/support`],KChartUnits[`core/icons`]);
|
|
1
|
+
KChartUnits["diagram/blocks"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a={depth:8,endpoints:400,items:1e3,edges:200,labelChars:24,desc:8},o=16,s=12,c=r.ITEM.gap,l=16,u=/^(row|col|grid|box|card|note|legend)(?:\s+(.*))?$/,d=[...r.STYLES,`default`,`db`,...Object.keys(r.EDGE_KINDS)],f=/\{((?:"[^"\n]*"|[^{}"]|"(?=[^"\n]*\}$))*)\}$/,p=/^[A-Za-z_][A-Za-z0-9_-]*$/,m=/[::]|->|=>|~>/,h=e=>[...e].length;function g(e,t,n){let i=e.match(f),a=(i?e.slice(0,i.index):e).trim(),o={},s=`${r.STYLES.join(`, `)}, ${t===`box`?`db, `:`"tag", `}#XX, @id`,c=e=>n(`未知属性或属性位置无效:${e}`,`Unknown or misplaced attribute: ${e}`,`在标题末尾用 {...},仅使用:${s}`,`Use {...} after the title with only: ${s}`);/[{}]/.test(a)&&c(a);for(let e of i?.[1].match(/(?:"[^"]*"|[^,\s"]+)+|"/g)||[])if(r.STYLES.includes(e))o.style?n(`只能使用一种样式`,`Only one style is allowed`,`保留一个样式词`,`Keep one style word`):o.style=e;else if(e===`db`&&t===`box`&&!o.db)o.db=!0;else if(e.startsWith(`#`))o.badge||!/^#[0-9A-Za-z.-]{1,4}$/.test(e)?n(`徽章无效或重复`,`Invalid or repeated badge`,`只写一个 # 加 1–4 个字母、数字、点或连字符`,`Use one # followed by 1–4 letters, digits, dots or hyphens`):o.badge=e.slice(1);else if(e.startsWith(`@`))o.ref||!p.test(e.slice(1))?n(`引用 ID 无效或重复`,`Invalid or repeated reference ID`,`只写一个 @id,以字母或下划线开头,后接字母、数字、下划线或连字符`,`Use one @id starting with a letter or underscore, followed by letters, digits, underscores or hyphens`):o.ref=e.slice(1);else if(e.startsWith(`"`)&&t===`card`){let t=e.slice(1,-1);o.tag||!/^"[^"\n]+"$/.test(e)||!t.trim()||h(t)>12?n(`标签无效、重复或过长`,`Invalid, repeated or overlong tag`,`只写一个双引号标签,最多 12 个字符`,`Use one double-quoted tag of at most 12 characters`):o.tag=t}else c(e);return{title:a,...o}}function _(e,{lang:i,options:o={},firstLine:s=2}){let c=[],l=[],f=[],p=[],_=[],v=[],y=[],b=new Map,x=new Map,S=new Set,C=e=>(n,r,a,o)=>c.push((0,t.error)(i,e,n,r,a,o)),w=(e,t,n)=>e(t,n,`拆成两张图`,`Split into two diagrams`);for(let e of Object.keys(o))C(s-1)(`blocks 不支持选项「${e}」`,`Unsupported blocks option: ${e}`,`删除这个选项`,`Remove this option`);for(let[t,i]of String(e).split(`
|
|
2
|
+
`).entries()){if(!i.trim()||i.trimStart().startsWith(`%%`))continue;let e=s+t,o=C(e);if(/^ *\t/.test(i)){o(`缩进不能使用 Tab`,`Tabs are not allowed in indentation`,`把 Tab 换成空格`,`Replace tabs with spaces`);continue}let c=i.match(/^ */)[0].length,m=i.trim();for(;p.length&&c<=p.at(-1).indent;)p.pop();let T=p.at(-1);if(T?.kind===`card`){T.desc.push(m),T.desc.length===a.desc+1&&o(`卡片描述最多 8 行`,`At most 8 card description lines`,`合并描述行或拆成两张卡片`,`Combine description lines or split into two cards`);continue}if(T?.kind===`legend`){let e=m.match(/^([^::]+)[::]\s*(.+)$/),t=e?.[1].trim();!e||!d.includes(t)?o(`图例键无效或缺少说明`,`Unknown legend key or missing meaning`,`使用「键: 说明」;键为 ${d.join(`, `)}`,`Use "key: meaning" with one of ${d.join(`, `)}`):T.entries.some(e=>e.key===t)?o(`图例键「${t}」重复`,`Repeated legend key: ${t}`,`合并同一个键的说明`,`Combine the meanings for this key`):T.entries.push({key:t,label:e[2]});continue}let E=m.match(u);T?.kind===`box`&&E&&(/^(card|note)$/.test(m)||E[1]===`legend`&&E[2])&&(E=null);let D=m.match(/^(.+?)\s*(->|=>|~>)\s*(.+?)(?:\s*[::]\s*(.*))?$/);if(D&&!E&&(!T||T.kind!==`box`||T.inline)){c&&o(`关系必须写在顶格`,`Relations must start at column 0`,`去掉这一行的缩进`,`Remove the indentation from this relation`);let t=(D[4]||``).trim();h(t)>a.labelChars&&o(`关系标签过长`,`Relation label is too long`,`把标签缩到 24 个字符以内`,`Keep the label within 24 characters`),f.push({id:`edge-${f.length}`,ends:[D[1].trim(),D[3].trim()],kind:r.EDGE_KINDS[D[2]],label:t,line:e}),f.length===a.edges+1&&w(o,`关系最多 200 条`,`At most 200 relations`);continue}if(T?.kind===`note`){o(`note 不能有子条目`,`Notes cannot have children`,`将这一行退回到与 note 同级`,`Move this line to the same indentation as the note`);continue}let O=(t,r)=>{t.children.length&&o(`box 不能混用能力项和结构行`,`A box cannot mix capabilities and structure lines`,`将能力项移到单独的 box`,`Move capabilities to their own box`);for(let i of r.split(/[,,]/)){let r=i.trim(),s=r.match(/^\[icon:([a-z0-9][\w.-]*)\]\s*/i),c=s?r.slice(s[0].length):r,l=c.match(/^([+~=])\s*/)?.[1]||``,u=c.replace(/^[+~=]\s*/,``).trim();if(!u){o(`能力项名称不能为空`,`Capability labels cannot be empty`,`删除空项或补上名称`,`Remove the empty item or add a label`);continue}(s?!(0,n.has)(s[1]):/\[icon:/.test(r))&&o(`未知图标或图标写法无效`,`Unknown icon or invalid icon syntax`,`写成 [icon:database] 名称`,`Use a valid icon, e.g. [icon:database] name`);let d={name:u,label:l?`${l} ${u}`:u,mark:l,tone:{"+":`new`,"~":`info`,"=":`ok`}[l],icon:s?.[1],line:e};t.items.push(d),y.push(d),S.add(u),S.add(d.label),y.length===a.items+1&&w(o,`能力项最多 1000 个`,`At most 1000 capabilities`)}};if(!E&&T?.kind===`box`&&!T.inline){O(T,m);continue}if(!E){T?o(`能力项只能写在 box 内`,`Capabilities belong inside a box`,`把这一行改成 box,或移入 box`,`Change this line into a box or move it inside a box`):o(`无法识别这一行`,`Unrecognized line`,`使用结构关键字,或写成「A -> B」`,`Use a structure keyword or write a relation as "A -> B"`);continue}let k=p.length;if(k>=a.depth){w(o,`嵌套超过 8 层`,`Nesting exceeds 8 levels`);continue}if(_[k]??=c,_[k]!==c){o(`同级条目的缩进不一致`,`Inconsistent indentation at the same level`,`把这一行缩进改为 ${_[k]} 个空格`,`Indent this line with ${_[k]} spaces`);continue}let A=E[1],j=E[2]||``,M={kind:A,line:e,indent:c,parent:T,weight:1,children:[],items:[]};if(T?.items.length&&o(`box 不能混用能力项和结构行`,`A box cannot mix capabilities and structure lines`,`将子结构移到单独的 box`,`Move the child structures to a separate box`),A===`row`||A===`col`||A===`box`){let e=j.match(A===`box`?/^(\d+(?:\.\d+)?)\s+(?![::\s])/:/^\d+(?:\.\d+)?$/);if(e){let t=Number(e[0]);t>0&&Number.isFinite(t)?(M.weight=t,M.explicit=!0):A===`box`&&Number.isFinite(t)||o(`权重必须是有限正数`,`Weight must be finite and positive`,`使用较小的正数,例如 3`,`Use a small positive number such as 3`),j=j.slice(e[0].length)}else A!==`box`&&j&&o(`${A} 后面只能写权重`,`Only a weight may follow ${A}`,`删除多余文字,或写成正数`,`Remove the extra text or use a positive number`)}if(A===`box`||A===`card`){let e=A===`box`?j.match(/^(?:\{[^}]*\}|[^::\{])*([::])/)?.[0].length:null;Object.assign(M,g(e?j.slice(0,e-1).trim():j,A,o)),M.title||o(`标题不能为空`,`Title cannot be empty`,`在关键字后补上标题`,`Add a title after the keyword`),M.id=M.ref||`#${v.length+1}`,v.push(M),v.length===a.endpoints+1&&w(o,`容器和卡片合计最多 400 个`,`At most 400 boxes and cards combined`),M.ref&&(b.has(M.ref)?o(`引用 ID @${M.ref} 重复`,`Duplicate reference ID @${M.ref}`,`换一个未使用的 @id`,`Use a different, unused @id`):b.set(M.ref,M)),x.has(M.title)||x.set(M.title,[]),x.get(M.title).push(M),A===`card`?M.desc=[]:e&&j.slice(e).trim()&&(M.inline=!0,O(M,j.slice(e)))}else A===`grid`?(M.cols=Number(j),(!/^\d+$/.test(j)||M.cols<1||M.cols>12)&&o(`grid 列数必须在 1–12 之间`,`Grid column count must be between 1 and 12`,`写成 grid 1 到 grid 12`,`Use grid 1 through grid 12`)):A===`note`?(M.text=j,S.add(j),j||o(`note 缺少正文`,`Note text is missing`,`在 note 后写上正文`,`Add text after note`)):A===`legend`&&(M.entries=[],j&&o(`legend 说明必须缩进另写`,`Legend entries must be on indented lines`,`将说明移到下一行并缩进`,`Move the entry to its own indented line`));(T?T.children:l).push(M),p.push(M)}for(let e of f){let t=C(e.line);[e.from,e.to]=e.ends.map(e=>{let n=b.get(e.replace(/^@/,``));if(n)return n;let r=m.test(e)?null:x.get(e);return r?.length===1?r[0]:(S.has(e)&&!r?.length?t(`关系不能指向注释或能力项「${e}」`,`Relations cannot target a note or capability: ${e}`,`改为所属 box 或 card 的名称`,`Use the containing box or a card as the endpoint`):t(r?.length?`关系端点「${e}」不唯一`:`关系端点「${e}」不存在`,r?.length?`Ambiguous relation endpoint: ${e}`:`Unknown relation endpoint: ${e}`,`给目标加 {@id},并在关系中使用该 id`,`Add {@id} to the one you mean and use that id in the relation`),null)}),e.from&&e.from===e.to&&t(`关系不能指向自身`,`A relation cannot target itself`,`选择不同的端点或删除该关系`,`Choose a different endpoint or remove the relation`)}return l.length||C(s)(`图中没有结构`,`Diagram has no structure`,`添加 box 或 card`,`Add a box or card`),{model:{nodes:l,endpoints:v,edges:f,items:y},errors:c}}var v=e=>e.reduce((e,t)=>e+t,0),y=(e,t)=>{let n=e.findIndex((e,n)=>e!==t[n]);return n>=0&&e[n]<t[n]},b=(e,t)=>{let n=0;return e.map((e,r)=>{let i=n;return n+=e+(t[r]||0),i})};function x(e,t,n){let r=Math.max(0,n-v(e)),i=Math.max(...t)||1,a=t.map(e=>e/i),o=v(a),s=e.map((e,t)=>e+Math.floor(r*a[t]/o)),c=n-v(s);for(let e=0;c>=1;e=(e+1)%s.length)t[e]&&(s[e]++,c--);return s}function S(e,t,n){let r;for(let i=1;i<=e.length;i++){let a=Math.floor((n-c*(i-1))/i);if(a<t&&i>1)break;let o=Math.ceil(e.length/i),s=[+(a>260),o*i-e.length,Math.abs(i-o),o];(!r||y(s,r.score))&&(r={cols:i,rows:o,cw:Math.max(a,t),score:s})}return r}var C=e=>e?[...C(e.parent),e]:[],w=(e,t,n)=>{let r=e.children.indexOf(t);return e.kind===`grid`?n===`x`?r%e.cols:Math.floor(r/e.cols):e.kind===`col`==(n===`y`)?r:0};function T(e,t){let n=new Map,r=e=>(n.has(e)||n.set(e,{x:new Map,y:new Map,inner:[]}),n.get(e));for(let n of t){let t=C(n.from),i=C(n.to);e!==t[0]&&(t.unshift(e),i.unshift(e));let a=0;for(;t[a]&&t[a]===i[a];)a++;let o=t[a-1];if(t[a]&&i[a])for(let e of[`x`,`y`]){let s=w(o,t[a],e),c=w(o,i[a],e),l=r(o)[e];for(let e=Math.min(s,c);e<Math.max(s,c);e++)l.has(e)||l.set(e,[]),l.get(e).push(n)}else o.kind===`box`&&r(o).inner.push(n);for(let e of[...t.slice(a,-1),...i.slice(a,-1)])e.kind===`box`&&r(e).inner.push(n)}return n}function E(e,{width:n,lang:a,measure:u,compact:d}){let f=[],p=e.nodes.length===1?e.nodes[0]:{kind:`col`,children:e.nodes,items:[]},m=new Map,g=(e,n,r)=>f.push((0,t.error)(a,e.line,n,r,`缩短文字,把说明移到图注`,`Shorten the text and move details to the caption`));for(let t of e.endpoints){let e=t.kind===`card`?(0,r.measureCard)(t,u):(0,r.frameTitle)(t,u);(t.kind===`card`?e.titleLines.length>2:e.lines.length>3)&&g(t,t.kind===`card`?`卡片标题最多换行成 2 行`:`容器标题最多换行成 3 行`,t.kind===`card`?`Card titles may wrap to at most 2 lines`:`Box titles may wrap to at most 3 lines`),m.set(t,e)}for(let n of e.items)(h(n.name)>24||u(n.name,t.FONT.body)>312)&&g(n,`能力项「${n.label}」过长`,`Capability label is too long: ${n.label}`);let _=e.edges.map(e=>{let t=(0,r.measureLabel)(e.label,u);return t?.lines.length>2&&g(e,`关系标签最多换行成 2 行`,`Relation labels may wrap to at most 2 lines`),{...e,label:t}});if(f.length)return{width:n,height:0,errors:f};let y=T(p,_),C,w,E;for(let e=0;e<(_.length?3:1);e++){let t=new Map,a=(t,n,r)=>Array.from({length:r-1},(r,i)=>{let a=y.get(t)?.[n].get(i)||[];return a.length?Math.max(28,16+12*a.length,...a.map(e=>e.label?24+(n===`x`?e.label.w:e.label.h):0))+e*16:o});function O(n){let{kind:i,children:o,items:c}=n,l=m.get(n),d;if(i===`card`)d={w:l.w};else if(i===`note`)d={w:Math.max(24,(0,r.measureNote)(n.text,u).w)};else if(i===`legend`)d={w:Math.max(52,(0,r.measureLegend)(n.entries,u,240).w)};else{let t=i===`grid`,f=i===`col`,p=t?n.cols:f?1:Math.max(1,o.length),m=f?Math.max(1,o.length):Math.max(1,Math.ceil(o.length/p)),h=a(n,`x`,p),g=a(n,`y`,m),_=Array(p).fill(0);o.forEach((e,t)=>{let n=t%p;_[n]=Math.max(_[n],O(e).w)});let b=e=>e.kind===`box`&&!e.children.length&&!e.items.length,x=o.some(e=>e.explicit);if(t)_.fill(Math.max(24,..._));else if(!f&&!x){let e=new Map;o.forEach((t,n)=>{t.items.length&&e.set(t.items.length,Math.max(e.get(t.items.length)||0,_[n]))}),o.forEach((t,n)=>{t.items.length&&(_[n]=e.get(t.items.length))})}let S=t||f?_.map(()=>1):o.map((e,t)=>x?e.weight:b(e)?0:Math.max(72,_[t]));S.every(e=>!e)&&S.fill(1);let C=y.get(n)?.inner.length||0,w=i===`box`?Math.max(s,C?16+Math.min(C,4)*6+e*12:0):0,T=i===`box`?Math.max(36,l.band)+w-s:0,E=c.length?Math.max(...c.map(e=>(0,r.measureItem)(e,u))):0;d={w:Math.max(i===`box`?48:72,l?.minW||0,2*w+Math.max(E,v(_)+v(h))),pad:w,top:T,cell:E,columns:p,gx:h,gy:g,mins:_,weights:S}}return t.set(n,d),d}let f=l+e*16,h=O(p).w+f*2;E??=h;let g=d?h:Math.max(Math.floor(n),h);function k(e,n){let i=t.get(e),{kind:a}=e;if(a===`card`||a===`note`||a===`legend`){let t=a===`card`?m.get(e):a===`note`?(0,r.measureNote)(e.text,u,n):(0,r.measureLegend)(e.entries,u,n);return{node:e,w:n,h:t.h,paint:t,plan:i}}let{pad:o,top:s,columns:l,mins:d,weights:f,gx:p,gy:h,cell:g}=i,_=n-2*o;if(e.items.length){let t=S(e.items,g,_);return{node:e,w:n,h:s+t.rows*r.ITEM.h+(t.rows-1)*c+o,grid:t,plan:i}}let y=e.children.length?a===`grid`?d.map(()=>Math.floor((_-v(p))/l)):x(d,f,_-v(p)):[],b=e.children.map((e,t)=>k(e,y[t%l])),C=Array(h.length+1).fill(0);return b.forEach((e,t)=>{let n=Math.floor(t/l);C[n]=Math.max(C[n],e.h)}),{node:e,w:n,h:Math.max(a===`box`?48:0,s+v(C)+v(h)+o),cols:y,rows:C,children:b,plan:i}}let T=[],j=[],M=[],N=[],P=[];function A(e,t,n,i,a){let{node:o,w:s,plan:l,paint:u,grid:d,children:f,cols:p,rows:h}=e,{kind:g,id:_,style:y,db:S,badge:C,tag:w}=o,E={x:t,y:n,w:s,h:i};if(g===`card`){j.push({...u,...E,id:_,style:y,badge:C,tag:w,parent:a?.id});return}if(g===`note`||g===`legend`){(g===`note`?M:N).push({...E,...u});return}if(g===`box`){let e=m.get(o),t={...E,id:_,name:o.title,style:y,db:S,badge:C,title:e,parent:a?.id};t.titleRect=(0,r.titleRect)(t,e),T.push(t),a=t}let{pad:D,top:O,gx:k,gy:F,columns:I}=l;if(d){let e=t+Math.floor((s-d.cw*d.cols-c*(d.cols-1))/2);o.items.forEach((t,i)=>P.push({...t,parent:a,id:`${_}/item-${i}`,x:e+i%d.cols*(d.cw+c),y:n+O+Math.floor(i/d.cols)*(r.ITEM.h+c),w:d.cw,h:r.ITEM.h}))}else if(f.length){let e=x(h,h.map(()=>1),i-O-D-v(F)),r=b(p,k),o=b(e,F),s=new Set(f.filter(e=>e.node.kind!==`card`).map(e=>Math.floor(f.indexOf(e)/I)));f.forEach((i,c)=>{let l=c%I,u=Math.floor(c/I),d=g!==`col`&&i.node.kind===`card`&&s.has(u);A(i,t+D+r[l],n+O+o[u]+(d?(e[u]-i.h)/2:0),d?i.h:e[u],a)})}}let F=k(p,g-2*f);if(A(F,f,f,F.h,void 0),C={width:g,height:F.h+2*f,frames:T,cards:j,notes:M,legends:N,nodes:P},w=(0,i.routeBoard)({...C,nodes:[...j,...P.map(e=>({...e,parent:e.parent.id}))],blockers:[...M,...N],edges:_.map(e=>({id:e.id,from:e.from.id,to:e.to.id,label:e.label}))}),!w.failed.length&&w.edges.every(e=>!e.labelRect||D(e.labelRect,C)))break}let j=new Map(w.edges.map(e=>[e.id,e])),M=[];for(let e of _){let n=j.get(e.id);!n||e.label&&!D(n.labelRect,C)?f.push((0,t.error)(a,e.line,`关系「${e.ends.join(` → `)}」没有可用通道`,`No clear route for "${e.ends.join(` → `)}"`,`减少共享同一通道的关系,或调整 row、col、grid 的组合`,`Reduce relations sharing the corridor or adjust the row, col or grid composition`)):M.push({...n,from:e.from.id,to:e.to.id,kind:e.kind,labelLines:e.label?.lines})}return(e.endpoints.length>60||E>n*2)&&f.push((0,t.warning)(`LARGE_DIAGRAM`,a,e.nodes[0].line,`图较大,可滚动查看`,`Large board; scroll to view it`,`可拆成总图和分图`,`Consider splitting into an overview and detail boards`)),{...C,edges:M,errors:f}}function D(e,{width:t,height:n}){return e&&e.x>=0&&e.y>=0&&e.x+e.w<=t&&e.y+e.h<=n}function O(e,t){let i=[...e.cards,...e.frames].map(e=>e.style).concat(e.nodes.map(e=>e.tone),e.legends.flatMap(e=>e.rows.flat().map(e=>e.key))),a=(0,r.boardLook)(t,i),o=(0,r.markers)(t),s=({x:t,y:n,w:i=2,h:o=2})=>(0,r.surfaceAt)(e.frames,a,t+i/2,n+o/2),c=e.nodes.map(e=>({...(0,r.drawItem)(t,{...e,icon:e.icon?(0,n.geometry)(e.icon):null,under:s(e)},a),meta:{kind:`capability`,label:e.name,container:e.parent.name,...e.mark?{mark:e.mark}:{}}})),l=[],u=[];for(let n of e.edges){let i=a.edge(n.kind);if(l.push((0,r.drawEdge)(t,n,i,{end:o.url(`arrow`,i.stroke)})),n.labelLines){let i=n.labelRect;u.push((0,r.drawLabel)(t,{from:n.from,to:n.to,rect:i,lines:n.labelLines,plate:(0,r.surfaceAt)(e.frames,a,i.x+i.w/2,i.y+i.h/2)},a))}}let d=e.legends.map(e=>(0,r.drawLegend)(t,e,a,o,s({x:e.x,y:e.y})));return{width:e.width,height:e.height,children:[...o.defs(),...e.frames.map(e=>(0,r.drawFrame)(t,e,a)),...c,...e.cards.map(e=>(0,r.drawCard)(t,{...e,under:s(e)},a)),...e.notes.map(e=>(0,r.drawNote)(t,e,a)),...d,...l,...u]}}return e.implementations={blocks:{parse:_,layout:E,scene:O}},e})({},KChartUnits[`diagram/support`],KChartUnits[`core/icons`],KChartUnits[`diagram/board-paint`],KChartUnits[`diagram/board-route`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/board-paint"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.freeze([`accent`,`new`,`info`,`ok`,`warn`,`danger`,`ext`]),i=new Set([`new`,`info`,`ok`,`warn`,`danger`]),a=Object.freeze({padX:14,padY:12,text:240,min:112,title:20,desc:18,gap:4}),o=Object.freeze({h:18,padX:6,gap:8,font:Object.freeze({size:12,weight:600})}),s=Object.freeze({inset:12,top:10,line:17,after:8,text:360,cylinder:7,font:Object.freeze({size:13,weight:600})}),c=Object.freeze({line:18,font:n.FONT.label}),l=Object.freeze({swatch:22,gap:6,item:18,row:22,font:n.FONT.label}),u=Object.freeze({text:160,line:16,padX:6,padY:2,font:n.FONT.label}),d=Object.freeze({h:36,padX:12,min:72,gap:8,font:n.FONT.body}),f=Object.freeze({"->":`plain`,"=>":`strong`,"~>":`dashed`}),p=Object.freeze({size:16,gap:6}),m=`5 4`,h=.07,g=.72,_=12,v=4.5,y=e=>+Number(e).toFixed(2),b=(e,t)=>e?Math.ceil(t(String(e),o.font)+o.padX*2):0;function x({title:e,desc:t=[],badge:r,tag:i},s){let c=b(r,s),l=b(i,s),u=c?c+o.gap:0,d=l?l+o.gap:0,f=(0,n.wrapText)(String(e??``),Math.max(48,a.text-u-d),n.FONT.title,s),p=t.flatMap(e=>(0,n.wrapText)(String(e),a.text,n.FONT.label,s)),m=Math.max(u+(0,n.maxWidthOf)(f,n.FONT.title,s)+d,(0,n.maxWidthOf)(p,n.FONT.label,s));return{w:Math.max(a.min,Math.ceil(m+a.padX*2)),h:a.padY*2+f.length*a.title+(p.length?a.gap+p.length*a.desc:0),titleLines:f,descLines:p,badgeW:c,tagW:l}}function S({label:e,icon:t},n){return Math.max(d.min,Math.ceil(n(String(e),d.font)+(t?p.size+p.gap:0)+d.padX*2))}function C({title:e=``,badge:t,icon:r,db:i=!1},a){let c=b(t,a),l=(c?c+o.gap:0)+(r?p.size+p.gap:0),u=String(e).trim()?(0,n.wrapText)(String(e),s.text-l,s.font,a):[],d=Math.max(u.length,t||r?1:0),f=d?Math.ceil(l+(0,n.maxWidthOf)(u,s.font,a)):0,m=s.top+(i?s.cylinder:0);return{lines:u,badgeW:c,w:f,top:m,rows:d,band:d?m+d*s.line+s.after:0,minW:d?f+s.inset*2:0}}function w(e,t){return t?.rows?{x:e.x+s.inset-2,y:e.y+t.top-2,w:t.w+4,h:t.rows*s.line+4}:null}function T(e,t,r=a.text){let i=(0,n.wrapText)(String(e??``),Math.max(24,r),c.font,t);return{lines:i,w:Math.ceil((0,n.maxWidthOf)(i,c.font,t)),h:i.length*c.line}}function E(e,t,r){let i=String(e??``).trim()?(0,n.wrapText)(String(e),u.text,u.font,t):[];if(!i.length&&!r)return null;let a=r?p.size+(i.length?p.gap:0):0;return{lines:i,w:Math.ceil(a+(0,n.maxWidthOf)(i,u.font,t))+u.padX*2,h:Math.max(i.length*u.line,r?p.size:0)+u.padY*2}}function D(e,t,r=1/0){let i=[],a=[],o=0,s=0;for(let c of e){let e=(0,n.wrapText)(String(c.label),Math.max(24,Math.min(r,480)-l.swatch-l.gap),l.font,t),u=Math.ceil(l.swatch+l.gap+(0,n.maxWidthOf)(e,l.font,t));a.length&&o+l.item+u>r&&(i.push(a),a=[],o=0);let d=a.length?o+l.item:0;a.push({...c,lines:e,x:d,w:u}),o=d+u,s=Math.max(s,o)}a.length&&i.push(a);let c=i.map(e=>Math.max(...e.map(e=>e.lines.length))*l.row);return{rows:i,heights:c,w:s,h:c.reduce((e,t)=>e+t,0)+Math.max(0,i.length-1)*6}}function O(e,r=[]){let a=e.design,o=(0,n.appearance)(e),s=a.bg,c=t=>e.tint(s,t,g),l=e.frameTone(e.color(`accent`),!0),u=r.includes(`accent`)&&r.some(e=>i.has(e)&&(0,t.deltaE2000)(c(l),c(a[e]))<_)?a.fg1:l,d=e=>e===`accent`?u:i.has(e)?a[e]:null,f=(e,n)=>(0,t.contrast)(e,n)>=v?e:(0,t.pushContrast)(e,a.fg1,n,v),p=e.tint(s,e.color(`muted`),.62),y=o.node===a.surface2?a.surface:a.surface2,b=t=>e.tint(t,a.fg3,h),x=t=>{let n=e.tint(s,t,.14);return{fill:n,color:f(t,n)}};return{bg:s,radius:Math.min(o.radius,10),smallRadius:Math.min(o.smallRadius,8),fg:a.fg1,muted:a.fg3,line:p,tag:{fill:o.node,stroke:a.line2,color:f(a.fg3,o.node)},item(t,n=a.surface){let r=i.has(t)?a[t]:null;return r?{fill:o.node,stroke:e.mix(s,r,.4),mark:f(r,o.node)}:{fill:b(n),stroke:null,mark:a.fg1}},card(e,t=a.surface){if(e===`ext`)return{fill:y,stroke:p,dash:m,desc:f(a.fg3,y),badge:x(u)};let n=d(e);if(!n){let e=b(t);return{fill:e,stroke:null,dash:null,desc:f(a.fg3,e),badge:x(u)}}return{fill:o.node,stroke:c(n),dash:null,desc:f(a.fg3,o.node),badge:x(n)}},frame(t){let n=t===`ext`?null:d(t),r=t===`ext`?a.surface2:a.surface;return{fill:r,stroke:n?e.tint(s,n,.55):a.line2,title:f(n||a.fg3,r),badge:x(n||u)}},edge(t=`plain`,n){return{stroke:i.has(n)?a[n]:t===`strong`?u:e.color(`muted`),width:t===`strong`?1.75:1.25,dash:t===`dashed`?m:null}}}}function k(e,t,n,r,i,{fill:a,stroke:s,color:c}){return e.el(`g`,{},[e.rect(t,n-o.h/2,r,o.h,{rx:o.h/2,fill:a,...s?{stroke:s,"stroke-width":1}:{}}),e.text(t+r/2,n,i,{anchor:`middle`,size:o.font.size,weight:o.font.weight,fill:c,"dominant-baseline":`central`})])}function A(e,t,n,r,i,a=p.size){let[o,s,c,l]=t.viewBox.split(/\s+/).map(Number),u=a/Math.max(c,l),d=t.set===`tabler`;return e.el(`g`,{transform:`translate(${y(n+(a-c*u)/2)} ${y(r-l*u/2)}) scale(${y(u)}) translate(${-o} ${-s})`,fill:d?`none`:i,stroke:d?i:`none`,"stroke-width":1.8,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function j({x:e,y:t,w:n,h:r}){let i=s.cylinder;return`M${e} ${t+i} A${n/2} ${i} 0 0 1 ${e+n} ${t+i} V${t+r-i} A${n/2} ${i} 0 0 1 ${e} ${t+r-i} Z M${e} ${t+i} A${n/2} ${i} 0 0 0 ${e+n} ${t+i}`}function M(e,t,n){let{id:r,x:i,y:a,w:c,h:l,style:u,db:d,badge:f,icon:h,title:g}=t,_=n.frame(u),v=[d?e.path(j(t),{fill:_.fill,stroke:_.stroke,"stroke-width":1}):e.rect(i,a,c,l,{rx:n.radius,fill:_.fill,stroke:_.stroke,"stroke-width":1,"stroke-dasharray":m})];if(g?.rows){let t=i+s.inset,n=a+g.top+s.line/2;f&&(v.push(k(e,t,n,g.badgeW,f,_.badge)),t+=g.badgeW+o.gap),h&&(v.push(A(e,h,t,n,_.title)),t+=p.size+p.gap),g.lines.forEach((i,a)=>v.push(e.text(t,n+a*s.line,i,{size:s.font.size,weight:s.font.weight,fill:_.title,"dominant-baseline":`central`,meta:{kind:`frame-title`,id:r}})))}return{...e.el(`g`,{},v),meta:{kind:`frame`,id:r,...u?{style:u}:{}}}}var N=(e,t)=>e.stroke?{stroke:e.stroke,"stroke-width":t,...e.dash?{"stroke-dasharray":e.dash}:{}}:{};function P(e,t,r){let{id:i,x:s,y:c,w:l,h:u,style:d,badge:f,tag:p,titleLines:m,descLines:h,badgeW:g,tagW:_,under:v}=t,y=r.card(d,v),b=[e.rect(s,c,l,u,{rx:r.radius,fill:y.fill,...N(y,1.25)})],x=s+a.padX,S=c+a.padY+a.title/2;f&&(b.push(k(e,x,S,g,f,y.badge)),x+=g+o.gap),m.forEach((t,i)=>b.push(e.text(x,S+i*a.title,t,{size:n.FONT.title.size,weight:n.FONT.title.weight,fill:r.fg,"dominant-baseline":`central`}))),p&&b.push(k(e,s+l-a.padX-_,S,_,p,r.tag));let C=c+a.padY+m.length*a.title+a.gap+a.desc/2;return h.forEach((t,r)=>b.push(e.text(s+a.padX,C+r*a.desc,t,{size:n.FONT.label.size,weight:n.FONT.label.weight,fill:y.desc,"dominant-baseline":`central`}))),{...e.el(`g`,{},b),meta:{kind:`node`,id:i,...d?{style:d}:{}}}}function F(e,t,n){let{x:r,y:i,w:a,h:o,label:s,name:c,mark:l,tone:u,icon:f,under:m}=t,h=n.item(u,m),g=f?p.size+p.gap:0,_=r+(a-g-e.measure(s,d.font.size,d.font.weight))/2,v=i+o/2,y=[e.rect(r,i,a,o,{rx:n.smallRadius,fill:h.fill,...N(h,1)})];f&&y.push(A(e,f,_,v,n.muted));let b={size:d.font.size,weight:d.font.weight,fill:n.fg,"dominant-baseline":`central`},x=e.font(b.size,b.weight);return y.push(l?e.el(`text`,{x:_+g,y:v,"text-anchor":`start`,"dominant-baseline":`central`,"font-size":x.size,"font-weight":x.weight,fill:n.fg},[{...e.el(`tspan`,{fill:h.mark}),text:l},{...e.el(`tspan`),text:` ${c}`}]):e.text(_+g,v,s,b)),e.el(`g`,{},y)}function I(e,t,n){return{...e.el(`g`,{},t.lines.map((r,i)=>e.text(t.x,t.y+(i+.5)*c.line,r,{size:c.font.size,weight:c.font.weight,fill:n.muted,"dominant-baseline":`central`}))),meta:{kind:`note`}}}function L(e){let t=new Map;return{url(n,r){let i=`board-${n}-${String(r).replace(/[^\da-z]/gi,``)}`;if(!t.has(i)){let a=n===`circle`?e.el(`circle`,{cx:5,cy:5,r:4,fill:e.design.bg,stroke:r}):n===`cross`?e.path(`M1 1 L9 9 M9 1 L1 9`,{fill:`none`,stroke:r,"stroke-width":1.8}):e.path(`M0 0 L10 5 L0 10 Z`,{fill:r});t.set(i,e.el(`marker`,{id:i,viewBox:`0 0 10 10`,refX:9,refY:5,markerWidth:7,markerHeight:7,markerUnits:`userSpaceOnUse`,orient:`auto-start-reverse`},[a]))}return`url(#${i})`},defs:()=>t.size?[e.el(`defs`,{},[...t.values()])]:[]}}function R(e,t,n,r){let i=null;for(let t of e)n>=t.x&&n<=t.x+t.w&&r>=t.y&&r<=t.y+t.h&&(!i||t.w*t.h<i.w*i.h)&&(i=t);return i?t.frame(i.style).fill:t.bg}function z(e,t,n,{start:r,end:i}={}){let a=`M${t.points.map(e=>`${y(e.x)} ${y(e.y)}`).join(` L`)}`,o={fill:`none`,stroke:n.stroke,"stroke-width":n.width,"stroke-linecap":`round`,"stroke-linejoin":`round`,...n.dash?{"stroke-dasharray":n.dash}:{},...r?{"marker-start":r}:{},...i?{"marker-end":i}:{}};return{...e.path(a,o),meta:{kind:`edge`,from:t.from,to:t.to}}}function B(e,{from:t,to:n,rect:r,lines:i,icon:a,plate:o},s){let c=a?p.size+(i.length?p.gap:0):0,l=r.x+(r.w+c)/2,d=r.y+r.h/2;return{...e.el(`g`,{},[e.rect(r.x,r.y,r.w,r.h,{rx:3,fill:o}),...a?[A(e,a,r.x+u.padX,d,s.muted)]:[],...i.map((t,n)=>e.text(l,d+(n-(i.length-1)/2)*u.line,t,{anchor:`middle`,size:u.font.size,weight:u.font.weight,fill:s.muted,"dominant-baseline":`central`}))]),meta:{kind:`edge-label-group`,from:t,to:n}}}function V(e,t,n,r,i){let a=[],o=t.y;return t.rows.forEach((s,c)=>{for(let c of s){let s=t.x+c.x,u=o+l.row/2,d=[],p=f[c.key];if(p){let t=n.edge(p);d.push(z(e,{points:[{x:s+1,y:u},{x:s+l.swatch-1,y:u}]},t,{end:r.url(`arrow`,t.stroke)})),delete d[0].meta}else if(c.key===`db`){let t=n.frame();d.push(e.path(`M${s+2} ${u-4} A8 3 0 0 1 ${s+18} ${u-4} V${u+4} A8 3 0 0 1 ${s+2} ${u+4} Z M${s+2} ${u-4} A8 3 0 0 0 ${s+18} ${u-4}`,{fill:t.fill,stroke:n.line,"stroke-width":1}))}else{let t=n.card(c.key==="default"?void 0:c.key,i);d.push(e.rect(s+1,u-6,l.swatch-2,12,{rx:3,fill:t.fill,...N({...t,dash:t.dash&&`3 2`},1.25)}))}c.lines.forEach((t,r)=>d.push(e.text(s+l.swatch+l.gap,u+r*l.row,t,{size:l.font.size,weight:l.font.weight,fill:n.fg,"dominant-baseline":`central`}))),a.push(e.el(`g`,{},d))}o+=t.heights[c]+6}),{...e.el(`g`,{},a),meta:{kind:`legend`}}}return e.CARD=a,e.CHIP=o,e.EDGE_KINDS=f,e.FRAME=s,e.ICON=p,e.ITEM=d,e.LABEL=u,e.LEGEND=l,e.NOTE=c,e.STYLES=r,e.boardLook=O,e.drawCard=P,e.drawEdge=z,e.drawFrame=M,e.drawItem=F,e.drawLabel=B,e.drawLegend=V,e.drawNote=I,e.frameTitle=C,e.iconGlyph=A,e.markers=L,e.measureCard=x,e.measureItem=S,e.measureLabel=E,e.measureLegend=D,e.measureNote=T,e.surfaceAt=R,e.titleRect=w,e})({},KChartUnits[`core/color`],KChartUnits[`diagram/support`]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
KChartUnits["diagram/board-route"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),r=(e,t)=>({p0:e,c1:e,c2:t,p1:t}),i=`\0blocker`;function a({width:e,height:a,nodes:o,frames:s,blockers:c=[],edges:l}){let u=new Map([...o,...s].map(e=>[e.id,e])),d=l.map(e=>{let t=n(u.get(e.from)),i=n(u.get(e.to)),a=[r(t,i)];return{id:e.id,from:e.from,to:e.to,start:t,end:i,segments:a,initial:a,...e.label?{labelRect:{w:e.label.w,h:e.label.h}}:{}}}),f={type:`board`,width:e,height:a,labels:[],edges:d,nodes:[...o.map(e=>({...e})),...c.map((e,t)=>({...e,id:`${i}${t}`}))],frames:s.map(e=>({...e}))};return(0,t.repairRoutes)(f,new Map(d.map(e=>[e.id,{from:e.from,to:e.to}])),{board:!0}),{failed:d.filter(e=>e.segments===e.initial).map(e=>e.id),edges:d.filter(e=>e.segments!==e.initial).map(e=>({id:e.id,points:[e.segments[0].p0,...e.segments.map(e=>e.p1)],...e.labelRect?{labelRect:e.labelRect}:{}}))}}return e.routeBoard=a,e})({},KChartUnits[`diagram/graph-route`]);
|
package/dist/units/diagram/c4.js
CHANGED
|
@@ -3,4 +3,4 @@ KChartUnits["diagram/c4"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.
|
|
|
3
3
|
`,t);t=(n<0?e.length:n)-1;continue}if(a&&s===`\\`&&/["\\]/.test(e[t+1]??``)){n+=s+e[++t];continue}let c=/^\s*(?:title\s|accTitle\s*:|accDescr\s*:)/i.test(n),l=/^\s*(?:classDef|style|linkStyle)\s/i.test(n);s===`"`&&!c&&(a=!a),!a&&!c&&s===`(`&&o++,!a&&!c&&s===`)`&&o--,!a&&!c&&!o&&s===`{`&&!/^\s*accDescr\s*$/i.test(n)?(yield{text:n.trim()+`{`,line:i},n=``):!a&&!c&&!o&&s===`}`?(/^\s*accDescr\s*\{/i.test(n)?yield{text:n.trim()+`}`,line:i}:(n.trim()&&(yield{text:n.trim(),line:i}),yield{text:`}`,line:r}),n=``):(s===`
|
|
4
4
|
`||s===`;`&&!c&&!l)&&!a&&o<=0&&!/^\s*accDescr\s*\{/i.test(n)?n.trim()&&!(s===`
|
|
5
5
|
`&&/^\s*\{/.test(e.slice(t+1))&&/\)\s*$/.test(n))&&(yield{text:n.trim(),line:i},n=``,o=0):(!n.trim()&&/\S/.test(s)&&(i=r),n+=s),s===`
|
|
6
|
-
`&&r++}n.trim()&&(yield{text:n.trim(),line:i})}var h=[`sprite`,`tags`,`link`],g={c4ShapeInRow:4,c4BoundaryInRow:2},_=Object.keys(g).map(e=>`c4.${e}`),v=(e,t)=>Object.entries(e??{}).find(([e])=>e.toLowerCase()===t.toLowerCase())?.[1],y=(e,t,n)=>{let r=Number.parseInt(n,10);Number.isSafeInteger(r)&&r>=1&&(e[t]=r)},b=/\s*(?::::(?<class>[\w-]+)|::icon\(\s*(?<icon>[\w:-]+)\s*\))$/i,x=/::icon\(\s*([\w:-]+)\s*\)|(?<![\w:-])((?:logos|mdi|tabler|simple-icons):[\w-]+)/gi;function S(e,{kind:t,lang:o,firstLine:_=2,config:S}){let C=new Map,w=new Map,T=[],E=[],D=new Map,O={...g},k=(0,i.presentation)({lang:o}),A=new Set,j=v(S,`c4`);for(let e of Object.keys(O))y(O,e,v(j,e));let M=e=>{A.has(e.message)||(A.add(e.message),T.push(e))},N=(e,t)=>{let r=(0,n.resolveIconRef)(e);return r||M((0,a.warning)(`IGNORED_ASSET`,o,t,`未知图标 ${e}`,`Unknown icon ${e}`,`改用内置图标`,`Use a supported icon`)),r},P=(e,t)=>{let n=null,i=e.replace(x,(e,r,i)=>{let a=N(r||i,t);return n??=a,``}),a=(0,r.normalizeLabel)(i,{lang:o,line:t});return a.diagnostics.forEach(M),{text:a.text,icon:n??a.icon}},F,I=(e,t,n)=>T.push((0,a.error)(o,e,t,n,`检查 C4 声明及其参数`,`Check the C4 declaration and its arguments`)),L=(e,t,n)=>{if(n.length){D.has(e)||D.set(e,{line:t,fields:new Set});for(let t of n)D.get(e).fields.add(t)}};if(e.length>2e5)return I(_,`C4 源文本过长`,`C4 source is too long`),{model:null,errors:T};for(let t of m(e,_)){let{text:e}=t,{line:n}=t;if(k.accept(e,n))continue;if(/^title\s+/i.test(e)){F=P(e.replace(/^title\s+/i,``),n).text;continue}if(/^acc(?:Title|Descr)\s*:|^accDescr\s*\{[\s\S]*\}$/i.test(e))continue;if(e===`}`){E.length?E.pop():I(n,`没有对应的边界起点`,`Unmatched boundary close`);continue}let r=e.endsWith(`{`);r&&(e=e.slice(0,-1).trimEnd());let m=[];for(let t;t=b.exec(e);e=e.slice(0,t.index).trimEnd())m.unshift(t.groups);let[,g,_]=/^(\w+)\s*\(([\s\S]*)\)$/.exec(e)||[],v=s.get(g),x=u.has(g),S=c.get(g),D=d.has(g),A=g===`UpdateElementStyle`?[`alias`,`bgColor`,`fontColor`,`borderColor`,`shadowing`,`shape`,`sprite`,`techn`,`legendText`,`legendSprite`]:g===`UpdateRelStyle`?[`from`,`to`,`textColor`,`lineColor`,`offsetX`,`offsetY`]:null,j=v?[`alias`,`label`,...v.tech?[`techn`]:[],`descr`,...h]:x?[`alias`,`label`,`type`,`descr`,...h]:S?[`alias`,`label`,...g===`Boundary`?[`type`]:[],`tags`,`link`]:D?[...g===`RelIndex`?[`index`]:[],`from`,`to`,`label`,`techn`,`descr`,...h]:A??(g===`UpdateLayoutConfig`?Object.keys(O):null);if(!j&&/^(?:Legend|Lay_[UDLR]|Add(?:Element|Rel)Tag|\w+Shape)$/.test(g??``)){L(`IGNORED_STYLE`,n,[g]);continue}let M=j&&p(_,j);if(!M||r&&!S&&!x||S&&!r){I(n,`无法识别 C4 语句`,`Unrecognized C4 statement`);continue}let{from:N,to:R}=M,[z,...B]=(M.alias??``).split(`:::`),V=JSON.stringify([N,R]);if(g===`UpdateLayoutConfig`)for(let e of j)y(O,e,M[e]);else if(A){let e=g===`UpdateElementStyle`?C.get(z):w.get(V),t=f.get(M.shape?.toLowerCase()),r=[`bgColor`,`fontColor`,`borderColor`,`textColor`,`lineColor`];if(e){for(let t of r)M[t]&&(e[t]=(0,i.roleOfColor)(M[t]));t&&!e.frame&&(e.shape=t),M.techn!==void 0&&(e.techn=M.techn);for(let t of[`offsetX`,`offsetY`]){let n=Number.parseInt(M[t],10);Number.isFinite(n)&&(e[t]=n)}}L(`IGNORED_STYLE`,n,A.filter(n=>M[n]&&!(r.includes(n)&&e?.[n])&&![`alias`,`from`,`to`,`techn`,`offsetX`,`offsetY`].includes(n)&&!(n===`shape`&&t&&e&&!e.frame)))}else if(D){if(!N||!R){I(n,`关系缺少端点`,`Relationship is missing an endpoint`);continue}w.set(V,{from:N,to:R,label:M.label,techn:M.techn,descr:M.descr,line:n,icon:m.find(e=>e.icon)?.icon,index:M.index,hint:d.get(g),start:g===`BiRel`||g===`Rel_Back`,end:g!==`Rel_Back`}),L(`IGNORED_STYLE`,n,h.filter(e=>M[e]))}else{if(!z||C.has(z)){I(n,`元素别名缺失或重复`,`Missing or duplicate element alias`);continue}let e=[M.shape,M.sprite,...(M.tags??``).split(`+`)].map(e=>f.get(e?.toLowerCase())).find(Boolean),t={id:z,label:M.label||z,techn:M.techn,descr:M.descr,type:x?M.type||`Node`:S?M.type||S:v.label,zh:v?.zh??(M.type?void 0:l[x?`Node`:S]),external:v?.external,shape:e||v?.shape||`box`,parent:E.at(-1)?.id,frame:!!r,align:g===`Node_R`?`right`:`left`,line:n};k.addClasses(z,[...B,...m.map(e=>e.class).filter(Boolean)],n),t.icon=m.find(e=>e.icon)?.icon,C.set(z,t),r&&E.push(t),L(`IGNORED_STYLE`,n,h.filter(e=>M[e]&&!f.has(M[e].toLowerCase())).concat(M.shape&&!e?[`shape`]:[]))}if(C.size>300||w.size>300||E.length>64){T.push((0,a.error)(o,n,`C4 图最多 300 个元素、300 条关系、64 层边界`,`C4 supports up to 300 elements, 300 relations and 64 boundary levels`,`请拆分图表`,`Split the diagram`));break}}E.length&&I(E.at(-1).line,`C4 边界未关闭`,`Unclosed C4 boundary`);for(let e of w.values())for(let t of[e.from,e.to])C.has(t)||I(e.line,`未声明关系端点「${t}」`,`Undeclared relationship endpoint "${t}"`);for(let e of[...C.values(),...w.values()]){let t=e.icon?N(e.icon,e.line):null;for(let n of[`label`,`type`,`techn`,`descr`]){if(!e[n])continue;let r=P(e[n],e.line);e[n]=r.text,t??=r.icon}e.icon=t}for(let e of C.values())e.status=k.statusOf(e.id),e.link=k.linkOf(e.id);if([...w.values()].forEach((e,t)=>{e.status=k.edgeStatusOf(t)}),T.push(...k.diagnostics()),t===`C4Dynamic`){let e=0;for(let t of w.values())t.label=`${++e}: ${t.label??``}`}for(let[e,{line:t,fields:n}]of D){let r=[...n].join(`, `);T.push((0,a.warning)(e,o,t,`以下 C4 表现属性未应用:${r}`,`C4 presentation options not applied: ${r}`,`使用主题控制外观`,`Use the theme to control appearance`))}return{model:{kind:t,title:F,items:[...C.values()],rels:[...w.values()],config:O},errors:T}}var C=16,w=64,T=216,E=17,D=e=>e.x+e.w/2,O=e=>e.y+e.h/2,k=(e,t)=>({x:e.x-t,y:e.y-t,w:e.w+2*t,h:e.h+2*t}),A=(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,j=(e,t)=>e.x<=t.x&&e.y<=t.y&&e.x+e.w>=t.x+t.w&&e.y+e.h>=t.y+t.h,M=(e,t)=>({x:e,y:t}),N=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),P=(e,t,n)=>M(e.x+(t.x-e.x)*n,e.y+(t.y-e.y)*n),F=e=>e.slice(1).map((t,n)=>[e[n],t]);function I(e,t){let n=[e.label,e.techn&&`[${e.techn}]`,e.descr].filter(Boolean).flatMap(e=>t.wrap(e,156,a.FONT.label.size)),r=e.icon?22:0;return!n.length&&!r?null:{lines:n,iconSpace:r,w:Math.max(r,...n.map(e=>t.measure(e,a.FONT.label.size,a.FONT.label.weight)))+16,h:n.length*E+8+r}}function L(e,t,n){let r=new Map;for(let t of e.items)r.has(t.parent)||r.set(t.parent,[]),r.get(t.parent).push(t);let i=(e,n,r=176)=>e?t.wrap(e,r,n.size,n.weight).map(e=>({text:e,font:n})):[],o=new Map(e.items.map(e=>[e.id,e.parent])),s=e=>{let t=new Set;for(let n=e;n!==void 0&&!t.has(n);n=o.get(n))t.add(n);return t},c=e.rels.flatMap(e=>{let n=I(e,t);return n?[{from:s(e.from),to:s(e.to),label:n}]:[]}),l=(e,t,n)=>{let r=new Set(e.map(e=>e.id)),i=new Set(t.map(e=>e.id)),a=(e,t)=>[...e].some(e=>t.has(e));return Math.max(w,...c.filter(({from:e,to:t})=>a(e,r)&&a(t,i)||a(e,i)&&a(t,r)).map(({label:e})=>e[n]+20))},u=e=>{let t=`${e.external?(0,a.isEn)(n)?`External `:`外部`:``}${!(0,a.isEn)(n)&&e.zh?e.zh:e.type}`,r=e.techn?`${(0,a.isEn)(n)?`: `:`:`}${e.techn}`:``,o=[...i(e.label,a.FONT.title),...i(`[${t}${r}]`,a.FONT.label),...i(e.descr,a.FONT.body)],s=e.frame?d(e.id):null,c=e.icon||e.shape===`person`&&!e.frame?25:0,l=c+(e.shape===`database`&&!e.frame?8:0),u=32+o.length*E+l;return{...e,x:0,y:0,lines:o,topSpace:l,iconSpace:c,header:u,w:Math.max(T,(s?.w??0)+32),h:u+(s?s.h+C:0),children:s?.boxes??[]}};function d(t){let n=r.get(t)??[],i=[];for(let[t,r]of[[!1,e.config.c4ShapeInRow],[!0,e.config.c4BoundaryInRow]]){let e=n.filter(e=>e.frame===t);for(let t=0;t<e.length;t+=r)i.push(e.slice(t,t+r))}let a=[],o=0,s=0,c=null;for(let e of i){let t=e.map(u);c&&(s+=Math.max(...c.map(e=>e.h))+l(c,t,`h`));let n=0;t.forEach((e,r)=>{r&&(n+=t[r-1].w+l([t[r-1]],[e],`w`)),Object.assign(e,{x:n,y:s}),o=Math.max(o,n+e.w)}),a.push(...t),c=t}return{w:o,h:c?s+Math.max(...c.map(e=>e.h)):0,boxes:a}}return d(void 0)}function R([e,t],n){let r=0,i=1;for(let[a,o]of[[`x`,`w`],[`y`,`h`]]){let s=t[a]-e[a],c=n[a]-e[a],l=c+n[o];if(!s){if(c>0||l<0)return!1;continue}let u=c/s,d=l/s;if(r=Math.max(r,Math.min(u,d)),i=Math.min(i,Math.max(u,d)),r>i)return!1}return!0}var z=8;function B([e,t],[n,r]){let i=N(e,t);if(!i)return!1;let a=(t.x-e.x)/i,o=(t.y-e.y)/i,s=t=>a*(t.y-e.y)-o*(t.x-e.x),c=t=>a*(t.x-e.x)+o*(t.y-e.y),l=c(n),u=c(r),d=s(n),f=s(r)-d;if(Math.abs(f)>Math.abs(u-l)*.1||l===u)return!1;let p=Math.max(0,Math.min(l,u)),m=Math.min(i,Math.max(l,u)),h=Math.max(...[p,m].map(e=>Math.abs(d+(e-l)*f/(u-l))));return m-p>3&&h<=1.1||m-p>8&&h<z}function V(e,t,n,r,i,a){let o=e=>F(e).every(e=>!n.some(t=>R(e,t))&&!r.some(t=>B(t,e)||B(e,t))),s=(e,t)=>{let n=M(D(e),O(e));return P(n,t,Math.min(e.w/2/Math.abs(t.x-n.x),e.h/2/Math.abs(t.y-n.y)))};if(D(e)!==D(t)||O(e)!==O(t)){let n=[s(e,M(D(t),O(t))),s(t,M(D(e),O(e)))];if(o(n))return n}let c,l=1/0,u=e=>{e=e.filter((t,n)=>!n||N(t,e[n-1])>.01);let t=F(e).reduce((e,[t,n])=>e+N(t,n),0)+(e.length-2)*14;e.length>=2&&t<l&&o(e)&&(c=e,l=t)},d=(e,t,n)=>t===0?M(e.x,e.y+e.h*n):t===1?M(e.x+e.w,e.y+e.h*n):t===2?M(e.x+e.w*n,e.y):M(e.x+e.w*n,e.y+e.h);for(let n of[.5,.36,.64,.24,.76]){let r=12+a%5*4;for(let a=0;a<4;a++)for(let o=0;o<4;o++){if(e===t&&a===o)continue;let s=d(e,a,n),c=d(t,o,n),l=(e,t)=>M(e.x+(t===0?-r:t===1?r:0),e.y+(t===2?-r:t===3?r:0)),f=l(s,a),p=l(c,o);u([s,f,p,c]),u([s,f,M(f.x,p.y),p,c]),u([s,f,M(p.x,f.y),p,c]);for(let e of[(f.x+p.x)/2,i.x,i.x+i.w,f.x,p.x])u([s,f,M(e,f.y),M(e,p.y),p,c]);for(let e of[(f.y+p.y)/2,i.y,i.y+i.h,f.y,p.y])u([s,f,M(f.x,e),M(p.x,e),p,c])}if(c)break}return c}function H(e,t,n,r,i){if(!t)return[];let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=18/Math.max(s,c),u=t.set===`simple`;return[{...e.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n))),meta:{kind:`icon`}}]}function U(e,n){let{x:r,y:i,w:o,h:s}=n,c=n.borderColor||n.status||n.bgColor||(n.external?`ext`:null),l=e.design[c]??e.frameTone((0,t.mix)(e.design.line2,e.design.fg3,n.frame?.48:.27)),u=n.bgColor||n.status,d={fill:n.frame?`none`:u?(0,t.mix)(e.design.surface,e.design[u],.08):e.design.surface,stroke:l,"stroke-width":1.25,...n.frame||n.external?{"stroke-dasharray":n.frame?`5 4`:`3 3`}:{}},f={kind:n.frame?`frame`:`node`,id:n.id},p,m=[];!n.frame&&n.shape===`database`?(p=e.shape(`path`,{d:`M${r} ${i+8} C${r} ${i-3} ${r+o} ${i-3} ${r+o} ${i+8} V${i+s-8} C${r+o} ${i+s+3} ${r} ${i+s+3} ${r} ${i+s-8} Z`,...d},f),m=[e.path(`M${r} ${i+8} C${r} ${i+19} ${r+o} ${i+19} ${r+o} ${i+8}`,{fill:`none`,stroke:l})]):!n.frame&&n.shape===`queue`?(p=e.shape(`path`,{d:`M${r+10} ${i} H${r+o-10} C${r+o+3.33} ${i} ${r+o+3.33} ${i+s} ${r+o-10} ${i+s} H${r+10} C${r-3.33} ${i+s} ${r-3.33} ${i} ${r+10} ${i} Z`,...d},f),m=[e.shape(`ellipse`,{cx:r+10,cy:O(n),rx:10,ry:s/2,fill:`none`,stroke:l})]):(p=e.shape(`rect`,{x:r,y:i,width:o,height:s,rx:n.frame?5:8,...d},f),!n.frame&&n.shape===`component`&&(m=[e.rect(r+8,i+9,4,s-18,{fill:l,rx:2})]),!n.frame&&n.shape===`person`&&!n.icon&&(m=[e.shape(`circle`,{cx:D(n),cy:i+15,r:5,fill:l}),e.path(`M${D(n)-9} ${i+32} C${D(n)-9} ${i+21} ${D(n)+9} ${i+21} ${D(n)+9} ${i+32} Z`,{fill:l})]));let h=n.frame&&n.align===`right`,g=n.lines.map(({text:t,font:s},c)=>e.text(n.frame?h?r+o-C:r+C:D(n),i+C+n.topSpace+(c+.5)*E,t,{anchor:n.frame?h?`end`:`start`:`middle`,"dominant-baseline":`central`,size:s.size,weight:s.weight,fill:s===a.FONT.title?e.design[n.fontColor]??e.design.fg1:e.design.fg3})),_=H(e,n.icon,n.frame?h?r+o-C-9:r+C+9:D(n),i+C+n.iconSpace-11,l),v=[p,...m,..._,...g];return n.link?[e.link(n.link.href,v,n.link)]:v}function W(e,{width:t,ctx:n,lang:r}){let i=L(e,n,r),o=[],s=[],c=new Map,l=Math.max(t,i.w+76),u=i.h+76;function d(e,t,n){for(let r of e){let e={...r,x:t+r.x,y:n+r.y};(e.frame?s:o).push(e),c.set(e.id,e),d(e.children,e.x+C,e.y+e.header)}}d(i.boxes,Math.max(38,(l-i.w)/2),38);let f=s.map(e=>{let t=Math.max(e.iconSpace,...e.lines.map(({text:e,font:t})=>n.measure(e,t.size,t.weight)))+6;return{x:e.align===`right`?e.x+e.w-C+3-t:e.x+C-3,y:e.y+C-3,w:t,h:e.topSpace+e.lines.length*E+6}}),p=s.flatMap(e=>U(n,e)),m=[...o,...f],h=[],g=[],_=[],v=[];for(let[t,i]of e.rels.entries()){let e=c.get(i.from),d=c.get(i.to),m=s.filter(t=>t!==e&&t!==d&&!j(t,e)&&!j(t,d)),y=[...o.filter(t=>t!==e&&t!==d).map(e=>k(e,z)),...[...f,...m].map(e=>k(e,4))],b=[e,d].filter(t=>!t.frame||e===d||!j(t,t===e?d:e)).map(e=>k(e,-2)),x=V(e,d,[...y,...b],h,{x:10+t%7*3,y:10+t%7*3,w:l-20-t%7*6,h:u-20-t%7*6},t);if(!x){_.push((0,a.error)(r,i.line,`找不到不穿过元素的 C4 连线`,`No clear route for this C4 relationship`,`拆分图表或调整声明顺序`,`Split the diagram or reorder declarations`));continue}let S={from:i.from,to:i.to},C=n.design[i.status||i.lineColor]??n.design.fg3;p.push(n.shape(`polyline`,{points:x.map(e=>`${e.x},${e.y}`).join(` `),fill:`none`,stroke:C,"stroke-width":1.35,"stroke-linejoin":`round`},{kind:`edge`,...S}));for(let[e,t,r,a]of[[i.start,x[0],x[1],`start`],[i.end,x.at(-1),x.at(-2),`end`]]){if(!e)continue;v.push({x:t.x-8,y:t.y-8,w:16,h:16});let i=P(t,r,8/N(t,r)),o=(t.x-i.x)*.45,s=(t.y-i.y)*.45;p.push(n.shape(`polygon`,{points:`${t.x},${t.y} ${i.x-s},${i.y+o} ${i.x+s},${i.y-o}`,fill:C},{kind:`relation-marker`,...S,end:a}))}h.push(...F(x)),g.push({path:x,rel:i,meta:S})}p.push(...o.flatMap(e=>U(n,e)));let y=[];for(let{path:e,rel:t,meta:r}of g){let i=I(t,n);if(!i)continue;let{lines:o,iconSpace:c,w:d,h:f}=i,g=F(e),_=g.reduce((e,[t,n])=>e+N(t,n),0),b=t=>{let n=_*t;for(let[e,t]of g){let r=N(e,t);if(n<=r)return P(e,t,n/r);n-=r}return e.at(-1)},x=b(.5),S=t.hint===`U`?f/2+6:0,C=M(x.x+(t.offsetX??0),x.y+(t.offsetY??S)),w=e=>({x:Math.max(6,Math.min(e.x-d/2,l-d-6)),y:e.y-f/2,w:d,h:f}),T=e=>e.y>=6&&e.y+f<=u-6&&!m.some(t=>A(k(e,4),t))&&!v.some(t=>A(e,t)),L=[[C,x]];for(let e of[.5,.4,.6,.3,.7,.2,.8,.1,.9]){let t=b(e);L.push([M(t.x,6+f/2),t],[M(t.x,u-6-f/2),t]);for(let e of[0,-d/2-4,d/2+4])for(let n of[0,-f/2-4,f/2+4,-f-8,f+8])L.push([M(t.x+e,t.y+n),t])}let z,B,V=1/0,U=h.filter(t=>!e.includes(t[0])||!e.includes(t[1])).concat(y);for(let[e,t]of L){let n=w(e);if(!T(n))continue;let r=M(Math.max(n.x,Math.min(n.x+d,t.x)),Math.max(n.y,Math.min(n.y+f,t.y))),i=g.some(e=>R(e,n))?null:[t,r];if(i&&m.some(e=>R(i,e)))continue;let a=s.some(e=>!j(e,k(n,2))&&A(e,k(n,2))),o=N(M(D(n),O(n)),C)+(i?N(...i)*2:0)+(a?34:0)+240*U.filter(e=>R(e,n)).length;o<V&&(V=o,z=n,B=i)}z||(z=w(M(x.x,u+f/2)),u+=f+14,B=[x,M(D(z),z.y)]),B&&(y.push(B),p.push(n.path(`M${B[0].x} ${B[0].y} L${B[1].x} ${B[1].y}`,{fill:`none`,stroke:n.design.fg3,"stroke-dasharray":`2 3`,meta:{kind:`leader`,...r}}))),m.push(z),p.push({...n.el(`g`,{},[n.rect(z.x,z.y,z.w,z.h,{fill:n.design.bg,stroke:n.design.line2,rx:5}),...H(n,t.icon,D(z),z.y+14,n.design[t.status||t.textColor]??n.design.fg3),...o.map((e,r)=>n.text(D(z),z.y+4+c+(r+.5)*E,e,{anchor:`middle`,"dominant-baseline":`central`,size:a.FONT.label.size,fill:n.design[t.textColor]??n.design.fg1}))]),meta:{kind:`edge-label-group`,...r}})}return(l>2*t||o.length>60)&&_.push((0,a.warning)(`LARGE_DIAGRAM`,r,1,`C4 图较大`,`Large C4 diagram`,`考虑拆分图表`,`Consider splitting the diagram`)),{scene:{width:l,height:u,children:p,title:e.title,heading:e.title},errors:_}}return e.implementations=Object.fromEntries(o.map(e=>[e,{parse:S,layout:W,acceptsPresentation:!0,honoredConfig:_}])),e})({},KChartUnits[`core/color`],KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
6
|
+
`&&r++}n.trim()&&(yield{text:n.trim(),line:i})}var h=[`sprite`,`tags`,`link`],g={c4ShapeInRow:4,c4BoundaryInRow:2},_=Object.keys(g).map(e=>`c4.${e}`),v=(e,t)=>Object.entries(e??{}).find(([e])=>e.toLowerCase()===t.toLowerCase())?.[1],y=(e,t,n)=>{let r=Number.parseInt(n,10);Number.isSafeInteger(r)&&r>=1&&(e[t]=r)},b=/\s*(?::::(?<class>[\w-]+)|::icon\(\s*(?<icon>[\w:-]+)\s*\))$/i,x=/::icon\(\s*([\w:-]+)\s*\)|(?<![\w:-])((?:logos|mdi|tabler|simple-icons):[\w-]+)/gi;function S(e,{kind:t,lang:o,firstLine:_=2,config:S}){let C=new Map,w=new Map,T=[],E=[],D=new Map,O={...g},k=(0,i.presentation)({lang:o}),A=new Set,j=v(S,`c4`);for(let e of Object.keys(O))y(O,e,v(j,e));let M=e=>{A.has(e.message)||(A.add(e.message),T.push(e))},N=(e,t)=>{let r=(0,n.resolveIconRef)(e);return r||M((0,a.warning)(`IGNORED_ASSET`,o,t,`未知图标 ${e}`,`Unknown icon ${e}`,`改用内置图标`,`Use a supported icon`)),r},P=(e,t)=>{let n=null,i=e.replace(x,(e,r,i)=>{let a=N(r||i,t);return n??=a,``}),a=(0,r.normalizeLabel)(i,{lang:o,line:t});return a.diagnostics.forEach(M),{text:a.text,icon:n??a.icon}},F,I=(e,t,n)=>T.push((0,a.error)(o,e,t,n,`检查 C4 声明及其参数`,`Check the C4 declaration and its arguments`)),L=(e,t,n)=>{if(n.length){D.has(e)||D.set(e,{line:t,fields:new Set});for(let t of n)D.get(e).fields.add(t)}};if(e.length>2e5)return I(_,`C4 源文本过长`,`C4 source is too long`),{model:null,errors:T};for(let t of m(e,_)){let{text:e}=t,{line:n}=t;if(k.accept(e,n))continue;if(/^title\s+/i.test(e)){F=P(e.replace(/^title\s+/i,``),n).text;continue}if(/^acc(?:Title|Descr)\s*:|^accDescr\s*\{[\s\S]*\}$/i.test(e))continue;if(e===`}`){E.length?E.pop():I(n,`没有对应的边界起点`,`Unmatched boundary close`);continue}let r=e.endsWith(`{`);r&&(e=e.slice(0,-1).trimEnd());let m=[];for(let t;t=b.exec(e);e=e.slice(0,t.index).trimEnd())m.unshift(t.groups);let[,g,_]=/^(\w+)\s*\(([\s\S]*)\)$/.exec(e)||[],v=s.get(g),x=u.has(g),S=c.get(g),D=d.has(g),A=g===`UpdateElementStyle`?[`alias`,`bgColor`,`fontColor`,`borderColor`,`shadowing`,`shape`,`sprite`,`techn`,`legendText`,`legendSprite`]:g===`UpdateRelStyle`?[`from`,`to`,`textColor`,`lineColor`,`offsetX`,`offsetY`]:null,j=v?[`alias`,`label`,...v.tech?[`techn`]:[],`descr`,...h]:x?[`alias`,`label`,`type`,`descr`,...h]:S?[`alias`,`label`,...g===`Boundary`?[`type`]:[],`tags`,`link`]:D?[...g===`RelIndex`?[`index`]:[],`from`,`to`,`label`,`techn`,`descr`,...h]:A??(g===`UpdateLayoutConfig`?Object.keys(O):null);if(!j&&/^(?:Legend|Lay_[UDLR]|Add(?:Element|Rel)Tag|\w+Shape)$/.test(g??``)){L(`IGNORED_STYLE`,n,[g]);continue}let M=j&&p(_,j);if(!M||r&&!S&&!x||S&&!r){I(n,`无法识别 C4 语句`,`Unrecognized C4 statement`);continue}let{from:N,to:R}=M,[z,...B]=(M.alias??``).split(`:::`),V=JSON.stringify([N,R]);if(g===`UpdateLayoutConfig`)for(let e of j)y(O,e,M[e]);else if(A){let e=g===`UpdateElementStyle`?C.get(z):w.get(V),t=f.get(M.shape?.toLowerCase()),r=[`bgColor`,`fontColor`,`borderColor`,`textColor`,`lineColor`];if(e){for(let t of r)M[t]&&(e[t]=(0,i.roleOfColor)(M[t]));t&&!e.frame&&(e.shape=t),M.techn!==void 0&&(e.techn=M.techn);for(let t of[`offsetX`,`offsetY`]){let n=Number.parseInt(M[t],10);Number.isFinite(n)&&(e[t]=n)}}L(`IGNORED_STYLE`,n,A.filter(n=>M[n]&&!(r.includes(n)&&e?.[n])&&![`alias`,`from`,`to`,`techn`,`offsetX`,`offsetY`].includes(n)&&!(n===`shape`&&t&&e&&!e.frame)))}else if(D){if(!N||!R){I(n,`关系缺少端点`,`Relationship is missing an endpoint`);continue}w.set(V,{from:N,to:R,label:M.label,techn:M.techn,descr:M.descr,line:n,icon:m.find(e=>e.icon)?.icon,index:M.index,hint:d.get(g),start:g===`BiRel`||g===`Rel_Back`,end:g!==`Rel_Back`}),L(`IGNORED_STYLE`,n,h.filter(e=>M[e]))}else{if(!z||C.has(z)){I(n,`元素别名缺失或重复`,`Missing or duplicate element alias`);continue}let e=[M.shape,M.sprite,...(M.tags??``).split(`+`)].map(e=>f.get(e?.toLowerCase())).find(Boolean),t={id:z,label:M.label||z,techn:M.techn,descr:M.descr,type:x?M.type||`Node`:S?M.type||S:v.label,zh:v?.zh??(M.type?void 0:l[x?`Node`:S]),external:v?.external,shape:e||v?.shape||`box`,parent:E.at(-1)?.id,frame:!!r,align:g===`Node_R`?`right`:`left`,line:n};k.addClasses(z,[...B,...m.map(e=>e.class).filter(Boolean)],n),t.icon=m.find(e=>e.icon)?.icon,C.set(z,t),r&&E.push(t),L(`IGNORED_STYLE`,n,h.filter(e=>M[e]&&!f.has(M[e].toLowerCase())).concat(M.shape&&!e?[`shape`]:[]))}if(C.size>300||w.size>300||E.length>64){T.push((0,a.error)(o,n,`C4 图最多 300 个元素、300 条关系、64 层边界`,`C4 supports up to 300 elements, 300 relations and 64 boundary levels`,`请拆分图表`,`Split the diagram`));break}}E.length&&I(E.at(-1).line,`C4 边界未关闭`,`Unclosed C4 boundary`);for(let e of w.values())for(let t of[e.from,e.to])C.has(t)||I(e.line,`未声明关系端点「${t}」`,`Undeclared relationship endpoint "${t}"`);for(let e of[...C.values(),...w.values()]){let t=e.icon?N(e.icon,e.line):null;for(let n of[`label`,`type`,`techn`,`descr`]){if(!e[n])continue;let r=P(e[n],e.line);e[n]=r.text,t??=r.icon}e.icon=t}for(let e of C.values())e.status=k.statusOf(e.id),e.link=k.linkOf(e.id);if([...w.values()].forEach((e,t)=>{e.status=k.edgeStatusOf(t)}),T.push(...k.diagnostics()),t===`C4Dynamic`){let e=0;for(let t of w.values())t.label=`${++e}: ${t.label??``}`}for(let[e,{line:t,fields:n}]of D){let r=[...n].join(`, `);T.push((0,a.warning)(e,o,t,`以下 C4 表现属性未应用:${r}`,`C4 presentation options not applied: ${r}`,`使用主题控制外观`,`Use the theme to control appearance`))}return{model:{kind:t,title:F,items:[...C.values()],rels:[...w.values()],config:O},errors:T}}var C=16,w=64,T=216,E=17,D=e=>e.x+e.w/2,O=e=>e.y+e.h/2,k=(e,t)=>({x:e.x-t,y:e.y-t,w:e.w+2*t,h:e.h+2*t}),A=(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,j=(e,t)=>e.x<=t.x&&e.y<=t.y&&e.x+e.w>=t.x+t.w&&e.y+e.h>=t.y+t.h,M=(e,t)=>({x:e,y:t}),N=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),P=(e,t,n)=>M(e.x+(t.x-e.x)*n,e.y+(t.y-e.y)*n),F=e=>e.slice(1).map((t,n)=>[e[n],t]);function I(e,t){let n=[e.label,e.techn&&`[${e.techn}]`,e.descr].filter(Boolean).flatMap(e=>t.wrap(e,156,a.FONT.label.size)),r=e.icon?22:0;return!n.length&&!r?null:{lines:n,iconSpace:r,w:Math.max(r,...n.map(e=>t.measure(e,a.FONT.label.size,a.FONT.label.weight)))+16,h:n.length*E+8+r}}function L(e,t,n){let r=new Map;for(let t of e.items)r.has(t.parent)||r.set(t.parent,[]),r.get(t.parent).push(t);let i=(e,n,r=176)=>e?t.wrap(e,r,n.size,n.weight).map(e=>({text:e,font:n})):[],o=new Map(e.items.map(e=>[e.id,e.parent])),s=e=>{let t=new Set;for(let n=e;n!==void 0&&!t.has(n);n=o.get(n))t.add(n);return t},c=e.rels.flatMap(e=>{let n=I(e,t);return n?[{from:s(e.from),to:s(e.to),label:n}]:[]}),l=(e,t,n)=>{let r=new Set(e.map(e=>e.id)),i=new Set(t.map(e=>e.id)),a=(e,t)=>[...e].some(e=>t.has(e));return Math.max(w,...c.filter(({from:e,to:t})=>a(e,r)&&a(t,i)||a(e,i)&&a(t,r)).map(({label:e})=>e[n]+20))},u=e=>{let t=`${e.external?(0,a.isEn)(n)?`External `:`外部`:``}${!(0,a.isEn)(n)&&e.zh?e.zh:e.type}`,r=e.techn?`${(0,a.isEn)(n)?`: `:`:`}${e.techn}`:``,o=[...i(e.label,a.FONT.title),...i(`[${t}${r}]`,a.FONT.label),...i(e.descr,a.FONT.body)],s=e.frame?d(e.id):null,c=e.icon||e.shape===`person`&&!e.frame?25:0,l=c+(e.shape===`database`&&!e.frame?8:0),u=32+o.length*E+l;return{...e,x:0,y:0,lines:o,topSpace:l,iconSpace:c,header:u,w:Math.max(T,(s?.w??0)+32),h:u+(s?s.h+C:0),children:s?.boxes??[]}};function d(t){let n=r.get(t)??[],i=[];for(let[t,r]of[[!1,e.config.c4ShapeInRow],[!0,e.config.c4BoundaryInRow]]){let e=n.filter(e=>e.frame===t);for(let t=0;t<e.length;t+=r)i.push(e.slice(t,t+r))}let a=[],o=0,s=0,c=null;for(let e of i){let t=e.map(u);c&&(s+=Math.max(...c.map(e=>e.h))+l(c,t,`h`));let n=0;t.forEach((e,r)=>{r&&(n+=t[r-1].w+l([t[r-1]],[e],`w`)),Object.assign(e,{x:n,y:s}),o=Math.max(o,n+e.w)}),a.push(...t),c=t}return{w:o,h:c?s+Math.max(...c.map(e=>e.h)):0,boxes:a}}return d(void 0)}function R([e,t],n){let r=0,i=1;for(let[a,o]of[[`x`,`w`],[`y`,`h`]]){let s=t[a]-e[a],c=n[a]-e[a],l=c+n[o];if(!s){if(c>0||l<0)return!1;continue}let u=c/s,d=l/s;if(r=Math.max(r,Math.min(u,d)),i=Math.min(i,Math.max(u,d)),r>i)return!1}return!0}var z=8;function B([e,t],[n,r]){let i=N(e,t);if(!i)return!1;let a=(t.x-e.x)/i,o=(t.y-e.y)/i,s=t=>a*(t.y-e.y)-o*(t.x-e.x),c=t=>a*(t.x-e.x)+o*(t.y-e.y),l=c(n),u=c(r),d=s(n),f=s(r)-d;if(Math.abs(f)>Math.abs(u-l)*.1||l===u)return!1;let p=Math.max(0,Math.min(l,u)),m=Math.min(i,Math.max(l,u)),h=Math.max(...[p,m].map(e=>Math.abs(d+(e-l)*f/(u-l))));return m-p>3&&h<=1.1||m-p>8&&h<z}function V(e,t,n,r,i,a){let o=e=>F(e).every(e=>!n.some(t=>R(e,t))&&!r.some(t=>B(t,e)||B(e,t))),s=(e,t)=>{let n=M(D(e),O(e));return P(n,t,Math.min(e.w/2/Math.abs(t.x-n.x),e.h/2/Math.abs(t.y-n.y)))};if(D(e)!==D(t)||O(e)!==O(t)){let n=[s(e,M(D(t),O(t))),s(t,M(D(e),O(e)))];if(o(n))return n}let c,l=1/0,u=e=>{e=e.filter((t,n)=>!n||N(t,e[n-1])>.01);let t=F(e).reduce((e,[t,n])=>e+N(t,n),0)+(e.length-2)*14;e.length>=2&&t<l&&o(e)&&(c=e,l=t)},d=(e,t,n)=>t===0?M(e.x,e.y+e.h*n):t===1?M(e.x+e.w,e.y+e.h*n):t===2?M(e.x+e.w*n,e.y):M(e.x+e.w*n,e.y+e.h);for(let n of[.5,.36,.64,.24,.76]){let r=12+a%5*4;for(let a=0;a<4;a++)for(let o=0;o<4;o++){if(e===t&&a===o)continue;let s=d(e,a,n),c=d(t,o,n),l=(e,t)=>M(e.x+(t===0?-r:t===1?r:0),e.y+(t===2?-r:t===3?r:0)),f=l(s,a),p=l(c,o);u([s,f,p,c]),u([s,f,M(f.x,p.y),p,c]),u([s,f,M(p.x,f.y),p,c]);for(let e of[(f.x+p.x)/2,i.x,i.x+i.w,f.x,p.x])u([s,f,M(e,f.y),M(e,p.y),p,c]);for(let e of[(f.y+p.y)/2,i.y,i.y+i.h,f.y,p.y])u([s,f,M(f.x,e),M(p.x,e),p,c])}if(c)break}return c}function H(e,t,n,r,i){if(!t)return[];let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=18/Math.max(s,c),u=t.set===`simple`;return[{...e.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n))),meta:{kind:`icon`}}]}function U(e,n){let{x:r,y:i,w:o,h:s}=n,c=n.borderColor||n.status||n.bgColor||(n.external?`ext`:null),l=e.design[c]??e.frameTone((0,t.mix)(e.design.line2,e.design.fg3,n.frame?.48:.27)),u=n.bgColor||n.status,d={fill:n.frame?`none`:u?(0,t.mix)(e.design.surface,e.design[u],.08):e.design.surface,stroke:l,"stroke-width":1.25,...n.frame||n.external?{"stroke-dasharray":n.frame?`5 4`:`3 3`}:{}},f={kind:n.frame?`frame`:`node`,id:n.id},p,m=[];!n.frame&&n.shape===`database`?(p=e.shape(`path`,{d:`M${r} ${i+8} C${r} ${i-3} ${r+o} ${i-3} ${r+o} ${i+8} V${i+s-8} C${r+o} ${i+s+3} ${r} ${i+s+3} ${r} ${i+s-8} Z`,...d},f),m=[e.path(`M${r} ${i+8} C${r} ${i+19} ${r+o} ${i+19} ${r+o} ${i+8}`,{fill:`none`,stroke:l})]):!n.frame&&n.shape===`queue`?(p=e.shape(`path`,{d:`M${r+10} ${i} H${r+o-10} C${r+o+3.33} ${i} ${r+o+3.33} ${i+s} ${r+o-10} ${i+s} H${r+10} C${r-3.33} ${i+s} ${r-3.33} ${i} ${r+10} ${i} Z`,...d},f),m=[e.shape(`ellipse`,{cx:r+10,cy:O(n),rx:10,ry:s/2,fill:`none`,stroke:l})]):(p=e.shape(`rect`,{x:r,y:i,width:o,height:s,rx:n.frame?5:8,...d},f),!n.frame&&n.shape===`component`&&(m=[e.rect(r+8,i+9,4,s-18,{fill:l,rx:2})]),!n.frame&&n.shape===`person`&&!n.icon&&(m=[e.shape(`circle`,{cx:D(n),cy:i+15,r:5,fill:l}),e.path(`M${D(n)-9} ${i+32} C${D(n)-9} ${i+21} ${D(n)+9} ${i+21} ${D(n)+9} ${i+32} Z`,{fill:l})]));let h=n.frame&&n.align===`right`,g=n.lines.map(({text:t,font:s},c)=>e.text(n.frame?h?r+o-C:r+C:D(n),i+C+n.topSpace+(c+.5)*E,t,{anchor:n.frame?h?`end`:`start`:`middle`,"dominant-baseline":`central`,size:s.size,weight:s.weight,fill:s===a.FONT.title?e.design[n.fontColor]??e.design.fg1:e.design.fg3})),_=H(e,n.icon,n.frame?h?r+o-C-9:r+C+9:D(n),i+C+n.iconSpace-11,l),v=[p,...m,..._,...g];return n.link?[e.link(n.link.href,v,n.link)]:v}function W(e,{width:t,ctx:n,lang:r,compact:i}){let o=L(e,n,r),s=[],c=[],l=new Map,u=Math.max(i?0:t,o.w+76),d=o.h+76;function f(e,t,n){for(let r of e){let e={...r,x:t+r.x,y:n+r.y};(e.frame?c:s).push(e),l.set(e.id,e),f(e.children,e.x+C,e.y+e.header)}}f(o.boxes,Math.max(38,(u-o.w)/2),38);let p=c.map(e=>{let t=Math.max(e.iconSpace,...e.lines.map(({text:e,font:t})=>n.measure(e,t.size,t.weight)))+6;return{x:e.align===`right`?e.x+e.w-C+3-t:e.x+C-3,y:e.y+C-3,w:t,h:e.topSpace+e.lines.length*E+6}}),m=c.flatMap(e=>U(n,e)),h=[...s,...p],g=[],_=[],v=[],y=[];for(let[t,i]of e.rels.entries()){let e=l.get(i.from),o=l.get(i.to),f=c.filter(t=>t!==e&&t!==o&&!j(t,e)&&!j(t,o)),h=[...s.filter(t=>t!==e&&t!==o).map(e=>k(e,z)),...[...p,...f].map(e=>k(e,4))],b=[e,o].filter(t=>!t.frame||e===o||!j(t,t===e?o:e)).map(e=>k(e,-2)),x=V(e,o,[...h,...b],g,{x:10+t%7*3,y:10+t%7*3,w:u-20-t%7*6,h:d-20-t%7*6},t);if(!x){v.push((0,a.error)(r,i.line,`找不到不穿过元素的 C4 连线`,`No clear route for this C4 relationship`,`拆分图表或调整声明顺序`,`Split the diagram or reorder declarations`));continue}let S={from:i.from,to:i.to},C=n.design[i.status||i.lineColor]??n.design.fg3;m.push(n.shape(`polyline`,{points:x.map(e=>`${e.x},${e.y}`).join(` `),fill:`none`,stroke:C,"stroke-width":1.35,"stroke-linejoin":`round`},{kind:`edge`,...S}));for(let[e,t,r,a]of[[i.start,x[0],x[1],`start`],[i.end,x.at(-1),x.at(-2),`end`]]){if(!e)continue;y.push({x:t.x-8,y:t.y-8,w:16,h:16});let i=P(t,r,8/N(t,r)),o=(t.x-i.x)*.45,s=(t.y-i.y)*.45;m.push(n.shape(`polygon`,{points:`${t.x},${t.y} ${i.x-s},${i.y+o} ${i.x+s},${i.y-o}`,fill:C},{kind:`relation-marker`,...S,end:a}))}g.push(...F(x)),_.push({path:x,rel:i,meta:S})}m.push(...s.flatMap(e=>U(n,e)));let b=[],x=[.5,.4,.6,.3,.7,.2,.8,.1,.9],S=Array.from({length:19},(e,t)=>t+1).flatMap(e=>[(20-e)/40,(20+e)/40]).filter(e=>!x.includes(e));for(let{path:e,rel:t,meta:r}of _){let i=I(t,n);if(!i)continue;let{lines:o,iconSpace:s,w:l,h:f}=i,p=F(e),_=p.reduce((e,[t,n])=>e+N(t,n),0),v=t=>{let n=_*t;for(let[e,t]of p){let r=N(e,t);if(n<=r)return P(e,t,n/r);n-=r}return e.at(-1)},C=v(.5),w=t.hint===`U`?f/2+6:0,T=M(C.x+(t.offsetX??0),C.y+(t.offsetY??w)),L=e=>({x:Math.max(6,Math.min(e.x-l/2,u-l-6)),y:e.y-f/2,w:l,h:f}),z=e=>e.y>=6&&e.y+f<=d-6&&!h.some(t=>A(k(e,4),t))&&!y.some(t=>A(e,t)),B,V,U=1/0,W=g.filter(t=>!e.includes(t[0])||!e.includes(t[1])).concat(b),G=e=>!h.some(t=>R(e,t)),K=(e,t)=>{let n=L(e);if(!z(n))return;let r=M(Math.max(n.x,Math.min(n.x+l,t.x)),Math.max(n.y,Math.min(n.y+f,t.y))),i=p.some(e=>R(e,n))?null:[t,r];if(i&&!G(i))return;let a=k(n,2);if(c.some(e=>A(e,a)&&!j(e,a)))return;let o=N(M(D(n),O(n)),T)+(i?N(...i)*2:0)+240*W.filter(e=>R(e,n)).length;o<U&&(U=o,B=n,V=i)},q=e=>{for(let t of e){let e=v(t);K(M(e.x,6+f/2),e),K(M(e.x,d-6-f/2),e);for(let t of[0,-l/2-4,l/2+4])for(let n of[0,-f/2-4,f/2+4,-f-8,f+8])K(M(e.x+t,e.y+n),e)}};if(K(T,C),q(x),B||q(S),!B)for(let e of x){let t=v(e);for(let e of[6+l/2,u-6-l/2]){let n=L(M(e,t.y)),r=k(n,2);if(!z(n)||c.some(e=>A(e,r)&&!j(e,r)))continue;let i=[t,M(t.x<e?n.x:n.x+l,t.y)];if(!G(i))continue;let a=N(...i);a<U&&(U=a,B=n,V=i)}}if(!B){let t=[...e,...x.map(v),...S.map(v)].sort((e,t)=>t.y-e.y);for(let e of t){let t=L(M(e.x,d+f/2)),n=[e,M(e.x,t.y)];if(!(e.x<t.x||e.x>t.x+l||!G(n))){B=t,V=n;break}}B||(B=L(M(C.x,d+f/2)),V=[C,M(D(B),B.y)]),d+=f+14}V&&(b.push(V),m.push(n.path(`M${V[0].x} ${V[0].y} L${V[1].x} ${V[1].y}`,{fill:`none`,stroke:n.design.fg3,"stroke-dasharray":`2 3`,meta:{kind:`leader`,...r}}))),h.push(B),m.push({...n.el(`g`,{},[n.rect(B.x,B.y,B.w,B.h,{fill:n.design.bg,stroke:n.design.line2,rx:5}),...H(n,t.icon,D(B),B.y+14,n.design[t.status||t.textColor]??n.design.fg3),...o.map((e,r)=>n.text(D(B),B.y+4+s+(r+.5)*E,e,{anchor:`middle`,"dominant-baseline":`central`,size:a.FONT.label.size,fill:n.design[t.textColor]??n.design.fg1}))]),meta:{kind:`edge-label-group`,...r}})}return(u>2*t||s.length>60)&&v.push((0,a.warning)(`LARGE_DIAGRAM`,r,1,`C4 图较大`,`Large C4 diagram`,`考虑拆分图表`,`Consider splitting the diagram`)),{scene:{width:u,height:d,children:m,title:e.title,heading:e.title},errors:v}}return e.implementations=Object.fromEntries(o.map(e=>[e,{parse:S,layout:W,acceptsPresentation:!0,honoredConfig:_}])),e})({},KChartUnits[`core/color`],KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
KChartUnits["diagram/class"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.freeze({kind:`classDiagram`,syntax:`mermaid`,topic:`data-model`,aliases:Object.freeze([`classDiagram-v2`])}),c=Object.freeze([s]),l=Object.freeze({cards:2e3,edges:5e3,large:60}),u=Object.freeze([`TB`,`BT`,`RL`,`LR`]),d=Object.freeze([`triangle`,`filledDiamond`,`hollowDiamond`,`arrow`,`circle`,`cross`]),f=Object.freeze({"<|":`triangle`,"|>":`triangle`,"*":`filledDiamond`,o:`hollowDiamond`,">":`arrow`,"<":`arrow`,"()":`circle`}),p=`#+~-`,m=(e,n,r,i,a,o,s=1)=>(0,t.error)(e,n,r,i,a,o,s),h=(e,t,n)=>m(e,t,`不支持或无效的类图语句:「${n}」`,`Unsupported or invalid class-diagram statement: "${n}"`,`使用 class、namespace、note、direction 或「A <|-- B : 标签」`,`Use class, namespace, note, direction, or "A <|-- B : label"`),g=e=>{let t=String(e??``).trim(),n=/^"([^"]*)"$/u.exec(t);return n?n[1]:/^`[^`]*`$/u.test(t)?t.slice(1,-1):t},_=String.raw`(?:\u0060[^\u0060]*\u0060|~[^~\s]*~|[\p{L}\p{N}\p{M}_$]|[-.](?![-.]))`,v=`${_}+`,y=String.raw`(?:<\|?|\|>|\(\s*\)|o|\*|>|<)`,b=RegExp(`^(?:${_})+`,`u`),x=RegExp(`^(${v})\\s*(?:"([^"]*)")?\\s*((?:${y})?(?:--|\\.\\.)(?:${y})?)\\s*(?:"([^"]*)")?\\s*(${v})(?:\\s*:\\s*(.+))?$`,`u`),S=RegExp(`^(?:(${y}))?(--|\\.\\.)(?:(${y}))?$`,`u`),C=RegExp(`^note\\s+for\\s+(${v})\\s+"([^"]*)"$`,`iu`),w=/^note\s+"([^"]*)"$/iu,T=/^class\s+(.+)$/iu,E=/^namespace\s+(.+)$/iu,D=RegExp(`^<<\\s*([^<>]+?)\\s*>>\\s+(${v})$`,`u`),O=/^<<\s*([^<>]+?)\s*>>/u,k=RegExp(`^(${v})\\s*:\\s*([\\s\\S]+)$`,`u`),A=RegExp(`^(${v})\\s*:::\\s*([\\w-]+(?:\\s*,\\s*[\\w-]+)*)$`,`u`),j=RegExp(`^(${v})$`,`u`),M=/^\[\s*"([^"]*)"\s*\]/u,N=/^:::\s*([\w-]+(?:\s*,\s*[\w-]+)*)/u,ee=RegExp(`\\bdirection\\s+(${u.join(`|`)})\\b`,`iu`),te=/^::icon\s*\(\s*([^()]+?)\s*\)/u,ne=/^acc(?:Title|Descr)\b/iu,P=/^([#+~-])?(.+)\((.*)\)([\s$*])?(.*)([$*])?$/u;function re(e){let t=``,n=!1;for(let r=0;r<e.length;r+=1){let i=e[r];if(n)i==="`"&&(n=!1);else if(i==="`")n=!0;else if(t)i===t&&(t=``);else if(i===`"`||i===`'`)t=i;else if(i===`%`&&e[r+1]===`%`)return e.slice(0,r)}return e}function ie(e,t){let n=``,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i];if(r)a==="`"&&(r=!1);else if(a==="`")r=!0;else if(n)a===n&&(n=``);else if(a===`"`||a===`'`)n=a;else if(t===`arrow`?(a===`-`||a===`.`)&&e[i+1]===a:a===t)return i}return-1}function F(e,t){return Array.isArray(e)?e.filter(e=>e&&typeof e.text==`string`).map(e=>({text:e.text,line:Number.isFinite(e.line)?e.line:t})):String(e??``).replace(/\r\n?/gu,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`).map((e,n)=>({text:e,line:t+n}))}function ae(e,t=0){let n=b.exec(e.slice(t));return n?{raw:n[0],next:t+n[0].length}:null}function I(e){let t=(String(e).startsWith("`")?String(e).slice(1,-1):String(e)).split(`~`);return{id:t[0],generic:t.length>1?t[1]:``}}var L=e=>Math.max(0,String(e).split(`~`).length-1);function R(e){let t=L(e);if(t<=1)return e;let n=e,r=!1;t%2!=0&&n.startsWith(`~`)&&(n=n.slice(1),r=!0);let i=[...n],a=i.indexOf(`~`),o=i.lastIndexOf(`~`);for(;a!==-1&&o!==-1&&a!==o;)i[a]=`<`,i[o]=`>`,a=i.indexOf(`~`),o=i.lastIndexOf(`~`);return r&&i.unshift(`~`),i.join(``)}function z(e){let t=String(e??``).split(/(,)/u),n=[];for(let e=0;e<t.length;e+=1){let r=t[e];r===`,`&&e>0&&e+1<t.length&&L(t[e-1])===1&&L(t[e+1])===1&&(r=`${t[e-1]},${t[e+1]}`,e+=1,n.pop()),n.push(R(r))}return n.join(``)}function B(e,t){return t===`*`?e.fontStyle=`italic`:t===`$`&&(e.decoration=`underline`),e}function V(e){let t=String(e).trim(),n=t.indexOf(`)`)>0?P.exec(t):null;if(n){let e=n[1]||``,t=String(n[2]).trim(),r=String(n[3]||``).trim(),i=String(n[4]||``).trim(),a=String(n[5]||``).trim();!i&&/[$*]$/u.test(a)&&(i=a.slice(-1),a=a.slice(0,-1));let o=`${e}${z(t)}(${z(r)})`;return{method:!0,item:B({text:(a?`${o} : ${z(a)}`:o).trim()},i)}}let r=t.length,i=p.includes(t[0]||``)?t[0]:``,a=/[$*]$/u.test(t)?t.slice(-1):``,o=t.slice(+!!i,a?r-1:r);return o=o.startsWith(` `)?` ${o.trim()}`:o.trim(),{method:!1,item:B({text:`${i}${z(o)}`.trim()},a)}}function H(e,t){if(!e||typeof e!=`object`||Array.isArray(e))return;let n=t.toLowerCase();for(let[t,r]of Object.entries(e))if(t.toLowerCase()===n)return r}function oe(e,t,n){let r=H(H(e,`class`),t);if(typeof r==`boolean`)return r;if(typeof r==`string`){let e=r.trim().toLowerCase();if(e===`true`)return!0;if(e===`false`)return!1}return n}function U(e,r={}){let i=r.lang||`zh`,a=r.firstLine||2,o=[],s=[];for(let e of Object.keys(r.options||{}))o.push(m(i,a-1,`类图不接受选项「${e}」`,`Class diagrams take no option: ${e}`,`把方向写成正文的 direction TB|BT|RL|LR`,`Write the direction as a body statement: direction TB|BT|RL|LR`));let c=oe(r.config,`hierarchicalNamespaces`,!0),u=oe(r.config,`hideEmptyMembersBox`,!1),d=[],p=new Map,_=new Map,v=[],y=[],b=(0,n.presentation)({lang:i,classKeyword:`cssClass`}),P=[],L=`TB`,R=null,B=!1,H=0,U=0,W=(e,t)=>{let n={id:e,label:e,generic:``,annotations:[],members:[],methods:[],parent:null,declared:!1,note:!1,hidden:!1,interface:!1,line:t};return p.set(e,n),d.push(n),n},G=(e,t)=>{let n=p.get(e.id)||W(e.id,t);return e.generic&&!n.generic&&(n.generic=e.generic),n},K=(e,t)=>{let n=G(e,t);return n.declared=!0,n.interface&&(n.interface=!1,n.hidden=!1),P.length&&(n.parent=P.at(-1)),n},q=(e,t)=>{let n=String(t).trim();if(!n||!e)return;if(n.startsWith(`<<`)&&n.endsWith(`>>`)){e.annotations.push({text:n.slice(2,-2).trim()});return}let r=V(n);(r.method?e.methods:e.members).push(r.item)},J=(e,t,n)=>{let r=P.length?`${P.at(-1)}.${e}`:e;P.push(r);let i=_.get(r);if(i){i.explicit=!0,t&&(i.label=t);return}let a=r.split(`.`);for(let e=1;e<=a.length;e+=1){let r=a.slice(0,e).join(`.`),i=e===a.length,o=e>1?a.slice(0,e-1).join(`.`):null,s=_.get(r);s?i&&(s.explicit=!0,t&&(s.label=t)):_.set(r,{id:r,label:i&&t?t:a[e-1],parent:o,depth:e-1,explicit:i,line:n})}},ce=e=>{let t=e;for(;t;){let e=_.get(t);if(!e)return null;if(e.explicit)return t;t=e.parent}return null},Y=(e,t,n)=>{for(;p.has(`note${U}`);)U+=1;let r=W(`note${U}`,n);return U+=1,Object.assign(r,{note:!0,label:e,parent:P.at(-1)||null}),t&&y.push({card:r,target:t,line:n}),r},X=(e,t)=>{if(!p.get(e)){let n=W(e,t);return Object.assign(n,{interface:!0,hidden:!0,parent:P.at(-1)||null}),n}for(;p.has(`interface${H}`);)H+=1;let n=W(`interface${H}`,t);return H+=1,Object.assign(n,{interface:!0,hidden:!0,label:e,parent:P.at(-1)||null}),n};for(let t of F(e,a)){let e=t.line,n=re(t.text).trim();if(!n)continue;if(B){n.includes(`}`)&&(B=!1);continue}if(/^accDescr\s*\{/iu.test(n)){B=!n.slice(n.indexOf(`{`)+1).includes(`}`);continue}if(R){let t=R,r=n;if(n.endsWith(`}`)&&(r=n.slice(0,-1),R=null),r.includes(`{`)){o.push(m(i,e,`类成员里不能再写 {`,`A class body has no nested {`,`把成员写在 class 块内的独立行上`,`Write members on their own lines inside the class block`));continue}q(t,r);continue}let r=ee.exec(n);if(r){L=r[1].toUpperCase();continue}if(n===`}`){P.length?P.pop():o.push(m(i,e,`多余的 }`,`Unmatched }`,`删掉这一行,或补上它对应的 namespace`,`Remove this line, or add the namespace it closes`));continue}let a=E.exec(n);if(a){let t=a[1].trim(),n=ae(t);if(!n){o.push(m(i,e,`namespace 后需要命名空间名称`,`A namespace needs a name`,`写成 namespace 名称 {`,`Write namespace name {`));continue}let r=I(n.raw).id;t=t.slice(n.next).trim();let s=M.exec(t),c=null;if(s&&(c=s[1],t=t.slice(s[0].length).trim()),t!==`{`){o.push(m(i,e,`命名空间后需要 {,块内容从下一行开始`,`A namespace opens with { and its body starts on the next line`,`写成 namespace 名称 { 再逐行写 class`,`Write namespace name { and put each class on its own line`));continue}J(r,c,e);continue}let s=T.exec(n);if(s){let t=s[1].trim(),r=ae(t);if(!r){o.push(m(i,e,`class 后需要类名`,`A class needs a name`,`写成 class 类名、class 类名["标签"] 或 class 类名 {`,`Write class Name, class Name["label"] or class Name {`));continue}let a=K(I(r.raw),e);t=t.slice(r.next).trim();let c=M.exec(t);if(c)a.label=c[1],t=t.slice(c[0].length).trim();else{let e=/^as\s+([\s\S]+)$/iu.exec(t);e&&(a.label=g(e[1]),t=``)}let l=null,u=null;for(;t=t.trim(),t;){let n=O.exec(t);if(n){a.annotations.push({text:n[1].trim()}),t=t.slice(n[0].length).trim();continue}let r=N.exec(t);if(r)b.addClasses(a.id,r[1].split(/\s*,\s*/u),e),t=t.slice(r[0].length).trim();else{if(t.startsWith(`{`)){l=t.slice(1);break}u=t;break}}if(u!==null){o.push(h(i,e,n));continue}if(l===null)continue;let d=l.trim();if(d.endsWith(`}`)){let e=d.slice(0,-1);e.trim()&&q(a,e)}else d&&q(a,d),R=a;continue}let c=D.exec(n);if(c){K(I(c[2]),e).annotations.push({text:c[1].trim()});continue}let l=C.exec(n);if(l){Y(l[2],I(l[1]).id,e);continue}let u=w.exec(n);if(u){Y(u[1],null,e);continue}if(/^note\b/iu.test(n)){o.push(m(i,e,`note 的文本需要写在双引号里`,`A note needs its text in double quotes`,`写成 note "文本" 或 note for 类名 "文本"`,`Write note "text" or note for Name "text"`));continue}if(b.accept(n,e))continue;let d=n.indexOf(`::icon`),p=d>0?te.exec(n.slice(d)):null;if(p&&d+p[0].length===n.length&&j.test(n.slice(0,d).trimEnd())){K(I(n.slice(0,d).trimEnd()),e).iconRef=p[1];continue}if(ne.test(n))continue;let _=ie(n,`arrow`),y=ie(n,`:`);if(_>=0&&(y<0||_<y)){let t=x.exec(n),r=t?S.exec(t[3]):null;if(!r){o.push(h(i,e,n));continue}let a=r[1]?String(r[1]).replace(/\s+/gu,``):``,s=r[3]?String(r[3]).replace(/\s+/gu,``):``,c=a?f[a]:void 0,l=s?f[s]:void 0;if(a&&!c||s&&!l){o.push(h(i,e,n));continue}let u=I(t[1]),d=I(t[5]),p=c===`circle`&&!l?X(u.id,e):G(u,e),m=l===`circle`&&!c?X(d.id,e):G(d,e);v.push({from:p.id,to:m.id,label:t[6]?t[6].trim():``,...r[2]===`..`?{dashed:!0}:{dashed:!1},...c?{start:c}:{},...l?{end:l}:{},...t[2]?{c1:t[2].trim()}:{},...t[4]?{c2:t[4].trim()}:{},line:e});continue}let F=A.exec(n);if(F){b.addClasses(K(I(F[1]),e).id,F[2].split(/\s*,\s*/u),e);continue}let z=k.exec(n);if(z){q(G(I(z[1]),e),z[2]);continue}let V=j.exec(n);V?K(I(V[1]),e):o.push(h(i,e,n))}R&&o.push(m(i,R.line,`class 块缺少结束的 }`,`A class block is missing its closing }`,`在块末尾补上 }`,`Add } at the end of the block`)),P.length&&o.push(m(i,_.get(P.at(-1))?.line??a,`namespace 块缺少结束的 }`,`A namespace block is missing its closing }`,`在块末尾补上 }`,`Add } at the end of the block`));for(let e of y){let n=p.get(e.target);n?v.push({from:e.card.id,to:n.id,label:``,dashed:!0,line:e.line}):s.push((0,t.warning)(`DIAGRAM_HINT`,i,e.line,`note for 指向的「${e.target}」不是任何类,这张注释没有连线`,`"${e.target}" is not a class, so this note stays unconnected`,`把 note for 后面的类名改成图中的类`,`Point note for at a class in the diagram`))}v.sort((e,t)=>e.line-t.line),d.length>l.large&&s.push((0,t.warning)(`LARGE_DIAGRAM`,i,d[0]?.line??a,`${d.length} 个类或注释,图会很大,建议拆分`,`${d.length} classes and notes; consider splitting this diagram`,`按命名空间拆成多张图,并用文字说明它们的对应关系`,`Split by namespace and describe the mapping in prose`)),d.length>l.cards&&o.push(m(i,d[l.cards].line,`类与注释最多 ${l.cards} 个`,`At most ${l.cards} classes and notes`,`拆成多张图`,`Split into several diagrams`)),v.length>l.edges&&o.push(m(i,v[l.edges].line,`关系最多 ${l.edges} 条`,`At most ${l.edges} relations`,`删掉次要关系,或拆成多张图`,`Remove secondary relations, or split into several diagrams`));let Z=e=>e.note||e.hidden||u&&!e.members.length&&!e.methods.length?[]:[e.members,e.methods],Q=e=>{let t=e.generic?z(e.generic):``;return t?`${e.label}<${t}>`:e.label},$=[];for(let e of _.values())(c||e.explicit)&&$.push({id:e.id,label:c?e.label:e.id,parent:c?e.parent:null,depth:c?e.depth:0,line:e.line});let le={kind:`classDiagram`,direction:L,cards:d.map(e=>{let t=e.parent?c?e.parent:ce(e.parent):null;return{id:e.id,title:e.note?e.label:Q(e),...e.annotations.length?{annotations:e.annotations.map(e=>({text:e.text}))}:{},sections:Z(e),...t?{parent:t}:{},...e.note?{note:!0}:{},...e.hidden?{hidden:!0}:{},...e.iconRef?{iconRef:e.iconRef}:{},line:e.line}}),frames:$,edges:v};return o.push(...se(le,b,i)),{errors:[...o,...s],warnings:[...s,...o.filter(e=>e.severity===`warning`)],model:le}}function se(e,n,a){let o=new Map,s=e=>{(o.get(e.message)?.line??1/0)>e.line&&o.set(e.message,e)},c=(e,t,n=e)=>{if(e[t]==null)return;let{text:i,icon:o,diagnostics:c}=(0,r.normalizeLabel)(e[t],{lang:a,line:n.line});e[t]=i,o&&(n.icon??=o),c.forEach(s)};for(let r of e.cards){let e=n.statusOf(r.id),o=n.linkOf(r.id);if(e&&(r.tone=e),o&&(r.link=o),r.iconRef){let e=r.iconRef,n=(0,i.resolveIconRef)(e);n?r.icon=n:s((0,t.warning)(`IGNORED_ASSET`,a,r.line,`未知图标 ${e}`,`Unknown icon ${e}`,`使用内置图标`,`Use a built-in icon`)),delete r.iconRef}c(r,`title`);for(let e of[...r.annotations||[],...r.sections.flat()])c(e,`text`,r)}for(let t of e.frames||[])c(t,`label`);for(let[t,r]of e.edges.entries()){let e=n.edgeStatusOf(t);e&&(r.tone=e);for(let e of[`label`,`c1`,`c2`])c(r,e)}return[...n.diagnostics(),...o.values()]}var W=(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,G=``,K=(e,t)=>t?`${G} ${e}`:e,q=(e,t)=>`uml-${e}${t?`-${t}`:``}`;function J(e,t,n,r,i){let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=14/Math.max(s,c);return e.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`},t.elements.map(({tag:n,attrs:r})=>e.shape(n,{...r,...t.set===`simple`?{fill:i}:{fill:`none`,stroke:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))}function ce(e,t,n){let r=t.surface,i={triangle:[`M2 2 L13 7 L2 12 Z`,r],hollowDiamond:[`M1 7 L7 2 L13 7 L7 12 Z`,r],filledDiamond:[`M1 7 L7 2 L13 7 L7 12 Z`,null],arrow:[`M4 3 L13 7 L4 11`,`none`],cross:[`M5 3 L13 11 M5 11 L13 3`,`none`]},a=new Map(n.flatMap(e=>[e.start,e.end].filter(Boolean).map(n=>[q(n,e.tone),{name:n,ink:t[e.tone]||t.fg4}])));return e.el(`defs`,{},[...a].map(([t,{name:n,ink:a}])=>{let o={stroke:a,"stroke-width":1.25},s=n===`contains`?[e.circle(8,7,4,{...o,fill:r}),e.path(`M4 7 H12 M8 3 V11`,{...o,fill:`none`})]:n===`circle`?[e.circle(7,7,5,{...o,fill:r})]:[e.path(i[n][0],{...o,fill:i[n][1]??a})];return e.el(`marker`,{id:t,viewBox:`0 0 14 14`,refX:n===`circle`?7:13,refY:7,markerWidth:14,markerHeight:14,markerUnits:`userSpaceOnUse`,orient:`auto-start-reverse`},s)}))}function Y(e,t,n,r){return e.split(`
|
|
4
|
-
`).flatMap(e=>{let i=e.split(r),a=[],o=i.shift();for(let e of i)o&&n(o+e)>t?(a.push(o.trimEnd()),o=e.trimStart()):o+=e;return[...a,o]})}function X(e){let t=new Map([...e.nodes,...e.frames].map(e=>[e.id,e.parent])),n=(e,n)=>{for(let r=t.get(n);r;r=t.get(r))if(r===e.id)return!0;return!1};for(let t of e.frames){let r={...t};for(let i of e.edges.filter(e=>n(t,e.from)||n(t,e.to)))for(let{p0:e,p1:n,c1:a,c2:o}of i.segments)for(let[i,s,c,l]of[[`x`,`y`,`w`,`h`],[`y`,`x`,`h`,`w`]]){let u=e[i];if(![n,a,o].every(e=>Math.abs(e[i]-u)<.1)||Math.min(Math.max(e[s],n[s]),r[s]+r[l])-Math.max(Math.min(e[s],n[s]),r[s])<16)continue;let d=r[i],f=d+r[c];if(Math.abs(u-d)<8){let e=Math.max(0,t[i]-u+8);t[i]-=e,t[c]+=e}Math.abs(u-f)<8&&(t[c]=Math.max(t[c],u+8-t[i]))}}}function Z(e,{ctx:n,width:r,lang:i,measure:s=(e,t)=>n.measure(e,t.size,t.weight)}){let{cards:c,frames:u=[],edges:d,direction:f}=e,p=e.type===`requirementDiagram`,m=(0,t.appearance)(n),h=new Map(c.map(e=>[e.id,e])),g=new Map,_=new Map(u.map(e=>[e.id,e])),v=new Map,y=new Map(u.map((e,t)=>{let r=K(e.label,e.icon),i=e=>e.startsWith(G)?18+n.measure(e.slice(1),13,600):n.measure(e,13,600),a=Y(r,332,i,/(?<=\.)/u),o=a.map((e,n)=>{if(!e)return``;let r=`\ue000${t}.${n}\ue001`;return v.set(r,Math.min(199,i(e))),r});return[e.id,{lines:a,slots:o,w:Math.max(...a.map(i))}]})),b=new Map;if(f===`TB`||f===`BT`){let e=new Set;for(let t of c)if(!t.hidden)for(let n=t.parent;n&&!e.has(n);n=_.get(n)?.parent){e.add(n);let{w:r}=y.get(n);r>199&&b.set(t.id,Math.max(b.get(t.id)||0,r+2))}}let x=c.map((e,r)=>{let i=(e,r=!1)=>e.flatMap(e=>(r?Y(e.text,328,e=>s(e,t.FONT.label),/(?<=,)|(?<=[^\s:])(?=\s*:(?!:))/u):n.wrap(e.text,172,t.FONT.label.size,t.FONT.label.weight)).map(t=>({...e,text:t}))),[a,...o]=e.sections,c=a?.[0]?.role===`stereotype`,l=i(c?a:(e.annotations||[]).map(e=>({...e,text:`«${e.text}»`}))),u=(c?o:e.sections).map(e=>i(e,!p)),d=e.title||`\xA0`,f=n.wrap(d,200,t.FONT.title.size,t.FONT.title.weight);g.set(e.id,{annotations:l,sections:u,lines:f});let m=[...l,...u.flat()],h=Math.max(64,b.get(e.id)||0,28+Math.max(0,...f.map(e=>s(e,t.FONT.title)),...m.map(e=>s(e.text,t.FONT.body)))),_=l.length+Number(!!e.icon)+u.reduce((e,t)=>e+Math.max(1,t.length),0),v=Math.max(40,20+f.length*19+(_?5+_*17:0));return{id:e.id,seq:r,label:d,parent:e.parent,...e.hidden?{kind:`start`}:{block:{w:h,h:v}}}}),
|
|
5
|
-
`)})),edges:d.map((e,t)=>({...e,seq:t,label:K(e.label,e.icon),style:e.dashed?`dashed`:`solid`,startArrow:!!e.start,endArrow:!!e.end}))},{lang:i,measure:(e,t)=>v.get(e)??(e.startsWith(G)?18+s(e.slice(1),t):s(e,t))});for(let e of
|
|
4
|
+
`).flatMap(e=>{let i=e.split(r),a=[],o=i.shift();for(let e of i)o&&n(o+e)>t?(a.push(o.trimEnd()),o=e.trimStart()):o+=e;return[...a,o]})}function X(e){let t=new Map([...e.nodes,...e.frames].map(e=>[e.id,e.parent])),n=(e,n)=>{for(let r=t.get(n);r;r=t.get(r))if(r===e.id)return!0;return!1};for(let t of e.frames){let r={...t};for(let i of e.edges.filter(e=>n(t,e.from)||n(t,e.to)))for(let{p0:e,p1:n,c1:a,c2:o}of i.segments)for(let[i,s,c,l]of[[`x`,`y`,`w`,`h`],[`y`,`x`,`h`,`w`]]){let u=e[i];if(![n,a,o].every(e=>Math.abs(e[i]-u)<.1)||Math.min(Math.max(e[s],n[s]),r[s]+r[l])-Math.max(Math.min(e[s],n[s]),r[s])<16)continue;let d=r[i],f=d+r[c];if(Math.abs(u-d)<8){let e=Math.max(0,t[i]-u+8);t[i]-=e,t[c]+=e}Math.abs(u-f)<8&&(t[c]=Math.max(t[c],u+8-t[i]))}}}function Z(e,{ctx:n,width:r,lang:i,measure:s=(e,t)=>n.measure(e,t.size,t.weight)}){let{cards:c,frames:u=[],edges:d,direction:f}=e,p=e.type===`requirementDiagram`,m=(0,t.appearance)(n),h=new Map(c.map(e=>[e.id,e])),g=new Map,_=new Map(u.map(e=>[e.id,e])),v=new Map,y=new Map(u.map((e,t)=>{let r=K(e.label,e.icon),i=e=>e.startsWith(G)?18+n.measure(e.slice(1),13,600):n.measure(e,13,600),a=Y(r,332,i,/(?<=\.)/u),o=a.map((e,n)=>{if(!e)return``;let r=`\ue000${t}.${n}\ue001`;return v.set(r,Math.min(199,i(e))),r});return[e.id,{lines:a,slots:o,w:Math.max(...a.map(i))}]})),b=new Map;if(f===`TB`||f===`BT`){let e=new Set;for(let t of c)if(!t.hidden)for(let n=t.parent;n&&!e.has(n);n=_.get(n)?.parent){e.add(n);let{w:r}=y.get(n);r>199&&b.set(t.id,Math.max(b.get(t.id)||0,r+2))}}let x=(e,t,n)=>!p&&e.length&&t<n.length-1?5:0,S=c.map((e,r)=>{let i=(e,r=!1)=>e.flatMap(e=>(r?Y(e.text,328,e=>s(e,t.FONT.label),/(?<=,)|(?<=[^\s:])(?=\s*:(?!:))/u):n.wrap(e.text,172,t.FONT.label.size,t.FONT.label.weight)).map(t=>({...e,text:t}))),[a,...o]=e.sections,c=a?.[0]?.role===`stereotype`,l=i(c?a:(e.annotations||[]).map(e=>({...e,text:`«${e.text}»`}))),u=(c?o:e.sections).map(e=>i(e,!p)),d=e.title||`\xA0`,f=n.wrap(d,200,t.FONT.title.size,t.FONT.title.weight);g.set(e.id,{annotations:l,sections:u,lines:f});let m=[...l,...u.flat()],h=Math.max(64,b.get(e.id)||0,28+Math.max(0,...f.map(e=>s(e,t.FONT.title)),...m.map(e=>s(e.text,t.FONT.body)))),_=l.length+Number(!!e.icon)+u.reduce((e,t)=>e+Math.max(1,t.length),0),v=Math.max(40,20+f.length*19+(_?5+_*17:0)+u.reduce((e,t,n)=>e+x(t,n,u),0));return{id:e.id,seq:r,label:d,parent:e.parent,...e.hidden?{kind:`start`}:{block:{w:h,h:v}}}}),C=(0,a.layoutGraph)({type:`flowchart`,direction:f,nodes:S,subgraphs:u.map((e,t)=>({...e,seq:t,title:y.get(e.id).slots.join(`
|
|
5
|
+
`)})),edges:d.map((e,t)=>({...e,seq:t,label:K(e.label,e.icon),style:e.dashed?`dashed`:`solid`,startArrow:!!e.start,endArrow:!!e.end}))},{lang:i,measure:(e,t)=>v.get(e)??(e.startsWith(G)?18+s(e.slice(1),t):s(e,t))});for(let e of C.frames){let t=y.get(e.id),n=e.titleRect;t&&n&&(e.lines=t.lines,n.w=t.w,e.w=Math.max(e.w,n.x-e.x+n.w+14))}X(C);for(let e of C.frames)C.width=Math.max(C.width,e.x+e.w+8),C.height=Math.max(C.height,e.y+e.h+8);let w=(e,t,r,i={})=>n.text(e,t,r,{"dominant-baseline":`central`,fill:m.fg3,...i}),T=[],E=[],D=[],O=[],k=[],A=[...C.nodes,...C.frames.map(e=>e.titleRect).filter(Boolean),...C.edges.map(e=>e.labelRect).filter(Boolean)],j=C.edges.flatMap(e=>e.segments.map(({p0:e,c1:t,c2:n,p1:r})=>{let i=[e.x,t.x,n.x,r.x],a=[e.y,t.y,n.y,r.y],o=Math.min(...i),s=Math.min(...a);return{x:o-1,y:s-1,w:Math.max(...i)-o+2,h:Math.max(...a)-s+2}})),M=e=>!A.some(t=>W(e,t))&&!j.some(t=>W(e,t));for(let e of C.frames){if(T.push(n.rect(e.x,e.y,e.w,e.h,{rx:7,fill:m.surface,stroke:m.line2,meta:{kind:`frame`,id:e.id}})),!e.titleRect)continue;let t=e.titleRect;E.push(n.rect(t.x-3,t.y,t.w+6,t.h,{rx:3,fill:m.surface})),e.lines.forEach((r,i)=>{let a=t.y+(i+.5)*17,o=_.get(e.id)?.icon;o&&r.startsWith(G)?(E.push(J(n,o,t.x+7,a,m.fg3)),E.push(w(t.x+18,a,r.slice(1).trimStart(),{size:13,weight:600}))):E.push(w(t.x,a,r,{size:13,weight:600}))})}for(let e of C.edges){if(!e.segments?.length)continue;let t=d[e.id];D.push(n.path((0,o.cubicPath)(e.segments),{fill:`none`,stroke:m[t.tone]||m.fg4,"stroke-width":1.25,"stroke-dasharray":t.dashed?`5 4`:null,"marker-start":t.start?`url(#${q(t.start,t.tone)})`:null,"marker-end":t.end?`url(#${q(t.end,t.tone)})`:null,meta:{kind:`edge`,from:t.from,to:t.to}}));let r=e.labelRect;if(r&&e.labelLines.length){let i=[n.rect(r.x,r.y,r.w,r.h,{rx:4,fill:m.surface,stroke:m.line1,"stroke-width":.6})];e.labelLines.forEach((a,o)=>{let s=r.x+r.w/2,c=r.y+r.h/2+(o-(e.labelLines.length-1)/2)*16;if(t.icon&&a.startsWith(G)){let e=a.slice(1).trimStart(),r=s-(n.measure(e,12,400)+18)/2;i.push(J(n,t.icon,r+7,c,m.fg3)),e&&i.push(w(r+18,c,e,{size:12}))}else i.push(w(s,c,a,{size:12,anchor:`middle`}))}),k.push({...n.el(`g`,{},i),meta:{kind:`edge-label-group`,from:t.from,to:t.to}})}for(let[r,i]of[[t.c1,!0],[t.c2,!1]]){if(!r)continue;let t=i?e.segments[0]:e.segments.at(-1),a=i?t.p0:t.p1,o=i?t.c1||t.p1:t.c2||t.p0,s=Math.abs(o.y-a.y)>=Math.abs(o.x-a.x),c=Math.sign(s?o.y-a.y:o.x-a.x)||1,l=n.measure(r,12,400),u;for(let e of[10,18,26,36,48]){for(let t of i?[-1,1]:[1,-1]){let n=s?{x:a.x+(t<0?-8-l:8),y:a.y+c*e-7,w:l,h:14}:{x:a.x+(c<0?-e-l:e),y:a.y+t*12-7,w:l,h:14};if(u=n,M(n))break}if(M(u))break}A.push(u),k.push(w(u.x,u.y+7,r,{size:12,meta:{kind:`cardinality`,endpoint:i?`start`:`end`}}))}}for(let e of C.nodes){let r=h.get(e.id);if(r.hidden)continue;let{x:i,y:a,w:o,h:s}=e,{annotations:c,sections:l,lines:u}=g.get(e.id),d=r.tone?m[r.tone]:m.line2,f=r.tone&&r.tone!==`ext`?n.mix(m.node,d,m.soft):m.node,_=p||r.note?`start`:`middle`,v=_===`start`?i+14:i+o/2,y=20+(c.length+Number(!!r.icon))*17+u.length*19,b=[];b.push(n.rect(i,a,o,s,{rx:7,fill:f,stroke:d,"stroke-width":1.25,"stroke-dasharray":r.tone===`ext`?`4 3`:void 0,meta:{kind:`node`,id:r.id,...r.tone?{status:r.tone}:{}}})),l.length&&b.push(n.rect(i+1,a+1,o-2,y-1,{rx:6,fill:r.tone&&r.tone!==`ext`?n.mix(m.node,d,Math.max(.2,m.soft)):m.line1,"fill-opacity":r.tone&&r.tone!==`ext`?1:.3}));let S=a+10;r.icon&&(b.push(J(n,r.icon,v+(_===`start`?7:0),S+8.5,d)),S+=17);let C=(e,n,r,i)=>b.push(w(n,r,e.text,{size:t.FONT.label.size,"font-style":e.fontStyle,"text-decoration":e.decoration,...i}));for(let e of c)C(e,v,S+8.5,{anchor:_}),S+=17;for(let e of u)b.push(w(v,S+9.5,e,{...t.FONT.title,...r.note?{weight:400}:{},anchor:_,fill:m.fg1})),S+=19;S+=10;for(let[e,t]of l.entries()){b.push(n.line(i+(e?9:0),S,i+o-(e?9:0),S,{stroke:m.line2,"stroke-width":.7}));for(let[e,n]of t.entries())C(n,i+14,S+11+e*17,{});S+=Math.max(1,t.length)*17+x(t,e,l)}r.link?O.push(n.link(r.link.href,b,r.link)):O.push(...b)}for(let e of C.edges)for(let[t,n,r,i]of[[e.from,d[e.id].start,e.start,e.end],[e.to,d[e.id].end,e.end,e.start]]){let e=h.get(t);if(n!==`circle`||!e?.hidden||!r||!i)continue;let a=f===`LR`||f===`RL`,o=(a?r.x-i.x:r.y-i.y)>=0?1:-1;k.push(w(r.x+(a?o*11:0),r.y+(a?0:o*14),e.title,{size:12,anchor:a?o>0?`start`:`end`:`middle`}))}let N=C.width>2*r&&c.length<=l.large?[(0,t.warning)(`LARGE_DIAGRAM`,i,1,`图较宽,将横向滚动`,`This diagram is wide and will scroll horizontally`,`考虑拆分成多张图`,`Consider splitting it into several diagrams`)]:[],ee={width:C.width,height:C.height,title:e.title||e.kind||e.type,heading:e.title,children:[ce(n,m,d),...T,...D,...O,...k,...E]};return{width:C.width,height:C.height,geometry:C,scene:ee,errors:N}}var Q={parse:U,layout:Z,acceptsPresentation:!0,honoredConfig:[`class.hideEmptyMembersBox`,`class.hierarchicalNamespaces`]},$={classDiagram:Q};return e.arrowMarkers=f,e.directions=u,e.finishCards=se,e.implementation=Q,e.implementations=$,e.kind=s,e.kinds=c,e.layoutCards=Z,e.limits=l,e.markers=d,e.parse=U,e.parseClass=U,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/label`],KChartUnits[`core/icons`],KChartUnits[`diagram/graph-layout`],KChartUnits[`core/geometry`]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
KChartUnits["diagram/cynefin"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=[`complex`,`complicated`,`clear`,`chaotic`,`confusion`],o=[`complex`,`complicated`,`chaotic`,`clear`],s={complex:[0,0],complicated:[1,0],chaotic:[0,1],clear:[1,1]},c={complex:`Complex`,complicated:`Complicated`,chaotic:`Chaotic`,clear:`Clear`,confusion:`Confusion`},l={complex:[`Probe → Sense → Respond`,`Emergent Practices`],complicated:[`Sense → Analyse → Respond`,`Good Practices`],clear:[`Sense → Categorise → Respond`,`Best Practices`],chaotic:[`Act → Sense → Respond`,`Novel Practices`],confusion:[``,`Disorder`]},u={complex:`复杂`,complicated:`繁杂`,chaotic:`混乱`,clear:`清晰`,confusion:`困惑`},d={complex:[`探测 → 感知 → 响应`,`涌现实践`],complicated:[`感知 → 分析 → 响应`,`良好实践`],clear:[`感知 → 分类 → 响应`,`最佳实践`],chaotic:[`行动 → 感知 → 响应`,`新颖实践`],confusion:[``,`失序`]},f={complex:`tone1`,complicated:`tone2`,chaotic:`tone3`,clear:`tone4`,confusion:`tone5`},p=24,m=20,h=14,g=640,_=960,v=22,y=46,b=18,x=18,S=10,C=10,w=24,ee=15,T=4,te=190,E=4,D=16,O=.12,
|
|
1
|
+
KChartUnits["diagram/cynefin"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=[`complex`,`complicated`,`clear`,`chaotic`,`confusion`],o=[`complex`,`complicated`,`chaotic`,`clear`],s={complex:[0,0],complicated:[1,0],chaotic:[0,1],clear:[1,1]},c={complex:`Complex`,complicated:`Complicated`,chaotic:`Chaotic`,clear:`Clear`,confusion:`Confusion`},l={complex:[`Probe → Sense → Respond`,`Emergent Practices`],complicated:[`Sense → Analyse → Respond`,`Good Practices`],clear:[`Sense → Categorise → Respond`,`Best Practices`],chaotic:[`Act → Sense → Respond`,`Novel Practices`],confusion:[``,`Disorder`]},u={complex:`复杂`,complicated:`繁杂`,chaotic:`混乱`,clear:`清晰`,confusion:`困惑`},d={complex:[`探测 → 感知 → 响应`,`涌现实践`],complicated:[`感知 → 分析 → 响应`,`良好实践`],clear:[`感知 → 分类 → 响应`,`最佳实践`],chaotic:[`行动 → 感知 → 响应`,`新颖实践`],confusion:[``,`失序`]},f={complex:`tone1`,complicated:`tone2`,chaotic:`tone3`,clear:`tone4`,confusion:`tone5`},p=24,m=20,h=14,g=640,_=960,v=22,y=46,b=18,x=18,S=10,C=10,w=24,ee=15,T=4,te=190,E=4,D=16,O=.12,k=12,A=16,ne=200,re=60;new Set(a);var ie=/^(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)')/,j=/\\(["'\\])/g;function M(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]===`%`)return e.slice(0,n)}return e}function N(e){let t=[],n=String(e??``);for(;;){let e=ie.exec(n);if(!e)break;t.push((e[1]??e[2]??``).replace(j,`$1`)),n=n.slice(e[0].length)}return{items:t,rest:n.trim()}}function P(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=Object.fromEntries(a.map(e=>[e,[]])),d=[],f=(0,r.presentation)({lang:o}),p={kind:`cynefin-beta`,title:``,accTitle:``,accDescr:``,domains:u,transitions:d,showDomainDescriptions:t.config?.cynefin?.showDomainDescriptions!==!1},m=new Set,h=(e,t)=>{let r=(0,n.normalizeLabel)(e,{lang:o,line:t});for(let e of r.diagnostics)m.has(e.message)||(m.add(e.message),l.push(e));return{label:r.text,icon:r.icon}},g=(e,t)=>(0,i.error)(o,t,`未知的 Cynefin 域「${e}」`,`Unknown Cynefin domain "${e}"`,`使用 ${a.join(` / `)}`,`Use one of ${a.join(` / `)}`),_=(e,t)=>{p.title?l.push((0,i.error)(o,t,`标题重复`,`Duplicate title`,`只保留一个 title`,`Keep only one title`)):p.title=h(e.trim(),t).label},v=String(t.params??``).replace(/^:/,``).trim();if(v){let e=/^title\b\s*([\s\S]*)$/i.exec(v);e?_(e[1],c):l.push((0,i.error)(o,c,`标题行之后多出「${v}」`,`Unexpected text after the header: "${v}"`,`把标题写成单独一行 title …`,`Put the title on its own line`))}let y=null,b=null;for(let[t,n]of String(e??``).split(`
|
|
2
2
|
`).entries()){let e=s+t,r=M(n).trim();if(b){b.lines.push(r),/}/.test(r)&&(p.accDescr=(0,i.labelText)(b.lines.join(`
|
|
3
3
|
`).replace(/}\s*$/,``).trim()),b=null);continue}if(!r||f.accept(r,e))continue;let c=/^accTitle\s*:\s*([\s\S]*)$/i.exec(r);if(c){p.accTitle=(0,i.labelText)(c[1].trim());continue}let m=/^accDescr\s*:\s*([\s\S]*)$/i.exec(r);if(m){p.accDescr=(0,i.labelText)(m[1].trim());continue}let v=/^accDescr\s*\{([\s\S]*)$/i.exec(r);if(v){/}/.test(v[1])?p.accDescr=(0,i.labelText)(v[1].replace(/}[\s\S]*$/,``).trim()):b={lines:[v[1]]};continue}let x=/^title\b\s*([\s\S]*)$/i.exec(r);if(x){_(x[1],e);continue}if(/^[A-Za-z]+\s*[-=.][-=>=.]*\s*>/.test(r)){let t=/^([A-Za-z]+)\s*-->\s*([A-Za-z]+)\s*(?::\s*([\s\S]*))?$/.exec(r);if(!t){l.push((0,i.error)(o,e,`只支持 --> 转移箭头`,`Only --> transitions are supported`,`把转移写成 complex --> clear`,`Write the transition as complex --> clear`));continue}let n=a.find(e=>e===t[1].toLowerCase()),s=a.find(e=>e===t[2].toLowerCase());if(!n){l.push(g(t[1],e));continue}if(!s){l.push(g(t[2],e));continue}let c=``;if(t[3]!==void 0){let n=N(t[3]);if(!n.items.length){l.push((0,i.error)(o,e,`转移标签必须使用引号`,`Expected a quoted transition label`,`把标签写成 : "文本"`,`Write the label as : "text"`));continue}if(n.rest){l.push((0,i.error)(o,e,`转移标签后多出「${n.rest}」`,`Unexpected text after the transition label: "${n.rest}"`,`一个转移只写一个引号标签`,`Use one quoted label per transition`));continue}c=h(n.items[0],e).label}if(n===s){l.push((0,i.warning)(`DIAGRAM_HINT`,o,e,`自环转移「${n}」已省略`,`The self-loop on "${n}" was dropped`,`删除自环;域不能转移到自身`,`Remove the self-loop; a domain cannot transition to itself`));continue}d.push({from:n,to:s,label:c,line:e});continue}let S=/^([A-Za-z]+)([\s\S]*)$/.exec(r),C=S&&a.find(e=>e===S[1].toLowerCase());if(C){y=C;let t=N(S[2]);t.rest&&l.push((0,i.error)(o,e,`域「${C}」之后多出「${t.rest}」`,`Unexpected text after domain "${C}": "${t.rest}"`,`每个条目写成一行引号字符串`,`Put each item on its own line as a quoted string`));for(let n of t.items)u[C].push({...h(n,e),line:e});continue}if(!y){l.push(g(S?S[1]:r,e));continue}let w=N(r);if(!w.items.length)l.push((0,i.error)(o,e,`域条目必须是引号字符串`,`Expected a quoted string for a domain item`,`把条目写成 "文本"`,`Wrap the item in quotes`));else if(w.rest)l.push((0,i.error)(o,e,`条目之后多出「${w.rest}」`,`Unexpected text after the item: "${w.rest}"`,`每个条目只写一个引号字符串`,`Use one quoted string per item`));else for(let t of w.items)u[y].push({...h(t,e),line:e})}b&&(l.push((0,i.error)(o,s,`accDescr 缺少结束的 }`,`accDescr is missing its closing }`,`补齐 accDescr 的右花括号`,`Close the accDescr block`)),p.accDescr=(0,i.labelText)(b.lines.join(`
|
|
4
|
-
`).trim())),l.push(...f.diagnostics()),d.forEach((e,t)=>{e.status=f.edgeStatusOf(t)});for(let e of a)u[e].forEach((t,n)=>{t.id=`${e}-${n}`,t.status=f.statusOf(t.id)??f.statusOf(e),t.link=f.linkOf(t.id)??f.linkOf(e)});return{model:p,errors:l}}var F=(e,t,n)=>Math.min(n,Math.max(t,e)),I=e=>e.ellipse?{x:e.cx,y:e.cy}:{x:e.x+e.w/2,y:e.y+e.h/2};function ae(e,t){let n=I(e),r=I(t);if(e.ellipse){let t=Math.atan2((r.y-e.cy)/e.ry,(r.x-e.cx)/e.rx),n=Math.cos(t),i=Math.sin(t);return{x:e.cx+(e.rx+8)*n,y:e.cy+(e.ry+8)*i}}let i=r.x-n.x,a=r.y-n.y;return Math.abs(i)>=Math.abs(a)?{x:i>=0?e.x+e.w+D:e.x-D,y:n.y}:{x:n.x,y:a>=0?e.y+e.h+D:e.y-D}}function oe(e,t,n,r,i){let a=t.x-e.x,o=t.y-e.y,s=Math.hypot(a,o)||1,c=-o/s,l=a/s,u={x:(e.x+t.x)/2,y:(e.y+t.y)/2},d=(u.x-n.x)*c+(u.y-n.y)*l>=0?1:-1,f=a=>{for(let o=0;o<=20;o+=1){let s=o/20,c=1-s,l=c*c*e.x+2*c*s*a.x+s*s*t.x,u=c*c*e.y+2*c*s*a.y+s*s*t.y;if(Math.hypot((l-n.x)/r,(u-n.y)/i)<1.12)return!1}return!0},p=Math.max(
|
|
4
|
+
`).trim())),l.push(...f.diagnostics()),d.forEach((e,t)=>{e.status=f.edgeStatusOf(t)});for(let e of a)u[e].forEach((t,n)=>{t.id=`${e}-${n}`,t.status=f.statusOf(t.id)??f.statusOf(e),t.link=f.linkOf(t.id)??f.linkOf(e)});return{model:p,errors:l}}var F=(e,t,n)=>Math.min(n,Math.max(t,e)),I=e=>e.ellipse?{x:e.cx,y:e.cy}:{x:e.x+e.w/2,y:e.y+e.h/2};function ae(e,t){let n=I(e),r=I(t);if(e.ellipse){let t=Math.atan2((r.y-e.cy)/e.ry,(r.x-e.cx)/e.rx),n=Math.cos(t),i=Math.sin(t);return{x:e.cx+(e.rx+8)*n,y:e.cy+(e.ry+8)*i}}let i=r.x-n.x,a=r.y-n.y;return Math.abs(i)>=Math.abs(a)?{x:i>=0?e.x+e.w+D:e.x-D,y:n.y}:{x:n.x,y:a>=0?e.y+e.h+D:e.y-D}}function oe(e,t,n,r,i){let a=t.x-e.x,o=t.y-e.y,s=Math.hypot(a,o)||1,c=-o/s,l=a/s,u={x:(e.x+t.x)/2,y:(e.y+t.y)/2},d=(u.x-n.x)*c+(u.y-n.y)*l>=0?1:-1,f=a=>{for(let o=0;o<=20;o+=1){let s=o/20,c=1-s,l=c*c*e.x+2*c*s*a.x+s*s*t.x,u=c*c*e.y+2*c*s*a.y+s*s*t.y;if(Math.hypot((l-n.x)/r,(u-n.y)/i)<1.12)return!1}return!0},p=Math.max(k,s*O),m={x:u.x+c*p*d,y:u.y+l*p*d},h=s*1.4+240;for(;!f(m)&&p<h;)p+=8,m={x:u.x+c*p*d,y:u.y+l*p*d};let g={x:(e.x+2*m.x+t.x)/4,y:(e.y+2*m.y+t.y)/4};return{a:e,b:t,ctrl:m,away:d,nx:c,ny:l,apex:g,offset:p}}function L(e,t={}){let n=t.measure||i.fallbackMeasure,r=Math.max(1,Number(t.width)||800),C=t.lang||`zh`,D=(0,i.isEn)(C)?c:u,O=(0,i.isEn)(C)?l:d,k=[],ie=(e,t)=>Math.max(0,n(e,t.size,t.weight)),j=(e,t,r)=>(0,i.wrapText)(e,t,r,(e,t)=>n(e,t)),M=t.compact===!0,N={size:M?13:i.FONT.title.size,weight:i.FONT.title.weight},P={size:i.FONT.label.size,weight:i.FONT.label.weight},I=(e,t)=>Math.ceil(Math.max(0,...e.map(e=>ie(e,t)))),L=e.title?j(e.title,Math.max(160,Math.min(640,r-48)),N):[],se=!t.embedHeading&&L.length?L.length*m+h:0,ce=a.reduce((t,n)=>t+e.domains[n].length,0),le=e.transitions.some(e=>e.label)?104:0,R=M?Math.min(_,Math.max(480,440+ce*14)+le):F(r-48,g,_),ue=Math.max(96,Math.min(te,R/2-44-8)),de=(e,t,n)=>{let r=j(e,t,P);return{lines:r,w:I(r,P)+20+(n?18:0),h:Math.max(w,r.length*ee+12)}},z={},B=0;for(let t of o){let n=e.domains[t];B+=n.length;let r=n.map((e,n)=>({...e,id:`${t}-${n}`,line:e.line,...de(e.label,ue,e.icon)}));n.length>E&&k.push((0,i.warning)(`DIAGRAM_HINT`,C,n[E].line,`「${D[t]}」有 ${n.length} 个条目,面板会变高`,`"${D[t]}" holds ${n.length} items and makes a tall panel`,`每个域保留 ${E} 个条目以内`,`Keep at most ${E} items per domain`));let a=e.showDomainDescriptions?O[t]:[O[t][1]],o=Math.ceil(Math.max(I([D[t]],N),I(a,P),...r.map(e=>e.w),0)),s=r.reduce((e,t)=>e+t.h+T,-4);z[t]={id:t,subs:a,chips:r,w:o,h:24+a.length*x+(r.length?S+s:0),tone:f[t],count:n.length}}let fe=Math.max(...o.map(e=>z[e].h)),V=e.domains.confusion;B+=V.length;let pe=Math.max(80,R*.15*2-56),H=V.map((e,t)=>({...e,id:`confusion-${t}`,line:e.line,...de(e.label,pe,e.icon)})),me=H.reduce((e,t)=>e+t.h+T,-4),he=24+(e.showDomainDescriptions?x:0)+(H.length?S+me:0),ge=Math.max(0,...H.map(e=>e.w))/2,U=Math.max(R*.15,Math.ceil(ge*(M?1.5:1))+18),_e=he*.68+12,W=Math.ceil(Math.max(F(R*.72,380,620),2*(v+fe+y),2*(_e+y))),G=Math.max(W*.15,_e),ve=R/2,ye=W/2,K=p,q=p+se,J={x:K+R/2,y:q+W/2},be=Math.max(z.chaotic.h,z.clear.h),Y={};for(let e of o){let[t,n]=s[e],r={x:K+t*ve,y:q+n*ye,w:ve,h:ye},i=z[e],a=r.x+(r.w-i.w)/2+(M&&H.length?t===0?-12:12:0),o=n===0?r.y+v:r.y+r.h-v-be,c=[],l=o;c.push({kind:`name`,text:D[e],x:a+i.w/2,y:l+b/2,font:N}),l+=24;for(let e of i.subs)c.push({kind:`sub`,text:e,x:a+i.w/2,y:l+x/2,font:P}),l+=x;i.chips.length&&(l+=S);for(let e of i.chips)e.x=a+(i.w-e.w)/2,e.y=l,l+=e.h+T;Y[e]={...i,...r,row:n,blockX:a,blockY:o,content:{x:a,y:o,w:i.w,h:i.h},texts:c}}let X=[];{let t=J.y-he/2;X.push({kind:`name`,text:D.confusion,x:J.x,y:t+b/2,font:N}),t+=24,e.showDomainDescriptions&&(X.push({kind:`sub`,text:O.confusion[1],x:J.x,y:t+x/2,font:P}),t+=x),t+=S;for(let e of H)e.x=J.x-e.w/2,e.y=t,t+=e.h+T}let Z={...Object.fromEntries(o.map(e=>[e,Y[e].content])),confusion:{ellipse:!0,cx:J.x,cy:J.y,rx:U,ry:G}},xe=[];for(let t of e.transitions){let e=oe(ae(Z[t.from],Z[t.to]),ae(Z[t.to],Z[t.from]),J,U,G),n=null;if(t.label){let r=j(t.label,Math.max(96,Math.min(ne,R-80)),P),i=I(r,P)+16,a=r.length*A+6,s=F(e.apex.x+e.nx*e.away*16-i/2,30,K+R-6-i),c=F(e.apex.y+e.ny*e.away*16-a/2,q+6,q+W-6-a);if(n={lines:r,x:s,y:c,w:i,h:a},M){let e=[...o.map(e=>Y[e].content),...xe.map(e=>e.label).filter(Boolean)],t=(t,n)=>{let r=Math.max(t-J.x,J.x-t-i,0),o=Math.max(n-J.y,J.y-n-a,0);return(r/U)**2+(o/G)**2>1&&!e.some(e=>t<e.x+e.w+4&&t+i+4>e.x&&n<e.y+e.h+4&&n+a+4>e.y)};if(!t(s,c))outer:for(let e of[12,24,36,48])for(let[r,o]of[[0,1],[0,-1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]){let l=F(s+r*e,30,K+R-6-i),u=F(c+o*e,q+6,q+W-6-a);if(t(l,u)){n={...n,x:l,y:u};break outer}}}}xe.push({...t,...e,label:n})}if(B>re){let t=e.transitions[0]?.line||V[0]?.line||1;k.push((0,i.warning)(`LARGE_DIAGRAM`,C,t,`Cynefin 图有 ${B} 个条目,建议拆分`,`The Cynefin map holds ${B} items; consider splitting it`,`按域拆成多张图`,`Split the map by domain`))}let Q=Math.ceil(R+48),$=Math.ceil(q+W+p);if(B<=re&&(Q>r*2||$>r*2)){let e=V[0]?.line||1;k.push((0,i.warning)(`LARGE_DIAGRAM`,C,e,`Cynefin 图需要 ${Q}×${$}px,超过图框两倍`,`The Cynefin map needs ${Q}×${$}px, more than twice the frame`,`加宽图框,或减少域条目`,`Widen the frame, or trim the domain items`))}return{width:Q,height:$,compact:M,title:L.length?{lines:L,x:K+R/2,top:34}:null,...t.embedHeading?{embedHeading:!0,heading:e.title}:{},plot:{x:K,y:q,w:R,h:W},centre:J,rx:U,ry:G,quadrants:o.map(e=>Y[e]),confusion:{texts:X,chips:H},arcs:xe,errors:k,anchor:{x:J.x,y:J.y}}}var se=(e,t,n,r)=>e.path(t,{...n,...r?{meta:r}:{}});function ce(e,n){let r=(0,i.appearance)(n),a=n.color(`bg`),o=n.design,s=e=>n.frameTone(n.color(f[e])),c=[],l=(e,t,r,i,a,o=`middle`)=>n.text(i,a,e,{anchor:o,size:t.size,weight:t.weight,fill:r,"dominant-baseline":`central`}),u={tag:`marker`,attrs:{id:`cynefin-arrow`,viewBox:`0 0 8 8`,refX:7,refY:4,markerWidth:8,markerHeight:8,markerUnits:`userSpaceOnUse`,orient:`auto`},children:[n.path(`M0 0 L8 4 L0 8 Z`,{fill:o.fg4})]};c.push(n.el(`defs`,{},[u]));for(let t of e.quadrants){let e=s(t.id);c.push(n.rect(t.x,t.y,t.w,t.h,{rx:8,fill:n.tint(a,e,.07),stroke:n.tint(a,e,.35),"stroke-width":1,meta:{kind:`frame`,id:t.id}}))}let{x:d,y:p,w:h,h:g}=e.plot,_=e.centre.y,v=e.centre.x,y=e.rx+12,b=e.ry+12;c.push(n.line(d,_,v-y,_,{stroke:n.color(`axis`),"stroke-width":2,"stroke-linecap":`round`})),c.push(n.line(v+y,_,d+h,_,{stroke:n.color(`axis`),"stroke-width":2,"stroke-linecap":`round`})),c.push(n.line(v,p,v,_-b,{stroke:n.color(`axis`),"stroke-width":2,"stroke-linecap":`round`})),c.push(n.line(v,_+b,v,p+g,{stroke:o.danger,"stroke-width":3,"stroke-linecap":`round`})),c.push({...n.el(`ellipse`,{cx:e.centre.x,cy:e.centre.y,rx:e.rx,ry:e.ry,fill:n.tint(a,s(`confusion`),.08),stroke:o.fg4,"stroke-width":1.5,"stroke-dasharray":`4 3`}),meta:{kind:`frame`,id:`confusion`}});for(let t of e.quadrants)for(let e of t.texts)c.push(l(e.text,e.font,e.kind===`name`?o.fg1:n.color(`muted`),e.x,e.y));for(let t of e.confusion.texts)c.push(l(t.text,t.font,t.kind===`name`?o.fg1:n.color(`muted`),t.x,t.y));let x=(e,a={})=>n.el(`g`,{},[n.rect(e.x,e.y,e.w,e.h,{rx:r.smallRadius,fill:a.fill||(e.status?n.tint(n.design.surface,o[e.status],.1):n.design.surface),stroke:a.dashed?o.line2:e.status?o[e.status]:n.design.line2,"stroke-width":1,...a.dashed?{"stroke-dasharray":`4 3`}:{},...a.meta?{meta:a.meta}:{}}),...e.icon?[(0,t.labelIcon)(n,e.icon,e.x+C+6,e.y+e.h/2,12,o.fg3)]:[],...e.lines.map((t,n)=>l(t,i.FONT.label,o.fg2,e.x+e.w/2+(e.icon?9:0),e.y+e.h/2+(n-(e.lines.length-1)/2)*A))]),S=e=>{let t=x(e,{meta:{kind:`node`,id:e.id}});c.push(e.link?n.link(e.link.href,[t],e.link):t)};for(let t of e.quadrants)for(let e of t.chips)S(e);for(let t of e.confusion.chips)S(t);for(let t of e.arcs)c.push(se(n,`M${t.a.x} ${t.a.y} Q${t.ctrl.x} ${t.ctrl.y} ${t.b.x} ${t.b.y}`,{fill:`none`,stroke:t.status?n.frameTone(o[t.status]):o.fg4,"stroke-width":1.5,"marker-end":`url(#cynefin-arrow)`},{kind:`edge`,from:t.from,to:t.to}));for(let t of e.arcs)t.label&&c.push({...n.el(`g`,{},[n.rect(t.label.x,t.label.y,t.label.w,t.label.h,{rx:r.smallRadius,fill:a,stroke:n.tint(a,o.fg4,.35),"stroke-width":1}),...t.label.lines.map((e,r)=>l(e,{size:i.FONT.label.size,weight:400},n.color(`muted`),t.label.x+t.label.w/2,t.label.y+t.label.h/2+(r-(t.label.lines.length-1)/2)*A))]),meta:{kind:`edge-label-group`,from:t.from,to:t.to}});return!e.embedHeading&&e.title&&e.title.lines.forEach((t,n)=>c.push(l(t,{size:e.compact?13:i.FONT.title.size,weight:i.FONT.title.weight},o.fg1,e.title.x,e.title.top+n*m))),{width:e.width,height:e.height,title:e.title?e.title.lines.join(` `):void 0,...e.embedHeading?{heading:e.heading}:{},children:c,anchor:e.anchor}}var le={"cynefin-beta":{optionMode:`raw`,parse:P,layout:L,scene:ce,acceptsPresentation:!0,honoredConfig:[`cynefin.showDomainDescriptions`]}};return e.DOMAINS=a,e.NOTES=l,e.implementations=le,e})({},KChartUnits[`diagram/tree-family-icon`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -2,4 +2,4 @@ KChartUnits["diagram/eventmodeling"]=(function(e,t,n){Object.defineProperty(e,Sy
|
|
|
2
2
|
`).map(e=>e.replace(/\r$/,``)),c=[],l=[],u=[],d=[],f=[],p=[],m=[],h=(0,n.mapLabels)(a,e=>l.push(e)),{text:g,icon:_}=i.title?h(i.title,i.headerLine):{},v=(e,n,r,i,o)=>c.push((0,t.error)(a,e,n,r,i,o));if(String(e??``).length>r.chars)return v(o,`源码超过 ${r.chars} 个字符`,`Source exceeds ${r.chars} characters`,`拆成多张事件模型图`,`Split the source into several event modeling diagrams`),{model:null,errors:c};let y={block:!1},b=e=>{let t=[];for(let n=e;n<s.length;n+=1){if(/^}\s*$/.test(s[n]))return{body:t,next:n+1};t.push(s[n])}return{body:null,next:s.length}};for(let e=0;e<s.length;e+=1){let n=o+e,r=F(s[e],y).trim();if(!r)continue;let c=(/^([A-Za-z][\w-]*)/.exec(r)?.[1]||``).toLowerCase();if(A.has(c)){let e=/^(tf|timeframe|rf|resetframe)\s+(\d{1,3})\s+([A-Za-z]+)\s+([A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*)([\s\S]*)$/.exec(r);if(!e){v(n,`时间框写法无效`,`Invalid time frame`,`使用「tf 01 evt ItemAdded」或「timeframe 01 event ItemAdded」`,`Use "tf 01 evt ItemAdded" or "timeframe 01 event ItemAdded"`);continue}let i=k.get(e[3].toLowerCase());if(!i){v(n,`不支持的时间框类型「${e[3]}」`,`Unknown time frame type: ${e[3]}`,`使用 ui、pcr/processor、cmd/command、rmo/readmodel、evt/event`,`Use ui, pcr/processor, cmd/command, rmo/readmodel, or evt/event`);continue}let o=e[5],s=[],c=e=>{let t=e.exec(o);return t?(o=o.slice(t[0].length),t):null},d;for(;d=c(/^\s*->>\s*(\d{1,3})(?![\w])/);)s.push(d[1]);let f=c(/^\s*\[\[\s*([A-Za-z_][\w]*)\s*\]\]/);o=o.trim();let p=null;if(o){let e=null,r=o,i=/^`([A-Za-z]+)`\s*([\s\S]*)$/.exec(o);i&&(e=i[1].toLowerCase(),r=i[2].trim()),e&&!j.has(e)&&l.push((0,t.warning)(`DIAGRAM_HINT`,a,n,`未知的行内数据类型「${e}」,按文本显示`,`Unknown inline data type: ${e}; shown as text`,`使用 json、text 等受支持的类型`,`Use a supported type such as json or text`)),/^\{[\s\S]*\}$/.test(r)||/^"[\s\S]*"$/.test(r)||/^'[\s\S]*'$/.test(r)?r=r.slice(1,-1).trim():(v(n,`行内数据写法无效`,`Invalid inline data`,`用花括号或引号包住数据,例如 { description: string }`,`Wrap the data in braces or quotes, for example { description: string }`),r=``),p={type:e,body:r}}let m=P(e[4]);u.push({id:e[2],kind:/^r/.test(e[1].toLowerCase())?`rf`:`tf`,type:i,identifier:e[4],namespace:m.length===2?m[0]:null,name:m.length===2?m[1]:m.join(`.`),sources:s,dataRef:f?f[1]:null,inline:p,line:n})}else if(c===`data`||c===`note`){let i=c===`data`?/^data\s+([A-Za-z_][\w]*)\s*(?:`([A-Za-z]+)`)?\s*\{\s*$/.exec(r):/^note\s+(\d{1,3})\s*(?:`([A-Za-z]+)`)?\s*\{\s*$/.exec(r);if(!i){v(n,`${c} 写法无效`,`Invalid ${c} block`,c===`data`?`使用「data 名称 {」开块并在下一行起写内容`:`使用「note 01 {」开块并在下一行起写内容`,c===`data`?`Use "data Name {" and put the content on the following lines`:`Use "note 01 {" and put the content on the following lines`);continue}let o=b(e+1);if(e=o.next-1,!o.body){v(n,`${c} 数据块缺少结尾的 }`,`The ${c} block is missing its closing }`,`在数据块末尾补上单独一行的 }`,`Add a line containing } at the end of the block`);continue}let s=i[2]?i[2].toLowerCase():null;s&&!j.has(s)&&l.push((0,t.warning)(`DIAGRAM_HINT`,a,n,`未知的数据类型「${s}」,按文本显示`,`Unknown data type: ${s}; shown as text`,`使用 json、text 等受支持的类型`,`Use a supported type such as json or text`)),c===`data`?d.push({id:i[1],type:s,lines:I(o.body),line:n}):f.push({id:i[1],type:s,lines:I(o.body),line:n})}else if(c===`entity`){let e=/^entity\s+([A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*)\s*$/.exec(r);e?m.push({name:e[1],line:n}):v(n,`entity 写法无效`,`Invalid entity declaration`,`使用「entity 名称」,不要附加其它内容`,`Use "entity Name" without anything after it`)}else if(c===`gwt`){let t=r;for(;e+1<s.length;){let n=s[e+1].trim(),r=n.split(/\s+/,1)[0];if(!n||n.startsWith(`%%`))e+=1;else{if(![`given`,`when`,`then`].includes(r)&&!k.has(r))break;t+=` ${F(s[++e],y).trim()}`}}let i=/^gwt\s+(\d{1,3})\s+(.*)$/.exec(t),a=i&&te(i[2]);if(!a){v(n,`gwt 写法无效`,`Invalid gwt statement`,`使用「gwt 01 given evt A when cmd B then rmo C」`,`Use "gwt 01 given evt A when cmd B then rmo C"`);continue}p.push({id:i[1],sections:a,line:n})}else if(c===`title`)i.title||({text:g,icon:_}=h(r.replace(/^title\s*:?\s*/i,``),n));else if(c===`acctitle`||c===`accdescr`){if(/^accDescr\s*\{/i.test(r)){for(;e+1<s.length&&!/^\s*\}/.test(s[e+1]);)e+=1;e+=1}}else v(n,`无法识别这一行「${r}」`,`Unrecognized line: ${r}`,`使用 tf/rf 时间框、data 数据块、note、entity 或 gwt`,`Use tf/rf time frames, data blocks, note, entity, or gwt`)}let x=new Set;for(let e of u)x.has(e.id)?c.push({...(0,t.error)(a,e.line,`时间框编号「${e.id}」重复`,`Duplicate event modeling frame ID "${e.id}"`,`给每个时间框分配唯一编号`,`Give every time frame a unique id`),code:`eventmodeling.duplicate-frame`}):x.add(e.id);u.length>r.workFrames&&v(u[r.workFrames].line,`时间框超过渲染上限 ${r.workFrames} 个`,`More than ${r.workFrames} time frames cannot be drawn`,`按业务阶段拆成多张图`,`Split the timeline into several diagrams`);let S=new Map(u.map(e=>[e.id,e])),C=new Map(d.map(e=>[e.id,e]));for(let e of u){for(let t of e.sources)S.has(t)||v(e.line,`引用的时间框「${t}」不存在`,`Unknown time frame reference: ${t}`,`使用本图中已声明的时间框编号`,`Use the id of a time frame declared in this diagram`);e.dataRef&&!C.has(e.dataRef)&&v(e.line,`引用的数据块「${e.dataRef}」不存在`,`Unknown data block: ${e.dataRef}`,`先声明 data 数据块,或修正 [[…]] 中的名称`,`Declare the data block, or fix the name inside [[…]]`)}for(let e of p)S.has(e.id)||v(e.line,`gwt 引用的时间框「${e.id}」不存在`,`gwt references an unknown time frame: ${e.id}`,`使用本图中已声明的时间框编号`,`Use the id of a time frame declared in this diagram`);let w=new Set(p.flatMap(e=>Object.values(e.sections).flat().map(e=>e.id))),T=m.filter(e=>!w.has(e.name.split(`.`).pop()));return T.length&&l.push((0,t.warning)(`DIAGRAM_HINT`,a,T[0].line,`entity 声明未在 gwt 中使用:${T.map(e=>e.name).join(`、`)}`,`Entities not used by any gwt statement: ${T.map(e=>e.name).join(`, `)}`,`在 gwt 中引用这些实体,或删除声明`,`Reference the entities in a gwt statement, or remove the declarations`)),{model:{type:`eventmodeling`,title:g,titleIcon:_,frames:u,dataBlocks:d,notes:f,gwt:p,entities:m},errors:[...c,...l]}}function ne(e,n={}){let r=n.lang||`zh`,i=[];for(let t of e.frames){let n=M[t.type];if(n&&t.sources.length)for(let r of t.sources){let a=e.frames.find(e=>e.id===r);a&&a!==t&&!n.includes(a.type)&&i.push({frame:t,source:a})}}let a=e.frames.filter(e=>e.sources.includes(e.id)),o=[];if(i.length){let e=i[0].frame,n=i.slice(0,3).map(({frame:e,source:t})=>`${t.id} ${N(t.type,r)} → ${e.id} ${N(e.type,r)}`).join(`;`),a=[...new Set(M[e.type])].map(e=>N(e,r)).join(`/`);o.push((0,t.warning)(`DIAGRAM_HINT`,r,e.line,`「${N(e.type,r)}」只应接收来自「${a}」的输入:${n}`,`A ${N(e.type,`en`)} should only receive input from a ${[...new Set(M[e.type])].map(e=>N(e,`en`)).join(`/`)}: ${n}`,`调整 ->> 指向的来源时间框`,`Point ->> at a matching upstream time frame`))}for(let e of a)o.push((0,t.warning)(`DIAGRAM_HINT`,r,e.line,`时间框「${e.id}」引用了自己,已忽略`,`Time frame ${e.id} references itself and is skipped`,`去掉指向自身的 ->>`,`Remove the ->> that points at the frame itself`));return o}function re(e,n,i,a,o){let s=e.inline||(n?{type:n.type,body:n.lines.join(`
|
|
3
3
|
`)}:null);if(!s)return null;let c=String(s.body??``).split(`
|
|
4
4
|
`).map(e=>e.replace(/\s+$/,``));for(;c.length&&!c[0].trim();)c.shift();for(;c.length&&!c[c.length-1].trim();)c.pop();let l=c.flatMap(e=>(0,t.wrapText)(e,a,w,i)),u=l.slice(0,o?4:r.dataLines);return l.length>u.length&&(o?u.push(`+${l.length-u.length}`):u[u.length-1]=`…`),{type:s.type||null,lines:u,total:l.length,text:c.join(`
|
|
5
|
-
`)}}function ie(e,u={},E={}){let D=u.lang||E.lang||`zh`,O=Math.max(1,Number(u.width)||800),k=O<560,A=(0,n.mapConfig)((0,n.mapConfig)(E.config,`eventmodeling`),`padding`),j=typeof A==`number`&&Number.isFinite(A)?Math.min(120,Math.max(8,A)):i,M=u.measure||((e,n=t.FONT.body)=>[...String(e??``)].length*n.size*.56),N=[];if(!e.frames.length)return N.push((0,t.error)(D,E.firstLine||1,`图中没有时间框`,`The diagram has no time frame`,`至少写一行「tf 01 ui 名称」`,`Add at least one "tf 01 ui Name" line`)),{width:O,height:0,errors:N};let P=[],F=new Map;for(let n of e.frames){let e=ee[n.type],r=`${e.band}:${n.namespace||``}`,i=F.get(r);if(!i){let a=P.filter(t=>t.band===e.band).map(e=>e.index);i={id:`lane-${P.length}`,band:e.band,index:n.namespace?Math.max(e.band,...a)+1:e.band,namespace:n.namespace,label:n.namespace?(0,t.message)(D,...e.prefix)+n.namespace:(0,t.message)(D,...e.lane)},P.push(i),F.set(r,i)}n.lane=i}let I=[...P].sort((e,t)=>e.band-t.band||e.index-t.index),te=new Map(e.dataBlocks.map(e=>[e.id,e])),L=e.frames.map((e,n)=>{let r=ee[e.type],i=Math.ceil(M(r.glyph,S)),a=(0,t.wrapText)(e.name,400-i-d,x,M),o=re(e,e.dataRef?te.get(e.dataRef):null,M,400,k),s=Math.max((0,t.maxWidthOf)(a,x,M)+i+d,o?(0,t.maxWidthOf)(o.lines,w,M):0),c=Math.min(g,Math.max(h,(0,t.snap)(s+20))),l=a.length*_+(o?.lines.length?y+o.lines.length*v:0),u=Math.max(m,(0,t.snap)(20+l));return{frame:e,index:n,lane:e.lane,glyph:r.glyph,glyphW:i,nameLines:a,data:o,contentW:s,contentH:l,w:c,h:u,x:0,r:0,y:0}}),ne=Math.max(56,...I.map(e=>Math.ceil(M(e.label,C)))),ie=k?o:ne+24,R=j,ae=j+ie,oe=new Map,z=null;for(let e of L){let n=oe.get(e.lane)??null,r=z===null?ae:z+a;n!==null&&(r=Math.max(r,n+a)),e.x=(0,t.snap)(r),e.r=e.x+e.w,oe.set(e.lane,e.r),z=e.r}let se=Math.max(...L.map(e=>e.r)),B=Math.max(se+o,j+ne+24),ce=new Map(I.map((e,t)=>[e,t])),V=new Map(L.map(e=>[e.frame.id,e])),H=[];for(let e of L){let{frame:t}=e;if(t.sources.length)for(let n of t.sources){let r=V.get(n);r&&r!==e&&H.push({from:n,to:t.id,line:t.line})}else if(e.index!==0&&t.kind!==`rf`){for(let n=e.index-1;n>=0;--n)if(L[n].lane!==e.lane){H.push({from:L[n].frame.id,to:t.id,line:t.line});break}}}let
|
|
5
|
+
`)}}function ie(e,u={},E={}){let D=u.lang||E.lang||`zh`,O=Math.max(1,Number(u.width)||800),k=O<560,A=(0,n.mapConfig)((0,n.mapConfig)(E.config,`eventmodeling`),`padding`),j=typeof A==`number`&&Number.isFinite(A)?Math.min(120,Math.max(8,A)):i,M=u.measure||((e,n=t.FONT.body)=>[...String(e??``)].length*n.size*.56),N=[];if(!e.frames.length)return N.push((0,t.error)(D,E.firstLine||1,`图中没有时间框`,`The diagram has no time frame`,`至少写一行「tf 01 ui 名称」`,`Add at least one "tf 01 ui Name" line`)),{width:O,height:0,errors:N};let P=[],F=new Map;for(let n of e.frames){let e=ee[n.type],r=`${e.band}:${n.namespace||``}`,i=F.get(r);if(!i){let a=P.filter(t=>t.band===e.band).map(e=>e.index);i={id:`lane-${P.length}`,band:e.band,index:n.namespace?Math.max(e.band,...a)+1:e.band,namespace:n.namespace,label:n.namespace?(0,t.message)(D,...e.prefix)+n.namespace:(0,t.message)(D,...e.lane)},P.push(i),F.set(r,i)}n.lane=i}let I=[...P].sort((e,t)=>e.band-t.band||e.index-t.index),te=new Map(e.dataBlocks.map(e=>[e.id,e])),L=e.frames.map((e,n)=>{let r=ee[e.type],i=Math.ceil(M(r.glyph,S)),a=(0,t.wrapText)(e.name,400-i-d,x,M),o=re(e,e.dataRef?te.get(e.dataRef):null,M,400,k),s=Math.max((0,t.maxWidthOf)(a,x,M)+i+d,o?(0,t.maxWidthOf)(o.lines,w,M):0),c=Math.min(g,Math.max(h,(0,t.snap)(s+20))),l=a.length*_+(o?.lines.length?y+o.lines.length*v:0),u=Math.max(m,(0,t.snap)(20+l));return{frame:e,index:n,lane:e.lane,glyph:r.glyph,glyphW:i,nameLines:a,data:o,contentW:s,contentH:l,w:c,h:u,x:0,r:0,y:0}}),ne=Math.max(56,...I.map(e=>Math.ceil(M(e.label,C)))),ie=k?o:ne+24,R=j,ae=j+ie,oe=new Map,z=null;for(let e of L){let n=oe.get(e.lane)??null,r=z===null?ae:z+a;n!==null&&(r=Math.max(r,n+a)),e.x=(0,t.snap)(r),e.r=e.x+e.w,oe.set(e.lane,e.r),z=e.r}let se=Math.max(...L.map(e=>e.r)),B=Math.max(se+o,j+ne+24),ce=new Map(I.map((e,t)=>[e,t])),V=new Map(L.map(e=>[e.frame.id,e])),H=[];for(let e of L){let{frame:t}=e;if(t.sources.length)for(let n of t.sources){let r=V.get(n);r&&r!==e&&H.push({from:n,to:t.id,line:t.line})}else if(e.index!==0&&t.kind!==`rf`){for(let n=e.index-1;n>=0;--n)if(L[n].lane!==e.lane){H.push({from:L[n].frame.id,to:t.id,line:t.line});break}}}let le=new Map,U=new Map,W=new Map,G=(e,t,n)=>{let r=e.x+f,i=e.r-f,a=`${e.frame.id}:${t}`,o=le.get(a)||[],s=Math.min(i,Math.max(r,n)),c=[0];for(let e=1;e<=24;e+=1)c.push(-e*10,e*10);for(let e of c){let t=Math.round(s+e);if(!(t<r-.01||t>i+.01||o.some(e=>Math.abs(e-t)<8)))return o.push(t),le.set(a,o),t}return o.push(s),le.set(a,o),s},ue=(e,t,n)=>{for(let r of e){let e=Math.round(L[r].r),i=L[r+1].x-L[r].r,a=U.get(r)||[];for(let o=1;o*l<i-2;o+=1){let i=e+o*l;if(!a.some(e=>e.slot===o&&e.lo<=n&&t<=e.hi))return a.push({slot:o,lo:t,hi:n}),U.set(r,a),i}}let r=e[0],i=Math.round(L[r].r+l),a=U.get(r)||[];return a.push({slot:1,lo:t,hi:n}),U.set(r,a),i},K=(e,t,n)=>{let r=W.get(e)||[];for(let i=0;i<12;i+=1)if(!r.some(e=>e.track===i&&e.lo-4<=n&&t<=e.hi+4))return r.push({track:i,lo:t,hi:n}),W.set(e,r),i;return r.push({track:0,lo:t,hi:n}),W.set(e,r),0},q=[];for(let e of H){let t=V.get(e.from),n=V.get(e.to),r=ce.get(t.lane),i=ce.get(n.lane),a={from:e.from,to:e.to,line:e.line},o=(Math.max(t.x,n.x)+Math.min(t.r,n.r))/2;if(r===i){let e=r<I.length-1||I.length===1,i=e?r:r-1;a.kind=`hook`,a.gap=i,a.side=e?`bottom`:`top`,a.exitX=G(t,a.side,o),a.entryX=G(n,a.side,o),a.track=K(i,Math.min(a.exitX,a.entryX),Math.max(a.exitX,a.entryX)),q.push(a);continue}let s=i>r;a.exitSide=s?`bottom`:`top`,a.entrySide=s?`top`:`bottom`;let c=s?r:r-1,l=s?i-1:i;if(c===l){if(a.exitX=G(t,a.exitSide,o),a.entryX=G(n,a.entrySide,o),Math.abs(a.exitX-a.entryX)<.5){a.kind=`straight`,q.push(a);continue}a.kind=`elbow`,a.gap=c,a.track=K(c,Math.min(a.exitX,a.entryX),Math.max(a.exitX,a.entryX)),q.push(a);continue}let u=Math.min(t.index,n.index),d=Math.max(t.index,n.index),f=[];for(let e=u;e<d;e+=1)f.push(e);a.stripX=ue(f,Math.min(r,i)+1,Math.max(r,i)-1),a.exitX=G(t,a.exitSide,a.stripX),a.entryX=G(n,a.entrySide,a.stripX),a.kind=`cross`,a.gapA=c,a.gapB=l,a.trackA=K(c,Math.min(a.exitX,a.stripX),Math.max(a.exitX,a.stripX)),a.trackB=K(l,Math.min(a.entryX,a.stripX),Math.max(a.entryX,a.stripX)),q.push(a)}for(let e of I){let t=L.filter(t=>t.lane===e);e.maxH=Math.max(0,...t.map(e=>e.h)),e.h=Math.max(p,e.maxH+24+(k?18:0)),e.w=B-R,e.x=R,e.labelX=e.x+10}let de=I.map((e,t)=>{let n=W.get(t)||[],r=Math.max(0,...n.map(e=>e.track));return n.length?s+r*c:t<I.length-1?s:0}),{title:J,titleIcon:fe}=e,pe=!u.embedHeading&&(J||fe)?(0,t.wrapText)(J,B-j-(fe?20:0),t.FONT.title,M):[],me=j+pe.length*20;I.forEach((e,t)=>{e.y=me,e.labelY=e.y+(k?13:e.h/2),me+=e.h+de[t]});let he=me;for(let e of L)e.y=e.lane.y+o+(k?18:0);let Y=(e,t)=>I[e].y+I[e].h+6+t*c,ge=q.map(e=>{let t=V.get(e.from),n=V.get(e.to),r=(e.exitSide||e.side)===`bottom`?t.y+t.h:t.y,i=(e.entrySide||e.side)===`bottom`?n.y+n.h:n.y,a;a=e.kind===`straight`?[{x:e.exitX,y:r},{x:e.entryX,y:i}]:e.kind===`elbow`||e.kind===`hook`?[{x:e.exitX,y:r},{x:e.exitX,y:Y(e.gap,e.track)},{x:e.entryX,y:Y(e.gap,e.track)},{x:e.entryX,y:i}]:[{x:e.exitX,y:r},{x:e.exitX,y:Y(e.gapA,e.trackA)},{x:e.stripX,y:Y(e.gapA,e.trackA)},{x:e.stripX,y:Y(e.gapB,e.trackB)},{x:e.entryX,y:Y(e.gapB,e.trackB)},{x:e.entryX,y:i}];let o=a.filter((e,t)=>!t||e.x!==a[t-1].x||e.y!==a[t-1].y);return{from:e.from,to:e.to,line:e.line,points:o,d:o.map((e,t)=>`${t?`L`:`M`}${Math.round(e.x)} ${Math.round(e.y)}`).join(` `)}}),X=[],_e=R+4,ve=Math.max(120,B-_e-12),Z=he+18,Q=(e,t,n)=>{X.push({x:_e,y:Z,text:e,kind:t,fill:n}),Z+=b},ye=e=>(0,t.message)(D,...e);for(let n of e.gwt){X.length&&(Z+=6),Q(`GWT ${n.id}`,`heading`);for(let e of[`given`,`when`,`then`]){let r=n.sections[e];if(!r.length)continue;let i=`${ye({given:[`给定 Given`,`Given`],when:[`当 When`,`When`],then:[`那么 Then`,`Then`]}[e])}: ${r.map(e=>`${e.type} ${e.id}`).join(` · `)}`;for(let e of(0,t.wrapText)(i,ve,T,M))Q(e,`body`)}}for(let n of e.notes){X.length&&(Z+=6),Q(`Note ${n.id}`,`heading`);for(let e of n.lines.flatMap(e=>(0,t.wrapText)(e,ve,T,M)))Q(e,`body`)}if(e.entities.length){X.length&&(Z+=6),Q(ye([`实体`,`Entities`]),`heading`);for(let n of(0,t.wrapText)(e.entities.map(e=>e.name).join(` · `),ve,T,M))Q(n,`body`)}let be=X.length?Z+j-b+4:he+j,$=B+j,xe=(0,t.snap)(Math.max(1,be));return(e.frames.length>r.largeFrames||$>O*2)&&N.push((0,t.warning)(`LARGE_DIAGRAM`,D,E.firstLine||1,`图较大(${e.frames.length} 个时间框、宽 ${$}px),建议拆成多张`,`Large diagram (${e.frames.length} time frames, ${$}px wide); consider splitting it`,`按业务阶段拆分时间线`,`Split the timeline by business stage`)),{type:`eventmodeling`,width:$,height:xe,lanes:I,boxes:L,edges:ge,captions:X,errors:N,title:J,titleIcon:fe,titleLines:pe,pad:j,...u.embedHeading?{heading:J}:{}}}function R(e,r){let i=(0,t.appearance)(r),a=[],{pad:o,titleIcon:s,titleLines:c}=e;if(c.length){let e=Math.max(9,o);a.push(r.textLines(o+(s?20:0),e,c,{...t.FONT.title,leading:20,fill:i.fg1,"dominant-baseline":`central`})),s&&a.push((0,n.mapIcon)(r,s,o+7,e,i.fg1))}let l=`em-arrow`;a.push(r.el(`defs`,{},[r.el(`marker`,{id:l,viewBox:`0 0 8 8`,refX:7,refY:4,markerWidth:8,markerHeight:8,markerUnits:`userSpaceOnUse`,orient:`auto`},[r.path(`M0 0 L8 4 L0 8 Z`,{fill:r.color(`muted`)})])]));for(let[t,n]of e.lanes.entries()){let e=r.el(`g`,{},[r.rect(n.x,n.y,n.w,n.h,{fill:t%2?i.surface2:i.surface,stroke:i.line,"stroke-width":1,rx:i.radius,meta:{kind:`frame`,id:n.id}}),r.text(n.labelX,n.labelY,n.label,{size:C.size,weight:C.weight,fill:i.fg3,anchor:`start`,"dominant-baseline":`central`})]);e.meta={kind:`frame`,id:n.id},a.push(e)}for(let t of e.boxes){let e=ee[t.frame.type],n=e.role?r.frameTone(r.color(e.role)):null,o=n?r.tint(i.bg,n,.12):i.node,s=n?r.tint(i.bg,n,.45):i.line2,c=r.textOn(o),l=n?r.textColor(n):i.fg3,f=t.x+Math.max(u,(t.w-t.contentW)/2),p=t.y+(t.h-t.contentH)/2,m=f+t.glyphW+d,h=p+_/2,g=[r.rect(t.x,t.y,t.w,t.h,{fill:o,stroke:s,"stroke-width":1,rx:i.smallRadius,meta:{kind:`node`,id:t.frame.id}}),r.text(f,h,t.glyph,{size:S.size,weight:S.weight,fill:l,anchor:`start`,"dominant-baseline":`central`})];for(let[e,n]of t.nameLines.entries())g.push(r.text(m,h+e*_,n,{size:x.size,weight:x.weight,fill:c,anchor:`start`,"dominant-baseline":`central`}));let b=p+t.nameLines.length*_+y;for(let[e,n]of(t.data?.lines||[]).entries())g.push(r.text(f,b+v/2+e*v,n,{size:w.size,weight:w.weight,fill:c,anchor:`start`,"dominant-baseline":`central`}));let C=[t.frame.id,t.frame.identifier,t.data?.text].filter(Boolean).join(` · `);a.push(r.titled(r.el(`g`,{},g),C))}for(let t of e.edges)a.push(r.path(t.d,{fill:`none`,stroke:r.color(`muted`),"stroke-width":1.25,"stroke-linejoin":`round`,"marker-end":`url(#${l})`,meta:{kind:`edge`,from:t.from,to:t.to}}));for(let t of e.captions)a.push(r.text(t.x,t.y,t.text,{size:T.size,weight:t.kind===`heading`?C.weight:T.weight,fill:t.kind===`heading`?i.fg3:i.fg2,anchor:`start`,"dominant-baseline":`central`}));return{width:e.width,height:e.height,title:e.title,...e.heading?{heading:e.heading}:{},children:a}}return e.implementations={eventmodeling:{parse:L,validate:ne,layout:ie,scene:R,honoredConfig:[`eventmodeling.padding`]}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/map-label`]);
|