المكوّنات · إدخال بطاقة بتحقّق لون
إدخال بطاقة بتحقّق لون
الرقم يُفحص بخوارزمية لون، والشبكة تُستنتج من بادئته
12 تصاميم من هذه العائلة
<div class="cm cmp">
<h4 data-ar="بيانات البطاقة" data-en="Card details">بيانات البطاقة</h4>
<label><span data-ar="رقم البطاقة" data-en="Card number">رقم البطاقة</span>
<span class="fld"><input class="no" inputmode="numeric" placeholder="0000 0000 0000 0000" dir="ltr">
<b class="net"></b></span>
<em class="err"></em></label>
<div class="row">
<label><span data-ar="الانتهاء" data-en="Expiry">الانتهاء</span>
<input class="ex" inputmode="numeric" placeholder="MM/YY" dir="ltr" maxlength="5">
<em class="err"></em></label>
<label><span data-ar="الرمز" data-en="CVC">الرمز</span>
<input class="cv" inputmode="numeric" placeholder="123" dir="ltr" maxlength="4">
<em class="err"></em></label>
</div>
<button class="pay" disabled data-ar="ادفع" data-en="Pay">ادفع</button>
<p class="safe" data-ar="لا نخزّن رقم بطاقتك — يمرّ مشفَّرًا إلى بوّابة الدفع." data-en="We never store your card — it passes encrypted to the payment gateway.">لا نخزّن رقم بطاقتك — يمرّ مشفَّرًا إلى بوّابة الدفع.</p>
</div>
/* pt-scoped */
/* commerce-payment — متجر إلكترونيات */
.cmp{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.cmp h4{margin:0;font-size:10.5px;color:var(--pt-text-primary);font-weight:600}
.cmp p{margin:0;font-size:8.5px;color:var(--pt-text-muted);line-height:1.75}
.cmp .num{font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.cmp button{font:inherit;cursor:pointer}
.cmp button:disabled{cursor:not-allowed;opacity:.45}
.cmp button:focus-visible, .cmp input:focus-visible, .cmp select:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.cmp .bar{height:3px;border-radius:99px;background:var(--pt-border-subtle);overflow:hidden}
.cmp .bar i{display:block;height:100%;background:var(--pt-accent);border-radius:inherit;
transition:width var(--pt-motion-duration-normal) var(--pt-motion-easing-standard)}
@media(prefers-reduced-motion:reduce){.cmp .bar i{transition:none}
}
@media(pointer:coarse){.cmp button{min-height:44px}
}
/* شخصية: نموذج بنكي، انحناء صغير، شارة شبكة داخل الحقل */
.cmp{gap:6px;padding:11px 12px;justify-content:center}
.cmp label{display:flex;flex-direction:column;gap:2px}
.cmp label > span{font-size:8px;color:var(--pt-text-muted)}
.cmp .row{display:grid;grid-template-columns:1fr 1fr;gap:6px}
.cmp .fld{display:flex;align-items:center;gap:5px;padding:0 8px;
border-radius:var(--pt-radius-xs);border:1px solid var(--pt-border-default);
background:var(--pt-bg-inset)}
.cmp .fld:focus-within{border-color:var(--pt-accent)}
.cmp input{width:100%;border:0;background:var(--pt-bg-inset);padding:6px 8px;
border-radius:var(--pt-radius-xs);border:1px solid var(--pt-border-default);
font:inherit;font-size:9.5px;color:var(--pt-text-primary);outline:none;
font-variant-numeric:tabular-nums;letter-spacing:.06em}
.cmp .fld input{border:0;background:transparent;padding:6px 0}
.cmp input[aria-invalid=true]{border-color:var(--pt-color-danger-400)}
.cmp .fld:has(input[aria-invalid=true]){border-color:var(--pt-color-danger-400)}
.cmp .net{font-size:8px;color:var(--pt-accent);white-space:nowrap;font-weight:700}
.cmp .err{font-style:normal;font-size:7.5px;color:var(--pt-color-danger-400);min-height:9px}
.cmp .pay{padding:7px;border-radius:var(--pt-radius-xs);border:0;background:var(--pt-accent);
color:var(--pt-color-ink-900);font-size:9.5px;font-weight:700}
.cmp .safe{font-size:7.5px;text-align:center}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.cmp');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
var ar = document.documentElement.lang !== 'en';
var n = function (v, d) { return Number(v).toLocaleString('en-US', {
minimumFractionDigits: d === undefined ? 2 : d,
maximumFractionDigits: d === undefined ? 2 : d }); };
/* العملة: ر.ع (OMR) — سوق عُمان.
الأرقام مخزَّنة بـالريال وتُحوَّل، فتبقى
المبالغ معقولة في كل سوق. والتحويل لا التبديل: «18,500» راتبًا بالريال
معقول، وبالدينار الأردني ثروة.
وثلاث خانات عشرية — الدينار يُقسَّم إلى ألف فلس. */
var money = (function () {
var RATE = 0.3845, DEC = 3;
return function (v, d) {
var out = (Number(v) / 3.75) * RATE;
var places = d === undefined ? DEC : d;
var s = out.toLocaleString('en-US', {
minimumFractionDigits: places, maximumFractionDigits: places });
return ar ? s + ' ر.ع' : 'OMR ' + s;
};
})();
var set = function (sel, t) { var e = root.querySelector(sel); if (e) e.textContent = t; return e; };
var no = root.querySelector('.no'), ex = root.querySelector('.ex'), cv = root.querySelector('.cv');
var pay = root.querySelector('.pay'), net = root.querySelector('.net');
function digits(v) {
return String(v).replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.replace(/\D/g, '');
}
/* لون (Luhn): تُضاعَف كل خانة ثانية من اليمين، ويُطرح 9 ممّا تجاوز 9،
ثمّ يُجمع الكل — والمجموع يقبل القسمة على 10. تلتقط معظم أخطاء الخانة
الواحدة والقلب بين خانتين، فتوفّر على المستخدم رفضًا وعليك رسم بوّابة. */
function luhn(s) {
if (s.length < 13) return false;
var sum = 0, alt = false;
for (var i = s.length - 1; i >= 0; i--) {
var d = +s[i];
if (alt) { d *= 2; if (d > 9) d -= 9; }
sum += d; alt = !alt;
}
return sum % 10 === 0;
}
var NETS = [
{ re: /^4/, ar: 'فيزا', en: 'Visa', len: 16 },
{ re: /^5[1-5]|^2[2-7]/, ar: 'ماستركارد', en: 'Mastercard', len: 16 },
{ re: /^3[47]/, ar: 'أمريكان', en: 'Amex', len: 15 },
{ re: /^9/, ar: 'مدى', en: 'mada', len: 16 }
];
function detect(s) {
for (var i = 0; i < NETS.length; i++) if (NETS[i].re.test(s)) return NETS[i];
return null;
}
function err(el, msg) {
var e = el.closest('label').querySelector('.err');
el.setAttribute('aria-invalid', String(!!msg));
e.textContent = msg || '';
}
function okExpiry(v) {
var m = v.match(/^(\d{2})\/(\d{2})$/);
if (!m) return false;
var mm = +m[1], yy = 2000 + (+m[2]);
if (mm < 1 || mm > 12) return false;
var now = new Date();
/* الشهر نفسه صالح حتى آخره — والمقارنة بآخر يوم لا بأوّله */
return new Date(yy, mm, 0) >= new Date(now.getFullYear(), now.getMonth(), 1);
}
function refresh() {
var s = digits(no.value);
var nw = detect(s);
net.textContent = nw ? (ar ? nw.ar : nw.en) : '';
var numOk = luhn(s) && (!nw || s.length === nw.len);
var cvcLen = nw && nw.en === 'Amex' ? 4 : 3;
var exOk = okExpiry(ex.value), cvOk = digits(cv.value).length === cvcLen;
if (s.length >= 13) err(no, numOk ? '' : (ar ? 'رقم البطاقة غير صحيح' : 'Invalid card number'));
else err(no, '');
if (ex.value.length >= 5) err(ex, exOk ? '' : (ar ? 'تاريخ منتهٍ أو خاطئ' : 'Expired or invalid'));
else err(ex, '');
if (cv.value.length >= cvcLen) err(cv, cvOk ? '' : (ar ? cvcLen + ' أرقام' : cvcLen + ' digits'));
else err(cv, '');
pay.disabled = !(numOk && exOk && cvOk);
}
no.addEventListener('input', function () {
var s = digits(no.value).slice(0, 16);
var nw = detect(s);
/* أمريكان إكسبرس 4-6-5 لا 4-4-4-4 — التجميع الخطأ يربك المستخدم */
no.value = nw && nw.en === 'Amex'
? s.replace(/(.{4})(.{0,6})(.{0,5})/, function (_, a, b, c) {
return [a, b, c].filter(Boolean).join(' '); })
: s.replace(/(.{4})/g, '$1 ').trim();
refresh();
});
ex.addEventListener('input', function () {
var s = digits(ex.value).slice(0, 4);
ex.value = s.length > 2 ? s.slice(0, 2) + '/' + s.slice(2) : s;
refresh();
});
cv.addEventListener('input', function () { cv.value = digits(cv.value).slice(0, 4); refresh(); });
pay.addEventListener('click', function () {
pay.disabled = true;
pay.textContent = ar ? '✓ تمّ الدفع' : '✓ Paid';
});
no.value = '4242 4242 4242 4242';
ex.value = '12/28'; cv.value = '123';
refresh();
}
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(); });
})();
# Card Input with Luhn Check
**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:** Card Input with Luhn Check — Validated with the Luhn algorithm; the network is inferred from its prefix
**Why this component matters:** Run the Luhn checksum before submitting: it catches most single-digit typos and transpositions locally, sparing the user a declined transaction and you a gateway fee.
**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.