Fix #5648 - New design for post release report
[raphael] / raphael.svg.js
1 // ┌─────────────────────────────────────────────────────────────────────┐ \\
2 // │ Raphaël - 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     addGradientFill = function (element, gradient) {
54         var type = "linear",
55             id = element.id + gradient,
56             fx = .5, fy = .5,
57             o = element.node,
58             SVG = element.paper,
59             s = o.style,
60             el = R._g.doc.getElementById(id);
61         if (!el) {
62             gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
63                 type = "radial";
64                 if (_fx && _fy) {
65                     fx = toFloat(_fx);
66                     fy = toFloat(_fy);
67                     var dir = ((fy > .5) * 2 - 1);
68                     pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
69                         (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
70                         fy != .5 &&
71                         (fy = fy.toFixed(5) - 1e-5 * dir);
72                 }
73                 return E;
74             });
75             gradient = gradient.split(/\s*\-\s*/);
76             if (type == "linear") {
77                 var angle = gradient.shift();
78                 angle = -toFloat(angle);
79                 if (isNaN(angle)) {
80                     return null;
81                 }
82                 var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
83                     max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
84                 vector[2] *= max;
85                 vector[3] *= max;
86                 if (vector[2] < 0) {
87                     vector[0] = -vector[2];
88                     vector[2] = 0;
89                 }
90                 if (vector[3] < 0) {
91                     vector[1] = -vector[3];
92                     vector[3] = 0;
93                 }
94             }
95             var dots = R._parseDots(gradient);
96             if (!dots) {
97                 return null;
98             }
99             id = id.replace(/[\(\)\s,\xb0#]/g, "_");
100             
101             if (element.gradient && id != element.gradient.id) {
102                 SVG.defs.removeChild(element.gradient);
103                 delete element.gradient;
104             }
105
106             if (!element.gradient) {
107                 el = $(type + "Gradient", {id: id});
108                 element.gradient = el;
109                 $(el, type == "radial" ? {
110                     fx: fx,
111                     fy: fy
112                 } : {
113                     x1: vector[0],
114                     y1: vector[1],
115                     x2: vector[2],
116                     y2: vector[3],
117                     gradientTransform: element.matrix.invert()
118                 });
119                 SVG.defs.appendChild(el);
120                 for (var i = 0, ii = dots.length; i < ii; i++) {
121                     el.appendChild($("stop", {
122                         offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
123                         "stop-color": dots[i].color || "#fff"
124                     }));
125                 }
126             }
127         }
128         $(o, {
129             fill: "url(#" + id + ")",
130             opacity: 1,
131             "fill-opacity": 1
132         });
133         s.fill = E;
134         s.opacity = 1;
135         s.fillOpacity = 1;
136         return 1;
137     },
138     updatePosition = function (o) {
139         var bbox = o.getBBox(1);
140         $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
141     },
142     addArrow = function (o, value, isEnd) {
143         if (o.type == "path") {
144             var values = Str(value).toLowerCase().split("-"),
145                 p = o.paper,
146                 se = isEnd ? "end" : "start",
147                 node = o.node,
148                 attrs = o.attrs,
149                 stroke = attrs["stroke-width"],
150                 i = values.length,
151                 type = "classic",
152                 from,
153                 to,
154                 dx,
155                 refX,
156                 attr,
157                 w = 3,
158                 h = 3,
159                 t = 5;
160             while (i--) {
161                 switch (values[i]) {
162                     case "block":
163                     case "classic":
164                     case "oval":
165                     case "diamond":
166                     case "open":
167                     case "none":
168                         type = values[i];
169                         break;
170                     case "wide": h = 5; break;
171                     case "narrow": h = 2; break;
172                     case "long": w = 5; break;
173                     case "short": w = 2; break;
174                 }
175             }
176             if (type == "open") {
177                 w += 2;
178                 h += 2;
179                 t += 2;
180                 dx = 1;
181                 refX = isEnd ? 4 : 1;
182                 attr = {
183                     fill: "none",
184                     stroke: attrs.stroke
185                 };
186             } else {
187                 refX = dx = w / 2;
188                 attr = {
189                     fill: attrs.stroke,
190                     stroke: "none"
191                 };
192             }
193             if (o._.arrows) {
194                 if (isEnd) {
195                     o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
196                     o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
197                 } else {
198                     o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
199                     o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
200                 }
201             } else {
202                 o._.arrows = {};
203             }
204             if (type != "none") {
205                 var pathId = "raphael-marker-" + type,
206                     markerId = "raphael-marker-" + se + type + w + h;
207                 if (!R._g.doc.getElementById(pathId)) {
208                     p.defs.appendChild($($("path"), {
209                         "stroke-linecap": "round",
210                         d: markers[type],
211                         id: pathId
212                     }));
213                     markerCounter[pathId] = 1;
214                 } else {
215                     markerCounter[pathId]++;
216                 }
217                 var marker = R._g.doc.getElementById(markerId),
218                     use;
219                 if (!marker) {
220                     marker = $($("marker"), {
221                         id: markerId,
222                         markerHeight: h,
223                         markerWidth: w,
224                         orient: "auto",
225                         refX: refX,
226                         refY: h / 2
227                     });
228                     use = $($("use"), {
229                         "xlink:href": "#" + pathId,
230                         transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
231                         "stroke-width": 1 / ((w / t + h / t) / 2)
232                     });
233                     marker.appendChild(use);
234                     p.defs.appendChild(marker);
235                     markerCounter[markerId] = 1;
236                 } else {
237                     markerCounter[markerId]++;
238                     use = marker.getElementsByTagName("use")[0];
239                 }
240                 $(use, attr);
241                 var delta = dx * (type != "diamond" && type != "oval");
242                 if (isEnd) {
243                     from = o._.arrows.startdx * stroke || 0;
244                     to = R.getTotalLength(attrs.path) - delta * stroke;
245                 } else {
246                     from = delta * stroke;
247                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
248                 }
249                 attr = {};
250                 attr["marker-" + se] = "url(#" + markerId + ")";
251                 if (to || from) {
252                     attr.d = Raphael.getSubpath(attrs.path, from, to);
253                 }
254                 $(node, attr);
255                 o._.arrows[se + "Path"] = pathId;
256                 o._.arrows[se + "Marker"] = markerId;
257                 o._.arrows[se + "dx"] = delta;
258                 o._.arrows[se + "Type"] = type;
259                 o._.arrows[se + "String"] = value;
260             } else {
261                 if (isEnd) {
262                     from = o._.arrows.startdx * stroke || 0;
263                     to = R.getTotalLength(attrs.path) - from;
264                 } else {
265                     from = 0;
266                     to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
267                 }
268                 o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
269                 delete o._.arrows[se + "Path"];
270                 delete o._.arrows[se + "Marker"];
271                 delete o._.arrows[se + "dx"];
272                 delete o._.arrows[se + "Type"];
273                 delete o._.arrows[se + "String"];
274             }
275             for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
276                 var item = R._g.doc.getElementById(attr);
277                 item && item.parentNode.removeChild(item);
278             }
279         }
280     },
281     dasharray = {
282         "": [0],
283         "none": [0],
284         "-": [3, 1],
285         ".": [1, 1],
286         "-.": [3, 1, 1, 1],
287         "-..": [3, 1, 1, 1, 1, 1],
288         ". ": [1, 3],
289         "- ": [4, 3],
290         "--": [8, 3],
291         "- .": [4, 3, 1, 3],
292         "--.": [8, 3, 1, 3],
293         "--..": [8, 3, 1, 3, 1, 3]
294     },
295     addDashes = function (o, value, params) {
296         value = dasharray[Str(value).toLowerCase()];
297         if (value) {
298             var width = o.attrs["stroke-width"] || "1",
299                 butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
300                 dashes = [],
301                 i = value.length;
302             while (i--) {
303                 dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
304             }
305             $(o.node, {"stroke-dasharray": dashes.join(",")});
306         }
307     },
308     setFillAndStroke = function (o, params) {
309         var node = o.node,
310             attrs = o.attrs,
311             vis = node.style.visibility;
312         node.style.visibility = "hidden";
313         for (var att in params) {
314             if (params[has](att)) {
315                 if (!R._availableAttrs[has](att)) {
316                     continue;
317                 }
318                 var value = params[att];
319                 attrs[att] = value;
320                 switch (att) {
321                     case "blur":
322                         o.blur(value);
323                         break;
324                     case "href":
325                     case "title":
326                     case "target":
327                         var pn = node.parentNode;
328                         if (pn.tagName.toLowerCase() != "a") {
329                             var hl = $("a");
330                             pn.insertBefore(hl, node);
331                             hl.appendChild(node);
332                             pn = hl;
333                         }
334                         if (att == "target" && value == "blank") {
335                             pn.setAttributeNS(xlink, "show", "new");
336                         } else {
337                             pn.setAttributeNS(xlink, att, value);
338                         }
339                         break;
340                     case "cursor":
341                         node.style.cursor = value;
342                         break;
343                     case "transform":
344                         o.transform(value);
345                         break;
346                     case "arrow-start":
347                         addArrow(o, value);
348                         break;
349                     case "arrow-end":
350                         addArrow(o, value, 1);
351                         break;
352                     case "clip-rect":
353                         var rect = Str(value).split(separator);
354                         if (rect.length == 4) {
355                             o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
356                             var el = $("clipPath"),
357                                 rc = $("rect");
358                             el.id = R.createUUID();
359                             $(rc, {
360                                 x: rect[0],
361                                 y: rect[1],
362                                 width: rect[2],
363                                 height: rect[3]
364                             });
365                             el.appendChild(rc);
366                             o.paper.defs.appendChild(el);
367                             $(node, {"clip-path": "url(#" + el.id + ")"});
368                             o.clip = rc;
369                         }
370                         if (!value) {
371                             var path = node.getAttribute("clip-path");
372                             if (path) {
373                                 var clip = R._g.doc.getElementById(path.replace(/(^url\(#|\)$)/g, E));
374                                 clip && clip.parentNode.removeChild(clip);
375                                 $(node, {"clip-path": E});
376                                 delete o.clip;
377                             }
378                         }
379                     break;
380                     case "path":
381                         if (o.type == "path") {
382                             $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
383                             o._.dirty = 1;
384                             if (o._.arrows) {
385                                 "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
386                                 "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
387                             }
388                         }
389                         break;
390                     case "width":
391                         node.setAttribute(att, value);
392                         o._.dirty = 1;
393                         if (attrs.fx) {
394                             att = "x";
395                             value = attrs.x;
396                         } else {
397                             break;
398                         }
399                     case "x":
400                         if (attrs.fx) {
401                             value = -attrs.x - (attrs.width || 0);
402                         }
403                     case "rx":
404                         if (att == "rx" && o.type == "rect") {
405                             break;
406                         }
407                     case "cx":
408                         node.setAttribute(att, value);
409                         o.pattern && updatePosition(o);
410                         o._.dirty = 1;
411                         break;
412                     case "height":
413                         node.setAttribute(att, value);
414                         o._.dirty = 1;
415                         if (attrs.fy) {
416                             att = "y";
417                             value = attrs.y;
418                         } else {
419                             break;
420                         }
421                     case "y":
422                         if (attrs.fy) {
423                             value = -attrs.y - (attrs.height || 0);
424                         }
425                     case "ry":
426                         if (att == "ry" && o.type == "rect") {
427                             break;
428                         }
429                     case "cy":
430                         node.setAttribute(att, value);
431                         o.pattern && updatePosition(o);
432                         o._.dirty = 1;
433                         break;
434                     case "r":
435                         if (o.type == "rect") {
436                             $(node, {rx: value, ry: value});
437                         } else {
438                             node.setAttribute(att, value);
439                         }
440                         o._.dirty = 1;
441                         break;
442                     case "src":
443                         if (o.type == "image") {
444                             node.setAttributeNS(xlink, "href", value);
445                         }
446                         break;
447                     case "stroke-width":
448                         if (o._.sx != 1 || o._.sy != 1) {
449                             value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
450                         }
451                         if (o.paper._vbSize) {
452                             value *= o.paper._vbSize;
453                         }
454                         node.setAttribute(att, value);
455                         if (attrs["stroke-dasharray"]) {
456                             addDashes(o, attrs["stroke-dasharray"], params);
457                         }
458                         if (o._.arrows) {
459                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
460                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
461                         }
462                         break;
463                     case "stroke-dasharray":
464                         addDashes(o, value, params);
465                         break;
466                     case "fill":
467                         var isURL = Str(value).match(R._ISURL);
468                         if (isURL) {
469                             el = $("pattern");
470                             var ig = $("image");
471                             el.id = R.createUUID();
472                             $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
473                             $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
474                             el.appendChild(ig);
475
476                             (function (el) {
477                                 R._preload(isURL[1], function () {
478                                     var w = this.offsetWidth,
479                                         h = this.offsetHeight;
480                                     $(el, {width: w, height: h});
481                                     $(ig, {width: w, height: h});
482                                     o.paper.safari();
483                                 });
484                             })(el);
485                             o.paper.defs.appendChild(el);
486                             node.style.fill = "url(#" + el.id + ")";
487                             $(node, {fill: "url(#" + el.id + ")"});
488                             o.pattern = el;
489                             o.pattern && updatePosition(o);
490                             break;
491                         }
492                         var clr = R.getRGB(value);
493                         if (!clr.error) {
494                             delete params.gradient;
495                             delete attrs.gradient;
496                             !R.is(attrs.opacity, "undefined") &&
497                                 R.is(params.opacity, "undefined") &&
498                                 $(node, {opacity: attrs.opacity});
499                             !R.is(attrs["fill-opacity"], "undefined") &&
500                                 R.is(params["fill-opacity"], "undefined") &&
501                                 $(node, {"fill-opacity": attrs["fill-opacity"]});
502                         } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
503                             if ("opacity" in attrs || "fill-opacity" in attrs) {
504                                 var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
505                                 if (gradient) {
506                                     var stops = gradient.getElementsByTagName("stop");
507                                     $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
508                                 }
509                             }
510                             attrs.gradient = value;
511                             attrs.fill = "none";
512                             break;
513                         }
514                         clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
515                     case "stroke":
516                         clr = R.getRGB(value);
517                         node.setAttribute(att, clr.hex);
518                         att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
519                         if (att == "stroke" && o._.arrows) {
520                             "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
521                             "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
522                         }
523                         break;
524                     case "gradient":
525                         (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
526                         break;
527                     case "opacity":
528                         if (attrs.gradient && !attrs[has]("stroke-opacity")) {
529                             $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
530                         }
531                         // fall
532                     case "fill-opacity":
533                         if (attrs.gradient) {
534                             gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
535                             if (gradient) {
536                                 stops = gradient.getElementsByTagName("stop");
537                                 $(stops[stops.length - 1], {"stop-opacity": value});
538                             }
539                             break;
540                         }
541                     default:
542                         att == "font-size" && (value = toInt(value, 10) + "px");
543                         var cssrule = att.replace(/(\-.)/g, function (w) {
544                             return w.substring(1).toUpperCase();
545                         });
546                         node.style[cssrule] = value;
547                         o._.dirty = 1;
548                         node.setAttribute(att, value);
549                         break;
550                 }
551             }
552         }
553
554         tuneText(o, params);
555         node.style.visibility = vis;
556     },
557     leading = 1.2,
558     tuneText = function (el, params) {
559         if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
560             return;
561         }
562         var a = el.attrs,
563             node = el.node,
564             fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
565
566         if (params[has]("text")) {
567             a.text = params.text;
568             while (node.firstChild) {
569                 node.removeChild(node.firstChild);
570             }
571             var texts = Str(params.text).split("\n"),
572                 tspans = [],
573                 tspan;
574             for (var i = 0, ii = texts.length; i < ii; i++) {
575                 tspan = $("tspan");
576                 i && $(tspan, {dy: fontSize * leading, x: a.x});
577                 tspan.appendChild(R._g.doc.createTextNode(texts[i]));
578                 node.appendChild(tspan);
579                 tspans[i] = tspan;
580             }
581         } else {
582             tspans = node.getElementsByTagName("tspan");
583             for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
584                 $(tspans[i], {dy: fontSize * leading, x: a.x});
585             } else {
586                 $(tspans[0], {dy: 0});
587             }
588         }
589         $(node, {x: a.x, y: a.y});
590         el._.dirty = 1;
591         var bb = el._getBBox(),
592             dif = a.y - (bb.y + bb.height / 2);
593         dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
594     },
595     Element = function (node, svg) {
596         var X = 0,
597             Y = 0;
598         /*\
599          * Element.node
600          [ property (object) ]
601          **
602          * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
603          **
604          * Note: Don’t mess with it.
605          > Usage
606          | // draw a circle at coordinate 10,10 with radius of 10
607          | var c = paper.circle(10, 10, 10);
608          | c.node.onclick = function () {
609          |     c.attr("fill", "red");
610          | };
611         \*/
612         this[0] = this.node = node;
613         /*\
614          * Element.raphael
615          [ property (object) ]
616          **
617          * Internal reference to @Raphael object. In case it is not available.
618          > Usage
619          | Raphael.el.red = function () {
620          |     var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
621          |     hsb.h = 1;
622          |     this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
623          | }
624         \*/
625         node.raphael = true;
626         /*\
627          * Element.id
628          [ property (number) ]
629          **
630          * Unique id of the element. Especially usesful when you want to listen to events of the element, 
631          * because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
632         \*/
633         this.id = R._oid++;
634         node.raphaelid = this.id;
635         this.matrix = R.matrix();
636         this.realPath = null;
637         /*\
638          * Element.paper
639          [ property (object) ]
640          **
641          * Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
642          > Usage
643          | Raphael.el.cross = function () {
644          |     this.attr({fill: "red"});
645          |     this.paper.path("M10,10L50,50M50,10L10,50")
646          |         .attr({stroke: "red"});
647          | }
648         \*/
649         this.paper = svg;
650         this.attrs = this.attrs || {};
651         this._ = {
652             transform: [],
653             sx: 1,
654             sy: 1,
655             deg: 0,
656             dx: 0,
657             dy: 0,
658             dirty: 1
659         };
660         !svg.bottom && (svg.bottom = this);
661         /*\
662          * Element.prev
663          [ property (object) ]
664          **
665          * Reference to the previous element in the hierarchy.
666         \*/
667         this.prev = svg.top;
668         svg.top && (svg.top.next = this);
669         svg.top = this;
670         /*\
671          * Element.next
672          [ property (object) ]
673          **
674          * Reference to the next element in the hierarchy.
675         \*/
676         this.next = null;
677     },
678     elproto = R.el;
679
680     Element.prototype = elproto;
681     elproto.constructor = Element;
682
683     R._engine.path = function (pathString, SVG) {
684         var el = $("path");
685         SVG.canvas && SVG.canvas.appendChild(el);
686         var p = new Element(el, SVG);
687         p.type = "path";
688         setFillAndStroke(p, {
689             fill: "none",
690             stroke: "#000",
691             path: pathString
692         });
693         return p;
694     };
695     /*\
696      * Element.rotate
697      [ method ]
698      **
699      * Adds rotation by given angle around given point to the list of
700      * transformations of the element.
701      > Parameters
702      - deg (number) angle in degrees
703      - cx (number) #optional x coordinate of the centre of rotation
704      - cy (number) #optional y coordinate of the centre of rotation
705      * If cx & cy aren’t specified centre of the shape is used as a point of rotation.
706      = (object) @Element
707     \*/
708     elproto.rotate = function (deg, cx, cy) {
709         if (this.removed) {
710             return this;
711         }
712         deg = Str(deg).split(separator);
713         if (deg.length - 1) {
714             cx = toFloat(deg[1]);
715             cy = toFloat(deg[2]);
716         }
717         deg = toFloat(deg[0]);
718         (cy == null) && (cx = cy);
719         if (cx == null || cy == null) {
720             var bbox = this.getBBox(1);
721             cx = bbox.x + bbox.width / 2;
722             cy = bbox.y + bbox.height / 2;
723         }
724         this.transform(this._.transform.concat([["r", deg, cx, cy]]));
725         return this;
726     };
727     /*\
728      * Element.scale
729      [ method ]
730      **
731      * Adds scale by given amount relative to given point to the list of
732      * transformations of the element.
733      > Parameters
734      - sx (number) horisontal scale amount
735      - sy (number) vertical scale amount
736      - cx (number) #optional x coordinate of the centre of scale
737      - cy (number) #optional y coordinate of the centre of scale
738      * If cx & cy aren’t specified centre of the shape is used instead.
739      = (object) @Element
740     \*/
741     elproto.scale = function (sx, sy, cx, cy) {
742         if (this.removed) {
743             return this;
744         }
745         sx = Str(sx).split(separator);
746         if (sx.length - 1) {
747             sy = toFloat(sx[1]);
748             cx = toFloat(sx[2]);
749             cy = toFloat(sx[3]);
750         }
751         sx = toFloat(sx[0]);
752         (sy == null) && (sy = sx);
753         (cy == null) && (cx = cy);
754         if (cx == null || cy == null) {
755             var bbox = this.getBBox(1);
756         }
757         cx = cx == null ? bbox.x + bbox.width / 2 : cx;
758         cy = cy == null ? bbox.y + bbox.height / 2 : cy;
759         this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
760         return this;
761     };
762     /*\
763      * Element.translate
764      [ method ]
765      **
766      * Adds translation by given amount to the list of transformations of the element.
767      > Parameters
768      - dx (number) horisontal shift
769      - dy (number) vertical shift
770      = (object) @Element
771     \*/
772     elproto.translate = function (dx, dy) {
773         if (this.removed) {
774             return this;
775         }
776         dx = Str(dx).split(separator);
777         if (dx.length - 1) {
778             dy = toFloat(dx[1]);
779         }
780         dx = toFloat(dx[0]) || 0;
781         dy = +dy || 0;
782         this.transform(this._.transform.concat([["t", dx, dy]]));
783         return this;
784     };
785     /*\
786      * Element.transform
787      [ method ]
788      **
789      * Adds transformation to the element which is separate to other attributes,
790      * i.e. translation doesn’t change `x` or `y` of the rectange. The format
791      * of transformation string is similar to the path string syntax:
792      | "t100,100r30,100,100s2,2,100,100r45s1.5"
793      * Each letter is a command. There are four commands: `t` is for translate, `r` is for rotate, `s` is for
794      * scale and `m` is for matrix.
795      *
796      * 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`.
797      *
798      * So, the example line above could be read like “translate by 100, 100; rotate 30° around 100, 100; scale twice around 100, 100;
799      * rotate 45° around centre; scale 1.5 times relative to centre”. As you can see rotate and scale commands have origin
800      * coordinates as optional parameters, the default is the centre point of the element.
801      * Matrix accepts six parameters.
802      > Usage
803      | var el = paper.rect(10, 20, 300, 200);
804      | // translate 100, 100, rotate 45°, translate -100, 0
805      | el.transform("t100,100r45t-100,0");
806      | // if you want you can append or prepend transformations
807      | el.transform("...t50,50");
808      | el.transform("s2...");
809      | // or even wrap
810      | el.transform("t50,50...t-50-50");
811      | // to reset transformation call method with empty string
812      | el.transform("");
813      | // to get current value call it without parameters
814      | console.log(el.transform());
815      > Parameters
816      - tstr (string) #optional transformation string
817      * If tstr isn’t specified
818      = (string) current transformation string
819      * else
820      = (object) @Element
821     \*/
822     elproto.transform = function (tstr) {
823         var _ = this._;
824         if (tstr == null) {
825             return _.transform;
826         }
827         R._extractTransform(this, tstr);
828
829         this.clip && $(this.clip, {transform: this.matrix.invert()});
830         this.pattern && updatePosition(this);
831         this.node && $(this.node, {transform: this.matrix});
832     
833         if (_.sx != 1 || _.sy != 1) {
834             var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
835             this.attr({"stroke-width": sw});
836         }
837
838         return this;
839     };
840     /*\
841      * Element.hide
842      [ method ]
843      **
844      * Makes element invisible. See @Element.show.
845      = (object) @Element
846     \*/
847     elproto.hide = function () {
848         !this.removed && this.paper.safari(this.node.style.display = "none");
849         return this;
850     };
851     /*\
852      * Element.show
853      [ method ]
854      **
855      * Makes element visible. See @Element.hide.
856      = (object) @Element
857     \*/
858     elproto.show = function () {
859         !this.removed && this.paper.safari(this.node.style.display = "");
860         return this;
861     };
862     /*\
863      * Element.remove
864      [ method ]
865      **
866      * Removes element form the paper.
867     \*/
868     elproto.remove = function () {
869         if (this.removed) {
870             return;
871         }
872         var paper = this.paper;
873         paper.__set__ && paper.__set__.exclude(this);
874         eve.unbind("*.*." + this.id);
875         if (this.gradient) {
876             paper.defs.removeChild(this.gradient);
877         }
878         R._tear(this, paper);
879         this.node.parentNode.removeChild(this.node);
880         for (var i in this) {
881             this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
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) the x-axis coordinate of the center of the circle, or ellipse
925      o cy (number) the y-axis coordinate of the center of the circle, or ellipse
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) radius of the circle, ellipse or rounded corner on the rect
937      o rx (number) horisontal radius of the ellipse
938      o ry (number) vertical radius of the ellipse
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         if (this.node.parentNode.tagName.toLowerCase() == "a") {
1054             this.node.parentNode.parentNode.appendChild(this.node.parentNode);
1055         } else {
1056             this.node.parentNode.appendChild(this.node);
1057         }
1058         var svg = this.paper;
1059         svg.top != this && R._tofront(this, svg);
1060         return this;
1061     };
1062     /*\
1063      * Element.toBack
1064      [ method ]
1065      **
1066      * Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
1067      = (object) @Element
1068     \*/
1069     elproto.toBack = function () {
1070         if (this.removed) {
1071             return this;
1072         }
1073         var parent = this.node.parentNode;
1074         if (parent.tagName.toLowerCase() == "a") {
1075             parent.parentNode.insertBefore(this.node.parentNode, this.node.parentNode.parentNode.firstChild); 
1076         } else if (parent.firstChild != this.node) {
1077             parent.insertBefore(this.node, this.node.parentNode.firstChild);
1078         }
1079         R._toback(this, this.paper);
1080         var svg = this.paper;
1081         return this;
1082     };
1083     /*\
1084      * Element.insertAfter
1085      [ method ]
1086      **
1087      * Inserts current object after the given one.
1088      = (object) @Element
1089     \*/
1090     elproto.insertAfter = function (element) {
1091         if (this.removed) {
1092             return this;
1093         }
1094         var node = element.node || element[element.length - 1].node;
1095         if (node.nextSibling) {
1096             node.parentNode.insertBefore(this.node, node.nextSibling);
1097         } else {
1098             node.parentNode.appendChild(this.node);
1099         }
1100         R._insertafter(this, element, this.paper);
1101         return this;
1102     };
1103     /*\
1104      * Element.insertBefore
1105      [ method ]
1106      **
1107      * Inserts current object before the given one.
1108      = (object) @Element
1109     \*/
1110     elproto.insertBefore = function (element) {
1111         if (this.removed) {
1112             return this;
1113         }
1114         var node = element.node || element[0].node;
1115         node.parentNode.insertBefore(this.node, node);
1116         R._insertbefore(this, element, this.paper);
1117         return this;
1118     };
1119     elproto.blur = function (size) {
1120         // Experimental. No Safari support. Use it on your own risk.
1121         var t = this;
1122         if (+size !== 0) {
1123             var fltr = $("filter"),
1124                 blur = $("feGaussianBlur");
1125             t.attrs.blur = size;
1126             fltr.id = R.createUUID();
1127             $(blur, {stdDeviation: +size || 1.5});
1128             fltr.appendChild(blur);
1129             t.paper.defs.appendChild(fltr);
1130             t._blur = fltr;
1131             $(t.node, {filter: "url(#" + fltr.id + ")"});
1132         } else {
1133             if (t._blur) {
1134                 t._blur.parentNode.removeChild(t._blur);
1135                 delete t._blur;
1136                 delete t.attrs.blur;
1137             }
1138             t.node.removeAttribute("filter");
1139         }
1140     };
1141     R._engine.circle = function (svg, x, y, r) {
1142         var el = $("circle");
1143         svg.canvas && svg.canvas.appendChild(el);
1144         var res = new Element(el, svg);
1145         res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
1146         res.type = "circle";
1147         $(el, res.attrs);
1148         return res;
1149     };
1150     R._engine.rect = function (svg, x, y, w, h, r) {
1151         var el = $("rect");
1152         svg.canvas && svg.canvas.appendChild(el);
1153         var res = new Element(el, svg);
1154         res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
1155         res.type = "rect";
1156         $(el, res.attrs);
1157         return res;
1158     };
1159     R._engine.ellipse = function (svg, x, y, rx, ry) {
1160         var el = $("ellipse");
1161         svg.canvas && svg.canvas.appendChild(el);
1162         var res = new Element(el, svg);
1163         res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
1164         res.type = "ellipse";
1165         $(el, res.attrs);
1166         return res;
1167     };
1168     R._engine.image = function (svg, src, x, y, w, h) {
1169         var el = $("image");
1170         $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
1171         el.setAttributeNS(xlink, "href", src);
1172         svg.canvas && svg.canvas.appendChild(el);
1173         var res = new Element(el, svg);
1174         res.attrs = {x: x, y: y, width: w, height: h, src: src};
1175         res.type = "image";
1176         return res;
1177     };
1178     R._engine.text = function (svg, x, y, text) {
1179         var el = $("text");
1180         // $(el, {x: x, y: y, "text-anchor": "middle"});
1181         svg.canvas && svg.canvas.appendChild(el);
1182         var res = new Element(el, svg);
1183         res.attrs = {
1184             x: x,
1185             y: y,
1186             "text-anchor": "middle",
1187             text: text,
1188             font: R._availableAttrs.font,
1189             stroke: "none",
1190             fill: "#000"
1191         };
1192         res.type = "text";
1193         setFillAndStroke(res, res.attrs);
1194         return res;
1195     };
1196     R._engine.setSize = function (width, height) {
1197         this.width = width || this.width;
1198         this.height = height || this.height;
1199         this.canvas.setAttribute("width", this.width);
1200         this.canvas.setAttribute("height", this.height);
1201         if (this._viewBox) {
1202             this.setViewBox.apply(this, this._viewBox);
1203         }
1204         return this;
1205     };
1206     R._engine.create = function () {
1207         var con = R._getContainer.apply(0, arguments),
1208             container = con && con.container,
1209             x = con.x,
1210             y = con.y,
1211             width = con.width,
1212             height = con.height;
1213         if (!container) {
1214             throw new Error("SVG container not found.");
1215         }
1216         var cnvs = $("svg"),
1217             css = "overflow:hidden;",
1218             isFloating;
1219         x = x || 0;
1220         y = y || 0;
1221         width = width || 512;
1222         height = height || 342;
1223         $(cnvs, {
1224             height: height,
1225             version: 1.1,
1226             width: width,
1227             xmlns: "http://www.w3.org/2000/svg"
1228         });
1229         if (container == 1) {
1230             cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
1231             R._g.doc.body.appendChild(cnvs);
1232             isFloating = 1;
1233         } else {
1234             cnvs.style.cssText = css + "position:relative";
1235             if (container.firstChild) {
1236                 container.insertBefore(cnvs, container.firstChild);
1237             } else {
1238                 container.appendChild(cnvs);
1239             }
1240         }
1241         container = new R._Paper;
1242         container.width = width;
1243         container.height = height;
1244         container.canvas = cnvs;
1245         // plugins.call(container, container, R.fn);
1246         container.clear();
1247         container._left = container._top = 0;
1248         isFloating && (container.renderfix = function () {});
1249         container.renderfix();
1250         return container;
1251     };
1252     R._engine.setViewBox = function (x, y, w, h, fit) {
1253         eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
1254         var size = mmax(w / this.width, h / this.height),
1255             top = this.top,
1256             aspectRatio = fit ? "meet" : "xMinYMin",
1257             vb,
1258             sw;
1259         if (x == null) {
1260             if (this._vbSize) {
1261                 size = 1;
1262             }
1263             delete this._vbSize;
1264             vb = "0 0 " + this.width + S + this.height;
1265         } else {
1266             this._vbSize = size;
1267             vb = x + S + y + S + w + S + h;
1268         }
1269         $(this.canvas, {
1270             viewBox: vb,
1271             preserveAspectRatio: aspectRatio
1272         });
1273         while (size && top) {
1274             sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
1275             top.attr({"stroke-width": sw});
1276             top._.dirty = 1;
1277             top._.dirtyT = 1;
1278             top = top.prev;
1279         }
1280         this._viewBox = [x, y, w, h, !!fit];
1281         return this;
1282     };
1283     /*\
1284      * Paper.renderfix
1285      [ method ]
1286      **
1287      * Fixes the issue of Firefox and IE9 regarding subpixel rendering. If paper is dependant
1288      * on other elements after reflow it could shift half pixel which cause for lines to lost their crispness.
1289      * This method fixes the issue.
1290      **
1291        Special thanks to Mariusz Nowak (http://www.medikoo.com/) for this method.
1292     \*/
1293     R.prototype.renderfix = function () {
1294         var cnvs = this.canvas,
1295             s = cnvs.style,
1296             pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix(),
1297             left = -pos.e % 1,
1298             top = -pos.f % 1;
1299         if (left || top) {
1300             if (left) {
1301                 this._left = (this._left + left) % 1;
1302                 s.left = this._left + "px";
1303             }
1304             if (top) {
1305                 this._top = (this._top + top) % 1;
1306                 s.top = this._top + "px";
1307             }
1308         }
1309     };
1310     /*\
1311      * Paper.clear
1312      [ method ]
1313      **
1314      * Clears the paper, i.e. removes all the elements.
1315     \*/
1316     R.prototype.clear = function () {
1317         R.eve("clear", this);
1318         var c = this.canvas;
1319         while (c.firstChild) {
1320             c.removeChild(c.firstChild);
1321         }
1322         this.bottom = this.top = null;
1323         (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
1324         c.appendChild(this.desc);
1325         c.appendChild(this.defs = $("defs"));
1326     };
1327     /*\
1328      * Paper.remove
1329      [ method ]
1330      **
1331      * Removes the paper from the DOM.
1332     \*/
1333     R.prototype.remove = function () {
1334         eve("remove", this);
1335         this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
1336         for (var i in this) {
1337             this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
1338         }
1339     };
1340     var setproto = R.st;
1341     for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
1342         setproto[method] = (function (methodname) {
1343             return function () {
1344                 var arg = arguments;
1345                 return this.forEach(function (el) {
1346                     el[methodname].apply(el, arg);
1347                 });
1348             };
1349         })(method);
1350     }
1351 }(window.Raphael);