- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
648 lines (570 loc) · 23.6 KB
/
Copy pathscript.js
File metadata and controls
648 lines (570 loc) · 23.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/* ==============================================================
STATE
============================================================== */
letcurrentZoom=40;
letdebounceTimer=null;
/* ==============================================================
PARSER
============================================================== */
functionparse(source){
constlines=source.split('\n');
consttokens=[];
constglobalConfig={split: 3,size: 15};
for(letrawoflines){
constline=raw.trimEnd();
if(line.trim()==='')continue;
if(line.trim().startsWith('//'))continue;
// #split
letm=line.match(/^#split\s+(\d+)/i);
if(m){globalConfig.split=Math.max(1,Math.min(6,parseInt(m[1])));continue;}
// #size
m=line.match(/^#size\s+(\d+)/i);
if(m){globalConfig.size=parseInt(m[1]);continue;}
// ### section
m=line.match(/^###\s+(.+)/);
if(m){tokens.push({type: 'section',text: m[1].trim()});continue;}
// ## subtitle
m=line.match(/^##\s+(.+)/);
if(m){tokens.push({type: 'subtitle',text: m[1].trim()});continue;}
// # title
m=line.match(/^#\s+(.+)/);
if(m){tokens.push({type: 'title',text: m[1].trim()});continue;}
// === column break
if(/^={3,}\s*$/.test(line.trim())){tokens.push({type: 'colbreak'});continue;}
// --- hr
if(/^-{3,}\s*$/.test(line.trim())){tokens.push({type: 'hr'});continue;}
// K-N
m=line.match(/^K-(\d+)\s*/i);
if(m){tokens.push({type: 'blankspace',lines: parseInt(m[1]),noNum: true});continue;}
// numbered items
m=line.match(/^([^.]+)\.\s*([A-Za-z])-(\d+)/);
if(m){
constnum=m[1];
constcode=m[2].toUpperCase();
constparam=parseInt(m[3]);
switch(code){
case'X': tokens.push({type: 'choice', num,count: param});break;
case'T': tokens.push({type: 'fill', num,count: param});break;
case'L': tokens.push({type: 'lines', num,count: param});break;
case'B': tokens.push({type: 'numbered', num,count: param});break;
case'J': tokens.push({type: 'blankspace', num,lines: param});break;
default: tokens.push({type: 'text',text: line});
}
continue;
}
tokens.push({type: 'text',text: line});
}
return{config: globalConfig, tokens };
}
/* ==============================================================
TOKEN → HTML (single item)
============================================================== */
functionrenderOneToken(tok){
switch(tok.type){
case'title':
return`<div class="sheet-item sheet-main-title">${esc(tok.text)}</div>`;
case'subtitle':
return`<div class="sheet-item sheet-sub-title">${esc(tok.text)}</div>`;
case'section':
return`<div class="sheet-item sheet-section-title">${esc(tok.text)}</div>`;
case'choice': {
constL='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
leto='';
for(leti=0;i<tok.count;i++)o+=`<span class="sheet-option-box">${L[i]}</span>`;
return`<div class="sheet-item sheet-q-row">
<span class="sheet-qnum">${tok.num}</span>
<span class="sheet-q-body"><span class="sheet-options">${o}</span></span>
</div>`;
}
case'fill': {
letb='';
for(leti=0;i<tok.count;i++)b+=`<span class="sheet-fill-blank"></span>`;
return`<div class="sheet-item sheet-q-row">
<span class="sheet-qnum">${tok.num}</span>
<span class="sheet-q-body"><span class="sheet-fill-blanks">${b}</span></span>
</div>`;
}
case'lines': {
letlh='';
for(leti=0;i<tok.count;i++)lh+=`<div class="sheet-writing-line"></div>`;
return`<div class="sheet-item sheet-q-row">
<span class="sheet-qnum">${tok.num}</span>
<span class="sheet-q-body">${lh}</span>
</div>`;
}
case'numbered': {
leto='';
for(leti=1;i<=tok.count;i++)o+=`<span class="sheet-option-box">${i}</span>`;
return`<div class="sheet-item sheet-q-row">
<span class="sheet-qnum">${tok.num}</span>
<span class="sheet-q-body"><span class="sheet-options">${o}</span></span>
</div>`;
}
case'blankspace': {
consth=tok.lines*10;
constnumHtml=tok.num
? `<span class="sheet-qnum">${tok.num}</span>`
: '';
constbodyStyle=`height:${h}mm;`;
if(tok.num){
return`<div class="sheet-item sheet-q-row">
${numHtml}
<span class="sheet-q-body"><div class="sheet-blank-inner" style="${bodyStyle}"></div></span>
</div>`;
}else{
return`<div class="sheet-item"><div class="sheet-blank-inner" style="${bodyStyle}"></div></div>`;
}
}
case'hr':
return`<hr class="sheet-item sheet-hr">`;
case'text':
return`<div class="sheet-item sheet-text">${esc(tok.text)}</div>`;
case'colbreak':
return'';// handled at layout level
default:
return'';
}
}
functionesc(s){
constd=document.createElement('div');
d.textContent=s;
returnd.innerHTML;
}
/* ==============================================================
COLUMN-AWARE LAYOUT ENGINE
with === column breaks and overflow → next page
============================================================== */
functionrender(){
constsource=document.getElementById('editor').value;
const{ config, tokens }=parse(source);
// 提取标题用于页头,从 tokens 中移除
constheaderTitles={main: '',sub: ''};
for(leti=tokens.length-1;i>=0;i--){
if(tokens[i].type==='title'){headerTitles.main=tokens[i].text;tokens.splice(i,1);}
if(tokens[i].type==='subtitle'){headerTitles.sub=tokens[i].text;tokens.splice(i,1);}
}
constfontSize=config.size||15;
constnumCols=config.split||3;
constcontainer=document.getElementById('previewContainer');
container.innerHTML='';
if(tokens.length===0){
container.appendChild(buildEmptyPage(fontSize,numCols));
applyZoom();
return;
}
// Step 1: measure each token's rendered height in a single-column context
constmeasurer=buildPageSkeleton(fontSize,numCols,false,null);
measurer.style.cssText+='position:absolute;left:-99999px;top:0;visibility:hidden;';
document.body.appendChild(measurer);
measurer.offsetHeight;
constproxyCol=document.createElement('div');
measurer.querySelectorAll('.sheet-col')[0].appendChild(proxyCol);
proxyCol.innerHTML='';
constheights=[];// { index, height, isColbreak, html }
for(leti=0;i<tokens.length;i++){
consttok=tokens[i];
if(tok.type==='colbreak'){
heights.push({index: i,height: 0,isColbreak: true,html: ''});
continue;
}
consthtml=renderOneToken(tok);
proxyCol.innerHTML=html;
consthBefore=proxyCol.scrollHeight;
proxyCol.innerHTML=html+html;
consthAfter=proxyCol.scrollHeight;
consth=hAfter-hBefore;
proxyCol.innerHTML='';
console.log(h);
heights.push({index: i,height: h,isColbreak: false, html });
proxyCol.innerHTML='';
}
consttestPage=buildPageSkeleton(fontSize,numCols);
testPage.style.cssText+='position:absolute;left:-99999px;top:0;visibility:hidden;';
document.body.appendChild(testPage);
// 强制布局计算
testPage.offsetHeight;
constcolEls=testPage.querySelectorAll('.sheet-col');
constcolHeight=colEls[0].getBoundingClientRect().height;
// 测量第一页第一栏可用高度(有页头)
consttestPageFirst=buildPageSkeleton(fontSize,numCols,true,headerTitles);
testPageFirst.style.cssText+='position:absolute;left:-99999px;top:0;visibility:hidden;';
document.body.appendChild(testPageFirst);
testPageFirst.offsetHeight;
constfirstColHeight=testPageFirst.querySelectorAll('.sheet-col')[0].getBoundingClientRect().height;
document.body.removeChild(testPageFirst);
// Step 2: bin-pack into columns → pages
constpages=[];// each page = array of numCols arrays of html strings
letcurrentPage=newPageCols(numCols);
letcurrentColIdx=0;
letcurrentPageIdx=0;
console.log(firstColHeight,colHeight);
functiongetColCapacity(){
return(currentPageIdx===0&¤tColIdx===0) ? firstColHeight : colHeight;
}
letcurrentColUsed=0;
for(constitemofheights){
// console.log(`item ${item.index}, height=${item.height}, token=${item.html}}`);
if(item.isColbreak){
// console.log(`Column break at token index ${item.index}`);
currentColIdx++;
if(currentColIdx>=numCols){
pages.push(currentPage);
currentPage=newPageCols(numCols);
currentColIdx=0;
currentPageIdx++;
}
currentColUsed=0;
continue;
}
if(currentColUsed+item.height>getColCapacity()+2&¤tColUsed>0){
console.log(`Page ${currentPageIdx+1} Col ${currentColIdx+1} full (used ${currentColUsed}px, item ${item.height}px) capacity = ${getColCapacity()}px, moving to next column`);
currentColIdx++;
if(currentColIdx>=numCols){
pages.push(currentPage);
currentPage=newPageCols(numCols);
currentColIdx=0;
currentPageIdx++;
}
currentColUsed=0;
}
currentPage[currentColIdx].push(item.html);
currentColUsed+=item.height;
}
pages.push(currentPage);
// Step 3: build DOM
for(letpi=0;pi<pages.length;pi++){
constpageCols=pages[pi];
constisFirst=(pi===0);
constpageEl=buildPageSkeleton(fontSize,numCols,isFirst,isFirst ? headerTitles : null);
constcols=pageEl.querySelectorAll('.sheet-col');
for(letc=0;c<numCols;c++){
if(pageCols[c]){
cols[c].innerHTML=pageCols[c].join('');
}
}
container.appendChild(pageEl);
}
applyZoom();
}
functionnewPageCols(n){
constarr=[];
for(leti=0;i<n;i++)arr.push([]);
returnarr;
}
functionbuildHeaderHTML(titles){
// titles = { main: '...', sub: '...' } 从解析的 title/subtitle token 获取
constmainTitle=titles.main||'';
constsubTitle=titles.sub||'';
letdots='';
for(leti=0;i<24;i++)dots+='<div class="sheet-header-dot"></div>';
letidBoxes='';
for(leti=0;i<9;i++)idBoxes+='<div class="sheet-header-id-box"></div>';
return`<div class="sheet-header">
<div class="sheet-header-dots">${dots}</div>
<div class="sheet-header-titles">
<div class="sheet-header-title-main">${esc(mainTitle)}</div>
<div class="sheet-header-title-sub">${esc(subTitle)}</div>
</div>
<div class="sheet-header-info">
<div class="sheet-header-left">
<div class="sheet-header-field">
<span class="sheet-header-field-label">姓\u2003\u2003名</span>
<span class="sheet-header-field-line"></span>
</div>
<div class="sheet-header-field" style="margin-top:4mm;">
<span class="sheet-header-field-label">准考证号</span>
<div class="sheet-header-id-boxes">${idBoxes}</div>
</div>
</div>
<div class="sheet-header-barcode">粘贴条形码区</div>
</div>
<div class="sheet-header-notice">
<div class="sheet-header-notice-left">
<div style="display:flex;align-items:flex-start;gap:2mm;">
<div class="fill-label">填涂样例</div>
<div style="align-items: center; display: flex; flex-direction: column;">
<div style="font-size:0.85em;margin-bottom:1mm;">正确填涂</div>
<div class="sheet-fill-example"><div class="sheet-fill-example-block"></div></div>
<div style="font-size:0.85em;margin-bottom:1mm;margin-top:1.5mm;">错误填涂</div>
<div class="sheet-fill-wrong-row">
<div class="sheet-fill-wrong-item">✔</div>
<div class="sheet-fill-wrong-item">✘</div>
<div class="sheet-fill-wrong-item">○</div>
</div>
<div class="sheet-fill-wrong-row" style="margin-top:1mm;">
<div class="sheet-fill-wrong-item">●</div>
<div class="sheet-fill-wrong-item">☐</div>
<div class="sheet-fill-wrong-item">□</div>
</div>
</div>
</div>
</div>
<div class="sheet-header-notice-right">
<p>1. 答题前,考生先在答题纸正面准确填写姓名、准考证号,在答题纸反面准确填写姓名,认真核对条形码上的准考证号、姓名和科目是否有误,并将核对后的条形码粘贴于指定区域。</p>
<p>2. 选择题部分必须使用2B铅笔填涂,作图使用2B铅笔,其余题型使用黑色字迹的钢笔、水笔或圆珠笔书写,字体工整、笔迹清楚。</p>
<p>3. 考生应在各题目的答题区域内作答,超出答题区域书写的答案无效。</p>
<p>4. 保持纸面清洁,不折叠,不破损。</p>
<span class="sheet-header-absence">缺考标记:<span class="sheet-header-absence-box"></span>(考生不准填涂)</span>
</div>
</div>
</div>`;
}
functionbuildPageSkeleton(fontSize,numCols,isFirstPage,headerTitles){
constpage=document.createElement('div');
page.className='sheet-page';
page.style.fontSize=fontSize+'px';
consthintText='请在各题目的答题区域内作答,超出矩形边框限定区域的答案无效';
letcolsHtml='';
for(leti=0;i<numCols;i++){
constheaderPart=(isFirstPage&&i===0&&headerTitles) ? buildHeaderHTML(headerTitles) : '';
colsHtml+=`<div class="sheet-col-outer">
${headerPart}
<div class="sheet-col-wrap">
<div class="sheet-col-hint">${hintText}</div>
<div class="sheet-col-inner">
<div class="sheet-col"></div>
</div>
<div class="sheet-col-hint-bottom">${hintText}</div>
</div>
</div>`;
}
page.innerHTML=`
<div class="sheet-outer-frame">${colsHtml}</div>
<div class="sheet-footer-mark">上海市教育考试院设计与监制</div>
`;
returnpage;
}
functionbuildEmptyPage(fontSize,numCols){
returnbuildPageSkeleton(fontSize,numCols,false,null);
}
/* ==============================================================
ZOOM
============================================================== */
functionapplyZoom(){
constpages=document.querySelectorAll('#previewContainer .sheet-page');
pages.forEach(p=>{
p.style.transform=`scale(${currentZoom/100})`;
p.style.marginBottom=`-${(1-currentZoom/100)*p.offsetHeight}px`;
constshrinkX=(1-currentZoom/100)*p.offsetWidth;
p.style.marginLeft=`-${shrinkX/2}px`;
p.style.marginRight=`-${shrinkX/2}px`;
});
document.getElementById('zoomLabel').textContent=currentZoom+'%';
}
functionzoom(delta){
currentZoom=Math.max(15,Math.min(150,currentZoom+delta));
applyZoom();
}
functionzoomFit(){
constscrollEl=document.getElementById('previewScroll');
constw=scrollEl.clientWidth-60;
constpageWidthPx=420*3.7795;
currentZoom=Math.round((w/pageWidthPx)*100);
currentZoom=Math.max(15,Math.min(150,currentZoom));
applyZoom();
}
/* ==============================================================
EDITOR
============================================================== */
consteditor=document.getElementById('editor');
editor.addEventListener('input',()=>{
clearTimeout(debounceTimer);
debounceTimer=setTimeout(render,200);
});
editor.addEventListener('keyup',updateLineInfo);
editor.addEventListener('click',updateLineInfo);
functionupdateLineInfo(){
constval=editor.value;
constpos=editor.selectionStart;
constbefore=val.substring(0,pos);
constline=before.split('\n').length;
constcol=pos-before.lastIndexOf('\n');
document.getElementById('lineInfo').textContent=`行 ${line}, 列 ${col}`;
}
editor.addEventListener('keydown',(e)=>{
if(e.key==='Tab'){
e.preventDefault();
consts=editor.selectionStart,end=editor.selectionEnd;
editor.value=editor.value.substring(0,s)+' '+editor.value.substring(end);
editor.selectionStart=editor.selectionEnd=s+2;
clearTimeout(debounceTimer);
debounceTimer=setTimeout(render,150);
}
});
/* ==============================================================
RESIZER
============================================================== */
constresizer=document.getElementById('resizer');
consteditorPanel=document.getElementById('editorPanel');
letisResizing=false;
resizer.addEventListener('mousedown',(e)=>{
isResizing=true;
resizer.classList.add('active');
document.body.style.cursor='col-resize';
document.body.style.userSelect='none';
e.preventDefault();
});
document.addEventListener('mousemove',(e)=>{
if(!isResizing)return;
constw=Math.max(280,Math.min(window.innerWidth*0.7,e.clientX));
editorPanel.style.width=w+'px';
});
document.addEventListener('mouseup',()=>{
if(isResizing){
isResizing=false;
resizer.classList.remove('active');
document.body.style.cursor='';
document.body.style.userSelect='';
setTimeout(zoomFit,100);
}
});
/* ==============================================================
DRAG & DROP
============================================================== */
constdropOverlay=document.getElementById('dropOverlay');
letdragCounter=0;
document.addEventListener('dragenter',(e)=>{e.preventDefault();dragCounter++;dropOverlay.classList.add('active');});
document.addEventListener('dragleave',(e)=>{e.preventDefault();dragCounter--;if(dragCounter<=0){dragCounter=0;dropOverlay.classList.remove('active');}});
document.addEventListener('dragover',(e)=>e.preventDefault());
document.addEventListener('drop',(e)=>{
e.preventDefault();
dragCounter=0;
dropOverlay.classList.remove('active');
constfile=e.dataTransfer.files[0];
if(file&&(file.name.endsWith('.md')||file.name.endsWith('.txt'))){
constreader=newFileReader();
reader.onload=(ev)=>{editor.value=ev.target.result;render();toast('success',`已加载: ${file.name}`);};
reader.readAsText(file);
}else{
toast('error','请拖入 .md 或 .txt 文件');
}
});
/* ==============================================================
EXPORT PDF
============================================================== */
functionexportPDF(){
constprintWin=window.open('','_blank');
constpages=document.querySelectorAll('#previewContainer .sheet-page');
letpagesHtml='';
pages.forEach((p,i)=>{
constclone=p.cloneNode(true);
clone.style.transform='none';
clone.style.marginBottom='0';
clone.style.marginRight='0';
clone.style.boxShadow='none';
if(i>0)clone.style.pageBreakBefore='always';
pagesHtml+=clone.outerHTML;
});
// Extract only relevant styles (skip dark/light media queries for print — force light)
// const styleText = document.querySelector('style').textContent;
printWin.document.write(`<!DOCTYPE html><html><head><meta charset="UTF-8"><title>答题卡</title>
<link rel="stylesheet" href="style.css">
<style>
@media print {
body { margin:0; padding:0; overflow: scroll; }
@page { size: A3 landscape; margin: 0; }
.sheet-page { page-break-after: always; box-shadow: none !important; margin-left: 0px !important; }
.sheet-page:last-child { page-break-after: auto; }
.sheet-header-dot { background: black !important; }
}
body { margin:0; padding:0; } .sheet-page { page-break-after: always; box-shadow: none !important; margin-left: 0px !important; }
</style></head><body>
<div class="print-container">${pagesHtml}</div>
<script>window.onload=function(){setTimeout(function(){window.print()},400)};<\/script>
</body></html>`);
printWin.document.close();
toast('info','打印窗口已打开,请选择「另存为 PDF」');
}
document.addEventListener('keydown',(e)=>{
if((e.ctrlKey||e.metaKey)&&e.key==='p'){e.preventDefault();exportPDF();}
});
/* ==============================================================
EXPORT .md
============================================================== */
functionexportMD(){
constcontent=editor.value;
if(!content.trim()){toast('error','编辑器为空');return;}
constblob=newBlob([content],{type: 'text/markdown;charset=utf-8'});
consturl=URL.createObjectURL(blob);
consta=document.createElement('a');
a.href=url;
a.download='答题卡.md';
a.click();
URL.revokeObjectURL(url);
toast('success','已导出 答题卡.md');
}
/* ==============================================================
TEMPLATE
============================================================== */
functioninsertTemplate(){
editor.value=`#split 3
#size 15
# 2025 年上海市普通高中学业水平等级性考试
## 物理 答题纸
### 一、光学实验
1. X-4
2. X-4
3. T-2
---
### 二、量子百年
1. X-4
2. X-5
3. T-1
4. X-4
---
### 三、滑动变阻器
1. T-2
2 (1). X-4
2 (2). T-1
2 (3). X-4
3. T-2
===
### 四、竖直圆轨道
1. X-5
2. X-4
3 (1). J-5
3 (2). J-7
---
### 五、特雷门琴
1 (1). X-3
1 (2). X-4
2 (1). T-1
2 (2). X-4
2 (3). T-2
3. X-4
===
### 六、再生制动与气囊减震
1. X-4
2. J-5
3 (1). J-5
3 (2). J-6
3 (3) (1). X-3
3 (3) (2). J-4`;
render();
toast('success','已插入示例模板');
}
/* ==============================================================
MISC
============================================================== */
functionclearEditor(){
if(editor.value.trim()&&!confirm('确定清空?'))return;
editor.value='';
render();
toast('info','已清空');
}
functionshowHelp(){document.getElementById('helpModal').classList.add('active');}
functioncloseHelp(){document.getElementById('helpModal').classList.remove('active');}
document.getElementById('helpModal').addEventListener('click',(e)=>{if(e.target===document.getElementById('helpModal'))closeHelp();});
functiontoast(type,msg){
constc=document.getElementById('toastContainer');
constel=document.createElement('div');
el.className=`toast ${type}`;
el.textContent=msg;
c.appendChild(el);
setTimeout(()=>el.remove(),3000);
}
/* ==============================================================
INIT
============================================================== */
window.addEventListener('load',()=>{setTimeout(zoomFit,100);render();insertTemplate();});
window.addEventListener('resize',()=>{clearTimeout(window._rzT);window._rzT=setTimeout(zoomFit,200);});