figma-metadata-extractor 1.0.3 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -1374,7 +1374,8 @@ async function getFigmaMetadata(figmaUrl, options = {}) {
1374
1374
  downloadImages = false,
1375
1375
  localPath,
1376
1376
  imageFormat = "png",
1377
- pngScale = 2
1377
+ pngScale = 2,
1378
+ useRelativePaths = true
1378
1379
  } = options;
1379
1380
  if (!apiKey && !oauthToken) {
1380
1381
  throw new Error("Either apiKey or oauthToken is required");
@@ -1432,7 +1433,7 @@ async function getFigmaMetadata(figmaUrl, options = {}) {
1432
1433
  imageNodes,
1433
1434
  { pngScale: imageFormat === "png" ? pngScale : void 0 }
1434
1435
  );
1435
- result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults);
1436
+ result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths);
1436
1437
  Logger.log(`Successfully downloaded and enriched ${downloadResults.length} images`);
1437
1438
  }
1438
1439
  }
@@ -1556,18 +1557,26 @@ function hasImageFill(node, globalVars) {
1556
1557
  }
1557
1558
  return fillData.some((fill) => fill?.type === "IMAGE");
1558
1559
  }
1559
- function enrichNodesWithImages(nodes, imageAssets, downloadResults) {
1560
+ function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths = true) {
1560
1561
  const imageMap = /* @__PURE__ */ new Map();
1561
1562
  imageAssets.forEach((asset, index) => {
1562
1563
  const result = downloadResults[index];
1563
1564
  if (result) {
1565
+ let pathForMarkup;
1566
+ if (useRelativePaths === false) {
1567
+ pathForMarkup = result.filePath;
1568
+ } else if (typeof useRelativePaths === "string") {
1569
+ pathForMarkup = result.filePath.replace(useRelativePaths, ".");
1570
+ } else {
1571
+ pathForMarkup = result.filePath.replace(process.cwd(), ".");
1572
+ }
1564
1573
  imageMap.set(asset.id, {
1565
1574
  filePath: result.filePath,
1566
- relativePath: result.filePath.replace(process.cwd(), "."),
1575
+ relativePath: pathForMarkup,
1567
1576
  dimensions: result.finalDimensions,
1568
1577
  wasCropped: result.wasCropped,
1569
- markdown: `![${asset.name}](${result.filePath.replace(process.cwd(), ".")})`,
1570
- html: `<img src="${result.filePath.replace(process.cwd(), ".")}" alt="${asset.name}" width="${result.finalDimensions.width}" height="${result.finalDimensions.height}">`
1578
+ markdown: `![${asset.name}](${pathForMarkup})`,
1579
+ html: `<img src="${pathForMarkup}" alt="${asset.name}" width="${result.finalDimensions.width}" height="${result.finalDimensions.height}">`
1571
1580
  });
1572
1581
  }
1573
1582
  });
package/dist/index.js CHANGED
@@ -1372,7 +1372,8 @@ async function getFigmaMetadata(figmaUrl, options = {}) {
1372
1372
  downloadImages = false,
1373
1373
  localPath,
1374
1374
  imageFormat = "png",
1375
- pngScale = 2
1375
+ pngScale = 2,
1376
+ useRelativePaths = true
1376
1377
  } = options;
1377
1378
  if (!apiKey && !oauthToken) {
1378
1379
  throw new Error("Either apiKey or oauthToken is required");
@@ -1430,7 +1431,7 @@ async function getFigmaMetadata(figmaUrl, options = {}) {
1430
1431
  imageNodes,
1431
1432
  { pngScale: imageFormat === "png" ? pngScale : void 0 }
1432
1433
  );
1433
- result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults);
1434
+ result.nodes = enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths);
1434
1435
  Logger.log(`Successfully downloaded and enriched ${downloadResults.length} images`);
1435
1436
  }
1436
1437
  }
@@ -1554,18 +1555,26 @@ function hasImageFill(node, globalVars) {
1554
1555
  }
1555
1556
  return fillData.some((fill) => fill?.type === "IMAGE");
1556
1557
  }
1557
- function enrichNodesWithImages(nodes, imageAssets, downloadResults) {
1558
+ function enrichNodesWithImages(nodes, imageAssets, downloadResults, useRelativePaths = true) {
1558
1559
  const imageMap = /* @__PURE__ */ new Map();
1559
1560
  imageAssets.forEach((asset, index) => {
1560
1561
  const result = downloadResults[index];
1561
1562
  if (result) {
1563
+ let pathForMarkup;
1564
+ if (useRelativePaths === false) {
1565
+ pathForMarkup = result.filePath;
1566
+ } else if (typeof useRelativePaths === "string") {
1567
+ pathForMarkup = result.filePath.replace(useRelativePaths, ".");
1568
+ } else {
1569
+ pathForMarkup = result.filePath.replace(process.cwd(), ".");
1570
+ }
1562
1571
  imageMap.set(asset.id, {
1563
1572
  filePath: result.filePath,
1564
- relativePath: result.filePath.replace(process.cwd(), "."),
1573
+ relativePath: pathForMarkup,
1565
1574
  dimensions: result.finalDimensions,
1566
1575
  wasCropped: result.wasCropped,
1567
- markdown: `![${asset.name}](${result.filePath.replace(process.cwd(), ".")})`,
1568
- html: `<img src="${result.filePath.replace(process.cwd(), ".")}" alt="${asset.name}" width="${result.finalDimensions.width}" height="${result.finalDimensions.height}">`
1576
+ markdown: `![${asset.name}](${pathForMarkup})`,
1577
+ html: `<img src="${pathForMarkup}" alt="${asset.name}" width="${result.finalDimensions.width}" height="${result.finalDimensions.height}">`
1569
1578
  });
1570
1579
  }
1571
1580
  });
package/dist/lib.d.ts CHANGED
@@ -17,6 +17,13 @@ export interface FigmaMetadataOptions {
17
17
  imageFormat?: 'png' | 'svg';
18
18
  /** Export scale for PNG images (defaults to 2) */
19
19
  pngScale?: number;
20
+ /**
21
+ * Use relative paths in downloadedImage properties instead of absolute paths.
22
+ * If true, paths will be relative to process.cwd().
23
+ * If a string, paths will be relative to that base path.
24
+ * Default: true
25
+ */
26
+ useRelativePaths?: boolean | string;
20
27
  }
21
28
  export interface FigmaImageOptions {
22
29
  /** Export scale for PNG images (defaults to 2) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figma-metadata-extractor",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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",