🏠 الرئيسية📚 الدرس✖️ تبسيط تعبير حرفي في a
🏆 0 نقطة
🤖
مرحباً!
📹 فيديو توضيحي

✖️ الضرب في ℚ

تبسيط تعبير حرفي في a

🎓 الثامنة — أعداد موجبة وسالبةتبسيط تعبير حرفي في a⭐ متوسط

📹 فيديو توضيحي

0 من 0 تمرين
📝 تمارين — تبسيط تعبير حرفي في a — الصفحة 4 من 10

✏️ أدخل تعبيرك أو استخدم الوضع التلقائي

🎉 أحسنت!

لقد أنجزت جميع التمارين

⭐⭐⭐

tex="\\neq">≠
`; /* ══════════════════════════════════════════════════════════ 3. INITIALISATION AU CHARGEMENT DE LA PAGE ══════════════════════════════════════════════════════════ */ function init() { // Éviter double-chargement if (document.getElementById('ka-popup')) return; // Injecter le CSS const style = document.createElement('style'); style.id = 'ka-style'; style.textContent = CSS; document.head.appendChild(style); // Injecter la popup const div = document.createElement('div'); div.innerHTML = POPUP_HTML; document.body.appendChild(div.firstElementChild); // Lancer le moteur launchEngine(); } /* ══════════════════════════════════════════════════════════ 4. MOTEUR MATHÉMATIQUE ══════════════════════════════════════════════════════════ */ function launchEngine() { const mk = () => ({ tokens: [], cursor: 0 }); const T = { ch : (c, l) => ({ type: 'ch', char: c, latex: l || c }), frac: () => ({ type: 'frac', num: mk(), den: mk() }), pow : (base) => ({ type: 'pow', base: base || mk(), exp: mk() }), sqrt: () => ({ type: 'sqrt', rad: mk() }), }; let root = mk(), path = [root]; let activeAnswerEl = null; let activeLatexInput = null; /* ── État sauvegardé par champ (clé = id du champ) ── */ const fieldStates = new Map(); const cur = () => path[path.length - 1]; const dep = () => path.length; const mpty = g => g.tokens.length === 0; function ins(tok) { const g = cur(); g.tokens.splice(g.cursor, 0, tok); g.cursor++; if (tok.type === 'frac') path.push(tok.num); else if (tok.type === 'pow') path.push(tok.exp); else if (tok.type === 'sqrt') path.push(tok.rad); upd(); } function bs() { const g = cur(); if (g.cursor > 0) { const t = g.tokens[g.cursor - 1]; if ((t.type === 'frac' && mpty(t.num) && mpty(t.den)) || (t.type === 'sqrt' && mpty(t.rad))) { g.tokens.splice(g.cursor - 1, 1); g.cursor--; } else if (t.type === 'pow' && mpty(t.exp)) { const b = t.base.tokens; g.tokens.splice(g.cursor - 1, 1); g.cursor--; b.forEach(x => { g.tokens.splice(g.cursor, 0, x); g.cursor++; }); } else { g.tokens.splice(g.cursor - 1, 1); g.cursor--; } } else if (dep() > 1) path.pop(); upd(); } function mvL() { const g = cur(); if (g.cursor > 0) { g.cursor--; const t = g.tokens[g.cursor]; if (t?.type === 'frac') { path.push(t.den); t.den.cursor = t.den.tokens.length; } else if (t?.type === 'pow') { path.push(t.exp); t.exp.cursor = t.exp.tokens.length; } else if (t?.type === 'sqrt') { path.push(t.rad); t.rad.cursor = t.rad.tokens.length; } } else if (dep() > 1) { path.pop(); mvL(); return; } upd(); } function mvR() { const g = cur(); if (g.cursor < g.tokens.length) { const t = g.tokens[g.cursor]; if (t?.type === 'frac') { path.push(t.num); t.num.cursor = 0; g.cursor++; } else if (t?.type === 'pow') { path.push(t.exp); t.exp.cursor = 0; g.cursor++; } else if (t?.type === 'sqrt') { path.push(t.rad); t.rad.cursor = 0; g.cursor++; } else g.cursor++; } else if (dep() > 1) path.pop(); upd(); } function exit() { if (dep() < 2) { upd(); return; } const inner = path[dep() - 1]; path.pop(); const p = path[dep() - 1], tok = p.tokens[p.cursor - 1]; if (tok?.type === 'frac' && inner === tok.num) { path.push(tok.den); tok.den.cursor = tok.den.tokens.length; } upd(); } /* LaTeX */ function toLx(g) { return g.tokens.map(tl).join(''); } function tl(t) { if (t.type === 'ch') return t.latex; if (t.type === 'frac') return `\\frac{${toLx(t.num) || '\\square'}}{${toLx(t.den) || '\\square'}}`; if (t.type === 'pow') return `${toLx(t.base)}^{${toLx(t.exp) || 'n'}}`; if (t.type === 'sqrt') return `\\sqrt{${toLx(t.rad) || '\\square'}}`; return ''; } /* Rendu HTML visuel */ function bld(g) { const a = cur(); let h = ''; for (let i = 0; i <= g.tokens.length; i++) { if (i === g.cursor && g === a) h += ''; if (i === g.tokens.length) break; const t = g.tokens[i]; if (t.type === 'ch') { h += `${esc(t.char)}`; } else if (t.type === 'frac') { const an = a === t.num, ad = a === t.den; h += ` ${bld(t.num)} ${bld(t.den)} `; } else if (t.type === 'pow') { const ae = a === t.exp; h += ` ${bld(t.base)} ${bld(t.exp)} `; } else if (t.type === 'sqrt') { const ar = a === t.rad; h += ` ${bld(t.rad)} `; } } return h; } const esc = c => c.replace(/&/g, '&').replace(//g, '>'); const preview = document.getElementById('ka-preview'); const popup = document.getElementById('ka-popup'); function upd() { const html = bld(root); const latex = toLx(root); const empty = !latex.trim(); preview.innerHTML = html; preview.classList.toggle('empty', empty); if (activeAnswerEl) { activeAnswerEl.innerHTML = empty ? '' : html; activeAnswerEl.classList.toggle('empty', empty); } if (activeLatexInput) activeLatexInput.value = latex; } /* Dispatcher */ function doBtn(btn) { const a = btn.dataset.action, ch = btn.dataset.char, lx = btn.dataset.latex; switch (a) { case 'frac': ins(T.frac()); break; case 'pow': { const g = cur(), base = mk(); if (g.cursor > 0) { const p = g.tokens.splice(g.cursor - 1, 1)[0]; g.cursor--; base.tokens.push(p); base.cursor = 1; } ins(T.pow(base)); break; } case 'pow2': case 'pow3': { const g = cur(), base = mk(); if (g.cursor > 0) { const p = g.tokens.splice(g.cursor - 1, 1)[0]; g.cursor--; base.tokens.push(p); base.cursor = 1; } const pt = T.pow(base), n = a === 'pow2' ? '2' : '3'; pt.exp.tokens.push(T.ch(n, n)); pt.exp.cursor = 1; g.tokens.splice(g.cursor, 0, pt); g.cursor++; upd(); break; } case 'sqrt': ins(T.sqrt()); break; case 'braces': ins(T.ch('{','\\{')); ins(T.ch('}','\\}')); mvL(); break; case 'brackets': ins(T.ch('[','[')); ins(T.ch(']',']')); mvL(); break; case 'abs': ins(T.ch('|','|')); ins(T.ch('|','|')); mvL(); break; case 'bs': bs(); break; case 'left': mvL(); break; case 'right': mvR(); break; case 'exit': exit(); break; default: if (ch) ins(T.ch(ch, lx || ch)); else if (lx) ins(T.ch(lx, lx)); } } /* Délégation d'événements sur la popup (gère les boutons .kk) */ popup.addEventListener('mousedown', e => { const btn = e.target.closest('.kk'); if (btn) { e.preventDefault(); doBtn(btn); } }); popup.addEventListener('touchend', e => { const btn = e.target.closest('.kk'); if (btn) { e.preventDefault(); doBtn(btn); } }); /* Tabs */ popup.querySelectorAll('.ka-tab').forEach(t => { t.addEventListener('click', () => { popup.querySelectorAll('.ka-tab').forEach(x => x.classList.remove('active')); popup.querySelectorAll('.ka-panel').forEach(x => x.classList.remove('active')); t.classList.add('active'); document.getElementById(t.dataset.panel).classList.add('active'); }); }); /* ── Gestion popup ── */ function openFor(triggerBtn) { const answerId = triggerBtn.dataset.target; const latexId = triggerBtn.dataset.latex; /* Sauvegarder l'état du champ actif AVANT de changer */ if (activeAnswerEl) { fieldStates.set(activeAnswerEl.id, { root, path }); } activeAnswerEl = document.getElementById(answerId); activeLatexInput = document.getElementById(latexId); /* Restaurer l'état sauvegardé pour ce champ, ou repartir de zéro */ if (fieldStates.has(answerId)) { const saved = fieldStates.get(answerId); root = saved.root; path = saved.path; } else { root = mk(); path = [root]; } popup.style.width = '300px'; popup.style.height = ''; /* Rendre visible hors-écran pour mesurer la hauteur réelle */ popup.style.visibility = 'hidden'; popup.classList.add('visible'); popup.style.transform = 'none'; const ph = popup.offsetHeight; const pw = 300; const gap = 8; popup.style.visibility = ''; const tr = triggerBtn.getBoundingClientRect(); /* ── Horizontale : rester dans l'écran ── */ let left = tr.left; if (left + pw > window.innerWidth - 4) left = window.innerWidth - pw - 4; if (left < 4) left = 4; /* ── Verticale : dessous si assez de place, sinon dessus ── */ const spaceBelow = window.innerHeight - tr.bottom; const spaceAbove = tr.top; let top, openAbove; if (spaceBelow >= ph + gap || spaceBelow >= spaceAbove) { top = tr.bottom + gap; openAbove = false; } else { top = tr.top - ph - gap; openAbove = true; } /* Sécurité : ne pas sortir au-dessus de l'écran */ if (top < 4) top = 4; popup.style.left = left + 'px'; popup.style.top = top + 'px'; /* Inverser la flèche décorative selon la position */ popup.classList.toggle('ka-above', openAbove); document.querySelectorAll('.math-answer').forEach(el => { el.classList.remove('focused'); el.classList.add('ka-cursor-off'); // fige les autres champs }); activeAnswerEl.classList.add('focused'); activeAnswerEl.classList.remove('ka-cursor-off'); // ← réactive le curseur du champ actif upd(); } function closePop() { /* Sauvegarder l'état du champ actif avant fermeture */ if (activeAnswerEl) { fieldStates.set(activeAnswerEl.id, { root, path }); } popup.classList.remove('visible'); document.querySelectorAll('.ka-trigger').forEach(b => b.classList.remove('open')); document.querySelectorAll('.math-answer').forEach(el => { el.classList.remove('focused'); el.classList.add('ka-cursor-off'); }); } /* Délégation sur le document pour les boutons .ka-trigger (y compris ceux ajoutés dynamiquement) */ document.addEventListener('click', e => { const btn = e.target.closest('.ka-trigger'); if (btn) { e.stopPropagation(); if (popup.classList.contains('visible') && activeAnswerEl?.id === btn.dataset.target) { closePop(); } else { document.querySelectorAll('.ka-trigger').forEach(b => b.classList.remove('open')); btn.classList.add('open'); openFor(btn); } return; } if (popup.classList.contains('visible') && !popup.contains(e.target)) closePop(); }); document.getElementById('ka-close').addEventListener('click', closePop); document.getElementById('ka-insert').addEventListener('click', closePop); document.getElementById('ka-clr').addEventListener('mousedown', e => { e.preventDefault(); root = mk(); path = [root]; if (activeAnswerEl) fieldStates.delete(activeAnswerEl.id); upd(); }); /* ── Drag ── */ (() => { const hdr = document.getElementById('ka-header'); let dr = false, ox = 0, oy = 0; hdr.addEventListener('mousedown', e => { if (e.target.closest('.ka-tab,.ka-close')) return; dr = true; const r = popup.getBoundingClientRect(); ox = e.clientX - r.left; oy = e.clientY - r.top; popup.style.transform = 'none'; e.preventDefault(); }); document.addEventListener('mousemove', e => { if (!dr) return; let nx = e.clientX - ox, ny = e.clientY - oy; nx = Math.max(0, Math.min(nx, window.innerWidth - popup.offsetWidth)); ny = Math.max(0, Math.min(ny, window.innerHeight - 40)); popup.style.left = nx + 'px'; popup.style.top = ny + 'px'; }); document.addEventListener('mouseup', () => { dr = false; }); hdr.addEventListener('touchstart', e => { if (e.target.closest('.ka-tab,.ka-close')) return; const t = e.touches[0], r = popup.getBoundingClientRect(); dr = true; ox = t.clientX - r.left; oy = t.clientY - r.top; }, { passive: true }); document.addEventListener('touchmove', e => { if (!dr) return; const t = e.touches[0]; let nx = t.clientX - ox, ny = t.clientY - oy; nx = Math.max(0, Math.min(nx, window.innerWidth - popup.offsetWidth)); ny = Math.max(0, Math.min(ny, window.innerHeight - 40)); popup.style.left = nx + 'px'; popup.style.top = ny + 'px'; }, { passive: true }); document.addEventListener('touchend', () => { dr = false; }); })(); /* ── Resize ── */ (() => { let rz = false, dir = '', sx = 0, sy = 0, sw = 0, sh = 0, sl = 0, st = 0; const MW = 220, MH = 150; popup.querySelectorAll('.rh').forEach(h => { h.addEventListener('mousedown', e => { rz = true; dir = h.dataset.dir; sx = e.clientX; sy = e.clientY; const r = popup.getBoundingClientRect(); sw = r.width; sh = r.height; sl = r.left; st = r.top; popup.style.transform = 'none'; e.preventDefault(); e.stopPropagation(); }); }); document.addEventListener('mousemove', e => { if (!rz) return; const dx = e.clientX - sx, dy = e.clientY - sy; let nw = sw, nh = sh, nl = sl, nt = st; if (dir.includes('e')) nw = Math.max(MW, sw + dx); if (dir.includes('w')) { nw = Math.max(MW, sw - dx); if (nw > MW) nl = sl + dx; } if (dir.includes('s')) nh = Math.max(MH, sh + dy); if (dir.includes('n')) { nh = Math.max(MH, sh - dy); if (nh > MH) nt = st + dy; } popup.style.width = nw + 'px'; popup.style.height = nh + 'px'; popup.style.left = nl + 'px'; popup.style.top = nt + 'px'; }); document.addEventListener('mouseup', () => { rz = false; }); })(); /* ── Raccourcis clavier ── */ document.addEventListener('keydown', e => { if (!popup.classList.contains('visible')) return; if (['INPUT', 'TEXTAREA'].includes(e.target.tagName)) return; if (e.key === 'Escape') { closePop(); return; } if (e.key === 'Backspace') { e.preventDefault(); bs(); return; } if (e.key === 'ArrowLeft') { e.preventDefault(); mvL(); return; } if (e.key === 'ArrowRight') { e.preventDefault(); mvR(); return; } if (e.key === 'Tab') { e.preventDefault(); exit(); return; } if (e.key === 'Enter') { e.preventDefault(); closePop(); return; } if (e.ctrlKey && e.key === '/') { e.preventDefault(); ins(T.frac()); return; } if (e.key === '^' && !e.ctrlKey) { e.preventDefault(); const g = cur(), base = mk(); if (g.cursor > 0) { const p = g.tokens.splice(g.cursor - 1, 1)[0]; g.cursor--; base.tokens.push(p); base.cursor = 1; } ins(T.pow(base)); return; } if (e.key.length === 1 && !e.ctrlKey && !e.altKey) ins(T.ch(e.key)); }); upd(); } /* ── Lancement ── */ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();