All Projects → wopian → smooth-corners

wopian / smooth-corners

Licence: MIT license
CSS superellipse masks using the Houdini API

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to smooth-corners

react-native-super-ellipse-mask
Apple flavored smooth corners for React Native
Stars: ✭ 55 (-58.65%)
Mutual labels:  superellipse, squircle, smooth-corners
squircle-houdini-css
A tiny CSS Houdini module that allows to add a squircle shape to HTML elements
Stars: ✭ 104 (-21.8%)
Mutual labels:  houdini, squircle
whot
A Game API for the Nigerian Whot Card Game. https://github.com/mykeels/whot-server, https://github.com/CodeByOmar/whot-app
Stars: ✭ 51 (-61.65%)
Mutual labels:  square, circle
interpolations
Lightweight Unity library for smoothing movements and value progressions in code (dragging, easing, tweening).
Stars: ✭ 29 (-78.2%)
Mutual labels:  smoothing, curve-interpolation
discrete frechet
Compute the Fréchet distance between two polygonal curves in Euclidean space.
Stars: ✭ 68 (-48.87%)
Mutual labels:  curve, smoothing
flagpack
A lightweight flag icon toolkit for the web.
Stars: ✭ 51 (-61.65%)
Mutual labels:  square, rectangle
react-native-tcharts
基于React Native ART的图表组件库
Stars: ✭ 25 (-81.2%)
Mutual labels:  circle, ellipse
SquareImageView
SquareImageView is a simple wrapper library for Android ImageView
Stars: ✭ 28 (-78.95%)
Mutual labels:  square, rectangle
react-native-square-reader-sdk
React Native Plugin for Square Reader SDK
Stars: ✭ 94 (-29.32%)
Mutual labels:  square
Core
The contents of this repository have been integrated into https://github.com/SixLabors/ImageSharp
Stars: ✭ 26 (-80.45%)
Mutual labels:  rectangle
NumPad
Number Pad (inspired by Square)
Stars: ✭ 81 (-39.1%)
Mutual labels:  square
diamond
Dependency management built for Sass, Less, and CSS.
Stars: ✭ 19 (-85.71%)
Mutual labels:  diamond
AnimationDNA
Maya > Arnold > Nuke pipeline
Stars: ✭ 101 (-24.06%)
Mutual labels:  houdini
LEAmountInputView
Amount Input View (inspired by Square's design)
Stars: ✭ 44 (-66.92%)
Mutual labels:  square
payment-fields
React component for Braintree/Stripe/Square payment fields
Stars: ✭ 17 (-87.22%)
Mutual labels:  square
SquaresLoadingView
A SquaresLoadingView based on android.View, nicely rotation、easy to use.
Stars: ✭ 26 (-80.45%)
Mutual labels:  square
hpaste
simple plain text snippet exchange for Houdini
Stars: ✭ 79 (-40.6%)
Mutual labels:  houdini
LINE-Source
Line Application Source
Stars: ✭ 43 (-67.67%)
Mutual labels:  square
texture-synthesis-houdini
🎨 Houdini / PDG Plugin for Embark Studios' Example-based texture synthesis
Stars: ✭ 91 (-31.58%)
Mutual labels:  houdini
Interactive Data Editor
A Software to interactively edit data in a graphical manner
Stars: ✭ 35 (-73.68%)
Mutual labels:  smoothing

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].