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.
- package/dist/converter/midi/convert.js +8 -55
- package/dist/converter/musicxml/features.d.ts +1 -1
- package/dist/converter/musicxml/features.js +1 -1
- package/dist/converter/musicxml/index.js +8 -18
- package/dist/converter/source.d.ts +4 -7
- package/dist/converter/source.js +11 -9
- package/dist/functions/ASTtypes.d.ts +1 -14
- package/dist/functions/ASTtypes.js +5 -36
- package/dist/functions/adjust/index.js +45 -33
- package/dist/functions/arpeggio/index.js +42 -45
- package/dist/functions/arpeggio/shape.d.ts +2 -3
- package/dist/functions/arpeggio/shape.js +20 -50
- package/dist/functions/bar/index.js +3 -8
- package/dist/functions/beam/auto.js +54 -123
- package/dist/functions/beam/index.js +4 -9
- package/dist/functions/box/index.js +0 -6
- package/dist/functions/dash/index.js +3 -4
- package/dist/functions/div/index.d.ts +2 -4
- package/dist/functions/div/index.js +10 -10
- package/dist/functions/dot/index.js +3 -9
- package/dist/functions/dyn/index.js +6 -26
- package/dist/functions/gliss/index.js +95 -89
- package/dist/functions/grace/index.d.ts +2 -5
- package/dist/functions/grace/index.js +44 -89
- package/dist/functions/head/index.js +9 -6
- package/dist/functions/key/index.js +6 -6
- package/dist/functions/meter/index.js +3 -3
- package/dist/functions/note/index.js +1 -1
- package/dist/functions/note/source-transform.js +2 -5
- package/dist/functions/ottava/index.js +11 -32
- package/dist/functions/page/index.js +13 -16
- package/dist/functions/rest/index.js +2 -4
- package/dist/functions/slide/index.js +0 -1
- package/dist/functions/stack/index.js +8 -57
- package/dist/functions/temporal.d.ts +2 -2
- package/dist/functions/temporal.js +7 -0
- package/dist/functions/text/index.js +24 -30
- package/dist/functions/tie/index.js +14 -37
- package/dist/functions/tremolo/index.js +0 -1
- package/dist/functions/tuplet/index.js +0 -6
- package/dist/functions/up/index.js +79 -83
- package/dist/functions/voice/connections.d.ts +2 -1
- package/dist/functions/voice/connections.js +48 -10
- package/dist/functions/voice/index.d.ts +2 -3
- package/dist/functions/voice/index.js +2 -970
- package/dist/functions/voice/lyrics.d.ts +30 -0
- package/dist/functions/voice/lyrics.js +289 -0
- package/dist/functions/voice/voice.d.ts +63 -0
- package/dist/functions/voice/voice.js +373 -0
- package/dist/functions/voice/voices.d.ts +106 -0
- package/dist/functions/voice/voices.js +423 -0
- package/dist/functions/volta/index.js +5 -23
- package/dist/jpfun.core.min.js +65 -56
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +7 -7
- package/dist/jpfun.min.js +68 -59
- package/dist/layout/engine.js +30 -18
- package/dist/layout/model.d.ts +0 -1
- package/dist/layout/model.js +1 -4
- package/dist/layout/page.d.ts +2 -1
- package/dist/layout/page.js +14 -14
- package/dist/layout/range.d.ts +7 -6
- package/dist/layout/range.js +23 -14
- package/dist/layout/types.d.ts +9 -28
- package/dist/lowering/loweringContext.d.ts +8 -11
- package/dist/lowering/loweringContext.js +7 -13
- package/dist/lowering/track.d.ts +8 -1
- package/dist/lowering/types.d.ts +12 -8
- package/dist/parser/parse-utils/call-utils.d.ts +1 -2
- package/dist/parser/parse-utils/call-utils.js +6 -34
- package/dist/parser/parse-utils/note-utils.d.ts +3 -3
- package/dist/parser/parse-utils/note-utils.js +17 -28
- package/dist/parser/parse-utils/string-utils.d.ts +1 -1
- package/dist/parser/parse-utils/string-utils.js +8 -6
- package/dist/parser/parserContext.d.ts +9 -9
- package/dist/parser/parserContext.js +54 -10
- package/dist/pipeline.js +2 -2
- package/dist/playback/compile.js +13 -14
- package/dist/playback/event.d.ts +6 -6
- package/dist/playback/event.js +13 -49
- package/dist/render/canvas.d.ts +0 -2
- package/dist/render/canvas.js +0 -21
- package/dist/render/svg.d.ts +0 -1
- package/dist/render/svg.js +33 -31
- package/dist/render/text.d.ts +36 -1
- package/dist/render/text.js +134 -0
- package/dist/render/types.d.ts +0 -2
- package/grammar.md +16 -13
- package/package.json +1 -1
- package/dist/iife/core.d.ts +0 -1
- package/dist/iife/core.js +0 -3
- package/dist/iife/from-midi.d.ts +0 -1
- package/dist/iife/from-midi.js +0 -15
- package/dist/iife/from-musicxml.d.ts +0 -1
- package/dist/iife/from-musicxml.js +0 -3
- package/dist/iife/full.d.ts +0 -1
- package/dist/iife/full.js +0 -3
|
@@ -11,9 +11,10 @@ export interface ConnectionSpec {
|
|
|
11
11
|
kind: ConnectionKind;
|
|
12
12
|
from?: number;
|
|
13
13
|
to?: number;
|
|
14
|
+
name?: string;
|
|
14
15
|
}
|
|
15
16
|
/** 开放端点在声部收集完毕后补全 */
|
|
16
|
-
export type VoiceConnection = Required<ConnectionSpec
|
|
17
|
+
export type VoiceConnection = ConnectionSpec & Required<Pick<ConnectionSpec, "from" | "to">>;
|
|
17
18
|
export declare function parseConnections(value: string, span: SourceSpan): ConnectionSpec[];
|
|
18
19
|
export declare function resolveConnections(specs: readonly ConnectionSpec[], count: number, span: SourceSpan): VoiceConnection[];
|
|
19
20
|
export declare function serializeConnections(specs: readonly ConnectionSpec[]): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ErrorDiagnostic } from "../../diagnostic.js";
|
|
2
2
|
import { pathBounds } from "../../layout/path.js";
|
|
3
|
+
import { findClosingQuote, parseString, quote } from "../../parser/parse-utils/string-utils.js";
|
|
3
4
|
export const CURVED_BRACE_COMMANDS = [
|
|
4
5
|
{ op: "M", x: 2.98438, y: -165.5 },
|
|
5
6
|
{ op: "C", cx1: 8.9375, cy1: -171.781, cx2: 20.5156, cy2: -184.688, x: 20.5156, y: -208.531 },
|
|
@@ -47,19 +48,24 @@ export const BRACKET_HOOK_COMMANDS = [
|
|
|
47
48
|
},
|
|
48
49
|
{ op: "Z" },
|
|
49
50
|
];
|
|
51
|
+
const CONNECTION_RANGE_RE = /\s*([\[{])\s*(?:(?:(\d+)\s*)?-\s*(?:(\d+)\s*)?|(\d+)\s*)/y;
|
|
52
|
+
const WHITESPACE_RE = /\s/;
|
|
53
|
+
const FORBIDDEN_RAW_NAME_RE = /[\[\]{}:"\r\n]/;
|
|
50
54
|
function invalidConnection(span) {
|
|
51
|
-
return new ErrorDiagnostic("E_VOICES_CONNECT", '@voices 的 connect 必须是 [起点-终点]、{起点-终点}、[编号] 或 {编号}
|
|
55
|
+
return new ErrorDiagnostic("E_VOICES_CONNECT", '@voices 的 connect 必须是 [起点-终点]、{起点-终点}、[编号] 或 {编号}(可用 :名称 指定分组名)的组合;范围端点可省略,否则须为有效声部编号。空字符串表示只有连谱线。', span);
|
|
52
56
|
}
|
|
53
57
|
export function parseConnections(value, span) {
|
|
54
58
|
const source = value.trim();
|
|
55
59
|
// 粘连匹配必须消费整串,不能跳过非法字符
|
|
56
60
|
// 非空数字与其后空白一起可选,避免省略端点时重复回溯
|
|
57
|
-
const pattern = /\s*([\[{])\s*(?:(?:(\d+)\s*)?-\s*(?:(\d+)\s*)?|(\d+)\s*)([\]}])\s*/y;
|
|
58
61
|
const result = [];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
for (let pos = 0; pos < source.length; pos++) {
|
|
63
|
+
CONNECTION_RANGE_RE.lastIndex = pos;
|
|
64
|
+
const match = CONNECTION_RANGE_RE.exec(source);
|
|
65
|
+
if (!match)
|
|
62
66
|
throw invalidConnection(span);
|
|
67
|
+
pos = CONNECTION_RANGE_RE.lastIndex;
|
|
68
|
+
const close = match[1] === "[" ? "]" : "}";
|
|
63
69
|
const fromText = match[4] ?? match[2];
|
|
64
70
|
const toText = match[4] ?? match[3];
|
|
65
71
|
const from = fromText ? Number(fromText) : undefined;
|
|
@@ -71,20 +77,52 @@ export function parseConnections(value, span) {
|
|
|
71
77
|
}
|
|
72
78
|
if (from !== undefined && to !== undefined && from > to)
|
|
73
79
|
throw invalidConnection(span);
|
|
74
|
-
|
|
80
|
+
let name;
|
|
81
|
+
if (source[pos] === ":") {
|
|
82
|
+
pos++;
|
|
83
|
+
while (pos < source.length && WHITESPACE_RE.test(source[pos]))
|
|
84
|
+
pos++;
|
|
85
|
+
if (source[pos] === '"') {
|
|
86
|
+
const closeQuote = findClosingQuote(source, pos, source.length);
|
|
87
|
+
const parsed = closeQuote < 0 ? null : parseString(source.slice(pos, closeQuote + 1));
|
|
88
|
+
if (typeof parsed !== "string" || !parsed)
|
|
89
|
+
throw invalidConnection(span);
|
|
90
|
+
name = parsed;
|
|
91
|
+
pos = closeQuote + 1;
|
|
92
|
+
while (pos < source.length && WHITESPACE_RE.test(source[pos]))
|
|
93
|
+
pos++;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const closeAt = source.indexOf(close, pos);
|
|
97
|
+
const raw = closeAt < 0 ? "" : source.slice(pos, closeAt);
|
|
98
|
+
name = FORBIDDEN_RAW_NAME_RE.test(raw) ? "" : raw.trim();
|
|
99
|
+
if (!name)
|
|
100
|
+
throw invalidConnection(span);
|
|
101
|
+
pos = closeAt;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (source[pos] !== close)
|
|
105
|
+
throw invalidConnection(span);
|
|
106
|
+
result.push({
|
|
107
|
+
kind: match[1] === "[" ? "bracket" : "brace",
|
|
108
|
+
from,
|
|
109
|
+
to,
|
|
110
|
+
...(name ? { name } : {}),
|
|
111
|
+
});
|
|
75
112
|
}
|
|
76
113
|
return result;
|
|
77
114
|
}
|
|
78
115
|
export function resolveConnections(specs, count, span) {
|
|
79
|
-
return specs.map(({ kind, from = 1, to = count }) => {
|
|
116
|
+
return specs.map(({ kind, from = 1, to = count, name }) => {
|
|
80
117
|
if (from > to || to > count)
|
|
81
118
|
throw invalidConnection(span);
|
|
82
|
-
return { kind, from, to };
|
|
119
|
+
return { kind, from, to, ...(name ? { name } : {}) };
|
|
83
120
|
});
|
|
84
121
|
}
|
|
85
122
|
export function serializeConnections(specs) {
|
|
86
|
-
return specs.map(({ kind, from, to }) => {
|
|
87
|
-
const
|
|
123
|
+
return specs.map(({ kind, from, to, name }) => {
|
|
124
|
+
const label = !name ? "" : `:${FORBIDDEN_RAW_NAME_RE.test(name) || name.trim() !== name ? quote(name) : name}`;
|
|
125
|
+
const range = `${from ?? ""}-${to ?? ""}${label}`;
|
|
88
126
|
return kind === "brace" ? `{${range}}` : `[${range}]`;
|
|
89
127
|
}).join("");
|
|
90
128
|
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export declare const VoicesNode: ASTFunctionClass;
|
|
1
|
+
export { VoiceNode } from "./voice.js";
|
|
2
|
+
export { VoicesNode } from "./voices.js";
|