المكوّنات · حلقة تقدّم
حلقة تقدّم
نسبة من هدف، ومحيط الحلقة محسوب من نصف قطرها
12 تصاميم من هذه العائلة
<div class="st str" data-now="184300" data-goal="240000">
<svg viewBox="0 0 44 44" aria-hidden="true">
<circle class="trk" cx="22" cy="22" r="18"></circle>
<circle class="bar" cx="22" cy="22" r="18"></circle>
</svg>
<div class="txt">
<b class="v"></b>
<span class="k" data-ar="من الميزانية" data-en="of budget">من الميزانية</span>
<span class="amt"></span>
</div>
</div>
/* pt-scoped */
/* stats-ring */
.str{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.str .k{font-size:8.5px;color:var(--pt-text-muted);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.str .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);
letter-spacing:-.01em;line-height:1.15}
.str .d{font-size:8px;font-variant-numeric:tabular-nums;white-space:nowrap}
.str .up{color:var(--pt-accent)}
.str .dn{color:var(--pt-color-danger-400)}
/* شخصية: دائرية بالكامل، محتوى متمركز، بلا حدود للحاوية */
.str{flex-direction:row;align-items:center;justify-content:center;gap:14px;
padding:10px;background:var(--pt-bg-inset);border-radius:var(--pt-radius-2xl)}
.str svg{width:62px;height:62px;flex:none;transform:rotate(-90deg)}
[dir=rtl] .str svg{transform:rotate(-90deg) scaleY(-1)}
.str .trk{fill:none;stroke:var(--pt-border-default);stroke-width:4}
.str .bar{fill:none;stroke:var(--pt-accent);stroke-width:4;stroke-linecap:round;
transition:stroke-dashoffset var(--pt-motion-duration-slow) var(--pt-motion-easing-standard)}
.str .txt{display:flex;flex-direction:column;gap:2px;min-width:0}
.str .v{font-size:19px;font-weight:700}
.str .amt{font-size:8.5px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.str');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
function nf(n, dec) {
return Number(n).toLocaleString('en-US',
{ minimumFractionDigits: dec || 0, maximumFractionDigits: dec || 0 });
}
function money(n) {
var ar = document.documentElement.lang !== 'en';
// ق١ب: الرمز يلي الرقم عربيًّا ويسبقه إنجليزيًّا · التثبيت 3.75
return ar ? nf(Math.round(n * 3.75)) + ' ر.س' : '$' + nf(n);
}
function pct(a, b) { return b === 0 ? 0 : ((a - b) / b) * 100; }
function sign(x) { return (x >= 0 ? '+' : '−') + nf(Math.abs(x), 1) + '%'; }
var now = parseFloat(root.dataset.now), goal = parseFloat(root.dataset.goal);
var bar = root.querySelector('.bar');
var r = parseFloat(bar.getAttribute('r'));
// المحيط يُحسب من نصف القطر — الرقم المكتوب يدويًّا يكسر عند أي تغيير مقاس
var C = 2 * Math.PI * r;
var share = Math.max(0, Math.min(1, now / goal));
bar.style.strokeDasharray = C.toFixed(2);
bar.style.strokeDashoffset = C.toFixed(2);
root.querySelector('.v').textContent = nf(share * 100, 1) + '%';
function paintAmount() {
root.querySelector('.amt').textContent = money(now) + ' / ' + money(goal);
}
paintAmount();
requestAnimationFrame(function () {
bar.style.strokeDashoffset = (C * (1 - share)).toFixed(2);
});
}
function mount() {
ac = new AbortController();
var real = window.document;
/* وسيط يمرّر كل شيء إلى المستند الحقيقي، ويعلّق كل مستمع بإشارة
تُقطع عند إعادة التركيب — فلا يبقى مستمع من نسخة ماتت. */
var doc = new Proxy(real, {
get: function (t, k) {
if (k === 'addEventListener') {
return function (type, fn, opts) {
var o = (opts && typeof opts === 'object') ? Object.assign({}, opts)
: { capture: !!opts };
o.signal = ac.signal;
return t.addEventListener(type, fn, o);
};
}
var v = t[k];
return typeof v === 'function' ? v.bind(t) : v;
}
});
function track(fn) {
return function (f, ms) { var id = fn(f, ms); timers.push(id); return id; };
}
run(host, doc, track(window.setTimeout.bind(window)),
track(window.setInterval.bind(window)));
}
function unmount() {
if (ac) ac.abort();
// المعرّفان يتشاركان فضاءً واحدًا في المتصفّح، فالإلغاء المزدوج آمن
timers.forEach(function (id) { window.clearTimeout(id); window.clearInterval(id); });
timers = [];
host.innerHTML = snapshot;
}
mount();
addEventListener('pt-lang', function () { unmount(); mount(); });
})();
# Progress Ring
**Role:** You are an Arabic-first UI designer and front-end engineer. Read the whole
specification before writing a single line, then follow it literally. If two requirements
conflict, favour usability over visual effect.
**Goal:** Progress Ring — A share of a target — the ring’s circumference computed from its radius
**Why this component matters:** Rings are usually faked with a hardcoded stroke-dasharray, which breaks the moment the size changes. Computing the circumference from the radius keeps the fill exact at any dimension.
**Direction:** Genuine RTL — not a mirrored Latin layout. Use logical properties
(`margin-inline-start`, `padding-inline`, `inset-inline-start`, `text-align: start`),
never physical ones (`margin-left`, `left`). The layout must flip with `dir` on its own,
with no duplicated rules.
**Typography:** Cairo for Arabic, IBM Plex Sans for Latin. Arabic line-height must be
`0.18` higher than the Latin equivalent — dots, hamzas and maddas need more vertical room.
Arabic font-size runs `1.06×` the Latin size at the same optical weight.
**Numerals:** Western digits in both languages (`1,234.50`). Only the currency changes:
`ر.س` **after** the number in Arabic, `$` **before** it in English. Jordanian dinar
uses **three** decimal places, not two.
**Colors:** Dark mode — background `#0D142B` · surfaces `#211F54` · borders `#545C91` · text `#918FC2`.
Accent `#ADA9E8` must never exceed 8% of the screen area.
**Language:** Bilingual — every string carries both Arabic and English, and the layout
flips with `dir` automatically.
**States:** `default` · `hover` · `focus` · `active` · `disabled` · `loading` · `error`.
Do not design the resting state alone.
**Accessibility:** Contrast ratio at least `4.5:1`, complete keyboard navigation,
visible focus rings, and honour `prefers-reduced-motion`.
**Output:** Clean HTML and CSS in two separate files. No frameworks, no libraries,
no external dependencies.