feat!: directly pass through rough js options

This commit is contained in:
Anthony Fu
2024-02-24 15:46:34 +01:00
parent 446eaa36f9
commit 57ec6a67c4
4 changed files with 17 additions and 9 deletions

View File

@@ -83,7 +83,7 @@ export function renderAnnotation(
const animate = (config.animate === undefined) ? true : (!!config.animate)
const iterations = config.iterations || 2
const rtl = config.rtl ? 1 : 0
const o = getOptions('single', seed, config.overrides)
const o = getOptions('single', seed, config)
switch (config.type) {
case 'underline': {
@@ -183,7 +183,7 @@ export function renderAnnotation(
break
}
case 'circle': {
const doubleO = getOptions('double', seed, config.overrides)
const doubleO = getOptions('double', seed, config)
const width = rect.w + (padding[1] + padding[3])
const height = rect.h + (padding[0] + padding[2])
const x = rect.x - padding[3] + (width / 2)
@@ -199,7 +199,7 @@ export function renderAnnotation(
break
}
case 'highlight': {
const o = getOptions('highlight', seed, config.overrides)
const o = getOptions('highlight', seed, config)
strokeWidth = rect.h * 0.95
const y = rect.y + (rect.h / 2)
for (let i = rtl; i < iterations + rtl; i++) {

View File

@@ -23,6 +23,17 @@ class RoughAnnotationImpl implements RoughAnnotation {
this.attach()
}
getConfig<T extends keyof RoughAnnotationConfig>(key: T) {
return this._config[key]
}
setConfig<T extends keyof RoughAnnotationConfig>(key: T, value: RoughAnnotationConfig[T]) {
if (this._config[key] !== value) {
this._config[key] = value
this.refresh()
}
}
get animate() { return this._config.animate }
set animate(value) { this._config.animate = value }

View File

@@ -18,7 +18,7 @@ export interface RoughAnnotationConfig extends RoughAnnotationConfigBase {
rtl?: boolean
}
export interface RoughAnnotationConfigBase {
export interface RoughAnnotationConfigBase extends Partial<ResolvedOptions> {
animate?: boolean // defaults to true
animationDuration?: number // defaults to 1000ms
color?: string // defaults to currentColor
@@ -30,10 +30,6 @@ export interface RoughAnnotationConfigBase {
* Additional class to add to the root SVG element
*/
class?: string
/**
* RoughJS options
*/
overrides?: Partial<ResolvedOptions>
}
export interface RoughAnnotation extends RoughAnnotationConfigBase {