@niracler/encore 0.2.0 → 0.4.0

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,6 +1,7 @@
1
1
  import { createTranslator, resolveLang } from './i18n.mjs'
2
+ import { attachAttachmentReaders } from './attachment-reader.mjs'
2
3
  import { escapeHtml } from './markdown.mjs'
3
- import { buildPlayerData, elapsedClock, renderPlayerWidget, wallClock } from './render.mjs'
4
+ import { buildPlayerData, elapsedClock, renderPlayerWidget, renderTimelineBar, wallClock } from './render.mjs'
4
5
  import { timeline } from './timeline.mjs'
5
6
 
6
7
  const shorten = (text, length) => (text.length > length ? `${text.slice(0, length)}…` : text)
@@ -112,11 +113,11 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
112
113
  const stageTrigger = containerEl.querySelector('[data-session-stage-trigger]')
113
114
  const composerText = containerEl.querySelector('[data-session-composer-text]')
114
115
  const sendBtn = containerEl.querySelector('[data-session-send]')
115
- const progressBar = containerEl.querySelector('[data-session-progress]')
116
116
  const timelineBar = containerEl.querySelector('[data-session-timeline]')
117
117
  const tlTrack = timelineBar?.querySelector('[data-tl-track]')
118
118
  const tlPop = timelineBar?.querySelector('[data-tl-pop]')
119
- 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
120
121
  const tlPins = timelineBar ? [...timelineBar.querySelectorAll('[data-tl-jump]')] : []
121
122
  const lightbox = containerEl.querySelector('[data-session-lightbox]')
122
123
  const lightboxImg = lightbox?.querySelector('[data-lightbox-img]')
@@ -142,8 +143,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
142
143
  let curTime = 0
143
144
  let playHead = initialStep
144
145
  let prevRenderedHead = initialStep
145
- let selectedIdx = initialStep
146
- let userClickedInspect = false
147
146
  let isInitialMount = true
148
147
  let playing = false
149
148
  let stepBusy = false
@@ -265,13 +264,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
265
264
  stepBusy = false
266
265
  }
267
266
 
268
- function updateProgressHairline(idx = playHead) {
269
- if (!progressBar) return
270
- const ratio = steps.length > 0 && idx >= 0 ? Math.max(0, Math.min(1, (idx + 0.5) / steps.length)) : 0
271
- progressBar.style.opacity = idx >= 0 || playing ? '1' : '0'
272
- progressBar.style.transform = `scaleX(${ratio.toFixed(4)})`
273
- }
274
-
275
267
  function rawPromptTextOf(stepIdx) {
276
268
  const step = steps[stepIdx]
277
269
  if (!step || step.kind !== 'prompt') return ''
@@ -351,12 +343,37 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
351
343
  return idx < 0 ? buildPrePromptStep() : model.selectStep(idx)
352
344
  }
353
345
 
354
- function currentSelectedState() {
355
- return stateForIndex(selectedIdx)
356
- }
357
-
358
346
  if (play) play.hidden = false
347
+ attachAttachmentReaders(containerEl, t, () => { if (playing) setPlaying(false) })
359
348
  if (log) log.classList.add('is-staged')
349
+ for (const formats of containerEl.querySelectorAll('.session-video-formats')) {
350
+ const figure = formats.closest('figure')
351
+ const video = figure.querySelector('video')
352
+ formats.addEventListener('click', async event => {
353
+ const button = event.target.closest('[data-video-format]')
354
+ if (!button || button.getAttribute('aria-pressed') === 'true') return
355
+ const time = video.currentTime
356
+ const resume = !video.paused && !video.ended
357
+ formats.querySelector('[aria-pressed="true"]').setAttribute('aria-pressed', 'false')
358
+ button.setAttribute('aria-pressed', 'true')
359
+ video.dataset.format = button.dataset.videoFormat
360
+ if (button.dataset.cover) video.poster = button.dataset.cover
361
+ else video.removeAttribute('poster')
362
+ video.preload = time > 0 ? 'metadata' : 'none'
363
+ video.src = button.dataset.src
364
+ video.load()
365
+ if (time > 0) video.currentTime = time
366
+ figure.scrollIntoView({ block: 'nearest' })
367
+ if (resume) {
368
+ try {
369
+ await video.play()
370
+ } catch (error) {
371
+ // Switching again or pausing can interrupt the pending play request.
372
+ if (error.name !== 'AbortError') throw error
373
+ }
374
+ }
375
+ })
376
+ }
360
377
  if (scrubber) {
361
378
  scrubber.classList.add('is-ready')
362
379
  scrubber.removeAttribute('aria-hidden')
@@ -371,10 +388,9 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
371
388
 
372
389
  function applyEchoHighlight() {
373
390
  if (!asidePane) return
374
- const activeKey = hoverCat || (userClickedInspect ? openCat : null)
375
- stackedBar?.classList.toggle('lc-stacked-dim', Boolean(activeKey))
391
+ stackedBar?.classList.toggle('lc-stacked-dim', Boolean(hoverCat))
376
392
  asidePane.querySelectorAll('[data-cat-key]').forEach(el => {
377
- const match = activeKey && el.dataset.catKey === activeKey
393
+ const match = hoverCat && el.dataset.catKey === hoverCat
378
394
  el.classList.toggle('lc-stacked-seg-on', Boolean(match && el.classList.contains('lc-stacked-seg')))
379
395
  el.classList.toggle('lc-chip-on', Boolean(match && el.classList.contains('lc-chip')))
380
396
  })
@@ -387,6 +403,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
387
403
  entry.addEventListener('click', event => {
388
404
  const lbBtn = event.target.closest('[data-lightbox-src]')
389
405
  if (lbBtn && lightbox && lightboxImg) {
406
+ event.preventDefault()
390
407
  event.stopPropagation()
391
408
  if (playing) setPlaying(false)
392
409
  lightbox.classList.remove('is-doc')
@@ -424,18 +441,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
424
441
  }
425
442
  if (event.target.closest('a, audio, video, summary, button')) return
426
443
  if (stepIndex > playHead) return
427
- if (playing) setPlaying(false)
428
- const step = steps[stepIndex]
429
- selectedIdx = stepIndex
430
- userClickedInspect = true
431
- openCat = step?.primaryCat || null
432
- follow = false
433
- render()
434
- if (openCat) {
435
- requestAnimationFrame(() => {
436
- asidePane?.querySelector(`[data-browser-cat="${openCat}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
437
- })
438
- }
444
+ jumpToStep(stepIndex)
439
445
  })
440
446
  entry.addEventListener('mouseenter', () => {
441
447
  if (stepIndex > playHead) return
@@ -456,8 +462,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
456
462
  if (snapLabel) {
457
463
  if (stepState.index < 0) {
458
464
  snapLabel.textContent = t('snapInitial')
459
- } else if (selectedIdx < playHead) {
460
- snapLabel.textContent = t('snapInspect', { step: stepState.index + 1, total: steps.length })
461
465
  } else {
462
466
  snapLabel.textContent = t('snapCurrent', { step: stepState.index + 1, total: steps.length })
463
467
  }
@@ -558,15 +562,17 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
558
562
  if (event.target === lightbox) closeLightbox()
559
563
  })
560
564
 
565
+ let hoverStep = null
561
566
  function renderTimelineHover(idx) {
562
- if (!tlPop) return
567
+ if (!tlPop || hoverStep === idx) return
568
+ hoverStep = idx
563
569
  if (idx === null || idx < 0 || idx >= steps.length) {
564
570
  tlPop.hidden = true
565
571
  return
566
572
  }
567
573
  const s = steps[idx]
568
574
  const pct = steps.length > 0 ? Math.min(88, Math.max(12, ((idx + 0.5) / steps.length) * 100)) : 50
569
- const frame = s.frames?.[0]
575
+ const frame = s.frames?.find(frame => frame.who === 'ai') || s.frames?.[0]
570
576
  const doc = s.docs?.[0]
571
577
  const ci = s.compactInfo
572
578
  const thumbHtml = frame
@@ -582,50 +588,75 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
582
588
  ? t('tlPromptTitle', { turn: s.turn, summary: shorten(s.summary || '', 20) })
583
589
  : shorten(s.summary || t('tlStepFallback'), 24)
584
590
  const tokStr = `${((s.contextSnapshot?.totalTokens || 0) / 1000).toFixed(1)}k`
585
- tlPop.style.left = `${pct.toFixed(1)}%`
586
- 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>Context ≈${escapeHtml(tokStr)}</span></span>`
591
+ tlPop.style.left = `clamp(min(130px, 50%), ${pct.toFixed(1)}%, max(50%, 100% - 130px))`
592
+ 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>`
587
593
  tlPop.hidden = false
588
594
  }
589
595
 
590
- function jumpViaTimeline(idx) {
591
- const clamped = Math.max(0, Math.min(steps.length - 1, idx))
592
- if (playing) setPlaying(false)
593
- activate()
594
- if (clamped > playHead) {
595
- clearStepAnimations()
596
- playHead = clamped
597
- prevRenderedHead = clamped
598
- animatedHead = clamped
599
- selectedIdx = clamped
600
- userClickedInspect = false
601
- openCat = steps[clamped]?.primaryCat || null
602
- const next = steps[playHead + 1]
603
- const nextDraft = next?.kind === 'prompt' ? rawPromptTextOf(next.index) : ''
604
- if (nextDraft) setComposerVisual('draft', nextDraft)
605
- else setComposerVisual('idle')
606
- follow = true
607
- render()
608
- } else {
609
- selectedIdx = clamped
610
- userClickedInspect = clamped < playHead
611
- openCat = steps[clamped]?.primaryCat || null
612
- follow = false
613
- render()
614
- const targetEntry = stepEntries.find(e => e.stepIndex === clamped)?.entry
615
- if (targetEntry) camera.frameEntry(targetEntry, false)
596
+ function jumpToStep(idx) {
597
+ setPlaying(false)
598
+ // A seek shows the completed Step immediately, including a one-Step jump.
599
+ prevRenderedHead = idx
600
+ goToStage(idx)
601
+ }
602
+
603
+ function seekFromTimeline(idx) {
604
+ const before = tlTrack.getBoundingClientRect()
605
+ jumpToStep(idx)
606
+ // On mobile the context list sits above the rail and can grow by several screens.
607
+ if (before.top >= 0 && before.bottom <= window.innerHeight) {
608
+ const delta = tlTrack.getBoundingClientRect().top - before.top
609
+ if (delta) window.scrollBy({ top: delta, behavior: 'instant' })
610
+ }
611
+ }
612
+
613
+ const priority = { compress: 0, frame: 1, doc: 2, turn: 3 }
614
+ const labelOrder = [...tlPins].sort((a, b) => priority[a.dataset.kind] - priority[b.dataset.kind])
615
+ function fitTimelineLabels() {
616
+ const width = tlTrack.clientWidth
617
+ const occupied = []
618
+ // Fit full captions first. A crowded milestone can still appear as an icon.
619
+ for (const pin of labelOrder) pin.classList.remove('is-visible', 'is-compact')
620
+ for (const compact of [false, true]) {
621
+ const candidates = labelOrder.filter(pin => !pin.classList.contains('is-visible') && (compact || pin.dataset.kind !== 'turn'))
622
+ for (const pin of candidates) pin.classList.toggle('is-compact', compact)
623
+ const measured = candidates.map(pin => ({ pin, size: pin.offsetWidth }))
624
+ for (const { pin, size } of measured) {
625
+ const anchor = (Number(pin.dataset.tlJump) + 1.5) / (steps.length + 1) * width
626
+ const left = Math.max(0, Math.min(width - size, anchor - size / 2))
627
+ const right = left + size
628
+ if (right > width || occupied.some(span => right + 4 > span.left && left < span.right + 4)) continue
629
+ pin.style.left = `${left}px`
630
+ pin.classList.add('is-visible')
631
+ occupied.push({ left, right })
632
+ }
616
633
  }
617
634
  }
618
635
 
619
- tlTrack?.addEventListener('mouseover', event => {
620
- const h = event.target.closest('[data-tl-hover]')
621
- renderTimelineHover(h ? Number(h.dataset.tlHover) : null)
636
+ const labelObserver = tlPins.length ? new ResizeObserver(fitTimelineLabels) : null
637
+ if (labelObserver) labelObserver.observe(tlTrack)
638
+ tlRange?.addEventListener('input', () => seekFromTimeline(tlRange.valueAsNumber - 1))
639
+ tlRange?.addEventListener('pointerdown', () => { if (playing) setPlaying(false) })
640
+ tlTrack?.addEventListener('pointermove', event => {
641
+ const pin = event.target.closest('[data-tl-jump]')
642
+ if (pin) return renderTimelineHover(Number(pin.dataset.tlJump))
643
+ if (event.target !== tlRange || !steps.length) return renderTimelineHover(null)
644
+ const rect = tlRange.getBoundingClientRect()
645
+ const step = Math.floor((event.clientX - rect.left) / rect.width * (steps.length + 1))
646
+ renderTimelineHover(Math.max(0, Math.min(steps.length - 1, step - 1)))
622
647
  })
623
- tlTrack?.addEventListener('mouseleave', () => renderTimelineHover(null))
648
+ tlTrack?.addEventListener('focusin', event => {
649
+ const pin = event.target.closest('[data-tl-jump]')
650
+ renderTimelineHover(pin ? Number(pin.dataset.tlJump) : playHead)
651
+ })
652
+ tlTrack?.addEventListener('focusout', () => renderTimelineHover(null))
653
+ tlTrack?.addEventListener('keydown', event => {
654
+ if (event.key === 'Escape') renderTimelineHover(null)
655
+ })
656
+ tlTrack?.addEventListener('pointerleave', () => renderTimelineHover(null))
624
657
  tlTrack?.addEventListener('click', event => {
625
- const el = event.target.closest('[data-tl-jump], [data-tl-step]')
626
- if (!el) return
627
- const idx = Number(el.dataset.tlJump ?? el.dataset.tlStep)
628
- if (Number.isFinite(idx)) jumpViaTimeline(idx)
658
+ const pin = event.target.closest('[data-tl-jump]')
659
+ if (pin) seekFromTimeline(Number(pin.dataset.tlJump))
629
660
  })
630
661
 
631
662
  asidePane?.addEventListener('click', event => {
@@ -655,7 +686,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
655
686
  if (chipOrSeg) {
656
687
  const catId = chipOrSeg.dataset.catKey
657
688
  openCat = openCat === catId ? null : catId
658
- renderContextSidebar(currentSelectedState())
689
+ renderContextSidebar(stateForIndex(playHead))
659
690
  asidePane.querySelector(`[data-browser-cat="${catId}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
660
691
  return
661
692
  }
@@ -663,7 +694,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
663
694
  if (catBtn && !catBtn.disabled) {
664
695
  const catId = catBtn.dataset.browserCatToggle
665
696
  openCat = openCat === catId ? null : catId
666
- renderContextSidebar(currentSelectedState())
697
+ renderContextSidebar(stateForIndex(playHead))
667
698
  return
668
699
  }
669
700
  const itemBtn = event.target.closest('[data-browser-item-toggle]')
@@ -671,7 +702,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
671
702
  const itemId = itemBtn.dataset.browserItemToggle
672
703
  if (openItems.has(itemId)) openItems.delete(itemId)
673
704
  else openItems.add(itemId)
674
- renderContextSidebar(currentSelectedState())
705
+ renderContextSidebar(stateForIndex(playHead))
675
706
  }
676
707
  })
677
708
 
@@ -900,7 +931,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
900
931
  }
901
932
 
902
933
  function runHeadChoreography(headState, headEntry, animateNewStep, steppedForwardOne) {
903
- updateProgressHairline()
904
934
  if (!animateNewStep) return
905
935
  clearStepAnimations()
906
936
 
@@ -944,7 +974,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
944
974
  if (headState.kind === 'compact') {
945
975
  setComposerVisual('running')
946
976
  openCat = 'tool'
947
- renderContextSidebar(currentSelectedState())
977
+ renderContextSidebar(stateForIndex(playHead))
948
978
  if (headEntry && !calm.matches && typeof headEntry.animate === 'function') {
949
979
  activeAnims.push(headEntry.animate(
950
980
  [
@@ -973,7 +1003,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
973
1003
 
974
1004
  function render() {
975
1005
  const headState = stateForIndex(playHead)
976
- const selectedState = currentSelectedState()
977
1006
  curTime = headState.index < 0 ? 0 : headState.t
978
1007
  const x = (playerData.end > 0 ? ((curTime / playerData.end) * width) : 0).toFixed(1)
979
1008
  if (head) {
@@ -994,48 +1023,32 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
994
1023
  play.setAttribute('aria-label', atEnd ? t('replayAria') : t('playAria'))
995
1024
  }
996
1025
 
997
- renderContextSidebar(selectedState)
998
- const shownIdx = userClickedInspect && selectedIdx >= 0 ? selectedIdx : playHead
999
- const shownTime = shownIdx < 0 ? 0 : (steps[shownIdx]?.t || 0)
1000
- updateProgressHairline(shownIdx)
1001
- if (speedBadge) {
1002
- speedBadge.innerHTML = `<b>${Math.max(0, shownIdx + 1)}</b> / ${steps.length} · ${elapsedClock(shownTime)}`
1026
+ renderContextSidebar(headState)
1027
+ const stepNumber = playHead + 1
1028
+ if (speedBadge) speedBadge.innerHTML = `<b>${stepNumber}</b> / ${steps.length} · ${elapsedClock(curTime)}`
1029
+ if (tlRange) {
1030
+ tlRange.value = String(stepNumber)
1031
+ tlRange.setAttribute('aria-valuetext', t('tlStepMeta', { step: stepNumber, time: elapsedClock(curTime) }))
1003
1032
  }
1004
- tlSegs.forEach((seg, idx) => {
1005
- seg.classList.toggle('is-past', idx <= playHead && idx !== shownIdx)
1006
- seg.classList.toggle('is-active', idx === shownIdx && shownIdx >= 0)
1007
- })
1008
- tlPins.forEach(pin => {
1009
- const pIdx = Number(pin.dataset.tlJump)
1010
- pin.classList.toggle('is-on', pIdx === shownIdx && shownIdx >= 0)
1011
- pin.classList.toggle('is-reached', pIdx <= playHead)
1012
- })
1033
+ if (cells) {
1034
+ for (let i = 0; i < cells.length; i++) {
1035
+ cells[i].classList.toggle('is-past', i > 0 && i < stepNumber)
1036
+ cells[i].classList.toggle('is-active', i === stepNumber)
1037
+ }
1038
+ }
1039
+ if (tlRange?.matches(':focus-visible')) renderTimelineHover(playHead)
1040
+ for (const pin of tlPins) pin.classList.toggle('is-on', Number(pin.dataset.tlJump) === playHead)
1013
1041
 
1014
1042
  let latestVisibleEntry
1015
1043
  for (const item of stepEntries) {
1016
1044
  const future = item.stepIndex > playHead
1017
1045
  item.entry.classList.toggle('is-future', future)
1018
- const isInspectSelected = !future && userClickedInspect && item.stepIndex === selectedIdx
1019
- item.entry.classList.toggle('is-selected', isInspectSelected)
1020
-
1021
- let tag = item.entry.querySelector('.session-inspect-tag')
1022
- if (isInspectSelected) {
1023
- if (!tag) {
1024
- tag = document.createElement('span')
1025
- tag.className = 'session-inspect-tag'
1026
- item.entry.prepend(tag)
1027
- }
1028
- const stTime = steps[selectedIdx]?.t || 0
1029
- tag.textContent = t.lang === 'en'
1030
- ? `Snapshot #${selectedIdx + 1} · ${elapsedClock(stTime)}`
1031
- : `快照 #${selectedIdx + 1} · ${elapsedClock(stTime)}`
1032
- } else if (tag) {
1033
- tag.remove()
1034
- }
1035
-
1036
1046
  if (!future) latestVisibleEntry = item.entry
1037
1047
  }
1038
1048
  for (const aux of auxEntries) {
1049
+ if (aux.forStep > playHead && aux.entry.matches('.session-files:not(.is-future)')) {
1050
+ aux.entry.querySelectorAll('video').forEach(video => video.pause())
1051
+ }
1039
1052
  aux.entry.classList.toggle('is-future', aux.forStep > playHead)
1040
1053
  }
1041
1054
 
@@ -1063,8 +1076,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1063
1076
  activate()
1064
1077
  if (shouldScroll) camera.resumeFollow()
1065
1078
  playHead = Math.max(-1, Math.min(steps.length - 1, nextIdx))
1066
- selectedIdx = playHead
1067
- userClickedInspect = false
1068
1079
  openCat = playHead < 0 ? null : (steps[playHead]?.primaryCat || null)
1069
1080
  follow = shouldScroll
1070
1081
  animatedHead = -2
@@ -1088,7 +1099,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1088
1099
  const nextDraft = next?.kind === 'prompt' ? rawPromptTextOf(next.index) : ''
1089
1100
  if (nextDraft) setComposerVisual('draft', nextDraft)
1090
1101
  else setComposerVisual('idle')
1091
- updateProgressHairline()
1092
1102
  return
1093
1103
  }
1094
1104
  activate()
@@ -1097,19 +1107,11 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1097
1107
  clearStepAnimations()
1098
1108
  playHead = -1
1099
1109
  prevRenderedHead = -1
1100
- selectedIdx = -1
1101
- userClickedInspect = false
1102
1110
  openCat = null
1103
1111
  follow = true
1104
1112
  animatedHead = -1
1105
1113
  render()
1106
1114
  }
1107
- if (selectedIdx < playHead) {
1108
- selectedIdx = playHead
1109
- userClickedInspect = false
1110
- openCat = steps[playHead]?.primaryCat || null
1111
- render()
1112
- }
1113
1115
  if (!stepBusy) {
1114
1116
  if (playHead < 0) {
1115
1117
  const firstDraft = steps[0]?.kind === 'prompt' ? rawPromptTextOf(0) : ''
@@ -1163,8 +1165,8 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1163
1165
  })
1164
1166
 
1165
1167
  const onKeyDown = event => {
1166
- if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return
1167
- if (event.target.closest('input, textarea, select, a, audio, video, summary, [contenteditable]')) return
1168
+ if (lightbox?.open || event.target.closest('dialog[open]') || event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return
1169
+ if (event.target.closest('input, textarea, select, a, audio, video, .session-video-formats, summary, [contenteditable]')) return
1168
1170
  if (event.key === ' ' && event.target.closest('button')) return
1169
1171
  if (event.key === 'ArrowLeft') {
1170
1172
  setPlaying(false)
@@ -1179,9 +1181,8 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1179
1181
  }
1180
1182
  event.preventDefault()
1181
1183
  }
1182
- if (typeof document !== 'undefined') {
1183
- document.addEventListener('keydown', onKeyDown)
1184
- }
1184
+ if (!appEl.hasAttribute('tabindex')) appEl.tabIndex = -1
1185
+ appEl.addEventListener('keydown', onKeyDown)
1185
1186
 
1186
1187
  if (scrubber) {
1187
1188
  const fromPointer = event => {
@@ -1211,9 +1212,8 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
1211
1212
  destroy() {
1212
1213
  clearStepAnimations()
1213
1214
  camera.stop()
1214
- if (typeof document !== 'undefined') {
1215
- document.removeEventListener('keydown', onKeyDown)
1216
- }
1215
+ labelObserver?.disconnect()
1216
+ appEl.removeEventListener('keydown', onKeyDown)
1217
1217
  },
1218
1218
  goToStage,
1219
1219
  setPlaying,
@@ -1240,6 +1240,10 @@ export async function createEncorePlayer(targetEl, sourceOrSession, options = {}
1240
1240
  const appNode = el.querySelector('.session-app')
1241
1241
  const activeLang = resolveLang(options.lang || el.dataset.lang || appNode?.dataset.encoreLang || 'zh')
1242
1242
  const playerData = JSON.parse(preRenderedData.textContent)
1243
+ const footer = el.querySelector('[data-session-timeline]')
1244
+ if (footer && !footer.querySelector('.session-tl-cells')) {
1245
+ footer.outerHTML = renderTimelineBar(playerData, createTranslator(activeLang))
1246
+ }
1243
1247
  const activeController = attachPlayerController(el, playerData, {
1244
1248
  lang: activeLang,
1245
1249
  initialStep: options.initialStep ?? -1,
@@ -1282,7 +1286,7 @@ export async function createEncorePlayer(targetEl, sourceOrSession, options = {}
1282
1286
  if (activeController) activeController.destroy()
1283
1287
  activeLang = resolveLang(lang)
1284
1288
  const line = timeline(session, { lang: activeLang })
1285
- el.innerHTML = renderPlayerWidget(session, line, { lang: activeLang, baseUrl })
1289
+ el.innerHTML = renderPlayerWidget(session, line, { ...options, lang: activeLang, baseUrl })
1286
1290
  if (session.title && document.querySelectorAll('[data-encore-player]').length <= 1) {
1287
1291
  document.title = `${session.title} · Encore`
1288
1292
  }
@@ -1309,7 +1313,19 @@ export async function autoMountEncorePlayers() {
1309
1313
  if (node.dataset.encoreMounted) continue
1310
1314
  node.dataset.encoreMounted = '1'
1311
1315
  try {
1312
- await createEncorePlayer(node)
1316
+ const player = await createEncorePlayer(node)
1317
+ const showLinkedDelivery = () => {
1318
+ const match = /^#delivery-(\d+)$/.exec(location.hash)
1319
+ const files = match ? node.querySelector(`[data-delivery="${match[1]}"]`)
1320
+ : location.hash === '#deliverables' && [...node.querySelectorAll('[data-delivery]')].at(-1)
1321
+ if (!files) return
1322
+ const controller = player.getController()
1323
+ controller.setPlaying(false)
1324
+ controller.goToStage(Number(files.dataset.forStep), false)
1325
+ files.scrollIntoView({ block: 'start' })
1326
+ }
1327
+ showLinkedDelivery()
1328
+ window.addEventListener('hashchange', showLinkedDelivery)
1313
1329
  } catch (err) {
1314
1330
  node.innerHTML = `<div class="encore-load-error">Failed to load session replay: ${escapeHtml(err.message || String(err))}</div>`
1315
1331
  }