@dxtmisha/wiki 0.57.1 → 0.57.4

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.
Files changed (151) hide show
  1. package/dist/{defineProperty-3CuEayIP.js → defineProperty-Dcl1xgfx.js} +4 -4
  2. package/dist/library.js +2 -1
  3. package/dist/storybook.js +1 -1
  4. package/package.json +1 -1
  5. package/src/media/functional/figma/classes/FigmaPostAbstract/FigmaPostAbstract.en.mdx +46 -0
  6. package/src/media/functional/figma/classes/FigmaPostAbstract/FigmaPostAbstract.ru.mdx +46 -0
  7. package/src/media/functional/figma/classes/FigmaPostAbstract/FigmaPostAbstract.vi.mdx +46 -0
  8. package/src/media/functional/figma/classes/FigmaPostCode/FigmaPostCode.en.mdx +3 -23
  9. package/src/media/functional/figma/classes/FigmaPostCode/FigmaPostCode.ru.mdx +3 -23
  10. package/src/media/functional/figma/classes/FigmaPostCode/FigmaPostCode.vi.mdx +3 -23
  11. package/src/media/functional/figma/functions/fetchClientStorage/fetchClientStorage.en.mdx +46 -0
  12. package/src/media/functional/figma/functions/fetchClientStorage/fetchClientStorage.ru.mdx +46 -0
  13. package/src/media/functional/figma/functions/fetchClientStorage/fetchClientStorage.vi.mdx +46 -0
  14. package/src/media/functional/figma/functions/fetchFrameSelection/fetchFrameSelection.en.mdx +34 -0
  15. package/src/media/functional/figma/functions/fetchFrameSelection/fetchFrameSelection.ru.mdx +34 -0
  16. package/src/media/functional/figma/functions/fetchFrameSelection/fetchFrameSelection.vi.mdx +34 -0
  17. package/src/media/functional/figma/functions/fetchFrameStyles/fetchFrameStyles.en.mdx +49 -0
  18. package/src/media/functional/figma/functions/fetchFrameStyles/fetchFrameStyles.ru.mdx +49 -0
  19. package/src/media/functional/figma/functions/fetchFrameStyles/fetchFrameStyles.vi.mdx +49 -0
  20. package/src/media/functional/figma/functions/fetchFramesSelected/fetchFramesSelected.en.mdx +19 -8
  21. package/src/media/functional/figma/functions/fetchFramesSelected/fetchFramesSelected.ru.mdx +18 -7
  22. package/src/media/functional/figma/functions/fetchFramesSelected/fetchFramesSelected.vi.mdx +19 -8
  23. package/src/media/functional/figma/functions/fetchStorage/fetchStorage.en.mdx +42 -0
  24. package/src/media/functional/figma/functions/fetchStorage/fetchStorage.ru.mdx +42 -0
  25. package/src/media/functional/figma/functions/fetchStorage/fetchStorage.vi.mdx +42 -0
  26. package/src/media/functional/figma/functions/fetchTopLevelFrames/fetchTopLevelFrames.en.mdx +29 -7
  27. package/src/media/functional/figma/functions/fetchTopLevelFrames/fetchTopLevelFrames.ru.mdx +28 -6
  28. package/src/media/functional/figma/functions/fetchTopLevelFrames/fetchTopLevelFrames.vi.mdx +29 -7
  29. package/src/media/functional/figma/functions/sendClientStorage/sendClientStorage.en.mdx +29 -0
  30. package/src/media/functional/figma/functions/sendClientStorage/sendClientStorage.ru.mdx +29 -0
  31. package/src/media/functional/figma/functions/sendClientStorage/sendClientStorage.vi.mdx +29 -0
  32. package/src/media/functional/figma/functions/sendFrameSelection/sendFrameSelection.en.mdx +28 -0
  33. package/src/media/functional/figma/functions/sendFrameSelection/sendFrameSelection.ru.mdx +28 -0
  34. package/src/media/functional/figma/functions/sendFrameSelection/sendFrameSelection.vi.mdx +28 -0
  35. package/src/media/functional/figma/functions/sendFrameStyles/sendFrameStyles.en.mdx +40 -0
  36. package/src/media/functional/figma/functions/sendFrameStyles/sendFrameStyles.ru.mdx +40 -0
  37. package/src/media/functional/figma/functions/sendFrameStyles/sendFrameStyles.vi.mdx +40 -0
  38. package/src/media/functional/figma/functions/sendFramesSelected/sendFramesSelected.en.mdx +29 -0
  39. package/src/media/functional/figma/functions/sendFramesSelected/sendFramesSelected.ru.mdx +29 -0
  40. package/src/media/functional/figma/functions/sendFramesSelected/sendFramesSelected.vi.mdx +29 -0
  41. package/src/media/functional/figma/functions/sendStorage/sendStorage.en.mdx +30 -0
  42. package/src/media/functional/figma/functions/sendStorage/sendStorage.ru.mdx +30 -0
  43. package/src/media/functional/figma/functions/sendStorage/sendStorage.vi.mdx +30 -0
  44. package/src/media/functional/figma-code/classes/FigmaClientStorage/FigmaClientStorage.en.mdx +64 -0
  45. package/src/media/functional/figma-code/classes/FigmaClientStorage/FigmaClientStorage.ru.mdx +64 -0
  46. package/src/media/functional/figma-code/classes/FigmaClientStorage/FigmaClientStorage.vi.mdx +64 -0
  47. package/src/media/functional/figma-code/classes/FigmaFrame/FigmaFrame.en.mdx +168 -35
  48. package/src/media/functional/figma-code/classes/FigmaFrame/FigmaFrame.ru.mdx +168 -35
  49. package/src/media/functional/figma-code/classes/FigmaFrame/FigmaFrame.vi.mdx +168 -35
  50. package/src/media/functional/figma-code/classes/FigmaFramesSelected/FigmaFramesSelected.en.mdx +23 -69
  51. package/src/media/functional/figma-code/classes/FigmaFramesSelected/FigmaFramesSelected.ru.mdx +22 -68
  52. package/src/media/functional/figma-code/classes/FigmaFramesSelected/FigmaFramesSelected.vi.mdx +23 -69
  53. package/src/media/functional/figma-code/classes/FigmaItem/FigmaItem.en.mdx +79 -56
  54. package/src/media/functional/figma-code/classes/FigmaItem/FigmaItem.ru.mdx +79 -56
  55. package/src/media/functional/figma-code/classes/FigmaItem/FigmaItem.vi.mdx +79 -56
  56. package/src/media/functional/figma-code/classes/FigmaPluginMessenger/FigmaPluginMessenger.en.mdx +18 -48
  57. package/src/media/functional/figma-code/classes/FigmaPluginMessenger/FigmaPluginMessenger.ru.mdx +18 -48
  58. package/src/media/functional/figma-code/classes/FigmaPluginMessenger/FigmaPluginMessenger.vi.mdx +18 -48
  59. package/src/media/functional/figma-code/classes/FigmaStorage/FigmaStorage.en.mdx +22 -67
  60. package/src/media/functional/figma-code/classes/FigmaStorage/FigmaStorage.ru.mdx +22 -67
  61. package/src/media/functional/figma-code/classes/FigmaStorage/FigmaStorage.vi.mdx +22 -67
  62. package/src/media/functional/figma-code/classes/FigmaStorageData/FigmaStorageData.en.mdx +57 -0
  63. package/src/media/functional/figma-code/classes/FigmaStorageData/FigmaStorageData.ru.mdx +57 -0
  64. package/src/media/functional/figma-code/classes/FigmaStorageData/FigmaStorageData.vi.mdx +57 -0
  65. package/src/media/functional/figma-code/classes/FigmaTopLevelFrames/FigmaTopLevelFrames.en.mdx +24 -27
  66. package/src/media/functional/figma-code/classes/FigmaTopLevelFrames/FigmaTopLevelFrames.ru.mdx +23 -26
  67. package/src/media/functional/figma-code/classes/FigmaTopLevelFrames/FigmaTopLevelFrames.vi.mdx +24 -27
  68. package/src/media/functional/figma-code/functions/getFigmaFrameById/getFigmaFrameById.en.mdx +28 -0
  69. package/src/media/functional/figma-code/functions/getFigmaFrameById/getFigmaFrameById.ru.mdx +28 -0
  70. package/src/media/functional/figma-code/functions/getFigmaFrameById/getFigmaFrameById.vi.mdx +28 -0
  71. package/src/media/functional/figma-code/functions/getFigmaItemById/getFigmaItemById.en.mdx +43 -0
  72. package/src/media/functional/figma-code/functions/getFigmaItemById/getFigmaItemById.ru.mdx +43 -0
  73. package/src/media/functional/figma-code/functions/getFigmaItemById/getFigmaItemById.vi.mdx +43 -0
  74. package/src/media/functional/figma-code/functions/getFigmaItemByIdOrRoot/getFigmaItemByIdOrRoot.en.mdx +30 -0
  75. package/src/media/functional/figma-code/functions/getFigmaItemByIdOrRoot/getFigmaItemByIdOrRoot.ru.mdx +30 -0
  76. package/src/media/functional/figma-code/functions/getFigmaItemByIdOrRoot/getFigmaItemByIdOrRoot.vi.mdx +30 -0
  77. package/src/media/functional/figma-code/functions/makeFigmaFrameSelection/makeFigmaFrameSelection.en.mdx +21 -0
  78. package/src/media/functional/figma-code/functions/makeFigmaFrameSelection/makeFigmaFrameSelection.ru.mdx +21 -0
  79. package/src/media/functional/figma-code/functions/makeFigmaFrameSelection/makeFigmaFrameSelection.vi.mdx +21 -0
  80. package/src/media/functional/figma-code/functions/makeFigmaTexts/makeFigmaTexts.en.mdx +28 -0
  81. package/src/media/functional/figma-code/functions/makeFigmaTexts/makeFigmaTexts.ru.mdx +28 -0
  82. package/src/media/functional/figma-code/functions/makeFigmaTexts/makeFigmaTexts.vi.mdx +28 -0
  83. package/src/media/functional/figma-code/functions/setupClientStorage/setupClientStorage.en.mdx +28 -0
  84. package/src/media/functional/figma-code/functions/setupClientStorage/setupClientStorage.ru.mdx +28 -0
  85. package/src/media/functional/figma-code/functions/setupClientStorage/setupClientStorage.vi.mdx +28 -0
  86. package/src/media/functional/figma-code/functions/setupFrameSelection/setupFrameSelection.en.mdx +22 -0
  87. package/src/media/functional/figma-code/functions/setupFrameSelection/setupFrameSelection.ru.mdx +22 -0
  88. package/src/media/functional/figma-code/functions/setupFrameSelection/setupFrameSelection.vi.mdx +22 -0
  89. package/src/media/functional/figma-code/functions/setupFrameStyles/setupFrameStyles.en.mdx +19 -0
  90. package/src/media/functional/figma-code/functions/setupFrameStyles/setupFrameStyles.ru.mdx +19 -0
  91. package/src/media/functional/figma-code/functions/setupFrameStyles/setupFrameStyles.vi.mdx +19 -0
  92. package/src/media/functional/figma-code/functions/setupStorage/setupStorage.en.mdx +28 -0
  93. package/src/media/functional/figma-code/functions/setupStorage/setupStorage.ru.mdx +28 -0
  94. package/src/media/functional/figma-code/functions/setupStorage/setupStorage.vi.mdx +28 -0
  95. package/src/media/functional/figma-code/functions/toFrameSelection/toFrameSelection.en.mdx +27 -0
  96. package/src/media/functional/figma-code/functions/toFrameSelection/toFrameSelection.ru.mdx +27 -0
  97. package/src/media/functional/figma-code/functions/toFrameSelection/toFrameSelection.vi.mdx +27 -0
  98. package/src/media/functional/figma-ref/composables/useFigmaClientStorage/useFigmaClientStorage.en.mdx +26 -0
  99. package/src/media/functional/figma-ref/composables/useFigmaClientStorage/useFigmaClientStorage.ru.mdx +26 -0
  100. package/src/media/functional/figma-ref/composables/useFigmaClientStorage/useFigmaClientStorage.vi.mdx +26 -0
  101. package/src/media/functional/figma-ref/composables/useFigmaFrameSelection/useFigmaFrameSelection.en.mdx +35 -0
  102. package/src/media/functional/figma-ref/composables/useFigmaFrameSelection/useFigmaFrameSelection.ru.mdx +35 -0
  103. package/src/media/functional/figma-ref/composables/useFigmaFrameSelection/useFigmaFrameSelection.vi.mdx +35 -0
  104. package/src/media/functional/figma-ref/composables/useFigmaFrameStyles/useFigmaFrameStyles.en.mdx +33 -0
  105. package/src/media/functional/figma-ref/composables/useFigmaFrameStyles/useFigmaFrameStyles.ru.mdx +33 -0
  106. package/src/media/functional/figma-ref/composables/useFigmaFrameStyles/useFigmaFrameStyles.vi.mdx +33 -0
  107. package/src/media/functional/figma-ref/composables/useFigmaStorage/useFigmaStorage.en.mdx +28 -0
  108. package/src/media/functional/figma-ref/composables/useFigmaStorage/useFigmaStorage.ru.mdx +28 -0
  109. package/src/media/functional/figma-ref/composables/useFigmaStorage/useFigmaStorage.vi.mdx +28 -0
  110. package/src/media/functional/figma-ref/composables/useFigmaUiFrames/useFigmaUiFrames.en.mdx +7 -12
  111. package/src/media/functional/figma-ref/composables/useFigmaUiFrames/useFigmaUiFrames.ru.mdx +7 -12
  112. package/src/media/functional/figma-ref/composables/useFigmaUiFrames/useFigmaUiFrames.vi.mdx +8 -13
  113. package/src/media/functional/figma-ref/composables/useFigmaUiSelected/useFigmaUiSelected.en.mdx +12 -17
  114. package/src/media/functional/figma-ref/composables/useFigmaUiSelected/useFigmaUiSelected.ru.mdx +13 -18
  115. package/src/media/functional/figma-ref/composables/useFigmaUiSelected/useFigmaUiSelected.vi.mdx +14 -19
  116. package/src/media/functional/functional/composables/useApiAsyncRef/useApiAsyncRef.en.mdx +2 -3
  117. package/src/media/functional/functional/composables/useApiAsyncRef/useApiAsyncRef.ru.mdx +2 -3
  118. package/src/media/functional/functional/composables/useApiAsyncRef/useApiAsyncRef.vi.mdx +2 -3
  119. package/src/media/functional/functional/composables/useApiManagementRef/useApiManagementAsyncRef.en.mdx +41 -0
  120. package/src/media/functional/functional/composables/useApiManagementRef/useApiManagementAsyncRef.ru.mdx +41 -0
  121. package/src/media/functional/functional/composables/useApiManagementRef/useApiManagementAsyncRef.vi.mdx +41 -0
  122. package/src/media/functional/functional/composables/useApiManagementRef/useApiManagementRef.en.mdx +12 -0
  123. package/src/media/functional/functional/composables/useApiManagementRef/useApiManagementRef.ru.mdx +12 -0
  124. package/src/media/functional/functional/composables/useApiManagementRef/useApiManagementRef.vi.mdx +6 -0
  125. package/src/media/functional/functional/composables/useApiRef/useApiRef.en.mdx +12 -9
  126. package/src/media/functional/functional/composables/useApiRef/useApiRef.ru.mdx +12 -9
  127. package/src/media/functional/functional/composables/useApiRef/useApiRef.vi.mdx +11 -9
  128. package/src/media/functional/nitro-basic/functions/getInject.en.mdx +27 -0
  129. package/src/media/functional/nitro-basic/functions/getInject.ru.mdx +27 -0
  130. package/src/media/functional/nitro-basic/functions/getInject.vi.mdx +20 -0
  131. package/src/media/functional/ui-figma/about/about.en.mdx +52 -0
  132. package/src/media/functional/ui-figma/about/about.ru.mdx +52 -0
  133. package/src/media/functional/ui-figma/about/about.vi.mdx +52 -0
  134. package/src/media/functional/ui-figma/frames/frames.en.mdx +58 -0
  135. package/src/media/functional/ui-figma/frames/frames.ru.mdx +58 -0
  136. package/src/media/functional/ui-figma/frames/frames.vi.mdx +58 -0
  137. package/src/media/functional/ui-figma/messenger/messenger.en.mdx +67 -0
  138. package/src/media/functional/ui-figma/messenger/messenger.ru.mdx +67 -0
  139. package/src/media/functional/ui-figma/messenger/messenger.vi.mdx +67 -0
  140. package/src/media/functional/ui-figma/selection/selection.en.mdx +65 -0
  141. package/src/media/functional/ui-figma/selection/selection.ru.mdx +65 -0
  142. package/src/media/functional/ui-figma/selection/selection.vi.mdx +65 -0
  143. package/src/media/functional/ui-figma/storage/storage.en.mdx +53 -0
  144. package/src/media/functional/ui-figma/storage/storage.ru.mdx +53 -0
  145. package/src/media/functional/ui-figma/storage/storage.vi.mdx +53 -0
  146. package/src/media/functional/ui-figma/styles/styles.en.mdx +57 -0
  147. package/src/media/functional/ui-figma/styles/styles.ru.mdx +57 -0
  148. package/src/media/functional/ui-figma/styles/styles.vi.mdx +57 -0
  149. /package/src/media/functional/ui/{wiki-data.en.mdx → wiki/wiki-data.en.mdx} +0 -0
  150. /package/src/media/functional/ui/{wiki-data.ru.mdx → wiki/wiki-data.ru.mdx} +0 -0
  151. /package/src/media/functional/ui/{wiki-data.vi.mdx → wiki/wiki-data.vi.mdx} +0 -0
