Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

Site: star counts show the current total and no longer animate

Eric Brownroutfe2a22a5b81a
diff --git a/site/public/marketing/activity.mjs b/site/public/marketing/activity.mjs
index 1e39a084..9aa69325 100644
--- a/site/public/marketing/activity.mjs
+++ b/site/public/marketing/activity.mjs
@@ -3,147 +3,62 @@ import { refreshSummary, hour, navStars } from './stars-data.mjs'
const section = document.querySelector('#progress'),
number = section.querySelector('.stat-value'),
clip = section.querySelector('.chart-clip'),
- chart = section.querySelector('.star-chart'),
- points = Array.from(section.querySelector('.chart-line').points),
- reduce = matchMedia('(prefers-reduced-motion: reduce)'),
- nav = document.querySelector('.nav-stars')
+ reduce = matchMedia('(prefers-reduced-motion: reduce)')
let total = Number(number.textContent.replaceAll(',', ''))
const format = new Intl.NumberFormat('en')
-number.setAttribute('aria-hidden', 'true')
-number.parentElement.setAttribute('aria-label', `${format.format(total)} GitHub stars`)
-const tailGaps = [3000, 8000, 15000, 24000, 35000, 48000]
-let tailSize = Math.min(tailGaps.length, total),
- base = total - tailSize
let started = false,
visible = false,
finished = reduce.matches,
clock = null,
- raf = 0,
- tailStage = false,
- tailValue = base,
- tailTimer = 0,
- tailRemaining = tailGaps[0],
- tailMark = 0
-// The nav shows the same count as the tile: the starting count until the tile has played, then each later star with it.
-const showNav = count => { nav.querySelector('span').textContent = navStars(count) }
-if (!finished) showNav(base)
-// Interpolate the same straight segment that is visible at the clipping edge.
-function heightAt(progress) {
- if (progress === 0 || progress === 1 || points.length < 2) return progress
- const { width, height } = chart.viewBox.baseVal
- const x = width * progress
- let left = 0, right = points.length - 1
- while (right - left > 1) {
- const middle = (left + right) >>> 1
- if (points[middle].x <= x) left = middle
- else right = middle
- }
- const a = points[left], b = points[right]
- const t = b.x === a.x ? 1 : (x - a.x) / (b.x - a.x)
- const y = a.y + (b.y - a.y) * t
- const lastHeight = height - points.at(-1).y
- return lastHeight > 0 ? Math.min(1, (height - y) / lastHeight) : progress
-}
+ raf = 0
+// The count is always the real total. Only the line draws in.
function paint(progress) {
clip.style.transform = 'scaleX(' + progress + ')'
- updateCount(heightAt(progress))
-}
-function updateCount(progress) {
- number.textContent = format.format(Math.round((finished ? total : base) * progress))
}
function stop() {
cancelAnimationFrame(raf)
raf = 0
clock?.pause()
- if (tailTimer) {
- clearTimeout(tailTimer)
- tailTimer = 0
- tailRemaining = Math.max(0, tailRemaining - (performance.now() - tailMark))
- }
}
-function rest() {
- finished = true
- tailStage = false
+function rest(state) {
+ stop()
clock?.cancel()
clock = null
- updateCount(1)
- showNav(total)
- section.dataset.stars = 'complete'
-}
-function scheduleTail() {
- if (tailTimer || document.hidden || reduce.matches || finished) return
- tailMark = performance.now()
- tailTimer = setTimeout(() => {
- tailTimer = 0
- tailValue = Math.min(total, tailValue + 1)
- tailRemaining = tailGaps[tailValue - base] ?? 0
- number.textContent = format.format(tailValue)
- showNav(tailValue)
- if (tailValue === total) rest()
- else scheduleTail()
- }, tailRemaining)
-}
-function finishCountUp() {
+ finished = true
paint(1)
- clock?.cancel()
- clock = null
- if (!tailSize) {
- rest()
- return
- }
- tailStage = true
- tailValue = base
- section.dataset.stars = 'settling'
- scheduleTail()
+ section.dataset.stars = state
}
function tick() {
- if (reduce.matches) {
+ if (reduce.matches || !visible || document.hidden) {
sync()
return
}
- if (!visible || document.hidden) {
- stop()
- return
- }
const progress = clock.effect.getComputedTiming().progress ?? 0
paint(progress)
if (clock.playState === 'finished' || progress >= 1) {
- raf = 0
- finishCountUp()
+ rest('complete')
return
}
raf = requestAnimationFrame(tick)
}
function sync() {
if (reduce.matches) {
- stop()
- clock?.cancel()
- clock = null
- finished = true
- paint(1)
- showNav(total)
- section.dataset.stars = 'still'
+ rest('still')
return
}
- if (document.hidden || (!visible && !tailStage)) {
+ if (!visible || document.hidden) {
stop()
return
}
- if (!started && !finished) return
- if (finished) return
- if (tailStage) {
- scheduleTail()
- return
- }
+ if (!started || finished) return
if (!clock) {
- // A timing-only effect lets one frame update both the clip and the count.
clock = new Animation(new KeyframeEffect(null, [], {
duration: 1800, easing: 'cubic-bezier(.30,.60,.40,1)', fill: 'both',
}), document.timeline)
- clock.play()
paint(0)
- } else clock.play()
+ }
+ clock.play()
section.dataset.stars = 'playing'
if (!raf) raf = requestAnimationFrame(tick)
}
@@ -195,6 +110,7 @@ new IntersectionObserver(([entry])=>{
document.addEventListener('visibilitychange',syncStatusPulse)
reduce.addEventListener('change',syncStatusPulse)
+const nav = document.querySelector('.nav-stars')
const releaseCount = section.querySelector('.oss-calendar .oss-figure')
const releaseLink = section.querySelector('.oss-latest')
const version = releaseLink.querySelector('.release-version strong')
@@ -220,18 +136,12 @@ async function refresh() {
} })
lastSummary = data
if (data.count !== total) {
- const ticks = tailValue - base
total = data.count
- tailSize = Math.min(tailGaps.length, total)
- base = total - tailSize
- tailValue = Math.min(total, base + ticks)
const label = format.format(total)
- showNav(finished ? total : tailStage ? tailValue : base)
+ number.textContent = label
+ nav.querySelector('span').textContent = navStars(total)
nav.setAttribute('aria-label', 'Yogurt on GitHub, ' + label + ' stars')
section.querySelector('.oss-history').setAttribute('aria-label', label + ' GitHub stars. View on GitHub')
- number.parentElement.setAttribute('aria-label', label + ' GitHub stars')
- if (finished) updateCount(1)
- else if (tailStage) number.textContent = format.format(tailValue)
}
releaseCount.textContent = format.format(data.releases)
version.textContent = data.latest.tag
diff --git a/site/scripts/stars.test.mjs b/site/scripts/stars.test.mjs
index 601ecb92..b04e3961 100644
--- a/site/scripts/stars.test.mjs
+++ b/site/scripts/stars.test.mjs
@@ -134,7 +134,6 @@ function chartPage(reduced = false) {
constructor(effect) { return animation(effect.frames, effect.options) }
},
document: doc,
- navStars: count => count.toLocaleString('en'),
window: { addEventListener() {}, removeEventListener() {} },
innerHeight: 800,
Intl,
@@ -166,7 +165,6 @@ function chartPage(reduced = false) {
})
return {
number,
- nav: () => query('span').textContent,
enter: (ratio = 1) => observe([{ isIntersecting: true, intersectionRatio: ratio }]),
clip: () => query('.chart-clip').style.transform,
fill: () => query('.chart-fill').style.transform,
@@ -185,46 +183,28 @@ function chartPage(reduced = false) {
}
}
const chart = chartPage()
-assert.equal(chart.nav(), '128') // The nav starts on the count the tile will land on.
assert.equal(chart.clip(), 'scaleX(0)')
-assert.equal(chart.number.textContent, '0')
+assert.equal(chart.number.textContent, '134') // The count is the real total from the first paint.
chart.enter(.2)
assert.equal(chart.timing(), undefined)
chart.enter(.55)
assert.equal(chart.timing().options.duration, 1800)
-chart.at(.25)
-assert.equal(chart.clip(), 'scaleX(0.25)')
-assert.equal(chart.number.textContent, '48') // Halfway up the first segment.
chart.at(.5)
assert.equal(chart.clip(), 'scaleX(0.5)')
-assert.equal(chart.number.textContent, '96') // At the measured midpoint, the count is 75% of the total.
-chart.at(.75)
-assert.equal(chart.number.textContent, '112')
+assert.equal(chart.number.textContent, '134')
assert.equal(chart.fill(), undefined)
chart.finishCountUp()
assert.equal(chart.clip(), 'scaleX(1)')
-assert.equal(chart.number.textContent, '128')
-assert.equal(chart.timer().ms, 3000)
-assert.equal(chart.nav(), '128')
-chart.leave() // Later stars keep arriving after the reader scrolls away from the tile.
-assert.equal(chart.timer().ms, 3000)
-for (const [i, delay] of [3000, 8000, 15000, 24000, 35000, 48000].entries()) {
- const t = chart.timer()
- assert.equal(t.ms, delay)
- chart.advance(delay)
- t.fn()
- assert.equal(chart.number.textContent, String(129 + i))
- assert.equal(chart.nav(), chart.number.textContent) // The nav and the tile change together.
-}
+assert.equal(chart.number.textContent, '134')
+assert(!chart.timer()) // Nothing keeps counting after the line has drawn.
assert.equal(chart.state(), 'complete')
const still = chartPage(true)
still.enter()
assert.equal(still.number.textContent, '134')
-assert.equal(still.nav(), '134')
assert(!still.timer())
assert.equal(still.clip(), 'scaleX(1)')
assert.equal(still.timing(), undefined)
-console.log('Shared chart and count timing, linear axes, growing intervals, nav in step with the tile, later stars continuing offscreen and reduced-motion total passed.')
+console.log('Chart line draw, a count that never changes while it draws, and reduced-motion rest passed.')
const template=load('../content/home.html')
const featureSection=template.match(/<section aria-labelledby="features-title"[\s\S]*?<\/section>/)[0]