abcjs-rails 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/abcjs-rails.js +1 -0
- data/app/assets/javascripts/abcjs/api/abc_tunebook.js +158 -0
- data/app/assets/javascripts/abcjs/data/abc_tune.js +686 -0
- data/app/assets/javascripts/abcjs/edit/abc_editor.js +414 -0
- data/app/assets/javascripts/abcjs/midi/abc_midiwriter.js +698 -0
- data/app/assets/javascripts/abcjs/parse/abc_common.js +76 -0
- data/app/assets/javascripts/abcjs/parse/abc_parse.js +1385 -0
- data/app/assets/javascripts/abcjs/parse/abc_parse_directive.js +546 -0
- data/app/assets/javascripts/abcjs/parse/abc_parse_header.js +521 -0
- data/app/assets/javascripts/abcjs/parse/abc_parse_key_voice.js +781 -0
- data/app/assets/javascripts/abcjs/parse/abc_tokenizer.js +751 -0
- data/app/assets/javascripts/abcjs/write/abc_glyphs.js +105 -0
- data/app/assets/javascripts/abcjs/write/abc_graphelements.js +781 -0
- data/app/assets/javascripts/abcjs/write/abc_layout.js +959 -0
- data/app/assets/javascripts/abcjs/write/abc_write.js +487 -0
- data/app/assets/javascripts/abcjs/write/raphael.js +3395 -0
- data/app/assets/javascripts/abcjs/write/sprintf.js +61 -0
- data/lib/abcjs-rails/version.rb +1 -1
- metadata +18 -1
@@ -0,0 +1,3395 @@
|
|
1
|
+
/*!
|
2
|
+
* Raphael 1.4.3 - JavaScript Vector Library
|
3
|
+
*
|
4
|
+
* Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
|
5
|
+
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
|
6
|
+
*/
|
7
|
+
|
8
|
+
Raphael = (function () {
|
9
|
+
function R() {
|
10
|
+
if (R.is(arguments[0], array)) {
|
11
|
+
var a = arguments[0],
|
12
|
+
cnv = create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
|
13
|
+
res = cnv.set();
|
14
|
+
for (var i = 0, ii = a[length]; i < ii; i++) {
|
15
|
+
var j = a[i] || {};
|
16
|
+
elements.test(j.type) && res[push](cnv[j.type]().attr(j));
|
17
|
+
}
|
18
|
+
return res;
|
19
|
+
}
|
20
|
+
return create[apply](R, arguments);
|
21
|
+
}
|
22
|
+
R.version = "1.4.3";
|
23
|
+
var separator = /[, ]+/,
|
24
|
+
elements = /^(circle|rect|path|ellipse|text|image)$/,
|
25
|
+
proto = "prototype",
|
26
|
+
has = "hasOwnProperty",
|
27
|
+
doc = document,
|
28
|
+
win = window,
|
29
|
+
oldRaphael = {
|
30
|
+
was: Object[proto][has].call(win, "Raphael"),
|
31
|
+
is: win.Raphael
|
32
|
+
},
|
33
|
+
Paper = function () {},
|
34
|
+
appendChild = "appendChild",
|
35
|
+
apply = "apply",
|
36
|
+
concat = "concat",
|
37
|
+
supportsTouch = "createTouch" in doc,
|
38
|
+
E = "",
|
39
|
+
S = " ",
|
40
|
+
split = "split",
|
41
|
+
events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend orientationchange touchcancel gesturestart gesturechange gestureend"[split](S),
|
42
|
+
touchMap = {
|
43
|
+
mousedown: "touchstart",
|
44
|
+
mousemove: "touchmove",
|
45
|
+
mouseup: "touchend"
|
46
|
+
},
|
47
|
+
join = "join",
|
48
|
+
length = "length",
|
49
|
+
lowerCase = String[proto].toLowerCase,
|
50
|
+
math = Math,
|
51
|
+
mmax = math.max,
|
52
|
+
mmin = math.min,
|
53
|
+
nu = "number",
|
54
|
+
string = "string",
|
55
|
+
array = "array",
|
56
|
+
toString = "toString",
|
57
|
+
fillString = "fill",
|
58
|
+
objectToString = Object[proto][toString],
|
59
|
+
paper = {},
|
60
|
+
pow = math.pow,
|
61
|
+
push = "push",
|
62
|
+
rg = /^(?=[\da-f]$)/,
|
63
|
+
ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
|
64
|
+
colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+(?:\s*,\s*[\d\.]+)?)\s*\)|rgba?\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%(?:\s*,\s*[\d\.]+%))\s*\)|hs[bl]\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hs[bl]\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i,
|
65
|
+
round = math.round,
|
66
|
+
setAttribute = "setAttribute",
|
67
|
+
toFloat = parseFloat,
|
68
|
+
toInt = parseInt,
|
69
|
+
ms = " progid:DXImageTransform.Microsoft",
|
70
|
+
upperCase = String[proto].toUpperCase,
|
71
|
+
availableAttrs = {blur: 0, "clip-rect": "0 0 1e9 1e9", cursor: "default", cx: 0, cy: 0, fill: "#fff", "fill-opacity": 1, font: '10px "Arial"', "font-family": '"Arial"', "font-size": "10", "font-style": "normal", "font-weight": 400, gradient: 0, height: 0, href: "http://raphaeljs.com/", opacity: 1, path: "M0,0", r: 0, rotation: 0, rx: 0, ry: 0, scale: "1 1", src: "", stroke: "#000", "stroke-dasharray": "", "stroke-linecap": "butt", "stroke-linejoin": "butt", "stroke-miterlimit": 0, "stroke-opacity": 1, "stroke-width": 1, target: "_blank", "text-anchor": "middle", title: "Raphael", translation: "0 0", width: 0, x: 0, y: 0},
|
72
|
+
availableAnimAttrs = {along: "along", blur: nu, "clip-rect": "csv", cx: nu, cy: nu, fill: "colour", "fill-opacity": nu, "font-size": nu, height: nu, opacity: nu, path: "path", r: nu, rotation: "csv", rx: nu, ry: nu, scale: "csv", stroke: "colour", "stroke-opacity": nu, "stroke-width": nu, translation: "csv", width: nu, x: nu, y: nu},
|
73
|
+
rp = "replace";
|
74
|
+
R.type = (win.SVGAngle || doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
|
75
|
+
if (R.type == "VML") {
|
76
|
+
var d = doc.createElement("div");
|
77
|
+
d.innerHTML = '<!--[if vml]><br><br><![endif]-->';
|
78
|
+
if (d.childNodes[length] != 2) {
|
79
|
+
return R.type = null;
|
80
|
+
}
|
81
|
+
d = null;
|
82
|
+
}
|
83
|
+
R.svg = !(R.vml = R.type == "VML");
|
84
|
+
Paper[proto] = R[proto];
|
85
|
+
R._id = 0;
|
86
|
+
R._oid = 0;
|
87
|
+
R.fn = {};
|
88
|
+
R.is = function (o, type) {
|
89
|
+
type = lowerCase.call(type);
|
90
|
+
return (type == "object" && o === Object(o)) ||
|
91
|
+
(type == "undefined" && typeof o == type) ||
|
92
|
+
(type == "null" && o == null) ||
|
93
|
+
lowerCase.call(objectToString.call(o).slice(8, -1)) == type;
|
94
|
+
};
|
95
|
+
|
96
|
+
R.setWindow = function (newwin) {
|
97
|
+
win = newwin;
|
98
|
+
doc = win.document;
|
99
|
+
};
|
100
|
+
// colour utilities
|
101
|
+
var toHex = function (color) {
|
102
|
+
if (R.vml) {
|
103
|
+
// http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
|
104
|
+
var trim = /^\s+|\s+$/g;
|
105
|
+
toHex = cacher(function (color) {
|
106
|
+
var bod;
|
107
|
+
color = (color + E)[rp](trim, E);
|
108
|
+
try {
|
109
|
+
var docum = new win.ActiveXObject("htmlfile");
|
110
|
+
docum.write("<body>");
|
111
|
+
docum.close();
|
112
|
+
bod = docum.body;
|
113
|
+
} catch(e) {
|
114
|
+
bod = win.createPopup().document.body;
|
115
|
+
}
|
116
|
+
var range = bod.createTextRange();
|
117
|
+
try {
|
118
|
+
bod.style.color = color;
|
119
|
+
var value = range.queryCommandValue("ForeColor");
|
120
|
+
value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
|
121
|
+
return "#" + ("000000" + value[toString](16)).slice(-6);
|
122
|
+
} catch(e) {
|
123
|
+
return "none";
|
124
|
+
}
|
125
|
+
});
|
126
|
+
} else {
|
127
|
+
var i = doc.createElement("i");
|
128
|
+
i.title = "Rapha\xebl Colour Picker";
|
129
|
+
i.style.display = "none";
|
130
|
+
doc.body[appendChild](i);
|
131
|
+
toHex = cacher(function (color) {
|
132
|
+
i.style.color = color;
|
133
|
+
return doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
|
134
|
+
});
|
135
|
+
}
|
136
|
+
return toHex(color);
|
137
|
+
};
|
138
|
+
var hsbtoString = function () {
|
139
|
+
return "hsb(" + [this.h, this.s, this.b] + ")";
|
140
|
+
},
|
141
|
+
rgbtoString = function () {
|
142
|
+
return this.hex;
|
143
|
+
};
|
144
|
+
R.hsb2rgb = cacher(function (hue, saturation, brightness) {
|
145
|
+
if (R.is(hue, "object") && "h" in hue && "s" in hue && "b" in hue) {
|
146
|
+
brightness = hue.b;
|
147
|
+
saturation = hue.s;
|
148
|
+
hue = hue.h;
|
149
|
+
}
|
150
|
+
var red,
|
151
|
+
green,
|
152
|
+
blue;
|
153
|
+
if (brightness == 0) {
|
154
|
+
return {r: 0, g: 0, b: 0, hex: "#000"};
|
155
|
+
}
|
156
|
+
if (hue > 1 || saturation > 1 || brightness > 1) {
|
157
|
+
hue /= 255;
|
158
|
+
saturation /= 255;
|
159
|
+
brightness /= 255;
|
160
|
+
}
|
161
|
+
var i = ~~(hue * 6),
|
162
|
+
f = (hue * 6) - i,
|
163
|
+
p = brightness * (1 - saturation),
|
164
|
+
q = brightness * (1 - (saturation * f)),
|
165
|
+
t = brightness * (1 - (saturation * (1 - f)));
|
166
|
+
red = [brightness, q, p, p, t, brightness, brightness][i];
|
167
|
+
green = [t, brightness, brightness, q, p, p, t][i];
|
168
|
+
blue = [p, p, t, brightness, brightness, q, p][i];
|
169
|
+
red *= 255;
|
170
|
+
green *= 255;
|
171
|
+
blue *= 255;
|
172
|
+
var rgb = {r: red, g: green, b: blue, toString: rgbtoString},
|
173
|
+
r = (~~red)[toString](16),
|
174
|
+
g = (~~green)[toString](16),
|
175
|
+
b = (~~blue)[toString](16);
|
176
|
+
r = r[rp](rg, "0");
|
177
|
+
g = g[rp](rg, "0");
|
178
|
+
b = b[rp](rg, "0");
|
179
|
+
rgb.hex = "#" + r + g + b;
|
180
|
+
return rgb;
|
181
|
+
}, R);
|
182
|
+
R.rgb2hsb = cacher(function (red, green, blue) {
|
183
|
+
if (R.is(red, "object") && "r" in red && "g" in red && "b" in red) {
|
184
|
+
blue = red.b;
|
185
|
+
green = red.g;
|
186
|
+
red = red.r;
|
187
|
+
}
|
188
|
+
if (R.is(red, string)) {
|
189
|
+
var clr = R.getRGB(red);
|
190
|
+
red = clr.r;
|
191
|
+
green = clr.g;
|
192
|
+
blue = clr.b;
|
193
|
+
}
|
194
|
+
if (red > 1 || green > 1 || blue > 1) {
|
195
|
+
red /= 255;
|
196
|
+
green /= 255;
|
197
|
+
blue /= 255;
|
198
|
+
}
|
199
|
+
var max = mmax(red, green, blue),
|
200
|
+
min = mmin(red, green, blue),
|
201
|
+
hue,
|
202
|
+
saturation,
|
203
|
+
brightness = max;
|
204
|
+
if (min == max) {
|
205
|
+
return {h: 0, s: 0, b: max};
|
206
|
+
} else {
|
207
|
+
var delta = (max - min);
|
208
|
+
saturation = delta / max;
|
209
|
+
if (red == max) {
|
210
|
+
hue = (green - blue) / delta;
|
211
|
+
} else if (green == max) {
|
212
|
+
hue = 2 + ((blue - red) / delta);
|
213
|
+
} else {
|
214
|
+
hue = 4 + ((red - green) / delta);
|
215
|
+
}
|
216
|
+
hue /= 6;
|
217
|
+
hue < 0 && hue++;
|
218
|
+
hue > 1 && hue--;
|
219
|
+
}
|
220
|
+
return {h: hue, s: saturation, b: brightness, toString: hsbtoString};
|
221
|
+
}, R);
|
222
|
+
var p2s = /,?([achlmqrstvxz]),?/gi,
|
223
|
+
commaSpaces = /\s*,\s*/,
|
224
|
+
hsrg = {hs: 1, rg: 1};
|
225
|
+
R._path2string = function () {
|
226
|
+
return this.join(",")[rp](p2s, "$1");
|
227
|
+
};
|
228
|
+
function cacher(f, scope, postprocessor) {
|
229
|
+
function newf() {
|
230
|
+
var arg = Array[proto].slice.call(arguments, 0),
|
231
|
+
args = arg[join]("\u25ba"),
|
232
|
+
cache = newf.cache = newf.cache || {},
|
233
|
+
count = newf.count = newf.count || [];
|
234
|
+
if (cache[has](args)) {
|
235
|
+
return postprocessor ? postprocessor(cache[args]) : cache[args];
|
236
|
+
}
|
237
|
+
count[length] >= 1e3 && delete cache[count.shift()];
|
238
|
+
count[push](args);
|
239
|
+
cache[args] = f[apply](scope, arg);
|
240
|
+
return postprocessor ? postprocessor(cache[args]) : cache[args];
|
241
|
+
}
|
242
|
+
return newf;
|
243
|
+
}
|
244
|
+
|
245
|
+
R.getRGB = cacher(function (colour) {
|
246
|
+
if (!colour || !!((colour = colour + E).indexOf("-") + 1)) {
|
247
|
+
return {r: -1, g: -1, b: -1, hex: "none", error: 1};
|
248
|
+
}
|
249
|
+
if (colour == "none") {
|
250
|
+
return {r: -1, g: -1, b: -1, hex: "none"};
|
251
|
+
}
|
252
|
+
!(hsrg[has](colour.substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
|
253
|
+
var res,
|
254
|
+
red,
|
255
|
+
green,
|
256
|
+
blue,
|
257
|
+
opacity,
|
258
|
+
t,
|
259
|
+
rgb = colour.match(colourRegExp);
|
260
|
+
if (rgb) {
|
261
|
+
if (rgb[2]) {
|
262
|
+
blue = toInt(rgb[2].substring(5), 16);
|
263
|
+
green = toInt(rgb[2].substring(3, 5), 16);
|
264
|
+
red = toInt(rgb[2].substring(1, 3), 16);
|
265
|
+
}
|
266
|
+
if (rgb[3]) {
|
267
|
+
blue = toInt((t = rgb[3].charAt(3)) + t, 16);
|
268
|
+
green = toInt((t = rgb[3].charAt(2)) + t, 16);
|
269
|
+
red = toInt((t = rgb[3].charAt(1)) + t, 16);
|
270
|
+
}
|
271
|
+
if (rgb[4]) {
|
272
|
+
rgb = rgb[4][split](commaSpaces);
|
273
|
+
red = toFloat(rgb[0]);
|
274
|
+
green = toFloat(rgb[1]);
|
275
|
+
blue = toFloat(rgb[2]);
|
276
|
+
opacity = toFloat(rgb[3]);
|
277
|
+
}
|
278
|
+
if (rgb[5]) {
|
279
|
+
rgb = rgb[5][split](commaSpaces);
|
280
|
+
red = toFloat(rgb[0]) * 2.55;
|
281
|
+
green = toFloat(rgb[1]) * 2.55;
|
282
|
+
blue = toFloat(rgb[2]) * 2.55;
|
283
|
+
opacity = toFloat(rgb[3]);
|
284
|
+
}
|
285
|
+
if (rgb[6]) {
|
286
|
+
rgb = rgb[6][split](commaSpaces);
|
287
|
+
red = toFloat(rgb[0]);
|
288
|
+
green = toFloat(rgb[1]);
|
289
|
+
blue = toFloat(rgb[2]);
|
290
|
+
return R.hsb2rgb(red, green, blue);
|
291
|
+
}
|
292
|
+
if (rgb[7]) {
|
293
|
+
rgb = rgb[7][split](commaSpaces);
|
294
|
+
red = toFloat(rgb[0]) * 2.55;
|
295
|
+
green = toFloat(rgb[1]) * 2.55;
|
296
|
+
blue = toFloat(rgb[2]) * 2.55;
|
297
|
+
return R.hsb2rgb(red, green, blue);
|
298
|
+
}
|
299
|
+
rgb = {r: red, g: green, b: blue};
|
300
|
+
var r = (~~red)[toString](16),
|
301
|
+
g = (~~green)[toString](16),
|
302
|
+
b = (~~blue)[toString](16);
|
303
|
+
r = r[rp](rg, "0");
|
304
|
+
g = g[rp](rg, "0");
|
305
|
+
b = b[rp](rg, "0");
|
306
|
+
rgb.hex = "#" + r + g + b;
|
307
|
+
isFinite(toFloat(opacity)) && (rgb.o = opacity);
|
308
|
+
return rgb;
|
309
|
+
}
|
310
|
+
return {r: -1, g: -1, b: -1, hex: "none", error: 1};
|
311
|
+
}, R);
|
312
|
+
R.getColor = function (value) {
|
313
|
+
var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
|
314
|
+
rgb = this.hsb2rgb(start.h, start.s, start.b);
|
315
|
+
start.h += .075;
|
316
|
+
if (start.h > 1) {
|
317
|
+
start.h = 0;
|
318
|
+
start.s -= .2;
|
319
|
+
start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
|
320
|
+
}
|
321
|
+
return rgb.hex;
|
322
|
+
};
|
323
|
+
R.getColor.reset = function () {
|
324
|
+
delete this.start;
|
325
|
+
};
|
326
|
+
// path utilities
|
327
|
+
var pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
|
328
|
+
pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig;
|
329
|
+
R.parsePathString = cacher(function (pathString) {
|
330
|
+
if (!pathString) {
|
331
|
+
return null;
|
332
|
+
}
|
333
|
+
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
|
334
|
+
data = [];
|
335
|
+
if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
|
336
|
+
data = pathClone(pathString);
|
337
|
+
}
|
338
|
+
if (!data[length]) {
|
339
|
+
(pathString + E)[rp](pathCommand, function (a, b, c) {
|
340
|
+
var params = [],
|
341
|
+
name = lowerCase.call(b);
|
342
|
+
c[rp](pathValues, function (a, b) {
|
343
|
+
b && params[push](+b);
|
344
|
+
});
|
345
|
+
if (name == "m" && params[length] > 2) {
|
346
|
+
data[push]([b][concat](params.splice(0, 2)));
|
347
|
+
name = "l";
|
348
|
+
b = b == "m" ? "l" : "L";
|
349
|
+
}
|
350
|
+
while (params[length] >= paramCounts[name]) {
|
351
|
+
data[push]([b][concat](params.splice(0, paramCounts[name])));
|
352
|
+
if (!paramCounts[name]) {
|
353
|
+
break;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
});
|
357
|
+
}
|
358
|
+
data[toString] = R._path2string;
|
359
|
+
return data;
|
360
|
+
});
|
361
|
+
R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
|
362
|
+
var t1 = 1 - t,
|
363
|
+
x = pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
|
364
|
+
y = pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y,
|
365
|
+
mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x),
|
366
|
+
my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y),
|
367
|
+
nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x),
|
368
|
+
ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y),
|
369
|
+
ax = (1 - t) * p1x + t * c1x,
|
370
|
+
ay = (1 - t) * p1y + t * c1y,
|
371
|
+
cx = (1 - t) * c2x + t * p2x,
|
372
|
+
cy = (1 - t) * c2y + t * p2y,
|
373
|
+
alpha = (90 - math.atan((mx - nx) / (my - ny)) * 180 / math.PI);
|
374
|
+
(mx > nx || my < ny) && (alpha += 180);
|
375
|
+
return {x: x, y: y, m: {x: mx, y: my}, n: {x: nx, y: ny}, start: {x: ax, y: ay}, end: {x: cx, y: cy}, alpha: alpha};
|
376
|
+
};
|
377
|
+
var pathDimensions = cacher(function (path) {
|
378
|
+
if (!path) {
|
379
|
+
return {x: 0, y: 0, width: 0, height: 0};
|
380
|
+
}
|
381
|
+
path = path2curve(path);
|
382
|
+
var x = 0,
|
383
|
+
y = 0,
|
384
|
+
X = [],
|
385
|
+
Y = [],
|
386
|
+
p;
|
387
|
+
for (var i = 0, ii = path[length]; i < ii; i++) {
|
388
|
+
p = path[i];
|
389
|
+
if (p[0] == "M") {
|
390
|
+
x = p[1];
|
391
|
+
y = p[2];
|
392
|
+
X[push](x);
|
393
|
+
Y[push](y);
|
394
|
+
} else {
|
395
|
+
var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
|
396
|
+
X = X[concat](dim.min.x, dim.max.x);
|
397
|
+
Y = Y[concat](dim.min.y, dim.max.y);
|
398
|
+
x = p[5];
|
399
|
+
y = p[6];
|
400
|
+
}
|
401
|
+
}
|
402
|
+
var xmin = mmin[apply](0, X),
|
403
|
+
ymin = mmin[apply](0, Y);
|
404
|
+
return {
|
405
|
+
x: xmin,
|
406
|
+
y: ymin,
|
407
|
+
width: mmax[apply](0, X) - xmin,
|
408
|
+
height: mmax[apply](0, Y) - ymin
|
409
|
+
};
|
410
|
+
}),
|
411
|
+
pathClone = function (pathArray) {
|
412
|
+
var res = [];
|
413
|
+
if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
|
414
|
+
pathArray = R.parsePathString(pathArray);
|
415
|
+
}
|
416
|
+
for (var i = 0, ii = pathArray[length]; i < ii; i++) {
|
417
|
+
res[i] = [];
|
418
|
+
for (var j = 0, jj = pathArray[i][length]; j < jj; j++) {
|
419
|
+
res[i][j] = pathArray[i][j];
|
420
|
+
}
|
421
|
+
}
|
422
|
+
res[toString] = R._path2string;
|
423
|
+
return res;
|
424
|
+
},
|
425
|
+
pathToRelative = cacher(function (pathArray) {
|
426
|
+
if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
|
427
|
+
pathArray = R.parsePathString(pathArray);
|
428
|
+
}
|
429
|
+
var res = [],
|
430
|
+
x = 0,
|
431
|
+
y = 0,
|
432
|
+
mx = 0,
|
433
|
+
my = 0,
|
434
|
+
start = 0;
|
435
|
+
if (pathArray[0][0] == "M") {
|
436
|
+
x = pathArray[0][1];
|
437
|
+
y = pathArray[0][2];
|
438
|
+
mx = x;
|
439
|
+
my = y;
|
440
|
+
start++;
|
441
|
+
res[push](["M", x, y]);
|
442
|
+
}
|
443
|
+
for (var i = start, ii = pathArray[length]; i < ii; i++) {
|
444
|
+
var r = res[i] = [],
|
445
|
+
pa = pathArray[i];
|
446
|
+
if (pa[0] != lowerCase.call(pa[0])) {
|
447
|
+
r[0] = lowerCase.call(pa[0]);
|
448
|
+
switch (r[0]) {
|
449
|
+
case "a":
|
450
|
+
r[1] = pa[1];
|
451
|
+
r[2] = pa[2];
|
452
|
+
r[3] = pa[3];
|
453
|
+
r[4] = pa[4];
|
454
|
+
r[5] = pa[5];
|
455
|
+
r[6] = +(pa[6] - x).toFixed(3);
|
456
|
+
r[7] = +(pa[7] - y).toFixed(3);
|
457
|
+
break;
|
458
|
+
case "v":
|
459
|
+
r[1] = +(pa[1] - y).toFixed(3);
|
460
|
+
break;
|
461
|
+
case "m":
|
462
|
+
mx = pa[1];
|
463
|
+
my = pa[2];
|
464
|
+
default:
|
465
|
+
for (var j = 1, jj = pa[length]; j < jj; j++) {
|
466
|
+
r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
|
467
|
+
}
|
468
|
+
}
|
469
|
+
} else {
|
470
|
+
r = res[i] = [];
|
471
|
+
if (pa[0] == "m") {
|
472
|
+
mx = pa[1] + x;
|
473
|
+
my = pa[2] + y;
|
474
|
+
}
|
475
|
+
for (var k = 0, kk = pa[length]; k < kk; k++) {
|
476
|
+
res[i][k] = pa[k];
|
477
|
+
}
|
478
|
+
}
|
479
|
+
var len = res[i][length];
|
480
|
+
switch (res[i][0]) {
|
481
|
+
case "z":
|
482
|
+
x = mx;
|
483
|
+
y = my;
|
484
|
+
break;
|
485
|
+
case "h":
|
486
|
+
x += +res[i][len - 1];
|
487
|
+
break;
|
488
|
+
case "v":
|
489
|
+
y += +res[i][len - 1];
|
490
|
+
break;
|
491
|
+
default:
|
492
|
+
x += +res[i][len - 2];
|
493
|
+
y += +res[i][len - 1];
|
494
|
+
}
|
495
|
+
}
|
496
|
+
res[toString] = R._path2string;
|
497
|
+
return res;
|
498
|
+
}, 0, pathClone),
|
499
|
+
pathToAbsolute = cacher(function (pathArray) {
|
500
|
+
if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
|
501
|
+
pathArray = R.parsePathString(pathArray);
|
502
|
+
}
|
503
|
+
var res = [],
|
504
|
+
x = 0,
|
505
|
+
y = 0,
|
506
|
+
mx = 0,
|
507
|
+
my = 0,
|
508
|
+
start = 0;
|
509
|
+
if (pathArray[0][0] == "M") {
|
510
|
+
x = +pathArray[0][1];
|
511
|
+
y = +pathArray[0][2];
|
512
|
+
mx = x;
|
513
|
+
my = y;
|
514
|
+
start++;
|
515
|
+
res[0] = ["M", x, y];
|
516
|
+
}
|
517
|
+
for (var i = start, ii = pathArray[length]; i < ii; i++) {
|
518
|
+
var r = res[i] = [],
|
519
|
+
pa = pathArray[i];
|
520
|
+
if (pa[0] != upperCase.call(pa[0])) {
|
521
|
+
r[0] = upperCase.call(pa[0]);
|
522
|
+
switch (r[0]) {
|
523
|
+
case "A":
|
524
|
+
r[1] = pa[1];
|
525
|
+
r[2] = pa[2];
|
526
|
+
r[3] = pa[3];
|
527
|
+
r[4] = pa[4];
|
528
|
+
r[5] = pa[5];
|
529
|
+
r[6] = +(pa[6] + x);
|
530
|
+
r[7] = +(pa[7] + y);
|
531
|
+
break;
|
532
|
+
case "V":
|
533
|
+
r[1] = +pa[1] + y;
|
534
|
+
break;
|
535
|
+
case "H":
|
536
|
+
r[1] = +pa[1] + x;
|
537
|
+
break;
|
538
|
+
case "M":
|
539
|
+
mx = +pa[1] + x;
|
540
|
+
my = +pa[2] + y;
|
541
|
+
default:
|
542
|
+
for (var j = 1, jj = pa[length]; j < jj; j++) {
|
543
|
+
r[j] = +pa[j] + ((j % 2) ? x : y);
|
544
|
+
}
|
545
|
+
}
|
546
|
+
} else {
|
547
|
+
for (var k = 0, kk = pa[length]; k < kk; k++) {
|
548
|
+
res[i][k] = pa[k];
|
549
|
+
}
|
550
|
+
}
|
551
|
+
switch (r[0]) {
|
552
|
+
case "Z":
|
553
|
+
x = mx;
|
554
|
+
y = my;
|
555
|
+
break;
|
556
|
+
case "H":
|
557
|
+
x = r[1];
|
558
|
+
break;
|
559
|
+
case "V":
|
560
|
+
y = r[1];
|
561
|
+
break;
|
562
|
+
default:
|
563
|
+
x = res[i][res[i][length] - 2];
|
564
|
+
y = res[i][res[i][length] - 1];
|
565
|
+
}
|
566
|
+
}
|
567
|
+
res[toString] = R._path2string;
|
568
|
+
return res;
|
569
|
+
}, null, pathClone),
|
570
|
+
l2c = function (x1, y1, x2, y2) {
|
571
|
+
return [x1, y1, x2, y2, x2, y2];
|
572
|
+
},
|
573
|
+
q2c = function (x1, y1, ax, ay, x2, y2) {
|
574
|
+
var _13 = 1 / 3,
|
575
|
+
_23 = 2 / 3;
|
576
|
+
return [
|
577
|
+
_13 * x1 + _23 * ax,
|
578
|
+
_13 * y1 + _23 * ay,
|
579
|
+
_13 * x2 + _23 * ax,
|
580
|
+
_13 * y2 + _23 * ay,
|
581
|
+
x2,
|
582
|
+
y2
|
583
|
+
];
|
584
|
+
},
|
585
|
+
a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
|
586
|
+
// for more information of where this math came from visit:
|
587
|
+
// http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
|
588
|
+
var PI = math.PI,
|
589
|
+
_120 = PI * 120 / 180,
|
590
|
+
rad = PI / 180 * (+angle || 0),
|
591
|
+
res = [],
|
592
|
+
xy,
|
593
|
+
rotate = cacher(function (x, y, rad) {
|
594
|
+
var X = x * math.cos(rad) - y * math.sin(rad),
|
595
|
+
Y = x * math.sin(rad) + y * math.cos(rad);
|
596
|
+
return {x: X, y: Y};
|
597
|
+
});
|
598
|
+
if (!recursive) {
|
599
|
+
xy = rotate(x1, y1, -rad);
|
600
|
+
x1 = xy.x;
|
601
|
+
y1 = xy.y;
|
602
|
+
xy = rotate(x2, y2, -rad);
|
603
|
+
x2 = xy.x;
|
604
|
+
y2 = xy.y;
|
605
|
+
var cos = math.cos(PI / 180 * angle),
|
606
|
+
sin = math.sin(PI / 180 * angle),
|
607
|
+
x = (x1 - x2) / 2,
|
608
|
+
y = (y1 - y2) / 2;
|
609
|
+
var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
|
610
|
+
if (h > 1) {
|
611
|
+
h = math.sqrt(h);
|
612
|
+
rx = h * rx;
|
613
|
+
ry = h * ry;
|
614
|
+
}
|
615
|
+
var rx2 = rx * rx,
|
616
|
+
ry2 = ry * ry,
|
617
|
+
k = (large_arc_flag == sweep_flag ? -1 : 1) *
|
618
|
+
math.sqrt(math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
|
619
|
+
cx = k * rx * y / ry + (x1 + x2) / 2,
|
620
|
+
cy = k * -ry * x / rx + (y1 + y2) / 2,
|
621
|
+
f1 = math.asin(((y1 - cy) / ry).toFixed(7)),
|
622
|
+
f2 = math.asin(((y2 - cy) / ry).toFixed(7));
|
623
|
+
|
624
|
+
f1 = x1 < cx ? PI - f1 : f1;
|
625
|
+
f2 = x2 < cx ? PI - f2 : f2;
|
626
|
+
f1 < 0 && (f1 = PI * 2 + f1);
|
627
|
+
f2 < 0 && (f2 = PI * 2 + f2);
|
628
|
+
if (sweep_flag && f1 > f2) {
|
629
|
+
f1 = f1 - PI * 2;
|
630
|
+
}
|
631
|
+
if (!sweep_flag && f2 > f1) {
|
632
|
+
f2 = f2 - PI * 2;
|
633
|
+
}
|
634
|
+
} else {
|
635
|
+
f1 = recursive[0];
|
636
|
+
f2 = recursive[1];
|
637
|
+
cx = recursive[2];
|
638
|
+
cy = recursive[3];
|
639
|
+
}
|
640
|
+
var df = f2 - f1;
|
641
|
+
if (math.abs(df) > _120) {
|
642
|
+
var f2old = f2,
|
643
|
+
x2old = x2,
|
644
|
+
y2old = y2;
|
645
|
+
f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
|
646
|
+
x2 = cx + rx * math.cos(f2);
|
647
|
+
y2 = cy + ry * math.sin(f2);
|
648
|
+
res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
|
649
|
+
}
|
650
|
+
df = f2 - f1;
|
651
|
+
var c1 = math.cos(f1),
|
652
|
+
s1 = math.sin(f1),
|
653
|
+
c2 = math.cos(f2),
|
654
|
+
s2 = math.sin(f2),
|
655
|
+
t = math.tan(df / 4),
|
656
|
+
hx = 4 / 3 * rx * t,
|
657
|
+
hy = 4 / 3 * ry * t,
|
658
|
+
m1 = [x1, y1],
|
659
|
+
m2 = [x1 + hx * s1, y1 - hy * c1],
|
660
|
+
m3 = [x2 + hx * s2, y2 - hy * c2],
|
661
|
+
m4 = [x2, y2];
|
662
|
+
m2[0] = 2 * m1[0] - m2[0];
|
663
|
+
m2[1] = 2 * m1[1] - m2[1];
|
664
|
+
if (recursive) {
|
665
|
+
return [m2, m3, m4][concat](res);
|
666
|
+
} else {
|
667
|
+
res = [m2, m3, m4][concat](res)[join]()[split](",");
|
668
|
+
var newres = [];
|
669
|
+
for (var i = 0, ii = res[length]; i < ii; i++) {
|
670
|
+
newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
|
671
|
+
}
|
672
|
+
return newres;
|
673
|
+
}
|
674
|
+
},
|
675
|
+
findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
|
676
|
+
var t1 = 1 - t;
|
677
|
+
return {
|
678
|
+
x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
|
679
|
+
y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
|
680
|
+
};
|
681
|
+
},
|
682
|
+
curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
|
683
|
+
var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
|
684
|
+
b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
|
685
|
+
c = p1x - c1x,
|
686
|
+
t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
|
687
|
+
t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
|
688
|
+
y = [p1y, p2y],
|
689
|
+
x = [p1x, p2x],
|
690
|
+
dot;
|
691
|
+
math.abs(t1) > 1e12 && (t1 = .5);
|
692
|
+
math.abs(t2) > 1e12 && (t2 = .5);
|
693
|
+
if (t1 > 0 && t1 < 1) {
|
694
|
+
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
|
695
|
+
x[push](dot.x);
|
696
|
+
y[push](dot.y);
|
697
|
+
}
|
698
|
+
if (t2 > 0 && t2 < 1) {
|
699
|
+
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
|
700
|
+
x[push](dot.x);
|
701
|
+
y[push](dot.y);
|
702
|
+
}
|
703
|
+
a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
|
704
|
+
b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
|
705
|
+
c = p1y - c1y;
|
706
|
+
t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
|
707
|
+
t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
|
708
|
+
math.abs(t1) > 1e12 && (t1 = .5);
|
709
|
+
math.abs(t2) > 1e12 && (t2 = .5);
|
710
|
+
if (t1 > 0 && t1 < 1) {
|
711
|
+
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
|
712
|
+
x[push](dot.x);
|
713
|
+
y[push](dot.y);
|
714
|
+
}
|
715
|
+
if (t2 > 0 && t2 < 1) {
|
716
|
+
dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
|
717
|
+
x[push](dot.x);
|
718
|
+
y[push](dot.y);
|
719
|
+
}
|
720
|
+
return {
|
721
|
+
min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
|
722
|
+
max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
|
723
|
+
};
|
724
|
+
}),
|
725
|
+
path2curve = cacher(function (path, path2) {
|
726
|
+
var p = pathToAbsolute(path),
|
727
|
+
p2 = path2 && pathToAbsolute(path2),
|
728
|
+
attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
|
729
|
+
attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
|
730
|
+
processPath = function (path, d) {
|
731
|
+
var nx, ny;
|
732
|
+
if (!path) {
|
733
|
+
return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
|
734
|
+
}
|
735
|
+
!(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
|
736
|
+
switch (path[0]) {
|
737
|
+
case "M":
|
738
|
+
d.X = path[1];
|
739
|
+
d.Y = path[2];
|
740
|
+
break;
|
741
|
+
case "A":
|
742
|
+
path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
|
743
|
+
break;
|
744
|
+
case "S":
|
745
|
+
nx = d.x + (d.x - (d.bx || d.x));
|
746
|
+
ny = d.y + (d.y - (d.by || d.y));
|
747
|
+
path = ["C", nx, ny][concat](path.slice(1));
|
748
|
+
break;
|
749
|
+
case "T":
|
750
|
+
d.qx = d.x + (d.x - (d.qx || d.x));
|
751
|
+
d.qy = d.y + (d.y - (d.qy || d.y));
|
752
|
+
path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
|
753
|
+
break;
|
754
|
+
case "Q":
|
755
|
+
d.qx = path[1];
|
756
|
+
d.qy = path[2];
|
757
|
+
path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
|
758
|
+
break;
|
759
|
+
case "L":
|
760
|
+
path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
|
761
|
+
break;
|
762
|
+
case "H":
|
763
|
+
path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
|
764
|
+
break;
|
765
|
+
case "V":
|
766
|
+
path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
|
767
|
+
break;
|
768
|
+
case "Z":
|
769
|
+
path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
|
770
|
+
break;
|
771
|
+
}
|
772
|
+
return path;
|
773
|
+
},
|
774
|
+
fixArc = function (pp, i) {
|
775
|
+
if (pp[i][length] > 7) {
|
776
|
+
pp[i].shift();
|
777
|
+
var pi = pp[i];
|
778
|
+
while (pi[length]) {
|
779
|
+
pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
|
780
|
+
}
|
781
|
+
pp.splice(i, 1);
|
782
|
+
ii = mmax(p[length], p2 && p2[length] || 0);
|
783
|
+
}
|
784
|
+
},
|
785
|
+
fixM = function (path1, path2, a1, a2, i) {
|
786
|
+
if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
|
787
|
+
path2.splice(i, 0, ["M", a2.x, a2.y]);
|
788
|
+
a1.bx = 0;
|
789
|
+
a1.by = 0;
|
790
|
+
a1.x = path1[i][1];
|
791
|
+
a1.y = path1[i][2];
|
792
|
+
ii = mmax(p[length], p2 && p2[length] || 0);
|
793
|
+
}
|
794
|
+
};
|
795
|
+
for (var i = 0, ii = mmax(p[length], p2 && p2[length] || 0); i < ii; i++) {
|
796
|
+
p[i] = processPath(p[i], attrs);
|
797
|
+
fixArc(p, i);
|
798
|
+
p2 && (p2[i] = processPath(p2[i], attrs2));
|
799
|
+
p2 && fixArc(p2, i);
|
800
|
+
fixM(p, p2, attrs, attrs2, i);
|
801
|
+
fixM(p2, p, attrs2, attrs, i);
|
802
|
+
var seg = p[i],
|
803
|
+
seg2 = p2 && p2[i],
|
804
|
+
seglen = seg[length],
|
805
|
+
seg2len = p2 && seg2[length];
|
806
|
+
attrs.x = seg[seglen - 2];
|
807
|
+
attrs.y = seg[seglen - 1];
|
808
|
+
attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
|
809
|
+
attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
|
810
|
+
attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
|
811
|
+
attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
|
812
|
+
attrs2.x = p2 && seg2[seg2len - 2];
|
813
|
+
attrs2.y = p2 && seg2[seg2len - 1];
|
814
|
+
}
|
815
|
+
return p2 ? [p, p2] : p;
|
816
|
+
}, null, pathClone),
|
817
|
+
parseDots = cacher(function (gradient) {
|
818
|
+
var dots = [];
|
819
|
+
for (var i = 0, ii = gradient[length]; i < ii; i++) {
|
820
|
+
var dot = {},
|
821
|
+
par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
|
822
|
+
dot.color = R.getRGB(par[1]);
|
823
|
+
if (dot.color.error) {
|
824
|
+
return null;
|
825
|
+
}
|
826
|
+
dot.color = dot.color.hex;
|
827
|
+
par[2] && (dot.offset = par[2] + "%");
|
828
|
+
dots[push](dot);
|
829
|
+
}
|
830
|
+
for (i = 1, ii = dots[length] - 1; i < ii; i++) {
|
831
|
+
if (!dots[i].offset) {
|
832
|
+
var start = toFloat(dots[i - 1].offset || 0),
|
833
|
+
end = 0;
|
834
|
+
for (var j = i + 1; j < ii; j++) {
|
835
|
+
if (dots[j].offset) {
|
836
|
+
end = dots[j].offset;
|
837
|
+
break;
|
838
|
+
}
|
839
|
+
}
|
840
|
+
if (!end) {
|
841
|
+
end = 100;
|
842
|
+
j = ii;
|
843
|
+
}
|
844
|
+
end = toFloat(end);
|
845
|
+
var d = (end - start) / (j - i + 1);
|
846
|
+
for (; i < j; i++) {
|
847
|
+
start += d;
|
848
|
+
dots[i].offset = start + "%";
|
849
|
+
}
|
850
|
+
}
|
851
|
+
}
|
852
|
+
return dots;
|
853
|
+
}),
|
854
|
+
getContainer = function (x, y, w, h) {
|
855
|
+
var container;
|
856
|
+
if (R.is(x, string) || R.is(x, "object")) {
|
857
|
+
container = R.is(x, string) ? doc.getElementById(x) : x;
|
858
|
+
if (container.tagName) {
|
859
|
+
if (y == null) {
|
860
|
+
return {
|
861
|
+
container: container,
|
862
|
+
width: container.style.pixelWidth || container.offsetWidth,
|
863
|
+
height: container.style.pixelHeight || container.offsetHeight
|
864
|
+
};
|
865
|
+
} else {
|
866
|
+
return {container: container, width: y, height: w};
|
867
|
+
}
|
868
|
+
}
|
869
|
+
} else {
|
870
|
+
return {container: 1, x: x, y: y, width: w, height: h};
|
871
|
+
}
|
872
|
+
},
|
873
|
+
plugins = function (con, add) {
|
874
|
+
var that = this;
|
875
|
+
for (var prop in add) {
|
876
|
+
if (add[has](prop) && !(prop in con)) {
|
877
|
+
switch (typeof add[prop]) {
|
878
|
+
case "function":
|
879
|
+
(function (f) {
|
880
|
+
con[prop] = con === that ? f : function () { return f[apply](that, arguments); };
|
881
|
+
})(add[prop]);
|
882
|
+
break;
|
883
|
+
case "object":
|
884
|
+
con[prop] = con[prop] || {};
|
885
|
+
plugins.call(this, con[prop], add[prop]);
|
886
|
+
break;
|
887
|
+
default:
|
888
|
+
con[prop] = add[prop];
|
889
|
+
break;
|
890
|
+
}
|
891
|
+
}
|
892
|
+
}
|
893
|
+
},
|
894
|
+
tear = function (el, paper) {
|
895
|
+
el == paper.top && (paper.top = el.prev);
|
896
|
+
el == paper.bottom && (paper.bottom = el.next);
|
897
|
+
el.next && (el.next.prev = el.prev);
|
898
|
+
el.prev && (el.prev.next = el.next);
|
899
|
+
},
|
900
|
+
tofront = function (el, paper) {
|
901
|
+
if (paper.top === el) {
|
902
|
+
return;
|
903
|
+
}
|
904
|
+
tear(el, paper);
|
905
|
+
el.next = null;
|
906
|
+
el.prev = paper.top;
|
907
|
+
paper.top.next = el;
|
908
|
+
paper.top = el;
|
909
|
+
},
|
910
|
+
toback = function (el, paper) {
|
911
|
+
if (paper.bottom === el) {
|
912
|
+
return;
|
913
|
+
}
|
914
|
+
tear(el, paper);
|
915
|
+
el.next = paper.bottom;
|
916
|
+
el.prev = null;
|
917
|
+
paper.bottom.prev = el;
|
918
|
+
paper.bottom = el;
|
919
|
+
},
|
920
|
+
insertafter = function (el, el2, paper) {
|
921
|
+
tear(el, paper);
|
922
|
+
el2 == paper.top && (paper.top = el);
|
923
|
+
el2.next && (el2.next.prev = el);
|
924
|
+
el.next = el2.next;
|
925
|
+
el.prev = el2;
|
926
|
+
el2.next = el;
|
927
|
+
},
|
928
|
+
insertbefore = function (el, el2, paper) {
|
929
|
+
tear(el, paper);
|
930
|
+
el2 == paper.bottom && (paper.bottom = el);
|
931
|
+
el2.prev && (el2.prev.next = el);
|
932
|
+
el.prev = el2.prev;
|
933
|
+
el2.prev = el;
|
934
|
+
el.next = el2;
|
935
|
+
},
|
936
|
+
removed = function (methodname) {
|
937
|
+
return function () {
|
938
|
+
throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
|
939
|
+
};
|
940
|
+
},
|
941
|
+
radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/;
|
942
|
+
|
943
|
+
// SVG
|
944
|
+
if (R.svg) {
|
945
|
+
Paper[proto].svgns = "http://www.w3.org/2000/svg";
|
946
|
+
Paper[proto].xlink = "http://www.w3.org/1999/xlink";
|
947
|
+
round = function (num) {
|
948
|
+
return +num + (~~num === num) * .5;
|
949
|
+
};
|
950
|
+
var $ = function (el, attr) {
|
951
|
+
if (attr) {
|
952
|
+
for (var key in attr) {
|
953
|
+
if (attr[has](key)) {
|
954
|
+
el[setAttribute](key, attr[key] + E);
|
955
|
+
}
|
956
|
+
}
|
957
|
+
} else {
|
958
|
+
el = doc.createElementNS(Paper[proto].svgns, el);
|
959
|
+
el.style.webkitTapHighlightColor = "rgba(0,0,0,0)";
|
960
|
+
return el;
|
961
|
+
}
|
962
|
+
};
|
963
|
+
R[toString] = function () {
|
964
|
+
return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
|
965
|
+
};
|
966
|
+
var thePath = function (pathString, SVG) {
|
967
|
+
var el = $("path");
|
968
|
+
SVG.canvas && SVG.canvas[appendChild](el);
|
969
|
+
var p = new Element(el, SVG);
|
970
|
+
p.type = "path";
|
971
|
+
setFillAndStroke(p, {fill: "none", stroke: "#000", path: pathString});
|
972
|
+
return p;
|
973
|
+
};
|
974
|
+
var addGradientFill = function (o, gradient, SVG) {
|
975
|
+
var type = "linear",
|
976
|
+
fx = .5, fy = .5,
|
977
|
+
s = o.style;
|
978
|
+
gradient = (gradient + E)[rp](radial_gradient, function (all, _fx, _fy) {
|
979
|
+
type = "radial";
|
980
|
+
if (_fx && _fy) {
|
981
|
+
fx = toFloat(_fx);
|
982
|
+
fy = toFloat(_fy);
|
983
|
+
var dir = ((fy > .5) * 2 - 1);
|
984
|
+
pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
|
985
|
+
(fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
|
986
|
+
fy != .5 &&
|
987
|
+
(fy = fy.toFixed(5) - 1e-5 * dir);
|
988
|
+
}
|
989
|
+
return E;
|
990
|
+
});
|
991
|
+
gradient = gradient[split](/\s*\-\s*/);
|
992
|
+
if (type == "linear") {
|
993
|
+
var angle = gradient.shift();
|
994
|
+
angle = -toFloat(angle);
|
995
|
+
if (isNaN(angle)) {
|
996
|
+
return null;
|
997
|
+
}
|
998
|
+
var vector = [0, 0, math.cos(angle * math.PI / 180), math.sin(angle * math.PI / 180)],
|
999
|
+
max = 1 / (mmax(math.abs(vector[2]), math.abs(vector[3])) || 1);
|
1000
|
+
vector[2] *= max;
|
1001
|
+
vector[3] *= max;
|
1002
|
+
if (vector[2] < 0) {
|
1003
|
+
vector[0] = -vector[2];
|
1004
|
+
vector[2] = 0;
|
1005
|
+
}
|
1006
|
+
if (vector[3] < 0) {
|
1007
|
+
vector[1] = -vector[3];
|
1008
|
+
vector[3] = 0;
|
1009
|
+
}
|
1010
|
+
}
|
1011
|
+
var dots = parseDots(gradient);
|
1012
|
+
if (!dots) {
|
1013
|
+
return null;
|
1014
|
+
}
|
1015
|
+
var id = o.getAttribute(fillString);
|
1016
|
+
id = id.match(/^url\(#(.*)\)$/);
|
1017
|
+
id && SVG.defs.removeChild(doc.getElementById(id[1]));
|
1018
|
+
|
1019
|
+
var el = $(type + "Gradient");
|
1020
|
+
el.id = "r" + (R._id++)[toString](36);
|
1021
|
+
$(el, type == "radial" ? {fx: fx, fy: fy} : {x1: vector[0], y1: vector[1], x2: vector[2], y2: vector[3]});
|
1022
|
+
SVG.defs[appendChild](el);
|
1023
|
+
for (var i = 0, ii = dots[length]; i < ii; i++) {
|
1024
|
+
var stop = $("stop");
|
1025
|
+
$(stop, {
|
1026
|
+
offset: dots[i].offset ? dots[i].offset : !i ? "0%" : "100%",
|
1027
|
+
"stop-color": dots[i].color || "#fff"
|
1028
|
+
});
|
1029
|
+
el[appendChild](stop);
|
1030
|
+
}
|
1031
|
+
$(o, {
|
1032
|
+
fill: "url(#" + el.id + ")",
|
1033
|
+
opacity: 1,
|
1034
|
+
"fill-opacity": 1
|
1035
|
+
});
|
1036
|
+
s.fill = E;
|
1037
|
+
s.opacity = 1;
|
1038
|
+
s.fillOpacity = 1;
|
1039
|
+
return 1;
|
1040
|
+
};
|
1041
|
+
var updatePosition = function (o) {
|
1042
|
+
var bbox = o.getBBox();
|
1043
|
+
$(o.pattern, {patternTransform: R.format("translate({0},{1})", bbox.x, bbox.y)});
|
1044
|
+
};
|
1045
|
+
var setFillAndStroke = function (o, params) {
|
1046
|
+
var dasharray = {
|
1047
|
+
"": [0],
|
1048
|
+
"none": [0],
|
1049
|
+
"-": [3, 1],
|
1050
|
+
".": [1, 1],
|
1051
|
+
"-.": [3, 1, 1, 1],
|
1052
|
+
"-..": [3, 1, 1, 1, 1, 1],
|
1053
|
+
". ": [1, 3],
|
1054
|
+
"- ": [4, 3],
|
1055
|
+
"--": [8, 3],
|
1056
|
+
"- .": [4, 3, 1, 3],
|
1057
|
+
"--.": [8, 3, 1, 3],
|
1058
|
+
"--..": [8, 3, 1, 3, 1, 3]
|
1059
|
+
},
|
1060
|
+
node = o.node,
|
1061
|
+
attrs = o.attrs,
|
1062
|
+
rot = o.rotate(),
|
1063
|
+
addDashes = function (o, value) {
|
1064
|
+
value = dasharray[lowerCase.call(value)];
|
1065
|
+
if (value) {
|
1066
|
+
var width = o.attrs["stroke-width"] || "1",
|
1067
|
+
butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
|
1068
|
+
dashes = [];
|
1069
|
+
var i = value[length];
|
1070
|
+
while (i--) {
|
1071
|
+
dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
|
1072
|
+
}
|
1073
|
+
$(node, {"stroke-dasharray": dashes[join](",")});
|
1074
|
+
}
|
1075
|
+
};
|
1076
|
+
params[has]("rotation") && (rot = params.rotation);
|
1077
|
+
var rotxy = (rot + E)[split](separator);
|
1078
|
+
if (!(rotxy.length - 1)) {
|
1079
|
+
rotxy = null;
|
1080
|
+
} else {
|
1081
|
+
rotxy[1] = +rotxy[1];
|
1082
|
+
rotxy[2] = +rotxy[2];
|
1083
|
+
}
|
1084
|
+
toFloat(rot) && o.rotate(0, true);
|
1085
|
+
for (var att in params) {
|
1086
|
+
if (params[has](att)) {
|
1087
|
+
if (!availableAttrs[has](att)) {
|
1088
|
+
continue;
|
1089
|
+
}
|
1090
|
+
var value = params[att];
|
1091
|
+
attrs[att] = value;
|
1092
|
+
switch (att) {
|
1093
|
+
case "blur":
|
1094
|
+
o.blur(value);
|
1095
|
+
break;
|
1096
|
+
case "rotation":
|
1097
|
+
o.rotate(value, true);
|
1098
|
+
break;
|
1099
|
+
case "href":
|
1100
|
+
case "title":
|
1101
|
+
case "target":
|
1102
|
+
var pn = node.parentNode;
|
1103
|
+
if (lowerCase.call(pn.tagName) != "a") {
|
1104
|
+
var hl = $("a");
|
1105
|
+
pn.insertBefore(hl, node);
|
1106
|
+
hl[appendChild](node);
|
1107
|
+
pn = hl;
|
1108
|
+
}
|
1109
|
+
pn.setAttributeNS(o.paper.xlink, att, value);
|
1110
|
+
break;
|
1111
|
+
case "cursor":
|
1112
|
+
node.style.cursor = value;
|
1113
|
+
break;
|
1114
|
+
case "clip-rect":
|
1115
|
+
var rect = (value + E)[split](separator);
|
1116
|
+
if (rect[length] == 4) {
|
1117
|
+
o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
|
1118
|
+
var el = $("clipPath"),
|
1119
|
+
rc = $("rect");
|
1120
|
+
el.id = "r" + (R._id++)[toString](36);
|
1121
|
+
$(rc, {
|
1122
|
+
x: rect[0],
|
1123
|
+
y: rect[1],
|
1124
|
+
width: rect[2],
|
1125
|
+
height: rect[3]
|
1126
|
+
});
|
1127
|
+
el[appendChild](rc);
|
1128
|
+
o.paper.defs[appendChild](el);
|
1129
|
+
$(node, {"clip-path": "url(#" + el.id + ")"});
|
1130
|
+
o.clip = rc;
|
1131
|
+
}
|
1132
|
+
if (!value) {
|
1133
|
+
var clip = doc.getElementById(node.getAttribute("clip-path")[rp](/(^url\(#|\)$)/g, E));
|
1134
|
+
clip && clip.parentNode.removeChild(clip);
|
1135
|
+
$(node, {"clip-path": E});
|
1136
|
+
delete o.clip;
|
1137
|
+
}
|
1138
|
+
break;
|
1139
|
+
case "path":
|
1140
|
+
if (o.type == "path") {
|
1141
|
+
$(node, {d: value ? attrs.path = pathToAbsolute(value) : "M0,0"});
|
1142
|
+
}
|
1143
|
+
break;
|
1144
|
+
case "width":
|
1145
|
+
node[setAttribute](att, value);
|
1146
|
+
if (attrs.fx) {
|
1147
|
+
att = "x";
|
1148
|
+
value = attrs.x;
|
1149
|
+
} else {
|
1150
|
+
break;
|
1151
|
+
}
|
1152
|
+
case "x":
|
1153
|
+
if (attrs.fx) {
|
1154
|
+
value = -attrs.x - (attrs.width || 0);
|
1155
|
+
}
|
1156
|
+
case "rx":
|
1157
|
+
if (att == "rx" && o.type == "rect") {
|
1158
|
+
break;
|
1159
|
+
}
|
1160
|
+
case "cx":
|
1161
|
+
rotxy && (att == "x" || att == "cx") && (rotxy[1] += value - attrs[att]);
|
1162
|
+
node[setAttribute](att, round(value));
|
1163
|
+
o.pattern && updatePosition(o);
|
1164
|
+
break;
|
1165
|
+
case "height":
|
1166
|
+
node[setAttribute](att, value);
|
1167
|
+
if (attrs.fy) {
|
1168
|
+
att = "y";
|
1169
|
+
value = attrs.y;
|
1170
|
+
} else {
|
1171
|
+
break;
|
1172
|
+
}
|
1173
|
+
case "y":
|
1174
|
+
if (attrs.fy) {
|
1175
|
+
value = -attrs.y - (attrs.height || 0);
|
1176
|
+
}
|
1177
|
+
case "ry":
|
1178
|
+
if (att == "ry" && o.type == "rect") {
|
1179
|
+
break;
|
1180
|
+
}
|
1181
|
+
case "cy":
|
1182
|
+
rotxy && (att == "y" || att == "cy") && (rotxy[2] += value - attrs[att]);
|
1183
|
+
node[setAttribute](att, round(value));
|
1184
|
+
o.pattern && updatePosition(o);
|
1185
|
+
break;
|
1186
|
+
case "r":
|
1187
|
+
if (o.type == "rect") {
|
1188
|
+
$(node, {rx: value, ry: value});
|
1189
|
+
} else {
|
1190
|
+
node[setAttribute](att, value);
|
1191
|
+
}
|
1192
|
+
break;
|
1193
|
+
case "src":
|
1194
|
+
if (o.type == "image") {
|
1195
|
+
node.setAttributeNS(o.paper.xlink, "href", value);
|
1196
|
+
}
|
1197
|
+
break;
|
1198
|
+
case "stroke-width":
|
1199
|
+
node.style.strokeWidth = value;
|
1200
|
+
// Need following line for Firefox
|
1201
|
+
node[setAttribute](att, value);
|
1202
|
+
if (attrs["stroke-dasharray"]) {
|
1203
|
+
addDashes(o, attrs["stroke-dasharray"]);
|
1204
|
+
}
|
1205
|
+
break;
|
1206
|
+
case "stroke-dasharray":
|
1207
|
+
addDashes(o, value);
|
1208
|
+
break;
|
1209
|
+
case "translation":
|
1210
|
+
var xy = (value + E)[split](separator);
|
1211
|
+
xy[0] = +xy[0] || 0;
|
1212
|
+
xy[1] = +xy[1] || 0;
|
1213
|
+
if (rotxy) {
|
1214
|
+
rotxy[1] += xy[0];
|
1215
|
+
rotxy[2] += xy[1];
|
1216
|
+
}
|
1217
|
+
translate.call(o, xy[0], xy[1]);
|
1218
|
+
break;
|
1219
|
+
case "scale":
|
1220
|
+
xy = (value + E)[split](separator);
|
1221
|
+
o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, isNaN(toFloat(xy[2])) ? null : +xy[2], isNaN(toFloat(xy[3])) ? null : +xy[3]);
|
1222
|
+
break;
|
1223
|
+
case fillString:
|
1224
|
+
var isURL = (value + E).match(ISURL);
|
1225
|
+
if (isURL) {
|
1226
|
+
el = $("pattern");
|
1227
|
+
var ig = $("image");
|
1228
|
+
el.id = "r" + (R._id++)[toString](36);
|
1229
|
+
$(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
|
1230
|
+
$(ig, {x: 0, y: 0});
|
1231
|
+
ig.setAttributeNS(o.paper.xlink, "href", isURL[1]);
|
1232
|
+
el[appendChild](ig);
|
1233
|
+
|
1234
|
+
var img = doc.createElement("img");
|
1235
|
+
img.style.cssText = "position:absolute;left:-9999em;top-9999em";
|
1236
|
+
img.onload = function () {
|
1237
|
+
$(el, {width: this.offsetWidth, height: this.offsetHeight});
|
1238
|
+
$(ig, {width: this.offsetWidth, height: this.offsetHeight});
|
1239
|
+
doc.body.removeChild(this);
|
1240
|
+
o.paper.safari();
|
1241
|
+
};
|
1242
|
+
doc.body[appendChild](img);
|
1243
|
+
img.src = isURL[1];
|
1244
|
+
o.paper.defs[appendChild](el);
|
1245
|
+
node.style.fill = "url(#" + el.id + ")";
|
1246
|
+
$(node, {fill: "url(#" + el.id + ")"});
|
1247
|
+
o.pattern = el;
|
1248
|
+
o.pattern && updatePosition(o);
|
1249
|
+
break;
|
1250
|
+
}
|
1251
|
+
var clr = R.getRGB(value);
|
1252
|
+
if (!clr.error) {
|
1253
|
+
delete params.gradient;
|
1254
|
+
delete attrs.gradient;
|
1255
|
+
!R.is(attrs.opacity, "undefined") &&
|
1256
|
+
R.is(params.opacity, "undefined") &&
|
1257
|
+
$(node, {opacity: attrs.opacity});
|
1258
|
+
!R.is(attrs["fill-opacity"], "undefined") &&
|
1259
|
+
R.is(params["fill-opacity"], "undefined") &&
|
1260
|
+
$(node, {"fill-opacity": attrs["fill-opacity"]});
|
1261
|
+
} else if ((({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper)) {
|
1262
|
+
attrs.gradient = value;
|
1263
|
+
attrs.fill = "none";
|
1264
|
+
break;
|
1265
|
+
}
|
1266
|
+
clr[has]("o") && $(node, {"fill-opacity": clr.o / 100});
|
1267
|
+
case "stroke":
|
1268
|
+
clr = R.getRGB(value);
|
1269
|
+
node[setAttribute](att, clr.hex);
|
1270
|
+
att == "stroke" && clr[has]("o") && $(node, {"stroke-opacity": clr.o / 100});
|
1271
|
+
break;
|
1272
|
+
case "gradient":
|
1273
|
+
(({circle: 1, ellipse: 1})[has](o.type) || (value + E).charAt() != "r") && addGradientFill(node, value, o.paper);
|
1274
|
+
break;
|
1275
|
+
case "opacity":
|
1276
|
+
case "fill-opacity":
|
1277
|
+
if (attrs.gradient) {
|
1278
|
+
var gradient = doc.getElementById(node.getAttribute(fillString)[rp](/^url\(#|\)$/g, E));
|
1279
|
+
if (gradient) {
|
1280
|
+
var stops = gradient.getElementsByTagName("stop");
|
1281
|
+
stops[stops[length] - 1][setAttribute]("stop-opacity", value);
|
1282
|
+
}
|
1283
|
+
break;
|
1284
|
+
}
|
1285
|
+
default:
|
1286
|
+
att == "font-size" && (value = toInt(value, 10) + "px");
|
1287
|
+
var cssrule = att[rp](/(\-.)/g, function (w) {
|
1288
|
+
return upperCase.call(w.substring(1));
|
1289
|
+
});
|
1290
|
+
node.style[cssrule] = value;
|
1291
|
+
// Need following line for Firefox
|
1292
|
+
node[setAttribute](att, value);
|
1293
|
+
break;
|
1294
|
+
}
|
1295
|
+
}
|
1296
|
+
}
|
1297
|
+
|
1298
|
+
tuneText(o, params);
|
1299
|
+
if (rotxy) {
|
1300
|
+
o.rotate(rotxy.join(S));
|
1301
|
+
} else {
|
1302
|
+
toFloat(rot) && o.rotate(rot, true);
|
1303
|
+
}
|
1304
|
+
};
|
1305
|
+
var leading = 1.2,
|
1306
|
+
tuneText = function (el, params) {
|
1307
|
+
if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
|
1308
|
+
return;
|
1309
|
+
}
|
1310
|
+
var a = el.attrs,
|
1311
|
+
node = el.node,
|
1312
|
+
fontSize = node.firstChild ? toInt(doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
|
1313
|
+
|
1314
|
+
if (params[has]("text")) {
|
1315
|
+
a.text = params.text;
|
1316
|
+
while (node.firstChild) {
|
1317
|
+
node.removeChild(node.firstChild);
|
1318
|
+
}
|
1319
|
+
var texts = (params.text + E)[split]("\n");
|
1320
|
+
for (var i = 0, ii = texts[length]; i < ii; i++) if (texts[i]) {
|
1321
|
+
var tspan = $("tspan");
|
1322
|
+
i && $(tspan, {dy: fontSize * leading, x: a.x});
|
1323
|
+
tspan[appendChild](doc.createTextNode(texts[i]));
|
1324
|
+
node[appendChild](tspan);
|
1325
|
+
}
|
1326
|
+
} else {
|
1327
|
+
texts = node.getElementsByTagName("tspan");
|
1328
|
+
for (i = 0, ii = texts[length]; i < ii; i++) {
|
1329
|
+
i && $(texts[i], {dy: fontSize * leading, x: a.x});
|
1330
|
+
}
|
1331
|
+
}
|
1332
|
+
$(node, {y: a.y});
|
1333
|
+
var bb = el.getBBox(),
|
1334
|
+
dif = a.y - (bb.y + bb.height / 2);
|
1335
|
+
dif && isFinite(dif) && $(node, {y: a.y + dif});
|
1336
|
+
},
|
1337
|
+
Element = function (node, svg) {
|
1338
|
+
var X = 0,
|
1339
|
+
Y = 0;
|
1340
|
+
this[0] = node;
|
1341
|
+
this.id = R._oid++;
|
1342
|
+
this.node = node;
|
1343
|
+
node.raphael = this;
|
1344
|
+
this.paper = svg;
|
1345
|
+
this.attrs = this.attrs || {};
|
1346
|
+
this.transformations = []; // rotate, translate, scale
|
1347
|
+
this._ = {
|
1348
|
+
tx: 0,
|
1349
|
+
ty: 0,
|
1350
|
+
rt: {deg: 0, cx: 0, cy: 0},
|
1351
|
+
sx: 1,
|
1352
|
+
sy: 1
|
1353
|
+
};
|
1354
|
+
!svg.bottom && (svg.bottom = this);
|
1355
|
+
this.prev = svg.top;
|
1356
|
+
svg.top && (svg.top.next = this);
|
1357
|
+
svg.top = this;
|
1358
|
+
this.next = null;
|
1359
|
+
};
|
1360
|
+
Element[proto].rotate = function (deg, cx, cy) {
|
1361
|
+
if (this.removed) {
|
1362
|
+
return this;
|
1363
|
+
}
|
1364
|
+
if (deg == null) {
|
1365
|
+
if (this._.rt.cx) {
|
1366
|
+
return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
|
1367
|
+
}
|
1368
|
+
return this._.rt.deg;
|
1369
|
+
}
|
1370
|
+
var bbox = this.getBBox();
|
1371
|
+
deg = (deg + E)[split](separator);
|
1372
|
+
if (deg[length] - 1) {
|
1373
|
+
cx = toFloat(deg[1]);
|
1374
|
+
cy = toFloat(deg[2]);
|
1375
|
+
}
|
1376
|
+
deg = toFloat(deg[0]);
|
1377
|
+
if (cx != null) {
|
1378
|
+
this._.rt.deg = deg;
|
1379
|
+
} else {
|
1380
|
+
this._.rt.deg += deg;
|
1381
|
+
}
|
1382
|
+
(cy == null) && (cx = null);
|
1383
|
+
this._.rt.cx = cx;
|
1384
|
+
this._.rt.cy = cy;
|
1385
|
+
cx = cx == null ? bbox.x + bbox.width / 2 : cx;
|
1386
|
+
cy = cy == null ? bbox.y + bbox.height / 2 : cy;
|
1387
|
+
if (this._.rt.deg) {
|
1388
|
+
this.transformations[0] = R.format("rotate({0} {1} {2})", this._.rt.deg, cx, cy);
|
1389
|
+
this.clip && $(this.clip, {transform: R.format("rotate({0} {1} {2})", -this._.rt.deg, cx, cy)});
|
1390
|
+
} else {
|
1391
|
+
this.transformations[0] = E;
|
1392
|
+
this.clip && $(this.clip, {transform: E});
|
1393
|
+
}
|
1394
|
+
$(this.node, {transform: this.transformations[join](S)});
|
1395
|
+
return this;
|
1396
|
+
};
|
1397
|
+
Element[proto].hide = function () {
|
1398
|
+
!this.removed && (this.node.style.display = "none");
|
1399
|
+
return this;
|
1400
|
+
};
|
1401
|
+
Element[proto].show = function () {
|
1402
|
+
!this.removed && (this.node.style.display = "");
|
1403
|
+
return this;
|
1404
|
+
};
|
1405
|
+
Element[proto].remove = function () {
|
1406
|
+
if (this.removed) {
|
1407
|
+
return;
|
1408
|
+
}
|
1409
|
+
tear(this, this.paper);
|
1410
|
+
this.node.parentNode.removeChild(this.node);
|
1411
|
+
for (var i in this) {
|
1412
|
+
delete this[i];
|
1413
|
+
}
|
1414
|
+
this.removed = true;
|
1415
|
+
};
|
1416
|
+
Element[proto].getBBox = function () {
|
1417
|
+
if (this.removed) {
|
1418
|
+
return this;
|
1419
|
+
}
|
1420
|
+
if (this.type == "path") {
|
1421
|
+
return pathDimensions(this.attrs.path);
|
1422
|
+
}
|
1423
|
+
if (this.node.style.display == "none") {
|
1424
|
+
this.show();
|
1425
|
+
var hide = true;
|
1426
|
+
}
|
1427
|
+
var bbox = {};
|
1428
|
+
try {
|
1429
|
+
bbox = this.node.getBBox();
|
1430
|
+
} catch(e) {
|
1431
|
+
// Firefox 3.0.x plays badly here
|
1432
|
+
} finally {
|
1433
|
+
bbox = bbox || {};
|
1434
|
+
}
|
1435
|
+
if (this.type == "text") {
|
1436
|
+
bbox = {x: bbox.x, y: Infinity, width: 0, height: 0};
|
1437
|
+
for (var i = 0, ii = this.node.getNumberOfChars(); i < ii; i++) {
|
1438
|
+
var bb = this.node.getExtentOfChar(i);
|
1439
|
+
(bb.y < bbox.y) && (bbox.y = bb.y);
|
1440
|
+
(bb.y + bb.height - bbox.y > bbox.height) && (bbox.height = bb.y + bb.height - bbox.y);
|
1441
|
+
(bb.x + bb.width - bbox.x > bbox.width) && (bbox.width = bb.x + bb.width - bbox.x);
|
1442
|
+
}
|
1443
|
+
}
|
1444
|
+
hide && this.hide();
|
1445
|
+
return bbox;
|
1446
|
+
};
|
1447
|
+
Element[proto].attr = function (name, value) {
|
1448
|
+
if (this.removed) {
|
1449
|
+
return this;
|
1450
|
+
}
|
1451
|
+
if (name == null) {
|
1452
|
+
var res = {};
|
1453
|
+
for (var i in this.attrs) if (this.attrs[has](i)) {
|
1454
|
+
res[i] = this.attrs[i];
|
1455
|
+
}
|
1456
|
+
this._.rt.deg && (res.rotation = this.rotate());
|
1457
|
+
(this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
|
1458
|
+
res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
|
1459
|
+
return res;
|
1460
|
+
}
|
1461
|
+
if (value == null && R.is(name, string)) {
|
1462
|
+
if (name == "translation") {
|
1463
|
+
return translate.call(this);
|
1464
|
+
}
|
1465
|
+
if (name == "rotation") {
|
1466
|
+
return this.rotate();
|
1467
|
+
}
|
1468
|
+
if (name == "scale") {
|
1469
|
+
return this.scale();
|
1470
|
+
}
|
1471
|
+
if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
|
1472
|
+
return this.attrs.gradient;
|
1473
|
+
}
|
1474
|
+
return this.attrs[name];
|
1475
|
+
}
|
1476
|
+
if (value == null && R.is(name, array)) {
|
1477
|
+
var values = {};
|
1478
|
+
for (var j = 0, jj = name.length; j < jj; j++) {
|
1479
|
+
values[name[j]] = this.attr(name[j]);
|
1480
|
+
}
|
1481
|
+
return values;
|
1482
|
+
}
|
1483
|
+
if (value != null) {
|
1484
|
+
var params = {};
|
1485
|
+
params[name] = value;
|
1486
|
+
setFillAndStroke(this, params);
|
1487
|
+
} else if (name != null && R.is(name, "object")) {
|
1488
|
+
setFillAndStroke(this, name);
|
1489
|
+
}
|
1490
|
+
return this;
|
1491
|
+
};
|
1492
|
+
Element[proto].toFront = function () {
|
1493
|
+
if (this.removed) {
|
1494
|
+
return this;
|
1495
|
+
}
|
1496
|
+
this.node.parentNode[appendChild](this.node);
|
1497
|
+
var svg = this.paper;
|
1498
|
+
svg.top != this && tofront(this, svg);
|
1499
|
+
return this;
|
1500
|
+
};
|
1501
|
+
Element[proto].toBack = function () {
|
1502
|
+
if (this.removed) {
|
1503
|
+
return this;
|
1504
|
+
}
|
1505
|
+
if (this.node.parentNode.firstChild != this.node) {
|
1506
|
+
this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
|
1507
|
+
toback(this, this.paper);
|
1508
|
+
var svg = this.paper;
|
1509
|
+
}
|
1510
|
+
return this;
|
1511
|
+
};
|
1512
|
+
Element[proto].insertAfter = function (element) {
|
1513
|
+
if (this.removed) {
|
1514
|
+
return this;
|
1515
|
+
}
|
1516
|
+
var node = element.node;
|
1517
|
+
if (node.nextSibling) {
|
1518
|
+
node.parentNode.insertBefore(this.node, node.nextSibling);
|
1519
|
+
} else {
|
1520
|
+
node.parentNode[appendChild](this.node);
|
1521
|
+
}
|
1522
|
+
insertafter(this, element, this.paper);
|
1523
|
+
return this;
|
1524
|
+
};
|
1525
|
+
Element[proto].insertBefore = function (element) {
|
1526
|
+
if (this.removed) {
|
1527
|
+
return this;
|
1528
|
+
}
|
1529
|
+
var node = element.node;
|
1530
|
+
node.parentNode.insertBefore(this.node, node);
|
1531
|
+
insertbefore(this, element, this.paper);
|
1532
|
+
return this;
|
1533
|
+
};
|
1534
|
+
Element[proto].blur = function (size) {
|
1535
|
+
// Experimental. No Safari support. Use it on your own risk.
|
1536
|
+
var t = this;
|
1537
|
+
if (+size !== 0) {
|
1538
|
+
var fltr = $("filter"),
|
1539
|
+
blur = $("feGaussianBlur");
|
1540
|
+
t.attrs.blur = size;
|
1541
|
+
fltr.id = "r" + (R._id++)[toString](36);
|
1542
|
+
$(blur, {stdDeviation: +size || 1.5});
|
1543
|
+
fltr.appendChild(blur);
|
1544
|
+
t.paper.defs.appendChild(fltr);
|
1545
|
+
t._blur = fltr;
|
1546
|
+
$(t.node, {filter: "url(#" + fltr.id + ")"});
|
1547
|
+
} else {
|
1548
|
+
if (t._blur) {
|
1549
|
+
t._blur.parentNode.removeChild(t._blur);
|
1550
|
+
delete t._blur;
|
1551
|
+
delete t.attrs.blur;
|
1552
|
+
}
|
1553
|
+
t.node.removeAttribute("filter");
|
1554
|
+
}
|
1555
|
+
};
|
1556
|
+
var theCircle = function (svg, x, y, r) {
|
1557
|
+
x = round(x);
|
1558
|
+
y = round(y);
|
1559
|
+
var el = $("circle");
|
1560
|
+
svg.canvas && svg.canvas[appendChild](el);
|
1561
|
+
var res = new Element(el, svg);
|
1562
|
+
res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
|
1563
|
+
res.type = "circle";
|
1564
|
+
$(el, res.attrs);
|
1565
|
+
return res;
|
1566
|
+
};
|
1567
|
+
var theRect = function (svg, x, y, w, h, r) {
|
1568
|
+
x = round(x);
|
1569
|
+
y = round(y);
|
1570
|
+
var el = $("rect");
|
1571
|
+
svg.canvas && svg.canvas[appendChild](el);
|
1572
|
+
var res = new Element(el, svg);
|
1573
|
+
res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
|
1574
|
+
res.type = "rect";
|
1575
|
+
$(el, res.attrs);
|
1576
|
+
return res;
|
1577
|
+
};
|
1578
|
+
var theEllipse = function (svg, x, y, rx, ry) {
|
1579
|
+
x = round(x);
|
1580
|
+
y = round(y);
|
1581
|
+
var el = $("ellipse");
|
1582
|
+
svg.canvas && svg.canvas[appendChild](el);
|
1583
|
+
var res = new Element(el, svg);
|
1584
|
+
res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
|
1585
|
+
res.type = "ellipse";
|
1586
|
+
$(el, res.attrs);
|
1587
|
+
return res;
|
1588
|
+
};
|
1589
|
+
var theImage = function (svg, src, x, y, w, h) {
|
1590
|
+
var el = $("image");
|
1591
|
+
$(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
|
1592
|
+
el.setAttributeNS(svg.xlink, "href", src);
|
1593
|
+
svg.canvas && svg.canvas[appendChild](el);
|
1594
|
+
var res = new Element(el, svg);
|
1595
|
+
res.attrs = {x: x, y: y, width: w, height: h, src: src};
|
1596
|
+
res.type = "image";
|
1597
|
+
return res;
|
1598
|
+
};
|
1599
|
+
var theText = function (svg, x, y, text) {
|
1600
|
+
var el = $("text");
|
1601
|
+
$(el, {x: x, y: y, "text-anchor": "middle"});
|
1602
|
+
svg.canvas && svg.canvas[appendChild](el);
|
1603
|
+
var res = new Element(el, svg);
|
1604
|
+
res.attrs = {x: x, y: y, "text-anchor": "middle", text: text, font: availableAttrs.font, stroke: "none", fill: "#000"};
|
1605
|
+
res.type = "text";
|
1606
|
+
setFillAndStroke(res, res.attrs);
|
1607
|
+
return res;
|
1608
|
+
};
|
1609
|
+
var setSize = function (width, height) {
|
1610
|
+
this.width = width || this.width;
|
1611
|
+
this.height = height || this.height;
|
1612
|
+
this.canvas[setAttribute]("width", this.width);
|
1613
|
+
this.canvas[setAttribute]("height", this.height);
|
1614
|
+
return this;
|
1615
|
+
};
|
1616
|
+
var create = function () {
|
1617
|
+
var con = getContainer[apply](0, arguments),
|
1618
|
+
container = con && con.container,
|
1619
|
+
x = con.x,
|
1620
|
+
y = con.y,
|
1621
|
+
width = con.width,
|
1622
|
+
height = con.height;
|
1623
|
+
if (!container) {
|
1624
|
+
throw new Error("SVG container not found.");
|
1625
|
+
}
|
1626
|
+
var cnvs = $("svg");
|
1627
|
+
x = x || 0;
|
1628
|
+
y = y || 0;
|
1629
|
+
width = width || 512;
|
1630
|
+
height = height || 342;
|
1631
|
+
$(cnvs, {
|
1632
|
+
xmlns: "http://www.w3.org/2000/svg",
|
1633
|
+
version: 1.1,
|
1634
|
+
width: width,
|
1635
|
+
height: height
|
1636
|
+
});
|
1637
|
+
if (container == 1) {
|
1638
|
+
cnvs.style.cssText = "position:absolute;left:" + x + "px;top:" + y + "px";
|
1639
|
+
doc.body[appendChild](cnvs);
|
1640
|
+
} else {
|
1641
|
+
if (container.firstChild) {
|
1642
|
+
container.insertBefore(cnvs, container.firstChild);
|
1643
|
+
} else {
|
1644
|
+
container[appendChild](cnvs);
|
1645
|
+
}
|
1646
|
+
}
|
1647
|
+
container = new Paper;
|
1648
|
+
container.width = width;
|
1649
|
+
container.height = height;
|
1650
|
+
container.canvas = cnvs;
|
1651
|
+
plugins.call(container, container, R.fn);
|
1652
|
+
container.clear();
|
1653
|
+
return container;
|
1654
|
+
};
|
1655
|
+
Paper[proto].clear = function () {
|
1656
|
+
var c = this.canvas;
|
1657
|
+
while (c.firstChild) {
|
1658
|
+
c.removeChild(c.firstChild);
|
1659
|
+
}
|
1660
|
+
this.bottom = this.top = null;
|
1661
|
+
(this.desc = $("desc"))[appendChild](doc.createTextNode("Created with Rapha\xebl"));
|
1662
|
+
c[appendChild](this.desc);
|
1663
|
+
c[appendChild](this.defs = $("defs"));
|
1664
|
+
};
|
1665
|
+
Paper[proto].remove = function () {
|
1666
|
+
this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
|
1667
|
+
for (var i in this) {
|
1668
|
+
this[i] = removed(i);
|
1669
|
+
}
|
1670
|
+
};
|
1671
|
+
}
|
1672
|
+
|
1673
|
+
// VML
|
1674
|
+
if (R.vml) {
|
1675
|
+
var map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
|
1676
|
+
bites = /([clmz]),?([^clmz]*)/gi,
|
1677
|
+
val = /-?[^,\s-]+/g,
|
1678
|
+
coordsize = 1e3 + S + 1e3,
|
1679
|
+
zoom = 10,
|
1680
|
+
pathlike = {path: 1, rect: 1},
|
1681
|
+
path2vml = function (path) {
|
1682
|
+
var total = /[ahqstv]/ig,
|
1683
|
+
command = pathToAbsolute;
|
1684
|
+
(path + E).match(total) && (command = path2curve);
|
1685
|
+
total = /[clmz]/g;
|
1686
|
+
if (command == pathToAbsolute && !(path + E).match(total)) {
|
1687
|
+
var res = (path + E)[rp](bites, function (all, command, args) {
|
1688
|
+
var vals = [],
|
1689
|
+
isMove = lowerCase.call(command) == "m",
|
1690
|
+
res = map[command];
|
1691
|
+
args[rp](val, function (value) {
|
1692
|
+
if (isMove && vals[length] == 2) {
|
1693
|
+
res += vals + map[command == "m" ? "l" : "L"];
|
1694
|
+
vals = [];
|
1695
|
+
}
|
1696
|
+
vals[push](round(value * zoom));
|
1697
|
+
});
|
1698
|
+
return res + vals;
|
1699
|
+
});
|
1700
|
+
return res;
|
1701
|
+
}
|
1702
|
+
var pa = command(path), p, r;
|
1703
|
+
res = [];
|
1704
|
+
for (var i = 0, ii = pa[length]; i < ii; i++) {
|
1705
|
+
p = pa[i];
|
1706
|
+
r = lowerCase.call(pa[i][0]);
|
1707
|
+
r == "z" && (r = "x");
|
1708
|
+
for (var j = 1, jj = p[length]; j < jj; j++) {
|
1709
|
+
r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
|
1710
|
+
}
|
1711
|
+
res[push](r);
|
1712
|
+
}
|
1713
|
+
return res[join](S);
|
1714
|
+
};
|
1715
|
+
|
1716
|
+
R[toString] = function () {
|
1717
|
+
return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
|
1718
|
+
};
|
1719
|
+
thePath = function (pathString, vml) {
|
1720
|
+
var g = createNode("group");
|
1721
|
+
g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
|
1722
|
+
g.coordsize = vml.coordsize;
|
1723
|
+
g.coordorigin = vml.coordorigin;
|
1724
|
+
var el = createNode("shape"), ol = el.style;
|
1725
|
+
ol.width = vml.width + "px";
|
1726
|
+
ol.height = vml.height + "px";
|
1727
|
+
el.coordsize = coordsize;
|
1728
|
+
el.coordorigin = vml.coordorigin;
|
1729
|
+
g[appendChild](el);
|
1730
|
+
var p = new Element(el, g, vml),
|
1731
|
+
attr = {fill: "none", stroke: "#000"};
|
1732
|
+
pathString && (attr.path = pathString);
|
1733
|
+
p.isAbsolute = true;
|
1734
|
+
p.type = "path";
|
1735
|
+
p.path = [];
|
1736
|
+
p.Path = E;
|
1737
|
+
setFillAndStroke(p, attr);
|
1738
|
+
vml.canvas[appendChild](g);
|
1739
|
+
return p;
|
1740
|
+
};
|
1741
|
+
setFillAndStroke = function (o, params) {
|
1742
|
+
o.attrs = o.attrs || {};
|
1743
|
+
var node = o.node,
|
1744
|
+
a = o.attrs,
|
1745
|
+
s = node.style,
|
1746
|
+
xy,
|
1747
|
+
newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && o.type == "rect",
|
1748
|
+
res = o;
|
1749
|
+
|
1750
|
+
for (var par in params) if (params[has](par)) {
|
1751
|
+
a[par] = params[par];
|
1752
|
+
}
|
1753
|
+
if (newpath) {
|
1754
|
+
a.path = rectPath(a.x, a.y, a.width, a.height, a.r);
|
1755
|
+
o.X = a.x;
|
1756
|
+
o.Y = a.y;
|
1757
|
+
o.W = a.width;
|
1758
|
+
o.H = a.height;
|
1759
|
+
}
|
1760
|
+
params.href && (node.href = params.href);
|
1761
|
+
params.title && (node.title = params.title);
|
1762
|
+
params.target && (node.target = params.target);
|
1763
|
+
params.cursor && (s.cursor = params.cursor);
|
1764
|
+
"blur" in params && o.blur(params.blur);
|
1765
|
+
if (params.path && o.type == "path" || newpath) {
|
1766
|
+
node.path = path2vml(a.path);
|
1767
|
+
}
|
1768
|
+
if (params.rotation != null) {
|
1769
|
+
o.rotate(params.rotation, true);
|
1770
|
+
}
|
1771
|
+
if (params.translation) {
|
1772
|
+
xy = (params.translation + E)[split](separator);
|
1773
|
+
translate.call(o, xy[0], xy[1]);
|
1774
|
+
if (o._.rt.cx != null) {
|
1775
|
+
o._.rt.cx +=+ xy[0];
|
1776
|
+
o._.rt.cy +=+ xy[1];
|
1777
|
+
o.setBox(o.attrs, xy[0], xy[1]);
|
1778
|
+
}
|
1779
|
+
}
|
1780
|
+
if (params.scale) {
|
1781
|
+
xy = (params.scale + E)[split](separator);
|
1782
|
+
o.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
|
1783
|
+
}
|
1784
|
+
if ("clip-rect" in params) {
|
1785
|
+
var rect = (params["clip-rect"] + E)[split](separator);
|
1786
|
+
if (rect[length] == 4) {
|
1787
|
+
rect[2] = +rect[2] + (+rect[0]);
|
1788
|
+
rect[3] = +rect[3] + (+rect[1]);
|
1789
|
+
var div = node.clipRect || doc.createElement("div"),
|
1790
|
+
dstyle = div.style,
|
1791
|
+
group = node.parentNode;
|
1792
|
+
dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
|
1793
|
+
if (!node.clipRect) {
|
1794
|
+
dstyle.position = "absolute";
|
1795
|
+
dstyle.top = 0;
|
1796
|
+
dstyle.left = 0;
|
1797
|
+
dstyle.width = o.paper.width + "px";
|
1798
|
+
dstyle.height = o.paper.height + "px";
|
1799
|
+
group.parentNode.insertBefore(div, group);
|
1800
|
+
div[appendChild](group);
|
1801
|
+
node.clipRect = div;
|
1802
|
+
}
|
1803
|
+
}
|
1804
|
+
if (!params["clip-rect"]) {
|
1805
|
+
node.clipRect && (node.clipRect.style.clip = E);
|
1806
|
+
}
|
1807
|
+
}
|
1808
|
+
if (o.type == "image" && params.src) {
|
1809
|
+
node.src = params.src;
|
1810
|
+
}
|
1811
|
+
if (o.type == "image" && params.opacity) {
|
1812
|
+
node.filterOpacity = ms + ".Alpha(opacity=" + (params.opacity * 100) + ")";
|
1813
|
+
s.filter = (node.filterMatrix || E) + (node.filterOpacity || E);
|
1814
|
+
}
|
1815
|
+
params.font && (s.font = params.font);
|
1816
|
+
params["font-family"] && (s.fontFamily = '"' + params["font-family"][split](",")[0][rp](/^['"]+|['"]+$/g, E) + '"'); //'; //for readability
|
1817
|
+
params["font-size"] && (s.fontSize = params["font-size"]);
|
1818
|
+
params["font-weight"] && (s.fontWeight = params["font-weight"]);
|
1819
|
+
params["font-style"] && (s.fontStyle = params["font-style"]);
|
1820
|
+
if (params.opacity != null ||
|
1821
|
+
params["stroke-width"] != null ||
|
1822
|
+
params.fill != null ||
|
1823
|
+
params.stroke != null ||
|
1824
|
+
params["stroke-width"] != null ||
|
1825
|
+
params["stroke-opacity"] != null ||
|
1826
|
+
params["fill-opacity"] != null ||
|
1827
|
+
params["stroke-dasharray"] != null ||
|
1828
|
+
params["stroke-miterlimit"] != null ||
|
1829
|
+
params["stroke-linejoin"] != null ||
|
1830
|
+
params["stroke-linecap"] != null) {
|
1831
|
+
node = o.shape || node;
|
1832
|
+
var fill = (node.getElementsByTagName(fillString) && node.getElementsByTagName(fillString)[0]),
|
1833
|
+
newfill = false;
|
1834
|
+
!fill && (newfill = fill = createNode(fillString));
|
1835
|
+
if ("fill-opacity" in params || "opacity" in params) {
|
1836
|
+
var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
|
1837
|
+
opacity < 0 && (opacity = 0);
|
1838
|
+
opacity > 1 && (opacity = 1);
|
1839
|
+
fill.opacity = opacity;
|
1840
|
+
}
|
1841
|
+
params.fill && (fill.on = true);
|
1842
|
+
if (fill.on == null || params.fill == "none") {
|
1843
|
+
fill.on = false;
|
1844
|
+
}
|
1845
|
+
if (fill.on && params.fill) {
|
1846
|
+
var isURL = params.fill.match(ISURL);
|
1847
|
+
if (isURL) {
|
1848
|
+
fill.src = isURL[1];
|
1849
|
+
fill.type = "tile";
|
1850
|
+
} else {
|
1851
|
+
fill.color = R.getRGB(params.fill).hex;
|
1852
|
+
fill.src = E;
|
1853
|
+
fill.type = "solid";
|
1854
|
+
if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || (params.fill + E).charAt() != "r") && addGradientFill(res, params.fill)) {
|
1855
|
+
a.fill = "none";
|
1856
|
+
a.gradient = params.fill;
|
1857
|
+
}
|
1858
|
+
}
|
1859
|
+
}
|
1860
|
+
newfill && node[appendChild](fill);
|
1861
|
+
var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
|
1862
|
+
newstroke = false;
|
1863
|
+
!stroke && (newstroke = stroke = createNode("stroke"));
|
1864
|
+
if ((params.stroke && params.stroke != "none") ||
|
1865
|
+
params["stroke-width"] ||
|
1866
|
+
params["stroke-opacity"] != null ||
|
1867
|
+
params["stroke-dasharray"] ||
|
1868
|
+
params["stroke-miterlimit"] ||
|
1869
|
+
params["stroke-linejoin"] ||
|
1870
|
+
params["stroke-linecap"]) {
|
1871
|
+
stroke.on = true;
|
1872
|
+
}
|
1873
|
+
(params.stroke == "none" || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
|
1874
|
+
var strokeColor = R.getRGB(params.stroke);
|
1875
|
+
stroke.on && params.stroke && (stroke.color = strokeColor.hex);
|
1876
|
+
opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
|
1877
|
+
var width = (toFloat(params["stroke-width"]) || 1) * .75;
|
1878
|
+
opacity < 0 && (opacity = 0);
|
1879
|
+
opacity > 1 && (opacity = 1);
|
1880
|
+
params["stroke-width"] == null && (width = a["stroke-width"]);
|
1881
|
+
params["stroke-width"] && (stroke.weight = width);
|
1882
|
+
width && width < 1 && (opacity *= width) && (stroke.weight = 1);
|
1883
|
+
stroke.opacity = opacity;
|
1884
|
+
|
1885
|
+
params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
|
1886
|
+
stroke.miterlimit = params["stroke-miterlimit"] || 8;
|
1887
|
+
params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
|
1888
|
+
if (params["stroke-dasharray"]) {
|
1889
|
+
var dasharray = {
|
1890
|
+
"-": "shortdash",
|
1891
|
+
".": "shortdot",
|
1892
|
+
"-.": "shortdashdot",
|
1893
|
+
"-..": "shortdashdotdot",
|
1894
|
+
". ": "dot",
|
1895
|
+
"- ": "dash",
|
1896
|
+
"--": "longdash",
|
1897
|
+
"- .": "dashdot",
|
1898
|
+
"--.": "longdashdot",
|
1899
|
+
"--..": "longdashdotdot"
|
1900
|
+
};
|
1901
|
+
stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
|
1902
|
+
}
|
1903
|
+
newstroke && node[appendChild](stroke);
|
1904
|
+
}
|
1905
|
+
if (res.type == "text") {
|
1906
|
+
s = res.paper.span.style;
|
1907
|
+
a.font && (s.font = a.font);
|
1908
|
+
a["font-family"] && (s.fontFamily = a["font-family"]);
|
1909
|
+
a["font-size"] && (s.fontSize = a["font-size"]);
|
1910
|
+
a["font-weight"] && (s.fontWeight = a["font-weight"]);
|
1911
|
+
a["font-style"] && (s.fontStyle = a["font-style"]);
|
1912
|
+
res.node.string && (res.paper.span.innerHTML = (res.node.string + E)[rp](/</g, "<")[rp](/&/g, "&")[rp](/\n/g, "<br>"));
|
1913
|
+
res.W = a.w = res.paper.span.offsetWidth;
|
1914
|
+
res.H = a.h = res.paper.span.offsetHeight;
|
1915
|
+
res.X = a.x;
|
1916
|
+
res.Y = a.y + round(res.H / 2);
|
1917
|
+
|
1918
|
+
// text-anchor emulationm
|
1919
|
+
switch (a["text-anchor"]) {
|
1920
|
+
case "start":
|
1921
|
+
res.node.style["v-text-align"] = "left";
|
1922
|
+
res.bbx = round(res.W / 2);
|
1923
|
+
break;
|
1924
|
+
case "end":
|
1925
|
+
res.node.style["v-text-align"] = "right";
|
1926
|
+
res.bbx = -round(res.W / 2);
|
1927
|
+
break;
|
1928
|
+
default:
|
1929
|
+
res.node.style["v-text-align"] = "center";
|
1930
|
+
break;
|
1931
|
+
}
|
1932
|
+
}
|
1933
|
+
};
|
1934
|
+
addGradientFill = function (o, gradient) {
|
1935
|
+
o.attrs = o.attrs || {};
|
1936
|
+
var attrs = o.attrs,
|
1937
|
+
fill,
|
1938
|
+
type = "linear",
|
1939
|
+
fxfy = ".5 .5";
|
1940
|
+
o.attrs.gradient = gradient;
|
1941
|
+
gradient = (gradient + E)[rp](radial_gradient, function (all, fx, fy) {
|
1942
|
+
type = "radial";
|
1943
|
+
if (fx && fy) {
|
1944
|
+
fx = toFloat(fx);
|
1945
|
+
fy = toFloat(fy);
|
1946
|
+
pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
|
1947
|
+
fxfy = fx + S + fy;
|
1948
|
+
}
|
1949
|
+
return E;
|
1950
|
+
});
|
1951
|
+
gradient = gradient[split](/\s*\-\s*/);
|
1952
|
+
if (type == "linear") {
|
1953
|
+
var angle = gradient.shift();
|
1954
|
+
angle = -toFloat(angle);
|
1955
|
+
if (isNaN(angle)) {
|
1956
|
+
return null;
|
1957
|
+
}
|
1958
|
+
}
|
1959
|
+
var dots = parseDots(gradient);
|
1960
|
+
if (!dots) {
|
1961
|
+
return null;
|
1962
|
+
}
|
1963
|
+
o = o.shape || o.node;
|
1964
|
+
fill = o.getElementsByTagName(fillString)[0] || createNode(fillString);
|
1965
|
+
!fill.parentNode && o.appendChild(fill);
|
1966
|
+
if (dots[length]) {
|
1967
|
+
fill.on = true;
|
1968
|
+
fill.method = "none";
|
1969
|
+
fill.color = dots[0].color;
|
1970
|
+
fill.color2 = dots[dots[length] - 1].color;
|
1971
|
+
var clrs = [];
|
1972
|
+
for (var i = 0, ii = dots[length]; i < ii; i++) {
|
1973
|
+
dots[i].offset && clrs[push](dots[i].offset + S + dots[i].color);
|
1974
|
+
}
|
1975
|
+
fill.colors && (fill.colors.value = clrs[length] ? clrs[join]() : "0% " + fill.color);
|
1976
|
+
if (type == "radial") {
|
1977
|
+
fill.type = "gradientradial";
|
1978
|
+
fill.focus = "100%";
|
1979
|
+
fill.focussize = fxfy;
|
1980
|
+
fill.focusposition = fxfy;
|
1981
|
+
} else {
|
1982
|
+
fill.type = "gradient";
|
1983
|
+
fill.angle = (270 - angle) % 360;
|
1984
|
+
}
|
1985
|
+
}
|
1986
|
+
return 1;
|
1987
|
+
};
|
1988
|
+
Element = function (node, group, vml) {
|
1989
|
+
var Rotation = 0,
|
1990
|
+
RotX = 0,
|
1991
|
+
RotY = 0,
|
1992
|
+
Scale = 1;
|
1993
|
+
this[0] = node;
|
1994
|
+
this.id = R._oid++;
|
1995
|
+
this.node = node;
|
1996
|
+
node.raphael = this;
|
1997
|
+
this.X = 0;
|
1998
|
+
this.Y = 0;
|
1999
|
+
this.attrs = {};
|
2000
|
+
this.Group = group;
|
2001
|
+
this.paper = vml;
|
2002
|
+
this._ = {
|
2003
|
+
tx: 0,
|
2004
|
+
ty: 0,
|
2005
|
+
rt: {deg:0},
|
2006
|
+
sx: 1,
|
2007
|
+
sy: 1
|
2008
|
+
};
|
2009
|
+
!vml.bottom && (vml.bottom = this);
|
2010
|
+
this.prev = vml.top;
|
2011
|
+
vml.top && (vml.top.next = this);
|
2012
|
+
vml.top = this;
|
2013
|
+
this.next = null;
|
2014
|
+
};
|
2015
|
+
Element[proto].rotate = function (deg, cx, cy) {
|
2016
|
+
if (this.removed) {
|
2017
|
+
return this;
|
2018
|
+
}
|
2019
|
+
if (deg == null) {
|
2020
|
+
if (this._.rt.cx) {
|
2021
|
+
return [this._.rt.deg, this._.rt.cx, this._.rt.cy][join](S);
|
2022
|
+
}
|
2023
|
+
return this._.rt.deg;
|
2024
|
+
}
|
2025
|
+
deg = (deg + E)[split](separator);
|
2026
|
+
if (deg[length] - 1) {
|
2027
|
+
cx = toFloat(deg[1]);
|
2028
|
+
cy = toFloat(deg[2]);
|
2029
|
+
}
|
2030
|
+
deg = toFloat(deg[0]);
|
2031
|
+
if (cx != null) {
|
2032
|
+
this._.rt.deg = deg;
|
2033
|
+
} else {
|
2034
|
+
this._.rt.deg += deg;
|
2035
|
+
}
|
2036
|
+
cy == null && (cx = null);
|
2037
|
+
this._.rt.cx = cx;
|
2038
|
+
this._.rt.cy = cy;
|
2039
|
+
this.setBox(this.attrs, cx, cy);
|
2040
|
+
this.Group.style.rotation = this._.rt.deg;
|
2041
|
+
// gradient fix for rotation. TODO
|
2042
|
+
// var fill = (this.shape || this.node).getElementsByTagName(fillString);
|
2043
|
+
// fill = fill[0] || {};
|
2044
|
+
// var b = ((360 - this._.rt.deg) - 270) % 360;
|
2045
|
+
// !R.is(fill.angle, "undefined") && (fill.angle = b);
|
2046
|
+
return this;
|
2047
|
+
};
|
2048
|
+
Element[proto].setBox = function (params, cx, cy) {
|
2049
|
+
if (this.removed) {
|
2050
|
+
return this;
|
2051
|
+
}
|
2052
|
+
var gs = this.Group.style,
|
2053
|
+
os = (this.shape && this.shape.style) || this.node.style;
|
2054
|
+
params = params || {};
|
2055
|
+
for (var i in params) if (params[has](i)) {
|
2056
|
+
this.attrs[i] = params[i];
|
2057
|
+
}
|
2058
|
+
cx = cx || this._.rt.cx;
|
2059
|
+
cy = cy || this._.rt.cy;
|
2060
|
+
var attr = this.attrs,
|
2061
|
+
x,
|
2062
|
+
y,
|
2063
|
+
w,
|
2064
|
+
h;
|
2065
|
+
switch (this.type) {
|
2066
|
+
case "circle":
|
2067
|
+
x = attr.cx - attr.r;
|
2068
|
+
y = attr.cy - attr.r;
|
2069
|
+
w = h = attr.r * 2;
|
2070
|
+
break;
|
2071
|
+
case "ellipse":
|
2072
|
+
x = attr.cx - attr.rx;
|
2073
|
+
y = attr.cy - attr.ry;
|
2074
|
+
w = attr.rx * 2;
|
2075
|
+
h = attr.ry * 2;
|
2076
|
+
break;
|
2077
|
+
case "image":
|
2078
|
+
x = +attr.x;
|
2079
|
+
y = +attr.y;
|
2080
|
+
w = attr.width || 0;
|
2081
|
+
h = attr.height || 0;
|
2082
|
+
break;
|
2083
|
+
case "text":
|
2084
|
+
this.textpath.v = ["m", round(attr.x), ", ", round(attr.y - 2), "l", round(attr.x) + 1, ", ", round(attr.y - 2)][join](E);
|
2085
|
+
x = attr.x - round(this.W / 2);
|
2086
|
+
y = attr.y - this.H / 2;
|
2087
|
+
w = this.W;
|
2088
|
+
h = this.H;
|
2089
|
+
break;
|
2090
|
+
case "rect":
|
2091
|
+
case "path":
|
2092
|
+
if (!this.attrs.path) {
|
2093
|
+
x = 0;
|
2094
|
+
y = 0;
|
2095
|
+
w = this.paper.width;
|
2096
|
+
h = this.paper.height;
|
2097
|
+
} else {
|
2098
|
+
var dim = pathDimensions(this.attrs.path);
|
2099
|
+
x = dim.x;
|
2100
|
+
y = dim.y;
|
2101
|
+
w = dim.width;
|
2102
|
+
h = dim.height;
|
2103
|
+
}
|
2104
|
+
break;
|
2105
|
+
default:
|
2106
|
+
x = 0;
|
2107
|
+
y = 0;
|
2108
|
+
w = this.paper.width;
|
2109
|
+
h = this.paper.height;
|
2110
|
+
break;
|
2111
|
+
}
|
2112
|
+
cx = (cx == null) ? x + w / 2 : cx;
|
2113
|
+
cy = (cy == null) ? y + h / 2 : cy;
|
2114
|
+
var left = cx - this.paper.width / 2,
|
2115
|
+
top = cy - this.paper.height / 2, t;
|
2116
|
+
gs.left != (t = left + "px") && (gs.left = t);
|
2117
|
+
gs.top != (t = top + "px") && (gs.top = t);
|
2118
|
+
this.X = pathlike[has](this.type) ? -left : x;
|
2119
|
+
this.Y = pathlike[has](this.type) ? -top : y;
|
2120
|
+
this.W = w;
|
2121
|
+
this.H = h;
|
2122
|
+
if (pathlike[has](this.type)) {
|
2123
|
+
os.left != (t = -left * zoom + "px") && (os.left = t);
|
2124
|
+
os.top != (t = -top * zoom + "px") && (os.top = t);
|
2125
|
+
} else if (this.type == "text") {
|
2126
|
+
os.left != (t = -left + "px") && (os.left = t);
|
2127
|
+
os.top != (t = -top + "px") && (os.top = t);
|
2128
|
+
} else {
|
2129
|
+
gs.width != (t = this.paper.width + "px") && (gs.width = t);
|
2130
|
+
gs.height != (t = this.paper.height + "px") && (gs.height = t);
|
2131
|
+
os.left != (t = x - left + "px") && (os.left = t);
|
2132
|
+
os.top != (t = y - top + "px") && (os.top = t);
|
2133
|
+
os.width != (t = w + "px") && (os.width = t);
|
2134
|
+
os.height != (t = h + "px") && (os.height = t);
|
2135
|
+
}
|
2136
|
+
};
|
2137
|
+
Element[proto].hide = function () {
|
2138
|
+
!this.removed && (this.Group.style.display = "none");
|
2139
|
+
return this;
|
2140
|
+
};
|
2141
|
+
Element[proto].show = function () {
|
2142
|
+
!this.removed && (this.Group.style.display = "block");
|
2143
|
+
return this;
|
2144
|
+
};
|
2145
|
+
Element[proto].getBBox = function () {
|
2146
|
+
if (this.removed) {
|
2147
|
+
return this;
|
2148
|
+
}
|
2149
|
+
if (pathlike[has](this.type)) {
|
2150
|
+
return pathDimensions(this.attrs.path);
|
2151
|
+
}
|
2152
|
+
return {
|
2153
|
+
x: this.X + (this.bbx || 0),
|
2154
|
+
y: this.Y,
|
2155
|
+
width: this.W,
|
2156
|
+
height: this.H
|
2157
|
+
};
|
2158
|
+
};
|
2159
|
+
Element[proto].remove = function () {
|
2160
|
+
if (this.removed) {
|
2161
|
+
return;
|
2162
|
+
}
|
2163
|
+
tear(this, this.paper);
|
2164
|
+
this.node.parentNode.removeChild(this.node);
|
2165
|
+
this.Group.parentNode.removeChild(this.Group);
|
2166
|
+
this.shape && this.shape.parentNode.removeChild(this.shape);
|
2167
|
+
for (var i in this) {
|
2168
|
+
delete this[i];
|
2169
|
+
}
|
2170
|
+
this.removed = true;
|
2171
|
+
};
|
2172
|
+
Element[proto].attr = function (name, value) {
|
2173
|
+
if (this.removed) {
|
2174
|
+
return this;
|
2175
|
+
}
|
2176
|
+
if (name == null) {
|
2177
|
+
var res = {};
|
2178
|
+
for (var i in this.attrs) if (this.attrs[has](i)) {
|
2179
|
+
res[i] = this.attrs[i];
|
2180
|
+
}
|
2181
|
+
this._.rt.deg && (res.rotation = this.rotate());
|
2182
|
+
(this._.sx != 1 || this._.sy != 1) && (res.scale = this.scale());
|
2183
|
+
res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
|
2184
|
+
return res;
|
2185
|
+
}
|
2186
|
+
if (value == null && R.is(name, string)) {
|
2187
|
+
if (name == "translation") {
|
2188
|
+
return translate.call(this);
|
2189
|
+
}
|
2190
|
+
if (name == "rotation") {
|
2191
|
+
return this.rotate();
|
2192
|
+
}
|
2193
|
+
if (name == "scale") {
|
2194
|
+
return this.scale();
|
2195
|
+
}
|
2196
|
+
if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
|
2197
|
+
return this.attrs.gradient;
|
2198
|
+
}
|
2199
|
+
return this.attrs[name];
|
2200
|
+
}
|
2201
|
+
if (this.attrs && value == null && R.is(name, array)) {
|
2202
|
+
var ii, values = {};
|
2203
|
+
for (i = 0, ii = name[length]; i < ii; i++) {
|
2204
|
+
values[name[i]] = this.attr(name[i]);
|
2205
|
+
}
|
2206
|
+
return values;
|
2207
|
+
}
|
2208
|
+
var params;
|
2209
|
+
if (value != null) {
|
2210
|
+
params = {};
|
2211
|
+
params[name] = value;
|
2212
|
+
}
|
2213
|
+
value == null && R.is(name, "object") && (params = name);
|
2214
|
+
if (params) {
|
2215
|
+
if (params.text && this.type == "text") {
|
2216
|
+
this.node.string = params.text;
|
2217
|
+
}
|
2218
|
+
setFillAndStroke(this, params);
|
2219
|
+
if (params.gradient && (({circle: 1, ellipse: 1})[has](this.type) || (params.gradient + E).charAt() != "r")) {
|
2220
|
+
addGradientFill(this, params.gradient);
|
2221
|
+
}
|
2222
|
+
(!pathlike[has](this.type) || this._.rt.deg) && this.setBox(this.attrs);
|
2223
|
+
}
|
2224
|
+
return this;
|
2225
|
+
};
|
2226
|
+
Element[proto].toFront = function () {
|
2227
|
+
!this.removed && this.Group.parentNode[appendChild](this.Group);
|
2228
|
+
this.paper.top != this && tofront(this, this.paper);
|
2229
|
+
return this;
|
2230
|
+
};
|
2231
|
+
Element[proto].toBack = function () {
|
2232
|
+
if (this.removed) {
|
2233
|
+
return this;
|
2234
|
+
}
|
2235
|
+
if (this.Group.parentNode.firstChild != this.Group) {
|
2236
|
+
this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
|
2237
|
+
toback(this, this.paper);
|
2238
|
+
}
|
2239
|
+
return this;
|
2240
|
+
};
|
2241
|
+
Element[proto].insertAfter = function (element) {
|
2242
|
+
if (this.removed) {
|
2243
|
+
return this;
|
2244
|
+
}
|
2245
|
+
if (element.Group.nextSibling) {
|
2246
|
+
element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
|
2247
|
+
} else {
|
2248
|
+
element.Group.parentNode[appendChild](this.Group);
|
2249
|
+
}
|
2250
|
+
insertafter(this, element, this.paper);
|
2251
|
+
return this;
|
2252
|
+
};
|
2253
|
+
Element[proto].insertBefore = function (element) {
|
2254
|
+
if (this.removed) {
|
2255
|
+
return this;
|
2256
|
+
}
|
2257
|
+
element.Group.parentNode.insertBefore(this.Group, element.Group);
|
2258
|
+
insertbefore(this, element, this.paper);
|
2259
|
+
return this;
|
2260
|
+
};
|
2261
|
+
var blurregexp = / progid:\S+Blur\([^\)]+\)/g;
|
2262
|
+
Element[proto].blur = function (size) {
|
2263
|
+
var s = this.node.style,
|
2264
|
+
f = s.filter;
|
2265
|
+
f = f.replace(blurregexp, "");
|
2266
|
+
if (+size !== 0) {
|
2267
|
+
this.attrs.blur = size;
|
2268
|
+
s.filter = f + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
|
2269
|
+
s.margin = Raphael.format("-{0}px 0 0 -{0}px", Math.round(+size || 1.5));
|
2270
|
+
} else {
|
2271
|
+
s.filter = f;
|
2272
|
+
s.margin = 0;
|
2273
|
+
delete this.attrs.blur;
|
2274
|
+
}
|
2275
|
+
};
|
2276
|
+
|
2277
|
+
theCircle = function (vml, x, y, r) {
|
2278
|
+
var g = createNode("group"),
|
2279
|
+
o = createNode("oval"),
|
2280
|
+
ol = o.style;
|
2281
|
+
g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
|
2282
|
+
g.coordsize = coordsize;
|
2283
|
+
g.coordorigin = vml.coordorigin;
|
2284
|
+
g[appendChild](o);
|
2285
|
+
var res = new Element(o, g, vml);
|
2286
|
+
res.type = "circle";
|
2287
|
+
setFillAndStroke(res, {stroke: "#000", fill: "none"});
|
2288
|
+
res.attrs.cx = x;
|
2289
|
+
res.attrs.cy = y;
|
2290
|
+
res.attrs.r = r;
|
2291
|
+
res.setBox({x: x - r, y: y - r, width: r * 2, height: r * 2});
|
2292
|
+
vml.canvas[appendChild](g);
|
2293
|
+
return res;
|
2294
|
+
};
|
2295
|
+
function rectPath(x, y, w, h, r) {
|
2296
|
+
if (r) {
|
2297
|
+
return R.format("M{0},{1}l{2},0a{3},{3},0,0,1,{3},{3}l0,{5}a{3},{3},0,0,1,{4},{3}l{6},0a{3},{3},0,0,1,{4},{4}l0,{7}a{3},{3},0,0,1,{3},{4}z", x + r, y, w - r * 2, r, -r, h - r * 2, r * 2 - w, r * 2 - h);
|
2298
|
+
} else {
|
2299
|
+
return R.format("M{0},{1}l{2},0,0,{3},{4},0z", x, y, w, h, -w);
|
2300
|
+
}
|
2301
|
+
}
|
2302
|
+
theRect = function (vml, x, y, w, h, r) {
|
2303
|
+
var path = rectPath(x, y, w, h, r),
|
2304
|
+
res = vml.path(path),
|
2305
|
+
a = res.attrs;
|
2306
|
+
res.X = a.x = x;
|
2307
|
+
res.Y = a.y = y;
|
2308
|
+
res.W = a.width = w;
|
2309
|
+
res.H = a.height = h;
|
2310
|
+
a.r = r;
|
2311
|
+
a.path = path;
|
2312
|
+
res.type = "rect";
|
2313
|
+
return res;
|
2314
|
+
};
|
2315
|
+
theEllipse = function (vml, x, y, rx, ry) {
|
2316
|
+
var g = createNode("group"),
|
2317
|
+
o = createNode("oval"),
|
2318
|
+
ol = o.style;
|
2319
|
+
g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
|
2320
|
+
g.coordsize = coordsize;
|
2321
|
+
g.coordorigin = vml.coordorigin;
|
2322
|
+
g[appendChild](o);
|
2323
|
+
var res = new Element(o, g, vml);
|
2324
|
+
res.type = "ellipse";
|
2325
|
+
setFillAndStroke(res, {stroke: "#000"});
|
2326
|
+
res.attrs.cx = x;
|
2327
|
+
res.attrs.cy = y;
|
2328
|
+
res.attrs.rx = rx;
|
2329
|
+
res.attrs.ry = ry;
|
2330
|
+
res.setBox({x: x - rx, y: y - ry, width: rx * 2, height: ry * 2});
|
2331
|
+
vml.canvas[appendChild](g);
|
2332
|
+
return res;
|
2333
|
+
};
|
2334
|
+
theImage = function (vml, src, x, y, w, h) {
|
2335
|
+
var g = createNode("group"),
|
2336
|
+
o = createNode("image"),
|
2337
|
+
ol = o.style;
|
2338
|
+
g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
|
2339
|
+
g.coordsize = coordsize;
|
2340
|
+
g.coordorigin = vml.coordorigin;
|
2341
|
+
o.src = src;
|
2342
|
+
g[appendChild](o);
|
2343
|
+
var res = new Element(o, g, vml);
|
2344
|
+
res.type = "image";
|
2345
|
+
res.attrs.src = src;
|
2346
|
+
res.attrs.x = x;
|
2347
|
+
res.attrs.y = y;
|
2348
|
+
res.attrs.w = w;
|
2349
|
+
res.attrs.h = h;
|
2350
|
+
res.setBox({x: x, y: y, width: w, height: h});
|
2351
|
+
vml.canvas[appendChild](g);
|
2352
|
+
return res;
|
2353
|
+
};
|
2354
|
+
theText = function (vml, x, y, text) {
|
2355
|
+
var g = createNode("group"),
|
2356
|
+
el = createNode("shape"),
|
2357
|
+
ol = el.style,
|
2358
|
+
path = createNode("path"),
|
2359
|
+
ps = path.style,
|
2360
|
+
o = createNode("textpath");
|
2361
|
+
g.style.cssText = "position:absolute;left:0;top:0;width:" + vml.width + "px;height:" + vml.height + "px";
|
2362
|
+
g.coordsize = coordsize;
|
2363
|
+
g.coordorigin = vml.coordorigin;
|
2364
|
+
path.v = R.format("m{0},{1}l{2},{1}", round(x * 10), round(y * 10), round(x * 10) + 1);
|
2365
|
+
path.textpathok = true;
|
2366
|
+
ol.width = vml.width;
|
2367
|
+
ol.height = vml.height;
|
2368
|
+
o.string = text + E;
|
2369
|
+
o.on = true;
|
2370
|
+
el[appendChild](o);
|
2371
|
+
el[appendChild](path);
|
2372
|
+
g[appendChild](el);
|
2373
|
+
var res = new Element(o, g, vml);
|
2374
|
+
res.shape = el;
|
2375
|
+
res.textpath = path;
|
2376
|
+
res.type = "text";
|
2377
|
+
res.attrs.text = text;
|
2378
|
+
res.attrs.x = x;
|
2379
|
+
res.attrs.y = y;
|
2380
|
+
res.attrs.w = 1;
|
2381
|
+
res.attrs.h = 1;
|
2382
|
+
setFillAndStroke(res, {font: availableAttrs.font, stroke: "none", fill: "#000"});
|
2383
|
+
res.setBox();
|
2384
|
+
vml.canvas[appendChild](g);
|
2385
|
+
return res;
|
2386
|
+
};
|
2387
|
+
setSize = function (width, height) {
|
2388
|
+
var cs = this.canvas.style;
|
2389
|
+
width == +width && (width += "px");
|
2390
|
+
height == +height && (height += "px");
|
2391
|
+
cs.width = width;
|
2392
|
+
cs.height = height;
|
2393
|
+
cs.clip = "rect(0 " + width + " " + height + " 0)";
|
2394
|
+
return this;
|
2395
|
+
};
|
2396
|
+
var createNode;
|
2397
|
+
doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
|
2398
|
+
try {
|
2399
|
+
!doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
|
2400
|
+
createNode = function (tagName) {
|
2401
|
+
return doc.createElement('<rvml:' + tagName + ' class="rvml">');
|
2402
|
+
};
|
2403
|
+
} catch (e) {
|
2404
|
+
createNode = function (tagName) {
|
2405
|
+
return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
|
2406
|
+
};
|
2407
|
+
}
|
2408
|
+
create = function () {
|
2409
|
+
var con = getContainer[apply](0, arguments),
|
2410
|
+
container = con.container,
|
2411
|
+
height = con.height,
|
2412
|
+
s,
|
2413
|
+
width = con.width,
|
2414
|
+
x = con.x,
|
2415
|
+
y = con.y;
|
2416
|
+
if (!container) {
|
2417
|
+
throw new Error("VML container not found.");
|
2418
|
+
}
|
2419
|
+
var res = new Paper,
|
2420
|
+
c = res.canvas = doc.createElement("div"),
|
2421
|
+
cs = c.style;
|
2422
|
+
x = x || 0;
|
2423
|
+
y = y || 0;
|
2424
|
+
width = width || 512;
|
2425
|
+
height = height || 342;
|
2426
|
+
width == +width && (width += "px");
|
2427
|
+
height == +height && (height += "px");
|
2428
|
+
res.width = 1e3;
|
2429
|
+
res.height = 1e3;
|
2430
|
+
res.coordsize = zoom * 1e3 + S + zoom * 1e3;
|
2431
|
+
res.coordorigin = "0 0";
|
2432
|
+
res.span = doc.createElement("span");
|
2433
|
+
res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
|
2434
|
+
c[appendChild](res.span);
|
2435
|
+
cs.cssText = R.format("width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
|
2436
|
+
if (container == 1) {
|
2437
|
+
doc.body[appendChild](c);
|
2438
|
+
cs.left = x + "px";
|
2439
|
+
cs.top = y + "px";
|
2440
|
+
cs.position = "absolute";
|
2441
|
+
} else {
|
2442
|
+
if (container.firstChild) {
|
2443
|
+
container.insertBefore(c, container.firstChild);
|
2444
|
+
} else {
|
2445
|
+
container[appendChild](c);
|
2446
|
+
}
|
2447
|
+
}
|
2448
|
+
plugins.call(res, res, R.fn);
|
2449
|
+
return res;
|
2450
|
+
};
|
2451
|
+
Paper[proto].clear = function () {
|
2452
|
+
this.canvas.innerHTML = E;
|
2453
|
+
this.span = doc.createElement("span");
|
2454
|
+
this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
|
2455
|
+
this.canvas[appendChild](this.span);
|
2456
|
+
this.bottom = this.top = null;
|
2457
|
+
};
|
2458
|
+
Paper[proto].remove = function () {
|
2459
|
+
this.canvas.parentNode.removeChild(this.canvas);
|
2460
|
+
for (var i in this) {
|
2461
|
+
this[i] = removed(i);
|
2462
|
+
}
|
2463
|
+
return true;
|
2464
|
+
};
|
2465
|
+
}
|
2466
|
+
|
2467
|
+
// rest
|
2468
|
+
// Safari or Chrome (WebKit) rendering bug workaround method
|
2469
|
+
if ((/^Apple|^Google/).test(win.navigator.vendor) && (!(win.navigator.userAgent.indexOf("Version/4.0") + 1) || win.navigator.platform.slice(0, 2) == "iP")) {
|
2470
|
+
Paper[proto].safari = function () {
|
2471
|
+
var rect = this.rect(-99, -99, this.width + 99, this.height + 99);
|
2472
|
+
win.setTimeout(function () {rect.remove();});
|
2473
|
+
};
|
2474
|
+
} else {
|
2475
|
+
Paper[proto].safari = function () {};
|
2476
|
+
}
|
2477
|
+
|
2478
|
+
// Events
|
2479
|
+
var preventDefault = function () {
|
2480
|
+
this.returnValue = false;
|
2481
|
+
},
|
2482
|
+
preventTouch = function () {
|
2483
|
+
return this.originalEvent.preventDefault();
|
2484
|
+
},
|
2485
|
+
stopPropagation = function () {
|
2486
|
+
this.cancelBubble = true;
|
2487
|
+
},
|
2488
|
+
stopTouch = function () {
|
2489
|
+
return this.originalEvent.stopPropagation();
|
2490
|
+
},
|
2491
|
+
addEvent = (function () {
|
2492
|
+
if (doc.addEventListener) {
|
2493
|
+
return function (obj, type, fn, element) {
|
2494
|
+
var realName = supportsTouch && touchMap[type] ? touchMap[type] : type;
|
2495
|
+
var f = function (e) {
|
2496
|
+
if (supportsTouch && touchMap[has](type)) {
|
2497
|
+
for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
|
2498
|
+
if (e.targetTouches[i].target == obj) {
|
2499
|
+
var olde = e;
|
2500
|
+
e = e.targetTouches[i];
|
2501
|
+
e.originalEvent = olde;
|
2502
|
+
e.preventDefault = preventTouch;
|
2503
|
+
e.stopPropagation = stopTouch;
|
2504
|
+
break;
|
2505
|
+
}
|
2506
|
+
}
|
2507
|
+
}
|
2508
|
+
return fn.call(element, e);
|
2509
|
+
};
|
2510
|
+
obj.addEventListener(realName, f, false);
|
2511
|
+
return function () {
|
2512
|
+
obj.removeEventListener(realName, f, false);
|
2513
|
+
return true;
|
2514
|
+
};
|
2515
|
+
};
|
2516
|
+
} else if (doc.attachEvent) {
|
2517
|
+
return function (obj, type, fn, element) {
|
2518
|
+
var f = function (e) {
|
2519
|
+
e = e || win.event;
|
2520
|
+
e.preventDefault = e.preventDefault || preventDefault;
|
2521
|
+
e.stopPropagation = e.stopPropagation || stopPropagation;
|
2522
|
+
return fn.call(element, e);
|
2523
|
+
};
|
2524
|
+
obj.attachEvent("on" + type, f);
|
2525
|
+
var detacher = function () {
|
2526
|
+
obj.detachEvent("on" + type, f);
|
2527
|
+
return true;
|
2528
|
+
};
|
2529
|
+
return detacher;
|
2530
|
+
};
|
2531
|
+
}
|
2532
|
+
})();
|
2533
|
+
for (var i = events[length]; i--;) {
|
2534
|
+
(function (eventName) {
|
2535
|
+
R[eventName] = Element[proto][eventName] = function (fn) {
|
2536
|
+
if (R.is(fn, "function")) {
|
2537
|
+
this.events = this.events || [];
|
2538
|
+
this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || doc, eventName, fn, this)});
|
2539
|
+
}
|
2540
|
+
return this;
|
2541
|
+
};
|
2542
|
+
R["un" + eventName] = Element[proto]["un" + eventName] = function (fn) {
|
2543
|
+
var events = this.events,
|
2544
|
+
l = events[length];
|
2545
|
+
while (l--) if (events[l].name == eventName && events[l].f == fn) {
|
2546
|
+
events[l].unbind();
|
2547
|
+
events.splice(l, 1);
|
2548
|
+
!events.length && delete this.events;
|
2549
|
+
return this;
|
2550
|
+
}
|
2551
|
+
return this;
|
2552
|
+
};
|
2553
|
+
})(events[i]);
|
2554
|
+
}
|
2555
|
+
Element[proto].hover = function (f_in, f_out) {
|
2556
|
+
return this.mouseover(f_in).mouseout(f_out);
|
2557
|
+
};
|
2558
|
+
Element[proto].unhover = function (f_in, f_out) {
|
2559
|
+
return this.unmouseover(f_in).unmouseout(f_out);
|
2560
|
+
};
|
2561
|
+
Element[proto].drag = function (onmove, onstart, onend) {
|
2562
|
+
this._drag = {};
|
2563
|
+
var el = this.mousedown(function (e) {
|
2564
|
+
(e.originalEvent ? e.originalEvent : e).preventDefault();
|
2565
|
+
this._drag.x = e.clientX;
|
2566
|
+
this._drag.y = e.clientY;
|
2567
|
+
this._drag.id = e.identifier;
|
2568
|
+
onstart && onstart.call(this, e.clientX, e.clientY);
|
2569
|
+
Raphael.mousemove(move).mouseup(up);
|
2570
|
+
}),
|
2571
|
+
move = function (e) {
|
2572
|
+
var x = e.clientX,
|
2573
|
+
y = e.clientY;
|
2574
|
+
if (supportsTouch) {
|
2575
|
+
var i = e.touches.length,
|
2576
|
+
touch;
|
2577
|
+
while (i--) {
|
2578
|
+
touch = e.touches[i];
|
2579
|
+
if (touch.identifier == el._drag.id) {
|
2580
|
+
x = touch.clientX;
|
2581
|
+
y = touch.clientY;
|
2582
|
+
(e.originalEvent ? e.originalEvent : e).preventDefault();
|
2583
|
+
break;
|
2584
|
+
}
|
2585
|
+
}
|
2586
|
+
} else {
|
2587
|
+
e.preventDefault();
|
2588
|
+
}
|
2589
|
+
onmove && onmove.call(el, x - el._drag.x, y - el._drag.y, x, y);
|
2590
|
+
},
|
2591
|
+
up = function () {
|
2592
|
+
el._drag = {};
|
2593
|
+
Raphael.unmousemove(move).unmouseup(up);
|
2594
|
+
onend && onend.call(el);
|
2595
|
+
};
|
2596
|
+
return this;
|
2597
|
+
};
|
2598
|
+
Paper[proto].circle = function (x, y, r) {
|
2599
|
+
return theCircle(this, x || 0, y || 0, r || 0);
|
2600
|
+
};
|
2601
|
+
Paper[proto].rect = function (x, y, w, h, r) {
|
2602
|
+
return theRect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
|
2603
|
+
};
|
2604
|
+
Paper[proto].ellipse = function (x, y, rx, ry) {
|
2605
|
+
return theEllipse(this, x || 0, y || 0, rx || 0, ry || 0);
|
2606
|
+
};
|
2607
|
+
Paper[proto].path = function (pathString) {
|
2608
|
+
pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
|
2609
|
+
return thePath(R.format[apply](R, arguments), this);
|
2610
|
+
};
|
2611
|
+
Paper[proto].image = function (src, x, y, w, h) {
|
2612
|
+
return theImage(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
|
2613
|
+
};
|
2614
|
+
Paper[proto].text = function (x, y, text) {
|
2615
|
+
return theText(this, x || 0, y || 0, text || E);
|
2616
|
+
};
|
2617
|
+
Paper[proto].set = function (itemsArray) {
|
2618
|
+
arguments[length] > 1 && (itemsArray = Array[proto].splice.call(arguments, 0, arguments[length]));
|
2619
|
+
return new Set(itemsArray);
|
2620
|
+
};
|
2621
|
+
Paper[proto].setSize = setSize;
|
2622
|
+
Paper[proto].top = Paper[proto].bottom = null;
|
2623
|
+
Paper[proto].raphael = R;
|
2624
|
+
function x_y() {
|
2625
|
+
return this.x + S + this.y;
|
2626
|
+
}
|
2627
|
+
Element[proto].resetScale = function () {
|
2628
|
+
if (this.removed) {
|
2629
|
+
return this;
|
2630
|
+
}
|
2631
|
+
this._.sx = 1;
|
2632
|
+
this._.sy = 1;
|
2633
|
+
this.attrs.scale = "1 1";
|
2634
|
+
};
|
2635
|
+
Element[proto].scale = function (x, y, cx, cy) {
|
2636
|
+
if (this.removed) {
|
2637
|
+
return this;
|
2638
|
+
}
|
2639
|
+
if (x == null && y == null) {
|
2640
|
+
return {
|
2641
|
+
x: this._.sx,
|
2642
|
+
y: this._.sy,
|
2643
|
+
toString: x_y
|
2644
|
+
};
|
2645
|
+
}
|
2646
|
+
y = y || x;
|
2647
|
+
!+y && (y = x);
|
2648
|
+
var dx,
|
2649
|
+
dy,
|
2650
|
+
dcx,
|
2651
|
+
dcy,
|
2652
|
+
a = this.attrs;
|
2653
|
+
if (x != 0) {
|
2654
|
+
var bb = this.getBBox(),
|
2655
|
+
rcx = bb.x + bb.width / 2,
|
2656
|
+
rcy = bb.y + bb.height / 2,
|
2657
|
+
kx = x / this._.sx,
|
2658
|
+
ky = y / this._.sy;
|
2659
|
+
cx = (+cx || cx == 0) ? cx : rcx;
|
2660
|
+
cy = (+cy || cy == 0) ? cy : rcy;
|
2661
|
+
var dirx = ~~(x / math.abs(x)),
|
2662
|
+
diry = ~~(y / math.abs(y)),
|
2663
|
+
s = this.node.style,
|
2664
|
+
ncx = cx + (rcx - cx) * kx,
|
2665
|
+
ncy = cy + (rcy - cy) * ky;
|
2666
|
+
switch (this.type) {
|
2667
|
+
case "rect":
|
2668
|
+
case "image":
|
2669
|
+
var neww = a.width * dirx * kx,
|
2670
|
+
newh = a.height * diry * ky;
|
2671
|
+
this.attr({
|
2672
|
+
height: newh,
|
2673
|
+
r: a.r * mmin(dirx * kx, diry * ky),
|
2674
|
+
width: neww,
|
2675
|
+
x: ncx - neww / 2,
|
2676
|
+
y: ncy - newh / 2
|
2677
|
+
});
|
2678
|
+
break;
|
2679
|
+
case "circle":
|
2680
|
+
case "ellipse":
|
2681
|
+
this.attr({
|
2682
|
+
rx: a.rx * dirx * kx,
|
2683
|
+
ry: a.ry * diry * ky,
|
2684
|
+
r: a.r * mmin(dirx * kx, diry * ky),
|
2685
|
+
cx: ncx,
|
2686
|
+
cy: ncy
|
2687
|
+
});
|
2688
|
+
break;
|
2689
|
+
case "text":
|
2690
|
+
this.attr({
|
2691
|
+
x: ncx,
|
2692
|
+
y: ncy
|
2693
|
+
});
|
2694
|
+
break;
|
2695
|
+
case "path":
|
2696
|
+
var path = pathToRelative(a.path),
|
2697
|
+
skip = true;
|
2698
|
+
for (var i = 0, ii = path[length]; i < ii; i++) {
|
2699
|
+
var p = path[i],
|
2700
|
+
P0 = upperCase.call(p[0]);
|
2701
|
+
if (P0 == "M" && skip) {
|
2702
|
+
continue;
|
2703
|
+
} else {
|
2704
|
+
skip = false;
|
2705
|
+
}
|
2706
|
+
if (P0 == "A") {
|
2707
|
+
p[path[i][length] - 2] *= kx;
|
2708
|
+
p[path[i][length] - 1] *= ky;
|
2709
|
+
p[1] *= dirx * kx;
|
2710
|
+
p[2] *= diry * ky;
|
2711
|
+
p[5] = +!(dirx + diry ? !+p[5] : +p[5]);
|
2712
|
+
} else if (P0 == "H") {
|
2713
|
+
for (var j = 1, jj = p[length]; j < jj; j++) {
|
2714
|
+
p[j] *= kx;
|
2715
|
+
}
|
2716
|
+
} else if (P0 == "V") {
|
2717
|
+
for (j = 1, jj = p[length]; j < jj; j++) {
|
2718
|
+
p[j] *= ky;
|
2719
|
+
}
|
2720
|
+
} else {
|
2721
|
+
for (j = 1, jj = p[length]; j < jj; j++) {
|
2722
|
+
p[j] *= (j % 2) ? kx : ky;
|
2723
|
+
}
|
2724
|
+
}
|
2725
|
+
}
|
2726
|
+
var dim2 = pathDimensions(path);
|
2727
|
+
dx = ncx - dim2.x - dim2.width / 2;
|
2728
|
+
dy = ncy - dim2.y - dim2.height / 2;
|
2729
|
+
path[0][1] += dx;
|
2730
|
+
path[0][2] += dy;
|
2731
|
+
this.attr({path: path});
|
2732
|
+
break;
|
2733
|
+
}
|
2734
|
+
if (this.type in {text: 1, image:1} && (dirx != 1 || diry != 1)) {
|
2735
|
+
if (this.transformations) {
|
2736
|
+
this.transformations[2] = "scale("[concat](dirx, ",", diry, ")");
|
2737
|
+
this.node[setAttribute]("transform", this.transformations[join](S));
|
2738
|
+
dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
|
2739
|
+
dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
|
2740
|
+
this.attr({x: dx, y: dy});
|
2741
|
+
a.fx = dirx - 1;
|
2742
|
+
a.fy = diry - 1;
|
2743
|
+
} else {
|
2744
|
+
this.node.filterMatrix = ms + ".Matrix(M11="[concat](dirx,
|
2745
|
+
", M12=0, M21=0, M22=", diry,
|
2746
|
+
", Dx=0, Dy=0, sizingmethod='auto expand', filtertype='bilinear')");
|
2747
|
+
s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
|
2748
|
+
}
|
2749
|
+
} else {
|
2750
|
+
if (this.transformations) {
|
2751
|
+
this.transformations[2] = E;
|
2752
|
+
this.node[setAttribute]("transform", this.transformations[join](S));
|
2753
|
+
a.fx = 0;
|
2754
|
+
a.fy = 0;
|
2755
|
+
} else {
|
2756
|
+
this.node.filterMatrix = E;
|
2757
|
+
s.filter = (this.node.filterMatrix || E) + (this.node.filterOpacity || E);
|
2758
|
+
}
|
2759
|
+
}
|
2760
|
+
a.scale = [x, y, cx, cy][join](S);
|
2761
|
+
this._.sx = x;
|
2762
|
+
this._.sy = y;
|
2763
|
+
}
|
2764
|
+
return this;
|
2765
|
+
};
|
2766
|
+
Element[proto].clone = function () {
|
2767
|
+
if (this.removed) {
|
2768
|
+
return null;
|
2769
|
+
}
|
2770
|
+
var attr = this.attr();
|
2771
|
+
delete attr.scale;
|
2772
|
+
delete attr.translation;
|
2773
|
+
return this.paper[this.type]().attr(attr);
|
2774
|
+
};
|
2775
|
+
var getPointAtSegmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
|
2776
|
+
var len = 0,
|
2777
|
+
old;
|
2778
|
+
for (var i = 0; i < 1.001; i+=.001) {
|
2779
|
+
var dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
|
2780
|
+
i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
|
2781
|
+
if (len >= length) {
|
2782
|
+
return dot;
|
2783
|
+
}
|
2784
|
+
old = dot;
|
2785
|
+
}
|
2786
|
+
}),
|
2787
|
+
getLengthFactory = function (istotal, subpath) {
|
2788
|
+
return function (path, length, onlystart) {
|
2789
|
+
path = path2curve(path);
|
2790
|
+
var x, y, p, l, sp = "", subpaths = {}, point,
|
2791
|
+
len = 0;
|
2792
|
+
for (var i = 0, ii = path.length; i < ii; i++) {
|
2793
|
+
p = path[i];
|
2794
|
+
if (p[0] == "M") {
|
2795
|
+
x = +p[1];
|
2796
|
+
y = +p[2];
|
2797
|
+
} else {
|
2798
|
+
l = segmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
|
2799
|
+
if (len + l > length) {
|
2800
|
+
if (subpath && !subpaths.start) {
|
2801
|
+
point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
|
2802
|
+
sp += ["C", point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
|
2803
|
+
if (onlystart) {return sp;}
|
2804
|
+
subpaths.start = sp;
|
2805
|
+
sp = ["M", point.x, point.y + "C", point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]][join]();
|
2806
|
+
len += l;
|
2807
|
+
x = +p[5];
|
2808
|
+
y = +p[6];
|
2809
|
+
continue;
|
2810
|
+
}
|
2811
|
+
if (!istotal && !subpath) {
|
2812
|
+
point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
|
2813
|
+
return {x: point.x, y: point.y, alpha: point.alpha};
|
2814
|
+
}
|
2815
|
+
}
|
2816
|
+
len += l;
|
2817
|
+
x = +p[5];
|
2818
|
+
y = +p[6];
|
2819
|
+
}
|
2820
|
+
sp += p;
|
2821
|
+
}
|
2822
|
+
subpaths.end = sp;
|
2823
|
+
point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
|
2824
|
+
point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
|
2825
|
+
return point;
|
2826
|
+
};
|
2827
|
+
},
|
2828
|
+
segmentLength = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
|
2829
|
+
var old = {x: 0, y: 0},
|
2830
|
+
len = 0;
|
2831
|
+
for (var i = 0; i < 1.01; i+=.01) {
|
2832
|
+
var dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
|
2833
|
+
i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
|
2834
|
+
old = dot;
|
2835
|
+
}
|
2836
|
+
return len;
|
2837
|
+
});
|
2838
|
+
var getTotalLength = getLengthFactory(1),
|
2839
|
+
getPointAtLength = getLengthFactory(),
|
2840
|
+
getSubpathsAtLength = getLengthFactory(0, 1);
|
2841
|
+
Element[proto].getTotalLength = function () {
|
2842
|
+
if (this.type != "path") {return;}
|
2843
|
+
if (this.node.getTotalLength) {
|
2844
|
+
return this.node.getTotalLength();
|
2845
|
+
}
|
2846
|
+
return getTotalLength(this.attrs.path);
|
2847
|
+
};
|
2848
|
+
Element[proto].getPointAtLength = function (length) {
|
2849
|
+
if (this.type != "path") {return;}
|
2850
|
+
return getPointAtLength(this.attrs.path, length);
|
2851
|
+
};
|
2852
|
+
Element[proto].getSubpath = function (from, to) {
|
2853
|
+
if (this.type != "path") {return;}
|
2854
|
+
if (math.abs(this.getTotalLength() - to) < 1e-6) {
|
2855
|
+
return getSubpathsAtLength(this.attrs.path, from).end;
|
2856
|
+
}
|
2857
|
+
var a = getSubpathsAtLength(this.attrs.path, to, 1);
|
2858
|
+
return from ? getSubpathsAtLength(a, from).end : a;
|
2859
|
+
};
|
2860
|
+
|
2861
|
+
// animation easing formulas
|
2862
|
+
R.easing_formulas = {
|
2863
|
+
linear: function (n) {
|
2864
|
+
return n;
|
2865
|
+
},
|
2866
|
+
"<": function (n) {
|
2867
|
+
return pow(n, 3);
|
2868
|
+
},
|
2869
|
+
">": function (n) {
|
2870
|
+
return pow(n - 1, 3) + 1;
|
2871
|
+
},
|
2872
|
+
"<>": function (n) {
|
2873
|
+
n = n * 2;
|
2874
|
+
if (n < 1) {
|
2875
|
+
return pow(n, 3) / 2;
|
2876
|
+
}
|
2877
|
+
n -= 2;
|
2878
|
+
return (pow(n, 3) + 2) / 2;
|
2879
|
+
},
|
2880
|
+
backIn: function (n) {
|
2881
|
+
var s = 1.70158;
|
2882
|
+
return n * n * ((s + 1) * n - s);
|
2883
|
+
},
|
2884
|
+
backOut: function (n) {
|
2885
|
+
n = n - 1;
|
2886
|
+
var s = 1.70158;
|
2887
|
+
return n * n * ((s + 1) * n + s) + 1;
|
2888
|
+
},
|
2889
|
+
elastic: function (n) {
|
2890
|
+
if (n == 0 || n == 1) {
|
2891
|
+
return n;
|
2892
|
+
}
|
2893
|
+
var p = .3,
|
2894
|
+
s = p / 4;
|
2895
|
+
return pow(2, -10 * n) * math.sin((n - s) * (2 * math.PI) / p) + 1;
|
2896
|
+
},
|
2897
|
+
bounce: function (n) {
|
2898
|
+
var s = 7.5625,
|
2899
|
+
p = 2.75,
|
2900
|
+
l;
|
2901
|
+
if (n < (1 / p)) {
|
2902
|
+
l = s * n * n;
|
2903
|
+
} else {
|
2904
|
+
if (n < (2 / p)) {
|
2905
|
+
n -= (1.5 / p);
|
2906
|
+
l = s * n * n + .75;
|
2907
|
+
} else {
|
2908
|
+
if (n < (2.5 / p)) {
|
2909
|
+
n -= (2.25 / p);
|
2910
|
+
l = s * n * n + .9375;
|
2911
|
+
} else {
|
2912
|
+
n -= (2.625 / p);
|
2913
|
+
l = s * n * n + .984375;
|
2914
|
+
}
|
2915
|
+
}
|
2916
|
+
}
|
2917
|
+
return l;
|
2918
|
+
}
|
2919
|
+
};
|
2920
|
+
|
2921
|
+
var animationElements = {length : 0},
|
2922
|
+
animation = function () {
|
2923
|
+
var Now = +new Date;
|
2924
|
+
for (var l in animationElements) if (l != "length" && animationElements[has](l)) {
|
2925
|
+
var e = animationElements[l];
|
2926
|
+
if (e.stop || e.el.removed) {
|
2927
|
+
delete animationElements[l];
|
2928
|
+
animationElements[length]--;
|
2929
|
+
continue;
|
2930
|
+
}
|
2931
|
+
var time = Now - e.start,
|
2932
|
+
ms = e.ms,
|
2933
|
+
easing = e.easing,
|
2934
|
+
from = e.from,
|
2935
|
+
diff = e.diff,
|
2936
|
+
to = e.to,
|
2937
|
+
t = e.t,
|
2938
|
+
prev = e.prev || 0,
|
2939
|
+
that = e.el,
|
2940
|
+
callback = e.callback,
|
2941
|
+
set = {},
|
2942
|
+
now;
|
2943
|
+
if (time < ms) {
|
2944
|
+
var pos = R.easing_formulas[easing] ? R.easing_formulas[easing](time / ms) : time / ms;
|
2945
|
+
for (var attr in from) if (from[has](attr)) {
|
2946
|
+
switch (availableAnimAttrs[attr]) {
|
2947
|
+
case "along":
|
2948
|
+
now = pos * ms * diff[attr];
|
2949
|
+
to.back && (now = to.len - now);
|
2950
|
+
var point = getPointAtLength(to[attr], now);
|
2951
|
+
that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
|
2952
|
+
diff.x = point.x;
|
2953
|
+
diff.y = point.y;
|
2954
|
+
that.translate(point.x - diff.sx, point.y - diff.sy);
|
2955
|
+
to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
|
2956
|
+
break;
|
2957
|
+
case nu:
|
2958
|
+
now = +from[attr] + pos * ms * diff[attr];
|
2959
|
+
break;
|
2960
|
+
case "colour":
|
2961
|
+
now = "rgb(" + [
|
2962
|
+
upto255(round(from[attr].r + pos * ms * diff[attr].r)),
|
2963
|
+
upto255(round(from[attr].g + pos * ms * diff[attr].g)),
|
2964
|
+
upto255(round(from[attr].b + pos * ms * diff[attr].b))
|
2965
|
+
][join](",") + ")";
|
2966
|
+
break;
|
2967
|
+
case "path":
|
2968
|
+
now = [];
|
2969
|
+
for (var i = 0, ii = from[attr][length]; i < ii; i++) {
|
2970
|
+
now[i] = [from[attr][i][0]];
|
2971
|
+
for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
|
2972
|
+
now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
|
2973
|
+
}
|
2974
|
+
now[i] = now[i][join](S);
|
2975
|
+
}
|
2976
|
+
now = now[join](S);
|
2977
|
+
break;
|
2978
|
+
case "csv":
|
2979
|
+
switch (attr) {
|
2980
|
+
case "translation":
|
2981
|
+
var x = diff[attr][0] * (time - prev),
|
2982
|
+
y = diff[attr][1] * (time - prev);
|
2983
|
+
t.x += x;
|
2984
|
+
t.y += y;
|
2985
|
+
now = x + S + y;
|
2986
|
+
break;
|
2987
|
+
case "rotation":
|
2988
|
+
now = +from[attr][0] + pos * ms * diff[attr][0];
|
2989
|
+
from[attr][1] && (now += "," + from[attr][1] + "," + from[attr][2]);
|
2990
|
+
break;
|
2991
|
+
case "scale":
|
2992
|
+
now = [+from[attr][0] + pos * ms * diff[attr][0], +from[attr][1] + pos * ms * diff[attr][1], (2 in to[attr] ? to[attr][2] : E), (3 in to[attr] ? to[attr][3] : E)][join](S);
|
2993
|
+
break;
|
2994
|
+
case "clip-rect":
|
2995
|
+
now = [];
|
2996
|
+
i = 4;
|
2997
|
+
while (i--) {
|
2998
|
+
now[i] = +from[attr][i] + pos * ms * diff[attr][i];
|
2999
|
+
}
|
3000
|
+
break;
|
3001
|
+
}
|
3002
|
+
break;
|
3003
|
+
}
|
3004
|
+
set[attr] = now;
|
3005
|
+
}
|
3006
|
+
that.attr(set);
|
3007
|
+
that._run && that._run.call(that);
|
3008
|
+
} else {
|
3009
|
+
if (to.along) {
|
3010
|
+
point = getPointAtLength(to.along, to.len * !to.back);
|
3011
|
+
that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
|
3012
|
+
to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
|
3013
|
+
}
|
3014
|
+
(t.x || t.y) && that.translate(-t.x, -t.y);
|
3015
|
+
to.scale && (to.scale += E);
|
3016
|
+
that.attr(to);
|
3017
|
+
delete animationElements[l];
|
3018
|
+
animationElements[length]--;
|
3019
|
+
that.in_animation = null;
|
3020
|
+
R.is(callback, "function") && callback.call(that);
|
3021
|
+
}
|
3022
|
+
e.prev = time;
|
3023
|
+
}
|
3024
|
+
R.svg && that && that.paper && that.paper.safari();
|
3025
|
+
animationElements[length] && win.setTimeout(animation);
|
3026
|
+
},
|
3027
|
+
upto255 = function (color) {
|
3028
|
+
return mmax(mmin(color, 255), 0);
|
3029
|
+
},
|
3030
|
+
translate = function (x, y) {
|
3031
|
+
if (x == null) {
|
3032
|
+
return {x: this._.tx, y: this._.ty, toString: x_y};
|
3033
|
+
}
|
3034
|
+
this._.tx += +x;
|
3035
|
+
this._.ty += +y;
|
3036
|
+
switch (this.type) {
|
3037
|
+
case "circle":
|
3038
|
+
case "ellipse":
|
3039
|
+
this.attr({cx: +x + this.attrs.cx, cy: +y + this.attrs.cy});
|
3040
|
+
break;
|
3041
|
+
case "rect":
|
3042
|
+
case "image":
|
3043
|
+
case "text":
|
3044
|
+
this.attr({x: +x + this.attrs.x, y: +y + this.attrs.y});
|
3045
|
+
break;
|
3046
|
+
case "path":
|
3047
|
+
var path = pathToRelative(this.attrs.path);
|
3048
|
+
path[0][1] += +x;
|
3049
|
+
path[0][2] += +y;
|
3050
|
+
this.attr({path: path});
|
3051
|
+
break;
|
3052
|
+
}
|
3053
|
+
return this;
|
3054
|
+
};
|
3055
|
+
Element[proto].animateWith = function (element, params, ms, easing, callback) {
|
3056
|
+
animationElements[element.id] && (params.start = animationElements[element.id].start);
|
3057
|
+
return this.animate(params, ms, easing, callback);
|
3058
|
+
};
|
3059
|
+
Element[proto].animateAlong = along();
|
3060
|
+
Element[proto].animateAlongBack = along(1);
|
3061
|
+
function along(isBack) {
|
3062
|
+
return function (path, ms, rotate, callback) {
|
3063
|
+
var params = {back: isBack};
|
3064
|
+
R.is(rotate, "function") ? (callback = rotate) : (params.rot = rotate);
|
3065
|
+
path && path.constructor == Element && (path = path.attrs.path);
|
3066
|
+
path && (params.along = path);
|
3067
|
+
return this.animate(params, ms, callback);
|
3068
|
+
};
|
3069
|
+
}
|
3070
|
+
Element[proto].onAnimation = function (f) {
|
3071
|
+
this._run = f || 0;
|
3072
|
+
return this;
|
3073
|
+
};
|
3074
|
+
Element[proto].animate = function (params, ms, easing, callback) {
|
3075
|
+
if (R.is(easing, "function") || !easing) {
|
3076
|
+
callback = easing || null;
|
3077
|
+
}
|
3078
|
+
var from = {},
|
3079
|
+
to = {},
|
3080
|
+
diff = {};
|
3081
|
+
for (var attr in params) if (params[has](attr)) {
|
3082
|
+
if (availableAnimAttrs[has](attr)) {
|
3083
|
+
from[attr] = this.attr(attr);
|
3084
|
+
(from[attr] == null) && (from[attr] = availableAttrs[attr]);
|
3085
|
+
to[attr] = params[attr];
|
3086
|
+
switch (availableAnimAttrs[attr]) {
|
3087
|
+
case "along":
|
3088
|
+
var len = getTotalLength(params[attr]),
|
3089
|
+
point = getPointAtLength(params[attr], len * !!params.back),
|
3090
|
+
bb = this.getBBox();
|
3091
|
+
diff[attr] = len / ms;
|
3092
|
+
diff.tx = bb.x;
|
3093
|
+
diff.ty = bb.y;
|
3094
|
+
diff.sx = point.x;
|
3095
|
+
diff.sy = point.y;
|
3096
|
+
to.rot = params.rot;
|
3097
|
+
to.back = params.back;
|
3098
|
+
to.len = len;
|
3099
|
+
params.rot && (diff.r = toFloat(this.rotate()) || 0);
|
3100
|
+
break;
|
3101
|
+
case nu:
|
3102
|
+
diff[attr] = (to[attr] - from[attr]) / ms;
|
3103
|
+
break;
|
3104
|
+
case "colour":
|
3105
|
+
from[attr] = R.getRGB(from[attr]);
|
3106
|
+
var toColour = R.getRGB(to[attr]);
|
3107
|
+
diff[attr] = {
|
3108
|
+
r: (toColour.r - from[attr].r) / ms,
|
3109
|
+
g: (toColour.g - from[attr].g) / ms,
|
3110
|
+
b: (toColour.b - from[attr].b) / ms
|
3111
|
+
};
|
3112
|
+
break;
|
3113
|
+
case "path":
|
3114
|
+
var pathes = path2curve(from[attr], to[attr]);
|
3115
|
+
from[attr] = pathes[0];
|
3116
|
+
var toPath = pathes[1];
|
3117
|
+
diff[attr] = [];
|
3118
|
+
for (var i = 0, ii = from[attr][length]; i < ii; i++) {
|
3119
|
+
diff[attr][i] = [0];
|
3120
|
+
for (var j = 1, jj = from[attr][i][length]; j < jj; j++) {
|
3121
|
+
diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
|
3122
|
+
}
|
3123
|
+
}
|
3124
|
+
break;
|
3125
|
+
case "csv":
|
3126
|
+
var values = (params[attr] + E)[split](separator),
|
3127
|
+
from2 = (from[attr] + E)[split](separator);
|
3128
|
+
switch (attr) {
|
3129
|
+
case "translation":
|
3130
|
+
from[attr] = [0, 0];
|
3131
|
+
diff[attr] = [values[0] / ms, values[1] / ms];
|
3132
|
+
break;
|
3133
|
+
case "rotation":
|
3134
|
+
from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
|
3135
|
+
diff[attr] = [(values[0] - from[attr][0]) / ms, 0, 0];
|
3136
|
+
break;
|
3137
|
+
case "scale":
|
3138
|
+
params[attr] = values;
|
3139
|
+
from[attr] = (from[attr] + E)[split](separator);
|
3140
|
+
diff[attr] = [(values[0] - from[attr][0]) / ms, (values[1] - from[attr][1]) / ms, 0, 0];
|
3141
|
+
break;
|
3142
|
+
case "clip-rect":
|
3143
|
+
from[attr] = (from[attr] + E)[split](separator);
|
3144
|
+
diff[attr] = [];
|
3145
|
+
i = 4;
|
3146
|
+
while (i--) {
|
3147
|
+
diff[attr][i] = (values[i] - from[attr][i]) / ms;
|
3148
|
+
}
|
3149
|
+
break;
|
3150
|
+
}
|
3151
|
+
to[attr] = values;
|
3152
|
+
}
|
3153
|
+
}
|
3154
|
+
}
|
3155
|
+
this.stop();
|
3156
|
+
this.in_animation = 1;
|
3157
|
+
animationElements[this.id] = {
|
3158
|
+
start: params.start || +new Date,
|
3159
|
+
ms: ms,
|
3160
|
+
easing: easing,
|
3161
|
+
from: from,
|
3162
|
+
diff: diff,
|
3163
|
+
to: to,
|
3164
|
+
el: this,
|
3165
|
+
callback: callback,
|
3166
|
+
t: {x: 0, y: 0}
|
3167
|
+
};
|
3168
|
+
++animationElements[length] == 1 && animation();
|
3169
|
+
return this;
|
3170
|
+
};
|
3171
|
+
Element[proto].stop = function () {
|
3172
|
+
animationElements[this.id] && animationElements[length]--;
|
3173
|
+
delete animationElements[this.id];
|
3174
|
+
return this;
|
3175
|
+
};
|
3176
|
+
Element[proto].translate = function (x, y) {
|
3177
|
+
return this.attr({translation: x + " " + y});
|
3178
|
+
};
|
3179
|
+
Element[proto][toString] = function () {
|
3180
|
+
return "Rapha\xebl\u2019s object";
|
3181
|
+
};
|
3182
|
+
R.ae = animationElements;
|
3183
|
+
|
3184
|
+
// Set
|
3185
|
+
var Set = function (items) {
|
3186
|
+
this.items = [];
|
3187
|
+
this[length] = 0;
|
3188
|
+
this.type = "set";
|
3189
|
+
if (items) {
|
3190
|
+
for (var i = 0, ii = items[length]; i < ii; i++) {
|
3191
|
+
if (items[i] && (items[i].constructor == Element || items[i].constructor == Set)) {
|
3192
|
+
this[this.items[length]] = this.items[this.items[length]] = items[i];
|
3193
|
+
this[length]++;
|
3194
|
+
}
|
3195
|
+
}
|
3196
|
+
}
|
3197
|
+
};
|
3198
|
+
Set[proto][push] = function () {
|
3199
|
+
var item,
|
3200
|
+
len;
|
3201
|
+
for (var i = 0, ii = arguments[length]; i < ii; i++) {
|
3202
|
+
item = arguments[i];
|
3203
|
+
if (item && (item.constructor == Element || item.constructor == Set)) {
|
3204
|
+
len = this.items[length];
|
3205
|
+
this[len] = this.items[len] = item;
|
3206
|
+
this[length]++;
|
3207
|
+
}
|
3208
|
+
}
|
3209
|
+
return this;
|
3210
|
+
};
|
3211
|
+
Set[proto].pop = function () {
|
3212
|
+
delete this[this[length]--];
|
3213
|
+
return this.items.pop();
|
3214
|
+
};
|
3215
|
+
for (var method in Element[proto]) if (Element[proto][has](method)) {
|
3216
|
+
Set[proto][method] = (function (methodname) {
|
3217
|
+
return function () {
|
3218
|
+
for (var i = 0, ii = this.items[length]; i < ii; i++) {
|
3219
|
+
this.items[i][methodname][apply](this.items[i], arguments);
|
3220
|
+
}
|
3221
|
+
return this;
|
3222
|
+
};
|
3223
|
+
})(method);
|
3224
|
+
}
|
3225
|
+
Set[proto].attr = function (name, value) {
|
3226
|
+
if (name && R.is(name, array) && R.is(name[0], "object")) {
|
3227
|
+
for (var j = 0, jj = name[length]; j < jj; j++) {
|
3228
|
+
this.items[j].attr(name[j]);
|
3229
|
+
}
|
3230
|
+
} else {
|
3231
|
+
for (var i = 0, ii = this.items[length]; i < ii; i++) {
|
3232
|
+
this.items[i].attr(name, value);
|
3233
|
+
}
|
3234
|
+
}
|
3235
|
+
return this;
|
3236
|
+
};
|
3237
|
+
Set[proto].animate = function (params, ms, easing, callback) {
|
3238
|
+
(R.is(easing, "function") || !easing) && (callback = easing || null);
|
3239
|
+
var len = this.items[length],
|
3240
|
+
i = len,
|
3241
|
+
item,
|
3242
|
+
set = this,
|
3243
|
+
collector;
|
3244
|
+
callback && (collector = function () {
|
3245
|
+
!--len && callback.call(set);
|
3246
|
+
});
|
3247
|
+
easing = R.is(easing, string) ? easing : collector;
|
3248
|
+
item = this.items[--i].animate(params, ms, easing, collector);
|
3249
|
+
while (i--) {
|
3250
|
+
this.items[i].animateWith(item, params, ms, easing, collector);
|
3251
|
+
}
|
3252
|
+
return this;
|
3253
|
+
};
|
3254
|
+
Set[proto].insertAfter = function (el) {
|
3255
|
+
var i = this.items[length];
|
3256
|
+
while (i--) {
|
3257
|
+
this.items[i].insertAfter(el);
|
3258
|
+
}
|
3259
|
+
return this;
|
3260
|
+
};
|
3261
|
+
Set[proto].getBBox = function () {
|
3262
|
+
var x = [],
|
3263
|
+
y = [],
|
3264
|
+
w = [],
|
3265
|
+
h = [];
|
3266
|
+
for (var i = this.items[length]; i--;) {
|
3267
|
+
var box = this.items[i].getBBox();
|
3268
|
+
x[push](box.x);
|
3269
|
+
y[push](box.y);
|
3270
|
+
w[push](box.x + box.width);
|
3271
|
+
h[push](box.y + box.height);
|
3272
|
+
}
|
3273
|
+
x = mmin[apply](0, x);
|
3274
|
+
y = mmin[apply](0, y);
|
3275
|
+
return {
|
3276
|
+
x: x,
|
3277
|
+
y: y,
|
3278
|
+
width: mmax[apply](0, w) - x,
|
3279
|
+
height: mmax[apply](0, h) - y
|
3280
|
+
};
|
3281
|
+
};
|
3282
|
+
Set[proto].clone = function (s) {
|
3283
|
+
s = new Set;
|
3284
|
+
for (var i = 0, ii = this.items[length]; i < ii; i++) {
|
3285
|
+
s[push](this.items[i].clone());
|
3286
|
+
}
|
3287
|
+
return s;
|
3288
|
+
};
|
3289
|
+
|
3290
|
+
R.registerFont = function (font) {
|
3291
|
+
if (!font.face) {
|
3292
|
+
return font;
|
3293
|
+
}
|
3294
|
+
this.fonts = this.fonts || {};
|
3295
|
+
var fontcopy = {
|
3296
|
+
w: font.w,
|
3297
|
+
face: {},
|
3298
|
+
glyphs: {}
|
3299
|
+
},
|
3300
|
+
family = font.face["font-family"];
|
3301
|
+
for (var prop in font.face) if (font.face[has](prop)) {
|
3302
|
+
fontcopy.face[prop] = font.face[prop];
|
3303
|
+
}
|
3304
|
+
if (this.fonts[family]) {
|
3305
|
+
this.fonts[family][push](fontcopy);
|
3306
|
+
} else {
|
3307
|
+
this.fonts[family] = [fontcopy];
|
3308
|
+
}
|
3309
|
+
if (!font.svg) {
|
3310
|
+
fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
|
3311
|
+
for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
|
3312
|
+
var path = font.glyphs[glyph];
|
3313
|
+
fontcopy.glyphs[glyph] = {
|
3314
|
+
w: path.w,
|
3315
|
+
k: {},
|
3316
|
+
d: path.d && "M" + path.d[rp](/[mlcxtrv]/g, function (command) {
|
3317
|
+
return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
|
3318
|
+
}) + "z"
|
3319
|
+
};
|
3320
|
+
if (path.k) {
|
3321
|
+
for (var k in path.k) if (path[has](k)) {
|
3322
|
+
fontcopy.glyphs[glyph].k[k] = path.k[k];
|
3323
|
+
}
|
3324
|
+
}
|
3325
|
+
}
|
3326
|
+
}
|
3327
|
+
return font;
|
3328
|
+
};
|
3329
|
+
Paper[proto].getFont = function (family, weight, style, stretch) {
|
3330
|
+
stretch = stretch || "normal";
|
3331
|
+
style = style || "normal";
|
3332
|
+
weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
|
3333
|
+
if (!R.fonts) {
|
3334
|
+
return;
|
3335
|
+
}
|
3336
|
+
var font = R.fonts[family];
|
3337
|
+
if (!font) {
|
3338
|
+
var name = new RegExp("(^|\\s)" + family[rp](/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
|
3339
|
+
for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
|
3340
|
+
if (name.test(fontName)) {
|
3341
|
+
font = R.fonts[fontName];
|
3342
|
+
break;
|
3343
|
+
}
|
3344
|
+
}
|
3345
|
+
}
|
3346
|
+
var thefont;
|
3347
|
+
if (font) {
|
3348
|
+
for (var i = 0, ii = font[length]; i < ii; i++) {
|
3349
|
+
thefont = font[i];
|
3350
|
+
if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
|
3351
|
+
break;
|
3352
|
+
}
|
3353
|
+
}
|
3354
|
+
}
|
3355
|
+
return thefont;
|
3356
|
+
};
|
3357
|
+
Paper[proto].print = function (x, y, string, font, size, origin) {
|
3358
|
+
origin = origin || "middle"; // baseline|middle
|
3359
|
+
var out = this.set(),
|
3360
|
+
letters = (string + E)[split](E),
|
3361
|
+
shift = 0,
|
3362
|
+
path = E,
|
3363
|
+
scale;
|
3364
|
+
R.is(font, string) && (font = this.getFont(font));
|
3365
|
+
if (font) {
|
3366
|
+
scale = (size || 16) / font.face["units-per-em"];
|
3367
|
+
var bb = font.face.bbox.split(separator),
|
3368
|
+
top = +bb[0],
|
3369
|
+
height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
|
3370
|
+
for (var i = 0, ii = letters[length]; i < ii; i++) {
|
3371
|
+
var prev = i && font.glyphs[letters[i - 1]] || {},
|
3372
|
+
curr = font.glyphs[letters[i]];
|
3373
|
+
shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) : 0;
|
3374
|
+
curr && curr.d && out[push](this.path(curr.d).attr({fill: "#000", stroke: "none", translation: [shift, 0]}));
|
3375
|
+
}
|
3376
|
+
out.scale(scale, scale, top, height).translate(x - top, y - height);
|
3377
|
+
}
|
3378
|
+
return out;
|
3379
|
+
};
|
3380
|
+
|
3381
|
+
var formatrg = /\{(\d+)\}/g;
|
3382
|
+
R.format = function (token, params) {
|
3383
|
+
var args = R.is(params, array) ? [0][concat](params) : arguments;
|
3384
|
+
token && R.is(token, string) && args[length] - 1 && (token = token[rp](formatrg, function (str, i) {
|
3385
|
+
return args[++i] == null ? E : args[i];
|
3386
|
+
}));
|
3387
|
+
return token || E;
|
3388
|
+
};
|
3389
|
+
R.ninja = function () {
|
3390
|
+
oldRaphael.was ? (Raphael = oldRaphael.is) : delete Raphael;
|
3391
|
+
return R;
|
3392
|
+
};
|
3393
|
+
R.el = Element[proto];
|
3394
|
+
return R;
|
3395
|
+
})();
|