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

styled_dom

v1.16.0

Published

This micro service allows you to create styled vanilla components with a different options

Downloads

19

Readme

This micro library will allow you to create customizable DOM elements in a convenient format, similar to styled components used in well-known JS frameworks. You will have the opportunity to style your components the way you want without going beyond the js file. So far there are 2 styling modes - Inline and Internal css. The project will continue to be improved and developed.

Examples:

make a simple ES6 import and just use

Here we create an "instance" of main Styled "class", its element() method returns a function, which returns a DOM string to use further. Plus this Component also takes a function to do more deep manipulations as it showed below. Component Header takes Component Nav and returns updated new structure. Similar to HOC or just HOF.

You see element() method takes params as object to inject styles. These very styles will be whether Inline or Internal depending on what value "isInlineCSS" takes - true or false. By default it is true. It may seem verbose but there is nothing much complicated. Also this method takes different params as Array [] and the last as String ''. Array takes attributes which may be used in your Component if you wish so. And the last parameter is selector which is used as className selector for CSS. Use it if you d like to style not by tag selector!

const {ref} = Styled

Method ref() finds in vDOM node proper selector and parent which will mount it in real DOM

Finally, you see there are also two important methods - render() and mount(). The main difference is that render() appends your created Elements in some kind of virtual copy of DOM through DOMParser API and all elements located there before to be appended in real DOM. Why? As you know, direct DOM handling through creating html strings, transforming and styling them - very resource-intensive operation. To minimize a little, all manipulations go in the "vDOM"

const nodes = Styled.render(Header(Nav)) - HOF

console.log(nodes) - log this node.

And method mount() - says "take that node dotted or the whole in vDOM and insert in real Document"

I hope you will like it.

Updates:

1.13.0 - There was added independent function "toFragment", which allows to do all standart operations out of real DOM structure to increase performance.

toFragment() method returns a function which can be used to return another node inside main one. If it's not necessary just pass "null". After, v_DOM is constructed you can take it and use usual DOM api to find proper elements with selectors and insert whereever you want or the whole vDOM

Examples: