@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
@@ -12,10 +12,16 @@ function bind(parse, toSpec, lineFor, options) {
12
12
  ...options,
13
13
  parse,
14
14
  validate: (model, info) => validateWith(toSpec(model, info), info, (detail) => lineFor(model, detail.path)),
15
- layout: (model, options, info) => renderWith(toSpec(model, info), options, info, (detail) => lineFor(model, detail.path))
15
+ layout(model, options, info) {
16
+ const width = options.compact ? Math.min(560, Math.max(360, 290 + model.rows.length * 24)) : options.width;
17
+ return renderWith(toSpec(model, info, options.compact === true), {
18
+ ...options,
19
+ width
20
+ }, info, (detail) => lineFor(model, detail.path));
21
+ }
16
22
  };
17
23
  }
18
- var pie = bind(parsePie, (model) => ({
24
+ var pie = bind(parsePie, (model, _info, compact) => ({
19
25
  chart: "pie",
20
26
  title: model.title || void 0,
21
27
  sliceLabels: true,
@@ -27,7 +33,10 @@ var pie = bind(parsePie, (model) => ({
27
33
  category: "category",
28
34
  value: "value"
29
35
  },
30
- [compositionPresentation]: { labelRadius: model.labelRadius }
36
+ [compositionPresentation]: {
37
+ labelRadius: model.labelRadius,
38
+ ...compact ? { compact: true } : {}
39
+ }
31
40
  }), (model, path) => path === "/title" ? model.titleLine : model.rows[Number(path?.split("/")[2])]?.line || model.rows[0]?.line, {
32
41
  optionMode: "raw",
33
42
  honoredConfig: ["pie.textPosition"]
@@ -68,8 +77,19 @@ var implementations = {
68
77
  return diagnostics(validate(spec).errors, info, (detail) => treemapLine(model, detail.path));
69
78
  },
70
79
  layout(model, options, info) {
80
+ const compact = options.compact === true;
71
81
  const spec = treemapSpec(model, info), lineFor = (detail) => treemapLine(model, detail.path);
72
- const result = renderWith(spec, options, info, lineFor, treemapRegistry.layout);
82
+ if (compact) spec[compositionPresentation] = {
83
+ ...spec[compositionPresentation],
84
+ compact: true
85
+ };
86
+ const singleLeaf = model.data.children?.length === 1 && !model.data.children[0]?.children?.length;
87
+ const width = compact ? singleLeaf ? 256 : Math.min(640, 480 + Math.max(0, model.nodeCount - 1) * 10) : options.width;
88
+ const renderOptions = compact ? {
89
+ ...options,
90
+ width
91
+ } : options;
92
+ const result = renderWith(spec, renderOptions, info, lineFor, treemapRegistry.layout);
73
93
  if (result.scene && (model.nodeCount > 60 || model.depth > 5 || result.width > options.width * 2)) result.errors.push(warning("LARGE_DIAGRAM", info.lang, info.headerLine, "矩形树图较大,可滚动查看", "Large treemap; scroll to view it", "考虑拆分图表", "Consider splitting the chart"));
74
94
  return result;
75
95
  }
@@ -20,7 +20,7 @@ function validateWith(spec, info, lineFor) {
20
20
  function addVisibleHeader(scene, options) {
21
21
  if (options.renderOptions?.frame) return scene;
22
22
  const { ctx } = options;
23
- const heading = scene.heading || "";
23
+ const heading = options.embedHeading ? "" : scene.heading || "";
24
24
  const subtitle = scene.subtitle || "";
25
25
  if (!heading && !subtitle) return scene;
26
26
  const available = Math.max(24, scene.width - 32), children = [];
@@ -1,15 +1,15 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { error, warning } from "./support.js";
3
3
  import { numericLabel, renderWith, validateWith } from "./numeric-model.js";
4
- import "../chart/multivariate.js";
4
+ import { sizeBudget } from "../chart/spec.js";
5
+ import { compactNumeric } from "../chart/multivariate.js";
5
6
  // src/diagram/numeric-radar.js
6
7
  var numeric_radar_exports = /* @__PURE__ */ __exportAll({
7
8
  honoredConfig: () => honoredConfig,
8
9
  implementations: () => implementations
9
10
  });
10
11
  var limit = 24;
11
- var MIN_AXES = 3;
12
- var MAX_AXES = 6;
12
+ var MAX_AXES = 24;
13
13
  var MIN_RINGS = 2;
14
14
  var MAX_RINGS = 8;
15
15
  var DEFAULT_RINGS = 5;
@@ -253,8 +253,15 @@ function parseRadar(source, info) {
253
253
  const declaredMax = configNumber(radarConfig, "max") ?? options.max ?? null;
254
254
  const showLegend = configFlag(radarConfig, "showLegend") ?? options.showLegend ?? true;
255
255
  const graticule = String(configValue(radarConfig, "graticule") ?? options.graticule ?? "circle").toLowerCase();
256
- if (axes.length < MIN_AXES || axes.length > MAX_AXES) errors.push(issue(info, axisLine || info.firstLine, `radar 需要 ${MIN_AXES}–${MAX_AXES} 个维度,当前 ${axes.length} 个`, `Radar needs ${MIN_AXES}–${MAX_AXES} axes, got ${axes.length}`, `维度必须在 ${MIN_AXES}–${MAX_AXES} 个之间;合并维度或拆分图表`, `Keep axes between ${MIN_AXES} and ${MAX_AXES}; merge dimensions or split the chart`));
257
- if (!curves.length && !errors.length) errors.push(issue(info, info.firstLine, "radar 至少需要一条 curve", "Radar needs at least one curve"));
256
+ if (!axes.length) errors.push(issue(info, info.firstLine, "radar 至少需要一个维度", "Radar needs at least one axis", "添加 axis 语句", "Add an axis statement"));
257
+ else if (axes.length > MAX_AXES) {
258
+ errors.push(issue(info, axes[MAX_AXES].line, `radar 维度安全上限为 ${MAX_AXES} 个,当前 ${axes.length} 个`, `Radar safety cap is ${MAX_AXES} axes; got ${axes.length}`, "将维度拆分到多张雷达图", "Split the axes across multiple radar charts"));
259
+ return {
260
+ model: null,
261
+ errors
262
+ };
263
+ } else if (axes.length < 3) errors.push(hint(info, axisLine, `radar 只有 ${axes.length} 个维度,无法形成面积`, `Radar has ${axes.length} axes and cannot enclose an area`, "建议至少使用 3 个维度", "Use at least 3 axes for an area"));
264
+ if (!curves.length && !errors.some((item) => item.severity === "error")) errors.push(issue(info, info.firstLine, "radar 至少需要一条 curve", "Radar needs at least one curve"));
258
265
  if (declaredMax !== null && declaredMax <= min) errors.push(issue(info, options.line || info.firstLine, "radar max 必须大于 min", "Radar max must be greater than min"));
259
266
  const resolved = resolveCurves(info, curves, axes, errors);
260
267
  const kept = resolved.filter((curve) => {
@@ -304,6 +311,10 @@ function parseRadar(source, info) {
304
311
  function toSpec(model) {
305
312
  return {
306
313
  chart: "radar",
314
+ [sizeBudget]: {
315
+ minDimensions: 1,
316
+ maxDimensions: MAX_AXES
317
+ },
307
318
  ...model.title ? { title: model.title } : {},
308
319
  data: model.rows,
309
320
  encode: {
@@ -334,8 +345,15 @@ function lineFor(model, detail) {
334
345
  }
335
346
  var validate = (model, info) => validateWith(toSpec(model), info, (detail) => lineFor(model, detail));
336
347
  var layout = (model, options, info) => {
337
- const result = renderWith(toSpec(model), options, info, (detail) => lineFor(model, detail));
338
- if (result.scene && (model.rows.length > 12 || result.width > options.width * 2)) result.errors.push(warning("LARGE_DIAGRAM", info.lang, model.curveLines[0] || model.optionsLine, `radar 有 ${model.rows.length} 条曲线,图表较大,可滚动查看`, `The radar chart has ${model.rows.length} curves and is large; scroll to view`, "按主题拆分为多张雷达图", "Split the curves into smaller radar charts by topic"));
348
+ const width = options.compact ? Math.min(720, 440 + model.axes.length * 5) : options.width;
349
+ const renderOptions = width === options.width ? options : {
350
+ ...options,
351
+ width
352
+ };
353
+ const spec = toSpec(model);
354
+ if (options.compact === true) spec[compactNumeric] = true;
355
+ const result = renderWith(spec, renderOptions, info, (detail) => lineFor(model, detail));
356
+ if (result.scene && result.width > renderOptions.width) result.errors.push(warning("LARGE_DIAGRAM", info.lang, model.optionsLine, "雷达图超出可用宽度,可滚动查看", "The radar chart exceeds the available width; scroll to view", "缩短维度标签或拆分图表", "Shorten axis labels or split the chart"));
339
357
  return result;
340
358
  };
341
359
  var honoredConfig = Object.freeze([
@@ -2,7 +2,7 @@ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { error, warning } from "./support.js";
3
3
  import { numericLabel, renderWith, validateWith } from "./numeric-model.js";
4
4
  import { presentation } from "./presentation.js";
5
- import { sankeyPresentation } from "../chart/relations.js";
5
+ import { sankeyCompact, sankeyPresentation } from "../chart/relations.js";
6
6
  import { createRegistry, layouts } from "../chart/registry.js";
7
7
  import { sizeBudget, validate as validate$1 } from "../chart/spec.js";
8
8
  // src/diagram/numeric-sankey.js
@@ -124,11 +124,12 @@ function unitOf(info) {
124
124
  const [pre, post] = [text(prefix), text(suffix)];
125
125
  return /^[\p{L}\p{Sc}%‰°]*\p{Sc}?[\p{L}\p{Sc}%‰°]*$/u.test(`${pre}${post}`) && `${pre}${post}` ? `${pre}${post}` : void 0;
126
126
  }
127
- function toSpec(model) {
127
+ function toSpec(model, compact = false) {
128
128
  return {
129
129
  chart: "sankey",
130
130
  tolerant: true,
131
131
  [sankeyPresentation]: true,
132
+ ...compact ? { [sankeyCompact]: true } : {},
132
133
  [sizeBudget]: {
133
134
  nodes: MAX_NODES,
134
135
  edges: MAX_EDGES
@@ -181,7 +182,7 @@ function validate(model, info) {
181
182
  var sankeyRegistry = createRegistry(validate$1);
182
183
  sankeyRegistry.register("sankey", layouts.get("sankey"));
183
184
  var layout = (model, options, info) => {
184
- const result = renderWith(toSpec(model), options, info, (detail) => lineFor(model, detail), sankeyRegistry.layout);
185
+ const result = renderWith(toSpec(model, options.compact === true), options, info, (detail) => lineFor(model, detail), sankeyRegistry.layout);
185
186
  if (result.scene && (result.width > options.width * 2 || model.nodes.length > LARGE_NODES || model.edges.length > LARGE_EDGES)) result.errors.push(warning("LARGE_DIAGRAM", info.lang, info.headerLine, "桑基图较大,可滚动查看", "Large Sankey diagram; scroll to view it", "考虑拆分图表", "Consider splitting the diagram"));
186
187
  return result;
187
188
  };
@@ -2,7 +2,7 @@ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { error, warning } from "./support.js";
3
3
  import { numericLabel, renderWith, validateWith } from "./numeric-model.js";
4
4
  import { diagramLine } from "../chart/basic.js";
5
- import { diagramCombo } from "../chart/multivariate.js";
5
+ import { compactNumeric, diagramCombo } from "../chart/multivariate.js";
6
6
  // src/diagram/numeric-xy.js
7
7
  var numeric_xy_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
8
8
  var NUMBER = "[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)";
@@ -296,7 +296,7 @@ function parseXychart(source, info) {
296
296
  errors
297
297
  };
298
298
  }
299
- function specOf(model, info) {
299
+ function specOf(model, info, panelIndex = 0) {
300
300
  const en = isEnglish(info?.lang);
301
301
  const subtitle = [model.xLabel, model.yLabel].filter(Boolean).join(" · ") || void 0;
302
302
  const domain = model.yDomain ? { domain: model.yDomain } : {};
@@ -304,7 +304,7 @@ function specOf(model, info) {
304
304
  const data = model.categories.map((category, index) => Object.fromEntries([["category", category], ...model.datasets.map((dataset, series) => [`v${series}`, dataset.values[index]])]));
305
305
  return {
306
306
  chart: "combo",
307
- [diagramCombo]: true,
307
+ [diagramCombo]: { index: panelIndex },
308
308
  ...model.title ? { title: model.title } : {},
309
309
  ...subtitle ? { subtitle } : {},
310
310
  data,
@@ -391,7 +391,17 @@ function panelsOf(model, info) {
391
391
  }
392
392
  var validate = (model, info) => panelsOf(model, info).flatMap((panel) => validateWith(specOf(panel, info), info, (detail) => lineFor(panel, detail)));
393
393
  var layout = (model, options, info) => {
394
- const results = panelsOf(model, info).map((panel) => renderWith(specOf(panel, info), options, info, (detail) => lineFor(panel, detail)));
394
+ const panels = panelsOf(model, info);
395
+ const width = options.compact ? Math.min(720, Math.max(360, 180 + model.categories.length * 52)) : options.width;
396
+ const renderOptions = width === options.width ? options : {
397
+ ...options,
398
+ width
399
+ };
400
+ const results = panels.map((panel, index) => {
401
+ const spec = specOf(panel, info, index);
402
+ if (options.compact === true) spec[compactNumeric] = true;
403
+ return renderWith(spec, renderOptions, info, (detail) => lineFor(panel, detail));
404
+ });
395
405
  if (results.some((result) => !result.scene)) return results.find((result) => !result.scene);
396
406
  const result = results[0];
397
407
  if (results.length > 1) {
@@ -83,7 +83,7 @@ function parse(body, { lang, firstLine = 2, title = "", config, options = {} })
83
83
  errors
84
84
  };
85
85
  }
86
- function layout(model, { width, ctx, renderOptions }, info = {}) {
86
+ function layout(model, { width, ctx, renderOptions, compact, embedHeading }, info = {}) {
87
87
  const { title, fields, config } = model, t = appearance(ctx);
88
88
  const perRow = Number.isInteger(config.bitsPerRow) && config.bitsPerRow >= 1 && config.bitsPerRow <= 128 ? config.bitsPerRow : 32;
89
89
  const showBits = config.showBits !== false, descending = config.bitOrder === "descending";
@@ -106,11 +106,11 @@ function layout(model, { width, ctx, renderOptions }, info = {}) {
106
106
  const minimumRow = dimension("rowHeight", 34, 26, 240);
107
107
  const pad = 18, range = (f) => f.start === f.end ? String(f.start) : `${f.start}–${f.end}`;
108
108
  const needed = Math.ceil(rows.flat().reduce((min, f) => Math.max(min, ...f.label.split(/\s+/).map((word) => (ctx.measure(word, FONT.body.size) + 10 + gap) / f.bits), showBits ? (ctx.measure(range(f), FONT.label.size) + 6) / f.bits : 0), 12));
109
- const pitch = Math.max(needed, Math.floor((width - 36) / perRow), dimension("bitWidth", 12, 12, 96));
110
- const w = Math.max(width, perRow * pitch + 36), left = (w - perRow * pitch) / 2;
109
+ const pitch = Math.max(needed, compact ? 0 : Math.floor((width - 36) / perRow), dimension("bitWidth", 12, 12, 96));
110
+ const w = Math.max(compact ? 0 : width, perRow * pitch + 36), left = (w - perRow * pitch) / 2;
111
111
  const children = [];
112
112
  let y = pad;
113
- if (title && !renderOptions?.frame) {
113
+ if (title && !renderOptions?.frame && !embedHeading) {
114
114
  children.push(ctx.text(w / 2, y + 8, title, {
115
115
  ...FONT.title,
116
116
  anchor: "middle",
@@ -136,12 +136,12 @@ function parse(body, { lang, title = "", firstLine = 2, config, options = {} })
136
136
  errors
137
137
  };
138
138
  }
139
- function layout(model, { ctx, width, renderOptions }, info = {}) {
139
+ function layout(model, { ctx, width, renderOptions, compact = false, embedHeading }, info = {}) {
140
140
  const { title, captions, axes, points, config } = model, t = appearance(ctx);
141
141
  const dimension = (key, fallback, min, max) => Number.isFinite(config[key]) ? Math.min(max, Math.max(min, config[key])) : fallback;
142
142
  const size = dimension("pointLabelFontSize", 12, 12, 24);
143
143
  const r = dimension("pointRadius", 5, 3, 12);
144
- const titleInline = title && !renderOptions?.frame;
144
+ const titleInline = title && !renderOptions?.frame && !embedHeading;
145
145
  const xTop = config.xAxisPosition ? config.xAxisPosition === "top" : !points.length;
146
146
  const yRight = config.yAxisPosition === "right";
147
147
  const centered = {
@@ -158,8 +158,11 @@ function layout(model, { ctx, width, renderOptions }, info = {}) {
158
158
  const top = pad + (titleInline ? 32 : 0) + (xTop && axes.x ? xRoom : 0);
159
159
  const left = pad + (!yRight && axes.y ? yRoom : 0);
160
160
  const right = pad + (yRight && axes.y ? yRoom : 0);
161
- const span = Math.max(Math.min(520, width - left - right), 360, dimension("chartWidth", 0, 0, 4e3), spanOf(axes.x), ...captions.map((s) => 2 * W(s, FONT.title) + 44).filter(Number.isFinite));
162
- const h = Math.max(340, spanOf(axes.y), dimension("chartHeight", 0, 0, 4e3));
161
+ const compactSpan = Math.min(440, 360 + Math.min(80, points.length * 2));
162
+ const span = Math.max(compact ? compactSpan : Math.min(520, width - left - right), compact ? 0 : 360, dimension("chartWidth", 0, 0, 4e3), spanOf(axes.x), ...captions.map((s) => 2 * W(s, FONT.title) + 44).filter(Number.isFinite));
163
+ const upright = (text) => /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u.test(text);
164
+ const ySpan = (axes.y || []).reduce((sum, text) => sum + (upright(text) ? Array.from(text).length * 14 : W(text)), 36);
165
+ const h = Math.max(340, ySpan, dimension("chartHeight", 0, 0, 4e3));
163
166
  const w = left + span + right, bottom = top + h;
164
167
  const children = [], occupied = [];
165
168
  const pushText = (x, y, value, font = FONT.label, fill = t.fg1, attrs = {}) => {
@@ -225,7 +228,11 @@ function layout(model, { ctx, width, renderOptions }, info = {}) {
225
228
  top,
226
229
  "end"
227
230
  ]].forEach(([text, y, anchor]) => {
228
- pushText(x, y, text, FONT.label, t.fg2, {
231
+ if (upright(text)) {
232
+ const lines = Array.from(text);
233
+ const firstY = anchor === "end" ? y + 7 : y - lines.length * 14 + 7;
234
+ lines.forEach((line, i) => pushText(x, firstY + i * 14, line, FONT.label, t.fg2));
235
+ } else pushText(x, y, text, FONT.label, t.fg2, {
229
236
  anchor,
230
237
  transform: `rotate(-90 ${x} ${y})`
231
238
  });
@@ -117,11 +117,21 @@ function reader(body, info, dialect, look, assets) {
117
117
  token = void 0;
118
118
  return next;
119
119
  }
120
- function expect(kind, code = "unexpected-token") {
120
+ function expect(kind, code = "unexpected-token", ruleName) {
121
121
  const next = take(kind);
122
122
  if (next) return next;
123
123
  if (["\"", "'"].includes(peek().kind) && !(abnf && peek().kind === "'")) fail("unterminated-string", "字符串未闭合", "Unterminated string", "添加对应的结束引号", "Add the matching closing quote");
124
- fail(code, `应为「${kind}」`, `Expected ${kind}`, `在此处使用「${kind}」`, `Use ${kind} here`);
124
+ if (ruleName !== void 0) {
125
+ const example = dialect === "ir" ? "item = terminal(\"x\");" : `item ${kind} "x";`;
126
+ const operator = dialect === "ebnf" ? "= 或 ::=" : kind;
127
+ const operatorEn = dialect === "ebnf" ? "= or ::=" : kind;
128
+ const title = ruleName === "diagram-title" && peek().kind === ":";
129
+ fail(code, `规则名后应为 ${operator}`, `Expected ${operatorEn} after the rule name`, title ? `标题请写 title 标题;规则请写成 ${example}` : `在规则名后使用 ${operator},例如 ${example}`, title ? `Write titles as title My Grammar; write rules as ${example}` : `Use ${operatorEn} after the rule name, as in ${example}`);
130
+ }
131
+ if (kind === "id") fail(code, "此处需要名称", "Expected a name", "使用字母开头的规则名或构造器名,例如 item", "Use a rule or constructor name starting with a letter, such as item");
132
+ if (kind === "string") fail(code, "此处需要带引号的字符串", "Expected a quoted string", "用双引号包住文字,例如 \"x\"", "Enclose the text in double quotes, as in \"x\"");
133
+ if (kind === ";") fail(code, "规则末尾缺少分号", "Expected ; at the end of the rule", "在规则表达式结束处加分号 ;", "End the rule expression with a semicolon (;)");
134
+ fail(code, `此处应为「${kind}」`, `Expected ${kind}`, `在此处补上「${kind}」`, `Insert ${kind} here`);
125
135
  }
126
136
  function checkDepth(depth) {
127
137
  if (depth > DEPTH) fail("depth-limit", "语法轨道嵌套过深", "Railroad nesting is too deep", "将嵌套部分提取为规则", "Extract nested expressions into rules");
@@ -230,13 +240,13 @@ function expression(r, dialect, hints) {
230
240
  "?",
231
241
  "'",
232
242
  "{"
233
- ].includes(kind)) r.fail("abnf-unsupported", "此写法不属于 ABNF", "This syntax is not ABNF", "使用 /、双引号和前置重复次数", "Use /, double quotes and a repeat prefix");
243
+ ].includes(kind)) r.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\"");
234
244
  if (peg && [
235
245
  "[",
236
246
  "{",
237
247
  "-",
238
248
  "|"
239
- ].includes(kind)) r.fail("peg-unsupported", "此写法不属于 PEG", "This syntax is not PEG", "使用 /、圆括号和后置 ?、*、+", "Use /, parentheses and postfix ?, *, +");
249
+ ].includes(kind)) r.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\")+");
240
250
  }
241
251
  function factor(depth) {
242
252
  const start = r.peek();
@@ -246,7 +256,7 @@ function expression(r, dialect, hints) {
246
256
  if (count) {
247
257
  const [lo, hi] = count.value.split("*");
248
258
  const min = Number(lo), max = hi === void 0 ? min : hi === "" ? Infinity : Number(hi);
249
- if (!Number.isSafeInteger(min) || max !== Infinity && !Number.isSafeInteger(max) || min > max) r.fail("abnf-bad-repeat", "无效的 ABNF 重复次数", "Invalid ABNF repetition bounds", "使用递增的整数范围", "Use an ascending integer range", count);
259
+ if (!Number.isSafeInteger(min) || max !== Infinity && !Number.isSafeInteger(max) || min > max) r.fail("abnf-bad-repeat", "无效的 ABNF 重复次数", "Invalid ABNF repetition bounds", "先写最小次数,再写最大次数,例如 2*4\"x\"", "Put the minimum before the maximum, as in 2*4\"x\"", count);
250
260
  node = min === 0 && max === 1 ? optional(node) : repetition(node, min, max);
251
261
  }
252
262
  if (ebnf || peg) {
@@ -306,7 +316,7 @@ function irExpression(r, depth = 1) {
306
316
  const build = constructors.get(name.value);
307
317
  if (!build) r.fail("ir-unknown-constructor", `未知构造器「${name.value}」`, `Unknown constructor ${name.value}`, `使用 ${[...constructors.keys()].join("、")}`, `Use ${[...constructors.keys()].join(", ")}`, name);
308
318
  r.expect("(");
309
- if (r.peek().kind === ")") r.fail("ir-arity", "构造器缺少参数", "Constructor has no arguments", "添加构造器参数", "Add a constructor argument");
319
+ if (r.peek().kind === ")") r.fail("ir-arity", "构造器缺少参数", "Constructor has no arguments", "添加参数,例如 terminal(\"x\") 或 optional(terminal(\"x\"))", "Add an argument, as in terminal(\"x\") or optional(terminal(\"x\"))");
310
320
  let node;
311
321
  if ([
312
322
  "terminal",
@@ -358,7 +368,7 @@ function parseRules(body, info, dialect) {
358
368
  const abnf = dialect === "abnf";
359
369
  const key = (name) => abnf ? name.toLowerCase() : name;
360
370
  try {
361
- if (body.length > 2e5) r.fail("source-limit", "语法文本过长", "Railroad source is too large", "拆分语法图", "Split the grammar into diagrams");
371
+ if (body.length > 2e5) r.fail("source-limit", "语法文本过长", "Railroad source is too long", "按规则拆分,每张图最多 200,000 个字符", "Split by rule into diagrams of at most 200,000 characters");
362
372
  while (r.peek().kind !== "end") {
363
373
  if (r.presentationLine()) continue;
364
374
  if (abnf && r.take(";")) {
@@ -386,15 +396,15 @@ function parseRules(body, info, dialect) {
386
396
  line: name.line,
387
397
  column: name.column
388
398
  }, name.value, name);
389
- if (dialect === "peg") r.expect("<-", "peg-bad-operator");
390
- else if (!(dialect === "ebnf" && r.take("::="))) r.expect("=");
399
+ if (dialect === "peg") r.expect("<-", "peg-bad-operator", name.value);
400
+ else if (!(dialect === "ebnf" && r.take("::="))) r.expect("=", "unexpected-token", name.value);
391
401
  const definition = dialect === "ir" ? irExpression(r) : expression(r, dialect, hints);
392
402
  r.expect(";", "rule-expected");
393
403
  if (abnf) r.commentTail();
394
404
  const stack = [[definition, 1]];
395
405
  while (stack.length) {
396
406
  const [node, depth] = stack.pop();
397
- if (++count > CAP) r.fail("node-limit", "语法图节点过多", "Too many railroad nodes", "拆分语法图", "Split the grammar into diagrams", name);
407
+ if (++count > CAP) r.fail("node-limit", "语法图节点过多", `Too many railroad nodes (limit ${CAP})`, `按规则拆分,每张图最多 ${CAP} 个节点`, `Split by rule into diagrams of at most ${CAP} nodes`, name);
398
408
  if (depth > DEPTH) r.fail("depth-limit", "语法轨道嵌套过深", "Railroad nesting is too deep", "将嵌套部分提取为规则", "Extract nested expressions into rules", name);
399
409
  for (const child of childrenOf(node)) stack.push([child, depth + 1]);
400
410
  }
@@ -261,7 +261,7 @@ function layout(model, { width, ctx, measure, lang, renderOptions }, info) {
261
261
  natural = Math.max(natural, end + marker + pad);
262
262
  y = baseline + t.down + gap + 14;
263
263
  }
264
- const errors = natural > 2 * width || model.count > 60 ? [warning("LARGE_DIAGRAM", lang, info.headerLine, "语法图较大,可在图框中滚动", "Large grammar; scroll inside the frame", "考虑拆分规则", "Consider splitting the rules")] : [];
264
+ const errors = natural > 2 * width || model.count > 60 ? [warning("LARGE_DIAGRAM", lang, info.headerLine, "语法图较大,可在图框中滚动", "Large syntax diagram; scroll inside the frame", "将完整规则分到多张图;把过长的表达式提取为命名规则", "Split whole rules across diagrams; extract long expressions into named rules")] : [];
265
265
  return {
266
266
  scene: {
267
267
  width: natural,
@@ -2,8 +2,9 @@ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { ignoredConfigWarning, inferLang, parseOptions, prepareSource, siteConfig } from "./source.js";
3
3
  import { blocking, error, measureOf } from "./support.js";
4
4
  import { createContext } from "../core/context.js";
5
- import { containText, el } from "../core/scene.js";
5
+ import { containText, cropInk, el } from "../core/scene.js";
6
6
  import { renderScene } from "../core/svg.js";
7
+ import { wrapText } from "../core/text.js";
7
8
  import { ExpectedDiagnostic } from "../core/diagnostics.js";
8
9
  // src/diagram/registry.js
9
10
  var registry_exports = /* @__PURE__ */ __exportAll({ createDiagramApi: () => createDiagramApi });
@@ -159,7 +160,10 @@ function createDiagramApi(implementations, types) {
159
160
  diagnostics: preparedDiagnostics
160
161
  };
161
162
  const shown = prepared.kind || prepared.body.trim().split(/\s+/)[0].slice(0, 40) || syntax;
162
- const unknown = error(options.lang, headerLineOf(prepared), `未知结构图类型「${shown}」`, `Unknown diagram type "${shown}"`, "使用已声明的结构图类型", "Use a supported diagram type");
163
+ const near = rawKind.endsWith("-beta") ? rawKind.slice(0, -5) : `${rawKind}-beta`;
164
+ const candidate = syntax === "mermaid" && rawKind && byAlias.get(near);
165
+ const keyword = candidate?.syntax === "mermaid" && [candidate.kind, ...candidate.aliases].find((alias) => alias.toLowerCase() === near);
166
+ const unknown = error(options.lang, headerLineOf(prepared), `未知结构图类型「${shown}」`, `Unknown diagram type "${shown}"`, keyword ? `将头行关键字改为「${keyword}」` : "使用已声明的结构图类型", keyword ? `Use "${keyword}" as the header keyword` : "Use a supported diagram type");
163
167
  return {
164
168
  info,
165
169
  type: null,
@@ -230,9 +234,12 @@ function createDiagramApi(implementations, types) {
230
234
  const implementation = implementations[parsed.type.kind];
231
235
  if (typeof implementation.layout !== "function") throw new TypeError(`Missing layout for diagram: ${parsed.type.kind}`);
232
236
  const width = Math.max(1, Number(options.width) || 800);
237
+ const compact = options.compact === true;
238
+ const layoutWidth = compact ? Math.min(width, 720) : width;
233
239
  const ctx = createContext({
234
240
  ...options,
235
- width,
241
+ width: layoutWidth,
242
+ compact,
236
243
  lang: parsed.info.lang
237
244
  });
238
245
  const measure = measureOf(ctx);
@@ -240,12 +247,20 @@ function createDiagramApi(implementations, types) {
240
247
  ...options,
241
248
  frame: options.frame ?? true
242
249
  };
250
+ const embedHeading = renderOptions.frame === false;
251
+ const sharedHeading = compact && embedHeading;
252
+ const layoutOptions = sharedHeading ? {
253
+ ...renderOptions,
254
+ frame: true
255
+ } : renderOptions;
243
256
  const geometry = implementation.layout(parsed.model, {
244
- width,
257
+ width: layoutWidth,
258
+ compact,
259
+ embedHeading,
245
260
  lang: ctx.lang,
246
261
  measure,
247
262
  ctx,
248
- renderOptions
263
+ renderOptions: layoutOptions
249
264
  }, parsed.info);
250
265
  const diagnostics = merge(parsed.diagnostics, normalize(geometry?.errors, parsed.type));
251
266
  if (diagnostics.some(blocking)) return {
@@ -255,8 +270,31 @@ function createDiagramApi(implementations, types) {
255
270
  };
256
271
  const laid = geometry?.scene || (typeof implementation.scene === "function" ? implementation.scene(geometry, ctx, parsed.info) : null);
257
272
  if (!laid || !Number.isFinite(laid.width) || !Number.isFinite(laid.height) || !Array.isArray(laid.children)) throw new TypeError(`Invalid scene for diagram: ${parsed.type.kind}`);
258
- const contained = containText(laid, ctx.measure, { blockPadding: 4 });
259
- const sceneWidth = Math.max(width, contained.width);
273
+ const heading = parsed.info.title || laid.heading;
274
+ const header = [];
275
+ if (sharedHeading && (heading || laid.subtitle)) {
276
+ const wrap = (value, size, weight) => wrapText(value, Math.max(14, layoutWidth - 4), ctx.font(size, weight), (text, font) => ctx.measureInk(text, font.size, font.weight), { bounded: true });
277
+ const lines = heading ? wrap(heading, 16, 650) : [];
278
+ if (lines.length) header.push(ctx.textLines(0, 0, lines, {
279
+ size: 16,
280
+ weight: 650,
281
+ leading: 22,
282
+ fill: ctx.color("fg"),
283
+ meta: { kind: "diagram-title" }
284
+ }));
285
+ if (laid.subtitle) header.push(ctx.textLines(0, lines.length * 22, wrap(laid.subtitle, 12, 400), {
286
+ size: 12,
287
+ weight: 400,
288
+ leading: 18,
289
+ fill: ctx.color("muted")
290
+ }));
291
+ }
292
+ const headingNode = header.length ? el("g", {}, header) : null;
293
+ const contained = compact ? cropInk(laid, sharedHeading ? ctx.measureInk : ctx.measureRendered, {
294
+ fullText: sharedHeading,
295
+ heading: headingNode
296
+ }) : containText(laid, ctx.measure, { blockPadding: 4 });
297
+ const sceneWidth = compact ? contained.width : Math.max(width, contained.width);
260
298
  const offset = Math.max(0, (sceneWidth - contained.width) / 2);
261
299
  const children = offset ? [el("g", { transform: `translate(${offset} 0)` }, contained.children)] : contained.children;
262
300
  const anchor = contained.anchor ? {
@@ -271,7 +309,7 @@ function createDiagramApi(implementations, types) {
271
309
  ...anchor ? { anchor } : {},
272
310
  title,
273
311
  ...parsed.info.accDescr !== void 0 ? { description: parsed.info.accDescr } : {},
274
- heading: parsed.info.title || contained.heading
312
+ heading
275
313
  };
276
314
  return {
277
315
  svg: renderScene(scene, renderOptions),
@@ -475,7 +475,7 @@ var ICON_SPACE = 20;
475
475
  var MESSAGE_PADDING = 36;
476
476
  var MESSAGE_END_GAP = 12;
477
477
  var iconSpace = (item) => item.icon ? ICON_SPACE : 0;
478
- function layout(model, { measure, width, lang }, info = {}) {
478
+ function layout(model, { measure, width, lang, compact }, info = {}) {
479
479
  const config = info.config?.sequence;
480
480
  const mirrorActors = config?.mirrorActors !== false;
481
481
  const errors = [];
@@ -768,7 +768,7 @@ function layout(model, { measure, width, lang }, info = {}) {
768
768
  };
769
769
  let xs = xsOf();
770
770
  let geometry = geometryOf(xs);
771
- for (let pass = 0; pass < 4; pass += 1) {
771
+ for (let pass = 0; !compact && pass < 4; pass += 1) {
772
772
  const slack = Math.floor(width) - 16 - (geometry.right - geometry.left);
773
773
  if (slack < 1) break;
774
774
  const add = Math.min(slack / (count + 1), 128);
@@ -855,7 +855,17 @@ function layout(model, { measure, width, lang }, info = {}) {
855
855
  if (event.deactivateOn && event.destroy !== event.deactivateOn) stop(event.deactivateOn, y + 8);
856
856
  if (event.destroy) while (active.get(event.destroy).length) stop(event.destroy, y, 0);
857
857
  }
858
- const barsByX = [...activations].sort((a, b) => a.x - b.x);
858
+ const labelObstacles = [...activations];
859
+ if (model.zenuml) for (const actor of actors) {
860
+ const created = creations.get(actor.id);
861
+ const y = created == null ? top - 4 : created + actor.head.h / 2;
862
+ labelObstacles.push({
863
+ x: actor.x - 1,
864
+ y,
865
+ h: bottom - y
866
+ });
867
+ }
868
+ const barsByX = labelObstacles.sort((a, b) => a.x - b.x);
859
869
  const labelXOf = (box, y, width) => {
860
870
  let x = box.x + 8;
861
871
  for (const bar of barsByX) {
@@ -901,7 +911,7 @@ function layout(model, { measure, width, lang }, info = {}) {
901
911
  for (const bar of active.get(actor.id)) bar.h = Math.max(0, actor.life.y2 - bar.y);
902
912
  }
903
913
  const naturalWidth = snap(contentRight + 8);
904
- const canvas = naturalWidth <= width ? Math.floor(width) : naturalWidth;
914
+ const canvas = !compact && naturalWidth <= width ? Math.floor(width) : naturalWidth;
905
915
  if (naturalWidth > width * 2 || actors.length > 60 || model.messages > 200) errors.push(warning("LARGE_DIAGRAM", lang, actors[0].line, "时序图较大,可滚动查看", "Large sequence diagram; scroll to view it", "可将时序图拆分", "Consider splitting the diagram"));
906
916
  return {
907
917
  type: "sequence",
@@ -911,7 +921,8 @@ function layout(model, { measure, width, lang }, info = {}) {
911
921
  events,
912
922
  activations,
913
923
  errors,
914
- title: model.title
924
+ title: model.title,
925
+ ...model.zenuml ? { zenuml: true } : {}
915
926
  };
916
927
  }
917
928
  function scene(layout, ctx) {
@@ -1042,7 +1053,8 @@ function scene(layout, ctx) {
1042
1053
  });
1043
1054
  };
1044
1055
  for (const event of layout.events) if (event.kind === "open") paintFrame(event);
1045
- for (const actor of layout.actors) children.push(line(actor.life.x, actor.life.y1, actor.life.x, actor.life.y2, {
1056
+ const lifelineIndex = children.length, labelGaps = [];
1057
+ if (!layout.zenuml) for (const actor of layout.actors) children.push(line(actor.life.x, actor.life.y1, actor.life.x, actor.life.y2, {
1046
1058
  stroke: theme.line2,
1047
1059
  "stroke-width": 1
1048
1060
  }));
@@ -1138,6 +1150,12 @@ function scene(layout, ctx) {
1138
1150
  const labelRight = labelLeft + event.textW;
1139
1151
  const labelTop = (event.ordinal ? ordinalY : labelY - (event.lines.length - 1) * 8) - 7;
1140
1152
  const labelBottom = (event.lines.length ? labelY + (event.lines.length - 1) * 8 : ordinalY) + 7;
1153
+ if (layout.zenuml && event.textW) labelGaps.push({
1154
+ left: labelLeft - 2,
1155
+ right: labelRight + 2,
1156
+ top: labelTop - 2,
1157
+ bottom: labelBottom + 2
1158
+ });
1141
1159
  if (event.textW && boxes.some((box) => box.y < labelBottom && box.y + box.h > labelTop && [box.x, box.x + box.w].some((edge) => labelLeft - 2 < edge && edge < labelRight + 2))) children.push(ctx.rect(labelLeft - 4, labelTop, event.textW + 8, labelBottom - labelTop, {
1142
1160
  fill: theme.bg,
1143
1161
  rx: theme.smallRadius
@@ -1210,6 +1228,25 @@ function scene(layout, ctx) {
1210
1228
  children.push(actor.link ? ctx.link(actor.link.href, [card], actor.link) : card);
1211
1229
  }
1212
1230
  children.push(...creationRoutes);
1231
+ if (layout.zenuml) {
1232
+ const lifelines = [];
1233
+ for (const { life: { x, y1, y2 } } of layout.actors) {
1234
+ let start = y1;
1235
+ const segment = (end) => {
1236
+ if (end > start) lifelines.push(line(x, start, x, end, {
1237
+ stroke: theme.fg3,
1238
+ "stroke-width": 1,
1239
+ "stroke-dasharray": "4 4"
1240
+ }));
1241
+ };
1242
+ for (const gap of labelGaps) if (x >= gap.left && x <= gap.right && gap.bottom > start && gap.top < y2) {
1243
+ segment(gap.top);
1244
+ start = gap.bottom;
1245
+ }
1246
+ segment(y2);
1247
+ }
1248
+ children.splice(lifelineIndex, 0, ...lifelines);
1249
+ }
1213
1250
  return {
1214
1251
  width: layout.width,
1215
1252
  height: layout.height,
@@ -318,7 +318,7 @@ function findCycle(runs, orders) {
318
318
  }
319
319
  return cycle;
320
320
  }
321
- function layout(model, { measure, width, lang }) {
321
+ function layout(model, { measure, width, lang, compact }) {
322
322
  const horizontal = model.direction === "LR";
323
323
  const crossOf = (node) => horizontal ? node.h : node.w;
324
324
  const alongOf = (node) => horizontal ? node.w : node.h;
@@ -842,7 +842,7 @@ function layout(model, { measure, width, lang }) {
842
842
  return alongCursor;
843
843
  });
844
844
  const alongTotal = alongAt[maxStep] + steps[maxStep] + (bandTracks.has(maxStep) ? bands[maxStep] : 0);
845
- const canvasW = horizontal ? Math.max(snap(width), alongTotal) : crossTotal;
845
+ const canvasW = horizontal ? Math.max(compact ? 0 : snap(width), alongTotal) : crossTotal;
846
846
  const canvasH = horizontal ? crossTotal : alongTotal;
847
847
  const bandStart = (band) => alongAt[band] + steps[band];
848
848
  const trackAt = (band, track) => bandStart(band) + CLEAR + track * TRACK;
@@ -403,8 +403,8 @@ var text = (ctx, value, x, y, size = 13, fill = ctx.color("ink"), anchor = "star
403
403
  "dominant-baseline": "middle"
404
404
  });
405
405
  var wrap = (ctx, value, width, size) => ctx.wrap(String(value), Math.max(size, width), size, 400);
406
- function layout(model, { measure, width, ctx, renderOptions }) {
407
- const inSceneTitle = !renderOptions?.frame && Boolean(model.title);
406
+ function layout(model, { measure, width, ctx, renderOptions, embedHeading }) {
407
+ const inSceneTitle = !renderOptions?.frame && !embedHeading && Boolean(model.title);
408
408
  const headRow = ["gantt", "journey"].includes(model.type) ? 14 : 0;
409
409
  const right = 24, top = renderOptions?.frame ? 54 : (inSceneTitle ? 54 : 24) + headRow, rowH = 54;
410
410
  const FLAG = /^en\b/i.test(ctx.lang || "zh") ? {
@@ -469,7 +469,7 @@ function layout(model, { measure, width, ctx, renderOptions }) {
469
469
  "stroke-width": sw
470
470
  }));
471
471
  if (inSceneTitle) label(model.title, 22, 24, 17, colors.ink, "start", 650);
472
- else if (renderOptions?.frame) scene.heading = model.title || void 0;
472
+ else if (renderOptions?.frame || embedHeading) scene.heading = model.title || void 0;
473
473
  if (model.type === "gantt") {
474
474
  const headerH = 30, rows = [];
475
475
  let section;