Skip to content

textmode.js / plugins

plugins

Plugin system types for extending textmode.js functionality.

Plugins receive the Textmodifier instance for existing public state (canvas, dimensions, font, grid, layers, and per-layer framebuffers) plus a plugin context used only for plugin-owned concerns:

  • Define instance-safe methods and accessors on supported runtime objects
  • Hook into the render lifecycle (pre/post draw, per-layer rendering)
  • React to layer creation and disposal events
  • Replace layer or composited scene output with custom framebuffers

Example

ts
import type { TextmodeLayer, TextmodePlugin, TextmodePluginContext } from 'textmode.js';

const states = new WeakMap<TextmodeLayer, { value: number }>();

const MyPlugin: TextmodePlugin = {
  name: 'my-plugin',
  version: '1.0.0',
  install(textmodifier, context: TextmodePluginContext) {
    context.defineExtension('layer', 'setMyState', {
      value(value: number) {
        states.set(this, { value });
      }
    });

    // Hook into layer rendering
    context.on('layerPreRender', (layer) => {
      const state = states.get(layer);
      if (state && state.value > 0.5) {
        // Render custom content based on plugin state
      }
    });
  }
};

Interfaces

InterfaceDescription
TextmodeExtensionDescriptorDescriptor for a plugin-provided method or accessor.
TextmodeLayerOutputTransformContextValues supplied to a layer output transform.
TextmodePluginA plugin interface for extending the functionality of a Textmodifier instance.
TextmodePluginContextHost facilities available while installing a plugin.
TextmodePluginHookMapTyped callback map used by TextmodePluginContext.on.

Type Aliases

Type AliasDescription
TextmodeExtensionInstanceInstance type associated with an extension target.
TextmodeExtensionTargetRuntime objects that plugins may extend.
TextmodeLayerOutputPhaseStage at which a rendered layer output can be replaced by a plugin.
TextmodePluginHookNameName of a plugin hook accepted by TextmodePluginContext.on.