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

borderline

v0.0.3

Published

A React component for drawing borders around groups of elements

Downloads

33

Readme

Borderline

⚠️ Early Testing Phase - Probably Broken ⚠️

A React component for drawing borders around groups of elements

Inverted corners are hard. Have you ever wanted to do this?

Three uneven divs with a border around them

Good Luck! 😅

Until now... Check this out:

Three uneven divs with a border around them, animated gif

😎

Installation

npm install borderline

Usage

import Borderline from 'borderline';

function App() {
  return (
    <>
      <Borderline>
        <div>One</div>
        <div>Two</div>
        <div>Three</div>
      </Borderline>
    </>
  );	
}

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | pathRadius | number | 2 | The radius of the borderline | | pathStroke | string | "black" | The color of the borderline | | pathFill | string | "transparent" | The color of the fill of the borderline shape | | cornerRadius | number | 20 | The radius of the corners of the elements | | controlRatio | number | 0.551915 | The ratio of the control points for the bezier curves. The default point approximates a circle. | | sharpTopLeftCorner | boolean | false | Make the top left corner sharp | | sharpTopRightCorner | boolean | false | Make the top right corner sharp | | sharpBottomLeftCorner | boolean | false | Make the bottom left corner sharp | | sharpBottomRightCorner | boolean | false | Make the bottom right corner sharp |

Development Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | skipSmallLedges | boolean | false | Skip small ledges when traversing the elements | | roundedPoints | boolean | true | Round the points to the nearest integer |

How it works

The algorithm is pretty simple, it is the same one that those toy robot line-followers use:

  1. Find all the elements that are direct children of the Borderline component
  2. For each bounding box, create vectors between the corners in a clockwise direction
  3. Start at the top left corner and begin following the vectors
  4. At each endpoint, try to turn left, continue straight, or turn right, in that order.
  5. Continue until you reach the starting point.
  6. Calculate the midpoints, anchor points, and control points for the SVG path.
  7. Draw the path. Done!

There are some finer details, like how to avoid hopping over nontraversable gaps and such, but that's basically it.

Another approach would be a hull algorithm, but they do not handle concavity well and do not take advantage of the fact that we know the elements are rectangles.

Caveats

  • The elements must be rectangles
  • The only elements that are counted ane the direct children of the Borderline component
  • The elements must not overlap
  • There is some lag, because it needs to wait for the elements to render before calculating the path
  • The algorithm is not optimized and could be faster. If I use it enough, I might have to rewrite it.
  • It generally kinda seems like overkill to create a traversal vectorspace and fire a whole pathfinding algorithm every frame that changes. Such is the price of beauty, I suppose.

TODO:

  • [ ] Smooth out skipping small ledges
  • [ ] Break apart the algorithm into smaller functions
  • [ ] Optimize the algorithm
  • [ ] Fix corners to use the path corners instead of the element corners
  • [ ] Add tests
  • [ ] Add examples
  • [ ] Support overlapping divs
  • [ ] Support multiple borders for disconnected groups within the same element
  • [ ] TailwindCSS plugin component
  • [ ] Add support for different border styles
  • [ ] Figure out why the package is so big