@@ -48,6 +48,8 @@ const head = document.querySelector('head');
4848let globalCSS = '' ;
4949let accent ;
5050
51+ let debugMode = false ;
52+
5153window . onload = ( ) => {
5254 if ( ! document . querySelector ( 'meta[name=viewport]' ) ) {
5355 let metaViewport = document . createElement ( 'meta' ) ;
@@ -68,39 +70,39 @@ window.onload = () => {
6870 }
6971} ;
7072
71- let elementsTree ;
73+ export let elementsTree ;
7274
73- export function view ( elements , debugLog = false ) {
75+ export function view ( elements , debug = false ) {
7476 elementsTree = elements ;
7577 if ( document . body . hasChildNodes ( ) ) {
7678 document . body . innerHTML = '' ;
7779 }
78- if ( debugLog === true ) {
79- debug ( elements ) ;
80+ if ( debug === true ) {
81+ printDebug ( elements ) ;
8082 }
8183 render ( document . body , elements ) ;
82- setTimeout ( function ( ) {
84+ setTimeout ( function ( ) {
8385 applyGlobalStyle ( ) ;
8486 } , 500 ) ;
8587 return new Body ( ) ;
8688}
8789
88- function updateView ( debugLog = false ) {
90+ function updateView ( debug = false ) {
8991 if ( document . body . hasChildNodes ( ) ) {
9092 document . body . innerHTML = '' ;
9193 }
92- if ( debugLog === true ) {
93- debug ( elementsTree ) ;
94+ if ( debug === true ) {
95+ printDebug ( elementsTree ) ;
9496 }
9597 render ( document . body , elementsTree ) ;
96- setTimeout ( function ( ) {
98+ setTimeout ( function ( ) {
9799 document . querySelector ( 'style#jsUI' ) . innerText = globalCSS ;
98100 } , 500 ) ;
99101}
100102
101103export function render ( parent , elements ) {
102104 if ( Array . isArray ( elements ) ) {
103- elements . forEach ( function ( element ) {
105+ elements . forEach ( function ( element ) {
104106 if ( Array . isArray ( element ) ) {
105107 render ( parent , element ) ;
106108 } else {
@@ -154,7 +156,7 @@ class GlobalElementStyle extends Element {
154156 this . element = element ;
155157 this . selector = selector ;
156158 const instance = this ;
157- setTimeout ( function ( ) {
159+ setTimeout ( function ( ) {
158160 instance . #apply( ) ;
159161 } , 100 ) ;
160162 }
@@ -214,22 +216,22 @@ export function accentColor(hexColor) {
214216 }
215217 addCSS ( {
216218 '::selection' : {
217- 'background' : hexColor + '50'
219+ 'background' : hexColor + '50' ,
218220 } ,
219221 '::moz-selection' : {
220- 'background' : hexColor + '50'
222+ 'background' : hexColor + '50' ,
221223 } ,
222224 'a:link' : {
223- 'color' : hexColor
225+ 'color' : hexColor ,
224226 } ,
225227 '.jsui-spinner' : {
226- 'border-top-color' : hexColor
228+ 'border-top-color' : hexColor ,
227229 } ,
228230 'input,textarea,select' : {
229231 'accent-color' : hexColor ,
230232 'outline-color' : hexColor ,
231- 'caret-color' : hexColor
232- }
233+ 'caret-color' : hexColor ,
234+ } ,
233235 } ) ;
234236 return this ;
235237}
@@ -262,23 +264,23 @@ function findRef(elements, reference) {
262264}
263265
264266export function select ( selector ) {
265- return new InstanceSelector ( selector ) ;
267+ return new Selector ( selector ) ;
266268}
267269
268- class InstanceSelector extends Element {
270+ class Selector extends Element {
269271 constructor ( selector ) {
270- const element = document . getElementById ( selector ) ;
272+ const element = document . querySelector ( selector ) ;
271273 if ( element ) {
272274 super ( element ) ;
273275 this . element = element ;
274276 } else {
275- console . error ( 'Cannot find element with name : ' + selector ) ;
277+ console . error ( 'Cannot find element with selector : ' + selector ) ;
276278 return false ;
277279 }
278280 }
279281}
280282
281- export function debug ( elements ) {
283+ export function printDebug ( elements ) {
282284 const body = document . body ;
283285 const globalStyle = document . querySelector ( 'style#jsUI' ) ;
284286 console . log ( '[javascript-ui] Generated HTML' , body ) ;
@@ -293,9 +295,16 @@ function printElements(elements) {
293295 console . group ( `[${ element . constructor . name } ]` ) ;
294296 if ( element . element ) {
295297 const tagName = element . tag ( ) ;
298+ const selector = element . selector ( ) ;
296299 if ( tagName ) {
297300 console . log ( `HTML Tag: <${ tagName } />` ) ;
298301 }
302+ if ( selector ) {
303+ console . log ( `Selector: ${ selector } ` ) ;
304+ }
305+ if ( element . reference ) {
306+ console . log ( `Reference: ${ element . reference } ` ) ;
307+ }
299308 }
300309 if ( element . elements || Array . isArray ( element ) ) {
301310 console . group ( '[Elements]' ) ;
@@ -309,5 +318,5 @@ function printElements(elements) {
309318 console . log ( `Content: "${ element . element . innerHTML ?? element . element . innerText } "` ) ;
310319 }
311320 console . groupEnd ( ) ;
312- } )
321+ } ) ;
313322}
0 commit comments