@onepercentio/one-ui 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
function getTextNodesIn(elem: HTMLElement): ChildNode[] {
|
|
2
|
+
var textNodes: ChildNode[] = [];
|
|
3
|
+
if (elem) {
|
|
4
|
+
for (var nodes = elem.childNodes, i = nodes.length; i--;) {
|
|
5
|
+
var node = nodes[i], nodeType = node.nodeType;
|
|
6
|
+
if (nodeType == 3) {
|
|
7
|
+
textNodes.push(node);
|
|
8
|
+
}
|
|
9
|
+
else if (nodeType == 1 || nodeType == 9 || nodeType == 11) {
|
|
10
|
+
textNodes = textNodes.concat(getTextNodesIn(node as HTMLElement));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return textNodes;
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
export default function inlineCSS() {
|
|
2
18
|
if (process.env.NODE_ENV === "development") return;
|
|
3
19
|
const allEls = Array.from(document.querySelectorAll("*")) as HTMLElement[];
|
|
@@ -19,6 +35,17 @@ export default function inlineCSS() {
|
|
|
19
35
|
el.setAttribute("style", s);
|
|
20
36
|
});
|
|
21
37
|
|
|
38
|
+
getTextNodesIn(document.body).forEach(n => {
|
|
39
|
+
n.replaceWith(...n.textContent
|
|
40
|
+
.split(/\n/g)
|
|
41
|
+
.reduce((r, txt, i, arr) =>
|
|
42
|
+
(arr.length - 1 === i )
|
|
43
|
+
? [...r, txt]
|
|
44
|
+
: [...r, txt, document.createElement("br")],
|
|
45
|
+
[] as (Node | string)[])
|
|
46
|
+
);
|
|
47
|
+
})
|
|
48
|
+
|
|
22
49
|
if (process.env.NODE_ENV !== "test")
|
|
23
50
|
document.querySelectorAll("style").forEach((e) => e.remove());
|
|
24
51
|
}
|