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

solid-shiki-textarea

v0.1.6

Published

textarea with shiki syntax highlighting

Downloads

12

Readme

📄 solid-shiki-textarea

pnpm

Textarea with syntax highlighting powered by solid-js and shiki.

https://github.com/bigmistqke/solid-shiki-textarea/assets/10504064/7bb4a2e1-a2c4-460d-b782-fe9bf7cac43a

Installation

npm i shiki solid-shiki-textarea
# or
yarn add shiki solid-shiki-textarea
# or
pnpm add shiki solid-shiki-textarea

Solid Component

The main export of solid-shiki-textarea is a solid component.

Types

interface ShikiTextareaProps extends Omit<ComponentProps<'div'>, 'style' | 'lang'> {
  lang:
    | Promise<LanguageRegistration[]>
    | Promise<{ default: LanguageRegistration[] }>
    | LanguageRegistration[]
  style?: JSX.CSSProperties
  theme:
    | Promise<ThemeRegistrationRaw | ThemeRegistration>
    | Promise<{ default: ThemeRegistrationRaw | ThemeRegistration }>
    | ThemeRegistrationRaw
    | ThemeRegistration
  value: string
}

Usage

Static import of theme/lang

import { ShikiTextarea } from 'solid-shiki-textarea'
import minLight from 'shiki/themes/min-light.mjs'
import tsx from 'shiki/langs/tsx.mjs'

export default () => (
  <ShikiTextarea
    lang={tsx}
    theme={minLight}
    value="const sum = (a: string, b: string) => a + b"
    onInput={e => console.log(e.target.value)}
  />
)

Dynamic import of theme/lang

import { ShikiTextarea } from 'solid-shiki-textarea'

export default () => (
  <ShikiTextarea
    lang={import('https://esm.sh/shiki/langs/tsx.mjs')}
    theme={import('https://esm.sh/shiki/themes/min-light.mjs')}
    value="const sum = (a: string, b: string) => a + b"
    onInput={e => console.log(e.target.value)}
  />
)

Custom Element

We also export a custom-element wrapper <shiki-textarea/> powered by @lume/element

Types

interface ShikiTextareaAttributes extends {
  lang?: BundledLanguage
  cdn?: string
  theme?: BundledTheme
  value?: string
}

Usage

import { registerShikiTextarea } from 'solid-shiki-textarea/custom-element'

// Noop to prevent <shiki-textarea/> from being treeshaken
registerShikiTextarea()

export default () => (
  <shiki-textarea
    lang="tsx"
    theme="theme"
    value="const sum = (a: string, b: string) => a + b"
    style={{
      '--padding': '10px',
      '--font-size': '16pt',
    }}
    onInput={e => console.log(e.target.value)}
  />
)

It resolves the theme and lang from a cdn, defaulted to esm.sh.

Note

I have not yet found another cdn that can resolve shiki's theme/lang besides esm.sh. It also takes quite a bit before the theme/lang is resolved, so maybe there is a better solution (PRs welcome!)

CSS Variables

The following css-variables are available:

  • --padding
  • --padding-top
  • --padding-bottom
  • --padding-left
  • --padding-right
  • --width
  • --height
  • --font-size

For the solid-component, these can also be set directly from the component's style-prop.