المكوّنات · رقم مع منحنى
رقم مع منحنى
المنحنى مرسوم من البيانات نفسها، لا صورة ثابتة
12 تصاميم من هذه العائلة
<div class="st stt" data-series="41,38,45,52,49,58,63,61,72,78,74,86">
<div class="top">
<span class="k" data-ar="الطلبات هذا الأسبوع" data-en="Requests this week">الطلبات هذا الأسبوع</span>
<span class="d"></span>
</div>
<b class="v"></b>
<svg class="spark" viewBox="0 0 100 30" preserveAspectRatio="none" aria-hidden="true">
<path class="area" d=""></path><path class="line" d=""></path>
</svg>
<div class="foot"><span class="lo"></span><span class="hi"></span></div>
</div>
/* pt-scoped */
/* stats-trend */
.stt{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.stt .k{font-size:8.5px;color:var(--pt-text-muted);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.stt .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);
letter-spacing:-.01em;line-height:1.15}
.stt .d{font-size:8px;font-variant-numeric:tabular-nums;white-space:nowrap}
.stt .up{color:var(--pt-accent)}
.stt .dn{color:var(--pt-color-danger-400)}
/* شخصية: بطاقة واحدة فسيحة، انحناء كبير، الرقم يقود */
.stt{padding:12px 13px;gap:5px;justify-content:center;
border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-xl);
background:var(--pt-surface)}
.stt .top{display:flex;align-items:center;justify-content:space-between;gap:8px}
.stt .v{font-size:22px;font-weight:700}
.stt .spark{width:100%;height:34px;display:block;overflow:visible}
.stt .line{fill:none;stroke:var(--pt-accent);stroke-width:1.6;
stroke-linejoin:round;stroke-linecap:round;vector-effect:non-scaling-stroke}
.stt .area{fill:color-mix(in srgb,var(--pt-accent) 16%,transparent);stroke:none}
.stt .foot{display:flex;justify-content:space-between;font-size:8px;
color:var(--pt-text-muted);font-variant-numeric:tabular-nums}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.stt');
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 s = root.dataset.series.split(',').map(Number);
var lo = Math.min.apply(null, s), hi = Math.max.apply(null, s);
var span = hi - lo || 1;
var pts = s.map(function (n, i) {
return [(i / (s.length - 1)) * 100, 30 - ((n - lo) / span) * 26 - 2];
});
var line = pts.map(function (p, i) {
return (i ? 'L' : 'M') + p[0].toFixed(2) + ' ' + p[1].toFixed(2);
}).join(' ');
root.querySelector('.line').setAttribute('d', line);
root.querySelector('.area').setAttribute('d', line + ' L100 30 L0 30 Z');
root.querySelector('.v').textContent = nf(s[s.length - 1]);
var p = pct(s[s.length - 1], s[0]);
var d = root.querySelector('.d');
d.textContent = sign(p);
d.className = 'd ' + (p >= 0 ? 'up' : 'dn');
root.querySelector('.lo').textContent = nf(lo);
root.querySelector('.hi').textContent = nf(hi);
}
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(); });
})();
# Stat with Sparkline
**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:** Stat with Sparkline — The curve is drawn from the data itself — not a static image
**Why this component matters:** A sparkline pasted as an SVG shape is decoration. Generating the path from the series means the line always tells the truth, and the min/max labels stay correct.
**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.