@@ -1,73 +1,96 @@
1
- import {Meta} from '@storybook/addon-docs/blocks'
1
+ import { Meta, Source } from '@storybook/addon-docs/blocks'
2
2
 
3
- <Meta title='@dxtmisha/en/figma-code/Classes/FigmaItem - Node Wrapper'/>
3
+ <Meta title='@dxtmisha/en/figma-code/Classes/FigmaItem - Figma node wrapper'/>
4
4
 
5
- # FigmaItem Class
5
+ # Class `FigmaItem`
6
6
 
7
- A wrapper class for Figma nodes (`UiFigmaNode`) that provides a simplified, typed interface for common operations such as type checking, tree navigation, and asynchronous export.
7
+ A versatile wrapper class for interacting with any type of Figma node. It provides typed methods for type checking, tree navigation, and common operations such as exporting and viewport management.
8
8
 
9
9
  ## Key Features
10
10
 
11
- - **Typed Access** — Provides type guard methods for `DOCUMENT`, `FRAME`, `SECTION`, and `TEXT` nodes.
12
- - **Simplified Navigation** — Easily access parent or child nodes wrapped in `FigmaItem` instances.
13
- - **Export Hook** — High-level methods for exporting nodes to JPG or JSON formats.
14
- - **Content Analysis** — Specialized logic for extracting and validating text content.
11
+ - **Type Safety** — Utilizes Type Guards (`isFrame`, `isText`, etc.) for safe access to properties specific to certain node types.
12
+ - **Fluent Navigation** — Convenient methods for retrieving parent elements or child nodes already wrapped in `FigmaItem` instances.
13
+ - **Integrated Actions** — Built-in support for exporting nodes to JPG/JSON and controlling the Figma viewport (selection and zoom).
15
14
 
