Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { trimPathStart, trimPathEnd, trimPathOffset } = layer;
// TODO: make sure this works with compound paths as well (Android behavior is different)
const pathLength = layer.pathData ? layer.pathData.getPathLength() : 0;
const dashArray = pathLength
? LayerUtil.toStrokeDashArray(trimPathStart, trimPathEnd, trimPathOffset, pathLength)
: undefined;
const dashOffset = pathLength
? LayerUtil.toStrokeDashOffset(trimPathStart, trimPathEnd, trimPathOffset, pathLength)
: undefined;
const f = ColorUtil.parseAndroidColor(fillColor);
const s = ColorUtil.parseAndroidColor(strokeColor);
// TODO: import a compound path instead
return new paper.Path({
data: { id: layer.id },
pathData: layer.pathData ? layer.pathData.getPathString() : '',
fillColor: f ? new paper.Color(f.r, f.g, f.b, f.a * fillAlpha) : undefined,
strokeColor: s ? new paper.Color(s.r, s.g, s.b, s.a * strokeAlpha) : undefined,
strokeWidth: layer.strokeWidth,
miterLimit: layer.strokeMiterLimit,
strokeJoin: layer.strokeLinejoin,
strokeCap: layer.strokeLinecap,
fillRule: layer.fillType === 'evenOdd' ? 'evenodd' : 'nonzero',
dashArray,
dashOffset,
});
}
const applyColor = (path: Path, color: string) => {
path.strokeColor = new Color(color);
const fill = new Color(color);
fill.alpha = 0.2;
path.fillColor = fill;
};
function parseAndroidColor(androidColor: string, alpha = 1) {
const color = ColorUtil.parseAndroidColor(androidColor);
return color
? new paper.Color(color.r / 255, color.g / 255, color.b / 255, (color.a / 255) * alpha)
: undefined;
}
rectSelect(point1, point2) {
let rect = new paper.Path.Rectangle(point1, point2);
rect.fillColor = new paper.Color(0, .3, 1, .4);
rect.strokeColor = new paper.Color(0, 0, 0);
rect.strokeWidth = 2;
rect.selected = true;
return rect;
}
}
export function toColor(value: string | number | Color): paper.Color {
if (value === 'transparent') {
return new paper.Color(1, 1, 1, 0.0001);
} else {
const color = Color.fromValue(value);
return new paper.Color(color.r, color.g, color.b);
}
}
}
const applyColor = (path: Path, color: string) => {
path.strokeColor = new Color(color);
const fill = new Color(color);
fill.alpha = 0.2;
path.fillColor = fill;
};
rectSelect(point1, point2) {
let rect = new paper.Path.Rectangle(point1, point2);
rect.fillColor = new paper.Color(0, .3, 1, .4);
rect.strokeColor = new paper.Color(0, 0, 0);
rect.strokeWidth = 2;
rect.selected = true;
return rect;
}
}
}
}
},
path(
{
segments: state => state.current,
selected: true
}
),
iterate(
{ getArray: (state: State) => state.paths },
path<[Segment[], State, number], Action>(
{
segments: ([segments]) => segments,
strokeWidth: 2,
strokeColor: new Color(0.75, 0.75, 0.75),
selected: ([_, state, index]) => state.paths.length - 1 === index
}
)
)
)
)
)