-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathui.html
985 lines (802 loc) · 34.2 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
<style>
#frame {
/* COLORS */
/* Basic foreground */
--black: #000000;
--black6: rgba(0, 0, 0, .6);
--black8: rgba(0, 0, 0, .8);
--black8-opaque: #333333;
--black3: rgba(0, 0, 0, .3);
--black3-opaque: #B3B3B3;
--white: #ffffff;
--white8: rgba(255, 255, 255, .8);
--white4: rgba(255, 255, 255, .4);
/* Basic background */
--grey: #f0f0f0;
--silver: #e5e5e5;
--hud: #222222;
--toolbar: #2c2c2c;
--ui-color:#CC00FF;
--spacers-bg: #FAE3FF;
}
* {
font-family: 'Inter', sans-serif;
font-weight: 500;
font-size: 13px;
line-height: 15px;
letter-spacing: 0.005em;
text-align: center;
}
hr{
border-top: 0.5px solid var(--silver);
margin-top: 16px;
margin-bottom: 10px;
}
*:focus {
/* outline-color: #D56CEC;*/
}
body {
/*max-width: 120px;*/
margin: 0px
}
#show {
color: var(--ui-color) ;
border: 1px solid var(--ui-color) ;
}
#hide {
color: var(--black8);
border: 1px solid var(--black8);
}
.header{
position: relative;
margin: 8px;
/* Pos – UI 11 Bold */
font-family: 'Inter', sans-serif;
font-style: normal;
font-weight: 600;
font-size: 11px;
line-height: 16px;
/* identical to box height, or 145% */
display: block;
letter-spacing: .015em;
text-align: left;
/* Black 8 */
color: var(--black8);
}
.headerTop{
font-weight: 600;
font-size: 17px;
margin-top: 16px;
margin-bottom: 8px;
line-height: 24px;
/* identical to box height, or 145% */
display: block;
letter-spacing: .02em;
text-align: center;
/* Black 8 */
color: var(--ui-color);
}
button {
color: var(--black8);
border: 1px solid var(--black8);
background-color: var(--white);
padding: 7px 16px;
border-radius: 6px;
display: inline-block;
margin: 0px 7px;
}
button:hover {
cursor: pointer;
}
#switches,
#spacers {
display: flex;
justify-content: center;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
flex-shrink: 0;
max-width: 284px;
}
#spacers {
margin-top: 0px;
margin-bottom: 8px;
display: inline-flex;
}
#position-buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
margin: -12px auto;
width: 98px;
height: 98px;
}
#position-buttons div {
position: relative;
}
.rtop {
grid-column-start: 2;
grid-row-start: 1;
}
.rleft {
grid-column-start: 1;
grid-row-start: 2;
}
.rright {
grid-column-start: 3;
grid-row-start: 2;
}
.rbottom {
grid-column-start: 2;
grid-row-start: 3;
}
.rreplace {
grid-column-start: 2;
grid-row-start: 2;
}
.spacer-button {
width: 40px;
height : 40px;
border: none ;/*1px solid rgba(222, 222, 222, 0.42);*/
border-radius: 0;
color: var(--spacers-fg);
background-color: var(--spacers-bg);
margin: 10px 8px;
display: flex;
justify-content: center;
margin-bottom: 0px;
}
.spacer-button p{
font-size: 14px;
font-weight: 400;
line-height: 14px;
margin: 0;
}
.spacer-button p span{
font-size: 10px;
font-weight: 300;
line-height:14px;
opacity: 0.6;
}
.spacer-button:hover {
transition: all 0.2s;
border-radius: 0;
border: none;
box-shadow: inset 0px 0px 4px 0px var(--silver);
}
.spacer-button div {
vertical-align: middle;
width: 100px;
}
.spacer-button p {
line-height: 0px;
}
button span {
font-size: 15px;
}
#switches {
display: inline-flex;
justify-content: flex-start;
align-items: center;
transition: background-color 0.2s ease;
display: inline-flex;
align-items: center;
position: relative;
}
.top input:hover,
.top label:hover {
cursor: pointer;
}
#switches label {
margin-right: 51px;
display: inline-flex;
align-items: center;
}
#switches label:after {
content: "";
width: 18px;
height: 18px;
border-radius: 20px;
background-color: var(--black6);
left: 53px;
transition: all 0.3s;
position: absolute;
}
#switches input:checked+label:after {
position: absolute;
transform: translateX(-20px);
transition: all 0.3s;
background-color: var(--ui-color);
}
#switches input:checked+label:before {
background-color: var(--silver);
transition: all 0.2s ease;
}
#switches label:before {
content: "";
width: 40px;
height: 20px;
background-color: var(--silver);
border: 1px solid var(--black3);
display: inline-block;
vertical-align: middle;
border-radius: 40px;
position: relative;
margin-left: 8px;
margin-right: 8px;
cursor: pointer;
position: relative;
display: inline-flex;
justify-content: flex-start;
align-items: center;
transition: all 0.2s ease;
display: inline-flex;
align-items: center;
position: absolute;
left: 23px;
}
#force {
cursor: pointer;
bottom: -10px;
text-align: center;
font-size: 11px;
text-decoration: underline;
position: absolute;
right: -1px;
display: none;
}
#force:hover {
color: var(--ui-color);
}
#switches:hover input:not(:checked)~#force {
display: block;
}
#position-buttons label {
position: relative;
height: 30px;
background-color: transparent;
color: var(--white);
border: none;
margin-right: 0;
transition: all 0.2s;
cursor: pointer;
transition: all 0.2s ease;
background-repeat: no-repeat;
display : block;
}
#position-buttons svg{
position: absolute;
}
#position-buttons svg.radio-svg-selected{
display: none;
}
#position-buttons input:checked+label svg.radio-svg-default, #position-buttons input+label:hover svg.radio-svg-default{
/*display:none;*/
}
#position-buttons input:checked+label svg.radio-svg-selected, #position-buttons input+label:hover svg.radio-svg-selected{
display:block;
}
.rtop svg {
bottom: 0px;
left: 0px;
}
.rleft svg {
right: 0px;
top: 0px;
}
.rright svg {
left: 0px;
top: 0px;
}
.rbottom svg {
left: 0px;
top: 0px;
}
.rreplace svg {
left: 4px;
top: 4px;
}
#switches input {
position: absolute;
width: 100%;
opacity: 0;
height: 100%;
}
#position-buttons input {
display: none;
}
#position-buttons input+label:hover {
}
#position-buttons input:checked+label {
}
.top {
display: flex;
justify-content: space-between;
margin: 10px 31px 9px 40px;
align-items: center
}
#config {
cursor: pointer;
text-align: center;
border-bottom: 2px solid transparent;
}
#config:hover,
#configDiv .reset:hover {
border-bottom: 2px solid var(--ui-color);
}
#config svg,
.reset svg,
.cancel svg {
margin-right: 5px;
/*fill: var(--ui-color);*/
}
#config svg{
top:0px;
}
#configDiv .cancel {
margin-left: 0;
padding-left: 0;
}
#configDiv {
display: none;
flex-direction: column;
margin: auto auto;
}
#configDiv button {
padding: 0;
line-height: 0px;
height: 24px;
margin-top: 6px;
}
#configDiv input {
padding: 8px 2px;
margin: 2px 8px;
font-weight: 500;
font-size: 12px;
max-width: 112px;
}
#configDiv .ok , #configDiv .cancel {
padding: 10px 10px;
transition: all 0.2s;
display: inline-block;
margin: 0px;
margin-top:12px;
margin-bottom: 24px;
}
#configDiv .ok {
background-color: var(--ui-color);
color:var(--white);
border: 1px solid var(--spacers-sg);
font-size: 14px;
}
#configDiv .cancel {
background-color: transparent;
color:var(--black);
border: 1px solid var(--black);
font-size: 12px;
font-weight: 500;
margin-right: 2px;
}
#configDiv .reset {
border: 0;
border: none;
border-bottom: 2px solid transparent;
border-radius: 0;
margin: 0;
margin-bottom: -10px;
padding: 0;
font-size: 11px;
height: auto;
line-height: 20px;
}
</style>
<div id="frame">
<div id="main">
<div class="header"> Visibility </div>
<div id="switches">
<svg width="26" height="26" viewBox="0 0 34 36" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M30.3038 12.2998V9.04448H27.0853V6.79595H24.0353V3.54061H26.4113V0H23.0916V3.54061H20.7156V6.79595H12.7788V3.54061H10.4028V0H7.10005V3.54061H9.47604V6.79595H6.37546V9.06126H3.59505V12.3166H1V23.9285H4.4039V17.2332H6.37546V23.2405H8.16166V25.791H14.1606V22.1498H10.049V19.1965H23.4118V22.1498H19.4687V25.791H25.4676V23.2405H27.0853V17.2332H29.5961V23.9285H33V12.2998H30.3038ZM12.2059 14.3638H8.97051V8.96058H12.189V14.3638H12.2059ZM23.6646 14.3638H20.446V8.96058H23.6646V14.3638Z"
fill="var(--ui-color)" />
<path
d="M0.361328 31.6709L1.76758 31.5342C1.85221 32.0062 2.02311 32.3529 2.28027 32.5742C2.54069 32.7956 2.89062 32.9062 3.33008 32.9062C3.79557 32.9062 4.14551 32.8086 4.37988 32.6133C4.61751 32.4147 4.73633 32.1836 4.73633 31.9199C4.73633 31.7507 4.68587 31.6074 4.58496 31.4902C4.4873 31.3698 4.31478 31.2656 4.06738 31.1777C3.89811 31.1191 3.51237 31.015 2.91016 30.8652C2.13542 30.6732 1.5918 30.4372 1.2793 30.1572C0.839844 29.7633 0.620117 29.2832 0.620117 28.7168C0.620117 28.3522 0.722656 28.012 0.927734 27.6963C1.13607 27.3773 1.43392 27.1348 1.82129 26.9688C2.21191 26.8027 2.68229 26.7197 3.23242 26.7197C4.13086 26.7197 4.80632 26.9167 5.25879 27.3105C5.71452 27.7044 5.95378 28.2301 5.97656 28.8877L4.53125 28.9512C4.4694 28.5833 4.33594 28.3197 4.13086 28.1602C3.92904 27.9974 3.62467 27.916 3.21777 27.916C2.79785 27.916 2.46908 28.0023 2.23145 28.1748C2.07845 28.2855 2.00195 28.4336 2.00195 28.6191C2.00195 28.7884 2.07357 28.9333 2.2168 29.0537C2.39909 29.2067 2.8418 29.3662 3.54492 29.5322C4.24805 29.6982 4.76725 29.8708 5.10254 30.0498C5.44108 30.2256 5.70475 30.4681 5.89355 30.7773C6.08561 31.0833 6.18164 31.4626 6.18164 31.915C6.18164 32.3252 6.06771 32.7093 5.83984 33.0674C5.61198 33.4255 5.28971 33.6924 4.87305 33.8682C4.45638 34.0407 3.93717 34.127 3.31543 34.127C2.41048 34.127 1.71549 33.9186 1.23047 33.502C0.745443 33.082 0.455729 32.4717 0.361328 31.6709ZM8.30234 34V26.8418H9.74766V29.6592H12.5797V26.8418H14.025V34H12.5797V30.8701H9.74766V34H8.30234ZM16.1311 30.4648C16.1311 29.7357 16.2401 29.1237 16.4582 28.6289C16.621 28.2643 16.8423 27.9372 17.1223 27.6475C17.4055 27.3577 17.7147 27.1429 18.05 27.0029C18.496 26.8141 19.0103 26.7197 19.593 26.7197C20.6477 26.7197 21.4908 27.0469 22.1223 27.7012C22.757 28.3555 23.0744 29.2653 23.0744 30.4307C23.0744 31.5863 22.7603 32.4912 22.132 33.1455C21.5038 33.7965 20.6639 34.1221 19.6125 34.1221C18.548 34.1221 17.7017 33.7982 17.0734 33.1504C16.4452 32.4993 16.1311 31.6042 16.1311 30.4648ZM17.6203 30.416C17.6203 31.2266 17.8075 31.8418 18.1818 32.2617C18.5562 32.6784 19.0314 32.8867 19.6076 32.8867C20.1838 32.8867 20.6558 32.68 21.0236 32.2666C21.3947 31.8499 21.5803 31.2266 21.5803 30.3965C21.5803 29.5762 21.3996 28.9642 21.0383 28.5605C20.6802 28.1569 20.2033 27.9551 19.6076 27.9551C19.0119 27.9551 18.5318 28.1602 18.1672 28.5703C17.8026 28.9772 17.6203 29.5924 17.6203 30.416ZM26.1229 34L24.4139 26.8418H25.8934L26.9725 31.7588L28.2811 26.8418H29.9998L31.2547 31.8418L32.3533 26.8418H33.8084L32.0701 34H30.5369L29.1111 28.6484L27.6902 34H26.1229Z"
fill="var(--ui-color)" />
</svg>
<input type="checkbox" id="showToggle" checked onchange="switchShow()" title="make spacers visible or not"/>
<label for="showToggle"></label>
<svg width="26" height="36" viewBox="0 0 34 34" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0)">
<path
d="M0.732422 34V26.8418H2.17773V29.6592H5.00977V26.8418H6.45508V34H5.00977V30.8701H2.17773V34H0.732422ZM11.1102 34V26.8418H12.5555V34H11.1102ZM17.1324 26.8418H19.774C20.3697 26.8418 20.8238 26.8874 21.1363 26.9785C21.5562 27.1022 21.916 27.3219 22.2154 27.6377C22.5149 27.9535 22.7428 28.3408 22.899 28.7998C23.0553 29.2555 23.1334 29.8187 23.1334 30.4893C23.1334 31.0785 23.0602 31.5863 22.9137 32.0127C22.7346 32.5335 22.4791 32.9551 22.1471 33.2773C21.8964 33.5215 21.5579 33.7119 21.1314 33.8486C20.8124 33.9495 20.386 34 19.8521 34H17.1324V26.8418ZM18.5777 28.0527V32.7939H19.6568C20.0605 32.7939 20.3518 32.7712 20.5309 32.7256C20.7652 32.667 20.9589 32.5677 21.1119 32.4277C21.2682 32.2878 21.3951 32.0583 21.4928 31.7393C21.5904 31.417 21.6393 30.9792 21.6393 30.4258C21.6393 29.8724 21.5904 29.4476 21.4928 29.1514C21.3951 28.8551 21.2584 28.624 21.0826 28.458C20.9068 28.292 20.6839 28.1797 20.4137 28.1211C20.2118 28.0755 19.8163 28.0527 19.2271 28.0527H18.5777ZM27.5639 34V26.8418H32.8715V28.0527H29.0092V29.6396H32.6029V30.8457H29.0092V32.7939H33.0082V34H27.5639Z"
fill="var(--black3-opaque)" />
<path fill-rule="evenodd" clip-rule="evenodd"
d="M26.4113 2V0H23.0916V3.54061H20.7156V6.79595H12.7788V3.54061H10.4028V0H7.10005V3.54061H9.47604V6.79595H6.37546V9.06126H3.59505V12.3166H1V23.9285H4.4039V17.2332H6.37546V22H7V21H8V20H9V19H10V18H11V17H12V16H13V15H14V14H15V13H16V12H17V11H18V10H19V9H20V8H21V7H22V6H23V5H24V4H24.0353V3.54061H25V3H26V2H26.4113ZM27 6.79595V7H26V8H25V9H24V10H23.6646V14.3638H20.446V13H20V14H19V15H18V16H17V17H16V18H15V19H14V19.1965H23.4118V22.1498H19.4687V25.791H25.4676V23.2405H27.0853V17.2332H29.5961V23.9285H33V12.2998H30.3038V9.04448H27.0853V6.79595H27ZM11 22.1498V23H10V24H9V25H8.16166V25.791H14.1606V22.1498H11ZM8.97051 14.3638H12.189V8.96058H8.97051V14.3638Z"
fill="var(--black3-opaque)" />
<path d="M5 25H6V26H5V25Z" fill="var(--ui-color)" />
<path d="M6 24H7V25H6V24Z" fill="var(--ui-color)" />
<path d="M7 23H8V24H7V23Z" fill="var(--ui-color)" />
<path d="M8 22H9V23H8V22Z" fill="var(--ui-color)" />
<path d="M9 21H10V22H9V21Z" fill="var(--ui-color)" />
<path d="M10 20H11V21H10V20Z" fill="var(--ui-color)" />
<path d="M11 19H12V20H11V19Z" fill="var(--ui-color)" />
<path d="M12 18H13V19H12V18Z" fill="var(--ui-color)" />
<path d="M13 17H14V18H13V17Z" fill="var(--ui-color)" />
<path d="M14 16H15V17H14V16Z" fill="var(--ui-color)" />
<path d="M15 15H16V16H15V15Z" fill="var(--ui-color)" />
<path d="M16 14H17V15H16V14Z" fill="var(--ui-color)" />
<path d="M17 13H18V14H17V13Z" fill="var(--ui-color)" />
<path d="M18 12H19V13H18V12Z" fill="var(--ui-color)" />
<path d="M19 11H20V12H19V11Z" fill="var(--ui-color)" />
<path d="M20 10H21V11H20V10Z" fill="var(--ui-color)" />
<path d="M21 9H22V10H21V9Z" fill="var(--ui-color)" />
<path d="M22 8H23V9H22V8Z" fill="var(--ui-color)" />
<path d="M23 7H24V8H23V7Z" fill="var(--ui-color)" />
<path d="M24 6H25V7H24V6Z" fill="var(--ui-color)" />
<path d="M25 5H26V6H25V5Z" fill="var(--ui-color)" />
<path d="M26 4H27V5H26V4Z" fill="var(--ui-color)" />
<path d="M27 3H28V4H27V3Z" fill="var(--ui-color)" />
<path d="M28 2H29V3H28V2Z" fill="var(--ui-color)" />
</g>
<defs>
<clipPath id="clip0">
<rect width="34" height="34" fill="var(--white)" />
</clipPath>
</defs>
</svg>
<div id="force" onclick="post('force')" title="clean can be necessary when old spacers are pasted in a project">clean</div>
</div>
<hr>
<div class="header"> Insert Direction </div>
<div id="position-buttons">
<div class="rleft" ><input type="radio" id="idleft" class="position" onclick="place('LEFT')"
name="position"><label for="idleft" title="position spacers on the left of selected element">
<svg class='radio-svg-default' width="16" height="32" viewBox="0 0 16 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.97053 16.3484C1.78201 16.1544 1.78201 15.8456 1.97053 15.6516L15.0584 2.18098C15.3712 1.85899 15.917 2.08046 15.917 2.5294L15.917 29.4706C15.917 29.9195 15.3712 30.141 15.0584 29.819L9.03456 23.619L1.97053 16.3484Z"
stroke="var(--black3-opaque)"/>
</svg>
<svg class='radio-svg-selected' width="16" height="32" viewBox="0 0 16 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.2975 16.6462C4.90138 16.2547 4.90138 15.6151 5.2975 15.2236L12.5891 8.01776C13.2208 7.39354 14.292 7.84098 14.292 8.72904L14.292 23.1407C14.292 24.0288 13.2208 24.4762 12.5891 23.852L9.4349 20.7349L5.2975 16.6462Z"
fill="var(--ui-color)"/>
</svg>
</label>
</div>
<div class="rbottom"><input type="radio" id="idbottom" class="position" onclick="place('BOTTOM')"
name="position" checked="checked"><label for="idbottom" title="position spacers at bottom of selected element">
<!--svg class='radio-svg-default' width="32" height="16" viewBox="0 0 32 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 16 L16 0 L32 16 H0 16" stroke="var(--black3-opaque)"/>
</svg-->
<svg class='radio-svg-default' width="32" height="16" viewBox="0 0 32 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.2833 14.9643C16.0893 15.1529 15.7805 15.1529 15.5865 14.9643L2.11585 1.87646C1.79387 1.56363 2.01534 1.01785 2.46428 1.01785L29.4055 1.01786C29.8544 1.01786 30.0759 1.56363 29.7539 1.87647L23.5539 7.90032L16.2833 14.9643Z"
stroke="var(--black3-opaque)"/>
</svg>
<svg class='radio-svg-selected' width="32" height="16" viewBox="0 0 32 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.581 11.6374C16.1896 12.0335 15.5499 12.0335 15.1585 11.6374L7.9526 4.34577C7.32838 3.71412 7.77583 2.64286 8.66388 2.64286L23.0756 2.64286C23.9636 2.64286 24.4111 3.71412 23.7869 4.34577L20.6697 7.5L16.581 11.6374Z"
fill="var(--ui-color)"/>
</svg>
</label>
</div>
<div class="rright"><input type="radio" id="idright" class="position" onclick="place('RIGHT')"
name="position"><label for="idright" title="position spacers on the right of selected element">
<svg class='radio-svg-default' width="16" height="32" viewBox="0 0 16 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14.9643 15.5864C15.1529 15.7805 15.1529 16.0893 14.9643 16.2833L1.87646 29.7539C1.56363 30.0759 1.01786 29.8544 1.01786 29.4055L1.01786 2.46428C1.01786 2.01535 1.56363 1.79387 1.87647 2.11586L7.90032 8.31586L14.9643 15.5864Z"
stroke="var(--black3-opaque)"/>
</svg>
<svg class='radio-svg-selected' width="16" height="32" viewBox="0 0 16 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.6374 15.2887C12.0335 15.6802 12.0335 16.3198 11.6374 16.7113L4.34574 23.9171C3.71409 24.5413 2.64283 24.0939 2.64283 23.2058L2.64283 8.79415C2.64283 7.90609 3.71409 7.45865 4.34574 8.08287L7.49997 11.2L11.6374 15.2887Z"
fill="var(--ui-color)"/>
</svg>
</label>
</div>
<div class="rtop"><input type="radio" class="idposition" id="idtop" onclick="place('TOP')"
name="position">
<label for="idtop" title="position spacers on top of selected element">
<!--svg class='radio-svg-default' width="32" height="16" viewBox="0 0 32 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 16 L16 0 L32 16 H0 16" stroke="var(--black3-opaque)"/>
</svg>
<svg class='radio-svg-selected' width="32" height="16" viewBox="0 0 32 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 14 L14 2 L28 14 H0 14" fill="var(--black3-opaque)"/>
</svg-->
<svg class='radio-svg-default' width="32" height="16" viewBox="0 0 32 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M15.5864 1.03566C15.7805 0.847139 16.0893 0.847139 16.2833 1.03566L29.7539 14.1235C30.0759 14.4364 29.8544 14.9821 29.4055 14.9821H2.46428C2.01535 14.9821 1.79387 14.4364 2.11586 14.1235L8.31586 8.09968L15.5864 1.03566Z"
stroke="var(--black3-opaque)"/>
</svg>
<svg class='radio-svg-selected' width="32" height="16" viewBox="0 0 32 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M15.2887 4.3626C15.6802 3.96648 16.3198 3.96648 16.7113 4.3626L23.9171 11.6542C24.5414 12.2859 24.0939 13.3571 23.2059 13.3571H8.79418C7.90612 13.3571 7.45868 12.2859 8.0829 11.6542L11.2 8.5L15.2887 4.3626Z"
fill="var(--ui-color)"/>
</svg>
</label>
</div>
<div class="rreplace"><input type="radio" id="idreplace" class="position" onclick="place('REPLACE')"
name="position"><label for="idreplace" title="replace selected spacers by another spacer">
<svg class='radio-svg-default' width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0.5" y="0.5" width="23" height="23" stroke="var(--black3-opaque)"/>
</svg>
<svg class='radio-svg-selected' width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="3.5" y="3.5" width="17" height="17" rx="1" fill="var(--ui-color)"/>
</svg>
</label>
</div>
</div>
<hr>
<div class="header"> Spacers</div>
<div id="spacers">
</div>
<hr>
<div id="config" class="header" onclick="showConfig()">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="14"
height="14">
<path
d="M502.6 389.5L378.2 265c-15.6-15.6-36.1-23.4-56.6-23.4-15.4 0-30.8 4.4-44.1 13.3L192 169.4V96L64 0 0 64l96 128h73.4l85.5 85.5c-20.6 31.1-17.2 73.3 10.2 100.7l124.5 124.5c6.2 6.2 14.4 9.4 22.6 9.4 8.2 0 16.4-3.1 22.6-9.4l67.9-67.9c12.4-12.6 12.4-32.8-.1-45.3zM160 158.1v1.9h-48L42.3 67 67 42.3l93 69.7v46.1zM412.1 480L287.7 355.5c-9.1-9.1-14.1-21.1-14.1-33.9 0-12.8 5-24.9 14.1-33.9 9.1-9.1 21.1-14.1 33.9-14.1 12.8 0 24.9 5 33.9 14.1L480 412.1 412.1 480zM64 432c0 8.8 7.2 16 16 16s16-7.2 16-16-7.2-16-16-16-16 7.2-16 16zM276.8 66.9C299.5 44.2 329.4 32 360.6 32c6.9 0 13.8.6 20.7 1.8L312 103.2l13.8 83 83.1 13.8 69.3-69.3c6.7 38.2-5.3 76.8-33.1 104.5-8.9 8.9-19.1 16-30 21.5l23.6 23.6c10.4-6.2 20.2-13.6 29-22.5 37.8-37.8 52.7-91.4 39.7-143.3-2.3-9.5-9.7-17-19.1-19.6-9.5-2.6-19.7 0-26.7 7l-63.9 63.9-44.2-7.4-7.4-44.2L410 50.3c6.9-6.9 9.6-17.1 7-26.5-2.6-9.5-10.2-16.8-19.7-19.2C345.6-8.3 292 6.5 254.1 44.3c-12.9 12.9-22.9 27.9-30.1 44v67.8l22.1 22.1c-9.6-40.4 1.6-82.2 30.7-111.3zM107 467.1c-16.6 16.6-45.6 16.6-62.2 0-17.1-17.1-17.1-45.1 0-62.2l146.1-146.1-22.6-22.6L22.2 382.3c-29.6 29.6-29.6 77.8 0 107.5C36.5 504.1 55.6 512 75.9 512c20.3 0 39.4-7.9 53.7-22.3L231.4 388c-6.7-9.2-11.8-19.3-15.5-29.8L107 467.1z" />
</svg>
Settings
</div>
</div>
<div id="configDiv" >
<div class="headerTop" >
Settings
</div>
<hr>
<div class="header">
Spacers
</div>
<input id="values" ></input>
<button onclick="valueInput.value = Base8.toString();" class="reset">set to default</button>
<hr>
<div class="header">
Background color
</div>
<input id="bg-color"></input>
<button onclick="bgInput.value = bgColorDefault;" class="reset">set to default</button>
<hr>
<div class="header">
Foreground color
</div>
<input id="fg-color" ></input>
<button onclick="fgInput.value = fgColorDefault;" class="reset">set to default</button>
<hr>
<div>
<button onclick="showMain();" class="cancel"> Cancel</button>
<button onclick="setNewConfig();" class="ok">OK</button>
</div>
</div>
</div>
<script>
//CONSTANT
const Base8 = [8, 16, 24, 32, 40, 48];
const bgColorDefault = '#FAE3FF';
const fgColorDefault = '#CC00FF';
const hexCheckRex = /^#([0-9A-F]{3}){1,2}$/i;
const spacersListCheckRex = /^([0-9]+,)*[0-9]+$/i;
//state
var hiddenState;
var spacerValues;
var bgColor;
var fgColor;
//HTML elements
var showToggle = document.getElementById("showToggle");
var forceLink = document.getElementById("force");
var configDiv = document.getElementById("configDiv");
var spacersDiv = document.getElementById("spacers");
var mainDiv = document.getElementById("main");
var frameDiv = document.getElementById("frame");
var valueInput = document.getElementById("values");
var fgInput = document.getElementById("fg-color");
var bgInput = document.getElementById("bg-color");
/**
* receive plugin properties
* change state if necessary
*/
onmessage = (event) => {
//console.log("refresh UI if necessary");
if (event.data.pluginMessage.type === "set-properties-from-project") {
var spacers = event.data.pluginMessage.spacers;
if (String(spacers) !== String(spacerValues)) {
console.log("diff in spacers list : doc property=" + spacers + " plugin=" + spacerValues);
setSpacers(spacers);
}
var bg = event.data.pluginMessage.bgColor;
if (bg !== bgColor) {
console.log("diff in bg color : doc property=" + bg + " plugin=" + bgColor);
setBackgroundColor(bg);
}
var fg = event.data.pluginMessage.fgColor;
if (fg !== fgColor) {
console.log("diff in fg color : doc property=" + fg + " plugin=" + fgColor);
setForegroundColor(fg);
}
var hidden = event.data.pluginMessage.hide;
if (hidden != hiddenState) {
console.log("hidden state different : doc property=" + hidden + " plugin=" + hiddenState);
if (hidden){
showToggle.checked = false;
hiddenState = true;
} else {
showToggle.checked = true;
hiddenState = false;
}
}
}
}
//change the spacers buttons
function setSpacers(spacers) {
if (!Array.isArray(spacers)) spacers = Base8;
//reset div
while (spacersDiv.firstChild) spacersDiv.removeChild(spacersDiv.firstChild);
for (let coef of spacers) {
if (!isNaN(coef) && coef > 0)
spacersDiv.appendChild(createSpacerButton(coef));
}
//store the spacers value
spacerValues = spacers;
setPropertyInProject('spacers',spacers);
}
function setForegroundColor(hexColor){
if (!hexColor || !(hexCheckRex.test(hexColor))) fgColor = fgColorDefault;
else fgColor = hexColor;
frameDiv.style.setProperty('--spacers-fg', fgColor);
updateUIColor();
setPropertyInProject('fg-color',fgColor);
}
function updateUIColor(){
if (luminance(bgColor)>luminance(fgColor))
frameDiv.style.setProperty('--ui-color', fgColor);
else frameDiv.style.setProperty('--ui-color', bgColor);
}
function setBackgroundColor(hexColor){
if (!hexColor || !(hexCheckRex.test(hexColor))) bgColor = bgColorDefault;
else bgColor = hexColor;
frameDiv.style.setProperty('--spacers-bg', bgColor);
updateUIColor();
setPropertyInProject('bg-color',bgColor);
}
function switchShow() {
if (showToggle.checked) show();
else hide();
}
//show spacers
function show() {
showToggle.checked = true;
hiddenState = false;
// forceLink.style.display = "none";
post('show-spacer-infos');
}
//hide spacers
function hide() {
showToggle.checked = false;
hiddenState = true;
//forceLink.style.display = "block";
post('hide-spacer-infos');
}
//util
function arrayFrom(string) {
return string.split(',').map(Number);
}
// change ui to show configuration mode
function showConfig() {
mainDiv.style.display = "none";
valueInput.value = spacerValues.toString();
bgInput.value = bgColor;
fgInput.value = fgColor;
configDiv.style.display = "block";
}
function showMain(){
configDiv.style.display = "none";
mainDiv.style.display = "block";
}
//set the new config and go back to main display
function setNewConfig(){
//check values before setting new config
var bg = bgInput.value;
if (!(bg.startsWith('#'))) bg = '#'+bg;
if (!hexCheckRex.test(bg)){
notify("Please enter a valid background color in hexadecimal");
return;
}
var fg = fgInput.value;
if (!(fg.startsWith('#'))) fg = '#'+fg;
if (!hexCheckRex.test(fg)){
notify("Please enter a valid foreground color in hexadecimal");
return;
}
if (!spacersListCheckRex.test(valueInput.value)){
notify("Please enter a valid list of spacers (numbers separated by , )");
return;
}
//if tests pass then set
setSpacers(arrayFrom(valueInput.value));
setBackgroundColor(bg);
setForegroundColor(fg);
showMain();
}
// create a spacer button for a specific size
function createSpacerButton(size) {
var button = document.createElement("button");
button.id = "add" + size;
button.onclick = function () {
add(size)
};
button.className = "spacer-button";
button.title = "add a "+size+"px spacer beside the selected element";
var p = document.createElement("p");
p.innerHTML = "" + size;
var span = document.createElement("span");
span.innerHTML = "px";
p.appendChild(span);
button.appendChild(p);
return button;
}
//util
function post(msg) {
parent.postMessage({
pluginMessage: {
type: msg
}
}, '*');
//release focus
parent.focus();
}
// call code for adding a specific spacer in figma element
function add(size) {
parent.postMessage({
pluginMessage: {
type: 'add-spacer',
size: size
}
}, '*');
//release focus
parent.focus();
}
// call code for defining position
function notify(msg) {
parent.postMessage({
pluginMessage: {
type: 'notify',
msg: msg
}
}, '*');
}
// call code for defining position
function place(position) {
parent.postMessage({
pluginMessage: {
type: 'place-spacer',
position: position
}
}, '*');
//release focus
parent.focus();
}
//generic property setter for project properties
function setPropertyInProject(property, value) {
parent.postMessage({
pluginMessage: {
type: property,
value: value
}
}, '*');
}
function luminance(hex) {
if (!hex) return 0;
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
var fullRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
const result = [
parseInt(fullRegex[1], 16)/255,
parseInt(fullRegex[2], 16)/255,
parseInt(fullRegex[3], 16)/255
]
var a = result.map(function (v) {
v /= 255;
return v <= 0.03928
? v / 12.92
: Math.pow( (v + 0.055) / 1.055, 2.4 );
});
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
}
//ask for plugin properties at startup
post("get-properties-in-project");
//check every 30s if properties have changed
window.setInterval(post, 30000, "get-properties-in-project");
</script>