المكوّنات · انقطاع اتّصال بطابور
انقطاع اتّصال بطابور
يحتفظ بما لم يُرسل ويبعثه عند عودة الشبكة
12 تصاميم من هذه العائلة
<div class="fb fbo">
<div class="net" role="status"><span class="dot" aria-hidden="true"></span>
<span class="lbl"></span>
<button class="sim" data-ar="حاكِ الانقطاع" data-en="Simulate offline">حاكِ الانقطاع</button></div>
<div class="body">
<button class="act" data-ar="أرسل تحديث الموقع" data-en="Send location update">أرسل تحديث الموقع</button>
<ul class="q"></ul>
<p class="hint"></p>
</div>
</div>
/* pt-scoped */
/* feedback-offline — تطبيق توصيل */
.fbo{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.fbo h4{margin:0;font-size:11px;color:var(--pt-text-primary);font-weight:600;line-height:1.5}
.fbo p{margin:0;font-size:9px;line-height:1.85;color:var(--pt-text-muted)}
.fbo .num{font-variant-numeric:tabular-nums}
.fbo button{font:inherit;cursor:pointer}
.fbo button:focus-visible, .fbo input:focus-visible, .fbo a:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:2px}
.fbo button:disabled{cursor:not-allowed;opacity:.45}
/* كل حالة تُعلَن لقارئ الشاشة: تغيّرٌ لا يُرى ولا يُسمَع لم يحدث */
.fbo [role=status], .fbo [role=alert]{display:block}
@media(pointer:coarse){.fbo button{min-height:44px}
}
/* شخصية: شريط حالة علوي، طابور تحته، انحناء متوسّط */
.fbo{gap:8px;padding:10px 12px}
.fbo .net{display:flex;align-items:center;gap:6px;padding:5px 9px;
border-radius:var(--pt-radius-full);font-size:8.5px;
background:var(--pt-bg-inset);border:1px solid var(--pt-border-subtle)}
.fbo .dot{width:6px;height:6px;border-radius:50%;flex:none}
.fbo.on .dot{background:var(--pt-accent)}
.fbo.off .dot{background:var(--pt-color-warn-400)}
.fbo.off .net{background:color-mix(in srgb,var(--pt-color-warn-400) 12%,transparent);
border-color:var(--pt-color-warn-400)}
.fbo .lbl{flex:1}
.fbo .sim{padding:3px 9px;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:transparent;
color:var(--pt-text-secondary);font-size:7.5px}
.fbo .body{flex:1;display:flex;flex-direction:column;gap:6px;min-height:0}
.fbo .act{padding:7px;border-radius:var(--pt-radius-md);border:0;
background:var(--pt-accent);color:var(--pt-color-ink-900);font-size:9px;font-weight:600}
.fbo .q{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:3px;
flex:1;overflow-y:auto;min-height:0}
.fbo .q li{display:flex;align-items:center;justify-content:space-between;gap:8px;
padding:4px 8px;border-radius:var(--pt-radius-sm);background:var(--pt-surface);
border:1px solid var(--pt-border-subtle);font-size:8px}
.fbo .q .st{font-size:7.5px}
.fbo .q li.pend .st{color:var(--pt-color-warn-400)}
.fbo .q li.sent .st{color:var(--pt-accent)}
.fbo .hint{font-size:7.5px;min-height:10px}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.fbo');
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 || 0, maximumFractionDigits: d || 0 }); };
var net = root.querySelector('.lbl'), q = root.querySelector('.q');
var hint = root.querySelector('.hint'), act = root.querySelector('.act');
var forced = false, seq = 0;
function online() { return !forced && navigator.onLine; }
function paint() {
root.className = 'fb fbo ' + (online() ? 'on' : 'off');
net.textContent = online() ? (ar ? 'متّصل' : 'Online')
: (ar ? 'غير متّصل — الإجراءات تُحفظ' : 'Offline — actions are queued');
if (online()) flush();
}
/* الطابور بدل الفشل: فقدان نقرة لأنّ النفق بلا تغطية أسرع طريق لفقدان الطلب */
function flush() {
var pend = [].slice.call(q.querySelectorAll('li.pend'));
if (!pend.length) return;
pend.forEach(function (li, i) {
setTimeout(function () {
li.className = 'sent';
li.querySelector('.st').textContent = ar ? '✓ أُرسل' : '✓ Sent';
}, 260 * (i + 1));
});
hint.textContent = ar ? 'عادت الشبكة — أُرسل ' + pend.length + ' من الطابور'
: 'Back online — flushed ' + pend.length + ' queued';
}
act.addEventListener('click', function () {
var li = document.createElement('li');
var t = new Date().toLocaleTimeString(ar ? 'ar-SA-u-nu-latn' : 'en-GB',
{ hour: '2-digit', minute: '2-digit', second: '2-digit' });
li.className = online() ? 'sent' : 'pend';
li.innerHTML = '<span>' + (ar ? 'تحديث موقع #' : 'Location #') + (++seq) +
' · ' + t + '</span><span class="st">' +
(online() ? (ar ? '✓ أُرسل' : '✓ Sent') : (ar ? '⏳ في الطابور' : '⏳ Queued')) + '</span>';
q.appendChild(li);
q.scrollTop = q.scrollHeight;
hint.textContent = online() ? '' : (ar ? 'سيُرسل تلقائيًّا عند عودة الشبكة'
: 'Will send automatically when the network returns');
});
root.querySelector('.sim').addEventListener('click', function () { forced = !forced; paint(); });
addEventListener('online', paint);
addEventListener('offline', paint);
paint();
}
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(); });
})();
# Offline with a Queue
**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:** Offline with a Queue — Holds what could not be sent and flushes it when the network returns
**Why this component matters:** Listen to the online and offline events, and queue user actions instead of failing them. Losing a tap because the tunnel had no signal is the fastest way to lose the order.
**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.