jpfun 0.8.0 → 1.0.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 (140) hide show
  1. package/README.md +10 -15
  2. package/dist/diagnostic.d.ts +29 -2
  3. package/dist/diagnostic.js +5 -4
  4. package/dist/functions/ASTtypes.d.ts +1 -14
  5. package/dist/functions/ASTtypes.js +5 -36
  6. package/dist/functions/adjust/index.js +45 -33
  7. package/dist/functions/arpeggio/index.js +44 -48
  8. package/dist/functions/arpeggio/shape.d.ts +2 -3
  9. package/dist/functions/arpeggio/shape.js +20 -50
  10. package/dist/functions/bar/index.d.ts +3 -0
  11. package/dist/functions/bar/index.js +21 -11
  12. package/dist/functions/beam/auto.js +54 -123
  13. package/dist/functions/beam/index.js +4 -9
  14. package/dist/functions/beam/layout.js +3 -2
  15. package/dist/functions/box/index.js +1 -6
  16. package/dist/functions/dash/index.js +6 -4
  17. package/dist/functions/div/index.d.ts +3 -5
  18. package/dist/functions/div/index.js +14 -12
  19. package/dist/functions/dot/index.js +3 -9
  20. package/dist/functions/dyn/index.js +7 -26
  21. package/dist/functions/gliss/index.js +99 -91
  22. package/dist/functions/grace/index.d.ts +2 -5
  23. package/dist/functions/grace/index.js +47 -94
  24. package/dist/functions/head/index.js +32 -36
  25. package/dist/functions/key/index.js +9 -12
  26. package/dist/functions/meter/index.d.ts +1 -0
  27. package/dist/functions/meter/index.js +6 -3
  28. package/dist/functions/meter/shape.d.ts +1 -1
  29. package/dist/functions/note/accidentals.d.ts +3 -3
  30. package/dist/functions/note/accidentals.js +29 -16
  31. package/dist/functions/note/index.js +12 -14
  32. package/dist/functions/note/source-transform.d.ts +15 -0
  33. package/dist/functions/note/source-transform.js +75 -71
  34. package/dist/functions/ottava/index.js +12 -32
  35. package/dist/functions/page/index.js +15 -17
  36. package/dist/functions/rest/index.js +10 -10
  37. package/dist/functions/slide/index.js +1 -1
  38. package/dist/functions/stack/index.js +8 -57
  39. package/dist/functions/temporal.d.ts +11 -5
  40. package/dist/functions/temporal.js +22 -2
  41. package/dist/functions/text/index.js +24 -30
  42. package/dist/functions/tie/index.js +42 -41
  43. package/dist/functions/tremolo/index.js +1 -1
  44. package/dist/functions/tuplet/index.js +1 -6
  45. package/dist/functions/up/index.js +82 -88
  46. package/dist/functions/voice/connections.d.ts +3 -2
  47. package/dist/functions/voice/connections.js +48 -10
  48. package/dist/functions/voice/index.d.ts +2 -3
  49. package/dist/functions/voice/index.js +2 -970
  50. package/dist/functions/voice/lyrics.d.ts +34 -0
  51. package/dist/functions/voice/lyrics.js +393 -0
  52. package/dist/functions/voice/voice.d.ts +67 -0
  53. package/dist/functions/voice/voice.js +405 -0
  54. package/dist/functions/voice/voices.d.ts +106 -0
  55. package/dist/functions/voice/voices.js +424 -0
  56. package/dist/functions/volta/index.js +6 -23
  57. package/dist/index.d.ts +97 -3
  58. package/dist/index.js +97 -3
  59. package/dist/jpfun.min.js +63 -67
  60. package/dist/layout/engine.d.ts +4 -3
  61. package/dist/layout/engine.js +190 -24
  62. package/dist/layout/model.d.ts +12 -4
  63. package/dist/layout/model.js +16 -11
  64. package/dist/layout/page.d.ts +2 -1
  65. package/dist/layout/page.js +15 -15
  66. package/dist/layout/path.js +1 -1
  67. package/dist/layout/range.d.ts +7 -6
  68. package/dist/layout/range.js +23 -14
  69. package/dist/layout/types.d.ts +19 -30
  70. package/dist/lowering/loweringContext.d.ts +8 -11
  71. package/dist/lowering/loweringContext.js +7 -13
  72. package/dist/lowering/track.d.ts +8 -1
  73. package/dist/lowering/types.d.ts +12 -8
  74. package/dist/parser/grammarType.d.ts +3 -3
  75. package/dist/parser/parse-utils/brace-utils.js +7 -17
  76. package/dist/parser/parse-utils/call-utils.d.ts +4 -3
  77. package/dist/parser/parse-utils/call-utils.js +23 -66
  78. package/dist/parser/parse-utils/note-utils.d.ts +7 -3
  79. package/dist/parser/parse-utils/note-utils.js +25 -40
  80. package/dist/parser/parse-utils/string-utils.d.ts +1 -1
  81. package/dist/parser/parse-utils/string-utils.js +8 -6
  82. package/dist/parser/parserContext.d.ts +17 -11
  83. package/dist/parser/parserContext.js +111 -65
  84. package/dist/parser/preprocess.d.ts +7 -0
  85. package/dist/parser/preprocess.js +21 -19
  86. package/dist/pipeline.d.ts +1 -1
  87. package/dist/pipeline.js +2 -2
  88. package/dist/playback/compile.js +14 -15
  89. package/dist/playback/event.d.ts +6 -6
  90. package/dist/playback/event.js +13 -49
  91. package/dist/render/canvas.d.ts +0 -2
  92. package/dist/render/canvas.js +50 -56
  93. package/dist/render/index.d.ts +1 -1
  94. package/dist/render/index.js +1 -1
  95. package/dist/render/paint.d.ts +7 -0
  96. package/dist/render/paint.js +70 -20
  97. package/dist/render/recording.d.ts +8 -1
  98. package/dist/render/recording.js +12 -0
  99. package/dist/render/svg.d.ts +5 -2
  100. package/dist/render/svg.js +70 -48
  101. package/dist/render/text.d.ts +37 -2
  102. package/dist/render/text.js +136 -1
  103. package/dist/render/translate.d.ts +3 -1
  104. package/dist/render/translate.js +6 -0
  105. package/dist/render/types.d.ts +9 -2
  106. package/grammar.md +18 -14
  107. package/package.json +8 -18
  108. package/dist/converter/midi/convert.d.ts +0 -42
  109. package/dist/converter/midi/convert.js +0 -729
  110. package/dist/converter/midi/index.d.ts +0 -5
  111. package/dist/converter/midi/index.js +0 -11
  112. package/dist/converter/midi/json.d.ts +0 -38
  113. package/dist/converter/midi/json.js +0 -1
  114. package/dist/converter/midi/triplet.d.ts +0 -30
  115. package/dist/converter/midi/triplet.js +0 -75
  116. package/dist/converter/musicxml/dom.d.ts +0 -25
  117. package/dist/converter/musicxml/dom.js +0 -65
  118. package/dist/converter/musicxml/features.d.ts +0 -114
  119. package/dist/converter/musicxml/features.js +0 -501
  120. package/dist/converter/musicxml/index.d.ts +0 -14
  121. package/dist/converter/musicxml/index.js +0 -1295
  122. package/dist/converter/musicxml/model.d.ts +0 -176
  123. package/dist/converter/musicxml/model.js +0 -1
  124. package/dist/converter/musicxml/resolve.d.ts +0 -10
  125. package/dist/converter/musicxml/resolve.js +0 -152
  126. package/dist/converter/source.d.ts +0 -22
  127. package/dist/converter/source.js +0 -51
  128. package/dist/core.d.ts +0 -24
  129. package/dist/core.js +0 -24
  130. package/dist/iife/core.d.ts +0 -1
  131. package/dist/iife/core.js +0 -3
  132. package/dist/iife/from-midi.d.ts +0 -1
  133. package/dist/iife/from-midi.js +0 -15
  134. package/dist/iife/from-musicxml.d.ts +0 -1
  135. package/dist/iife/from-musicxml.js +0 -3
  136. package/dist/iife/full.d.ts +0 -1
  137. package/dist/iife/full.js +0 -3
  138. package/dist/jpfun.core.min.js +0 -123
  139. package/dist/jpfun.from-midi.min.js +0 -9
  140. package/dist/jpfun.from-musicxml.min.js +0 -12
