jpfun 0.8.0 → 0.9.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 (97) hide show
  1. package/dist/converter/midi/convert.js +8 -55
  2. package/dist/converter/musicxml/features.d.ts +1 -1
  3. package/dist/converter/musicxml/features.js +1 -1
  4. package/dist/converter/musicxml/index.js +8 -18
  5. package/dist/converter/source.d.ts +4 -7
  6. package/dist/converter/source.js +11 -9
  7. package/dist/functions/ASTtypes.d.ts +1 -14
  8. package/dist/functions/ASTtypes.js +5 -36
  9. package/dist/functions/adjust/index.js +45 -33
  10. package/dist/functions/arpeggio/index.js +42 -45
  11. package/dist/functions/arpeggio/shape.d.ts +2 -3
  12. package/dist/functions/arpeggio/shape.js +20 -50
  13. package/dist/functions/bar/index.js +3 -8
  14. package/dist/functions/beam/auto.js +54 -123
  15. package/dist/functions/beam/index.js +4 -9
  16. package/dist/functions/box/index.js +0 -6
  17. package/dist/functions/dash/index.js +3 -4
  18. package/dist/functions/div/index.d.ts +2 -4
  19. package/dist/functions/div/index.js +10 -10
  20. package/dist/functions/dot/index.js +3 -9
  21. package/dist/functions/dyn/index.js +6 -26
  22. package/dist/functions/gliss/index.js +95 -89
  23. package/dist/functions/grace/index.d.ts +2 -5
  24. package/dist/functions/grace/index.js +44 -89
  25. package/dist/functions/head/index.js +9 -6
  26. package/dist/functions/key/index.js +6 -6
  27. package/dist/functions/meter/index.js +3 -3
  28. package/dist/functions/note/index.js +1 -1
  29. package/dist/functions/note/source-transform.js +2 -5
  30. package/dist/functions/ottava/index.js +11 -32
  31. package/dist/functions/page/index.js +13 -16
  32. package/dist/functions/rest/index.js +2 -4
  33. package/dist/functions/slide/index.js +0 -1
  34. package/dist/functions/stack/index.js +8 -57
  35. package/dist/functions/temporal.d.ts +2 -2
  36. package/dist/functions/temporal.js +7 -0
  37. package/dist/functions/text/index.js +24 -30
  38. package/dist/functions/tie/index.js +14 -37
  39. package/dist/functions/tremolo/index.js +0 -1
  40. package/dist/functions/tuplet/index.js +0 -6
  41. package/dist/functions/up/index.js +79 -83
  42. package/dist/functions/voice/connections.d.ts +2 -1
  43. package/dist/functions/voice/connections.js +48 -10
  44. package/dist/functions/voice/index.d.ts +2 -3
  45. package/dist/functions/voice/index.js +2 -970
  46. package/dist/functions/voice/lyrics.d.ts +30 -0
  47. package/dist/functions/voice/lyrics.js +289 -0
  48. package/dist/functions/voice/voice.d.ts +63 -0
  49. package/dist/functions/voice/voice.js +373 -0
  50. package/dist/functions/voice/voices.d.ts +106 -0
  51. package/dist/functions/voice/voices.js +423 -0
  52. package/dist/functions/volta/index.js +5 -23
  53. package/dist/jpfun.core.min.js +65 -56
  54. package/dist/jpfun.from-midi.min.js +5 -5
  55. package/dist/jpfun.from-musicxml.min.js +7 -7
  56. package/dist/jpfun.min.js +68 -59
  57. package/dist/layout/engine.js +30 -18
  58. package/dist/layout/model.d.ts +0 -1
  59. package/dist/layout/model.js +1 -4
  60. package/dist/layout/page.d.ts +2 -1
  61. package/dist/layout/page.js +14 -14
  62. package/dist/layout/range.d.ts +7 -6
  63. package/dist/layout/range.js +23 -14
  64. package/dist/layout/types.d.ts +9 -28
  65. package/dist/lowering/loweringContext.d.ts +8 -11
  66. package/dist/lowering/loweringContext.js +7 -13
  67. package/dist/lowering/track.d.ts +8 -1
  68. package/dist/lowering/types.d.ts +12 -8
  69. package/dist/parser/parse-utils/call-utils.d.ts +1 -2
  70. package/dist/parser/parse-utils/call-utils.js +6 -34
  71. package/dist/parser/parse-utils/note-utils.d.ts +3 -3
  72. package/dist/parser/parse-utils/note-utils.js +17 -28
  73. package/dist/parser/parse-utils/string-utils.d.ts +1 -1
  74. package/dist/parser/parse-utils/string-utils.js +8 -6
  75. package/dist/parser/parserContext.d.ts +9 -9
  76. package/dist/parser/parserContext.js +54 -10
  77. package/dist/pipeline.js +2 -2
  78. package/dist/playback/compile.js +13 -14
  79. package/dist/playback/event.d.ts +6 -6
  80. package/dist/playback/event.js +13 -49
  81. package/dist/render/canvas.d.ts +0 -2
  82. package/dist/render/canvas.js +0 -21
  83. package/dist/render/svg.d.ts +0 -1
  84. package/dist/render/svg.js +33 -31
  85. package/dist/render/text.d.ts +36 -1
  86. package/dist/render/text.js +134 -0
  87. package/dist/render/types.d.ts +0 -2
  88. package/grammar.md +16 -13
  89. package/package.json +1 -1
  90. package/dist/iife/core.d.ts +0 -1
  91. package/dist/iife/core.js +0 -3
  92. package/dist/iife/from-midi.d.ts +0 -1
  93. package/dist/iife/from-midi.js +0 -15
  94. package/dist/iife/from-musicxml.d.ts +0 -1
  95. package/dist/iife/from-musicxml.js +0 -3
  96. package/dist/iife/full.d.ts +0 -1
  97. package/dist/iife/full.js +0 -3
