figma-metadata-extractor 1.0.4 → 1.0.5
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 +12 -4
- package/dist/index.js +12 -4
- package/dist/lib.d.ts +4 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1433,7 +1433,7 @@ async function getFigmaMetadata(figmaUrl, options = {}) {
|
|
|
1433
1433
|
imageNodes,
|
|
1434
1434
|
{ pngScale: imageFormat === "png" ? pngScale : void 0 }
|
|
1435
1435
|
);
|
|
1436
|
-
result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths);
|
|
1436
|
+
result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths, localPath);
|
|
1437
1437
|
Logger.log(`Successfully downloaded and enriched ${downloadResults.length} images`);
|
|
1438
1438
|
}
|
|
1439
1439
|
}
|
|
@@ -1557,7 +1557,7 @@ function hasImageFill(node, globalVars) {
|
|
|
1557
1557
|
}
|
|
1558
1558
|
return fillData.some((fill) => fill?.type === "IMAGE");
|
|
1559
1559
|
}
|
|
1560
|
-
function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths = true) {
|
|
1560
|
+
function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths = true, localPath) {
|
|
1561
1561
|
const imageMap = /* @__PURE__ */ new Map();
|
|
1562
1562
|
imageAssets.forEach((asset, index) => {
|
|
1563
1563
|
const result = downloadResults[index];
|
|
@@ -1566,9 +1566,17 @@ function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativeP
|
|
|
1566
1566
|
if (useRelativePaths === false) {
|
|
1567
1567
|
pathForMarkup = result.filePath;
|
|
1568
1568
|
} else if (typeof useRelativePaths === "string") {
|
|
1569
|
-
|
|
1569
|
+
const basePath = useRelativePaths.endsWith("/") ? useRelativePaths : useRelativePaths + "/";
|
|
1570
|
+
const normalizedFilePath = result.filePath.replace(/\\/g, "/");
|
|
1571
|
+
const normalizedBasePath = basePath.replace(/\\/g, "/");
|
|
1572
|
+
if (normalizedFilePath.startsWith(normalizedBasePath)) {
|
|
1573
|
+
pathForMarkup = "./" + normalizedFilePath.substring(normalizedBasePath.length);
|
|
1574
|
+
} else {
|
|
1575
|
+
pathForMarkup = "./" + result.filePath.split(/[/\\]/).pop();
|
|
1576
|
+
}
|
|
1570
1577
|
} else {
|
|
1571
|
-
|
|
1578
|
+
const fileName = result.filePath.split(/[/\\]/).pop();
|
|
1579
|
+
pathForMarkup = "./" + fileName;
|
|
1572
1580
|
}
|
|
1573
1581
|
imageMap.set(asset.id, {
|
|
1574
1582
|
filePath: result.filePath,
|
package/dist/index.js
CHANGED
|
@@ -1431,7 +1431,7 @@ async function getFigmaMetadata(figmaUrl, options = {}) {
|
|
|
1431
1431
|
imageNodes,
|
|
1432
1432
|
{ pngScale: imageFormat === "png" ? pngScale : void 0 }
|
|
1433
1433
|
);
|
|
1434
|
-
result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths);
|
|
1434
|
+
result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths, localPath);
|
|
1435
1435
|
Logger.log(`Successfully downloaded and enriched ${downloadResults.length} images`);
|
|
1436
1436
|
}
|
|
1437
1437
|
}
|
|
@@ -1555,7 +1555,7 @@ function hasImageFill(node, globalVars) {
|
|
|
1555
1555
|
}
|
|
1556
1556
|
return fillData.some((fill) => fill?.type === "IMAGE");
|
|
1557
1557
|
}
|
|
1558
|
-
function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths = true) {
|
|
1558
|
+
function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths = true, localPath) {
|
|
1559
1559
|
const imageMap = /* @__PURE__ */ new Map();
|
|
1560
1560
|
imageAssets.forEach((asset, index) => {
|
|
1561
1561
|
const result = downloadResults[index];
|
|
@@ -1564,9 +1564,17 @@ function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativeP
|
|
|
1564
1564
|
if (useRelativePaths === false) {
|
|
1565
1565
|
pathForMarkup = result.filePath;
|
|
1566
1566
|
} else if (typeof useRelativePaths === "string") {
|
|
1567
|
-
|
|
1567
|
+
const basePath = useRelativePaths.endsWith("/") ? useRelativePaths : useRelativePaths + "/";
|
|
1568
|
+
const normalizedFilePath = result.filePath.replace(/\\/g, "/");
|
|
1569
|
+
const normalizedBasePath = basePath.replace(/\\/g, "/");
|
|
1570
|
+
if (normalizedFilePath.startsWith(normalizedBasePath)) {
|
|
1571
|
+
pathForMarkup = "./" + normalizedFilePath.substring(normalizedBasePath.length);
|
|
1572
|
+
} else {
|
|
1573
|
+
pathForMarkup = "./" + result.filePath.split(/[/\\]/).pop();
|
|
1574
|
+
}
|
|
1568
1575
|
} else {
|
|
1569
|
-
|
|
1576
|
+
const fileName = result.filePath.split(/[/\\]/).pop();
|
|
1577
|
+
pathForMarkup = "./" + fileName;
|
|
1570
1578
|
}
|
|
1571
1579
|
imageMap.set(asset.id, {
|
|
1572
1580
|
filePath: result.filePath,
|
package/dist/lib.d.ts
CHANGED
|
@@ -18,9 +18,10 @@ export interface FigmaMetadataOptions {
|
|
|
18
18
|
/** Export scale for PNG images (defaults to 2) */
|
|
19
19
|
pngScale?: number;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Control how image paths are generated in downloadedImage properties.
|
|
22
|
+
* - true (default): Just the filename (e.g., "./icon.png")
|
|
23
|
+
* - false: Absolute file path (e.g., "/absolute/path/to/images/icon.png")
|
|
24
|
+
* - string: Strip this base path from file path (e.g., "/var/www" → "./images/icon.png")
|
|
24
25
|
* Default: true
|
|
25
26
|
*/
|
|
26
27
|
useRelativePaths?: boolean | string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "figma-metadata-extractor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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",
|