From c797576580bb05b50dfab0dbbeebc0e75a34abda Mon Sep 17 00:00:00 2001 From: zealotchen <92966734+zealotchen0@users.noreply.github.com> Date: Mon, 25 Sep 2023 13:08:42 +0800 Subject: [PATCH] feat(vue): revert css match (#3528) * feat(vue): revert css match * feat(vue): block PseudoClassSelector dynamic --- .../renderer/native/style/css-selectors.js | 49 +++++++------------ 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/driver/js/packages/hippy-vue/src/renderer/native/style/css-selectors.js b/driver/js/packages/hippy-vue/src/renderer/native/style/css-selectors.js index 725eb8dc63c..c2b3897ebe0 100644 --- a/driver/js/packages/hippy-vue/src/renderer/native/style/css-selectors.js +++ b/driver/js/packages/hippy-vue/src/renderer/native/style/css-selectors.js @@ -219,7 +219,7 @@ class PseudoClassSelector extends SimpleSelector { super(); this.specificity = 0x00000100; this.rarity = 0; - this.dynamic = true; + this.dynamic = false; this.cssPseudoClass = cssPseudoClass; } @@ -457,40 +457,26 @@ class SiblingGroup { class Selector extends SelectorCore { constructor(selectors) { super(); - const supportedCombinator = [undefined, ' ', '>', '+', '~']; - let siblingGroup = []; - let lastGroup = []; + const supportedCombinator = [undefined, ' ', '>', '+']; + let siblingGroup; + let lastGroup; const groups = []; - const selectorList = [...selectors]; - const length = selectorList.length - 1; - this.specificity = 0; - this.dynamic = false; - - for (let i = length; i >= 0; i--) { - const sel = selectorList[i]; + selectors.reverse().forEach((sel) => { if (supportedCombinator.indexOf(sel.combinator) === -1) { - console.error(`Unsupported combinator "${sel.combinator}".`); throw new Error(`Unsupported combinator "${sel.combinator}".`); } - if (sel.combinator === undefined || sel.combinator === ' ') { - groups.push(lastGroup = [(siblingGroup = [])]); + groups.push(lastGroup = [siblingGroup = []]); } if (sel.combinator === '>') { - lastGroup.push((siblingGroup = [])); - } - - this.specificity += sel.specificity; - - if (sel.dynamic) { - this.dynamic = true; + lastGroup.push(siblingGroup = []); } - siblingGroup.push(sel); - } - - this.groups = groups.map(g => new ChildGroup(g.map(sg => new SiblingGroup(sg)))); - this.last = selectorList[length]; + }); + this.groups = groups.map(g => new Selector.ChildGroup(g.map(sg => new Selector.SiblingGroup(sg)))); + this.last = selectors[0]; + this.specificity = selectors.reduce((sum, sel) => sel.specificity + sum, 0); + this.dynamic = selectors.some(sel => sel.dynamic); } toString() { @@ -498,7 +484,6 @@ class Selector extends SelectorCore { } match(node) { - if (!node) return false; return this.groups.every((group, i) => { if (i === 0) { node = group.match(node); @@ -547,7 +532,7 @@ class Selector extends SelectorCore { return false; }); - // Calculating the right bounds for each selector won't save much + // Calculating the right bounds for each selectors won't save much if (!mayMatch) { return false; } @@ -562,12 +547,12 @@ class Selector extends SelectorCore { continue; } const bound = bounds[i]; - let node = bound.left; + let leftBound = bound.left; do { - if (group.mayMatch(node)) { - group.trackChanges(node, map); + if (group.mayMatch(leftBound)) { + group.trackChanges(leftBound, map); } - } while ((node !== bound.right) && (node = node.parentNode)); + } while ((leftBound !== bound.right) && (leftBound = node.parentNode)); } return mayMatch;