@@ -17,6 +17,38 @@ export const QUERIES = "f";
1717// export const SELECTOR = "selector";
1818// export const QUERIES = "queries";
1919
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+
2052const getElementData = ( queries , conditions = null , selector = null ) => {
2153 const newElementData = { } ;
2254
@@ -30,7 +62,7 @@ const getElementData = (queries, conditions = null, selector = null) => {
3062
3163 if (
3264 ( ! query [ CONDITIONS ] && ! conditions ) ||
33- _ . isEqual ( query [ CONDITIONS ] , conditions )
65+ sameCondition ( query [ CONDITIONS ] , conditions )
3466 ) {
3567 const elementsLength = query [ ELEMENTS ] . length ;
3668 for ( let j = 0 ; j < elementsLength ; j ++ ) {
@@ -75,7 +107,7 @@ export default class MetaBuilder {
75107 }
76108
77109 flush ( ) {
78- if ( _ . isEmpty ( this . current . styles ) && _ . isEmpty ( this . current . values ) ) {
110+ if ( isEmpty ( this . current . styles ) && isEmpty ( this . current . values ) ) {
79111 // nothing to flush
80112 return ;
81113 }
@@ -87,15 +119,15 @@ export default class MetaBuilder {
87119 ) ;
88120
89121 // Merge new styles to the stored element data
90- if ( ! _ . isEmpty ( this . current . styles ) ) {
122+ if ( ! isEmpty ( this . current . styles ) ) {
91123 if ( ! storedElementData [ STYLES ] ) {
92124 storedElementData [ STYLES ] = { } ;
93125 }
94126
95127 objectAssign ( storedElementData [ STYLES ] , this . current . styles ) ;
96128 }
97129
98- if ( ! _ . isEmpty ( this . current . values ) ) {
130+ if ( ! isEmpty ( this . current . values ) ) {
99131 if ( ! storedElementData [ VALUES ] ) {
100132 storedElementData [ VALUES ] = { } ;
101133 }
@@ -113,12 +145,11 @@ export default class MetaBuilder {
113145 const style = [ ] ;
114146
115147 if ( typeof node === "string" ) {
116- const matches = node . match ( / ( [ ^ : ] + ) : ( .+ ) / ) ;
117- if ( ! matches ) {
148+ const parts = node . match ( / * ( [ ^ : ] + ) : * ( .+ ) / ) ;
149+ if ( ! parts ) {
118150 throw new Error ( `Invalid CSS declaration format: "${ node } "` ) ;
119151 }
120152
121- const parts = matches . map ( part => _ . trim ( part ) ) ;
122153 style . push ( parts [ 1 ] , parts [ 2 ] ) ;
123154 } else if (
124155 typeof node === "object" &&
0 commit comments