Final small fixes…
[raphael] / raphael.svg.js
1 // ┌─────────────────────────────────────────────────────────────────────┐ \\
2 // │ Raphaël 2 - JavaScript Vector Library                               │ \\
3 // ├─────────────────────────────────────────────────────────────────────┤ \\
4 // │ SVG Module                                                          │ \\
5 // ├─────────────────────────────────────────────────────────────────────┤ \\
6 // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
7 // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
8 // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
9 // └─────────────────────────────────────────────────────────────────────┘ \\
10 window.Raphael.svg && function (R) {
11     var has = "hasOwnProperty",
12         Str = String,
13         toFloat = parseFloat,
14         toInt = parseInt,
15         math = Math,
16         mmax = math.max,
17         abs = math.abs,
18         pow = math.pow,
19         separator = /[, ]+/,
20         eve = R.eve,
21         E = "",
22         S = " ";
23     var xlink = "http://www.w3.org/1999/xlink",
24         markers = {
25             block: "M5,0 0,2.5 5,5z",
26             classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
27             diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
28             open: "M6,1 1,3.5 6,6",
29             oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
30         },
31         markerCounter = {};
32     R.toString = function () {
33         return  "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
34     };
35     var $ = function (el, attr) {
36         if (attr) {
37             if (typeof el == "string") {
38                 el = $(el);
39             }
40             for (var key in attr) if (attr[has](key)) {
41                 if (key.substring(0, 6) == "xlink:") {
42                     el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
43                 } else {
44                     el.setAttribute(key, Str(attr[key]));
45                 }
46             }
47         } else {
48             el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
49             el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
50         }
51         return el;
52     },
53     gradients = {},
54     rgGrad = /^url\(#(.*)\)$/,
55     removeGradientFill = function (node, paper) {
56         var oid = node.getAttribute("fill");
57         oid = oid && oid.match(rgGrad);
58         if (oid && !--gradients[oid[1]]) {
59             delete gradients[oid[1]];
60             paper.defs.removeChild(R._g.doc.getElementById(oid[1]));
61         }
62     },
63     addGradientFill = function (element, gradient) {
64         var type = "linear",
65             id = element.id + gradient,
66             fx = .5, fy = .5,
67             o = element.node,
68             SVG = element.paper,
69             s = o.style,
70             el = R._g.doc.getElementById(id);
71         if (!el) {
72             gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
73                 type = "radial";
74                 if (_fx && _fy) {
75                     fx = toFloat(_fx);
76                     fy = toFloat(_fy);
77                     var dir = ((fy > .5) * 2 - 1);
78                     pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
79                         (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
80                         fy != .5 &&
81                         (fy = fy.toFixed(5) - 1e-5 * dir);
82                 }
83                 return E;
84             });
85             gradient = gradient.split(/\s*\-\s*/);
86             if (type == "linear") {
87                 var angle = gradient.shift();
88                 angle = -toFloat(angle);
89                 if (isNaN(angle)) {
90                     return null;
91                 }
92                 var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
93                     max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
94                 vector[2] *= max;
95                 vector[3] *= max;
96                 if (vector[2] < 0) {
97                     vector[0] = -vector[2];
98                     vector[2] = 0;
99                 }
100                 if (vector[3] < 0) {
101                     vector[1] = -vector[3];
102                     vector[3] = 0;
103                 }
104             }
105             var dots = R._parseDots(gradient);
106             if (!dots) {
107                 return null;
108             }
109             if (element.gradient) {
110                 SVG.defs.removeChild(element.gradient);
111                 delete element.gradient;
112             }
113
114             id = id.replace(/[\(\)\s,\xb0#]/g, "-");
115             el = $(type + "Gradient", {id: id});
116             element.gradient = el;
117             $(el, type == "radial" ? {
118                 fx: fx,
119                 fy: fy
120             } : {
121                 x1: vector[0],
122                 y1: vector[1],
123                 x2: vector[2],
124                 y2: vector[3],
125                 gradientTransform: element.matrix.invert()
126             });
127             SVG.defs.appendChild(el);
128             for (var i = 0, ii = dots.length; i < ii; i++) {
129                 el.appendChild($("stop", {
130                     offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
131                     "stop-color": dots[i].color || "#fff"
132                 }));
133             }
134         }
135         $(o, {
136             fill: "url(#" + id + ")",
137             opacity: 1,
138             "fill-opacity": 1
139         });
140         s.fill = E;
141         s.opacity = 1;
142         s.fillOpacity = 1;
143         return 1;
144     },
145     updatePosition = function (o) {
146         var bbox = o.getBBox(1);
147         $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
148     },
149     addArrow = function (o, value, isEnd) {
150         if (o.type == "path") {
151             var values = Str(value).toLowerCase().split("-"),
152                 p = o.paper,
153                 se = isEnd ? "end" : "start",
154                 node = o.node,
155                 attrs = o.attrs,
156                 stroke = attrs["stroke-width"],
157                 i = values.length,
158                 type = "classic",
159                 from,
160                 to,
161                 dx,
162                 refX,
163                 attr,
164                 w = 3,
165                 h = 3,
166                 t = 5;
167             while (i--) {
168                 switch (values[i]) {
169                     case "block":
170                     case "classic":
171                     case "oval":
172                     case "diamond":
173                     case "open":
174                     case "none":
175                         type = values[i];
176                         break;
177                     case "wide": h = 5; break;
178                     case "narrow": h = 2; break;
179                     case "long": w = 5; break;
180                     case "short": w = 2; break;
181                 }
182             }
183             if (type == "open") {
184                 w += 2;
185                 h += 2;
186                 t += 2;
187                 dx = 1;
188                 refX = isEnd ? 4 : 1;
189                 attr = {
190                     fill: "none",
191                     stroke: attrs.stroke
192                 };
193             } else {
194                 refX = dx = w / 2;
195                 attr = {
196                     fill: attrs.stroke,
197                     stroke: "none"
198                 };
199             }
200             if (o._.arrows) {
201                 if (isEnd) {
202                     o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
203                     o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
204                 } else {
205                     o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
206                     o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
207                 }
208             } else {
209                 o._.arrows = {};
210             }
211             if (type != "none") {
212                 var pathId = "raphael-marker-" + type,
213                     markerId = "raphael-marker-" + se + type + w + h;
214                 if (!R._g.doc.getElementById(pathId)) {
215                     p.defs.appendChild($($("path"), {
216                         "stroke-linecap": "round",
217                         d: markers[type],
218                         id: pathId
219                     }));
220                     markerCounter[pathId] = 1;
221                 } else {
222                     markerCounter[pathId]++;
223                 }
224                 var marker = R._g.doc.getElementById(markerId),
225                     use;
226                 if (!marker) {
227                     marker = $($("marker"), {
228                         id: markerId,
229                         markerHeight: h,
230                         markerWidth: w,
231                         orient: "auto",
232                         refX: refX,
233                         refY: h / 2
234                     });
235                     use = $($("use"), {
236                         "xlink:href": "#" + pathId,
237                         transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
238                         "stroke-width": 1 / ((w / t + h / t) / 2)
239                     });
240                     marker.appendChild(use);
241                     p.defs.appendChild(marker);
242                     markerCounter[markerId] = 1;
243                 } else {
244                     markerCounter[markerId]++;
245                     use = marker.getElementsByTagName("use")[0];
246                 }
247                 $(use, attr);
248                 var delta = dx * (type != "diamond" && type != "oval");
249                 if (isEnd) {
250                     from = o._.arrows.startdx * stroke || 0;
251                     to = R.getTotalLength(attrs.path) - delta * stroke;
252                 } else {
253                     from = delta * stroke;
254                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
255                 }
256                 attr = {};
257                 attr["marker-" + se] = "url(#" + markerId + ")";
258                 if (to || from) {
259                     attr.d = Raphael.getSubpath(attrs.path, from, to);
260                 }
261                 $(node, attr);
262                 o._.arrows[se + "Path"] = pathId;
263                 o._.arrows[se + "Marker"] = markerId;
264                 o._.arrows[se + "dx"] = delta;
265                 o._.arrows[se + "Type"] = type;
266                 o._.arrows[se + "String"] = value;
267             } else {
268                 if (isEnd) {
269                     from = o._.arrows.startdx * stroke || 0;
270                     to = R.getTotalLength(attrs.path) - from;
271                 } else {
272                     from = 0;
273                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
274                 }
275                 o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
276                 delete o._.arrows[se + "Path"];
277                 delete o._.arrows[se + "Marker"];
278                 delete o._.arrows[se + "dx"];
279                 delete o._.arrows[se + "Type"];
280                 delete o._.arrows[se + "String"];
281             }
282             for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
283                 var item = R._g.doc.getElementById(attr);
284                 item && item.parentNode.removeChild(item);
285             }
286         }
287     },
288     dasharray = {
289         "": [0],
290         "none": [0],
291         "-": [3, 1],
292         ".": [1, 1],
293         "-.": [3, 1, 1, 1],
294         "-..": [3, 1, 1, 1, 1, 1],
295         ". ": [1, 3],
296         "- ": [4, 3],
297         "--": [8, 3],
298         "- .": [4, 3, 1, 3],
299         "--.": [8, 3, 1, 3],
300         "--..": [8, 3, 1, 3, 1, 3]
301     },
302     addDashes = function (o, value, params) {
303         value = dasharray[Str(value).toLowerCase()];
304         if (value) {
305             var width = o.attrs["stroke-width"] || "1",
306                 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
307                 dashes = [],
308                 i = value.length;
309             while (i--) {
310                 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
311             }
312             $(o.node, {"stroke-dasharray": dashes.join(",")});
313         }
314     },
315     setFillAndStroke = function (o, params) {
316         var node = o.node,
317             attrs = o.attrs,
318             vis = node.style.visibility;
319         node.style.visibility = "hidden";
320         for (var att in params) {
321             if (params[has](att)) {
322                 if (!R._availableAttrs[has](att)) {
323                     continue;
324                 }
325                 var value = params[att];
326                 attrs[att] = value;
327                 switch (att) {
328                     case "blur":
329                         o.blur(value);
330                         break;
331                     case "href":
332                     case "title":
333                     case "target":
334                         var pn = node.parentNode;
335                         if (pn.tagName.toLowerCase() != "a") {
336                             var hl = $("a");
337                             pn.insertBefore(hl, node);
338                             hl.appendChild(node);
339                             pn = hl;
340                         }
341                         if (att == "target" && value == "blank") {
342                             pn.setAttributeNS(xlink, "show", "new");
343                         } else {
344                             pn.setAttributeNS(xlink, att, value);
345                         }
346                         break;
347                     case "cursor":
348                         node.style.cursor = value;
349                         break;
350                     case "transform":
351                         o.transform(value);
352                         break;
353                     case "arrow-start":
354                         addArrow(o, value);
355                         break;
356                     case "arrow-end":
357                         addArrow(o, value, 1);
358                         break;
359                     case "clip-rect":
360                         var rect = Str(value).split(separator);
361                         if (rect.length == 4) {
362                             o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
363                             var el = $("clipPath"),
364                                 rc = $("rect");
365                             el.id = R.createUUID();
366                             $(rc, {
367                                 x: rect[0],
368                                 y: rect[1],
369                                 width: rect[2],
370                                 height: rect[3]
371                             });
372                             el.appendChild(rc);
373                             o.paper.defs.appendChild(el);
374                             $(node, {"clip-path": "url(#" + el.id + ")"});
375                             o.clip = rc;
376                         }
377                         if (!value) {
378                             var clip = R._g.doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, E));
379                             clip && clip.parentNode.removeChild(clip);
380                             $(node, {"clip-path": E});
381                             delete o.clip;
382                         }
383                     break;
384                     case "path":
385                         if (o.type == "path") {
386                             $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
387                             o._.dirty = 1;
388                             if (o._.arrows) {
389                                 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
390                                 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
391                             }
392                         }
393                         break;
394                     case "width":
395                         node.setAttribute(att, value);
396                         o._.dirty = 1;
397                         if (attrs.fx) {
398                             att = "x";
399                             value = attrs.x;
400                         } else {
401                             break;
402                         }
403                     case "x":
404                         if (attrs.fx) {
405                             value = -attrs.x - (attrs.width || 0);
406                         }
407                     case "rx":
408                         if (att == "rx" && o.type == "rect") {
409                             break;
410                         }
411                     case "cx":
412                         node.setAttribute(att, value);
413                         o.pattern && updatePosition(o);
414                         o._.dirty = 1;
415                         break;
416                     case "height":
417                         node.setAttribute(att, value);
418                         o._.dirty = 1;
419                         if (attrs.fy) {
420                             att = "y";
421                             value = attrs.y;
422                         } else {
423                             break;
424                         }
425                     case "y":
426                         if (attrs.fy) {
427                             value = -attrs.y - (attrs.height || 0);
428                         }
429                     case "ry":
430                         if (att == "ry" && o.type == "rect") {
431                             break;
432                         }
433                     case "cy":
434                         node.setAttribute(att, value);
435                         o.pattern && updatePosition(o);
436                         o._.dirty = 1;
437                         break;
438                     case "r":
439                         if (o.type == "rect") {
440                             $(node, {rx: value, ry: value});
441                         } else {
442                             node.setAttribute(att, value);
443                         }
444                         o._.dirty = 1;
445                         break;
446                     case "src":
447                         if (o.type == "image") {
448                             node.setAttributeNS(xlink, "href", value);
449                         }
450                         break;
451                     case "stroke-width":
452                         if (o._.sx != 1 || o._.sy != 1) {
453                             value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
454                         }
455                         if (o.paper._vbSize) {
456                             value *= o.paper._vbSize;
457                         }
458                         node.setAttribute(att, value);
459                         if (attrs["stroke-dasharray"]) {
460                             addDashes(o, attrs["stroke-dasharray"], params);
461                         }
462                         if (o._.arrows) {
463                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
464                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
465                         }
466                         break;
467                     case "stroke-dasharray":
468                         addDashes(o, value, params);
469                         break;
470                     case "fill":
471                         var isURL = Str(value).match(R._ISURL);
472                         if (isURL) {
473                             el = $("pattern");
474                             var ig = $("image");
475                             el.id = R.createUUID();
476                             $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
477                             $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
478                             el.appendChild(ig);
479
480                             (function (el) {
481                                 R._preload(isURL[1], function () {
482                                     var w = this.offsetWidth,
483                                         h = this.offsetHeight;
484                                     $(el, {width: w, height: h});
485                                     $(ig, {width: w, height: h});
486                                     o.paper.safari();
487                                 });
488                             })(el);
489                             o.paper.defs.appendChild(el);
490                             node.style.fill = "url(#" + el.id + ")";
491                             $(node, {fill: "url(#" + el.id + ")"});
492                             o.pattern = el;
493                             o.pattern && updatePosition(o);
494                             break;
495                         }
496                         var clr = R.getRGB(value);
497                         if (!clr.error) {
498                             delete params.gradient;
499                             delete attrs.gradient;
500                             !R.is(attrs.opacity, "undefined") &&
501                                 R.is(params.opacity, "undefined") &&
502                                 $(node, {opacity: attrs.opacity});
503                             !R.is(attrs["fill-opacity"], "undefined") &&
504                                 R.is(params["fill-opacity"], "undefined") &&
505                                 $(node, {"fill-opacity": attrs["fill-opacity"]});
506                         } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
507                             if ("opacity" in attrs || "fill-opacity" in attrs) {
508                                 var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
509                                 if (gradient) {
510                                     var stops = gradient.getElementsByTagName("stop");
511                                     $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
512                                 }
513                             }
514                             attrs.gradient = value;
515                             attrs.fill = "none";
516                             break;
517                         }
518                         clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
519                     case "stroke":
520                         clr = R.getRGB(value);
521                         node.setAttribute(att, clr.hex);
522                         att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
523                         if (att == "stroke" && o._.arrows) {
524                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
525                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
526                         }
527                         break;
528                     case "gradient":
529                         (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
530                         break;
531                     case "opacity":
532                         if (attrs.gradient && !attrs[has]("stroke-opacity")) {
533                             $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
534                         }
535                         // fall
536                     case "fill-opacity":
537                         if (attrs.gradient) {
538                             gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
539                             if (gradient) {
540                                 stops = gradient.getElementsByTagName("stop");
541                                 $(stops[stops.length - 1], {"stop-opacity": value});
542                             }
543                             break;
544                         }
545                     default:
546                         att == "font-size" && (value = toInt(value, 10) + "px");
547                         var cssrule = att.replace(/(\-.)/g, function (w) {
548                             return w.substring(1).toUpperCase();
549                         });
550                         node.style[cssrule] = value;
551                         o._.dirty = 1;
552                         node.setAttribute(att, value);
553                         break;
554                 }
555             }
556         }
557
558         tuneText(o, params);
559         node.style.visibility = vis;
560     },
561     leading = 1.2,
562     tuneText = function (el, params) {
563         if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
564             return;
565         }
566         var a = el.attrs,
567             node = el.node,
568             fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
569
570         if (params[has]("text")) {
571             a.text = params.text;
572             while (node.firstChild) {
573                 node.removeChild(node.firstChild);
574             }
575             var texts = Str(params.text).split("\n"),
576                 tspans = [],
577                 tspan;
578             for (var i = 0, ii = texts.length; i < ii; i++) {
579                 tspan = $("tspan");
580                 i && $(tspan, {dy: fontSize * leading, x: a.x});
581                 tspan.appendChild(R._g.doc.createTextNode(texts[i]));
582                 node.appendChild(tspan);
583                 tspans[i] = tspan;
584             }
585         } else {
586             tspans = node.getElementsByTagName("tspan");
587             for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
588                 $(tspans[i], {dy: fontSize * leading, x: a.x});
589             } else {
590                 $(tspans[0], {dy: 0});
591             }
592         }
593         $(node, {x: a.x, y: a.y});
594         el._.dirty = 1;
595         var bb = el._getBBox(),
596             dif = a.y - (bb.y + bb.height / 2);
597         dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
598     },
599     Element = function (node, svg) {
600         var X = 0,
601             Y = 0;
602         /*\
603          * Element.node
604          [ property (object) ]
605          **
606          * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
607          **
608          * Note: Don’t mess with it.
609          > Usage
610          | // draw a circle at coordinate 10,10 with radius of 10
611          | var c = paper.circle(10, 10, 10);
612          | c.node.onclick = function () {
613          |     c.attr("fill", "red");
614          | };
615         \*/
616         this[0] = this.node = node;
617         /*\
618          * Element.raphael
619          [ property (object) ]
620          **
621          * Internal reference to @Raphael object. In case it is not available.
622          > Usage
623          | Raphael.el.red = function () {
624          |     var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
625          |     hsb.h = 1;
626          |     this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
627          | }
628         \*/
629         node.raphael = true;
630         /*\
631          * Element.id
632          [ property (number) ]
633          **
634          * Unique id of the element. Especially usesful when you want to listen to events of the element, 
635          * because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
636         \*/
637         this.id = R._oid++;
638         node.raphaelid = this.id;
639         this.matrix = R.matrix();
640         this.realPath = null;
641         /*\
642          * Element.paper
643          [ property (object) ]
644          **
645          * Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
646          > Usage
647          | Raphael.el.cross = function () {
648          |     this.attr({fill: "red"});
649          |     this.paper.path("M10,10L50,50M50,10L10,50")
650          |         .attr({stroke: "red"});
651          | }
652         \*/
653         this.paper = svg;
654         this.attrs = this.attrs || {};
655         this._ = {
656             transform: [],
657             sx: 1,
658             sy: 1,
659             deg: 0,
660             dx: 0,
661             dy: 0,
662             dirty: 1
663         };
664         !svg.bottom && (svg.bottom = this);
665         /*\
666          * Element.prev
667          [ property (object) ]
668          **
669          * Reference to the previous element in the hierarchy.
670         \*/
671         this.prev = svg.top;
672         svg.top && (svg.top.next = this);
673         svg.top = this;
674         /*\
675          * Element.next
676          [ property (object) ]
677          **
678          * Reference to the next element in the hierarchy.
679         \*/
680         this.next = null;
681     },
682     elproto = R.el;
683
684     Element.prototype = elproto;
685     elproto.constructor = Element;
686
687     R._engine.path = function (pathString, SVG) {
688         var el = $("path");
689         SVG.canvas && SVG.canvas.appendChild(el);
690         var p = new Element(el, SVG);
691         p.type = "path";
692         setFillAndStroke(p, {
693             fill: "none",
694             stroke: "#000",
695             path: pathString
696         });
697         return p;
698     };
699     /*\
700      * Element.rotate
701      [ method ]
702      **
703      * Adds rotation by given angle around given point to the list of
704      * transformations of the element.
705      > Parameters
706      - deg (number) angle in degrees
707      - cx (number) #optional x coordinate of the centre of rotation
708      - cy (number) #optional y coordinate of the centre of rotation
709      * If cx & cy aren’t specified centre of the shape is used as a point of rotation.
710      = (object) @Element
711     \*/
712     elproto.rotate = function (deg, cx, cy) {
713         if (this.removed) {
714             return this;
715         }
716         deg = Str(deg).split(separator);
717         if (deg.length - 1) {
718             cx = toFloat(deg[1]);
719             cy = toFloat(deg[2]);
720         }
721         deg = toFloat(deg[0]);
722         (cy == null) && (cx = cy);
723         if (cx == null || cy == null) {
724             var bbox = this.getBBox(1);
725             cx = bbox.x + bbox.width / 2;
726             cy = bbox.y + bbox.height / 2;
727         }
728         this.transform(this._.transform.concat([["r", deg, cx, cy]]));
729         return this;
730     };
731     /*\
732      * Element.scale
733      [ method ]
734      **
735      * Adds scale by given amount relative to given point to the list of
736      * transformations of the element.
737      > Parameters
738      - sx (number) horisontal scale amount
739      - sy (number) vertical scale amount
740      - cx (number) #optional x coordinate of the centre of scale
741      - cy (number) #optional y coordinate of the centre of scale
742      * If cx & cy aren’t specified centre of the shape is used instead.
743      = (object) @Element
744     \*/
745     elproto.scale = function (sx, sy, cx, cy) {
746         if (this.removed) {
747             return this;
748         }
749         sx = Str(sx).split(separator);
750         if (sx.length - 1) {
751             sy = toFloat(sx[1]);
752             cx = toFloat(sx[2]);
753             cy = toFloat(sx[3]);
754         }
755         sx = toFloat(sx[0]);
756         (sy == null) && (sy = sx);
757         (cy == null) && (cx = cy);
758         if (cx == null || cy == null) {
759             var bbox = this.getBBox(1);
760         }
761         cx = cx == null ? bbox.x + bbox.width / 2 : cx;
762         cy = cy == null ? bbox.y + bbox.height / 2 : cy;
763         this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
764         return this;
765     };
766     /*\
767      * Element.translate
768      [ method ]
769      **
770      * Adds translation by given amount to the list of transformations of the element.
771      > Parameters
772      - dx (number) horisontal shift
773      - dy (number) vertical shift
774      = (object) @Element
775     \*/
776     elproto.translate = function (dx, dy) {
777         if (this.removed) {
778             return this;
779         }
780         dx = Str(dx).split(separator);
781         if (dx.length - 1) {
782             dy = toFloat(dx[1]);
783         }
784         dx = toFloat(dx[0]) || 0;
785         dy = +dy || 0;
786         this.transform(this._.transform.concat([["t", dx, dy]]));
787         return this;
788     };
789     /*\
790      * Element.transform
791      [ method ]
792      **
793      * Adds transformation to the element which is separate to other attributes,
794      * i.e. translation doesn’t change `x` or `y` of the rectange. The format
795      * of transformation string is similar to the path string syntax:
796      | "t100,100r30,100,100s2,2,100,100r45s1.5"
797      * Each letter is a command. There are four commands: `t` is for translate, `r` is for rotate, `s` is for
798      * scale and `m` is for matrix.
799      *
800      * There are also alternative “absolute” translation, rotation and scale: `T`, `R` and `S`. They will not take previous transformation into account. For example, `...T100,0` will always move element 100 px horisontally, while `...t100,0` could move it vertically if there is `r90` before. Just compare results of `r90t100,0` and `r90T100,0`.
801      *
802      * So, the example line above could be read like “translate by 100, 100; rotate 30° around 100, 100; scale twice around 100, 100;
803      * rotate 45° around centre; scale 1.5 times relative to centre”. As you can see rotate and scale commands have origin
804      * coordinates as optional parameters, the default is the centre point of the element.
805      * Matrix accepts six parameters.
806      > Usage
807      | var el = paper.rect(10, 20, 300, 200);
808      | // translate 100, 100, rotate 45°, translate -100, 0
809      | el.transform("t100,100r45t-100,0");
810      | // if you want you can append or prepend transformations
811      | el.transform("...t50,50");
812      | el.transform("s2...");
813      | // or even wrap
814      | el.transform("t50,50...t-50-50");
815      | // to reset transformation call method with empty string
816      | el.transform("");
817      | // to get current value call it without parameters
818      | console.log(el.transform());
819      > Parameters
820      - tstr (string) #optional transformation string
821      * If tstr isn’t specified
822      = (string) current transformation string
823      * else
824      = (object) @Element
825     \*/
826     elproto.transform = function (tstr) {
827         var _ = this._;
828         if (tstr == null) {
829             return _.transform;
830         }
831         R._extractTransform(this, tstr);
832
833         this.clip && $(this.clip, {transform: this.matrix.invert()});
834         this.pattern && updatePosition(this);
835         this.node && $(this.node, {transform: this.matrix});
836     
837         if (_.sx != 1 || _.sy != 1) {
838             var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
839             this.attr({"stroke-width": sw});
840         }
841
842         return this;
843     };
844     /*\
845      * Element.hide
846      [ method ]
847      **
848      * Makes element invisible. See @Element.show.
849      = (object) @Element
850     \*/
851     elproto.hide = function () {
852         !this.removed && this.paper.safari(this.node.style.display = "none");
853         return this;
854     };
855     /*\
856      * Element.show
857      [ method ]
858      **
859      * Makes element visible. See @Element.hide.
860      = (object) @Element
861     \*/
862     elproto.show = function () {
863         !this.removed && this.paper.safari(this.node.style.display = "");
864         return this;
865     };
866     /*\
867      * Element.remove
868      [ method ]
869      **
870      * Removes element form the paper.
871     \*/
872     elproto.remove = function () {
873         if (this.removed) {
874             return;
875         }
876         this.paper.__set__ && this.paper.__set__.exclude(this);
877         eve.unbind("*.*." + this.id);
878         R._tear(this, this.paper);
879         this.node.parentNode.removeChild(this.node);
880         for (var i in this) {
881             delete this[i];
882         }
883         this.removed = true;
884     };
885     elproto._getBBox = function () {
886         if (this.node.style.display == "none") {
887             this.show();
888             var hide = true;
889         }
890         var bbox = {};
891         try {
892             bbox = this.node.getBBox();
893         } catch(e) {
894             // Firefox 3.0.x plays badly here
895         } finally {
896             bbox = bbox || {};
897         }
898         hide && this.hide();
899         return bbox;
900     };
901     /*\
902      * Element.attr
903      [ method ]
904      **
905      * Sets the attributes of the element.
906      > Parameters
907      - attrName (string) attribute’s name
908      - value (string) value
909      * or
910      - params (object) object of name/value pairs
911      * or
912      - attrName (string) attribute’s name
913      * or
914      - attrNames (array) in this case method returns array of current values for given attribute names
915      = (object) @Element if attrsName & value or params are passed in.
916      = (...) value of the attribute if only attrsName is passed in.
917      = (array) array of values of the attribute if attrsNames is passed in.
918      = (object) object of attributes if nothing is passed in.
919      > Possible parameters
920      # <p>Please refer to the <a href="http://www.w3.org/TR/SVG/" title="The W3C Recommendation for the SVG language describes these properties in detail.">SVG specification</a> for an explanation of these parameters.</p>
921      o arrow-end (string) arrowhead on the end of the path. The format for string is `<type>[-<width>[-<length>]]`. Possible types: `classic`, `block`, `open`, `oval`, `diamond`, `none`, width: `wide`, `narrow`, `midium`, length: `long`, `short`, `midium`.
922      o clip-rect (string) comma or space separated values: x, y, width and height
923      o cursor (string) CSS type of the cursor
924      o cx (number)
925      o cy (number)
926      o fill (string) colour, gradient or image
927      o fill-opacity (number)
928      o font (string)
929      o font-family (string)
930      o font-size (number) font size in pixels
931      o font-weight (string)
932      o height (number)
933      o href (string) URL, if specified element behaves as hyperlink
934      o opacity (number)
935      o path (string) SVG path string format
936      o r (number)
937      o rx (number)
938      o ry (number)
939      o src (string) image URL, only works for @Element.image element
940      o stroke (string) stroke colour
941      o stroke-dasharray (string) [“”, “`-`”, “`.`”, “`-.`”, “`-..`”, “`. `”, “`- `”, “`--`”, “`- .`”, “`--.`”, “`--..`”]
942      o stroke-linecap (string) [“`butt`”, “`square`”, “`round`”]
943      o stroke-linejoin (string) [“`bevel`”, “`round`”, “`miter`”]
944      o stroke-miterlimit (number)
945      o stroke-opacity (number)
946      o stroke-width (number) stroke width in pixels, default is '1'
947      o target (string) used with href
948      o text (string) contents of the text element. Use `\n` for multiline text
949      o text-anchor (string) [“`start`”, “`middle`”, “`end`”], default is “`middle`”
950      o title (string) will create tooltip with a given text
951      o transform (string) see @Element.transform
952      o width (number)
953      o x (number)
954      o y (number)
955      > Gradients
956      * Linear gradient format: “`‹angle›-‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`90-#fff-#000`” – 90°
957      * gradient from white to black or “`0-#fff-#f00:20-#000`” – 0° gradient from white via red (at 20%) to black.
958      *
959      * radial gradient: “`r[(‹fx›, ‹fy›)]‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`r#fff-#000`” –
960      * gradient from white to black or “`r(0.25, 0.75)#fff-#000`” – gradient from white to black with focus point
961      * at 0.25, 0.75. Focus point coordinates are in 0..1 range. Radial gradients can only be applied to circles and ellipses.
962      > Path String
963      # <p>Please refer to <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path’s data attribute’s format are described in the SVG specification.">SVG documentation regarding path string</a>. Raphaël fully supports it.</p>
964      > Colour Parsing
965      # <ul>
966      #     <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
967      #     <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
968      #     <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
969      #     <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
970      #     <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
971      #     <li>rgba(•••, •••, •••, •••) — red, green and blue channels’ values: (“<code>rgba(200,&nbsp;100,&nbsp;0, .5)</code>”)</li>
972      #     <li>rgba(•••%, •••%, •••%, •••%) — same as above, but in %: (“<code>rgba(100%,&nbsp;175%,&nbsp;0%, 50%)</code>”)</li>
973      #     <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
974      #     <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
975      #     <li>hsba(•••, •••, •••, •••) — same as above, but with opacity</li>
976      #     <li>hsl(•••, •••, •••) — almost the same as hsb, see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV" title="HSL and HSV - Wikipedia, the free encyclopedia">Wikipedia page</a></li>
977      #     <li>hsl(•••%, •••%, •••%) — same as above, but in %</li>
978      #     <li>hsla(•••, •••, •••, •••) — same as above, but with opacity</li>
979      #     <li>Optionally for hsb and hsl you could specify hue as a degree: “<code>hsl(240deg,&nbsp;1,&nbsp;.5)</code>” or, if you want to go fancy, “<code>hsl(240°,&nbsp;1,&nbsp;.5)</code>”</li>
980      # </ul>
981     \*/
982     elproto.attr = function (name, value) {
983         if (this.removed) {
984             return this;
985         }
986         if (name == null) {
987             var res = {};
988             for (var a in this.attrs) if (this.attrs[has](a)) {
989                 res[a] = this.attrs[a];
990             }
991             res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
992             res.transform = this._.transform;
993             return res;
994         }
995         if (value == null && R.is(name, "string")) {
996             if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
997                 return this.attrs.gradient;
998             }
999             if (name == "transform") {
1000                 return this._.transform;
1001             }
1002             var names = name.split(separator),
1003                 out = {};
1004             for (var i = 0, ii = names.length; i < ii; i++) {
1005                 name = names[i];
1006                 if (name in this.attrs) {
1007                     out[name] = this.attrs[name];
1008                 } else if (R.is(this.paper.customAttributes[name], "function")) {
1009                     out[name] = this.paper.customAttributes[name].def;
1010                 } else {
1011                     out[name] = R._availableAttrs[name];
1012                 }
1013             }
1014             return ii - 1 ? out : out[names[0]];
1015         }
1016         if (value == null && R.is(name, "array")) {
1017             out = {};
1018             for (i = 0, ii = name.length; i < ii; i++) {
1019                 out[name[i]] = this.attr(name[i]);
1020             }
1021             return out;
1022         }
1023         if (value != null) {
1024             var params = {};
1025             params[name] = value;
1026         } else if (name != null && R.is(name, "object")) {
1027             params = name;
1028         }
1029         for (var key in params) {
1030             eve("attr." + key + "." + this.id, this, params[key]);
1031         }
1032         for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
1033             var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
1034             this.attrs[key] = params[key];
1035             for (var subkey in par) if (par[has](subkey)) {
1036                 params[subkey] = par[subkey];
1037             }
1038         }
1039         setFillAndStroke(this, params);
1040         return this;
1041     };
1042     /*\
1043      * Element.toFront
1044      [ method ]
1045      **
1046      * Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
1047      = (object) @Element
1048     \*/
1049     elproto.toFront = function () {
1050         if (this.removed) {
1051             return this;
1052         }
1053         this.node.parentNode.appendChild(this.node);
1054         var svg = this.paper;
1055         svg.top != this && R._tofront(this, svg);
1056         return this;
1057     };
1058     /*\
1059      * Element.toBack
1060      [ method ]
1061      **
1062      * Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
1063      = (object) @Element
1064     \*/
1065     elproto.toBack = function () {
1066         if (this.removed) {
1067             return this;
1068         }
1069         if (this.node.parentNode.firstChild != this.node) {
1070             this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
1071             R._toback(this, this.paper);
1072             var svg = this.paper;
1073         }
1074         return this;
1075     };
1076     /*\
1077      * Element.insertAfter
1078      [ method ]
1079      **
1080      * Inserts current object after the given one.
1081      = (object) @Element
1082     \*/
1083     elproto.insertAfter = function (element) {
1084         if (this.removed) {
1085             return this;
1086         }
1087         var node = element.node || element[element.length - 1].node;
1088         if (node.nextSibling) {
1089             node.parentNode.insertBefore(this.node, node.nextSibling);
1090         } else {
1091             node.parentNode.appendChild(this.node);
1092         }
1093         R._insertafter(this, element, this.paper);
1094         return this;
1095     };
1096     /*\
1097      * Element.insertBefore
1098      [ method ]
1099      **
1100      * Inserts current object before the given one.
1101      = (object) @Element
1102     \*/
1103     elproto.insertBefore = function (element) {
1104         if (this.removed) {
1105             return this;
1106         }
1107         var node = element.node || element[0].node;
1108         node.parentNode.insertBefore(this.node, node);
1109         R._insertbefore(this, element, this.paper);
1110         return this;
1111     };
1112     elproto.blur = function (size) {
1113         // Experimental. No Safari support. Use it on your own risk.
1114         var t = this;
1115         if (+size !== 0) {
1116             var fltr = $("filter"),
1117                 blur = $("feGaussianBlur");
1118             t.attrs.blur = size;
1119             fltr.id = R.createUUID();
1120             $(blur, {stdDeviation: +size || 1.5});
1121             fltr.appendChild(blur);
1122             t.paper.defs.appendChild(fltr);
1123             t._blur = fltr;
1124             $(t.node, {filter: "url(#" + fltr.id + ")"});
1125         } else {
1126             if (t._blur) {
1127                 t._blur.parentNode.removeChild(t._blur);
1128                 delete t._blur;
1129                 delete t.attrs.blur;
1130             }
1131             t.node.removeAttribute("filter");
1132         }
1133     };
1134     R._engine.circle = function (svg, x, y, r) {
1135         var el = $("circle");
1136         svg.canvas && svg.canvas.appendChild(el);
1137         var res = new Element(el, svg);
1138         res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1139         res.type = "circle";
1140         $(el, res.attrs);
1141         return res;
1142     };
1143     R._engine.rect = function (svg, x, y, w, h, r) {
1144         var el = $("rect");
1145         svg.canvas && svg.canvas.appendChild(el);
1146         var res = new Element(el, svg);
1147         res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1148         res.type = "rect";
1149         $(el, res.attrs);
1150         return res;
1151     };
1152     R._engine.ellipse = function (svg, x, y, rx, ry) {
1153         var el = $("ellipse");
1154         svg.canvas && svg.canvas.appendChild(el);
1155         var res = new Element(el, svg);
1156         res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1157         res.type = "ellipse";
1158         $(el, res.attrs);
1159         return res;
1160     };
1161     R._engine.image = function (svg, src, x, y, w, h) {
1162         var el = $("image");
1163         $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1164         el.setAttributeNS(xlink, "href", src);
1165         svg.canvas && svg.canvas.appendChild(el);
1166         var res = new Element(el, svg);
1167         res.attrs = {x: x, y: y, width: w, height: h, src: src};
1168         res.type = "image";
1169         return res;
1170     };
1171     R._engine.text = function (svg, x, y, text) {
1172         var el = $("text");
1173         // $(el, {x: x, y: y, "text-anchor": "middle"});
1174         svg.canvas && svg.canvas.appendChild(el);
1175         var res = new Element(el, svg);
1176         res.attrs = {
1177             x: x,
1178             y: y,
1179             "text-anchor": "middle",
1180             text: text,
1181             font: R._availableAttrs.font,
1182             stroke: "none",
1183             fill: "#000"
1184         };
1185         res.type = "text";
1186         setFillAndStroke(res, res.attrs);
1187         return res;
1188     };
1189     R._engine.setSize = function (width, height) {
1190         this.width = width || this.width;
1191         this.height = height || this.height;
1192         this.canvas.setAttribute("width", this.width);
1193         this.canvas.setAttribute("height", this.height);
1194         if (this._viewBox) {
1195             this.setViewBox.apply(this, this._viewBox);
1196         }
1197         return this;
1198     };
1199     R._engine.create = function () {
1200         var con = R._getContainer.apply(0, arguments),
1201             container = con && con.container,
1202             x = con.x,
1203             y = con.y,
1204             width = con.width,
1205             height = con.height;
1206         if (!container) {
1207             throw new Error("SVG container not found.");
1208         }
1209         var cnvs = $("svg"),
1210             css = "overflow:hidden;",
1211             isFloating;
1212         x = x || 0;
1213         y = y || 0;
1214         width = width || 512;
1215         height = height || 342;
1216         $(cnvs, {
1217             height: height,
1218             version: 1.1,
1219             width: width,
1220             xmlns: "http://www.w3.org/2000/svg"
1221         });
1222         if (container == 1) {
1223             cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
1224             R._g.doc.body.appendChild(cnvs);
1225             isFloating = 1;
1226         } else {
1227             cnvs.style.cssText = css + "position:relative";
1228             if (container.firstChild) {
1229                 container.insertBefore(cnvs, container.firstChild);
1230             } else {
1231                 container.appendChild(cnvs);
1232             }
1233         }
1234         container = new R._Paper;
1235         container.width = width;
1236         container.height = height;
1237         container.canvas = cnvs;
1238         // plugins.call(container, container, R.fn);
1239         container.clear();
1240         container._left = container._top = 0;
1241         isFloating && (container.renderfix = function () {});
1242         container.renderfix();
1243         return container;
1244     };
1245     R._engine.setViewBox = function (x, y, w, h, fit) {
1246         eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
1247         var size = mmax(w / this.width, h / this.height),
1248             top = this.top,
1249             aspectRatio = fit ? "meet" : "xMinYMin",
1250             vb,
1251             sw;
1252         if (x == null) {
1253             if (this._vbSize) {
1254                 size = 1;
1255             }
1256             delete this._vbSize;
1257             vb = "0 0 " + this.width + S + this.height;
1258         } else {
1259             this._vbSize = size;
1260             vb = x + S + y + S + w + S + h;
1261         }
1262         $(this.canvas, {
1263             viewBox: vb,
1264             preserveAspectRatio: aspectRatio
1265         });
1266         while (size && top) {
1267             sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
1268             top.attr({"stroke-width": sw});
1269             top._.dirty = 1;
1270             top._.dirtyT = 1;
1271             top = top.prev;
1272         }
1273         this._viewBox = [x, y, w, h, !!fit];
1274         return this;
1275     };
1276     /*\
1277      * Paper.renderfix
1278      [ method ]
1279      **
1280      * Fixes the issue of Firefox and IE9 regarding subpixel rendering. If paper is dependant
1281      * on other elements after reflow it could shift half pixel which cause for lines to lost their crispness.
1282      * This method fixes the issue.
1283      **
1284        Special thanks to Mariusz Nowak (http://www.medikoo.com/) for this method.
1285     \*/
1286     R.prototype.renderfix = function () {
1287         var cnvs = this.canvas,
1288             s = cnvs.style,
1289             pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix(),
1290             left = -pos.e % 1,
1291             top = -pos.f % 1;
1292         if (left || top) {
1293             if (left) {
1294                 this._left = (this._left + left) % 1;
1295                 s.left = this._left + "px";
1296             }
1297             if (top) {
1298                 this._top = (this._top + top) % 1;
1299                 s.top = this._top + "px";
1300             }
1301         }
1302     };
1303     /*\
1304      * Paper.clear
1305      [ method ]
1306      **
1307      * Clears the paper, i.e. removes all the elements.
1308     \*/
1309     R.prototype.clear = function () {
1310         R.eve("clear", this);
1311         var c = this.canvas;
1312         while (c.firstChild) {
1313             c.removeChild(c.firstChild);
1314         }
1315         this.bottom = this.top = null;
1316         (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
1317         c.appendChild(this.desc);
1318         c.appendChild(this.defs = $("defs"));
1319     };
1320     /*\
1321      * Paper.remove
1322      [ method ]
1323      **
1324      * Removes the paper from the DOM.
1325     \*/
1326     R.prototype.remove = function () {
1327         eve("remove", this);
1328         this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1329         for (var i in this) {
1330             this[i] = removed(i);
1331         }
1332     };
1333     var setproto = R.st;
1334     for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
1335         setproto[method] = (function (methodname) {
1336             return function () {
1337                 var arg = arguments;
1338                 return this.forEach(function (el) {
1339                     el[methodname].apply(el, arg);
1340                 });
1341             };
1342         })(method);
1343     }
1344 }(window.Raphael);