Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom linear gradient angles #3109

Merged
merged 13 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: further lint errors
macintoshhelper committed Oct 15, 2024
commit b3cf758e105b77bb3d1e243758494d8437dc214a
Original file line number Diff line number Diff line change
@@ -205,7 +205,7 @@ describe('convertStringtoFigmaGradient', () => {
r: 1,
g: 0,
b: 0,
a: 1
a: 1,
},
position: 0.056100000000000004,
},
Original file line number Diff line number Diff line change
@@ -20,9 +20,10 @@ export function convertFigmaGradientToString(paint: GradientPaint) {
const roundToPrecision = (value, precision = 10) => {
const roundToPrecisionVal = 10 ** precision;
return Math.round((value + Number.EPSILON) * roundToPrecisionVal) / roundToPrecisionVal;
}
};

export function convertStringToFigmaGradient(value: string/*, node?: BaseNode | PaintStyle*/) {
// if node type check is needed due to bugs caused by obscure node types, use (value: string/*, node?: BaseNode | PaintStyle) and convertStringToFigmaGradient(value, target)
export function convertStringToFigmaGradient(value: string) {
const parts = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(', ').map(s => s.trim());

// Default angle is to top (180 degrees)
@@ -84,7 +85,7 @@ export function convertStringToFigmaGradient(value: string/*, node?: BaseNode |
scale = normalisedCos;
// Implement fallback if bugs are caused by obscure node types. This appears to be unnecessary
// if (!['RECTANGLE', 'FRAME', 'VECTOR'].includes(node?.type || '')) {
// // Old scale computation:
// // Old scale computation:
// scale = angle % 90 === 0 ? 1 : Math.sqrt(1 + Math.tan(angle * (Math.PI / 180)) ** 2);
// }