wiki-plugin-rcngraph 0.1.14 → 0.1.16

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.
@@ -178,17 +178,6 @@
178
178
  const el = groupFor(svg, 'node', n.id)
179
179
  if (!el) return
180
180
  el.style.opacity = op('nodes', String(n.id))
181
- // A ring on what this step brings in for the first time.
182
- if (lit && lit.nodes.has(String(n.id)) && !seen.nodes.has(String(n.id)) && n.w && n.h) {
183
- const r = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse')
184
- r.setAttribute('class', 'rcn-walk-ring')
185
- r.setAttribute('cx', '0'); r.setAttribute('cy', '0')
186
- r.setAttribute('rx', String(n.w / 2 + 9)); r.setAttribute('ry', String(n.h / 2 + 9))
187
- r.setAttribute('fill', 'none'); r.setAttribute('stroke', BUILD_COLOR)
188
- r.setAttribute('stroke-width', '3'); r.setAttribute('opacity', '.8')
189
- r.setAttribute('pointer-events', 'none')
190
- el.appendChild(r)
191
- }
192
181
  })
193
182
  g.edges.forEach(e => {
194
183
  const el = groupFor(svg, 'edge', e.id)
@@ -180,17 +180,6 @@
180
180
  const el = groupFor(svg, 'node', n.id)
181
181
  if (!el) return
182
182
  el.style.opacity = op('nodes', String(n.id))
183
- // A ring on what this step brings in for the first time.
184
- if (lit && lit.nodes.has(String(n.id)) && !seen.nodes.has(String(n.id)) && n.w && n.h) {
185
- const r = document.createElementNS('http://www.w3.org/2000/svg', 'ellipse')
186
- r.setAttribute('class', 'rcn-walk-ring')
187
- r.setAttribute('cx', '0'); r.setAttribute('cy', '0')
188
- r.setAttribute('rx', String(n.w / 2 + 9)); r.setAttribute('ry', String(n.h / 2 + 9))
189
- r.setAttribute('fill', 'none'); r.setAttribute('stroke', BUILD_COLOR)
190
- r.setAttribute('stroke-width', '3'); r.setAttribute('opacity', '.8')
191
- r.setAttribute('pointer-events', 'none')
192
- el.appendChild(r)
193
- }
194
183
  })
195
184
  g.edges.forEach(e => {
196
185
  const el = groupFor(svg, 'edge', e.id)
@@ -232,6 +221,55 @@
232
221
  })
233
222
  }
234
223
 
