@syncfusion/ej2-diagrams
Version:
Feature-rich diagram control to create diagrams like flow charts, organizational charts, mind maps, and BPMN diagrams. Its rich feature set includes built-in shapes, editing, serializing, exporting, printing, overview, data binding, and automatic layouts.
1,596 lines (1,591 loc) • 4.18 MB
JavaScript
import { Property, ChildProperty, compile, getValue, Collection, ComplexFactory, initializeCSPTemplate, Complex, isBlazor, CollectionFactory, Component, Browser, EventHandler, Event, isNullOrUndefined, createElement, remove, L10n, Fetch, Droppable, Draggable } from '@syncfusion/ej2-base';
import { Tooltip } from '@syncfusion/ej2-popups';
import { DataManager, Query } from '@syncfusion/ej2-data';
import { ContextMenu, Accordion } from '@syncfusion/ej2-navigations';
/**
* Size defines and processes the size(width/height) of the objects
*/
var Size = /** @__PURE__ @class */ (function () {
function Size(width, height) {
this.width = width;
this.height = height;
}
/**
* isEmpty method \
*
* @returns { boolean } isEmpty method .\
*
* @private
*/
Size.prototype.isEmpty = function () {
return this.height === 0 && this.width === 0;
};
// public static get empty(): Size {
// return new Size();
// }
// public get isEmpty(): boolean {
// return this.equals(Size.empty);
// }
// public equals(size2: Size): boolean {
// return this.width === size2.width && this.height === size2.height;
// }
// public union(size: Size): void {
// size.width = Math.max(size.width, this.width);
// size.height = Math.max(size.height, this.height);
// }
/**
* clone method \
*
* @returns { Size } clone method .\
*
* @private
*/
Size.prototype.clone = function () {
return new Size(this.width, this.height);
};
return Size;
}());
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;
};
/**
* Defines and processes coordinates
*/
var Point = /** @__PURE__ @class */ (function (_super) {
__extends(Point, _super);
function Point() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* equals method \
*
* @returns { boolean } equals method .\
* @param {PointModel} point1 - provide the point1 value.
* @param {PointModel} point2 - provide the point1 value.
*
* @private
*/
Point.equals = function (point1, point2) {
if (point1 === point2) {
return true;
}
if (!point1 || !point2) {
return false;
}
return !point1 || !point2 || point1.x === point2.x && point1.y === point2.y;
};
/**
* isEmptyPoint method \
*
* @returns { boolean } isEmptyPoint method .\
* @param {PointModel} point - provide the points value.
*
* @private
*/
Point.isEmptyPoint = function (point) {
if (point.x && point.y) {
return false;
}
return true;
};
// public add(point1: PointModel, point2: PointModel): PointModel {
// return { x: point1.x + point2.x, y: point1.y + point2.y };
// }
// public subtract(point1: PointModel, point2: PointModel): PointModel {
// return { x: point1.x - point2.x, y: point1.y - point2.y };
// }
// public multiply(point1: PointModel, point2: PointModel): PointModel {
// return {
// x: point1.x * point2.x, y: point1.y * point2.y
// };
// }
// public crossProduct(point1: PointModel, point2: PointModel): PointModel {
// return {
// x: point1.x * point2.y, y: point2.x * point1.y
// };
// }
// public offset(offsetX: number, offsetY: number): void {
// this.x += offsetX;
// this.y += offsetY;
// }
// public rotate(angle: number): PointModel {
// let c: number = Math.cos(angle);
// let s: number = Math.sin(angle);
// return {
// x: c * this.x - s * this.y, y: s * this.x + c * this.y
// };
// }
// public distance(point2: PointModel): number {
// return Math.sqrt(Math.pow(this.x - point2.x, 2) + Math.pow(this.y - point2.y, 2));
// }
/**
* transform method \
*
* @returns { PointModel } transform method .\
* @param {PointModel} point - provide the points value.
* @param {number} angle - provide the points value.
* @param {number} length - provide the points value.
*
* @private
*/
Point.transform = function (point, angle, length) {
var pt = { x: 0, y: 0 };
pt.x = Math.round((point.x + length * Math.cos(angle * Math.PI / 180)) * 100) / 100;
pt.y = Math.round((point.y + length * Math.sin(angle * Math.PI / 180)) * 100) / 100;
return pt;
};
/**
* findLength method \
*
* @returns { number } findLength method .\
* @param {PointModel} s - provide the points value.
* @param {PointModel} e - provide the points value.
*
* @private
*/
Point.findLength = function (s, e) {
var length = Math.sqrt(Math.pow((s.x - e.x), 2) + Math.pow((s.y - e.y), 2));
return length;
};
/**
* findAngle method \
*
* @returns { number } findAngle method .\
* @param {PointModel} point1 - provide the points value.
* @param {PointModel} point2 - provide the points value.
*
* @private
*/
Point.findAngle = function (point1, point2) {
var angle = Math.atan2(point2.y - point1.y, point2.x - point1.x);
angle = (180 * angle / Math.PI);
angle %= 360;
if (angle < 0) {
angle += 360;
}
return angle;
};
/**
* distancePoints method \
*
* @returns { number } distancePoints method .\
* @param {PointModel} pt1 - provide the points value.
* @param {PointModel} pt2 - provide the points value.
*
* @private
*/
Point.distancePoints = function (pt1, pt2) {
return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
};
/**
* getLengthFromListOfPoints method \
*
* @returns { number } getLengthFromListOfPoints method .\
* @param {PointModel[]} points - provide the points value.
*
* @private
*/
Point.getLengthFromListOfPoints = function (points) {
var length = 0;
for (var j = 0; j < points.length - 1; j++) {
length += this.distancePoints(points[parseInt(j.toString(), 10)], points[j + 1]);
}
return length;
};
/**
* adjustPoint method \
*
* @returns { PointModel } adjustPoint method .\
* @param {PointModel} source - provide the points value.
* @param {PointModel} target - provide the points value.
* @param {boolean} isStart - provide the isStart value.
* @param {number} length - provide the length value.
*
* @private
*/
Point.adjustPoint = function (source, target, isStart, length) {
var pt = isStart ? { x: source.x, y: source.y } : { x: target.x, y: target.y };
var angle;
if (source.x === target.x) {
if (source.y < target.y && isStart || source.y > target.y && !isStart) {
pt.y += length;
}
else {
pt.y -= length;
}
}
else if (source.y === target.y) {
if (source.x < target.x && isStart || source.x > target.x && !isStart) {
pt.x += length;
}
else {
pt.x -= length;
}
}
else {
if (isStart) {
angle = this.findAngle(source, target);
pt = this.transform(source, angle, length);
}
else {
angle = this.findAngle(target, source);
pt = this.transform(target, angle, length);
}
}
return pt;
};
/**
* direction method \
*
* @returns { string } direction method .\
* @param {PointModel} pt1 - provide the points value.
* @param {PointModel} pt2 - provide the points value.
*
* @private
*/
Point.direction = function (pt1, pt2) {
if (Math.abs(pt2.x - pt1.x) > Math.abs(pt2.y - pt1.y)) {
return pt1.x < pt2.x ? 'Right' : 'Left';
}
else {
return pt1.y < pt2.y ? 'Bottom' : 'Top';
}
};
//Move these methods to util
//public CompareTo(point: PointModel): number {
// let result: number = this.X.CompareTo(point.X);
// return result != 0 ? result : this.Y.CompareTo(point.Y);
//}
//public CompareOnYAxis(point: PointModel): number {
// let result: number = this.X.CompareTo(point.X);
// return result != 0 ? result : this.Y.CompareTo(point.Y);
//}
//public CompareOnXAxis(point: PointModel): number {
// let result: number = this.Y.CompareTo(point.Y);
// return result != 0 ? result : this.X.CompareTo(point.X);
//}
// public round(): void {
// this.x = Math.round(this.x);
// this.y = Math.round(this.y);
// }
/**
* getClassName method \
*
* @returns { string } getClassName method .\
*
* @private
*/
Point.prototype.getClassName = function () {
return 'Point';
};
__decorate([
Property(0)
], Point.prototype, "x", void 0);
__decorate([
Property(0)
], Point.prototype, "y", void 0);
return Point;
}(ChildProperty));
/**
* These utility methods help to process the data and to convert it to desired dimensions
*/
/**
* processPathData method \
*
* @returns {Object[]} processPathData method .\
* @param { string } data - provide the data value.
* @private
*/
function processPathData(data) {
var collection = [];
var j;
var arrayCollection = parsePathData(data);
if (arrayCollection.length > 0) {
for (var i = 0; i < arrayCollection.length; i++) {
var ob = arrayCollection[parseInt(i.toString(), 10)];
var char = '';
char = ob[0];
switch (char.toLowerCase()) {
case 'm':
for (j = 1; j < ob.length; j++) {
collection.push({ command: char, x: ob[parseInt(j.toString(), 10)], y: ob[j + 1] });
j = j + 1;
if (char === 'm') {
char = 'l';
}
else if (char === 'M') {
char = 'L';
}
}
break;
case 'l':
case 't':
for (j = 1; j < ob.length; j++) {
collection.push({ command: char, x: ob[parseInt(j.toString(), 10)], y: ob[j + 1] });
j = j + 1;
}
break;
case 'h':
for (j = 1; j < ob.length; j++) {
collection.push({ command: char, x: ob[parseInt(j.toString(), 10)] });
}
break;
case 'v':
for (j = 1; j < ob.length; j++) {
collection.push({ command: char, y: ob[parseInt(j.toString(), 10)] });
}
break;
case 'z':
collection.push({ command: char });
break;
case 'c':
for (j = 1; j < ob.length; j++) {
collection.push({
command: char, x1: ob[parseInt(j.toString(), 10)], y1: ob[j + 1], x2: ob[j + 2],
y2: ob[j + 3], x: ob[j + 4], y: ob[j + 5]
});
j = j + 5;
}
break;
case 's':
for (j = 1; j < ob.length; j++) {
collection.push({ command: char, x2: ob[parseInt(j.toString(), 10)], y2: ob[j + 1], x: ob[j + 2], y: ob[j + 3] });
j = j + 3;
}
break;
case 'q':
for (j = 1; j < ob.length; j++) {
collection.push({ command: char, x1: ob[parseInt(j.toString(), 10)], y1: ob[j + 1], x: ob[j + 2], y: ob[j + 3] });
j = j + 3;
}
break;
case 'a':
for (j = 1; j < ob.length; j++) {
collection.push({
command: char, r1: ob[parseInt(j.toString(), 10)], r2: ob[j + 1], angle: ob[j + 2], largeArc: ob[j + 3],
sweep: ob[j + 4], x: ob[j + 5], y: ob[j + 6]
});
j = j + 6;
}
break;
}
}
}
return collection;
}
/**
* parsePathData method \
*
* @returns {Object[]} parsePathData method .\
* @param { string } data - provide the data value.
* @private
*/
function parsePathData(data) {
var tokenizer = /([a-z]+)|([+-]?(?:\d+\.?\d*|\.\d+))/gi;
var current = [];
var commands = [];
var match = {};
tokenizer.lastIndex = 0;
var isExponential = false;
match = tokenizer.exec(data);
while (match) {
if (match[1] === 'e') {
//let s1: string = '';
isExponential = true;
}
else if (match[1]) {
if (match[1].toLowerCase() === 'zm') {
if (current.length) {
commands.push(current);
}
commands.push(['Z']);
current = [match[1].substring(1, 2)];
}
else {
if (current.length) {
commands.push(current);
}
current = [match[1]];
}
isExponential = false;
}
else {
if (!current.length) {
current = [];
}
if (!isExponential) {
current.push(Number(match[2]));
}
isExponential = false;
}
match = tokenizer.exec(data);
}
if (current.length) {
commands.push(current);
}
return commands;
}
/**
* getRectanglePath method \
*
* @returns {string} getRectanglePath method .\
* @param { number } cornerRadius - provide the data value.
* @param { number } height - provide the height value.
* @param { number } width - provide the width value.
* @private
*/
function getRectanglePath(cornerRadius, height, width) {
var x = 0;
var y = 0;
var path = '';
var points = [{ x: x + cornerRadius, y: y }, { x: x + width - cornerRadius, y: y },
{ x: x + width, y: y + cornerRadius }, { x: x + width, y: y + height - cornerRadius },
{ x: x + width - cornerRadius, y: y + height }, { x: x + cornerRadius, y: y + height },
{ x: x, y: y + height - cornerRadius }, { x: x, y: y + cornerRadius }
];
var corners = [{ x: x + width, y: y }, { x: x + width, y: y + height }, { x: x, y: y + height }, { x: x, y: y }];
var corner = 0;
var point2;
var next;
path = 'M' + points[0].x + ' ' + points[0].y;
var i;
for (i = 0; i < points.length; i = i + 2) {
point2 = points[i + 1];
path += 'L' + point2.x + ' ' + point2.y;
next = points[i + 2] || points[0];
path += 'Q' + corners[parseInt(corner.toString(), 10)].x + ' ' + corners[parseInt(corner.toString(), 10)].y + ' ' + next.x + ' ' + next.y;
corner++;
}
return path;
}
/**
* getPolygonPath method \
*
* @returns {string} getPolygonPath method .\
* @param { PointModel[] } collection - provide the data value.
* @private
*/
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;
}
/**
* getFreeHandPath method \
*
* @returns {string} getFreeHandPath method .\
* @param { PointModel[] } collection - provide the data value.
* @private
*/
function getFreeHandPath(collection) {
var k;
for (k = 0; k < collection.length; k++) {
collection[parseInt(k.toString(), 10)].x = Math.round(collection[parseInt(k.toString(), 10)].x);
collection[parseInt(k.toString(), 10)].y = Math.round(collection[parseInt(k.toString(), 10)].y);
}
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;
}
return path;
}
/* eslint-disable */
/**
* pathSegmentCollection method \
*
* @returns {string} pathSegmentCollection method .\
* @param { Object[]} collection - provide the collection value.
* @private
*/
function pathSegmentCollection(collection) {
var x0;
var y0;
var x1;
var y1;
var x2;
var y2;
var x;
var y;
var length;
var i;
var segments = [];
for (x = 0, y = 0, i = 0, length = collection.length; i < length; ++i) {
var obj = collection[i];
var seg = obj;
var char = '';
char = seg.command;
if ('y1' in seg) {
y1 = seg.y1;
}
if ('y2' in seg) {
y2 = seg.y2;
}
if ('x1' in seg) {
x1 = seg.x1;
}
if ('x2' in seg) {
x2 = seg.x2;
}
if ('x' in seg) {
x = seg.x;
}
if ('y' in seg) {
y = seg.y;
}
var prev = segments[segments.length - 1];
switch (char) {
case 'M':
segments.push({ command: 'M', x: x, y: y });
break;
case 'L':
segments.push({ command: 'L', x0: x0, y0: y0, x: x, y: y });
break;
case 'H':
segments.push({ command: 'L', x0: x0, y0: y0, x: x, y: y0 });
break;
case 'V':
segments.push({ command: 'L', x0: x0, y0: y0, x: x0, y: y });
break;
case 'C':
segments.push({ command: 'C', x0: x0, y0: y0, x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y });
break;
case 'S':
if (prev) {
var ctrl = void 0;
if (prev.command === 'C' || prev.command === 'S') {
ctrl = { x: prev.x2, y: prev.y2 };
}
else {
ctrl = { x: x0, y: y0 };
}
var cpt2 = { x: 2 * x0 - ctrl.x, y: 2 * y0 - ctrl.y };
segments.push({ command: 'C', x0: x0, y0: y0, x1: cpt2.x, y1: cpt2.y, x2: x2, y2: y2, x: x, y: y });
}
break;
case 'Q':
//ctx.quadraticCurveTo(x1, y1, x, y);
segments.push({ command: 'Q', x0: x0, y0: y0, x1: x1, y1: y1, x: x, y: y });
break;
case 'T':
if (prev) {
var ctrl = void 0;
if (prev.command === 'Q') {
ctrl = { x: prev.x1, y: prev.y1 };
}
else {
ctrl = { x: x0, y: y0 };
}
var cpt2 = { x: 2 * x0 - ctrl.x, y: 2 * y0 - ctrl.y };
segments.push({ command: 'Q', x0: x0, y0: y0, x1: cpt2.x, y1: cpt2.y, x: x, y: y });
}
break;
case 'A':
var newSeg = seg;
newSeg.command = 'A';
segments.push(newSeg);
break;
case 'Z':
case 'z':
segments.push({ command: 'Z' });
x = x0;
y = y0;
break;
}
x0 = x;
y0 = y;
}
return segments;
}
/**
* transformPath method \
*
* @returns {string} transformPath method .\
* @param { Object[]} arr - provide the collection value.
* @param { number} sX - provide the collection value.
* @param { number} sY - provide the collection value.
* @param { boolean} s - provide the collection value.
* @param {number} bX - provide the collection value.
* @param { number} bY - provide the collection value.
* @param { number} iX - provide the collection value.
* @param { number} iY - provide the collection value.
* @private
*/
function transformPath(arr, sX, sY, s, bX, bY, iX, iY) {
var x1;
var y1;
var x2;
var y2;
var x;
var y;
var length;
var i;
var newSeg;
for (x = 0, y = 0, i = 0, length = arr.length; i < length; ++i) {
var obj = arr[i];
var seg = obj;
var char = seg.command;
if ('x' in seg) {
x = seg.x;
}
if ('y' in seg) {
y = seg.y;
}
if ('y1' in seg) {
y1 = seg.y1;
}
if ('y2' in seg) {
y2 = seg.y2;
}
if ('x1' in seg) {
x1 = seg.x1;
}
if ('x2' in seg) {
x2 = seg.x2;
}
if (s) {
if (x !== undefined) {
x = scalePathData(x, sX, bX, iX);
}
if (y !== undefined) {
y = scalePathData(y, sY, bY, iY);
}
if (x1 !== undefined) {
x1 = scalePathData(x1, sX, bX, iX);
}
if (y1 !== undefined) {
y1 = scalePathData(y1, sY, bY, iY);
}
if (x2 !== undefined) {
x2 = scalePathData(x2, sX, bX, iX);
}
if (y2 !== undefined) {
y2 = scalePathData(y2, sY, bY, iY);
}
}
else {
if (x !== undefined) {
x = Number((x + sX).toFixed(2));
}
if (y !== undefined) {
y = Number((y + sY).toFixed(2));
}
if (x1 !== undefined) {
x1 = Number((x1 + sX).toFixed(2));
}
if (y1 !== undefined) {
y1 = Number((y1 + sY).toFixed(2));
}
if (x2 !== undefined) {
x2 = Number((x2 + sX).toFixed(2));
}
if (y2 !== undefined) {
y2 = Number((y2 + sY).toFixed(2));
}
}
var scaledPath = { x: x, y: y, x1: x1, y1: y1, x2: x2, y2: y2, r1: seg.r1, r2: seg.r2 };
newSeg = updatedSegment(seg, char, scaledPath, s, sX, sY);
if (newSeg) {
arr[i] = newSeg;
}
}
var pathData = getPathString(arr);
return pathData;
}
/**
* updatedSegment method \
*
* @returns {string} updatedSegment method .\
* @param { PathSegment} segment - provide the collection value.
* @param { PathSegment} char - provide the collection value.
* @param { number} obj - provide the collection value.
* @param { boolean} isScale - provide the collection value.
* @param {number} sX - provide the collection value.
* @param { number} sY - provide the collection value.
* @private
*/
function updatedSegment(segment, char, obj, isScale, sX, sY) {
switch (char) {
case 'M':
segment.x = obj.x;
segment.y = obj.y;
break;
case 'L':
segment.x = obj.x;
segment.y = obj.y;
break;
case 'H':
segment.x = obj.x;
break;
case 'V':
segment.y = obj.y;
break;
case 'C':
segment.x = obj.x;
segment.y = obj.y;
segment.x1 = obj.x1;
segment.y1 = obj.y1;
segment.x2 = obj.x2;
segment.y2 = obj.y2;
break;
case 'S':
segment.x = obj.x;
segment.y = obj.y;
segment.x2 = obj.x2;
segment.y2 = obj.y2;
break;
case 'Q':
segment.x = obj.x;
segment.y = obj.y;
segment.x1 = obj.x1;
segment.y1 = obj.y1;
break;
case 'T':
segment.x = obj.x;
segment.y = obj.y;
break;
case 'A':
var r1 = obj.r1;
var r2 = obj.r2;
if (isScale) {
obj.r1 = r1 = (r1 * sX);
obj.r2 = r2 = (r2 * sY);
}
segment.x = obj.x;
segment.y = obj.y;
segment.r1 = obj.r1;
segment.r2 = obj.r2;
break;
case 'z':
case 'Z':
segment = { command: 'Z' };
break;
}
return segment;
}
/* eslint-enable */
/**
* scalePathData method \
*
* @returns {string} scalePathData method .\
* @param { number} val - provide the val value.
* @param { number} scaleFactor - provide the scaleFactor value.
* @param { number} oldOffset - provide the oldOffset value.
* @param { number} newOffset - provide the newOffset value.
* @private
*/
function scalePathData(val, scaleFactor, oldOffset, newOffset) {
if (val !== oldOffset) {
if (newOffset !== oldOffset) {
val = (((val * scaleFactor) - (Number(oldOffset) * scaleFactor - Number(oldOffset)))
+ (newOffset - Number(oldOffset)));
}
else {
val = ((Number(val) * scaleFactor) - (Number(oldOffset) * scaleFactor - Number(oldOffset)));
}
}
else {
if (newOffset !== oldOffset) {
val = newOffset;
}
}
return Number(val.toFixed(2));
}
/**
* splitArrayCollection method \
*
* @returns {Object[]} splitArrayCollection method .\
* @param { Object[]} arrayCollection - provide the val value.
* @private
*/
function splitArrayCollection(arrayCollection) {
var x0;
var y0;
var x1;
var y1;
var x2;
var y2;
var x;
var y;
var length;
var i;
for (x = 0, y = 0, i = 0, length = arrayCollection.length; i < length; ++i) {
var path = arrayCollection[parseInt(i.toString(), 10)];
var seg = path;
var char = seg.command;
if (/[MLHVCSQTA]/.test(char)) {
if ('x' in seg) {
seg.x = x = seg.x;
}
if ('y' in seg) {
seg.y = y = seg.y;
}
}
else {
if ('x1' in seg) {
seg.x1 = x1 = x + seg.x1;
}
if ('x2' in seg) {
seg.x2 = x2 = x + seg.x2;
}
if ('y1' in seg) {
seg.y1 = y1 = y + seg.y1;
}
if ('y2' in seg) {
seg.y2 = y2 = y + seg.y2;
}
if ('x' in seg) {
seg.x = x += seg.x;
}
if ('y' in seg) {
seg.y = y += seg.y;
}
var newSeg = void 0;
switch (char) {
case 'm':
case 'M':
newSeg = { command: 'M', x: x, y: y };
break;
case 'l':
case 'L':
newSeg = { command: 'L', x: x, y: y };
break;
case 'h':
case 'H':
newSeg = { command: 'H', x: x };
break;
case 'v':
case 'V':
newSeg = { command: 'V', y: y };
break;
case 'c':
case 'C':
newSeg = { command: 'C', x: x, y: y, x1: x1, y1: y1, x2: x2, y2: y2 };
break;
case 's':
case 'S':
newSeg = { command: 'S', x: x, y: y, x2: x2, y2: y2 };
break;
case 'q':
case 'Q':
newSeg = { command: 'Q', x: x, y: y, x1: x1, y1: y1 };
break;
case 't':
case 'T':
newSeg = { command: 'T', x: x, y: y };
break;
case 'a':
case 'A':
newSeg = { command: 'A', x: x, y: y };
newSeg.r1 = seg.r1;
newSeg.r2 = seg.r2;
newSeg.angle = seg.angle;
newSeg.largeArc = seg.largeArc;
newSeg.sweep = seg.sweep;
break;
case 'z':
case 'Z':
newSeg = { command: 'Z' };
x = x0;
y = y0;
newSeg = arrayCollection[parseInt(i.toString(), 10)];
break;
}
if (newSeg) {
arrayCollection[parseInt(i.toString(), 10)] = newSeg;
}
}
if (char === 'M' || char === 'm') {
x0 = x;
y0 = y;
}
}
return arrayCollection;
}
/**
* getPathString method \
*
* @returns {string} getPathString method .\
* @param { Object[]} arrayCollection - provide the val value.
* @private
*/
function getPathString(arrayCollection) {
var getNewString = '';
var i;
for (i = 0; i < arrayCollection.length; i++) {
if (i === 0) {
getNewString += getString(arrayCollection[parseInt(i.toString(), 10)]);
}
else {
getNewString += ' ' + getString(arrayCollection[parseInt(i.toString(), 10)]);
}
}
return getNewString;
}
/* eslint-disable */
/**
* getString method \
*
* @returns {string} getString method .\
* @param { PathSegment} arrayCollection - provide the val value.
* @private
*/
function getString(obj) {
var string = '';
switch (obj.command) {
case 'Z':
case 'z':
string = obj.command;
break;
case 'M':
case 'm':
case 'L':
case 'l':
string = obj.command + ' ' + obj.x + ' ' + obj.y;
break;
case 'C':
case 'c':
string = obj.command + ' ' + obj.x1 + ' ' + obj.y1 + ' ' + obj.x2 + ' ' + obj.y2 + ' ' + obj.x + ' ' + obj.y;
break;
case 'Q':
case 'q':
string = obj.command + ' ' + obj.x1 + ' ' + obj.y1 + ' ' + obj.x + ' ' + obj.y;
break;
case 'A':
case 'a':
var cmd = obj.command;
var ang = obj.angle;
var l = (obj.largeArc ? '1' : '0');
var s = (obj.sweep ? '1' : '0');
string = cmd + ' ' + obj.r1 + ' ' + obj.r2 + ' ' + ang + ' ' + l + ' ' + s + ' ' + obj.x + ' ' + obj.y;
break;
case 'H':
case 'h':
string = obj.command + ' ' + obj.x;
break;
case 'V':
case 'v':
string = obj.command + ' ' + obj.y;
break;
case 'S':
case 's':
string = obj.command + ' ' + obj.x2 + ' ' + obj.y2 + ' ' + obj.x + ' ' + obj.y;
break;
case 'T':
case 't':
string = obj.command + ' ' + obj.x + ' ' + obj.y;
}
return string;
}
/**
* Rect defines and processes rectangular regions
*/
var Rect = /** @__PURE__ @class */ (function () {
function Rect(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;
}
Object.defineProperty(Rect.prototype, "left", {
// eslint-disable-next-line jsdoc/require-returns
/** @private */
get: function () {
return this.x;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "right", {
/**
* right method \
*
* @returns { Rect } right method .\
*
* @private
*/
get: function () {
return this.x + this.width;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "top", {
/**
* toBounds method \
*
* @returns { Rect } toBounds method .\
*
* @private
*/
get: function () {
return this.y;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "bottom", {
/**
* bottom method \
*
* @returns { Rect } bottom method .\
*
* @private
*/
get: function () {
return this.y + this.height;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "topLeft", {
/**
* topLeft method \
*
* @returns { Rect } topLeft method .\
*
* @private
*/
get: function () {
return { x: this.left, y: this.top };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "topRight", {
/**
* topRight method \
*
* @returns { Rect } topRight method .\
*
* @private
*/
get: function () {
return { x: this.right, y: this.top };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "bottomLeft", {
/**
* bottomLeft method \
*
* @returns { Rect } bottomLeft method .\
*
* @private
*/
get: function () {
return { x: this.left, y: this.bottom };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "bottomRight", {
/**
* bottomRight method \
*
* @returns { Rect } bottomRight method .\
*
* @private
*/
get: function () {
return { x: this.right, y: this.bottom };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "middleLeft", {
/**
* middleLeft method \
*
* @returns { Rect } middleLeft method .\
*
* @private
*/
get: function () {
return { x: this.left, y: this.y + this.height / 2 };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "middleRight", {
/**
* middleRight method \
*
* @returns { Rect } middleRight method .\
*
* @private
*/
get: function () {
return { x: this.right, y: this.y + this.height / 2 };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "topCenter", {
/**
* topCenter method \
*
* @returns { Rect } topCenter method .\
*
* @private
*/
get: function () {
return { x: this.x + this.width / 2, y: this.top };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "bottomCenter", {
/**
* bottomCenter method \
*
* @returns { Rect } bottomCenter method .\
*
* @private
*/
get: function () {
return { x: this.x + this.width / 2, y: this.bottom };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Rect.prototype, "center", {
/**
* center method \
*
* @returns { PointModel } center method .\
*
* @private
*/
get: function () {
return { x: this.x + this.width / 2, y: this.y + this.height / 2 };
},
enumerable: true,
configurable: true
});
/**
* equals method \
*
* @returns { boolean } equals method .\
* @param {Rect} rect1 - provide the rect1 value.
* @param {Rect} rect2 - provide the rect2 value.
*
* @private
*/
Rect.prototype.equals = function (rect1, rect2) {
return rect1.x === rect2.x && rect1.y === rect2.y && rect1.width === rect2.width && rect1.height === rect2.height;
};
/**
* uniteRect method \
*
* @returns { Rect } uniteRect method .\
* @param {Rect} rect - provide the points value.
*
* @private
*/
Rect.prototype.uniteRect = function (rect) {
var right = Math.max(isNaN(this.right) || this.x === Number.MAX_VALUE ? rect.right : this.right, rect.right);
var bottom = Math.max(isNaN(this.bottom) || this.y === Number.MAX_VALUE ? rect.bottom : this.bottom, rect.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;
};
/**
* unitePoint method \
*
* @returns { void } unitePoint method .\
* @param {PointModel} point - provide the points value.
*
* @private
*/
Rect.prototype.unitePoint = function (point) {
if (this.x === Number.MAX_VALUE) {
this.x = point.x;
this.y = point.y;
return;
}
var x = Math.min(this.left, point.x);
var y = Math.min(this.top, point.y);
var right = Math.max(this.right, point.x);
var bottom = Math.max(this.bottom, point.y);
this.x = x;
this.y = y;
this.width = right - this.x;
this.height = bottom - this.y;
};
// public intersection(rect: Rect): Rect {
// if (this.intersects(rect)) {
// let left: number = Math.max(this.left, rect.left);
// let top: number = Math.max(this.top, rect.top);
// let right: number = Math.min(this.right, rect.right);
// let bottom: number = Math.min(this.bottom, rect.bottom);
// return new Rect(left, top, right - left, bottom - top);
// }
// return Rect.empty;
// }
/**
* Inflate method \
*
* @returns { Rect } Inflate method .\
* @param {number} padding - provide the points value.
*
* @private
*/
Rect.prototype.Inflate = function (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;
// }
/**
* intersects method \
*
* @returns { boolean } intersects method .\
* @param {Rect} rect - provide the points value.
*
* @private
*/
Rect.prototype.intersects = function (rect) {
if (this.right < rect.left || this.left > rect.right || this.top > rect.bottom || this.bottom < rect.top) {
return false;
}
return true;
};
/**
* containsRect method \
*
* @returns { boolean } containsRect method .\
* @param {Rect} rect - provide the points value.
*
* @private
*/
Rect.prototype.containsRect = function (rect) {
return this.left <= rect.left && this.right >= rect.right && this.top <= rect.top && this.bottom >= rect.bottom;
};
/**
* containsPoint method \
*
* @returns { boolean } containsPoint method .\
* @param {PointModel} point - provide the points value.
* @param {number} padding - provide the padding value.
*
* @private
*/
Rect.prototype.containsPoint = function (point, padding) {
if (padding === void 0) { padding = 0; }
return this.left - padding <= point.x && this.right + padding >= point.x
&& this.top - padding <= point.y && this.bottom + padding >= point.y;
};
// public toPoints(): PointModel[] {
// let points: PointModel[] = [];
// points.push(this.topLeft);
// points.push(this.topRight);
// points.push(this.bottomLeft);
// points.push(this.bottomRight);
// return points;
// }
/**
* toBounds method \
*
* @returns { Rect } toBounds method .\
* @param {PointModel[]} points - provide the points value.
*
* @private
*/
Rect.toBounds = function (points) {
var rect = new Rect();
for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
var pt = points_1[_i];
rect.unitePoint(pt);
}
return rect;
};
/** @private */
Rect.empty = new Rect(Number.MAX_VALUE, Number.MIN_VALUE, 0, 0);
return Rect;
}());
/**
* Matrix module is used to transform points based on offsets, angle
*/
/** @private */
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 = {}));
/** @private */
var Matrix = /** @__PURE__ @class */ (function () {
function Matrix(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;
}
return Matrix;
}());
/**
* Will identify the matrix .\
*
* @returns {Matrix} Will identify the matrix .
* @private
*/
function identityMatrix() {
return new Matrix(1, 0, 0, 1, 0, 0, MatrixTypes.Identity);
}
/**
* Will transform the points by matrix .\
*
* @returns {PointModel[]} Will transform the points by matrix .
*
* @param {Matrix} matrix - provide the matrix value .
* @param {number} point - provide the points value.
* @private
*/
function transformPointByMatrix(matrix, point) {
var pt = multiplyPoint(matrix, point.x, point.y);
return { x: Math.round(pt.x * 100) / 100, y: Math.round(pt.y * 100) / 100 };
}
/**
* Will transform the points by matrix .\
*
* @returns {PointModel[]} Will transform the points by matrix .
*
* @param {Matrix} matrix - provide the matrix value .
* @param {number} points - provide the points value.
* @private
*/
function transformPointsByMatrix(matrix, points) {
var transformedPoints = [];
for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
var point = points_1[_i];
transformedPoints.push(transformPointByMatrix(matrix, point));
}
return transformedPoints;
}
/**
* Will rotate the matrix .\
*
* @returns {void} Will rotate the matrix .
*
* @param {Matrix} matrix - provide the matrix value .
* @param {number} angle - provide the angle value.
* @param {number} centerX - provide the centerX value .
* @param {number} centerY - provide the centerY value .
* @private
*/
function rotateMatrix(matrix, angle, centerX, centerY) {
angle %= 360.0;
multiplyMatrix(matrix, createRotationRadians(angle * 0.017453292519943295, centerX ? centerX : 0, centerY ? centerY : 0));
}
/**
* Will scale the matrix .\
*
* @returns {void} Will scale the matrix .
*
* @param {Matrix} matrix - provide the matrix value .
* @param {number} scaleX - provide the scaleXvalue.
* @param {number} scaleY - provide the scaleY value .
* @param {number} centerX - provide the centerX value .
* @param {number} centerY - provide the centerY value .
* @private
*/
function scaleMatrix(matrix, scaleX, scaleY, centerX, centerY) {
if (centerX === void 0) { centerX = 0; }
if (centerY === void 0) { centerY = 0; }
multiplyMatrix(matrix, createScaling(scaleX, scaleY, centerX, centerY));
}
/**
* Will translate the matrix .\
*
* @returns {void} Will translate the matrix .
*
* @param {Matrix} matrix - provide the matrix value .
* @param {number} offsetX - provide the offset x value.
* @param {number} offsetY - provide the offset y value .
* @private
*/
function translateMatrix(matrix, offsetX, offsetY) {
//Removed identity and unknown matrix type checking
matrix.offsetX += offsetX;
matrix.offsetY += offsetY;
matrix.type |= MatrixTypes.Translation;
}
/**
* Will create scaling value .\
*
* @returns {Matrix} Will create scaling value . .
*
* @param {Matrix} scaleX - provide the scale x value .
* @param {number} scaleY - provide the scale y value.
* @param {number} centerX - provide the centerX x value .
* @param {number} centerY - provide the centerX y value .
* @private
*/
function createScaling(scaleX, scaleY, centerX, centerY) {
var 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;
}
/**
* Will create the rotation radians.\
*
* @returns {Matrix} Will create the rotation radians .
*
* @param {Matrix} angle - provide the angle .
* @param {number} centerX - provide the x value .
* @param {number} centerY - provide the y value .
* @private
*/
function createRotationRadians(angle, centerX, centerY) {
var result = identityMatrix();
var num = Math.sin(angle);
var num2 = Math.cos(angle);
var offsetX = centerX * (1.0 - num2) + centerY * num;
var offsetY = centerY * (1.0 - num2) - centerX * num;
result.type = MatrixTypes.Unknown;
setMatrix(result, num2, num, -num, num2, offsetX, offsetY);
return result;
}
/**
* Multiply the point .\
*
* @returns {void} Multiply the point .
*
* @param {Matrix} matrix - Provide the matrix .
* @param {number} x - provide the x value .
* @param {number} y - provide the y value .
* @private
*/
function multiplyPoint(matrix, x, y) {
switch (matrix.type) {
//Removed identity and translation and scaling matrix type checking
case MatrixTypes.Translation | MatrixTypes.Scaling:
x *= matrix.m11;
x += matrix.offsetX;
y *= matrix.m22;
y += matrix.offsetY;
break;
default:
// eslint-disable-next-line no-case-declarations
var num = y * matrix.m21 + matrix.offsetX;
// eslint-disable-next-line no-case-declarations
var num2 = x * matrix.m12 + matrix.offsetY;
x *= matrix.m11;
x += num;
y *= matrix.m22;
y += num2;
break;
}
return { x: x, y: y };
}
/**
* Will multiply the matrix .\
*
* @returns {void} Will multiply the matrix .
*
* @param {Matrix} matrix1 - Provide the matrix 1 value .
* @param {Matrix} matrix2 - Provide the matrix 2 value .
* @private
*/
function multiplyMatrix(matrix1, matrix2) {
var type = matrix1.type;
var type2 = matrix2.type;
//Removed identity matrix type checking
if (type === MatrixTypes.Identity) {
assignMatrix(matrix1, matrix2);
matrix1.type = matrix2.type;
return;
}
//Removed translation matrix type checking
if (type !== MatrixTypes.Translation) {
var num = ty