| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| const TYPE_LABELS = { |
| spelling: 'إملائي', |
| grammar: 'نحوي', |
| punctuation: 'ترقيم', |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| function resolveAlternatives(suggestion) { |
| return suggestion.alternatives && suggestion.alternatives.length > 0 |
| ? suggestion.alternatives |
| : [suggestion.correction, suggestion.original]; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function calculateWritingScore(spelling, grammar, punctuation) { |
| const score = 100 - spelling * 8 - grammar * 6 - punctuation * 3; |
| return Math.max(0, Math.min(100, score)); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| function buildSuggestionCardHTML(suggestion, index) { |
| const badgeClass = `bayan-badge-${suggestion.type}`; |
| const label = TYPE_LABELS[suggestion.type] || suggestion.type; |
| const alts = resolveAlternatives(suggestion); |
| const suggestionId = suggestion.id || index; |
|
|
| let altsHTML = ''; |
| alts.forEach((alt, i) => { |
| const isKeep = alt === suggestion.original; |
| const isMain = i === 0; |
| const cls = isKeep |
| ? 'bayan-alt-chip bayan-alt-chip--keep' |
| : isMain |
| ? 'bayan-alt-chip bayan-alt-chip--main' |
| : 'bayan-alt-chip'; |
| const chipLabel = isKeep ? `${escapeHtml(alt)} ✓` : escapeHtml(alt); |
| altsHTML += `<button class="${cls}" data-card-alt="${escapeHtml(alt)}" data-card-id="${suggestionId}" type="button">${chipLabel}</button>`; |
| }); |
|
|
| return ` |
| <div class="bayan-suggestion-card" role="listitem" tabindex="0" |
| data-suggestion-id="${suggestionId}" |
| aria-label="${label}: ${escapeHtml(suggestion.original)} إلى ${escapeHtml(suggestion.correction)}"> |
| <span class="bayan-suggestion-badge ${badgeClass}">${label}</span> |
| <div class="bayan-suggestion-change"> |
| <span class="bayan-suggestion-original">${escapeHtml(suggestion.original)}</span> |
| <span class="bayan-suggestion-arrow">←</span> |
| <span class="bayan-suggestion-correction">${escapeHtml(suggestion.correction)}</span> |
| </div> |
| <div class="bayan-suggestion-alts">${altsHTML}</div> |
| </div>`; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function getScoreHint(score, total) { |
| if (total === 0) return 'ابدأ الكتابة لرؤية تقييمك'; |
| if (score >= 90) return 'كتابة ممتازة! استمر.'; |
| if (score >= 70) return 'جيد — راجع الاقتراحات لتحسين النص.'; |
| return 'يحتاج النص إلى بعض التحسينات.'; |
| } |
|
|