From 58b7a5d864c2102f0c7ef61d818023ab1b5c74c8 Mon Sep 17 00:00:00 2001 From: Preet Shihn Date: Tue, 16 Jun 2020 01:34:19 -0700 Subject: [PATCH] fixed a bug in rehighlighting --- package.json | 2 +- src/render.ts | 7 +++---- src/rough-notation.ts | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index df98de2..541a56c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rough-notation", - "version": "0.3.2", + "version": "0.3.3", "description": "Create and animate hand-drawn annotations on a web page", "main": "lib/rough-notation.cjs.js", "module": "lib/rough-notation.esm.js", diff --git a/src/render.ts b/src/render.ts index bf385c2..0367155 100644 --- a/src/render.ts +++ b/src/render.ts @@ -1,4 +1,4 @@ -import { Rect, RoughAnnotationConfig, SVG_NS, DEFAULT_ANIMATION_DURATION, FullPadding } from './model.js'; +import { Rect, RoughAnnotationConfig, SVG_NS, FullPadding } from './model.js'; import { ResolvedOptions, OpSet } from 'roughjs/bin/core'; import { line, rectangle, ellipse } from 'roughjs/bin/renderer'; @@ -54,7 +54,7 @@ function parsePadding(config: RoughAnnotationConfig): FullPadding { return [5, 5, 5, 5]; } -export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAnnotationConfig, animationGroupDelay: number, seed: number) { +export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAnnotationConfig, animationGroupDelay: number, animationDuration: number, seed: number) { const opList: OpSet[] = []; let strokeWidth = config.strokeWidth || 2; const padding = parsePadding(config); @@ -156,7 +156,6 @@ export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAn const lengths: number[] = []; const pathElements: SVGPathElement[] = []; let totalLength = 0; - const totalDuration = config.animationDuration === 0 ? 0 : (config.animationDuration || DEFAULT_ANIMATION_DURATION); const setAttr = (p: SVGPathElement, an: string, av: string) => p.setAttribute(an, av); for (const d of pathStrings) { @@ -179,7 +178,7 @@ export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAn for (let i = 0; i < pathElements.length; i++) { const path = pathElements[i]; const length = lengths[i]; - const duration = totalLength ? (totalDuration * (length / totalLength)) : 0; + const duration = totalLength ? (animationDuration * (length / totalLength)) : 0; const delay = animationGroupDelay + durationOffset; const style = path.style; style.strokeDashoffset = `${length}`; diff --git a/src/rough-notation.ts b/src/rough-notation.ts index 780d1f4..3ca0ba5 100644 --- a/src/rough-notation.ts +++ b/src/rough-notation.ts @@ -216,9 +216,9 @@ class RoughAnnotationImpl implements RoughAnnotation { let delay = 0; for (let i = 0; i < rects.length; i++) { const rect = rects[i]; - config.animationDuration = totalDuration * (rect.w / totalWidth); - renderAnnotation(svg, rects[i], config, delay + this._animationDelay, this._seed); - delay += config.animationDuration; + const ad = totalDuration * (rect.w / totalWidth); + renderAnnotation(svg, rects[i], config, delay + this._animationDelay, ad, this._seed); + delay += ad; } this._lastSizes = rects; this._state = 'showing';