mirror of https://github.com/vizality/vizality
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
786 B
26 lines
786 B
@use 'str-replace' as *;
|
|
|
|
// Function to create an optimized svg url
|
|
@function svg-uri($svg){
|
|
@if ($svg == null) {
|
|
@return null;
|
|
}
|
|
// Chunk up string in order to avoid "SystemStackError: stack level too deep"
|
|
$encoded:'';
|
|
$slice: 2000;
|
|
$index: 0;
|
|
$loops: ceil(str-length($svg)/$slice);
|
|
@for $i from 1 through $loops {
|
|
$chunk: str-slice($svg, $index, $index + $slice - 1);
|
|
$chunk: str-replace($chunk,'"','\'');
|
|
$chunk: str-replace($chunk,'<','%3C');
|
|
$chunk: str-replace($chunk,'>','%3E');
|
|
$chunk: str-replace($chunk,'&','%26');
|
|
$chunk: str-replace($chunk,'#','%23');
|
|
$chunk: str-replace($chunk,"\A", "");
|
|
$encoded: #{$encoded}#{$chunk};
|
|
$index: $index + $slice;
|
|
}
|
|
@return url("data:image/svg+xml;charset=utf8,#{$encoded}");
|
|
}
|