@niracler/encore 0.3.0 → 0.4.1

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.
@@ -1,7 +1,7 @@
1
1
  import { createTranslator, resolveLang } from './i18n.mjs'
2
2
  import { attachAttachmentReaders } from './attachment-reader.mjs'
3
3
  import { escapeHtml } from './markdown.mjs'
4
- import { buildPlayerData, elapsedClock, renderPlayerWidget, wallClock } from './render.mjs'
4
+ import { buildPlayerData, categoryUsageLabel, contextUsageLabel, elapsedClock, renderPlayerWidget, renderTimelineBar, wallClock } from './render.mjs'
5
5
  import { timeline } from './timeline.mjs'
6
6
 
7
7
  const shorten = (text, length) => (text.length > length ? `${text.slice(0, length)}…` : text)
@@ -113,11 +113,11 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
113
113
  const stageTrigger = containerEl.querySelector('[data-session-stage-trigger]')
114
114
  const composerText = containerEl.querySelector('[data-session-composer-text]')
115
115
  const sendBtn = containerEl.querySelector('[data-session-send]')
116
- const progressBar = containerEl.querySelector('[data-session-progress]')
117
116
  const timelineBar = containerEl.querySelector('[data-session-timeline]')
118
117
  const tlTrack = timelineBar?.querySelector('[data-tl-track]')
119
118
  const tlPop = timelineBar?.querySelector('[data-tl-pop]')
120
- const tlSegs = timelineBar ? [...timelineBar.querySelectorAll('[data-tl-step]')] : []
119
+ const tlRange = tlTrack?.querySelector('[data-tl-range]')
120
+ const cells = tlTrack?.querySelector('.session-tl-cells')?.children
121
121
  const tlPins = timelineBar ? [...timelineBar.querySelectorAll('[data-tl-jump]')] : []
122
122
  const lightbox = containerEl.querySelector('[data-session-lightbox]')
123
123
  const lightboxImg = lightbox?.querySelector('[data-lightbox-img]')
@@ -143,8 +143,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
143
143
  let curTime = 0
144
144
  let playHead = initialStep
145
145
  let prevRenderedHead = initialStep
146
- let selectedIdx = initialStep
147
- let userClickedInspect = false
148
146
  let isInitialMount = true
149
147
  let playing = false
150
148
  let stepBusy = false
@@ -266,13 +264,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
266
264
  stepBusy = false
267
265
  }
268
266
 
269
- function updateProgressHairline(idx = playHead) {
270
- if (!progressBar) return
271
- const ratio = steps.length > 0 && idx >= 0 ? Math.max(0, Math.min(1, (idx + 0.5) / steps.length)) : 0
272
- progressBar.style.opacity = idx >= 0 || playing ? '1' : '0'
273
- progressBar.style.transform = `scaleX(${ratio.toFixed(4)})`
274
- }
275
-
276
267
  function rawPromptTextOf(stepIdx) {
277
268
  const step = steps[stepIdx]
278
269
  if (!step || step.kind !== 'prompt') return ''
@@ -352,10 +343,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
352
343
  return idx < 0 ? buildPrePromptStep() : model.selectStep(idx)
353
344
  }
354
345
 
355
- function currentSelectedState() {
356
- return stateForIndex(selectedIdx)
357
- }
358
-
359
346
  if (play) play.hidden = false
360
347
  attachAttachmentReaders(containerEl, t, () => { if (playing) setPlaying(false) })
361
348
  if (log) log.classList.add('is-staged')
@@ -401,10 +388,9 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
401
388
 
