wiki-plugin-rcngraph 0.1.21 → 0.1.23

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.
@@ -154,6 +154,95 @@
154
154
  if (f.seen.has(id)) return 0.42
155
155
  return f.click ? 0.3 : 0.13
156
156
  }
157
+ // Whole or Step, item by item (Nov 17 2026), the same choice as the explorer's
158
+ // panes (tools/rcn-together.html). Step: a walk — this item's or one it
159
+ // follows — zooms the item to each step. Whole: the item shows the whole
160
+ // timeline, map or drawing and stays where you put it; steps light things in
161
+ // place, and you pan and zoom by hand. A click elsewhere still brings the item
162
+ // to what was clicked. ⤢ shows the whole thing again. Each kind of item
163
+ // (timeline, map, sketch) remembers its last choice in this browser.
164
+ const FRAME_KEY = 'rcnLineupFrame'
165
+ const frameSaved = () => { try { return JSON.parse(localStorage.getItem(FRAME_KEY)) || {} } catch (e) { return {} } }
166
+ R.frame = el => el.rcnFrame || (el.rcnFrame = frameSaved()[el.rcnKind] === 'whole' ? 'whole' : 'step')
167
+ R.whole = el => R.frame(el) === 'whole'
168
+ const frameHTML = fr => {
169
+ const b = 'font:inherit;font-size:12px;border:0;padding:2px 8px;cursor:pointer;'
170
+ const on = 'background:#4f46e5;color:#fff;', off = 'background:#fff;color:#334155;'
171
+ return `<button data-fr="whole" style="${b}${fr === 'whole' ? on : off}" title="Show the whole thing; a walk lights things where they are and leaves the view to you. Drag to pan, pinch or ⌘-scroll to zoom.">Whole</button>` +
172
+ `<button data-fr="step" style="${b}border-left:1px solid #cbd5e1;${fr === 'step' ? on : off}" title="Zoom in on each step of a walk">Step</button>` +
173
+ (fr === 'whole' ? `<button data-fr="fit" style="${b}border-left:1px solid #cbd5e1;${off}" title="Show the whole thing again">⤢</button>` : '')
174
+ }
175
+ // The switch, for an item's button row. kind: 'timeline' | 'map' | 'sketch'.
176
+ R.frameSwitch = kind => `<span class="rcn-frame" data-kind="${kind}" style="display:inline-flex;vertical-align:middle;border:1px solid #cbd5e1;border-radius:6px;overflow:hidden" role="group" aria-label="During a walk"></span>`
177
+ // Wire an item's switch. fn(frame, fit) redraws the item for the new choice.
178
+ R.bindFrame = function (el, kind, fn) {
179
+ el.rcnKind = kind
180
+ const draw = () => el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
181
+ draw()
182
+ if (el.rcnFrameBound) { el.rcnFrameFn = fn; return }
183
+ el.rcnFrameBound = true; el.rcnFrameFn = fn
184
+ el.addEventListener('click', e => {
185
+ const b = e.target.closest && e.target.closest('.rcn-frame button')
186
+ if (!b) return
187
+ e.stopPropagation()
188
+ const v = b.dataset.fr, was = R.frame(el)
189
+ if (v !== 'fit') {
190
+ el.rcnFrame = v
191
+ const s = frameSaved(); s[kind] = v
192
+ try { localStorage.setItem(FRAME_KEY, JSON.stringify(s)) } catch (err) {}
193
+ }
194
+ el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
195
+ if (v === 'fit' || v !== was) try { el.rcnFrameFn(R.frame(el), v === 'fit') } catch (err) { console.warn('rcn-frame:', err) }
196
+ })
197
+ }
198
+ // Hand pan and zoom on an element, for items without their own (the timeline
199
+ // and the drawing; the map has Leaflet's). Only while on() says so. Drag pans,
200
+ // pinch or ⌘/Ctrl-scroll zooms about the pointer, double-click shows the whole.
201
+ // A drag swallows the click that ends it, so it never counts as a click on a box.
202
+ // h: {on(), pan(dxPx, dyPx), zoom(factor, xPx, yPx), reset()}; positions are
203
+ // relative to the element's top-left corner.
204
+ R.handView = function (box, h) {
205
+ if (box.rcnHand) { box.rcnHand = h; return }
206
+ box.rcnHand = h
207
+ let drag = null, moved = false
208
+ box.addEventListener('pointerdown', e => {
209
+ if (!box.rcnHand.on() || e.button !== 0) return
210
+ drag = { x: e.clientX, y: e.clientY, id: e.pointerId }; moved = false
211
+ })
212
+ box.addEventListener('pointermove', e => {
213
+ if (!drag || e.pointerId !== drag.id) return
214
+ const dx = e.clientX - drag.x, dy = e.clientY - drag.y
215
+ if (!moved && Math.hypot(dx, dy) < 4) return
216
+ if (!moved) { moved = true; try { box.setPointerCapture(e.pointerId) } catch (err) {} box.style.cursor = 'grabbing' }
217
+ drag.x = e.clientX; drag.y = e.clientY
218
+ box.rcnHand.pan(dx, dy)
219
+ })
220
+ const up = () => { if (drag) { drag = null; box.style.cursor = '' } }
221
+ box.addEventListener('pointerup', up); box.addEventListener('pointercancel', up)
222
+ box.addEventListener('click', e => { if (moved) { moved = false; e.stopPropagation(); e.preventDefault() } }, true)
223
+ box.addEventListener('wheel', e => {
224
+ if (!box.rcnHand.on() || !(e.ctrlKey || e.metaKey)) return // a plain scroll still scrolls the wiki page
225
+ e.preventDefault()
226
+ const r = box.getBoundingClientRect()
227
+ box.rcnHand.zoom(Math.exp(-e.deltaY * (e.deltaMode ? 0.05 : 0.002) * (e.ctrlKey ? 10 : 1)), e.clientX - r.left, e.clientY - r.top) // a pinch arrives as ctrl+wheel in small steps
228
+ }, { passive: false })
229
+ box.addEventListener('dblclick', e => { if (box.rcnHand.on()) { e.preventDefault(); e.stopPropagation(); box.rcnHand.reset() } }, true)
230
+ }
231
+ // "⧉ Open together": the Time Place Causality Explorer on an item's set file
232
+ // (item.set). A bare file name lives in the site's /assets/NDC/ folder beside
233
+ // the explorer and the full tools; a full address may point anywhere, and the
234
+ // explorer is then looked for in that set's own folder. A local wiki opens the
235
+ // working copy on :8765.
236
+ R.together = function (set) {
237
+ const local = /(^|\.)localhost$/.test(location.hostname)
238
+ const s = new URL(set, location.origin + '/assets/NDC/')
239
+ const page = local ? 'http://localhost:8765/tools/rcn-together.html' : new URL('rcn-together.html', s).href
240
+ return page + '?set=' + encodeURIComponent(new URL(page).origin === s.origin ? s.pathname : s.href)
241
+ }
242
+ R.togetherButton = item => item && typeof item.set === 'string' && item.set.trim()
243
+ ? '<button class="rcn-together" style="cursor:pointer;font-size:12px;padding:2px 8px" title="Open this with its timeline, map and sketch side by side in the Time Place Causality Explorer">⧉ Open together ↗</button>'
244
+ : ''
245
+ R.openTogether = item => { const w = window.open(R.together(item.set.trim()), 'rcntogether'); if (w) try { w.focus() } catch (e) {} }
157
246
  return R
