@@ -17,6 +17,38 @@ export const QUERIES = "f";
17
17
// export const SELECTOR = "selector";
18
18
// export const QUERIES = "queries";
19
19
20
+ const isEmpty = obj => Object . keys ( obj ) . length === 0 ;
21
+
22
+ const sameCondition = ( cond1 , cond2 ) => {
23
+ if ( ! Array . isArray ( cond1 ) || ! Array . isArray ( cond2 ) ) {
24
+ return cond1 === cond2 ;
25
+ }
26
+
27
+ if ( cond1 . length !== cond2 . length ) {
28
+ return false ;
29
+ }
30
+
31
+ cond1 = cond1 [ 0 ] ;
32
+ cond2 = cond2 [ 0 ] ;
33
+
34
+ if ( cond1 . length !== cond2 . length ) {
35
+ return false ;
36
+ }
37
+
38
+ const outerArrLength = cond1 . length ;
39
+ for ( let i = 0 ; i < outerArrLength ; i ++ ) {
40
+ const innerArrLength = cond1 [ i ] . length ;
41
+
42
+ for ( let j = 0 ; j < innerArrLength ; j ++ ) {
43
+ if ( cond1 [ i ] [ j ] !== cond2 [ i ] [ j ] ) {
44
+ return false ;
45
+ }
46
+ }
47
+ }
48
+
49
+ return true ;
50
+ } ;
51
+
20
52
const getElementData = ( queries , conditions = null , selector = null ) => {
21
53
const newElementData = { } ;
22
54
@@ -30,7 +62,7 @@ const getElementData = (queries, conditions = null, selector = null) => {
30
62
31
63
if (
32
64
( ! query [ CONDITIONS ] && ! conditions ) ||
33
- _ . isEqual ( query [ CONDITIONS ] , conditions )
65
+ sameCondition ( query [ CONDITIONS ] , conditions )
34
66
) {
35
67
const elementsLength = query [ ELEMENTS ] . length ;
36
68
for ( let j = 0 ; j < elementsLength ; j ++ ) {
@@ -75,7 +107,7 @@ export default class MetaBuilder {
75
107
}
76
108
77
109
flush ( ) {
78
- if ( _ . isEmpty ( this . current . styles ) && _ . isEmpty ( this . current . values ) ) {
110
+ if ( isEmpty ( this . current . styles ) && isEmpty ( this . current . values ) ) {
79
111
// nothing to flush
80
112
return ;
81
113
}
@@ -87,15 +119,15 @@ export default class MetaBuilder {
87
119
) ;
88
120
89
121
// Merge new styles to the stored element data
90
- if ( ! _ . isEmpty ( this . current . styles ) ) {
122
+ if ( ! isEmpty ( this . current . styles ) ) {
91
123
if ( ! storedElementData [ STYLES ] ) {
92
124
storedElementData [ STYLES ] = { } ;
93
125
}
94
126
95
127
objectAssign ( storedElementData [ STYLES ] , this . current . styles ) ;
96
128
}
97
129
98
- if ( ! _ . isEmpty ( this . current . values ) ) {
130
+ if ( ! isEmpty ( this . current . values ) ) {
99
131
if ( ! storedElementData [ VALUES ] ) {
100
132
storedElementData [ VALUES ] = { } ;
101
133
}
@@ -113,12 +145,11 @@ export default class MetaBuilder {
113
145
const style = [ ] ;
114
146
115
147
if ( typeof node === "string" ) {
116
- const matches = node . match ( / ( [ ^ : ] + ) : ( .+ ) / ) ;
117
- if ( ! matches ) {
148
+ const parts = node . match ( / * ( [ ^ : ] + ) : * ( .+ ) / ) ;
149
+ if ( ! parts ) {
118
150
throw new Error ( `Invalid CSS declaration format: "${ node } "` ) ;
119
151
}
120
152
121
- const parts = matches . map ( part => _ . trim ( part ) ) ;
122
153
style . push ( parts [ 1 ] , parts [ 2 ] ) ;
123
154
} else if (
124
155
typeof node === "object" &&
0 commit comments