2 * Raphael 1.4.7 - JavaScript Vector Library
4 * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
8 Raphael = (function () {
10 if (R.is(arguments[0], array)) {
12 cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
14 for (var i = 0, ii = a[length]; i < ii; i++) {
16 elements.test(j.type) && res[push](cnv[j.type]().attr(j));
20 return create[apply](R, arguments);
23 var separator = /[, ]+/,
24 elements = /^(circle|rect|path|ellipse|text|image)$/,
26 has = "hasOwnProperty",
30 was: Object[proto][has].call(win, "Raphael"),
33 Paper = function () {},
34 appendChild = "appendChild",
37 supportsTouch = "createTouch" in doc,
42 events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
44 mousedown: "touchstart",
45 mousemove: "touchmove",
50 lowerCase = String[proto].toLowerCase,
57 toString = "toString",
59 objectToString = Object[proto][toString],
64 ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
65 colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+(?:\s*,\s*[\d\.]+)?)\s*\)|rgba?\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%(?:\s*,\s*[\d\.]+%)?)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i,
67 setAttribute = "setAttribute",
70 ms = " progid:DXImageTransform.Microsoft",
71 upperCase = String[proto].toUpperCase,
72 availableAttrs = {blur: 0, "clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
73 availableAnimAttrs = {along: "along", blur: nu, "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu},
75 R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
76 if (R.type == "VML") {
77 var d = doc.createElement("div"),
79 d.innerHTML = '<v:shape adj="1"/>';
81 b.style.behavior = "url(#default#VML)";
82 if (!(b && typeof b.adj == "object")) {
87 R.svg = !(R.vml = R.type == "VML");
88 Paper[proto] = R[proto];
92 R.is = function (o, type) {
93 type = lowerCase.call(type);
94 return (type == "object" && o === Object(o)) ||
95 (type == "undefined" && typeof o == type) ||
96 (type == "null" && o == null) ||
97 (type == "array" && Array.isArray && Array.isArray(o)) ||
98 lowerCase.call(objectToString.call(o).slice(8, -1)) == type;
101 R.setWindow = function (newwin) {
106 var toHex = function (color) {
108 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
109 var trim = /^\s+|\s+$/g;
110 toHex = cacher(function (color) {
112 color = Str(color)[rp](trim, E);
114 var docum = new win.ActiveXObject("htmlfile");
115 docum.write("<body>");
119 bod = win.createPopup().document.body;
121 var range = bod.createTextRange();
123 bod.style.color = color;
124 var value = range.queryCommandValue("ForeColor");
125 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
126 return "#" + ("000000" + value[toString](16)).slice(-6);
132 var i = doc.createElement("i");
133 i.title = "Rapha\xebl Colour Picker";
134 i.style.display = "none";
135 doc.body[appendChild](i);
136 toHex = cacher(function (color) {
137 i.style.color = color;
138 return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
143 hsbtoString = function () {
144 return "hsb(" + [this.h, this.s, this.b] + ")";
146 hsltoString = function () {
147 return "hsl(" + [this.h, this.s, this.l] + ")";
149 rgbtoString = function () {
152 R.hsb2rgb = function (h, s, b) {
153 if (R.is(h, "object") && "h" in h && "s" in h && "b" in h) {
158 return R.hsl2rgb(h, s, b / 2);
160 R.hsl2rgb = function (h, s, l) {
161 if (R.is(h, "object") && "h" in h && "s" in h && "l" in h) {
167 channels = ["r", "g", "b"],
182 for (var i = 0, ii = channels.length; i < ii; i++) {
183 t3 = h + 1 / 3 * -(i - 1);
187 rgb[channels[i]] = t1 + (t2 - t1) * 6 * t3;
188 } else if (t3 * 2 < 1) {
189 rgb[channels[i]] = t2;
190 } else if (t3 * 3 < 2) {
191 rgb[channels[i]] = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
193 rgb[channels[i]] = t1;
200 r = (~~rgb.r)[toString](16);
201 g = (~~rgb.g)[toString](16);
202 b = (~~rgb.b)[toString](16);
206 rgb.hex = "#" + r + g + b;
207 rgb.toString = rgbtoString;
210 R.rgb2hsb = function (red, green, blue) {
211 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
216 if (green == null && R.is(red, string)) {
217 var clr = R.getRGB(red);
222 if (red > 1 || green > 1 || blue > 1) {
227 var max = mmax(red, green, blue),
228 min = mmin(red, green, blue),
233 return {h: 0, s: 0, b: max, toString: hsbtoString};
235 var delta = (max - min);
236 saturation = delta / max;
238 hue = (green - blue) / delta;
239 } else if (green == max) {
240 hue = 2 + ((blue - red) / delta);
242 hue = 4 + ((red - green) / delta);
248 return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
250 R.rgb2hsl = function (red, green, blue) {
251 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
256 if (green == null && R.is(red, string)) {
257 var clr = R.getRGB(red);
262 if (red > 1 || green > 1 || blue > 1) {
267 var max = mmax(red, green, blue),
268 min = mmin(red, green, blue),
274 hsl = {h: 0, s: 0, l: l};
276 var delta = max - min;
277 s = l < .5 ? delta / (max + min) : delta / (2 - max - min);
279 h = (green - blue) / delta;
280 } else if (green == max) {
281 h = 2 + (blue - red) / delta;
283 h = 4 + (red - green) / delta;
288 hsl = {h: h, s: s, l: l};
290 hsl.toString = hsltoString;
293 var p2s = /,?([achlmqrstvxz]),?/gi,
294 commaSpaces = /\s*,\s*/,
295 hsrg = {hs: 1, rg: 1};
296 R._path2string = function () {
297 return this.join(",")[rp](p2s, "$1");
299 function cacher(f, scope, postprocessor) {
301 var arg = Array[proto].slice.call(arguments, 0),
302 args = arg[join]("\u25ba"),
303 cache = newf.cache = newf.cache || {},
304 count = newf.count = newf.count || [];
305 if (cache[has](args)) {
306 return postprocessor ? postprocessor(cache[args]) : cache[args];
308 count[length] >= 1e3 && delete cache[count.shift()];
310 cache[args] = f[apply](scope, arg);
311 return postprocessor ? postprocessor(cache[args]) : cache[args];
316 R.getRGB = cacher(function (colour) {
317 if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
318 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
320 if (colour == "none") {
321 return {r: -1, g: -1, b: -1, hex: "none"};
323 !(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
330 rgb = colour.match(colourRegExp);
333 blue = toInt(rgb[2].substring(5), 16);
334 green = toInt(rgb[2].substring(3, 5), 16);
335 red = toInt(rgb[2].substring(1, 3), 16);
338 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
339 green = toInt((t = rgb[3].charAt(2)) + t, 16);
340 red = toInt((t = rgb[3].charAt(1)) + t, 16);
343 rgb = rgb[4][split](commaSpaces);
344 red = toFloat(rgb[0]);
345 green = toFloat(rgb[1]);
346 blue = toFloat(rgb[2]);
347 opacity = toFloat(rgb[3]);
350 rgb = rgb[5][split](commaSpaces);
351 red = toFloat(rgb[0]) * 2.55;
352 green = toFloat(rgb[1]) * 2.55;
353 blue = toFloat(rgb[2]) * 2.55;
354 opacity = toFloat(rgb[3]);
357 rgb = rgb[6][split](commaSpaces);
358 red = toFloat(rgb[0]);
359 green = toFloat(rgb[1]);
360 blue = toFloat(rgb[2]);
361 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
362 return R.hsb2rgb(red, green, blue);
365 rgb = rgb[7][split](commaSpaces);
366 red = toFloat(rgb[0]) * 2.55;
367 green = toFloat(rgb[1]) * 2.55;
368 blue = toFloat(rgb[2]) * 2.55;
369 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
370 return R.hsb2rgb(red, green, blue);
373 rgb = rgb[8][split](commaSpaces);
374 red = toFloat(rgb[0]);
375 green = toFloat(rgb[1]);
376 blue = toFloat(rgb[2]);
377 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
378 return R.hsl2rgb(red, green, blue);
381 rgb = rgb[9][split](commaSpaces);
382 red = toFloat(rgb[0]) * 2.55;
383 green = toFloat(rgb[1]) * 2.55;
384 blue = toFloat(rgb[2]) * 2.55;
385 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
386 return R.hsl2rgb(red, green, blue);
388 rgb = {r: red, g: green, b: blue};
389 var r = (~~red)[toString](16),
390 g = (~~green)[toString](16),
391 b = (~~blue)[toString](16);
395 rgb.hex = "#" + r + g + b;
396 isFinite(toFloat(opacity)) && (rgb.o = opacity);
399 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
401 R.getColor = function (value) {
402 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
403 rgb = this.hsb2rgb(start.h, start.s, start.b);
408 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
412 R.getColor.reset = function () {
416 var pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
417 pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig;
418 R.parsePathString = cacher(function (pathString) {
422 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
424 if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
425 data = pathClone(pathString);
428 Str(pathString)[rp](pathCommand, function (a, b, c) {
430 name = lowerCase.call(b);
431 c[rp](pathValues, function (a, b) {
432 b && params[push](+b);
434 if (name == "m" && params[length] > 2) {
435 data[push]([b][concat](params.splice(0, 2)));
437 b = b == "m" ? "l" : "L";
439 while (params[length] >= paramCounts[name]) {
440 data[push]([b][concat](params.splice(0, paramCounts[name])));
441 if (!paramCounts[name]) {
447 data[toString] = R._path2string;
450 R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
452 x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
453 y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
454 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
455 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
456 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
457 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
458 ax = (1 - t) * p1x + t * c1x,
459 ay = (1 - t) * p1y + t * c1y,
460 cx = (1 - t) * c2x + t * p2x,
461 cy = (1 - t) * c2y + t * p2y,
462 alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
463 (mx > nx || my < ny) && (alpha += 180);
464 return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha};
466 var pathDimensions = cacher(function (path) {
468 return {x: 0, y: 0, width: 0, height: 0};
470 path = path2curve(path);
476 for (var i = 0, ii = path[length]; i < ii; i++) {
484 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
485 X = X[concat](dim.min.x, dim.max.x);
486 Y = Y[concat](dim.min.y, dim.max.y);
491 var xmin = mmin[apply](0, X),
492 ymin = mmin[apply](0, Y);
496 width: mmax[apply](0, X) - xmin,
497 height: mmax[apply](0, Y) - ymin
500 pathClone = function (pathArray) {
502 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
503 pathArray = R.parsePathString(pathArray);
505 for (var i = 0, ii = pathArray[length]; i < ii; i++) {
507 for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
508 res[i][j] = pathArray[i][j];
511 res[toString] = R._path2string;
514 pathToRelative = cacher(function (pathArray) {
515 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
516 pathArray = R.parsePathString(pathArray);
524 if (pathArray[0][0] == "M") {
530 res[push](["M", x, y]);
532 for (var i = start, ii = pathArray[length]; i < ii; i++) {
535 if (pa[0] != lowerCase.call(pa[0])) {
536 r[0] = lowerCase.call(pa[0]);
544 r[6] = +(pa[6] - x).toFixed(3);
545 r[7] = +(pa[7] - y).toFixed(3);
548 r[1] = +(pa[1] - y).toFixed(3);
554 for (var j = 1, jj = pa[length]; j < jj; j++) {
555 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
564 for (var k = 0, kk = pa[length]; k < kk; k++) {
568 var len = res[i][length];
575 x += +res[i][len - 1];
578 y += +res[i][len - 1];
581 x += +res[i][len - 2];
582 y += +res[i][len - 1];
585 res[toString] = R._path2string;
588 pathToAbsolute = cacher(function (pathArray) {
589 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
590 pathArray = R.parsePathString(pathArray);
598 if (pathArray[0][0] == "M") {
599 x = +pathArray[0][1];
600 y = +pathArray[0][2];
604 res[0] = ["M", x, y];
606 for (var i = start, ii = pathArray[length]; i < ii; i++) {
609 if (pa[0] != upperCase.call(pa[0])) {
610 r[0] = upperCase.call(pa[0]);
631 for (var j = 1, jj = pa[length]; j < jj; j++) {
632 r[j] = +pa[j] + ((j % 2) ? x : y);
636 for (var k = 0, kk = pa[length]; k < kk; k++) {
652 mx = res[i][res[i][length] - 2];
653 my = res[i][res[i][length] - 1];
655 x = res[i][res[i][length] - 2];
656 y = res[i][res[i][length] - 1];
659 res[toString] = R._path2string;
662 l2c = function (x1, y1, x2, y2) {
663 return [x1, y1, x2, y2, x2, y2];
665 q2c = function (x1, y1, ax, ay, x2, y2) {
677 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
678 // for more information of where this math came from visit:
679 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
681 _120 = PI * 120 / 180,
682 rad = PI / 180 * (+angle || 0),
685 rotate = cacher(function (x, y, rad) {
686 var X = x * math.cos(rad) - y * math.sin(rad),
687 Y = x * math.sin(rad) + y * math.cos(rad);
691 xy = rotate(x1, y1, -rad);
694 xy = rotate(x2, y2, -rad);
697 var cos = math.cos(PI / 180 * angle),
698 sin = math.sin(PI / 180 * angle),
701 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
709 k = (large_arc_flag == sweep_flag ? -1 : 1) *
710 math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
711 cx = k * rx * y / ry + (x1 + x2) / 2,
712 cy = k * -ry * x / rx + (y1 + y2) / 2,
713 f1 = math.asin(((y1 - cy) / ry).toFixed(7)),
714 f2 = math.asin(((y2 - cy) / ry).toFixed(7));
716 f1 = x1 < cx ? PI - f1 : f1;
717 f2 = x2 < cx ? PI - f2 : f2;
718 f1 < 0 && (f1 = PI * 2 + f1);
719 f2 < 0 && (f2 = PI * 2 + f2);
720 if (sweep_flag && f1 > f2) {
723 if (!sweep_flag && f2 > f1) {
733 if (math.abs(df) > _120) {
737 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
738 x2 = cx + rx * math.cos(f2);
739 y2 = cy + ry * math.sin(f2);
740 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
743 var c1 = math.cos(f1),
747 t = math.tan(df / 4),
751 m2 = [x1 + hx * s1, y1 - hy * c1],
752 m3 = [x2 + hx * s2, y2 - hy * c2],
754 m2[0] = 2 * m1[0] - m2[0];
755 m2[1] = 2 * m1[1] - m2[1];
757 return [m2, m3, m4][concat](res);
759 res = [m2, m3, m4][concat](res)[join]()[split](",");
761 for (var i = 0, ii = res[length]; i < ii; i++) {
762 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
767 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
770 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
771 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
774 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
775 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
776 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
778 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
779 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
783 math.abs(t1) > 1e12 && (t1 = .5);
784 math.abs(t2) > 1e12 && (t2 = .5);
785 if (t1 > 0 && t1 < 1) {
786 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
790 if (t2 > 0 && t2 < 1) {
791 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
795 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
796 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
798 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
799 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
800 math.abs(t1) > 1e12 && (t1 = .5);
801 math.abs(t2) > 1e12 && (t2 = .5);
802 if (t1 > 0 && t1 < 1) {
803 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
807 if (t2 > 0 && t2 < 1) {
808 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
813 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
814 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
817 path2curve = cacher(function (path, path2) {
818 var p = pathToAbsolute(path),
819 p2 = path2 && pathToAbsolute(path2),
820 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
821 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
822 processPath = function (path, d) {
825 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
827 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
834 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
837 nx = d.x + (d.x - (d.bx || d.x));
838 ny = d.y + (d.y - (d.by || d.y));
839 path = ["C", nx, ny][concat](path.slice(1));
842 d.qx = d.x + (d.x - (d.qx || d.x));
843 d.qy = d.y + (d.y - (d.qy || d.y));
844 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
849 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
852 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
855 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
858 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
861 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
866 fixArc = function (pp, i) {
867 if (pp[i][length] > 7) {
871 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
874 ii = mmax(p[length], p2 && p2[length] || 0);
877 fixM = function (path1, path2, a1, a2, i) {
878 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
879 path2.splice(i, 0, ["M", a2.x, a2.y]);
884 ii = mmax(p[length], p2 && p2[length] || 0);
887 for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
888 p[i] = processPath(p[i], attrs);
890 p2 && (p2[i] = processPath(p2[i], attrs2));
892 fixM(p, p2, attrs, attrs2, i);
893 fixM(p2, p, attrs2, attrs, i);
896 seglen = seg[length],
897 seg2len = p2 && seg2[length];
898 attrs.x = seg[seglen - 2];
899 attrs.y = seg[seglen - 1];
900 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
901 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
902 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
903 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
904 attrs2.x = p2 && seg2[seg2len - 2];
905 attrs2.y = p2 && seg2[seg2len - 1];
907 return p2 ? [p, p2] : p;
909 parseDots = cacher(function (gradient) {
911 for (var i = 0, ii = gradient[length]; i < ii; i++) {
913 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
914 dot.color = R.getRGB(par[1]);
915 if (dot.color.error) {
918 dot.color = dot.color.hex;
919 par[2] && (dot.offset = par[2] + "%");
922 for (i = 1, ii = dots[length] - 1; i < ii; i++) {
923 if (!dots[i].offset) {
924 var start = toFloat(dots[i - 1].offset || 0),
926 for (var j = i + 1; j < ii; j++) {
927 if (dots[j].offset) {
928 end = dots[j].offset;
937 var d = (end - start) / (j - i + 1);
940 dots[i].offset = start + "%";
946 getContainer = function (x, y, w, h) {
948 if (R.is(x, string) || R.is(x, "object")) {
949 container = R.is(x, string) ? doc.getElementById(x) : x;
950 if (container.tagName) {
953 container: container,
954 width: container.style.pixelWidth || container.offsetWidth,
955 height: container.style.pixelHeight || container.offsetHeight
958 return {container: container, width: y, height: w};
962 return {container: 1, x: x, y: y, width: w, height: h};
965 plugins = function (con, add) {
967 for (var prop in add) {
968 if (add[has](prop) && !(prop in con)) {
969 switch (typeof add[prop]) {
972 con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
976 con[prop] = con[prop] || {};
977 plugins.call(this, con[prop], add[prop]);
980 con[prop] = add[prop];
986 tear = function (el, paper) {
987 el == paper.top && (paper.top = el.prev);
988 el == paper.bottom && (paper.bottom = el.next);
989 el.next && (el.next.prev = el.prev);
990 el.prev && (el.prev.next = el.next);
992 tofront = function (el, paper) {
993 if (paper.top === el) {
1002 toback = function (el, paper) {
1003 if (paper.bottom === el) {
1007 el.next = paper.bottom;
1009 paper.bottom.prev = el;
1012 insertafter = function (el, el2, paper) {
1014 el2 == paper.top && (paper.top = el);
1015 el2.next && (el2.next.prev = el);
1020 insertbefore = function (el, el2, paper) {
1022 el2 == paper.bottom && (paper.bottom = el);
1023 el2.prev && (el2.prev.next = el);
1028 removed = function (methodname) {
1029 return function () {
1030 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1033 radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
1034 R.pathToRelative = pathToRelative;
1037 Paper[proto].svgns = "http://www.w3.org/2000/svg";
1038 Paper[proto].xlink = "http://www.w3.org/1999/xlink";
1039 round = function (num) {
1040 return +num + (~~num === num) * .5;
1042 var $ = function (el, attr) {
1044 for (var key in attr) {
1045 if (attr[has](key)) {
1046 el[setAttribute](key, Str(attr[key]));
1050 el = doc.createElementNS(Paper[proto].svgns, el);
1051 el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
1055 R[toString] = function () {
1056 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
1058 var thePath = function (pathString, SVG) {
1060 SVG.canvas && SVG.canvas[appendChild](el);
1061 var p = new Element(el, SVG);
1063 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
1066 var addGradientFill = function (o, gradient, SVG) {
1067 var type = "linear",
1070 gradient = Str(gradient)[rp](radial_gradient, function (all, _fx, _fy) {
1075 var dir = ((fy > .5) * 2 - 1);
1076 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
1077 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
1079 (fy = fy.toFixed(5) - 1e-5 * dir);
1083 gradient = gradient[split](/\s*\-\s*/);
1084 if (type == "linear") {
1085 var angle = gradient.shift();
1086 angle = -toFloat(angle);
1090 var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
1091 max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1);
1094 if (vector[2] < 0) {
1095 vector[0] = -vector[2];
1098 if (vector[3] < 0) {
1099 vector[1] = -vector[3];
1103 var dots = parseDots(gradient);
1107 var id = o.getAttribute(fillString);
1108 id = id.match(/^url\(#(.*)\)$/);
1109 id && SVG.defs.removeChild(doc.getElementById(id[1]));
1111 var el = $(type + "Gradient");
1112 el.id = "r" + (R._id++)[toString](36);
1113 $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
1114 SVG.defs[appendChild](el);
1115 for (var i = 0, ii = dots[length]; i < ii; i++) {
1116 var stop = $("stop");
1118 offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
1119 "stop-color": dots[i].color || "#fff"
1121 el[appendChild](stop);
1124 fill: "url(#" + el.id + ")",
1133 var updatePosition = function (o) {
1134 var bbox = o.getBBox();
1135 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
1137 var setFillAndStroke = function (o, params) {
1144 "-..": [3, 1, 1, 1, 1, 1],
1148 "- .": [4, 3, 1, 3],
1149 "--.": [8, 3, 1, 3],
1150 "--..": [8, 3, 1, 3, 1, 3]
1155 addDashes = function (o, value) {
1156 value = dasharray[lowerCase.call(value)];
1158 var width = o.attrs["stroke-width"] || "1",
1159 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1161 var i = value[length];
1163 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
1165 $(node, {"stroke-dasharray": dashes[join](",")});
1168 params[has]("rotation") && (rot = params.rotation);
1169 var rotxy = Str(rot)[split](separator);
1170 if (!(rotxy.length - 1)) {
1173 rotxy[1] = +rotxy[1];
1174 rotxy[2] = +rotxy[2];
1176 toFloat(rot) && o.rotate(0, true);
1177 for (var att in params) {
1178 if (params[has](att)) {
1179 if (!availableAttrs[has](att)) {
1182 var value = params[att];
1189 o.rotate(value, true);
1194 var pn = node.parentNode;
1195 if (lowerCase.call(pn.tagName) != "a") {
1197 pn.insertBefore(hl, node);
1198 hl[appendChild](node);
1201 pn.setAttributeNS(o.paper.xlink, att, value);
1204 node.style.cursor = value;
1207 var rect = Str(value)[split](separator);
1208 if (rect[length] == 4) {
1209 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
1210 var el = $("clipPath"),
1212 el.id = "r" + (R._id++)[toString](36);
1219 el[appendChild](rc);
1220 o.paper.defs[appendChild](el);
1221 $(node, {"clip-path": "url(#" + el.id + ")"});
1225 var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
1226 clip && clip.parentNode.removeChild(clip);
1227 $(node, {"clip-path": E});
1232 if (o.type == "path") {
1233 $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
1237 node[setAttribute](att, value);
1246 value = -attrs.x - (attrs.width || 0);
1249 if (att == "rx" && o.type == "rect") {
1253 rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
1254 node[setAttribute](att, value);
1255 o.pattern && updatePosition(o);
1258 node[setAttribute](att, value);
1267 value = -attrs.y - (attrs.height || 0);
1270 if (att == "ry" && o.type == "rect") {
1274 rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
1275 node[setAttribute](att, value);
1276 o.pattern && updatePosition(o);
1279 if (o.type == "rect") {
1280 $(node, {rx: value, ry: value});
1282 node[setAttribute](att, value);
1286 if (o.type == "image") {
1287 node.setAttributeNS(o.paper.xlink, "href", value);
1290 case "stroke-width":
1291 node.style.strokeWidth = value;
1292 // Need following line for Firefox
1293 node[setAttribute](att, value);
1294 if (attrs["stroke-dasharray"]) {
1295 addDashes(o, attrs["stroke-dasharray"]);
1298 case "stroke-dasharray":
1299 addDashes(o, value);
1302 var xy = Str(value)[split](separator);
1303 xy[0] = +xy[0] || 0;
1304 xy[1] = +xy[1] || 0;
1309 translate.call(o, xy[0], xy[1]);
1312 xy = Str(value)[split](separator);
1313 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
1316 var isURL = Str(value).match(ISURL);
1319 var ig = $("image");
1320 el.id = "r" + (R._id++)[toString](36);
1321 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
1322 $(ig, {x: 0, y: 0});
1323 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1324 el[appendChild](ig);
1326 var img = doc.createElement("img");
1327 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
1328 img.onload = function () {
1329 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1330 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1331 doc.body.removeChild(this);
1334 doc.body[appendChild](img);
1336 o.paper.defs[appendChild](el);
1337 node.style.fill = "url(#" + el.id + ")";
1338 $(node, {fill: "url(#" + el.id + ")"});
1340 o.pattern && updatePosition(o);
1343 var clr = R.getRGB(value);
1345 delete params.gradient;
1346 delete attrs.gradient;
1347 !R.is(attrs.opacity, "undefined") &&
1348 R.is(params.opacity, "undefined") &&
1349 $(node, {opacity: attrs.opacity});
1350 !R.is(attrs["fill-opacity"], "undefined") &&
1351 R.is(params["fill-opacity"], "undefined") &&
1352 $(node, {"fill-opacity": attrs["fill-opacity"]});
1353 } else if ((({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper)) {
1354 attrs.gradient = value;
1355 attrs.fill = "none";
1358 clr[has]("o") && $(node, {"fill-opacity": clr.o / 100});
1360 clr = R.getRGB(value);
1361 node[setAttribute](att, clr.hex);
1362 att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o / 100});
1365 (({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper);
1368 case "fill-opacity":
1369 if (attrs.gradient) {
1370 var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
1372 var stops = gradient.getElementsByTagName("stop");
1373 stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1378 att == "font-size" && (value = toInt(value, 10) + "px");
1379 var cssrule = att[rp](/(\-.)/g, function (w) {
1380 return upperCase.call(w.substring(1));
1382 node.style[cssrule] = value;
1383 // Need following line for Firefox
1384 node[setAttribute](att, value);
1390 tuneText(o, params);
1392 o.rotate(rotxy.join(S));
1394 toFloat(rot) && o.rotate(rot, true);
1398 tuneText = function (el, params) {
1399 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1404 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1406 if (params[has]("text")) {
1407 a.text = params.text;
1408 while (node.firstChild) {
1409 node.removeChild(node.firstChild);
1411 var texts = Str(params.text)[split]("\n");
1412 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1413 var tspan = $("tspan");
1414 i && $(tspan, {dy: fontSize * leading, x: a.x});
1415 tspan[appendChild](doc.createTextNode(texts[i]));
1416 node[appendChild](tspan);
1419 texts = node.getElementsByTagName("tspan");
1420 for (i = 0, ii = texts[length]; i < ii; i++) {
1421 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1425 var bb = el.getBBox(),
1426 dif = a.y - (bb.y + bb.height / 2);
1427 dif && isFinite(dif) && $(node, {y: a.y + dif});
1429 Element = function (node, svg) {
1435 node.raphael = this;
1437 this.attrs = this.attrs || {};
1438 this.transformations = []; // rotate, translate, scale
1442 rt: {deg: 0, cx: 0, cy: 0},
1446 !svg.bottom && (svg.bottom = this);
1447 this.prev = svg.top;
1448 svg.top && (svg.top.next = this);
1452 Element[proto].rotate = function (deg, cx, cy) {
1458 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1460 return this._.rt.deg;
1462 var bbox = this.getBBox();
1463 deg = Str(deg)[split](separator);
1464 if (deg[length] - 1) {
1465 cx = toFloat(deg[1]);
1466 cy = toFloat(deg[2]);
1468 deg = toFloat(deg[0]);
1470 this._.rt.deg = deg;
1472 this._.rt.deg += deg;
1474 (cy == null) && (cx = null);
1477 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1478 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1479 if (this._.rt.deg) {
1480 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1481 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1483 this.transformations[0] = E;
1484 this.clip && $(this.clip, {transform: E});
1486 $(this.node, {transform: this.transformations[join](S)});
1489 Element[proto].hide = function () {
1490 !this.removed && (this.node.style.display = "none");
1493 Element[proto].show = function () {
1494 !this.removed && (this.node.style.display = "");
1497 Element[proto].remove = function () {
1501 tear(this, this.paper);
1502 this.node.parentNode.removeChild(this.node);
1503 for (var i in this) {
1506 this.removed = true;
1508 Element[proto].getBBox = function () {
1512 if (this.type == "path") {
1513 return pathDimensions(this.attrs.path);
1515 if (this.node.style.display == "none") {
1521 bbox = this.node.getBBox();
1523 // Firefox 3.0.x plays badly here
1527 if (this.type == "text") {
1528 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1529 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1530 var bb = this.node.getExtentOfChar(i);
1531 (bb.y < bbox.y) && (bbox.y = bb.y);
1532 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1533 (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1536 hide && this.hide();
1539 Element[proto].attr = function (name, value) {
1545 for (var i in this.attrs) if (this.attrs[has](i)) {
1546 res[i] = this.attrs[i];
1548 this._.rt.deg && (res.rotation = this.rotate());
1549 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1550 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1553 if (value == null && R.is(name, string)) {
1554 if (name == "translation") {
1555 return translate.call(this);
1557 if (name == "rotation") {
1558 return this.rotate();
1560 if (name == "scale") {
1561 return this.scale();
1563 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
1564 return this.attrs.gradient;
1566 return this.attrs[name];
1568 if (value == null && R.is(name, array)) {
1570 for (var j = 0, jj = name.length; j < jj; j++) {
1571 values[name[j]] = this.attr(name[j]);
1575 if (value != null) {
1577 params[name] = value;
1578 setFillAndStroke(this, params);
1579 } else if (name != null && R.is(name, "object")) {
1580 setFillAndStroke(this, name);
1584 Element[proto].toFront = function () {
1588 this.node.parentNode[appendChild](this.node);
1589 var svg = this.paper;
1590 svg.top != this && tofront(this, svg);
1593 Element[proto].toBack = function () {
1597 if (this.node.parentNode.firstChild != this.node) {
1598 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1599 toback(this, this.paper);
1600 var svg = this.paper;
1604 Element[proto].insertAfter = function (element) {
1608 var node = element.node || element[element.length].node;
1609 if (node.nextSibling) {
1610 node.parentNode.insertBefore(this.node, node.nextSibling);
1612 node.parentNode[appendChild](this.node);
1614 insertafter(this, element, this.paper);
1617 Element[proto].insertBefore = function (element) {
1621 var node = element.node || element[0].node;
1622 node.parentNode.insertBefore(this.node, node);
1623 insertbefore(this, element, this.paper);
1626 Element[proto].blur = function (size) {
1627 // Experimental. No Safari support. Use it on your own risk.
1630 var fltr = $("filter"),
1631 blur = $("feGaussianBlur");
1632 t.attrs.blur = size;
1633 fltr.id = "r" + (R._id++)[toString](36);
1634 $(blur, {stdDeviation: +size || 1.5});
1635 fltr.appendChild(blur);
1636 t.paper.defs.appendChild(fltr);
1638 $(t.node, {filter: "url(#" + fltr.id + ")"});
1641 t._blur.parentNode.removeChild(t._blur);
1643 delete t.attrs.blur;
1645 t.node.removeAttribute("filter");
1648 var theCircle = function (svg, x, y, r) {
1649 var el = $("circle");
1650 svg.canvas && svg.canvas[appendChild](el);
1651 var res = new Element(el, svg);
1652 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1653 res.type = "circle";
1657 var theRect = function (svg, x, y, w, h, r) {
1659 svg.canvas && svg.canvas[appendChild](el);
1660 var res = new Element(el, svg);
1661 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1666 var theEllipse = function (svg, x, y, rx, ry) {
1667 var el = $("ellipse");
1668 svg.canvas && svg.canvas[appendChild](el);
1669 var res = new Element(el, svg);
1670 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1671 res.type = "ellipse";
1675 var theImage = function (svg, src, x, y, w, h) {
1676 var el = $("image");
1677 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1678 el.setAttributeNS(svg.xlink, "href", src);
1679 svg.canvas && svg.canvas[appendChild](el);
1680 var res = new Element(el, svg);
1681 res.attrs = {x: x, y: y, width: w, height: h, src: src};
1685 var theText = function (svg, x, y, text) {
1687 $(el, {x: x, y: y, "text-anchor": "middle"});
1688 svg.canvas && svg.canvas[appendChild](el);
1689 var res = new Element(el, svg);
1690 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1692 setFillAndStroke(res, res.attrs);
1695 var setSize = function (width, height) {
1696 this.width = width || this.width;
1697 this.height = height || this.height;
1698 this.canvas[setAttribute]("width", this.width);
1699 this.canvas[setAttribute]("height", this.height);
1702 var create = function () {
1703 var con = getContainer[apply](0, arguments),
1704 container = con && con.container,
1708 height = con.height;
1710 throw new Error("SVG container not found.");
1712 var cnvs = $("svg");
1715 width = width || 512;
1716 height = height || 342;
1718 xmlns: "http://www.w3.org/2000/svg",
1723 if (container == 1) {
1724 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1725 doc.body[appendChild](cnvs);
1727 if (container.firstChild) {
1728 container.insertBefore(cnvs, container.firstChild);
1730 container[appendChild](cnvs);
1733 container = new Paper;
1734 container.width = width;
1735 container.height = height;
1736 container.canvas = cnvs;
1737 plugins.call(container, container, R.fn);
1741 Paper[proto].clear = function () {
1742 var c = this.canvas;
1743 while (c.firstChild) {
1744 c.removeChild(c.firstChild);
1746 this.bottom = this.top = null;
1747 (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1748 c[appendChild](this.desc);
1749 c[appendChild](this.defs = $("defs"));
1751 Paper[proto].remove = function () {
1752 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1753 for (var i in this) {
1754 this[i] = removed(i);
1761 var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1762 bites = /([clmz]),?([^clmz]*)/gi,
1763 val = /-?[^,\s-]+/g,
1764 coordsize = 1e3 + S + 1e3,
1766 pathlike = {path: 1, rect: 1},
1767 path2vml = function (path) {
1768 var total = /[ahqstv]/ig,
1769 command = pathToAbsolute;
1770 Str(path).match(total) && (command = path2curve);
1772 if (command == pathToAbsolute && !Str(path).match(total)) {
1773 var res = Str(path)[rp](bites, function (all, command, args) {
1775 isMove = lowerCase.call(command) == "m",
1777 args[rp](val, function (value) {
1778 if (isMove && vals[length] == 2) {
1779 res += vals + map[command == "m" ? "l" : "L"];
1782 vals[push](round(value * zoom));
1788 var pa = command(path), p, r;
1790 for (var i = 0, ii = pa[length]; i < ii; i++) {
1792 r = lowerCase.call(pa[i][0]);
1793 r == "z" && (r = "x");
1794 for (var j = 1, jj = p[length]; j < jj; j++) {
1795 r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
1799 return res[join](S);
1802 R[toString] = function () {
1803 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1805 thePath = function (pathString, vml) {
1806 var g = createNode("group");
1807 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
1808 g.coordsize = vml.coordsize;
1809 g.coordorigin = vml.coordorigin;
1810 var el = createNode("shape"), ol = el.style;
1811 ol.width = vml.width + "px";
1812 ol.height = vml.height + "px";
1813 el.coordsize = coordsize;
1814 el.coordorigin = vml.coordorigin;
1816 var p = new Element(el, g, vml),
1817 attr = {fill: "none", stroke: "#000"};
1818 pathString && (attr.path = pathString);
1819 p.isAbsolute = true;
1823 setFillAndStroke(p, attr);
1824 vml.canvas[appendChild](g);
1827 setFillAndStroke = function (o, params) {
1828 o.attrs = o.attrs || {};
1833 newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
1836 for (var par in params) if (params[has](par)) {
1837 a[par] = params[par];
1840 a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
1846 params.href && (node.href = params.href);
1847 params.title && (node.title = params.title);
1848 params.target && (node.target = params.target);
1849 params.cursor && (s.cursor = params.cursor);
1850 "blur" in params && o.blur(params.blur);
1851 if (params.path && o.type == "path" || newpath) {
1852 node.path = path2vml(a.path);
1854 if (params.rotation != null) {
1855 o.rotate(params.rotation, true);
1857 if (params.translation) {
1858 xy = Str(params.translation)[split](separator);
1859 translate.call(o, xy[0], xy[1]);
1860 if (o._.rt.cx != null) {
1861 o._.rt.cx +=+ xy[0];
1862 o._.rt.cy +=+ xy[1];
1863 o.setBox(o.attrs, xy[0], xy[1]);
1867 xy = Str(params.scale)[split](separator);
1868 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1870 if ("clip-rect" in params) {
1871 var rect = Str(params["clip-rect"])[split](separator);
1872 if (rect[length] == 4) {
1873 rect[2] = +rect[2] + (+rect[0]);
1874 rect[3] = +rect[3] + (+rect[1]);
1875 var div = node.clipRect || doc.createElement("div"),
1877 group = node.parentNode;
1878 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1879 if (!node.clipRect) {
1880 dstyle.position = "absolute";
1883 dstyle.width = o.paper.width + "px";
1884 dstyle.height = o.paper.height + "px";
1885 group.parentNode.insertBefore(div, group);
1886 div[appendChild](group);
1887 node.clipRect = div;
1890 if (!params["clip-rect"]) {
1891 node.clipRect && (node.clipRect.style.clip = E);
1894 if (o.type == "image" && params.src) {
1895 node.src = params.src;
1897 if (o.type == "image" && params.opacity) {
1898 node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
1899 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1901 params.font && (s.font = params.font);
1902 params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1903 params["font-size"] && (s.fontSize = params["font-size"]);
1904 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1905 params["font-style"] && (s.fontStyle = params["font-style"]);
1906 if (params.opacity != null ||
1907 params["stroke-width"] != null ||
1908 params.fill != null ||
1909 params.stroke != null ||
1910 params["stroke-width"] != null ||
1911 params["stroke-opacity"] != null ||
1912 params["fill-opacity"] != null ||
1913 params["stroke-dasharray"] != null ||
1914 params["stroke-miterlimit"] != null ||
1915 params["stroke-linejoin"] != null ||
1916 params["stroke-linecap"] != null) {
1917 node = o.shape || node;
1918 var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
1920 !fill && (newfill = fill = createNode(fillString));
1921 if ("fill-opacity" in params || "opacity" in params) {
1922 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
1923 opacity < 0 && (opacity = 0);
1924 opacity > 1 && (opacity = 1);
1925 fill.opacity = opacity;
1927 params.fill && (fill.on = true);
1928 if (fill.on == null || params.fill == "none") {
1931 if (fill.on && params.fill) {
1932 var isURL = params.fill.match(ISURL);
1934 fill.src = isURL[1];
1937 fill.color = R.getRGB(params.fill).hex;
1939 fill.type = "solid";
1940 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
1942 a.gradient = params.fill;
1946 newfill && node[appendChild](fill);
1947 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
1949 !stroke && (newstroke = stroke = createNode("stroke"));
1950 if ((params.stroke && params.stroke != "none") ||
1951 params["stroke-width"] ||
1952 params["stroke-opacity"] != null ||
1953 params["stroke-dasharray"] ||
1954 params["stroke-miterlimit"] ||
1955 params["stroke-linejoin"] ||
1956 params["stroke-linecap"]) {
1959 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
1960 var strokeColor = R.getRGB(params.stroke);
1961 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
1962 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
1963 var width = (toFloat(params["stroke-width"]) || 1) * .75;
1964 opacity < 0 && (opacity = 0);
1965 opacity > 1 && (opacity = 1);
1966 params["stroke-width"] == null && (width = a["stroke-width"]);
1967 params["stroke-width"] && (stroke.weight = width);
1968 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
1969 stroke.opacity = opacity;
1971 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
1972 stroke.miterlimit = params["stroke-miterlimit"] || 8;
1973 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
1974 if (params["stroke-dasharray"]) {
1978 "-.": "shortdashdot",
1979 "-..": "shortdashdotdot",
1984 "--.": "longdashdot",
1985 "--..": "longdashdotdot"
1987 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
1989 newstroke && node[appendChild](stroke);
1991 if (res.type == "text") {
1992 s = res.paper.span.style;
1993 a.font && (s.font = a.font);
1994 a["font-family"] && (s.fontFamily = a["font-family"]);
1995 a["font-size"] && (s.fontSize = a["font-size"]);
1996 a["font-weight"] && (s.fontWeight = a["font-weight"]);
1997 a["font-style"] && (s.fontStyle = a["font-style"]);
1998 res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "<")[rp](/&/g, "&")[rp](/\n/g, "<br>"));
1999 res.W = a.w = res.paper.span.offsetWidth;
2000 res.H = a.h = res.paper.span.offsetHeight;
2002 res.Y = a.y + round(res.H / 2);
2004 // text-anchor emulationm
2005 switch (a["text-anchor"]) {
2007 res.node.style["v-text-align"] = "left";
2008 res.bbx = round(res.W / 2);
2011 res.node.style["v-text-align"] = "right";
2012 res.bbx = -round(res.W / 2);
2015 res.node.style["v-text-align"] = "center";
2020 addGradientFill = function (o, gradient) {
2021 o.attrs = o.attrs || {};
2022 var attrs = o.attrs,
2026 o.attrs.gradient = gradient;
2027 gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
2032 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
2037 gradient = gradient[split](/\s*\-\s*/);
2038 if (type == "linear") {
2039 var angle = gradient.shift();
2040 angle = -toFloat(angle);
2045 var dots = parseDots(gradient);
2049 o = o.shape || o.node;
2050 fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
2051 !fill.parentNode && o.appendChild(fill);
2054 fill.method = "none";
2055 fill.color = dots[0].color;
2056 fill.color2 = dots[dots[length] - 1].color;
2058 for (var i = 0, ii = dots[length]; i < ii; i++) {
2059 dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
2061 fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
2062 if (type == "radial") {
2063 fill.type = "gradientradial";
2064 fill.focus = "100%";
2065 fill.focussize = fxfy;
2066 fill.focusposition = fxfy;
2068 fill.type = "gradient";
2069 fill.angle = (270 - angle) % 360;
2074 Element = function (node, group, vml) {
2082 node.raphael = this;
2095 !vml.bottom && (vml.bottom = this);
2096 this.prev = vml.top;
2097 vml.top && (vml.top.next = this);
2101 Element[proto].rotate = function (deg, cx, cy) {
2107 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
2109 return this._.rt.deg;
2111 deg = Str(deg)[split](separator);
2112 if (deg[length] - 1) {
2113 cx = toFloat(deg[1]);
2114 cy = toFloat(deg[2]);
2116 deg = toFloat(deg[0]);
2118 this._.rt.deg = deg;
2120 this._.rt.deg += deg;
2122 cy == null && (cx = null);
2125 this.setBox(this.attrs, cx, cy);
2126 this.Group.style.rotation = this._.rt.deg;
2127 // gradient fix for rotation. TODO
2128 // var fill = (this.shape || this.node).getElementsByTagName(fillString);
2129 // fill = fill[0] || {};
2130 // var b = ((360 - this._.rt.deg) - 270) % 360;
2131 // !R.is(fill.angle, "undefined") && (fill.angle = b);
2134 Element[proto].setBox = function (params, cx, cy) {
2138 var gs = this.Group.style,
2139 os = (this.shape && this.shape.style) || this.node.style;
2140 params = params || {};
2141 for (var i in params) if (params[has](i)) {
2142 this.attrs[i] = params[i];
2144 cx = cx || this._.rt.cx;
2145 cy = cy || this._.rt.cy;
2146 var attr = this.attrs,
2151 switch (this.type) {
2153 x = attr.cx - attr.r;
2154 y = attr.cy - attr.r;
2158 x = attr.cx - attr.rx;
2159 y = attr.cy - attr.ry;
2166 w = attr.width || 0;
2167 h = attr.height || 0;
2170 this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
2171 x = attr.x - round(this.W / 2);
2172 y = attr.y - this.H / 2;
2178 if (!this.attrs.path) {
2181 w = this.paper.width;
2182 h = this.paper.height;
2184 var dim = pathDimensions(this.attrs.path);
2194 w = this.paper.width;
2195 h = this.paper.height;
2198 cx = (cx == null) ? x + w / 2 : cx;
2199 cy = (cy == null) ? y + h / 2 : cy;
2200 var left = cx - this.paper.width / 2,
2201 top = cy - this.paper.height / 2, t;
2202 gs.left != (t = left + "px") && (gs.left = t);
2203 gs.top != (t = top + "px") && (gs.top = t);
2204 this.X = pathlike[has](this.type) ? -left : x;
2205 this.Y = pathlike[has](this.type) ? -top : y;
2208 if (pathlike[has](this.type)) {
2209 os.left != (t = -left * zoom + "px") && (os.left = t);
2210 os.top != (t = -top * zoom + "px") && (os.top = t);
2211 } else if (this.type == "text") {
2212 os.left != (t = -left + "px") && (os.left = t);
2213 os.top != (t = -top + "px") && (os.top = t);
2215 gs.width != (t = this.paper.width + "px") && (gs.width = t);
2216 gs.height != (t = this.paper.height + "px") && (gs.height = t);
2217 os.left != (t = x - left + "px") && (os.left = t);
2218 os.top != (t = y - top + "px") && (os.top = t);
2219 os.width != (t = w + "px") && (os.width = t);
2220 os.height != (t = h + "px") && (os.height = t);
2223 Element[proto].hide = function () {
2224 !this.removed && (this.Group.style.display = "none");
2227 Element[proto].show = function () {
2228 !this.removed && (this.Group.style.display = "block");
2231 Element[proto].getBBox = function () {
2235 if (pathlike[has](this.type)) {
2236 return pathDimensions(this.attrs.path);
2239 x: this.X + (this.bbx || 0),
2245 Element[proto].remove = function () {
2249 tear(this, this.paper);
2250 this.node.parentNode.removeChild(this.node);
2251 this.Group.parentNode.removeChild(this.Group);
2252 this.shape && this.shape.parentNode.removeChild(this.shape);
2253 for (var i in this) {
2256 this.removed = true;
2258 Element[proto].attr = function (name, value) {
2264 for (var i in this.attrs) if (this.attrs[has](i)) {
2265 res[i] = this.attrs[i];
2267 this._.rt.deg && (res.rotation = this.rotate());
2268 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2269 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2272 if (value == null && R.is(name, string)) {
2273 if (name == "translation") {
2274 return translate.call(this);
2276 if (name == "rotation") {
2277 return this.rotate();
2279 if (name == "scale") {
2280 return this.scale();
2282 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
2283 return this.attrs.gradient;
2285 return this.attrs[name];
2287 if (this.attrs && value == null && R.is(name, array)) {
2288 var ii, values = {};
2289 for (i = 0, ii = name[length]; i < ii; i++) {
2290 values[name[i]] = this.attr(name[i]);
2295 if (value != null) {
2297 params[name] = value;
2299 value == null && R.is(name, "object") && (params = name);
2301 if (params.text && this.type == "text") {
2302 this.node.string = params.text;
2304 setFillAndStroke(this, params);
2305 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
2306 addGradientFill(this, params.gradient);
2308 (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
2312 Element[proto].toFront = function () {
2313 !this.removed && this.Group.parentNode[appendChild](this.Group);
2314 this.paper.top != this && tofront(this, this.paper);
2317 Element[proto].toBack = function () {
2321 if (this.Group.parentNode.firstChild != this.Group) {
2322 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2323 toback(this, this.paper);
2327 Element[proto].insertAfter = function (element) {
2331 if (element.constructor == Set) {
2332 element = element[element.length];
2334 if (element.Group.nextSibling) {
2335 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2337 element.Group.parentNode[appendChild](this.Group);
2339 insertafter(this, element, this.paper);
2342 Element[proto].insertBefore = function (element) {
2346 if (element.constructor == Set) {
2347 element = element[0];
2349 element.Group.parentNode.insertBefore(this.Group, element.Group);
2350 insertbefore(this, element, this.paper);
2353 var blurregexp = / progid:\S+Blur\([^\)]+\)/g;
2354 Element[proto].blur = function (size) {
2355 var s = this.node.runtimeStyle,
2357 f = f.replace(blurregexp, E);
2359 this.attrs.blur = size;
2360 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
2361 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
2365 delete this.attrs.blur;
2369 theCircle = function (vml, x, y, r) {
2370 var g = createNode("group"),
2371 o = createNode("oval"),
2373 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2374 g.coordsize = coordsize;
2375 g.coordorigin = vml.coordorigin;
2377 var res = new Element(o, g, vml);
2378 res.type = "circle";
2379 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2383 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2384 vml.canvas[appendChild](g);
2387 function rectPath(x, y, w, h, r) {
2389 return R.format("M{0},{1}l{2},0a{3},{3},0,0,1,{3},{3}l0,{5}a{3},{3},0,0,1,{4},{3}l{6},0a{3},{3},0,0,1,{4},{4}l0,{7}a{3},{3},0,0,1,{3},{4}z", x + r, y, w - r * 2, r, -r, h - r * 2, r * 2 - w, r * 2 - h);
2391 return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
2394 theRect = function (vml, x, y, w, h, r) {
2395 var path = rectPath(x, y, w, h, r),
2396 res = vml.path(path),
2400 res.W = a.width = w;
2401 res.H = a.height = h;
2407 theEllipse = function (vml, x, y, rx, ry) {
2408 var g = createNode("group"),
2409 o = createNode("oval"),
2411 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2412 g.coordsize = coordsize;
2413 g.coordorigin = vml.coordorigin;
2415 var res = new Element(o, g, vml);
2416 res.type = "ellipse";
2417 setFillAndStroke(res, {stroke: "#000"});
2422 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2423 vml.canvas[appendChild](g);
2426 theImage = function (vml, src, x, y, w, h) {
2427 var g = createNode("group"),
2428 o = createNode("image"),
2430 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2431 g.coordsize = coordsize;
2432 g.coordorigin = vml.coordorigin;
2435 var res = new Element(o, g, vml);
2437 res.attrs.src = src;
2442 res.setBox({x: x, y: y, width: w, height: h});
2443 vml.canvas[appendChild](g);
2446 theText = function (vml, x, y, text) {
2447 var g = createNode("group"),
2448 el = createNode("shape"),
2450 path = createNode("path"),
2452 o = createNode("textpath");
2453 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2454 g.coordsize = coordsize;
2455 g.coordorigin = vml.coordorigin;
2456 path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
2457 path.textpathok = true;
2458 ol.width = vml.width;
2459 ol.height = vml.height;
2460 o.string = Str(text);
2463 el[appendChild](path);
2465 var res = new Element(o, g, vml);
2467 res.textpath = path;
2469 res.attrs.text = text;
2474 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2476 vml.canvas[appendChild](g);
2479 setSize = function (width, height) {
2480 var cs = this.canvas.style;
2481 width == +width && (width += "px");
2482 height == +height && (height += "px");
2485 cs.clip = "rect(0 " + width + " " + height + " 0)";
2489 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2491 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2492 createNode = function (tagName) {
2493 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2496 createNode = function (tagName) {
2497 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2500 create = function () {
2501 var con = getContainer[apply](0, arguments),
2502 container = con.container,
2503 height = con.height,
2509 throw new Error("VML container not found.");
2511 var res = new Paper,
2512 c = res.canvas = doc.createElement("div"),
2516 width = width || 512;
2517 height = height || 342;
2518 width == +width && (width += "px");
2519 height == +height && (height += "px");
2522 res.coordsize = zoom * 1e3 + S + zoom * 1e3;
2523 res.coordorigin = "0 0";
2524 res.span = doc.createElement("span");
2525 res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2526 c[appendChild](res.span);
2527 cs.cssText = R.format("width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
2528 if (container == 1) {
2529 doc.body[appendChild](c);
2532 cs.position = "absolute";
2534 if (container.firstChild) {
2535 container.insertBefore(c, container.firstChild);
2537 container[appendChild](c);
2540 plugins.call(res, res, R.fn);
2543 Paper[proto].clear = function () {
2544 this.canvas.innerHTML = E;
2545 this.span = doc.createElement("span");
2546 this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2547 this.canvas[appendChild](this.span);
2548 this.bottom = this.top = null;
2550 Paper[proto].remove = function () {
2551 this.canvas.parentNode.removeChild(this.canvas);
2552 for (var i in this) {
2553 this[i] = removed(i);
2560 // WebKit rendering bug workaround method
2561 if ((navigator.vendor == "Apple Computer, Inc.") && (navigator.userAgent.match(/Version\/(.*?)\s/)[1] < 4 || win.navigator.platform.slice(0, 2) == "iP")) {
2562 Paper[proto].safari = function () {
2563 var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2564 win.setTimeout(function () {rect.remove();});
2567 Paper[proto].safari = function () {};
2571 var preventDefault = function () {
2572 this.returnValue = false;
2574 preventTouch = function () {
2575 return this.originalEvent.preventDefault();
2577 stopPropagation = function () {
2578 this.cancelBubble = true;
2580 stopTouch = function () {
2581 return this.originalEvent.stopPropagation();
2583 addEvent = (function () {
2584 if (doc.addEventListener) {
2585 return function (obj, type, fn, element) {
2586 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
2587 var f = function (e) {
2588 if (supportsTouch && touchMap[has](type)) {
2589 for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2590 if (e.targetTouches[i].target == obj) {
2592 e = e.targetTouches[i];
2593 e.originalEvent = olde;
2594 e.preventDefault = preventTouch;
2595 e.stopPropagation = stopTouch;
2600 return fn.call(element, e);
2602 obj.addEventListener(realName, f, false);
2603 return function () {
2604 obj.removeEventListener(realName, f, false);
2608 } else if (doc.attachEvent) {
2609 return function (obj, type, fn, element) {
2610 var f = function (e) {
2612 e.preventDefault = e.preventDefault || preventDefault;
2613 e.stopPropagation = e.stopPropagation || stopPropagation;
2614 return fn.call(element, e);
2616 obj.attachEvent("on" + type, f);
2617 var detacher = function () {
2618 obj.detachEvent("on" + type, f);
2626 dragMove = function (e) {
2633 if (supportsTouch) {
2634 var i = e.touches.length,
2637 touch = e.touches[i];
2638 if (touch.identifier == dragi.el._drag.id) {
2641 (e.originalEvent ? e.originalEvent : e).preventDefault();
2648 dragi.move && dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
2651 dragUp = function () {
2652 R.unmousemove(dragMove).unmouseup(dragUp);
2653 var i = drag.length,
2657 dragi.el._drag = {};
2658 dragi.end && dragi.end.call(dragi.el);
2662 for (var i = events[length]; i--;) {
2663 (function (eventName) {
2664 R[eventName] = Element[proto][eventName] = function (fn) {
2665 if (R.is(fn, "function")) {
2666 this.events = this.events || [];
2667 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
2671 R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
2672 var events = this.events,
2674 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2676 events.splice(l, 1);
2677 !events.length && delete this.events;
2684 Element[proto].hover = function (f_in, f_out) {
2685 return this.mouseover(f_in).mouseout(f_out);
2687 Element[proto].unhover = function (f_in, f_out) {
2688 return this.unmouseover(f_in).unmouseout(f_out);
2690 Element[proto].drag = function (onmove, onstart, onend) {
2692 this.mousedown(function (e) {
2693 (e.originalEvent || e).preventDefault();
2694 this._drag.x = e.clientX;
2695 this._drag.y = e.clientY;
2696 this._drag.id = e.identifier;
2697 onstart && onstart.call(this, e.clientX, e.clientY);
2698 !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2699 drag.push({el: this, move: onmove, end: onend});
2703 Element[proto].undrag = function (onmove, onstart, onend) {
2704 var i = drag.length;
2706 drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i, 1);
2707 !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2710 Paper[proto].circle = function (x, y, r) {
2711 return theCircle(this, x || 0, y || 0, r || 0);
2713 Paper[proto].rect = function (x, y, w, h, r) {
2714 return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2716 Paper[proto].ellipse = function (x, y, rx, ry) {
2717 return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2719 Paper[proto].path = function (pathString) {
2720 pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2721 return thePath(R.format[apply](R, arguments), this);
2723 Paper[proto].image = function (src, x, y, w, h) {
2724 return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2726 Paper[proto].text = function (x, y, text) {
2727 return theText(this, x || 0, y || 0, text || E);
2729 Paper[proto].set = function (itemsArray) {
2730 arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2731 return new Set(itemsArray);
2733 Paper[proto].setSize = setSize;
2734 Paper[proto].top = Paper[proto].bottom = null;
2735 Paper[proto].raphael = R;
2737 return this.x + S + this.y;
2739 Element[proto].resetScale = function () {
2745 this.attrs.scale = "1 1";
2747 Element[proto].scale = function (x, y, cx, cy) {
2751 if (x == null && y == null) {
2766 var bb = this.getBBox(),
2767 rcx = bb.x + bb.width / 2,
2768 rcy = bb.y + bb.height / 2,
2771 cx = (+cx || cx == 0) ? cx : rcx;
2772 cy = (+cy || cy == 0) ? cy : rcy;
2773 var dirx = ~~(x / math.abs(x)),
2774 diry = ~~(y / math.abs(y)),
2775 s = this.node.style,
2776 ncx = cx + (rcx - cx) * kx,
2777 ncy = cy + (rcy - cy) * ky;
2778 switch (this.type) {
2781 var neww = a.width * dirx * kx,
2782 newh = a.height * diry * ky;
2785 r: a.r * mmin(dirx * kx, diry * ky),
2794 rx: a.rx * dirx * kx,
2795 ry: a.ry * diry * ky,
2796 r: a.r * mmin(dirx * kx, diry * ky),
2808 var path = pathToRelative(a.path),
2810 for (var i = 0, ii = path[length]; i < ii; i++) {
2812 P0 = upperCase.call(p[0]);
2813 if (P0 == "M" && skip) {
2819 p[path[i][length] - 2] *= kx;
2820 p[path[i][length] - 1] *= ky;
2823 p[5] = +!(dirx + diry ? !+p[5] : +p[5]);
2824 } else if (P0 == "H") {
2825 for (var j = 1, jj = p[length]; j < jj; j++) {
2828 } else if (P0 == "V") {
2829 for (j = 1, jj = p[length]; j < jj; j++) {
2833 for (j = 1, jj = p[length]; j < jj; j++) {
2834 p[j] *= (j % 2) ? kx : ky;
2838 var dim2 = pathDimensions(path);
2839 dx = ncx - dim2.x - dim2.width / 2;
2840 dy = ncy - dim2.y - dim2.height / 2;
2843 this.attr({path: path});
2846 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2847 if (this.transformations) {
2848 this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2849 this.node[setAttribute]("transform", this.transformations[join](S));
2850 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2851 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2852 this.attr({x: dx, y: dy});
2856 this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
2857 ", M12=0, M21=0, M22=", diry,
2858 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2859 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2862 if (this.transformations) {
2863 this.transformations[2] = E;
2864 this.node[setAttribute]("transform", this.transformations[join](S));
2868 this.node.filterMatrix = E;
2869 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2872 a.scale = [x, y, cx, cy][join](S);
2878 Element[proto].clone = function () {
2882 var attr = this.attr();
2884 delete attr.translation;
2885 return this.paper[this.type]().attr(attr);
2887 var getPointAtSegmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2890 for (var i = 0; i < 1.01; i+=.01) {
2891 var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
2892 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2893 if (len >= length) {
2899 getLengthFactory = function (istotal, subpath) {
2900 return function (path, length, onlystart) {
2901 path = path2curve(path);
2902 var x, y, p, l, sp = "", subpaths = {}, point,
2904 for (var i = 0, ii = path.length; i < ii; i++) {
2910 l = segmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
2911 if (len + l > length) {
2912 if (subpath && !subpaths.start) {
2913 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2914 sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
2915 if (onlystart) {return sp;}
2916 subpaths.start = sp;
2917 sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
2923 if (!istotal && !subpath) {
2924 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2925 return {x: point.x, y: point.y, alpha: point.alpha};
2935 point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
2936 point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
2940 segmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
2941 var old = {x: 0, y: 0},
2943 for (var i = 0; i < 1.01; i+=.01) {
2944 var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
2945 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2950 var getTotalLength = getLengthFactory(1),
2951 getPointAtLength = getLengthFactory(),
2952 getSubpathsAtLength = getLengthFactory(0, 1);
2953 Element[proto].getTotalLength = function () {
2954 if (this.type != "path") {return;}
2955 if (this.node.getTotalLength) {
2956 return this.node.getTotalLength();
2958 return getTotalLength(this.attrs.path);
2960 Element[proto].getPointAtLength = function (length) {
2961 if (this.type != "path") {return;}
2962 if (this.node.getPointAtLength) {
2963 return this.node.getPointAtLength(length);
2965 return getPointAtLength(this.attrs.path, length);
2967 Element[proto].getSubpath = function (from, to) {
2968 if (this.type != "path") {return;}
2969 if (math.abs(this.getTotalLength() - to) < 1e-6) {
2970 return getSubpathsAtLength(this.attrs.path, from).end;
2972 var a = getSubpathsAtLength(this.attrs.path, to, 1);
2973 return from ? getSubpathsAtLength(a, from).end : a;
2976 // animation easing formulas
2977 R.easing_formulas = {
2978 linear: function (n) {
2985 return pow(n - 1, 3) + 1;
2987 "<>": function (n) {
2990 return pow(n, 3) / 2;
2993 return (pow(n, 3) + 2) / 2;
2995 backIn: function (n) {
2997 return n * n * ((s + 1) * n - s);
2999 backOut: function (n) {
3002 return n * n * ((s + 1) * n + s) + 1;
3004 elastic: function (n) {
3005 if (n == 0 || n == 1) {
3010 return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
3012 bounce: function (n) {
3021 l = s * n * n + .75;
3023 if (n < (2.5 / p)) {
3025 l = s * n * n + .9375;
3028 l = s * n * n + .984375;
3036 var animationElements = {length : 0},
3037 animation = function () {
3038 var Now = +new Date;
3039 for (var l in animationElements) if (l != "length" && animationElements[has](l)) {
3040 var e = animationElements[l];
3041 if (e.stop || e.el.removed) {
3042 delete animationElements[l];
3043 animationElements[length]--;
3046 var time = Now - e.start,
3055 callback = e.callback,
3059 var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
3060 for (var attr in from) if (from[has](attr)) {
3061 switch (availableAnimAttrs[attr]) {
3063 now = pos * ms * diff[attr];
3064 to.back && (now = to.len - now);
3065 var point = getPointAtLength(to[attr], now);
3066 that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
3069 that.translate(point.x - diff.sx, point.y - diff.sy);
3070 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3073 now = +from[attr] + pos * ms * diff[attr];
3077 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3078 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3079 upto255(round(from[attr].b + pos * ms * diff[attr].b))
3084 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3085 now[i] = [from[attr][i][0]];
3086 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3087 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3089 now[i] = now[i][join](S);
3096 var x = diff[attr][0] * (time - prev),
3097 y = diff[attr][1] * (time - prev);
3103 now = +from[attr][0] + pos * ms * diff[attr][0];
3104 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
3107 now = [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in to[attr] ? to[attr][2] : E), (3 in to[attr] ? to[attr][3] : E)][join](S);
3113 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3122 that._run && that._run.call(that);
3125 point = getPointAtLength(to.along, to.len * !to.back);
3126 that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
3127 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3129 (t.x || t.y) && that.translate(-t.x, -t.y);
3130 to.scale && (to.scale += E);
3132 delete animationElements[l];
3133 animationElements[length]--;
3134 that.in_animation = null;
3135 R.is(callback, "function") && callback.call(that);
3139 R.svg && that && that.paper && that.paper.safari();
3140 animationElements[length] && win.setTimeout(animation);
3142 upto255 = function (color) {
3143 return mmax(mmin(color, 255), 0);
3145 translate = function (x, y) {
3147 return {x: this._.tx, y: this._.ty, toString: x_y};
3151 switch (this.type) {
3154 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
3159 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
3162 var path = pathToRelative(this.attrs.path);
3165 this.attr({path: path});
3170 Element[proto].animateWith = function (element, params, ms, easing, callback) {
3171 animationElements[element.id] && (params.start = animationElements[element.id].start);
3172 return this.animate(params, ms, easing, callback);
3174 Element[proto].animateAlong = along();
3175 Element[proto].animateAlongBack = along(1);
3176 function along(isBack) {
3177 return function (path, ms, rotate, callback) {
3178 var params = {back: isBack};
3179 R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
3180 path && path.constructor == Element && (path = path.attrs.path);
3181 path && (params.along = path);
3182 return this.animate(params, ms, callback);
3185 Element[proto].onAnimation = function (f) {
3189 Element[proto].animate = function (params, ms, easing, callback) {
3190 if (R.is(easing, "function") || !easing) {
3191 callback = easing || null;
3196 for (var attr in params) if (params[has](attr)) {
3197 if (availableAnimAttrs[has](attr)) {
3198 from[attr] = this.attr(attr);
3199 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3200 to[attr] = params[attr];
3201 switch (availableAnimAttrs[attr]) {
3203 var len = getTotalLength(params[attr]);
3204 var point = getPointAtLength(params[attr], len * !!params.back);
3205 var bb = this.getBBox();
3206 diff[attr] = len / ms;
3211 to.rot = params.rot;
3212 to.back = params.back;
3214 params.rot && (diff.r = toFloat(this.rotate()) || 0);
3217 diff[attr] = (to[attr] - from[attr]) / ms;
3220 from[attr] = R.getRGB(from[attr]);
3221 var toColour = R.getRGB(to[attr]);
3223 r: (toColour.r - from[attr].r) / ms,
3224 g: (toColour.g - from[attr].g) / ms,
3225 b: (toColour.b - from[attr].b) / ms
3229 var pathes = path2curve(from[attr], to[attr]);
3230 from[attr] = pathes[0];
3231 var toPath = pathes[1];
3233 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3234 diff[attr][i] = [0];
3235 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3236 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3241 var values = Str(params[attr])[split](separator),
3242 from2 = Str(from[attr])[split](separator);
3245 from[attr] = [0, 0];
3246 diff[attr] = [values[0] / ms, values[1] / ms];
3249 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
3250 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
3253 params[attr] = values;
3254 from[attr] = Str(from[attr])[split](separator);
3255 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
3258 from[attr] = Str(from[attr])[split](separator);
3262 diff[attr][i] = (values[i] - from[attr][i]) / ms;
3271 this.in_animation = 1;
3272 animationElements[this.id] = {
3273 start: params.start || +new Date,
3283 ++animationElements[length] == 1 && animation();
3286 Element[proto].stop = function () {
3287 animationElements[this.id] && animationElements[length]--;
3288 delete animationElements[this.id];
3291 Element[proto].translate = function (x, y) {
3292 return this.attr({translation: x + " " + y});
3294 Element[proto][toString] = function () {
3295 return "Rapha\xebl\u2019s object";
3297 R.ae = animationElements;
3300 var Set = function (items) {
3305 for (var i = 0, ii = items[length]; i < ii; i++) {
3306 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
3307 this[this.items[length]] = this.items[this.items[length]] = items[i];
3313 Set[proto][push] = function () {
3316 for (var i = 0, ii = arguments[length]; i < ii; i++) {
3317 item = arguments[i];
3318 if (item && (item.constructor == Element || item.constructor == Set)) {
3319 len = this.items[length];
3320 this[len] = this.items[len] = item;
3326 Set[proto].pop = function () {
3327 delete this[this[length]--];
3328 return this.items.pop();
3330 for (var method in Element[proto]) if (Element[proto][has](method)) {
3331 Set[proto][method] = (function (methodname) {
3332 return function () {
3333 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3334 this.items[i][methodname][apply](this.items[i], arguments);
3340 Set[proto].attr = function (name, value) {
3341 if (name && R.is(name, array) && R.is(name[0], "object")) {
3342 for (var j = 0, jj = name[length]; j < jj; j++) {
3343 this.items[j].attr(name[j]);
3346 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3347 this.items[i].attr(name, value);
3352 Set[proto].animate = function (params, ms, easing, callback) {
3353 (R.is(easing, "function") || !easing) && (callback = easing || null);
3354 var len = this.items[length],
3359 callback && (collector = function () {
3360 !--len && callback.call(set);
3362 easing = R.is(easing, string) ? easing : collector;
3363 item = this.items[--i].animate(params, ms, easing, collector);
3365 this.items[i].animateWith(item, params, ms, easing, collector);
3369 Set[proto].insertAfter = function (el) {
3370 var i = this.items[length];
3372 this.items[i].insertAfter(el);
3376 Set[proto].getBBox = function () {
3381 for (var i = this.items[length]; i--;) {
3382 var box = this.items[i].getBBox();
3385 w[push](box.x + box.width);
3386 h[push](box.y + box.height);
3388 x = mmin[apply](0, x);
3389 y = mmin[apply](0, y);
3393 width: mmax[apply](0, w) - x,
3394 height: mmax[apply](0, h) - y
3397 Set[proto].clone = function (s) {
3399 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3400 s[push](this.items[i].clone());
3405 R.registerFont = function (font) {
3409 this.fonts = this.fonts || {};
3415 family = font.face["font-family"];
3416 for (var prop in font.face) if (font.face[has](prop)) {
3417 fontcopy.face[prop] = font.face[prop];
3419 if (this.fonts[family]) {
3420 this.fonts[family][push](fontcopy);
3422 this.fonts[family] = [fontcopy];
3425 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3426 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3427 var path = font.glyphs[glyph];
3428 fontcopy.glyphs[glyph] = {
3431 d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3432 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3436 for (var k in path.k) if (path[has](k)) {
3437 fontcopy.glyphs[glyph].k[k] = path.k[k];
3444 Paper[proto].getFont = function (family, weight, style, stretch) {
3445 stretch = stretch || "normal";
3446 style = style || "normal";
3447 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3451 var font = R.fonts[family];
3453 var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3454 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3455 if (name.test(fontName)) {
3456 font = R.fonts[fontName];
3463 for (var i = 0, ii = font[length]; i < ii; i++) {
3465 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3472 Paper[proto].print = function (x, y, string, font, size, origin) {
3473 origin = origin || "middle"; // baseline|middle
3474 var out = this.set(),
3475 letters = Str(string)[split](E),
3479 R.is(font, string) && (font = this.getFont(font));
3481 scale = (size || 16) / font.face["units-per-em"];
3482 var bb = font.face.bbox.split(separator),
3484 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3485 for (var i = 0, ii = letters[length]; i < ii; i++) {
3486 var prev = i && font.glyphs[letters[i - 1]] || {},
3487 curr = font.glyphs[letters[i]];
3488 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
3489 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3491 out.scale(scale, scale, top, height).translate(x - top, y - height);
3496 var formatrg = /\{(\d+)\}/g;
3497 R.format = function (token, params) {
3498 var args = R.is(params, array) ? [0][concat](params) : arguments;
3499 token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
3500 return args[++i] == null ? E : args[i];
3504 R.ninja = function () {
3505 oldRaphael.was ? (Raphael = oldRaphael.is) : delete Raphael;
3508 R.el = Element[proto];