@dxtmisha/figma-code 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/ai-description.txt +1 -0
- package/ai-doc.ru.txt +12 -0
- package/ai-doc.txt +12 -0
- package/ai-types.txt +288 -0
- package/dist/classes/FigmaAiText.d.ts +10 -0
- package/dist/classes/FigmaClientStorage.d.ts +61 -0
- package/dist/classes/FigmaFrame.d.ts +167 -0
- package/dist/classes/FigmaFramesSelected.d.ts +75 -0
- package/dist/classes/FigmaItem.d.ts +223 -0
- package/dist/classes/FigmaPluginMessenger.d.ts +29 -0
- package/dist/classes/FigmaStorage.d.ts +74 -0
- package/dist/classes/FigmaStorageData.d.ts +117 -0
- package/dist/classes/FigmaTopLevelFrames.d.ts +32 -0
- package/dist/config.d.ts +3 -0
- package/dist/functions/getFigmaFrameById.d.ts +10 -0
- package/dist/functions/getFigmaItemById.d.ts +9 -0
- package/dist/functions/getFigmaItemByIdOrRoot.d.ts +8 -0
- package/dist/functions/makeFigmaFrameSelection.d.ts +6 -0
- package/dist/functions/makeFigmaTexts.d.ts +6 -0
- package/dist/functions/setupClientStorage.d.ts +6 -0
- package/dist/functions/setupFrameSelection.d.ts +12 -0
- package/dist/functions/setupFrameStyles.d.ts +6 -0
- package/dist/functions/setupStorage.d.ts +6 -0
- package/dist/functions/toFrameSelection.d.ts +6 -0
- package/dist/library.d.ts +19 -0
- package/dist/library.js +546 -0
- package/dist/media/prompt/text.ru.d.ts +2 -0
- package/dist/types/figmaTypes.d.ts +33 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-05-10
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Recursive AI Prompt Generator**: Implemented a recursive AI prompt generator for advanced automation and design-to-code workflows.
|
|
9
|
+
- **Figma Styles Synchronization**: Added functionality to synchronize Figma styles with the project codebase.
|
|
10
|
+
- **Zip Export**: Integrated Zip archiving for exporting styles and assets directly from Figma.
|
|
11
|
+
- **Figma Frame & Item Management**: Implemented `FigmaFrame` and `FigmaItem` classes for comprehensive management of Figma elements.
|
|
12
|
+
- **Figma Storage**: Added `FigmaStorage`, `FigmaStorageData`, and `FigmaClientStorage` for robust data persistence within the Figma environment.
|
|
13
|
+
- **Figma Plugin Messaging**: Implemented `FigmaPluginMessenger` for standardized, type-safe communication between the plugin and Figma.
|
|
14
|
+
- **Selection Support**: Added `FigmaFramesSelected` and `useFigmaUiSelected` for efficient management of selected Figma elements.
|
|
15
|
+
- **DesignWikiStorm Support**: Added support for events and slots in `DesignWikiStorm`.
|
|
16
|
+
- **Unit Testing**: Added a comprehensive unit testing suite for core logic and classes.
|
|
17
|
+
- **AI-Assisted Documentation**: Integrated AI-assisted documentation metadata to improve developer experience.
|
|
18
|
+
|
|
19
|
+
### Changed / Improved
|
|
20
|
+
- **Checkbox Design Refactor**: Refactored Checkbox design integration to align with the new design system.
|
|
21
|
+
- **Selection Logic**: Consolidated and standardized frame selection logic and messengers across the package.
|
|
22
|
+
- **Storage Mechanics**: Refined data storage mechanics and callback handling for better reliability.
|
|
23
|
+
- **Internal Architecture**: Improved class hierarchy and modularity for Figma-related logic.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- **Selection Issues**: Fixed various bugs related to frame selection and event propagation.
|
|
27
|
+
- **Type Definitions**: Addressed TypeScript type definition errors and improved overall type safety.
|
|
28
|
+
- **Event Handling**: Fixed issues with event and slot support in `DesignWikiStorm`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 dxtmisha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @dxtmisha/figma-code
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@dxtmisha/figma-code)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
`@dxtmisha/figma-code` is a structured TypeScript abstraction layer for Figma Plugin backend development. It provides high-level tools for node manipulation, persistent storage, and bidirectional communication between the plugin's logic and its UI.
|
|
7
|
+
|
|
8
|
+
## Why this library?
|
|
9
|
+
|
|
10
|
+
Developing Figma plugins often involves repetitive tasks like traversing complex node trees, managing character data in text nodes, and handling persistent state through `clientStorage` or `pluginData`.
|
|
11
|
+
|
|
12
|
+
The native Figma API is powerful but low-level. `figma-code` wraps these APIs into intuitive, type-safe classes and functions that handle common patterns automatically—such as caching storage values, traversing parent-child relationships, and managing message exchange between the sandbox and the iframe.
|
|
13
|
+
|
|
14
|
+
## What does it do?
|
|
15
|
+
|
|
16
|
+
For **node manipulation (DOM-like API)** — the `FigmaItem` class and its specialized derivatives (like `FigmaFrame`) provide a convenient way to interact with Figma nodes. They offer methods for type checking (`isText`, `isFrame`), accessing parent/page context, and extracting CSS or JSON representations of nodes.
|
|
17
|
+
|
|
18
|
+
For **persistent storage** — robust wrappers for Figma's storage systems. `FigmaStorage` handles `setPluginData` (node-level storage) with built-in caching and aging logic, while `FigmaClientStorage` provides a similar interface for `figma.clientStorage` (plugin-level storage).
|
|
19
|
+
|
|
20
|
+
For **bidirectional messaging** — `FigmaPluginMessenger` simplifies communication between the plugin backend and the UI. It provides a standardized way to send messages (`post`) and handle incoming ones, ensuring type safety across the boundary.
|
|
21
|
+
|
|
22
|
+
For **selection and navigation** — utilities like `FigmaFramesSelected` and `FigmaTopLevelFrames` allow developers to easily track and manipulate user selections or find specific elements within the document without manual recursion.
|
|
23
|
+
|
|
24
|
+
For **content processing** — specialized modules like `FigmaAiText` facilitate text analysis and manipulation, which is essential for building AI-driven translation or design-to-code tools.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @dxtmisha/figma-code
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { FigmaItem, FigmaStorage, FigmaPluginMessenger } from '@dxtmisha/figma-code'
|
|
36
|
+
|
|
37
|
+
// 1. Working with nodes
|
|
38
|
+
const selectedNode = figma.currentPage.selection[0]
|
|
39
|
+
if (selectedNode) {
|
|
40
|
+
const item = new FigmaItem(selectedNode)
|
|
41
|
+
console.log('Node Name:', item.getName())
|
|
42
|
+
if (item.isText()) {
|
|
43
|
+
console.log('Text Content:', item.getText())
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 2. Persistent storage with caching
|
|
48
|
+
const userSettings = FigmaStorage.getInstance('settings')
|
|
49
|
+
const theme = userSettings.get({ theme: 'light' })
|
|
50
|
+
userSettings.set({ ...theme, theme: 'dark' })
|
|
51
|
+
|
|
52
|
+
// 3. Messaging to UI
|
|
53
|
+
const messenger = FigmaPluginMessenger.getInstance()
|
|
54
|
+
messenger.post('UPDATE_STATUS', { status: 'ready' })
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Principles
|
|
58
|
+
|
|
59
|
+
- **Structured Abstraction** — moves beyond raw Figma nodes to a more object-oriented approach that is easier to reason about.
|
|
60
|
+
- **Type Safety** — built from the ground up with TypeScript, ensuring that your plugin logic is robust and predictable.
|
|
61
|
+
- **Performance Optimized** — includes caching mechanisms for data-heavy operations like reading storage or processing complex node trees.
|
|
62
|
+
- **Developer Experience** — focuses on reducing boilerplate code for common plugin tasks, letting you focus on the core features of your plugin.
|
|
63
|
+
|
|
64
|
+
## Documentation
|
|
65
|
+
|
|
66
|
+
Full API reference and guides:
|
|
67
|
+
|
|
68
|
+
**[📖 https://dxtmisha.github.io/dxt-ui/?path=/docs/dxtmisha-en-figma-code-about-library--docs](https://dxtmisha.github.io/dxt-ui/?path=/docs/dxtmisha-en-figma-code-about-library--docs)**
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
[MIT](LICENSE)
|
|
73
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This library is a structured TypeScript abstraction layer for Figma Plugin backend development, specifically designed to automate node manipulation, data persistence, and bidirectional messaging. Its core purpose is to provide high-level wrappers around the native Figma API for node traversal (FigmaItem), frame-specific metadata extraction (FigmaFrame), and persistent state management using both figma.clientStorage and node-level PluginData with built-in caching and aging logic. AI coding assistants should study this library when implementing features for automated CSS/style extraction, programmatic selection management, screenshot generation, or text content processing for translation and key-value mapping. The integration context bridges the Figma backend to the UI via FigmaPluginMessenger and includes specialized modules for AI-driven text analysis, relying on a shared type system for Figma nodes and message payloads.
|
package/ai-doc.ru.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
ПАКЕТ ЛОГИКИ ПЛАГИНА FIGMA (BACKEND):
|
|
2
|
+
Данная библиотека предназначена для работы на стороне основного процесса плагина (Code side). Она обеспечивает прямой доступ к Figma API и реализует логику обработки запросов от UI.
|
|
3
|
+
|
|
4
|
+
1. ПРЕДНАЗНАЧЕНИЕ: Реализация фоновой логики плагина. Отвечает за манипуляцию объектами Figma (фреймы, текст, стили), управление хранилищем (`FigmaStorage`) и отправку данных обратно в UI через `FigmaPluginMessenger`.
|
|
5
|
+
2. ВЗАИМОДЕЙСТВИЕ: Работает в связке с пакетом `@dxtmisha/figma`. Получает сообщения от UI, выполняет операции через Figma API и отправляет результат обратно.
|
|
6
|
+
3. КЛЮЧЕВЫЕ КЛАССЫ:
|
|
7
|
+
- `FigmaPluginMessenger`: Синглтон для управления сообщениями на стороне Backend.
|
|
8
|
+
- `FigmaFrame`, `FigmaItem`: Обертки для удобной работы с узлами (nodes) Figma.
|
|
9
|
+
- `setup...` функции: Слушатели, которые автоматически обрабатывают стандартные запросы от UI (например, `setupFrameSelection`).
|
|
10
|
+
|
|
11
|
+
Используй этот пакет только в коде, который выполняется в основном процессе плагина Figma (main thread).
|
|
12
|
+
|
package/ai-doc.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
FIGMA PLUGIN LOGIC PACKAGE (BACKEND):
|
|
2
|
+
This library is intended for use on the main process side of a Figma plugin (Code side). It provides direct access to the Figma API and implements the logic for handling requests from the UI.
|
|
3
|
+
|
|
4
|
+
1. PURPOSE: Implementing the background logic of the plugin. It is responsible for manipulating Figma objects (frames, text, styles), managing storage (`FigmaStorage`), and sending data back to the UI via `FigmaPluginMessenger`.
|
|
5
|
+
2. INTERACTION: Works in conjunction with the `@dxtmisha/figma` package. It receives messages from the UI, performs operations via the Figma API, and sends results back.
|
|
6
|
+
3. KEY CLASSES:
|
|
7
|
+
- `FigmaPluginMessenger`: A singleton for managing messages on the Backend side.
|
|
8
|
+
- `FigmaFrame`, `FigmaItem`: Wrappers for convenient handling of Figma nodes.
|
|
9
|
+
- `setup...` functions: Listeners that automatically process standard UI requests (e.g., `setupFrameSelection`).
|
|
10
|
+
|
|
11
|
+
Use this package only in code that executes in the main process of the Figma plugin (main thread).
|
|
12
|
+
|
package/ai-types.txt
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
1) All these methods are in the @dxtmisha/figma-code library.
|
|
2
|
+
2) Everything that is exported can be used.
|
|
3
|
+
3) Use what is in this library if it exists; do not use other libraries if there is an analogue here. Do not create new ones if an analogue already exists here.
|
|
4
|
+
|
|
5
|
+
The following is the content of "exports" from package.json:
|
|
6
|
+
{
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/library.js",
|
|
9
|
+
"types": "./dist/library.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./style.css": "./dist/style.css",
|
|
12
|
+
"./types/*": "./dist/*",
|
|
13
|
+
"./types/**/*.d.ts": "./dist/**/*.d.ts"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// File: classes/FigmaAiText.d.ts
|
|
17
|
+
export declare class FigmaAiText {
|
|
18
|
+
constructor(ai: AiAbstract, data: UiFigmaMessageTexts);
|
|
19
|
+
make(): Promise<this>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// File: classes/FigmaClientStorage.d.ts
|
|
23
|
+
/** Figma client storage wrapper. */
|
|
24
|
+
export declare class FigmaClientStorage<T> {
|
|
25
|
+
/**
|
|
26
|
+
* Get class instance.
|
|
27
|
+
* @param name value name
|
|
28
|
+
* @returns current instance
|
|
29
|
+
*/
|
|
30
|
+
static getInstance<T>(name: string): FigmaClientStorage<T>;
|
|
31
|
+
constructor(name: string, cache?: number | undefined);
|
|
32
|
+
/**
|
|
33
|
+
* Get data from storage.
|
|
34
|
+
* @param defaultValue default value
|
|
35
|
+
*/
|
|
36
|
+
get(defaultValue?: T | (() => T | Promise<T>)): Promise<T | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Set data in storage.
|
|
39
|
+
* @param value new values
|
|
40
|
+
* @returns current value
|
|
41
|
+
*/
|
|
42
|
+
set(value?: T | (() => T | Promise<T>)): Promise<T | undefined>;
|
|
43
|
+
/** Remove data from storage. */
|
|
44
|
+
remove(): Promise<this>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// File: classes/FigmaFrame.d.ts
|
|
48
|
+
/** Figma frames and elements manager. */
|
|
49
|
+
export declare class FigmaFrame {
|
|
50
|
+
/**
|
|
51
|
+
* @param page Figma page or node
|
|
52
|
+
* @param selection use selection or entire page
|
|
53
|
+
*/
|
|
54
|
+
constructor(page: UiFigmaNode, selection?: boolean);
|
|
55
|
+
/** Check if context is a selection. */
|
|
56
|
+
isSelection(): this is {
|
|
57
|
+
page: PageNode;
|
|
58
|
+
};
|
|
59
|
+
/** Get all frame items. */
|
|
60
|
+
getItemsFrame(): FigmaItem<FrameNode>[];
|
|
61
|
+
/** Get all section items. */
|
|
62
|
+
getItemsSection(): FigmaItem<SectionNode>[];
|
|
63
|
+
/** Get all text items. */
|
|
64
|
+
getItemsText(): FigmaItem<TextNode>[];
|
|
65
|
+
/** Get frames info (names, IDs, screenshots). */
|
|
66
|
+
getItemsInfo(): Promise<UiFigmaFramesList>;
|
|
67
|
+
/** Get CSS styles for all items. */
|
|
68
|
+
getItemsCss(): Promise<UiFigmaFrameStylesCssList>;
|
|
69
|
+
/** Get frames with styles. */
|
|
70
|
+
getItemsStyles(): Promise<UiFigmaFrameStylesList>;
|
|
71
|
+
/** Get main frames from root. */
|
|
72
|
+
getMainFrames(): FigmaItem[];
|
|
73
|
+
/** Get main items info. */
|
|
74
|
+
getMainItemsInfo(): Promise<UiFigmaFramesList>;
|
|
75
|
+
/** Get main frames with styles. */
|
|
76
|
+
getMainItemsStyles(): Promise<UiFigmaFrameStylesList>;
|
|
77
|
+
/** Get text nodes grouped by content. */
|
|
78
|
+
getTexts(): UiFigmaItemText[];
|
|
79
|
+
/** Screenshot main items. */
|
|
80
|
+
screenshot(): Promise<Uint8Array<ArrayBufferLike>[]>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// File: classes/FigmaFramesSelected.d.ts
|
|
84
|
+
/** Manages selected frames in plugin. */
|
|
85
|
+
export declare class FigmaFramesSelected {
|
|
86
|
+
/**
|
|
87
|
+
* Check if frame ID is selected.
|
|
88
|
+
* @param id Frame ID
|
|
89
|
+
*/
|
|
90
|
+
static has(id: string): boolean;
|
|
91
|
+
/** Get current selected frame IDs. */
|
|
92
|
+
static get(): string[];
|
|
93
|
+
/** Add frame ID to selection. */
|
|
94
|
+
static add(id: string): void;
|
|
95
|
+
/** Remove frame ID from selection. */
|
|
96
|
+
static remove(id: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Toggle frame selection state.
|
|
99
|
+
* @param id Frame ID
|
|
100
|
+
* @param selected selection state
|
|
101
|
+
*/
|
|
102
|
+
static toggle(id: string, selected: boolean): void;
|
|
103
|
+
/** Sync selection state via messenger. */
|
|
104
|
+
static send(): void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// File: classes/FigmaItem.d.ts
|
|
108
|
+
/** Figma node wrapper. */
|
|
109
|
+
export declare class FigmaItem<T extends UiFigmaNode = UiFigmaNode> {
|
|
110
|
+
constructor(item: T);
|
|
111
|
+
isDocument(): this is {
|
|
112
|
+
item: DocumentNode;
|
|
113
|
+
};
|
|
114
|
+
isFrame(): this is {
|
|
115
|
+
item: FrameNode;
|
|
116
|
+
};
|
|
117
|
+
isSection(): this is {
|
|
118
|
+
item: SectionNode;
|
|
119
|
+
};
|
|
120
|
+
isText(): this is {
|
|
121
|
+
item: TextNode;
|
|
122
|
+
};
|
|
123
|
+
isTextNoValue(): this is {
|
|
124
|
+
item: TextNode;
|
|
125
|
+
};
|
|
126
|
+
inCurrentPage(): boolean;
|
|
127
|
+
/** Get Figma node. */
|
|
128
|
+
get(): T;
|
|
129
|
+
getType(): "SLICE" | "FRAME" | "GROUP" | "COMPONENT_SET" | "COMPONENT" | "INSTANCE" | "BOOLEAN_OPERATION" | "VECTOR" | "STAR" | "LINE" | "ELLIPSE" | "POLYGON" | "RECTANGLE" | "TEXT" | "TEXT_PATH" | "TRANSFORM_GROUP" | "STICKY" | "CONNECTOR" | "SHAPE_WITH_TEXT" | "CODE_BLOCK" | "STAMP" | "WIDGET" | "EMBED" | "LINK_UNFURL" | "MEDIA" | "SECTION" | "HIGHLIGHT" | "WASHI_TAPE" | "TABLE" | "SLIDE" | "SLIDE_ROW" | "SLIDE_GRID" | "SLOT" | "INTERACTIVE_SLIDE_ELEMENT" | "DOCUMENT" | "PAGE" | undefined;
|
|
130
|
+
getParent(): (BaseNode & ChildrenMixin) | undefined;
|
|
131
|
+
getParentItem(): FigmaItem | undefined;
|
|
132
|
+
getParentPage(): PageNode | undefined;
|
|
133
|
+
getParentPageItem(): FigmaItem | undefined;
|
|
134
|
+
getChildren(): UiFigmaNode[];
|
|
135
|
+
getChildrenItems(): FigmaItem[];
|
|
136
|
+
getId(): string;
|
|
137
|
+
getName(): string;
|
|
138
|
+
getText(): string;
|
|
139
|
+
getCss(): Promise<Record<string, string>>;
|
|
140
|
+
getInfo(): Promise<UiFigmaFramesItem>;
|
|
141
|
+
getStyles(): Promise<UiFigmaFrameStylesItem>;
|
|
142
|
+
exportJpg(): Promise<Uint8Array<ArrayBufferLike> | "">;
|
|
143
|
+
exportJson(): Promise<Uint8Array<ArrayBufferLike> | "">;
|
|
144
|
+
exportJsonCompact(): Promise<UiFigmaFrameStylesData | undefined>;
|
|
145
|
+
/** Select node. */
|
|
146
|
+
toSelection(): void;
|
|
147
|
+
/** Move to page and select node. */
|
|
148
|
+
toPageAndSelection(): Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// File: classes/FigmaPluginMessenger.d.ts
|
|
152
|
+
/** Figma plugin backend messenger. */
|
|
153
|
+
export declare class FigmaPluginMessenger extends FigmaPostAbstract {
|
|
154
|
+
static getInstance(): FigmaPluginMessenger;
|
|
155
|
+
/** Send message to UI. */
|
|
156
|
+
post<Message>(type: string, message?: Message): void;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// File: classes/FigmaStorage.d.ts
|
|
160
|
+
/** Figma PluginData storage wrapper. */
|
|
161
|
+
export declare class FigmaStorage<T> {
|
|
162
|
+
/**
|
|
163
|
+
* Get instance.
|
|
164
|
+
* @param name value name
|
|
165
|
+
* @param item data container
|
|
166
|
+
*/
|
|
167
|
+
static getInstance<T>(name: string, item?: UiFigmaNode): FigmaStorage<T>;
|
|
168
|
+
/**
|
|
169
|
+
* Get instance by ID.
|
|
170
|
+
* @param id object id
|
|
171
|
+
*/
|
|
172
|
+
static getInstanceById<T>(name: string, id?: string): Promise<FigmaStorage<T>>;
|
|
173
|
+
constructor(name: string, item?: PluginDataMixin, cache?: number | undefined);
|
|
174
|
+
get(defaultValue?: T | (() => T)): T | undefined;
|
|
175
|
+
set(value?: T | (() => T)): T | undefined;
|
|
176
|
+
remove(): this;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// File: classes/FigmaStorageData.d.ts
|
|
180
|
+
export type FigmaStorageDataValue<T> = {
|
|
181
|
+
value: T;
|
|
182
|
+
age: number;
|
|
183
|
+
};
|
|
184
|
+
/** Figma storage data manager. */
|
|
185
|
+
export declare class FigmaStorageData<T> {
|
|
186
|
+
constructor(name: string, cache?: number | undefined);
|
|
187
|
+
isNull(): boolean;
|
|
188
|
+
isCache(): boolean;
|
|
189
|
+
isValue(): boolean;
|
|
190
|
+
get(): T | undefined;
|
|
191
|
+
getAge(): number | undefined;
|
|
192
|
+
getName(): string;
|
|
193
|
+
getCache(): number | undefined;
|
|
194
|
+
set(value?: T, age?: number): this;
|
|
195
|
+
setByObject(value?: FigmaStorageDataValue<T>): this;
|
|
196
|
+
setValue(value?: T): this;
|
|
197
|
+
setAge(age?: number): this;
|
|
198
|
+
update(value?: T): this;
|
|
199
|
+
remove(): this;
|
|
200
|
+
toValue(): FigmaStorageDataValue<T>;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// File: classes/FigmaTopLevelFrames.d.ts
|
|
204
|
+
/** Manages top-level frames list. */
|
|
205
|
+
export declare class FigmaTopLevelFrames {
|
|
206
|
+
/** Get cached list of top-level frames. */
|
|
207
|
+
static get(): Promise<UiFigmaFramesList>;
|
|
208
|
+
/** Listen for frame requests and send data. */
|
|
209
|
+
static send(): void;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// File: config.d.ts
|
|
213
|
+
export declare const FIGMA_IMAGE_TYPE = "image/jpeg";
|
|
214
|
+
export declare const FIGMA_MESSAGE_TEXTS = "texts";
|
|
215
|
+
|
|
216
|
+
// File: functions/getFigmaFrameById.d.ts
|
|
217
|
+
/** Get FigmaFrame by ID. */
|
|
218
|
+
export declare function getFigmaFrameById(id: string): Promise<FigmaFrame | undefined>;
|
|
219
|
+
|
|
220
|
+
// File: functions/getFigmaItemById.d.ts
|
|
221
|
+
/** Get Figma item wrapper by ID. */
|
|
222
|
+
export declare function getFigmaItemById<T extends UiFigmaNode = UiFigmaNode>(id: string): Promise<FigmaItem<T> | undefined>;
|
|
223
|
+
|
|
224
|
+
// File: functions/getFigmaItemByIdOrRoot.d.ts
|
|
225
|
+
/** Get Figma node by ID or figma.root. */
|
|
226
|
+
export declare function getFigmaItemByIdOrRoot<T extends UiFigmaNode = UiFigmaNode>(id?: string): Promise<T>;
|
|
227
|
+
|
|
228
|
+
// File: functions/makeFigmaFrameSelection.d.ts
|
|
229
|
+
/** Sync Figma selection changes to UI. */
|
|
230
|
+
export declare const makeFigmaFrameSelection: () => void;
|
|
231
|
+
|
|
232
|
+
// File: functions/makeFigmaTexts.d.ts
|
|
233
|
+
/** Sync Figma text selection to UI. */
|
|
234
|
+
export declare const makeFigmaTexts: () => void;
|
|
235
|
+
|
|
236
|
+
// File: functions/setupClientStorage.d.ts
|
|
237
|
+
/** Init client storage listeners. */
|
|
238
|
+
export declare function setupClientStorage(): void;
|
|
239
|
+
|
|
240
|
+
// File: functions/setupFrameSelection.d.ts
|
|
241
|
+
/** Init bidirectional frame selection management. */
|
|
242
|
+
export declare function setupFrameSelection(): void;
|
|
243
|
+
|
|
244
|
+
// File: functions/setupFrameStyles.d.ts
|
|
245
|
+
/** Listen for style update messages. */
|
|
246
|
+
export declare function setupFrameStyles(): void;
|
|
247
|
+
|
|
248
|
+
// File: functions/setupStorage.d.ts
|
|
249
|
+
/** Init storage listeners. */
|
|
250
|
+
export declare function setupStorage(): void;
|
|
251
|
+
|
|
252
|
+
// File: functions/toFrameSelection.d.ts
|
|
253
|
+
/** Focus and select item by ID. */
|
|
254
|
+
export declare function toFrameSelection(id?: string): Promise<void>;
|
|
255
|
+
|
|
256
|
+
// File: library.d.ts
|
|
257
|
+
export * from './classes/FigmaClientStorage';
|
|
258
|
+
export * from './classes/FigmaFrame';
|
|
259
|
+
export * from './classes/FigmaFramesSelected';
|
|
260
|
+
export * from './classes/FigmaItem';
|
|
261
|
+
export * from './classes/FigmaPluginMessenger';
|
|
262
|
+
export * from './classes/FigmaStorage';
|
|
263
|
+
export * from './classes/FigmaStorageData';
|
|
264
|
+
export * from './classes/FigmaTopLevelFrames';
|
|
265
|
+
export * from './functions/getFigmaFrameById';
|
|
266
|
+
export * from './functions/getFigmaItemById';
|
|
267
|
+
export * from './functions/getFigmaItemByIdOrRoot';
|
|
268
|
+
export * from './functions/makeFigmaFrameSelection';
|
|
269
|
+
export * from './functions/makeFigmaTexts';
|
|
270
|
+
export * from './functions/setupClientStorage';
|
|
271
|
+
export * from './functions/setupFrameSelection';
|
|
272
|
+
export * from './functions/setupFrameStyles';
|
|
273
|
+
export * from './functions/setupStorage';
|
|
274
|
+
export * from './functions/toFrameSelection';
|
|
275
|
+
export * from './types/figmaTypes';
|
|
276
|
+
|
|
277
|
+
// File: types/figmaTypes.d.ts
|
|
278
|
+
export type UiFigmaNode = ChildrenMixin | SceneNode | DefaultShapeMixin | DocumentNode | PageNode | FrameNode | SectionNode | TextNode | BaseNode;
|
|
279
|
+
export type UiFigmaItemText = {
|
|
280
|
+
id: string[];
|
|
281
|
+
text: string;
|
|
282
|
+
};
|
|
283
|
+
export type UiFigmaExportFormat = 'PNG' | 'JPG' | 'SVG' | 'PDF' | 'JSON_REST_V1';
|
|
284
|
+
export type UiFigmaMessageTexts = {
|
|
285
|
+
frame: FigmaFrame;
|
|
286
|
+
texts: UiFigmaItemText[];
|
|
287
|
+
screenshot: Uint8Array[];
|
|
288
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AiAbstract } from '@dxtmisha/scripts/ai';
|
|
2
|
+
import { UiFigmaMessageTexts } from '../types/figmaTypes';
|
|
3
|
+
export declare class FigmaAiText {
|
|
4
|
+
protected readonly ai: AiAbstract;
|
|
5
|
+
protected readonly data: UiFigmaMessageTexts;
|
|
6
|
+
constructor(ai: AiAbstract, data: UiFigmaMessageTexts);
|
|
7
|
+
make(): Promise<this>;
|
|
8
|
+
protected makeImage(): this;
|
|
9
|
+
protected initTexts(): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { FigmaStorageData, FigmaStorageDataValue } from './FigmaStorageData';
|
|
2
|
+
/**
|
|
3
|
+
* Class for working with Figma client storage (clientStorage).
|
|
4
|
+
*
|
|
5
|
+
* Класс для работы с клиентским хранилищем Figma (clientStorage).
|
|
6
|
+
*/
|
|
7
|
+
export declare class FigmaClientStorage<T> {
|
|
8
|
+
protected readonly name: string;
|
|
9
|
+
protected readonly cache?: number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Getting an instance of the class for working with Figma client storage (clientStorage).
|
|
12
|
+
*
|
|
13
|
+
* Получение экземпляра класса для работы с клиентским хранилищем Figma (clientStorage).
|
|
14
|
+
* @param name value name/ название значения
|
|
15
|
+
* @returns current instance/ текущий экземпляр
|
|
16
|
+
*/
|
|
17
|
+
static getInstance<T>(name: string): FigmaClientStorage<T>;
|
|
18
|
+
protected data: FigmaStorageData<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor
|
|
21
|
+
* @param name value name/ название значения
|
|
22
|
+
* @param cache cache time/ время кэширования
|
|
23
|
+
*/
|
|
24
|
+
constructor(name: string, cache?: number | undefined);
|
|
25
|
+
/**
|
|
26
|
+
* Getting data from storage.
|
|
27
|
+
*
|
|
28
|
+
* Получение данных из хранилища.
|
|
29
|
+
* @param defaultValue default value/ значение по умолчанию
|
|
30
|
+
*/
|
|
31
|
+
get(defaultValue?: T | (() => T | Promise<T>)): Promise<T | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Changing data in storage.
|
|
34
|
+
*
|
|
35
|
+
* Изменение данных в хранилище.
|
|
36
|
+
* @param value new values/ новые значения
|
|
37
|
+
* @returns current value/ текущее значение
|
|
38
|
+
*/
|
|
39
|
+
set(value?: T | (() => T | Promise<T>)): Promise<T | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Removing data from storage.
|
|
42
|
+
*
|
|
43
|
+
* Удаление данных из хранилища.
|
|
44
|
+
* @returns current instance/ текущий экземпляр
|
|
45
|
+
*/
|
|
46
|
+
remove(): Promise<this>;
|
|
47
|
+
/**
|
|
48
|
+
* Getting data from storage.
|
|
49
|
+
*
|
|
50
|
+
* Получение данных из хранилища.
|
|
51
|
+
* @returns data from storage/ данные из хранилища
|
|
52
|
+
*/
|
|
53
|
+
protected getValue(): Promise<FigmaStorageDataValue<T> | undefined>;
|
|
54
|
+
/**
|
|
55
|
+
* Making an instance from storage data.
|
|
56
|
+
*
|
|
57
|
+
* Создание экземпляра из данных хранилища.
|
|
58
|
+
* @returns current instance/ текущий экземпляр
|
|
59
|
+
*/
|
|
60
|
+
protected make(): Promise<this>;
|
|
61
|
+
}
|