16
15
  ## Initialization
17
16
 
18
- To initialize the object, call the `FigmaItem(item)` constructor.
19
-
20
- ### Generic Constraints
21
-
22
- The class supports a generic parameter for strict typing:
23
- - `T extends UiFigmaNode` — The specific type of the wrapped Figma node.
24
-
25
- **Parameters:**
26
- - `item: T` — The native Figma node (e.g., `SceneNode`, `FrameNode`, `TextNode`) to be wrapped.
17
+ Wrap any Figma node in a `FigmaItem` instance to access its helper methods.
27
18
 
28
19
  ```typescript
29
20
  import { FigmaItem } from '@dxtmisha/figma-code'
30
21
 
31
- // 1. Wrapping a selected node
22
+ // Wrap a node (e.g., from selection)
32
23
  const item = new FigmaItem(figma.currentPage.selection[0])
33
24
 
34
- // 2. Using generics for specific node types
35
- const frameItem = new FigmaItem<FrameNode>(someFrameNode)
25
+ if (item.isFrame()) {
26
+ console.log('Node is a frame:', item.getName())
27
+ }
36
28
  ```
37
29
 
38
- ## Identification
39
-
40
- - `isDocument(): boolean` — Checks if the wrapped node is a `DOCUMENT`. Example: `item.isDocument()`
41
- - `isFrame(): boolean` — Checks if the wrapped node is a `FRAME`. Example: `item.isFrame()`
42
- - `isSection(): boolean` — Checks if the wrapped node is a `SECTION`. Example: `item.isSection()`
43
- - `isText(): boolean` — Checks if the wrapped node is a `TEXT` node. Example: `item.isText()`
44
- - `isTextNoValue(): boolean` — Filters for text nodes with meaningful content. Example: `item.isTextNoValue()`
45
- - `getType(): string | undefined` — Returns the string type constant of the node. Example: `const type = item.getType()`
46
- - `getId(): string` — Returns the unique ID of the node. Example: `const id = item.getId()`
47
- - `getName(): string` — Returns the display name of the node. Example: `const name = item.getName()`
48
-
49
- ## Navigation
50
-
51
- - `getParent(): UiFigmaNode | undefined` — Returns the raw parent node. Example: `const parent = item.getParent()`
52
- - `getParentItem(): FigmaItem | undefined` — Returns the wrapped parent. Example: `const parentItem = item.getParentItem()`
53
- - `getChildren(): UiFigmaNode[]` — Returns an array of raw child nodes. Example: `const children = item.getChildren()`
54
- - `getChildrenItems(): FigmaItem[]` — Returns an array of wrapped child nodes. Example: `const items = item.getChildrenItems()`
55
-
56
- ## Data & Export
57
-
58
- - `get(): T` — Returns the raw underlying Figma node. Example: `const raw = item.get()`
59
- - `exportJpg(): Promise<Uint8Array | string>` — Asynchronously exports the node in JPG format. Example: `const bytes = await item.exportJpg()`
60
- - `exportJson(): Promise<Uint8Array | string>` — Asynchronously exports the node in JSON format. Example: `const json = await item.exportJson()`
61
- - `getText(): string` — Retrieves the trimmed text content from the node. Example: `const content = item.getText()`
62
-
63
- ## Types
64
-
65
- ### `UiFigmaNode`
66
-
67
- A union type representing any relevant Figma node that can be wrapped by `FigmaItem`.
68
- - Includes: `DocumentNode`, `PageNode`, `FrameNode`, `SectionNode`, `TextNode`, and other `SceneNode` variants.
69
-
70
- ### `UiFigmaExportFormat`
71
-
72
- Supported formats for node export operations.
73
- - Values: `'PNG'`, `'JPG'`, `'SVG'`, `'PDF'`, `'JSON_REST_V1'`.
30
+ ## Methods
31
+
32
+ ### Type Guards
33
+
34
+ - `isDocument(): boolean` — Checks if the node is a Document.
35
+ - `isFrame(): boolean` — Checks if the node is a Frame.
36
+ - `isSection(): boolean` — Checks if the node is a Section.
37
+ - `isText(): boolean` — Checks if the node is a Text node.
38
+ - `isTextNoValue(): boolean` — Checks if the node is a text node with meaningful content.
39
+ - `inCurrentPage(): boolean` — Checks if the node belongs to the current active page.
40
+
41
+ ### Hierarchy and Navigation
42
+
43
+ - `get(): T` — Returns the original Figma node.
44
+ - `getParent(): UiFigmaNode | undefined` — Returns the original parent node.
45
+ - `getParentItem(): FigmaItem | undefined` — Returns the parent node wrapped in `FigmaItem`.
46
+ - `getParentPage(): PageNode | undefined` — Returns the parent page of the node.
47
+ - `getParentPageItem(): FigmaItem | undefined` — Returns the parent page wrapped in `FigmaItem`.
48
+ - `getChildren(): UiFigmaNode[]` — Returns the list of child nodes in original format.
49
+ - `getChildrenItems(): FigmaItem[]` — Returns all child nodes wrapped in `FigmaItem`.
50
+
51
+ ### Content and Information
52
+
53
+ - `getId(): string` — Returns the unique identifier of the node.
54
+ - `getName(): string` — Returns the name of the node.
55
+ - `getType(): string` — Returns the node type string.
56
+ - `getText(): string` — Returns the text content (for text nodes only).
57
+ - `getInfo(): Promise<UiFigmaFramesItem>` — Asynchronously collects basic node information (name, ID, screenshot).
58
+ - `getCss(): Promise<Record<string, string>>` — Asynchronously extracts CSS styles of the node.
59
+ - `getStyles(): Promise<UiFigmaFrameStylesItem>` Asynchronously extracts extended style information (CSS, text, JSON).
60
+
61
+ ### Export and Actions
62
+
63
+ - `exportJpg(): Promise<Uint8Array>` — Exports the node as a JPG image.
64
+ - `exportJson(): Promise<any>` — Exports full node data in JSON format.
65
+ - `exportJsonCompact(): Promise<UiFigmaFrameStylesData | undefined>` Exports node data in a compact JSON format.
66
+ - `toSelection(): void` — Selects the node and focuses the viewport on it.
67
+ - `toPageAndSelection(): Promise<void>` — Switches to the node's page and selects it.
68
+
69
+ ## Data Types
70
+
71
+ #### `UiFigmaFramesItem`
72
+ Simplified information about an element for display in the interface.
73
+ - `name: string` — The name of the element in Figma.
74
+ - `id: string` — The unique identifier of the node.
75
+ - `image?: Uint8Array | string` — A screenshot of the element (binary data or base64).
76
+
77
+ #### `UiFigmaFrameStylesItem`
78
+ Extended information about an element, including its styles. Inherits all fields from `UiFigmaFramesItem`.
79
+ - `json?: UiFigmaFrameStylesData` — Node data and styles structure in JSON format.
80
+ - `text?: string` — Text content (if the node is a text node).
81
+ - `styles?: Record<string, string>` — An object with CSS properties of the element itself.
82
+ - `childrenStyles?: Record<string, Record<string, string>>` — A map of CSS styles for all child elements, indexed by their ID.
83
+
84
+ #### `UiFigmaFrameStylesData`
85
+ - `document: UiFigmaFrameStylesJson` — Node tree in a compact format.
86
+ - `styles: Record<string, any>` — A dictionary of document style definitions.
87
+
88
+ #### `UiFigmaFrameStylesJson`
89
+ Compact representation of a Figma node for JSON export.
90
+ - `id: string` — Unique identifier of the node.
91
+ - `name: string` — Name of the node.
92
+ - `type: string` — Type of the node.
93
+ - `characters?: string` — Text (for text nodes).
94
+ - `children?: UiFigmaFrameStylesJson[]` — Recursive list of child elements.
95
+ - `style?: Record<string, any>` — Appearance parameters.
96
+ - `styles?: Record<string, any>` — Associated styles.
@@ -1,73 +1,96 @@
1
- import {Meta} from '@storybook/addon-docs/blocks'
1
+ import { Meta, Source } from '@storybook/addon-docs/blocks'
2
2
 
