Skip to content

[Feature] #5091

Closed as not planned
Closed as not planned

Description

@omare75777-hue

Problem

l

Proposed solution

<title>السبورة الذكية الاحترافية الشاملة - Pro Board</title> <script src="https://cdn.tailwindcss.com"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> <style> Import (A place for python bower components) (@import) url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap'); body { font-family: 'Cairo', sans-serif; } .canvas-container { cursor: crosshair; } .tool-btn.active { apply bg-blue-600 text-white shadow-lg scale-105; } </style>
<!-- الشريط العلوي (Top Header) -->
<header class="bg-slate-900 text-white px-6 py-3 flex justify-between items-center shadow-lg z-20">
    <div class="flex items-center space-x-3 space-x-reverse">
        <i class="fa-solid fa-graduation-cap text-2xl text-blue-400"></i>
        <h1 class="text-xl font-bold">السبورة الذكية الاحترافية</h1>
    </div>

    <!-- خيارات التحكم والتصدير -->
    <div class="flex items-center gap-2">
        <button id="btnUndo" title="تراجع" class="bg-slate-800 hover:bg-slate-700 px-3 py-2 rounded-lg text-sm transition">
            <i class="fa-solid fa-rotate-left ml-1"></i> تراجع
        </button>
        <button id="btnRedo" title="إعادة" class="bg-slate-800 hover:bg-slate-700 px-3 py-2 rounded-lg text-sm transition">
            <i class="fa-solid fa-rotate-right ml-1"></i> إعادة
        </button>
        <div class="h-6 w-px bg-slate-700 mx-1"></div>
        <button id="btnClear" title="مسح اللوحة" class="bg-red-600 hover:bg-red-700 px-3 py-2 rounded-lg text-sm transition">
            <i class="fa-solid fa-trash ml-1"></i> مسح
        </button>
        
        <!-- قائمة تصدير الملفات -->
        <div class="relative inline-block text-left">
            <button id="btnExportMenu" class="bg-emerald-600 hover:bg-emerald-700 px-4 py-2 rounded-lg text-sm font-semibold transition flex items-center">
                <i class="fa-solid fa-download ml-1"></i> تصدير <i class="fa-solid fa-chevron-down mr-2 text-xs"></i>
            </button>
        </div>
    </div>
</header>

