MCPcopy Create free account
hub / github.com/CanadaHonk/shadow / testCSSConditions

Method testCSSConditions

engine/layout.js:130–155  ·  view source on GitHub ↗
(conds)

Source from the content-addressed store, hash-verified

128 }
129
130 testCSSConditions(conds) {
131 const pseudoCheck = text => {
132 switch (text) {
133 case 'root':
134 return this.tagName === 'html';
135
136 case 'link': // we have no history recorded (yet)
137 case 'any-link':
138 return this.tagName === 'a' && !!this.attrs.href;
139 }
140
141 return false;
142 };
143
144 for (const x of conds) { // a#b.c (a AND b AND c)
145 if (
146 !(x.type === SelectorType.Tag && this.tagName === x.text) && // tag
147 !(x.type === SelectorType.Id && this.id === x.text) && // id
148 !(x.type === SelectorType.Class && this.hasClass(x.text)) && // class
149 !(x.type === SelectorType.Pseudo && pseudoCheck(x.text)) && // pseudo classes
150 !(x.type === SelectorType.Universal) // universal (*)
151 ) return false;
152 }
153
154 return true;
155 }
156
157 // selectors (a, b, c)
158 // combinators (a b > c)

Callers 1

matchesCSSMethod · 0.95

Calls 1

hasClassMethod · 0.80

Tested by

no test coverage detected