git.iko.soy/typeable/elm-ui
on cc9b2ac help sign in
98 lines 2.2 kB history raw
1(function () {
2 var ruleCache = new Set()
4 function createStyleNode() {
6 const node = document.createElement('style')
7 // Without it, IE will have a broken source order specificity if we
8 // insert rules after we insert the style tag.
9 // It seems to kick-off the source order specificity algorithm.
10 node.textContent = '\n'
11 document.head.appendChild(node);
12 return node
13 }
16 var staticSheet = createStyleNode();
17 var sheet = createStyleNode().sheet;
21 function sync_static(newStyleString) {
22 staticSheet.textContent = newStyleString
23 }
25 function sync(newStyles) {
26 Object.keys(newStyles).forEach((key) => {
27 if (!ruleCache.has(key)) {
28 const newRule = newStyles[key]
29 for (var i = 0; i < newRule.length; i++) {
30 sheet.insertRule(newRule[i])
31 }
33 ruleCache.add(key)
34 }
35 });
36 }
38 class CssRulesNode extends HTMLElement {
39 constructor() {
40 var self = super();
41 }
42 connectedCallback() {
43 sync(this.rulesPayload)
44 }
45 set rules(rules) {
46 console.log("set rules")
47 console.log(rules)
48 if (self.rulesPayload) {
49 console.log(self.rulesPayload)
50 }
51 this._rules = rules;
52 console.log(this._rules)
53 }
54 attributeChangedCallback(attrName, oldVal, newVal) {
55 console.log(attrName, oldVal, newVal)
56 }
57 }
58 customElements.define('elm-ui-rules', CssRulesNode);
62 class CssStaticRulesNode extends HTMLElement {
63 constructor() {
64 var self = super();
65 this._rules = null;
66 }
67 connectedCallback() {
68 // console.log("static connected")
69 // console.log(this)
70 // if (this._rules) {
71 // sync_static(this._rules)
72 // }
73 }
74 set rules(rules) {
75 this._rules = rules
76 sync_static(this._rules)
77 // console.log("set static rules")
78 // console.log(rules)
79 }
81 attributeChangedCallback(attrName, oldVal, newVal) {
82 console.log("attribute cng")
83 console.log(attrName)
84 if (attrName == "rules") {
85 sync_static(newVal)
86 }
87 }
88 }
89 customElements.define('elm-ui-static-rules', CssStaticRulesNode);
98}())