<!-- منطقة العمل الرئيسية -->
<div class="flex flex-1 relative overflow-hidden">
    
    <!-- شريط الأدوات الجانبي (الأدوات والهندسة) -->
    <aside class="w-20 bg-white border-l border-gray-200 flex flex-col items-center py-4 gap-3 shadow-sm z-10 overflow-y-auto">
        <button id="toolPen" class="tool-btn active w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="قلم">
            <i class="fa-solid fa-pen text-lg"></i>
            <span class="text-[10px] mt-1">قلم</span>
        </button>
        
        <button id="toolHighlighter" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="محدد">
            <i class="fa-solid fa-highlighter text-lg text-yellow-500"></i>
            <span class="text-[10px] mt-1">تحديد</span>
        </button>

        <button id="toolEraser" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="ممحاة">
            <i class="fa-solid fa-eraser text-lg"></i>
            <span class="text-[10px] mt-1">ممحاة</span>
        </button>

        <hr class="w-8 border-gray-200 my-1">

        <!-- أدوات الأشكال والخطوط -->
        <button id="toolLine" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="خط مستقيم">
            <i class="fa-solid fa-slash text-lg"></i>
            <span class="text-[10px] mt-1">خط</span>
        </button>

        <button id="toolArrow" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="سهم">
            <i class="fa-solid fa-arrow-right-long text-lg"></i>
            <span class="text-[10px] mt-1">سهم</span>
        </button>

        <button id="toolDotted" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="خط منقط">
            <i class="fa-solid fa-ellipsis text-lg"></i>
            <span class="text-[10px] mt-1">منقط</span>
        </button>

        <button id="toolRect" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="مستطيل">
            <i class="fa-regular fa-square text-lg"></i>
            <span class="text-[10px] mt-1">مستطيل</span>
        </button>

        <button id="toolCircle" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="دائرة">
            <i class="fa-regular fa-circle text-lg"></i>
            <span class="text-[10px] mt-1">دائرة</span>
        </button>
    </aside>

    <!-- لوحة الرسم الرسمية -->
    <main class="flex-1 relative bg-white canvas-container">
        <canvas id="whiteboardCanvas" class="w-full h-full block"></canvas>
    </main>

    <!-- لوحة التحكم الجانبية (الألوان والسمك والتصدير) -->
    <aside class="w-64 bg-white border-r border-gray-200 p-4 flex flex-col gap-5 shadow-sm z-10">
        
        <!-- الألوان -->
        <div>
            <h3 class="text-xs font-bold text-gray-500 uppercase mb-2">الألوان الأساسية</h3>
            <div class="grid grid-cols-4 gap-2">
                <button class="color-btn w-8 h-8 rounded-full bg-black ring-2 ring-blue-500" data-color="#000000"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-red-600" data-color="#dc2626"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-blue-600" data-color="#2563eb"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-green-600" data-color="#16a34a"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-yellow-400" data-color="#facc15"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-purple-600" data-color="#9333ea"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-orange-500" data-color="#f97316"></button>
                <input type="color" id="customColor" class="w-8 h-8 rounded-full border-none cursor-pointer bg-transparent">
            </div>
        </div>

        <!-- السمك -->
        <div>
            <div class="flex justify-between items-center mb-1">
                <label class="text-xs font-bold text-gray-500 uppercase">حجم الخط / الممحاة</label>
                <span id="sizeVal" class="text-xs font-bold text-blue-600">4px</span>
            </div>
            <input type="range" id="sizeInput" min="1" max="50" value="4" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
        </div>

        <!-- خيارات حفظ وتصدير الملفات -->
        <div class="mt-auto border-t border-gray-100 pt-4">
            <h3 class="text-xs font-bold text-gray-500 uppercase mb-3">حفظ وتصدير العمل</h3>
            <div class="flex flex-col gap-2">
                <button id="exportPNG" class="w-full bg-slate-100 hover:bg-slate-200 text-slate-800 text-xs py-2 rounded-lg font-semibold transition flex items-center justify-center">
                    <i class="fa-regular fa-image ml-2"></i> تصدير بصيغة PNG
                </button>
                <button id="exportPDF" class="w-full bg-slate-100 hover:bg-slate-200 text-slate-800 text-xs py-2 rounded-lg font-semibold transition flex items-center justify-center">
                    <i class="fa-regular fa-file-pdf ml-2"></i> تصدير كمستند PDF
                </button>
            </div>
        </div>
    </aside>
</div>

