-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
1290 lines (1107 loc) · 30.2 KB
/
main.js
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
const {Artboard, BooleanGroup, Color, Ellipse, GraphicNode, Group, Line, LinkedGraphic, Path, Rectangle, RepeatGrid, RootNode, SceneNode, SymbolInstance, Text, selection} = require("scenegraph");
const platform = require("os").platform();
const {editDocument} = require("application");
const application = require("application");
const localFileSystem = require("uxp").storage.localFileSystem;
const commands = require("commands");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - REFERENCES
// - - - - - - - - - - - - - - - - - - - - UI
var dataFolder;
var settingsFile;
var settingsO;
var pluginTitle = "Pattern Maker";
var labelFontSizeMini = 9;
var labelFontSize = 10;
var textFontSize = 11;
var activeColor = "#2680EB";
var inactiveColor = "#A0A0A0";
var activeBkgColor = "#E2E2E2";
var lightBkgColor = "#FBFBFB";
var labelColor = "#666666";
var labelQuietColor = "#999999";
var separatorColor = "#E4E4E4";
var errorColor = "#FF0000";
var artboard;
var artboardWidth;
var artboardHeight;
var selectedObject;
var selectedObjectBounds;
var selectedObjectWidth;
var selectedObjectHeight;
var multipleSelection = false;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CONTAINER
var container = document.createElement("div");
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PATTERN MODE MODULE
var patternModeModule = createModule("top", "PATTERN MODE");
patternModeModule.style.marginTop = 0;
container.appendChild(patternModeModule);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PATTERN MODE MENU
var patternModeMenu = document.createElement("div");
patternModeMenu.style.display = "flex";
patternModeMenu.style.flexDirection = "row";
// patternModeMenu.style.margin = "0px auto 20px auto";
// patternModeMenu.style.width = 132; // 40;
patternModeMenu.style.flexGrow = 1;
patternModeMenu.style.height = 24; // 30; // 40;
patternModeMenu.style.background = lightBkgColor;
patternModeMenu.style.border = "1px solid";
patternModeMenu.style.borderColor = separatorColor;
patternModeMenu.style.borderRadius = 4;
patternModeModule.appendChild(patternModeMenu);
// - - - - - - - - - - - - - - - - - - - - SEAMLESS BUTTON
var seamlessB = document.createElement("div");
seamlessB.style.display = "flex";
seamlessB.style.alignItems = "center";
seamlessB.style.justifyContent = "center";
// seamlessB.style.width = 66; // 143;
seamlessB.style.flexGrow = 1;
seamlessB.style.background = activeBkgColor;
seamlessB.style.borderRadius = "4px 0px 0px 4px";
seamlessB.setAttribute("title", "Seamless");
patternModeMenu.appendChild(seamlessB);
var seamlessIcon = document.createElement("img");
seamlessIcon.src = "img/seamless.png";
seamlessB.appendChild(seamlessIcon);
// - - - - - - - - - - - - - - - - - - - - GRID BUTTON
var gridB = document.createElement("div");
gridB.style.display = "flex";
gridB.style.alignItems = "center";
gridB.style.justifyContent = "center";
// gridB.style.width = 66; // 143;
gridB.style.flexGrow = 1;
gridB.style.borderRadius = "0px 4px 4px 0px";
gridB.setAttribute("title", "Grid");
patternModeMenu.appendChild(gridB);
var gridIcon = document.createElement("img");
gridIcon.src = "img/grid.png";
gridB.appendChild(gridIcon);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OPTIONS MODULE
var optionsModule = createModule("internal", "OPTIONS");
container.appendChild(optionsModule);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SEAMLESS SETTINGS
var seamlessSettings = document.createElement("div");
seamlessSettings.style.display = "flex";
seamlessSettings.style.flexWrap = "wrap";
optionsModule.appendChild(seamlessSettings);
var seamlessColumnsGroup = document.createElement("div");
seamlessColumnsGroup.style.marginRight = 16;
seamlessColumnsGroup.style.display = "flex";
seamlessColumnsGroup.style.flexDirection = "row";
seamlessColumnsGroup.style.alignItems = "center";
seamlessSettings.appendChild(seamlessColumnsGroup);
var seamlessColumnsL = createLabel("Columns");
seamlessColumnsL.style.color = labelQuietColor;
seamlessColumnsGroup.appendChild(seamlessColumnsL);
var seamlessColumnsTF = createTextInput("", 36, true);
seamlessColumnsTF.type = "number";
seamlessColumnsTF.min = 3;
seamlessColumnsTF.oninput = (e) => setSeamlessColumns();
seamlessColumnsGroup.appendChild(seamlessColumnsTF);
var seamlessRowsGroup = document.createElement("div");
seamlessRowsGroup.style.display = "flex";
seamlessRowsGroup.style.flexDirection = "row";
seamlessRowsGroup.style.alignItems = "center";
seamlessSettings.appendChild(seamlessRowsGroup);
var seamlessRowsL = createLabel("Rows");
seamlessRowsL.style.color = labelQuietColor;
seamlessRowsGroup.appendChild(seamlessRowsL);
var seamlessRowsTF = createTextInput("", 36, true);
seamlessRowsTF.type = "number";
seamlessRowsTF.min = 3;
seamlessRowsTF.oninput = (e) => setSeamlessRows();
seamlessRowsGroup.appendChild(seamlessRowsTF);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GRID SETTINGS
var gridSettings = document.createElement("div");
gridSettings.style.display = "flex";
gridSettings.style.flexWrap = "wrap";
gridSettings.style.display = "none";
optionsModule.appendChild(gridSettings);
var gridColumnsGroup = document.createElement("div");
gridColumnsGroup.style.marginRight = 16;
gridColumnsGroup.style.display = "flex";
gridColumnsGroup.style.flexDirection = "row";
gridColumnsGroup.style.alignItems = "center";
gridSettings.appendChild(gridColumnsGroup);
var gridColumnsL = createLabel("Columns");
gridColumnsL.style.color = labelQuietColor;
gridColumnsGroup.appendChild(gridColumnsL);
var gridColumnsTF = createTextInput("", 36, true);
gridColumnsTF.type = "number";
gridColumnsTF.min = 1;
gridColumnsTF.oninput = (e) => setGridColumns();
gridColumnsGroup.appendChild(gridColumnsTF);
var gridRowsGroup = document.createElement("div");
gridRowsGroup.style.marginRight = 16;
gridRowsGroup.style.display = "flex";
gridRowsGroup.style.flexDirection = "row";
gridRowsGroup.style.alignItems = "center";
gridSettings.appendChild(gridRowsGroup);
var gridRowsL = createLabel("Rows");
gridRowsL.style.color = labelQuietColor;
gridRowsGroup.appendChild(gridRowsL);
var gridRowsTF = createTextInput("", 36, true);
gridRowsTF.type = "number";
gridRowsTF.min = 1;
gridRowsTF.oninput = (e) => setGridRows();
gridRowsGroup.appendChild(gridRowsTF);
var gridPaddingGroup = document.createElement("div");
gridPaddingGroup.style.display = "flex";
gridPaddingGroup.style.flexDirection = "row";
gridPaddingGroup.style.alignItems = "center";
gridSettings.appendChild(gridPaddingGroup);
var gridPaddingL = createLabel("Padding");
gridPaddingL.style.color = labelQuietColor;
gridPaddingGroup.appendChild(gridPaddingL);
var gridPaddingTF = createTextInput("", 36, true);
gridPaddingTF.type = "number";
gridPaddingTF.min = 0;
gridPaddingTF.oninput = (e) => setGridPadding();
gridPaddingGroup.appendChild(gridPaddingTF);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BOTTOM SEPARATOR
var bottomSeparator = createSeparator();
bottomSeparator.style.marginTop = 14;
container.appendChild(bottomSeparator);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FOOTER
var footer = document.createElement("footer");
// footer.style.justifyContent = "center";
// footer.style.marginTop = 30;
container.appendChild(footer);
var okB = createButton("Make Pattern", "cta");
okB.id = "makePattern";
okB.onclick = (e) => validatePanel(e);
footer.appendChild(okB);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WARNING
var warningBox = document.createElement("div");
warningBox.style.marginTop = 10;
warningBox.style.display = "flex";
warningBox.style.justifyContent = "center";
container.appendChild(warningBox);
var warningMessage = document.createElement("div");
warningMessage.style.color = errorColor;
warningMessage.style.visibility = "hidden";
warningMessage.style.fontSize = labelFontSize;
warningMessage.style.lineHeight = "15px";
warningMessage.textContent = "Warning Message";
warningBox.appendChild(warningMessage);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MAIN FUNCTIONS
async function show(_e)
{
console.log("show()");
// console.log(_e.node.nodeName);
try
{
await init();
}
catch(_error)
{
console.log(_error);
}
_e.node.appendChild(container);
}
async function hide(_e)
{
console.log("hide()");
// console.log(_e.node.nodeName);
try
{
await saveSettings();
}
catch(_error)
{
console.log(_error);
}
_e.node.firstChild.remove();
}
function update()
{
// console.log("update()");
}
async function init()
{
// set default settings
try
{
await setDefaultSettings();
}
catch(_error)
{
console.log(_error);
}
// get settings
try
{
await getSettings();
}
catch(_error)
{
console.log(_error);
}
setPatternMode(settingsO["patternMode"]);
seamlessColumnsTF.value = settingsO["seamlessColumns"];
seamlessRowsTF.value = settingsO["seamlessRows"];
gridColumnsTF.value = settingsO["gridColumns"];
gridRowsTF.value = settingsO["gridRows"];
gridPaddingTF.value = settingsO["gridPadding"];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SELECTION CHECK
async function checkSelection()
{
console.log("checkSelection()");
let alertDialogMessage = "Select an object inside an Artboard, excluding objects inside Repeat Grids, Symbols, groups or Pasteboard.";
// if there is no selection OR selection is an artboard
if(selection.items.length == 0 || selection.items[0].constructor.name == "Artboard")
{
// displayWarning(alertDialogMessage);
try
{
await openAlertDialog(pluginTitle, alertDialogMessage);
}
catch(_error)
{
console.log(_error);
}
return false;
}
// if selected object is not inside an artboard
if(selection.items[0].parent.constructor.name != "Artboard")
{
// displayWarning(alertDialogMessage);
try
{
await openAlertDialog(pluginTitle, alertDialogMessage);
}
catch(_error)
{
console.log(_error);
}
return false;
}
// if there is a selection
if(selection.items.length > 0)
{
// if selected object is inside a group
if(selection.items[0].parent.constructor.name == "Group")
{
// displayWarning(alertDialogMessage);
try
{
await openAlertDialog(pluginTitle, alertDialogMessage);
}
catch(_error)
{
console.log(_error);
}
return false;
}
}
// if there are 2 or more selected objects
if(selection.items.length > 1)
{
multipleSelection = true;
}
// get the first selected object's container
let firstObjectParent = selection.items[0].parent;
// console.log("firstSelectedObjectParentName: " + firstObjectParent);
for(let i = 0; i < selection.items.length; i++)
{
// check if other selected objects are inside different artboards
if(selection.items[i].parent != firstObjectParent)
{
// displayWarning("Make sure selected objects are all in the same Artboard.");
try
{
await openAlertDialog(pluginTitle, "Make sure selected objects are all in the same Artboard.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ALERT DIALOG
async function openAlertDialog(_title, _message)
{
let alertDialog = document.createElement("dialog");
// CONTAINER
let alertContainer = document.createElement("form");
alertContainer.style.width = 300;
alertContainer.onsubmit = (e) => alertDialog.close();
alertDialog.appendChild(alertContainer);
// TITLE
let alertTitle = document.createElement("h1");
alertTitle.textContent = _title;
alertTitle.style.marginBottom = 10;
alertContainer.appendChild(alertTitle);
// SEPARATOR
let separator = createSeparator();
separator.style.marginBottom = 30;
alertContainer.appendChild(separator);
// MESSAGE
let alertMessage = document.createElement("div");
alertMessage.style.padding = "0px 6px";
alertMessage.style.fontSize = textFontSize;
alertMessage.style.lineHeight = 1.5;
alertMessage.innerHTML = _message;
alertContainer.appendChild(alertMessage);
// FOOTER
let alertFooter = document.createElement("footer");
alertFooter.style.marginTop = 30;
alertContainer.appendChild(alertFooter);
let alertOkB = createButton("OK", "cta");
alertOkB.setAttribute("type", "submit");
alertOkB.onclick = (e) => alertDialog.close();
alertFooter.appendChild(alertOkB);
document.body.appendChild(alertDialog);
try
{
await alertDialog.showModal();
}
catch(_error)
{
console.log(_error)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PANEL VALIDATION
async function validatePanel(_e)
{
// console.log("validatePanel()");
// _e.preventDefault();
editDocument({editLabel: "Make Pattern"}, async() =>
{
try
{
let s = await checkSelection();
if(s == false)
{
return;
}
else
{
// switch(patternMode)
switch(settingsO["patternMode"])
{
case "seamless":
try
{
let s = await checkSeamlessSettings();
// alertDialog.close("Replace");
if(s == false)
{
return;
}
}
catch(_error)
{
console.log(_error);
}
break;
case "grid":
try
{
let s = await checkGridSettings();
// alertDialog.close("Replace");
if(s == false)
{
return;
}
}
catch(_error)
{
console.log(_error);
}
break;
}
}
makePatternOK();
}
catch(_error)
{
console.log(_error);
}
});
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DATA CHECK
function checkTextFieldNumber(_textFieldValue)
{
let numbers = /^[0-9]+$/;
if(!_textFieldValue.match(numbers))
{
return false;
}
else
{
return true;
}
}
async function checkSeamlessSettings()
{
console.log("checkSeamlessSettings()");
// check if columns or rows are empty
if(seamlessColumnsTF.value === "")
{
// displayWarning("Insert columns.");
try
{
seamlessColumnsTF.focus();
await openAlertDialog(pluginTitle, "Insert columns.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(seamlessRowsTF.value === "")
{
// displayWarning("Insert rows.");
try
{
seamlessRowsTF.focus();
await openAlertDialog(pluginTitle, "Insert rows.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
// check if columns or rows are less than 3
if(seamlessColumnsTF.value < 3)
{
// displayWarning("Columns must be at least 3.");
try
{
seamlessColumnsTF.focus();
await openAlertDialog(pluginTitle, "Columns must be at least 3.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(seamlessRowsTF.value < 3)
{
// displayWarning("Rows must be at least 3.");
try
{
seamlessRowsTF.focus();
await openAlertDialog(pluginTitle, "Rows must be at least 3.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
// check if rows is an even number
if(seamlessRowsTF.value % 2 == 0)
{
// displayWarning("Rows must be an odd number.");
try
{
seamlessRowsTF.focus();
await openAlertDialog(pluginTitle, "Rows must be an odd number.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
// check if columns or rows contain numbers
if(!checkTextFieldNumber(seamlessColumnsTF.value.toString()))
{
try
{
seamlessColumnsTF.focus();
await openAlertDialog(pluginTitle, "Columns must be an integer number.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(!checkTextFieldNumber(seamlessRowsTF.value.toString()))
{
try
{
seamlessRowsTF.focus();
await openAlertDialog(pluginTitle, "Rows must be an integer number.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
else
{
return true;
}
}
async function checkGridSettings()
{
console.log("checkGridSettings()");
/* gridColumns = Number(gridColumnsTF.value);
gridRows = Number(gridRowsTF.value);
gridPadding = Number(gridPaddingTF.value); */
// check if columns or rows are empty
if(gridColumnsTF.value === "")
{
try
{
gridColumnsTF.focus();
await openAlertDialog(pluginTitle, "Insert columns.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(gridRowsTF.value === "")
{
try
{
gridRowsTF.focus();
await openAlertDialog(pluginTitle, "Insert rows.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(gridPaddingTF.value === "")
{
try
{
gridPaddingTF.focus();
await openAlertDialog(pluginTitle, "Insert padding.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
// check if columns or rows are 0
if(gridColumnsTF.value == 0)
{
try
{
gridColumnsTF.focus();
await openAlertDialog(pluginTitle, "Columns must be at least 1.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(gridRowsTF.value == 0)
{
try
{
gridRowsTF.focus();
await openAlertDialog(pluginTitle, "Rows must be at least 1.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(gridColumnsTF.value == 1 && gridRowsTF.value == 1)
{
// displayWarning("1x1 grids are not allowed.");
try
{
gridColumnsTF.focus();
await openAlertDialog(pluginTitle, "1x1 grids are not allowed.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
// check if columns or rows contain numbers
if(!checkTextFieldNumber(gridColumnsTF.value.toString()))
{
// displayWarning("Columns must be an integer number.");
try
{
gridColumnsTF.focus();
await openAlertDialog(pluginTitle, "Columns must be an integer number.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(!checkTextFieldNumber(gridRowsTF.value.toString()))
{
// displayWarning("Rows must be an integer number.");
try
{
gridRowsTF.focus();
await openAlertDialog(pluginTitle, "Rows must be an integer number.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
if(!checkTextFieldNumber(gridPaddingTF.value.toString()))
{
// displayWarning("Padding must be an integer number.");
try
{
gridPaddingTF.focus();
await openAlertDialog(pluginTitle, "Padding must be an integer number.");
}
catch(_error)
{
console.log(_error);
}
return false;
}
else
{
return true;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HELPERS
// - - - - - - - - - - - - - - - - - - - - UI
function createModule(_position, _title)
{
let newModule = document.createElement("div");
newModule.style.marginTop = 20;
let separator = createSeparator();
if(_position != "top")
{
newModule.appendChild(separator);
}
if(_title != "")
{
separator.style.marginBottom = 12;
let titleLabel = createLabelMini(_title);
titleLabel.style.marginBottom = 20;
titleLabel.style.color = labelQuietColor;
// titleLabel.style.letterSpacing = 1.3;
newModule.appendChild(titleLabel);
}
else
{
separator.style.marginBottom = 16;
}
return newModule;
}
function createButton(_text, _variant, _quiet)
{
let newButton = document.createElement("button");
newButton.textContent = _text;
newButton.setAttribute("uxp-variant", _variant);
newButton.setAttribute("uxp-quiet", _quiet);
return newButton;
}
function createTextInput(_placeholder, _width, _quiet)
{
let newTextInput = document.createElement("input");
newTextInput.style.width = _width;
newTextInput.setAttribute("placeholder", _placeholder);
newTextInput.setAttribute("uxp-quiet", _quiet);
return newTextInput;
}
function createCheckBox(_text, _width, _checked)
{
let newCheckBox = document.createElement("label");
newCheckBox.style.display = "flex";
newCheckBox.style.flexDirection = "row";
newCheckBox.style.alignItems = "center";
let checkBox = document.createElement("input");
checkBox.type = "checkbox";
if (_checked)
{
checkBox.checked = true;
}
newCheckBox.appendChild(checkBox);
let checkBoxLabel = createLabel(_text);
checkBoxLabel.style.marginLeft = 6;
checkBoxLabel.style.width = _width;
newCheckBox.appendChild(checkBoxLabel);
return newCheckBox;
}
function createLabel(_text)
{
let newLabel = document.createElement("div");
newLabel.style.textAlign = "left";
newLabel.style.fontSize = labelFontSize;
newLabel.style.color = labelColor;
newLabel.textContent = _text;
return newLabel;
}
function createLabelMini(_text)
{
let newLabel = document.createElement("div");
newLabel.style.textAlign = "left";
newLabel.style.fontSize = labelFontSizeMini;
newLabel.style.color = labelColor;
newLabel.textContent = _text;
return newLabel;
}
function createSeparator()
{
let newSeparator = document.createElement("div");
newSeparator.style.height = 1;
newSeparator.style.background = separatorColor;
return newSeparator;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FUNCTIONS
function platformIsMac()
{
if(platform == "darwin")
{
return true;
}
else
{
return false;
}
}
async function setDefaultSettings()
{
console.log("setDefaultSettings()");
// console.log("renditionsA: ", renditionsA);
try
{
// console.log("\tget data folder");
dataFolder = await localFileSystem.getDataFolder();
try
{
// console.log("\tget settings file");
settingsFile = await dataFolder.getEntry("settings.json");
}
catch(_error)
{
// console.log(_error);
// console.log("\t\tsettings file not found");
try
{
// console.log("\t\tcreate settings.json");
settingsFile = await dataFolder.createFile("settings.json", {overwrite: true});
try
{
let defaultSettingsO = {};
defaultSettingsO["patternMode"] = "seamless";
defaultSettingsO["seamlessColumns"] = 3;
defaultSettingsO["seamlessRows"] = 3;
defaultSettingsO["gridColumns"] = 3;
defaultSettingsO["gridRows"] = 3;
defaultSettingsO["gridPadding"] = 10;
// set default settings
await settingsFile.write(JSON.stringify(defaultSettingsO), {append: false});
}
catch(_error)
{
console.log(_error);
}
}
catch(_error)
{
console.log(_error);
}
}
}
catch(_error)
{
console.log(_error);
}
}
async function getSettings()
{
console.log("getSettings()");
let jsonSettings;
try
{
// console.log("read settings file");
jsonSettings = await settingsFile.read();
}
catch (_error)
{
console.log(_error);
}
settingsO = JSON.parse(jsonSettings);
// console.log("settingsO:");
// console.log(settingsO);
}
async function saveSettings()
{
console.log("saveSettings()");
// console.log(JSON.stringify(settingsO));
try
{
// console.log("\twrite settings");
await settingsFile.write(JSON.stringify(settingsO), {append: false});
}
catch (_error)
{
}
}
function setPatternMode(_patternMode)
{
// console.log("setPatternMode(): " + _patternMode);
warningMessage.style.visibility = "hidden";
switch(_patternMode)
{
case "seamless":
seamlessB.onclick = (e) => "";
gridB.onclick = (e) => setPatternMode("grid");
seamlessB.style.background = activeBkgColor;
gridB.style.background = lightBkgColor;
/* seamlessIcon.src = "img/seamless_on.png";
gridIcon.src = "img/grid_off.png"; */
// seamlessB.style.color = activeColor;
// gridB.style.color = inactiveColor;
seamlessSettings.style.display = "flex";
gridSettings.style.display = "none";
// patternMode = "seamless";
break;
case "grid":
seamlessB.onclick = (e) => setPatternMode("seamless");
gridB.onclick = (e) => "";