2 * Raphael 1.5.1 - 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.
9 if (R.is(arguments[0], array)) {
11 cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
13 for (var i = 0, ii = a[length]; i < ii; i++) {
15 elements[has](j.type) && res[push](cnv[j.type]().attr(j));
19 return create[apply](R, arguments);
22 var separator = /[, ]+/,
23 elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
24 formatrg = /\{(\d+)\}/g,
26 has = "hasOwnProperty",
30 was: Object[proto][has].call(win, "Raphael"),
34 this.customAttributes = {};
37 appendChild = "appendChild",
40 supportsTouch = "createTouch" in doc,
45 events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
47 mousedown: "touchstart",
48 mousemove: "touchmove",
53 lowerCase = Str[proto].toLowerCase,
62 toString = "toString",
64 objectToString = Object[proto][toString],
68 ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
69 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,
70 isnan = /^(NaN|-?Infinity)$/,
71 bezierrg = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
73 setAttribute = "setAttribute",
76 ms = " progid:DXImageTransform.Microsoft",
77 upperCase = Str[proto].toUpperCase,
78 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},
79 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},
81 p2s = /,?([achlmqrstvxz]),?/gi,
82 commaSpaces = /\s*,\s*/,
83 hsrg = {hs: 1, rg: 1},
84 animKeyFrames= /^(from|to|\d+%)$/,
85 pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
86 pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig,
87 sortByKey = function (a, b) {
91 R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
92 if (R.type == "VML") {
93 var d = doc.createElement("div"),
95 d.innerHTML = '<v:shape adj="1"/>';
97 b.style.behavior = "url(#default#VML)";
98 if (!(b && typeof b.adj == "object")) {
103 R.svg = !(R.vml = R.type == "VML");
104 Paper[proto] = R[proto];
105 paperproto = Paper[proto];
109 R.is = function (o, type) {
110 type = lowerCase.call(type);
111 if (type == "finite") {
112 return !isnan.test(+o);
114 return (type == "null" && o === null) ||
115 (type == typeof o) ||
116 (type == "object" && o === Object(o)) ||
117 (type == "array" && Array.isArray && Array.isArray(o)) ||
118 objectToString.call(o).slice(8, -1).toLowerCase() == type;
120 R.angle = function (x1, y1, x2, y2, x3, y3) {
127 return ((x < 0) * 180 + math.atan(-y / -x) * 180 / math.PI + 360) % 360;
129 return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
132 R.snapTo = function (values, value, tolerance) {
133 tolerance = tolerance || 10;
134 values = [][concat](values);
135 var i = values.length;
136 while (i--) if (abs(values[i] - value) <= tolerance) {
142 R.setWindow = function (newwin) {
147 var toHex = function (color) {
149 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
150 var trim = /^\s+|\s+$/g;
153 var docum = new ActiveXObject("htmlfile");
154 docum.write("<body>");
158 bod = createPopup().document.body;
160 var range = bod.createTextRange();
161 toHex = cacher(function (color) {
163 bod.style.color = Str(color)[rp](trim, E);
164 var value = range.queryCommandValue("ForeColor");
165 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
166 return "#" + ("000000" + value[toString](16)).slice(-6);
172 var i = doc.createElement("i");
173 i.title = "Rapha\xebl Colour Picker";
174 i.style.display = "none";
175 doc.body[appendChild](i);
176 toHex = cacher(function (color) {
177 i.style.color = color;
178 return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
183 hsbtoString = function () {
184 return "hsb(" + [this.h, this.s, this.b] + ")";
186 hsltoString = function () {
187 return "hsl(" + [this.h, this.s, this.l] + ")";
189 rgbtoString = function () {
192 R.hsb2rgb = function (h, s, b) {
193 if (R.is(h, "object") && "h" in h && "s" in h && "b" in h) {
198 return R.hsl2rgb(h, s, b / 2);
200 R.hsl2rgb = function (h, s, l) {
201 if (R.is(h, "object") && "h" in h && "s" in h && "l" in h) {
206 if (h > 1 || s > 1 || l > 1) {
212 channels = ["r", "g", "b"],
227 for (var i = 0, ii = channels.length; i < ii; i++) {
228 t3 = h + 1 / 3 * -(i - 1);
232 rgb[channels[i]] = t1 + (t2 - t1) * 6 * t3;
233 } else if (t3 * 2 < 1) {
234 rgb[channels[i]] = t2;
235 } else if (t3 * 3 < 2) {
236 rgb[channels[i]] = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
238 rgb[channels[i]] = t1;
245 r = (~~rgb.r)[toString](16);
246 g = (~~rgb.g)[toString](16);
247 b = (~~rgb.b)[toString](16);
251 rgb.hex = "#" + r + g + b;
252 rgb.toString = rgbtoString;
255 R.rgb2hsb = function (red, green, blue) {
256 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
261 if (green == null && R.is(red, string)) {
262 var clr = R.getRGB(red);
267 if (red > 1 || green > 1 || blue > 1) {
272 var max = mmax(red, green, blue),
273 min = mmin(red, green, blue),
278 return {h: 0, s: 0, b: max, toString: hsbtoString};
280 var delta = (max - min);
281 saturation = delta / max;
283 hue = (green - blue) / delta;
284 } else if (green == max) {
285 hue = 2 + ((blue - red) / delta);
287 hue = 4 + ((red - green) / delta);
293 return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
295 R.rgb2hsl = function (red, green, blue) {
296 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
301 if (green == null && R.is(red, string)) {
302 var clr = R.getRGB(red);
307 if (red > 1 || green > 1 || blue > 1) {
312 var max = mmax(red, green, blue),
313 min = mmin(red, green, blue),
319 hsl = {h: 0, s: 0, l: l};
321 var delta = max - min;
322 s = l < .5 ? delta / (max + min) : delta / (2 - max - min);
324 h = (green - blue) / delta;
325 } else if (green == max) {
326 h = 2 + (blue - red) / delta;
328 h = 4 + (red - green) / delta;
333 hsl = {h: h, s: s, l: l};
335 hsl.toString = hsltoString;
338 R._path2string = function () {
339 return this.join(",")[rp](p2s, "$1");
341 function cacher(f, scope, postprocessor) {
343 var arg = Array[proto].slice.call(arguments, 0),
344 args = arg[join]("\u25ba"),
345 cache = newf.cache = newf.cache || {},
346 count = newf.count = newf.count || [];
347 if (cache[has](args)) {
348 return postprocessor ? postprocessor(cache[args]) : cache[args];
350 count[length] >= 1e3 && delete cache[count.shift()];
352 cache[args] = f[apply](scope, arg);
353 return postprocessor ? postprocessor(cache[args]) : cache[args];
358 R.getRGB = cacher(function (colour) {
359 if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
360 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
362 if (colour == "none") {
363 return {r: -1, g: -1, b: -1, hex: "none"};
365 !(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
372 rgb = colour.match(colourRegExp);
375 blue = toInt(rgb[2].substring(5), 16);
376 green = toInt(rgb[2].substring(3, 5), 16);
377 red = toInt(rgb[2].substring(1, 3), 16);
380 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
381 green = toInt((t = rgb[3].charAt(2)) + t, 16);
382 red = toInt((t = rgb[3].charAt(1)) + t, 16);
385 rgb = rgb[4][split](commaSpaces);
386 red = toFloat(rgb[0]);
387 green = toFloat(rgb[1]);
388 blue = toFloat(rgb[2]);
389 opacity = toFloat(rgb[3]);
392 rgb = rgb[5][split](commaSpaces);
393 red = toFloat(rgb[0]) * 2.55;
394 green = toFloat(rgb[1]) * 2.55;
395 blue = toFloat(rgb[2]) * 2.55;
396 opacity = toFloat(rgb[3]);
399 rgb = rgb[6][split](commaSpaces);
400 red = toFloat(rgb[0]);
401 green = toFloat(rgb[1]);
402 blue = toFloat(rgb[2]);
403 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
404 return R.hsb2rgb(red, green, blue);
407 rgb = rgb[7][split](commaSpaces);
408 red = toFloat(rgb[0]) * 2.55;
409 green = toFloat(rgb[1]) * 2.55;
410 blue = toFloat(rgb[2]) * 2.55;
411 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
412 return R.hsb2rgb(red, green, blue);
415 rgb = rgb[8][split](commaSpaces);
416 red = toFloat(rgb[0]);
417 green = toFloat(rgb[1]);
418 blue = toFloat(rgb[2]);
419 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
420 return R.hsl2rgb(red, green, blue);
423 rgb = rgb[9][split](commaSpaces);
424 red = toFloat(rgb[0]) * 2.55;
425 green = toFloat(rgb[1]) * 2.55;
426 blue = toFloat(rgb[2]) * 2.55;
427 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
428 return R.hsl2rgb(red, green, blue);
430 rgb = {r: red, g: green, b: blue};
431 var r = (~~red)[toString](16),
432 g = (~~green)[toString](16),
433 b = (~~blue)[toString](16);
437 rgb.hex = "#" + r + g + b;
438 isFinite(toFloat(opacity)) && (rgb.o = opacity);
441 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
443 R.getColor = function (value) {
444 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
445 rgb = this.hsb2rgb(start.h, start.s, start.b);
450 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
454 R.getColor.reset = function () {
458 R.parsePathString = cacher(function (pathString) {
462 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
464 if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
465 data = pathClone(pathString);
468 Str(pathString)[rp](pathCommand, function (a, b, c) {
470 name = lowerCase.call(b);
471 c[rp](pathValues, function (a, b) {
472 b && params[push](+b);
474 if (name == "m" && params[length] > 2) {
475 data[push]([b][concat](params.splice(0, 2)));
477 b = b == "m" ? "l" : "L";
479 while (params[length] >= paramCounts[name]) {
480 data[push]([b][concat](params.splice(0, paramCounts[name])));
481 if (!paramCounts[name]) {
487 data[toString] = R._path2string;
490 R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
492 x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
493 y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
494 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
495 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
496 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
497 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
498 ax = (1 - t) * p1x + t * c1x,
499 ay = (1 - t) * p1y + t * c1y,
500 cx = (1 - t) * c2x + t * p2x,
501 cy = (1 - t) * c2y + t * p2y,
502 alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
503 (mx > nx || my < ny) && (alpha += 180);
504 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};
506 var pathDimensions = cacher(function (path) {
508 return {x: 0, y: 0, width: 0, height: 0};
510 path = path2curve(path);
516 for (var i = 0, ii = path[length]; i < ii; i++) {
524 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
525 X = X[concat](dim.min.x, dim.max.x);
526 Y = Y[concat](dim.min.y, dim.max.y);
531 var xmin = mmin[apply](0, X),
532 ymin = mmin[apply](0, Y);
536 width: mmax[apply](0, X) - xmin,
537 height: mmax[apply](0, Y) - ymin
540 pathClone = function (pathArray) {
542 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
543 pathArray = R.parsePathString(pathArray);
545 for (var i = 0, ii = pathArray[length]; i < ii; i++) {
547 for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
548 res[i][j] = pathArray[i][j];
551 res[toString] = R._path2string;
554 pathToRelative = cacher(function (pathArray) {
555 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
556 pathArray = R.parsePathString(pathArray);
564 if (pathArray[0][0] == "M") {
570 res[push](["M", x, y]);
572 for (var i = start, ii = pathArray[length]; i < ii; i++) {
575 if (pa[0] != lowerCase.call(pa[0])) {
576 r[0] = lowerCase.call(pa[0]);
584 r[6] = +(pa[6] - x).toFixed(3);
585 r[7] = +(pa[7] - y).toFixed(3);
588 r[1] = +(pa[1] - y).toFixed(3);
594 for (var j = 1, jj = pa[length]; j < jj; j++) {
595 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
604 for (var k = 0, kk = pa[length]; k < kk; k++) {
608 var len = res[i][length];
615 x += +res[i][len - 1];
618 y += +res[i][len - 1];
621 x += +res[i][len - 2];
622 y += +res[i][len - 1];
625 res[toString] = R._path2string;
628 pathToAbsolute = cacher(function (pathArray) {
629 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
630 pathArray = R.parsePathString(pathArray);
638 if (pathArray[0][0] == "M") {
639 x = +pathArray[0][1];
640 y = +pathArray[0][2];
644 res[0] = ["M", x, y];
646 for (var i = start, ii = pathArray[length]; i < ii; i++) {
649 if (pa[0] != upperCase.call(pa[0])) {
650 r[0] = upperCase.call(pa[0]);
671 for (var j = 1, jj = pa[length]; j < jj; j++) {
672 r[j] = +pa[j] + ((j % 2) ? x : y);
676 for (var k = 0, kk = pa[length]; k < kk; k++) {
692 mx = res[i][res[i][length] - 2];
693 my = res[i][res[i][length] - 1];
695 x = res[i][res[i][length] - 2];
696 y = res[i][res[i][length] - 1];
699 res[toString] = R._path2string;
702 l2c = function (x1, y1, x2, y2) {
703 return [x1, y1, x2, y2, x2, y2];
705 q2c = function (x1, y1, ax, ay, x2, y2) {
717 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
718 // for more information of where this math came from visit:
719 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
721 _120 = PI * 120 / 180,
722 rad = PI / 180 * (+angle || 0),
725 rotate = cacher(function (x, y, rad) {
726 var X = x * math.cos(rad) - y * math.sin(rad),
727 Y = x * math.sin(rad) + y * math.cos(rad);
731 xy = rotate(x1, y1, -rad);
734 xy = rotate(x2, y2, -rad);
737 var cos = math.cos(PI / 180 * angle),
738 sin = math.sin(PI / 180 * angle),
741 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
749 k = (large_arc_flag == sweep_flag ? -1 : 1) *
750 math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
751 cx = k * rx * y / ry + (x1 + x2) / 2,
752 cy = k * -ry * x / rx + (y1 + y2) / 2,
753 f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
754 f2 = math.asin(((y2 - cy) / ry).toFixed(9));
756 f1 = x1 < cx ? PI - f1 : f1;
757 f2 = x2 < cx ? PI - f2 : f2;
758 f1 < 0 && (f1 = PI * 2 + f1);
759 f2 < 0 && (f2 = PI * 2 + f2);
760 if (sweep_flag && f1 > f2) {
763 if (!sweep_flag && f2 > f1) {
773 if (abs(df) > _120) {
777 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
778 x2 = cx + rx * math.cos(f2);
779 y2 = cy + ry * math.sin(f2);
780 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
783 var c1 = math.cos(f1),
787 t = math.tan(df / 4),
791 m2 = [x1 + hx * s1, y1 - hy * c1],
792 m3 = [x2 + hx * s2, y2 - hy * c2],
794 m2[0] = 2 * m1[0] - m2[0];
795 m2[1] = 2 * m1[1] - m2[1];
797 return [m2, m3, m4][concat](res);
799 res = [m2, m3, m4][concat](res)[join]()[split](",");
801 for (var i = 0, ii = res[length]; i < ii; i++) {
802 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
807 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
810 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
811 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
814 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
815 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
816 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
818 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
819 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
823 abs(t1) > "1e12" && (t1 = .5);
824 abs(t2) > "1e12" && (t2 = .5);
825 if (t1 > 0 && t1 < 1) {
826 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
830 if (t2 > 0 && t2 < 1) {
831 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
835 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
836 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
838 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
839 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
840 abs(t1) > "1e12" && (t1 = .5);
841 abs(t2) > "1e12" && (t2 = .5);
842 if (t1 > 0 && t1 < 1) {
843 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
847 if (t2 > 0 && t2 < 1) {
848 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
853 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
854 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
857 path2curve = cacher(function (path, path2) {
858 var p = pathToAbsolute(path),
859 p2 = path2 && pathToAbsolute(path2),
860 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
861 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
862 processPath = function (path, d) {
865 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
867 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
874 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
877 nx = d.x + (d.x - (d.bx || d.x));
878 ny = d.y + (d.y - (d.by || d.y));
879 path = ["C", nx, ny][concat](path.slice(1));
882 d.qx = d.x + (d.x - (d.qx || d.x));
883 d.qy = d.y + (d.y - (d.qy || d.y));
884 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
889 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
892 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
895 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
898 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
901 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
906 fixArc = function (pp, i) {
907 if (pp[i][length] > 7) {
911 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
914 ii = mmax(p[length], p2 && p2[length] || 0);
917 fixM = function (path1, path2, a1, a2, i) {
918 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
919 path2.splice(i, 0, ["M", a2.x, a2.y]);
924 ii = mmax(p[length], p2 && p2[length] || 0);
927 for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
928 p[i] = processPath(p[i], attrs);
930 p2 && (p2[i] = processPath(p2[i], attrs2));
932 fixM(p, p2, attrs, attrs2, i);
933 fixM(p2, p, attrs2, attrs, i);
936 seglen = seg[length],
937 seg2len = p2 && seg2[length];
938 attrs.x = seg[seglen - 2];
939 attrs.y = seg[seglen - 1];
940 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
941 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
942 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
943 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
944 attrs2.x = p2 && seg2[seg2len - 2];
945 attrs2.y = p2 && seg2[seg2len - 1];
947 return p2 ? [p, p2] : p;
949 parseDots = cacher(function (gradient) {
951 for (var i = 0, ii = gradient[length]; i < ii; i++) {
953 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
954 dot.color = R.getRGB(par[1]);
955 if (dot.color.error) {
958 dot.color = dot.color.hex;
959 par[2] && (dot.offset = par[2] + "%");
962 for (i = 1, ii = dots[length] - 1; i < ii; i++) {
963 if (!dots[i].offset) {
964 var start = toFloat(dots[i - 1].offset || 0),
966 for (var j = i + 1; j < ii; j++) {
967 if (dots[j].offset) {
968 end = dots[j].offset;
977 var d = (end - start) / (j - i + 1);
980 dots[i].offset = start + "%";
986 getContainer = function (x, y, w, h) {
988 if (R.is(x, string) || R.is(x, "object")) {
989 container = R.is(x, string) ? doc.getElementById(x) : x;
990 if (container.tagName) {
993 container: container,
994 width: container.style.pixelWidth || container.offsetWidth,
995 height: container.style.pixelHeight || container.offsetHeight
998 return {container: container, width: y, height: w};
1002 return {container: 1, x: x, y: y, width: w, height: h};
1005 plugins = function (con, add) {
1007 for (var prop in add) {
1008 if (add[has](prop) && !(prop in con)) {
1009 switch (typeof add[prop]) {
1012 con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
1016 con[prop] = con[prop] || {};
1017 plugins.call(this, con[prop], add[prop]);
1020 con[prop] = add[prop];
1026 tear = function (el, paper) {
1027 el == paper.top && (paper.top = el.prev);
1028 el == paper.bottom && (paper.bottom = el.next);
1029 el.next && (el.next.prev = el.prev);
1030 el.prev && (el.prev.next = el.next);
1032 tofront = function (el, paper) {
1033 if (paper.top === el) {
1038 el.prev = paper.top;
1039 paper.top.next = el;
1042 toback = function (el, paper) {
1043 if (paper.bottom === el) {
1047 el.next = paper.bottom;
1049 paper.bottom.prev = el;
1052 insertafter = function (el, el2, paper) {
1054 el2 == paper.top && (paper.top = el);
1055 el2.next && (el2.next.prev = el);
1060 insertbefore = function (el, el2, paper) {
1062 el2 == paper.bottom && (paper.bottom = el);
1063 el2.prev && (el2.prev.next = el);
1068 removed = function (methodname) {
1069 return function () {
1070 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1073 radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
1074 R.pathToRelative = pathToRelative;
1077 paperproto.svgns = "http://www.w3.org/2000/svg";
1078 paperproto.xlink = "http://www.w3.org/1999/xlink";
1079 round = function (num) {
1080 return +num + (~~num === num) * .5;
1082 var $ = function (el, attr) {
1084 for (var key in attr) {
1085 if (attr[has](key)) {
1086 el[setAttribute](key, Str(attr[key]));
1090 el = doc.createElementNS(paperproto.svgns, el);
1091 el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
1095 R[toString] = function () {
1096 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
1098 var thePath = function (pathString, SVG) {
1100 SVG.canvas && SVG.canvas[appendChild](el);
1101 var p = new Element(el, SVG);
1103 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
1106 var addGradientFill = function (o, gradient, SVG) {
1107 var type = "linear",
1110 gradient = Str(gradient)[rp](radial_gradient, function (all, _fx, _fy) {
1115 var dir = ((fy > .5) * 2 - 1);
1116 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
1117 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
1119 (fy = fy.toFixed(5) - 1e-5 * dir);
1123 gradient = gradient[split](/\s*\-\s*/);
1124 if (type == "linear") {
1125 var angle = gradient.shift();
1126 angle = -toFloat(angle);
1130 var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
1131 max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
1134 if (vector[2] < 0) {
1135 vector[0] = -vector[2];
1138 if (vector[3] < 0) {
1139 vector[1] = -vector[3];
1143 var dots = parseDots(gradient);
1147 var id = o.getAttribute(fillString);
1148 id = id.match(/^url\(#(.*)\)$/);
1149 id && SVG.defs.removeChild(doc.getElementById(id[1]));
1151 var el = $(type + "Gradient");
1152 el.id = "r" + (R._id++)[toString](36);
1153 $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
1154 SVG.defs[appendChild](el);
1155 for (var i = 0, ii = dots[length]; i < ii; i++) {
1156 var stop = $("stop");
1158 offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
1159 "stop-color": dots[i].color || "#fff"
1161 el[appendChild](stop);
1164 fill: "url(#" + el.id + ")",
1173 var updatePosition = function (o) {
1174 var bbox = o.getBBox();
1175 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
1177 var setFillAndStroke = function (o, params) {
1184 "-..": [3, 1, 1, 1, 1, 1],
1188 "- .": [4, 3, 1, 3],
1189 "--.": [8, 3, 1, 3],
1190 "--..": [8, 3, 1, 3, 1, 3]
1195 addDashes = function (o, value) {
1196 value = dasharray[lowerCase.call(value)];
1198 var width = o.attrs["stroke-width"] || "1",
1199 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1201 var i = value[length];
1203 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
1205 $(node, {"stroke-dasharray": dashes[join](",")});
1208 params[has]("rotation") && (rot = params.rotation);
1209 var rotxy = Str(rot)[split](separator);
1210 if (!(rotxy.length - 1)) {
1213 rotxy[1] = +rotxy[1];
1214 rotxy[2] = +rotxy[2];
1216 toFloat(rot) && o.rotate(0, true);
1217 for (var att in params) {
1218 if (params[has](att)) {
1219 if (!availableAttrs[has](att)) {
1222 var value = params[att];
1229 o.rotate(value, true);
1234 var pn = node.parentNode;
1235 if (lowerCase.call(pn.tagName) != "a") {
1237 pn.insertBefore(hl, node);
1238 hl[appendChild](node);
1241 if (att == "target" && value == "blank") {
1242 pn.setAttributeNS(o.paper.xlink, "show", "new");
1244 pn.setAttributeNS(o.paper.xlink, att, value);
1248 node.style.cursor = value;
1251 var rect = Str(value)[split](separator);
1252 if (rect[length] == 4) {
1253 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
1254 var el = $("clipPath"),
1256 el.id = "r" + (R._id++)[toString](36);
1263 el[appendChild](rc);
1264 o.paper.defs[appendChild](el);
1265 $(node, {"clip-path": "url(#" + el.id + ")"});
1269 var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
1270 clip && clip.parentNode.removeChild(clip);
1271 $(node, {"clip-path": E});
1276 if (o.type == "path") {
1277 $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
1281 node[setAttribute](att, value);
1290 value = -attrs.x - (attrs.width || 0);
1293 if (att == "rx" && o.type == "rect") {
1297 rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
1298 node[setAttribute](att, value);
1299 o.pattern && updatePosition(o);
1302 node[setAttribute](att, value);
1311 value = -attrs.y - (attrs.height || 0);
1314 if (att == "ry" && o.type == "rect") {
1318 rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
1319 node[setAttribute](att, value);
1320 o.pattern && updatePosition(o);
1323 if (o.type == "rect") {
1324 $(node, {rx: value, ry: value});
1326 node[setAttribute](att, value);
1330 if (o.type == "image") {
1331 node.setAttributeNS(o.paper.xlink, "href", value);
1334 case "stroke-width":
1335 node.style.strokeWidth = value;
1336 // Need following line for Firefox
1337 node[setAttribute](att, value);
1338 if (attrs["stroke-dasharray"]) {
1339 addDashes(o, attrs["stroke-dasharray"]);
1342 case "stroke-dasharray":
1343 addDashes(o, value);
1346 var xy = Str(value)[split](separator);
1347 xy[0] = +xy[0] || 0;
1348 xy[1] = +xy[1] || 0;
1353 translate.call(o, xy[0], xy[1]);
1356 xy = Str(value)[split](separator);
1357 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
1360 var isURL = Str(value).match(ISURL);
1363 var ig = $("image");
1364 el.id = "r" + (R._id++)[toString](36);
1365 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
1366 $(ig, {x: 0, y: 0});
1367 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1368 el[appendChild](ig);
1370 var img = doc.createElement("img");
1371 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
1372 img.onload = function () {
1373 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1374 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1375 doc.body.removeChild(this);
1378 doc.body[appendChild](img);
1380 o.paper.defs[appendChild](el);
1381 node.style.fill = "url(#" + el.id + ")";
1382 $(node, {fill: "url(#" + el.id + ")"});
1384 o.pattern && updatePosition(o);
1387 var clr = R.getRGB(value);
1389 delete params.gradient;
1390 delete attrs.gradient;
1391 !R.is(attrs.opacity, "undefined") &&
1392 R.is(params.opacity, "undefined") &&
1393 $(node, {opacity: attrs.opacity});
1394 !R.is(attrs["fill-opacity"], "undefined") &&
1395 R.is(params["fill-opacity"], "undefined") &&
1396 $(node, {"fill-opacity": attrs["fill-opacity"]});
1397 } else if ((({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper)) {
1398 attrs.gradient = value;
1399 attrs.fill = "none";
1402 clr[has]("o") && $(node, {"fill-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1404 clr = R.getRGB(value);
1405 node[setAttribute](att, clr.hex);
1406 att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1409 (({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper);
1412 case "fill-opacity":
1413 if (attrs.gradient) {
1414 var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
1416 var stops = gradient.getElementsByTagName("stop");
1417 stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1422 att == "font-size" && (value = toInt(value, 10) + "px");
1423 var cssrule = att[rp](/(\-.)/g, function (w) {
1424 return upperCase.call(w.substring(1));
1426 node.style[cssrule] = value;
1427 // Need following line for Firefox
1428 node[setAttribute](att, value);
1434 tuneText(o, params);
1436 o.rotate(rotxy.join(S));
1438 toFloat(rot) && o.rotate(rot, true);
1442 tuneText = function (el, params) {
1443 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1448 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1450 if (params[has]("text")) {
1451 a.text = params.text;
1452 while (node.firstChild) {
1453 node.removeChild(node.firstChild);
1455 var texts = Str(params.text)[split]("\n");
1456 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1457 var tspan = $("tspan");
1458 i && $(tspan, {dy: fontSize * leading, x: a.x});
1459 tspan[appendChild](doc.createTextNode(texts[i]));
1460 node[appendChild](tspan);
1463 texts = node.getElementsByTagName("tspan");
1464 for (i = 0, ii = texts[length]; i < ii; i++) {
1465 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1469 var bb = el.getBBox(),
1470 dif = a.y - (bb.y + bb.height / 2);
1471 dif && isFinite(dif) && $(node, {y: a.y + dif});
1473 Element = function (node, svg) {
1479 node.raphael = this;
1481 this.attrs = this.attrs || {};
1482 this.transformations = []; // rotate, translate, scale
1486 rt: {deg: 0, cx: 0, cy: 0},
1490 !svg.bottom && (svg.bottom = this);
1491 this.prev = svg.top;
1492 svg.top && (svg.top.next = this);
1496 var elproto = Element[proto];
1497 Element[proto].rotate = function (deg, cx, cy) {
1503 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1505 return this._.rt.deg;
1507 var bbox = this.getBBox();
1508 deg = Str(deg)[split](separator);
1509 if (deg[length] - 1) {
1510 cx = toFloat(deg[1]);
1511 cy = toFloat(deg[2]);
1513 deg = toFloat(deg[0]);
1514 if (cx != null && cx !== false) {
1515 this._.rt.deg = deg;
1517 this._.rt.deg += deg;
1519 (cy == null) && (cx = null);
1522 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1523 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1524 if (this._.rt.deg) {
1525 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1526 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1528 this.transformations[0] = E;
1529 this.clip && $(this.clip, {transform: E});
1531 $(this.node, {transform: this.transformations[join](S)});
1534 Element[proto].hide = function () {
1535 !this.removed && (this.node.style.display = "none");
1538 Element[proto].show = function () {
1539 !this.removed && (this.node.style.display = "");
1542 Element[proto].remove = function () {
1546 tear(this, this.paper);
1547 this.node.parentNode.removeChild(this.node);
1548 for (var i in this) {
1551 this.removed = true;
1553 Element[proto].getBBox = function () {
1557 if (this.type == "path") {
1558 return pathDimensions(this.attrs.path);
1560 if (this.node.style.display == "none") {
1566 bbox = this.node.getBBox();
1568 // Firefox 3.0.x plays badly here
1572 if (this.type == "text") {
1573 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1574 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1575 var bb = this.node.getExtentOfChar(i);
1576 (bb.y < bbox.y) && (bbox.y = bb.y);
1577 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1578 (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1581 hide && this.hide();
1584 Element[proto].attr = function (name, value) {
1590 for (var i in this.attrs) if (this.attrs[has](i)) {
1591 res[i] = this.attrs[i];
1593 this._.rt.deg && (res.rotation = this.rotate());
1594 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1595 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1598 if (value == null && R.is(name, string)) {
1599 if (name == "translation") {
1600 return translate.call(this);
1602 if (name == "rotation") {
1603 return this.rotate();
1605 if (name == "scale") {
1606 return this.scale();
1608 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
1609 return this.attrs.gradient;
1611 return this.attrs[name];
1613 if (value == null && R.is(name, array)) {
1615 for (var j = 0, jj = name.length; j < jj; j++) {
1616 values[name[j]] = this.attr(name[j]);
1620 if (value != null) {
1622 params[name] = value;
1623 } else if (name != null && R.is(name, "object")) {
1626 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1627 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
1628 this.attrs[key] = params[key];
1629 for (var subkey in par) if (par[has](subkey)) {
1630 params[subkey] = par[subkey];
1633 setFillAndStroke(this, params);
1636 Element[proto].toFront = function () {
1640 this.node.parentNode[appendChild](this.node);
1641 var svg = this.paper;
1642 svg.top != this && tofront(this, svg);
1645 Element[proto].toBack = function () {
1649 if (this.node.parentNode.firstChild != this.node) {
1650 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1651 toback(this, this.paper);
1652 var svg = this.paper;
1656 Element[proto].insertAfter = function (element) {
1660 var node = element.node || element[element.length - 1].node;
1661 if (node.nextSibling) {
1662 node.parentNode.insertBefore(this.node, node.nextSibling);
1664 node.parentNode[appendChild](this.node);
1666 insertafter(this, element, this.paper);
1669 Element[proto].insertBefore = function (element) {
1673 var node = element.node || element[0].node;
1674 node.parentNode.insertBefore(this.node, node);
1675 insertbefore(this, element, this.paper);
1678 Element[proto].blur = function (size) {
1679 // Experimental. No Safari support. Use it on your own risk.
1682 var fltr = $("filter"),
1683 blur = $("feGaussianBlur");
1684 t.attrs.blur = size;
1685 fltr.id = "r" + (R._id++)[toString](36);
1686 $(blur, {stdDeviation: +size || 1.5});
1687 fltr.appendChild(blur);
1688 t.paper.defs.appendChild(fltr);
1690 $(t.node, {filter: "url(#" + fltr.id + ")"});
1693 t._blur.parentNode.removeChild(t._blur);
1695 delete t.attrs.blur;
1697 t.node.removeAttribute("filter");
1700 var theCircle = function (svg, x, y, r) {
1701 var el = $("circle");
1702 svg.canvas && svg.canvas[appendChild](el);
1703 var res = new Element(el, svg);
1704 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1705 res.type = "circle";
1709 theRect = function (svg, x, y, w, h, r) {
1711 svg.canvas && svg.canvas[appendChild](el);
1712 var res = new Element(el, svg);
1713 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1718 theEllipse = function (svg, x, y, rx, ry) {
1719 var el = $("ellipse");
1720 svg.canvas && svg.canvas[appendChild](el);
1721 var res = new Element(el, svg);
1722 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1723 res.type = "ellipse";
1727 theImage = function (svg, src, x, y, w, h) {
1728 var el = $("image");
1729 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1730 el.setAttributeNS(svg.xlink, "href", src);
1731 svg.canvas && svg.canvas[appendChild](el);
1732 var res = new Element(el, svg);
1733 res.attrs = {x: x, y: y, width: w, height: h, src: src};
1737 theText = function (svg, x, y, text) {
1739 $(el, {x: x, y: y, "text-anchor": "middle"});
1740 svg.canvas && svg.canvas[appendChild](el);
1741 var res = new Element(el, svg);
1742 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1744 setFillAndStroke(res, res.attrs);
1747 setSize = function (width, height) {
1748 this.width = width || this.width;
1749 this.height = height || this.height;
1750 this.canvas[setAttribute]("width", this.width);
1751 this.canvas[setAttribute]("height", this.height);
1754 create = function () {
1755 var con = getContainer[apply](0, arguments),
1756 container = con && con.container,
1760 height = con.height;
1762 throw new Error("SVG container not found.");
1764 var cnvs = $("svg");
1767 width = width || 512;
1768 height = height || 342;
1770 xmlns: "http://www.w3.org/2000/svg",
1775 if (container == 1) {
1776 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1777 doc.body[appendChild](cnvs);
1779 if (container.firstChild) {
1780 container.insertBefore(cnvs, container.firstChild);
1782 container[appendChild](cnvs);
1785 container = new Paper;
1786 container.width = width;
1787 container.height = height;
1788 container.canvas = cnvs;
1789 plugins.call(container, container, R.fn);
1793 paperproto.clear = function () {
1794 var c = this.canvas;
1795 while (c.firstChild) {
1796 c.removeChild(c.firstChild);
1798 this.bottom = this.top = null;
1799 (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1800 c[appendChild](this.desc);
1801 c[appendChild](this.defs = $("defs"));
1803 paperproto.remove = function () {
1804 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1805 for (var i in this) {
1806 this[i] = removed(i);
1813 var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1814 bites = /([clmz]),?([^clmz]*)/gi,
1815 blurregexp = / progid:\S+Blur\([^\)]+\)/g,
1816 val = /-?[^,\s-]+/g,
1817 coordsize = 1e3 + S + 1e3,
1819 pathlike = {path: 1, rect: 1},
1820 path2vml = function (path) {
1821 var total = /[ahqstv]/ig,
1822 command = pathToAbsolute;
1823 Str(path).match(total) && (command = path2curve);
1825 if (command == pathToAbsolute && !Str(path).match(total)) {
1826 var res = Str(path)[rp](bites, function (all, command, args) {
1828 isMove = lowerCase.call(command) == "m",
1830 args[rp](val, function (value) {
1831 if (isMove && vals[length] == 2) {
1832 res += vals + map[command == "m" ? "l" : "L"];
1835 vals[push](round(value * zoom));
1841 var pa = command(path), p, r;
1843 for (var i = 0, ii = pa[length]; i < ii; i++) {
1845 r = lowerCase.call(pa[i][0]);
1846 r == "z" && (r = "x");
1847 for (var j = 1, jj = p[length]; j < jj; j++) {
1848 r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
1852 return res[join](S);
1855 R[toString] = function () {
1856 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1858 thePath = function (pathString, vml) {
1859 var g = createNode("group");
1860 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
1861 g.coordsize = vml.coordsize;
1862 g.coordorigin = vml.coordorigin;
1863 var el = createNode("shape"), ol = el.style;
1864 ol.width = vml.width + "px";
1865 ol.height = vml.height + "px";
1866 el.coordsize = coordsize;
1867 el.coordorigin = vml.coordorigin;
1869 var p = new Element(el, g, vml),
1870 attr = {fill: "none", stroke: "#000"};
1871 pathString && (attr.path = pathString);
1875 setFillAndStroke(p, attr);
1876 vml.canvas[appendChild](g);
1879 setFillAndStroke = function (o, params) {
1880 o.attrs = o.attrs || {};
1885 newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
1888 for (var par in params) if (params[has](par)) {
1889 a[par] = params[par];
1892 a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
1898 params.href && (node.href = params.href);
1899 params.title && (node.title = params.title);
1900 params.target && (node.target = params.target);
1901 params.cursor && (s.cursor = params.cursor);
1902 "blur" in params && o.blur(params.blur);
1903 if (params.path && o.type == "path" || newpath) {
1904 node.path = path2vml(a.path);
1906 if (params.rotation != null) {
1907 o.rotate(params.rotation, true);
1909 if (params.translation) {
1910 xy = Str(params.translation)[split](separator);
1911 translate.call(o, xy[0], xy[1]);
1912 if (o._.rt.cx != null) {
1913 o._.rt.cx +=+ xy[0];
1914 o._.rt.cy +=+ xy[1];
1915 o.setBox(o.attrs, xy[0], xy[1]);
1919 xy = Str(params.scale)[split](separator);
1920 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1922 if ("clip-rect" in params) {
1923 var rect = Str(params["clip-rect"])[split](separator);
1924 if (rect[length] == 4) {
1925 rect[2] = +rect[2] + (+rect[0]);
1926 rect[3] = +rect[3] + (+rect[1]);
1927 var div = node.clipRect || doc.createElement("div"),
1929 group = node.parentNode;
1930 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1931 if (!node.clipRect) {
1932 dstyle.position = "absolute";
1935 dstyle.width = o.paper.width + "px";
1936 dstyle.height = o.paper.height + "px";
1937 group.parentNode.insertBefore(div, group);
1938 div[appendChild](group);
1939 node.clipRect = div;
1942 if (!params["clip-rect"]) {
1943 node.clipRect && (node.clipRect.style.clip = E);
1946 if (o.type == "image" && params.src) {
1947 node.src = params.src;
1949 if (o.type == "image" && params.opacity) {
1950 node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
1951 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1953 params.font && (s.font = params.font);
1954 params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1955 params["font-size"] && (s.fontSize = params["font-size"]);
1956 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1957 params["font-style"] && (s.fontStyle = params["font-style"]);
1958 if (params.opacity != null ||
1959 params["stroke-width"] != null ||
1960 params.fill != null ||
1961 params.stroke != null ||
1962 params["stroke-width"] != null ||
1963 params["stroke-opacity"] != null ||
1964 params["fill-opacity"] != null ||
1965 params["stroke-dasharray"] != null ||
1966 params["stroke-miterlimit"] != null ||
1967 params["stroke-linejoin"] != null ||
1968 params["stroke-linecap"] != null) {
1969 node = o.shape || node;
1970 var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
1972 !fill && (newfill = fill = createNode(fillString));
1973 if ("fill-opacity" in params || "opacity" in params) {
1974 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
1975 opacity = mmin(mmax(opacity, 0), 1);
1976 fill.opacity = opacity;
1978 params.fill && (fill.on = true);
1979 if (fill.on == null || params.fill == "none") {
1982 if (fill.on && params.fill) {
1983 var isURL = params.fill.match(ISURL);
1985 fill.src = isURL[1];
1988 fill.color = R.getRGB(params.fill).hex;
1990 fill.type = "solid";
1991 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
1993 a.gradient = params.fill;
1997 newfill && node[appendChild](fill);
1998 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
2000 !stroke && (newstroke = stroke = createNode("stroke"));
2001 if ((params.stroke && params.stroke != "none") ||
2002 params["stroke-width"] ||
2003 params["stroke-opacity"] != null ||
2004 params["stroke-dasharray"] ||
2005 params["stroke-miterlimit"] ||
2006 params["stroke-linejoin"] ||
2007 params["stroke-linecap"]) {
2010 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
2011 var strokeColor = R.getRGB(params.stroke);
2012 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
2013 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
2014 var width = (toFloat(params["stroke-width"]) || 1) * .75;
2015 opacity = mmin(mmax(opacity, 0), 1);
2016 params["stroke-width"] == null && (width = a["stroke-width"]);
2017 params["stroke-width"] && (stroke.weight = width);
2018 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
2019 stroke.opacity = opacity;
2021 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
2022 stroke.miterlimit = params["stroke-miterlimit"] || 8;
2023 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
2024 if (params["stroke-dasharray"]) {
2028 "-.": "shortdashdot",
2029 "-..": "shortdashdotdot",
2034 "--.": "longdashdot",
2035 "--..": "longdashdotdot"
2037 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
2039 newstroke && node[appendChild](stroke);
2041 if (res.type == "text") {
2042 s = res.paper.span.style;
2043 a.font && (s.font = a.font);
2044 a["font-family"] && (s.fontFamily = a["font-family"]);
2045 a["font-size"] && (s.fontSize = a["font-size"]);
2046 a["font-weight"] && (s.fontWeight = a["font-weight"]);
2047 a["font-style"] && (s.fontStyle = a["font-style"]);
2048 res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "<")[rp](/&/g, "&")[rp](/\n/g, "<br>"));
2049 res.W = a.w = res.paper.span.offsetWidth;
2050 res.H = a.h = res.paper.span.offsetHeight;
2052 res.Y = a.y + round(res.H / 2);
2054 // text-anchor emulationm
2055 switch (a["text-anchor"]) {
2057 res.node.style["v-text-align"] = "left";
2058 res.bbx = round(res.W / 2);
2061 res.node.style["v-text-align"] = "right";
2062 res.bbx = -round(res.W / 2);
2065 res.node.style["v-text-align"] = "center";
2070 addGradientFill = function (o, gradient) {
2071 o.attrs = o.attrs || {};
2072 var attrs = o.attrs,
2076 o.attrs.gradient = gradient;
2077 gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
2082 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
2087 gradient = gradient[split](/\s*\-\s*/);
2088 if (type == "linear") {
2089 var angle = gradient.shift();
2090 angle = -toFloat(angle);
2095 var dots = parseDots(gradient);
2099 o = o.shape || o.node;
2100 fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
2101 !fill.parentNode && o.appendChild(fill);
2104 fill.method = "none";
2105 fill.color = dots[0].color;
2106 fill.color2 = dots[dots[length] - 1].color;
2108 for (var i = 0, ii = dots[length]; i < ii; i++) {
2109 dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
2111 fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
2112 if (type == "radial") {
2113 fill.type = "gradientradial";
2114 fill.focus = "100%";
2115 fill.focussize = fxfy;
2116 fill.focusposition = fxfy;
2118 fill.type = "gradient";
2119 fill.angle = (270 - angle) % 360;
2124 Element = function (node, group, vml) {
2132 node.raphael = this;
2145 !vml.bottom && (vml.bottom = this);
2146 this.prev = vml.top;
2147 vml.top && (vml.top.next = this);
2151 elproto = Element[proto];
2152 elproto.rotate = function (deg, cx, cy) {
2158 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
2160 return this._.rt.deg;
2162 deg = Str(deg)[split](separator);
2163 if (deg[length] - 1) {
2164 cx = toFloat(deg[1]);
2165 cy = toFloat(deg[2]);
2167 deg = toFloat(deg[0]);
2169 this._.rt.deg = deg;
2171 this._.rt.deg += deg;
2173 cy == null && (cx = null);
2176 this.setBox(this.attrs, cx, cy);
2177 this.Group.style.rotation = this._.rt.deg;
2178 // gradient fix for rotation. TODO
2179 // var fill = (this.shape || this.node).getElementsByTagName(fillString);
2180 // fill = fill[0] || {};
2181 // var b = ((360 - this._.rt.deg) - 270) % 360;
2182 // !R.is(fill.angle, "undefined") && (fill.angle = b);
2185 elproto.setBox = function (params, cx, cy) {
2189 var gs = this.Group.style,
2190 os = (this.shape && this.shape.style) || this.node.style;
2191 params = params || {};
2192 for (var i in params) if (params[has](i)) {
2193 this.attrs[i] = params[i];
2195 cx = cx || this._.rt.cx;
2196 cy = cy || this._.rt.cy;
2197 var attr = this.attrs,
2202 switch (this.type) {
2204 x = attr.cx - attr.r;
2205 y = attr.cy - attr.r;
2209 x = attr.cx - attr.rx;
2210 y = attr.cy - attr.ry;
2217 w = attr.width || 0;
2218 h = attr.height || 0;
2221 this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
2222 x = attr.x - round(this.W / 2);
2223 y = attr.y - this.H / 2;
2229 if (!this.attrs.path) {
2232 w = this.paper.width;
2233 h = this.paper.height;
2235 var dim = pathDimensions(this.attrs.path);
2245 w = this.paper.width;
2246 h = this.paper.height;
2249 cx = (cx == null) ? x + w / 2 : cx;
2250 cy = (cy == null) ? y + h / 2 : cy;
2251 var left = cx - this.paper.width / 2,
2252 top = cy - this.paper.height / 2, t;
2253 gs.left != (t = left + "px") && (gs.left = t);
2254 gs.top != (t = top + "px") && (gs.top = t);
2255 this.X = pathlike[has](this.type) ? -left : x;
2256 this.Y = pathlike[has](this.type) ? -top : y;
2259 if (pathlike[has](this.type)) {
2260 os.left != (t = -left * zoom + "px") && (os.left = t);
2261 os.top != (t = -top * zoom + "px") && (os.top = t);
2262 } else if (this.type == "text") {
2263 os.left != (t = -left + "px") && (os.left = t);
2264 os.top != (t = -top + "px") && (os.top = t);
2266 gs.width != (t = this.paper.width + "px") && (gs.width = t);
2267 gs.height != (t = this.paper.height + "px") && (gs.height = t);
2268 os.left != (t = x - left + "px") && (os.left = t);
2269 os.top != (t = y - top + "px") && (os.top = t);
2270 os.width != (t = w + "px") && (os.width = t);
2271 os.height != (t = h + "px") && (os.height = t);
2274 elproto.hide = function () {
2275 !this.removed && (this.Group.style.display = "none");
2278 elproto.show = function () {
2279 !this.removed && (this.Group.style.display = "block");
2282 elproto.getBBox = function () {
2286 if (pathlike[has](this.type)) {
2287 return pathDimensions(this.attrs.path);
2290 x: this.X + (this.bbx || 0),
2296 elproto.remove = function () {
2300 tear(this, this.paper);
2301 this.node.parentNode.removeChild(this.node);
2302 this.Group.parentNode.removeChild(this.Group);
2303 this.shape && this.shape.parentNode.removeChild(this.shape);
2304 for (var i in this) {
2307 this.removed = true;
2309 elproto.attr = function (name, value) {
2315 for (var i in this.attrs) if (this.attrs[has](i)) {
2316 res[i] = this.attrs[i];
2318 this._.rt.deg && (res.rotation = this.rotate());
2319 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2320 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2323 if (value == null && R.is(name, "string")) {
2324 if (name == "translation") {
2325 return translate.call(this);
2327 if (name == "rotation") {
2328 return this.rotate();
2330 if (name == "scale") {
2331 return this.scale();
2333 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
2334 return this.attrs.gradient;
2336 return this.attrs[name];
2338 if (this.attrs && value == null && R.is(name, array)) {
2339 var ii, values = {};
2340 for (i = 0, ii = name[length]; i < ii; i++) {
2341 values[name[i]] = this.attr(name[i]);
2346 if (value != null) {
2348 params[name] = value;
2350 value == null && R.is(name, "object") && (params = name);
2352 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
2353 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
2354 this.attrs[key] = params[key];
2355 for (var subkey in par) if (par[has](subkey)) {
2356 params[subkey] = par[subkey];
2359 if (params.text && this.type == "text") {
2360 this.node.string = params.text;
2362 setFillAndStroke(this, params);
2363 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
2364 addGradientFill(this, params.gradient);
2366 (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
2370 elproto.toFront = function () {
2371 !this.removed && this.Group.parentNode[appendChild](this.Group);
2372 this.paper.top != this && tofront(this, this.paper);
2375 elproto.toBack = function () {
2379 if (this.Group.parentNode.firstChild != this.Group) {
2380 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2381 toback(this, this.paper);
2385 elproto.insertAfter = function (element) {
2389 if (element.constructor == Set) {
2390 element = element[element.length - 1];
2392 if (element.Group.nextSibling) {
2393 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2395 element.Group.parentNode[appendChild](this.Group);
2397 insertafter(this, element, this.paper);
2400 elproto.insertBefore = function (element) {
2404 if (element.constructor == Set) {
2405 element = element[0];
2407 element.Group.parentNode.insertBefore(this.Group, element.Group);
2408 insertbefore(this, element, this.paper);
2411 elproto.blur = function (size) {
2412 var s = this.node.runtimeStyle,
2414 f = f.replace(blurregexp, E);
2416 this.attrs.blur = size;
2417 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
2418 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
2422 delete this.attrs.blur;
2426 theCircle = function (vml, x, y, r) {
2427 var g = createNode("group"),
2428 o = createNode("oval"),
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;
2434 var res = new Element(o, g, vml);
2435 res.type = "circle";
2436 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2440 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2441 vml.canvas[appendChild](g);
2444 function rectPath(x, y, w, h, r) {
2446 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);
2448 return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
2451 theRect = function (vml, x, y, w, h, r) {
2452 var path = rectPath(x, y, w, h, r),
2453 res = vml.path(path),
2457 res.W = a.width = w;
2458 res.H = a.height = h;
2464 theEllipse = function (vml, x, y, rx, ry) {
2465 var g = createNode("group"),
2466 o = createNode("oval"),
2468 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2469 g.coordsize = coordsize;
2470 g.coordorigin = vml.coordorigin;
2472 var res = new Element(o, g, vml);
2473 res.type = "ellipse";
2474 setFillAndStroke(res, {stroke: "#000"});
2479 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2480 vml.canvas[appendChild](g);
2483 theImage = function (vml, src, x, y, w, h) {
2484 var g = createNode("group"),
2485 o = createNode("image");
2486 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2487 g.coordsize = coordsize;
2488 g.coordorigin = vml.coordorigin;
2491 var res = new Element(o, g, vml);
2493 res.attrs.src = src;
2498 res.setBox({x: x, y: y, width: w, height: h});
2499 vml.canvas[appendChild](g);
2502 theText = function (vml, x, y, text) {
2503 var g = createNode("group"),
2504 el = createNode("shape"),
2506 path = createNode("path"),
2508 o = createNode("textpath");
2509 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2510 g.coordsize = coordsize;
2511 g.coordorigin = vml.coordorigin;
2512 path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
2513 path.textpathok = true;
2514 ol.width = vml.width;
2515 ol.height = vml.height;
2516 o.string = Str(text);
2519 el[appendChild](path);
2521 var res = new Element(o, g, vml);
2523 res.textpath = path;
2525 res.attrs.text = text;
2530 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2532 vml.canvas[appendChild](g);
2535 setSize = function (width, height) {
2536 var cs = this.canvas.style;
2537 width == +width && (width += "px");
2538 height == +height && (height += "px");
2541 cs.clip = "rect(0 " + width + " " + height + " 0)";
2545 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2547 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2548 createNode = function (tagName) {
2549 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2552 createNode = function (tagName) {
2553 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2556 create = function () {
2557 var con = getContainer[apply](0, arguments),
2558 container = con.container,
2559 height = con.height,
2565 throw new Error("VML container not found.");
2567 var res = new Paper,
2568 c = res.canvas = doc.createElement("div"),
2572 width = width || 512;
2573 height = height || 342;
2574 width == +width && (width += "px");
2575 height == +height && (height += "px");
2578 res.coordsize = zoom * 1e3 + S + zoom * 1e3;
2579 res.coordorigin = "0 0";
2580 res.span = doc.createElement("span");
2581 res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2582 c[appendChild](res.span);
2583 cs.cssText = R.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
2584 if (container == 1) {
2585 doc.body[appendChild](c);
2588 cs.position = "absolute";
2590 if (container.firstChild) {
2591 container.insertBefore(c, container.firstChild);
2593 container[appendChild](c);
2596 plugins.call(res, res, R.fn);
2599 paperproto.clear = function () {
2600 this.canvas.innerHTML = E;
2601 this.span = doc.createElement("span");
2602 this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2603 this.canvas[appendChild](this.span);
2604 this.bottom = this.top = null;
2606 paperproto.remove = function () {
2607 this.canvas.parentNode.removeChild(this.canvas);
2608 for (var i in this) {
2609 this[i] = removed(i);
2616 // WebKit rendering bug workaround method
2617 var version = navigator.userAgent.match(/Version\/(.*?)\s/);
2618 if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP")) {
2619 paperproto.safari = function () {
2620 var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2621 win.setTimeout(function () {rect.remove();});
2624 paperproto.safari = function () {};
2628 var preventDefault = function () {
2629 this.returnValue = false;
2631 preventTouch = function () {
2632 return this.originalEvent.preventDefault();
2634 stopPropagation = function () {
2635 this.cancelBubble = true;
2637 stopTouch = function () {
2638 return this.originalEvent.stopPropagation();
2640 addEvent = (function () {
2641 if (doc.addEventListener) {
2642 return function (obj, type, fn, element) {
2643 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
2644 var f = function (e) {
2645 if (supportsTouch && touchMap[has](type)) {
2646 for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2647 if (e.targetTouches[i].target == obj) {
2649 e = e.targetTouches[i];
2650 e.originalEvent = olde;
2651 e.preventDefault = preventTouch;
2652 e.stopPropagation = stopTouch;
2657 return fn.call(element, e);
2659 obj.addEventListener(realName, f, false);
2660 return function () {
2661 obj.removeEventListener(realName, f, false);
2665 } else if (doc.attachEvent) {
2666 return function (obj, type, fn, element) {
2667 var f = function (e) {
2669 e.preventDefault = e.preventDefault || preventDefault;
2670 e.stopPropagation = e.stopPropagation || stopPropagation;
2671 return fn.call(element, e);
2673 obj.attachEvent("on" + type, f);
2674 var detacher = function () {
2675 obj.detachEvent("on" + type, f);
2683 dragMove = function (e) {
2686 scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2687 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft,
2692 if (supportsTouch) {
2693 var i = e.touches.length,
2696 touch = e.touches[i];
2697 if (touch.identifier == dragi.el._drag.id) {
2700 (e.originalEvent ? e.originalEvent : e).preventDefault();
2709 dragi.move && dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
2712 dragUp = function () {
2713 R.unmousemove(dragMove).unmouseup(dragUp);
2714 var i = drag.length,
2718 dragi.el._drag = {};
2719 dragi.end && dragi.end.call(dragi.el);
2723 for (var i = events[length]; i--;) {
2724 (function (eventName) {
2725 R[eventName] = Element[proto][eventName] = function (fn) {
2726 if (R.is(fn, "function")) {
2727 this.events = this.events || [];
2728 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
2732 R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
2733 var events = this.events,
2735 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2737 events.splice(l, 1);
2738 !events.length && delete this.events;
2745 elproto.hover = function (f_in, f_out) {
2746 return this.mouseover(f_in).mouseout(f_out);
2748 elproto.unhover = function (f_in, f_out) {
2749 return this.unmouseover(f_in).unmouseout(f_out);
2751 elproto.drag = function (onmove, onstart, onend) {
2753 this.mousedown(function (e) {
2754 (e.originalEvent || e).preventDefault();
2755 var scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2756 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft;
2757 this._drag.x = e.clientX + scrollX;
2758 this._drag.y = e.clientY + scrollY;
2759 this._drag.id = e.identifier;
2760 onstart && onstart.call(this, e.clientX + scrollX, e.clientY + scrollY);
2761 !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2762 drag.push({el: this, move: onmove, end: onend});
2766 elproto.undrag = function (onmove, onstart, onend) {
2767 var i = drag.length;
2769 drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i++, 1);
2771 !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2773 paperproto.circle = function (x, y, r) {
2774 return theCircle(this, x || 0, y || 0, r || 0);
2776 paperproto.rect = function (x, y, w, h, r) {
2777 return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2779 paperproto.ellipse = function (x, y, rx, ry) {
2780 return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2782 paperproto.path = function (pathString) {
2783 pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2784 return thePath(R.format[apply](R, arguments), this);
2786 paperproto.image = function (src, x, y, w, h) {
2787 return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2789 paperproto.text = function (x, y, text) {
2790 return theText(this, x || 0, y || 0, Str(text));
2792 paperproto.set = function (itemsArray) {
2793 arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2794 return new Set(itemsArray);
2796 paperproto.setSize = setSize;
2797 paperproto.top = paperproto.bottom = null;
2798 paperproto.raphael = R;
2800 return this.x + S + this.y;
2802 elproto.resetScale = function () {
2808 this.attrs.scale = "1 1";
2810 elproto.scale = function (x, y, cx, cy) {
2814 if (x == null && y == null) {
2829 var bb = this.getBBox(),
2830 rcx = bb.x + bb.width / 2,
2831 rcy = bb.y + bb.height / 2,
2832 kx = abs(x / this._.sx),
2833 ky = abs(y / this._.sy);
2834 cx = (+cx || cx == 0) ? cx : rcx;
2835 cy = (+cy || cy == 0) ? cy : rcy;
2836 var posx = this._.sx > 0,
2837 posy = this._.sy > 0,
2838 dirx = ~~(x / abs(x)),
2839 diry = ~~(y / abs(y)),
2842 s = this.node.style,
2843 ncx = cx + abs(rcx - cx) * dkx * (rcx > cx == posx ? 1 : -1),
2844 ncy = cy + abs(rcy - cy) * dky * (rcy > cy == posy ? 1 : -1),
2845 fr = (x * dirx > y * diry ? ky : kx);
2846 switch (this.type) {
2849 var neww = a.width * kx,
2850 newh = a.height * ky;
2876 var path = pathToRelative(a.path),
2878 fx = posx ? dkx : kx,
2879 fy = posy ? dky : ky;
2880 for (var i = 0, ii = path[length]; i < ii; i++) {
2882 P0 = upperCase.call(p[0]);
2883 if (P0 == "M" && skip) {
2889 p[path[i][length] - 2] *= fx;
2890 p[path[i][length] - 1] *= fy;
2893 p[5] = +(dirx + diry ? !+p[4] : !!+p[4]);
2894 } else if (P0 == "H") {
2895 for (var j = 1, jj = p[length]; j < jj; j++) {
2898 } else if (P0 == "V") {
2899 for (j = 1, jj = p[length]; j < jj; j++) {
2903 for (j = 1, jj = p[length]; j < jj; j++) {
2904 p[j] *= (j % 2) ? fx : fy;
2908 var dim2 = pathDimensions(path);
2909 dx = ncx - dim2.x - dim2.width / 2;
2910 dy = ncy - dim2.y - dim2.height / 2;
2913 this.attr({path: path});
2916 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2917 if (this.transformations) {
2918 this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2919 this.node[setAttribute]("transform", this.transformations[join](S));
2920 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2921 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2922 this.attr({x: dx, y: dy});
2926 this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
2927 ", M12=0, M21=0, M22=", diry,
2928 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2929 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2932 if (this.transformations) {
2933 this.transformations[2] = E;
2934 this.node[setAttribute]("transform", this.transformations[join](S));
2938 this.node.filterMatrix = E;
2939 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2942 a.scale = [x, y, cx, cy][join](S);
2948 elproto.clone = function () {
2952 var attr = this.attr();
2954 delete attr.translation;
2955 return this.paper[this.type]().attr(attr);
2957 var curveslengths = {},
2958 getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2961 name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2962 cache = curveslengths[name],
2964 !cache && (curveslengths[name] = cache = {data: []});
2965 cache.timer && clearTimeout(cache.timer);
2966 cache.timer = setTimeout(function () {delete curveslengths[name];}, 2000);
2967 if (length != null) {
2968 var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2969 precision = ~~total * 10;
2971 for (var i = 0; i < precision + 1; i++) {
2972 if (cache.data[length] > i) {
2973 dot = cache.data[i * precision];
2975 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
2976 cache.data[i] = dot;
2978 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2979 if (length != null && len >= length) {
2984 if (length == null) {
2988 getLengthFactory = function (istotal, subpath) {
2989 return function (path, length, onlystart) {
2990 path = path2curve(path);
2991 var x, y, p, l, sp = "", subpaths = {}, point,
2993 for (var i = 0, ii = path.length; i < ii; i++) {
2999 l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
3000 if (len + l > length) {
3001 if (subpath && !subpaths.start) {
3002 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3003 sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
3004 if (onlystart) {return sp;}
3005 subpaths.start = sp;
3006 sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
3012 if (!istotal && !subpath) {
3013 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3014 return {x: point.x, y: point.y, alpha: point.alpha};
3024 point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
3025 point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
3029 var getTotalLength = getLengthFactory(1),
3030 getPointAtLength = getLengthFactory(),
3031 getSubpathsAtLength = getLengthFactory(0, 1);
3032 elproto.getTotalLength = function () {
3033 if (this.type != "path") {return;}
3034 if (this.node.getTotalLength) {
3035 return this.node.getTotalLength();
3037 return getTotalLength(this.attrs.path);
3039 elproto.getPointAtLength = function (length) {
3040 if (this.type != "path") {return;}
3041 return getPointAtLength(this.attrs.path, length);
3043 elproto.getSubpath = function (from, to) {
3044 if (this.type != "path") {return;}
3045 if (abs(this.getTotalLength() - to) < "1e-6") {
3046 return getSubpathsAtLength(this.attrs.path, from).end;
3048 var a = getSubpathsAtLength(this.attrs.path, to, 1);
3049 return from ? getSubpathsAtLength(a, from).end : a;
3052 // animation easing formulas
3053 R.easing_formulas = {
3054 linear: function (n) {
3061 return pow(n - 1, 3) + 1;
3063 "<>": function (n) {
3066 return pow(n, 3) / 2;
3069 return (pow(n, 3) + 2) / 2;
3071 backIn: function (n) {
3073 return n * n * ((s + 1) * n - s);
3075 backOut: function (n) {
3078 return n * n * ((s + 1) * n + s) + 1;
3080 elastic: function (n) {
3081 if (n == 0 || n == 1) {
3086 return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
3088 bounce: function (n) {
3097 l = s * n * n + .75;
3099 if (n < (2.5 / p)) {
3101 l = s * n * n + .9375;
3104 l = s * n * n + .984375;
3112 var animationElements = [],
3113 animation = function () {
3114 var Now = +new Date;
3115 for (var l = 0; l < animationElements[length]; l++) {
3116 var e = animationElements[l];
3117 if (e.stop || e.el.removed) {
3120 var time = Now - e.start,
3131 var pos = easing(time / ms);
3132 for (var attr in from) if (from[has](attr)) {
3133 switch (availableAnimAttrs[attr]) {
3135 now = pos * ms * diff[attr];
3136 to.back && (now = to.len - now);
3137 var point = getPointAtLength(to[attr], now);
3138 that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
3141 that.translate(point.x - diff.sx, point.y - diff.sy);
3142 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3145 now = +from[attr] + pos * ms * diff[attr];
3149 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3150 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3151 upto255(round(from[attr].b + pos * ms * diff[attr].b))
3156 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3157 now[i] = [from[attr][i][0]];
3158 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3159 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3161 now[i] = now[i][join](S);
3168 var x = pos * ms * diff[attr][0] - t.x,
3169 y = pos * ms * diff[attr][1] - t.y;
3175 now = +from[attr][0] + pos * ms * diff[attr][0];
3176 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
3179 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);
3185 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3191 var from2 = [].concat(from[attr]);
3193 i = that.paper.customAttributes[attr].length;
3195 now[i] = +from2[i] + pos * ms * diff[attr][i];
3202 that._run && that._run.call(that);
3205 point = getPointAtLength(to.along, to.len * !to.back);
3206 that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
3207 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3209 (t.x || t.y) && that.translate(-t.x, -t.y);
3210 to.scale && (to.scale += E);
3212 animationElements.splice(l--, 1);
3215 R.svg && that && that.paper && that.paper.safari();
3216 animationElements[length] && setTimeout(animation);
3218 keyframesRun = function (attr, element, time, prev, prevcallback) {
3219 var dif = time - prev;
3220 element.timeouts.push(setTimeout(function () {
3221 R.is(prevcallback, "function") && prevcallback.call(element);
3222 element.animate(attr, dif, attr.easing);
3225 upto255 = function (color) {
3226 return mmax(mmin(color, 255), 0);
3228 translate = function (x, y) {
3230 return {x: this._.tx, y: this._.ty, toString: x_y};
3234 switch (this.type) {
3237 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
3242 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
3245 var path = pathToRelative(this.attrs.path);
3248 this.attr({path: path});
3253 elproto.animateWith = function (element, params, ms, easing, callback) {
3254 for (var i = 0, ii = animationElements.length; i < ii; i++) {
3255 if (animationElements[i].el.id == element.id) {
3256 params.start = animationElements[i].start;
3259 return this.animate(params, ms, easing, callback);
3261 elproto.animateAlong = along();
3262 elproto.animateAlongBack = along(1);
3263 function along(isBack) {
3264 return function (path, ms, rotate, callback) {
3265 var params = {back: isBack};
3266 R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
3267 path && path.constructor == Element && (path = path.attrs.path);
3268 path && (params.along = path);
3269 return this.animate(params, ms, callback);
3272 function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
3274 bx = 3 * (p2x - p1x) - cx,
3277 by = 3 * (p2y - p1y) - cy,
3279 function sampleCurveX(t) {
3280 return ((ax * t + bx) * t + cx) * t;
3282 function solve(x, epsilon) {
3283 var t = solveCurveX(x, epsilon);
3284 return ((ay * t + by) * t + cy) * t;
3286 function solveCurveX(x, epsilon) {
3287 var t0, t1, t2, x2, d2, i;
3288 for(t2 = x, i = 0; i < 8; i++) {
3289 x2 = sampleCurveX(t2) - x;
3290 if (abs(x2) < epsilon) {
3293 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
3294 if (abs(d2) < 1e-6) {
3309 x2 = sampleCurveX(t2);
3310 if (abs(x2 - x) < epsilon) {
3318 t2 = (t1 - t0) / 2 + t0;
3322 return solve(t, 1 / (200 * duration));
3324 elproto.onAnimation = function (f) {
3328 elproto.animate = function (params, ms, easing, callback) {
3330 element.timeouts = element.timeouts || [];
3331 if (R.is(easing, "function") || !easing) {
3332 callback = easing || null;
3334 if (element.removed) {
3335 callback && callback.call(element);
3340 animateable = false,
3342 for (var attr in params) if (params[has](attr)) {
3343 if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
3345 from[attr] = element.attr(attr);
3346 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3347 to[attr] = params[attr];
3348 switch (availableAnimAttrs[attr]) {
3350 var len = getTotalLength(params[attr]);
3351 var point = getPointAtLength(params[attr], len * !!params.back);
3352 var bb = element.getBBox();
3353 diff[attr] = len / ms;
3358 to.rot = params.rot;
3359 to.back = params.back;
3361 params.rot && (diff.r = toFloat(element.rotate()) || 0);
3364 diff[attr] = (to[attr] - from[attr]) / ms;
3367 from[attr] = R.getRGB(from[attr]);
3368 var toColour = R.getRGB(to[attr]);
3370 r: (toColour.r - from[attr].r) / ms,
3371 g: (toColour.g - from[attr].g) / ms,
3372 b: (toColour.b - from[attr].b) / ms
3376 var pathes = path2curve(from[attr], to[attr]);
3377 from[attr] = pathes[0];
3378 var toPath = pathes[1];
3380 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3381 diff[attr][i] = [0];
3382 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3383 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3388 var values = Str(params[attr])[split](separator),
3389 from2 = Str(from[attr])[split](separator);
3392 from[attr] = [0, 0];
3393 diff[attr] = [values[0] / ms, values[1] / ms];
3396 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
3397 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
3400 params[attr] = values;
3401 from[attr] = Str(from[attr])[split](separator);
3402 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
3405 from[attr] = Str(from[attr])[split](separator);
3409 diff[attr][i] = (values[i] - from[attr][i]) / ms;
3416 values = [].concat(params[attr]);
3417 from2 = [].concat(from[attr]);
3419 i = element.paper.customAttributes[attr][length];
3421 diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
3430 for (var key in params) if (params[has](key) && animKeyFrames.test(key)) {
3431 attr = {value: params[key]};
3432 key == "from" && (key = 0);
3433 key == "to" && (key = 100);
3434 attr.key = toInt(key, 10);
3437 attrs.sort(sortByKey);
3439 attrs.unshift({key: 0, value: element.attrs});
3441 for (i = 0, ii = attrs[length]; i < ii; i++) {
3442 keyframesRun(attrs[i].value, element, ms / 100 * attrs[i].key, ms / 100 * (attrs[i - 1] && attrs[i - 1].key || 0), attrs[i - 1] && attrs[i - 1].value.callback);
3444 lastcall = attrs[attrs[length] - 1].value.callback;
3446 element.timeouts.push(setTimeout(function () {lastcall.call(element);}, ms));
3449 var easyeasy = R.easing_formulas[easing];
3451 easyeasy = Str(easing).match(bezierrg);
3452 if (easyeasy && easyeasy[length] == 5) {
3453 var curve = easyeasy;
3454 easyeasy = function (t) {
3455 return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
3458 easyeasy = function (t) {
3463 animationElements.push({
3464 start: params.start || +new Date,
3473 R.is(callback, "function") && (element._ac = setTimeout(function () {
3474 callback.call(element);
3476 animationElements[length] == 1 && setTimeout(animation);
3480 elproto.stop = function () {
3481 for (var i = 0; i < animationElements.length; i++) {
3482 animationElements[i].el.id == this.id && animationElements.splice(i--, 1);
3484 for (i = 0, ii = this.timeouts && this.timeouts.length; i < ii; i++) {
3485 clearTimeout(this.timeouts[i]);
3488 clearTimeout(this._ac);
3492 elproto.translate = function (x, y) {
3493 return this.attr({translation: x + " " + y});
3495 elproto[toString] = function () {
3496 return "Rapha\xebl\u2019s object";
3498 R.ae = animationElements;
3501 var Set = function (items) {
3506 for (var i = 0, ii = items[length]; i < ii; i++) {
3507 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
3508 this[this.items[length]] = this.items[this.items[length]] = items[i];
3514 Set[proto][push] = function () {
3517 for (var i = 0, ii = arguments[length]; i < ii; i++) {
3518 item = arguments[i];
3519 if (item && (item.constructor == Element || item.constructor == Set)) {
3520 len = this.items[length];
3521 this[len] = this.items[len] = item;
3527 Set[proto].pop = function () {
3528 delete this[this[length]--];
3529 return this.items.pop();
3531 for (var method in elproto) if (elproto[has](method)) {
3532 Set[proto][method] = (function (methodname) {
3533 return function () {
3534 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3535 this.items[i][methodname][apply](this.items[i], arguments);
3541 Set[proto].attr = function (name, value) {
3542 if (name && R.is(name, array) && R.is(name[0], "object")) {
3543 for (var j = 0, jj = name[length]; j < jj; j++) {
3544 this.items[j].attr(name[j]);
3547 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3548 this.items[i].attr(name, value);
3553 Set[proto].animate = function (params, ms, easing, callback) {
3554 (R.is(easing, "function") || !easing) && (callback = easing || null);
3555 var len = this.items[length],
3560 callback && (collector = function () {
3561 !--len && callback.call(set);
3563 easing = R.is(easing, string) ? easing : collector;
3564 item = this.items[--i].animate(params, ms, easing, collector);
3566 this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, params, ms, easing, collector);
3570 Set[proto].insertAfter = function (el) {
3571 var i = this.items[length];
3573 this.items[i].insertAfter(el);
3577 Set[proto].getBBox = function () {
3582 for (var i = this.items[length]; i--;) {
3583 var box = this.items[i].getBBox();
3586 w[push](box.x + box.width);
3587 h[push](box.y + box.height);
3589 x = mmin[apply](0, x);
3590 y = mmin[apply](0, y);
3594 width: mmax[apply](0, w) - x,
3595 height: mmax[apply](0, h) - y
3598 Set[proto].clone = function (s) {
3600 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3601 s[push](this.items[i].clone());
3606 R.registerFont = function (font) {
3610 this.fonts = this.fonts || {};
3616 family = font.face["font-family"];
3617 for (var prop in font.face) if (font.face[has](prop)) {
3618 fontcopy.face[prop] = font.face[prop];
3620 if (this.fonts[family]) {
3621 this.fonts[family][push](fontcopy);
3623 this.fonts[family] = [fontcopy];
3626 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3627 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3628 var path = font.glyphs[glyph];
3629 fontcopy.glyphs[glyph] = {
3632 d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3633 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3637 for (var k in path.k) if (path[has](k)) {
3638 fontcopy.glyphs[glyph].k[k] = path.k[k];
3645 paperproto.getFont = function (family, weight, style, stretch) {
3646 stretch = stretch || "normal";
3647 style = style || "normal";
3648 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3652 var font = R.fonts[family];
3654 var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3655 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3656 if (name.test(fontName)) {
3657 font = R.fonts[fontName];
3664 for (var i = 0, ii = font[length]; i < ii; i++) {
3666 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3673 paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3674 origin = origin || "middle"; // baseline|middle
3675 letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3676 var out = this.set(),
3677 letters = Str(string)[split](E),
3681 R.is(font, string) && (font = this.getFont(font));
3683 scale = (size || 16) / font.face["units-per-em"];
3684 var bb = font.face.bbox.split(separator),
3686 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3687 for (var i = 0, ii = letters[length]; i < ii; i++) {
3688 var prev = i && font.glyphs[letters[i - 1]] || {},
3689 curr = font.glyphs[letters[i]];
3690 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3691 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3693 out.scale(scale, scale, top, height).translate(x - top, y - height);
3698 R.format = function (token, params) {
3699 var args = R.is(params, array) ? [0][concat](params) : arguments;
3700 token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
3701 return args[++i] == null ? E : args[i];
3705 R.ninja = function () {
3706 oldRaphael.was ? (win.Raphael = oldRaphael.is) : delete Raphael;
3712 oldRaphael.was ? (win.Raphael = R) : (Raphael = R);