224
+ // People's own recordings of a step, made in the Graph Tool, Map or Timeline walk
225
+ // editor: step.voices = {name: {audio, say}}. A step plays its recording when it has
226
+ // one, else the computer voice. The listener picks whose, kept in this browser with
227
+ // the other walk settings (rcnWalkPrefs.speaker: '' any, '-' computer only, or a name).
228
+ let recAudio = null
229
+ const recOk = src => typeof src === 'string' && /^(data:audio\/|https?:\/\/|\/)/.test(src)
230
+ const recNames = st => st && st.voices ? Object.keys(st.voices).filter(n => st.voices[n] && recOk(st.voices[n].audio)) : []
231
+ const recSpeakers = walk => [...new Set(((walk && walk.steps) || []).flatMap(recNames))].sort()
232
+ function recSpeaker() {
233
+ try { return JSON.parse(localStorage.getItem('rcnWalkPrefs') || '{}').speaker || '' } catch (e) { return '' }
234
+ }
235
+ function recSetSpeaker(v) {
236
+ let p = {}
237
+ try { p = JSON.parse(localStorage.getItem('rcnWalkPrefs') || '{}') } catch (e) {}
238
+ p.speaker = v
239
+ try { localStorage.setItem('rcnWalkPrefs', JSON.stringify(p)) } catch (e) {}
240
+ }
241
+ function recSpeakerOptions(walk) {
242
+ const ns = recSpeakers(walk), cur = recSpeaker()
243
+ if (!ns.length) return ''
244
+ const opt = (v, label) => `<option value="${esc(v)}"${cur === v ? ' selected' : ''}>${esc(label)}</option>`
245
+ return opt('', 'Recorded voices') + ns.map(n => opt(n, 'Recorded: ' + n)).join('') + opt('-', 'Computer voice only')
246
+ }
247
+ function recHush() {
248
+ const a = recAudio
249
+ recAudio = null
250
+ if (a) { a.onended = a.onerror = null; try { a.pause() } catch (e) {} }
251
+ }
252
+ // Say a step: a person's recording when it has one, else the computer voice.
253
+ function walkSayStep(st, isCurrent, done) {
254
+ const ns = recNames(st), want = recSpeaker()
255
+ if (!walkPrefs().on || want === '-' || !ns.length) { walkSay(st.say, isCurrent, done); return }
256
+ try { if (window.speechSynthesis) speechSynthesis.cancel() } catch (e) {}
257
+ recHush()
258
+ const a = new Audio(st.voices[ns.includes(want) ? want : ns[0]].audio)
259
+ recAudio = a
260
+ let out = false
261
+ const fin = ok => {
262
+ if (out || recAudio !== a) return
263
+ out = true; recAudio = null
264
+ if (!isCurrent()) return
265
+ if (ok) done(); else walkSay(st.say, isCurrent, done)
266
+ }
267
+ a.onended = () => fin(true)
268
+ a.onerror = () => fin(false)
269
+ const p = a.play()
270
+ if (p && p.catch) p.catch(() => fin(false))
271
+ }
272
+
235
273
  function walkBar(item) {
236
274
  const g = graphModel(item)
237
275
  const ws = walkList(g)
@@ -250,6 +288,7 @@
250
288
  <button class="walk-next" style="${b}display:none" title="Next step (→)">▶</button>
251
289
  <span class="walk-count" style="display:none;font-size:12px;color:#64748b;min-width:70px;text-align:center"></span>
252
290
  <button class="walk-voice" style="${b}display:none" title="Read the words aloud, or show them only"></button>
291
+ <select class="walk-speaker" style="font-size:12px;max-width:170px;display:none" title="Whose voice reads the walk (kept in this browser)"></select>
253
292
  <button class="walk-close" style="${b}display:none" title="Stop the walk (Esc)">■ Stop</button>
254
293
  </div>
255
294
  <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>
@@ -375,7 +414,7 @@
375
414
  // so a step that was skipped or stopped can never move the walk on.
376
415
  const wk = { w: null, i: 0, playing: false, token: 0, heard: null }
377
416
  const curWalk = () => { const g = graphModel(item); return g && wk.w !== null ? walkList(g)[wk.w] : null }
378
- const stopVoice = () => { wk.token++; try { if (window.speechSynthesis) speechSynthesis.cancel() } catch (e) {} }
417
+ const stopVoice = () => { wk.token++; recHush(); try { if (window.speechSynthesis) speechSynthesis.cancel() } catch (e) {} }
379
418
  const walkUI = note => {
380
419
  const walk = curWalk(), open = !!walk
381
420
  if (note) wk.heard = wk.i; else if (wk.playing) wk.heard = null
@@ -385,6 +424,9 @@
385
424
  $bar.find('.walk-say').toggle(open)
386
425
  $bar.find('.walk-play').text(wk.playing ? '❚❚' : '▶')
387
426
  $bar.find('.walk-voice').text(walkPrefs().on ? '🔈 Voice on' : '🔇 Voice off')
427
+ const so = open ? recSpeakerOptions(walk) : '', $sp = $bar.find('.walk-speaker')
428
+ if ($sp.data('opts') !== so) $sp.html(so).data('opts', so)
429
+ $sp.toggle(!!so)
388
430
  $bar.find('.walk-count').text(open ? 'Step ' + (wk.i + 1) + ' of ' + walk.steps.length : '')
389
431
  $bar.find('.walk-note').text(note || (open && !wk.playing ? 'Space plays · ← → step · Esc stops' : ''))
390
432
  }
@@ -402,7 +444,7 @@
402
444
  const walkSpeak = () => {
403
445
  const tok = ++wk.token, walk = curWalk(), st = walk && walk.steps[wk.i]
404
446
  if (!st) return
405
- walkSay(st.say, () => tok === wk.token && activeWalk === wk, () => {
447
+ walkSayStep(st, () => tok === wk.token && activeWalk === wk, () => {
406
448
  const last = wk.i >= walk.steps.length - 1
407
449
  if (st.ask || last) { wk.playing = false; walkUI(last && !st.ask ? 'End of the walk. ← to go back, Esc to stop.' : 'Over to you. Press Space or ▶ to go on.'); return }
408
450
  setTimeout(() => { if (tok === wk.token && wk.playing) walkShow(wk.i + 1) }, 800)
@@ -444,6 +486,7 @@
444
486
  $item.on('click.rcnwalk', '.walk-prev', () => walkShow(wk.i - 1))
445
487
  $item.on('click.rcnwalk', '.walk-next', () => walkShow(wk.i + 1))
446
488
  $item.on('click.rcnwalk', '.walk-close', () => walkEnd())
489
+ $item.on('change.rcnwalk', '.walk-speaker', e => { recSetSpeaker(e.target.value); if (wk.playing) walkSpeak() })
447
490
  $item.on('click.rcnwalk', '.walk-voice', () => {
448
491
  const on = !walkPrefs().on
449
492
  try { localStorage.setItem('rcnWalkVoice', on ? 'on' : 'off') } catch (e) {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcngraph",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Federated Wiki - RCN Graph Plug-in",
5
5
  "keywords": [
6
6
  "wiki",