-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.html
1046 lines (826 loc) · 42.1 KB
/
ui.html
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>
<head>
<meta charset="UTF-8">
<title>Figma Plugin with Tabs</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
padding: 0px;
margin: 0px;
}
/*----------FEEDBACK BAR----------*/
.feedback {
height: 35px;
background-color: #EAF2FE;
font-weight: 550;
font-size: 12px;
display: flex;
align-items: center;
border-radius: 0px 0px 8px 8px;
padding: 4px 10px;
}
.blue-link-color {
font-weight: 300;
color: #2462C6;
}
.feedback a {
text-decoration: none;
color: black;
margin-left: 12px;
}
.feedback .blue-link-color:hover {
text-decoration: underline;
}
/*----------NAVBAR----------*/
.navbar {
display: flex;
}
.nav-tab {
flex: 1;
color: #333; /* Text color */
padding: 10px 0;
text-align: center;
cursor: pointer;
font-size: 14px; /* Smaller font size */
position: relative;
font-weight: 400; /* Regular font weight */
transition: color 0.3s; /* Smooth text color transition */
}
.nav-tab.active {
font-weight: 700; /* Bold font weight for active tab */
color: #1366E2; /* Active tab text color */
}
.nav-tab::after {
content: "";
position: absolute;
bottom: 0;
left: 50%;
width: 0;
height: 2px;
background-color: #1366E2; /* Color of the underline */
transition: width 0.3s, left 0.3s; /* Transition for underline */
}
.nav-tab.active::after {
width: 100%;
left: 0;
}
.content {
display: none;
padding: 20px;
}
.active {
display: block;
}
/*----------SCAN CONTENT----------*/
.main-content {
text-align: center;
}
.main-page-big {
font-size: 14px;
font-weight: 600;
margin-top: 195px;
color: rgba(0,0,0,.8);
text-align: center;
}
.main-page-small {
font-size: 12px;
font-weight: 400;
color: rgba(0,0,0,.8);
text-align: center;
}
.styles-detected-msg, #frames-msg {
font-size: 12px;
font-weight: 400;
color: rgba(0,0,0,.8);
display: none;
margin: 0px 0px 5px;
text-align: left;
}
.scan-btn {
width: 316px;
height: 45px;
font-size: 14px;
font-weight: 600;
color: white;
background-color: #1366E2;
border: none;
border-radius: 6px;
/* position: absolute;
bottom: 15;
left: 22.5; */
position: fixed; /* Change this line */
bottom: 15px; /* Change this line */
left: 22.5px; /* Change this line */
z-index: 999;
}
.scan-btn:hover {
background-color: #0E57C2;
}
/*----------ELEMENTS TO FIX----------*/
.scrollable-container {
max-height: 440px; /* Adjust the height as needed */ /*change to just height??*/
overflow-y: auto;
}
.element-list {
list-style-type: none;
padding: 0;
text-align: left;
}
.element {
border-radius: 8px;;
padding: 15px;
margin: 10px 0px;
position: relative;
}
.element:hover {
background-color: #F8F8F8;
}
.element:hover .suggested-text-style, .element:hover .suggested-paint-style {
color: #0E57C2;
}
.element:hover .element-name {
font-weight: 600;
}
.element-name {
font-weight: 400;
font-size: 12px;
margin-bottom: 8px;
margin-left: 20px;
color: rgba(0,0,0,.8);
}
.suggested-text-style, .suggested-paint-style {
font-weight: 600;
font-size: 12px;
margin-left: 20px;
color: rgba(0,0,0,.8);
}
.zoom-icon {
fill: #CECCCC;
transition: fill 0.1s;
position: absolute;
right: 5;
bottom: 15;
}
.zoom-icon:hover {
fill: rgba(0,0,0,.6);
}
.element-icon {
position: absolute;
width: 15px;
height: 15px;
left: 10;
bottom: 52;
fill: rgba(0,0,0,.6);
}
/*----------GET CSS CONTENT----------*/
#copy-css-container {
width: 100%;
background-color: rgba(0,0,0,.65);
border-radius: 8px 8px 0px 0px;
text-align: right;
padding: 5px 0px;
}
#copy-css-button {
color: rgba(255,255,255,.8);
background-color: rgba(0,0,0,0);
border: none;
padding: 3px;
margin-right: 10px;
}
#copy-icon {
vertical-align: middle;
margin-left: 5px;
fill: rgba(255,255,255,.8);
}
#copy-css-button:hover, #copy-css-button:hover #copy-icon {
cursor: pointer;
color: rgba(255,255,255,.6);
fill: rgba(255,255,255,.6);
}
#css-textbox {
width: 100%;
height: 420px;
background-color: rgba(0,0,0,.8);
color: #fff;
border: 3px solid rgba(0,0,0,0);
resize: none;
border-radius: 0px 0px 8px 8px;
}
/*----------SUGESTIONS CONTENT----------*/
.suggestions-list {
list-style-type: none;
padding: 0;
text-align: left;
max-height: 440px;
}
.suggestion {
border-radius: 8px;
padding: 15px;
margin: 10px 0px;
position: relative;
background-color: #FFF9EC;
}
.suggestion .suggestion-name {
font-weight: 600;
font-size: 12px;
margin-bottom: 8px;
margin-left: 20px;
color: rgba(0, 0, 0, 0.8);
}
.suggestion .text-suggestion,
.suggestion .paint-suggestion {
font-weight: 400;
font-size: 12px;
margin-left: 20px;
color: rgba(0, 0, 0, 0.6);
}
.warn-icon {
fill: rgba(0,0,0,.6);
transition: fill 0.1s;
position: absolute;
width: 18px;
height: 18px;
left: 10;
top: 13;
}
/*----------FRAMES LIST----------*/
.frame-list {
list-style-type: none;
padding: 0;
text-align: left;
}
.frame {
border-radius: 8px;;
padding: 15px;
margin: 10px 0px;
position: relative;
height: 15px;
}
.frame-name {
font-weight: 600;
font-size: 12px;
margin-bottom: 8px;
margin-left: 20px;
color: rgba(0,0,0,.8);
}
.frame:hover {
background-color: #F8F8F8;
}
.frame:hover .frame-name {
font-weight: 600;
}
.frame-icon {
position: absolute;
width: 15px;
height: 15px;
left: 10;
bottom: 16;
fill: rgba(0,0,0,.6);
}
.back-button {
display: none;
flex-direction: row;
justify-content: middle;
font-size: 14px;
color: rgba(0,0,0,.6);
font-weight: 500;
background-color: transparent;;
border: none;
height: auto;
width: auto;
margin-top: 10px;
margin-bottom: 0;
}
.back-button:hover {
color: rgba(0,0,0,.8);
}
.back-button:hover .backBtn-svg {
fill: rgba(0, 0, 0, 0.8);
}
.backBtn-svg {
width: 18px;
height: 18px;
fill: rgba(0,0,0,.6);
margin-right: 5px;
margin-bottom: 0;
}
.back-button p {
justify-content: middle;
margin-top: 4px;
margin-bottom: 0;
}
</style>
</head>
<body>
<!--FEEDBACK-->
<div class="feedback">
<a target="_blank" href="https://forms.gle/Bmchu1G4oCtsyhkR9"><p><span class="blue-link-color">Feedback or Requests?</span> -> Let us know</p></a>
</div>
<!--NAVBAR-->
<nav class="navbar">
<div class="nav-tab active" id="scan-tab">Scan</div>
<div class="nav-tab" id="export-css-tab">Export CSS</div>
<div class="nav-tab" id="suggestions-tab">Suggestions</div>
</nav>
<!--SCAN CONTENT-->
<div id="scan-content" class="content">
<div class="main-content">
<!--Pointer Vector Image?-->
<p class="main-page-big">Welcome to DESY!</p>
<p class="main-page-small">Press "Scan File" to get started.</p>
<p class="styles-detected-msg" id="styles-detected-msg"><!--placeholder--></p>
<!--Back Button for FRAMES-->
<button class="back-button">
<svg class="backBtn-svg" xmlns="http://www.w3.org/2000/svg"><path d="M13.293 6.293 7.586 12l5.707 5.707 1.414-1.414L10.414 12l4.293-4.293z"></path></svg>
<p id="back">Back</p>
</button>
<!--FRAMES FIRST BEFORE ELEMENTS-->
<div id="frame-list-content">
<p id="frames-msg"><!--placeholder--></p>
<div class="scrollable-container">
<ul class="frame-list">
<!-- Frame items will be added here dynamically -->
</ul>
</div>
</div>
<div class="scrollable-container">
<ul class="element-list">
<!-- <li class="element">
<div class="element-name">Element 1</div>
<div class="suggested-text-style">Suggested Text Style</div>
<div class="suggested-paint-style">Suggested Paint Style</div>
<button class="zoom-button">Zoom</button>
</li> -->
<!-- Add more elements here -->
</ul>
</div>
<button class="scan-btn runTestButton" id="runTestButton">Scan File</button>
</div>
</div>
<!--EXPORT CSS CONTENT-->
<div id="export-css-content" class="content">
<div id="export-css" class="tabcontent">
<div id="copy-css-container">
<button id="copy-css-button">Copy code<svg id="copy-icon" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path d="M20 2H10c-1.103 0-2 .897-2 2v4H4c-1.103 0-2 .897-2 2v10c0 1.103.897 2 2 2h10c1.103 0 2-.897 2-2v-4h4c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zM4 20V10h10l.002 10H4zm16-6h-4v-4c0-1.103-.897-2-2-2h-4V4h10v10z"></path></svg></button>
</div>
<textarea id="css-textbox" readonly></textarea>
<button class="scan-btn" id="get-css-button">Get CSS</button>
</div>
</div>
<!--SUGGESTIONS CONTENT-->
<div id="suggestions-content" class="content">
<div class="main-content">
<p class="main-page-big">Welcome to DESY!</p>
<p class="main-page-small">Press "Scan File" to get started.</p>
<p class="styles-detected-msg" id="suggestions-detected-msg"><!--placeholder--></p>
<div class="scrollable-container">
<ul class="suggestions-list">
<!-- <li class="element">
<div class="element-name">Element 1</div>
<div class="suggested-text-style">Suggested Text Style</div>
<div class="suggested-paint-style">Suggested Paint Style</div>
<button class="zoom-button">Zoom</button>
</li> -->
<!-- Add more elements here -->
</ul>
</div>
<button class="scan-btn runTestButton" id="runTestButton">Scan File</button>
</div>
</div>
<script>
// ----------NAVBAR-----------
const tabs = document.querySelectorAll('.nav-tab');
const contents = document.querySelectorAll('.content');
tabs.forEach((tab, index) => {
tab.addEventListener('click', () => {
// Remove "active" class from all tabs and contents
tabs.forEach(tab => tab.classList.remove('active'));
contents.forEach(content => content.classList.remove('active'));
// Add "active" class to the clicked tab and corresponding content
tab.classList.add('active');
contents[index].classList.add('active');
});
});
// Show the "Scan" tab and content by default
document.getElementById('scan-tab').classList.add('active');
document.getElementById('scan-content').classList.add('active');
// ----------SCAN PAGE----------
const testBtns = document.getElementsByClassName("runTestButton");
Array.from(testBtns).forEach(btn => {
btn.addEventListener('click', () => {
updateButtonState(btn);
parent.postMessage({
pluginMessage: {
type: 'runTest',
}
}, '*');
});
});
// Disable all buttons with the specified class
function updateButtonState(button) {
document.querySelectorAll('.runTestButton').forEach(disableBtn => {
disableBtn.disabled = true;
disableBtn.style.backgroundColor = 'grey';
});
}
// adding elements to elements list
onmessage = (event) => {
const pluginMessage = event.data.pluginMessage;
// Elements in the scan page
document.querySelector("#scan-content .main-page-big").style.display = "none";
document.querySelector("#scan-content .main-page-small").style.display = "none";
document.querySelector("#scan-content .styles-detected-msg").style.display = "block";
// Elements in the suggestions page
document.querySelector("#suggestions-content .main-page-big").style.display = "none";
document.querySelector("#suggestions-content .main-page-small").style.display = "none";
// document.querySelector(".main-page-big").style.display = "none";
// document.querySelector(".main-page-small").style.display = "none";
// document.querySelector(".styles-detected-msg").style.display = "block";
document.querySelector("#suggestions-detected-msg").style.display = "block";
if (pluginMessage.type === 'updateElements') {
const elementsToFix = pluginMessage.elementsToFix;
const stylesDetectedMsg = document.getElementById("styles-detected-msg"); // Get the element
const elementList = document.querySelector('.element-list');
elementList.innerHTML = ''; // Clear the existing list
// TEST FOR FRAMES
var frameNamesList = {};
if (elementsToFix.length === 0) {
// Handle the case when there are no items to fix
const noItemsElement = document.createElement('li');
noItemsElement.textContent = 'No items to fix.';
elementList.appendChild(noItemsElement);
} else {
// stylesDetectedMsg.textContent = `${elementsToFix.length} element(s) detected with no style applied.`;
// Iterate through the items to fix and create UI elements for each
for (const item of elementsToFix) {
// For each item you want to add
const frame = {
parentFrameName: item.parentFrameName, // Example parent frame name
parentFrameId: item.parentFrameId,
suggestedTextStyle: item.suggestedTextStyle,
suggestedPaintStyle: item.suggestedPaintStyle,
};
// Create an element object
const element = {
name: item.name,
suggestedTextStyle: item.suggestedTextStyle,
suggestedPaintStyle: item.suggestedPaintStyle,
id: item.id
};
// Check if the parentFrameName is already in frameNamesList
if (!frameNamesList.hasOwnProperty(frame.parentFrameName)) {
// If not, create an array for the parentFrameName key and push the element
frameNamesList[frame.parentFrameName] = [element];
} else {
// If yes, push the element to the existing array for the parentFrameName key
frameNamesList[frame.parentFrameName].push(element);
}
// can uncomment to go back to regualar elements list
// const elementItem = document.createElement('li');
// elementItem.className = 'element';
// const elementName = document.createElement('div');
// elementName.className = 'element-name';
// elementName.textContent = item.name;
// elementItem.appendChild(elementName);
// if (item.suggestedTextStyle) {
// const suggestedTextStyle = document.createElement('div');
// suggestedTextStyle.className = 'suggested-text-style';
// suggestedTextStyle.textContent = 'Suggested Text Style: ' + item.suggestedTextStyle;
// elementItem.appendChild(suggestedTextStyle);
// }
// if (item.suggestedPaintStyle) {
// const suggestedPaintStyle = document.createElement('div');
// suggestedPaintStyle.className = 'suggested-paint-style';
// suggestedPaintStyle.textContent = 'Suggested Paint Style: ' + item.suggestedPaintStyle;
// elementItem.appendChild(suggestedPaintStyle);
// }
// // elementList.appendChild(elementItem);
// // Create SVG icons for different element types
// const textIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M5 8h2V6h3.252L7.68 18H5v2h8v-2h-2.252L13.32 6H17v2h2V4H5z"></path></svg>`;
// const rectangleIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M20 3H4a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V4a1 1 0 0 0-1-1zm-1 16H5V5h14v14z"></path></svg>`;
// const vectorIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M10.061 19.061 17.121 12l-7.06-7.061-2.122 2.122L12.879 12l-4.94 4.939z"></path></svg>`;
// const otherIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M17.867 2.504c-.355-.624-1.381-.623-1.736 0l-3.999 7A1 1 0 0 0 13 11h8a1.001 1.001 0 0 0 .868-1.496l-4.001-7zM3 22h7a1 1 0 0 0 1-1v-7a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1zm14.5-9c-2.481 0-4.5 2.019-4.5 4.5s2.019 4.5 4.5 4.5 4.5-2.019 4.5-4.5-2.019-4.5-4.5-4.5z"></path></svg>';
// // Assuming element.type contains the type of the element (e.g., "text", "rectangle", "vector")
// const typeContainer = document.createElement('div');
// typeContainer.className = 'element-name';
// typeContainer.textContent = item.name; // Element title
// // Create an icon container
// const iconContainer = document.createElement('div');
// iconContainer.className = 'element-icon';
// // Add the appropriate icon to the icon container based on the element type
// let icon;
// // console.log(item.type);
// switch (item.type) {
// case 'TEXT':
// icon = textIcon;
// break;
// case 'RECTANGLE':
// icon = rectangleIcon;
// break;
// case 'VECTOR':
// icon = vectorIcon;
// break;
// default:
// // Use a default icon or handle other types
// icon = otherIcon;
// }
// // Set the innerHTML of the icon container to the selected icon
// iconContainer.innerHTML = icon;
// // Append the icon container and element title to the elementItem
// elementItem.appendChild(iconContainer);
// // adds zoom icon
// const svgIcon = `
// <svg class="zoom-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24";"><circle cx="12" cy="12" r="4"></circle><path d="M13 4.069V2h-2v2.069A8.01 8.01 0 0 0 4.069 11H2v2h2.069A8.008 8.008 0 0 0 11 19.931V22h2v-2.069A8.007 8.007 0 0 0 19.931 13H22v-2h-2.069A8.008 8.008 0 0 0 13 4.069zM12 18c-3.309 0-6-2.691-6-6s2.691-6 6-6 6 2.691 6 6-2.691 6-6 6z"></path></svg>
// `;
// const iconDiv = document.createElement('div');
// iconDiv.className = 'zoom-icon';
// // Set the innerHTML of the iconDiv to your SVG icon
// iconDiv.innerHTML = svgIcon;
// // Add a click event listener to the iconDiv
// iconDiv.addEventListener('click', () => {
// // Use the Figma Plugin API to select and zoom to the specific element
// parent.postMessage({
// pluginMessage: {
// type: 'zoomToElement',
// elementId: item.id, // Provide the ID of the element to zoom to
// }
// }, '*');
// });
// // Append the iconDiv to the elementItem
// elementItem.appendChild(iconDiv);
}
// .frame is li
// .frame-name is div of frame name
// frames message
const framesMsg = document.querySelector("#frames-msg");
framesMsg.style.display = 'block';
framesMsg.textContent = `${Object.keys(frameNamesList).length} frame(s) with errors.`;
// TESTING ADDING FRAMES
for (const name of Object.keys(frameNamesList)) {
console.log(name);
const frameItem = document.createElement('li');
frameItem.className = 'frame';
const frameName = document.createElement('div');
frameName.className = 'frame-name';
frameName.textContent = name;
frameItem.appendChild(frameName);
// add frame icon
const svgFrameIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 9a1 1 0 0 0 1-1V4a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v1H9V4a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h1v6H4a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-1h6v1a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1h-1V9h1zm-3-4h2v2h-2V5zM5 5h2v2H5V5zm2 14H5v-2h2v2zm12 0h-2v-2h2v2zm-2-4h-1a1 1 0 0 0-1 1v1H9v-1a1 1 0 0 0-1-1H7V9h1a1 1 0 0 0 1-1V7h6v1a1 1 0 0 0 1 1h1v6z"></path></svg>';
const frameIconDiv = document.createElement('div');
frameIconDiv.className = 'frame-icon';
frameIconDiv.innerHTML = svgFrameIcon;
frameItem.appendChild(frameIconDiv);
const elementList = document.querySelector('.element-list');
const frameList = document.querySelector('.frame-list');
frameItem.addEventListener('click', () => {
// console.log(frameNamesList[name]);
elementList.innerHTML = ''; // Clear the existing elements list
//frameList.innerHTML = ''; // Clear the existing frames list
const framesListElement = document.querySelector('#frame-list-content');
framesListElement.style.display = 'none';
// Show the back button
const backButton = document.querySelector('.back-button');
backButton.style.display = 'flex';
console.log( "STYLE: " + backButton.style.display);
for (item of frameNamesList[name]) {
// console.log(item);
processElement(item);
}
framesMsg.style.display = 'none';
stylesDetectedMsg.style.display = 'block';
stylesDetectedMsg.textContent = `${frameNamesList[name].length} element(s) detected with no style applied.`;
});
frameList.appendChild(frameItem);
}
// Add this event listener outside the loop
const backButton = document.querySelector('.back-button');
backButton.addEventListener('click', () => {
// clear elements count
stylesDetectedMsg.style.display = 'none';
framesMsg.style.display = 'block';
framesMsg.textContent = `${Object.keys(frameNamesList).length} frame(s) with error.`;
// Show the frame list
const framesListElement = document.querySelector('#frame-list-content');
framesListElement.style.display = 'block';
// Hide the back button
backButton.style.display = 'none';
// Clear the existing element list
const elementList = document.querySelector('.element-list');
elementList.innerHTML = '';
});
} // end else for length > 0
} else if (pluginMessage.type === 'stylingSuggestions') {
// console.log("got suggestions message"); // worked
const suggestionsToMake = pluginMessage.suggestionsToMake;
const suggestionsDetectedMsg = document.getElementById("suggestions-detected-msg"); // Get the element
const suggestionsList = document.querySelector('.suggestions-list');
suggestionsList.innerHTML = ''; // clear existing list
if (suggestionsToMake.length === 0) {
const noSuggestionsElement = document.createElement('li');
noSuggestionsElement.textContent = 'No items to fix.';
suggestionsList.appendChild(noSuggestionsElement);
} else {
// gets length of two sublists (one is color style one is text style)
var suggestionAmount = suggestionsToMake[0].length + suggestionsToMake[1].length;
suggestionsDetectedMsg.textContent = `${suggestionAmount} saved style suggestions created.`;
for (const item of suggestionsToMake) {
for (const elt of item) {
const styleSpecs = rgbToHex(elt.styleSpecs);
const repeats = elt.repeats;
const sentence = elt.sentence;
// const suggestionTitle = repeats + " items found using " + styleSpecs;
// console.log(elt);
const suggestionElement = document.createElement('li');
suggestionElement.className = 'suggestion';
const suggestionName = document.createElement('div');
suggestionName.className = 'suggestion-name';
// adding warning icon
const svgWarnIcon = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M11 7h2v7h-2zm0 8h2v2h-2z"></path><path d="m21.707 7.293-5-5A.996.996 0 0 0 16 2H8a.996.996 0 0 0-.707.293l-5 5A.996.996 0 0 0 2 8v8c0 .266.105.52.293.707l5 5A.996.996 0 0 0 8 22h8c.266 0 .52-.105.707-.293l5-5A.996.996 0 0 0 22 16V8a.996.996 0 0 0-.293-.707zM20 15.586 15.586 20H8.414L4 15.586V8.414L8.414 4h7.172L20 8.414v7.172z"></path></svg>
`;
const warnIconDiv = document.createElement('div');
warnIconDiv.className = 'warn-icon';
warnIconDiv.innerHTML = svgWarnIcon;
suggestionElement.appendChild(warnIconDiv);
if (elt.type == "text") {
suggestionName.textContent = repeats + " elements found with text color " + styleSpecs;
suggestionElement.appendChild(suggestionName);
const textSuggestion = document.createElement('div');
textSuggestion.className = 'text-suggestion';
textSuggestion.textContent = "Consider making it a new color style or applying existing color styles to these items.";
suggestionElement.appendChild(textSuggestion);
}
if (elt.type == "color") {
suggestionName.textContent = repeats + " elements found with fill color " + styleSpecs;
suggestionElement.appendChild(suggestionName);
const paintSuggestion = document.createElement('div');
paintSuggestion.className = 'paint-suggestion';
paintSuggestion.textContent = "Consider making it a new color style or applying existing color styles to these items.";
suggestionElement.appendChild(paintSuggestion);
}
suggestionsList.appendChild(suggestionElement);
}
}
}
}
// re enables the scan button after any change is made
else if (pluginMessage.type === 'enableButton') {
const stylesDetectedMsg2 = document.getElementById("styles-detected-msg");
stylesDetectedMsg2.style.display = 'none';
document.querySelectorAll('.runTestButton').forEach(enableBtn => {
enableBtn.disabled = false;
enableBtn.style.backgroundColor = '#1366E2';
});
}
// Generate CSS for paint styles (fills)
else if (pluginMessage.type === 'cssData') {
const generatedCSS = pluginMessage.css;
// Update the textarea with the generated CSS
document.getElementById('css-textbox').value = generatedCSS;
} // end get CSS data loop
else if (pluginMessage.type === 'stylesData') {
const styles = pluginMessage.styles;
// Use the received text styles and paint styles as needed
const savedTextStyles = styles.textStyles;
const savedPaintStyles = styles.paintStyles;
} // end loop for get styles CSS data
}
// only works with this included - come back to
// enable all buttons with the specified class
function revertButtonState(button) {
document.querySelectorAll('.runTestButton').forEach(enableBtn => {
enableBtn.disabled = false;
enableBtn.style.backgroundColor = '#1366E2';
});
}
// export CSS Code
document.getElementById('get-css-button').onclick = () => {
parent.postMessage({ pluginMessage: { type: 'getStyles' } }, '*');
parent.postMessage({pluginMessage: {type: 'getCSS',},}, '*');
} // end CSS button click
// Copy the generated CSS code to the clipboard
document.getElementById('copy-css-button').onclick = () => {
const cssTextarea = document.getElementById('css-textbox');
// Create a range and select the text in the textarea
const range = document.createRange();
range.selectNode(cssTextarea);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
try {
// Copy the selected text to the clipboard
document.execCommand('copy');
console.log('Text copied to clipboard!');
// green border on copy, disappears after 1 second
cssTextarea.style.border = '3px solid #00ff00';
setTimeout(() => {
cssTextarea.style.border = '3px solid rgba(0,0,0,0)';
}, 1000);
} catch (err) {
console.error('Unable to copy text to clipboard', err);
} finally {
// Clean up by deselecting the text
window.getSelection().removeAllRanges();
}
}; // end copy button click
// comnvert from RGB to HEX
function rgbToHex(rgbValue) {
// Split the RGB values using the "-" separator
const rgbArray = rgbValue.split('-').map(Number);
// Ensure the input values are within the valid range (0-1)
const r = Math.min(1, Math.max(0, rgbArray[0]));
const g = Math.min(1, Math.max(0, rgbArray[1]));
const b = Math.min(1, Math.max(0, rgbArray[2]));
// Convert the values to integers
const red = Math.round(r * 255);
const green = Math.round(g * 255);
const blue = Math.round(b * 255);
// Convert to hexadecimal format
const redHex = red.toString(16).padStart(2, '0');
const greenHex = green.toString(16).padStart(2, '0');
const blueHex = blue.toString(16).padStart(2, '0');
// Combine the values to form the hex color code
const hexColor = `#${redHex}${greenHex}${blueHex}`;
return hexColor;
}
function processElement(item) {
const elementList = document.querySelector('.element-list');
// elementList.innerHTML = ''; // Clear the existing list
console.log("item: " + item.name);
const elementItem = document.createElement('li');
elementItem.className = 'element';
const elementName = document.createElement('div');
elementName.className = 'element-name';
elementName.textContent = item.name;
elementItem.appendChild(elementName);
if (item.suggestedTextStyle) {
const suggestedTextStyle = document.createElement('div');
suggestedTextStyle.className = 'suggested-text-style';
suggestedTextStyle.textContent = 'Suggested Text Style: ' + item.suggestedTextStyle;
elementItem.appendChild(suggestedTextStyle);
}
if (item.suggestedPaintStyle) {
const suggestedPaintStyle = document.createElement('div');
suggestedPaintStyle.className = 'suggested-paint-style';
suggestedPaintStyle.textContent = 'Suggested Paint Style: ' + item.suggestedPaintStyle;
elementItem.appendChild(suggestedPaintStyle);
}
elementList.appendChild(elementItem);
// Create SVG icons for different element types
const textIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M5 8h2V6h3.252L7.68 18H5v2h8v-2h-2.252L13.32 6H17v2h2V4H5z"></path></svg>`;
const rectangleIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M20 3H4a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V4a1 1 0 0 0-1-1zm-1 16H5V5h14v14z"></path></svg>`;
const vectorIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M10.061 19.061 17.121 12l-7.06-7.061-2.122 2.122L12.879 12l-4.94 4.939z"></path></svg>`;
const otherIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24";"><path d="M17.867 2.504c-.355-.624-1.381-.623-1.736 0l-3.999 7A1 1 0 0 0 13 11h8a1.001 1.001 0 0 0 .868-1.496l-4.001-7zM3 22h7a1 1 0 0 0 1-1v-7a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1zm14.5-9c-2.481 0-4.5 2.019-4.5 4.5s2.019 4.5 4.5 4.5 4.5-2.019 4.5-4.5-2.019-4.5-4.5-4.5z"></path></svg>';
// Assuming element.type contains the type of the element (e.g., "text", "rectangle", "vector")
const typeContainer = document.createElement('div');
typeContainer.className = 'element-name';
typeContainer.textContent = item.name; // Element title
// Create an icon container
const iconContainer = document.createElement('div');
iconContainer.className = 'element-icon';
// Add the appropriate icon to the icon container based on the element type
let icon;
// console.log(item.type);
switch (item.type) {
case 'TEXT':
icon = textIcon;