From d76556f3ad46aee3483ece2d879e26a88d321d5a Mon Sep 17 00:00:00 2001 From: Tobias Buschor Date: Fri, 29 May 2020 10:53:10 +0200 Subject: [PATCH 1/2] runtimeStyle performance! --- ie11CustomProperties.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ie11CustomProperties.js b/ie11CustomProperties.js index a632a44..bb73bc4 100644 --- a/ie11CustomProperties.js +++ b/ie11CustomProperties.js @@ -84,6 +84,9 @@ if (!('innerHTML' in Element.prototype)) { copyProperty('innerHTML', HTMLElement.prototype, Element.prototype); } + if (!('runtimeStyle' in Element.prototype)) { // new + copyProperty('runtimeStyle', HTMLElement.prototype, Element.prototype); + } if (!('sheet' in SVGStyleElement.prototype)) { Object.defineProperty(SVGStyleElement.prototype, 'sheet', { get:function(){ @@ -412,6 +415,9 @@ } var style = getComputedStyle(el); let css = ''; + + el.runtimeStyle.cssText = ''; // new + for (var prop in el.ieCPSelectors) { var important = style['-ieVar-❗' + prop]; let valueWithVar = important || style['-ieVar-' + prop]; @@ -428,10 +434,11 @@ // beta if (!important && details.allByRoot !== false) continue; // dont have to draw root-properties - //let selector = item.selector.replace(/>? \.[^ ]+/, ' ', item.selector); // todo: try to equalize specificity - let selector = item.selector; - css += selector + '.iecp-u' + el.ieCP_unique + item.pseudo + '{' + prop + ':' + value + '}\n'; - // el.runtimeStyle[prop] = value; // todo + if (item.pseudo) { + css += item.selector + '.iecp-u' + el.ieCP_unique + item.pseudo + '{' + prop + ':' + value + '}\n'; + } else { + el.runtimeStyle[prop] = value; // new + } } } } From 7c541eaa84be9492e32b2cdaacda4cee9d6c9ccd Mon Sep 17 00:00:00 2001 From: Tobias Buschor Date: Tue, 9 Jun 2020 23:43:35 +0200 Subject: [PATCH 2/2] add tests --- tests/performance.html | 6 ++-- tests/tests.html | 77 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/tests/performance.html b/tests/performance.html index 4511881..23b2e45 100644 --- a/tests/performance.html +++ b/tests/performance.html @@ -32,7 +32,7 @@ var html = '
'; html += '

no vars

'; html += ''; - for (var i=0; i<500;i++) { + for (var i=0; i<1000;i++) { html += 'x '; } html += 'x '; @@ -55,7 +55,7 @@ var html = '
'; html += '

getting root vars

'; html += ''; - for (var i=0; i<500;i++) { + for (var i=0; i<1000;i++) { html += 'x '; } html += 'x '; @@ -78,7 +78,7 @@ var html = '
'; html += '

getting non-root vars

'; html += ''; - for (var i=0; i<500;i++) { + for (var i=0; i<1000;i++) { html += 'x '; } html += 'x '; diff --git a/tests/tests.html b/tests/tests.html index dfe130a..8ddcc9b 100644 --- a/tests/tests.html +++ b/tests/tests.html @@ -14,6 +14,7 @@ } body { --body-green:green; + --body-red:red; } .tests > * { color:#fff; @@ -467,7 +468,7 @@
- specificity: CP will not overwrite #id + specificity: .CP-getter will not overwrite #id
                 #specificity_id {
@@ -481,7 +482,7 @@
     
- specificity: CP will not overwrite .class.class + specificity: .CP-getter will not overwrite .class.class
                 .specificity_class.specificity_class {
@@ -494,24 +495,80 @@
         
+
+ specificity: #CP-getter will not overwrite !important +
+
+                .specificity_imortant {
+                   background-color:green !important;
+                }
+                #specificity_imortant {
+                    background-color:var(--red);
+                }
+            
+
+
+
+ specificity: CP-getter before not overwrites same selector after +
+
+                .specificity_cp_before {
+                    background-color:var(--red);
+                }
+                .specificity_cp_before {
+                    background-color:green;
+                }
+            
+
+
- +
+ + +