jpfun 0.3.0 → 0.4.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 (125) hide show
  1. package/README.md +73 -1
  2. package/dist/converter/midi/convert.d.ts +50 -0
  3. package/dist/converter/midi/convert.js +700 -0
  4. package/dist/converter/midi/index.d.ts +5 -0
  5. package/dist/converter/midi/index.js +11 -0
  6. package/dist/converter/midi/json.d.ts +38 -0
  7. package/dist/converter/midi/json.js +1 -0
  8. package/dist/converter/midi/triplet.d.ts +30 -0
  9. package/dist/converter/midi/triplet.js +75 -0
  10. package/dist/converter/musicxml/dom.d.ts +25 -0
  11. package/dist/converter/musicxml/dom.js +65 -0
  12. package/dist/converter/musicxml/features.d.ts +51 -0
  13. package/dist/converter/musicxml/features.js +232 -0
  14. package/dist/converter/musicxml/index.d.ts +9 -0
  15. package/dist/converter/musicxml/index.js +1140 -0
  16. package/dist/converter/musicxml/model.d.ts +123 -0
  17. package/dist/converter/musicxml/model.js +1 -0
  18. package/dist/converter/source.d.ts +22 -0
  19. package/dist/converter/source.js +51 -0
  20. package/dist/core.d.ts +22 -0
  21. package/dist/core.js +22 -0
  22. package/dist/functions/ASTtypes.d.ts +28 -25
  23. package/dist/functions/ASTtypes.js +25 -23
  24. package/dist/functions/adjust/index.js +1 -1
  25. package/dist/functions/arpeggio/index.d.ts +2 -0
  26. package/dist/functions/arpeggio/index.js +180 -0
  27. package/dist/functions/arpeggio/shape.d.ts +7 -0
  28. package/dist/functions/arpeggio/shape.js +122 -0
  29. package/dist/functions/bar/index.js +23 -15
  30. package/dist/functions/beam/auto.d.ts +1 -1
  31. package/dist/functions/beam/auto.js +1 -1
  32. package/dist/functions/beam/layout.d.ts +2 -2
  33. package/dist/functions/beam/layout.js +1 -1
  34. package/dist/functions/box/index.js +2 -2
  35. package/dist/functions/br/index.js +1 -1
  36. package/dist/functions/dash/index.js +7 -6
  37. package/dist/functions/default.js +6 -2
  38. package/dist/functions/dot/index.js +12 -22
  39. package/dist/functions/dyn/index.d.ts +2 -0
  40. package/dist/functions/dyn/index.js +242 -0
  41. package/dist/functions/grace/index.d.ts +1 -1
  42. package/dist/functions/grace/index.js +2 -3
  43. package/dist/functions/head/index.js +149 -145
  44. package/dist/functions/key/index.js +5 -4
  45. package/dist/functions/meter/index.js +6 -5
  46. package/dist/functions/note/index.js +68 -21
  47. package/dist/functions/note/noteNameFSM.js +52 -63
  48. package/dist/functions/page/index.d.ts +2 -0
  49. package/dist/functions/page/index.js +22 -7
  50. package/dist/functions/program/index.d.ts +2 -0
  51. package/dist/functions/program/index.js +30 -0
  52. package/dist/functions/set/index.js +8 -5
  53. package/dist/functions/symbol/index.d.ts +13 -3
  54. package/dist/functions/symbol/index.js +61 -16
  55. package/dist/functions/symbol/shape.d.ts +2 -0
  56. package/dist/functions/symbol/shape.js +14 -10
  57. package/dist/functions/symbol/symbols/dc.d.ts +4 -0
  58. package/dist/functions/symbol/symbols/dc.js +82 -0
  59. package/dist/functions/symbol/symbols/{f.d.ts → ds.d.ts} +1 -1
  60. package/dist/functions/symbol/symbols/ds.js +93 -0
  61. package/dist/functions/symbol/symbols/dynamics.d.ts +3 -0
  62. package/dist/functions/symbol/symbols/dynamics.js +168 -0
  63. package/dist/functions/symbol/symbols/{p.d.ts → fine.d.ts} +1 -1
  64. package/dist/functions/symbol/symbols/fine.js +12 -0
  65. package/dist/functions/symbol/symbols/mordent.js +44 -31
  66. package/dist/functions/symbol/symbols/prall.d.ts +2 -0
  67. package/dist/functions/symbol/symbols/prall.js +42 -0
  68. package/dist/functions/symbol/symbols/segno.d.ts +4 -0
  69. package/dist/functions/symbol/symbols/segno.js +82 -0
  70. package/dist/functions/symbol/symbols/tr.js +0 -4
  71. package/dist/functions/tempo/index.js +5 -3
  72. package/dist/functions/temporal.d.ts +138 -0
  73. package/dist/functions/temporal.js +101 -0
  74. package/dist/functions/text/index.js +14 -7
  75. package/dist/functions/tie/index.js +37 -28
  76. package/dist/functions/tuplet/index.js +14 -7
  77. package/dist/functions/up/index.js +23 -21
  78. package/dist/functions/voice/index.js +121 -45
  79. package/dist/functions/volta/index.js +51 -48
  80. package/dist/iife/core.d.ts +1 -0
  81. package/dist/iife/core.js +3 -0
  82. package/dist/iife/from-midi.d.ts +1 -0
  83. package/dist/iife/from-midi.js +15 -0
  84. package/dist/iife/from-musicxml.d.ts +1 -0
  85. package/dist/iife/from-musicxml.js +3 -0
  86. package/dist/iife/full.d.ts +1 -0
  87. package/dist/iife/full.js +3 -0
  88. package/dist/index.d.ts +3 -21
  89. package/dist/index.js +3 -21
  90. package/dist/jpfun.core.min.js +153 -0
  91. package/dist/jpfun.from-midi.min.js +9 -0
  92. package/dist/jpfun.from-musicxml.min.js +12 -0
  93. package/dist/jpfun.min.js +71 -48
  94. package/dist/layout/default.js +2 -3
  95. package/dist/layout/engine.d.ts +2 -1
  96. package/dist/layout/engine.js +71 -26
  97. package/dist/layout/model.d.ts +4 -4
  98. package/dist/layout/model.js +15 -12
  99. package/dist/layout/page.js +5 -4
  100. package/dist/layout/path.js +3 -3
  101. package/dist/layout/types.d.ts +20 -2
  102. package/dist/lowering/loweringContext.d.ts +3 -1
  103. package/dist/lowering/loweringContext.js +28 -14
  104. package/dist/lowering/track.d.ts +4 -8
  105. package/dist/lowering/track.js +6 -1
  106. package/dist/lowering/types.d.ts +5 -128
  107. package/dist/lowering/types.js +1 -98
  108. package/dist/parser/parse-utils/string-utils.d.ts +2 -0
  109. package/dist/parser/parse-utils/string-utils.js +4 -0
  110. package/dist/parser/parserContext.d.ts +7 -8
  111. package/dist/parser/parserContext.js +41 -36
  112. package/dist/pipeline.d.ts +6 -5
  113. package/dist/pipeline.js +4 -5
  114. package/dist/playback/compile.d.ts +1 -1
  115. package/dist/playback/compile.js +15 -2
  116. package/dist/playback/event.d.ts +17 -3
  117. package/dist/playback/event.js +30 -12
  118. package/dist/playback/time.js +1 -1
  119. package/dist/playback/types.d.ts +5 -4
  120. package/dist/render/text.d.ts +6 -1
  121. package/dist/render/text.js +8 -1
  122. package/grammar.md +44 -8
  123. package/package.json +11 -2
  124. package/dist/functions/symbol/symbols/f.js +0 -55
  125. package/dist/functions/symbol/symbols/p.js +0 -61
