jianpurender 1.1.6

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 (59) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +101 -0
  3. package/dist/jianpurender.js +1 -0
  4. package/es5/index.d.ts +4 -0
  5. package/es5/jianpu_block.d.ts +32 -0
  6. package/es5/jianpu_info.d.ts +29 -0
  7. package/es5/jianpu_model.d.ts +20 -0
  8. package/es5/jianpu_svg_render.d.ts +59 -0
  9. package/es5/lib.d.ts +1 -0
  10. package/es5/measure_info.d.ts +26 -0
  11. package/es5/model_constants.d.ts +7 -0
  12. package/es5/render_constants.d.ts +11 -0
  13. package/es5/svg_paths.d.ts +8 -0
  14. package/es5/svg_tools.d.ts +9 -0
  15. package/es6/index.d.ts +4 -0
  16. package/es6/index.js +1 -0
  17. package/es6/jianpu_block.d.ts +32 -0
  18. package/es6/jianpu_block.js +1 -0
  19. package/es6/jianpu_info.d.ts +29 -0
  20. package/es6/jianpu_info.js +1 -0
  21. package/es6/jianpu_model.d.ts +20 -0
  22. package/es6/jianpu_model.js +1 -0
  23. package/es6/jianpu_svg_render.d.ts +59 -0
  24. package/es6/jianpu_svg_render.js +1 -0
  25. package/es6/lib.d.ts +1 -0
  26. package/es6/lib.js +1 -0
  27. package/es6/measure_info.d.ts +26 -0
  28. package/es6/measure_info.js +1 -0
  29. package/es6/model_constants.d.ts +7 -0
  30. package/es6/model_constants.js +1 -0
  31. package/es6/render_constants.d.ts +11 -0
  32. package/es6/render_constants.js +1 -0
  33. package/es6/svg_paths.d.ts +8 -0
  34. package/es6/svg_paths.js +1 -0
  35. package/es6/svg_tools.d.ts +9 -0
  36. package/es6/svg_tools.js +1 -0
  37. package/node/index.d.ts +4 -0
  38. package/node/index.js +1 -0
  39. package/node/jianpu_block.d.ts +32 -0
  40. package/node/jianpu_block.js +1 -0
  41. package/node/jianpu_info.d.ts +29 -0
  42. package/node/jianpu_info.js +1 -0
  43. package/node/jianpu_model.d.ts +20 -0
  44. package/node/jianpu_model.js +1 -0
  45. package/node/jianpu_svg_render.d.ts +59 -0
  46. package/node/jianpu_svg_render.js +1 -0
  47. package/node/lib.d.ts +1 -0
  48. package/node/lib.js +1 -0
  49. package/node/measure_info.d.ts +26 -0
  50. package/node/measure_info.js +1 -0
  51. package/node/model_constants.d.ts +7 -0
  52. package/node/model_constants.js +1 -0
  53. package/node/render_constants.d.ts +11 -0
  54. package/node/render_constants.js +1 -0
  55. package/node/svg_paths.d.ts +8 -0
  56. package/node/svg_paths.js +1 -0
  57. package/node/svg_tools.d.ts +9 -0
  58. package/node/svg_tools.js +1 -0
  59. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright 2025 flufy3d. All rights reserved.
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright 2025, flufy3d
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # JianpuRender
2
+
3
+ 专业的浏览器端简谱渲染库,基于TypeScript和SVG技术实现音乐符号精准绘制。支持动态交互与多端适配。
4
+
5
+ ## 核心功能
6
+
7
+ ✅ 完整简谱符号体系支持
8
+ - 音符/休止符(全音符至64分音符)
9
+ - 升降记号(#/b)与附点音符
10
+ - 12种调号支持(含5个升号调与6个降号调)
11
+ - 复杂节拍组合(2/4, 3/8, 5/16等)
12
+
13
+ 🎛 交互特性
14
+ - 音符高亮反馈
15
+ - 实时音频同步播放
16
+ - SVG动画效果支持
17
+
18
+ 🔧 开发者工具
19
+ - 类型安全的API设计
20
+ - 模块化SVG绘图工具集
21
+ - 自动化测试覆盖率85%+
22
+
23
+ ## 在线演示
24
+
25
+ [基础符号演示](https://flufy3d.github.io/JianpuRender/basic_symbols.html)
26
+ [动态音符演示](https://flufy3d.github.io/JianpuRender/active_notes.html)
27
+ [SVG工具测试](https://flufy3d.github.io/JianpuRender/svg_tools_test.html)
28
+
29
+ ## 快速开始
30
+
31
+ ```bash
32
+ npm install jianpurender
33
+ # 或
34
+ pnpm add jianpurender
35
+ ```
36
+
37
+ ```typescript
38
+ import { JianpuSVGRender } from 'jianpurender';
39
+
40
+ // 初始化容器
41
+ const container = document.getElementById('score-container')! as HTMLDivElement;
42
+
43
+ // 创建渲染实例
44
+ const renderer = new JianpuSVGRender(
45
+ {
46
+ notes: [
47
+ { start: 0, length: 1, pitch: 60 },
48
+ { start: 1, length: 1, pitch: 62 },
49
+ { start: 2, length: 1, pitch: 64 },
50
+ { start: 3, length: 1, pitch: 65 },
51
+ { start: 4, length: 1, pitch: 67 },
52
+ { start: 5, length: 1, pitch: 69 },
53
+ { start: 6, length: 1, pitch: 71 },
54
+ { start: 7, length: 1, pitch: 72 }
55
+ ],
56
+ keySignatures: [{ start: 0, key: 0 }],
57
+ timeSignatures: [{ start: 0, numerator: 4, denominator: 4 }]
58
+ },
59
+ { noteHeight: 24 },
60
+ container
61
+ );
62
+ ```
63
+
64
+ ## 开发指南
65
+
66
+ ```bash
67
+ git clone https://github.com/flufy3d/jianpurender.git
68
+ cd jianpurender
69
+
70
+ # 安装依赖
71
+ yarn install
72
+
73
+ # 构建项目
74
+ yarn build
75
+
76
+ # 运行测试
77
+ yarn test
78
+
79
+ # 启动本地演示
80
+ yarn demo:serve
81
+ ```
82
+
83
+ ## 贡献规范
84
+
85
+ 1. 提交前运行完整测试套件:
86
+ ```bash
87
+ yarn test-and-build
88
+ ```
89
+ 2. 新功能开发需配套测试用例
90
+ 3. API变更需更新`/node/index.d.ts`文件
91
+ 4. 文档更新同步至`/docs/`目录
92
+
93
+ ## 技术栈
94
+
95
+ - SVG绘图引擎:`src/svg_tools.ts`
96
+ - 乐谱解析器:`src/jianpu_model.ts`
97
+ - 渲染管线:`src/jianpu_svg_render.ts`
98
+
99
+ ![测试覆盖率](https://img.shields.io/badge/coverage-85%25-brightgreen)
100
+
101
+
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var t,e={75:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DURATION_LINE_SCALES=e.SMALL_FONT_SIZE_MULTIPLIER=e.FONT_SIZE_MULTIPLIER=e.AUGMENTATION_SPACING_FACTOR=e.ACCIDENTAL_SPACING_FACTOR=e.AUGMENTATION_DASH_FACTOR=e.DOT_SIZE_FACTOR=e.OCTAVE_DOT_OFFSET_FACTOR=e.UNDERLINE_SPACING_FACTOR=e.COMPACT_SPACING_FACTOR=e.LINE_STROKE_WIDTH=void 0,e.LINE_STROKE_WIDTH=1,e.COMPACT_SPACING_FACTOR=1.5,e.UNDERLINE_SPACING_FACTOR=.2,e.OCTAVE_DOT_OFFSET_FACTOR=1,e.DOT_SIZE_FACTOR=.1,e.AUGMENTATION_DASH_FACTOR=.8,e.ACCIDENTAL_SPACING_FACTOR=.1,e.AUGMENTATION_SPACING_FACTOR=.2,e.FONT_SIZE_MULTIPLIER=1.2,e.SMALL_FONT_SIZE_MULTIPLIER=.75,e.DURATION_LINE_SCALES=new Map([[1,1.78],[2,1.6],[3,1.3],[4,1.15]])},88:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuSVGRender=e.ScrollType=void 0;var n,r=i(75),a=i(811),s=i(388),o=i(567),h=i(186),u=i(214);!function(t){t[t.PAGE=0]="PAGE",t[t.NOTE=1]="NOTE",t[t.BAR=2]="BAR"}(n||(e.ScrollType=n={}));var l=function(){function t(t,e,i){var a,s,u,l,c,d,g,m,f,p,S,T=this;this.handleScrollEvent=function(t){T.lastKnownScrollLeft=T.parentElement.scrollLeft,T.isScrolling||window.requestAnimationFrame((function(){T.updateOverlaySignaturesForScroll(T.lastKnownScrollLeft),T.isScrolling=!1})),T.isScrolling=!0},this.jianpuInfo=t,this.div=i,this.config={noteHeight:null!==(a=e.noteHeight)&&void 0!==a?a:20,noteSpacingFactor:null!==(s=e.noteSpacingFactor)&&void 0!==s?s:r.COMPACT_SPACING_FACTOR,pixelsPerTimeStep:null!==(u=e.pixelsPerTimeStep)&&void 0!==u?u:0,noteColor:null!==(l=e.noteColor)&&void 0!==l?l:"black",activeNoteColor:null!==(c=e.activeNoteColor)&&void 0!==c?c:"red",defaultKey:null!==(d=e.defaultKey)&&void 0!==d?d:0,scrollType:null!==(g=e.scrollType)&&void 0!==g?g:n.PAGE,fontFamily:null!==(m=e.fontFamily)&&void 0!==m?m:"sans-serif",width:null!==(f=e.width)&&void 0!==f?f:0,height:null!==(p=e.height)&&void 0!==p?p:0},this.jianpuModel=new h.JianpuModel(this.jianpuInfo,this.config.defaultKey),this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(S=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==S?S:o.DEFAULT_TIME_SIGNATURE,this.playingNotes=new Map,this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.numberFontSize=this.config.noteHeight*r.FONT_SIZE_MULTIPLIER,this.smallFontSize=this.config.noteHeight*r.SMALL_FONT_SIZE_MULTIPLIER,this.estimatedNoteWidth=.6*this.numberFontSize,this.yBaseline=1.5*this.config.noteHeight,this.height=0,this.width=0,this.clear(),this.redraw()}return t.prototype.clear=function(){for(var t;this.div.lastChild;)this.div.removeChild(this.div.lastChild);this.div.style.position="relative",this.div.style.overflow="hidden",this.overlaySVG=document.createElementNS(a.SVGNS,"svg"),this.overlaySVG.style.position="absolute",this.overlaySVG.style.left="0",this.overlaySVG.style.top="0",this.overlaySVG.style.pointerEvents="none",this.div.appendChild(this.overlaySVG),this.overlayG=(0,a.createSVGGroupChild)(this.overlaySVG,"overlay"),this.parentElement=document.createElement("div"),this.parentElement.style.overflowX="auto",this.parentElement.style.overflowY="hidden",this.parentElement.style.width="100%",this.parentElement.style.height="100%",this.div.appendChild(this.parentElement),this.parentElement.addEventListener("scroll",this.handleScrollEvent),this.mainSVG=document.createElementNS(a.SVGNS,"svg"),this.mainSVG.style.display="block",this.parentElement.appendChild(this.mainSVG),this.mainG=(0,a.createSVGGroupChild)(this.mainSVG,"main-content"),this.signaturesG=(0,a.createSVGGroupChild)(this.mainG,"signatures"),this.musicG=(0,a.createSVGGroupChild)(this.mainG,"music"),this.playingNotes.clear(),this.lastRenderedQ=-1,this.signaturesBlinking=!1,this.lastKnownScrollLeft=0,this.isScrolling=!1,this.height=this.config.height>0?this.config.height:5*this.config.noteHeight,this.width=this.config.width>0?this.config.width:0,this.currentKey=this.jianpuModel.measuresInfo.keySignatureAtQ(0),this.currentTimeSignature=null!==(t=this.jianpuModel.measuresInfo.timeSignatureAtQ(0))&&void 0!==t?t:o.DEFAULT_TIME_SIGNATURE,this.drawSignatures(this.overlayG,0,!0,!0),this.updateLayout()},t.prototype.updateLayout=function(t){this.width=null!=t?t:this.width,this.config.width>0&&(this.width=this.config.width),this.height=Math.max(this.height,6*this.config.noteHeight),this.config.height>0&&(this.height=this.config.height);var e=1.65*this.config.noteHeight;this.mainSVG.setAttribute("width","".concat(this.width)),this.mainSVG.setAttribute("height","".concat(this.height)),this.mainG.setAttribute("transform","translate(0, ".concat(this.yBaseline+e,")")),this.overlaySVG.setAttribute("width","200"),this.overlaySVG.setAttribute("height","".concat(this.height)),this.overlayG.setAttribute("transform","translate(0, ".concat(this.yBaseline,")"))},t.prototype.redraw=function(t,e){var i=this,r=-1,s=this.config.pixelsPerTimeStep<=0;if(t){var o="".concat(t.start,"-").concat(t.pitch);if(this.playingNotes.forEach((function(t,e){if(e!==o){var n=i.mainSVG.querySelector('g[data-id="'.concat(e,'"]'));n&&(0,a.resetElementHighlight)(n,i.config.noteColor),i.playingNotes.delete(e)}})),!this.playingNotes.has(o)){var h=this.mainSVG.querySelector('g[data-id="'.concat(o,'"]'));if(h){(0,a.highlightElement)(h,this.config.activeNoteColor),this.playingNotes.set(o,t);var u=h.getBoundingClientRect(),l=this.mainSVG.getBoundingClientRect();r=u.left-l.left+this.parentElement.scrollLeft;var c=h.hasAttribute("data-is-measure-start");e&&(this.config.scrollType!==n.BAR||c)&&this.scrollIntoViewIfNeeded(r)}}if(!s&&this.signaturesBlinking){var d=this.overlayG.getBoundingClientRect().width;this.jianpuModel.measuresInfo.quartersToTime(t.start,t.start)*this.config.pixelsPerTimeStep>d&&(this.signaturesBlinking=!1,(0,a.setBlinkAnimation)(this.overlayG,!1))}}else{this.jianpuModel.update(this.jianpuInfo,this.config.defaultKey);var g=this.width,m=this.width,f=this.height>0?this.height-this.yBaseline:3*this.config.noteHeight,p=0,S=new Map;this.jianpuModel.jianpuBlockMap.forEach((function(t,e){if(e>=i.lastRenderedQ-1e-9){g=s?m:i.jianpuModel.measuresInfo.quartersToTime(e,e)*i.config.pixelsPerTimeStep;var n=i.drawJianpuBlock(t,g,S);s?m+=n:m=Math.max(m,g+n);var r=i.mainSVG.querySelector('g[data-block-start="'.concat(t.start,'"]'));if(r)try{var a=r.getBBox(),o=a.y,h=a.y+a.height;p=Math.min(p,o),f=Math.max(f,h)}catch(t){}i.lastRenderedQ=e+t.length}})),this.height=Math.max(this.height,f-p+this.config.noteHeight),this.updateLayout(m)}return r},t.prototype.drawJianpuBlock=function(t,e,i){var n=0,o=this.config.pixelsPerTimeStep<=0,h=t.isMeasureBeginning(),u=(0,a.createSVGGroupChild)(this.musicG,"block-".concat(t.start));if(u.setAttribute("data-block-start","".concat(t.start)),h&&t.start>1e-6){var l=e-(o?.6*this.estimatedNoteWidth:4),c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE);(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)}var m=this.updateCurrentKey(t.start),f=this.updateCurrentTimeSignature(t.start),p=0;if((m||f)&&t.start>1e-6){var S=e+n;p=this.drawSignatures(this.signaturesG,S,m,f),o&&(n+=p+.2*this.estimatedNoteWidth)}var T=e+n,v=0;if(t.notes.length>0?v=this.drawNotes(t,T,i,u):t.length>1e-6&&(v=this.drawRest(t,T,u)),o){n+=v;var A=this.estimatedNoteWidth*this.config.noteSpacingFactor;t.beatEnd?A*=1:t.length<.0625?A*=.05:t.length<.125?A*=.1:t.length<.25?A*=.2:t.length<.5?A*=.4:t.length<1&&(A*=.5),n+=A}else n=Math.max(p,v);return this.jianpuModel.isLastMeasureAtQ(t.start+t.length)&&(l=e+n,c=2*this.config.noteHeight,d=0,g=(0,a.drawSVGPath)(this.musicG,s.barPath,l,d,1,c/s.PATH_SCALE),(0,a.setStroke)(g,this.config.noteColor,r.LINE_STROKE_WIDTH),o&&(n+=r.LINE_STROKE_WIDTH)),n},t.prototype.drawNotes=function(t,e,i,n){var o=this,h=e,u=e,l=.1*this.estimatedNoteWidth,c="".concat(this.numberFontSize,"px"),d="".concat(this.smallFontSize,"px"),g=t.durationLines,m=void 0===g?0:g,f=t.augmentationDots,p=void 0===f?0:f,S=t.augmentationDash,T=void 0!==S&&S;return t.notes.forEach((function(e){var g,f,S,v="".concat(e.start,"-").concat(e.pitch),A=(0,a.createSVGGroupChild)(n,v);t.isMeasureBeginning()&&A.setAttribute("data-is-measure-start","true");var E=h,_=E;if(0!==e.accidental){var I=s.ACCIDENTAL_TEXT[e.accidental];(0,a.drawSVGText)(A,I,E+l,0,d,"normal","end","text-top",o.config.noteColor)}var N=0;if(T){var y=o.config.noteHeight*r.AUGMENTATION_DASH_FACTOR,M=y/50,C=(0,a.drawSVGPath)(A,s.augmentationDashPath,E,0,M,1);(0,a.setStroke)(C,o.config.noteColor,r.LINE_STROKE_WIDTH),_=E+(N=y)}else{var L="".concat(e.jianpuNumber);_=E+(N=(0,a.drawSVGText)(A,L,E,0,c,"normal","start","middle",o.config.noteColor).getBBox().width)}if(0!==e.octaveDot&&!1===T)for(var b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),O=E+N/2,R=2.8*H,G=o.config.noteHeight*r.OCTAVE_DOT_OFFSET_FACTOR,D=0;D<Math.abs(e.octaveDot);D++){var P=(e.octaveDot>0?-G:.6*G)-D*R*(e.octaveDot>0?1:-1);(0,a.drawSVGPath)(A,s.dotPath,O,P,b,b)}if(m>0)for(var w=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,F=o.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,k=N/s.PATH_SCALE*(null!==(g=r.DURATION_LINE_SCALES.get(m))&&void 0!==g?g:1),V=0;V<m;V++){var x=w+V*F,B=(0,a.drawSVGPath)(A,s.underlinePath,E,x,k,1);(0,a.setStroke)(B,o.config.noteColor,r.LINE_STROKE_WIDTH)}var U=_+l;if(p>0){var H;for(b=(H=o.config.noteHeight*r.DOT_SIZE_FACTOR)/(.15*s.PATH_SCALE),D=0;D<p;D++)(0,a.drawSVGPath)(A,s.dotPath,U,0,b,b),U+=H+l;_=U+l}var j=_;if(e.tiedTo&&!T)i.set(e,{g:A,xNoteRight:j,yNoteBaseline:0});else if(e.tiedFrom){for(var Q=e.tiedFrom;Q.tiedFrom;)Q=Q.tiedFrom;var J=i.get(Q);if(J){var K=1*J.xNoteRight,W=(T?E-2.2*o.estimatedNoteWidth:E-l)-K,q=1.2*-o.config.noteHeight,Z=W/s.PATH_SCALE*1.3,z=o.config.noteHeight/s.PATH_SCALE*1.6;W>1&&(0,a.drawSVGPath)(J.g,s.tiePath,K-(null!==(S=null===(f=J.g.getCTM())||void 0===f?void 0:f.e)&&void 0!==S?S:0),q,Z,z);for(var X=Q;X&&X!==e;){i.delete(X);var Y=X.tiedTo;Y&&(X=Y)}}else console.warn("Missing linked SVG details for first tied note:",Q)}u=Math.max(u,_)})),u-e},t.prototype.drawRest=function(t,e,i){var n,o="".concat(this.numberFontSize,"px"),h=.1*this.estimatedNoteWidth,u=t.durationLines,l=void 0===u?0:u,c=t.augmentationDots,d=void 0===c?0:c,g=e,m=g,f=(0,a.drawSVGText)(i,"0",g,0,o,"normal","start","middle",this.config.noteColor).getBBox().width;if(m=g+f,l>0)for(var p=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR*2.5,S=this.config.noteHeight*r.UNDERLINE_SPACING_FACTOR,T=f/s.PATH_SCALE*(null!==(n=r.DURATION_LINE_SCALES.get(l))&&void 0!==n?n:1),v=0;v<l;v++){var A=p+v*S,E=(0,a.drawSVGPath)(i,s.underlinePath,g,A,T,1);(0,a.setStroke)(E,this.config.noteColor,r.LINE_STROKE_WIDTH)}var _=m+h;if(d>0){for(var I=this.config.noteHeight*r.DOT_SIZE_FACTOR,N=I/(.15*s.PATH_SCALE),y=0;y<d;y++)(0,a.drawSVGPath)(i,s.dotPath,_,0,N,N),_+=I+h;m=_+h}return m-e},t.prototype.drawSignatures=function(t,e,i,n){var r,s=e,o=.3*this.estimatedNoteWidth,h="".concat(this.smallFontSize,"px"),l="".concat(this.numberFontSize,"px");if(i){var c=null!==(r=u.PITCH_CLASS_NAMES[this.currentKey%12])&&void 0!==r?r:"C",d="1=".concat(c);s+=(0,a.drawSVGText)(t,d,s,0,l,"normal","start","middle",this.config.noteColor).getBBox().width+2*o}if(n){var g="".concat(this.currentTimeSignature.numerator,"/").concat(this.currentTimeSignature.denominator);s+=(0,a.drawSVGText)(t,g,s,0,h,"normal","start","middle",this.config.noteColor).getBBox().width+o}var m=s-e;try{var f=t.getBBox(),p=f.y,S=f.y+f.height,T=Math.max(this.yBaseline+S,this.yBaseline-p)+.5*this.config.noteHeight;this.height=Math.max(this.height,T)}catch(t){}return t===this.overlayG&&this.config.pixelsPerTimeStep>0&&(this.signaturesBlinking=!0,(0,a.setBlinkAnimation)(this.overlayG,!0)),m},t.prototype.updateCurrentKey=function(t){var e=this.jianpuModel.measuresInfo.keySignatureAtQ(t,!0);return-1!==e&&e!==this.currentKey&&(this.currentKey=e,!0)},t.prototype.updateCurrentTimeSignature=function(t){var e=this.jianpuModel.measuresInfo.timeSignatureAtQ(t,!0);return!(!e||e.numerator===this.currentTimeSignature.numerator&&e.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=e,0))},t.prototype.scrollIntoViewIfNeeded=function(t){var e=this.parentElement.getBoundingClientRect().width,i=this.parentElement.scrollLeft,r=i;this.config.scrollType===n.PAGE?t<i+20?r=t-20:t>i+e-20&&(r=t-e+20):r=t-.5*e,r=Math.max(0,Math.min(r,this.parentElement.scrollWidth-e)),Math.abs(r-i)>1&&(this.parentElement.scrollTo({left:r,behavior:"smooth"}),this.updateOverlaySignaturesForScroll(r))},t.prototype.updateOverlaySignaturesForScroll=function(t){var e,i=this.pixelsToTime(t),n=this.jianpuModel.measuresInfo.keySignatureAtQ(i),r=null!==(e=this.jianpuModel.measuresInfo.timeSignatureAtQ(i))&&void 0!==e?e:this.currentTimeSignature,s=!1;if(n!==this.currentKey&&(this.currentKey=n,s=!0),r.numerator===this.currentTimeSignature.numerator&&r.denominator===this.currentTimeSignature.denominator||(this.currentTimeSignature=r,s=!0),s){for(;this.overlayG.lastChild;)this.overlayG.removeChild(this.overlayG.lastChild);this.drawSignatures(this.overlayG,0,!0,!0),t<10&&this.config.pixelsPerTimeStep>0?((0,a.setBlinkAnimation)(this.overlayG,!0),this.signaturesBlinking=!0):this.config.pixelsPerTimeStep>0&&((0,a.setBlinkAnimation)(this.overlayG,!1),this.signaturesBlinking=!1)}},t.prototype.pixelsToTime=function(t){return this.config.pixelsPerTimeStep<=0?0:this.jianpuModel.measuresInfo.timeToQuarters(t/this.config.pixelsPerTimeStep,0)},t}();e.JianpuSVGRender=l},186:function(t,e,i){var n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuModel=void 0,e.mapMidiToJianpu=u;var r=i(567),a=i(980),s=i(826),o=i(214),h=function(){function t(t,e){this.jianpuInfo=t,this.jianpuBlockMap=new Map,this.lastQ=0,this.update(t,e)}return t.prototype.isLastMeasureAtQ=function(t){return t>=this.lastQ-1e-6},t.prototype.getTotalDuration=function(){return this.lastQ},t.prototype.update=function(t,e){var i=this;this.jianpuInfo=t,t.notes.sort((function(t,e){return t.start-e.start})),this.lastQ=0,t.notes.forEach((function(t){i.lastQ=Math.max(i.lastQ,t.start+t.length)})),this.lastQ+=1e-6,t.tempos=t.tempos&&t.tempos.length?t.tempos:[r.DEFAULT_TEMPO],t.tempos.sort((function(t,e){return t.start-e.start})),t.tempos[0].start>1e-6&&t.tempos.unshift(n(n({},r.DEFAULT_TEMPO),{start:0}));var s=void 0!==e?{start:0,key:e}:n({},r.DEFAULT_KEY_SIGNATURE);t.keySignatures=t.keySignatures&&t.keySignatures.length?t.keySignatures:[s],t.keySignatures.sort((function(t,e){return t.start-e.start})),t.keySignatures[0].start>1e-6&&t.keySignatures.unshift(n(n({},s),{start:0})),t.timeSignatures=t.timeSignatures&&t.timeSignatures.length?t.timeSignatures:[r.DEFAULT_TIME_SIGNATURE],t.timeSignatures.sort((function(t,e){return t.start-e.start})),t.timeSignatures[0].start>1e-6&&t.timeSignatures.unshift(n(n({},r.DEFAULT_TIME_SIGNATURE),{start:0})),this.measuresInfo=new a.MeasuresInfo(t,this.lastQ),this.infoToBlocks()},t.prototype.infoToBlocks=function(){var t=this,e=new Map,i=0;if(this.jianpuInfo.notes.forEach((function(n){var r=n.start,a=t.measuresInfo.measureNumberAtQ(r);if(r>i+1e-6){var o=i,h=r-o,u=t.measuresInfo.measureNumberAtQ(o),l=new s.JianpuBlock(o,h,[],u);e.set(o,l)}var c=t.measuresInfo.keySignatureAtQ(r),d=t.createJianpuNote(n,c),g=e.get(r);g||(g=new s.JianpuBlock(r,0,[],a),e.set(r,g)),g.addNote(d),i=Math.max(i,r+g.length)})),this.lastQ>i+1e-6){var n=i,r=this.lastQ-n;if(r>1e-6){var a=this.measuresInfo.measureNumberAtQ(n),o=new s.JianpuBlock(n,r,[],a);e.set(n,o)}}this.jianpuBlockMap=new Map;var h=Array.from(e.keys()).sort((function(t,e){return t-e})),u=[];h.forEach((function(t){u.push(e.get(t))}));for(var l=new Set;u.length>0;){var c=u.shift();l.has(c.start)&&this.jianpuBlockMap.has(c.start);var d=c.splitToBeat(this.measuresInfo);if(d)c.mergeToMap(this.jianpuBlockMap),l.add(c.start),u.unshift(d);else{var g=c,m=null;do{m=g.splitToStandardSymbol(this.measuresInfo),g.mergeToMap(this.jianpuBlockMap),l.add(g.start),m&&(g=m)}while(m)}}this.jianpuBlockMap.forEach((function(e){e.calculateRenderProperties(t.measuresInfo)}))},t.prototype.createJianpuNote=function(t,e){var i=u(t.pitch,e);return n(n({},t),{jianpuNumber:i.jianpuNumber,octaveDot:i.octaveDot,accidental:i.accidental})},t}();function u(t,e){var i=e%12,n=o.MIDDLE_C_MIDI+i;i>o.MIDDLE_C_MIDI%12&&(n-=12);var r=(t-(n+12*Math.round((t-n)/12))+12)%12,a=o.MAJOR_SCALE_INTERVALS[r],s=0;if(void 0===a){switch(r){case 1:a=o.MAJOR_SCALE_INTERVALS[0],s=1;break;case 3:a=o.MAJOR_SCALE_INTERVALS[4],s=2;break;case 6:a=o.MAJOR_SCALE_INTERVALS[5],s=1;break;case 8:a=o.MAJOR_SCALE_INTERVALS[9],s=2;break;case 10:a=o.MAJOR_SCALE_INTERVALS[11],s=2;break;default:console.warn("Unexpected chromatic interval ".concat(r," in mapMidiToJianpu. Defaulting to sharp of lower valid degree."));var h=(r-1+12)%12,u=(r+1+12)%12,l=o.MAJOR_SCALE_INTERVALS[h],c=o.MAJOR_SCALE_INTERVALS[u];void 0!==l?(a=l,s=1):void 0!==c?(a=c,s=2):(a=1,s=1,console.error("Could not determine Jianpu number components for MIDI ".concat(t,", interval ").concat(r," from tonic in key ").concat(e,".")))}void 0===a&&(console.error("Jianpu number became undefined for MIDI ".concat(t," (interval ").concat(r,", key ").concat(e,") after chromatic processing. This indicates a logic error or misconfigured MAJOR_SCALE_INTERVALS.")),a=1,s=1)}return{jianpuNumber:a,octaveDot:Math.floor((t-n)/12),accidental:s}}e.JianpuModel=h},214:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MIDDLE_C_MIDI=e.MAJOR_SCALE_INTERVALS=e.PITCH_CLASS_NAMES=e.MAX_QUARTER_DIVISION=e.MIN_RESOLUTION=void 0,e.MIN_RESOLUTION=.0625,e.MAX_QUARTER_DIVISION=240,e.PITCH_CLASS_NAMES=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],e.MAJOR_SCALE_INTERVALS={0:1,2:2,4:3,5:4,7:5,9:6,11:7},e.MIDDLE_C_MIDI=60},229:function(t,e,i){var n=this&&this.__createBinding||(Object.create?function(t,e,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(e,i);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,n,r)}:function(t,e,i,n){void 0===n&&(n=i),t[n]=e[i]}),r=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||n(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),r(i(88),e),r(i(186),e),r(i(826),e),r(i(567),e)},388:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.dotPath=e.tiePath=e.augmentationDashPath=e.underlinePath=e.barPath=e.ACCIDENTAL_TEXT=e.ACCIDENTAL_PATHS=e.PATH_SCALE=void 0,e.PATH_SCALE=100,e.ACCIDENTAL_PATHS=[null,"m 30,15 h 40 m -35,20 h 40 M 50,0 v 50 M 70,5 v 50","m 45,5 v 40 c 0,15 20,15 20,0 V 20 C 65,5 45,5 45,5 Z","M 45,5 v 45 M 65,0 v 45 H 45 m 20,10 H 45"],e.ACCIDENTAL_TEXT=["","#","b"],e.barPath="m 0,-50 v 100",e.underlinePath="m 0,0 h 100",e.augmentationDashPath="m 0,0 h 50",e.tiePath="M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z",e.dotPath="M 0 0 a 15 15 0 1 0 0.0001 0 z"},567:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_TIME_SIGNATURE=e.DEFAULT_KEY_SIGNATURE=e.DEFAULT_TEMPO=void 0,e.getMeasureLength=function(t){return t.numerator*(4/t.denominator)},e.DEFAULT_TEMPO={start:0,qpm:60},e.DEFAULT_KEY_SIGNATURE={start:0,key:0},e.DEFAULT_TIME_SIGNATURE={start:0,numerator:4,denominator:4}},811:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SVGNS=void 0,e.drawSVGPath=function(t,i,n,r,a,s,o){void 0===o&&(o=1);var h=document.createElementNS(e.SVGNS,"path");return h.setAttributeNS(null,"d",i),h.setAttributeNS(null,"transform","translate(".concat(n,", ").concat(r,") scale(").concat(a,", ").concat(s,")")),o<1&&h.setAttributeNS(null,"opacity","".concat(o)),t.appendChild(h),h},e.drawSVGText=function(t,i,n,r,a,s,o,h,u,l){void 0===s&&(s="normal"),void 0===o&&(o="middle"),void 0===h&&(h="middle"),void 0===u&&(u="currentColor"),void 0===l&&(l=1);var c=document.createElementNS(e.SVGNS,"text");c.setAttributeNS(null,"font-family","sans-serif"),c.setAttributeNS(null,"font-size",a),c.setAttributeNS(null,"font-weight",s),c.setAttributeNS(null,"x","".concat(n)),c.setAttributeNS(null,"y","".concat(r)),c.setAttributeNS(null,"text-anchor",o),c.setAttributeNS(null,"dominant-baseline",h),"currentColor"!==u&&c.setAttributeNS(null,"fill",u),l<1&&c.setAttributeNS(null,"opacity","".concat(l));var d=document.createTextNode(i);return c.appendChild(d),t.appendChild(c),c},e.createSVGGroupChild=function(t,i){var n=document.createElementNS(e.SVGNS,"g");return i&&n.setAttribute("data-id",i),t.appendChild(n),n},e.setBlinkAnimation=function(t,i,n){void 0===i&&(i=!0),void 0===n&&(n="1s");var r=t.querySelector('animate[attributeName="opacity"]');return i?r?(r.setAttributeNS(null,"repeatCount","indefinite"),r.beginElement()):((r=document.createElementNS(e.SVGNS,"animate")).setAttributeNS(null,"attributeName","opacity"),r.setAttributeNS(null,"values","1;0.2;1"),r.setAttributeNS(null,"keyTimes","0;0.5;1"),r.setAttributeNS(null,"dur",n),r.setAttributeNS(null,"repeatCount","indefinite"),t.appendChild(r)):(r&&(r.endElement(),r.setAttributeNS(null,"repeatCount","0"),t.style.opacity="1"),t.style.opacity="1"),t},e.setFill=function(t,e){t.setAttributeNS(null,"fill",e)},e.setStroke=function(t,e,i){t.setAttributeNS(null,"stroke",e),t.setAttributeNS(null,"stroke-width","".concat(i))},e.highlightElement=function(t,e){var i=[];return t.matches("text, path")&&i.push(t),t.querySelectorAll("text, path").forEach((function(t){i.push(t)})),i.forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)})),t},e.resetElementHighlight=function(t,e){t.querySelectorAll("text, path").forEach((function(t){"none"!==t.getAttribute("fill")&&t.setAttribute("fill",e)}))},e.SVGNS="http://www.w3.org/2000/svg"},826:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.JianpuBlock=void 0,e.splitJianpuNote=a;var n=i(214);function r(t){return Math.abs(t)<1e-6}function a(t,e){var i=t.start+t.length;if(e<=t.start||e>=i||r(i-e))return null;var n=i-e;t.length=e-t.start;var a={start:e,length:n,pitch:t.pitch,intensity:t.intensity,jianpuNumber:t.jianpuNumber,octaveDot:t.octaveDot,accidental:0,tiedFrom:t};return t.tiedTo&&(a.tiedTo=t.tiedTo,t.tiedTo.tiedFrom=a),t.tiedTo=a,a}var s=function(){function t(t,e,i,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=[]),void 0===n&&(n=1),this.start=t,this.length=e,this.notes=i,this.measureNumber=n}return t.prototype.addNote=function(t){if(0===this.notes.length)return this.start=t.start,this.length=t.length,this.notes.push(t),!0;if(!r(this.start-t.start))return console.warn("JianpuBlock: Attempted to add note at ".concat(t.start," to block starting at ").concat(this.start,". Ignoring.")),!1;for(var e=!1,i=!1,n=0;n<this.notes.length;n++)if(this.notes[n].pitch===t.pitch){i=!0,t.length<this.notes[n].length&&(this.notes[n].tiedFrom&&(t.tiedFrom=this.notes[n].tiedFrom,t.tiedFrom&&(t.tiedFrom.tiedTo=t)),this.notes[n].tiedTo&&(t.tiedTo=this.notes[n].tiedTo,t.tiedTo&&(t.tiedTo.tiedFrom=t)),this.notes[n]=t,e=!0);break}i||this.notes.push(t);for(var a=1/0,s=0,o=this.notes;s<o.length;s++){var h=o[s];a=Math.min(a,h.length)}return this.length=a,!i||e},t.prototype.split=function(e,i){var n=this.start+this.length;if(e<=this.start||e>=n||r(n-e))return null;for(var s=n-e,o=e-this.start,h=new t(e,s,[],i.measureNumberAtQ(e)),u=[],l=0,c=this.notes;l<c.length;l++){var d=c[l],g=d.start+d.length;if(g>e+1e-6){var m=a(d,e);m?u.push(m):console.warn("Split failed for note, unexpected state.")}else r(g-e)}return u.forEach((function(t){return h.addNote(t)})),this.length=o,delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash,this.beatEnd&&(h.beatEnd=!0,delete this.beatEnd),this.isTieEnd&&(h.isTieStart=!0,delete this.isTieEnd),h},t.prototype.splitToBeat=function(t){var e=t.timeSignatureAtQ(this.start);if(!e)return null;var i=t.measureLengthAtQ(this.start),n=t.measureNumberAtQ(this.start),a=this.start-(n-Math.floor(n))*i,s=this.start-a,o=4/e.denominator,h=s/o;this.beatBegin=r(h-Math.round(h));var u=a+(Math.floor(h+1e-6)+1)*o,l=a+i,c=this.start+this.length,d=null;u<c-1e-6&&u>this.start+1e-6&&(d=u),l<c-1e-6&&l>this.start+1e-6&&(null===d||l<d)&&(d=l);var g=null;if(null!==d)(g=this.split(d,t))&&(this.beatEnd=!0);else{var m=(s+this.length)/o;this.beatEnd=r(m-Math.round(m)),this.beatEnd||(this.beatEnd=r(c-l))}return this.isTieStart=this.notes.some((function(t){return t.tiedFrom})),this.isTieEnd=this.notes.some((function(t){return t.tiedTo})),g&&(g.isTieStart=g.notes.some((function(t){return t.tiedFrom})),g.isTieEnd=g.notes.some((function(t){return t.tiedTo})),this.notes.some((function(t){return t.tiedTo&&t.start+t.length>d}))&&delete this.isTieEnd),g},t.prototype.calculateRenderProperties=function(t){delete this.durationLines,delete this.augmentationDots,delete this.augmentationDash;var e=this.length;if(!(r(e)||e<0)){if(t.allowDottedRests||this.notes.length>0){if(r(e-1.5))return void(this.augmentationDots=1);if(r(e-.75))return this.durationLines=1,void(this.augmentationDots=1);if(r(e-.375))return this.durationLines=2,void(this.augmentationDots=1);r(e-3)&&(this.augmentationDots=1)}if(this.durationLines=e>=3.999999||e>=1.999999||e>=.999999?0:e>=.499999?1:e>=.249999?2:e>=.124999?3:4,this.augmentationDash=!1,1===this.notes.length){var i=this.notes[0],n=t.timeSignatureAtQ(this.start);if(!n)return;var a=Math.max(4/n.denominator,1);if(!(this.measureNumber%1<=1e-6)&&i.tiedFrom&&r(i.tiedFrom.length-a)&&i.tiedFrom.pitch===i.pitch&&i.length>=1){var s=!0;if(i.tiedTo){var o=i.start+i.length;s=Math.floor(t.measureNumberAtQ(this.start))===Math.floor(t.measureNumberAtQ(o))&&i.tiedTo.length>=1}s&&(this.augmentationDash=!0)}}}},t.prototype.splitToStandardSymbol=function(t){var e=this.length;if(r(e)||e<n.MIN_RESOLUTION-1e-6)return null;var i=[];t.allowDottedRests||this.notes.length>0?(i.push(6),i.push(4),i.push(3),i.push(2),i.push(1.5),i.push(1),i.push(.75),i.push(.5),i.push(.375),i.push(.25),i.push(.125),i.push(.0625)):(i.push(4),i.push(2),i.push(1),i.push(.5),i.push(.25),i.push(.125),i.push(.0625));for(var a=0,s=0,o=i;s<o.length;s++){var h=o[s];if(e>=h-1e-6){a=h;break}}r(a)&&e<(a=n.MIN_RESOLUTION)-1e-6&&e>1e-6&&console.warn("Block length ".concat(e," is too small, rendering as ").concat(a));var u=null;return e>a+1e-6?(u=this.split(this.start+a,t),this.length!==a&&(console.warn("Adjusting block length after split from ".concat(this.length," to ").concat(a)),this.length=a)):this.length=a,u},t.prototype.mergeToMap=function(t){var e=t.get(this.start);e?(this.notes.forEach((function(t){return e.addNote(t)})),0!==this.measureNumber&&(e.measureNumber=this.measureNumber)):t.set(this.start,this)},t.prototype.isMeasureBeginning=function(){return r(this.measureNumber-Math.floor(this.measureNumber))},t}();e.JianpuBlock=s},980:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MeasuresInfo=void 0;var n=i(567),r=i(214),a=function(){function t(t,e){this.allowDottedRests=!0,this.measuresInfo=[];for(var i=0,a=0,s=0,o=t.tempos[0],h=t.keySignatures[0],u=t.timeSignatures[0],l=1,c=(0,n.getMeasureLength)(u),d=u.start,g=r.MIN_RESOLUTION,m=0;m<e;m+=g){var f={start:m,measureNumber:l+(m-d)/c,measureLength:c,tempo:o,keySignature:h,timeSignature:u};i<t.tempos.length&&Math.abs(t.tempos[i].start-m)<g/2&&(o=t.tempos[i++],f.tempo=o,f.tempoChange=!0),a<t.keySignatures.length&&Math.abs(t.keySignatures[a].start-m)<g/2&&(h=t.keySignatures[a++],f.keySignature=h,f.keyChange=!0),s<t.timeSignatures.length&&Math.abs(t.timeSignatures[s].start-m)<g/2&&(l+=(t.timeSignatures[s].start-d)/c,l=Math.round(1e3*l)/1e3,u=t.timeSignatures[s++],f.timeSignature=u,c=(0,n.getMeasureLength)(u),f.measureLength=c,f.measureNumber=l,f.timeChange=!0,d=f.start),this.measuresInfo.push(f)}}return t.prototype.findIndex=function(t){return Math.max(0,Math.min(this.measuresInfo.length-1,Math.floor(t/r.MIN_RESOLUTION)))},t.prototype.measureNumberAtQ=function(t){if(0===this.measuresInfo.length)return 1;var e=this.findIndex(t),i=this.measuresInfo[e],n=(t-i.start)/i.measureLength;return i.measureNumber+n+1e-9},t.prototype.measureLengthAtQ=function(t){if(0===this.measuresInfo.length)return(0,n.getMeasureLength)(n.DEFAULT_TIME_SIGNATURE);var e=this.findIndex(t);return this.measuresInfo[e].measureLength},t.prototype.tempoAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TEMPO.qpm;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.tempoChange&&s?a.tempo.qpm:-1},t.prototype.keySignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_KEY_SIGNATURE.key;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.keyChange&&s?a.keySignature.key:-1},t.prototype.timeSignatureAtQ=function(t,e){if(void 0===e&&(e=!1),0===this.measuresInfo.length)return n.DEFAULT_TIME_SIGNATURE;var i=this.findIndex(t),a=this.measuresInfo[i],s=Math.abs(a.start-t)<r.MIN_RESOLUTION/2;return!e||a.timeChange&&s?a.timeSignature:null},t.prototype.quartersToTime=function(t,e){var i=this.tempoAtQ(e);return i<=0?0:t/i*60},t.prototype.timeToQuarters=function(t,e){var i=this.tempoAtQ(e);if(i<=0)return 0;var n=t*i/60;return Math.round(n*r.MAX_QUARTER_DIVISION)/r.MAX_QUARTER_DIVISION},t.prototype.isBeatStart=function(t){if(0===this.measuresInfo.length)return!1;var e=this.findIndex(t),i=this.measuresInfo[e],n=i.timeSignature,a=(t-(i.start-(i.measureNumber-Math.floor(i.measureNumber))*i.measureLength))/(4/n.denominator);return Math.abs(a-Math.round(a))<r.MIN_RESOLUTION/2},t}();e.MeasuresInfo=a}},i={};t=function t(n){var r=i[n];if(void 0!==r)return r.exports;var a=i[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}(229),window.jr=t})();
package/es5/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './jianpu_svg_render';
2
+ export * from './jianpu_model';
3
+ export * from './jianpu_block';
4
+ export * from './jianpu_info';
@@ -0,0 +1,32 @@
1
+ import { NoteInfo } from './jianpu_info';
2
+ import { MeasuresInfo } from './measure_info';
3
+ export type JianpuBlockMap = Map<number, JianpuBlock>;
4
+ export interface JianpuNote extends NoteInfo {
5
+ jianpuNumber: number;
6
+ octaveDot: number;
7
+ accidental: number;
8
+ tiedFrom?: JianpuNote;
9
+ tiedTo?: JianpuNote;
10
+ }
11
+ export declare function splitJianpuNote(jianpuNote: JianpuNote, quarters: number): JianpuNote | null;
12
+ export declare class JianpuBlock {
13
+ start: number;
14
+ length: number;
15
+ notes: JianpuNote[];
16
+ measureNumber: number;
17
+ durationLines?: number;
18
+ augmentationDots?: number;
19
+ augmentationDash?: boolean;
20
+ beatBegin?: boolean;
21
+ beatEnd?: boolean;
22
+ isTieStart?: boolean;
23
+ isTieEnd?: boolean;
24
+ constructor(start?: number, length?: number, notes?: JianpuNote[], measureNumber?: number);
25
+ addNote(jianpuNote: JianpuNote): boolean;
26
+ split(quarters: number, measuresInfo: MeasuresInfo): JianpuBlock | null;
27
+ splitToBeat(measuresInfo: MeasuresInfo): JianpuBlock | null;
28
+ calculateRenderProperties(measuresInfo: MeasuresInfo): void;
29
+ splitToStandardSymbol(measuresInfo: MeasuresInfo): JianpuBlock | null;
30
+ mergeToMap(map: JianpuBlockMap): void;
31
+ isMeasureBeginning(): boolean;
32
+ }
@@ -0,0 +1,29 @@
1
+ export interface NoteInfo {
2
+ start: number;
3
+ length: number;
4
+ pitch: number;
5
+ intensity: number;
6
+ }
7
+ export interface TempoInfo {
8
+ start: number;
9
+ qpm: number;
10
+ }
11
+ export interface KeySignatureInfo {
12
+ start: number;
13
+ key: number;
14
+ }
15
+ export interface TimeSignatureInfo {
16
+ start: number;
17
+ numerator: number;
18
+ denominator: number;
19
+ }
20
+ export interface JianpuInfo {
21
+ notes: NoteInfo[];
22
+ tempos?: TempoInfo[];
23
+ keySignatures?: KeySignatureInfo[];
24
+ timeSignatures?: TimeSignatureInfo[];
25
+ }
26
+ export declare const DEFAULT_TEMPO: TempoInfo;
27
+ export declare const DEFAULT_KEY_SIGNATURE: KeySignatureInfo;
28
+ export declare const DEFAULT_TIME_SIGNATURE: TimeSignatureInfo;
29
+ export declare function getMeasureLength(timeSignature: TimeSignatureInfo): number;
@@ -0,0 +1,20 @@
1
+ import { JianpuInfo } from './jianpu_info';
2
+ import { MeasuresInfo } from './measure_info';
3
+ import { JianpuBlockMap } from './jianpu_block';
4
+ export declare class JianpuModel {
5
+ jianpuInfo: JianpuInfo;
6
+ measuresInfo: MeasuresInfo;
7
+ jianpuBlockMap: JianpuBlockMap;
8
+ private lastQ;
9
+ constructor(jianpuInfo: JianpuInfo, defaultKey?: number);
10
+ isLastMeasureAtQ(q: number): boolean;
11
+ getTotalDuration(): number;
12
+ update(jianpuInfo: JianpuInfo, defaultKey?: number): void;
13
+ private infoToBlocks;
14
+ private createJianpuNote;
15
+ }
16
+ export declare function mapMidiToJianpu(midiPitch: number, key: number): {
17
+ jianpuNumber: number;
18
+ octaveDot: number;
19
+ accidental: number;
20
+ };
@@ -0,0 +1,59 @@
1
+ import { JianpuInfo, NoteInfo } from './jianpu_info';
2
+ import { JianpuModel } from './jianpu_model';
3
+ export declare enum ScrollType {
4
+ PAGE = 0,
5
+ NOTE = 1,
6
+ BAR = 2
7
+ }
8
+ export interface JianpuSVGRenderConfig {
9
+ noteHeight?: number;
10
+ noteSpacingFactor?: number;
11
+ pixelsPerTimeStep?: number;
12
+ noteColor?: string;
13
+ activeNoteColor?: string;
14
+ defaultKey?: number;
15
+ scrollType?: ScrollType;
16
+ fontFamily?: string;
17
+ width?: number;
18
+ height?: number;
19
+ }
20
+ export declare class JianpuSVGRender {
21
+ jianpuInfo: JianpuInfo;
22
+ jianpuModel: JianpuModel;
23
+ private config;
24
+ private height;
25
+ private width;
26
+ private parentElement;
27
+ private div;
28
+ private mainSVG;
29
+ private mainG;
30
+ private musicG;
31
+ private signaturesG;
32
+ private overlaySVG;
33
+ private overlayG;
34
+ private signaturesBlinking;
35
+ private lastKnownScrollLeft;
36
+ private isScrolling;
37
+ private currentKey;
38
+ private currentTimeSignature;
39
+ private playingNotes;
40
+ private lastRenderedQ;
41
+ private estimatedNoteWidth;
42
+ private numberFontSize;
43
+ private smallFontSize;
44
+ private yBaseline;
45
+ constructor(score: JianpuInfo, config: JianpuSVGRenderConfig, div: HTMLDivElement);
46
+ clear(): void;
47
+ private updateLayout;
48
+ redraw(activeNote?: NoteInfo, scrollIntoView?: boolean): number;
49
+ private drawJianpuBlock;
50
+ private drawNotes;
51
+ private drawRest;
52
+ private drawSignatures;
53
+ private updateCurrentKey;
54
+ private updateCurrentTimeSignature;
55
+ private handleScrollEvent;
56
+ private scrollIntoViewIfNeeded;
57
+ private updateOverlaySignaturesForScroll;
58
+ private pixelsToTime;
59
+ }
package/es5/lib.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { JianpuInfo, TempoInfo, TimeSignatureInfo, KeySignatureInfo } from './jianpu_info';
2
+ export interface MeasureInfo {
3
+ start: number;
4
+ measureNumber: number;
5
+ measureLength: number;
6
+ tempo: TempoInfo;
7
+ keySignature: KeySignatureInfo;
8
+ timeSignature: TimeSignatureInfo;
9
+ tempoChange?: boolean;
10
+ keyChange?: boolean;
11
+ timeChange?: boolean;
12
+ }
13
+ export declare class MeasuresInfo {
14
+ private measuresInfo;
15
+ allowDottedRests?: boolean;
16
+ constructor(jianpuInfo: JianpuInfo, lastQ: number);
17
+ private findIndex;
18
+ measureNumberAtQ(start: number): number;
19
+ measureLengthAtQ(start: number): number;
20
+ tempoAtQ(start: number, onlyChanges?: boolean): number;
21
+ keySignatureAtQ(start: number, onlyChanges?: boolean): number;
22
+ timeSignatureAtQ(start: number, onlyChanges?: boolean): TimeSignatureInfo | null;
23
+ quartersToTime(quarters: number, startTime: number): number;
24
+ timeToQuarters(time: number, startTime: number): number;
25
+ isBeatStart(time: number): boolean;
26
+ }
@@ -0,0 +1,7 @@
1
+ export declare const MIN_RESOLUTION = 0.0625;
2
+ export declare const MAX_QUARTER_DIVISION: number;
3
+ export declare const PITCH_CLASS_NAMES: string[];
4
+ export declare const MAJOR_SCALE_INTERVALS: {
5
+ [interval: number]: number;
6
+ };
7
+ export declare const MIDDLE_C_MIDI = 60;
@@ -0,0 +1,11 @@
1
+ export declare const LINE_STROKE_WIDTH = 1;
2
+ export declare const COMPACT_SPACING_FACTOR = 1.5;
3
+ export declare const UNDERLINE_SPACING_FACTOR = 0.2;
4
+ export declare const OCTAVE_DOT_OFFSET_FACTOR = 1;
5
+ export declare const DOT_SIZE_FACTOR = 0.1;
6
+ export declare const AUGMENTATION_DASH_FACTOR = 0.8;
7
+ export declare const ACCIDENTAL_SPACING_FACTOR = 0.1;
8
+ export declare const AUGMENTATION_SPACING_FACTOR = 0.2;
9
+ export declare const FONT_SIZE_MULTIPLIER = 1.2;
10
+ export declare const SMALL_FONT_SIZE_MULTIPLIER = 0.75;
11
+ export declare const DURATION_LINE_SCALES: Map<number, number>;
@@ -0,0 +1,8 @@
1
+ export declare const PATH_SCALE = 100;
2
+ export declare const ACCIDENTAL_PATHS: string[];
3
+ export declare const ACCIDENTAL_TEXT: string[];
4
+ export declare const barPath = "m 0,-50 v 100";
5
+ export declare const underlinePath = "m 0,0 h 100";
6
+ export declare const augmentationDashPath = "m 0,0 h 50";
7
+ export declare const tiePath = "M -13,5 C 15,-15 65,-15 90,5 C 65,-25 15,-25 -13,5 Z";
8
+ export declare const dotPath = "M 0 0 a 15 15 0 1 0 0.0001 0 z";
@@ -0,0 +1,9 @@
1
+ export declare const SVGNS = "http://www.w3.org/2000/svg";
2
+ export declare function drawSVGPath(e: SVGElement, path: string, x: number, y: number, scaleX: number, scaleY: number, opacity?: number): SVGPathElement;
3
+ export declare function drawSVGText(e: SVGElement, text: string, x: number, y: number, fontSize: string, fontWeight?: string, textAnchor?: 'start' | 'middle' | 'end', dominantBaseline?: string, fill?: string, opacity?: number): SVGTextElement;
4
+ export declare function createSVGGroupChild(parent: SVGElement, id?: string): SVGGElement;
5
+ export declare function setBlinkAnimation(e: SVGElement, enable?: boolean, duration?: string): SVGElement;
6
+ export declare function setFill(e: SVGElement, color: string): void;
7
+ export declare function setStroke(e: SVGElement, color: string, strokeWidth: number): void;
8
+ export declare function highlightElement(e: SVGElement, color: string): SVGElement;
9
+ export declare function resetElementHighlight(e: SVGElement, defaultColor: string): void;
package/es6/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './jianpu_svg_render';
2
+ export * from './jianpu_model';
3
+ export * from './jianpu_block';
4
+ export * from './jianpu_info';