archcss 0.0.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/dom.js ADDED
@@ -0,0 +1,977 @@
1
+ "use strict";
2
+ /**
3
+ * @package : ArchCSS - Modern CSS framework for responsive and attractive websites and applications.
4
+ * @version : 1.0.0
5
+ * @author : @bebagodfried - [archCSS dev.](https://archcss.com/team/@bebagodfried)
6
+ * @license : MIT license
7
+ */
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ /**
18
+ * AJAX
19
+ * HttpRequest: Create XMLHttpRequest object
20
+ */
21
+ let HttpRequest = () => {
22
+ if (window.XMLHttpRequest) {
23
+ return new XMLHttpRequest;
24
+ }
25
+ else {
26
+ try {
27
+ return new ActiveXObject('Microsoft.XMLHTTP');
28
+ }
29
+ catch (e) {
30
+ try {
31
+ return new ActiveXObject('Msxml2.XMLHTTP');
32
+ }
33
+ catch (XMLHttpRequest_ERR) {
34
+ console.error(XMLHttpRequest_ERR);
35
+ return;
36
+ }
37
+ }
38
+ }
39
+ };
40
+ /**
41
+ * Globals
42
+ * $_: Get/set document vars
43
+ */
44
+ let $_ = (get, set = '') => {
45
+ switch (get) {
46
+ // DOM Objects
47
+ case 'title':
48
+ if (set) {
49
+ document.title = `${set}`;
50
+ break;
51
+ }
52
+ else {
53
+ return document.title;
54
+ }
55
+ case 'charset':
56
+ return document.characterSet;
57
+ case 'baseURI':
58
+ return document.baseURI;
59
+ case 'links':
60
+ return document.links;
61
+ case 'scripts':
62
+ return document.scripts;
63
+ case 'embeds':
64
+ return document.embeds;
65
+ case 'images':
66
+ return document.images;
67
+ case 'readyState':
68
+ return document.readyState;
69
+ // BOM Objects
70
+ case 'cookies':
71
+ return navigator.cookieEnabled;
72
+ case 'language':
73
+ return navigator.language;
74
+ case 'online':
75
+ return navigator.onLine;
76
+ case 'userAgent':
77
+ return navigator.userAgent;
78
+ // Server & location
79
+ case 'host':
80
+ if (set) {
81
+ location.host = `${set}`;
82
+ break;
83
+ }
84
+ else {
85
+ return location.host;
86
+ }
87
+ case 'hostname':
88
+ if (set) {
89
+ location.hostname = `${set}`;
90
+ break;
91
+ }
92
+ else {
93
+ return location.hostname;
94
+ }
95
+ case 'href':
96
+ if (set) {
97
+ location.href = `${set}`;
98
+ break;
99
+ }
100
+ else {
101
+ return location.href;
102
+ }
103
+ case 'url':
104
+ if (set) {
105
+ location.href = `${set}`;
106
+ break;
107
+ }
108
+ else {
109
+ return location.href;
110
+ }
111
+ case 'pathname':
112
+ if (set) {
113
+ location.pathname = `${set}`;
114
+ break;
115
+ }
116
+ else {
117
+ return location.pathname;
118
+ }
119
+ case 'port':
120
+ if (set) {
121
+ location.port = `${set}`;
122
+ break;
123
+ }
124
+ else {
125
+ return location.port;
126
+ }
127
+ case 'protocol':
128
+ if (set) {
129
+ location.protocol = `${set}`;
130
+ break;
131
+ }
132
+ else {
133
+ return location.protocol;
134
+ }
135
+ case 'search':
136
+ if (set) {
137
+ location.search = `${set}`;
138
+ break;
139
+ }
140
+ else {
141
+ return location.search;
142
+ }
143
+ case 'history':
144
+ switch (set) {
145
+ case -1: return history.back();
146
+ case +1: return history.forward();
147
+ case 0: return history.go();
148
+ case 'back': return history.back();
149
+ case 'forward': return history.forward();
150
+ case 'reload': return history.go();
151
+ default: return history.go();
152
+ }
153
+ case 'update':
154
+ return document.lastModified;
155
+ // Return https(SSl) state of current page
156
+ case 'https':
157
+ if (location.protocol = 'https') {
158
+ return true;
159
+ }
160
+ else {
161
+ return false;
162
+ }
163
+ // Owner
164
+ case 'author-org':
165
+ return 'archcss-dev';
166
+ case 'author-name':
167
+ return 'Beba Godfried';
168
+ case 'author-right':
169
+ return 'Godfried\'Ux';
170
+ case 'author-email':
171
+ return 'me@bebagodfried.com';
172
+ case 'author-site':
173
+ return 'https://bebagodfried.com';
174
+ case 'copyright':
175
+ return 'Powered by Godfried\'Ux';
176
+ case 'owner':
177
+ return 'archcss-dev - by Godfried\'Ux';
178
+ case 'version':
179
+ return '2.0.0';
180
+ default:
181
+ console.info(`[404]: Reference '${get}' not found!`);
182
+ return null;
183
+ }
184
+ };
185
+ /** end:Globals **/
186
+ // date: Return date
187
+ let date = (format = '', type = '') => {
188
+ // New date object
189
+ var date = new Date();
190
+ // return Alwayse two digits
191
+ const digit = function (i) {
192
+ if (i < 10)
193
+ i = '0' + i;
194
+ return i;
195
+ };
196
+ // H: Hours
197
+ const H = date.getHours();
198
+ // i: Minutes
199
+ const i = digit(date.getMinutes());
200
+ // s: Seconds
201
+ const s = digit(date.getSeconds());
202
+ // ms: Seconds
203
+ const ms = date.getMilliseconds();
204
+ // t: Timezone
205
+ const t = date.getTimezoneOffset();
206
+ // Y: Year
207
+ const Y = date.getFullYear();
208
+ // m: Month
209
+ const m = date.getMonth();
210
+ // d: Day
211
+ const d = date.getDate();
212
+ // f: Weekday
213
+ const f = date.getDay();
214
+ switch (format) {
215
+ case 'H': //=> Hours
216
+ if (isset(type)) {
217
+ if (type == 'En') {
218
+ // return 12 hours format
219
+ if (H >> 12) {
220
+ return (H - 12);
221
+ }
222
+ else {
223
+ return H;
224
+ }
225
+ }
226
+ else if (type == 'Fr') {
227
+ // return 24 hours format
228
+ return H;
229
+ }
230
+ }
231
+ else {
232
+ return H;
233
+ }
234
+ case 'i': return i; //=> Minutes
235
+ case 's': return s; //=> Seconds
236
+ case 'ms': return s; //=> Seconds
237
+ case 't': return t; //=> Timezone
238
+ case 'Y': return Y; //=> Year
239
+ case 'm': //=> Month
240
+ if (isset(type)) {
241
+ if (type == 'En') {
242
+ // return the month in english
243
+ return months_en[m];
244
+ }
245
+ else if (type == 'Fr') {
246
+ // return the month in french
247
+ return months_fr[m];
248
+ }
249
+ }
250
+ else {
251
+ // return the month as number
252
+ return m;
253
+ }
254
+ case 'd': return (d); //=> Day
255
+ case 'f': return f; //=> Weekday
256
+ case 'En': return weekdays_en[f] + ', ' + months_en[m] + ' ' + digit(d) + ', ' + Y;
257
+ case 'Fr': return weekdays_fr[f] + ' ' + digit(d) + ' ' + months_fr[m] + ' ' + Y;
258
+ case 'DD/MM/YY': return digit(d) + '/' + digit(m) + '/' + Y;
259
+ case 'MM/DD/YY': return digit(m) + '/' + digit(d) + '/' + Y;
260
+ case 'DD-MM-YY': return digit(d) + '-' + digit(m) + '-' + Y;
261
+ case 'MM-DD-YY': return digit(m) + '-' + digit(d) + '-' + Y;
262
+ case 'DD/MM': return digit(d) + '/' + digit(m);
263
+ case 'MM/DD': return digit(m) + '/' + digit(d);
264
+ case 'DD-MM': return digit(d) + '-' + digit(m);
265
+ case 'MM-DD': return digit(m) + '-' + digit(d);
266
+ // hours:minutes
267
+ case 'H:i':
268
+ if (isset(type)) {
269
+ if (type == 'En') {
270
+ // return time in 12 hours format
271
+ if (H >> 12) {
272
+ return (H - 12) + ':' + i;
273
+ }
274
+ else {
275
+ return H + ':' + i;
276
+ }
277
+ }
278
+ else if (type == 'Fr') {
279
+ // return time in 24 hours format
280
+ return H + ':' + i;
281
+ }
282
+ }
283
+ else {
284
+ // return time hours:minutes
285
+ return H + ':' + i;
286
+ }
287
+ // hours:minutes:seconds
288
+ case 'H:i:s':
289
+ if (isset(type)) {
290
+ if (type == 'En') {
291
+ // return time in 12 hours format with seconds
292
+ if (H >> 12) {
293
+ return (H - 12) + ':' + i + ':' + s;
294
+ }
295
+ else {
296
+ return H + ':' + i + ':' + s;
297
+ }
298
+ }
299
+ else if (type == 'Fr') {
300
+ // return time in 24 hours format with seconds
301
+ return H + ':' + i + ':' + s;
302
+ }
303
+ }
304
+ else {
305
+ // return time in hours:minutes:seconds
306
+ return H + ':' + i + ':' + s;
307
+ }
308
+ default: return date.toLocaleString();
309
+ }
310
+ };
311
+ // Days
312
+ let weekdays_en = ['Sunday', 'Monday', 'Thuesday', 'Wednesday', 'Tursday', 'Friday', 'Saturday'];
313
+ let weekdays_fr = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
314
+ // Months
315
+ let months_en = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
316
+ let months_fr = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'];
317
+ // DOM: Document Objects Manipulation
318
+ let DOM = (el, all = true) => {
319
+ try {
320
+ // Remove white space around the element
321
+ if (typeof (el) == 'string' && el != null)
322
+ el = el.trim();
323
+ // By default `all = true` indicate that all `el` are selected
324
+ // all = true
325
+ // all = false
326
+ if (all) {
327
+ return [...document.querySelectorAll(el)];
328
+ }
329
+ else {
330
+ return document.querySelector(el);
331
+ }
332
+ }
333
+ catch (DOM_ERR) {
334
+ // DOM() debug
335
+ // console.error(DOM_ERR)
336
+ console.error('DOM(el: string)' + `: => '${el}' is not a valid selector.`);
337
+ return null;
338
+ }
339
+ };
340
+ // strcopy: copie a text to clipboard
341
+ let strcopy = (text) => __awaiter(void 0, void 0, void 0, function* () {
342
+ try {
343
+ yield navigator.clipboard.writeText(text);
344
+ }
345
+ catch (err) {
346
+ console.error('Failed to copy text: ', err);
347
+ }
348
+ });
349
+ // goto: on event redirection to somewhere
350
+ let goto = (_location) => {
351
+ try {
352
+ location.href = _location.toString();
353
+ }
354
+ catch (err) {
355
+ console.error('Failed to redirect: ', err);
356
+ }
357
+ };
358
+ // attrib: Return element specific attribute
359
+ let attrib = (el, attrib, set) => {
360
+ // Element selection
361
+ let dom = select(el);
362
+ // Set an attrribute value
363
+ if (set) {
364
+ dom.setAttribute(`${attrib}`, `${set}`);
365
+ // else return attrribute value
366
+ }
367
+ else {
368
+ return dom.getAttribute(`${attrib}`);
369
+ }
370
+ };
371
+ // set_attrib: Set an attrribute value to element
372
+ let set_attrib = (el, attrib, set) => {
373
+ // Element selection
374
+ let dom = select(el);
375
+ // Apply the attrribute value to element
376
+ if (set) {
377
+ dom.setAttribute(`${attrib}`, `${set}`);
378
+ }
379
+ else {
380
+ console.warn('set_attrib(el: string, attrib: any, set?: any)' + `: => '${el}.atribute(${attrib}) will be empty.`);
381
+ dom.setAttribute(`${attrib}`, '');
382
+ }
383
+ };
384
+ // get_attrib: Get an attrribute value to element
385
+ let get_attrib = (el, attrib) => {
386
+ // Element selection
387
+ let dom = select(el);
388
+ // Return the attrribute value of the element
389
+ try {
390
+ return dom.getAttribute(`${attrib}`);
391
+ }
392
+ catch (ATTR_ERR) {
393
+ // Debug get_attrib()
394
+ console.error(`${ATTR_ERR.name}: get_attrib(el: string, attrib: any) => '${el}' has no a ${attrib} attribute.`);
395
+ return null;
396
+ }
397
+ };
398
+ /**
399
+ * classlist: add/remove element classes
400
+ * If token is true, adds token (same as [...].classList.add()).
401
+ * If force is false, removes token (same as [...].classList.remove()).
402
+ * */
403
+ let classlist = (el, tokens) => {
404
+ let dom = select(el);
405
+ // check for each token force
406
+ tokens.forEach(key => {
407
+ dom.classList.toggle(key);
408
+ });
409
+ };
410
+ /** end:classlist */
411
+ // create: Create node elements
412
+ let create = (el) => {
413
+ return document.createElement(el);
414
+ };
415
+ // select: Node list selector
416
+ let select = (el, all = false) => {
417
+ try {
418
+ // Remove white space around the element
419
+ if (typeof (el) == 'string' && el != null)
420
+ el = el.trim();
421
+ // By default `all = false` indicate that select the first `el`
422
+ // all = true
423
+ // all = false
424
+ if (all) {
425
+ return [...document.querySelectorAll(el)];
426
+ }
427
+ else {
428
+ return document.querySelector(el);
429
+ }
430
+ }
431
+ catch (select_ERR) {
432
+ // Debug get_attrib()
433
+ console.error(`${select_ERR.name}: select(elememt: string, all?: boolean) => '${el}' is not a valid selector.`);
434
+ return null;
435
+ }
436
+ };
437
+ // select_tag: HTMLCollection selector
438
+ let select_tag = (el) => {
439
+ try {
440
+ // Remove white space around the element
441
+ if (typeof (el) == 'string' && el != null)
442
+ el = el.trim();
443
+ return document.getElementsByTagName(el);
444
+ }
445
+ catch (select_ERR) {
446
+ // Debug select()
447
+ console.error(`${select_ERR.name}: selectTag(tag: string) => '${el}' is not a valid selector.`);
448
+ return null;
449
+ }
450
+ };
451
+ // select_id: Element `Id` selector
452
+ let select_id = (el) => {
453
+ try {
454
+ // Remove white space around the element
455
+ if (typeof (el) == 'string' && el != null)
456
+ el = el.trim();
457
+ return document.getElementById(el);
458
+ }
459
+ catch (select_id_ERR) {
460
+ // Debug select_id()
461
+ console.error(`${select_id_ERR.name}: select_id(id: srting) => '${el}' is not a valid selector.`);
462
+ return null;
463
+ }
464
+ };
465
+ // drop_all: Remove element(s) list from DOM
466
+ let drop_all = (list) => {
467
+ list.forEach(el => {
468
+ // Element selection from list
469
+ const dom = select(el);
470
+ try {
471
+ dom.remove();
472
+ }
473
+ catch (Drop_ERR) {
474
+ // Escape
475
+ return null;
476
+ }
477
+ });
478
+ };
479
+ // drop: Remove element first occurence from DOM
480
+ let drop = (token) => {
481
+ // Element selection
482
+ const dom = select(token);
483
+ try {
484
+ dom.remove();
485
+ }
486
+ catch (Drop_ERR) {
487
+ // Escape
488
+ return null;
489
+ }
490
+ };
491
+ // echo: Add/Replace the content of element(s)
492
+ let echo = (text, el, all = false) => {
493
+ if (isset(el)) {
494
+ if (all) {
495
+ // all = true
496
+ // Genearate a list of all `el`
497
+ let list = select(el, all);
498
+ // for each element of the list add/replace content
499
+ list.forEach((el) => {
500
+ el.innerHTML = `${text}`;
501
+ });
502
+ // by default
503
+ // add/replace the first `el` occurence
504
+ }
505
+ else {
506
+ try {
507
+ return document.querySelector(el).innerHTML = `${text}`;
508
+ }
509
+ catch (e) {
510
+ return el.innerHTML = `${text}`;
511
+ }
512
+ }
513
+ }
514
+ else {
515
+ console.log(`${text}`);
516
+ }
517
+ };
518
+ // get_innerTEXT: Get element text content
519
+ let get_innerTEXT = (el) => {
520
+ // Element selection
521
+ let dom = select(el);
522
+ return dom.innerTEXT;
523
+ };
524
+ // set_innerTEXT: Replace element text content
525
+ let set_innerTEXT = (el, text) => {
526
+ try {
527
+ document.querySelector(el).innerTEXT = `${text}`;
528
+ }
529
+ catch (error) {
530
+ // Debug set_innerTEXT()
531
+ console.error(error);
532
+ }
533
+ };
534
+ // get_innerHTML: Get html content of element
535
+ let get_innerHTML = (el) => {
536
+ // Get html content of an element
537
+ return document.querySelector(el).innerHTML;
538
+ };
539
+ // set_innerHTML: Replace html content of element
540
+ let set_innerHTML = (el, concent) => {
541
+ try {
542
+ document.querySelector(el).innerHTML = `${concent}`;
543
+ }
544
+ catch (error) {
545
+ // Debug get_innerHTML()
546
+ console.error(error);
547
+ }
548
+ };
549
+ // display: Display/hide specific DOM element
550
+ let display = (el, displayValue = 'block') => {
551
+ // Element selection
552
+ const dom = select(el);
553
+ // if hidden by style attribute then display as `displayValue`
554
+ if (dom.style.display == 'none') {
555
+ return dom.style.display == `${displayValue}`;
556
+ // if displayed by style attribute then change the value to `none`
557
+ }
558
+ else if (dom.style.display == `${displayValue}`) {
559
+ return dom.style.display == 'none';
560
+ }
561
+ else {
562
+ // if hidden by class attribute containing `hidden` token
563
+ // then remove the `hidden` class and add the `displayValue` class
564
+ if (dom.classList.contains('hidden')) {
565
+ try {
566
+ dom.classList.remove('hidden');
567
+ dom.classList.add(`${displayValue}`);
568
+ }
569
+ catch (display_ERR) {
570
+ // Debug display() #1
571
+ console.error(display_ERR);
572
+ }
573
+ // if displayed by class attribute as containing `displayValue` token
574
+ // then remove the `displayValue` class and add the `hidden` class
575
+ }
576
+ else if (dom.classList.contains(`${displayValue}`)) {
577
+ try {
578
+ dom.classList.remove(`${displayValue}`);
579
+ dom.classList.add('hidden');
580
+ }
581
+ catch (display_ERR) {
582
+ // Debug display() #2
583
+ console.error(display_ERR);
584
+ }
585
+ }
586
+ else {
587
+ // if hidden by hidden attribute
588
+ // then remove the `hidden` class and add the `displayValue` class
589
+ // Get the attribute
590
+ try {
591
+ let hide = dom.getAttribute('hidden');
592
+ if (isset(hide)) {
593
+ if (hide == true) {
594
+ return hide = false;
595
+ }
596
+ else {
597
+ return hide = true;
598
+ }
599
+ }
600
+ }
601
+ catch (display_ERR) {
602
+ // Debug display() #3
603
+ console.error(display_ERR);
604
+ }
605
+ }
606
+ }
607
+ };
608
+ // hide: make hidden element of first occurence from DOM
609
+ let hide = (el) => {
610
+ // Possible classlist values
611
+ const list = ['block', 'inline-block', 'flex', 'inline-flex'];
612
+ // Element selection
613
+ const dom = select(el);
614
+ try {
615
+ // for each display token from list
616
+ // if `el` classList.contains a token display then change it to `hidden`
617
+ list.forEach(display => {
618
+ if (dom.classList.contains(`${display}`)) {
619
+ dom.classList.remove(`${display}`);
620
+ dom.classList.add('hidden');
621
+ }
622
+ });
623
+ }
624
+ catch (hide_ERR) {
625
+ // hide `el` by attribute
626
+ let hide = dom.getAttribute('hidden');
627
+ try {
628
+ if (!isset(hide)) {
629
+ return hide = true;
630
+ }
631
+ }
632
+ catch (display_ERR) {
633
+ // Debug hide()
634
+ console.error(display_ERR);
635
+ }
636
+ }
637
+ };
638
+ /**
639
+ * Events listners
640
+ * ...
641
+ */
642
+ // On: Events listner
643
+ let on = (event, listener) => {
644
+ event = event.trim();
645
+ document.addEventListener(event, listener);
646
+ };
647
+ let on_scroll = (el, add_list, rm_list = [], offset = 0) => {
648
+ var dom = select(el);
649
+ // Add or remove class based on scroll position
650
+ if (window.scrollY > offset) {
651
+ add_list.forEach(key => {
652
+ dom.classList.add(key);
653
+ });
654
+ rm_list.forEach(key => {
655
+ dom.classList.remove(key);
656
+ });
657
+ }
658
+ else {
659
+ add_list.forEach(key => {
660
+ dom.classList.remove(key);
661
+ });
662
+ rm_list.forEach(key => {
663
+ dom.classList.add(key);
664
+ });
665
+ }
666
+ };
667
+ let scroll_to = (el) => {
668
+ // JavaScript to scroll to the target element
669
+ var dom = select_id(el);
670
+ dom.scrollIntoView({ behavior: 'smooth', block: 'start' });
671
+ };
672
+ // Onclick: Click listner
673
+ let onClick = (el, listener) => {
674
+ const d = select_id(el);
675
+ return d.onclick = listener;
676
+ };
677
+ // Ondlclick: Double click listner
678
+ let onDblClick = (el, listener) => {
679
+ const d = select_id(el);
680
+ return d.ondblclick = listener;
681
+ };
682
+ /**
683
+ * Validation
684
+ * Check for exist listner
685
+ */
686
+ // Isset: Return true for no-empty Object/var
687
+ let isset = (key) => {
688
+ if (key != null && key != false && key != undefined) {
689
+ return true;
690
+ }
691
+ else if (key != '' && key != ' ') {
692
+ return true;
693
+ }
694
+ else {
695
+ return false;
696
+ }
697
+ };
698
+ /**
699
+ * Mixed
700
+ * popUp: create advenced pup-up box style
701
+ * @param popUp
702
+ */
703
+ let popUp = function (window = { title: ``, favicon: ``, content: ``, html: ``, href: ``, titlebar: true, rounded: true, shadow: true, classlist: [], style: ``, border: true, overlay: false, height: ``, width: ``, top: ``, right: ``, bottom: ``, left: ``, index: 8, timeout: 0 }) {
704
+ // Pop_up
705
+ // #1. Create a new window with basic set
706
+ const WINDOW = create('div');
707
+ // setup
708
+ WINDOW.id = window.title;
709
+ WINDOW.classList.add('rounded', 'flex', 'flex-column', 'select-none');
710
+ WINDOW.style.position = 'fixed';
711
+ // size
712
+ WINDOW.style.height = window.height;
713
+ WINDOW.style.width = window.width;
714
+ // #2. Check window's already exist
715
+ if (select_id(`${WINDOW.id}`)) {
716
+ let el = select_id(WINDOW.id);
717
+ el === null || el === void 0 ? void 0 : el.classList.add('animate-pulse');
718
+ setTimeout(() => {
719
+ el === null || el === void 0 ? void 0 : el.classList.remove('animate-pulse');
720
+ }, 1000);
721
+ return null;
722
+ }
723
+ // #3. classlist: Add more features/tweaks
724
+ if (window.classlist) {
725
+ window.classlist.forEach(classItem => {
726
+ WINDOW.classList.add(classItem);
727
+ });
728
+ }
729
+ // #4. index/z-index: add a window priority (default: 8)
730
+ if (window.index) {
731
+ WINDOW.classList.add(`${'z-' + window.index}`);
732
+ }
733
+ else {
734
+ WINDOW.classList.add('z-8');
735
+ }
736
+ // #5. style: choose apearence between dark/light (default: light)
737
+ if (`${window.style}` == 'dark') {
738
+ WINDOW.classList.add('bg-dark-900', 'fg-light');
739
+ }
740
+ else if (`${window.style}` == 'light') {
741
+ WINDOW.classList.add('bg-light', 'fg-dark-900');
742
+ }
743
+ else if (`${window.style}` == 'none') {
744
+ WINDOW.style.color = 'inherit';
745
+ }
746
+ else {
747
+ WINDOW.classList.add('bg-light', 'fg-dark-900');
748
+ }
749
+ // #6. border: enable window border (default: true)
750
+ if (window.border == true) {
751
+ WINDOW.classList.add('border');
752
+ }
753
+ else if (window.border == false) {
754
+ // do nothing ...
755
+ }
756
+ else {
757
+ WINDOW.classList.add('border');
758
+ }
759
+ // #7. rounded: enable window rounded border (default: true)
760
+ if (window.rounded == true) {
761
+ WINDOW.classList.add('rounded');
762
+ }
763
+ else if (window.rounded == false) {
764
+ // do nothing ...
765
+ }
766
+ else {
767
+ WINDOW.classList.add('rounded');
768
+ }
769
+ // #8. shadow: enable window shadow (default: true)
770
+ if (window.shadow == true) {
771
+ WINDOW.classList.add('shadow-sm');
772
+ }
773
+ else if (window.shadow == false) {
774
+ // do nothing ...
775
+ }
776
+ else {
777
+ WINDOW.classList.add('shadow-sm');
778
+ }
779
+ // #9. [top, right, bottom, left]: set window position
780
+ if (window.top || window.right || window.bottom || window.left) {
781
+ WINDOW.style.top = window.top;
782
+ WINDOW.style.right = window.right;
783
+ WINDOW.style.bottom = window.bottom;
784
+ WINDOW.style.left = window.left;
785
+ }
786
+ else {
787
+ WINDOW.style.top = '50%';
788
+ WINDOW.style.left = '50%';
789
+ WINDOW.classList.add('translate--50');
790
+ }
791
+ // #10. header/title bar
792
+ // #10.1 Create a title bar
793
+ const HEADER = create('div');
794
+ HEADER.classList.add('flex', 'items-center', 'justify-between', 'full-width');
795
+ HEADER.style.padding = '.2rem';
796
+ // #10.2 favicon: add an icon as window illustrator
797
+ const FAVICON = create('img');
798
+ if (window.favicon) {
799
+ FAVICON.src = window.favicon;
800
+ FAVICON.classList.add('size-32');
801
+ }
802
+ // #10.3 Window action bar
803
+ // * title: set the window title/id
804
+ const TITLE = create('span');
805
+ TITLE.classList.add('pl-1', 'line-clamp-1', 'sm:line-clamp-1');
806
+ TITLE.innerHTML = window.title;
807
+ // * add moving icon
808
+ const WIN_Move = create('button');
809
+ WIN_Move.classList.add('bg-none', 'cursor-default', 'fa-solid', 'fa-up-down-left-right', 'p-0', 'rounded-full', 'size-32', 'muted');
810
+ // * add closing button
811
+ const WIN_Close = create('button');
812
+ WIN_Close.classList.add('bg-none', 'fa-solid', 'fa-times', 'hover:bg-danger', 'p-0', 'rounded-full', 'size-32');
813
+ // #11. views: create adaptable content
814
+ var view = '';
815
+ if (window.content) {
816
+ view = 'p';
817
+ }
818
+ else if (window.html) {
819
+ view = 'div';
820
+ }
821
+ else if (window.href) {
822
+ view = 'iframe';
823
+ }
824
+ // - create main window view
825
+ const CONTENT = create(view);
826
+ if (window.content) {
827
+ CONTENT.classList.add('m-0', 'px-2', 'py-1', 'w-full');
828
+ CONTENT.innerHTML = window.content;
829
+ if (window.titlebar == true) {
830
+ CONTENT.classList.add('border', 'border-0', 'border-t-1');
831
+ }
832
+ }
833
+ else if (window.html) {
834
+ CONTENT.classList.add('max-height', 'border-0', 'border-t-1', 'border-white', 'px-2', 'py-1', 'w-full');
835
+ CONTENT.innerHTML = window.html;
836
+ }
837
+ else if (window.href) {
838
+ CONTENT.classList.add('no-border');
839
+ CONTENT.height = '100%';
840
+ CONTENT.width = '100%';
841
+ CONTENT.src = window.href;
842
+ if (window.titlebar == true) {
843
+ CONTENT.classList.add('border-0', 'border-t-1', 'border-white');
844
+ }
845
+ }
846
+ // #12. Actions
847
+ // #12.1 draging action (double-click)
848
+ WINDOW.ondblclick = () => {
849
+ let move = get_attrib('.js_focus', 'aria-grabbed');
850
+ WINDOW.classList.toggle('cursor-grabbing');
851
+ if (move == 'true') {
852
+ WINDOW.setAttribute('aria-grabbed', 'false');
853
+ WIN_Move.classList.add('muted');
854
+ }
855
+ else {
856
+ WINDOW.setAttribute('aria-grabbed', 'true');
857
+ WIN_Move.classList.remove('muted');
858
+ }
859
+ };
860
+ WINDOW.addEventListener('mousemove', (e) => {
861
+ let focus = select('.js_focus');
862
+ let drag = get_attrib(`#${focus.id}`, 'aria-grabbed');
863
+ // ajust window option according to cursor position
864
+ if (focus && drag == 'true') {
865
+ let x = e.clientX;
866
+ let y = e.clientY;
867
+ WINDOW.style.left = `${x}px`;
868
+ WINDOW.style.top = `${y}px`;
869
+ }
870
+ });
871
+ // #12.1 closing action (cross button click)
872
+ WIN_Close.onclick = () => {
873
+ drop('.js_focus');
874
+ try {
875
+ // remove window overlay if enabled
876
+ drop('#window_overlay');
877
+ }
878
+ catch (error) {
879
+ return null;
880
+ }
881
+ };
882
+ // #12.2 focus/`switch focus` action priority(hover/click on window)
883
+ WINDOW.addEventListener('mouseover', () => {
884
+ WINDOW.classList.add('js_focus');
885
+ if (!window.index) {
886
+ WINDOW.onclick = () => {
887
+ let lostFocus = select('.z-8');
888
+ if (lostFocus) {
889
+ lostFocus.classList.add('z-7');
890
+ lostFocus.classList.remove('z-8');
891
+ }
892
+ WINDOW.classList.add('z-8');
893
+ };
894
+ }
895
+ });
896
+ // #12.3 lost focus priority
897
+ WINDOW.addEventListener('mouseleave', () => {
898
+ WINDOW.classList.remove('js_focus');
899
+ });
900
+ // #12.4 timeout
901
+ if (window.timeout != 0 && window.timeout != null) {
902
+ let timeout = window.timeout;
903
+ setTimeout(() => {
904
+ WINDOW.classList.add('animate-fadeOut');
905
+ }, timeout);
906
+ WINDOW.remove();
907
+ }
908
+ // #13. final views
909
+ // # header sections
910
+ // - favicon & title block
911
+ let div_1 = create('div');
912
+ div_1.classList.add('flex', 'items-center');
913
+ if (window.favicon) {
914
+ div_1.appendChild(FAVICON);
915
+ }
916
+ div_1.appendChild(TITLE);
917
+ // - window actions block
918
+ let div_2 = create('div');
919
+ div_2.classList.add('flex', 'items-center', 'g-1');
920
+ div_2.appendChild(WIN_Move);
921
+ div_2.appendChild(WIN_Close);
922
+ HEADER.appendChild(div_1);
923
+ HEADER.appendChild(div_2);
924
+ // #14. Ready header view's
925
+ if (window.titlebar != false) {
926
+ WINDOW.appendChild(HEADER);
927
+ }
928
+ // #15. Ready content view's
929
+ WINDOW.appendChild(CONTENT);
930
+ // *** overlay options view ***
931
+ if (window.overlay == true) {
932
+ let overlay = create('div');
933
+ overlay.id = 'window_overlay';
934
+ overlay.classList.add('absolute', 'fullscreen', 'top-0', 'left-0', 'backdrop-blur-10', 'ease-in', 'animate-fadeIn', 'animated-500');
935
+ if (window.index) {
936
+ let i = window.index;
937
+ overlay.classList.add(`z-${i - 1}`);
938
+ }
939
+ else {
940
+ overlay.classList.add('z-8');
941
+ }
942
+ document.body.appendChild(overlay);
943
+ document.body.appendChild(WINDOW);
944
+ }
945
+ else {
946
+ document.body.appendChild(WINDOW);
947
+ }
948
+ };
949
+ /**
950
+ * Cookies manage
951
+ */
952
+ let set_cookie = (cookieName, cookieValue, cookieExpiry) => {
953
+ try {
954
+ if (isset(cookieExpiry)) {
955
+ document.cookie = `${cookieName = cookieValue}; expires=${cookieExpiry};`;
956
+ }
957
+ else {
958
+ document.cookie = `${cookieName = cookieValue}`;
959
+ }
960
+ }
961
+ catch (Cookie_ERR) {
962
+ console.error(Cookie_ERR);
963
+ }
964
+ };
965
+ let unset_cookie = (cookieName, cookieExpiry) => {
966
+ try {
967
+ if (isset(cookieExpiry)) {
968
+ document.cookie = `username=${cookieName}; expires=${cookieExpiry};`;
969
+ }
970
+ else {
971
+ document.cookie = `username=${cookieName}; expires=Thu, 01 Jan 1970 00:00:00 UTC`;
972
+ }
973
+ }
974
+ catch (Cookie_ERR) {
975
+ console.error(Cookie_ERR);
976
+ }
977
+ };