feat: .show() returns promise

This commit is contained in:
Anthony Fu
2024-02-21 17:53:44 +01:00
parent 7dfdf887c4
commit f86983354e
3 changed files with 23 additions and 12 deletions

View File

@@ -68,7 +68,14 @@ function parsePadding(config: RoughAnnotationConfig): FullPadding {
return [5, 5, 5, 5]
}
export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAnnotationConfig, animationGroupDelay: number, animationDuration: number, seed: number) {
export function renderAnnotation(
svg: SVGSVGElement,
rect: Rect,
config: RoughAnnotationConfig,
animationGroupDelay: number,
animationDuration: number,
seed: number,
): Promise<void> {
const opList: OpSet[] = []
let strokeWidth = config.strokeWidth || 2
const padding = parsePadding(config)
@@ -239,8 +246,14 @@ export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAn
style.animation = `rough-notation-dash ${duration}ms ease-out ${delay}ms forwards`
durationOffset += duration
}
return sleep(animationDuration + animationGroupDelay)
}
}
return sleep(0)
}
function sleep(ms: number) {
return new Promise<void>(resolve => setTimeout(resolve, ms))
}
function opsToPath(opList: OpSet[]): string[] {
@@ -253,7 +266,6 @@ function opsToPath(opList: OpSet[]): string[] {
case 'move':
if (path.trim())
paths.push(path.trim())
path = `M${data[0]} ${data[1]} `
break
case 'bcurveTo':