wiki-plugin-rcntimeline 0.3.8 → 0.3.9

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.
@@ -478,6 +478,36 @@
478
478
  try { on = localStorage.getItem('rcnWalkVoice') !== 'off' } catch (e) {}
479
479
  return { voice: p.voice || '', rate: (+p.rate >= 0.6 && +p.rate <= 1.4) ? +p.rate : 0.95, on }
480
480
  }
481
+ function walkSetPref (k, v) {
482
+ let p = {}
483
+ try { p = JSON.parse(localStorage.getItem('rcnWalkPrefs') || '{}') } catch (e) {}
484
+ p[k] = v
485
+ try { localStorage.setItem('rcnWalkPrefs', JSON.stringify(p)) } catch (e) {}
486
+ }
487
+ // The ⚙ Voice panel (Nov 8 2026): the Graph Tool's voice and speed controls, the
488
+ // same rcnWalkPrefs keys, so a choice made here holds in the tools and other plugins.
489
+ const goodVoice = v => /Enhanced|Premium|Natural|Neural/i.test(v.name)
490
+ function voiceOptions () {
491
+ const vs = window.speechSynthesis ? speechSynthesis.getVoices().filter(v => /^en/i.test(v.lang)) : []
492
+ if (!vs.length) return '<option value="">No voices found in this browser</option>'
493
+ const cur = walkVoice(walkPrefs().voice)
494
+ return vs.slice().sort((a, b) => (goodVoice(b) - goodVoice(a)) || a.name.localeCompare(b.name))
495
+ .map(v => `<option value="${esc(v.name)}"${cur && cur.name === v.name ? ' selected' : ''}>${goodVoice(v) ? '★ ' : ''}${esc(v.name)} (${esc(v.lang)})</option>`).join('')
496
+ }
497
+ function voiceHint () {
498
+ const vs = window.speechSynthesis ? speechSynthesis.getVoices().filter(v => /^en/i.test(v.lang)) : []
499
+ const mac = /Mac/i.test(navigator.platform || navigator.userAgent)
500
+ return vs.some(goodVoice) ? '★ marks the more natural voices. Speed is for the computer voice; a recording plays as it was recorded.'
501
+ : mac ? 'No natural-sounding voice is installed. On a Mac: System Settings → Accessibility → Spoken Content → System voice → Manage Voices… Download an English voice marked Enhanced or Premium, then quit the browser (⌘Q) and open it again: reloading the page is not enough.'
502
+ : 'No natural-sounding voice is installed. Your system’s speech settings can add more voices; reload this page after.'
503
+ }
504
+ function voiceSample () {
505
+ if (!window.speechSynthesis) return
506
+ const p = walkPrefs(), v = walkVoice(p.voice), u = new SpeechSynthesisUtterance('This is how a walk will sound.')
507
+ if (v) { u.voice = v; u.lang = v.lang }
508
+ u.rate = p.rate
509
+ speechSynthesis.speak(u)
510
+ }
481
511
  function walkVoice (name) {
482
512
  const vs = window.speechSynthesis ? speechSynthesis.getVoices().filter(v => /^en/i.test(v.lang)) : []
483
513
  return vs.find(v => v.name === name) || vs.find(v => /Enhanced|Premium|Natural|Neural/i.test(v.name)) ||
@@ -585,8 +615,17 @@
585
615
  <span class="walk-count" style="display:none;font-size:12px;color:#64748b;min-width:70px;text-align:center"></span>
586
616
  <button class="walk-voice" style="${b}display:none" title="Read the words aloud, or show them only"></button>
587
617
  <select class="walk-speaker" style="font-size:12px;max-width:170px;display:none" title="Whose voice reads the walk (kept in this browser)"></select>
618
+ <button class="walk-voiceset" style="${b}display:none" title="Choose the voice and how fast it speaks">⚙ Voice</button>
588
619
  <button class="walk-close" style="${b}display:none" title="Stop the walk (Esc)">■ Stop</button>
589
620
  </div>
621
+ <div class="walk-voicepanel" style="display:none;margin:6px 4px 0;padding:8px 10px;background:#eef2ff;border-radius:8px;font-size:12px;color:#374151">
622
+ <div style="display:flex;flex-wrap:wrap;gap:8px 14px;align-items:center;justify-content:center">
623
+ <label>Voice <select class="walk-voicesel" style="font-size:12px;max-width:260px" title="Which computer voice reads the walk (kept in this browser)"></select></label>
624
+ <label>Speed <input class="walk-rate" type="range" min="0.6" max="1.4" step="0.05" style="vertical-align:middle"> <span class="walk-rate-val"></span></label>
625
+ <button class="walk-sample" style="${b}" title="Hear the chosen voice at the chosen speed">Hear a sample</button>
626
+ </div>
627
+ <div class="walk-voicehint" style="font-size:11px;color:#6b7280;text-align:center;margin-top:4px"></div>
628
+ </div>
590
629
  <div class="walk-say" aria-live="polite" style="display:none;margin:8px 4px 0;padding:10px 12px;background:#fff;border:1px solid #c7d2fe;border-radius:8px;font-size:17px;line-height:1.45;color:#1e1b4b"></div>
591
630
  <div class="walk-note" style="font-size:11px;color:#64748b;text-align:center;margin-top:3px"></div>
592
631
  </div>`
@@ -602,7 +641,9 @@
602
641
  const ui = note => {
603
642
  const walk = cur(), open = !!walk
604
643
  const $bar = $item.find('.walk-bar')
605
- $bar.find('.walk-prev, .walk-next, .walk-play, .walk-count, .walk-voice, .walk-close').toggle(open)
644
+ $bar.find('.walk-prev, .walk-next, .walk-play, .walk-count, .walk-voice, .walk-voiceset, .walk-close').toggle(open)
645
+ $bar.find('.walk-voicepanel').toggle(open && !!wk.vp)
646
+ $bar.find('.walk-voiceset').css('background', wk.vp ? '#eef2ff' : '')
606
647
  $bar.find('.walk-start, .walk-pick').toggle(!open)
607
648
  $bar.find('.walk-say').toggle(open)
608
649
  $bar.find('.walk-play').text(wk.playing ? '❚❚' : '▶')
@@ -669,6 +710,29 @@
669
710
  $item.on('click.rcntwalk', '.walk-next', () => show(wk.i + 1))
670
711
  $item.on('click.rcntwalk', '.walk-close', () => end())
671
712
  $item.on('change.rcntwalk', '.walk-speaker', e => { recSetSpeaker(e.target.value); if (wk.playing) speak() })
713
+ const fillVoices = () => {
714
+ const p = walkPrefs()
715
+ $item.find('.walk-voicesel').html(voiceOptions())
716
+ $item.find('.walk-rate').val(p.rate)
717
+ $item.find('.walk-rate-val').text(Math.round(p.rate * 100) + '%')
718
+ $item.find('.walk-voicehint').text(voiceHint())
719
+ }
720
+ const sample = () => { pause(); voiceSample() }
721
+ $item.on('click.rcntwalk', '.walk-voiceset', () => { wk.vp = !wk.vp; if (wk.vp) fillVoices(); ui() })
722
+ $item.on('change.rcntwalk', '.walk-voicesel', e => { walkSetPref('voice', e.target.value); sample() })
723
+ $item.on('input.rcntwalk', '.walk-rate', e => {
724
+ const r = Math.max(0.6, Math.min(1.4, +e.target.value || 0.95))
725
+ walkSetPref('rate', r)
726
+ $item.find('.walk-rate-val').text(Math.round(r * 100) + '%')
727
+ })
728
+ $item.on('click.rcntwalk', '.walk-sample', () => sample())
729
+ // Voices arrive late in Chrome; refresh an open panel when they do.
730
+ // One listener per item however often it redraws; it calls this binding's fillVoices.
731
+ el.rcntFillVoices = fillVoices
732
+ if (!el.rcntVoiceListen && window.speechSynthesis && speechSynthesis.addEventListener) {
733
+ el.rcntVoiceListen = true
734
+ speechSynthesis.addEventListener('voiceschanged', () => { if (wk.vp && document.body.contains(el) && el.rcntFillVoices) el.rcntFillVoices() })
735
+ }
672
736
  $item.on('click.rcntwalk', '.walk-voice', () => {
673
737
  const on = !walkPrefs().on
674
738
  try { localStorage.setItem('rcnWalkVoice', on ? 'on' : 'off') } catch (e) {}
@@ -677,7 +741,7 @@
677
741
  ui()
678
742
  })
679
743
  $item.on('keydown.rcntwalk', '.walk-bar', e => {
680
- if (wk.w === null || $(e.target).is('select')) return
744
+ if (wk.w === null || $(e.target).is('select, input')) return
681
745
  if (e.key === ' ') { e.preventDefault(); e.stopPropagation(); toggle() }
682
746
  else if (e.key === 'ArrowRight') { e.preventDefault(); e.stopPropagation(); show(wk.i + 1) }
683
747
  else if (e.key === 'ArrowLeft') { e.preventDefault(); e.stopPropagation(); show(wk.i - 1) }
@@ -797,7 +861,7 @@
797
861
  const blob = await (await fetch(dataUrl)).blob()
798
862
  const sum = new Uint8Array(await crypto.subtle.digest('SHA-256', await blob.arrayBuffer()))
799
863
  const hex = [...sum.slice(0, 12)].map(b => b.toString(16).padStart(2, '0')).join('')
800
- const ext = /mp4|m4a|aac/.test(blob.type) ? 'm4a' : /wav/.test(blob.type) ? 'wav' : /ogg/.test(blob.type) ? 'ogg' : 'webm'
864
+ const ext = /mpeg|mp3/.test(blob.type) ? 'mp3' : /mp4|m4a|aac/.test(blob.type) ? 'm4a' : /wav/.test(blob.type) ? 'wav' : /ogg/.test(blob.type) ? 'ogg' : 'webm'
801
865
  const name = hex + '.' + ext
802
866
  const url = location.origin + '/assets/' + VOICE_FOLDER + '/' + name
803
867
  const have = await fetch(url, { method: 'HEAD', cache: 'no-store' }).then(r => r.ok, () => false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcntimeline",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Federated Wiki plugin: a small RCN timeline on a page — intervals with fuzzy edges, the links between them, a date axis; each bar opens its page",
5
5
  "keywords": [
6
6
  "wiki",