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

refactor: gradient & support more degree unit #624

Merged
merged 4 commits into from
Jul 4, 2024

Conversation

Jackie1210
Copy link
Contributor

I am working on implementing repeating-linear-gradient, but I think we should refactor logic here at first for future.

  • I made a lib css-gradient-parser since vendor we currently use is lack of tests and really hard to read and debug.
  • support turn, rad, grad in linear-gradient

Fix #581 (comment)
Fix #581 (comment)

@Jackie1210 Jackie1210 requested a review from shuding as a code owner June 22, 2024 03:40
Copy link

vercel bot commented Jun 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
satori-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2024 3:41am

Copy link
Member

@shuding shuding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 😊

@shuding shuding merged commit fe2534a into vercel:main Jul 4, 2024
9 checks passed
@Jackie1210 Jackie1210 deleted the refactor/gradient branch July 4, 2024 14:48
shuding pushed a commit that referenced this pull request Sep 14, 2024
Now that #624 has been merged, let me bring`repeating-linear-gradient`
to satori~ ❤️

Close #554

Note about the algorithm:
<hr>

Option 1: `0 < deg < 90`

define

```math
r=(h/w)^2
```
then, calculate the intersection point of the last two lines
```math
y = - r / tan(angle) ·x + w / 2  + h/2+r·w/ (2·tan(angle))
```
```math
y=tan(angle) ·x + h
```
Finally, we can get `(x1, y1)`, `(x2, y2)`

about length:
```math
y = - 1 / tan(angle) ·x + w / 2  + h/2+r·w/ (2·tan(angle))
```
```math
y=tan(angle) ·x + h
```

then, we can get a point: `(a, b)`, so length is $`2 ·\sqrt{(a - w/2)^2
+ (b - h/2)^2}`$

<hr>

Option 2: `90 < deg < 180`

define

```math
r=(h/w)^2
```
then, calculate the intersection point of the last two lines
```math
y = - r / tan(angle) ·x + w / 2  + h/2+r·w/ (2·tan(angle))
```
```math
y=tan(angle) ·x
```
Finally, we can get `(x1, y1)`, `(x2, y2)`

about length:
```math
y = - 1 / tan(angle) ·x + w / 2  + h/2+r·w/ (2·tan(angle))
```
```math
y=tan(angle) ·x
```

then, we can get a point: `(a, b)`, so length is $`2 ·\sqrt{(a - w/2)^2
+ (b - h/2)^2}`$

Actually, I didn't find any spec of the algorithm on calculating the
points. I just came across the algorithm accidentally. It turns out it
shows the same result just like chrome renders.
Copy link

🎉 This PR is included in version 0.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error with linear-gradient
2 participants