المكوّنات · بحث بنطاق مكاني
بحث بنطاق مكاني
المسافة محسوبة بهافرساين لا بفرق الإحداثيات
12 تصاميم من هذه العائلة
<div class="sr srgeo">
<div class="fld">
<span aria-hidden="true">📍</span>
<input type="search" aria-label="ابحث عن مطعم" placeholder="اسم المطعم أو نوع الطعام…">
</div>
<label class="rad"><span><span data-ar="ضمن" data-en="Within">ضمن</span>
<b class="rv"></b></span>
<input type="range" min="1" max="20" step="1" value="5" aria-label="نصف القطر"></label>
<div class="cnt"></div>
<ul></ul>
<p class="empty" hidden data-ar="لا مطعم ضمن هذا النطاق" data-en="Nothing within this radius">لا مطعم ضمن هذا النطاق</p>
</div>
/* pt-scoped */
/* search-geo — تطبيق توصيل */
.srgeo{width:100%;height:100%;display:flex;flex-direction:column;gap:7px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;position:relative}
.srgeo .fld{display:flex;align-items:center;gap:6px;width:100%}
.srgeo input[type=search], .srgeo input[type=text]{flex:1;min-width:0;border:0;background:transparent;
color:var(--pt-text-primary);font:inherit;font-size:10px;outline:none}
.srgeo input::placeholder{color:var(--pt-text-muted)}
.srgeo ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px;
overflow-y:auto}
.srgeo li[hidden]{display:none}
.srgeo mark{background:color-mix(in srgb,var(--pt-accent) 30%,transparent);
color:inherit;border-radius:2px;padding:0 1px}
.srgeo .empty{margin:0;padding:9px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
.srgeo .cnt{font-size:8.5px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
white-space:nowrap}
.srgeo{padding:9px;gap:6px}
.srgeo .fld{padding:6px 9px;border-radius:var(--pt-radius-lg);
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset);font-size:10px}
.srgeo .fld:focus-within{border-color:var(--pt-accent)}
.srgeo .rad{display:flex;flex-direction:column;gap:3px;font-size:8px;color:var(--pt-text-muted)}
.srgeo .rad > span{display:flex;align-items:baseline;gap:4px}
.srgeo .rv{color:var(--pt-accent);font-weight:700;font-variant-numeric:tabular-nums;font-size:9px}
.srgeo input[type=range]{width:100%;accent-color:var(--pt-accent);height:3px}
.srgeo ul{flex:1;gap:3px}
.srgeo li{display:flex;align-items:center;gap:8px;padding:5px 8px;
border-radius:var(--pt-radius-lg);background:var(--pt-surface);
border:1px solid var(--pt-border-subtle);font-size:9px}
.srgeo li .t{flex:1;color:var(--pt-text-primary)}
.srgeo li .k{color:var(--pt-text-muted);font-size:7.5px}
.srgeo li .d{color:var(--pt-accent);font-weight:700;font-variant-numeric:tabular-nums;font-size:8.5px}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.srgeo');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
function norm(s) {
return String(s).replace(/[\u064B-\u0652\u0670\u0640]/g, '')
.replace(/[\u0622\u0623\u0625\u0671]/g, '\u0627')
.replace(/\u0629/g, '\u0647').replace(/\u0649/g, '\u064A')
.replace(/\u0624/g, '\u0648').replace(/\u0626/g, '\u064A')
.replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.toLowerCase().replace(/\s+/g, ' ').trim();
}
function stripAl(w) { return w.length > 4 && w.indexOf('\u0627\u0644') === 0 ? w.slice(2) : w; }
function hit(hay, q) {
var terms = norm(q).split(' ').filter(Boolean);
if (!terms.length) return true;
var h = norm(hay);
return terms.every(function (t) { return h.indexOf(t) !== -1 || h.indexOf(stripAl(t)) !== -1; });
}
/* التظليل يعمل على النصّ الأصلي لا المطبَّع: الأطوال تختلف بعد التطبيع،
فالمطابقة على المطبَّع تظلّل الحرف الخطأ. نبحث عن أطول بادئة مطابقة. */
function mark(el, q) {
var raw = el.dataset.raw || el.textContent;
el.dataset.raw = raw;
var t = norm(q).split(' ').filter(Boolean)[0];
if (!t) { el.textContent = raw; return; }
for (var i = 0; i < raw.length; i++) {
for (var j = raw.length; j > i; j--) {
if (norm(raw.slice(i, j)) === t) {
el.innerHTML = '';
el.appendChild(document.createTextNode(raw.slice(0, i)));
var m = document.createElement('mark');
m.textContent = raw.slice(i, j);
el.appendChild(m);
el.appendChild(document.createTextNode(raw.slice(j)));
return;
}
}
}
el.textContent = raw;
}
var ME = { lat: 24.7136, lon: 46.6753 }; /* الرياض */
var PLACES = [
{ t: 'مندي الديرة', k: 'مأكولات شعبية', lat: 24.7290, lon: 46.6900 },
{ t: 'بيت الشاورما', k: 'شاورما', lat: 24.7050, lon: 46.6820 },
{ t: 'برجر الحيّ', k: 'برجر', lat: 24.7740, lon: 46.7380 },
{ t: 'مطعم البحر', k: 'أسماك', lat: 24.6580, lon: 46.7120 },
{ t: 'كافيه الرصيف', k: 'قهوة ومعجّنات', lat: 24.7180, lon: 46.6690 },
{ t: 'مطبخ الشام', k: 'مأكولات شامية', lat: 24.8420, lon: 46.6320 }
];
var ar = document.documentElement.lang !== 'en';
/* هافرساين: طرح الإحداثيات ليس مسافة — درجة الطول تنكمش كلّما ارتفع العرض */
function dist(a, b) {
var R = 6371, rad = Math.PI / 180;
var dLat = (b.lat - a.lat) * rad, dLon = (b.lon - a.lon) * rad;
var h = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(a.lat * rad) * Math.cos(b.lat * rad) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
return 2 * R * Math.asin(Math.sqrt(h));
}
var input = root.querySelector('input[type=search]');
var range = root.querySelector('input[type=range]');
var rv = root.querySelector('.rv'), list = root.querySelector('ul');
var cnt = root.querySelector('.cnt'), empty = root.querySelector('.empty');
var withD = PLACES.map(function (p) { return { p: p, d: dist(ME, p) }; })
.sort(function (x, y) { return x.d - y.d; });
list.innerHTML = withD.map(function (o) {
return '<li><span class="t">' + o.p.t + '</span><span class="k">' + o.p.k +
'</span><span class="d">' + o.d.toFixed(1) + (ar ? ' كم' : ' km') + '</span></li>';
}).join('');
var lis = [].slice.call(list.children);
function run() {
var r = +range.value, q = input.value, shown = 0;
rv.textContent = r + (ar ? ' كم' : ' km');
lis.forEach(function (li, i) {
var o = withD[i];
var ok = o.d <= r && hit(o.p.t + ' ' + o.p.k, q);
li.hidden = !ok;
if (ok) { shown++; mark(li.querySelector('.t'), q); }
});
empty.hidden = shown > 0;
cnt.textContent = shown + (ar ? ' مطعمًا ضمن النطاق' : ' places in range');
}
input.addEventListener('input', run);
range.addEventListener('input', run);
run();
}
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(); });
})();
# Radius Search
**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:** Radius Search — Distance computed with haversine, not raw coordinate differences
**Why this component matters:** Subtracting latitudes and longitudes is not distance: a degree of longitude shrinks with latitude. Use the haversine formula or the radius filter is simply wrong.
**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.
**Important:** This component has no equivalent in any global library. Do not imitate a
Latin pattern and translate its labels — build it from Gulf market requirements directly.