import { Meta, Source } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/figma-code/Classes/FigmaPluginMessenger - Plugin messenger (Backend)'/>

# Class `FigmaPluginMessenger`

A specialized messenger for the Figma plugin backend. It extends `FigmaPostAbstract` to provide a robust communication layer between the plugin's main logic (code side) and its user interface (UI).

## Key Features

- **Singleton Architecture** — Use `getInstance()` to ensure all parts of the plugin use the same communication hub.
- **Simplified API** — Wraps standard `figma.ui.postMessage` and `figma.ui.onmessage` into a more manageable interface.
- **Type Safety** — Supports generic types for messages to ensure data consistency.

## Initialization

Access the singleton instance using the static `getInstance()` method.

```typescript
import { FigmaPluginMessenger } from '@dxtmisha/figma-code'

const messenger = FigmaPluginMessenger.getInstance()
```

## Methods

### Communication

Methods for sending and receiving messages.

- `post<Message>(type: string, message?: Message): void` — Sends a message of a specific type to the Figma UI.
- `add(type: string, callback: (data: any) => void): this` — (Inherited) Registers a listener for messages from the UI.
- `remove(type: string): this` — (Inherited) Removes a listener.
