Bmg/مولد النصوص
htmlv1MITنُشر ٢٣ أكتوبر ٢٠٢٦· ♥ 0 · ⬇ 24 · 💬 0
أداة توليد نصوص عربية حتمية (كلمات • أرقام • حروف • مختلط) تعمل أوفلاين بدون خوادم.
bmg-1.html
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Bmg/مولد النصوص</title>
<script src="https://unpkg.com/lucide@latest"></script>
<script type="module">
let tsLib = null;
try {
const mod = await import('https://esm.sh/[email protected]');
tsLib = mod.default || mod;
} catch (e) { console.warn('TS CDN failed', e); }
window.__TS__ = tsLib;
window.__compileTS__ = (source) => {
if (tsLib && tsLib.transpileModule) {
return tsLib.transpileModule(source, {
compilerOptions: { target: 99, module: 1, strict: true }
}).outputText;
}
return null;
};
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&family=Source+Serif+4:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;margin:0;padding:0}
:root{
--bg:#111;--text:#c8c8c8;--muted:#97958e;--bub:#292929;
--glass:rgba(41,41,41,.7);--line:rgba(255,255,255,.1);
--accent:#1f86fc;--pad:80px;--ease:cubic-bezier(.2,.85,.3,1);
--ui:'Inter','IBM Plex Sans Arabic',system-ui,sans-serif;
--serif:'Source Serif 4','Noto Naskh Arabic',serif;
--blur:blur(18px) saturate(180%);
--box:rgba(41,41,41,.8);--btn:rgba(13,13,13,.8);
--codebg:#1a1a1a;--inline:#222;--hover:#2a2a2a;
--field:#333;--icon:#ddd;--fs:1;
--ok:#2b9729;--err:#f44236;--warn:#f59e0b;
}
[data-theme=light]{
color-scheme:light;
--bg:#fafafa;--text:#2a2a28;--muted:#6f6e69;--bub:#e8e8e5;
--glass:rgba(255,255,255,.78);--line:rgba(0,0,0,.1);
--box:rgba(255,255,255,.9);--btn:rgba(0,0,0,.06);
--codebg:#f0f0ee;--inline:#e6e6e3;--hover:#ececea;
--field:#ececea;--icon:#3a3a38;
}
html,body{
background:var(--bg);color:var(--text);margin:0;padding:0;
min-height:100dvh;width:100%;font-family:var(--ui);
overscroll-behavior:none;
}
body{display:flex;justify-content:center;padding:20px 16px 40px;min-height:100dvh}
/* ===== Card ===== */
.card{
width:100%;max-width:780px;
background:var(--box);
border:1px solid var(--line);
border-radius:24px;
padding:28px 24px 22px;
backdrop-filter:var(--blur);
-webkit-backdrop-filter:var(--blur);
box-shadow:0 20px 50px rgba(0,0,0,.45);
animation:rise .45s var(--ease);
}
@keyframes rise{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:none}}
/* ===== Header ===== */
.header{display:flex;align-items:center;gap:14px;margin-bottom:6px}
.logo-box{
width:52px;height:52px;border-radius:14px;
background:var(--field);
border:1px solid var(--line);
display:flex;align-items:center;justify-content:center;
flex-shrink:0;overflow:hidden;
}
.logo-box svg{width:34px;height:34px}
h1{font-family:var(--serif);font-weight:600;font-size:22px;letter-spacing:-.3px;color:var(--text)}
.badge{
font-size:11px;font-weight:600;
background:rgba(31,134,252,.15);color:var(--accent);
border:1px solid rgba(31,134,252,.3);
padding:3px 10px;border-radius:99px;margin-right:auto;
}
.sub{color:var(--muted);font-size:13px;margin:4px 0 20px;line-height:1.5}
/* ===== Toolbar ===== */
.toolbar{
display:flex;flex-wrap:wrap;gap:10px;align-items:center;
background:var(--field);
border:1px solid var(--line);
border-radius:16px;padding:10px;margin-bottom:14px;
}
.num-wrap,.seed-wrap{
display:flex;align-items:center;gap:8px;
background:var(--bub);border:1px solid var(--line);
border-radius:12px;padding:6px 12px;height:42px;
}
.num-wrap input,.seed-wrap input{
width:78px;background:transparent;border:none;color:var(--text);
font-size:17px;font-weight:600;outline:none;text-align:center;
font-family:'JetBrains Mono',monospace;
}
.seed-wrap input{color:#fbbf24;width:100px}
.seg{
display:flex;background:var(--bub);border-radius:12px;padding:3px;gap:3px;
border:1px solid var(--line);
}
.seg button{
background:transparent;border:none;color:var(--muted);
padding:8px 12px;border-radius:9px;cursor:pointer;
font-weight:600;font-size:13px;transition:.15s;white-space:nowrap;
}
.seg button.active{
background:var(--text);color:var(--bg);font-weight:700;
}
.btn-main{
background:var(--text);color:var(--bg);border:none;
padding:0 22px;height:42px;border-radius:12px;
font-weight:700;font-size:15px;display:flex;align-items:center;gap:8px;
cursor:pointer;transition:.2s var(--ease);
}
.btn-main:hover{opacity:.9;transform:translateY(-1px)}
.btn-main:active{transform:scale(.97)}
.icon-btn{
background:var(--bub);border:1px solid var(--line);
border-radius:10px;color:var(--icon);width:36px;height:36px;
display:flex;align-items:center;justify-content:center;
cursor:pointer;transition:.15s;
}
.icon-btn:hover{background:var(--hover);color:var(--text)}
/* ===== Type selector ===== */
.type-row{
display:flex;flex-wrap:wrap;gap:8px;margin-bottom:14px;
}
.type-chip{
background:var(--field);border:1px solid var(--line);
color:var(--muted);border-radius:20px;padding:8px 14px;
font-size:13px;font-weight:600;cursor:pointer;
display:flex;align-items:center;gap:6px;transition:.15s;
}
.type-chip.active{
background:var(--text);color:var(--bg);border-color:var(--text);
}
.type-chip:hover:not(.active){background:var(--hover);color:var(--text)}
/* ===== Stats ===== */
.stats{
display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin-bottom:14px;
}
.stat{
background:var(--field);border:1px solid var(--line);
border-radius:14px;padding:10px 6px;text-align:center;
}
.stat b{display:block;font-size:18px;font-family:'JetBrains Mono',monospace;color:var(--accent);font-weight:600}
.stat span{font-size:11px;color:var(--muted)}
.stat.ok b{color:var(--ok)}
.stat.err b{color:var(--err)}
/* ===== Result ===== */
#result{
background:var(--bub);border:1px solid var(--line);
border-radius:18px;padding:20px;min-height:140px;
line-height:2.1;font-size:17px;word-break:break-word;
max-height:380px;overflow-y:auto;transition:border-color .25s,box-shadow .25s;
font-family:var(--serif);
}
#result.valid{border-color:var(--ok);box-shadow:0 0 0 2px rgba(43,151,41,.15)}
#result.invalid{border-color:var(--err);box-shadow:0 0 0 2px rgba(244,66,54,.15)}
#result .w{display:inline-block;animation:pop .28s var(--ease) both}
@keyframes pop{from{opacity:0;transform:translateY(5px) scale(.92)}to{opacity:1}}
/* ===== Actions ===== */
.actions{display:flex;gap:8px;margin-top:14px;flex-wrap:wrap}
.btn-sec{
flex:1;min-width:100px;background:var(--field);border:1px solid var(--line);
color:var(--text);padding:11px 8px;border-radius:12px;
display:flex;align-items:center;justify-content:center;gap:6px;
cursor:pointer;font-weight:600;font-size:13px;transition:.15s;
}
.btn-sec:hover{background:var(--hover);transform:translateY(-1px)}
.btn-sec:active{transform:scale(.97)}
/* ===== Log & TS source ===== */
.log{
margin-top:12px;font-family:'JetBrains Mono',monospace;font-size:11px;
color:var(--muted);background:var(--field);padding:8px 14px;
border-radius:10px;direction:ltr;display:flex;align-items:center;gap:8px;
border:1px solid var(--line);
}
.log .dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}
.ts-src{margin-top:12px;background:var(--codebg);border:1px solid var(--line);border-radius:12px;overflow:hidden}
.ts-src summary{
padding:10px 16px;font-weight:600;font-size:13px;cursor:pointer;
color:var(--accent);display:flex;align-items:center;gap:8px;user-select:none;
}
.ts-src pre{
padding:14px 16px;font-family:'JetBrains Mono',monospace;font-size:11.5px;
line-height:1.65;direction:ltr;text-align:left;overflow-x:auto;
color:#a5b4fc;max-height:240px;overflow-y:auto;
}
/* ===== Toast ===== */
#toast{
position:fixed;bottom:28px;left:50%;transform:translateX(-50%) translateY(80px);
background:var(--glass);border:1px solid var(--line);color:var(--text);
padding:12px 24px;border-radius:99px;font-weight:600;font-size:14px;
opacity:0;transition:.3s var(--ease);z-index:99;pointer-events:none;
backdrop-filter:var(--blur);-webkit-backdrop-filter:var(--blur);
box-shadow:0 8px 30px rgba(0,0,0,.4);
}
#toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
/* ===== Theme toggle ===== */
.theme-btn{
position:fixed;top:18px;left:18px;z-index:50;
background:var(--glass);border:1px solid var(--line);
width:42px;height:42px;border-radius:50%;
display:flex;align-items:center;justify-content:center;
color:var(--icon);cursor:pointer;backdrop-filter:var(--blur);
-webkit-backdrop-filter:var(--blur);transition:.2s;
}
.theme-btn:hover{background:var(--hover)}
@media(max-width:600px){
.stats{grid-template-columns:repeat(3,1fr)}
.toolbar{flex-direction:column;align-items:stretch}
.seg{width:100%;justify-content:space-between}
.btn-main{width:100%;justify-content:center}
h1{font-size:19px}
}
</style>
</head>
<body>
<button class="theme-btn" id="themeBtn" title="تبديل الوضع"><i data-lucide="moon"></i></button>
<div class="card">
<div class="header">
<div class="logo-box">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1600 1600">
<rect width="1600" height="1600" fill="transparent"/>
<path fill="currentColor" d="
M 1061,296
L 862,464
L 882,483
L 895,505
L 900,525
L 900,578
L 841,616
L 814,626
L 791,627
L 770,622
L 756,615
L 699,577
L 699,528
L 704,505
L 718,482
L 738,465
L 540,297
L 567,344
L 595,407
L 606,444
L 614,485
L 614,525
L 401,391
L 401,394
L 430,441
L 474,535
L 516,649
L 536,724
L 538,723
L 537,601
L 539,599
L 615,649
L 615,712
L 613,726
L 606,747
L 588,777
L 587,782
L 626,818
L 652,849
L 678,888
L 699,928
L 699,705
L 701,703
L 720,720
L 730,735
L 736,748
L 741,771
L 741,1044
L 772,1097
L 799,1154
L 833,1086
L 859,1043
L 859,766
L 864,746
L 871,732
L 879,721
L 899,703
L 900,928
L 921,888
L 949,847
L 971,821
L 1013,782
L 995,749
L 986,722
L 985,648
L 1061,600
L 1062,724
L 1064,723
L 1077,669
L 1122,545
L 1164,453
L 1199,392
L 986,525
L 984,523
L 986,481
L 1000,420
L 1019,371
L 1045,321
Z
"/>
</svg>
</div>
<div>
<h1>مولد النصوص العربي Pro</h1>
<p class="sub" style="margin:2px 0 0">توليد حتمي • كلمات • أرقام • حروف • مختلط • بدون خوادم</p>
</div>
<span class="badge" id="engineBadge">TypeScript</span>
</div>
<!-- نوع التوليد -->
<div class="type-row" id="typeRow">
<button class="type-chip active" data-type="words"><i data-lucide="type" style="width:14px"></i> كلمات عربية</button>
<button class="type-chip" data-type="numbers"><i data-lucide="hash" style="width:14px"></i> أرقام</button>
<button class="type-chip" data-type="letters"><i data-lucide="case-sensitive" style="width:14px"></i> حروف إنجليزية</button>
<button class="type-chip" data-type="arabic-letters"><i data-lucide="languages" style="width:14px"></i> حروف عربية</button>
<button class="type-chip" data-type="mixed"><i data-lucide="shuffle" style="width:14px"></i> مختلط</button>
</div>
<div class="toolbar">
<div class="num-wrap">
<i data-lucide="hash" style="opacity:.5;width:16px"></i>
<input type="number" id="wordCount" value="50" min="1" max="100000" title="العدد">
</div>
<div class="seg" id="modeSeg">
<button data-mode="random" class="active">عشوائي</button>
<button data-mode="sentence">جُمل</button>
<button data-mode="freq">متوازن</button>
</div>
<div class="seed-wrap">
<button class="icon-btn" id="diceBtn" title="بذرة عشوائية" style="width:32px;height:32px;border:none;background:transparent">
<i data-lucide="dices" style="color:#fbbf24;width:18px"></i>
</button>
<input type="text" id="seedInput" value="2026" title="Seed — نفس البذرة = نفس النتيجة">
</div>
<button class="btn-main" id="genBtn"><i data-lucide="sparkles" style="width:16px"></i> توليد</button>
</div>
<div class="stats">
<div class="stat"><b id="sReq">50</b><span>مطلوب</span></div>
<div class="stat"><b id="sActual">0</b><span>فعلي</span></div>
<div class="stat"><b id="sChars">0</b><span>حرف</span></div>
<div class="stat"><b id="sTime">0ms</b><span>زمن</span></div>
<div class="stat" id="sState"><b id="sStatus">—</b><span>الحالة</span></div>
</div>
<div id="result">اضغط «توليد» للبدء…</div>
<div class="actions">
<button class="btn-sec" id="copyBtn"><i data-lucide="copy" style="width:15px"></i> نسخ</button>
<button class="btn-sec" id="dlTxt"><i data-lucide="file-text" style="width:15px"></i> TXT</button>
<button class="btn-sec" id="dlJson"><i data-lucide="file-json" style="width:15px"></i> JSON</button>
<button class="btn-sec" id="dlMd"><i data-lucide="file-down" style="width:15px"></i> Markdown</button>
<button class="btn-sec" id="historyBtn"><i data-lucide="history" style="width:15px"></i> آخر نتيجة</button>
</div>
<div class="log">
<span class="dot" id="logDot" style="background:#94a3b8"></span>
<span id="tsLog">TS engine: initializing…</span>
</div>
<details class="ts-src">
<summary><i data-lucide="file-code-2" style="width:15px"></i> عرض كود TypeScript المصدري</summary>
<pre id="tsSourceView"></pre>
</details>
</div>
<div id="toast"></div>
<script>
// ================================================================
// كود TypeScript المصدري
// ================================================================
const TS_SOURCE = `
type Mode = "random" | "sentence" | "freq";
type GenType = "words" | "numbers" | "letters" | "arabic-letters" | "mixed";
interface GenOptions { count: number; mode: Mode; seed: number; type: GenType; }
interface StatsResult { count: number; chars: number; unique: number; ms: number; }
function mulberry32(seed: number): () => number {
let a = seed >>> 0;
return () => {
a |= 0; a = (a + 0x6D2B79F5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
class ArabicGenerator {
private rnd: () => number;
private readonly NOUNS: readonly string[] = [
"الذكاء","التكنولوجيا","المستقبل","الابتكار","الإبداع","المعرفة","العلم","التطور","النجاح","الحياة",
"الطموح","العزيمة","الثقة","الفكر","العقل","الإنسان","الكون","الطبيعة","الجامعة","الطالب",
"المعلم","الفكرة","القصة","المدينة","الأسرة","الصديق","الحرية","الشركة","السوق","الاقتصاد",
"الصناعة","الطاقة","البيئة","الكمبيوتر","البرمجة","البيانات","الإنترنت","التطبيق","المهندس","الشمس",
"القمر","السماء","البحر","الجبل","الرحلة","الفرصة","التحدي","الإنجاز","التقدم","الازدهار",
"الأماني","النجوم","الصحراء","الحديقة","المكتبة","المختبر","الشبكة","الذاكرة","الخيال","الواقع"
];
private readonly VERBS: readonly string[] = [
"يكتب","يقرأ","يفكر","يحلم","يعمل","يبتكر","يتعلم","يصنع","يبني","يصمم",
"يستكشف","يوثق","يرسم","يحلل","يطور","يواجه","يحقق","يحوّل","يربط","يحرر"
];
private readonly ADJS: readonly string[] = [
"جميل","عظيم","ذكي","جديد","عملاق","مذهل","عميق","واسع","مضيء","قوي",
"سريع","دقيق","مستدام","متجدد","آمن","مفتوح","عالمي","رقمي","حديث","خلاق"
];
private readonly STARTERS: readonly string[] = ["في","وقد","ثم","لقد","وبعد","عندما","كلما","حيث"];
private readonly ENDERS: readonly string[] = ["بشكل مستمر","بثقة واطمئنان","نحو المستقبل","بلا توقف","بروح طموحة","كل يوم","بلا حدود"];
private readonly LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private readonly ARABIC_LETTERS = "ابتثجحخدذرزسشصضطظعغفقكلمنهويأإآؤئىة";
constructor(seed: number) { this.rnd = mulberry32(seed); }
private pick<T>(arr: readonly T[] | string): T {
return (arr as any)[Math.floor(this.rnd() * arr.length)];
}
private makeSentence(targetLen: number): string[] {
const words: string[] = [this.pick(this.STARTERS), this.pick(this.NOUNS), this.pick(this.VERBS)];
while (words.length < targetLen - 1) {
const r = this.rnd();
if (r < 0.45) words.push(this.pick(this.NOUNS));
else if (r < 0.75) words.push(this.pick(this.ADJS));
else words.push(this.pick(this.VERBS));
}
if (targetLen > 3) words.push(this.pick(this.ENDERS));
return words;
}
private genNumber(): string {
const len = 1 + Math.floor(this.rnd() * 6);
let n = "";
for (let i = 0; i < len; i++) n += Math.floor(this.rnd() * 10);
return n.replace(/^0+(?=\\d)/, "") || "0";
}
private genLetter(arabic = false): string {
const src = arabic ? this.ARABIC_LETTERS : this.LETTERS;
return this.pick(src);
}
private genWord(): string {
const bank = [...this.NOUNS, ...this.NOUNS, ...this.VERBS, ...this.ADJS];
return this.pick(bank);
}
generate(opts: GenOptions): string[] {
const out: string[] = [];
const { count, mode, type } = opts;
if (type === "words" && mode === "sentence") {
while (out.length < count) {
const remaining = count - out.length;
const len = Math.min(remaining, 4 + Math.floor(this.rnd() * 5));
out.push(...this.makeSentence(len));
}
return out.slice(0, count);
}
for (let i = 0; i < count; i++) {
let item = "";
if (type === "words") {
item = this.genWord();
if (mode === "freq" && i % 7 === 0) item = item + " " + item;
} else if (type === "numbers") {
item = this.genNumber();
} else if (type === "letters") {
item = this.genLetter(false);
} else if (type === "arabic-letters") {
item = this.genLetter(true);
} else if (type === "mixed") {
const r = this.rnd();
if (r < 0.35) item = this.genWord();
else if (r < 0.55) item = this.genNumber();
else if (r < 0.75) item = this.genLetter(false);
else item = this.genLetter(true);
}
out.push(item);
}
return out;
}
}
class ArabicValidator {
static countWords(text: string): number {
if (!text || !text.trim()) return 0;
const m = text.trim().match(/[\\u0600-\\u06FF0-9a-zA-Z]+(?:[''-][\\u0600-\\u06FFa-zA-Z]+)*/g);
return m ? m.length : 0;
}
static fullStats(text: string): StatsResult {
const t0 = performance.now();
const count = this.countWords(text);
return {
count,
chars: text.length,
unique: new Set(text.trim().split(/\\s+/)).size,
ms: Math.round((performance.now() - t0) * 100) / 100
};
}
}
window.__GEN__ = { ArabicGenerator, ArabicValidator, mulberry32 };
`;
// ================================================================
// Fallback JS
// ================================================================
const FALLBACK_JS = `
function mulberry32(seed){let a=seed>>>0;return()=>{a|=0;a=(a+0x6D2B79F5)|0;let t=Math.imul(a^(a>>>15),1|a);t=(t+Math.imul(t^(t>>>7),61|t))^t;return((t^(t>>>14))>>>0)/4294967296;};}
class ArabicGenerator{constructor(s){this.rnd=mulberry32(s);
this.N=["الذكاء","التكنولوجيا","المستقبل","الابتكار","الإبداع","المعرفة","العلم","التطور","النجاح","الحياة","الطموح","العزيمة","الثقة","الفكر","العقل","الإنسان","الكون","الطبيعة","الجامعة","الطالب","المعلم","الفكرة","القصة","المدينة","الأسرة","الصديق","الحرية","الشركة","السوق","الاقتصاد","الصناعة","الطاقة","البيئة","الكمبيوتر","البرمجة","البيانات","الإنترنت","التطبيق","المهندس","الشمس","القمر","السماء","البحر","الجبل","الرحلة","الفرصة","التحدي","الإنجاز","التقدم","الازدهار","الأماني","النجوم","الصحراء","الحديقة","المكتبة","المختبر","الشبكة","الذاكرة","الخيال","الواقع"];
this.V=["يكتب","يقرأ","يفكر","يحلم","يعمل","يبتكر","يتعلم","يصنع","يبني","يصمم","يستكشف","يوثق","يرسم","يحلل","يطور","يواجه","يحقق","يحوّل","يربط","يحرر"];
this.A=["جميل","عظيم","ذكي","جديد","عملاق","مذهل","عميق","واسع","مضيء","قوي","سريع","دقيق","مستدام","متجدد","آمن","مفتوح","عالمي","رقمي","حديث","خلاق"];
this.S=["في","وقد","ثم","لقد","وبعد","عندما","كلما","حيث"];
this.E=["بشكل مستمر","بثقة واطمئنان","نحو المستقبل","بلا توقف","بروح طموحة","كل يوم","بلا حدود"];
this.LETTERS="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
this.ARABIC_LETTERS="ابتثجحخدذرزسشصضطظعغفقكلمنهويأإآؤئىة";}
p(x){return x[Math.floor(this.rnd()*x.length)];}
mk(len){const w=[this.p(this.S),this.p(this.N),this.p(this.V)];while(w.length<len-1){const r=this.rnd();w.push(r<.45?this.p(this.N):r<.75?this.p(this.A):this.p(this.V));}if(len>3)w.push(this.p(this.E));return w;}
genNumber(){const len=1+Math.floor(this.rnd()*6);let n="";for(let i=0;i<len;i++)n+=Math.floor(this.rnd()*10);return n.replace(/^0+(?=\\d)/,"")||"0";}
genLetter(ar){return this.p(ar?this.ARABIC_LETTERS:this.LETTERS);}
genWord(){const b=[...this.N,...this.N,...this.V,...this.A];return this.p(b);}
gen(o){const out=[];if(o.type==="words"&&o.mode==="sentence"){while(out.length<o.count){const r=o.count-out.length;out.push(...this.mk(Math.min(r,4+Math.floor(this.rnd()*5))));}return out.slice(0,o.count);}
for(let i=0;i<o.count;i++){let item="";if(o.type==="words"){item=this.genWord();if(o.mode==="freq"&&i%7===0)item=item+" "+item;}
else if(o.type==="numbers")item=this.genNumber();
else if(o.type==="letters")item=this.genLetter(false);
else if(o.type==="arabic-letters")item=this.genLetter(true);
else if(o.type==="mixed"){const r=this.rnd();if(r<.35)item=this.genWord();else if(r<.55)item=this.genNumber();else if(r<.75)item=this.genLetter(false);else item=this.genLetter(true);}
out.push(item);}return out;}}
window.__GEN__={ArabicGenerator};
`;
// ============ تشغيل المحرك ============
(async function boot() {
const log = document.getElementById('tsLog');
const dot = document.getElementById('logDot');
const badge = document.getElementById('engineBadge');
await new Promise(r => setTimeout(r, 60));
const compile = window.__compileTS__;
if (compile) {
try {
const code = compile(TS_SOURCE);
const fn = new Function('window','exports','module', code);
const module = { exports: {} };
fn(window, module.exports, module);
badge.textContent = 'TypeScript ✓';
log.textContent = 'TS engine: compiled & executed in-browser';
dot.style.background = '#2b9729';
} catch (e) {
console.error('TS compile failed:', e);
}
}
if (!window.__GEN__) {
try { new Function(FALLBACK_JS)(); } catch(e) { console.error(e); }
badge.textContent = 'JS Fallback';
log.textContent = 'TS engine: CDN unavailable → fallback active';
dot.style.background = '#f59e0b';
}
initApp();
})();
function initApp() {
const { ArabicGenerator } = window.__GEN__;
const $ = id => document.getElementById(id);
const els = {
input: $('wordCount'), seed: $('seedInput'), result: $('result'),
sReq: $('sReq'), sActual: $('sActual'), sChars: $('sChars'),
sTime: $('sTime'), sStatus: $('sStatus'), sState: $('sState')
};
let mode = 'random';
let genType = 'words';
let lastResult = null;
document.getElementById('tsSourceView').textContent = TS_SOURCE;
const toast = msg => {
const t = $('toast'); t.textContent = msg; t.classList.add('show');
clearTimeout(t._tm); t._tm = setTimeout(() => t.classList.remove('show'), 2200);
};
function generate() {
const count = Math.max(1, Math.min(100000, parseInt(els.input.value) || 50));
els.input.value = count;
const seed = (parseInt(els.seed.value) || 0) >>> 0;
const t0 = performance.now();
const gen = new ArabicGenerator(seed);
const words = gen.gen({ count, mode, seed, type: genType });
const text = words.join(' ');
const ms = Math.round((performance.now() - t0) * 10) / 10;
els.result.innerHTML = '';
const frag = document.createDocumentFragment();
words.forEach((w, i) => {
const sp = document.createElement('span');
sp.className = 'w'; sp.textContent = w;
sp.style.animationDelay = Math.min(i * 6, 350) + 'ms';
frag.appendChild(sp);
frag.appendChild(document.createTextNode(' '));
});
els.result.appendChild(frag);
const m = text.trim().match(/[\u0600-\u06FF0-9a-zA-Z]+/g) || [];
const actual = m.length;
const ok = actual === count;
els.sReq.textContent = count;
els.sActual.textContent = actual;
els.sChars.textContent = text.length;
els.sTime.textContent = ms + 'ms';
els.sStatus.textContent = ok ? '✓ مظبوط' : '✗ خلل';
els.sState.className = 'stat ' + (ok ? 'ok' : 'err');
els.result.classList.toggle('valid', ok);
els.result.classList.toggle('invalid', !ok);
lastResult = { text, count, mode, type: genType, seed, ms, ts: new Date().toISOString() };
try { localStorage.setItem('awp:last', JSON.stringify(lastResult)); } catch(e){}
document.getElementById('tsLog').textContent =
`TS > type=${genType} mode=${mode} seed=${seed} expected=${count} actual=${actual} valid=${ok} gen=${ms}ms`;
}
// Type chips
document.getElementById('typeRow').addEventListener('click', e => {
const b = e.target.closest('.type-chip');
if (!b) return;
genType = b.dataset.type;
document.querySelectorAll('.type-chip').forEach(x => x.classList.toggle('active', x === b));
// إخفاء أوضاع الجملة والمتوازن إذا مش كلمات
const modeSeg = document.getElementById('modeSeg');
if (genType !== 'words') {
modeSeg.style.opacity = '0.4';
modeSeg.style.pointerEvents = 'none';
mode = 'random';
document.querySelectorAll('#modeSeg button').forEach(x => x.classList.toggle('active', x.dataset.mode === 'random'));
} else {
modeSeg.style.opacity = '1';
modeSeg.style.pointerEvents = 'auto';
}
generate();
});
// Events
$('genBtn').addEventListener('click', generate);
document.getElementById('modeSeg').addEventListener('click', e => {
const b = e.target.closest('button'); if (!b) return;
mode = b.dataset.mode;
document.querySelectorAll('#modeSeg button').forEach(x => x.classList.toggle('active', x === b));
generate();
});
$('diceBtn').addEventListener('click', () => {
els.seed.value = Math.floor(Math.random() * 1e9);
toast('🎲 بذرة جديدة: ' + els.seed.value);
generate();
});
els.input.addEventListener('change', generate);
els.seed.addEventListener('change', generate);
$('copyBtn').addEventListener('click', async () => {
await navigator.clipboard.writeText(els.result.textContent.trim());
toast('✓ تم النسخ');
});
const download = (content, name, type) => {
const a = document.createElement('a');
a.href = URL.createObjectURL(new Blob([content], { type }));
a.download = name; a.click();
setTimeout(() => URL.revokeObjectURL(a.href), 2000);
};
$('dlTxt').addEventListener('click', () => {
if (!lastResult) return toast('ولّد أولاً');
download(lastResult.text, `arabic-${lastResult.count}.txt`, 'text/plain;charset=utf-8');
toast('✓ تم تنزيل TXT');
});
$('dlJson').addEventListener('click', () => {
if (!lastResult) return toast('ولّد أولاً');
download(JSON.stringify({ ...lastResult, items: lastResult.text.split(' ') }, null, 2),
`arabic-${lastResult.count}.json`, 'application/json');
toast('✓ تم تنزيل JSON');
});
$('dlMd').addEventListener('click', () => {
if (!lastResult) return toast('ولّد أولاً');
download(`# مولد النصوص العربي Pro\\n\\n- **العدد:** ${lastResult.count}\\n- **النوع:** ${lastResult.type}\\n- **النمط:** ${lastResult.mode}\\n- **Seed:** ${lastResult.seed}\\n- **الزمن:** ${lastResult.ms}ms\\n\\n${lastResult.text}`,
`arabic-${lastResult.count}.md`, 'text/markdown;charset=utf-8');
toast('✓ تم تنزيل Markdown');
});
$('historyBtn').addEventListener('click', () => {
try {
const s = JSON.parse(localStorage.getItem('awp:last') || 'null');
if (!s) return toast('لا يوجد تاريخ');
els.input.value = s.count; els.seed.value = s.seed;
mode = s.mode; genType = s.type || 'words';
document.querySelectorAll('#modeSeg button').forEach(x => x.classList.toggle('active', x.dataset.mode === mode));
document.querySelectorAll('.type-chip').forEach(x => x.classList.toggle('active', x.dataset.type === genType));
els.result.textContent = s.text;
toast('↩ تمت استعادة آخر نتيجة');
} catch(e) { toast('خطأ في الاستعادة'); }
});
// Theme toggle
const themeBtn = $('themeBtn');
const savedTheme = localStorage.getItem('awp:theme');
if (savedTheme === 'light') document.documentElement.setAttribute('data-theme', 'light');
themeBtn.addEventListener('click', () => {
const isLight = document.documentElement.getAttribute('data-theme') === 'light';
if (isLight) {
document.documentElement.removeAttribute('data-theme');
localStorage.setItem('awp:theme', 'dark');
themeBtn.innerHTML = '<i data-lucide="moon"></i>';
} else {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('awp:theme', 'light');
themeBtn.innerHTML = '<i data-lucide="sun"></i>';
}
lucide.createIcons();
});
if (savedTheme === 'light') themeBtn.innerHTML = '<i data-lucide="sun"></i>';
document.addEventListener('keydown', e => {
if (e.key === 'Enter' && document.activeElement !== els.input) generate();
});
lucide.createIcons();
generate();
}
</script>
</body>
</html>
1280×720 · 58%
محاكاة عرض المتصفح: يتغير عرض الصفحة الفعلي فتُطبَّق استعلامات CSS، لكنها ليست جهازاً حقيقياً (لا لمس ولا نظام تشغيل مختلف). المعاينة معزولة بلا ملفات تعريف ارتباط ولا اتصال بالشبكة.
ملفات الويب تُعرض في تبويب «المعاينة».
التعليقات (0)
سجّل الدخول للتعليق.