figma-metadata-extractor 1.0.8 → 1.0.10
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/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/lib.d.ts +51 -3
- package/dist/utils/image-processing.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -420,7 +420,7 @@ class FigmaService {
|
|
|
420
420
|
cropTransform,
|
|
421
421
|
requiresImageDimensions,
|
|
422
422
|
returnBuffer
|
|
423
|
-
) : null;
|
|
423
|
+
).then((result) => ({ ...result, nodeId })) : null;
|
|
424
424
|
}).filter((promise) => promise !== null);
|
|
425
425
|
if (pngDownloads.length > 0) {
|
|
426
426
|
downloadPromises.push(Promise.all(pngDownloads));
|
|
@@ -443,7 +443,7 @@ class FigmaService {
|
|
|
443
443
|
cropTransform,
|
|
444
444
|
requiresImageDimensions,
|
|
445
445
|
returnBuffer
|
|
446
|
-
) : null;
|
|
446
|
+
).then((result) => ({ ...result, nodeId })) : null;
|
|
447
447
|
}).filter((promise) => promise !== null);
|
|
448
448
|
if (svgDownloads.length > 0) {
|
|
449
449
|
downloadPromises.push(Promise.all(svgDownloads));
|
package/dist/index.js
CHANGED
|
@@ -418,7 +418,7 @@ class FigmaService {
|
|
|
418
418
|
cropTransform,
|
|
419
419
|
requiresImageDimensions,
|
|
420
420
|
returnBuffer
|
|
421
|
-
) : null;
|
|
421
|
+
).then((result) => ({ ...result, nodeId })) : null;
|
|
422
422
|
}).filter((promise) => promise !== null);
|
|
423
423
|
if (pngDownloads.length > 0) {
|
|
424
424
|
downloadPromises.push(Promise.all(pngDownloads));
|
|
@@ -441,7 +441,7 @@ class FigmaService {
|
|
|
441
441
|
cropTransform,
|
|
442
442
|
requiresImageDimensions,
|
|
443
443
|
returnBuffer
|
|
444
|
-
) : null;
|
|
444
|
+
).then((result) => ({ ...result, nodeId })) : null;
|
|
445
445
|
}).filter((promise) => promise !== null);
|
|
446
446
|
if (svgDownloads.length > 0) {
|
|
447
447
|
downloadPromises.push(Promise.all(svgDownloads));
|
package/dist/lib.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export interface FigmaMetadataResult {
|
|
|
61
61
|
images?: FigmaImageResult[];
|
|
62
62
|
}
|
|
63
63
|
export interface FigmaImageResult {
|
|
64
|
+
nodeId?: string;
|
|
64
65
|
filePath?: string;
|
|
65
66
|
buffer?: ArrayBuffer;
|
|
66
67
|
finalDimensions: {
|
|
@@ -97,7 +98,13 @@ export interface FigmaFrameImageOptions {
|
|
|
97
98
|
* @param options - Configuration options including API credentials
|
|
98
99
|
* @returns Promise resolving to the extracted metadata
|
|
99
100
|
*/
|
|
100
|
-
export declare function getFigmaMetadata(figmaUrl: string, options
|
|
101
|
+
export declare function getFigmaMetadata(figmaUrl: string, options: FigmaMetadataOptions & {
|
|
102
|
+
outputFormat: 'json';
|
|
103
|
+
}): Promise<string>;
|
|
104
|
+
export declare function getFigmaMetadata(figmaUrl: string, options: FigmaMetadataOptions & {
|
|
105
|
+
outputFormat: 'yaml';
|
|
106
|
+
}): Promise<string>;
|
|
107
|
+
export declare function getFigmaMetadata(figmaUrl: string, options?: FigmaMetadataOptions): Promise<FigmaMetadataResult>;
|
|
101
108
|
/**
|
|
102
109
|
* Download images from a Figma file
|
|
103
110
|
*
|
|
@@ -115,17 +122,58 @@ export declare function downloadFigmaImages(figmaUrl: string, nodes: FigmaImageN
|
|
|
115
122
|
* @returns Promise resolving to the download result
|
|
116
123
|
*/
|
|
117
124
|
export declare function downloadFigmaFrameImage(figmaUrl: string, options: FigmaFrameImageOptions): Promise<FigmaImageResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Get image node information from metadata
|
|
127
|
+
*
|
|
128
|
+
* Returns an array of objects containing node IDs and names for all images in the metadata.
|
|
129
|
+
* Use this to create a mapping between node IDs and uploaded URLs.
|
|
130
|
+
*
|
|
131
|
+
* @param metadata - The metadata result from getFigmaMetadata
|
|
132
|
+
* @returns Array of objects with nodeId and name for each image
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const imageInfo = getImageNodeInfo(metadata);
|
|
137
|
+
* // [{ nodeId: '123:456', name: 'icon' }, { nodeId: '789:012', name: 'logo' }]
|
|
138
|
+
*
|
|
139
|
+
* // Upload images and create mapping
|
|
140
|
+
* const urlMap: Record<string, string> = {};
|
|
141
|
+
* for (const info of imageInfo) {
|
|
142
|
+
* const url = await uploadToS3(metadata.images.find(img => img.nodeId === info.nodeId).buffer);
|
|
143
|
+
* urlMap[info.nodeId] = url;
|
|
144
|
+
* }
|
|
145
|
+
*
|
|
146
|
+
* // Enrich metadata with URLs
|
|
147
|
+
* const enriched = enrichMetadataWithImages(metadata, urlMap);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function getImageNodeInfo(metadata: FigmaMetadataResult): Array<{
|
|
151
|
+
nodeId: string;
|
|
152
|
+
name: string;
|
|
153
|
+
}>;
|
|
118
154
|
/**
|
|
119
155
|
* Enrich metadata with saved image file paths
|
|
120
156
|
*
|
|
121
157
|
* Use this function after saving images from buffers to disk to add file path information to the metadata.
|
|
122
158
|
*
|
|
123
159
|
* @param metadata - The metadata result from getFigmaMetadata
|
|
124
|
-
* @param imagePaths - Array of file paths
|
|
160
|
+
* @param imagePaths - Array of file paths (ordered) OR object mapping node IDs to paths/URLs
|
|
125
161
|
* @param options - Options for path generation
|
|
126
162
|
* @returns Enriched metadata with downloadedImage properties on nodes
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // Array format (ordered)
|
|
167
|
+
* const enriched = enrichMetadataWithImages(metadata, ['/path/to/img1.png', '/path/to/img2.png']);
|
|
168
|
+
*
|
|
169
|
+
* // Object format (keyed by node ID) - useful after uploading to CDN
|
|
170
|
+
* const enriched = enrichMetadataWithImages(metadata, {
|
|
171
|
+
* '123:456': 'https://cdn.example.com/icon.png',
|
|
172
|
+
* '789:012': 'https://cdn.example.com/logo.png'
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
127
175
|
*/
|
|
128
|
-
export declare function enrichMetadataWithImages(metadata: FigmaMetadataResult, imagePaths: string[], options?: {
|
|
176
|
+
export declare function enrichMetadataWithImages(metadata: FigmaMetadataResult, imagePaths: string[] | Record<string, string>, options?: {
|
|
129
177
|
useRelativePaths?: boolean | string;
|
|
130
178
|
localPath?: string;
|
|
131
179
|
}): FigmaMetadataResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "figma-metadata-extractor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Extract metadata and download images from Figma files. A standalone library for accessing Figma design data and downloading frame images programmatically.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|