|
@@ -44,6 +44,7 @@ export default class Redaction extends Base {
|
|
|
this.onMousedown = this.handleMouseDown.bind(this)
|
|
|
this.onMouseup = this.handleMouseUp.bind(this)
|
|
|
this.onDelete = this.handleDelete.bind(this)
|
|
|
+ this.onKeydown = this.handleKeyDown.bind(this)
|
|
|
this.render()
|
|
|
}
|
|
|
|
|
@@ -58,66 +59,54 @@ export default class Redaction extends Base {
|
|
|
this.start = start
|
|
|
this.end = end
|
|
|
|
|
|
- const rect = this.calculate(start, end)
|
|
|
+ const wholeRect = this.calculate(start, end)
|
|
|
+
|
|
|
+ const rects = []
|
|
|
+ if (annotation.rects && annotation.rects.length) {
|
|
|
+ annotation.rects.forEach(rect => {
|
|
|
+ const { start, end } = this.getActualRect(this.viewport, this.scale, rect)
|
|
|
+ rects.push(this.calculate(start, end))
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ rects.push(wholeRect)
|
|
|
+ }
|
|
|
|
|
|
- const annotationContainer = document.createElement('div')
|
|
|
- annotationContainer.id = annotation.name
|
|
|
- annotationContainer.className = 'annotation'
|
|
|
- annotationContainer.style.top = rect.top + 'px'
|
|
|
- annotationContainer.style.left = rect.left + 'px'
|
|
|
- annotationContainer.style.width = rect.width + 'px'
|
|
|
- annotationContainer.style.height = rect.height + 'px'
|
|
|
+ const annotationContainer = createElement(
|
|
|
+ 'div',
|
|
|
+ {
|
|
|
+ left: wholeRect.left + 'px',
|
|
|
+ top: wholeRect.top + 'px',
|
|
|
+ width: `${Math.abs(wholeRect.width)}px`,
|
|
|
+ height: `${Math.abs(wholeRect.height)}px`,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: annotation.name,
|
|
|
+ class: 'annotation redact'
|
|
|
+ }
|
|
|
+ )
|
|
|
this.annotationContainer = annotationContainer
|
|
|
|
|
|
const actualbdwidth = (annotation.borderWidth || 2) * this.scale
|
|
|
- let shapeElement
|
|
|
- if (annotation.erasure) {
|
|
|
- shapeElement = document.createElementNS("http://www.w3.org/2000/svg", "svg")
|
|
|
- shapeElement.setAttribute("viewBox", `0 0 ${rect.width} ${rect.height}`)
|
|
|
- shapeElement.addEventListener('mousedown', this.handleClick.bind(this))
|
|
|
-
|
|
|
- const rectElement = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- x: actualbdwidth / 2,
|
|
|
- y: actualbdwidth / 2,
|
|
|
- width: `${Math.abs(rect.width - actualbdwidth)}px`,
|
|
|
- height: `${Math.abs(rect.height - actualbdwidth)}px`,
|
|
|
- stroke: annotation.borderColor || '#FF0000',
|
|
|
- 'stroke-width': actualbdwidth,
|
|
|
- 'stroke-opacity': annotation.opacity || 1,
|
|
|
- fill: annotation.fillColor || 'none',
|
|
|
- 'fill-opacity': annotation.opacity || 1,
|
|
|
- }
|
|
|
- )
|
|
|
- shapeElement.append(rectElement)
|
|
|
- } else {
|
|
|
- shapeElement = createElement(
|
|
|
+ const shapeElements = []
|
|
|
+ rects.forEach(rect => {
|
|
|
+ const shapeElement = createElement(
|
|
|
'div',
|
|
|
{
|
|
|
- left: 0,
|
|
|
- top: 0,
|
|
|
- width: `${Math.abs(rect.width)}px`,
|
|
|
+ left: rect.left - wholeRect.left - (annotation.erasure ? actualbdwidth / 2 : actualbdwidth) + 'px',
|
|
|
+ top: rect.top - wholeRect.top + 'px',
|
|
|
+ width: `${Math.abs(rect.width) + (annotation.erasure ? actualbdwidth : actualbdwidth * 2) }px`,
|
|
|
height: `${Math.abs(rect.height)}px`,
|
|
|
- position: 'relative',
|
|
|
+ position: 'absolute',
|
|
|
border: `${actualbdwidth}px solid #FF0000`,
|
|
|
transition: 'none'
|
|
|
}
|
|
|
)
|
|
|
-
|
|
|
- this.annotationContainer.addEventListener('mousedown', this.handleClick.bind(this))
|
|
|
- this.annotationContainer.addEventListener('mouseenter', () => {
|
|
|
- shapeElement.style.backgroundColor = '#000000'
|
|
|
- shapeElement.style.border = ''
|
|
|
- })
|
|
|
- this.annotationContainer.addEventListener('mouseleave', () => {
|
|
|
- shapeElement.style.backgroundColor = ''
|
|
|
- shapeElement.style.border = `${actualbdwidth}px solid #FF0000`
|
|
|
- })
|
|
|
- }
|
|
|
- this.shapeElement = shapeElement
|
|
|
- this.annotationContainer.append(this.shapeElement)
|
|
|
+ annotation.erasure && (shapeElement.style.backgroundColor = 'rgba(255, 255, 255)')
|
|
|
+ shapeElements.push(shapeElement)
|
|
|
+ this.annotationContainer.append(shapeElement)
|
|
|
+ })
|
|
|
this.container.append(this.annotationContainer)
|
|
|
+ this.annotationContainer.addEventListener('mousedown', this.handleClick.bind(this))
|
|
|
|
|
|
this.outerLineContainer = document.createElement('div')
|
|
|
this.outerLineContainer.className = 'outline-container'
|
|
@@ -132,14 +121,15 @@ export default class Redaction extends Base {
|
|
|
},
|
|
|
{
|
|
|
width: '30px',
|
|
|
- height: '30px'
|
|
|
+ height: '30px',
|
|
|
+ zIndex: 1
|
|
|
}
|
|
|
);
|
|
|
this.deletetButton.addEventListener('click', this.onDelete)
|
|
|
this.deletetButton.innerHTML = this.deleteSvgStr
|
|
|
|
|
|
- const left = (rect.left + rect.width - 30) + 'px'
|
|
|
- const top = (rect.top + rect.height + 8) + 'px'
|
|
|
+ const left = (wholeRect.left + wholeRect.width - 30) + 'px'
|
|
|
+ const top = (wholeRect.top + wholeRect.height + 8) + 'px'
|
|
|
this.deletetButton.style.left = left
|
|
|
this.deletetButton.style.top = top
|
|
|
|
|
@@ -147,10 +137,10 @@ export default class Redaction extends Base {
|
|
|
|
|
|
outerLine.style.position = 'absolute'
|
|
|
outerLine.style.zIndex = 1
|
|
|
- outerLine.style.left = `${rect.left - 8}px`
|
|
|
- outerLine.style.top = `${rect.top - 8}px`
|
|
|
- outerLine.style.width = `${rect.width + 8 * 2}px`
|
|
|
- outerLine.style.height = `${rect.height + 8 * 2}px`
|
|
|
+ outerLine.style.left = `${wholeRect.left - 8 - (annotation.erasure ? actualbdwidth / 2 : actualbdwidth)}px`
|
|
|
+ outerLine.style.top = `${wholeRect.top - 8}px`
|
|
|
+ outerLine.style.width = `${wholeRect.width + 8 * 2 + (annotation.erasure ? actualbdwidth : actualbdwidth * 2)}px`
|
|
|
+ outerLine.style.height = `${wholeRect.height + 8 * 2}px`
|
|
|
this.outerLine = outerLine
|
|
|
|
|
|
this.moveRect = createSvg(
|
|
@@ -161,8 +151,8 @@ export default class Redaction extends Base {
|
|
|
stroke: "#4982E6",
|
|
|
'stroke-width': 1,
|
|
|
'fill-opacity': 0,
|
|
|
- width: rect.width + 8,
|
|
|
- height: rect.height + 8,
|
|
|
+ width: wholeRect.width + 8 + (annotation.erasure ? actualbdwidth : actualbdwidth * 2),
|
|
|
+ height: wholeRect.height + 8,
|
|
|
x: 4,
|
|
|
y: 4
|
|
|
}, {
|
|
@@ -174,21 +164,40 @@ export default class Redaction extends Base {
|
|
|
this.outerLineContainer.append(this.outerLine)
|
|
|
this.outerLineContainer.append(this.deletetButton)
|
|
|
|
|
|
- !annotation.erasure && this.moveRect.addEventListener('mouseenter', () => {
|
|
|
- this.shapeElement.style.backgroundColor = '#000000'
|
|
|
- this.shapeElement.style.border = ''
|
|
|
- })
|
|
|
- !annotation.erasure && this.moveRect.addEventListener('mouseleave', () => {
|
|
|
- this.shapeElement.style.backgroundColor = ''
|
|
|
- this.shapeElement.style.border = '2px solid #FF0000'
|
|
|
- })
|
|
|
+ if (!annotation.erasure) {
|
|
|
+ this.annotationContainer.addEventListener('mouseenter', () => {
|
|
|
+ if (this.layer.pageDiv.classList.contains('selecting')) return
|
|
|
+ shapeElements.forEach(el => {
|
|
|
+ el.style.backgroundColor = '#000000'
|
|
|
+ el.style.border = ''
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.annotationContainer.addEventListener('mouseleave', () => {
|
|
|
+ shapeElements.forEach(el => {
|
|
|
+ el.style.backgroundColor = ''
|
|
|
+ el.style.border = `${actualbdwidth}px solid #FF0000`
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ this.moveRect.addEventListener('mouseenter', () => {
|
|
|
+ shapeElements.forEach(el => {
|
|
|
+ el.style.backgroundColor = '#000000'
|
|
|
+ el.style.border = ''
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.moveRect.addEventListener('mouseleave', () => {
|
|
|
+ shapeElements.forEach(el => {
|
|
|
+ el.style.backgroundColor = ''
|
|
|
+ el.style.border = '2px solid #FF0000'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
this.initial = true
|
|
|
}
|
|
|
|
|
|
- getActualRect (viewport, s,) {
|
|
|
- const annotation = this.annotation
|
|
|
- const { left: x1, top: y1, right: x2, bottom: y2 } = annotation.rect
|
|
|
+ getActualRect (viewport, s, rect) {
|
|
|
+ const { left: x1, top: y1, right: x2, bottom: y2 } = rect || this.annotation.rect
|
|
|
|
|
|
const start = getActualPoint(
|
|
|
{
|
|
@@ -270,6 +279,7 @@ export default class Redaction extends Base {
|
|
|
this.container.append(this.outerLineContainer)
|
|
|
this.outerLine.addEventListener('mousedown', this.onMousedown)
|
|
|
this.outerLine.addEventListener('touchstart', this.onMousedown)
|
|
|
+ document.addEventListener('keydown', this.onKeydown)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -296,6 +306,7 @@ export default class Redaction extends Base {
|
|
|
this.outerLine.removeEventListener('mousedown', this.onMousedown)
|
|
|
this.outerLine.removeEventListener('touchstart', this.onMousedown)
|
|
|
this.outerLineContainer.remove()
|
|
|
+ document.removeEventListener('keydown', this.onKeydown)
|
|
|
}
|
|
|
|
|
|
handleMouseDown (event) {
|
|
@@ -378,4 +389,11 @@ export default class Redaction extends Base {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ handleKeyDown (event) {
|
|
|
+ const keyCode = event.keyCode || event.which
|
|
|
+ if (keyCode === 8 || keyCode === 46) { // 8 delete键,46 backspace键
|
|
|
+ this.handleDelete(event)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|