Skip to content

textmode.js / plugins

plugins

Plugin system types for extending textmode.js functionality.

Plugins can:

  • Add methods to TextmodeLayer instances (e.g., .synth())
  • Hook into the render lifecycle (pre/post draw, per-layer rendering)
  • React to layer creation and disposal events
  • Access the WebGL renderer, framebuffers, and other internals

Example

ts
import type { TextmodePlugin, TextmodePluginAPI } from 'textmode.js/plugins';

const MyPlugin: TextmodePlugin = {
  name: 'my-plugin',
  version: '1.0.0',
  install(textmodifier, api) {
    // Extend layers with a new method
    api.extendLayer('setMyState', function(value: number) {
      // `this` is bound to the TextmodeLayer instance
      this.setPluginState('my-plugin', { value });
    });

    // Hook into layer rendering
    api.registerLayerPreRenderHook((layer) => {
      const state = layer.getPluginState<{ value: number }>('my-plugin');
      if (state && state.value > 0.5) {
        // Render custom content based on plugin state
      }
    });
  }
};

Interfaces

InterfaceDescription
TextmodePluginA plugin interface for extending the functionality of a Textmodifier instance.
TextmodePluginAPIAn extended API provided to plugins when they are installed on a Textmodifier instance.

Type Aliases

Type AliasDescription
LayerExtensionImplementationType for layer extension method implementations.
LayerLifecycleHookCallback type for layer lifecycle events.
LayerRenderHookCallback type for layer render hooks.
SetupLifecycleHookCallback type for setup lifecycle hooks.
TextmodePluginHookCallback type for simple plugin hooks without parameters.