Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

8011 Zeilen
288KB

  1. // ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐ \\
  2. // │ Raphaël 2.3.0 - JavaScript Vector Library │ \\
  3. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  4. // │ Copyright © 2008-2016 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5. // │ Copyright © 2008-2016 Sencha Labs (http://sencha.com) │ \\
  6. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  7. // │ Licensed under the MIT (https://github.com/DmitryBaranovskiy/raphael/blob/master/license.txt) license.│ \\
  8. // └───────────────────────────────────────────────────────────────────────────────────────────────────────┘ \\
  9. (function webpackUniversalModuleDefinition(root, factory) {
  10. if(typeof exports === 'object' && typeof module === 'object')
  11. module.exports = factory(require("eve"));
  12. else if(typeof define === 'function' && define.amd)
  13. define(["eve"], factory);
  14. else if(typeof exports === 'object')
  15. exports["Raphael"] = factory(require("eve"));
  16. else
  17. root["Raphael"] = factory(root["eve"]);
  18. })(window, function(__WEBPACK_EXTERNAL_MODULE_eve__) {
  19. return /******/ (function(modules) { // webpackBootstrap
  20. /******/ // The module cache
  21. /******/ var installedModules = {};
  22. /******/
  23. /******/ // The require function
  24. /******/ function __webpack_require__(moduleId) {
  25. /******/
  26. /******/ // Check if module is in cache
  27. /******/ if(installedModules[moduleId]) {
  28. /******/ return installedModules[moduleId].exports;
  29. /******/ }
  30. /******/ // Create a new module (and put it into the cache)
  31. /******/ var module = installedModules[moduleId] = {
  32. /******/ i: moduleId,
  33. /******/ l: false,
  34. /******/ exports: {}
  35. /******/ };
  36. /******/
  37. /******/ // Execute the module function
  38. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39. /******/
  40. /******/ // Flag the module as loaded
  41. /******/ module.l = true;
  42. /******/
  43. /******/ // Return the exports of the module
  44. /******/ return module.exports;
  45. /******/ }
  46. /******/
  47. /******/
  48. /******/ // expose the modules object (__webpack_modules__)
  49. /******/ __webpack_require__.m = modules;
  50. /******/
  51. /******/ // expose the module cache
  52. /******/ __webpack_require__.c = installedModules;
  53. /******/
  54. /******/ // define getter function for harmony exports
  55. /******/ __webpack_require__.d = function(exports, name, getter) {
  56. /******/ if(!__webpack_require__.o(exports, name)) {
  57. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  58. /******/ }
  59. /******/ };
  60. /******/
  61. /******/ // define __esModule on exports
  62. /******/ __webpack_require__.r = function(exports) {
  63. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  64. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  65. /******/ }
  66. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  67. /******/ };
  68. /******/
  69. /******/ // create a fake namespace object
  70. /******/ // mode & 1: value is a module id, require it
  71. /******/ // mode & 2: merge all properties of value into the ns
  72. /******/ // mode & 4: return value when already ns object
  73. /******/ // mode & 8|1: behave like require
  74. /******/ __webpack_require__.t = function(value, mode) {
  75. /******/ if(mode & 1) value = __webpack_require__(value);
  76. /******/ if(mode & 8) return value;
  77. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  78. /******/ var ns = Object.create(null);
  79. /******/ __webpack_require__.r(ns);
  80. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  81. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  82. /******/ return ns;
  83. /******/ };
  84. /******/
  85. /******/ // getDefaultExport function for compatibility with non-harmony modules
  86. /******/ __webpack_require__.n = function(module) {
  87. /******/ var getter = module && module.__esModule ?
  88. /******/ function getDefault() { return module['default']; } :
  89. /******/ function getModuleExports() { return module; };
  90. /******/ __webpack_require__.d(getter, 'a', getter);
  91. /******/ return getter;
  92. /******/ };
  93. /******/
  94. /******/ // Object.prototype.hasOwnProperty.call
  95. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  96. /******/
  97. /******/ // __webpack_public_path__
  98. /******/ __webpack_require__.p = "";
  99. /******/
  100. /******/
  101. /******/ // Load entry module and return exports
  102. /******/ return __webpack_require__(__webpack_require__.s = "./dev/raphael.amd.js");
  103. /******/ })
  104. /************************************************************************/
  105. /******/ ({
  106. /***/ "./dev/raphael.amd.js":
  107. /*!****************************!*\
  108. !*** ./dev/raphael.amd.js ***!
  109. \****************************/
  110. /*! no static exports found */
  111. /***/ (function(module, exports, __webpack_require__) {
  112. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! ./raphael.core */ "./dev/raphael.core.js"), __webpack_require__(/*! ./raphael.svg */ "./dev/raphael.svg.js"), __webpack_require__(/*! ./raphael.vml */ "./dev/raphael.vml.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(R) {
  113. return R;
  114. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  115. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  116. /***/ }),
  117. /***/ "./dev/raphael.core.js":
  118. /*!*****************************!*\
  119. !*** ./dev/raphael.core.js ***!
  120. \*****************************/
  121. /*! no static exports found */
  122. /***/ (function(module, exports, __webpack_require__) {
  123. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! eve */ "eve")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(eve) {
  124. /*\
  125. * Raphael
  126. [ method ]
  127. **
  128. * Creates a canvas object on which to draw.
  129. * You must do this first, as all future calls to drawing methods
  130. * from this instance will be bound to this canvas.
  131. > Parameters
  132. **
  133. - container (HTMLElement|string) DOM element or its ID which is going to be a parent for drawing surface
  134. - width (number)
  135. - height (number)
  136. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  137. * or
  138. - x (number)
  139. - y (number)
  140. - width (number)
  141. - height (number)
  142. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  143. * or
  144. - all (array) (first 3 or 4 elements in the array are equal to [containerID, width, height] or [x, y, width, height]. The rest are element descriptions in format {type: type, <attributes>}). See @Paper.add.
  145. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  146. * or
  147. - onReadyCallback (function) function that is going to be called on DOM ready event. You can also subscribe to this event via Eve’s “DOMLoad” event. In this case method returns `undefined`.
  148. = (object) @Paper
  149. > Usage
  150. | // Each of the following examples create a canvas
  151. | // that is 320px wide by 200px high.
  152. | // Canvas is created at the viewport’s 10,50 coordinate.
  153. | var paper = Raphael(10, 50, 320, 200);
  154. | // Canvas is created at the top left corner of the #notepad element
  155. | // (or its top right corner in dir="rtl" elements)
  156. | var paper = Raphael(document.getElementById("notepad"), 320, 200);
  157. | // Same as above
  158. | var paper = Raphael("notepad", 320, 200);
  159. | // Image dump
  160. | var set = Raphael(["notepad", 320, 200, {
  161. | type: "rect",
  162. | x: 10,
  163. | y: 10,
  164. | width: 25,
  165. | height: 25,
  166. | stroke: "#f00"
  167. | }, {
  168. | type: "text",
  169. | x: 30,
  170. | y: 40,
  171. | text: "Dump"
  172. | }]);
  173. \*/
  174. function R(first) {
  175. if (R.is(first, "function")) {
  176. return loaded ? first() : eve.on("raphael.DOMload", first);
  177. } else if (R.is(first, array)) {
  178. return R._engine.create[apply](R, first.splice(0, 3 + R.is(first[0], nu))).add(first);
  179. } else {
  180. var args = Array.prototype.slice.call(arguments, 0);
  181. if (R.is(args[args.length - 1], "function")) {
  182. var f = args.pop();
  183. return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("raphael.DOMload", function () {
  184. f.call(R._engine.create[apply](R, args));
  185. });
  186. } else {
  187. return R._engine.create[apply](R, arguments);
  188. }
  189. }
  190. }
  191. R.version = "2.3.0";
  192. R.eve = eve;
  193. var loaded,
  194. separator = /[, ]+/,
  195. elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
  196. formatrg = /\{(\d+)\}/g,
  197. proto = "prototype",
  198. has = "hasOwnProperty",
  199. g = {
  200. doc: document,
  201. win: window
  202. },
  203. oldRaphael = {
  204. was: Object.prototype[has].call(g.win, "Raphael"),
  205. is: g.win.Raphael
  206. },
  207. Paper = function () {
  208. /*\
  209. * Paper.ca
  210. [ property (object) ]
  211. **
  212. * Shortcut for @Paper.customAttributes
  213. \*/
  214. /*\
  215. * Paper.customAttributes
  216. [ property (object) ]
  217. **
  218. * If you have a set of attributes that you would like to represent
  219. * as a function of some number you can do it easily with custom attributes:
  220. > Usage
  221. | paper.customAttributes.hue = function (num) {
  222. | num = num % 1;
  223. | return {fill: "hsb(" + num + ", 0.75, 1)"};
  224. | };
  225. | // Custom attribute “hue” will change fill
  226. | // to be given hue with fixed saturation and brightness.
  227. | // Now you can use it like this:
  228. | var c = paper.circle(10, 10, 10).attr({hue: .45});
  229. | // or even like this:
  230. | c.animate({hue: 1}, 1e3);
  231. |
  232. | // You could also create custom attribute
  233. | // with multiple parameters:
  234. | paper.customAttributes.hsb = function (h, s, b) {
  235. | return {fill: "hsb(" + [h, s, b].join(",") + ")"};
  236. | };
  237. | c.attr({hsb: "0.5 .8 1"});
  238. | c.animate({hsb: [1, 0, 0.5]}, 1e3);
  239. \*/
  240. this.ca = this.customAttributes = {};
  241. },
  242. paperproto,
  243. appendChild = "appendChild",
  244. apply = "apply",
  245. concat = "concat",
  246. //taken from Modernizr touch test: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js#L40
  247. supportsTouch = ('ontouchstart' in window) || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch,
  248. E = "",
  249. S = " ",
  250. Str = String,
  251. split = "split",
  252. events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
  253. touchMap = {
  254. mousedown: "touchstart",
  255. mousemove: "touchmove",
  256. mouseup: "touchend"
  257. },
  258. lowerCase = Str.prototype.toLowerCase,
  259. math = Math,
  260. mmax = math.max,
  261. mmin = math.min,
  262. abs = math.abs,
  263. pow = math.pow,
  264. PI = math.PI,
  265. nu = "number",
  266. string = "string",
  267. array = "array",
  268. toString = "toString",
  269. fillString = "fill",
  270. objectToString = Object.prototype.toString,
  271. paper = {},
  272. push = "push",
  273. ISURL = R._ISURL = /^url\(['"]?(.+?)['"]?\)$/i,
  274. colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
  275. isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
  276. bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
  277. round = math.round,
  278. setAttribute = "setAttribute",
  279. toFloat = parseFloat,
  280. toInt = parseInt,
  281. upperCase = Str.prototype.toUpperCase,
  282. availableAttrs = R._availableAttrs = {
  283. "arrow-end": "none",
  284. "arrow-start": "none",
  285. blur: 0,
  286. "clip-rect": "0 0 1e9 1e9",
  287. cursor: "default",
  288. cx: 0,
  289. cy: 0,
  290. fill: "#fff",
  291. "fill-opacity": 1,
  292. font: '10px "Arial"',
  293. "font-family": '"Arial"',
  294. "font-size": "10",
  295. "font-style": "normal",
  296. "font-weight": 400,
  297. gradient: 0,
  298. height: 0,
  299. href: "http://raphaeljs.com/",
  300. "letter-spacing": 0,
  301. opacity: 1,
  302. path: "M0,0",
  303. r: 0,
  304. rx: 0,
  305. ry: 0,
  306. src: "",
  307. stroke: "#000",
  308. "stroke-dasharray": "",
  309. "stroke-linecap": "butt",
  310. "stroke-linejoin": "butt",
  311. "stroke-miterlimit": 0,
  312. "stroke-opacity": 1,
  313. "stroke-width": 1,
  314. target: "_blank",
  315. "text-anchor": "middle",
  316. title: "Raphael",
  317. transform: "",
  318. width: 0,
  319. x: 0,
  320. y: 0,
  321. "class": ""
  322. },
  323. availableAnimAttrs = R._availableAnimAttrs = {
  324. blur: nu,
  325. "clip-rect": "csv",
  326. cx: nu,
  327. cy: nu,
  328. fill: "colour",
  329. "fill-opacity": nu,
  330. "font-size": nu,
  331. height: nu,
  332. opacity: nu,
  333. path: "path",
  334. r: nu,
  335. rx: nu,
  336. ry: nu,
  337. stroke: "colour",
  338. "stroke-opacity": nu,
  339. "stroke-width": nu,
  340. transform: "transform",
  341. width: nu,
  342. x: nu,
  343. y: nu
  344. },
  345. whitespace = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]/g,
  346. commaSpaces = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/,
  347. hsrg = {hs: 1, rg: 1},
  348. p2s = /,?([achlmqrstvxz]),?/gi,
  349. pathCommand = /([achlmrqstvz])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  350. tCommand = /([rstm])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  351. pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/ig,
  352. radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*([^\)]+?)\))?/,
  353. eldata = {},
  354. sortByKey = function (a, b) {
  355. return a.key - b.key;
  356. },
  357. sortByNumber = function (a, b) {
  358. return toFloat(a) - toFloat(b);
  359. },
  360. fun = function () {},
  361. pipe = function (x) {
  362. return x;
  363. },
  364. rectPath = R._rectPath = function (x, y, w, h, r) {
  365. if (r) {
  366. return [["M", x + r, y], ["l", w - r * 2, 0], ["a", r, r, 0, 0, 1, r, r], ["l", 0, h - r * 2], ["a", r, r, 0, 0, 1, -r, r], ["l", r * 2 - w, 0], ["a", r, r, 0, 0, 1, -r, -r], ["l", 0, r * 2 - h], ["a", r, r, 0, 0, 1, r, -r], ["z"]];
  367. }
  368. return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
  369. },
  370. ellipsePath = function (x, y, rx, ry) {
  371. if (ry == null) {
  372. ry = rx;
  373. }
  374. return [["M", x, y], ["m", 0, -ry], ["a", rx, ry, 0, 1, 1, 0, 2 * ry], ["a", rx, ry, 0, 1, 1, 0, -2 * ry], ["z"]];
  375. },
  376. getPath = R._getPath = {
  377. path: function (el) {
  378. return el.attr("path");
  379. },
  380. circle: function (el) {
  381. var a = el.attrs;
  382. return ellipsePath(a.cx, a.cy, a.r);
  383. },
  384. ellipse: function (el) {
  385. var a = el.attrs;
  386. return ellipsePath(a.cx, a.cy, a.rx, a.ry);
  387. },
  388. rect: function (el) {
  389. var a = el.attrs;
  390. return rectPath(a.x, a.y, a.width, a.height, a.r);
  391. },
  392. image: function (el) {
  393. var a = el.attrs;
  394. return rectPath(a.x, a.y, a.width, a.height);
  395. },
  396. text: function (el) {
  397. var bbox = el._getBBox();
  398. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  399. },
  400. set : function(el) {
  401. var bbox = el._getBBox();
  402. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  403. }
  404. },
  405. /*\
  406. * Raphael.mapPath
  407. [ method ]
  408. **
  409. * Transform the path string with given matrix.
  410. > Parameters
  411. - path (string) path string
  412. - matrix (object) see @Matrix
  413. = (string) transformed path string
  414. \*/
  415. mapPath = R.mapPath = function (path, matrix) {
  416. if (!matrix) {
  417. return path;
  418. }
  419. var x, y, i, j, ii, jj, pathi;
  420. path = path2curve(path);
  421. for (i = 0, ii = path.length; i < ii; i++) {
  422. pathi = path[i];
  423. for (j = 1, jj = pathi.length; j < jj; j += 2) {
  424. x = matrix.x(pathi[j], pathi[j + 1]);
  425. y = matrix.y(pathi[j], pathi[j + 1]);
  426. pathi[j] = x;
  427. pathi[j + 1] = y;
  428. }
  429. }
  430. return path;
  431. };
  432. R._g = g;
  433. /*\
  434. * Raphael.type
  435. [ property (string) ]
  436. **
  437. * Can be “SVG”, “VML” or empty, depending on browser support.
  438. \*/
  439. R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
  440. if (R.type == "VML") {
  441. var d = g.doc.createElement("div"),
  442. b;
  443. d.innerHTML = '<v:shape adj="1"/>';
  444. b = d.firstChild;
  445. b.style.behavior = "url(#default#VML)";
  446. if (!(b && typeof b.adj == "object")) {
  447. return (R.type = E);
  448. }
  449. d = null;
  450. }
  451. /*\
  452. * Raphael.svg
  453. [ property (boolean) ]
  454. **
  455. * `true` if browser supports SVG.
  456. \*/
  457. /*\
  458. * Raphael.vml
  459. [ property (boolean) ]
  460. **
  461. * `true` if browser supports VML.
  462. \*/
  463. R.svg = !(R.vml = R.type == "VML");
  464. R._Paper = Paper;
  465. /*\
  466. * Raphael.fn
  467. [ property (object) ]
  468. **
  469. * You can add your own method to the canvas. For example if you want to draw a pie chart,
  470. * you can create your own pie chart function and ship it as a Raphaël plugin. To do this
  471. * you need to extend the `Raphael.fn` object. You should modify the `fn` object before a
  472. * Raphaël instance is created, otherwise it will take no effect. Please note that the
  473. * ability for namespaced plugins was removed in Raphael 2.0. It is up to the plugin to
  474. * ensure any namespacing ensures proper context.
  475. > Usage
  476. | Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
  477. | return this.path( ... );
  478. | };
  479. | // or create namespace
  480. | Raphael.fn.mystuff = {
  481. | arrow: function () {…},
  482. | star: function () {…},
  483. | // etc…
  484. | };
  485. | var paper = Raphael(10, 10, 630, 480);
  486. | // then use it
  487. | paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
  488. | paper.mystuff.arrow();
  489. | paper.mystuff.star();
  490. \*/
  491. R.fn = paperproto = Paper.prototype = R.prototype;
  492. R._id = 0;
  493. /*\
  494. * Raphael.is
  495. [ method ]
  496. **
  497. * Handful of replacements for `typeof` operator.
  498. > Parameters
  499. - o (…) any object or primitive
  500. - type (string) name of the type, i.e. “string”, “function”, “number”, etc.
  501. = (boolean) is given value is of given type
  502. \*/
  503. R.is = function (o, type) {
  504. type = lowerCase.call(type);
  505. if (type == "finite") {
  506. return !isnan[has](+o);
  507. }
  508. if (type == "array") {
  509. return o instanceof Array;
  510. }
  511. return (type == "null" && o === null) ||
  512. (type == typeof o && o !== null) ||
  513. (type == "object" && o === Object(o)) ||
  514. (type == "array" && Array.isArray && Array.isArray(o)) ||
  515. objectToString.call(o).slice(8, -1).toLowerCase() == type;
  516. };
  517. function clone(obj) {
  518. if (typeof obj == "function" || Object(obj) !== obj) {
  519. return obj;
  520. }
  521. var res = new obj.constructor;
  522. for (var key in obj) if (obj[has](key)) {
  523. res[key] = clone(obj[key]);
  524. }
  525. return res;
  526. }
  527. /*\
  528. * Raphael.angle
  529. [ method ]
  530. **
  531. * Returns angle between two or three points
  532. > Parameters
  533. - x1 (number) x coord of first point
  534. - y1 (number) y coord of first point
  535. - x2 (number) x coord of second point
  536. - y2 (number) y coord of second point
  537. - x3 (number) #optional x coord of third point
  538. - y3 (number) #optional y coord of third point
  539. = (number) angle in degrees.
  540. \*/
  541. R.angle = function (x1, y1, x2, y2, x3, y3) {
  542. if (x3 == null) {
  543. var x = x1 - x2,
  544. y = y1 - y2;
  545. if (!x && !y) {
  546. return 0;
  547. }
  548. return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
  549. } else {
  550. return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
  551. }
  552. };
  553. /*\
  554. * Raphael.rad
  555. [ method ]
  556. **
  557. * Transform angle to radians
  558. > Parameters
  559. - deg (number) angle in degrees
  560. = (number) angle in radians.
  561. \*/
  562. R.rad = function (deg) {
  563. return deg % 360 * PI / 180;
  564. };
  565. /*\
  566. * Raphael.deg
  567. [ method ]
  568. **
  569. * Transform angle to degrees
  570. > Parameters
  571. - rad (number) angle in radians
  572. = (number) angle in degrees.
  573. \*/
  574. R.deg = function (rad) {
  575. return Math.round ((rad * 180 / PI% 360)* 1000) / 1000;
  576. };
  577. /*\
  578. * Raphael.snapTo
  579. [ method ]
  580. **
  581. * Snaps given value to given grid.
  582. > Parameters
  583. - values (array|number) given array of values or step of the grid
  584. - value (number) value to adjust
  585. - tolerance (number) #optional tolerance for snapping. Default is `10`.
  586. = (number) adjusted value.
  587. \*/
  588. R.snapTo = function (values, value, tolerance) {
  589. tolerance = R.is(tolerance, "finite") ? tolerance : 10;
  590. if (R.is(values, array)) {
  591. var i = values.length;
  592. while (i--) if (abs(values[i] - value) <= tolerance) {
  593. return values[i];
  594. }
  595. } else {
  596. values = +values;
  597. var rem = value % values;
  598. if (rem < tolerance) {
  599. return value - rem;
  600. }
  601. if (rem > values - tolerance) {
  602. return value - rem + values;
  603. }
  604. }
  605. return value;
  606. };
  607. /*\
  608. * Raphael.createUUID
  609. [ method ]
  610. **
  611. * Returns RFC4122, version 4 ID
  612. \*/
  613. var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) {
  614. return function () {
  615. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
  616. };
  617. })(/[xy]/g, function (c) {
  618. var r = math.random() * 16 | 0,
  619. v = c == "x" ? r : (r & 3 | 8);
  620. return v.toString(16);
  621. });
  622. /*\
  623. * Raphael.setWindow
  624. [ method ]
  625. **
  626. * Used when you need to draw in `&lt;iframe>`. Switched window to the iframe one.
  627. > Parameters
  628. - newwin (window) new window object
  629. \*/
  630. R.setWindow = function (newwin) {
  631. eve("raphael.setWindow", R, g.win, newwin);
  632. g.win = newwin;
  633. g.doc = g.win.document;
  634. if (R._engine.initWin) {
  635. R._engine.initWin(g.win);
  636. }
  637. };
  638. var toHex = function (color) {
  639. if (R.vml) {
  640. // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
  641. var trim = /^\s+|\s+$/g;
  642. var bod;
  643. try {
  644. var docum = new ActiveXObject("htmlfile");
  645. docum.write("<body>");
  646. docum.close();
  647. bod = docum.body;
  648. } catch(e) {
  649. bod = createPopup().document.body;
  650. }
  651. var range = bod.createTextRange();
  652. toHex = cacher(function (color) {
  653. try {
  654. bod.style.color = Str(color).replace(trim, E);
  655. var value = range.queryCommandValue("ForeColor");
  656. value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
  657. return "#" + ("000000" + value.toString(16)).slice(-6);
  658. } catch(e) {
  659. return "none";
  660. }
  661. });
  662. } else {
  663. var i = g.doc.createElement("i");
  664. i.title = "Rapha\xebl Colour Picker";
  665. i.style.display = "none";
  666. g.doc.body.appendChild(i);
  667. toHex = cacher(function (color) {
  668. i.style.color = color;
  669. return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
  670. });
  671. }
  672. return toHex(color);
  673. },
  674. hsbtoString = function () {
  675. return "hsb(" + [this.h, this.s, this.b] + ")";
  676. },
  677. hsltoString = function () {
  678. return "hsl(" + [this.h, this.s, this.l] + ")";
  679. },
  680. rgbtoString = function () {
  681. return this.hex;
  682. },
  683. prepareRGB = function (r, g, b) {
  684. if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
  685. b = r.b;
  686. g = r.g;
  687. r = r.r;
  688. }
  689. if (g == null && R.is(r, string)) {
  690. var clr = R.getRGB(r);
  691. r = clr.r;
  692. g = clr.g;
  693. b = clr.b;
  694. }
  695. if (r > 1 || g > 1 || b > 1) {
  696. r /= 255;
  697. g /= 255;
  698. b /= 255;
  699. }
  700. return [r, g, b];
  701. },
  702. packageRGB = function (r, g, b, o) {
  703. r *= 255;
  704. g *= 255;
  705. b *= 255;
  706. var rgb = {
  707. r: r,
  708. g: g,
  709. b: b,
  710. hex: R.rgb(r, g, b),
  711. toString: rgbtoString
  712. };
  713. R.is(o, "finite") && (rgb.opacity = o);
  714. return rgb;
  715. };
  716. /*\
  717. * Raphael.color
  718. [ method ]
  719. **
  720. * Parses the color string and returns object with all values for the given color.
  721. > Parameters
  722. - clr (string) color string in one of the supported formats (see @Raphael.getRGB)
  723. = (object) Combined RGB & HSB object in format:
  724. o {
  725. o r (number) red,
  726. o g (number) green,
  727. o b (number) blue,
  728. o hex (string) color in HTML/CSS format: #••••••,
  729. o error (boolean) `true` if string can’t be parsed,
  730. o h (number) hue,
  731. o s (number) saturation,
  732. o v (number) value (brightness),
  733. o l (number) lightness
  734. o }
  735. \*/
  736. R.color = function (clr) {
  737. var rgb;
  738. if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
  739. rgb = R.hsb2rgb(clr);
  740. clr.r = rgb.r;
  741. clr.g = rgb.g;
  742. clr.b = rgb.b;
  743. clr.hex = rgb.hex;
  744. } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
  745. rgb = R.hsl2rgb(clr);
  746. clr.r = rgb.r;
  747. clr.g = rgb.g;
  748. clr.b = rgb.b;
  749. clr.hex = rgb.hex;
  750. } else {
  751. if (R.is(clr, "string")) {
  752. clr = R.getRGB(clr);
  753. }
  754. if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
  755. rgb = R.rgb2hsl(clr);
  756. clr.h = rgb.h;
  757. clr.s = rgb.s;
  758. clr.l = rgb.l;
  759. rgb = R.rgb2hsb(clr);
  760. clr.v = rgb.b;
  761. } else {
  762. clr = {hex: "none"};
  763. clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
  764. }
  765. }
  766. clr.toString = rgbtoString;
  767. return clr;
  768. };
  769. /*\
  770. * Raphael.hsb2rgb
  771. [ method ]
  772. **
  773. * Converts HSB values to RGB object.
  774. > Parameters
  775. - h (number) hue
  776. - s (number) saturation
  777. - v (number) value or brightness
  778. = (object) RGB object in format:
  779. o {
  780. o r (number) red,
  781. o g (number) green,
  782. o b (number) blue,
  783. o hex (string) color in HTML/CSS format: #••••••
  784. o }
  785. \*/
  786. R.hsb2rgb = function (h, s, v, o) {
  787. if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
  788. v = h.b;
  789. s = h.s;
  790. o = h.o;
  791. h = h.h;
  792. }
  793. h *= 360;
  794. var R, G, B, X, C;
  795. h = (h % 360) / 60;
  796. C = v * s;
  797. X = C * (1 - abs(h % 2 - 1));
  798. R = G = B = v - C;
  799. h = ~~h;
  800. R += [C, X, 0, 0, X, C][h];
  801. G += [X, C, C, X, 0, 0][h];
  802. B += [0, 0, X, C, C, X][h];
  803. return packageRGB(R, G, B, o);
  804. };
  805. /*\
  806. * Raphael.hsl2rgb
  807. [ method ]
  808. **
  809. * Converts HSL values to RGB object.
  810. > Parameters
  811. - h (number) hue
  812. - s (number) saturation
  813. - l (number) luminosity
  814. = (object) RGB object in format:
  815. o {
  816. o r (number) red,
  817. o g (number) green,
  818. o b (number) blue,
  819. o hex (string) color in HTML/CSS format: #••••••
  820. o }
  821. \*/
  822. R.hsl2rgb = function (h, s, l, o) {
  823. if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
  824. l = h.l;
  825. s = h.s;
  826. h = h.h;
  827. }
  828. if (h > 1 || s > 1 || l > 1) {
  829. h /= 360;
  830. s /= 100;
  831. l /= 100;
  832. }
  833. h *= 360;
  834. var R, G, B, X, C;
  835. h = (h % 360) / 60;
  836. C = 2 * s * (l < .5 ? l : 1 - l);
  837. X = C * (1 - abs(h % 2 - 1));
  838. R = G = B = l - C / 2;
  839. h = ~~h;
  840. R += [C, X, 0, 0, X, C][h];
  841. G += [X, C, C, X, 0, 0][h];
  842. B += [0, 0, X, C, C, X][h];
  843. return packageRGB(R, G, B, o);
  844. };
  845. /*\
  846. * Raphael.rgb2hsb
  847. [ method ]
  848. **
  849. * Converts RGB values to HSB object.
  850. > Parameters
  851. - r (number) red
  852. - g (number) green
  853. - b (number) blue
  854. = (object) HSB object in format:
  855. o {
  856. o h (number) hue
  857. o s (number) saturation
  858. o b (number) brightness
  859. o }
  860. \*/
  861. R.rgb2hsb = function (r, g, b) {
  862. b = prepareRGB(r, g, b);
  863. r = b[0];
  864. g = b[1];
  865. b = b[2];
  866. var H, S, V, C;
  867. V = mmax(r, g, b);
  868. C = V - mmin(r, g, b);
  869. H = (C == 0 ? null :
  870. V == r ? (g - b) / C :
  871. V == g ? (b - r) / C + 2 :
  872. (r - g) / C + 4
  873. );
  874. H = ((H + 360) % 6) * 60 / 360;
  875. S = C == 0 ? 0 : C / V;
  876. return {h: H, s: S, b: V, toString: hsbtoString};
  877. };
  878. /*\
  879. * Raphael.rgb2hsl
  880. [ method ]
  881. **
  882. * Converts RGB values to HSL object.
  883. > Parameters
  884. - r (number) red
  885. - g (number) green
  886. - b (number) blue
  887. = (object) HSL object in format:
  888. o {
  889. o h (number) hue
  890. o s (number) saturation
  891. o l (number) luminosity
  892. o }
  893. \*/
  894. R.rgb2hsl = function (r, g, b) {
  895. b = prepareRGB(r, g, b);
  896. r = b[0];
  897. g = b[1];
  898. b = b[2];
  899. var H, S, L, M, m, C;
  900. M = mmax(r, g, b);
  901. m = mmin(r, g, b);
  902. C = M - m;
  903. H = (C == 0 ? null :
  904. M == r ? (g - b) / C :
  905. M == g ? (b - r) / C + 2 :
  906. (r - g) / C + 4);
  907. H = ((H + 360) % 6) * 60 / 360;
  908. L = (M + m) / 2;
  909. S = (C == 0 ? 0 :
  910. L < .5 ? C / (2 * L) :
  911. C / (2 - 2 * L));
  912. return {h: H, s: S, l: L, toString: hsltoString};
  913. };
  914. R._path2string = function () {
  915. return this.join(",").replace(p2s, "$1");
  916. };
  917. function repush(array, item) {
  918. for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
  919. return array.push(array.splice(i, 1)[0]);
  920. }
  921. }
  922. function cacher(f, scope, postprocessor) {
  923. function newf() {
  924. var arg = Array.prototype.slice.call(arguments, 0),
  925. args = arg.join("\u2400"),
  926. cache = newf.cache = newf.cache || {},
  927. count = newf.count = newf.count || [];
  928. if (cache[has](args)) {
  929. repush(count, args);
  930. return postprocessor ? postprocessor(cache[args]) : cache[args];
  931. }
  932. count.length >= 1e3 && delete cache[count.shift()];
  933. count.push(args);
  934. cache[args] = f[apply](scope, arg);
  935. return postprocessor ? postprocessor(cache[args]) : cache[args];
  936. }
  937. return newf;
  938. }
  939. var preload = R._preload = function (src, f) {
  940. var img = g.doc.createElement("img");
  941. img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
  942. img.onload = function () {
  943. f.call(this);
  944. this.onload = null;
  945. g.doc.body.removeChild(this);
  946. };
  947. img.onerror = function () {
  948. g.doc.body.removeChild(this);
  949. };
  950. g.doc.body.appendChild(img);
  951. img.src = src;
  952. };
  953. function clrToString() {
  954. return this.hex;
  955. }
  956. /*\
  957. * Raphael.getRGB
  958. [ method ]
  959. **
  960. * Parses colour string as RGB object
  961. > Parameters
  962. - colour (string) colour string in one of formats:
  963. # <ul>
  964. # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
  965. # <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
  966. # <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
  967. # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
  968. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
  969. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
  970. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  971. # <li>hsl(•••, •••, •••) — same as hsb</li>
  972. # <li>hsl(•••%, •••%, •••%) — same as hsb</li>
  973. # </ul>
  974. = (object) RGB object in format:
  975. o {
  976. o r (number) red,
  977. o g (number) green,
  978. o b (number) blue
  979. o hex (string) color in HTML/CSS format: #••••••,
  980. o error (boolean) true if string can’t be parsed
  981. o }
  982. \*/
  983. R.getRGB = cacher(function (colour) {
  984. if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
  985. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  986. }
  987. if (colour == "none") {
  988. return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
  989. }
  990. !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  991. var res,
  992. red,
  993. green,
  994. blue,
  995. opacity,
  996. t,
  997. values,
  998. rgb = colour.match(colourRegExp);
  999. if (rgb) {
  1000. if (rgb[2]) {
  1001. blue = toInt(rgb[2].substring(5), 16);
  1002. green = toInt(rgb[2].substring(3, 5), 16);
  1003. red = toInt(rgb[2].substring(1, 3), 16);
  1004. }
  1005. if (rgb[3]) {
  1006. blue = toInt((t = rgb[3].charAt(3)) + t, 16);
  1007. green = toInt((t = rgb[3].charAt(2)) + t, 16);
  1008. red = toInt((t = rgb[3].charAt(1)) + t, 16);
  1009. }
  1010. if (rgb[4]) {
  1011. values = rgb[4][split](commaSpaces);
  1012. red = toFloat(values[0]);
  1013. values[0].slice(-1) == "%" && (red *= 2.55);
  1014. green = toFloat(values[1]);
  1015. values[1].slice(-1) == "%" && (green *= 2.55);
  1016. blue = toFloat(values[2]);
  1017. values[2].slice(-1) == "%" && (blue *= 2.55);
  1018. rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
  1019. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1020. }
  1021. if (rgb[5]) {
  1022. values = rgb[5][split](commaSpaces);
  1023. red = toFloat(values[0]);
  1024. values[0].slice(-1) == "%" && (red *= 2.55);
  1025. green = toFloat(values[1]);
  1026. values[1].slice(-1) == "%" && (green *= 2.55);
  1027. blue = toFloat(values[2]);
  1028. values[2].slice(-1) == "%" && (blue *= 2.55);
  1029. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1030. rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
  1031. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1032. return R.hsb2rgb(red, green, blue, opacity);
  1033. }
  1034. if (rgb[6]) {
  1035. values = rgb[6][split](commaSpaces);
  1036. red = toFloat(values[0]);
  1037. values[0].slice(-1) == "%" && (red *= 2.55);
  1038. green = toFloat(values[1]);
  1039. values[1].slice(-1) == "%" && (green *= 2.55);
  1040. blue = toFloat(values[2]);
  1041. values[2].slice(-1) == "%" && (blue *= 2.55);
  1042. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1043. rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
  1044. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1045. return R.hsl2rgb(red, green, blue, opacity);
  1046. }
  1047. rgb = {r: red, g: green, b: blue, toString: clrToString};
  1048. rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
  1049. R.is(opacity, "finite") && (rgb.opacity = opacity);
  1050. return rgb;
  1051. }
  1052. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  1053. }, R);
  1054. /*\
  1055. * Raphael.hsb
  1056. [ method ]
  1057. **
  1058. * Converts HSB values to hex representation of the colour.
  1059. > Parameters
  1060. - h (number) hue
  1061. - s (number) saturation
  1062. - b (number) value or brightness
  1063. = (string) hex representation of the colour.
  1064. \*/
  1065. R.hsb = cacher(function (h, s, b) {
  1066. return R.hsb2rgb(h, s, b).hex;
  1067. });
  1068. /*\
  1069. * Raphael.hsl
  1070. [ method ]
  1071. **
  1072. * Converts HSL values to hex representation of the colour.
  1073. > Parameters
  1074. - h (number) hue
  1075. - s (number) saturation
  1076. - l (number) luminosity
  1077. = (string) hex representation of the colour.
  1078. \*/
  1079. R.hsl = cacher(function (h, s, l) {
  1080. return R.hsl2rgb(h, s, l).hex;
  1081. });
  1082. /*\
  1083. * Raphael.rgb
  1084. [ method ]
  1085. **
  1086. * Converts RGB values to hex representation of the colour.
  1087. > Parameters
  1088. - r (number) red
  1089. - g (number) green
  1090. - b (number) blue
  1091. = (string) hex representation of the colour.
  1092. \*/
  1093. R.rgb = cacher(function (r, g, b) {
  1094. function round(x) { return (x + 0.5) | 0; }
  1095. return "#" + (16777216 | round(b) | (round(g) << 8) | (round(r) << 16)).toString(16).slice(1);
  1096. });
  1097. /*\
  1098. * Raphael.getColor
  1099. [ method ]
  1100. **
  1101. * On each call returns next colour in the spectrum. To reset it back to red call @Raphael.getColor.reset
  1102. > Parameters
  1103. - value (number) #optional brightness, default is `0.75`
  1104. = (string) hex representation of the colour.
  1105. \*/
  1106. R.getColor = function (value) {
  1107. var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
  1108. rgb = this.hsb2rgb(start.h, start.s, start.b);
  1109. start.h += .075;
  1110. if (start.h > 1) {
  1111. start.h = 0;
  1112. start.s -= .2;
  1113. start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
  1114. }
  1115. return rgb.hex;
  1116. };
  1117. /*\
  1118. * Raphael.getColor.reset
  1119. [ method ]
  1120. **
  1121. * Resets spectrum position for @Raphael.getColor back to red.
  1122. \*/
  1123. R.getColor.reset = function () {
  1124. delete this.start;
  1125. };
  1126. // http://schepers.cc/getting-to-the-point
  1127. function catmullRom2bezier(crp, z) {
  1128. var d = [];
  1129. for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
  1130. var p = [
  1131. {x: +crp[i - 2], y: +crp[i - 1]},
  1132. {x: +crp[i], y: +crp[i + 1]},
  1133. {x: +crp[i + 2], y: +crp[i + 3]},
  1134. {x: +crp[i + 4], y: +crp[i + 5]}
  1135. ];
  1136. if (z) {
  1137. if (!i) {
  1138. p[0] = {x: +crp[iLen - 2], y: +crp[iLen - 1]};
  1139. } else if (iLen - 4 == i) {
  1140. p[3] = {x: +crp[0], y: +crp[1]};
  1141. } else if (iLen - 2 == i) {
  1142. p[2] = {x: +crp[0], y: +crp[1]};
  1143. p[3] = {x: +crp[2], y: +crp[3]};
  1144. }
  1145. } else {
  1146. if (iLen - 4 == i) {
  1147. p[3] = p[2];
  1148. } else if (!i) {
  1149. p[0] = {x: +crp[i], y: +crp[i + 1]};
  1150. }
  1151. }
  1152. d.push(["C",
  1153. (-p[0].x + 6 * p[1].x + p[2].x) / 6,
  1154. (-p[0].y + 6 * p[1].y + p[2].y) / 6,
  1155. (p[1].x + 6 * p[2].x - p[3].x) / 6,
  1156. (p[1].y + 6*p[2].y - p[3].y) / 6,
  1157. p[2].x,
  1158. p[2].y
  1159. ]);
  1160. }
  1161. return d;
  1162. }
  1163. /*\
  1164. * Raphael.parsePathString
  1165. [ method ]
  1166. **
  1167. * Utility method
  1168. **
  1169. * Parses given path string into an array of arrays of path segments.
  1170. > Parameters
  1171. - pathString (string|array) path string or array of segments (in the last case it will be returned straight away)
  1172. = (array) array of segments.
  1173. \*/
  1174. R.parsePathString = function (pathString) {
  1175. if (!pathString) {
  1176. return null;
  1177. }
  1178. var pth = paths(pathString);
  1179. if (pth.arr) {
  1180. return pathClone(pth.arr);
  1181. }
  1182. var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
  1183. data = [];
  1184. if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
  1185. data = pathClone(pathString);
  1186. }
  1187. if (!data.length) {
  1188. Str(pathString).replace(pathCommand, function (a, b, c) {
  1189. var params = [],
  1190. name = b.toLowerCase();
  1191. c.replace(pathValues, function (a, b) {
  1192. b && params.push(+b);
  1193. });
  1194. if (name == "m" && params.length > 2) {
  1195. data.push([b][concat](params.splice(0, 2)));
  1196. name = "l";
  1197. b = b == "m" ? "l" : "L";
  1198. }
  1199. if (name == "r") {
  1200. data.push([b][concat](params));
  1201. } else while (params.length >= paramCounts[name]) {
  1202. data.push([b][concat](params.splice(0, paramCounts[name])));
  1203. if (!paramCounts[name]) {
  1204. break;
  1205. }
  1206. }
  1207. });
  1208. }
  1209. data.toString = R._path2string;
  1210. pth.arr = pathClone(data);
  1211. return data;
  1212. };
  1213. /*\
  1214. * Raphael.parseTransformString
  1215. [ method ]
  1216. **
  1217. * Utility method
  1218. **
  1219. * Parses given path string into an array of transformations.
  1220. > Parameters
  1221. - TString (string|array) transform string or array of transformations (in the last case it will be returned straight away)
  1222. = (array) array of transformations.
  1223. \*/
  1224. R.parseTransformString = cacher(function (TString) {
  1225. if (!TString) {
  1226. return null;
  1227. }
  1228. var paramCounts = {r: 3, s: 4, t: 2, m: 6},
  1229. data = [];
  1230. if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
  1231. data = pathClone(TString);
  1232. }
  1233. if (!data.length) {
  1234. Str(TString).replace(tCommand, function (a, b, c) {
  1235. var params = [],
  1236. name = lowerCase.call(b);
  1237. c.replace(pathValues, function (a, b) {
  1238. b && params.push(+b);
  1239. });
  1240. data.push([b][concat](params));
  1241. });
  1242. }
  1243. data.toString = R._path2string;
  1244. return data;
  1245. }, this, function(elem) {
  1246. if (!elem) return elem;
  1247. var newData = [];
  1248. for (var i = 0; i < elem.length; i++) {
  1249. var newLevel = [];
  1250. for (var j = 0; j < elem[i].length; j++) {
  1251. newLevel.push(elem[i][j]);
  1252. }
  1253. newData.push(newLevel);
  1254. }
  1255. return newData; } );
  1256. // PATHS
  1257. var paths = function (ps) {
  1258. var p = paths.ps = paths.ps || {};
  1259. if (p[ps]) {
  1260. p[ps].sleep = 100;
  1261. } else {
  1262. p[ps] = {
  1263. sleep: 100
  1264. };
  1265. }
  1266. setTimeout(function () {
  1267. for (var key in p) if (p[has](key) && key != ps) {
  1268. p[key].sleep--;
  1269. !p[key].sleep && delete p[key];
  1270. }
  1271. });
  1272. return p[ps];
  1273. };
  1274. /*\
  1275. * Raphael.findDotsAtSegment
  1276. [ method ]
  1277. **
  1278. * Utility method
  1279. **
  1280. * Find dot coordinates on the given cubic bezier curve at the given t.
  1281. > Parameters
  1282. - p1x (number) x of the first point of the curve
  1283. - p1y (number) y of the first point of the curve
  1284. - c1x (number) x of the first anchor of the curve
  1285. - c1y (number) y of the first anchor of the curve
  1286. - c2x (number) x of the second anchor of the curve
  1287. - c2y (number) y of the second anchor of the curve
  1288. - p2x (number) x of the second point of the curve
  1289. - p2y (number) y of the second point of the curve
  1290. - t (number) position on the curve (0..1)
  1291. = (object) point information in format:
  1292. o {
  1293. o x: (number) x coordinate of the point
  1294. o y: (number) y coordinate of the point
  1295. o m: {
  1296. o x: (number) x coordinate of the left anchor
  1297. o y: (number) y coordinate of the left anchor
  1298. o }
  1299. o n: {
  1300. o x: (number) x coordinate of the right anchor
  1301. o y: (number) y coordinate of the right anchor
  1302. o }
  1303. o start: {
  1304. o x: (number) x coordinate of the start of the curve
  1305. o y: (number) y coordinate of the start of the curve
  1306. o }
  1307. o end: {
  1308. o x: (number) x coordinate of the end of the curve
  1309. o y: (number) y coordinate of the end of the curve
  1310. o }
  1311. o alpha: (number) angle of the curve derivative at the point
  1312. o }
  1313. \*/
  1314. R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  1315. var t1 = 1 - t,
  1316. t13 = pow(t1, 3),
  1317. t12 = pow(t1, 2),
  1318. t2 = t * t,
  1319. t3 = t2 * t,
  1320. x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
  1321. y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
  1322. mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
  1323. my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
  1324. nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
  1325. ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
  1326. ax = t1 * p1x + t * c1x,
  1327. ay = t1 * p1y + t * c1y,
  1328. cx = t1 * c2x + t * p2x,
  1329. cy = t1 * c2y + t * p2y,
  1330. alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
  1331. (mx > nx || my < ny) && (alpha += 180);
  1332. return {
  1333. x: x,
  1334. y: y,
  1335. m: {x: mx, y: my},
  1336. n: {x: nx, y: ny},
  1337. start: {x: ax, y: ay},
  1338. end: {x: cx, y: cy},
  1339. alpha: alpha
  1340. };
  1341. };
  1342. /*\
  1343. * Raphael.bezierBBox
  1344. [ method ]
  1345. **
  1346. * Utility method
  1347. **
  1348. * Return bounding box of a given cubic bezier curve
  1349. > Parameters
  1350. - p1x (number) x of the first point of the curve
  1351. - p1y (number) y of the first point of the curve
  1352. - c1x (number) x of the first anchor of the curve
  1353. - c1y (number) y of the first anchor of the curve
  1354. - c2x (number) x of the second anchor of the curve
  1355. - c2y (number) y of the second anchor of the curve
  1356. - p2x (number) x of the second point of the curve
  1357. - p2y (number) y of the second point of the curve
  1358. * or
  1359. - bez (array) array of six points for bezier curve
  1360. = (object) point information in format:
  1361. o {
  1362. o min: {
  1363. o x: (number) x coordinate of the left point
  1364. o y: (number) y coordinate of the top point
  1365. o }
  1366. o max: {
  1367. o x: (number) x coordinate of the right point
  1368. o y: (number) y coordinate of the bottom point
  1369. o }
  1370. o }
  1371. \*/
  1372. R.bezierBBox = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  1373. if (!R.is(p1x, "array")) {
  1374. p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
  1375. }
  1376. var bbox = curveDim.apply(null, p1x);
  1377. return {
  1378. x: bbox.min.x,
  1379. y: bbox.min.y,
  1380. x2: bbox.max.x,
  1381. y2: bbox.max.y,
  1382. width: bbox.max.x - bbox.min.x,
  1383. height: bbox.max.y - bbox.min.y
  1384. };
  1385. };
  1386. /*\
  1387. * Raphael.isPointInsideBBox
  1388. [ method ]
  1389. **
  1390. * Utility method
  1391. **
  1392. * Returns `true` if given point is inside bounding boxes.
  1393. > Parameters
  1394. - bbox (string) bounding box
  1395. - x (string) x coordinate of the point
  1396. - y (string) y coordinate of the point
  1397. = (boolean) `true` if point inside
  1398. \*/
  1399. R.isPointInsideBBox = function (bbox, x, y) {
  1400. return x >= bbox.x && x <= bbox.x2 && y >= bbox.y && y <= bbox.y2;
  1401. };
  1402. /*\
  1403. * Raphael.isBBoxIntersect
  1404. [ method ]
  1405. **
  1406. * Utility method
  1407. **
  1408. * Returns `true` if two bounding boxes intersect
  1409. > Parameters
  1410. - bbox1 (string) first bounding box
  1411. - bbox2 (string) second bounding box
  1412. = (boolean) `true` if they intersect
  1413. \*/
  1414. R.isBBoxIntersect = function (bbox1, bbox2) {
  1415. var i = R.isPointInsideBBox;
  1416. return i(bbox2, bbox1.x, bbox1.y)
  1417. || i(bbox2, bbox1.x2, bbox1.y)
  1418. || i(bbox2, bbox1.x, bbox1.y2)
  1419. || i(bbox2, bbox1.x2, bbox1.y2)
  1420. || i(bbox1, bbox2.x, bbox2.y)
  1421. || i(bbox1, bbox2.x2, bbox2.y)
  1422. || i(bbox1, bbox2.x, bbox2.y2)
  1423. || i(bbox1, bbox2.x2, bbox2.y2)
  1424. || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
  1425. && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
  1426. };
  1427. function base3(t, p1, p2, p3, p4) {
  1428. var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
  1429. t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
  1430. return t * t2 - 3 * p1 + 3 * p2;
  1431. }
  1432. function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
  1433. if (z == null) {
  1434. z = 1;
  1435. }
  1436. z = z > 1 ? 1 : z < 0 ? 0 : z;
  1437. var z2 = z / 2,
  1438. n = 12,
  1439. Tvalues = [-0.1252,0.1252,-0.3678,0.3678,-0.5873,0.5873,-0.7699,0.7699,-0.9041,0.9041,-0.9816,0.9816],
  1440. Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472],
  1441. sum = 0;
  1442. for (var i = 0; i < n; i++) {
  1443. var ct = z2 * Tvalues[i] + z2,
  1444. xbase = base3(ct, x1, x2, x3, x4),
  1445. ybase = base3(ct, y1, y2, y3, y4),
  1446. comb = xbase * xbase + ybase * ybase;
  1447. sum += Cvalues[i] * math.sqrt(comb);
  1448. }
  1449. return z2 * sum;
  1450. }
  1451. function getTatLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) {
  1452. if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) {
  1453. return;
  1454. }
  1455. var t = 1,
  1456. step = t / 2,
  1457. t2 = t - step,
  1458. l,
  1459. e = .01;
  1460. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1461. while (abs(l - ll) > e) {
  1462. step /= 2;
  1463. t2 += (l < ll ? 1 : -1) * step;
  1464. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1465. }
  1466. return t2;
  1467. }
  1468. function intersect(x1, y1, x2, y2, x3, y3, x4, y4) {
  1469. if (
  1470. mmax(x1, x2) < mmin(x3, x4) ||
  1471. mmin(x1, x2) > mmax(x3, x4) ||
  1472. mmax(y1, y2) < mmin(y3, y4) ||
  1473. mmin(y1, y2) > mmax(y3, y4)
  1474. ) {
  1475. return;
  1476. }
  1477. var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
  1478. ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
  1479. denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  1480. if (!denominator) {
  1481. return;
  1482. }
  1483. var px = nx / denominator,
  1484. py = ny / denominator,
  1485. px2 = +px.toFixed(2),
  1486. py2 = +py.toFixed(2);
  1487. if (
  1488. px2 < +mmin(x1, x2).toFixed(2) ||
  1489. px2 > +mmax(x1, x2).toFixed(2) ||
  1490. px2 < +mmin(x3, x4).toFixed(2) ||
  1491. px2 > +mmax(x3, x4).toFixed(2) ||
  1492. py2 < +mmin(y1, y2).toFixed(2) ||
  1493. py2 > +mmax(y1, y2).toFixed(2) ||
  1494. py2 < +mmin(y3, y4).toFixed(2) ||
  1495. py2 > +mmax(y3, y4).toFixed(2)
  1496. ) {
  1497. return;
  1498. }
  1499. return {x: px, y: py};
  1500. }
  1501. function inter(bez1, bez2) {
  1502. return interHelper(bez1, bez2);
  1503. }
  1504. function interCount(bez1, bez2) {
  1505. return interHelper(bez1, bez2, 1);
  1506. }
  1507. function interHelper(bez1, bez2, justCount) {
  1508. var bbox1 = R.bezierBBox(bez1),
  1509. bbox2 = R.bezierBBox(bez2);
  1510. if (!R.isBBoxIntersect(bbox1, bbox2)) {
  1511. return justCount ? 0 : [];
  1512. }
  1513. var l1 = bezlen.apply(0, bez1),
  1514. l2 = bezlen.apply(0, bez2),
  1515. n1 = mmax(~~(l1 / 5), 1),
  1516. n2 = mmax(~~(l2 / 5), 1),
  1517. dots1 = [],
  1518. dots2 = [],
  1519. xy = {},
  1520. res = justCount ? 0 : [];
  1521. for (var i = 0; i < n1 + 1; i++) {
  1522. var p = R.findDotsAtSegment.apply(R, bez1.concat(i / n1));
  1523. dots1.push({x: p.x, y: p.y, t: i / n1});
  1524. }
  1525. for (i = 0; i < n2 + 1; i++) {
  1526. p = R.findDotsAtSegment.apply(R, bez2.concat(i / n2));
  1527. dots2.push({x: p.x, y: p.y, t: i / n2});
  1528. }
  1529. for (i = 0; i < n1; i++) {
  1530. for (var j = 0; j < n2; j++) {
  1531. var di = dots1[i],
  1532. di1 = dots1[i + 1],
  1533. dj = dots2[j],
  1534. dj1 = dots2[j + 1],
  1535. ci = abs(di1.x - di.x) < .001 ? "y" : "x",
  1536. cj = abs(dj1.x - dj.x) < .001 ? "y" : "x",
  1537. is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
  1538. if (is) {
  1539. if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {
  1540. continue;
  1541. }
  1542. xy[is.x.toFixed(4)] = is.y.toFixed(4);
  1543. var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
  1544. t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
  1545. if (t1 >= 0 && t1 <= 1.001 && t2 >= 0 && t2 <= 1.001) {
  1546. if (justCount) {
  1547. res++;
  1548. } else {
  1549. res.push({
  1550. x: is.x,
  1551. y: is.y,
  1552. t1: mmin(t1, 1),
  1553. t2: mmin(t2, 1)
  1554. });
  1555. }
  1556. }
  1557. }
  1558. }
  1559. }
  1560. return res;
  1561. }
  1562. /*\
  1563. * Raphael.pathIntersection
  1564. [ method ]
  1565. **
  1566. * Utility method
  1567. **
  1568. * Finds intersections of two paths
  1569. > Parameters
  1570. - path1 (string) path string
  1571. - path2 (string) path string
  1572. = (array) dots of intersection
  1573. o [
  1574. o {
  1575. o x: (number) x coordinate of the point
  1576. o y: (number) y coordinate of the point
  1577. o t1: (number) t value for segment of path1
  1578. o t2: (number) t value for segment of path2
  1579. o segment1: (number) order number for segment of path1
  1580. o segment2: (number) order number for segment of path2
  1581. o bez1: (array) eight coordinates representing beziér curve for the segment of path1
  1582. o bez2: (array) eight coordinates representing beziér curve for the segment of path2
  1583. o }
  1584. o ]
  1585. \*/
  1586. R.pathIntersection = function (path1, path2) {
  1587. return interPathHelper(path1, path2);
  1588. };
  1589. R.pathIntersectionNumber = function (path1, path2) {
  1590. return interPathHelper(path1, path2, 1);
  1591. };
  1592. function interPathHelper(path1, path2, justCount) {
  1593. path1 = R._path2curve(path1);
  1594. path2 = R._path2curve(path2);
  1595. var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
  1596. res = justCount ? 0 : [];
  1597. for (var i = 0, ii = path1.length; i < ii; i++) {
  1598. var pi = path1[i];
  1599. if (pi[0] == "M") {
  1600. x1 = x1m = pi[1];
  1601. y1 = y1m = pi[2];
  1602. } else {
  1603. if (pi[0] == "C") {
  1604. bez1 = [x1, y1].concat(pi.slice(1));
  1605. x1 = bez1[6];
  1606. y1 = bez1[7];
  1607. } else {
  1608. bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
  1609. x1 = x1m;
  1610. y1 = y1m;
  1611. }
  1612. for (var j = 0, jj = path2.length; j < jj; j++) {
  1613. var pj = path2[j];
  1614. if (pj[0] == "M") {
  1615. x2 = x2m = pj[1];
  1616. y2 = y2m = pj[2];
  1617. } else {
  1618. if (pj[0] == "C") {
  1619. bez2 = [x2, y2].concat(pj.slice(1));
  1620. x2 = bez2[6];
  1621. y2 = bez2[7];
  1622. } else {
  1623. bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
  1624. x2 = x2m;
  1625. y2 = y2m;
  1626. }
  1627. var intr = interHelper(bez1, bez2, justCount);
  1628. if (justCount) {
  1629. res += intr;
  1630. } else {
  1631. for (var k = 0, kk = intr.length; k < kk; k++) {
  1632. intr[k].segment1 = i;
  1633. intr[k].segment2 = j;
  1634. intr[k].bez1 = bez1;
  1635. intr[k].bez2 = bez2;
  1636. }
  1637. res = res.concat(intr);
  1638. }
  1639. }
  1640. }
  1641. }
  1642. }
  1643. return res;
  1644. }
  1645. /*\
  1646. * Raphael.isPointInsidePath
  1647. [ method ]
  1648. **
  1649. * Utility method
  1650. **
  1651. * Returns `true` if given point is inside a given closed path.
  1652. > Parameters
  1653. - path (string) path string
  1654. - x (number) x of the point
  1655. - y (number) y of the point
  1656. = (boolean) true, if point is inside the path
  1657. \*/
  1658. R.isPointInsidePath = function (path, x, y) {
  1659. var bbox = R.pathBBox(path);
  1660. return R.isPointInsideBBox(bbox, x, y) &&
  1661. interPathHelper(path, [["M", x, y], ["H", bbox.x2 + 10]], 1) % 2 == 1;
  1662. };
  1663. R._removedFactory = function (methodname) {
  1664. return function () {
  1665. eve("raphael.log", null, "Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object", methodname);
  1666. };
  1667. };
  1668. /*\
  1669. * Raphael.pathBBox
  1670. [ method ]
  1671. **
  1672. * Utility method
  1673. **
  1674. * Return bounding box of a given path
  1675. > Parameters
  1676. - path (string) path string
  1677. = (object) bounding box
  1678. o {
  1679. o x: (number) x coordinate of the left top point of the box
  1680. o y: (number) y coordinate of the left top point of the box
  1681. o x2: (number) x coordinate of the right bottom point of the box
  1682. o y2: (number) y coordinate of the right bottom point of the box
  1683. o width: (number) width of the box
  1684. o height: (number) height of the box
  1685. o cx: (number) x coordinate of the center of the box
  1686. o cy: (number) y coordinate of the center of the box
  1687. o }
  1688. \*/
  1689. var pathDimensions = R.pathBBox = function (path) {
  1690. var pth = paths(path);
  1691. if (pth.bbox) {
  1692. return clone(pth.bbox);
  1693. }
  1694. if (!path) {
  1695. return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0};
  1696. }
  1697. path = path2curve(path);
  1698. var x = 0,
  1699. y = 0,
  1700. X = [],
  1701. Y = [],
  1702. p;
  1703. for (var i = 0, ii = path.length; i < ii; i++) {
  1704. p = path[i];
  1705. if (p[0] == "M") {
  1706. x = p[1];
  1707. y = p[2];
  1708. X.push(x);
  1709. Y.push(y);
  1710. } else {
  1711. var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  1712. X = X[concat](dim.min.x, dim.max.x);
  1713. Y = Y[concat](dim.min.y, dim.max.y);
  1714. x = p[5];
  1715. y = p[6];
  1716. }
  1717. }
  1718. var xmin = mmin[apply](0, X),
  1719. ymin = mmin[apply](0, Y),
  1720. xmax = mmax[apply](0, X),
  1721. ymax = mmax[apply](0, Y),
  1722. width = xmax - xmin,
  1723. height = ymax - ymin,
  1724. bb = {
  1725. x: xmin,
  1726. y: ymin,
  1727. x2: xmax,
  1728. y2: ymax,
  1729. width: width,
  1730. height: height,
  1731. cx: xmin + width / 2,
  1732. cy: ymin + height / 2
  1733. };
  1734. pth.bbox = clone(bb);
  1735. return bb;
  1736. },
  1737. pathClone = function (pathArray) {
  1738. var res = clone(pathArray);
  1739. res.toString = R._path2string;
  1740. return res;
  1741. },
  1742. pathToRelative = R._pathToRelative = function (pathArray) {
  1743. var pth = paths(pathArray);
  1744. if (pth.rel) {
  1745. return pathClone(pth.rel);
  1746. }
  1747. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1748. pathArray = R.parsePathString(pathArray);
  1749. }
  1750. var res = [],
  1751. x = 0,
  1752. y = 0,
  1753. mx = 0,
  1754. my = 0,
  1755. start = 0;
  1756. if (pathArray[0][0] == "M") {
  1757. x = pathArray[0][1];
  1758. y = pathArray[0][2];
  1759. mx = x;
  1760. my = y;
  1761. start++;
  1762. res.push(["M", x, y]);
  1763. }
  1764. for (var i = start, ii = pathArray.length; i < ii; i++) {
  1765. var r = res[i] = [],
  1766. pa = pathArray[i];
  1767. if (pa[0] != lowerCase.call(pa[0])) {
  1768. r[0] = lowerCase.call(pa[0]);
  1769. switch (r[0]) {
  1770. case "a":
  1771. r[1] = pa[1];
  1772. r[2] = pa[2];
  1773. r[3] = pa[3];
  1774. r[4] = pa[4];
  1775. r[5] = pa[5];
  1776. r[6] = +(pa[6] - x).toFixed(3);
  1777. r[7] = +(pa[7] - y).toFixed(3);
  1778. break;
  1779. case "v":
  1780. r[1] = +(pa[1] - y).toFixed(3);
  1781. break;
  1782. case "m":
  1783. mx = pa[1];
  1784. my = pa[2];
  1785. default:
  1786. for (var j = 1, jj = pa.length; j < jj; j++) {
  1787. r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
  1788. }
  1789. }
  1790. } else {
  1791. r = res[i] = [];
  1792. if (pa[0] == "m") {
  1793. mx = pa[1] + x;
  1794. my = pa[2] + y;
  1795. }
  1796. for (var k = 0, kk = pa.length; k < kk; k++) {
  1797. res[i][k] = pa[k];
  1798. }
  1799. }
  1800. var len = res[i].length;
  1801. switch (res[i][0]) {
  1802. case "z":
  1803. x = mx;
  1804. y = my;
  1805. break;
  1806. case "h":
  1807. x += +res[i][len - 1];
  1808. break;
  1809. case "v":
  1810. y += +res[i][len - 1];
  1811. break;
  1812. default:
  1813. x += +res[i][len - 2];
  1814. y += +res[i][len - 1];
  1815. }
  1816. }
  1817. res.toString = R._path2string;
  1818. pth.rel = pathClone(res);
  1819. return res;
  1820. },
  1821. pathToAbsolute = R._pathToAbsolute = function (pathArray) {
  1822. var pth = paths(pathArray);
  1823. if (pth.abs) {
  1824. return pathClone(pth.abs);
  1825. }
  1826. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1827. pathArray = R.parsePathString(pathArray);
  1828. }
  1829. if (!pathArray || !pathArray.length) {
  1830. return [["M", 0, 0]];
  1831. }
  1832. var res = [],
  1833. x = 0,
  1834. y = 0,
  1835. mx = 0,
  1836. my = 0,
  1837. start = 0;
  1838. if (pathArray[0][0] == "M") {
  1839. x = +pathArray[0][1];
  1840. y = +pathArray[0][2];
  1841. mx = x;
  1842. my = y;
  1843. start++;
  1844. res[0] = ["M", x, y];
  1845. }
  1846. var crz = pathArray.length == 3 && pathArray[0][0] == "M" && pathArray[1][0].toUpperCase() == "R" && pathArray[2][0].toUpperCase() == "Z";
  1847. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  1848. res.push(r = []);
  1849. pa = pathArray[i];
  1850. if (pa[0] != upperCase.call(pa[0])) {
  1851. r[0] = upperCase.call(pa[0]);
  1852. switch (r[0]) {
  1853. case "A":
  1854. r[1] = pa[1];
  1855. r[2] = pa[2];
  1856. r[3] = pa[3];
  1857. r[4] = pa[4];
  1858. r[5] = pa[5];
  1859. r[6] = +(pa[6] + x);
  1860. r[7] = +(pa[7] + y);
  1861. break;
  1862. case "V":
  1863. r[1] = +pa[1] + y;
  1864. break;
  1865. case "H":
  1866. r[1] = +pa[1] + x;
  1867. break;
  1868. case "R":
  1869. var dots = [x, y][concat](pa.slice(1));
  1870. for (var j = 2, jj = dots.length; j < jj; j++) {
  1871. dots[j] = +dots[j] + x;
  1872. dots[++j] = +dots[j] + y;
  1873. }
  1874. res.pop();
  1875. res = res[concat](catmullRom2bezier(dots, crz));
  1876. break;
  1877. case "M":
  1878. mx = +pa[1] + x;
  1879. my = +pa[2] + y;
  1880. default:
  1881. for (j = 1, jj = pa.length; j < jj; j++) {
  1882. r[j] = +pa[j] + ((j % 2) ? x : y);
  1883. }
  1884. }
  1885. } else if (pa[0] == "R") {
  1886. dots = [x, y][concat](pa.slice(1));
  1887. res.pop();
  1888. res = res[concat](catmullRom2bezier(dots, crz));
  1889. r = ["R"][concat](pa.slice(-2));
  1890. } else {
  1891. for (var k = 0, kk = pa.length; k < kk; k++) {
  1892. r[k] = pa[k];
  1893. }
  1894. }
  1895. switch (r[0]) {
  1896. case "Z":
  1897. x = mx;
  1898. y = my;
  1899. break;
  1900. case "H":
  1901. x = r[1];
  1902. break;
  1903. case "V":
  1904. y = r[1];
  1905. break;
  1906. case "M":
  1907. mx = r[r.length - 2];
  1908. my = r[r.length - 1];
  1909. default:
  1910. x = r[r.length - 2];
  1911. y = r[r.length - 1];
  1912. }
  1913. }
  1914. res.toString = R._path2string;
  1915. pth.abs = pathClone(res);
  1916. return res;
  1917. },
  1918. l2c = function (x1, y1, x2, y2) {
  1919. return [x1, y1, x2, y2, x2, y2];
  1920. },
  1921. q2c = function (x1, y1, ax, ay, x2, y2) {
  1922. var _13 = 1 / 3,
  1923. _23 = 2 / 3;
  1924. return [
  1925. _13 * x1 + _23 * ax,
  1926. _13 * y1 + _23 * ay,
  1927. _13 * x2 + _23 * ax,
  1928. _13 * y2 + _23 * ay,
  1929. x2,
  1930. y2
  1931. ];
  1932. },
  1933. a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  1934. // for more information of where this math came from visit:
  1935. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  1936. var _120 = PI * 120 / 180,
  1937. rad = PI / 180 * (+angle || 0),
  1938. res = [],
  1939. xy,
  1940. rotate = cacher(function (x, y, rad) {
  1941. var X = x * math.cos(rad) - y * math.sin(rad),
  1942. Y = x * math.sin(rad) + y * math.cos(rad);
  1943. return {x: X, y: Y};
  1944. });
  1945. if (!recursive) {
  1946. xy = rotate(x1, y1, -rad);
  1947. x1 = xy.x;
  1948. y1 = xy.y;
  1949. xy = rotate(x2, y2, -rad);
  1950. x2 = xy.x;
  1951. y2 = xy.y;
  1952. var cos = math.cos(PI / 180 * angle),
  1953. sin = math.sin(PI / 180 * angle),
  1954. x = (x1 - x2) / 2,
  1955. y = (y1 - y2) / 2;
  1956. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  1957. if (h > 1) {
  1958. h = math.sqrt(h);
  1959. rx = h * rx;
  1960. ry = h * ry;
  1961. }
  1962. var rx2 = rx * rx,
  1963. ry2 = ry * ry,
  1964. k = (large_arc_flag == sweep_flag ? -1 : 1) *
  1965. math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
  1966. cx = k * rx * y / ry + (x1 + x2) / 2,
  1967. cy = k * -ry * x / rx + (y1 + y2) / 2,
  1968. f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
  1969. f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  1970. f1 = x1 < cx ? PI - f1 : f1;
  1971. f2 = x2 < cx ? PI - f2 : f2;
  1972. f1 < 0 && (f1 = PI * 2 + f1);
  1973. f2 < 0 && (f2 = PI * 2 + f2);
  1974. if (sweep_flag && f1 > f2) {
  1975. f1 = f1 - PI * 2;
  1976. }
  1977. if (!sweep_flag && f2 > f1) {
  1978. f2 = f2 - PI * 2;
  1979. }
  1980. } else {
  1981. f1 = recursive[0];
  1982. f2 = recursive[1];
  1983. cx = recursive[2];
  1984. cy = recursive[3];
  1985. }
  1986. var df = f2 - f1;
  1987. if (abs(df) > _120) {
  1988. var f2old = f2,
  1989. x2old = x2,
  1990. y2old = y2;
  1991. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  1992. x2 = cx + rx * math.cos(f2);
  1993. y2 = cy + ry * math.sin(f2);
  1994. res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  1995. }
  1996. df = f2 - f1;
  1997. var c1 = math.cos(f1),
  1998. s1 = math.sin(f1),
  1999. c2 = math.cos(f2),
  2000. s2 = math.sin(f2),
  2001. t = math.tan(df / 4),
  2002. hx = 4 / 3 * rx * t,
  2003. hy = 4 / 3 * ry * t,
  2004. m1 = [x1, y1],
  2005. m2 = [x1 + hx * s1, y1 - hy * c1],
  2006. m3 = [x2 + hx * s2, y2 - hy * c2],
  2007. m4 = [x2, y2];
  2008. m2[0] = 2 * m1[0] - m2[0];
  2009. m2[1] = 2 * m1[1] - m2[1];
  2010. if (recursive) {
  2011. return [m2, m3, m4][concat](res);
  2012. } else {
  2013. res = [m2, m3, m4][concat](res).join()[split](",");
  2014. var newres = [];
  2015. for (var i = 0, ii = res.length; i < ii; i++) {
  2016. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  2017. }
  2018. return newres;
  2019. }
  2020. },
  2021. findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  2022. var t1 = 1 - t;
  2023. return {
  2024. x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
  2025. y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
  2026. };
  2027. },
  2028. curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  2029. var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
  2030. b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
  2031. c = p1x - c1x,
  2032. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2033. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2034. y = [p1y, p2y],
  2035. x = [p1x, p2x],
  2036. dot;
  2037. abs(t1) > "1e12" && (t1 = .5);
  2038. abs(t2) > "1e12" && (t2 = .5);
  2039. if (t1 > 0 && t1 < 1) {
  2040. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2041. x.push(dot.x);
  2042. y.push(dot.y);
  2043. }
  2044. if (t2 > 0 && t2 < 1) {
  2045. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2046. x.push(dot.x);
  2047. y.push(dot.y);
  2048. }
  2049. a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
  2050. b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
  2051. c = p1y - c1y;
  2052. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2053. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2054. abs(t1) > "1e12" && (t1 = .5);
  2055. abs(t2) > "1e12" && (t2 = .5);
  2056. if (t1 > 0 && t1 < 1) {
  2057. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2058. x.push(dot.x);
  2059. y.push(dot.y);
  2060. }
  2061. if (t2 > 0 && t2 < 1) {
  2062. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2063. x.push(dot.x);
  2064. y.push(dot.y);
  2065. }
  2066. return {
  2067. min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
  2068. max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
  2069. };
  2070. }),
  2071. path2curve = R._path2curve = cacher(function (path, path2) {
  2072. var pth = !path2 && paths(path);
  2073. if (!path2 && pth.curve) {
  2074. return pathClone(pth.curve);
  2075. }
  2076. var p = pathToAbsolute(path),
  2077. p2 = path2 && pathToAbsolute(path2),
  2078. attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2079. attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2080. processPath = function (path, d, pcom) {
  2081. var nx, ny, tq = {T:1, Q:1};
  2082. if (!path) {
  2083. return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
  2084. }
  2085. !(path[0] in tq) && (d.qx = d.qy = null);
  2086. switch (path[0]) {
  2087. case "M":
  2088. d.X = path[1];
  2089. d.Y = path[2];
  2090. break;
  2091. case "A":
  2092. path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
  2093. break;
  2094. case "S":
  2095. if (pcom == "C" || pcom == "S") { // In "S" case we have to take into account, if the previous command is C/S.
  2096. nx = d.x * 2 - d.bx; // And reflect the previous
  2097. ny = d.y * 2 - d.by; // command's control point relative to the current point.
  2098. }
  2099. else { // or some else or nothing
  2100. nx = d.x;
  2101. ny = d.y;
  2102. }
  2103. path = ["C", nx, ny][concat](path.slice(1));
  2104. break;
  2105. case "T":
  2106. if (pcom == "Q" || pcom == "T") { // In "T" case we have to take into account, if the previous command is Q/T.
  2107. d.qx = d.x * 2 - d.qx; // And make a reflection similar
  2108. d.qy = d.y * 2 - d.qy; // to case "S".
  2109. }
  2110. else { // or something else or nothing
  2111. d.qx = d.x;
  2112. d.qy = d.y;
  2113. }
  2114. path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  2115. break;
  2116. case "Q":
  2117. d.qx = path[1];
  2118. d.qy = path[2];
  2119. path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
  2120. break;
  2121. case "L":
  2122. path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
  2123. break;
  2124. case "H":
  2125. path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
  2126. break;
  2127. case "V":
  2128. path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
  2129. break;
  2130. case "Z":
  2131. path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
  2132. break;
  2133. }
  2134. return path;
  2135. },
  2136. fixArc = function (pp, i) {
  2137. if (pp[i].length > 7) {
  2138. pp[i].shift();
  2139. var pi = pp[i];
  2140. while (pi.length) {
  2141. pcoms1[i]="A"; // if created multiple C:s, their original seg is saved
  2142. p2 && (pcoms2[i]="A"); // the same as above
  2143. pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
  2144. }
  2145. pp.splice(i, 1);
  2146. ii = mmax(p.length, p2 && p2.length || 0);
  2147. }
  2148. },
  2149. fixM = function (path1, path2, a1, a2, i) {
  2150. if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
  2151. path2.splice(i, 0, ["M", a2.x, a2.y]);
  2152. a1.bx = 0;
  2153. a1.by = 0;
  2154. a1.x = path1[i][1];
  2155. a1.y = path1[i][2];
  2156. ii = mmax(p.length, p2 && p2.length || 0);
  2157. }
  2158. },
  2159. pcoms1 = [], // path commands of original path p
  2160. pcoms2 = [], // path commands of original path p2
  2161. pfirst = "", // temporary holder for original path command
  2162. pcom = ""; // holder for previous path command of original path
  2163. for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
  2164. p[i] && (pfirst = p[i][0]); // save current path command
  2165. if (pfirst != "C") // C is not saved yet, because it may be result of conversion
  2166. {
  2167. pcoms1[i] = pfirst; // Save current path command
  2168. i && ( pcom = pcoms1[i-1]); // Get previous path command pcom
  2169. }
  2170. p[i] = processPath(p[i], attrs, pcom); // Previous path command is inputted to processPath
  2171. if (pcoms1[i] != "A" && pfirst == "C") pcoms1[i] = "C"; // A is the only command
  2172. // which may produce multiple C:s
  2173. // so we have to make sure that C is also C in original path
  2174. fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1
  2175. if (p2) { // the same procedures is done to p2
  2176. p2[i] && (pfirst = p2[i][0]);
  2177. if (pfirst != "C")
  2178. {
  2179. pcoms2[i] = pfirst;
  2180. i && (pcom = pcoms2[i-1]);
  2181. }
  2182. p2[i] = processPath(p2[i], attrs2, pcom);
  2183. if (pcoms2[i]!="A" && pfirst=="C") pcoms2[i]="C";
  2184. fixArc(p2, i);
  2185. }
  2186. fixM(p, p2, attrs, attrs2, i);
  2187. fixM(p2, p, attrs2, attrs, i);
  2188. var seg = p[i],
  2189. seg2 = p2 && p2[i],
  2190. seglen = seg.length,
  2191. seg2len = p2 && seg2.length;
  2192. attrs.x = seg[seglen - 2];
  2193. attrs.y = seg[seglen - 1];
  2194. attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
  2195. attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
  2196. attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
  2197. attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
  2198. attrs2.x = p2 && seg2[seg2len - 2];
  2199. attrs2.y = p2 && seg2[seg2len - 1];
  2200. }
  2201. if (!p2) {
  2202. pth.curve = pathClone(p);
  2203. }
  2204. return p2 ? [p, p2] : p;
  2205. }, null, pathClone),
  2206. parseDots = R._parseDots = cacher(function (gradient) {
  2207. var dots = [];
  2208. for (var i = 0, ii = gradient.length; i < ii; i++) {
  2209. var dot = {},
  2210. par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
  2211. dot.color = R.getRGB(par[1]);
  2212. if (dot.color.error) {
  2213. return null;
  2214. }
  2215. dot.opacity = dot.color.opacity;
  2216. dot.color = dot.color.hex;
  2217. par[2] && (dot.offset = par[2] + "%");
  2218. dots.push(dot);
  2219. }
  2220. for (i = 1, ii = dots.length - 1; i < ii; i++) {
  2221. if (!dots[i].offset) {
  2222. var start = toFloat(dots[i - 1].offset || 0),
  2223. end = 0;
  2224. for (var j = i + 1; j < ii; j++) {
  2225. if (dots[j].offset) {
  2226. end = dots[j].offset;
  2227. break;
  2228. }
  2229. }
  2230. if (!end) {
  2231. end = 100;
  2232. j = ii;
  2233. }
  2234. end = toFloat(end);
  2235. var d = (end - start) / (j - i + 1);
  2236. for (; i < j; i++) {
  2237. start += d;
  2238. dots[i].offset = start + "%";
  2239. }
  2240. }
  2241. }
  2242. return dots;
  2243. }),
  2244. tear = R._tear = function (el, paper) {
  2245. el == paper.top && (paper.top = el.prev);
  2246. el == paper.bottom && (paper.bottom = el.next);
  2247. el.next && (el.next.prev = el.prev);
  2248. el.prev && (el.prev.next = el.next);
  2249. },
  2250. tofront = R._tofront = function (el, paper) {
  2251. if (paper.top === el) {
  2252. return;
  2253. }
  2254. tear(el, paper);
  2255. el.next = null;
  2256. el.prev = paper.top;
  2257. paper.top.next = el;
  2258. paper.top = el;
  2259. },
  2260. toback = R._toback = function (el, paper) {
  2261. if (paper.bottom === el) {
  2262. return;
  2263. }
  2264. tear(el, paper);
  2265. el.next = paper.bottom;
  2266. el.prev = null;
  2267. paper.bottom.prev = el;
  2268. paper.bottom = el;
  2269. },
  2270. insertafter = R._insertafter = function (el, el2, paper) {
  2271. tear(el, paper);
  2272. el2 == paper.top && (paper.top = el);
  2273. el2.next && (el2.next.prev = el);
  2274. el.next = el2.next;
  2275. el.prev = el2;
  2276. el2.next = el;
  2277. },
  2278. insertbefore = R._insertbefore = function (el, el2, paper) {
  2279. tear(el, paper);
  2280. el2 == paper.bottom && (paper.bottom = el);
  2281. el2.prev && (el2.prev.next = el);
  2282. el.prev = el2.prev;
  2283. el2.prev = el;
  2284. el.next = el2;
  2285. },
  2286. /*\
  2287. * Raphael.toMatrix
  2288. [ method ]
  2289. **
  2290. * Utility method
  2291. **
  2292. * Returns matrix of transformations applied to a given path
  2293. > Parameters
  2294. - path (string) path string
  2295. - transform (string|array) transformation string
  2296. = (object) @Matrix
  2297. \*/
  2298. toMatrix = R.toMatrix = function (path, transform) {
  2299. var bb = pathDimensions(path),
  2300. el = {
  2301. _: {
  2302. transform: E
  2303. },
  2304. getBBox: function () {
  2305. return bb;
  2306. }
  2307. };
  2308. extractTransform(el, transform);
  2309. return el.matrix;
  2310. },
  2311. /*\
  2312. * Raphael.transformPath
  2313. [ method ]
  2314. **
  2315. * Utility method
  2316. **
  2317. * Returns path transformed by a given transformation
  2318. > Parameters
  2319. - path (string) path string
  2320. - transform (string|array) transformation string
  2321. = (string) path
  2322. \*/
  2323. transformPath = R.transformPath = function (path, transform) {
  2324. return mapPath(path, toMatrix(path, transform));
  2325. },
  2326. extractTransform = R._extractTransform = function (el, tstr) {
  2327. if (tstr == null) {
  2328. return el._.transform;
  2329. }
  2330. tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
  2331. var tdata = R.parseTransformString(tstr),
  2332. deg = 0,
  2333. dx = 0,
  2334. dy = 0,
  2335. sx = 1,
  2336. sy = 1,
  2337. _ = el._,
  2338. m = new Matrix;
  2339. _.transform = tdata || [];
  2340. if (tdata) {
  2341. for (var i = 0, ii = tdata.length; i < ii; i++) {
  2342. var t = tdata[i],
  2343. tlen = t.length,
  2344. command = Str(t[0]).toLowerCase(),
  2345. absolute = t[0] != command,
  2346. inver = absolute ? m.invert() : 0,
  2347. x1,
  2348. y1,
  2349. x2,
  2350. y2,
  2351. bb;
  2352. if (command == "t" && tlen == 3) {
  2353. if (absolute) {
  2354. x1 = inver.x(0, 0);
  2355. y1 = inver.y(0, 0);
  2356. x2 = inver.x(t[1], t[2]);
  2357. y2 = inver.y(t[1], t[2]);
  2358. m.translate(x2 - x1, y2 - y1);
  2359. } else {
  2360. m.translate(t[1], t[2]);
  2361. }
  2362. } else if (command == "r") {
  2363. if (tlen == 2) {
  2364. bb = bb || el.getBBox(1);
  2365. m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2366. deg += t[1];
  2367. } else if (tlen == 4) {
  2368. if (absolute) {
  2369. x2 = inver.x(t[2], t[3]);
  2370. y2 = inver.y(t[2], t[3]);
  2371. m.rotate(t[1], x2, y2);
  2372. } else {
  2373. m.rotate(t[1], t[2], t[3]);
  2374. }
  2375. deg += t[1];
  2376. }
  2377. } else if (command == "s") {
  2378. if (tlen == 2 || tlen == 3) {
  2379. bb = bb || el.getBBox(1);
  2380. m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2381. sx *= t[1];
  2382. sy *= t[tlen - 1];
  2383. } else if (tlen == 5) {
  2384. if (absolute) {
  2385. x2 = inver.x(t[3], t[4]);
  2386. y2 = inver.y(t[3], t[4]);
  2387. m.scale(t[1], t[2], x2, y2);
  2388. } else {
  2389. m.scale(t[1], t[2], t[3], t[4]);
  2390. }
  2391. sx *= t[1];
  2392. sy *= t[2];
  2393. }
  2394. } else if (command == "m" && tlen == 7) {
  2395. m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
  2396. }
  2397. _.dirtyT = 1;
  2398. el.matrix = m;
  2399. }
  2400. }
  2401. /*\
  2402. * Element.matrix
  2403. [ property (object) ]
  2404. **
  2405. * Keeps @Matrix object, which represents element transformation
  2406. \*/
  2407. el.matrix = m;
  2408. _.sx = sx;
  2409. _.sy = sy;
  2410. _.deg = deg;
  2411. _.dx = dx = m.e;
  2412. _.dy = dy = m.f;
  2413. if (sx == 1 && sy == 1 && !deg && _.bbox) {
  2414. _.bbox.x += +dx;
  2415. _.bbox.y += +dy;
  2416. } else {
  2417. _.dirtyT = 1;
  2418. }
  2419. },
  2420. getEmpty = function (item) {
  2421. var l = item[0];
  2422. switch (l.toLowerCase()) {
  2423. case "t": return [l, 0, 0];
  2424. case "m": return [l, 1, 0, 0, 1, 0, 0];
  2425. case "r": if (item.length == 4) {
  2426. return [l, 0, item[2], item[3]];
  2427. } else {
  2428. return [l, 0];
  2429. }
  2430. case "s": if (item.length == 5) {
  2431. return [l, 1, 1, item[3], item[4]];
  2432. } else if (item.length == 3) {
  2433. return [l, 1, 1];
  2434. } else {
  2435. return [l, 1];
  2436. }
  2437. }
  2438. },
  2439. equaliseTransform = R._equaliseTransform = function (t1, t2) {
  2440. t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
  2441. t1 = R.parseTransformString(t1) || [];
  2442. t2 = R.parseTransformString(t2) || [];
  2443. var maxlength = mmax(t1.length, t2.length),
  2444. from = [],
  2445. to = [],
  2446. i = 0, j, jj,
  2447. tt1, tt2;
  2448. for (; i < maxlength; i++) {
  2449. tt1 = t1[i] || getEmpty(t2[i]);
  2450. tt2 = t2[i] || getEmpty(tt1);
  2451. if ((tt1[0] != tt2[0]) ||
  2452. (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
  2453. (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
  2454. ) {
  2455. return;
  2456. }
  2457. from[i] = [];
  2458. to[i] = [];
  2459. for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
  2460. j in tt1 && (from[i][j] = tt1[j]);
  2461. j in tt2 && (to[i][j] = tt2[j]);
  2462. }
  2463. }
  2464. return {
  2465. from: from,
  2466. to: to
  2467. };
  2468. };
  2469. R._getContainer = function (x, y, w, h) {
  2470. var container;
  2471. container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
  2472. if (container == null) {
  2473. return;
  2474. }
  2475. if (container.tagName) {
  2476. if (y == null) {
  2477. return {
  2478. container: container,
  2479. width: container.style.pixelWidth || container.offsetWidth,
  2480. height: container.style.pixelHeight || container.offsetHeight
  2481. };
  2482. } else {
  2483. return {
  2484. container: container,
  2485. width: y,
  2486. height: w
  2487. };
  2488. }
  2489. }
  2490. return {
  2491. container: 1,
  2492. x: x,
  2493. y: y,
  2494. width: w,
  2495. height: h
  2496. };
  2497. };
  2498. /*\
  2499. * Raphael.pathToRelative
  2500. [ method ]
  2501. **
  2502. * Utility method
  2503. **
  2504. * Converts path to relative form
  2505. > Parameters
  2506. - pathString (string|array) path string or array of segments
  2507. = (array) array of segments.
  2508. \*/
  2509. R.pathToRelative = pathToRelative;
  2510. R._engine = {};
  2511. /*\
  2512. * Raphael.path2curve
  2513. [ method ]
  2514. **
  2515. * Utility method
  2516. **
  2517. * Converts path to a new path where all segments are cubic bezier curves.
  2518. > Parameters
  2519. - pathString (string|array) path string or array of segments
  2520. = (array) array of segments.
  2521. \*/
  2522. R.path2curve = path2curve;
  2523. /*\
  2524. * Raphael.matrix
  2525. [ method ]
  2526. **
  2527. * Utility method
  2528. **
  2529. * Returns matrix based on given parameters.
  2530. > Parameters
  2531. - a (number)
  2532. - b (number)
  2533. - c (number)
  2534. - d (number)
  2535. - e (number)
  2536. - f (number)
  2537. = (object) @Matrix
  2538. \*/
  2539. R.matrix = function (a, b, c, d, e, f) {
  2540. return new Matrix(a, b, c, d, e, f);
  2541. };
  2542. function Matrix(a, b, c, d, e, f) {
  2543. if (a != null) {
  2544. this.a = +a;
  2545. this.b = +b;
  2546. this.c = +c;