wiki-plugin-rcntimeline 0.3.4 → 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 +120 -15
- 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,
|
|
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
|
@@ -311,25 +311,123 @@
|
|
|
311
311
|
walkMark($item, lit)
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
//
|
|
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 }
|
|
317
321
|
function walkMark ($item, lit) {
|
|
318
322
|
const svg = $item.find('.rcnt-canvas svg')[0]
|
|
319
323
|
if (!svg) return
|
|
320
|
-
const W = +svg.getAttribute('width')
|
|
321
|
-
const mk = (tag, a) => { const n = document.createElementNS(NS, tag); for (const k in a) n.setAttribute(k, a[k]); return n }
|
|
324
|
+
const W = +svg.getAttribute('width')
|
|
322
325
|
$item.find('.rcnt-canvas g.rcnt-bar').each(function () {
|
|
323
|
-
|
|
326
|
+
const id = this.getAttribute('data-iv')
|
|
327
|
+
if (!lit.has(id)) return
|
|
324
328
|
const b = this.getBBox()
|
|
325
329
|
if (b.x + b.width < 0 || b.x > W) return
|
|
326
|
-
|
|
327
|
-
if (!still) ring.appendChild(mk('animate', { attributeName: 'stroke-width', values: '5;2', dur: '0.9s', fill: 'freeze' }))
|
|
328
|
-
svg.appendChild(ring)
|
|
329
|
-
const core = this.lastElementChild.getBBox()
|
|
330
|
-
const cx = Math.max(6, Math.min(W - 6, core.x + core.width / 2)), tip = b.y - 4
|
|
331
|
-
svg.appendChild(mk('path', { d: `M${cx - 5},${tip - 7} L${cx + 5},${tip - 7} L${cx},${tip} Z`, fill: '#4f46e5', stroke: '#fff', 'stroke-width': 1, 'stroke-linejoin': 'round', 'pointer-events': 'none' }))
|
|
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' }))
|
|
332
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)
|
|
333
431
|
}
|
|
334
432
|
|
|
335
433
|
// Voice and speed are the listener's: kept in this browser, the same keys the Graph Tool uses.
|
|
@@ -346,6 +444,7 @@
|
|
|
346
444
|
['Samantha', 'Daniel', 'Karen', 'Moira', 'Google UK English Female', 'Google US English', 'Microsoft Aria']
|
|
347
445
|
.map(p => vs.find(v => v.name.indexOf(p) === 0)).find(Boolean) || vs[0] || null
|
|
348
446
|
}
|
|
447
|
+
let spokenHook = null // the walk pointer's ear on the voice's word boundaries
|
|
349
448
|
const stopVoice = () => { recHush(); try { if (window.speechSynthesis) speechSynthesis.cancel() } catch (e) {} }
|
|
350
449
|
// Say the words; done() runs once when they have been said. One utterance per
|
|
351
450
|
// sentence, because Chrome stops a long one after about fifteen seconds.
|
|
@@ -358,10 +457,13 @@
|
|
|
358
457
|
if (!prefs.on || !window.speechSynthesis || !text) { setTimeout(after, text ? words * 400 + 2000 : 1200); return }
|
|
359
458
|
const v = walkVoice(prefs.voice)
|
|
360
459
|
const parts = text.match(/[^.!?]+[.!?]+["'”’)]*\s*|[^.!?]+$/g) || [text]
|
|
460
|
+
let off = 0
|
|
361
461
|
parts.forEach((s, k) => {
|
|
362
|
-
const u = new SpeechSynthesisUtterance(s.trim())
|
|
462
|
+
const u = new SpeechSynthesisUtterance(s.trim()), o = off
|
|
463
|
+
off += s.length
|
|
363
464
|
if (v) { u.voice = v; u.lang = v.lang }
|
|
364
465
|
u.rate = prefs.rate
|
|
466
|
+
u.onboundary = e => { if (isCurrent() && spokenHook) spokenHook(o + (e.charIndex || 0)) }
|
|
365
467
|
if (k === parts.length - 1) u.onend = after
|
|
366
468
|
speechSynthesis.speak(u)
|
|
367
469
|
})
|
|
@@ -465,6 +567,8 @@
|
|
|
465
567
|
const tok = ++wk.token, walk = cur(), st = walk && walk.steps[wk.i]
|
|
466
568
|
if (!st) return
|
|
467
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 }
|
|
468
572
|
walkSayStep(st, () => tok === wk.token && window.rcnActiveWalk === wk, () => {
|
|
469
573
|
const last = wk.i >= walk.steps.length - 1
|
|
470
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 }
|
|
@@ -475,9 +579,10 @@
|
|
|
475
579
|
const walk = cur()
|
|
476
580
|
if (!walk) return
|
|
477
581
|
wk.i = Math.max(0, Math.min(walk.steps.length - 1, i))
|
|
478
|
-
wk.token++; stopVoice()
|
|
582
|
+
wk.token++; stopVoice(); ptrStop(wk)
|
|
479
583
|
if (el.rcntPaint) el.rcntPaint()
|
|
480
584
|
const st = walk.steps[wk.i]
|
|
585
|
+
ptrStart($item, el.rcntModel, st)
|
|
481
586
|
$item.find('.walk-say').text(st.say || '').css({ color: st.ask ? '#7c2d12' : '#1e1b4b', fontStyle: st.ask ? 'italic' : 'normal' })
|
|
482
587
|
ui()
|
|
483
588
|
if (wk.playing) speak()
|
|
@@ -495,7 +600,7 @@
|
|
|
495
600
|
ui(); speak()
|
|
496
601
|
}
|
|
497
602
|
const end = () => {
|
|
498
|
-
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)
|
|
499
604
|
if (window.rcnActiveWalk === wk) { stopVoice(); window.rcnActiveWalk = null }
|
|
500
605
|
if (el.rcntPaint) el.rcntPaint()
|
|
501
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>",
|