-
Notifications
You must be signed in to change notification settings - Fork 39
/
Styles.js
68 lines (58 loc) · 1.67 KB
/
Styles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var _gdotdesign$elm_ui$Native_Styles = function() {
if(typeof document === "undefined") {
return {patchStyles: function() {}};
}
var currentStyles = {}
var setupObserver = function () {
if(window.MutationObserver) {
new MutationObserver(function (mutations) {
patchStyles()
}).observe(document.body, { childList: true, subtree: true });
} else {
var patch = function(){
patchStyles()
if(document.querySelector('[class^=container-]')) { return }
requestAnimationFrame(patch)
}
requestAnimationFrame(patch)
}
}
if (document.body) {
setupObserver()
} else {
document.addEventListener('DOMContentLoaded', setupObserver)
}
function patchStyles(){
var currentNode
var tags = {}
var iterator =
document
.createNodeIterator(document.documentElement, NodeFilter.SHOW_ELEMENT)
var nextStyles = {}
while(currentNode = iterator.nextNode()) {
if (!currentNode.__styles) { continue }
if (nextStyles[currentNode.__styles.id]) { continue }
nextStyles[currentNode.__styles.id] = currentNode.__styles.value
}
for(var id in nextStyles) {
if(currentStyles[id]) {
nextStyles[id] = currentStyles[id]
delete currentStyles[id]
} else {
var style = document.createElement('style')
style.innerHTML = nextStyles[id]
style.setAttribute('id', id)
document.head.appendChild(style)
nextStyles[id] = style
}
}
for(var id in currentStyles) {
currentStyles[id].remove()
}
currentStyles = nextStyles
}
/* Interface */
return {
patchStyles: patchStyles
}
}()