2024-05-13 06:21:46 -05:00
|
|
|
import {
|
|
|
|
transformBlend,
|
|
|
|
transformDimensionAndPositionFromVectorPath,
|
|
|
|
transformEffects,
|
|
|
|
transformProportion,
|
|
|
|
transformSceneNode,
|
|
|
|
transformStrokes
|
|
|
|
} from '@plugin/transformers/partials';
|
|
|
|
import { createLineGeometry, translateVectorPath, translateVectorPaths } from '@plugin/translators';
|
|
|
|
import { translateFills } from '@plugin/translators';
|
2024-04-17 03:53:38 -05:00
|
|
|
|
2024-05-06 01:06:14 -05:00
|
|
|
import { PathAttributes } from '@ui/lib/types/shapes/pathShape';
|
2024-05-13 06:21:46 -05:00
|
|
|
import { PathShape } from '@ui/lib/types/shapes/pathShape';
|
|
|
|
import { Children } from '@ui/lib/types/utils/children';
|
2024-04-17 03:53:38 -05:00
|
|
|
|
|
|
|
const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): VectorPaths => {
|
|
|
|
switch (node.type) {
|
|
|
|
case 'STAR':
|
|
|
|
case 'POLYGON':
|
|
|
|
return node.fillGeometry;
|
|
|
|
case 'VECTOR':
|
2024-04-26 10:09:57 -05:00
|
|
|
return node.vectorPaths;
|
2024-04-17 03:53:38 -05:00
|
|
|
case 'LINE':
|
2024-05-10 04:08:00 -05:00
|
|
|
return createLineGeometry(node);
|
2024-04-17 03:53:38 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-13 06:21:46 -05:00
|
|
|
export const transformVectorPathsAsContent = (
|
2024-04-17 03:53:38 -05:00
|
|
|
node: VectorNode | StarNode | LineNode | PolygonNode,
|
|
|
|
baseX: number,
|
|
|
|
baseY: number
|
|
|
|
): PathAttributes => {
|
|
|
|
const vectorPaths = getVectorPaths(node);
|
|
|
|
|
|
|
|
return {
|
|
|
|
content: translateVectorPaths(vectorPaths, baseX + node.x, baseY + node.y)
|
|
|
|
};
|
|
|
|
};
|
2024-05-13 06:21:46 -05:00
|
|
|
|
|
|
|
export const transformVectorPathsAsChildren = async (
|
|
|
|
node: VectorNode,
|
|
|
|
baseX: number,
|
|
|
|
baseY: number
|
|
|
|
): Promise<Children> => {
|
|
|
|
return {
|
|
|
|
children: await Promise.all(
|
|
|
|
node.vectorPaths.map((vectorPath, index) =>
|
|
|
|
transformVectorPath(
|
|
|
|
node,
|
|
|
|
vectorPath,
|
|
|
|
(node.vectorNetwork.regions ?? [])[index],
|
|
|
|
baseX,
|
|
|
|
baseY
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const transformVectorPath = async (
|
|
|
|
node: VectorNode,
|
|
|
|
vectorPath: VectorPath,
|
|
|
|
vectorRegion: VectorRegion | undefined,
|
|
|
|
baseX: number,
|
|
|
|
baseY: number
|
|
|
|
): Promise<PathShape> => {
|
|
|
|
return {
|
|
|
|
type: 'path',
|
|
|
|
name: 'svg-path',
|
|
|
|
content: translateVectorPath(vectorPath, baseX + node.x, baseY + node.y),
|
2024-05-13 09:44:00 -05:00
|
|
|
fills: await translateFills(vectorRegion?.fills ?? node.fills),
|
2024-05-13 06:21:46 -05:00
|
|
|
...(await transformStrokes(node)),
|
|
|
|
...transformEffects(node),
|
2024-05-13 09:44:00 -05:00
|
|
|
...transformDimensionAndPositionFromVectorPath(vectorPath, baseX, baseY),
|
2024-05-13 06:21:46 -05:00
|
|
|
...transformSceneNode(node),
|
|
|
|
...transformBlend(node),
|
|
|
|
...transformProportion(node)
|
|
|
|
};
|
|
|
|
};
|