transformation-matrix
Advanced tools
Comparing version 1.15.3 to 2.0.0
@@ -8,7 +8,8 @@ "use strict"; | ||
exports.applyToPoints = applyToPoints; | ||
/** | ||
* Calculate a point transformed with an affine matrix | ||
* @param matrix Affine matrix | ||
* @param point Point | ||
* @returns {{x: number, y: number} | Array} Point | ||
* @param matrix {Matrix} Affine Matrix | ||
* @param point {Point} Point | ||
* @returns {Point} Point | ||
*/ | ||
@@ -21,13 +22,12 @@ function applyToPoint(matrix, point) { | ||
} | ||
/** | ||
* Calculate an array of points transformed with an affine matrix | ||
* @param matrix Affine matrix | ||
* @param points Array of points | ||
* @returns {array} Array of points | ||
* @param matrix {Matrix} Affine Matrix | ||
* @param points {Point[]} Array of point | ||
* @returns {Point[]} Array of point | ||
*/ | ||
function applyToPoints(matrix, points) { | ||
return points.map(function (point) { | ||
return applyToPoint(matrix, point); | ||
}); | ||
return points.map(point => applyToPoint(matrix, point)); | ||
} |
@@ -7,7 +7,8 @@ "use strict"; | ||
exports.fromObject = fromObject; | ||
/** | ||
* Extract an affine matrix from an object that contains a,b,c,d,e,f keys | ||
* Each value could be a float or a string that contains a float | ||
* @param object | ||
* @return {{a: *, b: *, c: *, e: *, d: *, f: *}}} | ||
* Any value could be a float or a string that contains a float | ||
* @param object {Object} Object that contains a,b,c,d,e,f keys | ||
* @return {Matrix} Affine Matrix | ||
*/ | ||
@@ -14,0 +15,0 @@ function fromObject(object) { |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.fromString = fromString; | ||
/** | ||
@@ -12,12 +13,16 @@ * @ignore | ||
*/ | ||
var matrixRegex = /^matrix\(\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*\)$/i; | ||
const matrixRegex = /^matrix\(\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*\)$/i; | ||
/** | ||
* Parse a string matrix formatted as matrix(a,b,c,d,e,f) | ||
* @param string String with a matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* Parse a string formatted as matrix(a,b,c,d,e,f) | ||
* @param string {string} String with an affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
* | ||
* @example | ||
* > fromString('matrix(1,2,3,4,5,6)') | ||
* {a: 1, b: 2, c: 3, d: 4, c: 5, e: 6} | ||
*/ | ||
function fromString(string) { | ||
var parsed = string.match(matrixRegex); | ||
if (parsed === null || parsed.length < 7) throw new Error("'" + string + "' is not a matrix"); | ||
let parsed = string.match(matrixRegex); | ||
if (parsed === null || parsed.length < 7) throw new Error(`'${string}' is not a matrix`); | ||
return { | ||
@@ -24,0 +29,0 @@ a: parseFloat(parsed[1]), |
@@ -6,4 +6,7 @@ "use strict"; | ||
}); | ||
// Generated by PEG.js v0.11.0-dev, https://pegjs.org/ | ||
exports.SyntaxError = peg$SyntaxError; | ||
exports.parse = peg$parse; | ||
exports.default = void 0; | ||
// Generated by PEG.js v0.11.0-master.30f3260, https://pegjs.org/ | ||
function peg$subclass(child, parent) { | ||
@@ -13,2 +16,3 @@ function C() { | ||
} | ||
C.prototype = parent.prototype; | ||
@@ -23,5 +27,4 @@ child.prototype = new C(); | ||
this.location = location; | ||
this.name = "SyntaxError"; | ||
this.name = "SyntaxError"; // istanbul ignore next | ||
// istanbul ignore next | ||
if (typeof Error.captureStackTrace === "function") { | ||
@@ -36,27 +39,21 @@ Error.captureStackTrace(this, peg$SyntaxError); | ||
var DESCRIBE_EXPECTATION_FNS = { | ||
literal: function literal(expectation) { | ||
literal: function (expectation) { | ||
return "\"" + literalEscape(expectation.text) + "\""; | ||
}, | ||
class: function _class(expectation) { | ||
class: function (expectation) { | ||
var escapedParts = expectation.parts.map(function (part) { | ||
return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part); | ||
}); | ||
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; | ||
}, | ||
any: function any() { | ||
any: function () { | ||
return "any character"; | ||
}, | ||
end: function end() { | ||
end: function () { | ||
return "end of input"; | ||
}, | ||
other: function other(expectation) { | ||
other: function (expectation) { | ||
return expectation.description; | ||
}, | ||
not: function not(expectation) { | ||
not: function (expectation) { | ||
return "not " + describeExpectation(expectation.expected); | ||
@@ -93,3 +90,2 @@ } | ||
var i, j; | ||
descriptions.sort(); | ||
@@ -104,2 +100,3 @@ | ||
} | ||
descriptions.length = j; | ||
@@ -129,8 +126,7 @@ } | ||
options = options !== undefined ? options : {}; | ||
var peg$FAILED = {}; | ||
var peg$startRuleFunctions = { transformList: peg$parsetransformList }; | ||
var peg$startRuleFunctions = { | ||
transformList: peg$parsetransformList | ||
}; | ||
var peg$startRuleFunction = peg$parsetransformList; | ||
var peg$c0 = "matrix"; | ||
@@ -146,3 +142,2 @@ var peg$c1 = "("; | ||
var peg$c9 = "."; | ||
var peg$r0 = /^[eE]/; | ||
@@ -152,3 +147,2 @@ var peg$r1 = /^[+\-]/; | ||
var peg$r3 = /^[ \t\r\n]/; | ||
var peg$e0 = peg$literalExpectation("matrix", false); | ||
@@ -169,23 +163,46 @@ var peg$e1 = peg$literalExpectation("(", false); | ||
var peg$f0 = function peg$f0(ts) { | ||
var peg$f0 = function (ts) { | ||
return ts; | ||
}; | ||
var peg$f1 = function peg$f1(t, ts) { | ||
var peg$f1 = function (t, ts) { | ||
return t.concat(ts); | ||
}; | ||
var peg$f2 = function peg$f2(a, b, c, d, e, f) { | ||
return [{ type: 'matrix', a: a, b: b, c: c, d: d, e: e, f: f }]; | ||
var peg$f2 = function (a, b, c, d, e, f) { | ||
return [{ | ||
type: 'matrix', | ||
a: a, | ||
b: b, | ||
c: c, | ||
d: d, | ||
e: e, | ||
f: f | ||
}]; | ||
}; | ||
var peg$f3 = function peg$f3(tx, ty) { | ||
var t = { type: 'translate', tx: tx }; | ||
var peg$f3 = function (tx, ty) { | ||
var t = { | ||
type: 'translate', | ||
tx: tx | ||
}; | ||
if (ty) t.ty = ty; | ||
return [t]; | ||
}; | ||
var peg$f4 = function peg$f4(sx, sy) { | ||
var s = { type: 'scale', sx: sx }; | ||
var peg$f4 = function (sx, sy) { | ||
var s = { | ||
type: 'scale', | ||
sx: sx | ||
}; | ||
if (sy) s.sy = sy; | ||
return [s]; | ||
}; | ||
var peg$f5 = function peg$f5(angle, c) { | ||
var r = { type: 'rotate', angle: angle }; | ||
var peg$f5 = function (angle, c) { | ||
var r = { | ||
type: 'rotate', | ||
angle: angle | ||
}; | ||
if (c) { | ||
@@ -195,29 +212,45 @@ r.cx = c[0]; | ||
} | ||
return [r]; | ||
}; | ||
var peg$f6 = function peg$f6(angle) { | ||
return [{ type: 'skewX', angle: angle }]; | ||
var peg$f6 = function (angle) { | ||
return [{ | ||
type: 'skewX', | ||
angle: angle | ||
}]; | ||
}; | ||
var peg$f7 = function peg$f7(angle) { | ||
return [{ type: 'skewY', angle: angle }]; | ||
var peg$f7 = function (angle) { | ||
return [{ | ||
type: 'skewY', | ||
angle: angle | ||
}]; | ||
}; | ||
var peg$f8 = function peg$f8(f) { | ||
var peg$f8 = function (f) { | ||
return parseFloat(f.join("")); | ||
}; | ||
var peg$f9 = function peg$f9(i) { | ||
var peg$f9 = function (i) { | ||
return parseInt(i.join("")); | ||
}; | ||
var peg$f10 = function peg$f10(n) { | ||
var peg$f10 = function (n) { | ||
return n; | ||
}; | ||
var peg$f11 = function peg$f11(n1, n2) { | ||
var peg$f11 = function (n1, n2) { | ||
return [n1, n2]; | ||
}; | ||
var peg$f12 = function peg$f12(ds) { | ||
var peg$f12 = function (ds) { | ||
return ds.join(""); | ||
}; | ||
var peg$f13 = function peg$f13(d1, d2) { | ||
var peg$f13 = function (d1, d2) { | ||
return [d1 ? d1.join("") : null, ".", d2.join("")].join(""); | ||
}; | ||
var peg$f14 = function peg$f14(d) { | ||
var peg$f14 = function (d) { | ||
return d.join(""); | ||
@@ -228,6 +261,8 @@ }; | ||
var peg$savedPos = 0; | ||
var peg$posDetailsCache = [{ line: 1, column: 1 }]; | ||
var peg$posDetailsCache = [{ | ||
line: 1, | ||
column: 1 | ||
}]; | ||
var peg$expected = []; | ||
var peg$silentFails = 0; | ||
var peg$result; | ||
@@ -261,3 +296,2 @@ | ||
location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos); | ||
throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location); | ||
@@ -268,3 +302,2 @@ } | ||
location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos); | ||
throw peg$buildSimpleError(message, location); | ||
@@ -274,19 +307,35 @@ } | ||
function peg$literalExpectation(text, ignoreCase) { | ||
return { type: "literal", text: text, ignoreCase: ignoreCase }; | ||
return { | ||
type: "literal", | ||
text: text, | ||
ignoreCase: ignoreCase | ||
}; | ||
} | ||
function peg$classExpectation(parts, inverted, ignoreCase) { | ||
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; | ||
return { | ||
type: "class", | ||
parts: parts, | ||
inverted: inverted, | ||
ignoreCase: ignoreCase | ||
}; | ||
} | ||
function peg$anyExpectation() { | ||
return { type: "any" }; | ||
return { | ||
type: "any" | ||
}; | ||
} | ||
function peg$endExpectation() { | ||
return { type: "end" }; | ||
return { | ||
type: "end" | ||
}; | ||
} | ||
function peg$otherExpectation(description) { | ||
return { type: "other", description: description }; | ||
return { | ||
type: "other", | ||
description: description | ||
}; | ||
} | ||
@@ -302,2 +351,3 @@ | ||
p = pos - 1; | ||
while (!peg$posDetailsCache[p]) { | ||
@@ -325,3 +375,2 @@ p--; | ||
peg$posDetailsCache[pos] = details; | ||
return details; | ||
@@ -332,7 +381,6 @@ } | ||
var peg$VALIDFILENAME = typeof options.filename === "string" && options.filename.length > 0; | ||
function peg$computeLocation(startPos, endPos) { | ||
var loc = {}; | ||
if (peg$VALIDFILENAME) loc.filename = options.filename; | ||
var startPosDetails = peg$computePosDetails(startPos); | ||
@@ -344,3 +392,2 @@ loc.start = { | ||
}; | ||
var endPosDetails = peg$computePosDetails(endPos); | ||
@@ -352,3 +399,2 @@ loc.end = { | ||
}; | ||
return loc; | ||
@@ -358,3 +404,6 @@ } | ||
function peg$begin() { | ||
peg$expected.push({ pos: peg$currPos, variants: [] }); | ||
peg$expected.push({ | ||
pos: peg$currPos, | ||
variants: [] | ||
}); | ||
} | ||
@@ -388,3 +437,6 @@ | ||
variants = variants.map(function (e) { | ||
return e.type === "not" ? e.expected : { type: "not", expected: e }; | ||
return e.type === "not" ? e.expected : { | ||
type: "not", | ||
expected: e | ||
}; | ||
}); | ||
@@ -407,3 +459,2 @@ } | ||
var failPos = expected.pos; | ||
return peg$buildStructuredError(expected.variants, failPos < input.length ? input.charAt(failPos) : null, failPos < input.length ? peg$computeLocation(failPos, failPos + 1) : peg$computeLocation(failPos, failPos)); | ||
@@ -415,3 +466,3 @@ } | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -423,2 +474,3 @@ }; | ||
s2 = peg$parsewsp(); | ||
while (s2 !== peg$FAILED) { | ||
@@ -428,8 +480,12 @@ s1.push(s2); | ||
} | ||
s2 = peg$parsetransforms(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = []; | ||
s4 = peg$parsewsp(); | ||
while (s4 !== peg$FAILED) { | ||
@@ -439,5 +495,5 @@ s3.push(s4); | ||
} | ||
peg$savedPos = s0; | ||
s0 = peg$f0(s2); | ||
return s0; | ||
@@ -449,3 +505,3 @@ } | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -456,5 +512,7 @@ }; | ||
s1 = peg$parsetransform(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsecommaWsp(); | ||
if (s3 !== peg$FAILED) { | ||
@@ -468,4 +526,6 @@ while (s3 !== peg$FAILED) { | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsetransforms(); | ||
if (s3 !== peg$FAILED) { | ||
@@ -486,2 +546,3 @@ peg$savedPos = s0; | ||
} | ||
if (s0 === peg$FAILED) { | ||
@@ -497,3 +558,3 @@ s0 = peg$parsetransform(); | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -503,10 +564,15 @@ }; | ||
s0 = peg$parsematrix(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parsetranslate(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parsescale(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parserotate(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseskewX(); | ||
if (s0 === peg$FAILED) { | ||
@@ -526,3 +592,3 @@ s0 = peg$parseskewY(); | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -533,2 +599,3 @@ }; | ||
rule$expects(peg$e0); | ||
if (input.substr(peg$currPos, 6) === peg$c0) { | ||
@@ -540,5 +607,7 @@ s1 = peg$c0; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
@@ -548,3 +617,5 @@ s2.push(s3); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
@@ -556,5 +627,7 @@ s3 = peg$c1; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
@@ -564,26 +637,39 @@ s4.push(s5); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWsp(); | ||
if (s6 !== peg$FAILED) { | ||
s7 = peg$parsenumber(); | ||
if (s7 !== peg$FAILED) { | ||
s8 = peg$parsecommaWsp(); | ||
if (s8 !== peg$FAILED) { | ||
s9 = peg$parsenumber(); | ||
if (s9 !== peg$FAILED) { | ||
s10 = peg$parsecommaWsp(); | ||
if (s10 !== peg$FAILED) { | ||
s11 = peg$parsenumber(); | ||
if (s11 !== peg$FAILED) { | ||
s12 = peg$parsecommaWsp(); | ||
if (s12 !== peg$FAILED) { | ||
s13 = peg$parsenumber(); | ||
if (s13 !== peg$FAILED) { | ||
s14 = peg$parsecommaWsp(); | ||
if (s14 !== peg$FAILED) { | ||
s15 = peg$parsenumber(); | ||
if (s15 !== peg$FAILED) { | ||
s16 = []; | ||
s17 = peg$parsewsp(); | ||
while (s17 !== peg$FAILED) { | ||
@@ -593,3 +679,5 @@ s16.push(s17); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
@@ -601,2 +689,3 @@ s17 = peg$c2; | ||
} | ||
if (s17 !== peg$FAILED) { | ||
@@ -668,3 +757,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -675,2 +764,3 @@ }; | ||
rule$expects(peg$e3); | ||
if (input.substr(peg$currPos, 9) === peg$c3) { | ||
@@ -682,5 +772,7 @@ s1 = peg$c3; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
@@ -690,3 +782,5 @@ s2.push(s3); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
@@ -698,5 +792,7 @@ s3 = peg$c1; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
@@ -706,10 +802,15 @@ s4.push(s5); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWspNumber(); | ||
if (s6 === peg$FAILED) { | ||
s6 = null; | ||
} | ||
s7 = []; | ||
s8 = peg$parsewsp(); | ||
while (s8 !== peg$FAILED) { | ||
@@ -719,3 +820,5 @@ s7.push(s8); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
@@ -727,2 +830,3 @@ s8 = peg$c2; | ||
} | ||
if (s8 !== peg$FAILED) { | ||
@@ -754,3 +858,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -761,2 +865,3 @@ }; | ||
rule$expects(peg$e4); | ||
if (input.substr(peg$currPos, 5) === peg$c4) { | ||
@@ -768,5 +873,7 @@ s1 = peg$c4; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
@@ -776,3 +883,5 @@ s2.push(s3); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
@@ -784,5 +893,7 @@ s3 = peg$c1; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
@@ -792,10 +903,15 @@ s4.push(s5); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWspNumber(); | ||
if (s6 === peg$FAILED) { | ||
s6 = null; | ||
} | ||
s7 = []; | ||
s8 = peg$parsewsp(); | ||
while (s8 !== peg$FAILED) { | ||
@@ -805,3 +921,5 @@ s7.push(s8); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
@@ -813,2 +931,3 @@ s8 = peg$c2; | ||
} | ||
if (s8 !== peg$FAILED) { | ||
@@ -840,3 +959,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -847,2 +966,3 @@ }; | ||
rule$expects(peg$e5); | ||
if (input.substr(peg$currPos, 6) === peg$c5) { | ||
@@ -854,5 +974,7 @@ s1 = peg$c5; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
@@ -862,3 +984,5 @@ s2.push(s3); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
@@ -870,5 +994,7 @@ s3 = peg$c1; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
@@ -878,10 +1004,15 @@ s4.push(s5); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWspTwoNumbers(); | ||
if (s6 === peg$FAILED) { | ||
s6 = null; | ||
} | ||
s7 = []; | ||
s8 = peg$parsewsp(); | ||
while (s8 !== peg$FAILED) { | ||
@@ -891,3 +1022,5 @@ s7.push(s8); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
@@ -899,2 +1032,3 @@ s8 = peg$c2; | ||
} | ||
if (s8 !== peg$FAILED) { | ||
@@ -926,3 +1060,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -933,2 +1067,3 @@ }; | ||
rule$expects(peg$e6); | ||
if (input.substr(peg$currPos, 5) === peg$c6) { | ||
@@ -940,5 +1075,7 @@ s1 = peg$c6; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
@@ -948,3 +1085,5 @@ s2.push(s3); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
@@ -956,5 +1095,7 @@ s3 = peg$c1; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
@@ -964,6 +1105,9 @@ s4.push(s5); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = []; | ||
s7 = peg$parsewsp(); | ||
while (s7 !== peg$FAILED) { | ||
@@ -973,3 +1117,5 @@ s6.push(s7); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
@@ -981,2 +1127,3 @@ s7 = peg$c2; | ||
} | ||
if (s7 !== peg$FAILED) { | ||
@@ -1008,3 +1155,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1015,2 +1162,3 @@ }; | ||
rule$expects(peg$e7); | ||
if (input.substr(peg$currPos, 5) === peg$c7) { | ||
@@ -1022,5 +1170,7 @@ s1 = peg$c7; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
@@ -1030,3 +1180,5 @@ s2.push(s3); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
@@ -1038,5 +1190,7 @@ s3 = peg$c1; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
@@ -1046,6 +1200,9 @@ s4.push(s5); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = []; | ||
s7 = peg$parsewsp(); | ||
while (s7 !== peg$FAILED) { | ||
@@ -1055,3 +1212,5 @@ s6.push(s7); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
@@ -1063,2 +1222,3 @@ s7 = peg$c2; | ||
} | ||
if (s7 !== peg$FAILED) { | ||
@@ -1090,3 +1250,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1098,6 +1258,9 @@ }; | ||
s2 = peg$parsesign(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = peg$parsefloatingPointConstant(); | ||
if (s3 !== peg$FAILED) { | ||
@@ -1110,2 +1273,3 @@ s2 = [s2, s3]; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
@@ -1115,3 +1279,5 @@ peg$savedPos = s0; | ||
} | ||
s0 = s1; | ||
if (s0 === peg$FAILED) { | ||
@@ -1121,6 +1287,9 @@ s0 = peg$currPos; | ||
s2 = peg$parsesign(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = peg$parseintegerConstant(); | ||
if (s3 !== peg$FAILED) { | ||
@@ -1133,2 +1302,3 @@ s2 = [s2, s3]; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
@@ -1138,2 +1308,3 @@ peg$savedPos = s0; | ||
} | ||
s0 = s1; | ||
@@ -1148,3 +1319,3 @@ } | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1155,4 +1326,6 @@ }; | ||
s1 = peg$parsecommaWsp(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsenumber(); | ||
if (s2 !== peg$FAILED) { | ||
@@ -1176,3 +1349,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1183,8 +1356,12 @@ }; | ||
s1 = peg$parsecommaWsp(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsenumber(); | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsecommaWsp(); | ||
if (s3 !== peg$FAILED) { | ||
s4 = peg$parsenumber(); | ||
if (s4 !== peg$FAILED) { | ||
@@ -1216,3 +1393,3 @@ peg$savedPos = s0; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1224,2 +1401,3 @@ }; | ||
s2 = peg$parsewsp(); | ||
if (s2 !== peg$FAILED) { | ||
@@ -1233,9 +1411,13 @@ while (s2 !== peg$FAILED) { | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsecomma(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = []; | ||
s4 = peg$parsewsp(); | ||
while (s4 !== peg$FAILED) { | ||
@@ -1245,2 +1427,3 @@ s3.push(s4); | ||
} | ||
s1 = [s1, s2, s3]; | ||
@@ -1252,8 +1435,11 @@ s0 = s1; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parsecomma(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
@@ -1263,2 +1449,3 @@ s2.push(s3); | ||
} | ||
s1 = [s1, s2]; | ||
@@ -1278,3 +1465,3 @@ s0 = s1; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1284,2 +1471,3 @@ }; | ||
rule$expects(peg$e8); | ||
if (input.charCodeAt(peg$currPos) === 44) { | ||
@@ -1298,3 +1486,3 @@ s0 = peg$c8; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1305,2 +1493,3 @@ }; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 !== peg$FAILED) { | ||
@@ -1310,4 +1499,4 @@ peg$savedPos = s0; | ||
} | ||
s0 = s1; | ||
return s0; | ||
@@ -1319,3 +1508,3 @@ } | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1326,7 +1515,10 @@ }; | ||
s1 = peg$parsefractionalConstant(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parseexponent(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s1 = [s1, s2]; | ||
@@ -1338,7 +1530,10 @@ s0 = s1; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parseexponent(); | ||
if (s2 !== peg$FAILED) { | ||
@@ -1363,3 +1558,3 @@ s1 = [s1, s2]; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1372,5 +1567,7 @@ }; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 === peg$FAILED) { | ||
s1 = null; | ||
} | ||
if (input.charCodeAt(peg$currPos) === 46) { | ||
@@ -1382,4 +1579,6 @@ s2 = peg$c9; | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsedigitSequence(); | ||
if (s3 !== peg$FAILED) { | ||
@@ -1396,5 +1595,7 @@ peg$savedPos = s0; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 !== peg$FAILED) { | ||
@@ -1407,2 +1608,3 @@ if (input.charCodeAt(peg$currPos) === 46) { | ||
} | ||
if (s2 !== peg$FAILED) { | ||
@@ -1420,4 +1622,4 @@ peg$savedPos = s0; | ||
} | ||
peg$silentFails--; | ||
return s0; | ||
@@ -1429,3 +1631,3 @@ } | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1436,2 +1638,3 @@ }; | ||
rule$expects(peg$e10); | ||
if (peg$r0.test(input.charAt(peg$currPos))) { | ||
@@ -1443,8 +1646,12 @@ s1 = input.charAt(peg$currPos); | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsesign(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = peg$parsedigitSequence(); | ||
if (s3 !== peg$FAILED) { | ||
@@ -1468,3 +1675,3 @@ s1 = [s1, s2, s3]; | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1474,2 +1681,3 @@ }; | ||
rule$expects(peg$e11); | ||
if (peg$r1.test(input.charAt(peg$currPos))) { | ||
@@ -1488,3 +1696,3 @@ s0 = input.charAt(peg$currPos); | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1495,2 +1703,3 @@ }; | ||
s1 = peg$parsedigit(); | ||
if (s1 !== peg$FAILED) { | ||
@@ -1511,3 +1720,3 @@ while (s1 !== peg$FAILED) { | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1517,2 +1726,3 @@ }; | ||
rule$expects(peg$e12); | ||
if (peg$r2.test(input.charAt(peg$currPos))) { | ||
@@ -1531,3 +1741,3 @@ s0 = input.charAt(peg$currPos); | ||
var rule$expects = function rule$expects(expected) { | ||
var rule$expects = function (expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
@@ -1537,2 +1747,3 @@ }; | ||
rule$expects(peg$e13); | ||
if (peg$r3.test(input.charAt(peg$currPos))) { | ||
@@ -1562,7 +1773,6 @@ s0 = input.charAt(peg$currPos); | ||
exports.SyntaxError = peg$SyntaxError; | ||
exports.parse = peg$parse; | ||
exports.default = { | ||
var _default = { | ||
SyntaxError: peg$SyntaxError, | ||
parse: peg$parse | ||
}; | ||
}; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -8,71 +8,23 @@ Object.defineProperty(exports, "__esModule", { | ||
var _fromTransformAttribute = require('./fromTransformAttribute.autogenerated'); | ||
var _fromTransformAttribute = require("./fromTransformAttribute.autogenerated"); | ||
var _translate = require('./translate'); | ||
var _rotate = require('./rotate'); | ||
var _fromObject = require('./fromObject'); | ||
var _scale = require('./scale'); | ||
var _skew = require('./skew'); | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
/** | ||
* Parser for SVG Trasform Attribute http://www.w3.org/TR/SVG/coords.html#TransformAttribute <br/> | ||
* Warning: This should be considered BETA until it is released a stable version of pegjs. | ||
* @param transformString string | ||
* @returns {{descriptors: *, matrices: *}} Parsed matrices | ||
* @param transformString {string} Transform string as defined by w3 Consortium | ||
* @returns {Matrix[]} Array of MatrixDescriptor | ||
* | ||
* @example | ||
* > fromTransformAttribute('translate(-10,-10) scale(2,2) translate(10,10)') | ||
* [ | ||
* { type: 'translate', tx: -10, ty: -10}, | ||
* { type: 'scale', sx: 2, sy: 2 }, | ||
* { type: 'translate', tx: 10, ty: 10} | ||
* ] | ||
* | ||
* > compose(fromDefinition(fromTransformAttribute('translate(-10, -10) scale(10, 10)'))) | ||
* { a: 10, c: 0, e: -10, b: 0, d: 10, f: -10 } | ||
*/ | ||
function fromTransformAttribute(transformString) { | ||
var descriptors = (0, _fromTransformAttribute.parse)(transformString); | ||
var matrices = descriptors.map(convertMatrixDescriptorToMatrix); | ||
return { descriptors: descriptors, matrices: matrices }; | ||
} | ||
function convertMatrixDescriptorToMatrix(matrixDescriptor) { | ||
var hasParam = function hasParam(key) { | ||
return matrixDescriptor.hasOwnProperty(key); | ||
}; | ||
var type = matrixDescriptor.type, | ||
params = _objectWithoutProperties(matrixDescriptor, ['type']); | ||
switch (type) { | ||
case 'matrix': | ||
return (0, _fromObject.fromObject)(params); | ||
case 'translate': | ||
if (hasParam('ty')) { | ||
return (0, _translate.translate)(params.tx, params.ty); | ||
} | ||
return (0, _translate.translate)(params.tx); | ||
case 'scale': | ||
if (hasParam('sy')) { | ||
return (0, _scale.scale)(params.sx, params.sy); | ||
} | ||
return (0, _scale.scale)(params.sx); | ||
case 'rotate': | ||
if (hasParam('cx') && hasParam('cy')) { | ||
return (0, _rotate.rotateDEG)(params.angle, params.cx, params.cy); | ||
} | ||
return (0, _rotate.rotateDEG)(params.angle); | ||
case 'skewX': | ||
return (0, _skew.skewDEG)(params.angle, 0); | ||
case 'skewY': | ||
return (0, _skew.skewDEG)(0, params.angle); | ||
default: | ||
/* istanbul ignore next */ | ||
throw new Error('Unsupported descriptor'); | ||
} | ||
return (0, _fromTransformAttribute.parse)(transformString); | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -8,13 +8,13 @@ Object.defineProperty(exports, "__esModule", { | ||
var _inverse = require('./inverse'); | ||
var _inverse = require("./inverse"); | ||
var _transform = require('./transform'); | ||
var _transform = require("./transform"); | ||
var _smoothMatrix = require('./smoothMatrix'); | ||
var _smoothMatrix = require("./smoothMatrix"); | ||
/** | ||
* Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible. | ||
* @param t1 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the first triangle | ||
* @param t2 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the second triangle | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix which transforms t1 to t2 | ||
* @param t1 {Point[]} Array of points containing the three points for the first triangle | ||
* @param t2 {Point[]} Array of points containing the three points for the second triangle | ||
* @returns {Matrix} Matrix which transforms t1 to t2 | ||
* @throws Exception if the matrix becomes not invertible | ||
@@ -24,20 +24,17 @@ */ | ||
// point p = first point of the triangle | ||
var px1 = t1[0].x != null ? t1[0].x : t1[0][0]; | ||
var py1 = t1[0].y != null ? t1[0].y : t1[0][1]; | ||
var px2 = t2[0].x != null ? t2[0].x : t2[0][0]; | ||
var py2 = t2[0].y != null ? t2[0].y : t2[0][1]; | ||
let px1 = t1[0].x != null ? t1[0].x : t1[0][0]; | ||
let py1 = t1[0].y != null ? t1[0].y : t1[0][1]; | ||
let px2 = t2[0].x != null ? t2[0].x : t2[0][0]; | ||
let py2 = t2[0].y != null ? t2[0].y : t2[0][1]; // point q = second point of the triangle | ||
// point q = second point of the triangle | ||
var qx1 = t1[1].x != null ? t1[1].x : t1[1][0]; | ||
var qy1 = t1[1].y != null ? t1[1].y : t1[1][1]; | ||
var qx2 = t2[1].x != null ? t2[1].x : t2[1][0]; | ||
var qy2 = t2[1].y != null ? t2[1].y : t2[1][1]; | ||
let qx1 = t1[1].x != null ? t1[1].x : t1[1][0]; | ||
let qy1 = t1[1].y != null ? t1[1].y : t1[1][1]; | ||
let qx2 = t2[1].x != null ? t2[1].x : t2[1][0]; | ||
let qy2 = t2[1].y != null ? t2[1].y : t2[1][1]; // point r = third point of the triangle | ||
// point r = third point of the triangle | ||
var rx1 = t1[2].x != null ? t1[2].x : t1[2][0]; | ||
var ry1 = t1[2].y != null ? t1[2].y : t1[2][1]; | ||
var rx2 = t2[2].x != null ? t2[2].x : t2[2][0]; | ||
var ry2 = t2[2].y != null ? t2[2].y : t2[2][1]; | ||
var r1 = { | ||
let rx1 = t1[2].x != null ? t1[2].x : t1[2][0]; | ||
let ry1 = t1[2].y != null ? t1[2].y : t1[2][1]; | ||
let rx2 = t2[2].x != null ? t2[2].x : t2[2][0]; | ||
let ry2 = t2[2].y != null ? t2[2].y : t2[2][1]; | ||
let r1 = { | ||
a: px1 - rx1, | ||
@@ -50,3 +47,3 @@ b: py1 - ry1, | ||
}; | ||
var r2 = { | ||
let r2 = { | ||
a: px2 - rx2, | ||
@@ -59,8 +56,6 @@ b: py2 - ry2, | ||
}; | ||
let inverseR1 = (0, _inverse.inverse)(r1); | ||
let affineMatrix = (0, _transform.transform)([r2, inverseR1]); // round the matrix elements to smooth the finite inversion | ||
var inverseR1 = (0, _inverse.inverse)(r1); | ||
var affineMatrix = (0, _transform.transform)([r2, inverseR1]); | ||
// round the matrix elements to smooth the finite inversion | ||
return (0, _smoothMatrix.smoothMatrix)(affineMatrix); | ||
} |
@@ -7,5 +7,6 @@ "use strict"; | ||
exports.identity = identity; | ||
/** | ||
* Identity matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -12,0 +13,0 @@ function identity() { |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,3 +7,3 @@ Object.defineProperty(exports, "__esModule", { | ||
var _applyToPoint = require('./applyToPoint'); | ||
var _applyToPoint = require("./applyToPoint"); | ||
@@ -14,3 +14,3 @@ Object.keys(_applyToPoint).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _applyToPoint[key]; | ||
@@ -21,3 +21,3 @@ } | ||
var _fromObject = require('./fromObject'); | ||
var _fromObject = require("./fromObject"); | ||
@@ -28,3 +28,3 @@ Object.keys(_fromObject).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _fromObject[key]; | ||
@@ -35,3 +35,3 @@ } | ||
var _fromString = require('./fromString'); | ||
var _fromString = require("./fromString"); | ||
@@ -42,3 +42,3 @@ Object.keys(_fromString).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _fromString[key]; | ||
@@ -49,3 +49,3 @@ } | ||
var _identity = require('./identity'); | ||
var _identity = require("./identity"); | ||
@@ -56,3 +56,3 @@ Object.keys(_identity).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _identity[key]; | ||
@@ -63,3 +63,3 @@ } | ||
var _inverse = require('./inverse'); | ||
var _inverse = require("./inverse"); | ||
@@ -70,3 +70,3 @@ Object.keys(_inverse).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _inverse[key]; | ||
@@ -77,3 +77,3 @@ } | ||
var _isAffineMatrix = require('./isAffineMatrix'); | ||
var _isAffineMatrix = require("./isAffineMatrix"); | ||
@@ -84,3 +84,3 @@ Object.keys(_isAffineMatrix).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _isAffineMatrix[key]; | ||
@@ -91,3 +91,3 @@ } | ||
var _rotate = require('./rotate'); | ||
var _rotate = require("./rotate"); | ||
@@ -98,3 +98,3 @@ Object.keys(_rotate).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _rotate[key]; | ||
@@ -105,3 +105,3 @@ } | ||
var _scale = require('./scale'); | ||
var _scale = require("./scale"); | ||
@@ -112,3 +112,3 @@ Object.keys(_scale).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _scale[key]; | ||
@@ -119,3 +119,3 @@ } | ||
var _shear = require('./shear'); | ||
var _shear = require("./shear"); | ||
@@ -126,3 +126,3 @@ Object.keys(_shear).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _shear[key]; | ||
@@ -133,3 +133,3 @@ } | ||
var _skew = require('./skew'); | ||
var _skew = require("./skew"); | ||
@@ -140,3 +140,3 @@ Object.keys(_skew).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _skew[key]; | ||
@@ -147,3 +147,3 @@ } | ||
var _toString = require('./toString'); | ||
var _toString = require("./toString"); | ||
@@ -154,3 +154,3 @@ Object.keys(_toString).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _toString[key]; | ||
@@ -161,3 +161,3 @@ } | ||
var _transform = require('./transform'); | ||
var _transform = require("./transform"); | ||
@@ -168,3 +168,3 @@ Object.keys(_transform).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _transform[key]; | ||
@@ -175,3 +175,3 @@ } | ||
var _translate = require('./translate'); | ||
var _translate = require("./translate"); | ||
@@ -182,3 +182,3 @@ Object.keys(_translate).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _translate[key]; | ||
@@ -189,3 +189,3 @@ } | ||
var _fromTriangles = require('./fromTriangles'); | ||
var _fromTriangles = require("./fromTriangles"); | ||
@@ -196,3 +196,3 @@ Object.keys(_fromTriangles).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _fromTriangles[key]; | ||
@@ -203,3 +203,3 @@ } | ||
var _smoothMatrix = require('./smoothMatrix'); | ||
var _smoothMatrix = require("./smoothMatrix"); | ||
@@ -210,6 +210,30 @@ Object.keys(_smoothMatrix).forEach(function (key) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _smoothMatrix[key]; | ||
} | ||
}); | ||
}); | ||
var _fromDefinition = require("./fromDefinition"); | ||
Object.keys(_fromDefinition).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _fromDefinition[key]; | ||
} | ||
}); | ||
}); | ||
var _fromTransformAttribute = require("./fromTransformAttribute"); | ||
Object.keys(_fromTransformAttribute).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _fromTransformAttribute[key]; | ||
} | ||
}); | ||
}); |
@@ -7,20 +7,19 @@ "use strict"; | ||
exports.inverse = inverse; | ||
/** | ||
* Calculate a matrix that is the inverse of the provided matrix | ||
* @param matrix Affine matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {Matrix} Inverted Affine Matrix | ||
*/ | ||
function inverse(matrix) { | ||
// http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D | ||
var a = matrix.a, | ||
b = matrix.b, | ||
c = matrix.c, | ||
d = matrix.d, | ||
e = matrix.e, | ||
f = matrix.f; | ||
var denom = a * d - b * c; | ||
let { | ||
a, | ||
b, | ||
c, | ||
d, | ||
e, | ||
f | ||
} = matrix; | ||
let denom = a * d - b * c; | ||
return { | ||
@@ -27,0 +26,0 @@ a: d / denom, |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,20 +6,13 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.isAffineMatrix = isAffineMatrix; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _utils = require("./utils"); | ||
exports.isAffineMatrix = isAffineMatrix; | ||
var isNumeric = function isNumeric(n) { | ||
return typeof n === 'number' && !isNaN(n) && isFinite(n); | ||
}; | ||
var isObject = function isObject(obj) { | ||
return obj != null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; | ||
}; | ||
/** | ||
* Check if the object contain an affine matrix | ||
* @param object | ||
* @return {boolean} | ||
* @param object {Object} Generic Plain Object | ||
* @return {boolean} True if is an object and contains an affine matrix | ||
*/ | ||
function isAffineMatrix(object) { | ||
return isObject(object) && object.hasOwnProperty('a') && isNumeric(object.a) && object.hasOwnProperty('b') && isNumeric(object.b) && object.hasOwnProperty('c') && isNumeric(object.c) && object.hasOwnProperty('d') && isNumeric(object.d) && object.hasOwnProperty('e') && isNumeric(object.e) && object.hasOwnProperty('f') && isNumeric(object.f); | ||
return (0, _utils.isObject)(object) && object.hasOwnProperty('a') && (0, _utils.isNumeric)(object.a) && object.hasOwnProperty('b') && (0, _utils.isNumeric)(object.b) && object.hasOwnProperty('c') && (0, _utils.isNumeric)(object.c) && object.hasOwnProperty('d') && (0, _utils.isNumeric)(object.d) && object.hasOwnProperty('e') && (0, _utils.isNumeric)(object.e) && object.hasOwnProperty('f') && (0, _utils.isNumeric)(object.f); | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,23 +9,25 @@ Object.defineProperty(exports, "__esModule", { | ||
var _utils = require('./utils'); | ||
var _utils = require("./utils"); | ||
var _translate = require('./translate'); | ||
var _translate = require("./translate"); | ||
var _transform = require('./transform'); | ||
var _transform = require("./transform"); | ||
var cos = Math.cos, | ||
sin = Math.sin, | ||
PI = Math.PI; | ||
const { | ||
cos, | ||
sin, | ||
PI | ||
} = Math; | ||
/** | ||
* Calculate a rotation matrix | ||
* @param angle Angle in radians | ||
* @param [cx] If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] If (cx,cy) are supplied the rotate is about this point | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix * | ||
* @param angle {number} Angle in radians | ||
* @param [cx] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function rotate(angle, cx, cy) { | ||
var cosAngle = cos(angle); | ||
var sinAngle = sin(angle); | ||
var rotationMatrix = { | ||
let cosAngle = cos(angle); | ||
let sinAngle = sin(angle); | ||
let rotationMatrix = { | ||
a: cosAngle, | ||
@@ -38,2 +40,3 @@ c: -sinAngle, | ||
}; | ||
if ((0, _utils.isUndefined)(cx) || (0, _utils.isUndefined)(cy)) { | ||
@@ -45,15 +48,13 @@ return rotationMatrix; | ||
} | ||
/** | ||
* Calculate a rotation matrix with a DEG angle | ||
* @param angle Angle in degree | ||
* @param [cx] If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] If (cx,cy) are supplied the rotate is about this point | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param angle {number} Angle in degree | ||
* @param [cx] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function rotateDEG(angle) { | ||
var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; | ||
function rotateDEG(angle, cx = undefined, cy = undefined) { | ||
return rotate(angle * PI / 180, cx, cy); | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -8,13 +8,11 @@ Object.defineProperty(exports, "__esModule", { | ||
var _utils = require('./utils'); | ||
var _utils = require("./utils"); | ||
/** | ||
* Calculate a scaling matrix | ||
* @param sx Scaling on axis x | ||
* @param [sy = sx] Scaling on axis y (default sx) | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param sx {number} Scaling on axis x | ||
* @param [sy = sx] {number} Scaling on axis y (default sx) | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function scale(sx) { | ||
var sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
function scale(sx, sy = undefined) { | ||
if ((0, _utils.isUndefined)(sy)) sy = sx; | ||
@@ -21,0 +19,0 @@ return { |
@@ -7,7 +7,8 @@ "use strict"; | ||
exports.shear = shear; | ||
/** | ||
* Calculate a shear matrix | ||
* @param shx Shear on axis x | ||
* @param shy Shear on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param shx {number} Shear on axis x | ||
* @param shy {number} Shear on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -14,0 +15,0 @@ function shear(shx, shy) { |
@@ -9,9 +9,10 @@ "use strict"; | ||
// https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew | ||
var tan = Math.tan; | ||
const { | ||
tan | ||
} = Math; | ||
/** | ||
* Calculate a skew matrix | ||
* @param ax Skew on axis x | ||
* @param ay Skew on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param ax {number} Skew on axis x | ||
* @param ay {number} Skew on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -29,11 +30,12 @@ | ||
} | ||
/** | ||
* Calculate a skew matrix using DEG angles | ||
* @param ax Skew on axis x | ||
* @param ay Skew on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param ax {number} Skew on axis x | ||
* @param ay {number} Skew on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function skewDEG(ax, ay) { | ||
return skew(ax * Math.PI / 180, ay * Math.PI / 180); | ||
} |
@@ -7,19 +7,18 @@ "use strict"; | ||
exports.smoothMatrix = smoothMatrix; | ||
/** | ||
* Rounds all elements of the given matrix using the given precision | ||
* @param m {{a: number, b: number, c: number, d: number, e: number, f: number}} a matrix to round | ||
* @param [precision] a precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | ||
* @returns {{a: number, b: number, c: number, d: number, e: number, f: number}} the rounded matrix | ||
* @param matrix {Matrix} An affine matrix to round | ||
* @param [precision] {number} A precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | ||
* @returns {Matrix} The rounded Affine Matrix | ||
*/ | ||
function smoothMatrix(m) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10000000000; | ||
function smoothMatrix(matrix, precision = 10000000000) { | ||
return { | ||
a: Math.round(m.a * precision) / precision, | ||
b: Math.round(m.b * precision) / precision, | ||
c: Math.round(m.c * precision) / precision, | ||
d: Math.round(m.d * precision) / precision, | ||
e: Math.round(m.e * precision) / precision, | ||
f: Math.round(m.f * precision) / precision | ||
a: Math.round(matrix.a * precision) / precision, | ||
b: Math.round(matrix.b * precision) / precision, | ||
c: Math.round(matrix.c * precision) / precision, | ||
d: Math.round(matrix.d * precision) / precision, | ||
e: Math.round(matrix.e * precision) / precision, | ||
f: Math.round(matrix.f * precision) / precision | ||
}; | ||
} |
@@ -9,6 +9,7 @@ "use strict"; | ||
exports.toString = toString; | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
@@ -18,19 +19,21 @@ function toCSS(matrix) { | ||
} | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
function toSVG(matrix) { | ||
return toString(matrix); | ||
} | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
function toString(matrix) { | ||
return "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")"; | ||
return `matrix(${matrix.a},${matrix.b},${matrix.c},${matrix.d},${matrix.e},${matrix.f})`; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,19 +9,11 @@ Object.defineProperty(exports, "__esModule", { | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | ||
/** | ||
* Merge multiple matrices into one | ||
* @param matrices {...object} list of matrices | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param matrices {Matrix[]} Array of affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function transform() { | ||
for (var _len = arguments.length, matrices = Array(_len), _key = 0; _key < _len; _key++) { | ||
matrices[_key] = arguments[_key]; | ||
} | ||
function transform(...matrices) { | ||
matrices = Array.isArray(matrices[0]) ? matrices[0] : matrices; | ||
var multiply = function multiply(m1, m2) { | ||
const multiply = (m1, m2) => { | ||
return { | ||
@@ -48,20 +40,16 @@ a: m1.a * m2.a + m1.c * m2.b, | ||
default: | ||
var _matrices = matrices, | ||
_matrices2 = _toArray(_matrices), | ||
m1 = _matrices2[0], | ||
m2 = _matrices2[1], | ||
rest = _matrices2.slice(2); | ||
var m = multiply(m1, m2); | ||
return transform.apply(undefined, [m].concat(_toConsumableArray(rest))); | ||
let [m1, m2, ...rest] = matrices; | ||
let m = multiply(m1, m2); | ||
return transform(m, ...rest); | ||
} | ||
} | ||
/** | ||
* Merge multiple matrices into one (alias of `transform`) | ||
* @param matrices {...object} list of matrices | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* Merge multiple matrices into one | ||
* @param matrices {Matrix[]} Array of matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function compose() { | ||
return transform.apply(undefined, arguments); | ||
function compose(...matrices) { | ||
return transform(...matrices); | ||
} |
@@ -7,11 +7,10 @@ "use strict"; | ||
exports.translate = translate; | ||
/** | ||
* Calculate a translate matrix | ||
* @param tx Translation on axis x | ||
* @param [ty = 0] Translation on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param tx {number} Translation on axis x | ||
* @param [ty = 0] {number} Translation on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function translate(tx) { | ||
var ty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
function translate(tx, ty = 0) { | ||
return { | ||
@@ -18,0 +17,0 @@ a: 1, |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,4 +7,20 @@ Object.defineProperty(exports, "__esModule", { | ||
exports.isUndefined = isUndefined; | ||
exports.isNumeric = isNumeric; | ||
exports.isObject = isObject; | ||
exports.matchesShape = matchesShape; | ||
function isUndefined(val) { | ||
return typeof val === 'undefined'; | ||
} | ||
function isNumeric(n) { | ||
return typeof n === 'number' && !Number.isNaN(n) && Number.isFinite(n); | ||
} | ||
function isObject(obj) { | ||
return typeof obj === 'object' && obj !== null && !Array.isArray(obj); | ||
} | ||
function matchesShape(obj, keys) { | ||
return keys.every(key => key in obj); | ||
} |
@@ -107,5 +107,5 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
* Calculate a point transformed with an affine matrix | ||
* @param matrix Affine matrix | ||
* @param point Point | ||
* @returns {{x: number, y: number} | Array} Point | ||
* @param matrix {Matrix} Affine Matrix | ||
* @param point {Point} Point | ||
* @returns {Point} Point | ||
*/ | ||
@@ -118,9 +118,9 @@ function applyToPoint(matrix, point) { | ||
} | ||
/** | ||
* Calculate an array of points transformed with an affine matrix | ||
* @param matrix Affine matrix | ||
* @param points Array of points | ||
* @returns {array} Array of points | ||
* @param matrix {Matrix} Affine Matrix | ||
* @param points {Point[]} Array of point | ||
* @returns {Point[]} Array of point | ||
*/ | ||
function applyToPoints(matrix, points) { | ||
@@ -134,5 +134,5 @@ return points.map(function (point) { | ||
* Extract an affine matrix from an object that contains a,b,c,d,e,f keys | ||
* Each value could be a float or a string that contains a float | ||
* @param object | ||
* @return {{a: *, b: *, c: *, e: *, d: *, f: *}}} | ||
* Any value could be a float or a string that contains a float | ||
* @param object {Object} Object that contains a,b,c,d,e,f keys | ||
* @return {Matrix} Affine Matrix | ||
*/ | ||
@@ -155,11 +155,15 @@ function fromObject(object) { | ||
var matrixRegex = /^matrix\(\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*\)$/i; | ||
/** | ||
* Parse a string matrix formatted as matrix(a,b,c,d,e,f) | ||
* @param string String with a matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* Parse a string formatted as matrix(a,b,c,d,e,f) | ||
* @param string {string} String with an affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
* | ||
* @example | ||
* > fromString('matrix(1,2,3,4,5,6)') | ||
* {a: 1, b: 2, c: 3, d: 4, c: 5, e: 6} | ||
*/ | ||
function fromString(string) { | ||
var parsed = string.match(matrixRegex); | ||
if (parsed === null || parsed.length < 7) throw new Error("'" + string + "' is not a matrix"); | ||
if (parsed === null || parsed.length < 7) throw new Error("'".concat(string, "' is not a matrix")); | ||
return { | ||
@@ -177,3 +181,3 @@ a: parseFloat(parsed[1]), | ||
* Identity matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -193,8 +197,7 @@ function identity() { | ||
* Calculate a matrix that is the inverse of the provided matrix | ||
* @param matrix Affine matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {Matrix} Inverted Affine Matrix | ||
*/ | ||
function inverse(matrix) { | ||
// http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D | ||
var a = matrix.a, | ||
@@ -206,6 +209,3 @@ b = matrix.b, | ||
f = matrix.f; | ||
var denom = a * d - b * c; | ||
return { | ||
@@ -220,34 +220,39 @@ a: d / denom, | ||
} | ||
// CONCATENATED MODULE: ./src/utils.js | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function isUndefined(val) { | ||
return typeof val === 'undefined'; | ||
} | ||
function isNumeric(n) { | ||
return typeof n === 'number' && !Number.isNaN(n) && Number.isFinite(n); | ||
} | ||
function isObject(obj) { | ||
return _typeof(obj) === 'object' && obj !== null && !Array.isArray(obj); | ||
} | ||
function matchesShape(obj, keys) { | ||
return keys.every(function (key) { | ||
return key in obj; | ||
}); | ||
} | ||
// CONCATENATED MODULE: ./src/isAffineMatrix.js | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var isNumeric = function isNumeric(n) { | ||
return typeof n === 'number' && !isNaN(n) && isFinite(n); | ||
}; | ||
var isObject = function isObject(obj) { | ||
return obj != null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; | ||
}; | ||
/** | ||
* Check if the object contain an affine matrix | ||
* @param object | ||
* @return {boolean} | ||
* @param object {Object} Generic Plain Object | ||
* @return {boolean} True if is an object and contains an affine matrix | ||
*/ | ||
function isAffineMatrix(object) { | ||
return isObject(object) && object.hasOwnProperty('a') && isNumeric(object.a) && object.hasOwnProperty('b') && isNumeric(object.b) && object.hasOwnProperty('c') && isNumeric(object.c) && object.hasOwnProperty('d') && isNumeric(object.d) && object.hasOwnProperty('e') && isNumeric(object.e) && object.hasOwnProperty('f') && isNumeric(object.f); | ||
} | ||
// CONCATENATED MODULE: ./src/utils.js | ||
function isUndefined(val) { | ||
return typeof val === 'undefined'; | ||
} | ||
// CONCATENATED MODULE: ./src/translate.js | ||
/** | ||
* Calculate a translate matrix | ||
* @param tx Translation on axis x | ||
* @param [ty = 0] Translation on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param tx {number} Translation on axis x | ||
* @param [ty = 0] {number} Translation on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function translate(tx) { | ||
var ty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
return { | ||
@@ -263,13 +268,23 @@ a: 1, | ||
// CONCATENATED MODULE: ./src/transform.js | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
/** | ||
* Merge multiple matrices into one | ||
* @param matrices {...object} list of matrices | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param matrices {Matrix[]} Array of affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function transform() { | ||
for (var _len = arguments.length, matrices = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, matrices = new Array(_len), _key = 0; _key < _len; _key++) { | ||
matrices[_key] = arguments[_key]; | ||
@@ -309,13 +324,13 @@ } | ||
var m = multiply(m1, m2); | ||
return transform.apply(undefined, [m].concat(_toConsumableArray(rest))); | ||
return transform.apply(void 0, [m].concat(_toConsumableArray(rest))); | ||
} | ||
} | ||
/** | ||
* Merge multiple matrices into one (alias of `transform`) | ||
* @param matrices {...object} list of matrices | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* Merge multiple matrices into one | ||
* @param matrices {Matrix[]} Array of matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function compose() { | ||
return transform.apply(undefined, arguments); | ||
return transform.apply(void 0, arguments); | ||
} | ||
@@ -326,3 +341,2 @@ // CONCATENATED MODULE: ./src/rotate.js | ||
var cos = Math.cos, | ||
@@ -333,6 +347,6 @@ sin = Math.sin, | ||
* Calculate a rotation matrix | ||
* @param angle Angle in radians | ||
* @param [cx] If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] If (cx,cy) are supplied the rotate is about this point | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix * | ||
* @param angle {number} Angle in radians | ||
* @param [cx] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -351,2 +365,3 @@ | ||
}; | ||
if (isUndefined(cx) || isUndefined(cy)) { | ||
@@ -358,14 +373,13 @@ return rotationMatrix; | ||
} | ||
/** | ||
* Calculate a rotation matrix with a DEG angle | ||
* @param angle Angle in degree | ||
* @param [cx] If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] If (cx,cy) are supplied the rotate is about this point | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param angle {number} Angle in degree | ||
* @param [cx] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function rotateDEG(angle) { | ||
var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; | ||
return rotate(angle * PI / 180, cx, cy); | ||
@@ -375,12 +389,11 @@ } | ||
/** | ||
* Calculate a scaling matrix | ||
* @param sx Scaling on axis x | ||
* @param [sy = sx] Scaling on axis y (default sx) | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param sx {number} Scaling on axis x | ||
* @param [sy = sx] {number} Scaling on axis y (default sx) | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function scale(sx) { | ||
var sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
if (isUndefined(sy)) sy = sx; | ||
@@ -399,5 +412,5 @@ return { | ||
* Calculate a shear matrix | ||
* @param shx Shear on axis x | ||
* @param shy Shear on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param shx {number} Shear on axis x | ||
* @param shy {number} Shear on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -417,8 +430,7 @@ function shear(shx, shy) { | ||
var tan = Math.tan; | ||
/** | ||
* Calculate a skew matrix | ||
* @param ax Skew on axis x | ||
* @param ay Skew on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param ax {number} Skew on axis x | ||
* @param ay {number} Skew on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -436,9 +448,9 @@ | ||
} | ||
/** | ||
* Calculate a skew matrix using DEG angles | ||
* @param ax Skew on axis x | ||
* @param ay Skew on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param ax {number} Skew on axis x | ||
* @param ay {number} Skew on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
function skewDEG(ax, ay) { | ||
@@ -449,5 +461,5 @@ return skew(ax * Math.PI / 180, ay * Math.PI / 180); | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
@@ -457,19 +469,19 @@ function toCSS(matrix) { | ||
} | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
function toSVG(matrix) { | ||
return toString_toString(matrix); | ||
} | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
function toString_toString(matrix) { | ||
return "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")"; | ||
return "matrix(".concat(matrix.a, ",").concat(matrix.b, ",").concat(matrix.c, ",").concat(matrix.d, ",").concat(matrix.e, ",").concat(matrix.f, ")"); | ||
} | ||
@@ -479,16 +491,15 @@ // CONCATENATED MODULE: ./src/smoothMatrix.js | ||
* Rounds all elements of the given matrix using the given precision | ||
* @param m {{a: number, b: number, c: number, d: number, e: number, f: number}} a matrix to round | ||
* @param [precision] a precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | ||
* @returns {{a: number, b: number, c: number, d: number, e: number, f: number}} the rounded matrix | ||
* @param matrix {Matrix} An affine matrix to round | ||
* @param [precision] {number} A precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | ||
* @returns {Matrix} The rounded Affine Matrix | ||
*/ | ||
function smoothMatrix(m) { | ||
function smoothMatrix(matrix) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10000000000; | ||
return { | ||
a: Math.round(m.a * precision) / precision, | ||
b: Math.round(m.b * precision) / precision, | ||
c: Math.round(m.c * precision) / precision, | ||
d: Math.round(m.d * precision) / precision, | ||
e: Math.round(m.e * precision) / precision, | ||
f: Math.round(m.f * precision) / precision | ||
a: Math.round(matrix.a * precision) / precision, | ||
b: Math.round(matrix.b * precision) / precision, | ||
c: Math.round(matrix.c * precision) / precision, | ||
d: Math.round(matrix.d * precision) / precision, | ||
e: Math.round(matrix.e * precision) / precision, | ||
f: Math.round(matrix.f * precision) / precision | ||
}; | ||
@@ -500,10 +511,10 @@ } | ||
/** | ||
* Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible. | ||
* @param t1 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the first triangle | ||
* @param t2 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the second triangle | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix which transforms t1 to t2 | ||
* @param t1 {Point[]} Array of points containing the three points for the first triangle | ||
* @param t2 {Point[]} Array of points containing the three points for the second triangle | ||
* @returns {Matrix} Matrix which transforms t1 to t2 | ||
* @throws Exception if the matrix becomes not invertible | ||
*/ | ||
function fromTriangles(t1, t2) { | ||
@@ -514,11 +525,9 @@ // point p = first point of the triangle | ||
var px2 = t2[0].x != null ? t2[0].x : t2[0][0]; | ||
var py2 = t2[0].y != null ? t2[0].y : t2[0][1]; | ||
var py2 = t2[0].y != null ? t2[0].y : t2[0][1]; // point q = second point of the triangle | ||
// point q = second point of the triangle | ||
var qx1 = t1[1].x != null ? t1[1].x : t1[1][0]; | ||
var qy1 = t1[1].y != null ? t1[1].y : t1[1][1]; | ||
var qx2 = t2[1].x != null ? t2[1].x : t2[1][0]; | ||
var qy2 = t2[1].y != null ? t2[1].y : t2[1][1]; | ||
var qy2 = t2[1].y != null ? t2[1].y : t2[1][1]; // point r = third point of the triangle | ||
// point r = third point of the triangle | ||
var rx1 = t1[2].x != null ? t1[2].x : t1[2][0]; | ||
@@ -528,3 +537,2 @@ var ry1 = t1[2].y != null ? t1[2].y : t1[2][1]; | ||
var ry2 = t2[2].y != null ? t2[2].y : t2[2][1]; | ||
var r1 = { | ||
@@ -546,9 +554,1758 @@ a: px1 - rx1, | ||
}; | ||
var inverseR1 = inverse(r1); | ||
var affineMatrix = transform([r2, inverseR1]); | ||
var affineMatrix = transform([r2, inverseR1]); // round the matrix elements to smooth the finite inversion | ||
// round the matrix elements to smooth the finite inversion | ||
return smoothMatrix(affineMatrix); | ||
} | ||
// CONCATENATED MODULE: ./src/fromDefinition.js | ||
/** | ||
* Converts array of matrix descriptor to array of matrix | ||
* @param definitionOrArrayOfDefinition {Object[]} Array of object describing the matrix | ||
* @returns {Matrix[]} Array of matrix | ||
* | ||
* @example | ||
* > fromDefinition([ | ||
* { type: 'matrix', a:1, b:2, c:3, d:4, e:5, f:6 }, | ||
* { type: 'translate', tx: 10, ty: 20 }, | ||
* { type: 'scale', sx: 2, sy: 4 }, | ||
* { type: 'rotate', angle: 90, sx: 50, sy: 25 }, | ||
* { type: 'skewX', angle: 45 }, | ||
* { type: 'skewY', angle: 45 }, | ||
* { type: 'shear', shx: 10, shy: 20} | ||
* ]) | ||
* | ||
* [ | ||
* { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }, | ||
* { a: 1, c: 0, e: 10, b: 0, d: 1, f: 20 }, | ||
* { a: 2, c: 0, e: 0, b: 0, d: 4, f: 0 }, | ||
* { a: 6.123, c: -1, e: 0, b: 1, d: 6.123, f: 0 }, | ||
* { a: 1, c: 0.99.., e: 0, b: 0, d: 1, f: 0 }, | ||
* { a: 1, c: 0, e: 0, b: 0.99, d: 1, f: 0 }, | ||
* { a: 1, c: 10, e: 0, b: 20, d: 1, f: 0 } | ||
* ] | ||
**/ | ||
function fromDefinition(definitionOrArrayOfDefinition) { | ||
return Array.isArray(definitionOrArrayOfDefinition) ? definitionOrArrayOfDefinition.map(mapper) : mapper(definitionOrArrayOfDefinition); | ||
function mapper(descriptor) { | ||
switch (descriptor.type) { | ||
case 'matrix': | ||
if ('a' in descriptor && 'b' in descriptor && 'c' in descriptor && 'd' in descriptor && 'e' in descriptor && 'f' in descriptor) { | ||
return fromObject(descriptor); | ||
} else { | ||
throw new Error('MISSING_MANDATORY_PARAM'); | ||
} | ||
case 'translate': | ||
if (!('tx' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM'); | ||
if ('ty' in descriptor) return translate(descriptor.tx, descriptor.ty); | ||
return translate(descriptor.tx); | ||
case 'scale': | ||
if (!('sx' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM'); | ||
if ('sy' in descriptor) return scale(descriptor.sx, descriptor.sy); | ||
return scale(descriptor.sx); | ||
case 'rotate': | ||
if (!('angle' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM'); | ||
if ('cx' in descriptor && 'cy' in descriptor) { | ||
return rotateDEG(descriptor.angle, descriptor.cx, descriptor.cy); | ||
} | ||
return rotateDEG(descriptor.angle); | ||
case 'skewX': | ||
if (!('angle' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM'); | ||
return skewDEG(descriptor.angle, 0); | ||
case 'skewY': | ||
if (!('angle' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM'); | ||
return skewDEG(0, descriptor.angle); | ||
case 'shear': | ||
if (!('shx' in descriptor && 'shy' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM'); | ||
return shear(descriptor.shx, descriptor.shy); | ||
default: | ||
throw new Error('UNSUPPORTED_DESCRIPTOR'); | ||
} | ||
} | ||
} | ||
// CONCATENATED MODULE: ./src/fromTransformAttribute.autogenerated.js | ||
// Generated by PEG.js v0.11.0-master.30f3260, https://pegjs.org/ | ||
function peg$subclass(child, parent) { | ||
function C() { | ||
this.constructor = child; | ||
} | ||
C.prototype = parent.prototype; | ||
child.prototype = new C(); | ||
} | ||
function peg$SyntaxError(message, expected, found, location) { | ||
this.message = message; | ||
this.expected = expected; | ||
this.found = found; | ||
this.location = location; | ||
this.name = "SyntaxError"; // istanbul ignore next | ||
if (typeof Error.captureStackTrace === "function") { | ||
Error.captureStackTrace(this, peg$SyntaxError); | ||
} | ||
} | ||
peg$subclass(peg$SyntaxError, Error); | ||
peg$SyntaxError.buildMessage = function (expected, found) { | ||
var DESCRIBE_EXPECTATION_FNS = { | ||
literal: function literal(expectation) { | ||
return "\"" + literalEscape(expectation.text) + "\""; | ||
}, | ||
"class": function _class(expectation) { | ||
var escapedParts = expectation.parts.map(function (part) { | ||
return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part); | ||
}); | ||
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; | ||
}, | ||
any: function any() { | ||
return "any character"; | ||
}, | ||
end: function end() { | ||
return "end of input"; | ||
}, | ||
other: function other(expectation) { | ||
return expectation.description; | ||
}, | ||
not: function not(expectation) { | ||
return "not " + describeExpectation(expectation.expected); | ||
} | ||
}; | ||
function hex(ch) { | ||
return ch.charCodeAt(0).toString(16).toUpperCase(); | ||
} | ||
function literalEscape(s) { | ||
return s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function (ch) { | ||
return "\\x0" + hex(ch); | ||
}).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { | ||
return "\\x" + hex(ch); | ||
}); | ||
} | ||
function classEscape(s) { | ||
return s.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, function (ch) { | ||
return "\\x0" + hex(ch); | ||
}).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { | ||
return "\\x" + hex(ch); | ||
}); | ||
} | ||
function describeExpectation(expectation) { | ||
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); | ||
} | ||
function describeExpected(expected) { | ||
var descriptions = expected.map(describeExpectation); | ||
var i, j; | ||
descriptions.sort(); | ||
if (descriptions.length > 0) { | ||
for (i = 1, j = 1; i < descriptions.length; i++) { | ||
if (descriptions[i - 1] !== descriptions[i]) { | ||
descriptions[j] = descriptions[i]; | ||
j++; | ||
} | ||
} | ||
descriptions.length = j; | ||
} | ||
switch (descriptions.length) { | ||
case 1: | ||
return descriptions[0]; | ||
case 2: | ||
return descriptions[0] + " or " + descriptions[1]; | ||
default: | ||
return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1]; | ||
} | ||
} | ||
function describeFound(found) { | ||
return found ? "\"" + literalEscape(found) + "\"" : "end of input"; | ||
} | ||
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; | ||
}; | ||
function peg$parse(input, options) { | ||
options = options !== undefined ? options : {}; | ||
var peg$FAILED = {}; | ||
var peg$startRuleFunctions = { | ||
transformList: peg$parsetransformList | ||
}; | ||
var peg$startRuleFunction = peg$parsetransformList; | ||
var peg$c0 = "matrix"; | ||
var peg$c1 = "("; | ||
var peg$c2 = ")"; | ||
var peg$c3 = "translate"; | ||
var peg$c4 = "scale"; | ||
var peg$c5 = "rotate"; | ||
var peg$c6 = "skewX"; | ||
var peg$c7 = "skewY"; | ||
var peg$c8 = ","; | ||
var peg$c9 = "."; | ||
var peg$r0 = /^[eE]/; | ||
var peg$r1 = /^[+\-]/; | ||
var peg$r2 = /^[0-9]/; | ||
var peg$r3 = /^[ \t\r\n]/; | ||
var peg$e0 = peg$literalExpectation("matrix", false); | ||
var peg$e1 = peg$literalExpectation("(", false); | ||
var peg$e2 = peg$literalExpectation(")", false); | ||
var peg$e3 = peg$literalExpectation("translate", false); | ||
var peg$e4 = peg$literalExpectation("scale", false); | ||
var peg$e5 = peg$literalExpectation("rotate", false); | ||
var peg$e6 = peg$literalExpectation("skewX", false); | ||
var peg$e7 = peg$literalExpectation("skewY", false); | ||
var peg$e8 = peg$literalExpectation(",", false); | ||
var peg$e9 = peg$otherExpectation("fractionalConstant"); | ||
var peg$e10 = peg$classExpectation(["e", "E"], false, false); | ||
var peg$e11 = peg$classExpectation(["+", "-"], false, false); | ||
var peg$e12 = peg$classExpectation([["0", "9"]], false, false); | ||
var peg$e13 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); | ||
var peg$f0 = function peg$f0(ts) { | ||
return ts; | ||
}; | ||
var peg$f1 = function peg$f1(t, ts) { | ||
return t.concat(ts); | ||
}; | ||
var peg$f2 = function peg$f2(a, b, c, d, e, f) { | ||
return [{ | ||
type: 'matrix', | ||
a: a, | ||
b: b, | ||
c: c, | ||
d: d, | ||
e: e, | ||
f: f | ||
}]; | ||
}; | ||
var peg$f3 = function peg$f3(tx, ty) { | ||
var t = { | ||
type: 'translate', | ||
tx: tx | ||
}; | ||
if (ty) t.ty = ty; | ||
return [t]; | ||
}; | ||
var peg$f4 = function peg$f4(sx, sy) { | ||
var s = { | ||
type: 'scale', | ||
sx: sx | ||
}; | ||
if (sy) s.sy = sy; | ||
return [s]; | ||
}; | ||
var peg$f5 = function peg$f5(angle, c) { | ||
var r = { | ||
type: 'rotate', | ||
angle: angle | ||
}; | ||
if (c) { | ||
r.cx = c[0]; | ||
r.cy = c[1]; | ||
} | ||
return [r]; | ||
}; | ||
var peg$f6 = function peg$f6(angle) { | ||
return [{ | ||
type: 'skewX', | ||
angle: angle | ||
}]; | ||
}; | ||
var peg$f7 = function peg$f7(angle) { | ||
return [{ | ||
type: 'skewY', | ||
angle: angle | ||
}]; | ||
}; | ||
var peg$f8 = function peg$f8(f) { | ||
return parseFloat(f.join("")); | ||
}; | ||
var peg$f9 = function peg$f9(i) { | ||
return parseInt(i.join("")); | ||
}; | ||
var peg$f10 = function peg$f10(n) { | ||
return n; | ||
}; | ||
var peg$f11 = function peg$f11(n1, n2) { | ||
return [n1, n2]; | ||
}; | ||
var peg$f12 = function peg$f12(ds) { | ||
return ds.join(""); | ||
}; | ||
var peg$f13 = function peg$f13(d1, d2) { | ||
return [d1 ? d1.join("") : null, ".", d2.join("")].join(""); | ||
}; | ||
var peg$f14 = function peg$f14(d) { | ||
return d.join(""); | ||
}; | ||
var peg$currPos = 0; | ||
var peg$savedPos = 0; | ||
var peg$posDetailsCache = [{ | ||
line: 1, | ||
column: 1 | ||
}]; | ||
var peg$expected = []; | ||
var peg$silentFails = 0; | ||
var peg$result; | ||
if ("startRule" in options) { | ||
if (!(options.startRule in peg$startRuleFunctions)) { | ||
throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); | ||
} | ||
peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; | ||
} | ||
function text() { | ||
return input.substring(peg$savedPos, peg$currPos); | ||
} | ||
function offset() { | ||
return peg$savedPos; | ||
} | ||
function range() { | ||
return [peg$savedPos, peg$currPos]; | ||
} | ||
function location() { | ||
return peg$computeLocation(peg$savedPos, peg$currPos); | ||
} | ||
function expected(description, location) { | ||
location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos); | ||
throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location); | ||
} | ||
function error(message, location) { | ||
location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos); | ||
throw peg$buildSimpleError(message, location); | ||
} | ||
function peg$literalExpectation(text, ignoreCase) { | ||
return { | ||
type: "literal", | ||
text: text, | ||
ignoreCase: ignoreCase | ||
}; | ||
} | ||
function peg$classExpectation(parts, inverted, ignoreCase) { | ||
return { | ||
type: "class", | ||
parts: parts, | ||
inverted: inverted, | ||
ignoreCase: ignoreCase | ||
}; | ||
} | ||
function peg$anyExpectation() { | ||
return { | ||
type: "any" | ||
}; | ||
} | ||
function peg$endExpectation() { | ||
return { | ||
type: "end" | ||
}; | ||
} | ||
function peg$otherExpectation(description) { | ||
return { | ||
type: "other", | ||
description: description | ||
}; | ||
} | ||
function peg$computePosDetails(pos) { | ||
var details = peg$posDetailsCache[pos]; | ||
var p; | ||
if (details) { | ||
return details; | ||
} else { | ||
p = pos - 1; | ||
while (!peg$posDetailsCache[p]) { | ||
p--; | ||
} | ||
details = peg$posDetailsCache[p]; | ||
details = { | ||
line: details.line, | ||
column: details.column | ||
}; | ||
while (p < pos) { | ||
if (input.charCodeAt(p) === 10) { | ||
details.line++; | ||
details.column = 1; | ||
} else { | ||
details.column++; | ||
} | ||
p++; | ||
} | ||
peg$posDetailsCache[pos] = details; | ||
return details; | ||
} | ||
} | ||
var peg$VALIDFILENAME = typeof options.filename === "string" && options.filename.length > 0; | ||
function peg$computeLocation(startPos, endPos) { | ||
var loc = {}; | ||
if (peg$VALIDFILENAME) loc.filename = options.filename; | ||
var startPosDetails = peg$computePosDetails(startPos); | ||
loc.start = { | ||
offset: startPos, | ||
line: startPosDetails.line, | ||
column: startPosDetails.column | ||
}; | ||
var endPosDetails = peg$computePosDetails(endPos); | ||
loc.end = { | ||
offset: endPos, | ||
line: endPosDetails.line, | ||
column: endPosDetails.column | ||
}; | ||
return loc; | ||
} | ||
function peg$begin() { | ||
peg$expected.push({ | ||
pos: peg$currPos, | ||
variants: [] | ||
}); | ||
} | ||
function peg$expect(expected) { | ||
var top = peg$expected[peg$expected.length - 1]; | ||
if (peg$currPos < top.pos) { | ||
return; | ||
} | ||
if (peg$currPos > top.pos) { | ||
top.pos = peg$currPos; | ||
top.variants = []; | ||
} | ||
top.variants.push(expected); | ||
} | ||
function peg$end(invert) { | ||
var expected = peg$expected.pop(); | ||
var top = peg$expected[peg$expected.length - 1]; | ||
var variants = expected.variants; | ||
if (top.pos !== expected.pos) { | ||
return; | ||
} | ||
if (invert) { | ||
variants = variants.map(function (e) { | ||
return e.type === "not" ? e.expected : { | ||
type: "not", | ||
expected: e | ||
}; | ||
}); | ||
} | ||
Array.prototype.push.apply(top.variants, variants); | ||
} | ||
function peg$buildSimpleError(message, location) { | ||
return new peg$SyntaxError(message, null, null, location); | ||
} | ||
function peg$buildStructuredError(expected, found, location) { | ||
return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location); | ||
} | ||
function peg$buildError() { | ||
var expected = peg$expected[0]; | ||
var failPos = expected.pos; | ||
return peg$buildStructuredError(expected.variants, failPos < input.length ? input.charAt(failPos) : null, failPos < input.length ? peg$computeLocation(failPos, failPos + 1) : peg$computeLocation(failPos, failPos)); | ||
} | ||
function peg$parsetransformList() { | ||
var s0, s1, s2, s3, s4; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = []; | ||
s2 = peg$parsewsp(); | ||
while (s2 !== peg$FAILED) { | ||
s1.push(s2); | ||
s2 = peg$parsewsp(); | ||
} | ||
s2 = peg$parsetransforms(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = []; | ||
s4 = peg$parsewsp(); | ||
while (s4 !== peg$FAILED) { | ||
s3.push(s4); | ||
s4 = peg$parsewsp(); | ||
} | ||
peg$savedPos = s0; | ||
s0 = peg$f0(s2); | ||
return s0; | ||
} | ||
function peg$parsetransforms() { | ||
var s0, s1, s2, s3; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = peg$parsetransform(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsecommaWsp(); | ||
if (s3 !== peg$FAILED) { | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsecommaWsp(); | ||
} | ||
} else { | ||
s2 = peg$FAILED; | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsetransforms(); | ||
if (s3 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f1(s1, s3); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parsetransform(); | ||
} | ||
return s0; | ||
} | ||
function peg$parsetransform() { | ||
var s0; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$parsematrix(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parsetranslate(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parsescale(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parserotate(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseskewX(); | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseskewY(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return s0; | ||
} | ||
function peg$parsematrix() { | ||
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
rule$expects(peg$e0); | ||
if (input.substr(peg$currPos, 6) === peg$c0) { | ||
s1 = peg$c0; | ||
peg$currPos += 6; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s3 = peg$c1; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
s4.push(s5); | ||
s5 = peg$parsewsp(); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWsp(); | ||
if (s6 !== peg$FAILED) { | ||
s7 = peg$parsenumber(); | ||
if (s7 !== peg$FAILED) { | ||
s8 = peg$parsecommaWsp(); | ||
if (s8 !== peg$FAILED) { | ||
s9 = peg$parsenumber(); | ||
if (s9 !== peg$FAILED) { | ||
s10 = peg$parsecommaWsp(); | ||
if (s10 !== peg$FAILED) { | ||
s11 = peg$parsenumber(); | ||
if (s11 !== peg$FAILED) { | ||
s12 = peg$parsecommaWsp(); | ||
if (s12 !== peg$FAILED) { | ||
s13 = peg$parsenumber(); | ||
if (s13 !== peg$FAILED) { | ||
s14 = peg$parsecommaWsp(); | ||
if (s14 !== peg$FAILED) { | ||
s15 = peg$parsenumber(); | ||
if (s15 !== peg$FAILED) { | ||
s16 = []; | ||
s17 = peg$parsewsp(); | ||
while (s17 !== peg$FAILED) { | ||
s16.push(s17); | ||
s17 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s17 = peg$c2; | ||
peg$currPos++; | ||
} else { | ||
s17 = peg$FAILED; | ||
} | ||
if (s17 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f2(s5, s7, s9, s11, s13, s15); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsetranslate() { | ||
var s0, s1, s2, s3, s4, s5, s6, s7, s8; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
rule$expects(peg$e3); | ||
if (input.substr(peg$currPos, 9) === peg$c3) { | ||
s1 = peg$c3; | ||
peg$currPos += 9; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s3 = peg$c1; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
s4.push(s5); | ||
s5 = peg$parsewsp(); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWspNumber(); | ||
if (s6 === peg$FAILED) { | ||
s6 = null; | ||
} | ||
s7 = []; | ||
s8 = peg$parsewsp(); | ||
while (s8 !== peg$FAILED) { | ||
s7.push(s8); | ||
s8 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s8 = peg$c2; | ||
peg$currPos++; | ||
} else { | ||
s8 = peg$FAILED; | ||
} | ||
if (s8 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f3(s5, s6); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsescale() { | ||
var s0, s1, s2, s3, s4, s5, s6, s7, s8; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
rule$expects(peg$e4); | ||
if (input.substr(peg$currPos, 5) === peg$c4) { | ||
s1 = peg$c4; | ||
peg$currPos += 5; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s3 = peg$c1; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
s4.push(s5); | ||
s5 = peg$parsewsp(); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWspNumber(); | ||
if (s6 === peg$FAILED) { | ||
s6 = null; | ||
} | ||
s7 = []; | ||
s8 = peg$parsewsp(); | ||
while (s8 !== peg$FAILED) { | ||
s7.push(s8); | ||
s8 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s8 = peg$c2; | ||
peg$currPos++; | ||
} else { | ||
s8 = peg$FAILED; | ||
} | ||
if (s8 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f4(s5, s6); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parserotate() { | ||
var s0, s1, s2, s3, s4, s5, s6, s7, s8; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
rule$expects(peg$e5); | ||
if (input.substr(peg$currPos, 6) === peg$c5) { | ||
s1 = peg$c5; | ||
peg$currPos += 6; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s3 = peg$c1; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
s4.push(s5); | ||
s5 = peg$parsewsp(); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = peg$parsecommaWspTwoNumbers(); | ||
if (s6 === peg$FAILED) { | ||
s6 = null; | ||
} | ||
s7 = []; | ||
s8 = peg$parsewsp(); | ||
while (s8 !== peg$FAILED) { | ||
s7.push(s8); | ||
s8 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s8 = peg$c2; | ||
peg$currPos++; | ||
} else { | ||
s8 = peg$FAILED; | ||
} | ||
if (s8 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f5(s5, s6); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parseskewX() { | ||
var s0, s1, s2, s3, s4, s5, s6, s7; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
rule$expects(peg$e6); | ||
if (input.substr(peg$currPos, 5) === peg$c6) { | ||
s1 = peg$c6; | ||
peg$currPos += 5; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s3 = peg$c1; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
s4.push(s5); | ||
s5 = peg$parsewsp(); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = []; | ||
s7 = peg$parsewsp(); | ||
while (s7 !== peg$FAILED) { | ||
s6.push(s7); | ||
s7 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s7 = peg$c2; | ||
peg$currPos++; | ||
} else { | ||
s7 = peg$FAILED; | ||
} | ||
if (s7 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f6(s5); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parseskewY() { | ||
var s0, s1, s2, s3, s4, s5, s6, s7; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
rule$expects(peg$e7); | ||
if (input.substr(peg$currPos, 5) === peg$c7) { | ||
s1 = peg$c7; | ||
peg$currPos += 5; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e1); | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s3 = peg$c1; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = []; | ||
s5 = peg$parsewsp(); | ||
while (s5 !== peg$FAILED) { | ||
s4.push(s5); | ||
s5 = peg$parsewsp(); | ||
} | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
s6 = []; | ||
s7 = peg$parsewsp(); | ||
while (s7 !== peg$FAILED) { | ||
s6.push(s7); | ||
s7 = peg$parsewsp(); | ||
} | ||
rule$expects(peg$e2); | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s7 = peg$c2; | ||
peg$currPos++; | ||
} else { | ||
s7 = peg$FAILED; | ||
} | ||
if (s7 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f7(s5); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsenumber() { | ||
var s0, s1, s2, s3; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = peg$currPos; | ||
s2 = peg$parsesign(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = peg$parsefloatingPointConstant(); | ||
if (s3 !== peg$FAILED) { | ||
s2 = [s2, s3]; | ||
s1 = s2; | ||
} else { | ||
peg$currPos = s1; | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$f8(s1); | ||
} | ||
s0 = s1; | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$currPos; | ||
s2 = peg$parsesign(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = peg$parseintegerConstant(); | ||
if (s3 !== peg$FAILED) { | ||
s2 = [s2, s3]; | ||
s1 = s2; | ||
} else { | ||
peg$currPos = s1; | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$f9(s1); | ||
} | ||
s0 = s1; | ||
} | ||
return s0; | ||
} | ||
function peg$parsecommaWspNumber() { | ||
var s0, s1, s2; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = peg$parsecommaWsp(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsenumber(); | ||
if (s2 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f10(s2); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsecommaWspTwoNumbers() { | ||
var s0, s1, s2, s3, s4; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = peg$parsecommaWsp(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsenumber(); | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsecommaWsp(); | ||
if (s3 !== peg$FAILED) { | ||
s4 = peg$parsenumber(); | ||
if (s4 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f11(s2, s4); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsecommaWsp() { | ||
var s0, s1, s2, s3, s4; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = []; | ||
s2 = peg$parsewsp(); | ||
if (s2 !== peg$FAILED) { | ||
while (s2 !== peg$FAILED) { | ||
s1.push(s2); | ||
s2 = peg$parsewsp(); | ||
} | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsecomma(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = []; | ||
s4 = peg$parsewsp(); | ||
while (s4 !== peg$FAILED) { | ||
s3.push(s4); | ||
s4 = peg$parsewsp(); | ||
} | ||
s1 = [s1, s2, s3]; | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parsecomma(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = []; | ||
s3 = peg$parsewsp(); | ||
while (s3 !== peg$FAILED) { | ||
s2.push(s3); | ||
s3 = peg$parsewsp(); | ||
} | ||
s1 = [s1, s2]; | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} | ||
return s0; | ||
} | ||
function peg$parsecomma() { | ||
var s0; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
rule$expects(peg$e8); | ||
if (input.charCodeAt(peg$currPos) === 44) { | ||
s0 = peg$c8; | ||
peg$currPos++; | ||
} else { | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parseintegerConstant() { | ||
var s0, s1; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$f12(s1); | ||
} | ||
s0 = s1; | ||
return s0; | ||
} | ||
function peg$parsefloatingPointConstant() { | ||
var s0, s1, s2; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
s1 = peg$parsefractionalConstant(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parseexponent(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s1 = [s1, s2]; | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parseexponent(); | ||
if (s2 !== peg$FAILED) { | ||
s1 = [s1, s2]; | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} | ||
return s0; | ||
} | ||
function peg$parsefractionalConstant() { | ||
var s0, s1, s2, s3; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
rule$expects(peg$e9); | ||
peg$silentFails++; | ||
s0 = peg$currPos; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 === peg$FAILED) { | ||
s1 = null; | ||
} | ||
if (input.charCodeAt(peg$currPos) === 46) { | ||
s2 = peg$c9; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsedigitSequence(); | ||
if (s3 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f13(s1, s3); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parsedigitSequence(); | ||
if (s1 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 46) { | ||
s2 = peg$c9; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
} | ||
if (s2 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s0 = peg$f14(s1); | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} | ||
peg$silentFails--; | ||
return s0; | ||
} | ||
function peg$parseexponent() { | ||
var s0, s1, s2, s3; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = peg$currPos; | ||
rule$expects(peg$e10); | ||
if (peg$r0.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
peg$currPos++; | ||
} else { | ||
s1 = peg$FAILED; | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parsesign(); | ||
if (s2 === peg$FAILED) { | ||
s2 = null; | ||
} | ||
s3 = peg$parsedigitSequence(); | ||
if (s3 !== peg$FAILED) { | ||
s1 = [s1, s2, s3]; | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsesign() { | ||
var s0; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
rule$expects(peg$e11); | ||
if (peg$r1.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
peg$currPos++; | ||
} else { | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsedigitSequence() { | ||
var s0, s1; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
s0 = []; | ||
s1 = peg$parsedigit(); | ||
if (s1 !== peg$FAILED) { | ||
while (s1 !== peg$FAILED) { | ||
s0.push(s1); | ||
s1 = peg$parsedigit(); | ||
} | ||
} else { | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsedigit() { | ||
var s0; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
rule$expects(peg$e12); | ||
if (peg$r2.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
peg$currPos++; | ||
} else { | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
function peg$parsewsp() { | ||
var s0; | ||
var rule$expects = function rule$expects(expected) { | ||
if (peg$silentFails === 0) peg$expect(expected); | ||
}; | ||
rule$expects(peg$e13); | ||
if (peg$r3.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
peg$currPos++; | ||
} else { | ||
s0 = peg$FAILED; | ||
} | ||
return s0; | ||
} | ||
peg$begin(); | ||
peg$result = peg$startRuleFunction(); | ||
if (peg$result !== peg$FAILED && peg$currPos === input.length) { | ||
return peg$result; | ||
} else { | ||
if (peg$result !== peg$FAILED && peg$currPos < input.length) { | ||
peg$expect(peg$endExpectation()); | ||
} | ||
throw peg$buildError(); | ||
} | ||
} | ||
/* harmony default export */ var fromTransformAttribute_autogenerated = ({ | ||
SyntaxError: peg$SyntaxError, | ||
parse: peg$parse | ||
}); | ||
// CONCATENATED MODULE: ./src/fromTransformAttribute.js | ||
/** | ||
* Parser for SVG Trasform Attribute http://www.w3.org/TR/SVG/coords.html#TransformAttribute <br/> | ||
* Warning: This should be considered BETA until it is released a stable version of pegjs. | ||
* @param transformString {string} Transform string as defined by w3 Consortium | ||
* @returns {Matrix[]} Array of MatrixDescriptor | ||
* | ||
* @example | ||
* > fromTransformAttribute('translate(-10,-10) scale(2,2) translate(10,10)') | ||
* [ | ||
* { type: 'translate', tx: -10, ty: -10}, | ||
* { type: 'scale', sx: 2, sy: 2 }, | ||
* { type: 'translate', tx: 10, ty: 10} | ||
* ] | ||
* | ||
* > compose(fromDefinition(fromTransformAttribute('translate(-10, -10) scale(10, 10)'))) | ||
* { a: 10, c: 0, e: -10, b: 0, d: 10, f: -10 } | ||
*/ | ||
function fromTransformAttribute(transformString) { | ||
return peg$parse(transformString); | ||
} | ||
// CONCATENATED MODULE: ./src/index.js | ||
@@ -576,2 +2333,4 @@ /* concated harmony reexport applyToPoint */__webpack_require__.d(__webpack_exports__, "applyToPoint", function() { return applyToPoint; }); | ||
/* concated harmony reexport smoothMatrix */__webpack_require__.d(__webpack_exports__, "smoothMatrix", function() { return smoothMatrix; }); | ||
/* concated harmony reexport fromDefinition */__webpack_require__.d(__webpack_exports__, "fromDefinition", function() { return fromDefinition; }); | ||
/* concated harmony reexport fromTransformAttribute */__webpack_require__.d(__webpack_exports__, "fromTransformAttribute", function() { return fromTransformAttribute; }); | ||
@@ -593,2 +2352,4 @@ | ||
/***/ }) | ||
@@ -595,0 +2356,0 @@ /******/ ]); |
@@ -1,2 +0,2 @@ | ||
!function(n,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.TransformationMatrix=r():n.TransformationMatrix=r()}(window,function(){return function(n){var r={};function t(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=n,t.c=r,t.d=function(n,r,e){t.o(n,r)||Object.defineProperty(n,r,{enumerable:!0,get:e})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,r){if(1&r&&(n=t(n)),8&r)return n;if(4&r&&"object"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(t.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:n}),2&r&&"string"!=typeof n)for(var o in n)t.d(e,o,function(r){return n[r]}.bind(null,o));return e},t.n=function(n){var r=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(r,"a",r),r},t.o=function(n,r){return Object.prototype.hasOwnProperty.call(n,r)},t.p="",t(t.s=0)}([function(n,r,t){"use strict";function e(n,r){return Array.isArray(r)?[n.a*r[0]+n.c*r[1]+n.e,n.b*r[0]+n.d*r[1]+n.f]:{x:n.a*r.x+n.c*r.y+n.e,y:n.b*r.x+n.d*r.y+n.f}}function o(n,r){return r.map(function(r){return e(n,r)})}function u(n){return{a:parseFloat(n.a),b:parseFloat(n.b),c:parseFloat(n.c),d:parseFloat(n.d),e:parseFloat(n.e),f:parseFloat(n.f)}}t.r(r);var a=/^matrix\(\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*\)$/i;function i(n){var r=n.match(a);if(null===r||r.length<7)throw new Error("'"+n+"' is not a matrix");return{a:parseFloat(r[1]),b:parseFloat(r[2]),c:parseFloat(r[3]),d:parseFloat(r[4]),e:parseFloat(r[5]),f:parseFloat(r[6])}}function f(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function c(n){var r=n.a,t=n.b,e=n.c,o=n.d,u=n.e,a=n.f,i=r*o-t*e;return{a:o/i,b:t/-i,c:e/-i,d:r/i,e:(o*u-e*a)/-i,f:(t*u-r*a)/i}}var d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},l=function(n){return"number"==typeof n&&!isNaN(n)&&isFinite(n)},s=function(n){return null!=n&&"object"===(void 0===n?"undefined":d(n))};function y(n){return s(n)&&n.hasOwnProperty("a")&&l(n.a)&&n.hasOwnProperty("b")&&l(n.b)&&n.hasOwnProperty("c")&&l(n.c)&&n.hasOwnProperty("d")&&l(n.d)&&n.hasOwnProperty("e")&&l(n.e)&&n.hasOwnProperty("f")&&l(n.f)}function p(n){return void 0===n}function b(n){return{a:1,c:0,e:n,b:0,d:1,f:arguments.length>1&&void 0!==arguments[1]?arguments[1]:0}}function v(){for(var n=arguments.length,r=Array(n),t=0;t<n;t++)r[t]=arguments[t];var e=function(n,r){return{a:n.a*r.a+n.c*r.b,c:n.a*r.c+n.c*r.d,e:n.a*r.e+n.c*r.f+n.e,b:n.b*r.a+n.d*r.b,d:n.b*r.c+n.d*r.d,f:n.b*r.e+n.d*r.f+n.f}};switch((r=Array.isArray(r[0])?r[0]:r).length){case 0:throw new Error("no matrices provided");case 1:return r[0];case 2:return e(r[0],r[1]);default:var o=function(n){return Array.isArray(n)?n:Array.from(n)}(r),u=o[0],a=o[1],i=o.slice(2),f=e(u,a);return v.apply(void 0,[f].concat(function(n){if(Array.isArray(n)){for(var r=0,t=Array(n.length);r<n.length;r++)t[r]=n[r];return t}return Array.from(n)}(i)))}}function h(){return v.apply(void 0,arguments)}var m=Math.cos,x=Math.sin,M=Math.PI;function g(n,r,t){var e=m(n),o=x(n),u={a:e,c:-o,e:0,b:o,d:e,f:0};return p(r)||p(t)?u:v([b(r,t),u,b(-r,-t)])}function w(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return g(n*M/180,r,t)}function P(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return p(r)&&(r=n),{a:n,c:0,e:0,b:0,d:r,f:0}}function S(n,r){return{a:1,c:n,e:0,b:r,d:1,f:0}}var O=Math.tan;function A(n,r){return{a:1,c:O(n),e:0,b:O(r),d:1,f:0}}function F(n,r){return A(n*Math.PI/180,r*Math.PI/180)}function j(n){return T(n)}function _(n){return T(n)}function T(n){return"matrix("+n.a+","+n.b+","+n.c+","+n.d+","+n.e+","+n.f+")"}function E(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e10;return{a:Math.round(n.a*r)/r,b:Math.round(n.b*r)/r,c:Math.round(n.c*r)/r,d:Math.round(n.d*r)/r,e:Math.round(n.e*r)/r,f:Math.round(n.f*r)/r}}function G(n,r){var t=null!=n[0].x?n[0].x:n[0][0],e=null!=n[0].y?n[0].y:n[0][1],o=null!=r[0].x?r[0].x:r[0][0],u=null!=r[0].y?r[0].y:r[0][1],a=null!=n[1].x?n[1].x:n[1][0],i=null!=n[1].y?n[1].y:n[1][1],f=null!=r[1].x?r[1].x:r[1][0],d=null!=r[1].y?r[1].y:r[1][1],l=null!=n[2].x?n[2].x:n[2][0],s=null!=n[2].y?n[2].y:n[2][1],y=null!=r[2].x?r[2].x:r[2][0],p=null!=r[2].y?r[2].y:r[2][1];return E(v([{a:o-y,b:u-p,c:f-y,d:d-p,e:y,f:p},c({a:t-l,b:e-s,c:a-l,d:i-s,e:l,f:s})]))}t.d(r,"applyToPoint",function(){return e}),t.d(r,"applyToPoints",function(){return o}),t.d(r,"fromObject",function(){return u}),t.d(r,"fromString",function(){return i}),t.d(r,"identity",function(){return f}),t.d(r,"inverse",function(){return c}),t.d(r,"isAffineMatrix",function(){return y}),t.d(r,"rotate",function(){return g}),t.d(r,"rotateDEG",function(){return w}),t.d(r,"scale",function(){return P}),t.d(r,"shear",function(){return S}),t.d(r,"skew",function(){return A}),t.d(r,"skewDEG",function(){return F}),t.d(r,"toCSS",function(){return j}),t.d(r,"toSVG",function(){return _}),t.d(r,"toString",function(){return T}),t.d(r,"transform",function(){return v}),t.d(r,"compose",function(){return h}),t.d(r,"translate",function(){return b}),t.d(r,"fromTriangles",function(){return G}),t.d(r,"smoothMatrix",function(){return E})}])}); | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.TransformationMatrix=n():r.TransformationMatrix=n()}(window,function(){return function(r){var n={};function t(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=n,t.d=function(r,n,e){t.o(r,n)||Object.defineProperty(r,n,{enumerable:!0,get:e})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,n){if(1&n&&(r=t(r)),8&n)return r;if(4&n&&"object"==typeof r&&r&&r.__esModule)return r;var e=Object.create(null);if(t.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:r}),2&n&&"string"!=typeof r)for(var o in r)t.d(e,o,function(n){return r[n]}.bind(null,o));return e},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},t.p="",t(t.s=0)}([function(r,n,t){"use strict";function e(r,n){return Array.isArray(n)?[r.a*n[0]+r.c*n[1]+r.e,r.b*n[0]+r.d*n[1]+r.f]:{x:r.a*n.x+r.c*n.y+r.e,y:r.b*n.x+r.d*n.y+r.f}}function o(r,n){return n.map(function(n){return e(r,n)})}function u(r){return{a:parseFloat(r.a),b:parseFloat(r.b),c:parseFloat(r.c),d:parseFloat(r.d),e:parseFloat(r.e),f:parseFloat(r.f)}}t.r(n);var i=/^matrix\(\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*,\s*([0-9_+-.e]+)\s*\)$/i;function a(r){var n=r.match(i);if(null===n||n.length<7)throw new Error("'".concat(r,"' is not a matrix"));return{a:parseFloat(n[1]),b:parseFloat(n[2]),c:parseFloat(n[3]),d:parseFloat(n[4]),e:parseFloat(n[5]),f:parseFloat(n[6])}}function c(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function f(r){var n=r.a,t=r.b,e=r.c,o=r.d,u=r.e,i=r.f,a=n*o-t*e;return{a:o/a,b:t/-a,c:e/-a,d:n/a,e:(o*u-e*i)/-a,f:(t*u-n*i)/a}}function s(r){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function l(r){return void 0===r}function p(r){return"number"==typeof r&&!Number.isNaN(r)&&Number.isFinite(r)}function d(r){return"object"===s(n=r)&&null!==n&&!Array.isArray(n)&&r.hasOwnProperty("a")&&p(r.a)&&r.hasOwnProperty("b")&&p(r.b)&&r.hasOwnProperty("c")&&p(r.c)&&r.hasOwnProperty("d")&&p(r.d)&&r.hasOwnProperty("e")&&p(r.e)&&r.hasOwnProperty("f")&&p(r.f);var n}function h(r){return{a:1,c:0,e:r,b:0,d:1,f:arguments.length>1&&void 0!==arguments[1]?arguments[1]:0}}function y(r){return function(r){if(Array.isArray(r)){for(var n=0,t=new Array(r.length);n<r.length;n++)t[n]=r[n];return t}}(r)||A(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function v(r){return function(r){if(Array.isArray(r))return r}(r)||A(r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function A(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}function b(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];var e=function(r,n){return{a:r.a*n.a+r.c*n.b,c:r.a*n.c+r.c*n.d,e:r.a*n.e+r.c*n.f+r.e,b:r.b*n.a+r.d*n.b,d:r.b*n.c+r.d*n.d,f:r.b*n.e+r.d*n.f+r.f}};switch((n=Array.isArray(n[0])?n[0]:n).length){case 0:throw new Error("no matrices provided");case 1:return n[0];case 2:return e(n[0],n[1]);default:var o=v(n),u=o[0],i=o[1],a=o.slice(2),c=e(u,i);return b.apply(void 0,[c].concat(y(a)))}}function x(){return b.apply(void 0,arguments)}var g=Math.cos,m=Math.sin,w=Math.PI;function M(r,n,t){var e=g(r),o=m(r),u={a:e,c:-o,e:0,b:o,d:e,f:0};return l(n)||l(t)?u:b([h(n,t),u,h(-n,-t)])}function S(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return M(r*w/180,n,t)}function _(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return l(n)&&(n=r),{a:r,c:0,e:0,b:0,d:n,f:0}}function P(r,n){return{a:1,c:r,e:0,b:n,d:1,f:0}}var O=Math.tan;function C(r,n){return{a:1,c:O(r),e:0,b:O(n),d:1,f:0}}function E(r,n){return C(r*Math.PI/180,n*Math.PI/180)}function j(r){return I(r)}function F(r){return I(r)}function I(r){return"matrix(".concat(r.a,",").concat(r.b,",").concat(r.c,",").concat(r.d,",").concat(r.e,",").concat(r.f,")")}function R(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e10;return{a:Math.round(r.a*n)/n,b:Math.round(r.b*n)/n,c:Math.round(r.c*n)/n,d:Math.round(r.d*n)/n,e:Math.round(r.e*n)/n,f:Math.round(r.f*n)/n}}function T(r,n){var t=null!=r[0].x?r[0].x:r[0][0],e=null!=r[0].y?r[0].y:r[0][1],o=null!=n[0].x?n[0].x:n[0][0],u=null!=n[0].y?n[0].y:n[0][1],i=null!=r[1].x?r[1].x:r[1][0],a=null!=r[1].y?r[1].y:r[1][1],c=null!=n[1].x?n[1].x:n[1][0],s=null!=n[1].y?n[1].y:n[1][1],l=null!=r[2].x?r[2].x:r[2][0],p=null!=r[2].y?r[2].y:r[2][1],d=null!=n[2].x?n[2].x:n[2][0],h=null!=n[2].y?n[2].y:n[2][1];return R(b([{a:o-d,b:u-h,c:c-d,d:s-h,e:d,f:h},f({a:t-l,b:e-p,c:i-l,d:a-p,e:l,f:p})]))}function N(r){return Array.isArray(r)?r.map(n):n(r);function n(r){switch(r.type){case"matrix":if("a"in r&&"b"in r&&"c"in r&&"d"in r&&"e"in r&&"f"in r)return u(r);throw new Error("MISSING_MANDATORY_PARAM");case"translate":if(!("tx"in r))throw new Error("MISSING_MANDATORY_PARAM");return"ty"in r?h(r.tx,r.ty):h(r.tx);case"scale":if(!("sx"in r))throw new Error("MISSING_MANDATORY_PARAM");return"sy"in r?_(r.sx,r.sy):_(r.sx);case"rotate":if(!("angle"in r))throw new Error("MISSING_MANDATORY_PARAM");return"cx"in r&&"cy"in r?S(r.angle,r.cx,r.cy):S(r.angle);case"skewX":if(!("angle"in r))throw new Error("MISSING_MANDATORY_PARAM");return E(r.angle,0);case"skewY":if(!("angle"in r))throw new Error("MISSING_MANDATORY_PARAM");return E(0,r.angle);case"shear":if(!("shx"in r&&"shy"in r))throw new Error("MISSING_MANDATORY_PARAM");return P(r.shx,r.shy);default:throw new Error("UNSUPPORTED_DESCRIPTOR")}}}function k(r,n,t,e){this.message=r,this.expected=n,this.found=t,this.location=e,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,k)}function D(r,n){n=void 0!==n?n:{};var t,e={},o={transformList:cr},u=cr,i="matrix",a="(",c=")",f="translate",s="scale",l="rotate",p="skewX",d="skewY",h=",",y=".",v=/^[eE]/,A=/^[+\-]/,b=/^[0-9]/,x=/^[ \t\r\n]/,g=rr("matrix",!1),m=rr("(",!1),w=rr(")",!1),M=rr("translate",!1),S=rr("scale",!1),_=rr("rotate",!1),P=rr("skewX",!1),O=rr("skewY",!1),C=rr(",",!1),E=tr("fractionalConstant"),j=nr(["e","E"],!1,!1),F=nr(["+","-"],!1,!1),I=nr([["0","9"]],!1,!1),R=nr([" ","\t","\r","\n"],!1,!1),T=function(r){return r},N=function(r,n){return r.concat(n)},D=function(r,n,t,e,o,u){return[{type:"matrix",a:r,b:n,c:t,d:e,e:o,f:u}]},Y=function(r,n){var t={type:"translate",tx:r};return n&&(t.ty=n),[t]},G=function(r,n){var t={type:"scale",sx:r};return n&&(t.sy=n),[t]},X=function(r,n){var t={type:"rotate",angle:r};return n&&(t.cx=n[0],t.cy=n[1]),[t]},U=function(r){return[{type:"skewX",angle:r}]},L=function(r){return[{type:"skewY",angle:r}]},V=function(r){return parseFloat(r.join(""))},$=function(r){return parseInt(r.join(""))},q=function(r){return r},z=function(r,n){return[r,n]},B=function(r){return r.join("")},H=function(r,n){return[r?r.join(""):null,".",n.join("")].join("")},J=function(r){return r.join("")},K=0,Q=[{line:1,column:1}],W=[],Z=0;if("startRule"in n){if(!(n.startRule in o))throw new Error("Can't start parsing from rule \""+n.startRule+'".');u=o[n.startRule]}function rr(r,n){return{type:"literal",text:r,ignoreCase:n}}function nr(r,n,t){return{type:"class",parts:r,inverted:n,ignoreCase:t}}function tr(r){return{type:"other",description:r}}function er(n){var t,e=Q[n];if(e)return e;for(t=n-1;!Q[t];)t--;for(e={line:(e=Q[t]).line,column:e.column};t<n;)10===r.charCodeAt(t)?(e.line++,e.column=1):e.column++,t++;return Q[n]=e,e}var or="string"==typeof n.filename&&n.filename.length>0;function ur(r,t){var e={};or&&(e.filename=n.filename);var o=er(r);e.start={offset:r,line:o.line,column:o.column};var u=er(t);return e.end={offset:t,line:u.line,column:u.column},e}function ir(r){var n=W[W.length-1];K<n.pos||(K>n.pos&&(n.pos=K,n.variants=[]),n.variants.push(r))}function ar(r,n,t){return new k(k.buildMessage(r,n),r,n,t)}function cr(){var r,n,t,o,u;for(r=K,n=[],t=br();t!==e;)n.push(t),t=br();for((t=function r(){var n,t,o,u;n=K;t=fr();if(t!==e){if(o=[],(u=pr())!==e)for(;u!==e;)o.push(u),u=pr();else o=e;o!==e&&(u=r())!==e?(n,n=N(t,u)):(K=n,n=e)}else K=n,n=e;n===e&&(n=fr());return n}())===e&&(t=null),o=[],u=br();u!==e;)o.push(u),u=br();return r,r=T(t)}function fr(){var n;return(n=function(){var n,t,o,u,f,s,l,p,d,h,y,v,A,b=function(r){0===Z&&ir(r)};n=K,b(g),r.substr(K,6)===i?(t=i,K+=6):t=e;if(t!==e){for(o=[],u=br();u!==e;)o.push(u),u=br();if(b(m),40===r.charCodeAt(K)?(u=a,K++):u=e,u!==e){for(f=[],s=br();s!==e;)f.push(s),s=br();if((s=sr())!==e)if(pr()!==e)if((l=sr())!==e)if(pr()!==e)if((p=sr())!==e)if(pr()!==e)if((d=sr())!==e)if(pr()!==e)if((h=sr())!==e)if(pr()!==e)if((y=sr())!==e){for(v=[],A=br();A!==e;)v.push(A),A=br();b(w),41===r.charCodeAt(K)?(A=c,K++):A=e,A!==e?(n,n=D(s,l,p,d,h,y)):(K=n,n=e)}else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e;else K=n,n=e}else K=n,n=e}else K=n,n=e;return n}())===e&&(n=function(){var n,t,o,u,i,s,l,p,d,h=function(r){0===Z&&ir(r)};n=K,h(M),r.substr(K,9)===f?(t=f,K+=9):t=e;if(t!==e){for(o=[],u=br();u!==e;)o.push(u),u=br();if(h(m),40===r.charCodeAt(K)?(u=a,K++):u=e,u!==e){for(i=[],s=br();s!==e;)i.push(s),s=br();if((s=sr())!==e){for((l=lr())===e&&(l=null),p=[],d=br();d!==e;)p.push(d),d=br();h(w),41===r.charCodeAt(K)?(d=c,K++):d=e,d!==e?(n,n=Y(s,l)):(K=n,n=e)}else K=n,n=e}else K=n,n=e}else K=n,n=e;return n}())===e&&(n=function(){var n,t,o,u,i,f,l,p,d,h=function(r){0===Z&&ir(r)};n=K,h(S),r.substr(K,5)===s?(t=s,K+=5):t=e;if(t!==e){for(o=[],u=br();u!==e;)o.push(u),u=br();if(h(m),40===r.charCodeAt(K)?(u=a,K++):u=e,u!==e){for(i=[],f=br();f!==e;)i.push(f),f=br();if((f=sr())!==e){for((l=lr())===e&&(l=null),p=[],d=br();d!==e;)p.push(d),d=br();h(w),41===r.charCodeAt(K)?(d=c,K++):d=e,d!==e?(n,n=G(f,l)):(K=n,n=e)}else K=n,n=e}else K=n,n=e}else K=n,n=e;return n}())===e&&(n=function(){var n,t,o,u,i,f,s,p,d,h=function(r){0===Z&&ir(r)};n=K,h(_),r.substr(K,6)===l?(t=l,K+=6):t=e;if(t!==e){for(o=[],u=br();u!==e;)o.push(u),u=br();if(h(m),40===r.charCodeAt(K)?(u=a,K++):u=e,u!==e){for(i=[],f=br();f!==e;)i.push(f),f=br();if((f=sr())!==e){for((s=function(){var r,n,t;r=K,pr()!==e&&(n=sr())!==e&&pr()!==e&&(t=sr())!==e?(r,r=z(n,t)):(K=r,r=e);return r}())===e&&(s=null),p=[],d=br();d!==e;)p.push(d),d=br();h(w),41===r.charCodeAt(K)?(d=c,K++):d=e,d!==e?(n,n=X(f,s)):(K=n,n=e)}else K=n,n=e}else K=n,n=e}else K=n,n=e;return n}())===e&&(n=function(){var n,t,o,u,i,f,s,l,d=function(r){0===Z&&ir(r)};n=K,d(P),r.substr(K,5)===p?(t=p,K+=5):t=e;if(t!==e){for(o=[],u=br();u!==e;)o.push(u),u=br();if(d(m),40===r.charCodeAt(K)?(u=a,K++):u=e,u!==e){for(i=[],f=br();f!==e;)i.push(f),f=br();if((f=sr())!==e){for(s=[],l=br();l!==e;)s.push(l),l=br();d(w),41===r.charCodeAt(K)?(l=c,K++):l=e,l!==e?(n,n=U(f)):(K=n,n=e)}else K=n,n=e}else K=n,n=e}else K=n,n=e;return n}())===e&&(n=function(){var n,t,o,u,i,f,s,l,p=function(r){0===Z&&ir(r)};n=K,p(O),r.substr(K,5)===d?(t=d,K+=5):t=e;if(t!==e){for(o=[],u=br();u!==e;)o.push(u),u=br();if(p(m),40===r.charCodeAt(K)?(u=a,K++):u=e,u!==e){for(i=[],f=br();f!==e;)i.push(f),f=br();if((f=sr())!==e){for(s=[],l=br();l!==e;)s.push(l),l=br();p(w),41===r.charCodeAt(K)?(l=c,K++):l=e,l!==e?(n,n=L(f)):(K=n,n=e)}else K=n,n=e}else K=n,n=e}else K=n,n=e;return n}()),n}function sr(){var n,t,o,u;return n=K,t=K,(o=yr())===e&&(o=null),(u=function(){var n,t,o;n=K,(t=function(){var n,t,o,u,i;return i=E,0===Z&&ir(i),Z++,n=K,(t=vr())===e&&(t=null),46===r.charCodeAt(K)?(o=y,K++):o=e,o!==e&&(u=vr())!==e?(n,n=H(t,u)):(K=n,n=e),n===e&&(n=K,(t=vr())!==e?(46===r.charCodeAt(K)?(o=y,K++):o=e,o!==e?(n,n=J(t)):(K=n,n=e)):(K=n,n=e)),Z--,n}())!==e?((o=hr())===e&&(o=null),n=t=[t,o]):(K=n,n=e);n===e&&(n=K,(t=vr())!==e&&(o=hr())!==e?n=t=[t,o]:(K=n,n=e));return n}())!==e?t=o=[o,u]:(K=t,t=e),t!==e&&(n,t=V(t)),(n=t)===e&&(n=K,t=K,(o=yr())===e&&(o=null),(u=function(){var r,n;r=K,(n=vr())!==e&&(r,n=B(n));return r=n}())!==e?t=o=[o,u]:(K=t,t=e),t!==e&&(n,t=$(t)),n=t),n}function lr(){var r,n;return r=K,pr()!==e&&(n=sr())!==e?(r,r=q(n)):(K=r,r=e),r}function pr(){var r,n,t,o,u;if(r=K,n=[],(t=br())!==e)for(;t!==e;)n.push(t),t=br();else n=e;if(n!==e){for((t=dr())===e&&(t=null),o=[],u=br();u!==e;)o.push(u),u=br();r=n=[n,t,o]}else K=r,r=e;if(r===e)if(r=K,(n=dr())!==e){for(t=[],o=br();o!==e;)t.push(o),o=br();r=n=[n,t]}else K=r,r=e;return r}function dr(){var n,t;return t=C,0===Z&&ir(t),44===r.charCodeAt(K)?(n=h,K++):n=e,n}function hr(){var n,t,o,u,i;return n=K,i=j,0===Z&&ir(i),v.test(r.charAt(K))?(t=r.charAt(K),K++):t=e,t!==e?((o=yr())===e&&(o=null),(u=vr())!==e?n=t=[t,o,u]:(K=n,n=e)):(K=n,n=e),n}function yr(){var n,t;return t=F,0===Z&&ir(t),A.test(r.charAt(K))?(n=r.charAt(K),K++):n=e,n}function vr(){var r,n;if(r=[],(n=Ar())!==e)for(;n!==e;)r.push(n),n=Ar();else r=e;return r}function Ar(){var n,t;return t=I,0===Z&&ir(t),b.test(r.charAt(K))?(n=r.charAt(K),K++):n=e,n}function br(){var n,t;return t=R,0===Z&&ir(t),x.test(r.charAt(K))?(n=r.charAt(K),K++):n=e,n}if(W.push({pos:K,variants:[]}),(t=u())!==e&&K===r.length)return t;throw t!==e&&K<r.length&&ir({type:"end"}),function(){var n=W[0],t=n.pos;return ar(n.variants,t<r.length?r.charAt(t):null,t<r.length?ur(t,t+1):ur(t,t))}()}!function(r,n){function t(){this.constructor=r}t.prototype=n.prototype,r.prototype=new t}(k,Error),k.buildMessage=function(r,n){var t={literal:function(r){return'"'+o(r.text)+'"'},class:function(r){var n=r.parts.map(function(r){return Array.isArray(r)?u(r[0])+"-"+u(r[1]):u(r)});return"["+(r.inverted?"^":"")+n+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(r){return r.description},not:function(r){return"not "+i(r.expected)}};function e(r){return r.charCodeAt(0).toString(16).toUpperCase()}function o(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(r){return"\\x0"+e(r)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(r){return"\\x"+e(r)})}function u(r){return r.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(r){return"\\x0"+e(r)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(r){return"\\x"+e(r)})}function i(r){return t[r.type](r)}return"Expected "+function(r){var n,t,e=r.map(i);if(e.sort(),e.length>0){for(n=1,t=1;n<e.length;n++)e[n-1]!==e[n]&&(e[t]=e[n],t++);e.length=t}switch(e.length){case 1:return e[0];case 2:return e[0]+" or "+e[1];default:return e.slice(0,-1).join(", ")+", or "+e[e.length-1]}}(r)+" but "+function(r){return r?'"'+o(r)+'"':"end of input"}(n)+" found."};function Y(r){return D(r)}t.d(n,"applyToPoint",function(){return e}),t.d(n,"applyToPoints",function(){return o}),t.d(n,"fromObject",function(){return u}),t.d(n,"fromString",function(){return a}),t.d(n,"identity",function(){return c}),t.d(n,"inverse",function(){return f}),t.d(n,"isAffineMatrix",function(){return d}),t.d(n,"rotate",function(){return M}),t.d(n,"rotateDEG",function(){return S}),t.d(n,"scale",function(){return _}),t.d(n,"shear",function(){return P}),t.d(n,"skew",function(){return C}),t.d(n,"skewDEG",function(){return E}),t.d(n,"toCSS",function(){return j}),t.d(n,"toSVG",function(){return F}),t.d(n,"toString",function(){return I}),t.d(n,"transform",function(){return b}),t.d(n,"compose",function(){return x}),t.d(n,"translate",function(){return h}),t.d(n,"fromTriangles",function(){return T}),t.d(n,"smoothMatrix",function(){return R}),t.d(n,"fromDefinition",function(){return N}),t.d(n,"fromTransformAttribute",function(){return Y})}])}); | ||
//# sourceMappingURL=transformation-matrix.min.js.map |
{ | ||
"name": "transformation-matrix", | ||
"version": "1.15.3", | ||
"version": "2.0.0", | ||
"description": "2d transformation matrix functions written in ES6 syntax. Tree shaking ready!", | ||
"main": "./build-commonjs/index.js", | ||
"typings": "transformation-matrix.d.ts", | ||
"module": "./build-es/index.js", | ||
"jsnext:main": "./build-es/index.js", | ||
"module": "./src/index.js", | ||
"jsnext:main": "./src/index.js", | ||
"unpkg": "./build-umd/transformation-matrix.min.js", | ||
@@ -16,3 +16,3 @@ "files": [ | ||
"transformation-matrix.d.ts", | ||
".babelrc" | ||
"babel.config.js" | ||
], | ||
@@ -24,11 +24,10 @@ "scripts": { | ||
"test": "jest", | ||
"build-commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir build-commonjs", | ||
"build-es": "cross-env BABEL_ENV=es babel src --out-dir build-es", | ||
"build-commonjs": "babel src --out-dir build-commonjs", | ||
"build-docs": "jsdoc2md --partial disclaimer.hbs --template README.template.hbs src/*.js > README.md", | ||
"build-umd-min": "cross-env BABEL_ENV=es webpack --config ./webpack-umd.config.js --env.minimize", | ||
"build-umd": "cross-env BABEL_ENV=es webpack --config ./webpack-umd.config.js", | ||
"build-umd-min": "webpack --config ./webpack-umd.config.js --env.minimize", | ||
"build-umd": "webpack --config ./webpack-umd.config.js", | ||
"build-parser": "pegjs -o src/fromTransformAttribute.autogenerated.js --format es src/fromTransformAttribute.pegjs", | ||
"clean": "del build-*", | ||
"version": "npm-run-all clean test build add-readme-to-vcs", | ||
"build": "npm-run-all clean build-commonjs build-es build-docs build-umd build-umd-min build-parser", | ||
"build": "npm-run-all clean build-commonjs build-docs build-umd build-umd-min build-parser", | ||
"add-readme-to-vcs": "git add -A README.md", | ||
@@ -57,21 +56,18 @@ "standard": "standard" | ||
"devDependencies": { | ||
"@types/jest": "^23.3.1", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-jest": "^23.4.2", | ||
"babel-loader": "^7.1.5", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-register": "^6.26.0", | ||
"coveralls": "^3.0.2", | ||
"cross-env": "^5.2.0", | ||
"@babel/cli": "^7.4.3", | ||
"@babel/core": "^7.4.3", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.4.3", | ||
"@babel/plugin-transform-runtime": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"@types/jest": "^24.0.11", | ||
"babel-loader": "^8.0.5", | ||
"coveralls": "^3.0.3", | ||
"del-cli": "^1.1.0", | ||
"jest": "^23.5.0", | ||
"jest": "^24.7.1", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"npm-run-all": "^4.1.3", | ||
"pegjs": "0.11.0-dev.273", | ||
"standard": "^11.0.1", | ||
"webpack": "^4.17.1", | ||
"webpack-cli": "^3.1.0" | ||
"npm-run-all": "^4.1.5", | ||
"pegjs": "0.11.0-master.30f3260", | ||
"standard": "^12.0.1", | ||
"webpack": "^4.29.6", | ||
"webpack-cli": "^3.3.0" | ||
}, | ||
@@ -78,0 +74,0 @@ "standard": { |
404
README.md
@@ -14,3 +14,3 @@ <!--------------------------------------------------------------------> | ||
[](https://standardjs.com) | ||
[](https://chrvadala.github.io) | ||
[](https://travis-ci.org/chrvadala/transformation-matrix) | ||
@@ -57,25 +57,5 @@ [](https://coveralls.io/github/chrvadala/transformation-matrix?branch=master) | ||
```html | ||
<script src="https://unpkg.com/transformation-matrix@1"></script> | ||
<script src="https://unpkg.com/transformation-matrix@2"></script> | ||
``` | ||
## Data Model | ||
A **Transformation Matrix** is defined as an `Object` with 6 keys: `a`, `b`, `c`, `d`, `e` and `f`. | ||
```js | ||
const matrix = { a: 1, c: 0, e: 0, | ||
b: 0, d: 1, f: 0 } | ||
``` | ||
A **Point** can be defined in two different ways: | ||
- as `Object`, with inside two keys: `x` and `y` | ||
```js | ||
const point = { x: 24, y: 42 } | ||
``` | ||
- as `Array`, with two items in the form `[x, y]` | ||
```js | ||
const point = [ 24, 42 ] | ||
``` | ||
## Live Demo | ||
available at [http://chrvadala.github.io/transformation-matrix/](http://chrvadala.github.io/transformation-matrix/) | ||
# Reference | ||
@@ -85,26 +65,29 @@ ## Functions | ||
<dl> | ||
<dt><a href="#applyToPoint">applyToPoint(matrix, point)</a> ⇒ <code>Object</code> | <code>Array</code></dt> | ||
<dt><a href="#applyToPoint">applyToPoint(matrix, point)</a> ⇒ <code>Point</code></dt> | ||
<dd><p>Calculate a point transformed with an affine matrix</p> | ||
</dd> | ||
<dt><a href="#applyToPoints">applyToPoints(matrix, points)</a> ⇒ <code>array</code></dt> | ||
<dt><a href="#applyToPoints">applyToPoints(matrix, points)</a> ⇒ <code>Array.<Point></code></dt> | ||
<dd><p>Calculate an array of points transformed with an affine matrix</p> | ||
</dd> | ||
<dt><a href="#fromObject">fromObject(object)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#fromDefinition">fromDefinition(definitionOrArrayOfDefinition)</a> ⇒ <code>Array.<Matrix></code></dt> | ||
<dd><p>Converts array of matrix descriptor to array of matrix</p> | ||
</dd> | ||
<dt><a href="#fromObject">fromObject(object)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Extract an affine matrix from an object that contains a,b,c,d,e,f keys | ||
Each value could be a float or a string that contains a float</p> | ||
Any value could be a float or a string that contains a float</p> | ||
</dd> | ||
<dt><a href="#fromString">fromString(string)</a> ⇒ <code>Object</code></dt> | ||
<dd><p>Parse a string matrix formatted as matrix(a,b,c,d,e,f)</p> | ||
<dt><a href="#fromString">fromString(string)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Parse a string formatted as matrix(a,b,c,d,e,f)</p> | ||
</dd> | ||
<dt><a href="#fromTransformAttribute">fromTransformAttribute(transformString)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#fromTransformAttribute">fromTransformAttribute(transformString)</a> ⇒ <code>Array.<Matrix></code></dt> | ||
<dd><p>Parser for SVG Trasform Attribute <a href="http://www.w3.org/TR/SVG/coords.html#TransformAttribute">http://www.w3.org/TR/SVG/coords.html#TransformAttribute</a> <br/> | ||
Warning: This should be considered BETA until it is released a stable version of pegjs.</p> | ||
</dd> | ||
<dt><a href="#fromTriangles">fromTriangles(t1, t2)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#fromTriangles">fromTriangles(t1, t2)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible.</p> | ||
</dd> | ||
<dt><a href="#identity">identity()</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#identity">identity()</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Identity matrix</p> | ||
</dd> | ||
<dt><a href="#inverse">inverse(matrix)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#inverse">inverse(matrix)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a matrix that is the inverse of the provided matrix</p> | ||
@@ -115,39 +98,39 @@ </dd> | ||
</dd> | ||
<dt><a href="#rotate">rotate(angle, [cx], [cy])</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#rotate">rotate(angle, [cx], [cy])</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a rotation matrix</p> | ||
</dd> | ||
<dt><a href="#rotateDEG">rotateDEG(angle, [cx], [cy])</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#rotateDEG">rotateDEG(angle, [cx], [cy])</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a rotation matrix with a DEG angle</p> | ||
</dd> | ||
<dt><a href="#scale">scale(sx, [sy])</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#scale">scale(sx, [sy])</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a scaling matrix</p> | ||
</dd> | ||
<dt><a href="#shear">shear(shx, shy)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#shear">shear(shx, shy)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a shear matrix</p> | ||
</dd> | ||
<dt><a href="#skew">skew(ax, ay)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#skew">skew(ax, ay)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a skew matrix</p> | ||
</dd> | ||
<dt><a href="#skewDEG">skewDEG(ax, ay)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#skewDEG">skewDEG(ax, ay)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a skew matrix using DEG angles</p> | ||
</dd> | ||
<dt><a href="#smoothMatrix">smoothMatrix(m, [precision])</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#smoothMatrix">smoothMatrix(matrix, [precision])</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Rounds all elements of the given matrix using the given precision</p> | ||
</dd> | ||
<dt><a href="#toCSS">toCSS(matrix)</a> ⇒ <code>string</code></dt> | ||
<dd><p>Serialize the matrix to a string that can be used with CSS or SVG</p> | ||
<dd><p>Serialize an affine matrix to a string that can be used with CSS or SVG</p> | ||
</dd> | ||
<dt><a href="#toSVG">toSVG(matrix)</a> ⇒ <code>string</code></dt> | ||
<dd><p>Serialize the matrix to a string that can be used with CSS or SVG</p> | ||
<dd><p>Serialize an affine matrix to a string that can be used with CSS or SVG</p> | ||
</dd> | ||
<dt><a href="#toString">toString(matrix)</a> ⇒ <code>string</code></dt> | ||
<dd><p>Serialize the matrix to a string that can be used with CSS or SVG</p> | ||
<dd><p>Serialize an affine matrix to a string that can be used with CSS or SVG</p> | ||
</dd> | ||
<dt><a href="#transform">transform(...matrices)</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#transform">transform(matrices)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Merge multiple matrices into one</p> | ||
</dd> | ||
<dt><a href="#compose">compose(...matrices)</a> ⇒ <code>Object</code></dt> | ||
<dd><p>Merge multiple matrices into one (alias of <code>transform</code>)</p> | ||
<dt><a href="#compose">compose(matrices)</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Merge multiple matrices into one</p> | ||
</dd> | ||
<dt><a href="#translate">translate(tx, [ty])</a> ⇒ <code>Object</code></dt> | ||
<dt><a href="#translate">translate(tx, [ty])</a> ⇒ <code>Matrix</code></dt> | ||
<dd><p>Calculate a translate matrix</p> | ||
@@ -175,75 +158,117 @@ </dd> | ||
- **1.15**- Adds `fromTriangle` and `smoothMatrix` functions [#41](https://github.com/chrvadala/transformation-matrix/issues/41) | ||
- **2.0**- Migrates to Babel 7 and updates dependencies; introduces `fromDefinition` function; breaking changes on `fromTransformAttribute` function; improves docs | ||
## Some projects using transformation-matrix | ||
- [**React Planner**](https://github.com/cvdlab/react-planner) | ||
- [**React SVG Pan Zoom**](https://github.com/chrvadala/react-svg-pan-zoom) | ||
- [**ngx-graph**](https://github.com/swimlane/ngx-graph) | ||
- [**learn-anything**](https://github.com/learn-anything/learn-anything) | ||
- [**Others...**](https://github.com/chrvadala/transformation-matrix/network/dependents) | ||
- Pull request your project! | ||
# API | ||
## Contributors | ||
- [chrvadala](https://github.com/chrvadala) (author) | ||
- [forabi](https://github.com/forabi) | ||
- [nidu](https://github.com/nidu) (PEG.js descriptor) | ||
- [aubergene](https://github.com/aubergene) | ||
- [SophiaLi1](https://github.com/SophiaLi1) | ||
- [Shuhei-Tsunoda](https://github.com/Shuhei-Tsunoda) | ||
## Data Model | ||
A transformation **Matrix** is defined as a `Plain Object` with 6 keys: `a`, `b`, `c`, `d`, `e` and `f`. | ||
```js | ||
const matrix = { | ||
a: 1, c: 0, e: 0, | ||
b: 0, d: 1, f: 0 | ||
} | ||
``` | ||
A **Point** can be defined in two different ways: | ||
- as `Plain Object`, with inside two keys: `x` and `y` | ||
```js | ||
const point = { x: 24, y: 42 } | ||
``` | ||
- as `Array`, with two items in the form `[x, y]` | ||
```js | ||
const point = [ 24, 42 ] | ||
``` | ||
# API | ||
<a name="applyToPoint"></a> | ||
## applyToPoint(matrix, point) ⇒ <code>Object</code> \| <code>Array</code> | ||
## applyToPoint(matrix, point) ⇒ <code>Point</code> | ||
Calculate a point transformed with an affine matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> \| <code>Array</code> - Point | ||
**Returns**: <code>Point</code> - Point | ||
| Param | Description | | ||
| --- | --- | | ||
| matrix | Affine matrix | | ||
| point | Point | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| matrix | <code>Matrix</code> | Affine Matrix | | ||
| point | <code>Point</code> | Point | | ||
<a name="applyToPoints"></a> | ||
## applyToPoints(matrix, points) ⇒ <code>array</code> | ||
## applyToPoints(matrix, points) ⇒ <code>Array.<Point></code> | ||
Calculate an array of points transformed with an affine matrix | ||
**Kind**: global function | ||
**Returns**: <code>array</code> - Array of points | ||
**Returns**: <code>Array.<Point></code> - Array of point | ||
| Param | Description | | ||
| --- | --- | | ||
| matrix | Affine matrix | | ||
| points | Array of points | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| matrix | <code>Matrix</code> | Affine Matrix | | ||
| points | <code>Array.<Point></code> | Array of point | | ||
<a name="fromDefinition"></a> | ||
## fromDefinition(definitionOrArrayOfDefinition) ⇒ <code>Array.<Matrix></code> | ||
Converts array of matrix descriptor to array of matrix | ||
**Kind**: global function | ||
**Returns**: <code>Array.<Matrix></code> - Array of matrix | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| definitionOrArrayOfDefinition | <code>Array.<Object></code> | Array of object describing the matrix | | ||
**Example** | ||
```js | ||
> fromDefinition([ | ||
{ type: 'matrix', a:1, b:2, c:3, d:4, e:5, f:6 }, | ||
{ type: 'translate', tx: 10, ty: 20 }, | ||
{ type: 'scale', sx: 2, sy: 4 }, | ||
{ type: 'rotate', angle: 90, sx: 50, sy: 25 }, | ||
{ type: 'skewX', angle: 45 }, | ||
{ type: 'skewY', angle: 45 }, | ||
{ type: 'shear', shx: 10, shy: 20} | ||
]) | ||
[ | ||
{ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }, | ||
{ a: 1, c: 0, e: 10, b: 0, d: 1, f: 20 }, | ||
{ a: 2, c: 0, e: 0, b: 0, d: 4, f: 0 }, | ||
{ a: 6.123, c: -1, e: 0, b: 1, d: 6.123, f: 0 }, | ||
{ a: 1, c: 0.99.., e: 0, b: 0, d: 1, f: 0 }, | ||
{ a: 1, c: 0, e: 0, b: 0.99, d: 1, f: 0 }, | ||
{ a: 1, c: 10, e: 0, b: 20, d: 1, f: 0 } | ||
] | ||
``` | ||
<a name="fromObject"></a> | ||
## fromObject(object) ⇒ <code>Object</code> | ||
## fromObject(object) ⇒ <code>Matrix</code> | ||
Extract an affine matrix from an object that contains a,b,c,d,e,f keys | ||
Each value could be a float or a string that contains a float | ||
Any value could be a float or a string that contains a float | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - } | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | | ||
| --- | | ||
| object | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| object | <code>Object</code> | Object that contains a,b,c,d,e,f keys | | ||
<a name="fromString"></a> | ||
## fromString(string) ⇒ <code>Object</code> | ||
Parse a string matrix formatted as matrix(a,b,c,d,e,f) | ||
## fromString(string) ⇒ <code>Matrix</code> | ||
Parse a string formatted as matrix(a,b,c,d,e,f) | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Description | | ||
| --- | --- | | ||
| string | String with a matrix | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| string | <code>string</code> | String with an affine matrix | | ||
**Example** | ||
```js | ||
> fromString('matrix(1,2,3,4,5,6)') | ||
{a: 1, b: 2, c: 3, d: 4, c: 5, e: 6} | ||
``` | ||
<a name="fromTransformAttribute"></a> | ||
## fromTransformAttribute(transformString) ⇒ <code>Object</code> | ||
## fromTransformAttribute(transformString) ⇒ <code>Array.<Matrix></code> | ||
Parser for SVG Trasform Attribute http://www.w3.org/TR/SVG/coords.html#TransformAttribute <br/> | ||
@@ -253,15 +278,27 @@ Warning: This should be considered BETA until it is released a stable version of pegjs. | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Parsed matrices | ||
**Returns**: <code>Array.<Matrix></code> - Array of MatrixDescriptor | ||
| Param | Description | | ||
| --- | --- | | ||
| transformString | string | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| transformString | <code>string</code> | Transform string as defined by w3 Consortium | | ||
**Example** | ||
```js | ||
> fromTransformAttribute('translate(-10,-10) scale(2,2) translate(10,10)') | ||
[ | ||
{ type: 'translate', tx: -10, ty: -10}, | ||
{ type: 'scale', sx: 2, sy: 2 }, | ||
{ type: 'translate', tx: 10, ty: 10} | ||
] | ||
> compose(fromDefinition(fromTransformAttribute('translate(-10, -10) scale(10, 10)'))) | ||
{ a: 10, c: 0, e: -10, b: 0, d: 10, f: -10 } | ||
``` | ||
<a name="fromTriangles"></a> | ||
## fromTriangles(t1, t2) ⇒ <code>Object</code> | ||
## fromTriangles(t1, t2) ⇒ <code>Matrix</code> | ||
Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible. | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix which transforms t1 to t2 | ||
**Returns**: <code>Matrix</code> - Matrix which transforms t1 to t2 | ||
**Throws**: | ||
@@ -274,23 +311,23 @@ | ||
| --- | --- | --- | | ||
| t1 | <code>Array.<{x: number, y: number}></code> \| <code>Array.<Array.<number>></code> | an array of points containing the three points for the first triangle | | ||
| t2 | <code>Array.<{x: number, y: number}></code> \| <code>Array.<Array.<number>></code> | an array of points containing the three points for the second triangle | | ||
| t1 | <code>Array.<Point></code> | Array of points containing the three points for the first triangle | | ||
| t2 | <code>Array.<Point></code> | Array of points containing the three points for the second triangle | | ||
<a name="identity"></a> | ||
## identity() ⇒ <code>Object</code> | ||
## identity() ⇒ <code>Matrix</code> | ||
Identity matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
<a name="inverse"></a> | ||
## inverse(matrix) ⇒ <code>Object</code> | ||
## inverse(matrix) ⇒ <code>Matrix</code> | ||
Calculate a matrix that is the inverse of the provided matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Inverted Affine Matrix | ||
| Param | Description | | ||
| --- | --- | | ||
| matrix | Affine matrix | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| matrix | <code>Matrix</code> | Affine Matrix | | ||
@@ -303,99 +340,100 @@ <a name="isAffineMatrix"></a> | ||
**Kind**: global function | ||
**Returns**: <code>boolean</code> - True if is an object and contains an affine matrix | ||
| Param | | ||
| --- | | ||
| object | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| object | <code>Object</code> | Generic Plain Object | | ||
<a name="rotate"></a> | ||
## rotate(angle, [cx], [cy]) ⇒ <code>Object</code> | ||
## rotate(angle, [cx], [cy]) ⇒ <code>Matrix</code> | ||
Calculate a rotation matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix * | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Description | | ||
| --- | --- | | ||
| angle | Angle in radians | | ||
| [cx] | If (cx,cy) are supplied the rotate is about this point | | ||
| [cy] | If (cx,cy) are supplied the rotate is about this point | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| angle | <code>number</code> | Angle in radians | | ||
| [cx] | <code>number</code> | If (cx,cy) are supplied the rotate is about this point | | ||
| [cy] | <code>number</code> | If (cx,cy) are supplied the rotate is about this point | | ||
<a name="rotateDEG"></a> | ||
## rotateDEG(angle, [cx], [cy]) ⇒ <code>Object</code> | ||
## rotateDEG(angle, [cx], [cy]) ⇒ <code>Matrix</code> | ||
Calculate a rotation matrix with a DEG angle | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Description | | ||
| --- | --- | | ||
| angle | Angle in degree | | ||
| [cx] | If (cx,cy) are supplied the rotate is about this point | | ||
| [cy] | If (cx,cy) are supplied the rotate is about this point | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| angle | <code>number</code> | Angle in degree | | ||
| [cx] | <code>number</code> | If (cx,cy) are supplied the rotate is about this point | | ||
| [cy] | <code>number</code> | If (cx,cy) are supplied the rotate is about this point | | ||
<a name="scale"></a> | ||
## scale(sx, [sy]) ⇒ <code>Object</code> | ||
## scale(sx, [sy]) ⇒ <code>Matrix</code> | ||
Calculate a scaling matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Default | Description | | ||
| --- | --- | --- | | ||
| sx | | Scaling on axis x | | ||
| [sy] | <code>sx</code> | Scaling on axis y (default sx) | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| sx | <code>number</code> | | Scaling on axis x | | ||
| [sy] | <code>number</code> | <code>sx</code> | Scaling on axis y (default sx) | | ||
<a name="shear"></a> | ||
## shear(shx, shy) ⇒ <code>Object</code> | ||
## shear(shx, shy) ⇒ <code>Matrix</code> | ||
Calculate a shear matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Description | | ||
| --- | --- | | ||
| shx | Shear on axis x | | ||
| shy | Shear on axis y | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| shx | <code>number</code> | Shear on axis x | | ||
| shy | <code>number</code> | Shear on axis y | | ||
<a name="skew"></a> | ||
## skew(ax, ay) ⇒ <code>Object</code> | ||
## skew(ax, ay) ⇒ <code>Matrix</code> | ||
Calculate a skew matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Description | | ||
| --- | --- | | ||
| ax | Skew on axis x | | ||
| ay | Skew on axis y | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| ax | <code>number</code> | Skew on axis x | | ||
| ay | <code>number</code> | Skew on axis y | | ||
<a name="skewDEG"></a> | ||
## skewDEG(ax, ay) ⇒ <code>Object</code> | ||
## skewDEG(ax, ay) ⇒ <code>Matrix</code> | ||
Calculate a skew matrix using DEG angles | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Description | | ||
| --- | --- | | ||
| ax | Skew on axis x | | ||
| ay | Skew on axis y | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| ax | <code>number</code> | Skew on axis x | | ||
| ay | <code>number</code> | Skew on axis y | | ||
<a name="smoothMatrix"></a> | ||
## smoothMatrix(m, [precision]) ⇒ <code>Object</code> | ||
## smoothMatrix(matrix, [precision]) ⇒ <code>Matrix</code> | ||
Rounds all elements of the given matrix using the given precision | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - the rounded matrix | ||
**Returns**: <code>Matrix</code> - The rounded Affine Matrix | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| m | <code>Object</code> | a matrix to round | | ||
| [precision] | | a precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | | ||
| matrix | <code>Matrix</code> | An affine matrix to round | | ||
| [precision] | <code>number</code> | A precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | | ||
@@ -405,10 +443,10 @@ <a name="toCSS"></a> | ||
## toCSS(matrix) ⇒ <code>string</code> | ||
Serialize the matrix to a string that can be used with CSS or SVG | ||
Serialize an affine matrix to a string that can be used with CSS or SVG | ||
**Kind**: global function | ||
**Returns**: <code>string</code> - String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
**Returns**: <code>string</code> - String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
| Param | Description | | ||
| --- | --- | | ||
| matrix | Affine matrix | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| matrix | <code>Matrix</code> | Affine Matrix | | ||
@@ -418,10 +456,10 @@ <a name="toSVG"></a> | ||
## toSVG(matrix) ⇒ <code>string</code> | ||
Serialize the matrix to a string that can be used with CSS or SVG | ||
Serialize an affine matrix to a string that can be used with CSS or SVG | ||
**Kind**: global function | ||
**Returns**: <code>string</code> - String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
**Returns**: <code>string</code> - String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
| Param | Description | | ||
| --- | --- | | ||
| matrix | Affine matrix | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| matrix | <code>Matrix</code> | Affine Matrix | | ||
@@ -431,47 +469,63 @@ <a name="toString"></a> | ||
## toString(matrix) ⇒ <code>string</code> | ||
Serialize the matrix to a string that can be used with CSS or SVG | ||
Serialize an affine matrix to a string that can be used with CSS or SVG | ||
**Kind**: global function | ||
**Returns**: <code>string</code> - String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
**Returns**: <code>string</code> - String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
| Param | Description | | ||
| --- | --- | | ||
| matrix | Affine matrix | | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| matrix | <code>Matrix</code> | Affine Matrix | | ||
<a name="transform"></a> | ||
## transform(...matrices) ⇒ <code>Object</code> | ||
## transform(matrices) ⇒ <code>Matrix</code> | ||
Merge multiple matrices into one | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| ...matrices | <code>object</code> | list of matrices | | ||
| matrices | <code>Array.<Matrix></code> | Array of affine matrix | | ||
<a name="compose"></a> | ||
## compose(...matrices) ⇒ <code>Object</code> | ||
Merge multiple matrices into one (alias of `transform`) | ||
## compose(matrices) ⇒ <code>Matrix</code> | ||
Merge multiple matrices into one | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| ...matrices | <code>object</code> | list of matrices | | ||
| matrices | <code>Array.<Matrix></code> | Array of matrix | | ||
<a name="translate"></a> | ||
## translate(tx, [ty]) ⇒ <code>Object</code> | ||
## translate(tx, [ty]) ⇒ <code>Matrix</code> | ||
Calculate a translate matrix | ||
**Kind**: global function | ||
**Returns**: <code>Object</code> - Affine matrix | ||
**Returns**: <code>Matrix</code> - Affine Matrix | ||
| Param | Default | Description | | ||
| --- | --- | --- | | ||
| tx | | Translation on axis x | | ||
| [ty] | <code>0</code> | Translation on axis y | | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| tx | <code>number</code> | | Translation on axis x | | ||
| [ty] | <code>number</code> | <code>0</code> | Translation on axis y | | ||
## Some projects using transformation-matrix | ||
- [**React Planner**](https://github.com/cvdlab/react-planner) | ||
- [**React SVG Pan Zoom**](https://github.com/chrvadala/react-svg-pan-zoom) | ||
- [**ngx-graph**](https://github.com/swimlane/ngx-graph) | ||
- [**learn-anything**](https://github.com/learn-anything/learn-anything) | ||
- [**Others...**](https://github.com/chrvadala/transformation-matrix/network/dependents) | ||
- Pull request your project! | ||
## Contributors | ||
- [chrvadala](https://github.com/chrvadala) (author) | ||
- [forabi](https://github.com/forabi) | ||
- [nidu](https://github.com/nidu) (PEG.js descriptor) | ||
- [aubergene](https://github.com/aubergene) | ||
- [SophiaLi1](https://github.com/SophiaLi1) | ||
- [Shuhei-Tsunoda](https://github.com/Shuhei-Tsunoda) | ||
/** | ||
* Calculate a point transformed with an affine matrix | ||
* @param matrix Affine matrix | ||
* @param point Point | ||
* @returns {{x: number, y: number} | Array} Point | ||
* @param matrix {Matrix} Affine Matrix | ||
* @param point {Point} Point | ||
* @returns {Point} Point | ||
*/ | ||
@@ -19,5 +19,5 @@ export function applyToPoint (matrix, point) { | ||
* Calculate an array of points transformed with an affine matrix | ||
* @param matrix Affine matrix | ||
* @param points Array of points | ||
* @returns {array} Array of points | ||
* @param matrix {Matrix} Affine Matrix | ||
* @param points {Point[]} Array of point | ||
* @returns {Point[]} Array of point | ||
*/ | ||
@@ -24,0 +24,0 @@ export function applyToPoints (matrix, points) { |
/** | ||
* Extract an affine matrix from an object that contains a,b,c,d,e,f keys | ||
* Each value could be a float or a string that contains a float | ||
* @param object | ||
* @return {{a: *, b: *, c: *, e: *, d: *, f: *}}} | ||
* Any value could be a float or a string that contains a float | ||
* @param object {Object} Object that contains a,b,c,d,e,f keys | ||
* @return {Matrix} Affine Matrix | ||
*/ | ||
@@ -7,0 +7,0 @@ export function fromObject (object) { |
@@ -8,5 +8,9 @@ /** | ||
/** | ||
* Parse a string matrix formatted as matrix(a,b,c,d,e,f) | ||
* @param string String with a matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* Parse a string formatted as matrix(a,b,c,d,e,f) | ||
* @param string {string} String with an affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
* | ||
* @example | ||
* > fromString('matrix(1,2,3,4,5,6)') | ||
* {a: 1, b: 2, c: 3, d: 4, c: 5, e: 6} | ||
*/ | ||
@@ -13,0 +17,0 @@ export function fromString (string) { |
@@ -1,2 +0,2 @@ | ||
// Generated by PEG.js v0.11.0-dev, https://pegjs.org/ | ||
// Generated by PEG.js v0.11.0-master.30f3260, https://pegjs.org/ | ||
@@ -311,3 +311,3 @@ function peg$subclass(child, parent) { | ||
var peg$VALIDFILENAME = typeof options.filename === "string" && options.filename.length > 0; | ||
var peg$VALIDFILENAME = typeof options.filename === "string" && options.filename.length > 0; | ||
function peg$computeLocation(startPos, endPos) { | ||
@@ -314,0 +314,0 @@ var loc = {}; |
@@ -1,7 +0,2 @@ | ||
import {parse} from './fromTransformAttribute.autogenerated' | ||
import {translate} from './translate' | ||
import {rotateDEG} from './rotate' | ||
import {fromObject} from './fromObject' | ||
import {scale} from './scale' | ||
import {skewDEG} from './skew' | ||
import { parse } from './fromTransformAttribute.autogenerated' | ||
@@ -11,44 +6,18 @@ /** | ||
* Warning: This should be considered BETA until it is released a stable version of pegjs. | ||
* @param transformString string | ||
* @returns {{descriptors: *, matrices: *}} Parsed matrices | ||
* @param transformString {string} Transform string as defined by w3 Consortium | ||
* @returns {Matrix[]} Array of MatrixDescriptor | ||
* | ||
* @example | ||
* > fromTransformAttribute('translate(-10,-10) scale(2,2) translate(10,10)') | ||
* [ | ||
* { type: 'translate', tx: -10, ty: -10}, | ||
* { type: 'scale', sx: 2, sy: 2 }, | ||
* { type: 'translate', tx: 10, ty: 10} | ||
* ] | ||
* | ||
* > compose(fromDefinition(fromTransformAttribute('translate(-10, -10) scale(10, 10)'))) | ||
* { a: 10, c: 0, e: -10, b: 0, d: 10, f: -10 } | ||
*/ | ||
export function fromTransformAttribute (transformString) { | ||
let descriptors = parse(transformString) | ||
let matrices = descriptors.map(convertMatrixDescriptorToMatrix) | ||
return {descriptors, matrices} | ||
return parse(transformString) | ||
} | ||
function convertMatrixDescriptorToMatrix (matrixDescriptor) { | ||
let hasParam = key => matrixDescriptor.hasOwnProperty(key) | ||
let {type, ...params} = matrixDescriptor | ||
switch (type) { | ||
case 'matrix': | ||
return fromObject(params) | ||
case 'translate': | ||
if (hasParam('ty')) { return translate(params.tx, params.ty) } | ||
return translate(params.tx) | ||
case 'scale': | ||
if (hasParam('sy')) { return scale(params.sx, params.sy) } | ||
return scale(params.sx) | ||
case 'rotate': | ||
if (hasParam('cx') && hasParam('cy')) { return rotateDEG(params.angle, params.cx, params.cy) } | ||
return rotateDEG(params.angle) | ||
case 'skewX': | ||
return skewDEG(params.angle, 0) | ||
case 'skewY': | ||
return skewDEG(0, params.angle) | ||
default: | ||
/* istanbul ignore next */ | ||
throw new Error('Unsupported descriptor') | ||
} | ||
} |
@@ -7,5 +7,5 @@ import { inverse } from './inverse' | ||
* Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible. | ||
* @param t1 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the first triangle | ||
* @param t2 {Array.<{x: number, y: number}> | Array.<Array<number>>} an array of points containing the three points for the second triangle | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix which transforms t1 to t2 | ||
* @param t1 {Point[]} Array of points containing the three points for the first triangle | ||
* @param t2 {Point[]} Array of points containing the three points for the second triangle | ||
* @returns {Matrix} Matrix which transforms t1 to t2 | ||
* @throws Exception if the matrix becomes not invertible | ||
@@ -12,0 +12,0 @@ */ |
/** | ||
* Identity matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -5,0 +5,0 @@ export function identity () { |
@@ -16,1 +16,3 @@ export * from './applyToPoint' | ||
export * from './smoothMatrix' | ||
export * from './fromDefinition' | ||
export * from './fromTransformAttribute' |
/** | ||
* Calculate a matrix that is the inverse of the provided matrix | ||
* @param matrix Affine matrix | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {Matrix} Inverted Affine Matrix | ||
*/ | ||
@@ -9,3 +9,3 @@ export function inverse (matrix) { | ||
let {a, b, c, d, e, f} = matrix | ||
let { a, b, c, d, e, f } = matrix | ||
@@ -12,0 +12,0 @@ let denom = a * d - b * c |
@@ -1,9 +0,9 @@ | ||
let isNumeric = n => typeof n === 'number' && !isNaN(n) && isFinite(n) | ||
let isObject = obj => obj != null && (typeof obj === 'object') | ||
import { isNumeric, isObject } from './utils' | ||
/** | ||
* Check if the object contain an affine matrix | ||
* @param object | ||
* @return {boolean} | ||
* @param object {Object} Generic Plain Object | ||
* @return {boolean} True if is an object and contains an affine matrix | ||
*/ | ||
export function isAffineMatrix (object) { | ||
@@ -10,0 +10,0 @@ return isObject(object) && |
@@ -1,12 +0,12 @@ | ||
import {isUndefined} from './utils' | ||
import {translate} from './translate' | ||
import {transform} from './transform' | ||
import { isUndefined } from './utils' | ||
import { translate } from './translate' | ||
import { transform } from './transform' | ||
const {cos, sin, PI} = Math | ||
const { cos, sin, PI } = Math | ||
/** | ||
* Calculate a rotation matrix | ||
* @param angle Angle in radians | ||
* @param [cx] If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] If (cx,cy) are supplied the rotate is about this point | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix * | ||
* @param angle {number} Angle in radians | ||
* @param [cx] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -37,6 +37,6 @@ export function rotate (angle, cx, cy) { | ||
* Calculate a rotation matrix with a DEG angle | ||
* @param angle Angle in degree | ||
* @param [cx] If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] If (cx,cy) are supplied the rotate is about this point | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param angle {number} Angle in degree | ||
* @param [cx] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @param [cy] {number} If (cx,cy) are supplied the rotate is about this point | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -43,0 +43,0 @@ export function rotateDEG (angle, cx = undefined, cy = undefined) { |
@@ -1,8 +0,8 @@ | ||
import {isUndefined} from './utils' | ||
import { isUndefined } from './utils' | ||
/** | ||
* Calculate a scaling matrix | ||
* @param sx Scaling on axis x | ||
* @param [sy = sx] Scaling on axis y (default sx) | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param sx {number} Scaling on axis x | ||
* @param [sy = sx] {number} Scaling on axis y (default sx) | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -9,0 +9,0 @@ export function scale (sx, sy = undefined) { |
/** | ||
* Calculate a shear matrix | ||
* @param shx Shear on axis x | ||
* @param shy Shear on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param shx {number} Shear on axis x | ||
* @param shy {number} Shear on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -7,0 +7,0 @@ export function shear (shx, shy) { |
// https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew | ||
const {tan} = Math | ||
const { tan } = Math | ||
/** | ||
* Calculate a skew matrix | ||
* @param ax Skew on axis x | ||
* @param ay Skew on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param ax {number} Skew on axis x | ||
* @param ay {number} Skew on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -23,5 +23,5 @@ export function skew (ax, ay) { | ||
* Calculate a skew matrix using DEG angles | ||
* @param ax Skew on axis x | ||
* @param ay Skew on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param ax {number} Skew on axis x | ||
* @param ay {number} Skew on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -28,0 +28,0 @@ export function skewDEG (ax, ay) { |
/** | ||
* Rounds all elements of the given matrix using the given precision | ||
* @param m {{a: number, b: number, c: number, d: number, e: number, f: number}} a matrix to round | ||
* @param [precision] a precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | ||
* @returns {{a: number, b: number, c: number, d: number, e: number, f: number}} the rounded matrix | ||
* @param matrix {Matrix} An affine matrix to round | ||
* @param [precision] {number} A precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma). | ||
* @returns {Matrix} The rounded Affine Matrix | ||
*/ | ||
export function smoothMatrix (m, precision = 10000000000) { | ||
export function smoothMatrix (matrix, precision = 10000000000) { | ||
return { | ||
a: Math.round(m.a * precision) / precision, | ||
b: Math.round(m.b * precision) / precision, | ||
c: Math.round(m.c * precision) / precision, | ||
d: Math.round(m.d * precision) / precision, | ||
e: Math.round(m.e * precision) / precision, | ||
f: Math.round(m.f * precision) / precision | ||
a: Math.round(matrix.a * precision) / precision, | ||
b: Math.round(matrix.b * precision) / precision, | ||
c: Math.round(matrix.c * precision) / precision, | ||
d: Math.round(matrix.d * precision) / precision, | ||
e: Math.round(matrix.e * precision) / precision, | ||
f: Math.round(matrix.f * precision) / precision | ||
} | ||
} |
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
@@ -11,5 +11,5 @@ export function toCSS (matrix) { | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
@@ -21,5 +21,5 @@ export function toSVG (matrix) { | ||
/** | ||
* Serialize the matrix to a string that can be used with CSS or SVG | ||
* @param matrix Affine matrix | ||
* @returns {string} String that contains a matrix formatted as matrix(a,b,c,d,e,f) | ||
* Serialize an affine matrix to a string that can be used with CSS or SVG | ||
* @param matrix {Matrix} Affine Matrix | ||
* @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f) | ||
*/ | ||
@@ -26,0 +26,0 @@ export function toString (matrix) { |
/** | ||
* Merge multiple matrices into one | ||
* @param matrices {...object} list of matrices | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param matrices {Matrix[]} Array of affine matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -38,5 +38,5 @@ export function transform (...matrices) { | ||
/** | ||
* Merge multiple matrices into one (alias of `transform`) | ||
* @param matrices {...object} list of matrices | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* Merge multiple matrices into one | ||
* @param matrices {Matrix[]} Array of matrix | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -43,0 +43,0 @@ export function compose (...matrices) { |
/** | ||
* Calculate a translate matrix | ||
* @param tx Translation on axis x | ||
* @param [ty = 0] Translation on axis y | ||
* @returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | ||
* @param tx {number} Translation on axis x | ||
* @param [ty = 0] {number} Translation on axis y | ||
* @returns {Matrix} Affine Matrix | ||
*/ | ||
@@ -7,0 +7,0 @@ export function translate (tx, ty = 0) { |
export function isUndefined (val) { | ||
return typeof val === 'undefined' | ||
} | ||
export function isNumeric (n) { | ||
return typeof n === 'number' && | ||
!Number.isNaN(n) && | ||
Number.isFinite(n) | ||
} | ||
export function isObject (obj) { | ||
return typeof obj === 'object' && | ||
obj !== null && | ||
!Array.isArray(obj) | ||
} | ||
export function matchesShape (obj, keys) { | ||
return keys.every(key => key in obj) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
417204
16
521
51
5992