3
- <Meta title='@dxtmisha/ru/figma-code/Classes/FigmaItem - Обертка узла'/>
3
+ <Meta title='@dxtmisha/ru/figma-code/Classes/FigmaItem - Обертка для узлов Figma'/>
4
4
 
5
- # Класс FigmaItem
5
+ # Класс `FigmaItem`
6
6
 
7
- Класс-обертка для узлов Figma (`UiFigmaNode`), который предоставляет упрощенный типизированный интерфейс для общих операций, таких как проверка типа, навигация по дереву и асинхронный экспорт.
7
+ Универсальный класс-обертка для работы с любыми типами узлов Figma. Предоставляет типизированные методы для проверки типов, навигации по дереву элементов и выполнения частых операций, таких как экспорт и управление вьюпортом.
8
8
 
9
9
  ## Ключевые особенности
10
10
 
11
- - **Типизированный доступ** Предоставляет методы-тайпгарды для узлов `DOCUMENT`, `FRAME`, `SECTION` и `TEXT`.
12
- - **Упрощенная навигация** — Легкий доступ к родительским или дочерним узлам, обернутым в экземпляры `FigmaItem`.
13
- - **Экспорт**Высокоуровневые методы для экспорта узлов в форматы JPG или JSON.
14
- - **Анализ контента** — Специализированная логика для извлечения и валидации текстового содержимого.
11
+ - **Типобезопасность**Использует Type Guards (`isFrame`, `isText` и т. д.) для безопасного доступа к свойствам конкретных типов узлов.
12
+ - **Удобная навигация** — Методы для получения родительских элементов или дочерних узлов, уже обернутых в экземпляры `FigmaItem`.
13
+ - **Встроенные действия** Поддержка экспорта узлов в JPG/JSON и управления вьюпортом Figma (выделение и масштабирование).
15
14
 
