1
+ import { getChildFromSinglePath } from './getChildFromSinglePath.js' ;
2
+ import { cd } from './cd.js' ;
3
+ import { dashToCamelCase } from './dashToCamelCase.js' ;
4
+
1
5
class $hell {
2
- static DASH_TO_CAMEL = / - [ a - z ] / g;
3
6
4
- static dashToCamelCase ( dash ) {
5
- return dash . replace ( $hell . DASH_TO_CAMEL , m => m [ 1 ] . toUpperCase ( ) ) ;
6
- }
7
7
static $0 : HTMLElement ;
8
- static pathHistory : string [ ] ;
8
+ static pathHistory : string [ ] = [ ] ;
9
9
static get pwd ( ) {
10
10
return this . pathHistory . join ( '/' ) ;
11
11
}
@@ -16,62 +16,12 @@ class $hell{
16
16
static cd ( path : string ) {
17
17
if ( ! this . $0 || path . startsWith ( '/' ) ) {
18
18
this . initialize ( ) ;
19
- }
20
- const splitPath = path . split ( '/' ) ;
21
- splitPath . forEach ( token => {
22
- if ( ! token ) return ;
23
- this . pathHistory . push ( token ) ;
24
- // let idx = 0;
25
- // let nonIndexedToken = token;
26
- // if(token === '..'){
27
- // this.$0 = this.$0.parentElement;
28
- // //if(typeof $0 !== 'undefined') $0 = this.currentEl;
29
- // return this.$0;
30
- // }else if(token.endsWith(']')){
31
- // const posOfOpen = token.indexOf('[');
32
- // const indxString = token.substring(posOfOpen + 1, token.length - 1);
33
- // idx = parseInt(indxString);
34
- // nonIndexedToken = token.substring(0, posOfOpen);
35
- // }
36
- // //const children = this.$0.querySelectorAll(':scope > ' + nonIndexedToken);
37
- // const matchingNodes = [];
38
- // this.children.forEach((child : HTMLElement) =>{
39
- // if(child.matches && child.matches(nonIndexedToken)){
40
- // matchingNodes.push(child);
41
- // }
42
- // })
43
-
44
- //this.$0 = matchingNodes[idx] as HTMLElement;
45
- this . $0 = this . getChildFromSinglePath ( this . $0 , token ) ;
46
-
47
- } )
19
+ }
20
+ this . $0 = cd ( this . $0 , path , this . pathHistory ) ;
48
21
return this . $0 ;
49
22
}
50
23
51
- static getChildFromSinglePath ( el : HTMLElement , token : string ) {
52
- let idx = 0 ;
53
- let nonIndexedToken = token ;
54
- if ( token === '..' ) {
55
- // this.$0 = this.$0.parentElement;
56
- // return this.$0;
57
- return e . parentNode ;
58
- }
59
- if ( token . endsWith ( ']' ) ) {
60
- const posOfOpen = token . indexOf ( '[' ) ;
61
- const indxString = token . substring ( posOfOpen + 1 , token . length - 1 ) ;
62
- idx = parseInt ( indxString ) ;
63
- nonIndexedToken = token . substring ( 0 , posOfOpen ) ;
64
- }
65
- //const children = this.$0.querySelectorAll(':scope > ' + nonIndexedToken);
66
- const matchingNodes = [ ] ;
67
- this . getChildren ( el ) . forEach ( ( child : HTMLElement ) => {
68
- if ( child . matches && child . matches ( nonIndexedToken ) ) {
69
- matchingNodes . push ( child ) ;
70
- }
71
- } )
72
24
73
- return matchingNodes [ idx ] as HTMLElement ;
74
- }
75
25
static getChildren ( parent : HTMLElement ) {
76
26
switch ( parent . nodeName ) {
77
27
case 'IFRAME' :
@@ -159,7 +109,7 @@ class $hell{
159
109
const observedAttributes = ce [ 'observedAttributes' ] as string [ ] ;
160
110
if ( observedAttributes ) {
161
111
observedAttributes . forEach ( attrib => {
162
- const camelCase = this . dashToCamelCase ( attrib ) ;
112
+ const camelCase = dashToCamelCase ( attrib ) ;
163
113
props [ camelCase ] = true ;
164
114
} )
165
115
}
@@ -197,7 +147,7 @@ class $hell{
197
147
const list = this . getList ( this . getChildren ( parent ) ) ;
198
148
let path = '' ;
199
149
list . forEach ( token => {
200
- const testEl = this . getChildFromSinglePath ( parent , token ) ;
150
+ const testEl = getChildFromSinglePath ( parent , token ) ;
201
151
if ( testEl === el ) {
202
152
path = token ;
203
153
}
0 commit comments