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

inline-style-editor

v1.3.7

Published

Update CSS rules or add inline style to elements visualy

Downloads

58

Readme

inline-style-editor

Lightweight (~42KB, ~16KB gzipped) tool to graphically change style and CSS (on classes or inline) using a graphical interface.

See demo.

Install

npm install inline-style-editor

Then, to use it:

As a JS module

import InlineStyleEditor from "node_modules/inline-style-editor/dist/inline-style-editor.mjs";
const editor = new InlineStyleEditor();

Also don't forget to import the css in: node_modules/inline-style-editor/dist/inline-style-editor.css.

Using a CDN:

<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/dist/inline-style-editor.css" />
<script src="https://unpkg.com/[email protected]/dist/inline-style-editor.js"></script>

Examples

Manual opening of editor:

const editor = new InlineStyleEditor();
document.body.addEventListener('click', (e) => {
    const target = e.target;
    editor.open(target, e.pageX, e.pageY);
});

Or automatic (in which case it automatically listen to the <body> element for clicks):

new InlineStyleEditor({
  listenOnClick: true,
});

Options

| option | type | Description | | ------------- |:-------------:| -----:| | listenOnClick | Boolean | Default to false. If true, click events will be listened on the <body> element, and the editor opened where clicked | | inlineDeletable | Function | Defaults to a function always returning true. The function takes the currently selected DOM node, and should return a boolean to determine whether the element can be deleted | | getElems | Function | A function called everytime the editor is opened. Should return a list of [HTMLElement, name], or HTMLElement (in which case the displayed name will be Elem i ). The returned elements will be editable as well. The first argument is the element on which the editor is about to be opened. | | onStyleChanged | Function | A function called everytime a style is modified. The first argument is the current target element, the second the edited CSS rule, or 'inline' if inline, the third the CSS prop name, the fourth the prop value | | cssSelector | Function | If defined, the CSS rules to edit can be filtered. The function takes an element and associated CSS selection text. If the function returns false, the current CSS rule will not appear in the popup. | | customProps | Object | An object defining custom properties to edit. See below. |

customProps

customProps is an object on the form of propName (as displayed in the editor) -> definition.

definition is an object defining the property to edit and the used widget:

  • type: One of slider, select or color.
    • If slider, min, max and step must be defined (floats).
    • If select, choices must be defined. It is a function returning a list to select from
  • getter: A function to get the property value. Takes the edited HTMLElement as first argument. If null is returned, the widget will not be awailable for the current element.
  • setter: A function to set the property value. Takes the edited HTMLElement as first argument, and the new value as second argument.

Example, to edit the pathLength of an SVG element using a slider:

new InlineStyleEditor({
    customProps: {
        'pathLength': {
            type: 'slider', min: 1, max: 500, step: 1,
            getter: (el) => {
                // disable when elem is not a SVG geometry
                if (!el.getTotalLength) return null;
                const pathLength = el.getAttribute('pathLength');
                if (!pathLength) return Math.round(el.getTotalLength());
                return parseInt(pathLength);
            },
            setter: (el, val) => {
                el.setAttribute('pathLength', val);
            }
        },
    }
});

Suported css properties

  • border-radius
  • border-width
  • border-style
  • border-color
  • font-family
  • font-size
  • font-weight
  • color
  • stroke-width
  • stroke-linejoin
  • stroke
  • fill
  • stroke-dasharray
  • background-color