jpfun 0.4.0 → 0.4.1

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 (36) hide show
  1. package/dist/functions/ASTtypes.d.ts +2 -1
  2. package/dist/functions/adjust/index.js +12 -5
  3. package/dist/functions/arpeggio/index.js +7 -3
  4. package/dist/functions/bar/index.js +7 -8
  5. package/dist/functions/beam/index.js +6 -1
  6. package/dist/functions/beam/layout.d.ts +1 -1
  7. package/dist/functions/beam/layout.js +5 -3
  8. package/dist/functions/box/index.js +8 -1
  9. package/dist/functions/br/index.js +9 -5
  10. package/dist/functions/dash/index.js +5 -3
  11. package/dist/functions/div/index.d.ts +4 -1
  12. package/dist/functions/div/index.js +8 -7
  13. package/dist/functions/dot/index.js +9 -6
  14. package/dist/functions/dyn/index.js +8 -8
  15. package/dist/functions/grace/index.js +15 -8
  16. package/dist/functions/head/index.js +19 -14
  17. package/dist/functions/key/index.js +7 -3
  18. package/dist/functions/meter/index.js +8 -1
  19. package/dist/functions/note/index.js +13 -18
  20. package/dist/functions/page/index.d.ts +3 -1
  21. package/dist/functions/page/index.js +17 -10
  22. package/dist/functions/program/index.js +11 -2
  23. package/dist/functions/set/index.js +9 -7
  24. package/dist/functions/stack/index.js +7 -5
  25. package/dist/functions/symbol/index.js +10 -6
  26. package/dist/functions/tempo/index.js +7 -1
  27. package/dist/functions/text/index.js +11 -3
  28. package/dist/functions/tie/index.js +8 -2
  29. package/dist/functions/tuplet/index.js +7 -1
  30. package/dist/functions/up/index.js +15 -12
  31. package/dist/functions/voice/index.js +32 -23
  32. package/dist/functions/volta/index.js +11 -7
  33. package/dist/jpfun.core.min.js +94 -128
  34. package/dist/jpfun.min.js +101 -135
  35. package/grammar.md +90 -72
  36. package/package.json +1 -1
@@ -64,6 +64,7 @@ export declare class ASTBraceNode extends ASTNodeBase {
64
64
  }
