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

fork-lightningjs-renderer

v0.5.2

Published

Lightning 3 Renderer

Downloads

809

Readme

Lightning 3 Renderer (Beta)

Warning: This is beta software and all of the exposed APIs are subject to breaking changes

A powerful 2D scene renderer designed for rendering highly performant user interfaces on web browsers running on embedded devices using WebGL.

The Renderer is not designed for direct application development but instead to provide a lightweight API for front-end application frameworks like Bolt and Solid.

Setup & Commands

# Install renderer + example dependencies
pnpm install

# Build Renderer
pnpm build

# Build Renderer (watch mode)
pnpm watch

# Run unit tests
pnpm test

# Build API Documentation (builds into ./docs folder)
pnpm typedoc

# Launch test examples in dev mode (includes Build Renderer (watch mode))
pnpm start

# Launch test examples in production mode
# IMPORTANT: To run test examples on embedded devices that use older browser versions
# you MUST run the examples in this mode.
pnpm start:prod

Test Examples

See examples/README.md

Release Procedure

See RELEASE.md

Main Space vs Core Space

The Lightning 3 Renderer runs code in two logically seperate environments: the Main Space and the Core Space.

Users of the Renderer will write most of their code for the Main Space using the Main API. This is code that will always run on the browser's main thread and includes initializing the Renderer, creating/modifying/destroying nodes, controlling animations, etc.

The Core Space is where the actual rendering of each UI frame happens and is mostly meant to be transparent to users of the Renderer. However, the Core Space is where all of the code that must be tightly coupled to the rendering process must be loaded and run. The Core Space is extendible by users by writing Core Extensions via the Core API. This allows for users to develop their own shaders, textures, text renderers, dynamic shader effects, and more. Fonts used in an application must be loaded in this way too. The Core Space exists seperately from the Main Space because it is allowed to execute on the page's main thread OR a Web Worker thread. A Core Driver (see below) is used to bridge the Main Space with the Core Space.

Core Drivers

The Lightning 3 Renderer is designed to be able to use a single thread or multiple web worker threads based on the configuration of a Core Driver.

A Core Driver essentially acts as a bridge between the Main and Core spaces defined above.

The Renderer comes with two Core Drivers: the Main Core Driver for single threaded rendering and the ThreadX Core Driver for multi-threaded rendering.

NOTE: The ThreadX Core Driver is experimental and even when the Renderer graduates from beta may still not be ready for production use.

Main Core Driver

The Main Core Driver renders your application on the web page's main thread.

It can be configured into the Renderer like so:

import { MainRenderDriver, RendererMain } from '@lightningjs/renderer';

const renderer = new RendererMain(
  {
    // App Config
  },
  'app', // App div ID
  new MainRenderDriver(), // Main Render driver
);

// ...

ThreadX Core Driver

The ThreadX Core Driver renders your application on a seperately spawned Web Worker thread.

It can be configured into the Renderer like so:

import {
  ThreadXRenderDriver,
  RendererMain,
} from '@lightningjs/renderer';

// The `@lightningjs/vite-plugin-import-chunk-url` Vite plugin is required for this:
import coreWorkerUrl from './common/CoreWorker.js?importChunkUrl';

const renderer = new RendererMain(
  {
    // App Config
  },
  'app', // App div ID
  new ThreadXRenderDriver({
    coreWorkerUrl,
  });
);

Core Extensions

To load fonts, and/or other custom code into the Core Space, you must write a Core Extension and pass it via dynamically importable URL to the initialization of the Renderer.

Just like with loading the ThreadX Core Web Worker for the ThreadX, you import your core extension using the @lightningjs/vite-plugin-import-chunk-url plugin so that it's code is bundled and loaded seperately from your main app's bundle.

You can write a Core Extension by extending the CoreExtension class from the Core API like so:

import {
  CoreExtension,
  WebTrFontFace,
  SdfTrFontFace,
  type Stage,
} from '@lightning/renderer/core';

export default class MyCoreExtension extends CoreExtension {
  async run(stage: Stage) {
    // Load fonts into core
    stage.fontManager.addFontFace(
      new WebTrFontFace('Ubuntu', {}, '/fonts/Ubuntu-Regular.ttf'),
    );

    stage.fontManager.addFontFace(
      new SdfTrFontFace(
        'Ubuntu',
        {},
        'msdf',
        stage,
        '/fonts/Ubuntu-Regular.msdf.png',
        '/fonts/Ubuntu-Regular.msdf.json',
      ),
    );
  }
}

And then in your application's main entry point you can import it using @lightningjs/vite-plugin-import-chunk-url:

import coreExtensionModuleUrl from './MyCoreExtension.js?importChunkUrl';

// Set up driver, etc.

// Initialize the Renderer
const renderer = new RendererMain(
  {
    // Other Renderer Config...
    coreExtensionModule: coreExtensionModuleUrl,
  },
  'app',
  driver,
);