jpfun 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +134 -0
- package/dist/diagnostic.d.ts +27 -0
- package/dist/diagnostic.js +141 -0
- package/dist/functions/ASTtypes.d.ts +115 -0
- package/dist/functions/ASTtypes.js +187 -0
- package/dist/functions/bar/index.d.ts +2 -0
- package/dist/functions/bar/index.js +180 -0
- package/dist/functions/beam/auto.d.ts +4 -0
- package/dist/functions/beam/auto.js +202 -0
- package/dist/functions/beam/index.d.ts +2 -0
- package/dist/functions/beam/index.js +54 -0
- package/dist/functions/beam/layout.d.ts +9 -0
- package/dist/functions/beam/layout.js +233 -0
- package/dist/functions/box/index.d.ts +2 -0
- package/dist/functions/box/index.js +202 -0
- package/dist/functions/br/index.d.ts +2 -0
- package/dist/functions/br/index.js +83 -0
- package/dist/functions/dash/index.d.ts +2 -0
- package/dist/functions/dash/index.js +61 -0
- package/dist/functions/default.d.ts +2 -0
- package/dist/functions/default.js +32 -0
- package/dist/functions/div/index.d.ts +50 -0
- package/dist/functions/div/index.js +190 -0
- package/dist/functions/dot/index.d.ts +2 -0
- package/dist/functions/dot/index.js +160 -0
- package/dist/functions/grace/index.d.ts +84 -0
- package/dist/functions/grace/index.js +464 -0
- package/dist/functions/key/index.d.ts +2 -0
- package/dist/functions/key/index.js +40 -0
- package/dist/functions/note/accidentals.d.ts +10 -0
- package/dist/functions/note/accidentals.js +60 -0
- package/dist/functions/note/index.d.ts +2 -0
- package/dist/functions/note/index.js +284 -0
- package/dist/functions/note/noteNameFSM.d.ts +8 -0
- package/dist/functions/note/noteNameFSM.js +192 -0
- package/dist/functions/over/index.d.ts +2 -0
- package/dist/functions/over/index.js +307 -0
- package/dist/functions/page/index.d.ts +20 -0
- package/dist/functions/page/index.js +63 -0
- package/dist/functions/set/index.d.ts +2 -0
- package/dist/functions/set/index.js +55 -0
- package/dist/functions/stack/index.d.ts +2 -0
- package/dist/functions/stack/index.js +164 -0
- package/dist/functions/tempo/index.d.ts +2 -0
- package/dist/functions/tempo/index.js +37 -0
- package/dist/functions/text/index.d.ts +2 -0
- package/dist/functions/text/index.js +65 -0
- package/dist/functions/tie/index.d.ts +2 -0
- package/dist/functions/tie/index.js +301 -0
- package/dist/functions/voice/index.d.ts +3 -0
- package/dist/functions/voice/index.js +714 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -0
- package/dist/layout/default.d.ts +12 -0
- package/dist/layout/default.js +27 -0
- package/dist/layout/engine.d.ts +47 -0
- package/dist/layout/engine.js +410 -0
- package/dist/layout/model.d.ts +73 -0
- package/dist/layout/model.js +422 -0
- package/dist/layout/page.d.ts +27 -0
- package/dist/layout/page.js +121 -0
- package/dist/layout/types.d.ts +197 -0
- package/dist/layout/types.js +1 -0
- package/dist/lowering/loweringContext.d.ts +126 -0
- package/dist/lowering/loweringContext.js +625 -0
- package/dist/lowering/track.d.ts +61 -0
- package/dist/lowering/track.js +35 -0
- package/dist/lowering/types.d.ts +176 -0
- package/dist/lowering/types.js +82 -0
- package/dist/parser/grammarType.d.ts +81 -0
- package/dist/parser/grammarType.js +1 -0
- package/dist/parser/parse-utils/brace-utils.d.ts +1 -0
- package/dist/parser/parse-utils/brace-utils.js +29 -0
- package/dist/parser/parse-utils/call-utils.d.ts +24 -0
- package/dist/parser/parse-utils/call-utils.js +178 -0
- package/dist/parser/parse-utils/label-utils.d.ts +4 -0
- package/dist/parser/parse-utils/label-utils.js +17 -0
- package/dist/parser/parse-utils/length-utils.d.ts +3 -0
- package/dist/parser/parse-utils/length-utils.js +20 -0
- package/dist/parser/parse-utils/note-utils.d.ts +10 -0
- package/dist/parser/parse-utils/note-utils.js +111 -0
- package/dist/parser/parserContext.d.ts +93 -0
- package/dist/parser/parserContext.js +542 -0
- package/dist/parser/preprocess.d.ts +6 -0
- package/dist/parser/preprocess.js +193 -0
- package/dist/parser/types.d.ts +31 -0
- package/dist/parser/types.js +2 -0
- package/dist/pipeline.d.ts +36 -0
- package/dist/pipeline.js +51 -0
- package/dist/render/canvas.d.ts +19 -0
- package/dist/render/canvas.js +121 -0
- package/dist/render/index.d.ts +5 -0
- package/dist/render/index.js +5 -0
- package/dist/render/recording.d.ts +46 -0
- package/dist/render/recording.js +76 -0
- package/dist/render/svg.d.ts +18 -0
- package/dist/render/svg.js +126 -0
- package/dist/render/text.d.ts +6 -0
- package/dist/render/text.js +17 -0
- package/dist/render/types.d.ts +86 -0
- package/dist/render/types.js +1 -0
- package/grammar.md +123 -0
- package/package.json +58 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { ASTFunctionNode, functionAddonKey } from "../ASTtypes.js";
|
|
2
|
+
const DIV_FUNC_NAME = "div";
|
|
3
|
+
export const DIV_ADDON_KEY = functionAddonKey(DIV_FUNC_NAME);
|
|
4
|
+
/** div 暴露自己的线段端口,不依赖任何关系函数 */
|
|
5
|
+
export function divLinePortName(level, edge) {
|
|
6
|
+
return `div.${level}.${edge}`;
|
|
7
|
+
}
|
|
8
|
+
export function claimDivLine(host, level) {
|
|
9
|
+
const port = host.ports[divLinePortName(level, "left")];
|
|
10
|
+
if (port)
|
|
11
|
+
port.claimed = true;
|
|
12
|
+
}
|
|
13
|
+
function parseAutoBeamFlag(raw) {
|
|
14
|
+
if (typeof raw === "boolean")
|
|
15
|
+
return raw;
|
|
16
|
+
if (typeof raw === "number")
|
|
17
|
+
return raw !== 0;
|
|
18
|
+
if (typeof raw === "string") {
|
|
19
|
+
const normalized = raw.trim().toLowerCase();
|
|
20
|
+
if (normalized === "true" || normalized === "1" || normalized === "on")
|
|
21
|
+
return true;
|
|
22
|
+
if (normalized === "false" || normalized === "0" || normalized === "off")
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
class DivFunction extends ASTFunctionNode {
|
|
28
|
+
static def = {
|
|
29
|
+
name: [DIV_FUNC_NAME, "/"],
|
|
30
|
+
description: "减时线",
|
|
31
|
+
example: `@div(C1, 2): C1下方创建2根减时线
|
|
32
|
+
@/({C1 C2 @dash()}, 3): C1、C2和增时线下方创建3根减时线并连接
|
|
33
|
+
语法糖:在音符后加斜杠'/',可以多个
|
|
34
|
+
@div(C1, 2) === C1//
|
|
35
|
+
@div(C1 C2/ @dash(), 2) === {C1 C2/ @dash()}//
|
|
36
|
+
设置命名参数前缀: div
|
|
37
|
+
`,
|
|
38
|
+
allowExtraArgs: false,
|
|
39
|
+
args: [
|
|
40
|
+
{
|
|
41
|
+
type: "content",
|
|
42
|
+
default: null,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "n",
|
|
46
|
+
type: "number",
|
|
47
|
+
default: 1,
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
static deSugarAtom(source, start, end) {
|
|
52
|
+
// 检查 / 的数量
|
|
53
|
+
let divCnt = 0;
|
|
54
|
+
let pos = start;
|
|
55
|
+
while (pos < end && source[pos] === '/') {
|
|
56
|
+
divCnt++;
|
|
57
|
+
pos++;
|
|
58
|
+
}
|
|
59
|
+
if (divCnt === 0)
|
|
60
|
+
return null;
|
|
61
|
+
// 对前一个节点的探查放到 deSugarRelation 中
|
|
62
|
+
const node = {
|
|
63
|
+
kind: "sugar",
|
|
64
|
+
data: {
|
|
65
|
+
class: DivFunction,
|
|
66
|
+
n: divCnt,
|
|
67
|
+
},
|
|
68
|
+
span: { start, end: pos },
|
|
69
|
+
};
|
|
70
|
+
return { next: pos, node };
|
|
71
|
+
}
|
|
72
|
+
;
|
|
73
|
+
static deSugarRelation(ctx, nodes, at) {
|
|
74
|
+
const n = nodes[at++];
|
|
75
|
+
if (n.data?.class !== DivFunction)
|
|
76
|
+
return null;
|
|
77
|
+
// 向前找到第一个有效节点
|
|
78
|
+
const prev = ASTFunctionNode.findLastFuncContentNode(ctx.nodes, ctx.nodes.length - 1);
|
|
79
|
+
if (!prev)
|
|
80
|
+
return at; // 没有了 直接当作无效文本跳过
|
|
81
|
+
if (prev instanceof DivFunction) {
|
|
82
|
+
// 已经是div了 继续加深
|
|
83
|
+
prev.n += n.data.n;
|
|
84
|
+
return at;
|
|
85
|
+
}
|
|
86
|
+
const argMap = new Map();
|
|
87
|
+
argMap.set(0, prev);
|
|
88
|
+
argMap.set("n", n.data.n);
|
|
89
|
+
const spanPrev = prev.sourceSpan;
|
|
90
|
+
const node = new DivFunction({
|
|
91
|
+
start: Math.min(spanPrev.start, n.span.start),
|
|
92
|
+
end: Math.max(spanPrev.end, n.span.end),
|
|
93
|
+
}, argMap, ctx, null);
|
|
94
|
+
ctx.nodes.pop(); // 消耗掉prev
|
|
95
|
+
ctx.pushNode(node);
|
|
96
|
+
return at;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 减时线是目标对象下方的通用装饰
|
|
100
|
+
* 多对象自动连线属于 beam 的关系排版,不在这里猜测相邻元素
|
|
101
|
+
*/
|
|
102
|
+
static layoutDecorationHandler = (host, value) => {
|
|
103
|
+
const count = Math.max(0, Math.floor(Number(value) || 0));
|
|
104
|
+
if (count === 0)
|
|
105
|
+
return null;
|
|
106
|
+
const lineGap = host.ast.size * 0.14;
|
|
107
|
+
const strokeWidth = Math.max(1, host.ast.size * 0.055);
|
|
108
|
+
const lineBlockHeight = (count - 1) * lineGap + strokeWidth;
|
|
109
|
+
let lineLeft = 0;
|
|
110
|
+
let lineRight = 0;
|
|
111
|
+
let firstLine = 0;
|
|
112
|
+
return {
|
|
113
|
+
// 减时线声明为靠近主体的下方项
|
|
114
|
+
// 引擎只按通用 order 排列,不识别 @div
|
|
115
|
+
below: {
|
|
116
|
+
order: 0,
|
|
117
|
+
gap: -host.ast.size * 0.08,
|
|
118
|
+
height: lineBlockHeight,
|
|
119
|
+
place(y) {
|
|
120
|
+
lineLeft = host.ports["body.left"]?.x ?? 0;
|
|
121
|
+
lineRight = host.ports["body.right"]?.x ?? host.box.w;
|
|
122
|
+
firstLine = y + strokeWidth / 2;
|
|
123
|
+
// 每一级提供完整局部范围
|
|
124
|
+
// 关系对象可以据此一次绘制整条连接线
|
|
125
|
+
for (let i = 0; i < count; i++) {
|
|
126
|
+
const lineY = firstLine + i * lineGap;
|
|
127
|
+
host.ports[divLinePortName(i, "left")] = {
|
|
128
|
+
x: lineLeft,
|
|
129
|
+
y: lineY,
|
|
130
|
+
};
|
|
131
|
+
host.ports[divLinePortName(i, "right")] = {
|
|
132
|
+
x: lineRight,
|
|
133
|
+
y: lineY,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
paint(painter) {
|
|
139
|
+
// 未被关系对象接管的级别仍由本装饰独立绘制
|
|
140
|
+
for (let i = 0; i < count; i++) {
|
|
141
|
+
const leftPort = host.ports[divLinePortName(i, "left")];
|
|
142
|
+
if (leftPort.claimed)
|
|
143
|
+
continue;
|
|
144
|
+
const y = host.box.y + firstLine + i * lineGap;
|
|
145
|
+
painter.drawLine(host.box.x + lineLeft, y, host.box.x + lineRight, y, { stroke: "#000", strokeWidth });
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
loweringEnter(ctx) {
|
|
151
|
+
const count = this.n;
|
|
152
|
+
ctx.beginLoweringGroup(this, {
|
|
153
|
+
onTemporal(node) {
|
|
154
|
+
if (count === 0)
|
|
155
|
+
return;
|
|
156
|
+
const addon = node.addon ??= {};
|
|
157
|
+
addon[DIV_ADDON_KEY] = (Number(addon[DIV_ADDON_KEY]) || 0) + count;
|
|
158
|
+
node.T /= 2 ** count;
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
loweringExit(ctx) {
|
|
164
|
+
ctx.endLoweringGroup(this);
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
content;
|
|
168
|
+
n;
|
|
169
|
+
/** parse 时冻结;只控制不同 div 之间的自动连接,不影响当前 div 内部连接 */
|
|
170
|
+
autoBeamEnabled;
|
|
171
|
+
get children() { return [this.content]; }
|
|
172
|
+
timeFlowModel() {
|
|
173
|
+
return {
|
|
174
|
+
children: [this.content],
|
|
175
|
+
mode: "sequence",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
constructor(sourceSpan, args, ctx, parent = null) {
|
|
179
|
+
super(sourceSpan, parent);
|
|
180
|
+
[this.content, this.n] = this.getArgValue(args, ctx);
|
|
181
|
+
// beam loweringAugment 只读取这个快照,不读取之后可能已经变化的 ParserContext
|
|
182
|
+
this.autoBeamEnabled = parseAutoBeamFlag(ctx.variables["autobeam"]);
|
|
183
|
+
// div 允许修饰任意 都会加下划线
|
|
184
|
+
this.content.parent = this;
|
|
185
|
+
}
|
|
186
|
+
toString(source) {
|
|
187
|
+
return `@div(${this.content.toString(source)}, ${this.n})`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export const DivNode = DivFunction;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { ASTFunctionNode, functionAddonKey } from "../ASTtypes.js";
|
|
2
|
+
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
3
|
+
const DOT_FUNC_NAME = "dot";
|
|
4
|
+
const DOT_ADDON_KEY = functionAddonKey(DOT_FUNC_NAME);
|
|
5
|
+
function durationFactor(count) {
|
|
6
|
+
return 2 - Math.pow(2, -count);
|
|
7
|
+
}
|
|
8
|
+
class DotFunction extends ASTFunctionNode {
|
|
9
|
+
static def = {
|
|
10
|
+
name: [DOT_FUNC_NAME, "."],
|
|
11
|
+
description: "附点",
|
|
12
|
+
example: `@dot(C1, 2): C1右侧创建2个点 仅接收一个可接收元素
|
|
13
|
+
语法糖:在音符后加斜杠'.',可以多个
|
|
14
|
+
@dot(C1, 2) === C1..
|
|
15
|
+
@dot(C1 C2/ @dash(), 2) 报错 因为点只能接收一个元素
|
|
16
|
+
设置命名参数前缀: dot
|
|
17
|
+
`,
|
|
18
|
+
allowExtraArgs: false,
|
|
19
|
+
args: [
|
|
20
|
+
{
|
|
21
|
+
type: "content",
|
|
22
|
+
default: null,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "n",
|
|
26
|
+
type: "number",
|
|
27
|
+
default: 1,
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
};
|
|
31
|
+
static deSugarAtom(source, start, end) {
|
|
32
|
+
// 检查 . 的数量
|
|
33
|
+
let dotCnt = 0;
|
|
34
|
+
let pos = start;
|
|
35
|
+
while (pos < end && source[pos] === '.') {
|
|
36
|
+
dotCnt++;
|
|
37
|
+
pos++;
|
|
38
|
+
}
|
|
39
|
+
if (dotCnt === 0)
|
|
40
|
+
return null;
|
|
41
|
+
// 对前一个节点的探查放到 deSugarRelation 中
|
|
42
|
+
const node = {
|
|
43
|
+
kind: "sugar",
|
|
44
|
+
data: {
|
|
45
|
+
class: DotFunction,
|
|
46
|
+
n: dotCnt,
|
|
47
|
+
},
|
|
48
|
+
span: { start, end: pos },
|
|
49
|
+
};
|
|
50
|
+
return { next: pos, node };
|
|
51
|
+
}
|
|
52
|
+
;
|
|
53
|
+
static deSugarRelation(ctx, nodes, at) {
|
|
54
|
+
const n = nodes[at++];
|
|
55
|
+
if (n.data?.class !== DotFunction)
|
|
56
|
+
return null;
|
|
57
|
+
// 向前找到第一个有效节点
|
|
58
|
+
const prev = ASTFunctionNode.findLastFuncContentNode(ctx.nodes, ctx.nodes.length - 1);
|
|
59
|
+
if (!prev)
|
|
60
|
+
return at; // 没有了 直接当作无效文本跳过
|
|
61
|
+
if (prev instanceof DotFunction) {
|
|
62
|
+
// 已经是dot了 继续加深
|
|
63
|
+
prev.n += n.data.n;
|
|
64
|
+
return at;
|
|
65
|
+
}
|
|
66
|
+
// 参数数量不校验 在构造函数里写
|
|
67
|
+
const argMap = new Map();
|
|
68
|
+
argMap.set(0, prev);
|
|
69
|
+
argMap.set("n", n.data.n);
|
|
70
|
+
const spanPrev = prev.sourceSpan;
|
|
71
|
+
const node = new DotFunction({
|
|
72
|
+
start: Math.min(spanPrev.start, n.span.start),
|
|
73
|
+
end: Math.max(spanPrev.end, n.span.end),
|
|
74
|
+
}, argMap, ctx, null);
|
|
75
|
+
ctx.nodes.pop(); // 消耗掉prev
|
|
76
|
+
ctx.pushNode(node);
|
|
77
|
+
return at;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 附点是目标对象右侧的通用装饰
|
|
81
|
+
* 默认从目标右边界、视觉轴开始排列;目标可用 ports["dot"] 覆盖锚点
|
|
82
|
+
*/
|
|
83
|
+
static layoutDecorationHandler = (host, value) => {
|
|
84
|
+
const count = Math.max(0, Math.floor(Number(value) || 0));
|
|
85
|
+
if (count === 0)
|
|
86
|
+
return null;
|
|
87
|
+
const radius = host.ast.size * 0.075;
|
|
88
|
+
const gap = host.ast.size * 0.12;
|
|
89
|
+
const anchor = host.ports["dot"] ?? {
|
|
90
|
+
x: host.box.w,
|
|
91
|
+
y: host.box.visualAxis,
|
|
92
|
+
};
|
|
93
|
+
const start = anchor.x + gap + radius;
|
|
94
|
+
const step = radius * 2 + gap;
|
|
95
|
+
const right = start + (count - 1) * step + radius;
|
|
96
|
+
// 自定义锚点可能已经位于扩张后的盒内,也可能在盒外
|
|
97
|
+
host.box.w = Math.max(host.box.w, right);
|
|
98
|
+
return {
|
|
99
|
+
paint(painter) {
|
|
100
|
+
const centerY = host.box.y + anchor.y;
|
|
101
|
+
for (let i = 0; i < count; i++) {
|
|
102
|
+
painter.drawCircle(host.box.x + start + i * step, centerY, radius, { fill: "#000" });
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
loweringEnter(ctx) {
|
|
108
|
+
const count = this.n;
|
|
109
|
+
ctx.beginLoweringGroup(this, {
|
|
110
|
+
onTemporal(node) {
|
|
111
|
+
if (count === 0)
|
|
112
|
+
return;
|
|
113
|
+
const addon = node.addon ??= {};
|
|
114
|
+
const current = Number(addon[DOT_ADDON_KEY]) || 0;
|
|
115
|
+
const total = current + count;
|
|
116
|
+
node.T *= durationFactor(total) / durationFactor(current);
|
|
117
|
+
addon[DOT_ADDON_KEY] = total;
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
loweringExit(ctx) {
|
|
123
|
+
ctx.endLoweringGroup(this);
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
timeFlowModel() {
|
|
127
|
+
return {
|
|
128
|
+
children: [this.content],
|
|
129
|
+
mode: "sequence",
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
content;
|
|
133
|
+
n;
|
|
134
|
+
get children() { return [this.content]; }
|
|
135
|
+
constructor(sourceSpan, args, ctx, parent = null) {
|
|
136
|
+
super(sourceSpan, parent);
|
|
137
|
+
[this.content, this.n] = this.getArgValue(args, ctx);
|
|
138
|
+
const contentJudge = DotFunction.leafNum(this.content);
|
|
139
|
+
if (contentJudge !== 1) {
|
|
140
|
+
throw new ErrorDiagnostic("E_DOT_INVALID_CONTENT", `函数 @dot 只能接收 1个元素,但找到了 ${contentJudge} 个`, sourceSpan);
|
|
141
|
+
}
|
|
142
|
+
this.content.parent = this;
|
|
143
|
+
}
|
|
144
|
+
toString(source) {
|
|
145
|
+
return `@dot(${this.content.toString(source)}, ${this.n})`;
|
|
146
|
+
}
|
|
147
|
+
// 判断叶节点数量
|
|
148
|
+
static leafNum(node) {
|
|
149
|
+
let count = 0;
|
|
150
|
+
const chs = node.children;
|
|
151
|
+
if (chs) { // 不是叶节点
|
|
152
|
+
for (const child of chs)
|
|
153
|
+
count += DotFunction.leafNum(child);
|
|
154
|
+
}
|
|
155
|
+
else
|
|
156
|
+
count++;
|
|
157
|
+
return count;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export const DotNode = DotFunction;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { LayoutBox, LayoutPrepareContext } from "../../layout/types.js";
|
|
2
|
+
import type { LoweringContext } from "../../lowering/loweringContext.js";
|
|
3
|
+
import type { Track } from "../../lowering/track.js";
|
|
4
|
+
import { TemporalNodeBase, type LoweringResult, type VisualTemporalNode } from "../../lowering/types.js";
|
|
5
|
+
import { GrammarNode, GrammarSugarNode } from "../../parser/grammarType.js";
|
|
6
|
+
import { ParserContext } from "../../parser/parserContext.js";
|
|
7
|
+
import type { Painter } from "../../render/types.js";
|
|
8
|
+
import { ASTFunctionClass, ASTFunctionNode, ASTNodeBase, FunctionArgs, FunctionDef, SourceSpan } from "../ASTtypes.js";
|
|
9
|
+
type GraceSide = "pre" | "post";
|
|
10
|
+
declare class GraceFunction extends ASTFunctionNode {
|
|
11
|
+
static def: FunctionDef;
|
|
12
|
+
labelable(): this;
|
|
13
|
+
static deSugarAtom(source: string, start: number, _end: number): {
|
|
14
|
+
next: number;
|
|
15
|
+
node: GrammarSugarNode;
|
|
16
|
+
} | null;
|
|
17
|
+
static deSugarRelation(ctx: ParserContext, nodes: (GrammarNode | number)[], at: number): number | null;
|
|
18
|
+
/**
|
|
19
|
+
* 语义确定后,把提升上来的修饰交还给宿主成员
|
|
20
|
+
*
|
|
21
|
+
* lowering 期间修饰必须挂在复合节点上,自动连梁之类的 augmenter 才看得到它的节奏;
|
|
22
|
+
* 但渲染上「宿主代表整个复合体」,减时线要画在宿主音符下面而不是整个盒子下面。
|
|
23
|
+
*/
|
|
24
|
+
static loweringFinalize: (result: LoweringResult) => void;
|
|
25
|
+
host: ASTNodeBase;
|
|
26
|
+
grace: ASTNodeBase;
|
|
27
|
+
side: GraceSide;
|
|
28
|
+
size: number;
|
|
29
|
+
/**
|
|
30
|
+
* `A > B`:前倚音必须左结合,而右操作数是把后续全部解析完才取的,
|
|
31
|
+
* 所以 `1>2>3` 到这里已经成了 `1>(2>3)`。把 A 插回链条最深处就能恢复为 `(1>2)>3`
|
|
32
|
+
*/
|
|
33
|
+
private static attachPre;
|
|
34
|
+
private static create;
|
|
35
|
+
/** 宿主在前:findActiveDivs 下潜子树时要先命中宿主的 @div,而不是倚音的 */
|
|
36
|
+
get children(): ASTNodeBase[];
|
|
37
|
+
constructor(span: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent?: ASTNodeBase | null, scale?: number);
|
|
38
|
+
setGrace(node: ASTNodeBase, factor?: number): void;
|
|
39
|
+
private adopt;
|
|
40
|
+
/** 倚音与宿主各自收敛成可见 Temporal,然后整体折叠进一个复合节点 */
|
|
41
|
+
loweringEnter(ctx: LoweringContext, track: Track): GraceTemporal[];
|
|
42
|
+
toString(source: string): string;
|
|
43
|
+
}
|
|
44
|
+
export declare const GraceNode: ASTFunctionClass;
|
|
45
|
+
/** 倚音复合体:宿主与倚音都折叠在这一个盒子里,对外只是一个可见事件 */
|
|
46
|
+
export declare class GraceTemporal extends TemporalNodeBase {
|
|
47
|
+
ast: GraceFunction;
|
|
48
|
+
box: LayoutBox;
|
|
49
|
+
readonly host: VisualTemporalNode;
|
|
50
|
+
readonly graces: readonly VisualTemporalNode[];
|
|
51
|
+
readonly side: GraceSide;
|
|
52
|
+
/** 成员相对本盒左上角的局部偏移,onPlaced 时同步为绝对坐标 */
|
|
53
|
+
private hostOffset;
|
|
54
|
+
private graceOffsets;
|
|
55
|
+
/** 倚音线起点,同样是局部偏移 */
|
|
56
|
+
private hookOrigin;
|
|
57
|
+
private divLines;
|
|
58
|
+
constructor(ast: GraceFunction, host: VisualTemporalNode, graces: readonly VisualTemporalNode[], side: GraceSide);
|
|
59
|
+
onTimeState(state: Record<string, any>): void;
|
|
60
|
+
/**
|
|
61
|
+
* 播放时倚音从宿主借走的时值(前倚音从开头、后倚音从末尾)
|
|
62
|
+
*
|
|
63
|
+
* 比例 = 倚音字面总时值 / 四分音符,而四分音符 T=1,所以直接累加成员的 T。
|
|
64
|
+
* 基准取宿主经过 div 与 dot 后的实际时值;延时线是独立事件、tie 不改 T,天然不计入。
|
|
65
|
+
*/
|
|
66
|
+
get stealTime(): number;
|
|
67
|
+
/**
|
|
68
|
+
* 宿主留在轨道基线上,倚音整体抬到它的左上或右上角
|
|
69
|
+
*
|
|
70
|
+
* 倚音成员之间自己紧排,不参与横向弹簧;整块的宽度计入复合盒,
|
|
71
|
+
* 因此左右邻居会被固有宽度推开,不会在空间紧张时被压穿。
|
|
72
|
+
*/
|
|
73
|
+
prepareLayout(context: LayoutPrepareContext): void;
|
|
74
|
+
/**
|
|
75
|
+
* 把相邻倚音成员的同级减时线连成整条
|
|
76
|
+
*
|
|
77
|
+
* 折叠成员不进入全局时间列,自动连梁看不到它们,只能由复合体自己连。
|
|
78
|
+
*/
|
|
79
|
+
private connectGraceDivLines;
|
|
80
|
+
/** 引擎每次改变本节点坐标后,按准备阶段保存的局部偏移重算成员绝对坐标 */
|
|
81
|
+
onPlaced(): void;
|
|
82
|
+
paint(painter: Painter): void;
|
|
83
|
+
}
|
|
84
|
+
export {};
|