158
247
  })()
159
248
  // END rcn-lineup-follow
@@ -316,15 +405,19 @@
316
405
  }
317
406
 
318
407
  // i === null: no walk, everything back to normal.
408
+ // Whole (the Whole / Step switch, rcn-lineup-follow): steps light boxes where they
409
+ // are; the view is the whole drawing or wherever you have dragged and zoomed it.
410
+ const isWhole = $item => !!(RL && RL.whole && RL.whole($item.get(0)))
319
411
  function showWalkStep($item, g, walk, i) {
320
412
  const svg = $item.find('svg').get(0)
321
413
  if (!svg) return
414
+ const hold = isWhole($item)
322
415
  svg.querySelectorAll('.rcn-walk-ring').forEach(el => el.remove())
323
416
  $item.find('.graph-box').css('max-height', i === null ? '280px' : 'none')
324
417
  if (i === null) {
325
418
  g.nodes.forEach(n => { const el = groupFor(svg, 'node', n.id); if (el) el.style.opacity = '' })
326
419
  g.edges.forEach(e => { const el = groupFor(svg, 'edge', e.id); if (el) el.style.opacity = '' })
327
- walkZoom(svg, null)
420
+ if (!hold) walkZoom(svg, null)
328
421
  return
329
422
  }
330
423
  const seen = { nodes: new Set(), edges: new Set() }
@@ -343,7 +436,7 @@
343
436
  const el = groupFor(svg, 'edge', e.id)
344
437
  if (el) el.style.opacity = op('edges', String(e.id))
345
438
  })
346
- walkZoom(svg, lit ? [...lit.nodes].map(id => groupFor(svg, 'node', id)).filter(Boolean) : null)
439
+ if (!hold) walkZoom(svg, lit ? [...lit.nodes].map(id => groupFor(svg, 'node', id)).filter(Boolean) : null)
347
440
  }