@@ -1,4 +1,4 @@
1
- import { ANCHOR_KEY, isVisualTemporalNode, } from "../../lowering/types.js";
1
+ import { ANCHOR_KEY, isVisualTemporalNode, } from "../temporal.js";
2
2
  import { repeatPass } from "../bar/index.js";
3
3
  import { ASTFunctionNode, } from "../ASTtypes.js";
4
4
  import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
@@ -40,6 +40,7 @@ pass 是遍数:整段谱面演奏到第几遍时才播这里,必填正整数
40
40
  passes;
41
41
  /** 区间没有可见宿主时括线的尺寸基准 */
42
42
  size;
43
+ font;
43
44
  /** volta 不推进时间,只把 AST 端点解析成稳定的 temporal 引用 */
44
45
  loweringEnter(ctx) {
45
46
  let from = ctx.getTemporalNodes(this.from).at(0);
@@ -58,6 +59,7 @@ pass 是遍数:整段谱面演奏到第几遍时才播这里,必填正整数
58
59
  constructor(span, args, ctx, parent = null) {
59
60
  super(span, parent);
60
61
  const [from, to, pass] = this.getArgValue(args, ctx);
62
+ this.font = ctx.variables.numberfont;
61
63
  // 第一个遍数走 def.args,其余的落在 extraArgType 里,按位置索引取
62
64
  const passes = new Set([pass]);
63
65
  for (let i = 3; args.has(i); i++)
@@ -65,7 +67,7 @@ pass 是遍数:整段谱面演奏到第几遍时才播这里,必填正整数
65
67
  this.from = from;
66
68
  this.to = to;
67
69
  this.passes = [...passes].sort((a, b) => a - b);
68
- this.size = ctx.fontSize;
70
+ this.size = ctx.variables.fontsize;
69
71
  if (this.passes.some(value => !Number.isSafeInteger(value) || value <= 0)) {
70
72
  throw new ErrorDiagnostic("E_VOLTA_INVALID_PASS", "@volta 的遍数必须是正整数", span);
71
73
  }
@@ -87,14 +89,6 @@ class VoltaAttachment {
87
89
  from;
88
90
  to;
89
91
  layer = "foreground";
90
- /** 首末端点列最上方的对象、区间最大字号与紧邻的小节线,横向准备时填入 */
91
- head;
92
- tail;
93
- span = 0;
94
- leftBar;
95
- rightBar;
96
- /** 逐行记下覆盖列内各轨的最高点,相对该轨视觉轴;轴要等纵向求解才知道 */
97
- topsByLine = [];
98
92
  constructor(ast, from, to) {
99
93
  this.ast = ast;
100
94
  this.from = from;
@@ -117,11 +111,12 @@ class VoltaAttachment {
117
111
  : { kind: "jump", column: end + 1 },
118
112
  };
119
113
  }
120
- prepareHorizontal(lines) {
121
- if (!isVisualTemporalNode(this.from) || !isVisualTemporalNode(this.to))
122
- return;
114
+ createGeometry(context) {
115
+ if (!isVisualTemporalNode(this.from) || !isVisualTemporalNode(this.to)) {
116
+ return { regions: [], paint() { } };
117
+ }
123
118
  const locate = (node) => {
124
- const view = lines[node.layoutLine];
119
+ const view = context.lines[node.layoutLine];
125
120
  return { line: node.layoutLine, view, column: view.columnOf(node) };
126
121
  };
127
122
  // 两个标签谁写在前面不一定,按谱面顺序摆正
@@ -130,42 +125,29 @@ class VoltaAttachment {
130
125
  [from, to] = [to, from];
131
126
  }
132
127
  if (from.column < 0 || to.column < 0)
133
- return;
134
- this.head = from.view.columns[from.column][0];
135
- this.tail = to.view.columns[to.column][0];
136
- this.leftBar = barIn(from.view.columns[from.column - 1]);
137
- this.rightBar = barIn(to.view.columns[to.column + 1]);
138
- this.span = 0;
139
- this.topsByLine.length = 0;
128
+ return { regions: [], paint() { } };
129
+ const head = from.view.columns[from.column][0];
130
+ const tail = to.view.columns[to.column][0];
131
+ const leftBar = barIn(from.view.columns[from.column - 1]);
132
+ const rightBar = barIn(to.view.columns[to.column + 1]);
133
+ let span = 0;
134
+ const coverage = [];
140
135
  // 括线盖住的是:首行从起点列向右、末行向左到终点列、中间行整行
141
136
  for (let line = from.line; line <= to.line; line++) {
142
- const view = lines[line];
137
+ const view = context.lines[line];
143
138
  const start = line === from.line ? from.column : 0;
144
139
  const end = line === to.line ? to.column : view.columns.length - 1;
145
- const tops = new Map();
146
140
  for (let column = start; column <= end; column++) {
147
- const hosts = view.columns[column];
148
- this.span = Math.max(this.span, hosts[0].ast.size);
149
- // 此刻 visualAxis 已冻结,纵向求解后 box.y 就是 该轨视觉轴 - visualAxis
150
- for (const host of hosts) {
151
- const top = -host.box.visualAxis;
152
- const known = tops.get(host.track);
153
- if (known === undefined || top < known)
154
- tops.set(host.track, top);
155
- }
141
+ span = Math.max(span, view.columns[column][0].ast.size);
156
142
  }
157
- this.topsByLine.push(tops);
143
+ coverage.push({ from: start, to: end, wholeLine: line !== from.line && line !== to.line });
158
144
  }
159
- }
160
- createGeometry(context) {
161
- const { head, tail, leftBar, rightBar } = this;
162
- if (!head || !tail)
163
- return { regions: [], paint() { } };
164
145
  const firstLine = head.layoutLine;
165
146
  const lastLine = tail.layoutLine;
166
- const size = this.span || this.ast.size;
147
+ const size = span || this.ast.size;
167
148
  const style = {
168
149
  fontSize: size * 0.6,
150
+ fontFamily: this.ast.font,
169
151
  textAlign: "left",
170
152
  fill: "#000",
171
153
  };
@@ -179,17 +161,14 @@ class VoltaAttachment {
179
161
  // 中间行可能没有本房子的可见对象,仍要补满,所以按行号连续遍历
180
162
  const draws = Array.from({ length: lastLine - firstLine + 1 }, (_, offset) => {
181
163
  const line = firstLine + offset;
182
- // 跨行断开的那一侧一直画到页边,接上下一行
183
- const left = line !== firstLine ? context.originX
184
- : leftBar?.layoutLine === line ? leftBar.box.x + leftBar.box.anchor + 5 // 5是防止前后房子竖线重合
185
- : head.box.x + (head.ports["body.left"]?.x ?? 0);
186
- const right = line !== lastLine ? context.originX + context.width
187
- : rightBar?.layoutLine === line ? rightBar.box.x + rightBar.box.anchor
188
- : tail.box.x + (tail.ports["body.right"]?.x ?? tail.box.w);
189
164
  let topTrack = head.track;
190
165
  let hostTop = Infinity;
191
- for (const [track, top] of this.topsByLine[offset]) {
192
- const y = context.getVisualAxis(line, track) + top;
166
+ const range = coverage[offset];
167
+ const extents = range.wholeLine
168
+ ? context.getRangeExtents(line)
169
+ : context.getRangeExtents(line, [range.from, range.to]);
170
+ for (const [track, extent] of extents) {
171
+ const y = context.getVisualAxis(line, track) + extent.top;
193
172
  if (y < hostTop) {
194
173
  topTrack = track;
195
174
  hostTop = y;
@@ -198,6 +177,15 @@ class VoltaAttachment {
198
177
  // 整行空白时没有主体可以参照,退到轨道轴上
199
178
  if (hostTop === Infinity)
200
179
  hostTop = context.getVisualAxis(line, topTrack);
180
+ // 换行断点跟随系统的视觉边界;空行没有主体时仍退到内容区页边
181
+ const rawLeft = line !== firstLine ? this.lineEntryX(context, line, topTrack)
182
+ : leftBar?.layoutLine === line ? leftBar.box.x + leftBar.box.anchor + 5 // 5是防止前后房子竖线重合
183
+ : head.box.x + (head.ports["body.left"]?.x ?? 0);
184
+ const rawRight = line !== lastLine ? this.lineRightX(context, line)
185
+ : rightBar?.layoutLine === line ? rightBar.box.x + rightBar.box.anchor
186
+ : tail.box.x + (tail.ports["body.right"]?.x ?? tail.box.w);
187
+ const left = Math.min(rawLeft, rawRight);
188
+ const right = Math.max(rawLeft, rawRight);
201
189
  return { left, right, lineY: hostTop - size * 0.2 - hook, line, track: topTrack };
202
190
  });
203
191
  return {
@@ -224,4 +212,19 @@ class VoltaAttachment {
224
212
  },
225
213
  };
226
214
  }
215
+ lineEntryX(context, line, track) {
216
+ const host = context.lines[line].trackRuns.get(track)?.find(item => !item.T.isZero());
217
+ return host?.box.x ?? context.originX;
218
+ }
219
+ lineRightX(context, line) {
220
+ const runs = context.lines[line].trackRuns;
221
+ if (runs.size === 0)
222
+ return context.originX + context.width;
223
+ let right = context.originX;
224
+ for (const run of runs.values()) {
225
+ for (const host of run)
226
+ right = Math.max(right, host.box.x + host.box.w);
227
+ }
228
+ return right;
229
+ }
227
230
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import * as core from "../core.js";
2
+ const target = globalThis;
3
+ Object.assign(target.jpfun ??= {}, core);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { convertMidiJsonToJpFun, } from "../converter/midi/convert.js";
2
+ const target = globalThis;
3
+ const api = target.jpfun ??= {};
4
+ Object.assign(api, {
5
+ midiJsonToJpFun(input, options = {}) {
6
+ const layoutCapability = (options.barsPerLine ?? 0) <= 0
7
+ ? {
8
+ compileScore: api.compileScore,
9
+ anchorKey: api.ANCHOR_KEY,
10
+ page: api.DEFAULT_PAGE_CONFIG,
11
+ }
12
+ : undefined;
13
+ return convertMidiJsonToJpFun(input, options, layoutCapability);
14
+ },
15
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { musicXmlToJpFun } from "../converter/musicxml/index.js";
2
+ const target = globalThis;
3
+ Object.assign(target.jpfun ??= {}, { musicXmlToJpFun });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import * as full from "../index.js";
2
+ const target = globalThis;
3
+ Object.assign(target.jpfun ??= {}, full);
package/dist/index.d.ts CHANGED
@@ -1,21 +1,3 @@
1
- export * from "./pipeline.js";
2
- export * from "./functions/ASTtypes.js";
3
- export * from "./functions/default.js";
4
- export * from "./diagnostic.js";
5
- export * from "./fraction.js";
6
- export * from "./parser/types.js";
7
- export * from "./parser/grammarType.js";
8
- export * from "./parser/parserContext.js";
9
- export * from "./parser/preprocess.js";
10
- export * from "./lowering/types.js";
11
- export * from "./lowering/loweringContext.js";
12
- export * from "./lowering/track.js";
13
- export * from "./playback/types.js";
14
- export * from "./playback/time.js";
15
- export * from "./playback/compile.js";
16
- export * from "./layout/types.js";
17
- export * from "./layout/model.js";
18
- export * from "./layout/default.js";
19
- export * from "./layout/page.js";
20
- export * from "./layout/engine.js";
21
- export * from "./render/index.js";
1
+ export * from "./core.js";
2
+ export * from "./converter/midi/index.js";
3
+ export * from "./converter/musicxml/index.js";
package/dist/index.js CHANGED
@@ -1,21 +1,3 @@
1
- export * from "./pipeline.js";
2
- export * from "./functions/ASTtypes.js";
3
- export * from "./functions/default.js";
4
- export * from "./diagnostic.js";
5
- export * from "./fraction.js";
6
- export * from "./parser/types.js";
7
- export * from "./parser/grammarType.js";
8
- export * from "./parser/parserContext.js";
9
- export * from "./parser/preprocess.js";
10
- export * from "./lowering/types.js";
11
- export * from "./lowering/loweringContext.js";
12
- export * from "./lowering/track.js";
13
- export * from "./playback/types.js";
14
- export * from "./playback/time.js";
15
- export * from "./playback/compile.js";
16
- export * from "./layout/types.js";
17
- export * from "./layout/model.js";
18
- export * from "./layout/default.js";
19
- export * from "./layout/page.js";
20
- export * from "./layout/engine.js";
21
- export * from "./render/index.js";
1
+ export * from "./core.js";
2
+ export * from "./converter/midi/index.js";
3
+ export * from "./converter/musicxml/index.js";