-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Nothing has changed here, just forcing a new major so semantic-release doesn't step on old 1.0.x releases
- Loading branch information
Showing
1 changed file
with
30 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
class SmoothCornersPainter { | ||
static get inputProperties() { | ||
return ['--smooth-corners']; | ||
return ['--smooth-corners'] | ||
} | ||
|
||
superellipse(a, b, nX = 4, nY) { | ||
if (Number.isNaN(nX)) nX = 4; | ||
if (typeof nY === 'undefined' || Number.isNaN(nY)) nY = nX; | ||
if (nX > 100) nX = 100; | ||
if (nY > 100) nY = 100; | ||
if (nX < 0.00000000001) nX = 0.00000000001; | ||
if (nY < 0.00000000001) nY = 0.00000000001; | ||
|
||
const nX2 = 2 / nX; | ||
const nY2 = nY ? 2 / nY : nX2; | ||
const steps = 360; | ||
const step = (2 * Math.PI) / steps; | ||
if (Number.isNaN(nX)) nX = 4 | ||
if (typeof nY === 'undefined' || Number.isNaN(nY)) nY = nX | ||
if (nX > 100) nX = 100 | ||
if (nY > 100) nY = 100 | ||
if (nX < 0.00000000001) nX = 0.00000000001 | ||
if (nY < 0.00000000001) nY = 0.00000000001 | ||
|
||
const nX2 = 2 / nX | ||
const nY2 = nY ? 2 / nY : nX2 | ||
const steps = 360 | ||
const step = (2 * Math.PI) / steps | ||
const points = t => { | ||
const cosT = Math.cos(t); | ||
const sinT = Math.sin(t); | ||
const cosT = Math.cos(t) | ||
const sinT = Math.sin(t) | ||
return { | ||
x: Math.abs(cosT) ** nX2 * a * Math.sign(cosT), | ||
y: Math.abs(sinT) ** nY2 * b * Math.sign(sinT) | ||
}; | ||
}; | ||
return Array.from({ length: steps }, (_, i) => points(i * step)); | ||
} | ||
} | ||
return Array.from({ length: steps }, (_, i) => points(i * step)) | ||
} | ||
|
||
paint(ctx, geom, properties) { | ||
const [nX, nY] = properties | ||
.get('--smooth-corners') | ||
.toString() | ||
.replace(/ /g, '') | ||
.split(','); | ||
.split(',') | ||
|
||
const width = geom.width / 2; | ||
const height = geom.height / 2; | ||
const width = geom.width / 2 | ||
const height = geom.height / 2 | ||
const smooth = this.superellipse( | ||
width, | ||
height, | ||
parseFloat(nX), | ||
parseFloat(nY) | ||
); | ||
) | ||
|
||
ctx.fillStyle = '#000'; | ||
ctx.setTransform(1, 0, 0, 1, width, height); | ||
ctx.beginPath(); | ||
ctx.fillStyle = '#000' | ||
ctx.setTransform(1, 0, 0, 1, width, height) | ||
ctx.beginPath() | ||
|
||
for (let i = 0; i < smooth.length; i++) { | ||
const { x, y } = smooth[i]; | ||
if (i === 0) ctx.moveTo(x, y); | ||
else ctx.lineTo(x, y); | ||
const { x, y } = smooth[i] | ||
if (i === 0) ctx.moveTo(x, y) | ||
else ctx.lineTo(x, y) | ||
} | ||
|
||
ctx.closePath(); | ||
ctx.fill(); | ||
ctx.closePath() | ||
ctx.fill() | ||
} | ||
} | ||
|
||
// eslint-disable-next-line no-undef | ||
registerPaint('smooth-corners', SmoothCornersPainter); | ||
registerPaint('smooth-corners', SmoothCornersPainter) |