الكود الكامل (HTML + CSS + JS)
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>مخطط الدونات الجزء إلى الكل — Part-to-Whole Donut Ring</title>
<style>
body { margin: 0; background: #0d0e11; color: #f3f4f6; font-family: system-ui, sans-serif; }
:root { --font-mono: ui-monospace, Menlo, Consolas, monospace; }
#stage { position: relative; width: 100%; height: 220px; box-sizing: border-box; padding: 16px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #090a0d; }
</style>
</head>
<body>
<div id="stage"></div>
<script>
function play(stage) {
const fx = { id: 23, mode: "g_donut" };
const timers = [], rafs = [], anims = [], listeners = [];
const regTimer = (t) => { timers.push(t); return t; };
const regRaf = (r) => { rafs.push(r); return r; };
const regAnim = (a) => { anims.push(a); return a; };
const regListen = (el, ev, fn) => { el.addEventListener(ev, fn); listeners.push([el, ev, fn]); };
const accent = '#ff5e1a', white = '#f3f4f6', muted = '#a1a8b3', surface = '#1e2129';
const svgEl = (tag, attrs = {}) => {
const el = document.createElementNS('http://www.w3.org/2000/svg', tag);
Object.entries(attrs).forEach(([k, v]) => el.setAttribute(k, v));
return el;
};
switch (fx.mode) {
case 'g_donut': {
const svg = svgEl('svg', { viewBox: '0 0 120 120', width: '116', height: '116' });
const c = 2 * Math.PI * 42;
const segs = [{ pct: 0.48, col: accent, off: 0 }, { pct: 0.30, col: white, off: -0.48 * c }, { pct: 0.22, col: '#4b5563', off: -0.78 * c }];
segs.forEach((s, i) => {
const ring = svgEl('circle', { cx: 60, cy: 60, r: 42, fill: 'none', stroke: s.col, 'stroke-width': '14', 'stroke-dasharray': `${s.pct * c} ${c}`, 'stroke-dashoffset': s.off, transform: 'rotate(-90 60 60)' });
svg.appendChild(ring);
regAnim(ring.animate([{ opacity: 0, strokeDasharray: `0 ${c}` }, { opacity: 1, strokeDasharray: `${s.pct * c} ${c}` }], { duration: 750, delay: i * 180, easing: 'cubic-bezier(0.16,1,0.3,1)', fill: 'forwards' }));
});
stage.appendChild(svg);
break;
}
}
return () => {
timers.forEach(clearTimeout);
rafs.forEach(cancelAnimationFrame);
anims.forEach(a => { try { a.cancel(); } catch (_) {} });
listeners.forEach(([el, ev, fn]) => el.removeEventListener(ev, fn));
};
}
const MS = 1900, PAUSE = 1500; // MS = 0: the effect already runs continuously
const host = document.getElementById('stage');
const still = matchMedia('(prefers-reduced-motion: reduce)').matches;
let stop = null, timer = null, shown = false;
function run() { if (stop) stop(); host.innerHTML = ""; stop = play(host); }
function loop() { run(); if (!still && MS) timer = setTimeout(loop, MS + PAUSE); }
new IntersectionObserver(([e]) => {
if (e.isIntersecting && !shown) { shown = true; loop(); }
else if (!e.isIntersecting && shown) { shown = false; clearTimeout(timer); if (stop) stop(); }
}, { threshold: 0.1 }).observe(host);
</script>
</body>
</html>