@@ -3,6 +3,10 @@ import { WarningDiagnostic } from "../../diagnostic.js";
3
3
  import { createAutomaticBeamAttachments } from "../beam/auto.js";
4
4
  const DIV_FUNC_NAME = "div";
5
5
  export const DIV_ADDON_KEY = functionAddonKey(DIV_FUNC_NAME);
6
+ const DIV_OWNER_KEY = Symbol("div.owner");
7
+ export function getDivOwner(node) {
8
+ return node.addon?.[DIV_OWNER_KEY];
9
+ }
6
10
  /** div 暴露自己的线段端口,不依赖任何关系函数 */
7
11
  export function divLinePortName(level, edge) {
8
12
  return `div.${level}.${edge}`;
@@ -101,24 +105,24 @@ class DivFunction extends ASTFunctionNode {
101
105
  const n = nodes[at++];
102
106
  if (n.data?.class !== DivFunction)
103
107
  return null;
104
- const prevIndex = ASTFunctionNode.findLastFuncContentIndex(ctx.nodes, ctx.nodes.length - 1);
108
+ const prevIndex = ctx.findLastOperandIndex();
105
109
  if (prevIndex < 0)
106
110
  return at; // 没有了 直接当作无效文本跳过
107
111
  const prev = ctx.nodes[prevIndex];
108
112
  if (prev instanceof DivFunction) {
109
113
  // 已经是div了 继续加深
110
114
  prev.n += n.data.n;
115
+ prev.sourceSpan.end = Math.max(prev.sourceSpan.end, n.span.end);
111
116
  return at;
112
117
  }
113
118
  const argMap = new Map();
114
119
  argMap.set(0, prev);
115
120
  argMap.set("n", n.data.n);
116
121
  const spanPrev = prev.sourceSpan;
117
- const node = new DivFunction({
122
+ ctx.nodes[prevIndex] = new DivFunction({
118
123
  start: Math.min(spanPrev.start, n.span.start),
119
124
  end: Math.max(spanPrev.end, n.span.end),
120
125
  }, argMap, ctx, null);
121
- ctx.nodes[prevIndex] = node;
122
126
  return at;
123
127
  }
124
128
  /**
@@ -177,11 +181,13 @@ class DivFunction extends ASTFunctionNode {
177
181
  const count = this.n;
178
182
  if (count === 0)
179
183
  return [];
184
+ const self = this;
180
185
  ctx.deferFinalize(DivFunction.loweringFinalize, -5);
181
186
  ctx.beginLoweringGroup(this, {
182
187
  onTemporal(node) {
183
- const addon = node.addon ??= {};
188
+ const addon = (node.addon ??= {});
184
189
  addon[DIV_ADDON_KEY] = (Number(addon[DIV_ADDON_KEY]) || 0) + count;
190
+ addon[DIV_OWNER_KEY] = self;
185
191
  node.T.divPow2(count);
186
192
  },
187
193
  });
@@ -198,12 +204,6 @@ class DivFunction extends ASTFunctionNode {
198
204
  /** parse 时冻结;只控制不同 div 之间的自动连接,不影响当前 div 内部连接 */
199
205
  autoBeamEnabled;
200
206
  get children() { return [this.content]; }
201
- timeFlowModel() {
202
- return {
203
- children: [this.content],
204
- mode: "sequence",
205
- };
206
- }
207
207
  constructor(sourceSpan, args, ctx, parent = null) {
208
208
  super(sourceSpan, parent);
209
209
  [this.content, this.n, this.autoBeamEnabled] = this.getArgValue(args, ctx);
@@ -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 [];
@@ -184,10 +179,10 @@ class DynAttachment {
184
179
  }
185
180
  ranges.push({
186
181
  line,
187
- startX: line === fromLine ? this.fromHost.box.x : this.lineEntryX(context, line),
182
+ startX: line === fromLine ? this.fromHost.box.x : lineEntryX(context, line, this.track),
188
183
  endX: line === toLine
189
184
  ? this.toHost.box.x + this.toHost.box.w
190
- : this.lineRightX(context, line),
185
+ : lineRightX(context, line),
191
186
  });
192
187
  }
193
188
  // 允许左边超出一点
@@ -238,19 +233,4 @@ class DynAttachment {
238
233
  },
239
234
  };
240
235
  }
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
236
  }
