@ugfoundation/swaralipi-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +347 -0
  2. package/README.md +257 -0
  3. package/dist/batch-NF2Q2CFS.js +47 -0
  4. package/dist/batch-NF2Q2CFS.js.map +1 -0
  5. package/dist/chunk-C6O7DYU5.js +115 -0
  6. package/dist/chunk-C6O7DYU5.js.map +1 -0
  7. package/dist/chunk-GWXI2HJA.js +14 -0
  8. package/dist/chunk-GWXI2HJA.js.map +1 -0
  9. package/dist/chunk-N3NNWAOW.js +593 -0
  10. package/dist/chunk-N3NNWAOW.js.map +1 -0
  11. package/dist/cli.cjs +913 -0
  12. package/dist/cli.cjs.map +1 -0
  13. package/dist/cli.d.cts +1 -0
  14. package/dist/cli.d.ts +1 -0
  15. package/dist/cli.js +91 -0
  16. package/dist/cli.js.map +1 -0
  17. package/dist/convert/index.cjs +720 -0
  18. package/dist/convert/index.cjs.map +1 -0
  19. package/dist/convert/index.d.cts +270 -0
  20. package/dist/convert/index.d.ts +270 -0
  21. package/dist/convert/index.js +5 -0
  22. package/dist/convert/index.js.map +1 -0
  23. package/dist/index.cjs +143 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +4 -0
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.js +4 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/player/index.cjs +775 -0
  30. package/dist/player/index.cjs.map +1 -0
  31. package/dist/player/index.d.cts +285 -0
  32. package/dist/player/index.d.ts +285 -0
  33. package/dist/player/index.js +743 -0
  34. package/dist/player/index.js.map +1 -0
  35. package/dist/schema-gxhG45OK.d.cts +467 -0
  36. package/dist/schema-gxhG45OK.d.ts +467 -0
  37. package/dist/spec/index.cjs +143 -0
  38. package/dist/spec/index.cjs.map +1 -0
  39. package/dist/spec/index.d.cts +70 -0
  40. package/dist/spec/index.d.ts +70 -0
  41. package/dist/spec/index.js +4 -0
  42. package/dist/spec/index.js.map +1 -0
  43. package/dist/taals-DguYW0wf.d.cts +60 -0
  44. package/dist/taals-DguYW0wf.d.ts +60 -0
  45. package/dist/viewer/index.cjs +998 -0
  46. package/dist/viewer/index.cjs.map +1 -0
  47. package/dist/viewer/index.d.cts +285 -0
  48. package/dist/viewer/index.d.ts +285 -0
  49. package/dist/viewer/index.js +814 -0
  50. package/dist/viewer/index.js.map +1 -0
  51. package/package.json +93 -0
