transformation-matrix.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["TransformationMatrix"] = factory();
  8. else
  9. root["TransformationMatrix"] = factory();
  10. })(window, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 0);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ([
  98. /* 0 */
  99. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  100. "use strict";
  101. __webpack_require__.r(__webpack_exports__);
  102. // CONCATENATED MODULE: ./src/applyToPoint.js
  103. /**
  104. * Calculate a point transformed with an affine matrix
  105. * @param matrix {Matrix} Affine Matrix
  106. * @param point {Point} Point
  107. * @returns {Point} Point
  108. */
  109. function applyToPoint(matrix, point) {
  110. return Array.isArray(point) ? [matrix.a * point[0] + matrix.c * point[1] + matrix.e, matrix.b * point[0] + matrix.d * point[1] + matrix.f] : {
  111. x: matrix.a * point.x + matrix.c * point.y + matrix.e,
  112. y: matrix.b * point.x + matrix.d * point.y + matrix.f
  113. };
  114. }
  115. /**
  116. * Calculate an array of points transformed with an affine matrix
  117. * @param matrix {Matrix} Affine Matrix
  118. * @param points {Point[]} Array of point
  119. * @returns {Point[]} Array of point
  120. */
  121. function applyToPoints(matrix, points) {
  122. return points.map(function (point) {
  123. return applyToPoint(matrix, point);
  124. });
  125. }
  126. // CONCATENATED MODULE: ./src/fromObject.js
  127. /**
  128. * Extract an affine matrix from an object that contains a,b,c,d,e,f keys
  129. * Any value could be a float or a string that contains a float
  130. * @param object {Object} Object that contains a,b,c,d,e,f keys
  131. * @return {Matrix} Affine Matrix
  132. */
  133. function fromObject(object) {
  134. return {
  135. a: parseFloat(object.a),
  136. b: parseFloat(object.b),
  137. c: parseFloat(object.c),
  138. d: parseFloat(object.d),
  139. e: parseFloat(object.e),
  140. f: parseFloat(object.f)
  141. };
  142. }
  143. // CONCATENATED MODULE: ./src/fromString.js
  144. /**
  145. * @ignore
  146. * @type {RegExp}
  147. */
  148. 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;
  149. /**
  150. * Parse a string formatted as matrix(a,b,c,d,e,f)
  151. * @param string {string} String with an affine matrix
  152. * @returns {Matrix} Affine Matrix
  153. *
  154. * @example
  155. * > fromString('matrix(1,2,3,4,5,6)')
  156. * {a: 1, b: 2, c: 3, d: 4, c: 5, e: 6}
  157. */
  158. function fromString(string) {
  159. var parsed = string.match(matrixRegex);
  160. if (parsed === null || parsed.length < 7) throw new Error("'".concat(string, "' is not a matrix"));
  161. return {
  162. a: parseFloat(parsed[1]),
  163. b: parseFloat(parsed[2]),
  164. c: parseFloat(parsed[3]),
  165. d: parseFloat(parsed[4]),
  166. e: parseFloat(parsed[5]),
  167. f: parseFloat(parsed[6])
  168. };
  169. }
  170. // CONCATENATED MODULE: ./src/identity.js
  171. /**
  172. * Identity matrix
  173. * @returns {Matrix} Affine Matrix
  174. */
  175. function identity() {
  176. return {
  177. a: 1,
  178. c: 0,
  179. e: 0,
  180. b: 0,
  181. d: 1,
  182. f: 0
  183. };
  184. }
  185. // CONCATENATED MODULE: ./src/inverse.js
  186. /**
  187. * Calculate a matrix that is the inverse of the provided matrix
  188. * @param matrix {Matrix} Affine Matrix
  189. * @returns {Matrix} Inverted Affine Matrix
  190. */
  191. function inverse(matrix) {
  192. // http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D
  193. var a = matrix.a,
  194. b = matrix.b,
  195. c = matrix.c,
  196. d = matrix.d,
  197. e = matrix.e,
  198. f = matrix.f;
  199. var denom = a * d - b * c;
  200. return {
  201. a: d / denom,
  202. b: b / -denom,
  203. c: c / -denom,
  204. d: a / denom,
  205. e: (d * e - c * f) / -denom,
  206. f: (b * e - a * f) / denom
  207. };
  208. }
  209. // CONCATENATED MODULE: ./src/utils.js
  210. 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); }
  211. function isUndefined(val) {
  212. return typeof val === 'undefined';
  213. }
  214. function isNumeric(n) {
  215. return typeof n === 'number' && !Number.isNaN(n) && Number.isFinite(n);
  216. }
  217. function isObject(obj) {
  218. return _typeof(obj) === 'object' && obj !== null && !Array.isArray(obj);
  219. }
  220. function matchesShape(obj, keys) {
  221. return keys.every(function (key) {
  222. return key in obj;
  223. });
  224. }
  225. // CONCATENATED MODULE: ./src/isAffineMatrix.js
  226. /**
  227. * Check if the object contain an affine matrix
  228. * @param object {Object} Generic Plain Object
  229. * @return {boolean} True if is an object and contains an affine matrix
  230. */
  231. function isAffineMatrix(object) {
  232. return isObject(object) && 'a' in object && isNumeric(object.a) && 'b' in object && isNumeric(object.b) && 'c' in object && isNumeric(object.c) && 'd' in object && isNumeric(object.d) && 'e' in object && isNumeric(object.e) && 'f' in object && isNumeric(object.f);
  233. }
  234. // CONCATENATED MODULE: ./src/translate.js
  235. /**
  236. * Calculate a translate matrix
  237. * @param tx {number} Translation on axis x
  238. * @param [ty = 0] {number} Translation on axis y
  239. * @returns {Matrix} Affine Matrix
  240. */
  241. function translate(tx) {
  242. var ty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  243. return {
  244. a: 1,
  245. c: 0,
  246. e: tx,
  247. b: 0,
  248. d: 1,
  249. f: ty
  250. };
  251. }
  252. // CONCATENATED MODULE: ./src/transform.js
  253. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
  254. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
  255. 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; } }
  256. function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
  257. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  258. function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
  259. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  260. /**
  261. * Merge multiple matrices into one
  262. * @param matrices {...Matrix | Matrix[]} Matrices listed as separate parameters or in an array
  263. * @returns {Matrix} Affine Matrix
  264. */
  265. function transform() {
  266. for (var _len = arguments.length, matrices = new Array(_len), _key = 0; _key < _len; _key++) {
  267. matrices[_key] = arguments[_key];
  268. }
  269. matrices = Array.isArray(matrices[0]) ? matrices[0] : matrices;
  270. var multiply = function multiply(m1, m2) {
  271. return {
  272. a: m1.a * m2.a + m1.c * m2.b,
  273. c: m1.a * m2.c + m1.c * m2.d,
  274. e: m1.a * m2.e + m1.c * m2.f + m1.e,
  275. b: m1.b * m2.a + m1.d * m2.b,
  276. d: m1.b * m2.c + m1.d * m2.d,
  277. f: m1.b * m2.e + m1.d * m2.f + m1.f
  278. };
  279. };
  280. switch (matrices.length) {
  281. case 0:
  282. throw new Error('no matrices provided');
  283. case 1:
  284. return matrices[0];
  285. case 2:
  286. return multiply(matrices[0], matrices[1]);
  287. default:
  288. {
  289. var _matrices = matrices,
  290. _matrices2 = _toArray(_matrices),
  291. m1 = _matrices2[0],
  292. m2 = _matrices2[1],
  293. rest = _matrices2.slice(2);
  294. var m = multiply(m1, m2);
  295. return transform.apply(void 0, [m].concat(_toConsumableArray(rest)));
  296. }
  297. }
  298. }
  299. /**
  300. * Merge multiple matrices into one
  301. * @param matrices {...Matrix | Matrix[]} Matrices listed as separate parameters or in an array
  302. * @returns {Matrix} Affine Matrix
  303. */
  304. function compose() {
  305. return transform.apply(void 0, arguments);
  306. }
  307. // CONCATENATED MODULE: ./src/rotate.js
  308. var cos = Math.cos,
  309. sin = Math.sin,
  310. PI = Math.PI;
  311. /**
  312. * Calculate a rotation matrix
  313. * @param angle {number} Angle in radians
  314. * @param [cx] {number} If (cx,cy) are supplied the rotate is about this point
  315. * @param [cy] {number} If (cx,cy) are supplied the rotate is about this point
  316. * @returns {Matrix} Affine Matrix
  317. */
  318. function rotate(angle, cx, cy) {
  319. var cosAngle = cos(angle);
  320. var sinAngle = sin(angle);
  321. var rotationMatrix = {
  322. a: cosAngle,
  323. c: -sinAngle,
  324. e: 0,
  325. b: sinAngle,
  326. d: cosAngle,
  327. f: 0
  328. };
  329. if (isUndefined(cx) || isUndefined(cy)) {
  330. return rotationMatrix;
  331. }
  332. return transform([translate(cx, cy), rotationMatrix, translate(-cx, -cy)]);
  333. }
  334. /**
  335. * Calculate a rotation matrix with a DEG angle
  336. * @param angle {number} Angle in degree
  337. * @param [cx] {number} If (cx,cy) are supplied the rotate is about this point
  338. * @param [cy] {number} If (cx,cy) are supplied the rotate is about this point
  339. * @returns {Matrix} Affine Matrix
  340. */
  341. function rotateDEG(angle) {
  342. var cx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
  343. var cy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
  344. return rotate(angle * PI / 180, cx, cy);
  345. }
  346. // CONCATENATED MODULE: ./src/scale.js
  347. /**
  348. * Calculate a scaling matrix
  349. * @param sx {number} Scaling on axis x
  350. * @param [sy = sx] {number} Scaling on axis y (default sx)
  351. * @returns {Matrix} Affine Matrix
  352. */
  353. function scale(sx) {
  354. var sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
  355. if (isUndefined(sy)) sy = sx;
  356. return {
  357. a: sx,
  358. c: 0,
  359. e: 0,
  360. b: 0,
  361. d: sy,
  362. f: 0
  363. };
  364. }
  365. // CONCATENATED MODULE: ./src/shear.js
  366. /**
  367. * Calculate a shear matrix
  368. * @param shx {number} Shear on axis x
  369. * @param shy {number} Shear on axis y
  370. * @returns {Matrix} Affine Matrix
  371. */
  372. function shear(shx, shy) {
  373. return {
  374. a: 1,
  375. c: shx,
  376. e: 0,
  377. b: shy,
  378. d: 1,
  379. f: 0
  380. };
  381. }
  382. // CONCATENATED MODULE: ./src/skew.js
  383. // https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew
  384. var tan = Math.tan;
  385. /**
  386. * Calculate a skew matrix
  387. * @param ax {number} Skew on axis x
  388. * @param ay {number} Skew on axis y
  389. * @returns {Matrix} Affine Matrix
  390. */
  391. function skew(ax, ay) {
  392. return {
  393. a: 1,
  394. c: tan(ax),
  395. e: 0,
  396. b: tan(ay),
  397. d: 1,
  398. f: 0
  399. };
  400. }
  401. /**
  402. * Calculate a skew matrix using DEG angles
  403. * @param ax {number} Skew on axis x
  404. * @param ay {number} Skew on axis y
  405. * @returns {Matrix} Affine Matrix
  406. */
  407. function skewDEG(ax, ay) {
  408. return skew(ax * Math.PI / 180, ay * Math.PI / 180);
  409. }
  410. // CONCATENATED MODULE: ./src/toString.js
  411. /**
  412. * Serialize an affine matrix to a string that can be used with CSS or SVG
  413. * @param matrix {Matrix} Affine Matrix
  414. * @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f)
  415. */
  416. function toCSS(matrix) {
  417. return toString_toString(matrix);
  418. }
  419. /**
  420. * Serialize an affine matrix to a string that can be used with CSS or SVG
  421. * @param matrix {Matrix} Affine Matrix
  422. * @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f)
  423. */
  424. function toSVG(matrix) {
  425. return toString_toString(matrix);
  426. }
  427. /**
  428. * Serialize an affine matrix to a string that can be used with CSS or SVG
  429. * @param matrix {Matrix} Affine Matrix
  430. * @returns {string} String that contains an affine matrix formatted as matrix(a,b,c,d,e,f)
  431. */
  432. function toString_toString(matrix) {
  433. return "matrix(".concat(matrix.a, ",").concat(matrix.b, ",").concat(matrix.c, ",").concat(matrix.d, ",").concat(matrix.e, ",").concat(matrix.f, ")");
  434. }
  435. // CONCATENATED MODULE: ./src/smoothMatrix.js
  436. /**
  437. * Rounds all elements of the given matrix using the given precision
  438. * @param matrix {Matrix} An affine matrix to round
  439. * @param [precision] {number} A precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma).
  440. * @returns {Matrix} The rounded Affine Matrix
  441. */
  442. function smoothMatrix(matrix) {
  443. var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10000000000;
  444. return {
  445. a: Math.round(matrix.a * precision) / precision,
  446. b: Math.round(matrix.b * precision) / precision,
  447. c: Math.round(matrix.c * precision) / precision,
  448. d: Math.round(matrix.d * precision) / precision,
  449. e: Math.round(matrix.e * precision) / precision,
  450. f: Math.round(matrix.f * precision) / precision
  451. };
  452. }
  453. // CONCATENATED MODULE: ./src/fromTriangles.js
  454. /**
  455. * Returns a matrix that transforms a triangle t1 into another triangle t2, or throws an exception if it is impossible.
  456. * @param t1 {Point[]} Array of points containing the three points for the first triangle
  457. * @param t2 {Point[]} Array of points containing the three points for the second triangle
  458. * @returns {Matrix} Matrix which transforms t1 to t2
  459. * @throws Exception if the matrix becomes not invertible
  460. */
  461. function fromTriangles(t1, t2) {
  462. // point p = first point of the triangle
  463. var px1 = t1[0].x != null ? t1[0].x : t1[0][0];
  464. var py1 = t1[0].y != null ? t1[0].y : t1[0][1];
  465. var px2 = t2[0].x != null ? t2[0].x : t2[0][0];
  466. var py2 = t2[0].y != null ? t2[0].y : t2[0][1]; // point q = second point of the triangle
  467. var qx1 = t1[1].x != null ? t1[1].x : t1[1][0];
  468. var qy1 = t1[1].y != null ? t1[1].y : t1[1][1];
  469. var qx2 = t2[1].x != null ? t2[1].x : t2[1][0];
  470. var qy2 = t2[1].y != null ? t2[1].y : t2[1][1]; // point r = third point of the triangle
  471. var rx1 = t1[2].x != null ? t1[2].x : t1[2][0];
  472. var ry1 = t1[2].y != null ? t1[2].y : t1[2][1];
  473. var rx2 = t2[2].x != null ? t2[2].x : t2[2][0];
  474. var ry2 = t2[2].y != null ? t2[2].y : t2[2][1];
  475. var r1 = {
  476. a: px1 - rx1,
  477. b: py1 - ry1,
  478. c: qx1 - rx1,
  479. d: qy1 - ry1,
  480. e: rx1,
  481. f: ry1
  482. };
  483. var r2 = {
  484. a: px2 - rx2,
  485. b: py2 - ry2,
  486. c: qx2 - rx2,
  487. d: qy2 - ry2,
  488. e: rx2,
  489. f: ry2
  490. };
  491. var inverseR1 = inverse(r1);
  492. var affineMatrix = transform([r2, inverseR1]); // round the matrix elements to smooth the finite inversion
  493. return smoothMatrix(affineMatrix);
  494. }
  495. // CONCATENATED MODULE: ./src/fromDefinition.js
  496. /**
  497. * Converts array of matrix descriptor to array of matrix
  498. * @param definitionOrArrayOfDefinition {Object[]} Array of object describing the matrix
  499. * @returns {Matrix[]} Array of matrix
  500. *
  501. * @example
  502. * > fromDefinition([
  503. * { type: 'matrix', a:1, b:2, c:3, d:4, e:5, f:6 },
  504. * { type: 'translate', tx: 10, ty: 20 },
  505. * { type: 'scale', sx: 2, sy: 4 },
  506. * { type: 'rotate', angle: 90, cx: 50, cy: 25 },
  507. * { type: 'skewX', angle: 45 },
  508. * { type: 'skewY', angle: 45 },
  509. * { type: 'shear', shx: 10, shy: 20}
  510. * ])
  511. *
  512. * [
  513. * { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 },
  514. * { a: 1, c: 0, e: 10, b: 0, d: 1, f: 20 },
  515. * { a: 2, c: 0, e: 0, b: 0, d: 4, f: 0 },
  516. * { a: 6.123, c: -1, e: 0, b: 1, d: 6.123, f: 0 },
  517. * { a: 1, c: 0.99.., e: 0, b: 0, d: 1, f: 0 },
  518. * { a: 1, c: 0, e: 0, b: 0.99, d: 1, f: 0 },
  519. * { a: 1, c: 10, e: 0, b: 20, d: 1, f: 0 }
  520. * ]
  521. **/
  522. function fromDefinition(definitionOrArrayOfDefinition) {
  523. return Array.isArray(definitionOrArrayOfDefinition) ? definitionOrArrayOfDefinition.map(mapper) : mapper(definitionOrArrayOfDefinition);
  524. function mapper(descriptor) {
  525. switch (descriptor.type) {
  526. case 'matrix':
  527. if ('a' in descriptor && 'b' in descriptor && 'c' in descriptor && 'd' in descriptor && 'e' in descriptor && 'f' in descriptor) {
  528. return fromObject(descriptor);
  529. } else {
  530. throw new Error('MISSING_MANDATORY_PARAM');
  531. }
  532. case 'translate':
  533. if (!('tx' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM');
  534. if ('ty' in descriptor) return translate(descriptor.tx, descriptor.ty);
  535. return translate(descriptor.tx);
  536. case 'scale':
  537. if (!('sx' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM');
  538. if ('sy' in descriptor) return scale(descriptor.sx, descriptor.sy);
  539. return scale(descriptor.sx);
  540. case 'rotate':
  541. if (!('angle' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM');
  542. if ('cx' in descriptor && 'cy' in descriptor) {
  543. return rotateDEG(descriptor.angle, descriptor.cx, descriptor.cy);
  544. }
  545. return rotateDEG(descriptor.angle);
  546. case 'skewX':
  547. if (!('angle' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM');
  548. return skewDEG(descriptor.angle, 0);
  549. case 'skewY':
  550. if (!('angle' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM');
  551. return skewDEG(0, descriptor.angle);
  552. case 'shear':
  553. if (!('shx' in descriptor && 'shy' in descriptor)) throw new Error('MISSING_MANDATORY_PARAM');
  554. return shear(descriptor.shx, descriptor.shy);
  555. default:
  556. throw new Error('UNSUPPORTED_DESCRIPTOR');
  557. }
  558. }
  559. }
  560. // CONCATENATED MODULE: ./src/fromTransformAttribute.autogenerated.js
  561. // Generated by PEG.js v0.11.0-master.30f3260, https://pegjs.org/
  562. function peg$subclass(child, parent) {
  563. function C() {
  564. this.constructor = child;
  565. }
  566. C.prototype = parent.prototype;
  567. child.prototype = new C();
  568. }
  569. function peg$SyntaxError(message, expected, found, location) {
  570. this.message = message;
  571. this.expected = expected;
  572. this.found = found;
  573. this.location = location;
  574. this.name = "SyntaxError"; // istanbul ignore next
  575. if (typeof Error.captureStackTrace === "function") {
  576. Error.captureStackTrace(this, peg$SyntaxError);
  577. }
  578. }
  579. peg$subclass(peg$SyntaxError, Error);
  580. peg$SyntaxError.buildMessage = function (expected, found) {
  581. var DESCRIBE_EXPECTATION_FNS = {
  582. literal: function literal(expectation) {
  583. return "\"" + literalEscape(expectation.text) + "\"";
  584. },
  585. "class": function _class(expectation) {
  586. var escapedParts = expectation.parts.map(function (part) {
  587. return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part);
  588. });
  589. return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
  590. },
  591. any: function any() {
  592. return "any character";
  593. },
  594. end: function end() {
  595. return "end of input";
  596. },
  597. other: function other(expectation) {
  598. return expectation.description;
  599. },
  600. not: function not(expectation) {
  601. return "not " + describeExpectation(expectation.expected);
  602. }
  603. };
  604. function hex(ch) {
  605. return ch.charCodeAt(0).toString(16).toUpperCase();
  606. }
  607. function literalEscape(s) {
  608. 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) {
  609. return "\\x0" + hex(ch);
  610. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  611. return "\\x" + hex(ch);
  612. });
  613. }
  614. function classEscape(s) {
  615. 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) {
  616. return "\\x0" + hex(ch);
  617. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  618. return "\\x" + hex(ch);
  619. });
  620. }
  621. function describeExpectation(expectation) {
  622. return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
  623. }
  624. function describeExpected(expected) {
  625. var descriptions = expected.map(describeExpectation);
  626. var i, j;
  627. descriptions.sort();
  628. if (descriptions.length > 0) {
  629. for (i = 1, j = 1; i < descriptions.length; i++) {
  630. if (descriptions[i - 1] !== descriptions[i]) {
  631. descriptions[j] = descriptions[i];
  632. j++;
  633. }
  634. }
  635. descriptions.length = j;
  636. }
  637. switch (descriptions.length) {
  638. case 1:
  639. return descriptions[0];
  640. case 2:
  641. return descriptions[0] + " or " + descriptions[1];
  642. default:
  643. return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
  644. }
  645. }
  646. function describeFound(found) {
  647. return found ? "\"" + literalEscape(found) + "\"" : "end of input";
  648. }
  649. return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
  650. };
  651. function peg$parse(input, options) {
  652. options = options !== undefined ? options : {};
  653. var peg$FAILED = {};
  654. var peg$startRuleFunctions = {
  655. transformList: peg$parsetransformList
  656. };
  657. var peg$startRuleFunction = peg$parsetransformList;
  658. var peg$c0 = "matrix";
  659. var peg$c1 = "(";
  660. var peg$c2 = ")";
  661. var peg$c3 = "translate";
  662. var peg$c4 = "scale";
  663. var peg$c5 = "rotate";
  664. var peg$c6 = "skewX";
  665. var peg$c7 = "skewY";
  666. var peg$c8 = ",";
  667. var peg$c9 = ".";
  668. var peg$r0 = /^[eE]/;
  669. var peg$r1 = /^[+\-]/;
  670. var peg$r2 = /^[0-9]/;
  671. var peg$r3 = /^[ \t\r\n]/;
  672. var peg$e0 = peg$literalExpectation("matrix", false);
  673. var peg$e1 = peg$literalExpectation("(", false);
  674. var peg$e2 = peg$literalExpectation(")", false);
  675. var peg$e3 = peg$literalExpectation("translate", false);
  676. var peg$e4 = peg$literalExpectation("scale", false);
  677. var peg$e5 = peg$literalExpectation("rotate", false);
  678. var peg$e6 = peg$literalExpectation("skewX", false);
  679. var peg$e7 = peg$literalExpectation("skewY", false);
  680. var peg$e8 = peg$literalExpectation(",", false);
  681. var peg$e9 = peg$otherExpectation("fractionalConstant");
  682. var peg$e10 = peg$classExpectation(["e", "E"], false, false);
  683. var peg$e11 = peg$classExpectation(["+", "-"], false, false);
  684. var peg$e12 = peg$classExpectation([["0", "9"]], false, false);
  685. var peg$e13 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false);
  686. var peg$f0 = function peg$f0(ts) {
  687. return ts;
  688. };
  689. var peg$f1 = function peg$f1(t, ts) {
  690. return t.concat(ts);
  691. };
  692. var peg$f2 = function peg$f2(a, b, c, d, e, f) {
  693. return [{
  694. type: 'matrix',
  695. a: a,
  696. b: b,
  697. c: c,
  698. d: d,
  699. e: e,
  700. f: f
  701. }];
  702. };
  703. var peg$f3 = function peg$f3(tx, ty) {
  704. var t = {
  705. type: 'translate',
  706. tx: tx
  707. };
  708. if (ty) t.ty = ty;
  709. return [t];
  710. };
  711. var peg$f4 = function peg$f4(sx, sy) {
  712. var s = {
  713. type: 'scale',
  714. sx: sx
  715. };
  716. if (sy) s.sy = sy;
  717. return [s];
  718. };
  719. var peg$f5 = function peg$f5(angle, c) {
  720. var r = {
  721. type: 'rotate',
  722. angle: angle
  723. };
  724. if (c) {
  725. r.cx = c[0];
  726. r.cy = c[1];
  727. }
  728. return [r];
  729. };
  730. var peg$f6 = function peg$f6(angle) {
  731. return [{
  732. type: 'skewX',
  733. angle: angle
  734. }];
  735. };
  736. var peg$f7 = function peg$f7(angle) {
  737. return [{
  738. type: 'skewY',
  739. angle: angle
  740. }];
  741. };
  742. var peg$f8 = function peg$f8(f) {
  743. return parseFloat(f.join(""));
  744. };
  745. var peg$f9 = function peg$f9(i) {
  746. return parseInt(i.join(""));
  747. };
  748. var peg$f10 = function peg$f10(n) {
  749. return n;
  750. };
  751. var peg$f11 = function peg$f11(n1, n2) {
  752. return [n1, n2];
  753. };
  754. var peg$f12 = function peg$f12(ds) {
  755. return ds.join("");
  756. };
  757. var peg$f13 = function peg$f13(d1, d2) {
  758. return [d1 ? d1.join("") : null, ".", d2.join("")].join("");
  759. };
  760. var peg$f14 = function peg$f14(d) {
  761. return d.join("");
  762. };
  763. var peg$currPos = 0;
  764. var peg$savedPos = 0;
  765. var peg$posDetailsCache = [{
  766. line: 1,
  767. column: 1
  768. }];
  769. var peg$expected = [];
  770. var peg$silentFails = 0;
  771. var peg$result;
  772. if ("startRule" in options) {
  773. if (!(options.startRule in peg$startRuleFunctions)) {
  774. throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
  775. }
  776. peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
  777. }
  778. function text() {
  779. return input.substring(peg$savedPos, peg$currPos);
  780. }
  781. function offset() {
  782. return peg$savedPos;
  783. }
  784. function range() {
  785. return [peg$savedPos, peg$currPos];
  786. }
  787. function location() {
  788. return peg$computeLocation(peg$savedPos, peg$currPos);
  789. }
  790. function expected(description, location) {
  791. location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos);
  792. throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
  793. }
  794. function error(message, location) {
  795. location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos);
  796. throw peg$buildSimpleError(message, location);
  797. }
  798. function peg$literalExpectation(text, ignoreCase) {
  799. return {
  800. type: "literal",
  801. text: text,
  802. ignoreCase: ignoreCase
  803. };
  804. }
  805. function peg$classExpectation(parts, inverted, ignoreCase) {
  806. return {
  807. type: "class",
  808. parts: parts,
  809. inverted: inverted,
  810. ignoreCase: ignoreCase
  811. };
  812. }
  813. function peg$anyExpectation() {
  814. return {
  815. type: "any"
  816. };
  817. }
  818. function peg$endExpectation() {
  819. return {
  820. type: "end"
  821. };
  822. }
  823. function peg$otherExpectation(description) {
  824. return {
  825. type: "other",
  826. description: description
  827. };
  828. }
  829. function peg$computePosDetails(pos) {
  830. var details = peg$posDetailsCache[pos];
  831. var p;
  832. if (details) {
  833. return details;
  834. } else {
  835. p = pos - 1;
  836. while (!peg$posDetailsCache[p]) {
  837. p--;
  838. }
  839. details = peg$posDetailsCache[p];
  840. details = {
  841. line: details.line,
  842. column: details.column
  843. };
  844. while (p < pos) {
  845. if (input.charCodeAt(p) === 10) {
  846. details.line++;
  847. details.column = 1;
  848. } else {
  849. details.column++;
  850. }
  851. p++;
  852. }
  853. peg$posDetailsCache[pos] = details;
  854. return details;
  855. }
  856. }
  857. var peg$VALIDFILENAME = typeof options.filename === "string" && options.filename.length > 0;
  858. function peg$computeLocation(startPos, endPos) {
  859. var loc = {};
  860. if (peg$VALIDFILENAME) loc.filename = options.filename;
  861. var startPosDetails = peg$computePosDetails(startPos);
  862. loc.start = {
  863. offset: startPos,
  864. line: startPosDetails.line,
  865. column: startPosDetails.column
  866. };
  867. var endPosDetails = peg$computePosDetails(endPos);
  868. loc.end = {
  869. offset: endPos,
  870. line: endPosDetails.line,
  871. column: endPosDetails.column
  872. };
  873. return loc;
  874. }
  875. function peg$begin() {
  876. peg$expected.push({
  877. pos: peg$currPos,
  878. variants: []
  879. });
  880. }
  881. function peg$expect(expected) {
  882. var top = peg$expected[peg$expected.length - 1];
  883. if (peg$currPos < top.pos) {
  884. return;
  885. }
  886. if (peg$currPos > top.pos) {
  887. top.pos = peg$currPos;
  888. top.variants = [];
  889. }
  890. top.variants.push(expected);
  891. }
  892. function peg$end(invert) {
  893. var expected = peg$expected.pop();
  894. var top = peg$expected[peg$expected.length - 1];
  895. var variants = expected.variants;
  896. if (top.pos !== expected.pos) {
  897. return;
  898. }
  899. if (invert) {
  900. variants = variants.map(function (e) {
  901. return e.type === "not" ? e.expected : {
  902. type: "not",
  903. expected: e
  904. };
  905. });
  906. }
  907. Array.prototype.push.apply(top.variants, variants);
  908. }
  909. function peg$buildSimpleError(message, location) {
  910. return new peg$SyntaxError(message, null, null, location);
  911. }
  912. function peg$buildStructuredError(expected, found, location) {
  913. return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
  914. }
  915. function peg$buildError() {
  916. var expected = peg$expected[0];
  917. var failPos = expected.pos;
  918. return peg$buildStructuredError(expected.variants, failPos < input.length ? input.charAt(failPos) : null, failPos < input.length ? peg$computeLocation(failPos, failPos + 1) : peg$computeLocation(failPos, failPos));
  919. }
  920. function peg$parsetransformList() {
  921. var s0, s1, s2, s3, s4;
  922. var rule$expects = function rule$expects(expected) {
  923. if (peg$silentFails === 0) peg$expect(expected);
  924. };
  925. s0 = peg$currPos;
  926. s1 = [];
  927. s2 = peg$parsewsp();
  928. while (s2 !== peg$FAILED) {
  929. s1.push(s2);
  930. s2 = peg$parsewsp();
  931. }
  932. s2 = peg$parsetransforms();
  933. if (s2 === peg$FAILED) {
  934. s2 = null;
  935. }
  936. s3 = [];
  937. s4 = peg$parsewsp();
  938. while (s4 !== peg$FAILED) {
  939. s3.push(s4);
  940. s4 = peg$parsewsp();
  941. }
  942. peg$savedPos = s0;
  943. s0 = peg$f0(s2);
  944. return s0;
  945. }
  946. function peg$parsetransforms() {
  947. var s0, s1, s2, s3;
  948. var rule$expects = function rule$expects(expected) {
  949. if (peg$silentFails === 0) peg$expect(expected);
  950. };
  951. s0 = peg$currPos;
  952. s1 = peg$parsetransform();
  953. if (s1 !== peg$FAILED) {
  954. s2 = [];
  955. s3 = peg$parsecommaWsp();
  956. if (s3 !== peg$FAILED) {
  957. while (s3 !== peg$FAILED) {
  958. s2.push(s3);
  959. s3 = peg$parsecommaWsp();
  960. }
  961. } else {
  962. s2 = peg$FAILED;
  963. }
  964. if (s2 !== peg$FAILED) {
  965. s3 = peg$parsetransforms();
  966. if (s3 !== peg$FAILED) {
  967. peg$savedPos = s0;
  968. s0 = peg$f1(s1, s3);
  969. } else {
  970. peg$currPos = s0;
  971. s0 = peg$FAILED;
  972. }
  973. } else {
  974. peg$currPos = s0;
  975. s0 = peg$FAILED;
  976. }
  977. } else {
  978. peg$currPos = s0;
  979. s0 = peg$FAILED;
  980. }
  981. if (s0 === peg$FAILED) {
  982. s0 = peg$parsetransform();
  983. }
  984. return s0;
  985. }
  986. function peg$parsetransform() {
  987. var s0;
  988. var rule$expects = function rule$expects(expected) {
  989. if (peg$silentFails === 0) peg$expect(expected);
  990. };
  991. s0 = peg$parsematrix();
  992. if (s0 === peg$FAILED) {
  993. s0 = peg$parsetranslate();
  994. if (s0 === peg$FAILED) {
  995. s0 = peg$parsescale();
  996. if (s0 === peg$FAILED) {
  997. s0 = peg$parserotate();
  998. if (s0 === peg$FAILED) {
  999. s0 = peg$parseskewX();
  1000. if (s0 === peg$FAILED) {
  1001. s0 = peg$parseskewY();
  1002. }
  1003. }
  1004. }
  1005. }
  1006. }
  1007. return s0;
  1008. }
  1009. function peg$parsematrix() {
  1010. var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17;
  1011. var rule$expects = function rule$expects(expected) {
  1012. if (peg$silentFails === 0) peg$expect(expected);
  1013. };
  1014. s0 = peg$currPos;
  1015. rule$expects(peg$e0);
  1016. if (input.substr(peg$currPos, 6) === peg$c0) {
  1017. s1 = peg$c0;
  1018. peg$currPos += 6;
  1019. } else {
  1020. s1 = peg$FAILED;
  1021. }
  1022. if (s1 !== peg$FAILED) {
  1023. s2 = [];
  1024. s3 = peg$parsewsp();
  1025. while (s3 !== peg$FAILED) {
  1026. s2.push(s3);
  1027. s3 = peg$parsewsp();
  1028. }
  1029. rule$expects(peg$e1);
  1030. if (input.charCodeAt(peg$currPos) === 40) {
  1031. s3 = peg$c1;
  1032. peg$currPos++;
  1033. } else {
  1034. s3 = peg$FAILED;
  1035. }
  1036. if (s3 !== peg$FAILED) {
  1037. s4 = [];
  1038. s5 = peg$parsewsp();
  1039. while (s5 !== peg$FAILED) {
  1040. s4.push(s5);
  1041. s5 = peg$parsewsp();
  1042. }
  1043. s5 = peg$parsenumber();
  1044. if (s5 !== peg$FAILED) {
  1045. s6 = peg$parsecommaWsp();
  1046. if (s6 !== peg$FAILED) {
  1047. s7 = peg$parsenumber();
  1048. if (s7 !== peg$FAILED) {
  1049. s8 = peg$parsecommaWsp();
  1050. if (s8 !== peg$FAILED) {
  1051. s9 = peg$parsenumber();
  1052. if (s9 !== peg$FAILED) {
  1053. s10 = peg$parsecommaWsp();
  1054. if (s10 !== peg$FAILED) {
  1055. s11 = peg$parsenumber();
  1056. if (s11 !== peg$FAILED) {
  1057. s12 = peg$parsecommaWsp();
  1058. if (s12 !== peg$FAILED) {
  1059. s13 = peg$parsenumber();
  1060. if (s13 !== peg$FAILED) {
  1061. s14 = peg$parsecommaWsp();
  1062. if (s14 !== peg$FAILED) {
  1063. s15 = peg$parsenumber();
  1064. if (s15 !== peg$FAILED) {
  1065. s16 = [];
  1066. s17 = peg$parsewsp();
  1067. while (s17 !== peg$FAILED) {
  1068. s16.push(s17);
  1069. s17 = peg$parsewsp();
  1070. }
  1071. rule$expects(peg$e2);
  1072. if (input.charCodeAt(peg$currPos) === 41) {
  1073. s17 = peg$c2;
  1074. peg$currPos++;
  1075. } else {
  1076. s17 = peg$FAILED;
  1077. }
  1078. if (s17 !== peg$FAILED) {
  1079. peg$savedPos = s0;
  1080. s0 = peg$f2(s5, s7, s9, s11, s13, s15);
  1081. } else {
  1082. peg$currPos = s0;
  1083. s0 = peg$FAILED;
  1084. }
  1085. } else {
  1086. peg$currPos = s0;
  1087. s0 = peg$FAILED;
  1088. }
  1089. } else {
  1090. peg$currPos = s0;
  1091. s0 = peg$FAILED;
  1092. }
  1093. } else {
  1094. peg$currPos = s0;
  1095. s0 = peg$FAILED;
  1096. }
  1097. } else {
  1098. peg$currPos = s0;
  1099. s0 = peg$FAILED;
  1100. }
  1101. } else {
  1102. peg$currPos = s0;
  1103. s0 = peg$FAILED;
  1104. }
  1105. } else {
  1106. peg$currPos = s0;
  1107. s0 = peg$FAILED;
  1108. }
  1109. } else {
  1110. peg$currPos = s0;
  1111. s0 = peg$FAILED;
  1112. }
  1113. } else {
  1114. peg$currPos = s0;
  1115. s0 = peg$FAILED;
  1116. }
  1117. } else {
  1118. peg$currPos = s0;
  1119. s0 = peg$FAILED;
  1120. }
  1121. } else {
  1122. peg$currPos = s0;
  1123. s0 = peg$FAILED;
  1124. }
  1125. } else {
  1126. peg$currPos = s0;
  1127. s0 = peg$FAILED;
  1128. }
  1129. } else {
  1130. peg$currPos = s0;
  1131. s0 = peg$FAILED;
  1132. }
  1133. } else {
  1134. peg$currPos = s0;
  1135. s0 = peg$FAILED;
  1136. }
  1137. return s0;
  1138. }
  1139. function peg$parsetranslate() {
  1140. var s0, s1, s2, s3, s4, s5, s6, s7, s8;
  1141. var rule$expects = function rule$expects(expected) {
  1142. if (peg$silentFails === 0) peg$expect(expected);
  1143. };
  1144. s0 = peg$currPos;
  1145. rule$expects(peg$e3);
  1146. if (input.substr(peg$currPos, 9) === peg$c3) {
  1147. s1 = peg$c3;
  1148. peg$currPos += 9;
  1149. } else {
  1150. s1 = peg$FAILED;
  1151. }
  1152. if (s1 !== peg$FAILED) {
  1153. s2 = [];
  1154. s3 = peg$parsewsp();
  1155. while (s3 !== peg$FAILED) {
  1156. s2.push(s3);
  1157. s3 = peg$parsewsp();
  1158. }
  1159. rule$expects(peg$e1);
  1160. if (input.charCodeAt(peg$currPos) === 40) {
  1161. s3 = peg$c1;
  1162. peg$currPos++;
  1163. } else {
  1164. s3 = peg$FAILED;
  1165. }
  1166. if (s3 !== peg$FAILED) {
  1167. s4 = [];
  1168. s5 = peg$parsewsp();
  1169. while (s5 !== peg$FAILED) {
  1170. s4.push(s5);
  1171. s5 = peg$parsewsp();
  1172. }
  1173. s5 = peg$parsenumber();
  1174. if (s5 !== peg$FAILED) {
  1175. s6 = peg$parsecommaWspNumber();
  1176. if (s6 === peg$FAILED) {
  1177. s6 = null;
  1178. }
  1179. s7 = [];
  1180. s8 = peg$parsewsp();
  1181. while (s8 !== peg$FAILED) {
  1182. s7.push(s8);
  1183. s8 = peg$parsewsp();
  1184. }
  1185. rule$expects(peg$e2);
  1186. if (input.charCodeAt(peg$currPos) === 41) {
  1187. s8 = peg$c2;
  1188. peg$currPos++;
  1189. } else {
  1190. s8 = peg$FAILED;
  1191. }
  1192. if (s8 !== peg$FAILED) {
  1193. peg$savedPos = s0;
  1194. s0 = peg$f3(s5, s6);
  1195. } else {
  1196. peg$currPos = s0;
  1197. s0 = peg$FAILED;
  1198. }
  1199. } else {
  1200. peg$currPos = s0;
  1201. s0 = peg$FAILED;
  1202. }
  1203. } else {
  1204. peg$currPos = s0;
  1205. s0 = peg$FAILED;
  1206. }
  1207. } else {
  1208. peg$currPos = s0;
  1209. s0 = peg$FAILED;
  1210. }
  1211. return s0;
  1212. }
  1213. function peg$parsescale() {
  1214. var s0, s1, s2, s3, s4, s5, s6, s7, s8;
  1215. var rule$expects = function rule$expects(expected) {
  1216. if (peg$silentFails === 0) peg$expect(expected);
  1217. };
  1218. s0 = peg$currPos;
  1219. rule$expects(peg$e4);
  1220. if (input.substr(peg$currPos, 5) === peg$c4) {
  1221. s1 = peg$c4;
  1222. peg$currPos += 5;
  1223. } else {
  1224. s1 = peg$FAILED;
  1225. }
  1226. if (s1 !== peg$FAILED) {
  1227. s2 = [];
  1228. s3 = peg$parsewsp();
  1229. while (s3 !== peg$FAILED) {
  1230. s2.push(s3);
  1231. s3 = peg$parsewsp();
  1232. }
  1233. rule$expects(peg$e1);
  1234. if (input.charCodeAt(peg$currPos) === 40) {
  1235. s3 = peg$c1;
  1236. peg$currPos++;
  1237. } else {
  1238. s3 = peg$FAILED;
  1239. }
  1240. if (s3 !== peg$FAILED) {
  1241. s4 = [];
  1242. s5 = peg$parsewsp();
  1243. while (s5 !== peg$FAILED) {
  1244. s4.push(s5);
  1245. s5 = peg$parsewsp();
  1246. }
  1247. s5 = peg$parsenumber();
  1248. if (s5 !== peg$FAILED) {
  1249. s6 = peg$parsecommaWspNumber();
  1250. if (s6 === peg$FAILED) {
  1251. s6 = null;
  1252. }
  1253. s7 = [];
  1254. s8 = peg$parsewsp();
  1255. while (s8 !== peg$FAILED) {
  1256. s7.push(s8);
  1257. s8 = peg$parsewsp();
  1258. }
  1259. rule$expects(peg$e2);
  1260. if (input.charCodeAt(peg$currPos) === 41) {
  1261. s8 = peg$c2;
  1262. peg$currPos++;
  1263. } else {
  1264. s8 = peg$FAILED;
  1265. }
  1266. if (s8 !== peg$FAILED) {
  1267. peg$savedPos = s0;
  1268. s0 = peg$f4(s5, s6);
  1269. } else {
  1270. peg$currPos = s0;
  1271. s0 = peg$FAILED;
  1272. }
  1273. } else {
  1274. peg$currPos = s0;
  1275. s0 = peg$FAILED;
  1276. }
  1277. } else {
  1278. peg$currPos = s0;
  1279. s0 = peg$FAILED;
  1280. }
  1281. } else {
  1282. peg$currPos = s0;
  1283. s0 = peg$FAILED;
  1284. }
  1285. return s0;
  1286. }
  1287. function peg$parserotate() {
  1288. var s0, s1, s2, s3, s4, s5, s6, s7, s8;
  1289. var rule$expects = function rule$expects(expected) {
  1290. if (peg$silentFails === 0) peg$expect(expected);
  1291. };
  1292. s0 = peg$currPos;
  1293. rule$expects(peg$e5);
  1294. if (input.substr(peg$currPos, 6) === peg$c5) {
  1295. s1 = peg$c5;
  1296. peg$currPos += 6;
  1297. } else {
  1298. s1 = peg$FAILED;
  1299. }
  1300. if (s1 !== peg$FAILED) {
  1301. s2 = [];
  1302. s3 = peg$parsewsp();
  1303. while (s3 !== peg$FAILED) {
  1304. s2.push(s3);
  1305. s3 = peg$parsewsp();
  1306. }
  1307. rule$expects(peg$e1);
  1308. if (input.charCodeAt(peg$currPos) === 40) {
  1309. s3 = peg$c1;
  1310. peg$currPos++;
  1311. } else {
  1312. s3 = peg$FAILED;
  1313. }
  1314. if (s3 !== peg$FAILED) {
  1315. s4 = [];
  1316. s5 = peg$parsewsp();
  1317. while (s5 !== peg$FAILED) {
  1318. s4.push(s5);
  1319. s5 = peg$parsewsp();
  1320. }
  1321. s5 = peg$parsenumber();
  1322. if (s5 !== peg$FAILED) {
  1323. s6 = peg$parsecommaWspTwoNumbers();
  1324. if (s6 === peg$FAILED) {
  1325. s6 = null;
  1326. }
  1327. s7 = [];
  1328. s8 = peg$parsewsp();
  1329. while (s8 !== peg$FAILED) {
  1330. s7.push(s8);
  1331. s8 = peg$parsewsp();
  1332. }
  1333. rule$expects(peg$e2);
  1334. if (input.charCodeAt(peg$currPos) === 41) {
  1335. s8 = peg$c2;
  1336. peg$currPos++;
  1337. } else {
  1338. s8 = peg$FAILED;
  1339. }
  1340. if (s8 !== peg$FAILED) {
  1341. peg$savedPos = s0;
  1342. s0 = peg$f5(s5, s6);
  1343. } else {
  1344. peg$currPos = s0;
  1345. s0 = peg$FAILED;
  1346. }
  1347. } else {
  1348. peg$currPos = s0;
  1349. s0 = peg$FAILED;
  1350. }
  1351. } else {
  1352. peg$currPos = s0;
  1353. s0 = peg$FAILED;
  1354. }
  1355. } else {
  1356. peg$currPos = s0;
  1357. s0 = peg$FAILED;
  1358. }
  1359. return s0;
  1360. }
  1361. function peg$parseskewX() {
  1362. var s0, s1, s2, s3, s4, s5, s6, s7;
  1363. var rule$expects = function rule$expects(expected) {
  1364. if (peg$silentFails === 0) peg$expect(expected);
  1365. };
  1366. s0 = peg$currPos;
  1367. rule$expects(peg$e6);
  1368. if (input.substr(peg$currPos, 5) === peg$c6) {
  1369. s1 = peg$c6;
  1370. peg$currPos += 5;
  1371. } else {
  1372. s1 = peg$FAILED;
  1373. }
  1374. if (s1 !== peg$FAILED) {
  1375. s2 = [];
  1376. s3 = peg$parsewsp();
  1377. while (s3 !== peg$FAILED) {
  1378. s2.push(s3);
  1379. s3 = peg$parsewsp();
  1380. }
  1381. rule$expects(peg$e1);
  1382. if (input.charCodeAt(peg$currPos) === 40) {
  1383. s3 = peg$c1;
  1384. peg$currPos++;
  1385. } else {
  1386. s3 = peg$FAILED;
  1387. }
  1388. if (s3 !== peg$FAILED) {
  1389. s4 = [];
  1390. s5 = peg$parsewsp();
  1391. while (s5 !== peg$FAILED) {
  1392. s4.push(s5);
  1393. s5 = peg$parsewsp();
  1394. }
  1395. s5 = peg$parsenumber();
  1396. if (s5 !== peg$FAILED) {
  1397. s6 = [];
  1398. s7 = peg$parsewsp();
  1399. while (s7 !== peg$FAILED) {
  1400. s6.push(s7);
  1401. s7 = peg$parsewsp();
  1402. }
  1403. rule$expects(peg$e2);
  1404. if (input.charCodeAt(peg$currPos) === 41) {
  1405. s7 = peg$c2;
  1406. peg$currPos++;
  1407. } else {
  1408. s7 = peg$FAILED;
  1409. }
  1410. if (s7 !== peg$FAILED) {
  1411. peg$savedPos = s0;
  1412. s0 = peg$f6(s5);
  1413. } else {
  1414. peg$currPos = s0;
  1415. s0 = peg$FAILED;
  1416. }
  1417. } else {
  1418. peg$currPos = s0;
  1419. s0 = peg$FAILED;
  1420. }
  1421. } else {
  1422. peg$currPos = s0;
  1423. s0 = peg$FAILED;
  1424. }
  1425. } else {
  1426. peg$currPos = s0;
  1427. s0 = peg$FAILED;
  1428. }
  1429. return s0;
  1430. }
  1431. function peg$parseskewY() {
  1432. var s0, s1, s2, s3, s4, s5, s6, s7;
  1433. var rule$expects = function rule$expects(expected) {
  1434. if (peg$silentFails === 0) peg$expect(expected);
  1435. };
  1436. s0 = peg$currPos;
  1437. rule$expects(peg$e7);
  1438. if (input.substr(peg$currPos, 5) === peg$c7) {
  1439. s1 = peg$c7;
  1440. peg$currPos += 5;
  1441. } else {
  1442. s1 = peg$FAILED;
  1443. }
  1444. if (s1 !== peg$FAILED) {
  1445. s2 = [];
  1446. s3 = peg$parsewsp();
  1447. while (s3 !== peg$FAILED) {
  1448. s2.push(s3);
  1449. s3 = peg$parsewsp();
  1450. }
  1451. rule$expects(peg$e1);
  1452. if (input.charCodeAt(peg$currPos) === 40) {
  1453. s3 = peg$c1;
  1454. peg$currPos++;
  1455. } else {
  1456. s3 = peg$FAILED;
  1457. }
  1458. if (s3 !== peg$FAILED) {
  1459. s4 = [];
  1460. s5 = peg$parsewsp();
  1461. while (s5 !== peg$FAILED) {
  1462. s4.push(s5);
  1463. s5 = peg$parsewsp();
  1464. }
  1465. s5 = peg$parsenumber();
  1466. if (s5 !== peg$FAILED) {
  1467. s6 = [];
  1468. s7 = peg$parsewsp();
  1469. while (s7 !== peg$FAILED) {
  1470. s6.push(s7);
  1471. s7 = peg$parsewsp();
  1472. }
  1473. rule$expects(peg$e2);
  1474. if (input.charCodeAt(peg$currPos) === 41) {
  1475. s7 = peg$c2;
  1476. peg$currPos++;
  1477. } else {
  1478. s7 = peg$FAILED;
  1479. }
  1480. if (s7 !== peg$FAILED) {
  1481. peg$savedPos = s0;
  1482. s0 = peg$f7(s5);
  1483. } else {
  1484. peg$currPos = s0;
  1485. s0 = peg$FAILED;
  1486. }
  1487. } else {
  1488. peg$currPos = s0;
  1489. s0 = peg$FAILED;
  1490. }
  1491. } else {
  1492. peg$currPos = s0;
  1493. s0 = peg$FAILED;
  1494. }
  1495. } else {
  1496. peg$currPos = s0;
  1497. s0 = peg$FAILED;
  1498. }
  1499. return s0;
  1500. }
  1501. function peg$parsenumber() {
  1502. var s0, s1, s2, s3;
  1503. var rule$expects = function rule$expects(expected) {
  1504. if (peg$silentFails === 0) peg$expect(expected);
  1505. };
  1506. s0 = peg$currPos;
  1507. s1 = peg$currPos;
  1508. s2 = peg$parsesign();
  1509. if (s2 === peg$FAILED) {
  1510. s2 = null;
  1511. }
  1512. s3 = peg$parsefloatingPointConstant();
  1513. if (s3 !== peg$FAILED) {
  1514. s2 = [s2, s3];
  1515. s1 = s2;
  1516. } else {
  1517. peg$currPos = s1;
  1518. s1 = peg$FAILED;
  1519. }
  1520. if (s1 !== peg$FAILED) {
  1521. peg$savedPos = s0;
  1522. s1 = peg$f8(s1);
  1523. }
  1524. s0 = s1;
  1525. if (s0 === peg$FAILED) {
  1526. s0 = peg$currPos;
  1527. s1 = peg$currPos;
  1528. s2 = peg$parsesign();
  1529. if (s2 === peg$FAILED) {
  1530. s2 = null;
  1531. }
  1532. s3 = peg$parseintegerConstant();
  1533. if (s3 !== peg$FAILED) {
  1534. s2 = [s2, s3];
  1535. s1 = s2;
  1536. } else {
  1537. peg$currPos = s1;
  1538. s1 = peg$FAILED;
  1539. }
  1540. if (s1 !== peg$FAILED) {
  1541. peg$savedPos = s0;
  1542. s1 = peg$f9(s1);
  1543. }
  1544. s0 = s1;
  1545. }
  1546. return s0;
  1547. }
  1548. function peg$parsecommaWspNumber() {
  1549. var s0, s1, s2;
  1550. var rule$expects = function rule$expects(expected) {
  1551. if (peg$silentFails === 0) peg$expect(expected);
  1552. };
  1553. s0 = peg$currPos;
  1554. s1 = peg$parsecommaWsp();
  1555. if (s1 !== peg$FAILED) {
  1556. s2 = peg$parsenumber();
  1557. if (s2 !== peg$FAILED) {
  1558. peg$savedPos = s0;
  1559. s0 = peg$f10(s2);
  1560. } else {
  1561. peg$currPos = s0;
  1562. s0 = peg$FAILED;
  1563. }
  1564. } else {
  1565. peg$currPos = s0;
  1566. s0 = peg$FAILED;
  1567. }
  1568. return s0;
  1569. }
  1570. function peg$parsecommaWspTwoNumbers() {
  1571. var s0, s1, s2, s3, s4;
  1572. var rule$expects = function rule$expects(expected) {
  1573. if (peg$silentFails === 0) peg$expect(expected);
  1574. };
  1575. s0 = peg$currPos;
  1576. s1 = peg$parsecommaWsp();
  1577. if (s1 !== peg$FAILED) {
  1578. s2 = peg$parsenumber();
  1579. if (s2 !== peg$FAILED) {
  1580. s3 = peg$parsecommaWsp();
  1581. if (s3 !== peg$FAILED) {
  1582. s4 = peg$parsenumber();
  1583. if (s4 !== peg$FAILED) {
  1584. peg$savedPos = s0;
  1585. s0 = peg$f11(s2, s4);
  1586. } else {
  1587. peg$currPos = s0;
  1588. s0 = peg$FAILED;
  1589. }
  1590. } else {
  1591. peg$currPos = s0;
  1592. s0 = peg$FAILED;
  1593. }
  1594. } else {
  1595. peg$currPos = s0;
  1596. s0 = peg$FAILED;
  1597. }
  1598. } else {
  1599. peg$currPos = s0;
  1600. s0 = peg$FAILED;
  1601. }
  1602. return s0;
  1603. }
  1604. function peg$parsecommaWsp() {
  1605. var s0, s1, s2, s3, s4;
  1606. var rule$expects = function rule$expects(expected) {
  1607. if (peg$silentFails === 0) peg$expect(expected);
  1608. };
  1609. s0 = peg$currPos;
  1610. s1 = [];
  1611. s2 = peg$parsewsp();
  1612. if (s2 !== peg$FAILED) {
  1613. while (s2 !== peg$FAILED) {
  1614. s1.push(s2);
  1615. s2 = peg$parsewsp();
  1616. }
  1617. } else {
  1618. s1 = peg$FAILED;
  1619. }
  1620. if (s1 !== peg$FAILED) {
  1621. s2 = peg$parsecomma();
  1622. if (s2 === peg$FAILED) {
  1623. s2 = null;
  1624. }
  1625. s3 = [];
  1626. s4 = peg$parsewsp();
  1627. while (s4 !== peg$FAILED) {
  1628. s3.push(s4);
  1629. s4 = peg$parsewsp();
  1630. }
  1631. s1 = [s1, s2, s3];
  1632. s0 = s1;
  1633. } else {
  1634. peg$currPos = s0;
  1635. s0 = peg$FAILED;
  1636. }
  1637. if (s0 === peg$FAILED) {
  1638. s0 = peg$currPos;
  1639. s1 = peg$parsecomma();
  1640. if (s1 !== peg$FAILED) {
  1641. s2 = [];
  1642. s3 = peg$parsewsp();
  1643. while (s3 !== peg$FAILED) {
  1644. s2.push(s3);
  1645. s3 = peg$parsewsp();
  1646. }
  1647. s1 = [s1, s2];
  1648. s0 = s1;
  1649. } else {
  1650. peg$currPos = s0;
  1651. s0 = peg$FAILED;
  1652. }
  1653. }
  1654. return s0;
  1655. }
  1656. function peg$parsecomma() {
  1657. var s0;
  1658. var rule$expects = function rule$expects(expected) {
  1659. if (peg$silentFails === 0) peg$expect(expected);
  1660. };
  1661. rule$expects(peg$e8);
  1662. if (input.charCodeAt(peg$currPos) === 44) {
  1663. s0 = peg$c8;
  1664. peg$currPos++;
  1665. } else {
  1666. s0 = peg$FAILED;
  1667. }
  1668. return s0;
  1669. }
  1670. function peg$parseintegerConstant() {
  1671. var s0, s1;
  1672. var rule$expects = function rule$expects(expected) {
  1673. if (peg$silentFails === 0) peg$expect(expected);
  1674. };
  1675. s0 = peg$currPos;
  1676. s1 = peg$parsedigitSequence();
  1677. if (s1 !== peg$FAILED) {
  1678. peg$savedPos = s0;
  1679. s1 = peg$f12(s1);
  1680. }
  1681. s0 = s1;
  1682. return s0;
  1683. }
  1684. function peg$parsefloatingPointConstant() {
  1685. var s0, s1, s2;
  1686. var rule$expects = function rule$expects(expected) {
  1687. if (peg$silentFails === 0) peg$expect(expected);
  1688. };
  1689. s0 = peg$currPos;
  1690. s1 = peg$parsefractionalConstant();
  1691. if (s1 !== peg$FAILED) {
  1692. s2 = peg$parseexponent();
  1693. if (s2 === peg$FAILED) {
  1694. s2 = null;
  1695. }
  1696. s1 = [s1, s2];
  1697. s0 = s1;
  1698. } else {
  1699. peg$currPos = s0;
  1700. s0 = peg$FAILED;
  1701. }
  1702. if (s0 === peg$FAILED) {
  1703. s0 = peg$currPos;
  1704. s1 = peg$parsedigitSequence();
  1705. if (s1 !== peg$FAILED) {
  1706. s2 = peg$parseexponent();
  1707. if (s2 !== peg$FAILED) {
  1708. s1 = [s1, s2];
  1709. s0 = s1;
  1710. } else {
  1711. peg$currPos = s0;
  1712. s0 = peg$FAILED;
  1713. }
  1714. } else {
  1715. peg$currPos = s0;
  1716. s0 = peg$FAILED;
  1717. }
  1718. }
  1719. return s0;
  1720. }
  1721. function peg$parsefractionalConstant() {
  1722. var s0, s1, s2, s3;
  1723. var rule$expects = function rule$expects(expected) {
  1724. if (peg$silentFails === 0) peg$expect(expected);
  1725. };
  1726. rule$expects(peg$e9);
  1727. peg$silentFails++;
  1728. s0 = peg$currPos;
  1729. s1 = peg$parsedigitSequence();
  1730. if (s1 === peg$FAILED) {
  1731. s1 = null;
  1732. }
  1733. if (input.charCodeAt(peg$currPos) === 46) {
  1734. s2 = peg$c9;
  1735. peg$currPos++;
  1736. } else {
  1737. s2 = peg$FAILED;
  1738. }
  1739. if (s2 !== peg$FAILED) {
  1740. s3 = peg$parsedigitSequence();
  1741. if (s3 !== peg$FAILED) {
  1742. peg$savedPos = s0;
  1743. s0 = peg$f13(s1, s3);
  1744. } else {
  1745. peg$currPos = s0;
  1746. s0 = peg$FAILED;
  1747. }
  1748. } else {
  1749. peg$currPos = s0;
  1750. s0 = peg$FAILED;
  1751. }
  1752. if (s0 === peg$FAILED) {
  1753. s0 = peg$currPos;
  1754. s1 = peg$parsedigitSequence();
  1755. if (s1 !== peg$FAILED) {
  1756. if (input.charCodeAt(peg$currPos) === 46) {
  1757. s2 = peg$c9;
  1758. peg$currPos++;
  1759. } else {
  1760. s2 = peg$FAILED;
  1761. }
  1762. if (s2 !== peg$FAILED) {
  1763. peg$savedPos = s0;
  1764. s0 = peg$f14(s1);
  1765. } else {
  1766. peg$currPos = s0;
  1767. s0 = peg$FAILED;
  1768. }
  1769. } else {
  1770. peg$currPos = s0;
  1771. s0 = peg$FAILED;
  1772. }
  1773. }
  1774. peg$silentFails--;
  1775. return s0;
  1776. }
  1777. function peg$parseexponent() {
  1778. var s0, s1, s2, s3;
  1779. var rule$expects = function rule$expects(expected) {
  1780. if (peg$silentFails === 0) peg$expect(expected);
  1781. };
  1782. s0 = peg$currPos;
  1783. rule$expects(peg$e10);
  1784. if (peg$r0.test(input.charAt(peg$currPos))) {
  1785. s1 = input.charAt(peg$currPos);
  1786. peg$currPos++;
  1787. } else {
  1788. s1 = peg$FAILED;
  1789. }
  1790. if (s1 !== peg$FAILED) {
  1791. s2 = peg$parsesign();
  1792. if (s2 === peg$FAILED) {
  1793. s2 = null;
  1794. }
  1795. s3 = peg$parsedigitSequence();
  1796. if (s3 !== peg$FAILED) {
  1797. s1 = [s1, s2, s3];
  1798. s0 = s1;
  1799. } else {
  1800. peg$currPos = s0;
  1801. s0 = peg$FAILED;
  1802. }
  1803. } else {
  1804. peg$currPos = s0;
  1805. s0 = peg$FAILED;
  1806. }
  1807. return s0;
  1808. }
  1809. function peg$parsesign() {
  1810. var s0;
  1811. var rule$expects = function rule$expects(expected) {
  1812. if (peg$silentFails === 0) peg$expect(expected);
  1813. };
  1814. rule$expects(peg$e11);
  1815. if (peg$r1.test(input.charAt(peg$currPos))) {
  1816. s0 = input.charAt(peg$currPos);
  1817. peg$currPos++;
  1818. } else {
  1819. s0 = peg$FAILED;
  1820. }
  1821. return s0;
  1822. }
  1823. function peg$parsedigitSequence() {
  1824. var s0, s1;
  1825. var rule$expects = function rule$expects(expected) {
  1826. if (peg$silentFails === 0) peg$expect(expected);
  1827. };
  1828. s0 = [];
  1829. s1 = peg$parsedigit();
  1830. if (s1 !== peg$FAILED) {
  1831. while (s1 !== peg$FAILED) {
  1832. s0.push(s1);
  1833. s1 = peg$parsedigit();
  1834. }
  1835. } else {
  1836. s0 = peg$FAILED;
  1837. }
  1838. return s0;
  1839. }
  1840. function peg$parsedigit() {
  1841. var s0;
  1842. var rule$expects = function rule$expects(expected) {
  1843. if (peg$silentFails === 0) peg$expect(expected);
  1844. };
  1845. rule$expects(peg$e12);
  1846. if (peg$r2.test(input.charAt(peg$currPos))) {
  1847. s0 = input.charAt(peg$currPos);
  1848. peg$currPos++;
  1849. } else {
  1850. s0 = peg$FAILED;
  1851. }
  1852. return s0;
  1853. }
  1854. function peg$parsewsp() {
  1855. var s0;
  1856. var rule$expects = function rule$expects(expected) {
  1857. if (peg$silentFails === 0) peg$expect(expected);
  1858. };
  1859. rule$expects(peg$e13);
  1860. if (peg$r3.test(input.charAt(peg$currPos))) {
  1861. s0 = input.charAt(peg$currPos);
  1862. peg$currPos++;
  1863. } else {
  1864. s0 = peg$FAILED;
  1865. }
  1866. return s0;
  1867. }
  1868. peg$begin();
  1869. peg$result = peg$startRuleFunction();
  1870. if (peg$result !== peg$FAILED && peg$currPos === input.length) {
  1871. return peg$result;
  1872. } else {
  1873. if (peg$result !== peg$FAILED && peg$currPos < input.length) {
  1874. peg$expect(peg$endExpectation());
  1875. }
  1876. throw peg$buildError();
  1877. }
  1878. }
  1879. /* harmony default export */ var fromTransformAttribute_autogenerated = ({
  1880. SyntaxError: peg$SyntaxError,
  1881. parse: peg$parse
  1882. });
  1883. // CONCATENATED MODULE: ./src/fromTransformAttribute.js
  1884. /**
  1885. * Parser for SVG Trasform Attribute http://www.w3.org/TR/SVG/coords.html#TransformAttribute <br/>
  1886. * Warning: This should be considered BETA until it is released a stable version of pegjs.
  1887. * @param transformString {string} Transform string as defined by w3 Consortium
  1888. * @returns {MatrixDescriptor[]} Array of MatrixDescriptor
  1889. *
  1890. * @example
  1891. * > fromTransformAttribute('translate(-10,-10) scale(2,2) translate(10,10)')
  1892. * [
  1893. * { type: 'translate', tx: -10, ty: -10},
  1894. * { type: 'scale', sx: 2, sy: 2 },
  1895. * { type: 'translate', tx: 10, ty: 10}
  1896. * ]
  1897. *
  1898. * > compose(fromDefinition(fromTransformAttribute('translate(-10, -10) scale(10, 10)')))
  1899. * { a: 10, c: 0, e: -10, b: 0, d: 10, f: -10 }
  1900. */
  1901. function fromTransformAttribute(transformString) {
  1902. return peg$parse(transformString);
  1903. }
  1904. // CONCATENATED MODULE: ./src/index.js
  1905. /* concated harmony reexport applyToPoint */__webpack_require__.d(__webpack_exports__, "applyToPoint", function() { return applyToPoint; });
  1906. /* concated harmony reexport applyToPoints */__webpack_require__.d(__webpack_exports__, "applyToPoints", function() { return applyToPoints; });
  1907. /* concated harmony reexport fromObject */__webpack_require__.d(__webpack_exports__, "fromObject", function() { return fromObject; });
  1908. /* concated harmony reexport fromString */__webpack_require__.d(__webpack_exports__, "fromString", function() { return fromString; });
  1909. /* concated harmony reexport identity */__webpack_require__.d(__webpack_exports__, "identity", function() { return identity; });
  1910. /* concated harmony reexport inverse */__webpack_require__.d(__webpack_exports__, "inverse", function() { return inverse; });
  1911. /* concated harmony reexport isAffineMatrix */__webpack_require__.d(__webpack_exports__, "isAffineMatrix", function() { return isAffineMatrix; });
  1912. /* concated harmony reexport rotate */__webpack_require__.d(__webpack_exports__, "rotate", function() { return rotate; });
  1913. /* concated harmony reexport rotateDEG */__webpack_require__.d(__webpack_exports__, "rotateDEG", function() { return rotateDEG; });
  1914. /* concated harmony reexport scale */__webpack_require__.d(__webpack_exports__, "scale", function() { return scale; });
  1915. /* concated harmony reexport shear */__webpack_require__.d(__webpack_exports__, "shear", function() { return shear; });
  1916. /* concated harmony reexport skew */__webpack_require__.d(__webpack_exports__, "skew", function() { return skew; });
  1917. /* concated harmony reexport skewDEG */__webpack_require__.d(__webpack_exports__, "skewDEG", function() { return skewDEG; });
  1918. /* concated harmony reexport toCSS */__webpack_require__.d(__webpack_exports__, "toCSS", function() { return toCSS; });
  1919. /* concated harmony reexport toSVG */__webpack_require__.d(__webpack_exports__, "toSVG", function() { return toSVG; });
  1920. /* concated harmony reexport toString */__webpack_require__.d(__webpack_exports__, "toString", function() { return toString_toString; });
  1921. /* concated harmony reexport transform */__webpack_require__.d(__webpack_exports__, "transform", function() { return transform; });
  1922. /* concated harmony reexport compose */__webpack_require__.d(__webpack_exports__, "compose", function() { return compose; });
  1923. /* concated harmony reexport translate */__webpack_require__.d(__webpack_exports__, "translate", function() { return translate; });
  1924. /* concated harmony reexport fromTriangles */__webpack_require__.d(__webpack_exports__, "fromTriangles", function() { return fromTriangles; });
  1925. /* concated harmony reexport smoothMatrix */__webpack_require__.d(__webpack_exports__, "smoothMatrix", function() { return smoothMatrix; });
  1926. /* concated harmony reexport fromDefinition */__webpack_require__.d(__webpack_exports__, "fromDefinition", function() { return fromDefinition; });
  1927. /* concated harmony reexport fromTransformAttribute */__webpack_require__.d(__webpack_exports__, "fromTransformAttribute", function() { return fromTransformAttribute; });
  1928. /***/ })
  1929. /******/ ]);
  1930. });
  1931. //# sourceMappingURL=transformation-matrix.js.map