fix bug custom shape

This commit is contained in:
hamid zarghami
2026-06-13 16:46:37 +03:30
parent 9447500725
commit ebb2092ec1
7 changed files with 171 additions and 34 deletions
+26 -2
View File
@@ -51,13 +51,20 @@ export const getKonvaGradientProps = (
width: number,
height: number,
mode: GradientPointMode,
offset: Point = { x: 0, y: 0 },
) => {
if (fillType !== "gradient" || !gradient) return {};
const points = getGradientPoints(width, height, gradient.angle, mode);
return {
fillPriority: "linear-gradient" as const,
fillLinearGradientStartPoint: points.start,
fillLinearGradientEndPoint: points.end,
fillLinearGradientStartPoint: {
x: points.start.x + offset.x,
y: points.start.y + offset.y,
},
fillLinearGradientEndPoint: {
x: points.end.x + offset.x,
y: points.end.y + offset.y,
},
fillLinearGradientColorStops: [0, gradient.from, 1, gradient.to] as [
number,
string,
@@ -67,6 +74,23 @@ export const getKonvaGradientProps = (
};
};
/** SVG linearGradient endpoints matching the Konva gradient math. */
export const getSvgGradientEndpoints = (
gradient: LinearGradient,
width: number,
height: number,
mode: GradientPointMode = "rect",
offset: Point = { x: 0, y: 0 },
) => {
const points = getGradientPoints(width, height, gradient.angle, mode);
return {
x1: points.start.x + offset.x,
y1: points.start.y + offset.y,
x2: points.end.x + offset.x,
y2: points.end.y + offset.y,
};
};
export const toCssLinearGradient = (gradient: LinearGradient | undefined) => {
if (!gradient) return undefined;
return `linear-gradient(${normalizeAngle(gradient.angle)}deg, ${gradient.from} 0%, ${gradient.to} 100%)`;