Is it possible to retrieve the browsers default value for a CSS property, ignoring any inline/imported styles, using JS?
Some context: I'm using JS to in-line all styles on a specific SVG element and its children (which allows me to turn it into a PNG using canvg). At the moment my output is hugely bloated with every single available style, I would like to be able to discard any properties which are using the browser default values from the array of styles that are include in-line.
Demo of what's happening:
$.extend($.fn, {
makeCssInline: function() {
this.each(function(idx, el) {
var style = el.style;
var properties = [];
for (var property in style) {
if ($(this).css(property)) {
// TODO: Only in-line this style if it's not browser default
properties.push(property + ':' + $(this).css(property));
}
}
this.style.cssText = properties.join(';');
$(this).children().makeCssInline();
});
}
});
$(document).ready(function() {
$("#before").text($("svg")[0].outerHTML.length);
$("svg").makeCssInline();
$("#after").text($("svg")[0].outerHTML.length);
});
svg circle {
fill: #080;
}
svg text {
fill: #FFF;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg version="1.1" baseProfile="full" width="300" height="100" xmlns="http://www.w3.org/2000/svg">
<circle cx="150" cy="50" r="50" />
<text x="150" y="65" font-size="40" text-anchor="middle">SVG</text>
</svg>
<p>Total characters before in-lining styles: <span id="before"></span></p>
<p>Total characters after in-lining styles: <span id="after"></span></p>
As you can see, even for a simple SVG this process adds a huge amount of unnecessary data.