2024-04-12 09:52:36 -05:00
|
|
|
import { Fill } from '@ui/lib/types/utils/fill';
|
2024-05-06 01:06:14 -05:00
|
|
|
import { Gradient, LINEAR_TYPE, RADIAL_TYPE } from '@ui/lib/types/utils/gradient';
|
2024-06-05 05:36:49 -05:00
|
|
|
import { ImageColor, PartialImageColor } from '@ui/lib/types/utils/imageColor';
|
|
|
|
import { uiImages } from '@ui/parser/libraries';
|
2024-04-12 06:55:42 -05:00
|
|
|
|
2024-06-03 10:29:33 -05:00
|
|
|
export const symbolFills = (fills?: Fill[]): Fill[] | undefined => {
|
2024-05-09 09:59:27 -05:00
|
|
|
if (!fills) return;
|
2024-05-06 01:06:14 -05:00
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
return fills.map(fill => {
|
|
|
|
if (fill.fillColorGradient) {
|
2024-05-29 05:52:21 -05:00
|
|
|
fill.fillColorGradient = symbolFillGradient(fill.fillColorGradient);
|
2024-04-12 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
2024-06-03 10:29:33 -05:00
|
|
|
if (fill.fillImage) {
|
|
|
|
fill.fillImage = symbolFillImage(fill.fillImage);
|
|
|
|
}
|
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
return fill;
|
|
|
|
});
|
|
|
|
};
|
2024-05-06 01:06:14 -05:00
|
|
|
|
2024-06-03 10:44:03 -05:00
|
|
|
const symbolFillGradient = (fillGradient: Gradient): Gradient => {
|
|
|
|
if (typeof fillGradient.type !== 'string') return fillGradient;
|
|
|
|
|
|
|
|
const { type, ...rest } = fillGradient;
|
|
|
|
|
2024-05-06 01:06:14 -05:00
|
|
|
switch (type) {
|
|
|
|
case 'linear':
|
|
|
|
return {
|
|
|
|
type: LINEAR_TYPE,
|
|
|
|
...rest
|
|
|
|
};
|
|
|
|
case 'radial':
|
|
|
|
return {
|
|
|
|
type: RADIAL_TYPE,
|
|
|
|
...rest
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2024-06-03 10:29:33 -05:00
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
export const symbolFillImage = (
|
|
|
|
fillImage: ImageColor | PartialImageColor
|
|
|
|
): ImageColor | undefined => {
|
|
|
|
if (!isPartialFillColor(fillImage)) return fillImage;
|
2024-06-03 10:29:33 -05:00
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
return uiImages.get(fillImage.imageHash);
|
|
|
|
};
|
2024-06-03 10:29:33 -05:00
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
const isPartialFillColor = (
|
|
|
|
imageColor: ImageColor | PartialImageColor
|
|
|
|
): imageColor is PartialImageColor => {
|
|
|
|
return 'imageHash' in imageColor;
|
2024-06-03 10:29:33 -05:00
|
|
|
};
|