المكوّنات · تسجيل بقياس قوّة كلمة المرور
تسجيل بقياس قوّة كلمة المرور
القوّة محسوبة من التنوّع والطول معًا، لا من الطول وحده
12 تصاميم من هذه العائلة
<div class="sg sgw">
<h5 data-ar="حساب جديد" data-en="New account">حساب جديد</h5>
<label><span data-ar="البريد الإلكتروني" data-en="Email">البريد الإلكتروني</span>
<input class="em" type="email" placeholder="name@company.com" dir="ltr">
<span class="err"></span></label>
<label><span data-ar="كلمة المرور" data-en="Password">كلمة المرور</span>
<span class="pw-row"><input class="pw" type="password" placeholder="••••••••">
<button class="eye" type="button" aria-label="إظهار كلمة المرور">◉</button></span>
<span class="meter"><i></i></span>
<span class="lvl"></span></label>
<ul class="rules"></ul>
<button class="go" data-ar="إنشاء الحساب" data-en="Create account">إنشاء الحساب</button>
</div>
/* pt-scoped */
/* signup-password — متجر إلكتروني */
.sgw{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.sgw h5{margin:0;font-size:11px;color:var(--pt-text-primary);font-weight:600}
.sgw .sub{margin:0;font-size:8.5px;color:var(--pt-text-muted)}
.sgw label{display:flex;flex-direction:column;gap:3px}
.sgw label > span{font-size:8.5px;color:var(--pt-text-muted)}
.sgw input, .sgw select{width:100%;font:inherit;font-size:9.5px;
color:var(--pt-text-primary);outline:none}
.sgw input::placeholder{color:var(--pt-text-muted)}
.sgw .err{font-size:8px;color:var(--pt-color-danger-400);min-height:0}
.sgw .ok{color:var(--pt-accent)}
.sgw button{font:inherit;cursor:pointer}
.sgw button:focus-visible, .sgw input:focus-visible{outline:2px solid var(--pt-focus-ring);
outline-offset:1px}
/* شخصية: مربّعة الحواف، مقياس شريطي، قائمة شروط تتبدّل */
.sgw{padding:10px;gap:6px;justify-content:center;
border:1px solid var(--pt-border-default);border-radius:var(--pt-radius-sm);
background:var(--pt-bg-base)}
.sgw input{padding:6px 8px;border-radius:var(--pt-radius-xs);
border:1px solid var(--pt-border-default);background:var(--pt-bg-raised)}
.sgw input[aria-invalid=true]{border-color:var(--pt-color-danger-400)}
.sgw .pw-row{display:flex;gap:4px}
.sgw .eye{flex:none;width:26px;border-radius:var(--pt-radius-xs);
border:1px solid var(--pt-border-default);background:var(--pt-bg-raised);
color:var(--pt-text-muted);font-size:10px}
.sgw .eye[aria-pressed=true]{color:var(--pt-accent);border-color:var(--pt-accent)}
.sgw .meter{display:block;height:4px;border-radius:99px;background:var(--pt-border-subtle);
overflow:hidden;margin-top:2px}
.sgw .meter i{display:block;height:100%;width:0;border-radius:inherit;
transition:width var(--pt-motion-duration-normal) var(--pt-motion-easing-standard),
background var(--pt-motion-duration-normal) var(--pt-motion-easing-standard)}
.sgw .lvl{font-size:8px;font-weight:600}
.sgw .rules{list-style:none;margin:0;padding:0;display:grid;
grid-template-columns:1fr 1fr;gap:2px 8px;font-size:8px;color:var(--pt-text-muted)}
.sgw .rules li::before{content:'○ ';color:var(--pt-text-muted)}
.sgw .rules li.on{color:var(--pt-accent)}
.sgw .rules li.on::before{content:'● ';color:var(--pt-accent)}
.sgw .go{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:600}
.sgw .go:disabled{opacity:.45;cursor:not-allowed}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sgw');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
/* الخطأ يظهر بعد مغادرة الحقل لا مع كل حرف: القراءة أثناء الكتابة
تُشعر المستخدم بالفشل قبل أن ينتهي من الإدخال. */
function bind(input, check, msg) {
var box = input.closest('label') || input.parentElement;
var err = box.querySelector('.err') || box.parentElement.querySelector('.err');
var touched = false;
function paint() {
var good = check(input.value);
input.setAttribute('aria-invalid', String(touched && !good));
if (err) err.textContent = touched && !good ? msg : '';
return good;
}
input.addEventListener('blur', function () { touched = true; paint(); });
input.addEventListener('input', function () { if (touched) paint(); });
return paint;
}
var em = root.querySelector('.em'), pw = root.querySelector('.pw');
var eye = root.querySelector('.eye'), bar = root.querySelector('.meter i');
var lvl = root.querySelector('.lvl'), rules = root.querySelector('.rules');
var go = root.querySelector('.go');
var RULES = [
{ t: '8 أحرف فأكثر', f: function (v) { return v.length >= 8; } },
{ t: 'حرف كبير', f: function (v) { return /[A-Z]/.test(v); } },
{ t: 'حرف صغير', f: function (v) { return /[a-z]/.test(v); } },
{ t: 'رقم', f: function (v) { return /\d/.test(v); } },
{ t: 'رمز', f: function (v) { return /[^\w\s]/.test(v); } },
{ t: 'بلا تكرار طويل', f: function (v) { return !/(.)\1{2,}/.test(v); } }
];
rules.innerHTML = RULES.map(function (r) { return '<li>' + r.t + '</li>'; }).join('');
var lis = [].slice.call(rules.children);
/* التنوّع لا الطول: مقياس يعتمد الطول وحده يصف «aaaaaaaaaaaa» بالقويّة.
نجمع الشروط المحقّقة، ونكافئ الطول الزائد بحدّ أقصى لا يتجاوزه. */
function score(v) {
if (!v) return 0;
var met = RULES.filter(function (r) { return r.f(v); }).length;
var lenBonus = Math.min(2, Math.floor((v.length - 8) / 4));
return Math.max(0, Math.min(6, met + (v.length >= 8 ? lenBonus : -2)));
}
var LEVELS = [
{ t: 'ضعيفة جدًّا', c: 'var(--pt-color-danger-500)' },
{ t: 'ضعيفة', c: 'var(--pt-color-danger-400)' },
{ t: 'مقبولة', c: 'var(--pt-color-info-400)' },
{ t: 'جيّدة', c: 'var(--pt-color-info-300)' },
{ t: 'قويّة', c: 'var(--pt-accent)' },
{ t: 'قويّة جدًّا', c: 'var(--pt-accent)' },
{ t: 'ممتازة', c: 'var(--pt-accent)' }
];
function emailOk(v) { return /^[^@\s]+@[^@\s]+\.[a-z]{2,}$/i.test(v); }
bind(em, emailOk, 'صيغة البريد غير صحيحة');
function refresh() {
var s = score(pw.value);
lis.forEach(function (li, i) { li.classList.toggle('on', RULES[i].f(pw.value)); });
bar.style.width = (s / 6 * 100) + '%';
bar.style.background = LEVELS[s].c;
lvl.textContent = pw.value ? LEVELS[s].t : '';
lvl.style.color = LEVELS[s].c;
go.disabled = !(emailOk(em.value) && s >= 4);
}
pw.addEventListener('input', refresh);
em.addEventListener('input', refresh);
eye.addEventListener('click', function () {
var on = pw.type === 'password';
pw.type = on ? 'text' : 'password';
eye.setAttribute('aria-pressed', String(on));
eye.setAttribute('aria-label', on ? 'إخفاء كلمة المرور' : 'إظهار كلمة المرور');
});
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(); });
})();
# Sign-up with Password Strength
**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:** Sign-up with Password Strength — Strength computed from variety and length together — not length alone
**Why this component matters:** Length-only meters call “aaaaaaaaaaaa” strong. Score character-class variety, penalise repetition, and cap the score so a long weak password never reads as safe.
**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.