@@ -1,20 +1,19 @@
1
1
  import { 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;
@@ -81,26 +72,25 @@ class GlissAttachment {
81
72
  }
82
73
  finalize({ columns, diagnostics }) {
83
74
  const [a, b] = this.endPoints;
84
- const fromHost = layoutHost(a);
85
- const toHost = layoutHost(b);
75
+ let fromHost = layoutHost(a);
76
+ let toHost = layoutHost(b);
86
77
  if (fromHost.t.equals(toHost.t)) {
87
78
  throw new ErrorDiagnostic("E_GLISS_ORDER", "@gliss 两个端点不能位于同一时刻", this.sourceSpan);
88
79
  }
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)
80
+ if (fromHost.t.compare(toHost.t) > 0) {
93
81
  this.endPoints = [b, a];
82
+ [fromHost, toHost] = [toHost, fromHost];
83
+ }
94
84
  const [endpoint, target] = this.endPoints;
95
- const sourcePitchNode = findPitchNode(columns, endpoint);
96
- const targetPitchNode = findPitchNode(columns, target);
85
+ const sourcePitchNode = findPitchNode(columns, endpoint, fromHost);
86
+ const targetPitchNode = findPitchNode(columns, target, toHost);
97
87
  if (!sourcePitchNode || !targetPitchNode) {
98
88
  diagnostics.push(new WarningDiagnostic("W_GLISS_NO_PITCH", "@gliss 端点没有可用音高", this.sourceSpan));
99
89
  return;
100
90
  }
101
- this.direction = Math.sign(pitchOf(targetPitchNode) - pitchOf(sourcePitchNode));
91
+ this.direction = Math.sign(targetPitchNode.resolvedMidi - sourcePitchNode.resolvedMidi);
102
92
  const emit = endpoint.emitPlayback;
103
- const targetMidi = pitchOf(targetPitchNode) + (targetPitchNode.playbackState?.pitchShift ?? 0);
93
+ const targetMidi = targetPitchNode.resolvedMidi + (targetPitchNode.playbackState?.pitchShift ?? 0);
104
94
  endpoint.emitPlayback = emitter => {
105
95
  emit?.call(endpoint, emitter);
106
96
  const { start: glissStart, end: glissEnd } = emitter;
@@ -109,29 +99,27 @@ class GlissAttachment {
109
99
  const note = context.notes[i];
110
100
  if (note.track !== emitter.track)
111
101
  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;
102
+ if (!note.end.equals(glissEnd))
103
+ return;
104
+ context.transform(note, (_ctx, owned) => {
105
+ const item = owned.at(-1);
106
+ const startFrom = glissStart.compare(item.start) > 0 ? glissStart : item.start;
107
+ const steps = Math.abs(targetMidi - item.midi);
108
+ if (item.end.compare(startFrom) <= 0 || steps <= 1)
109
+ return;
110
+ const dir = Math.sign(targetMidi - item.midi);
111
+ const step = item.end.clone().sub(startFrom).div(steps);
112
+ return [
113
+ ...owned.slice(0, -1),
114
+ ...Array.from({ length: steps }, (_, k) => ({
115
+ ...item,
116
+ start: k === 0 ? item.start.clone() : step.clone().mul(k).add(startFrom),
117
+ end: step.clone().mul(k + 1).add(startFrom),
118
+ midi: item.midi + k * dir,
119
+ })),
120
+ ];
121
+ });
122
+ return;
135
123
  }
136
124
  });
137
125
  };
