wiki-plugin-rcntimeline 0.3.3 → 0.3.5
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/README.md +1 -1
- package/client/rcntimeline.js +130 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,6 @@ Part of the [RCN toolset](https://github.com/marpie1/rcn), MIT.
|
|
|
48
48
|
|
|
49
49
|
Marc Pierson and Claude Opus 5.5 · September 2026
|
|
50
50
|
|
|
51
|
-
**Walks** (0.3.0). A timeline made in the full tool can carry `walks`: readings that play one step at a time. **▶ Walk** under the timeline redraws each step's years, fades the other bars, and reads the words aloud with a caption; Space, ← →, Esc. Open in RCN Timeline and Save to wiki carry the walks both ways.
|
|
51
|
+
**Walks** (0.3.0). A timeline made in the full tool can carry `walks`: readings that play one step at a time. **▶ Walk** under the timeline redraws each step's years, fades the other bars, rings the step's bars, and moves one pointer from bar to bar as the words reach each one: a ▼ over the bar, a line up to the axis and the bar's dates there (0.3.5; the pointer glides and the ring pulses, unless the reader has asked for reduced motion), and reads the words aloud with a caption; Space, ← →, Esc. Open in RCN Timeline and Save to wiki carry the walks both ways.
|
|
52
52
|
|
|
53
53
|
**Recorded voices** (0.3.1). A step may carry `voices`, people's own recordings of its words, made with ● Record in the timeline's walk editor: `{"<name>": {audio, say}}`. The walk plays a step's recording when it has one and the computer voice otherwise; a chooser in the walk bar picks whose, or the computer voice only (kept in `rcnWalkPrefs.speaker`). On Save to wiki the plugin moves each recording into the site's assets, `assets/voice-files/<content hash>.webm`, uploaded once however often the page is saved, and the step keeps only the file's full address, so pages and their history never hold audio and a forked page still plays from the original site. If the upload fails (not signed in), the recording stays inside the walk until the next save that can upload it.
|
package/client/rcntimeline.js
CHANGED
|
@@ -308,6 +308,126 @@
|
|
|
308
308
|
$item.find('.rcnt-canvas [data-from]').each(function () {
|
|
309
309
|
this.style.opacity = Math.min(op(this.getAttribute('data-from')), op(this.getAttribute('data-to')))
|
|
310
310
|
})
|
|
311
|
+
walkMark($item, lit)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Each bar the step is about gets a pale ring. One pointer then moves to the bar the
|
|
315
|
+
// words have reached: a ▼ over it, a line up to the date axis and its dates on the
|
|
316
|
+
// axis, so it shows the thing and the time together; that bar's ring turns strong and
|
|
317
|
+
// pulses as the pointer arrives. Indigo, like the caption box. Same as the tool.
|
|
318
|
+
const PTR = '#4f46e5', PALE = '#c7d2fe'
|
|
319
|
+
const still = () => { try { return matchMedia('(prefers-reduced-motion: reduce)').matches } catch (e) { return false } }
|
|
320
|
+
const svgEl = (tag, a) => { const n = document.createElementNS(NS, tag); for (const k in a) n.setAttribute(k, a[k]); return n }
|
|
321
|
+
function walkMark ($item, lit) {
|
|
322
|
+
const svg = $item.find('.rcnt-canvas svg')[0]
|
|
323
|
+
if (!svg) return
|
|
324
|
+
const W = +svg.getAttribute('width')
|
|
325
|
+
$item.find('.rcnt-canvas g.rcnt-bar').each(function () {
|
|
326
|
+
const id = this.getAttribute('data-iv')
|
|
327
|
+
if (!lit.has(id)) return
|
|
328
|
+
const b = this.getBBox()
|
|
329
|
+
if (b.x + b.width < 0 || b.x > W) return
|
|
330
|
+
svg.appendChild(svgEl('rect', { 'data-wkring': id, x: b.x - 3, y: b.y - 3, width: Math.max(8, b.width + 6), height: b.height + 6, rx: 5, fill: 'none', stroke: PALE, 'stroke-width': 1.5, 'pointer-events': 'none' }))
|
|
331
|
+
})
|
|
332
|
+
const wk = $item.get(0).rcntWalk
|
|
333
|
+
if (wk && wk.ptr) ptrDraw($item, wk.ptr, false)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Where the words reach each bar: the first place they use a clue only that bar's label
|
|
337
|
+
// has. Clues, strongest first: acronyms (BHP), words (first five letters, so "reopens"
|
|
338
|
+
// finds "reopened"), then the start year. A bar never named takes its turn in list order.
|
|
339
|
+
const PTR_STOP = new Set(['with', 'from', 'that', 'this', 'into', 'over', 'again', 'first', 'begins', 'their', 'after', 'still', 'about'])
|
|
340
|
+
function ptrClues (v) {
|
|
341
|
+
const caps = (String(v.label).match(/\b[A-Z]{2,5}\b/g) || []).map(x => x.toLowerCase())
|
|
342
|
+
const words = (String(v.label).toLowerCase().match(/[a-z\u00c0-\u024f]{4,}/g) || []).filter(x => !PTR_STOP.has(x)).map(x => x.slice(0, 5))
|
|
343
|
+
return [caps, words, [fmt(v.s).split(' ').pop()]]
|
|
344
|
+
}
|
|
345
|
+
function ptrCues (m, st) {
|
|
346
|
+
const byId = {}; m.intervals.forEach(v => { byId[String(v.id)] = v })
|
|
347
|
+
const ids = (st.intervals || []).map(String).filter(id => byId[id]), text = String(st.say || '').toLowerCase(), n = ids.length
|
|
348
|
+
const C = {}; ids.forEach(id => { C[id] = ptrClues(byId[id]) })
|
|
349
|
+
const cues = ids.map((id, k) => {
|
|
350
|
+
const others = new Set(); ids.forEach(o => { if (o !== id) C[o].forEach(t => t.forEach(x => others.add(x))) })
|
|
351
|
+
let at = -1
|
|
352
|
+
C[id].some(tier => {
|
|
353
|
+
tier.forEach(x => {
|
|
354
|
+
if (others.has(x)) return
|
|
355
|
+
const i = x.length < 4 ? text.search(new RegExp('\\b' + x + '\\b')) : text.indexOf(x)
|
|
356
|
+
if (i >= 0 && (at < 0 || i < at)) at = i
|
|
357
|
+
})
|
|
358
|
+
return at >= 0
|
|
359
|
+
})
|
|
360
|
+
return { id, k, at: at >= 0 ? at / Math.max(1, text.length) : k / n, v: byId[id] }
|
|
361
|
+
})
|
|
362
|
+
cues.sort((a, b) => a.at - b.at || a.k - b.k)
|
|
363
|
+
if (cues.length) cues[0].at = 0
|
|
364
|
+
return cues
|
|
365
|
+
}
|
|
366
|
+
// When: a recording's own clock, the voice's word boundaries when the browser sends
|
|
367
|
+
// them, otherwise an estimate from the length of the words at the chosen rate.
|
|
368
|
+
function ptrStart ($item, m, st) {
|
|
369
|
+
const wk = $item.get(0).rcntWalk
|
|
370
|
+
ptrStop(wk)
|
|
371
|
+
if (!st || st.all) return
|
|
372
|
+
const cues = ptrCues(m, st)
|
|
373
|
+
if (!cues.length) return
|
|
374
|
+
const len = Math.max(1, String(st.say || '').length)
|
|
375
|
+
const p = wk.ptr = { cues, k: 0, len, t0: performance.now(), est: len * 1000 / (14 * walkPrefs().rate), spoken: null, geo: null, raf: 0 }
|
|
376
|
+
ptrDraw($item, p, true)
|
|
377
|
+
const tick = () => {
|
|
378
|
+
if (wk.ptr !== p) return
|
|
379
|
+
const f = recAudio && recAudio.duration > 0 && isFinite(recAudio.duration) ? recAudio.currentTime / recAudio.duration
|
|
380
|
+
: p.spoken != null ? p.spoken / p.len : (performance.now() - p.t0) / p.est
|
|
381
|
+
let k = p.k
|
|
382
|
+
while (k + 1 < p.cues.length && p.cues[k + 1].at <= f) k++
|
|
383
|
+
if (k !== p.k) { p.k = k; ptrDraw($item, p, true) }
|
|
384
|
+
if (p.k < p.cues.length - 1) p.raf = requestAnimationFrame(tick)
|
|
385
|
+
}
|
|
386
|
+
tick()
|
|
387
|
+
}
|
|
388
|
+
function ptrStop (wk) { if (wk && wk.ptr) { cancelAnimationFrame(wk.ptr.raf); wk.ptr = null } }
|
|
389
|
+
// The dates as the pointer shows them: the day when it is known, else the year.
|
|
390
|
+
function ptrWhen (v) {
|
|
391
|
+
const one = (y, f) => f >= 0.1 ? fmt(y).split(' ').pop() : fmt(y)
|
|
392
|
+
return v.e - v.s < 1 / 365 ? one(v.s, v.sf) : one(v.s, v.sf) + ' – ' + one(v.e, v.ef)
|
|
393
|
+
}
|
|
394
|
+
function ptrDraw ($item, p, animate) {
|
|
395
|
+
const svg = $item.find('.rcnt-canvas svg')[0]
|
|
396
|
+
if (!svg) return
|
|
397
|
+
$(svg).find('.rcnt-ptr').remove()
|
|
398
|
+
const cue = p.cues[p.k], bar = $(svg).find('g.rcnt-bar').filter(function () { return this.getAttribute('data-iv') === cue.id })[0]
|
|
399
|
+
if (!bar) return
|
|
400
|
+
const W = +svg.getAttribute('width'), b = bar.getBBox(), core = bar.lastElementChild.getBBox()
|
|
401
|
+
if (b.x + b.width < 0 || b.x > W) return
|
|
402
|
+
const to = { x: Math.max(8, Math.min(W - 8, core.x)), y: b.y - 3 }
|
|
403
|
+
const from = animate && p.geo && !still() ? p.geo : to
|
|
404
|
+
p.geo = to
|
|
405
|
+
const when = ptrWhen(cue.v), cw = textWidth(when) + 12
|
|
406
|
+
const line = svgEl('line', { class: 'rcnt-ptr', stroke: PTR, 'stroke-width': 1.2, 'stroke-dasharray': '3 3', opacity: 0.8, 'pointer-events': 'none' })
|
|
407
|
+
const tri = svgEl('path', { class: 'rcnt-ptr', fill: PTR, stroke: '#fff', 'stroke-width': 1, 'stroke-linejoin': 'round', 'pointer-events': 'none' })
|
|
408
|
+
const cr = svgEl('rect', { class: 'rcnt-ptr', y: 2, height: 15, width: cw, rx: 7, fill: PTR, 'pointer-events': 'none' })
|
|
409
|
+
const ct = svgEl('text', { class: 'rcnt-ptr', y: 13, fill: '#fff', 'font-size': 10, 'font-weight': 600, 'text-anchor': 'middle', 'pointer-events': 'none' })
|
|
410
|
+
ct.textContent = when
|
|
411
|
+
;[line, tri, cr, ct].forEach(n => svg.appendChild(n))
|
|
412
|
+
const place = (x, y) => {
|
|
413
|
+
line.setAttribute('x1', x); line.setAttribute('x2', x); line.setAttribute('y1', AXIS_H - 4); line.setAttribute('y2', y - 9)
|
|
414
|
+
tri.setAttribute('d', `M${x - 6},${y - 8} L${x + 6},${y - 8} L${x},${y} Z`)
|
|
415
|
+
const cx = Math.max(cw / 2 + 2, Math.min(W - cw / 2 - 2, x)); cr.setAttribute('x', cx - cw / 2); ct.setAttribute('x', cx)
|
|
416
|
+
}
|
|
417
|
+
$(svg).find('[data-wkring]').each(function () {
|
|
418
|
+
const on = this.getAttribute('data-wkring') === cue.id
|
|
419
|
+
this.setAttribute('stroke', on ? PTR : PALE); this.setAttribute('stroke-width', on ? 2 : 1.5)
|
|
420
|
+
if (on && animate && !still()) { const a = svgEl('animate', { attributeName: 'stroke-width', values: '5;2', dur: '0.9s', begin: 'indefinite', fill: 'freeze' }); this.appendChild(a); try { a.beginElement() } catch (e) {} }
|
|
421
|
+
})
|
|
422
|
+
if (from === to) { place(to.x, to.y); return }
|
|
423
|
+
const t0 = performance.now()
|
|
424
|
+
const step = now => {
|
|
425
|
+
if (!line.parentNode) return
|
|
426
|
+
const u = Math.min(1, (now - t0) / 450), e = u < 0.5 ? 2 * u * u : 1 - Math.pow(-2 * u + 2, 2) / 2
|
|
427
|
+
place(from.x + (to.x - from.x) * e, from.y + (to.y - from.y) * e)
|
|
428
|
+
if (u < 1) requestAnimationFrame(step)
|
|
429
|
+
}
|
|
430
|
+
step(t0)
|
|
311
431
|
}
|
|
312
432
|
|
|
313
433
|
// Voice and speed are the listener's: kept in this browser, the same keys the Graph Tool uses.
|
|
@@ -324,6 +444,7 @@
|
|
|
324
444
|
['Samantha', 'Daniel', 'Karen', 'Moira', 'Google UK English Female', 'Google US English', 'Microsoft Aria']
|
|
325
445
|
.map(p => vs.find(v => v.name.indexOf(p) === 0)).find(Boolean) || vs[0] || null
|
|
326
446
|
}
|
|
447
|
+
let spokenHook = null // the walk pointer's ear on the voice's word boundaries
|
|
327
448
|
const stopVoice = () => { recHush(); try { if (window.speechSynthesis) speechSynthesis.cancel() } catch (e) {} }
|
|
328
449
|
// Say the words; done() runs once when they have been said. One utterance per
|
|
329
450
|
// sentence, because Chrome stops a long one after about fifteen seconds.
|
|
@@ -336,10 +457,13 @@
|
|
|
336
457
|
if (!prefs.on || !window.speechSynthesis || !text) { setTimeout(after, text ? words * 400 + 2000 : 1200); return }
|
|
337
458
|
const v = walkVoice(prefs.voice)
|
|
338
459
|
const parts = text.match(/[^.!?]+[.!?]+["'”’)]*\s*|[^.!?]+$/g) || [text]
|
|
460
|
+
let off = 0
|
|
339
461
|
parts.forEach((s, k) => {
|
|
340
|
-
const u = new SpeechSynthesisUtterance(s.trim())
|
|
462
|
+
const u = new SpeechSynthesisUtterance(s.trim()), o = off
|
|
463
|
+
off += s.length
|
|
341
464
|
if (v) { u.voice = v; u.lang = v.lang }
|
|
342
465
|
u.rate = prefs.rate
|
|
466
|
+
u.onboundary = e => { if (isCurrent() && spokenHook) spokenHook(o + (e.charIndex || 0)) }
|
|
343
467
|
if (k === parts.length - 1) u.onend = after
|
|
344
468
|
speechSynthesis.speak(u)
|
|
345
469
|
})
|
|
@@ -443,6 +567,8 @@
|
|
|
443
567
|
const tok = ++wk.token, walk = cur(), st = walk && walk.steps[wk.i]
|
|
444
568
|
if (!st) return
|
|
445
569
|
wk.heard = wk.i
|
|
570
|
+
if (!wk.ptr || wk.ptr.k > 0 || performance.now() - wk.ptr.t0 > 300) ptrStart($item, el.rcntModel, st)
|
|
571
|
+
spokenHook = c => { if (wk.ptr) wk.ptr.spoken = c }
|
|
446
572
|
walkSayStep(st, () => tok === wk.token && window.rcnActiveWalk === wk, () => {
|
|
447
573
|
const last = wk.i >= walk.steps.length - 1
|
|
448
574
|
if (st.ask || last) { wk.playing = false; ui(last && !st.ask ? 'End of the walk. ← to go back, Esc to stop.' : 'Over to you. Press Space or ▶ to go on.'); return }
|
|
@@ -453,9 +579,10 @@
|
|
|
453
579
|
const walk = cur()
|
|
454
580
|
if (!walk) return
|
|
455
581
|
wk.i = Math.max(0, Math.min(walk.steps.length - 1, i))
|
|
456
|
-
wk.token++; stopVoice()
|
|
582
|
+
wk.token++; stopVoice(); ptrStop(wk)
|
|
457
583
|
if (el.rcntPaint) el.rcntPaint()
|
|
458
584
|
const st = walk.steps[wk.i]
|
|
585
|
+
ptrStart($item, el.rcntModel, st)
|
|
459
586
|
$item.find('.walk-say').text(st.say || '').css({ color: st.ask ? '#7c2d12' : '#1e1b4b', fontStyle: st.ask ? 'italic' : 'normal' })
|
|
460
587
|
ui()
|
|
461
588
|
if (wk.playing) speak()
|
|
@@ -473,7 +600,7 @@
|
|
|
473
600
|
ui(); speak()
|
|
474
601
|
}
|
|
475
602
|
const end = () => {
|
|
476
|
-
wk.playing = false; wk.token++; wk.w = null; wk.heard = null
|
|
603
|
+
wk.playing = false; wk.token++; wk.w = null; wk.heard = null; ptrStop(wk)
|
|
477
604
|
if (window.rcnActiveWalk === wk) { stopVoice(); window.rcnActiveWalk = null }
|
|
478
605
|
if (el.rcntPaint) el.rcntPaint()
|
|
479
606
|
ui()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-plugin-rcntimeline",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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": ["wiki", "federated wiki", "plugin", "rcn", "timeline"],
|
|
6
6
|
"author": "RCN Network <rcn@relocalizecreativity.net>",
|