348
441
 
349
442
  // Voice and speed are the listener's: kept in this browser, the same keys the Graph Tool uses.
@@ -504,7 +597,7 @@
504
597
  const op = id => RL.op(f, String(id))
505
598
  g.nodes.forEach(n => { const el = groupFor(svg, 'node', n.id); if (el) el.style.opacity = String(op(n.id)) })
506
599
  g.edges.forEach(e => { const el = groupFor(svg, 'edge', e.id); if (el) el.style.opacity = String(Math.min(op(e.src), op(e.tgt))) })
507
- walkZoom(svg, [...f.lit].map(id => groupFor(svg, 'node', id)).filter(Boolean))
600
+ if (!isWhole($item) || f.click) walkZoom(svg, [...f.lit].map(id => groupFor(svg, 'node', id)).filter(Boolean)) // a click brings it into view even on Whole
508
601
  }
509
602
 
510
603
  function esc(s) { return String(s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c])) }
@@ -519,6 +612,8 @@
519
612
  </div>
520
613
  <div style="padding:6px 0 0;display:flex;gap:6px;justify-content:center;">
521
614
  <button class="edit-graph" style="cursor:pointer;">Edit in Graph Tool ↗</button>
615
+ ${RL ? RL.togetherButton(item) : ''}
616
+ ${RL && RL.frameSwitch ? RL.frameSwitch('sketch') : ''}
522
617
  </div>
523
618
  ${buildBar(item)}
524
619
  ${walkBar(item)}
@@ -720,6 +815,7 @@
720
815
  function bind($item, item) {
721
816
  aboutMark($item, 'rcngraph')
722
817
  bindNotes($item, item)
818
+ $item.on('click', '.rcn-together', e => { e.stopPropagation(); RL.openTogether(item) })
723
819
  $item.on('click', '.open-graph, .edit-graph', () => {
724
820
  pendingItem = item
725
821
  pending$item = $item
@@ -728,7 +824,7 @@
728
824
  })
729
825
  $item.on('dblclick', e => {
730
826
  // Stepping a build or a walk is quick clicking — never let it open the editor.
731
- if ($(e.target).closest('.build-bar, .walk-bar').length) return
827
+ if ($(e.target).closest('.build-bar, .walk-bar, .rcn-frame').length) return
732
828
  wiki.textEditor($item, item)
733
829
  })
734
830
  // Build playback. Namespaced and reset, because a save re-runs bind.
@@ -824,6 +920,39 @@
824
920
  walkUI()
825
921
  }
826
922
  wk.end = walkEnd
923
+ // Whole / Step (rcn-lineup-follow). Whole and ⤢ show the whole drawing; Step
924
+ // frames what is lit now. In Whole the drawing is yours to pan and zoom.
925
+ if (RL && RL.bindFrame && $item.find('.graph-box svg').length) {
926
+ const svgNow = () => $item.find('.graph-box svg').get(0)
927
+ RL.bindFrame(elG, 'sketch', (fr, fit) => {
928
+ const g = graphModel(item), svg = svgNow()
929
+ if (!g || !svg) return
930
+ if (fr === 'whole' || fit) { walkZoom(svg, null); return }
931
+ if (wk.w !== null) showWalkStep($item, g, curWalk(), wk.i)
932
+ else if (elG.rcnFollow && elG.rcnFollow.lit) showFollow($item, g, elG.rcnFollow)
933
+ })
934
+ const vb = svg => (svg.getAttribute('viewBox') || svg.__fullViewBox || '0 0 1000 600').split(/[\s,]+/).map(Number)
935
+ const put = (svg, v) => { svg.__zoomId = (svg.__zoomId || 0) + 1; svg.setAttribute('viewBox', v.join(' ')) } // also stops a zoom still easing in
936
+ RL.handView($item.find('.graph-box').get(0), {
937
+ on: () => isWhole($item) && !!svgNow(),
938
+ pan: (dx, dy) => {
939
+ const svg = svgNow(), v = vb(svg), r = svg.getBoundingClientRect()
940
+ if (!svg.__fullViewBox) svg.__fullViewBox = v.join(' ')
941
+ const k = Math.max(v[2] / r.width, v[3] / r.height)
942
+ put(svg, [v[0] - dx * k, v[1] - dy * k, v[2], v[3]])
943
+ },
944
+ zoom: (f, x, y) => {
945
+ const svg = svgNow(), v = vb(svg), r = svg.getBoundingClientRect(), box = svg.parentNode.getBoundingClientRect()
946
+ if (!svg.__fullViewBox) svg.__fullViewBox = v.join(' ')
947
+ const full = svg.__fullViewBox.split(/[\s,]+/).map(Number)
948
+ const k = Math.max(v[2] / r.width, v[3] / r.height)
949
+ const px = v[0] + (x + box.left - r.left) * k, py = v[1] + (y + box.top - r.top) * k // the drawing's point under the pointer
950
+ const w = Math.max(full[2] / 20, Math.min(full[2] * 2, v[2] / f)), s = w / v[2]
951
+ put(svg, [px - (px - v[0]) * s, py - (py - v[1]) * s, w, v[3] * s])
952
+ },
953
+ reset: () => { const svg = svgNow(); if (svg) walkZoom(svg, null) }
954
+ })
955
+ }
827
956
  // Follow the other timeline, map and drawing items in the lineup, and the full