<script>
    // إعدادات الكانفاس المحسنة
    const canvas = document.getElementById('whiteboardCanvas');
    const ctx = canvas.getContext('2d');

    let isDrawing = false;
    let currentTool = 'pen';
    let currentColor = '#000000';
    let currentSize = 4;
    let startX = 0, startY = 0;

    const undoStack = [];
    const redoStack = [];

    function initCanvas() {
        canvas.width = canvas.parentElement.clientWidth;
        canvas.height = canvas.parentElement.clientHeight;
        ctx.fillStyle = '#FFFFFF';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
    }

    function saveState() {
        if (undoStack.length > 25) undoStack.shift();
        undoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
        redoStack.length = 0;
    }

    function getPos(e) {
        const rect = canvas.getBoundingClientRect();
        const clientX = e.touches ? e.touches[0].clientX : e.clientX;
        const clientY = e.touches ? e.touches[0].clientY : e.clientY;
        return { x: clientX - rect.left, y: clientY - rect.top };
    }

    function start(e) {
        isDrawing = true;
        saveState();
        const pos = getPos(e);
        startX = pos.x;
        startY = pos.y;
        ctx.beginPath();
        ctx.moveTo(startX, startY);
    }

    function draw(e) {
        if (!isDrawing) return;
        const pos = getPos(e);

        ctx.lineWidth = currentSize;
        ctx.lineCap = 'round';
        ctx.lineJoin = 'round';

        if (currentTool === 'pen') {
            ctx.strokeStyle = currentColor;
            ctx.globalAlpha = 1.0;
            ctx.setLineDash([]);
            ctx.lineTo(pos.x, pos.y);
            ctx.stroke();
        } else if (currentTool === 'highlighter') {
            ctx.strokeStyle = currentColor;
            ctx.globalAlpha = 0.3;
            ctx.setLineDash([]);
            ctx.lineTo(pos.x, pos.y);
            ctx.stroke();
        } else if (currentTool === 'eraser') {
            ctx.strokeStyle = '#FFFFFF';
            ctx.globalAlpha = 1.0;
            ctx.setLineDash([]);
            ctx.lineTo(pos.x, pos.y);
            ctx.stroke();
        } else if (['line', 'arrow', 'dotted', 'rect', 'circle'].includes(currentTool)) {
            ctx.putImageData(undoStack[undoStack.length - 1], 0, 0);
            ctx.strokeStyle = currentColor;
            ctx.globalAlpha = 1.0;
            ctx.beginPath();

            if (currentTool === 'line') {
                ctx.setLineDash([]);
                ctx.moveTo(startX, startY);
                ctx.lineTo(pos.x, pos.y);
            } else if (currentTool === 'dotted') {
                ctx.setLineDash([6, 6]);
                ctx.moveTo(startX, startY);
                ctx.lineTo(pos.x, pos.y);
            } else if (currentTool === 'arrow') {
                ctx.setLineDash([]);
                ctx.moveTo(startX, startY);
                ctx.lineTo(pos.x, pos.y);
                // رسم رأس السهم
                const angle = Math.atan2(pos.y - startY, pos.x - startX);
                ctx.lineTo(pos.x - 15 * Math.cos(angle - Math.PI / 6), pos.y - 15 * Math.sin(angle - Math.PI / 6));
                ctx.moveTo(pos.x, pos.y);
                ctx.lineTo(pos.x - 15 * Math.cos(angle + Math.PI / 6), pos.y - 15 * Math.sin(angle + Math.PI / 6));
            } else if (currentTool === 'rect') {
                ctx.setLineDash([]);
                ctx.strokeRect(startX, startY, pos.x - startX, pos.y - startY);
            } else if (currentTool === 'circle') {
                ctx.setLineDash([]);
                const r = Math.sqrt(Math.pow(pos.x - startX, 2) + Math.pow(pos.y - startY, 2));
                ctx.arc(startX, startY, r, 0, 2 * Math.PI);
            }
            ctx.stroke();
        }
    }

    function stop() {
        isDrawing = false;
    }

    // أحداث اللوحة
    window.addEventListener('resize', initCanvas);
    canvas.addEventListener('mousedown', start);
    canvas.addEventListener('mousemove', draw);
    canvas.addEventListener('mouseup', stop);
    canvas.addEventListener('touchstart', (e) => { e.preventDefault(); start(e); });
    canvas.addEventListener('touchmove', (e) => { e.preventDefault(); draw(e); });
    canvas.addEventListener('touchend', stop);

    // ربط الأدوات
    const tools = ['toolPen', 'toolHighlighter', 'toolEraser', 'toolLine', 'toolArrow', 'toolDotted', 'toolRect', 'toolCircle'];
    tools.forEach(id => {
        document.getElementById(id).addEventListener('click', (e) => {
            document.querySelectorAll('.tool-btn').forEach(btn => btn.classList.remove('active'));
            const target = e.currentTarget;
            target.classList.add('active');
            currentTool = id.replace('tool', '').toLowerCase();
        });
    });

    // اختيار الألوان والسمك
    document.querySelectorAll('.color-btn').forEach(btn => {
        btn.addEventListener('click', () => {
            currentColor = btn.getAttribute('data-color');
        });
    });
    document.getElementById('customColor').addEventListener('input', (e) => currentColor = e.target.value);
    document.getElementById('sizeInput').addEventListener('input', (e) => {
        currentSize = e.target.value;
        document.getElementById('sizeVal').innerText = `${currentSize}px`;
    });

    // التراجع والإعادة والمسح
    document.getElementById('btnUndo').addEventListener('click', () => {
        if (undoStack.length > 0) {
            redoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
            ctx.putImageData(undoStack.pop(), 0, 0);
        }
    });
    document.getElementById('btnRedo').addEventListener('click', () => {
        if (redoStack.length > 0) {
            undoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
            ctx.putImageData(redoStack.pop(), 0, 0);
        }
    });
    document.getElementById('btnClear').addEventListener('click', () => {
        saveState();
        ctx.fillStyle = '#FFFFFF';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
    });

    // التصدير إلى صورة PNG
    document.getElementById('exportPNG').addEventListener('click', () => {
        const link = document.createElement('a');
        link.download = `whiteboard-${Date.now()}.png`;
        link.href = canvas.toDataURL();
        link.click();
    });

    // التصدير إلى PDF
    document.getElementById('exportPDF').addEventListener('click', () => {
        const { jsPDF } = window.jspdf;
        const pdf = new jsPDF('landscape');
        const imgData = canvas.toDataURL('image/png');
        pdf.addImage(imgData, 'PNG', 10, 10, 270, 180);
        pdf.save(`whiteboard-${Date.now()}.pdf`);
    });

    // بدء التشغيل
    initCanvas();