65
65
  export interface FunctionArgDef {
66
66
  name?: string;
67
+ description?: string;
67
68
  type: paramType;
68
69
  /** 参数默认值 null表示必填 否则报错 */
69
70
  default: paramValue | null;
@@ -71,7 +72,7 @@ export interface FunctionArgDef {
71
72
  export interface FunctionDef {
72
73
  name: string | string[];
73
74
  description: string;
74
- example: string;
75
+ details: string;
75
76
  allowExtraArgs: boolean;
76
77
  extraArgType?: paramType;
77
78
  args: FunctionArgDef[];
@@ -5,34 +5,41 @@ import { isLayoutAttachment, } from "../../layout/types.js";
5
5
  class AdjustFunction extends ASTFunctionNode {
6
6
  static def = {
7
7
  name: ["adjust", "adj"],
8
- description: "微调目标的位置与占位",
9
- example: `@adjust(content, dx=0px, dy=0px, dw=0px, dh=0px)
10
- dw/dh 在排版前增减占位,最终尺寸不小于 0;dw 按原左右占位比例分配,dh 调整下方;
11
- dx/dy 在排版完成后平移目标,邻居不会让开,因此可以故意重叠。
12
- 括住的若是关系对象(连音线等)且其中没有对象,平移的就是这条关系对象`,
8
+ description: "微调目标的绘制位置与排版占位",
9
+ details: `\
10
+ ~~~jpfun
11
+ @adjust(1, dx=2px, dy=-1px, dw=0.2em, dh=0px)
12
+ ~~~
13
+
14
+ 位置偏移在排版后应用,相邻对象保持原位;占位调整在排版前应用。只包裹关系对象时,平移作用于该关系对象本身。`,
13
15
  allowExtraArgs: false,
14
16
  args: [
15
17
  {
16
18
  type: "content",
19
+ description: "要微调的内容或关系对象",
17
20
  default: null,
18
21
  },
19
22
  {
20
23
  name: "dx",
24
+ description: "排版后的水平偏移,正值向右,不改变占位",
21
25
  type: "length",
22
26
  default: { value: 0, unit: "px" },
23
27
  },
24
28
  {
25
29
  name: "dy",
30
+ description: "排版后的垂直偏移,正值向下,不改变占位",
26
31
  type: "length",
27
32
  default: { value: 0, unit: "px" },
28
33
  },
29
34
  {
30
35
  name: "dw",
36
+ description: "增减水平占位,按原左右比例分配,最终宽度不小于 0",
31
37
  type: "length",
32
38
  default: { value: 0, unit: "px" },
33
39
  },
34
40
  {
35
41
  name: "dh",
42
+ description: "增减下方占位,最终高度不小于 0",
36
43
  type: "length",
37
44
  default: { value: 0, unit: "px" },
38
45
  },
@@ -18,18 +18,22 @@ class ArpeggioFunction extends ASTFunctionNode {
18
18
  static def = {
19
19
  name: ["arp", "arpeggio"],
20
20
  description: "琶音",
21
- example: `@arp({1 ^ 3 ^ 5}) 默认从低到高,无箭头
22
- @arp({1 ^ 3 ^ 5}, direction=up) 从低到高,顶端带箭头
23
- @arp({1 ^ 3 ^ 5}, direction=down) 从高到低,底端带箭头`,
21
+ details: `\
22
+ ~~~jpfun
23
+ @arp({1 ^ 3 ^ 5}, direction=up)
24
+ ~~~
25
+ 给和弦绘制一个从低到高的琶音`,
24
26
  allowExtraArgs: false,
25
27
  args: [
26
28
  {
27
29
  name: "content",
30
+ description: "由 `up` / `down` 堆叠形成的和弦",
28
31
  type: "content",
29
32
  default: null
30
33
  },
31
34
  {
32
35
  name: "direction",
36
+ description: "空值从低到高、不画箭头;`up` 从低到高、顶端带箭头;`down` 从高到低、底端带箭头",
33
37
  type: "string",
34
38
  default: ""
35
39
  },
@@ -4,23 +4,22 @@ class BarFunction extends ASTFunctionNode {
4
4
  static def = {
5
5
  name: ["bar", "|"],
6
6
  description: "小节线",
7
- example: `@bar(type, lengthEM) 创建一个小节线
8
- 语法糖:
9
- - type0: '|' 普通小节线
10
- - type1: '||' 终止小节线 左细右粗
11
- - type2: '|:' 重复小节线 左粗右细
12
- - type3: ':|'
13
- - type4: ':|:' 左右反复
14
- `,
7
+ details: `\
8
+ ~~~jpfun
9
+ @bar(0, length=1.25em)
10
+ ~~~
11
+ 有语法糖简写,见 type 参数的说明。`,
15
12
  allowExtraArgs: false,
16
13
  args: [
17
14
  {
18
15
  name: "type",
16
+ description: "0:普通线 `|`;1:终止线 `||`(左细右粗);2:反复起点 `|:`;3:反复终点 `:|`;4:左右反复 `:|:`",
19
17
  type: "number",
20
18
  default: 0,
21
19
  },
22
20
  {
23
21
  name: "length",
22
+ description: "小节线高度",
24
23
  type: "length",
25
24
  default: {
26
25
  value: 1.25,
@@ -8,7 +8,12 @@ class BeamFunction extends ASTFunctionNode {
8
8
  static def = {
9
9
  name: ["beam"],
10
10
  description: "减时线连接",
11
- example: "@beam(label1, label2, ...): 将多个已标记音符按顺序连接为减时线组",
11
+ details: `\
12
+ 事后将多个减时线**强行**相连
13
+ ~~~jpfun
14
+ 1/@a 2/@b | 3/@c @beam(a, b, c)
15
+ ~~~
16
+ **位置参数**:已标记音符的标签,按传入顺序连接减时线,显式指定一组。先用 \`/\` 或 \`@div\` 为目标添加减时线,再用 \`@beam\` 控制连接。端点须同轨、同谱面行且相邻,可跨小节线;连线直接穿过小节线,保留原有间距。`,
12
17
  allowExtraArgs: true,
13
18
  extraArgType: "label",
14
19
  args: [],
@@ -4,7 +4,7 @@ import type { LayoutAttachment } from "../../layout/types.js";
4
4
  import type { LoweringAttachment, LoweringResult } from "../../lowering/types.js";
5
5
  /** 显式和自动分组共享同一个几何对象 */
6
6
  export declare function createBeamLayoutAttachment(endPoints: TemporalNodeBase[], explicit: boolean, sourceSpan: SourceSpan): LayoutAttachment;
7
- /** 显式 beam 必须严格连接最终同轨同谱面行中的相邻可见主体 */
7
+ /** 显式 beam 连接同轨同谱面行中的相邻可见主体,忽略零时长小节线 */
8
8
  export declare function validateExplicitBeamAttachments(result: LoweringResult): void;
9
9
  /** 自动分组在 loweringAugment 当下读取已经注册的显式 beam 端点 */
10
10
  export declare function collectExplicitBeamEndpoints(attachments: readonly LoweringAttachment[]): Set<TemporalNodeBase>;
@@ -1,17 +1,19 @@
1
- import { isVisualTemporalNode, } from "../temporal.js";
1
+ import { ANCHOR_KEY, isVisualTemporalNode, } from "../temporal.js";
2
2
  import { ErrorDiagnostic } from "../../diagnostic.js";
3
3
  import { claimDivLine, divLinePortName, divLineRuns, divLineWidth, } from "../div/index.js";
4
4
  /** 显式和自动分组共享同一个几何对象 */
5
5
  export function createBeamLayoutAttachment(endPoints, explicit, sourceSpan) {
6
6
  return new BeamLayoutAttachment(endPoints, explicit, sourceSpan);
7
7
  }
8
- /** 显式 beam 必须严格连接最终同轨同谱面行中的相邻可见主体 */
8
+ /** 显式 beam 连接同轨同谱面行中的相邻可见主体,忽略零时长小节线 */
9
9
  export function validateExplicitBeamAttachments(result) {
10
10
  const tracks = new Map();
11
11
  for (const column of result.columns) {
12
12
  for (const node of column) {
13
13
  if (!isVisualTemporalNode(node))
14
14
  continue;
15
+ if (node.mergeKey === ANCHOR_KEY && node.T.isZero())
16
+ continue;
15
17
  let lineTracks = tracks.get(node.layoutLine);
16
18
  if (!lineTracks) {
17
19
  lineTracks = new Map();
@@ -50,7 +52,7 @@ export function validateExplicitBeamAttachments(result) {
50
52
  && secondPosition.index === firstPosition.index + 1;
51
53
  if (adjacent)
52
54
  continue;
53
- throw new ErrorDiagnostic("E_NON_ADJACENT_BEAM", "@beam 的端点必须按时间顺序连接同一轨道、同一谱面行中的相邻可见元素", attachment.sourceSpan);
55
+ throw new ErrorDiagnostic("E_NON_ADJACENT_BEAM", "@beam 的端点必须按时间顺序连接同一轨道、同一谱面行中的相邻可见元素(可跨小节线)", attachment.sourceSpan);
54
56
  }
55
57
  }
56
58
  }
@@ -8,15 +8,20 @@ class BoxFunction extends ASTFunctionNode {
8
8
  static def = {
9
9
  name: ["box"],
10
10
  description: "给目标结构或对象加外框",
11
- example: `@box(content, padding=0.2em, stroke=0.08em, width=-1px)`,
11
+ details: `\
12
+ ~~~jpfun
13
+ @box({1 2 3}, padding=0.2em, stroke=0.08em)
14
+ ~~~`,
12
15
  allowExtraArgs: false,
13
16
  args: [
14
17
  {
15
18
  type: "content",
19
+ description: "需要加框的内容或结构",
16
20
  default: null,
17
21
  },
18
22
  {
19
23
  name: "padding",
24
+ description: "内容到框线的内边距",
20
25
  type: "length",
21
26
  default: {
22
27
  value: 0,
@@ -25,6 +30,7 @@ class BoxFunction extends ASTFunctionNode {
25
30
  },
26
31
  {
27
32
  name: "stroke",
33
+ description: "框线宽度",
28
34
  type: "length",
29
35
  default: {
30
36
  value: 1,
@@ -33,6 +39,7 @@ class BoxFunction extends ASTFunctionNode {
33
39
  },
34
40
  {
35
41
  name: "width",
42
+ description: "约束内部排版的宽度,非正值表示随内容自动确定",
36
43
  type: "length",
37
44
  default: {
38
45
  value: -1,
@@ -7,15 +7,19 @@ class BrFunction extends ASTFunctionNode {
7
7
  static def = {
8
8
  name: ["br"],
9
9
  description: "换行",
10
- example: `@br(offset=1): 在后续事件前偏移指定行数
11
- @br() === @br(1)
12
- @br(2): 空出一行后继续
13
- 语法糖: [仅限顶层]至少连续两个换行
14
- `,
10
+ details: `\
11
+ ~~~jpfun
12
+ 1 2 @br() 3 4
13
+ ~~~
14
+
15
+ \`@br()\` 换到下一行,\`@br(2)\` 空出一行再继续
16
+
17
+ **简写**:仅在顶层,连续至少两个换行表示换行`,
15
18
  allowExtraArgs: false,
16
19
  args: [
17
20
  {
18
21
  name: "offset",
22
+ description: "后续内容偏移的谱面行数,2 表示空出一行再继续",
19
23
  type: "number",
20
24
  default: 1,
21
25
  },
@@ -5,9 +5,11 @@ class DashFunction extends ASTFunctionNode {
5
5
  static def = {
6
6
  name: ["dash", "-"],
7
7
  description: "增时线",
8
- example: `@dash() 创建一根增时线
9
- 语法糖: 一个 '-' 代表一个 @dash()
10
- `,
8
+ details: `\
9
+ ~~~jpfun
10
+ 1 @dash()
11
+ ~~~
12
+ 无参数。添加一根增时线,延续前方音符的发声;也可简写为 \`1 -\`。每根线的基础时值为一个四分音符,可用减时线或附点调整。`,
11
13
  allowExtraArgs: false,
12
14
  args: []
13
15
  };
@@ -22,18 +22,21 @@ declare class DivFunction extends ASTFunctionNode {
22
22
  static def: {
23
23
  name: string[];
24
24
  description: string;
25
- example: string;
25
+ details: string;
26
26
  allowExtraArgs: boolean;
27
27
  args: ({
28
28
  type: "content";
29
+ description: string;
29
30
  default: null;
30
31
  name?: undefined;
31
32
  } | {
32
33
  name: string;
34
+ description: string;
33
35
  type: "number";
34
36
  default: number;
35
37
  } | {
36
38
  name: string;
39
+ description: string;
37
40
  type: "boolean";
38
41
  default: boolean;
39
42
  })[];
@@ -48,26 +48,27 @@ class DivFunction extends ASTFunctionNode {
48
48
  static def = {
49
49
  name: [DIV_FUNC_NAME, "/"],
50
50
  description: "减时线",
51
- example: `@div(C1, 2): C1下方创建2根减时线
52
- @/({C1 C2 @dash()}, 3): C1、C2和增时线下方创建3根减时线并连接
53
- 语法糖:在音符后加斜杠'/',可以多个
54
- @div(C1, 2) === C1//
55
- @div(C1 C2/ @dash(), 2) === {C1 C2/ @dash()}//
56
- 设置命名参数前缀: div
57
- `,
51
+ details: `\
52
+ ~~~jpfun
53
+ @div({1 2 -}, n=2, autobeam=true)
54
+ ~~~
55
+ **简写**:在目标后加 \`/\`,可重复或作用于内容块。\`@div(1, 2)\` 等价于 \`1//\`,\`@div({1 2/ -}, 2)\` 等价于 \`{1 2/ -}//\`。默认参数使用 \`div.n\`、\`div.autobeam\` 设置。`,
58
56
  allowExtraArgs: false,
59
57
  args: [
60
58
  {
61
59
  type: "content",
60
+ description: "要减时的内容,可包含多个音符或增时线",
62
61
  default: null,
63
62
  },
64
63
  {
65
64
  name: "n",
65
+ description: "减时层数,每级将时值减半,取非负整数",
66
66
  type: "number",
67
67
  default: 1,
68
68
  },
69
69
  {
70
70
  name: "autobeam",
71
+ description: "是否参与不同 div 之间的自动连线,同一 div 内部的连线不受影响",
71
72
  type: "boolean",
72
73
  default: true,
73
74
  },
@@ -10,20 +10,23 @@ class DotFunction extends ASTFunctionNode {
10
10
  static def = {
11
11
  name: [DOT_FUNC_NAME, "."],
12
12
  description: "附点",
13
- example: `@dot(C1, 2): C1右侧创建2个点 仅接收一个可接收元素
14
- 语法糖:在目标后加'.',可以多个
15
- @dot(C1, 2) === C1..
16
- {1^2}. === {1.^2}
17
- @dot(C1 C2/ @dash(), 2) 报错 因为点只能接收一个可见时间元素
18
- `,
13
+ details: `\
14
+ ~~~jpfun
15
+ @dot(1, n=2)
16
+ ~~~
17
+ **简写**:目标后加 \`.\`,可重复。\`@dot(1, 2)\` 等价于 \`1..\`;\`{1^2}.\` 等价于 \`{1.^2}\`。
18
+
19
+ \`@dot({1 2/ -}, 2)\` 包含多个时间元素,会报错;需要分别为各元素添加附点。`,
19
20
  allowExtraArgs: false,
20
21
  args: [
21
22
  {
22
23
  type: "content",
24
+ description: "单个可见时间元素,如音符、增时线或折叠和弦",
23
25
  default: null,
24
26
  },
25
27
  {
26
28
  name: "n",
29
+ description: "附点数,第一点增加原时值的一半,后续各点增加量再减半",
27
30
  type: "number",
28
31
  default: 1,
29
32
  },
@@ -5,17 +5,17 @@ class DynFunction extends ASTFunctionNode {
5
5
  static def = {
6
6
  name: ["dyn"],
7
7
  description: "渐强渐弱",
8
- example: `@dyn(from, to, dv) 在两个标签之间线性改变力度
9
- from、to 必须位于同一音轨且时间不同
10
- dv 为正时渐强,为负时渐弱;变化量叠加在每个音符原有力度上
11
-
8
+ details: `\
9
+ ~~~jpfun
12
10
  1 ^ $p 2@a 3 4@b
13
- @dyn(a, b, 24)`,
11
+ @dyn(a, b, 24)
12
+ ~~~
13
+ 端点须位于同一音轨、不同时间;变化量沿区间线性增加,叠加在每个音符原有力度上。本例从 \`a\` 到 \`b\` 渐强,终点增加 24 的力度。`,
14
14
  allowExtraArgs: false,
15
15
  args: [
16
- { name: "from", type: "label", default: null },
17
- { name: "to", type: "label", default: null },
18
- { name: "dv", type: "number", default: null },
16
+ { name: "from", description: "渐变起点的标签", type: "label", default: null },
17
+ { name: "to", description: "渐变终点的标签", type: "label", default: null },
18
+ { name: "dv", description: "力度变化量,正数渐强,负数渐弱", type: "number", default: null },
19
19
  ],
20
20
  };
21
21
  static loweringFinalize = (result) => {
@@ -31,27 +31,34 @@ class GraceFunction extends ASTFunctionNode {
31
31
  static def = {
32
32
  name: ["grace"],
33
33
  description: "倚音",
34
- example: `前倚音: @grace(宿主, 倚音, side=pre) 后倚音: @grace(宿主, 倚音, side=post)
35
- 语法糖:'>' 与 '<',箭头永远指向宿主
36
- 2>1 前倚音:2 是 1 的倚音,画在 1 的左上角
37
- 1<2 后倚音:2 是 1 的倚音,画在 1 的右上角
38
- {3 2}>1 多个倚音用大括号括起来
39
- 1>2>3 允许嵌套:1 是 2 的倚音,2 是 3 的倚音
40
- 倚音默认就是八分音符(自带一条减时线),再写 '/' 变成十六分音符`,
41
- allowExtraArgs: true,
34
+ details: `\
35
+ ~~~jpfun
36
+ @grace(1, {3 2}, side=pre)
37
+ ~~~
38
+ **简写**:箭头始终指向宿主
39
+ - \`2>1\`:\`2\` 是 \`1\` 的前倚音,位于左上方
40
+ - \`1<2\`:\`2\` 是 \`1\` 的后倚音,位于右上方
41
+ - \`{3 2}>1\`:一组前倚音,等价于上例
42
+ - \`1>2>3\`:允许嵌套,\`1\` 修饰 \`2\`,\`2\` 修饰 \`3\`
43
+
44
+ 倚音默认带一条减时线,按八分音符书写;再加 \`/\` 变为十六分音符`,
45
+ allowExtraArgs: false,
42
46
  args: [
43
47
  {
44
48
  name: "host",
49
+ description: "被倚音修饰的宿主内容",
45
50
  type: "content",
46
51
  default: null,
47
52
  },
48
53
  {
49
54
  name: "grace",
55
+ description: "倚音内容,多个音符可用大括号组合",
50
56
  type: "content",
51
57
  default: null,
52
58
  },
53
59
  {
54
60
  name: "side",
61
+ description: "`pre` 为前倚音,`post` 为后倚音",
55
62
  type: "string",
56
63
  default: "pre",
57
64
  }
@@ -296,22 +296,27 @@ class HeadSlotNode extends ASTNodeBase {
296
296
  class HeadFunction extends ASTFunctionNode {
297
297
  static def = {
298
298
  name: ["head"],
299
- description: "提供左、中、右三块布局,常用于曲谱头部信息展示;也可用连续的 H.*: 行声明构造",
300
- example: `@head(left={{@key(C) @meter(4,4)}}, center={@text(标题)}, right={@text(作者)})
301
- 语法糖:相邻的 H.*: 声明合并为一个 head,每条声明生成对应槽的一行;空行或普通内容结束组合
302
- H.title: 标题 center 槽,预设大字号居中 Text
303
- H.subtitle: 副标题 center 槽,预设小字号居中 Text
304
- H.author: 作者 right 槽,预设小字号右对齐 Text
305
- H.signature: 1=C 4/4 left 槽,同一行生成 Key 和 Meter
306
- H.tempo: 94 left 槽,生成 Tempo
307
- H.left: / H.center: / H.right: 接受对应槽的任意零时长 DSL 内容
308
- 以 @ 或 { 开头时按 DSL 解析,否则按该字段的裸文本规则生成 Text`,
299
+ description: "左、中、右三区布局",
300
+ details: `常用于谱头:
301
+ ~~~jpfun
302
+ @head(left={{@key(C) @meter(4,4)}},
303
+ center={@text(标题)}, right={@text(作者)})
304
+ ~~~
305
+ **简写**:相邻的 \`H.*:\` 行合并为同一个谱头,每条声明生成所在区的一行;空行或普通内容结束组合
306
+ ~~~jpfun
307
+ H.title: 标题
308
+ H.subtitle: 副标题
309
+ H.author: 作者
310
+ H.signature: 1=C 4/4
311
+ H.tempo: 94
312
+ ~~~
313
+ \`title\` / \`subtitle\` 居中,分别预设大、小字号;\`author\` 小字号右对齐;\`signature\` 和 \`tempo\` 放在左区。\`H.left:\`、\`H.center:\`、\`H.right:\` 可直接写对应区的零时长内容。以 \`@\` 或 \`{\` 开头的值按 jpFun 解析,其余按字段的文本规则处理。`,
309
314
  allowExtraArgs: false,
310
315
  args: [
311
- { name: "left", type: "content", default: "" },
312
- { name: "center", type: "content", default: "" },
313
- { name: "right", type: "content", default: "" },
314
- { name: "gap", type: "length", default: { value: DEFAULT_GAP_PX, unit: "px" } },
316
+ { name: "left", description: "左区零时长内容,如调性、拍号与速度记号", type: "content", default: "" },
317
+ { name: "center", description: "中区零时长内容,如标题与副标题", type: "content", default: "" },
318
+ { name: "right", description: "右区零时长内容,如作者与署名", type: "content", default: "" },
319
+ { name: "gap", description: "每个区内相邻行的垂直间距", type: "length", default: { value: DEFAULT_GAP_PX, unit: "px" } },
315
320
  ],
316
321
  };
317
322
  slots;
@@ -33,18 +33,22 @@ class KeyFunction extends ASTFunctionNode {
33
33
  static def = {
34
34
  name: ["key", "1"],
35
35
  description: "设置时间线上的 1= 调性基准",
36
- example: `@1(C4) 或 @key(F#3)
37
- 它不会修改 parser 的局部变量,而是在时间固化阶段影响其后的数字音名解释
38
- 画出来的记号只含音名和升降号,不含八度;通常叠在音符上方书写:1 ^ @1(F#)`,
36
+ details: `\
37
+ ~~~jpfun
38
+ 1 ^ @key(F#3)
39
+ ~~~
40
+ 调性沿时间线影响后续数字音名。谱面记号显示音名与升降号,省略八度;通常用 \`^\` 叠在音符上方。`,
39
41
  allowExtraArgs: false,
40
42
  args: [
41
43
  {
42
44
  name: "tonality",
45
+ description: "`1=` 的音高基准,如 `C4`、`F#3`",
43
46
  type: "string",
44
47
  default: null,
45
48
  },
46
49
  {
47
50
  name: "size",
51
+ description: "调性记号字号",
48
52
  type: "length",
49
53
  default: {
50
54
  value: 1,
@@ -6,21 +6,28 @@ class MeterFunction extends ASTFunctionNode {
6
6
  static def = {
7
7
  name: ["meter"],
8
8
  description: "设置拍号",
9
- example: `@meter(6, 8) 设置 6/8 拍号`,
9
+ details: `\
10
+ ~~~jpfun
11
+ @meter(6, 8)
12
+ ~~~
13
+ 设置 \`6/8\` 拍号:每小节含六个八分音符的时值`,
10
14
  allowExtraArgs: false,
11
15
  args: [
12
16
  {
13
17
  name: "num",
18
+ description: "拍号分子,每小节包含的单位拍数",
14
19
  type: "number",
15
20
  default: null
16
21
  },
17
22
  {
18
23
  name: "den",
24
+ description: "拍号分母,以几分音符为单位拍",
19
25
  type: "number",
20
26
  default: null
21
27
  },
22
28
  {
23
29
  name: "size",
30
+ description: "拍号字号",
24
31
  type: "length",
25
32
  default: { value: 0.7, unit: "em" },
26
33
  },
@@ -7,43 +7,38 @@ class NoteFunction extends ASTFunctionNode {
7
7
  static def = {
8
8
  name: ["note", "n"],
9
9
  description: "创建音符",
10
- example: `@note(name, acc, octave, color)
11
- 参数说明:
12
- - name: [必填]音符名,可以是大写字母或者数字,不允许小写字母(会和降号冲突)。此参数写法有语法糖,见下。
13
- 其中 0 或 Z 是休止符,8 是隐形占位,9 或 X 是只打拍不发音的节拍记号(显示为 X),这三者都不显示升降号和八度点。
14
- - acc: [可选]的额外升降号字符串,例如 "##" 表示再升两个半音,"b" 表示再降一个半音。
15
- - octave: [可选]八度,类型为数字。如果 name 是字母,则此项代表绝对八度;如果是数字,则此项代表相对八度。
16
-
17
- 语法糖:数字音名写作 [升降号][音名][相对八度];字母音名写作 [音名][升降号][绝对八度]
18
- 例:A#3 === @note(A#3) === @note(A, #, 3)
19
- 也支持 A##bn99 的写法。可以设置 note.octave 改变默认的绝对八度
20
-
21
- 兼容无歧义的后置升降号:A3# 等价于 A#3,6#,, 等价于 #6,,
22
- 如果整段升降号后紧跟数字,则升降号属于下一个音符:6#3 解析为 6 和 #3
23
-
24
- 支持 数字音名, 此时 octave 为相对八度
25
- 支持使用数字音名时使用相对八度,如 "1,," 代表在当前基准音(由上下文属性"1=?"决定)的基础上降低两倍八度,"1'" 代表在当前基准音的基础上提高一个八度
26
- 例:#1' === @note("#1'") === @note(1, #, 1)
27
- `,
10
+ details: `\
11
+ ~~~jpfun
12
+ @note(A, acc=#, octave=3, color=#c33)
13
+ ~~~
14
+ **简写**:数字音名按“升降号、音名、相对八度”书写;字母音名按“音名、升降号、绝对八度”书写。\`1,,\` 比当前调性基准低两个八度,\`1'\` 高一个八度。
15
+ - \`A#3\` 等价于 \`@note(A#3)\` 或 \`@note(A, #, 3)\`
16
+ - \`#1'\` 等价于 \`@note("#1'")\` 或 \`@note(1, #, 1)\`
17
+ - 支持组合升降号,如 \`A##bn99\`;无歧义时也接受后置写法,如 \`A3#\`、\`6#,,\`
18
+ - 升降号后紧跟数字时归入下一音符:\`6#3\` 解析为 \`6\` 和 \`#3\``,
28
19
  allowExtraArgs: false,
29
20
  args: [
30
21
  {
31
22
  name: "name",
23
+ description: "数字音名或大写字母音名,可自带升降号与八度;`0` / `Z` 为休止符,`8` 为隐形占位,`9` / `X` 为节拍记号,后三类不显示升降号和八度点",
32
24
  type: "string",
33
25
  default: null,
34
26
  },
35
27
  {
36
28
  name: "acc",
29
+ description: "额外升降号,`##` 再升两个半音,`b` 再降一个半音",
37
30
  type: "string",
38
31
  default: "",
39
32
  },
40
33
  {
41
34
  name: "octave",
35
+ description: "字母音名使用绝对八度;数字音名使用相对八度,省略时为 0",
42
36
  type: "number",
43
37
  default: 4, // 如果是数字则默认值为0 需要代码中区分
44
38
  },
45
39
  {
46
40
  name: "color",
41
+ description: "音符颜色,使用 CSS 颜色值",
47
42
  type: "string",
48
43
  default: "#000",
49
44
  }
@@ -7,14 +7,16 @@ export declare class PageFunction extends ASTFunctionNode {
7
7
  static def: {
8
8
  name: string[];
9
9
  description: string;
10
- example: string;
10
+ details: string;
11
11
  allowExtraArgs: boolean;
12
12
  args: ({
13
13
  name: string;
14
+ description: string;
14
15
  type: "length";
15
16
  default: LengthValue;
16
17
  } | {
17
18
  name: string;
19
+ description: string;
18
20
  type: "string";
19
21
  default: string;
20
22
  })[];
@@ -46,19 +46,26 @@ export class PageFunction extends ASTFunctionNode {
46
46
  static def = {
47
47
  name: ["page"],
48
48
  description: "设置文档页面尺寸、边距、最小谱面行间距和页码",
49
- example: "@page(width=794px, height=1123px, top=48px, bottom=48px, left=40px, right=40px, gap=1em, numbering=\"1/1\")",
49
+ details: `\
50
+ ~~~jpfun
51
+ @page(
52
+ width=794px, height=1123px, top=48px, bottom=48px,
53
+ left=40px, right=40px, gap=1em, numbering="1/1"
54
+ )
55
+ ~~~
56
+ 尺寸接受 \`px\` 或 \`em\`。页边距和行距须非负,左右边距之和须小于页宽;固定页高时,上下边距之和也须小于页高。`,
50
57
  allowExtraArgs: false,
51
58
  args: [
52
- { name: "width", type: "length", default: px(DEFAULT_PAGE_CONFIG.width) },
53
- { name: "height", type: "length", default: px(0) },
54
- { name: "top", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginTop) },
55
- { name: "bottom", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginBottom) },
56
- { name: "left", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginLeft) },
57
- { name: "right", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginRight) },
58
- { name: "gap", type: "length", default: { value: 1, unit: "em" } },
59
+ { name: "width", description: "页面宽度,须大于左右页边距之和", type: "length", default: px(DEFAULT_PAGE_CONFIG.width) },
60
+ { name: "height", description: "页面高度,0 表示不分页、高度随内容增长;宽度为 `794px` 时,A4 对应高度约为 `1123px`", type: "length", default: px(0) },
61
+ { name: "top", description: "页面上边距", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginTop) },
62
+ { name: "bottom", description: "页面下边距,启用页码时至少为 `16px`", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginBottom) },
63
+ { name: "left", description: "页面左边距", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginLeft) },
64
+ { name: "right", description: "页面右边距", type: "length", default: px(DEFAULT_PAGE_CONFIG.marginRight) },
65
+ { name: "gap", description: "谱面行之间的最小间距", type: "length", default: { value: 1, unit: "em" } },
59
66
  // 单个 1 取当前页;多个 1 中最后一个取总页数
60
- { name: "numbering", type: "string", default: "" },
61
- { name: "font", type: "string", default: "" },
67
+ { name: "numbering", description: "页码格式,空值隐藏;`1` 显示当前页,`1/1` 显示当前页/总页数", type: "string", default: "" },
68
+ { name: "font", description: "页码字体,空值沿用当前字体设置", type: "string", default: "" },
62
69
  ],
63
70
  };
64
71
  config;