jpfun 1.0.0 → 1.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/README.md +1 -1
- package/dist/functions/bar/index.js +3 -0
- package/dist/functions/default.js +2 -1
- package/dist/functions/gliss/index.js +81 -7
- package/dist/functions/grace/index.d.ts +1 -8
- package/dist/functions/grace/index.js +20 -48
- package/dist/functions/key/index.js +1 -0
- package/dist/functions/note/index.d.ts +5 -2
- package/dist/functions/note/index.js +158 -13
- package/dist/functions/note/source-transform.d.ts +8 -2
- package/dist/functions/note/source-transform.js +25 -11
- package/dist/functions/page/index.d.ts +1 -36
- package/dist/functions/page/index.js +4 -4
- package/dist/functions/set/index.js +2 -2
- package/dist/functions/stack/index.js +6 -4
- package/dist/functions/temporal.d.ts +3 -0
- package/dist/functions/text/index.js +2 -2
- package/dist/functions/up/index.js +9 -7
- package/dist/functions/voice/connections.js +2 -2
- package/dist/functions/voice/lyrics.d.ts +2 -0
- package/dist/functions/voice/lyrics.js +4 -4
- package/dist/functions/voice/voice.js +2 -2
- package/dist/functions/voice/voices.d.ts +2 -1
- package/dist/functions/voice/voices.js +2 -2
- package/dist/index.d.ts +6 -34
- package/dist/index.js +6 -34
- package/dist/jpfun.min.js +41 -41
- package/dist/layout/engine.js +13 -21
- package/dist/layout/model.d.ts +1 -1
- package/dist/layout/types.d.ts +2 -1
- package/dist/lowering/accidentalMemory.d.ts +33 -0
- package/dist/lowering/accidentalMemory.js +84 -0
- package/dist/lowering/loweringContext.js +4 -0
- package/dist/parser/grammarType.d.ts +6 -1
- package/dist/parser/parse-utils/string-utils.d.ts +1 -1
- package/dist/parser/parse-utils/string-utils.js +1 -1
- package/dist/parser/parserContext.d.ts +25 -25
- package/dist/parser/parserContext.js +54 -146
- package/dist/parser/preprocess.js +10 -23
- package/dist/parser/syntax.d.ts +9 -0
- package/dist/parser/syntax.js +109 -0
- package/dist/pipeline.js +3 -2
- package/dist/playback/compile.js +4 -6
- package/dist/playback/event.d.ts +1 -2
- package/dist/playback/event.js +2 -3
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.js +1 -0
- package/grammar.md +1 -0
- package/package.json +1 -1
- package/dist/functions/voice/index.d.ts +0 -2
- package/dist/functions/voice/index.js +0 -2
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
2
2
|
import { preprocessSource } from "../../parser/preprocess.js";
|
|
3
3
|
import { callArgName, readCall } from "../../parser/parse-utils/call-utils.js";
|
|
4
|
-
import { findClosingQuote,
|
|
4
|
+
import { findClosingQuote, quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
5
5
|
import { FLAT_NOTE_NAMES, NOTE_LETTERS, NoteNameMap, SHARP_NOTE_NAMES, normalizeAccidentalOffset, offsetToAccidental, resolveLetterNameToJianpu, tonality2Midi, wrapPitchClass, } from "../../parser/parse-utils/note-utils.js";
|
|
6
6
|
import { parseNoteName } from "./noteName.js";
|
|
7
7
|
function fail(span) {
|
|
8
8
|
throw new ErrorDiagnostic("E_NOTE_TRANSFORM", "无法安全改写此音符的音高", span);
|
|
9
9
|
}
|
|
10
|
+
/** 未传 ranges 视为全选;否则音符须完整落入任一选区 */
|
|
11
|
+
export function selects(ranges, span) {
|
|
12
|
+
return !ranges || ranges.some(range => range.start <= span.start && range.end >= span.end);
|
|
13
|
+
}
|
|
10
14
|
/** 音高计算只读固化事实;互转保留调内级数,半音操作采用最少升降号的拼写 */
|
|
11
15
|
function targetPitch(note, operation) {
|
|
12
16
|
const absolute = operation === "to-absolute"
|
|
@@ -32,6 +36,8 @@ function targetPitch(note, operation) {
|
|
|
32
36
|
if (!relative)
|
|
33
37
|
fail(ast.sourceSpan);
|
|
34
38
|
({ renderName: name, renderAcc: acc, renderOctave: octave } = relative);
|
|
39
|
+
// carry 下按显示的记号写出,数字音名读回来音高不变
|
|
40
|
+
acc = note.displayAcc ?? acc;
|
|
35
41
|
}
|
|
36
42
|
else {
|
|
37
43
|
const value = absolute ? midi : midi - tonic;
|
|
@@ -96,8 +102,10 @@ export function rewriteNoteCall(source, masked, call, pitch, hasDefaultAcc, edit
|
|
|
96
102
|
const accSlot = slots.get("acc") ?? slots.get(1);
|
|
97
103
|
const octaveSlot = slots.get("octave") ?? slots.get(2);
|
|
98
104
|
const additions = [];
|
|
99
|
-
const valueText = (value, slot) => !value || value.includes(",") || slot && source[slot.start] === '"' ?
|
|
100
|
-
|
|
105
|
+
const valueText = (value, slot) => !value || value.includes(",") || slot && source[slot.start] === '"' ? quoteSourceString(value) : value;
|
|
106
|
+
// name 末尾的 `!`(force)不属于音高,原样保留
|
|
107
|
+
const bang = nameSlot && /!"?$/.test(source.slice(nameSlot.start, nameSlot.end)) ? "!" : "";
|
|
108
|
+
const name = pitchToken(pitch, !accSlot && !hasDefaultAcc, !octaveSlot) + bang;
|
|
101
109
|
if (nameSlot)
|
|
102
110
|
pushEdit(edits, source, masked, nameSlot, valueText(name, nameSlot));
|
|
103
111
|
else
|
|
@@ -105,7 +113,7 @@ export function rewriteNoteCall(source, masked, call, pitch, hasDefaultAcc, edit
|
|
|
105
113
|
if (accSlot)
|
|
106
114
|
pushEdit(edits, source, masked, accSlot, valueText(pitch.acc, accSlot));
|
|
107
115
|
else if (hasDefaultAcc)
|
|
108
|
-
additions.push(`acc=${
|
|
116
|
+
additions.push(`acc=${quoteSourceString(pitch.acc)}`);
|
|
109
117
|
if (octaveSlot)
|
|
110
118
|
pushEdit(edits, source, masked, octaveSlot, String(pitch.octave));
|
|
111
119
|
if (additions.length) {
|
|
@@ -115,8 +123,11 @@ export function rewriteNoteCall(source, masked, call, pitch, hasDefaultAcc, edit
|
|
|
115
123
|
}
|
|
116
124
|
return edits;
|
|
117
125
|
}
|
|
118
|
-
/**
|
|
119
|
-
|
|
126
|
+
/**
|
|
127
|
+
* edits 始终引用原文;参数只改值,默认参数只在当前调用覆盖,避免影响其他音符。
|
|
128
|
+
* pins 给指定音符强制写出升降号(升降半音后为保持 carry 下其他音高不变而补记)
|
|
129
|
+
*/
|
|
130
|
+
export function rewriteNotes(source, notes, operation, ranges, pins) {
|
|
120
131
|
const { maskedSource: masked } = preprocessSource(source);
|
|
121
132
|
const edits = [];
|
|
122
133
|
const tokens = [];
|
|
@@ -129,16 +140,19 @@ export function rewriteNotes(source, notes, operation, ranges) {
|
|
|
129
140
|
|| operation === "to-relative" && /^[1-7]$/.test(ast.name);
|
|
130
141
|
if (!explicit)
|
|
131
142
|
tokens.push({ span, text: source.slice(span.start, span.end) });
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (
|
|
143
|
+
const pin = pins?.get(ast);
|
|
144
|
+
const selected = selects(ranges, span) && note.resolvedMidi !== null && !already;
|
|
145
|
+
if (!selected && pin === undefined)
|
|
135
146
|
continue;
|
|
136
|
-
const pitch = targetPitch(note, operation);
|
|
147
|
+
const pitch = selected ? targetPitch(note, operation) : { name: ast.name, acc: ast.acc, octave: ast.octave, absolute: false };
|
|
148
|
+
if (pin !== undefined)
|
|
149
|
+
pitch.acc = pin;
|
|
137
150
|
if (explicit) {
|
|
138
151
|
rewriteNoteCall(source, masked, call, pitch, ast.hasDefaultAcc, edits);
|
|
139
152
|
continue;
|
|
140
153
|
}
|
|
141
|
-
|
|
154
|
+
// 简写末尾的 `!`(force)不属于音高,原样保留
|
|
155
|
+
let text = pitchToken(pitch) + (source[span.end - 1] === "!" ? "!" : "");
|
|
142
156
|
if (text.includes(",") && needsBraces(masked, ast))
|
|
143
157
|
text = `{${text}}`;
|
|
144
158
|
tokens[tokens.length - 1].text = text;
|
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { PageConfig } from "../../layout/types.js";
|
|
3
|
-
import { ASTFunctionNode, type ASTFunctionClass, type ASTNodeBase, type FunctionArgs, type LengthValue, type ParserContext, type SourceSpan } from "../ASTtypes.js";
|
|
4
|
-
/** 页码字号,同时也是放得下页码所需的最小下边距 */
|
|
5
|
-
export declare const PAGE_NUMBER_FONT_SIZE = 16;
|
|
6
|
-
export declare class PageFunction extends ASTFunctionNode {
|
|
7
|
-
static def: {
|
|
8
|
-
name: string[];
|
|
9
|
-
description: string;
|
|
10
|
-
details: string;
|
|
11
|
-
allowExtraArgs: boolean;
|
|
12
|
-
args: ({
|
|
13
|
-
name: string;
|
|
14
|
-
description: string;
|
|
15
|
-
type: "length";
|
|
16
|
-
default: LengthValue;
|
|
17
|
-
} | {
|
|
18
|
-
name: string;
|
|
19
|
-
description: string;
|
|
20
|
-
type: "string";
|
|
21
|
-
default: string;
|
|
22
|
-
} | {
|
|
23
|
-
name: string;
|
|
24
|
-
description: string;
|
|
25
|
-
type: "number";
|
|
26
|
-
default: number;
|
|
27
|
-
})[];
|
|
28
|
-
};
|
|
29
|
-
readonly config: PageConfig | null;
|
|
30
|
-
private readonly numbering;
|
|
31
|
-
private readonly barNumbering;
|
|
32
|
-
readonly font: string;
|
|
33
|
-
constructor(sourceSpan: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent?: ASTNodeBase | null);
|
|
34
|
-
loweringEnter(ctx: LoweringContext): never[];
|
|
35
|
-
toString(): string;
|
|
36
|
-
}
|
|
1
|
+
import { type ASTFunctionClass } from "../ASTtypes.js";
|
|
37
2
|
export declare const PageNode: ASTFunctionClass;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { DEFAULT_PAGE_CONFIG, normalizePageConfig, } from "../../layout/page.js";
|
|
2
2
|
import { ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
|
|
3
|
-
import {
|
|
3
|
+
import { quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
4
4
|
import { registerBarNumbering } from "../bar/index.js";
|
|
5
5
|
import { ASTFunctionNode, } from "../ASTtypes.js";
|
|
6
6
|
const px = (value) => ({ value, unit: "px" });
|
|
7
7
|
/** 页码字号,同时也是放得下页码所需的最小下边距 */
|
|
8
|
-
|
|
8
|
+
const PAGE_NUMBER_FONT_SIZE = 16;
|
|
9
9
|
const PAGE_NUMBER_STYLE = { fontSize: PAGE_NUMBER_FONT_SIZE, textAlign: "center", fill: "#606060" };
|
|
10
10
|
/** 单个 1 取当前页;多个 1 中最后一个取总页数,其余取当前页 */
|
|
11
11
|
function formatPageNumber(pattern, current, total) {
|
|
@@ -44,7 +44,7 @@ class PageNumberAttachment {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
class PageFunction extends ASTFunctionNode {
|
|
48
48
|
static def = {
|
|
49
49
|
name: ["page"],
|
|
50
50
|
description: "设置文档页面",
|
|
@@ -135,7 +135,7 @@ export class PageFunction extends ASTFunctionNode {
|
|
|
135
135
|
if (!this.config)
|
|
136
136
|
return "@page()";
|
|
137
137
|
const { width, height, marginTop, marginBottom, marginLeft, marginRight, lineGap, minLineGap, fillRatio } = this.config;
|
|
138
|
-
return `@page(width=${width}px, height=${Number.isFinite(height) ? height : 0}px, top=${marginTop}px, bottom=${marginBottom}px, left=${marginLeft}px, right=${marginRight}px, gap=${lineGap}px, minGap=${minLineGap}px, numbering=${
|
|
138
|
+
return `@page(width=${width}px, height=${Number.isFinite(height) ? height : 0}px, top=${marginTop}px, bottom=${marginBottom}px, left=${marginLeft}px, right=${marginRight}px, gap=${lineGap}px, minGap=${minLineGap}px, numbering=${quoteSourceString(this.numbering)}, barNumbering=${quoteSourceString(this.barNumbering)}, font=${quoteSourceString(this.font)}, fillRatio=${fillRatio})`;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
export const PageNode = PageFunction;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASTFunctionNode, primaryName, resolveArgType } from "../ASTtypes.js";
|
|
2
2
|
import { WarningDiagnostic } from "../../diagnostic.js";
|
|
3
|
-
import {
|
|
3
|
+
import { quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
4
4
|
import { ParserContext } from "../../parser/parserContext.js";
|
|
5
5
|
class SetFunction extends ASTFunctionNode {
|
|
6
6
|
static def = {
|
|
@@ -63,7 +63,7 @@ class SetFunction extends ASTFunctionNode {
|
|
|
63
63
|
}
|
|
64
64
|
toString() {
|
|
65
65
|
return `@set(${Array.from(this.args, ([key, value]) => {
|
|
66
|
-
const text = typeof value === "string" ?
|
|
66
|
+
const text = typeof value === "string" ? quoteSourceString(value)
|
|
67
67
|
: value && typeof value === "object" && "unit" in value ? `${value.value}${value.unit}` : value;
|
|
68
68
|
return `${key}=${text}`;
|
|
69
69
|
}).join(", ")})`;
|
|
@@ -72,10 +72,12 @@ class StackFunction extends ASTFunctionNode {
|
|
|
72
72
|
const host = leftNode instanceof StackFunction
|
|
73
73
|
? leftNode
|
|
74
74
|
: new StackFunction(n.span, new Map(), ctx).addContent(leftNode);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
ctx.deferRightOperand(right => {
|
|
76
|
+
if (!right)
|
|
77
|
+
throw new ErrorDiagnostic("E_STACK_NO_TARGET", "@stack语法糖错误: 右边没有找到可叠加的目标", n.span);
|
|
78
|
+
return host.addContent(right);
|
|
79
|
+
});
|
|
80
|
+
return at;
|
|
79
81
|
}
|
|
80
82
|
contents = [];
|
|
81
83
|
get children() { return this.contents; }
|
|
@@ -6,6 +6,7 @@ import { type ASTNodeBase } from "./ASTtypes.js";
|
|
|
6
6
|
import { Fraction } from "../fraction.js";
|
|
7
7
|
import type { HorizontalSpringConfig, LayoutBox, LayoutDecoration, LayoutHost, LayoutPoint, LayoutPrepareContext, HorizontalLineView, TimeLineEvent } from "../layout/types.js";
|
|
8
8
|
import type { Track } from "../lowering/track.js";
|
|
9
|
+
import type { AccidentalMemory } from "../lowering/accidentalMemory.js";
|
|
9
10
|
import type { PlaybackEmitter, PlaybackState } from "../playback/types.js";
|
|
10
11
|
import type { Painter } from "../render/types.js";
|
|
11
12
|
/**
|
|
@@ -21,6 +22,8 @@ export interface TimeState {
|
|
|
21
22
|
velocity: number;
|
|
22
23
|
keySignature: string;
|
|
23
24
|
program: number;
|
|
25
|
+
/** 小节内变音记忆。系统字段,由 solidifyColumns 创建,任何时刻都能直接读写 */
|
|
26
|
+
accidentals: AccidentalMemory;
|
|
24
27
|
/** 当前小节时长(QN);尚无显式拍号或散板时为 undefined */
|
|
25
28
|
meter?: Fraction;
|
|
26
29
|
[key: string]: any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASTFunctionNode } from "../ASTtypes.js";
|
|
2
2
|
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
3
|
-
import { findClosingQuote,
|
|
3
|
+
import { findClosingQuote, quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
4
4
|
import { DEFAULT_KEY, TemporalNodeBase } from "../temporal.js";
|
|
5
5
|
import { paintRichLine, parseRichText, prepareRichLine } from "../../render/text.js";
|
|
6
6
|
class TextFunction extends ASTFunctionNode {
|
|
@@ -92,7 +92,7 @@ class TextFunction extends ASTFunctionNode {
|
|
|
92
92
|
}
|
|
93
93
|
loweringEnter() { return [new TextTemporalNode(this)]; }
|
|
94
94
|
toString() {
|
|
95
|
-
return `@text(${
|
|
95
|
+
return `@text(${quoteSourceString(this.text)}, size=${this.size}px, lineheight=${this.lineHeight}, align=${this.align}, font=${quoteSourceString(this.font)})`;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
export const TextNode = TextFunction;
|
|
@@ -116,7 +116,7 @@ class FoldFunction extends ASTFunctionNode {
|
|
|
116
116
|
*
|
|
117
117
|
* 被掏空的一方必须撤销候选登记:空壳已不在 AST 里,留在表中会让 @tie() 取到孤儿端点。
|
|
118
118
|
*/
|
|
119
|
-
flatten(drop, side, ctx, gap = this.gap) {
|
|
119
|
+
flatten(drop, side, ctx, gap = this.gap, registered = true) {
|
|
120
120
|
// 成员顺序跟随源码;比较必须在 growSpan 之前
|
|
121
121
|
const front = drop.sourceSpan.start < this.sourceSpan.start ? drop : this;
|
|
122
122
|
const back = front === drop ? this : drop;
|
|
@@ -133,6 +133,8 @@ class FoldFunction extends ASTFunctionNode {
|
|
|
133
133
|
c.parent = this;
|
|
134
134
|
this.growSpan(drop.sourceSpan);
|
|
135
135
|
drop.contents.length = drop.belows.length = drop.aboveGaps.length = drop.belowGaps.length = 0;
|
|
136
|
+
if (!registered)
|
|
137
|
+
return this; // 语法糖新建的左包装从未入表;合成在本层末尾,整表扫描会让平放和弦变成平方级
|
|
136
138
|
const stale = ctx.labelableNodes.lastIndexOf(drop);
|
|
137
139
|
if (stale >= 0)
|
|
138
140
|
ctx.labelableNodes.splice(stale, 1);
|
|
@@ -155,19 +157,19 @@ class FoldFunction extends ASTFunctionNode {
|
|
|
155
157
|
const host = leftNode instanceof FoldFunction
|
|
156
158
|
? leftNode
|
|
157
159
|
: wrapper.addContent(leftNode, "above", ctx);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
ctx.deferRightOperand(right => {
|
|
161
|
+
if (!right)
|
|
162
|
+
throw new ErrorDiagnostic("E_FOLD_NO_TARGET", "{fn}语法糖错误: 右边没有找到可叠加的目标", n.span, { fn: label });
|
|
163
|
+
// 右操作数可能已被 @tie() 等按引用取走(它就在本层剩余部分里,先于合成解析),
|
|
160
164
|
// 而新建的左包装无人引用,所以合并时让右边存活;接收者就是存活的那一方
|
|
161
165
|
const merged = right instanceof FoldFunction
|
|
162
|
-
? right.flatten(host, this.side, ctx, wrapper.gap)
|
|
166
|
+
? right.flatten(host, this.side, ctx, wrapper.gap, host !== wrapper)
|
|
163
167
|
: host.addContent(right, this.side, ctx, wrapper.gap);
|
|
164
168
|
// 语法糖不走 pushNode,这里补登记;null 同样入表,和显式调用一样成为边界
|
|
165
169
|
ctx.labelableNodes.push(merged.labelable());
|
|
166
170
|
return merged;
|
|
167
171
|
});
|
|
168
|
-
|
|
169
|
-
return next;
|
|
170
|
-
throw new ErrorDiagnostic("E_FOLD_NO_TARGET", "{fn}语法糖错误: 右边没有找到可叠加的目标", n.span, { fn: label });
|
|
172
|
+
return at;
|
|
171
173
|
}
|
|
172
174
|
}
|
|
173
175
|
class UpFunction extends FoldFunction {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
2
2
|
import { pathBounds } from "../../layout/path.js";
|
|
3
|
-
import { findClosingQuote, parseString,
|
|
3
|
+
import { findClosingQuote, parseString, quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
4
4
|
export const CURVED_BRACE_COMMANDS = [
|
|
5
5
|
{ op: "M", x: 2.98438, y: -165.5 },
|
|
6
6
|
{ op: "C", cx1: 8.9375, cy1: -171.781, cx2: 20.5156, cy2: -184.688, x: 20.5156, y: -208.531 },
|
|
@@ -121,7 +121,7 @@ export function resolveConnections(specs, count, span) {
|
|
|
121
121
|
}
|
|
122
122
|
export function serializeConnections(specs) {
|
|
123
123
|
return specs.map(({ kind, from, to, name }) => {
|
|
124
|
-
const label = !name ? "" : `:${FORBIDDEN_RAW_NAME_RE.test(name) || name.trim() !== name ?
|
|
124
|
+
const label = !name ? "" : `:${FORBIDDEN_RAW_NAME_RE.test(name) || name.trim() !== name ? quoteSourceString(name) : name}`;
|
|
125
125
|
const range = `${from ?? ""}-${to ?? ""}${label}`;
|
|
126
126
|
return kind === "brace" ? `{${range}}` : `[${range}]`;
|
|
127
127
|
}).join("");
|
|
@@ -6,6 +6,8 @@ import type { VisualTemporalNode } from "../temporal.js";
|
|
|
6
6
|
import type { VoiceNameTemporal } from "./voice.js";
|
|
7
7
|
/** 歌词与歌词行名称相对声部字号的字号 */
|
|
8
8
|
export declare const LYRIC_SIZE_RATIO = 0.88;
|
|
9
|
+
export declare const LYRIC_OPENING_PUNCTUATION: Set<string>;
|
|
10
|
+
export declare const LYRIC_SILENT_PUNCTUATION: Set<string>;
|
|
9
11
|
/** 歌词行名称与歌词正文共用同一个基础样式 */
|
|
10
12
|
export declare function lyricNameStyle(size: number, fontFamily: string): TextStyle;
|
|
11
13
|
export type LyricSlot = RichTextRun[] | null;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getLayoutBounds } from "../../layout/engine.js";
|
|
2
|
-
import {
|
|
2
|
+
import { quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
3
3
|
import { appendRun, markdownToggles, paintRichLine, prepareRichLine, scanMarkdown, } from "../../render/text.js";
|
|
4
4
|
const WHITESPACE_RE = /\s/;
|
|
5
5
|
/** 歌词与歌词行名称相对声部字号的字号 */
|
|
6
6
|
export const LYRIC_SIZE_RATIO = 0.88;
|
|
7
7
|
// 分词跟后面的标点
|
|
8
|
-
const LYRIC_OPENING_PUNCTUATION = new Set("(([
|
|
8
|
+
export const LYRIC_OPENING_PUNCTUATION = new Set("(([[{〈《「『【〔〖〘〚‘“⒈⒉⒊⒋⒌");
|
|
9
9
|
// 不发声的标点;位于歌词槽首尾时只渲染,不占位,也不参与对齐中心计算
|
|
10
|
-
const LYRIC_SILENT_PUNCTUATION = new Set([
|
|
10
|
+
export const LYRIC_SILENT_PUNCTUATION = new Set([
|
|
11
11
|
...LYRIC_OPENING_PUNCTUATION,
|
|
12
12
|
...",。!?;:、,.!?;:))]]}〉》」』】〕〗〙〛’”\"'…—–",
|
|
13
13
|
]);
|
|
@@ -198,7 +198,7 @@ export function parseLyric(value, offsets, tokenSpans) {
|
|
|
198
198
|
return result;
|
|
199
199
|
}
|
|
200
200
|
export function serializeLyric(tokens) {
|
|
201
|
-
return
|
|
201
|
+
return quoteSourceString(tokens.flatMap((runs, i) => {
|
|
202
202
|
if (runs === null)
|
|
203
203
|
return [];
|
|
204
204
|
if (runs.length === 0)
|
|
@@ -2,7 +2,7 @@ import { ASTBraceNode, ASTFunctionNode, ASTTextNode } from "../ASTtypes.js";
|
|
|
2
2
|
import { Diagnostic, ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
|
|
3
3
|
import { isLayoutAttachment } from "../../layout/types.js";
|
|
4
4
|
import { findRightParen, trimRange } from "../../parser/parse-utils/call-utils.js";
|
|
5
|
-
import { findClosingQuote,
|
|
5
|
+
import { findClosingQuote, quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
6
6
|
import { ParserContext, skipSpaces } from "../../parser/parserContext.js";
|
|
7
7
|
import { paintRichLine, prepareRichLine } from "../../render/text.js";
|
|
8
8
|
import { isVisualTemporalNode, TemporalNodeBase } from "../temporal.js";
|
|
@@ -350,7 +350,7 @@ L: la la la
|
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
toString(source) {
|
|
353
|
-
const parameters = [`${this.content.toString(source)},${
|
|
353
|
+
const parameters = [`${this.content.toString(source)},${quoteSourceString(this.name)}`];
|
|
354
354
|
for (const lyric of this.lyrics) {
|
|
355
355
|
const text = serializeLyric(lyric.tokens);
|
|
356
356
|
parameters.push(lyric.name ? `${lyric.name}=${text}` : text);
|
|
@@ -3,6 +3,7 @@ import type { LoweringContext } from "../../lowering/loweringContext.js";
|
|
|
3
3
|
import type { MeasureFn, Track } from "../../lowering/track.js";
|
|
4
4
|
import type { GrammarNode } from "../../parser/grammarType.js";
|
|
5
5
|
import { ParserContext } from "../../parser/parserContext.js";
|
|
6
|
+
import { type ConnectionSpec } from "./connections.js";
|
|
6
7
|
import { VoiceFunction } from "./voice.js";
|
|
7
8
|
/**
|
|
8
9
|
* voices 块在宿主基线上局部居中:首末两条 voice 基线的中点对齐宿主轴
|
|
@@ -85,7 +86,7 @@ export declare class VoicesFunction extends ASTFunctionNode {
|
|
|
85
86
|
private readonly connect;
|
|
86
87
|
/** 声部名右侧为大括号预留的横向空间 */
|
|
87
88
|
get braceSpace(): number;
|
|
88
|
-
|
|
89
|
+
get connectionSpecs(): ConnectionSpec[];
|
|
89
90
|
get children(): VoiceFunction[];
|
|
90
91
|
timeFlowModel(): {
|
|
91
92
|
children: VoiceFunction[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASTFunctionNode, ASTTextNode } from "../ASTtypes.js";
|
|
2
2
|
import { ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
|
|
3
|
-
import { findClosingQuote,
|
|
3
|
+
import { findClosingQuote, quoteSourceString } from "../../parser/parse-utils/string-utils.js";
|
|
4
4
|
import { ParserContext } from "../../parser/parserContext.js";
|
|
5
5
|
import { paintRichLine, prepareRichLine } from "../../render/text.js";
|
|
6
6
|
import { BRACKET_HOOK_COMMANDS, BRACKET_HOOK_DROP, BRACKET_HOOK_REACH, CURVED_BRACE_BOUNDS, CURVED_BRACE_COMMANDS, parseConnections, resolveConnections, serializeConnections, } from "./connections.js";
|
|
@@ -272,7 +272,7 @@ N(女低): 1 2 3
|
|
|
272
272
|
}
|
|
273
273
|
toString(source) {
|
|
274
274
|
const parameters = this.voices.map(voice => `\t${voice.toString(source)}`);
|
|
275
|
-
parameters.push(`\tconnect=${
|
|
275
|
+
parameters.push(`\tconnect=${quoteSourceString(serializeConnections(this.connectionSpecs))}`, `\tgap=${this.gap}px`, `\tminGap=${this.minGap}px`);
|
|
276
276
|
return `@voices(\n${parameters.join(",\n")}\n)`;
|
|
277
277
|
}
|
|
278
278
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,25 +4,20 @@ export * from "./functions/temporal.js";
|
|
|
4
4
|
export * from "./functions/default.js";
|
|
5
5
|
export * from "./functions/adjust/index.js";
|
|
6
6
|
export * from "./functions/arpeggio/index.js";
|
|
7
|
-
export
|
|
8
|
-
export * from "./functions/bar/index.js";
|
|
7
|
+
export { BarNode } from "./functions/bar/index.js";
|
|
9
8
|
export * from "./functions/beam/index.js";
|
|
10
|
-
export * from "./functions/beam/auto.js";
|
|
11
|
-
export * from "./functions/beam/layout.js";
|
|
12
9
|
export * from "./functions/box/index.js";
|
|
13
10
|
export * from "./functions/br/index.js";
|
|
14
11
|
export * from "./functions/dash/index.js";
|
|
15
|
-
export
|
|
12
|
+
export { DivNode } from "./functions/div/index.js";
|
|
16
13
|
export * from "./functions/dot/index.js";
|
|
17
14
|
export * from "./functions/dyn/index.js";
|
|
18
15
|
export * from "./functions/gliss/index.js";
|
|
19
16
|
export * from "./functions/grace/index.js";
|
|
20
17
|
export * from "./functions/head/index.js";
|
|
21
18
|
export * from "./functions/key/index.js";
|
|
22
|
-
export
|
|
23
|
-
export * from "./functions/meter/shape.js";
|
|
19
|
+
export { MeterNode } from "./functions/meter/index.js";
|
|
24
20
|
export * from "./functions/note/index.js";
|
|
25
|
-
export * from "./functions/note/accidentals.js";
|
|
26
21
|
export * from "./functions/note/noteName.js";
|
|
27
22
|
export * from "./functions/note/source-transform.js";
|
|
28
23
|
export * from "./functions/ottava/index.js";
|
|
@@ -34,28 +29,7 @@ export * from "./functions/set/index.js";
|
|
|
34
29
|
export * from "./functions/slide/index.js";
|
|
35
30
|
export * from "./functions/stack/index.js";
|
|
36
31
|
export * from "./functions/symbol/index.js";
|
|
37
|
-
export * from "./functions/symbol/ornament.js";
|
|
38
|
-
export * from "./functions/symbol/shape.js";
|
|
39
|
-
export * from "./functions/symbol/symbols/accent.js";
|
|
40
|
-
export * from "./functions/symbol/symbols/coda.js";
|
|
41
|
-
export * from "./functions/symbol/symbols/dc.js";
|
|
42
|
-
export * from "./functions/symbol/symbols/ds.js";
|
|
43
|
-
export * from "./functions/symbol/symbols/dynamics.js";
|
|
44
|
-
export * from "./functions/symbol/symbols/fermata.js";
|
|
45
|
-
export * from "./functions/symbol/symbols/fine.js";
|
|
46
|
-
export * from "./functions/symbol/symbols/harmonic.js";
|
|
47
|
-
export * from "./functions/symbol/symbols/marcato.js";
|
|
48
|
-
export * from "./functions/symbol/symbols/mordent.js";
|
|
49
|
-
export * from "./functions/symbol/symbols/prall.js";
|
|
50
|
-
export * from "./functions/symbol/symbols/segno.js";
|
|
51
|
-
export * from "./functions/symbol/symbols/staccato.js";
|
|
52
|
-
export * from "./functions/symbol/symbols/tenuto.js";
|
|
53
|
-
export * from "./functions/symbol/symbols/tocoda.js";
|
|
54
|
-
export * from "./functions/symbol/symbols/tr.js";
|
|
55
|
-
export * from "./functions/symbol/symbols/turn.js";
|
|
56
|
-
export * from "./functions/symbol/symbols/wheel.js";
|
|
57
32
|
export * from "./functions/tempo/index.js";
|
|
58
|
-
export * from "./functions/tempo/glyph.js";
|
|
59
33
|
export * from "./functions/text/index.js";
|
|
60
34
|
export * from "./functions/tie/index.js";
|
|
61
35
|
export * from "./functions/tremolo/index.js";
|
|
@@ -63,7 +37,7 @@ export * from "./functions/tuplet/index.js";
|
|
|
63
37
|
export * from "./functions/up/index.js";
|
|
64
38
|
export * from "./functions/voice/voice.js";
|
|
65
39
|
export * from "./functions/voice/voices.js";
|
|
66
|
-
export
|
|
40
|
+
export { parseConnections, resolveConnections, serializeConnections, type ConnectionSpec, type VoiceConnection, } from "./functions/voice/connections.js";
|
|
67
41
|
export * from "./functions/voice/lyrics.js";
|
|
68
42
|
export * from "./functions/volta/index.js";
|
|
69
43
|
export * from "./diagnostic.js";
|
|
@@ -78,20 +52,18 @@ export * from "./parser/parse-utils/label-utils.js";
|
|
|
78
52
|
export * from "./parser/parse-utils/length-utils.js";
|
|
79
53
|
export * from "./parser/parse-utils/note-utils.js";
|
|
80
54
|
export * from "./parser/parse-utils/string-utils.js";
|
|
81
|
-
export { quote as quoteSourceString } from "./parser/parse-utils/string-utils.js";
|
|
82
55
|
export * from "./lowering/types.js";
|
|
83
56
|
export * from "./lowering/loweringContext.js";
|
|
84
57
|
export * from "./lowering/track.js";
|
|
58
|
+
export * from "./lowering/accidentalMemory.js";
|
|
85
59
|
export * from "./playback/types.js";
|
|
86
|
-
export * from "./playback/event.js";
|
|
87
60
|
export * from "./playback/time.js";
|
|
88
61
|
export * from "./playback/compile.js";
|
|
89
62
|
export * from "./layout/types.js";
|
|
90
63
|
export * from "./layout/model.js";
|
|
91
64
|
export * from "./layout/default.js";
|
|
92
|
-
export
|
|
65
|
+
export { DEFAULT_PAGE_CONFIG, normalizePageConfig, paginateLayoutLines, type DocumentLayoutPage, } from "./layout/page.js";
|
|
93
66
|
export * from "./layout/engine.js";
|
|
94
67
|
export * from "./layout/path.js";
|
|
95
68
|
export * from "./layout/range.js";
|
|
96
69
|
export * from "./render/index.js";
|
|
97
|
-
export * from "./render/translate.js";
|
package/dist/index.js
CHANGED
|
@@ -4,25 +4,20 @@ export * from "./functions/temporal.js";
|
|
|
4
4
|
export * from "./functions/default.js";
|
|
5
5
|
export * from "./functions/adjust/index.js";
|
|
6
6
|
export * from "./functions/arpeggio/index.js";
|
|
7
|
-
export
|
|
8
|
-
export * from "./functions/bar/index.js";
|
|
7
|
+
export { BarNode } from "./functions/bar/index.js";
|
|
9
8
|
export * from "./functions/beam/index.js";
|
|
10
|
-
export * from "./functions/beam/auto.js";
|
|
11
|
-
export * from "./functions/beam/layout.js";
|
|
12
9
|
export * from "./functions/box/index.js";
|
|
13
10
|
export * from "./functions/br/index.js";
|
|
14
11
|
export * from "./functions/dash/index.js";
|
|
15
|
-
export
|
|
12
|
+
export { DivNode } from "./functions/div/index.js";
|
|
16
13
|
export * from "./functions/dot/index.js";
|
|
17
14
|
export * from "./functions/dyn/index.js";
|
|
18
15
|
export * from "./functions/gliss/index.js";
|
|
19
16
|
export * from "./functions/grace/index.js";
|
|
20
17
|
export * from "./functions/head/index.js";
|
|
21
18
|
export * from "./functions/key/index.js";
|
|
22
|
-
export
|
|
23
|
-
export * from "./functions/meter/shape.js";
|
|
19
|
+
export { MeterNode } from "./functions/meter/index.js";
|
|
24
20
|
export * from "./functions/note/index.js";
|
|
25
|
-
export * from "./functions/note/accidentals.js";
|
|
26
21
|
export * from "./functions/note/noteName.js";
|
|
27
22
|
export * from "./functions/note/source-transform.js";
|
|
28
23
|
export * from "./functions/ottava/index.js";
|
|
@@ -34,28 +29,7 @@ export * from "./functions/set/index.js";
|
|
|
34
29
|
export * from "./functions/slide/index.js";
|
|
35
30
|
export * from "./functions/stack/index.js";
|
|
36
31
|
export * from "./functions/symbol/index.js";
|
|
37
|
-
export * from "./functions/symbol/ornament.js";
|
|
38
|
-
export * from "./functions/symbol/shape.js";
|
|
39
|
-
export * from "./functions/symbol/symbols/accent.js";
|
|
40
|
-
export * from "./functions/symbol/symbols/coda.js";
|
|
41
|
-
export * from "./functions/symbol/symbols/dc.js";
|
|
42
|
-
export * from "./functions/symbol/symbols/ds.js";
|
|
43
|
-
export * from "./functions/symbol/symbols/dynamics.js";
|
|
44
|
-
export * from "./functions/symbol/symbols/fermata.js";
|
|
45
|
-
export * from "./functions/symbol/symbols/fine.js";
|
|
46
|
-
export * from "./functions/symbol/symbols/harmonic.js";
|
|
47
|
-
export * from "./functions/symbol/symbols/marcato.js";
|
|
48
|
-
export * from "./functions/symbol/symbols/mordent.js";
|
|
49
|
-
export * from "./functions/symbol/symbols/prall.js";
|
|
50
|
-
export * from "./functions/symbol/symbols/segno.js";
|
|
51
|
-
export * from "./functions/symbol/symbols/staccato.js";
|
|
52
|
-
export * from "./functions/symbol/symbols/tenuto.js";
|
|
53
|
-
export * from "./functions/symbol/symbols/tocoda.js";
|
|
54
|
-
export * from "./functions/symbol/symbols/tr.js";
|
|
55
|
-
export * from "./functions/symbol/symbols/turn.js";
|
|
56
|
-
export * from "./functions/symbol/symbols/wheel.js";
|
|
57
32
|
export * from "./functions/tempo/index.js";
|
|
58
|
-
export * from "./functions/tempo/glyph.js";
|
|
59
33
|
export * from "./functions/text/index.js";
|
|
60
34
|
export * from "./functions/tie/index.js";
|
|
61
35
|
export * from "./functions/tremolo/index.js";
|
|
@@ -63,7 +37,7 @@ export * from "./functions/tuplet/index.js";
|
|
|
63
37
|
export * from "./functions/up/index.js";
|
|
64
38
|
export * from "./functions/voice/voice.js";
|
|
65
39
|
export * from "./functions/voice/voices.js";
|
|
66
|
-
export
|
|
40
|
+
export { parseConnections, resolveConnections, serializeConnections, } from "./functions/voice/connections.js";
|
|
67
41
|
export * from "./functions/voice/lyrics.js";
|
|
68
42
|
export * from "./functions/volta/index.js";
|
|
69
43
|
export * from "./diagnostic.js";
|
|
@@ -78,20 +52,18 @@ export * from "./parser/parse-utils/label-utils.js";
|
|
|
78
52
|
export * from "./parser/parse-utils/length-utils.js";
|
|
79
53
|
export * from "./parser/parse-utils/note-utils.js";
|
|
80
54
|
export * from "./parser/parse-utils/string-utils.js";
|
|
81
|
-
export { quote as quoteSourceString } from "./parser/parse-utils/string-utils.js";
|
|
82
55
|
export * from "./lowering/types.js";
|
|
83
56
|
export * from "./lowering/loweringContext.js";
|
|
84
57
|
export * from "./lowering/track.js";
|
|
58
|
+
export * from "./lowering/accidentalMemory.js";
|
|
85
59
|
export * from "./playback/types.js";
|
|
86
|
-
export * from "./playback/event.js";
|
|
87
60
|
export * from "./playback/time.js";
|
|
88
61
|
export * from "./playback/compile.js";
|
|
89
62
|
export * from "./layout/types.js";
|
|
90
63
|
export * from "./layout/model.js";
|
|
91
64
|
export * from "./layout/default.js";
|
|
92
|
-
export
|
|
65
|
+
export { DEFAULT_PAGE_CONFIG, normalizePageConfig, paginateLayoutLines, } from "./layout/page.js";
|
|
93
66
|
export * from "./layout/engine.js";
|
|
94
67
|
export * from "./layout/path.js";
|
|
95
68
|
export * from "./layout/range.js";
|
|
96
69
|
export * from "./render/index.js";
|
|
97
|
-
export * from "./render/translate.js";
|