@ugfoundation/swaralipi-js 0.7.5 → 0.7.7

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 (41) hide show
  1. package/dist/{batch-DLPDVNFK.js → batch-6MCPHHKF.js} +5 -5
  2. package/dist/{batch-DLPDVNFK.js.map → batch-6MCPHHKF.js.map} +1 -1
  3. package/dist/{chunk-YAXYP7BR.js → chunk-ALN4SWMS.js} +3 -3
  4. package/dist/{chunk-YAXYP7BR.js.map → chunk-ALN4SWMS.js.map} +1 -1
  5. package/dist/{chunk-UF5OSJRP.js → chunk-QM4CXKW2.js} +11 -3
  6. package/dist/chunk-QM4CXKW2.js.map +1 -0
  7. package/dist/{chunk-ZAK3QRDN.js → chunk-QQC6WVLJ.js} +4 -4
  8. package/dist/{chunk-ZAK3QRDN.js.map → chunk-QQC6WVLJ.js.map} +1 -1
  9. package/dist/{chunk-2SAZWTTK.js → chunk-TKTQCUKD.js} +5 -5
  10. package/dist/chunk-TKTQCUKD.js.map +1 -0
  11. package/dist/cli.cjs +1 -1
  12. package/dist/cli.cjs.map +1 -1
  13. package/dist/cli.js +3 -3
  14. package/dist/convert/index.cjs +1 -1
  15. package/dist/convert/index.cjs.map +1 -1
  16. package/dist/convert/index.js +3 -3
  17. package/dist/index.cjs +11 -1
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +2 -2
  22. package/dist/player/index.cjs +41 -7
  23. package/dist/player/index.cjs.map +1 -1
  24. package/dist/player/index.d.cts +15 -1
  25. package/dist/player/index.d.ts +15 -1
  26. package/dist/player/index.js +34 -8
  27. package/dist/player/index.js.map +1 -1
  28. package/dist/spec/index.cjs +11 -1
  29. package/dist/spec/index.cjs.map +1 -1
  30. package/dist/spec/index.d.cts +18 -4
  31. package/dist/spec/index.d.ts +18 -4
  32. package/dist/spec/index.js +2 -2
  33. package/dist/viewer/index.cjs +21 -5
  34. package/dist/viewer/index.cjs.map +1 -1
  35. package/dist/viewer/index.d.cts +0 -27
  36. package/dist/viewer/index.d.ts +0 -27
  37. package/dist/viewer/index.js +3 -4
  38. package/dist/viewer/index.js.map +1 -1
  39. package/package.json +1 -1
  40. package/dist/chunk-2SAZWTTK.js.map +0 -1
  41. package/dist/chunk-UF5OSJRP.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { SPEC_VERSION, graceNotes, parseSwaralipi, safeParseSwaralipi } from './spec/index.js';
1
+ export { SPEC_VERSION, graceNotes, hasKomal, hasTivra, parseSwaralipi, safeParseSwaralipi } from './spec/index.js';
2
2
  export { B as Bar, b as Bracket, G as Grace, M as Meta, c as Microtone, N as Note, O as Octave, P as Part, R as Row, d as Svara, a as SvaraLetter, S as Swaralipi, T as Taal, e as barSchema, f as bracketSchema, g as graceSchema, m as metaSchema, h as microtoneSchema, n as noteSchema, o as octaveSchema, p as partSchema, r as rowSchema, s as svaraLetterSchema, i as svaraSchema, j as swaralipiSchema, t as taalSchema } from './schema-DqBXPGkL.js';
3
3
  export { a as TAALS, T as TaalId } from './taals-CjzBuZ35.js';
4
4
  import 'zod';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { SPEC_VERSION, barSchema, bracketSchema, graceSchema, metaSchema, microtoneSchema, noteSchema, octaveSchema, parseSwaralipi, partSchema, rowSchema, safeParseSwaralipi, svaraLetterSchema, svaraSchema, swaralipiSchema, taalSchema } from './chunk-YAXYP7BR.js';
2
- export { TAALS, graceNotes } from './chunk-UF5OSJRP.js';
1
+ export { SPEC_VERSION, barSchema, bracketSchema, graceSchema, metaSchema, microtoneSchema, noteSchema, octaveSchema, parseSwaralipi, partSchema, rowSchema, safeParseSwaralipi, svaraLetterSchema, svaraSchema, swaralipiSchema, taalSchema } from './chunk-ALN4SWMS.js';
2
+ export { TAALS, graceNotes, hasKomal, hasTivra } from './chunk-QM4CXKW2.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -29,6 +29,14 @@ function graceNotes(grace) {
29
29
  return typeof grace[0] === "string" ? [{ svara: grace }] : grace;
30
30
  }
31
31
 
32
+ // src/spec/svara.ts
33
+ function hasKomal(letter) {
34
+ return letter === "r" || letter === "g" || letter === "d" || letter === "n";
35
+ }
36
+ function hasTivra(letter) {
37
+ return letter === "m";
38
+ }
39
+
32
40
  // src/player/pitch.ts
