• Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CSS superellipse masks using the Houdini API

Smooth Corners

npm npm bundlephobia

checks devDeps sponsor

Superellipse masks using the CSS Houdini API

Static demo of Smooth Corners

Demo

Live demo featuring several different --smooth-corners values and an interactive editor

Limitations

To avoid leaking visited sites, the CSS Paint API is disabled on Chromium-based browsers for <a> elements with an href attribute and all children of that element. For further details see the following:

To work around this limitation, mask-image: paint(smooth-corners) can be applied to the parent element of the <a> element, for example:

<div style='mask-image: paint(smooth-corners)'>
  <a href='https://github.com/wopian/smooth-corners'>Smooth Corners</a>
</div>

Usage

CSS

Add mask-image: paint(smooth-corners) to the elements you want to mask

Default (Squircle)

.squircle {
  mask-image: paint(smooth-corners);
  -webkit-mask-image: paint(smooth-corners);
  background: #d01257; /* So you can see it */
}

Customise Curvature

You can customise the mask curvature by using a CSS variable. This can be scoped locally to the selector or defined globally in :root {}

--smooth-corners: X[, Y]

  • X - Float, Curvature of the X axis
  • Y - Float, Curvature of the Y axis (optional, defaults to X axis)
Shapes by X value
  • 0.6 - Astroid
  • < 1 - Concave rhombus
  • = 1 - Rhombus
  • > 1 and < 2 - Convex rhombus
  • = 2 - Circle
  • > 2 - Rounded rectangles
  • 2.6 - KakaoTalk profile icon
  • 4.0 - Squircle
  • 5.0 - iOS app icon
Example
.mask {
  --smooth-corners: 3;
  mask-image: paint(smooth-corners);
  -webkit-mask-image: paint(smooth-corners);
  background: #d01257; /* So you can see it */

Registering the Paint Worklet

Register the Paint Worklet to the distributed path of paint.js.

Register with a CDN (preferred)

Use any CDN that serves packages from the NPM registry, for example:

<script>
  if (CSS && 'paintWorklet' in CSS) CSS.paintWorklet.addModule('https://unpkg.com/smooth-corners')
</script>

Register with a file path

Download paint.js or install with npm install smooth-corners

// src/assets/paint.js
import 'smooth-corners' // ES Modules
// src/assets/paint.js
require('smooth-corners') // CommonJS

Like Web Workers, the Paint Worklet API requests the module path in the browser during runtime and must be a seperate entryfile. This is not the path to the source code location.

<script>
  if (CSS && 'paintWorklet' in CSS) CSS.paintWorklet.addModule('/assets/paint.js')
</script>

Result

2 examples: A rounded pink square and a pink squircle

More Repositories

1

kitsu

๐ŸฆŠ A simple, lightweight & framework agnostic JSON:API client
JavaScript
270
star
2

hibari

๐ŸฆŠ Vue app for Kitsu
Vue
26
star
3

kitsu-season-trends

๐ŸฆŠ Kitsu seasonal anime trends
JavaScript
21
star
4

mpv-config

โš™๏ธ Personal mpv configuration
Lua
16
star
5

preferred-locale

๐ŸŽŒ Get a users' preferred locale/language from your app's available translations
TypeScript
16
star
6

agc-assembly

โ˜„๏ธ VS Code syntax highlighting for Apollo Guidance Computer source code
TypeScript
14
star
7

kitsu-inactivity-pruner

๐ŸฆŠ Prune your inactive Kitsu follows
JavaScript
9
star
8

tracker-killer

๐Ÿ’‰ Library performance tester for media tracking sites
JavaScript
7
star
9

wopian.me

๐ŸŒ Homepage for my projects and open source contributions
Pug
7
star
10

kitsu-anime-by-scores

๐ŸฆŠ Kitsu anime by scores
JavaScript
5
star
11

kitsu-season-grabber

๐ŸฆŠ Grab seasonal shows using Kitsu
JavaScript
3
star
12

zeepkist-records

Zeepkist World Records
Vue
2
star
13

eslint-config-wopian

โš™๏ธ Standard ESLint Config for my projects
JavaScript
2
star
14

zeepkist-bot

Discord Bot for displaying Zeepkist records
TypeScript
2
star
15

jest-reporter-github-annotations

JavaScript
2
star
16

kitsu-popular-grabber

๐ŸฆŠ Grab the most popular titles on Kitsu
JavaScript
2
star
17

amoled-quasi-deepin-dark

Pure black colour scheme for Deepin Plasma/GTK themes
1
star
18

kitsu-missing-enddates

๐ŸฆŠ CLI tool to aid with database maintenance
JavaScript
1
star
19

latex-bnu

LaTeX Report Document Class
TeX
1
star
20

conventional-changelog-angular-all-2

JavaScript
1
star
21

base-65503

๐Ÿ“ฆ Base 65503 encoder & decoder
JavaScript
1
star
22

kitsu-post-bumper

๐ŸฆŠ Bump posts on Kitsu
JavaScript
1
star
23

cmder-tinacious-design

๐Ÿšฅ Tinacious Design theme for Cmder
1
star