Spaces:
Running
Running
Download index.html from danialagent/smart-clean-studio: direct link, hf CLI and curl.
- Browser
- Download file 53.5 kB
-
https://huggingface.co/spaces/danialagent/smart-clean-studio/resolve/main/index.html
- Command line
-
hf download hf://spaces/danialagent/smart-clean-studio/index.html
-
curl -L -o index.html https://huggingface.co/spaces/danialagent/smart-clean-studio/resolve/main/index.html
53.5 kB
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>نقشه خوانی معماری - برنامه حرفهای دسکتاپ</title>
<meta name="description" content="برنامه دسکتاپ حرفهای برای یادگیری نقشه خوانی و ترسیم معماری با ابزارهای کامل، درسهای مرحلهای و کتابخانه نمادها." />
<style>
:root{
--bg:#0f141a;
--panel:#141a22;
--panel-2:#0b1016;
--text:#e5e7eb;
--muted:#a1a7b3;
--primary:#3b82f6;
--primary-2:#2563eb;
--accent:#10b981;
--danger:#ef4444;
--warn:#f59e0b;
--border:#263041;
--card:#111827;
--shadow:0 10px 30px rgba(0,0,0,.35);
--radius:10px;
--grid:#1f2937;
--grid-major:#374151;
--accent-2:#06b6d4;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
margin:0;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", "IRANSans", "Vazirmatn", "Tahoma", sans-serif;
color:var(--text);
background:linear-gradient(180deg,#0a0f14,#0b1117 40%, #0c1219);
}
header{
display:flex;align-items:center;justify-content:space-between;
padding:12px 18px;border-bottom:1px solid var(--border);
background:rgba(13,19,26,.8);backdrop-filter:blur(10px);
position:sticky;top:0;z-index:10;
}
.brand{display:flex;align-items:center;gap:10px;font-weight:700}
.brand .logo{
width:36px;height:36px;border-radius:9px;
background:linear-gradient(135deg,var(--primary),var(--accent));
display:grid;place-items:center;color:white;font-weight:800;box-shadow:var(--shadow)
}
.brand small{display:block;color:var(--muted);font-weight:500}
.top-actions{display:flex;gap:10px;align-items:center}
.link{
color:var(--muted);text-decoration:none;padding:6px 10px;border-radius:8px;
}
.link:hover{background:var(--panel);color:var(--text)}
.btn{
background:var(--primary);border:none;color:white;border-radius:10px;
padding:8px 14px;font-weight:600;cursor:pointer;box-shadow:0 4px 12px rgba(59,130,246,.3)
}
.btn:hover{background:var(--primary-2)}
.btn.secondary{background:transparent;border:1px solid var(--border);color:var(--text)}
.btn.ghost{background:transparent;color:var(--text)}
.container{
display:grid;grid-template-columns:280px 1fr 320px;gap:0;min-height:calc(100vh - 60px)
}
aside{
border-left:1px solid var(--border);
background:linear-gradient(180deg,var(--panel),var(--panel-2));
overflow:auto;
}
.left{
border-left:none;border-right:1px solid var(--border)
}
.panel{padding:16px}
.panel h3{margin:0 0 10px 0;font-size:15px;color:#dbe2ea}
.panel .muted{color:var(--muted);font-size:13px;line-height:1.6}
.tools{
display:grid;grid-template-columns:repeat(3,1fr);gap:8px
}
.tool{
background:var(--card);border:1px solid var(--border);border-radius:10px;padding:10px;
display:flex;flex-direction:column;align-items:center;gap:6px;cursor:pointer;transition:.2s;
}
.tool.active{outline:2px solid var(--primary);border-color:transparent;background:linear-gradient(180deg,#122032,#0d1521)}
.tool:hover{transform:translateY(-2px)}
.tool svg{width:22px;height:22px}
.tool span{font-size:12px;color:#dbe2ea}
.layers{display:flex;flex-direction:column;gap:10px;margin-top:10px}
.layer{
display:flex;align-items:center;justify-content:space-between;padding:8px 10px;border:1px solid var(--border);border-radius:8px;background:#0d131b;
}
.layer .row{display:flex;align-items:center;gap:8px}
.layer input[type="checkbox"]{transform:scale(1.1)}
.canvas-wrap{
position:relative;display:flex;flex-direction:column;background:radial-gradient(circle at 20% 0%, #0e1723, #0c131b);
overflow:hidden;
}
.canvas-toolbar{
display:flex;align-items:center;gap:8px;padding:10px;border-bottom:1px solid var(--border);background:rgba(15,21,29,.7);backdrop-filter:blur(8px)
}
.group{display:flex;gap:8px;align-items:center}
.field{
display:flex;gap:6px;align-items:center;background:#0b1016;border:1px solid var(--border);padding:6px;border-radius:8px
}
.field input[type="color"]{border:none;background:transparent;width:30px;height:24px;padding:0}
.field input[type="number"], .field input[type="text"]{
width:70px;border:none;background:transparent;color:var(--text);text-align:center;padding:2px 4px
}
.prop-grid{
display:grid;grid-template-columns:1fr 1fr;gap:8px
}
.prop{
background:#0b1016;border:1px solid var(--border);padding:10px;border-radius:8px
}
.prop label{display:block;font-size:12px;color:var(--muted);margin-bottom:4px}
.prop input, .prop select{
width:100%;padding:6px;border-radius:8px;border:1px solid var(--border);background:#0a0f14;color:var(--text)
}
#canvas{
flex:1;background: #0a0f14;
width:100%;height:100%;cursor:crosshair;display:block;
}
.lessons{display:flex;flex-direction:column;gap:10px}
.lesson{
border:1px solid var(--border);border-radius:10px;padding:10px;background:#0c131b;cursor:pointer
}
.lesson.active{outline:2px solid var(--accent);border-color:transparent}
.lesson small{color:var(--muted)}
.status{
display:inline-flex;align-items:center;gap:6px;padding:2px 8px;border-radius:999px;font-size:12px;background:#0b1016;border:1px solid var(--border);color:var(--muted)
}
.status.done{background:rgba(16,185,129,.1);border-color:#134e4a;color:#34d399}
.legend{
display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin-top:10px
}
.legend .item{
border:1px solid var(--border);background:#0b1016;border-radius:10px;padding:10px;cursor:pointer
}
.footer{
padding:10px;border-top:1px solid var(--border);text-align:center;color:var(--muted);font-size:12px;background:rgba(11,16,22,.7)
}
.modal{
position:fixed;inset:0;background:rgba(0,0,0,.6);display:none;align-items:center;justify-content:center;z-index:1000
}
.modal.show{display:flex}
.modal-card{
width:min(900px,92vw);max-height:86vh;overflow:auto;background:linear-gradient(180deg,#0d1420,#0a0f14);
border:1px solid var(--border);border-radius:14px;box-shadow:var(--shadow);padding:18px
}
.modal-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}
.modal-body{display:flex;flex-direction:column;gap:12px}
.steps{display:flex;flex-direction:column;gap:12px}
.step{border:1px solid var(--border);background:#0b1016;border-radius:10px;padding:12px}
.step h4{margin:0 0 8px 0}
.check{
display:flex;align-items:center;gap:8px;margin-top:6px;color:var(--muted)
}
.kbd{
background:#0b1016;border:1px solid var(--border);padding:2px 6px;border-radius:6px;font-size:12px
}
.hint{
padding:8px;border-radius:8px;background:rgba(59,130,246,.08);border:1px dashed rgba(59,130,246,.4);color:#cfe1ff;font-size:13px
}
.hotkeys{
display:flex;flex-wrap:wrap;gap:8px;margin-top:8px
}
.pill{
display:inline-flex;gap:6px;align-items:center;background:#0b1016;border:1px solid var(--border);border-radius:999px;padding:6px 10px;font-size:12px;color:var(--muted)
}
.right .panel{height:calc(100vh - 60px);display:flex;flex-direction:column}
.panel-scroll{overflow:auto;flex:1}
.divider{height:1px;background:var(--border);margin:10px 0}
.badge{display:inline-flex;align-items:center;gap:6px;background:#0b1016;border:1px solid var(--border);padding:4px 8px;border-radius:8px;color:var(--muted);font-size:12px}
.danger{background:rgba(239,68,68,.1);border-color:#7f1d1d;color:#fecaca}
.success{background:rgba(16,185,129,.1);border-color:#134e4a;color:#d1fae5}
@media (max-width: 1100px){
.container{grid-template-columns:220px 1fr}
.right{display:none}
}
@media (max-width: 800px){
.container{grid-template-columns:1fr}
.left{display:none}
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="logo">N</div>
<div>
نقشه خوانی معماری - دسکتاپ
<small>یادگیری، تمرین و ترسیم حرفهای</small>
</div>
</div>
<div class="top-actions">
<a class="link" href="#" id="btn-help">راهنما</a>
<a class="link" href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" rel="noopener">Built with anycoder</a>
<button class="btn" id="btn-export">خروجی تصویر</button>
</div>
</header>
<div class="container">
<!-- Left Sidebar: Lessons & Tools -->
<aside class="left">
<div class="panel">
<h3>درسها</h3>
<div class="lessons" id="lessons"></div>
</div>
<div class="divider"></div>
<div class="panel">
<h3>ابزارها</h3>
<div class="tools" id="tools"></div>
<div class="divider"></div>
<h3>نمادها</h3>
<div class="legend" id="symbols"></div>
<div class="divider"></div>
<h3>لایهها</h3>
<div class="layers" id="layers"></div>
</div>
<div class="footer">© 2025 - برنامه حرفهای دسکتاپ برای نقشهخوانی معماری</div>
</aside>
<!-- Main Canvas -->
<main class="canvas-wrap">
<div class="canvas-toolbar">
<div class="group">
<div class="field">
<label style="font-size:12px;color:var(--muted)">رنگ خط</label>
<input type="color" id="strokeColor" value="#e5e7eb">
</div>
<div class="field">
<label style="font-size:12px;color:var(--muted)">رنگ پر</label>
<input type="color" id="fillColor" value="#00000000">
</div>
<div class="field">
<label style="font-size:12px;color:var(--muted)">ضخامت</label>
<input type="number" id="lineWidth" min="0.25" step="0.25" value="1.5">
</div>
<div class="field">
<label style="font-size:12px;color:var(--muted)">مقیاس نقشه</label>
<input type="text" id="mapScale" value="1:100" title="مقیاس نقشه">
</div>
<div class="field">
<label style="font-size:12px;color:var(--muted)">گام شبکه</label>
<input type="number" id="gridStep" min="2" step="1" value="10">
</div>
<div class="field">
<label style="font-size:12px;color:var(--muted)">خطوط اصلی هر</label>
<input type="number" id="majorEvery" min="2" step="1" value="5">
</div>
<div class="field">
<label style="font-size:12px;color:var(--muted)">ضربکلیک</label>
<input type="number" id="multiplier" min="0.5" step="0.5" value="1">
</div>
</div>
<div class="group">
<button class="btn secondary" id="btn-undo" title="Ctrl+Z">بازگردانی</button>
<button class="btn secondary" id="btn-redo" title="Ctrl+Y">حذف بازگردانی</button>
<button class="btn ghost" id="btn-clear">پاکسازی</button>
</div>
<div class="group" style="margin-inline-start:auto">
<div class="hotkeys">
<span class="pill"><span class="kbd">V</span>انتخاب</span>
<span class="pill"><span class="kbd">P</span> pan</span>
<span class="pill"><span class="kbd">+</span>/<span class="kbd">-</span> زوم</span>
<span class="pill"><span class="kbd">0</span> برگردان 100%</span>
<span class="pill"><span class="kbd">Ctrl+S</span> ذخیره</span>
</div>
</div>
</div>
<canvas id="canvas"></canvas>
</main>
<!-- Right Sidebar: Properties -->
<aside class="right">
<div class="panel">
<h3>ویژگیها</h3>
<div class="panel-scroll">
<div class="prop">
<label>عنوان پروژه</label>
<input type="text" id="projectTitle" placeholder="مثلاً: مجتمع مسکونی آفتاب">
</div>
<div class="prop-grid" style="margin-top:8px">
<div class="prop">
<label>گام شبکه (px)</label>
<input type="number" id="propGridStep" value="10" min="2">
</div>
<div class="prop">
<label>خطوط اصلی هر</label>
<input type="number" id="propMajorEvery" value="5" min="2">
</div>
<div class="prop">
<label>چرخش شبکه (درجه)</label>
<input type="number" id="propGridRot" value="0" step="1">
</div>
<div class="prop">
<label>چسبیدن به شبکه</label>
<select id="propSnap">
<option value="on">روشن</option>
<option value="off">خاموش</option>
</select>
</div>
</div>
<div class="divider"></div>
<h3>لایهها و کنترل</h3>
<div class="layers" id="rightLayers"></div>
<div class="group" style="margin-top:8px">
<button class="btn secondary" id="btn-add-layer">لایه جدید</button>
<button class="btn secondary" id="btn-del-layer">حذف لایه</button>
</div>
<div class="divider"></div>
<h3>برچسبها</h3>
<div class="prop">
<label>متن</label>
<input type="text" id="labelText" placeholder="مثال: اتاق خواب">
</div>
<div class="prop-grid" style="margin-top:8px">
<div class="prop">
<label>اندازه فونت</label>
<input type="number" id="labelSize" min="8" step="1" value="14">
</div>
<div class="prop">
<label>چرخش (درجه)</label>
<input type="number" id="labelRot" value="0" step="1">
</div>
</div>
<div class="divider"></div>
<h3>ابزار مکعب</h3>
<div class="prop-grid">
<div class="prop">
<label>ارتفاع (px)</label>
<input type="number" id="blockH" value="120">
</div>
<div class="prop">
<label>شیب سایه</label>
<input type="number" id="blockShadow" value="0.7" min="0" max="1" step="0.1">
</div>
</div>
<div class="divider"></div>
<h3>پروژه</h3>
<div class="group">
<button class="btn" id="btn-save">ذخیره (LocalStorage)</button>
<button class="btn secondary" id="btn-load">بارگذاری</button>
</div>
<div class="hint" style="margin-top:8px">
برای پشتیبانگیری، خروجی تصویر بگیرید یا پروژه را ذخیره کنید.
</div>
</div>
</div>
<div class="footer">برنامه حرفهای دسکتاپ برای یادگیری و ترسیم نقشههای معماری</div>
</aside>
</div>
<!-- Lesson Modal -->
<div class="modal" id="lessonModal" aria-hidden="true">
<div class="modal-card">
<div class="modal-header">
<h2 id="lessonTitle">درس</h2>
<div class="group">
<span id="lessonBadge" class="badge">پیشرفت: 0%</span>
<button class="btn ghost" id="btn-close-lesson">بستن</button>
</div>
</div>
<div class="modal-body">
<div id="lessonIntro" class="muted"></div>
<div class="steps" id="lessonSteps"></div>
<div class="divider"></div>
<div class="group">
<button class="btn" id="btn-lesson-prev">قبلی</button>
<button class="btn" id="btn-lesson-next">بعدی</button>
</div>
</div>
</div>
</div>
<!-- Help Modal -->
<div class="modal" id="helpModal" aria-hidden="true">
<div class="modal-card">
<div class="modal-header">
<h2>راهنمای کوتاه</h2>
<button class="btn ghost" id="btn-close-help">بستن</button>
</div>
<div class="modal-body">
<ul class="muted">
<li>ابزار V: انتخاب/جابجایی عناصر</li>
<li>ابزار P: حرکت بین نقشه (Pan) - یا نگه داشت Space</li>
<li>ابزارهای ترسیم: خط، مستطیل، دایره، پیکان، منحنی، مکعب، متن</li>
<li>زوم: کلیدهای + و -، برگرداندن به 100% با کلید 0</li>
<li>شبکه: مقدار گام و خطوط اصلی را از نوار ابزار تنظیم کنید</li>
<li>گامبندی با Shift: با نگه داشت Shift هنگام رسم، طولها به گامهای مشخص گره میخورند</li>
<li>لایهها: از سمت راست لایهها را مدیریت کنید و با دکمه «لایه جدید» بسازید</li>
<li>ضربکلیک: اندازهگذاری را در واحد نقشه ضرب میکند (مثلا 1:100 => 100)</li>
<li>ذخیره/بارگذاری: از LocalStorage مرورگر استفاده میشود</li>
</ul>
</div>
</div>
</div>
<script>
;(() => {
'use strict';
// Utilities
const $ = (sel, el=document) => el.querySelector(sel);
const $$ = (sel, el=document) => Array.from(el.querySelectorAll(sel));
const uid = (p='id') => p + '_' + Math.random().toString(36).slice(2,9);
const clamp = (v,min,max)=>Math.min(max,Math.max(min,v));
const deg2rad = d => d * Math.PI / 180;
const rad2deg = r => r * 180 / Math.PI;
// State
const state = {
tool: 'select',
stroke: '#e5e7eb',
fill: '#00000000',
lineWidth: 1.5,
currentLayer: 'اصلی',
layers: [
{id: uid('layer'), name: 'اصلی', visible: true, lock: false, entities: []}
],
snap: true,
grid: {
step: 10,
majorEvery: 5,
rotation: 0
},
zoom: 1,
pan: {x: 0, y: 0},
projectTitle: '',
multiplier: 1,
mapScale: '1:100',
history: [],
future: [],
selection: null,
dragging: false,
drawing: false,
start: {x:0,y:0},
temp: null,
doc: {
labels: [], // {id,text,x,y,size,rot,color,layer}
blocks: [], // {id,x,y,w,h,hPx,shadow,color,layer}
},
lessons: [
{
id:'l1',
title:'اصول نقشهخوانی و مقیاس',
intro:'در این درس با کلیات نقشهکشی، مقیاسها و گامبندی آشنا میشوید.',
steps:[
{title:'تنظیم مقیاس', text:'مقیاس نقشه را روی 1:100 قرار دهید.', check: s => s.mapScale === '1:100'},
{title:'گام شبکه', text:'گام شبکه را روی 10 و خطوط اصلی را هر 5 قرار دهید.', check: s => s.grid.step===10 && s.grid.majorEvery===5},
{title:'ضربکلیک', text:'ضربکلیک را روی 1 قرار دهید.', check: s => s.multiplier===1}
]
},
{
id:'l2',
title:'ترسیم خط و مستطیل',
intro:'یاد میگیرید که دیوارها را با خط/مستطیل و گامبندی دقیق رسم کنید.',
steps:[
{title:'ابزار خط', text:'ابزار خط را انتخاب کنید.', check: s => s.tool==='line'},
{title:'رسم دیوار', text:'با ابزار خط، یک خط افقی به طول 300 واحد رسم کنید. (Shift برای گامبندی)', check: s => hasEntityType(s,'line',300)},
{title:'مستطیل اتاق', text:'با ابزار مستطیل، یک اتاق 400x300 واحد رسم کنید.', check: s => hasEntityType(s,'rect',400,300)}
]
},
{
id:'l3',
title:'دایره، پیکان و منحنی',
intro:'آشنایی با پلهها، ستونها و مسیرها با دایره و منحنی، و جهتها با پیکان.',
steps:[
{title:'دایره', text:'با ابزار دایره، یک ستون دایرهای به قطر 50 رسم کنید.', check: s => hasEntityType(s,'circle',50)},
{title:'پیکان', text:'با ابزار پیکان، مسیر خروجی را مشخص کنید.', check: s => hasEntityType(s,'arrow')},
{title:'منحنی', text:'با ابزار منحنی، مسیر پیادهرو داخلی بکشید.', check: s => hasEntityType(s,'curve')}
]
},
{
id:'l4',
title:'اندازهگذاری و متن',
intro:'کار با اندازهگذاری و برچسبگذاری برای خوانایی حرفهای.',
steps:[
{title:'اندازهگذاری', text:'ابزار اندازهگذاری را انتخاب کنید.', check: s => s.tool==='dimension'},
{title:'افزودن متن', text:'یک متن با عنوان «اتاق نشیمن» اضافه کنید.', check: s => s.doc.labels.some(l => l.text.includes('اتاق'))}
]
},
{
id:'l5',
title:'ایزومتریک مکعب',
intro:'رسم سریع حجم ساختمان با ابزار مکعب ایزومتریک.',
steps:[
{title:'مکعب', text:'یک مکعب ایزومتریک با پایه 200x150 و ارتفاع 120 رسم کنید.', check: s => hasBlockSize(s,200,150,120)}
]
},
{
id:'l6',
title:'پروژه نهایی: پلان ۱ خوابه',
intro:'ترکیب همه مهارتها برای رسم یک پلان ساده.',
steps:[
{title:'اتاق اصلی', text:'اتاق اصلی 400x300', check: s => hasEntityType(s,'rect',400,300)},
{title:'آشپزخانه', text:'فضای آشپزخانه 250x200', check: s => hasEntityType(s,'rect',250,200)},
{title:'سرویس بهداشتی', text:'فضای سرویس 150x120', check: s => hasEntityType(s,'rect',150,120)},
{title:'ستون', text:'یک ستون دایرهای قطر 50', check: s => hasEntityType(s,'circle',50)},
{title:'برچسبها', text:'حداقل سه متن مختلف بگذارید.', check: s => s.doc.labels.length >= 3},
{title:'ایزومتریک', text:'یک حجم مکعب ایزومتریک رسم کنید.', check: s => s.doc.blocks.length >= 1}
]
}
],
currentLessonIndex: -1
};
// Canvas Setup
const canvas = $('#canvas');
const ctx = canvas.getContext('2d');
const DPR = window.devicePixelRatio || 1;
function resizeCanvas(){
const rect = canvas.getBoundingClientRect();
canvas.width = Math.floor(rect.width * DPR);
canvas.height = Math.floor(rect.height * DPR);
ctx.setTransform(DPR,0,0,DPR,0,0);
draw();
}
window.addEventListener('resize', resizeCanvas);
setTimeout(resizeCanvas, 0);
// Tool Icons (SVG)
const toolsConfig = [
{id:'select', label:'انتخاب', svg:'<svg viewBox="0 0 24 24"><path fill="currentColor" d="M12 2l3 7h7l-5.5 4.5L18 21l-6-4-6 4 1.5-7.5L2 9h7z"/></svg>'},
{id:'pan', label:'Pan', svg:'<svg viewBox="0 0 24 24"><path fill="currentColor" d="M12 2l4 4h-3v6h6v-3l4 4-4 4v-3h-6v6h3l-4 4-4-4h3v-6H6v3l-4-4 4-4v3h6V6H8z"/></svg>'},
{id:'line', label:'خط', svg:'<svg viewBox="0 0 24 24"><path stroke="currentColor" stroke-width="2" d="M4 20L20 4"/></svg>'},
{id:'rect', label:'مستطیل', svg:'<svg viewBox="0 0 24 24"><rect x="4" y="6" width="16" height="12" rx="2" stroke="currentColor" stroke-width="2" fill="none"/></svg>'},
{id:'circle', label:'دایره', svg:'<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="7" stroke="currentColor" stroke-width="2" fill="none"/></svg>'},
{id:'arrow', label:'پیکان', svg:'<svg viewBox="0 0 24 24"><path stroke="currentColor" stroke-width="2" d="M4 12h12"/><path fill="currentColor" d="M16 9l5 3-5 3z"/></svg>'},
{id:'curve', label:'منحنی', svg:'<svg viewBox="0 0 24 24"><path d="M4 18C8 8 16 8 20 18" stroke="currentColor" stroke-width="2" fill="none"/></svg>'},
{id:'dimension', label:'اندازه', svg:'<svg viewBox="0 0 24 24"><path d="M4 12h16" stroke="currentColor" stroke-width="2"/><path d="M8 9v6M16 9v6" stroke="currentColor" stroke-width="2"/></svg>'},
{id:'text', label:'متن', svg:'<svg viewBox="0 0 24 24"><path d="M4 6h16M12 6v12M6 18h12" stroke="currentColor" stroke-width="2"/></svg>'},
{id:'cube', label:'مکعب', svg:'<svg viewBox="0 0 24 24"><path d="M12 3l9 6-9 6-9-6zM3 9l9 6 9-6" stroke="currentColor" stroke-width="2" fill="none"/></svg>'}
];
// Entities Manager
function currentEntities(){
return state.layers.find(l => l.name===state.currentLayer)?.entities || [];
}
function setEntities(arr){
const layer = state.layers.find(l => l.name===state.currentLayer);
if(layer){ layer.entities = arr; }
}
function addEntity(ent){
const layer = state.layers.find(l => l.name===state.currentLayer);
if(layer){ layer.entities.push(ent); pushHistory(); draw(); }
}
function hasEntityType(s, type, w=0, h=0){
for(const L of s.layers){
for(const e of (L.entities||[])){
if(e.type===type){
if(type==='line' && Math.abs(e.w)>=w-1) return true;
if(type==='rect'){
if(w && Math.abs(e.w)>=w-1 && h && Math.abs(e.h)>=h-1) return true;
if(w && !h && Math.abs(e.w)>=w-1) return true;
}
if(type==='circle' && Math.abs(e.r*2)>=w-1) return true;
if(type==='arrow' || type==='curve') return true;
}
}
}
return false;
}
function hasBlockSize(s,w,h,hPx){
for(const b of s.doc.blocks){
if(b.w>=w-1 && b.h>=h-1 && Math.abs(b.hPx- hPx)<=1) return true;
}
return false;
}
// History
function snapshot(){
const snap = JSON.stringify(state.layers, (k,v) => (k==='entities'? v: v));
state.history.push(snap);
if(state.history.length>50) state.history.shift();
state.future.length = 0;
}
function pushHistory(){ snapshot(); }
function undo(){
if(state.history.length<2) return;
state.future.push(state.history.pop());
const prev = state.history[state.history.length-1];
restoreState(prev);
}
function redo(){
const next = state.future.pop();
if(next){ state.history.push(next); restoreState(next); }
}
function restoreState(json){
try{
const data = JSON.parse(json);
// shallow restore layers
data.forEach(L=>{
const target = state.layers.find(x=>x.name===L.name);
if(target){ target.entities = L.entities||[]; target.visible=L.visible; target.lock=L.lock; }
});
// doc restore might be missing; keep current doc
draw();
}catch(e){}
}
snapshot(); // initial
// Tools UI
const toolsDiv = $('#tools');
function renderTools(){
toolsDiv.innerHTML = '';
toolsConfig.forEach(t=>{
const div = document.createElement('div');
div.className = 'tool' + (state.tool===t.id?' active':'');
div.dataset.tool = t.id;
div.innerHTML = t.svg + '<span>'+t.label+'</span>';
div.addEventListener('click', ()=>{
setTool(t.id);
});
toolsDiv.appendChild(div);
});
}
function setTool(id){
state.tool = id;
renderTools();
const tt = $('#tools .tool.active');
if(tt) tt.classList.add('active');
draw();
}
renderTools();
// Layers UI
const leftLayers = $('#layers');
const rightLayers = $('#rightLayers');
function renderLayers(){
leftLayers.innerHTML = '';
rightLayers.innerHTML = '';
state.layers.forEach((layer, idx)=>{
const row = document.createElement('div');
row.className = 'layer';
const left = document.createElement('div'); left.className='row';
const cb = document.createElement('input'); cb.type='checkbox'; cb.checked = layer.visible;
cb.addEventListener('change', ()=>{ layer.visible = cb.checked; draw(); });
const name = document.createElement('strong'); name.textContent = layer.name;
if(layer.name===state.currentLayer) name.style.color = 'var(--accent)';
name.style.cursor='pointer';
name.addEventListener('click', ()=>{ state.currentLayer = layer.name; renderLayers(); });
left.appendChild(cb); left.appendChild(name);
const right = document.createElement('div'); right.className='row';
const lockBtn = document.createElement('button'); lockBtn.className='btn secondary'; lockBtn.textContent=layer.lock?'قفل':'باز';
lockBtn.addEventListener('click', ()=>{ layer.lock=!layer.lock; renderLayers(); });
row.appendChild(left); row.appendChild(lockBtn);
leftLayers.appendChild(row);
const row2 = document.createElement('div');
row2.className='layer';
const rleft = document.createElement('div'); rleft.className='row';
const rcb = document.createElement('input'); rcb.type='checkbox'; rcb.checked=layer.visible;
rcb.addEventListener('change', ()=>{ layer.visible=rcb.checked; draw(); });
const rname = document.createElement('strong'); rname.textContent=layer.name;
if(layer.name===state.currentLayer) rname.style.color='var(--accent)';
rname.addEventListener('click', ()=>{ state.currentLayer=layer.name; renderLayers(); });
rleft.appendChild(rcb); rleft.appendChild(rname);
const rright = document.createElement('div'); rright.className='row';
const setBtn = document.createElement('button'); setBtn.className='btn secondary'; setBtn.textContent='فعال';
setBtn.addEventListener('click', ()=>{ state.currentLayer=layer.name; renderLayers(); });
rright.appendChild(setBtn);
row2.appendChild(rleft); row2.appendChild(rright);
rightLayers.appendChild(row2);
});
}
renderLayers();
$('#btn-add-layer').addEventListener('click', ()=>{
const name = prompt('نام لایه جدید:', 'لایه '+(state.layers.length+1));
if(!name) return;
state.layers.push({id:uid('layer'), name, visible:true, lock:false, entities:[]});
renderLayers();
});
$('#btn-del-layer').addEventListener('click', ()=>{
if(state.layers.length<=1){ alert('حداقل یک لایه باقی بماند.'); return; }
if(!confirm('لایه جاری حذف شود؟')) return;
const idx = state.layers.findIndex(l=>l.name===state.currentLayer);
if(idx>=0){
state.layers.splice(idx,1);
state.currentLayer = state.layers[0].name;
renderLayers(); draw();
}
});
// Lessons UI
const lessonsDiv = $('#lessons');
function renderLessons(){
lessonsDiv.innerHTML = '';
state.lessons.forEach((ls, i)=>{
const div = document.createElement('div');
div.className = 'lesson'+(state.currentLessonIndex===i?' active':'');
div.innerHTML = `<strong>${ls.title}</strong><br><small>${ls.intro}</small>`;
div.addEventListener('click', ()=> openLesson(i));
lessonsDiv.appendChild(div);
});
}
renderLessons();
// Symbols UI
const symbolsDiv = $('#symbols');
const symbols = [
{name:'در', draw: (ctx,x,y,s)=>{ctx.save();ctx.translate(x,y);ctx.strokeStyle=state.stroke;ctx.lineWidth=1;ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(20*s,0);ctx.moveTo(10*s,-6*s);ctx.arc(10*s,0,6*s,0,Math.PI,true);ctx.stroke();ctx.restore();}},
{name:'پنجره', draw: (ctx,x,y,s)=>{ctx.save();ctx.translate(x,y);ctx.strokeStyle=state.stroke;ctx.lineWidth=1;ctx.beginPath();ctx.rect(0,-6*s,24*s,12*s);ctx.moveTo(8*s,-6*s);ctx.lineTo(8*s,6*s);ctx.moveTo(16*s,-6*s);ctx.lineTo(16*s,6*s);ctx.stroke();ctx.restore();}},
{name:'مبل', draw:(ctx,x,y,s)=>{ctx.save();ctx.translate(x,y);ctx.strokeStyle=state.stroke;ctx.lineWidth=1;ctx.strokeRect(-12*s,-8*s,24*s,16*s);ctx.strokeRect(-16*s,-10*s,32*s,6*s);ctx.strokeRect(-16*s,4*s,32*s,6*s);ctx.restore();}},
{name:'تخت', draw:(ctx,x,y,s)=>{ctx.save();ctx.translate(x,y);ctx.strokeStyle=state.stroke;ctx.lineWidth=1;ctx.strokeRect(-18*s,-12*s,36*s,24*s);ctx.moveTo(-18*s,-12*s);ctx.lineTo(-18*s,-16*s);ctx.strokeRect(-22*s,-16*s,8*s,8*s);ctx.strokeRect(14*s,-16*s,8*s,8*s);ctx.restore();}},
{name:'Stove', draw:(ctx,x,y,s)=>{ctx.save();ctx.translate(x,y);ctx.strokeStyle=state.stroke;ctx.lineWidth=1;ctx.strokeRect(-10*s,-10*s,20*s,20*s);ctx.beginPath();ctx.arc(-5*s,-5*s,2*s,0,Math.PI*2);ctx.arc(5*s,-5*s,2*s,0,Math.PI*2);ctx.arc(-5*s,5*s,2*s,0,Math.PI*2);ctx.arc(5*s,5*s,2*s,0,Math.PI*2);ctx.stroke();ctx.restore();}}
];
function renderSymbols(){
symbolsDiv.innerHTML = '';
symbols.forEach((sym, i)=>{
const div = document.createElement('div');
div.className = 'item';
div.innerHTML = `<div style="height:70px;display:grid;place-items:center;border:1px dashed var(--border);border-radius:8px;margin-bottom:6px" id="sym_${i}"></div><strong style="font-size:12px">${sym.name}</strong>`;
div.addEventListener('click', ()=>{
setTool('symbol');
state.currentSymbolIndex = i;
});
symbolsDiv.appendChild(div);
// draw preview
const holder = div.querySelector('div');
const c = document.createElement('canvas');
c.width = 70; c.height = 60; c.style.width='70px'; c.style.height='60px';
holder.appendChild(c);
const cx = c.getContext('2d');
sym.draw(cx, 35, 30, 1);
});
}
renderSymbols();
// Controls
$('#strokeColor').addEventListener('input', e=>{ state.stroke = e.target.value; draw(); });
$('#fillColor').addEventListener('input', e=>{ state.fill = e.target.value; draw(); });
$('#lineWidth').addEventListener('input', e=>{ state.lineWidth = parseFloat(e.target.value)||1; draw(); });
$('#mapScale').addEventListener('input', e=>{ state.mapScale = e.target.value || '1:100'; });
$('#gridStep').addEventListener('input', e=>{
state.grid.step = parseFloat(e.target.value)||10;
$('#propGridStep').value = state.grid.step;
draw();
});
$('#majorEvery').addEventListener('input', e=>{
state.grid.majorEvery = parseFloat(e.target.value)||5;
$('#propMajorEvery').value = state.grid.majorEvery;
draw();
});
$('#multiplier').addEventListener('input', e=>{ state.multiplier = parseFloat(e.target.value)||1; });
$('#propGridStep').addEventListener('input', e=>{
state.grid.step = parseFloat(e.target.value)||10;
$('#gridStep').value = state.grid.step;
draw();
});
$('#propMajorEvery').addEventListener('input', e=>{
state.grid.majorEvery = parseFloat(e.target.value)||5;
$('#majorEvery').value = state.grid.majorEvery;
draw();
});
$('#propGridRot').addEventListener('input', e=>{
state.grid.rotation = deg2rad(parseFloat(e.target.value)||0);
draw();
});
$('#propSnap').addEventListener('change', e=>{
state.snap = e.target.value === 'on';
});
$('#projectTitle').addEventListener('input', e=>{ state.projectTitle = e.target.value; });
$('#labelText').addEventListener('input', ()=>{});
$('#labelSize').addEventListener('input', ()=>{});
$('#labelRot').addEventListener('input', ()=>{});
$('#blockH').addEventListener('input', ()=>{});
$('#blockShadow').addEventListener('input', ()=>{});
$('#btn-undo').addEventListener('click', undo);
$('#btn-redo').addEventListener('click', redo);
$('#btn-clear').addEventListener('click', ()=>{
if(!confirm('همه عناصر لایه جاری پاک شود؟')) return;
const L = state.layers.find(l=>l.name===state.currentLayer);
if(L){ L.entities = []; pushHistory(); draw(); }
});
$('#btn-save').addEventListener('click', ()=>{
const save = JSON.stringify({state, doc: state.doc}, null, 0);
localStorage.setItem('archi_desktop_project', save);
alert('ذخیره شد (LocalStorage).');
});
$('#btn-load').addEventListener('click', ()=>{
const raw = localStorage.getItem('archi_desktop_project');
if(!raw){ alertNothingSaved(); return; }
try{
const obj = JSON.parse(raw);
Object.assign(state, obj.state);
state.doc = obj.doc || state.doc;
renderTools(); renderLayers(); renderLessons(); draw();
alert('بارگذاری شد.');
}catch(e){ alert('مشکل در بارگذاری.'); }
});
$('#btn-export').addEventListener('click', ()=>{
// create export of whole document
const off = document.createElement('canvas');
const W = 1600, H = 1000;
off.width = W; off.height = H;
const ox = off.getContext('2d');
// white background
ox.fillStyle = '#ffffff'; ox.fillRect(0,0,W,H);
// draw grid minimal? optional
// Render entities scaled to fit
const margin = 60;
const bounds = computeAllBounds();
let scale = 1;
if(bounds){
scale = Math.min((W - margin*2)/bounds.w, (H - margin*2)/bounds.h);
if(!isFinite(scale) || scale<=0) scale = 1;
}
// temporarily draw by shifting origin to bounds.min
ox.save();
ox.translate(margin, margin);
if(bounds) ox.translate(-bounds.minX, -bounds.minY);
ox.scale(scale, scale);
// draw all layers
for(const L of state.layers){
if(!L.visible) continue;
drawEntities(ox, L.entities, false);
}
// draw blocks
for(const b of state.doc.blocks){
drawBlock(ox, b, false);
}
ox.restore();
// download
off.toBlob(blob=>{
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = (state.projectTitle || 'project') + '.png';
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
});
});
$('#btn-help').addEventListener('click', (e)=>{ e.preventDefault(); openHelp(); });
function openHelp(){ $('#helpModal').classList.add('show'); }
$('#btn-close-help').addEventListener('click', ()=> $('#helpModal').classList.remove('show'));
// Keyboard
let spaceDown = false;
document.addEventListener('keydown', (e)=>{
if(e.code==='Space'){ spaceDown = true; if(state.tool!=='pan'){ state.tool='pan'; renderTools(); } e.preventDefault(); }
if(e.key==='v' || e.key==='V'){ setTool('select'); }
if(e.key==='p' || e.key==='P'){ setTool('pan'); }
if(e.key==='+'){ zoomAtCenter(1.1); }
if(e.key==='-'){ zoomAtCenter(1/1.1); }
if(e.key==='0'){ state.zoom=1; state.pan={x:0,y:0}; draw(); }
if(e.ctrlKey && e.key.toLowerCase()==='z'){ e.preventDefault(); undo(); }
if(e.ctrlKey && e.key.toLowerCase()==='y'){ e.preventDefault(); redo(); }
if(e.ctrlKey && e.key.toLowerCase()==='s'){ e.preventDefault(); $('#btn-save').click(); }
});
document.addEventListener('keyup', (e)=>{
if(e.code==='Space'){ spaceDown = false; if(state.tool==='pan'){ setTool('select'); } }
});
// Pointer handling
let pointerDown = false;
let last = {x:0,y:0};
canvas.addEventListener('pointerdown', (e)=>{
canvas.setPointerCapture(e.pointerId);
pointerDown = true;
const pt = screenToWorld(e);
last = pt;
state.start = pt;
if(state.tool==='pan'){
state.dragging = true;
}else if(state.tool==='select'){
const hit = hitTest(pt);
if(hit){
state.selection = hit;
state.dragging = true;
state.dragOffset = {dx: pt.x - hit.x, dy: pt.y - hit.y};
}else{
state.selection = null;
}
draw();
}else{
state.drawing = true;
state.temp = makeTempEntity(state.tool, pt);
draw();
}
});
canvas.addEventListener('pointermove', (e)=>{
const pt = screenToWorld(e);
if(pointerDown){
if(state.tool==='pan' || spaceDown){
const dx = pt.x - last.x;
const dy = pt.y - last.y;
state.pan.x += dx;
state.pan.y += dy;
draw();
}else if(state.tool==='select' && state.dragging && state.selection){
// move entity
const nx = pt.x - state.dragOffset.dx;
const ny = pt.y - state.dragOffset.dy;
moveEntity(state.selection, nx, ny);
draw();
}else if(state.drawing && state.temp){
updateTempEntity(state.temp, pt);
draw();
}
}
last = pt;
});
canvas.addEventListener('pointerup', (e)=>{
canvas.releasePointerCapture(e.pointerId);
pointerDown = false;
if(state.tool==='pan'){ state.dragging=false; }
if(state.tool==='select' && state.dragging){ state.dragging=false; pushHistory(); }
if(state.drawing){
finalizeTempEntity(state.temp);
state.temp = null;
state.drawing = false;
}
});
canvas.addEventListener('wheel', (e)=>{
e.preventDefault();
const delta = e.deltaY<0 ? 1.1 : 1/1.1;
const rect = canvas.getBoundingClientRect();
const cx = (e.clientX - rect.left);
const cy = (e.clientY - rect.top);
zoomAtPoint(delta, cx, cy);
}, {passive:false});
function zoomAtPoint(factor, sx, sy){
const before = screenToWorld({x: sx, y: sy});
state.zoom = clamp(state.zoom * factor, 0.2, 5);
const after = screenToWorld({x: sx, y: sy});
state.pan.x += (after.x - before.x);
state.pan.y += (after.y - before.y);
draw();
}
function zoomAtCenter(f){
zoomAtPoint(f, canvas.clientWidth/2, canvas.clientHeight/2);
}
function screenToWorld(pt){
const rect = canvas.getBoundingClientRect();
const x = (pt.x - rect.left) / state.zoom - state.pan.x;
const y = (pt.y - rect.top) / state.zoom - state.pan.y;
// rotate grid?
// world positions not rotated, grid draws rotated only
return {x, y};
}
// Drawing
function draw(){
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.save();
ctx.scale(state.zoom, state.zoom);
ctx.translate(state.pan.x, state.pan.y);
drawGrid(ctx);
drawAll(ctx);
drawSelection(ctx);
drawTemp(ctx);
ctx.restore();
renderTools();
renderLayers();
}
function drawAll(ctx2){
for(const L of state.layers){
if(!L.visible) continue;
drawEntities(ctx2, L.entities, true);
}
// blocks and labels (global)
for(const b of state.doc.blocks) drawBlock(ctx2, b, true);
for(const lb of state.doc.labels) drawLabel(ctx2, lb, true);
}
function drawEntities(ctx2, ents, useStroke=true){
for(const e of ents){
ctx2.save();
ctx2.lineWidth = e.lineWidth || state.lineWidth;
ctx2.strokeStyle = e.color || state.stroke;
ctx2.fillStyle = e.fill || 'transparent';
if(useStroke) ctx2.strokeStyle = e.color || state.stroke;
if(e.type==='line' || e.type==='arrow'){
ctx2.beginPath();
ctx2.moveTo(e.x, e.y);
ctx2.lineTo(e.x+e.w, e.y+e.h);
if(e.type==='arrow'){
drawArrowHead(ctx2, e.x+e.w, e.y+e.h, Math.atan2(e.h, e.w), 8, e.color||state.stroke);
}
ctx2.stroke();
}else if(e.type==='rect'){
ctx2.beginPath();
ctx2.rect(e.x, e.y, e.w, e.h);
ctx2.fill();
ctx2.stroke();
}else if(e.type==='circle'){
ctx2.beginPath();
ctx2.arc(e.x, e.y, e.r, 0, Math.PI*2);
ctx2.fill(); ctx2.stroke();
}else if(e.type==='curve'){
ctx2.beginPath();
ctx2.moveTo(e.x, e.y);
ctx2.quadraticCurveTo(e.cx, e.cy, e.x+e.w, e.y+e.h);
ctx2.stroke();
}else if(e.type==='dimension'){
ctx2.beginPath();
ctx2.moveTo(e.x, e.y);
ctx2.lineTo(e.x+e.w, e.y);
ctx2.moveTo(e.x, e.y-8); ctx2.lineTo(e.x, e.y+8);
ctx2.moveTo(e.x+e.w, e.y-8); ctx2.lineTo(e.x+e.w, e.y+8);
ctx2.stroke();
// value
const val = Math.round(Math.abs(e.w) * state.multiplier);
ctx2.fillStyle = e.color || state.stroke;
ctx2.font = '12px sans-serif';
ctx2.textAlign='center';
ctx2.fillText(val.toString(), e.x+e.w/2, e.y-10);
}else if(e.type==='symbol'){
const sym = symbols[e.symbolIndex||0];
if(sym){ sym.draw(ctx2, e.x, e.y, e.scale||1); }
}
ctx2.restore();
}
}
function drawArrowHead(ctx2, x, y, angle, size, color){
ctx2.save();
ctx2.translate(x, y);
ctx2.rotate(angle);
ctx2.fillStyle = color || state.stroke;
ctx2.beginPath();
ctx2.moveTo(0, 0);
ctx2.lineTo(-size, size/2);
ctx2.lineTo(-size, -size/2);
ctx2.closePath();
ctx2.fill();
ctx2.restore();
}
function drawGrid(ctx2){
const w = canvas.clientWidth / state.zoom;
const h = canvas.clientHeight / state.zoom;
const step = state.grid.step;
const major = state.grid.majorEvery;
const rot = state.grid.rotation || 0;
ctx2.save();
ctx2.strokeStyle = 'rgba(255,255,255,0.04)';
ctx2.lineWidth = 1/state.zoom;
// minor lines
const drawLine = (x1,y1,x2,y2)=>{ ctx2.beginPath(); ctx2.moveTo(x1,y1); ctx2.lineTo(x2,y2); ctx2.stroke(); };
// rotate around center of viewport
ctx2.translate(state.pan.x + w/2, state.pan.y + h/2);
ctx2.rotate(rot);
ctx2.translate(-(state.pan.x + w/2), -(state.pan.y + h/2));
// determine bounds
const minX = state.pan.x - w/2;
const minY = state.pan.y - h/2;
const maxX = state.pan.x + w/2;
const maxY = state.pan.y + h/2;
// vertical
let startX = Math.floor(minX/step)*step;
for(let x=startX; x<=maxX; x+=step){
const ix = Math.round(x/step);
ctx2.strokeStyle = (ix % major === 0) ? 'rgba(255,255,255,0.08)' : 'rgba(255,255,255,0.04)';
drawLine(x, minY, x, maxY);
}
// horizontal
let startY = Math.floor(minY/step)*step;
for(let y=startY; y<=maxY; y+=step){
const iy = Math.round(y/step);
ctx2.strokeStyle = (iy % major === 0) ? 'rgba(255,255,255,0.08)' : 'rgba(255,255,255,0.04)';
drawLine(minX, y, maxX, y);
}
ctx2.restore();
}
function drawSelection(ctx2){
if(!state.selection) return;
const e = state.selection;
ctx2.save();
ctx2.strokeStyle = 'rgba(59,130,246,.9)';
ctx2.lineWidth = 1/state.zoom;
ctx2.setLineDash([4/state.zoom, 4/state.zoom]);
if(e.type==='line' || e.type==='arrow'){
ctx2.strokeRect(Math.min(e.x, e.x+e.w), Math.min(e.y, e.y+e.h), Math.abs(e.w), Math.abs(e.h));
}else if(e.type==='rect' || e.type==='circle' || e.type==='symbol'){
if(e.type==='circle'){
ctx2.beginPath();
ctx2.arc(e.x, e.y, e.r, 0, Math.PI*2);
ctx2.stroke();
}else{
ctx2.strokeRect(e.x, e.y, e.w, e.h);
}
}else if(e.type==='curve'){
ctx2.beginPath();
ctx2.moveTo(e.x, e.y);
ctx2.quadraticCurveTo(e.cx, e.cy, e.x+e.w, e.y+e.h);
ctx2.stroke();
}else if(e.type==='dimension'){
ctx2.strokeRect(Math.min(e.x, e.x+e.w), e.y-10, Math.abs(e.w), 20);
}
ctx2.restore();
}
function drawTemp(ctx2){
if(!state.temp) return;
const t = state.temp;
ctx2.save();
ctx2.globalAlpha = 0.7;
ctx2.lineWidth = (t.lineWidth || state.lineWidth);
ctx2.strokeStyle = t.color || state.stroke;
ctx2.fillStyle = t.fill || 'transparent';
if(t.type==='line' || t.type==='arrow'){
ctx2.beginPath();
ctx2.moveTo(t.x, t.y);
ctx2.lineTo(t.x+t.w, t.y+t.h);
ctx2.stroke();
}else if(t.type==='rect'){
ctx2.beginPath(); ctx2.rect(t.x, t.y, t.w, t.h); ctx2.fill(); ctx2.stroke();
}else if(t.type==='circle'){
ctx2.beginPath(); ctx2.arc(t.x, t.y, t.r, 0, Math.PI*2); ctx2.fill(); ctx2.stroke();
}else if(t.type==='curve'){
ctx2.beginPath(); ctx2.moveTo(t.x, t.y); ctx2.quadraticCurveTo(t.cx, t.cy, t.x+t.w, t.y+t.h); ctx2.stroke();
}else if(t.type==='dimension'){
ctx2.beginPath();
ctx2.moveTo(t.x, t.y); ctx2.lineTo(t.x+t.w, t.y);
ctx2.moveTo(t.x, t.y-6); ctx2.lineTo(t.x, t.y+6);
ctx2.moveTo(t.x+t.w, t.y-6); ctx2.lineTo(t.x+t.w, t.y+6);
ctx2.stroke();
const val = Math.round(Math.abs(t.w) * state.multiplier);
ctx2.fillStyle = t.color || state.stroke;
ctx2.font = '12px sans-serif'; ctx2.textAlign='center';
ctx2.fillText(val.toString(), t.x+t.w/2, t.y-10);
}
ctx2.restore();
}
function drawLabel(ctx2, lb, useStroke){
ctx2.save();
ctx2.fillStyle = lb.color || state.stroke;
ctx2.font = (lb.size||14)+'px sans-serif';
ctx2.textAlign = 'center';
ctx2.translate(lb.x, lb.y);
ctx2.rotate(deg2rad(lb.rot||0));
ctx2.fillText(lb.text, 0, 0);
ctx2.restore();
}
function drawBlock(ctx2, b, useStroke){
const w = b.w, h = b.h, hPx = b.hPx || 100;
const shadow = clamp(b.shadow ?? 0.7, 0, 1);
// top diamond
ctx2.save();
ctx2.translate(b.x + w/2, b.y - h/2);
ctx2.fillStyle = shade(state.stroke || '#e5e7eb', 0.05);
ctx2.strokeStyle = b.color || state.stroke;
ctx2.lineWidth = 1.2;
ctx2.beginPath();
ctx2.moveTo(0, -h/2);
ctx2.lineTo(w/2, 0);
ctx2.lineTo(0, h/2);
ctx2.lineTo(-w/2, 0);
ctx2.closePath();
ctx2.fill(); ctx2.stroke();
// left face
ctx2.beginPath();
ctx2.moveTo(-w/2, 0);
ctx2.lineTo(0, h/2);
ctx2.lineTo(0, h/2 + hPx);
ctx2.lineTo(-w/2, hPx);
ctx2.closePath();
ctx2.fillStyle = shade(state.stroke || '#e5e7eb', -0.15*(1-shadow));
ctx2.fill(); ctx2.stroke();
// right face
ctx2.beginPath();
ctx2.moveTo(w/2, 0);
ctx2.lineTo(0, h/2);
ctx2.lineTo(0, h/2 + hPx);
ctx2.lineTo(w/2, hPx);
ctx2.closePath();
ctx2.fillStyle = shade(state.stroke || '#e5e7eb', -0.25*(1-shadow));
ctx2.fill(); ctx2.stroke();
ctx2.restore();
}
function shade(hex, pct){
// simple shade: pct in [-1,1]
const c = hex.replace('#','');
const r = parseInt(c.slice(0,2),16);
const g = parseInt(c.slice(2,4),16);
const b = parseInt(c.slice(4,6),16);
const nr = clamp(Math.round(r + (pct*255)), 0, 255);
const ng = clamp(Math.round(g + (pct*255)), 0, 255);
const nb = clamp(Math.round(b + (pct*255)), 0, 255);
return '#'+[nr,ng,nb].map(v=>v.toString(16).padStart(2,'0')).join('');
}
// Entity helpers
function makeTempEntity(tool, pt){
const t = {type: tool, x: pt.x, y: pt.y, w: 0, h: 0, r: 0, cx: pt.x, cy: pt.y, color: state.stroke, fill: state.fill, lineWidth: state.lineWidth};
if(tool==='circle'){ t.r = 1; }
if(tool==='symbol'){ t.symbolIndex = state.currentSymbolIndex||0; t.scale = 1; }
return t;
}
function snapVal(v){
if(!state.snap) return v;
const g = state.grid.step;
return Math.round(v / g) * g;
}
function updateTempEntity(t, pt){
const dx = pt.x - t.x;
const dy = pt.y - t.y;
const shift = isShiftDown();
if(t.type==='line' || t.type==='arrow'){
let nx = dx, ny = dy;
if(shift){
const ang = Math.atan2(dy, dx);
const stepAng = Math.PI/4; // 45°
const snapped = Math.round(ang/stepAng)*stepAng;
const len = Math.hypot(dx,dy);
nx = Math.cos(snapped)*len;
ny = Math.sin(snapped)*len;
}
t.w = nx; t.h = ny;
}else if(t.type==='rect'){
t.w = dx; t.h = dy;
}else if(t.type==='circle'){
t.r = Math.hypot(dx,dy);
}else if(t.type==='curve'){
t.w = dx; t.h = dy;
t.cx = t.x + dx/2; t.cy = t.y + dy/2;
}else if(t.type==='dimension'){
t.w = dx; t.h = 0;
}
}
function finalizeTempEntity(t){
if(!t) return;
// snap end points
if(state.snap
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>نقشه خوانی معماری - برنامه حرفهای دسکتاپ</title>
<meta name="description" content="برنامه دسکتاپ حرفهای برای یادگیری نقشه خوانی و ترسیم معماری با ابزارهای کامل، درسهای مرحلهای و کتابخانه نمادها." />
<style>
:root{
--bg:#0f141a;
--panel:#141a22;
--panel-2:#0b1016;
--text:#e5e7eb;
--muted:#a1a7b3;
--primary:#3b82f6;
--primary-2:#2563eb;
--accent:#10b981;
--danger:#ef4444;
--warn:#f59e0b;
--border:#263041;
--card:#111827;
--shadow:0 10px 30px rgba(0,0,0,.35);
--radius:10px;
--grid:#1f2937;
--grid-major:#374151;
--accent-2:#06b6d4;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
margin:0;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", "IRANSans", "Vazirmatn", "Tahoma", sans-serif;
color:var(--text);
background:linear-gradient(180deg,#0a0f14,#0b1117 40%, #0c1219);
}
header{
display:flex;align-items:center;justify-content:space-between;
padding:12px 18px;border-bottom:1px solid var(--border);
background:rgba(13,19,26,.8);backdrop-filter:blur(10px);
position:sticky;top:0;z-index:10;
}
.brand{display:flex;align-items:center;gap:10px;font-weight:700}
.brand .logo{
width:36px;height:36px;border-radius:9px;
background:linear-gradient(135deg,var(--primary),var(--accent));
display:grid;place-items:center;color:white;font-weight:800;box-shadow:var(--shadow)
}
.brand small{display:block;color:var(--muted);font-weight:500}
.top-actions{display:flex;gap:10px;align-items:center}
.link{
color:var(--muted);text-decoration:none;padding:6px 10px;border-radius:8px;
}
.link:hover{background:var(--panel);color:var(--text)}
.btn{
background:var(--primary);border:none;color:white;border-radius:10px;
padding:8px 14px;font-weight:600;cursor:pointer;box-shadow:0 4px 12px rgba(59,130,246,.3)
}
.btn:hover{background:var(--primary-2)}
.btn.secondary{background:transparent;border:1px solid var(--border);color:var(--text)}
.btn.ghost{background:transparent;color:var(--text)}
.container{
display:grid;grid-template-columns:280px 1fr 320px;gap:0;min-height:calc(100vh - 60px)
}
aside{
border-left:1px solid var(--border);
background:linear-gradient(180deg,var(--panel),var(--panel-2));
overflow:auto;
}
.left{
border-left:none;border-right:1px solid var(--border)
}
.panel{padding:16px}
.panel h3{margin:0 0 10px 0;font-size:15px;color:#dbe2ea}
.panel .muted{color:var(--muted);font-size:13px;line-height:1.6}
.tools{
display:grid;grid-template-columns:repeat(3,1fr);gap:8px
}
.tool{
background:var(--card);border:1px solid var(--border);border-radius:10px;padding:10px;
display:flex;flex-direction:column;align-items:center;gap:6px;cursor:pointer;transition:.2s;
}
.tool.active{outline:2px solid var(--primary);border-color:transparent;background:linear-gradient(180deg,#122032,#0d1521)}
.tool:hover{transform:translateY(-2px)}
.tool svg{width:22px;height:22px}
.tool span{font-size:12px;color:#dbe2ea}
.layers{display:flex;flex-direction:column;gap:10px;margin-top:10px}
.layer{
display:flex;align-items:center;justify-content:space-between;padding:8px 10px;border:1px solid var(--border);border-radius:8px;background:#0d131b;
}
.layer .row{display:flex;align-items:center;gap:8px}
.layer input[type="checkbox"]{transform:scale(1.1)}
.canvas-wrap{
position:relative;display:flex;flex-direction:column;background:radial-gradient(circle at 20% 0%, #0e1723, #0c131b);
overflow:hidden;
}
.canvas-toolbar{
display:flex;align-items:center;gap:8px;padding:10px;border-bottom:1px solid var(--border);background:rgba(15,21,29,.7);backdrop-filter:blur(8px)
}
.group{display:flex;gap:8px;align-items:center}
.field{