openfig-cli 0.3.24 → 0.3.26
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/lib/core/fig-deck.mjs +22 -7
- package/manifest.json +1 -1
- package/package.json +1 -1
package/lib/core/fig-deck.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { join, resolve } from 'path';
|
|
|
20
20
|
import { tmpdir } from 'os';
|
|
21
21
|
import { nid } from './node-helpers.mjs';
|
|
22
22
|
import { deepClone } from './deep-clone.mjs';
|
|
23
|
+
import { hashToHex } from './image-helpers.mjs';
|
|
23
24
|
|
|
24
25
|
export class FigDeck {
|
|
25
26
|
constructor() {
|
|
@@ -420,15 +421,29 @@ export class FigDeck {
|
|
|
420
421
|
mkdirSync(this.imagesDir, { recursive: true });
|
|
421
422
|
}
|
|
422
423
|
|
|
424
|
+
const copyImagePaint = (paint) => {
|
|
425
|
+
if (!paint) return;
|
|
426
|
+
if (paint.type === 'IMAGE' || paint.image) {
|
|
427
|
+
// Files on disk are named by SHA1 hex hash, not image.name (which is human-readable)
|
|
428
|
+
const hash = paint.image?.hash?.length ? hashToHex(paint.image.hash) : null;
|
|
429
|
+
if (hash) this._copyImageAsset(sourceDeck.imagesDir, hash);
|
|
430
|
+
}
|
|
431
|
+
if (paint.imageThumbnail) {
|
|
432
|
+
const tHash = paint.imageThumbnail.hash?.length ? hashToHex(paint.imageThumbnail.hash) : null;
|
|
433
|
+
if (tHash) this._copyImageAsset(sourceDeck.imagesDir, tHash);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
423
437
|
for (const clone of clonedNodes) {
|
|
424
|
-
// Copy IMAGE fills
|
|
438
|
+
// Copy IMAGE fills from node fillPaints
|
|
425
439
|
if (clone.fillPaints) {
|
|
426
|
-
for (const paint of clone.fillPaints)
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
440
|
+
for (const paint of clone.fillPaints) copyImagePaint(paint);
|
|
441
|
+
}
|
|
442
|
+
// Copy images from symbolOverrides (INSTANCE nodes)
|
|
443
|
+
if (clone.symbolData?.symbolOverrides) {
|
|
444
|
+
for (const ov of clone.symbolData.symbolOverrides) {
|
|
445
|
+
if (ov.fillPaints) {
|
|
446
|
+
for (const paint of ov.fillPaints) copyImagePaint(paint);
|
|
432
447
|
}
|
|
433
448
|
}
|
|
434
449
|
}
|
package/manifest.json
CHANGED