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

rgba-hex-to-func

v1.0.1

Published

Converts any rgba hex values to IE11 compliant rgba() functions

Downloads

4

Readme

rgba-hex-to-func

Small Stylis v4 plugin to convert any RGBA Hex values to the rgba() syntax. This is plugin came about from a desire to use charkra-ui with IE11, which does not support the Hex RGBA annotations.

Usage

Defaults:

By default, this plugin supports a set of all potential standard rgba valued properties. It is not exhaustive though, so feel free to contribute missing components.

Raw Stylis V4

import { serialize, compile, middleware, stringify } from 'stylis'
import createRGBAHexToFuncMiddleware from('rgba-hex-to-func';

// create a middleware and apply it to your middleware chain
serialize(compile('.SomeCssClass { color: #ffffffff; }'), middleware([createRGBAHexToFuncMiddleware(), stringify]));

EmotionJS

import createCache from '@emotion/cache'

export const myCache = createCache({
  key: 'my-prefix-key',
  stylisPlugins: [
    createRGBAHexToFuncMiddleware()
  ]
})

Finer Control

Since this plugin is effectively undoing modern CSS for the sake of IE11, a few options are supplied to allow you to minimize the scope at which this plugin in applied.

See __tests__ for examples.

  • cssPropertyMatch - Either a an array of css properties to only look for and transform Hex codes on OR a function that allows you to determine if a property should be looked and an transformed

  • applyWhen - If supplied this function will determine when to attempt to apply this plugin.

    Given the tricky nature of Server Side Rendering and determining if a browser is IE11, this is left as an open-ended problem for the user to solve.

    Note: This means that this plugin will apply to ALL browsers by default - which may be undesired for your use case.

Examples of basic IE11 detection on client-side

Raw Stylis V4

import { serialize, compile, middleware, stringify } from 'stylis'
import createRGBAHexToFuncMiddleware from('rgba-hex-to-func';

// create a middleware and apply it to your middleware chain
serialize(compile('.SomeCssClass { color: #ffffffff; }'), middleware([createRGBAHexToFuncMiddleware({
    applyWhen: () => window !== undefined && !!window.MSInputMethodContext && !!document.documentMode,
}), stringify]));

EmotionJS

import createCache from '@emotion/cache'

export const myCache = createCache({
  key: 'my-prefix-key',
  stylisPlugins: [
    createRGBAHexToFuncMiddleware({
        applyWhen: () => window !== undefined && !!window.MSInputMethodContext && !!document.documentMode,
    }),
  ]
});