2024-06-03 10:29:33 -05:00
|
|
|
import { imagesLibrary } from '@plugin/ImageLibrary';
|
2024-05-13 10:04:13 -05:00
|
|
|
|
|
|
|
import { Fill } from '@ui/lib/types/utils/fill';
|
2024-06-05 05:36:49 -05:00
|
|
|
import { PartialImageColor } from '@ui/lib/types/utils/imageColor';
|
2024-05-13 10:04:13 -05:00
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
export const translateImageFill = (fill: ImagePaint): Fill | undefined => {
|
|
|
|
const fillImage = translateImage(fill.imageHash);
|
2024-05-13 10:04:13 -05:00
|
|
|
if (!fillImage) return;
|
|
|
|
|
|
|
|
return {
|
|
|
|
fillOpacity: !fill.visible ? 0 : fill.opacity,
|
2024-06-03 10:29:33 -05:00
|
|
|
fillImage
|
2024-05-13 10:04:13 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
const translateImage = (imageHash: string | null): PartialImageColor | undefined => {
|
2024-05-13 10:04:13 -05:00
|
|
|
if (!imageHash) return;
|
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
if (imagesLibrary.get(imageHash) === undefined) {
|
|
|
|
imagesLibrary.register(imageHash, figma.getImageByHash(imageHash));
|
|
|
|
}
|
2024-06-03 10:29:33 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
imageHash
|
|
|
|
};
|
|
|
|
};
|