|
1 | | -import { Rect, RoughAnnotationConfig, SVG_NS, FullPadding } from './model.js'; |
| 1 | +import { Rect, RoughAnnotationConfig, SVG_NS, FullPadding, BracketType } from './model.js'; |
2 | 2 | import { ResolvedOptions, OpSet } from 'roughjs/bin/core'; |
3 | | -import { line, rectangle, ellipse } from 'roughjs/bin/renderer'; |
| 3 | +import { line, rectangle, ellipse, linearPath } from 'roughjs/bin/renderer'; |
| 4 | +import { Point } from 'roughjs/bin/geometry'; |
4 | 5 |
|
5 | 6 | type RoughOptionsType = 'highlight' | 'single' | 'double'; |
6 | 7 |
|
@@ -97,6 +98,55 @@ export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAn |
97 | 98 | } |
98 | 99 | break; |
99 | 100 | } |
| 101 | + case 'bracket': { |
| 102 | + const o = getOptions('single', seed); |
| 103 | + const brackets: BracketType[] = Array.isArray(config.brackets) ? config.brackets : (config.brackets ? [config.brackets] : ['right']); |
| 104 | + const lx = rect.x - padding[3] * 2; |
| 105 | + const rx = rect.x + rect.w + padding[1] * 2; |
| 106 | + const ty = rect.y - padding[0] * 2; |
| 107 | + const by = rect.y + rect.h + padding[2] * 2; |
| 108 | + for (const br of brackets) { |
| 109 | + let points: Point[]; |
| 110 | + switch (br) { |
| 111 | + case 'bottom': |
| 112 | + points = [ |
| 113 | + [lx, rect.y + rect.h], |
| 114 | + [lx, by], |
| 115 | + [rx, by], |
| 116 | + [rx, rect.y + rect.h] |
| 117 | + ]; |
| 118 | + break; |
| 119 | + case 'top': |
| 120 | + points = [ |
| 121 | + [lx, rect.y], |
| 122 | + [lx, ty], |
| 123 | + [rx, ty], |
| 124 | + [rx, rect.y] |
| 125 | + ]; |
| 126 | + break; |
| 127 | + case 'left': |
| 128 | + points = [ |
| 129 | + [rect.x, ty], |
| 130 | + [lx, ty], |
| 131 | + [lx, by], |
| 132 | + [rect.x, by] |
| 133 | + ]; |
| 134 | + break; |
| 135 | + case 'right': |
| 136 | + points = [ |
| 137 | + [rect.x + rect.w, ty], |
| 138 | + [rx, ty], |
| 139 | + [rx, by], |
| 140 | + [rect.x + rect.w, by] |
| 141 | + ]; |
| 142 | + break; |
| 143 | + } |
| 144 | + if (points) { |
| 145 | + opList.push(linearPath(points, false, o)); |
| 146 | + } |
| 147 | + } |
| 148 | + break; |
| 149 | + } |
100 | 150 | case 'crossed-off': { |
101 | 151 | const o = getOptions('single', seed); |
102 | 152 | const x = rect.x; |
|
0 commit comments