git.iko.soy/typeable/elm-ui
on d2934da help sign in
95 lines 2.1 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 sheet.insertRule(newRule)
30 ruleCache.add(key)
31 }
32 });
33 }
35 class CssRulesNode extends HTMLElement {
36 constructor() {
37 var self = super();
38 }
39 connectedCallback() {
40 sync(this.rulesPayload)
41 }
42 set rules(rules) {
43 console.log("set rules")
44 console.log(rules)
45 if (self.rulesPayload) {
46 console.log(self.rulesPayload)
47 }
48 this._rules = rules;
49 console.log(this._rules)
50 }
51 attributeChangedCallback(attrName, oldVal, newVal) {
52 console.log(attrName, oldVal, newVal)
53 }
54 }
55 customElements.define('elm-ui-rules', CssRulesNode);
59 class CssStaticRulesNode extends HTMLElement {
60 constructor() {
61 var self = super();
62 this._rules = null;
63 }
64 connectedCallback() {
65 // console.log("static connected")
66 // console.log(this)
67 // if (this._rules) {
68 // sync_static(this._rules)
69 // }
70 }
71 set rules(rules) {
72 this._rules = rules
73 sync_static(this._rules)
74 // console.log("set static rules")
75 // console.log(rules)
76 }
78 attributeChangedCallback(attrName, oldVal, newVal) {
79 console.log("attribute cng")
80 console.log(attrName)
81 if (attrName == "rules") {
82 sync_static(newVal)
83 }
84 }
85 }
86 customElements.define('elm-ui-static-rules', CssStaticRulesNode);
95}())