wiki-plugin-rcngraph 0.1.16 → 0.1.18
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.
- package/client/rcngraph.js +132 -9
- package/package.json +1 -1
package/client/rcngraph.js
CHANGED
|
@@ -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}display:none" title="Choose the voice and how fast it speaks">⚙ 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
|
`)
|
|
@@ -419,7 +458,9 @@
|
|
|
419
458
|
const walk = curWalk(), open = !!walk
|
|
420
459
|
if (note) wk.heard = wk.i; else if (wk.playing) wk.heard = null
|
|
421
460
|
const $bar = $item.find('.walk-bar')
|
|
422
|
-
$bar.find('.walk-prev, .walk-next, .walk-play, .walk-count, .walk-voice, .walk-close').toggle(open)
|
|
461
|
+
$bar.find('.walk-prev, .walk-next, .walk-play, .walk-count, .walk-voice, .walk-voiceset, .walk-close').toggle(open)
|
|
462
|
+
$bar.find('.walk-voicepanel').toggle(open && !!wk.vp)
|
|
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) }
|
|
@@ -517,6 +582,57 @@
|
|
|
517
582
|
})
|
|
518
583
|
}
|
|
519
584
|
|
|
585
|
+
// Recordings live as files in this site's assets (assets/voice-files), one file per
|
|
586
|
+
// recording, named by its content. On save, any recording still held inside a walk
|
|
587
|
+
// (a data: URL from a walk editor) is uploaded there and replaced by the file's full
|
|
588
|
+
// address, so a page and its history keep only addresses, a recording is never
|
|
589
|
+
// stored twice, and a forked page still plays from the site that has the file.
|
|
590
|
+
// If the upload fails (not signed in, say) the recording stays inside the walk, so
|
|
591
|
+
// nothing is lost, and the next save that can upload moves it out.
|
|
592
|
+
const VOICE_FOLDER = 'voice-files'
|
|
593
|
+
function voiceSteps(walks) {
|
|
594
|
+
const out = []
|
|
595
|
+
for (const w of walks || []) for (const st of (w && w.steps) || []) {
|
|
596
|
+
for (const n of Object.keys((st && st.voices) || {})) {
|
|
597
|
+
const v = st.voices[n]
|
|
598
|
+
if (v && typeof v.audio === 'string' && /^data:audio\//.test(v.audio)) out.push(v)
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return out
|
|
602
|
+
}
|
|
603
|
+
async function voiceFile(dataUrl) {
|
|
604
|
+
const blob = await (await fetch(dataUrl)).blob()
|
|
605
|
+
const sum = new Uint8Array(await crypto.subtle.digest('SHA-256', await blob.arrayBuffer()))
|
|
606
|
+
const hex = [...sum.slice(0, 12)].map(b => b.toString(16).padStart(2, '0')).join('')
|
|
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'
|
|
608
|
+
const name = hex + '.' + ext
|
|
609
|
+
const url = location.origin + '/assets/' + VOICE_FOLDER + '/' + name
|
|
610
|
+
const have = await fetch(url, { method: 'HEAD', cache: 'no-store' }).then(r => r.ok, () => false)
|
|
611
|
+
if (!have) {
|
|
612
|
+
const form = new FormData()
|
|
613
|
+
form.append('assets', VOICE_FOLDER) // before the file: the server reads the folder first
|
|
614
|
+
form.append('uploads[]', blob, name)
|
|
615
|
+
const r = await fetch('/plugin/assets/upload', { method: 'POST', body: form, credentials: 'same-origin' })
|
|
616
|
+
if (!r.ok) throw new Error(r.status === 401 ? 'sign in to this wiki to save recordings as files' : 'upload failed (' + r.status + ')')
|
|
617
|
+
}
|
|
618
|
+
return url
|
|
619
|
+
}
|
|
620
|
+
// Move every embedded recording in these walks to a file; resolves to a note
|
|
621
|
+
// for the reader when some could not be moved, else ''.
|
|
622
|
+
async function voicesToFiles(walks) {
|
|
623
|
+
const vs = voiceSteps(walks)
|
|
624
|
+
let failed = '', n = 0
|
|
625
|
+
for (const v of vs) {
|
|
626
|
+
try { v.audio = await voiceFile(v.audio); n++ } catch (e) { failed = e.message || String(e) }
|
|
627
|
+
}
|
|
628
|
+
if (n) console.log('voice files: ' + n + ' recording' + (n === 1 ? '' : 's') + ' now point to assets/' + VOICE_FOLDER + ' (each file is uploaded once)')
|
|
629
|
+
return failed ? 'Recordings were kept inside the page: ' + failed + '.' : ''
|
|
630
|
+
}
|
|
631
|
+
function voiceNotice($item, msg) {
|
|
632
|
+
$item.find('.voice-note').remove()
|
|
633
|
+
if (msg) $item.append($('<div class="voice-note" style="font-size:12px;color:#92400e;padding:4px 0"></div>').text(msg))
|
|
634
|
+
}
|
|
635
|
+
|
|
520
636
|
function graphListener(event) {
|
|
521
637
|
if (!event.source || !event.source.opener) return
|
|
522
638
|
if (!event.data || event.data.toolType !== 'rcn-graph') return
|
|
@@ -533,12 +649,19 @@
|
|
|
533
649
|
}
|
|
534
650
|
case 'saveGraph': {
|
|
535
651
|
if (!pendingItem || !pending$item) break
|
|
536
|
-
pendingItem
|
|
537
|
-
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
652
|
+
const item = pendingItem, $item = pending$item
|
|
653
|
+
let g = data.graphJSON
|
|
654
|
+
const asText = typeof g === 'string'
|
|
655
|
+
try { if (asText) g = JSON.parse(g) } catch (e) { g = null }
|
|
656
|
+
const moved = g && voiceSteps(g.walks).length ? voicesToFiles(g.walks) : Promise.resolve('')
|
|
657
|
+
moved.then(note => {
|
|
658
|
+
item.graphJSON = g ? (asText ? JSON.stringify(g) : g) : data.graphJSON
|
|
659
|
+
item.svgString = data.svgString
|
|
660
|
+
wiki.pageHandler.put($item.parents('.page:first'), { type: 'edit', id: item.id, item })
|
|
661
|
+
renderContent($item, item)
|
|
662
|
+
bind($item, item)
|
|
663
|
+
voiceNotice($item, note)
|
|
664
|
+
})
|
|
542
665
|
break
|
|
543
666
|
}
|
|
544
667
|
case 'doInternalLink': {
|