@@ -139,61 +127,79 @@ class GlissAttachment {
139
127
  /** 定位端点所在时间列,并为箭头登记水平留白 */
140
128
  prepareHorizontal(lines) {
141
129
  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) {
130
+ const fromLine = lines[endpoint.layoutLine];
131
+ const toLine = lines[target.layoutLine];
132
+ const from = fromLine && layoutHost(endpoint, fromLine);
133
+ const to = toLine && layoutHost(target, toLine);
134
+ const start = from ? fromLine.columnOf(from) : -1;
135
+ const end = to ? toLine.columnOf(to) : -1;
136
+ if (!fromLine || !toLine || start < 0 || end < 0 || (fromLine === toLine && end <= start)) {
148
137
  throw new ErrorDiagnostic("E_GLISS_DOMAIN", "@gliss 的端点必须位于同一排版域的不同时间列", this.sourceSpan);
149
138
  }
150
- const right = from.box.w - from.box.anchor + Math.max(endpoint.ast.size, target.ast.size) * 1.4;
139
+ const span = Math.max(endpoint.ast.size, target.ast.size) * 1.4;
140
+ const right = from.box.w - from.box.anchor + span;
151
141
  // 只扩张求解器占位,不改变端点图形、附点位置或下一轮的 box
152
- line.registerHorizontalLayoutHook(from, to, ({ columns }) => {
142
+ fromLine.registerHorizontalLayoutHook(from, from, ({ columns }) => {
153
143
  // 留白作用于起点整列;取最大值,避免多条关系重复累加占位。
154
144
  for (const element of columns[start])
155
145
  element.WR = Math.max(element.WR, right);
156
146
  });
147
+ if (fromLine !== toLine) {
148
+ const left = to.box.anchor + span;
149
+ toLine.registerHorizontalLayoutHook(to, to, ({ columns }) => {
150
+ for (const element of columns[end])
151
+ element.WL = Math.max(element.WL, left);
152
+ });
153
+ }
157
154
  }
158
- createGeometry() {
155
+ createGeometry(context) {
159
156
  const [from, to] = this.endPoints;
160
157
  const size = Math.max(from.ast.size, to.ast.size);
161
158
  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
- }
159
+ const dy = from.track === to.track ? (this.direction ?? 0) * size * 0.24 : 0;
160
+ const start = { x: from.box.x + from.box.w + gap, y: from.box.y + from.box.visualAxis + dy };
161
+ const end = {
162
+ x: to.box.x - gap,
163
+ y: from.track === to.track && this.direction === undefined && from.layoutLine === to.layoutLine
164
+ ? start.y
165
+ : to.box.y + to.box.visualAxis - dy,
166
+ };
167
+ const pairs = [[start, end, from.layoutLine, from.track]];
168
+ if (from.layoutLine !== to.layoutLine) {
169
+ const end1X = Math.max(start.x + size, lineRightX(context, from.layoutLine));
170
+ const start2X = Math.min(end.x - size, lineEntryX(context, to.layoutLine, to.track, end.x));
171
+ const w1 = end1X - start.x;
172
+ const cut = dy * (1 - 2 * w1 / (w1 + end.x - start2X));
173
+ pairs[0] = [start, { x: end1X, y: start.y - dy + cut }, from.layoutLine, from.track];
174
+ pairs.push([{ x: start2X, y: end.y + dy + cut }, end, to.layoutLine, to.track]);
172
175
  }
173
- if (end.x <= start.x) {
176
+ else if (end.x <= start.x) {
174
177
  throw new ErrorDiagnostic("E_GLISS_SPACE", "@gliss 的端点之间没有可用的水平绘制空间", this.sourceSpan);
175
178
  }
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
179
  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
- };
180
+ const commands = [];
181
+ const regions = pairs.map(([s, e, line, track], i) => {
182
+ const part = [{ op: "M", ...s }, { op: "L", ...e }];
183
+ if (i === pairs.length - 1) {
184
+ const angle = Math.atan2(e.y - s.y, e.x - s.x);
185
+ const length = Math.min(size * 0.3, Math.hypot(e.x - s.x, e.y - s.y) * 0.35);
186
+ const wing = (offset) => ({
187
+ x: e.x - length * Math.cos(angle + offset),
188
+ y: e.y - length * Math.sin(angle + offset),
189
+ });
190
+ part.push({ op: "M", ...wing(-Math.PI / 6) }, { op: "L", ...e }, { op: "L", ...wing(Math.PI / 6) });
191
+ }
192
+ commands.push(...part);
193
+ const bounds = pathBounds(part);
194
+ return {
195
+ x: bounds.x - strokeWidth / 2, y: bounds.y - strokeWidth / 2,
196
+ w: bounds.w + strokeWidth, h: bounds.h + strokeWidth, line, track,
197
+ };
198
+ });
193
199
  return {
194
- regions: [{ ...region, line: from.layoutLine, track: from.track }],
200
+ regions,
195
201
  // 跨轨连线不把整段高度算到起点轨,否则纵向求解会反复撑开两轨
196
- occupancy: from.track === to.track ? [{ ...region, line: from.layoutLine, track: from.track }] : [],
202
+ occupancy: from.track === to.track ? regions : [],
197
203
  paint: (painter) => {
198
204
  painter.drawPath(commands, { fill: "none", stroke: "#000", strokeWidth });
199
205
  },
@@ -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;