Skip to content

Commit

Permalink
feat: support style option to drawTo method
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Oct 24, 2024
1 parent 125a109 commit 9464363
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/canvas/setCanvasContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function setCanvasContext(
strokeLinecap = 'round',
strokeLinejoin = 'miter',
strokeMiterlimit = 0,
strokeDasharray,
strokeDasharray = [],
strokeDashoffset = 0,
shadowOffsetX = 0,
shadowOffsetY = 0,
Expand All @@ -35,7 +35,7 @@ export function setCanvasContext(
ctx.lineCap = strokeLinecap
ctx.lineJoin = lineJoinMap[strokeLinejoin]
ctx.miterLimit = strokeMiterlimit
strokeDasharray && ctx.setLineDash(strokeDasharray)
ctx.setLineDash(strokeDasharray)
ctx.lineDashOffset = strokeDashoffset

// shadow
Expand Down
9 changes: 4 additions & 5 deletions src/paths/Path2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,10 @@ export class Path2D {
return `data:image/svg+xml;base64,${btoa(this.getSvgXml())}`
}

drawTo(ctx: CanvasRenderingContext2D, withStyle = true): void {
const { fill = '#000', stroke = 'none' } = this.style
if (withStyle) {
setCanvasContext(ctx, this.style)
}
drawTo(ctx: CanvasRenderingContext2D, style: Partial<PathStyle> = {}): void {
style = { ...this.style, ...style }
const { fill = '#000', stroke = 'none' } = style
setCanvasContext(ctx, style)
this.paths.forEach((path) => {
path.drawTo(ctx)
})
Expand Down

0 comments on commit 9464363

Please sign in to comment.