igniteui-react-core
Version:
Ignite UI React Core.
522 lines (521 loc) • 16.3 kB
JavaScript
/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { Base, markType } from "./type";
import { SVGRoot } from "./SVGRoot";
import { SVGGroup } from "./SVGGroup";
import { SVGRect } from "./SVGRect";
import { SVGLine } from "./SVGLine";
import { SVGPath } from "./SVGPath";
import { SVGCircle } from "./SVGCircle";
import { SVGEllipse } from "./SVGEllipse";
import { Geometry } from "./Geometry";
import { Rect } from "./Rect";
import { TransformGroup } from "./TransformGroup";
import { RotateTransform } from "./RotateTransform";
import { TranslateTransform } from "./TranslateTransform";
import { ScaleTransform } from "./ScaleTransform";
import { MatrixTransform } from "./MatrixTransform";
import { Matrix } from "./Matrix";
import { SVGBrush } from "./SVGBrush";
import { Brush } from "./Brush";
import { stringEndsWith, stringReplace, stringStartsWith, stringContains } from "./string";
import { trimStart } from "./stringExtended";
/**
* @hidden
*/
var SVGParser = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(SVGParser, _super);
function SVGParser() {
return _super !== null && _super.apply(this, arguments) || this;
}
SVGParser.c = function (a) {
var b = false;
var c = "";
var d = "";
var e = null;
for (var f = 0; f < a.length; f++) {
var g = a.charAt(f);
if (g == '<') {
b = true;
continue;
}
if (b) {
if (g == ' ' || g == '>') {
if (g == '>') {
f--;
}
b = false;
continue;
}
d += g;
continue;
}
if (a.charAt(f) != '>' && !(a.charAt(f) == '/' && a.charAt(f + 1) == '>')) {
c += g;
}
else {
if (d == "svg") {
e = SVGParser.d(1, null, c);
if (a.charAt(f) == '>') {
f = SVGParser.f(a, f + 1, e);
}
return e;
}
else {
b = false;
c = "";
d = "";
}
}
}
return null;
};
SVGParser.f = function (a, b, c) {
var d = false;
var e = false;
var f = null;
var g = "";
var h = "";
for (var i = b; i < a.length; i++) {
var j = a.charAt(i);
if (j == '<') {
d = true;
e = true;
continue;
}
if (!e) {
continue;
}
if (d) {
if (c != null && j == '/') {
switch (c.c) {
case 2: return i + ("g>").length;
case 3:
case 7:
case 4: return i + ("rect>").length;
case 5: return i + ("circle>").length;
case 6: return i + ("ellipse>").length;
case 1: return i + ("svg>").length;
}
}
if (j == ' ' || j == '>') {
if (j == '>') {
i--;
}
d = false;
continue;
}
g += j;
continue;
}
if (a.charAt(i) != '>' && !(a.charAt(i) == '/' && a.charAt(i + 1) == '>')) {
h += j;
}
else {
var k = false;
switch (g) {
case "svg":
f = SVGParser.d(1, c, h);
break;
case "g":
f = SVGParser.d(2, c, h);
break;
case "line":
f = SVGParser.d(3, c, h);
break;
case "path":
f = SVGParser.d(7, c, h);
break;
case "rect":
f = SVGParser.d(4, c, h);
break;
case "circle":
f = SVGParser.d(5, c, h);
break;
case "ellipse":
f = SVGParser.d(6, c, h);
break;
}
if (f == null) {
var l = "";
var m = i;
while (m < a.length) {
l += a.charAt(m);
if (stringEndsWith(l, "/" + g + ">")) {
break;
}
m++;
i++;
}
}
else {
if (c != null) {
c.e.add(f);
}
if (a.charAt(i) == '>') {
i = SVGParser.f(a, i + 1, f);
}
}
d = false;
e = false;
g = "";
h = "";
}
}
return -1;
};
SVGParser.d = function (a, b, c) {
var d = null;
switch (a) {
case 1:
d = new SVGRoot();
break;
case 2:
d = new SVGGroup(b);
break;
case 4:
d = new SVGRect(b);
break;
case 3:
d = new SVGLine(b);
break;
case 7:
d = new SVGPath(b);
break;
case 5:
d = new SVGCircle(b);
break;
case 6:
d = new SVGEllipse(b);
break;
}
var e = true;
var f = false;
var g = "";
var h = "";
for (var i = 0; i < c.length; i++) {
if (c.charAt(i) == '=') {
e = false;
continue;
}
if (c.charAt(i) == '\"') {
f = !f;
if (!f && i == c.length - 1) {
SVGParser.g(d, g, h);
e = true;
f = false;
g = "";
h = "";
}
continue;
}
if (!e && !f && (c.charAt(i) == ' ' || i == c.length - 1)) {
SVGParser.g(d, g, h);
e = true;
f = false;
g = "";
h = "";
continue;
}
if (e) {
g += c.charAt(i);
}
if (f) {
h += c.charAt(i);
}
}
return d;
};
SVGParser.g = function (a, b, c) {
switch (b) {
case "id":
a.g = c;
break;
case "transform":
a.h = SVGParser.j(c);
break;
case "class":
a.f = c;
break;
}
if (a.c == 1) {
var d = a;
switch (b) {
case "width":
d.x = SVGParser.e(c);
break;
case "height":
d.w = SVGParser.e(c);
break;
case "viewBox":
d.y = SVGParser.k(c);
break;
}
}
else if (a.c == 7) {
var e = a;
switch (b) {
case "d":
e.w = Geometry.a(c);
break;
}
}
else if (a.c == 4) {
var f = a;
switch (b) {
case "width":
f.z = SVGParser.e(c);
break;
case "height":
f.w = SVGParser.e(c);
break;
case "rx":
f.x = SVGParser.e(c);
break;
case "ry":
f.y = SVGParser.e(c);
break;
}
}
else if (a.c == 3) {
var g = a;
switch (b) {
case "x1":
g.w = SVGParser.e(c);
break;
case "y1":
g.y = SVGParser.e(c);
break;
case "x2":
g.x = SVGParser.e(c);
break;
case "y2":
g.z = SVGParser.e(c);
break;
}
}
else if (a.c == 6 || a.c == 5) {
var h = a;
switch (b) {
case "cx":
h.w = SVGParser.e(c);
break;
case "cy":
h.x = SVGParser.e(c);
break;
case "r":
h.y = SVGParser.e(c);
h.z = SVGParser.e(c);
break;
case "rx":
h.y = SVGParser.e(c);
break;
case "ry":
h.z = SVGParser.e(c);
break;
}
}
if (a.d()) {
var i = a;
switch (b) {
case "opacity":
i.q = parseFloat(c);
break;
case "fill":
i.l = SVGParser.b(c);
break;
case "fill-opacity":
i.p = parseFloat(c);
break;
case "stroke":
i.m = SVGParser.b(c);
break;
case "stroke-linecap":
i.u = SVGParser.h(c);
break;
case "stroke-linejoin":
i.v = SVGParser.i(c);
break;
case "stroke-width":
i.t = SVGParser.e(c);
break;
case "stroke-miterlimit":
i.r = SVGParser.e(c);
break;
case "stroke-dasharray":
i.i = SVGParser.a(c);
break;
case "stroke-opacity":
i.s = parseFloat(c);
break;
}
}
};
SVGParser.e = function (a) {
return parseFloat(stringReplace(stringReplace(a, "px", ""), "%", ""));
};
SVGParser.k = function (a) {
var b = new Rect(4);
var c = a.split(' ');
if (c.length == 1) {
var d = SVGParser.e(c[0]);
b.x = d;
b.y = d;
b.width = d;
b.height = d;
}
else if (c.length == 2) {
b.x = SVGParser.e(c[0]);
b.y = b.x;
b.width = SVGParser.e(c[1]);
b.height = b.width;
}
else if (c.length == 3) {
b.x = SVGParser.e(c[0]);
b.y = SVGParser.e(c[1]);
b.width = SVGParser.e(c[2]);
b.height = b.width;
}
else {
b.x = SVGParser.e(c[0]);
b.y = SVGParser.e(c[1]);
b.width = SVGParser.e(c[2]);
b.height = SVGParser.e(c[3]);
}
return b;
};
SVGParser.j = function (a) {
var b = a.split(')');
var c = new TransformGroup();
var _loop_1 = function (d) {
var e = trimStart(b[d]);
if (stringStartsWith(e, "rotate")) {
var f_1;
if (stringContains(e, ",")) {
f_1 = stringReplace(e, "rotate(", "").split(',');
}
else {
f_1 = stringReplace(e, "rotate(", "").split(' ');
}
var g = ((function () {
var $ret = new RotateTransform();
$ret.j = parseFloat(f_1[0]);
return $ret;
})());
if (f_1.length > 1) {
g.k = parseFloat(f_1[1]);
g.l = parseFloat(f_1[2]);
}
c.j.insert(0, g);
}
else if (stringStartsWith(e, "translate")) {
var h_1;
if (stringContains(e, ",")) {
h_1 = stringReplace(e, "translate(", "").split(',');
}
else {
h_1 = stringReplace(e, "translate(", "").split(' ');
}
var i = ((function () {
var $ret = new TranslateTransform();
$ret.j = parseFloat(h_1[0]);
$ret.k = parseFloat(h_1[1]);
return $ret;
})());
c.j.insert(0, i);
}
else if (stringStartsWith(e, "scale")) {
var j = void 0;
if (stringContains(e, ",")) {
j = stringReplace(e, "scale(", "").split(',');
}
else {
j = stringReplace(e, "scale(", "").split(' ');
}
var k = new ScaleTransform();
if (j.length == 1) {
k.l = parseFloat(j[0]);
k.m = k.l;
}
else if (j.length == 2) {
k.l = parseFloat(j[0]);
k.m = parseFloat(j[1]);
}
c.j.insert(0, k);
}
else if (stringStartsWith(e, "matrix")) {
var l = void 0;
if (stringContains(e, ",")) {
l = stringReplace(e, "matrix(", "").split(',');
}
else {
l = stringReplace(e, "matrix(", "").split(' ');
}
var m = new MatrixTransform();
var n = new Matrix();
n.j = parseFloat(l[0]);
n.k = parseFloat(l[1]);
n.l = parseFloat(l[2]);
n.m = parseFloat(l[3]);
n.n = parseFloat(l[4]);
n.o = parseFloat(l[5]);
m.j = n;
c.j.insert(0, m);
}
};
for (var d = 0; d < b.length; d++) {
_loop_1(d);
}
return c;
};
SVGParser.b = function (a) {
var b = new SVGBrush();
if (a == "none") {
b.b = 0;
return b;
}
else if (a == "inherits") {
b.b = 1;
return b;
}
else {
b.b = 2;
b.e = ((function () {
var $ret = new Brush();
$ret.fill = a;
return $ret;
})());
return b;
}
};
SVGParser.h = function (a) {
switch (a) {
case "round": return 2;
case "square": return 1;
default: return 0;
}
};
SVGParser.i = function (a) {
switch (a) {
case "bevel": return 1;
case "round": return 2;
default: return 0;
}
};
SVGParser.a = function (a) {
var b = a.split(' ');
var c = new Array(b.length);
for (var d = 0; d < b.length; d++) {
c[d] = parseFloat(b[d]);
}
return c;
};
SVGParser.$t = markType(SVGParser, 'SVGParser');
return SVGParser;
}(Base));
export { SVGParser };