wiki-plugin-rcngraph 0.1.17 → 0.1.19

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 (2) hide show
  1. package/client/rcngraph.js +68 -3
  2. package/package.json +1 -1
@@ -196,6 +196,36 @@
196
196
  try { on = localStorage.getItem('rcnWalkVoice') !== 'off' } catch (e) {}
197
197
  return { voice: p.voice || '', rate: (+p.rate >= 0.6 && +p.rate <= 1.4) ? +p.rate : 0.95, on }
198
198
  }
199
+ function walkSetPref(k, v) {
200
+ let p = {}
201
+ try { p = JSON.parse(localStorage.getItem('rcnWalkPrefs') || '{}') } catch (e) {}
202
+ p[k] = v
203
+ try { localStorage.setItem('rcnWalkPrefs', JSON.stringify(p)) } catch (e) {}
204
+ }
205
+ // The ⚙ Voice panel (Nov 8 2026): the Graph Tool's voice and speed controls, the
206
+ // same rcnWalkPrefs keys, so a choice made here holds in the tools and other plugins.
207
+ const goodVoice = v => /Enhanced|Premium|Natural|Neural/i.test(v.name)
208
+ const enVoices = () => window.speechSynthesis ? speechSynthesis.getVoices().filter(v => /^en/i.test(v.lang)) : []
209
+ function voiceOptions() {
210
+ const vs = enVoices()
211
+ if (!vs.length) return '<option value="">No voices found in this browser</option>'
212
+ const cur = walkVoice(walkPrefs().voice)
213
+ return vs.slice().sort((a, b) => (goodVoice(b) - goodVoice(a)) || a.name.localeCompare(b.name))
214
+ .map(v => `<option value="${esc(v.name)}"${cur && cur.name === v.name ? ' selected' : ''}>${goodVoice(v) ? '★ ' : ''}${esc(v.name)} (${esc(v.lang)})</option>`).join('')
215
+ }
216
+ function voiceHint() {
217
+ const mac = /Mac/i.test(navigator.platform || navigator.userAgent)
218
+ return enVoices().some(goodVoice) ? '★ marks the more natural voices. Speed is for the computer voice; a recording plays as it was recorded.'
219
+ : 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.'
220
+ : 'No natural-sounding voice is installed. Your system’s speech settings can add more voices; reload this page after.'
221
+ }
222
+ function voiceSample() {
223
+ if (!window.speechSynthesis) return
224
+ const p = walkPrefs(), v = walkVoice(p.voice), u = new SpeechSynthesisUtterance('This is how a walk will sound.')
225
+ if (v) { u.voice = v; u.lang = v.lang }
226
+ u.rate = p.rate
227
+ speechSynthesis.speak(u)
228
+ }
199
229
  function walkVoice(name) {
200
230
  const vs = window.speechSynthesis ? speechSynthesis.getVoices().filter(v => /^en/i.test(v.lang)) : []
201
231
  return vs.find(v => v.name === name) || vs.find(v => /Enhanced|Premium|Natural|Neural/i.test(v.name)) ||
@@ -289,8 +319,17 @@
289
319
  <span class="walk-count" style="display:none;font-size:12px;color:#64748b;min-width:70px;text-align:center"></span>
290
320
  <button class="walk-voice" style="${b}display:none" title="Read the words aloud, or show them only"></button>
291
321
  <select class="walk-speaker" style="font-size:12px;max-width:170px;display:none" title="Whose voice reads the walk (kept in this browser)"></select>
322
+ <button class="walk-voiceset" style="${b}" title="Choose which voice reads the walk, and how fast">⚙ Choose voice</button>
292
323
  <button class="walk-close" style="${b}display:none" title="Stop the walk (Esc)">■ Stop</button>
293
324
  </div>
325
+ <div class="walk-voicepanel" style="display:none;margin:6px 4px 0;padding:8px 10px;background:#eef2ff;border-radius:8px;font-size:12px;color:#374151">
326
+ <div style="display:flex;flex-wrap:wrap;gap:8px 14px;align-items:center;justify-content:center">
327
+ <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>
328
+ <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>
329
+ <button class="walk-sample" style="${b}" title="Hear the chosen voice at the chosen speed">Hear a sample</button>
330
+ </div>
331
+ <div class="walk-voicehint" style="font-size:11px;color:#6b7280;text-align:center;margin-top:4px"></div>
332
+ </div>
294
333
  <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>
295
334
  <div class="walk-note" style="font-size:11px;color:#64748b;text-align:center;margin-top:3px"></div>
296
335
  </div>`
@@ -317,7 +356,7 @@
317
356
  $item.append(`
318
357
  <div style="background-color:#eee;padding:15px;text-align:center;">
319
358
  <p style="font-weight:bold;margin:0 0 6px;">RCN Graph Tool</p>
320
- <p style="color:#666;font-size:0.85em;margin:0 0 12px;">CLD · EIP · NRM · Trace · Wardley · OPM · SFD · LOP · VSM</p>
359
+ <p style="color:#666;font-size:0.85em;margin:0 0 12px;">CLD · EIP · NRM · Trace · Wardley · OPM · SFD · LOP · VSM · IBIS</p>
321
360
  <button class="open-graph" style="cursor:pointer;">Open Graph Tool ↗</button>
322
361
  </div>
323
362
  `)
@@ -420,6 +459,8 @@
420
459
  if (note) wk.heard = wk.i; else if (wk.playing) wk.heard = null
421
460
  const $bar = $item.find('.walk-bar')
422
461
  $bar.find('.walk-prev, .walk-next, .walk-play, .walk-count, .walk-voice, .walk-close').toggle(open)
462
+ $bar.find('.walk-voicepanel').toggle(!!wk.vp) // before a walk starts too: choose first, then listen
463
+ $bar.find('.walk-voiceset').css('background', wk.vp ? '#eef2ff' : '')
423
464
  $bar.find('.walk-start, .walk-pick').toggle(!open)
424
465
  $bar.find('.walk-say').toggle(open)
425
466
  $bar.find('.walk-play').text(wk.playing ? '❚❚' : '▶')
@@ -487,6 +528,30 @@
487
528
  $item.on('click.rcnwalk', '.walk-next', () => walkShow(wk.i + 1))
488
529
  $item.on('click.rcnwalk', '.walk-close', () => walkEnd())
489
530
  $item.on('change.rcnwalk', '.walk-speaker', e => { recSetSpeaker(e.target.value); if (wk.playing) walkSpeak() })
531
+ const fillVoices = () => {
532
+ const p = walkPrefs()
533
+ $item.find('.walk-voicesel').html(voiceOptions())
534
+ $item.find('.walk-rate').val(p.rate)
535
+ $item.find('.walk-rate-val').text(Math.round(p.rate * 100) + '%')
536
+ $item.find('.walk-voicehint').text(voiceHint())
537
+ }
538
+ const sample = () => { walkPause(); voiceSample() }
539
+ $item.on('click.rcnwalk', '.walk-voiceset', () => { wk.vp = !wk.vp; if (wk.vp) fillVoices(); walkUI() })
540
+ $item.on('change.rcnwalk', '.walk-voicesel', e => { walkSetPref('voice', e.target.value); sample() })
541
+ $item.on('input.rcnwalk', '.walk-rate', e => {
542
+ const r = Math.max(0.6, Math.min(1.4, +e.target.value || 0.95))
543
+ walkSetPref('rate', r)
544
+ $item.find('.walk-rate-val').text(Math.round(r * 100) + '%')
545
+ })
546
+ $item.on('click.rcnwalk', '.walk-sample', () => sample())
547
+ // Voices arrive late in Chrome; refresh an open panel when they do. One listener
548
+ // per item however often it is bound; it calls the latest binding's fillVoices.
549
+ const el0 = $item.get(0)
550
+ el0.rcnFillVoices = () => { if (wk.vp) fillVoices() }
551
+ if (!el0.rcnVoiceListen && window.speechSynthesis && speechSynthesis.addEventListener) {
552
+ el0.rcnVoiceListen = true
553
+ speechSynthesis.addEventListener('voiceschanged', () => { if (document.body.contains(el0) && el0.rcnFillVoices) el0.rcnFillVoices() })
554
+ }
490
555
  $item.on('click.rcnwalk', '.walk-voice', () => {
491
556
  const on = !walkPrefs().on
492
557
  try { localStorage.setItem('rcnWalkVoice', on ? 'on' : 'off') } catch (e) {}
@@ -497,7 +562,7 @@
497
562
  // Clicking the drawing to look closer pauses the voice.
498
563
  $item.on('pointerdown.rcnwalk', '.graph-box', () => { if (wk.playing) walkPause() })
499
564
  $item.on('keydown.rcnwalk', '.walk-bar', e => {
500
- if (wk.w === null || $(e.target).is('select')) return
565
+ if (wk.w === null || $(e.target).is('select, input')) return
501
566
  if (e.key === ' ') { e.preventDefault(); e.stopPropagation(); walkToggle() }
502
567
  else if (e.key === 'ArrowRight') { e.preventDefault(); e.stopPropagation(); walkShow(wk.i + 1) }
503
568
  else if (e.key === 'ArrowLeft') { e.preventDefault(); e.stopPropagation(); walkShow(wk.i - 1) }
@@ -539,7 +604,7 @@
539
604
  const blob = await (await fetch(dataUrl)).blob()
540
605
  const sum = new Uint8Array(await crypto.subtle.digest('SHA-256', await blob.arrayBuffer()))
541
606
  const hex = [...sum.slice(0, 12)].map(b => b.toString(16).padStart(2, '0')).join('')
542
- const ext = /mp4|m4a|aac/.test(blob.type) ? 'm4a' : /wav/.test(blob.type) ? 'wav' : /ogg/.test(blob.type) ? 'ogg' : 'webm'
607
+ 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'
543
608
  const name = hex + '.' + ext
544
609
  const url = location.origin + '/assets/' + VOICE_FOLDER + '/' + name
545
610
  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-rcngraph",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Federated Wiki - RCN Graph Plug-in",
5
5
  "keywords": [
6
6
  "wiki",