wiki-plugin-rcntimeline 0.3.1 → 0.3.3
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 +77 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,4 +50,4 @@ Marc Pierson and Claude Opus 5.5 · September 2026
|
|
|
50
50
|
|
|
51
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.
|
|
52
52
|
|
|
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`).
|
|
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
|
@@ -66,7 +66,8 @@
|
|
|
66
66
|
return y + (Date.UTC(y, mo, day) - a) / (b - a)
|
|
67
67
|
}
|
|
68
68
|
function fmt (y) {
|
|
69
|
-
const yr = Math.floor(y),
|
|
69
|
+
const yr = Math.floor(y), ms = Date.UTC(yr, 0, 1) + (y - yr) * (Date.UTC(yr + 1, 0, 1) - Date.UTC(yr, 0, 1))
|
|
70
|
+
const d = new Date(Math.round(ms / 864e5) * 864e5) // to the nearest day, so Feb 1 never prints as Jan 31
|
|
70
71
|
return MON_NAME[d.getUTCMonth()] + ' ' + d.getUTCDate() + ' ' + d.getUTCFullYear()
|
|
71
72
|
}
|
|
72
73
|
const relWords = r => Array.isArray(r) ? 'one of ' + r.join(', ') : (r || 'before')
|
|
@@ -158,11 +159,22 @@
|
|
|
158
159
|
// A tick step that gives four to seven labels across the span.
|
|
159
160
|
function ticks (lo, hi) {
|
|
160
161
|
const span = hi - lo
|
|
161
|
-
const steps = [1 / 12, 0.25, 0.5, 1, 2, 5, 10, 20, 25, 50, 100]
|
|
162
|
+
const D = 1 / 365.25, steps = [D, 2 * D, 7 * D, 14 * D, 1 / 12, 0.25, 0.5, 1, 2, 5, 10, 20, 25, 50, 100]
|
|
162
163
|
const step = steps.find(s => span / s <= 7) || 100
|
|
163
164
|
const out = []
|
|
165
|
+
if (step >= 1 / 12 && step < 1) { // months on real month starts, not twelfths of a year
|
|
166
|
+
const every = Math.round(step * 12)
|
|
167
|
+
for (let y = Math.floor(lo), mo = 0; y <= Math.ceil(hi); mo += every) {
|
|
168
|
+
if (mo >= 12) { y += Math.floor(mo / 12); mo %= 12 }
|
|
169
|
+
const t = frac(y, mo, 1)
|
|
170
|
+
if (t > hi + 1e-9) break
|
|
171
|
+
if (t >= lo - 1e-9) out.push({ t, label: fmt(t).replace(/ \d+ /, ' ') })
|
|
172
|
+
}
|
|
173
|
+
return out
|
|
174
|
+
}
|
|
164
175
|
for (let t = Math.ceil(lo / step) * step; t <= hi + 1e-9; t += step) {
|
|
165
|
-
|
|
176
|
+
// years, or days and weeks as "Mon D"
|
|
177
|
+
out.push({ t, label: step >= 1 ? String(Math.round(t)) : step >= 1 / 12 ? fmt(t).replace(/ \d+ /, ' ') : fmt(t).replace(/ \d+$/, '') })
|
|
166
178
|
}
|
|
167
179
|
return out
|
|
168
180
|
}
|
|
@@ -281,7 +293,8 @@
|
|
|
281
293
|
const ivs = lit ? m.intervals.filter(v => lit.has(String(v.id))) : []
|
|
282
294
|
if (!ivs.length) return null
|
|
283
295
|
let lo = Math.min(...ivs.map(v => v.s - v.sf)), hi = Math.max(...ivs.map(v => v.e + v.ef))
|
|
284
|
-
|
|
296
|
+
// at least 3 years, unless the bars are much shorter: then zoom in to them, down to 2 days (same rule as the tool)
|
|
297
|
+
const ext = hi - lo, span = ext > 0 ? Math.max(ext, Math.min(3, 4 * ext), 2 / 365.25) : 3, mid = (lo + hi) / 2
|
|
285
298
|
return { lo: mid - span * 0.62, hi: mid + span * 0.62 }
|
|
286
299
|
}
|
|
287
300
|
|
|
@@ -581,19 +594,73 @@
|
|
|
581
594
|
emit($item, item)
|
|
582
595
|
}
|
|
583
596
|
|
|
597
|
+
// Recordings live as files in this site's assets (assets/voice-files), one file per
|
|
598
|
+
// recording, named by its content. On save, any recording still held inside a walk
|
|
599
|
+
// (a data: URL from a walk editor) is uploaded there and replaced by the file's full
|
|
600
|
+
// address, so a page and its history keep only addresses, a recording is never
|
|
601
|
+
// stored twice, and a forked page still plays from the site that has the file.
|
|
602
|
+
// If the upload fails (not signed in, say) the recording stays inside the walk, so
|
|
603
|
+
// nothing is lost, and the next save that can upload moves it out.
|
|
604
|
+
const VOICE_FOLDER = 'voice-files'
|
|
605
|
+
function voiceSteps (walks) {
|
|
606
|
+
const out = []
|
|
607
|
+
for (const w of walks || []) for (const st of (w && w.steps) || []) {
|
|
608
|
+
for (const n of Object.keys((st && st.voices) || {})) {
|
|
609
|
+
const v = st.voices[n]
|
|
610
|
+
if (v && typeof v.audio === 'string' && /^data:audio\//.test(v.audio)) out.push(v)
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return out
|
|
614
|
+
}
|
|
615
|
+
async function voiceFile (dataUrl) {
|
|
616
|
+
const blob = await (await fetch(dataUrl)).blob()
|
|
617
|
+
const sum = new Uint8Array(await crypto.subtle.digest('SHA-256', await blob.arrayBuffer()))
|
|
618
|
+
const hex = [...sum.slice(0, 12)].map(b => b.toString(16).padStart(2, '0')).join('')
|
|
619
|
+
const ext = /mp4|m4a|aac/.test(blob.type) ? 'm4a' : /wav/.test(blob.type) ? 'wav' : /ogg/.test(blob.type) ? 'ogg' : 'webm'
|
|
620
|
+
const name = hex + '.' + ext
|
|
621
|
+
const url = location.origin + '/assets/' + VOICE_FOLDER + '/' + name
|
|
622
|
+
const have = await fetch(url, { method: 'HEAD', cache: 'no-store' }).then(r => r.ok, () => false)
|
|
623
|
+
if (!have) {
|
|
624
|
+
const form = new FormData()
|
|
625
|
+
form.append('assets', VOICE_FOLDER) // before the file: the server reads the folder first
|
|
626
|
+
form.append('uploads[]', blob, name)
|
|
627
|
+
const r = await fetch('/plugin/assets/upload', { method: 'POST', body: form, credentials: 'same-origin' })
|
|
628
|
+
if (!r.ok) throw new Error(r.status === 401 ? 'sign in to this wiki to save recordings as files' : 'upload failed (' + r.status + ')')
|
|
629
|
+
}
|
|
630
|
+
return url
|
|
631
|
+
}
|
|
632
|
+
// Move every embedded recording in these walks to a file; resolves to a note
|
|
633
|
+
// for the reader when some could not be moved, else ''.
|
|
634
|
+
async function voicesToFiles (walks) {
|
|
635
|
+
const vs = voiceSteps(walks)
|
|
636
|
+
let failed = '', n = 0
|
|
637
|
+
for (const v of vs) {
|
|
638
|
+
try { v.audio = await voiceFile(v.audio); n++ } catch (e) { failed = e.message || String(e) }
|
|
639
|
+
}
|
|
640
|
+
if (n) console.log('voice files: ' + n + ' recording' + (n === 1 ? '' : 's') + ' now point to assets/' + VOICE_FOLDER + ' (each file is uploaded once)')
|
|
641
|
+
return failed ? 'Recordings were kept inside the page: ' + failed + '.' : ''
|
|
642
|
+
}
|
|
643
|
+
function voiceNotice ($item, msg) {
|
|
644
|
+
$item.find('.voice-note').remove()
|
|
645
|
+
if (msg) $item.append($('<div class="voice-note" style="font-size:12px;color:#92400e;padding:4px 0"></div>').text(msg))
|
|
646
|
+
}
|
|
647
|
+
|
|
584
648
|
// Save-back from the full tool. Only the window this page opened is heard,
|
|
585
649
|
// and it saves into the item opened last.
|
|
586
650
|
function toolListener (event) {
|
|
587
651
|
if (!pending || !event.data || event.data.toolType !== 'rcn-timeline') return
|
|
588
652
|
if (pending.win && event.source !== pending.win) return
|
|
589
653
|
if (event.data.action !== 'saveTimeline' || !event.data.timeline) return
|
|
590
|
-
const { item, $item } = pending
|
|
654
|
+
const { item, $item } = pending, src = event.source
|
|
591
655
|
const tl = event.data.timeline
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
656
|
+
voicesToFiles(tl.walks).then(note => {
|
|
657
|
+
item.timeline = Object.assign({ intervals: tl.intervals || [], links: tl.links || [] }, Array.isArray(tl.walks) && tl.walks.length ? { walks: tl.walks } : {})
|
|
658
|
+
delete item.frozen // what was frozen is now in the item's own timeline
|
|
659
|
+
item.text = words(item, item.timeline)
|
|
660
|
+
save($item, item)
|
|
661
|
+
voiceNotice($item, note)
|
|
662
|
+
try { src.postMessage({ toolType: 'rcn-timeline', action: 'saved', page: $item.parents('.page:first').data('data').title }, '*') } catch (e) {}
|
|
663
|
+
})
|
|
597
664
|
}
|
|
598
665
|
|
|
599
666
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-plugin-rcntimeline",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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>",
|