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": 1, "Infinity": 1, "-Infinity": 1},
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[has](+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 = R.is(tolerance, "finite") ? tolerance : 10;
134 if (R.is(values, array)) {
135 var i = values.length;
136 while (i--) if (abs(values[i] - value) <= tolerance) {
141 var rem = value % values;
142 if (rem < tolerance) {
145 if (rem > values - tolerance) {
146 return value - rem + values;
151 function createUUID() {
152 // http://www.ietf.org/rfc/rfc4122.txt
155 for (; i < 32; i++) {
156 s[i] = (~~(math.random() * 16))[toString](16);
158 s[12] = 4; // bits 12-15 of the time_hi_and_version field to 0010
159 s[16] = ((s[16] & 3) | 8)[toString](16); // bits 6-7 of the clock_seq_hi_and_reserved to 01
160 return "r-" + s[join]("");
163 R.setWindow = function (newwin) {
168 var toHex = function (color) {
170 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
171 var trim = /^\s+|\s+$/g;
174 var docum = new ActiveXObject("htmlfile");
175 docum.write("<body>");
179 bod = createPopup().document.body;
181 var range = bod.createTextRange();
182 toHex = cacher(function (color) {
184 bod.style.color = Str(color)[rp](trim, E);
185 var value = range.queryCommandValue("ForeColor");
186 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
187 return "#" + ("000000" + value[toString](16)).slice(-6);
193 var i = doc.createElement("i");
194 i.title = "Rapha\xebl Colour Picker";
195 i.style.display = "none";
196 doc.body[appendChild](i);
197 toHex = cacher(function (color) {
198 i.style.color = color;
199 return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
204 hsbtoString = function () {
205 return "hsb(" + [this.h, this.s, this.b] + ")";
207 hsltoString = function () {
208 return "hsl(" + [this.h, this.s, this.l] + ")";
210 rgbtoString = function () {
213 R.hsb2rgb = function (h, s, b) {
214 if (R.is(h, "object") && "h" in h && "s" in h && "b" in h) {
219 return R.hsl2rgb(h, s, b / 2);
221 R.hsl2rgb = function (h, s, l) {
222 if (R.is(h, "object") && "h" in h && "s" in h && "l" in h) {
227 if (h > 1 || s > 1 || l > 1) {
233 channels = ["r", "g", "b"],
248 for (var i = 0, ii = channels.length; i < ii; i++) {
249 t3 = h + 1 / 3 * -(i - 1);
253 rgb[channels[i]] = t1 + (t2 - t1) * 6 * t3;
254 } else if (t3 * 2 < 1) {
255 rgb[channels[i]] = t2;
256 } else if (t3 * 3 < 2) {
257 rgb[channels[i]] = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
259 rgb[channels[i]] = t1;
266 r = (~~rgb.r)[toString](16);
267 g = (~~rgb.g)[toString](16);
268 b = (~~rgb.b)[toString](16);
272 rgb.hex = "#" + r + g + b;
273 rgb.toString = rgbtoString;
276 R.rgb2hsb = function (red, green, blue) {
277 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
282 if (green == null && R.is(red, string)) {
283 var clr = R.getRGB(red);
288 if (red > 1 || green > 1 || blue > 1) {
293 var max = mmax(red, green, blue),
294 min = mmin(red, green, blue),
299 return {h: 0, s: 0, b: max, toString: hsbtoString};
301 var delta = (max - min);
302 saturation = delta / max;
304 hue = (green - blue) / delta;
305 } else if (green == max) {
306 hue = 2 + ((blue - red) / delta);
308 hue = 4 + ((red - green) / delta);
314 return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
316 R.rgb2hsl = function (red, green, blue) {
317 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
322 if (green == null && R.is(red, string)) {
323 var clr = R.getRGB(red);
328 if (red > 1 || green > 1 || blue > 1) {
333 var max = mmax(red, green, blue),
334 min = mmin(red, green, blue),
340 hsl = {h: 0, s: 0, l: l};
342 var delta = max - min;
343 s = l < .5 ? delta / (max + min) : delta / (2 - max - min);
345 h = (green - blue) / delta;
346 } else if (green == max) {
347 h = 2 + (blue - red) / delta;
349 h = 4 + (red - green) / delta;
354 hsl = {h: h, s: s, l: l};
356 hsl.toString = hsltoString;
359 R._path2string = function () {
360 return this.join(",")[rp](p2s, "$1");
362 function cacher(f, scope, postprocessor) {
364 var arg = Array[proto].slice.call(arguments, 0),
365 args = arg[join]("\u25ba"),
366 cache = newf.cache = newf.cache || {},
367 count = newf.count = newf.count || [];
368 if (cache[has](args)) {
369 return postprocessor ? postprocessor(cache[args]) : cache[args];
371 count[length] >= 1e3 && delete cache[count.shift()];
373 cache[args] = f[apply](scope, arg);
374 return postprocessor ? postprocessor(cache[args]) : cache[args];
379 R.getRGB = cacher(function (colour) {
380 if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
381 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
383 if (colour == "none") {
384 return {r: -1, g: -1, b: -1, hex: "none"};
386 !(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
393 rgb = colour.match(colourRegExp);
396 blue = toInt(rgb[2].substring(5), 16);
397 green = toInt(rgb[2].substring(3, 5), 16);
398 red = toInt(rgb[2].substring(1, 3), 16);
401 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
402 green = toInt((t = rgb[3].charAt(2)) + t, 16);
403 red = toInt((t = rgb[3].charAt(1)) + t, 16);
406 rgb = rgb[4][split](commaSpaces);
407 red = toFloat(rgb[0]);
408 green = toFloat(rgb[1]);
409 blue = toFloat(rgb[2]);
410 opacity = toFloat(rgb[3]);
413 rgb = rgb[5][split](commaSpaces);
414 red = toFloat(rgb[0]) * 2.55;
415 green = toFloat(rgb[1]) * 2.55;
416 blue = toFloat(rgb[2]) * 2.55;
417 opacity = toFloat(rgb[3]);
420 rgb = rgb[6][split](commaSpaces);
421 red = toFloat(rgb[0]);
422 green = toFloat(rgb[1]);
423 blue = toFloat(rgb[2]);
424 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
425 return R.hsb2rgb(red, green, blue);
428 rgb = rgb[7][split](commaSpaces);
429 red = toFloat(rgb[0]) * 2.55;
430 green = toFloat(rgb[1]) * 2.55;
431 blue = toFloat(rgb[2]) * 2.55;
432 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
433 return R.hsb2rgb(red, green, blue);
436 rgb = rgb[8][split](commaSpaces);
437 red = toFloat(rgb[0]);
438 green = toFloat(rgb[1]);
439 blue = toFloat(rgb[2]);
440 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
441 return R.hsl2rgb(red, green, blue);
444 rgb = rgb[9][split](commaSpaces);
445 red = toFloat(rgb[0]) * 2.55;
446 green = toFloat(rgb[1]) * 2.55;
447 blue = toFloat(rgb[2]) * 2.55;
448 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
449 return R.hsl2rgb(red, green, blue);
451 rgb = {r: red, g: green, b: blue};
452 var r = (~~red)[toString](16),
453 g = (~~green)[toString](16),
454 b = (~~blue)[toString](16);
458 rgb.hex = "#" + r + g + b;
459 isFinite(toFloat(opacity)) && (rgb.o = opacity);
462 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
464 R.getColor = function (value) {
465 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
466 rgb = this.hsb2rgb(start.h, start.s, start.b);
471 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
475 R.getColor.reset = function () {
479 R.parsePathString = cacher(function (pathString) {
483 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
485 if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
486 data = pathClone(pathString);
489 Str(pathString)[rp](pathCommand, function (a, b, c) {
491 name = lowerCase.call(b);
492 c[rp](pathValues, function (a, b) {
493 b && params[push](+b);
495 if (name == "m" && params[length] > 2) {
496 data[push]([b][concat](params.splice(0, 2)));
498 b = b == "m" ? "l" : "L";
500 while (params[length] >= paramCounts[name]) {
501 data[push]([b][concat](params.splice(0, paramCounts[name])));
502 if (!paramCounts[name]) {
508 data[toString] = R._path2string;
511 R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
513 x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
514 y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
515 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
516 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
517 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
518 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
519 ax = (1 - t) * p1x + t * c1x,
520 ay = (1 - t) * p1y + t * c1y,
521 cx = (1 - t) * c2x + t * p2x,
522 cy = (1 - t) * c2y + t * p2y,
523 alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
524 (mx > nx || my < ny) && (alpha += 180);
525 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};
527 var pathDimensions = cacher(function (path) {
529 return {x: 0, y: 0, width: 0, height: 0};
531 path = path2curve(path);
537 for (var i = 0, ii = path[length]; i < ii; i++) {
545 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
546 X = X[concat](dim.min.x, dim.max.x);
547 Y = Y[concat](dim.min.y, dim.max.y);
552 var xmin = mmin[apply](0, X),
553 ymin = mmin[apply](0, Y);
557 width: mmax[apply](0, X) - xmin,
558 height: mmax[apply](0, Y) - ymin
561 pathClone = function (pathArray) {
563 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
564 pathArray = R.parsePathString(pathArray);
566 for (var i = 0, ii = pathArray[length]; i < ii; i++) {
568 for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
569 res[i][j] = pathArray[i][j];
572 res[toString] = R._path2string;
575 pathToRelative = cacher(function (pathArray) {
576 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
577 pathArray = R.parsePathString(pathArray);
585 if (pathArray[0][0] == "M") {
591 res[push](["M", x, y]);
593 for (var i = start, ii = pathArray[length]; i < ii; i++) {
596 if (pa[0] != lowerCase.call(pa[0])) {
597 r[0] = lowerCase.call(pa[0]);
605 r[6] = +(pa[6] - x).toFixed(3);
606 r[7] = +(pa[7] - y).toFixed(3);
609 r[1] = +(pa[1] - y).toFixed(3);
615 for (var j = 1, jj = pa[length]; j < jj; j++) {
616 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
625 for (var k = 0, kk = pa[length]; k < kk; k++) {
629 var len = res[i][length];
636 x += +res[i][len - 1];
639 y += +res[i][len - 1];
642 x += +res[i][len - 2];
643 y += +res[i][len - 1];
646 res[toString] = R._path2string;
649 pathToAbsolute = cacher(function (pathArray) {
650 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
651 pathArray = R.parsePathString(pathArray);
659 if (pathArray[0][0] == "M") {
660 x = +pathArray[0][1];
661 y = +pathArray[0][2];
665 res[0] = ["M", x, y];
667 for (var i = start, ii = pathArray[length]; i < ii; i++) {
670 if (pa[0] != upperCase.call(pa[0])) {
671 r[0] = upperCase.call(pa[0]);
692 for (var j = 1, jj = pa[length]; j < jj; j++) {
693 r[j] = +pa[j] + ((j % 2) ? x : y);
697 for (var k = 0, kk = pa[length]; k < kk; k++) {
713 mx = res[i][res[i][length] - 2];
714 my = res[i][res[i][length] - 1];
716 x = res[i][res[i][length] - 2];
717 y = res[i][res[i][length] - 1];
720 res[toString] = R._path2string;
723 l2c = function (x1, y1, x2, y2) {
724 return [x1, y1, x2, y2, x2, y2];
726 q2c = function (x1, y1, ax, ay, x2, y2) {
738 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
739 // for more information of where this math came from visit:
740 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
742 _120 = PI * 120 / 180,
743 rad = PI / 180 * (+angle || 0),
746 rotate = cacher(function (x, y, rad) {
747 var X = x * math.cos(rad) - y * math.sin(rad),
748 Y = x * math.sin(rad) + y * math.cos(rad);
752 xy = rotate(x1, y1, -rad);
755 xy = rotate(x2, y2, -rad);
758 var cos = math.cos(PI / 180 * angle),
759 sin = math.sin(PI / 180 * angle),
762 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
770 k = (large_arc_flag == sweep_flag ? -1 : 1) *
771 math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
772 cx = k * rx * y / ry + (x1 + x2) / 2,
773 cy = k * -ry * x / rx + (y1 + y2) / 2,
774 f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
775 f2 = math.asin(((y2 - cy) / ry).toFixed(9));
777 f1 = x1 < cx ? PI - f1 : f1;
778 f2 = x2 < cx ? PI - f2 : f2;
779 f1 < 0 && (f1 = PI * 2 + f1);
780 f2 < 0 && (f2 = PI * 2 + f2);
781 if (sweep_flag && f1 > f2) {
784 if (!sweep_flag && f2 > f1) {
794 if (abs(df) > _120) {
798 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
799 x2 = cx + rx * math.cos(f2);
800 y2 = cy + ry * math.sin(f2);
801 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
804 var c1 = math.cos(f1),
808 t = math.tan(df / 4),
812 m2 = [x1 + hx * s1, y1 - hy * c1],
813 m3 = [x2 + hx * s2, y2 - hy * c2],
815 m2[0] = 2 * m1[0] - m2[0];
816 m2[1] = 2 * m1[1] - m2[1];
818 return [m2, m3, m4][concat](res);
820 res = [m2, m3, m4][concat](res)[join]()[split](",");
822 for (var i = 0, ii = res[length]; i < ii; i++) {
823 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
828 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
831 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
832 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
835 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
836 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
837 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
839 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
840 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
844 abs(t1) > "1e12" && (t1 = .5);
845 abs(t2) > "1e12" && (t2 = .5);
846 if (t1 > 0 && t1 < 1) {
847 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
851 if (t2 > 0 && t2 < 1) {
852 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
856 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
857 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
859 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
860 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
861 abs(t1) > "1e12" && (t1 = .5);
862 abs(t2) > "1e12" && (t2 = .5);
863 if (t1 > 0 && t1 < 1) {
864 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
868 if (t2 > 0 && t2 < 1) {
869 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
874 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
875 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
878 path2curve = cacher(function (path, path2) {
879 var p = pathToAbsolute(path),
880 p2 = path2 && pathToAbsolute(path2),
881 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
882 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
883 processPath = function (path, d) {
886 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
888 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
895 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
898 nx = d.x + (d.x - (d.bx || d.x));
899 ny = d.y + (d.y - (d.by || d.y));
900 path = ["C", nx, ny][concat](path.slice(1));
903 d.qx = d.x + (d.x - (d.qx || d.x));
904 d.qy = d.y + (d.y - (d.qy || d.y));
905 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
910 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
913 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
916 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
919 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
922 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
927 fixArc = function (pp, i) {
928 if (pp[i][length] > 7) {
932 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
935 ii = mmax(p[length], p2 && p2[length] || 0);
938 fixM = function (path1, path2, a1, a2, i) {
939 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
940 path2.splice(i, 0, ["M", a2.x, a2.y]);
945 ii = mmax(p[length], p2 && p2[length] || 0);
948 for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
949 p[i] = processPath(p[i], attrs);
951 p2 && (p2[i] = processPath(p2[i], attrs2));
953 fixM(p, p2, attrs, attrs2, i);
954 fixM(p2, p, attrs2, attrs, i);
957 seglen = seg[length],
958 seg2len = p2 && seg2[length];
959 attrs.x = seg[seglen - 2];
960 attrs.y = seg[seglen - 1];
961 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
962 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
963 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
964 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
965 attrs2.x = p2 && seg2[seg2len - 2];
966 attrs2.y = p2 && seg2[seg2len - 1];
968 return p2 ? [p, p2] : p;
970 parseDots = cacher(function (gradient) {
972 for (var i = 0, ii = gradient[length]; i < ii; i++) {
974 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
975 dot.color = R.getRGB(par[1]);
976 if (dot.color.error) {
979 dot.color = dot.color.hex;
980 par[2] && (dot.offset = par[2] + "%");
983 for (i = 1, ii = dots[length] - 1; i < ii; i++) {
984 if (!dots[i].offset) {
985 var start = toFloat(dots[i - 1].offset || 0),
987 for (var j = i + 1; j < ii; j++) {
988 if (dots[j].offset) {
989 end = dots[j].offset;
998 var d = (end - start) / (j - i + 1);
1001 dots[i].offset = start + "%";
1007 getContainer = function (x, y, w, h) {
1009 if (R.is(x, string) || R.is(x, "object")) {
1010 container = R.is(x, string) ? doc.getElementById(x) : x;
1011 if (container.tagName) {
1014 container: container,
1015 width: container.style.pixelWidth || container.offsetWidth,
1016 height: container.style.pixelHeight || container.offsetHeight
1019 return {container: container, width: y, height: w};
1023 return {container: 1, x: x, y: y, width: w, height: h};
1026 plugins = function (con, add) {
1028 for (var prop in add) {
1029 if (add[has](prop) && !(prop in con)) {
1030 switch (typeof add[prop]) {
1033 con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
1037 con[prop] = con[prop] || {};
1038 plugins.call(this, con[prop], add[prop]);
1041 con[prop] = add[prop];
1047 tear = function (el, paper) {
1048 el == paper.top && (paper.top = el.prev);
1049 el == paper.bottom && (paper.bottom = el.next);
1050 el.next && (el.next.prev = el.prev);
1051 el.prev && (el.prev.next = el.next);
1053 tofront = function (el, paper) {
1054 if (paper.top === el) {
1059 el.prev = paper.top;
1060 paper.top.next = el;
1063 toback = function (el, paper) {
1064 if (paper.bottom === el) {
1068 el.next = paper.bottom;
1070 paper.bottom.prev = el;
1073 insertafter = function (el, el2, paper) {
1075 el2 == paper.top && (paper.top = el);
1076 el2.next && (el2.next.prev = el);
1081 insertbefore = function (el, el2, paper) {
1083 el2 == paper.bottom && (paper.bottom = el);
1084 el2.prev && (el2.prev.next = el);
1089 removed = function (methodname) {
1090 return function () {
1091 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1094 radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
1095 R.pathToRelative = pathToRelative;
1098 paperproto.svgns = "http://www.w3.org/2000/svg";
1099 paperproto.xlink = "http://www.w3.org/1999/xlink";
1100 round = function (num) {
1101 return +num + (~~num === num) * .5;
1103 var $ = function (el, attr) {
1105 for (var key in attr) {
1106 if (attr[has](key)) {
1107 el[setAttribute](key, Str(attr[key]));
1111 el = doc.createElementNS(paperproto.svgns, el);
1112 el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
1116 R[toString] = function () {
1117 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
1119 var thePath = function (pathString, SVG) {
1121 SVG.canvas && SVG.canvas[appendChild](el);
1122 var p = new Element(el, SVG);
1124 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
1127 var addGradientFill = function (o, gradient, SVG) {
1128 var type = "linear",
1131 gradient = Str(gradient)[rp](radial_gradient, function (all, _fx, _fy) {
1136 var dir = ((fy > .5) * 2 - 1);
1137 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
1138 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
1140 (fy = fy.toFixed(5) - 1e-5 * dir);
1144 gradient = gradient[split](/\s*\-\s*/);
1145 if (type == "linear") {
1146 var angle = gradient.shift();
1147 angle = -toFloat(angle);
1151 var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
1152 max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
1155 if (vector[2] < 0) {
1156 vector[0] = -vector[2];
1159 if (vector[3] < 0) {
1160 vector[1] = -vector[3];
1164 var dots = parseDots(gradient);
1168 var id = o.getAttribute(fillString);
1169 id = id.match(/^url\(#(.*)\)$/);
1170 id && SVG.defs.removeChild(doc.getElementById(id[1]));
1172 var el = $(type + "Gradient");
1173 el.id = createUUID();
1174 $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
1175 SVG.defs[appendChild](el);
1176 for (var i = 0, ii = dots[length]; i < ii; i++) {
1177 var stop = $("stop");
1179 offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
1180 "stop-color": dots[i].color || "#fff"
1182 el[appendChild](stop);
1185 fill: "url(#" + el.id + ")",
1194 var updatePosition = function (o) {
1195 var bbox = o.getBBox();
1196 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
1198 var setFillAndStroke = function (o, params) {
1205 "-..": [3, 1, 1, 1, 1, 1],
1209 "- .": [4, 3, 1, 3],
1210 "--.": [8, 3, 1, 3],
1211 "--..": [8, 3, 1, 3, 1, 3]
1216 addDashes = function (o, value) {
1217 value = dasharray[lowerCase.call(value)];
1219 var width = o.attrs["stroke-width"] || "1",
1220 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1222 var i = value[length];
1224 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
1226 $(node, {"stroke-dasharray": dashes[join](",")});
1229 params[has]("rotation") && (rot = params.rotation);
1230 var rotxy = Str(rot)[split](separator);
1231 if (!(rotxy.length - 1)) {
1234 rotxy[1] = +rotxy[1];
1235 rotxy[2] = +rotxy[2];
1237 toFloat(rot) && o.rotate(0, true);
1238 for (var att in params) {
1239 if (params[has](att)) {
1240 if (!availableAttrs[has](att)) {
1243 var value = params[att];
1250 o.rotate(value, true);
1255 var pn = node.parentNode;
1256 if (lowerCase.call(pn.tagName) != "a") {
1258 pn.insertBefore(hl, node);
1259 hl[appendChild](node);
1262 if (att == "target" && value == "blank") {
1263 pn.setAttributeNS(o.paper.xlink, "show", "new");
1265 pn.setAttributeNS(o.paper.xlink, att, value);
1269 node.style.cursor = value;
1272 var rect = Str(value)[split](separator);
1273 if (rect[length] == 4) {
1274 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
1275 var el = $("clipPath"),
1277 el.id = createUUID();
1284 el[appendChild](rc);
1285 o.paper.defs[appendChild](el);
1286 $(node, {"clip-path": "url(#" + el.id + ")"});
1290 var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
1291 clip && clip.parentNode.removeChild(clip);
1292 $(node, {"clip-path": E});
1297 if (o.type == "path") {
1298 $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
1302 node[setAttribute](att, value);
1311 value = -attrs.x - (attrs.width || 0);
1314 if (att == "rx" && o.type == "rect") {
1318 rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
1319 node[setAttribute](att, value);
1320 o.pattern && updatePosition(o);
1323 node[setAttribute](att, value);
1332 value = -attrs.y - (attrs.height || 0);
1335 if (att == "ry" && o.type == "rect") {
1339 rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
1340 node[setAttribute](att, value);
1341 o.pattern && updatePosition(o);
1344 if (o.type == "rect") {
1345 $(node, {rx: value, ry: value});
1347 node[setAttribute](att, value);
1351 if (o.type == "image") {
1352 node.setAttributeNS(o.paper.xlink, "href", value);
1355 case "stroke-width":
1356 node.style.strokeWidth = value;
1357 // Need following line for Firefox
1358 node[setAttribute](att, value);
1359 if (attrs["stroke-dasharray"]) {
1360 addDashes(o, attrs["stroke-dasharray"]);
1363 case "stroke-dasharray":
1364 addDashes(o, value);
1367 var xy = Str(value)[split](separator);
1368 xy[0] = +xy[0] || 0;
1369 xy[1] = +xy[1] || 0;
1374 translate.call(o, xy[0], xy[1]);
1377 xy = Str(value)[split](separator);
1378 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
1381 var isURL = Str(value).match(ISURL);
1384 var ig = $("image");
1385 el.id = createUUID();
1386 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
1387 $(ig, {x: 0, y: 0});
1388 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1389 el[appendChild](ig);
1391 var img = doc.createElement("img");
1392 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
1393 img.onload = function () {
1394 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1395 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1396 doc.body.removeChild(this);
1399 doc.body[appendChild](img);
1401 o.paper.defs[appendChild](el);
1402 node.style.fill = "url(#" + el.id + ")";
1403 $(node, {fill: "url(#" + el.id + ")"});
1405 o.pattern && updatePosition(o);
1408 var clr = R.getRGB(value);
1410 delete params.gradient;
1411 delete attrs.gradient;
1412 !R.is(attrs.opacity, "undefined") &&
1413 R.is(params.opacity, "undefined") &&
1414 $(node, {opacity: attrs.opacity});
1415 !R.is(attrs["fill-opacity"], "undefined") &&
1416 R.is(params["fill-opacity"], "undefined") &&
1417 $(node, {"fill-opacity": attrs["fill-opacity"]});
1418 } else if ((({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper)) {
1419 attrs.gradient = value;
1420 attrs.fill = "none";
1423 clr[has]("o") && $(node, {"fill-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1425 clr = R.getRGB(value);
1426 node[setAttribute](att, clr.hex);
1427 att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1430 (({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper);
1433 if (attrs.gradient && !attrs[has]("stroke-opacity")) {
1434 $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
1437 case "fill-opacity":
1438 if (attrs.gradient) {
1439 var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
1441 var stops = gradient.getElementsByTagName("stop");
1442 stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1447 att == "font-size" && (value = toInt(value, 10) + "px");
1448 var cssrule = att[rp](/(\-.)/g, function (w) {
1449 return upperCase.call(w.substring(1));
1451 node.style[cssrule] = value;
1452 // Need following line for Firefox
1453 node[setAttribute](att, value);
1459 tuneText(o, params);
1461 o.rotate(rotxy.join(S));
1463 toFloat(rot) && o.rotate(rot, true);
1467 tuneText = function (el, params) {
1468 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1473 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1475 if (params[has]("text")) {
1476 a.text = params.text;
1477 while (node.firstChild) {
1478 node.removeChild(node.firstChild);
1480 var texts = Str(params.text)[split]("\n");
1481 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1482 var tspan = $("tspan");
1483 i && $(tspan, {dy: fontSize * leading, x: a.x});
1484 tspan[appendChild](doc.createTextNode(texts[i]));
1485 node[appendChild](tspan);
1488 texts = node.getElementsByTagName("tspan");
1489 for (i = 0, ii = texts[length]; i < ii; i++) {
1490 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1494 var bb = el.getBBox(),
1495 dif = a.y - (bb.y + bb.height / 2);
1496 dif && isFinite(dif) && $(node, {y: a.y + dif});
1498 Element = function (node, svg) {
1504 node.raphael = this;
1506 this.attrs = this.attrs || {};
1507 this.transformations = []; // rotate, translate, scale
1511 rt: {deg: 0, cx: 0, cy: 0},
1515 !svg.bottom && (svg.bottom = this);
1516 this.prev = svg.top;
1517 svg.top && (svg.top.next = this);
1521 var elproto = Element[proto];
1522 Element[proto].rotate = function (deg, cx, cy) {
1528 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1530 return this._.rt.deg;
1532 var bbox = this.getBBox();
1533 deg = Str(deg)[split](separator);
1534 if (deg[length] - 1) {
1535 cx = toFloat(deg[1]);
1536 cy = toFloat(deg[2]);
1538 deg = toFloat(deg[0]);
1539 if (cx != null && cx !== false) {
1540 this._.rt.deg = deg;
1542 this._.rt.deg += deg;
1544 (cy == null) && (cx = null);
1547 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1548 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1549 if (this._.rt.deg) {
1550 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1551 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1553 this.transformations[0] = E;
1554 this.clip && $(this.clip, {transform: E});
1556 $(this.node, {transform: this.transformations[join](S)});
1559 Element[proto].hide = function () {
1560 !this.removed && (this.node.style.display = "none");
1563 Element[proto].show = function () {
1564 !this.removed && (this.node.style.display = "");
1567 Element[proto].remove = function () {
1571 tear(this, this.paper);
1572 this.node.parentNode.removeChild(this.node);
1573 for (var i in this) {
1576 this.removed = true;
1578 Element[proto].getBBox = function () {
1582 if (this.type == "path") {
1583 return pathDimensions(this.attrs.path);
1585 if (this.node.style.display == "none") {
1591 bbox = this.node.getBBox();
1593 // Firefox 3.0.x plays badly here
1597 if (this.type == "text") {
1598 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1599 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1600 var bb = this.node.getExtentOfChar(i);
1601 (bb.y < bbox.y) && (bbox.y = bb.y);
1602 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1603 (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1606 hide && this.hide();
1609 Element[proto].attr = function (name, value) {
1615 for (var i in this.attrs) if (this.attrs[has](i)) {
1616 res[i] = this.attrs[i];
1618 this._.rt.deg && (res.rotation = this.rotate());
1619 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1620 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1623 if (value == null && R.is(name, string)) {
1624 if (name == "translation") {
1625 return translate.call(this);
1627 if (name == "rotation") {
1628 return this.rotate();
1630 if (name == "scale") {
1631 return this.scale();
1633 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
1634 return this.attrs.gradient;
1636 return this.attrs[name];
1638 if (value == null && R.is(name, array)) {
1640 for (var j = 0, jj = name.length; j < jj; j++) {
1641 values[name[j]] = this.attr(name[j]);
1645 if (value != null) {
1647 params[name] = value;
1648 } else if (name != null && R.is(name, "object")) {
1651 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1652 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
1653 this.attrs[key] = params[key];
1654 for (var subkey in par) if (par[has](subkey)) {
1655 params[subkey] = par[subkey];
1658 setFillAndStroke(this, params);
1661 Element[proto].toFront = function () {
1665 this.node.parentNode[appendChild](this.node);
1666 var svg = this.paper;
1667 svg.top != this && tofront(this, svg);
1670 Element[proto].toBack = function () {
1674 if (this.node.parentNode.firstChild != this.node) {
1675 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1676 toback(this, this.paper);
1677 var svg = this.paper;
1681 Element[proto].insertAfter = function (element) {
1685 var node = element.node || element[element.length - 1].node;
1686 if (node.nextSibling) {
1687 node.parentNode.insertBefore(this.node, node.nextSibling);
1689 node.parentNode[appendChild](this.node);
1691 insertafter(this, element, this.paper);
1694 Element[proto].insertBefore = function (element) {
1698 var node = element.node || element[0].node;
1699 node.parentNode.insertBefore(this.node, node);
1700 insertbefore(this, element, this.paper);
1703 Element[proto].blur = function (size) {
1704 // Experimental. No Safari support. Use it on your own risk.
1707 var fltr = $("filter"),
1708 blur = $("feGaussianBlur");
1709 t.attrs.blur = size;
1710 fltr.id = createUUID();
1711 $(blur, {stdDeviation: +size || 1.5});
1712 fltr.appendChild(blur);
1713 t.paper.defs.appendChild(fltr);
1715 $(t.node, {filter: "url(#" + fltr.id + ")"});
1718 t._blur.parentNode.removeChild(t._blur);
1720 delete t.attrs.blur;
1722 t.node.removeAttribute("filter");
1725 var theCircle = function (svg, x, y, r) {
1726 var el = $("circle");
1727 svg.canvas && svg.canvas[appendChild](el);
1728 var res = new Element(el, svg);
1729 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1730 res.type = "circle";
1734 theRect = function (svg, x, y, w, h, r) {
1736 svg.canvas && svg.canvas[appendChild](el);
1737 var res = new Element(el, svg);
1738 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1743 theEllipse = function (svg, x, y, rx, ry) {
1744 var el = $("ellipse");
1745 svg.canvas && svg.canvas[appendChild](el);
1746 var res = new Element(el, svg);
1747 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1748 res.type = "ellipse";
1752 theImage = function (svg, src, x, y, w, h) {
1753 var el = $("image");
1754 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1755 el.setAttributeNS(svg.xlink, "href", src);
1756 svg.canvas && svg.canvas[appendChild](el);
1757 var res = new Element(el, svg);
1758 res.attrs = {x: x, y: y, width: w, height: h, src: src};
1762 theText = function (svg, x, y, text) {
1764 $(el, {x: x, y: y, "text-anchor": "middle"});
1765 svg.canvas && svg.canvas[appendChild](el);
1766 var res = new Element(el, svg);
1767 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1769 setFillAndStroke(res, res.attrs);
1772 setSize = function (width, height) {
1773 this.width = width || this.width;
1774 this.height = height || this.height;
1775 this.canvas[setAttribute]("width", this.width);
1776 this.canvas[setAttribute]("height", this.height);
1779 create = function () {
1780 var con = getContainer[apply](0, arguments),
1781 container = con && con.container,
1785 height = con.height;
1787 throw new Error("SVG container not found.");
1789 var cnvs = $("svg");
1792 width = width || 512;
1793 height = height || 342;
1795 xmlns: "http://www.w3.org/2000/svg",
1800 if (container == 1) {
1801 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1802 doc.body[appendChild](cnvs);
1804 if (container.firstChild) {
1805 container.insertBefore(cnvs, container.firstChild);
1807 container[appendChild](cnvs);
1810 container = new Paper;
1811 container.width = width;
1812 container.height = height;
1813 container.canvas = cnvs;
1814 plugins.call(container, container, R.fn);
1818 paperproto.clear = function () {
1819 var c = this.canvas;
1820 while (c.firstChild) {
1821 c.removeChild(c.firstChild);
1823 this.bottom = this.top = null;
1824 (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1825 c[appendChild](this.desc);
1826 c[appendChild](this.defs = $("defs"));
1828 paperproto.remove = function () {
1829 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1830 for (var i in this) {
1831 this[i] = removed(i);
1838 var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1839 bites = /([clmz]),?([^clmz]*)/gi,
1840 blurregexp = / progid:\S+Blur\([^\)]+\)/g,
1841 val = /-?[^,\s-]+/g,
1842 coordsize = 1e3 + S + 1e3,
1844 pathlike = {path: 1, rect: 1},
1845 path2vml = function (path) {
1846 var total = /[ahqstv]/ig,
1847 command = pathToAbsolute;
1848 Str(path).match(total) && (command = path2curve);
1850 if (command == pathToAbsolute && !Str(path).match(total)) {
1851 var res = Str(path)[rp](bites, function (all, command, args) {
1853 isMove = lowerCase.call(command) == "m",
1855 args[rp](val, function (value) {
1856 if (isMove && vals[length] == 2) {
1857 res += vals + map[command == "m" ? "l" : "L"];
1860 vals[push](round(value * zoom));
1866 var pa = command(path), p, r;
1868 for (var i = 0, ii = pa[length]; i < ii; i++) {
1870 r = lowerCase.call(pa[i][0]);
1871 r == "z" && (r = "x");
1872 for (var j = 1, jj = p[length]; j < jj; j++) {
1873 r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
1877 return res[join](S);
1880 R[toString] = function () {
1881 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1883 thePath = function (pathString, vml) {
1884 var g = createNode("group");
1885 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
1886 g.coordsize = vml.coordsize;
1887 g.coordorigin = vml.coordorigin;
1888 var el = createNode("shape"), ol = el.style;
1889 ol.width = vml.width + "px";
1890 ol.height = vml.height + "px";
1891 el.coordsize = coordsize;
1892 el.coordorigin = vml.coordorigin;
1894 var p = new Element(el, g, vml),
1895 attr = {fill: "none", stroke: "#000"};
1896 pathString && (attr.path = pathString);
1900 setFillAndStroke(p, attr);
1901 vml.canvas[appendChild](g);
1904 setFillAndStroke = function (o, params) {
1905 o.attrs = o.attrs || {};
1910 newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
1913 for (var par in params) if (params[has](par)) {
1914 a[par] = params[par];
1917 a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
1923 params.href && (node.href = params.href);
1924 params.title && (node.title = params.title);
1925 params.target && (node.target = params.target);
1926 params.cursor && (s.cursor = params.cursor);
1927 "blur" in params && o.blur(params.blur);
1928 if (params.path && o.type == "path" || newpath) {
1929 node.path = path2vml(a.path);
1931 if (params.rotation != null) {
1932 o.rotate(params.rotation, true);
1934 if (params.translation) {
1935 xy = Str(params.translation)[split](separator);
1936 translate.call(o, xy[0], xy[1]);
1937 if (o._.rt.cx != null) {
1938 o._.rt.cx +=+ xy[0];
1939 o._.rt.cy +=+ xy[1];
1940 o.setBox(o.attrs, xy[0], xy[1]);
1944 xy = Str(params.scale)[split](separator);
1945 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1947 if ("clip-rect" in params) {
1948 var rect = Str(params["clip-rect"])[split](separator);
1949 if (rect[length] == 4) {
1950 rect[2] = +rect[2] + (+rect[0]);
1951 rect[3] = +rect[3] + (+rect[1]);
1952 var div = node.clipRect || doc.createElement("div"),
1954 group = node.parentNode;
1955 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1956 if (!node.clipRect) {
1957 dstyle.position = "absolute";
1960 dstyle.width = o.paper.width + "px";
1961 dstyle.height = o.paper.height + "px";
1962 group.parentNode.insertBefore(div, group);
1963 div[appendChild](group);
1964 node.clipRect = div;
1967 if (!params["clip-rect"]) {
1968 node.clipRect && (node.clipRect.style.clip = E);
1971 if (o.type == "image" && params.src) {
1972 node.src = params.src;
1974 if (o.type == "image" && params.opacity) {
1975 node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
1976 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1978 params.font && (s.font = params.font);
1979 params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1980 params["font-size"] && (s.fontSize = params["font-size"]);
1981 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1982 params["font-style"] && (s.fontStyle = params["font-style"]);
1983 if (params.opacity != null ||
1984 params["stroke-width"] != null ||
1985 params.fill != null ||
1986 params.stroke != null ||
1987 params["stroke-width"] != null ||
1988 params["stroke-opacity"] != null ||
1989 params["fill-opacity"] != null ||
1990 params["stroke-dasharray"] != null ||
1991 params["stroke-miterlimit"] != null ||
1992 params["stroke-linejoin"] != null ||
1993 params["stroke-linecap"] != null) {
1994 node = o.shape || node;
1995 var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
1997 !fill && (newfill = fill = createNode(fillString));
1998 if ("fill-opacity" in params || "opacity" in params) {
1999 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
2000 opacity = mmin(mmax(opacity, 0), 1);
2001 fill.opacity = opacity;
2003 params.fill && (fill.on = true);
2004 if (fill.on == null || params.fill == "none") {
2007 if (fill.on && params.fill) {
2008 var isURL = params.fill.match(ISURL);
2010 fill.src = isURL[1];
2013 fill.color = R.getRGB(params.fill).hex;
2015 fill.type = "solid";
2016 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
2018 a.gradient = params.fill;
2022 newfill && node[appendChild](fill);
2023 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
2025 !stroke && (newstroke = stroke = createNode("stroke"));
2026 if ((params.stroke && params.stroke != "none") ||
2027 params["stroke-width"] ||
2028 params["stroke-opacity"] != null ||
2029 params["stroke-dasharray"] ||
2030 params["stroke-miterlimit"] ||
2031 params["stroke-linejoin"] ||
2032 params["stroke-linecap"]) {
2035 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
2036 var strokeColor = R.getRGB(params.stroke);
2037 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
2038 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
2039 var width = (toFloat(params["stroke-width"]) || 1) * .75;
2040 opacity = mmin(mmax(opacity, 0), 1);
2041 params["stroke-width"] == null && (width = a["stroke-width"]);
2042 params["stroke-width"] && (stroke.weight = width);
2043 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
2044 stroke.opacity = opacity;
2046 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
2047 stroke.miterlimit = params["stroke-miterlimit"] || 8;
2048 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
2049 if (params["stroke-dasharray"]) {
2053 "-.": "shortdashdot",
2054 "-..": "shortdashdotdot",
2059 "--.": "longdashdot",
2060 "--..": "longdashdotdot"
2062 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
2064 newstroke && node[appendChild](stroke);
2066 if (res.type == "text") {
2067 s = res.paper.span.style;
2068 a.font && (s.font = a.font);
2069 a["font-family"] && (s.fontFamily = a["font-family"]);
2070 a["font-size"] && (s.fontSize = a["font-size"]);
2071 a["font-weight"] && (s.fontWeight = a["font-weight"]);
2072 a["font-style"] && (s.fontStyle = a["font-style"]);
2073 res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "<")[rp](/&/g, "&")[rp](/\n/g, "<br>"));
2074 res.W = a.w = res.paper.span.offsetWidth;
2075 res.H = a.h = res.paper.span.offsetHeight;
2077 res.Y = a.y + round(res.H / 2);
2079 // text-anchor emulationm
2080 switch (a["text-anchor"]) {
2082 res.node.style["v-text-align"] = "left";
2083 res.bbx = round(res.W / 2);
2086 res.node.style["v-text-align"] = "right";
2087 res.bbx = -round(res.W / 2);
2090 res.node.style["v-text-align"] = "center";
2095 addGradientFill = function (o, gradient) {
2096 o.attrs = o.attrs || {};
2097 var attrs = o.attrs,
2101 o.attrs.gradient = gradient;
2102 gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
2107 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
2112 gradient = gradient[split](/\s*\-\s*/);
2113 if (type == "linear") {
2114 var angle = gradient.shift();
2115 angle = -toFloat(angle);
2120 var dots = parseDots(gradient);
2124 o = o.shape || o.node;
2125 fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
2126 !fill.parentNode && o.appendChild(fill);
2129 fill.method = "none";
2130 fill.color = dots[0].color;
2131 fill.color2 = dots[dots[length] - 1].color;
2133 for (var i = 0, ii = dots[length]; i < ii; i++) {
2134 dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
2136 fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
2137 if (type == "radial") {
2138 fill.type = "gradientradial";
2139 fill.focus = "100%";
2140 fill.focussize = fxfy;
2141 fill.focusposition = fxfy;
2143 fill.type = "gradient";
2144 fill.angle = (270 - angle) % 360;
2149 Element = function (node, group, vml) {
2157 node.raphael = this;
2170 !vml.bottom && (vml.bottom = this);
2171 this.prev = vml.top;
2172 vml.top && (vml.top.next = this);
2176 elproto = Element[proto];
2177 elproto.rotate = function (deg, cx, cy) {
2183 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
2185 return this._.rt.deg;
2187 deg = Str(deg)[split](separator);
2188 if (deg[length] - 1) {
2189 cx = toFloat(deg[1]);
2190 cy = toFloat(deg[2]);
2192 deg = toFloat(deg[0]);
2194 this._.rt.deg = deg;
2196 this._.rt.deg += deg;
2198 cy == null && (cx = null);
2201 this.setBox(this.attrs, cx, cy);
2202 this.Group.style.rotation = this._.rt.deg;
2203 // gradient fix for rotation. TODO
2204 // var fill = (this.shape || this.node).getElementsByTagName(fillString);
2205 // fill = fill[0] || {};
2206 // var b = ((360 - this._.rt.deg) - 270) % 360;
2207 // !R.is(fill.angle, "undefined") && (fill.angle = b);
2210 elproto.setBox = function (params, cx, cy) {
2214 var gs = this.Group.style,
2215 os = (this.shape && this.shape.style) || this.node.style;
2216 params = params || {};
2217 for (var i in params) if (params[has](i)) {
2218 this.attrs[i] = params[i];
2220 cx = cx || this._.rt.cx;
2221 cy = cy || this._.rt.cy;
2222 var attr = this.attrs,
2227 switch (this.type) {
2229 x = attr.cx - attr.r;
2230 y = attr.cy - attr.r;
2234 x = attr.cx - attr.rx;
2235 y = attr.cy - attr.ry;
2242 w = attr.width || 0;
2243 h = attr.height || 0;
2246 this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
2247 x = attr.x - round(this.W / 2);
2248 y = attr.y - this.H / 2;
2254 if (!this.attrs.path) {
2257 w = this.paper.width;
2258 h = this.paper.height;
2260 var dim = pathDimensions(this.attrs.path);
2270 w = this.paper.width;
2271 h = this.paper.height;
2274 cx = (cx == null) ? x + w / 2 : cx;
2275 cy = (cy == null) ? y + h / 2 : cy;
2276 var left = cx - this.paper.width / 2,
2277 top = cy - this.paper.height / 2, t;
2278 gs.left != (t = left + "px") && (gs.left = t);
2279 gs.top != (t = top + "px") && (gs.top = t);
2280 this.X = pathlike[has](this.type) ? -left : x;
2281 this.Y = pathlike[has](this.type) ? -top : y;
2284 if (pathlike[has](this.type)) {
2285 os.left != (t = -left * zoom + "px") && (os.left = t);
2286 os.top != (t = -top * zoom + "px") && (os.top = t);
2287 } else if (this.type == "text") {
2288 os.left != (t = -left + "px") && (os.left = t);
2289 os.top != (t = -top + "px") && (os.top = t);
2291 gs.width != (t = this.paper.width + "px") && (gs.width = t);
2292 gs.height != (t = this.paper.height + "px") && (gs.height = t);
2293 os.left != (t = x - left + "px") && (os.left = t);
2294 os.top != (t = y - top + "px") && (os.top = t);
2295 os.width != (t = w + "px") && (os.width = t);
2296 os.height != (t = h + "px") && (os.height = t);
2299 elproto.hide = function () {
2300 !this.removed && (this.Group.style.display = "none");
2303 elproto.show = function () {
2304 !this.removed && (this.Group.style.display = "block");
2307 elproto.getBBox = function () {
2311 if (pathlike[has](this.type)) {
2312 return pathDimensions(this.attrs.path);
2315 x: this.X + (this.bbx || 0),
2321 elproto.remove = function () {
2325 tear(this, this.paper);
2326 this.node.parentNode.removeChild(this.node);
2327 this.Group.parentNode.removeChild(this.Group);
2328 this.shape && this.shape.parentNode.removeChild(this.shape);
2329 for (var i in this) {
2332 this.removed = true;
2334 elproto.attr = function (name, value) {
2340 for (var i in this.attrs) if (this.attrs[has](i)) {
2341 res[i] = this.attrs[i];
2343 this._.rt.deg && (res.rotation = this.rotate());
2344 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2345 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2348 if (value == null && R.is(name, "string")) {
2349 if (name == "translation") {
2350 return translate.call(this);
2352 if (name == "rotation") {
2353 return this.rotate();
2355 if (name == "scale") {
2356 return this.scale();
2358 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
2359 return this.attrs.gradient;
2361 return this.attrs[name];
2363 if (this.attrs && value == null && R.is(name, array)) {
2364 var ii, values = {};
2365 for (i = 0, ii = name[length]; i < ii; i++) {
2366 values[name[i]] = this.attr(name[i]);
2371 if (value != null) {
2373 params[name] = value;
2375 value == null && R.is(name, "object") && (params = name);
2377 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
2378 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
2379 this.attrs[key] = params[key];
2380 for (var subkey in par) if (par[has](subkey)) {
2381 params[subkey] = par[subkey];
2384 if (params.text && this.type == "text") {
2385 this.node.string = params.text;
2387 setFillAndStroke(this, params);
2388 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
2389 addGradientFill(this, params.gradient);
2391 (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
2395 elproto.toFront = function () {
2396 !this.removed && this.Group.parentNode[appendChild](this.Group);
2397 this.paper.top != this && tofront(this, this.paper);
2400 elproto.toBack = function () {
2404 if (this.Group.parentNode.firstChild != this.Group) {
2405 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2406 toback(this, this.paper);
2410 elproto.insertAfter = function (element) {
2414 if (element.constructor == Set) {
2415 element = element[element.length - 1];
2417 if (element.Group.nextSibling) {
2418 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2420 element.Group.parentNode[appendChild](this.Group);
2422 insertafter(this, element, this.paper);
2425 elproto.insertBefore = function (element) {
2429 if (element.constructor == Set) {
2430 element = element[0];
2432 element.Group.parentNode.insertBefore(this.Group, element.Group);
2433 insertbefore(this, element, this.paper);
2436 elproto.blur = function (size) {
2437 var s = this.node.runtimeStyle,
2439 f = f.replace(blurregexp, E);
2441 this.attrs.blur = size;
2442 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
2443 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
2447 delete this.attrs.blur;
2451 theCircle = function (vml, x, y, r) {
2452 var g = createNode("group"),
2453 o = createNode("oval"),
2455 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2456 g.coordsize = coordsize;
2457 g.coordorigin = vml.coordorigin;
2459 var res = new Element(o, g, vml);
2460 res.type = "circle";
2461 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2465 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2466 vml.canvas[appendChild](g);
2469 function rectPath(x, y, w, h, r) {
2471 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);
2473 return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
2476 theRect = function (vml, x, y, w, h, r) {
2477 var path = rectPath(x, y, w, h, r),
2478 res = vml.path(path),
2482 res.W = a.width = w;
2483 res.H = a.height = h;
2489 theEllipse = function (vml, x, y, rx, ry) {
2490 var g = createNode("group"),
2491 o = createNode("oval"),
2493 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2494 g.coordsize = coordsize;
2495 g.coordorigin = vml.coordorigin;
2497 var res = new Element(o, g, vml);
2498 res.type = "ellipse";
2499 setFillAndStroke(res, {stroke: "#000"});
2504 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2505 vml.canvas[appendChild](g);
2508 theImage = function (vml, src, x, y, w, h) {
2509 var g = createNode("group"),
2510 o = createNode("image");
2511 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2512 g.coordsize = coordsize;
2513 g.coordorigin = vml.coordorigin;
2516 var res = new Element(o, g, vml);
2518 res.attrs.src = src;
2523 res.setBox({x: x, y: y, width: w, height: h});
2524 vml.canvas[appendChild](g);
2527 theText = function (vml, x, y, text) {
2528 var g = createNode("group"),
2529 el = createNode("shape"),
2531 path = createNode("path"),
2533 o = createNode("textpath");
2534 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2535 g.coordsize = coordsize;
2536 g.coordorigin = vml.coordorigin;
2537 path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
2538 path.textpathok = true;
2539 ol.width = vml.width;
2540 ol.height = vml.height;
2541 o.string = Str(text);
2544 el[appendChild](path);
2546 var res = new Element(o, g, vml);
2548 res.textpath = path;
2550 res.attrs.text = text;
2555 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2557 vml.canvas[appendChild](g);
2560 setSize = function (width, height) {
2561 var cs = this.canvas.style;
2562 width == +width && (width += "px");
2563 height == +height && (height += "px");
2566 cs.clip = "rect(0 " + width + " " + height + " 0)";
2570 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2572 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2573 createNode = function (tagName) {
2574 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2577 createNode = function (tagName) {
2578 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2581 create = function () {
2582 var con = getContainer[apply](0, arguments),
2583 container = con.container,
2584 height = con.height,
2590 throw new Error("VML container not found.");
2592 var res = new Paper,
2593 c = res.canvas = doc.createElement("div"),
2597 width = width || 512;
2598 height = height || 342;
2599 width == +width && (width += "px");
2600 height == +height && (height += "px");
2603 res.coordsize = zoom * 1e3 + S + zoom * 1e3;
2604 res.coordorigin = "0 0";
2605 res.span = doc.createElement("span");
2606 res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2607 c[appendChild](res.span);
2608 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);
2609 if (container == 1) {
2610 doc.body[appendChild](c);
2613 cs.position = "absolute";
2615 if (container.firstChild) {
2616 container.insertBefore(c, container.firstChild);
2618 container[appendChild](c);
2621 plugins.call(res, res, R.fn);
2624 paperproto.clear = function () {
2625 this.canvas.innerHTML = E;
2626 this.span = doc.createElement("span");
2627 this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2628 this.canvas[appendChild](this.span);
2629 this.bottom = this.top = null;
2631 paperproto.remove = function () {
2632 this.canvas.parentNode.removeChild(this.canvas);
2633 for (var i in this) {
2634 this[i] = removed(i);
2641 // WebKit rendering bug workaround method
2642 var version = navigator.userAgent.match(/Version\/(.*?)\s/);
2643 if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP")) {
2644 paperproto.safari = function () {
2645 var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2646 win.setTimeout(function () {rect.remove();});
2649 paperproto.safari = function () {};
2653 var preventDefault = function () {
2654 this.returnValue = false;
2656 preventTouch = function () {
2657 return this.originalEvent.preventDefault();
2659 stopPropagation = function () {
2660 this.cancelBubble = true;
2662 stopTouch = function () {
2663 return this.originalEvent.stopPropagation();
2665 addEvent = (function () {
2666 if (doc.addEventListener) {
2667 return function (obj, type, fn, element) {
2668 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
2669 var f = function (e) {
2670 if (supportsTouch && touchMap[has](type)) {
2671 for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2672 if (e.targetTouches[i].target == obj) {
2674 e = e.targetTouches[i];
2675 e.originalEvent = olde;
2676 e.preventDefault = preventTouch;
2677 e.stopPropagation = stopTouch;
2682 return fn.call(element, e);
2684 obj.addEventListener(realName, f, false);
2685 return function () {
2686 obj.removeEventListener(realName, f, false);
2690 } else if (doc.attachEvent) {
2691 return function (obj, type, fn, element) {
2692 var f = function (e) {
2694 e.preventDefault = e.preventDefault || preventDefault;
2695 e.stopPropagation = e.stopPropagation || stopPropagation;
2696 return fn.call(element, e);
2698 obj.attachEvent("on" + type, f);
2699 var detacher = function () {
2700 obj.detachEvent("on" + type, f);
2708 dragMove = function (e) {
2711 scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2712 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft,
2717 if (supportsTouch) {
2718 var i = e.touches.length,
2721 touch = e.touches[i];
2722 if (touch.identifier == dragi.el._drag.id) {
2725 (e.originalEvent ? e.originalEvent : e).preventDefault();
2734 dragi.move && dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
2737 dragUp = function () {
2738 R.unmousemove(dragMove).unmouseup(dragUp);
2739 var i = drag.length,
2743 dragi.el._drag = {};
2744 dragi.end && dragi.end.call(dragi.el);
2748 for (var i = events[length]; i--;) {
2749 (function (eventName) {
2750 R[eventName] = Element[proto][eventName] = function (fn) {
2751 if (R.is(fn, "function")) {
2752 this.events = this.events || [];
2753 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
2757 R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
2758 var events = this.events,
2760 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2762 events.splice(l, 1);
2763 !events.length && delete this.events;
2770 elproto.hover = function (f_in, f_out) {
2771 return this.mouseover(f_in).mouseout(f_out);
2773 elproto.unhover = function (f_in, f_out) {
2774 return this.unmouseover(f_in).unmouseout(f_out);
2776 elproto.drag = function (onmove, onstart, onend) {
2778 this.mousedown(function (e) {
2779 (e.originalEvent || e).preventDefault();
2780 var scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2781 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft;
2782 this._drag.x = e.clientX + scrollX;
2783 this._drag.y = e.clientY + scrollY;
2784 this._drag.id = e.identifier;
2785 onstart && onstart.call(this, e.clientX + scrollX, e.clientY + scrollY);
2786 !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2787 drag.push({el: this, move: onmove, end: onend});
2791 elproto.undrag = function (onmove, onstart, onend) {
2792 var i = drag.length;
2794 drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i++, 1);
2796 !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2798 paperproto.circle = function (x, y, r) {
2799 return theCircle(this, x || 0, y || 0, r || 0);
2801 paperproto.rect = function (x, y, w, h, r) {
2802 return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2804 paperproto.ellipse = function (x, y, rx, ry) {
2805 return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2807 paperproto.path = function (pathString) {
2808 pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2809 return thePath(R.format[apply](R, arguments), this);
2811 paperproto.image = function (src, x, y, w, h) {
2812 return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2814 paperproto.text = function (x, y, text) {
2815 return theText(this, x || 0, y || 0, Str(text));
2817 paperproto.set = function (itemsArray) {
2818 arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2819 return new Set(itemsArray);
2821 paperproto.setSize = setSize;
2822 paperproto.top = paperproto.bottom = null;
2823 paperproto.raphael = R;
2825 return this.x + S + this.y;
2827 elproto.resetScale = function () {
2833 this.attrs.scale = "1 1";
2835 elproto.scale = function (x, y, cx, cy) {
2839 if (x == null && y == null) {
2854 var bb = this.getBBox(),
2855 rcx = bb.x + bb.width / 2,
2856 rcy = bb.y + bb.height / 2,
2857 kx = abs(x / this._.sx),
2858 ky = abs(y / this._.sy);
2859 cx = (+cx || cx == 0) ? cx : rcx;
2860 cy = (+cy || cy == 0) ? cy : rcy;
2861 var posx = this._.sx > 0,
2862 posy = this._.sy > 0,
2863 dirx = ~~(x / abs(x)),
2864 diry = ~~(y / abs(y)),
2867 s = this.node.style,
2868 ncx = cx + abs(rcx - cx) * dkx * (rcx > cx == posx ? 1 : -1),
2869 ncy = cy + abs(rcy - cy) * dky * (rcy > cy == posy ? 1 : -1),
2870 fr = (x * dirx > y * diry ? ky : kx);
2871 switch (this.type) {
2874 var neww = a.width * kx,
2875 newh = a.height * ky;
2901 var path = pathToRelative(a.path),
2903 fx = posx ? dkx : kx,
2904 fy = posy ? dky : ky;
2905 for (var i = 0, ii = path[length]; i < ii; i++) {
2907 P0 = upperCase.call(p[0]);
2908 if (P0 == "M" && skip) {
2914 p[path[i][length] - 2] *= fx;
2915 p[path[i][length] - 1] *= fy;
2918 p[5] = +(dirx + diry ? !+p[4] : !!+p[4]);
2919 } else if (P0 == "H") {
2920 for (var j = 1, jj = p[length]; j < jj; j++) {
2923 } else if (P0 == "V") {
2924 for (j = 1, jj = p[length]; j < jj; j++) {
2928 for (j = 1, jj = p[length]; j < jj; j++) {
2929 p[j] *= (j % 2) ? fx : fy;
2933 var dim2 = pathDimensions(path);
2934 dx = ncx - dim2.x - dim2.width / 2;
2935 dy = ncy - dim2.y - dim2.height / 2;
2938 this.attr({path: path});
2941 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2942 if (this.transformations) {
2943 this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2944 this.node[setAttribute]("transform", this.transformations[join](S));
2945 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2946 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2947 this.attr({x: dx, y: dy});
2951 this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
2952 ", M12=0, M21=0, M22=", diry,
2953 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2954 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2957 if (this.transformations) {
2958 this.transformations[2] = E;
2959 this.node[setAttribute]("transform", this.transformations[join](S));
2963 this.node.filterMatrix = E;
2964 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2967 a.scale = [x, y, cx, cy][join](S);
2973 elproto.clone = function () {
2977 var attr = this.attr();
2979 delete attr.translation;
2980 return this.paper[this.type]().attr(attr);
2982 var curveslengths = {},
2983 getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2986 name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
2987 cache = curveslengths[name],
2989 !cache && (curveslengths[name] = cache = {data: []});
2990 cache.timer && clearTimeout(cache.timer);
2991 cache.timer = setTimeout(function () {delete curveslengths[name];}, 2000);
2992 if (length != null) {
2993 var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
2994 precision = ~~total * 10;
2996 for (var i = 0; i < precision + 1; i++) {
2997 if (cache.data[length] > i) {
2998 dot = cache.data[i * precision];
3000 dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
3001 cache.data[i] = dot;
3003 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
3004 if (length != null && len >= length) {
3009 if (length == null) {
3013 getLengthFactory = function (istotal, subpath) {
3014 return function (path, length, onlystart) {
3015 path = path2curve(path);
3016 var x, y, p, l, sp = "", subpaths = {}, point,
3018 for (var i = 0, ii = path.length; i < ii; i++) {
3024 l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
3025 if (len + l > length) {
3026 if (subpath && !subpaths.start) {
3027 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3028 sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
3029 if (onlystart) {return sp;}
3030 subpaths.start = sp;
3031 sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
3037 if (!istotal && !subpath) {
3038 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
3039 return {x: point.x, y: point.y, alpha: point.alpha};
3049 point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
3050 point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
3054 var getTotalLength = getLengthFactory(1),
3055 getPointAtLength = getLengthFactory(),
3056 getSubpathsAtLength = getLengthFactory(0, 1);
3057 elproto.getTotalLength = function () {
3058 if (this.type != "path") {return;}
3059 if (this.node.getTotalLength) {
3060 return this.node.getTotalLength();
3062 return getTotalLength(this.attrs.path);
3064 elproto.getPointAtLength = function (length) {
3065 if (this.type != "path") {return;}
3066 return getPointAtLength(this.attrs.path, length);
3068 elproto.getSubpath = function (from, to) {
3069 if (this.type != "path") {return;}
3070 if (abs(this.getTotalLength() - to) < "1e-6") {
3071 return getSubpathsAtLength(this.attrs.path, from).end;
3073 var a = getSubpathsAtLength(this.attrs.path, to, 1);
3074 return from ? getSubpathsAtLength(a, from).end : a;
3077 // animation easing formulas
3078 R.easing_formulas = {
3079 linear: function (n) {
3086 return pow(n - 1, 3) + 1;
3088 "<>": function (n) {
3091 return pow(n, 3) / 2;
3094 return (pow(n, 3) + 2) / 2;
3096 backIn: function (n) {
3098 return n * n * ((s + 1) * n - s);
3100 backOut: function (n) {
3103 return n * n * ((s + 1) * n + s) + 1;
3105 elastic: function (n) {
3106 if (n == 0 || n == 1) {
3111 return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
3113 bounce: function (n) {
3122 l = s * n * n + .75;
3124 if (n < (2.5 / p)) {
3126 l = s * n * n + .9375;
3129 l = s * n * n + .984375;
3137 var animationElements = [],
3138 animation = function () {
3139 var Now = +new Date;
3140 for (var l = 0; l < animationElements[length]; l++) {
3141 var e = animationElements[l];
3142 if (e.stop || e.el.removed) {
3145 var time = Now - e.start,
3156 var pos = easing(time / ms);
3157 for (var attr in from) if (from[has](attr)) {
3158 switch (availableAnimAttrs[attr]) {
3160 now = pos * ms * diff[attr];
3161 to.back && (now = to.len - now);
3162 var point = getPointAtLength(to[attr], now);
3163 that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
3166 that.translate(point.x - diff.sx, point.y - diff.sy);
3167 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3170 now = +from[attr] + pos * ms * diff[attr];
3174 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3175 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3176 upto255(round(from[attr].b + pos * ms * diff[attr].b))
3181 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3182 now[i] = [from[attr][i][0]];
3183 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3184 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3186 now[i] = now[i][join](S);
3193 var x = pos * ms * diff[attr][0] - t.x,
3194 y = pos * ms * diff[attr][1] - t.y;
3200 now = +from[attr][0] + pos * ms * diff[attr][0];
3201 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
3204 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);
3210 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3216 var from2 = [].concat(from[attr]);
3218 i = that.paper.customAttributes[attr].length;
3220 now[i] = +from2[i] + pos * ms * diff[attr][i];
3227 that._run && that._run.call(that);
3230 point = getPointAtLength(to.along, to.len * !to.back);
3231 that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
3232 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3234 (t.x || t.y) && that.translate(-t.x, -t.y);
3235 to.scale && (to.scale += E);
3237 animationElements.splice(l--, 1);
3240 R.svg && that && that.paper && that.paper.safari();
3241 animationElements[length] && setTimeout(animation);
3243 keyframesRun = function (attr, element, time, prev, prevcallback) {
3244 var dif = time - prev;
3245 element.timeouts.push(setTimeout(function () {
3246 R.is(prevcallback, "function") && prevcallback.call(element);
3247 element.animate(attr, dif, attr.easing);
3250 upto255 = function (color) {
3251 return mmax(mmin(color, 255), 0);
3253 translate = function (x, y) {
3255 return {x: this._.tx, y: this._.ty, toString: x_y};
3259 switch (this.type) {
3262 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
3267 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
3270 var path = pathToRelative(this.attrs.path);
3273 this.attr({path: path});
3278 elproto.animateWith = function (element, params, ms, easing, callback) {
3279 for (var i = 0, ii = animationElements.length; i < ii; i++) {
3280 if (animationElements[i].el.id == element.id) {
3281 params.start = animationElements[i].start;
3284 return this.animate(params, ms, easing, callback);
3286 elproto.animateAlong = along();
3287 elproto.animateAlongBack = along(1);
3288 function along(isBack) {
3289 return function (path, ms, rotate, callback) {
3290 var params = {back: isBack};
3291 R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
3292 path && path.constructor == Element && (path = path.attrs.path);
3293 path && (params.along = path);
3294 return this.animate(params, ms, callback);
3297 function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
3299 bx = 3 * (p2x - p1x) - cx,
3302 by = 3 * (p2y - p1y) - cy,
3304 function sampleCurveX(t) {
3305 return ((ax * t + bx) * t + cx) * t;
3307 function solve(x, epsilon) {
3308 var t = solveCurveX(x, epsilon);
3309 return ((ay * t + by) * t + cy) * t;
3311 function solveCurveX(x, epsilon) {
3312 var t0, t1, t2, x2, d2, i;
3313 for(t2 = x, i = 0; i < 8; i++) {
3314 x2 = sampleCurveX(t2) - x;
3315 if (abs(x2) < epsilon) {
3318 d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
3319 if (abs(d2) < 1e-6) {
3334 x2 = sampleCurveX(t2);
3335 if (abs(x2 - x) < epsilon) {
3343 t2 = (t1 - t0) / 2 + t0;
3347 return solve(t, 1 / (200 * duration));
3349 elproto.onAnimation = function (f) {
3353 elproto.animate = function (params, ms, easing, callback) {
3355 element.timeouts = element.timeouts || [];
3356 if (R.is(easing, "function") || !easing) {
3357 callback = easing || null;
3359 if (element.removed) {
3360 callback && callback.call(element);
3365 animateable = false,
3367 for (var attr in params) if (params[has](attr)) {
3368 if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
3370 from[attr] = element.attr(attr);
3371 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3372 to[attr] = params[attr];
3373 switch (availableAnimAttrs[attr]) {
3375 var len = getTotalLength(params[attr]);
3376 var point = getPointAtLength(params[attr], len * !!params.back);
3377 var bb = element.getBBox();
3378 diff[attr] = len / ms;
3383 to.rot = params.rot;
3384 to.back = params.back;
3386 params.rot && (diff.r = toFloat(element.rotate()) || 0);
3389 diff[attr] = (to[attr] - from[attr]) / ms;
3392 from[attr] = R.getRGB(from[attr]);
3393 var toColour = R.getRGB(to[attr]);
3395 r: (toColour.r - from[attr].r) / ms,
3396 g: (toColour.g - from[attr].g) / ms,
3397 b: (toColour.b - from[attr].b) / ms
3401 var pathes = path2curve(from[attr], to[attr]);
3402 from[attr] = pathes[0];
3403 var toPath = pathes[1];
3405 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3406 diff[attr][i] = [0];
3407 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3408 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3413 var values = Str(params[attr])[split](separator),
3414 from2 = Str(from[attr])[split](separator);
3417 from[attr] = [0, 0];
3418 diff[attr] = [values[0] / ms, values[1] / ms];
3421 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
3422 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
3425 params[attr] = values;
3426 from[attr] = Str(from[attr])[split](separator);
3427 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
3430 from[attr] = Str(from[attr])[split](separator);
3434 diff[attr][i] = (values[i] - from[attr][i]) / ms;
3441 values = [].concat(params[attr]);
3442 from2 = [].concat(from[attr]);
3444 i = element.paper.customAttributes[attr][length];
3446 diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
3455 for (var key in params) if (params[has](key) && animKeyFrames.test(key)) {
3456 attr = {value: params[key]};
3457 key == "from" && (key = 0);
3458 key == "to" && (key = 100);
3459 attr.key = toInt(key, 10);
3462 attrs.sort(sortByKey);
3464 attrs.unshift({key: 0, value: element.attrs});
3466 for (i = 0, ii = attrs[length]; i < ii; i++) {
3467 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);
3469 lastcall = attrs[attrs[length] - 1].value.callback;
3471 element.timeouts.push(setTimeout(function () {lastcall.call(element);}, ms));
3474 var easyeasy = R.easing_formulas[easing];
3476 easyeasy = Str(easing).match(bezierrg);
3477 if (easyeasy && easyeasy[length] == 5) {
3478 var curve = easyeasy;
3479 easyeasy = function (t) {
3480 return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
3483 easyeasy = function (t) {
3488 animationElements.push({
3489 start: params.start || +new Date,
3498 R.is(callback, "function") && (element._ac = setTimeout(function () {
3499 callback.call(element);
3501 animationElements[length] == 1 && setTimeout(animation);
3505 elproto.stop = function () {
3506 for (var i = 0; i < animationElements.length; i++) {
3507 animationElements[i].el.id == this.id && animationElements.splice(i--, 1);
3509 for (i = 0, ii = this.timeouts && this.timeouts.length; i < ii; i++) {
3510 clearTimeout(this.timeouts[i]);
3513 clearTimeout(this._ac);
3517 elproto.translate = function (x, y) {
3518 return this.attr({translation: x + " " + y});
3520 elproto[toString] = function () {
3521 return "Rapha\xebl\u2019s object";
3523 R.ae = animationElements;
3526 var Set = function (items) {
3531 for (var i = 0, ii = items[length]; i < ii; i++) {
3532 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
3533 this[this.items[length]] = this.items[this.items[length]] = items[i];
3539 Set[proto][push] = function () {
3542 for (var i = 0, ii = arguments[length]; i < ii; i++) {
3543 item = arguments[i];
3544 if (item && (item.constructor == Element || item.constructor == Set)) {
3545 len = this.items[length];
3546 this[len] = this.items[len] = item;
3552 Set[proto].pop = function () {
3553 delete this[this[length]--];
3554 return this.items.pop();
3556 for (var method in elproto) if (elproto[has](method)) {
3557 Set[proto][method] = (function (methodname) {
3558 return function () {
3559 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3560 this.items[i][methodname][apply](this.items[i], arguments);
3566 Set[proto].attr = function (name, value) {
3567 if (name && R.is(name, array) && R.is(name[0], "object")) {
3568 for (var j = 0, jj = name[length]; j < jj; j++) {
3569 this.items[j].attr(name[j]);
3572 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3573 this.items[i].attr(name, value);
3578 Set[proto].animate = function (params, ms, easing, callback) {
3579 (R.is(easing, "function") || !easing) && (callback = easing || null);
3580 var len = this.items[length],
3585 callback && (collector = function () {
3586 !--len && callback.call(set);
3588 easing = R.is(easing, string) ? easing : collector;
3589 item = this.items[--i].animate(params, ms, easing, collector);
3591 this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, params, ms, easing, collector);
3595 Set[proto].insertAfter = function (el) {
3596 var i = this.items[length];
3598 this.items[i].insertAfter(el);
3602 Set[proto].getBBox = function () {
3607 for (var i = this.items[length]; i--;) {
3608 var box = this.items[i].getBBox();
3611 w[push](box.x + box.width);
3612 h[push](box.y + box.height);
3614 x = mmin[apply](0, x);
3615 y = mmin[apply](0, y);
3619 width: mmax[apply](0, w) - x,
3620 height: mmax[apply](0, h) - y
3623 Set[proto].clone = function (s) {
3625 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3626 s[push](this.items[i].clone());
3631 R.registerFont = function (font) {
3635 this.fonts = this.fonts || {};
3641 family = font.face["font-family"];
3642 for (var prop in font.face) if (font.face[has](prop)) {
3643 fontcopy.face[prop] = font.face[prop];
3645 if (this.fonts[family]) {
3646 this.fonts[family][push](fontcopy);
3648 this.fonts[family] = [fontcopy];
3651 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3652 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3653 var path = font.glyphs[glyph];
3654 fontcopy.glyphs[glyph] = {
3657 d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3658 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3662 for (var k in path.k) if (path[has](k)) {
3663 fontcopy.glyphs[glyph].k[k] = path.k[k];
3670 paperproto.getFont = function (family, weight, style, stretch) {
3671 stretch = stretch || "normal";
3672 style = style || "normal";
3673 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3677 var font = R.fonts[family];
3679 var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3680 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3681 if (name.test(fontName)) {
3682 font = R.fonts[fontName];
3689 for (var i = 0, ii = font[length]; i < ii; i++) {
3691 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3698 paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
3699 origin = origin || "middle"; // baseline|middle
3700 letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
3701 var out = this.set(),
3702 letters = Str(string)[split](E),
3706 R.is(font, string) && (font = this.getFont(font));
3708 scale = (size || 16) / font.face["units-per-em"];
3709 var bb = font.face.bbox.split(separator),
3711 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3712 for (var i = 0, ii = letters[length]; i < ii; i++) {
3713 var prev = i && font.glyphs[letters[i - 1]] || {},
3714 curr = font.glyphs[letters[i]];
3715 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
3716 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3718 out.scale(scale, scale, top, height).translate(x - top, y - height);
3723 R.format = function (token, params) {
3724 var args = R.is(params, array) ? [0][concat](params) : arguments;
3725 token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
3726 return args[++i] == null ? E : args[i];
3730 R.ninja = function () {
3731 oldRaphael.was ? (win.Raphael = oldRaphael.is) : delete Raphael;
3737 oldRaphael.was ? (win.Raphael = R) : (Raphael = R);