-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.html
752 lines (709 loc) · 30.5 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
<!-- ui.html -->
<!DOCTYPE html>
<html>
<head>
<!-- Standard link tag-->
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* style.css */
body,
html {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
body {
width: 100%;
height: auto;
font-family: "Inter";
}
.container {
max-width: 800px;
margin: auto;
padding: 20px;
text-align: left;
}
.tab-content {
display: none;
}
</style>
</head>
<body class="bg-white dark:bg-slate-800">
<div class="container">
<h1 class="flex items-center text-3xl font-extrabold dark:text-white mb-4">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="32" height="32" fill="currentColor" class="mr-2">
<path
d="M4.25705 5.67127L6.39362 7.80783C5.5184 8.97641 5 10.4277 5 12C5 15.866 8.13401 19 12 19C15.866 19 19 15.866 19 12C19 8.13401 15.866 5 12 5C10.4277 5 8.97641 5.5184 7.80783 6.39362L5.67127 4.25705C7.39514 2.84637 9.59873 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 9.59873 2.84637 7.39514 4.25705 5.67127ZM7.8284 9.24261L12 13.4142L13.4142 12L9.24261 7.8284C10.033 7.30488 10.9809 7 12 7C14.7614 7 17 9.23858 17 12C17 14.7614 14.7614 17 12 17C9.23858 17 7 14.7614 7 12C7 10.9809 7.30488 10.033 7.8284 9.24261Z"
></path>
</svg> Design System Radar
</h1>
<button type="button" id="getDataButton" class="text-white bg-indigo-500 hover:bg-indigo-600 focus:ring-4 focus:outline-none focus:ring-indigo-100 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center me-2 dark:bg-indigo-500 dark:hover:bg-indigo-500 dark:focus:ring-indigo-100">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="20"
height="20"
fill="currentColor"
class="mr-2"
>
<path
d="M5.67127 4.25705L13.4142 12L12 13.4142L8.55382 9.96803C8.20193 10.5635 8 11.2582 8 12C8 14.2091 9.79086 16 12 16C14.2091 16 16 14.2091 16 12C16 9.87494 14.3429 8.13693 12.2503 8.00771L10.4459 6.20323C10.9416 6.07067 11.4625 6 12 6C15.3137 6 18 8.68629 18 12C18 15.3137 15.3137 18 12 18C8.68629 18 6 15.3137 6 12C6 10.7042 6.41079 9.50428 7.10925 8.52347L5.68014 7.09436C4.62708 8.44904 4 10.1513 4 12C4 16.4183 7.58172 20 12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C10.8915 4 9.83557 4.22547 8.8757 4.63306L7.37443 3.13179C8.75768 2.40883 10.3311 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 8.87842 3.43029 6.09091 5.67127 4.25705Z"
></path>
</svg>
Scan selection
</button>
<p class="mb-3 text-gray-500 dark:text-gray-400 text-sm mt-2">
Scan your interfaces to make them Design System compliant
</p>
<div class="border-b border-gray-200 dark:border-gray-700">
<ul class="flex flex-wrap -mb-px text-sm font-medium text-center text-gray-500 dark:text-gray-400">
<li class="me-2">
<button onclick="openTab(event, 'Instances')" id="tabInstances" class="tab-button inline-flex items-center justify-center p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-500 dark:hover:text-gray-300 group">
<svg
width="16"
height="16"
fill="none"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
class="w-4 h-4 me-2"
>
<rect
x="12"
y="1.88388"
width="14.75"
height="14.75"
transform="rotate(45 12 1.88388)"
stroke="currentColor"
stroke-width="1.25"
/></svg
>Instances
<span
id="instancesCount"
class="ml-1 text-xs font-medium me-2 px-2 py-0.5 font-semibold text-indigo-600 bg-indigo-100 dark:bg-indigo-500 border border-transparent dark:text-white rounded-full"
>0</span
>
</button>
</li>
<li class="me-2">
<button onclick="openTab(event, 'Variables')" id="tabVariablesButton" class="tab-button inline-flex items-center justify-center p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-500 dark:hover:text-gray-300 group">
<svg
width="20"
height="16"
viewBox="0 0 20 16"
xmlns="http://www.w3.org/2000/svg"
class="w-4 h-4 me-2"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M6.8936 1.59903L1.37872 4.79986V11.1988L6.8936 14.3996L12.4085 11.1988V4.79986L6.8936 1.59764V1.59903ZM13.7872 3.99896L6.8936 0L0 3.99896V11.9997L6.8936 16L13.7872 11.9997V3.99896ZM17.9234 11.1988L11.0298 15.1991L12.4085 16L19.3021 11.9997V3.99896L12.4085 0L11.0298 0.799515L17.9234 4.79986V11.1988ZM8.27232 7.99931C8.27232 8.76418 7.65465 9.38495 6.8936 9.38495C6.13255 9.38495 5.51488 8.76418 5.51488 7.99931C5.51488 7.23443 6.13255 6.61367 6.8936 6.61367C7.65465 6.61367 8.27232 7.23443 8.27232 7.99931Z"
fill="currentColor"
/>
</svg>
Variables
<span
id="variablesCount"
class="bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300 border border-red-400 ml-1 text-xs font-medium me-2 px-2 py-0.5 font-semibold rounded-full"
>0</span
>
</button>
</li>
<li class="me-2">
<button onclick="openTab(event, 'Dimension')" class="tab-button inline-flex items-center justify-center p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-500 dark:hover:text-gray-300 group">
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="currentColor"
class="w-4 h-4 me-2"
>
<path
d="M17 19H19V14H10V5H5V7H7V9H5V11H8V13H5V15H7V17H5V19H7V17H9V19H11V16H13V19H15V17H17V19ZM12 12H20C20.5523 12 21 12.4477 21 13V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H11C11.5523 3 12 3.44772 12 4V12Z"
></path>
</svg>
Dimensions
<span
id="dimensionCount"
class="border border-red-400 bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300 ml-1 text-xs font-medium me-2 px-2 py-0.5 font-semibold rounded-full"
>0</span
>
</button>
</li>
</ul>
</div>
<div id="Instances" class="tab-content">
<div class="table-container">
<div class="relative overflow-x-auto mt-2">
<caption class="p-5 text-lg text-left rtl:text-right text-gray-900 bg-white dark:text-white dark:bg-gray-800">
<strong class="font-semibold dark:text-slate-100">Instances checker:</strong
>
<p
class="mt-1 text-sm font-normal text-gray-500 dark:text-gray-400"
>
List of instances in the selection
</p>
<p class="mt-1 text-sm font-normal text-gray-500 dark:text-gray-400 italic">You can write <code>[ds-radar]</code> in your design system components description to reference them in the instance analysis.</p>
</caption>
<table
id="dataList"
class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400 mt-2"
>
<thead
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400"
>
<tr>
<th scope="col" class="px-6 py-3">Instance name</th>
<th scope="col" class="px-6 py-3">
Design system component?
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div id="Variables" class="tab-content">
<div class="relative overflow-x-auto mt-2">
<div id="styleAnalysisResult">
<div
class="max-w-sm p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow dark:bg-slate-800 dark:border-slate-700"
>
<svg
class="w-6 h-6 text-gray-800 dark:text-white mb-3"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 19 19"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M11.013 7.962a3.519 3.519 0 0 0-4.975 0l-3.554 3.554a3.518 3.518 0 0 0 4.975 4.975l.461-.46m-.461-4.515a3.518 3.518 0 0 0 4.975 0l3.553-3.554a3.518 3.518 0 0 0-4.974-4.975L10.3 3.7"
/>
</svg>
<p class="mb-2 font-normal text-gray-500 dark:text-gray-400">
Linked variables:
</p>
<span id="percentageBound"></span>
</div>
<caption
class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white dark:text-white dark:bg-gray-800"
>
<strong class="font-semibold dark:text-slate-100"
>Nodes with unbounded variables:</strong
>
<p
class="mt-1 text-sm font-normal text-gray-500 dark:text-gray-400"
>
List of unbounded variables in your selection
</p>
</caption>
<div class="relative overflow-x-auto mt-2">
<table
class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400"
>
<thead
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400"
>
<tr>
<th scope="col" class="px-6 py-3">Node</th>
<th scope="col" class="px-6 py-3">Preview</th>
</tr>
</thead>
<tbody id="listUnboundNodes"></tbody>
</table>
</div>
</div>
</div>
</div>
<div id="Dimension" class="tab-content">
<div class="relative overflow-x-auto mt-2">
<div class="relative w-full">
<input id="spacingInput" type="text" placeholder="Ex: 8, 16, 32" class="block p-2.5 w-full z-20 text-sm text-gray-900 bg-gray-50 rounded-e-lg rounded-lg rounded-s-gray-100 rounded-s-2 border border-gray-300 focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:border-indigo-500"
/>
<button id="updateButton" class="absolute top-0 end-0 p-2.5 h-full text-sm font-medium text-white bg-indigo-500 rounded-e-lg hover:bg-indigo-600 focus:ring-4 focus:outline-none focus:ring-indigo-100 dark:bg-indigo-500 dark:hover:bg-indigo-600 dark:focus:ring-indigo-800">Set dimensions system</button>
</div>
<p class="mt-2 mb-2 text-sm text-gray-500 dark:text-gray-400">You can use your own dimensions system. For ex: 0, 2, 4, 8, 12, 16, 32, ...</p>
<caption
class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white dark:text-white dark:bg-gray-800"
>
<strong class="font-semibold dark:text-slate-100"
>Dimensions</strong
>
<p
class="mt-1 text-sm font-normal text-gray-500 dark:text-gray-400"
>
You must bind correct units for spacing.
</p>
</caption>
<div class="relative overflow-x-auto mt-2">
<table
class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400"
id="dimensionTable"
>
<thead
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400"
>
<tr>
<th scope="col" class="px-6 py-3">Frame Name</th>
<th scope="col" class="px-6 py-3">Prop</th>
<th scope="col" class="px-6 py-3">Spacing</th>
</tr>
</thead>
<tbody id="dimensionsList"></tbody>
</table>
</div>
</div>
</div>
</div>
<script>
function openTab(evt, tabName) {
var i, tabcontent, tabbuttons;
// Cacher tout le contenu des onglets
tabcontent = document.getElementsByClassName("tab-content");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Retirer les classes actives et ajouter les classes de base à tous les boutons des onglets
tabbuttons = document.getElementsByClassName("tab-button");
for (i = 0; i < tabbuttons.length; i++) {
tabbuttons[i].classList.remove(
"text-indigo-600",
"border-indigo-600",
"active",
"dark:text-indigo-500",
"dark:border-indigo-600"
);
tabbuttons[i].classList.add(
"border-transparent",
"hover:text-gray-600",
"hover:border-gray-500",
"dark:hover:text-gray-300"
);
}
// Afficher le contenu de l'onglet actuel
document.getElementById(tabName).style.display = "block";
// Ajouter les classes actives à l'onglet actuellement sélectionné
evt.currentTarget.classList.add(
"text-indigo-600",
"border-indigo-600",
"active",
"dark:text-indigo-500",
"dark:border-indigo-600"
);
evt.currentTarget.classList.remove(
"border-transparent",
"hover:text-gray-600",
"hover:border-gray-500",
"dark:hover:text-gray-300"
);
}
// Définir l'onglet par défaut ouvert
document.getElementById("Instances").click();
const dataList = document.getElementById("dataList");
const getDataButton = document.getElementById("getDataButton");
getDataButton.onclick = () => {
//openTabEvent("Instances");
dataList.innerHTML = `<tr>
<th scope="col" class="px-6 py-3">Instance name</th>
<th scope="col" class="px-6 py-3">Design system component?</th>
</tr>`;
parent.postMessage(
{
pluginMessage: {
type: "get-data",
},
},
"*"
);
parent.postMessage(
{
pluginMessage: {
type: "analyze-selection",
},
},
"*"
);
parent.postMessage(
{ pluginMessage: { type: "analyze-dimensions" } },
"*"
);
};
function openTabEvent(tabName) {
var tabButton = document.getElementById("tab" + tabName);
if (tabButton) {
tabButton.click();
}
}
window.onmessage = (event) => {
const message = event.data.pluginMessage;
if (message.type === "instance-data") {
let rows = "";
message.data.forEach(({ instanceName, hasSuffix, instanceId }) => {
rows += `<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
<td class="px-6 py-4"><a href="#" class="instance-link font-medium hover:underline" data-id="${instanceId}">${instanceName}</a></td>
<td class="px-6 py-4">${
hasSuffix
? `<svg class="w-3 h-3 text-green-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5.917 5.724 10.5 15 1.5"/>
</svg>`
: `<svg class="w-3 h-3 text-red-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
</svg>`
}</td>
</tr>`;
});
dataList.innerHTML = `<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-3">Instance name</th>
<th scope="col" class="px-6 py-3">Design system component?</th>
</tr>
</thead>
<tbody>${rows}</tbody>`;
const instancesCountElement =
document.getElementById("instancesCount");
instancesCountElement.textContent = message.data.length.toString();
}
if (message.type === "style-analysis-result") {
updateUIWithAnalysisResults(message.data);
}
if (message.type === "dimension-analysis-result") {
updateDimensionsUI(message.data);
}
const { type, allowedSpacings } = event.data.pluginMessage;
if (type === 'set-allowed-spacings') {
spacingInput.value = allowedSpacings.join(', ');
}
};
// Écouteur d'événements pour les liens d'instance
document.addEventListener("click", function (event) {
if (event.target.classList.contains("instance-link")) {
event.preventDefault();
const instanceId = event.target.getAttribute("data-id");
parent.postMessage(
{
pluginMessage: {
type: "navigate-to-instance",
instanceId,
},
},
"*"
);
}
if (event.target.classList.contains("unbound-node-link")) {
event.preventDefault();
const nodeId = event.target.dataset.id;
parent.postMessage(
{
pluginMessage: {
type: "navigate-to-node",
nodeId,
},
},
"*"
);
}
if (event.target.classList.contains("dimension-link")) {
event.preventDefault();
const nodeId = event.target.dataset.id;
parent.postMessage(
{
pluginMessage: {
type: "navigate-to-node",
nodeId,
},
},
"*"
);
}
});
function updateDimensionsUI(dimensionNodes) {
const dimensionsList = document.getElementById("dimensionsList");
const dimensionCountElement = document.getElementById("dimensionCount");
if (!dimensionsList || !dimensionCountElement) {
console.error("Necessary elements not found in the DOM");
return;
}
// Mettre à jour le compteur de dimensions
dimensionCountElement.textContent = dimensionNodes.length.toString();
// Vérifier si le nombre de nœuds est égal à 0
if (dimensionNodes.length === 0) {
dimensionsList.innerHTML = `<div class="py-2 rounded-lg">
<p class="text-sm text-gray-500 dark:text-gray-400">
<span class="bg-green-100 text-green-800 text-xs font-medium inline-flex items-center px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-green-400 border border-green-400">
<svg class="w-2.5 h-2.5 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5.917 5.724 10.5 15 1.5"/>
</svg>
All dimensions are correct
</span>
</p>
</div>
`;
dimensionCountElement.textContent = "Correct";
dimensionCountElement.classList.add(
"bg-green-100",
"text-green-800",
"dark:bg-green-900",
"dark:text-green-300",
"border-green-400"
);
} else {
dimensionsList.innerHTML = "";
dimensionCountElement.classList.remove(
"bg-green-100",
"text-green-800",
"dark:bg-green-900",
"dark:text-green-300",
"border-green-400"
);
// Construire et afficher le tableau avec les nœuds
dimensionNodes.forEach((node) => {
const row = document.createElement("tr");
row.classList.add(
"bg-white",
"border-b",
"dark:bg-gray-800",
"dark:border-gray-700"
);
// Cellule pour le nom du nœud
const nameCell = document.createElement("td");
nameCell.classList.add("px-6", "py-4");
const link = document.createElement("a");
link.href = "#";
link.textContent = node.name;
link.classList.add(
"dimension-link",
"font-medium",
"hover:underline"
);
link.dataset.id = node.id;
nameCell.appendChild(link);
row.appendChild(nameCell);
//Cellule pour le type de propriété d'espacement
const propCell = document.createElement("td");
propCell.classList.add("px-6", "py-4");
propCell.textContent = node.spacingProp;
row.appendChild(propCell);
// Cellule pour l'espacement
const spacingCell = document.createElement("td");
spacingCell.classList.add("px-6", "py-4");
const spacingData = document.createElement("span");
spacingData.classList.add(
"bg-gray-100",
"text-gray-800",
"text-sm",
"font-medium",
"me-2",
"px-2.5",
"py-0.5",
"rounded",
"dark:bg-gray-700",
"dark:text-gray-300"
);
spacingData.textContent = node.spacing + " px";
spacingCell.appendChild(spacingData);
row.appendChild(spacingCell);
// Ajouter la ligne complète au tableau
dimensionsList.appendChild(row);
});
}
}
function updateUIWithAnalysisResults(data) {
// Décomposer les données reçues
const { totalNodes, boundNodes, unboundNodes } = data;
// Calculer le pourcentage de nœuds liés à une variable
const percentageBound =
totalNodes > 0 ? (boundNodes / totalNodes) * 100 : 0;
const percentageElement = document.getElementById("percentageBound");
percentageElement.textContent = `${percentageBound.toFixed(2)}%`;
// Attribuer une nouvelle classe en fonction du pourcentage
if (percentageBound >= 80) {
for (let i = percentageElement.classList.length - 1; i >= 0; i--) {
const className = percentageElement.classList[i];
if (className.startsWith('bg-') || className.startsWith('text-') ||
className.startsWith('dark:bg-') || className.startsWith('dark:text-') || className.startsWith('border-')) {
percentageElement.classList.remove(className);
}
}
percentageElement.classList.add(
"bg-green-100",
"text-green-800",
"text-md",
"font-bold",
"me-2",
"px-2.5",
"py-0.5",
"rounded",
"dark:bg-gray-700",
"dark:text-green-400",
"border",
"border-green-400"
);
} else if (percentageBound >= 60) {
for (let i = percentageElement.classList.length - 1; i >= 0; i--) {
const className = percentageElement.classList[i];
if (className.startsWith('bg-') || className.startsWith('text-') ||
className.startsWith('dark:bg-') || className.startsWith('dark:text-') || className.startsWith('border-')) {
percentageElement.classList.remove(className);
}
}
percentageElement.classList.add(
"bg-lime-100",
"text-lime-800",
"text-md",
"font-bold",
"me-2",
"px-2.5",
"py-0.5",
"rounded",
"dark:bg-gray-700",
"dark:text-lime-400",
"border",
"border-lime-400"
);
} else if (percentageBound >= 40) {
for (let i = percentageElement.classList.length - 1; i >= 0; i--) {
const className = percentageElement.classList[i];
if (className.startsWith('bg-') || className.startsWith('text-') ||
className.startsWith('dark:bg-') || className.startsWith('dark:text-') || className.startsWith('border-')) {
percentageElement.classList.remove(className);
}
}
percentageElement.classList.add(
"bg-yellow-100",
"text-yellow-800",
"text-md",
"font-bold",
"me-2",
"px-2.5",
"py-0.5",
"rounded",
"dark:bg-gray-700",
"dark:text-yellow-400",
"border",
"border-yellow-400"
);
} else if (percentageBound >= 20) {
for (let i = percentageElement.classList.length - 1; i >= 0; i--) {
const className = percentageElement.classList[i];
if (className.startsWith('bg-') || className.startsWith('text-') ||
className.startsWith('dark:bg-') || className.startsWith('dark:text-') || className.startsWith('border-')) {
percentageElement.classList.remove(className);
}
}
percentageElement.classList.add(
"bg-amber-100",
"text-amber-800",
"text-md",
"font-bold",
"me-2",
"px-2.5",
"py-0.5",
"rounded",
"dark:bg-gray-700",
"dark:text-amber-400",
"border",
"border-amber-400"
);
} else if (percentageBound >= 0){
for (let i = percentageElement.classList.length - 1; i >= 0; i--) {
const className = percentageElement.classList[i];
if (className.startsWith('bg-') || className.startsWith('text-') ||
className.startsWith('dark:bg-') || className.startsWith('dark:text-') || className.startsWith('border-')) {
percentageElement.classList.remove(className);
}
}
percentageElement.classList.add(
"bg-red-100",
"text-red-800",
"text-md",
"font-bold",
"me-2",
"px-2.5",
"py-0.5",
"rounded",
"dark:bg-gray-700",
"dark:text-red-400",
"border",
"border-red-400"
);
}
const listUnboundNodes = document.getElementById("listUnboundNodes");
listUnboundNodes.innerHTML = "";
unboundNodes.forEach((node) => {
// Créer une nouvelle ligne de tableau
const row = document.createElement("tr");
row.classList.add(
"bg-white",
"border-b",
"dark:bg-gray-800",
"dark:border-gray-700"
);
// Créer une cellule pour le nom du nœud et ajouter le lien
const nameCell = document.createElement("td");
nameCell.classList.add("px-6", "py-4");
const link = document.createElement("a");
link.href = "#";
link.textContent = node.name;
link.classList.add(
"unbound-node-link",
"font-medium",
"hover:underline"
);
link.dataset.id = node.id;
nameCell.appendChild(link);
// Créer une cellule pour l'aperçu de la couleur
const colorCell = document.createElement("td");
colorCell.classList.add("px-6", "py-4");
const colorSquare = document.createElement("div");
colorSquare.style.width = "20px";
colorSquare.style.height = "20px";
colorSquare.style.backgroundColor = node.color;
colorSquare.classList.add(
"rounded-sm",
"border",
"border-slate-200",
"dark:border-slate-600"
);
colorCell.appendChild(colorSquare);
row.appendChild(nameCell);
row.appendChild(colorCell);
listUnboundNodes.appendChild(row);
});
const variablesCountElement = document.getElementById("variablesCount");
variablesCountElement.textContent = unboundNodes.length.toString();
if (unboundNodes.length === 0) {
variablesCountElement.textContent = "Correct";
variablesCountElement.classList.add(
"bg-green-100",
"text-green-800",
"dark:bg-green-900",
"dark:text-green-300",
"border-green-400"
);
} else {
variablesCountElement.classList.remove(
"bg-green-100",
"text-green-800",
"dark:bg-green-900",
"dark:text-green-300",
"border-green-400"
);
}
}
const spacingInput = document.getElementById('spacingInput');
const updateButton = document.getElementById('updateButton');
// Envoie les nouvelles valeurs au backend lorsque l'utilisateur clique sur le bouton
updateButton.onclick = () => {
const newSpacings = spacingInput.value.split(',').map(Number);
parent.postMessage({ pluginMessage: { type: 'update-spacings', newSpacings } }, '*');
console.log(newSpacings);
};
</script>
</body>
</html>