</script>

Alternatives considered

No response

Additional context

<title>السبورة الذكية الاحترافية الشاملة - Pro Board</title> <script src="https://cdn.tailwindcss.com"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> <style> Import (A place for python bower components) (@import) url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap'); body { font-family: 'Cairo', sans-serif; } .canvas-container { cursor: crosshair; } .tool-btn.active { apply bg-blue-600 text-white shadow-lg scale-105; } </style>
<!-- الشريط العلوي (Top Header) -->
<header class="bg-slate-900 text-white px-6 py-3 flex justify-between items-center shadow-lg z-20">
    <div class="flex items-center space-x-3 space-x-reverse">
        <i class="fa-solid fa-graduation-cap text-2xl text-blue-400"></i>
        <h1 class="text-xl font-bold">السبورة الذكية الاحترافية</h1>
    </div>

    <!-- خيارات التحكم والتصدير -->
    <div class="flex items-center gap-2">
        <button id="btnUndo" title="تراجع" class="bg-slate-800 hover:bg-slate-700 px-3 py-2 rounded-lg text-sm transition">
            <i class="fa-solid fa-rotate-left ml-1"></i> تراجع
        </button>
        <button id="btnRedo" title="إعادة" class="bg-slate-800 hover:bg-slate-700 px-3 py-2 rounded-lg text-sm transition">
            <i class="fa-solid fa-rotate-right ml-1"></i> إعادة
        </button>
        <div class="h-6 w-px bg-slate-700 mx-1"></div>
        <button id="btnClear" title="مسح اللوحة" class="bg-red-600 hover:bg-red-700 px-3 py-2 rounded-lg text-sm transition">
            <i class="fa-solid fa-trash ml-1"></i> مسح
        </button>
        
        <!-- قائمة تصدير الملفات -->
        <div class="relative inline-block text-left">
            <button id="btnExportMenu" class="bg-emerald-600 hover:bg-emerald-700 px-4 py-2 rounded-lg text-sm font-semibold transition flex items-center">
                <i class="fa-solid fa-download ml-1"></i> تصدير <i class="fa-solid fa-chevron-down mr-2 text-xs"></i>
            </button>
        </div>
    </div>
