|
@@ -34,18 +34,15 @@ export default class Redaction extends Base {
|
|
|
this.start = null
|
|
|
this.end = null
|
|
|
|
|
|
- this.newStart = null
|
|
|
- this.newEnd = null
|
|
|
-
|
|
|
this.startCircle = null
|
|
|
this.endCircle = null
|
|
|
|
|
|
this.show = show
|
|
|
this.highlight = highlight
|
|
|
|
|
|
+
|
|
|
this.onMousedown = this.handleMouseDown.bind(this)
|
|
|
this.onMouseup = this.handleMouseUp.bind(this)
|
|
|
- this.onMousemove = this.handleMouseMove.bind(this)
|
|
|
this.onDelete = this.handleDelete.bind(this)
|
|
|
this.render()
|
|
|
}
|
|
@@ -59,6 +56,7 @@ export default class Redaction extends Base {
|
|
|
)
|
|
|
this.start = start
|
|
|
this.end = end
|
|
|
+ this.isRedaction = this.annotation.type === 'redaction'
|
|
|
|
|
|
const rect = this.calculate(start, end)
|
|
|
|
|
@@ -69,45 +67,58 @@ export default class Redaction extends Base {
|
|
|
annotationContainer.style.left = rect.left + 'px'
|
|
|
annotationContainer.style.width = rect.width + 'px'
|
|
|
annotationContainer.style.height = rect.height + 'px'
|
|
|
- annotationContainer.style.backgroundColor = this.highlight ? '#93B9FD' : ''
|
|
|
- annotationContainer.style.opacity = 0.3
|
|
|
this.annotationContainer = annotationContainer
|
|
|
- this.annotationContainer.addEventListener('mousedown', this.handleClick.bind(this))
|
|
|
|
|
|
+ const actualbdwidth = (annotation.borderWidth || 2) * this.scale
|
|
|
let shapeElement
|
|
|
- shapeElement = createElement(
|
|
|
- 'div',
|
|
|
- {
|
|
|
- left: 0,
|
|
|
- top: 0,
|
|
|
- width: `${Math.abs(rect.width)}px`,
|
|
|
- height: `${Math.abs(rect.height)}px`,
|
|
|
- position: 'relative'
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
+ if (this.isRedaction) {
|
|
|
+ shapeElement = createElement(
|
|
|
+ 'div',
|
|
|
+ {
|
|
|
+ left: 0,
|
|
|
+ top: 0,
|
|
|
+ width: `${Math.abs(rect.width)}px`,
|
|
|
+ height: `${Math.abs(rect.height)}px`,
|
|
|
+ position: 'relative',
|
|
|
+ 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`
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ 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 ? annotation.fillColor : 'none',
|
|
|
+ 'fill-opacity': annotation.opacity || 1,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ shapeElement.append(rectElement)
|
|
|
+ }
|
|
|
this.shapeElement = shapeElement
|
|
|
-
|
|
|
this.annotationContainer.append(this.shapeElement)
|
|
|
-
|
|
|
this.container.append(this.annotationContainer)
|
|
|
|
|
|
- this.buttonContainer = createElement(
|
|
|
- 'a',
|
|
|
- {
|
|
|
- display: 'block',
|
|
|
- width: '100%',
|
|
|
- height: '100%',
|
|
|
- outline: 'none'
|
|
|
- }
|
|
|
- )
|
|
|
- this.shapeElement.append(this.buttonContainer)
|
|
|
- this.buttonContainer.addEventListener('blur', this.onBlur)
|
|
|
- if (this.annotation.url) {
|
|
|
- this.buttonContainer.setAttribute('href', this.annotation.url)
|
|
|
- this.buttonContainer.setAttribute('target', '_blank')
|
|
|
- }
|
|
|
-
|
|
|
this.outerLineContainer = document.createElement('div')
|
|
|
this.outerLineContainer.className = 'outline-container'
|
|
|
this.deletetButton = createSvg(
|
|
@@ -154,140 +165,24 @@ export default class Redaction extends Base {
|
|
|
height: rect.height + 8,
|
|
|
x: 4,
|
|
|
y: 4
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.topLeftRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "nw-resize",
|
|
|
- 'data-id': "nw-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: 1,
|
|
|
- y: 1
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.LeftRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "w-resize",
|
|
|
- 'data-id': "w-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: 1,
|
|
|
- y: rect.height / 2 + 5
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.bottomLeftRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "sw-resize",
|
|
|
- 'data-id': "sw-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: 1,
|
|
|
- y: rect.height + 9
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.bottomRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "s-resize",
|
|
|
- 'data-id': "s-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: rect.width / 2 + 5,
|
|
|
- y: rect.height + 9
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.bottomRightRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "se-resize",
|
|
|
- 'data-id': "se-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: rect.width + 9,
|
|
|
- y: rect.height + 9
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.rightRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "e-resize",
|
|
|
- 'data-id': "e-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: rect.width + 9,
|
|
|
- y: rect.height / 2 + 5
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.topRightRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "ne-resize",
|
|
|
- 'data-id': "ne-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: rect.width + 9,
|
|
|
- y: 1
|
|
|
- }
|
|
|
- );
|
|
|
-
|
|
|
- this.topRect = createSvg(
|
|
|
- "rect",
|
|
|
- {
|
|
|
- class: "n-resize",
|
|
|
- 'data-id': "n-resize",
|
|
|
- fill: "#FFFFFF",
|
|
|
- stroke: "#4982E6",
|
|
|
- 'stroke-width': 1,
|
|
|
- width: 6,
|
|
|
- height: 6,
|
|
|
- x: rect.width / 2 + 5,
|
|
|
- y: 1
|
|
|
+ }, {
|
|
|
+ cursor: 'pointer'
|
|
|
}
|
|
|
);
|
|
|
|
|
|
this.outerLine.append(this.moveRect)
|
|
|
- this.outerLine.append(this.topLeftRect)
|
|
|
- this.outerLine.append(this.LeftRect)
|
|
|
- this.outerLine.append(this.bottomLeftRect)
|
|
|
- this.outerLine.append(this.bottomRect)
|
|
|
- this.outerLine.append(this.bottomRightRect)
|
|
|
- this.outerLine.append(this.rightRect)
|
|
|
- this.outerLine.append(this.topRightRect)
|
|
|
- this.outerLine.append(this.topRect)
|
|
|
this.outerLineContainer.append(this.outerLine)
|
|
|
this.outerLineContainer.append(this.deletetButton)
|
|
|
+
|
|
|
+ this.isRedaction && this.moveRect.addEventListener('mouseenter', () => {
|
|
|
+ this.shapeElement.style.backgroundColor = '#000000'
|
|
|
+ this.shapeElement.style.border = ''
|
|
|
+ })
|
|
|
+ this.isRedaction && this.moveRect.addEventListener('mouseleave', () => {
|
|
|
+ this.shapeElement.style.backgroundColor = ''
|
|
|
+ this.shapeElement.style.border = '2px solid #FF0000'
|
|
|
+ })
|
|
|
+
|
|
|
this.initial = true
|
|
|
}
|
|
|
|
|
@@ -328,13 +223,12 @@ export default class Redaction extends Base {
|
|
|
|
|
|
calculate (start, end) {
|
|
|
const initRect = this.rectCalc({ start, end });
|
|
|
- const actualbdwidth = (this.annotation.borderWidth || 2) * this.scale
|
|
|
|
|
|
return {
|
|
|
- top: initRect.top - actualbdwidth,
|
|
|
- left: initRect.left - actualbdwidth,
|
|
|
- width: initRect.width + actualbdwidth * 2,
|
|
|
- height: initRect.height + actualbdwidth * 2,
|
|
|
+ top: initRect.top,
|
|
|
+ left: initRect.left,
|
|
|
+ width: initRect.width,
|
|
|
+ height: initRect.height,
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -381,7 +275,7 @@ export default class Redaction extends Base {
|
|
|
|
|
|
handleClick () {
|
|
|
if (!this.hidden || document.fullscreenElement || this.layer.annotationStore.creating || this.layer.toolMode === 'editor') return
|
|
|
- if (this.layer.toolMode === 'security' && this.layer.tool === 'redaction') {
|
|
|
+ if (this.layer.toolMode === 'security') {
|
|
|
this.hidden = false
|
|
|
this.updateTool()
|
|
|
|
|
@@ -418,146 +312,12 @@ export default class Redaction extends Base {
|
|
|
clickY: pageY,
|
|
|
}
|
|
|
|
|
|
- document.addEventListener('mousemove', this.onMousemove)
|
|
|
document.addEventListener('mouseup', this.onMouseup)
|
|
|
- document.addEventListener('touchmove', this.onMousemove)
|
|
|
document.addEventListener('touchend', this.onMouseup)
|
|
|
|
|
|
this.handleClick()
|
|
|
};
|
|
|
|
|
|
- handleMouseMove (event) {
|
|
|
- if (event.button !== 0 && event.type === 'mousemove') return
|
|
|
- if (event.type === 'touchmove') {
|
|
|
- document.querySelector('.document-container').style.overflow = 'hidden'
|
|
|
- }
|
|
|
- this.moving = true
|
|
|
- const { pageX, pageY } = getClickPoint(event)
|
|
|
- const start = this.start
|
|
|
- const end = this.end
|
|
|
- const startState = this.startState
|
|
|
-
|
|
|
- const { width, height } = this.viewport
|
|
|
- if (startState.operator === 'nw-resize') {
|
|
|
- let x1 = pageX - (startState.clickX - this.start.x);
|
|
|
- let y1 = pageY - (startState.clickY - this.start.y);
|
|
|
- x1 = Math.min(end.x - 5, x1)
|
|
|
- x1 = Math.max(0, x1)
|
|
|
- y1 = Math.min(end.y - 5, y1)
|
|
|
- y1 = Math.max(0, y1)
|
|
|
-
|
|
|
- this.update({
|
|
|
- start: { x: x1, y: y1 },
|
|
|
- end,
|
|
|
- });
|
|
|
- } else if (startState.operator === 'w-resize') {
|
|
|
- let x1 = pageX - (startState.clickX - this.start.x);
|
|
|
- x1 = Math.min(end.x - 5, x1)
|
|
|
- x1 = Math.max(0, x1)
|
|
|
-
|
|
|
- this.update({
|
|
|
- start: { x: x1, y: start.y },
|
|
|
- end,
|
|
|
- });
|
|
|
- } else if (startState.operator === 'sw-resize') {
|
|
|
- let x1 = pageX - (startState.clickX - this.start.x);
|
|
|
- let y1 = pageY - (startState.clickY - this.end.y);
|
|
|
- x1 = Math.min(end.x - 5, x1)
|
|
|
- x1 = Math.max(0, x1)
|
|
|
- y1 = Math.min(height, y1)
|
|
|
- y1 = Math.max(start.y + 5, y1)
|
|
|
-
|
|
|
- this.update({
|
|
|
- start: { x: x1, y: start.y },
|
|
|
- end: { x: end.x, y: y1 },
|
|
|
- });
|
|
|
- } else if (startState.operator === 's-resize') {
|
|
|
- let y1 = pageY - (startState.clickY - this.end.y);
|
|
|
- y1 = Math.min(height, y1)
|
|
|
- y1 = Math.max(start.y + 5, y1)
|
|
|
- this.update({
|
|
|
- start,
|
|
|
- end: { x: end.x, y: y1 },
|
|
|
- });
|
|
|
- } else if (startState.operator === 'se-resize') {
|
|
|
- let x = pageX - (startState.clickX - this.end.x);
|
|
|
- let y = pageY - (startState.clickY - this.end.y);
|
|
|
- x = Math.min(width, x)
|
|
|
- x = Math.max(start.x + 5, x)
|
|
|
- y = Math.min(height, y)
|
|
|
- y = Math.max(start.y + 5, y)
|
|
|
- this.update({
|
|
|
- start,
|
|
|
- end: { x, y },
|
|
|
- });
|
|
|
- } else if (startState.operator === 'e-resize') {
|
|
|
- let x = pageX - (startState.clickX - this.end.x);
|
|
|
- x = Math.min(width, x)
|
|
|
- x = Math.max(start.x + 5, x)
|
|
|
- this.update({
|
|
|
- start,
|
|
|
- end: { x, y: end.y },
|
|
|
- });
|
|
|
- } else if (startState.operator === 'ne-resize') {
|
|
|
- let x = pageX - (startState.clickX - this.end.x);
|
|
|
- let y = pageY - (startState.clickY - this.start.y);
|
|
|
- x = Math.min(width, x)
|
|
|
- x = Math.max(start.x + 5, x)
|
|
|
- y = Math.min(end.y - 5, y)
|
|
|
- y = Math.max(0, y)
|
|
|
- this.update({
|
|
|
- start: { x: start.x, y },
|
|
|
- end: { x, y: end.y },
|
|
|
- });
|
|
|
- } else if (startState.operator === 'n-resize') {
|
|
|
- let y = pageY - (startState.clickY - this.start.y);
|
|
|
- y = Math.min(end.y - 5, y)
|
|
|
- y = Math.max(0, y)
|
|
|
- this.update({
|
|
|
- start: { x: start.x, y },
|
|
|
- end,
|
|
|
- });
|
|
|
- } else if (startState.operator === 'move') {
|
|
|
- let x1 = pageX - (startState.clickX - this.start.x);
|
|
|
- let y1 = pageY - (startState.clickY - this.start.y);
|
|
|
- let x2 = pageX - (startState.clickX - this.end.x);
|
|
|
- let y2 = pageY - (startState.clickY - this.end.y);
|
|
|
-
|
|
|
- const rect = {
|
|
|
- width: Math.abs(start.x -end.x),
|
|
|
- height: Math.abs(start.y -end.y)
|
|
|
- }
|
|
|
- if (x1 < x2) {
|
|
|
- x1 = Math.max(0, x1)
|
|
|
- x1 = Math.min(width - rect.width, x1)
|
|
|
- x2 = Math.max(rect.width, x2)
|
|
|
- x2 = Math.min(width, x2)
|
|
|
- } else {
|
|
|
- x2 = Math.max(0, x2)
|
|
|
- x2 = Math.min(width - rect.width, x2)
|
|
|
- x1 = Math.max(rect.width, x1)
|
|
|
- x1 = Math.min(width, x1)
|
|
|
- }
|
|
|
-
|
|
|
- if (y1 < y2) {
|
|
|
- y1 = Math.max(0, y1)
|
|
|
- y1 = Math.min(height - rect.height, y1)
|
|
|
- y2 = Math.max(rect.height, y2)
|
|
|
- y2 = Math.min(height, y2)
|
|
|
- } else {
|
|
|
- y2 = Math.max(0, y2)
|
|
|
- y2 = Math.min(height - rect.height, y2)
|
|
|
- y1 = Math.max(rect.height, y1)
|
|
|
- y1 = Math.min(height, y1)
|
|
|
- }
|
|
|
-
|
|
|
- this.update({
|
|
|
- start: { x: x1, y: y1 },
|
|
|
- end: { x: x2, y: y2 },
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
handleDelete (event) {
|
|
|
if (!this.annotationContainer) return
|
|
|
if (this.layer.tool && event) {
|
|
@@ -590,18 +350,12 @@ export default class Redaction extends Base {
|
|
|
if (event.type === 'touchend') {
|
|
|
document.querySelector('.document-container').style.overflow = 'auto'
|
|
|
}
|
|
|
- this.moving = false
|
|
|
- document.removeEventListener('mousemove', this.onMousemove)
|
|
|
document.removeEventListener('mouseup', this.onMouseup)
|
|
|
- document.removeEventListener('touchmove', this.onMousemove)
|
|
|
document.removeEventListener('touchend', this.onMouseup)
|
|
|
|
|
|
const { pageX, pageY } = getClickPoint(event)
|
|
|
if (pageX === this.startState.clickX && pageY === this.startState.clickY) return
|
|
|
|
|
|
- this.start = this.newStart
|
|
|
- this.end = this.newEnd
|
|
|
-
|
|
|
const annotation = this.annotation
|
|
|
const { start, end } = this.getInitialPoint()
|
|
|
|
|
@@ -624,55 +378,4 @@ export default class Redaction extends Base {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
- update ({ start, end }) {
|
|
|
- const rect = this.calculate(start, end)
|
|
|
-
|
|
|
- this.newStart = start
|
|
|
- this.newEnd = end
|
|
|
-
|
|
|
- this.annotationContainer.style.top = rect.top + 'px'
|
|
|
- this.annotationContainer.style.left = rect.left + 'px'
|
|
|
- this.annotationContainer.style.width = rect.width + 'px'
|
|
|
- this.annotationContainer.style.height = rect.height + 'px'
|
|
|
-
|
|
|
- this.annotationContainer.style.width = `${rect.width}px`;
|
|
|
- this.annotationContainer.style.height = `${rect.height}px`;
|
|
|
-
|
|
|
- this.shapeElement.style.width = `${rect.width}px`;
|
|
|
- this.shapeElement.style.height = `${rect.height}px`;
|
|
|
-
|
|
|
- this.outerLine.style.left = `${rect.left - 8}px`
|
|
|
- this.outerLine.style.top = `${rect.top - 8}px`
|
|
|
- this.outerLine.style.width = `${rect.width + 8 * 2}px`
|
|
|
- this.outerLine.style.height = `${rect.height + 8 * 2}px`
|
|
|
-
|
|
|
- const left = (rect.left + rect.width - 30) + 'px'
|
|
|
- const top = (rect.top + rect.height + 8) + 'px'
|
|
|
- this.deletetButton.style.left = left
|
|
|
- this.deletetButton.style.top = top
|
|
|
-
|
|
|
- this.moveRect.setAttribute('width', rect.width + 9)
|
|
|
- this.moveRect.setAttribute('height', rect.height + 9)
|
|
|
-
|
|
|
- this.LeftRect.setAttribute("y", rect.height / 2 + 5)
|
|
|
-
|
|
|
- this.bottomLeftRect.setAttribute("y", rect.height + 9)
|
|
|
-
|
|
|
- this.bottomRect.setAttribute("x", rect.width / 2 + 5)
|
|
|
- this.bottomRect.setAttribute("y", rect.height + 9)
|
|
|
-
|
|
|
-
|
|
|
- this.bottomRightRect.setAttribute("x", rect.width + 9)
|
|
|
- this.bottomRightRect.setAttribute("y", rect.height + 9)
|
|
|
-
|
|
|
-
|
|
|
- this.rightRect.setAttribute("x", rect.width + 9)
|
|
|
- this.rightRect.setAttribute("y", rect.height / 2 + 5)
|
|
|
-
|
|
|
-
|
|
|
- this.topRightRect.setAttribute("x", rect.width + 9)
|
|
|
-
|
|
|
- this.topRect.setAttribute("x", rect.width / 2 + 5)
|
|
|
- }
|
|
|
}
|