Ver código fonte

retrieve style info from pseudo-elements

Gildas 6 anos atrás
pai
commit
02066329d1
1 arquivos alterados com 19 adições e 12 exclusões
  1. 19 12
      lib/single-file/util/doc-helper.js

+ 19 - 12
lib/single-file/util/doc-helper.js

@@ -156,22 +156,29 @@ this.docHelper = this.docHelper || (() => {
 		const elements = Array.from(element.childNodes).filter(node => !win || node instanceof win.Element);
 		elements.forEach(element => {
 			getElementsInfo(win, element, elementsInfo);
-			const computedStyle = win.getComputedStyle(element);
-			elementsInfo.set(element, {
-				display: computedStyle.getPropertyValue("display"),
-				opacity: computedStyle.getPropertyValue("opacity"),
-				visibility: computedStyle.getPropertyValue("visibility"),
-				fontFamily: computedStyle.getPropertyValue("font-family"),
-				fontWeight: getFontWeight(computedStyle.getPropertyValue("font-weight")),
-				fontStyle: computedStyle.getPropertyValue("font-style") || "normal",
-				fontVariant: computedStyle.getPropertyValue("font-variant") || "normal",
-				whiteSpace: computedStyle.getPropertyValue("white-space"),
-				shadowRoot: element.shadowRoot
-			});
+			setInfo(win, element, elementsInfo);
+			setInfo(win, element, elementsInfo, "first-letter");
+			setInfo(win, element, elementsInfo, "before");
+			setInfo(win, element, elementsInfo, "after");
 		});
 		return elementsInfo;
 	}
 
+	function setInfo(win, element, elementsInfo, pseudoElement) {
+		const computedStyle = win.getComputedStyle(element, pseudoElement);
+		elementsInfo.set(element, {
+			display: computedStyle.getPropertyValue("display"),
+			opacity: computedStyle.getPropertyValue("opacity"),
+			visibility: computedStyle.getPropertyValue("visibility"),
+			fontFamily: computedStyle.getPropertyValue("font-family"),
+			fontWeight: getFontWeight(computedStyle.getPropertyValue("font-weight")),
+			fontStyle: computedStyle.getPropertyValue("font-style") || "normal",
+			fontVariant: computedStyle.getPropertyValue("font-variant") || "normal",
+			whiteSpace: computedStyle.getPropertyValue("white-space"),
+			shadowRoot: element.shadowRoot
+		});
+	}
+
 	function markHiddenCandidates(win, element, styles, elementHidden, removedCandidates, ignoredTags) {
 		const elements = Array.from(element.childNodes).filter(node => node instanceof win.HTMLElement);
 		elements.forEach(element => markHiddenCandidates(win, element, styles, elementHidden || testHiddenElement(element, styles.get(element)), removedCandidates, ignoredTags));