المكوّنات · عدّاد حيّ
عدّاد حيّ
يتحرّك بين قيمتين بسلاسة، ويحترم تقليل الحركة
12 تصاميم من هذه العائلة
<div class="st stl">
<div class="head">
<span class="dot" aria-hidden="true"></span>
<span class="k" data-ar="متصلون الآن" data-en="Online now">متصلون الآن</span>
</div>
<b class="v" aria-live="polite" aria-atomic="true">0</b>
<div class="acts">
<button class="b" data-step="-5">−5</button>
<button class="b" data-step="5">+5</button>
</div>
</div>
/* pt-scoped */
/* stats-live */
.stl{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.stl .k{font-size:8.5px;color:var(--pt-text-muted);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.stl .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);
letter-spacing:-.01em;line-height:1.15}
.stl .d{font-size:8px;font-variant-numeric:tabular-nums;white-space:nowrap}
.stl .up{color:var(--pt-accent)}
.stl .dn{color:var(--pt-color-danger-400)}
/* شخصية: متمركزة، حاوية بلا حدّ، نبضة حيّة، أزرار كبسولية */
.stl{align-items:center;justify-content:center;gap:7px;padding:10px;
background:color-mix(in srgb,var(--pt-accent) 6%,var(--pt-surface));
border-radius:var(--pt-radius-lg)}
.stl .head{display:flex;align-items:center;gap:6px}
.stl .dot{width:6px;height:6px;border-radius:50%;background:var(--pt-accent);
animation:stlPulse 2s ease-in-out infinite}
@keyframes stlPulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.4;transform:scale(.8)}}
.stl .v{font-size:26px;font-weight:700}
.stl .acts{display:flex;gap:6px}
.stl .b{padding:4px 12px;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:var(--pt-bg-raised);
color:var(--pt-text-secondary);font:inherit;font-size:9.5px;cursor:pointer;
font-variant-numeric:tabular-nums}
.stl .b:hover{border-color:var(--pt-accent);color:var(--pt-accent)}
.stl .b:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
@media(prefers-reduced-motion:reduce){.stl .dot{animation:none}
}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.stl');
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 el = root.querySelector('.v');
var cur = 0, target = 128;
var reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
function ease(t) { return 1 - Math.pow(1 - t, 3); }
function animate(to) {
if (reduce) { cur = to; el.textContent = nf(cur); return; }
var from = cur, t0 = performance.now(), dur = 600;
(function step(now) {
var t = Math.min(1, (now - t0) / dur);
cur = Math.round(from + (to - from) * ease(t));
el.textContent = nf(cur);
if (t < 1) requestAnimationFrame(step);
})(t0);
}
animate(target);
root.querySelectorAll('.b').forEach(function (b) {
b.addEventListener('click', function () {
target = Math.max(0, target + parseInt(b.dataset.step, 10));
animate(target);
});
});
setInterval(function () {
target = Math.max(0, target + (Math.random() > 0.5 ? 1 : -1) * Math.round(Math.random() * 4));
animate(target);
}, 4000);
}
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(); });
})();
# Live Counter
**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:** Live Counter — Animates between values smoothly and honours reduced motion
**Why this component matters:** A counter that jumps is hard to read; one that animates for two seconds is annoying. Ease it over ~600ms, and skip the animation entirely when prefers-reduced-motion is set.
**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.