@fengwk/kchart 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +31 -2
- package/README.zh-CN.md +31 -2
- package/dist/esm/_virtual/_kchart-families.js +2 -1
- package/dist/esm/chart/composition.js +7 -5
- package/dist/esm/chart/maps.js +9 -7
- package/dist/esm/chart/mindmap.js +19 -5
- package/dist/esm/chart/multivariate.js +49 -14
- package/dist/esm/chart/relations.js +15 -7
- package/dist/esm/chart/spec.js +5 -2
- package/dist/esm/core/context.js +29 -10
- package/dist/esm/core/scene.js +238 -21
- package/dist/esm/core/text.js +1 -1
- package/dist/esm/diagram/block.js +287 -295
- package/dist/esm/diagram/blocks.js +541 -605
- package/dist/esm/diagram/board-paint.js +594 -0
- package/dist/esm/diagram/board-route.js +60 -0
- package/dist/esm/diagram/c4.js +75 -35
- package/dist/esm/diagram/class.js +3 -2
- package/dist/esm/diagram/cynefin.js +55 -9
- package/dist/esm/diagram/eventmodeling.js +4 -2
- package/dist/esm/diagram/gantt.js +37 -15
- package/dist/esm/diagram/gitgraph.js +26 -5
- package/dist/esm/diagram/graph-layout.js +39 -2
- package/dist/esm/diagram/graph-route.js +296 -38
- package/dist/esm/diagram/info.js +32 -0
- package/dist/esm/diagram/journey.js +5 -5
- package/dist/esm/diagram/kanban.js +3 -3
- package/dist/esm/diagram/layers.js +9 -7
- package/dist/esm/diagram/mindmap.js +5 -1
- package/dist/esm/diagram/numeric-composition.js +24 -4
- package/dist/esm/diagram/numeric-model.js +1 -1
- package/dist/esm/diagram/numeric-radar.js +25 -7
- package/dist/esm/diagram/numeric-sankey.js +4 -3
- package/dist/esm/diagram/numeric-xy.js +12 -2
- package/dist/esm/diagram/packet.js +4 -4
- package/dist/esm/diagram/quadrant.js +12 -5
- package/dist/esm/diagram/railroad-parse.js +20 -10
- package/dist/esm/diagram/railroad.js +1 -1
- package/dist/esm/diagram/registry.js +46 -8
- package/dist/esm/diagram/sequence.js +43 -6
- package/dist/esm/diagram/swimlane.js +2 -2
- package/dist/esm/diagram/time.js +3 -3
- package/dist/esm/diagram/timeline.js +5 -5
- package/dist/esm/diagram/treeview.js +5 -3
- package/dist/esm/diagram/venn.js +35 -15
- package/dist/esm/diagram/wardley.js +61 -26
- package/dist/esm/diagram/zenuml.js +338 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/mermaid.d.ts +1 -1
- package/dist/esm/mermaid.js +2 -1
- package/dist/esm/node.js +8 -2
- package/dist/esm/src/families.js +6 -1
- package/dist/units/chart/composition.js +1 -1
- package/dist/units/chart/maps.js +1 -1
- package/dist/units/chart/mindmap.js +1 -1
- package/dist/units/chart/multivariate.js +1 -1
- package/dist/units/chart/relations.js +1 -1
- package/dist/units/chart/spec.js +1 -1
- package/dist/units/core/context.js +1 -1
- package/dist/units/core/scene.js +1 -1
- package/dist/units/core/text.js +1 -1
- package/dist/units/diagram/block.js +2 -2
- package/dist/units/diagram/blocks.js +2 -2
- package/dist/units/diagram/board-paint.js +1 -0
- package/dist/units/diagram/board-route.js +1 -0
- package/dist/units/diagram/c4.js +1 -1
- package/dist/units/diagram/class.js +2 -2
- package/dist/units/diagram/cynefin.js +2 -2
- package/dist/units/diagram/eventmodeling.js +1 -1
- package/dist/units/diagram/gantt.js +3 -3
- package/dist/units/diagram/gitgraph.js +2 -1
- package/dist/units/diagram/graph-layout.js +1 -1
- package/dist/units/diagram/graph-route.js +1 -1
- package/dist/units/diagram/info.js +2 -0
- package/dist/units/diagram/journey.js +3 -3
- package/dist/units/diagram/kanban.js +1 -1
- package/dist/units/diagram/layers.js +1 -1
- package/dist/units/diagram/mindmap.js +1 -1
- package/dist/units/diagram/numeric-composition.js +1 -1
- package/dist/units/diagram/numeric-model.js +1 -1
- package/dist/units/diagram/numeric-radar.js +2 -2
- package/dist/units/diagram/numeric-sankey.js +1 -1
- package/dist/units/diagram/numeric-xy.js +1 -1
- package/dist/units/diagram/packet.js +1 -1
- package/dist/units/diagram/quadrant.js +1 -1
- package/dist/units/diagram/railroad-parse.js +2 -2
- package/dist/units/diagram/railroad.js +1 -1
- package/dist/units/diagram/registry.js +2 -2
- package/dist/units/diagram/sequence.js +1 -1
- package/dist/units/diagram/swimlane.js +2 -2
- package/dist/units/diagram/time.js +1 -1
- package/dist/units/diagram/timeline.js +1 -1
- package/dist/units/diagram/treeview.js +1 -1
- package/dist/units/diagram/venn.js +1 -1
- package/dist/units/diagram/wardley.js +4 -4
- package/dist/units/diagram/zenuml.js +2 -0
- package/dist/units.json +79 -51
- package/package.json +1 -1
- package/dist/esm/diagram/relations.js +0 -966
- package/dist/units/diagram/relations.js +0 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
KChartUnits["diagram/journey"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=60,o=2e3,s=[`journey`],c=new Map([[`taskfontsize`,`taskFontSize`],[`maxlabelwidth`,`maxLabelWidth`],[`titlefontsize`,`titleFontSize`],[`leftmargin`,`leftMargin`]]),l=new Set([`actorcolours`,`sectionfills`,`sectioncolours`,`titlecolor`]),u=e=>String(e).toLowerCase().replace(/[-_]/g,``),d=9,f=14,p=5,m={labelX:12,labelPad:12,plotGap:6,right:16,band:10,bottom:16,row:48,chipR:4,chipGap:6};m.chip=m.chipR*2+m.chipGap;var h=(e,t,r,i,a,o)=>(0,n.error)(e,t,r,i,a,o),g=(e,t,n,r)=>{if(e==null||e===``)return t;if(typeof e==`number`)return Number.isFinite(e)?Math.min(r,Math.max(n,e)):t;let i=/^([+-]?\d*\.?\d+)\s*(px|pt|ex|em|rem)?$/i.exec(String(e).trim());if(!i)return t;let a={px:1,pt:4/3,ex:4,em:12,rem:12}[(i[2]||`px`).toLowerCase()];return Math.min(r,Math.max(n,Number(i[1])*a))};function _(e){let t=``;for(let n=0;n<e.length;n+=1){let r=e[n];if(t)r===t&&(t=``);else if(r===`"`||r===`'`)t=r;else if(r===`%`&&e[n+1]===`%`||r===`#`&&!/^#[\w]+;/.test(e.slice(n)))return e.slice(0,n).trimEnd()}return e}var v=e=>e.replace(/(?:&#?|#)[\w]+;/g,``).includes(`;`);function y(e,t,r,i){let a=e?.config?.journey,o={};if(!a||typeof a!=`object`||Array.isArray(a))return o;let s=[],d=[];for(let[e,t]of Object.entries(a)){let n=u(e);c.has(n)?o[c.get(n)]=t:l.has(n)?s.push(e):d.push(e)}return s.length&&i.push((0,n.warning)(`IGNORED_STYLE`,t,r,`旅程图颜色由主题决定,已忽略配置:${s.join(`, `)}`,`Journey colors come from the theme; ignored: ${s.join(`, `)}`,`改用主题调色板`,`Use the theme palette`)),d.length&&i.push((0,n.warning)(`IGNORED_CONFIG`,t,r,`旅程图不支持这些配置,已忽略:${d.join(`, `)}`,`Ignored journey config: ${d.join(`, `)}`,`移除这些配置项`,`Remove these config keys`)),o}function b(e,a={}){let s=a.lang||`zh`,c=Number.isInteger(a.firstLine)?a.firstLine:2,l=[];if(e.length>2e5)return{model:null,errors:[h(s,c,`旅程图源码超过 200000 字符`,`Journey source exceeds 200,000 characters`,`拆分旅程图`,`Split the journey`)]};let u=y(a,s,a.headerLine||Math.max(1,c-1),l),d={taskFontSize:g(u.taskFontSize,n.FONT.body.size,12,20),maxLabelWidth:g(u.maxLabelWidth,360,120,640),titleFontSize:g(u.titleFontSize,n.FONT.title.size,12,28),leftMargin:g(u.leftMargin,0,0,480)},f=[],p=[{name:``,tasks:[]}],m=(0,i.presentation)({lang:s}),b=new Set,x=e=>e.forEach(e=>{e.code===`IGNORED_ASSET`&&b.has(e.message)||(l.push(e),e.code===`IGNORED_ASSET`&&b.add(e.message))}),S=(e,t)=>{let n,i=e=>(n??=e,``),a=e.replace(/::icon\(([^)]+)\)/gi,(e,t)=>i(t.trim())).replace(/(?<![\w:/.-])(?:logos|mdi|tabler|simple-icons):[a-z\d-]+/gi,i),o=(0,r.normalizeLabel)(a,{lang:s,line:t});return x(o.diagnostics),{text:o.text,icon:(n?C(n,t):null)||o.icon}},C=(e,r)=>{let i=(0,t.resolveIconRef)(e);return i||x([(0,n.warning)(`IGNORED_ASSET`,s,r,`未知图标 ${e}`,`Unknown icon ${e}`,`使用内置图标`,`Use a built-in icon`)]),i},w=a.title||``,T=a.headerLine||Math.max(1,c-1),E=!1,D=!1,O=Object.keys(a.options||{});O.length&&l.push((0,n.warning)(`IGNORED_CONFIG`,s,a.headerLine||Math.max(1,c-1),`旅程图标题行不接受选项,已忽略:${O.join(`, `)}`,`Journey header options are ignored: ${O.join(`, `)}`,`只保留 journey 关键字`,`Keep only the journey keyword`));let k=String(e??``).replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);for(let e=0;e<k.length;e+=1){let t=c+e,r=k[e].trim();if(m.accept(r,t))continue;let i=_(r).trim();if(!i||i.startsWith(`%%`))continue;if(v(i)){l.push(h(s,t,`分号不能用于分隔旅程图语句`,`Semicolons cannot separate journey statements`,`每行只写一条语句`,`Write one statement per line`));continue}let a;if(a=/^title(?:\s*:|\s+)(.*)$/i.exec(i)){w=a[1].trim(),T=t;continue}if(/^title$/i.test(i))continue;if(/^section\b/i.test(i)){let e=/^section\s+(.+)$/i.exec(i);if(!e||!e[1].trim()){l.push(h(s,t,`分组名不能为空`,`A section name must be non-empty`,`写成「section 名称」`,`Write "section name"`));continue}let n=S(e[1].trim(),t);p.push({name:n.text,icon:n.icon,tasks:[],line:t});continue}let u=[],d=i.replace(/:::([\w-]+)/g,(e,t)=>(u.push(t),``)),g=[...d.matchAll(/::icon\([^)]+\)|(?<![\w:/.-])(?:fa[bsrlk]?|logos|mdi|tabler|simple-icons):[a-z\d-]+|(:)/gi)].find(e=>e[1])?.index,y=g==null?``:d.slice(0,g).trim();if(!y){l.push(h(s,t,`旅程任务需要写成「任务名: 评分: 参与者」`,`A journey task reads "task name: score: actors"`,`在冒号前写任务名`,`Write the task name before the colon`));continue}let[,b,x=``]=/^\s*([^:]*?)(?:\s*:\s*(.*))?$/.exec(d.slice(g+1)),C=b.trim()?Number(b):NaN,O=x.split(`,`).map(e=>S(e.trim(),t)),A=[...new Set(O.map(e=>e.text).filter(Boolean))];if(!Number.isFinite(C)){l.push(h(s,t,`评分「${b}」不是数字`,`Score "${b}" is not a number`,`用 1–5 的整数评分`,`Use a whole score from 1 to 5`));continue}if(C<1||C>5){l.push(h(s,t,`评分 ${C} 超出 1–5 的范围`,`Score ${C} is outside 1–5`,`把评分改为 1 到 5`,`Use a score from 1 to 5`));continue}if(!Number.isInteger(C)&&!E&&(E=!0,l.push((0,n.warning)(`DIAGRAM_HINT`,s,t,`评分 ${C} 不是整数,已按原值绘制`,`Score ${C} is not whole; drawn as written`,`使用 1–5 的整数评分`,`Use whole scores from 1 to 5`))),f.length>=o){D||(D=!0,l.push(h(s,t,`旅程图最多 ${o} 个任务`,`A journey can contain at most ${o} tasks`,`把旅程拆成两张图`,`Split the journey into two diagrams`)));continue}let j=S(y,t),M=`task:${f.length}`;u.length&&m.addClasses(M,u,t);let N={id:M,name:j.text,icon:j.icon,score:C,actors:A,actorLabels:O,line:t};f.push(N),p.at(-1).tasks.push(N)}let A=S(w,T);w=A.text,a.title=w,!f.length&&!l.some(e=>e.severity!==`warning`)&&l.push(h(s,c,`旅程图中没有任务`,`Journey has no tasks`,`添加「任务名: 评分: 参与者」`,`Add "task name: score: actors"`));let j=[...new Set(f.flatMap(e=>e.actors))],M=new Map,N=new Map;for(let e of f)for(let t of e.actorLabels)t.text&&(t.icon&&!M.has(t.text)&&M.set(t.text,t.icon),N.has(t.text)||N.set(t.text,m.linkOf(t.text)));for(let e of f)e.status=m.statusOf(e.id),e.link=m.linkOf(e.id);for(let e of p)e.status=m.statusOf(e.name),e.link=m.linkOf(e.name);return l.push(...m.diagnostics()),{model:{type:`journey`,title:w,titleIcon:A.icon,titleLink:m.linkOf(w),tasks:f,sections:p,actors:j,actorIcons:Object.fromEntries(M),actorLinks:Object.fromEntries(N),actorStatuses:Object.fromEntries(j.map(e=>[e,m.statusOf(e)])),config:d},errors:l}}function x(e,t,n,r,i=f,a=e.color(`fg`)){if(!t)return null;let[o,s,c,l]=t.viewBox.split(/\s+/).map(Number),u=i/Math.max(c,l),d=t.set===`tabler`;return e.el(`g`,{transform:`translate(${n+(i-c*u)/2} ${r+(i-l*u)/2}) scale(${u}) translate(${-o} ${-s})`,fill:d?`none`:a,stroke:d?a:`none`,"stroke-width":1.8,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function S(e,t={}){let{width:r=800,ctx:i,renderOptions:o={}}=t;if(!i)throw TypeError(`journey layout needs a theme context`);let
|
|
4
|
-
`).map((t,n)=>
|
|
5
|
-
`):[],r=K,i=r+(n.length?10+18*n.length:0),a=t.tasks.map(e=>{let t=
|
|
3
|
+
`);for(let e=0;e<k.length;e+=1){let t=c+e,r=k[e].trim();if(m.accept(r,t))continue;let i=_(r).trim();if(!i||i.startsWith(`%%`))continue;if(v(i)){l.push(h(s,t,`分号不能用于分隔旅程图语句`,`Semicolons cannot separate journey statements`,`每行只写一条语句`,`Write one statement per line`));continue}let a;if(a=/^title(?:\s*:|\s+)(.*)$/i.exec(i)){w=a[1].trim(),T=t;continue}if(/^title$/i.test(i))continue;if(/^section\b/i.test(i)){let e=/^section\s+(.+)$/i.exec(i);if(!e||!e[1].trim()){l.push(h(s,t,`分组名不能为空`,`A section name must be non-empty`,`写成「section 名称」`,`Write "section name"`));continue}let n=S(e[1].trim(),t);p.push({name:n.text,icon:n.icon,tasks:[],line:t});continue}let u=[],d=i.replace(/:::([\w-]+)/g,(e,t)=>(u.push(t),``)),g=[...d.matchAll(/::icon\([^)]+\)|(?<![\w:/.-])(?:fa[bsrlk]?|logos|mdi|tabler|simple-icons):[a-z\d-]+|(:)/gi)].find(e=>e[1])?.index,y=g==null?``:d.slice(0,g).trim();if(!y){l.push(h(s,t,`旅程任务需要写成「任务名: 评分: 参与者」`,`A journey task reads "task name: score: actors"`,`在冒号前写任务名`,`Write the task name before the colon`));continue}let[,b,x=``]=/^\s*([^:]*?)(?:\s*:\s*(.*))?$/.exec(d.slice(g+1)),C=b.trim()?Number(b):NaN,O=x.split(`,`).map(e=>S(e.trim(),t)),A=[...new Set(O.map(e=>e.text).filter(Boolean))];if(!Number.isFinite(C)){l.push(h(s,t,`评分「${b}」不是数字`,`Score "${b}" is not a number`,`用 1–5 的整数评分`,`Use a whole score from 1 to 5`));continue}if(C<1||C>5){l.push(h(s,t,`评分 ${C} 超出 1–5 的范围`,`Score ${C} is outside 1–5`,`把评分改为 1 到 5`,`Use a score from 1 to 5`));continue}if(!Number.isInteger(C)&&!E&&(E=!0,l.push((0,n.warning)(`DIAGRAM_HINT`,s,t,`评分 ${C} 不是整数,已按原值绘制`,`Score ${C} is not whole; drawn as written`,`使用 1–5 的整数评分`,`Use whole scores from 1 to 5`))),f.length>=o){D||(D=!0,l.push(h(s,t,`旅程图最多 ${o} 个任务`,`A journey can contain at most ${o} tasks`,`把旅程拆成两张图`,`Split the journey into two diagrams`)));continue}let j=S(y,t),M=`task:${f.length}`;u.length&&m.addClasses(M,u,t);let N={id:M,name:j.text,icon:j.icon,score:C,actors:A,actorLabels:O,line:t};f.push(N),p.at(-1).tasks.push(N)}let A=S(w,T);w=A.text,a.title=w,!f.length&&!l.some(e=>e.severity!==`warning`)&&l.push(h(s,c,`旅程图中没有任务`,`Journey has no tasks`,`添加「任务名: 评分: 参与者」`,`Add "task name: score: actors"`));let j=[...new Set(f.flatMap(e=>e.actors))],M=new Map,N=new Map;for(let e of f)for(let t of e.actorLabels)t.text&&(t.icon&&!M.has(t.text)&&M.set(t.text,t.icon),N.has(t.text)||N.set(t.text,m.linkOf(t.text)));for(let e of f)e.status=m.statusOf(e.id),e.link=m.linkOf(e.id);for(let e of p)e.status=m.statusOf(e.name),e.link=m.linkOf(e.name);return l.push(...m.diagnostics()),{model:{type:`journey`,title:w,titleIcon:A.icon,titleLink:m.linkOf(w),tasks:f,sections:p,actors:j,actorIcons:Object.fromEntries(M),actorLinks:Object.fromEntries(N),actorStatuses:Object.fromEntries(j.map(e=>[e,m.statusOf(e)])),config:d},errors:l}}function x(e,t,n,r,i=f,a=e.color(`fg`)){if(!t)return null;let[o,s,c,l]=t.viewBox.split(/\s+/).map(Number),u=i/Math.max(c,l),d=t.set===`tabler`;return e.el(`g`,{transform:`translate(${n+(i-c*u)/2} ${r+(i-l*u)/2}) scale(${u}) translate(${-o} ${-s})`,fill:d?`none`:a,stroke:d?a:`none`,"stroke-width":1.8,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function S(e,t={}){let{width:r=800,ctx:i,renderOptions:o={},compact:s,embedHeading:c}=t;if(!i)throw TypeError(`journey layout needs a theme context`);let l=(0,n.appearance)(i),u=t.measure||((e,t)=>i.measure(e,t.size,t.weight)),h=i.color(`bg`),g=i.color(`accent`),_=i.color(`grid`),v=i.color(`fg`),y=i.color(`muted`),b=e.config||{},S={size:b.taskFontSize||n.FONT.body.size,weight:n.FONT.body.weight},C={size:n.FONT.label.size,weight:n.FONT.label.weight},w=(0,n.isEn)(i.lang)?`Score`:`评分`,T=b.titleFontSize||n.FONT.title.size,E=b.maxLabelWidth||360,{tasks:D,actors:O}=e,k=e.sections.filter(e=>e.name||e.icon||e.tasks.length),A=new Map(O.map((e,t)=>[e,t])),j=(e,t)=>e?[i.link(e.href,t,e)]:t,M=e=>e?18:0,N=[],P=[],ee=(e,t)=>({size:e,weight:t}),F=(e,t)=>u(e,t),I=t=>{let n=A.get(t),r=e.actorStatuses?.[t];return i.tint(h,r?i.design[r]:i.color(`tone${n%6+1}`),.8)},te=new Map(D.map(e=>[e,i.wrap(e.name,Math.max(40,E-M(e.icon)),S.size,S.weight)])),ne=e=>e.actors.length?(e.actors.length-1)*m.chip+m.chipR*2:0,re=Math.max(0,...D.map(e=>M(e.icon)+Math.max(0,...te.get(e).map(e=>F(e,S)))+(e.actors.length?10+ne(e):0))),L=ee(n.FONT.body.size,600),ie=Math.max(0,...k.flatMap(e=>e.name.split(`
|
|
4
|
+
`).map((t,n)=>F(t,L)+(n===0?M(e.icon):0)))),R=S.size+5,z=Math.max(b.leftMargin||0,m.labelX+Math.max(re,ie,F(w,C))+m.labelPad+d+m.plotGap),B=s?140:Math.max(140,r-z-m.right),V=z,H=z+B,U=B/4,W=Math.ceil(Math.max(s?0:r,H+m.right)),G=!!e.title&&!o?.frame&&!c;if(G){let t=i.text(m.labelX+M(e.titleIcon),T+12,e.title,{size:T,weight:600,fill:v}),n=[...e.titleIcon?[x(i,e.titleIcon,m.labelX,T+12-f/2)]:[],t];N.push(...j(e.titleLink,[i.el(`g`,{},n)]))}let K=G?12+T+18:16,q=Math.max(120,H-m.labelX),J=[],Y=[],X=0,Z=0;for(let t of O){let n=i.wrap(t,Math.max(40,q-13-M(e.actorIcons?.[t])),C.size,C.weight),r=13+M(e.actorIcons?.[t])+Math.max(0,...n.map(e=>F(e,C)));Y.length&&X+r>q&&(J.push({items:Y,height:Z}),Y=[],X=0,Z=0),Y.push({name:t,lines:n,width:r}),X+=r+14,Z=Math.max(Z,n.length*15)}Y.length&&J.push({items:Y,height:Z});for(let t of J){let n=m.labelX;for(let r of t.items){let t=e.actorIcons?.[r.name],a=M(t),o=i.titled(i.circle(n+m.chipR,K+8,m.chipR,{fill:I(r.name),stroke:h,"stroke-width":1}),r.name);N.push(...j(e.actorLinks?.[r.name],[o])),t&&N.push(x(i,t,n+13,K+1)),r.lines.forEach((t,o)=>N.push(...j(e.actorLinks?.[r.name],[i.text(n+13+a,K+8+o*15,t,{...C,fill:y,"dominant-baseline":`middle`})]))),n+=r.width+a+14}K+=t.height+(J.length>1?4:0)}J.length&&(K+=10);let Q=K+8;N.push(i.text(m.labelX,Q,w,{...C,fill:y,"dominant-baseline":`middle`}));for(let e=1;e<=p;e+=1)N.push(i.text(V+(e-1)*U,Q,String(e),{...C,fill:y,anchor:`middle`,"dominant-baseline":`middle`}));K=Q+14;let $=[];for(let[e,t]of k.entries()){let n=t.name||t.icon?t.name.split(`
|
|
5
|
+
`):[],r=K,i=r+(n.length?10+18*n.length:0),a=t.tasks.map(e=>{let t=te.get(e),n=Math.max(m.row,t.length*R+24),r={task:e,lines:t,y:i,height:n,mid:i+n/2};return i+=n,r});$.push({group:t,index:e,y:r,height:i-r,sectionLines:n,rows:a}),K=i+m.band}let ae=$.length?K-m.band:K;for(let e of $){if(!e.group.name)continue;let t=e.group.status?i.design[e.group.status]:i.color(`tone${e.index%6+1}`);N.push(i.rect(8,e.y,H+m.labelPad-8,e.height,{rx:l.radius,fill:i.tint(h,t,.06),meta:{kind:`frame`,id:`section:${e.index}`,...e.group.status?{status:e.group.status}:{}}}))}for(let t of $){t.sectionLines.forEach((e,n)=>{let r=n===0?M(t.group.icon):0,a=i.text(m.labelX+r,t.y+15+n*18,e,{...L,fill:y,"dominant-baseline":`middle`}),o=[...n===0&&t.group.icon?[x(i,t.group.icon,m.labelX,t.y+8)]:[],a];N.push(...j(t.group.link,o))});for(let{task:n,lines:r,mid:a}of t.rows){let t=M(n.icon);if(n.icon&&N.push(x(i,n.icon,m.labelX,a-f/2)),r.forEach((e,o)=>N.push(...j(n.link,[i.text(m.labelX+t,a+(o-(r.length-1)/2)*R,e,{...S,fill:v,"dominant-baseline":`middle`})]))),n.actors.length){let o=m.labelX+t+Math.max(0,...r.map(e=>F(e,S)))+10+m.chipR;n.actors.forEach((t,n)=>{let r=i.titled(i.circle(o+n*m.chip,a,m.chipR,{fill:I(t),stroke:h,"stroke-width":1}),t);N.push(...j(e.actorLinks?.[t],[r]))})}N.push(i.line(V,a,H,a,{stroke:_,"stroke-width":1}));let o=V+(n.score-1)*U,s=n.status?i.design[n.status]:g,c=i.circle(o,a,d,{fill:i.tint(h,s,.06),stroke:s,"stroke-width":1.4,role:`img`,"aria-label":`${n.name}: ${w} ${n.score}/${p}`,meta:{kind:`node`,id:n.id,...n.status?{status:n.status}:{}}});N.push(...j(n.link,[c]));for(let e of[-3,3])N.push(i.circle(o+e,a-2.5,1.2,{fill:y}));let l=n.score>3?`M${o-4} ${a+2} Q${o} ${a+7} ${o+4} ${a+2}`:n.score<3?`M${o-4} ${a+5.5} Q${o} ${a+.5} ${o+4} ${a+5.5}`:`M${o-4} ${a+3.5} L${o+4} ${a+3.5}`;N.push(i.path(l,{fill:`none`,stroke:g,"stroke-width":1.4,"stroke-linecap":`round`}))}}let oe=Math.ceil(Math.max(160,ae+m.bottom));return D.length>a?P.push((0,n.warning)(`LARGE_DIAGRAM`,t.lang||i.lang||`zh`,D[a].line,`旅程图有 ${D.length} 个任务,建议拆分`,`The journey has ${D.length} tasks; consider splitting it`,`按阶段拆成两张旅程图`,`Split the journey by stage`)):W>r*2&&P.push((0,n.warning)(`LARGE_DIAGRAM`,t.lang||i.lang||`zh`,1,`旅程图比给定宽度宽很多`,`The journey is much wider than the requested width`,`缩小任务名或拆分旅程图`,`Shorten task names or split the journey`)),{width:W,height:oe,scene:{width:W,height:oe,children:N,...e.title?{title:e.title}:{},...(o?.frame||c)&&e.title?{heading:e.title}:{}},errors:P}}return e.implementations={journey:{parse:b,layout:S,honoredConfig:s,acceptsPresentation:!0}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/kanban"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=new Map([[`Very High`,`danger`],[`High`,`warn`],[`Medium`,null],[`Low`,`info`],[`Very Low`,`info`]]),o=[[`((`,`))`],[`{{`,`}}`],[`))`,`((`],[`-)`,`(-`],[`(-`,`-)`],[`[`,`]`],[`(`,`)`],[`)`,`(`]],s=[`kanban.sectionWidth`,`kanban.padding`,`kanban.ticketBaseUrl`];function c(e){let t=new Map,n=/\s*([\w-]+)\s*:\s*("(?:\\.|[^"\\])*"|'(?:''|[^'])*'|[^,]+?)\s*(,|$)/y,r=0;for(;r<e.length;){n.lastIndex=r;let i=n.exec(e);if(!i)return null;let a=i[2].trim();t.set(i[1],a.startsWith(`"`)?a.slice(1,-1).replace(/\\(.)/g,`$1`):a.startsWith(`'`)?a.slice(1,-1).replace(/''/g,`'`):a),r=n.lastIndex}return t}function l(e,{lang:s,firstLine:l=2,title:u=``,config:d,options:f={}}){let p=[],m=[],h=new Map,g=new Set,_=(0,r.presentation)({lang:s}),v=e=>{g.has(e.message)||(g.add(e.message),m.push(e))},y=(e,t)=>{let r=(0,n.normalizeLabel)(e,{lang:s,line:t});return r.diagnostics.forEach(v),r},b=(e,t,n)=>m.push((0,i.error)(s,e,t,n,`修正列或卡片声明`,`Fix the column or card declaration`));Object.keys(f).length&&b(l-1,`kanban 不接受标题行选项`,`Unexpected kanban header option`);let x,S,C=0;for(let[n,r]of e.split(`
|
|
2
|
-
`).entries()){let e=l+n,u=r.trim();if(!u||u.startsWith(`%%`)||_.accept(u,e))continue;let d=/\s*(?:::icon\(([^()]+)\)|:::([\w-]+))$/,f,m,g=[];for(;f=d.exec(u);)f[2]?g.unshift(f[2]):m??=f[1].trim(),u=u.slice(0,f.index).trimEnd();if(!u&&(g.length||m)&&S){let n=S.cards.at(-1)||S;_.addClasses(n.key,g,e),m&&(n.icon=(0,t.resolveIconRef)(m)),m&&!n.icon&&v((0,i.warning)(`IGNORED_ASSET`,s,e,`未知图标 ${m}`,`Unknown icon ${m}`));continue}let w=/\s*@\{([\s\S]*)\}\s*$/.exec(u),T=w?c(w[1].trim()):new Map;w&&(u=u.slice(0,w.index).trimEnd());let E=u.search(/[\[({)]|-\)/),D=o.find(([e,t])=>E>=0&&u.slice(E).startsWith(e)&&u.endsWith(t));if(!T||!D&&(E>=0||!/^\S+$/.test(u))||/:::/.test(u.slice(0,E<0?u.length:E))){b(e,`无效的看板条目`,`Invalid kanban item`);continue}let O=D?u.slice(0,E).trim():u,k=y(T.get(`label`)??(D?u.slice(E+D[0].length,-D[1].length):O),e);m??=T.get(`icon`);let A=m&&(0,t.resolveIconRef)(m)||k.icon;m&&!(0,t.resolveIconRef)(m)&&v((0,i.warning)(`IGNORED_ASSET`,s,e,`未知图标 ${m}`,`Unknown icon ${m}`));let j=O||`kanban-item-${e}`;g.length&&_.addClasses(j,g,e);let M={id:O,key:j,label:k.text,icon:A},N=r.search(/\S/);if(x??=N,N<x){b(e,`缩进小于首列的 ${x} 个空格`,`Indentation is shallower than the first column (${x})`);continue}if(++C>2e3){b(e,`看板超过 2000 个条目,请拆分图表`,`Board exceeds 2000 items; split the diagram`);break}if(N===x){p.push(S={...M,cards:[],ids:new Set});continue}if(O&&S.ids.has(O)){b(e,`本列的卡片 ID 重复:${O}`,`Duplicate card ID in this column: ${O}`);continue}O&&S.ids.add(O);let P=T.get(`priority`);P&&!a.has(P)&&!h.has(P)&&h.set(P,e),S.cards.push({...M,line:e,ticket:y(T.get(`ticket`),e).text,assigned:y(T.get(`assigned`),e).text,priority:P})}for(let e of p)for(let t of[e,...e.cards])t.status=_.statusOf(t.key),t.link=_.linkOf(t.key);if(m.push(..._.diagnostics()),p.length||b(l,`缺少看板列`,`Expected at least one column`),h.size){let e=[...h.keys()].join(`, `);m.push((0,i.warning)(`DIAGRAM_HINT`,s,h.values().next().value,`未知优先级:${e}`,`Unknown priorities: ${e}`,`使用标准优先级`,`Use a standard priority`))}return{model:{type:`kanban`,columns:p,title:u,count:C,config:d?.kanban||{}},errors:m}}function u(e,t,n,r,i){let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c),u=t.set===`simple`;return e.el(`g`,{transform:`translate(${n-a*l} ${r-o*l}) scale(${l})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function d(e,{width:t,ctx:n,renderOptions:o},
|
|
2
|
+
`).entries()){let e=l+n,u=r.trim();if(!u||u.startsWith(`%%`)||_.accept(u,e))continue;let d=/\s*(?:::icon\(([^()]+)\)|:::([\w-]+))$/,f,m,g=[];for(;f=d.exec(u);)f[2]?g.unshift(f[2]):m??=f[1].trim(),u=u.slice(0,f.index).trimEnd();if(!u&&(g.length||m)&&S){let n=S.cards.at(-1)||S;_.addClasses(n.key,g,e),m&&(n.icon=(0,t.resolveIconRef)(m)),m&&!n.icon&&v((0,i.warning)(`IGNORED_ASSET`,s,e,`未知图标 ${m}`,`Unknown icon ${m}`));continue}let w=/\s*@\{([\s\S]*)\}\s*$/.exec(u),T=w?c(w[1].trim()):new Map;w&&(u=u.slice(0,w.index).trimEnd());let E=u.search(/[\[({)]|-\)/),D=o.find(([e,t])=>E>=0&&u.slice(E).startsWith(e)&&u.endsWith(t));if(!T||!D&&(E>=0||!/^\S+$/.test(u))||/:::/.test(u.slice(0,E<0?u.length:E))){b(e,`无效的看板条目`,`Invalid kanban item`);continue}let O=D?u.slice(0,E).trim():u,k=y(T.get(`label`)??(D?u.slice(E+D[0].length,-D[1].length):O),e);m??=T.get(`icon`);let A=m&&(0,t.resolveIconRef)(m)||k.icon;m&&!(0,t.resolveIconRef)(m)&&v((0,i.warning)(`IGNORED_ASSET`,s,e,`未知图标 ${m}`,`Unknown icon ${m}`));let j=O||`kanban-item-${e}`;g.length&&_.addClasses(j,g,e);let M={id:O,key:j,label:k.text,icon:A},N=r.search(/\S/);if(x??=N,N<x){b(e,`缩进小于首列的 ${x} 个空格`,`Indentation is shallower than the first column (${x})`);continue}if(++C>2e3){b(e,`看板超过 2000 个条目,请拆分图表`,`Board exceeds 2000 items; split the diagram`);break}if(N===x){p.push(S={...M,cards:[],ids:new Set});continue}if(O&&S.ids.has(O)){b(e,`本列的卡片 ID 重复:${O}`,`Duplicate card ID in this column: ${O}`);continue}O&&S.ids.add(O);let P=T.get(`priority`);P&&!a.has(P)&&!h.has(P)&&h.set(P,e),S.cards.push({...M,line:e,ticket:y(T.get(`ticket`),e).text,assigned:y(T.get(`assigned`),e).text,priority:P})}for(let e of p)for(let t of[e,...e.cards])t.status=_.statusOf(t.key),t.link=_.linkOf(t.key);if(m.push(..._.diagnostics()),p.length||b(l,`缺少看板列`,`Expected at least one column`),h.size){let e=[...h.keys()].join(`, `);m.push((0,i.warning)(`DIAGRAM_HINT`,s,h.values().next().value,`未知优先级:${e}`,`Unknown priorities: ${e}`,`使用标准优先级`,`Use a standard priority`))}return{model:{type:`kanban`,columns:p,title:u,count:C,config:d?.kanban||{}},errors:m}}function u(e,t,n,r,i){let[a,o,s,c]=t.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c),u=t.set===`simple`;return e.el(`g`,{transform:`translate(${n-a*l} ${r-o*l}) scale(${l})`,fill:u?i:`none`,stroke:u?`none`:i,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`},t.elements.map(({tag:t,attrs:n})=>e.shape(t,n)))}function d(e,{width:t,ctx:n,renderOptions:o,compact:s,embedHeading:c},l={}){let{columns:d,config:f,title:p,count:m}=e,h=(0,i.appearance)(n),g=Math.max(180,Math.min(560,Number(f.sectionWidth)||220)),_=Math.max(8,Math.min(28,Number(f.padding)||10)),v=d.length*(g+14)-14,y=Math.max(s?0:t,v+36),b=(y-v)/2,x=p&&!o?.frame&&!c,S=x?52:18,C=g-2*_,w=C-24,T=d.map(e=>n.wrap(e.label,C-(e.icon?22:0),i.FONT.title.size,i.FONT.title.weight)),E=Math.max(...T.map(e=>e.length))*18+22,D=[],O=[];x&&D.push(n.text(b,32,p,{...i.FONT.title,fill:h.fg1}));let k=d.map((e,t)=>{let o=b+t*(g+14),s=o+_,c=S+E,l=[...n.textLines(s+(e.icon?22:0),S+24,T[t],{...i.FONT.title,leading:18,fill:h.fg1}).children??[]];return e.icon&&l.push(u(n,e.icon,s,S+11,h[e.status]||h.fg1)),D.push(...e.link?[n.link(e.link.href,l,e.link)]:l),e.cards.forEach((e,o)=>{let l=D.length,d=e.icon?22:0,p=n.wrap(e.label,w-d,i.FONT.body.size),m=[e.ticket,e.assigned].map(e=>n.measure(e,i.FONT.label.size)),g=m[0]+m[1]+12<=w,_=e.ticket?n.wrap(e.ticket,w,i.FONT.label.size):[],v=e.assigned?n.wrap(e.assigned,w,i.FONT.label.size):[],y=g?Math.max(_.length,v.length):_.length+v.length,b=22+p.length*17+(y?5+y*16:0),x=c+17+p.length*17+5;D.push(n.rect(s,c,C,b,{rx:h.smallRadius,fill:e.status?n.tint(h.surface,h[e.status],.1):h.surface,stroke:h[e.status]||h.line,meta:{kind:`node`,id:`${t}:${o}`}}));let S=a.get(e.priority);if(S&&D.push(n.rect(s+1,c+7,4,b-14,{rx:2,fill:h[S],opacity:e.priority===`Very Low`?.4:1})),e.icon&&D.push(u(n,e.icon,s+12,c+6,h[e.status]||h.fg1)),D.push(...n.textLines(s+12+d,c+17,p,{...i.FONT.body,leading:17,fill:h.fg1}).children??[]),_.length){let t=n.textLines(s+12,x,_,i.FONT.label),a=typeof f.ticketBaseUrl==`string`&&f.ticketBaseUrl.replaceAll(`#TICKET#`,()=>encodeURIComponent(e.ticket)),o=a&&/^https?:\/\//i.test(a)&&(0,r.safeHref)(a);o&&!e.link?D.push(n.link(o,[t])):(D.push(t),a&&!o&&!O.some(e=>e.code===`IGNORED_INTERACTION`)&&O.push((0,i.warning)(`IGNORED_INTERACTION`,n.lang,e.line,`工单链接未启用`,`Ticket links are unavailable`,`使用安全的 HTTP(S) 工单地址`,`Use a safe HTTP(S) ticket URL`)))}D.push(...n.textLines(s+C-12,x+(g?0:_.length*16),v,{...i.FONT.label,anchor:`end`}).children??[]),e.link&&D.push(n.link(e.link.href,D.splice(l),e.link)),c+=b+8}),{x:o,h:c-S+_-(e.cards.length?8:0)}}),A=Math.max(...k.map(e=>e.h));D.unshift(...k.map(({x:e},t)=>n.rect(e,S,g,A,{rx:6,stroke:n.frameTone(h[d[t].status]||h.line),fill:`transparent`,meta:{kind:`frame`,id:`column:${t}`}})));let j=S+A+18;return(y>t*2||m>60)&&O.push((0,i.warning)(`LARGE_DIAGRAM`,n.lang,l.headerLine||1,`看板较大`,`Large kanban board`,`考虑拆分图表`,`Consider splitting the diagram`)),{width:y,height:j,scene:{width:y,height:j,children:D,title:p,heading:p},errors:O}}return e.implementations={kanban:{parse:l,layout:d,honoredConfig:s,acceptsPresentation:!0}},e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
KChartUnits["diagram/layers"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n={layers:8,groups:6,items:30,labelWidth:208},r=12,i=12,a=8,o=32,s=56,c=40,l=(e,n,r,i,a=`拆成两张图,或把说明移到图外`,o=`Split into two diagrams, or move descriptions outside the diagram`)=>(0,t.error)(e,n,r,i,a,o);function u(e,r){let i={...r,lang:r.lang,firstLine:r.firstLine,options:r.options||{}},{items:a,errors:o}=(0,t.parseIndented)(e,i),{lang:s,options:c}=i;for(let e of Object.keys(c))o.push(l(s,i.firstLine-1,`layers 不支持选项「${e}」`,`Unsupported layers option: ${e}`,`移除这个选项`,`Remove this option`));let u=a.map(e=>/[::]/.test(e.text.split(`|`)[0])||!e.text.includes(`|`)&&e.children.some(e=>/^[^::>]+>/.test(e.text)));u.some(Boolean)&&u.some(e=>!e)&&o.push(l(s,a[u.findIndex(e=>e!==u[0])].line,`顶层不能混用层与分组`,`Do not mix layers and groups at the top level`,`顶层全部写成层,或全部写成分组`,`Use only layers or only groups at the top level`));function d(e,t){return e.split(/[,,]/).map(e=>{let n=e.trim(),r=n.match(/^([+~=])\s*/)?.[1]||``;return n&&n.replace(/^[+~=]\s*/,``)||o.push(l(s,t,`能力项名称不能为空`,`Capability labels cannot be empty`,`删除空项或补上名称`,`Remove the empty item or add a label`)),{label:r?`${r} ${n.replace(/^[+~=]\s*/,``)}`:n,mark:r,tone:{"+":`new`,"~":`info`,"=":`ok`}[r]||``,line:t}})}function f(e){let t=e.text.split(/[::]/),r=t.shift().trim(),i=r.match(/\s*\{(db|ext)\}$/)?.[1]||``,a=r.replace(/\s*\{(db|ext)\}$/,``).trim();(!a||/[{}|>]/.test(a))&&o.push(l(s,e.line,`分组名称或标志无效`,`Invalid group name or flag`,`使用「名称 {db}: 项, 项」或普通名称`,`Use "Name {db}: item, item" or a plain name`));let c={title:a,flag:i,line:e.line,items:[],categories:[]};if(t.length)c.items=d(t.join(`:`),e.line),e.children.length&&o.push(l(s,e.children[0].line,`行内能力项不能再带子项`,`Inline capabilities cannot have children`,`改成分类行写法,或删除子项`,`Use category rows, or remove the children`));else{e.children.length||o.push(l(s,e.line,`分组中没有能力项`,`Group has no capabilities`,`在名称后加「: 项, 项」,或添加分类行`,`Add ": item, item" or category rows`));for(let t of e.children){let e=t.text.match(/^(.+?)\s*>\s*(.+)$/);if(!e||t.children.length){o.push(l(s,t.children[0]?.line||t.line,`分类行写法无效`,`Invalid category row`,`使用「- 分类 > 项, 项」,不嵌套子项`,`Use "- Category > item, item" without nesting`));continue}let n={label:e[1].trim(),line:t.line,items:d(e[2],t.line)};c.categories.push(n),c.items.push(...n.items)}}return c.items.length>n.items&&o.push(l(s,e.line,`每组最多 ${n.items} 项`,`At most ${n.items} capabilities per group`)),c}let p=!u.some(Boolean),m=p?a.map(e=>{let[t,...r]=e.text.split(`|`).map(e=>e.trim());return(!t||/[{}>]/.test(t))&&o.push(l(s,e.line,`层名称无效`,`Invalid layer name`,`使用「- 层名 | 说明」`,`Use "- Layer | description"`)),e.children.length||o.push(l(s,e.line,`层中没有分组`,`Layer has no groups`,`给这一层添加分组和能力项`,`Add groups and capabilities to this layer`)),e.children.length>n.groups&&o.push(l(s,e.line,`每层最多 ${n.groups} 组`,`At most ${n.groups} groups per layer`)),{title:t,description:r.join(` | `),line:e.line,groups:e.children.map(f)}}):[],h=p?[]:a.map(f);return a.length||o.push(l(s,i.firstLine,`图中没有条目`,`Diagram is empty`,`添加层、分组与能力项`,`Add layers, groups and capabilities`)),p&&m.length>n.layers&&o.push(l(s,a[n.layers].line,`最多 ${n.layers} 层`,`At most ${n.layers} layers`)),{model:{type:`layers`,layered:p,layers:m,groups:h},errors:o}}function d(e,{measure:u,width:d,lang:f}){let
|
|
1
|
+
KChartUnits["diagram/layers"]=(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n={layers:8,groups:6,items:30,labelWidth:208},r=12,i=12,a=8,o=32,s=56,c=40,l=(e,n,r,i,a=`拆成两张图,或把说明移到图外`,o=`Split into two diagrams, or move descriptions outside the diagram`)=>(0,t.error)(e,n,r,i,a,o);function u(e,r){let i={...r,lang:r.lang,firstLine:r.firstLine,options:r.options||{}},{items:a,errors:o}=(0,t.parseIndented)(e,i),{lang:s,options:c}=i;for(let e of Object.keys(c))o.push(l(s,i.firstLine-1,`layers 不支持选项「${e}」`,`Unsupported layers option: ${e}`,`移除这个选项`,`Remove this option`));let u=a.map(e=>/[::]/.test(e.text.split(`|`)[0])||!e.text.includes(`|`)&&e.children.some(e=>/^[^::>]+>/.test(e.text)));u.some(Boolean)&&u.some(e=>!e)&&o.push(l(s,a[u.findIndex(e=>e!==u[0])].line,`顶层不能混用层与分组`,`Do not mix layers and groups at the top level`,`顶层全部写成层,或全部写成分组`,`Use only layers or only groups at the top level`));function d(e,t){return e.split(/[,,]/).map(e=>{let n=e.trim(),r=n.match(/^([+~=])\s*/)?.[1]||``;return n&&n.replace(/^[+~=]\s*/,``)||o.push(l(s,t,`能力项名称不能为空`,`Capability labels cannot be empty`,`删除空项或补上名称`,`Remove the empty item or add a label`)),{label:r?`${r} ${n.replace(/^[+~=]\s*/,``)}`:n,mark:r,tone:{"+":`new`,"~":`info`,"=":`ok`}[r]||``,line:t}})}function f(e){let t=e.text.split(/[::]/),r=t.shift().trim(),i=r.match(/\s*\{(db|ext)\}$/)?.[1]||``,a=r.replace(/\s*\{(db|ext)\}$/,``).trim();(!a||/[{}|>]/.test(a))&&o.push(l(s,e.line,`分组名称或标志无效`,`Invalid group name or flag`,`使用「名称 {db}: 项, 项」或普通名称`,`Use "Name {db}: item, item" or a plain name`));let c={title:a,flag:i,line:e.line,items:[],categories:[]};if(t.length)c.items=d(t.join(`:`),e.line),e.children.length&&o.push(l(s,e.children[0].line,`行内能力项不能再带子项`,`Inline capabilities cannot have children`,`改成分类行写法,或删除子项`,`Use category rows, or remove the children`));else{e.children.length||o.push(l(s,e.line,`分组中没有能力项`,`Group has no capabilities`,`在名称后加「: 项, 项」,或添加分类行`,`Add ": item, item" or category rows`));for(let t of e.children){let e=t.text.match(/^(.+?)\s*>\s*(.+)$/);if(!e||t.children.length){o.push(l(s,t.children[0]?.line||t.line,`分类行写法无效`,`Invalid category row`,`使用「- 分类 > 项, 项」,不嵌套子项`,`Use "- Category > item, item" without nesting`));continue}let n={label:e[1].trim(),line:t.line,items:d(e[2],t.line)};c.categories.push(n),c.items.push(...n.items)}}return c.items.length>n.items&&o.push(l(s,e.line,`每组最多 ${n.items} 项`,`At most ${n.items} capabilities per group`)),c}let p=!u.some(Boolean),m=p?a.map(e=>{let[t,...r]=e.text.split(`|`).map(e=>e.trim());return(!t||/[{}>]/.test(t))&&o.push(l(s,e.line,`层名称无效`,`Invalid layer name`,`使用「- 层名 | 说明」`,`Use "- Layer | description"`)),e.children.length||o.push(l(s,e.line,`层中没有分组`,`Layer has no groups`,`给这一层添加分组和能力项`,`Add groups and capabilities to this layer`)),e.children.length>n.groups&&o.push(l(s,e.line,`每层最多 ${n.groups} 组`,`At most ${n.groups} groups per layer`)),{title:t,description:r.join(` | `),line:e.line,groups:e.children.map(f)}}):[],h=p?[]:a.map(f);return a.length||o.push(l(s,i.firstLine,`图中没有条目`,`Diagram is empty`,`添加层、分组与能力项`,`Add layers, groups and capabilities`)),p&&m.length>n.layers&&o.push(l(s,a[n.layers].line,`最多 ${n.layers} 层`,`At most ${n.layers} layers`)),{model:{type:`layers`,layered:p,layers:m,groups:h},errors:o}}function d(e,{measure:u,width:d,lang:f,compact:p}){let m=[],h=[],g=[],_=[],v=e.layered?e.layers.flatMap(e=>e.groups):e.groups;for(let e of v)for(let r of e.items)u(r.label.replace(/^[+~=]\s*/,``),t.FONT.body)>n.labelWidth&&m.push(l(f,r.line,`能力项「${r.label}」过长`,`Capability label is too long: ${r.label}`,`把说明移到图外,名称缩短至约 16 个汉字`,`Move descriptions outside; shorten the label to about 16 CJK characters`));if(m.length)return{width:d,height:0,errors:m};let y=(e,n)=>(0,t.snap)(Math.max(e.flag===`db`?80:64,...e.items.map(e=>u(e.label,t.FONT.body)+n))),b=(e,t)=>e.flag===`db`?Math.max(1,Math.round((t*o+(t-1)*a)/64)):t,x=(e,t)=>Math.max(1,Math.ceil(e.items.length/b(e,t))),S=e=>(0,t.snap)(Math.max(0,...e.categories.map(e=>u(e.label,t.FONT.body)))+16);function C(e,n,r){let i;if(e.categories.length)i=S(e)+a+Math.max(...e.categories.map(e=>e.items.reduce((e,n)=>e+(0,t.snap)(Math.max(64,u(n.label,t.FONT.body)+r)),0)+a*(e.items.length-1)));else{let t=x(e,n);i=t*y(e,r)+a*(t-1)}return(0,t.snap)(Math.max(i,u(e.title,t.FONT.title))+24)}let w=(e,t)=>52+(e.categories.length?e.categories.length*(e.flag===`db`?s:o)+(e.categories.length-1)*a:b(e,t)*(e.flag===`db`?s:o)+(b(e,t)-1)*a),T=(e,t,n)=>e.reduce((e,r)=>e+C(r,t,n),0)+r*(e.length-1);function E(e,t,n){let r=Math.max(0,n-e.reduce((e,t)=>e+t,0)),i=t.reduce((e,t)=>e+t,0),a=e.map((e,n)=>e+Math.floor(r*t[n]/i/4)*4);return a[a.length-1]+=n-a.reduce((e,t)=>e+t,0),a}let D=0;function O(e,n,r,l,d,f,m){let g={...e,x:n,y:r,w:l,h:d,rows:f,color:m,id:`group-${D++}`,nodes:[],categoryNodes:[]};h.push(g);let v=(t,n,r,i,a,o=!1)=>{let s={...t,x:n,y:r,w:i,h:a,shape:!o&&e.flag===`db`?`db`:`rect`,group:g.id,category:o,color:m};_.push(s),(o?g.categoryNodes:g.nodes).push(s)},b=l-24;if(e.categories.length){let l=S(e),d=e.flag===`db`?s:o;e.categories.forEach((e,o)=>{let s=r+c+o*(d+a);v({label:e.label,line:e.line},n+i,s,l,d,!0);let f=e.items.map(e=>(0,t.snap)(Math.max(64,u(e.label,t.FONT.body)+16))),m=p?f:E(f,f.map(e=>e+8),b-l-a*e.items.length),h=n+i+l+a;e.items.forEach((e,t)=>{v(e,h,s,m[t],d),h+=m[t]+a})})}else{let t=x(e,f),u=e.flag===`db`?s:o,d=Math.ceil(e.items.length/t),m=r+c;for(let r=0;r<d;r+=1){let o=e.items.slice(r*t,(r+1)*t),s=e.flag===`db`,c=s||p?t:o.length,d=p?y(e,16):Math.floor((b-(c-1)*a)/c/4)*4,f=n+i+(s?Math.floor((b-(o.length*d+(o.length-1)*a))/8)*4:0);o.forEach((e,t)=>{let c=!s&&!p&&t===o.length-1?n+l-i-f:d;v(e,f,m+r*(u+a),c,u),f+=d+a})}}return g}let k=Math.floor(d),A=4;if(e.layered){let i=e=>u(e.title,t.FONT.title)+16,a=e=>e.description?Math.min(120,u(e.description,t.FONT.label)+8):0,o=(0,t.snap)(Math.max(80,...e.layers.map(e=>Math.max(i(e),a(e))))),s=Math.min(o,160);o>160&&e.layers.some(e=>i(e)>160)&&m.push(l(f,e.layers.find(e=>i(e)>160).line,`层名称过长`,`Layer name is too long`,`缩短层名,把说明放在「|」之后`,`Shorten the name; put descriptions after "|"`));let c=4+s+r;for(let t of e.layers)k=Math.max(k,c+T(t.groups,n.items*2,16)+4);let d=k-c-4;for(let i of e.layers){let e=1;for(;e<n.items*2&&T(i.groups,e,16)>d;)e+=1;let a=i.groups.map(t=>C(t,e,16)),o=i.groups.map(t=>C(t,e,24)),l=p?a:E(a,o,d-r*(i.groups.length-1)),f=i.description?(0,t.wrapText)(i.description,s-8,t.FONT.label,u):[],m=Math.max(...i.groups.map(t=>w(t,e)),32+f.length*16),h=g.length%6+1;g.push({...i,x:4,y:A,w:s,h:m,rows:e,color:h,descriptionLines:f});let _=c;i.groups.forEach((t,n)=>{O(t,_,A,l[n],m,e,h),_+=l[n]+r}),A+=m+16}}else{for(let t of e.groups)k=Math.max(k,C(t,n.items*2,16)+8);let t=k-8,i=new Map(e.groups.map(e=>{let r=1;for(;!e.categories.length&&r<n.items*2&&C(e,r,16)>t;)r+=1;return[e,r]})),a=e=>i.get(e),o=[],s=[];for(let n of e.groups)s.length&&s.reduce((e,t)=>e+C(t,a(t),16),0)+r*s.length+C(n,a(n),16)>t&&(o.push(s),s=[]),s.push(n);s.length&&o.push(s);for(let n of o){let i=n.map(e=>C(e,a(e),16)),o=p?i:E(i,n.map(e=>C(e,a(e),24)),t-r*(n.length-1)),s=Math.max(...n.map(e=>w(e,a(e)))),c=4;n.forEach((t,n)=>{O(t,c,A,o[n],s,a(t),e.groups.indexOf(t)%6+1),c+=o[n]+r}),A+=s+16}}return{type:`layers`,width:k,height:A-12,layers:g,groups:h,nodes:_,errors:m}}function f(e,n){let r=[],i=(0,t.appearance)(n),a=e=>n.frameTone(n.color(`tone${e}`)),o=(e,t,r,i,a)=>n.text(e,t,r,{size:i.size,weight:i.weight,fill:a,anchor:`middle`,"dominant-baseline":`central`}),s=(e,r)=>{let a=e.tone&&e.label.match(/^([+~=])\s/);if(!a)return o(e.x+e.w/2,r,e.label,t.FONT.body,i.fg1);let s=e.x+e.w/2-n.measure(e.label,t.FONT.body.size,t.FONT.body.weight)/2,c=n.measure(a[1],t.FONT.body.size,t.FONT.body.weight);return n.el(`g`,{},[n.text(s,r,a[1],{size:t.FONT.body.size,weight:t.FONT.body.weight,fill:i[e.tone],anchor:`start`,"dominant-baseline":`central`}),n.text(s+c,r,e.label.slice(1),{size:t.FONT.body.size,weight:t.FONT.body.weight,fill:i.fg1,anchor:`start`,"dominant-baseline":`central`})])};for(let s of e.groups){let e=a(s.color),c=n.tint(i.bg,e,.07),l=n.tint(i.bg,e,.45);r.push(n.rect(s.x,s.y,s.w,s.h,{rx:i.radius,fill:c,stroke:l,"stroke-width":1,"stroke-dasharray":s.flag===`ext`?`5 4`:void 0,meta:{kind:`layers`,group:s.id,role:`group`}})),r.push(o(s.x+s.w/2,s.y+20,s.title,t.FONT.title,i.fg1))}for(let n of e.layers){let e=n.y+n.h/2,a=n.descriptionLines.length*16,s=e-(20+(a?a+4:0))/2;r.push(o(n.x+n.w/2,s+10,n.title,t.FONT.title,i.fg1)),n.descriptionLines.forEach((e,a)=>r.push(o(n.x+n.w/2,s+20+4+(a+.5)*16,e,t.FONT.label,i.fg2)))}for(let t of e.nodes){let e=t.tone?i[t.tone]:a(t.color),o=t.tone?n.mix:n.tint,c=t.category?o(i.bg,e,.08):i.node,l=o(i.bg,e,.4),u={fill:c,stroke:l,"stroke-width":1,"stroke-dasharray":t.category?`5 4`:void 0,meta:{kind:`layers`,group:t.group,line:t.line,role:t.category?`category`:`capability`}};if(t.shape===`db`){let{x:e,y:i,w:a,h:o}=t;r.push(n.path(`M${e} ${i+8} a${a/2} 8 0 0 1 ${a} 0 V${i+o-8} a${a/2} 8 0 0 1 ${-a} 0 Z`,{...u,meta:{...u.meta,shape:`database`}})),r.push(n.path(`M${e} ${i+8} a${a/2} 8 0 0 0 ${a} 0`,{fill:`none`,stroke:l,"stroke-width":1,meta:{...u.meta,role:`database-rim`}}))}else r.push(n.rect(t.x,t.y,t.w,t.h,{rx:i.smallRadius,...u}));r.push(s(t,t.y+t.h/2+(t.shape===`db`?4:0)))}return{width:e.width,height:e.height,children:r}}return e.implementations={layers:{parse:u,layout:d,scene:f}},e.limits=n,e})({},KChartUnits[`diagram/support`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/mindmap"]=(function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=2e3,l=100,u=[`bilateral`,`right`,`left`,`radial`,`org`,`brace`,`fishbone`,`timeline`],d=new Set([`tidy-tree`,`dagre`,`elk`,`cose-bilkent`]),f=[[`((`,`))`,`circle`],[`))`,`((`,`bang`],[`{{`,`}}`,`hexagon`],[`-)`,`(-`,`cloud`],[`(-`,`-)`,`cloud`],[`[`,`]`,`rect`],[`(`,`)`,`rounded`],[`)`,`(`,`cloud`]],p=/[()[\]{}]|-\)|\(-/,m=e=>e.length>1&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e;function h(e){let t=e.trim(),n=t.search(p);if(n<0)return{label:m(t).trim(),shape:`none`};for(let[e,r,i]of f)if(!(!t.startsWith(e,n)||!t.endsWith(r)||t.length<n+e.length+r.length))return{label:m(t.slice(n+e.length,t.length-r.length).trim()).trim(),shape:i};return{label:t,shape:``}}function g(e,n,r,i){let a=[];for(let[o,s]of e.entries()){if(!s.trim()||s.trimStart().startsWith(`%%`))continue;let e=n+o;if(/^[ \t]*\t/.test(s)){i.push((0,t.error)(r,e,`缩进不能使用 Tab`,`Tabs are not allowed in indentation`,`把 Tab 换成空格`,`Replace tabs with spaces`));continue}let c=s.match(/^ */)[0].length;a.push({text:s.slice(c).trimEnd(),line:e,indent:c})}return a}function _(e,a={}){let f=a.lang||`zh`,m=Number.isInteger(a.firstLine)?a.firstLine:2,_=a.headerLine||m-1,v=[],y=(e,n,r,i=`修正脑图语法后重试`,a=`Correct the mindmap syntax and try again`,o=1)=>{v.push((0,t.error)(f,e,n,r,i,a,o))},b=String(e??``).split(`
|
|
2
|
-
`),x=(0,n.presentation)({lang:f}),S=new Set,C=new Map,w=e=>{S.has(e.message)||(S.add(e.message),v.push(e))},T=new Map,E=-1;for(let e=0;e<b.length;e+=1){let n=b[e].trim();if(n&&!n.startsWith(`%%`)){if(x.accept(n,m+e))b[e]=``;else if(/^(?::::|::icon\b)/i.test(n)){b[e]=``;let r=/^:::\s*([\w-]+(?:\s+[\w-]+)*)$/.exec(n)?.[1],a=/^::icon\(\s*([^()]+?)\s*\)$/i.exec(n)?.[1];if(E<0||!r&&!a)y(m+e,`脑图装饰无效或前面缺少节点`,`Malformed mindmap decoration or missing preceding node`);else{let n=T.get(E)||{classes:[]};r&&n.classes.push(...r.split(/\s+/)),a&&(n.icon=(0,i.resolveIconRef)(a),n.icon||w((0,t.warning)(`IGNORED_ASSET`,f,m+e,`未知图标 ${a}`,`Unknown icon ${a}`,`改用内置图标`,`Use a supported icon`))),T.set(E,n)}}else E=e}}let D=g(b,m,f,v),O=[],k=[],A=new Map,j=0,M=0;for(let e of D){for(;k.length&&e.indent<=k.at(-1).indent;)k.pop();let t=k.at(-1)?.node??null,n=k.length;M=Math.max(M,n+1);let{label:i,shape:a}=h(e.text),o=(a===`none`?``:e.text.split(p,1)[0].trim())||i,s=(0,r.normalizeLabel)(i,{lang:f,line:e.line});s.diagnostics.forEach(w);let u=s.text||(s.icon?o||` `:``);j+=1,j===2001&&y(e.line,`脑图超过安全上限 ${c} 个节点`,`Mindmap exceeds the safety cap of ${c} nodes`,`拆分脑图后重试`,`Split the mindmap and try again`),n>=l&&y(e.line,`脑图超过安全深度上限 ${l} 层`,`Mindmap exceeds the safety depth cap of ${l}`,`拆分脑图或降低层级`,`Split the mindmap or reduce its depth`),/:::(?:[\w-]+)?|::icon\(/i.test(e.text)&&y(e.line,`不支持行内节点装饰`,`Inline node decorations are unsupported`,`在节点下一行使用受控 :::状态 标记`,`Use a supported :::status marker on the next line`),u||y(e.line,`节点名称不能为空`,`Node label cannot be empty`);let d={label:u,children:[]};a&&(d.shape=a);let g=T.get(e.line-m);g?.classes.length&&x.addClasses(o,g.classes,e.line),C.set(d,{id:o,icon:g?.icon||s.icon});let _=t?t.children.length:O.length;A.set(t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`,e.line);let v=t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`;t?t.children.push(d):O.length?(y(e.line,`mindmap 只能有一个根节点:「${u}」没有父节点`,`A mindmap can have only one root: "${u}" has no parent`,`把该节点缩进到更浅一级的节点下面`,`Indent this node under a shallower node`),O[0].children.push(d)):O.push(d),k.push({indent:e.indent,node:d,path:v})}O.length||y(m,`脑图中没有节点`,`Mindmap is empty`,`保留一个根节点并将其他节点缩进到它下面`,`Keep one root node and indent all other nodes beneath it`);let N=a.config?.layout??a.config?.mindmap?.layoutAlgorithm??(typeof a.layout==`string`?a.layout:a.layout?.config?.layout??a.layout?.layout),P=`bilateral`;if(N!=null&&N!==``){let e=String(N).toLowerCase();d.has(e)?P=`bilateral`:u.includes(e)?P=e:v.push((0,t.warning)(`IGNORED_CONFIG`,f,_,`脑图布局「${N}」不生效;按 bilateral 排版`,`Mindmap layout "${N}" is not honored; laid out as bilateral`,`改用 bilateral、right、left、radial、org、brace、fishbone 或 timeline`,`Use bilateral, right, left, radial, org, brace, fishbone, or timeline`))}for(let e of Object.keys(a.options||{}))y(_,`脑图头行不支持选项「${e}」`,`Mindmap header option is unsupported: ${e}`,`移除头行选项,使用 config.layout 指定布局`,`Remove the header option; use config.layout to choose a layout`);let F=O[0]||{label:``};A.has(`/roots/0`)&&A.set(`/data`,A.get(`/roots/0`)),v.push(...x.diagnostics());for(let[e,{id:t,icon:n}]of C){let r=x.statusOf(t);r&&(e.status=r),e[s.mindmapPresentation]={icon:n,link:x.linkOf(t)}}let I={chart:`mindmap`,data:F,layout:P,[s.mindmapPresentation]:!0,[o.sizeBudget]:{nodes:2001,depth:101}};Object.defineProperties(I,{nodeCount:{value:j},maxDepth:{value:M}}),a.title&&(I.title=a.title);let L=(0,o.validate)(I);for(let e of L.errors){let n=``,r=m;for(let t of e.path.split(`/`).slice(1))n+=`/${t}`,A.has(n)&&(r=A.get(n));v.push({...(0,t.error)(f,r,e.message,e.message,e.fix,e.fix),code:e.code,path:e.path})}return{model:I,errors:v}}var v=(0,a.createRegistry)(o.validate);v.register(`mindmap`,a.layouts.get(`mindmap`));function y(e,n={},r={}){let i=e.nodeCount>80&&e.layout!==`radial`,a=v.layout(i?{...e,layout:`radial`}:e,n.
|
|
2
|
+
`),x=(0,n.presentation)({lang:f}),S=new Set,C=new Map,w=e=>{S.has(e.message)||(S.add(e.message),v.push(e))},T=new Map,E=-1;for(let e=0;e<b.length;e+=1){let n=b[e].trim();if(n&&!n.startsWith(`%%`)){if(x.accept(n,m+e))b[e]=``;else if(/^(?::::|::icon\b)/i.test(n)){b[e]=``;let r=/^:::\s*([\w-]+(?:\s+[\w-]+)*)$/.exec(n)?.[1],a=/^::icon\(\s*([^()]+?)\s*\)$/i.exec(n)?.[1];if(E<0||!r&&!a)y(m+e,`脑图装饰无效或前面缺少节点`,`Malformed mindmap decoration or missing preceding node`);else{let n=T.get(E)||{classes:[]};r&&n.classes.push(...r.split(/\s+/)),a&&(n.icon=(0,i.resolveIconRef)(a),n.icon||w((0,t.warning)(`IGNORED_ASSET`,f,m+e,`未知图标 ${a}`,`Unknown icon ${a}`,`改用内置图标`,`Use a supported icon`))),T.set(E,n)}}else E=e}}let D=g(b,m,f,v),O=[],k=[],A=new Map,j=0,M=0;for(let e of D){for(;k.length&&e.indent<=k.at(-1).indent;)k.pop();let t=k.at(-1)?.node??null,n=k.length;M=Math.max(M,n+1);let{label:i,shape:a}=h(e.text),o=(a===`none`?``:e.text.split(p,1)[0].trim())||i,s=(0,r.normalizeLabel)(i,{lang:f,line:e.line});s.diagnostics.forEach(w);let u=s.text||(s.icon?o||` `:``);j+=1,j===2001&&y(e.line,`脑图超过安全上限 ${c} 个节点`,`Mindmap exceeds the safety cap of ${c} nodes`,`拆分脑图后重试`,`Split the mindmap and try again`),n>=l&&y(e.line,`脑图超过安全深度上限 ${l} 层`,`Mindmap exceeds the safety depth cap of ${l}`,`拆分脑图或降低层级`,`Split the mindmap or reduce its depth`),/:::(?:[\w-]+)?|::icon\(/i.test(e.text)&&y(e.line,`不支持行内节点装饰`,`Inline node decorations are unsupported`,`在节点下一行使用受控 :::状态 标记`,`Use a supported :::status marker on the next line`),u||y(e.line,`节点名称不能为空`,`Node label cannot be empty`);let d={label:u,children:[]};a&&(d.shape=a);let g=T.get(e.line-m);g?.classes.length&&x.addClasses(o,g.classes,e.line),C.set(d,{id:o,icon:g?.icon||s.icon});let _=t?t.children.length:O.length;A.set(t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`,e.line);let v=t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`;t?t.children.push(d):O.length?(y(e.line,`mindmap 只能有一个根节点:「${u}」没有父节点`,`A mindmap can have only one root: "${u}" has no parent`,`把该节点缩进到更浅一级的节点下面`,`Indent this node under a shallower node`),O[0].children.push(d)):O.push(d),k.push({indent:e.indent,node:d,path:v})}O.length||y(m,`脑图中没有节点`,`Mindmap is empty`,`保留一个根节点并将其他节点缩进到它下面`,`Keep one root node and indent all other nodes beneath it`);let N=a.config?.layout??a.config?.mindmap?.layoutAlgorithm??(typeof a.layout==`string`?a.layout:a.layout?.config?.layout??a.layout?.layout),P=`bilateral`;if(N!=null&&N!==``){let e=String(N).toLowerCase();d.has(e)?P=`bilateral`:u.includes(e)?P=e:v.push((0,t.warning)(`IGNORED_CONFIG`,f,_,`脑图布局「${N}」不生效;按 bilateral 排版`,`Mindmap layout "${N}" is not honored; laid out as bilateral`,`改用 bilateral、right、left、radial、org、brace、fishbone 或 timeline`,`Use bilateral, right, left, radial, org, brace, fishbone, or timeline`))}for(let e of Object.keys(a.options||{}))y(_,`脑图头行不支持选项「${e}」`,`Mindmap header option is unsupported: ${e}`,`移除头行选项,使用 config.layout 指定布局`,`Remove the header option; use config.layout to choose a layout`);let F=O[0]||{label:``};A.has(`/roots/0`)&&A.set(`/data`,A.get(`/roots/0`)),v.push(...x.diagnostics());for(let[e,{id:t,icon:n}]of C){let r=x.statusOf(t);r&&(e.status=r),e[s.mindmapPresentation]={icon:n,link:x.linkOf(t)}}let I={chart:`mindmap`,data:F,layout:P,[s.mindmapPresentation]:!0,[o.sizeBudget]:{nodes:2001,depth:101}};Object.defineProperties(I,{nodeCount:{value:j},maxDepth:{value:M}}),a.title&&(I.title=a.title);let L=(0,o.validate)(I);for(let e of L.errors){let n=``,r=m;for(let t of e.path.split(`/`).slice(1))n+=`/${t}`,A.has(n)&&(r=A.get(n));v.push({...(0,t.error)(f,r,e.message,e.message,e.fix,e.fix),code:e.code,path:e.path})}return{model:I,errors:v}}var v=(0,a.createRegistry)(o.validate);v.register(`mindmap`,a.layouts.get(`mindmap`));function y(e,n={},r={}){let i=e.nodeCount>80&&e.layout!==`radial`,a=n.renderOptions||n,o=v.layout(i?{...e,layout:`radial`}:e,n.compact?{...a,width:n.width}:a),s=n.width||800,c=e.nodeCount>60||e.maxDepth>5||o.width>s*2?[(0,t.warning)(`LARGE_DIAGRAM`,r.lang||n.lang||`zh`,r.firstLine||1,i?`大型脑图使用径向布局以避免重叠`:`脑图较大,可在图内滚动查看`,i?`Large mindmap uses radial layout to avoid overlaps`:`Large mindmap; scroll within the figure`,`拆分脑图以便阅读`,`Split the mindmap for readability`)]:[];return{width:o.width,height:o.height,scene:o,errors:c}}return e.implementations={mindmap:{acceptsPresentation:!0,honoredConfig:[`layout`,`mindmap.layoutAlgorithm`],parse:_,layout:y,scene:e=>e.scene}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/label`],KChartUnits[`core/icons`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`],KChartUnits[`chart/mindmap`]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
KChartUnits["diagram/numeric-composition"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function s(e,t,r,i){return{...i,parse:e,validate:(e,i)=>(0,n.validateWith)(t(e,i),i,t=>r(e,t.path)),layout
|
|
1
|
+
KChartUnits["diagram/numeric-composition"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function s(e,t,r,i){return{...i,parse:e,validate:(e,i)=>(0,n.validateWith)(t(e,i),i,t=>r(e,t.path)),layout(e,i,a){let o=i.compact?Math.min(560,Math.max(360,290+e.rows.length*24)):i.width;return(0,n.renderWith)(t(e,a,i.compact===!0),{...i,width:o},a,t=>r(e,t.path))}}}var c=s(t.parsePie,(e,t,n)=>({chart:`pie`,title:e.title||void 0,sliceLabels:!0,data:e.rows.map(({category:e,value:t})=>({category:e,value:t})),encode:{category:`category`,value:`value`},[r.compositionPresentation]:{labelRadius:e.labelRadius,...n?{compact:!0}:{}}}),(e,t)=>t===`/title`?e.titleLine:e.rows[Number(t?.split(`/`)[2])]?.line||e.rows[0]?.line,{optionMode:`raw`,honoredConfig:[`pie.textPosition`]}),l=(e,n)=>({chart:`treemap`,title:e.title||void 0,data:e.data,fields:e.valueField?{value:e.valueField}:void 0,[r.compositionPresentation]:{showValues:n.config?.treemap?.showValues!==!1,prefix:e.prefix,namedRoot:e.namedRoot},[a.sizeBudget]:{nodes:t.TREEMAP_MAX_NODES+1,depth:t.TREEMAP_MAX_DEPTH+1}}),u=(e,t)=>{if(t===`/title`)return e.titleLine;for(let n=t;n;n=n.slice(0,n.lastIndexOf(`/`))){if(e.treeLines[n])return e.treeLines[n];if(!n.includes(`/`))break}return null},d=(0,i.createRegistry)(a.validate);return d.register(`treemap`,i.layouts.get(`treemap`)),e.implementations={pie:c,treemap:{parse:t.parseTreemap,acceptsPresentation:!0,honoredConfig:[`treemap.showValues`,`treemap.valueFormat`],validate(e,t){let r=l(e,t);return(0,n.diagnostics)((0,a.validate)(r).errors,t,t=>u(e,t.path))},layout(e,t,i){let a=t.compact===!0,s=l(e,i),c=t=>u(e,t.path);a&&(s[r.compositionPresentation]={...s[r.compositionPresentation],compact:!0});let f=e.data.children?.length===1&&!e.data.children[0]?.children?.length,p=a?f?256:Math.min(640,480+Math.max(0,e.nodeCount-1)*10):t.width,m=a?{...t,width:p}:t,h=(0,n.renderWith)(s,m,i,c,d.layout);return h.scene&&(e.nodeCount>60||e.depth>5||h.width>t.width*2)&&h.errors.push((0,o.warning)(`LARGE_DIAGRAM`,i.lang,i.headerLine,`矩形树图较大,可滚动查看`,`Large treemap; scroll to view it`,`考虑拆分图表`,`Consider splitting the chart`)),h}}},e})({},KChartUnits[`diagram/numeric-parse`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/composition`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`],KChartUnits[`diagram/support`]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
KChartUnits["diagram/numeric-model"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e,n,r){return e.map(e=>(0,t.error)(n.lang,r(e)||n.firstLine,e.message||`KChart 声明无效`,e.message||`Invalid KChart declaration`,e.fix||`修正图表声明`,e.fix||`Correct the chart declaration`))}function s(e,t,n){return o((0,r.validate)(e).errors,t,n)}function c(e,t){if(t.renderOptions?.frame)return e;let{ctx:n}=t,r=e.heading||``,i=e.subtitle||``;if(!r&&!i)return e;let a=Math.max(24,e.width-32),o=[],s=16,c=e.width,l=(e,t,r)=>{if(!e)return;let i=n.wrap(e,a,t,r),l=t+6;c=Math.max(c,32+Math.max(0,...i.map(e=>n.measure(e,t,r)))),o.push(n.textLines(16,s+t,i,{leading:l,size:t,weight:r,fill:n.color(r>400?`fg`:`muted`)})),s+=i.length*l+6};return l(r,16,650),l(i,12,400),s+=8,{...e,width:c,height:e.height+s,children:[...o,n.el(`g`,{transform:`translate(0 ${s})`},e.children)]}}function l(e,t,n,r,s=i.layout){let l={...t.renderOptions,width:t.width,lang:n.lang,...!t.renderOptions?.measure&&t.measure?{measure:(e,n=12,r=400)=>t.measure(e,{size:n,weight:r})}:{}};try{let n=c(s(e,l),t);return{width:n.width,height:n.height,scene:n,errors:[]}}catch(e){if(!(e instanceof a.ExpectedDiagnostic))throw e;return{width:t.width,height:0,errors:o(e.errors||[],n,r)}}}function u(e,r,i,a){let{text:o,icon:s,diagnostics:c}=(0,n.normalizeLabel)(e,{lang:r.lang,line:i});s&&c.push((0,t.warning)(`IGNORED_ASSET`,r.lang,i,`数值图标签仅绘制文字,不绘制图标`,`Numeric chart labels show text only; icons are omitted`,`改用纯文本标签`,`Use a text label`));for(let e of c)a.some(t=>t.message===e.message)||a.push(e);return o.trim()||String(e)}return e.diagnostics=o,e.numericLabel=u,e.renderWith=l,e.validateWith=s,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`chart/spec`],KChartUnits[`chart/registry`],KChartUnits[`core/diagnostics`]);
|
|
1
|
+
KChartUnits["diagram/numeric-model"]=(function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e,n,r){return e.map(e=>(0,t.error)(n.lang,r(e)||n.firstLine,e.message||`KChart 声明无效`,e.message||`Invalid KChart declaration`,e.fix||`修正图表声明`,e.fix||`Correct the chart declaration`))}function s(e,t,n){return o((0,r.validate)(e).errors,t,n)}function c(e,t){if(t.renderOptions?.frame)return e;let{ctx:n}=t,r=t.embedHeading?``:e.heading||``,i=e.subtitle||``;if(!r&&!i)return e;let a=Math.max(24,e.width-32),o=[],s=16,c=e.width,l=(e,t,r)=>{if(!e)return;let i=n.wrap(e,a,t,r),l=t+6;c=Math.max(c,32+Math.max(0,...i.map(e=>n.measure(e,t,r)))),o.push(n.textLines(16,s+t,i,{leading:l,size:t,weight:r,fill:n.color(r>400?`fg`:`muted`)})),s+=i.length*l+6};return l(r,16,650),l(i,12,400),s+=8,{...e,width:c,height:e.height+s,children:[...o,n.el(`g`,{transform:`translate(0 ${s})`},e.children)]}}function l(e,t,n,r,s=i.layout){let l={...t.renderOptions,width:t.width,lang:n.lang,...!t.renderOptions?.measure&&t.measure?{measure:(e,n=12,r=400)=>t.measure(e,{size:n,weight:r})}:{}};try{let n=c(s(e,l),t);return{width:n.width,height:n.height,scene:n,errors:[]}}catch(e){if(!(e instanceof a.ExpectedDiagnostic))throw e;return{width:t.width,height:0,errors:o(e.errors||[],n,r)}}}function u(e,r,i,a){let{text:o,icon:s,diagnostics:c}=(0,n.normalizeLabel)(e,{lang:r.lang,line:i});s&&c.push((0,t.warning)(`IGNORED_ASSET`,r.lang,i,`数值图标签仅绘制文字,不绘制图标`,`Numeric chart labels show text only; icons are omitted`,`改用纯文本标签`,`Use a text label`));for(let e of c)a.some(t=>t.message===e.message)||a.push(e);return o.trim()||String(e)}return e.diagnostics=o,e.numericLabel=u,e.renderWith=l,e.validateWith=s,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/label`],KChartUnits[`chart/spec`],KChartUnits[`chart/registry`],KChartUnits[`core/diagnostics`]);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
KChartUnits["diagram/numeric-radar"]=(function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var
|
|
1
|
+
KChartUnits["diagram/numeric-radar"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=24,o=24,s=2,c=8,l=5,u=e=>{let t=String(e).trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1).replace(/\\([\\"'])/g,`$1`):t},d=e=>/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(String(e).trim())?Number(e):null,f=(e,n,r,i,a=`修正 Mermaid radar 语法`,o=`Correct the Mermaid radar syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),p=(e,n,r,i,a,o)=>(0,t.warning)(`DIAGRAM_HINT`,e.lang,n,r,i,a,o);function m(e,t){let n=[],r=null,i=0,a=0;return String(e).split(`
|
|
2
2
|
`).forEach((e,o)=>{let s=e.trim();(r!==null||s&&!s.startsWith(`%%`))&&(r===null&&(i=t+o,r=``),r+=(r?`
|
|
3
|
-
`:``)+s,a=Math.max(0,a+(s.match(/\{/g)||[]).length-(s.match(/\}/g)||[]).length),a||(n.push({text:r,line:i}),r=null))}),r!==null&&n.push({text:r,line:i}),n}function
|
|
3
|
+
`:``)+s,a=Math.max(0,a+(s.match(/\{/g)||[]).length-(s.match(/\}/g)||[]).length),a||(n.push({text:r,line:i}),r=null))}),r!==null&&n.push({text:r,line:i}),n}function h(e){let t=[],n=``,r=``,i=0;for(let a of e)r?(n+=a,a===r&&(r=``)):a===`"`||a===`'`?(r=a,n+=a):((a===`[`||a===`{`)&&(i+=1),(a===`]`||a===`}`)&&--i,a===`,`&&i===0?(t.push(n.trim()),n=``):n+=a);return t.push(n.trim()),t}var g=`(?:\\[\\s*(?:"((?:[^"\\\\]|\\\\.)*)"|'((?:[^'\\\\]|\\\\.)*)'|([^\\]]*))\\s*\\])?`,_=`[\\p{L}\\p{N}_][\\p{L}\\p{N}_.-]*`,v=RegExp(`^(${_})\\s*${g}$`,`u`),y=RegExp(`^(${_})\\s*${g}\\s*\\{([\\s\\S]*)\\}$`,`u`),b=RegExp(`^(${_})\\s*:?\\s*([-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+))$`,`u`),x=(e,t)=>{let n=[e[2],e[3],e[4]].find(e=>e!==void 0);return(n===void 0?t:u(n))||t};function S(e){let t=String(e.params||``).replace(/\s*:\s*$/,``).trim();return t?f(e,e.headerLine||e.firstLine,`radar-beta 不支持头行选项「${t}」`,`radar-beta does not accept header options: ${t}`,`把选项写成独立语句(max、min、ticks、showLegend、graticule)`,`Write options as their own statements`):null}function C(e,t,r,i,a){for(let o of h(t.replace(/^axis\s+/i,``))){let t=v.exec(o);if(!t){a.push(f(e,r,`无法识别 radar 维度「${o}」`,`Unrecognized radar axis "${o}"`,'使用 `axis 名称` 或 `axis 名称["显示名"]`','Use `axis name` or `axis name["Label"]`'));continue}let s=t[1];i.some(e=>e.id===s)?a.push(f(e,r,`radar 维度「${s}」重复`,`Duplicate radar axis "${s}"`,`每个维度只声明一次`,`Declare each axis once`)):i.push({id:s,label:(0,n.numericLabel)(x(t,s),e,r,a),line:r})}}function w(e,t,r,i,a){for(let o of h(t.replace(/^curve\s+/i,``))){let t=y.exec(o);if(!t){a.push(f(e,r,`无法识别 radar 曲线「${o}」`,`Unrecognized radar curve "${o}"`,'使用 `curve 名称["显示名"]{值, 值}` 或 `curve 名称{维度: 值}`','Use `curve name["Label"]{value, value}` or `curve name{axis: value}`'));continue}let s=t[1],c=[],l=t[5].split(/[,\n]/).map(e=>e.trim()).filter(Boolean),u=!1;for(let t of l){let n=d(t);if(n!==null){c.push({axis:null,value:n});continue}let i=b.exec(t);i?c.push({axis:i[1],value:Number(i[2])}):(a.push(f(e,r,`radar 曲线「${s}」的值「${t}」无效`,`Invalid value "${t}" in radar curve "${s}"`,"曲线值必须是数值,或 `维度名: 数值`","Curve values must be numbers or `axis: number` pairs")),u=!0)}u||i.push({id:s,label:(0,n.numericLabel)(x(t,s),e,r,a),entries:c,line:r})}}function T(e,t,n,r){return t.flatMap(t=>{let i=t.entries.filter(e=>e.axis!==null);if(!i.length)return[{...t,values:t.entries.map(e=>e.value)}];if(i.length!==t.entries.length)return r.push(f(e,t.line,`radar 曲线「${t.label}」不能混用按位和按维度取值`,`Radar curve "${t.label}" mixes positional and named values`,`整条曲线统一使用一种写法`,`Use one value form for the whole curve`)),[];let a=i.filter(e=>!n.some(t=>t.id===e.axis));if(a.length)return r.push(f(e,t.line,`radar 曲线「${t.label}」引用了未声明的维度「${a[0].axis}」`,`Radar curve "${t.label}" references undeclared axis "${a[0].axis}"`,`先声明该维度,或删去这一项`,`Declare the axis first, or remove that entry`)),[];let o=n.filter(e=>!i.some(t=>t.axis===e.id));return o.length?(r.push(f(e,t.line,`radar 曲线「${t.label}」缺少维度「${o.map(e=>e.id).join(`、`)}」的值`,`Radar curve "${t.label}" is missing values for ${o.map(e=>e.id).join(`, `)}`,"为每个维度各写一个 `维度名: 数值`","Give one `axis: number` entry per axis")),[]):[{...t,values:n.map(e=>i.find(t=>t.axis===e.id).value)}]})}function E(e,t,n,r,i){for(let a of h(t)){let t=/^(showLegend|ticks|max|min|graticule)\s+(\S+)$/i.exec(a);if(!t){i.push(f(e,n,`无法识别 radar 语句「${a}」`,`Unrecognized radar statement "${a}"`,`支持 axis、curve、max、min、ticks、showLegend、graticule`,`Supported: axis, curve, max, min, ticks, showLegend, graticule`));continue}let o=t[1].toLowerCase(),s=t[2];if(o===`showlegend`){if(!/^(true|false)$/i.test(s)){i.push(f(e,n,`showLegend 只接受 true 或 false`,`showLegend accepts only true or false`));continue}r.showLegend=s.toLowerCase()===`true`,r.line??=n;continue}if(o===`graticule`){if(!/^(circle|polygon)$/i.test(s)){i.push(f(e,n,`graticule 只接受 circle 或 polygon`,`graticule accepts only circle or polygon`));continue}r.graticule=s.toLowerCase(),r.line??=n;continue}let c=d(s);c===null?i.push(f(e,n,`radar ${o} 值「${s}」无效`,`Invalid radar ${o} value "${s}"`)):(r[o]=c,r.line??=n)}}var D=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return;let n=Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase());return n===void 0?void 0:e[n]},O=(e,t)=>{let n=D(e,t);return typeof n==`boolean`?n:void 0},k=(e,t)=>{let n=D(e,t),r=typeof n==`number`?n:d(n??``);return r!==null&&Number.isFinite(r)?r:void 0};function A(e,t){let r=[],i=[],d=[],h={},g=S(t);g&&r.push(g);let _=null,v=null,y=null;for(let a of m(e,t.firstLine))if(/^title\s+/i.test(a.text)){if(_!==null){r.push(f(t,a.line,`radar 只能有一个 title`));continue}_=(0,n.numericLabel)(u(a.text.replace(/^title\s+/i,``)),t,a.line,r),v=a.line}else/^axis\s+/i.test(a.text)?(y??=a.line,C(t,a.text,a.line,i,r)):/^curve\s+/i.test(a.text)?w(t,a.text,a.line,d,r):E(t,a.text,a.line,h,r);let b=D(t.config,`radar`),x=k(b,`ticks`)??h.ticks??l,A=k(b,`min`)??h.min??0,j=k(b,`max`)??h.max??null,M=O(b,`showLegend`)??h.showLegend??!0,N=String(D(b,`graticule`)??h.graticule??`circle`).toLowerCase();if(!i.length)r.push(f(t,t.firstLine,`radar 至少需要一个维度`,`Radar needs at least one axis`,`添加 axis 语句`,`Add an axis statement`));else if(i.length>o)return r.push(f(t,i[o].line,`radar 维度安全上限为 ${o} 个,当前 ${i.length} 个`,`Radar safety cap is ${o} axes; got ${i.length}`,`将维度拆分到多张雷达图`,`Split the axes across multiple radar charts`)),{model:null,errors:r};else i.length<3&&r.push(p(t,y,`radar 只有 ${i.length} 个维度,无法形成面积`,`Radar has ${i.length} axes and cannot enclose an area`,`建议至少使用 3 个维度`,`Use at least 3 axes for an area`));!d.length&&!r.some(e=>e.severity===`error`)&&r.push(f(t,t.firstLine,`radar 至少需要一条 curve`,`Radar needs at least one curve`)),j!==null&&j<=A&&r.push(f(t,h.line||t.firstLine,`radar max 必须大于 min`,`Radar max must be greater than min`));let P=T(t,d,i,r),F=P.filter(e=>e.values.length===i.length||(r.push(p(t,e.line,`radar 曲线「${e.label}」有 ${e.values.length} 个值、${i.length} 个维度,已跳过`,`Radar curve "${e.label}" has ${e.values.length} values for ${i.length} axes and was skipped`,`为每个维度写一个值`,`Give one value per axis`)),!1));P.length>a&&r.push(f(t,P[a].line,`radar 安全上限为 ${a} 条曲线,当前 ${P.length} 条`,`radar safety cap is ${a} curves; got ${P.length}`,`将曲线合并到 ${a} 条以内,或拆成多张图`,`Merge curves to stay within ${a}, or split the chart`));let I=F.flatMap(e=>e.values).filter(Number.isFinite),L=I.length?Math.max(...I):0,R=I.length?Math.min(...I):0,z=j??Math.max(L,A+1),B=A;z>B||(z=B+1),L>z&&(r.push(p(t,h.line||t.firstLine,`radar max ${z} 小于数据最大值 ${L},已扩展到 ${L}`,`Radar max ${z} is below the data maximum ${L}; extended to ${L}`,`把 max 改为不小于 ${L}`,`Set max to at least ${L}`)),z=L),R<B&&(r.push(p(t,h.line||t.firstLine,`radar min ${B} 大于数据最小值 ${R},已扩展到 ${R}`,`Radar min ${B} is above the data minimum ${R}; extended to ${R}`,`把 min 改为不大于 ${R}`,`Set min to no more than ${R}`)),B=R);let V=Math.max(s,Math.min(c,Math.round(x)));V!==x&&r.push(p(t,h.line||t.firstLine,`radar ticks ${x} 超出 ${s}–${c} 环的可读范围,按 ${V} 环绘制`,`Radar ticks ${x} is outside the readable ${s}–${c} rings; drawing ${V}`,`把 ticks 设为 ${s}–${c} 之间的整数`,`Set ticks to an integer within ${s}–${c}`));let H=i.map((e,t)=>({name:`d${t}`,label:e.label})),U=F.map(e=>Object.fromEntries([[`label`,e.label],...H.map((t,n)=>[t.name,e.values[n]])]));return{model:{chart:`radar`,title:_,titleLine:v,axisLine:y,axes:i,fields:H,rows:U,domain:[B,z],rings:V,graticule:N,showLegend:M,curveLines:F.map(e=>e.line),optionsLine:h.line||y||t.firstLine},errors:r}}function j(e){return{chart:`radar`,[r.sizeBudget]:{minDimensions:1,maxDimensions:o},...e.title?{title:e.title}:{},data:e.rows,encode:{label:`label`,dimensions:e.fields.map(e=>e.name)},fields:Object.fromEntries(e.fields.map(t=>[t.name,{label:t.label,domain:e.domain}])),rings:e.rings,graticule:e.graticule,legend:e.showLegend}}function M(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=Number(n[1]);return n[0]===`title`?e.titleLine:n[0]===`data`&&Number.isInteger(r)&&e.curveLines[r]?e.curveLines[r]:n[0]===`fields`||n[0]===`encode`?e.axisLine:[`rings`,`graticule`,`legend`].includes(n[0])?e.optionsLine:e.axisLine||e.curveLines[0]||e.optionsLine}var N=(e,t)=>(0,n.validateWith)(j(e),t,t=>M(e,t)),P=(e,r,a)=>{let o=r.compact?Math.min(720,440+e.axes.length*5):r.width,s=o===r.width?r:{...r,width:o},c=j(e);r.compact===!0&&(c[i.compactNumeric]=!0);let l=(0,n.renderWith)(c,s,a,t=>M(e,t));return l.scene&&l.width>s.width&&l.errors.push((0,t.warning)(`LARGE_DIAGRAM`,a.lang,e.optionsLine,`雷达图超出可用宽度,可滚动查看`,`The radar chart exceeds the available width; scroll to view`,`缩短维度标签或拆分图表`,`Shorten axis labels or split the chart`)),l},F=Object.freeze([`radar.ticks`,`radar.min`,`radar.max`,`radar.showLegend`,`radar.graticule`]),I={"radar-beta":{parse:A,validate:N,layout:P,optionMode:`raw`,honoredConfig:F}};return e.honoredConfig=F,e.implementations=I,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/spec`],KChartUnits[`chart/multivariate`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/numeric-sankey"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=600,c=500,l=60,u=120,d=(e,n,r,i,a=`修正 Mermaid sankey 语法`,o=`Correct the Mermaid sankey syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),f=e=>{let t=[],n=``,r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(r)o===`"`&&e[a+1]===`"`?(n+=`"`,a+=1):o===`"`?(r=!1,i=!0):n+=o;else if(o===`"`){if(n.trim()||i)return null;n=``,r=!0}else if(o===`,`)t.push(n.trim()),n=``,i=!1;else if(i&&!/\s/.test(o))return null;else n+=o}return r?null:(t.push(n.trim()),t)},p=e=>{let t=Number.parseFloat(e);return Number.isFinite(t)?t:null},m=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return;let n=Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase());return n===void 0?void 0:e[n]},h=(e,t)=>{let n=m(e,t);return typeof n==`boolean`?n:void 0};function g(e,t){let a=[],o=[],l=[],u=(0,r.presentation)({lang:t.lang}),g=String(t.params||Object.keys(t.options||{}).join(` `)).replace(/\s*:\s*$/,``).trim();g&&a.push(d(t,t.headerLine||t.firstLine,`sankey 不支持头行选项「${g}」`,`sankey does not accept header options: ${g}`,`把配置写在前言区 sankey: 下`,`Put options under front matter sankey:`)),String(e).split(`
|
|
2
|
-
`).forEach((e,n)=>{let r=e.trim(),i=t.firstLine+n;if(!r||r.startsWith(`%%`)||u.accept(r,i))return;let s=f(r);if(!s){a.push(d(t,i,`sankey CSV 引号格式错误`,`Malformed sankey CSV quoting`,`用成对的 " 包住含逗号的名称,字段内引号写作 ""`,`Wrap names that contain commas in " and write inner quotes as ""`));return}if(s.length!==3){a.push(d(t,i,`sankey 每行必须是 Source,Target,Value 三列,本行 ${s.length} 列`,`Each sankey row needs exactly 3 columns, got ${s.length}`,`每行只写来源、目标、数值三列`,`Write source, target and value only`));return}let[c,m]=[s[0],s[1]],h=p(s[2]);if(!c||!m)a.push(d(t,i,`sankey 来源与目标不能为空`,`Sankey source and target must not be empty`));else if(h===null||h<=0)a.push(d(t,i,`sankey 流量必须为正有限数,本行「${s[2]}」`,`Sankey value must be a positive finite number, got "${s[2]}"`,`把数值改为大于 0 的有限数`,`Use a positive finite number`));else{for(let e of[c,m])l.includes(e)||l.push(e);o.push({id:`edge-${o.length+1}`,source:c,target:m,value:h,line:i})}}),!o.length&&!a.length&&a.push(d(t,t.firstLine,`sankey 至少需要一条有效流量 CSV 记录`,`Sankey needs at least one valid CSV flow record`)),l.length>s&&a.push(d(t,t.firstLine,`sankey 超过安全上限 ${s} 个节点(当前 ${l.length})`,`Sankey exceeds the safety cap of ${s} nodes (got ${l.length})`,`拆分图表后重试`,`Split the diagram and try again`)),o.length>c&&a.push(d(t,t.firstLine,`sankey 超过 Mermaid maxEdges 安全上限 ${c} 条流量(当前 ${o.length})`,`Sankey exceeds the Mermaid maxEdges safety cap of ${c} flows (got ${o.length})`,`拆分图表后重试`,`Split the diagram and try again`));let v=h(m(t.config,`sankey`),`showValues`)??!0;return{model:{chart:`sankey`,nodes:l.map(e=>({id:e,label:(0,n.numericLabel)(e,t,o.find(t=>t.source===e||t.target===e)?.line,a),[i.sankeyPresentation]:{status:u.statusOf(e),link:u.linkOf(e)}})),edges:o.map((e,t)=>({...e,[i.sankeyPresentation]:u.edgeStatusOf(t)})),showValues:v,unit:_(t)},errors:[...a,...u.diagnostics()]}}function _(e){let t=m(e.config,`sankey`),n=m(t,`prefix`),r=m(t,`suffix`);if(n===void 0&&r===void 0)return;let i=e=>e==null?``:String(e),[a,o]=[i(n),i(r)];return/^[\p{L}\p{Sc}%‰°]*\p{Sc}?[\p{L}\p{Sc}%‰°]*$/u.test(`${a}${o}`)&&`${a}${o}`?`${a}${o}`:void 0}function v(e){return{chart:`sankey`,tolerant:!0,[i.sankeyPresentation]:!0,[o.sizeBudget]:{nodes:s,edges:c},data:{nodes:e.nodes,edges:e.edges.map(({line:e,...t})=>t)},layout:`right`,showValues:e.showValues,...e.unit?{unit:e.unit}:{}}}function y(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>n[n.indexOf(e)+1],i=Number(r(`edges`));if(Number.isInteger(i)&&e.edges[i])return e.edges[i].line;let a=Number(r(`nodes`));if(Number.isInteger(a)&&e.nodes[a]){let t=e.nodes[a].id;return e.edges.find(e=>e.source===t||e.target===t)?.line}return e.edges[0]?.line}function b(e,t){let r=(0,n.validateWith)(v(e),t,t=>y(e,t));if(r.length||e.nodes.length<=l&&e.edges.length<=u)return r;let i=new Map(e.nodes.map(e=>[e.id,0])),a=new Map(e.nodes.map(e=>[e.id,[]])),o=new Map(e.nodes.map(e=>[e.id,0]));for(let{source:t,target:n}of e.edges)a.get(t).push(n),i.set(n,i.get(n)+1);let s=e.nodes.map(e=>e.id).filter(e=>!i.get(e));for(let e of s)for(let t of a.get(e))o.set(t,Math.max(o.get(t),o.get(e)+1)),i.set(t,i.get(t)-1),i.get(t)||s.push(t);let c=1e3,f=0;for(let{source:n,target:r,line:i}of e.edges)if(f+=o.get(r)-o.get(n),f>c)return[d(t,i,`桑基图最多支持 ${c} 个跨阶段流量分段`,`Sankey supports at most ${c} flow segments across stages`,`请按阶段拆分图表`,`Split the chart by stage`)];return r}var x=(0,a.createRegistry)(o.validate);x.register(`sankey`,a.layouts.get(`sankey`));var S=(e,r,i)=>{let a=(0,n.renderWith)(v(e),r,i,t=>y(e,t),x.layout);return a.scene&&(a.width>r.width*2||e.nodes.length>l||e.edges.length>u)&&a.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,i.headerLine,`桑基图较大,可滚动查看`,`Large Sankey diagram; scroll to view it`,`考虑拆分图表`,`Consider splitting the diagram`)),a},C=Object.freeze([`sankey.showValues`,`sankey.prefix`,`sankey.suffix`]),w={sankey:{parse:g,validate:b,layout:S,optionMode:`raw`,acceptsPresentation:!0,honoredConfig:C}};return e.honoredConfig=C,e.implementations=w,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`diagram/presentation`],KChartUnits[`chart/relations`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`]);
|
|
2
|
+
`).forEach((e,n)=>{let r=e.trim(),i=t.firstLine+n;if(!r||r.startsWith(`%%`)||u.accept(r,i))return;let s=f(r);if(!s){a.push(d(t,i,`sankey CSV 引号格式错误`,`Malformed sankey CSV quoting`,`用成对的 " 包住含逗号的名称,字段内引号写作 ""`,`Wrap names that contain commas in " and write inner quotes as ""`));return}if(s.length!==3){a.push(d(t,i,`sankey 每行必须是 Source,Target,Value 三列,本行 ${s.length} 列`,`Each sankey row needs exactly 3 columns, got ${s.length}`,`每行只写来源、目标、数值三列`,`Write source, target and value only`));return}let[c,m]=[s[0],s[1]],h=p(s[2]);if(!c||!m)a.push(d(t,i,`sankey 来源与目标不能为空`,`Sankey source and target must not be empty`));else if(h===null||h<=0)a.push(d(t,i,`sankey 流量必须为正有限数,本行「${s[2]}」`,`Sankey value must be a positive finite number, got "${s[2]}"`,`把数值改为大于 0 的有限数`,`Use a positive finite number`));else{for(let e of[c,m])l.includes(e)||l.push(e);o.push({id:`edge-${o.length+1}`,source:c,target:m,value:h,line:i})}}),!o.length&&!a.length&&a.push(d(t,t.firstLine,`sankey 至少需要一条有效流量 CSV 记录`,`Sankey needs at least one valid CSV flow record`)),l.length>s&&a.push(d(t,t.firstLine,`sankey 超过安全上限 ${s} 个节点(当前 ${l.length})`,`Sankey exceeds the safety cap of ${s} nodes (got ${l.length})`,`拆分图表后重试`,`Split the diagram and try again`)),o.length>c&&a.push(d(t,t.firstLine,`sankey 超过 Mermaid maxEdges 安全上限 ${c} 条流量(当前 ${o.length})`,`Sankey exceeds the Mermaid maxEdges safety cap of ${c} flows (got ${o.length})`,`拆分图表后重试`,`Split the diagram and try again`));let v=h(m(t.config,`sankey`),`showValues`)??!0;return{model:{chart:`sankey`,nodes:l.map(e=>({id:e,label:(0,n.numericLabel)(e,t,o.find(t=>t.source===e||t.target===e)?.line,a),[i.sankeyPresentation]:{status:u.statusOf(e),link:u.linkOf(e)}})),edges:o.map((e,t)=>({...e,[i.sankeyPresentation]:u.edgeStatusOf(t)})),showValues:v,unit:_(t)},errors:[...a,...u.diagnostics()]}}function _(e){let t=m(e.config,`sankey`),n=m(t,`prefix`),r=m(t,`suffix`);if(n===void 0&&r===void 0)return;let i=e=>e==null?``:String(e),[a,o]=[i(n),i(r)];return/^[\p{L}\p{Sc}%‰°]*\p{Sc}?[\p{L}\p{Sc}%‰°]*$/u.test(`${a}${o}`)&&`${a}${o}`?`${a}${o}`:void 0}function v(e,t=!1){return{chart:`sankey`,tolerant:!0,[i.sankeyPresentation]:!0,...t?{[i.sankeyCompact]:!0}:{},[o.sizeBudget]:{nodes:s,edges:c},data:{nodes:e.nodes,edges:e.edges.map(({line:e,...t})=>t)},layout:`right`,showValues:e.showValues,...e.unit?{unit:e.unit}:{}}}function y(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>n[n.indexOf(e)+1],i=Number(r(`edges`));if(Number.isInteger(i)&&e.edges[i])return e.edges[i].line;let a=Number(r(`nodes`));if(Number.isInteger(a)&&e.nodes[a]){let t=e.nodes[a].id;return e.edges.find(e=>e.source===t||e.target===t)?.line}return e.edges[0]?.line}function b(e,t){let r=(0,n.validateWith)(v(e),t,t=>y(e,t));if(r.length||e.nodes.length<=l&&e.edges.length<=u)return r;let i=new Map(e.nodes.map(e=>[e.id,0])),a=new Map(e.nodes.map(e=>[e.id,[]])),o=new Map(e.nodes.map(e=>[e.id,0]));for(let{source:t,target:n}of e.edges)a.get(t).push(n),i.set(n,i.get(n)+1);let s=e.nodes.map(e=>e.id).filter(e=>!i.get(e));for(let e of s)for(let t of a.get(e))o.set(t,Math.max(o.get(t),o.get(e)+1)),i.set(t,i.get(t)-1),i.get(t)||s.push(t);let c=1e3,f=0;for(let{source:n,target:r,line:i}of e.edges)if(f+=o.get(r)-o.get(n),f>c)return[d(t,i,`桑基图最多支持 ${c} 个跨阶段流量分段`,`Sankey supports at most ${c} flow segments across stages`,`请按阶段拆分图表`,`Split the chart by stage`)];return r}var x=(0,a.createRegistry)(o.validate);x.register(`sankey`,a.layouts.get(`sankey`));var S=(e,r,i)=>{let a=(0,n.renderWith)(v(e,r.compact===!0),r,i,t=>y(e,t),x.layout);return a.scene&&(a.width>r.width*2||e.nodes.length>l||e.edges.length>u)&&a.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,i.headerLine,`桑基图较大,可滚动查看`,`Large Sankey diagram; scroll to view it`,`考虑拆分图表`,`Consider splitting the diagram`)),a},C=Object.freeze([`sankey.showValues`,`sankey.prefix`,`sankey.suffix`]),w={sankey:{parse:g,validate:b,layout:S,optionMode:`raw`,acceptsPresentation:!0,honoredConfig:C}};return e.honoredConfig=C,e.implementations=w,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`diagram/presentation`],KChartUnits[`chart/relations`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/numeric-xy"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=`[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)`;RegExp(`^${a}$`);var o=RegExp(`^(.*?)\\s*(${a})\\s*-->\\s*(${a})\\s*$`),s=/^(.*?)\s*\[([^\]]*)\]\s*$/,c=/^(bar|line)\b([\s\S]*)$/i,l=RegExp(`^(${a})\\s*(?:"((?:[^"\\\\]|\\\\.)*)"|'((?:[^'\\\\]|\\\\.)*)')?$`),u=/^\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^\s[\]"]+))?\s*\[([\s\S]*)\]\s*$/,d=6,f=24,p=120,m=(e,n,r,i,a=`修正 Mermaid xychart 语法`,o=`Correct the Mermaid xychart syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),h=(e,n,r,i,a,o=`检查图表声明`,s=`Check the chart declaration`)=>e.push((0,t.warning)(`DIAGRAM_HINT`,n.lang,r,i,a,o,s)),g=e=>/^en(?:-|$)/i.test(String(e||``)),_=e=>String(e).replace(/\\([\\"'])/g,`$1`),v=e=>{let t=String(e).trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?_(t.slice(1,-1)):t},y=(e,t,n)=>[e,t,n].find(e=>e!==void 0);function b(e,t=`,`){let n=[],r=``,i=``,a=0;for(let o of String(e))i?(r+=o,o===i&&(i=``)):o===`"`||o===`'`?(i=o,r+=o):((o===`[`||o===`{`)&&(a+=1),(o===`]`||o===`}`)&&--a,o===t&&a===0?(n.push(r.trim()),r=``):r+=o);return n.push(r.trim()),n}function x(e,t){let n=[];return String(e).split(`
|
|
2
|
-
`).forEach((e,r)=>{let i=e.trim();if(i&&!i.startsWith(`%%`))for(let e of b(i,`;`))e&&n.push({text:e,line:t+r})}),n}function S(e,t){let n=null;for(let r of String(e.params||``).split(/\s+/).filter(Boolean))/^(?:horizontal|vertical)$/i.test(r)?n=r.toLowerCase():t.push(m(e,e.headerLine||e.firstLine,`xychart 不支持头行选项「${r}」`,`xychart does not accept header options: ${r}`,`头行只接受 horizontal 或 vertical`,`Only horizontal or vertical is allowed after the header`));return n}function C(e,t,n,r){let i=[];for(let a of b(e)){let e=l.exec(a);if(!e)return r.push(m(t,n,`数据点「${a}」须为数值,可带一个引号标签`,`Data point "${a}" must be a number, optionally with a quoted label`,'写成 `12` 或 `12 "标签"`','Write `12` or `12 "Label"`')),null;let o=y(e[2],e[3],void 0);i.push({value:Number(e[1]),label:o===void 0?null:_(o)||null})}return i}function w(e,t,n,r){let i=s.exec(t);if(i){let t=i[1].trim()?v(i[1]):null,a=b(i[2]);return!a.length||a.some(e=>!e)?(r.push(m(e,n,`x-axis 需要非空类别列表`,`x-axis needs a non-empty category list`,`去掉空类别或多余的逗号`,`Remove empty categories or extra commas`)),{title:t,data:null}):{title:t,data:{kind:`band`,categories:a.map(v)}}}let a=o.exec(t);if(a&&!/-$/.test(a[1])){let e=Number(a[2]),t=Number(a[3]);return{title:a[1].trim()?v(a[1]):null,data:{kind:`linear`,min:e,max:t}}}return{title:t?v(t):null,data:null}}function T(e,t,n,r){let i=new Map,a=[],o=!1;for(let e of r){let t=(i.get(e)||0)+1;i.set(e,t),t===1?a.push(e):(o=!0,a.push(`${e} (${t})`))}return o&&h(e,t,n,`x-axis 类别名重复,已按出现顺序加序号区分`,`Duplicate x-axis categories were numbered in source order`,`让每个类别名唯一`,`Give every category a unique name`),a}function E(e,t,n){let r=e=>String(Number(e.toPrecision(12)));if(n<=0)return[];if(n===1)return[r(e)];let i=(t-e)/(n-1);return Array.from({length:n},(t,n)=>r(e+n*i))}function D(e,t,n,r){let i=c.exec(t),a=i[1].toLowerCase(),o=u.exec(i[2]);if(!o)return r.push(m(e,n,`无法识别 ${a} 数据「${t}」`,`Unrecognized ${a} data "${t}"`,`写成 \`${a} [值, 值]\` 或 \`${a} "名称" [值, 值]\``,`Write \`${a} [value, value]\` or \`${a} "Name" [value, value]\``)),null;let s=C(o[4],e,n,r);if(!s)return null;let l=y(o[1],o[2],o[3]);return{type:a,name:l===void 0?null:_(l),points:s,line:n}}function O(e,t){let r=[],i=null,a=null,o=null,s=null,l=null,u=null,d=null,g=null,_=[],y=S(t,r);for(let f of x(e,t.firstLine))if(/^title\b/i.test(f.text)){let e=f.text.replace(/^title\b/i,``).trim();if(!e){r.push(m(t,f.line,`title 需要标题文字`,`title needs some text`));continue}if(i!==null){r.push(m(t,f.line,`xychart 只能有一个 title`,`xychart accepts one title`));continue}i=(0,n.numericLabel)(v(e),t,f.line,r),a=f.line}else if(/^x-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^x-axis\b/i,``).trim(),f.line,r);e.title!==null&&(o!==null&&h(r,t,f.line,`xychart 重复的 x-axis,只保留最后一条`,`Duplicate x-axis; the last one is used`),o=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&(l&&h(r,t,f.line,`xychart 重复的 x-axis 数据,只保留最后一条`,`Duplicate x-axis data; the last one is used`),l=e.data,u=f.line),u??=f.line}else if(/^y-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^y-axis\b/i,``).trim(),f.line,r);d??=f.line,e.title!==null&&(s!==null&&h(r,t,f.line,`xychart 重复的 y-axis,只保留最后一条`,`Duplicate y-axis; the last one is used`),s=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&e.data.kind===`linear`?(g&&h(r,t,f.line,`xychart 重复的 y-axis 范围,只保留最后一条`,`Duplicate y-axis range; the last one is used`),g=[e.data.min,e.data.max]):e.data?.kind===`band`&&r.push(m(t,f.line,"y-axis 只接受数值范围 `min --> max`","y-axis accepts only a numeric range `min --> max`",'改成 `y-axis "标题" 0 --> 100`','Use `y-axis "Title" 0 --> 100`'))}else if(c.test(f.text)){let e=D(t,f.text,f.line,r);e&&_.push(e)}else r.push(m(t,f.line,`无法识别 xychart 语句「${f.text}」`,`Unrecognized xychart statement "${f.text}"`,`支持 title、x-axis、y-axis、bar、line`,`Supported: title, x-axis, y-axis, bar, line`));_.length||r.push(m(t,t.firstLine,`xychart 至少需要一条 bar 或 line 数据`,`xychart needs at least one bar or line plot`)),_.length>f&&r.push(m(t,_[f].line,`xychart 安全上限为 ${f} 条数据序列,当前 ${_.length} 条`,`xychart safety cap is ${f} plots; got ${_.length}`,`将数据序列合并到 ${f} 条以内,或拆成多张图`,`Merge series to stay within ${f} plots, or split the chart`));let b=_.length===1&&_[0].name,C=_.some(e=>e.type===`line`&&e.points.some(e=>e.label)),O=_.length>1||b&&!(_[0].type===`line`&&_[0].points.some(e=>e.label))?`combo`:_[0]?.type===`bar`?`column`:`line`,k=u||_[0]?.line||t.firstLine,A=_.map(e=>e.points.length),j=l?.kind===`band`?l.categories.length:Math.max(0,...A);j>p&&O!==`column`&&r.push(m(t,k,`xychart 最多支持 ${p} 个横轴类别`,`xychart supports at most ${p} x-axis categories`,`按横轴范围拆分图表`,`Split the chart by x-axis range`));let M;M=l?.kind===`band`?T(r,t,k,l.categories.map(e=>(0,n.numericLabel)(e,t,k,r))):l?.kind===`linear`?E(l.min,l.max,j):Array.from({length:j},(e,t)=>String(t+1));let N=_.map(e=>{let i=e.points.length>M.length,a=O===`combo`||e.type===`line`?null:0;return i?h(r,t,e.line,`数据点数 ${e.points.length} 多于类别数 ${M.length},多余的点已略去`,`${e.points.length} points exceed ${M.length} categories; extra points were dropped`,`补齐 x-axis 类别或删去多余的点`,`Add x-axis categories or remove the extra points`):e.points.length<M.length&&a===0&&h(r,t,e.line,`bar 数据点数少于类别数,缺少的点按 0 绘制`,`The bar plot has fewer points than categories; missing points are drawn as 0`,`补齐数据点`,`Provide a value for every category`),{type:e.type,name:e.name&&(0,n.numericLabel)(e.name,t,e.line,r),line:e.line,values:M.map((t,n)=>e.points[n]?.value??a),pointLabels:M.map((i,a)=>{let o=e.points[a]?.label;return o?(0,n.numericLabel)(o,t,e.line,r):null})}});O===`combo`&&C&&h(r,t,_[0].line,`组合图中的数据点标签未绘制`,`Point labels are not drawn on a combined chart`,`把该序列拆成单独的 line 图,或删去标签`,`Split that plot into a line-only chart or drop the labels`),O!==`combo`&&N[0]?.name&&C&&h(r,t,_[0].line,`单序列折线的名称「${N[0].name}」未作为图例绘制`,`The name "${N[0].name}" of this single line is not drawn as a legend`,`需要图例时不要同时使用数据点标签`,`Do not combine point labels with a series name if the legend matters`);let P=_.find(e=>e.type===`bar`&&e.points.some(e=>e.label));P&&h(r,t,P.line,`bar 的数据点标签被忽略(Mermaid 也只对 line 绘制点标签)`,`Point labels on a bar plot are ignored (Mermaid draws them on line plots only)`,`改用 line 绘制带标签的序列`,`Use line for a labeled series`);let F=_.flatMap(e=>e.points.map(e=>e.value)),I=Math.min(...F),L=Math.max(...F),R=null;return g&&(g[1]>g[0]?R=[g[0],g[1]]:h(r,t,d,`y-axis 范围 ${g[0]} --> ${g[1]} 不是递增区间,已改为按数据取值`,`y-axis range ${g[0]} --> ${g[1]} is not increasing; derived from data instead`,"把范围写成 `小值 --> 大值`","Write the range as `low --> high`")),R&&(R[0]>I&&(h(r,t,d,`y-axis 最小值 ${R[0]} 高于数据最小值 ${I},已扩展到 ${I}`,`y-axis minimum ${R[0]} is above the data minimum ${I}; extended to ${I}`,`把最小值改为不大于 ${I}`,`Set the minimum to at most ${I}`),R[0]=I),R[1]<L&&(h(r,t,d,`y-axis 最大值 ${R[1]} 低于数据最大值 ${L},已扩展到 ${L}`,`y-axis maximum ${R[1]} is below the data maximum ${L}; extended to ${L}`,`把最大值改为不小于 ${L}`,`Set the maximum to at least ${L}`),R[1]=L),_.some(e=>e.type===`bar`)&&(R[0]>0||R[1]<0)&&(h(r,t,d,`柱形 y 轴已自动包含 0 基线(${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`The bar y-axis now includes the zero baseline (${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`把 y-axis 范围写成包含 0 的区间`,`Declare a y-axis range that includes 0`),R=[Math.min(0,R[0]),Math.max(0,R[1])])),y===`horizontal`&&h(r,t,t.headerLine||t.firstLine,`xychart horizontal 暂不支持,按纵向绘制`,`Horizontal xychart is not supported yet; drawing vertically`,"改成 `xychart` 或 `xychart vertical`","Use `xychart` or `xychart vertical`"),l?.kind===`linear`&&new Set(M).size!==M.length&&h(r,t,k,`数值 x 轴 ${l.min} --> ${l.max} 的刻度有重复,类别名已加序号`,`The numeric x-axis ${l.min} --> ${l.max} produces repeated ticks; categories were numbered`,`扩大范围或减少数据点`,`Widen the range or use fewer points`),{model:{chart:O,title:i,titleLine:a,xLabel:o,yLabel:s,xLine:u,yLine:d,yDomain:R,categories:M,datasets:N,horizontal:y===`horizontal`},errors:r}}function k(e,t,n=0){let a=g(t?.lang),o=[e.xLabel,e.yLabel].filter(Boolean).join(` · `)||void 0,s=e.yDomain?{domain:e.yDomain}:{};if(e.chart===`combo`){let t=e.categories.map((t,n)=>Object.fromEntries([[`category`,t],...e.datasets.map((e,t)=>[`v${t}`,e.values[n]])]));return{chart:`combo`,[i.diagramCombo]:{index:n},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:t,encode:{category:`category`},layers:e.datasets.map((e,t)=>({mark:e.type===`bar`?`column`:`line`,field:`v${t}`,axis:`left`})),fields:Object.fromEntries(e.datasets.map((e,t)=>[`v${t}`,{label:e.name||(a?`Series ${t+1}`:`系列 ${t+1}`),...s}]))}}let c=e.datasets[0],l=c.pointLabels.some(Boolean),u=e.categories.map((e,t)=>({category:e,value:c.values[t],...l?{id:String(t)}:{}}));return{chart:e.chart,...e.chart===`line`?{[r.diagramLine]:!0}:{},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:u,encode:{category:`category`,value:`value`,...l?{id:`id`}:{}},fields:{value:{...s,...c.name?{label:c.name}:{}}},...l?{annotations:c.pointLabels.flatMap((e,t)=>e?[{kind:`note`,field:`value`,record:String(t),text:e}]:[])}:{}}}function A(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>{let t=/^v(\d+)$/.exec(String(e||``));return t?Number(t[1]):null};if(n[0]===`title`)return e.titleLine;if(n[0]===`subtitle`)return e.xLine||e.yLine;if(n[0]===`layers`)return e.datasets[Number(n[1])]?.line||e.datasets[0]?.line;if(n[0]===`fields`){let t=r(n[1]);return(t===null?null:e.datasets[t]?.line)||e.yLine||e.datasets[0]?.line}if(n[0]===`encode`)return e.xLine||e.datasets[0]?.line;if(n[0]===`annotations`)return e.datasets[0]?.line;if(n[0]===`data`){let t=r(n[2]);return(t===null?null:e.datasets[t]?.line)||e.datasets[0]?.line}return e.datasets[0]?.line}function j(e,t){if(e.datasets.length<=d)return[e];let n=e.datasets.flatMap(e=>e.values.filter(Number.isFinite)),r=e.datasets.some(e=>e.type===`bar`)?[0]:[],i=Math.min(...n,...r),a=Math.max(...n,...r),o=e.yDomain??[i,a>i?a:i+1],s=[];for(let n=0;n<e.datasets.length;n+=d)s.push({...e,yDomain:o,title:n?null:e.title,datasets:e.datasets.slice(n,n+d).map((e,r)=>({...e,name:e.name||`${g(t.lang)?`Series `:`系列 `}${n+r+1}`}))});return s}return e.implementations={xychart:{parse:O,validate:(e,t)=>j(e,t).flatMap(e=>(0,n.validateWith)(k(e,t),t,t=>A(e,t))),layout:(e,r,i)=>{let a=j(e,i).map((e,t)=>(0,n.renderWith)(k(e,i,t),r,i,t=>A(e,t)));if(a.some(e=>!e.scene))return a.find(e=>!e.scene);let o=a[0];if(a.length>1){let e=0,t=a.map(({scene:t})=>{let n=r.ctx.el(`g`,{transform:`translate(${e} 0)`},t.children);return e+=t.width+24,n});o.width=e-24,o.height=Math.max(...a.map(e=>e.height)),o.scene={...o.scene,width:o.width,height:o.height,children:t}}return(e.categories.length>60||o.width>r.width*2||a.length>1)&&o.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,e.xLine||e.datasets[0]?.line||i.firstLine,a.length>1?`XY 图按数据序列分栏,可横向滚动`:`XY 图较大,可滚动查看`,a.length>1?`XY series are arranged in panels; scroll horizontally`:`Large XY chart; scroll to view it`,`按数据序列或横轴范围拆分图表`,`Split the chart by series or x-axis range`)),o},optionMode:`raw`}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/basic`],KChartUnits[`chart/multivariate`]);
|
|
2
|
+
`).forEach((e,r)=>{let i=e.trim();if(i&&!i.startsWith(`%%`))for(let e of b(i,`;`))e&&n.push({text:e,line:t+r})}),n}function S(e,t){let n=null;for(let r of String(e.params||``).split(/\s+/).filter(Boolean))/^(?:horizontal|vertical)$/i.test(r)?n=r.toLowerCase():t.push(m(e,e.headerLine||e.firstLine,`xychart 不支持头行选项「${r}」`,`xychart does not accept header options: ${r}`,`头行只接受 horizontal 或 vertical`,`Only horizontal or vertical is allowed after the header`));return n}function C(e,t,n,r){let i=[];for(let a of b(e)){let e=l.exec(a);if(!e)return r.push(m(t,n,`数据点「${a}」须为数值,可带一个引号标签`,`Data point "${a}" must be a number, optionally with a quoted label`,'写成 `12` 或 `12 "标签"`','Write `12` or `12 "Label"`')),null;let o=y(e[2],e[3],void 0);i.push({value:Number(e[1]),label:o===void 0?null:_(o)||null})}return i}function w(e,t,n,r){let i=s.exec(t);if(i){let t=i[1].trim()?v(i[1]):null,a=b(i[2]);return!a.length||a.some(e=>!e)?(r.push(m(e,n,`x-axis 需要非空类别列表`,`x-axis needs a non-empty category list`,`去掉空类别或多余的逗号`,`Remove empty categories or extra commas`)),{title:t,data:null}):{title:t,data:{kind:`band`,categories:a.map(v)}}}let a=o.exec(t);if(a&&!/-$/.test(a[1])){let e=Number(a[2]),t=Number(a[3]);return{title:a[1].trim()?v(a[1]):null,data:{kind:`linear`,min:e,max:t}}}return{title:t?v(t):null,data:null}}function T(e,t,n,r){let i=new Map,a=[],o=!1;for(let e of r){let t=(i.get(e)||0)+1;i.set(e,t),t===1?a.push(e):(o=!0,a.push(`${e} (${t})`))}return o&&h(e,t,n,`x-axis 类别名重复,已按出现顺序加序号区分`,`Duplicate x-axis categories were numbered in source order`,`让每个类别名唯一`,`Give every category a unique name`),a}function E(e,t,n){let r=e=>String(Number(e.toPrecision(12)));if(n<=0)return[];if(n===1)return[r(e)];let i=(t-e)/(n-1);return Array.from({length:n},(t,n)=>r(e+n*i))}function D(e,t,n,r){let i=c.exec(t),a=i[1].toLowerCase(),o=u.exec(i[2]);if(!o)return r.push(m(e,n,`无法识别 ${a} 数据「${t}」`,`Unrecognized ${a} data "${t}"`,`写成 \`${a} [值, 值]\` 或 \`${a} "名称" [值, 值]\``,`Write \`${a} [value, value]\` or \`${a} "Name" [value, value]\``)),null;let s=C(o[4],e,n,r);if(!s)return null;let l=y(o[1],o[2],o[3]);return{type:a,name:l===void 0?null:_(l),points:s,line:n}}function O(e,t){let r=[],i=null,a=null,o=null,s=null,l=null,u=null,d=null,g=null,_=[],y=S(t,r);for(let f of x(e,t.firstLine))if(/^title\b/i.test(f.text)){let e=f.text.replace(/^title\b/i,``).trim();if(!e){r.push(m(t,f.line,`title 需要标题文字`,`title needs some text`));continue}if(i!==null){r.push(m(t,f.line,`xychart 只能有一个 title`,`xychart accepts one title`));continue}i=(0,n.numericLabel)(v(e),t,f.line,r),a=f.line}else if(/^x-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^x-axis\b/i,``).trim(),f.line,r);e.title!==null&&(o!==null&&h(r,t,f.line,`xychart 重复的 x-axis,只保留最后一条`,`Duplicate x-axis; the last one is used`),o=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&(l&&h(r,t,f.line,`xychart 重复的 x-axis 数据,只保留最后一条`,`Duplicate x-axis data; the last one is used`),l=e.data,u=f.line),u??=f.line}else if(/^y-axis\b/i.test(f.text)){let e=w(t,f.text.replace(/^y-axis\b/i,``).trim(),f.line,r);d??=f.line,e.title!==null&&(s!==null&&h(r,t,f.line,`xychart 重复的 y-axis,只保留最后一条`,`Duplicate y-axis; the last one is used`),s=(0,n.numericLabel)(e.title,t,f.line,r)),e.data&&e.data.kind===`linear`?(g&&h(r,t,f.line,`xychart 重复的 y-axis 范围,只保留最后一条`,`Duplicate y-axis range; the last one is used`),g=[e.data.min,e.data.max]):e.data?.kind===`band`&&r.push(m(t,f.line,"y-axis 只接受数值范围 `min --> max`","y-axis accepts only a numeric range `min --> max`",'改成 `y-axis "标题" 0 --> 100`','Use `y-axis "Title" 0 --> 100`'))}else if(c.test(f.text)){let e=D(t,f.text,f.line,r);e&&_.push(e)}else r.push(m(t,f.line,`无法识别 xychart 语句「${f.text}」`,`Unrecognized xychart statement "${f.text}"`,`支持 title、x-axis、y-axis、bar、line`,`Supported: title, x-axis, y-axis, bar, line`));_.length||r.push(m(t,t.firstLine,`xychart 至少需要一条 bar 或 line 数据`,`xychart needs at least one bar or line plot`)),_.length>f&&r.push(m(t,_[f].line,`xychart 安全上限为 ${f} 条数据序列,当前 ${_.length} 条`,`xychart safety cap is ${f} plots; got ${_.length}`,`将数据序列合并到 ${f} 条以内,或拆成多张图`,`Merge series to stay within ${f} plots, or split the chart`));let b=_.length===1&&_[0].name,C=_.some(e=>e.type===`line`&&e.points.some(e=>e.label)),O=_.length>1||b&&!(_[0].type===`line`&&_[0].points.some(e=>e.label))?`combo`:_[0]?.type===`bar`?`column`:`line`,k=u||_[0]?.line||t.firstLine,A=_.map(e=>e.points.length),j=l?.kind===`band`?l.categories.length:Math.max(0,...A);j>p&&O!==`column`&&r.push(m(t,k,`xychart 最多支持 ${p} 个横轴类别`,`xychart supports at most ${p} x-axis categories`,`按横轴范围拆分图表`,`Split the chart by x-axis range`));let M;M=l?.kind===`band`?T(r,t,k,l.categories.map(e=>(0,n.numericLabel)(e,t,k,r))):l?.kind===`linear`?E(l.min,l.max,j):Array.from({length:j},(e,t)=>String(t+1));let N=_.map(e=>{let i=e.points.length>M.length,a=O===`combo`||e.type===`line`?null:0;return i?h(r,t,e.line,`数据点数 ${e.points.length} 多于类别数 ${M.length},多余的点已略去`,`${e.points.length} points exceed ${M.length} categories; extra points were dropped`,`补齐 x-axis 类别或删去多余的点`,`Add x-axis categories or remove the extra points`):e.points.length<M.length&&a===0&&h(r,t,e.line,`bar 数据点数少于类别数,缺少的点按 0 绘制`,`The bar plot has fewer points than categories; missing points are drawn as 0`,`补齐数据点`,`Provide a value for every category`),{type:e.type,name:e.name&&(0,n.numericLabel)(e.name,t,e.line,r),line:e.line,values:M.map((t,n)=>e.points[n]?.value??a),pointLabels:M.map((i,a)=>{let o=e.points[a]?.label;return o?(0,n.numericLabel)(o,t,e.line,r):null})}});O===`combo`&&C&&h(r,t,_[0].line,`组合图中的数据点标签未绘制`,`Point labels are not drawn on a combined chart`,`把该序列拆成单独的 line 图,或删去标签`,`Split that plot into a line-only chart or drop the labels`),O!==`combo`&&N[0]?.name&&C&&h(r,t,_[0].line,`单序列折线的名称「${N[0].name}」未作为图例绘制`,`The name "${N[0].name}" of this single line is not drawn as a legend`,`需要图例时不要同时使用数据点标签`,`Do not combine point labels with a series name if the legend matters`);let P=_.find(e=>e.type===`bar`&&e.points.some(e=>e.label));P&&h(r,t,P.line,`bar 的数据点标签被忽略(Mermaid 也只对 line 绘制点标签)`,`Point labels on a bar plot are ignored (Mermaid draws them on line plots only)`,`改用 line 绘制带标签的序列`,`Use line for a labeled series`);let F=_.flatMap(e=>e.points.map(e=>e.value)),I=Math.min(...F),L=Math.max(...F),R=null;return g&&(g[1]>g[0]?R=[g[0],g[1]]:h(r,t,d,`y-axis 范围 ${g[0]} --> ${g[1]} 不是递增区间,已改为按数据取值`,`y-axis range ${g[0]} --> ${g[1]} is not increasing; derived from data instead`,"把范围写成 `小值 --> 大值`","Write the range as `low --> high`")),R&&(R[0]>I&&(h(r,t,d,`y-axis 最小值 ${R[0]} 高于数据最小值 ${I},已扩展到 ${I}`,`y-axis minimum ${R[0]} is above the data minimum ${I}; extended to ${I}`,`把最小值改为不大于 ${I}`,`Set the minimum to at most ${I}`),R[0]=I),R[1]<L&&(h(r,t,d,`y-axis 最大值 ${R[1]} 低于数据最大值 ${L},已扩展到 ${L}`,`y-axis maximum ${R[1]} is below the data maximum ${L}; extended to ${L}`,`把最大值改为不小于 ${L}`,`Set the maximum to at least ${L}`),R[1]=L),_.some(e=>e.type===`bar`)&&(R[0]>0||R[1]<0)&&(h(r,t,d,`柱形 y 轴已自动包含 0 基线(${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`The bar y-axis now includes the zero baseline (${R[0]} --> ${R[1]} → ${Math.min(0,R[0])} --> ${Math.max(0,R[1])})`,`把 y-axis 范围写成包含 0 的区间`,`Declare a y-axis range that includes 0`),R=[Math.min(0,R[0]),Math.max(0,R[1])])),y===`horizontal`&&h(r,t,t.headerLine||t.firstLine,`xychart horizontal 暂不支持,按纵向绘制`,`Horizontal xychart is not supported yet; drawing vertically`,"改成 `xychart` 或 `xychart vertical`","Use `xychart` or `xychart vertical`"),l?.kind===`linear`&&new Set(M).size!==M.length&&h(r,t,k,`数值 x 轴 ${l.min} --> ${l.max} 的刻度有重复,类别名已加序号`,`The numeric x-axis ${l.min} --> ${l.max} produces repeated ticks; categories were numbered`,`扩大范围或减少数据点`,`Widen the range or use fewer points`),{model:{chart:O,title:i,titleLine:a,xLabel:o,yLabel:s,xLine:u,yLine:d,yDomain:R,categories:M,datasets:N,horizontal:y===`horizontal`},errors:r}}function k(e,t,n=0){let a=g(t?.lang),o=[e.xLabel,e.yLabel].filter(Boolean).join(` · `)||void 0,s=e.yDomain?{domain:e.yDomain}:{};if(e.chart===`combo`){let t=e.categories.map((t,n)=>Object.fromEntries([[`category`,t],...e.datasets.map((e,t)=>[`v${t}`,e.values[n]])]));return{chart:`combo`,[i.diagramCombo]:{index:n},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:t,encode:{category:`category`},layers:e.datasets.map((e,t)=>({mark:e.type===`bar`?`column`:`line`,field:`v${t}`,axis:`left`})),fields:Object.fromEntries(e.datasets.map((e,t)=>[`v${t}`,{label:e.name||(a?`Series ${t+1}`:`系列 ${t+1}`),...s}]))}}let c=e.datasets[0],l=c.pointLabels.some(Boolean),u=e.categories.map((e,t)=>({category:e,value:c.values[t],...l?{id:String(t)}:{}}));return{chart:e.chart,...e.chart===`line`?{[r.diagramLine]:!0}:{},...e.title?{title:e.title}:{},...o?{subtitle:o}:{},data:u,encode:{category:`category`,value:`value`,...l?{id:`id`}:{}},fields:{value:{...s,...c.name?{label:c.name}:{}}},...l?{annotations:c.pointLabels.flatMap((e,t)=>e?[{kind:`note`,field:`value`,record:String(t),text:e}]:[])}:{}}}function A(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=e=>{let t=/^v(\d+)$/.exec(String(e||``));return t?Number(t[1]):null};if(n[0]===`title`)return e.titleLine;if(n[0]===`subtitle`)return e.xLine||e.yLine;if(n[0]===`layers`)return e.datasets[Number(n[1])]?.line||e.datasets[0]?.line;if(n[0]===`fields`){let t=r(n[1]);return(t===null?null:e.datasets[t]?.line)||e.yLine||e.datasets[0]?.line}if(n[0]===`encode`)return e.xLine||e.datasets[0]?.line;if(n[0]===`annotations`)return e.datasets[0]?.line;if(n[0]===`data`){let t=r(n[2]);return(t===null?null:e.datasets[t]?.line)||e.datasets[0]?.line}return e.datasets[0]?.line}function j(e,t){if(e.datasets.length<=d)return[e];let n=e.datasets.flatMap(e=>e.values.filter(Number.isFinite)),r=e.datasets.some(e=>e.type===`bar`)?[0]:[],i=Math.min(...n,...r),a=Math.max(...n,...r),o=e.yDomain??[i,a>i?a:i+1],s=[];for(let n=0;n<e.datasets.length;n+=d)s.push({...e,yDomain:o,title:n?null:e.title,datasets:e.datasets.slice(n,n+d).map((e,r)=>({...e,name:e.name||`${g(t.lang)?`Series `:`系列 `}${n+r+1}`}))});return s}return e.implementations={xychart:{parse:O,validate:(e,t)=>j(e,t).flatMap(e=>(0,n.validateWith)(k(e,t),t,t=>A(e,t))),layout:(e,r,a)=>{let o=j(e,a),s=r.compact?Math.min(720,Math.max(360,180+e.categories.length*52)):r.width,c=s===r.width?r:{...r,width:s},l=o.map((e,t)=>{let o=k(e,a,t);return r.compact===!0&&(o[i.compactNumeric]=!0),(0,n.renderWith)(o,c,a,t=>A(e,t))});if(l.some(e=>!e.scene))return l.find(e=>!e.scene);let u=l[0];if(l.length>1){let e=0,t=l.map(({scene:t})=>{let n=r.ctx.el(`g`,{transform:`translate(${e} 0)`},t.children);return e+=t.width+24,n});u.width=e-24,u.height=Math.max(...l.map(e=>e.height)),u.scene={...u.scene,width:u.width,height:u.height,children:t}}return(e.categories.length>60||u.width>r.width*2||l.length>1)&&u.errors.push((0,t.warning)(`LARGE_DIAGRAM`,a.lang,e.xLine||e.datasets[0]?.line||a.firstLine,l.length>1?`XY 图按数据序列分栏,可横向滚动`:`XY 图较大,可滚动查看`,l.length>1?`XY series are arranged in panels; scroll horizontally`:`Large XY chart; scroll to view it`,`按数据序列或横轴范围拆分图表`,`Split the chart by series or x-axis range`)),u},optionMode:`raw`}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/basic`],KChartUnits[`chart/multivariate`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/packet"]=(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=[`bitsPerRow`,`bitOrder`,`showBits`,`bitWidth`,`rowHeight`,`paddingX`,`paddingY`].map(e=>`packet.${e}`);function a(e,{lang:i,firstLine:a=2,title:o=``,config:s,options:c={}}){let l=[],u=[],d=new Set,f=(0,n.presentation)({lang:i}),p=(e,n)=>{let{text:a,icon:o,diagnostics:s}=(0,t.normalizeLabel)(e,{lang:i,line:n});o&&s.push((0,r.warning)(`IGNORED_ASSET`,i,n,`位域仅显示文本`,`Packet fields display text only`));for(let e of s)d.has(e.message)||(d.add(e.message),u.push(e));return a},m=(e,t,n)=>u.push((0,r.error)(i,e,t,n,`修正连续位域,或拆分图表`,`Fix the contiguous bit fields, or split the diagram`));Object.keys(c).length&&m(a-1,`packet 不接受标题行选项`,`Unexpected packet header option`);let h=0;for(let[t,n]of e.split(`
|
|
2
|
-
`).entries()){let e=a+t,r=n.trim();if(!r||r.startsWith(`%%`)||f.accept(r,e))continue;let i=/^title(?:\s*:\s*|\s+)(.+)/i.exec(r);if(i){o=p(i[1],e);continue}let s=/^(?:(\d+)(?:\s*-\s*(\d+))?|\+(\d+))\s*:\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')\s*(?:::\:([\w-]+))?\s*(?:%%.*)?$/.exec(r);if(!s){m(e,`需要位范围及带引号的名称`,`Expected a bit range and a quoted field name`);continue}let c=s[3]===void 0?Number(s[1]):h,u=s[3]===void 0?Number(s[2]??s[1]):h+Number(s[3])-1;if(c!==h){m(e,`位域应从第 ${h} 位开始`,`Field must start at bit ${h}`);continue}if(u<c){m(e,`位域长度必须为正`,`Field must have positive width`);continue}if(u>=4096||l.length>=2e3){m(e,`位域超过 4096 位或 2000 个字段`,`Packet exceeds 4096 bits or 2000 fields`);break}let d=s[4].slice(1,-1).replace(/\\(.)/g,`$1`);s[5]&&f.addClasses(d,[s[5]],e),l.push({start:c,end:u,id:d,label:p(d,e)}),h=u+1}l.length||m(a,`缺少位域`,`Expected at least one field`);for(let e of l)e.status=f.statusOf(e.id),e.link=f.linkOf(e.id);return u.push(...f.diagnostics()),{model:{type:`packet`,title:o,fields:l,config:s?.packet||{}},errors:u}}function o(e,{width:t,ctx:n,renderOptions:i},
|
|
2
|
+
`).entries()){let e=a+t,r=n.trim();if(!r||r.startsWith(`%%`)||f.accept(r,e))continue;let i=/^title(?:\s*:\s*|\s+)(.+)/i.exec(r);if(i){o=p(i[1],e);continue}let s=/^(?:(\d+)(?:\s*-\s*(\d+))?|\+(\d+))\s*:\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')\s*(?:::\:([\w-]+))?\s*(?:%%.*)?$/.exec(r);if(!s){m(e,`需要位范围及带引号的名称`,`Expected a bit range and a quoted field name`);continue}let c=s[3]===void 0?Number(s[1]):h,u=s[3]===void 0?Number(s[2]??s[1]):h+Number(s[3])-1;if(c!==h){m(e,`位域应从第 ${h} 位开始`,`Field must start at bit ${h}`);continue}if(u<c){m(e,`位域长度必须为正`,`Field must have positive width`);continue}if(u>=4096||l.length>=2e3){m(e,`位域超过 4096 位或 2000 个字段`,`Packet exceeds 4096 bits or 2000 fields`);break}let d=s[4].slice(1,-1).replace(/\\(.)/g,`$1`);s[5]&&f.addClasses(d,[s[5]],e),l.push({start:c,end:u,id:d,label:p(d,e)}),h=u+1}l.length||m(a,`缺少位域`,`Expected at least one field`);for(let e of l)e.status=f.statusOf(e.id),e.link=f.linkOf(e.id);return u.push(...f.diagnostics()),{model:{type:`packet`,title:o,fields:l,config:s?.packet||{}},errors:u}}function o(e,{width:t,ctx:n,renderOptions:i,compact:a,embedHeading:o},s={}){let{title:c,fields:l,config:u}=e,d=(0,r.appearance)(n),f=Number.isInteger(u.bitsPerRow)&&u.bitsPerRow>=1&&u.bitsPerRow<=128?u.bitsPerRow:32,p=u.showBits!==!1,m=u.bitOrder===`descending`,h=[];l.forEach((e,t)=>{for(let n=e.start;n<=e.end;){let r=Math.floor(n/f),i=Math.min(e.end,(r+1)*f-1);(h[r]??=[]).push({...e,start:n,end:i,id:t,bits:i-n+1}),n=i+1}});let g=(e,t,n,r)=>Number.isFinite(u[e])?Math.min(r,Math.max(n,u[e])):t,_=g(`paddingX`,0,0,24),v=g(`paddingY`,12,6,60),y=g(`rowHeight`,34,26,240),b=e=>e.start===e.end?String(e.start):`${e.start}–${e.end}`,x=Math.ceil(h.flat().reduce((e,t)=>Math.max(e,...t.label.split(/\s+/).map(e=>(n.measure(e,r.FONT.body.size)+10+_)/t.bits),p?(n.measure(b(t),r.FONT.label.size)+6)/t.bits:0),12)),S=Math.max(x,a?0:Math.floor((t-36)/f),g(`bitWidth`,12,12,96)),C=Math.max(a?0:t,f*S+36),w=(C-f*S)/2,T=[],E=18;c&&!i?.frame&&!o&&(T.push(n.text(C/2,E+8,c,{...r.FONT.title,anchor:`middle`,fill:d.fg1,"dominant-baseline":`central`})),E+=30);for(let e of h){let t=e.map(e=>({...e,lines:n.wrap(e.label,e.bits*S-_-8,r.FONT.body.size)})),i=Math.max(y,...t.map(e=>e.lines.length*17+14));for(let e of t){let t=w+(m?f-e.start%f-e.bits:e.start%f)*S,a=e.bits*S-_,o=t+a/2,s=d[e.status]||d.line,c=[n.rect(t,E,a,i,{fill:e.status?n.tint(d.bg,s,.1):e.id%2?d.surface:d.bg,stroke:s,meta:{kind:`node`,id:`${e.id}:${e.start}`}}),(0,r.textBlock)(n,{x:o,y:E+i/2,lines:e.lines,lineHeight:17})];T.push(...e.link?[n.link(e.link.href,c,e.link)]:c),p&&T.push(n.text(o,E+i+12,b(e),{...r.FONT.label,anchor:`middle`,"dominant-baseline":`central`}))}E+=i+v+(p?16:0)}let D=E+6,O=C>t*2||l.length>60?[(0,r.warning)(`LARGE_DIAGRAM`,n.lang,s.headerLine||1,`封包图较大`,`Large packet diagram`,`考虑拆分图表`,`Consider splitting the diagram`)]:[];return{width:C,height:D,scene:{width:C,height:D,children:T,title:c,heading:c},errors:O}}return e.implementations={packet:{parse:a,layout:o,honoredConfig:i,acceptsPresentation:!0}},e})({},KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
KChartUnits["diagram/quadrant"]=(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=[`chartWidth`,`chartHeight`,`pointRadius`,`pointLabelFontSize`,`xAxisPosition`,`yAxisPosition`,`quadrantPadding`,`xAxisLabelPadding`,`yAxisLabelPadding`,`quadrantTextTopPadding`,`pointTextPadding`].map(e=>`quadrantChart.${e}`);function a(e,{lang:i,title:a=``,firstLine:o=2,config:s,options:c={}}){let l=[],u=[],d={},f=[],p=new Set,m=new Map,h=new Set,g=(0,n.presentation)({lang:i}),_=(e,n)=>{let{text:a,icon:o,diagnostics:s}=(0,t.normalizeLabel)(e.trim().replace(/^"(.*)"$/,`$1`),{lang:i,line:n});o&&s.push((0,r.warning)(`IGNORED_ASSET`,i,n,`象限图标签仅显示文本`,`Quadrant labels display text only`));for(let e of s)h.has(e.message)||(h.add(e.message),f.push(e));return a.replace(/\n/g,` `)},v=(e,t,n)=>f.push((0,r.error)(i,e,t,n,`修正坐标或图表声明`,`Fix the coordinates or chart declaration`));Object.keys(c).length&&v(o-1,`象限图不接受标题行选项`,`Unexpected quadrantChart header option`);let y,b,x=(e,t)=>{let r={};for(let i of e?e.split(/,(?![^()]*\))/):[]){let e=/^(radius|color|stroke-color|stroke-width)\s*:\s*(.+)$/i.exec(i.trim());if(!e){v(t,`无效的点样式`,`Invalid point style`);continue}let a=e[1].toLowerCase(),o=e[2];if(a.endsWith(`color`)){let e=(0,n.roleOfColor)(o);e?r[a]=e:(y??=t,p.add(`${a}: ${o}`))}else{let e=Number(o.replace(/px$/i,``));if(!Number.isFinite(e)){v(t,`点样式需要数值`,`Expected a numeric point style`);continue}r[a]=a===`radius`?Math.min(12,Math.max(3,e)):Math.min(3,Math.max(0,e))}}return r};for(let[t,n]of e.split(`
|
|
2
|
-
`).entries()){let e=o+t,r=n.trim();if(!r||r.startsWith(`%%`))continue;let i=/^classDef\s+(\w+)\s+((?:radius|color|stroke-color|stroke-width)\s*:.*)$/i.exec(r);if(i){m.set(i[1],x(i[2],e));continue}if(g.accept(r,e))continue;let s=/^title(?:\s*:\s*|\s+)(.+)/i.exec(r);if(s){a=_(s[1],e);continue}let c=/^([xy])-axis\s+(.+)/i.exec(r);if(c){let t=[...c[2].matchAll(/"[^"]*"|--+>/g)].find(([e])=>e.startsWith(`-`)),n=t?[c[2].slice(0,t.index),c[2].slice(t.index+t[0].length)]:[c[2]];d[c[1].toLowerCase()]=n.map(t=>_(t,e)),n.length===1&&(d[c[1].toLowerCase()][0]+=` ⟶`);continue}let f=/^quadrant-([1-4])\s+(.+)/i.exec(r);if(f){u[Number(f[1])-1]=_(f[2],e);continue}let p=/^("[^"]*"|[^:]+?)(?:::\:(\w+))?\s*:\s*(\[)?\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\s*(\])?\s*(.*)$/.exec(r);if(!p||!!p[3]!=!!p[6]||!p[3]&&p[7]||Number(p[4])>1||Number(p[5])>1){v(e,`坐标必须在 0 到 1 之间`,`Expected a point with coordinates in [0, 1]`);continue}if(l.length===2e3){v(e,`点超过 2000 个,请拆分图表`,`More than 2000 points; split the diagram`);break}p[3]||(b??=e);let h=p[1].trim().replace(/^"(.*)"$/,`$1`),y=p[2];y&&g.addClasses(h,[y],e),l.push({id:h,className:y,text:_(p[1],e),x:Number(p[4]),y:Number(p[5]),style:x(p[7],e)})}for(let e of l)e.style={color:g.statusOf(e.id),...m.get(e.className),...e.style},e.link=g.linkOf(e.id);if(f.push(...g.diagnostics()),b&&f.push((0,r.warning)(`DIAGRAM_HINT`,i,b,`点坐标缺少方括号,Mermaid 不接受这种旧写法`,`Mermaid rejects point coordinates without brackets`,`写成「名称: [x, y]」`,`Write the point as Name: [x, y]`)),p.size){let e=[...p].join(`, `);f.push((0,r.warning)(`IGNORED_STYLE`,i,y,`已忽略无法匹配主题的点颜色:${e}`,`Ignored unmappable point colors: ${e}`,`使用可映射为主题状态的颜色`,`Use colors that map to theme statuses`))}return{model:{type:`quadrantChart`,title:a,axes:d,captions:u,points:l,config:s?.quadrantChart||{}},errors:f}}function o(e,{ctx:t,width:n,renderOptions:i},
|
|
2
|
+
`).entries()){let e=o+t,r=n.trim();if(!r||r.startsWith(`%%`))continue;let i=/^classDef\s+(\w+)\s+((?:radius|color|stroke-color|stroke-width)\s*:.*)$/i.exec(r);if(i){m.set(i[1],x(i[2],e));continue}if(g.accept(r,e))continue;let s=/^title(?:\s*:\s*|\s+)(.+)/i.exec(r);if(s){a=_(s[1],e);continue}let c=/^([xy])-axis\s+(.+)/i.exec(r);if(c){let t=[...c[2].matchAll(/"[^"]*"|--+>/g)].find(([e])=>e.startsWith(`-`)),n=t?[c[2].slice(0,t.index),c[2].slice(t.index+t[0].length)]:[c[2]];d[c[1].toLowerCase()]=n.map(t=>_(t,e)),n.length===1&&(d[c[1].toLowerCase()][0]+=` ⟶`);continue}let f=/^quadrant-([1-4])\s+(.+)/i.exec(r);if(f){u[Number(f[1])-1]=_(f[2],e);continue}let p=/^("[^"]*"|[^:]+?)(?:::\:(\w+))?\s*:\s*(\[)?\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\s*(\])?\s*(.*)$/.exec(r);if(!p||!!p[3]!=!!p[6]||!p[3]&&p[7]||Number(p[4])>1||Number(p[5])>1){v(e,`坐标必须在 0 到 1 之间`,`Expected a point with coordinates in [0, 1]`);continue}if(l.length===2e3){v(e,`点超过 2000 个,请拆分图表`,`More than 2000 points; split the diagram`);break}p[3]||(b??=e);let h=p[1].trim().replace(/^"(.*)"$/,`$1`),y=p[2];y&&g.addClasses(h,[y],e),l.push({id:h,className:y,text:_(p[1],e),x:Number(p[4]),y:Number(p[5]),style:x(p[7],e)})}for(let e of l)e.style={color:g.statusOf(e.id),...m.get(e.className),...e.style},e.link=g.linkOf(e.id);if(f.push(...g.diagnostics()),b&&f.push((0,r.warning)(`DIAGRAM_HINT`,i,b,`点坐标缺少方括号,Mermaid 不接受这种旧写法`,`Mermaid rejects point coordinates without brackets`,`写成「名称: [x, y]」`,`Write the point as Name: [x, y]`)),p.size){let e=[...p].join(`, `);f.push((0,r.warning)(`IGNORED_STYLE`,i,y,`已忽略无法匹配主题的点颜色:${e}`,`Ignored unmappable point colors: ${e}`,`使用可映射为主题状态的颜色`,`Use colors that map to theme statuses`))}return{model:{type:`quadrantChart`,title:a,axes:d,captions:u,points:l,config:s?.quadrantChart||{}},errors:f}}function o(e,{ctx:t,width:n,renderOptions:i,compact:a=!1,embedHeading:o},s={}){let{title:c,captions:l,axes:u,points:d,config:f}=e,p=(0,r.appearance)(t),m=(e,t,n,r)=>Number.isFinite(f[e])?Math.min(r,Math.max(n,f[e])):t,h=m(`pointLabelFontSize`,12,12,24),g=m(`pointRadius`,5,3,12),_=c&&!i?.frame&&!o,v=f.xAxisPosition?f.xAxisPosition===`top`:!d.length,y=f.yAxisPosition===`right`,b={anchor:`middle`,"dominant-baseline":`central`},x=(e,n=r.FONT.label)=>t.measure(e||``,n.size,n.weight),S=e=>(e||[]).reduce((e,t)=>e+x(t),36),C=18+m(`quadrantPadding`,5,0,48),w=Math.max(5,...d.map(e=>(e.style.radius??g)+(e.style[`stroke-width`]??1)/2)),T=w+6+m(`xAxisLabelPadding`,5,5,48),E=w+6+m(`yAxisLabelPadding`,5,5,48),D=T+10,O=E+10,k=C+(_?32:0)+(v&&u.x?D:0),A=C+(!y&&u.y?O:0),j=C+(y&&u.y?O:0),M=Math.min(440,360+Math.min(80,d.length*2)),N=Math.max(a?M:Math.min(520,n-A-j),a?0:360,m(`chartWidth`,0,0,4e3),S(u.x),...l.map(e=>2*x(e,r.FONT.title)+44).filter(Number.isFinite)),P=e=>/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u.test(e),F=(u.y||[]).reduce((e,t)=>e+(P(t)?Array.from(t).length*14:x(t)),36),I=Math.max(340,F,m(`chartHeight`,0,0,4e3)),L=A+N+j,R=k+I,z=[],B=[],V=(e,n,i,a=r.FONT.label,o=p.fg1,s={})=>{i&&z.push(t.text(e,n,i,{...a,...b,fill:o,...s}))};_&&V(L/2,26,c,r.FONT.title),z.push(t.rect(A,k,N,I,{stroke:p.line,fill:p.bg,meta:{kind:`frame`,id:`quadrants`}}));for(let e=0;e<4;e++){let n=e===0||e===3?N/2:0,r=e>=2?I/2:0,i=A+n,a=k+r;z.push(t.rect(i,a,N/2,I/2,{fill:t.tint(p.bg,t.color(`tone${e+1}`),.08),stroke:p.line}))}let H=d.map(e=>({...e,cx:A+e.x*N,cy:R-e.y*I,r:e.style.radius??g})),U=(e,t,n,r)=>({x0:e-n,x1:e+n,y0:t-r,y1:t+r}),W=e=>B.every(t=>t.x1+3<=e.x0||t.x0-3>=e.x1||t.y1+3<=e.y0||t.y0-3>=e.y1);if(H.forEach(e=>B.push(U(e.cx,e.cy,e.r+2,e.r+2))),l.forEach((e,t)=>{let n=A+(t===0||t===3?.75:.25)*N,i=k+(t>=2?I/2:0),a=x(e,r.FONT.title)/2,o=i+(H.length?15+m(`quadrantTextTopPadding`,5,3,50):I/4);for(;!W(U(n,o,a,7));)o+=18;V(n,o,e,r.FONT.title,p.fg2),B.push(U(n,o,a,7))}),u.x){let e=v?k-T:R+T;V(A,e,u.x[0],r.FONT.label,p.fg2,{anchor:`start`}),V(A+N,e,u.x[1],r.FONT.label,p.fg2,{anchor:`end`})}if(u.y){let e=y?A+N+E:A-E;[[u.y[0],R,`start`],[u.y[1],k,`end`]].forEach(([t,n,i])=>{if(P(t)){let a=Array.from(t),o=i===`end`?n+7:n-a.length*14+7;a.forEach((t,n)=>V(e,o+n*14,t,r.FONT.label,p.fg2))}else V(e,n,t,r.FONT.label,p.fg2,{anchor:i,transform:`rotate(-90 ${e} ${n})`})})}let G=[];H.forEach((e,n)=>{let i=t.circle(e.cx,e.cy,e.r,{fill:p[e.style.color]||p.accent,stroke:p[e.style[`stroke-color`]]||p.bg,"stroke-width":e.style[`stroke-width`]??1,meta:{kind:`node`,id:n}});z.push(e.link?t.link(e.link.href,[i],e.link):i);let a={...r.FONT.label,size:h},o=x(e.text,a)/2,s=Math.min(A+N-o,Math.max(A+o,e.cx)),c=e.r+h/2+m(`pointTextPadding`,5,5,40),l=[[s,e.cy+c],[s,e.cy-c],[e.cx+c+o,e.cy],[e.cx-c-o,e.cy]].find(([e,t])=>e-o>=A&&e+o<=A+N&&t-h/2>=k&&t+h/2<=R&&W(U(e,t,o,h/2)));l?(V(...l,e.text,a,p.fg1,{meta:{kind:`edge-label`}}),B.push(U(...l,o,h/2))):G.push({text:`${e.text} (${e.x}, ${e.y})`,x:e.cx})});let K=t.labelLanes(t,G,{left:A,right:A+N,maxWidth:180}),q=R+(!v&&u.x?D:0)+C;for(let e of K.items)z.push(t.textLines(e.cx,q+10+e.offset,e.lines,{...r.FONT.label,...b,fill:p.fg1}));let J=q+K.height,Y=L>n*2||d.length>60?[(0,r.warning)(`LARGE_DIAGRAM`,t.lang,s.headerLine||1,`象限图较大`,`Large quadrant chart`,`考虑拆分图表`,`Consider splitting the diagram`)]:[];return{width:L,height:J,scene:{width:L,height:J,children:z,title:c,heading:c},errors:Y}}return e.implementations={quadrantChart:{parse:a,layout:o,honoredConfig:i,acceptsPresentation:!0}},e})({},KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
KChartUnits["diagram/railroad-parse"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=e=>({type:`terminal`,value:e}),o=(e,t)=>({type:`nonterminal`,name:e,line:t.line,column:t.column}),s=e=>({type:`special`,text:e}),c=e=>({type:`optional`,element:e}),l=(e,t,n=1/0)=>({type:`repetition`,element:e,min:t,max:n}),u=e=>e.length===1?e[0]:{type:`sequence`,elements:e},d=e=>e.length===1?e[0]:{type:`choice`,alternatives:e},f=e=>e.elements||e.alternatives||(e.element?[e.element]:[]),p=e=>e.replace(/\\(.)/g,(e,t)=>({n:`
|
|
2
2
|
`,r:`\r`,t:` `})[t]??t),m=2e3,h=24,g=class extends Error{constructor(e){super(e.message),this.diagnostic=e}};function _(e,r,a,o,s){let c=a===`abnf`,l=[[`hidden`,/\s+|%%[^\n]*/y],...a===`ir`||a===`ebnf`?[[`hidden`,/\/\*[\s\S]*?\*\//y]]:[],...a===`ebnf`?[[`hidden`,/\(\*[\s\S]*?\*\)/y],[`special`,/\?(?=[^?;]*[^?\s;][^?;]*\?)[^?;]*\?/y]]:[],...a===`peg`?[[`hidden`,/#[^\n]*/y]]:[],[`title`,/title[\t ]+(?:"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|[^\n]*?)(?=[\t ]*(?:%%|\n|$))/y],[`accessibility`,/accTitle[\t ]*:[^\n]*|accDescr(?:[\t ]*:[^\n]*|\s*\{[^}]*\})/y],[`string`,c?/"[^"]*"/y:/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/y],...c?[[`numeric`,/%[xXdDbB][0-9A-Fa-f]+(?:-[0-9A-Fa-f]+|\.[0-9A-Fa-f]+)*/y],[`repeat`,/[0-9]*\*[0-9]*|[0-9]+/y]]:[],[`id`,c?/[A-Za-z][A-Za-z0-9-]*/y:/[A-Za-z_][\w-]*/y],[`icon`,/::icon\(\s*[\w:-]+\s*\)/y],[`classes`,/:::[\w-]+(?:,[\w-]+)*/y],[`punctuation`,/::=|<-|[\s\S]/y]],u=0,d=r.firstLine??2,f=1,m;function _(e){u+=e.length;let t=e.split(`
|
|
3
|
-
`);d+=t.length-1,f=t.length===1?f+e.length:t.at(-1).length+1}function v(){for(;!m;){if(u===e.length)return{kind:`end`,value:``,line:d,column:f};for(let[t,n]of l){n.lastIndex=u;let r=n.exec(e)?.[0];if(!r)continue;let i=t===`string`?c?r.slice(1,-1):p(r.slice(1,-1)):r;t!==`hidden`&&(m={kind:t===`punctuation`?r:t,value:i,line:d,column:f}),_(r);break}}return m}function y(e,t,n,a,o,s=v()){throw new g({...(0,i.error)(r.lang,s.line,t,n,a,o,s.column),code:`railroad.${e}`})}function b(e){let t=v();return t.kind===e?(m=void 0,t):null}function x(e,t=`unexpected-token
|
|
4
|
-
`+e,t={...t,firstLine:t.headerLine});let a=[],o=[],s=[],c,l,u,d=0,y=(0,r.presentation)(t),S=new Map,C=_(e,t,n,y,S),w=n===`abnf`,T=e=>w?e.toLowerCase():e;try{for(e.length>2e5&&C.fail(`source-limit`,`语法文本过长`,`Railroad source is too
|
|
3
|
+
`);d+=t.length-1,f=t.length===1?f+e.length:t.at(-1).length+1}function v(){for(;!m;){if(u===e.length)return{kind:`end`,value:``,line:d,column:f};for(let[t,n]of l){n.lastIndex=u;let r=n.exec(e)?.[0];if(!r)continue;let i=t===`string`?c?r.slice(1,-1):p(r.slice(1,-1)):r;t!==`hidden`&&(m={kind:t===`punctuation`?r:t,value:i,line:d,column:f}),_(r);break}}return m}function y(e,t,n,a,o,s=v()){throw new g({...(0,i.error)(r.lang,s.line,t,n,a,o,s.column),code:`railroad.${e}`})}function b(e){let t=v();return t.kind===e?(m=void 0,t):null}function x(e,t=`unexpected-token`,n){let r=b(e);if(r)return r;if([`"`,`'`].includes(v().kind)&&!(c&&v().kind===`'`)&&y(`unterminated-string`,`字符串未闭合`,`Unterminated string`,`添加对应的结束引号`,`Add the matching closing quote`),n!==void 0){let r=a===`ir`?`item = terminal("x");`:`item ${e} "x";`,i=a===`ebnf`?`= 或 ::=`:e,o=a===`ebnf`?`= or ::=`:e,s=n===`diagram-title`&&v().kind===`:`;y(t,`规则名后应为 ${i}`,`Expected ${o} after the rule name`,s?`标题请写 title 标题;规则请写成 ${r}`:`在规则名后使用 ${i},例如 ${r}`,s?`Write titles as title My Grammar; write rules as ${r}`:`Use ${o} after the rule name, as in ${r}`)}e===`id`&&y(t,`此处需要名称`,`Expected a name`,`使用字母开头的规则名或构造器名,例如 item`,`Use a rule or constructor name starting with a letter, such as item`),e===`string`&&y(t,`此处需要带引号的字符串`,`Expected a quoted string`,`用双引号包住文字,例如 "x"`,`Enclose the text in double quotes, as in "x"`),e===`;`&&y(t,`规则末尾缺少分号`,`Expected ; at the end of the rule`,`在规则表达式结束处加分号 ;`,`End the rule expression with a semicolon (;)`),y(t,`此处应为「${e}」`,`Expected ${e}`,`在此处补上「${e}」`,`Insert ${e} here`)}function S(e){e>h&&y(`depth-limit`,`语法轨道嵌套过深`,`Railroad nesting is too deep`,`将嵌套部分提取为规则`,`Extract nested expressions into rules`)}function C(){/^[\t ]*[A-Za-z][A-Za-z0-9-]*[\t ]*=/.test(e.slice(u))||_(/^[^\n]*/.exec(e.slice(u))[0])}function w(){let t=v();if(t.kind!==`id`||!/^(class|classdef|style|linkstyle|click|href|link|callback)$/i.test(t.value))return!1;let n=/^[^\n]*/.exec(e.slice(u))[0];return/^\s*(?:=|::=|<-|:::|::icon\()/.test(n)||!o.accept(t.value+n,t.line)?!1:(m=void 0,_(n),!0)}function T(e){s.has(e.message)||s.set(e.message,e)}function E(e,n){let a=(0,t.resolveIconRef)(e);return a||T((0,i.warning)(`IGNORED_ASSET`,r.lang,n.line,`未知图标 ${e}`,`Unknown icon ${e}`,`改用内置图标`,`Use a supported icon`,n.column)),a}function D(e,t,i){if(!/[<&#$`]|(?:fa[bsrlk]?|logos|mdi|tabler|simple-icons):|::icon\(/i.test(t))return e;let a,o=t.replace(/::icon\(\s*([\w:-]+)\s*\)|(?<![\w:-])((?:logos|mdi|tabler|simple-icons):[\w-]+)/gi,(e,t,n)=>{let r=E(t??n,i);return a??=r,``}),s=(0,n.normalizeLabel)(o,{lang:r.lang,line:i.line});s.diagnostics.forEach(T),s.text!==t.trim()&&(e.label=s.text);let c=s.icon??a;return c&&(e.icon=c),e}function O(e,t,n){let r;for(;r=b(`classes`)||b(`icon`);)r.kind===`classes`?o.addClasses(t,r.value.slice(3).split(`,`),r.line):e.icon=E(r.value.slice(7,-1).trim(),n)??e.icon;return e}return{peek:v,take:b,expect:x,fail:y,checkDepth:S,commentTail:C,presentationLine:w,label:D,decorate:O}}function v(e,t,n){let r=t===`ebnf`,i=t===`abnf`,f=t===`peg`,p=r?[`(`,`[`,`{`]:i?[`(`,`[`]:[`(`],m=[`id`,`string`,...p,...r?[`special`]:i?[`numeric`,`repeat`]:[`&`,`!`,`.`]],h=r?`|`:`/`;function g(t){let n=e.peek();if(e.take(`string`)||i&&e.take(`numeric`))return e.label(a(n.value),n.value,n);if(e.take(`id`))return e.decorate(o(n.value,n),n.value,n);if(r&&e.take(`special`)){let t=n.value.slice(1,-1).trim();return e.label(s(t),t,n)}if(f&&e.take(`.`))return s(`.`);if(p.includes(n.kind)){e.take(n.kind);let r=y(t+1);return e.expect({"(":`)`,"[":`]`,"{":`}`}[n.kind]),n.kind===`[`?c(r):n.kind===`{`?l(r,0):r}_(),e.expect(`string`)}function _(){let t=e.peek().kind;i&&[`|`,`+`,`?`,`'`,`{`].includes(t)&&e.fail(`abnf-unsupported`,`此写法不属于 ABNF`,`This syntax is not ABNF`,`使用 / 分隔选项、双引号包住文字、将重复次数放在表达式前,例如 2*4"x" / "y"`,`Use / to separate alternatives, double quotes for text, and a repeat prefix, as in 2*4"x" / "y"`),f&&[`[`,`{`,`-`,`|`].includes(t)&&e.fail(`peg-unsupported`,`此写法不属于 PEG`,`This syntax is not PEG`,`使用 / 分隔选项,用圆括号分组,重复符号写在末尾,例如 ("x" / "y")+`,`Separate alternatives with /, group with parentheses, and put repetition operators last, as in ("x" / "y")+`)}function v(t){let o=e.peek(),d=i&&e.take(`repeat`),p=f&&(e.take(`&`)||e.take(`!`)),m=g(t);if(d){let[t,n]=d.value.split(`*`),r=Number(t),i=n===void 0?r:n===``?1/0:Number(n);(!Number.isSafeInteger(r)||i!==1/0&&!Number.isSafeInteger(i)||r>i)&&e.fail(`abnf-bad-repeat`,`无效的 ABNF 重复次数`,`Invalid ABNF repetition bounds`,`先写最小次数,再写最大次数,例如 2*4"x"`,`Put the minimum before the maximum, as in 2*4"x"`,d),m=r===0&&i===1?c(m):l(m,r,i)}if(r||f){let n=0;do{if(e.take(`?`))m=c(m);else if(e.take(`*`))m=l(m,0);else if(e.take(`+`))m=l(m,1);else if(r&&e.take(`-`))m=u([m,{...a(`-`),exception:!0},g(t)]);else break;e.checkDepth(t+ ++n)}while(r)}if(p){let e=m.type===`terminal`?JSON.stringify(m.value):m.name??m.text;return e===void 0&&n.push({type:`predicate`,...o}),s(p.value+(e??`(...)`))}return m}function y(t){e.checkDepth(t);let n=[];do{let i=[v(t)];for(;r&&e.take(`,`)||m.includes(e.peek().kind);)i.push(v(t));_(),n.push(u(i))}while(e.take(h));return d(n)}return y(1)}var y=new Map(Object.entries({terminal:a,nonterminal:o,special:s,optional:c,sequence:u,choice:d,zeroOrMore:e=>l(e,0),oneOrMore:e=>l(e,1)}));function b(e,t=1){e.checkDepth(t);let n=e.expect(`id`),r=y.get(n.value);r||e.fail(`ir-unknown-constructor`,`未知构造器「${n.value}」`,`Unknown constructor ${n.value}`,`使用 ${[...y.keys()].join(`、`)}`,`Use ${[...y.keys()].join(`, `)}`,n),e.expect(`(`),e.peek().kind===`)`&&e.fail(`ir-arity`,`构造器缺少参数`,`Constructor has no arguments`,`添加参数,例如 terminal("x") 或 optional(terminal("x"))`,`Add an argument, as in terminal("x") or optional(terminal("x"))`);let i;if([`terminal`,`nonterminal`,`special`].includes(n.value)){let t=e.expect(`string`);i=e.label(r(t.value,t),t.value,t)}else if([`sequence`,`choice`].includes(n.value)){let n=[];do n.push(b(e,t+1));while(e.take(`,`));i=r(n)}else i=r(b(e,t+1));return e.expect(`)`,`ir-arity`),i.type===`nonterminal`?e.decorate(i,i.name,n):i}var x=new Set([`alpha`,`bit`,`char`,`cr`,`crlf`,`ctl`,`digit`,`dquote`,`hexdig`,`htab`,`lf`,`lwsp`,`octet`,`sp`,`vchar`,`wsp`]);function S(e,t,n){t.params&&(e=` `.repeat(t.header.lastIndexOf(t.params))+t.params+`
|
|
4
|
+
`+e,t={...t,firstLine:t.headerLine});let a=[],o=[],s=[],c,l,u,d=0,y=(0,r.presentation)(t),S=new Map,C=_(e,t,n,y,S),w=n===`abnf`,T=e=>w?e.toLowerCase():e;try{for(e.length>2e5&&C.fail(`source-limit`,`语法文本过长`,`Railroad source is too long`,`按规则拆分,每张图最多 200,000 个字符`,`Split by rule into diagrams of at most 200,000 characters`);C.peek().kind!==`end`;){if(C.presentationLine())continue;if(w&&C.take(`;`)){C.commentTail();continue}let e=C.take(`title`);if(e){let t=e.value.slice(5).trim(),n=/^["']/.test(t)&&t.at(-1)===t[0]?p(t.slice(1,-1)):t;c=C.label({},n,e).label??n;continue}let t=C.take(`accessibility`);if(t){let e=t.value;e.startsWith(`accTitle`)?l=e.slice(e.indexOf(`:`)+1).trim():u=/^accDescr\s*\{/.test(e)?e.slice(e.indexOf(`{`)+1,-1).trim():e.slice(e.indexOf(`:`)+1).trim();continue}let r=C.expect(`id`),i=C.decorate({name:r.value,line:r.line,column:r.column},r.value,r);n===`peg`?C.expect(`<-`,`peg-bad-operator`,r.value):n===`ebnf`&&C.take(`::=`)||C.expect(`=`,`unexpected-token`,r.value);let o=n===`ir`?b(C):v(C,n,s);C.expect(`;`,`rule-expected`),w&&C.commentTail();let g=[[o,1]];for(;g.length;){let[e,t]=g.pop();++d>m&&C.fail(`node-limit`,`语法图节点过多`,`Too many railroad nodes (limit ${m})`,`按规则拆分,每张图最多 ${m} 个节点`,`Split by rule into diagrams of at most ${m} nodes`,r),t>h&&C.fail(`depth-limit`,`语法轨道嵌套过深`,`Railroad nesting is too deep`,`将嵌套部分提取为规则`,`Extract nested expressions into rules`,r);for(let n of f(e))g.push([n,t+1])}a.push({...i,definition:o})}}catch(e){if(!(e instanceof g))throw e;return{model:null,errors:[e.diagnostic]}}let E=new Set,D=new Set,O=new Set,k=(e,n,r,a,s)=>o.push((0,i.warning)(`DIAGRAM_HINT`,t.lang,e.line,n,r,a,s,e.column));for(let e of a){let t=T(e.name);E.has(t)&&!O.has(t)&&(O.add(t),k(e,`规则「${e.name}」重复`,`Duplicate rule ${e.name}`,`合并重复规则`,`Combine duplicate rules`)),E.add(t)}let A=(e,t)=>{let n=y.statusOf(t),r=y.linkOf(t);n&&(e.status=n),r&&(e.link=r)};for(let e of a){A(e,e.name);let t=[e.definition];for(;t.length;){let e=t.pop();e.type===`nonterminal`&&A(e,e.name),e.type===`nonterminal`&&!E.has(T(e.name))&&!(w&&x.has(T(e.name)))&&(e.undefined=!0,D.has(T(e.name))||(D.add(T(e.name)),k(e,`未定义规则「${e.name}」`,`Undefined rule ${e.name}`,`定义该规则或检查拼写`,`Define the rule or check its spelling`))),t.push(...f(e).slice().reverse())}}return s.length&&k(s[0],`复合前瞻显示为 (…)`,`Compound lookahead is shown as (...)`,`用命名规则显示前瞻目标`,`Use a named rule to show the lookahead target`),{model:{rules:a,title:c,accTitle:l,accDescr:u,count:d,edgeStatusOf:y.edgeStatusOf},errors:[...o,...S.values(),...y.diagnostics()]}}return e.childrenOf=f,e.parseAbnf=(e,t)=>S(e,t,`abnf`),e.parseEbnf=(e,t)=>S(e,t,`ebnf`),e.parseIr=(e,t)=>S(e,t,`ir`),e.parsePeg=(e,t)=>S(e,t,`peg`),e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
KChartUnits["diagram/railroad"]=(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=[`padding`,`verticalSeparation`,`horizontalSeparation`,`arcRadius`,`fontSize`,`showMarkers`,`markerRadius`,`compactMode`].map(e=>`railroad.${e}`);function a(e){let t=Object.entries(e??{}).find(([e])=>e.toLowerCase()===`railroad`)?.[1],r=new Map(Object.entries(t??{}).map(([e,t])=>[e.toLowerCase(),t])),i=(e,t,n,i)=>{let a=r.get(e.toLowerCase());return typeof a==`number`&&Number.isFinite(a)?Math.max(n,Math.min(i,a)):t},a=r.get(`compactmode`)===!0;return{pad:i(`padding`,16,8,80),rail:a?6:i(`horizontalSeparation`,12,6,80),gap:a?6:i(`verticalSeparation`,10,6,80),radius:i(`arcRadius`,9,6,16),marker:r.get(`showmarkers`)===!1?0:i(`markerRadius`,4,2,7),font:{...n.FONT.body,size:i(`fontSize`,n.FONT.body.size,12,32)}}}var o={...n.FONT.body,weight:600},s=({min:e,max:t})=>t===1/0?`${e}+`:e===t?`×${e}`:`${e}…${t}`,c=e=>e.replace(/[\n\r\t]/g,e=>({"\n":`\\n`,"\r":`\\r`," ":`\\t`})[e]);function l(e,t,i,{rail:a,gap:o,radius:l,font:u}){let d=new Map,f=[[e,!1]];for(;f.length;){let[e,p]=f.pop(),m=(0,r.childrenOf)(e);if(!p&&m.length){f.push([e,!0],...m.map(e=>[e,!1]).reverse());continue}let h=`${i}-${d.size}`,g=m.map(e=>d.get(e)),_={id:h,entry:`${h}-in`,exit:`${h}-out`,node:e,parts:g};if(!g.length){let r=c(e.label??e.text??e.value??e.name);_.label=e.type===`special`?`? ${r} ?`:r,_.labelWidth=Math.ceil(t(_.label,u)),_.w=Math.max(24,_.labelWidth+16+(e.icon?_.label?20:14:0)),_.up=_.down=(0,n.snap)(u.size+12)/2,_.entry=_.exit=h}else if(e.type===`sequence`)_.w=g.reduce((e,t)=>e+t.w,(g.length-1)*a),_.up=Math.max(...g.map(e=>e.up)),_.down=Math.max(...g.map(e=>e.down)),_.entry=g[0].entry,_.exit=g.at(-1).exit;else if(e.type===`choice`){let e=o+Math.min(14,Math.max(0,2*(g.length-3))),t=0,n=g.map(n=>{let r=t+n.up;return t=r+n.down+e,r}),r=n[Math.floor((n.length-1)/2)];_.lanes=n.map(e=>e-r),_.w=Math.max(...g.map(e=>e.w))+4*l,_.up=r,_.down=t-e-r}else{let[r]=g;_.bypass=e.type===`optional`||e.min===0,_.caption=e.type===`repetition`?s(e):null,_.w=4*l+Math.max(r.w,_.caption?Math.ceil(t(_.caption,n.FONT.label))+16:0),_.up=r.up+(_.bypass?2*l:0),_.down=r.down+(_.caption?2*l+8:0)}d.set(e,_)}return d.get(e)}function u(e,t,n,r,{rail:i,radius:a}){let o=[[e,t,n]],{edge:s,chip:c,count:l}=r;for(;o.length;){let[e,t,n]=o.pop(),r=t+e.w,u=a,{parts:d,entry:f,exit:p}=e;if(!d.length){c(e,t,n);continue}let m=[];if(e.node.type===`sequence`){let e=t;d.forEach((t,r)=>{r&&s(`M ${e-i} ${n} H ${e}`,d[r-1].exit,t.entry),m.push([t,e,n]),e+=t.w+i})}else if(e.node.type===`choice`){let i=t+u,a=r-u;s(`M ${t} ${n} H ${i}`,f,`${f}-fan`),s(`M ${a} ${n} H ${r}`,`${p}-fan`,p);let o=n+Math.min(0,e.lanes[0]+u),c=n+Math.max(0,e.lanes.at(-1)-u);s(`M ${i} ${o} V ${c}`,`${f}-fan`,`${f}-fan`),s(`M ${a} ${o} V ${c}`,`${p}-fan`,`${p}-fan`),d.forEach((r,o)=>{let c=n+e.lanes[o],l=t+(e.w-r.w)/2,d=Math.sign(e.lanes[o])*u,h=d?`M ${i} ${c-d} A ${u} ${u} 0 0 ${d>0?0:1} ${i+u} ${c}`:`M ${i} ${n}`,g=d?`H ${a-u} A ${u} ${u} 0 0 ${d>0?0:1} ${a} ${c-d}`:`H ${a}`;s(`${h} H ${l}`,`${f}-fan`,r.entry),s(`M ${l+r.w} ${c} ${g}`,r.exit,`${p}-fan`),m.push([r,l,c])})}else{let[i]=d,a=t+(e.w-i.w)/2,o=t+2*u,c=r-2*u;if(s(`M ${t} ${n} H ${a}`,f,i.entry),s(`M ${a+i.w} ${n} H ${r}`,i.exit,p),e.bypass){let i=n-e.up+2;s(`M ${t} ${n} Q ${t+u} ${n} ${t+u} ${n-u} V ${i+u} Q ${t+u} ${i} ${o} ${i} H ${c} Q ${r-u} ${i} ${r-u} ${i+u} V ${n-u} Q ${r-u} ${n} ${r} ${n}`,f,p)}if(e.caption){let t=n+i.down+2*u,r=(o+c)/2,a=l(e.caption,r,t);s(`M ${c} ${n} Q ${c+u} ${n} ${c+u} ${n+u} V ${t-u} Q ${c+u} ${t} ${c} ${t} H ${r+a}`,i.exit,`${e.id}-count`),s(`M ${r-a} ${t} H ${o} Q ${o-u} ${t} ${o-u} ${t-u} V ${n+u} Q ${o-u} ${n} ${o} ${n}`,`${e.id}-count`,i.entry)}m.push([i,a,n])}o.push(...m.reverse())}}function d(e,{width:r,ctx:i,measure:s,lang:c,renderOptions:d},f){let p=(0,t.structureRoles)(d).colors,m=a(f.config),{pad:h,gap:g,marker:_,font:v}=m,y=[],b=[],x=[],S=p[`edge-strong`],C=(t,n,r)=>y.push(i.path(t,{fill:`none`,stroke:i.design[e.edgeStatusOf(y.length)]??S,"stroke-width":1.5,"stroke-linecap":`round`,meta:{kind:`edge`,from:n,to:r}})),w=(e,t,r,a,o,s)=>(0,n.textBlock)(i,{lines:[e],x:t,y:r,font:a,anchor:o,fill:s}),T=(e,t)=>e?i.link(e.href,t,e):i.el(`g`,{},t);function E(e,t,n){let[r,a,o,s]=e.viewBox.split(/\s+/).map(Number),c=14/Math.max(o,s),l=i.design.fg1;return i.el(`g`,{transform:`translate(${t-(r+o/2)*c} ${n-(a+s/2)*c}) scale(${c})`},e.elements.map(({tag:t,attrs:n})=>i.shape(t,{...n,...e.set===`simple`?{fill:l}:{fill:`none`,stroke:l,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))}let D=(e,t,n)=>{let r=e.node.type===`special`,{icon:a,status:o,link:s}=e.node,c=i.design[o]??(e.node.undefined||e.node.exception?i.design.warn:r?p[`em-line`]:p[`node-line`]),l=t+e.w/2,u=[i.rect(t,n-e.up,e.w,e.up+e.down,{rx:e.node.type===`terminal`?e.up:2,fill:r?p[`em-fill`]:p.node,stroke:c,...r?{"stroke-dasharray":`4 3`}:{},meta:{kind:`node`,id:e.id}})];a&&u.push(E(a,l-(e.label?e.labelWidth/2+3:0),n)),e.label&&u.push(w(e.label,l+(a?10:0),n,v,`middle`,i.design.fg1)),b.push(T(s,u))},O=(e,t,r)=>(x.push(i.text(t,r,e,{...n.FONT.label,anchor:`middle`,fill:S,"dominant-baseline":`central`,meta:{kind:`edge-label`}})),Math.ceil(s(e,n.FONT.label))/2+5),k=h+Math.ceil(Math.max(0,...e.rules.map(e=>s(`${e.name} =`,o)+(e.icon?20:0))))+16,A=k+16,j=h,M=200;for(let[t,n]of e.rules.entries()){let e=`rule-${t}`,r=l(n.definition,s,e,m),a=j+r.up,c=A+r.w+16,d=i.design[n.status]??S,f=w(`${n.name} =`,h+(n.icon?20:0),a,o,`start`,i.textColor(i.design[n.status]??i.design.fg1));if(x.push(T(n.link,n.icon?[E(n.icon,h+7,a),f]:[f])),_)for(let[t,n]of[[k,`start`],[c,`end`]])b.push(i.circle(t,a,_,{fill:d,meta:{kind:`node`,id:`${e}-${n}`}}));C(`M ${k+_} ${a} H ${A}`,`${e}-start`,r.entry),u(r,A,a,{chip:D,count:O,edge:C},m),C(`M ${A+r.w} ${a} H ${c-_}`,r.exit,`${e}-end`),M=Math.max(M,c+_+h),j=a+r.down+g+14}let N=M>2*r||e.count>60?[(0,n.warning)(`LARGE_DIAGRAM`,c,f.headerLine,`语法图较大,可在图框中滚动`,`Large
|
|
1
|
+
KChartUnits["diagram/railroad"]=(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=[`padding`,`verticalSeparation`,`horizontalSeparation`,`arcRadius`,`fontSize`,`showMarkers`,`markerRadius`,`compactMode`].map(e=>`railroad.${e}`);function a(e){let t=Object.entries(e??{}).find(([e])=>e.toLowerCase()===`railroad`)?.[1],r=new Map(Object.entries(t??{}).map(([e,t])=>[e.toLowerCase(),t])),i=(e,t,n,i)=>{let a=r.get(e.toLowerCase());return typeof a==`number`&&Number.isFinite(a)?Math.max(n,Math.min(i,a)):t},a=r.get(`compactmode`)===!0;return{pad:i(`padding`,16,8,80),rail:a?6:i(`horizontalSeparation`,12,6,80),gap:a?6:i(`verticalSeparation`,10,6,80),radius:i(`arcRadius`,9,6,16),marker:r.get(`showmarkers`)===!1?0:i(`markerRadius`,4,2,7),font:{...n.FONT.body,size:i(`fontSize`,n.FONT.body.size,12,32)}}}var o={...n.FONT.body,weight:600},s=({min:e,max:t})=>t===1/0?`${e}+`:e===t?`×${e}`:`${e}…${t}`,c=e=>e.replace(/[\n\r\t]/g,e=>({"\n":`\\n`,"\r":`\\r`," ":`\\t`})[e]);function l(e,t,i,{rail:a,gap:o,radius:l,font:u}){let d=new Map,f=[[e,!1]];for(;f.length;){let[e,p]=f.pop(),m=(0,r.childrenOf)(e);if(!p&&m.length){f.push([e,!0],...m.map(e=>[e,!1]).reverse());continue}let h=`${i}-${d.size}`,g=m.map(e=>d.get(e)),_={id:h,entry:`${h}-in`,exit:`${h}-out`,node:e,parts:g};if(!g.length){let r=c(e.label??e.text??e.value??e.name);_.label=e.type===`special`?`? ${r} ?`:r,_.labelWidth=Math.ceil(t(_.label,u)),_.w=Math.max(24,_.labelWidth+16+(e.icon?_.label?20:14:0)),_.up=_.down=(0,n.snap)(u.size+12)/2,_.entry=_.exit=h}else if(e.type===`sequence`)_.w=g.reduce((e,t)=>e+t.w,(g.length-1)*a),_.up=Math.max(...g.map(e=>e.up)),_.down=Math.max(...g.map(e=>e.down)),_.entry=g[0].entry,_.exit=g.at(-1).exit;else if(e.type===`choice`){let e=o+Math.min(14,Math.max(0,2*(g.length-3))),t=0,n=g.map(n=>{let r=t+n.up;return t=r+n.down+e,r}),r=n[Math.floor((n.length-1)/2)];_.lanes=n.map(e=>e-r),_.w=Math.max(...g.map(e=>e.w))+4*l,_.up=r,_.down=t-e-r}else{let[r]=g;_.bypass=e.type===`optional`||e.min===0,_.caption=e.type===`repetition`?s(e):null,_.w=4*l+Math.max(r.w,_.caption?Math.ceil(t(_.caption,n.FONT.label))+16:0),_.up=r.up+(_.bypass?2*l:0),_.down=r.down+(_.caption?2*l+8:0)}d.set(e,_)}return d.get(e)}function u(e,t,n,r,{rail:i,radius:a}){let o=[[e,t,n]],{edge:s,chip:c,count:l}=r;for(;o.length;){let[e,t,n]=o.pop(),r=t+e.w,u=a,{parts:d,entry:f,exit:p}=e;if(!d.length){c(e,t,n);continue}let m=[];if(e.node.type===`sequence`){let e=t;d.forEach((t,r)=>{r&&s(`M ${e-i} ${n} H ${e}`,d[r-1].exit,t.entry),m.push([t,e,n]),e+=t.w+i})}else if(e.node.type===`choice`){let i=t+u,a=r-u;s(`M ${t} ${n} H ${i}`,f,`${f}-fan`),s(`M ${a} ${n} H ${r}`,`${p}-fan`,p);let o=n+Math.min(0,e.lanes[0]+u),c=n+Math.max(0,e.lanes.at(-1)-u);s(`M ${i} ${o} V ${c}`,`${f}-fan`,`${f}-fan`),s(`M ${a} ${o} V ${c}`,`${p}-fan`,`${p}-fan`),d.forEach((r,o)=>{let c=n+e.lanes[o],l=t+(e.w-r.w)/2,d=Math.sign(e.lanes[o])*u,h=d?`M ${i} ${c-d} A ${u} ${u} 0 0 ${d>0?0:1} ${i+u} ${c}`:`M ${i} ${n}`,g=d?`H ${a-u} A ${u} ${u} 0 0 ${d>0?0:1} ${a} ${c-d}`:`H ${a}`;s(`${h} H ${l}`,`${f}-fan`,r.entry),s(`M ${l+r.w} ${c} ${g}`,r.exit,`${p}-fan`),m.push([r,l,c])})}else{let[i]=d,a=t+(e.w-i.w)/2,o=t+2*u,c=r-2*u;if(s(`M ${t} ${n} H ${a}`,f,i.entry),s(`M ${a+i.w} ${n} H ${r}`,i.exit,p),e.bypass){let i=n-e.up+2;s(`M ${t} ${n} Q ${t+u} ${n} ${t+u} ${n-u} V ${i+u} Q ${t+u} ${i} ${o} ${i} H ${c} Q ${r-u} ${i} ${r-u} ${i+u} V ${n-u} Q ${r-u} ${n} ${r} ${n}`,f,p)}if(e.caption){let t=n+i.down+2*u,r=(o+c)/2,a=l(e.caption,r,t);s(`M ${c} ${n} Q ${c+u} ${n} ${c+u} ${n+u} V ${t-u} Q ${c+u} ${t} ${c} ${t} H ${r+a}`,i.exit,`${e.id}-count`),s(`M ${r-a} ${t} H ${o} Q ${o-u} ${t} ${o-u} ${t-u} V ${n+u} Q ${o-u} ${n} ${o} ${n}`,`${e.id}-count`,i.entry)}m.push([i,a,n])}o.push(...m.reverse())}}function d(e,{width:r,ctx:i,measure:s,lang:c,renderOptions:d},f){let p=(0,t.structureRoles)(d).colors,m=a(f.config),{pad:h,gap:g,marker:_,font:v}=m,y=[],b=[],x=[],S=p[`edge-strong`],C=(t,n,r)=>y.push(i.path(t,{fill:`none`,stroke:i.design[e.edgeStatusOf(y.length)]??S,"stroke-width":1.5,"stroke-linecap":`round`,meta:{kind:`edge`,from:n,to:r}})),w=(e,t,r,a,o,s)=>(0,n.textBlock)(i,{lines:[e],x:t,y:r,font:a,anchor:o,fill:s}),T=(e,t)=>e?i.link(e.href,t,e):i.el(`g`,{},t);function E(e,t,n){let[r,a,o,s]=e.viewBox.split(/\s+/).map(Number),c=14/Math.max(o,s),l=i.design.fg1;return i.el(`g`,{transform:`translate(${t-(r+o/2)*c} ${n-(a+s/2)*c}) scale(${c})`},e.elements.map(({tag:t,attrs:n})=>i.shape(t,{...n,...e.set===`simple`?{fill:l}:{fill:`none`,stroke:l,"stroke-width":1.6,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))}let D=(e,t,n)=>{let r=e.node.type===`special`,{icon:a,status:o,link:s}=e.node,c=i.design[o]??(e.node.undefined||e.node.exception?i.design.warn:r?p[`em-line`]:p[`node-line`]),l=t+e.w/2,u=[i.rect(t,n-e.up,e.w,e.up+e.down,{rx:e.node.type===`terminal`?e.up:2,fill:r?p[`em-fill`]:p.node,stroke:c,...r?{"stroke-dasharray":`4 3`}:{},meta:{kind:`node`,id:e.id}})];a&&u.push(E(a,l-(e.label?e.labelWidth/2+3:0),n)),e.label&&u.push(w(e.label,l+(a?10:0),n,v,`middle`,i.design.fg1)),b.push(T(s,u))},O=(e,t,r)=>(x.push(i.text(t,r,e,{...n.FONT.label,anchor:`middle`,fill:S,"dominant-baseline":`central`,meta:{kind:`edge-label`}})),Math.ceil(s(e,n.FONT.label))/2+5),k=h+Math.ceil(Math.max(0,...e.rules.map(e=>s(`${e.name} =`,o)+(e.icon?20:0))))+16,A=k+16,j=h,M=200;for(let[t,n]of e.rules.entries()){let e=`rule-${t}`,r=l(n.definition,s,e,m),a=j+r.up,c=A+r.w+16,d=i.design[n.status]??S,f=w(`${n.name} =`,h+(n.icon?20:0),a,o,`start`,i.textColor(i.design[n.status]??i.design.fg1));if(x.push(T(n.link,n.icon?[E(n.icon,h+7,a),f]:[f])),_)for(let[t,n]of[[k,`start`],[c,`end`]])b.push(i.circle(t,a,_,{fill:d,meta:{kind:`node`,id:`${e}-${n}`}}));C(`M ${k+_} ${a} H ${A}`,`${e}-start`,r.entry),u(r,A,a,{chip:D,count:O,edge:C},m),C(`M ${A+r.w} ${a} H ${c-_}`,r.exit,`${e}-end`),M=Math.max(M,c+_+h),j=a+r.down+g+14}let N=M>2*r||e.count>60?[(0,n.warning)(`LARGE_DIAGRAM`,c,f.headerLine,`语法图较大,可在图框中滚动`,`Large syntax diagram; scroll inside the frame`,`将完整规则分到多张图;把过长的表达式提取为命名规则`,`Split whole rules across diagrams; extract long expressions into named rules`)]:[];return{scene:{width:M,height:e.rules.length?j-g-14+h:100,children:[...y,...b,...x],title:f.accTitle||e.accTitle||e.title,heading:e.title,description:f.accDescr||e.accDescr},errors:N}}var f=e=>({optionMode:`raw`,parse:e,layout:d,acceptsPresentation:!0,honoredConfig:i});return e.implementations={"railroad-beta":f(r.parseIr),"railroad-ebnf-beta":f(r.parseEbnf),"railroad-abnf-beta":f(r.parseAbnf),"railroad-peg-beta":f(r.parsePeg)},e})({},KChartUnits[`core/context`],KChartUnits[`diagram/support`],KChartUnits[`diagram/railroad-parse`]);
|