828
957
  // tools in other tabs. A walk played elsewhere stops this one (and a build);
829
958
  // a click elsewhere is ignored while either is open. A box is lit by its own
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcngraph",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "Federated Wiki - RCN Graph Plug-in",
5
5
  "keywords": [
6
6
  "wiki",
@@ -36,6 +36,16 @@
36
36
  "id": "f2b474457cb3f7bd",
37
37
  "text": "Following. Put this page in a lineup beside pages with an RCN timeline, map or drawing, and the items follow each other. Press ▶ Walk in any of them: each step lights what it is about there, and the others light what is related to it: full strength for this step, half for earlier steps, the rest faded. Click a box and the timeline lights the bars about it, and the map their places. The others light where it is for them. Click empty space to let go. The timeline's bars are the bridges: each bar names a place on the map (place) and a box in the drawing (eip). One walk plays at a time, and starting one stops the others. A click that lights nothing beside it opens its page as before; beside items that follow, the page opens at the end of the lineup so they stay open, and shift-click always opens it. The full Timeline, Map and Graph Tool, opened from this wiki's assets in another tab, follow too, and lead too."
38
38
  },
39
+ {
40
+ "type": "paragraph",
41
+ "id": "eb1078f31385e806",
42
+ "text": "Opening the explorer. Give the item a set field naming a set file, for example \"set\": \"superior.set.json\", and it shows a ⧉ Open together button. The button opens the Time Place Causality Explorer, which puts the timeline, the map and the sketch side by side on one page. A bare file name means the site's /assets/NDC/ folder, where the explorer and the full tools sit; a full address can point to a set anywhere."
43
+ },
44
+ {
45
+ "type": "paragraph",
46
+ "id": "149c044870cee1eb",
47
+ "text": "Whole or Step. Beside the item's buttons, Whole · Step says what this drawing does while a walk plays, its own or one it follows. Step zooms in on what each step is about. Whole keeps the whole drawing, or wherever you have put it: each step lights its boxes where they are. In Whole, drag the drawing to move it, pinch or ⌘-scroll to zoom, and double-click (or ⤢) to see all of it again. A click on the timeline or the map beside it still brings the drawing to that box. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
48
+ },
39
49
  {
40
50
  "type": "rcngraph",
41
51
  "id": "8d4e2a7f1c9b3065",
@@ -202,6 +212,28 @@
202
212
  },
203
213
  "after": "8e7e435485d56e9e",
204
214
  "date": 1794193621097
215
+ },
216
+ {
217
+ "type": "add",
218
+ "id": "eb1078f31385e806",
219
+ "item": {
220
+ "type": "paragraph",
221
+ "id": "eb1078f31385e806",
222
+ "text": "Opening the explorer. Give the item a set field naming a set file, for example \"set\": \"superior.set.json\", and it shows a ⧉ Open together button. The button opens the Time Place Causality Explorer, which puts the timeline, the map and the sketch side by side on one page. A bare file name means the site's /assets/NDC/ folder, where the explorer and the full tools sit; a full address can point to a set anywhere."
223
+ },
224
+ "after": "f2b474457cb3f7bd",
225
+ "date": 1794195627668
226
+ },
227
+ {
228
+ "type": "add",
229
+ "id": "149c044870cee1eb",
230
+ "item": {
231
+ "type": "paragraph",
232
+ "id": "149c044870cee1eb",
233
+ "text": "Whole or Step. Beside the item's buttons, Whole · Step says what this drawing does while a walk plays, its own or one it follows. Step zooms in on what each step is about. Whole keeps the whole drawing, or wherever you have put it: each step lights its boxes where they are. In Whole, drag the drawing to move it, pinch or ⌘-scroll to zoom, and double-click (or ⤢) to see all of it again. A click on the timeline or the map beside it still brings the drawing to that box. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
234
+ },
235
+ "after": "eb1078f31385e806",
236
+ "date": 1794945537905
205
237
  }
206
238
  ]
207
239
  }