المكوّنات · عدّاد تنازلي بفرق زمني
عدّاد تنازلي بفرق زمني
يحسب الفرق من التاريخ الفعلي، فلا ينحرف مع الوقت
12 تصاميم من هذه العائلة
<div class="gg ggcd" data-target="2026-12-01T18:00:00+03:00">
<span class="k" data-ar="ملتقى الرياض للتقنية" data-en="Riyadh Tech Forum">ملتقى الرياض للتقنية</span>
<div class="units">
<span class="u"><b data-u="d">0</b><i data-ar="يوم" data-en="days">يوم</i></span>
<span class="u"><b data-u="h">0</b><i data-ar="ساعة" data-en="hrs">ساعة</i></span>
<span class="u"><b data-u="m">0</b><i data-ar="دقيقة" data-en="min">دقيقة</i></span>
<span class="u"><b data-u="s">0</b><i data-ar="ثانية" data-en="sec">ثانية</i></span>
</div>
<span class="when"></span>
<span class="live" aria-live="polite"></span>
</div>
/* pt-scoped */
/* gauge-countdown — تنظيم فعاليات */
.ggcd{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.ggcd .k{font-size:8.5px;color:var(--pt-text-muted)}
.ggcd .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);line-height:1.15}
.ggcd .up{color:var(--pt-accent)}
.ggcd .dn{color:var(--pt-color-danger-400)}
/* شخصية: أربع خانات كبسولية، أرقام كبيرة، حاوية بتدرّج خفيف */
.ggcd{padding:10px;gap:6px;align-items:center;justify-content:center;
border-radius:var(--pt-radius-xl);
background:linear-gradient(180deg,
color-mix(in srgb,var(--pt-accent) 7%,var(--pt-surface)),var(--pt-surface))}
.ggcd .units{display:flex;gap:5px}
.ggcd .u{display:flex;flex-direction:column;align-items:center;gap:2px;
min-width:38px;padding:6px 4px;border-radius:var(--pt-radius-lg);
background:var(--pt-bg-inset);border:1px solid var(--pt-border-subtle)}
.ggcd .u b{font-size:16px;font-weight:700;font-variant-numeric:tabular-nums;
color:var(--pt-text-primary);line-height:1}
.ggcd .u i{font-style:normal;font-size:7.5px;color:var(--pt-text-muted)}
.ggcd .when{font-size:8.5px;color:var(--pt-text-muted)}
.ggcd .live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.ggcd');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
function nf(x, d) {
return Number(x).toLocaleString('en-US',
{ minimumFractionDigits: d || 0, maximumFractionDigits: d || 0 });
}
function money(x) {
var ar = document.documentElement.lang !== 'en';
return ar ? nf(Math.round(x * 3.75)) + ' ر.س' : '$' + nf(x);
}
var target = new Date(root.dataset.target).getTime();
var out = {};
['d', 'h', 'm', 's'].forEach(function (u) { out[u] = root.querySelector('[data-u=' + u + ']'); });
var live = root.querySelector('.live');
root.querySelector('.when').textContent =
new Date(target).toLocaleDateString('ar-SA-u-nu-latn',
{ year: 'numeric', month: 'long', day: 'numeric' });
var lastDay = null;
function tick() {
// الفرق يُعاد حسابه من التاريخ في كل نبضة — الطرح المتتابع ينحرف
// لأن setInterval غير دقيق، ولأن اللسان المخفيّ يُبطّئه
var left = Math.max(0, target - Date.now());
var d = Math.floor(left / 864e5);
var h = Math.floor(left / 36e5) % 24;
var m = Math.floor(left / 6e4) % 60;
var s = Math.floor(left / 1e3) % 60;
out.d.textContent = nf(d); out.h.textContent = nf(h);
out.m.textContent = nf(m); out.s.textContent = nf(s);
if (d !== lastDay) { lastDay = d; live.textContent = 'بقي ' + d + ' يومًا'; }
}
tick();
setInterval(tick, 1000);
}
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(); });
})();
# Countdown from a Real Interval
**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:** Countdown from a Real Interval — Computes the gap from a real date, so it never drifts
**Why this component matters:** Counting down by subtracting one each second drifts: setInterval is not exact and a backgrounded tab throttles it. Recomputing the difference from the target date every tick is always right.
**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.