2 * Raphael 1.5.0 - JavaScript Vector Library
4 * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
8 Raphael = (function () {
10 if (R.is(arguments[0], array)) {
12 cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
14 for (var i = 0, ii = a[length]; i < ii; i++) {
16 elements.test(j.type) && res[push](cnv[j.type]().attr(j));
20 return create[apply](R, arguments);
23 var separator = /[, ]+/,
24 elements = /^(circle|rect|path|ellipse|text|image)$/,
26 has = "hasOwnProperty",
30 was: Object[proto][has].call(win, "Raphael"),
34 this.customAttributes = {};
36 appendChild = "appendChild",
39 supportsTouch = "createTouch" in doc,
44 events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
46 mousedown: "touchstart",
47 mousemove: "touchmove",
52 lowerCase = Str[proto].toLowerCase,
60 toString = "toString",
62 objectToString = Object[proto][toString],
66 ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
67 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,
68 isnan = /^(NaN|-?Infinity)$/,
70 setAttribute = "setAttribute",
73 ms = " progid:DXImageTransform.Microsoft",
74 upperCase = Str[proto].toUpperCase,
75 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},
76 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},
78 R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
79 if (R.type == "VML") {
80 var d = doc.createElement("div"),
82 d.innerHTML = '<v:shape adj="1"/>';
84 b.style.behavior = "url(#default#VML)";
85 if (!(b && typeof b.adj == "object")) {
90 R.svg = !(R.vml = R.type == "VML");
91 Paper[proto] = R[proto];
95 R.is = function (o, type) {
96 type = lowerCase.call(type);
97 if (type == "finite") {
98 return !isnan.test(+o);
100 return (type == "null" && o === null) ||
101 (type == typeof o) ||
102 (type == "object" && o === Object(o)) ||
103 (type == "array" && Array.isArray && Array.isArray(o)) ||
104 objectToString.call(o).slice(8, -1).toLowerCase() == type;
106 R.angle = function (dx, dy, cx, cy) {
109 return ((x < 0) * 180 + math.atan(-y / -x) * 180 / math.PI + 360) % 360;
111 R.snapTo = function (values, value, tolerance) {
112 tolerance = tolerance || 10;
113 values = [][concat](values);
114 var i = values.length;
115 while (i--) if (math.abs(values[i] - value) <= tolerance) {
121 R.setWindow = function (newwin) {
126 var toHex = function (color) {
128 // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
129 var trim = /^\s+|\s+$/g;
130 toHex = cacher(function (color) {
132 color = Str(color)[rp](trim, E);
134 var docum = new win.ActiveXObject("htmlfile");
135 docum.write("<body>");
139 bod = win.createPopup().document.body;
141 var range = bod.createTextRange();
143 bod.style.color = color;
144 var value = range.queryCommandValue("ForeColor");
145 value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
146 return "#" + ("000000" + value[toString](16)).slice(-6);
152 var i = doc.createElement("i");
153 i.title = "Rapha\xebl Colour Picker";
154 i.style.display = "none";
155 doc.body[appendChild](i);
156 toHex = cacher(function (color) {
157 i.style.color = color;
158 return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
163 hsbtoString = function () {
164 return "hsb(" + [this.h, this.s, this.b] + ")";
166 hsltoString = function () {
167 return "hsl(" + [this.h, this.s, this.l] + ")";
169 rgbtoString = function () {
172 R.hsb2rgb = function (h, s, b) {
173 if (R.is(h, "object") && "h" in h && "s" in h && "b" in h) {
178 return R.hsl2rgb(h, s, b / 2);
180 R.hsl2rgb = function (h, s, l) {
181 if (R.is(h, "object") && "h" in h && "s" in h && "l" in h) {
186 if (h > 1 || s > 1 || l > 1) {
192 channels = ["r", "g", "b"],
207 for (var i = 0, ii = channels.length; i < ii; i++) {
208 t3 = h + 1 / 3 * -(i - 1);
212 rgb[channels[i]] = t1 + (t2 - t1) * 6 * t3;
213 } else if (t3 * 2 < 1) {
214 rgb[channels[i]] = t2;
215 } else if (t3 * 3 < 2) {
216 rgb[channels[i]] = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
218 rgb[channels[i]] = t1;
225 r = (~~rgb.r)[toString](16);
226 g = (~~rgb.g)[toString](16);
227 b = (~~rgb.b)[toString](16);
231 rgb.hex = "#" + r + g + b;
232 rgb.toString = rgbtoString;
235 R.rgb2hsb = function (red, green, blue) {
236 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
241 if (green == null && R.is(red, string)) {
242 var clr = R.getRGB(red);
247 if (red > 1 || green > 1 || blue > 1) {
252 var max = mmax(red, green, blue),
253 min = mmin(red, green, blue),
258 return {h: 0, s: 0, b: max, toString: hsbtoString};
260 var delta = (max - min);
261 saturation = delta / max;
263 hue = (green - blue) / delta;
264 } else if (green == max) {
265 hue = 2 + ((blue - red) / delta);
267 hue = 4 + ((red - green) / delta);
273 return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
275 R.rgb2hsl = function (red, green, blue) {
276 if (green == null && R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
281 if (green == null && R.is(red, string)) {
282 var clr = R.getRGB(red);
287 if (red > 1 || green > 1 || blue > 1) {
292 var max = mmax(red, green, blue),
293 min = mmin(red, green, blue),
299 hsl = {h: 0, s: 0, l: l};
301 var delta = max - min;
302 s = l < .5 ? delta / (max + min) : delta / (2 - max - min);
304 h = (green - blue) / delta;
305 } else if (green == max) {
306 h = 2 + (blue - red) / delta;
308 h = 4 + (red - green) / delta;
313 hsl = {h: h, s: s, l: l};
315 hsl.toString = hsltoString;
318 var p2s = /,?([achlmqrstvxz]),?/gi,
319 commaSpaces = /\s*,\s*/,
320 hsrg = {hs: 1, rg: 1};
321 R._path2string = function () {
322 return this.join(",")[rp](p2s, "$1");
324 function cacher(f, scope, postprocessor) {
326 var arg = Array[proto].slice.call(arguments, 0),
327 args = arg[join]("\u25ba"),
328 cache = newf.cache = newf.cache || {},
329 count = newf.count = newf.count || [];
330 if (cache[has](args)) {
331 return postprocessor ? postprocessor(cache[args]) : cache[args];
333 count[length] >= 1e3 && delete cache[count.shift()];
335 cache[args] = f[apply](scope, arg);
336 return postprocessor ? postprocessor(cache[args]) : cache[args];
341 R.getRGB = cacher(function (colour) {
342 if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
343 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
345 if (colour == "none") {
346 return {r: -1, g: -1, b: -1, hex: "none"};
348 !(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
355 rgb = colour.match(colourRegExp);
358 blue = toInt(rgb[2].substring(5), 16);
359 green = toInt(rgb[2].substring(3, 5), 16);
360 red = toInt(rgb[2].substring(1, 3), 16);
363 blue = toInt((t = rgb[3].charAt(3)) + t, 16);
364 green = toInt((t = rgb[3].charAt(2)) + t, 16);
365 red = toInt((t = rgb[3].charAt(1)) + t, 16);
368 rgb = rgb[4][split](commaSpaces);
369 red = toFloat(rgb[0]);
370 green = toFloat(rgb[1]);
371 blue = toFloat(rgb[2]);
372 opacity = toFloat(rgb[3]);
375 rgb = rgb[5][split](commaSpaces);
376 red = toFloat(rgb[0]) * 2.55;
377 green = toFloat(rgb[1]) * 2.55;
378 blue = toFloat(rgb[2]) * 2.55;
379 opacity = toFloat(rgb[3]);
382 rgb = rgb[6][split](commaSpaces);
383 red = toFloat(rgb[0]);
384 green = toFloat(rgb[1]);
385 blue = toFloat(rgb[2]);
386 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
387 return R.hsb2rgb(red, green, blue);
390 rgb = rgb[7][split](commaSpaces);
391 red = toFloat(rgb[0]) * 2.55;
392 green = toFloat(rgb[1]) * 2.55;
393 blue = toFloat(rgb[2]) * 2.55;
394 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
395 return R.hsb2rgb(red, green, blue);
398 rgb = rgb[8][split](commaSpaces);
399 red = toFloat(rgb[0]);
400 green = toFloat(rgb[1]);
401 blue = toFloat(rgb[2]);
402 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360);
403 return R.hsl2rgb(red, green, blue);
406 rgb = rgb[9][split](commaSpaces);
407 red = toFloat(rgb[0]) * 2.55;
408 green = toFloat(rgb[1]) * 2.55;
409 blue = toFloat(rgb[2]) * 2.55;
410 (rgb[0].slice(-3) == "deg" || rgb[0].slice(-1) == "\xb0") && (red /= 360 * 2.55);
411 return R.hsl2rgb(red, green, blue);
413 rgb = {r: red, g: green, b: blue};
414 var r = (~~red)[toString](16),
415 g = (~~green)[toString](16),
416 b = (~~blue)[toString](16);
420 rgb.hex = "#" + r + g + b;
421 isFinite(toFloat(opacity)) && (rgb.o = opacity);
424 return {r: -1, g: -1, b: -1, hex: "none", error: 1};
426 R.getColor = function (value) {
427 var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
428 rgb = this.hsb2rgb(start.h, start.s, start.b);
433 start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
437 R.getColor.reset = function () {
441 var pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
442 pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig;
443 R.parsePathString = cacher(function (pathString) {
447 var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
449 if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
450 data = pathClone(pathString);
453 Str(pathString)[rp](pathCommand, function (a, b, c) {
455 name = lowerCase.call(b);
456 c[rp](pathValues, function (a, b) {
457 b && params[push](+b);
459 if (name == "m" && params[length] > 2) {
460 data[push]([b][concat](params.splice(0, 2)));
462 b = b == "m" ? "l" : "L";
464 while (params[length] >= paramCounts[name]) {
465 data[push]([b][concat](params.splice(0, paramCounts[name])));
466 if (!paramCounts[name]) {
472 data[toString] = R._path2string;
475 R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
477 x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
478 y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
479 mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
480 my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
481 nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
482 ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
483 ax = (1 - t) * p1x + t * c1x,
484 ay = (1 - t) * p1y + t * c1y,
485 cx = (1 - t) * c2x + t * p2x,
486 cy = (1 - t) * c2y + t * p2y,
487 alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
488 (mx > nx || my < ny) && (alpha += 180);
489 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};
491 var pathDimensions = cacher(function (path) {
493 return {x: 0, y: 0, width: 0, height: 0};
495 path = path2curve(path);
501 for (var i = 0, ii = path[length]; i < ii; i++) {
509 var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
510 X = X[concat](dim.min.x, dim.max.x);
511 Y = Y[concat](dim.min.y, dim.max.y);
516 var xmin = mmin[apply](0, X),
517 ymin = mmin[apply](0, Y);
521 width: mmax[apply](0, X) - xmin,
522 height: mmax[apply](0, Y) - ymin
525 pathClone = function (pathArray) {
527 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
528 pathArray = R.parsePathString(pathArray);
530 for (var i = 0, ii = pathArray[length]; i < ii; i++) {
532 for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
533 res[i][j] = pathArray[i][j];
536 res[toString] = R._path2string;
539 pathToRelative = cacher(function (pathArray) {
540 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
541 pathArray = R.parsePathString(pathArray);
549 if (pathArray[0][0] == "M") {
555 res[push](["M", x, y]);
557 for (var i = start, ii = pathArray[length]; i < ii; i++) {
560 if (pa[0] != lowerCase.call(pa[0])) {
561 r[0] = lowerCase.call(pa[0]);
569 r[6] = +(pa[6] - x).toFixed(3);
570 r[7] = +(pa[7] - y).toFixed(3);
573 r[1] = +(pa[1] - y).toFixed(3);
579 for (var j = 1, jj = pa[length]; j < jj; j++) {
580 r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
589 for (var k = 0, kk = pa[length]; k < kk; k++) {
593 var len = res[i][length];
600 x += +res[i][len - 1];
603 y += +res[i][len - 1];
606 x += +res[i][len - 2];
607 y += +res[i][len - 1];
610 res[toString] = R._path2string;
613 pathToAbsolute = cacher(function (pathArray) {
614 if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
615 pathArray = R.parsePathString(pathArray);
623 if (pathArray[0][0] == "M") {
624 x = +pathArray[0][1];
625 y = +pathArray[0][2];
629 res[0] = ["M", x, y];
631 for (var i = start, ii = pathArray[length]; i < ii; i++) {
634 if (pa[0] != upperCase.call(pa[0])) {
635 r[0] = upperCase.call(pa[0]);
656 for (var j = 1, jj = pa[length]; j < jj; j++) {
657 r[j] = +pa[j] + ((j % 2) ? x : y);
661 for (var k = 0, kk = pa[length]; k < kk; k++) {
677 mx = res[i][res[i][length] - 2];
678 my = res[i][res[i][length] - 1];
680 x = res[i][res[i][length] - 2];
681 y = res[i][res[i][length] - 1];
684 res[toString] = R._path2string;
687 l2c = function (x1, y1, x2, y2) {
688 return [x1, y1, x2, y2, x2, y2];
690 q2c = function (x1, y1, ax, ay, x2, y2) {
702 a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
703 // for more information of where this math came from visit:
704 // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
706 _120 = PI * 120 / 180,
707 rad = PI / 180 * (+angle || 0),
710 rotate = cacher(function (x, y, rad) {
711 var X = x * math.cos(rad) - y * math.sin(rad),
712 Y = x * math.sin(rad) + y * math.cos(rad);
716 xy = rotate(x1, y1, -rad);
719 xy = rotate(x2, y2, -rad);
722 var cos = math.cos(PI / 180 * angle),
723 sin = math.sin(PI / 180 * angle),
726 var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
734 k = (large_arc_flag == sweep_flag ? -1 : 1) *
735 math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
736 cx = k * rx * y / ry + (x1 + x2) / 2,
737 cy = k * -ry * x / rx + (y1 + y2) / 2,
738 f1 = math.asin(((y1 - cy) / ry).toFixed(7)),
739 f2 = math.asin(((y2 - cy) / ry).toFixed(7));
741 f1 = x1 < cx ? PI - f1 : f1;
742 f2 = x2 < cx ? PI - f2 : f2;
743 f1 < 0 && (f1 = PI * 2 + f1);
744 f2 < 0 && (f2 = PI * 2 + f2);
745 if (sweep_flag && f1 > f2) {
748 if (!sweep_flag && f2 > f1) {
758 if (math.abs(df) > _120) {
762 f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
763 x2 = cx + rx * math.cos(f2);
764 y2 = cy + ry * math.sin(f2);
765 res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
768 var c1 = math.cos(f1),
772 t = math.tan(df / 4),
776 m2 = [x1 + hx * s1, y1 - hy * c1],
777 m3 = [x2 + hx * s2, y2 - hy * c2],
779 m2[0] = 2 * m1[0] - m2[0];
780 m2[1] = 2 * m1[1] - m2[1];
782 return [m2, m3, m4][concat](res);
784 res = [m2, m3, m4][concat](res)[join]()[split](",");
786 for (var i = 0, ii = res[length]; i < ii; i++) {
787 newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
792 findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
795 x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
796 y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
799 curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
800 var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
801 b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
803 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
804 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
808 math.abs(t1) > "1e12" && (t1 = .5);
809 math.abs(t2) > "1e12" && (t2 = .5);
810 if (t1 > 0 && t1 < 1) {
811 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
815 if (t2 > 0 && t2 < 1) {
816 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
820 a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
821 b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
823 t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
824 t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
825 math.abs(t1) > "1e12" && (t1 = .5);
826 math.abs(t2) > "1e12" && (t2 = .5);
827 if (t1 > 0 && t1 < 1) {
828 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
832 if (t2 > 0 && t2 < 1) {
833 dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
838 min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
839 max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
842 path2curve = cacher(function (path, path2) {
843 var p = pathToAbsolute(path),
844 p2 = path2 && pathToAbsolute(path2),
845 attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
846 attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
847 processPath = function (path, d) {
850 return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
852 !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
859 path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
862 nx = d.x + (d.x - (d.bx || d.x));
863 ny = d.y + (d.y - (d.by || d.y));
864 path = ["C", nx, ny][concat](path.slice(1));
867 d.qx = d.x + (d.x - (d.qx || d.x));
868 d.qy = d.y + (d.y - (d.qy || d.y));
869 path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
874 path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
877 path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
880 path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
883 path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
886 path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
891 fixArc = function (pp, i) {
892 if (pp[i][length] > 7) {
896 pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
899 ii = mmax(p[length], p2 && p2[length] || 0);
902 fixM = function (path1, path2, a1, a2, i) {
903 if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
904 path2.splice(i, 0, ["M", a2.x, a2.y]);
909 ii = mmax(p[length], p2 && p2[length] || 0);
912 for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
913 p[i] = processPath(p[i], attrs);
915 p2 && (p2[i] = processPath(p2[i], attrs2));
917 fixM(p, p2, attrs, attrs2, i);
918 fixM(p2, p, attrs2, attrs, i);
921 seglen = seg[length],
922 seg2len = p2 && seg2[length];
923 attrs.x = seg[seglen - 2];
924 attrs.y = seg[seglen - 1];
925 attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
926 attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
927 attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
928 attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
929 attrs2.x = p2 && seg2[seg2len - 2];
930 attrs2.y = p2 && seg2[seg2len - 1];
932 return p2 ? [p, p2] : p;
934 parseDots = cacher(function (gradient) {
936 for (var i = 0, ii = gradient[length]; i < ii; i++) {
938 par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
939 dot.color = R.getRGB(par[1]);
940 if (dot.color.error) {
943 dot.color = dot.color.hex;
944 par[2] && (dot.offset = par[2] + "%");
947 for (i = 1, ii = dots[length] - 1; i < ii; i++) {
948 if (!dots[i].offset) {
949 var start = toFloat(dots[i - 1].offset || 0),
951 for (var j = i + 1; j < ii; j++) {
952 if (dots[j].offset) {
953 end = dots[j].offset;
962 var d = (end - start) / (j - i + 1);
965 dots[i].offset = start + "%";
971 getContainer = function (x, y, w, h) {
973 if (R.is(x, string) || R.is(x, "object")) {
974 container = R.is(x, string) ? doc.getElementById(x) : x;
975 if (container.tagName) {
978 container: container,
979 width: container.style.pixelWidth || container.offsetWidth,
980 height: container.style.pixelHeight || container.offsetHeight
983 return {container: container, width: y, height: w};
987 return {container: 1, x: x, y: y, width: w, height: h};
990 plugins = function (con, add) {
992 for (var prop in add) {
993 if (add[has](prop) && !(prop in con)) {
994 switch (typeof add[prop]) {
997 con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
1001 con[prop] = con[prop] || {};
1002 plugins.call(this, con[prop], add[prop]);
1005 con[prop] = add[prop];
1011 tear = function (el, paper) {
1012 el == paper.top && (paper.top = el.prev);
1013 el == paper.bottom && (paper.bottom = el.next);
1014 el.next && (el.next.prev = el.prev);
1015 el.prev && (el.prev.next = el.next);
1017 tofront = function (el, paper) {
1018 if (paper.top === el) {
1023 el.prev = paper.top;
1024 paper.top.next = el;
1027 toback = function (el, paper) {
1028 if (paper.bottom === el) {
1032 el.next = paper.bottom;
1034 paper.bottom.prev = el;
1037 insertafter = function (el, el2, paper) {
1039 el2 == paper.top && (paper.top = el);
1040 el2.next && (el2.next.prev = el);
1045 insertbefore = function (el, el2, paper) {
1047 el2 == paper.bottom && (paper.bottom = el);
1048 el2.prev && (el2.prev.next = el);
1053 removed = function (methodname) {
1054 return function () {
1055 throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
1058 radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
1059 R.pathToRelative = pathToRelative;
1062 Paper[proto].svgns = "http://www.w3.org/2000/svg";
1063 Paper[proto].xlink = "http://www.w3.org/1999/xlink";
1064 round = function (num) {
1065 return +num + (~~num === num) * .5;
1067 var $ = function (el, attr) {
1069 for (var key in attr) {
1070 if (attr[has](key)) {
1071 el[setAttribute](key, Str(attr[key]));
1075 el = doc.createElementNS(Paper[proto].svgns, el);
1076 el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
1080 R[toString] = function () {
1081 return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
1083 var thePath = function (pathString, SVG) {
1085 SVG.canvas && SVG.canvas[appendChild](el);
1086 var p = new Element(el, SVG);
1088 setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
1091 var addGradientFill = function (o, gradient, SVG) {
1092 var type = "linear",
1095 gradient = Str(gradient)[rp](radial_gradient, function (all, _fx, _fy) {
1100 var dir = ((fy > .5) * 2 - 1);
1101 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
1102 (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
1104 (fy = fy.toFixed(5) - 1e-5 * dir);
1108 gradient = gradient[split](/\s*\-\s*/);
1109 if (type == "linear") {
1110 var angle = gradient.shift();
1111 angle = -toFloat(angle);
1115 var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
1116 max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1);
1119 if (vector[2] < 0) {
1120 vector[0] = -vector[2];
1123 if (vector[3] < 0) {
1124 vector[1] = -vector[3];
1128 var dots = parseDots(gradient);
1132 var id = o.getAttribute(fillString);
1133 id = id.match(/^url\(#(.*)\)$/);
1134 id && SVG.defs.removeChild(doc.getElementById(id[1]));
1136 var el = $(type + "Gradient");
1137 el.id = "r" + (R._id++)[toString](36);
1138 $(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
1139 SVG.defs[appendChild](el);
1140 for (var i = 0, ii = dots[length]; i < ii; i++) {
1141 var stop = $("stop");
1143 offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
1144 "stop-color": dots[i].color || "#fff"
1146 el[appendChild](stop);
1149 fill: "url(#" + el.id + ")",
1158 var updatePosition = function (o) {
1159 var bbox = o.getBBox();
1160 $(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
1162 var setFillAndStroke = function (o, params) {
1169 "-..": [3, 1, 1, 1, 1, 1],
1173 "- .": [4, 3, 1, 3],
1174 "--.": [8, 3, 1, 3],
1175 "--..": [8, 3, 1, 3, 1, 3]
1180 addDashes = function (o, value) {
1181 value = dasharray[lowerCase.call(value)];
1183 var width = o.attrs["stroke-width"] || "1",
1184 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
1186 var i = value[length];
1188 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
1190 $(node, {"stroke-dasharray": dashes[join](",")});
1193 params[has]("rotation") && (rot = params.rotation);
1194 var rotxy = Str(rot)[split](separator);
1195 if (!(rotxy.length - 1)) {
1198 rotxy[1] = +rotxy[1];
1199 rotxy[2] = +rotxy[2];
1201 toFloat(rot) && o.rotate(0, true);
1202 for (var att in params) {
1203 if (params[has](att)) {
1204 if (!availableAttrs[has](att)) {
1207 var value = params[att];
1214 o.rotate(value, true);
1219 var pn = node.parentNode;
1220 if (lowerCase.call(pn.tagName) != "a") {
1222 pn.insertBefore(hl, node);
1223 hl[appendChild](node);
1226 pn.setAttributeNS(o.paper.xlink, att, value);
1229 node.style.cursor = value;
1232 var rect = Str(value)[split](separator);
1233 if (rect[length] == 4) {
1234 o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
1235 var el = $("clipPath"),
1237 el.id = "r" + (R._id++)[toString](36);
1244 el[appendChild](rc);
1245 o.paper.defs[appendChild](el);
1246 $(node, {"clip-path": "url(#" + el.id + ")"});
1250 var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
1251 clip && clip.parentNode.removeChild(clip);
1252 $(node, {"clip-path": E});
1257 if (o.type == "path") {
1258 $(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
1262 node[setAttribute](att, value);
1271 value = -attrs.x - (attrs.width || 0);
1274 if (att == "rx" && o.type == "rect") {
1278 rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
1279 node[setAttribute](att, value);
1280 o.pattern && updatePosition(o);
1283 node[setAttribute](att, value);
1292 value = -attrs.y - (attrs.height || 0);
1295 if (att == "ry" && o.type == "rect") {
1299 rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
1300 node[setAttribute](att, value);
1301 o.pattern && updatePosition(o);
1304 if (o.type == "rect") {
1305 $(node, {rx: value, ry: value});
1307 node[setAttribute](att, value);
1311 if (o.type == "image") {
1312 node.setAttributeNS(o.paper.xlink, "href", value);
1315 case "stroke-width":
1316 node.style.strokeWidth = value;
1317 // Need following line for Firefox
1318 node[setAttribute](att, value);
1319 if (attrs["stroke-dasharray"]) {
1320 addDashes(o, attrs["stroke-dasharray"]);
1323 case "stroke-dasharray":
1324 addDashes(o, value);
1327 var xy = Str(value)[split](separator);
1328 xy[0] = +xy[0] || 0;
1329 xy[1] = +xy[1] || 0;
1334 translate.call(o, xy[0], xy[1]);
1337 xy = Str(value)[split](separator);
1338 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
1341 var isURL = Str(value).match(ISURL);
1344 var ig = $("image");
1345 el.id = "r" + (R._id++)[toString](36);
1346 $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
1347 $(ig, {x: 0, y: 0});
1348 ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
1349 el[appendChild](ig);
1351 var img = doc.createElement("img");
1352 img.style.cssText = "position:absolute;left:-9999em;top-9999em";
1353 img.onload = function () {
1354 $(el, {width: this.offsetWidth, height: this.offsetHeight});
1355 $(ig, {width: this.offsetWidth, height: this.offsetHeight});
1356 doc.body.removeChild(this);
1359 doc.body[appendChild](img);
1361 o.paper.defs[appendChild](el);
1362 node.style.fill = "url(#" + el.id + ")";
1363 $(node, {fill: "url(#" + el.id + ")"});
1365 o.pattern && updatePosition(o);
1368 var clr = R.getRGB(value);
1370 delete params.gradient;
1371 delete attrs.gradient;
1372 !R.is(attrs.opacity, "undefined") &&
1373 R.is(params.opacity, "undefined") &&
1374 $(node, {opacity: attrs.opacity});
1375 !R.is(attrs["fill-opacity"], "undefined") &&
1376 R.is(params["fill-opacity"], "undefined") &&
1377 $(node, {"fill-opacity": attrs["fill-opacity"]});
1378 } else if ((({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper)) {
1379 attrs.gradient = value;
1380 attrs.fill = "none";
1383 clr[has]("o") && $(node, {"fill-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1385 clr = R.getRGB(value);
1386 node[setAttribute](att, clr.hex);
1387 att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o > 1 ? clr.o / 100 : clr.o});
1390 (({circle: 1, ellipse: 1})[has](o.type) || Str(value).charAt() != "r") && addGradientFill(node, value, o.paper);
1393 case "fill-opacity":
1394 if (attrs.gradient) {
1395 var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
1397 var stops = gradient.getElementsByTagName("stop");
1398 stops[stops[length] - 1][setAttribute]("stop-opacity", value);
1403 att == "font-size" && (value = toInt(value, 10) + "px");
1404 var cssrule = att[rp](/(\-.)/g, function (w) {
1405 return upperCase.call(w.substring(1));
1407 node.style[cssrule] = value;
1408 // Need following line for Firefox
1409 node[setAttribute](att, value);
1415 tuneText(o, params);
1417 o.rotate(rotxy.join(S));
1419 toFloat(rot) && o.rotate(rot, true);
1423 tuneText = function (el, params) {
1424 if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
1429 fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
1431 if (params[has]("text")) {
1432 a.text = params.text;
1433 while (node.firstChild) {
1434 node.removeChild(node.firstChild);
1436 var texts = Str(params.text)[split]("\n");
1437 for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
1438 var tspan = $("tspan");
1439 i && $(tspan, {dy: fontSize * leading, x: a.x});
1440 tspan[appendChild](doc.createTextNode(texts[i]));
1441 node[appendChild](tspan);
1444 texts = node.getElementsByTagName("tspan");
1445 for (i = 0, ii = texts[length]; i < ii; i++) {
1446 i && $(texts[i], {dy: fontSize * leading, x: a.x});
1450 var bb = el.getBBox(),
1451 dif = a.y - (bb.y + bb.height / 2);
1452 dif && isFinite(dif) && $(node, {y: a.y + dif});
1454 Element = function (node, svg) {
1460 node.raphael = this;
1462 this.attrs = this.attrs || {};
1463 this.transformations = []; // rotate, translate, scale
1467 rt: {deg: 0, cx: 0, cy: 0},
1471 !svg.bottom && (svg.bottom = this);
1472 this.prev = svg.top;
1473 svg.top && (svg.top.next = this);
1477 Element[proto].rotate = function (deg, cx, cy) {
1483 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
1485 return this._.rt.deg;
1487 var bbox = this.getBBox();
1488 deg = Str(deg)[split](separator);
1489 if (deg[length] - 1) {
1490 cx = toFloat(deg[1]);
1491 cy = toFloat(deg[2]);
1493 deg = toFloat(deg[0]);
1494 if (cx != null && cx !== false) {
1495 this._.rt.deg = deg;
1497 this._.rt.deg += deg;
1499 (cy == null) && (cx = null);
1502 cx = cx == null ? bbox.x + bbox.width / 2 : cx;
1503 cy = cy == null ? bbox.y + bbox.height / 2 : cy;
1504 if (this._.rt.deg) {
1505 this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
1506 this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
1508 this.transformations[0] = E;
1509 this.clip && $(this.clip, {transform: E});
1511 $(this.node, {transform: this.transformations[join](S)});
1514 Element[proto].hide = function () {
1515 !this.removed && (this.node.style.display = "none");
1518 Element[proto].show = function () {
1519 !this.removed && (this.node.style.display = "");
1522 Element[proto].remove = function () {
1526 tear(this, this.paper);
1527 this.node.parentNode.removeChild(this.node);
1528 for (var i in this) {
1531 this.removed = true;
1533 Element[proto].getBBox = function () {
1537 if (this.type == "path") {
1538 return pathDimensions(this.attrs.path);
1540 if (this.node.style.display == "none") {
1546 bbox = this.node.getBBox();
1548 // Firefox 3.0.x plays badly here
1552 if (this.type == "text") {
1553 bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
1554 for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
1555 var bb = this.node.getExtentOfChar(i);
1556 (bb.y < bbox.y) && (bbox.y = bb.y);
1557 (bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
1558 (bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
1561 hide && this.hide();
1564 Element[proto].attr = function (name, value) {
1570 for (var i in this.attrs) if (this.attrs[has](i)) {
1571 res[i] = this.attrs[i];
1573 this._.rt.deg && (res.rotation = this.rotate());
1574 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
1575 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
1578 if (value == null && R.is(name, string)) {
1579 if (name == "translation") {
1580 return translate.call(this);
1582 if (name == "rotation") {
1583 return this.rotate();
1585 if (name == "scale") {
1586 return this.scale();
1588 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
1589 return this.attrs.gradient;
1591 return this.attrs[name];
1593 if (value == null && R.is(name, array)) {
1595 for (var j = 0, jj = name.length; j < jj; j++) {
1596 values[name[j]] = this.attr(name[j]);
1600 if (value != null) {
1602 params[name] = value;
1603 } else if (name != null && R.is(name, "object")) {
1606 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1607 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
1608 this.attrs[key] = params[key];
1609 for (var subkey in par) if (par[has](subkey)) {
1610 params[subkey] = par[subkey];
1613 setFillAndStroke(this, params);
1616 Element[proto].toFront = function () {
1620 this.node.parentNode[appendChild](this.node);
1621 var svg = this.paper;
1622 svg.top != this && tofront(this, svg);
1625 Element[proto].toBack = function () {
1629 if (this.node.parentNode.firstChild != this.node) {
1630 this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1631 toback(this, this.paper);
1632 var svg = this.paper;
1636 Element[proto].insertAfter = function (element) {
1640 var node = element.node || element[element.length].node;
1641 if (node.nextSibling) {
1642 node.parentNode.insertBefore(this.node, node.nextSibling);
1644 node.parentNode[appendChild](this.node);
1646 insertafter(this, element, this.paper);
1649 Element[proto].insertBefore = function (element) {
1653 var node = element.node || element[0].node;
1654 node.parentNode.insertBefore(this.node, node);
1655 insertbefore(this, element, this.paper);
1658 Element[proto].blur = function (size) {
1659 // Experimental. No Safari support. Use it on your own risk.
1662 var fltr = $("filter"),
1663 blur = $("feGaussianBlur");
1664 t.attrs.blur = size;
1665 fltr.id = "r" + (R._id++)[toString](36);
1666 $(blur, {stdDeviation: +size || 1.5});
1667 fltr.appendChild(blur);
1668 t.paper.defs.appendChild(fltr);
1670 $(t.node, {filter: "url(#" + fltr.id + ")"});
1673 t._blur.parentNode.removeChild(t._blur);
1675 delete t.attrs.blur;
1677 t.node.removeAttribute("filter");
1680 var theCircle = function (svg, x, y, r) {
1681 var el = $("circle");
1682 svg.canvas && svg.canvas[appendChild](el);
1683 var res = new Element(el, svg);
1684 res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1685 res.type = "circle";
1689 var theRect = function (svg, x, y, w, h, r) {
1691 svg.canvas && svg.canvas[appendChild](el);
1692 var res = new Element(el, svg);
1693 res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1698 var theEllipse = function (svg, x, y, rx, ry) {
1699 var el = $("ellipse");
1700 svg.canvas && svg.canvas[appendChild](el);
1701 var res = new Element(el, svg);
1702 res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1703 res.type = "ellipse";
1707 var theImage = function (svg, src, x, y, w, h) {
1708 var el = $("image");
1709 $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1710 el.setAttributeNS(svg.xlink, "href", src);
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, src: src};
1717 var theText = function (svg, x, y, text) {
1719 $(el, {x: x, y: y, "text-anchor": "middle"});
1720 svg.canvas && svg.canvas[appendChild](el);
1721 var res = new Element(el, svg);
1722 res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
1724 setFillAndStroke(res, res.attrs);
1727 var setSize = function (width, height) {
1728 this.width = width || this.width;
1729 this.height = height || this.height;
1730 this.canvas[setAttribute]("width", this.width);
1731 this.canvas[setAttribute]("height", this.height);
1734 var create = function () {
1735 var con = getContainer[apply](0, arguments),
1736 container = con && con.container,
1740 height = con.height;
1742 throw new Error("SVG container not found.");
1744 var cnvs = $("svg");
1747 width = width || 512;
1748 height = height || 342;
1750 xmlns: "http://www.w3.org/2000/svg",
1755 if (container == 1) {
1756 cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
1757 doc.body[appendChild](cnvs);
1759 if (container.firstChild) {
1760 container.insertBefore(cnvs, container.firstChild);
1762 container[appendChild](cnvs);
1765 container = new Paper;
1766 container.width = width;
1767 container.height = height;
1768 container.canvas = cnvs;
1769 plugins.call(container, container, R.fn);
1773 Paper[proto].clear = function () {
1774 var c = this.canvas;
1775 while (c.firstChild) {
1776 c.removeChild(c.firstChild);
1778 this.bottom = this.top = null;
1779 (this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
1780 c[appendChild](this.desc);
1781 c[appendChild](this.defs = $("defs"));
1783 Paper[proto].remove = function () {
1784 this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1785 for (var i in this) {
1786 this[i] = removed(i);
1793 var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
1794 bites = /([clmz]),?([^clmz]*)/gi,
1795 val = /-?[^,\s-]+/g,
1796 coordsize = 1e3 + S + 1e3,
1798 pathlike = {path: 1, rect: 1},
1799 path2vml = function (path) {
1800 var total = /[ahqstv]/ig,
1801 command = pathToAbsolute;
1802 Str(path).match(total) && (command = path2curve);
1804 if (command == pathToAbsolute && !Str(path).match(total)) {
1805 var res = Str(path)[rp](bites, function (all, command, args) {
1807 isMove = lowerCase.call(command) == "m",
1809 args[rp](val, function (value) {
1810 if (isMove && vals[length] == 2) {
1811 res += vals + map[command == "m" ? "l" : "L"];
1814 vals[push](round(value * zoom));
1820 var pa = command(path), p, r;
1822 for (var i = 0, ii = pa[length]; i < ii; i++) {
1824 r = lowerCase.call(pa[i][0]);
1825 r == "z" && (r = "x");
1826 for (var j = 1, jj = p[length]; j < jj; j++) {
1827 r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
1831 return res[join](S);
1834 R[toString] = function () {
1835 return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
1837 thePath = function (pathString, vml) {
1838 var g = createNode("group");
1839 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
1840 g.coordsize = vml.coordsize;
1841 g.coordorigin = vml.coordorigin;
1842 var el = createNode("shape"), ol = el.style;
1843 ol.width = vml.width + "px";
1844 ol.height = vml.height + "px";
1845 el.coordsize = coordsize;
1846 el.coordorigin = vml.coordorigin;
1848 var p = new Element(el, g, vml),
1849 attr = {fill: "none", stroke: "#000"};
1850 pathString && (attr.path = pathString);
1854 setFillAndStroke(p, attr);
1855 vml.canvas[appendChild](g);
1858 setFillAndStroke = function (o, params) {
1859 o.attrs = o.attrs || {};
1864 newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
1867 for (var par in params) if (params[has](par)) {
1868 a[par] = params[par];
1871 a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
1877 params.href && (node.href = params.href);
1878 params.title && (node.title = params.title);
1879 params.target && (node.target = params.target);
1880 params.cursor && (s.cursor = params.cursor);
1881 "blur" in params && o.blur(params.blur);
1882 if (params.path && o.type == "path" || newpath) {
1883 node.path = path2vml(a.path);
1885 if (params.rotation != null) {
1886 o.rotate(params.rotation, true);
1888 if (params.translation) {
1889 xy = Str(params.translation)[split](separator);
1890 translate.call(o, xy[0], xy[1]);
1891 if (o._.rt.cx != null) {
1892 o._.rt.cx +=+ xy[0];
1893 o._.rt.cy +=+ xy[1];
1894 o.setBox(o.attrs, xy[0], xy[1]);
1898 xy = Str(params.scale)[split](separator);
1899 o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
1901 if ("clip-rect" in params) {
1902 var rect = Str(params["clip-rect"])[split](separator);
1903 if (rect[length] == 4) {
1904 rect[2] = +rect[2] + (+rect[0]);
1905 rect[3] = +rect[3] + (+rect[1]);
1906 var div = node.clipRect || doc.createElement("div"),
1908 group = node.parentNode;
1909 dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
1910 if (!node.clipRect) {
1911 dstyle.position = "absolute";
1914 dstyle.width = o.paper.width + "px";
1915 dstyle.height = o.paper.height + "px";
1916 group.parentNode.insertBefore(div, group);
1917 div[appendChild](group);
1918 node.clipRect = div;
1921 if (!params["clip-rect"]) {
1922 node.clipRect && (node.clipRect.style.clip = E);
1925 if (o.type == "image" && params.src) {
1926 node.src = params.src;
1928 if (o.type == "image" && params.opacity) {
1929 node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
1930 s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
1932 params.font && (s.font = params.font);
1933 params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"');
1934 params["font-size"] && (s.fontSize = params["font-size"]);
1935 params["font-weight"] && (s.fontWeight = params["font-weight"]);
1936 params["font-style"] && (s.fontStyle = params["font-style"]);
1937 if (params.opacity != null ||
1938 params["stroke-width"] != null ||
1939 params.fill != null ||
1940 params.stroke != null ||
1941 params["stroke-width"] != null ||
1942 params["stroke-opacity"] != null ||
1943 params["fill-opacity"] != null ||
1944 params["stroke-dasharray"] != null ||
1945 params["stroke-miterlimit"] != null ||
1946 params["stroke-linejoin"] != null ||
1947 params["stroke-linecap"] != null) {
1948 node = o.shape || node;
1949 var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
1951 !fill && (newfill = fill = createNode(fillString));
1952 if ("fill-opacity" in params || "opacity" in params) {
1953 var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
1954 opacity < 0 && (opacity = 0);
1955 opacity > 1 && (opacity = 1);
1956 fill.opacity = opacity;
1958 params.fill && (fill.on = true);
1959 if (fill.on == null || params.fill == "none") {
1962 if (fill.on && params.fill) {
1963 var isURL = params.fill.match(ISURL);
1965 fill.src = isURL[1];
1968 fill.color = R.getRGB(params.fill).hex;
1970 fill.type = "solid";
1971 if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill)) {
1973 a.gradient = params.fill;
1977 newfill && node[appendChild](fill);
1978 var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
1980 !stroke && (newstroke = stroke = createNode("stroke"));
1981 if ((params.stroke && params.stroke != "none") ||
1982 params["stroke-width"] ||
1983 params["stroke-opacity"] != null ||
1984 params["stroke-dasharray"] ||
1985 params["stroke-miterlimit"] ||
1986 params["stroke-linejoin"] ||
1987 params["stroke-linecap"]) {
1990 (params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
1991 var strokeColor = R.getRGB(params.stroke);
1992 stroke.on && params.stroke && (stroke.color = strokeColor.hex);
1993 opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
1994 var width = (toFloat(params["stroke-width"]) || 1) * .75;
1995 opacity < 0 && (opacity = 0);
1996 opacity > 1 && (opacity = 1);
1997 params["stroke-width"] == null && (width = a["stroke-width"]);
1998 params["stroke-width"] && (stroke.weight = width);
1999 width && width < 1 && (opacity *= width) && (stroke.weight = 1);
2000 stroke.opacity = opacity;
2002 params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
2003 stroke.miterlimit = params["stroke-miterlimit"] || 8;
2004 params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
2005 if (params["stroke-dasharray"]) {
2009 "-.": "shortdashdot",
2010 "-..": "shortdashdotdot",
2015 "--.": "longdashdot",
2016 "--..": "longdashdotdot"
2018 stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
2020 newstroke && node[appendChild](stroke);
2022 if (res.type == "text") {
2023 s = res.paper.span.style;
2024 a.font && (s.font = a.font);
2025 a["font-family"] && (s.fontFamily = a["font-family"]);
2026 a["font-size"] && (s.fontSize = a["font-size"]);
2027 a["font-weight"] && (s.fontWeight = a["font-weight"]);
2028 a["font-style"] && (s.fontStyle = a["font-style"]);
2029 res.node.string && (res.paper.span.innerHTML = Str(res.node.string)[rp](/</g, "<")[rp](/&/g, "&")[rp](/\n/g, "<br>"));
2030 res.W = a.w = res.paper.span.offsetWidth;
2031 res.H = a.h = res.paper.span.offsetHeight;
2033 res.Y = a.y + round(res.H / 2);
2035 // text-anchor emulationm
2036 switch (a["text-anchor"]) {
2038 res.node.style["v-text-align"] = "left";
2039 res.bbx = round(res.W / 2);
2042 res.node.style["v-text-align"] = "right";
2043 res.bbx = -round(res.W / 2);
2046 res.node.style["v-text-align"] = "center";
2051 addGradientFill = function (o, gradient) {
2052 o.attrs = o.attrs || {};
2053 var attrs = o.attrs,
2057 o.attrs.gradient = gradient;
2058 gradient = Str(gradient)[rp](radial_gradient, function (all, fx, fy) {
2063 pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
2068 gradient = gradient[split](/\s*\-\s*/);
2069 if (type == "linear") {
2070 var angle = gradient.shift();
2071 angle = -toFloat(angle);
2076 var dots = parseDots(gradient);
2080 o = o.shape || o.node;
2081 fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
2082 !fill.parentNode && o.appendChild(fill);
2085 fill.method = "none";
2086 fill.color = dots[0].color;
2087 fill.color2 = dots[dots[length] - 1].color;
2089 for (var i = 0, ii = dots[length]; i < ii; i++) {
2090 dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
2092 fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
2093 if (type == "radial") {
2094 fill.type = "gradientradial";
2095 fill.focus = "100%";
2096 fill.focussize = fxfy;
2097 fill.focusposition = fxfy;
2099 fill.type = "gradient";
2100 fill.angle = (270 - angle) % 360;
2105 Element = function (node, group, vml) {
2113 node.raphael = this;
2126 !vml.bottom && (vml.bottom = this);
2127 this.prev = vml.top;
2128 vml.top && (vml.top.next = this);
2132 Element[proto].rotate = function (deg, cx, cy) {
2138 return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
2140 return this._.rt.deg;
2142 deg = Str(deg)[split](separator);
2143 if (deg[length] - 1) {
2144 cx = toFloat(deg[1]);
2145 cy = toFloat(deg[2]);
2147 deg = toFloat(deg[0]);
2149 this._.rt.deg = deg;
2151 this._.rt.deg += deg;
2153 cy == null && (cx = null);
2156 this.setBox(this.attrs, cx, cy);
2157 this.Group.style.rotation = this._.rt.deg;
2158 // gradient fix for rotation. TODO
2159 // var fill = (this.shape || this.node).getElementsByTagName(fillString);
2160 // fill = fill[0] || {};
2161 // var b = ((360 - this._.rt.deg) - 270) % 360;
2162 // !R.is(fill.angle, "undefined") && (fill.angle = b);
2165 Element[proto].setBox = function (params, cx, cy) {
2169 var gs = this.Group.style,
2170 os = (this.shape && this.shape.style) || this.node.style;
2171 params = params || {};
2172 for (var i in params) if (params[has](i)) {
2173 this.attrs[i] = params[i];
2175 cx = cx || this._.rt.cx;
2176 cy = cy || this._.rt.cy;
2177 var attr = this.attrs,
2182 switch (this.type) {
2184 x = attr.cx - attr.r;
2185 y = attr.cy - attr.r;
2189 x = attr.cx - attr.rx;
2190 y = attr.cy - attr.ry;
2197 w = attr.width || 0;
2198 h = attr.height || 0;
2201 this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
2202 x = attr.x - round(this.W / 2);
2203 y = attr.y - this.H / 2;
2209 if (!this.attrs.path) {
2212 w = this.paper.width;
2213 h = this.paper.height;
2215 var dim = pathDimensions(this.attrs.path);
2225 w = this.paper.width;
2226 h = this.paper.height;
2229 cx = (cx == null) ? x + w / 2 : cx;
2230 cy = (cy == null) ? y + h / 2 : cy;
2231 var left = cx - this.paper.width / 2,
2232 top = cy - this.paper.height / 2, t;
2233 gs.left != (t = left + "px") && (gs.left = t);
2234 gs.top != (t = top + "px") && (gs.top = t);
2235 this.X = pathlike[has](this.type) ? -left : x;
2236 this.Y = pathlike[has](this.type) ? -top : y;
2239 if (pathlike[has](this.type)) {
2240 os.left != (t = -left * zoom + "px") && (os.left = t);
2241 os.top != (t = -top * zoom + "px") && (os.top = t);
2242 } else if (this.type == "text") {
2243 os.left != (t = -left + "px") && (os.left = t);
2244 os.top != (t = -top + "px") && (os.top = t);
2246 gs.width != (t = this.paper.width + "px") && (gs.width = t);
2247 gs.height != (t = this.paper.height + "px") && (gs.height = t);
2248 os.left != (t = x - left + "px") && (os.left = t);
2249 os.top != (t = y - top + "px") && (os.top = t);
2250 os.width != (t = w + "px") && (os.width = t);
2251 os.height != (t = h + "px") && (os.height = t);
2254 Element[proto].hide = function () {
2255 !this.removed && (this.Group.style.display = "none");
2258 Element[proto].show = function () {
2259 !this.removed && (this.Group.style.display = "block");
2262 Element[proto].getBBox = function () {
2266 if (pathlike[has](this.type)) {
2267 return pathDimensions(this.attrs.path);
2270 x: this.X + (this.bbx || 0),
2276 Element[proto].remove = function () {
2280 tear(this, this.paper);
2281 this.node.parentNode.removeChild(this.node);
2282 this.Group.parentNode.removeChild(this.Group);
2283 this.shape && this.shape.parentNode.removeChild(this.shape);
2284 for (var i in this) {
2287 this.removed = true;
2289 Element[proto].attr = function (name, value) {
2295 for (var i in this.attrs) if (this.attrs[has](i)) {
2296 res[i] = this.attrs[i];
2298 this._.rt.deg && (res.rotation = this.rotate());
2299 (this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
2300 res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
2303 if (value == null && R.is(name, "string")) {
2304 if (name == "translation") {
2305 return translate.call(this);
2307 if (name == "rotation") {
2308 return this.rotate();
2310 if (name == "scale") {
2311 return this.scale();
2313 if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
2314 return this.attrs.gradient;
2316 return this.attrs[name];
2318 if (this.attrs && value == null && R.is(name, array)) {
2319 var ii, values = {};
2320 for (i = 0, ii = name[length]; i < ii; i++) {
2321 values[name[i]] = this.attr(name[i]);
2326 if (value != null) {
2328 params[name] = value;
2330 value == null && R.is(name, "object") && (params = name);
2332 for (var key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
2333 var par = this.paper.customAttributes[key].apply(this, [][concat](params[key]));
2334 this.attrs[key] = params[key];
2335 for (var subkey in par) if (par[has](subkey)) {
2336 params[subkey] = par[subkey];
2339 if (params.text && this.type == "text") {
2340 this.node.string = params.text;
2342 setFillAndStroke(this, params);
2343 if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || Str(params.gradient).charAt() != "r")) {
2344 addGradientFill(this, params.gradient);
2346 (!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
2350 Element[proto].toFront = function () {
2351 !this.removed && this.Group.parentNode[appendChild](this.Group);
2352 this.paper.top != this && tofront(this, this.paper);
2355 Element[proto].toBack = function () {
2359 if (this.Group.parentNode.firstChild != this.Group) {
2360 this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
2361 toback(this, this.paper);
2365 Element[proto].insertAfter = function (element) {
2369 if (element.constructor == Set) {
2370 element = element[element.length];
2372 if (element.Group.nextSibling) {
2373 element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
2375 element.Group.parentNode[appendChild](this.Group);
2377 insertafter(this, element, this.paper);
2380 Element[proto].insertBefore = function (element) {
2384 if (element.constructor == Set) {
2385 element = element[0];
2387 element.Group.parentNode.insertBefore(this.Group, element.Group);
2388 insertbefore(this, element, this.paper);
2391 var blurregexp = / progid:\S+Blur\([^\)]+\)/g;
2392 Element[proto].blur = function (size) {
2393 var s = this.node.runtimeStyle,
2395 f = f.replace(blurregexp, E);
2397 this.attrs.blur = size;
2398 s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
2399 s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
2403 delete this.attrs.blur;
2407 theCircle = function (vml, x, y, r) {
2408 var g = createNode("group"),
2409 o = createNode("oval"),
2411 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2412 g.coordsize = coordsize;
2413 g.coordorigin = vml.coordorigin;
2415 var res = new Element(o, g, vml);
2416 res.type = "circle";
2417 setFillAndStroke(res, {stroke: "#000", fill: "none"});
2421 res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
2422 vml.canvas[appendChild](g);
2425 function rectPath(x, y, w, h, r) {
2427 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);
2429 return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
2432 theRect = function (vml, x, y, w, h, r) {
2433 var path = rectPath(x, y, w, h, r),
2434 res = vml.path(path),
2438 res.W = a.width = w;
2439 res.H = a.height = h;
2445 theEllipse = function (vml, x, y, rx, ry) {
2446 var g = createNode("group"),
2447 o = createNode("oval"),
2449 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2450 g.coordsize = coordsize;
2451 g.coordorigin = vml.coordorigin;
2453 var res = new Element(o, g, vml);
2454 res.type = "ellipse";
2455 setFillAndStroke(res, {stroke: "#000"});
2460 res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
2461 vml.canvas[appendChild](g);
2464 theImage = function (vml, src, x, y, w, h) {
2465 var g = createNode("group"),
2466 o = createNode("image");
2467 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2468 g.coordsize = coordsize;
2469 g.coordorigin = vml.coordorigin;
2472 var res = new Element(o, g, vml);
2474 res.attrs.src = src;
2479 res.setBox({x: x, y: y, width: w, height: h});
2480 vml.canvas[appendChild](g);
2483 theText = function (vml, x, y, text) {
2484 var g = createNode("group"),
2485 el = createNode("shape"),
2487 path = createNode("path"),
2489 o = createNode("textpath");
2490 g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
2491 g.coordsize = coordsize;
2492 g.coordorigin = vml.coordorigin;
2493 path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
2494 path.textpathok = true;
2495 ol.width = vml.width;
2496 ol.height = vml.height;
2497 o.string = Str(text);
2500 el[appendChild](path);
2502 var res = new Element(o, g, vml);
2504 res.textpath = path;
2506 res.attrs.text = text;
2511 setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
2513 vml.canvas[appendChild](g);
2516 setSize = function (width, height) {
2517 var cs = this.canvas.style;
2518 width == +width && (width += "px");
2519 height == +height && (height += "px");
2522 cs.clip = "rect(0 " + width + " " + height + " 0)";
2526 doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
2528 !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
2529 createNode = function (tagName) {
2530 return doc.createElement('<rvml:' + tagName + ' class="rvml">');
2533 createNode = function (tagName) {
2534 return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
2537 create = function () {
2538 var con = getContainer[apply](0, arguments),
2539 container = con.container,
2540 height = con.height,
2546 throw new Error("VML container not found.");
2548 var res = new Paper,
2549 c = res.canvas = doc.createElement("div"),
2553 width = width || 512;
2554 height = height || 342;
2555 width == +width && (width += "px");
2556 height == +height && (height += "px");
2559 res.coordsize = zoom * 1e3 + S + zoom * 1e3;
2560 res.coordorigin = "0 0";
2561 res.span = doc.createElement("span");
2562 res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2563 c[appendChild](res.span);
2564 cs.cssText = R.format("width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
2565 if (container == 1) {
2566 doc.body[appendChild](c);
2569 cs.position = "absolute";
2571 if (container.firstChild) {
2572 container.insertBefore(c, container.firstChild);
2574 container[appendChild](c);
2577 plugins.call(res, res, R.fn);
2580 Paper[proto].clear = function () {
2581 this.canvas.innerHTML = E;
2582 this.span = doc.createElement("span");
2583 this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
2584 this.canvas[appendChild](this.span);
2585 this.bottom = this.top = null;
2587 Paper[proto].remove = function () {
2588 this.canvas.parentNode.removeChild(this.canvas);
2589 for (var i in this) {
2590 this[i] = removed(i);
2597 // WebKit rendering bug workaround method
2598 var version = navigator.userAgent.match(/Version\/(.*?)\s/);
2599 if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP")) {
2600 Paper[proto].safari = function () {
2601 var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
2602 win.setTimeout(function () {rect.remove();});
2605 Paper[proto].safari = function () {};
2609 var preventDefault = function () {
2610 this.returnValue = false;
2612 preventTouch = function () {
2613 return this.originalEvent.preventDefault();
2615 stopPropagation = function () {
2616 this.cancelBubble = true;
2618 stopTouch = function () {
2619 return this.originalEvent.stopPropagation();
2621 addEvent = (function () {
2622 if (doc.addEventListener) {
2623 return function (obj, type, fn, element) {
2624 var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
2625 var f = function (e) {
2626 if (supportsTouch && touchMap[has](type)) {
2627 for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
2628 if (e.targetTouches[i].target == obj) {
2630 e = e.targetTouches[i];
2631 e.originalEvent = olde;
2632 e.preventDefault = preventTouch;
2633 e.stopPropagation = stopTouch;
2638 return fn.call(element, e);
2640 obj.addEventListener(realName, f, false);
2641 return function () {
2642 obj.removeEventListener(realName, f, false);
2646 } else if (doc.attachEvent) {
2647 return function (obj, type, fn, element) {
2648 var f = function (e) {
2650 e.preventDefault = e.preventDefault || preventDefault;
2651 e.stopPropagation = e.stopPropagation || stopPropagation;
2652 return fn.call(element, e);
2654 obj.attachEvent("on" + type, f);
2655 var detacher = function () {
2656 obj.detachEvent("on" + type, f);
2664 dragMove = function (e) {
2667 scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2668 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft,
2673 if (supportsTouch) {
2674 var i = e.touches.length,
2677 touch = e.touches[i];
2678 if (touch.identifier == dragi.el._drag.id) {
2681 (e.originalEvent ? e.originalEvent : e).preventDefault();
2690 dragi.move && dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
2693 dragUp = function () {
2694 R.unmousemove(dragMove).unmouseup(dragUp);
2695 var i = drag.length,
2699 dragi.el._drag = {};
2700 dragi.end && dragi.end.call(dragi.el);
2704 for (var i = events[length]; i--;) {
2705 (function (eventName) {
2706 R[eventName] = Element[proto][eventName] = function (fn) {
2707 if (R.is(fn, "function")) {
2708 this.events = this.events || [];
2709 this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
2713 R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
2714 var events = this.events,
2716 while (l--) if (events[l].name == eventName && events[l].f == fn) {
2718 events.splice(l, 1);
2719 !events.length && delete this.events;
2726 Element[proto].hover = function (f_in, f_out) {
2727 return this.mouseover(f_in).mouseout(f_out);
2729 Element[proto].unhover = function (f_in, f_out) {
2730 return this.unmouseover(f_in).unmouseout(f_out);
2732 Element[proto].drag = function (onmove, onstart, onend) {
2734 this.mousedown(function (e) {
2735 (e.originalEvent || e).preventDefault();
2736 var scrollY = doc.documentElement.scrollTop || doc.body.scrollTop,
2737 scrollX = doc.documentElement.scrollLeft || doc.body.scrollLeft;
2738 this._drag.x = e.clientX + scrollX;
2739 this._drag.y = e.clientY + scrollY;
2740 this._drag.id = e.identifier;
2741 onstart && onstart.call(this, e.clientX + scrollX, e.clientY + scrollY);
2742 !drag.length && R.mousemove(dragMove).mouseup(dragUp);
2743 drag.push({el: this, move: onmove, end: onend});
2747 Element[proto].undrag = function (onmove, onstart, onend) {
2748 var i = drag.length;
2750 drag[i].el == this && (drag[i].move == onmove && drag[i].end == onend) && drag.splice(i, 1);
2751 !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
2754 Paper[proto].circle = function (x, y, r) {
2755 return theCircle(this, x || 0, y || 0, r || 0);
2757 Paper[proto].rect = function (x, y, w, h, r) {
2758 return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
2760 Paper[proto].ellipse = function (x, y, rx, ry) {
2761 return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
2763 Paper[proto].path = function (pathString) {
2764 pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
2765 return thePath(R.format[apply](R, arguments), this);
2767 Paper[proto].image = function (src, x, y, w, h) {
2768 return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
2770 Paper[proto].text = function (x, y, text) {
2771 return theText(this, x || 0, y || 0, Str(text));
2773 Paper[proto].set = function (itemsArray) {
2774 arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
2775 return new Set(itemsArray);
2777 Paper[proto].setSize = setSize;
2778 Paper[proto].top = Paper[proto].bottom = null;
2779 Paper[proto].raphael = R;
2781 return this.x + S + this.y;
2783 Element[proto].resetScale = function () {
2789 this.attrs.scale = "1 1";
2791 Element[proto].scale = function (x, y, cx, cy) {
2795 if (x == null && y == null) {
2810 var bb = this.getBBox(),
2811 rcx = bb.x + bb.width / 2,
2812 rcy = bb.y + bb.height / 2,
2815 cx = (+cx || cx == 0) ? cx : rcx;
2816 cy = (+cy || cy == 0) ? cy : rcy;
2817 var dirx = ~~(x / math.abs(x)),
2818 diry = ~~(y / math.abs(y)),
2819 s = this.node.style,
2820 ncx = cx + (rcx - cx) * kx,
2821 ncy = cy + (rcy - cy) * ky;
2822 switch (this.type) {
2825 var neww = a.width * dirx * kx,
2826 newh = a.height * diry * ky;
2829 r: a.r * mmin(dirx * kx, diry * ky),
2838 rx: a.rx * dirx * kx,
2839 ry: a.ry * diry * ky,
2840 r: a.r * mmin(dirx * kx, diry * ky),
2852 var path = pathToRelative(a.path),
2854 for (var i = 0, ii = path[length]; i < ii; i++) {
2856 P0 = upperCase.call(p[0]);
2857 if (P0 == "M" && skip) {
2863 p[path[i][length] - 2] *= kx;
2864 p[path[i][length] - 1] *= ky;
2867 p[5] = +!(dirx + diry ? !+p[5] : +p[5]);
2868 } else if (P0 == "H") {
2869 for (var j = 1, jj = p[length]; j < jj; j++) {
2872 } else if (P0 == "V") {
2873 for (j = 1, jj = p[length]; j < jj; j++) {
2877 for (j = 1, jj = p[length]; j < jj; j++) {
2878 p[j] *= (j % 2) ? kx : ky;
2882 var dim2 = pathDimensions(path);
2883 dx = ncx - dim2.x - dim2.width / 2;
2884 dy = ncy - dim2.y - dim2.height / 2;
2887 this.attr({path: path});
2890 if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
2891 if (this.transformations) {
2892 this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
2893 this.node[setAttribute]("transform", this.transformations[join](S));
2894 dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
2895 dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
2896 this.attr({x: dx, y: dy});
2900 this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
2901 ", M12=0, M21=0, M22=", diry,
2902 ", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
2903 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2906 if (this.transformations) {
2907 this.transformations[2] = E;
2908 this.node[setAttribute]("transform", this.transformations[join](S));
2912 this.node.filterMatrix = E;
2913 s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
2916 a.scale = [x, y, cx, cy][join](S);
2922 Element[proto].clone = function () {
2926 var attr = this.attr();
2928 delete attr.translation;
2929 return this.paper[this.type]().attr(attr);
2931 var getPointAtSegmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
2934 for (var i = 0; i < 1.01; i+=.01) {
2935 var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
2936 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2937 if (len >= length) {
2943 getLengthFactory = function (istotal, subpath) {
2944 return function (path, length, onlystart) {
2945 path = path2curve(path);
2946 var x, y, p, l, sp = "", subpaths = {}, point,
2948 for (var i = 0, ii = path.length; i < ii; i++) {
2954 l = segmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
2955 if (len + l > length) {
2956 if (subpath && !subpaths.start) {
2957 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2958 sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
2959 if (onlystart) {return sp;}
2960 subpaths.start = sp;
2961 sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
2967 if (!istotal && !subpath) {
2968 point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
2969 return {x: point.x, y: point.y, alpha: point.alpha};
2979 point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
2980 point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
2984 segmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
2985 var old = {x: 0, y: 0},
2987 for (var i = 0; i < 1.01; i+=.01) {
2988 var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
2989 i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
2994 var getTotalLength = getLengthFactory(1),
2995 getPointAtLength = getLengthFactory(),
2996 getSubpathsAtLength = getLengthFactory(0, 1);
2997 Element[proto].getTotalLength = function () {
2998 if (this.type != "path") {return;}
2999 if (this.node.getTotalLength) {
3000 return this.node.getTotalLength();
3002 return getTotalLength(this.attrs.path);
3004 Element[proto].getPointAtLength = function (length) {
3005 if (this.type != "path") {return;}
3006 if (this.node.getPointAtLength) {
3007 return this.node.getPointAtLength(length);
3009 return getPointAtLength(this.attrs.path, length);
3011 Element[proto].getSubpath = function (from, to) {
3012 if (this.type != "path") {return;}
3013 if (math.abs(this.getTotalLength() - to) < 1e-6) {
3014 return getSubpathsAtLength(this.attrs.path, from).end;
3016 var a = getSubpathsAtLength(this.attrs.path, to, 1);
3017 return from ? getSubpathsAtLength(a, from).end : a;
3020 // animation easing formulas
3021 R.easing_formulas = {
3022 linear: function (n) {
3029 return pow(n - 1, 3) + 1;
3031 "<>": function (n) {
3034 return pow(n, 3) / 2;
3037 return (pow(n, 3) + 2) / 2;
3039 backIn: function (n) {
3041 return n * n * ((s + 1) * n - s);
3043 backOut: function (n) {
3046 return n * n * ((s + 1) * n + s) + 1;
3048 elastic: function (n) {
3049 if (n == 0 || n == 1) {
3054 return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
3056 bounce: function (n) {
3065 l = s * n * n + .75;
3067 if (n < (2.5 / p)) {
3069 l = s * n * n + .9375;
3072 l = s * n * n + .984375;
3080 var animationElements = {length : 0},
3081 animation = function () {
3082 var Now = +new Date;
3083 for (var l in animationElements) if (l != "length" && animationElements[has](l)) {
3084 var e = animationElements[l];
3085 if (e.stop || e.el.removed) {
3086 delete animationElements[l];
3087 animationElements[length]--;
3090 var time = Now - e.start,
3099 callback = e.callback,
3103 var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
3104 for (var attr in from) if (from[has](attr)) {
3105 switch (availableAnimAttrs[attr]) {
3107 now = pos * ms * diff[attr];
3108 to.back && (now = to.len - now);
3109 var point = getPointAtLength(to[attr], now);
3110 that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
3113 that.translate(point.x - diff.sx, point.y - diff.sy);
3114 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3117 now = +from[attr] + pos * ms * diff[attr];
3121 upto255(round(from[attr].r + pos * ms * diff[attr].r)),
3122 upto255(round(from[attr].g + pos * ms * diff[attr].g)),
3123 upto255(round(from[attr].b + pos * ms * diff[attr].b))
3128 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3129 now[i] = [from[attr][i][0]];
3130 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3131 now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
3133 now[i] = now[i][join](S);
3140 var x = pos * ms * diff[attr][0] - t.x,
3141 y = pos * ms * diff[attr][1] - t.y;
3147 now = +from[attr][0] + pos * ms * diff[attr][0];
3148 from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
3151 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);
3157 now[i] = +from[attr][i] + pos * ms * diff[attr][i];
3163 var from2 = [].concat(from[attr]);
3165 i = that.paper.customAttributes[attr].length;
3167 now[i] = +from2[i] + pos * ms * diff[attr][i];
3174 that._run && that._run.call(that);
3177 point = getPointAtLength(to.along, to.len * !to.back);
3178 that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
3179 to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
3181 (t.x || t.y) && that.translate(-t.x, -t.y);
3182 to.scale && (to.scale += E);
3184 delete animationElements[l];
3185 animationElements[length]--;
3186 that.in_animation = null;
3187 R.is(callback, "function") && callback.call(that);
3191 R.svg && that && that.paper && that.paper.safari();
3192 animationElements[length] && win.setTimeout(animation);
3194 upto255 = function (color) {
3195 return mmax(mmin(color, 255), 0);
3197 translate = function (x, y) {
3199 return {x: this._.tx, y: this._.ty, toString: x_y};
3203 switch (this.type) {
3206 this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
3211 this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
3214 var path = pathToRelative(this.attrs.path);
3217 this.attr({path: path});
3222 Element[proto].animateWith = function (element, params, ms, easing, callback) {
3223 animationElements[element.id] && (params.start = animationElements[element.id].start);
3224 return this.animate(params, ms, easing, callback);
3226 Element[proto].animateAlong = along();
3227 Element[proto].animateAlongBack = along(1);
3228 function along(isBack) {
3229 return function (path, ms, rotate, callback) {
3230 var params = {back: isBack};
3231 R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
3232 path && path.constructor == Element && (path = path.attrs.path);
3233 path && (params.along = path);
3234 return this.animate(params, ms, callback);
3237 Element[proto].onAnimation = function (f) {
3241 Element[proto].animate = function (params, ms, easing, callback) {
3242 if (R.is(easing, "function") || !easing) {
3243 callback = easing || null;
3248 for (var attr in params) if (params[has](attr)) {
3249 if (availableAnimAttrs[has](attr) || this.paper.customAttributes[has](attr)) {
3250 from[attr] = this.attr(attr);
3251 (from[attr] == null) && (from[attr] = availableAttrs[attr]);
3252 to[attr] = params[attr];
3253 switch (availableAnimAttrs[attr]) {
3255 var len = getTotalLength(params[attr]);
3256 var point = getPointAtLength(params[attr], len * !!params.back);
3257 var bb = this.getBBox();
3258 diff[attr] = len / ms;
3263 to.rot = params.rot;
3264 to.back = params.back;
3266 params.rot && (diff.r = toFloat(this.rotate()) || 0);
3269 diff[attr] = (to[attr] - from[attr]) / ms;
3272 from[attr] = R.getRGB(from[attr]);
3273 var toColour = R.getRGB(to[attr]);
3275 r: (toColour.r - from[attr].r) / ms,
3276 g: (toColour.g - from[attr].g) / ms,
3277 b: (toColour.b - from[attr].b) / ms
3281 var pathes = path2curve(from[attr], to[attr]);
3282 from[attr] = pathes[0];
3283 var toPath = pathes[1];
3285 for (var i = 0, ii = from[attr][length]; i < ii; i++) {
3286 diff[attr][i] = [0];
3287 for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
3288 diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
3293 var values = Str(params[attr])[split](separator),
3294 from2 = Str(from[attr])[split](separator);
3297 from[attr] = [0, 0];
3298 diff[attr] = [values[0] / ms, values[1] / ms];
3301 from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
3302 diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
3305 params[attr] = values;
3306 from[attr] = Str(from[attr])[split](separator);
3307 diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
3310 from[attr] = Str(from[attr])[split](separator);
3314 diff[attr][i] = (values[i] - from[attr][i]) / ms;
3321 values = [].concat(params[attr]);
3322 from2 = [].concat(from[attr]);
3324 i = this.paper.customAttributes[attr].length;
3326 diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
3333 this.in_animation = 1;
3334 animationElements[this.id] = {
3335 start: params.start || +new Date,
3345 ++animationElements[length] == 1 && animation();
3348 Element[proto].stop = function () {
3349 animationElements[this.id] && animationElements[length]--;
3350 delete animationElements[this.id];
3353 Element[proto].translate = function (x, y) {
3354 return this.attr({translation: x + " " + y});
3356 Element[proto][toString] = function () {
3357 return "Rapha\xebl\u2019s object";
3359 R.ae = animationElements;
3362 var Set = function (items) {
3367 for (var i = 0, ii = items[length]; i < ii; i++) {
3368 if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
3369 this[this.items[length]] = this.items[this.items[length]] = items[i];
3375 Set[proto][push] = function () {
3378 for (var i = 0, ii = arguments[length]; i < ii; i++) {
3379 item = arguments[i];
3380 if (item && (item.constructor == Element || item.constructor == Set)) {
3381 len = this.items[length];
3382 this[len] = this.items[len] = item;
3388 Set[proto].pop = function () {
3389 delete this[this[length]--];
3390 return this.items.pop();
3392 for (var method in Element[proto]) if (Element[proto][has](method)) {
3393 Set[proto][method] = (function (methodname) {
3394 return function () {
3395 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3396 this.items[i][methodname][apply](this.items[i], arguments);
3402 Set[proto].attr = function (name, value) {
3403 if (name && R.is(name, array) && R.is(name[0], "object")) {
3404 for (var j = 0, jj = name[length]; j < jj; j++) {
3405 this.items[j].attr(name[j]);
3408 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3409 this.items[i].attr(name, value);
3414 Set[proto].animate = function (params, ms, easing, callback) {
3415 (R.is(easing, "function") || !easing) && (callback = easing || null);
3416 var len = this.items[length],
3421 callback && (collector = function () {
3422 !--len && callback.call(set);
3424 easing = R.is(easing, string) ? easing : collector;
3425 item = this.items[--i].animate(params, ms, easing, collector);
3427 this.items[i].animateWith(item, params, ms, easing, collector);
3431 Set[proto].insertAfter = function (el) {
3432 var i = this.items[length];
3434 this.items[i].insertAfter(el);
3438 Set[proto].getBBox = function () {
3443 for (var i = this.items[length]; i--;) {
3444 var box = this.items[i].getBBox();
3447 w[push](box.x + box.width);
3448 h[push](box.y + box.height);
3450 x = mmin[apply](0, x);
3451 y = mmin[apply](0, y);
3455 width: mmax[apply](0, w) - x,
3456 height: mmax[apply](0, h) - y
3459 Set[proto].clone = function (s) {
3461 for (var i = 0, ii = this.items[length]; i < ii; i++) {
3462 s[push](this.items[i].clone());
3467 R.registerFont = function (font) {
3471 this.fonts = this.fonts || {};
3477 family = font.face["font-family"];
3478 for (var prop in font.face) if (font.face[has](prop)) {
3479 fontcopy.face[prop] = font.face[prop];
3481 if (this.fonts[family]) {
3482 this.fonts[family][push](fontcopy);
3484 this.fonts[family] = [fontcopy];
3487 fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
3488 for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
3489 var path = font.glyphs[glyph];
3490 fontcopy.glyphs[glyph] = {
3493 d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
3494 return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
3498 for (var k in path.k) if (path[has](k)) {
3499 fontcopy.glyphs[glyph].k[k] = path.k[k];
3506 Paper[proto].getFont = function (family, weight, style, stretch) {
3507 stretch = stretch || "normal";
3508 style = style || "normal";
3509 weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
3513 var font = R.fonts[family];
3515 var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
3516 for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
3517 if (name.test(fontName)) {
3518 font = R.fonts[fontName];
3525 for (var i = 0, ii = font[length]; i < ii; i++) {
3527 if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
3534 Paper[proto].print = function (x, y, string, font, size, origin) {
3535 origin = origin || "middle"; // baseline|middle
3536 var out = this.set(),
3537 letters = Str(string)[split](E),
3541 R.is(font, string) && (font = this.getFont(font));
3543 scale = (size || 16) / font.face["units-per-em"];
3544 var bb = font.face.bbox.split(separator),
3546 height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
3547 for (var i = 0, ii = letters[length]; i < ii; i++) {
3548 var prev = i && font.glyphs[letters[i - 1]] || {},
3549 curr = font.glyphs[letters[i]];
3550 shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
3551 curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
3553 out.scale(scale, scale, top, height).translate(x - top, y - height);
3558 var formatrg = /\{(\d+)\}/g;
3559 R.format = function (token, params) {
3560 var args = R.is(params, array) ? [0][concat](params) : arguments;
3561 token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
3562 return args[++i] == null ? E : args[i];
3566 R.ninja = function () {
3567 oldRaphael.was ? (Raphael = oldRaphael.is) : delete Raphael;
3570 R.el = Element[proto];