-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdev.html
More file actions
3633 lines (3439 loc) · 154 KB
/
Copy pathdev.html
File metadata and controls
3633 lines (3439 loc) · 154 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
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<meta name="theme-color" content="#000000">
<meta name="description" content="webXOS DEV — a JEV-compatible decision engine for developers. Local CAD kernel, vector models, IndexedDB, offline.">
<title>webXOS DEV — JEV Clone</title>
<style>
:root{
--bg:#050505; --bg2:#0a0a0a; --bg3:#0f0f0f; --panel:#0c0c0c;
--border:#1a1a1a; --border2:#242424; --border3:#333;
--fg:#c8c8c8; --fg2:#8a8a8a; --fg3:#555;
--accent:#00e0c0; --accent2:#ffb000; --accent3:#4d8dff;
--ok:#00ff88; --warn:#ffb000; --err:#ff3b3b;
--mono:'IBM Plex Mono','JetBrains Mono','SF Mono',Menlo,Consolas,'Courier New',monospace;
--sans:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;background:var(--bg);color:var(--fg);font-family:var(--mono);font-size:12px;line-height:1.55;overflow:hidden;-webkit-font-smoothing:antialiased}
body{display:flex;flex-direction:column}
::selection{background:var(--accent);color:#000}
::-webkit-scrollbar{width:8px;height:8px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:#222;border:1px solid #111}
::-webkit-scrollbar-thumb:hover{background:#333}
:focus-visible{outline:1px solid var(--accent);outline-offset:1px}
button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,[tabindex]:focus-visible{outline:1px solid var(--accent);outline-offset:1px}
/* ============ WIZARD ============ */
#wizard{position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,.94);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(6px)}
#wizard.hidden{display:none}
.wiz-card{width:640px;max-width:92vw;max-height:88vh;background:var(--bg2);border:1px solid var(--border3);padding:0;display:flex;flex-direction:column;box-shadow:0 0 0 1px #000,0 0 40px rgba(0,224,192,.08)}
.wiz-head{padding:18px 24px;border-bottom:1px solid var(--border);display:flex;align-items:center;gap:10px}
.wiz-logo{width:22px;height:22px;border:1px solid var(--accent);display:flex;align-items:center;justify-content:center;color:var(--accent);font-weight:700;font-size:11px}
.wiz-title{font-size:13px;letter-spacing:.08em;color:var(--fg);text-transform:uppercase}
.wiz-title b{color:var(--accent);font-weight:600}
.wiz-step-count{margin-left:auto;color:var(--fg3);font-size:11px;letter-spacing:.1em}
.wiz-body{padding:28px 32px;overflow-y:auto;flex:1}
.wiz-body h2{font-size:17px;color:var(--fg);margin-bottom:12px;font-weight:500;letter-spacing:.02em}
.wiz-body h2::before{content:'▸ ';color:var(--accent)}
.wiz-body p{color:var(--fg2);margin-bottom:14px;font-size:12.5px;line-height:1.7}
.wiz-body ul{list-style:none;margin:0 0 16px 0}
.wiz-body li{padding:5px 0 5px 18px;position:relative;color:var(--fg2);font-size:12.5px}
.wiz-body li::before{content:'·';position:absolute;left:4px;color:var(--accent);font-weight:700}
.wiz-body code{background:#0a0a0a;border:1px solid var(--border);padding:1px 5px;color:var(--accent);font-size:11.5px}
.wiz-body pre{background:#080808;border:1px solid var(--border);padding:14px;margin:12px 0;color:#c8c8c8;font-size:11.5px;line-height:1.6;overflow-x:auto;white-space:pre}
.wiz-body pre .k{color:var(--accent2)}
.wiz-body pre .s{color:var(--ok)}
.wiz-body pre .c{color:var(--fg3)}
.wiz-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin:14px 0}
.wiz-feat{border:1px solid var(--border);padding:12px 14px;background:var(--bg3)}
.wiz-feat .t{color:var(--accent);font-size:11px;letter-spacing:.08em;text-transform:uppercase;margin-bottom:6px}
.wiz-feat .d{color:var(--fg2);font-size:11.5px;line-height:1.6}
.wiz-foot{padding:14px 24px;border-top:1px solid var(--border);display:flex;align-items:center;gap:10px}
.wiz-dots{display:flex;gap:6px}
.wiz-dot{width:6px;height:6px;background:#222;transition:.2s}
.wiz-dot.on{background:var(--accent);box-shadow:0 0 6px var(--accent)}
.wiz-spacer{flex:1}
.wiz-btn{background:transparent;border:1px solid var(--border2);color:var(--fg);padding:7px 16px;font-family:var(--mono);font-size:11.5px;cursor:pointer;letter-spacing:.05em;transition:.15s}
.wiz-btn:hover:not(:disabled){border-color:var(--accent);color:var(--accent)}
.wiz-btn.primary{background:var(--accent);color:#000;border-color:var(--accent);font-weight:600}
.wiz-btn.primary:hover:not(:disabled){background:#00ffd5;color:#000}
.wiz-btn.ghost{border-color:transparent;color:var(--fg3)}
.wiz-btn.ghost:hover:not(:disabled){color:var(--fg)}
.wiz-btn:disabled,.wiz-btn[disabled]{opacity:.35;cursor:not-allowed;border-color:var(--border);color:var(--fg3);background:transparent}
/* ============ APP SHELL ============ */
#app{display:flex;flex-direction:column;height:100%;width:100%}
#topbar{display:flex;align-items:center;height:38px;background:var(--bg2);border-bottom:1px solid var(--border);padding:0 12px;gap:14px;flex-shrink:0}
.brand{display:flex;align-items:center;gap:8px;letter-spacing:.06em}
.brand .logo{width:20px;height:20px;border:1px solid var(--accent);display:flex;align-items:center;justify-content:center;color:var(--accent);font-weight:700;font-size:10px}
.brand .name{color:var(--fg);font-size:12px;font-weight:600}
.brand .tag{color:var(--fg3);font-size:10px;letter-spacing:.1em;text-transform:uppercase}
.top-tabs{display:flex;gap:0;margin-left:14px}
.top-tab{padding:0 14px;height:38px;display:flex;align-items:center;color:var(--fg2);font-size:11.5px;cursor:pointer;border-bottom:1px solid transparent;letter-spacing:.04em;transition:.15s;background:transparent;font-family:var(--mono);border-left:none;border-right:none;border-top:none}
.top-tab:hover{color:var(--fg)}
.top-tab.on{color:var(--accent);border-bottom-color:var(--accent)}
.top-actions{margin-left:auto;display:flex;align-items:center;gap:6px}
.btn{background:transparent;border:1px solid var(--border2);color:var(--fg);padding:5px 12px;font-family:var(--mono);font-size:11px;cursor:pointer;letter-spacing:.05em;transition:.15s;white-space:nowrap}
.btn:hover{border-color:var(--accent);color:var(--accent)}
.btn.primary{background:var(--accent);color:#000;border-color:var(--accent);font-weight:600}
.btn.primary:hover{background:#00ffd5}
.btn.icon{padding:5px 8px;color:var(--fg2)}
.btn.icon:hover{color:var(--accent)}
.btn:disabled{opacity:.4;cursor:not-allowed}
#main{display:flex;flex:1;min-height:0;position:relative}
/* ============ LEFT PANEL ============ */
#left{width:340px;min-width:340px;border-right:1px solid var(--border);display:flex;flex-direction:column;background:var(--panel);overflow:hidden}
.panel-head{display:flex;align-items:center;padding:8px 12px;border-bottom:1px solid var(--border);background:var(--bg2);flex-shrink:0}
.panel-head .label{font-size:10.5px;letter-spacing:.12em;color:var(--fg3);text-transform:uppercase}
.panel-head .actions{margin-left:auto;display:flex;gap:4px}
.panel-head .mini{font-size:10px;padding:2px 7px;border:1px solid var(--border);color:var(--fg2);cursor:pointer;letter-spacing:.05em;background:transparent;font-family:var(--mono)}
.panel-head .mini:hover{border-color:var(--accent);color:var(--accent)}
.editor-block{flex:1;display:flex;flex-direction:column;min-height:0;border-bottom:1px solid var(--border)}
.editor-block:last-child{border-bottom:none}
.editor-block.q{flex:1.2}
.editor-block.s{flex:1}
.editor-area{flex:1;width:100%;background:#070707;border:none;color:var(--fg);font-family:var(--mono);font-size:11.5px;line-height:1.6;padding:10px 12px;resize:none;outline:none;tab-size:2;overflow:auto}
.editor-area:focus{background:#080808;box-shadow:inset 0 0 0 1px var(--border2)}
.editor-area.error{box-shadow:inset 0 0 0 1px rgba(255,59,59,.4)}
.editor-status{font-size:10px;color:var(--fg3);padding:3px 10px;background:var(--bg2);border-top:1px solid var(--border);display:flex;gap:10px;flex-shrink:0}
.editor-status .ok{color:var(--ok)}
.editor-status .bad{color:var(--err)}
/* ============ CENTER ============ */
#center{flex:1;display:flex;flex-direction:column;min-width:0;background:var(--bg)}
.center-split{display:flex;flex-direction:column;flex:1;min-height:0}
#canvas-wrap{flex:1;position:relative;background:#050505;border-bottom:1px solid var(--border);min-height:180px;overflow:hidden}
#canvas{display:block;width:100%;height:100%;cursor:grab;touch-action:none}
#canvas:active{cursor:grabbing}
.canvas-overlay{position:absolute;top:8px;left:10px;font-size:10px;color:var(--fg3);letter-spacing:.08em;pointer-events:none;text-transform:uppercase}
.canvas-overlay b{color:var(--accent);font-weight:500}
.canvas-hint{position:absolute;bottom:8px;right:10px;font-size:10px;color:var(--fg3);letter-spacing:.06em;pointer-events:none}
.canvas-legend{position:absolute;top:8px;right:10px;font-size:10px;color:var(--fg3);letter-spacing:.06em;text-align:right;line-height:1.7;pointer-events:none}
.canvas-legend .c1{color:var(--accent)}
.canvas-legend .c2{color:var(--accent2)}
.canvas-legend .c3{color:var(--accent3)}
.canvas-error{position:absolute;bottom:8px;left:10px;font-size:10px;color:var(--err);letter-spacing:.05em;pointer-events:none;background:rgba(5,5,5,.85);border:1px solid var(--err);padding:3px 8px;display:none}
.canvas-error.on{display:block}
#output-wrap{flex:1;display:flex;flex-direction:column;min-height:0;background:var(--panel)}
#output{flex:1;overflow:auto;padding:10px 12px;font-size:11.5px;line-height:1.65}
.out-q{border:1px solid var(--border);margin-bottom:10px;background:var(--bg2)}
.out-q-head{padding:7px 12px;border-bottom:1px solid var(--border);display:flex;align-items:center;gap:10px;font-size:11px;background:var(--bg3)}
.out-q-head .id{color:var(--accent);font-weight:600;letter-spacing:.04em}
.out-q-head .type{color:var(--fg3);font-size:10px;letter-spacing:.1em;text-transform:uppercase;border:1px solid var(--border2);padding:1px 6px}
.out-q-head .lat{margin-left:auto;color:var(--fg3);font-size:10px}
.out-q-body{padding:10px 12px}
.out-row{display:flex;gap:8px;margin-bottom:5px;align-items:baseline}
.out-row .k{color:var(--fg3);font-size:10.5px;letter-spacing:.06em;min-width:100px;text-transform:uppercase}
.out-row .v{color:var(--fg);flex:1;word-break:break-word}
.out-row .v.answer{color:var(--ok);font-weight:600}
.out-row .v.num{color:var(--accent)}
.out-bar{height:6px;background:#111;margin-top:4px;position:relative;overflow:hidden;border:1px solid var(--border)}
.out-bar > i{position:absolute;left:0;top:0;bottom:0;background:var(--accent);transition:width .4s}
.out-bar.warn > i{background:var(--warn)}
.out-bar.err > i{background:var(--err)}
.out-trace{margin-top:8px;border-top:1px dashed var(--border);padding-top:6px}
.out-trace summary{color:var(--fg3);font-size:10.5px;cursor:pointer;letter-spacing:.06em;text-transform:uppercase}
.out-trace pre{margin-top:6px;background:#080808;border:1px solid var(--border);padding:8px;color:var(--fg2);font-size:10.5px;overflow-x:auto;white-space:pre}
.out-empty{color:var(--fg3);text-align:center;padding:40px 20px;font-size:11.5px;letter-spacing:.05em}
.out-empty .big{color:var(--fg2);font-size:13px;margin-bottom:8px;letter-spacing:.1em}
/* ============ RIGHT PANEL ============ */
#right{width:340px;min-width:340px;border-left:1px solid var(--border);display:flex;flex-direction:column;background:var(--panel);overflow:hidden}
.right-tabs{display:flex;border-bottom:1px solid var(--border);background:var(--bg2);flex-shrink:0}
.right-tab{flex:1;padding:9px 6px;text-align:center;color:var(--fg3);font-size:10.5px;letter-spacing:.1em;text-transform:uppercase;cursor:pointer;border-bottom:1px solid transparent;transition:.15s;background:transparent;font-family:var(--mono);border-left:none;border-right:none;border-top:none}
.right-tab:hover{color:var(--fg2)}
.right-tab.on{color:var(--accent);border-bottom-color:var(--accent);background:var(--bg3)}
.right-body{flex:1;overflow-y:auto;padding:10px}
.right-pane{display:none}
.right-pane.on{display:block}
/* Snippets */
.snip-search{width:100%;background:#070707;border:1px solid var(--border);color:var(--fg);font-family:var(--mono);font-size:11px;padding:6px 9px;outline:none;margin-bottom:10px}
.snip-search:focus{border-color:var(--accent)}
.snip-group{margin-bottom:14px}
.snip-group .gh{font-size:10px;letter-spacing:.14em;color:var(--fg3);text-transform:uppercase;margin-bottom:6px;padding-left:2px}
.snip{border:1px solid var(--border);background:var(--bg2);margin-bottom:6px;transition:.15s}
.snip:hover{border-color:var(--border3)}
.snip-head{padding:6px 9px;display:flex;align-items:center;gap:6px;cursor:pointer;user-select:none;background:transparent;border:none;width:100%;text-align:left;font-family:var(--mono);color:var(--fg)}
.snip-head:hover{background:var(--bg3)}
.snip-title{flex:1;font-size:11px;color:var(--fg);letter-spacing:.03em}
.snip-tag{font-size:9px;color:var(--fg3);border:1px solid var(--border2);padding:0 5px;letter-spacing:.08em;text-transform:uppercase}
.snip-body{padding:0 9px 9px;display:none}
.snip.open .snip-body{display:block}
.snip-desc{color:var(--fg3);font-size:10.5px;line-height:1.55;margin-bottom:6px}
.snip-code{background:#060606;border:1px solid var(--border);padding:8px;color:#bbb;font-size:10.5px;line-height:1.55;white-space:pre;overflow-x:auto;max-height:220px;overflow-y:auto}
.snip-actions{display:flex;gap:4px;margin-top:6px}
.snip-actions .mini{font-size:9.5px;padding:2px 8px;border:1px solid var(--border2);color:var(--fg2);cursor:pointer;background:transparent;font-family:var(--mono);letter-spacing:.05em}
.snip-actions .mini:hover{border-color:var(--accent);color:var(--accent)}
.snip-actions .mini.primary{border-color:var(--accent);color:var(--accent)}
/* Templates */
.tpl{border:1px solid var(--border);background:var(--bg2);margin-bottom:8px;transition:.15s}
.tpl:hover{border-color:var(--border3)}
.tpl-head{padding:8px 10px;display:flex;align-items:flex-start;gap:8px;cursor:pointer;background:transparent;border:none;width:100%;text-align:left;font-family:var(--mono);color:var(--fg)}
.tpl-head:hover{background:var(--bg3)}
.tpl-icon{width:22px;height:22px;border:1px solid var(--accent);color:var(--accent);display:flex;align-items:center;justify-content:center;font-size:10px;flex-shrink:0;font-weight:700}
.tpl-info{flex:1;min-width:0}
.tpl-name{font-size:11.5px;color:var(--fg);font-weight:600;letter-spacing:.02em;margin-bottom:2px}
.tpl-desc{font-size:10.5px;color:var(--fg3);line-height:1.5}
.tpl-meta{display:flex;gap:6px;margin-top:5px;flex-wrap:wrap}
.tpl-meta .m{font-size:9px;color:var(--fg3);border:1px solid var(--border2);padding:0 5px;letter-spacing:.05em}
.tpl-body{padding:0 10px 10px;display:none}
.tpl.open .tpl-body{display:block}
.tpl-guide{color:var(--fg2);font-size:10.5px;line-height:1.6;border-left:2px solid var(--accent);padding:2px 0 2px 8px;margin-bottom:8px}
.tpl-guide b{color:var(--accent);font-weight:600}
.tpl-actions{display:flex;gap:5px;margin-top:6px}
.tpl-actions .mini{font-size:10px;padding:3px 10px;border:1px solid var(--border2);color:var(--fg2);cursor:pointer;background:transparent;font-family:var(--mono);letter-spacing:.05em}
.tpl-actions .mini:hover{border-color:var(--accent);color:var(--accent)}
.tpl-actions .mini.primary{border-color:var(--accent);color:var(--accent);font-weight:600}
.tpl-actions .mini.primary:hover{background:var(--accent);color:#000}
/* Docs pane */
.docs h3{font-size:12px;color:var(--accent);margin:14px 0 6px;letter-spacing:.06em;text-transform:uppercase}
.docs h3:first-child{margin-top:0}
.docs p{color:var(--fg2);font-size:11.5px;margin-bottom:10px;line-height:1.7}
.docs ul{list-style:none;margin-bottom:10px}
.docs li{padding:3px 0 3px 16px;position:relative;color:var(--fg2);font-size:11.5px;line-height:1.6}
.docs li::before{content:'▸';position:absolute;left:0;color:var(--accent)}
.docs code{background:#0a0a0a;border:1px solid var(--border);padding:0 5px;color:var(--accent);font-size:11px}
.docs pre{background:#080808;border:1px solid var(--border);padding:10px;margin:8px 0;color:#bbb;font-size:10.5px;overflow-x:auto;line-height:1.6;white-space:pre}
.docs pre .k{color:var(--accent2)}
.docs pre .s{color:var(--ok)}
.docs pre .c{color:var(--fg3)}
.docs a{color:var(--accent);text-decoration:none}
.docs a:hover{text-decoration:underline}
/* ============ STATUS BAR ============ */
#statusbar{height:24px;background:var(--bg2);border-top:1px solid var(--border);display:flex;align-items:center;padding:0 12px;gap:16px;font-size:10.5px;color:var(--fg3);letter-spacing:.04em;flex-shrink:0;overflow:hidden}
#statusbar .m{display:flex;align-items:center;gap:5px;white-space:nowrap}
#statusbar .m .lbl{color:var(--fg3)}
#statusbar .m .val{color:var(--fg2)}
#statusbar .m .val.ok{color:var(--ok)}
#statusbar .m .val.warn{color:var(--warn)}
#statusbar .m .val.err{color:var(--err)}
#statusbar .m .val.accent{color:var(--accent)}
#statusbar .spacer{flex:1}
#statusbar .brandfoot{color:var(--fg3);font-size:10px;letter-spacing:.05em}
#statusbar .brandfoot a{color:var(--accent);text-decoration:none}
#statusbar .brandfoot a:hover{text-decoration:underline}
.led{width:6px;height:6px;border-radius:50%;background:var(--ok);box-shadow:0 0 4px var(--ok);display:inline-block}
.led.busy{background:var(--warn);box-shadow:0 0 4px var(--warn)}
.led.err{background:var(--err);box-shadow:0 0 4px var(--err)}
/* ============ MODAL ============ */
.modal{position:fixed;inset:0;z-index:500;background:rgba(0,0,0,.85);display:none;align-items:center;justify-content:center;backdrop-filter:blur(4px)}
.modal.on{display:flex}
.modal-card{width:520px;max-width:92vw;background:var(--bg2);border:1px solid var(--border3);padding:0;max-height:80vh;display:flex;flex-direction:column}
.modal-head{padding:12px 16px;border-bottom:1px solid var(--border);display:flex;align-items:center;font-size:12px;letter-spacing:.08em;text-transform:uppercase;color:var(--fg)}
.modal-head b{color:var(--accent);font-weight:600;margin-right:6px}
.modal-head .close{margin-left:auto;cursor:pointer;color:var(--fg3);font-size:14px;background:transparent;border:none;padding:0 4px}
.modal-head .close:hover{color:var(--err)}
.modal-body{padding:16px;overflow-y:auto;font-size:11.5px;color:var(--fg2);line-height:1.7}
.modal-body h4{color:var(--accent);font-size:11px;letter-spacing:.1em;text-transform:uppercase;margin:14px 0 6px}
.modal-body h4:first-child{margin-top:0}
.modal-body ul{list-style:none}
.modal-body li{padding:2px 0 2px 14px;position:relative}
.modal-body li::before{content:'·';position:absolute;left:2px;color:var(--accent);font-weight:700}
.modal-body code{background:#0a0a0a;border:1px solid var(--border);padding:0 5px;color:var(--accent)}
.modal-foot{padding:12px 16px;border-top:1px solid var(--border);display:flex;gap:8px;align-items:center}
.metric-row{display:flex;justify-content:space-between;padding:5px 0;border-bottom:1px dashed var(--border);font-size:11px}
.metric-row:last-child{border-bottom:none}
.metric-row .mk{color:var(--fg3);letter-spacing:.06em}
.metric-row .mv{color:var(--fg);font-weight:600}
.metric-row .mv.accent{color:var(--accent)}
.metric-row .mv.ok{color:var(--ok)}
.metric-row .mv.warn{color:var(--warn)}
.prompt-input{width:100%;background:#070707;border:1px solid var(--border);color:var(--fg);font-family:var(--mono);font-size:11.5px;padding:7px 10px;outline:none}
.prompt-input:focus{border-color:var(--accent)}
.settings-row{display:flex;align-items:center;gap:10px;padding:8px 0;border-bottom:1px dashed var(--border)}
.settings-row:last-child{border-bottom:none}
.settings-row .sk{flex:1;color:var(--fg2)}
.settings-row .sv{color:var(--fg3);font-size:10.5px}
/* ============ TOAST ============ */
#toast{position:fixed;bottom:36px;left:50%;transform:translateX(-50%) translateY(20px);background:var(--bg2);border:1px solid var(--accent);color:var(--accent);padding:8px 18px;font-size:11.5px;letter-spacing:.05em;opacity:0;pointer-events:none;transition:.25s;z-index:200;box-shadow:0 0 20px rgba(0,224,192,.15)}
#toast.on{opacity:1;transform:translateX(-50%) translateY(0)}
#toast.err{border-color:var(--err);color:var(--err);box-shadow:0 0 20px rgba(255,59,59,.15)}
/* ============ SCANLINE ============ */
.scanlines{position:fixed;inset:0;pointer-events:none;z-index:1;background:repeating-linear-gradient(0deg,rgba(255,255,255,.012) 0,rgba(255,255,255,.012) 1px,transparent 1px,transparent 2px);mix-blend-mode:overlay;opacity:.5}
.scanlines.hidden{display:none}
/* ============ MOBILE ============ */
.mobile-fab{
display:none;
position:fixed;
bottom:40px;
width:44px;height:44px;
border-radius:50%;
border:1px solid var(--accent);
background:var(--bg2);
color:var(--accent);
font-size:18px;
cursor:pointer;
z-index:150;
align-items:center;
justify-content:center;
font-family:var(--mono);
}
.mobile-fab.left{left:12px}
.mobile-fab.right{right:12px}
.mobile-backdrop{display:none;position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:120}
.mobile-backdrop.on{display:block}
@media (max-width:1100px){
#left{width:280px;min-width:280px}
#right{width:280px;min-width:280px}
}
@media (max-width:820px){
#main{flex-direction:column}
#left,#right{
position:fixed;
top:38px;
bottom:24px;
width:340px;
max-width:88vw;
z-index:130;
display:flex;
transition:transform .25s;
box-shadow:0 0 24px rgba(0,0,0,.6);
}
#left{
left:0;
transform:translateX(-101%);
border-right:1px solid var(--border3);
border-left:none;
}
#left.open{transform:translateX(0)}
#right{
right:0;
transform:translateX(101%);
border-left:1px solid var(--border3);
border-right:none;
}
#right.open{transform:translateX(0)}
#center{width:100%}
.mobile-fab{display:flex}
#output-wrap{min-height:180px}
.canvas-legend{display:none}
}
@media (min-width:821px){
#left,#right{transform:none !important}
}
</style>
</head>
<body>
<div class="scanlines" id="scanlines" aria-hidden="true"></div>
<!-- ============ STARTUP WIZARD ============ -->
<div id="wizard" class="hidden" role="dialog" aria-modal="true" aria-labelledby="wizTitle" aria-hidden="true">
<div class="wiz-card">
<div class="wiz-head">
<div class="wiz-logo" aria-hidden="true">▣</div>
<div class="wiz-title" id="wizTitle">webXOS <b>DEV</b> · setup</div>
<div class="wiz-step-count" id="wizCount"></div>
</div>
<div class="wiz-body" id="wizBody"></div>
<div class="wiz-foot">
<div class="wiz-dots" id="wizDots" aria-hidden="true"></div>
<div class="wiz-spacer"></div>
<button class="wiz-btn ghost" id="wizSkip" type="button">skip</button>
<button class="wiz-btn" id="wizPrev" type="button" aria-label="Previous step">← back</button>
<button class="wiz-btn primary" id="wizNext" type="button">next →</button>
</div>
</div>
</div>
<!-- ============ MAIN APP ============ -->
<div id="app">
<header id="topbar">
<div class="brand">
<div class="logo" aria-hidden="true">▣</div>
<div class="name">webXOS <span style="color:var(--accent)">DEV</span></div>
<div class="tag" id="versionTag">v1.0.5 · jev clone</div>
</div>
<div class="top-tabs" role="tablist" aria-label="Primary views">
<button class="top-tab on" data-tab="workbench" role="tab" aria-selected="true" aria-controls="center" type="button" id="topTab-workbench">workbench</button>
<button class="top-tab" data-tab="docs" role="tab" aria-selected="false" aria-controls="right" type="button" id="topTab-docs">docs</button>
<button class="top-tab" data-tab="metrics" role="tab" aria-selected="false" aria-controls="modalMetrics" type="button" id="topTab-metrics">metrics</button>
</div>
<div class="top-actions">
<button class="btn primary" id="btnRun" title="Run all questions (Ctrl+Enter)" type="button" aria-label="Run all questions">▶ run</button>
<button class="btn" id="btnSave" title="Save project to IndexedDB (Ctrl+S)" type="button" aria-label="Save project">save</button>
<button class="btn" id="btnOpen" title="Open saved projects" type="button" aria-label="Open saved projects">open</button>
<button class="btn icon" id="btnSettings" title="Settings" type="button" aria-label="Settings">⚙</button>
<button class="btn icon" id="btnWizard" title="Show setup wizard" type="button" aria-label="Show setup wizard">?</button>
</div>
</header>
<div id="main">
<!-- ============ LEFT ============ -->
<aside id="left" aria-label="Input editors">
<div class="editor-block s">
<div class="panel-head">
<span class="label">state</span>
<div class="actions">
<button class="mini" data-act="state-format" title="Format JSON" type="button" aria-label="Format state JSON">fmt</button>
<button class="mini" data-act="state-minify" title="Minify JSON" type="button" aria-label="Minify state JSON">min</button>
<button class="mini" data-act="state-copy" title="Copy state" type="button" aria-label="Copy state">copy</button>
<button class="mini" data-act="state-clear" title="Clear" type="button" aria-label="Clear state">clr</button>
</div>
</div>
<textarea class="editor-area" id="stateInput" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off" aria-label="State JSON editor"></textarea>
<div class="editor-status" id="stateStatus" aria-live="polite">
<span class="ok">● valid</span>
<span id="stateMeta">0 B · 0 entities</span>
</div>
</div>
<div class="editor-block q">
<div class="panel-head">
<span class="label">questions</span>
<div class="actions">
<button class="mini" data-act="q-format" title="Format JSON" type="button" aria-label="Format questions JSON">fmt</button>
<button class="mini" data-act="q-copy" title="Copy questions" type="button" aria-label="Copy questions">copy</button>
<button class="mini" data-act="q-add" title="Add starter question" type="button" aria-label="Add starter question">+</button>
</div>
</div>
<textarea class="editor-area" id="questionsInput" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off" aria-label="Questions JSON editor"></textarea>
<div class="editor-status" id="questionsStatus" aria-live="polite">
<span class="ok">● valid</span>
<span id="questionsMeta">0 questions</span>
</div>
</div>
</aside>
<!-- ============ CENTER ============ -->
<section id="center">
<div class="center-split">
<div id="canvas-wrap">
<canvas id="canvas" tabindex="0" aria-label="3D viewport. Use arrow keys to orbit, plus and minus to zoom, r to reset."></canvas>
<div class="canvas-overlay">viewport · <b id="viewLabel">perspective</b></div>
<div class="canvas-legend" aria-hidden="true">
<div><span class="c1">■</span> solid:main</div>
<div><span class="c2">■</span> augmented</div>
<div><span class="c3">■</span> plane</div>
</div>
<div class="canvas-hint" aria-hidden="true">drag · rotate · wheel · zoom · dblclick · reset</div>
<div class="canvas-error" id="canvasError" role="alert"></div>
</div>
<div id="output-wrap">
<div class="panel-head">
<span class="label">output</span>
<div class="actions">
<button class="mini" data-act="out-clear" title="Clear output" type="button" aria-label="Clear output">clr</button>
<button class="mini" data-act="out-copy" title="Copy output JSON" type="button" aria-label="Copy output JSON">copy</button>
<button class="mini" data-act="out-export" title="Export run as .jev.json" type="button" aria-label="Export run">exp</button>
</div>
</div>
<div id="output" role="log" aria-live="polite" aria-atomic="false">
<div class="out-empty">
<div class="big">▣ no run yet</div>
<div>press <span style="color:var(--accent)">▶ run</span> or <span style="color:var(--accent)">Ctrl+Enter</span> to evaluate questions</div>
</div>
</div>
</div>
</div>
</section>
<!-- ============ RIGHT ============ -->
<aside id="right" aria-label="Reference panels">
<div class="right-tabs" role="tablist" aria-label="Reference views">
<button class="right-tab on" data-rtab="snippets" role="tab" aria-selected="true" aria-controls="pane-snippets" type="button" id="rtab-snippets">snippets</button>
<button class="right-tab" data-rtab="templates" role="tab" aria-selected="false" aria-controls="pane-templates" type="button" id="rtab-templates">templates</button>
<button class="right-tab" data-rtab="guide" role="tab" aria-selected="false" aria-controls="pane-guide" type="button" id="rtab-guide">guide</button>
</div>
<div class="right-body">
<div class="right-pane on" id="pane-snippets" role="tabpanel" aria-labelledby="rtab-snippets">
<input class="snip-search" id="snipSearch" placeholder="filter snippets… (Ctrl+K)" aria-label="Filter snippets">
<div id="snipList"></div>
</div>
<div class="right-pane" id="pane-templates" role="tabpanel" aria-labelledby="rtab-templates">
<div id="tplList"></div>
</div>
<div class="right-pane" id="pane-guide" role="tabpanel" aria-labelledby="rtab-guide">
<div class="docs" id="guideContent"></div>
</div>
</div>
</aside>
</div>
<footer id="statusbar">
<div class="m"><span class="led" id="led" aria-hidden="true"></span><span class="val" id="stState" aria-live="polite">ready</span></div>
<div class="m"><span class="lbl">ops</span><span class="val accent" id="stOps">0</span></div>
<div class="m"><span class="lbl">answered</span><span class="val" id="stAnswered">0</span></div>
<div class="m"><span class="lbl">avg</span><span class="val" id="stAvg">0.00ms</span></div>
<div class="m"><span class="lbl">errors</span><span class="val" id="stErrors">0</span></div>
<div class="m"><span class="lbl">entities</span><span class="val" id="stEntities">0</span></div>
<div class="m"><span class="lbl">state</span><span class="val" id="stSize">0 B</span></div>
<div class="m"><span class="lbl">storage</span><span class="val" id="stStorage">—</span></div>
<div class="m"><span class="lbl">uptime</span><span class="val" id="stUptime">0s</span></div>
<div class="spacer"></div>
<div class="brandfoot">© 2026 <a href="https://github.com/webXOS" target="_blank" rel="noopener">webXOS</a> · MIT · offline</div>
</footer>
</div>
<!-- ============ MOBILE CONTROLS ============ -->
<button class="mobile-fab left" id="mobileOpenLeft" type="button" aria-label="Open input editors">✎</button>
<button class="mobile-fab right" id="mobileOpenRight" type="button" aria-label="Open reference panels">☰</button>
<div class="mobile-backdrop" id="mobileBackdrop"></div>
<!-- ============ MODALS ============ -->
<div class="modal" id="modalProjects" role="dialog" aria-modal="true" aria-labelledby="projectsTitle">
<div class="modal-card">
<div class="modal-head"><b aria-hidden="true">▣</b> <span id="projectsTitle">saved projects</span> <button class="close" data-close="modalProjects" type="button" aria-label="Close">✕</button></div>
<div class="modal-body" id="projectsBody"></div>
</div>
</div>
<div class="modal" id="modalMetrics" role="dialog" aria-modal="true" aria-labelledby="metricsTitle">
<div class="modal-card">
<div class="modal-head"><b aria-hidden="true">▣</b> <span id="metricsTitle">runtime metrics</span> <button class="close" data-close="modalMetrics" type="button" aria-label="Close">✕</button></div>
<div class="modal-body" id="metricsBody"></div>
</div>
</div>
<div class="modal" id="modalSettings" role="dialog" aria-modal="true" aria-labelledby="settingsTitle">
<div class="modal-card" style="width:480px;max-height:none">
<div class="modal-head"><b aria-hidden="true">▣</b> <span id="settingsTitle">settings</span> <button class="close" data-close="modalSettings" type="button" aria-label="Close">✕</button></div>
<div class="modal-body" id="settingsBody"></div>
</div>
</div>
<div class="modal" id="modalRestore" role="dialog" aria-modal="true" aria-labelledby="restoreTitle">
<div class="modal-card" style="width:480px;max-height:none">
<div class="modal-head"><b aria-hidden="true">▣</b> <span id="restoreTitle">restore session?</span></div>
<div class="modal-body">
<p>A previous editing session was found in this browser's storage. Restore it, or start fresh from the default template?</p>
<p style="color:var(--fg3);font-size:10.5px;margin-top:6px">The previous session will not be deleted until you save or start typing — you can always reopen it from <b>open</b>.</p>
</div>
<div class="modal-foot">
<div class="wiz-spacer"></div>
<button class="wiz-btn" id="restoreFresh" type="button">start fresh</button>
<button class="wiz-btn primary" id="restorePrevious" type="button">restore</button>
</div>
</div>
</div>
<!-- Prompt modal is placed last for readability; stacking order across all
modals is enforced dynamically by openModalEl (monotonic z-index). -->
<div class="modal" id="modalPrompt" role="dialog" aria-modal="true" aria-labelledby="promptTitle">
<div class="modal-card" style="width:440px;max-height:none">
<div class="modal-head"><b aria-hidden="true">▣</b> <span id="promptTitle">input</span></div>
<div class="modal-body">
<div id="promptMessage" style="margin-bottom:10px;color:var(--fg2)"></div>
<input class="prompt-input" id="promptInput" type="text" autocomplete="off" spellcheck="false" aria-label="Prompt input">
</div>
<div class="modal-foot">
<div class="wiz-spacer"></div>
<button class="wiz-btn ghost" id="promptCancel" type="button">cancel</button>
<button class="wiz-btn primary" id="promptOk" type="button">ok</button>
</div>
</div>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<script>
"use strict";
/* ============================================================
webXOS DEV — a JEV-compatible decision engine for developers.
Single-file, offline-first, MIT licensed.
© 2026 webXOS · github.com/webXOS
v1.0.5 — release polish (JGF NB4-ESC-NESTED, NB4-SAVE-OPEN-RACE,
NB4-COMMENT):
- Prompt keydown handlers now call stopPropagation() so a single
Escape resolves the prompt without also dismissing its parent.
- openProjects re-checks _activePrompt immediately before opening
its modal, closing a narrow Save→Open race.
- Header comment for #modalPrompt updated to reflect dynamic
z-index assignment.
Earlier passes retained: E01–E18, N01–N06, NB-1..NB-4.
============================================================ */
const DEV_VERSION = "1.0.5";
const DEV_START = performance.now();
const DB_NAME = "webxos-dev";
const DB_VERSION = 1;
const STORE_PROJECTS = "projects";
const STORE_TEMPLATES = "templates";
const STORE_SETTINGS = "settings";
const MAX_SAMPLES = 2000;
const MAX_TRIANGLES_WARN = 50000;
const MAX_TRIANGLES_HARD = 200000;
/* ============================================================
1. UTILITIES
============================================================ */
const $ = (s, r) => (r || document).querySelector(s);
const $$ = (s, r) => Array.from((r || document).querySelectorAll(s));
function esc(s){
return String(s).replace(/[&<>"'`]/g, c => ({
"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"
}[c]));
}
function now(){ return performance.now(); }
function fmtMs(n){ return n.toFixed(2)+"ms"; }
function fmtBytes(n){
if (n < 1024) return n + " B";
if (n < 1048576) return (n/1024).toFixed(1) + " KB";
return (n/1048576).toFixed(2) + " MB";
}
function fmtUptime(ms){
const s = Math.floor(ms/1000);
if (s < 60) return s + "s";
const m = Math.floor(s/60);
if (m < 60) return m + "m" + (s % 60) + "s";
return Math.floor(m/60) + "h" + (m % 60) + "m";
}
function hashInt(s){
let h = 2166136261 >>> 0;
for (let i = 0; i < s.length; i++){
h ^= s.charCodeAt(i);
h = Math.imul(h, 16777619);
}
return h >>> 0;
}
function uid(){ return Math.random().toString(36).slice(2,9); }
function clamp(v,a,b){ return Math.max(a, Math.min(b, v)); }
function safeParse(s){ try { return {ok:true, value:JSON.parse(s)}; } catch(e){ return {ok:false, error:e.message}; } }
function deepMerge(target, source){
if (Array.isArray(target) || Array.isArray(source)) return source;
if (target === null || typeof target !== "object") return source;
if (source === null || typeof source !== "object") return source;
const out = Object.assign({}, target);
for (const k of Object.keys(source)){
if (Object.prototype.hasOwnProperty.call(out, k)){
out[k] = deepMerge(out[k], source[k]);
} else {
out[k] = source[k];
}
}
return out;
}
function mulberry32(seed){
let a = seed >>> 0;
return function(){
a = (a + 0x6D2B79F5) >>> 0;
let t = a;
t = Math.imul(t ^ (t >>> 15), 1 | t);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
async function contentHash(text){
if (typeof crypto !== "undefined" && crypto.subtle && typeof TextEncoder !== "undefined"){
try {
const buf = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
return Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2,"0")).join("");
} catch(e){ /* fall through */ }
}
return fallbackHash128(text);
}
function fallbackHash128(text){
let a = 0xcbf29ce4 >>> 0, b = 0x84222325 >>> 0;
let c = 0x811c9dc5 >>> 0, d = 0x01000193 >>> 0;
for (let i = 0; i < text.length; i++){
const ch = text.charCodeAt(i);
a = Math.imul(a ^ ch, 0x01000193) >>> 0;
b = Math.imul((b + ch) >>> 0, 0x85ebca6b) >>> 0;
c = Math.imul(c ^ ch, 0x27d4eb2f) >>> 0;
d = Math.imul((d ^ ch) >>> 0, 0x165667b1) >>> 0;
}
const h1 = (a >>> 0).toString(16).padStart(8,"0") + (b >>> 0).toString(16).padStart(8,"0");
const h2 = (c >>> 0).toString(16).padStart(8,"0") + (d >>> 0).toString(16).padStart(8,"0");
return h1 + h2;
}
let toastTimer = null;
function toast(msg, isErr){
const t = $("#toast");
t.textContent = msg;
t.classList.toggle("err", !!isErr);
t.classList.add("on");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => t.classList.remove("on"), 2400);
}
async function copyText(text){
try {
if (navigator.clipboard && window.isSecureContext){
await navigator.clipboard.writeText(text);
return true;
}
} catch(e){ /* fall through */ }
try {
const ta = document.createElement("textarea");
ta.value = text;
ta.setAttribute("readonly","");
ta.style.position = "fixed";
ta.style.top = "0";
ta.style.left = "-9999px";
document.body.appendChild(ta);
ta.select();
ta.setSelectionRange(0, text.length);
const ok = document.execCommand("copy");
document.body.removeChild(ta);
return ok;
} catch(e){
return false;
}
}
function insertAtCursor(textarea, text){
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const before = textarea.value.slice(0, start);
const after = textarea.value.slice(end);
textarea.value = before + text + after;
const pos = start + text.length;
textarea.selectionStart = pos;
textarea.selectionEnd = pos;
}
/* ============================================================
2. FOCUS TRAP STACK + MODAL OPEN/CLOSE
============================================================ */
let _modalZCounter = 500;
const _focusTrapStack = []; /* [{el, release}] — topmost is last */
function trapFocus(container){
function focusables(){
return Array.from(container.querySelectorAll(
'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
)).filter(el => el.offsetParent !== null || el === document.activeElement);
}
function onKey(e){
if (e.key !== "Tab") return;
const list = focusables();
if (!list.length) return;
const first = list[0];
const last = list[list.length - 1];
if (e.shiftKey && document.activeElement === first){
e.preventDefault();
last.focus();
} else if (!e.shiftKey && document.activeElement === last){
e.preventDefault();
first.focus();
}
}
container.addEventListener("keydown", onKey);
return () => container.removeEventListener("keydown", onKey);
}
function releaseTrapFor(el){
for (let i = _focusTrapStack.length - 1; i >= 0; i--){
if (_focusTrapStack[i].el === el){
const entry = _focusTrapStack.splice(i, 1)[0];
try { entry.release(); } catch(_){ /* ignore */ }
return true;
}
}
return false;
}
function focusFirstInside(el){
if (!el) return;
const f = el.querySelector('input:not([disabled]), textarea:not([disabled]), button:not([disabled])');
if (f && document.body.contains(f)){
try { f.focus(); } catch(_){}
}
}
function openModalEl(el){
if (!el) return;
if (el.classList.contains("on")) return; /* already open — no double-push */
el.style.zIndex = String(++_modalZCounter);
el._previousFocus = document.activeElement;
el.classList.add("on");
el.setAttribute("aria-hidden", "false");
const release = trapFocus(el);
_focusTrapStack.push({ el, release });
setTimeout(() => focusFirstInside(el), 30);
}
function closeModalEl(el){
if (!el) return;
if (!el.classList.contains("on")) return;
el.classList.remove("on");
el.setAttribute("aria-hidden", "true");
releaseTrapFor(el);
const prev = el._previousFocus;
el._previousFocus = null;
if (prev && typeof prev.focus === "function" && document.body.contains(prev)){
try { prev.focus(); return; } catch(_){ /* fall through */ }
}
if (_focusTrapStack.length){
focusFirstInside(_focusTrapStack[_focusTrapStack.length - 1].el);
}
}
/* ============================================================
3. INDEXEDDB WRAPPER
============================================================ */
let DB = null;
let DBPrivateMode = false;
function openDB(){
return new Promise((resolve, reject) => {
if (!("indexedDB" in window)){
DBPrivateMode = true;
return reject(new Error("indexedDB unavailable"));
}
let req;
try {
req = indexedDB.open(DB_NAME, DB_VERSION);
} catch(e){
DBPrivateMode = true;
return reject(e);
}
req.onupgradeneeded = e => {
const d = e.target.result;
if (!d.objectStoreNames.contains(STORE_PROJECTS)) d.createObjectStore(STORE_PROJECTS, {keyPath:"hash"});
if (!d.objectStoreNames.contains(STORE_TEMPLATES)) d.createObjectStore(STORE_TEMPLATES, {keyPath:"id"});
if (!d.objectStoreNames.contains(STORE_SETTINGS)) d.createObjectStore(STORE_SETTINGS, {keyPath:"key"});
};
req.onsuccess = e => { DB = e.target.result; resolve(DB); };
req.onerror = e => {
const err = e.target.error;
if (err && (err.name === "InvalidStateError" || err.name === "SecurityError")){
DBPrivateMode = true;
}
reject(err || new Error("indexedDB open failed"));
};
});
}
function dbPut(store, value){
return new Promise((res, rej) => {
if (!DB) return rej(new Error("DB not open"));
const tx = DB.transaction(store, "readwrite");
let settled = false;
tx.onabort = () => { if (!settled){ settled = true; rej(tx.error || new Error("transaction aborted")); } };
tx.onerror = () => { if (!settled){ settled = true; rej(tx.error || new Error("transaction error")); } };
tx.oncomplete = () => { if (!settled){ settled = true; res(true); } };
try {
tx.objectStore(store).put(value);
} catch(e){
if (!settled){ settled = true; rej(e); }
}
});
}
function dbGet(store, key){
return new Promise((res, rej) => {
if (!DB) return rej(new Error("DB not open"));
const tx = DB.transaction(store, "readonly");
const r = tx.objectStore(store).get(key);
r.onsuccess = () => res(r.result);
r.onerror = () => rej(r.error);
});
}
function dbAll(store){
return new Promise((res, rej) => {
if (!DB) return rej(new Error("DB not open"));
const tx = DB.transaction(store, "readonly");
const r = tx.objectStore(store).getAll();
r.onsuccess = () => res(r.result || []);
r.onerror = () => rej(r.error);
});
}
function dbDelete(store, key){
return new Promise((res, rej) => {
if (!DB) return rej(new Error("DB not open"));
const tx = DB.transaction(store, "readwrite");
let settled = false;
tx.onabort = () => { if (!settled){ settled = true; rej(tx.error || new Error("transaction aborted")); } };
tx.onerror = () => { if (!settled){ settled = true; rej(tx.error || new Error("transaction error")); } };
tx.oncomplete = () => { if (!settled){ settled = true; res(true); } };
try {
tx.objectStore(store).delete(key);
} catch(e){
if (!settled){ settled = true; rej(e); }
}
});
}
function describeDbError(e){
if (!e) return "unknown error";
const n = e.name || "";
if (n === "QuotaExceededError" || /quota/i.test(e.message || "")){
return "Storage quota exceeded — free up space or use a different browser profile.";
}
if (DBPrivateMode || n === "InvalidStateError" || n === "SecurityError"){
return "Storage is unavailable (private browsing?). Projects cannot be saved.";
}
return e.message || String(e);
}
/* ============================================================
4. LOCAL CAD KERNEL
============================================================ */
const _windingNormalized = new WeakSet();
const _dirCache = new WeakMap();
const _validationCache = new WeakMap();
const Kernel = {
add:(a,b)=>[a[0]+b[0],a[1]+b[1],a[2]+b[2]],
sub:(a,b)=>[a[0]-b[0],a[1]-b[1],a[2]-b[2]],
scale:(a,s)=>[a[0]*s,a[1]*s,a[2]*s],
dot:(a,b)=>a[0]*b[0]+a[1]*b[1]+a[2]*b[2],
cross:(a,b)=>[a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0]],
len:a=>Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]),
dist:(a,b)=>Kernel.len(Kernel.sub(a,b)),
norm:a=>{ const l = Kernel.len(a) || 1; return [a[0]/l, a[1]/l, a[2]/l]; },
lerp:(a,b,t)=>[a[0]+(b[0]-a[0])*t, a[1]+(b[1]-a[1])*t, a[2]+(b[2]-a[2])*t],
validateSolid(solid){
if (_validationCache.has(solid)) return _validationCache.get(solid);
let out;
if (!solid || typeof solid !== "object"){
out = {ok:false, reason:"solid is not an object"};
} else if (!Array.isArray(solid.vertices) || !Array.isArray(solid.triangles)){
out = {ok:false, reason:"vertices/triangles must be arrays"};
} else if (solid.vertices.length < 3){
out = {ok:false, reason:"fewer than 3 vertices"};
} else if (solid.triangles.length < 1){
out = {ok:false, reason:"no triangles"};
} else {
const n = solid.vertices.length;
let fail = null;
for (let i = 0; i < n && !fail; i++){
const v = solid.vertices[i];
if (!Array.isArray(v) || v.length < 3){ fail = "vertex " + i + " is not a 3-vector"; break; }
for (let k = 0; k < 3; k++){
if (!Number.isFinite(v[k])){ fail = "vertex " + i + " has non-finite coordinate"; break; }
}
}
const m = solid.triangles.length;
for (let i = 0; i < m && !fail; i++){
const t = solid.triangles[i];
if (!Array.isArray(t) || t.length !== 3){ fail = "triangle " + i + " is not a 3-tuple"; break; }
for (let k = 0; k < 3; k++){
const idx = t[k];
if (!Number.isInteger(idx) || idx < 0 || idx >= n){
fail = "triangle " + i + " references vertex " + idx + " (out of range 0.." + (n-1) + ")";
break;
}
}
}
out = fail ? {ok:false, reason:fail} : {ok:true};
}
_validationCache.set(solid, out);
return out;
},
rayTriangle(orig, dir, v0, v1, v2){
const EPS = 1e-9;
const e1 = Kernel.sub(v1, v0);
const e2 = Kernel.sub(v2, v0);
const h = Kernel.cross(dir, e2);
const a = Kernel.dot(e1, h);
if (Math.abs(a) < EPS) return null;
const f = 1 / a;
const s = Kernel.sub(orig, v0);
const u = f * Kernel.dot(s, h);
if (u < 0 || u > 1) return null;
const q = Kernel.cross(s, e1);
const v = f * Kernel.dot(q, dir);
if (v < 0 || u + v > 1) return null;
const t = f * Kernel.dot(e2, q);
if (t < EPS) return null;
return t;
},
normalizeWinding(solid){
const v = Kernel.validateSolid(solid);
if (!v.ok) return;
const n = solid.triangles.length;
if (!n) return;
const edgeMap = new Map();
const ekey = (a, b) => a < b ? (a + "_" + b) : (b + "_" + a);
for (let i = 0; i < n; i++){
const t = solid.triangles[i];
for (let k = 0; k < 3; k++){
const a = t[k], b = t[(k+1)%3];
const kk = ekey(a, b);
let arr = edgeMap.get(kk);
if (!arr){ arr = []; edgeMap.set(kk, arr); }
arr.push({tri:i, dir: a < b ? 1 : -1});
}
}
const flipped = new Array(n).fill(false);
const visited = new Array(n).fill(false);
for (let seed = 0; seed < n; seed++){
if (visited[seed]) continue;
visited[seed] = true;
const queue = [seed];
while (queue.length){
const i = queue.shift();
const t = solid.triangles[i];
const flipI = flipped[i];
for (let k = 0; k < 3; k++){
const a = t[k], b = t[(k+1)%3];
const kk = ekey(a, b);
const entries = edgeMap.get(kk) || [];
const myDir = (a < b ? 1 : -1) * (flipI ? -1 : 1);
for (const e of entries){
if (e.tri === i) continue;
if (visited[e.tri]) continue;
if (myDir === e.dir) flipped[e.tri] = true;
visited[e.tri] = true;
queue.push(e.tri);
}
}
}
}
for (let i = 0; i < n; i++){