Skip to content

Commit fba85b5

Browse files
fix css linear-gradient deg calculatios
1 parent b9f323d commit fba85b5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

externals/design-sdk

packages/builder-css-styles/linear-gradient/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@ import { color } from "../color";
55
/**
66
* https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient()
77
*
8+
* TODO:
9+
* - [ ] stops support (position)
10+
*
811
* @param g
912
* @returns
1013
*/
1114
export function linearGradient(g: LinearGradientManifest): CSSProperty.Color {
12-
// throw "css gradient not ready";
13-
// TODO:
14-
// 1. stops support
15-
// 2. angle support
16-
var angleDeg =
15+
const angle =
1716
(Math.atan2(g.begin.y - g.end.y, g.begin.x - g.end.x) * 180) / Math.PI;
1817

18+
const gradient_angle =
19+
angle +
20+
// when the rotation value is 0, it means the gradient direction is left to right, which in css, it is 90deg.
21+
// so we have to subtract 90.
22+
// TODO: consider: extract this outside of the styles module?
23+
-90;
24+
1925
const colors = g.colors.map(color).join(", ");
20-
return `linear-gradient(${angleDeg}deg, ${colors})`;
26+
return `linear-gradient(${gradient_angle}deg, ${colors})`;
2127
}

0 commit comments

Comments
 (0)