package/LICENSE ADDED
@@ -0,0 +1,347 @@
1
+ swaralipi-js
2
+ Copyright (C) 2026 Upal & Gopa Das Foundation
3
+
4
+ This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License version 2 as
6
+ published by the Free Software Foundation.
7
+
8
+ ----------------------------------------------------------------------
9
+
10
+ GNU GENERAL PUBLIC LICENSE
11
+ Version 2, June 1991
12
+
13
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
14
+ <https://fsf.org/>
15
+ Everyone is permitted to copy and distribute verbatim copies
16
+ of this license document, but changing it is not allowed.
17
+
18
+ Preamble
19
+
20
+ The licenses for most software are designed to take away your
21
+ freedom to share and change it. By contrast, the GNU General Public
22
+ License is intended to guarantee your freedom to share and change free
23
+ software--to make sure the software is free for all its users. This
24
+ General Public License applies to most of the Free Software
25
+ Foundation's software and to any other program whose authors commit to
26
+ using it. (Some other Free Software Foundation software is covered by
27
+ the GNU Lesser General Public License instead.) You can apply it to
28
+ your programs, too.
29
+
30
+ When we speak of free software, we are referring to freedom, not
31
+ price. Our General Public Licenses are designed to make sure that you
32
+ have the freedom to distribute copies of free software (and charge for
33
+ this service if you wish), that you receive source code or can get it
34
+ if you want it, that you can change the software or use pieces of it
35
+ in new free programs; and that you know you can do these things.
36
+
37
+ To protect your rights, we need to make restrictions that forbid
38
+ anyone to deny you these rights or to ask you to surrender the rights.
39
+ These restrictions translate to certain responsibilities for you if you
40
+ distribute copies of the software, or if you modify it.
41
+
42
+ For example, if you distribute copies of such a program, whether
43
+ gratis or for a fee, you must give the recipients all the rights that
44
+ you have. You must make sure that they, too, receive or can get the
45
+ source code. And you must show them these terms so they know their
46
+ rights.
47
+
48
+ We protect your rights with two steps: (1) copyright the software, and
49
+ (2) offer you this license which gives you legal permission to copy,
50
+ distribute and/or modify the software.
51
+
52
+ Also, for each author's protection and ours, we want to make certain
53
+ that everyone understands that there is no warranty for this free
54
+ software. If the software is modified by someone else and passed on, we
55
+ want its recipients to know that what they have is not the original, so
56
+ that any problems introduced by others will not reflect on the original
57
+ authors' reputations.
58
+
59
+ Finally, any free program is threatened constantly by software
60
+ patents. We wish to avoid the danger that redistributors of a free
61
+ program will individually obtain patent licenses, in effect making the
62
+ program proprietary. To prevent this, we have made it clear that any
63
+ patent must be licensed for everyone's free use or not licensed at all.
64
+
65
+ The precise terms and conditions for copying, distribution and
66
+ modification follow.
67
+
68
+ GNU GENERAL PUBLIC LICENSE
69
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70
+
71
+ 0. This License applies to any program or other work which contains
72
+ a notice placed by the copyright holder saying it may be distributed
73
+ under the terms of this General Public License. The "Program", below,
74
+ refers to any such program or work, and a "work based on the Program"
75
+ means either the Program or any derivative work under copyright law:
76
+ that is to say, a work containing the Program or a portion of it,
77
+ either verbatim or with modifications and/or translated into another
78
+ language. (Hereinafter, translation is included without limitation in
79
+ the term "modification".) Each licensee is addressed as "you".
80
+
81
+ Activities other than copying, distribution and modification are not
82
+ covered by this License; they are outside its scope. The act of
83
+ running the Program is not restricted, and the output from the Program
84
+ is covered only if its contents constitute a work based on the
85
+ Program (independent of having been made by running the Program).
86
+ Whether that is true depends on what the Program does.
87
+
88
+ 1. You may copy and distribute verbatim copies of the Program's
89
+ source code as you receive it, in any medium, provided that you
90
+ conspicuously and appropriately publish on each copy an appropriate
91
+ copyright notice and disclaimer of warranty; keep intact all the
92
+ notices that refer to this License and to the absence of any warranty;
93
+ and give any other recipients of the Program a copy of this License
94
+ along with the Program.
95
+
96
+ You may charge a fee for the physical act of transferring a copy, and
97
+ you may at your option offer warranty protection in exchange for a fee.
98
+
99
+ 2. You may modify your copy or copies of the Program or any portion
100
+ of it, thus forming a work based on the Program, and copy and
101
+ distribute such modifications or work under the terms of Section 1
102
+ above, provided that you also meet all of these conditions:
103
+
104
+ a) You must cause the modified files to carry prominent notices
105
+ stating that you changed the files and the date of any change.
106
+
107
+ b) You must cause any work that you distribute or publish, that in
108
+ whole or in part contains or is derived from the Program or any
109
+ part thereof, to be licensed as a whole at no charge to all third
110
+ parties under the terms of this License.
111
+
112
+ c) If the modified program normally reads commands interactively
113
+ when run, you must cause it, when started running for such
114
+ interactive use in the most ordinary way, to print or display an
115
+ announcement including an appropriate copyright notice and a
116
+ notice that there is no warranty (or else, saying that you provide
117
+ a warranty) and that users may redistribute the program under
118
+ these conditions, and telling the user how to view a copy of this
119
+ License. (Exception: if the Program itself is interactive but
120
+ does not normally print such an announcement, your work based on
121
+ the Program is not required to print an announcement.)
122
+
123
+ These requirements apply to the modified work as a whole. If
124
+ identifiable sections of that work are not derived from the Program,
125
+ and can be reasonably considered independent and separate works in
126
+ themselves, then this License, and its terms, do not apply to those
127
+ sections when you distribute them as separate works. But when you
128
+ distribute the same sections as part of a whole which is a work based
129
+ on the Program, the distribution of the whole must be on the terms of
130
+ this License, whose permissions for other licensees extend to the
131
+ entire whole, and thus to each and every part regardless of who wrote it.
132
+
133
+ Thus, it is not the intent of this section to claim rights or contest
134
+ your rights to work written entirely by you; rather, the intent is to
135
+ exercise the right to control the distribution of derivative or
136
+ collective works based on the Program.
137
+
138
+ In addition, mere aggregation of another work not based on the Program
139
+ with the Program (or with a work based on the Program) on a volume of
140
+ a storage or distribution medium does not bring the other work under
141
+ the scope of this License.
142
+
143
+ 3. You may copy and distribute the Program (or a work based on it,
144
+ under Section 2) in object code or executable form under the terms of
145
+ Sections 1 and 2 above provided that you also do one of the following:
146
+
147
+ a) Accompany it with the complete corresponding machine-readable
148
+ source code, which must be distributed under the terms of Sections
149
+ 1 and 2 above on a medium customarily used for software interchange; or,
150
+
151
+ b) Accompany it with a written offer, valid for at least three
152
+ years, to give any third party, for a charge no more than your
153
+ cost of physically performing source distribution, a complete
154
+ machine-readable copy of the corresponding source code, to be
155
+ distributed under the terms of Sections 1 and 2 above on a medium
156
+ customarily used for software interchange; or,
157
+
158
+ c) Accompany it with the information you received as to the offer
159
+ to distribute corresponding source code. (This alternative is
160
+ allowed only for noncommercial distribution and only if you
161
+ received the program in object code or executable form with such
162
+ an offer, in accord with Subsection b above.)
163
+
164
+ The source code for a work means the preferred form of the work for
165
+ making modifications to it. For an executable work, complete source
166
+ code means all the source code for all modules it contains, plus any
167
+ associated interface definition files, plus the scripts used to
168
+ control compilation and installation of the executable. However, as a
169
+ special exception, the source code distributed need not include
170
+ anything that is normally distributed (in either source or binary
171
+ form) with the major components (compiler, kernel, and so on) of the
172
+ operating system on which the executable runs, unless that component
173
+ itself accompanies the executable.
174
+
175
+ If distribution of executable or object code is made by offering
176
+ access to copy from a designated place, then offering equivalent
177
+ access to copy the source code from the same place counts as
178
+ distribution of the source code, even though third parties are not
179
+ compelled to copy the source along with the object code.
180
+
181
+ 4. You may not copy, modify, sublicense, or distribute the Program
182
+ except as expressly provided under this License. Any attempt
183
+ otherwise to copy, modify, sublicense or distribute the Program is
184
+ void, and will automatically terminate your rights under this License.
185
+ However, parties who have received copies, or rights, from you under
186
+ this License will not have their licenses terminated so long as such
187
+ parties remain in full compliance.
188
+
189
+ 5. You are not required to accept this License, since you have not
190
+ signed it. However, nothing else grants you permission to modify or
191
+ distribute the Program or its derivative works. These actions are
192
+ prohibited by law if you do not accept this License. Therefore, by
193
+ modifying or distributing the Program (or any work based on the
194
+ Program), you indicate your acceptance of this License to do so, and
195
+ all its terms and conditions for copying, distributing or modifying
196
+ the Program or works based on it.
197
+
198
+ 6. Each time you redistribute the Program (or any work based on the
199
+ Program), the recipient automatically receives a license from the
200
+ original licensor to copy, distribute or modify the Program subject to
201
+ these terms and conditions. You may not impose any further
202
+ restrictions on the recipients' exercise of the rights granted herein.
203
+ You are not responsible for enforcing compliance by third parties to
204
+ this License.
205
+
206
+ 7. If, as a consequence of a court judgment or allegation of patent
207
+ infringement or for any other reason (not limited to patent issues),
208
+ conditions are imposed on you (whether by court order, agreement or
209
+ otherwise) that contradict the conditions of this License, they do not
210
+ excuse you from the conditions of this License. If you cannot
211
+ distribute so as to satisfy simultaneously your obligations under this
212
+ License and any other pertinent obligations, then as a consequence you
213
+ may not distribute the Program at all. For example, if a patent
214
+ license would not permit royalty-free redistribution of the Program by
215
+ all those who receive copies directly or indirectly through you, then
216
+ the only way you could satisfy both it and this License would be to
217
+ refrain entirely from distribution of the Program.
218
+
219
+ If any portion of this section is held invalid or unenforceable under
220
+ any particular circumstance, the balance of the section is intended to
221
+ apply and the section as a whole is intended to apply in other
222
+ circumstances.
223
+
224
+ It is not the purpose of this section to induce you to infringe any
225
+ patents or other property right claims or to contest validity of any
226
+ such claims; this section has the sole purpose of protecting the
227
+ integrity of the free software distribution system, which is
228
+ implemented by public license practices. Many people have made
229
+ generous contributions to the wide range of software distributed
230
+ through that system in reliance on consistent application of that
231
+ system; it is up to the author/donor to decide if he or she is willing
232
+ to distribute software through any other system and a licensee cannot
233
+ impose that choice.
234
+
235
+ This section is intended to make thoroughly clear what is believed to
236
+ be a consequence of the rest of this License.
237
+
238
+ 8. If the distribution and/or use of the Program is restricted in
239
+ certain countries either by patents or by copyrighted interfaces, the
240
+ original copyright holder who places the Program under this License
241
+ may add an explicit geographical distribution limitation excluding
242
+ those countries, so that distribution is permitted only in or among
243
+ countries not thus excluded. In such case, this License incorporates
244
+ the limitation as if written in the body of this License.
245
+
246
+ 9. The Free Software Foundation may publish revised and/or new versions
247
+ of the General Public License from time to time. Such new versions will
248
+ be similar in spirit to the present version, but may differ in detail to
249
+ address new problems or concerns.
250
+
251
+ Each version is given a distinguishing version number. If the Program
252
+ specifies a version number of this License which applies to it and "any
253
+ later version", you have the option of following the terms and conditions
254
+ either of that version or of any later version published by the Free
255
+ Software Foundation. If the Program does not specify a version number of
256
+ this License, you may choose any version ever published by the Free Software
257
+ Foundation.
258
+
259
+ 10. If you wish to incorporate parts of the Program into other free
260
+ programs whose distribution conditions are different, write to the author
261
+ to ask for permission. For software which is copyrighted by the Free
262
+ Software Foundation, write to the Free Software Foundation; we sometimes
263
+ make exceptions for this. Our decision will be guided by the two goals
264
+ of preserving the free status of all derivatives of our free software and
265
+ of promoting the sharing and reuse of software generally.
266
+
267
+ NO WARRANTY
268
+
269
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
270
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
271
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
272
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
273
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
274
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
275
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
276
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
277
+ REPAIR OR CORRECTION.
278
+
279
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
280
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
281
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
282
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
283
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
284
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
285
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
286
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
287
+ POSSIBILITY OF SUCH DAMAGES.
288
+
289
+ END OF TERMS AND CONDITIONS
290
+
291
+ How to Apply These Terms to Your New Programs
292
+
293
+ If you develop a new program, and you want it to be of the greatest
294
+ possible use to the public, the best way to achieve this is to make it
295
+ free software which everyone can redistribute and change under these terms.
296
+
297
+ To do so, attach the following notices to the program. It is safest
298
+ to attach them to the start of each source file to most effectively
299
+ convey the exclusion of warranty; and each file should have at least
300
+ the "copyright" line and a pointer to where the full notice is found.
301
+
302
+ <one line to give the program's name and a brief idea of what it does.>
303
+ Copyright (C) <year> <name of author>
304
+
305
+ This program is free software; you can redistribute it and/or modify
306
+ it under the terms of the GNU General Public License as published by
307
+ the Free Software Foundation; either version 2 of the License, or
308
+ (at your option) any later version.
309
+
310
+ This program is distributed in the hope that it will be useful,
311
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
312
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
313
+ GNU General Public License for more details.
314
+
315
+ You should have received a copy of the GNU General Public License along
316
+ with this program; if not, see <https://www.gnu.org/licenses/>.
317
+
318
+ Also add information on how to contact you by electronic and paper mail.
319
+
320
+ If the program is interactive, make it output a short notice like this
321
+ when it starts in an interactive mode:
322
+
323
+ Gnomovision version 69, Copyright (C) year name of author
324
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
325
+ This is free software, and you are welcome to redistribute it
326
+ under certain conditions; type `show c' for details.
327
+
328
+ The hypothetical commands `show w' and `show c' should show the appropriate
329
+ parts of the General Public License. Of course, the commands you use may
330
+ be called something other than `show w' and `show c'; they could even be
331
+ mouse-clicks or menu items--whatever suits your program.
332
+
333
+ You should also get your employer (if you work as a programmer) or your
334
+ school, if any, to sign a "copyright disclaimer" for the program, if
335
+ necessary. Here is a sample; alter the names:
336
+
337
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
338
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
339
+
340
+ <signature of Moe Ghoul>, 1 April 1989
341
+ Moe Ghoul, President of Vice
342
+
343
+ This General Public License does not permit incorporating your program into
344
+ proprietary programs. If your program is a subroutine library, you may
345
+ consider it more useful to permit linking proprietary applications with the
346
+ library. If this is what you want to do, use the GNU Lesser General
347
+ Public License instead of this License.
package/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # swaralipi-js
2
+
3
+ `@ugfoundation/swaralipi-js` — a JSON spec, a Unicode-Bengali viewer, a Tone.js player, and an NLTR converter for **Rabindrasangeet swaralipi** (Tagore's আকারমাত্রিক / *akarmatrik* notation).
4
+
5
+ The spec is the contract: write (or generate) a swaralipi **JSON document**, then hand the same document to the viewer, the player, or the printer. Built for [gitabitan.io](https://github.com/UGFoundation), published standalone under GPL-2.0-only.
6
+
7
+ ```sh
8
+ pnpm add @ugfoundation/swaralipi-js # or npm / yarn
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ The smallest useful program: validate a document and render it.
14
+
15
+ ```ts
16
+ import { parseSwaralipi } from '@ugfoundation/swaralipi-js/spec';
17
+ import { renderToHtml, SWARALIPI_CSS } from '@ugfoundation/swaralipi-js/viewer';
18
+
19
+ const doc = parseSwaralipi({
20
+ version: '0.1.0',
21
+ meta: { title: 'অকারণে', taal: { id: 'dadra', numBeats: 6 }, tonic: 'C' },
22
+ parts: [{ name: 'asthayi', rows: [{ notes: [
23
+ { svara: ['madhyam', 'm'], lyric: 'অ' },
24
+ { svara: ['madhyam', 'p'], lyric: 'কা' },
25
+ { sustain: true, lyric: '৹' },
26
+ { bar: 'single' },
27
+ ] }] }],
28
+ });
29
+
30
+ document.head.insertAdjacentHTML('beforeend', `<style>${SWARALIPI_CSS}</style>`);
31
+ document.body.innerHTML = renderToHtml(doc, { lang: 'bn' });
32
+ ```
33
+
34
+ ---
35
+
36
+ # Writing a swaralipi document
37
+
38
+ A document is a single JSON object: `{ version, meta, parts }`. A **part** is a section (আস্থায়ী / অন্তরা …) holding **rows** (written lines); a row holds **notes** (the tokens below). Build it by hand, generate it from a tool, or produce it with the [converter](#convert-nltr-html--json). Everything else in this package consumes this shape.
39
+
40
+ ```jsonc
41
+ {
42
+ "version": "0.1.0",
43
+ "meta": { /* see below */ },
44
+ "parts": [
45
+ { "name": "asthayi", "rows": [ { "notes": [ /* tokens */ ] } ] }
46
+ ]
47
+ }
48
+ ```
49
+
50
+ ### meta
51
+
52
+ Only `title` is required. The rest is optional but drives playback and the header.
53
+
54
+ ```jsonc
55
+ "meta": {
56
+ "title": "অকারণে অকালে মোর পড়ল যখন ডাক",
57
+ "taal": { "id": "dadra", "numBeats": 6, "bhaags": [3, 3], "sam": 0, "khaali": [3] },
58
+ "taalName": "দাদরা", // verbatim source name (use when `taal.id` is unknown)
59
+ "tonic": "C", // base pitch — "C", "C#"/"cs", "Db" all accepted
60
+ "bpm": 144, // default tempo, matra/min (player only; viewer ignores it)
61
+ "avartan": 2, // আবর্তন count, when the source states it
62
+ "notationBy": "…", "source": "…" // provenance
63
+ }
64
+ ```
65
+
66
+ ### svara — pitched notes
67
+
68
+ A pitch is a `[octave, letter]` tuple. Octaves: `ati-mandra`, `mandra`, `madhyam`, `taar`, `ati-taar`. Letters: `s r g m p d n` (`d`=ধৈবত/dha, `n`=নিষাদ/ni). Sharps/flats are **flags**, not letters:
69
+
70
+ ```jsonc
71
+ { "svara": ["madhyam", "g"] } // শুদ্ধ গ
72
+ { "svara": ["madhyam", "g"], "komal": true } // কোমল গ (flat)
73
+ { "svara": ["madhyam", "m"], "tivra": true } // কড়ি/তীব্র ম (sharp)
74
+ { "svara": ["taar", "s"] } // taar সা (high)
75
+ { "svara": ["mandra", "p"] } // mandra প (low)
76
+ { "svara": ["madhyam", "r"], "microtone": "atikomal" } // sub-komal: alpakomal | atikomal
77
+ ```
78
+
79
+ ### duration — matra groups
80
+
81
+ Default duration is **1 মাত্রা**. Use `durationMatra` for fractional or held notes; a run of fractions summing to a whole matra renders as one beamed group (`nsfa` → নর্সা):
82
+
83
+ ```jsonc
84
+ { "svara": ["madhyam", "n"], "durationMatra": 0.5 } // half-matra
85
+ { "svara": ["taar", "s"], "durationMatra": 0.5 } // …grouped with the one above
86
+ { "svara": ["madhyam", "p"], "durationMatra": 2 } // held two matras
87
+ ```
88
+
89
+ ### sustain (আ-কার) and melisma
90
+
91
+ ```jsonc
92
+ { "sustain": true, "lyric": "৹" } // hold prev pitch+vowel (আ-কার)
93
+ { "svara": ["taar", "s"], "sustain": true, "lyric": "৹" } // melisma: pitch moves, vowel continues
94
+ ```
95
+
96
+ ### rest (বিরাম)
97
+
98
+ ```jsonc
99
+ { "rest": true, "durationMatra": 1 } // silence for one matra
100
+ ```
101
+
102
+ ### bars — দাঁড়ি / দণ্ড
103
+
104
+ ```jsonc
105
+ { "bar": "dari" } // । vibhag separator inside the cycle
106
+ { "bar": "single" } // I end of one taal cycle (ফেরা)
107
+ { "bar": "double" } // II section / return-to-asthayi boundary
108
+ { "bar": "quad" } // IIII end of the song
109
+ ```
110
+
111
+ ### brackets — repeat / skip / alt
112
+
113
+ A bracket spans a range; the first note carries `edge: 'open'`, the last `edge: 'close'`.
114
+ `repeat` = `{}` গুন্ডবন্ধনী · `skip` = `()` omit on repeat · `alt` = `[]` changed-on-repeat.
115
+
116
+ ```jsonc
117
+ { "svara": ["madhyam", "s"], "brackets": [{ "kind": "repeat", "edge": "open" }] }
118
+ { "svara": ["madhyam", "r"], "brackets": [{ "kind": "repeat", "edge": "close" }] }
119
+ ```
120
+
121
+ ### kan (grace) and meend (glide)
122
+
123
+ ```jsonc
124
+ { "svara": ["madhyam", "n"], "kan": ["taar", "s"] } // কণ grace before the note
125
+ { "svara": ["madhyam", "p"], "meend": "start" } // মীড় slur start …
126
+ { "svara": ["madhyam", "g"], "meend": "end" } // … and end
127
+ ```
128
+
129
+ ### lyrics and annotations
130
+
131
+ `lyric` rides on the **note** (column-aligned, per-syllable). `above` / `below` attach recursive notes for alt-on-repeat passages, stop marks, or beat labels:
132
+
133
+ ```jsonc
134
+ { "svara": ["madhyam", "m"], "lyric": "অ",
135
+ "above": [{ "svara": ["madhyam", "p"] }] } // alt note printed above
136
+ ```
137
+
138
+ ### raw — lossless passthrough
139
+
140
+ Anything the converter can't decode is preserved verbatim in `raw` and rendered dimmed — **the spec is lossless by construction**, nothing is silently dropped. You rarely write `raw` by hand.
141
+
142
+ ```jsonc
143
+ { "raw": "w", "below": [/* … */] }
144
+ ```
145
+
146
+ ### Validate what you wrote
147
+
148
+ ```ts
149
+ import { parseSwaralipi, safeParseSwaralipi } from '@ugfoundation/swaralipi-js/spec';
150
+
151
+ parseSwaralipi(json); // returns typed Swaralipi, throws ZodError if invalid
152
+ safeParseSwaralipi(json); // { success, data | error } — no throw
153
+ ```
154
+
155
+ See [`fixtures/`](./fixtures) for worked documents — `octaves`, `microtones`, `matra-durations`, `repeat-brackets`, and the hand-checked `akarone` anchor.
156
+
157
+ ---
158
+
159
+ # Deploying the document
160
+
161
+ ## View: `<swaralipi-sheet>`
162
+
163
+ Renders the document as **Unicode Bengali + a CSS grid** — no images, no embedded font, no framework. Arcs, kan, bars, beat labels and annotations all render.
164
+
165
+ ```html
166
+ <script type="module">
167
+ import { defineSwaralipiSheet } from '@ugfoundation/swaralipi-js/viewer';
168
+ defineSwaralipiSheet();
169
+ </script>
170
+
171
+ <swaralipi-sheet src="/notation/4270.json" lang="bn"></swaralipi-sheet>
172
+ ```
173
+
174
+ Pass a URL via `src` or set the `doc` property directly. `lang` is `bn | hi | en` (Devanagari for `hi`, roman + octave dots for `en`); `hide-header`; `highlight('part.row.note')` for player sync. Styles are shadow-DOM-encapsulated, themeable via `--sw-font`, `--sw-size`, `--sw-cell-gap`, `--sw-hl`.
175
+
176
+ **SSR / static sites (Astro etc.)** — `renderToHtml` is a pure function (string in, string out, no DOM); emit it alongside `SWARALIPI_CSS`. See [Quick start](#quick-start).
177
+
178
+ ### Print / PDF
179
+
180
+ ```ts
181
+ import { printSwaralipi, renderPrintDocument } from '@ugfoundation/swaralipi-js/viewer';
182
+
183
+ printSwaralipi(doc, { lang: 'bn', title: 'song-name' }); // hidden-iframe → print dialog
184
+ const page = renderPrintDocument(doc); // full HTML string (new tab / headless)
185
+ ```
186
+
187
+ `document.querySelector('swaralipi-sheet').print()` is the element shortcut. PDF fidelity comes from the **browser's own engine** — the same Indic shaping (reph, conjuncts, matra) and CSS-drawn marks as the screen — so we deliberately avoid html2canvas/jsPDF, which can't shape Indic text.
188
+
189
+ ## Play: `SwaralipiPlayer`
190
+
191
+ A [Tone.js](https://tonejs.dev) player turns a document into audio — melody on **santoor / harmonium / violin / flute / grand piano**, a **tabla** loop (metronome for unrecorded taals), and a **tanpura** drone — and drives the viewer's highlight in sync. Tone is dynamically imported on first `play()`, so importing the module never touches `AudioContext` — safe in Node/SSR.
192
+
193
+ ```ts
194
+ import { SwaralipiPlayer } from '@ugfoundation/swaralipi-js/player';
195
+
196
+ const player = new SwaralipiPlayer(); // zero-config: samples from the project CDN
197
+ player.load(doc);
198
+ player.bindSheet(document.querySelector('swaralipi-sheet'), { autoScroll: true });
199
+
200
+ playButton.onclick = () => player.play(); // must be a user gesture (AudioContext)
201
+ ```
202
+
203
+ Controls: `setTonic('C#')`, `setBpm(120)`, `setInstrument(id)`, `setTaal(id|null)`, `setRhythm('tabla'|'metronome'|'none')`, `setTanpura(bool)`, `pause()` / `stop()` / `dispose()`. Each song loads only the samples covering its pitch range.
204
+
205
+ - **Self-host samples:** override `soundsBaseUrl` (layout: `santoor/<note>.mp3`, `tabla/<taal>/<taal><bpm>bpm.mp3`, `tanpura/<pc>.mp3`).
206
+ - **Add instruments:** `customInstruments: { sitar: { label, urls, baseUrl } }`.
207
+ - **Liveness:** `await player.checkInstruments()` → `{ id: available }`, to grey out picker options whose samples are down.
208
+
209
+ The pure, audio-free scheduler is exported too (`buildSchedule`, `svaraToMidi`, `parseTonic`, `INSTRUMENTS`, …) for a custom transport.
210
+
211
+ ## Convert: NLTR HTML → JSON
212
+
213
+ [NLTR's Rabindra Rachanabali](https://rabindra-rachanabali.nltr.org) renders swaralipi as HTML grids in the ASCII-encoded **Swarabitan** webfont. The converter decodes that codec into spec JSON, losslessly. Across the full 1,738-song corpus: 100% of files convert, **99.95%** of notation cells decode semantically, the rest preserved raw and reported.
214
+
215
+ ```sh
216
+ swaralipi convert 4270.html # spec JSON to stdout
217
+ swaralipi convert nltr/html -o out/ --report out/_report.json
218
+ ```
219
+
220
+ ```ts
221
+ import { convertNltrHtml } from '@ugfoundation/swaralipi-js/convert'; // Node-only subpath
222
+ const { doc, report } = convertNltrHtml(html, { nltrId: 4270 });
223
+ ```
224
+
225
+ ## Subpath exports
226
+
227
+ | Import | Environment |
228
+ |--------|-------------|
229
+ | `@ugfoundation/swaralipi-js` (root, re-exports `/spec`) | any |
230
+ | `@ugfoundation/swaralipi-js/spec` | any |
231
+ | `@ugfoundation/swaralipi-js/viewer` | browser / SSR |
232
+ | `@ugfoundation/swaralipi-js/player` | browser (Node/SSR-safe import) |
233
+ | `@ugfoundation/swaralipi-js/convert` | Node only |
234
+ | `swaralipi` CLI | Node |
235
+
236
+ ---
237
+
238
+ ## Develop
239
+
240
+ ```sh
241
+ pnpm install
242
+ pnpm build # tsup → dist/ (ESM + CJS + .d.ts)
243
+ pnpm test # vitest
244
+ pnpm check # tsc --noEmit
245
+ ```
246
+
247
+ Node 20 LTS (`.nvmrc`), pnpm 9. Contributions are welcome under a CLA — see [CONTRIBUTING.md](./CONTRIBUTING.md).
248
+
249
+ ## Credits
250
+
251
+ - **[NLTR](https://nltr.org)** (Society for Natural Language Technology Research) — the [Rabindra Rachanabali](https://rabindra-rachanabali.nltr.org) digital edition and its Swarabitan-encoded swaralipi are the source corpus this package decodes. Tagore's notation itself is in the public domain.
252
+ - **[sargam-spec](https://github.com/Studio-kalavati/sargam-spec)** by **Studio Kalavati** (EPL-2.0) — swaralipi-js's spec is an independent reimplementation that extends sargam-spec's format; we keep its `[octave, letter]` svara tuple and octave/letter conventions.
253
+ - **Audio samples**, all **CC-BY**: the default Salamander Grand Piano by Alexander Holm; harmonium / violin / flute from [tonejs-instruments](https://github.com/nbrosowsky/tonejs-instruments) by Nicholaus Brosowsky; santoor / tabla / tanpura / metronome redistributed on the project CDN.
254
+
255
+ ## License
256
+
257
+ GPL-2.0-only © Upal & Gopa Das Foundation. See [LICENSE](./LICENSE).
@@ -0,0 +1,47 @@
1
+ import { convertNltrHtml, aggregate, formatSummary } from './chunk-N3NNWAOW.js';
2
+ import './chunk-C6O7DYU5.js';
3
+ import './chunk-GWXI2HJA.js';
4
+ import { stat, readdir, mkdir, readFile, writeFile } from 'fs/promises';
5
+ import { join, basename } from 'path';
6
+
7
+ var nltrIdOf = (file) => {
8
+ const m = basename(file).match(/^(\d+)\.html$/);
9
+ return m ? Number(m[1]) : void 0;
10
+ };
11
+ var serialize = (doc, compact) => (compact ? JSON.stringify(doc) : JSON.stringify(doc, null, 2)) + "\n";
12
+ async function runConvert(input, opts = {}) {
13
+ const log = opts.log ?? ((line) => process.stderr.write(line + "\n"));
14
+ const stats = await stat(input);
15
+ const files = stats.isDirectory() ? (await readdir(input)).filter((f) => f.endsWith(".html")).sort((a, b) => (nltrIdOf(a) ?? 0) - (nltrIdOf(b) ?? 0) || a.localeCompare(b)).map((f) => join(input, f)) : [input];
16
+ const isDir = stats.isDirectory();
17
+ if (isDir && !opts.out) throw new Error("directory input requires -o <outDir>");
18
+ if (isDir && opts.out) await mkdir(opts.out, { recursive: true });
19
+ const reports = [];
20
+ const failures = [];
21
+ for (const file of files) {
22
+ try {
23
+ const html = await readFile(file, "utf8");
24
+ const { doc, report: report2 } = convertNltrHtml(html, { nltrId: nltrIdOf(file) });
25
+ reports.push(report2);
26
+ const json = serialize(doc, opts.compact);
27
+ if (isDir) {
28
+ const name = `${nltrIdOf(file) ?? basename(file, ".html")}.json`;
29
+ await writeFile(join(opts.out, name), json);
30
+ } else if (opts.out) {
31
+ await writeFile(opts.out, json);
32
+ } else {
33
+ process.stdout.write(json);
34
+ }
35
+ } catch (err) {
36
+ failures.push({ file: basename(file), error: err instanceof Error ? err.message : String(err) });
37
+ }
38
+ }
39
+ const report = aggregate(reports, failures);
40
+ if (opts.reportPath) await writeFile(opts.reportPath, serialize(report, false));
41
+ if (!opts.quiet) log(formatSummary(report));
42
+ return { exitCode: failures.length > 0 ? 1 : 0, report };
43
+ }
44
+
45
+ export { runConvert };
46
+ //# sourceMappingURL=batch-NF2Q2CFS.js.map
47
+ //# sourceMappingURL=batch-NF2Q2CFS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/convert/batch.ts"],"names":["report"],"mappings":"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","file":"batch-NF2Q2CFS.js","sourcesContent":["/**\n * File/dir conversion driver for the CLI (Node-only; not part of the\n * public `/convert` export). Continues past per-file failures and reports\n * them in the aggregate.\n */\nimport { mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';\nimport { basename, join } from 'node:path';\nimport { convertNltrHtml } from './index.js';\nimport { aggregate, formatSummary, type BatchFailure, type BatchReport, type FileReport } from './report.js';\n\nexport interface BatchOptions {\n /** Output file (single input) or directory (directory input). */\n out?: string;\n /** Write the aggregate report JSON here. */\n reportPath?: string;\n compact?: boolean;\n quiet?: boolean;\n /** Progress/summary sink (default stderr). */\n log?: (line: string) => void;\n}\n\nconst nltrIdOf = (file: string): number | undefined => {\n const m = basename(file).match(/^(\\d+)\\.html$/);\n return m ? Number(m[1]) : undefined;\n};\n\nconst serialize = (doc: unknown, compact: boolean | undefined): string =>\n (compact ? JSON.stringify(doc) : JSON.stringify(doc, null, 2)) + '\\n';\n\nexport async function runConvert(\n input: string,\n opts: BatchOptions = {},\n): Promise<{ exitCode: 0 | 1; report: BatchReport }> {\n const log = opts.log ?? ((line: string) => process.stderr.write(line + '\\n'));\n const stats = await stat(input);\n const files = stats.isDirectory()\n ? (await readdir(input))\n .filter((f) => f.endsWith('.html'))\n .sort((a, b) => (nltrIdOf(a) ?? 0) - (nltrIdOf(b) ?? 0) || a.localeCompare(b))\n .map((f) => join(input, f))\n : [input];\n\n const isDir = stats.isDirectory();\n if (isDir && !opts.out) throw new Error('directory input requires -o <outDir>');\n if (isDir && opts.out) await mkdir(opts.out, { recursive: true });\n\n const reports: FileReport[] = [];\n const failures: BatchFailure[] = [];\n for (const file of files) {\n try {\n const html = await readFile(file, 'utf8');\n const { doc, report } = convertNltrHtml(html, { nltrId: nltrIdOf(file) });\n reports.push(report);\n const json = serialize(doc, opts.compact);\n if (isDir) {\n const name = `${nltrIdOf(file) ?? basename(file, '.html')}.json`;\n await writeFile(join(opts.out!, name), json);\n } else if (opts.out) {\n await writeFile(opts.out, json);\n } else {\n process.stdout.write(json);\n }\n } catch (err) {\n failures.push({ file: basename(file), error: err instanceof Error ? err.message : String(err) });\n }\n }\n\n const report = aggregate(reports, failures);\n if (opts.reportPath) await writeFile(opts.reportPath, serialize(report, false));\n if (!opts.quiet) log(formatSummary(report));\n return { exitCode: failures.length > 0 ? 1 : 0, report };\n}\n"]}