-
Notifications
You must be signed in to change notification settings - Fork 93
Optionally postprocess inline CSS to SVG attributes #134
Comments
For |
Can you give some examples of what you need? Like input -> output. |
Feature 1: translate inline CSS styles in SVG data into SVG attributesParameters:
Input<svg viewBox='0 0 100 100' xmlns="http://www.w3.org/2000/svg">
<style>
circle {
opacity: 0.5;
}
</style>
<circle id='c1' r="32" cx="35" cy="65" style="fill: #F00;"/>
<circle id='c2' r="32" cx="65" cy="65" style="fill: #0F0;"/>
<circle id='c3' r="32" cx="50" cy="35" style="fill: #00F;"/>
</svg> Output<svg viewBox='0 0 100 100' xmlns="http://www.w3.org/2000/svg">
<circle r="32" cx="35" cy="65" fill="#F00" opacity="0.5"/>
<circle r="32" cx="65" cy="65" fill="#0F0" opacity="0.5"/>
<circle r="32" cx="50" cy="35" fill="#00F" opacity="0.5"/>
</svg> The output SVG data still works outside browsers (perhaps even better than the CSS-styled equivalent?). It also helps to control styling with Feature 2: unbundle SVG file into SVG data and CSS stylesheetParameters:
Input<svg viewBox='0 0 100 100' xmlns="http://www.w3.org/2000/svg">
<circle r="32" cx="35" cy="65" fill="#F00" opacity="0.5"/>
<circle r="32" cx="65" cy="65" fill="#0F0" opacity="0.5"/>
<circle r="32" cx="50" cy="35" fill="#00F" opacity="0.5"/>
</svg> OutputSVG 1.1<?xml version="1.0" standalone="no"?>
<?xml-stylesheet href="svg1.css" type="text/css"?>
<svg id='svg1' viewBox='0 0 100 100' xmlns="http://www.w3.org/2000/svg">
<circle id='c1' r="32" cx="35" cy="65"/>
<circle id='c2' r="32" cx="65" cy="65"/>
<circle id='c3' r="32" cx="50" cy="35"/>
</svg> SVG 2<svg id='svg1' viewBox='0 0 100 100' xmlns="http://www.w3.org/2000/svg">
<link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" href="svg1.css" type="text/css"/>
<circle id='c1' r="32" cx="35" cy="65"/>
<circle id='c2' r="32" cx="65" cy="65"/>
<circle id='c3' r="32" cx="50" cy="35"/>
</svg>
The separate CSS file, still uncompressed in the sample output, can then be processed by specialized tools. Moreover, this helps to control styling with |
|
Alright! 2 would fit ‘cleaning’, but yeah, maybe not optimization per se. |
I see there’s a mistake in the samples for the second feature. For my use case (CSP), I only need to extract all |
Some clarification needed: does it okay to store presentation properties as attributes and not as |
Yes, based on my last comment that would suffice for me. (But not for extracting all presentation as external CSS to do postprocessing on that CSS). So I understand, with |
So again to clarify: you need an option which will extract all presentation attributes to a separated CSS file? |
A separate CSS file would be useful, but not critical (for the CSP use case). |
But this is already implemented. |
This is an exploratory issue, I hope to get everyone’s views on this.
In some contexts, inline CSS limits compatibility of SVG data (e.g., given Web Content Security Policy restrictions, see plotly/plotly.js#2355). As noted in the previously mentioned issue, there exist equivalents of CSS style rules in the form of SVG attributes. Would you find it interesting to add (some amount of; optional) inline CSS -> SVG attributes postprocessing to
svgcleaner
?The text was updated successfully, but these errors were encountered: