-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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(): gradient transform + rm workarounds #9359
Draft
ShaMan123
wants to merge
14
commits into
master
Choose a base branch
from
fix-gradient
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
49c7682
use exisiting DOM API + math
ShaMan123 f2df473
offset
ShaMan123 0574c3d
correction
ShaMan123 30e2590
gradientTransform
ShaMan123 8e394b1
test
ShaMan123 4852712
update CHANGELOG.md
github-actions[bot] 08ebe26
update node template
ShaMan123 7db3da4
cleanup
ShaMan123 297bdb1
cleaner template
ShaMan123 ea66356
cleanup
ShaMan123 581bd25
Update index.node.ts
ShaMan123 9ae9bc3
more cleanup
ShaMan123 cdbe7a6
radial percentage
ShaMan123 5a5c38e
Update Gradient.ts
ShaMan123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,61 @@ | ||
/** | ||
* Runs from both the browser and node | ||
*/ | ||
|
||
export function render( | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports | ||
fabric: typeof import('fabric'), | ||
{ type, el }: { type: 'text' | 'rect'; el?: HTMLCanvasElement } | ||
) { | ||
const targets = new Array(8).fill(0).map((_, index) => { | ||
const angle = index * 45; | ||
const gradient = new fabric.Gradient({ | ||
coords: { | ||
x1: 0, | ||
y1: 0, | ||
x2: 1, | ||
y2: 1, | ||
}, | ||
gradientUnits: 'percentage', | ||
// offsetX: 150, | ||
gradientTransform: fabric.util.createRotateMatrix({ angle }), | ||
colorStops: [ | ||
{ | ||
offset: 0, | ||
color: 'red', | ||
}, | ||
{ | ||
offset: 1, | ||
color: 'blue', | ||
}, | ||
], | ||
}); | ||
|
||
return type === 'text' | ||
? new fabric.Text(`Gradient\n${angle}°`, { | ||
fontSize: 50, | ||
fontWeight: 'bold', | ||
fill: gradient, | ||
left: (index % 4) * 250, | ||
top: Math.floor(index / 4) * 250, | ||
}) | ||
: new fabric.Rect({ | ||
width: 150, | ||
height: 150, | ||
fill: gradient, | ||
left: (index % 4) * 250, | ||
top: Math.floor(index / 4) * 250, | ||
}); | ||
}); | ||
|
||
const canvas = new fabric.StaticCanvas(el, { | ||
width: 1000, | ||
height: 400, | ||
backgroundColor: 'white', | ||
enableRetinaScaling: false, | ||
}); | ||
canvas.add(...targets); | ||
canvas.renderAll(); | ||
|
||
return { canvas }; | ||
} |
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,36 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import type { StaticCanvas } from 'fabric/node'; | ||
import setup from '../../setup'; | ||
import { CanvasUtil } from '../../utils/CanvasUtil'; | ||
import { render } from './common'; | ||
|
||
for (const type of ['rect', 'text'] as const) { | ||
test.describe(`Gradient transform on ${type}`, () => { | ||
setup(() => ({ type })); | ||
test('Gradient transform', async ({ page }, config) => { | ||
await test.step('browser', async () => { | ||
expect( | ||
await new CanvasUtil(page).screenshot({ element: 'main' }), | ||
'browser snapshot' | ||
).toMatchSnapshot({ | ||
name: `${type}.png`, | ||
maxDiffPixelRatio: 0.05, | ||
}); | ||
}); | ||
|
||
await test.step('node', async () => { | ||
// we want the browser snapshot of a test to be committed and not the node snapshot | ||
config.config.updateSnapshots = 'none'; | ||
expect( | ||
( | ||
(await render(await import('../../..'), { type })) | ||
.canvas as StaticCanvas | ||
) | ||
.getNodeCanvas() | ||
.toBuffer(), | ||
'node snapshot should match browser snapshot' | ||
).toMatchSnapshot({ name: `${type}.png`, maxDiffPixelRatio: 0.05 }); | ||
}); | ||
}); | ||
}); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,11 @@ | ||
/** | ||
* Runs in the **BROWSER** | ||
*/ | ||
|
||
import * as fabric from 'fabric'; | ||
import { before } from '../test'; | ||
import { render } from './common'; | ||
|
||
before('#canvas', async (el) => | ||
render(fabric, { ...(await testConfig()), el }) | ||
); |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved canas init to the common method