402
389
  function applyEchoHighlight() {
403
390
  if (!asidePane) return
404
- const activeKey = hoverCat || (userClickedInspect ? openCat : null)
405
- stackedBar?.classList.toggle('lc-stacked-dim', Boolean(activeKey))
391
+ stackedBar?.classList.toggle('lc-stacked-dim', Boolean(hoverCat))
406
392
  asidePane.querySelectorAll('[data-cat-key]').forEach(el => {
407
- const match = activeKey && el.dataset.catKey === activeKey
393
+ const match = hoverCat && el.dataset.catKey === hoverCat
408
394
  el.classList.toggle('lc-stacked-seg-on', Boolean(match && el.classList.contains('lc-stacked-seg')))
409
395
  el.classList.toggle('lc-chip-on', Boolean(match && el.classList.contains('lc-chip')))
410
396
  })
@@ -417,6 +403,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
417
403
  entry.addEventListener('click', event => {
418
404
  const lbBtn = event.target.closest('[data-lightbox-src]')
419
405
  if (lbBtn && lightbox && lightboxImg) {
406
+ event.preventDefault()
420
407
  event.stopPropagation()
421
408
  if (playing) setPlaying(false)
422
409
  lightbox.classList.remove('is-doc')
@@ -454,18 +441,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
454
441
  }
455
442
  if (event.target.closest('a, audio, video, summary, button')) return
456
443
  if (stepIndex > playHead) return
457
- if (playing) setPlaying(false)
458
- const step = steps[stepIndex]
459
- selectedIdx = stepIndex
460
- userClickedInspect = true
461
- openCat = step?.primaryCat || null
462
- follow = false
463
- render()
464
- if (openCat) {
465
- requestAnimationFrame(() => {
466
- asidePane?.querySelector(`[data-browser-cat="${openCat}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
467
- })
468
- }
444
+ jumpToStep(stepIndex)
469
445
  })
470
446
  entry.addEventListener('mouseenter', () => {
471
447
  if (stepIndex > playHead) return
@@ -486,18 +462,23 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
486
462
  if (snapLabel) {
487
463
  if (stepState.index < 0) {
488
464
  snapLabel.textContent = t('snapInitial')
489
- } else if (selectedIdx < playHead) {
490
- snapLabel.textContent = t('snapInspect', { step: stepState.index + 1, total: steps.length })
491
465
  } else {
492
466
  snapLabel.textContent = t('snapCurrent', { step: stepState.index + 1, total: steps.length })
493
467
  }
494
468
  }
495
469
  const totEl = asidePane.querySelector('[data-context-tot]')
496
- if (totEl) totEl.textContent = `${(snap.totalTokens / 1000).toFixed(1)}k`
470
+ if (totEl) totEl.textContent = contextUsageLabel(snap, t, stepState.index < 0)
497
471
  const winEl = asidePane.querySelector('[data-context-win]')
498
- if (winEl && snap.windowLabel) winEl.textContent = snap.windowLabel
472
+ if (winEl) winEl.textContent = snap.windowLabel || t('unknownCapacity')
473
+ const unit = asidePane.querySelector('[data-capacity-unit]')
474
+ if (unit) unit.hidden = !snap.windowLabel
499
475
  const pctEl = asidePane.querySelector('[data-context-pct]')
500
- if (pctEl) pctEl.textContent = `${snap.pct}%`
476
+ if (pctEl) {
477
+ pctEl.parentElement.hidden = snap.pct == null
478
+ pctEl.textContent = snap.pct == null ? '' : snap.pct + '%'
479
+ }
480
+ const bar = asidePane.querySelector('[data-stacked-bar]')
481
+ if (bar) bar.hidden = snap.pct == null
501
482
 
502
483
  for (const [key, val] of Object.entries(snap.segments || {})) {
503
484
  const seg = asidePane.querySelector(`[data-seg="${key}"]`)
@@ -506,7 +487,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
506
487
 
507
488
  for (const [key, val] of Object.entries(snap.tokensByKind || {})) {
508
489
  const tokEl = asidePane.querySelector(`[data-pro-tok="${key}"]`)
509
- if (tokEl) tokEl.textContent = `≈${(val / 1000).toFixed(1)}k`
490
+ if (tokEl) tokEl.textContent = categoryUsageLabel(val, t)
510
491
  }
511
492
 
512
493
  const browserBox = asidePane.querySelector('[data-context-browser]')
@@ -588,22 +569,24 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
588
569
  if (event.target === lightbox) closeLightbox()
589
570
  })
590
571
 
572
+ let hoverStep = null
591
573
  function renderTimelineHover(idx) {
592
- if (!tlPop) return
574
+ if (!tlPop || hoverStep === idx) return
575
+ hoverStep = idx
593
576
  if (idx === null || idx < 0 || idx >= steps.length) {
594
577
  tlPop.hidden = true
595
578
  return
596
579
  }
597
580
  const s = steps[idx]
598
581
  const pct = steps.length > 0 ? Math.min(88, Math.max(12, ((idx + 0.5) / steps.length) * 100)) : 50
599
- const frame = s.frames?.[0]
582
+ const frame = s.frames?.find(frame => frame.who === 'ai') || s.frames?.[0]
600
583
  const doc = s.docs?.[0]
601
584
  const ci = s.compactInfo
602
585
  const thumbHtml = frame
603
586
  ? `<span class="session-tl-pop-thumb"><img src="${escapeHtml(frame.img)}" alt=""></span>`
604
587
  : ''
605
588
  const headTitle = ci
606
- ? t('tlCompressTitle', { seq: ci.seq, dropped: ((ci.droppedTokens || 0) / 1000).toFixed(0) })
589
+ ? (ci.droppedTokens == null ? t('compactTitle', { seq: ci.seq }) : t('tlCompressTitle', { seq: ci.seq, dropped: (ci.droppedTokens / 1000).toFixed(0) }))
607
590
  : frame
608
591
  ? `🖼 ${frame.label}`
609
592
  : doc
@@ -611,51 +594,76 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
611
594
  : s.kind === 'prompt'
612
595
  ? t('tlPromptTitle', { turn: s.turn, summary: shorten(s.summary || '', 20) })
613
596
  : shorten(s.summary || t('tlStepFallback'), 24)
614
- const tokStr = `${((s.contextSnapshot?.totalTokens || 0) / 1000).toFixed(1)}k`
615
- tlPop.style.left = `${pct.toFixed(1)}%`
616
- tlPop.innerHTML = `${thumbHtml}<span class="session-tl-pop-meta"><small>${escapeHtml(t('tlStepMeta', { step: idx + 1, time: elapsedClock(s.t) }))}</small><b>${escapeHtml(headTitle)}</b><span>${escapeHtml(t('contextLabel'))} ≈${escapeHtml(tokStr)}</span></span>`
597
+ const tokStr = contextUsageLabel(s.contextSnapshot, t)
598
+ tlPop.style.left = `clamp(min(130px, 50%), ${pct.toFixed(1)}%, max(50%, 100% - 130px))`
599
+ tlPop.innerHTML = `${thumbHtml}<span class="session-tl-pop-meta"><small>${escapeHtml(t('tlStepMeta', { step: idx + 1, time: elapsedClock(s.t) }))}</small><b>${escapeHtml(headTitle)}</b><span>${escapeHtml(t('contextLabel'))} ${escapeHtml(tokStr)}</span></span>`
617
600
  tlPop.hidden = false
618
601
  }
619
602
 
620
- function jumpViaTimeline(idx) {
621
- const clamped = Math.max(0, Math.min(steps.length - 1, idx))
622
- if (playing) setPlaying(false)
623
- activate()
624
- if (clamped > playHead) {
625
- clearStepAnimations()
626
- playHead = clamped
627
- prevRenderedHead = clamped
628
- animatedHead = clamped
629
- selectedIdx = clamped
630
- userClickedInspect = false
631
- openCat = steps[clamped]?.primaryCat || null
632
- const next = steps[playHead + 1]
633
- const nextDraft = next?.kind === 'prompt' ? rawPromptTextOf(next.index) : ''
634
- if (nextDraft) setComposerVisual('draft', nextDraft)
635
- else setComposerVisual('idle')
636
- follow = true
637
- render()
638
- } else {
639
- selectedIdx = clamped
640
- userClickedInspect = clamped < playHead
641
- openCat = steps[clamped]?.primaryCat || null
642
- follow = false
643
- render()
644
- const targetEntry = stepEntries.find(e => e.stepIndex === clamped)?.entry
645
- if (targetEntry) camera.frameEntry(targetEntry, false)
603
+ function jumpToStep(idx) {
604
+ setPlaying(false)
605
+ // A seek shows the completed Step immediately, including a one-Step jump.
606
+ prevRenderedHead = idx
607
+ goToStage(idx)
608
+ }
609
+
610
+ function seekFromTimeline(idx) {
611
+ const before = tlTrack.getBoundingClientRect()
612
+ jumpToStep(idx)
613
+ // On mobile the context list sits above the rail and can grow by several screens.
614
+ if (before.top >= 0 && before.bottom <= window.innerHeight) {
615
+ const delta = tlTrack.getBoundingClientRect().top - before.top
616
+ if (delta) window.scrollBy({ top: delta, behavior: 'instant' })
617
+ }
618
+ }
619
+
620
+ const priority = { compress: 0, frame: 1, doc: 2, turn: 3 }
621
+ const labelOrder = [...tlPins].sort((a, b) => priority[a.dataset.kind] - priority[b.dataset.kind])
622
+ function fitTimelineLabels() {
623
+ const width = tlTrack.clientWidth
624
+ const occupied = []
625
+ // Fit full captions first. A crowded milestone can still appear as an icon.
626
+ for (const pin of labelOrder) pin.classList.remove('is-visible', 'is-compact')
627
+ for (const compact of [false, true]) {
628
+ const candidates = labelOrder.filter(pin => !pin.classList.contains('is-visible') && (compact || pin.dataset.kind !== 'turn'))
629
+ for (const pin of candidates) pin.classList.toggle('is-compact', compact)
630
+ const measured = candidates.map(pin => ({ pin, size: pin.offsetWidth }))
631
+ for (const { pin, size } of measured) {
632
+ const anchor = (Number(pin.dataset.tlJump) + 1.5) / (steps.length + 1) * width
633
+ const left = Math.max(0, Math.min(width - size, anchor - size / 2))
634
+ const right = left + size
635
+ if (right > width || occupied.some(span => right + 4 > span.left && left < span.right + 4)) continue
636
+ pin.style.left = `${left}px`
637
+ pin.classList.add('is-visible')
638
+ occupied.push({ left, right })
639
+ }
646
640
  }
647
641
  }
648
642
 
649
- tlTrack?.addEventListener('mouseover', event => {
650
- const h = event.target.closest('[data-tl-hover]')
651
- renderTimelineHover(h ? Number(h.dataset.tlHover) : null)
643
+ const labelObserver = tlPins.length ? new ResizeObserver(fitTimelineLabels) : null
644
+ if (labelObserver) labelObserver.observe(tlTrack)
645
+ tlRange?.addEventListener('input', () => seekFromTimeline(tlRange.valueAsNumber - 1))
646
+ tlRange?.addEventListener('pointerdown', () => { if (playing) setPlaying(false) })
647
+ tlTrack?.addEventListener('pointermove', event => {
648
+ const pin = event.target.closest('[data-tl-jump]')
649
+ if (pin) return renderTimelineHover(Number(pin.dataset.tlJump))
650
+ if (event.target !== tlRange || !steps.length) return renderTimelineHover(null)
651
+ const rect = tlRange.getBoundingClientRect()
652
+ const step = Math.floor((event.clientX - rect.left) / rect.width * (steps.length + 1))
653
+ renderTimelineHover(Math.max(0, Math.min(steps.length - 1, step - 1)))
654
+ })
655
+ tlTrack?.addEventListener('focusin', event => {
656
+ const pin = event.target.closest('[data-tl-jump]')
657
+ renderTimelineHover(pin ? Number(pin.dataset.tlJump) : playHead)
652
658
  })
653
- tlTrack?.addEventListener('mouseleave', () => renderTimelineHover(null))
659
+ tlTrack?.addEventListener('focusout', () => renderTimelineHover(null))
660
+ tlTrack?.addEventListener('keydown', event => {
661
+ if (event.key === 'Escape') renderTimelineHover(null)
662
+ })
663
+ tlTrack?.addEventListener('pointerleave', () => renderTimelineHover(null))
654
664
  tlTrack?.addEventListener('click', event => {
655
- const el = event.target.closest('[data-tl-jump], [data-tl-step]')
656
- if (!el) return
657
- const idx = Number(el.dataset.tlJump ?? el.dataset.tlStep)
658
- if (Number.isFinite(idx)) jumpViaTimeline(idx)
665
+ const pin = event.target.closest('[data-tl-jump]')
666
+ if (pin) seekFromTimeline(Number(pin.dataset.tlJump))
659
667
  })
660
668
 
661
669
  asidePane?.addEventListener('click', event => {
@@ -685,7 +693,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
685
693
  if (chipOrSeg) {
686
694
  const catId = chipOrSeg.dataset.catKey
687
695
  openCat = openCat === catId ? null : catId
688
- renderContextSidebar(currentSelectedState())
696
+ renderContextSidebar(stateForIndex(playHead))
689
697
  asidePane.querySelector(`[data-browser-cat="${catId}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
690
698
  return
691
699
  }
@@ -693,7 +701,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
693
701
  if (catBtn && !catBtn.disabled) {
694
702
  const catId = catBtn.dataset.browserCatToggle
695
703
  openCat = openCat === catId ? null : catId
696
- renderContextSidebar(currentSelectedState())
704
+ renderContextSidebar(stateForIndex(playHead))
697
705
  return
698
706
  }
699
707
  const itemBtn = event.target.closest('[data-browser-item-toggle]')
@@ -701,7 +709,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
701
709
  const itemId = itemBtn.dataset.browserItemToggle
702
710
  if (openItems.has(itemId)) openItems.delete(itemId)
703
711
  else openItems.add(itemId)
704
- renderContextSidebar(currentSelectedState())
712
+ renderContextSidebar(stateForIndex(playHead))
705
713
  }
706
714
  })
707
715
 
@@ -930,7 +938,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
930
938
  }
931
939
 
932
940
  function runHeadChoreography(headState, headEntry, animateNewStep, steppedForwardOne) {
933
- updateProgressHairline()
934
941
  if (!animateNewStep) return
935
942
  clearStepAnimations()
936
943
 
@@ -974,7 +981,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
974
981
  if (headState.kind === 'compact') {
975
982
  setComposerVisual('running')
976
983
  openCat = 'tool'
977
- renderContextSidebar(currentSelectedState())
984
+ renderContextSidebar(stateForIndex(playHead))
978
985
  if (headEntry && !calm.matches && typeof headEntry.animate === 'function') {
979
986
  activeAnims.push(headEntry.animate(
980
987
  [
@@ -1003,7 +1010,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1003
1010
 
1004
1011
  function render() {
1005
1012
  const headState = stateForIndex(playHead)
1006
- const selectedState = currentSelectedState()
1007
1013
  curTime = headState.index < 0 ? 0 : headState.t
1008
1014
  const x = (playerData.end > 0 ? ((curTime / playerData.end) * width) : 0).toFixed(1)
1009
1015
  if (head) {
@@ -1024,45 +1030,26 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1024
1030
  play.setAttribute('aria-label', atEnd ? t('replayAria') : t('playAria'))
1025
1031
  }
1026
1032
 
1027
- renderContextSidebar(selectedState)
1028
- const shownIdx = userClickedInspect && selectedIdx >= 0 ? selectedIdx : playHead
1029
- const shownTime = shownIdx < 0 ? 0 : (steps[shownIdx]?.t || 0)
1030
- updateProgressHairline(shownIdx)
1031
- if (speedBadge) {
1032
- speedBadge.innerHTML = `<b>${Math.max(0, shownIdx + 1)}</b> / ${steps.length} · ${elapsedClock(shownTime)}`
1033
+ renderContextSidebar(headState)
1034
+ const stepNumber = playHead + 1
1035
+ if (speedBadge) speedBadge.innerHTML = `<b>${stepNumber}</b> / ${steps.length} · ${elapsedClock(curTime)}`
1036
+ if (tlRange) {
1037
+ tlRange.value = String(stepNumber)
1038
+ tlRange.setAttribute('aria-valuetext', t('tlStepMeta', { step: stepNumber, time: elapsedClock(curTime) }))
1033
1039
  }
1034
- tlSegs.forEach((seg, idx) => {
1035
- seg.classList.toggle('is-past', idx <= playHead && idx !== shownIdx)
1036
- seg.classList.toggle('is-active', idx === shownIdx && shownIdx >= 0)
1037
- })
1038
- tlPins.forEach(pin => {
1039
- const pIdx = Number(pin.dataset.tlJump)
1040
- pin.classList.toggle('is-on', pIdx === shownIdx && shownIdx >= 0)
1041
- pin.classList.toggle('is-reached', pIdx <= playHead)
1042
- })
1040
+ if (cells) {
1041
+ for (let i = 0; i < cells.length; i++) {
1042
+ cells[i].classList.toggle('is-past', i > 0 && i < stepNumber)
1043
+ cells[i].classList.toggle('is-active', i === stepNumber)
1044
+ }
1045
+ }
1046
+ if (tlRange?.matches(':focus-visible')) renderTimelineHover(playHead)
1047
+ for (const pin of tlPins) pin.classList.toggle('is-on', Number(pin.dataset.tlJump) === playHead)
1043
1048
 
1044
1049
  let latestVisibleEntry
1045
1050
  for (const item of stepEntries) {
1046
1051
  const future = item.stepIndex > playHead
1047
1052
  item.entry.classList.toggle('is-future', future)
1048
- const isInspectSelected = !future && userClickedInspect && item.stepIndex === selectedIdx
1049
- item.entry.classList.toggle('is-selected', isInspectSelected)
1050
-
1051
- let tag = item.entry.querySelector('.session-inspect-tag')
1052
- if (isInspectSelected) {
1053
- if (!tag) {
1054
- tag = document.createElement('span')
1055
- tag.className = 'session-inspect-tag'
1056
- item.entry.prepend(tag)
1057
- }
1058
- const stTime = steps[selectedIdx]?.t || 0
1059
- tag.textContent = t.lang === 'en'
1060
- ? `Snapshot #${selectedIdx + 1} · ${elapsedClock(stTime)}`
1061
- : `快照 #${selectedIdx + 1} · ${elapsedClock(stTime)}`
1062
- } else if (tag) {
1063
- tag.remove()
1064
- }
1065
-
1066
1053
  if (!future) latestVisibleEntry = item.entry
1067
1054
  }
1068
1055
  for (const aux of auxEntries) {
@@ -1096,8 +1083,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1096
1083
  activate()
1097
1084
  if (shouldScroll) camera.resumeFollow()
1098
1085
  playHead = Math.max(-1, Math.min(steps.length - 1, nextIdx))
1099
- selectedIdx = playHead
1100
- userClickedInspect = false
1101
1086
  openCat = playHead < 0 ? null : (steps[playHead]?.primaryCat || null)
1102
1087
  follow = shouldScroll
1103
1088
  animatedHead = -2
@@ -1121,7 +1106,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1121
1106
  const nextDraft = next?.kind === 'prompt' ? rawPromptTextOf(next.index) : ''
1122
1107
  if (nextDraft) setComposerVisual('draft', nextDraft)
1123
1108
  else setComposerVisual('idle')
1124
- updateProgressHairline()
1125
1109
  return
1126
1110
  }
1127
1111
  activate()
@@ -1130,19 +1114,11 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1130
1114
  clearStepAnimations()
1131
1115
  playHead = -1
1132
1116
  prevRenderedHead = -1
1133
- selectedIdx = -1
1134
- userClickedInspect = false
1135
1117
  openCat = null
1136
1118
  follow = true
1137
1119
  animatedHead = -1
1138
1120
  render()
1139
1121
  }
1140
- if (selectedIdx < playHead) {
1141
- selectedIdx = playHead
1142
- userClickedInspect = false
1143
- openCat = steps[playHead]?.primaryCat || null
1144
- render()
1145
- }
1146
1122
  if (!stepBusy) {
1147
1123
  if (playHead < 0) {
1148
1124
  const firstDraft = steps[0]?.kind === 'prompt' ? rawPromptTextOf(0) : ''
@@ -1243,6 +1219,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1243
1219
  destroy() {
1244
1220
  clearStepAnimations()
1245
1221
  camera.stop()
1222
+ labelObserver?.disconnect()
1246
1223
  appEl.removeEventListener('keydown', onKeyDown)
1247
1224
  },
1248
1225
  goToStage,
@@ -1270,6 +1247,10 @@ export async function createEncorePlayer(targetEl, sourceOrSession, options = {}
1270
1247
  const appNode = el.querySelector('.session-app')
1271
1248
  const activeLang = resolveLang(options.lang || el.dataset.lang || appNode?.dataset.encoreLang || 'zh')
1272
1249
  const playerData = JSON.parse(preRenderedData.textContent)
1250
+ const footer = el.querySelector('[data-session-timeline]')
1251
+ if (footer && !footer.querySelector('.session-tl-cells')) {
1252
+ footer.outerHTML = renderTimelineBar(playerData, createTranslator(activeLang))
1253
+ }
1273
1254
  const activeController = attachPlayerController(el, playerData, {
1274
1255
  lang: activeLang,
1275
1256
  initialStep: options.initialStep ?? -1,
@@ -1312,7 +1293,7 @@ export async function createEncorePlayer(targetEl, sourceOrSession, options = {}
1312
1293
  if (activeController) activeController.destroy()
1313
1294
  activeLang = resolveLang(lang)
1314
1295
  const line = timeline(session, { lang: activeLang })
1315
- el.innerHTML = renderPlayerWidget(session, line, { lang: activeLang, baseUrl, showLangToggle: options.showLangToggle })
1296
+ el.innerHTML = renderPlayerWidget(session, line, { ...options, lang: activeLang, baseUrl })
1316
1297
  if (session.title && document.querySelectorAll('[data-encore-player]').length <= 1) {
1317
1298
  document.title = `${session.title} · Encore`
1318
1299
  }