@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
1,032 lines (1,031 loc) • 121 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { randomId, Point } from '@syncfusion/ej2-drawings';
import { rotatePoint } from '@syncfusion/ej2-drawings';
import { Rect } from '@syncfusion/ej2-drawings';
import { transformPointByMatrix, rotateMatrix, identityMatrix } from '@syncfusion/ej2-drawings';
import { TextElement } from '@syncfusion/ej2-drawings';
import { Selector } from './selector';
import { findActiveElement } from './action';
import { cloneObject, isLineShapes } from './drawing-util';
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { updatePerimeterLabel } from './connector-util';
import { Browser } from '@syncfusion/ej2-base';
/**
* Defines the interactive tools
*
* @hidden
*/
var ToolBase = /** @class */ (function () {
/**
* Initializes the tool
*
* @param {PdfViewer} pdfViewer - Specified the pdfviewer component.
* @param {PdfViewerBase} pdfViewerBase - Specified the pdfViewer base component.
* @param {boolean} protectChange - Set the default value as false.
*/
function ToolBase(pdfViewer, pdfViewerBase, protectChange) {
if (protectChange === void 0) { protectChange = false; }
/**
* Command that is corresponding to the current action
*/
this.commandHandler = null;
/**
* Sets/Gets whether the interaction is being done
*/
this.inAction = false;
/**
* Sets/Gets the protect change
*/
this.pdfViewerBase = null;
/**
* Sets/Gets the current element that is under mouse
*/
/** @private */
this.currentElement = null;
/** @private */
this.blocked = false;
this.isTooltipVisible = false;
/** @private */
this.childTable = {};
/** @private */
this.helper = undefined;
/**
* Sets/Gets the previous object when mouse down
*/
this.undoElement = { annotations: [] };
this.undoParentElement = { annotations: [] };
this.commandHandler = pdfViewer;
this.pdfViewerBase = pdfViewerBase;
}
/**
* @param {IElement} currentElement - Specified the current element.
* @returns {void}
*/
ToolBase.prototype.startAction = function (currentElement) {
this.currentElement = currentElement;
this.inAction = true;
};
/**
* @private
* @param {MouseEventArgs} args - Mouse up event arguments.
* @returns {void}
*/
ToolBase.prototype.mouseDown = function (args) {
this.currentElement = args.source;
this.startPosition = this.currentPosition = this.prevPosition = args.position;
this.isTooltipVisible = true;
this.startAction(args.source);
};
/**
* @private
* @param {MouseEventArgs} args - Mouse up event arguments.
* @returns {boolean} - Returns true or false.
*/
ToolBase.prototype.mouseMove = function (args) {
this.currentPosition = args.position;
//this.currentElement = currentElement;
this.prevPageId = this.pdfViewerBase.activeElements.activePageID;
return !this.blocked;
};
/**
* @private
* @param {MouseEventArgs} args - Mouse up event arguments.
* @returns {void}
*/
ToolBase.prototype.mouseUp = function (args) {
this.currentPosition = args.position;
// this.currentElement = currentElement;
this.isTooltipVisible = false;
//At the end
this.endAction();
this.helper = null;
};
ToolBase.prototype.endAction = function () {
//remove helper
if (this.commandHandler) {
this.commandHandler.tool = '';
if (this.helper) {
this.commandHandler.remove(this.helper);
}
}
this.commandHandler = null;
this.currentElement = null;
this.currentPosition = null;
this.inAction = false;
this.blocked = false;
};
/**
* @private
* @param {MouseEventArgs} args - Mouse wheel event arguments.
* @returns {void}
*/
ToolBase.prototype.mouseWheel = function (args) {
this.currentPosition = args.position;
};
/**
* @private
* @param {MouseEventArgs} args - Mouse leave event arguments.
* @returns {void}
*/
ToolBase.prototype.mouseLeave = function (args) {
this.mouseUp(args);
};
ToolBase.prototype.updateSize = function (shape, startPoint, endPoint, corner, initialBounds, angle, isMouseUp) {
var zoom = this.commandHandler.viewerBase.getZoomFactor();
var difx = this.currentPosition.x / zoom - this.startPosition.x / zoom;
var dify = this.currentPosition.y / zoom - this.startPosition.y / zoom;
var rotateAngle = (shape instanceof TextElement) ? angle : shape.rotateAngle;
var matrix = identityMatrix();
rotateMatrix(matrix, -rotateAngle, 0, 0);
var deltaWidth = 0;
var deltaHeight = 0;
var diff;
var width = (shape instanceof TextElement) ? shape.actualSize.width : shape.wrapper.bounds.width;
var height = (shape instanceof TextElement) ? shape.actualSize.height : shape.wrapper.bounds.height;
var obj = shape;
if (!shape.formFieldAnnotationType) {
if (!shape.annotName && !shape.shapeAnnotationType) {
if (shape) {
obj = shape.annotations[0];
}
}
}
var annotationSettings = this.commandHandler.annotationModule ?
this.commandHandler.annotationModule.findAnnotationSettings(obj) : {};
var annotationMaxHeight = 0;
var annotationMaxWidth = 0;
var annotationMinHeight = 0;
var annotationMinWidth = 0;
if (annotationSettings.minWidth || annotationSettings.maxWidth || annotationSettings.minHeight || annotationSettings.maxHeight) {
annotationMaxHeight = annotationSettings.maxHeight ? annotationSettings.maxHeight : 2000;
annotationMaxWidth = annotationSettings.maxWidth ? annotationSettings.maxWidth : 2000;
annotationMinHeight = annotationSettings.minHeight ? annotationSettings.minHeight : 0;
annotationMinWidth = annotationSettings.minWidth ? annotationSettings.minWidth : 0;
}
var isAnnotationSet = false;
if (annotationMinHeight || annotationMinWidth || annotationMaxHeight || annotationMaxWidth) {
isAnnotationSet = true;
}
if (isAnnotationSet && isMouseUp) {
var size = this.getPositions(corner, difx, dify);
var newWidth = width + size.x;
var newHeight = height + size.y;
if (newHeight < annotationMinHeight) {
dify = annotationMinHeight - height;
}
else if (newHeight > annotationMaxHeight) {
dify = annotationMaxHeight - height;
}
if (newWidth < annotationMinWidth) {
difx = annotationMinWidth - width;
}
else if (newWidth > annotationMaxWidth) {
difx = annotationMaxWidth - width;
}
}
switch (corner) {
case 'ResizeWest':
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
deltaHeight = 1;
dify = 0;
if (isAnnotationSet) {
if (initialBounds.width - difx > annotationMaxWidth) {
difx = annotationMaxWidth - initialBounds.width;
}
}
deltaWidth = (initialBounds.width - difx) / width;
break;
case 'ResizeEast':
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
dify = 0;
if (isAnnotationSet) {
if (initialBounds.width + difx > annotationMaxWidth) {
difx = annotationMaxWidth - initialBounds.width;
}
}
deltaWidth = (initialBounds.width + difx) / width;
deltaHeight = 1;
break;
case 'ResizeNorth':
deltaWidth = 1;
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
if (isAnnotationSet) {
if (initialBounds.height - dify > annotationMaxHeight) {
dify = annotationMaxHeight - initialBounds.height;
}
}
deltaHeight = (initialBounds.height - dify) / height;
break;
case 'ResizeSouth':
deltaWidth = 1;
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
if (isAnnotationSet) {
if (initialBounds.height + dify > annotationMaxHeight) {
dify = annotationMaxHeight - initialBounds.height;
}
}
deltaHeight = (initialBounds.height + dify) / height;
break;
case 'ResizeNorthEast':
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
if (isAnnotationSet) {
if (initialBounds.width + difx > annotationMaxWidth) {
difx = annotationMaxWidth - initialBounds.width;
}
if (initialBounds.height - dify > annotationMaxHeight) {
dify = annotationMaxHeight - initialBounds.height;
}
}
deltaWidth = (initialBounds.width + difx) / width;
deltaHeight = (initialBounds.height - dify) / height;
break;
case 'ResizeNorthWest':
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
if (isAnnotationSet) {
if (initialBounds.width - difx > annotationMaxWidth) {
difx = annotationMaxWidth - initialBounds.width;
}
if (initialBounds.height - dify > annotationMaxHeight) {
dify = annotationMaxHeight - initialBounds.height;
}
}
deltaWidth = (initialBounds.width - difx) / width;
deltaHeight = (initialBounds.height - dify) / height;
break;
case 'ResizeSouthEast':
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
if (isAnnotationSet) {
if (initialBounds.width + difx > annotationMaxWidth) {
difx = annotationMaxWidth - initialBounds.width;
}
if (initialBounds.height + dify > annotationMaxHeight) {
dify = annotationMaxHeight - initialBounds.height;
}
}
deltaHeight = (initialBounds.height + dify) / height;
deltaWidth = (initialBounds.width + difx) / width;
break;
case 'ResizeSouthWest':
diff = transformPointByMatrix(matrix, ({ x: difx, y: dify }));
difx = diff.x;
dify = diff.y;
if (isAnnotationSet) {
if (initialBounds.width - difx > annotationMaxWidth) {
difx = annotationMaxWidth - initialBounds.width;
}
if (initialBounds.height + dify > annotationMaxHeight) {
dify = annotationMaxHeight - initialBounds.height;
}
}
deltaWidth = (initialBounds.width - difx) / width;
deltaHeight = (initialBounds.height + dify) / height;
break;
}
return { width: deltaWidth, height: deltaHeight };
};
ToolBase.prototype.getPivot = function (corner) {
switch (corner) {
case 'ResizeWest':
return { x: 1, y: 0.5 };
case 'ResizeEast':
return { x: 0, y: 0.5 };
case 'ResizeNorth':
return { x: 0.5, y: 1 };
case 'ResizeSouth':
return { x: 0.5, y: 0 };
case 'ResizeNorthEast':
return { x: 0, y: 1 };
case 'ResizeNorthWest':
return { x: 1, y: 1 };
case 'ResizeSouthEast':
return { x: 0, y: 0 };
case 'ResizeSouthWest':
return { x: 1, y: 0 };
}
return { x: 0.5, y: 0.5 };
};
ToolBase.prototype.getPositions = function (corner, x, y) {
switch (corner) {
case 'ResizeEast':
return { x: x, y: 0 };
case 'ResizeSouthEast':
return { x: x, y: y };
case 'ResizeSouth':
return { x: 0, y: y };
case 'ResizeNorth':
return { x: 0, y: -y };
case 'ResizeNorthEast':
return { x: x, y: -y };
case 'ResizeNorthWest':
return { x: -x, y: -y };
case 'ResizeWest':
return { x: -x, y: 0 };
case 'ResizeSouthWest':
return { x: -x, y: y };
}
return { x: x, y: y };
};
return ToolBase;
}());
export { ToolBase };
/**
* Helps to select the objects
*
* @hidden
*/
var SelectTool = /** @class */ (function (_super) {
__extends(SelectTool, _super);
function SelectTool(commandHandler, base) {
return _super.call(this, commandHandler, base, true) || this;
// this.action = action;
}
/**
* @private
* @param {MouseEventArgs} args - Mouse down event arguments.
* @returns {void}
*/
SelectTool.prototype.mouseDown = function (args) {
this.inAction = true;
this.mouseEventHelper(args);
_super.prototype.mouseDown.call(this, args);
};
SelectTool.prototype.mouseEventHelper = function (args) {
if (this.commandHandler && this.commandHandler.annotationModule) {
this.commandHandler.annotationModule.overlappedCollections =
findActiveElement(args, this.pdfViewerBase, this.commandHandler, true);
}
var object = findActiveElement(args, this.pdfViewerBase, this.commandHandler);
// if (!isNullOrUndefined(object) && (object as any).shapeAnnotationType !== 'Path'){
var isLock = false;
if (object && object.shapeAnnotationType === 'StickyNotes') {
if (object.annotationSettings && object.annotationSettings.isLock) {
if (this.commandHandler.annotationModule.checkAllowedInteractions('Select', object)) {
isLock = false;
}
else {
isLock = true;
}
}
}
if (!isLock) {
var currentSelctor = void 0;
if (args.source && args.annotationSelectorSettings !== null) {
currentSelctor = args.source.annotationSelectorSettings;
}
else {
currentSelctor = '';
}
if (this.commandHandler) {
var selectedObject = this.commandHandler.selectedItems;
if (selectedObject) {
var annotation = selectedObject.annotations[0];
var formField = selectedObject.formFields[0];
var currentAnnot = this.commandHandler.selectedItems.annotations[0];
var currentSource = args.source;
if ((selectedObject.annotations.length) && args.info && !args.info.ctrlKey
&& this.commandHandler.annotationModule &&
this.commandHandler.annotationModule.freeTextAnnotationModule.isInuptBoxInFocus === false) {
this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
}
else if (args.info && args.info.ctrlKey && ((currentSource && currentSource.shapeAnnotationType === 'FreeText') || (currentAnnot && currentAnnot.shapeAnnotationType === 'FreeText'))) {
this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
}
else if (isNullOrUndefined(object) && (this.commandHandler.annotationModule && !isNullOrUndefined(this.commandHandler.annotation.textMarkupAnnotationModule) && isNullOrUndefined(this.commandHandler.annotation.textMarkupAnnotationModule.currentTextMarkupAnnotation)) && this.commandHandler.formDesignerModule && !((currentSource && currentSource.shapeAnnotationType === 'FreeText') || (currentAnnot && (currentAnnot.shapeAnnotationType === 'FreeText' || currentAnnot.shapeAnnotationType === 'Image' || currentAnnot.shapeAnnotationType === 'StickyNotes')))) {
this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
}
if (object) {
if ((isNullOrUndefined(formField) || (formField &&
formField.id !== object.id)) &&
!isNullOrUndefined(this.pdfViewerBase.isFreeTextSelected) && !this.pdfViewerBase.isFreeTextSelected) {
this.commandHandler.select([object.id], currentSelctor);
this.commandHandler.viewerBase.isAnnotationMouseDown = true;
}
this.pdfViewerBase.isFreeTextSelected = false;
this.commandHandler.viewerBase.isFormFieldMouseDown = true;
}
if (selectedObject.annotations.length === 0 && annotation && annotation.shapeAnnotationType !== 'HandWrittenSignature' && annotation.shapeAnnotationType !== 'SignatureText' && annotation.shapeAnnotationType !== 'SignatureImage' && annotation.shapeAnnotationType !== 'Path' && !annotation.formFieldAnnotationType) {
if (this.commandHandler.enableToolbar && Browser.isDevice && !this.commandHandler.enableDesktopMode) {
this.commandHandler.toolbarModule.showToolbar(true);
}
this.commandHandler.fireAnnotationUnSelect(annotation.annotName, annotation.pageIndex, annotation);
}
if (selectedObject.annotations.length === 0 && annotation && (annotation.shapeAnnotationType === 'HandWrittenSignature' || annotation.shapeAnnotationType === 'SignatureText' || annotation.shapeAnnotationType === 'SignatureImage' || annotation.shapeAnnotationType === 'Path' || annotation.signatureType)) {
this.commandHandler.fireSignatureUnselect(annotation.signatureName, annotation.pageIndex, annotation);
}
if (selectedObject.formFields.length === 0 && this.commandHandler.formDesignerModule &&
formField && formField.formFieldAnnotationType) {
var field = { name: formField.name, id: formField.id,
value: formField.value, fontFamily: formField.fontFamily, fontSize: formField.fontSize,
fontStyle: formField.fontStyle,
color: formField.color,
backgroundColor: formField.backgroundColor,
alignment: formField.alignment, isReadonly: formField.isReadOnly,
visibility: formField.visibility,
maxLength: formField.maxLength, isRequired: formField.isRequired,
isPrint: formField.isPrint, rotation: formField.rotation, tooltip: formField.tooltip,
options: formField.options, isChecked: formField.isChecked,
isSelected: formField.isSelected,
customData: formField.customData, lineBound: formField.bounds,
pageNumber: formField.pageIndex, insertSpaces: formField.insertSpaces,
formFieldAnnotationType: formField.formFieldAnnotationType,
borderColor: formField.borderColor, thickness: formField.thickness,
isTransparent: formField.isTransparent
};
this.commandHandler.fireFormFieldUnselectEvent('formFieldUnselect', field, formField.pageIndex);
}
else if (this.pdfViewerBase.currentTarget && this.pdfViewerBase.currentTarget.id && this.commandHandler.formFields && event.type === 'mousedown') {
for (var i = 0; i < this.commandHandler.formFields.length; i++) {
var formField_1 = this.commandHandler.formFields[parseInt(i.toString(), 10)];
if (this.pdfViewerBase.currentTarget && this.pdfViewerBase.currentTarget.id === formField_1.id) {
var field = {
value: formField_1.value, fontFamily: formField_1.fontFamily, fontSize: formField_1.fontSize,
fontStyle: formField_1.fontStyle, color: formField_1.color,
backgroundColor: formField_1.backgroundColor, alignment: formField_1.alignment,
isReadonly: formField_1.isReadonly, visibility: formField_1.visibility,
maxLength: formField_1.maxLength, isRequired: formField_1.isRequired,
isPrint: formField_1.isPrint, rotation: formField_1.rotateAngle,
tooltip: formField_1.tooltip,
options: formField_1.options, isChecked: formField_1.isChecked,
isSelected: formField_1.isSelected, id: formField_1.id, name: formField_1.name
};
if (!object) {
this.commandHandler.fireFocusOutFormField(field, formField_1.pageIndex);
this.pdfViewerBase.currentTarget = null;
}
else {
if (this.pdfViewerBase.currentTarget.id !== event.target.id && event.target.className !== 'e-pv-text-layer') {
this.commandHandler.fireFocusOutFormField(field, formField_1.pageIndex);
this.pdfViewerBase.currentTarget = null;
}
}
}
}
}
}
}
}
// } else {
// if (!isNullOrUndefined(this.commandHandler))
// this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
// }
};
/**
* @private
* @param {MouseEventArgs} args - Mouse move event arguments.
* @returns {boolean} - Returns true or false.
*/
SelectTool.prototype.mouseMove = function (args) {
_super.prototype.mouseMove.call(this, args);
//draw selected region
return !this.blocked;
};
/**
* @private
* @param {MouseEventArgs} args - Mouse up event arguments.
* @returns {void}
*/
SelectTool.prototype.mouseUp = function (args) {
this.mouseEventHelper(args);
this.inAction = false;
_super.prototype.mouseUp.call(this, args);
};
/**
* @private
* @param {MouseEventArgs} args - Mouse leave event arguments.
* @returns {void}
*/
SelectTool.prototype.mouseLeave = function (args) {
if (this.inAction) {
this.mouseUp(args);
}
};
return SelectTool;
}(ToolBase));
export { SelectTool };
/** @hidden */
var MoveTool = /** @class */ (function (_super) {
__extends(MoveTool, _super);
function MoveTool(commandHandler, base) {
var _this = _super.call(this, commandHandler, base) || this;
/** @private */
_this.currentTarget = null;
/** @private */
_this.prevNode = null;
return _this;
}
/**
* @private
* @param {MouseEventArgs} args - Mouse down event arguments.
* @returns {void}
*/
MoveTool.prototype.mouseDown = function (args) {
_super.prototype.mouseDown.call(this, args);
this.offset = { x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY };
this.startPosition = args.position;
var nodeMouseDown = cloneObject(args.source);
this.redoElement = {
bounds: {
x: nodeMouseDown.wrapper.offsetX, y: nodeMouseDown.wrapper.offsetY,
width: nodeMouseDown.wrapper.actualSize.width, height: nodeMouseDown.wrapper.actualSize.height
}
};
if (isLineShapes(nodeMouseDown)) {
this.redoElement.vertexPoints = nodeMouseDown.vertexPoints;
this.redoElement.leaderHeight = nodeMouseDown.leaderHeight;
}
this.inAction = true;
};
/**
* @private
* @param {any} args - Specified the mouse event arguments.
* @returns {void}
*/
MoveTool.prototype.mouseUp = function (args) {
if (this.commandHandler && args.source) {
this.checkisAnnotationMove(args);
var isDragged = false;
var currentSelctor = args.source.annotationSelectorSettings;
this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
this.commandHandler.select([args.source.id], currentSelctor);
if (this.pdfViewerBase.activeElements.activePageID === args.source.pageIndex && this.pdfViewerBase.action === 'Drag') {
this.commandHandler.dragSelectedObjects(this.calculateMouseActionXDiff(args), this.calculateMouseActionYDiff(args), this.pdfViewerBase.activeElements.activePageID, currentSelctor, null);
}
if (args.source && (args.source.formFieldAnnotationType === 'Textbox' || args.source.formFieldAnnotationType === 'Checkbox'
|| args.source.formFieldAnnotationType === 'RadioButton' || args.source.formFieldAnnotationType === 'ListBox'
|| args.source.formFieldAnnotationType === 'SignatureField' || args.source.formFieldAnnotationType === 'InitialField' || args.source.formFieldAnnotationType === 'DropdownList'
|| args.source.formFieldAnnotationType === 'PasswordField')) {
this.commandHandler.formDesignerModule.updateHTMLElement(args.source);
}
this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelctor);
this.commandHandler.viewerBase.isAnnotationMouseMove = false;
this.commandHandler.viewerBase.isFormFieldMouseMove = false;
var newShapeObject = {
bounds: {
x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY,
width: args.source.wrapper.actualSize.width, height: args.source.wrapper.actualSize.height
}, modifiedDate: args.source.modifiedDate
};
if (isLineShapes(args.source)) {
newShapeObject.vertexPoints = args.source.vertexPoints;
newShapeObject.leaderHeight = args.source.leaderHeight;
}
if (args.target && args.target.formFieldAnnotationType) {
var node = args.target;
var field = {
value: node.value, fontFamily: node.fontFamily, fontSize: node.fontSize, fontStyle: node.fontStyle,
color: node.color, backgroundColor: node.backgroundColor,
borderColor: node.borderColor,
thickness: node.thickness, alignment: node.alignment,
isReadonly: node.isReadonly, visibility: node.visibility,
maxLength: node.maxLength, isRequired: node.isRequired, isPrint: node.isPrint,
rotation: node.rotateAngle, tooltip: node.tooltip, options: node.options,
isChecked: node.isChecked, isSelected: node.isSelected, id: args.source ? args.source.id : '',
name: node.name, customData: node.customData, lineBound: node.bounds,
pageNumber: node.pageIndex, insertSpaces: node.insertSpaces,
formFieldAnnotationType: node.formFieldAnnotationType, isTransparent: node.isTransparent
};
var actualWidth = args.source.wrapper.actualSize.width;
var actualHeight = args.source.wrapper.actualSize.height;
var currentPosition = { X: args.source.wrapper.offsetX - actualWidth / 2,
Y: args.source.wrapper.offsetY - actualHeight / 2,
Width: actualWidth, Height: actualHeight };
var previousPosition = { X: this.offset.x - actualWidth / 2, Y: this.offset.y - actualHeight / 2,
Width: args.source.wrapper.actualSize.width, Height: args.source.wrapper.actualSize.height };
this.commandHandler.fireFormFieldMoveEvent('formFieldMove', field, node.pageIndex, previousPosition, currentPosition);
}
if (!isNullOrUndefined(this.redoElement) && (this.redoElement.bounds.height !== newShapeObject.bounds.height ||
this.redoElement.bounds.width !== newShapeObject.bounds.width || this.redoElement.bounds.x !==
newShapeObject.bounds.x || this.redoElement.bounds.y !== newShapeObject.bounds.y)) {
isDragged = true;
}
if (this.commandHandler.annotation && isDragged) {
this.commandHandler.annotation.addAction(this.pageIndex, null, args.source, 'Drag', '', this.redoElement, newShapeObject);
this.commandHandler.annotation.stampAnnotationModule.updateSessionStorage(args.source, null, 'Drag');
this.commandHandler.annotation.stickyNotesAnnotationModule.updateStickyNotes(args.source, null);
}
}
var shapeAnnotationType = this.commandHandler && this.commandHandler.selectedItems &&
this.commandHandler.selectedItems.annotations && this.commandHandler.selectedItems.annotations.length > 0 ?
this.commandHandler.selectedItems.annotations[0].shapeAnnotationType : null;
if (shapeAnnotationType && shapeAnnotationType !== 'Image' && shapeAnnotationType !== 'SignatureImage') {
_super.prototype.mouseUp.call(this, args);
}
else if (shapeAnnotationType === 'Image' || shapeAnnotationType === 'SignatureImage') {
this.inAction = false;
}
else if (this.commandHandler && this.commandHandler.selectedItems && this.commandHandler.selectedItems.formFields &&
this.commandHandler.selectedItems.formFields.length > 0) {
_super.prototype.mouseUp.call(this, args);
}
};
MoveTool.prototype.calculateMouseXDiff = function () {
if (this.currentPosition && this.startPosition) {
return this.currentPosition.x - this.startPosition.x;
}
else {
return 0;
}
};
MoveTool.prototype.calculateMouseYDiff = function () {
if (this.currentPosition && this.startPosition) {
return this.currentPosition.y - this.startPosition.y;
}
else {
return 0;
}
};
MoveTool.prototype.calculateMouseActionXDiff = function (args) {
var x = this.calculateMouseXDiff() / this.commandHandler.viewerBase.getZoomFactor();
// let y: number = this.calculateMouseYDiff() / this.commandHandler.magnification.zoomFactor;
if (this.offset) {
var requiredX = this.offset.x + x;
// let requiredY: number = this.offset.y + y;
return requiredX - args.source.wrapper.offsetX;
//let diffY: number = requiredY - args.source.wrapper.offsetY;
}
else {
return 0;
}
};
MoveTool.prototype.calculateMouseActionYDiff = function (args) {
// let x: number = this.calculateMouseXDiff() / this.commandHandler.magnification.zoomFactor;
var y = this.calculateMouseYDiff() / this.commandHandler.viewerBase.getZoomFactor();
if (this.offset) {
// let requiredX: number = this.offset.x + x;
var requiredY = this.offset.y + y;
// let diffX: number = requiredX - args.source.wrapper.offsetX;
return requiredY - args.source.wrapper.offsetY;
}
else {
return 0;
}
};
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @param {boolean} isStamp - Specified the stamp annotation or not.
* @param {boolean} isSkip - Specified the annotation skip or not.
* @returns {boolean} - Returns the true or false.
*/
MoveTool.prototype.mouseMove = function (args, isStamp, isSkip) {
_super.prototype.mouseMove.call(this, args);
if (this.inAction) {
this.currentPosition = args.position;
this.currentTarget = args.target;
var currentSelctor = args.source.annotationSelectorSettings;
var x = this.calculateMouseXDiff() / this.commandHandler.viewerBase.getZoomFactor();
var y = this.calculateMouseYDiff() / this.commandHandler.viewerBase.getZoomFactor();
var requiredX = this.offset.x + x;
var requiredY = this.offset.y + y;
var diffX = this.calculateMouseActionXDiff(args);
var diffY = this.calculateMouseActionYDiff(args);
var selectedItem = this.commandHandler.selectedItems.annotations[0];
var cobject = void 0;
if (!this.helper) {
cobject = this.commandHandler.selectedItems.annotations.length > 0 ?
cloneObject(this.commandHandler.selectedItems.annotations[0]) :
cloneObject(this.commandHandler.selectedItems.formFields[0]);
if (cobject.wrapper) {
diffX = requiredX - cobject.wrapper.offsetX;
diffY = requiredY - cobject.wrapper.offsetY;
cobject.bounds = this.commandHandler.selectedItems.annotations.length > 0 ?
this.commandHandler.selectedItems.annotations[0].wrapper.bounds :
this.commandHandler.selectedItems.formFields[0].wrapper.bounds;
}
cobject.wrapper = undefined;
cobject.id = 'diagram_helper';
if (cobject.shapeAnnotationType === 'Stamp') {
cobject.strokeColor = '';
cobject.borderDashArray = '';
cobject.fillColor = 'transparent';
cobject.stampFillColor = 'transparent';
cobject.data = '';
}
else if (cobject.shapeAnnotationType === 'FreeText') {
cobject.strokeColor = 'blue';
cobject.fillColor = 'transparent';
cobject.thickness = 1;
cobject.opacity = 1;
cobject.dynamicText = '';
}
else if (cobject.shapeAnnotationType === 'SignatureText') {
cobject.strokeColor = 'red';
cobject.borderDashArray = '5,5';
cobject.fillColor = 'transparent';
cobject.thickness = 2;
cobject.opacity = 1;
cobject.data = '';
}
else {
cobject.strokeColor = 'red';
cobject.borderDashArray = '5,5';
cobject.fillColor = 'transparent';
cobject.thickness = 2;
cobject.opacity = 1;
}
if (cobject.enableShapeLabel === true) {
cobject.labelContent = '';
}
var shapeAnnotationType = cobject.shapeAnnotationType;
if (!isStamp && shapeAnnotationType !== 'Image' && shapeAnnotationType !== 'SignatureImage') {
this.helper = cobject = this.commandHandler.add(cobject);
}
else {
cobject = this.helper = args.source;
}
if (this.commandHandler.selectedItems.annotations.length > 0) {
this.commandHandler.selectedItems.annotations = [cobject];
}
else {
this.commandHandler.selectedItems.formFields = [cobject];
}
}
else {
diffX = requiredX - this.helper.wrapper.offsetX;
diffY = requiredY - this.helper.wrapper.offsetY;
}
if (this.helper && this.helper.shapeAnnotationType === 'Stamp') {
isStamp = true;
}
if (this.commandHandler.checkBoundaryConstraints(diffX, diffY, this.pdfViewerBase.activeElements.activePageID, this.helper.wrapper.bounds, isStamp, isSkip)) {
var shapeAnnotationType = this.helper.shapeAnnotationType;
if (this.helper && (shapeAnnotationType === 'Image' || shapeAnnotationType === 'SignatureImage')) {
this.checkisAnnotationMove(args);
var currentSelctor_1 = args.source.annotationSelectorSettings;
this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
this.commandHandler.select([args.source.id], currentSelctor_1);
this.commandHandler.dragSelectedObjects(diffX, diffY, this.pdfViewerBase.activeElements.activePageID, currentSelctor_1, this.helper);
this.commandHandler.renderSelector(this.pdfViewerBase.activeElements.activePageID, currentSelctor_1);
}
else {
this.commandHandler.dragSelectedObjects(diffX, diffY, this.pdfViewerBase.activeElements.activePageID, currentSelctor, this.helper);
}
this.prevNode = this.helper;
this.prevPosition = this.currentPosition;
}
else {
this.currentPosition = this.prevPosition;
}
if (selectedItem && selectedItem.annotName) {
this.commandHandler.annotation.triggerAnnotationMove(selectedItem, true);
}
}
return true;
};
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {void}
*/
MoveTool.prototype.mouseLeave = function (args) {
var currentSelctor = args.source.annotationSelectorSettings;
var requiredX = this.offset.x + this.calculateMouseXDiff();
var requiredY = this.offset.y + this.calculateMouseYDiff();
var diffX = requiredX - args.source.wrapper.offsetX;
var diffY = requiredY - args.source.wrapper.offsetY;
this.commandHandler.dragSelectedObjects(diffX, diffY, this.prevPageId, currentSelctor, null);
this.commandHandler.renderSelector(this.prevPageId, currentSelctor);
_super.prototype.mouseLeave.call(this, args);
};
/**
* @private
* @returns {void}
*/
MoveTool.prototype.endAction = function () {
_super.prototype.endAction.call(this);
this.currentTarget = null;
this.prevPosition = null;
};
MoveTool.prototype.checkisAnnotationMove = function (args) {
if (this.commandHandler.selectedItems && this.commandHandler.selectedItems.annotations &&
this.commandHandler.selectedItems.annotations.length > 0) {
if (this.commandHandler.selectedItems.annotations[0].annotName === args.source.annotName) {
this.commandHandler.viewerBase.isAnnotationMouseMove = true;
}
}
else {
this.commandHandler.viewerBase.isAnnotationMouseMove = false;
}
if (this.commandHandler.selectedItems && this.commandHandler.selectedItems.formFields &&
this.commandHandler.selectedItems.formFields.length > 0) {
if (this.commandHandler.selectedItems.formFields[0].name === args.source.name) {
this.commandHandler.viewerBase.isFormFieldMouseMove = true;
}
}
else {
this.commandHandler.viewerBase.isFormFieldMouseMove = false;
}
};
return MoveTool;
}(ToolBase));
export { MoveTool };
/** @hidden */
var StampTool = /** @class */ (function (_super) {
__extends(StampTool, _super);
function StampTool() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {void}
*/
StampTool.prototype.mouseDown = function (args) {
_super.prototype.mouseUp.call(this, args);
};
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {boolean} - Returns the true or false.
*/
StampTool.prototype.mouseMove = function (args) {
var newObject;
if (!this.inAction) {
var pageIndex = this.pdfViewerBase.activeElements.activePageID;
this.commandHandler.clearSelection(this.pdfViewerBase.activeElements.activePageID);
var nodeElement = this.commandHandler.annotation.stampAnnotationModule.moveStampElement(args.position.x, args.position.y, pageIndex);
if (nodeElement.shapeAnnotationType === 'SignatureText') {
var textWidth = this.getTextWidth(nodeElement.data, nodeElement.fontSize, nodeElement.fontFamily);
var widthRatio = 1;
if (textWidth > nodeElement.bounds.width) {
widthRatio = nodeElement.bounds.width / textWidth;
}
nodeElement.fontSize = this.getFontSize(Math.floor((nodeElement.fontSize * widthRatio)));
var defaultFontSize = 32; // default font size.
nodeElement.bounds.height = nodeElement.fontSize < defaultFontSize ? nodeElement.fontSize * 2 : nodeElement.bounds.height;
nodeElement.thickness = 0;
}
newObject = this.commandHandler.add(nodeElement);
args.source = this.commandHandler.annotations[this.commandHandler.annotations.length - 1];
args.sourceWrapper = args.source.wrapper;
this.inAction = true;
var currentSource = args.source;
if (currentSource && (currentSource.shapeAnnotationType === 'HandWrittenSignature' || currentSource.shapeAnnotationType === 'SignatureText' || currentSource.shapeAnnotationType === 'SignatureImage')) {
this['offset'] = { x: args.source.wrapper.offsetX - (args.source.wrapper.bounds.width / 2), y: args.source.wrapper.offsetY - (args.source.wrapper.bounds.height / 2) };
}
else {
this['offset'] = { x: args.source.wrapper.offsetX, y: args.source.wrapper.offsetY };
}
this.startPosition = args.position;
this.commandHandler.select([newObject.id]);
}
var currentSelctor = args.source.annotationSelectorSettings;
_super.prototype.mouseMove.call(this, args, true, true);
this.commandHandler.renderSelector(args.source.pageIndex, currentSelctor);
return this.inAction;
};
StampTool.prototype.getTextWidth = function (text, font, fontFamily) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var fontName;
if (font) {
fontName = font + 'px' + ' ' + fontFamily;
}
context.font = fontName || getComputedStyle(document.body).font;
var textWidth = context.measureText(text).width;
this.pdfViewerBase.releaseCanvas(canvas);
return textWidth;
};
/**
* @param {number} fontSize - Font size.
* @returns {number} - Returns the font size.
*/
StampTool.prototype.getFontSize = function (fontSize) {
return (fontSize % 2 === 0) ? fontSize : --fontSize;
};
return StampTool;
}(MoveTool));
export { StampTool };
/**
* Draws a node that is defined by the user
*
* @hidden
*/
var InkDrawingTool = /** @class */ (function (_super) {
__extends(InkDrawingTool, _super);
function InkDrawingTool(commandHandler, base, sourceObject) {
var _this = _super.call(this, commandHandler, base) || this;
_this.sourceObject = sourceObject;
return _this;
}
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {void}
*/
InkDrawingTool.prototype.mouseDown = function (args) {
this.pdfViewerBase.disableTextSelectionMode();
_super.prototype.mouseDown.call(this, args);
this.inAction = true;
var node = { currentPosition: this.currentPosition, prevPosition: this.prevPosition };
this.commandHandler.annotation.inkAnnotationModule.drawInkInCanvas(node, this.pdfViewerBase.activeElements.activePageID);
};
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {boolean} - Returns true or false.
*/
InkDrawingTool.prototype.mouseMove = function (args) {
_super.prototype.mouseMove.call(this, args);
if (this.inAction) {
var node = { currentPosition: this.currentPosition, prevPosition: this.pdfViewerBase.prevPosition };
this.commandHandler.annotation.inkAnnotationModule.drawInkInCanvas(node, this.pdfViewerBase.activeElements.activePageID);
}
return this.inAction;
};
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {boolean} - Returns true.
*/
InkDrawingTool.prototype.mouseUp = function (args) {
this.commandHandler.annotation.inkAnnotationModule.storePathData();
return true;
};
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {void}
*/
InkDrawingTool.prototype.mouseLeave = function (args) {
//this.mouseUp(args);
};
/**
* @private
* @returns {void}
*/
InkDrawingTool.prototype.endAction = function () {
_super.prototype.endAction.call(this);
};
return InkDrawingTool;
}(ToolBase));
export { InkDrawingTool };
/**
* Helps to edit the selected connectors
*
* @hidden
*/
var ConnectTool = /** @class */ (function (_super) {
__extends(ConnectTool, _super);
function ConnectTool(commandHandler, base, endPoint) {
var _this = _super.call(this, commandHandler, base, true) || this;
_this.endPoint = endPoint;
return _this;
}
/**
* @private
* @param {MouseEventArgs} args - Specified the mouse event arguments.
* @returns {void}
*/
ConnectTool.prototype.mouseDown = function (args) {
this.inAction = true;
this.undoElement = undefined;
_super.prototype.mouseDown.call(this, args);
var oldValue;
var connectors;
if (args.source && args.source.annotations) {
oldValue = { x: this.prevPosition.x, y: this.prevPosition.y };
connectors = args.source.annotations[0];
}
this.initialPosition = args.position;
this.prevSource = this.commandHandler.selectedItems.annotations[0];
var nodeElement = cloneObject(args.source);
this.redoElement = {
bounds: {
x: nodeElement.wrapper.offsetX, y: nodeElement.wrapper.offsetY,
width: nodeElement.wrapper.actualSize.width, height: nodeElement.wrapper.actualSize.height
}
};
if (isLineShapes(nodeElement)) {
this.redoElement.vertexPoints = nodeElement.vertexPoints;
this.redoElement.leaderHeight = nodeElement.leaderHeight;
if (nodeElement.measureType === 'Distance' || nodeElement.measureType === 'Perimeter' || nodeElement.measureType === 'Area' || nodeElement.measureType === 'Volume') {
this.redoElement.notes = nodeElement.notes;
}
}