npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-squircle

v3.0.1

Published

Classes for generating superellipse squircles in the form of SVG strings, to be used in clip-path and background inline styles.

Downloads

114

Readme

html-squircle

html-squircle is a lightweight, framework-agnostic JavaScript package designed to create superellipse squircles (smooth, rounded shapes) that can be used as SVG clip paths or backgrounds for web elements. This package is perfect for developers looking to add modern, beautifully-rounded corners to the web with minimal effort.

Features

  • Generate squircles as SVG strings for use in clip-path or background-image inline styles.
  • Unlike a true superellipse, transitions gracefully into straight edges, making it suitable for UI elements of various sizes.
  • Customizable curve length, curve smoothness, background (solid color or gradient), stroke color, stroke width, and SVG injections to defs or body.
  • Easy to use with any web framework or vanilla JavaScript.
  • Exports React hooks that will cache results across components and sync with the size of an element.

Installation

You can install html-squircle using npm:

npm install html-squircle

Usage

After installing html-squircle, you can import and use it in your project as follows:

import { clipSquircle, backgroundSquircle } from "html-squircle"
import type { SquircleOptionsSVG } from "html-squircle"

const squircleSquare200: SquircleOptionsSVG = {
  width: 200,
  height: 200,
  stroke: "black",
  strokeWidth: 2,
  background: "#ff6347"
}

// Example usage for a clip path
const clipPathStyle = clipSquircle(squircleSquare200)
document.getElementById("yourElementId").style.clipPath = clipPathStyle

// Example usage for a background with a solid color
const backgroundStyle = backgroundSquircle(squircleSquare200)
document.getElementById("anotherElementId").style.backgroundImage =
  backgroundStyle

The default values for curveLength (calculated based on shortest side) and roundness (0.2) will produce shapes exactly like Apple's app icons when the width and height are equal.

For React, useClipSquircle and useBackgroundSquircle are also exported. These accept the usual params, excluding width and height, since those are measured and kept in sync for you. They also accept options including ref for the element to be measured, deps for anything that could cause the rendered element to be removed from or added to the DOM, and cacheCapacity for the size of the LRU cache. For both, there's no need to ensure the input params have stable references. For improved performance, they also memoize the results across components for you automatically.

Tips

When trying to control the sharpness of the curve, first adjust the curveLength parameter. If you're not getting the result you want, then reach for roundness.

The backgroundSquircle function is only really useful if you need to add a stroke to your background (regular CSS border will be clipped if you use clip-path), or if you need to do something else fancy with SVG (see below).

Use the injectedDefs and injectedBody params if you need to do anything custom with the generated background SVG. This must be a string. You can refer to other elements of the SVG in <use /> elements by referring to their ids: #path, #rect, #clip, #mask, #grad. To create xml tag structures easily, you can use the exported tag function. For maximum browser support and to align with the rest of the SVG result, always use single quotes. Your input will be URI-encoded for you, so don't do this yourself.

The values can be partly animated with CSS. The width and height will smoothly transition, but the curves will fade from one definition to the next.