Repository navigation
Expand file tree
/
Copy pathstudio.html
More file actions
192 lines (192 loc) · 28.6 KB
/
Copy pathstudio.html
File metadata and controls
192 lines (192 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><script>try{document.documentElement.dataset.theme=localStorage.getItem("asw-theme")||""}catch{}</script><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Studio — Sheetstudio</title><link rel="icon" href="favicon.svg" type="image/svg+xml"><link rel="manifest" href="manifest.webmanifest"><link rel="apple-touch-icon" href="icon-192.png"><meta name="theme-color" content="#0f1626">
<link rel="preconnect" href="https://fonts.googleapis.com"><link href="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter:wght@400;500;600&family=Source+Serif+4:wght@400;600;700&family=Caveat:wght@500;700&display=swap" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/marked@12.0.2/marked.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.1.6/dist/purify.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10.9.1/dist/mermaid.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="assets/pro.css">
<style>:root{--bg:#F6F4FC;--ink:#1B133C;--mut:rgba(27,19,60,.62);--hair:rgba(27,19,60,.13);--or:#f97316;--card:#fff;--glass:rgba(255,255,255,.75);--on:#fff}
[data-theme=dark]{--bg:#0f1626;--ink:#f4f6fa;--mut:rgba(244,246,250,.62);--hair:rgba(255,255,255,.16);--card:#172036;--glass:rgba(23,32,54,.8);--on:#0f1626}
[data-theme=dark] .status.ok{color:#86efac}[data-theme=dark] .status.error{color:#fca5a5}
*{box-sizing:border-box;margin:0}
html,body{background:var(--bg);color:var(--ink);font:400 15px/1.45 'Inter',system-ui,sans-serif;height:100%}
a{color:inherit;text-decoration:none}
nav{position:fixed;top:0;left:0;right:0;z-index:30;display:flex;justify-content:center;padding:14px 12px 0}
.pillnav{display:flex;align-items:center;gap:18px;background:var(--glass);backdrop-filter:blur(10px);border-radius:12px;padding:9px 16px;box-shadow:0 1px 3px rgba(0,0,0,.08)}
.lk{font-size:14px;font-weight:500;color:rgba(27,19,60,.8)}.lk:hover{color:var(--ink)}
.pill{height:34px;padding:0 16px;border-radius:10px;border:0;background:var(--ink);color:var(--on);font:600 13px 'Inter';cursor:pointer;display:inline-flex;align-items:center}
.btn{height:40px;padding:0 16px;border-radius:10px;border:1px solid var(--hair);background:var(--card);color:var(--ink);font:600 13px 'Inter';cursor:pointer;display:inline-flex;align-items:center;justify-content:center;transition:.2s}
.btn:hover:not(:disabled){box-shadow:0 4px 12px rgba(0,0,0,.12)}.btn:disabled{opacity:.5;cursor:wait}.btn.sm{height:30px;padding:0 10px;font-size:12px}
.btn-generate{background:var(--ink);color:var(--on);border-color:var(--ink)}.btn-ghost{background:transparent}
.app{display:grid;grid-template-columns:350px 1fr;height:100vh;padding-top:74px}
#sidebar{overflow:auto;padding:14px 16px 24px;display:flex;flex-direction:column;gap:14px}
.brand h1{font:400 38px/1 'Instrument Serif',serif;letter-spacing:-.02em}.brand p{color:var(--mut);font-size:13px;margin-top:4px}
.card{background:var(--card);border:1px solid var(--hair);border-radius:16px;padding:14px;display:flex;flex-direction:column;gap:10px;box-shadow:0 1px 2px rgba(27,19,60,.04)}
.card h2{font:600 11px 'Inter';letter-spacing:.06em;text-transform:uppercase;color:var(--mut)}
.row{display:flex;gap:8px}.row>*{flex:1;min-width:0}
input,select,textarea{width:100%;background:var(--card);border:1px solid var(--hair);color:var(--ink);border-radius:10px;padding:9px 11px;font:400 14px 'Inter',sans-serif;outline:none}
input:focus,select:focus,textarea:focus{border-color:var(--ink)}
input[type=checkbox],input[type=range]{width:auto;accent-color:var(--or)}
textarea.q-text{min-height:78px;resize:vertical}
.field-label{font-size:11px;color:var(--mut);display:block;margin-bottom:3px}
.toggle-row{display:flex;align-items:center;gap:8px;font-size:13px;color:var(--mut)}
.status{font-size:12px;color:var(--mut);min-height:14px;line-height:1.4}.status.ok{color:#15803d}.status.error{color:#b91c1c}
.lib-i{display:flex;gap:6px;align-items:center}.lib-i span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px}
main{display:flex;flex-direction:column;min-width:0;padding:6px 16px 14px 0;gap:10px;height:100%}
.bar{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.seg{height:34px;padding:0 14px;border-radius:10px;border:1px solid var(--hair);background:var(--card);color:var(--mut);font:600 12px 'Inter';cursor:pointer}.seg.on{background:var(--ink);color:var(--on);border-color:var(--ink)}
.stats{margin-left:auto;color:var(--mut);font-size:12px}.tabs{display:none}
.panels{flex:1;display:flex;gap:12px;min-height:0}.panel{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px}
.pt{font:600 11px 'Inter';letter-spacing:.06em;text-transform:uppercase;color:var(--mut)}
#markdown-input{flex:1;resize:none;font:12.5px/1.55 ui-monospace,Consolas,monospace;border-radius:14px;padding:14px}
#preview-wrap{flex:1;position:relative;border-radius:14px;overflow:hidden;background:#fff;border:1px solid var(--hair);box-shadow:0 6px 24px rgba(27,19,60,.08)}
#preview{height:100%;overflow:auto;padding:36px 42px;background:#fff;color:#1e293b;font:400 15.5px/1.8 'Source Serif 4',Georgia,serif}
#preview h1{font:400 1.8rem/1.1 'Instrument Serif',serif;border-bottom:2px solid var(--ink);padding-bottom:6px;margin:1em 0 .4em;color:var(--ink)}#preview h2{font-size:1.08rem;color:#1d4ed8;margin:1em 0 .3em}#preview h3{font-size:1rem;margin:.8em 0 .2em}
#preview p{margin-bottom:.9em;text-align:justify}#preview ul,#preview ol{margin:0 0 .9em 1.4em}
#preview table{border-collapse:collapse;width:100%;margin:1.2em 0;font:.88rem 'Inter',sans-serif}#preview th,#preview td{border:1px solid #94a3b8;padding:7px 10px;text-align:left}#preview th{background:#f1f5f9}
#preview blockquote{border-left:3px solid var(--or);background:#fff7ed;padding:8px 14px;margin:1em 0;font-size:.92rem}
#preview pre{background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;padding:12px;overflow:auto;margin-bottom:1em;font:.82rem/1.5 ui-monospace,Consolas,monospace}
.mermaid{display:flex;justify-content:center;margin:18px 0}.mermaid svg{max-width:100%;height:auto;max-height:200mm}#preview h2+.mermaid,#preview h3+.mermaid{break-before:avoid}.fb{background:#fef2f2;border:1px solid #fecaca;color:#991b1b;border-radius:8px;padding:10px 12px;margin:14px 0;font:.85rem 'Inter',sans-serif}
mark.name{background:#fde68a;color:#78350f;padding:0 2px;border-radius:3px;font-weight:600}mark.key{background:#bbf7d0;color:#14532d;padding:0 2px;border-radius:3px;font-weight:600}
#preview.nokey mark.key{background:none;color:inherit;font-weight:700}
.strip{display:flex;flex-wrap:wrap;gap:4px 16px;border:1px solid #cbd5e1;border-radius:8px;background:#f8fafc;padding:9px 13px;margin-bottom:18px;font:.78rem 'Inter',sans-serif}.strip b{color:var(--ink)}
.page-break{display:none}#preview .pb{border-top:2px dashed #cbd5e1;padding-top:18px;margin-top:30px}
#preview .cover{text-align:center;padding:50px 10px 30px;color:#1B133C}.cv-c{font:700 1.15rem Inter,sans-serif;letter-spacing:.08em}.cv-t{font:400 3.2rem/1 'Instrument Serif',serif;margin:44px 0 10px}.cv-s{font:600 1.35rem Inter,sans-serif}.cv-a{font:1.05rem Inter,sans-serif;color:#475569;margin-top:4px}
#preview .cv-tb{margin:42px auto 0;width:auto;font:.95rem Inter,sans-serif}#preview .cv-tb td{border:0;padding:6px 16px;text-align:left}#preview .cv-tb td:first-child{color:#64748b}
#preview{--hwfont:'Caveat',cursive;--ink-h:#1d3a8a;--ls:1.8em;-webkit-print-color-adjust:exact;print-color-adjust:exact}
#preview.hw{--ls:2.1em;font-family:var(--hwfont);font-weight:500;font-size:calc(var(--hwsz,1.3rem)*var(--hw,1));line-height:var(--ls);color:var(--ink-h)}
#preview.hw p{text-align:left;margin-bottom:0}#preview.hw ul,#preview.hw ol{margin-bottom:0}
#preview.hw h1,#preview.hw h2,#preview.hw h3{font-family:var(--hwfont);color:var(--ink-h);border-color:var(--ink-h);line-height:var(--ls);margin:.3em 0 0}
#preview.hw h1{font-size:1.5em;padding-bottom:0}#preview.hw h2{font-size:1.2em}#preview.hw h3{font-size:1.05em}
#preview.hw table,#preview.hw .strip,#preview.hw .cover,#preview.hw pre,#preview.hw code{font-family:var(--hwfont);font-size:1em}
#preview.hw th{background:transparent}#preview.hw td,#preview.hw th{border-color:var(--ink-h)}
#preview.hw pre{background:transparent;border:0;line-height:var(--ls);padding:0;margin:0}#preview.hw .strip{background:transparent;border-color:var(--ink-h)}#preview.hw .cv-t,#preview.hw .cv-c{font-family:var(--hwfont)}
#preview.pp-ruled{line-height:var(--ls);background:repeating-linear-gradient(#fff,#fff calc(var(--ls) - 1px),#c7d6f5 calc(var(--ls) - 1px),#c7d6f5 var(--ls)) 0 .45em;border-left:3px solid #dc2626;padding-left:54px;margin-left:16px}
#preview.pp-grid{background:linear-gradient(#d5deec 1px,transparent 1px) 0 0/1.6rem 1.6rem,linear-gradient(90deg,#d5deec 1px,transparent 1px) 0 0/1.6rem 1.6rem,#fff}
#preview.pp-dots{background:radial-gradient(#9aa8bd 1.1px,transparent 1.4px) 0 0/1.6rem 1.6rem,#fff}
.pgb{position:absolute;inset:8px;border:1.5px solid #334155;pointer-events:none;display:none;z-index:4}.pgb.on{display:block}
#toast{position:fixed;bottom:18px;right:18px;background:var(--ink);color:var(--on);padding:10px 16px;border-radius:10px;font-weight:600;font-size:13px;opacity:0;transform:translateY(8px);transition:.25s;z-index:60;pointer-events:none}#toast.show{opacity:1;transform:none}
#preview table,#preview .mermaid,#preview pre,#preview blockquote,.strip{break-inside:avoid}#preview h1,#preview h2,#preview h3{break-after:avoid}
@media(max-width:900px){body{height:auto}.app{display:block;height:auto}main{height:auto;min-height:100vh;padding:6px 16px 20px}.tabs{display:flex;gap:8px}.panels{display:block}.panel{display:none;height:78vh}.panels[data-v=edit] #edit,.panels[data-v=prev] #prevp{display:flex}#preview{padding:22px 18px}}
@media print{nav,#sidebar,.bar,.tabs,#toast,.pt{display:none!important}html,body,.app,main{display:block;height:auto;overflow:visible;background:#fff;padding:0}.panels{display:block}#edit{display:none!important}#prevp{display:block!important}#preview-wrap{overflow:visible;border:0;box-shadow:none;border-radius:0}#preview{overflow:visible;height:auto;padding:0}@page{margin:18mm 20mm 16mm}#preview pre{white-space:pre-wrap;word-break:break-word;overflow:visible}#preview .pb{break-before:page;border:0;padding-top:0;margin-top:0}#preview .cover{break-after:page;min-height:75vh}#preview .cover+.pb,#preview>.pb:first-child{break-before:auto}#preview.hw{background-attachment:local}}
@media print{.pgb{position:fixed;inset:8mm}}</style><style id="pgs"></style></head><body>
<nav><div class="pillnav"><a href="./" aria-label="Home"><svg width="24" height="24" viewBox="0 0 256 256" fill="currentColor" aria-hidden="true"><path d="M 256 256 L 128 256 L 0 128 L 128 128 Z"/><path d="M 256 128 L 128 128 L 0 0 L 128 0 Z"/></svg></a>
<a class="lk" href="./">Home</a><a class="lk" href="https://console.groq.com/keys" target="_blank" rel="noopener">Free key</a><button class="btn btn-ghost sm" id="b-theme" type="button" aria-label="Toggle dark mode">◐</button><button class="pill" id="b-print" type="button">Export PDF</button></div></nav>
<div class="app"><aside id="sidebar">
<div class="brand"><h1>Studio</h1><p>JNTUH-style answers, diagrams and print-ready sheets.</p></div>
<div class="card"><h2>Paper & handwriting</h2>
<div class="row"><div><label class="field-label">Paper</label><select id="s-paper"><option value="plain">Plain white</option><option value="ruled">Ruled (lined)</option><option value="grid">Squared (checked)</option><option value="dots">Dotted</option></select></div>
<div><label class="field-label">Page size</label><select id="s-size"><option value="A4">A4</option><option value="Letter">Letter</option></select></div></div>
<div class="row"><div><label class="field-label">Handwriting</label><select id="s-font"><option value="caveat">Neat (Caveat)</option><option value="kalam">Natural (Kalam)</option><option value="patrick">Clean print (Patrick Hand)</option><option value="indie">Round (Indie Flower)</option><option value="shadows">Slim (Shadows Into Light)</option><option value="nanum">Fast pen (Nanum Pen)</option><option value="apple">Cursive (Homemade Apple)</option><option value="dancing">Joined (Dancing Script)</option></select></div>
<div><label class="field-label">Ink</label><select id="s-ink"><option value="blue">Blue</option><option value="black">Black</option><option value="navy">Navy</option><option value="violet">Violet</option></select></div></div>
<div class="toggle-row"><input type="checkbox" id="s-nat" checked><label for="s-nat">Natural variation (slight tilt)</label></div>
<div class="toggle-row"><input type="checkbox" id="s-border"><label for="s-border">Page border</label></div>
<div class="status">Handwriting applies when the Handwritten button is on. Paper applies to both modes.</div></div>
<div class="card"><h2>Student details</h2>
<div class="row"><div><label class="field-label">Name</label><input id="d-name" placeholder="Your full name"></div><div><label class="field-label">Roll no.</label><input id="d-roll" placeholder="Roll / hall ticket no."></div></div>
<div class="row"><div><label class="field-label">Class</label><input id="d-class" placeholder="e.g. B.Tech CSE"></div><div><label class="field-label">Year</label><input id="d-year" placeholder="e.g. Final Year"></div></div>
<div class="row"><div><label class="field-label">Group</label><input id="d-group" placeholder="e.g. CSE"></div><div><label class="field-label">Section</label><input id="d-section" placeholder="e.g. D"></div></div>
<div><label class="field-label">College</label><input id="d-college" placeholder="Your college or institute name"></div>
<div class="row"><div><label class="field-label">Subject</label><input id="d-subject" placeholder="e.g. Programming in C"></div><div><label class="field-label">Assignment</label><input id="d-assign" placeholder="e.g. Assignment 1"></div></div>
<div><label class="field-label">Date</label><input id="d-date"></div>
<div><label class="field-label">Faculty name</label><input id="d-faculty" placeholder="Faculty name"></div>
<div><label class="field-label">Faculty email</label><input id="d-femail" type="email" placeholder="faculty@college.edu"></div>
<div class="toggle-row"><input type="checkbox" id="t-cover"><label for="t-cover">Add a cover page</label></div>
<div class="toggle-row"><input type="checkbox" id="t-strip" checked><label for="t-strip">Show details strip on the sheet</label></div>
<div class="toggle-row"><input type="checkbox" id="t-key" checked><label for="t-key">Highlight key points (==term==)</label></div></div>
<div class="card"><h2>Document tools</h2>
<div class="row"><button class="btn btn-ghost" id="b-copy" type="button">Copy .md</button><button class="btn btn-ghost" id="b-dl" type="button">Download .md</button></div>
<div class="row"><button class="btn btn-ghost" id="b-sample" type="button">Load sample</button><button class="btn btn-ghost" id="b-clear" type="button">Clear all</button></div>
<div class="status">Drafts autosave in this browser.</div></div>
<div class="card"><h2>My library</h2><input id="lib-title" maxlength="80" placeholder="Title (optional)">
<button class="btn btn-ghost" id="lib-save" type="button">Save current answer</button><div id="lib-list" style="display:flex;flex-direction:column;gap:6px"></div>
<div class="row"><button class="btn btn-ghost sm" id="lib-exp" type="button">Export backup</button><label class="btn btn-ghost sm">Import<input id="lib-imp" type="file" accept="application/json" hidden></label></div></div>
<div class="card"><h2>Submit to faculty</h2><button class="btn btn-generate" id="b-send" type="button">Send to faculty</button><div class="status" id="send-s">Shares the .md file, or opens your email app. Attach the exported PDF for the best result.</div></div>
</aside>
<main><div class="bar"><button class="seg on" id="m-sys" type="button">System</button><button class="seg" id="m-hw" type="button">Handwritten</button>
<span id="hw-size" style="display:none;align-items:center;gap:6px;color:var(--i46);font-size:12px">Size <input type="range" id="hw-r" min=".85" max="1.3" step=".05" value="1" style="width:90px"></span>
<button class="seg" id="b-diag" type="button">+ Mermaid diagram</button><span class="stats" id="stats"></span></div>
<div class="tabs"><button class="seg on" data-v="edit" type="button">Edit</button><button class="seg" data-v="prev" type="button">Preview</button></div>
<div class="panels" id="panels" data-v="edit"><div class="panel" id="edit"><div class="pt">Markdown</div><textarea id="markdown-input" placeholder="Run the Pro Agent, or paste Markdown here…"></textarea></div>
<div class="panel" id="prevp"><div class="pt">Answer sheet</div><div id="preview-wrap"><div class="pgb" id="pgb"></div><div id="preview"></div></div></div></div></main></div>
<div id="toast"></div>
<script>
const $=id=>document.getElementById(id),md=$('markdown-input'),pv=$('preview'),wrap=$('preview-wrap');
const F=['name','roll','class','year','group','section','college','subject','assign','date','faculty','femail'],LB={name:'Name',roll:'Roll No.',class:'Class',year:'Year',group:'Group',section:'Section',college:'College',subject:'Subject',assign:'Assignment',date:'Date',faculty:'Faculty'};
const D=Object.fromEntries(F.map(k=>[k,$('d-'+k)])),KEY='asw-draft-v2';let seq=0,mode='sys',tm;
const toast=m=>{const t=$('toast');t.textContent=m;t.classList.add('show');clearTimeout(tm);tm=setTimeout(()=>t.classList.remove('show'),2200)};
try{mermaid.initialize({startOnLoad:false,theme:'default',securityLevel:'strict'})}catch{}
const esc=s=>s.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');
function hl(root,names){const src='('+names.map(esc).join('|')+')',re=new RegExp(src,'gi'),t1=new RegExp(src,'i'),w=document.createTreeWalker(root,NodeFilter.SHOW_TEXT),ns=[];
while(w.nextNode())ns.push(w.currentNode);
ns.forEach(n=>{if(n.parentNode.closest('pre,code,mark')||!t1.test(n.nodeValue))return;const f=document.createDocumentFragment();
n.nodeValue.split(re).forEach((s,i)=>{if(i%2){const m=document.createElement('mark');m.className='name';m.textContent=s;f.append(m)}else f.append(s)});n.replaceWith(f)})}
const FONTS={caveat:['Caveat','Caveat:wght@500;700','1.3rem'],kalam:['Kalam','Kalam:wght@400;700','1.05rem'],patrick:['Patrick Hand','Patrick+Hand','1.15rem'],indie:['Indie Flower','Indie+Flower','1.05rem'],shadows:['Shadows Into Light','Shadows+Into+Light','1.25rem'],nanum:['Nanum Pen Script','Nanum+Pen+Script','1.5rem'],apple:['Homemade Apple','Homemade+Apple','.95rem'],dancing:['Dancing Script','Dancing+Script:wght@500;700','1.2rem']};
const INKS={blue:'#1d3a8a',black:'#111827',navy:'#0b2a6b',violet:'#4c1d95'},SIDS=['s-paper','s-size','s-font','s-ink'],loadedF=new Set(['caveat']);
function getPS(){return{paper:$('s-paper').value,size:$('s-size').value,font:$('s-font').value,ink:$('s-ink').value,nat:$('s-nat').checked,border:$('s-border').checked}}
function setPS(p){if(!p)return;SIDS.forEach(i=>{const k=i.slice(2);if(p[k])$(i).value=p[k]});$('s-nat').checked=p.nat!==false;$('s-border').checked=!!p.border}
function applyStyle(){const p=getPS(),f=FONTS[p.font]||FONTS.caveat;
if(!loadedF.has(p.font)){loadedF.add(p.font);const l=document.createElement('link');l.rel='stylesheet';l.href='https://fonts.googleapis.com/css2?family='+f[1]+'&display=swap';document.head.append(l)}
pv.style.setProperty('--hwfont',"'"+f[0]+"',cursive");pv.style.setProperty('--hwsz',f[2]);pv.style.setProperty('--ink-h',INKS[p.ink]||INKS.blue);
['plain','ruled','grid','dots'].forEach(k=>pv.classList.toggle('pp-'+k,k===p.paper));$('pgb').classList.toggle('on',p.border)}
function cover(){const c=document.createElement('div');c.className='cover';const add=(cl,t)=>{if(!t)return;const e=document.createElement('div');e.className=cl;e.textContent=t;c.append(e)};
add('cv-c',D.college.value.trim().toUpperCase());add('cv-t','Assignment');add('cv-s',D.subject.value.trim());add('cv-a',D.assign.value.trim());
const tb=document.createElement('table');tb.className='cv-tb';[['Name',D.name],['Roll No.',D.roll],['Class',D.class],['Year',D.year],['Group',D.group],['Section',D.section],['Submitted to',D.faculty],['Date',D.date]].forEach(([l,el])=>{const v=el.value.trim();if(!v)return;const r=tb.insertRow();r.insertCell().textContent=l;r.insertCell().textContent=v});c.append(tb);return c}
async function render(){const id=++seq;
if(!window.marked||!window.DOMPurify){pv.textContent='Libraries failed to load. Check your connection and reload.';return}
const root=document.createElement('div');
root.innerHTML=DOMPurify.sanitize(marked.parse(md.value.split(/(```[\s\S]*?```)/g).map((x,i)=>i%2?x:x.replace(/==([^=\n]+)==/g,'<mark class="key">$1</mark>')).join('')));
const names=[D.name.value,D.faculty.value].map(s=>s.trim()).filter(s=>s.length>2);if(names.length)hl(root,names);
const nodes=[...root.querySelectorAll('pre>code.language-mermaid')].map(c=>{const d=document.createElement('div');d.className='mermaid';d.dataset.src=c.textContent;c.parentNode.replaceWith(d);return d});
for(const [i,n] of nodes.entries()){try{n.innerHTML=(await mermaid.render('mm'+id+'_'+i,n.dataset.src)).svg}
catch{document.getElementById('dmm'+id+'_'+i)?.remove();n.className='fb';n.textContent='Diagram could not be drawn. Fix the Mermaid code in the editor.'}
if(id!==seq)return}
const items=[];const filled=F.filter(k=>k!=='femail'&&D[k].value.trim());
root.querySelectorAll('.page-break').forEach(b=>{const n=b.nextElementSibling;if(n)n.classList.add('pb');b.remove()});
const nm=(D.name.value.trim()+(D.roll.value.trim()?' · '+D.roll.value.trim():'')).replace(/["\\]/g,'');
$('pgs').textContent='@page{size:'+$('s-size').value+';@bottom-left{content:"'+nm+'";font:8pt Inter,sans-serif;color:#64748b}@bottom-right{content:"Page " counter(page);font:8pt Inter,sans-serif;color:#64748b}}';
if($('t-cover').checked&&filled.length)items.push(cover());
else if($('t-strip').checked&&filled.length){const s=document.createElement('div');s.className='strip';
filled.forEach(k=>{const sp=document.createElement('span'),b=document.createElement('b');b.textContent=LB[k]+': ';sp.append(b,D[k].value.trim());s.append(sp)});items.push(s)}
if(mode==='hw'&&$('s-nat').checked)root.querySelectorAll('p,li,h1,h2,h3').forEach((e,i)=>{const h=(e.textContent.length*31+i*17)%11;e.style.transform='rotate('+((h-5)/12).toFixed(2)+'deg) translateX('+(h%4-1.5)+'px)';e.style.transformOrigin='left center'});
pv.replaceChildren(...items,...root.childNodes);pv.classList.toggle('nokey',!$('t-key').checked);
const w=(pv.textContent.match(/\S+/g)||[]).length;$('stats').textContent=w?`~${w} words · ~${Math.max(1,Math.ceil(w/(mode==='hw'?230:500)))} pages`:''}
let rt;const queue=()=>{clearTimeout(rt);rt=setTimeout(()=>{render();save()},250)};
function save(){try{localStorage.setItem(KEY,JSON.stringify({md:md.value,d:Object.fromEntries(F.map(k=>[k,D[k].value])),s:$('t-strip').checked,k:$('t-key').checked,c:$('t-cover').checked,ps:getPS()}))}catch{}}
try{const s=JSON.parse(localStorage.getItem(KEY)||'null');if(s){md.value=s.md||'';F.forEach(k=>{if(s.d&&k in s.d)D[k].value=s.d[k]});$('t-strip').checked=s.s!==false;$('t-key').checked=s.k!==false;$('t-cover').checked=!!s.c;setPS(s.ps);if(D.college.value==='Vaagdevi College of Engineering'&&!localStorage.getItem('asw-mig8')){D.college.value='';try{localStorage.setItem('asw-mig8','1')}catch{}}}}catch{}
md.addEventListener('input',queue);F.forEach(k=>D[k].addEventListener('input',queue));[...SIDS,'s-nat','s-border'].forEach(i=>$(i).addEventListener('change',()=>{applyStyle();queue()}));
['t-strip','t-key','t-cover'].forEach(i=>$(i).addEventListener('change',queue));
function setMode(m){mode=m;pv.classList.toggle('hw',m==='hw');$('m-sys').classList.toggle('on',m==='sys');$('m-hw').classList.toggle('on',m==='hw');$('hw-size').style.display=m==='hw'?'flex':'none';render()}
$('m-sys').onclick=()=>setMode('sys');$('m-hw').onclick=()=>setMode('hw');$('hw-r').oninput=e=>pv.style.setProperty('--hw',e.target.value);
document.querySelectorAll('.tabs .seg').forEach(b=>b.onclick=()=>{$('panels').dataset.v=b.dataset.v;document.querySelectorAll('.tabs .seg').forEach(x=>x.classList.toggle('on',x===b))});
$('b-diag').onclick=()=>{const s='\n```mermaid\nflowchart TD\n A[Start] --> B[Step]\n B --> C[End]\n```\n',a=md.selectionStart??md.value.length;md.value=md.value.slice(0,a)+s+md.value.slice(md.selectionEnd??a);queue()};
$('b-copy').onclick=async()=>{try{await navigator.clipboard.writeText(md.value);toast('Markdown copied')}catch{toast('Copy failed')}};
$('b-dl').onclick=()=>{const a=document.createElement('a');a.href=URL.createObjectURL(new Blob([md.value],{type:'text/markdown'}));a.download='answer-sheet.md';a.click();setTimeout(()=>URL.revokeObjectURL(a.href),1e3)};
$('b-clear').onclick=()=>{if(confirm('Clear the editor and the saved draft?')){md.value='';try{localStorage.removeItem(KEY)}catch{}render()}};
$('b-sample').onclick=()=>{md.value=`# Question 1: Database Normalization (16 Marks)\n\n## 1. Overview\n\n==Normalization== decomposes tables to remove redundancy and the insertion, update and deletion anomalies.\n\n| Form | Rule |\n| :-- | :-- |\n| 1NF | Atomic values only |\n| 2NF | No partial dependency |\n| 3NF | No transitive dependency |\n\n\`\`\`mermaid\nflowchart LR\n A[Unnormalized] --> B[1NF] --> C[2NF] --> D[3NF] --> E[BCNF]\n\`\`\`\n\n> Mnemonic: Atomic, Partial gone, Transitive gone, Boyce key only.\n`;queue()};
$('b-print').onclick=async()=>{try{await document.fonts.ready}catch{}const t=document.title;document.title='Answer Sheet - '+(D.name.value.trim()||'Student');window.print();setTimeout(()=>document.title=t,1500)};
$('b-send').onclick=async()=>{const n=D.name.value.trim()||'Student',f=new File([md.value],'answer-sheet.md',{type:'text/markdown'});
if(navigator.canShare&&navigator.canShare({files:[f]})){try{await navigator.share({files:[f],title:'Answer sheet - '+n,text:'Answer sheet by '+n});return}catch{}}
const q=encodeURIComponent;location.href='mailto:'+D.femail.value.trim()+'?subject='+q('Answer sheet - '+n)+'&body='+q('Respected sir/madam,\n\nPlease find my answer sheet attached.\n\nRegards,\n'+n+(D.roll.value?'\nRoll No: '+D.roll.value:''))};
const LK='asw-lib-v1',lib=()=>{try{return JSON.parse(localStorage.getItem(LK)||'[]')}catch{return[]}},putLib=a=>{try{localStorage.setItem(LK,JSON.stringify(a.slice(0,50)))}catch{toast('Storage full. Export a backup and delete old items.')}};
function drawLib(){const box=$('lib-list');box.replaceChildren();const a=lib();if(!a.length){const p=document.createElement('div');p.className='status';p.textContent='Nothing saved yet.';box.append(p);return}
a.forEach(it=>{const r=document.createElement('div');r.className='lib-i';const t=document.createElement('span');t.textContent=it.title;t.title=new Date(it.t).toLocaleString();
const o=document.createElement('button');o.className='btn btn-ghost sm';o.textContent='Open';o.onclick=()=>{md.value=it.md;queue();toast('Opened')};
const d=document.createElement('button');d.className='btn btn-ghost sm';d.textContent='Delete';d.onclick=()=>{putLib(lib().filter(x=>x.id!==it.id));drawLib()};r.append(t,o,d);box.append(r)})}
$('lib-save').onclick=()=>{if(!md.value.trim())return toast('Nothing to save yet');const h=(md.value.match(/^#+\s*(.+)$/m)||[])[1]||'Untitled answer',a=lib();
a.unshift({id:Date.now(),title:($('lib-title').value.trim()||h).slice(0,80),md:md.value.slice(0,200000),t:Date.now()});putLib(a);$('lib-title').value='';drawLib();toast('Saved to library')};
$('lib-exp').onclick=()=>{const a=document.createElement('a');a.href=URL.createObjectURL(new Blob([JSON.stringify(lib())],{type:'application/json'}));a.download='sheetstudio-library.json';a.click();setTimeout(()=>URL.revokeObjectURL(a.href),1e3)};
$('lib-imp').onchange=async e=>{const f=e.target.files[0];if(!f)return;try{const j=JSON.parse(await f.text());if(!Array.isArray(j))throw 0;
const ok=j.filter(x=>x&&typeof x.md==='string'&&typeof x.title==='string').map((x,i)=>({id:Date.now()+i,title:x.title.slice(0,80),md:x.md.slice(0,200000),t:+x.t||Date.now()}));putLib([...ok,...lib()]);drawLib();toast('Imported '+ok.length)}catch{toast('Invalid backup file')}e.target.value=''};
drawLib();window.drawLib=drawLib;
if('serviceWorker' in navigator&&location.protocol==='https:')navigator.serviceWorker.register('sw.js').catch(()=>{});
if(!D.date.value)D.date.value=new Date().toLocaleDateString('en-GB');
applyStyle();window.addEventListener('beforeunload',save);render();
</script>
<script src="assets/lib.js"></script><script src="assets/pro.js"></script><script src="assets/watermark.js"></script>
<script>
document.getElementById('b-theme').onclick=()=>{const d=document.documentElement,n=d.dataset.theme==='dark'?'':'dark';d.dataset.theme=n;try{localStorage.setItem('asw-theme',n)}catch{}};
document.getElementById('sidebar').addEventListener('click',e=>{const h=e.target.closest('.card>h2');if(h)h.parentElement.classList.toggle('collapsed')});
if(innerWidth<=900)document.querySelectorAll('#sidebar .card').forEach(c=>{if(!c.querySelector('#pro-go'))c.classList.add('collapsed')});
</script></body></html>