</header>

<!-- منطقة العمل الرئيسية -->
<div class="flex flex-1 relative overflow-hidden">
    
    <!-- شريط الأدوات الجانبي (الأدوات والهندسة) -->
    <aside class="w-20 bg-white border-l border-gray-200 flex flex-col items-center py-4 gap-3 shadow-sm z-10 overflow-y-auto">
        <button id="toolPen" class="tool-btn active w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="قلم">
            <i class="fa-solid fa-pen text-lg"></i>
            <span class="text-[10px] mt-1">قلم</span>
        </button>
        
        <button id="toolHighlighter" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="محدد">
            <i class="fa-solid fa-highlighter text-lg text-yellow-500"></i>
            <span class="text-[10px] mt-1">تحديد</span>
        </button>

        <button id="toolEraser" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="ممحاة">
            <i class="fa-solid fa-eraser text-lg"></i>
            <span class="text-[10px] mt-1">ممحاة</span>
        </button>

        <hr class="w-8 border-gray-200 my-1">

        <!-- أدوات الأشكال والخطوط -->
        <button id="toolLine" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="خط مستقيم">
            <i class="fa-solid fa-slash text-lg"></i>
            <span class="text-[10px] mt-1">خط</span>
        </button>

        <button id="toolArrow" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="سهم">
            <i class="fa-solid fa-arrow-right-long text-lg"></i>
            <span class="text-[10px] mt-1">سهم</span>
        </button>

        <button id="toolDotted" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="خط منقط">
            <i class="fa-solid fa-ellipsis text-lg"></i>
            <span class="text-[10px] mt-1">منقط</span>
        </button>

        <button id="toolRect" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="مستطيل">
            <i class="fa-regular fa-square text-lg"></i>
            <span class="text-[10px] mt-1">مستطيل</span>
        </button>

        <button id="toolCircle" class="tool-btn w-12 h-12 rounded-xl flex flex-col items-center justify-center text-gray-700 hover:bg-gray-100" title="دائرة">
            <i class="fa-regular fa-circle text-lg"></i>
            <span class="text-[10px] mt-1">دائرة</span>
        </button>
    </aside>

    <!-- لوحة الرسم الرسمية -->
    <main class="flex-1 relative bg-white canvas-container">
        <canvas id="whiteboardCanvas" class="w-full h-full block"></canvas>
    </main>

    <!-- لوحة التحكم الجانبية (الألوان والسمك والتصدير) -->
    <aside class="w-64 bg-white border-r border-gray-200 p-4 flex flex-col gap-5 shadow-sm z-10">
        
        <!-- الألوان -->
        <div>
            <h3 class="text-xs font-bold text-gray-500 uppercase mb-2">الألوان الأساسية</h3>
            <div class="grid grid-cols-4 gap-2">
                <button class="color-btn w-8 h-8 rounded-full bg-black ring-2 ring-blue-500" data-color="#000000"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-red-600" data-color="#dc2626"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-blue-600" data-color="#2563eb"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-green-600" data-color="#16a34a"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-yellow-400" data-color="#facc15"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-purple-600" data-color="#9333ea"></button>
                <button class="color-btn w-8 h-8 rounded-full bg-orange-500" data-color="#f97316"></button>
                <input type="color" id="customColor" class="w-8 h-8 rounded-full border-none cursor-pointer bg-transparent">
            </div>
        </div>

        <!-- السمك -->
        <div>
            <div class="flex justify-between items-center mb-1">
                <label class="text-xs font-bold text-gray-500 uppercase">حجم الخط / الممحاة</label>
                <span id="sizeVal" class="text-xs font-bold text-blue-600">4px</span>
            </div>
            <input type="range" id="sizeInput" min="1" max="50" value="4" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
        </div>

        <!-- خيارات حفظ وتصدير الملفات -->
        <div class="mt-auto border-t border-gray-100 pt-4">
            <h3 class="text-xs font-bold text-gray-500 uppercase mb-3">حفظ وتصدير العمل</h3>
            <div class="flex flex-col gap-2">
                <button id="exportPNG" class="w-full bg-slate-100 hover:bg-slate-200 text-slate-800 text-xs py-2 rounded-lg font-semibold transition flex items-center justify-center">
                    <i class="fa-regular fa-image ml-2"></i> تصدير بصيغة PNG
                </button>
                <button id="exportPDF" class="w-full bg-slate-100 hover:bg-slate-200 text-slate-800 text-xs py-2 rounded-lg font-semibold transition flex items-center justify-center">
                    <i class="fa-regular fa-file-pdf ml-2"></i> تصدير كمستند PDF
                </button>
            </div>
        </div>
    </aside>
</div>

<script>
    // إعدادات الكانفاس المحسنة
    const canvas = document.getElementById('whiteboardCanvas');
    const ctx = canvas.getContext('2d');

    let isDrawing = false;
    let currentTool = 'pen';
    let currentColor = '#000000';
    let currentSize = 4;
    let startX = 0, startY = 0;

    const undoStack = [];
    const redoStack = [];

    function initCanvas() {
        canvas.width = canvas.parentElement.clientWidth;
        canvas.height = canvas.parentElement.clientHeight;
        ctx.fillStyle = '#FFFFFF';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
    }

    function saveState() {
        if (undoStack.length > 25) undoStack.shift();
        undoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
        redoStack.length = 0;
    }

    function getPos(e) {
        const rect = canvas.getBoundingClientRect();
        const clientX = e.touches ? e.touches[0].clientX : e.clientX;
        const clientY = e.touches ? e.touches[0].clientY : e.clientY;
        return { x: clientX - rect.left, y: clientY - rect.top };
    }

    function start(e) {
        isDrawing = true;
        saveState();
        const pos = getPos(e);
        startX = pos.x;
        startY = pos.y;
        ctx.beginPath();
        ctx.moveTo(startX, startY);
    }

    function draw(e) {
        if (!isDrawing) return;
        const pos = getPos(e);

        ctx.lineWidth = currentSize;
        ctx.lineCap = 'round';
        ctx.lineJoin = 'round';

        if (currentTool === 'pen') {
            ctx.strokeStyle = currentColor;
            ctx.globalAlpha = 1.0;
            ctx.setLineDash([]);
            ctx.lineTo(pos.x, pos.y);
            ctx.stroke();
        } else if (currentTool === 'highlighter') {
            ctx.strokeStyle = currentColor;
            ctx.globalAlpha = 0.3;
            ctx.setLineDash([]);
            ctx.lineTo(pos.x, pos.y);
            ctx.stroke();
        } else if (currentTool === 'eraser') {
            ctx.strokeStyle = '#FFFFFF';
            ctx.globalAlpha = 1.0;
            ctx.setLineDash([]);
            ctx.lineTo(pos.x, pos.y);
            ctx.stroke();
        } else if (['line', 'arrow', 'dotted', 'rect', 'circle'].includes(currentTool)) {
            ctx.putImageData(undoStack[undoStack.length - 1], 0, 0);
            ctx.strokeStyle = currentColor;
            ctx.globalAlpha = 1.0;
            ctx.beginPath();

            if (currentTool === 'line') {
                ctx.setLineDash([]);
                ctx.moveTo(startX, startY);
                ctx.lineTo(pos.x, pos.y);
            } else if (currentTool === 'dotted') {
                ctx.setLineDash([6, 6]);
                ctx.moveTo(startX, startY);
                ctx.lineTo(pos.x, pos.y);
            } else if (currentTool === 'arrow') {
                ctx.setLineDash([]);
                ctx.moveTo(startX, startY);
                ctx.lineTo(pos.x, pos.y);
                // رسم رأس السهم
                const angle = Math.atan2(pos.y - startY, pos.x - startX);
                ctx.lineTo(pos.x - 15 * Math.cos(angle - Math.PI / 6), pos.y - 15 * Math.sin(angle - Math.PI / 6));
                ctx.moveTo(pos.x, pos.y);
                ctx.lineTo(pos.x - 15 * Math.cos(angle + Math.PI / 6), pos.y - 15 * Math.sin(angle + Math.PI / 6));
            } else if (currentTool === 'rect') {
                ctx.setLineDash([]);
                ctx.strokeRect(startX, startY, pos.x - startX, pos.y - startY);
            } else if (currentTool === 'circle') {
                ctx.setLineDash([]);
                const r = Math.sqrt(Math.pow(pos.x - startX, 2) + Math.pow(pos.y - startY, 2));
                ctx.arc(startX, startY, r, 0, 2 * Math.PI);
            }
            ctx.stroke();
        }
    }

    function stop() {
        isDrawing = false;
    }

    // أحداث اللوحة
    window.addEventListener('resize', initCanvas);
    canvas.addEventListener('mousedown', start);
    canvas.addEventListener('mousemove', draw);
    canvas.addEventListener('mouseup', stop);
    canvas.addEventListener('touchstart', (e) => { e.preventDefault(); start(e); });
    canvas.addEventListener('touchmove', (e) => { e.preventDefault(); draw(e); });
    canvas.addEventListener('touchend', stop);

    // ربط الأدوات
    const tools = ['toolPen', 'toolHighlighter', 'toolEraser', 'toolLine', 'toolArrow', 'toolDotted', 'toolRect', 'toolCircle'];
    tools.forEach(id => {
        document.getElementById(id).addEventListener('click', (e) => {
            document.querySelectorAll('.tool-btn').forEach(btn => btn.classList.remove('active'));
            const target = e.currentTarget;
            target.classList.add('active');
            currentTool = id.replace('tool', '').toLowerCase();
        });
    });

    // اختيار الألوان والسمك
    document.querySelectorAll('.color-btn').forEach(btn => {
        btn.addEventListener('click', () => {
            currentColor = btn.getAttribute('data-color');
        });
    });
    document.getElementById('customColor').addEventListener('input', (e) => currentColor = e.target.value);
    document.getElementById('sizeInput').addEventListener('input', (e) => {
        currentSize = e.target.value;
        document.getElementById('sizeVal').innerText = `${currentSize}px`;
    });

    // التراجع والإعادة والمسح
    document.getElementById('btnUndo').addEventListener('click', () => {
        if (undoStack.length > 0) {
            redoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
            ctx.putImageData(undoStack.pop(), 0, 0);
        }
    });
    document.getElementById('btnRedo').addEventListener('click', () => {
        if (redoStack.length > 0) {
            undoStack.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
            ctx.putImageData(redoStack.pop(), 0, 0);
        }
    });
    document.getElementById('btnClear').addEventListener('click', () => {
        saveState();
        ctx.fillStyle = '#FFFFFF';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
    });

    // التصدير إلى صورة PNG
    document.getElementById('exportPNG').addEventListener('click', () => {
        const link = document.createElement('a');
        link.download = `whiteboard-${Date.now()}.png`;
        link.href = canvas.toDataURL();
        link.click();
    });

    // التصدير إلى PDF
    document.getElementById('exportPDF').addEventListener('click', () => {
        const { jsPDF } = window.jspdf;
        const pdf = new jsPDF('landscape');
        const imgData = canvas.toDataURL('image/png');
        pdf.addImage(imgData, 'PNG', 10, 10, 270, 180);
        pdf.save(`whiteboard-${Date.now()}.pdf`);
    });

    // بدء التشغيل
    initCanvas();
</script>

Submission checks

  • I searched existing issues and did not find a duplicate.
  • This request is specifically about Microsoft Edge Tools for VS Code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions