├── .gitignore ├── LICENSE ├── README.md ├── docs ├── CNAME ├── _config.yml ├── _layouts │ └── default.html ├── editor │ ├── asset-manifest.json │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ ├── robots.txt │ └── static │ │ ├── css │ │ ├── 2.786ae0dd.chunk.css │ │ ├── 2.786ae0dd.chunk.css.map │ │ ├── main.886a1ecf.chunk.css │ │ └── main.886a1ecf.chunk.css.map │ │ └── js │ │ ├── 2.6118e75e.chunk.js │ │ ├── 2.6118e75e.chunk.js.LICENSE.txt │ │ ├── 2.6118e75e.chunk.js.map │ │ ├── 3.c09cd1f8.chunk.js │ │ ├── 3.c09cd1f8.chunk.js.map │ │ ├── 4.96e8a086.chunk.js │ │ ├── 4.96e8a086.chunk.js.map │ │ ├── main.afb59669.chunk.js │ │ ├── main.afb59669.chunk.js.map │ │ ├── runtime-main.74a6070c.js │ │ └── runtime-main.74a6070c.js.map ├── index.md └── screenshot.png ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.css ├── App.js ├── App.test.js ├── component ├── EditableContent │ ├── index.js │ └── index.module.css └── PopoverOnSvg │ ├── container.js │ ├── index.js │ └── index.module.css ├── example └── 烟雨.json ├── index.css ├── index.js ├── logo.svg ├── menu ├── editor.js ├── notation.js └── paragraph.js ├── reportWebVitals.js ├── setupTests.js ├── store ├── global.js ├── history.js └── state.js ├── util ├── dom-to-image.js ├── editor.js ├── file.js ├── html-escape.js ├── load-example.js ├── notation.js ├── paragraph.js ├── placement.js ├── tone-convert.js └── version.js └── view ├── Canvas ├── index.js └── index.module.css ├── ConfigModal └── index.js ├── Editor ├── index.js └── index.module.css ├── Header ├── LeftInfoBlock │ └── index.js ├── RightInfoBlock │ ├── index.js │ └── index.module.css ├── Title │ └── index.js └── index.js ├── HelpModal ├── index.js └── index.module.css ├── Notation ├── index.js └── index.module.css ├── Paragraph └── index.js ├── Row └── index.js └── Text └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright © 2007 Free Software Foundation, Inc. 5 | 6 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 11 | 12 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 13 | 14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 15 | 16 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 17 | 18 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 19 | 20 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 21 | 22 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 23 | 24 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 25 | 26 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 27 | 28 | The precise terms and conditions for copying, distribution and modification follow. 29 | 30 | TERMS AND CONDITIONS 31 | 32 | 0. Definitions. 33 | 34 | “This License” refers to version 3 of the GNU General Public License. 35 | 36 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 37 | 38 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 39 | 40 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 41 | 42 | A “covered work” means either the unmodified Program or a work based on the Program. 43 | 44 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 45 | 46 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 47 | 48 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 49 | 50 | 1. Source Code. 51 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 52 | 53 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 54 | 55 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 56 | 57 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 58 | 59 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 60 | 61 | The Corresponding Source for a work in source code form is that same work. 62 | 63 | 2. Basic Permissions. 64 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 65 | 66 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 67 | 68 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 69 | 70 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 71 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 72 | 73 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 74 | 75 | 4. Conveying Verbatim Copies. 76 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 77 | 78 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 79 | 80 | 5. Conveying Modified Source Versions. 81 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 82 | 83 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 84 | 85 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 86 | 87 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 88 | 89 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 90 | 91 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 92 | 93 | 6. Conveying Non-Source Forms. 94 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 95 | 96 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 97 | 98 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 99 | 100 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 101 | 102 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 103 | 104 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 105 | 106 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 107 | 108 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 109 | 110 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 111 | 112 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 113 | 114 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 115 | 116 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 117 | 118 | 7. Additional Terms. 119 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 120 | 121 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 122 | 123 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 124 | 125 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 126 | 127 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 128 | 129 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 130 | 131 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 132 | 133 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 134 | 135 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 136 | 137 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 138 | 139 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 140 | 141 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 142 | 143 | 8. Termination. 144 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 145 | 146 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 147 | 148 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 149 | 150 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 151 | 152 | 9. Acceptance Not Required for Having Copies. 153 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 154 | 155 | 10. Automatic Licensing of Downstream Recipients. 156 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 157 | 158 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 159 | 160 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 161 | 162 | 11. Patents. 163 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. 164 | 165 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 166 | 167 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 168 | 169 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 170 | 171 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 172 | 173 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 174 | 175 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 176 | 177 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 178 | 179 | 12. No Surrender of Others' Freedom. 180 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 181 | 182 | 13. Use with the GNU Affero General Public License. 183 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 184 | 185 | 14. Revised Versions of this License. 186 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 187 | 188 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 189 | 190 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 191 | 192 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 193 | 194 | 15. Disclaimer of Warranty. 195 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 196 | 197 | 16. Limitation of Liability. 198 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 199 | 200 | 17. Interpretation of Sections 15 and 16. 201 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 202 | 203 | END OF TERMS AND CONDITIONS 204 | 205 | How to Apply These Terms to Your New Programs 206 | 207 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 208 | 209 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. 210 | 211 | 212 | Copyright (C) 213 | 214 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 215 | 216 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 217 | 218 | You should have received a copy of the GNU General Public License along with this program. If not, see . 219 | 220 | Also add information on how to contact you by electronic and paper mail. 221 | 222 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 223 | 224 | Copyright (C) 225 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 226 | This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. 227 | 228 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. 229 | 230 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . 231 | 232 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . 233 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Web简谱编辑器 2 | 一个Web版简谱编辑器,支持一键转调和图片导出。 3 | 4 | ## 在线Demo 5 | [示例曲子:烟雨](https://mattuylee.github.io/numerical-notation-editor/editor/?loadExample) 6 | 7 | ## 功能 8 | * 所见即所得,支持常见简谱元素 9 | * 全键盘输入音符,高效快速 10 | * 一键转调,避免出错 11 | * 高清图片导出 12 | 13 | ## 使用 14 | 暂时未兼容移动端,要使用此程序的完整功能,必须连接键盘。详情的使用介绍请见[Wiki](https://github.com/mattuylee/numerical-notation-editor/wiki/%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)。 15 | 16 | ## RoadMap 17 | - [x] 转调 18 | - [ ] 歌词 19 | - [ ] 分节符 20 | - [ ] 滑音符号 21 | - [ ] 伴奏 22 | - [ ] 自动保存 23 | - [ ] PWA 24 | 25 | 不会支持的特性: 26 | - 五线谱 27 | 28 | 已经存在很多专业还免费的五线谱编辑器,请移步[MuseScore](https://musescore.org)。 29 | 30 | ## 构建 31 | ```shell 32 | git clone https://github.com/mattuylee/numerical-notation-editor 33 | cd numerical-notation-editor && npm install 34 | # 运行 35 | npm run start 36 | # 编译 37 | npm run build 38 | ``` 39 | 要部署Github Page,执行`npm run publish`,将会编译并复制到`docs/`。 40 | 41 | ## Q&A 42 | [Wiki](https://github.com/mattuylee/numerical-notation-editor/wiki) 43 | 44 | ## 贡献 45 | 欢迎提交[issue](https://github.com/mattuylee/numerical-notation-editor/issues/new)或PR。 46 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | note-editor.mattuy.top -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | -------------------------------------------------------------------------------- /docs/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {% seo %} 8 | 9 | 11 | 12 | 13 | 14 | 15 | {% include head-custom.html %} 16 | 17 | 18 | 19 | Skip to the content. 20 | 21 | 29 | 30 |
31 | {{ content }} 32 | 33 | 41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /docs/editor/asset-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": { 3 | "main.css": "./static/css/main.886a1ecf.chunk.css", 4 | "main.js": "./static/js/main.afb59669.chunk.js", 5 | "main.js.map": "./static/js/main.afb59669.chunk.js.map", 6 | "runtime-main.js": "./static/js/runtime-main.74a6070c.js", 7 | "runtime-main.js.map": "./static/js/runtime-main.74a6070c.js.map", 8 | "static/css/2.786ae0dd.chunk.css": "./static/css/2.786ae0dd.chunk.css", 9 | "static/js/2.6118e75e.chunk.js": "./static/js/2.6118e75e.chunk.js", 10 | "static/js/2.6118e75e.chunk.js.map": "./static/js/2.6118e75e.chunk.js.map", 11 | "static/js/3.c09cd1f8.chunk.js": "./static/js/3.c09cd1f8.chunk.js", 12 | "static/js/3.c09cd1f8.chunk.js.map": "./static/js/3.c09cd1f8.chunk.js.map", 13 | "static/js/4.96e8a086.chunk.js": "./static/js/4.96e8a086.chunk.js", 14 | "static/js/4.96e8a086.chunk.js.map": "./static/js/4.96e8a086.chunk.js.map", 15 | "index.html": "./index.html", 16 | "static/css/2.786ae0dd.chunk.css.map": "./static/css/2.786ae0dd.chunk.css.map", 17 | "static/css/main.886a1ecf.chunk.css.map": "./static/css/main.886a1ecf.chunk.css.map", 18 | "static/js/2.6118e75e.chunk.js.LICENSE.txt": "./static/js/2.6118e75e.chunk.js.LICENSE.txt" 19 | }, 20 | "entrypoints": [ 21 | "static/js/runtime-main.74a6070c.js", 22 | "static/css/2.786ae0dd.chunk.css", 23 | "static/js/2.6118e75e.chunk.js", 24 | "static/css/main.886a1ecf.chunk.css", 25 | "static/js/main.afb59669.chunk.js" 26 | ] 27 | } -------------------------------------------------------------------------------- /docs/editor/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattuylee/numerical-notation-editor/1b80f8903ec9f3bdd62df04ef69c8288b5c3b287/docs/editor/favicon.ico -------------------------------------------------------------------------------- /docs/editor/index.html: -------------------------------------------------------------------------------- 1 | 简单简谱编辑器
-------------------------------------------------------------------------------- /docs/editor/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattuylee/numerical-notation-editor/1b80f8903ec9f3bdd62df04ef69c8288b5c3b287/docs/editor/logo192.png -------------------------------------------------------------------------------- /docs/editor/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattuylee/numerical-notation-editor/1b80f8903ec9f3bdd62df04ef69c8288b5c3b287/docs/editor/logo512.png -------------------------------------------------------------------------------- /docs/editor/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /docs/editor/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /docs/editor/static/css/main.886a1ecf.chunk.css: -------------------------------------------------------------------------------- 1 | .Canvas_svg__2w1z4{border:1px solid #f8f8ff;box-shadow:0 0 10px #f8f8ff;font-size:16px}.Canvas_svg__2w1z4 text{-webkit-user-select:none;-ms-user-select:none;user-select:none}.PopoverOnSvg_popover__3bN4H{position:absolute;border-radius:4px;box-shadow:0 1px 8px rgba(0,0,0,.15);background-color:#fff;min-width:32px}.dark.PopoverOnSvg_popover__3bN4H{background-color:#000;color:#fff}.PopoverOnSvg_arrow__22-aj{display:block;position:absolute;z-index:-1;border:8px solid #fff;background-color:#fff;width:8px;height:8px}.dark.PopoverOnSvg_arrow__22-aj{border-color:#000;background-color:#000}.left.PopoverOnSvg_arrow__22-aj{right:-12px;-webkit-transform:translate(-50%,-50%) rotate(135deg);transform:translate(-50%,-50%) rotate(135deg);box-shadow:-2px -2px 6px -2px rgba(0,0,0,.06)}.right.PopoverOnSvg_arrow__22-aj{left:4px;-webkit-transform:translate(-50%,-50%) rotate(-45deg);transform:translate(-50%,-50%) rotate(-45deg);box-shadow:-2px -2px 6px -2px rgba(0,0,0,.06)}.top.PopoverOnSvg_arrow__22-aj{bottom:-12px;box-shadow:3px 3px 7px -2px rgba(0,0,0,.07)}.bottom.PopoverOnSvg_arrow__22-aj,.top.PopoverOnSvg_arrow__22-aj{-webkit-transform:translate(-50%,-50%) rotate(45deg);transform:translate(-50%,-50%) rotate(45deg)}.bottom.PopoverOnSvg_arrow__22-aj{top:4px;box-shadow:-3px -3px 8px -2px rgba(0,0,0,.07)}.PopoverOnSvg_content__1rAgR{padding:4px 8px}.PopoverOnSvg_header__URzxW{border-bottom:1px solid rgba(0,0,0,.08);padding:4px 8px;line-height:22px}.dark.PopoverOnSvg_header__URzxW{border-bottom:1px solid hsla(0,0%,100%,.35)}.EditableContent_buttonGroup__2qXGn{margin:8px 0 4px;width:300px;max-width:100%;text-align:right}.EditableContent_button__6qyvP{margin-right:8px}.EditableContent_menu__2ah_9{max-height:320px;overflow:auto}.EditableContent_menuItem__3P1Eu:hover{background-color:#f5f5f5;color:#000!important;-webkit-user-select:none;-ms-user-select:none;user-select:none}.selected.EditableContent_menuItem__3P1Eu{background-color:#f5f5f5}.HelpModal_list__syZn2{padding:0;list-style:none}.HelpModal_listItem__34m_q{display:inline-block;margin-top:8px;margin-right:16px;min-width:260px}.HelpModal_kbd__RCRud{display:inline-block;margin-right:8px;border-radius:4px;background-color:#d3d3d3;padding:4px;width:120px;text-align:center}.Notation_selectedNotation__3wsjJ{color:coral}.Editor_headerWrapper__2rEBR{margin-bottom:16px;border-bottom:1px solid #f5f5f5;width:100%}.Editor_header__2Qcr4{margin:auto;padding:8px 0}.Editor_container__3rhfS{display:flex;flex-direction:column;align-items:center;justify-content:center;background-color:#fff;min-width:100%;height:100%}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}code{font-family:source-code-pro,Menlo,Monaco,Consolas,"Courier New",monospace} 2 | /*# sourceMappingURL=main.886a1ecf.chunk.css.map */ -------------------------------------------------------------------------------- /docs/editor/static/css/main.886a1ecf.chunk.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack://src/view/Canvas/index.module.css","webpack://src/component/PopoverOnSvg/index.module.css","webpack://src/component/EditableContent/index.module.css","webpack://src/view/HelpModal/index.module.css","webpack://src/view/Notation/index.module.css","webpack://src/view/Editor/index.module.css","webpack://src/index.css"],"names":[],"mappings":"AAAA,mBACE,wBAA4B,CAC5B,2BAAmC,CACnC,cACF,CACA,wBACE,wBAAiB,CAAjB,oBAAiB,CAAjB,gBACF,CCPA,6BACE,iBAAkB,CAClB,iBAAkB,CAClB,oCAAyC,CACzC,qBAAuB,CACvB,cACF,CACA,kCACE,qBAAuB,CACvB,UACF,CACA,2BACE,aAAc,CACd,iBAAkB,CAClB,UAAW,CACX,qBAAuB,CACvB,qBAAuB,CACvB,SAAU,CACV,UACF,CACA,gCACE,iBAAmB,CACnB,qBACF,CACA,gCACE,WAAY,CACZ,qDAA+C,CAA/C,6CAA+C,CAC/C,6CACF,CACA,iCACE,QAAS,CACT,qDAA+C,CAA/C,6CAA+C,CAC/C,6CACF,CACA,+BACE,YAAa,CAEb,2CACF,CACA,iEAHE,oDAA8C,CAA9C,4CAOF,CAJA,kCACE,OAAQ,CAER,6CACF,CACA,6BACE,eACF,CACA,4BACE,uCAA4C,CAC5C,eAAgB,CAChB,gBACF,CACA,iCACE,2CACF,CCtDA,oCACE,gBAAmB,CACnB,WAAY,CACZ,cAAe,CACf,gBACF,CACA,+BACE,gBACF,CACA,6BACE,gBAAiB,CACjB,aACF,CACA,uCACE,wBAA4B,CAC5B,oBAAuB,CACvB,wBAAiB,CAAjB,oBAAiB,CAAjB,gBACF,CACA,0CACE,wBACF,CCpBA,uBACA,SAAU,CACV,eACA,CACA,2BACE,oBAAqB,CACrB,cAAe,CACf,iBAAkB,CAClB,eACF,CACA,sBACE,oBAAqB,CACrB,gBAAiB,CACjB,iBAAkB,CAClB,wBAA2B,CAC3B,WAAY,CACZ,WAAY,CACZ,iBACF,CClBA,kCACE,WACF,CCFA,6BACE,kBAAmB,CACnB,+BAAmC,CACnC,UACF,CACA,sBACG,WAAY,CACZ,aACH,CACA,yBACE,YAAa,CACb,qBAAsB,CACtB,kBAAmB,CACnB,sBAAuB,CACvB,qBAAuB,CACvB,cAAe,CACf,WACF,CCjBA,KACE,QAAS,CACT,mJAEY,CACZ,kCAAmC,CACnC,iCACF,CAEA,KACE,yEAEF","file":"main.886a1ecf.chunk.css","sourcesContent":[".svg {\n border: 1px solid ghostwhite;\n box-shadow: ghostwhite 0px 0px 10px;\n font-size: 16px;\n}\n.svg :global(text) {\n user-select: none;\n}",".popover {\n position: absolute;\n border-radius: 4px;\n box-shadow: 0 1px 8px rgba(0, 0, 0, 0.15);\n background-color: white;\n min-width: 32px;\n}\n:global(.dark).popover {\n background-color: black;\n color: white;\n}\n.arrow {\n display: block;\n position: absolute;\n z-index: -1;\n border: 8px solid white;\n background-color: white;\n width: 8px;\n height: 8px;\n}\n:global(.dark).arrow {\n border-color: black;\n background-color: black;\n}\n:global(.left).arrow {\n right: -12px;\n transform: translate(-50%, -50%) rotate(135deg);\n box-shadow: -2px -2px 6px -2px rgba(0, 0, 0, 0.06);\n}\n:global(.right).arrow {\n left: 4px;\n transform: translate(-50%, -50%) rotate(-45deg);\n box-shadow: -2px -2px 6px -2px rgba(0, 0, 0, 0.06);\n}\n:global(.top).arrow {\n bottom: -12px;\n transform: translate(-50%, -50%) rotate(45deg);\n box-shadow: 3px 3px 7px -2px rgba(0, 0, 0, 0.07);\n}\n:global(.bottom).arrow {\n top: 4px;\n transform: translate(-50%, -50%) rotate(45deg);\n box-shadow: -3px -3px 8px -2px rgba(0, 0, 0, 0.07);\n}\n.content {\n padding: 4px 8px;\n}\n.header {\n border-bottom: 1px solid rgba(0, 0, 0, 0.08);\n padding: 4px 8px;\n line-height: 22px;\n}\n:global(.dark).header {\n border-bottom: 1px solid rgba(255, 255, 255, 0.35);\n}\n",".buttonGroup {\n margin: 8px 0 4px 0;\n width: 300px;\n max-width: 100%;\n text-align: right;\n}\n.button {\n margin-right: 8px;\n}\n.menu {\n max-height: 320px;\n overflow: auto;\n}\n.menuItem:hover {\n background-color: whitesmoke;\n color: black !important;\n user-select: none;\n}\n:global(.selected).menuItem {\n background-color: whitesmoke;\n}",".list {\npadding: 0;\nlist-style: none;\n}\n.listItem {\n display: inline-block;\n margin-top: 8px;\n margin-right: 16px;\n min-width: 260px;\n}\n.kbd {\n display: inline-block;\n margin-right: 8px;\n border-radius: 4px;\n background-color: lightgray;\n padding: 4px;\n width: 120px;\n text-align: center;\n}\n",".selectedNotation {\n color: coral;\n}",".headerWrapper {\n margin-bottom: 16px;\n border-bottom: 1px solid whitesmoke;\n width: 100%;\n}\n.header {\n margin: auto;\n padding: 8px 0;\n}\n.container {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n background-color: white;\n min-width: 100%;\n height: 100%;\n}\n","body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n"]} -------------------------------------------------------------------------------- /docs/editor/static/js/2.6118e75e.chunk.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | object-assign 3 | (c) Sindre Sorhus 4 | @license MIT 5 | */ 6 | 7 | /*! 8 | Copyright (c) 2018 Jed Watson. 9 | Licensed under the MIT License (MIT), see 10 | http://jedwatson.github.io/classnames 11 | */ 12 | 13 | /** @license React v0.20.2 14 | * scheduler.production.min.js 15 | * 16 | * Copyright (c) Facebook, Inc. and its affiliates. 17 | * 18 | * This source code is licensed under the MIT license found in the 19 | * LICENSE file in the root directory of this source tree. 20 | */ 21 | 22 | /** @license React v16.13.1 23 | * react-is.production.min.js 24 | * 25 | * Copyright (c) Facebook, Inc. and its affiliates. 26 | * 27 | * This source code is licensed under the MIT license found in the 28 | * LICENSE file in the root directory of this source tree. 29 | */ 30 | 31 | /** @license React v17.0.2 32 | * react-dom.production.min.js 33 | * 34 | * Copyright (c) Facebook, Inc. and its affiliates. 35 | * 36 | * This source code is licensed under the MIT license found in the 37 | * LICENSE file in the root directory of this source tree. 38 | */ 39 | 40 | /** @license React v17.0.2 41 | * react-jsx-runtime.production.min.js 42 | * 43 | * Copyright (c) Facebook, Inc. and its affiliates. 44 | * 45 | * This source code is licensed under the MIT license found in the 46 | * LICENSE file in the root directory of this source tree. 47 | */ 48 | 49 | /** @license React v17.0.2 50 | * react.production.min.js 51 | * 52 | * Copyright (c) Facebook, Inc. and its affiliates. 53 | * 54 | * This source code is licensed under the MIT license found in the 55 | * LICENSE file in the root directory of this source tree. 56 | */ 57 | -------------------------------------------------------------------------------- /docs/editor/static/js/3.c09cd1f8.chunk.js: -------------------------------------------------------------------------------- 1 | (this["webpackJsonpnumerical-notation-editor"]=this["webpackJsonpnumerical-notation-editor"]||[]).push([[3],{253:function(t,e,n){"use strict";n.r(e),n.d(e,"getCLS",(function(){return p})),n.d(e,"getFCP",(function(){return S})),n.d(e,"getFID",(function(){return F})),n.d(e,"getLCP",(function(){return k})),n.d(e,"getTTFB",(function(){return C}));var i,a,r,o,u=function(t,e){return{name:t,value:void 0===e?-1:e,delta:0,entries:[],id:"v1-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},c=function(t,e){try{if(PerformanceObserver.supportedEntryTypes.includes(t)){if("first-input"===t&&!("PerformanceEventTiming"in self))return;var n=new PerformanceObserver((function(t){return t.getEntries().map(e)}));return n.observe({type:t,buffered:!0}),n}}catch(t){}},f=function(t,e){var n=function n(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(t(i),e&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},s=function(t){addEventListener("pageshow",(function(e){e.persisted&&t(e)}),!0)},m="function"==typeof WeakSet?new WeakSet:new Set,d=function(t,e,n){var i;return function(){e.value>=0&&(n||m.has(e)||"hidden"===document.visibilityState)&&(e.delta=e.value-(i||0),(e.delta||void 0===i)&&(i=e.value,t(e)))}},p=function(t,e){var n,i=u("CLS",0),a=function(t){t.hadRecentInput||(i.value+=t.value,i.entries.push(t),n())},r=c("layout-shift",a);r&&(n=d(t,i,e),f((function(){r.takeRecords().map(a),n()})),s((function(){i=u("CLS",0),n=d(t,i,e)})))},v=-1,l=function(){return"hidden"===document.visibilityState?0:1/0},h=function(){f((function(t){var e=t.timeStamp;v=e}),!0)},g=function(){return v<0&&(v=l(),h(),s((function(){setTimeout((function(){v=l(),h()}),0)}))),{get timeStamp(){return v}}},S=function(t,e){var n,i=g(),a=u("FCP"),r=function(t){"first-contentful-paint"===t.name&&(f&&f.disconnect(),t.startTime=0&&a1e12?new Date:performance.now())-t.timeStamp;"pointerdown"==t.type?function(t,e){var n=function(){w(t,e),a()},i=function(){a()},a=function(){removeEventListener("pointerup",n,y),removeEventListener("pointercancel",i,y)};addEventListener("pointerup",n,y),addEventListener("pointercancel",i,y)}(e,t):w(e,t)}},b=function(t){["mousedown","keydown","touchstart","pointerdown"].forEach((function(e){return t(e,T,y)}))},F=function(t,e){var n,r=g(),p=u("FID"),v=function(t){t.startTime=0&&(n||u.has(t)||\"hidden\"===document.visibilityState)&&(t.delta=t.value-(i||0),(t.delta||void 0===i)&&(i=t.value,e(t)))}},s=function(e,t){var n,i=a(\"CLS\",0),u=function(e){e.hadRecentInput||(i.value+=e.value,i.entries.push(e),n())},s=r(\"layout-shift\",u);s&&(n=f(e,i,t),o((function(){s.takeRecords().map(u),n()})),c((function(){i=a(\"CLS\",0),n=f(e,i,t)})))},m=-1,p=function(){return\"hidden\"===document.visibilityState?0:1/0},v=function(){o((function(e){var t=e.timeStamp;m=t}),!0)},d=function(){return m<0&&(m=p(),v(),c((function(){setTimeout((function(){m=p(),v()}),0)}))),{get timeStamp(){return m}}},l=function(e,t){var n,i=d(),o=a(\"FCP\"),s=function(e){\"first-contentful-paint\"===e.name&&(p&&p.disconnect(),e.startTime=0&&t1e12?new Date:performance.now())-e.timeStamp;\"pointerdown\"==e.type?function(e,t){var n=function(){y(e,t),a()},i=function(){a()},a=function(){removeEventListener(\"pointerup\",n,h),removeEventListener(\"pointercancel\",i,h)};addEventListener(\"pointerup\",n,h),addEventListener(\"pointercancel\",i,h)}(t,e):y(t,e)}},w=function(e){[\"mousedown\",\"keydown\",\"touchstart\",\"pointerdown\"].forEach((function(t){return e(t,E,h)}))},L=function(n,s){var m,p=d(),v=a(\"FID\"),l=function(e){e.startTime0.2%", 45 | "not dead", 46 | "not op_mini all" 47 | ], 48 | "development": [ 49 | "last 1 chrome version", 50 | "last 1 firefox version", 51 | "last 1 safari version" 52 | ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattuylee/numerical-notation-editor/1b80f8903ec9f3bdd62df04ef69c8288b5c3b287/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 简单简谱编辑器 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattuylee/numerical-notation-editor/1b80f8903ec9f3bdd62df04ef69c8288b5c3b287/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattuylee/numerical-notation-editor/1b80f8903ec9f3bdd62df04ef69c8288b5c3b287/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect } from "react"; 2 | import Editor from "./view/Editor"; 3 | import globalStore, { GlobalContext } from "./store/global"; 4 | import { loadExample } from "./util/load-example"; 5 | 6 | // ENHANCE: 替换掉antd组件库。。一堆莫名其妙的毛病 7 | function App() { 8 | useEffect(() => { 9 | loadExample(); 10 | }, []); 11 | return ( 12 | 13 | 14 | 15 | ); 16 | } 17 | 18 | export default App; 19 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/component/EditableContent/index.js: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useImperativeHandle, useState } from "react"; 2 | import { Button, Input, Menu } from "antd"; 3 | import PopoverOnSvg from "../PopoverOnSvg"; 4 | import Styles from "./index.module.css"; 5 | 6 | const EditableContent = function ( 7 | { 8 | children, 9 | title, 10 | initialValue, 11 | inputType, 12 | // ENHANCE: 去除这个prop,使用overlay代替 13 | options, 14 | // 选择模式要渲染的菜单,如果没有提供则根据options生成 15 | overlay, 16 | onChange, 17 | popoverProps, 18 | }, 19 | ref 20 | ) { 21 | const [inputValue, setInputValue] = useState(initialValue); 22 | const [popoverVisible, setPopoverVisible] = useState(false); 23 | useImperativeHandle( 24 | ref, 25 | () => ({ 26 | showPopover: setPopoverVisible.bind(null, true), 27 | hidePopover: setPopoverVisible.bind(null, false), 28 | }), 29 | [] 30 | ); 31 | const handleVisibilityChange = useCallback( 32 | function (value) { 33 | setPopoverVisible(value); 34 | if (!value) { 35 | setInputValue(initialValue); 36 | } 37 | }, 38 | [initialValue] 39 | ); 40 | const handleInput = useCallback(function (ev) { 41 | setInputValue(ev.target.value); 42 | }, []); 43 | const handleConfirm = useCallback( 44 | async function (value) { 45 | const v = value === undefined ? inputValue : value; 46 | const success = await (onChange && onChange(v)); 47 | success !== false && setPopoverVisible(false); 48 | }, 49 | [inputValue, onChange] 50 | ); 51 | const handleHideContextMenu = useCallback(() => { 52 | setPopoverVisible(false); 53 | }, []); 54 | const handleCancel = useCallback( 55 | function () { 56 | setInputValue(initialValue); 57 | setPopoverVisible(false); 58 | }, 59 | [initialValue] 60 | ); 61 | const renderTextInputPopover = useCallback( 62 | () => ( 63 | <> 64 | handleConfirm()} 69 | /> 70 |
71 | 78 | 79 |
80 | 81 | ), 82 | [inputValue, handleInput, handleConfirm, handleCancel] 83 | ); 84 | const renderSelectionPopover = useCallback(() => { 85 | if (overlay) { 86 | return
{overlay}
; 87 | } 88 | return ( 89 | 90 | {(options || []) 91 | .filter((op) => op.visible !== false) 92 | .map((option) => ( 93 | handleConfirm(option.key)} 101 | > 102 | {option.text} 103 | 104 | ))} 105 | 106 | ); 107 | }, [initialValue, options, handleConfirm, handleHideContextMenu, overlay]); 108 | let renderContent, renderPopover; 109 | switch (inputType) { 110 | case "select": 111 | renderContent = renderSelectionPopover; 112 | break; 113 | case "number": 114 | case "text": 115 | default: 116 | renderContent = renderTextInputPopover; 117 | } 118 | 119 | return ( 120 | 130 | {children} 131 | 132 | ); 133 | }; 134 | 135 | export default React.forwardRef(EditableContent); 136 | -------------------------------------------------------------------------------- /src/component/EditableContent/index.module.css: -------------------------------------------------------------------------------- 1 | .buttonGroup { 2 | margin: 8px 0 4px 0; 3 | width: 300px; 4 | max-width: 100%; 5 | text-align: right; 6 | } 7 | .button { 8 | margin-right: 8px; 9 | } 10 | .menu { 11 | max-height: 320px; 12 | overflow: auto; 13 | } 14 | .menuItem:hover { 15 | background-color: whitesmoke; 16 | color: black !important; 17 | user-select: none; 18 | } 19 | :global(.selected).menuItem { 20 | background-color: whitesmoke; 21 | } -------------------------------------------------------------------------------- /src/component/PopoverOnSvg/container.js: -------------------------------------------------------------------------------- 1 | let dirty = false; 2 | let memoizedRect = { x: 0, y: 0 }; 3 | let container; 4 | 5 | function getPopoverContainer() { 6 | if (!container) { 7 | container = document.createElement("div"); 8 | container.id = "svg-popover-container"; 9 | container.style = ` 10 | position: absolute; 11 | left: 0; 12 | top: 0; 13 | `; 14 | document.body.appendChild(container); 15 | document.addEventListener("scroll", () => void (dirty = true)); 16 | } 17 | return container; 18 | } 19 | 20 | function getContainerOffset() { 21 | if (dirty) { 22 | const rect = getPopoverContainer().getBoundingClientRect(); 23 | memoizedRect = { 24 | x: -rect.x, 25 | y: -rect.y, 26 | }; 27 | dirty = false; 28 | } 29 | return memoizedRect; 30 | } 31 | 32 | export { getPopoverContainer, getContainerOffset }; 33 | -------------------------------------------------------------------------------- /src/component/PopoverOnSvg/index.js: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useEffect, useRef, useState } from "react"; 2 | import { createPortal } from "react-dom"; 3 | import Styles from "./index.module.css"; 4 | import { getContainerOffset, getPopoverContainer } from "./container"; 5 | 6 | // ENHANCE: smart placement 7 | function PopoverOnSvg({ 8 | children, 9 | renderContent, 10 | renderPopover, 11 | darkMode, 12 | globalClassName, 13 | offset, 14 | placement, 15 | style, 16 | title, 17 | trigger, 18 | visible, 19 | autoHide, 20 | showArrow, 21 | onVisibilityChange, 22 | }) { 23 | const triggerBoxRef = useRef({ 24 | x: 0, 25 | y: 0, 26 | width: 0, 27 | height: 0, 28 | top: 0, 29 | bottom: 0, 30 | left: 0, 31 | right: 0, 32 | }); 33 | const initFlagRef = useRef(false); 34 | const triggerRef = useRef(); 35 | const popoverRef = useRef(); 36 | // initially, always set innerVisible to false. If the prop *visible* is 37 | // true, we'll update it after dom mounted, because we cannot calculate 38 | // correct position of popover before react mounting it. 39 | const [innerVisible, setInnerVisible] = useState(false); 40 | const [lastContextCord, setLastContextCord] = useState({ x: 0, y: 0 }); 41 | const [, forceUpdate] = useState(); 42 | const popoverClassNames = [Styles.popover, globalClassName].filter(Boolean); 43 | const arrowClassNames = [Styles.arrow]; 44 | const headerClassNames = [Styles.header]; 45 | let offsetX = (offset && offset.x) || 0; 46 | let offsetY = (offset && offset.y) || 0; 47 | let mergedStyles = { 48 | transform: "", 49 | }; 50 | const arrowStyles = {}; 51 | placement = placement.toLowerCase(); 52 | 53 | const makeOffset = function (x, y = 0) { 54 | offsetX += x; 55 | offsetY += y; 56 | }; 57 | const changeVisibility = useCallback( 58 | function (shouldShow) { 59 | shouldShow = shouldShow ?? !innerVisible; 60 | let newVisibility = visible === undefined ? shouldShow : visible; 61 | if (newVisibility) { 62 | if (!triggerRef.current) { 63 | setTimeout(changeVisibility, 0); 64 | return; 65 | } 66 | // re-get box of trigger element 67 | triggerBoxRef.current = triggerRef.current.getBoundingClientRect(); 68 | } 69 | setInnerVisible(newVisibility); 70 | // FIXME: visible由false变为true时React Warning: Cannot update a component (`EditableContent`) while rendering a different component (`PopoverOnSvg`). 71 | onVisibilityChange && onVisibilityChange(shouldShow); 72 | }, 73 | [visible, innerVisible, onVisibilityChange] 74 | ); 75 | const handleContextMenu = useCallback( 76 | (ev) => { 77 | setLastContextCord({ x: ev.pageX, y: ev.pageY }); 78 | ev.preventDefault(); 79 | changeVisibility(true); 80 | }, 81 | [changeVisibility] 82 | ); 83 | useEffect(() => { 84 | initFlagRef.current = true; 85 | }, []); 86 | useEffect(() => { 87 | if (autoHide === false) { 88 | return; 89 | } 90 | const handler = (ev) => { 91 | if (ev.type === "keydown" && ev.key === "Escape") { 92 | changeVisibility(false); 93 | } else if (ev.type === "mouseup") { 94 | for (let target = ev.target; target; target = target.parentElement) { 95 | if (target === popoverRef.current) { 96 | return; 97 | } else if (target === triggerRef.current) { 98 | if (trigger === "context" && ev.button !== 2) { 99 | continue; 100 | } else if (trigger === "click" && ev.button !== 0) { 101 | continue; 102 | } 103 | return; 104 | } 105 | } 106 | changeVisibility(false); 107 | } 108 | }; 109 | if (innerVisible) { 110 | document.addEventListener("mouseup", handler); 111 | document.addEventListener("keydown", handler); 112 | } 113 | return () => { 114 | document.removeEventListener("mouseup", handler); 115 | document.removeEventListener("keydown", handler); 116 | }; 117 | }, [innerVisible, autoHide, changeVisibility, trigger]); 118 | 119 | if (visible !== undefined && visible !== innerVisible) { 120 | if (initFlagRef.current) { 121 | changeVisibility(); 122 | } else { 123 | setTimeout(() => { 124 | // this is the first-time render, trigger dom has not mounted, so we 125 | // have to delay the rendering 126 | forceUpdate([]); 127 | }, 0); 128 | } 129 | } 130 | if (trigger !== "context") { 131 | const box = triggerBoxRef.current; 132 | switch (true) { 133 | case /^(left|right)(top|center|bottom)?$/i.test(placement): 134 | mergedStyles.minHeight = "32px"; 135 | if (placement.startsWith("right")) { 136 | mergedStyles.left = box.right + "px"; 137 | } else { 138 | mergedStyles.left = box.left + "px"; 139 | mergedStyles.transform += " translate(-100%, 0)"; 140 | } 141 | if (placement.endsWith("top")) { 142 | mergedStyles.top = box.top + "px"; 143 | mergedStyles.transform += " translate(0, 0)"; 144 | arrowStyles.top = "16px"; 145 | } else if (placement.endsWith("bottom")) { 146 | mergedStyles.top = box.bottom + "px"; 147 | mergedStyles.transform += " translate(0, -100%)"; 148 | arrowStyles.bottom = "0"; 149 | } else { 150 | mergedStyles.top = box.y + box.height / 2 + "px"; 151 | mergedStyles.transform += " translate(0, -50%)"; 152 | arrowStyles.top = "50%"; 153 | } 154 | break; 155 | case /^(top|bottom)(left|center|right)?$/i.test(placement): 156 | default: 157 | if (placement.startsWith("bottom")) { 158 | mergedStyles.top = box.bottom + "px"; 159 | } else { 160 | mergedStyles.top = box.y + "px"; 161 | mergedStyles.transform += " translate(0, -100%)"; 162 | } 163 | if (placement.endsWith("left")) { 164 | mergedStyles.left = box.left + "px"; 165 | arrowStyles.left = "16px"; 166 | } else if (placement.endsWith("right")) { 167 | mergedStyles.left = box.right + "px"; 168 | mergedStyles.transform += " translate(-100%, 0)"; 169 | arrowStyles.right = "0"; 170 | } else { 171 | mergedStyles.left = box.right - box.width / 2 + "px"; 172 | mergedStyles.transform += " translateX(-50%)"; 173 | arrowStyles.left = "50%"; 174 | } 175 | break; 176 | } 177 | switch (true) { 178 | case !showArrow: 179 | break; 180 | case placement.startsWith("left"): 181 | makeOffset(-8); 182 | arrowClassNames.push("left"); 183 | break; 184 | case placement.startsWith("right"): 185 | makeOffset(8); 186 | arrowClassNames.push("right"); 187 | break; 188 | case placement.startsWith("bottom"): 189 | makeOffset(0, 8); 190 | arrowClassNames.push("bottom"); 191 | break; 192 | case placement.startsWith("top"): 193 | default: 194 | makeOffset(0, -8); 195 | arrowClassNames.push("top"); 196 | break; 197 | } 198 | makeOffset(getContainerOffset().x, getContainerOffset().y); 199 | mergedStyles.transform += ` translate(${offsetX}px, ${offsetY}px)`; 200 | } else { 201 | mergedStyles.left = lastContextCord.x; 202 | mergedStyles.top = lastContextCord.y; 203 | mergedStyles.transform = `translate(${offsetX}px, ${offsetY}px)`; 204 | } 205 | if (darkMode) { 206 | popoverClassNames.push("dark"); 207 | arrowClassNames.push("dark"); 208 | headerClassNames.push("dark"); 209 | } 210 | mergedStyles = Object.assign(mergedStyles, style); 211 | return ( 212 | <> 213 | [] 214 | changeVisibility() : undefined} 218 | onMouseEnter={ 219 | trigger === "hover" ? () => changeVisibility(true) : undefined 220 | } 221 | onMouseLeave={ 222 | trigger === "hover" ? () => changeVisibility(false) : undefined 223 | } 224 | onContextMenu={trigger === "context" ? handleContextMenu : undefined} 225 | > 226 | {children} 227 | 228 | {innerVisible && 229 | createPortal( 230 |
235 | {renderPopover ? ( 236 | typeof renderPopover === "function" ? ( 237 | renderPopover() 238 | ) : ( 239 | renderPopover 240 | ) 241 | ) : ( 242 | <> 243 | {showArrow && ( 244 |
248 | )} 249 | {title && ( 250 |
251 | {title} 252 |
253 | )} 254 |
255 | {typeof renderContent === "function" 256 | ? renderContent() 257 | : renderContent ?? null} 258 |
259 | 260 | )} 261 |
, 262 | getPopoverContainer() 263 | )} 264 | 265 | ); 266 | } 267 | 268 | PopoverOnSvg.defaultProps = { 269 | trigger: "click", 270 | placement: "top", 271 | showArrow: true, 272 | }; 273 | 274 | export default React.memo(PopoverOnSvg); 275 | -------------------------------------------------------------------------------- /src/component/PopoverOnSvg/index.module.css: -------------------------------------------------------------------------------- 1 | .popover { 2 | position: absolute; 3 | border-radius: 4px; 4 | box-shadow: 0 1px 8px rgba(0, 0, 0, 0.15); 5 | background-color: white; 6 | min-width: 32px; 7 | } 8 | :global(.dark).popover { 9 | background-color: black; 10 | color: white; 11 | } 12 | .arrow { 13 | display: block; 14 | position: absolute; 15 | z-index: -1; 16 | border: 8px solid white; 17 | background-color: white; 18 | width: 8px; 19 | height: 8px; 20 | } 21 | :global(.dark).arrow { 22 | border-color: black; 23 | background-color: black; 24 | } 25 | :global(.left).arrow { 26 | right: -12px; 27 | transform: translate(-50%, -50%) rotate(135deg); 28 | box-shadow: -2px -2px 6px -2px rgba(0, 0, 0, 0.06); 29 | } 30 | :global(.right).arrow { 31 | left: 4px; 32 | transform: translate(-50%, -50%) rotate(-45deg); 33 | box-shadow: -2px -2px 6px -2px rgba(0, 0, 0, 0.06); 34 | } 35 | :global(.top).arrow { 36 | bottom: -12px; 37 | transform: translate(-50%, -50%) rotate(45deg); 38 | box-shadow: 3px 3px 7px -2px rgba(0, 0, 0, 0.07); 39 | } 40 | :global(.bottom).arrow { 41 | top: 4px; 42 | transform: translate(-50%, -50%) rotate(45deg); 43 | box-shadow: -3px -3px 8px -2px rgba(0, 0, 0, 0.07); 44 | } 45 | .content { 46 | padding: 4px 8px; 47 | } 48 | .header { 49 | border-bottom: 1px solid rgba(0, 0, 0, 0.08); 50 | padding: 4px 8px; 51 | line-height: 22px; 52 | } 53 | :global(.dark).header { 54 | border-bottom: 1px solid rgba(255, 255, 255, 0.35); 55 | } 56 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "antd/dist/antd.css"; 4 | import App from "./App"; 5 | import reportWebVitals from "./reportWebVitals"; 6 | import "./index.css"; 7 | 8 | ReactDOM.render( 9 | 10 | 11 | , 12 | document.getElementById("root") 13 | ); 14 | 15 | // If you want to start measuring performance in your app, pass a function 16 | // to log results (for example: reportWebVitals(console.log)) 17 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 18 | reportWebVitals(); 19 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/menu/editor.js: -------------------------------------------------------------------------------- 1 | import { 2 | FolderOpenOutlined, 3 | HighlightOutlined, 4 | MenuUnfoldOutlined, 5 | PlusOutlined, 6 | RedoOutlined, 7 | SaveOutlined, 8 | UndoOutlined, 9 | } from "@ant-design/icons"; 10 | import { Menu } from "antd"; 11 | import state from "../store/state"; 12 | import store from "../store/global"; 13 | import { 14 | cloneNotation, 15 | createNotation, 16 | isNote, 17 | notations as N, 18 | placeTie, 19 | } from "../util/notation"; 20 | import { 21 | cloneParagraph, 22 | createParagraph, 23 | createParagraphWithNotations, 24 | } from "../util/paragraph"; 25 | import { convertTone, convertToneTo } from "../util/tone-convert"; 26 | import { exportFile, loadFile, saveFile } from "../util/file"; 27 | import { findParagraphAndNotation, resetGlobalData } from "../util/editor"; 28 | import { 29 | go, 30 | runInWrappedAction, 31 | unwrappedAction, 32 | wrappedAction, 33 | } from "../store/history"; 34 | 35 | const { SubMenu } = Menu; 36 | 37 | const handleOpenFile = unwrappedAction((ev) => { 38 | const file = ev.target.files[0]; 39 | loadFile(file); 40 | }); 41 | const handleSaveFile = () => { 42 | saveFile(); 43 | }; 44 | const handleExportFile = unwrappedAction(() => { 45 | state.selectedNotationKey = null; 46 | exportFile(); 47 | }); 48 | const handleCreate = () => { 49 | resetGlobalData(); 50 | }; 51 | const handleEditMenu = wrappedAction(({ key }) => { 52 | switch (key) { 53 | case "undo": 54 | go(-1); 55 | break; 56 | case "redo": 57 | go(1); 58 | break; 59 | case "reset-title": 60 | runInWrappedAction(() => { 61 | store.title = "【歌曲名称】"; 62 | }); 63 | break; 64 | case "reset-authors": 65 | store.authors = [ 66 | "【作曲者】 作曲", 67 | "【填词者】 填词", 68 | "【记谱者】 记谱", 69 | ]; 70 | break; 71 | case "add-paragraph": { 72 | store.paragraphs.push(createParagraphWithNotations()); 73 | break; 74 | } 75 | default: 76 | break; 77 | } 78 | }); 79 | const handleConvertMenu = ({ key }) => { 80 | switch (true) { 81 | case key.startsWith("convertTo"): 82 | const destTone = key.split("-", 2)[1]; 83 | convertToneTo(destTone); 84 | break; 85 | case key === "convert-up": 86 | convertTone(2); 87 | break; 88 | case key === "convert-down": 89 | convertTone(-2); 90 | break; 91 | case key === "convert-up8": 92 | convertTone(12); 93 | break; 94 | case key === "convert-down8": 95 | convertTone(-12); 96 | break; 97 | default: 98 | break; 99 | } 100 | }; 101 | 102 | // 画布上的点击事件 103 | const handleClick = wrappedAction((ev) => { 104 | if (state.shouldNotationBlurAfterClick && state.selectedNotationKey) { 105 | state.lastSelectedNotationKey = state.selectedNotationKey; 106 | state.selectedNotationKey = null; 107 | } 108 | state.shouldNotationBlurAfterClick = true; 109 | }); 110 | 111 | const handleKeyPress = wrappedAction((ev) => { 112 | const inputKey = ev.key.toLowerCase(); 113 | const shift = ev.shiftKey; 114 | const ctrl = ev.ctrlKey; 115 | 116 | if (state.selectedNotationKey) { 117 | // 仅选中符号时作用 118 | if (state.helpDialogVisible || state.configDialogVisible) { 119 | return; 120 | } 121 | const { 122 | paragraph, 123 | notation, 124 | paragraphIndex, 125 | notationIndex, 126 | } = findParagraphAndNotation(state.selectedNotationKey); 127 | if (!notation) { 128 | return; 129 | } 130 | switch (true) { 131 | case isNote(inputKey) && !ctrl && !shift: 132 | notation.note = inputKey; 133 | break; 134 | case inputKey === "(" && !ctrl: 135 | notation.note = N.crackerOpen; 136 | break; 137 | case inputKey === ")" && !ctrl: 138 | notation.note = N.crackerClose; 139 | break; 140 | case inputKey === "-" && !ctrl && !shift: 141 | notation.note = N.extend; 142 | break; 143 | case inputKey === "|" && !ctrl: 144 | notation.note = N.separator; 145 | break; 146 | case inputKey === "u" && !ctrl && !shift: 147 | notation.underline += 1; 148 | break; 149 | case inputKey === "u" && !ctrl && shift: 150 | notation.underline -= 1; 151 | notation.underline = Math.max(0, notation.underline); 152 | break; 153 | case inputKey === "." && !ctrl && !shift: 154 | notation.dotted = !notation.dotted; 155 | break; 156 | case inputKey === "8" && !ctrl && !shift: 157 | notation.octave += 1; 158 | break; 159 | case inputKey === "*" && !ctrl: 160 | notation.octave -= 1; 161 | break; 162 | case inputKey === "#" && !ctrl: 163 | if (notation.prefixSups.indexOf("♯") !== 0) { 164 | if (notation.prefixSups[0] === "♭") { 165 | notation.prefixSups.shift(); 166 | } 167 | notation.prefixSups.unshift("♯"); 168 | } else { 169 | notation.prefixSups.shift(); 170 | } 171 | break; 172 | case inputKey === "b" && !ctrl && !shift: { 173 | if (notation.prefixSups.indexOf("♭") !== 0) { 174 | if (notation.prefixSups[0] === "♯") { 175 | notation.prefixSups.shift(); 176 | } 177 | notation.prefixSups.unshift("♭"); 178 | } else { 179 | notation.prefixSups.shift(); 180 | } 181 | break; 182 | } 183 | case inputKey === "a" && !ctrl && !shift: { 184 | if (!state.tieSourceKey) { 185 | state.tieSourceKey = notation.key; 186 | } else if (state.tieSourceKey === notation.key) { 187 | state.tieSourceKey = null; 188 | } else { 189 | placeTie(notation); 190 | } 191 | break; 192 | } 193 | case inputKey === "a" && !ctrl && shift: { 194 | if (notation.tieTo) { 195 | const { notation: tieDesc } = findParagraphAndNotation( 196 | notation.tieTo 197 | ); 198 | if (tieDesc) { 199 | tieDesc.tieTo = null; 200 | } 201 | notation.tieTo = null; 202 | break; 203 | } 204 | } 205 | case inputKey === "!" && !ctrl: { 206 | notation.breakUnderline = !notation.breakUnderline; 207 | break; 208 | } 209 | case inputKey === "~" && !ctrl: { 210 | if (notation.topDecorators.includes("~")) { 211 | notation.topDecorators.splice(notation.topDecorators.indexOf("~"), 1); 212 | } else { 213 | notation.topDecorators.push("~"); 214 | } 215 | break; 216 | } 217 | case inputKey === "enter" && !ctrl && !shift: { 218 | if (paragraph.notations[notationIndex + 1]) { 219 | state.selectedNotationKey = 220 | paragraph.notations[notationIndex + 1].key; 221 | } else { 222 | const nextNotation = createNotation(); 223 | paragraph.notations.push(nextNotation); 224 | state.selectedNotationKey = nextNotation.key; 225 | } 226 | break; 227 | } 228 | case inputKey === "l" && !ctrl && !shift: { 229 | const nextNotation = 230 | paragraph.notations[notationIndex + 1] || 231 | store.paragraphs[paragraphIndex + 1].notations?.at(0); 232 | if (nextNotation) { 233 | state.selectedNotationKey = nextNotation.key; 234 | } 235 | break; 236 | } 237 | case inputKey === "enter" && !ctrl && shift: { 238 | if (paragraph.notations[notationIndex - 1]) { 239 | state.selectedNotationKey = 240 | paragraph.notations[notationIndex - 1].key; 241 | } 242 | break; 243 | } 244 | case inputKey === "h" && !ctrl && !shift: { 245 | const prevNotation = 246 | paragraph.notations[notationIndex - 1] || 247 | store.paragraphs[paragraphIndex - 1].notations?.at(-1); 248 | if (prevNotation) { 249 | state.selectedNotationKey = prevNotation.key; 250 | } 251 | break; 252 | } 253 | case inputKey === "enter" && ctrl && !shift: { 254 | const newNotation = createNotation(); 255 | if ( 256 | notationIndex === paragraph.notations.length - 1 && 257 | paragraphIndex === store.paragraphs.length - 1 258 | ) { 259 | // 在最后一个音符时ctrl+enter插入新段落并创建符号 260 | store.paragraphs.push(createParagraph({ notations: [newNotation] })); 261 | state.selectedNotationKey = store.paragraphs 262 | .at(-1) 263 | .notations.at(0).key; 264 | } else { 265 | paragraph.notations.splice(notationIndex + 1, 0, newNotation); 266 | state.selectedNotationKey = newNotation.key; 267 | } 268 | break; 269 | } 270 | case inputKey === "j" && !ctrl && !shift: { 271 | const nextParagraph = store.paragraphs[paragraphIndex + 1]; 272 | if (nextParagraph?.notations?.length) { 273 | const nextNotation = 274 | nextParagraph.notations[notationIndex] || 275 | nextParagraph.notations.at(-1); 276 | state.selectedNotationKey = nextNotation.key; 277 | } 278 | break; 279 | } 280 | case inputKey === "k" && !ctrl && !shift: { 281 | const prevParagraph = store.paragraphs[paragraphIndex - 1]; 282 | if (prevParagraph?.notations?.length) { 283 | const prevNotation = 284 | prevParagraph.notations[notationIndex] || 285 | prevParagraph.notations.at(-1); 286 | state.selectedNotationKey = prevNotation.key; 287 | } 288 | break; 289 | } 290 | case inputKey === "backspace" && !ctrl && !shift: 291 | case inputKey === "delete" && !ctrl && !shift: { 292 | paragraph.notations.splice(notationIndex, 1); 293 | const currNotation = 294 | paragraph.notations[notationIndex] || 295 | paragraph.notations[notationIndex - 1]; 296 | state.selectedNotationKey = currNotation?.key; 297 | break; 298 | } 299 | case inputKey === "backspace" && !ctrl && shift: 300 | case inputKey === "delete" && !ctrl && shift: { 301 | store.paragraphs.splice(paragraphIndex, 1); 302 | const currParagraph = 303 | store.paragraphs[paragraphIndex] || store.paragraphs.at(-1); 304 | const currNotation = 305 | currParagraph?.notations?.at(notationIndex) || 306 | currParagraph?.notations?.at(-1); 307 | state.selectedNotationKey = currNotation?.key; 308 | break; 309 | } 310 | case inputKey === "=" && !ctrl && !shift: { 311 | if (typeof paragraph.alignJustify !== "boolean") { 312 | paragraph.alignJustify = !( 313 | paragraphIndex === 314 | store.paragraphs.length - 1 315 | ); 316 | } 317 | paragraph.alignJustify = !paragraph.alignJustify; 318 | break; 319 | } 320 | case inputKey === "c" && ctrl && !shift: { 321 | ev.preventDefault(); 322 | state.clipboardContent = notation; 323 | break; 324 | } 325 | case inputKey === "c" && ctrl && shift: { 326 | ev.preventDefault(); 327 | state.clipboardContent = paragraph; 328 | break; 329 | } 330 | case inputKey === "v" && ctrl && !shift: { 331 | ev.preventDefault(); 332 | if (state.clipboardContent) { 333 | switch (state.clipboardContent.type) { 334 | case "notation": 335 | paragraph.notations.splice( 336 | notationIndex + 1, 337 | 0, 338 | cloneNotation(state.clipboardContent) 339 | ); 340 | break; 341 | case "paragraph": 342 | store.paragraphs.splice( 343 | paragraphIndex + 1, 344 | 0, 345 | cloneParagraph(state.clipboardContent) 346 | ); 347 | break; 348 | default: 349 | state.clipboardContent = null; 350 | } 351 | } 352 | break; 353 | } 354 | default: 355 | break; 356 | } 357 | } else { 358 | // 仅未选中符号时 359 | switch (true) { 360 | case ["h", "j", "k", "l"].includes(inputKey): { 361 | const { notation: n } = findParagraphAndNotation( 362 | state.lastSelectedNotationKey 363 | ); 364 | state.selectedNotationKey = ( 365 | n || store.paragraphs?.at(0)?.notations?.at(0) 366 | )?.key; 367 | break; 368 | } 369 | default: 370 | break; 371 | } 372 | } 373 | // 全局 374 | switch (true) { 375 | case inputKey === "z" && ctrl && !shift: 376 | go(-1); 377 | break; 378 | case inputKey === "y" && ctrl && !shift: 379 | case inputKey === "z" && ctrl && shift: 380 | go(1); 381 | break; 382 | case inputKey === "s" && ctrl && !shift: { 383 | ev.preventDefault(); 384 | saveFile(); 385 | break; 386 | } 387 | case inputKey === "o" && ctrl && !shift: { 388 | ev.preventDefault(); 389 | const input = document.createElement("input"); 390 | input.type = "file"; 391 | input.accept = ".json"; 392 | input.onchange = handleOpenFile; 393 | input.click(); 394 | break; 395 | } 396 | case inputKey === "?" && !ctrl: { 397 | if (state.helpDialogVisible) { 398 | state.helpDialogVisible = false; 399 | } else { 400 | state.configDialogVisible = false; 401 | state.helpDialogVisible = true; 402 | } 403 | break; 404 | } 405 | default: 406 | break; 407 | } 408 | }); 409 | 410 | const fileMenu = ( 411 | 412 | } onClick={handleCreate}> 413 | 新建 414 | 415 | }> 416 | 打开 417 | 432 | 433 | } onClick={handleSaveFile}> 434 | 保存 435 | 436 | } onClick={handleExportFile}> 437 | 导出为图片 438 | 439 | 440 | ); 441 | const editMenu = ( 442 | 443 | }> 444 | 撤销 445 | 446 | }> 447 | 重做 448 | 449 | }> 450 | 添加段落 451 | 452 | }> 453 | 重置歌曲名称 454 | 455 | }> 456 | 重置作者信息 457 | 458 | 459 | ); 460 | 461 | const convertMenu = ( 462 | 463 | 464 | 1 = C 465 | 1 = D 466 | 1 = E 467 | 1 = F 468 | 1 = G 469 | 1 = A 470 | 1 = B 471 | 472 | 1 = D 473 | 474 | 475 | 1 = E 476 | 477 | 478 | 1 = G 479 | 480 | 481 | 1 = A 482 | 483 | 484 | 1 = B 485 | 486 | 487 | 升高一个音 488 | 降低一个音 489 | 升高一个八度 490 | 降低一个八度 491 | 492 | ); 493 | 494 | export { fileMenu, editMenu, convertMenu, handleKeyPress, handleClick }; 495 | -------------------------------------------------------------------------------- /src/menu/notation.js: -------------------------------------------------------------------------------- 1 | import { 2 | DeleteOutlined, 3 | RadiusSettingOutlined, 4 | StopOutlined, 5 | } from "@ant-design/icons"; 6 | import { Menu } from "antd"; 7 | import state from "../store/state"; 8 | import { findParagraphAndNotation } from "../util/editor"; 9 | import { isNote } from "../util/notation"; 10 | import { runInWrappedAction, wrappedAction } from "../store/history"; 11 | 12 | const getNotationContextMenu = (notation, paragraph) => { 13 | const hasTie = notation.tieTo; 14 | const handleMenu = wrappedAction(function ({ key }) { 15 | switch (true) { 16 | case key === "tie": { 17 | if (!hasTie) { 18 | state.tieSourceKey = notation.key; 19 | return; 20 | } 21 | const { notation: tieDesc } = findParagraphAndNotation(notation.tieTo); 22 | if (tieDesc) { 23 | tieDesc.tieTo = null; 24 | } 25 | notation.tieTo = null; 26 | break; 27 | } 28 | case key === "break-underline": 29 | notation.breakUnderline = !notation.breakUnderline; 30 | break; 31 | case key.startsWith("separator-"): { 32 | const separator = key.split("-", 2)[1]; 33 | notation.note = separator; 34 | break; 35 | } 36 | default: 37 | break; 38 | } 39 | }); 40 | 41 | return ( 42 | // ENHANCE: 分音符类型显示菜单项 43 | 44 | {isNote(notation) && ( 45 | }> 46 | {notation.breakUnderline 47 | ? "在此处延续增减时线" 48 | : "在此处打断增减时线"} 49 | 50 | )} 51 | {isNote(notation) && ( 52 | } 55 | notation={notation} 56 | > 57 | {notation.tieTo ? "删除连音线" : "从此处添加连音线到..."} 58 | 59 | )} 60 | }> 61 | 删除符号 62 | 63 | 64 | ); 65 | }; 66 | 67 | // ENHANCE: 使用EditableContent组件的overlay属性传入菜单 68 | // 执行选项回调。。 69 | function handleNotationContext(options, key) { 70 | runInWrappedAction(() => (state.shouldNotationBlurAfterClick = false)); 71 | const callback = options.find((ops) => ops.key === key)?.onClick; 72 | callback && callback(); 73 | } 74 | 75 | export { getNotationContextMenu, handleNotationContext }; 76 | -------------------------------------------------------------------------------- /src/menu/paragraph.js: -------------------------------------------------------------------------------- 1 | import { DeleteOutlined, EnterOutlined } from "@ant-design/icons"; 2 | import { Menu } from "antd"; 3 | import store from "../store/global"; 4 | import { createNotation, notations } from "../util/notation"; 5 | import { createParagraph } from "../util/paragraph"; 6 | import { wrappedAction } from "../store/history"; 7 | 8 | function getParagraphMenuOptions(paragraph) { 9 | const handleMenu = wrappedAction(({ key }) => { 10 | switch (key) { 11 | case "add": { 12 | const idx = store.paragraphs.findIndex((p) => p.key === paragraph.key); 13 | const para = createParagraph({ 14 | notations: [ 15 | createNotation({ note: "0" }), 16 | createNotation({ note: "0" }), 17 | createNotation({ note: "0" }), 18 | createNotation({ note: "0" }), 19 | createNotation({ note: notations.separator }), 20 | ], 21 | }); 22 | if (idx !== -1) { 23 | store.paragraphs.splice(idx + 1, 0, para); 24 | } else { 25 | store.paragraphs.push(para); 26 | } 27 | break; 28 | } 29 | case "delete": 30 | const idx = store.paragraphs.findIndex((p) => p.key === paragraph.key); 31 | if (idx !== -1) { 32 | store.paragraphs.splice(idx, 1); 33 | } 34 | break; 35 | default: 36 | break; 37 | } 38 | }); 39 | 40 | return ( 41 | 42 | }> 43 | 添加段落 44 | 45 | }> 46 | 删除段落 47 | 48 | 49 | ); 50 | } 51 | 52 | export { getParagraphMenuOptions }; 53 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/store/global.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { observable } from "mobx"; 3 | import { getDefaultGlobalDataWidthNotations } from "../util/editor"; 4 | 5 | // 全局数据及配置,需要持久化 6 | const globalStore = observable(getDefaultGlobalDataWidthNotations()); 7 | 8 | const GlobalContext = React.createContext(globalStore); 9 | 10 | export default globalStore; 11 | export { GlobalContext }; 12 | -------------------------------------------------------------------------------- /src/store/history.js: -------------------------------------------------------------------------------- 1 | import { action, runInAction, toJS } from "mobx"; 2 | import globalStore from "./global"; 3 | 4 | const storeHistory = []; 5 | let cursor = -1; 6 | 7 | // ENHANCE: 使用性能更好的方案 8 | // 比较历史记录 9 | function _isEqual(objA, objB) { 10 | const cacheSet = new Set(); 11 | function _isCommonObject(obj) { 12 | if (typeof obj !== "object" || obj === null) { 13 | return false; 14 | } 15 | const unRegularConstructors = [Promise, Map, Set, WeakMap, WeakSet]; 16 | return !unRegularConstructors.some((c) => obj instanceof c); 17 | } 18 | function _deepEqual(obj1, obj2) { 19 | if (!_isCommonObject(obj1) || !_isCommonObject(obj2)) { 20 | return obj1 === obj2; 21 | } 22 | if (obj1 === obj2) { 23 | return true; 24 | } 25 | if (cacheSet.has(obj1) || cacheSet.has(obj2)) { 26 | return false; 27 | } 28 | cacheSet.add(obj1); 29 | cacheSet.add(obj2); 30 | const keys1 = Object.keys(obj1); 31 | const keys2 = Object.keys(obj2); 32 | if (keys1.length !== keys2.length) { 33 | return false; 34 | } 35 | return keys1.every((key) => _deepEqual(obj1[key], obj2[key])); 36 | } 37 | return _deepEqual(objA, objB); 38 | } 39 | 40 | // 在历史记录中漫游 41 | function go(span) { 42 | const newCursor = Math.min( 43 | Math.max(0, cursor + span), 44 | storeHistory.length - 1 45 | ); 46 | if (newCursor === cursor) { 47 | return; 48 | } 49 | cursor = newCursor; 50 | Object.assign(globalStore, storeHistory[newCursor]); 51 | } 52 | 53 | function clearHistory() { 54 | storeHistory.length = 0; 55 | cursor = -1; 56 | } 57 | 58 | // 包装mobx的action以实现历史记录 59 | function executeAction(actionFunc, ...args) { 60 | actionFunc.apply(this, args); 61 | const current = toJS(globalStore); 62 | if (!_isEqual(storeHistory[cursor], current)) { 63 | storeHistory[++cursor] = current; 64 | storeHistory.length = cursor + 1; 65 | if (storeHistory.length > 256) { 66 | storeHistory.splice(0, 256 - storeHistory.length); 67 | } 68 | } 69 | } 70 | function wrappedAction(...args) { 71 | let name, func; 72 | if (typeof args[0] === "function") { 73 | func = args[0]; 74 | } else { 75 | name = args[0]; 76 | func = args[1]; 77 | } 78 | const realArgs = [name, executeAction.bind(this, func)]; 79 | if (name === undefined) { 80 | realArgs.shift(); 81 | } 82 | return action.apply(this, realArgs); 83 | } 84 | function runInWrappedAction(func) { 85 | runInAction(() => { 86 | executeAction.call(this, func); 87 | }); 88 | } 89 | 90 | // 不需要记录历史记录的时候直接使用原action 91 | const unwrappedAction = action; 92 | const runInUnwrappedAction = runInAction; 93 | 94 | export { 95 | go, 96 | clearHistory, 97 | wrappedAction, 98 | runInWrappedAction, 99 | unwrappedAction, 100 | runInUnwrappedAction, 101 | }; 102 | -------------------------------------------------------------------------------- /src/store/state.js: -------------------------------------------------------------------------------- 1 | import { observable } from "mobx"; 2 | 3 | // 非持久化全局状态 4 | let globalState = observable({ 5 | // 当前选中的符号 6 | selectedNotationKey: null, 7 | // 记录上次选中的符号,之后可恢复焦点 8 | lastSelectedNotationKey: null, 9 | // 当前点击事件是否应该让符号失去焦点。应该在符号自身和菜单等点击事件中将其置为false 10 | shouldNotationBlurAfterClick: true, 11 | // 正在操作的连音线起点 12 | tieSourceKey: null, 13 | // 帮助弹窗是否可见 14 | helpDialogVisible: false, 15 | // 配置项弹窗是否可见 16 | configDialogVisible: false, 17 | // 复制剪贴的内容 18 | clipboardContent: null, 19 | }); 20 | 21 | export default globalState; 22 | -------------------------------------------------------------------------------- /src/util/dom-to-image.js: -------------------------------------------------------------------------------- 1 | // COPIED FROM: https://github.com/tsayen/dom-to-image 2 | // 由于原仓库不支持高dpi改良了一下。上游合并和可引入库依赖 3 | 4 | var util = newUtil(); 5 | var inliner = newInliner(); 6 | var fontFaces = newFontFaces(); 7 | var images = newImages(); 8 | var dpi = window.devicePixelRatio || 1; 9 | 10 | // Default impl options 11 | var defaultOptions = { 12 | // Default is to fail on error, no placeholder 13 | imagePlaceholder: undefined, 14 | // Default cache bust is false, it will use the cache 15 | cacheBust: false, 16 | }; 17 | 18 | var domtoimage = { 19 | toSvg: toSvg, 20 | toPng: toPng, 21 | toJpeg: toJpeg, 22 | toBlob: toBlob, 23 | toPixelData: toPixelData, 24 | impl: { 25 | fontFaces: fontFaces, 26 | images: images, 27 | util: util, 28 | inliner: inliner, 29 | options: {}, 30 | }, 31 | }; 32 | 33 | /** 34 | * @param {Node} node - The DOM Node object to render 35 | * @param {Object} options - Rendering options 36 | * @param {Function} options.filter - Should return true if passed node should be included in the output 37 | * (excluding node means excluding it's children as well). Not called on the root node. 38 | * @param {String} options.bgcolor - color for the background, any valid CSS color value. 39 | * @param {Number} options.width - width to be applied to node before rendering. 40 | * @param {Number} options.height - height to be applied to node before rendering. 41 | * @param {Object} options.style - an object whose properties to be copied to node's style before rendering. 42 | * @param {Number} options.quality - a Number between 0 and 1 indicating image quality (applicable to JPEG only), 43 | defaults to 1.0. 44 | * @param {String} options.imagePlaceholder - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch 45 | * @param {Boolean} options.cacheBust - set to true to cache bust by appending the time to the request url 46 | * @return {Promise} - A promise that is fulfilled with a SVG image data URL 47 | * */ 48 | function toSvg(node, options) { 49 | options = options || {}; 50 | copyOptions(options); 51 | return Promise.resolve(node) 52 | .then(function (node) { 53 | return cloneNode(node, options.filter, true); 54 | }) 55 | .then(embedFonts) 56 | .then(inlineImages) 57 | .then(applyOptions) 58 | .then(function (clone) { 59 | return makeSvgDataUri( 60 | clone, 61 | (options.width || util.width(node)) * dpi, 62 | options.height || util.height(node) * dpi 63 | ); 64 | }); 65 | 66 | function applyOptions(clone) { 67 | if (options.bgcolor) clone.style.backgroundColor = options.bgcolor; 68 | 69 | if (options.width) clone.style.width = options.width + "px"; 70 | if (options.height) clone.style.height = options.height + "px"; 71 | 72 | if (options.style) 73 | Object.keys(options.style).forEach(function (property) { 74 | clone.style[property] = options.style[property]; 75 | }); 76 | 77 | return clone; 78 | } 79 | } 80 | 81 | /** 82 | * @param {Node} node - The DOM Node object to render 83 | * @param {Object} options - Rendering options, @see {@link toSvg} 84 | * @return {Promise} - A promise that is fulfilled with a Uint8Array containing RGBA pixel data. 85 | * */ 86 | function toPixelData(node, options) { 87 | return draw(node, options || {}).then(function (canvas) { 88 | return canvas 89 | .getContext("2d") 90 | .getImageData(0, 0, util.width(node) * dpi, util.height(node) * dpi).data; 91 | }); 92 | } 93 | 94 | /** 95 | * @param {Node} node - The DOM Node object to render 96 | * @param {Object} options - Rendering options, @see {@link toSvg} 97 | * @return {Promise} - A promise that is fulfilled with a PNG image data URL 98 | * */ 99 | function toPng(node, options) { 100 | return draw(node, options || {}).then(function (canvas) { 101 | return canvas.toDataURL(); 102 | }); 103 | } 104 | 105 | /** 106 | * @param {Node} node - The DOM Node object to render 107 | * @param {Object} options - Rendering options, @see {@link toSvg} 108 | * @return {Promise} - A promise that is fulfilled with a JPEG image data URL 109 | * */ 110 | function toJpeg(node, options) { 111 | options = options || {}; 112 | return draw(node, options).then(function (canvas) { 113 | return canvas.toDataURL("image/jpeg", options.quality || 1.0); 114 | }); 115 | } 116 | 117 | /** 118 | * @param {Node} node - The DOM Node object to render 119 | * @param {Object} options - Rendering options, @see {@link toSvg} 120 | * @return {Promise} - A promise that is fulfilled with a PNG image blob 121 | * */ 122 | function toBlob(node, options) { 123 | return draw(node, options || {}).then(util.canvasToBlob); 124 | } 125 | 126 | function copyOptions(options) { 127 | // Copy options to impl options for use in impl 128 | if (typeof options.imagePlaceholder === "undefined") { 129 | domtoimage.impl.options.imagePlaceholder = defaultOptions.imagePlaceholder; 130 | } else { 131 | domtoimage.impl.options.imagePlaceholder = options.imagePlaceholder; 132 | } 133 | 134 | if (typeof options.cacheBust === "undefined") { 135 | domtoimage.impl.options.cacheBust = defaultOptions.cacheBust; 136 | } else { 137 | domtoimage.impl.options.cacheBust = options.cacheBust; 138 | } 139 | } 140 | 141 | function draw(domNode, options) { 142 | return toSvg(domNode, options) 143 | .then(util.makeImage) 144 | .then(util.delay(100)) 145 | .then(function (image) { 146 | var canvas = newCanvas(domNode); 147 | canvas.getContext("2d").drawImage(image, 0, 0); 148 | return canvas; 149 | }); 150 | 151 | function newCanvas(domNode) { 152 | var canvas = document.createElement("canvas"); 153 | var width = options.width || util.width(domNode); 154 | var height = options.height || util.height(domNode); 155 | canvas.width = width * dpi; 156 | canvas.height = height * dpi; 157 | canvas.style.width = width + "px"; 158 | canvas.style.height = height + "px"; 159 | 160 | canvas.getContext("2d").scale(dpi, dpi); 161 | if (options.bgcolor) { 162 | var ctx = canvas.getContext("2d"); 163 | ctx.fillStyle = options.bgcolor; 164 | ctx.fillRect(0, 0, canvas.width, canvas.height); 165 | } 166 | 167 | return canvas; 168 | } 169 | } 170 | 171 | function cloneNode(node, filter, root) { 172 | if (!root && filter && !filter(node)) return Promise.resolve(); 173 | 174 | return Promise.resolve(node) 175 | .then(makeNodeCopy) 176 | .then(function (clone) { 177 | return cloneChildren(node, clone, filter); 178 | }) 179 | .then(function (clone) { 180 | return processClone(node, clone); 181 | }); 182 | 183 | function makeNodeCopy(node) { 184 | if (node instanceof HTMLCanvasElement) 185 | return util.makeImage(node.toDataURL()); 186 | return node.cloneNode(false); 187 | } 188 | 189 | function cloneChildren(original, clone, filter) { 190 | var children = original.childNodes; 191 | if (children.length === 0) return Promise.resolve(clone); 192 | 193 | return cloneChildrenInOrder(clone, util.asArray(children), filter).then( 194 | function () { 195 | return clone; 196 | } 197 | ); 198 | 199 | function cloneChildrenInOrder(parent, children, filter) { 200 | var done = Promise.resolve(); 201 | children.forEach(function (child) { 202 | done = done 203 | .then(function () { 204 | return cloneNode(child, filter); 205 | }) 206 | .then(function (childClone) { 207 | if (childClone) parent.appendChild(childClone); 208 | }); 209 | }); 210 | return done; 211 | } 212 | } 213 | 214 | function processClone(original, clone) { 215 | if (!(clone instanceof Element)) return clone; 216 | 217 | return Promise.resolve() 218 | .then(cloneStyle) 219 | .then(clonePseudoElements) 220 | .then(copyUserInput) 221 | .then(fixSvg) 222 | .then(function () { 223 | return clone; 224 | }); 225 | 226 | function cloneStyle() { 227 | copyStyle(window.getComputedStyle(original), clone.style); 228 | 229 | function copyStyle(source, target) { 230 | if (source.cssText) target.cssText = source.cssText; 231 | else copyProperties(source, target); 232 | 233 | function copyProperties(source, target) { 234 | util.asArray(source).forEach(function (name) { 235 | target.setProperty( 236 | name, 237 | source.getPropertyValue(name), 238 | source.getPropertyPriority(name) 239 | ); 240 | }); 241 | } 242 | } 243 | } 244 | 245 | function clonePseudoElements() { 246 | [":before", ":after"].forEach(function (element) { 247 | clonePseudoElement(element); 248 | }); 249 | 250 | function clonePseudoElement(element) { 251 | var style = window.getComputedStyle(original, element); 252 | var content = style.getPropertyValue("content"); 253 | 254 | if (content === "" || content === "none") return; 255 | 256 | var className = util.uid(); 257 | clone.className = clone.className + " " + className; 258 | var styleElement = document.createElement("style"); 259 | styleElement.appendChild( 260 | formatPseudoElementStyle(className, element, style) 261 | ); 262 | clone.appendChild(styleElement); 263 | 264 | function formatPseudoElementStyle(className, element, style) { 265 | var selector = "." + className + ":" + element; 266 | var cssText = style.cssText 267 | ? formatCssText(style) 268 | : formatCssProperties(style); 269 | return document.createTextNode(selector + "{" + cssText + "}"); 270 | 271 | function formatCssText(style) { 272 | var content = style.getPropertyValue("content"); 273 | return style.cssText + " content: " + content + ";"; 274 | } 275 | 276 | function formatCssProperties(style) { 277 | return util.asArray(style).map(formatProperty).join("; ") + ";"; 278 | 279 | function formatProperty(name) { 280 | return ( 281 | name + 282 | ": " + 283 | style.getPropertyValue(name) + 284 | (style.getPropertyPriority(name) ? " !important" : "") 285 | ); 286 | } 287 | } 288 | } 289 | } 290 | } 291 | 292 | function copyUserInput() { 293 | if (original instanceof HTMLTextAreaElement) 294 | clone.innerHTML = original.value; 295 | if (original instanceof HTMLInputElement) 296 | clone.setAttribute("value", original.value); 297 | } 298 | 299 | function fixSvg() { 300 | if (!(clone instanceof SVGElement)) return; 301 | clone.setAttribute("xmlns", "http://www.w3.org/2000/svg"); 302 | 303 | if (!(clone instanceof SVGRectElement)) return; 304 | ["width", "height"].forEach(function (attribute) { 305 | var value = clone.getAttribute(attribute); 306 | if (!value) return; 307 | 308 | clone.style.setProperty(attribute, value); 309 | }); 310 | } 311 | } 312 | } 313 | 314 | function embedFonts(node) { 315 | return fontFaces.resolveAll().then(function (cssText) { 316 | var styleNode = document.createElement("style"); 317 | node.appendChild(styleNode); 318 | styleNode.appendChild(document.createTextNode(cssText)); 319 | return node; 320 | }); 321 | } 322 | 323 | function inlineImages(node) { 324 | return images.inlineAll(node).then(function () { 325 | return node; 326 | }); 327 | } 328 | 329 | function makeSvgDataUri(node, width, height) { 330 | return Promise.resolve(node) 331 | .then(function (node) { 332 | node.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"); 333 | return new XMLSerializer().serializeToString(node); 334 | }) 335 | .then(util.escapeXhtml) 336 | .then(function (xhtml) { 337 | return ( 338 | '' + 339 | xhtml + 340 | "" 341 | ); 342 | }) 343 | .then(function (foreignObject) { 344 | return ( 345 | '' + 350 | foreignObject + 351 | "" 352 | ); 353 | }) 354 | .then(function (svg) { 355 | return "data:image/svg+xml;charset=utf-8," + svg; 356 | }); 357 | } 358 | 359 | function newUtil() { 360 | return { 361 | escape: escape, 362 | parseExtension: parseExtension, 363 | mimeType: mimeType, 364 | dataAsUrl: dataAsUrl, 365 | isDataUrl: isDataUrl, 366 | canvasToBlob: canvasToBlob, 367 | resolveUrl: resolveUrl, 368 | getAndEncode: getAndEncode, 369 | uid: uid(), 370 | delay: delay, 371 | asArray: asArray, 372 | escapeXhtml: escapeXhtml, 373 | makeImage: makeImage, 374 | width: width, 375 | height: height, 376 | }; 377 | 378 | function mimes() { 379 | /* 380 | * Only WOFF and EOT mime types for fonts are 'real' 381 | * see http://www.iana.org/assignments/media-types/media-types.xhtml 382 | */ 383 | var WOFF = "application/font-woff"; 384 | var JPEG = "image/jpeg"; 385 | 386 | return { 387 | woff: WOFF, 388 | woff2: WOFF, 389 | ttf: "application/font-truetype", 390 | eot: "application/vnd.ms-fontobject", 391 | png: "image/png", 392 | jpg: JPEG, 393 | jpeg: JPEG, 394 | gif: "image/gif", 395 | tiff: "image/tiff", 396 | svg: "image/svg+xml", 397 | }; 398 | } 399 | 400 | function parseExtension(url) { 401 | var match = /\.([^\.\/]*?)$/g.exec(url); 402 | if (match) return match[1]; 403 | else return ""; 404 | } 405 | 406 | function mimeType(url) { 407 | var extension = parseExtension(url).toLowerCase(); 408 | return mimes()[extension] || ""; 409 | } 410 | 411 | function isDataUrl(url) { 412 | return url.search(/^(data:)/) !== -1; 413 | } 414 | 415 | function toBlob(canvas) { 416 | return new Promise(function (resolve) { 417 | var binaryString = window.atob(canvas.toDataURL().split(",")[1]); 418 | var length = binaryString.length; 419 | var binaryArray = new Uint8Array(length); 420 | 421 | for (var i = 0; i < length; i++) 422 | binaryArray[i] = binaryString.charCodeAt(i); 423 | 424 | resolve( 425 | new Blob([binaryArray], { 426 | type: "image/png", 427 | }) 428 | ); 429 | }); 430 | } 431 | 432 | function canvasToBlob(canvas) { 433 | if (canvas.toBlob) 434 | return new Promise(function (resolve) { 435 | canvas.toBlob(resolve); 436 | }); 437 | 438 | return toBlob(canvas); 439 | } 440 | 441 | function resolveUrl(url, baseUrl) { 442 | var doc = document.implementation.createHTMLDocument(); 443 | var base = doc.createElement("base"); 444 | doc.head.appendChild(base); 445 | var a = doc.createElement("a"); 446 | doc.body.appendChild(a); 447 | base.href = baseUrl; 448 | a.href = url; 449 | return a.href; 450 | } 451 | 452 | function uid() { 453 | var index = 0; 454 | 455 | return function () { 456 | return "u" + fourRandomChars() + index++; 457 | 458 | function fourRandomChars() { 459 | /* see http://stackoverflow.com/a/6248722/2519373 */ 460 | return ( 461 | "0000" + ((Math.random() * Math.pow(36, 4)) << 0).toString(36) 462 | ).slice(-4); 463 | } 464 | }; 465 | } 466 | 467 | function makeImage(uri) { 468 | return new Promise(function (resolve, reject) { 469 | var image = new Image(); 470 | image.onload = function () { 471 | resolve(image); 472 | }; 473 | image.onerror = reject; 474 | image.src = uri; 475 | }); 476 | } 477 | 478 | function getAndEncode(url) { 479 | var TIMEOUT = 30000; 480 | if (domtoimage.impl.options.cacheBust) { 481 | // Cache bypass so we dont have CORS issues with cached images 482 | // Source: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache 483 | url += (/\?/.test(url) ? "&" : "?") + new Date().getTime(); 484 | } 485 | 486 | return new Promise(function (resolve) { 487 | var request = new XMLHttpRequest(); 488 | 489 | request.onreadystatechange = done; 490 | request.ontimeout = timeout; 491 | request.responseType = "blob"; 492 | request.timeout = TIMEOUT; 493 | request.open("GET", url, true); 494 | request.send(); 495 | 496 | var placeholder; 497 | if (domtoimage.impl.options.imagePlaceholder) { 498 | var split = domtoimage.impl.options.imagePlaceholder.split(/,/); 499 | if (split && split[1]) { 500 | placeholder = split[1]; 501 | } 502 | } 503 | 504 | function done() { 505 | if (request.readyState !== 4) return; 506 | 507 | if (request.status !== 200) { 508 | if (placeholder) { 509 | resolve(placeholder); 510 | } else { 511 | fail( 512 | "cannot fetch resource: " + url + ", status: " + request.status 513 | ); 514 | } 515 | 516 | return; 517 | } 518 | 519 | var encoder = new FileReader(); 520 | encoder.onloadend = function () { 521 | var content = encoder.result.split(/,/)[1]; 522 | resolve(content); 523 | }; 524 | encoder.readAsDataURL(request.response); 525 | } 526 | 527 | function timeout() { 528 | if (placeholder) { 529 | resolve(placeholder); 530 | } else { 531 | fail( 532 | "timeout of " + 533 | TIMEOUT + 534 | "ms occured while fetching resource: " + 535 | url 536 | ); 537 | } 538 | } 539 | 540 | function fail(message) { 541 | console.error(message); 542 | resolve(""); 543 | } 544 | }); 545 | } 546 | 547 | function dataAsUrl(content, type) { 548 | return "data:" + type + ";base64," + content; 549 | } 550 | 551 | function escape(string) { 552 | return string.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1"); 553 | } 554 | 555 | function delay(ms) { 556 | return function (arg) { 557 | return new Promise(function (resolve) { 558 | setTimeout(function () { 559 | resolve(arg); 560 | }, ms); 561 | }); 562 | }; 563 | } 564 | 565 | function asArray(arrayLike) { 566 | var array = []; 567 | var length = arrayLike.length; 568 | for (var i = 0; i < length; i++) array.push(arrayLike[i]); 569 | return array; 570 | } 571 | 572 | function escapeXhtml(string) { 573 | return string.replace(/#/g, "%23").replace(/\n/g, "%0A"); 574 | } 575 | 576 | function width(node) { 577 | var leftBorder = px(node, "border-left-width"); 578 | var rightBorder = px(node, "border-right-width"); 579 | return node.scrollWidth + leftBorder + rightBorder; 580 | } 581 | 582 | function height(node) { 583 | var topBorder = px(node, "border-top-width"); 584 | var bottomBorder = px(node, "border-bottom-width"); 585 | return node.scrollHeight + topBorder + bottomBorder; 586 | } 587 | 588 | function px(node, styleProperty) { 589 | var value = window.getComputedStyle(node).getPropertyValue(styleProperty); 590 | return parseFloat(value.replace("px", "")); 591 | } 592 | } 593 | 594 | function newInliner() { 595 | var URL_REGEX = /url\(['"]?([^'"]+?)['"]?\)/g; 596 | 597 | return { 598 | inlineAll: inlineAll, 599 | shouldProcess: shouldProcess, 600 | impl: { 601 | readUrls: readUrls, 602 | inline: inline, 603 | }, 604 | }; 605 | 606 | function shouldProcess(string) { 607 | return string.search(URL_REGEX) !== -1; 608 | } 609 | 610 | function readUrls(string) { 611 | var result = []; 612 | var match; 613 | while ((match = URL_REGEX.exec(string)) !== null) { 614 | result.push(match[1]); 615 | } 616 | return result.filter(function (url) { 617 | return !util.isDataUrl(url); 618 | }); 619 | } 620 | 621 | function inline(string, url, baseUrl, get) { 622 | return Promise.resolve(url) 623 | .then(function (url) { 624 | return baseUrl ? util.resolveUrl(url, baseUrl) : url; 625 | }) 626 | .then(get || util.getAndEncode) 627 | .then(function (data) { 628 | return util.dataAsUrl(data, util.mimeType(url)); 629 | }) 630 | .then(function (dataUrl) { 631 | return string.replace(urlAsRegex(url), "$1" + dataUrl + "$3"); 632 | }); 633 | 634 | function urlAsRegex(url) { 635 | return new RegExp( 636 | "(url\\(['\"]?)(" + util.escape(url) + ")(['\"]?\\))", 637 | "g" 638 | ); 639 | } 640 | } 641 | 642 | function inlineAll(string, baseUrl, get) { 643 | if (nothingToInline()) return Promise.resolve(string); 644 | 645 | return Promise.resolve(string) 646 | .then(readUrls) 647 | .then(function (urls) { 648 | var done = Promise.resolve(string); 649 | urls.forEach(function (url) { 650 | done = done.then(function (string) { 651 | return inline(string, url, baseUrl, get); 652 | }); 653 | }); 654 | return done; 655 | }); 656 | 657 | function nothingToInline() { 658 | return !shouldProcess(string); 659 | } 660 | } 661 | } 662 | 663 | function newFontFaces() { 664 | return { 665 | resolveAll: resolveAll, 666 | impl: { 667 | readAll: readAll, 668 | }, 669 | }; 670 | 671 | function resolveAll() { 672 | return readAll(document) 673 | .then(function (webFonts) { 674 | return Promise.all( 675 | webFonts.map(function (webFont) { 676 | return webFont.resolve(); 677 | }) 678 | ); 679 | }) 680 | .then(function (cssStrings) { 681 | return cssStrings.join("\n"); 682 | }); 683 | } 684 | 685 | function readAll() { 686 | return Promise.resolve(util.asArray(document.styleSheets)) 687 | .then(getCssRules) 688 | .then(selectWebFontRules) 689 | .then(function (rules) { 690 | return rules.map(newWebFont); 691 | }); 692 | 693 | function selectWebFontRules(cssRules) { 694 | return cssRules 695 | .filter(function (rule) { 696 | return rule.type === CSSRule.FONT_FACE_RULE; 697 | }) 698 | .filter(function (rule) { 699 | return inliner.shouldProcess(rule.style.getPropertyValue("src")); 700 | }); 701 | } 702 | 703 | function getCssRules(styleSheets) { 704 | var cssRules = []; 705 | styleSheets.forEach(function (sheet) { 706 | try { 707 | util 708 | .asArray(sheet.cssRules || []) 709 | .forEach(cssRules.push.bind(cssRules)); 710 | } catch (e) { 711 | console.log( 712 | "Error while reading CSS rules from " + sheet.href, 713 | e.toString() 714 | ); 715 | } 716 | }); 717 | return cssRules; 718 | } 719 | 720 | function newWebFont(webFontRule) { 721 | return { 722 | resolve: function resolve() { 723 | var baseUrl = (webFontRule.parentStyleSheet || {}).href; 724 | return inliner.inlineAll(webFontRule.cssText, baseUrl); 725 | }, 726 | src: function () { 727 | return webFontRule.style.getPropertyValue("src"); 728 | }, 729 | }; 730 | } 731 | } 732 | } 733 | 734 | function newImages() { 735 | return { 736 | inlineAll: inlineAll, 737 | impl: { 738 | newImage: newImage, 739 | }, 740 | }; 741 | 742 | function newImage(element) { 743 | return { 744 | inline: inline, 745 | }; 746 | 747 | function inline(get) { 748 | if (util.isDataUrl(element.src)) return Promise.resolve(); 749 | 750 | return Promise.resolve(element.src) 751 | .then(get || util.getAndEncode) 752 | .then(function (data) { 753 | return util.dataAsUrl(data, util.mimeType(element.src)); 754 | }) 755 | .then(function (dataUrl) { 756 | return new Promise(function (resolve, reject) { 757 | element.onload = resolve; 758 | element.onerror = reject; 759 | element.src = dataUrl; 760 | }); 761 | }); 762 | } 763 | } 764 | 765 | function inlineAll(node) { 766 | if (!(node instanceof Element)) return Promise.resolve(node); 767 | 768 | return inlineBackground(node).then(function () { 769 | if (node instanceof HTMLImageElement) return newImage(node).inline(); 770 | else 771 | return Promise.all( 772 | util.asArray(node.childNodes).map(function (child) { 773 | return inlineAll(child); 774 | }) 775 | ); 776 | }); 777 | 778 | function inlineBackground(node) { 779 | var background = node.style.getPropertyValue("background"); 780 | 781 | if (!background) return Promise.resolve(node); 782 | 783 | return inliner 784 | .inlineAll(background) 785 | .then(function (inlined) { 786 | node.style.setProperty( 787 | "background", 788 | inlined, 789 | node.style.getPropertyPriority("background") 790 | ); 791 | }) 792 | .then(function () { 793 | return node; 794 | }); 795 | } 796 | } 797 | } 798 | 799 | export default domtoimage; 800 | -------------------------------------------------------------------------------- /src/util/editor.js: -------------------------------------------------------------------------------- 1 | import { remove, transaction } from "mobx"; 2 | import state from "../store/state"; 3 | import store from "../store/global"; 4 | import { clearHistory, unwrappedAction } from "../store/history"; 5 | import { createParagraphWithNotations } from "../util/paragraph"; 6 | import { VERSION } from "./version"; 7 | 8 | const initialData = { 9 | version: VERSION, 10 | canvasWidth: 896, 11 | canvasHeight: 1024, 12 | defaultFontSize: 16, 13 | defaultSubFontSize: 12, 14 | title: "无标题", 15 | tone: "C", 16 | marginHorizontal: 64, 17 | marginTop: 32, 18 | gapAfterTitle: 16, 19 | gapAfterHeader: 32, 20 | gapBetweenParagraph: 32, 21 | gapBetweenNotation: 16, 22 | beat: [4, 4], 23 | speed: 75, 24 | authors: ["佚名 作词", "简谱编辑器 制谱"], 25 | notations: [], 26 | }; 27 | 28 | function getDefaultGlobalData() { 29 | return JSON.parse(JSON.stringify(initialData)); 30 | } 31 | function getDefaultGlobalDataWidthNotations() { 32 | const d = getDefaultGlobalData(); 33 | d.paragraphs = [createParagraphWithNotations()]; 34 | return d; 35 | } 36 | 37 | // 根据key查找符号在全局记录中的位置 38 | function findParagraphAndNotation(key) { 39 | let res = {}; 40 | const paras = store.paragraphs || []; 41 | paras.some((p, i) => { 42 | const notationIndex = (p.notations || []).findIndex((n) => n.key === key); 43 | if (notationIndex !== -1) { 44 | res.notation = p.notations[notationIndex]; 45 | res.notationIndex = notationIndex; 46 | res.paragraph = p; 47 | res.paragraphIndex = i; 48 | return true; 49 | } 50 | return false; 51 | }); 52 | return res; 53 | } 54 | 55 | const resetGlobalData = unwrappedAction((globalData) => { 56 | if (!globalData) { 57 | globalData = getDefaultGlobalDataWidthNotations(); 58 | } 59 | state.lastSelectedNotationKey = state.selectedNotationKey = state.tieSourceKey = null; 60 | clearHistory(); 61 | transaction(() => { 62 | for (const key of Object.keys(store)) { 63 | remove(store, key); 64 | } 65 | Object.assign(store, globalData); 66 | }); 67 | }); 68 | 69 | export { 70 | getDefaultGlobalData, 71 | findParagraphAndNotation, 72 | getDefaultGlobalDataWidthNotations, 73 | resetGlobalData, 74 | }; 75 | -------------------------------------------------------------------------------- /src/util/file.js: -------------------------------------------------------------------------------- 1 | import { message } from "antd"; 2 | import { toJS } from "mobx"; 3 | import store from "../store/global"; 4 | import domtoimage from "./dom-to-image"; 5 | import { VERSION } from "./version"; 6 | import { resetGlobalData } from "./editor"; 7 | 8 | function read(file) { 9 | return new Promise((resolve, reject) => { 10 | const reader = new FileReader(); 11 | reader.readAsText(file, "utf8"); 12 | reader.onloadend = () => { 13 | resolve(JSON.parse(reader.result)); 14 | }; 15 | }); 16 | } 17 | 18 | async function loadFile(file) { 19 | const data = await read(file); 20 | if (!(data.version <= VERSION)) { 21 | message.error("不支持的文件格式,请使用最新版本"); 22 | return; 23 | } 24 | resetGlobalData(data); 25 | } 26 | 27 | function saveFile() { 28 | const data = new Blob([JSON.stringify(toJS(store))], { 29 | type: "application/json", 30 | }); 31 | const downloadLink = document.createElement("a"); 32 | downloadLink.download = (store.title || "未标题") + ".json"; 33 | downloadLink.href = URL.createObjectURL(data); 34 | downloadLink.click(); 35 | URL.revokeObjectURL(downloadLink.href); 36 | } 37 | 38 | function exportFile() { 39 | domtoimage 40 | .toPng(document.querySelector("#temp_svg"), { bgcolor: "white" }) 41 | .then((dataUrl) => { 42 | const downloadLink = document.createElement("a"); 43 | downloadLink.download = (store.title || "未标题") + ".png"; 44 | downloadLink.href = dataUrl; 45 | downloadLink.click(); 46 | }); 47 | } 48 | 49 | export { saveFile, loadFile, exportFile }; 50 | -------------------------------------------------------------------------------- /src/util/html-escape.js: -------------------------------------------------------------------------------- 1 | // 为了解决svg text不渲染连续空格,对html转义并替换空格为  2 | export default function escapeHtml(text) { 3 | const span = document.createElement("span"); 4 | span.appendChild(document.createTextNode(text)); 5 | return span.innerHTML.replace(/\s/g, " "); 6 | } 7 | -------------------------------------------------------------------------------- /src/util/load-example.js: -------------------------------------------------------------------------------- 1 | import { resetGlobalData } from "./editor"; 2 | 3 | async function loadExample() { 4 | const regex = /(\?|&)loadExample(&|$)/; 5 | if (regex.test(window.location.search)) { 6 | const data = await import("../example/烟雨.json"); 7 | resetGlobalData(data.default); 8 | } 9 | } 10 | 11 | export { loadExample }; 12 | -------------------------------------------------------------------------------- /src/util/notation.js: -------------------------------------------------------------------------------- 1 | import { message } from "antd"; 2 | import { toJS } from "mobx"; 3 | import state from "../store/state"; 4 | import { wrappedAction } from "../store/history"; 5 | import { findParagraphAndNotation } from "./editor"; 6 | 7 | const notations = { 8 | zero: "0", 9 | do: "1", 10 | re: "2", 11 | mi: "3", 12 | fa: "4", 13 | sol: "5", 14 | la: "6", 15 | si: "7", 16 | extend: "─", 17 | separator: "│", 18 | crackerOpen: "(", 19 | crackerClose: ")", 20 | }; 21 | const notes = [ 22 | notations.zero, 23 | notations.do, 24 | notations.re, 25 | notations.mi, 26 | notations.fa, 27 | notations.sol, 28 | notations.la, 29 | notations.si, 30 | ]; 31 | const separators = ["│", "‖"]; 32 | 33 | function isNote(notationOrNote) { 34 | return notes.includes(notationOrNote?.note || notationOrNote); 35 | } 36 | function isPauseNote(notationOrNote) { 37 | return notations.zero === (notationOrNote?.note || notationOrNote); 38 | } 39 | function isSeparator(notationOrNote) { 40 | return separators.includes(notationOrNote?.note || notationOrNote); 41 | } 42 | // 创建符号 43 | function createNotation(initial) { 44 | const n = { 45 | type: "notation", 46 | key: `n_${String(Math.random())}`, 47 | note: "0", 48 | octave: 0, 49 | dotted: false, 50 | underline: 0, 51 | breakUnderline: false, 52 | prefixSups: [], 53 | topDecorators: [], 54 | tieTo: null, 55 | }; 56 | if (initial) { 57 | Object.assign(n, initial); 58 | } 59 | return n; 60 | } 61 | function cloneNotation(notation) { 62 | const origin = JSON.parse(JSON.stringify(toJS(notation))); 63 | delete origin.key; 64 | const n = createNotation(origin); 65 | return n; 66 | } 67 | 68 | // 放置连音线 69 | const placeTie = wrappedAction((notation) => { 70 | if (state.tieSourceKey) { 71 | // 处理连音线 72 | if (state.tieSourceKey === notation.key) { 73 | state.tieSourceKey = null; 74 | // NOTICE: 如果要添加其他逻辑注意这里的return 75 | return; 76 | } 77 | const { 78 | notation: sourceNotation, 79 | paragraph: sourceParagraph, 80 | } = findParagraphAndNotation(state.tieSourceKey); 81 | if (!sourceNotation) { 82 | state.tieSourceKey = null; 83 | return; 84 | } 85 | if (!sourceParagraph.notations.includes(notation)) { 86 | message.warn("只允许相同段落的音符相连!"); 87 | } else if (!isNote(notation)) { 88 | message.warn("只允许在音符上添加连音线!"); 89 | } else { 90 | sourceNotation.tieTo = notation.key; 91 | notation.tieTo = sourceNotation.key; 92 | } 93 | state.tieSourceKey = null; 94 | } 95 | }); 96 | 97 | export { 98 | notations, 99 | isNote, 100 | isPauseNote, 101 | isSeparator, 102 | createNotation, 103 | cloneNotation, 104 | placeTie, 105 | }; 106 | -------------------------------------------------------------------------------- /src/util/paragraph.js: -------------------------------------------------------------------------------- 1 | import { toJS } from "mobx"; 2 | import { cloneNotation, createNotation, notations as N } from "./notation"; 3 | 4 | // 新建段落 5 | function createParagraph(initial) { 6 | const p = { 7 | type: "paragraph", 8 | key: `p_${String(Math.random())}`, 9 | // 符号列表 10 | notations: [], 11 | // 是否两端对齐 12 | alignJustify: null, 13 | }; 14 | if (initial) { 15 | Object.assign(p, initial); 16 | } 17 | return p; 18 | } 19 | function createParagraphWithNotations() { 20 | return createParagraph({ 21 | notations: [ 22 | createNotation({ note: "0" }), 23 | createNotation({ note: "0" }), 24 | createNotation({ note: "0" }), 25 | createNotation({ note: "0" }), 26 | createNotation({ note: N.separator }), 27 | ], 28 | }); 29 | } 30 | function cloneParagraph(paragraph) { 31 | const origin = JSON.parse(JSON.stringify(toJS(paragraph))); 32 | delete origin.key; 33 | origin.notations = paragraph.notations.map((n) => cloneNotation(n)); 34 | return createParagraph(origin); 35 | } 36 | 37 | export { createParagraph, createParagraphWithNotations, cloneParagraph }; 38 | -------------------------------------------------------------------------------- /src/util/placement.js: -------------------------------------------------------------------------------- 1 | import { observable } from "mobx"; 2 | import store from "../store/global"; 3 | 4 | // ENHANCE: 通过mobx的computed机制缓存一些计算值 5 | 6 | let canvas, context2D, defaultFontFamily; 7 | let measureSvgEl, measureTextEl; 8 | 9 | function _initializeCanvas(fontSize) { 10 | if (!canvas) { 11 | canvas = document.createElement("canvas"); 12 | context2D = canvas.getContext("2d"); 13 | defaultFontFamily = window.getComputedStyle(document.body).fontFamily; 14 | } 15 | context2D.font = `${ 16 | fontSize || store.defaultFontSize 17 | }px ${defaultFontFamily}`; 18 | } 19 | 20 | function _calcTextWidth(fontSize, text) { 21 | _initializeCanvas(fontSize); 22 | return context2D.measureText(text).width; 23 | } 24 | 25 | function _calcTextBox(fontSize, text) { 26 | if (!measureSvgEl) { 27 | measureSvgEl = document.createElementNS( 28 | "http://www.w3.org/2000/svg", 29 | "svg" 30 | ); 31 | measureTextEl = document.createElementNS( 32 | "http://www.w3.org/2000/svg", 33 | "text" 34 | ); 35 | measureTextEl.style.visibility = "hidden"; 36 | measureSvgEl.appendChild(measureTextEl); 37 | document.body.appendChild(measureSvgEl); 38 | } 39 | measureTextEl.style.fontSize = fontSize + "px"; 40 | measureTextEl.textContent = text; 41 | return measureTextEl.getBBox(); 42 | } 43 | 44 | // 判断段落中的音符是否有连音线 45 | function _hasTie(paragraph) { 46 | const notations = paragraph?.notations || []; 47 | return notations.some( 48 | (n, i) => n.tieTo && notations.findIndex((nn) => nn.key === n.tieTo) > i 49 | ); 50 | } 51 | 52 | const placement = observable({ 53 | get maxContentWidth() { 54 | return Math.max(store.canvasWidth - store.marginHorizontal * 2, 0); 55 | }, 56 | get minTieHeight() { 57 | return 8; 58 | }, 59 | get maxTieHeight() { 60 | return 20; 61 | }, 62 | get maxTieBezierOffset() { 63 | return 25; 64 | }, 65 | get underlineStepOffsetY() { 66 | return 3; 67 | }, 68 | get underlineInitialOffsetY() { 69 | return this.xHeight / 2 - 3; 70 | }, 71 | get octaveStepOffsetY() { 72 | return 5; 73 | }, 74 | get octaveInitialOffsetAbove() { 75 | return placement.xHeight / 2 + 2; 76 | }, 77 | get octaveInitialOffsetBelow() { 78 | return placement.xHeight / 2 - 2; 79 | }, 80 | get titleOffsetY() { 81 | const titleHeight = 32; 82 | return store.marginTop + titleHeight + store.gapAfterTitle; 83 | }, 84 | get headerOffsetY() { 85 | const leftInfoBlockHeight = this.xHeight * 2; 86 | const titleOffset = this.titleOffsetY; 87 | const leftInfoBlockOffset = titleOffset + leftInfoBlockHeight; 88 | const rightInfoBlockOffset = 89 | titleOffset + this.xHeight * store.authors.length; 90 | return ( 91 | Math.max(titleOffset, leftInfoBlockOffset, rightInfoBlockOffset) + 92 | store.gapAfterHeader 93 | ); 94 | }, 95 | get baseFontData() { 96 | const data = _calcTextBox(store.defaultFontSize, "x"); 97 | return { 98 | xWidth: data.width, 99 | xHeight: data.height, 100 | }; 101 | }, 102 | get baseSubFontData() { 103 | const data = _calcTextBox(store.defaultSubFontSize, "x"); 104 | return { 105 | xWidth: data.width, 106 | xHeight: data.height, 107 | }; 108 | }, 109 | get xHeight() { 110 | return this.baseFontData.xHeight; 111 | }, 112 | get xWidth() { 113 | return this.baseFontData.xWidth; 114 | }, 115 | get subXHeight() { 116 | return this.baseSubFontData.xHeight; 117 | }, 118 | get subXWidth() { 119 | return this.baseSubFontData.xWidth; 120 | }, 121 | }); 122 | 123 | const calcTextWidth = _calcTextWidth.bind(null, store.defaultFontSize); 124 | const calcSubTextWidth = _calcTextWidth.bind(null, store.defaultSubFontSize); 125 | 126 | // 计算段落占的空间高 127 | function calcParagraphHeight(paragraph) { 128 | return calcParagraphContentHeight(paragraph) + store.gapBetweenParagraph; 129 | } 130 | // 计算段落内容的高度 131 | function calcParagraphContentHeight(paragraph) { 132 | const notations = paragraph.notations || []; 133 | if (notations.length === 0) { 134 | return placement.xHeight; 135 | } 136 | let tieHeight = 0; 137 | if (_hasTie(paragraph)) { 138 | // FIXME: 应该计算连音线高度 139 | // tieHeight = placement.maxTieHeight; 140 | } 141 | // 段落高度不是最高的音符的高度,而是上边偏移最大的音符的上部分偏移量+下边偏移最 142 | // 大的音符的下部分偏移量 143 | const noteHeightMap = notations.map((n) => calcNotationHeight(n)); 144 | const aboveOffsetMap = notations.map((n) => calcNotationAboveOffset(n)); 145 | const belowOffsetMap = noteHeightMap.map((v, i) => v - aboveOffsetMap[i]); 146 | const maxNoteOffset = 147 | Math.max(...belowOffsetMap) + Math.max(...aboveOffsetMap); 148 | return tieHeight + maxNoteOffset; 149 | } 150 | 151 | // 计算一行中所有音符的宽度和 152 | function calcParagraphWidth(paragraph) { 153 | const notations = paragraph.notations || []; 154 | if (notations.length === 0) { 155 | return 0; 156 | } 157 | return ( 158 | notations 159 | .map((n) => calcNotationWidth(n)) 160 | .reduce((prev, curr) => prev + curr, 0) - store.gapBetweenNotation 161 | ); 162 | } 163 | 164 | // 计算段落中的音符中心以上偏移量的最大值 165 | function calcParagraphAboveOffset(paragraph) { 166 | const notations = paragraph.notations || []; 167 | if (notations.length === 0) { 168 | return placement.xHeight / 2; 169 | } 170 | let tieHeight = 0; 171 | if (_hasTie(paragraph)) { 172 | // FIXME: 应该计算连音线高度 173 | // tieHeight = placement.maxTieHeight; 174 | } 175 | const notationOffset = notations 176 | .map((n) => calcNotationAboveOffset(n)) 177 | .reduce((prev, curr) => Math.max(prev, curr), placement.xHeight / 2); 178 | return notationOffset + tieHeight; 179 | } 180 | 181 | // 计算音符中心位置左边的宽度 182 | function calcNotationPrefixOffset(notation) { 183 | const prefixes = notation.prefixSups || []; 184 | return calcSubTextWidth(prefixes.join("")) + prefixes.length * 2; 185 | } 186 | 187 | // 计算音符中心位置以上的高度 188 | function calcNotationAboveOffset(notation) { 189 | const offsets = [0]; 190 | const noteOffsetTop = placement.xHeight / 2; 191 | offsets.push(noteOffsetTop); 192 | let octaveOffset = 0; 193 | if (notation.octave > 0) { 194 | octaveOffset = 195 | placement.octaveInitialOffsetAbove + 196 | placement.octaveStepOffsetY * Math.abs(notation.octave); 197 | } 198 | offsets.push(octaveOffset); 199 | const topDecoratorOffset = 200 | octaveOffset + 201 | placement.subXHeight * (notation.topDecorators?.length | 0) - 202 | 2; 203 | offsets.push(topDecoratorOffset); 204 | return Math.max(...offsets); 205 | } 206 | 207 | // 计算音符总体宽度 208 | function calcNotationWidth(notation) { 209 | const noteWidth = calcTextWidth(notation.note) + store.gapBetweenNotation; 210 | const dotWidth = 8; 211 | const prefixWidth = calcNotationPrefixOffset(notation); 212 | return prefixWidth + noteWidth + (notation.dotted ? dotWidth : 0); 213 | } 214 | 215 | // 计算音符自身高度,包含其装饰符,八度点等,不包括连音符 216 | function calcNotationHeight(notation) { 217 | // 以音符中心为基准线,分别计算正方向和负方向的最大偏移,二者之和为音符自身高度 218 | // 0保证取正方向偏移最值时不会取到负值,负方向亦然 219 | const offsets = [0]; 220 | let noteOffsetTop = placement.xHeight / 2, 221 | noteOffsetBottom = -placement.xHeight / 2, 222 | octaveOffsetY, 223 | supOffsetY; 224 | offsets.push(noteOffsetTop, noteOffsetBottom); 225 | const oc = notation.octave | 0; 226 | const underlineOffsetY = 227 | notation.underline > 0 228 | ? placement.underlineInitialOffsetY + 229 | placement.underlineStepOffsetY * (notation.underline | 0) 230 | : 0; 231 | offsets.push(underlineOffsetY); 232 | const octaveInitialOffsetY = 233 | notation.octave > 0 234 | ? -placement.octaveInitialOffsetAbove 235 | : placement.octaveInitialOffsetBelow + underlineOffsetY; 236 | if (oc > 0) { 237 | octaveOffsetY = octaveInitialOffsetY - 5 * Math.abs(oc); 238 | } else if (oc < 0) { 239 | octaveOffsetY = octaveInitialOffsetY + 5 * Math.abs(oc); 240 | } else { 241 | octaveOffsetY = 0; 242 | } 243 | offsets.push(octaveOffsetY); 244 | // 前置上标的top偏移,其定位基准为字符中心,y位置为(-P.subXHeight + 4),再 245 | // 加上基准以上的半个字符的高度,得到前置上标的最大纵向偏移 246 | supOffsetY = notation.prefixSups?.length ? placement.subXHeight - 4 : 0; 247 | offsets.push(supOffsetY); 248 | // 顶部装饰符在高八度点之上 249 | let octaveOffsetYAbove = 0; 250 | if (notation.octave > 0) { 251 | octaveOffsetYAbove = 252 | placement.octaveInitialOffsetAbove - 253 | placement.octaveStepOffsetY * notation.octave; 254 | } 255 | const topDecoratorOffset = 256 | octaveOffsetYAbove - 257 | placement.subXHeight * (notation.topDecorators?.length | 0) - 258 | 2; 259 | offsets.push(topDecoratorOffset); 260 | const maxOffsetY = Math.max(...offsets); 261 | const minOffsetY = Math.min(...offsets); 262 | return maxOffsetY - minOffsetY; 263 | } 264 | 265 | export default placement; 266 | export { 267 | calcNotationWidth, 268 | calcNotationPrefixOffset, 269 | calcNotationAboveOffset, 270 | calcParagraphWidth, 271 | calcParagraphHeight, 272 | calcParagraphContentHeight, 273 | calcParagraphAboveOffset, 274 | calcTextWidth, 275 | calcSubTextWidth, 276 | }; 277 | -------------------------------------------------------------------------------- /src/util/tone-convert.js: -------------------------------------------------------------------------------- 1 | import store from "../store/global"; 2 | import { wrappedAction } from "../store/history"; 3 | import { isNote, isPauseNote } from "./notation"; 4 | 5 | // 音符到音数 6 | const noteToLevelMap = { 7 | 1: 0, 8 | 2: 2, 9 | 3: 4, 10 | 4: 5, 11 | 5: 7, 12 | 6: 9, 13 | 7: 11, 14 | }; 15 | // 音数到音符 16 | const levelToNoteMap = { 17 | 0: 1, 18 | 1: 1, 19 | 2: 2, 20 | 3: 2, 21 | 4: 3, 22 | 5: 4, 23 | 6: 4, 24 | 7: 5, 25 | 8: 5, 26 | 9: 6, 27 | 10: 7, 28 | 11: 7, 29 | }; 30 | // 升降到音数 31 | const bumpSharpToLevelMap = { 32 | "♭": -1, 33 | "♯": 1, 34 | }; 35 | // 音数到升降 36 | const levelToBumpSharpMap = { 37 | 1: "♯", 38 | 3: "♯", 39 | 6: "♯", 40 | 8: "♯", 41 | 10: "♭", 42 | }; 43 | 44 | const toneToLevelMap = { 45 | C: 0, 46 | D: 2, 47 | E: 4, 48 | F: 5, 49 | G: 7, 50 | A: 9, 51 | B: 11, 52 | }; 53 | 54 | /** 55 | * 整体转调 56 | * @param {number} deltaVolume 要调整的音数 57 | */ 58 | const convertTone = wrappedAction(function (deltaVolume) { 59 | deltaVolume = deltaVolume | 0; 60 | store.paragraphs.forEach((p) => { 61 | p.notations.forEach((n) => { 62 | if (isNote(n) && !isPauseNote(n)) { 63 | n.octave += Math.trunc(deltaVolume / 12); 64 | let newLevel = 65 | noteToLevelMap[n.note] + 66 | (deltaVolume % 12) + 67 | (n.prefixSups || []).reduce( 68 | (prev, next) => prev + (bumpSharpToLevelMap[next] | 0), 69 | 0 70 | ); 71 | if (newLevel >= 12) { 72 | n.octave += 1; 73 | newLevel -= 12; 74 | } else if (newLevel < 0) { 75 | n.octave -= 1; 76 | newLevel += 12; 77 | } 78 | n.note = String(levelToNoteMap[newLevel]); 79 | n.prefixSups = (n.prefixSups || []).filter( 80 | (c) => c !== "♯" && c !== "♭" 81 | ); 82 | if (levelToBumpSharpMap[newLevel]) { 83 | n.prefixSups.unshift(levelToBumpSharpMap[newLevel]); 84 | } 85 | } 86 | }); 87 | }); 88 | }); 89 | 90 | // 转到1 = * 91 | const convertToneTo = wrappedAction((destTone) => { 92 | let deltaVolume = -( 93 | toneToLevelMap[destTone.split("").at(-1)] - 94 | toneToLevelMap[store.tone.split("").at(-1)] 95 | ); 96 | if (destTone.startsWith("♭") || store.tone.startsWith("♯")) { 97 | deltaVolume -= 1; 98 | } 99 | if (destTone.startsWith("♯") || store.tone.startsWith("♭")) { 100 | deltaVolume += 1; 101 | } 102 | convertTone(deltaVolume); 103 | store.tone = destTone; 104 | }); 105 | 106 | export { convertTone, convertToneTo }; 107 | -------------------------------------------------------------------------------- /src/util/version.js: -------------------------------------------------------------------------------- 1 | const VERSION = 1; 2 | 3 | export { VERSION }; 4 | -------------------------------------------------------------------------------- /src/view/Canvas/index.js: -------------------------------------------------------------------------------- 1 | import { observer } from "mobx-react-lite"; 2 | import store from "../../store/global"; 3 | import Styles from "./index.module.css"; 4 | 5 | // ENHANCE: 增加整体缩放能力 6 | 7 | // FIXME: 修改获取svg元素的方式 8 | function Canvas({ children, ...props }) { 9 | return ( 10 | ev.preventDefault()} 18 | {...props} 19 | > 20 | {children} 21 | 22 | ); 23 | } 24 | 25 | export default observer(Canvas); 26 | -------------------------------------------------------------------------------- /src/view/Canvas/index.module.css: -------------------------------------------------------------------------------- 1 | .svg { 2 | border: 1px solid ghostwhite; 3 | box-shadow: ghostwhite 0px 0px 10px; 4 | font-size: 16px; 5 | } 6 | .svg :global(text) { 7 | user-select: none; 8 | } -------------------------------------------------------------------------------- /src/view/ConfigModal/index.js: -------------------------------------------------------------------------------- 1 | import { Button, Form, Input, Modal } from "antd"; 2 | import { observer } from "mobx-react-lite"; 3 | import { useCallback } from "react"; 4 | import store from "../../store/global"; 5 | import { getDefaultGlobalData } from "../../util/editor"; 6 | import { unwrappedAction } from "../../store/history"; 7 | 8 | const ImmediateNumberConfigInput = observer(({ propertyName, ...props }) => { 9 | // ENHANCE: 防抖处理 10 | const handleChange = unwrappedAction((ev) => { 11 | const v = Number(ev.target.value) | 0; 12 | store[propertyName] = v; 13 | }); 14 | return ( 15 | 16 | ); 17 | }); 18 | function ImmediateNumberConfigItem({ propertyName, label, ...props }) { 19 | return ( 20 | 21 | 22 | 23 | ); 24 | } 25 | 26 | function ConfigModal({ visible, onVisibleChange }) { 27 | const handleClose = useCallback(() => { 28 | onVisibleChange?.call(null, false); 29 | }, [onVisibleChange]); 30 | const resetConfig = unwrappedAction(() => { 31 | const { 32 | canvasWidth, 33 | canvasHeight, 34 | marginTop, 35 | marginHorizontal, 36 | gapBetweenParagraph, 37 | gapBetweenNotation, 38 | } = getDefaultGlobalData(); 39 | Object.assign(store, { 40 | canvasWidth, 41 | canvasHeight, 42 | marginTop, 43 | marginHorizontal, 44 | gapBetweenParagraph, 45 | gapBetweenNotation, 46 | }); 47 | }); 48 | 49 | return ( 50 | 57 | 重置为默认 58 | , 59 | , 62 | ]} 63 | > 64 |
65 | 66 | 67 | 71 | 72 | 84 | 88 | 89 | 90 | 91 | 95 | 99 | 103 | 104 |
105 | ); 106 | } 107 | 108 | export default ConfigModal; 109 | -------------------------------------------------------------------------------- /src/view/Editor/index.js: -------------------------------------------------------------------------------- 1 | import { Button, Dropdown } from "antd"; 2 | import { 3 | EditOutlined, 4 | FileTextOutlined, 5 | QuestionOutlined, 6 | RetweetOutlined, 7 | SettingOutlined, 8 | } from "@ant-design/icons"; 9 | import { observer } from "mobx-react-lite"; 10 | import { useEffect } from "react"; 11 | import state from "../../store/state"; 12 | import store from "../../store/global"; 13 | import P, { 14 | calcParagraphAboveOffset, 15 | calcParagraphHeight, 16 | } from "../../util/placement"; 17 | import { 18 | convertMenu, 19 | editMenu, 20 | fileMenu, 21 | handleClick, 22 | handleKeyPress, 23 | } from "../../menu/editor"; 24 | import { unwrappedAction } from "../../store/history"; 25 | import Canvas from "../Canvas"; 26 | import ConfigModal from "../ConfigModal"; 27 | import Header from "../Header"; 28 | import HelpModal from "../HelpModal"; 29 | import Paragraph from "../Paragraph"; 30 | import Row from "../Row"; 31 | import Styles from "./index.module.css"; 32 | 33 | function Editor() { 34 | const heightCache = []; 35 | function accumulate(index) { 36 | const paragraphs = store.paragraphs || []; 37 | let height = 0; 38 | for (let i = 0; i < index; i++) { 39 | const p = paragraphs[i]; 40 | heightCache[i] = heightCache[i] || calcParagraphHeight(p); 41 | height += heightCache[i]; 42 | } 43 | // 段落渲染定位基于段落中心,因此加上上半部分的偏移量 44 | height += calcParagraphAboveOffset(paragraphs[index]); 45 | return height; 46 | } 47 | const handleChangeConfigModalVisibility = unwrappedAction((visible) => { 48 | state.configDialogVisible = visible; 49 | }); 50 | const handleChangeHelpModalVisibility = unwrappedAction((visible) => { 51 | state.helpDialogVisible = visible; 52 | }); 53 | const handleShowConfigDialog = () => { 54 | handleChangeConfigModalVisibility(true); 55 | }; 56 | const handleShowHelpDialog = () => { 57 | handleChangeHelpModalVisibility(true); 58 | }; 59 | useEffect(() => { 60 | document.addEventListener("keydown", handleKeyPress); 61 | return () => { 62 | document.removeEventListener("keydown", handleKeyPress); 63 | }; 64 | }, []); 65 | 66 | return ( 67 |
71 |
72 |
76 | 77 | 80 | 81 | 82 | 85 | 86 | 87 | 90 | 91 | 98 | 105 |
106 |
107 | 108 |
109 | 110 | {store.paragraphs.map((p, i) => { 111 | let alignJustify = p.alignJustify; 112 | if (typeof alignJustify !== "boolean") { 113 | alignJustify = !(i === store.paragraphs.length - 1); 114 | } 115 | return ( 116 | 122 | ); 123 | })} 124 | 125 | 126 | 130 | 134 |
135 | ); 136 | } 137 | 138 | export default observer(Editor); 139 | -------------------------------------------------------------------------------- /src/view/Editor/index.module.css: -------------------------------------------------------------------------------- 1 | .headerWrapper { 2 | margin-bottom: 16px; 3 | border-bottom: 1px solid whitesmoke; 4 | width: 100%; 5 | } 6 | .header { 7 | margin: auto; 8 | padding: 8px 0; 9 | } 10 | .container { 11 | display: flex; 12 | flex-direction: column; 13 | align-items: center; 14 | justify-content: center; 15 | background-color: white; 16 | min-width: 100%; 17 | height: 100%; 18 | } 19 | -------------------------------------------------------------------------------- /src/view/Header/LeftInfoBlock/index.js: -------------------------------------------------------------------------------- 1 | import { message } from "antd"; 2 | import { observer } from "mobx-react-lite"; 3 | import EditableContent from "../../../component/EditableContent"; 4 | import P from "../../../util/placement"; 5 | import store from "../../../store/global"; 6 | import { wrappedAction } from "../../../store/history"; 7 | import Row from "../../Row"; 8 | import Text from "../../Text"; 9 | 10 | const tones = [ 11 | "C", 12 | "D", 13 | "E", 14 | "F", 15 | "G", 16 | "A", 17 | "B", 18 | "♭C", 19 | "♭D", 20 | "♭E", 21 | "♭F", 22 | "♭G", 23 | "♭A", 24 | "♭B", 25 | ].map((t) => ({ key: t, text: t })); 26 | const handleChangeTone = wrappedAction(function (value) { 27 | store.tone = value; 28 | }); 29 | const handleChangeSpeed = wrappedAction(function (value) { 30 | store.speed = value; 31 | }); 32 | const handleChangeBeat = wrappedAction(function (value) { 33 | const beat = String(value).split("/"); 34 | if (beat.length !== 2) { 35 | message.error("请以【*/*】的格式输入节拍!"); 36 | return false; 37 | } 38 | const [c, t] = [parseInt(beat[0], 10), parseInt(beat[1], 10)]; 39 | if (c > 0 && t > 0) { 40 | store.beat = [c, t]; 41 | } else { 42 | message.error("请输入大于0的拍数和时值!"); 43 | return false; 44 | } 45 | }); 46 | 47 | function LeftInfoBlock() { 48 | return ( 49 | <> 50 | 57 | 63 | 1  = 64 | {store.tone.startsWith("♭") && ( 65 | 66 | ♭ 67 | 68 | )} 69 | 70 | 71 | {store.tone.at(-1)} 72 | 73 | 74 | 75 | 81 | 87 | 88 | {store.beat[0]} 89 | 90 | 91 | {store.beat[1]} 92 | 93 | 94 | 95 | 96 | 102 | 108 | 109 | = {store.speed} 110 | 111 | 112 | 113 | ); 114 | } 115 | 116 | export default observer(LeftInfoBlock); 117 | -------------------------------------------------------------------------------- /src/view/Header/RightInfoBlock/index.js: -------------------------------------------------------------------------------- 1 | import { DeleteOutlined, PlusOutlined } from "@ant-design/icons"; 2 | import { Modal } from "antd"; 3 | import { observer } from "mobx-react-lite"; 4 | import EditableContent from "../../../component/EditableContent"; 5 | import P from "../../../util/placement"; 6 | import store from "../../../store/global"; 7 | import { wrappedAction } from "../../../store/history"; 8 | import Row from "../../Row"; 9 | import Text from "../../Text"; 10 | 11 | const authorContextMenu = [ 12 | { 13 | key: "create", 14 | text: "添加", 15 | icon: , 16 | onClick: () => { 17 | store.authors.push("作者信息"); 18 | }, 19 | }, 20 | { 21 | key: "delete", 22 | text: "删除", 23 | icon: , 24 | onClick: (index) => { 25 | store.authors.splice(index, 1); 26 | }, 27 | }, 28 | ]; 29 | const blockContextMenu = [ 30 | { 31 | key: "create", 32 | text: "添加作者信息", 33 | icon: , 34 | onClick: () => { 35 | store.authors.push("【记谱者】 记谱"); 36 | }, 37 | }, 38 | ]; 39 | const handleSelectMenu = wrappedAction((index, value) => { 40 | const menu = authorContextMenu.find((m) => m.key === value); 41 | menu?.onClick(index); 42 | }); 43 | const handleSelectBlockMenu = wrappedAction((value) => { 44 | const menu = blockContextMenu.find((m) => m.key === value); 45 | menu?.onClick(); 46 | }); 47 | const handleChangeAuthor = wrappedAction((index, value) => { 48 | if (!value) { 49 | return new Promise((resolve) => { 50 | Modal.confirm({ 51 | title: "删除这条作者信息?", 52 | okText: "确定", 53 | cancelText: "取消", 54 | onOk: () => { 55 | resolve(true); 56 | store.authors.splice(index, 1); 57 | }, 58 | onCancel: () => { 59 | resolve(true); 60 | }, 61 | }); 62 | }); 63 | } 64 | store.authors[index] = value; 65 | }); 66 | 67 | function RightInfoBlock() { 68 | return ( 69 | 74 | 80 | 88 | 89 | {store.authors.map((author, i) => ( 90 | 97 | 102 | 103 | {author} 104 | 105 | 106 | 107 | ))} 108 | 109 | ); 110 | } 111 | 112 | export default observer(RightInfoBlock); 113 | -------------------------------------------------------------------------------- /src/view/Header/RightInfoBlock/index.module.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattuylee/numerical-notation-editor/1b80f8903ec9f3bdd62df04ef69c8288b5c3b287/src/view/Header/RightInfoBlock/index.module.css -------------------------------------------------------------------------------- /src/view/Header/Title/index.js: -------------------------------------------------------------------------------- 1 | import { observer } from "mobx-react-lite"; 2 | import { useRef } from "react"; 3 | import EditableContent from "../../../component/EditableContent"; 4 | import store from "../../../store/global"; 5 | import { wrappedAction } from "../../../store/history"; 6 | import Row from "../../Row"; 7 | import Text from "../../Text"; 8 | const handleChangeTitle = wrappedAction((value) => { 9 | store.title = value; 10 | }); 11 | 12 | function Title() { 13 | const ref = useRef(); 14 | return ( 15 | 16 | 22 | 30 | {store.title} 31 | 32 | 33 | 34 | ); 35 | } 36 | 37 | export default observer(Title); 38 | -------------------------------------------------------------------------------- /src/view/Header/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import LeftInfoBlock from "./LeftInfoBlock"; 3 | import RightInfoBlock from "./RightInfoBlock"; 4 | import Title from "./Title"; 5 | 6 | function Header() { 7 | return ( 8 | <> 9 | 10 | 11 | 12 | 13 | ); 14 | } 15 | 16 | export default React.memo(Header); 17 | -------------------------------------------------------------------------------- /src/view/HelpModal/index.js: -------------------------------------------------------------------------------- 1 | import { Button, Modal } from "antd"; 2 | import { useCallback } from "react"; 3 | import Styles from "./index.module.css"; 4 | 5 | function KeyboardDescItem({ kbd, desc }) { 6 | return ( 7 |
  • 8 | {kbd} 9 | {desc} 10 |
  • 11 | ); 12 | } 13 | 14 | function HelpModal({ visible, onVisibleChange }) { 15 | const handleClose = useCallback(() => { 16 | onVisibleChange?.call(null, false); 17 | }, [onVisibleChange]); 18 | 19 | return ( 20 | 29 | 确定 30 | 31 | } 32 | > 33 |

    快捷键

    34 |

    全局

    35 |
      36 | 37 | 38 | 39 | 40 | 41 |
    42 |

    仅选中符号时

    43 |

    输入音符

    44 | 直接按键盘上相应的键即可输入到当前符号。支持的音符符号有: 45 |

    46 | 0~7 47 | ─ ( ) 48 |

    49 |

    输入辅助元素

    50 |
      51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
    61 |

    操作

    62 |
      63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
    74 |

    提示

    75 |
      76 |
    • 段落上可以右键单击弹出操作菜单
    • 77 |
    • 增减时线默认连续,可在音符右键菜单中选择打断
    • 78 |
    79 |
    80 | ); 81 | } 82 | 83 | export default HelpModal; 84 | -------------------------------------------------------------------------------- /src/view/HelpModal/index.module.css: -------------------------------------------------------------------------------- 1 | .list { 2 | padding: 0; 3 | list-style: none; 4 | } 5 | .listItem { 6 | display: inline-block; 7 | margin-top: 8px; 8 | margin-right: 16px; 9 | min-width: 260px; 10 | } 11 | .kbd { 12 | display: inline-block; 13 | margin-right: 8px; 14 | border-radius: 4px; 15 | background-color: lightgray; 16 | padding: 4px; 17 | width: 120px; 18 | text-align: center; 19 | } 20 | -------------------------------------------------------------------------------- /src/view/Notation/index.js: -------------------------------------------------------------------------------- 1 | import { observer } from "mobx-react-lite"; 2 | import EditableContent from "../../component/EditableContent"; 3 | import state from "../../store/state"; 4 | import store from "../../store/global"; 5 | import P, { calcSubTextWidth } from "../../util/placement"; 6 | import { getNotationContextMenu } from "../../menu/notation"; 7 | import { notations, placeTie } from "../../util/notation"; 8 | import { wrappedAction } from "../../store/history"; 9 | import Row from "../Row"; 10 | import Text from "../Text"; 11 | import Styles from "./index.module.css"; 12 | 13 | function composeArray(octave) { 14 | const len = Math.abs(Number(octave)); 15 | if (!Number.isInteger(len)) { 16 | return []; 17 | } 18 | return Array(len).fill(0, 0, len); 19 | } 20 | 21 | function Notation({ offsetX, notation, paragraph }) { 22 | const handleClick = wrappedAction(() => { 23 | state.selectedNotationKey = notation.key; 24 | state.shouldNotationBlurAfterClick = false; 25 | placeTie(notation); 26 | }); 27 | 28 | const underlineOffset = P.underlineStepOffsetY * (notation.underline | 0); 29 | const octaveInitialOffset = 30 | notation.octave > 0 31 | ? -P.octaveInitialOffsetAbove 32 | : P.octaveInitialOffsetBelow + underlineOffset; 33 | const octaveStepOffset = (notation.octave > 0 ? -1 : 1) * P.octaveStepOffsetY; 34 | let topDecoratorOffset = 0; 35 | if (notation.octave > 0) { 36 | // 如果有高八度圆点,将顶部装饰符渲染到其上方 37 | topDecoratorOffset = octaveStepOffset * Math.abs(notation.octave); 38 | } 39 | 40 | const renderPrefixSups = () => { 41 | const sups = notation.prefixSups || []; 42 | const rendered = sups.map((s, i) => ( 43 | 51 | {s} 52 | 53 | )); 54 | return rendered; 55 | }; 56 | 57 | const renderTopDecorators = () => { 58 | const decs = notation.topDecorators || []; 59 | const rendered = decs.map((d, i) => ( 60 | 67 | {d} 68 | 69 | )); 70 | return rendered; 71 | }; 72 | 73 | const renderNote = () => { 74 | let transform; 75 | if (notation.note === notations.extend) { 76 | // 延音符太长了缩短一点 77 | transform = "scale(0.8, 1)"; 78 | } 79 | return ( 80 | 81 | {notation.note} 82 | 83 | ); 84 | }; 85 | 86 | const renderOctave = () => { 87 | return composeArray(notation.octave).map((oc, i) => ( 88 | 96 | )); 97 | }; 98 | return ( 99 | 104 | 115 | {renderPrefixSups()} 116 | {renderTopDecorators()} 117 | {renderNote()} 118 | {notation.dotted && ( 119 | 126 | )} 127 | {renderOctave()} 128 | 129 | 130 | ); 131 | } 132 | 133 | Notation.defaultProps = { 134 | offsetX: 0, 135 | offsetY: 0, 136 | }; 137 | 138 | export default observer(Notation); 139 | -------------------------------------------------------------------------------- /src/view/Notation/index.module.css: -------------------------------------------------------------------------------- 1 | .selectedNotation { 2 | color: coral; 3 | } -------------------------------------------------------------------------------- /src/view/Paragraph/index.js: -------------------------------------------------------------------------------- 1 | import { observer } from "mobx-react-lite"; 2 | import EditableContent from "../../component/EditableContent"; 3 | import P, { 4 | calcNotationAboveOffset, 5 | calcNotationPrefixOffset, 6 | calcNotationWidth, 7 | calcParagraphAboveOffset, 8 | calcParagraphContentHeight, 9 | calcParagraphWidth, 10 | } from "../../util/placement"; 11 | import { getParagraphMenuOptions } from "../../menu/paragraph"; 12 | import Notation from "../Notation"; 13 | import Row from "../Row"; 14 | 15 | function Paragraph({ paragraph, offsetY, alignJustify }) { 16 | const notations = paragraph.notations || []; 17 | const widthCache = []; 18 | let itemFlexOffset = 0; 19 | if (alignJustify && paragraph.notations?.length > 1) { 20 | const realWidth = calcParagraphWidth(paragraph); 21 | itemFlexOffset = 22 | (P.maxContentWidth - realWidth) / (paragraph.notations.length - 1); 23 | } 24 | 25 | // 计算前n个音符的宽度 26 | const accumulate = (index) => { 27 | let width = 0; 28 | for (let i = 0; i < index; i++) { 29 | const n = notations[i]; 30 | widthCache[i] = widthCache[i] || calcNotationWidth(n); 31 | width += widthCache[i]; 32 | } 33 | // 音符的定位基准是其中心,因此要加上当前音符的前缀部分偏移 34 | width += calcNotationPrefixOffset(notations[index]); 35 | return width; 36 | }; 37 | 38 | // 缓存音符偏移量 39 | const noteOffsets = notations.map((_, i) => { 40 | return ( 41 | // 渲染音符时坐标为其中心,故偏移半个音符宽 42 | P.xWidth / 2 + 43 | // 偏移前面音符的宽度 44 | accumulate(i) + 45 | // 两端对齐时自动偏移 46 | itemFlexOffset * i 47 | ); 48 | }); 49 | 50 | // 绘制音符的增减时线 51 | const renderUnderLine = (offsetY, fromIndex, toIndex) => { 52 | return ( 53 | 61 | ); 62 | }; 63 | const renderUnderlines = () => { 64 | const lines = []; 65 | // 记录音符当前需要绘制的增减时线的条数 66 | let helpMap = notations.map((n) => (n.underline > 0 ? n.underline : 0)); 67 | let baseOffsetY = P.underlineInitialOffsetY; 68 | while (helpMap.some((n) => n > 0)) { 69 | let fromIndex = -1; 70 | let toIndex = fromIndex; 71 | for (let i = 0; i < notations.length; ++i) { 72 | const n = notations[i]; 73 | if (helpMap[i] > 0) { 74 | // 当前音符需要添加增减时线 75 | if (fromIndex >= 0) { 76 | // 其前面的音符也需要添加增减时线 77 | if (n.breakUnderline) { 78 | // 当前音符禁止和前面的增减时线连续,绘制前面的增减时线 79 | lines.push(renderUnderLine(baseOffsetY, fromIndex, toIndex)); 80 | // 记录当前音符位置等待绘制 81 | fromIndex = toIndex = i; 82 | } else { 83 | // 当前音符可能和下一个音符的增减时线连续,本次循环不绘制 84 | toIndex = i; 85 | } 86 | } else { 87 | fromIndex = toIndex = i; 88 | } 89 | if (i === notations.length - 1) { 90 | // 已是最后一个音符,直接绘制增减时线 91 | lines.push(renderUnderLine(baseOffsetY, fromIndex, toIndex)); 92 | fromIndex = toIndex = -1; 93 | } 94 | --helpMap[i]; 95 | } else { 96 | // 当前音符不需要绘制增减时线 97 | if (fromIndex >= 0) { 98 | lines.push(renderUnderLine(baseOffsetY, fromIndex, toIndex)); 99 | fromIndex = toIndex = -1; 100 | } 101 | } 102 | } 103 | baseOffsetY += P.underlineStepOffsetY; 104 | } 105 | return lines; 106 | }; 107 | 108 | // 渲染连音线 109 | const renderTie = (offsetY, fromIndex, toIndex) => { 110 | const bezierX1 = noteOffsets[fromIndex]; 111 | const bezierX2 = bezierX1 + 4; 112 | const bezierX4 = noteOffsets[toIndex]; 113 | const bezierX3 = bezierX4 - 4; 114 | const x = bezierX4 - bezierX1; 115 | // ENHANCE: 优化贝赛尔曲线 116 | let y = 117 | 0.000021917145491103032 * x * x * x - 118 | 0.0062948773732605465 * x * x + 119 | 0.6378785891964498 * x - 120 | 0.6843414475200537; 121 | y = Math.max(Math.min(y, P.maxTieBezierOffset), P.minTieHeight); 122 | const bezierY = offsetY - y; 123 | return ( 124 | 130 | ); 131 | }; 132 | const renderTies = () => { 133 | const ties = []; 134 | const offsetMap = new Map(); 135 | for (let i = 0; i < notations.length; ++i) { 136 | const n = notations[i]; 137 | if (n.tieTo) { 138 | const toIndex = notations.findIndex((nn) => nn.key === n.tieTo); 139 | if (toIndex <= i) { 140 | // tieTo属性应该是双向的,仅遍历到第一个节点时渲染 141 | continue; 142 | } 143 | let minOffsetY = 0; 144 | for (let j = i; j <= toIndex; ++j) { 145 | let offset; 146 | if (offsetMap.has(notations[j].key)) { 147 | offset = offsetMap.get(notations[j].key); 148 | } else { 149 | offset = -calcNotationAboveOffset(notations[j]); 150 | offsetMap.set(notations[j].key, offset); 151 | } 152 | minOffsetY = Math.min(minOffsetY, offset); 153 | } 154 | ties.push(renderTie(minOffsetY, i, toIndex)); 155 | } 156 | } 157 | return ties; 158 | }; 159 | 160 | const renderParagraphMask = () => { 161 | const height = calcParagraphContentHeight(paragraph); 162 | return ( 163 | 167 | 174 | 175 | ); 176 | }; 177 | 178 | return ( 179 | 180 | {renderParagraphMask()} 181 | {renderTies()} 182 | {paragraph.notations.map((n, i) => ( 183 | 189 | ))} 190 | {renderUnderlines()} 191 | 192 | ); 193 | } 194 | 195 | export default observer(Paragraph); 196 | -------------------------------------------------------------------------------- /src/view/Row/index.js: -------------------------------------------------------------------------------- 1 | export default function Row({ 2 | children, 3 | type, 4 | editable, 5 | offset, 6 | offsetX, 7 | offsetY, 8 | ...props 9 | }) { 10 | offsetX = (offset?.x ?? offsetX) | 0; 11 | offsetY = (offset?.y ?? offsetY) | 0; 12 | return ( 13 | 25 | {children} 26 | 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /src/view/Text/index.js: -------------------------------------------------------------------------------- 1 | import escapeHtml from "../../util/html-escape"; 2 | 3 | export default function Text({ children, editable, ...props }) { 4 | if (typeof children === "string") { 5 | return ( 6 | 23 | ); 24 | } 25 | return ( 26 | 42 | {children} 43 | 44 | ); 45 | } 46 | --------------------------------------------------------------------------------