33
41
  var OCTAVE_OFFSET = {
34
42
  "ati-mandra": -2,
@@ -79,8 +87,8 @@ function svaraSemitone(note) {
79
87
  if (note.svara === void 0) return null;
80
88
  const [, letter] = note.svara;
81
89
  let semi = SHUDDHA[letter];
82
- if (note.komal === true || note.microtone !== void 0) semi -= 1;
83
- if (note.tivra === true) semi += 1;
90
+ if ((note.komal === true || note.microtone !== void 0) && hasKomal(letter)) semi -= 1;
91
+ if (note.tivra === true && hasTivra(letter)) semi += 1;
84
92
  return semi;
85
93
  }
86
94
  function svaraToMidi(note, tonicPc, baseOctave = 4) {
@@ -489,6 +497,7 @@ function createTanpura(Tone, base, stems = TANPURA_PCS) {
489
497
 
490
498
  // src/player/player.ts
491
499
  var STOP_FADE_SEC = 0.5;
500
+ var MEDIA_LEAD_SEC = 0.25;
492
501
  function midiRange(schedule) {
493
502
  let lo = Infinity;
494
503
  let hi = -Infinity;
@@ -502,6 +511,9 @@ function midiRange(schedule) {
502
511
  }
503
512
  return lo <= hi ? { lo, hi } : void 0;
504
513
  }
514
+ function playDurationSec(schedule, spb, rhythm) {
515
+ return schedule.totalBeats * spb + (rhythm !== "none" ? schedule.pickupBeats * spb : 0) + spb;
516
+ }
505
517
  async function loadedOrWarn(Tone) {
506
518
  try {
507
519
  await Tone.loaded();
@@ -582,6 +594,27 @@ var SwaralipiPlayer = class {
582
594
  const id = this.#taalId();
583
595
  return this.#opts.rhythm === "tabla" && id !== void 0 && SAMPLED_TAALS.has(id) && !!this.#opts.soundsBaseUrl;
584
596
  }
597
+ /**
598
+ * Length of one play-through in seconds, for a progress bar (the OS media
599
+ * session's, typically). Derived from the loaded notation on every read and
600
+ * never stored, because every input can move: re-engrave the document, drag
601
+ * the tempo, switch the rhythm off, and this changes with it. `Infinity` in
602
+ * taal mode (one avartan looping, no end — the value the Media Session spec
603
+ * reserves for exactly that), 0 with nothing loaded, and clamped by a preview
604
+ * cap when one is set, since that is when playback will really stop.
605
+ */
606
+ get durationSec() {
607
+ if (this.#taal !== void 0) return Infinity;
608
+ if (this.#doc === void 0) return 0;
609
+ const schedule = buildSchedule(this.#doc, { tonic: this.#opts.tonic, baseOctave: this.#opts.baseOctave });
610
+ const full = playDurationSec(schedule, 60 / this.#effectiveBpm(), this.#opts.rhythm);
611
+ return Math.min(full, this.#opts.previewLimitSec);
612
+ }
613
+ /** Seconds played so far, off the Transport's own clock — so it holds while
614
+ * paused, and reads 0 before the first play and after stop(). */
615
+ get positionSec() {
616
+ return this.#tone?.getTransport().seconds ?? 0;
617
+ }
585
618
  /* ----------------------------------------------------------------- */
586
619
  /* Loading + transport control */
587
620
  /* ----------------------------------------------------------------- */
@@ -894,6 +927,7 @@ var SwaralipiPlayer = class {
894
927
  }
895
928
  const draw = Tone.getDraw();
896
929
  const shift = this.#opts.rhythm !== "none" ? schedule.pickupBeats * spb : 0;
930
+ const mediaLead = Math.min(MEDIA_LEAD_SEC, spb);
897
931
  schedule.events.forEach((ev, i) => {
898
932
  const at = ev.beat * spb + shift;
899
933
  if (ev.midi !== null && ev.glide !== true) {
@@ -927,12 +961,12 @@ var SwaralipiPlayer = class {
927
961
  transport.scheduleOnce((time) => melody.triggerAttackRelease(name, dur, time), at);
928
962
  }
929
963
  }
930
- transport.scheduleOnce((time) => {
931
- this.#opts.onEvent?.(ev.path);
932
- draw.schedule(() => this.#emitHighlight(ev.path), time);
933
- }, at);
964
+ if (this.#opts.onEvent !== void 0) {
965
+ transport.scheduleOnce(() => this.#opts.onEvent?.(ev.path), Math.max(at - mediaLead, 0));
966
+ }
967
+ transport.scheduleOnce((time) => draw.schedule(() => this.#emitHighlight(ev.path), time), at);
934
968
  });
935
- const endAt = schedule.totalBeats * spb + shift + spb;
969
+ const endAt = playDurationSec(schedule, spb, this.#opts.rhythm);
936
970
  transport.scheduleOnce((time) => {
937
971
  this.#opts.onEvent?.(null);
938
972
  draw.schedule(() => this.#emitHighlight(null), time);