@@ -58,13 +58,14 @@ class DotFunction extends ASTFunctionNode {
58
58
  const n = nodes[at++];
59
59
  if (n.data?.class !== DotFunction)
60
60
  return null;
61
- const prevIndex = ASTFunctionNode.findLastFuncContentIndex(ctx.nodes, ctx.nodes.length - 1);
61
+ const prevIndex = ctx.findLastOperandIndex();
62
62
  if (prevIndex < 0)
63
63
  return at; // 没有了 直接当作无效文本跳过
64
64
  const prev = ctx.nodes[prevIndex];
65
65
  if (prev instanceof DotFunction) {
66
66
  // 已经是dot了 继续加深
67
67
  prev.n += n.data.n;
68
+ prev.sourceSpan.end = Math.max(prev.sourceSpan.end, n.span.end);
68
69
  return at;
69
70
  }
70
71
  // 参数数量不校验 在构造函数里写
@@ -72,11 +73,10 @@ class DotFunction extends ASTFunctionNode {
72
73
  argMap.set(0, prev);
73
74
  argMap.set("n", n.data.n);
74
75
  const spanPrev = prev.sourceSpan;
75
- const node = new DotFunction({
76
+ ctx.nodes[prevIndex] = new DotFunction({
76
77
  start: Math.min(spanPrev.start, n.span.start),
77
78
  end: Math.max(spanPrev.end, n.span.end),
78
79
  }, argMap, ctx, null);
79
- ctx.nodes[prevIndex] = node;
80
80
  return at;
81
81
  }
82
82
  /**
@@ -134,12 +134,6 @@ class DotFunction extends ASTFunctionNode {
134
134
  }
135
135
  return [];
136
136
  }
137
- timeFlowModel() {
138
- return {
139
- children: [this.content],
140
- mode: "sequence",
141
- };
142
- }
143
137
  content;
144
138
  n;
145
139
  get children() { return [this.content]; }
@@ -1,4 +1,5 @@
1
1
  import { Diagnostic, ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
2
+ import { lineEntryX, lineRightX } from "../../layout/range.js";
2
3
  import { isVisualTemporalNode, } from "../temporal.js";
3
4
  import { ASTFunctionNode, } from "../ASTtypes.js";
4
5
  function findRecordBoundary(records, time, after = false) {
@@ -44,9 +45,7 @@ class DynFunction extends ASTFunctionNode {
44
45
  const velocity = node.playbackState?.velocity;
45
46
  if (velocity === undefined)
46
47
  continue;
47
- let host = node;
48
- while (host.foldedInto)
49
- host = host.foldedInto;
48
+ const host = node.rootHost;
50
49
  recordsByTrack.get(host.track)?.push({ node, host, velocity, increment: 0 });
51
50
  }
52
51
  }
@@ -104,12 +103,8 @@ class DynFunction extends ASTFunctionNode {
104
103
  ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("dyn", this.sourceSpan));
105
104
  return [];
106
105
  }
107
- let fromHost = from;
108
- let toHost = to;
109
- while (fromHost.foldedInto)
110
- fromHost = fromHost.foldedInto;
111
- while (toHost.foldedInto)
112
- toHost = toHost.foldedInto;
106
+ const fromHost = from.rootHost;
107
+ const toHost = to.rootHost;
113
108
  if (!isVisualTemporalNode(fromHost) || !isVisualTemporalNode(toHost)) {
114
109
  ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("dyn", this.sourceSpan));
115
110
  return [];
@@ -156,6 +151,7 @@ class DynAttachment {
156
151
  end;
157
152
  fromHost;
158
153
  toHost;
154
+ kind = "dyn";
159
155
  layer = "foreground";
160
156
  constructor(ast, end, fromHost, toHost) {
161
157
  this.ast = ast;
@@ -184,10 +180,10 @@ class DynAttachment {
184
180
  }
185
181
  ranges.push({
186
182
  line,
187
- startX: line === fromLine ? this.fromHost.box.x : this.lineEntryX(context, line),
183
+ startX: line === fromLine ? this.fromHost.box.x : lineEntryX(context, line, this.track),
188
184
  endX: line === toLine
189
185
  ? this.toHost.box.x + this.toHost.box.w
190
- : this.lineRightX(context, line),
186
+ : lineRightX(context, line),
191
187
  });
192
188
  }
193
189
  // 允许左边超出一点
@@ -238,19 +234,4 @@ class DynAttachment {
238
234
  },
239
235
  };
240
236
  }
241
- lineEntryX(context, line) {
242
- const host = context.lines[line].trackRuns.get(this.track)?.find(item => !item.T.isZero());
243
- return host?.box.x ?? context.originX;
244
- }
245
- lineRightX(context, line) {
246
- const runs = context.lines[line].trackRuns;
247
- if (runs.size === 0)
248
- return context.originX + context.width;
249
- let right = context.originX;
250
- for (const run of runs.values()) {
251
- for (const host of run)
252
- right = Math.max(right, host.box.x + host.box.w);
253
- }
254
- return right;
255
- }
256
237
  }
@@ -1,20 +1,19 @@
1
- import { ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
1
+ import { Diagnostic, ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
2
2
  import { pathBounds } from "../../layout/path.js";
3
+ import { lineEntryX, lineRightX } from "../../layout/range.js";
3
4
  import { ASTFunctionNode, } from "../ASTtypes.js";
4
5
  import { isVisualTemporalNode } from "../temporal.js";
5
6
  // gliss 判断音高的准则是 resolvedMidi 属性
6
- function pitchOf(node) {
7
- const { resolvedMidi } = node;
8
- return typeof resolvedMidi === "number" ? resolvedMidi : undefined;
9
- }
10
- function findPitchNode(columns, node) {
7
+ function findPitchNode(columns, node, host) {
8
+ const check = (item) => typeof item?.resolvedMidi === "number"
9
+ ? item
10
+ : undefined;
11
11
  if ("resolvedMidi" in node)
12
- return pitchOf(node) !== undefined ? node : undefined;
13
- const host = layoutHost(node);
12
+ return check(node);
14
13
  for (let i = columns.findIndex(col => col.includes(host)) - 1; i >= 0; i--) {
15
14
  const previous = columns[i].find(item => item.track === host.track && "resolvedMidi" in item);
16
15
  if (previous)
17
- return pitchOf(previous) !== undefined ? previous : undefined;
16
+ return check(previous);
18
17
  }
19
18
  }
20
19
  class GlissFunction extends ASTFunctionNode {
@@ -28,16 +27,8 @@ class GlissFunction extends ASTFunctionNode {
28
27
  若附属对象无音高,将使用前面最近的同轨有音高对象的音高;播放时从起点音段按半音阶离散过渡至终点音高。`,
29
28
  allowExtraArgs: false,
30
29
  args: [
31
- {
32
- type: "label",
33
- default: null,
34
- description: "一个端点的标签,先后按谱面时间确定"
35
- },
36
- {
37
- type: "label",
38
- default: null,
39
- description: "另一个端点的标签"
40
- },
30
+ { type: "label", default: null, description: "一个端点的标签,先后按谱面时间确定" },
31
+ { type: "label", default: null, description: "另一个端点的标签" },
41
32
  ],
42
33
  };
43
34
  from;
@@ -50,7 +41,8 @@ class GlissFunction extends ASTFunctionNode {
50
41
  const from = ctx.getTemporalNodes(this.from).at(-1);
51
42
  const to = ctx.getTemporalNodes(this.to).at(-1);
52
43
  if (!from || !to || !isVisualTemporalNode(from) || !isVisualTemporalNode(to)) {
53
- throw new ErrorDiagnostic("E_GLISS_ENDPOINT", "@gliss 的标签必须指向已生成且具有排版盒子的对象", this.sourceSpan);
44
+ ctx.diagnostics.push(Diagnostic.warning.UnresolvedEndpoint("gliss", this.sourceSpan));
45
+ return [];
54
46
  }
55
47
  const attachment = new GlissAttachment(from, to, this.sourceSpan);
56
48
  ctx.addAttachment(attachment);
@@ -72,6 +64,7 @@ function layoutHost(node, line) {
72
64
  }
73
65
  class GlissAttachment {
74
66
  sourceSpan;
67
+ kind = "gliss";
75
68
  layer = "foreground";
76
69
  endPoints;
77
70
  direction;
@@ -81,26 +74,25 @@ class GlissAttachment {
81
74
  }
82
75
  finalize({ columns, diagnostics }) {
83
76
  const [a, b] = this.endPoints;
84
- const fromHost = layoutHost(a);
85
- const toHost = layoutHost(b);
77
+ let fromHost = layoutHost(a);
78
+ let toHost = layoutHost(b);
86
79
  if (fromHost.t.equals(toHost.t)) {
87
80
  throw new ErrorDiagnostic("E_GLISS_ORDER", "@gliss 两个端点不能位于同一时刻", this.sourceSpan);
88
81
  }
89
- if (fromHost.layoutLine !== toHost.layoutLine) {
90
- throw new ErrorDiagnostic("E_GLISS_CROSS_LINE", "@gliss 不支持跨谱面行", this.sourceSpan);
91
- }
92
- if (fromHost.t.compare(toHost.t) > 0)
82
+ if (fromHost.t.compare(toHost.t) > 0) {
93
83
  this.endPoints = [b, a];
84
+ [fromHost, toHost] = [toHost, fromHost];
85
+ }
94
86
  const [endpoint, target] = this.endPoints;
95
- const sourcePitchNode = findPitchNode(columns, endpoint);
96
- const targetPitchNode = findPitchNode(columns, target);
87
+ const sourcePitchNode = findPitchNode(columns, endpoint, fromHost);
88
+ const targetPitchNode = findPitchNode(columns, target, toHost);
97
89
  if (!sourcePitchNode || !targetPitchNode) {
98
90
  diagnostics.push(new WarningDiagnostic("W_GLISS_NO_PITCH", "@gliss 端点没有可用音高", this.sourceSpan));
99
91
  return;
100
92
  }
101
- this.direction = Math.sign(pitchOf(targetPitchNode) - pitchOf(sourcePitchNode));
93
+ this.direction = Math.sign(targetPitchNode.resolvedMidi - sourcePitchNode.resolvedMidi);
102
94
  const emit = endpoint.emitPlayback;
103
- const targetMidi = pitchOf(targetPitchNode) + (targetPitchNode.playbackState?.pitchShift ?? 0);
95
+ const targetMidi = targetPitchNode.resolvedMidi + (targetPitchNode.playbackState?.pitchShift ?? 0);
104
96
  endpoint.emitPlayback = emitter => {
105
97
  emit?.call(endpoint, emitter);
106
98
  const { start: glissStart, end: glissEnd } = emitter;
@@ -109,29 +101,27 @@ class GlissAttachment {
109
101
  const note = context.notes[i];
110
102
  if (note.track !== emitter.track)
111
103
  continue;
112
- if (note.end.equals(glissEnd)) {
113
- context.transform(note, (_ctx, owned) => {
114
- const item = owned.at(-1);
115
- const startFrom = glissStart.compare(item.start) > 0 ? glissStart : item.start;
116
- const fromMidi = item.midi;
117
- const steps = Math.abs(targetMidi - fromMidi);
118
- if (item.end.compare(startFrom) <= 0 || steps <= 1)
119
- return;
120
- const dir = targetMidi > fromMidi ? 1 : -1;
121
- const step = item.end.clone().sub(startFrom).div(steps);
122
- const out = owned.slice(0, -1);
123
- for (let k = 0; k < steps; k++) {
124
- out.push({
125
- ...item,
126
- start: k === 0 ? item.start.clone() : step.clone().mul(k).add(startFrom),
127
- end: step.clone().mul(k + 1).add(startFrom),
128
- midi: fromMidi + k * dir,
129
- });
130
- }
131
- return out;
132
- });
133
- }
134
- break;
104
+ if (!note.end.equals(glissEnd))
105
+ return;
106
+ context.transform(note, (_ctx, owned) => {
107
+ const item = owned.at(-1);
108
+ const startFrom = glissStart.compare(item.start) > 0 ? glissStart : item.start;
109
+ const steps = Math.abs(targetMidi - item.midi);
110
+ if (item.end.compare(startFrom) <= 0 || steps <= 1)
111
+ return;
112
+ const dir = Math.sign(targetMidi - item.midi);
113
+ const step = item.end.clone().sub(startFrom).div(steps);
114
+ return [
115
+ ...owned.slice(0, -1),
116
+ ...Array.from({ length: steps }, (_, k) => ({
117
+ ...item,
118
+ start: k === 0 ? item.start.clone() : step.clone().mul(k).add(startFrom),
119
+ end: step.clone().mul(k + 1).add(startFrom),
120
+ midi: item.midi + k * dir,
121
+ })),
122
+ ];
123
+ });
124
+ return;
135
125
  }
136
126
  });
137
127
  };
@@ -139,61 +129,79 @@ class GlissAttachment {
139
129
  /** 定位端点所在时间列,并为箭头登记水平留白 */
140
130
  prepareHorizontal(lines) {
141
131
  const [endpoint, target] = this.endPoints;
142
- const line = lines[endpoint.layoutLine];
143
- const from = line && layoutHost(endpoint, line);
144
- const to = line && layoutHost(target, line);
145
- const start = from ? line.columnOf(from) : -1;
146
- const end = to ? line.columnOf(to) : -1;
147
- if (!line || start < 0 || end <= start) {
132
+ const fromLine = lines[endpoint.layoutLine];
133
+ const toLine = lines[target.layoutLine];
134
+ const from = fromLine && layoutHost(endpoint, fromLine);
135
+ const to = toLine && layoutHost(target, toLine);
136
+ const start = from ? fromLine.columnOf(from) : -1;
137
+ const end = to ? toLine.columnOf(to) : -1;
138
+ if (!fromLine || !toLine || start < 0 || end < 0 || (fromLine === toLine && end <= start)) {
148
139
  throw new ErrorDiagnostic("E_GLISS_DOMAIN", "@gliss 的端点必须位于同一排版域的不同时间列", this.sourceSpan);
149
140
  }
150
- const right = from.box.w - from.box.anchor + Math.max(endpoint.ast.size, target.ast.size) * 1.4;
141
+ const span = Math.max(endpoint.ast.size, target.ast.size) * 1.4;
142
+ const right = from.box.w - from.box.anchor + span;
151
143
  // 只扩张求解器占位,不改变端点图形、附点位置或下一轮的 box
152
- line.registerHorizontalLayoutHook(from, to, ({ columns }) => {
144
+ fromLine.registerHorizontalLayoutHook(from, from, ({ columns }) => {
153
145
  // 留白作用于起点整列;取最大值,避免多条关系重复累加占位。
154
146
  for (const element of columns[start])
155
147
  element.WR = Math.max(element.WR, right);
156
148
  });
149
+ if (fromLine !== toLine) {
150
+ const left = to.box.anchor + span;
151
+ toLine.registerHorizontalLayoutHook(to, to, ({ columns }) => {
152
+ for (const element of columns[end])
153
+ element.WL = Math.max(element.WL, left);
154
+ });
155
+ }
157
156
  }
158
- createGeometry() {
157
+ createGeometry(context) {
159
158
  const [from, to] = this.endPoints;
160
159
  const size = Math.max(from.ast.size, to.ast.size);
161
160
  const gap = size * 0.12;
162
- const start = { x: from.box.x + from.box.w + gap, y: from.box.y + from.box.visualAxis };
163
- const end = { x: to.box.x - gap, y: to.box.y + to.box.visualAxis };
164
- if (from.track === to.track) {
165
- if (this.direction === undefined) {
166
- end.y = start.y;
167
- }
168
- else {
169
- start.y += this.direction * size * 0.24;
170
- end.y -= this.direction * size * 0.24;
171
- }
161
+ const dy = from.track === to.track ? (this.direction ?? 0) * size * 0.24 : 0;
162
+ const start = { x: from.box.x + from.box.w + gap, y: from.box.y + from.box.visualAxis + dy };
163
+ const end = {
164
+ x: to.box.x - gap,
165
+ y: from.track === to.track && this.direction === undefined && from.layoutLine === to.layoutLine
166
+ ? start.y
167
+ : to.box.y + to.box.visualAxis - dy,
168
+ };
169
+ const pairs = [[start, end, from.layoutLine, from.track]];
170
+ if (from.layoutLine !== to.layoutLine) {
171
+ const end1X = Math.max(start.x + size, lineRightX(context, from.layoutLine));
172
+ const start2X = Math.min(end.x - size, lineEntryX(context, to.layoutLine, to.track, end.x));
173
+ const w1 = end1X - start.x;
174
+ const cut = dy * (1 - 2 * w1 / (w1 + end.x - start2X));
175
+ pairs[0] = [start, { x: end1X, y: start.y - dy + cut }, from.layoutLine, from.track];
176
+ pairs.push([{ x: start2X, y: end.y + dy + cut }, end, to.layoutLine, to.track]);
172
177
  }
173
- if (end.x <= start.x) {
178
+ else if (end.x <= start.x) {
174
179
  throw new ErrorDiagnostic("E_GLISS_SPACE", "@gliss 的端点之间没有可用的水平绘制空间", this.sourceSpan);
175
180
  }
176
- const angle = Math.atan2(end.y - start.y, end.x - start.x);
177
- const length = Math.min(size * 0.3, Math.hypot(end.x - start.x, end.y - start.y) * 0.35);
178
- const wing = (offset) => ({
179
- x: end.x - length * Math.cos(angle + offset),
180
- y: end.y - length * Math.sin(angle + offset),
181
- });
182
- const commands = [
183
- { op: "M", ...start }, { op: "L", ...end },
184
- { op: "M", ...wing(-Math.PI / 6) }, { op: "L", ...end },
185
- { op: "L", ...wing(Math.PI / 6) },
186
- ];
187
181
  const strokeWidth = size * 0.05;
188
- const bounds = pathBounds(commands);
189
- const region = {
190
- x: bounds.x - strokeWidth / 2, y: bounds.y - strokeWidth / 2,
191
- w: bounds.w + strokeWidth, h: bounds.h + strokeWidth,
192
- };
182
+ const commands = [];
183
+ const regions = pairs.map(([s, e, line, track], i) => {
184
+ const part = [{ op: "M", ...s }, { op: "L", ...e }];
185
+ if (i === pairs.length - 1) {
186
+ const angle = Math.atan2(e.y - s.y, e.x - s.x);
187
+ const length = Math.min(size * 0.3, Math.hypot(e.x - s.x, e.y - s.y) * 0.35);
188
+ const wing = (offset) => ({
189
+ x: e.x - length * Math.cos(angle + offset),
190
+ y: e.y - length * Math.sin(angle + offset),
191
+ });
192
+ part.push({ op: "M", ...wing(-Math.PI / 6) }, { op: "L", ...e }, { op: "L", ...wing(Math.PI / 6) });
193
+ }
194
+ commands.push(...part);
195
+ const bounds = pathBounds(part);
196
+ return {
197
+ x: bounds.x - strokeWidth / 2, y: bounds.y - strokeWidth / 2,
198
+ w: bounds.w + strokeWidth, h: bounds.h + strokeWidth, line, track,
199
+ };
200
+ });
193
201
  return {
194
- regions: [{ ...region, line: from.layoutLine, track: from.track }],
202
+ regions,
195
203
  // 跨轨连线不把整段高度算到起点轨,否则纵向求解会反复撑开两轨
196
- occupancy: from.track === to.track ? [{ ...region, line: from.layoutLine, track: from.track }] : [],
204
+ occupancy: from.track === to.track ? regions : [],
197
205
  paint: (painter) => {
198
206
  painter.drawPath(commands, { fill: "none", stroke: "#000", strokeWidth });
199
207
  },
@@ -28,8 +28,8 @@ declare class GraceFunction extends ASTFunctionNode {
28
28
  */
29
29
  private static attachPre;
30
30
  private static create;
31
- /** 宿主在前:findActiveDivs 下潜子树时要先命中宿主的 @div,而不是倚音的 */
32
31
  get children(): ASTNodeBase[];
32
+ timeFlowModel(): null;
33
33
  constructor(span: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent?: ASTNodeBase | null, scale?: number);
34
34
  setGrace(node: ASTNodeBase, factor?: number): void;
35
35
  private adopt;
@@ -47,9 +47,6 @@ export declare class GraceTemporal extends TemporalNodeBase {
47
47
  readonly graceColumns: readonly (readonly VisualTemporalNode[])[];
48
48
  /** graceColumns 按列展开 */
49
49
  readonly graces: readonly VisualTemporalNode[];
50
- /** 承担节奏的倚音成员,按声部与零时长标记切段;同段视觉上首尾相接,无条件连成一束减时线 */
51
- readonly graceRuns: readonly (readonly VisualTemporalNode[])[];
52
- readonly side: GraceSide;
53
50
  /** 倚音子域的根轨:由宿主轨分出,不挂进它的分组,子域之外不可见 */
54
51
  private readonly root;
55
52
  /** 倚音内容里声明的附件,随子域排版 */
@@ -63,7 +60,7 @@ export declare class GraceTemporal extends TemporalNodeBase {
63
60
  private graceOffsets;
64
61
  /** 倚音线起点,同样是局部偏移 */
65
62
  private hookOrigin;
66
- constructor(ast: GraceFunction, host: VisualTemporalNode, columns: readonly (readonly TemporalNodeBase[])[], root: Track, attachments: readonly LoweringAttachment[], side: GraceSide);
63
+ constructor(ast: GraceFunction, host: VisualTemporalNode, columns: readonly (readonly TemporalNodeBase[])[], root: Track, attachments: readonly LoweringAttachment[], ctx: LoweringContext);
67
64
  /** 成员共享全局时间状态,按发声顺序固化 */
68
65
  onTimeState(state: TimeState): void | Fraction;
69
66
  prepareHorizontal(line: HorizontalLineView): void;