16
15
  ## Инициализация
17
16
 
18
- Для инициализации объекта вызовите конструктор `FigmaItem(item)`.
19
-
20
- ### Ограничения универсальных типов (Generics)
21
-
22
- Класс поддерживает параметр универсального типа для строгой типизации:
23
- - `T extends UiFigmaNode` — Конкретный тип обернутого узла Figma.
24
-
25
- **Параметры:**
26
- - `item: T` — Нативный узел Figma (например, `SceneNode`, `FrameNode`, `TextNode`), который необходимо обернуть.
17
+ Оберните любой узел Figma в экземпляр `FigmaItem`, чтобы получить доступ к его вспомогательным методам.
27
18
 
28
19
  ```typescript
29
20
  import { FigmaItem } from '@dxtmisha/figma-code'
30
21
 
31
- // 1. Обертывание текущего выделенного узла
22
+ // Обертывание узла (например, из выделения)
32
23
  const item = new FigmaItem(figma.currentPage.selection[0])
33
24
 
34
- // 2. Использование дженериков для конкретных типов узлов
35
- const frameItem = new FigmaItem<FrameNode>(someFrameNode)
25
+ if (item.isFrame()) {
26
+ console.log('Узел является фреймом:', item.getName())
27
+ }
36
28
  ```
37
29
 
