@niracler/encore 0.3.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.
- package/README.md +41 -109
- package/README.zh-CN.md +41 -109
- package/bin/encore.mjs +9 -100
- package/package.json +2 -2
- package/player/encore-player.css +42 -43
- package/player/encore-player.js +145 -201
- package/schema/session.schema.json +1 -1
- package/skills/encore/SKILL.md +2 -2
- package/src/antigravity.mjs +162 -0
- package/src/common.mjs +5 -2
- package/src/detect.mjs +96 -51
- package/src/external-files.mjs +22 -5
- package/src/i18n.mjs +1 -3
- package/src/index.d.ts +5 -2
- package/src/index.mjs +17 -6
- package/src/player-runtime.mjs +95 -121
- package/src/render.mjs +35 -70
- package/src/session-picker.mjs +162 -0
- package/src/timeline.mjs +12 -5
package/src/player-runtime.mjs
CHANGED
|
@@ -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, 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
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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,8 +462,6 @@ 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
|
}
|
|
@@ -588,15 +562,17 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
588
562
|
if (event.target === lightbox) closeLightbox()
|
|
589
563
|
})
|
|
590
564
|
|
|
565
|
+
let hoverStep = null
|
|
591
566
|
function renderTimelineHover(idx) {
|
|
592
|
-
if (!tlPop) return
|
|
567
|
+
if (!tlPop || hoverStep === idx) return
|
|
568
|
+
hoverStep = idx
|
|
593
569
|
if (idx === null || idx < 0 || idx >= steps.length) {
|
|
594
570
|
tlPop.hidden = true
|
|
595
571
|
return
|
|
596
572
|
}
|
|
597
573
|
const s = steps[idx]
|
|
598
574
|
const pct = steps.length > 0 ? Math.min(88, Math.max(12, ((idx + 0.5) / steps.length) * 100)) : 50
|
|
599
|
-
const frame = s.frames?.[0]
|
|
575
|
+
const frame = s.frames?.find(frame => frame.who === 'ai') || s.frames?.[0]
|
|
600
576
|
const doc = s.docs?.[0]
|
|
601
577
|
const ci = s.compactInfo
|
|
602
578
|
const thumbHtml = frame
|
|
@@ -612,50 +588,75 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
612
588
|
? t('tlPromptTitle', { turn: s.turn, summary: shorten(s.summary || '', 20) })
|
|
613
589
|
: shorten(s.summary || t('tlStepFallback'), 24)
|
|
614
590
|
const tokStr = `${((s.contextSnapshot?.totalTokens || 0) / 1000).toFixed(1)}k`
|
|
615
|
-
tlPop.style.left =
|
|
591
|
+
tlPop.style.left = `clamp(min(130px, 50%), ${pct.toFixed(1)}%, max(50%, 100% - 130px))`
|
|
616
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>`
|
|
617
593
|
tlPop.hidden = false
|
|
618
594
|
}
|
|
619
595
|
|
|
620
|
-
function
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
|
|
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)
|
|
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' })
|
|
646
610
|
}
|
|
647
611
|
}
|
|
648
612
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
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)))
|
|
647
|
+
})
|
|
648
|
+
tlTrack?.addEventListener('focusin', event => {
|
|
649
|
+
const pin = event.target.closest('[data-tl-jump]')
|
|
650
|
+
renderTimelineHover(pin ? Number(pin.dataset.tlJump) : playHead)
|
|
652
651
|
})
|
|
653
|
-
tlTrack?.addEventListener('
|
|
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))
|
|
654
657
|
tlTrack?.addEventListener('click', event => {
|
|
655
|
-
const
|
|
656
|
-
if (
|
|
657
|
-
const idx = Number(el.dataset.tlJump ?? el.dataset.tlStep)
|
|
658
|
-
if (Number.isFinite(idx)) jumpViaTimeline(idx)
|
|
658
|
+
const pin = event.target.closest('[data-tl-jump]')
|
|
659
|
+
if (pin) seekFromTimeline(Number(pin.dataset.tlJump))
|
|
659
660
|
})
|
|
660
661
|
|
|
661
662
|
asidePane?.addEventListener('click', event => {
|
|
@@ -685,7 +686,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
685
686
|
if (chipOrSeg) {
|
|
686
687
|
const catId = chipOrSeg.dataset.catKey
|
|
687
688
|
openCat = openCat === catId ? null : catId
|
|
688
|
-
renderContextSidebar(
|
|
689
|
+
renderContextSidebar(stateForIndex(playHead))
|
|
689
690
|
asidePane.querySelector(`[data-browser-cat="${catId}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
|
|
690
691
|
return
|
|
691
692
|
}
|
|
@@ -693,7 +694,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
693
694
|
if (catBtn && !catBtn.disabled) {
|
|
694
695
|
const catId = catBtn.dataset.browserCatToggle
|
|
695
696
|
openCat = openCat === catId ? null : catId
|
|
696
|
-
renderContextSidebar(
|
|
697
|
+
renderContextSidebar(stateForIndex(playHead))
|
|
697
698
|
return
|
|
698
699
|
}
|
|
699
700
|
const itemBtn = event.target.closest('[data-browser-item-toggle]')
|
|
@@ -701,7 +702,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
701
702
|
const itemId = itemBtn.dataset.browserItemToggle
|
|
702
703
|
if (openItems.has(itemId)) openItems.delete(itemId)
|
|
703
704
|
else openItems.add(itemId)
|
|
704
|
-
renderContextSidebar(
|
|
705
|
+
renderContextSidebar(stateForIndex(playHead))
|
|
705
706
|
}
|
|
706
707
|
})
|
|
707
708
|
|
|
@@ -930,7 +931,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
930
931
|
}
|
|
931
932
|
|
|
932
933
|
function runHeadChoreography(headState, headEntry, animateNewStep, steppedForwardOne) {
|
|
933
|
-
updateProgressHairline()
|
|
934
934
|
if (!animateNewStep) return
|
|
935
935
|
clearStepAnimations()
|
|
936
936
|
|
|
@@ -974,7 +974,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
974
974
|
if (headState.kind === 'compact') {
|
|
975
975
|
setComposerVisual('running')
|
|
976
976
|
openCat = 'tool'
|
|
977
|
-
renderContextSidebar(
|
|
977
|
+
renderContextSidebar(stateForIndex(playHead))
|
|
978
978
|
if (headEntry && !calm.matches && typeof headEntry.animate === 'function') {
|
|
979
979
|
activeAnims.push(headEntry.animate(
|
|
980
980
|
[
|
|
@@ -1003,7 +1003,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
1003
1003
|
|
|
1004
1004
|
function render() {
|
|
1005
1005
|
const headState = stateForIndex(playHead)
|
|
1006
|
-
const selectedState = currentSelectedState()
|
|
1007
1006
|
curTime = headState.index < 0 ? 0 : headState.t
|
|
1008
1007
|
const x = (playerData.end > 0 ? ((curTime / playerData.end) * width) : 0).toFixed(1)
|
|
1009
1008
|
if (head) {
|
|
@@ -1024,45 +1023,26 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
1024
1023
|
play.setAttribute('aria-label', atEnd ? t('replayAria') : t('playAria'))
|
|
1025
1024
|
}
|
|
1026
1025
|
|
|
1027
|
-
renderContextSidebar(
|
|
1028
|
-
const
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
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) }))
|
|
1033
1032
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
})
|
|
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)
|
|
1043
1041
|
|
|
1044
1042
|
let latestVisibleEntry
|
|
1045
1043
|
for (const item of stepEntries) {
|
|
1046
1044
|
const future = item.stepIndex > playHead
|
|
1047
1045
|
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
1046
|
if (!future) latestVisibleEntry = item.entry
|
|
1067
1047
|
}
|
|
1068
1048
|
for (const aux of auxEntries) {
|
|
@@ -1096,8 +1076,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
1096
1076
|
activate()
|
|
1097
1077
|
if (shouldScroll) camera.resumeFollow()
|
|
1098
1078
|
playHead = Math.max(-1, Math.min(steps.length - 1, nextIdx))
|
|
1099
|
-
selectedIdx = playHead
|
|
1100
|
-
userClickedInspect = false
|
|
1101
1079
|
openCat = playHead < 0 ? null : (steps[playHead]?.primaryCat || null)
|
|
1102
1080
|
follow = shouldScroll
|
|
1103
1081
|
animatedHead = -2
|
|
@@ -1121,7 +1099,6 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
1121
1099
|
const nextDraft = next?.kind === 'prompt' ? rawPromptTextOf(next.index) : ''
|
|
1122
1100
|
if (nextDraft) setComposerVisual('draft', nextDraft)
|
|
1123
1101
|
else setComposerVisual('idle')
|
|
1124
|
-
updateProgressHairline()
|
|
1125
1102
|
return
|
|
1126
1103
|
}
|
|
1127
1104
|
activate()
|
|
@@ -1130,19 +1107,11 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
1130
1107
|
clearStepAnimations()
|
|
1131
1108
|
playHead = -1
|
|
1132
1109
|
prevRenderedHead = -1
|
|
1133
|
-
selectedIdx = -1
|
|
1134
|
-
userClickedInspect = false
|
|
1135
1110
|
openCat = null
|
|
1136
1111
|
follow = true
|
|
1137
1112
|
animatedHead = -1
|
|
1138
1113
|
render()
|
|
1139
1114
|
}
|
|
1140
|
-
if (selectedIdx < playHead) {
|
|
1141
|
-
selectedIdx = playHead
|
|
1142
|
-
userClickedInspect = false
|
|
1143
|
-
openCat = steps[playHead]?.primaryCat || null
|
|
1144
|
-
render()
|
|
1145
|
-
}
|
|
1146
1115
|
if (!stepBusy) {
|
|
1147
1116
|
if (playHead < 0) {
|
|
1148
1117
|
const firstDraft = steps[0]?.kind === 'prompt' ? rawPromptTextOf(0) : ''
|
|
@@ -1243,6 +1212,7 @@ export function attachPlayerController(containerEl, playerData, { lang = 'zh', i
|
|
|
1243
1212
|
destroy() {
|
|
1244
1213
|
clearStepAnimations()
|
|
1245
1214
|
camera.stop()
|
|
1215
|
+
labelObserver?.disconnect()
|
|
1246
1216
|
appEl.removeEventListener('keydown', onKeyDown)
|
|
1247
1217
|
},
|
|
1248
1218
|
goToStage,
|
|
@@ -1270,6 +1240,10 @@ export async function createEncorePlayer(targetEl, sourceOrSession, options = {}
|
|
|
1270
1240
|
const appNode = el.querySelector('.session-app')
|
|
1271
1241
|
const activeLang = resolveLang(options.lang || el.dataset.lang || appNode?.dataset.encoreLang || 'zh')
|
|
1272
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
|
+
}
|
|
1273
1247
|
const activeController = attachPlayerController(el, playerData, {
|
|
1274
1248
|
lang: activeLang,
|
|
1275
1249
|
initialStep: options.initialStep ?? -1,
|
|
@@ -1312,7 +1286,7 @@ export async function createEncorePlayer(targetEl, sourceOrSession, options = {}
|
|
|
1312
1286
|
if (activeController) activeController.destroy()
|
|
1313
1287
|
activeLang = resolveLang(lang)
|
|
1314
1288
|
const line = timeline(session, { lang: activeLang })
|
|
1315
|
-
el.innerHTML = renderPlayerWidget(session, line, { lang: activeLang, baseUrl
|
|
1289
|
+
el.innerHTML = renderPlayerWidget(session, line, { ...options, lang: activeLang, baseUrl })
|
|
1316
1290
|
if (session.title && document.querySelectorAll('[data-encore-player]').length <= 1) {
|
|
1317
1291
|
document.title = `${session.title} · Encore`
|
|
1318
1292
|
}
|
package/src/render.mjs
CHANGED
|
@@ -6,6 +6,9 @@ import { binSeconds, describeStats, minutes, sumStats, timeline } from './timeli
|
|
|
6
6
|
const toolLabels = {
|
|
7
7
|
codex: 'Codex',
|
|
8
8
|
workbuddy: 'WorkBuddy',
|
|
9
|
+
antigravity: 'Antigravity',
|
|
10
|
+
'antigravity-app': 'Antigravity App',
|
|
11
|
+
'antigravity-cli': 'Antigravity CLI',
|
|
9
12
|
'claude-code': 'Claude Code',
|
|
10
13
|
'claude-ai': 'Claude',
|
|
11
14
|
}
|
|
@@ -84,7 +87,7 @@ function thumbs(names, baseUrl = '') {
|
|
|
84
87
|
if (!names?.length) return ''
|
|
85
88
|
return `<span class="session-thumbs">${names.map(name => {
|
|
86
89
|
const url = escape(resolveAsset(name, baseUrl))
|
|
87
|
-
return `<a href="${url}" target="_blank" rel="noopener noreferrer"><img src="${url}" alt="" width="96" loading="lazy"></a>`
|
|
90
|
+
return `<a href="${url}" data-lightbox-src="${url}" target="_blank" rel="noopener noreferrer"><img src="${url}" alt="" width="96" loading="lazy"></a>`
|
|
88
91
|
}).join('')}</span>`
|
|
89
92
|
}
|
|
90
93
|
|
|
@@ -155,77 +158,37 @@ function renderStepArtifacts(stepMeta, { skipImages = [], renderMd, t, baseUrl =
|
|
|
155
158
|
return `<div class="session-frame-deck" data-frame-deck>${subagentHtml}${mediaRow}</div>`
|
|
156
159
|
}
|
|
157
160
|
|
|
158
|
-
function renderTimelineBar(line, t) {
|
|
161
|
+
export function renderTimelineBar(line, t) {
|
|
159
162
|
const steps = line.steps || []
|
|
160
163
|
const total = steps.length
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
} else if (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const canShowText = pct => pct >= 5 && pct <= 95 && occupiedPcts.every(p => Math.abs(p - pct) >= 11)
|
|
185
|
-
for (const pin of rawPins) {
|
|
186
|
-
if (pin.pinType === 'compress' && canShowText(pin.pct)) {
|
|
187
|
-
pin.showText = true
|
|
188
|
-
occupiedPcts.push(pin.pct)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
for (const pin of rawPins) {
|
|
192
|
-
if (pin.pinType === 'frame' && canShowText(pin.pct)) {
|
|
193
|
-
pin.showText = true
|
|
194
|
-
occupiedPcts.push(pin.pct)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
for (const pin of rawPins) {
|
|
198
|
-
if (pin.pinType === 'doc' && canShowText(pin.pct)) {
|
|
199
|
-
pin.showText = true
|
|
200
|
-
occupiedPcts.push(pin.pct)
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (rawPins.length <= 14) {
|
|
204
|
-
for (const pin of rawPins) {
|
|
205
|
-
if (pin.pinType === 'turn' && canShowText(pin.pct)) {
|
|
206
|
-
pin.showText = true
|
|
207
|
-
occupiedPcts.push(pin.pct)
|
|
208
|
-
}
|
|
164
|
+
const pins = []
|
|
165
|
+
const cells = ['<span class="session-tl-cell"></span>']
|
|
166
|
+
for (const [idx, step] of steps.entries()) {
|
|
167
|
+
const frame = step.frames?.find(frame => frame.who === 'ai') || step.frames?.[0]
|
|
168
|
+
const doc = step.docs?.[0]
|
|
169
|
+
let kind = ''
|
|
170
|
+
let label = ''
|
|
171
|
+
let icon = ''
|
|
172
|
+
if (step.compactInfo) {
|
|
173
|
+
kind = 'compress'
|
|
174
|
+
label = t('tlCompressPin', { seq: step.compactInfo.seq })
|
|
175
|
+
icon = '🗜'
|
|
176
|
+
} else if (frame) {
|
|
177
|
+
kind = 'frame'
|
|
178
|
+
label = frame.label
|
|
179
|
+
icon = '🖼'
|
|
180
|
+
} else if (doc) {
|
|
181
|
+
kind = 'doc'
|
|
182
|
+
label = doc.title
|
|
183
|
+
icon = '📄'
|
|
184
|
+
} else if (step.kind === 'prompt') {
|
|
185
|
+
kind = 'turn'
|
|
186
|
+
label = t('tlPromptTitle', { turn: step.turn, summary: short(step.summary || '', 40) })
|
|
209
187
|
}
|
|
188
|
+
cells.push(`<span class="session-tl-cell ${kind}"></span>`)
|
|
189
|
+
if (label) pins.push(`<button type="button" class="session-tl-pin" data-kind="${kind}" data-tl-jump="${idx}" aria-label="${escape(t('tlJumpAria', { step: idx + 1, label }))}"><span aria-hidden="true">${icon}</span><span class="session-tl-caption">${escape(label)}</span></button>`)
|
|
210
190
|
}
|
|
211
191
|
|
|
212
|
-
const pinsHtml = rawPins.map(pin => {
|
|
213
|
-
const text = pin.pinType === 'compress'
|
|
214
|
-
? (pin.showText ? `🗜 ${escape(short(pin.label, 11))}` : '🗜')
|
|
215
|
-
: pin.pinType === 'frame'
|
|
216
|
-
? (pin.showText ? `🖼 ${escape(short(pin.label, 8))}` : '🖼')
|
|
217
|
-
: pin.pinType === 'doc'
|
|
218
|
-
? (pin.showText ? `📄 ${escape(short(pin.label, 8))}` : '📄')
|
|
219
|
-
: (pin.showText ? `💬 #${pin.turn}` : '')
|
|
220
|
-
const cls = `session-tl-pin is-${pin.pinType}${pin.showText ? ' has-label' : ' is-compact'}`
|
|
221
|
-
return `<button type="button" class="${cls}" style="left:${pin.pct.toFixed(2)}%" data-tl-jump="${pin.idx}" data-tl-hover="${pin.idx}" aria-label="${escape(t('tlJumpAria', { step: pin.idx + 1, label: pin.label }))}">${text}</button>`
|
|
222
|
-
}).join('')
|
|
223
|
-
|
|
224
|
-
const segsHtml = steps.map((s, idx) => (
|
|
225
|
-
`<div class="session-tl-seg${s.compactInfo ? ' has-compress' : s.frames?.length ? ' has-frame' : s.docs?.length ? ' has-doc' : ''}" data-tl-step="${idx}" data-tl-hover="${idx}"></div>`
|
|
226
|
-
)).join('')
|
|
227
|
-
const segGap = total > 360 ? '0px' : total > 160 ? '1px' : '2px'
|
|
228
|
-
|
|
229
192
|
return `<footer class="session-timeline-bar" data-session-timeline aria-label="${escape(t('tlAria'))}">
|
|
230
193
|
<div class="session-transport" role="group" aria-label="${escape(t('tlControlsAria'))}">
|
|
231
194
|
<button type="button" class="session-nav-btn" data-session-prev disabled aria-label="${escape(t('prevStep'))}">◀</button>
|
|
@@ -234,10 +197,12 @@ function renderTimelineBar(line, t) {
|
|
|
234
197
|
<span class="session-speed-badge" data-session-speed><b>0</b> / ${total} · 00:00</span>
|
|
235
198
|
</div>
|
|
236
199
|
<div class="session-tl-track-wrap" data-tl-track>
|
|
237
|
-
<span class="session-composer-progress" data-session-progress aria-hidden="true"></span>
|
|
238
200
|
<div class="session-tl-pop" data-tl-pop hidden></div>
|
|
239
|
-
|
|
240
|
-
<div class="session-tl-
|
|
201
|
+
${pins.length ? `<div class="session-tl-pins">${pins.join('')}</div>` : ''}
|
|
202
|
+
<div class="session-tl-rail" style="--tl-count:${total + 1}">
|
|
203
|
+
<div class="session-tl-cells" aria-hidden="true">${cells.join('')}</div>
|
|
204
|
+
<input class="session-tl-range" data-tl-range type="range" min="0" max="${total}" step="1" value="0" aria-label="${escape(t('tlAria'))}"${total ? '' : ' disabled'}>
|
|
205
|
+
</div>
|
|
241
206
|
</div>
|
|
242
207
|
</footer>`
|
|
243
208
|
}
|