-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from Axis-Fi/liv-svg
SVG representation for Linear Vesting
- Loading branch information
Showing
19 changed files
with
2,336 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.12; | ||
|
||
// hot-chain-svg: https://github.com/w1nt3r-eth/hot-chain-svg | ||
|
||
// Core utils used extensively to format CSS and numbers. | ||
library utils { | ||
// used to simulate empty strings | ||
string internal constant NULL = ""; | ||
|
||
// formats a CSS variable line. includes a semicolon for formatting. | ||
function setCssVar( | ||
string memory _key, | ||
string memory _val | ||
) internal pure returns (string memory) { | ||
return string.concat("--", _key, ":", _val, ";"); | ||
} | ||
|
||
// formats getting a css variable | ||
function getCssVar(string memory _key) internal pure returns (string memory) { | ||
return string.concat("var(--", _key, ")"); | ||
} | ||
|
||
// formats getting a def URL | ||
function getDefURL(string memory _id) internal pure returns (string memory) { | ||
return string.concat("url(#", _id, ")"); | ||
} | ||
|
||
// formats rgba white with a specified opacity / alpha | ||
function white_a(uint256 _a) internal pure returns (string memory) { | ||
return rgba(255, 255, 255, _a); | ||
} | ||
|
||
// formats rgba black with a specified opacity / alpha | ||
function black_a(uint256 _a) internal pure returns (string memory) { | ||
return rgba(0, 0, 0, _a); | ||
} | ||
|
||
// formats generic rgba color in css | ||
function rgba( | ||
uint256 _r, | ||
uint256 _g, | ||
uint256 _b, | ||
uint256 _a | ||
) internal pure returns (string memory) { | ||
string memory formattedA = _a < 100 ? string.concat("0.", utils.uint2str(_a)) : "1"; | ||
return string.concat( | ||
"rgba(", | ||
utils.uint2str(_r), | ||
",", | ||
utils.uint2str(_g), | ||
",", | ||
utils.uint2str(_b), | ||
",", | ||
formattedA, | ||
")" | ||
); | ||
} | ||
|
||
// checks if two strings are equal | ||
function stringsEqual(string memory _a, string memory _b) internal pure returns (bool) { | ||
return keccak256(abi.encodePacked(_a)) == keccak256(abi.encodePacked(_b)); | ||
} | ||
|
||
// returns the length of a string in characters | ||
function utfStringLength(string memory _str) internal pure returns (uint256 length) { | ||
uint256 i = 0; | ||
bytes memory string_rep = bytes(_str); | ||
|
||
while (i < string_rep.length) { | ||
if (string_rep[i] >> 7 == 0) { | ||
i += 1; | ||
} else if (string_rep[i] >> 5 == bytes1(uint8(0x6))) { | ||
i += 2; | ||
} else if (string_rep[i] >> 4 == bytes1(uint8(0xE))) { | ||
i += 3; | ||
} else if (string_rep[i] >> 3 == bytes1(uint8(0x1E))) { | ||
i += 4; | ||
} | ||
//For safety | ||
else { | ||
i += 1; | ||
} | ||
|
||
length++; | ||
} | ||
} | ||
|
||
// converts an unsigned integer to a string | ||
function uint2str(uint256 _i) internal pure returns (string memory _uintAsString) { | ||
if (_i == 0) { | ||
return "0"; | ||
} | ||
uint256 j = _i; | ||
uint256 len; | ||
while (j != 0) { | ||
len++; | ||
j /= 10; | ||
} | ||
bytes memory bstr = new bytes(len); | ||
uint256 k = len; | ||
while (_i != 0) { | ||
k = k - 1; | ||
uint8 temp = (48 + uint8(_i - (_i / 10) * 10)); | ||
bytes1 b1 = bytes1(temp); | ||
bstr[k] = b1; | ||
_i /= 10; | ||
} | ||
return string(bstr); | ||
} | ||
} | ||
|
||
// Core SVG utilitiy library which helps us construct | ||
// onchain SVG's with a simple, web-like API. | ||
library svg { | ||
/* MAIN ELEMENTS */ | ||
function g( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("g", _props, _children); | ||
} | ||
|
||
function path( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("path", _props, _children); | ||
} | ||
|
||
function text( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("text", _props, _children); | ||
} | ||
|
||
function line( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("line", _props, _children); | ||
} | ||
|
||
function circle( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("circle", _props, _children); | ||
} | ||
|
||
function circle(string memory _props) internal pure returns (string memory) { | ||
return el("circle", _props); | ||
} | ||
|
||
function ellipse( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("ellipse", _props, _children); | ||
} | ||
|
||
function ellipse(string memory _props) internal pure returns (string memory) { | ||
return el("ellipse", _props); | ||
} | ||
|
||
function rect( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("rect", _props, _children); | ||
} | ||
|
||
function rect(string memory _props) internal pure returns (string memory) { | ||
return el("rect", _props); | ||
} | ||
|
||
function filter( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("filter", _props, _children); | ||
} | ||
|
||
function cdata(string memory _content) internal pure returns (string memory) { | ||
return string.concat("<![CDATA[", _content, "]]>"); | ||
} | ||
|
||
/* GRADIENTS */ | ||
function radialGradient( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("radialGradient", _props, _children); | ||
} | ||
|
||
function linearGradient( | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return el("linearGradient", _props, _children); | ||
} | ||
|
||
function gradientStop( | ||
uint256 offset, | ||
string memory stopColor, | ||
string memory _props | ||
) internal pure returns (string memory) { | ||
return el( | ||
"stop", | ||
string.concat( | ||
prop("stop-color", stopColor), | ||
" ", | ||
prop("offset", string.concat(utils.uint2str(offset), "%")), | ||
" ", | ||
_props | ||
) | ||
); | ||
} | ||
|
||
function animateTransform(string memory _props) internal pure returns (string memory) { | ||
return el("animateTransform", _props); | ||
} | ||
|
||
function image( | ||
string memory _href, | ||
string memory _props | ||
) internal pure returns (string memory) { | ||
return el("image", string.concat(prop("href", _href), " ", _props)); | ||
} | ||
|
||
/* COMMON */ | ||
// A generic element, can be used to construct any SVG (or HTML) element | ||
function el( | ||
string memory _tag, | ||
string memory _props, | ||
string memory _children | ||
) internal pure returns (string memory) { | ||
return string.concat("<", _tag, " ", _props, ">", _children, "</", _tag, ">"); | ||
} | ||
|
||
// A generic element, can be used to construct any SVG (or HTML) element without children | ||
function el(string memory _tag, string memory _props) internal pure returns (string memory) { | ||
return string.concat("<", _tag, " ", _props, "/>"); | ||
} | ||
|
||
// an SVG attribute | ||
function prop(string memory _key, string memory _val) internal pure returns (string memory) { | ||
return string.concat(_key, "=", '"', _val, '" '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.