38
- ## Идентификация узла
39
-
40
- - `isDocument(): boolean` — Проверяет, является ли узел документом. Пример: `item.isDocument()`
41
- - `isFrame(): boolean` — Проверяет, является ли узел фреймом. Пример: `item.isFrame()`
42
- - `isSection(): boolean` — Проверяет, является ли узел секцией. Пример: `item.isSection()`
43
- - `isText(): boolean` — Проверяет, является ли узел текстовым. Пример: `item.isText()`
44
- - `isTextNoValue(): boolean` — Фильтрует текстовые узлы со значимым контентом. Пример: `item.isTextNoValue()`
45
- - `getType(): string | undefined` — Возвращает строковую константу типа узла. Пример: `const type = item.getType()`
46
- - `getId(): string` — Возвращает уникальный ID узла. Пример: `const id = item.getId()`
47
- - `getName(): string` — Возвращает отображаемое имя узла. Пример: `const name = item.getName()`
48
-
49
- ## Навигация
50
-
51
- - `getParent(): UiFigmaNode | undefined` — Возвращает нативный родительский узел. Пример: `const parent = item.getParent()`
52
- - `getParentItem(): FigmaItem | undefined` — Возвращает родителя, обернутого в `FigmaItem`. Пример: `const parentItem = item.getParentItem()`
53
- - `getChildren(): UiFigmaNode[]` — Возвращает массив нативных дочерних узлов. Пример: `const children = item.getChildren()`
54
- - `getChildrenItems(): FigmaItem[]` — Возвращает массив обернутых дочерних узлов. Пример: `const items = item.getChildrenItems()`
55
-
56
- ## Данные и экспорт
57
-
58
- - `get(): T` — Возвращает исходный нативный узел Figma. Пример: `const raw = item.get()`
59
- - `exportJpg(): Promise<Uint8Array | string>` — Асинхронно экспортирует узел в JPG. Пример: `const bytes = await item.exportJpg()`
60
- - `exportJson(): Promise<Uint8Array | string>` — Асинхронно экспортирует узел в JSON. Пример: `const json = await item.exportJson()`
61
- - `getText(): string` — Извлекает очищенное текстовое содержимое. Пример: `const content = item.getText()`
62
-
63
- ## Типы (Types)
64
-
65
- ### `UiFigmaNode`
66
-
67
- Тип-объединение (union), представляющий любой релевантный узел Figma, который может быть обернут в `FigmaItem`.
68
- - Включает: `DocumentNode`, `PageNode`, `FrameNode`, `SectionNode`, `TextNode` и другие варианты `SceneNode`.
69
-
70
- ### `UiFigmaExportFormat`
71
-
72
- Поддерживаемые форматы для операций экспорта узлов.
73
- - Значения: `'PNG'`, `'JPG'`, `'SVG'`, `'PDF'`, `'JSON_REST_V1'`.
30
+ ## Методы
31
+
32
+ ### Проверка типов
33
+
34
+ - `isDocument(): boolean` — Проверяет, является ли узел документом.
35
+ - `isFrame(): boolean` — Проверяет, является ли узел фреймом.
36
+ - `isSection(): boolean` — Проверяет, является ли узел секцией.
37
+ - `isText(): boolean` — Проверяет, является ли узел текстовым узлом.
38
+ - `isTextNoValue(): boolean` — Проверяет, является ли узел текстовым узлом с осмысленным содержанием.
39
+ - `inCurrentPage(): boolean` — Проверяет, принадлежит ли узел текущей активной странице.
40
+
41
+ ### Иерархия и навигация
42
+
43
+ - `get(): T` — Возвращает исходный узел Figma.
44
+ - `getParent(): UiFigmaNode | undefined` — Возвращает исходный родительский узел.
45
+ - `getParentItem(): FigmaItem | undefined` — Возвращает родительский узел, обернутый в `FigmaItem`.
46
+ - `getParentPage(): PageNode | undefined` — Возвращает родительскую страницу узла.
47
+ - `getParentPageItem(): FigmaItem | undefined` — Возвращает родительскую страницу, обернутую в `FigmaItem`.
48
+ - `getChildren(): UiFigmaNode[]` — Возвращает список дочерних узлов в исходном формате.
49
+ - `getChildrenItems(): FigmaItem[]` — Возвращает все дочерние узлы, обернутые в `FigmaItem`.
50
+
51
+ ### Контент и информация
52
+
53
+ - `getId(): string` — Возвращает уникальный идентификатор узла.
54
+ - `getName(): string` — Возвращает имя узла.
55
+ - `getType(): string` — Возвращает строку с типом узла.
56
+ - `getText(): string` — Возвращает текстовое содержимое (только для текстовых узлов).
57
+ - `getInfo(): Promise<UiFigmaFramesItem>` — Асинхронно собирает базовую информацию об узле (имя, ID, скриншот).
58
+ - `getCss(): Promise<Record<string, string>>` — Асинхронно извлекает CSS-стили текущего узла.
59
+ - `getStyles(): Promise<UiFigmaFrameStylesItem>` Асинхронно извлекает расширенную информацию о стилях (CSS, текст, JSON).
60
+
61
+ ### Экспорт и действия
62
+
63
+ - `exportJpg(): Promise<Uint8Array>` — Экспортирует узел как изображение JPG.
64
+ - `exportJson(): Promise<any>` Экспортирует полные данные узла в формате JSON.
65
+ - `exportJsonCompact(): Promise<UiFigmaFrameStylesData | undefined>` — Экспортирует данные узла в компактном формате JSON.
66
+ - `toSelection(): void` — Выделяет узел и фокусирует на нем вьюпорт.
67
+ - `toPageAndSelection(): Promise<void>` — Переключается на страницу узла и выделяет его.
68
+
69
+ ## Типы данных
70
+
71
+ #### `UiFigmaFramesItem`
72
+ Базовая информация об элементе для отображения в интерфейсе.
73
+ - `name: string` — Название элемента в Figma.
74
+ - `id: string` — Уникальный идентификатор узла.
75
+ - `image?: Uint8Array | string` — Скриншот элемента (бинарные данные или base64).
76
+
77
+ #### `UiFigmaFrameStylesItem`
78
+ Расширенная информация об элементе, включая его стили. Наследует все поля `UiFigmaFramesItem`.
79
+ - `json?: UiFigmaFrameStylesData` — Структура данных узла и стилей в формате JSON.
80
+ - `text?: string` — Текстовое содержимое (если узел является текстовым).
81
+ - `styles?: Record<string, string>` — Объект с CSS-свойствами самого элемента.
82
+ - `childrenStyles?: Record<string, Record<string, string>>` — Карта CSS-стилей для всех дочерних элементов, индексированная по их ID.
83
+
84
+ #### `UiFigmaFrameStylesData`
85
+ - `document: UiFigmaFrameStylesJson` — Дерево узлов в компактном формате.
86
+ - `styles: Record<string, any>` — Словарь определений стилей документа.
87
+
88
+ #### `UiFigmaFrameStylesJson`
89
+ Компактное представление узла Figma для JSON-экспорта.
90
+ - `id: string` — Уникальный идентификатор узла.
91
+ - `name: string` — Имя узла.
92
+ - `type: string` — Тип узла.
93
+ - `characters?: string` — Текст (для текстовых узлов).
94
+ - `children?: UiFigmaFrameStylesJson[]` — Рекурсивный список дочерних элементов.
95
+ - `style?: Record<string, any>` — Параметры оформления.
96
+ - `styles?: Record<string, any>` — Связанные стили.
@@ -1,73 +1,96 @@
1
- import {Meta} from '@storybook/addon-docs/blocks'
1
+ import { Meta, Source } from '@storybook/addon-docs/blocks'
2
2
 
3
- <Meta title='@dxtmisha/vi/figma-code/Classes/FigmaItem - Node Wrapper'/>
3
+ <Meta title='@dxtmisha/vi/figma-code/Classes/FigmaItem - Lớp bọc node Figma'/>
4
4
 
5
- # Lớp FigmaItem
5
+ # Lớp `FigmaItem`
6
6
 
7
- Một lớp wrapper cho các node Figma (`UiFigmaNode`) cung cấp giao diện được định nghĩa kiểu dữ liệu đơn giản cho các thao tác phổ biến như kiểm tra loại node, điều hướng cây node và xuất dữ liệu không đồng bộ.
7
+ Một lớp bọc đa năng để tương tác với bất kỳ loại node Figma nào. cung cấp các phương thức được định kiểu để kiểm tra kiểu, điều hướng cây node và các hoạt động phổ biến như xuất dữ liệu quản lý khung nhìn (viewport).
8
8
 
9
9
  ## Các tính năng chính
10
10
 
11
- - **Truy cập định kiểu** — Cung cấp các phương thức type guard cho các node `DOCUMENT`, `FRAME`, `SECTION`, `TEXT`.
12
- - **Điều hướng đơn giản** — Dễ dàng truy cập các node cha hoặc con được bọc trong các thực thể `FigmaItem`.
13
- - **Hỗ trợ Export** — Các phương thức cấp cao để xuất các node sang định dạng JPG hoặc JSON.
14
- - **Phân tích nội dung** — Logic chuyên biệt để trích xuất và xác thực nội dung văn bản.
11
+ - **An toàn kiểu dữ liệu** — Sử dụng Type Guards (`isFrame`, `isText`, v.v.) để truy cập an toàn vào các thuộc tính cụ thể của một số loại node.
12
+ - **Điều hướng linh hoạt** — Các phương thức thuận tiện để truy xuất các phần tử cha hoặc các node con đã được bọc trong các thực thể `FigmaItem`.
13
+ - **Hành động tích hợp** — Hỗ trợ tích hợp để xuất các node sang JPG/JSON điều khiển khung nhìn Figma (lựa chọn và thu phóng).
15
14
 
16
15
  ## Khởi tạo
17
16
 
18
- Để khởi tạo đối tượng, hãy gọi hàm dựng `FigmaItem(item)`.
19
-
20
- ### Ràng buộc Generics
21
-
22
- Lớp hỗ trợ một tham số generic để định kiểu nghiêm ngặt:
23
- - `T extends UiFigmaNode` — Loại cụ thể của node Figma được bọc.
24
-
25
- **Tham số:**
26
- - `item: T` — Node Figma gốc (ví dụ: `SceneNode`, `FrameNode`, `TextNode`) cần được bọc.
17
+ Bọc bất kỳ node Figma nào trong một thực thể `FigmaItem` để truy cập các phương thức hỗ trợ của nó.
27
18
 
28
19
  ```typescript
29
20
  import { FigmaItem } from '@dxtmisha/figma-code'
30
21
 
31
- // 1. Bọc một node đang được chọn
22
+ // Bọc một node (ví dụ: từ vùng lựa chọn)
32
23
  const item = new FigmaItem(figma.currentPage.selection[0])
33
24
 
34
- // 2. Sử dụng generics cho các loại node cụ thể
35
- const frameItem = new FigmaItem<FrameNode>(someFrameNode)
25
+ if (item.isFrame()) {
26
+ console.log('Node một frame:', item.getName())
27
+ }
36
28
  ```
37
29
 
38
- ## Định danh Node
39
-
40
- - `isDocument(): boolean` — Kiểm tra xem node được bọc có phải là DOCUMENT hay không. Ví dụ: `item.isDocument()`
41
- - `isFrame(): boolean` — Kiểm tra xem node có phải là FRAME hay không. Ví dụ: `item.isFrame()`
42
- - `isSection(): boolean` — Kiểm tra xem node có phải SECTION hay không. Ví dụ: `item.isSection()`
43
- - `isText(): boolean` — Kiểm tra xem node có phải TEXT hay không. Ví dụ: `item.isText()`
44
- - `isTextNoValue(): boolean` — Lọc các node văn bản có nội dung ý nghĩa. Ví dụ: `item.isTextNoValue()`
45
- - `getType(): string | undefined` — Trả về hằng số chuỗi loại của node. Ví dụ: `const type = item.getType()`
46
- - `getId(): string` — Trả về ID duy nhất của node. dụ: `const id = item.getId()`
47
- - `getName(): string` — Trả về tên hiển thị của node. dụ: `const name = item.getName()`
48
-
49
- ## Điều hướng
50
-
51
- - `getParent(): UiFigmaNode | undefined` — Trả về node cha gốc. Ví dụ: `const parent = item.getParent()`
52
- - `getParentItem(): FigmaItem | undefined` — Trả về node cha được bọc. Ví dụ: `const parentItem = item.getParentItem()`
53
- - `getChildren(): UiFigmaNode[]` — Trả về một mảng các node con gốc. dụ: `const children = item.getChildren()`
54
- - `getChildrenItems(): FigmaItem[]` — Trả về một mảng các node con đã bọc. Ví dụ: `const items = item.getChildrenItems()`
55
-
56
- ## Dữ liệu & Xuất bản
57
-
58
- - `get(): T` — Trả về node Figma gốc bên dưới. Ví dụ: `const raw = item.get()`
59
- - `exportJpg(): Promise<Uint8Array | string>` — Xuất node sang định dạng JPG. Ví dụ: `const bytes = await item.exportJpg()`
60
- - `exportJson(): Promise<Uint8Array | string>` — Xuất node sang định dạng JSON. Ví dụ: `const json = await item.exportJson()`
61
- - `getText(): string` — Lấy nội dung văn bản đã làm sạch. Ví dụ: `const content = item.getText()`
62
-
63
- ## Các loại dữ liệu (Types)
64
-
65
- ### `UiFigmaNode`
66
-
67
- Một kiểu union đại diện cho bất kỳ node Figma nào liên quan thể được bọc bởi `FigmaItem`.
68
- - Bao gồm: `DocumentNode`, `PageNode`, `FrameNode`, `SectionNode`, `TextNode`, và các biến thể `SceneNode` khác.
69
-
70
- ### `UiFigmaExportFormat`
71
-
72
- Các định dạng được hỗ trợ cho các thao tác xuất (export) node.
73
- - Các giá trị: `'PNG'`, `'JPG'`, `'SVG'`, `'PDF'`, `'JSON_REST_V1'`.
30
+ ## Các phương thức
31
+
32
+ ### Kiểm tra kiểu (Type Guards)
33
+
34
+ - `isDocument(): boolean` — Kiểm tra xem node là Document.
35
+ - `isFrame(): boolean` — Kiểm tra xem node là Frame.
36
+ - `isSection(): boolean` — Kiểm tra xem node Section.
37
+ - `isText(): boolean` — Kiểm tra xem node Text node.
38
+ - `isTextNoValue(): boolean` — Kiểm tra xem node nội dung ý nghĩa hay không.
39
+ - `inCurrentPage(): boolean` — Kiểm tra xem node thuộc trang đang hoạt động hay không.
40
+
41
+ ### Hệ thống cấp bậc và Điều hướng
42
+
43
+ - `get(): T` — Trả về node Figma gốc.
44
+ - `getParent(): UiFigmaNode | undefined` — Trả về node cha gốc.
45
+ - `getParentItem(): FigmaItem | undefined` — Trả về node cha được bọc trong `FigmaItem`.
46
+ - `getParentPage(): PageNode | undefined` — Trả về trang cha của node.
47
+ - `getParentPageItem(): FigmaItem | undefined` — Trả về trang cha được bọc trong `FigmaItem`.
48
+ - `getChildren(): UiFigmaNode[]` Trả về danh sách các node con ở định dạng gốc.
49
+ - `getChildrenItems(): FigmaItem[]` — Trả về tất cả các node con được bọc trong `FigmaItem`.
50
+
51
+ ### Nội dung Thông tin
52
+
53
+ - `getId(): string` — Trả về định danh duy nhất của node.
54
+ - `getName(): string` — Trả về tên của node.
55
+ - `getType(): string` Trả về chuỗi kiểu node.
56
+ - `getText(): string` — Trả về nội dung văn bản (chỉ dành cho text node).
57
+ - `getInfo(): Promise<UiFigmaFramesItem>` — Thu thập thông tin cơ bản về node (tên, ID, ảnh chụp màn hình) một cách không đồng bộ.
58
+ - `getCss(): Promise<Record<string, string>>` — Trích xuất các style CSS của node một cách không đồng bộ.
59
+ - `getStyles(): Promise<UiFigmaFrameStylesItem>` Trích xuất thông tin style mở rộng (CSS, văn bản, JSON) một cách không đồng bộ.
60
+
61
+ ### Xuất và Hành động
62
+
63
+ - `exportJpg(): Promise<Uint8Array>` — Xuất node dưới dạng hình ảnh JPG.
64
+ - `exportJson(): Promise<any>` Xuất dữ liệu node đầy đủ định dạng JSON.
65
+ - `exportJsonCompact(): Promise<UiFigmaFrameStylesData | undefined>` Xuất dữ liệu node ở định dạng JSON thu gọn.
66
+ - `toSelection(): void` — Chọn node và tập trung khung nhìn vào nó.
67
+ - `toPageAndSelection(): Promise<void>` — Chuyển đến trang của node và chọn nó.
68
+
69
+ ## Các kiểu dữ liệu
70
+
71
+ #### `UiFigmaFramesItem`
72
+ Thông tin đơn giản hóa về một phần tử để hiển thị trong giao diện.
73
+ - `name: string` — Tên của phần tử trong Figma.
74
+ - `id: string` — Định danh duy nhất của node.
75
+ - `image?: Uint8Array | string` — Ảnh chụp màn hình của phần tử (dữ liệu nhị phân hoặc base64).
76
+
77
+ #### `UiFigmaFrameStylesItem`
78
+ Thông tin mở rộng về một phần tử, bao gồm style của nó. Kế thừa tất cả các trường từ `UiFigmaFramesItem`.
79
+ - `json?: UiFigmaFrameStylesData` — Cấu trúc dữ liệu node và style dưới định dạng JSON.
80
+ - `text?: string` — Nội dung văn bản (nếu node là một node văn bản).
81
+ - `styles?: Record<string, string>` — Một đối tượng chứa các thuộc tính CSS của chính phần tử đó.
82
+ - `childrenStyles?: Record<string, Record<string, string>>` — Bản đồ các style CSS cho tất cả các phần tử con, được lập chỉ mục theo ID của chúng.
83
+
84
+ #### `UiFigmaFrameStylesData`
85
+ - `document: UiFigmaFrameStylesJson` — Cây node dưới định dạng nén.
86
+ - `styles: Record<string, any>` — Một từ điển các định nghĩa style của tài liệu.
87
+
88
+ #### `UiFigmaFrameStylesJson`
89
+ Biểu diễn thu gọn của một node Figma để xuất JSON.
90
+ - `id: string` — Định danh duy nhất của node.
91
+ - `name: string` — Tên node.
92
+ - `type: string` — Kiểu node.
93
+ - `characters?: string` — Văn bản (cho text node).
94
+ - `children?: UiFigmaFrameStylesJson[]` — Danh sách các phần tử con đệ quy.
95
+ - `style?: Record<string, any>` — Các tham số ngoại hình.
96
+ - `styles?: Record<string, any>` — Các style liên quan.
@@ -1,63 +1,33 @@
1
- import {Meta} from '@storybook/addon-docs/blocks'
1
+ import { Meta, Source } from '@storybook/addon-docs/blocks'
2
2
 
