@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
1,282 lines (1,277 loc) • 6.2 MB
JavaScript
import { Property, Complex, ChildProperty, isNullOrUndefined, Collection, getValue, compile, Browser, isBlazor, SanitizeHtmlHelper, createElement, Internationalization, initializeCSPTemplate, classList, closest, L10n, Event, NotifyPropertyChanges, Component, Draggable, Droppable, getComponent } from '@syncfusion/ej2-base';
import { Point, Size, Container, identityMatrix, rotateMatrix, transformPointByMatrix, Rect, RotateTransform, PathElement, TextElement, randomId, intersect3, DrawingElement, createMeasureElements, ImageElement, Canvas, refreshDiagramElements, getDiagramElement, ThumbsConstraints, scaleMatrix, cornersPointsBeforeRotation, DrawingRenderer, SvgRenderer, rotatePoint, contains, createHtmlElement, createSvgElement, setAttributeSvg, processPathData, splitArrayCollection, getPathString } from '@syncfusion/ej2-drawings';
import { NumericTextBox, Slider, ColorPicker, TextBox } from '@syncfusion/ej2-inputs';
import { Dialog, Tooltip } from '@syncfusion/ej2-popups';
import { DropDownButton } from '@syncfusion/ej2-splitbuttons';
import { InPlaceEditor } from '@syncfusion/ej2-inplace-editor';
import { Accordion, ContextMenu as ContextMenu$1, Toolbar as Toolbar$1, Tab, Menu, TreeView } from '@syncfusion/ej2-navigations';
import { Toast } from '@syncfusion/ej2-notifications';
import { _decode, PdfTrueTypeFont, PdfFontStyle, PdfBitmap, _stringToBytes, _ContentParser, PdfDocument, PdfPageSettings, PdfMargins, _encode, PdfAnnotationStateModel, PdfAnnotationState, PdfRotationAngle, PdfTextMarkupAnnotation, PdfLineAnnotation, PdfSquareAnnotation, PdfRectangleAnnotation, PdfCircleAnnotation, PdfEllipseAnnotation, PdfPolygonAnnotation, PdfPolyLineAnnotation, PdfAngleMeasurementAnnotation, PdfRubberStampAnnotation, PdfPopupAnnotation, PdfFreeTextAnnotation, PdfInkAnnotation, PdfSignatureField, PdfPermissionFlag, PdfPageImportOptions, DataFormat, PdfAnnotationExportSettings, PdfTextStyle, PdfUriAnnotation, PdfTextWebLinkAnnotation, PdfDocumentLinkAnnotation, PdfFormFieldExportSettings, PdfFontFamily, PdfStandardFont, PdfTextAlignment, PdfAnnotationFlag, PdfTextBoxField, PdfComboBoxField, PdfCheckBoxField, PdfListBoxField, PdfRadioButtonListField, PdfListFieldItem, PdfRadioButtonListItem, PdfPath, PdfFormFieldVisibility, PdfAnnotationBorder, PdfBorderEffect, PdfBorderEffectStyle, _PdfDictionary, _PdfName, PdfLineEndingStyle, PdfAnnotationIntent, PdfTextMarkupAnnotationType, PdfTemplate, PdfBrush, PdfPen, PdfLineIntent, PdfPopupIcon, PdfStringFormat, PdfVerticalAlignment, PdfMeasurementUnit, PdfRubberStampAnnotationIcon, PdfCircleMeasurementType, PdfLineCaptionType, PdfBorderStyle, _annotationFlagsToString } from '@syncfusion/ej2-pdf';
import { CheckBox, Button } from '@syncfusion/ej2-buttons';
import { ComboBox, AutoComplete, DropDownList } from '@syncfusion/ej2-dropdowns';
import { Query } from '@syncfusion/ej2-data';
import { ListView } from '@syncfusion/ej2-lists';
var __extends = (undefined && undefined.__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 __());
};
})();
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
* The `PdfBounds` is base for annotation bounds.
*
* @hidden
*/
var PdfBounds = /** @__PURE__ @class */ (function (_super) {
__extends(PdfBounds, _super);
function PdfBounds() {
return _super !== null && _super.apply(this, arguments) || this;
}
__decorate([
Property(0)
], PdfBounds.prototype, "x", void 0);
__decorate([
Property(0)
], PdfBounds.prototype, "y", void 0);
__decorate([
Property(0)
], PdfBounds.prototype, "width", void 0);
__decorate([
Property(0)
], PdfBounds.prototype, "height", void 0);
__decorate([
Property(0)
], PdfBounds.prototype, "left", void 0);
__decorate([
Property(0)
], PdfBounds.prototype, "top", void 0);
__decorate([
Property(0)
], PdfBounds.prototype, "right", void 0);
__decorate([
Property(0)
], PdfBounds.prototype, "bottom", void 0);
__decorate([
Complex({ x: 0, y: 0 }, Point)
], PdfBounds.prototype, "location", void 0);
__decorate([
Complex(new Size(0, 0), Size)
], PdfBounds.prototype, "size", void 0);
return PdfBounds;
}(ChildProperty));
/**
* The `PdfFont` is base for annotation Text styles.
*
* @hidden
*/
var PdfFont = /** @__PURE__ @class */ (function (_super) {
__extends(PdfFont, _super);
function PdfFont() {
return _super !== null && _super.apply(this, arguments) || this;
}
__decorate([
Property(false)
], PdfFont.prototype, "isBold", void 0);
__decorate([
Property(false)
], PdfFont.prototype, "isItalic", void 0);
__decorate([
Property(false)
], PdfFont.prototype, "isUnderline", void 0);
__decorate([
Property(false)
], PdfFont.prototype, "isStrikeout", void 0);
return PdfFont;
}(ChildProperty));
/**
* Defines the common behavior of PdfAnnotationBase
*
* @hidden
*/
var PdfAnnotationBase = /** @__PURE__ @class */ (function (_super) {
__extends(PdfAnnotationBase, _super);
function PdfAnnotationBase(parent, propName, defaultValue, isArray) {
return _super.call(this, parent, propName, defaultValue, isArray) || this;
}
__decorate([
Property('')
], PdfAnnotationBase.prototype, "id", void 0);
__decorate([
Property('Rectangle')
], PdfAnnotationBase.prototype, "shapeAnnotationType", void 0);
__decorate([
Property(null)
], PdfAnnotationBase.prototype, "formFieldAnnotationType", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "measureType", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "author", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "modifiedDate", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "subject", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "notes", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "isCommentLock", void 0);
__decorate([
Property('black')
], PdfAnnotationBase.prototype, "strokeColor", void 0);
__decorate([
Property('#ffffff00')
], PdfAnnotationBase.prototype, "fillColor", void 0);
__decorate([
Property('#ffffff00')
], PdfAnnotationBase.prototype, "stampFillColor", void 0);
__decorate([
Property('black')
], PdfAnnotationBase.prototype, "stampStrokeColor", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "data", void 0);
__decorate([
Property(1)
], PdfAnnotationBase.prototype, "opacity", void 0);
__decorate([
Property(1)
], PdfAnnotationBase.prototype, "thickness", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "borderStyle", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "borderDashArray", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "rotateAngle", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "isCloudShape", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "cloudIntensity", void 0);
__decorate([
Property(40)
], PdfAnnotationBase.prototype, "leaderHeight", void 0);
__decorate([
Property(null)
], PdfAnnotationBase.prototype, "lineHeadStart", void 0);
__decorate([
Property(null)
], PdfAnnotationBase.prototype, "lineHeadEnd", void 0);
__decorate([
Property([])
], PdfAnnotationBase.prototype, "vertexPoints", void 0);
__decorate([
Property(null)
], PdfAnnotationBase.prototype, "sourcePoint", void 0);
__decorate([
Property('None')
], PdfAnnotationBase.prototype, "sourceDecoraterShapes", void 0);
__decorate([
Property('None')
], PdfAnnotationBase.prototype, "taregetDecoraterShapes", void 0);
__decorate([
Property(null)
], PdfAnnotationBase.prototype, "targetPoint", void 0);
__decorate([
Property([])
], PdfAnnotationBase.prototype, "segments", void 0);
__decorate([
Complex({ x: 0, y: 0 }, PdfBounds)
], PdfAnnotationBase.prototype, "bounds", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "pageIndex", void 0);
__decorate([
Property(-1)
], PdfAnnotationBase.prototype, "zIndex", void 0);
__decorate([
Property(null)
], PdfAnnotationBase.prototype, "wrapper", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "isDynamicStamp", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "dynamicText", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "annotName", void 0);
__decorate([
Property({})
], PdfAnnotationBase.prototype, "review", void 0);
__decorate([
Property([])
], PdfAnnotationBase.prototype, "comments", void 0);
__decorate([
Property('#000')
], PdfAnnotationBase.prototype, "fontColor", void 0);
__decorate([
Property(16)
], PdfAnnotationBase.prototype, "fontSize", void 0);
__decorate([
Property('Helvetica')
], PdfAnnotationBase.prototype, "fontFamily", void 0);
__decorate([
Property('None')
], PdfAnnotationBase.prototype, "fontStyle", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "enableShapeLabel", void 0);
__decorate([
Property('label')
], PdfAnnotationBase.prototype, "labelContent", void 0);
__decorate([
Property('#ffffff00')
], PdfAnnotationBase.prototype, "labelFillColor", void 0);
__decorate([
Property(15)
], PdfAnnotationBase.prototype, "labelMaxLength", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "template", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "templateSize", void 0);
__decorate([
Property(1)
], PdfAnnotationBase.prototype, "labelOpacity", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "annotationSelectorSettings", void 0);
__decorate([
Property('#ffffff00')
], PdfAnnotationBase.prototype, "labelBorderColor", void 0);
__decorate([
Property('left')
], PdfAnnotationBase.prototype, "textAlign", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "signatureName", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "minHeight", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "minWidth", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "maxHeight", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "maxWidth", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "isLock", void 0);
__decorate([
Property('UI Drawn Annotation')
], PdfAnnotationBase.prototype, "annotationAddMode", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "annotationSettings", void 0);
__decorate([
Property(16)
], PdfAnnotationBase.prototype, "previousFontSize", void 0);
__decorate([
Complex({ isBold: false, isItalic: false, isStrikeout: false, isUnderline: false }, PdfFont)
], PdfAnnotationBase.prototype, "font", void 0);
__decorate([
Complex({ x: 0, y: 0 }, PdfBounds)
], PdfAnnotationBase.prototype, "labelBounds", void 0);
__decorate([
Property(null)
], PdfAnnotationBase.prototype, "customData", void 0);
__decorate([
Property(['None'])
], PdfAnnotationBase.prototype, "allowedInteractions", void 0);
__decorate([
Property(true)
], PdfAnnotationBase.prototype, "isPrint", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "isReadonly", void 0);
__decorate([
Property(0)
], PdfAnnotationBase.prototype, "pageRotation", void 0);
__decorate([
Property('')
], PdfAnnotationBase.prototype, "icon", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "isAddAnnotationProgrammatically", void 0);
__decorate([
Property(false)
], PdfAnnotationBase.prototype, "isTransparentSet", void 0);
return PdfAnnotationBase;
}(ChildProperty));
/**
* Defines the common behavior of PdfFormFieldBase
*
* @hidden
*/
var PdfFormFieldBase = /** @__PURE__ @class */ (function (_super) {
__extends(PdfFormFieldBase, _super);
function PdfFormFieldBase(parent, propName, defaultValue, isArray) {
return _super.call(this, parent, propName, defaultValue, isArray) || this;
}
__decorate([
Property('')
], PdfFormFieldBase.prototype, "id", void 0);
__decorate([
Property('')
], PdfFormFieldBase.prototype, "signatureType", void 0);
__decorate([
Property('')
], PdfFormFieldBase.prototype, "name", void 0);
__decorate([
Property('')
], PdfFormFieldBase.prototype, "value", void 0);
__decorate([
Property(null)
], PdfFormFieldBase.prototype, "formFieldAnnotationType", void 0);
__decorate([
Property('#daeaf7ff')
], PdfFormFieldBase.prototype, "backgroundColor", void 0);
__decorate([
Property('black')
], PdfFormFieldBase.prototype, "color", void 0);
__decorate([
Property('#303030')
], PdfFormFieldBase.prototype, "borderColor", void 0);
__decorate([
Property('')
], PdfFormFieldBase.prototype, "tooltip", void 0);
__decorate([
Property(1)
], PdfFormFieldBase.prototype, "opacity", void 0);
__decorate([
Property(1)
], PdfFormFieldBase.prototype, "thickness", void 0);
__decorate([
Property(0)
], PdfFormFieldBase.prototype, "rotateAngle", void 0);
__decorate([
Complex({ x: 0, y: 0 }, PdfBounds)
], PdfFormFieldBase.prototype, "bounds", void 0);
__decorate([
Property(0)
], PdfFormFieldBase.prototype, "pageIndex", void 0);
__decorate([
Property(1)
], PdfFormFieldBase.prototype, "pageNumber", void 0);
__decorate([
Property(-1)
], PdfFormFieldBase.prototype, "zIndex", void 0);
__decorate([
Property(null)
], PdfFormFieldBase.prototype, "wrapper", void 0);
__decorate([
Property(16)
], PdfFormFieldBase.prototype, "fontSize", void 0);
__decorate([
Property('Helvetica')
], PdfFormFieldBase.prototype, "fontFamily", void 0);
__decorate([
Property('None')
], PdfFormFieldBase.prototype, "fontStyle", void 0);
__decorate([
Property('left')
], PdfFormFieldBase.prototype, "alignment", void 0);
__decorate([
Property(0)
], PdfFormFieldBase.prototype, "minHeight", void 0);
__decorate([
Property(0)
], PdfFormFieldBase.prototype, "minWidth", void 0);
__decorate([
Property(0)
], PdfFormFieldBase.prototype, "maxHeight", void 0);
__decorate([
Property(0)
], PdfFormFieldBase.prototype, "maxWidth", void 0);
__decorate([
Property(0)
], PdfFormFieldBase.prototype, "maxLength", void 0);
__decorate([
Property('visible')
], PdfFormFieldBase.prototype, "visibility", void 0);
__decorate([
Property(true)
], PdfFormFieldBase.prototype, "isPrint", void 0);
__decorate([
Property(false)
], PdfFormFieldBase.prototype, "isReadonly", void 0);
__decorate([
Property(false)
], PdfFormFieldBase.prototype, "isChecked", void 0);
__decorate([
Property(false)
], PdfFormFieldBase.prototype, "isSelected", void 0);
__decorate([
Property(false)
], PdfFormFieldBase.prototype, "isRequired", void 0);
__decorate([
Property(false)
], PdfFormFieldBase.prototype, "isMultiline", void 0);
__decorate([
Property(false)
], PdfFormFieldBase.prototype, "isTransparent", void 0);
__decorate([
Property(false)
], PdfFormFieldBase.prototype, "insertSpaces", void 0);
__decorate([
Property('')
], PdfFormFieldBase.prototype, "options", void 0);
__decorate([
Property()
], PdfFormFieldBase.prototype, "signatureIndicatorSettings", void 0);
__decorate([
Complex({ isBold: false, isItalic: false, isStrikeout: false, isUnderline: false }, PdfFont)
], PdfFormFieldBase.prototype, "font", void 0);
__decorate([
Property()
], PdfFormFieldBase.prototype, "selectedIndex", void 0);
__decorate([
Property(null)
], PdfFormFieldBase.prototype, "customData", void 0);
return PdfFormFieldBase;
}(ChildProperty));
/**
* @hidden
*/
var ZOrderPageTable = /** @__PURE__ @class */ (function () {
function ZOrderPageTable() {
this.pageIdTemp = 0;
this.zIndexTemp = -1;
this.childNodesTemp = [];
this.objects = [];
this.zIndexTemp = -1;
this.pageIdTemp = 0;
}
Object.defineProperty(ZOrderPageTable.prototype, "pageId", {
/**
* @private
* @returns {number} - Returns the page Id.
*/
get: function () {
return this.pageIdTemp;
},
/**
* @private
* @param {number} offset - The page offset value.
*/
set: function (offset) {
this.pageIdTemp = offset;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ZOrderPageTable.prototype, "zIndex", {
/**
* @private
* @returns {number} - Returns the z-index value.
*/
get: function () {
return this.zIndexTemp;
},
/**
* @private
* @param {number} offset - The page offset value.
*/
set: function (offset) {
this.zIndexTemp = offset;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ZOrderPageTable.prototype, "objects", {
/**
* @private
* @returns {PdfAnnotationBaseModel[]} - Returns the annotation childNodes.
*/
get: function () {
return this.childNodesTemp;
},
/**
* @private
* @param {PdfAnnotationBaseModel[]} childNodes - Specified the annotation child nodes.
*/
set: function (childNodes) {
this.childNodesTemp = childNodes;
},
enumerable: true,
configurable: true
});
return ZOrderPageTable;
}());
var __extends$1 = (undefined && undefined.__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 __());
};
})();
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
* Defines the size and position of selected items and defines the appearance of selector
*
* @hidden
*/
var Selector = /** @__PURE__ @class */ (function (_super) {
__extends$1(Selector, _super);
function Selector() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Initializes the UI of the container
*
* @param {any} diagram - diagram element.
* @returns {Container} - Returns the container element.
*/
Selector.prototype.init = function (diagram) {
var container = new Container();
container.measureChildren = false;
container.children = [];
if (this.formFields && this.formFields.length > 0) {
for (var i = 0; i < this.formFields.length; i++) {
var node = diagram.pdfViewer.nameTable[this.formFields[parseInt(i.toString(), 10)].id];
var wrapper = node.wrapper;
container.children.push(wrapper);
}
}
else if (this.annotations) {
for (var i = 0; i < this.annotations.length; i++) {
if (!isNullOrUndefined(this.annotations[parseInt(i.toString(), 10)])) {
var node = diagram.pdfViewer.nameTable[this.annotations[parseInt(i.toString(), 10)].id];
var wrapper = node.wrapper;
container.children.push(wrapper);
}
}
}
this.wrapper = container;
return container;
};
__decorate$1([
Property(null)
], Selector.prototype, "wrapper", void 0);
__decorate$1([
Collection([], PdfAnnotationBase)
], Selector.prototype, "annotations", void 0);
__decorate$1([
Collection([], PdfFormFieldBase)
], Selector.prototype, "formFields", void 0);
__decorate$1([
Property()
], Selector.prototype, "width", void 0);
__decorate$1([
Property()
], Selector.prototype, "height", void 0);
__decorate$1([
Property(0)
], Selector.prototype, "rotateAngle", void 0);
__decorate$1([
Property(0)
], Selector.prototype, "offsetX", void 0);
__decorate$1([
Property(0)
], Selector.prototype, "offsetY", void 0);
__decorate$1([
Complex({ x: 0.5, y: 0.5 }, Point)
], Selector.prototype, "pivot", void 0);
return Selector;
}(ChildProperty));
/**
* @param {PdfAnnotationBaseModel} obj - Specified the shape annotation object.
* @hidden
* @returns {void}
*/
function isLineShapes(obj) {
if (obj.shapeAnnotationType === 'Line' || obj.shapeAnnotationType === 'LineWidthArrowHead'
|| obj.shapeAnnotationType === 'Distance' || obj.shapeAnnotationType === 'Polygon') {
return true;
}
return false;
}
/**
* @param {PdfAnnotationBaseModel | PdfFormFieldBaseModel} obj - Specified the annotation or form fields object.
* @param {DrawingElement} element - Specified the annotation drawing element.
* @returns {void}
* @hidden
*/
function setElementStype(obj, element) {
if (obj && element) {
if (obj.formFieldAnnotationType) {
if (obj.id.indexOf('diagram_helper') !== -1) {
element.style.fill = 'transparent';
element.style.strokeWidth = 1;
element.style.strokeDashArray = obj.borderDashArray;
}
else {
element.style.fill = 'transparent';
element.style.strokeWidth = 0;
}
}
else {
var fillColor = (obj.fillColor === '#ffffff00' ? 'transparent' : obj.fillColor);
element.style.fill = fillColor ? fillColor : 'white';
element.style.strokeColor = obj.strokeColor ?
obj.strokeColor : obj.borderColor;
element.style.color = obj.strokeColor ?
obj.strokeColor : obj.borderColor;
element.style.strokeWidth = obj.thickness;
if (obj.shapeAnnotationType === 'Image' || obj.shapeAnnotationType === 'SignatureText' || obj.shapeAnnotationType === 'SignatureImage') {
element.style.strokeWidth = 0;
}
element.style.strokeDashArray = obj.borderDashArray;
element.style.opacity = obj.opacity;
}
}
}
/**
* @param {PointModel[]} points - Specified the annotation points value.
* @hidden
* @returns {number} - Returns the points length.
*/
function findPointsLength(points) {
var length = 0;
for (var i = 0; i < points.length - 1; i++) {
length += Point.findLength(points[parseInt(i.toString(), 10)], points[i + 1]);
}
return length;
}
/**
* @param {PointModel[]} points - Specified the annotation points value.
* @hidden
* @returns {number} - Returns the points length.
*/
function findPerimeterLength(points) {
var length = Point.getLengthFromListOfPoints(points);
return length;
}
/**
* @private
* @param {DrawingElement} element - Specified the drawing element.
* @param {Transforms} transform - Specified the transform value.
* @returns {BaseAttributes} - Returns the base attributes value.
*/
function getBaseShapeAttributes(element, transform) {
var baseShapeAttributes = {
width: element.actualSize.width, height: element.actualSize.height,
x: element.offsetX - element.actualSize.width * element.pivot.x + 0.5,
y: element.offsetY - element.actualSize.height * element.pivot.y + 0.5,
angle: element.rotateAngle + element.parentTransform, fill: element.style.fill, stroke: element.style.strokeColor,
pivotX: element.pivot.x, pivotY: element.pivot.y, strokeWidth: 1,
opacity: element.style.opacity, dashArray: element.style.strokeDashArray || '',
visible: element.visible, id: element.id
};
if (transform) {
baseShapeAttributes.x += transform.tx;
baseShapeAttributes.y += transform.ty;
}
return baseShapeAttributes;
}
/**
* Get function
*
* @private
* @param {Function | string} value - Type of the function.
* @returns {Function} - Returns the function.
*/
function getFunction(value) {
if (value !== undefined) {
if (typeof value === 'string') {
value = getValue(value, window);
}
}
return value;
}
/**
* @private
* @param {any} obj - Specified the annotation object.
* @param {Function | string} additionalProp - Specified the annotation additional properties.
* @param {string} key - Specified the annotation key value.
* @returns {object} - Returns the cloned object.
*/
function cloneObject(obj, additionalProp, key) {
var newObject = {};
var keys = 'properties';
var prop = 'propName';
if (obj) {
key = obj["" + prop];
var sourceObject = obj["" + keys] || obj;
var properties = [];
properties = properties.concat(Object.keys(sourceObject));
var customProperties = [];
properties.push('version');
if (key) {
var propAdditional = getFunction(additionalProp);
if (propAdditional) {
customProperties = propAdditional(key);
}
else {
customProperties = [];
}
properties = properties.concat(customProperties);
}
var internalProp = getInternalProperties(key);
properties = properties.concat(internalProp);
for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
var property = properties_1[_i];
if (property !== 'historyManager') {
if (property !== 'wrapper') {
var isEventEmmitter = obj["" + property] && Object.prototype.hasOwnProperty.call(obj, 'observers') ? true : false;
if (!isEventEmmitter) {
if (obj["" + property] instanceof Array) {
newObject["" + property] = cloneArray((internalProp.indexOf(property) === -1 && obj["" + key]) ? obj["" + key]["" + property] : obj["" + property], additionalProp, property);
}
else if (obj["" + property] instanceof Array === false && obj["" + property] instanceof HTMLElement) {
newObject["" + property] = obj["" + property].cloneNode(true).innerHtml;
}
else if (obj["" + property] instanceof Array === false && obj["" + property] instanceof Object && property !== 'template') {
newObject["" + property] = cloneObject((internalProp.indexOf(property) === -1 && obj["" + key]) ? obj["" + key]["" + property] : obj["" + property]);
}
else {
newObject["" + property] = obj["" + property];
}
}
}
else {
if (obj["" + property]) {
newObject["" + property] = {
actualSize: {
width: obj["" + property].actualSize.width, height: obj["" + property].actualSize.height
}, offsetX: obj["" + property].offsetX, offsetY: obj["" + property].offsetY
};
}
}
}
}
}
return newObject;
}
/**
* @private
* @param {object[]} sourceArray - Specified the annotation source collections.
* @param {Function | string} additionalProp - Specified the annotation additional properties.
* @param {string} key - Specified the annotation key value.
* @returns {object[]} - Returns the cloned object array.
*/
function cloneArray(sourceArray, additionalProp, key) {
var clonedArray;
if (sourceArray) {
clonedArray = [];
for (var i = 0; i < sourceArray.length; i++) {
if (sourceArray[parseInt(i.toString(), 10)] instanceof Array) {
clonedArray.push(sourceArray[parseInt(i.toString(), 10)]);
}
else if (sourceArray[parseInt(i.toString(), 10)] instanceof Object) {
clonedArray.push(cloneObject(sourceArray[parseInt(i.toString(), 10)], additionalProp, key));
}
else {
clonedArray.push(sourceArray[parseInt(i.toString(), 10)]);
}
}
}
return clonedArray;
}
/**
* @private
* @param {string} propName - Specified the annotation property name.
* @returns {string[]} - Returns the internal properties.
*/
function getInternalProperties(propName) {
switch (propName) {
case 'nodes':
case 'children':
return ['inEdges', 'outEdges', 'parentId', 'processId', 'nodeId', 'umlIndex', 'isPhase', 'isLane'];
case 'connectors':
return ['parentId'];
case 'annotation':
return ['nodeId'];
case 'annotations':
return ['nodeId'];
case 'shape':
return ['hasHeader'];
}
return [];
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {string} position - Specified the annotation position.
* @hidden
* @returns {Leader} - Returns the leader value.
*/
function isLeader(obj, position) {
var rotatedPoint;
if (obj.shapeAnnotationType === 'Distance') {
var leaderCount = 0;
var newPoint1 = void 0;
for (var i = 0; i < obj.wrapper.children.length; i++) {
var angle = Point.findAngle(obj.sourcePoint, obj.targetPoint);
var segment = obj.wrapper.children[parseInt(i.toString(), 10)];
if (segment.id.indexOf('leader') > -1) {
var center = obj.wrapper.children[0].bounds.center;
if (leaderCount === 0) {
newPoint1 = { x: obj.sourcePoint.x, y: obj.sourcePoint.y - obj.leaderHeight };
center = obj.sourcePoint;
}
else {
newPoint1 = { x: obj.targetPoint.x, y: obj.targetPoint.y - obj.leaderHeight };
center = obj.targetPoint;
}
var matrix = identityMatrix();
rotateMatrix(matrix, angle, center.x, center.y);
rotatedPoint = transformPointByMatrix(matrix, { x: newPoint1.x, y: newPoint1.y });
if (position === 'Leader' + leaderCount) {
return { leader: 'leader' + leaderCount, point: rotatedPoint };
}
leaderCount++;
}
}
}
return { leader: '', point: rotatedPoint };
}
/**
* @private
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel[]} points - Specified the annotation points.
* @returns {PointModel[]} - Returns the annotation points model array.
*/
function getConnectorPoints(obj, points) {
points = obj.vertexPoints;
var newPoints = points.slice(0);
if (newPoints && newPoints.length > 0) {
obj.sourcePoint = newPoints[0];
obj.targetPoint = newPoints[newPoints.length - 1];
}
return newPoints;
}
/**
* @private
* @param {PdfAnnotationBaseModel} connector - Specified the annotation connector model.
* @param {PointModel[]} points - Specified the annotation points.
* @returns {string} - Returns the annotation path value.
*/
function getSegmentPath(connector, points) {
var path = '';
var getPt;
var pts = [];
var j = 0;
while (j < points.length) {
pts.push({ x: points[parseInt(j.toString(), 10)].x, y: points[parseInt(j.toString(), 10)].y });
j++;
}
pts = clipDecorators(connector, pts);
for (var k = 0; k < pts.length; k++) {
getPt = pts[parseInt(k.toString(), 10)];
if (k === 0) {
path = 'M' + getPt.x + ' ' + getPt.y;
}
if (k > 0) {
path += ' ' + 'L' + getPt.x + ' ' + getPt.y;
}
}
return path;
}
/**
* @private
* @param {PdfAnnotationBaseModel} connector - Specified the annotation connector model.
* @param {PointModel[]} points - Specified the annotation points.
* @param {PathElement} element - Specified the annotation element.
* @returns {PathElement} - Returns the annotation path element.
*/
function updateSegmentElement(connector, points, element) {
var bounds = new Rect();
var segmentPath = getSegmentPath(connector, points);
bounds = Rect.toBounds(points);
element.width = bounds.width;
element.height = bounds.height;
element.offsetX = bounds.x + element.width / 2;
element.offsetY = bounds.y + element.height / 2;
element.data = segmentPath;
if (connector.wrapper) {
connector.wrapper.offsetX = element.offsetX;
connector.wrapper.offsetY = element.offsetY;
var boundsValue = bounds.width;
if (bounds.width < bounds.height) {
boundsValue = bounds.height;
}
else {
boundsValue = bounds.width;
}
connector.wrapper.width = connector.enableShapeLabel ? boundsValue / 2 : boundsValue;
connector.wrapper.height = bounds.height;
}
return element;
}
/**
* @private
* @param {PdfAnnotationBaseModel} connector - Specified the annotation connector model.
* @param {PathElement} segmentElement - Specified the annotation segment element.
* @returns {PathElement} - Returns the annotation path element.
*/
function getSegmentElement(connector, segmentElement) {
var points = [];
points = getConnectorPoints(connector);
segmentElement.staticSize = true;
segmentElement = updateSegmentElement(connector, points, segmentElement);
setElementStype(connector, segmentElement);
return segmentElement;
}
/**
* @private
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {DrawingElement} element - Specified the annotation drawing element.
* @param {PointModel} pt - Specified the annotation point.
* @param {PointModel} adjacentPoint - Specified the annotation adjacent point.
* @param {boolean} isSource - Specified the is source value or not.
* @returns {void}
*/
function updateDecoratorElement(obj, element, pt, adjacentPoint, isSource) {
element.offsetX = pt.x;
element.offsetY = pt.y;
var angle = Point.findAngle(pt, adjacentPoint);
var getPath = getDecoratorShape(isSource ? obj.sourceDecoraterShapes : obj.taregetDecoraterShapes);
var thickness = 0;
var size;
if (obj.shapeAnnotationType === 'LineWidthArrowHead' || obj.shapeAnnotationType === 'Line') {
thickness = obj.thickness;
size = new Size(thickness * 12, thickness * 12);
}
else {
thickness = obj.thickness <= 5 ? 5 : obj.thickness;
size = new Size(thickness * 2, thickness * 2);
}
element.transform = RotateTransform.Self;
setElementStype(obj, element);
element.style.fill = (obj.fillColor !== 'tranparent') ? obj.fillColor : 'white';
element.rotateAngle = angle;
element.data = getPath;
element.canMeasurePath = true;
element.width = size.width;
element.height = size.height;
if (obj.sourceDecoraterShapes === 'Butt') {
element.width = size.width - 10;
element.height = size.height + 10;
}
}
/**
* @private
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel} offsetPoint - Specified the annotation offset point.
* @param {PointModel} adjacentPoint - Specified the annotation adjacent point.
* @param {boolean} isSource - Specified the is source value or not.
* @returns {PathElement} - Returns the annotation path element.
*/
function getDecoratorElement(obj, offsetPoint, adjacentPoint, isSource) {
var decEle = new PathElement();
updateDecoratorElement(obj, decEle, offsetPoint, adjacentPoint, isSource);
return decEle;
}
/**
* @private
* @param {PdfAnnotationBaseModel} connector - Specified the annotation object.
* @param {PointModel[]} pts - Specified the annotation point model array.
* @returns {PointModel[]} - Returns the annotation point model array.
*/
function clipDecorators(connector, pts) {
pts[0] = clipDecorator(connector, pts, true);
pts[pts.length - 1] = clipDecorator(connector, pts, false);
return pts;
}
/**
* @private
* @param {PdfAnnotationBaseModel} connector - Specified the annotation connector object.
* @param {PointModel[]} points - Specified the annotation offset point.
* @param {boolean} isSource - Specified the is source value or not.
* @returns {PointModel} - Returns the annotation point model.
*/
function clipDecorator(connector, points, isSource) {
var point = { x: 0, y: 0 };
var start = { x: 0, y: 0 };
var end = { x: 0, y: 0 };
var length = points.length;
start = !isSource ? points[length - 1] : points[0];
end = !isSource ? points[length - 2] : points[1];
var len = Point.distancePoints(start, end);
len = (len === 0) ? 1 : len;
var width = connector.thickness;
point.x = (Math.round(start.x + width * (end.x - start.x) / len));
point.y = (Math.round(start.y + width * (end.y - start.y) / len));
var strokeWidth = 1;
point = Point.adjustPoint(point, end, true, (strokeWidth / 2));
return point;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel[]} points - Specified the annotation point model array.
* @param {MeasureAnnotation} measure - Specified the measure annotation object.
* @param {PdfViewer} pdfviewer - Specified the pdfviewer element.
* @hidden
* @returns {TextElement[]} - Returns the text element collections.
*/
function initDistanceLabel(obj, points, measure, pdfviewer) {
var labels = [];
var angle = Point.findAngle(points[0], points[1]);
var textele = textElement(obj, angle);
if (!pdfviewer.enableImportAnnotationMeasurement && obj.notes && obj.notes !== '') {
textele.content = obj.notes;
}
else {
textele.content = measure.setConversion(findPointsLength([points[0], points[1]]) * measure.pixelToPointFactor, obj);
}
textele.rotateValue = { y: -10, angle: angle };
if (obj.enableShapeLabel === true) {
textele.style.strokeColor = obj.labelBorderColor;
textele.style.fill = obj.labelFillColor;
textele.style.fontSize = obj.fontSize;
textele.style.color = obj.fontColor;
textele.style.fontFamily = obj.fontFamily;
}
labels.push(textele);
return labels;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel[]} points - Specified the annotation point model array.
* @param {MeasureAnnotation} measure - Specified the measure annotation object.
* @hidden
* @returns {string} - Returns the distance value.
*/
function updateDistanceLabel(obj, points, measure) {
var distance;
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_1 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_1 && !isNullOrUndefined(textElement_1.content)) {
distance = measure.setConversion(findPointsLength([points[0], points[1]]) * measure.pixelToPointFactor, obj);
textElement_1.content = distance;
textElement_1.childNodes[0].text = textElement_1.content;
textElement_1.refreshTextElement();
}
}
return distance;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {MeasureAnnotation} measure - Specified the measure annotation object.
* @hidden
* @returns {string} - Returns the radius label value.
*/
function updateRadiusLabel(obj, measure) {
var radius;
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_2 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_2 && !isNullOrUndefined(textElement_2.content)) {
radius = measure.setConversion((obj.bounds.width / 2) * measure.pixelToPointFactor, obj);
textElement_2.content = radius;
if (textElement_2.childNodes.length === 2) {
textElement_2.childNodes[0].text = radius;
textElement_2.childNodes.splice(textElement_2.childNodes.length - 1, 1);
}
else {
textElement_2.childNodes[0].text = radius;
}
textElement_2.refreshTextElement();
}
}
return radius;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel[]} points - Specified the annotation point model array.
* @param {MeasureAnnotation} measure - Specified the measure annotation object.
* @param {PdfViewer} pdfviewer - Specified the pdfviewer element.
* @hidden
* @returns {TextElement[]} - Returns the text element collections.
*/
function initPerimeterLabel(obj, points, measure, pdfviewer) {
var labels = [];
var angle = Point.findAngle(points[0], points[1]);
var textele = textElement(obj, angle);
if (!pdfviewer.enableImportAnnotationMeasurement && obj.notes && obj.notes !== '') {
textele.content = obj.notes;
}
else {
textele.content = measure.calculatePerimeter(obj);
}
if (obj.enableShapeLabel === true) {
textele.style.strokeColor = obj.labelBorderColor;
textele.style.fill = obj.labelFillColor;
textele.style.fontSize = obj.fontSize;
textele.style.color = obj.fontColor;
textele.style.fontFamily = obj.fontFamily;
}
textele.rotateValue = { y: -10, angle: angle };
labels.push(textele);
return labels;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel[]} points - Specified the annotation point model array.
* @param {MeasureAnnotation} measure - Specified the measure annotation object.
* @hidden
* @returns {string} - Returns the perimeter label value.
*/
function updatePerimeterLabel(obj, points, measure) {
var perimeter;
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_3 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_3 && !isNullOrUndefined(textElement_3.content)) {
perimeter = measure.calculatePerimeter(obj);
textElement_3.content = perimeter;
textElement_3.childNodes[0].text = textElement_3.content;
textElement_3.refreshTextElement();
}
}
return perimeter;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @hidden
* @returns {void}
*/
function removePerimeterLabel(obj) {
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_4 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_4 && !isNullOrUndefined(textElement_4.content)) {
obj.wrapper.children.splice(i, 1);
}
}
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @hidden
* @returns {void}
*/
function updateCalibrateLabel(obj) {
if (obj.wrapper && obj.wrapper.children) {
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_5 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_5 && !isNullOrUndefined(textElement_5.content)) {
textElement_5.content = obj.notes;
textElement_5.childNodes[0].text = textElement_5.content;
textElement_5.refreshTextElement();
}
}
}
}
/**
* Used to find the path for polygon shapes
*
* @param {PointModel[]} collection - Specified the polygon annotaion points collection.
* @hidden
* @returns {string} - Returns the polygon annotation path.
*/
function getPolygonPath(collection) {
var path = '';
var seg;
path = 'M' + collection[0].x + ' ' + collection[0].y;
var i;
for (i = 1; i < collection.length; i++) {
seg = collection[parseInt(i.toString(), 10)];
path += 'L' + seg.x + ' ' + seg.y;
}
path += 'Z';
return path;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {number} angle - Specified the annotaion rotation angle.
* @hidden
* @returns {TextElement} - Returns the annotation text element.
*/
function textElement(obj, angle) {
var textele = new TextElement();
setElementStype(obj, textele);
textele.style.fill = 'transparent';
textele.id = randomId();
textele.horizontalAlignment = 'Center';
textele.rotateValue = { y: 10, angle: angle };
textele.verticalAlignment = 'Top';
textele.relativeMode = 'Object';
textele.setOffsetWithRespectToBounds(.5, .5, 'Absolute');
textele.style.textWrapping = 'NoWrap';
return textele;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel[]} points - Specified the annotaion leader points.
* @hidden
* @returns {PathElement[]} - Returns the annotation path elements.
*/
function initLeaders(obj, points) {
var leaders = [];
var leader = initLeader(obj, points[0], points[1]);
leaders.push(leader);
leader = initLeader(obj, points[1], points[0], true);
leaders.push(leader);
return leaders;
}
/**
* @param {PdfAnnotationBaseModel} obj - Specified the annotation object.
* @param {PointModel} point1 - Specified the annotaion leader point1.
* @param {PointModel} point2 - Specified the annotaion leader point2.
* @param {boolean} isSecondLeader - Specified the is second leader or not.
* @hidden
* @returns {PathElement} - Returns the annotation path element.
*/
function initLeader(obj, point1, point2, isSecondLeader) {
var element = new PathElement();
element.offsetX = point1.x;
element.offsetY = point1.y;
var angle = Point.findAngle(point1, point2);
var center = { x: (point1.x + point2.x) / 2, y: (point1.y + point2.y) / 2 };
var matrix = identityMatrix();
rotateMatrix(matrix, 0 - angle, center.x, center.y);
var rotatedPoint = transformPointByMatrix(matrix, point1);
var newPoint1 = { x: rotatedPoint.x, y: rotatedPoint.y - obj.leaderHeight };
matrix = identityMatrix();
rotateMatrix(matrix, angle, element.offsetX, element.offsetY);
rotatedPoint = transformPointByMatrix(matrix, newPoint1);
var finalPoint = { x: point1.x, y: point1.y };
element.offsetX = finalPoint.x;
element.offsetY = finalPoint.y;
element.transform = RotateTransform.Self;
var getPath = 'M' + point1.x + ',' + point1.y + ',L' + rotatedPoint.x + ',' + rotatedPoint.y + 'Z';
var size = new Size(0, obj.leaderHeight);
element.pivot.x = .5;
if (isSecondLeader) {
element.id = 'leader2_' + randomId();
element.pivot.y = 0;
}
else {
element.id = 'leader1_' + randomId();
element.pivot.y = 1;
}
setElementStype(obj, element);