@syncfusion/ej2-pdfviewer
Version:
Essential JS 2 PDF viewer Component
1,352 lines (1,346 loc) • 7.78 MB
JavaScript
import { Property, Collection, ComplexFactory, ChildProperty, createElement, Browser, Complex, isNullOrUndefined, getValue, compile, isBlazor, SanitizeHtmlHelper, initializeTelemetryFeature, Internationalization, initializeCSPTemplate, classList, enableRipple, closest, Component, initializeTelemetry, L10n, Event, NotifyPropertyChanges, Draggable, Droppable, getComponent } from '@syncfusion/ej2-base';
import { NumericTextBox, Slider, ColorPicker, TextBox } from '@syncfusion/ej2-inputs';
import { Dialog, Tooltip } from '@syncfusion/ej2-popups';
import { DropDownButton, SplitButton } 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 { MultiSelect, CheckBoxSelection, DropDownList, ComboBox, AutoComplete } from '@syncfusion/ej2-dropdowns';
import { _decode, PdfTrueTypeFont, PdfFontStyle, PdfDocument, PdfSignatureField, PdfFreeTextAnnotation, PdfFontFamily, PdfStandardFont, PdfTextAlignment, PdfAnnotationFlag, PdfRotationAngle, PdfRubberStampAnnotation, PdfBitmap, PdfTextBoxField, PdfComboBoxField, PdfCheckBoxField, PdfListBoxField, PdfRadioButtonListField, PdfListFieldItem, PdfRadioButtonListItem, PdfPath, PdfInkAnnotation, PdfFormFieldVisibility, PdfButtonField, PdfPageImportOptions, PdfTextMarkupAnnotation, PdfLineAnnotation, PdfSquareAnnotation, PdfRectangleAnnotation, PdfCircleAnnotation, PdfEllipseAnnotation, PdfPolygonAnnotation, PdfPolyLineAnnotation, PdfAngleMeasurementAnnotation, PdfRedactionAnnotation, PdfPopupAnnotation, _stringToBytes, _ContentParser, PdfPageSettings, PdfMargins, _encode, PdfAnnotationStateModel, PdfAnnotationState, PdfPermissionFlag, DataFormat, PdfAnnotationExportSettings, PdfTextStyle, PdfUriAnnotation, PdfTextWebLinkAnnotation, PdfDocumentLinkAnnotation, PdfFormFieldExportSettings, PdfAnnotationBorder, PdfBorderEffect, PdfBorderEffectStyle, _PdfDictionary, _PdfName, PdfLineEndingStyle, PdfAnnotationIntent, PdfTextMarkupAnnotationType, PdfTemplate, PdfBrush, PdfPen, PdfLineIntent, PdfCircleMeasurementType, PdfPopupIcon, PdfStringFormat, PdfVerticalAlignment, PdfMeasurementUnit, PdfRubberStampAnnotationIcon, PdfLineCaptionType, PdfBorderStyle, _annotationFlagsToString } from '@syncfusion/ej2-pdf';
import { CheckBox, Button, RadioButton } from '@syncfusion/ej2-buttons';
import { Query } from '@syncfusion/ej2-data';
import { ListView } from '@syncfusion/ej2-lists';
import { PdfRedactor } from '@syncfusion/ej2-pdf-data-extract';
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;
};
/**
* @param {Gradient} obj - obj
* @private
* @returns {Object} - Object
*/
const getGradientType = (obj) => {
switch (obj.type) {
case 'Linear':
return LinearGradient;
case 'Radial':
return RadialGradient;
default:
return LinearGradient;
}
};
/**
* @hidden
* Defines the space to be left between an object and its immediate parent
*/
class Margin extends ChildProperty {
}
__decorate([
Property(0)
], Margin.prototype, "left", void 0);
__decorate([
Property(0)
], Margin.prototype, "right", void 0);
__decorate([
Property(0)
], Margin.prototype, "top", void 0);
__decorate([
Property(0)
], Margin.prototype, "bottom", void 0);
/**
* Defines the different colors and the region of color transitions
* ```html
* <div id='diagram'></div>
* ```
* ```typescript
* let stopscol: StopModel[] = [];
* let stops1: StopModel = { color: 'white', offset: 0, opacity: 0.7 };
* stopscol.push(stops1);
* let stops2: StopModel = { color: 'red', offset: 0, opacity: 0.3 };
* stopscol.push(stops2);
* let gradient: RadialGradientModel = { cx: 50, cy: 50, fx: 50, fy: 50, stops: stopscol, type: 'Radial' };
* let nodes: NodeModel[] = [{ id: 'node1', width: 100, height: 100,
* style: { gradient: gradient }
* }];
* let diagram: Diagram = new Diagram({
* ...
* nodes: nodes,
* ...
* });
* diagram.appendTo('#diagram');
* ```
*/
/**
* @hidden
* Represents a gradient stop that defines a specific color
*/
class Stop extends ChildProperty {
/**
* @private
* @returns {string} - Returns the name of class Stop
*/
getClassName() {
return 'Stop';
}
}
__decorate([
Property('')
], Stop.prototype, "color", void 0);
__decorate([
Property(0)
], Stop.prototype, "offset", void 0);
__decorate([
Property(1)
], Stop.prototype, "opacity", void 0);
/**
* @hidden
* Paints the node with a smooth transition from one color to another color
*/
class Gradient extends ChildProperty {
}
__decorate([
Collection([], Stop)
], Gradient.prototype, "stops", void 0);
__decorate([
Property('None')
], Gradient.prototype, "type", void 0);
__decorate([
Property('')
], Gradient.prototype, "id", void 0);
/**
* Defines the linear gradient of styles
* ```html
* <div id='diagram'></div>
* ```
* ```typescript
* let stopscol: StopModel[] = [];
* let stops1: StopModel = { color: 'white', offset: 0, opacity: 0.7 };
* stopscol.push(stops1);
* let stops2: StopModel = { color: 'red', offset: 0, opacity: 0.3 };
* stopscol.push(stops2);
* let gradient: LinearGradientModel = { x1: 0, x2: 50, y1: 0, y2: 50, stops: stopscol, type: 'Linear' };
* let nodes: NodeModel[] = [{ id: 'node1', width: 100, height: 100,
* style: { gradient: gradient }
* }];
* let diagram: Diagram = new Diagram({
* ...
* nodes: nodes,
* ...
* });
* diagram.appendTo('#diagram');
* ```
*/
/**
* @hidden
* Paints the node with linear color transitions
*/
class LinearGradient extends Gradient {
}
__decorate([
Property(0)
], LinearGradient.prototype, "x1", void 0);
__decorate([
Property(0)
], LinearGradient.prototype, "x2", void 0);
__decorate([
Property(0)
], LinearGradient.prototype, "y1", void 0);
__decorate([
Property(0)
], LinearGradient.prototype, "y2", void 0);
/**
* A focal point defines the beginning of the gradient, and a circle defines the end point of the gradient
* ```html
* <div id='diagram'></div>
* ```
* ```typescript
* let stopscol: StopModel[] = [];
* let stops1: StopModel = { color: 'white', offset: 0, opacity: 0.7 };
* stopscol.push(stops1);
* let stops2: StopModel = { color: 'red', offset: 0, opacity: 0.3 };
* stopscol.push(stops2);
* let gradient: RadialGradientModel = { cx: 50, cy: 50, fx: 50, fy: 50, stops: stopscol, type: 'Radial' };
* let nodes: NodeModel[] = [{ id: 'node1', width: 100, height: 100,
* style: { gradient: gradient }
* }];
* let diagram: Diagram = new Diagram({
* ...
* nodes: nodes,
* ...
* });
* diagram.appendTo('#diagram');
* ```
*/
/**
* @hidden
*/
class RadialGradient extends Gradient {
}
__decorate([
Property(0)
], RadialGradient.prototype, "cx", void 0);
__decorate([
Property(0)
], RadialGradient.prototype, "cy", void 0);
__decorate([
Property(0)
], RadialGradient.prototype, "fx", void 0);
__decorate([
Property(0)
], RadialGradient.prototype, "fy", void 0);
__decorate([
Property(50)
], RadialGradient.prototype, "r", void 0);
/**
* @hidden
* Defines the style of shape/path
*/
class ShapeStyle extends ChildProperty {
}
__decorate([
Property('white')
], ShapeStyle.prototype, "fill", void 0);
__decorate([
Property('black')
], ShapeStyle.prototype, "strokeColor", void 0);
__decorate([
Property('')
], ShapeStyle.prototype, "strokeDashArray", void 0);
__decorate([
Property(1)
], ShapeStyle.prototype, "strokeWidth", void 0);
__decorate([
Property(1)
], ShapeStyle.prototype, "opacity", void 0);
__decorate([
ComplexFactory(getGradientType)
], ShapeStyle.prototype, "gradient", void 0);
/**
* @hidden
* Defines the stroke style of a path
*/
class StrokeStyle extends ShapeStyle {
}
__decorate([
Property('transparent')
], StrokeStyle.prototype, "fill", void 0);
/**
* @hidden
* Defines the appearance of text
* ```html
* <div id='diagram'></div>
* ```
* ```typescript
* let style: TextStyleModel = { strokeColor: 'black', opacity: 0.5, strokeWidth: 1 };
* let node: NodeModel;
* node = {
* ...
* id: 'node', width: 100, height: 100, offsetX: 100, offsetY: 100,
* annotations : [{
* content: 'text', style: style }];
* ...
* };
* let diagram: Diagram = new Diagram({
* ...
* nodes: [node],
* ...
* });
* diagram.appendTo('#diagram');
* ```
*/
class TextStyle extends ShapeStyle {
}
__decorate([
Property('black')
], TextStyle.prototype, "color", void 0);
__decorate([
Property('Arial')
], TextStyle.prototype, "fontFamily", void 0);
__decorate([
Property(12)
], TextStyle.prototype, "fontSize", void 0);
__decorate([
Property(false)
], TextStyle.prototype, "italic", void 0);
__decorate([
Property(false)
], TextStyle.prototype, "bold", void 0);
__decorate([
Property('CollapseSpace')
], TextStyle.prototype, "whiteSpace", void 0);
__decorate([
Property('WrapWithOverflow')
], TextStyle.prototype, "textWrapping", void 0);
__decorate([
Property('Center')
], TextStyle.prototype, "textAlign", void 0);
__decorate([
Property('None')
], TextStyle.prototype, "textDecoration", void 0);
__decorate([
Property('Wrap')
], TextStyle.prototype, "textOverflow", void 0);
__decorate([
Property('transparent')
], TextStyle.prototype, "fill", void 0);
/**
* enum module defines the public enumerations
*/
/**
* @hidden
* Defines the container/canvas transform
* Self - Sets the transform type as Self
* Parent - Sets the transform type as Parent
*/
var RotateTransform;
(function (RotateTransform) {
/** Self - Sets the transform type as Self */
RotateTransform[RotateTransform["Self"] = 1] = "Self";
/** Parent - Sets the transform type as Parent */
RotateTransform[RotateTransform["Parent"] = 2] = "Parent";
})(RotateTransform || (RotateTransform = {}));
/**
* @hidden
* Enables/Disables The element actions
* None - Diables all element actions are none
* ElementIsPort - Enable element action is port
* ElementIsGroup - Enable element action as Group
* @private
*/
var ElementAction;
(function (ElementAction) {
/** Disables all element actions are none */
ElementAction[ElementAction["None"] = 0] = "None";
/** Enable the element action is Port */
ElementAction[ElementAction["ElementIsPort"] = 2] = "ElementIsPort";
/** Enable the element action as Group */
ElementAction[ElementAction["ElementIsGroup"] = 4] = "ElementIsGroup";
})(ElementAction || (ElementAction = {}));
/**
* @hidden
* Defines the constraints to enable/disable certain features of connector.
* * None - Interaction of the connectors cannot be done.
* * Select - Selects the connector.
* * Delete - Delete the connector.
* * Drag - Drag the connector.
* * DragSourceEnd - Drag the source end of the connector.
* * DragTargetEnd - Drag the target end of the connector.
* * DragSegmentThump - Drag the segment thumb of the connector.
* * AllowDrop - Allow to drop a node.
* * Bridging - Creates bridge on intersection of two connectors.
* * BridgeObstacle -
* * InheritBridging - Creates bridge on intersection of two connectors.
* * PointerEvents - Sets the pointer events.
* * Tooltip - Displays a tooltip for the connectors.
* * InheritToolTip - Displays a tooltip for the connectors.
* * Interaction - Features of the connector used for interaction.
* * ReadOnly - Enables ReadOnly
* * Default - Default features of the connector.
* @aspNumberEnum
* @IgnoreSingular
*/
var ConnectorConstraints;
(function (ConnectorConstraints) {
/** Disable all connector Constraints. */
ConnectorConstraints[ConnectorConstraints["None"] = 1] = "None";
/** Enables connector to be selected. */
ConnectorConstraints[ConnectorConstraints["Select"] = 2] = "Select";
/** Enables connector to be Deleted. */
ConnectorConstraints[ConnectorConstraints["Delete"] = 4] = "Delete";
/** Enables connector to be Dragged. */
ConnectorConstraints[ConnectorConstraints["Drag"] = 8] = "Drag";
/** Enables connectors source end to be selected. */
ConnectorConstraints[ConnectorConstraints["DragSourceEnd"] = 16] = "DragSourceEnd";
/** Enables connectors target end to be selected. */
ConnectorConstraints[ConnectorConstraints["DragTargetEnd"] = 32] = "DragTargetEnd";
/** Enables control point and end point of every segment in a connector for editing. */
ConnectorConstraints[ConnectorConstraints["DragSegmentThumb"] = 64] = "DragSegmentThumb";
/** Enables AllowDrop constraints to the connector. */
ConnectorConstraints[ConnectorConstraints["AllowDrop"] = 128] = "AllowDrop";
/** Enables bridging to the connector. */
ConnectorConstraints[ConnectorConstraints["Bridging"] = 256] = "Bridging";
/** Enables or Disables Bridge Obstacles with overlapping of connectors. */
ConnectorConstraints[ConnectorConstraints["BridgeObstacle"] = 512] = "BridgeObstacle";
/** Enables bridging to the connector. */
ConnectorConstraints[ConnectorConstraints["InheritBridging"] = 1024] = "InheritBridging";
/** Used to set the pointer events. */
ConnectorConstraints[ConnectorConstraints["PointerEvents"] = 2048] = "PointerEvents";
/** Enables or disables tool tip for the connectors */
ConnectorConstraints[ConnectorConstraints["Tooltip"] = 4096] = "Tooltip";
/** Enables or disables tool tip for the connectors */
ConnectorConstraints[ConnectorConstraints["InheritTooltip"] = 8192] = "InheritTooltip";
/** Enables Interaction. */
ConnectorConstraints[ConnectorConstraints["Interaction"] = 4218] = "Interaction";
/** Enables ReadOnly */
ConnectorConstraints[ConnectorConstraints["ReadOnly"] = 16384] = "ReadOnly";
/** Enables all constraints. */
ConnectorConstraints[ConnectorConstraints["Default"] = 11838] = "Default";
})(ConnectorConstraints || (ConnectorConstraints = {}));
/**
* @hidden
* Enables/Disables the handles of the selector
* Rotate - Enable Rotate Thumb
* ConnectorSource - Enable Connector source point
* ConnectorTarget - Enable Connector target point
* ResizeNorthEast - Enable ResizeNorthEast Resize
* ResizeEast - Enable ResizeEast Resize
* ResizeSouthEast - Enable ResizeSouthEast Resize
* ResizeSouth - Enable ResizeSouth Resize
* ResizeSouthWest - Enable ResizeSouthWest Resize
* ResizeWest - Enable ResizeWest Resize
* ResizeNorthWest - Enable ResizeNorthWest Resize
* ResizeNorth - Enable ResizeNorth Resize
* Default - Enables all constraints
* @private
*/
var ThumbsConstraints;
(function (ThumbsConstraints) {
/** Enable Rotate Thumb */
ThumbsConstraints[ThumbsConstraints["Rotate"] = 2] = "Rotate";
/** Enable Connector source point */
ThumbsConstraints[ThumbsConstraints["ConnectorSource"] = 4] = "ConnectorSource";
/** Enable Connector target point */
ThumbsConstraints[ThumbsConstraints["ConnectorTarget"] = 8] = "ConnectorTarget";
/** Enable ResizeNorthEast Resize */
ThumbsConstraints[ThumbsConstraints["ResizeNorthEast"] = 16] = "ResizeNorthEast";
/** Enable ResizeEast Resize */
ThumbsConstraints[ThumbsConstraints["ResizeEast"] = 32] = "ResizeEast";
/** Enable ResizeSouthEast Resize */
ThumbsConstraints[ThumbsConstraints["ResizeSouthEast"] = 64] = "ResizeSouthEast";
/** Enable ResizeSouth Resize */
ThumbsConstraints[ThumbsConstraints["ResizeSouth"] = 128] = "ResizeSouth";
/** Enable ResizeSouthWest Resize */
ThumbsConstraints[ThumbsConstraints["ResizeSouthWest"] = 256] = "ResizeSouthWest";
/** Enable ResizeWest Resize */
ThumbsConstraints[ThumbsConstraints["ResizeWest"] = 512] = "ResizeWest";
/** Enable ResizeNorthWest Resize */
ThumbsConstraints[ThumbsConstraints["ResizeNorthWest"] = 1024] = "ResizeNorthWest";
/** Enable ResizeNorth Resize */
ThumbsConstraints[ThumbsConstraints["ResizeNorth"] = 2048] = "ResizeNorth";
/** Enables all constraints */
ThumbsConstraints[ThumbsConstraints["Default"] = 4094] = "Default";
})(ThumbsConstraints || (ThumbsConstraints = {}));
/**
* @hidden
* Defines the visibility of the selector handles
* None - Hides all the selector elements
* ConnectorSourceThumb - Shows/hides the source thumb of the connector
* ConnectorTargetThumb - Shows/hides the target thumb of the connector
* ResizeSouthEast - Shows/hides the bottom right resize handle of the selector
* ResizeSouthWest - Shows/hides the bottom left resize handle of the selector
* ResizeNorthEast - Shows/hides the top right resize handle of the selector
* ResizeNorthWest - Shows/hides the top left resize handle of the selector
* ResizeEast - Shows/hides the middle right resize handle of the selector
* ResizeWest - Shows/hides the middle left resize handle of the selector
* ResizeSouth - Shows/hides the bottom center resize handle of the selector
* ResizeNorth - Shows/hides the top center resize handle of the selector
* Rotate - Shows/hides the rotate handle of the selector
* UserHandles - Shows/hides the user handles of the selector
* Resize - Shows/hides all resize handles of the selector
* @aspNumberEnum
* @IgnoreSingular
*/
var SelectorConstraints;
(function (SelectorConstraints) {
/** Hides all the selector elements */
SelectorConstraints[SelectorConstraints["None"] = 1] = "None";
/** Shows/hides the source thumb of the connector */
SelectorConstraints[SelectorConstraints["ConnectorSourceThumb"] = 2] = "ConnectorSourceThumb";
/** Shows/hides the target thumb of the connector */
SelectorConstraints[SelectorConstraints["ConnectorTargetThumb"] = 4] = "ConnectorTargetThumb";
/** Shows/hides the bottom right resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeSouthEast"] = 8] = "ResizeSouthEast";
/** Shows/hides the bottom left resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeSouthWest"] = 16] = "ResizeSouthWest";
/** Shows/hides the top right resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeNorthEast"] = 32] = "ResizeNorthEast";
/** Shows/hides the top left resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeNorthWest"] = 64] = "ResizeNorthWest";
/** Shows/hides the middle right resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeEast"] = 128] = "ResizeEast";
/** Shows/hides the middle left resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeWest"] = 256] = "ResizeWest";
/** Shows/hides the bottom center resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeSouth"] = 512] = "ResizeSouth";
/** Shows/hides the top center resize handle of the selector */
SelectorConstraints[SelectorConstraints["ResizeNorth"] = 1024] = "ResizeNorth";
/** Shows/hides the rotate handle of the selector */
SelectorConstraints[SelectorConstraints["Rotate"] = 2048] = "Rotate";
/** Shows/hides the user handles of the selector */
SelectorConstraints[SelectorConstraints["UserHandle"] = 4096] = "UserHandle";
/** Shows/hides the default tooltip of nodes and connectors */
SelectorConstraints[SelectorConstraints["ToolTip"] = 8192] = "ToolTip";
/** Shows/hides all resize handles of the selector */
SelectorConstraints[SelectorConstraints["ResizeAll"] = 2046] = "ResizeAll";
/** Shows all handles of the selector */
SelectorConstraints[SelectorConstraints["All"] = 16382] = "All";
})(SelectorConstraints || (SelectorConstraints = {}));
/** @private */
var NoOfSegments;
(function (NoOfSegments) {
NoOfSegments[NoOfSegments["Zero"] = 0] = "Zero";
NoOfSegments[NoOfSegments["One"] = 1] = "One";
NoOfSegments[NoOfSegments["Two"] = 2] = "Two";
NoOfSegments[NoOfSegments["Three"] = 3] = "Three";
NoOfSegments[NoOfSegments["Four"] = 4] = "Four";
NoOfSegments[NoOfSegments["Five"] = 5] = "Five";
})(NoOfSegments || (NoOfSegments = {}));
/**
* @hidden
* Size defines and processes the size(width/height) of the objects
*/
class Size {
constructor(width, height) {
this.width = width;
this.height = height;
}
// /** @private */
// public isEmpty(): boolean {
// return this.height === 0 && this.width === 0;
// }
/**
* @private
* @returns {Size} - Size
*/
clone() {
return new Size(this.width, this.height);
}
}
/**
* @hidden
* Rect defines and processes rectangular regions
*/
class Rect {
constructor(x, y, width, height) {
/**
* Sets the x-coordinate of the starting point of a rectangular region
*
* @default 0
*/
this.x = Number.MAX_VALUE;
/**
* Sets the y-coordinate of the starting point of a rectangular region
*
* @default 0
*/
this.y = Number.MAX_VALUE;
/**
* Sets the width of a rectangular region
*
* @default 0
*/
this.width = 0;
/**
* Sets the height of a rectangular region
*
* @default 0
*/
this.height = 0;
if (x === undefined || y === undefined) {
x = y = Number.MAX_VALUE;
width = height = 0;
}
else {
if (width === undefined) {
width = 0;
}
if (height === undefined) {
height = 0;
}
}
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
/** @private */
get left() {
return this.x;
}
/** @private */
get right() {
return this.x + this.width;
}
/** @private */
get top() {
return this.y;
}
/** @private */
get bottom() {
return this.y + this.height;
}
/** @private */
get topLeft() {
return { x: this.left, y: this.top };
}
/** @private */
get topRight() {
return { x: this.right, y: this.top };
}
/** @private */
get bottomLeft() {
return { x: this.left, y: this.bottom };
}
/** @private */
get bottomRight() {
return { x: this.right, y: this.bottom };
}
/** @private */
get middleLeft() {
return { x: this.left, y: this.y + this.height / 2 };
}
/** @private */
get middleRight() {
return { x: this.right, y: this.y + this.height / 2 };
}
/** @private */
get topCenter() {
return { x: this.x + this.width / 2, y: this.top };
}
/** @private */
get bottomCenter() {
return { x: this.x + this.width / 2, y: this.bottom };
}
/** @private */
get center() {
return { x: this.x + this.width / 2, y: this.y + this.height / 2 };
}
/**
* @param {PointModel} rect1 - rect1
* @param {number} rect2 - rect2
* @private
* @returns {boolean} - boolean
*/
equals(rect1, rect2) {
return rect1.x === rect2.x && rect1.y === rect2.y && rect1.width === rect2.width && rect1.height === rect2.height;
}
/**
* @param {PointModel} rect - rect
* @private
* @returns {Rect} - Rect
*/
uniteRect(rect) {
// eslint-disable-next-line use-isnan
const right = Math.max(Number.NaN === this.right || this.x === Number.MAX_VALUE ? rect.right : this.right, rect.right);
const bottom = this.bottom;
this.x = Math.min(this.left, rect.left);
this.y = Math.min(this.top, rect.top);
this.width = right - this.x;
this.height = bottom - this.y;
return this;
}
/**
* @param {PointModel} point - point
* @private
* @returns {void} - void
*/
unitePoint(point) {
if (this.x === Number.MAX_VALUE) {
this.x = point.x;
this.y = point.y;
return;
}
const x = Math.min(this.left, point.x);
const y = Math.min(this.top, point.y);
const right = Math.max(this.right, point.x);
const bottom = Math.max(this.bottom, point.y);
this.x = x;
this.y = y;
this.width = right - this.x;
this.height = bottom - this.y;
}
/**
* @param {Rect} rect - rect
* @private
* @returns {Rect} - Rect
*/
intersection(rect) {
if (this.intersects(rect)) {
const left = Math.max(this.left, rect.left);
const top = Math.max(this.top, rect.top);
const right = Math.min(this.right, rect.right);
const bottom = Math.min(this.bottom, rect.bottom);
return new Rect(left, top, right - left, bottom - top);
}
return Rect.empty;
}
/**
* @param {number} padding - padding
* @private
* @returns {Rect} - Rect
*/
Inflate(padding) {
this.x -= padding;
this.y -= padding;
this.width += padding * 2;
this.height += padding * 2;
return this;
}
// public Inflate(size: Size): Rect {
// this.x -= size.Width;
// this.y -= size.Height;
// this.width += size.Width * 2;
// this.height += size.Height * 2;
// return this;
// }
// public inflate(width: number, height: number): void {
// this.x -= width;
// this.y -= height;
// this.width += width * 2;
// this.height += height * 2;
// }
/**
* @param {Rect} rect - rect
* @private
* @returns {boolean} - boolean
*/
intersects(rect) {
if (this.right < rect.left || this.left > rect.right || this.top > rect.bottom || this.bottom < rect.top) {
return false;
}
return true;
}
/**
* @param {Rect} rect - rect
* @private
* @returns {boolean} - boolean
*/
containsRect(rect) {
return this.left <= rect.left && this.right >= rect.right && this.top <= rect.top && this.bottom >= rect.bottom;
}
/**
* @param {PointModel} point - point
* @param {PointModel} padding - padding
* @private
* @returns {boolean} - boolean
*/
containsPoint(point, padding = 0) {
return this.left - padding <= point.x && this.right + padding >= point.x
&& this.top - padding <= point.y && this.bottom + padding >= point.y;
}
/**
* @private
* @returns {PointModel[]} - PointModel[]
*/
toPoints() {
const points = [];
points.push(this.topLeft);
points.push(this.topRight);
points.push(this.bottomLeft);
points.push(this.bottomRight);
return points;
}
/**
* @param {PointModel[]} points - points
* @private
* @returns {Rect} - Rect
*/
static toBounds(points) {
const rect = new Rect();
for (const pt of points) {
rect.unitePoint(pt);
}
return rect;
}
/**
* @param {number} scaleX - scaleX
* @param {number} scaleY - scaleY
* @private
* @returns {void} - void
*/
scale(scaleX, scaleY) {
this.width *= scaleX;
this.height *= scaleY;
}
/**
* @param {number} offsetX - offsetX
* @param {number} offsetY - offsetY
* @private
* @returns {void} - void
*/
offset(offsetX, offsetY) {
this.x += offsetX;
this.y += offsetY;
}
}
/** @private */
Rect.empty = new Rect(Number.MAX_VALUE, Number.MIN_VALUE, 0, 0);
/**
* @hidden
* Matrix module is used to transform points based on offsets, angle
*/
var MatrixTypes;
(function (MatrixTypes) {
MatrixTypes[MatrixTypes["Identity"] = 0] = "Identity";
MatrixTypes[MatrixTypes["Translation"] = 1] = "Translation";
MatrixTypes[MatrixTypes["Scaling"] = 2] = "Scaling";
MatrixTypes[MatrixTypes["Unknown"] = 4] = "Unknown";
})(MatrixTypes || (MatrixTypes = {}));
/**
* @hidden
* Matrix class
*/
class Matrix {
constructor(m11, m12, m21, m22, offsetX, offsetY, type) {
this.m11 = m11;
this.m12 = m12;
this.m21 = m21;
this.m22 = m22;
this.offsetX = offsetX;
this.offsetY = offsetY;
// if (type === undefined) {
// this.type = MatrixTypes.Unknown;
// } else {
// this.type = type;
// }
this.type = type;
}
}
/**
* @private
* @returns {Matrix} - Matrix
*/
function identityMatrix() {
return new Matrix(1, 0, 0, 1, 0, 0, MatrixTypes.Identity);
}
/**
* @param {Matrix} matrix - matrix
* @param {PointModel} point - point
* @private
* @returns {PointModel} - PointModel
*/
function transformPointByMatrix(matrix, point) {
const pt = multiplyPoint(matrix, point.x, point.y);
return { x: Math.round(pt.x * 100) / 100, y: Math.round(pt.y * 100) / 100 };
}
/**
* @param {Matrix} matrix - matrix
* @param {number} angle - angle
* @param {number} centerX - centerX
* @param {number} centerY - centerY
* @private
* @returns {void} - void
*/
function rotateMatrix(matrix, angle, centerX, centerY) {
angle %= 360.0;
multiplyMatrix(matrix, createRotationRadians(angle * 0.017453292519943295, centerX ? centerX : 0, centerY ? centerY : 0));
}
/**
* @param {number} matrix - matrix
* @param {number} scaleX - scaleX
* @param {number} scaleY - scaleY
* @param {number} centerX - centerX
* @param {number} centerY - centerY
* @private
* @returns {void} - void
*/
function scaleMatrix(matrix, scaleX, scaleY, centerX = 0, centerY = 0) {
multiplyMatrix(matrix, createScaling(scaleX, scaleY, centerX, centerY));
}
/**
* @param {number} scaleX - scaleX
* @param {number} scaleY - scaleY
* @param {number} centerX - centerX
* @param {number} centerY - centerY
* @private
* @returns {Matrix} - Matrix
*/
function createScaling(scaleX, scaleY, centerX, centerY) {
const result = identityMatrix();
result.type = !(centerX || centerY) ? MatrixTypes.Scaling : MatrixTypes.Scaling | MatrixTypes.Translation;
setMatrix(result, scaleX, 0.0, 0.0, scaleY, centerX - scaleX * centerX, centerY - scaleY * centerY);
return result;
}
/**
* @param {number} angle - angle
* @param {number} centerX - centerX
* @param {number} centerY - centerY
* @private
* @returns {Matrix} - Matrix
*/
function createRotationRadians(angle, centerX, centerY) {
const result = identityMatrix();
const num = Math.sin(angle);
const num2 = Math.cos(angle);
const offsetX = centerX * (1.0 - num2) + centerY * num;
const offsetY = centerY * (1.0 - num2) - centerX * num;
result.type = MatrixTypes.Unknown;
setMatrix(result, num2, num, -num, num2, offsetX, offsetY);
return result;
}
/**
* @param {number} matrix - matrix
* @param {number} x - x
* @param {number} y - y
* @private
* @returns {PointModel} - PointModel
*/
function multiplyPoint(matrix, x, y) {
switch (matrix.type) {
case MatrixTypes.Identity: break;
case MatrixTypes.Translation:
x += matrix.offsetX;
y += matrix.offsetY;
break;
case MatrixTypes.Scaling:
x *= matrix.m11;
y *= matrix.m22;
break;
case MatrixTypes.Translation | MatrixTypes.Scaling:
x *= matrix.m11;
x += matrix.offsetX;
y *= matrix.m22;
y += matrix.offsetY;
break;
default:
{
const num = y * matrix.m21 + matrix.offsetX;
const num2 = x * matrix.m12 + matrix.offsetY;
x *= matrix.m11;
x += num;
y *= matrix.m22;
y += num2;
break;
}
}
return { x: x, y: y };
}
/**
* @param {Matrix} matrix1 - matrix1
* @param {Matrix} matrix2 - matrix2
* @private
* @returns {void} - void
*/
function multiplyMatrix(matrix1, matrix2) {
const type = matrix1.type;
const type2 = matrix2.type;
if (type2 === MatrixTypes.Identity) {
return;
}
if (type === MatrixTypes.Identity) {
assignMatrix(matrix1, matrix2);
matrix1.type = matrix2.type;
return;
}
if (type2 === MatrixTypes.Translation) {
matrix1.offsetX += matrix2.offsetX;
matrix1.offsetY += matrix2.offsetY;
if (type !== MatrixTypes.Unknown) {
matrix1.type |= MatrixTypes.Translation;
}
return;
}
if (type !== MatrixTypes.Translation) {
const num = type << 4 | type2;
switch (num) {
case 34:
matrix1.m11 *= matrix2.m11;
matrix1.m22 *= matrix2.m22;
return;
case 35:
matrix1.m11 *= matrix2.m11;
matrix1.m22 *= matrix2.m22;
matrix1.offsetX = matrix2.offsetX;
matrix1.offsetY = matrix2.offsetY;
matrix1.type = (MatrixTypes.Translation | MatrixTypes.Scaling);
return;
case 36: break;
default:
{
switch (num) {
case 50:
matrix1.m11 *= matrix2.m11;
matrix1.m22 *= matrix2.m22;
matrix1.offsetX *= matrix2.m11;
matrix1.offsetY *= matrix2.m22;
return;
case 51:
matrix1.m11 *= matrix2.m11;
matrix1.m22 *= matrix2.m22;
matrix1.offsetX = matrix2.m11 * matrix1.offsetX + matrix2.offsetX;
matrix1.offsetY = matrix2.m22 * matrix1.offsetY + matrix2.offsetY;
return;
case 52: break;
default:
switch (num) {
case 66:
case 67:
case 68: break;
default: return;
}
break;
}
break;
}
}
const result = identityMatrix();
const m11New = matrix1.m11 * matrix2.m11 + matrix1.m12 * matrix2.m21;
const m12New = matrix1.m11 * matrix2.m12 + matrix1.m12 * matrix2.m22;
const m21New = matrix1.m21 * matrix2.m11 + matrix1.m22 * matrix2.m21;
const m22New = matrix1.m21 * matrix2.m12 + matrix1.m22 * matrix2.m22;
const offsetX = matrix1.offsetX * matrix2.m11 + matrix1.offsetY * matrix2.m21 + matrix2.offsetX;
const offsetY = matrix1.offsetX * matrix2.m12 + matrix1.offsetY * matrix2.m22 + matrix2.offsetY;
setMatrix(result, m11New, m12New, m21New, m22New, offsetX, offsetY);
if (result.m21 || result.m12) {
result.type = MatrixTypes.Unknown;
}
else {
if (result.m11 && result.m11 !== 1.0 || result.m22 && result.m22 !== 1.0) {
result.type = MatrixTypes.Scaling;
}
if (result.offsetX || result.offsetY) {
result.type |= MatrixTypes.Translation;
}
if ((result.type & (MatrixTypes.Translation | MatrixTypes.Scaling)) === MatrixTypes.Identity) {
result.type = MatrixTypes.Identity;
}
result.type = MatrixTypes.Scaling | MatrixTypes.Translation;
}
assignMatrix(matrix1, result);
matrix1.type = result.type;
return;
}
const offsetX = matrix1.offsetX;
const offsetY = matrix1.offsetY;
matrix1.offsetX = offsetX * matrix2.m11 + offsetY * matrix2.m21 + matrix2.offsetX;
matrix1.offsetY = offsetX * matrix2.m12 + offsetY * matrix2.m22 + matrix2.offsetY;
if (type2 === MatrixTypes.Unknown) {
matrix1.type = MatrixTypes.Unknown;
return;
}
matrix1.type = (MatrixTypes.Translation | MatrixTypes.Scaling);
}
/**
* @param {number} mat - mat
* @param {number} m11 - m11
* @param {number} m12 - m12
* @param {number} m21 - m21
* @param {number} m22 - m22
* @param {number} x - x
* @param {number} y - y
* @private
* @returns {void} - void
*/
function setMatrix(mat, m11, m12, m21, m22, x, y) {
mat.m11 = m11;
mat.m12 = m12;
mat.m21 = m21;
mat.m22 = m22;
mat.offsetX = x;
mat.offsetY = y;
}
/**
* @param {Matrix} matrix1 - matrix1
* @param {Matrix} matrix2 - matrix2
* @private
* @returns {void} - void
*/
function assignMatrix(matrix1, matrix2) {
matrix1.m11 = matrix2.m11;
matrix1.m12 = matrix2.m12;
matrix1.m21 = matrix2.m21;
matrix1.m22 = matrix2.m22;
matrix1.offsetX = matrix2.offsetX;
matrix1.offsetY = matrix2.offsetY;
matrix1.type = matrix2.type;
}
/**
* @param {SVGElement} node - node
* @private
* @returns {SVGElement[] | HTMLCollection} - child elements
*/
function getChildNode(node) {
let child;
let collection = [];
if (Browser.info.name === 'msie' || Browser.info.name === 'edge') {
for (let i = 0; i < node.childNodes.length; i++) {
child = node.childNodes[parseInt(i.toString(), 10)];
if (child.nodeType === 1) {
collection.push(child);
}
}
}
else {
collection = node.children;
}
return collection;
}
/**
* @param {string} data - data
* @private
* @returns {Rect} - Rect
*/
function measurePath(data) {
const path = 'pathTable';
if (!window[path]) {
window[path] = {};
}
if (data) {
const measureElement = 'measureElement';
window[measureElement].style.visibility = 'visible';
const svg = window[measureElement].children[2];
const element = getChildNode(svg)[0];
element.setAttribute('d', data);
//let bounds: SVGRect = element.getBBox();
let bounds;
if (window[path][data]) {
bounds = window[path][data];
}
else {
window[path][data] = bounds = element.getBBox();
if ((bounds.x === 0 || bounds.y === 0) && (bounds.width === 0 || bounds.height === 0)) {
window[path][data] = bounds = getBBox(data);
}
}
const svgBounds = new Rect(bounds.x, bounds.y, bounds.width, bounds.height);
window[measureElement].style.visibility = 'hidden';
return svgBounds;
}
return new Rect(0, 0, 0, 0);
}
/**
* @param {string} path - path
* @private
* @returns {any} - Rect
*/
function getBBox(path) {
let xmin = 0;
let xmax = 0;
let ymin = 0;
let ymax = 0;
// tslint:disable-next-line
let currentValue;
// tslint:disable-next-line
let currentpath = path;
currentpath = currentpath.replace(/[a-z].*/g, ' ').replace(/[\sA-Z]+/gi, ' ').trim().split(' ');
for (let i = 0; i < currentpath.length; i++) {
if (currentpath[parseInt(i.toString(), 10)].length > 1) {
currentValue = currentpath[parseInt(i.toString(), 10)].split(',');
xmin = xmax = currentValue[0];
ymin = ymax = currentValue[1];
}
}
for (let i = 0; i < currentpath.length; i++) {
currentValue = currentpath[parseInt(i.toString(), 10)].split(',');
if (!currentValue[1]) {
currentValue[0] = xmin;
currentValue[1] = ymin;
}
xmin = Math.min(xmin, currentValue[0]);
xmax = Math.max(xmax, currentValue[0]);
ymin = Math.min(ymin, currentValue[1]);
ymax = Math.max(ymax, currentValue[1]);
}
return { x: xmin, y: ymin, width: xmax - xmin, height: ymax - ymin };
}
/**
* @param {TextElement} element - element
* @param {number} maxWidth - maxWidth
* @private
* @returns {BaseAttributes} - BaseAttributes
*/
function getTextOptions(element, maxWidth) {
const options = {
fill: element.style.fill, stroke: element.style.strokeColor, angle: element.rotateAngle + element.parentTransform,
pivotX: element.pivot.x, pivotY: element.pivot.y, strokeWidth: element.style.strokeWidth,
dashArray: element.style.strokeDashArray, opacity: element.style.opacity,
visible: element.visible, id: element.id,
width: maxWidth || 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,
relativeMode: element.relativeMode
};
options.fontSize = element.style.fontSize;
options.fontFamily = element.style.fontFamily;
options.textOverflow = element.style.textOverflow;
options.textDecoration = element.style.textDecoration;
options.doWrap = element.doWrap;
options.whiteSpace = whiteSpaceToString(element.style.whiteSpace, element.style.textWrapping);
options.content = element.content;
options.textWrapping = element.style.textWrapping;
options.breakWord = wordBreakToString(element.style.textWrapping);
options.textAlign = textAlignToString(element.style.textAlign);
options.color = element.style.color;
options.italic = element.style.italic;
options.bold = element.style.bold;
if (element.thickness !== undefined) {
options.thickness = element.thickness;
}
options.dashArray = '';
options.strokeWidth = element.style.strokeWidth;
options.fill = '';
return options;
}
/**
* @param {TextAttributes} text - text
* @param {string} textValue - textValue
* @param {number} maxHeight - maxHeight
* @private
* @returns {SubTextElement[]} - array of SubTextElement
*/
function wrapSvgTextEJ2(text, textValue, maxHeight) {
let childNodes = [];
let k = 0;
let txtValue;
let bounds1;
const content = textValue || text.content;
if (text.whiteSpace !== 'nowrap' && text.whiteSpace !== 'pre') {
if (text.breakWord === 'breakall') {
txtValue = '';
txtValue += content[0];
for (k = 0; k < content.length; k++) {
bounds1 = bBoxText(txtValue, text);
if (bounds1 >= text.width && txtValue.length > 0) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: bounds1 };
txtValue = '';
}
else {
txtValue = txtValue + (content[k + 1] || '');
// if (txtValue.indexOf('\n') > -1) {
// txtValue = txtValue.replace('\n', '');
// }
const width = bBoxText(txtValue, text);
if ((Math.ceil(width) + 2 >= text.width && txtValue.length > 0) || (txtValue.indexOf('\n') > -1)) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: width };
txtValue = '';
}
if (k === content.length - 1 && txtValue.length > 0) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: width };
txtValue = '';
}
}
}
}
else {
childNodes = wordWrappingEJ2(text, textValue, maxHeight);
}
}
else {
childNodes[childNodes.length] = { text: content, x: 0, dy: 0, width: bBoxText(content, text) };
}
return childNodes;
}
/**
* @param {TextAttributes} text - text
* @param {string} textValue - textValue
* @param {number} maxHeight - maxHeight
* @private
* @returns {SubTextElement[]} - array of SubTextElement
*/
function wordWrappingEJ2(text, textValue, maxHeight) {
let childNodes = [];
let txtValue = '';
let j = 0;
let i = 0;
const wrap = text.whiteSpace !== 'nowrap' ? true : false;
const content = textValue || text.content;
let bounds1;
const eachLine = content.split('\n');
let words;
let newText;
let height = 0;
let existingWidth;
let existingText;
for (j = 0; j < eachLine.length; j++) {
words = text.textWrapping !== 'NoWrap' ? eachLine[parseInt(j.toString(), 10)].split(' ') : eachLine;
for (i = 0; i < words.length; i++) {
bounds1 = bBoxText(words[parseInt(i.toString(), 10)], text);
if (bounds1 > text.width && words[parseInt(i.toString(), 10)].length > 0 && text.textWrapping !== 'NoWrap') {
if (eachLine.length > 1) {
words[parseInt(i.toString(), 10)] = words[parseInt(i.toString(), 10)] + '\n';
}
const previousTextContent = text.content;
text.content = words[parseInt(i.toString(), 10)];
//childNodes = wrapText(text, txtValue, childNodes, maxHeight, height);
const res = wrapTextEJ2(text, txtValue, childNodes, maxHeight, height);
childNodes = res.childNode;
height = res.height;
text.content = previousTextContent;
}
else {
txtValue += (((i !== 0 || words.length === 1) && wrap && txtValue.length > 0) ? ' ' : '') + words[parseInt(i.toString(), 10)];
newText = txtValue + (words[i + 1] || '');
let width = bBoxText(newText, text);
if (text.content[text.content.indexOf(txtValue) + txtValue.length] === ' ') {
width += bBoxText(' ', text);
}
if (eachLine.length > 1 && i === words.length - 1) {
txtValue = txtValue + '\n';
}
if (Math.floor(width) > text.width - 2 && txtValue.length > 0) {
textValue = txtValue;
const differenceValue = (text.fontSize * 1.2) - bBoxTextHeight(txtValue, text);
height = height + bBoxTextHeight(txtValue, text) + differenceValue;
if (maxHeight === undefined || maxHeight === null || height <= maxHeight ||
(height > maxHeight && childNodes.length === 0)) {
childNodes[childNodes.length] = {
text: (txtValue.indexOf('\n') === -1 && i !== words.length - 1) ? txtValue + ' ' : textValue, x: 0, dy: 0,
width: newText === txtValue ? width : (txtValue === existingText) ? existingWidth : bBoxText(txtValue, text)
};
}
txtValue = '';
}
else {
if (i === words.length - 1) {
const differenceValue = (text.fontSize * 1.2) - bBoxTextHeight(txtValue, text);
height = height + bBoxTextHeight(txtValue, text) + differenceValue;
if (maxHeight === undefined || height <= maxHeight || (height > maxHeight && childNodes.length === 0)) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: width };
txtValue = '';
}
}
}
existingText = newText;
existingWidth = width;
}
}
}
return childNodes;
}
/**
* @param {TextAttributes} txt - txt
* @param {string} textValue - textValue
* @param {SubTextElement[]} childNode - childNode
* @param {number} maxHeight - maxHeight
* @param {number} height - height
* @private
* @returns {any} - any
*/
function wrapTextEJ2(txt, textValue, childNode, maxHeight, height) {
let k = 0;
let txtValue;
let bounds1;
const content = textValue || txt.content;
txtValue = '';
txtValue += content[0];
let isFreeTextHeightAllowed;
for (k = 0; k < content.length; k++) {
bounds1 = bBoxText(txtValue, txt);
if (bounds1 >= txt.width && txtValue.length > 0) {
const differenceValue = (txt.fontSize * 1.2) - bBoxTextHeight(txtValue, txt);
height = height + bBoxTextHeight(txtValue, txt) + differenceValue;
if (maxHeight === undefined || maxHeight === null || height <= maxHeight || (height > maxHeight && childNode.length === 0)) {
childNode[childNode.length] = { text: txtValue, x: 0, dy: 0, width: bounds1 };
}
txtValue = '';
}
else {
txtValue = txtValue + (content[k + 1] || '');
let width = bBoxText(txtValue, txt);
if ((Math.ceil(width) + 2 >= txt.width && txtValue.length > 0)) {
txtValue = txtValue.slice(0, -1);
const differenceValue = (txt.fontSize * 1.2) - bBoxTextHeight(txtValue, txt);
height = height + bBoxTextHeight(txtValue, txt) + differenceValue;
width = bBoxText(txtValue, txt);
isFreeTextHeightAllowed = (maxHeight === undefined || maxHeight === null ||
height <= maxHeight || (height > maxHeight && childNode.length === 0));
if (isFreeTextHeightAllowed) {
childNode[childNode.length] = { text: txtValue, x: 0, dy: 0, width: width };
}
txtValue = content[k + 1] || '';
}
if (k === content.length - 1 && txtValue.length > 0) {
const differenceVal