jpfun 0.7.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.
Files changed (152) hide show
  1. package/Bravura-LICENSE.txt +93 -0
  2. package/README.md +49 -146
  3. package/dist/Bravura-LICENSE.txt +93 -0
  4. package/dist/converter/midi/convert.d.ts +0 -10
  5. package/dist/converter/midi/convert.js +19 -56
  6. package/dist/converter/musicxml/features.d.ts +16 -8
  7. package/dist/converter/musicxml/features.js +88 -19
  8. package/dist/converter/musicxml/index.js +88 -50
  9. package/dist/converter/musicxml/model.d.ts +9 -0
  10. package/dist/converter/source.d.ts +4 -7
  11. package/dist/converter/source.js +11 -9
  12. package/dist/core.d.ts +1 -0
  13. package/dist/core.js +1 -0
  14. package/dist/diagnostic.d.ts +7 -1
  15. package/dist/diagnostic.js +40 -88
  16. package/dist/fraction.js +3 -2
  17. package/dist/functions/ASTtypes.d.ts +3 -32
  18. package/dist/functions/ASTtypes.js +5 -52
  19. package/dist/functions/adjust/index.js +45 -33
  20. package/dist/functions/arpeggio/index.js +50 -55
  21. package/dist/functions/arpeggio/shape.d.ts +2 -3
  22. package/dist/functions/arpeggio/shape.js +20 -50
  23. package/dist/functions/bar/index.d.ts +8 -0
  24. package/dist/functions/bar/index.js +105 -8
  25. package/dist/functions/beam/auto.d.ts +1 -2
  26. package/dist/functions/beam/auto.js +80 -135
  27. package/dist/functions/beam/index.js +6 -12
  28. package/dist/functions/beam/layout.d.ts +1 -1
  29. package/dist/functions/beam/layout.js +1 -1
  30. package/dist/functions/box/index.js +0 -6
  31. package/dist/functions/br/index.d.ts +34 -2
  32. package/dist/functions/br/index.js +5 -4
  33. package/dist/functions/dash/index.js +9 -10
  34. package/dist/functions/default.js +2 -1
  35. package/dist/functions/div/index.d.ts +3 -4
  36. package/dist/functions/div/index.js +18 -14
  37. package/dist/functions/dot/index.js +5 -11
  38. package/dist/functions/dyn/index.js +55 -57
  39. package/dist/functions/gliss/index.js +131 -103
  40. package/dist/functions/grace/index.d.ts +3 -12
  41. package/dist/functions/grace/index.js +52 -102
  42. package/dist/functions/head/index.js +10 -7
  43. package/dist/functions/key/index.js +13 -15
  44. package/dist/functions/meter/index.d.ts +56 -1
  45. package/dist/functions/meter/index.js +15 -10
  46. package/dist/functions/note/index.js +6 -6
  47. package/dist/functions/note/noteName.d.ts +16 -0
  48. package/dist/functions/note/noteName.js +88 -0
  49. package/dist/functions/note/source-transform.js +8 -10
  50. package/dist/functions/ottava/index.js +35 -40
  51. package/dist/functions/page/index.d.ts +1 -0
  52. package/dist/functions/page/index.js +27 -21
  53. package/dist/functions/pagebreak/index.js +2 -2
  54. package/dist/functions/rest/index.js +5 -5
  55. package/dist/functions/set/index.js +4 -4
  56. package/dist/functions/slide/index.js +0 -1
  57. package/dist/functions/stack/index.js +8 -57
  58. package/dist/functions/symbol/index.d.ts +21 -2
  59. package/dist/functions/symbol/index.js +69 -24
  60. package/dist/functions/symbol/ornament.d.ts +1 -2
  61. package/dist/functions/symbol/shape.d.ts +6 -0
  62. package/dist/functions/symbol/shape.js +16 -3
  63. package/dist/functions/symbol/symbols/coda.d.ts +4 -0
  64. package/dist/functions/symbol/symbols/coda.js +56 -0
  65. package/dist/functions/symbol/symbols/dynamics.d.ts +1 -1
  66. package/dist/functions/symbol/symbols/dynamics.js +18 -8
  67. package/dist/functions/symbol/symbols/harmonic.d.ts +2 -0
  68. package/dist/functions/symbol/symbols/harmonic.js +11 -0
  69. package/dist/functions/symbol/symbols/marcato.d.ts +2 -0
  70. package/dist/functions/symbol/symbols/marcato.js +22 -0
  71. package/dist/functions/symbol/symbols/staccato.d.ts +2 -0
  72. package/dist/functions/symbol/symbols/staccato.js +24 -0
  73. package/dist/functions/symbol/symbols/tenuto.d.ts +2 -0
  74. package/dist/functions/symbol/symbols/tenuto.js +11 -0
  75. package/dist/functions/symbol/symbols/tocoda.d.ts +2 -0
  76. package/dist/functions/symbol/symbols/tocoda.js +16 -0
  77. package/dist/functions/symbol/symbols/turn.d.ts +3 -0
  78. package/dist/functions/symbol/symbols/turn.js +50 -0
  79. package/dist/functions/symbol/symbols/wheel.d.ts +2 -0
  80. package/dist/functions/symbol/symbols/wheel.js +36 -0
  81. package/dist/functions/temporal.d.ts +3 -2
  82. package/dist/functions/temporal.js +8 -0
  83. package/dist/functions/text/index.js +38 -35
  84. package/dist/functions/tie/index.js +44 -43
  85. package/dist/functions/tremolo/index.d.ts +2 -0
  86. package/dist/functions/tremolo/index.js +318 -0
  87. package/dist/functions/tuplet/index.js +4 -14
  88. package/dist/functions/up/index.js +81 -85
  89. package/dist/functions/voice/connections.d.ts +2 -1
  90. package/dist/functions/voice/connections.js +48 -10
  91. package/dist/functions/voice/index.d.ts +2 -3
  92. package/dist/functions/voice/index.js +2 -963
  93. package/dist/functions/voice/lyrics.d.ts +30 -0
  94. package/dist/functions/voice/lyrics.js +289 -0
  95. package/dist/functions/voice/voice.d.ts +63 -0
  96. package/dist/functions/voice/voice.js +373 -0
  97. package/dist/functions/voice/voices.d.ts +106 -0
  98. package/dist/functions/voice/voices.js +423 -0
  99. package/dist/functions/volta/index.js +5 -23
  100. package/dist/jpfun.core.min.js +76 -59
  101. package/dist/jpfun.from-midi.min.js +5 -5
  102. package/dist/jpfun.from-musicxml.min.js +8 -8
  103. package/dist/jpfun.min.js +81 -64
  104. package/dist/layout/default.d.ts +0 -1
  105. package/dist/layout/default.js +0 -1
  106. package/dist/layout/engine.js +30 -18
  107. package/dist/layout/model.d.ts +0 -1
  108. package/dist/layout/model.js +1 -4
  109. package/dist/layout/page.d.ts +2 -1
  110. package/dist/layout/page.js +14 -14
  111. package/dist/layout/range.d.ts +7 -6
  112. package/dist/layout/range.js +23 -14
  113. package/dist/layout/types.d.ts +9 -28
  114. package/dist/lowering/loweringContext.d.ts +18 -23
  115. package/dist/lowering/loweringContext.js +33 -46
  116. package/dist/lowering/track.d.ts +8 -1
  117. package/dist/lowering/types.d.ts +13 -11
  118. package/dist/parser/parse-utils/call-utils.d.ts +1 -2
  119. package/dist/parser/parse-utils/call-utils.js +6 -34
  120. package/dist/parser/parse-utils/note-utils.d.ts +3 -3
  121. package/dist/parser/parse-utils/note-utils.js +21 -33
  122. package/dist/parser/parse-utils/string-utils.d.ts +3 -2
  123. package/dist/parser/parse-utils/string-utils.js +20 -5
  124. package/dist/parser/parserContext.d.ts +9 -9
  125. package/dist/parser/parserContext.js +62 -11
  126. package/dist/pipeline.js +2 -3
  127. package/dist/playback/compile.js +131 -82
  128. package/dist/playback/event.d.ts +6 -6
  129. package/dist/playback/event.js +13 -49
  130. package/dist/playback/time.js +42 -31
  131. package/dist/playback/types.d.ts +3 -1
  132. package/dist/render/canvas.js +4 -22
  133. package/dist/render/recording.js +1 -4
  134. package/dist/render/svg.d.ts +0 -1
  135. package/dist/render/svg.js +33 -31
  136. package/dist/render/text.d.ts +36 -1
  137. package/dist/render/text.js +134 -0
  138. package/dist/render/translate.d.ts +0 -1
  139. package/dist/render/translate.js +6 -23
  140. package/dist/render/types.d.ts +0 -2
  141. package/grammar.md +39 -30
  142. package/package.json +3 -3
  143. package/dist/functions/note/noteNameFSM.d.ts +0 -8
  144. package/dist/functions/note/noteNameFSM.js +0 -181
  145. package/dist/iife/core.d.ts +0 -1
  146. package/dist/iife/core.js +0 -3
  147. package/dist/iife/from-midi.d.ts +0 -1
  148. package/dist/iife/from-midi.js +0 -15
  149. package/dist/iife/from-musicxml.d.ts +0 -1
  150. package/dist/iife/from-musicxml.js +0 -3
  151. package/dist/iife/full.d.ts +0 -1
  152. package/dist/iife/full.js +0 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jpfun",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "A functional numbered musical notation typesetting engine",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,6 +27,7 @@
27
27
  "dist",
28
28
  "README.md",
29
29
  "LICENSE",
30
+ "Bravura-LICENSE.txt",
30
31
  "grammar.md"
31
32
  ],
32
33
  "engines": {
@@ -50,8 +51,7 @@
50
51
  "build:bundle": "node ../../scripts/build-jpfun-bundles.mjs && node --test ../../scripts/test-jpfun-bundles.mjs",
51
52
  "prepack": "pnpm run build",
52
53
  "typecheck": "tsc -p test/tsconfig.json",
53
- "test": "node --import tsx --test \"test/*.test.ts\"",
54
- "test:update": "node --import tsx --test \"test/*.test.ts\""
54
+ "test": "node --import tsx --test \"test/*.test.ts\""
55
55
  },
56
56
  "keywords": [
57
57
  "numbered-musical-notation",
@@ -1,8 +0,0 @@
1
- import { Diagnostic } from "../../diagnostic.js";
2
- export declare function parseNoteName(str: string, start?: number, end?: number): {
3
- name: string;
4
- next: number;
5
- acc: string | null;
6
- octave: number | null;
7
- absOctave: boolean;
8
- } | Diagnostic;
@@ -1,181 +0,0 @@
1
- import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
2
- const LETTER_NOTE_START_RE = /^[A-GXZ]/;
3
- const NUM_NOTE_START_RE = /^[0-9]/;
4
- const SHARP_RE = /^[#bn]+/;
5
- const ABS_OCTAVE_RE = /^[+-]?\d+/;
6
- const RELATIVE_OCTAVE_RE = /^[,']+/;
7
- export function parseNoteName(str, start = 0, end = str.length) {
8
- if ((end - start) === 0)
9
- return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 不能为空`, { start, end });
10
- // 用状态机解决 详细信息查看FSM.drawio
11
- let state = 0;
12
- let name = null, acc = null, octave = null, absOctave = false;
13
- let match;
14
- for (let pos = start; pos < end; pos++) {
15
- const ch = str[pos];
16
- switch (state) {
17
- case 0:
18
- if (LETTER_NOTE_START_RE.test(ch)) {
19
- name = ch;
20
- absOctave = true;
21
- state = 1;
22
- }
23
- else if (NUM_NOTE_START_RE.test(ch)) {
24
- name = ch;
25
- absOctave = false;
26
- state = 3;
27
- }
28
- else {
29
- const match = str.slice(pos, end).match(SHARP_RE);
30
- if (match) {
31
- acc = match[0];
32
- pos += acc.length - 1;
33
- absOctave = false;
34
- state = 2;
35
- }
36
- else
37
- return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 格式错误: 首字符 "${ch}" 不合法,期望 A-G (a-g)、0-9、X 或 Z 开头,或在开头直接使用升降号(#/b/n)`, { start: pos, end: pos + 1 });
38
- }
39
- break;
40
- case 1: // [字母模式] 已获得音名
41
- const subs = str.slice(pos, end);
42
- match = subs.match(ABS_OCTAVE_RE);
43
- if (match) {
44
- octave = parseInt(match[0], 10);
45
- pos += match[0].length - 1;
46
- state = 4;
47
- break;
48
- }
49
- match = subs.match(SHARP_RE);
50
- if (match) {
51
- acc = match[0];
52
- pos += acc.length - 1;
53
- state = 5;
54
- break;
55
- }
56
- return {
57
- name: name,
58
- next: pos,
59
- acc: null,
60
- octave: null,
61
- absOctave,
62
- };
63
- case 2: // [数字模式] 已获得升降号
64
- if (NUM_NOTE_START_RE.test(ch)) {
65
- name = ch;
66
- state = 6;
67
- break;
68
- }
69
- else
70
- return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 格式错误: 在升降号开头时,应该接数字音名,但发现字符 "${ch}"`, { start: pos, end: pos + 1 });
71
- case 3: // [数字模式] 已获得音名
72
- match = str.slice(pos, end).match(RELATIVE_OCTAVE_RE);
73
- if (match) {
74
- const octave_str = match[0];
75
- octave = relativeOctaveFromString(octave_str);
76
- return {
77
- name: name,
78
- next: pos + octave_str.length,
79
- acc,
80
- octave: octave,
81
- absOctave,
82
- };
83
- }
84
- match = str.slice(pos, end).match(SHARP_RE);
85
- if (match && !NUM_NOTE_START_RE.test(str[pos + match[0].length] ?? "")) {
86
- const accidental = match[0];
87
- acc = accidental;
88
- pos += accidental.length - 1;
89
- state = 6;
90
- break;
91
- }
92
- return {
93
- name: name,
94
- next: pos,
95
- acc,
96
- octave: octave,
97
- absOctave,
98
- };
99
- case 4: // [字母模式] 已获得音名和八度
100
- match = str.slice(pos, end).match(SHARP_RE);
101
- if (match && !NUM_NOTE_START_RE.test(str[pos + match[0].length] ?? "")) {
102
- const accidental = match[0];
103
- acc = accidental;
104
- return {
105
- name: name,
106
- next: pos + accidental.length,
107
- acc,
108
- octave,
109
- absOctave,
110
- };
111
- }
112
- return {
113
- name: name,
114
- next: pos,
115
- acc: null,
116
- octave,
117
- absOctave,
118
- };
119
- case 5: // [字母模式] 已获得音名和半音
120
- match = str.slice(pos, end).match(ABS_OCTAVE_RE);
121
- if (match) {
122
- octave = parseInt(match[0], 10);
123
- return {
124
- name: name,
125
- next: pos + match[0].length,
126
- acc,
127
- octave,
128
- absOctave,
129
- };
130
- }
131
- return {
132
- name: name,
133
- next: pos,
134
- acc: acc,
135
- octave: null,
136
- absOctave,
137
- };
138
- case 6: // [数字模式] 已获得升降号和音名
139
- match = str.slice(pos, end).match(RELATIVE_OCTAVE_RE);
140
- if (match) {
141
- const octave_str = match[0];
142
- octave = relativeOctaveFromString(octave_str);
143
- return {
144
- name: name,
145
- next: pos + octave_str.length,
146
- acc,
147
- octave,
148
- absOctave,
149
- };
150
- }
151
- return {
152
- name: name,
153
- next: pos,
154
- acc,
155
- octave,
156
- absOctave,
157
- };
158
- default:
159
- return Diagnostic.error.Bug("音符名称解析状态机进入了未定义的状态", { start: pos, end });
160
- }
161
- }
162
- if (name === null)
163
- return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 格式错误: 在升降号开头时,应该接数字音名,但输入已结束`, { start, end });
164
- return {
165
- name,
166
- next: end,
167
- acc,
168
- octave,
169
- absOctave
170
- };
171
- }
172
- function relativeOctaveFromString(octaveStr) {
173
- let octave = 0;
174
- for (let i = 0; i < octaveStr.length; i++) {
175
- if (octaveStr[i] === ',')
176
- octave--;
177
- else if (octaveStr[i] === "'")
178
- octave++;
179
- }
180
- return octave;
181
- }
@@ -1 +0,0 @@
1
- export {};
package/dist/iife/core.js DELETED
@@ -1,3 +0,0 @@
1
- import * as core from "../core.js";
2
- const target = globalThis;
3
- Object.assign(target.jpfun ??= {}, core);
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { musicXmlToJpFun } from "../converter/musicxml/index.js";
2
- const target = globalThis;
3
- Object.assign(target.jpfun ??= {}, { musicXmlToJpFun });
@@ -1 +0,0 @@
1
- export {};
package/dist/iife/full.js DELETED
@@ -1,3 +0,0 @@
1
- import * as full from "../index.js";
2
- const target = globalThis;
3
- Object.assign(target.jpfun ??= {}, full);