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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lit-code

v0.1.12

Published

Simple web editor created with web components

Readme

npm version Build Status Published on webcomponents.org Bundlephobia gzip size

logo

lit-code

Simple browser code editor for small code chunks.
Written with web-components and lit library.
Inspired by CodeFlask.

DEMO

preview

Features

  • Web component
  • Keeps your last line indentetion
  • Auto closing brackets, quotes
  • Indents line with the Tab key

Installation

npm i lit-code

Requires lit library and if you want highlight prismjs aswell.

Usage

Import it like this

import 'prismjs'; //to enable code highlight
//or import './my-version-of-prism.js'
import 'lit-code'; //component it self

Use it like any other custom element!

<lit-code></lit-code>

options

  • linenumbers - add line numbers
  • noshadow - disables element's shadow-dom so you can sepcify your own colorscheme
  • mycolors - disables buildin theme for highlight
  • code - set pre existing code
  • language - set language (must exists in Prism package)
  • grammar - grammar for you language (sets automaticaly with any change of language);

That's how you can use them:

<lit-code
    language='python'
    code='print("Hello, world!")'
    grammar=${Prism.languages.python}
    noshadow
    mycolors
    linenumbers
><lit-code>

API

To get any code updates use @update as event listener. That will proved you with latests changes in code:

<lit-code
    @update=${
        ({ detail: code }) => console.log('Hey, I\'ve got some new code:', code)
    }
></lit-code>

Or you can grab code with .getCode()

To set some code at runtime use .setCode().

Styling

lit-code by default (as css vars) support js, clike, html and css hightlight. Also lit-code keeps it self safe in comfy shadom-dom but you can still specify various colors to it via css variables:

--font-family: monospace;
--font-size:   12pt;
--line-height: 14pt;
--lines-width: 40px;

--editor-bg-color:    white;
--editor-text-color:  black;
--editor-caret-color: var(--editor-text-color);
--editor-sel-color:   #b9ecff;

--lines-bg-color:     #eee;
--lines-text-color:   black;
--scroll-track-color: #aaa;
--scroll-thumb-color: #eee;

/*lit-theme colors for default highlight tokens */
--hl-color-string:      #00ae22;
--hl-color-function:    #004eff;
--hl-color-number:      #dd9031;
--hl-color-operator:    #5a5a5a;
--hl-color-class-name:  #78c3ca;
--hl-color-punctuation: #4a4a4a;
--hl-color-keyword:     #8500ff;
--hl-color-comment:     #aaa;

These are default editor and highlight colors but you can spice things up by adding your own highlight with your Prism pacakge, disabling shadow-dom and creating new highlight colorscheme:

import './my-version-of-prism-with-cpp.js';
import 'lit-code';
<lit-code language='cpp' noshadow></lit-code>
.litcode {
    --editor-bg-color: black;
    --editor-text-color: white;
}
.litcode .token.type { color: red; }
.litcode .token.template { color: yellow; }

Pro tip

For easy access to parsed by prismjs words hold ctrl + shift while inspecting highlight with dev tools

Example

import { html, css, LitElement } from 'lit';
import 'prismjs';
import 'lit-code';

class JsCodePlayground extends LitElement {
  static styles = css`
    pre, lit-code {
      max-height: 300px;
      border-radius: 8px;
      border: 2px solid #eee;
    }
  `;

  static properties = {
    output: { type: String }
  };

  render() {
    return html`
      <lit-code linenumbers language='js'></lit-code>
      <button @click=${this.runCode}>Run code</button>
      <pre id="output">${this.output}</pre>
    `;
  }

  runCode() {
    const oldLog = console.log;
    console.log = (...args) => { this.output += args.join(' ') + '\n'; }
    this.output = '';
    const code = this.shadowRoot.querySelector('lit-code').getCode();
    eval(code); //eval is used only for demonstration purposes
    console.log = oldLog;
  }
};

customElements.define('js-code-playground', JsCodePlayground);