@fengwk/kchart 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +31 -2
  3. package/README.zh-CN.md +31 -2
  4. package/dist/esm/_virtual/_kchart-families.js +2 -1
  5. package/dist/esm/assets/themes/cloudmusic.js +1 -1
  6. package/dist/esm/chart/composition.js +7 -5
  7. package/dist/esm/chart/maps.js +9 -7
  8. package/dist/esm/chart/mindmap.js +19 -5
  9. package/dist/esm/chart/multivariate.js +99 -49
  10. package/dist/esm/chart/relations.js +15 -7
  11. package/dist/esm/chart/spec.js +11 -4
  12. package/dist/esm/core/context.js +29 -10
  13. package/dist/esm/core/scene.js +238 -21
  14. package/dist/esm/core/text.js +1 -1
  15. package/dist/esm/diagram/block.js +287 -295
  16. package/dist/esm/diagram/blocks.js +541 -605
  17. package/dist/esm/diagram/board-paint.js +594 -0
  18. package/dist/esm/diagram/board-route.js +60 -0
  19. package/dist/esm/diagram/c4.js +75 -35
  20. package/dist/esm/diagram/class.js +3 -2
  21. package/dist/esm/diagram/cynefin.js +55 -9
  22. package/dist/esm/diagram/eventmodeling.js +21 -10
  23. package/dist/esm/diagram/gantt.js +37 -15
  24. package/dist/esm/diagram/gitgraph.js +26 -5
  25. package/dist/esm/diagram/graph-layout.js +39 -2
  26. package/dist/esm/diagram/graph-route.js +296 -38
  27. package/dist/esm/diagram/info.js +32 -0
  28. package/dist/esm/diagram/journey.js +5 -5
  29. package/dist/esm/diagram/kanban.js +3 -3
  30. package/dist/esm/diagram/layers.js +9 -7
  31. package/dist/esm/diagram/mindmap.js +5 -1
  32. package/dist/esm/diagram/numeric-composition.js +24 -4
  33. package/dist/esm/diagram/numeric-model.js +1 -1
  34. package/dist/esm/diagram/numeric-radar.js +25 -7
  35. package/dist/esm/diagram/numeric-sankey.js +4 -3
  36. package/dist/esm/diagram/numeric-xy.js +14 -4
  37. package/dist/esm/diagram/packet.js +4 -4
  38. package/dist/esm/diagram/quadrant.js +12 -5
  39. package/dist/esm/diagram/railroad-parse.js +20 -10
  40. package/dist/esm/diagram/railroad.js +1 -1
  41. package/dist/esm/diagram/registry.js +46 -8
  42. package/dist/esm/diagram/sequence.js +43 -6
  43. package/dist/esm/diagram/swimlane.js +2 -2
  44. package/dist/esm/diagram/time.js +3 -3
  45. package/dist/esm/diagram/timeline.js +5 -5
  46. package/dist/esm/diagram/treeview.js +5 -3
  47. package/dist/esm/diagram/venn.js +117 -149
  48. package/dist/esm/diagram/wardley.js +61 -26
  49. package/dist/esm/diagram/zenuml.js +338 -0
  50. package/dist/esm/index.d.ts +3 -1
  51. package/dist/esm/mermaid.d.ts +1 -1
  52. package/dist/esm/mermaid.js +2 -1
  53. package/dist/esm/node.js +8 -2
  54. package/dist/esm/src/families.js +6 -1
  55. package/dist/units/chart/composition.js +1 -1
  56. package/dist/units/chart/maps.js +1 -1
  57. package/dist/units/chart/mindmap.js +1 -1
  58. package/dist/units/chart/multivariate.js +1 -1
  59. package/dist/units/chart/relations.js +1 -1
  60. package/dist/units/chart/spec.js +1 -1
  61. package/dist/units/core/context.js +1 -1
  62. package/dist/units/core/scene.js +1 -1
  63. package/dist/units/core/text.js +1 -1
  64. package/dist/units/core/theme.js +1 -1
  65. package/dist/units/diagram/block.js +2 -2
  66. package/dist/units/diagram/blocks.js +2 -2
  67. package/dist/units/diagram/board-paint.js +1 -0
  68. package/dist/units/diagram/board-route.js +1 -0
  69. package/dist/units/diagram/c4.js +1 -1
  70. package/dist/units/diagram/class.js +2 -2
  71. package/dist/units/diagram/cynefin.js +2 -2
  72. package/dist/units/diagram/eventmodeling.js +4 -4
  73. package/dist/units/diagram/gantt.js +3 -3
  74. package/dist/units/diagram/gitgraph.js +2 -1
  75. package/dist/units/diagram/graph-layout.js +1 -1
  76. package/dist/units/diagram/graph-route.js +1 -1
  77. package/dist/units/diagram/info.js +2 -0
  78. package/dist/units/diagram/journey.js +3 -3
  79. package/dist/units/diagram/kanban.js +1 -1
  80. package/dist/units/diagram/layers.js +1 -1
  81. package/dist/units/diagram/mindmap.js +1 -1
  82. package/dist/units/diagram/numeric-composition.js +1 -1
  83. package/dist/units/diagram/numeric-model.js +1 -1
  84. package/dist/units/diagram/numeric-radar.js +2 -2
  85. package/dist/units/diagram/numeric-sankey.js +1 -1
  86. package/dist/units/diagram/numeric-xy.js +1 -1
  87. package/dist/units/diagram/packet.js +1 -1
  88. package/dist/units/diagram/quadrant.js +1 -1
  89. package/dist/units/diagram/railroad-parse.js +2 -2
  90. package/dist/units/diagram/railroad.js +1 -1
  91. package/dist/units/diagram/registry.js +2 -2
  92. package/dist/units/diagram/sequence.js +1 -1
  93. package/dist/units/diagram/swimlane.js +2 -2
  94. package/dist/units/diagram/time.js +1 -1
  95. package/dist/units/diagram/timeline.js +1 -1
  96. package/dist/units/diagram/treeview.js +1 -1
  97. package/dist/units/diagram/venn.js +2 -2
  98. package/dist/units/diagram/wardley.js +4 -4
  99. package/dist/units/diagram/zenuml.js +2 -0
  100. package/dist/units.json +82 -52
  101. package/package.json +1 -1
  102. package/dist/esm/diagram/relations.js +0 -966
  103. package/dist/units/diagram/relations.js +0 -3
@@ -1,2 +1,2 @@
1
1
  KChartUnits["diagram/mindmap"]=(function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=2e3,l=100,u=[`bilateral`,`right`,`left`,`radial`,`org`,`brace`,`fishbone`,`timeline`],d=new Set([`tidy-tree`,`dagre`,`elk`,`cose-bilkent`]),f=[[`((`,`))`,`circle`],[`))`,`((`,`bang`],[`{{`,`}}`,`hexagon`],[`-)`,`(-`,`cloud`],[`(-`,`-)`,`cloud`],[`[`,`]`,`rect`],[`(`,`)`,`rounded`],[`)`,`(`,`cloud`]],p=/[()[\]{}]|-\)|\(-/,m=e=>e.length>1&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e;function h(e){let t=e.trim(),n=t.search(p);if(n<0)return{label:m(t).trim(),shape:`none`};for(let[e,r,i]of f)if(!(!t.startsWith(e,n)||!t.endsWith(r)||t.length<n+e.length+r.length))return{label:m(t.slice(n+e.length,t.length-r.length).trim()).trim(),shape:i};return{label:t,shape:``}}function g(e,n,r,i){let a=[];for(let[o,s]of e.entries()){if(!s.trim()||s.trimStart().startsWith(`%%`))continue;let e=n+o;if(/^[ \t]*\t/.test(s)){i.push((0,t.error)(r,e,`缩进不能使用 Tab`,`Tabs are not allowed in indentation`,`把 Tab 换成空格`,`Replace tabs with spaces`));continue}let c=s.match(/^ */)[0].length;a.push({text:s.slice(c).trimEnd(),line:e,indent:c})}return a}function _(e,a={}){let f=a.lang||`zh`,m=Number.isInteger(a.firstLine)?a.firstLine:2,_=a.headerLine||m-1,v=[],y=(e,n,r,i=`修正脑图语法后重试`,a=`Correct the mindmap syntax and try again`,o=1)=>{v.push((0,t.error)(f,e,n,r,i,a,o))},b=String(e??``).split(`
2
- `),x=(0,n.presentation)({lang:f}),S=new Set,C=new Map,w=e=>{S.has(e.message)||(S.add(e.message),v.push(e))},T=new Map,E=-1;for(let e=0;e<b.length;e+=1){let n=b[e].trim();if(n&&!n.startsWith(`%%`)){if(x.accept(n,m+e))b[e]=``;else if(/^(?::::|::icon\b)/i.test(n)){b[e]=``;let r=/^:::\s*([\w-]+(?:\s+[\w-]+)*)$/.exec(n)?.[1],a=/^::icon\(\s*([^()]+?)\s*\)$/i.exec(n)?.[1];if(E<0||!r&&!a)y(m+e,`脑图装饰无效或前面缺少节点`,`Malformed mindmap decoration or missing preceding node`);else{let n=T.get(E)||{classes:[]};r&&n.classes.push(...r.split(/\s+/)),a&&(n.icon=(0,i.resolveIconRef)(a),n.icon||w((0,t.warning)(`IGNORED_ASSET`,f,m+e,`未知图标 ${a}`,`Unknown icon ${a}`,`改用内置图标`,`Use a supported icon`))),T.set(E,n)}}else E=e}}let D=g(b,m,f,v),O=[],k=[],A=new Map,j=0,M=0;for(let e of D){for(;k.length&&e.indent<=k.at(-1).indent;)k.pop();let t=k.at(-1)?.node??null,n=k.length;M=Math.max(M,n+1);let{label:i,shape:a}=h(e.text),o=(a===`none`?``:e.text.split(p,1)[0].trim())||i,s=(0,r.normalizeLabel)(i,{lang:f,line:e.line});s.diagnostics.forEach(w);let u=s.text||(s.icon?o||` `:``);j+=1,j===2001&&y(e.line,`脑图超过安全上限 ${c} 个节点`,`Mindmap exceeds the safety cap of ${c} nodes`,`拆分脑图后重试`,`Split the mindmap and try again`),n>=l&&y(e.line,`脑图超过安全深度上限 ${l} 层`,`Mindmap exceeds the safety depth cap of ${l}`,`拆分脑图或降低层级`,`Split the mindmap or reduce its depth`),/:::(?:[\w-]+)?|::icon\(/i.test(e.text)&&y(e.line,`不支持行内节点装饰`,`Inline node decorations are unsupported`,`在节点下一行使用受控 :::状态 标记`,`Use a supported :::status marker on the next line`),u||y(e.line,`节点名称不能为空`,`Node label cannot be empty`);let d={label:u,children:[]};a&&(d.shape=a);let g=T.get(e.line-m);g?.classes.length&&x.addClasses(o,g.classes,e.line),C.set(d,{id:o,icon:g?.icon||s.icon});let _=t?t.children.length:O.length;A.set(t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`,e.line);let v=t?`${k.at(-1).path}/children/${_}`:`/roots/${_}`;t?t.children.push(d):O.length?(y(e.line,`mindmap 只能有一个根节点:「${u}」没有父节点`,`A mindmap can have only one root: "${u}" has no parent`,`把该节点缩进到更浅一级的节点下面`,`Indent this node under a shallower node`),O[0].children.push(d)):O.push(d),k.push({indent:e.indent,node:d,path:v})}O.length||y(m,`脑图中没有节点`,`Mindmap is empty`,`保留一个根节点并将其他节点缩进到它下面`,`Keep one root node and indent all other nodes beneath it`);let N=a.config?.layout??a.config?.mindmap?.layoutAlgorithm??(typeof a.layout==`string`?a.layout:a.layout?.config?.layout??a.layout?.layout),P=`bilateral`;if(N!=null&&N!==``){let e=String(N).toLowerCase();d.has(e)?P=`bilateral`:u.includes(e)?P=e:v.push((0,t.warning)(`IGNORED_CONFIG`,f,_,`脑图布局「${N}」不生效;按 bilateral 排版`,`Mindmap layout "${N}" is not honored; laid out as bilateral`,`改用 bilateral、right、left、radial、org、brace、fishbone 或 timeline`,`Use bilateral, right, left, radial, org, brace, fishbone, or timeline`))}for(let e of Object.keys(a.options||{}))y(_,`脑图头行不支持选项「${e}」`,`Mindmap header option is unsupported: ${e}`,`移除头行选项,使用 config.layout 指定布局`,`Remove the header option; use config.layout to choose a layout`);let F=O[0]||{label:``};A.has(`/roots/0`)&&A.set(`/data`,A.get(`/roots/0`)),v.push(...x.diagnostics());for(let[e,{id:t,icon:n}]of C){let r=x.statusOf(t);r&&(e.status=r),e[s.mindmapPresentation]={icon:n,link:x.linkOf(t)}}let I={chart:`mindmap`,data:F,layout:P,[s.mindmapPresentation]:!0,[o.sizeBudget]:{nodes:2001,depth:101}};Object.defineProperties(I,{nodeCount:{value:j},maxDepth:{value:M}}),a.title&&(I.title=a.title);let L=(0,o.validate)(I);for(let e of L.errors){let n=``,r=m;for(let t of e.path.split(`/`).slice(1))n+=`/${t}`,A.has(n)&&(r=A.get(n));v.push({...(0,t.error)(f,r,e.message,e.message,e.fix,e.fix),code:e.code,path:e.path})}return{model:I,errors:v}}var v=(0,a.createRegistry)(o.validate);v.register(`mindmap`,a.layouts.get(`mindmap`));function y(e,n={},r={}){let i=e.nodeCount>80&&e.layout!==`radial`,a=v.layout(i?{...e,layout:`radial`}:e,n.renderOptions||n),o=n.width||800,s=e.nodeCount>60||e.maxDepth>5||a.width>o*2?[(0,t.warning)(`LARGE_DIAGRAM`,r.lang||n.lang||`zh`,r.firstLine||1,i?`大型脑图使用径向布局以避免重叠`:`脑图较大,可在图内滚动查看`,i?`Large mindmap uses radial layout to avoid overlaps`:`Large mindmap; scroll within the figure`,`拆分脑图以便阅读`,`Split the mindmap for readability`)]:[];return{width:a.width,height:a.height,scene:a,errors:s}}return e.implementations={mindmap:{acceptsPresentation:!0,honoredConfig:[`layout`,`mindmap.layoutAlgorithm`],parse:_,layout:y,scene:e=>e.scene}},e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/label`],KChartUnits[`core/icons`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`],KChartUnits[`chart/mindmap`]);
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:(e,i,a)=>(0,n.renderWith)(t(e,a),i,a,t=>r(e,t.path))}}var c=s(t.parsePie,e=>({chart:`pie`,title:e.title||void 0,sliceLabels:!0,data:e.rows.map(({category:e,value:t})=>({category:e,value:t})),encode:{category:`category`,value:`value`},[r.compositionPresentation]:{labelRadius:e.labelRadius}}),(e,t)=>t===`/title`?e.titleLine:e.rows[Number(t?.split(`/`)[2])]?.line||e.rows[0]?.line,{optionMode:`raw`,honoredConfig:[`pie.textPosition`]}),l=(e,n)=>({chart:`treemap`,title:e.title||void 0,data:e.data,fields:e.valueField?{value:e.valueField}:void 0,[r.compositionPresentation]:{showValues:n.config?.treemap?.showValues!==!1,prefix:e.prefix,namedRoot:e.namedRoot},[a.sizeBudget]:{nodes:t.TREEMAP_MAX_NODES+1,depth:t.TREEMAP_MAX_DEPTH+1}}),u=(e,t)=>{if(t===`/title`)return e.titleLine;for(let n=t;n;n=n.slice(0,n.lastIndexOf(`/`))){if(e.treeLines[n])return e.treeLines[n];if(!n.includes(`/`))break}return null},d=(0,i.createRegistry)(a.validate);return d.register(`treemap`,i.layouts.get(`treemap`)),e.implementations={pie:c,treemap:{parse:t.parseTreemap,acceptsPresentation:!0,honoredConfig:[`treemap.showValues`,`treemap.valueFormat`],validate(e,t){let r=l(e,t);return(0,n.diagnostics)((0,a.validate)(r).errors,t,t=>u(e,t.path))},layout(e,t,r){let i=l(e,r),a=(0,n.renderWith)(i,t,r,t=>u(e,t.path),d.layout);return a.scene&&(e.nodeCount>60||e.depth>5||a.width>t.width*2)&&a.errors.push((0,o.warning)(`LARGE_DIAGRAM`,r.lang,r.headerLine,`矩形树图较大,可滚动查看`,`Large treemap; scroll to view it`,`考虑拆分图表`,`Consider splitting the chart`)),a}}},e})({},KChartUnits[`diagram/numeric-parse`],KChartUnits[`diagram/numeric-model`],KChartUnits[`chart/composition`],KChartUnits[`chart/registry`],KChartUnits[`chart/spec`],KChartUnits[`diagram/support`]);
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 r=24,i=3,a=6,o=2,s=8,c=5,l=e=>{let t=String(e).trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1).replace(/\\([\\"'])/g,`$1`):t},u=e=>/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(String(e).trim())?Number(e):null,d=(e,n,r,i,a=`修正 Mermaid radar 语法`,o=`Correct the Mermaid radar syntax`)=>(0,t.error)(e.lang,n,r,i,a,o),f=(e,n,r,i,a,o)=>(0,t.warning)(`DIAGRAM_HINT`,e.lang,n,r,i,a,o);function p(e,t){let n=[],r=null,i=0,a=0;return String(e).split(`
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 m(e){let t=[],n=``,r=``,i=0;for(let a of e)r?(n+=a,a===r&&(r=``)):a===`"`||a===`'`?(r=a,n+=a):((a===`[`||a===`{`)&&(i+=1),(a===`]`||a===`}`)&&--i,a===`,`&&i===0?(t.push(n.trim()),n=``):n+=a);return t.push(n.trim()),t}var h=`(?:\\[\\s*(?:"((?:[^"\\\\]|\\\\.)*)"|'((?:[^'\\\\]|\\\\.)*)'|([^\\]]*))\\s*\\])?`,g=`[\\p{L}\\p{N}_][\\p{L}\\p{N}_.-]*`,_=RegExp(`^(${g})\\s*${h}$`,`u`),v=RegExp(`^(${g})\\s*${h}\\s*\\{([\\s\\S]*)\\}$`,`u`),y=RegExp(`^(${g})\\s*:?\\s*([-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+))$`,`u`),b=(e,t)=>{let n=[e[2],e[3],e[4]].find(e=>e!==void 0);return(n===void 0?t:l(n))||t};function x(e){let t=String(e.params||``).replace(/\s*:\s*$/,``).trim();return t?d(e,e.headerLine||e.firstLine,`radar-beta 不支持头行选项「${t}」`,`radar-beta does not accept header options: ${t}`,`把选项写成独立语句(max、min、ticks、showLegend、graticule)`,`Write options as their own statements`):null}function S(e,t,r,i,a){for(let o of m(t.replace(/^axis\s+/i,``))){let t=_.exec(o);if(!t){a.push(d(e,r,`无法识别 radar 维度「${o}」`,`Unrecognized radar axis "${o}"`,'使用 `axis 名称` 或 `axis 名称["显示名"]`','Use `axis name` or `axis name["Label"]`'));continue}let s=t[1];i.some(e=>e.id===s)?a.push(d(e,r,`radar 维度「${s}」重复`,`Duplicate radar axis "${s}"`,`每个维度只声明一次`,`Declare each axis once`)):i.push({id:s,label:(0,n.numericLabel)(b(t,s),e,r,a),line:r})}}function C(e,t,r,i,a){for(let o of m(t.replace(/^curve\s+/i,``))){let t=v.exec(o);if(!t){a.push(d(e,r,`无法识别 radar 曲线「${o}」`,`Unrecognized radar curve "${o}"`,'使用 `curve 名称["显示名"]{值, 值}` 或 `curve 名称{维度: 值}`','Use `curve name["Label"]{value, value}` or `curve name{axis: value}`'));continue}let s=t[1],c=[],l=t[5].split(/[,\n]/).map(e=>e.trim()).filter(Boolean),f=!1;for(let t of l){let n=u(t);if(n!==null){c.push({axis:null,value:n});continue}let i=y.exec(t);i?c.push({axis:i[1],value:Number(i[2])}):(a.push(d(e,r,`radar 曲线「${s}」的值「${t}」无效`,`Invalid value "${t}" in radar curve "${s}"`,"曲线值必须是数值,或 `维度名: 数值`","Curve values must be numbers or `axis: number` pairs")),f=!0)}f||i.push({id:s,label:(0,n.numericLabel)(b(t,s),e,r,a),entries:c,line:r})}}function w(e,t,n,r){return t.flatMap(t=>{let i=t.entries.filter(e=>e.axis!==null);if(!i.length)return[{...t,values:t.entries.map(e=>e.value)}];if(i.length!==t.entries.length)return r.push(d(e,t.line,`radar 曲线「${t.label}」不能混用按位和按维度取值`,`Radar curve "${t.label}" mixes positional and named values`,`整条曲线统一使用一种写法`,`Use one value form for the whole curve`)),[];let a=i.filter(e=>!n.some(t=>t.id===e.axis));if(a.length)return r.push(d(e,t.line,`radar 曲线「${t.label}」引用了未声明的维度「${a[0].axis}」`,`Radar curve "${t.label}" references undeclared axis "${a[0].axis}"`,`先声明该维度,或删去这一项`,`Declare the axis first, or remove that entry`)),[];let o=n.filter(e=>!i.some(t=>t.axis===e.id));return o.length?(r.push(d(e,t.line,`radar 曲线「${t.label}」缺少维度「${o.map(e=>e.id).join(`、`)}」的值`,`Radar curve "${t.label}" is missing values for ${o.map(e=>e.id).join(`, `)}`,"为每个维度各写一个 `维度名: 数值`","Give one `axis: number` entry per axis")),[]):[{...t,values:n.map(e=>i.find(t=>t.axis===e.id).value)}]})}function T(e,t,n,r,i){for(let a of m(t)){let t=/^(showLegend|ticks|max|min|graticule)\s+(\S+)$/i.exec(a);if(!t){i.push(d(e,n,`无法识别 radar 语句「${a}」`,`Unrecognized radar statement "${a}"`,`支持 axis、curve、max、min、ticks、showLegend、graticule`,`Supported: axis, curve, max, min, ticks, showLegend, graticule`));continue}let o=t[1].toLowerCase(),s=t[2];if(o===`showlegend`){if(!/^(true|false)$/i.test(s)){i.push(d(e,n,`showLegend 只接受 true 或 false`,`showLegend accepts only true or false`));continue}r.showLegend=s.toLowerCase()===`true`,r.line??=n;continue}if(o===`graticule`){if(!/^(circle|polygon)$/i.test(s)){i.push(d(e,n,`graticule 只接受 circle 或 polygon`,`graticule accepts only circle or polygon`));continue}r.graticule=s.toLowerCase(),r.line??=n;continue}let c=u(s);c===null?i.push(d(e,n,`radar ${o} 值「${s}」无效`,`Invalid radar ${o} value "${s}"`)):(r[o]=c,r.line??=n)}}var E=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))return;let n=Object.keys(e).find(e=>e.toLowerCase()===t.toLowerCase());return n===void 0?void 0:e[n]},D=(e,t)=>{let n=E(e,t);return typeof n==`boolean`?n:void 0},O=(e,t)=>{let n=E(e,t),r=typeof n==`number`?n:u(n??``);return r!==null&&Number.isFinite(r)?r:void 0};function k(e,t){let u=[],m=[],h=[],g={},_=x(t);_&&u.push(_);let v=null,y=null,b=null;for(let r of p(e,t.firstLine))if(/^title\s+/i.test(r.text)){if(v!==null){u.push(d(t,r.line,`radar 只能有一个 title`));continue}v=(0,n.numericLabel)(l(r.text.replace(/^title\s+/i,``)),t,r.line,u),y=r.line}else/^axis\s+/i.test(r.text)?(b??=r.line,S(t,r.text,r.line,m,u)):/^curve\s+/i.test(r.text)?C(t,r.text,r.line,h,u):T(t,r.text,r.line,g,u);let k=E(t.config,`radar`),A=O(k,`ticks`)??g.ticks??c,j=O(k,`min`)??g.min??0,M=O(k,`max`)??g.max??null,N=D(k,`showLegend`)??g.showLegend??!0,P=String(E(k,`graticule`)??g.graticule??`circle`).toLowerCase();(m.length<i||m.length>a)&&u.push(d(t,b||t.firstLine,`radar 需要 ${i}–${a} 个维度,当前 ${m.length} 个`,`Radar needs ${i}–${a} axes, got ${m.length}`,`维度必须在 ${i}–${a} 个之间;合并维度或拆分图表`,`Keep axes between ${i} and ${a}; merge dimensions or split the chart`)),!h.length&&!u.length&&u.push(d(t,t.firstLine,`radar 至少需要一条 curve`,`Radar needs at least one curve`)),M!==null&&M<=j&&u.push(d(t,g.line||t.firstLine,`radar max 必须大于 min`,`Radar max must be greater than min`));let F=w(t,h,m,u),I=F.filter(e=>e.values.length===m.length||(u.push(f(t,e.line,`radar 曲线「${e.label}」有 ${e.values.length} 个值、${m.length} 个维度,已跳过`,`Radar curve "${e.label}" has ${e.values.length} values for ${m.length} axes and was skipped`,`为每个维度写一个值`,`Give one value per axis`)),!1));F.length>r&&u.push(d(t,F[r].line,`radar 安全上限为 ${r} 条曲线,当前 ${F.length} 条`,`radar safety cap is ${r} curves; got ${F.length}`,`将曲线合并到 ${r} 条以内,或拆成多张图`,`Merge curves to stay within ${r}, or split the chart`));let L=I.flatMap(e=>e.values).filter(Number.isFinite),R=L.length?Math.max(...L):0,z=L.length?Math.min(...L):0,B=M??Math.max(R,j+1),V=j;B>V||(B=V+1),R>B&&(u.push(f(t,g.line||t.firstLine,`radar max ${B} 小于数据最大值 ${R},已扩展到 ${R}`,`Radar max ${B} is below the data maximum ${R}; extended to ${R}`,`把 max 改为不小于 ${R}`,`Set max to at least ${R}`)),B=R),z<V&&(u.push(f(t,g.line||t.firstLine,`radar min ${V} 大于数据最小值 ${z},已扩展到 ${z}`,`Radar min ${V} is above the data minimum ${z}; extended to ${z}`,`把 min 改为不大于 ${z}`,`Set min to no more than ${z}`)),V=z);let H=Math.max(o,Math.min(s,Math.round(A)));H!==A&&u.push(f(t,g.line||t.firstLine,`radar ticks ${A} 超出 ${o}–${s} 环的可读范围,按 ${H} 环绘制`,`Radar ticks ${A} is outside the readable ${o}–${s} rings; drawing ${H}`,`把 ticks 设为 ${o}–${s} 之间的整数`,`Set ticks to an integer within ${o}–${s}`));let U=m.map((e,t)=>({name:`d${t}`,label:e.label})),W=I.map(e=>Object.fromEntries([[`label`,e.label],...U.map((t,n)=>[t.name,e.values[n]])]));return{model:{chart:`radar`,title:v,titleLine:y,axisLine:b,axes:m,fields:U,rows:W,domain:[V,B],rings:H,graticule:P,showLegend:N,curveLines:I.map(e=>e.line),optionsLine:g.line||b||t.firstLine},errors:u}}function A(e){return{chart:`radar`,...e.title?{title:e.title}:{},data:e.rows,encode:{label:`label`,dimensions:e.fields.map(e=>e.name)},fields:Object.fromEntries(e.fields.map(t=>[t.name,{label:t.label,domain:e.domain}])),rings:e.rings,graticule:e.graticule,legend:e.showLegend}}function j(e,t){let n=String(t?.path||``).split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),r=Number(n[1]);return n[0]===`title`?e.titleLine:n[0]===`data`&&Number.isInteger(r)&&e.curveLines[r]?e.curveLines[r]:n[0]===`fields`||n[0]===`encode`?e.axisLine:[`rings`,`graticule`,`legend`].includes(n[0])?e.optionsLine:e.axisLine||e.curveLines[0]||e.optionsLine}var M=(e,t)=>(0,n.validateWith)(A(e),t,t=>j(e,t)),N=(e,r,i)=>{let a=(0,n.renderWith)(A(e),r,i,t=>j(e,t));return a.scene&&(e.rows.length>12||a.width>r.width*2)&&a.errors.push((0,t.warning)(`LARGE_DIAGRAM`,i.lang,e.curveLines[0]||e.optionsLine,`radar 有 ${e.rows.length} 条曲线,图表较大,可滚动查看`,`The radar chart has ${e.rows.length} curves and is large; scroll to view`,`按主题拆分为多张雷达图`,`Split the curves into smaller radar charts by topic`)),a},P=Object.freeze([`radar.ticks`,`radar.min`,`radar.max`,`radar.showLegend`,`radar.graticule`]),F={"radar-beta":{parse:k,validate:M,layout:N,optionMode:`raw`,honoredConfig:P}};return e.honoredConfig=P,e.implementations=F,e})({},KChartUnits[`diagram/support`],KChartUnits[`diagram/numeric-model`]);
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){let n=g(t?.lang),a=[e.xLabel,e.yLabel].filter(Boolean).join(` · `)||void 0,o=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]:!0,...e.title?{title:e.title}:{},...a?{subtitle:a}:{},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||(n?`Series ${t+1}`:`系列 ${t+1}`),...o}]))}}let s=e.datasets[0],c=s.pointLabels.some(Boolean),l=e.categories.map((e,t)=>({category:e,value:s.values[t],...c?{id:String(t)}:{}}));return{chart:e.chart,...e.chart===`line`?{[r.diagramLine]:!0}:{},...e.title?{title:e.title}:{},...a?{subtitle:a}:{},data:l,encode:{category:`category`,value:`value`,...c?{id:`id`}:{}},fields:{value:{...o,...s.name?{label:s.name}:{}}},...c?{annotations:s.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=>(0,n.renderWith)(k(e,i),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},a={}){let{title:o,fields:s,config:c}=e,l=(0,r.appearance)(n),u=Number.isInteger(c.bitsPerRow)&&c.bitsPerRow>=1&&c.bitsPerRow<=128?c.bitsPerRow:32,d=c.showBits!==!1,f=c.bitOrder===`descending`,p=[];s.forEach((e,t)=>{for(let n=e.start;n<=e.end;){let r=Math.floor(n/u),i=Math.min(e.end,(r+1)*u-1);(p[r]??=[]).push({...e,start:n,end:i,id:t,bits:i-n+1}),n=i+1}});let m=(e,t,n,r)=>Number.isFinite(c[e])?Math.min(r,Math.max(n,c[e])):t,h=m(`paddingX`,0,0,24),g=m(`paddingY`,12,6,60),_=m(`rowHeight`,34,26,240),v=e=>e.start===e.end?String(e.start):`${e.start}–${e.end}`,y=Math.ceil(p.flat().reduce((e,t)=>Math.max(e,...t.label.split(/\s+/).map(e=>(n.measure(e,r.FONT.body.size)+10+h)/t.bits),d?(n.measure(v(t),r.FONT.label.size)+6)/t.bits:0),12)),b=Math.max(y,Math.floor((t-36)/u),m(`bitWidth`,12,12,96)),x=Math.max(t,u*b+36),S=(x-u*b)/2,C=[],w=18;o&&!i?.frame&&(C.push(n.text(x/2,w+8,o,{...r.FONT.title,anchor:`middle`,fill:l.fg1,"dominant-baseline":`central`})),w+=30);for(let e of p){let t=e.map(e=>({...e,lines:n.wrap(e.label,e.bits*b-h-8,r.FONT.body.size)})),i=Math.max(_,...t.map(e=>e.lines.length*17+14));for(let e of t){let t=S+(f?u-e.start%u-e.bits:e.start%u)*b,a=e.bits*b-h,o=t+a/2,s=l[e.status]||l.line,c=[n.rect(t,w,a,i,{fill:e.status?n.tint(l.bg,s,.1):e.id%2?l.surface:l.bg,stroke:s,meta:{kind:`node`,id:`${e.id}:${e.start}`}}),(0,r.textBlock)(n,{x:o,y:w+i/2,lines:e.lines,lineHeight:17})];C.push(...e.link?[n.link(e.link.href,c,e.link)]:c),d&&C.push(n.text(o,w+i+12,v(e),{...r.FONT.label,anchor:`middle`,"dominant-baseline":`central`}))}w+=i+g+(d?16:0)}let T=w+6,E=x>t*2||s.length>60?[(0,r.warning)(`LARGE_DIAGRAM`,n.lang,a.headerLine||1,`封包图较大`,`Large packet diagram`,`考虑拆分图表`,`Consider splitting the diagram`)]:[];return{width:x,height:T,scene:{width:x,height:T,children:C,title:o,heading:o},errors:E}}return e.implementations={packet:{parse:a,layout:o,honoredConfig:i,acceptsPresentation:!0}},e})({},KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
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},a={}){let{title:o,captions:s,axes:c,points:l,config:u}=e,d=(0,r.appearance)(t),f=(e,t,n,r)=>Number.isFinite(u[e])?Math.min(r,Math.max(n,u[e])):t,p=f(`pointLabelFontSize`,12,12,24),m=f(`pointRadius`,5,3,12),h=o&&!i?.frame,g=u.xAxisPosition?u.xAxisPosition===`top`:!l.length,_=u.yAxisPosition===`right`,v={anchor:`middle`,"dominant-baseline":`central`},y=(e,n=r.FONT.label)=>t.measure(e||``,n.size,n.weight),b=e=>(e||[]).reduce((e,t)=>e+y(t),36),x=18+f(`quadrantPadding`,5,0,48),S=Math.max(5,...l.map(e=>(e.style.radius??m)+(e.style[`stroke-width`]??1)/2)),C=S+6+f(`xAxisLabelPadding`,5,5,48),w=S+6+f(`yAxisLabelPadding`,5,5,48),T=C+10,E=w+10,D=x+(h?32:0)+(g&&c.x?T:0),O=x+(!_&&c.y?E:0),k=x+(_&&c.y?E:0),A=Math.max(Math.min(520,n-O-k),360,f(`chartWidth`,0,0,4e3),b(c.x),...s.map(e=>2*y(e,r.FONT.title)+44).filter(Number.isFinite)),j=Math.max(340,b(c.y),f(`chartHeight`,0,0,4e3)),M=O+A+k,N=D+j,P=[],F=[],I=(e,n,i,a=r.FONT.label,o=d.fg1,s={})=>{i&&P.push(t.text(e,n,i,{...a,...v,fill:o,...s}))};h&&I(M/2,26,o,r.FONT.title),P.push(t.rect(O,D,A,j,{stroke:d.line,fill:d.bg,meta:{kind:`frame`,id:`quadrants`}}));for(let e=0;e<4;e++){let n=e===0||e===3?A/2:0,r=e>=2?j/2:0,i=O+n,a=D+r;P.push(t.rect(i,a,A/2,j/2,{fill:t.tint(d.bg,t.color(`tone${e+1}`),.08),stroke:d.line}))}let L=l.map(e=>({...e,cx:O+e.x*A,cy:N-e.y*j,r:e.style.radius??m})),R=(e,t,n,r)=>({x0:e-n,x1:e+n,y0:t-r,y1:t+r}),z=e=>F.every(t=>t.x1+3<=e.x0||t.x0-3>=e.x1||t.y1+3<=e.y0||t.y0-3>=e.y1);if(L.forEach(e=>F.push(R(e.cx,e.cy,e.r+2,e.r+2))),s.forEach((e,t)=>{let n=O+(t===0||t===3?.75:.25)*A,i=D+(t>=2?j/2:0),a=y(e,r.FONT.title)/2,o=i+(L.length?15+f(`quadrantTextTopPadding`,5,3,50):j/4);for(;!z(R(n,o,a,7));)o+=18;I(n,o,e,r.FONT.title,d.fg2),F.push(R(n,o,a,7))}),c.x){let e=g?D-C:N+C;I(O,e,c.x[0],r.FONT.label,d.fg2,{anchor:`start`}),I(O+A,e,c.x[1],r.FONT.label,d.fg2,{anchor:`end`})}if(c.y){let e=_?O+A+w:O-w;[[c.y[0],N,`start`],[c.y[1],D,`end`]].forEach(([t,n,i])=>{I(e,n,t,r.FONT.label,d.fg2,{anchor:i,transform:`rotate(-90 ${e} ${n})`})})}let B=[];L.forEach((e,n)=>{let i=t.circle(e.cx,e.cy,e.r,{fill:d[e.style.color]||d.accent,stroke:d[e.style[`stroke-color`]]||d.bg,"stroke-width":e.style[`stroke-width`]??1,meta:{kind:`node`,id:n}});P.push(e.link?t.link(e.link.href,[i],e.link):i);let a={...r.FONT.label,size:p},o=y(e.text,a)/2,s=Math.min(O+A-o,Math.max(O+o,e.cx)),c=e.r+p/2+f(`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>=O&&e+o<=O+A&&t-p/2>=D&&t+p/2<=N&&z(R(e,t,o,p/2)));l?(I(...l,e.text,a,d.fg1,{meta:{kind:`edge-label`}}),F.push(R(...l,o,p/2))):B.push({text:`${e.text} (${e.x}, ${e.y})`,x:e.cx})});let V=t.labelLanes(t,B,{left:O,right:O+A,maxWidth:180}),H=N+(!g&&c.x?T:0)+x;for(let e of V.items)P.push(t.textLines(e.cx,H+10+e.offset,e.lines,{...r.FONT.label,...v,fill:d.fg1}));let U=H+V.height,W=M>n*2||l.length>60?[(0,r.warning)(`LARGE_DIAGRAM`,t.lang,a.headerLine||1,`象限图较大`,`Large quadrant chart`,`考虑拆分图表`,`Consider splitting the diagram`)]:[];return{width:M,height:U,scene:{width:M,height:U,children:P,title:o,heading:o},errors:W}}return e.implementations={quadrantChart:{parse:a,layout:o,honoredConfig:i,acceptsPresentation:!0}},e})({},KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
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`){let n=b(e);if(n)return n;[`"`,`'`].includes(v().kind)&&!(c&&v().kind===`'`)&&y(`unterminated-string`,`字符串未闭合`,`Unterminated string`,`添加对应的结束引号`,`Add the matching closing quote`),y(t,`应为「${e}」`,`Expected ${e}`,`在此处使用「${e}」`,`Use ${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`,`使用 /、双引号和前置重复次数`,`Use /, double quotes and a repeat prefix`),f&&[`[`,`{`,`-`,`|`].includes(t)&&e.fail(`peg-unsupported`,`此写法不属于 PEG`,`This syntax is not PEG`,`使用 /、圆括号和后置 ?、*、+`,`Use /, parentheses and postfix ?, *, +`)}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`,`使用递增的整数范围`,`Use an ascending integer range`,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`,`添加构造器参数`,`Add a constructor argument`);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 large`,`拆分语法图`,`Split the grammar into diagrams`);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`):n===`ebnf`&&C.take(`::=`)||C.expect(`=`);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`,`拆分语法图`,`Split the grammar into diagrams`,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`]);
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 grammar; scroll inside the frame`,`考虑拆分规则`,`Consider splitting the 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`]);
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`]);
@@ -1,2 +1,2 @@
1
- KChartUnits["diagram/registry"]=(function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=new Set([`securitylevel`,`startonload`,`loglevel`,`deterministicids`,`deterministicidseed`,`maxtextsize`,`maxedges`,`suppresserrorrendering`,`htmllabels`,`markdownautowrap`,`arrowmarkerabsolute`,`secure`,`dompurifyconfig`,`fontfamily`,`fontsize`]),c=new Map([[`look`,`classic`],[`layout`,`dagre`],[`theme`,`default`]]);function l(e,n){let r=(n?.honoredConfig??[]).map(e=>e.toLowerCase()),i=[];function a(t,n=``){for(let[o,l]of Object.entries(t)){let t=n+o,u=t.toLowerCase();s.has(u)||r.some(e=>u===e||u.startsWith(`${e}.`))||(l&&typeof l==`object`&&!Array.isArray(l)?a(l,`${t}.`):(typeof l!=`string`||c.get(u)!==l.toLowerCase())&&i.push([t,e.configLines[u]??1]))}}a(e.config);let o=e.errors.find(e=>e.code===`IGNORED_CONFIG`);if(!i.length)return o;i.sort((e,t)=>e[1]-t[1]);let l=i.map(([e])=>e).join(`, `);return o?{...o,line:Math.min(o.line,i[0][1]),message:`${o.message}, ${l}`}:(0,t.ignoredConfigWarning)(e.lang,i[0][1],l)}function u(e){if(e.syntax!==`mermaid`)return[];let t=[];for(let[r,i]of e.body.split(`
2
- `).entries()){let a=i.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g,``),o=/^\s*(classDef|style|linkStyle|click|href|callback)\s/i.exec(a)||/::icon\s*\(/i.exec(a),s=e.firstLine+r;if(o){let r=o[1]||`::icon`;t.push((0,n.error)(e.lang,s,`不支持 Mermaid 写法「${r}」`,`Unsupported Mermaid syntax "${r}"`,`移除样式、链接或回调写法;颜色由主题决定`,`Remove styles, links, or callbacks; colors are controlled by the theme`,i.toLowerCase().indexOf(r.toLowerCase())+1))}else!e.kind.toLowerCase().startsWith(`classdiagram`)&&/^\s*class\s+\S+\s+\S+/i.test(a)&&t.push((0,n.error)(e.lang,s,`不支持 Mermaid 样式类声明`,`Mermaid style-class declarations are not supported`,`使用 ::: 状态分类;不要声明通用样式类`,`Use ::: status classes; generic style classes are unsupported`,i.search(/\S/)+1))}return t}function d(e,s){if(!e||typeof e!=`object`||!Array.isArray(s))throw TypeError(`Invalid diagram registry configuration`);let c=new Map,d=new Map;for(let e of s){if(!e||typeof e.kind!=`string`||!e.kind||typeof e.syntax!=`string`||!e.syntax||!Array.isArray(e.aliases)||typeof e.topic!=`string`)throw TypeError(`Invalid diagram type descriptor`);let t=e.kind.toLowerCase();if(c.has(t))throw TypeError(`Duplicate diagram type: ${e.kind}`);c.set(t,e);for(let t of[e.kind,...e.aliases]){if(typeof t!=`string`||!t.trim())throw TypeError(`Invalid diagram alias: ${t}`);let n=t.toLowerCase();if(d.has(n))throw TypeError(`Duplicate diagram alias: ${t}`);d.set(n,e)}}let f=(e,t,n=`BAD_DIAGRAM`)=>({code:e.code||n,line:e.line??1,column:e.column??1,message:e.message||`无效的结构图`,fix:e.fix||`修正结构图声明后重试`,topic:e.topic||t?.topic||`diagram`,severity:e.severity===`warning`?`warning`:`error`}),p=(e,t)=>(e||[]).map(e=>f(e,t)),m=(...e)=>{let t=new Set;return e.flat().filter(e=>{let n=JSON.stringify([e.code,e.line,e.column,e.message,e.fix,e.topic,e.severity]);return!t.has(n)&&(t.add(n),!0)})},h=e=>e.headerLine||e.firstLine||1;function g(r,i={}){i={...i,lang:i.lang||(0,t.inferLang)(r)};let a=i.syntax||`mermaid`;if(/^mermaid$/i.test(a)&&String(r??``).length>5e4)return{info:null,type:null,model:null,diagnostics:p([(0,n.error)(i.lang,1,`Mermaid 源码最多 50000 个字符`,`Mermaid source is limited to 50,000 characters`,`请拆分图表`,`Split the diagram`)],null)};let o=(0,t.prepareSource)(r,{syntax:a,lang:i.lang,keepsTrailingComments:t=>e[d.get(t.toLowerCase())?.kind]?.trailingComments===!1,site:i[t.siteConfig]}),s=String(o.kind||``).toLowerCase(),g=d.get(s)||c.get(s),_=g&&e[g.kind],v=_?.optionMode===`raw`?{options:o.options||Object.create(null),errors:[]}:(0,t.parseOptions)(o.params,{lang:i.lang,line:o.headerLine||o.firstLine}),y={...o,...v.options?{options:v.options}:{},kind:g?.kind||o.kind,syntax:a,lang:i.lang},b=l(y,_),x=o.errors.filter(e=>e.code!==`IGNORED_CONFIG`),S=_&&_.acceptsPresentation!==!0?u(y):[],C=p(m(x,b?[b]:[],S,v.errors||[]),g);if(!g){if(C.some(n.blocking))return{info:y,type:null,model:null,diagnostics:C};let e=o.kind||o.body.trim().split(/\s+/)[0].slice(0,40)||a,t=(0,n.error)(i.lang,h(o),`未知结构图类型「${e}」`,`Unknown diagram type "${e}"`,`使用已声明的结构图类型`,`Use a supported diagram type`);return{info:y,type:null,model:null,diagnostics:[...C,f(t)]}}if(String(g.syntax).toLowerCase()!==String(a).toLowerCase()){let e=f((0,n.error)(i.lang,h(o),`图类型「${o.kind}」不支持语法「${a}」`,`Diagram type "${o.kind}" does not use ${a} syntax`,`使用 ${g.syntax} 语法`,`Use ${g.syntax} syntax`),g);return{info:y,type:g,model:null,diagnostics:m(C,[e])}}if(C.some(n.blocking))return{info:y,type:g,model:null,diagnostics:C};if(!_){let e=(0,n.error)(i.lang,h(o),`已知图类型「${g.kind}」尚未装入`,`Diagram type "${g.kind}" is not loaded`,`重新组装并装入该图类型`,`Load this diagram type before rendering`);return{info:y,type:g,model:null,diagnostics:[...C,f(e,g)]}}if(typeof _.parse!=`function`)throw TypeError(`Missing parser for diagram: ${g.kind}`);let w=_.parse(o.body,y);if(!w||!Array.isArray(w.errors))throw TypeError(`Invalid parser result for diagram: ${g.kind}`);let T=!w.errors.some(n.blocking)&&typeof _.validate==`function`&&_.validate(w.model,y)||[];if(!Array.isArray(T))throw TypeError(`Invalid validation result for diagram: ${g.kind}`);return{info:y,type:g,model:w.model,diagnostics:m(C,p(w.errors,g),p(T,g))}}function _(e,t={}){try{return g(e,t)}catch(e){if(!(e instanceof o.ExpectedDiagnostic))throw e;return{info:null,type:null,model:null,diagnostics:p(e.errors,null)}}}function v(e,t={}){return _(e,t).diagnostics}function y(t,s={}){let c=_(t,s);if(c.diagnostics.some(n.blocking))return{svg:null,scene:null,diagnostics:c.diagnostics};try{let t=e[c.type.kind];if(typeof t.layout!=`function`)throw TypeError(`Missing layout for diagram: ${c.type.kind}`);let o=Math.max(1,Number(s.width)||800),l=(0,r.createContext)({...s,width:o,lang:c.info.lang}),u=(0,n.measureOf)(l),d={...s,frame:s.frame??!0},f=t.layout(c.model,{width:o,lang:l.lang,measure:u,ctx:l,renderOptions:d},c.info),h=m(c.diagnostics,p(f?.errors,c.type));if(h.some(n.blocking))return{svg:null,scene:null,diagnostics:h};let g=f?.scene||(typeof t.scene==`function`?t.scene(f,l,c.info):null);if(!g||!Number.isFinite(g.width)||!Number.isFinite(g.height)||!Array.isArray(g.children))throw TypeError(`Invalid scene for diagram: ${c.type.kind}`);let _=(0,i.containText)(g,l.measure,{blockPadding:4}),v=Math.max(o,_.width),y=Math.max(0,(v-_.width)/2),b=y?[(0,i.el)(`g`,{transform:`translate(${y} 0)`},_.children)]:_.children,x=_.anchor?{..._.anchor,x:_.anchor.x+y}:_.anchor,S=c.info.accTitle||c.info.title||_.title||c.type.kind,C={..._,width:v,children:b,...x?{anchor:x}:{},title:S,...c.info.accDescr===void 0?{}:{description:c.info.accDescr},heading:c.info.title||_.heading};return{svg:(0,a.renderScene)(C,d),scene:C,diagnostics:h}}catch(e){if(!(e instanceof o.ExpectedDiagnostic))throw e;return{svg:null,scene:null,diagnostics:m(c.diagnostics,p(e.errors,c.type))}}}return Object.freeze({parse:_,check:v,diagram:y})}return e.createDiagramApi=d,e})({},KChartUnits[`diagram/source`],KChartUnits[`diagram/support`],KChartUnits[`core/context`],KChartUnits[`core/scene`],KChartUnits[`core/svg`],KChartUnits[`core/diagnostics`]);
1
+ KChartUnits["diagram/registry"]=(function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=new Set([`securitylevel`,`startonload`,`loglevel`,`deterministicids`,`deterministicidseed`,`maxtextsize`,`maxedges`,`suppresserrorrendering`,`htmllabels`,`markdownautowrap`,`arrowmarkerabsolute`,`secure`,`dompurifyconfig`,`fontfamily`,`fontsize`]),l=new Map([[`look`,`classic`],[`layout`,`dagre`],[`theme`,`default`]]);function u(e,n){let r=(n?.honoredConfig??[]).map(e=>e.toLowerCase()),i=[];function a(t,n=``){for(let[o,s]of Object.entries(t)){let t=n+o,u=t.toLowerCase();c.has(u)||r.some(e=>u===e||u.startsWith(`${e}.`))||(s&&typeof s==`object`&&!Array.isArray(s)?a(s,`${t}.`):(typeof s!=`string`||l.get(u)!==s.toLowerCase())&&i.push([t,e.configLines[u]??1]))}}a(e.config);let o=e.errors.find(e=>e.code===`IGNORED_CONFIG`);if(!i.length)return o;i.sort((e,t)=>e[1]-t[1]);let s=i.map(([e])=>e).join(`, `);return o?{...o,line:Math.min(o.line,i[0][1]),message:`${o.message}, ${s}`}:(0,t.ignoredConfigWarning)(e.lang,i[0][1],s)}function d(e){if(e.syntax!==`mermaid`)return[];let t=[];for(let[r,i]of e.body.split(`
2
+ `).entries()){let a=i.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g,``),o=/^\s*(classDef|style|linkStyle|click|href|callback)\s/i.exec(a)||/::icon\s*\(/i.exec(a),s=e.firstLine+r;if(o){let r=o[1]||`::icon`;t.push((0,n.error)(e.lang,s,`不支持 Mermaid 写法「${r}」`,`Unsupported Mermaid syntax "${r}"`,`移除样式、链接或回调写法;颜色由主题决定`,`Remove styles, links, or callbacks; colors are controlled by the theme`,i.toLowerCase().indexOf(r.toLowerCase())+1))}else!e.kind.toLowerCase().startsWith(`classdiagram`)&&/^\s*class\s+\S+\s+\S+/i.test(a)&&t.push((0,n.error)(e.lang,s,`不支持 Mermaid 样式类声明`,`Mermaid style-class declarations are not supported`,`使用 ::: 状态分类;不要声明通用样式类`,`Use ::: status classes; generic style classes are unsupported`,i.search(/\S/)+1))}return t}function f(e,c){if(!e||typeof e!=`object`||!Array.isArray(c))throw TypeError(`Invalid diagram registry configuration`);let l=new Map,f=new Map;for(let e of c){if(!e||typeof e.kind!=`string`||!e.kind||typeof e.syntax!=`string`||!e.syntax||!Array.isArray(e.aliases)||typeof e.topic!=`string`)throw TypeError(`Invalid diagram type descriptor`);let t=e.kind.toLowerCase();if(l.has(t))throw TypeError(`Duplicate diagram type: ${e.kind}`);l.set(t,e);for(let t of[e.kind,...e.aliases]){if(typeof t!=`string`||!t.trim())throw TypeError(`Invalid diagram alias: ${t}`);let n=t.toLowerCase();if(f.has(n))throw TypeError(`Duplicate diagram alias: ${t}`);f.set(n,e)}}let p=(e,t,n=`BAD_DIAGRAM`)=>({code:e.code||n,line:e.line??1,column:e.column??1,message:e.message||`无效的结构图`,fix:e.fix||`修正结构图声明后重试`,topic:e.topic||t?.topic||`diagram`,severity:e.severity===`warning`?`warning`:`error`}),m=(e,t)=>(e||[]).map(e=>p(e,t)),h=(...e)=>{let t=new Set;return e.flat().filter(e=>{let n=JSON.stringify([e.code,e.line,e.column,e.message,e.fix,e.topic,e.severity]);return!t.has(n)&&(t.add(n),!0)})},g=e=>e.headerLine||e.firstLine||1;function _(r,i={}){i={...i,lang:i.lang||(0,t.inferLang)(r)};let a=i.syntax||`mermaid`;if(/^mermaid$/i.test(a)&&String(r??``).length>5e4)return{info:null,type:null,model:null,diagnostics:m([(0,n.error)(i.lang,1,`Mermaid 源码最多 50000 个字符`,`Mermaid source is limited to 50,000 characters`,`请拆分图表`,`Split the diagram`)],null)};let o=(0,t.prepareSource)(r,{syntax:a,lang:i.lang,keepsTrailingComments:t=>e[f.get(t.toLowerCase())?.kind]?.trailingComments===!1,site:i[t.siteConfig]}),s=String(o.kind||``).toLowerCase(),c=f.get(s)||l.get(s),_=c&&e[c.kind],v=_?.optionMode===`raw`?{options:o.options||Object.create(null),errors:[]}:(0,t.parseOptions)(o.params,{lang:i.lang,line:o.headerLine||o.firstLine}),y={...o,...v.options?{options:v.options}:{},kind:c?.kind||o.kind,syntax:a,lang:i.lang},b=u(y,_),x=o.errors.filter(e=>e.code!==`IGNORED_CONFIG`),S=_&&_.acceptsPresentation!==!0?d(y):[],C=m(h(x,b?[b]:[],S,v.errors||[]),c);if(!c){if(C.some(n.blocking))return{info:y,type:null,model:null,diagnostics:C};let e=o.kind||o.body.trim().split(/\s+/)[0].slice(0,40)||a,t=s.endsWith(`-beta`)?s.slice(0,-5):`${s}-beta`,r=a===`mermaid`&&s&&f.get(t),c=r?.syntax===`mermaid`&&[r.kind,...r.aliases].find(e=>e.toLowerCase()===t),l=(0,n.error)(i.lang,g(o),`未知结构图类型「${e}」`,`Unknown diagram type "${e}"`,c?`将头行关键字改为「${c}」`:`使用已声明的结构图类型`,c?`Use "${c}" as the header keyword`:`Use a supported diagram type`);return{info:y,type:null,model:null,diagnostics:[...C,p(l)]}}if(String(c.syntax).toLowerCase()!==String(a).toLowerCase()){let e=p((0,n.error)(i.lang,g(o),`图类型「${o.kind}」不支持语法「${a}」`,`Diagram type "${o.kind}" does not use ${a} syntax`,`使用 ${c.syntax} 语法`,`Use ${c.syntax} syntax`),c);return{info:y,type:c,model:null,diagnostics:h(C,[e])}}if(C.some(n.blocking))return{info:y,type:c,model:null,diagnostics:C};if(!_){let e=(0,n.error)(i.lang,g(o),`已知图类型「${c.kind}」尚未装入`,`Diagram type "${c.kind}" is not loaded`,`重新组装并装入该图类型`,`Load this diagram type before rendering`);return{info:y,type:c,model:null,diagnostics:[...C,p(e,c)]}}if(typeof _.parse!=`function`)throw TypeError(`Missing parser for diagram: ${c.kind}`);let w=_.parse(o.body,y);if(!w||!Array.isArray(w.errors))throw TypeError(`Invalid parser result for diagram: ${c.kind}`);let T=!w.errors.some(n.blocking)&&typeof _.validate==`function`&&_.validate(w.model,y)||[];if(!Array.isArray(T))throw TypeError(`Invalid validation result for diagram: ${c.kind}`);return{info:y,type:c,model:w.model,diagnostics:h(C,m(w.errors,c),m(T,c))}}function v(e,t={}){try{return _(e,t)}catch(e){if(!(e instanceof s.ExpectedDiagnostic))throw e;return{info:null,type:null,model:null,diagnostics:m(e.errors,null)}}}function y(e,t={}){return v(e,t).diagnostics}function b(t,c={}){let l=v(t,c);if(l.diagnostics.some(n.blocking))return{svg:null,scene:null,diagnostics:l.diagnostics};try{let t=e[l.type.kind];if(typeof t.layout!=`function`)throw TypeError(`Missing layout for diagram: ${l.type.kind}`);let s=Math.max(1,Number(c.width)||800),u=c.compact===!0,d=u?Math.min(s,720):s,f=(0,r.createContext)({...c,width:d,compact:u,lang:l.info.lang}),p=(0,n.measureOf)(f),g={...c,frame:c.frame??!0},_=g.frame===!1,v=u&&_,y=v?{...g,frame:!0}:g,b=t.layout(l.model,{width:d,compact:u,embedHeading:_,lang:f.lang,measure:p,ctx:f,renderOptions:y},l.info),x=h(l.diagnostics,m(b?.errors,l.type));if(x.some(n.blocking))return{svg:null,scene:null,diagnostics:x};let S=b?.scene||(typeof t.scene==`function`?t.scene(b,f,l.info):null);if(!S||!Number.isFinite(S.width)||!Number.isFinite(S.height)||!Array.isArray(S.children))throw TypeError(`Invalid scene for diagram: ${l.type.kind}`);let C=l.info.title||S.heading,w=[];if(v&&(C||S.subtitle)){let e=(e,t,n)=>(0,o.wrapText)(e,Math.max(14,d-4),f.font(t,n),(e,t)=>f.measureInk(e,t.size,t.weight),{bounded:!0}),t=C?e(C,16,650):[];t.length&&w.push(f.textLines(0,0,t,{size:16,weight:650,leading:22,fill:f.color(`fg`),meta:{kind:`diagram-title`}})),S.subtitle&&w.push(f.textLines(0,t.length*22,e(S.subtitle,12,400),{size:12,weight:400,leading:18,fill:f.color(`muted`)}))}let T=w.length?(0,i.el)(`g`,{},w):null,E=u?(0,i.cropInk)(S,v?f.measureInk:f.measureRendered,{fullText:v,heading:T}):(0,i.containText)(S,f.measure,{blockPadding:4}),D=u?E.width:Math.max(s,E.width),O=Math.max(0,(D-E.width)/2),k=O?[(0,i.el)(`g`,{transform:`translate(${O} 0)`},E.children)]:E.children,A=E.anchor?{...E.anchor,x:E.anchor.x+O}:E.anchor,j=l.info.accTitle||l.info.title||E.title||l.type.kind,M={...E,width:D,children:k,...A?{anchor:A}:{},title:j,...l.info.accDescr===void 0?{}:{description:l.info.accDescr},heading:C};return{svg:(0,a.renderScene)(M,g),scene:M,diagnostics:x}}catch(e){if(!(e instanceof s.ExpectedDiagnostic))throw e;return{svg:null,scene:null,diagnostics:h(l.diagnostics,m(e.errors,l.type))}}}return Object.freeze({parse:v,check:y,diagram:b})}return e.createDiagramApi=f,e})({},KChartUnits[`diagram/source`],KChartUnits[`diagram/support`],KChartUnits[`core/context`],KChartUnits[`core/scene`],KChartUnits[`core/svg`],KChartUnits[`core/text`],KChartUnits[`core/diagnostics`]);
@@ -1,2 +1,2 @@
1
1
  KChartUnits["diagram/sequence"]=(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=Object.freeze({participants:300,messages:500,fragmentDepth:32,lines:4}),o=new Set([`else`,`and`,`option`]),s=new Set([`actor`,`boundary`,`collections`,`control`,`database`,`entity`,`participant`,`queue`]),c=new Map;for(let[e,t,n]of[[`->>`,`arrow`],[`->`,`none`],[`-x`,`cross`],[`-)`,`open`],[`<<->>`,`arrow`,`arrow`],[`-|\\`,`top`],[`-|/`,`bottom`],[`-\\\\`,`stick-top`],[`-//`,`stick-bottom`],[`/|-`,`none`,`top`],[`\\|-`,`none`,`bottom`],[`//-`,`none`,`stick-top`],[`\\\\-`,`none`,`stick-bottom`]])for(let r of[!1,!0]){let i=r?e.replace(`-`,`--`):e,a=t===`cross`?`lost`:t===`open`?`async`:r?`return`:`sync`;c.set(i,{token:i,head:t,start:n,dashed:r,style:a})}var l=new RegExp([...c.keys()].sort((e,t)=>t.length-e.length).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`),`i`),u=e=>/^[^\s<>::,;@()+]+$/.test(e),d=(e,t,n,r,a,o)=>(0,i.error)(e,t,n,r,a,o),f=/^(?:rgba?|hsla?)\([^)]*\)/i;function p(e){let t=[],n=0;for(let r of e.matchAll(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|&?#(?:x[\da-f]+|\w+);|&\w+;|%%|#|;/gi))if(!(r[0]===`#`&&/^\s*link\s+[^\s:]+\s*:[^@]*@\s*\S*$/i.test(e.slice(n,r.index)))&&(r[0]===`;`||r[0]===`#`||r[0]===`%%`)){if(t.push(e.slice(n,r.index)),r[0]!==`;`)return t;n=r.index+1}return t.push(e.slice(n)),t}function m(e=``){let t=e.matchAll(/(?:^|,)\s*["']?(type|alias|icon)["']?\s*:\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^,]+)\s*(?=,|$)/g);return Object.fromEntries(Array.from(t,([,e,t])=>{if(t=t.trim(),t.startsWith(`"`))try{return[e,JSON.parse(t)]}catch{}return[e,t.replace(/^(["'])(.*)\1$/,`$2`)]}))}function h(e,h){let{lang:g,options:_={},firstLine:v}=h,y=(0,r.presentation)({lang:g}),b=new Map,x=new Map,S=[];for(let e of Object.keys(_))S.push(d(g,v-1,`sequenceDiagram 不支持选项「${e}」`,`Unsupported sequenceDiagram option: ${e}`,`删掉第一行的选项`,`Remove the option from the first line`));let C=[],w=new Map,T=[],E=[],D=0,O,k,A,j=new Set,M=(e,t,...n)=>{j.has(e)||(j.add(e),S.push((0,i.warning)(e,g,t,...n)))},N=e=>{let t=`${e.code}:${e.message}`;j.has(t)||(j.add(t),S.push(e))},P=(e,t)=>{let{text:r,icon:i,diagnostics:a}=(0,n.normalizeLabel)(e.replace(/^(?:no)?wrap\s*:\s*/i,``),{lang:g,line:t});return a.forEach(N),{text:r,icon:i}},F=(e,t)=>{let[n,...r]=e.split(`:::`);return r.length&&y.addClasses(n,r,t),n},I=({id:e,line:t},n,r)=>S.push(d(g,t,`${e}:${n}`,`${e}: ${r}`,`修正下一条消息的参与者`,`Correct the participants in the next message`));function L(e,t,n=e){if(w.has(e))return w.get(e);if(C.length>=a.participants)return S.push(d(g,t,`参与者超过 ${a.participants} 个`,`More than ${a.participants} participants`,`删到 ${a.participants} 个参与者,或拆成两张图`,`Keep at most ${a.participants} participants, or split the diagram`)),null;let r={id:e,name:n,kind:`participant`,line:t,index:C.length};return C.push(r),w.set(e,r),r}function R(e){let t=E.at(-1);t?(E.pop(),T.push({type:`end`,line:e,target:t})):S.push(d(g,e,`end 没有对应的开始语句`,`end has no matching start`,`删掉这个 end,或在它前面补上片段、rect 或 box`,`Remove this end, or add the fragment, rect, or box it closes`))}let z=String(e).split(`
2
- `);function B(e,n){if(!e.trim()||e.trimStart().startsWith(`%%`))return;if(/^\s*\t|^\s+\t/.test(e)||e.includes(` `)){S.push(d(g,n,`时序图语句不能使用 Tab`,`Tabs are not allowed in sequence statements`,`把 Tab 换成空格`,`Replace tabs with spaces`));return}let p=e.trim(),h=/^title(?:\s*:\s*|\s+)(.+)$/i.exec(p);if(h){O=P(h[1],n).text;return}let _=/^(link|links|properties|details)\s+([^\s:]+)\s*:\s*(.*)$/i.exec(p);if(_){let[,e,t,i]=_;if(M(`IGNORED_INTERACTION`,n,`已省略参与者菜单和详情界面;仅保留首个安全链接`,`Participant menus and details are omitted; only the first safe URL is kept`,`把其他必要链接放在图外`,`Put other essential links outside the diagram`),!b.has(t)){let n=[];if(e.toLowerCase()===`link`){let e=/^(.*?)@\s*(.+)$/.exec(i);e&&(n=[[e[1].trim(),e[2]]])}else if(e.toLowerCase()===`links`)try{let e=JSON.parse(i);e&&typeof e==`object`&&!Array.isArray(e)&&(n=Object.entries(e))}catch{}for(let[e,i]of n){let n=typeof i==`string`&&(0,r.safeHref)(i.trim());if(n){b.set(t,{href:n,tooltip:e});break}}}return}if(y.accept(p,n))return;let v=/^(?:(create)\s+)?(participant|actor)\s+([^\s@]+)(?:\s*@\{([^}]*)\})?(?:\s+as\s+(.+))?$/i.exec(p);if(v){let[,e,r,a,o,c]=v,[,l,f]=/^(.*?)::icon\(([^)]+)\)$/.exec(a)??[],p=F(l??a,n),h=m(o);if(!u(p)){S.push(d(g,n,`参与者 ID 无效`,`Invalid participant id`,`写成 participant ID as 名称`,`Write participant ID as Name`));return}if(e&&(w.has(p)||k)){I({id:p,line:n},`重复创建或已有待创建的参与者`,`Duplicate or already pending creation`);return}let _=L(p,n);if(!_)return;let y=h.type||r.toLowerCase();s.has(y)||M(`DIAGRAM_HINT`,n,`未知参与者类型,使用普通方框`,`Unknown participant type; using a standard participant`,`检查 type`,`Check the type value`);let{text:b,icon:x}=P(c||h.alias||p,n),C=f||h.icon,D=C?(0,t.resolveIconRef)(C):null;C&&!D&&N((0,i.warning)(`IGNORED_ASSET`,g,n,`未知图标 ${C}`,`Unknown icon ${C}`,`使用内置图标`,`Use a supported icon`)),Object.assign(_,{name:b,icon:D||x,kind:s.has(y)?y:`participant`,declared:!0,line:n}),e&&(k={id:p,line:n}),E.at(-1)?.type===`box`&&E.at(-1).members.push(p),T.push({type:`participant`,id:p,line:n});return}let C=/^destroy\s+(\S+)$/i.exec(p);if(C){let e=C[1];!w.has(e)||A?I({id:e,line:n},`未知参与者或已有待销毁的参与者`,`Unknown participant or already pending destruction`):A={id:e,line:n};return}let j=/^autonumber(?:\s+(off|[+-]?\d+(?:\.\d+)?)(?:\s+([+-]?\d+(?:\.\d+)?))?)?$/i.exec(p);if(j){T.push({type:`numbering`,start:j[1]?.toLowerCase()===`off`?null:Number(j[1]??1),step:Number(j[2]??1),line:n});return}if(/^activate\s+(\S+)$/i.test(p)||/^deactivate\s+(\S+)$/i.test(p)){let[,e,t]=/^(activate|deactivate)\s+(\S+)$/i.exec(p);if(!L(t,n))return;T.push({type:e.toLowerCase(),id:t,line:n});return}let z=/^Note\s+(over\s+(\S+?)(?:\s*,\s*(\S+))?|left\s+of\s+(\S+)|right\s+of\s+(\S+))\s*:\s*(.*)$/i.exec(p);if(z){let e=z[2]?[z[2],z[3]].filter(Boolean):[z[4]||z[5]];if(e.some(e=>!L(e,n)))return;T.push({type:`note`,place:z[2]?`over`:z[4]?`left`:`right`,ids:e,...P(z[6].trim(),n),line:n});return}let B=/^(alt|opt|loop|par_over|par|critical|break|rect|box|else|and|option|end)(?:\s+(.*)|$)/i.exec(p);if(B){let e=B[1].toLowerCase().replace(`par_over`,`par`),t=(B[2]||``).trim(),i,s;if(e===`box`||e===`rect`){i=f.exec(t)?.[0]||/^transparent\b/i.exec(t)?.[0];let e=t.split(/\s/,1)[0];!i&&((0,r.roleOfColor)(e)||/^(?:black|white|(?:light|dark|slate|dim)?gr[ae]y|silver)$/i.test(e))&&(i=e),i&&(s=(0,r.roleOfColor)(i),s||/^transparent$/i.test(i)||x.has(i)||x.set(i,n),t=t.slice(i.length).trim())}if(e===`end`){t&&S.push(d(g,n,`end 后面不能再写内容`,`end cannot have trailing text`,`这一行只写 end`,`Leave only end on this line`)),R(n);return}let{text:c,icon:l}=P(t,n);if(o.has(e)){let t=E.at(-1),r={else:[`alt`],and:[`par`],option:[`critical`]}[e];if(!t||!r.includes(t.keyword)){S.push(d(g,n,`「${e}」不能出现在当前片段里`,`"${e}" is not valid in the current fragment`,`把它放到对应的 ${r.join(`/`)} 片段中`,`Place it inside ${r.join(`/`)} before end`));return}T.push({type:`section`,keyword:e,text:c,icon:l,line:n,owner:t}),t.sections.push({keyword:e,text:c,icon:l,line:n});return}if(E.length>=a.fragmentDepth){S.push(d(g,n,`组合片段最多嵌套 ${a.fragmentDepth} 层`,`Fragments nest at most ${a.fragmentDepth} levels`,`把内层片段拆到另一张图`,`Move the inner fragment to another diagram`));return}let u={type:e===`box`?`box`:e===`rect`?`rect`:`fragment`,keyword:e,text:c,icon:l,color:i,status:s,line:n,kind:e===`box`||e===`rect`?e:`fragment`,sections:[],members:[]};T.push(u),E.push(u);return}let V=Array.from(p.matchAll(/:::[\w-]+|:/g)).find(e=>e[0]===`:`)?.index,H=V!==void 0,U=H?p.slice(0,V):p,W=l.exec(U);if(W?.index>0){let e=c.get(W[0].toLowerCase()),t=/^(.*?)\s*(\(\))?\s*(\+)?$/.exec(U.slice(0,W.index).trim()),r=/^([+-])?\s*(\(\))?\s*(.*?)\s*(\+)?$/.exec(U.slice(W.index+W[0].length).trim()),[,i,o,s]=t,l=F(i,n),[,f,m,h,_]=r,v=f||s||_||(h.endsWith(`-`)&&!w.has(h)?`-`:``),y=F(v===`-`&&!f&&h.endsWith(`-`)?h.slice(0,-1):h,n);if(!u(l)||!u(y)){S.push(d(g,n,`消息的参与者写法无效`,`Invalid message participants`,`写成 A->>B: 消息,自调用写成 A->>A: 消息`,`Write A->>B: message, or A->>A: message for a self call`));return}if(!L(l,n)||!L(y,n))return;let b,x;if(k?(k.id===y?b=y:I(k,`下一条消息必须发给新参与者`,`The next message must target the new participant`),k=void 0):A&&=(A.id===l||A.id===y?x=A.id:I(A,`下一条消息必须涉及待销毁的参与者`,`The next message must involve the destroyed participant`),void 0),D+=1,D>a.messages){S.push(d(g,n,`消息超过 ${a.messages} 条`,`More than ${a.messages} messages`,`删到 ${a.messages} 条,或拆成两张图`,`Keep at most ${a.messages} messages, or split the diagram`));return}let C=v===`+`?y:``,E=v===`-`?l:``;T.push({type:`message`,from:l,to:y,style:e.style,arrow:e,centralStart:!!o,centralEnd:!!m,create:b,destroy:x,...P(H?p.slice(V+1).trim():``,n),line:n,activate:!!C,deactivate:!!E,activateOn:C,deactivateOn:E})}else S.push(d(g,n,`无法识别的语句「${p.slice(0,40)}」`,`Unrecognized statement: ${p.slice(0,40)}`,`改成 participant、消息、Note、片段、rect、box 或 end`,`Use participant, a message, Note, a fragment, rect, box, or end`))}z.forEach((e,t)=>{if(!(/^\s*(?:style|classDef|linkStyle)\s/i.test(e)&&y.accept(e,v+t)))for(let n of p(e))B(n,v+t)});for(let e of[k,A])e&&I(e,`缺少后续消息`,`Missing a following message`);for(let e of E)S.push(d(g,e.line,`「${e.keyword}」缺少 end`,`"${e.keyword}" is missing end`,`在第 ${z.length?v+z.length-1:e.line} 行后补上 end`,`Add end after the block`));let V=new Map;for(let e of T){if(e.type===`activate`&&V.set(e.id,(V.get(e.id)||0)+1),e.type===`message`&&e.activateOn&&V.set(e.activateOn,(V.get(e.activateOn)||0)+1),e.type===`deactivate`||e.type===`message`&&e.deactivateOn){let t=e.type===`deactivate`?e.id:e.deactivateOn,n=(V.get(t)||0)-1;n<0&&S.push(d(g,e.line,`「${t}」的激活条没有配对的开始`,`Activation of "${t}" has no matching start`,`在这条之前写 activate ${t},或给进入消息加 +`,`Write activate ${t} before this line, or add + to the incoming message`)),V.set(t,Math.max(0,n))}e.destroy&&V.delete(e.destroy)}C.length||S.push(d(g,v,`图中没有参与者`,`The diagram has no participants`,`写 participant,或写一条 A->>B: 消息`,`Add a participant or a message such as A->>B: text`));for(let e of C)e.status=y.statusOf(e.id),e.link=b.get(e.id)??y.linkOf(e.id);let H=0;for(let e of T)e.type===`message`&&(e.status=y.edgeStatusOf(H++));if(S.push(...y.diagnostics()),x.size){let e=[...x.keys()].join(`, `);S.push((0,i.warning)(`IGNORED_STYLE`,g,x.values().next().value,`区段颜色使用中性色:${e}`,`Region colors rendered as neutral: ${e}`,`使用有彩度的颜色`,`Use chromatic colors`))}return{model:{type:`sequence`,participants:C,statements:T,title:O,messages:D},errors:S}}var g=20,_=36,v=12,y=e=>e.icon?g:0;function b(e,{measure:t,width:n,lang:r},o={}){let s=o.config?.sequence,c=s?.mirrorActors!==!1,l=[],u=e.participants.map(e=>({...e})),f=e=>u.find(t=>t.id===e),p=(e,n,r)=>{let o=(0,i.wrapText)(e,168,n,t).slice(0,a.lines);return{lines:o,w:(0,i.snap)(Math.max(64,(0,i.maxWidthOf)(o,n,t)+24)),h:(0,i.snap)(Math.max(32,o.length*18+14+(r?24:0)))}};for(let e of u){let n=e.kind!==`participant`||!!e.icon;e.head=p(e.name,i.FONT.title,n),e.foot={...e.head},(0,i.wrapText)(e.name,168,i.FONT.title,t).length>a.lines&&l.push(d(r,e.line,`参与者「${e.name}」超过 ${a.lines} 行`,`Participant "${e.name}" exceeds ${a.lines} lines`,`缩短名称,说明移到图外`,`Shorten the name and move the description outside`))}let m=(Math.max(320,n)-16)/(u.length+1),h=Math.round(Math.max(96,Math.min(200,m))),g=Math.round(Math.max(96,Math.min(180,m))),v=[],b=[],x=e=>{v.push(e)},S=s?.showSequenceNumbers===!0?1:null,C=1,w=(e,n)=>{let r=e.text||e.icon?(0,i.wrapText)(e.text,Math.max(1,n-y(e)),i.FONT.label,t):[],a=(r.length?r.length*16+8:0)+(e.ordinal?16:0),o=e.create?f(e.create).head.h/2:0,s=e.from===e.to?e.ordinal?12:r.length?0:8:0,c=Math.max(a+(r.length?2:10)+s,o+8),l=(0,i.snap)(Math.max(a+20,c+o+12));Object.assign(e,{lines:r,h:l,lineOffset:c,textW:Math.max((0,i.maxWidthOf)(r,i.FONT.label,t)+y(e),t(e.ordinal,i.FONT.label))})};for(let n of e.statements)if(n.type===`box`||n.type===`rect`||n.type===`fragment`){let e=n.type===`box`||n.type===`rect`&&!n.text&&!n.icon?8:28;x({...n,kind:`open`,h:e,depth:b.length}),b.push(v.at(-1))}else if(n.type===`section`)x({...n,host:b.at(-1),kind:`section`,h:28});else if(n.type===`end`){let e=b.pop();x({...n,kind:`close`,h:12,depth:b.length}),e&&(e.close=v.at(-1))}else if(n.type===`note`){let e=i.FONT.label,o=n.place===`over`?Math.abs(f(n.ids[0]).index-f(n.ids.at(-1)).index):0,s=Math.max(g,Math.min(180,o*132)),c=(0,i.wrapText)(n.text,s,e,t);c.length>a.lines&&l.push(d(r,n.line,`注释超过 ${a.lines} 行`,`Note exceeds ${a.lines} lines`,`缩短注释,或拆成多条 Note`,`Shorten the note or split it into several Note lines`));let u=c.slice(0,a.lines);x({...n,kind:`note`,lines:u,h:(0,i.snap)(Math.max(u.length,+!!n.icon)*16+16),textW:(0,i.maxWidthOf)(u,e,t)+y(n)})}else if(n.type===`participant`)x({...n,kind:`participant`,h:0});else if(n.type===`activate`||n.type===`deactivate`)x({...n,kind:n.type,h:8});else if(n.type===`numbering`)S=n.start,C=n.step;else if(n.type===`message`){let e=S==null?``:String(Number(S.toPrecision(15)));S!=null&&(S+=C);let t={...n,kind:`message`,ordinal:e},r=Math.abs(f(n.from).index-f(n.to).index);w(t,r?Math.max(h,Math.min(200,r*132)):Math.min(168,h)),x(t)}if(l.length)return{width:n,height:0,errors:l};let T=u.length,E=new Map(v.map((e,t)=>[e,t])),D=new Map;for(let e of v){if(e.kind!==`open`||!e.close)continue;let t=[];for(let n=E.get(e)+1;n<E.get(e.close);n+=1)t.push(v[n]);D.set(e,t)}let O=e=>{let t=e.map(e=>f(e).index);return[Math.min(...t),Math.max(...t)]};for(let e of v){if(e.kind!==`open`)continue;let t=e.type===`box`?[...e.members||[]]:[];if(e.type!==`box`)for(let n of D.get(e)||[])(n.kind===`message`||n.kind===`note`)&&t.push(...n.kind===`note`?n.ids:[n.from,n.to]);let n=[...new Set(t)];n.length?[e.lo,e.hi]=O(n):(e.lo=0,e.hi=T-1)}if(l.length)return{width:n,height:0,errors:l};let k=u.map(e=>Math.max(e.head.w,e.foot.w)/2),A=Array(T+1).fill(0),j=Array(T+1).fill(0),M=(e,t)=>{e>=0&&e<=T&&(A[e]=Math.max(A[e],t))},N=(e,t,n)=>{let r=t-e;for(let i=e+1;i<=t;i+=1)M(i,n/r)};u.forEach((e,t)=>{M(t,k[t]+12),M(t+1,k[t]+12),j[t]=Math.max(j[t],k[t]+12),j[t+1]=Math.max(j[t+1],k[t]+12),t>0&&(M(t,k[t-1]+k[t]+16),j[t]=Math.max(j[t],k[t-1]+k[t]+16))});for(let e=1;e<T;e+=1)j[e]=Math.max(j[e],24);let P=new Map,F=[...k];for(let e of v){let t=e.activateOn||e.type===`activate`&&e.id,n=e.deactivateOn||e.type===`deactivate`&&e.id;if(t){let e=P.get(t)||0;P.set(t,e+1);let n=f(t).index;F[n]=Math.max(F[n],5+e*7)}n&&P.set(n,(P.get(n)||1)-1),e.destroy&&P.delete(e.destroy)}for(let e=0;e<T;e+=1)F[e]>k[e]&&M(e,F[e]+(e>0?k[e-1]+16:12));for(let e of v)if(e.kind===`note`){if(e.place!==`over`)M(e.place===`left`?f(e.ids[0]).index:f(e.ids.at(-1)).index+1,e.textW+28);else{let[t,n]=O(e.ids);t===n?M(n+1,e.textW+44):N(t,n,e.textW+28)}}let I=e=>_+(e.create?f(e.create).head.w/2:0);for(let e of v)if(e.kind===`message`){let[t,n]=O([e.from,e.to]);if(t===n)M(t+1,e.textW+60);else{let r=A.slice(t+1,n+1).reduce((e,t)=>e+t,0),i=e.textW+I(e)-r;if(i>0)for(let e=t+1;e<=n;e++)A[e]+=i/(n-t)}}let L=A.map((e,t)=>Math.max(e,j[t])),R=()=>{let e=[],t=L[0];for(let n=0;n<T;n+=1)e.push(t),t+=L[n+1];return e},z=(e,t)=>{let n=t[f(e.ids[0]).index],r=t[f(e.ids.at(-1)).index],a=(0,i.snap)(e.textW+16),o=e.h-8;if(e.place===`over`&&n!==r){let e=Math.max(a,Math.abs(n-r)+24);return{x:(n+r-e)/2,w:e,h:o}}return{x:e.place===`left`?n-a-16:n+16,w:a,h:o}},B=e=>[e.keyword,e.text].filter(Boolean).join(` `),V=e=>e.type===`fragment`?`${e.keyword}${e.text?` [${e.text}]`:``}`:e.text,H=e=>{let n=new Map;for(let t of v)t.kind===`note`&&n.set(t,z(t,e));let r=new Map;for(let a=v.length-1;a>=0;--a){let o=v[a];if(o.kind!==`open`||o.lo==null)continue;let s=18+o.depth*12,c=e[o.lo]-(o.type===`box`?k[o.lo]+4:s),l=e[o.hi]+(o.type===`box`?k[o.hi]+4:s);for(let t of D.get(o)||[])if(t.kind===`message`){let n=e[f(t.from).index],r=e[f(t.to).index];if(t.create){let e=f(t.create).head.w/2;c=Math.min(c,r-e-8),l=Math.max(l,r+e+8)}if(n===r)l=Math.max(l,n+52+t.textW+8);else{let e=(n+r)/2;c=Math.min(c,e-t.textW/2-4),l=Math.max(l,e+t.textW/2+4)}}else if(t.kind===`note`&&n.has(t)){let e=n.get(t);c=Math.min(c,e.x),l=Math.max(l,e.x+e.w)}else t.kind===`open`&&r.has(t)&&(c=Math.min(c,r.get(t).left-6),l=Math.max(l,r.get(t).right+6));let u=[t(V(o),i.FONT.label)+y(o),...o.sections.map(e=>t(B(e),i.FONT.label)+y(e))];l=Math.max(l,c+20+Math.max(...u)),r.set(o,{left:c,right:l})}let a=e[0]-F[0],o=e[T-1]+k[T-1];for(let e of r.values())a=Math.min(a,e.left),o=Math.max(o,e.right);for(let e of n.values())a=Math.min(a,e.x),o=Math.max(o,e.x+e.w);for(let t of v){if(t.kind!==`message`)continue;let n=e[f(t.from).index],r=e[f(t.to).index];if(n===r)o=Math.max(o,n+52+t.textW+8);else{let e=(n+r)/2;a=Math.min(a,e-t.textW/2-4),o=Math.max(o,e+t.textW/2+4)}}return{notes:n,frames:r,left:a,right:o}},U=R(),W=H(U);for(let e=0;e<4;e+=1){let e=Math.floor(n)-16-(W.right-W.left);if(e<1)break;let t=Math.min(e/(T+1),128);if(t<1)break;for(let e=0;e<=T;e+=1)L[e]+=t;U=R(),W=H(U)}for(let e of v)if(e.kind===`message`){let[t,n]=O([e.from,e.to]);t!==n&&w(e,U[n]-U[t]-I(e)+1e-6),e.lines.length>a.lines&&l.push(d(r,e.line,`消息「${e.text}」超过 ${a.lines} 行`,`Message "${e.text}" exceeds ${a.lines} lines`,`缩短消息,说明移到图外`,`Shorten the message and move details outside`))}if(l.length)return{width:n,height:0,errors:l};W=H(U);let ee=8-W.left;U=U.map(e=>e+ee),W=H(U),u.forEach((e,t)=>{e.x=U[t]});for(let[e,t]of W.notes)e.note=t;for(let[e,t]of W.frames)e.left=t.left,e.right=t.right;let G=W.right,te=v.some(e=>e.type===`box`),K=(0,i.snap)(8+Math.max(36,...u.map(e=>e.head.h))+12),q=K+(te?28:8),J=q;for(let e of v)e.y=J,J+=e.h;let ne=c?(0,i.snap)(Math.max(...u.map(e=>e.foot.h))+12):0,Y=J+8,re=Y+ne+8;for(let e of v){if(e.kind!==`open`||!e.close)continue;let t=e.type===`box`?K+20:e.y,n=(e.type===`box`?Y+4:e.close.y+e.close.h)-t;e.box={x:e.left,y:t,w:e.right-e.left,h:n}}for(let e of v)e.note&&(e.note.y=e.y+4);let X=[],Z=new Map(u.map(e=>[e.id,[]])),ie=e=>e.y+e.lineOffset,ae=new Map,oe=new Map,se=(e,t)=>{let n=Z.get(e),r={id:e,x:f(e).x-5-n.length*7,y:t,h:0};n.push(r),X.push(r)},Q=(e,t,n=16)=>{let r=Z.get(e).pop();r&&(r.h=Math.max(n,t-r.y))};for(let e of v){if(e.type===`activate`&&se(e.id,e.y+4),e.type===`deactivate`&&Q(e.id,e.y+4),e.kind!==`message`)continue;let t=ie(e);if(e.create&&ae.set(e.create,t),e.destroy&&oe.set(e.destroy,t),e.activateOn&&se(e.activateOn,t+(e.create?f(e.create).head.h/2:0)),e.fromBar=Z.get(e.from).at(-1),e.toBar=Z.get(e.to).at(-1),e.deactivateOn&&e.destroy!==e.deactivateOn&&Q(e.deactivateOn,t+8),e.destroy)for(;Z.get(e.destroy).length;)Q(e.destroy,t,0)}let ce=[...X].sort((e,t)=>e.x-t.x),le=(e,t,n)=>{let r=e.x+8;for(let e of ce){if(e.y>t+18||e.y+e.h<t)continue;let i=e.x+16;e.x<r+n&&i>r&&(r=i)}return r};for(let e of v){if(e.kind===`open`&&e.box&&e.type!==`box`){let n=V(e);if(!n&&!e.icon)continue;let r=t(n,i.FONT.label)+y(e);e.labelX=le(e.box,e.box.y,r),e.box.w=Math.max(e.box.w,e.labelX+r+12-e.box.x),G=Math.max(G,e.box.x+e.box.w)}if(e.kind===`section`){let{host:n}=e;if(!n?.box)continue;let r=t(B(e),i.FONT.label)+y(e);e.labelX=le(n.box,e.y,r),n.box.w=Math.max(n.box.w,e.labelX+r+12-n.box.x),G=Math.max(G,n.box.x+n.box.w)}}for(let e of u){let t=ae.get(e.id),n=oe.get(e.id);e.head.x=e.x-e.head.w/2,e.head.y=t==null?8:t-e.head.h/2,e.life={x:e.x,y1:t==null?q-4:t+e.head.h/2,y2:n??Y},e.destroyed=n!=null,e.destroyed||!c?e.foot=null:(e.foot.x=e.x-e.foot.w/2,e.foot.y=Y+8);for(let t of Z.get(e.id))t.h=Math.max(0,e.life.y2-t.y)}let $=(0,i.snap)(G+8),ue=$<=n?Math.floor(n):$;return($>n*2||u.length>60||e.messages>200)&&l.push((0,i.warning)(`LARGE_DIAGRAM`,r,u[0].line,`时序图较大,可滚动查看`,`Large sequence diagram; scroll to view it`,`可将时序图拆分`,`Consider splitting the diagram`)),{type:`sequence`,width:ue,height:(0,i.snap)(re),actors:u,events:v,activations:X,errors:l,title:e.title}}function x(e,t){let n=(0,i.appearance)(t),r=[],a=(e,n,r,i)=>{let[a,o,s,c]=e.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c);return t.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`},e.elements.map(({tag:n,attrs:r})=>t.shape(n,{...r,...e.set===`simple`?{fill:i}:{fill:`none`,stroke:i,"stroke-width":1.7,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))},o=(e,{x:r,y:o,lines:s,icon:c,meta:l,font:u=i.FONT.label,anchor:d=`middle`,lineHeight:f=16,fill:p=n.fg2,underline:m=!1})=>{let h=s.length?s:[``],_=o-(h.length-1)/2*f,v=[];if(c){let e=d===`middle`,n=e?t.measure(h[0],u.size,u.weight):0;v.push(a(c,e?r-n/2-(h[0]?2:0):r+8,_,p)),r+=e?g/2:g}h.forEach((e,n)=>{if(!e)return;let i=t.text(r,_+n*f,e,{anchor:d,size:u.size,weight:u.weight,fill:p,"dominant-baseline":`central`,...m?{"text-decoration":`underline`}:{}});v.push(l?{...i,meta:l}:i)}),v.length&&e.push(t.el(`g`,{},v))},s=(e,n,r,i,a={})=>t.line(e,n,r,i,a),c={arrow:`M1 1 L8 5 L1 9 Z`,open:`M1 1 L8 5 L1 9`,cross:`M1 1 L9 9 M1 9 L9 1`,top:`M1 1 L8 5 H1 Z`,bottom:`M1 9 L8 5 H1 Z`,"stick-top":`M1 1 L8 5`,"stick-bottom":`M1 9 L8 5`},l=(e,t)=>`seq-arrow${e===`arrow`?``:`-${e}`}${t?`-${t}`:``}`,u=e=>e?.replace(/top|bottom/,e=>e===`top`?`bottom`:`top`),d=new Map;for(let r of e.events)if(r.arrow)for(let e of[r.arrow.head,u(r.arrow.start)]){if(!c[e])continue;let i=l(e,r.status),a=n[r.status]??n.fg3;d.has(i)||d.set(i,t.el(`marker`,{id:i,viewBox:`0 0 10 10`,refX:e===`cross`?5:8,refY:5,markerWidth:10,markerHeight:10,orient:`auto-start-reverse`,markerUnits:`userSpaceOnUse`},[t.path(c[e],{fill:c[e].endsWith(`Z`)?a:`none`,stroke:a,"stroke-width":1.2})]))}d.size&&r.push(t.el(`defs`,{},[...d.values()]));let f={actor:`M12 1 a3 3 0 1 0 .01 0 M12 7 v7 m-6-4 h12 m-6 4 l-5 6 m5-6 l5 6`,boundary:`M16 3 a7 7 0 1 0 .01 0 M9 10 H3 M3 4 v12`,control:`M12 4 a7 7 0 1 0 .01 0 M15 1 l-4 3 4 3`,entity:`M12 2 a7 7 0 1 0 .01 0 M5 17 h14`,database:`M4 5 a8 3 0 1 0 16 0 a8 3 0 1 0-16 0 v12 a8 3 0 0 0 16 0 V5 M4 11 a8 3 0 0 0 16 0`,queue:`M19 3 a3 7 0 1 0 0 14 a3 7 0 1 0 0-14 H5 a3 7 0 0 0 0 14 h14`,collections:`M7 4 V2 h14 v13 h-3 M3 6 h14 v13 H3 Z`},p=t.frameTone(n.accent),m=t.frameTone(n.tones[1]),h=e=>{if(!e.box)return;let{x:i,y:a,w:s,h:c}=e.box,l=[],u=e.type===`box`,d=e.type===`rect`&&e.color,f=n[e.status],h=f?t.frameTone(f):e.color?n.line:m,g=/^transparent$/i.test(e.color)?`none`:d?f||n.fg4:e.type===`rect`?t.tint(n.bg,p,n.soft):u?t.tint(n.bg,e.color&&!f?n.fg4:h,.08):t.mix(n.bg,n.fg4,.07),_=d?`none`:e.type===`rect`?p:u?h:n.line;if(l.push(t.rect(i,a,s,c,{fill:g,stroke:_,...d?{"fill-opacity":.1}:e.type===`rect`?{"stroke-opacity":.45}:{},"stroke-width":1,rx:n.smallRadius,...u?{"stroke-dasharray":`5 4`}:{}})),u)(e.text||e.icon)&&o(r,{x:i+s/2,y:a-10,lines:[e.text],icon:e.icon});else if(e.type!==`rect`||e.text||e.icon){let t=e.type===`rect`?e.text:e.keyword+(e.text?` [`+e.text+`]`:``);o(l,{x:e.labelX??i+8,y:a+12,lines:[t],icon:e.icon,anchor:`start`})}r.push({...t.el(`g`,{},l),meta:{kind:`frame`,id:`sequence-frame-${e.y}`}})};for(let t of e.events)t.kind===`open`&&h(t);for(let t of e.actors)r.push(s(t.life.x,t.life.y1,t.life.x,t.life.y2,{stroke:n.line2,"stroke-width":1}));for(let i of e.activations)i.h>0&&r.push(t.rect(i.x,i.y,10,i.h,{fill:t.tint(n.bg,p,.28),stroke:p,"stroke-opacity":.45,"stroke-width":1}));let _=t=>e.actors.find(e=>e.id===t),y=[],b=e.events.filter(e=>e.kind===`open`&&e.type===`box`).map(e=>e.box);for(let i of e.events){if(i.kind===`section`){let{host:e}=i;if(!e?.box)continue;r.push(s(e.box.x,i.y+4,e.box.x+e.box.w,i.y+4,{stroke:n.line,"stroke-dasharray":`3 3`})),o(r,{x:i.labelX??e.box.x+8,y:i.y+14,lines:[[i.keyword,i.text].filter(Boolean).join(` `)],icon:i.icon,anchor:`start`})}if(i.kind===`note`){let{x:e,y:a,w:s,h:c}=i.note,l=[];l.push(t.rect(e,a,s,c,{fill:n.surface,stroke:n.line2,"stroke-width":1,rx:n.smallRadius}));let u=i.place===`over`&&i.ids[0]!==i.ids.at(-1);o(l,{x:u?e+s/2:e+8,y:a+c/2,lines:i.lines,icon:i.icon,anchor:u?`middle`:`start`}),r.push(t.el(`g`,{},l))}if(i.kind!==`message`)continue;let e=_(i.from),a=_(i.to),c=i.y+i.lineOffset,d=e===a,f=a.x>=e.x?1:-1,{head:p,start:m,dashed:h}=i.arrow,g=n[i.status]??n.fg3,x={stroke:g,"stroke-width":1.5,"stroke-linecap":`butt`,...h?{"stroke-dasharray":`5 4`}:{},...m?{"marker-start":`url(#${l(u(m),i.status)})`}:{},...p===`none`?{}:{"marker-end":`url(#${l(p,i.status)})`}},S=i.centralStart?e.x:i.fromBar?i.fromBar.x+(f>0?10:0):e.x+f*(d?6:8),C=d?c-14:c,w=d?c+4:c,T=i.create&&w>=a.head.y&&w<=a.head.y+a.head.h,E=i.centralEnd&&!i.create,D=T?f>0?a.head.x:a.head.x+a.head.w:E||p===`cross`&&i.destroy===a.id?a.x:!i.create&&i.toBar?i.toBar.x+(d||f<0?10:0):a.x-(d?-1:f)*v,O=S+(i.centralStart&&m?f*7:0),k=D-(E&&p!==`none`?(d?-1:f)*7:0),A=d?t.path(`M${O} ${C} h${40+S-O} v18 H${k}`,{fill:`none`,...x}):s(O,c,k,c,x);(T?y:r).push({...A,meta:{kind:`message`,from:e.id,to:a.id}});let j=(e,n)=>r.push(t.el(`circle`,{cx:e,cy:n,r:3.5,fill:g}));i.centralStart&&j(S,C),E&&j(D,w);let M=d?e.x+52:i.create?(S+D)/2:(e.x+a.x)/2,N=d?c-20-(i.lines.length-1)*8:c-i.lines.length*8-10,P=c-(i.lines.length*16+(d?28:18)),F=d?M:M-i.textW/2,I=F+i.textW,L=(i.ordinal?P:N-(i.lines.length-1)*8)-7,R=(i.lines.length?N+(i.lines.length-1)*8:P)+7;i.textW&&b.some(e=>e.y<R&&e.y+e.h>L&&[e.x,e.x+e.w].some(e=>F-2<e&&e<I+2))&&r.push(t.rect(F-4,L,i.textW+8,R-L,{fill:n.bg,rx:n.smallRadius}));let z={kind:`message-label`,from:e.id,to:a.id};if((i.lines.length||i.icon)&&o(r,{x:M,y:N,lines:i.lines,icon:i.icon,meta:z,anchor:d?`start`:`middle`}),i.ordinal&&o(r,{x:M,y:P,lines:[i.ordinal],meta:z,anchor:d?`start`:`middle`,fill:n.fg3}),i.destroy&&(p!==`cross`||i.destroy!==a.id)){let e=_(i.destroy).x;r.push(t.path(`M${e-4} ${c-4} l8 8 m0 -8 l-8 8`,{fill:`none`,stroke:n.fg3,"stroke-width":1.5}))}}for(let s of e.actors)for(let e of[s.head,s.foot].filter(Boolean)){let c=[],l=f[s.kind],u=n[s.status];c.push(t.rect(e.x,e.y,e.w,e.h,{fill:u?t.tint(n.surface,u,.12):n.surface,stroke:u?t.frameTone(u):n.line,"stroke-width":1,rx:n.smallRadius})),s.icon?c.push(a(s.icon,s.x,e.y+16,n.fg3)):l&&c.push(t.path(l,{transform:`translate(${s.x-12} ${e.y+6})`,fill:`none`,stroke:n.fg3,"stroke-width":1.3,"stroke-linecap":`round`,"stroke-linejoin":`round`})),o(c,{x:s.x,y:e.y+e.h/2+(l||s.icon?12:0),lines:e.lines,font:i.FONT.title,lineHeight:18,fill:n.fg1,underline:!!s.link});let d={...t.el(`g`,{},c),meta:{kind:`participant`,id:s.id}};r.push(s.link?t.link(s.link.href,[d],s.link):d)}return r.push(...y),{width:e.width,height:e.height,children:r,title:e.title,heading:e.title}}var S={sequenceDiagram:{parse:h,layout:b,scene:x,acceptsPresentation:!0,honoredConfig:[`sequence.mirrorActors`,`sequence.showSequenceNumbers`]}};return e.LIMITS=a,e.implementations=S,e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);
2
+ `);function B(e,n){if(!e.trim()||e.trimStart().startsWith(`%%`))return;if(/^\s*\t|^\s+\t/.test(e)||e.includes(` `)){S.push(d(g,n,`时序图语句不能使用 Tab`,`Tabs are not allowed in sequence statements`,`把 Tab 换成空格`,`Replace tabs with spaces`));return}let p=e.trim(),h=/^title(?:\s*:\s*|\s+)(.+)$/i.exec(p);if(h){O=P(h[1],n).text;return}let _=/^(link|links|properties|details)\s+([^\s:]+)\s*:\s*(.*)$/i.exec(p);if(_){let[,e,t,i]=_;if(M(`IGNORED_INTERACTION`,n,`已省略参与者菜单和详情界面;仅保留首个安全链接`,`Participant menus and details are omitted; only the first safe URL is kept`,`把其他必要链接放在图外`,`Put other essential links outside the diagram`),!b.has(t)){let n=[];if(e.toLowerCase()===`link`){let e=/^(.*?)@\s*(.+)$/.exec(i);e&&(n=[[e[1].trim(),e[2]]])}else if(e.toLowerCase()===`links`)try{let e=JSON.parse(i);e&&typeof e==`object`&&!Array.isArray(e)&&(n=Object.entries(e))}catch{}for(let[e,i]of n){let n=typeof i==`string`&&(0,r.safeHref)(i.trim());if(n){b.set(t,{href:n,tooltip:e});break}}}return}if(y.accept(p,n))return;let v=/^(?:(create)\s+)?(participant|actor)\s+([^\s@]+)(?:\s*@\{([^}]*)\})?(?:\s+as\s+(.+))?$/i.exec(p);if(v){let[,e,r,a,o,c]=v,[,l,f]=/^(.*?)::icon\(([^)]+)\)$/.exec(a)??[],p=F(l??a,n),h=m(o);if(!u(p)){S.push(d(g,n,`参与者 ID 无效`,`Invalid participant id`,`写成 participant ID as 名称`,`Write participant ID as Name`));return}if(e&&(w.has(p)||k)){I({id:p,line:n},`重复创建或已有待创建的参与者`,`Duplicate or already pending creation`);return}let _=L(p,n);if(!_)return;let y=h.type||r.toLowerCase();s.has(y)||M(`DIAGRAM_HINT`,n,`未知参与者类型,使用普通方框`,`Unknown participant type; using a standard participant`,`检查 type`,`Check the type value`);let{text:b,icon:x}=P(c||h.alias||p,n),C=f||h.icon,D=C?(0,t.resolveIconRef)(C):null;C&&!D&&N((0,i.warning)(`IGNORED_ASSET`,g,n,`未知图标 ${C}`,`Unknown icon ${C}`,`使用内置图标`,`Use a supported icon`)),Object.assign(_,{name:b,icon:D||x,kind:s.has(y)?y:`participant`,declared:!0,line:n}),e&&(k={id:p,line:n}),E.at(-1)?.type===`box`&&E.at(-1).members.push(p),T.push({type:`participant`,id:p,line:n});return}let C=/^destroy\s+(\S+)$/i.exec(p);if(C){let e=C[1];!w.has(e)||A?I({id:e,line:n},`未知参与者或已有待销毁的参与者`,`Unknown participant or already pending destruction`):A={id:e,line:n};return}let j=/^autonumber(?:\s+(off|[+-]?\d+(?:\.\d+)?)(?:\s+([+-]?\d+(?:\.\d+)?))?)?$/i.exec(p);if(j){T.push({type:`numbering`,start:j[1]?.toLowerCase()===`off`?null:Number(j[1]??1),step:Number(j[2]??1),line:n});return}if(/^activate\s+(\S+)$/i.test(p)||/^deactivate\s+(\S+)$/i.test(p)){let[,e,t]=/^(activate|deactivate)\s+(\S+)$/i.exec(p);if(!L(t,n))return;T.push({type:e.toLowerCase(),id:t,line:n});return}let z=/^Note\s+(over\s+(\S+?)(?:\s*,\s*(\S+))?|left\s+of\s+(\S+)|right\s+of\s+(\S+))\s*:\s*(.*)$/i.exec(p);if(z){let e=z[2]?[z[2],z[3]].filter(Boolean):[z[4]||z[5]];if(e.some(e=>!L(e,n)))return;T.push({type:`note`,place:z[2]?`over`:z[4]?`left`:`right`,ids:e,...P(z[6].trim(),n),line:n});return}let B=/^(alt|opt|loop|par_over|par|critical|break|rect|box|else|and|option|end)(?:\s+(.*)|$)/i.exec(p);if(B){let e=B[1].toLowerCase().replace(`par_over`,`par`),t=(B[2]||``).trim(),i,s;if(e===`box`||e===`rect`){i=f.exec(t)?.[0]||/^transparent\b/i.exec(t)?.[0];let e=t.split(/\s/,1)[0];!i&&((0,r.roleOfColor)(e)||/^(?:black|white|(?:light|dark|slate|dim)?gr[ae]y|silver)$/i.test(e))&&(i=e),i&&(s=(0,r.roleOfColor)(i),s||/^transparent$/i.test(i)||x.has(i)||x.set(i,n),t=t.slice(i.length).trim())}if(e===`end`){t&&S.push(d(g,n,`end 后面不能再写内容`,`end cannot have trailing text`,`这一行只写 end`,`Leave only end on this line`)),R(n);return}let{text:c,icon:l}=P(t,n);if(o.has(e)){let t=E.at(-1),r={else:[`alt`],and:[`par`],option:[`critical`]}[e];if(!t||!r.includes(t.keyword)){S.push(d(g,n,`「${e}」不能出现在当前片段里`,`"${e}" is not valid in the current fragment`,`把它放到对应的 ${r.join(`/`)} 片段中`,`Place it inside ${r.join(`/`)} before end`));return}T.push({type:`section`,keyword:e,text:c,icon:l,line:n,owner:t}),t.sections.push({keyword:e,text:c,icon:l,line:n});return}if(E.length>=a.fragmentDepth){S.push(d(g,n,`组合片段最多嵌套 ${a.fragmentDepth} 层`,`Fragments nest at most ${a.fragmentDepth} levels`,`把内层片段拆到另一张图`,`Move the inner fragment to another diagram`));return}let u={type:e===`box`?`box`:e===`rect`?`rect`:`fragment`,keyword:e,text:c,icon:l,color:i,status:s,line:n,kind:e===`box`||e===`rect`?e:`fragment`,sections:[],members:[]};T.push(u),E.push(u);return}let V=Array.from(p.matchAll(/:::[\w-]+|:/g)).find(e=>e[0]===`:`)?.index,H=V!==void 0,U=H?p.slice(0,V):p,W=l.exec(U);if(W?.index>0){let e=c.get(W[0].toLowerCase()),t=/^(.*?)\s*(\(\))?\s*(\+)?$/.exec(U.slice(0,W.index).trim()),r=/^([+-])?\s*(\(\))?\s*(.*?)\s*(\+)?$/.exec(U.slice(W.index+W[0].length).trim()),[,i,o,s]=t,l=F(i,n),[,f,m,h,_]=r,v=f||s||_||(h.endsWith(`-`)&&!w.has(h)?`-`:``),y=F(v===`-`&&!f&&h.endsWith(`-`)?h.slice(0,-1):h,n);if(!u(l)||!u(y)){S.push(d(g,n,`消息的参与者写法无效`,`Invalid message participants`,`写成 A->>B: 消息,自调用写成 A->>A: 消息`,`Write A->>B: message, or A->>A: message for a self call`));return}if(!L(l,n)||!L(y,n))return;let b,x;if(k?(k.id===y?b=y:I(k,`下一条消息必须发给新参与者`,`The next message must target the new participant`),k=void 0):A&&=(A.id===l||A.id===y?x=A.id:I(A,`下一条消息必须涉及待销毁的参与者`,`The next message must involve the destroyed participant`),void 0),D+=1,D>a.messages){S.push(d(g,n,`消息超过 ${a.messages} 条`,`More than ${a.messages} messages`,`删到 ${a.messages} 条,或拆成两张图`,`Keep at most ${a.messages} messages, or split the diagram`));return}let C=v===`+`?y:``,E=v===`-`?l:``;T.push({type:`message`,from:l,to:y,style:e.style,arrow:e,centralStart:!!o,centralEnd:!!m,create:b,destroy:x,...P(H?p.slice(V+1).trim():``,n),line:n,activate:!!C,deactivate:!!E,activateOn:C,deactivateOn:E})}else S.push(d(g,n,`无法识别的语句「${p.slice(0,40)}」`,`Unrecognized statement: ${p.slice(0,40)}`,`改成 participant、消息、Note、片段、rect、box 或 end`,`Use participant, a message, Note, a fragment, rect, box, or end`))}z.forEach((e,t)=>{if(!(/^\s*(?:style|classDef|linkStyle)\s/i.test(e)&&y.accept(e,v+t)))for(let n of p(e))B(n,v+t)});for(let e of[k,A])e&&I(e,`缺少后续消息`,`Missing a following message`);for(let e of E)S.push(d(g,e.line,`「${e.keyword}」缺少 end`,`"${e.keyword}" is missing end`,`在第 ${z.length?v+z.length-1:e.line} 行后补上 end`,`Add end after the block`));let V=new Map;for(let e of T){if(e.type===`activate`&&V.set(e.id,(V.get(e.id)||0)+1),e.type===`message`&&e.activateOn&&V.set(e.activateOn,(V.get(e.activateOn)||0)+1),e.type===`deactivate`||e.type===`message`&&e.deactivateOn){let t=e.type===`deactivate`?e.id:e.deactivateOn,n=(V.get(t)||0)-1;n<0&&S.push(d(g,e.line,`「${t}」的激活条没有配对的开始`,`Activation of "${t}" has no matching start`,`在这条之前写 activate ${t},或给进入消息加 +`,`Write activate ${t} before this line, or add + to the incoming message`)),V.set(t,Math.max(0,n))}e.destroy&&V.delete(e.destroy)}C.length||S.push(d(g,v,`图中没有参与者`,`The diagram has no participants`,`写 participant,或写一条 A->>B: 消息`,`Add a participant or a message such as A->>B: text`));for(let e of C)e.status=y.statusOf(e.id),e.link=b.get(e.id)??y.linkOf(e.id);let H=0;for(let e of T)e.type===`message`&&(e.status=y.edgeStatusOf(H++));if(S.push(...y.diagnostics()),x.size){let e=[...x.keys()].join(`, `);S.push((0,i.warning)(`IGNORED_STYLE`,g,x.values().next().value,`区段颜色使用中性色:${e}`,`Region colors rendered as neutral: ${e}`,`使用有彩度的颜色`,`Use chromatic colors`))}return{model:{type:`sequence`,participants:C,statements:T,title:O,messages:D},errors:S}}var g=20,_=36,v=12,y=e=>e.icon?g:0;function b(e,{measure:t,width:n,lang:r,compact:o},s={}){let c=s.config?.sequence,l=c?.mirrorActors!==!1,u=[],f=e.participants.map(e=>({...e})),p=e=>f.find(t=>t.id===e),m=(e,n,r)=>{let o=(0,i.wrapText)(e,168,n,t).slice(0,a.lines);return{lines:o,w:(0,i.snap)(Math.max(64,(0,i.maxWidthOf)(o,n,t)+24)),h:(0,i.snap)(Math.max(32,o.length*18+14+(r?24:0)))}};for(let e of f){let n=e.kind!==`participant`||!!e.icon;e.head=m(e.name,i.FONT.title,n),e.foot={...e.head},(0,i.wrapText)(e.name,168,i.FONT.title,t).length>a.lines&&u.push(d(r,e.line,`参与者「${e.name}」超过 ${a.lines} 行`,`Participant "${e.name}" exceeds ${a.lines} lines`,`缩短名称,说明移到图外`,`Shorten the name and move the description outside`))}let h=(Math.max(320,n)-16)/(f.length+1),g=Math.round(Math.max(96,Math.min(200,h))),v=Math.round(Math.max(96,Math.min(180,h))),b=[],x=[],S=e=>{b.push(e)},C=c?.showSequenceNumbers===!0?1:null,w=1,T=(e,n)=>{let r=e.text||e.icon?(0,i.wrapText)(e.text,Math.max(1,n-y(e)),i.FONT.label,t):[],a=(r.length?r.length*16+8:0)+(e.ordinal?16:0),o=e.create?p(e.create).head.h/2:0,s=e.from===e.to?e.ordinal?12:r.length?0:8:0,c=Math.max(a+(r.length?2:10)+s,o+8),l=(0,i.snap)(Math.max(a+20,c+o+12));Object.assign(e,{lines:r,h:l,lineOffset:c,textW:Math.max((0,i.maxWidthOf)(r,i.FONT.label,t)+y(e),t(e.ordinal,i.FONT.label))})};for(let n of e.statements)if(n.type===`box`||n.type===`rect`||n.type===`fragment`){let e=n.type===`box`||n.type===`rect`&&!n.text&&!n.icon?8:28;S({...n,kind:`open`,h:e,depth:x.length}),x.push(b.at(-1))}else if(n.type===`section`)S({...n,host:x.at(-1),kind:`section`,h:28});else if(n.type===`end`){let e=x.pop();S({...n,kind:`close`,h:12,depth:x.length}),e&&(e.close=b.at(-1))}else if(n.type===`note`){let e=i.FONT.label,o=n.place===`over`?Math.abs(p(n.ids[0]).index-p(n.ids.at(-1)).index):0,s=Math.max(v,Math.min(180,o*132)),c=(0,i.wrapText)(n.text,s,e,t);c.length>a.lines&&u.push(d(r,n.line,`注释超过 ${a.lines} 行`,`Note exceeds ${a.lines} lines`,`缩短注释,或拆成多条 Note`,`Shorten the note or split it into several Note lines`));let l=c.slice(0,a.lines);S({...n,kind:`note`,lines:l,h:(0,i.snap)(Math.max(l.length,+!!n.icon)*16+16),textW:(0,i.maxWidthOf)(l,e,t)+y(n)})}else if(n.type===`participant`)S({...n,kind:`participant`,h:0});else if(n.type===`activate`||n.type===`deactivate`)S({...n,kind:n.type,h:8});else if(n.type===`numbering`)C=n.start,w=n.step;else if(n.type===`message`){let e=C==null?``:String(Number(C.toPrecision(15)));C!=null&&(C+=w);let t={...n,kind:`message`,ordinal:e},r=Math.abs(p(n.from).index-p(n.to).index);T(t,r?Math.max(g,Math.min(200,r*132)):Math.min(168,g)),S(t)}if(u.length)return{width:n,height:0,errors:u};let E=f.length,D=new Map(b.map((e,t)=>[e,t])),O=new Map;for(let e of b){if(e.kind!==`open`||!e.close)continue;let t=[];for(let n=D.get(e)+1;n<D.get(e.close);n+=1)t.push(b[n]);O.set(e,t)}let k=e=>{let t=e.map(e=>p(e).index);return[Math.min(...t),Math.max(...t)]};for(let e of b){if(e.kind!==`open`)continue;let t=e.type===`box`?[...e.members||[]]:[];if(e.type!==`box`)for(let n of O.get(e)||[])(n.kind===`message`||n.kind===`note`)&&t.push(...n.kind===`note`?n.ids:[n.from,n.to]);let n=[...new Set(t)];n.length?[e.lo,e.hi]=k(n):(e.lo=0,e.hi=E-1)}if(u.length)return{width:n,height:0,errors:u};let A=f.map(e=>Math.max(e.head.w,e.foot.w)/2),j=Array(E+1).fill(0),M=Array(E+1).fill(0),N=(e,t)=>{e>=0&&e<=E&&(j[e]=Math.max(j[e],t))},P=(e,t,n)=>{let r=t-e;for(let i=e+1;i<=t;i+=1)N(i,n/r)};f.forEach((e,t)=>{N(t,A[t]+12),N(t+1,A[t]+12),M[t]=Math.max(M[t],A[t]+12),M[t+1]=Math.max(M[t+1],A[t]+12),t>0&&(N(t,A[t-1]+A[t]+16),M[t]=Math.max(M[t],A[t-1]+A[t]+16))});for(let e=1;e<E;e+=1)M[e]=Math.max(M[e],24);let F=new Map,I=[...A];for(let e of b){let t=e.activateOn||e.type===`activate`&&e.id,n=e.deactivateOn||e.type===`deactivate`&&e.id;if(t){let e=F.get(t)||0;F.set(t,e+1);let n=p(t).index;I[n]=Math.max(I[n],5+e*7)}n&&F.set(n,(F.get(n)||1)-1),e.destroy&&F.delete(e.destroy)}for(let e=0;e<E;e+=1)I[e]>A[e]&&N(e,I[e]+(e>0?A[e-1]+16:12));for(let e of b)if(e.kind===`note`){if(e.place!==`over`)N(e.place===`left`?p(e.ids[0]).index:p(e.ids.at(-1)).index+1,e.textW+28);else{let[t,n]=k(e.ids);t===n?N(n+1,e.textW+44):P(t,n,e.textW+28)}}let L=e=>_+(e.create?p(e.create).head.w/2:0);for(let e of b)if(e.kind===`message`){let[t,n]=k([e.from,e.to]);if(t===n)N(t+1,e.textW+60);else{let r=j.slice(t+1,n+1).reduce((e,t)=>e+t,0),i=e.textW+L(e)-r;if(i>0)for(let e=t+1;e<=n;e++)j[e]+=i/(n-t)}}let R=j.map((e,t)=>Math.max(e,M[t])),z=()=>{let e=[],t=R[0];for(let n=0;n<E;n+=1)e.push(t),t+=R[n+1];return e},B=(e,t)=>{let n=t[p(e.ids[0]).index],r=t[p(e.ids.at(-1)).index],a=(0,i.snap)(e.textW+16),o=e.h-8;if(e.place===`over`&&n!==r){let e=Math.max(a,Math.abs(n-r)+24);return{x:(n+r-e)/2,w:e,h:o}}return{x:e.place===`left`?n-a-16:n+16,w:a,h:o}},V=e=>[e.keyword,e.text].filter(Boolean).join(` `),H=e=>e.type===`fragment`?`${e.keyword}${e.text?` [${e.text}]`:``}`:e.text,U=e=>{let n=new Map;for(let t of b)t.kind===`note`&&n.set(t,B(t,e));let r=new Map;for(let a=b.length-1;a>=0;--a){let o=b[a];if(o.kind!==`open`||o.lo==null)continue;let s=18+o.depth*12,c=e[o.lo]-(o.type===`box`?A[o.lo]+4:s),l=e[o.hi]+(o.type===`box`?A[o.hi]+4:s);for(let t of O.get(o)||[])if(t.kind===`message`){let n=e[p(t.from).index],r=e[p(t.to).index];if(t.create){let e=p(t.create).head.w/2;c=Math.min(c,r-e-8),l=Math.max(l,r+e+8)}if(n===r)l=Math.max(l,n+52+t.textW+8);else{let e=(n+r)/2;c=Math.min(c,e-t.textW/2-4),l=Math.max(l,e+t.textW/2+4)}}else if(t.kind===`note`&&n.has(t)){let e=n.get(t);c=Math.min(c,e.x),l=Math.max(l,e.x+e.w)}else t.kind===`open`&&r.has(t)&&(c=Math.min(c,r.get(t).left-6),l=Math.max(l,r.get(t).right+6));let u=[t(H(o),i.FONT.label)+y(o),...o.sections.map(e=>t(V(e),i.FONT.label)+y(e))];l=Math.max(l,c+20+Math.max(...u)),r.set(o,{left:c,right:l})}let a=e[0]-I[0],o=e[E-1]+A[E-1];for(let e of r.values())a=Math.min(a,e.left),o=Math.max(o,e.right);for(let e of n.values())a=Math.min(a,e.x),o=Math.max(o,e.x+e.w);for(let t of b){if(t.kind!==`message`)continue;let n=e[p(t.from).index],r=e[p(t.to).index];if(n===r)o=Math.max(o,n+52+t.textW+8);else{let e=(n+r)/2;a=Math.min(a,e-t.textW/2-4),o=Math.max(o,e+t.textW/2+4)}}return{notes:n,frames:r,left:a,right:o}},W=z(),G=U(W);for(let e=0;!o&&e<4;e+=1){let e=Math.floor(n)-16-(G.right-G.left);if(e<1)break;let t=Math.min(e/(E+1),128);if(t<1)break;for(let e=0;e<=E;e+=1)R[e]+=t;W=z(),G=U(W)}for(let e of b)if(e.kind===`message`){let[t,n]=k([e.from,e.to]);t!==n&&T(e,W[n]-W[t]-L(e)+1e-6),e.lines.length>a.lines&&u.push(d(r,e.line,`消息「${e.text}」超过 ${a.lines} 行`,`Message "${e.text}" exceeds ${a.lines} lines`,`缩短消息,说明移到图外`,`Shorten the message and move details outside`))}if(u.length)return{width:n,height:0,errors:u};G=U(W);let ee=8-G.left;W=W.map(e=>e+ee),G=U(W),f.forEach((e,t)=>{e.x=W[t]});for(let[e,t]of G.notes)e.note=t;for(let[e,t]of G.frames)e.left=t.left,e.right=t.right;let K=G.right,te=b.some(e=>e.type===`box`),ne=(0,i.snap)(8+Math.max(36,...f.map(e=>e.head.h))+12),q=ne+(te?28:8),J=q;for(let e of b)e.y=J,J+=e.h;let re=l?(0,i.snap)(Math.max(...f.map(e=>e.foot.h))+12):0,Y=J+8,ie=Y+re+8;for(let e of b){if(e.kind!==`open`||!e.close)continue;let t=e.type===`box`?ne+20:e.y,n=(e.type===`box`?Y+4:e.close.y+e.close.h)-t;e.box={x:e.left,y:t,w:e.right-e.left,h:n}}for(let e of b)e.note&&(e.note.y=e.y+4);let X=[],Z=new Map(f.map(e=>[e.id,[]])),ae=e=>e.y+e.lineOffset,Q=new Map,oe=new Map,se=(e,t)=>{let n=Z.get(e),r={id:e,x:p(e).x-5-n.length*7,y:t,h:0};n.push(r),X.push(r)},$=(e,t,n=16)=>{let r=Z.get(e).pop();r&&(r.h=Math.max(n,t-r.y))};for(let e of b){if(e.type===`activate`&&se(e.id,e.y+4),e.type===`deactivate`&&$(e.id,e.y+4),e.kind!==`message`)continue;let t=ae(e);if(e.create&&Q.set(e.create,t),e.destroy&&oe.set(e.destroy,t),e.activateOn&&se(e.activateOn,t+(e.create?p(e.create).head.h/2:0)),e.fromBar=Z.get(e.from).at(-1),e.toBar=Z.get(e.to).at(-1),e.deactivateOn&&e.destroy!==e.deactivateOn&&$(e.deactivateOn,t+8),e.destroy)for(;Z.get(e.destroy).length;)$(e.destroy,t,0)}let ce=[...X];if(e.zenuml)for(let e of f){let t=Q.get(e.id),n=t==null?q-4:t+e.head.h/2;ce.push({x:e.x-1,y:n,h:Y-n})}let le=ce.sort((e,t)=>e.x-t.x),ue=(e,t,n)=>{let r=e.x+8;for(let e of le){if(e.y>t+18||e.y+e.h<t)continue;let i=e.x+16;e.x<r+n&&i>r&&(r=i)}return r};for(let e of b){if(e.kind===`open`&&e.box&&e.type!==`box`){let n=H(e);if(!n&&!e.icon)continue;let r=t(n,i.FONT.label)+y(e);e.labelX=ue(e.box,e.box.y,r),e.box.w=Math.max(e.box.w,e.labelX+r+12-e.box.x),K=Math.max(K,e.box.x+e.box.w)}if(e.kind===`section`){let{host:n}=e;if(!n?.box)continue;let r=t(V(e),i.FONT.label)+y(e);e.labelX=ue(n.box,e.y,r),n.box.w=Math.max(n.box.w,e.labelX+r+12-n.box.x),K=Math.max(K,n.box.x+n.box.w)}}for(let e of f){let t=Q.get(e.id),n=oe.get(e.id);e.head.x=e.x-e.head.w/2,e.head.y=t==null?8:t-e.head.h/2,e.life={x:e.x,y1:t==null?q-4:t+e.head.h/2,y2:n??Y},e.destroyed=n!=null,e.destroyed||!l?e.foot=null:(e.foot.x=e.x-e.foot.w/2,e.foot.y=Y+8);for(let t of Z.get(e.id))t.h=Math.max(0,e.life.y2-t.y)}let de=(0,i.snap)(K+8),fe=!o&&de<=n?Math.floor(n):de;return(de>n*2||f.length>60||e.messages>200)&&u.push((0,i.warning)(`LARGE_DIAGRAM`,r,f[0].line,`时序图较大,可滚动查看`,`Large sequence diagram; scroll to view it`,`可将时序图拆分`,`Consider splitting the diagram`)),{type:`sequence`,width:fe,height:(0,i.snap)(ie),actors:f,events:b,activations:X,errors:u,title:e.title,...e.zenuml?{zenuml:!0}:{}}}function x(e,t){let n=(0,i.appearance)(t),r=[],a=(e,n,r,i)=>{let[a,o,s,c]=e.viewBox.split(/\s+/).map(Number),l=16/Math.max(s,c);return t.el(`g`,{transform:`translate(${n-(a+s/2)*l} ${r-(o+c/2)*l}) scale(${l})`},e.elements.map(({tag:n,attrs:r})=>t.shape(n,{...r,...e.set===`simple`?{fill:i}:{fill:`none`,stroke:i,"stroke-width":1.7,"stroke-linecap":`round`,"stroke-linejoin":`round`}})))},o=(e,{x:r,y:o,lines:s,icon:c,meta:l,font:u=i.FONT.label,anchor:d=`middle`,lineHeight:f=16,fill:p=n.fg2,underline:m=!1})=>{let h=s.length?s:[``],_=o-(h.length-1)/2*f,v=[];if(c){let e=d===`middle`,n=e?t.measure(h[0],u.size,u.weight):0;v.push(a(c,e?r-n/2-(h[0]?2:0):r+8,_,p)),r+=e?g/2:g}h.forEach((e,n)=>{if(!e)return;let i=t.text(r,_+n*f,e,{anchor:d,size:u.size,weight:u.weight,fill:p,"dominant-baseline":`central`,...m?{"text-decoration":`underline`}:{}});v.push(l?{...i,meta:l}:i)}),v.length&&e.push(t.el(`g`,{},v))},s=(e,n,r,i,a={})=>t.line(e,n,r,i,a),c={arrow:`M1 1 L8 5 L1 9 Z`,open:`M1 1 L8 5 L1 9`,cross:`M1 1 L9 9 M1 9 L9 1`,top:`M1 1 L8 5 H1 Z`,bottom:`M1 9 L8 5 H1 Z`,"stick-top":`M1 1 L8 5`,"stick-bottom":`M1 9 L8 5`},l=(e,t)=>`seq-arrow${e===`arrow`?``:`-${e}`}${t?`-${t}`:``}`,u=e=>e?.replace(/top|bottom/,e=>e===`top`?`bottom`:`top`),d=new Map;for(let r of e.events)if(r.arrow)for(let e of[r.arrow.head,u(r.arrow.start)]){if(!c[e])continue;let i=l(e,r.status),a=n[r.status]??n.fg3;d.has(i)||d.set(i,t.el(`marker`,{id:i,viewBox:`0 0 10 10`,refX:e===`cross`?5:8,refY:5,markerWidth:10,markerHeight:10,orient:`auto-start-reverse`,markerUnits:`userSpaceOnUse`},[t.path(c[e],{fill:c[e].endsWith(`Z`)?a:`none`,stroke:a,"stroke-width":1.2})]))}d.size&&r.push(t.el(`defs`,{},[...d.values()]));let f={actor:`M12 1 a3 3 0 1 0 .01 0 M12 7 v7 m-6-4 h12 m-6 4 l-5 6 m5-6 l5 6`,boundary:`M16 3 a7 7 0 1 0 .01 0 M9 10 H3 M3 4 v12`,control:`M12 4 a7 7 0 1 0 .01 0 M15 1 l-4 3 4 3`,entity:`M12 2 a7 7 0 1 0 .01 0 M5 17 h14`,database:`M4 5 a8 3 0 1 0 16 0 a8 3 0 1 0-16 0 v12 a8 3 0 0 0 16 0 V5 M4 11 a8 3 0 0 0 16 0`,queue:`M19 3 a3 7 0 1 0 0 14 a3 7 0 1 0 0-14 H5 a3 7 0 0 0 0 14 h14`,collections:`M7 4 V2 h14 v13 h-3 M3 6 h14 v13 H3 Z`},p=t.frameTone(n.accent),m=t.frameTone(n.tones[1]),h=e=>{if(!e.box)return;let{x:i,y:a,w:s,h:c}=e.box,l=[],u=e.type===`box`,d=e.type===`rect`&&e.color,f=n[e.status],h=f?t.frameTone(f):e.color?n.line:m,g=/^transparent$/i.test(e.color)?`none`:d?f||n.fg4:e.type===`rect`?t.tint(n.bg,p,n.soft):u?t.tint(n.bg,e.color&&!f?n.fg4:h,.08):t.mix(n.bg,n.fg4,.07),_=d?`none`:e.type===`rect`?p:u?h:n.line;if(l.push(t.rect(i,a,s,c,{fill:g,stroke:_,...d?{"fill-opacity":.1}:e.type===`rect`?{"stroke-opacity":.45}:{},"stroke-width":1,rx:n.smallRadius,...u?{"stroke-dasharray":`5 4`}:{}})),u)(e.text||e.icon)&&o(r,{x:i+s/2,y:a-10,lines:[e.text],icon:e.icon});else if(e.type!==`rect`||e.text||e.icon){let t=e.type===`rect`?e.text:e.keyword+(e.text?` [`+e.text+`]`:``);o(l,{x:e.labelX??i+8,y:a+12,lines:[t],icon:e.icon,anchor:`start`})}r.push({...t.el(`g`,{},l),meta:{kind:`frame`,id:`sequence-frame-${e.y}`}})};for(let t of e.events)t.kind===`open`&&h(t);let _=r.length,y=[];if(!e.zenuml)for(let t of e.actors)r.push(s(t.life.x,t.life.y1,t.life.x,t.life.y2,{stroke:n.line2,"stroke-width":1}));for(let i of e.activations)i.h>0&&r.push(t.rect(i.x,i.y,10,i.h,{fill:t.tint(n.bg,p,.28),stroke:p,"stroke-opacity":.45,"stroke-width":1}));let b=t=>e.actors.find(e=>e.id===t),x=[],S=e.events.filter(e=>e.kind===`open`&&e.type===`box`).map(e=>e.box);for(let i of e.events){if(i.kind===`section`){let{host:e}=i;if(!e?.box)continue;r.push(s(e.box.x,i.y+4,e.box.x+e.box.w,i.y+4,{stroke:n.line,"stroke-dasharray":`3 3`})),o(r,{x:i.labelX??e.box.x+8,y:i.y+14,lines:[[i.keyword,i.text].filter(Boolean).join(` `)],icon:i.icon,anchor:`start`})}if(i.kind===`note`){let{x:e,y:a,w:s,h:c}=i.note,l=[];l.push(t.rect(e,a,s,c,{fill:n.surface,stroke:n.line2,"stroke-width":1,rx:n.smallRadius}));let u=i.place===`over`&&i.ids[0]!==i.ids.at(-1);o(l,{x:u?e+s/2:e+8,y:a+c/2,lines:i.lines,icon:i.icon,anchor:u?`middle`:`start`}),r.push(t.el(`g`,{},l))}if(i.kind!==`message`)continue;let a=b(i.from),c=b(i.to),d=i.y+i.lineOffset,f=a===c,p=c.x>=a.x?1:-1,{head:m,start:h,dashed:g}=i.arrow,_=n[i.status]??n.fg3,C={stroke:_,"stroke-width":1.5,"stroke-linecap":`butt`,...g?{"stroke-dasharray":`5 4`}:{},...h?{"marker-start":`url(#${l(u(h),i.status)})`}:{},...m===`none`?{}:{"marker-end":`url(#${l(m,i.status)})`}},w=i.centralStart?a.x:i.fromBar?i.fromBar.x+(p>0?10:0):a.x+p*(f?6:8),T=f?d-14:d,E=f?d+4:d,D=i.create&&E>=c.head.y&&E<=c.head.y+c.head.h,O=i.centralEnd&&!i.create,k=D?p>0?c.head.x:c.head.x+c.head.w:O||m===`cross`&&i.destroy===c.id?c.x:!i.create&&i.toBar?i.toBar.x+(f||p<0?10:0):c.x-(f?-1:p)*v,A=w+(i.centralStart&&h?p*7:0),j=k-(O&&m!==`none`?(f?-1:p)*7:0),M=f?t.path(`M${A} ${T} h${40+w-A} v18 H${j}`,{fill:`none`,...C}):s(A,d,j,d,C);(D?x:r).push({...M,meta:{kind:`message`,from:a.id,to:c.id}});let N=(e,n)=>r.push(t.el(`circle`,{cx:e,cy:n,r:3.5,fill:_}));i.centralStart&&N(w,T),O&&N(k,E);let P=f?a.x+52:i.create?(w+k)/2:(a.x+c.x)/2,F=f?d-20-(i.lines.length-1)*8:d-i.lines.length*8-10,I=d-(i.lines.length*16+(f?28:18)),L=f?P:P-i.textW/2,R=L+i.textW,z=(i.ordinal?I:F-(i.lines.length-1)*8)-7,B=(i.lines.length?F+(i.lines.length-1)*8:I)+7;e.zenuml&&i.textW&&y.push({left:L-2,right:R+2,top:z-2,bottom:B+2}),i.textW&&S.some(e=>e.y<B&&e.y+e.h>z&&[e.x,e.x+e.w].some(e=>L-2<e&&e<R+2))&&r.push(t.rect(L-4,z,i.textW+8,B-z,{fill:n.bg,rx:n.smallRadius}));let V={kind:`message-label`,from:a.id,to:c.id};if((i.lines.length||i.icon)&&o(r,{x:P,y:F,lines:i.lines,icon:i.icon,meta:V,anchor:f?`start`:`middle`}),i.ordinal&&o(r,{x:P,y:I,lines:[i.ordinal],meta:V,anchor:f?`start`:`middle`,fill:n.fg3}),i.destroy&&(m!==`cross`||i.destroy!==c.id)){let e=b(i.destroy).x;r.push(t.path(`M${e-4} ${d-4} l8 8 m0 -8 l-8 8`,{fill:`none`,stroke:n.fg3,"stroke-width":1.5}))}}for(let s of e.actors)for(let e of[s.head,s.foot].filter(Boolean)){let c=[],l=f[s.kind],u=n[s.status];c.push(t.rect(e.x,e.y,e.w,e.h,{fill:u?t.tint(n.surface,u,.12):n.surface,stroke:u?t.frameTone(u):n.line,"stroke-width":1,rx:n.smallRadius})),s.icon?c.push(a(s.icon,s.x,e.y+16,n.fg3)):l&&c.push(t.path(l,{transform:`translate(${s.x-12} ${e.y+6})`,fill:`none`,stroke:n.fg3,"stroke-width":1.3,"stroke-linecap":`round`,"stroke-linejoin":`round`})),o(c,{x:s.x,y:e.y+e.h/2+(l||s.icon?12:0),lines:e.lines,font:i.FONT.title,lineHeight:18,fill:n.fg1,underline:!!s.link});let d={...t.el(`g`,{},c),meta:{kind:`participant`,id:s.id}};r.push(s.link?t.link(s.link.href,[d],s.link):d)}if(r.push(...x),e.zenuml){let t=[];for(let{life:{x:r,y1:i,y2:a}}of e.actors){let e=i,o=i=>{i>e&&t.push(s(r,e,r,i,{stroke:n.fg3,"stroke-width":1,"stroke-dasharray":`4 4`}))};for(let t of y)r>=t.left&&r<=t.right&&t.bottom>e&&t.top<a&&(o(t.top),e=t.bottom);o(a)}r.splice(_,0,...t)}return{width:e.width,height:e.height,children:r,title:e.title,heading:e.title}}var S={sequenceDiagram:{parse:h,layout:b,scene:x,acceptsPresentation:!0,honoredConfig:[`sequence.mirrorActors`,`sequence.showSequenceNumbers`]}};return e.LIMITS=a,e.implementations=S,e})({},KChartUnits[`core/icons`],KChartUnits[`diagram/label`],KChartUnits[`diagram/presentation`],KChartUnits[`diagram/support`]);