3
- <Meta title='@dxtmisha/en/figma-code/Classes/FigmaPluginMessenger - Backend Messenger'/>
3
+ <Meta title='@dxtmisha/en/figma-code/Classes/FigmaPluginMessenger - Plugin messenger (Backend)'/>
4
4
 
5
- # FigmaPluginMessenger Class
5
+ # Class `FigmaPluginMessenger`
6
6
 
7
- Messenger for the Figma plugin side (backend). It handles sending messages to the Figma UI and listening for messages from the UI using the internal Figma `figma.ui` API.
7
+ 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).
8
+
9
+ ## Key Features
10
+
11
+ - **Singleton Architecture** — Use `getInstance()` to ensure all parts of the plugin use the same communication hub.
12
+ - **Simplified API** — Wraps standard `figma.ui.postMessage` and `figma.ui.onmessage` into a more manageable interface.
13
+ - **Type Safety** — Supports generic types for messages to ensure data consistency.
8
14
 
9
15
  ## Initialization
10
16
 
11
- Extends `FigmaPostAbstract`.
17
+ Access the singleton instance using the static `getInstance()` method.
12
18
 
13
19
  ```typescript
14
20
  import { FigmaPluginMessenger } from '@dxtmisha/figma-code'
15
21
 
16
- const messenger = new FigmaPluginMessenger()
17
- .make()
18
- .add('hello-ui', (msg) => console.log('UI:', msg))
19
- ```
20
-
21
- ## Public Methods
22
-
23
- ### `make`
24
-
25
- Initializes the message listener using the `figma.ui.onmessage` API. Should be called once to start receiving messages from the UI.
26
-
27
- **Returns:** `this`
28
-
29
- ```javascript
30
- messenger.make()
22
+ const messenger = FigmaPluginMessenger.getInstance()
31
23
  ```
32
24
 
33
- ### `add`
25
+ ## Methods
34
26
 
35
- Registers a listener for a specific message type coming from the UI.
27
+ ### Communication
36
28
 
37
- **Parameters:**
38
- - `type: string` — Unique identifier for the message type to listen for.
39
- - `callback: (message: Message) => void` — function to execute when a matching message arrives.
29
+ Methods for sending and receiving messages.
40
30
 
41
- **Returns:** `this`
42
-
43
- ```javascript
44
- messenger.add('resize-ui', (data) => {
45
- figma.ui.resize(data.width, data.height)
46
- })
47
- ```
48
-
49
- ### `post`
50
-
51
- Sends a message to the Figma UI side.
52
-
53
- **Parameters:**
54
- - `type: string` — The identifier of the message (type).
55
- - `message: Message` — (Optional) Data payload to send to the UI.
56
-
57
- **Returns:** `void`
58
-
59
- ```javascript
60
- messenger.post('selection-data', {
61
- ids: figma.currentPage.selection.map(node => node.id)
62
- })
63
- ```
31
+ - `post<Message>(type: string, message?: Message): void` — Sends a message of a specific type to the Figma UI.
32
+ - `add(type: string, callback: (data: any) => void): this` — (Inherited) Registers a listener for messages from the UI.
33
+ - `remove(type: string): this` — (Inherited) Removes a listener.