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

oberflaeche

v0.0.1

Published

Small library to build UIs with JSX in TypeScript or JavaScript

Downloads

1

Readme

Oberfläche

Oberfläche is a simple zero-dependency library that let's you build UIs with JSX in TypeScript or JavaScript. It also provides you with the possibility to use state, effects (experimental & clean up not fully working yet) and the option to manually refresh components. Furthermore it has a simple diffing algorithm for the rendering.

Important to know is that the state is always global, which means you can, if you decide to, hook into the state of any other component and control or read it. The same goes for manual refreshing of components. These component utilities, or also called component context, are always provided via the second component function argument.

Attention! This is just a little side project and should not be used for anything important!

Components

When working with Oberfläche we are differentiating between two types of components, stateless/non-reactive and stateful/reactive. Stateful/Reactive components have a few requirements that have to be obeyed.

Stateless/Non-reactive Component

type HalloProps = { name: string; }
const Hallo: Component<HalloProps> = ({ name }) => {
    return <h1>{name}</h1>
}

Stateful/Reactive Component

const Hallo: Component = ({}, ctx) => {
    const oberflaecheId = "my-globally-unique-oberflaeche-id"
    const [state, setState] = ctx.state(oberflaecheId, { count: 0, name: generateName })

    const generateName = () => {
        setState({ count: state().count + 1, name: aiBasedNameGenerator() })
    }

    return (
        <div oberflaecheId={oberflaecheId}>
            <h1>{name}</h1>
            <p>We had {state().count} names so far</p>
            <button oberflaecheId={`${oberflaecheId}-button`} onClick={generateName}>
                Show me a name
            </button>
        </div>
    )
}

Stateful components or components that are reactive must provide a globally unique oberflaecheId for each instance. Every component that uses any method from the context is a stateful/reactive component. For example, if you render a list of components, which are using state or something else that is reactive internally, each item will need a globally unique oberflaecheId that will stay the same during the time the component will be rendered and run. This means you cannot use random numbers or such as an oberflaecheId. Additionally each element with an event listener needs a unique oberflaecheId as well.

The oberflaecheId needs to be applied to the outer most container of a component, if you'd like to use the context. If you'd like to use event listeners for an element, then the oberflaecheId should be applied to the element itself. Your event handlers should also work, if you don't add a unique oberflaecheId to the element, but it will be less performant and could cause some unintended behavior.

You can always pass the oberflaecheId as a prop to any of your function components and Oberfläche will automatically pass it down and apply it to the outer most container. The only exception here is that you cannot do this on the initial parent component you will run .render on.

Example


// Generic button that will be used in multiple different components.
type ButtonProps = { text: string; onClick: () => void; }
const Button: Component<ButtonProps> = (props) => {
  const { text, onClick } = props

  return <button onClick={onClick}>{text}</button>
}

type Product = { id: string; name: string; price: number; }
type ShopItemsProps = { products: Product[] }
const ShopItems: Component<ShopItemsProps> = (props, ctx) => {
    const oberflaecheId = "my-globally-unique-oberflaeche-id"
    const [cart, updateCart] = ctx.state<string[]>(oberflaecheId, { productIds: [] })

    const addToCart = (id: string) => {
        updateCart({ cart: [...cart().productIds, id] })
    }

    // Adding a unique `oberflaecheId` for every instance of the `Button` that will be rendered.
    return (
        <div>
            <h1>Shop Items</h1>
            <p>You have {cart().productIds.length} items in the bag</p>
            <ul>
              {products.map(product => {
                return (
                  <li>
                    <h3>{product.name}</h3>
                    <p>{prodcut.price}</p>
                    {
                      !cart().productIds.includes(product.id) &&
                      <Button oberflaecheId={`${oberflaecheId}-add-${product.id}-button`} text="Add to cart" onClick={() => addToCart(product.id)} />
                    }
                  </li>
                )
              })}
            </ul>
        </div>
    )
}

Component Context

type ComponentContext = {
  refresh: (oberflaecheId: string, options?: { diffing?: boolean }) => void;
  refreshOther: (
    component: Component,
    props: Props,
    oberflaecheId: string,
    options?: { diffing?: boolean }
  ) => void;
  state: <STATE>(
    oberflaecheId: string,
    initialState?: STATE,
    options?: { diffing?: boolean; autoRefresh?: boolean }
  ) => [getState: () => STATE, setState: (newState: STATE) => void];
  stateOther: <STATE>(
    component: Component,
    props: Props,
    oberflaecheId: string,
    initialState?: STATE,
    options?: { diffing?: boolean; autoRefresh?: boolean }
  ) => [getState: () => STATE, setState: (newState: STATE) => void];
  globalState: <STATE>(oberflaecheId?: string) => STATE | Map<string, any>;
  effect: (effect: () => () => void, dependencies: any[], oberflaecheId: string, effectId: string) => void;
};

Installation


$ npm i -s oberflaeche

Example Webpack + Babel + TypeScript setup:

$ npm i -D @babel/cli @babel/plugin-transform-react-jsx @babel/preset-env @babel/preset-typescript typescript webpack webpack-cli webpack-dev-server @babel/core babel-loader css-loader mini-css-extract-plugin

.babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-typescript"],
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "runtime": "automatic",
        "importSource": "oberflaeche"
      }
    ]
  ]
}

tsconfig.json with the following added to your config:

"jsx": "react-jsx",
"jsxImportSource": "oberflaeche",

webpack.config.js

const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

const prod = process.argv.includes("-p");

module.exports = {
  devtool: prod ? "source-map" : "inline-source-map",
  entry: "./src/App.tsx",
  output: {
    path: path.resolve(__dirname, "public"),
    filename: "js/bundle.js",
    publicPath: "/",
  },
  resolve: {
    extensions: [".ts", ".js", ".tsx", ".jsx"],
  },
  devServer: {
    contentBase: path.join(__dirname, "public"),
    compress: true,
    port: 9000,
    historyApiFallback: true,
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
          },
          "css-loader",
        ],
      },
      {
        // Include ts(x) and js(x) files.
        test: /\.(ts|js)x?$/,
        exclude: [/node_modules/],
        loader: "babel-loader",
      },
    ],
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: "css/bundle.css",
    }),
  ],
};

Add these scripts to your package.json

"scripts": {
    "start:dev": "webpack-dev-server -p --open",
    "build": "webpack --mode production"
},

Additionally you'll need a public folder with a basic HTML file like this

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Oberfläche</title>
    <link rel="stylesheet" href="css/bundle.css" />
  </head>
  <body>
    <div id="app"></div>
    <script src="js/bundle.js"></script>
  </body>
</html>