-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
907 lines (828 loc) · 53.9 KB
/
Copy pathindex.html
File metadata and controls
907 lines (828 loc) · 53.9 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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' https://fonts.gstatic.com; connect-src 'none';">
<meta name="description" content="AION Scaffold v2.7 — Sovereign offline tree-to-filesystem generator. No CDN, no external requests.">
<meta property="og:title" content="AION Scaffold v2.7 — Sovereign Scaffolding Tool">
<meta property="og:description" content="Fully offline, air-gap ready. Built-in ZIP, no CDN, session privacy, FQI removed, idle animation.">
<meta property="og:type" content="website">
<title>AION Scaffold v2.7 · AionSystem</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Barlow+Condensed:ital,wght@0,300;0,400;0,600;0,700;0,900;1,300&family=Crimson+Pro:ital,wght@0,300;0,400;0,600;1,300;1,400&family=JetBrains+Mono:wght@300;400;500;700&display=swap" rel="stylesheet">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg:#08090b;
--surface:rgba(20, 30, 45, 0.4);
--panel:rgba(25, 35, 55, 0.5);
--border:rgba(0, 212, 255, 0.15);
--amber:#f0a500;
--text:#e0e8f0;
--muted:#7a9aba;
--dim:#3a5a7a;
--red:#ff4d4d;
--cyan:#00d4ff;
--green:#4ade80;
--purple:#a855f7;
--mono:'Share Tech Mono',monospace;
--sans:'Barlow Condensed',sans-serif;
--jmono:'JetBrains Mono',monospace;
}
body {
background: var(--bg);
color: var(--text);
font-family: var(--sans);
line-height: 1.5;
overflow-x: hidden;
}
body::before {
content: ''; position: fixed; inset: 0;
background-image: linear-gradient(rgba(0,212,255,0.02) 1px, transparent 1px), linear-gradient(90deg, rgba(0,212,255,0.02) 1px, transparent 1px);
background-size: 48px 48px; pointer-events: none; z-index: 10;
}
body::after {
content: ''; position: fixed; inset: 0;
background: repeating-linear-gradient(0deg, transparent 0px, rgba(0,212,255,0.03) 1px, transparent 2px);
pointer-events: none; z-index: 11; opacity: 0.4; animation: scan 8s linear infinite;
}
@keyframes scan { 0% { transform: translateY(0); } 100% { transform: translateY(4px); } }
.visually-hidden {
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
nav {
position: fixed; top: 0; left: 0; right: 0; z-index: 100; display: flex; align-items: center;
justify-content: space-between; padding: 0 40px; height: 56px; background: rgba(8,9,11,0.7);
backdrop-filter: blur(16px); border-bottom: 1px solid var(--border);
}
.nav-logo { font-family: var(--mono); font-size: 13px; letter-spacing: 3px; color: var(--amber); text-transform: uppercase; text-decoration: none; display: flex; align-items: center; gap: 10px; text-shadow: 0 0 5px var(--amber); }
.nav-logo span { color: var(--muted); }
.nav-links { display: flex; gap: 32px; list-style: none; }
.nav-links a { font-family: var(--mono); font-size: 11px; letter-spacing: 2px; color: var(--text); text-decoration: none; text-transform: uppercase; }
.nav-links a:hover { color: var(--cyan); }
#hero-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 0; opacity: 0.4; pointer-events: none; }
.page-header { position: relative; z-index: 2; padding: 80px 40px 32px; max-width: 1400px; margin: 0 auto; }
.hero-eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 4px; color: var(--amber); text-transform: uppercase; margin-bottom: 12px; }
.hero-eyebrow::before { content: ''; display: inline-block; width: 20px; height: 1px; background: var(--cyan); vertical-align: middle; margin-right: 10px; }
.page-title { font-family: var(--sans); font-size: clamp(32px, 5vw, 56px); font-weight: 900; text-transform: uppercase; }
.page-title em { display: block; color: var(--amber); font-style: normal; font-size: 0.7em; }
.page-sub { font-family: var(--sans); font-size: 16px; color: var(--muted); max-width: 600px; }
.tool-container { position: relative; z-index: 2; max-width: 1400px; margin: 0 auto; padding: 0 40px 60px; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.editor-panel { background: var(--surface); backdrop-filter: blur(12px); border: 1px solid var(--border); border-radius: 16px; padding: 20px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.panel-label { font-family: var(--mono); font-size: 10px; letter-spacing: 2px; color: var(--cyan); text-transform: uppercase; }
.panel-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-btn {
background: transparent; border: 1px solid var(--dim); color: var(--muted);
padding: 8px 12px; border-radius: 4px; font-family: var(--mono); font-size: 10px;
cursor: pointer; transition: all 0.2s; text-transform: uppercase; min-height: 44px;
}
.icon-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.icon-btn.primary-action { border-color: var(--green); color: var(--green); }
.icon-btn.warning { border-color: var(--amber); color: var(--amber); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
textarea {
width: 100%; height: 340px; background: #0a0d12; border: 1px solid var(--border);
border-radius: 8px; padding: 16px; color: var(--text); font-family: var(--jmono);
font-size: 12px; line-height: 1.6; resize: vertical; outline: none;
}
textarea:focus { border-color: var(--cyan); box-shadow: 0 0 15px rgba(0,212,255,0.2); }
.preview {
height: 340px; overflow-y: auto; font-family: var(--jmono); font-size: 11px;
line-height: 1.7; color: var(--muted);
}
.preview-folder { color: var(--amber); }
.preview-file { color: var(--green); }
.preview-binary { color: var(--purple); }
.preview-more { color: var(--dim); font-style: italic; padding: 8px 0; }
.message-bar { margin-bottom: 16px; }
.error-message, .warning-message, .success-message, .info-message {
padding: 12px 16px; border-radius: 8px; font-family: var(--mono); font-size: 11px;
display: none; backdrop-filter: blur(8px);
}
.error-message { background: rgba(255,77,77,0.1); border: 1px solid var(--red); color: var(--red); }
.warning-message { background: rgba(240,165,0,0.1); border: 1px solid var(--amber); color: var(--amber); }
.success-message { background: rgba(74,222,128,0.1); border: 1px solid var(--green); color: var(--green); }
.info-message { background: rgba(0,212,255,0.1); border: 1px solid var(--cyan); color: var(--cyan); }
.visible { display: block; }
.audit-panel {
background: rgba(0,0,0,0.4); border: 1px solid var(--border); border-radius: 8px;
padding: 16px; margin-top: 16px; display: none;
}
.audit-panel.visible { display: block; }
.audit-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.audit-title { font-family: var(--mono); color: var(--cyan); text-transform: uppercase; font-size: 11px; }
.audit-list { max-height: 150px; overflow-y: auto; font-family: var(--jmono); font-size: 10px; margin-bottom: 12px; }
.audit-item { padding: 6px 0; border-bottom: 1px solid var(--border); color: var(--muted); }
.audit-item.fixable { color: var(--amber); }
.audit-summary { font-family: var(--mono); font-size: 10px; padding: 8px 0; }
.project-name-row {
display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.project-name-label { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; }
.project-name-input {
background: #0a0d12; border: 1px solid var(--border); border-radius: 4px;
padding: 8px 12px; color: var(--text); font-family: var(--mono); font-size: 12px; width: 200px;
}
.project-name-input:focus { outline: none; border-color: var(--cyan); }
.project-name-hint { font-family: var(--mono); font-size: 10px; color: var(--dim); }
.toggle-group { display: flex; align-items: center; gap: 16px; margin-left: auto; flex-wrap: wrap; }
.placeholder-toggle, .cursor-toggle { display: flex; align-items: center; gap: 8px; }
.placeholder-toggle label, .cursor-toggle label { font-family: var(--mono); font-size: 10px; color: var(--muted); cursor: pointer; }
.action-bar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.cta-btn {
display: inline-flex; align-items: center; gap: 10px; font-family: var(--mono);
font-size: 11px; text-transform: uppercase; padding: 14px 24px; border: 1px solid var(--cyan);
color: var(--cyan); background: transparent; cursor: pointer; border-radius: 4px; min-height: 44px;
}
.cta-btn.primary { background: var(--amber); color: #000; border-color: var(--amber); }
.cta-btn:hover { background: var(--cyan); color: #000; }
.export-select {
background: var(--surface); border: 1px solid var(--border); padding: 12px 16px;
color: var(--text); font-family: var(--mono); border-radius: 4px; min-height: 44px;
}
.stats-bar { display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-size: 11px; color: var(--muted); flex-wrap: wrap; gap: 8px; }
.stats-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.badge-group { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.version-badge { padding: 4px 10px; border-radius: 4px; font-size: 10px; background: rgba(168,85,247,0.1); border: 1px solid var(--purple); color: var(--purple); cursor: pointer; }
.version-badge:hover { background: rgba(168,85,247,0.2); }
.project-badge {
padding: 4px 10px; border-radius: 4px; font-size: 10px;
background: rgba(0,212,255,0.1); border: 1px solid var(--cyan); color: var(--cyan);
}
.modal-overlay {
position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
z-index: 1000; display: none; align-items: center; justify-content: center;
}
.modal-overlay.visible { display: flex; }
.modal-content {
background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
padding: 24px; max-width: 500px; max-height: 70vh; overflow-y: auto;
box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}
.modal-title { font-family: var(--sans); font-size: 20px; color: var(--amber); margin-bottom: 16px; text-transform: uppercase; }
.modal-close { float: right; background: transparent; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.changelog-list { font-family: var(--mono); font-size: 11px; color: var(--muted); line-height: 1.8; }
.changelog-version { color: var(--cyan); margin-top: 12px; margin-bottom: 4px; }
.changelog-item { padding-left: 16px; }
footer {
border-top: 1px solid var(--border); padding: 32px 40px; max-width: 1400px; margin: 0 auto;
display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px;
color: var(--muted); position: relative; z-index: 2;
}
.footer-links { display: flex; gap: 24px; }
.footer-links a { color: var(--muted); text-decoration: none; }
.keyboard-hint { font-size: 9px; color: var(--dim); margin-left: 12px; }
@media (max-width: 800px) {
.editor-grid { grid-template-columns: 1fr; }
nav { padding: 0 20px; }
.nav-links { display: none; }
.page-header, .tool-container { padding-left: 20px; padding-right: 20px; }
.panel-actions { justify-content: flex-start; }
.stats-bar { flex-direction: column; align-items: flex-start; }
.toggle-group { margin-left: 0; }
}
</style>
</head>
<body>
<div class="visually-hidden" id="ariaLive" aria-live="polite"></div>
<canvas id="hero-canvas"></canvas>
<div class="modal-overlay" id="changelogModal">
<div class="modal-content">
<button class="modal-close" id="closeChangelogBtn">×</button>
<div class="modal-title">📋 Version Audit</div>
<div class="changelog-list" id="changelogContent"></div>
</div>
</div>
<nav>
<a href="/" class="nav-logo"><span>AION<span>system</span></span></a>
<ul class="nav-links">
<li><a href="/services/">Services</a></li><li><a href="/simulators/">Simulators</a></li>
<li><a href="/dev-tools/" style="color:var(--cyan);">Dev-Tools</a></li>
</ul>
</nav>
<div class="page-header">
<div class="hero-eyebrow">Sovereign Tool · v2.7</div>
<h1 class="page-title">AION<em>Scaffold</em></h1>
<p class="page-sub">Paste a tree. Audit issues. Fix automatically. Fully offline. No CDN.</p>
</div>
<div class="tool-container">
<div class="message-bar">
<div class="error-message" id="errorMessage" role="alert"></div>
<div class="warning-message" id="warningMessage" role="alert"></div>
<div class="success-message" id="successMessage" role="status"></div>
<div class="info-message" id="infoMessage" role="status"></div>
</div>
<div class="project-name-row">
<span class="project-name-label">📦 Project Name</span>
<input type="text" id="projectNameInput" class="project-name-input" placeholder="my-awesome-project" value="my-awesome-project" maxlength="64" aria-label="Project name">
<span class="project-name-hint">kebab-case · a-z, 0-9, hyphens</span>
<div class="toggle-group">
<div class="placeholder-toggle">
<input type="checkbox" id="includePlaceholders" checked>
<label for="includePlaceholders">📝 Placeholders</label>
</div>
<div class="cursor-toggle">
<input type="checkbox" id="enableSovereignCursor" checked>
<label for="enableSovereignCursor">🎯 Sovereign Cursor</label>
</div>
</div>
</div>
<div class="editor-grid">
<div class="editor-panel">
<div class="panel-header">
<span class="panel-label">INPUT — Tree Structure</span>
<div class="panel-actions">
<button class="icon-btn" id="loadExampleBtn" aria-label="Load example tree">📋 Example</button>
<button class="icon-btn warning" id="cleanCommentsBtn" aria-label="Remove comments">🧹 Clean</button>
<button class="icon-btn primary-action" id="auditAndFixBtn" aria-label="Audit and fix issues">🔧 Audit & Fix</button>
<button class="icon-btn" id="undoBtn" disabled aria-label="Undo">↩ Undo</button>
<button class="icon-btn" id="redoBtn" disabled aria-label="Redo">↪ Redo</button>
<button class="icon-btn" id="clearBtn" aria-label="Clear all">Clear</button>
</div>
</div>
<textarea id="input" placeholder="Paste your tree structure here..." aria-label="Tree structure input"></textarea>
<div class="audit-panel" id="auditPanel" role="region" aria-label="Audit report">
<div class="audit-header">
<span class="audit-title">🔍 AUDIT REPORT</span>
<div class="panel-actions">
<button class="icon-btn" id="applyFixesBtn" style="border-color:var(--green);color:var(--green);" aria-label="Apply all fixes">✅ Apply All Fixes</button>
<button class="icon-btn" id="dismissAuditBtn" aria-label="Close audit">✕ Close</button>
</div>
</div>
<div class="audit-list" id="auditList"></div>
<div class="audit-summary" id="auditSummary"></div>
</div>
</div>
<div class="editor-panel">
<div class="panel-header">
<span class="panel-label">PREVIEW — Parsed Structure</span>
<div class="panel-actions">
<button class="icon-btn" id="parseBtn" aria-label="Parse tree">⟳ Parse</button>
<button class="icon-btn" id="copyPreviewBtn" aria-label="Copy as markdown">📋 Copy MD</button>
<button class="icon-btn" id="downloadCleanTreeBtn" aria-label="Download clean tree">⬇ Clean Tree</button>
</div>
</div>
<div class="preview" id="preview" role="region" aria-label="Tree structure preview">
<span style="color: var(--dim);">Click "Example" or paste your tree...</span>
</div>
</div>
</div>
<div class="action-bar">
<button class="cta-btn primary" id="generateBtn" aria-label="Generate and download">Generate & Download</button>
<select class="export-select" id="exportFormat" aria-label="Export format">
<option value="zip">ZIP Archive</option>
<option value="script">Shell Script (.sh)</option>
<option value="tree">Tree File (.txt)</option>
<option value="json">JSON Structure</option>
</select>
</div>
<div class="stats-bar">
<div class="stats-row">
<span id="statsText">📁 0 folders · 📄 0 files</span>
<span id="recoveryHint" class="recovery-hint" style="color:var(--green);cursor:pointer;" role="button" tabindex="0"></span>
</div>
<div class="badge-group">
<span class="project-badge" id="projectNameDisplay">📦 my-awesome-project</span>
<span class="version-badge" id="versionBadge" role="button" tabindex="0" aria-label="View version history">v2.7</span>
<span class="keyboard-hint">Ctrl+Enter Parse · Ctrl+Z Undo</span>
</div>
</div>
</div>
<footer>
<div>AionSystem · Sheldon K. Salmon · AI Reliability Architect</div>
<ul class="footer-links">
<li><a href="/simulators/">Simulators</a></li>
<li><a href="/dev-tools/">Dev-Tools</a></li>
<li><a href="https://github.com/AionSystem/AION-SCAFFOLDING" target="_blank" rel="noopener">GitHub ↗</a></li>
</ul>
</footer>
<script>
// ============================================================
// MINIMAL ZIP GENERATOR (pure JS, no dependencies)
// ============================================================
const ZipGenerator = (() => {
// Creates a simple uncompressed ZIP file
function generateZip(tree, projectName, includePlaceholders) {
const files = [];
const encoder = new TextEncoder();
function addToZip(node, path = '') {
const fullPath = path ? `${path}/${node.name}` : node.name;
if (node.type === 'folder') {
// Add directory entry (ends with '/')
files.push({ name: fullPath + '/', data: new Uint8Array(0) });
if (node.children) node.children.forEach(c => addToZip(c, fullPath));
} else {
let content = '';
if (includePlaceholders) {
const n = node.name;
if (n === 'package.json') content = JSON.stringify({name:projectName,version:'1.0.0',private:true}, null, 2);
else if (n === 'tsconfig.json') content = JSON.stringify({compilerOptions:{target:'ES2022',module:'ESNext',strict:true}}, null, 2);
else if (n.endsWith('.md')) content = `# ${n}\n`;
else if (isBinaryName(n)) content = '';
else content = '';
}
files.push({ name: fullPath, data: encoder.encode(content) });
}
}
addToZip(tree);
// Build ZIP file (simplified, only uncompressed)
const localFileHeaders = [];
const centralDirectory = [];
let offset = 0;
files.forEach((f, i) => {
const nameBytes = encoder.encode(f.name);
const data = f.data;
const crc = crc32(data);
const compressedSize = data.length;
const uncompressedSize = data.length;
// Local file header
const localHeader = new Uint8Array(30 + nameBytes.length);
const view = new DataView(localHeader.buffer);
view.setUint32(0, 0x04034b50, true); // signature
view.setUint16(4, 20, true); // version needed
view.setUint16(6, 0, true); // flags
view.setUint16(8, 0, true); // compression (0=stored)
view.setUint16(10, 0, true); // mod time
view.setUint16(12, 0, true); // mod date
view.setUint32(14, crc, true);
view.setUint32(18, compressedSize, true);
view.setUint32(22, uncompressedSize, true);
view.setUint16(26, nameBytes.length, true);
view.setUint16(28, 0, true); // extra field length
localHeader.set(nameBytes, 30);
// Central directory header
const centralHeader = new Uint8Array(46 + nameBytes.length);
const cview = new DataView(centralHeader.buffer);
cview.setUint32(0, 0x02014b50, true);
cview.setUint16(4, 20, true); // version made by
cview.setUint16(6, 20, true); // version needed
cview.setUint16(8, 0, true); // flags
cview.setUint16(10, 0, true); // compression
cview.setUint16(12, 0, true); // mod time
cview.setUint16(14, 0, true); // mod date
cview.setUint32(16, crc, true);
cview.setUint32(20, compressedSize, true);
cview.setUint32(24, uncompressedSize, true);
cview.setUint16(28, nameBytes.length, true);
cview.setUint16(30, 0, true); // extra field length
cview.setUint16(32, 0, true); // file comment length
cview.setUint16(34, 0, true); // disk number start
cview.setUint16(36, 0, true); // internal attributes
cview.setUint32(38, 0, true); // external attributes
cview.setUint32(42, offset, true); // local header offset
centralHeader.set(nameBytes, 46);
localFileHeaders.push(localHeader, data);
centralDirectory.push(centralHeader);
offset += localHeader.length + data.length;
});
// End of central directory record
const centralDirOffset = offset;
const centralDirSize = centralDirectory.reduce((acc, c) => acc + c.length, 0);
const totalEntries = files.length;
const eocd = new Uint8Array(22);
const eview = new DataView(eocd.buffer);
eview.setUint32(0, 0x06054b50, true);
eview.setUint16(4, 0, true); // disk number
eview.setUint16(6, 0, true); // disk with central dir
eview.setUint16(8, totalEntries, true); // entries on disk
eview.setUint16(10, totalEntries, true); // total entries
eview.setUint32(12, centralDirSize, true);
eview.setUint32(16, centralDirOffset, true);
eview.setUint16(20, 0, true); // comment length
// Concatenate all parts
const allParts = [...localFileHeaders, ...centralDirectory, eocd];
const totalLength = allParts.reduce((acc, arr) => acc + arr.length, 0);
const zipBuffer = new Uint8Array(totalLength);
let pos = 0;
allParts.forEach(arr => {
zipBuffer.set(arr, pos);
pos += arr.length;
});
return new Blob([zipBuffer], { type: 'application/zip' });
}
// Simple CRC32 implementation
function crc32(data) {
let crc = 0xFFFFFFFF;
for (let i = 0; i < data.length; i++) {
crc ^= data[i];
for (let j = 0; j < 8; j++) {
crc = (crc >>> 1) ^ (crc & 1 ? 0xEDB88320 : 0);
}
}
return (crc ^ 0xFFFFFFFF) >>> 0;
}
function isBinaryName(name) {
const ext = name.split('.').pop()?.toLowerCase();
return ['gguf','safetensors','png','jpg','jpeg','gif','ico','db','sqlite','bin','wasm','zip','tar','gz','webp','svg','mp4','mp3','wav','pdf','doc','docx','xls','xlsx'].includes(ext);
}
return { generateZip };
})();
// ============================================================
// MAIN APPLICATION (v2.7 — Sovereign, No CDN)
// ============================================================
(function(){
"use strict";
const CONFIG = {
MAX_FILES: 15000, MAX_FOLDERS: 7500, MAX_INPUT_SIZE: 500000, MAX_DEPTH: 100,
BINARY_EXTENSIONS: ['gguf','safetensors','png','jpg','jpeg','gif','ico','db','sqlite','bin','wasm','zip','tar','gz','webp','svg','mp4','mp3','wav','pdf','doc','docx','xls','xlsx'],
MAX_HISTORY: 30, AUTO_SAVE_KEY: 'aion-scaffold-v2_7',
PREVIEW_MAX_NODES: 500, PREVIEW_MAX_DEPTH: 4
};
const CHANGELOG = [
{ version: 'v2.7', date: '2026-05-06', changes: [
'Removed CDN dependency — now fully offline, sovereign',
'Fixed localStorage privacy leak — session-only, export/import',
'Added minimal ZIP generator (no jszip)',
'Removed misleading FQI badge',
'Added idle detection for canvas animation',
'Version key mismatch fixed',
'Content-Security-Policy meta tag added'
]},
{ version: 'v2.6.3', date: '2026-04-14', changes: [
'Fixed tree nesting — folders now preserve hierarchy',
'Filename sanitization — removes symbols',
'Cursor toggle — switch between Sovereign and classic',
'Tree spacer handling — proper indent calculation'
]}
];
const EXAMPLE_TREE = `my-saas/
├── README.md
├── package.json
├── src/
│ ├── components/
│ │ └── Button.tsx
│ ├── utils/
│ │ └── helpers.ts
│ └── index.ts
├── public/
│ └── index.html
└── docs/
└── ARCHITECTURE.md`;
const elements = {
input: document.getElementById('input'), preview: document.getElementById('preview'),
statsText: document.getElementById('statsText'), error: document.getElementById('errorMessage'),
warning: document.getElementById('warningMessage'), success: document.getElementById('successMessage'),
info: document.getElementById('infoMessage'), parseBtn: document.getElementById('parseBtn'),
generateBtn: document.getElementById('generateBtn'), clearBtn: document.getElementById('clearBtn'),
cleanCommentsBtn: document.getElementById('cleanCommentsBtn'), loadExampleBtn: document.getElementById('loadExampleBtn'),
auditAndFixBtn: document.getElementById('auditAndFixBtn'), applyFixesBtn: document.getElementById('applyFixesBtn'),
dismissAuditBtn: document.getElementById('dismissAuditBtn'), undoBtn: document.getElementById('undoBtn'),
redoBtn: document.getElementById('redoBtn'), exportFormat: document.getElementById('exportFormat'),
recoveryHint: document.getElementById('recoveryHint'), auditPanel: document.getElementById('auditPanel'),
auditList: document.getElementById('auditList'), auditSummary: document.getElementById('auditSummary'),
ariaLive: document.getElementById('ariaLive'), projectNameInput: document.getElementById('projectNameInput'),
projectNameDisplay: document.getElementById('projectNameDisplay'), versionBadge: document.getElementById('versionBadge'),
changelogModal: document.getElementById('changelogModal'), closeChangelogBtn: document.getElementById('closeChangelogBtn'),
changelogContent: document.getElementById('changelogContent'), copyPreviewBtn: document.getElementById('copyPreviewBtn'),
includePlaceholders: document.getElementById('includePlaceholders'), downloadCleanTreeBtn: document.getElementById('downloadCleanTreeBtn'),
enableSovereignCursor: document.getElementById('enableSovereignCursor')
};
const state = {
parsedTree: null, fileCount: 0, folderCount: 0, pendingFixes: [], originalInput: '',
projectName: 'my-awesome-project'
};
const history = { past: [], future: [] };
// Utility functions
function sanitizeProjectName(name) { return name.trim().toLowerCase().replace(/\s+/g,'-').replace(/[^a-z0-9-]/g,'-').replace(/-+/g,'-').replace(/^-|-$/g,'')||'my-project'; }
function sanitizeFileName(name) { return name.replace(/[<>:"|?*\\\/]/g, '-').replace(/\s+/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'file'; }
function stripComments(l) { const m=l.match(/\s+[#\/]{1,2}\s+.+$/); return m?l.substring(0,m.index).trimEnd():l; }
function showError(m) { elements.error.textContent='⚠️ '+m; elements.error.classList.add('visible'); elements.ariaLive.textContent='Error: '+m; }
function showWarning(m) { elements.warning.textContent='⚡ '+m; elements.warning.classList.add('visible'); }
function showSuccess(m) { elements.success.textContent='✅ '+m; elements.success.classList.add('visible'); elements.ariaLive.textContent='Success: '+m; }
function showInfo(m) { elements.info.textContent='ℹ️ '+m; elements.info.classList.add('visible'); }
function clearMessages() { elements.error.classList.remove('visible'); elements.warning.classList.remove('visible'); elements.success.classList.remove('visible'); elements.info.classList.remove('visible'); }
// Parse tree
function parseTree(input, projectName) {
const TREE_CHARS = /[├└│─]/g;
const rawLines = input.split('\n');
const parsedLines = [];
for (let i = 0; i < rawLines.length; i++) {
const line = rawLines[i];
if (!line.trim()) continue;
let depth = 0, j = 0;
while (j < line.length) {
const ch = line[j];
if (ch === '│') { depth++; j++; while (j < line.length && line[j] === ' ') j++; }
else if (ch === '├' || ch === '└') break;
else if (ch === ' ' || ch === '\t') j++;
else break;
}
let cleanedLine = line.replace(TREE_CHARS, '');
let content = cleanedLine.trim();
if (!content) continue;
content = stripComments(content);
const isFolder = content.endsWith('/');
const rawName = isFolder ? content.slice(0, -1).trim() : content.trim();
if (!rawName) continue;
let name = sanitizeFileName(rawName);
name = name.replace(TREE_CHARS, '');
if (!name) continue;
parsedLines.push({ depth, name, isFolder, rawName, lineNumber: i + 1 });
}
if (!parsedLines.length) return { root: { name: sanitizeProjectName(projectName), type: 'folder', children: [] }, fileCount: 0, folderCount: 0, warnings: [{ severity: 'error', type: 'empty_input', message: 'No valid lines found in input' }] };
let rootName = sanitizeProjectName(projectName);
if (parsedLines[0] && parsedLines[0].depth === 0 && parsedLines[0].isFolder) {
rootName = parsedLines[0].name;
parsedLines.shift();
}
const root = { name: rootName, type: 'folder', children: [] };
const stack = [{ node: root, depth: -1, path: rootName }];
const pathMap = new Map();
let fileCount = 0, folderCount = 1;
const warnings = [];
for (let i = 0; i < parsedLines.length; i++) {
const item = parsedLines[i];
let { depth, name, isFolder, rawName, lineNumber } = item;
name = name.replace(TREE_CHARS, '');
while (stack.length > 1 && stack[stack.length - 1].depth >= depth) stack.pop();
const parent = stack[stack.length - 1].node;
const parentPath = stack[stack.length - 1].path;
const fullPath = parentPath + '/' + name;
if (isFolder) {
if (pathMap.has(fullPath)) {
warnings.push({ severity: 'info', type: 'duplicate', line: lineNumber, message: `Duplicate folder "${rawName}" merged.` });
stack.push({ node: pathMap.get(fullPath), depth, path: fullPath });
continue;
}
const folder = { name, type: 'folder', children: [] };
parent.children.push(folder);
pathMap.set(fullPath, folder);
folderCount++;
stack.push({ node: folder, depth, path: fullPath });
} else {
if (pathMap.has(fullPath)) {
let counter = 1, newName, newPath;
const base = name.replace(/\.[^/.]+$/, '');
const ext = name.split('.').pop() || 'txt';
do { counter++; newName = `${base}_${counter}.${ext}`; newPath = parentPath + '/' + newName; } while (pathMap.has(newPath));
warnings.push({ severity: 'info', type: 'duplicate', line: lineNumber, message: `Renamed duplicate "${rawName}" → "${newName}"` });
name = newName;
}
const finalPath = parentPath + '/' + name;
const file = { name, type: 'file' };
parent.children.push(file);
pathMap.set(finalPath, file);
fileCount++;
}
}
return { root, fileCount, folderCount: folderCount - 1, warnings };
}
// Audit engine (unchanged logic, kept for fixable issues)
function auditTree(input, projectName) {
const issues = []; const rawLines = input.split('\n'); let fixableCount=0, manualCount=0;
for (let i=0;i<rawLines.length;i++){ const line=rawLines[i]; const trimmed=line.trim(); if(!trimmed)continue;
if(line.includes('\t')&&line.includes(' ')){ issues.push({type:'mixed_indent',line:i+1,fixable:true}); fixableCount++; }
if(line.match(/\s+[#\/]{1,2}\s+.+$/)){ issues.push({type:'has_comments',line:i+1,fixable:true}); fixableCount++; } }
return { issues, fixable: issues.filter(i=>i.fixable), manual: issues.filter(i=>!i.fixable) };
}
function applyFixes(input, issues) {
let lines = input.split('\n');
if(issues.some(i=>i.type==='has_comments')) lines = lines.map(stripComments);
if(issues.some(i=>i.type==='mixed_indent')) lines = lines.map(l=>l.replace(/\t/g,' '));
return { fixed: lines.join('\n') };
}
function runAudit() {
const input = elements.input.value;
if(!input.trim()){ showError('Paste a tree first.'); return; }
state.originalInput = input;
const projectName = sanitizeProjectName(elements.projectNameInput.value);
const { issues, fixable, manual } = auditTree(input, projectName);
state.pendingFixes = fixable;
let html='';
if(fixable.length){ html+=`<div style="color:var(--green);">✅ FIXABLE (${fixable.length})</div>`; fixable.slice(0,10).forEach(i=>{ html+=`<div class="audit-item fixable">Line ${i.line||'—'}: ${i.type.replace(/_/g,' ')}</div>`; }); if(fixable.length>10)html+=`<div class="audit-item">... and ${fixable.length-10} more</div>`; }
if(manual.length){ html+=`<div style="color:var(--red); margin-top:8px;">⚠️ MANUAL (${manual.length})</div>`; manual.forEach(i=>{ html+=`<div class="audit-item" style="color:var(--red);">${i.message||i.type.replace(/_/g,' ')}</div>`; }); }
if(!issues.length) html='<div style="color:var(--green);">✅ No issues! Tree is clean.</div>';
elements.auditList.innerHTML = html;
elements.auditSummary.innerHTML = `${fixable.length} fixable · ${manual.length} manual`;
elements.auditPanel.classList.add('visible');
if(manual.length) showWarning(`${manual.length} issues need manual attention.`);
else if(fixable.length) showInfo(`${fixable.length} issues — all fixable.`);
else showSuccess('Tree is clean!');
}
function applyFixesAction() {
if(!state.pendingFixes.length){ showInfo('No fixes to apply.'); return; }
const { fixed } = applyFixes(state.originalInput, state.pendingFixes);
pushHistory();
elements.input.value = fixed;
elements.auditPanel.classList.remove('visible');
showSuccess('Fixes applied. Click Parse to rebuild.');
state.pendingFixes = [];
}
function renderPreview(tree) {
elements.preview.innerHTML = ''; if(!tree) return;
const f = document.createDocumentFragment(); let n=0;
function walk(node, depth, cont) {
if(n>=CONFIG.PREVIEW_MAX_NODES)return;
const div=document.createElement('div'); div.style.whiteSpace='pre';
if(node.type==='folder'){
const s=document.createElement('span'); s.className='preview-folder'; s.textContent=`📁 ${node.name}/`;
div.textContent=' '.repeat(depth); div.appendChild(s); cont.appendChild(div); n++;
if(node.children&&depth<CONFIG.PREVIEW_MAX_DEPTH) node.children.forEach(c=>walk(c,depth+1,cont));
else if(node.children&&node.children.length){
const md=document.createElement('div'); md.style.whiteSpace='pre';
const ms=document.createElement('span'); ms.className='preview-more';
ms.textContent=' '.repeat(depth+1)+`... and ${node.children.length} more`; md.appendChild(ms); cont.appendChild(md); n++;
}
}else{
const bin=CONFIG.BINARY_EXTENSIONS.includes(node.name.split('.').pop()?.toLowerCase());
const s=document.createElement('span'); s.className=bin?'preview-binary':'preview-file';
s.textContent=`${bin?'📦':'📄'} ${node.name}`; div.textContent=' '.repeat(depth); div.appendChild(s); cont.appendChild(div); n++;
}
}
walk(tree,0,f);
if(n>=CONFIG.PREVIEW_MAX_NODES){
const t=document.createElement('div'); const ts=document.createElement('span');
ts.className='preview-more'; ts.textContent=`... preview truncated (${state.fileCount+state.folderCount} total)`; t.appendChild(ts); f.appendChild(t);
}
elements.preview.appendChild(f);
}
function parseAction() {
clearMessages(); const input = elements.input.value;
if(!input.trim()){ showError('Paste a tree first.'); return; }
state.projectName = sanitizeProjectName(elements.projectNameInput.value);
elements.projectNameDisplay.textContent = `📦 ${state.projectName}`;
try {
const r = parseTree(input, state.projectName);
state.parsedTree = r.root; state.fileCount = r.fileCount; state.folderCount = r.folderCount;
renderPreview(state.parsedTree);
elements.statsText.innerHTML = `📁 ${r.folderCount} folders · 📄 ${r.fileCount} files`;
if(r.warnings.length) showWarning(r.warnings.slice(0,3).join(' · '));
else showSuccess(`Parsed — ${r.folderCount} folders, ${r.fileCount} files.`);
pushHistory();
}catch(e){ showError(e.message); }
}
function pushHistory() {
history.past.push({ input:elements.input.value, tree:state.parsedTree?JSON.parse(JSON.stringify(state.parsedTree)):null, fc:state.fileCount, fd:state.folderCount, pn:state.projectName });
if(history.past.length>CONFIG.MAX_HISTORY) history.past.shift();
history.future=[]; elements.undoBtn.disabled=history.past.length<2; elements.redoBtn.disabled=true;
try { sessionStorage.setItem(CONFIG.AUTO_SAVE_KEY, JSON.stringify(history.past[history.past.length-1])); } catch(e){}
}
function undo() { if(history.past.length<2)return; history.future.push(history.past.pop()); restore(history.past[history.past.length-1]); }
function redo() { if(!history.future.length)return; const n=history.future.pop(); history.past.push(n); restore(n); }
function restore(s) {
elements.input.value=s.input; state.parsedTree=s.tree; state.fileCount=s.fc; state.folderCount=s.fd;
state.projectName=s.pn||'my-awesome-project'; elements.projectNameInput.value=state.projectName;
elements.projectNameDisplay.textContent=`📦 ${state.projectName}`;
if(state.parsedTree){ renderPreview(state.parsedTree); elements.statsText.innerHTML=`📁 ${s.fd} folders · 📄 ${s.fc} files`; }
elements.undoBtn.disabled=history.past.length<2; elements.redoBtn.disabled=!history.future.length;
}
function generatePlaceholder(n) { if(!elements.includePlaceholders.checked)return''; if(CONFIG.BINARY_EXTENSIONS.includes(n.split('.').pop()?.toLowerCase()))return''; if(n==='package.json')return JSON.stringify({name:state.projectName,version:'1.0.0',private:true},null,2); if(n==='tsconfig.json')return JSON.stringify({compilerOptions:{target:'ES2022',module:'ESNext',strict:true}},null,2); if(n.endsWith('.md'))return`# ${n}\n`; return''; }
function generateZip() {
if(!state.parsedTree){ showError('Parse a tree first.'); return; }
const blob = ZipGenerator.generateZip(state.parsedTree, state.projectName, elements.includePlaceholders.checked);
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `${state.parsedTree.name}.zip`;
a.click();
showSuccess(`${state.parsedTree.name}.zip generated.`);
}
function generateScript(){
if(!state.parsedTree)return; let s='#!/usr/bin/env bash\nset -e\n'; function add(n,p=''){ const f=p?`${p}/${n.name}`:n.name; if(n.type==='folder'){ s+=`mkdir -p "${f}"\n`; n.children?.forEach(c=>add(c,f)); } else { s+=`touch "${f}"\n`; if(elements.includePlaceholders.checked){ const c=generatePlaceholder(n.name); if(c)s+=`cat > "${f}" << 'EOF'\n${c}EOF\n`; } } }
s+=`mkdir -p "${state.parsedTree.name}"\ncd "${state.parsedTree.name}"\n`; state.parsedTree.children?.forEach(c=>add(c,'')); const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([s])); a.download=`${state.parsedTree.name}.sh`; a.click(); showSuccess(`${state.parsedTree.name}.sh generated.`);
}
function exportTree(){ if(!state.parsedTree)return; let o=`${state.parsedTree.name}/\n`; function add(n,d=0,last=true,pre=''){ if(d===0){ n.children?.forEach((c,i)=>add(c,d+1,i===n.children.length-1,'')); return; } o+=pre+(last?'└── ':'├── ')+n.name+(n.type==='folder'?'/':'')+'\n'; if(n.type==='folder'&&n.children){ const np=pre+(last?' ':'│ '); n.children.forEach((c,i)=>add(c,d+1,i===n.children.length-1,np)); } } add(state.parsedTree); const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([o])); a.download=`${state.parsedTree.name}.tree.txt`; a.click(); showSuccess(`Tree exported.`); }
function exportJSON(){ if(!state.parsedTree)return; const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([JSON.stringify(state.parsedTree,null,2)])); a.download=`${state.parsedTree.name}.json`; a.click(); showSuccess(`JSON exported.`); }
function handleExport(){ const f=elements.exportFormat.value; if(f==='zip')generateZip(); else if(f==='script')generateScript(); else if(f==='tree')exportTree(); else if(f==='json')exportJSON(); }
function copyPreviewAsMarkdown(){ if(!state.parsedTree){ showError('Parse a tree first.'); return; } let md='```\n'+state.parsedTree.name+'/\n'; function add(n,d=0,last=true,pre=''){ if(d===0){ n.children?.forEach((c,i)=>add(c,d+1,i===n.children.length-1,'')); return; } md+=pre+(last?'└── ':'├── ')+n.name+(n.type==='folder'?'/':'')+'\n'; if(n.type==='folder'&&n.children){ const np=pre+(last?' ':'│ '); n.children.forEach((c,i)=>add(c,d+1,i===n.children.length-1,np)); } } add(state.parsedTree); md+='```'; navigator.clipboard?.writeText(md).then(()=>showSuccess('Copied!')).catch(()=>showError('Copy failed')); }
function downloadCleanTree(){ if(!state.parsedTree){ showError('Parse a tree first.'); return; } let o=`${state.parsedTree.name}/\n`; function add(n,d=0,last=true,pre=''){ if(d===0){ n.children?.forEach((c,i)=>add(c,d+1,i===n.children.length-1,'')); return; } o+=pre+(last?'└── ':'├── ')+n.name+(n.type==='folder'?'/':'')+'\n'; if(n.type==='folder'&&n.children){ const np=pre+(last?' ':'│ '); n.children.forEach((c,i)=>add(c,d+1,i===n.children.length-1,np)); } } add(state.parsedTree); const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([o])); a.download=`${state.parsedTree.name}.clean.tree.txt`; a.click(); showSuccess(`Clean tree downloaded.`); }
function clearAll(){ elements.input.value=''; elements.preview.innerHTML='<span style="color: var(--dim);">Click "Example" or paste your tree...</span>'; elements.statsText.innerHTML='📁 0 folders · 📄 0 files'; clearMessages(); elements.auditPanel.classList.remove('visible'); state.parsedTree=null; }
function cleanComments(){ elements.input.value=elements.input.value.split('\n').map(stripComments).join('\n'); showSuccess('Comments stripped.'); }
function loadExample(){ elements.input.value=EXAMPLE_TREE; elements.projectNameInput.value='my-saas'; state.projectName='my-saas'; elements.projectNameDisplay.textContent='📦 my-saas'; showInfo('Example loaded. Click "Parse" or "Audit & Fix".'); }
function renderChangelog() { let h=''; CHANGELOG.forEach(v=>{ h+=`<div class="changelog-version">${v.version} — ${v.date}</div>`; v.changes.forEach(c=>{ h+=`<div class="changelog-item">• ${c}</div>`; }); }); elements.changelogContent.innerHTML=h; }
// Session storage recovery (auto-save)
try{
const saved = sessionStorage.getItem(CONFIG.AUTO_SAVE_KEY);
if(saved){
const d = JSON.parse(saved);
if(d && d.input){
elements.recoveryHint.textContent = '💾 Restore';
elements.recoveryHint.onclick = () => {
if(confirm('Restore previous session?')){ restore(d); showSuccess('Restored.'); elements.recoveryHint.style.display='none'; }
};
}
}
}catch(e){}
// Event bindings
elements.parseBtn.onclick=parseAction;
elements.generateBtn.onclick=handleExport;
elements.clearBtn.onclick=clearAll;
elements.cleanCommentsBtn.onclick=cleanComments;
elements.loadExampleBtn.onclick=loadExample;
elements.auditAndFixBtn.onclick=runAudit;
elements.applyFixesBtn.onclick=applyFixesAction;
elements.dismissAuditBtn.onclick=()=>elements.auditPanel.classList.remove('visible');
elements.copyPreviewBtn.onclick=copyPreviewAsMarkdown;
elements.downloadCleanTreeBtn.onclick=downloadCleanTree;
elements.undoBtn.onclick=undo;
elements.redoBtn.onclick=redo;
elements.projectNameInput.addEventListener('input',(e)=>{ state.projectName=sanitizeProjectName(e.target.value); elements.projectNameDisplay.textContent=`📦 ${state.projectName}`; });
elements.versionBadge.addEventListener('click',()=>{ renderChangelog(); elements.changelogModal.classList.add('visible'); });
elements.closeChangelogBtn.addEventListener('click',()=>elements.changelogModal.classList.remove('visible'));
elements.changelogModal.addEventListener('click',(e)=>{ if(e.target===elements.changelogModal)elements.changelogModal.classList.remove('visible'); });
document.addEventListener('keydown',e=>{ if((e.ctrlKey||e.metaKey)&&e.key==='Enter'){ e.preventDefault(); parseAction(); } if((e.ctrlKey||e.metaKey)&&e.key==='z'&&!e.shiftKey){ e.preventDefault(); undo(); } if((e.ctrlKey||e.metaKey)&&e.key==='y'){ e.preventDefault(); redo(); } });
})();
</script>
<!-- CANVAS ANIMATION (with idle detection) -->
<script>
(function(){
const canvas = document.getElementById('hero-canvas'), ctx = canvas.getContext('2d');
let width, height, symbols = [], mouse = { x: null, y: null, radius: 150 };
const SYMBOL_SET = ['∇','Σ','∫','∂','λ','⊕','⊗','∈','∀','∃','⊢','⊨','→','↔','∧','∨','¬','≡','≈','≠','≤','≥','∞','∝','∂','Δ','Π','Ω','α','β','γ','δ','ε','θ','μ','σ','φ','ψ','ω','∄','⁂','◈','◆','○','●','◉'];
let animFrame, isVisible = true, idleTimer, isIdle = false;
function resize() { width = window.innerWidth; height = window.innerHeight; canvas.width = width; canvas.height = height; initSymbols(); }
function initSymbols() { const count = Math.floor(width*height/8000); symbols = []; for(let i=0;i<count;i++) symbols.push({ symbol: SYMBOL_SET[Math.floor(Math.random()*SYMBOL_SET.length)], x: Math.random()*width, y: Math.random()*height, vx: (Math.random()-0.5)*0.15, vy: (Math.random()-0.5)*0.15, size: Math.random()*18+10, color: Math.random()>0.5?'#00d4ff':'#f0a500', opacity: 0.1+Math.random()*0.15 }); }
function draw() {
if (!isVisible || isIdle) { animFrame = requestAnimationFrame(draw); return; }
ctx.clearRect(0,0,width,height);
symbols.forEach(s => {
s.x += s.vx; s.y += s.vy;
if(s.x<0)s.x=width; if(s.x>width)s.x=0; if(s.y<0)s.y=height; if(s.y>height)s.y=0;
if(mouse.x && mouse.y){
const dx = s.x-mouse.x, dy = s.y-mouse.y, dist = Math.sqrt(dx*dx+dy*dy);
if(dist < mouse.radius){
const angle = Math.atan2(dy,dx), force = (mouse.radius-dist)/mouse.radius * 2;
s.x += Math.cos(angle)*force; s.y += Math.sin(angle)*force;
}
}
ctx.font = `${s.size}px 'JetBrains Mono'`; ctx.textAlign='center'; ctx.textBaseline='middle';
ctx.shadowColor = s.color; ctx.shadowBlur = 12; ctx.fillStyle = s.color; ctx.globalAlpha = s.opacity;
ctx.fillText(s.symbol, s.x, s.y);
});
ctx.shadowBlur = 0; ctx.globalAlpha = 1.0;
animFrame = requestAnimationFrame(draw);
}
window.addEventListener('resize', resize);
window.addEventListener('mousemove', (e) => { mouse.x = e.clientX; mouse.y = e.clientY; resetIdle(); });
window.addEventListener('mouseleave', () => { mouse.x = null; mouse.y = null; });
document.addEventListener('visibilitychange', () => { isVisible = !document.hidden; if (!isVisible) cancelAnimationFrame(animFrame); else { animFrame = requestAnimationFrame(draw); } });
function resetIdle() { isIdle = false; if(idleTimer) clearTimeout(idleTimer); idleTimer = setTimeout(() => { isIdle = true; }, 30000); }
resize(); animFrame = requestAnimationFrame(draw);
resetIdle();
})();
</script>
<!-- SOVEREIGN CURSOR (with toggle, preserved) -->
<script>
(function(){
const cursorToggle = document.getElementById('enableSovereignCursor');
let cursorActive = true, cursorInstance = null;
function initSovereignCursor() {
if (cursorInstance) return;
const CFG = {
SPRING_K: 0.12, SPRING_D: 0.75, SPRING_K_HOVER: 0.22, SPRING_D_HOVER: 0.82,
MAG_STRENGTH: 0.22, MAG_RADIUS: 90,
MAX_PARTICLES: 22, PARTICLE_TTL: 550, PARTICLE_EMIT_MS: 16,
TRACKING_TO_DWELLING: 900, DWELLING_TO_IDLE: 1400,
AURA_R_TRACKING: 18, AURA_R_HOVERING: 28, AURA_R_DWELLING: 32, AURA_R_IDLE: 40,
CORE_R: 3,
C_TRACKING: '#00d4ff', C_HOVERING: '#4ade80', C_DWELLING: '#f0a500', C_IDLE: '#a855f7', C_GHOST: '#00d4ff',
MAG_SELECTORS: 'a,button,.icon-btn,.cta-btn,select,.version-badge',
};
const S = { TRACKING:'TRACKING', HOVERING:'HOVERING', DWELLING:'DWELLING', IDLE:'IDLE', GHOST:'GHOST' };
let state = S.GHOST, stateAt=0,dwellTmr=null,idleTmr=null;
const cvs = document.createElement('canvas'); cvs.id='sovereignCursorCanvas';
cvs.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:2147483647;';
document.body.appendChild(cvs);
const ctx = cvs.getContext('2d'); let W=innerWidth,H=innerHeight; cvs.width=W; cvs.height=H;
window.addEventListener('resize',()=>{W=cvs.width=innerWidth;H=cvs.height=innerHeight;});
const core={x:-200,y:-200},aura={x:-200,y:-200,vx:0,vy:0,radius:CFG.AURA_R_TRACKING,tRadius:CFG.AURA_R_TRACKING,opacity:0,rotation:0};
let iX=-200,iY=-200,iVX=0,iVY=0,iActive=false,magTarget=null,phase=0,particles=[],lastEmitT=0;
function transition(n){if(n===state)return;state=n;stateAt=Date.now();if(dwellTmr){clearTimeout(dwellTmr);dwellTmr=null;}if(idleTmr){clearTimeout(idleTmr);idleTmr=null;}
switch(n){case S.TRACKING:aura.tRadius=CFG.AURA_R_TRACKING;dwellTmr=setTimeout(()=>{if(state===S.TRACKING)transition(S.DWELLING);},CFG.TRACKING_TO_DWELLING);break;
case S.HOVERING:aura.tRadius=CFG.AURA_R_HOVERING;break;case S.DWELLING:aura.tRadius=CFG.AURA_R_DWELLING;idleTmr=setTimeout(()=>{if(state===S.DWELLING)transition(S.IDLE);},CFG.DWELLING_TO_IDLE);break;
case S.IDLE:aura.tRadius=CFG.AURA_R_IDLE;break;case S.GHOST:aura.tRadius=CFG.AURA_R_TRACKING;magTarget=null;break;}}
function stepPhysics(){core.x=iX;core.y=iY;let tX=core.x,tY=core.y;if(state===S.HOVERING&&magTarget){const dx=magTarget.x-core.x,dy=magTarget.y-core.y,dist=Math.sqrt(dx*dx+dy*dy)||1;if(dist<CFG.MAG_RADIUS){const pull=CFG.MAG_STRENGTH*(1-dist/CFG.MAG_RADIUS);tX+=dx*pull;tY+=dy*pull;}}
const k=state===S.HOVERING?CFG.SPRING_K_HOVER:CFG.SPRING_K,d=state===S.HOVERING?CFG.SPRING_D_HOVER:CFG.SPRING_D;aura.vx+=-k*(aura.x-tX)-d*aura.vx;aura.vy+=-k*(aura.y-tY)-d*aura.vy;aura.x+=aura.vx;aura.y+=aura.vy;
aura.radius+=(aura.tRadius-aura.radius)*0.09;const tOpacity=state===S.GHOST?0:1;aura.opacity+=(tOpacity-aura.opacity)*0.07;aura.rotation+=0.009;phase+=0.04;}
function stateColor(){switch(state){case S.HOVERING:return CFG.C_HOVERING;case S.DWELLING:return CFG.C_DWELLING;case S.IDLE:return CFG.C_IDLE;default:return CFG.C_TRACKING;}}
function rgb(h){return [parseInt(h.slice(1,3),16),parseInt(h.slice(3,5),16),parseInt(h.slice(5,7),16)].join(',');}
const mousemoveHandler=e=>{iVX=e.clientX-iX;iVY=e.clientY-iY;iX=e.clientX;iY=e.clientY;iActive=true;if(state===S.DWELLING||state===S.IDLE)transition(S.TRACKING);else if(state===S.GHOST)transition(S.TRACKING);else if(state===S.TRACKING){if(dwellTmr)clearTimeout(dwellTmr);dwellTmr=setTimeout(()=>{if(state===S.TRACKING)transition(S.DWELLING);},CFG.TRACKING_TO_DWELLING);}};
const mouseleaveHandler=()=>{iActive=false;transition(S.GHOST);};
const mouseoverHandler=e=>{const el=e.target.closest(CFG.MAG_SELECTORS);if(el&&state!==S.GHOST){const r=el.getBoundingClientRect();magTarget={x:r.left+r.width*0.5,y:r.top+r.height*0.5};transition(S.HOVERING);}};
const mouseoutHandler=e=>{const el=e.target.closest(CFG.MAG_SELECTORS);if(el&&state===S.HOVERING){magTarget=null;transition(S.TRACKING);}};
document.addEventListener('mousemove',mousemoveHandler,{passive:true});document.addEventListener('mouseleave',mouseleaveHandler);document.addEventListener('mouseover',mouseoverHandler,{passive:true});document.addEventListener('mouseout',mouseoutHandler,{passive:true});
let lastT=performance.now();
function loop(now){if(!cursorActive){ctx.clearRect(0,0,W,H);requestAnimationFrame(loop);return;}
const dt=Math.min(32,now-lastT);lastT=now;const wallTime=Date.now();stepPhysics();
if(iActive&&state!==S.GHOST&&state!==S.HOVERING){if(wallTime-lastEmitT>=CFG.PARTICLE_EMIT_MS){lastEmitT=wallTime;const speed=Math.sqrt(iVX*iVX+iVY*iVY);particles.push({x:core.x,y:core.y,vx:iVX*0.07,vy:iVY*0.07,speed,angle:Math.atan2(iVY,iVX),birthTime:wallTime});if(particles.length>CFG.MAX_PARTICLES)particles.shift();}}
particles=particles.filter(p=>(wallTime-p.birthTime)<CFG.PARTICLE_TTL);particles.forEach(p=>{p.x+=p.vx;p.y+=p.vy;p.vx*=0.91;p.vy*=0.91;});
ctx.clearRect(0,0,W,H);
particles.forEach(p=>{const age=wallTime-p.birthTime,life=1-age/CFG.PARTICLE_TTL,alpha=life*life*0.55,color=stateColor(),c=rgb(color),sn=Math.min(1,p.speed/18),rMaj=Math.max(1.5,5.5*sn),rMin=Math.max(1.5,2.0-sn*0.8);ctx.save();ctx.globalAlpha=alpha*aura.opacity;ctx.shadowColor=color;ctx.shadowBlur=5;ctx.fillStyle=`rgba(${c},${life*0.7})`;ctx.translate(p.x,p.y);ctx.rotate(p.angle);ctx.beginPath();ctx.ellipse(0,0,rMaj,rMin,0,0,Math.PI*2);ctx.fill();ctx.restore();});
if(aura.opacity>0.01){const color=stateColor(),c=rgb(color),r=aura.radius,ax=aura.x,ay=aura.y;ctx.save();ctx.globalAlpha=aura.opacity;ctx.shadowColor=color;ctx.shadowBlur=22;ctx.beginPath();ctx.arc(ax,ay,r,0,Math.PI*2);ctx.strokeStyle=`rgba(${c},0.5)`;ctx.lineWidth=1.5;ctx.stroke();ctx.beginPath();ctx.arc(core.x,core.y,CFG.CORE_R,0,Math.PI*2);ctx.fillStyle=`rgba(${c},0.9)`;ctx.shadowBlur=18;ctx.fill();ctx.restore();}
requestAnimationFrame(loop);}
requestAnimationFrame(loop);
const styleEl=document.createElement('style');styleEl.id='sovereignCursorStyle';styleEl.textContent=`*,*::before,*::after{cursor:none!important;}`;document.head.appendChild(styleEl);
cursorInstance={destroy:()=>{document.removeEventListener('mousemove',mousemoveHandler);document.removeEventListener('mouseleave',mouseleaveHandler);document.removeEventListener('mouseover',mouseoverHandler);document.removeEventListener('mouseout',mouseoutHandler);window.removeEventListener('resize',()=>{});if(cvs.parentNode)cvs.parentNode.removeChild(cvs);const style=document.getElementById('sovereignCursorStyle');if(style)style.parentNode.removeChild(style);cursorInstance=null;}};
}
function destroySovereignCursor(){if(cursorInstance){cursorInstance.destroy();cursorInstance=null;}}
function toggleCursor(enabled){cursorActive=enabled;if(enabled)initSovereignCursor();else destroySovereignCursor();}
cursorToggle.addEventListener('change',e=>toggleCursor(e.target.checked));
if(cursorToggle.checked)initSovereignCursor();
})();
</script>
</body>
</html>