// Reads the target value from data-pb-count and animates the
// SVG ring + centre number from 0 to that value over 1.4s.
// Drop this on every page where you render a .pb-count element.
document.querySelectorAll("[data-pb-count]").forEach(function (el) {
var target = Number(el.dataset.pbCount) || 0;
var num = el.querySelector("[data-pb-count-num]");
// Drive the ring's stroke-dashoffset via a CSS custom property
el.style.setProperty("--pb-count-pct", String(target / 100));
requestAnimationFrame(function () {
el.classList.add("is-ready");
});
// Tick the centre number in sync with the 1.4s ring transition
var start = null;
var duration = 1400;
function tick(t) {
if (start === null) start = t;
var p = Math.min(1, (t - start) / duration);
var eased = 1 - Math.pow(1 - p, 3); // ease-out cubic
var v = Math.round(target * eased);
if (num) num.textContent = v;
el.setAttribute("aria-valuenow", String(v));
if (p < 1) requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
});